2 * Scsi Host Layer for MPT (Message Passing Technology) based controllers
4 * This code is based on drivers/scsi/mpt2sas/mpt2_scsih.c
5 * Copyright (C) 2007-2010 LSI Corporation
6 * (mailto:DL-MPTFusionLinux@lsi.com)
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
19 * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
20 * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
21 * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
22 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
23 * solely responsible for determining the appropriateness of using and
24 * distributing the Program and assumes all risks associated with its
25 * exercise of rights under this Agreement, including but not limited to
26 * the risks and costs of program errors, damage to or loss of data,
27 * programs or equipment, and unavailability or interruption of operations.
29 * DISCLAIMER OF LIABILITY
30 * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
31 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
33 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
34 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
35 * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
36 * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
38 * You should have received a copy of the GNU General Public License
39 * along with this program; if not, write to the Free Software
40 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
44 #include <linux/module.h>
45 #include <linux/kernel.h>
46 #include <linux/init.h>
47 #include <linux/errno.h>
48 #include <linux/blkdev.h>
49 #include <linux/sched.h>
50 #include <linux/workqueue.h>
51 #include <linux/delay.h>
52 #include <linux/pci.h>
53 #include <linux/interrupt.h>
54 #include <linux/aer.h>
55 #include <linux/raid_class.h>
56 #include <linux/slab.h>
58 #include "mpt2sas_base.h"
60 MODULE_AUTHOR(MPT2SAS_AUTHOR);
61 MODULE_DESCRIPTION(MPT2SAS_DESCRIPTION);
62 MODULE_LICENSE("GPL");
63 MODULE_VERSION(MPT2SAS_DRIVER_VERSION);
65 #define RAID_CHANNEL 1
68 static void _scsih_expander_node_remove(struct MPT2SAS_ADAPTER *ioc,
69 struct _sas_node *sas_expander);
70 static void _firmware_event_work(struct work_struct *work);
72 static u8 _scsih_check_for_pending_tm(struct MPT2SAS_ADAPTER *ioc, u16 smid);
74 static void _scsih_scan_start(struct Scsi_Host *shost);
75 static int _scsih_scan_finished(struct Scsi_Host *shost, unsigned long time);
77 /* global parameters */
78 LIST_HEAD(mpt2sas_ioc_list);
80 /* local parameters */
81 static u8 scsi_io_cb_idx = -1;
82 static u8 tm_cb_idx = -1;
83 static u8 ctl_cb_idx = -1;
84 static u8 base_cb_idx = -1;
85 static u8 port_enable_cb_idx = -1;
86 static u8 transport_cb_idx = -1;
87 static u8 scsih_cb_idx = -1;
88 static u8 config_cb_idx = -1;
91 static u8 tm_tr_cb_idx = -1 ;
92 static u8 tm_tr_volume_cb_idx = -1 ;
93 static u8 tm_sas_control_cb_idx = -1;
95 /* command line options */
96 static u32 logging_level;
97 MODULE_PARM_DESC(logging_level, " bits for enabling additional logging info "
100 static ushort max_sectors = 0xFFFF;
101 module_param(max_sectors, ushort, 0);
102 MODULE_PARM_DESC(max_sectors, "max sectors, range 64 to 8192 default=8192");
104 /* scsi-mid layer global parmeter is max_report_luns, which is 511 */
105 #define MPT2SAS_MAX_LUN (16895)
106 static int max_lun = MPT2SAS_MAX_LUN;
107 module_param(max_lun, int, 0);
108 MODULE_PARM_DESC(max_lun, " max lun, default=16895 ");
110 /* diag_buffer_enable is bitwise
112 * bit 1 set = SNAPSHOT
113 * bit 2 set = EXTENDED
115 * Either bit can be set, or both
117 static int diag_buffer_enable = -1;
118 module_param(diag_buffer_enable, int, 0);
119 MODULE_PARM_DESC(diag_buffer_enable, " post diag buffers "
120 "(TRACE=1/SNAPSHOT=2/EXTENDED=4/default=0)");
123 * struct sense_info - common structure for obtaining sense keys
125 * @asc: additional sense code
126 * @ascq: additional sense code qualifier
135 #define MPT2SAS_TURN_ON_FAULT_LED (0xFFFC)
136 #define MPT2SAS_PORT_ENABLE_COMPLETE (0xFFFD)
137 #define MPT2SAS_REMOVE_UNRESPONDING_DEVICES (0xFFFF)
139 * struct fw_event_work - firmware event struct
140 * @list: link list framework
141 * @work: work object (ioc->fault_reset_work_q)
142 * @cancel_pending_work: flag set during reset handling
143 * @ioc: per adapter object
144 * @device_handle: device handle
145 * @VF_ID: virtual function id
146 * @VP_ID: virtual port id
147 * @ignore: flag meaning this event has been marked to ignore
148 * @event: firmware event MPI2_EVENT_XXX defined in mpt2_ioc.h
149 * @event_data: reply event data payload follows
151 * This object stored on ioc->fw_event_list.
153 struct fw_event_work {
154 struct list_head list;
155 u8 cancel_pending_work;
156 struct delayed_work delayed_work;
157 struct MPT2SAS_ADAPTER *ioc;
166 /* raid transport support */
167 static struct raid_template *mpt2sas_raid_template;
170 * struct _scsi_io_transfer - scsi io transfer
171 * @handle: sas device handle (assigned by firmware)
172 * @is_raid: flag set for hidden raid components
173 * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE,
174 * @data_length: data transfer length
175 * @data_dma: dma pointer to data
178 * @cdb_length: cdb length
180 * @timeout: timeout for this command
181 * @VF_ID: virtual function id
182 * @VP_ID: virtual port id
183 * @valid_reply: flag set for reply message
184 * @sense_length: sense length
185 * @ioc_status: ioc status
186 * @scsi_state: scsi state
187 * @scsi_status: scsi staus
188 * @log_info: log information
189 * @transfer_length: data length transfer when there is a reply message
191 * Used for sending internal scsi commands to devices within this module.
192 * Refer to _scsi_send_scsi_io().
194 struct _scsi_io_transfer {
197 enum dma_data_direction dir;
200 u8 sense[SCSI_SENSE_BUFFERSIZE];
208 /* the following bits are only valid when 'valid_reply = 1' */
218 * The pci device ids are defined in mpi/mpi2_cnfg.h.
220 static struct pci_device_id scsih_pci_table[] = {
221 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2004,
222 PCI_ANY_ID, PCI_ANY_ID },
224 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2008,
225 PCI_ANY_ID, PCI_ANY_ID },
226 /* Liberator ~ 2108 */
227 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_1,
228 PCI_ANY_ID, PCI_ANY_ID },
229 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_2,
230 PCI_ANY_ID, PCI_ANY_ID },
231 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_3,
232 PCI_ANY_ID, PCI_ANY_ID },
234 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_1,
235 PCI_ANY_ID, PCI_ANY_ID },
236 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_2,
237 PCI_ANY_ID, PCI_ANY_ID },
238 /* Thunderbolt ~ 2208 */
239 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_1,
240 PCI_ANY_ID, PCI_ANY_ID },
241 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_2,
242 PCI_ANY_ID, PCI_ANY_ID },
243 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_3,
244 PCI_ANY_ID, PCI_ANY_ID },
245 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_4,
246 PCI_ANY_ID, PCI_ANY_ID },
247 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_5,
248 PCI_ANY_ID, PCI_ANY_ID },
249 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_6,
250 PCI_ANY_ID, PCI_ANY_ID },
252 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_1,
253 PCI_ANY_ID, PCI_ANY_ID },
254 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_2,
255 PCI_ANY_ID, PCI_ANY_ID },
256 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_3,
257 PCI_ANY_ID, PCI_ANY_ID },
259 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SSS6200,
260 PCI_ANY_ID, PCI_ANY_ID },
261 {0} /* Terminating entry */
263 MODULE_DEVICE_TABLE(pci, scsih_pci_table);
266 * _scsih_set_debug_level - global setting of ioc->logging_level.
268 * Note: The logging levels are defined in mpt2sas_debug.h.
271 _scsih_set_debug_level(const char *val, struct kernel_param *kp)
273 int ret = param_set_int(val, kp);
274 struct MPT2SAS_ADAPTER *ioc;
279 printk(KERN_INFO "setting logging_level(0x%08x)\n", logging_level);
280 list_for_each_entry(ioc, &mpt2sas_ioc_list, list)
281 ioc->logging_level = logging_level;
284 module_param_call(logging_level, _scsih_set_debug_level, param_get_int,
285 &logging_level, 0644);
288 * _scsih_srch_boot_sas_address - search based on sas_address
289 * @sas_address: sas address
290 * @boot_device: boot device object from bios page 2
292 * Returns 1 when there's a match, 0 means no match.
295 _scsih_srch_boot_sas_address(u64 sas_address,
296 Mpi2BootDeviceSasWwid_t *boot_device)
298 return (sas_address == le64_to_cpu(boot_device->SASAddress)) ? 1 : 0;
302 * _scsih_srch_boot_device_name - search based on device name
303 * @device_name: device name specified in INDENTIFY fram
304 * @boot_device: boot device object from bios page 2
306 * Returns 1 when there's a match, 0 means no match.
309 _scsih_srch_boot_device_name(u64 device_name,
310 Mpi2BootDeviceDeviceName_t *boot_device)
312 return (device_name == le64_to_cpu(boot_device->DeviceName)) ? 1 : 0;
316 * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot
317 * @enclosure_logical_id: enclosure logical id
318 * @slot_number: slot number
319 * @boot_device: boot device object from bios page 2
321 * Returns 1 when there's a match, 0 means no match.
324 _scsih_srch_boot_encl_slot(u64 enclosure_logical_id, u16 slot_number,
325 Mpi2BootDeviceEnclosureSlot_t *boot_device)
327 return (enclosure_logical_id == le64_to_cpu(boot_device->
328 EnclosureLogicalID) && slot_number == le16_to_cpu(boot_device->
329 SlotNumber)) ? 1 : 0;
333 * _scsih_is_boot_device - search for matching boot device.
334 * @sas_address: sas address
335 * @device_name: device name specified in INDENTIFY fram
336 * @enclosure_logical_id: enclosure logical id
337 * @slot_number: slot number
338 * @form: specifies boot device form
339 * @boot_device: boot device object from bios page 2
341 * Returns 1 when there's a match, 0 means no match.
344 _scsih_is_boot_device(u64 sas_address, u64 device_name,
345 u64 enclosure_logical_id, u16 slot, u8 form,
346 Mpi2BiosPage2BootDevice_t *boot_device)
351 case MPI2_BIOSPAGE2_FORM_SAS_WWID:
354 rc = _scsih_srch_boot_sas_address(
355 sas_address, &boot_device->SasWwid);
357 case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT:
358 if (!enclosure_logical_id)
360 rc = _scsih_srch_boot_encl_slot(
361 enclosure_logical_id,
362 slot, &boot_device->EnclosureSlot);
364 case MPI2_BIOSPAGE2_FORM_DEVICE_NAME:
367 rc = _scsih_srch_boot_device_name(
368 device_name, &boot_device->DeviceName);
370 case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED:
378 * _scsih_get_sas_address - set the sas_address for given device handle
379 * @handle: device handle
380 * @sas_address: sas address
382 * Returns 0 success, non-zero when failure
385 _scsih_get_sas_address(struct MPT2SAS_ADAPTER *ioc, u16 handle,
388 Mpi2SasDevicePage0_t sas_device_pg0;
389 Mpi2ConfigReply_t mpi_reply;
393 if (handle <= ioc->sas_hba.num_phys) {
394 *sas_address = ioc->sas_hba.sas_address;
398 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
399 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
400 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", ioc->name,
401 __FILE__, __LINE__, __func__);
405 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
406 if (ioc_status == MPI2_IOCSTATUS_SUCCESS) {
407 *sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
411 /* we hit this becuase the given parent handle doesn't exist */
412 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
414 /* else error case */
415 printk(MPT2SAS_ERR_FMT "handle(0x%04x), ioc_status(0x%04x), "
416 "failure at %s:%d/%s()!\n", ioc->name, handle, ioc_status,
417 __FILE__, __LINE__, __func__);
422 * _scsih_determine_boot_device - determine boot device.
423 * @ioc: per adapter object
424 * @device: either sas_device or raid_device object
425 * @is_raid: [flag] 1 = raid object, 0 = sas object
427 * Determines whether this device should be first reported device to
428 * to scsi-ml or sas transport, this purpose is for persistent boot device.
429 * There are primary, alternate, and current entries in bios page 2. The order
430 * priority is primary, alternate, then current. This routine saves
431 * the corresponding device object and is_raid flag in the ioc object.
432 * The saved data to be used later in _scsih_probe_boot_devices().
435 _scsih_determine_boot_device(struct MPT2SAS_ADAPTER *ioc,
436 void *device, u8 is_raid)
438 struct _sas_device *sas_device;
439 struct _raid_device *raid_device;
442 u64 enclosure_logical_id;
445 /* only process this function when driver loads */
446 if (!ioc->is_driver_loading)
449 /* no Bios, return immediately */
450 if (!ioc->bios_pg3.BiosVersion)
455 sas_address = sas_device->sas_address;
456 device_name = sas_device->device_name;
457 enclosure_logical_id = sas_device->enclosure_logical_id;
458 slot = sas_device->slot;
460 raid_device = device;
461 sas_address = raid_device->wwid;
463 enclosure_logical_id = 0;
467 if (!ioc->req_boot_device.device) {
468 if (_scsih_is_boot_device(sas_address, device_name,
469 enclosure_logical_id, slot,
470 (ioc->bios_pg2.ReqBootDeviceForm &
471 MPI2_BIOSPAGE2_FORM_MASK),
472 &ioc->bios_pg2.RequestedBootDevice)) {
473 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT
474 "%s: req_boot_device(0x%016llx)\n",
476 (unsigned long long)sas_address));
477 ioc->req_boot_device.device = device;
478 ioc->req_boot_device.is_raid = is_raid;
482 if (!ioc->req_alt_boot_device.device) {
483 if (_scsih_is_boot_device(sas_address, device_name,
484 enclosure_logical_id, slot,
485 (ioc->bios_pg2.ReqAltBootDeviceForm &
486 MPI2_BIOSPAGE2_FORM_MASK),
487 &ioc->bios_pg2.RequestedAltBootDevice)) {
488 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT
489 "%s: req_alt_boot_device(0x%016llx)\n",
491 (unsigned long long)sas_address));
492 ioc->req_alt_boot_device.device = device;
493 ioc->req_alt_boot_device.is_raid = is_raid;
497 if (!ioc->current_boot_device.device) {
498 if (_scsih_is_boot_device(sas_address, device_name,
499 enclosure_logical_id, slot,
500 (ioc->bios_pg2.CurrentBootDeviceForm &
501 MPI2_BIOSPAGE2_FORM_MASK),
502 &ioc->bios_pg2.CurrentBootDevice)) {
503 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT
504 "%s: current_boot_device(0x%016llx)\n",
506 (unsigned long long)sas_address));
507 ioc->current_boot_device.device = device;
508 ioc->current_boot_device.is_raid = is_raid;
514 * mpt2sas_scsih_sas_device_find_by_sas_address - sas device search
515 * @ioc: per adapter object
516 * @sas_address: sas address
517 * Context: Calling function should acquire ioc->sas_device_lock
519 * This searches for sas_device based on sas_address, then return sas_device
523 mpt2sas_scsih_sas_device_find_by_sas_address(struct MPT2SAS_ADAPTER *ioc,
526 struct _sas_device *sas_device;
528 list_for_each_entry(sas_device, &ioc->sas_device_list, list)
529 if (sas_device->sas_address == sas_address)
532 list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
533 if (sas_device->sas_address == sas_address)
540 * _scsih_sas_device_find_by_handle - sas device search
541 * @ioc: per adapter object
542 * @handle: sas device handle (assigned by firmware)
543 * Context: Calling function should acquire ioc->sas_device_lock
545 * This searches for sas_device based on sas_address, then return sas_device
548 static struct _sas_device *
549 _scsih_sas_device_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
551 struct _sas_device *sas_device;
553 list_for_each_entry(sas_device, &ioc->sas_device_list, list)
554 if (sas_device->handle == handle)
557 list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
558 if (sas_device->handle == handle)
565 * _scsih_sas_device_remove - remove sas_device from list.
566 * @ioc: per adapter object
567 * @sas_device: the sas_device object
568 * Context: This function will acquire ioc->sas_device_lock.
570 * Removing object and freeing associated memory from the ioc->sas_device_list.
573 _scsih_sas_device_remove(struct MPT2SAS_ADAPTER *ioc,
574 struct _sas_device *sas_device)
581 spin_lock_irqsave(&ioc->sas_device_lock, flags);
582 if (mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
583 sas_device->sas_address)) {
584 list_del(&sas_device->list);
587 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
591 * _scsih_sas_device_add - insert sas_device to the list.
592 * @ioc: per adapter object
593 * @sas_device: the sas_device object
594 * Context: This function will acquire ioc->sas_device_lock.
596 * Adding new object to the ioc->sas_device_list.
599 _scsih_sas_device_add(struct MPT2SAS_ADAPTER *ioc,
600 struct _sas_device *sas_device)
604 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle"
605 "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
606 sas_device->handle, (unsigned long long)sas_device->sas_address));
608 spin_lock_irqsave(&ioc->sas_device_lock, flags);
609 list_add_tail(&sas_device->list, &ioc->sas_device_list);
610 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
612 if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
613 sas_device->sas_address_parent)) {
614 _scsih_sas_device_remove(ioc, sas_device);
615 } else if (!sas_device->starget) {
616 if (!ioc->is_driver_loading)
617 mpt2sas_transport_port_remove(ioc,
618 sas_device->sas_address,
619 sas_device->sas_address_parent);
620 _scsih_sas_device_remove(ioc, sas_device);
625 * _scsih_sas_device_init_add - insert sas_device to the list.
626 * @ioc: per adapter object
627 * @sas_device: the sas_device object
628 * Context: This function will acquire ioc->sas_device_lock.
630 * Adding new object at driver load time to the ioc->sas_device_init_list.
633 _scsih_sas_device_init_add(struct MPT2SAS_ADAPTER *ioc,
634 struct _sas_device *sas_device)
638 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle"
639 "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
640 sas_device->handle, (unsigned long long)sas_device->sas_address));
642 spin_lock_irqsave(&ioc->sas_device_lock, flags);
643 list_add_tail(&sas_device->list, &ioc->sas_device_init_list);
644 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
645 _scsih_determine_boot_device(ioc, sas_device, 0);
649 * _scsih_raid_device_find_by_id - raid device search
650 * @ioc: per adapter object
651 * @id: sas device target id
652 * @channel: sas device channel
653 * Context: Calling function should acquire ioc->raid_device_lock
655 * This searches for raid_device based on target id, then return raid_device
658 static struct _raid_device *
659 _scsih_raid_device_find_by_id(struct MPT2SAS_ADAPTER *ioc, int id, int channel)
661 struct _raid_device *raid_device, *r;
664 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
665 if (raid_device->id == id && raid_device->channel == channel) {
676 * _scsih_raid_device_find_by_handle - raid device search
677 * @ioc: per adapter object
678 * @handle: sas device handle (assigned by firmware)
679 * Context: Calling function should acquire ioc->raid_device_lock
681 * This searches for raid_device based on handle, then return raid_device
684 static struct _raid_device *
685 _scsih_raid_device_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
687 struct _raid_device *raid_device, *r;
690 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
691 if (raid_device->handle != handle)
702 * _scsih_raid_device_find_by_wwid - raid device search
703 * @ioc: per adapter object
704 * @handle: sas device handle (assigned by firmware)
705 * Context: Calling function should acquire ioc->raid_device_lock
707 * This searches for raid_device based on wwid, then return raid_device
710 static struct _raid_device *
711 _scsih_raid_device_find_by_wwid(struct MPT2SAS_ADAPTER *ioc, u64 wwid)
713 struct _raid_device *raid_device, *r;
716 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
717 if (raid_device->wwid != wwid)
728 * _scsih_raid_device_add - add raid_device object
729 * @ioc: per adapter object
730 * @raid_device: raid_device object
732 * This is added to the raid_device_list link list.
735 _scsih_raid_device_add(struct MPT2SAS_ADAPTER *ioc,
736 struct _raid_device *raid_device)
740 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle"
741 "(0x%04x), wwid(0x%016llx)\n", ioc->name, __func__,
742 raid_device->handle, (unsigned long long)raid_device->wwid));
744 spin_lock_irqsave(&ioc->raid_device_lock, flags);
745 list_add_tail(&raid_device->list, &ioc->raid_device_list);
746 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
750 * _scsih_raid_device_remove - delete raid_device object
751 * @ioc: per adapter object
752 * @raid_device: raid_device object
754 * This is removed from the raid_device_list link list.
757 _scsih_raid_device_remove(struct MPT2SAS_ADAPTER *ioc,
758 struct _raid_device *raid_device)
762 spin_lock_irqsave(&ioc->raid_device_lock, flags);
763 list_del(&raid_device->list);
764 memset(raid_device, 0, sizeof(struct _raid_device));
766 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
770 * mpt2sas_scsih_expander_find_by_handle - expander device search
771 * @ioc: per adapter object
772 * @handle: expander handle (assigned by firmware)
773 * Context: Calling function should acquire ioc->sas_device_lock
775 * This searches for expander device based on handle, then returns the
779 mpt2sas_scsih_expander_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
781 struct _sas_node *sas_expander, *r;
784 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
785 if (sas_expander->handle != handle)
795 * mpt2sas_scsih_expander_find_by_sas_address - expander device search
796 * @ioc: per adapter object
797 * @sas_address: sas address
798 * Context: Calling function should acquire ioc->sas_node_lock.
800 * This searches for expander device based on sas_address, then returns the
804 mpt2sas_scsih_expander_find_by_sas_address(struct MPT2SAS_ADAPTER *ioc,
807 struct _sas_node *sas_expander, *r;
810 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
811 if (sas_expander->sas_address != sas_address)
821 * _scsih_expander_node_add - insert expander device to the list.
822 * @ioc: per adapter object
823 * @sas_expander: the sas_device object
824 * Context: This function will acquire ioc->sas_node_lock.
826 * Adding new object to the ioc->sas_expander_list.
831 _scsih_expander_node_add(struct MPT2SAS_ADAPTER *ioc,
832 struct _sas_node *sas_expander)
836 spin_lock_irqsave(&ioc->sas_node_lock, flags);
837 list_add_tail(&sas_expander->list, &ioc->sas_expander_list);
838 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
842 * _scsih_is_end_device - determines if device is an end device
843 * @device_info: bitfield providing information about the device.
846 * Returns 1 if end device.
849 _scsih_is_end_device(u32 device_info)
851 if (device_info & MPI2_SAS_DEVICE_INFO_END_DEVICE &&
852 ((device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) |
853 (device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) |
854 (device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE)))
861 * _scsih_scsi_lookup_get - returns scmd entry
862 * @ioc: per adapter object
863 * @smid: system request message index
865 * Returns the smid stored scmd pointer.
867 static struct scsi_cmnd *
868 _scsih_scsi_lookup_get(struct MPT2SAS_ADAPTER *ioc, u16 smid)
870 return ioc->scsi_lookup[smid - 1].scmd;
874 * _scsih_scsi_lookup_get_clear - returns scmd entry
875 * @ioc: per adapter object
876 * @smid: system request message index
878 * Returns the smid stored scmd pointer.
879 * Then will derefrence the stored scmd pointer.
881 static inline struct scsi_cmnd *
882 _scsih_scsi_lookup_get_clear(struct MPT2SAS_ADAPTER *ioc, u16 smid)
885 struct scsi_cmnd *scmd;
887 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
888 scmd = ioc->scsi_lookup[smid - 1].scmd;
889 ioc->scsi_lookup[smid - 1].scmd = NULL;
890 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
896 * _scsih_scsi_lookup_find_by_scmd - scmd lookup
897 * @ioc: per adapter object
898 * @smid: system request message index
899 * @scmd: pointer to scsi command object
900 * Context: This function will acquire ioc->scsi_lookup_lock.
902 * This will search for a scmd pointer in the scsi_lookup array,
903 * returning the revelent smid. A returned value of zero means invalid.
906 _scsih_scsi_lookup_find_by_scmd(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd
913 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
915 for (i = 0; i < ioc->scsiio_depth; i++) {
916 if (ioc->scsi_lookup[i].scmd == scmd) {
917 smid = ioc->scsi_lookup[i].smid;
922 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
927 * _scsih_scsi_lookup_find_by_target - search for matching channel:id
928 * @ioc: per adapter object
931 * Context: This function will acquire ioc->scsi_lookup_lock.
933 * This will search for a matching channel:id in the scsi_lookup array,
934 * returning 1 if found.
937 _scsih_scsi_lookup_find_by_target(struct MPT2SAS_ADAPTER *ioc, int id,
944 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
946 for (i = 0 ; i < ioc->scsiio_depth; i++) {
947 if (ioc->scsi_lookup[i].scmd &&
948 (ioc->scsi_lookup[i].scmd->device->id == id &&
949 ioc->scsi_lookup[i].scmd->device->channel == channel)) {
955 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
960 * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun
961 * @ioc: per adapter object
965 * Context: This function will acquire ioc->scsi_lookup_lock.
967 * This will search for a matching channel:id:lun in the scsi_lookup array,
968 * returning 1 if found.
971 _scsih_scsi_lookup_find_by_lun(struct MPT2SAS_ADAPTER *ioc, int id,
972 unsigned int lun, int channel)
978 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
980 for (i = 0 ; i < ioc->scsiio_depth; i++) {
981 if (ioc->scsi_lookup[i].scmd &&
982 (ioc->scsi_lookup[i].scmd->device->id == id &&
983 ioc->scsi_lookup[i].scmd->device->channel == channel &&
984 ioc->scsi_lookup[i].scmd->device->lun == lun)) {
990 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
995 * _scsih_get_chain_buffer_tracker - obtain chain tracker
996 * @ioc: per adapter object
997 * @smid: smid associated to an IO request
999 * Returns chain tracker(from ioc->free_chain_list)
1001 static struct chain_tracker *
1002 _scsih_get_chain_buffer_tracker(struct MPT2SAS_ADAPTER *ioc, u16 smid)
1004 struct chain_tracker *chain_req;
1005 unsigned long flags;
1007 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1008 if (list_empty(&ioc->free_chain_list)) {
1009 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1010 printk(MPT2SAS_WARN_FMT "chain buffers not available\n",
1014 chain_req = list_entry(ioc->free_chain_list.next,
1015 struct chain_tracker, tracker_list);
1016 list_del_init(&chain_req->tracker_list);
1017 list_add_tail(&chain_req->tracker_list,
1018 &ioc->scsi_lookup[smid - 1].chain_list);
1019 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1024 * _scsih_build_scatter_gather - main sg creation routine
1025 * @ioc: per adapter object
1026 * @scmd: scsi command
1027 * @smid: system request message index
1030 * The main routine that builds scatter gather table from a given
1031 * scsi request sent via the .queuecommand main handler.
1033 * Returns 0 success, anything else error
1036 _scsih_build_scatter_gather(struct MPT2SAS_ADAPTER *ioc,
1037 struct scsi_cmnd *scmd, u16 smid)
1039 Mpi2SCSIIORequest_t *mpi_request;
1040 dma_addr_t chain_dma;
1041 struct scatterlist *sg_scmd;
1042 void *sg_local, *chain;
1047 u32 sges_in_segment;
1049 u32 sgl_flags_last_element;
1050 u32 sgl_flags_end_buffer;
1051 struct chain_tracker *chain_req;
1053 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
1055 /* init scatter gather flags */
1056 sgl_flags = MPI2_SGE_FLAGS_SIMPLE_ELEMENT;
1057 if (scmd->sc_data_direction == DMA_TO_DEVICE)
1058 sgl_flags |= MPI2_SGE_FLAGS_HOST_TO_IOC;
1059 sgl_flags_last_element = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT)
1060 << MPI2_SGE_FLAGS_SHIFT;
1061 sgl_flags_end_buffer = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT |
1062 MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_END_OF_LIST)
1063 << MPI2_SGE_FLAGS_SHIFT;
1064 sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT;
1066 sg_scmd = scsi_sglist(scmd);
1067 sges_left = scsi_dma_map(scmd);
1068 if (sges_left < 0) {
1069 sdev_printk(KERN_ERR, scmd->device, "pci_map_sg"
1070 " failed: request for %d bytes!\n", scsi_bufflen(scmd));
1074 sg_local = &mpi_request->SGL;
1075 sges_in_segment = ioc->max_sges_in_main_message;
1076 if (sges_left <= sges_in_segment)
1077 goto fill_in_last_segment;
1079 mpi_request->ChainOffset = (offsetof(Mpi2SCSIIORequest_t, SGL) +
1080 (sges_in_segment * ioc->sge_size))/4;
1082 /* fill in main message segment when there is a chain following */
1083 while (sges_in_segment) {
1084 if (sges_in_segment == 1)
1085 ioc->base_add_sg_single(sg_local,
1086 sgl_flags_last_element | sg_dma_len(sg_scmd),
1087 sg_dma_address(sg_scmd));
1089 ioc->base_add_sg_single(sg_local, sgl_flags |
1090 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
1091 sg_scmd = sg_next(sg_scmd);
1092 sg_local += ioc->sge_size;
1097 /* initializing the chain flags and pointers */
1098 chain_flags = MPI2_SGE_FLAGS_CHAIN_ELEMENT << MPI2_SGE_FLAGS_SHIFT;
1099 chain_req = _scsih_get_chain_buffer_tracker(ioc, smid);
1102 chain = chain_req->chain_buffer;
1103 chain_dma = chain_req->chain_buffer_dma;
1105 sges_in_segment = (sges_left <=
1106 ioc->max_sges_in_chain_message) ? sges_left :
1107 ioc->max_sges_in_chain_message;
1108 chain_offset = (sges_left == sges_in_segment) ?
1109 0 : (sges_in_segment * ioc->sge_size)/4;
1110 chain_length = sges_in_segment * ioc->sge_size;
1112 chain_offset = chain_offset <<
1113 MPI2_SGE_CHAIN_OFFSET_SHIFT;
1114 chain_length += ioc->sge_size;
1116 ioc->base_add_sg_single(sg_local, chain_flags | chain_offset |
1117 chain_length, chain_dma);
1120 goto fill_in_last_segment;
1122 /* fill in chain segments */
1123 while (sges_in_segment) {
1124 if (sges_in_segment == 1)
1125 ioc->base_add_sg_single(sg_local,
1126 sgl_flags_last_element |
1127 sg_dma_len(sg_scmd),
1128 sg_dma_address(sg_scmd));
1130 ioc->base_add_sg_single(sg_local, sgl_flags |
1131 sg_dma_len(sg_scmd),
1132 sg_dma_address(sg_scmd));
1133 sg_scmd = sg_next(sg_scmd);
1134 sg_local += ioc->sge_size;
1139 chain_req = _scsih_get_chain_buffer_tracker(ioc, smid);
1142 chain = chain_req->chain_buffer;
1143 chain_dma = chain_req->chain_buffer_dma;
1147 fill_in_last_segment:
1149 /* fill the last segment */
1152 ioc->base_add_sg_single(sg_local, sgl_flags_end_buffer |
1153 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
1155 ioc->base_add_sg_single(sg_local, sgl_flags |
1156 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
1157 sg_scmd = sg_next(sg_scmd);
1158 sg_local += ioc->sge_size;
1166 * _scsih_adjust_queue_depth - setting device queue depth
1167 * @sdev: scsi device struct
1168 * @qdepth: requested queue depth
1174 _scsih_adjust_queue_depth(struct scsi_device *sdev, int qdepth)
1176 struct Scsi_Host *shost = sdev->host;
1178 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1179 struct MPT2SAS_DEVICE *sas_device_priv_data;
1180 struct MPT2SAS_TARGET *sas_target_priv_data;
1181 struct _sas_device *sas_device;
1182 unsigned long flags;
1184 max_depth = shost->can_queue;
1186 /* limit max device queue for SATA to 32 */
1187 sas_device_priv_data = sdev->hostdata;
1188 if (!sas_device_priv_data)
1190 sas_target_priv_data = sas_device_priv_data->sas_target;
1191 if (!sas_target_priv_data)
1193 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))
1195 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1196 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1197 sas_device_priv_data->sas_target->sas_address);
1198 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1199 if (sas_device && sas_device->device_info &
1200 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1201 max_depth = MPT2SAS_SATA_QUEUE_DEPTH;
1205 if (!sdev->tagged_supported)
1207 if (qdepth > max_depth)
1209 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
1213 * _scsih_change_queue_depth - setting device queue depth
1214 * @sdev: scsi device struct
1215 * @qdepth: requested queue depth
1216 * @reason: SCSI_QDEPTH_DEFAULT/SCSI_QDEPTH_QFULL/SCSI_QDEPTH_RAMP_UP
1217 * (see include/scsi/scsi_host.h for definition)
1219 * Returns queue depth.
1222 _scsih_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
1224 if (reason == SCSI_QDEPTH_DEFAULT || reason == SCSI_QDEPTH_RAMP_UP)
1225 _scsih_adjust_queue_depth(sdev, qdepth);
1226 else if (reason == SCSI_QDEPTH_QFULL)
1227 scsi_track_queue_full(sdev, qdepth);
1231 if (sdev->inquiry_len > 7)
1232 sdev_printk(KERN_INFO, sdev, "qdepth(%d), tagged(%d), "
1233 "simple(%d), ordered(%d), scsi_level(%d), cmd_que(%d)\n",
1234 sdev->queue_depth, sdev->tagged_supported, sdev->simple_tags,
1235 sdev->ordered_tags, sdev->scsi_level,
1236 (sdev->inquiry[7] & 2) >> 1);
1238 return sdev->queue_depth;
1242 * _scsih_change_queue_type - changing device queue tag type
1243 * @sdev: scsi device struct
1244 * @tag_type: requested tag type
1246 * Returns queue tag type.
1249 _scsih_change_queue_type(struct scsi_device *sdev, int tag_type)
1251 if (sdev->tagged_supported) {
1252 scsi_set_tag_type(sdev, tag_type);
1254 scsi_activate_tcq(sdev, sdev->queue_depth);
1256 scsi_deactivate_tcq(sdev, sdev->queue_depth);
1264 * _scsih_target_alloc - target add routine
1265 * @starget: scsi target struct
1267 * Returns 0 if ok. Any other return is assumed to be an error and
1268 * the device is ignored.
1271 _scsih_target_alloc(struct scsi_target *starget)
1273 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1274 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1275 struct MPT2SAS_TARGET *sas_target_priv_data;
1276 struct _sas_device *sas_device;
1277 struct _raid_device *raid_device;
1278 unsigned long flags;
1279 struct sas_rphy *rphy;
1281 sas_target_priv_data = kzalloc(sizeof(struct scsi_target), GFP_KERNEL);
1282 if (!sas_target_priv_data)
1285 starget->hostdata = sas_target_priv_data;
1286 sas_target_priv_data->starget = starget;
1287 sas_target_priv_data->handle = MPT2SAS_INVALID_DEVICE_HANDLE;
1290 if (starget->channel == RAID_CHANNEL) {
1291 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1292 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1295 sas_target_priv_data->handle = raid_device->handle;
1296 sas_target_priv_data->sas_address = raid_device->wwid;
1297 sas_target_priv_data->flags |= MPT_TARGET_FLAGS_VOLUME;
1298 sas_target_priv_data->raid_device = raid_device;
1299 raid_device->starget = starget;
1301 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1305 /* sas/sata devices */
1306 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1307 rphy = dev_to_rphy(starget->dev.parent);
1308 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1309 rphy->identify.sas_address);
1312 sas_target_priv_data->handle = sas_device->handle;
1313 sas_target_priv_data->sas_address = sas_device->sas_address;
1314 sas_device->starget = starget;
1315 sas_device->id = starget->id;
1316 sas_device->channel = starget->channel;
1317 if (test_bit(sas_device->handle, ioc->pd_handles))
1318 sas_target_priv_data->flags |=
1319 MPT_TARGET_FLAGS_RAID_COMPONENT;
1321 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1327 * _scsih_target_destroy - target destroy routine
1328 * @starget: scsi target struct
1333 _scsih_target_destroy(struct scsi_target *starget)
1335 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1336 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1337 struct MPT2SAS_TARGET *sas_target_priv_data;
1338 struct _sas_device *sas_device;
1339 struct _raid_device *raid_device;
1340 unsigned long flags;
1341 struct sas_rphy *rphy;
1343 sas_target_priv_data = starget->hostdata;
1344 if (!sas_target_priv_data)
1347 if (starget->channel == RAID_CHANNEL) {
1348 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1349 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1352 raid_device->starget = NULL;
1353 raid_device->sdev = NULL;
1355 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1359 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1360 rphy = dev_to_rphy(starget->dev.parent);
1361 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1362 rphy->identify.sas_address);
1363 if (sas_device && (sas_device->starget == starget) &&
1364 (sas_device->id == starget->id) &&
1365 (sas_device->channel == starget->channel))
1366 sas_device->starget = NULL;
1368 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1371 kfree(sas_target_priv_data);
1372 starget->hostdata = NULL;
1376 * _scsih_slave_alloc - device add routine
1377 * @sdev: scsi device struct
1379 * Returns 0 if ok. Any other return is assumed to be an error and
1380 * the device is ignored.
1383 _scsih_slave_alloc(struct scsi_device *sdev)
1385 struct Scsi_Host *shost;
1386 struct MPT2SAS_ADAPTER *ioc;
1387 struct MPT2SAS_TARGET *sas_target_priv_data;
1388 struct MPT2SAS_DEVICE *sas_device_priv_data;
1389 struct scsi_target *starget;
1390 struct _raid_device *raid_device;
1391 unsigned long flags;
1393 sas_device_priv_data = kzalloc(sizeof(struct scsi_device), GFP_KERNEL);
1394 if (!sas_device_priv_data)
1397 sas_device_priv_data->lun = sdev->lun;
1398 sas_device_priv_data->flags = MPT_DEVICE_FLAGS_INIT;
1400 starget = scsi_target(sdev);
1401 sas_target_priv_data = starget->hostdata;
1402 sas_target_priv_data->num_luns++;
1403 sas_device_priv_data->sas_target = sas_target_priv_data;
1404 sdev->hostdata = sas_device_priv_data;
1405 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT))
1406 sdev->no_uld_attach = 1;
1408 shost = dev_to_shost(&starget->dev);
1409 ioc = shost_priv(shost);
1410 if (starget->channel == RAID_CHANNEL) {
1411 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1412 raid_device = _scsih_raid_device_find_by_id(ioc,
1413 starget->id, starget->channel);
1415 raid_device->sdev = sdev; /* raid is single lun */
1416 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1423 * _scsih_slave_destroy - device destroy routine
1424 * @sdev: scsi device struct
1429 _scsih_slave_destroy(struct scsi_device *sdev)
1431 struct MPT2SAS_TARGET *sas_target_priv_data;
1432 struct scsi_target *starget;
1433 struct Scsi_Host *shost;
1434 struct MPT2SAS_ADAPTER *ioc;
1435 struct _sas_device *sas_device;
1436 unsigned long flags;
1438 if (!sdev->hostdata)
1441 starget = scsi_target(sdev);
1442 sas_target_priv_data = starget->hostdata;
1443 sas_target_priv_data->num_luns--;
1445 shost = dev_to_shost(&starget->dev);
1446 ioc = shost_priv(shost);
1448 if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) {
1449 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1450 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1451 sas_target_priv_data->sas_address);
1453 sas_device->starget = NULL;
1454 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1457 kfree(sdev->hostdata);
1458 sdev->hostdata = NULL;
1462 * _scsih_display_sata_capabilities - sata capabilities
1463 * @ioc: per adapter object
1464 * @sas_device: the sas_device object
1465 * @sdev: scsi device struct
1468 _scsih_display_sata_capabilities(struct MPT2SAS_ADAPTER *ioc,
1469 struct _sas_device *sas_device, struct scsi_device *sdev)
1471 Mpi2ConfigReply_t mpi_reply;
1472 Mpi2SasDevicePage0_t sas_device_pg0;
1477 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
1478 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, sas_device->handle))) {
1479 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1480 ioc->name, __FILE__, __LINE__, __func__);
1484 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1485 MPI2_IOCSTATUS_MASK;
1486 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
1487 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1488 ioc->name, __FILE__, __LINE__, __func__);
1492 flags = le16_to_cpu(sas_device_pg0.Flags);
1493 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
1495 sdev_printk(KERN_INFO, sdev,
1496 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1497 "sw_preserve(%s)\n",
1498 (device_info & MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE) ? "y" : "n",
1499 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED) ? "y" : "n",
1500 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY) ? "y" :
1502 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED) ? "y" : "n",
1503 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED) ? "y" : "n",
1504 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE) ? "y" : "n");
1508 * _scsih_is_raid - return boolean indicating device is raid volume
1509 * @dev the device struct object
1512 _scsih_is_raid(struct device *dev)
1514 struct scsi_device *sdev = to_scsi_device(dev);
1515 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
1517 if (ioc->is_warpdrive)
1519 return (sdev->channel == RAID_CHANNEL) ? 1 : 0;
1523 * _scsih_get_resync - get raid volume resync percent complete
1524 * @dev the device struct object
1527 _scsih_get_resync(struct device *dev)
1529 struct scsi_device *sdev = to_scsi_device(dev);
1530 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
1531 static struct _raid_device *raid_device;
1532 unsigned long flags;
1533 Mpi2RaidVolPage0_t vol_pg0;
1534 Mpi2ConfigReply_t mpi_reply;
1535 u32 volume_status_flags;
1536 u8 percent_complete = 0;
1538 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1539 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1541 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1543 if (!raid_device || ioc->is_warpdrive)
1546 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
1547 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle,
1548 sizeof(Mpi2RaidVolPage0_t))) {
1549 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1550 ioc->name, __FILE__, __LINE__, __func__);
1554 volume_status_flags = le32_to_cpu(vol_pg0.VolumeStatusFlags);
1555 if (volume_status_flags & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS)
1556 percent_complete = raid_device->percent_complete;
1558 raid_set_resync(mpt2sas_raid_template, dev, percent_complete);
1562 * _scsih_get_state - get raid volume level
1563 * @dev the device struct object
1566 _scsih_get_state(struct device *dev)
1568 struct scsi_device *sdev = to_scsi_device(dev);
1569 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
1570 static struct _raid_device *raid_device;
1571 unsigned long flags;
1572 Mpi2RaidVolPage0_t vol_pg0;
1573 Mpi2ConfigReply_t mpi_reply;
1575 enum raid_state state = RAID_STATE_UNKNOWN;
1577 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1578 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1580 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1585 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
1586 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle,
1587 sizeof(Mpi2RaidVolPage0_t))) {
1588 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1589 ioc->name, __FILE__, __LINE__, __func__);
1593 volstate = le32_to_cpu(vol_pg0.VolumeStatusFlags);
1594 if (volstate & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS) {
1595 state = RAID_STATE_RESYNCING;
1599 switch (vol_pg0.VolumeState) {
1600 case MPI2_RAID_VOL_STATE_OPTIMAL:
1601 case MPI2_RAID_VOL_STATE_ONLINE:
1602 state = RAID_STATE_ACTIVE;
1604 case MPI2_RAID_VOL_STATE_DEGRADED:
1605 state = RAID_STATE_DEGRADED;
1607 case MPI2_RAID_VOL_STATE_FAILED:
1608 case MPI2_RAID_VOL_STATE_MISSING:
1609 state = RAID_STATE_OFFLINE;
1613 raid_set_state(mpt2sas_raid_template, dev, state);
1617 * _scsih_set_level - set raid level
1618 * @sdev: scsi device struct
1619 * @raid_device: raid_device object
1622 _scsih_set_level(struct scsi_device *sdev, struct _raid_device *raid_device)
1624 enum raid_level level = RAID_LEVEL_UNKNOWN;
1626 switch (raid_device->volume_type) {
1627 case MPI2_RAID_VOL_TYPE_RAID0:
1628 level = RAID_LEVEL_0;
1630 case MPI2_RAID_VOL_TYPE_RAID10:
1631 level = RAID_LEVEL_10;
1633 case MPI2_RAID_VOL_TYPE_RAID1E:
1634 level = RAID_LEVEL_1E;
1636 case MPI2_RAID_VOL_TYPE_RAID1:
1637 level = RAID_LEVEL_1;
1641 raid_set_level(mpt2sas_raid_template, &sdev->sdev_gendev, level);
1645 * _scsih_get_volume_capabilities - volume capabilities
1646 * @ioc: per adapter object
1647 * @sas_device: the raid_device object
1649 * Returns 0 for success, else 1
1652 _scsih_get_volume_capabilities(struct MPT2SAS_ADAPTER *ioc,
1653 struct _raid_device *raid_device)
1655 Mpi2RaidVolPage0_t *vol_pg0;
1656 Mpi2RaidPhysDiskPage0_t pd_pg0;
1657 Mpi2SasDevicePage0_t sas_device_pg0;
1658 Mpi2ConfigReply_t mpi_reply;
1662 if ((mpt2sas_config_get_number_pds(ioc, raid_device->handle,
1663 &num_pds)) || !num_pds) {
1664 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
1665 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1670 raid_device->num_pds = num_pds;
1671 sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
1672 sizeof(Mpi2RaidVol0PhysDisk_t));
1673 vol_pg0 = kzalloc(sz, GFP_KERNEL);
1675 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
1676 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1681 if ((mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
1682 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
1683 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
1684 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1690 raid_device->volume_type = vol_pg0->VolumeType;
1692 /* figure out what the underlying devices are by
1693 * obtaining the device_info bits for the 1st device
1695 if (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
1696 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
1697 vol_pg0->PhysDisk[0].PhysDiskNum))) {
1698 if (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
1699 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
1700 le16_to_cpu(pd_pg0.DevHandle)))) {
1701 raid_device->device_info =
1702 le32_to_cpu(sas_device_pg0.DeviceInfo);
1710 * _scsih_disable_ddio - Disable direct I/O for all the volumes
1711 * @ioc: per adapter object
1714 _scsih_disable_ddio(struct MPT2SAS_ADAPTER *ioc)
1716 Mpi2RaidVolPage1_t vol_pg1;
1717 Mpi2ConfigReply_t mpi_reply;
1718 struct _raid_device *raid_device;
1723 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
1724 &vol_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
1725 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1726 MPI2_IOCSTATUS_MASK;
1727 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
1729 handle = le16_to_cpu(vol_pg1.DevHandle);
1730 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
1732 raid_device->direct_io_enabled = 0;
1739 * _scsih_get_num_volumes - Get number of volumes in the ioc
1740 * @ioc: per adapter object
1743 _scsih_get_num_volumes(struct MPT2SAS_ADAPTER *ioc)
1745 Mpi2RaidVolPage1_t vol_pg1;
1746 Mpi2ConfigReply_t mpi_reply;
1752 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
1753 &vol_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
1754 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1755 MPI2_IOCSTATUS_MASK;
1756 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
1759 handle = le16_to_cpu(vol_pg1.DevHandle);
1766 * _scsih_init_warpdrive_properties - Set properties for warpdrive direct I/O.
1767 * @ioc: per adapter object
1768 * @raid_device: the raid_device object
1771 _scsih_init_warpdrive_properties(struct MPT2SAS_ADAPTER *ioc,
1772 struct _raid_device *raid_device)
1774 Mpi2RaidVolPage0_t *vol_pg0;
1775 Mpi2RaidPhysDiskPage0_t pd_pg0;
1776 Mpi2ConfigReply_t mpi_reply;
1779 u64 mb = 1024 * 1024;
1780 u64 tb_2 = 2 * mb * mb;
1785 if (!ioc->is_warpdrive)
1788 if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS) {
1789 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1790 "globally as drives are exposed\n", ioc->name);
1793 if (_scsih_get_num_volumes(ioc) > 1) {
1794 _scsih_disable_ddio(ioc);
1795 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1796 "globally as number of drives > 1\n", ioc->name);
1799 if ((mpt2sas_config_get_number_pds(ioc, raid_device->handle,
1800 &num_pds)) || !num_pds) {
1801 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1802 "Failure in computing number of drives\n", ioc->name);
1806 sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
1807 sizeof(Mpi2RaidVol0PhysDisk_t));
1808 vol_pg0 = kzalloc(sz, GFP_KERNEL);
1810 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1811 "Memory allocation failure for RVPG0\n", ioc->name);
1815 if ((mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
1816 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
1817 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1818 "Failure in retrieving RVPG0\n", ioc->name);
1824 * WARPDRIVE:If number of physical disks in a volume exceeds the max pds
1825 * assumed for WARPDRIVE, disable direct I/O
1827 if (num_pds > MPT_MAX_WARPDRIVE_PDS) {
1828 printk(MPT2SAS_WARN_FMT "WarpDrive : Direct IO is disabled "
1829 "for the drive with handle(0x%04x): num_mem=%d, "
1830 "max_mem_allowed=%d\n", ioc->name, raid_device->handle,
1831 num_pds, MPT_MAX_WARPDRIVE_PDS);
1835 for (count = 0; count < num_pds; count++) {
1836 if (mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
1837 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
1838 vol_pg0->PhysDisk[count].PhysDiskNum) ||
1839 pd_pg0.DevHandle == MPT2SAS_INVALID_DEVICE_HANDLE) {
1840 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is "
1841 "disabled for the drive with handle(0x%04x) member"
1842 "handle retrieval failed for member number=%d\n",
1843 ioc->name, raid_device->handle,
1844 vol_pg0->PhysDisk[count].PhysDiskNum);
1847 raid_device->pd_handle[count] = le16_to_cpu(pd_pg0.DevHandle);
1851 * Assumption for WD: Direct I/O is not supported if the volume is
1852 * not RAID0, if the stripe size is not 64KB, if the block size is
1853 * not 512 and if the volume size is >2TB
1855 if (raid_device->volume_type != MPI2_RAID_VOL_TYPE_RAID0 ||
1856 le16_to_cpu(vol_pg0->BlockSize) != 512) {
1857 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1858 "for the drive with handle(0x%04x): type=%d, "
1859 "s_sz=%uK, blk_size=%u\n", ioc->name,
1860 raid_device->handle, raid_device->volume_type,
1861 le32_to_cpu(vol_pg0->StripeSize)/2,
1862 le16_to_cpu(vol_pg0->BlockSize));
1866 capacity = (u64) le16_to_cpu(vol_pg0->BlockSize) *
1867 (le64_to_cpu(vol_pg0->MaxLBA) + 1);
1869 if (capacity > tb_2) {
1870 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1871 "for the drive with handle(0x%04x) since drive sz > 2TB\n",
1872 ioc->name, raid_device->handle);
1876 stripe_sz = le32_to_cpu(vol_pg0->StripeSize);
1878 for (i = 0; i < 32; i++) {
1885 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1886 "for the drive with handle(0x%04x) invalid stripe sz %uK\n",
1887 ioc->name, raid_device->handle,
1888 le32_to_cpu(vol_pg0->StripeSize)/2);
1891 raid_device->stripe_exponent = stripe_exp;
1892 raid_device->direct_io_enabled = 1;
1894 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is Enabled for the drive"
1895 " with handle(0x%04x)\n", ioc->name, raid_device->handle);
1897 * WARPDRIVE: Though the following fields are not used for direct IO,
1898 * stored for future purpose:
1900 raid_device->max_lba = le64_to_cpu(vol_pg0->MaxLBA);
1901 raid_device->stripe_sz = le32_to_cpu(vol_pg0->StripeSize);
1902 raid_device->block_sz = le16_to_cpu(vol_pg0->BlockSize);
1909 raid_device->direct_io_enabled = 0;
1910 for (count = 0; count < num_pds; count++)
1911 raid_device->pd_handle[count] = 0;
1917 * _scsih_enable_tlr - setting TLR flags
1918 * @ioc: per adapter object
1919 * @sdev: scsi device struct
1921 * Enabling Transaction Layer Retries for tape devices when
1922 * vpd page 0x90 is present
1926 _scsih_enable_tlr(struct MPT2SAS_ADAPTER *ioc, struct scsi_device *sdev)
1929 if (sdev->type != TYPE_TAPE)
1932 if (!(ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR))
1935 sas_enable_tlr(sdev);
1936 sdev_printk(KERN_INFO, sdev, "TLR %s\n",
1937 sas_is_tlr_enabled(sdev) ? "Enabled" : "Disabled");
1943 * _scsih_slave_configure - device configure routine.
1944 * @sdev: scsi device struct
1946 * Returns 0 if ok. Any other return is assumed to be an error and
1947 * the device is ignored.
1950 _scsih_slave_configure(struct scsi_device *sdev)
1952 struct Scsi_Host *shost = sdev->host;
1953 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1954 struct MPT2SAS_DEVICE *sas_device_priv_data;
1955 struct MPT2SAS_TARGET *sas_target_priv_data;
1956 struct _sas_device *sas_device;
1957 struct _raid_device *raid_device;
1958 unsigned long flags;
1965 sas_device_priv_data = sdev->hostdata;
1966 sas_device_priv_data->configured_lun = 1;
1967 sas_device_priv_data->flags &= ~MPT_DEVICE_FLAGS_INIT;
1968 sas_target_priv_data = sas_device_priv_data->sas_target;
1970 /* raid volume handling */
1971 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME) {
1973 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1974 raid_device = _scsih_raid_device_find_by_handle(ioc,
1975 sas_target_priv_data->handle);
1976 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1978 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
1979 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
1980 __LINE__, __func__));
1984 _scsih_get_volume_capabilities(ioc, raid_device);
1986 if (_scsih_get_volume_capabilities(ioc, raid_device)) {
1987 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
1988 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
1989 __LINE__, __func__));
1993 * WARPDRIVE: Initialize the required data for Direct IO
1995 _scsih_init_warpdrive_properties(ioc, raid_device);
1997 /* RAID Queue Depth Support
1998 * IS volume = underlying qdepth of drive type, either
1999 * MPT2SAS_SAS_QUEUE_DEPTH or MPT2SAS_SATA_QUEUE_DEPTH
2000 * IM/IME/R10 = 128 (MPT2SAS_RAID_QUEUE_DEPTH)
2002 if (raid_device->device_info &
2003 MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
2004 qdepth = MPT2SAS_SAS_QUEUE_DEPTH;
2007 qdepth = MPT2SAS_SATA_QUEUE_DEPTH;
2008 if (raid_device->device_info &
2009 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
2015 switch (raid_device->volume_type) {
2016 case MPI2_RAID_VOL_TYPE_RAID0:
2019 case MPI2_RAID_VOL_TYPE_RAID1E:
2020 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
2021 if (ioc->manu_pg10.OEMIdentifier &&
2022 (le32_to_cpu(ioc->manu_pg10.GenericFlags0) &
2023 MFG10_GF0_R10_DISPLAY) &&
2024 !(raid_device->num_pds % 2))
2029 case MPI2_RAID_VOL_TYPE_RAID1:
2030 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
2033 case MPI2_RAID_VOL_TYPE_RAID10:
2034 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
2037 case MPI2_RAID_VOL_TYPE_UNKNOWN:
2039 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
2044 if (!ioc->hide_ir_msg)
2045 sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), "
2046 "wwid(0x%016llx), pd_count(%d), type(%s)\n",
2047 r_level, raid_device->handle,
2048 (unsigned long long)raid_device->wwid,
2049 raid_device->num_pds, ds);
2050 _scsih_change_queue_depth(sdev, qdepth, SCSI_QDEPTH_DEFAULT);
2051 /* raid transport support */
2052 if (!ioc->is_warpdrive)
2053 _scsih_set_level(sdev, raid_device);
2057 /* non-raid handling */
2058 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2059 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
2060 sas_device_priv_data->sas_target->sas_address);
2061 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2063 if (sas_target_priv_data->flags &
2064 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2065 if (mpt2sas_config_get_volume_handle(ioc,
2066 sas_device->handle, &sas_device->volume_handle)) {
2067 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
2068 "failure at %s:%d/%s()!\n", ioc->name,
2069 __FILE__, __LINE__, __func__));
2072 if (sas_device->volume_handle &&
2073 mpt2sas_config_get_volume_wwid(ioc,
2074 sas_device->volume_handle,
2075 &sas_device->volume_wwid)) {
2076 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
2077 "failure at %s:%d/%s()!\n", ioc->name,
2078 __FILE__, __LINE__, __func__));
2082 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
2083 qdepth = MPT2SAS_SAS_QUEUE_DEPTH;
2087 qdepth = MPT2SAS_SATA_QUEUE_DEPTH;
2088 if (sas_device->device_info &
2089 MPI2_SAS_DEVICE_INFO_STP_TARGET)
2091 else if (sas_device->device_info &
2092 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
2096 sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), "
2097 "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n",
2098 ds, sas_device->handle,
2099 (unsigned long long)sas_device->sas_address,
2101 (unsigned long long)sas_device->device_name);
2102 sdev_printk(KERN_INFO, sdev, "%s: "
2103 "enclosure_logical_id(0x%016llx), slot(%d)\n", ds,
2104 (unsigned long long) sas_device->enclosure_logical_id,
2108 _scsih_display_sata_capabilities(ioc, sas_device, sdev);
2110 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
2111 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
2116 _scsih_change_queue_depth(sdev, qdepth, SCSI_QDEPTH_DEFAULT);
2119 sas_read_port_mode_page(sdev);
2120 _scsih_enable_tlr(ioc, sdev);
2126 * _scsih_bios_param - fetch head, sector, cylinder info for a disk
2127 * @sdev: scsi device struct
2128 * @bdev: pointer to block device context
2129 * @capacity: device size (in 512 byte sectors)
2130 * @params: three element array to place output:
2131 * params[0] number of heads (max 255)
2132 * params[1] number of sectors (max 63)
2133 * params[2] number of cylinders
2138 _scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev,
2139 sector_t capacity, int params[])
2149 dummy = heads * sectors;
2150 cylinders = capacity;
2151 sector_div(cylinders, dummy);
2154 * Handle extended translation size for logical drives
2157 if ((ulong)capacity >= 0x200000) {
2160 dummy = heads * sectors;
2161 cylinders = capacity;
2162 sector_div(cylinders, dummy);
2167 params[1] = sectors;
2168 params[2] = cylinders;
2174 * _scsih_response_code - translation of device response code
2175 * @ioc: per adapter object
2176 * @response_code: response code returned by the device
2181 _scsih_response_code(struct MPT2SAS_ADAPTER *ioc, u8 response_code)
2185 switch (response_code) {
2186 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE:
2187 desc = "task management request completed";
2189 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME:
2190 desc = "invalid frame";
2192 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED:
2193 desc = "task management request not supported";
2195 case MPI2_SCSITASKMGMT_RSP_TM_FAILED:
2196 desc = "task management request failed";
2198 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED:
2199 desc = "task management request succeeded";
2201 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN:
2202 desc = "invalid lun";
2205 desc = "overlapped tag attempted";
2207 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC:
2208 desc = "task queued, however not sent to target";
2214 printk(MPT2SAS_WARN_FMT "response_code(0x%01x): %s\n",
2215 ioc->name, response_code, desc);
2219 * _scsih_tm_done - tm completion routine
2220 * @ioc: per adapter object
2221 * @smid: system request message index
2222 * @msix_index: MSIX table index supplied by the OS
2223 * @reply: reply message frame(lower 32bit addr)
2226 * The callback handler when using scsih_issue_tm.
2228 * Return 1 meaning mf should be freed from _base_interrupt
2229 * 0 means the mf is freed from this function.
2232 _scsih_tm_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
2234 MPI2DefaultReply_t *mpi_reply;
2236 if (ioc->tm_cmds.status == MPT2_CMD_NOT_USED)
2238 if (ioc->tm_cmds.smid != smid)
2240 mpt2sas_base_flush_reply_queues(ioc);
2241 ioc->tm_cmds.status |= MPT2_CMD_COMPLETE;
2242 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
2244 memcpy(ioc->tm_cmds.reply, mpi_reply, mpi_reply->MsgLength*4);
2245 ioc->tm_cmds.status |= MPT2_CMD_REPLY_VALID;
2247 ioc->tm_cmds.status &= ~MPT2_CMD_PENDING;
2248 complete(&ioc->tm_cmds.done);
2253 * mpt2sas_scsih_set_tm_flag - set per target tm_busy
2254 * @ioc: per adapter object
2255 * @handle: device handle
2257 * During taskmangement request, we need to freeze the device queue.
2260 mpt2sas_scsih_set_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2262 struct MPT2SAS_DEVICE *sas_device_priv_data;
2263 struct scsi_device *sdev;
2266 shost_for_each_device(sdev, ioc->shost) {
2269 sas_device_priv_data = sdev->hostdata;
2270 if (!sas_device_priv_data)
2272 if (sas_device_priv_data->sas_target->handle == handle) {
2273 sas_device_priv_data->sas_target->tm_busy = 1;
2275 ioc->ignore_loginfos = 1;
2281 * mpt2sas_scsih_clear_tm_flag - clear per target tm_busy
2282 * @ioc: per adapter object
2283 * @handle: device handle
2285 * During taskmangement request, we need to freeze the device queue.
2288 mpt2sas_scsih_clear_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2290 struct MPT2SAS_DEVICE *sas_device_priv_data;
2291 struct scsi_device *sdev;
2294 shost_for_each_device(sdev, ioc->shost) {
2297 sas_device_priv_data = sdev->hostdata;
2298 if (!sas_device_priv_data)
2300 if (sas_device_priv_data->sas_target->handle == handle) {
2301 sas_device_priv_data->sas_target->tm_busy = 0;
2303 ioc->ignore_loginfos = 0;
2310 * mpt2sas_scsih_issue_tm - main routine for sending tm requests
2311 * @ioc: per adapter struct
2312 * @device_handle: device handle
2313 * @channel: the channel assigned by the OS
2314 * @id: the id assigned by the OS
2316 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
2317 * @smid_task: smid assigned to the task
2318 * @timeout: timeout in seconds
2319 * @serial_number: the serial_number from scmd
2320 * @m_type: TM_MUTEX_ON or TM_MUTEX_OFF
2323 * A generic API for sending task management requests to firmware.
2325 * The callback index is set inside `ioc->tm_cb_idx`.
2327 * Return SUCCESS or FAILED.
2330 mpt2sas_scsih_issue_tm(struct MPT2SAS_ADAPTER *ioc, u16 handle, uint channel,
2331 uint id, uint lun, u8 type, u16 smid_task, ulong timeout,
2332 unsigned long serial_number, enum mutex_type m_type)
2334 Mpi2SCSITaskManagementRequest_t *mpi_request;
2335 Mpi2SCSITaskManagementReply_t *mpi_reply;
2338 unsigned long timeleft;
2339 struct scsiio_tracker *scsi_lookup = NULL;
2342 if (m_type == TM_MUTEX_ON)
2343 mutex_lock(&ioc->tm_cmds.mutex);
2344 if (ioc->tm_cmds.status != MPT2_CMD_NOT_USED) {
2345 printk(MPT2SAS_INFO_FMT "%s: tm_cmd busy!!!\n",
2346 __func__, ioc->name);
2351 if (ioc->shost_recovery || ioc->remove_host ||
2352 ioc->pci_error_recovery) {
2353 printk(MPT2SAS_INFO_FMT "%s: host reset in progress!\n",
2354 __func__, ioc->name);
2359 ioc_state = mpt2sas_base_get_iocstate(ioc, 0);
2360 if (ioc_state & MPI2_DOORBELL_USED) {
2361 dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "unexpected doorbell "
2362 "active!\n", ioc->name));
2363 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2365 rc = (!rc) ? SUCCESS : FAILED;
2369 if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) {
2370 mpt2sas_base_fault_info(ioc, ioc_state &
2371 MPI2_DOORBELL_DATA_MASK);
2372 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2374 rc = (!rc) ? SUCCESS : FAILED;
2378 smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_cb_idx);
2380 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
2381 ioc->name, __func__);
2386 if (type == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK)
2387 scsi_lookup = &ioc->scsi_lookup[smid_task - 1];
2389 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "sending tm: handle(0x%04x),"
2390 " task_type(0x%02x), smid(%d)\n", ioc->name, handle, type,
2392 ioc->tm_cmds.status = MPT2_CMD_PENDING;
2393 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
2394 ioc->tm_cmds.smid = smid;
2395 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
2396 memset(ioc->tm_cmds.reply, 0, sizeof(Mpi2SCSITaskManagementReply_t));
2397 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
2398 mpi_request->DevHandle = cpu_to_le16(handle);
2399 mpi_request->TaskType = type;
2400 mpi_request->TaskMID = cpu_to_le16(smid_task);
2401 int_to_scsilun(lun, (struct scsi_lun *)mpi_request->LUN);
2402 mpt2sas_scsih_set_tm_flag(ioc, handle);
2403 init_completion(&ioc->tm_cmds.done);
2404 mpt2sas_base_put_smid_hi_priority(ioc, smid);
2405 timeleft = wait_for_completion_timeout(&ioc->tm_cmds.done, timeout*HZ);
2406 if (!(ioc->tm_cmds.status & MPT2_CMD_COMPLETE)) {
2407 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
2408 ioc->name, __func__);
2409 _debug_dump_mf(mpi_request,
2410 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
2411 if (!(ioc->tm_cmds.status & MPT2_CMD_RESET)) {
2412 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2414 rc = (!rc) ? SUCCESS : FAILED;
2415 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
2416 mpt2sas_scsih_clear_tm_flag(ioc, handle);
2421 if (ioc->tm_cmds.status & MPT2_CMD_REPLY_VALID) {
2422 mpi_reply = ioc->tm_cmds.reply;
2423 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "complete tm: "
2424 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
2425 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
2426 le32_to_cpu(mpi_reply->IOCLogInfo),
2427 le32_to_cpu(mpi_reply->TerminationCount)));
2428 if (ioc->logging_level & MPT_DEBUG_TM) {
2429 _scsih_response_code(ioc, mpi_reply->ResponseCode);
2430 if (mpi_reply->IOCStatus)
2431 _debug_dump_mf(mpi_request,
2432 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
2437 case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK:
2439 if (scsi_lookup->scmd == NULL)
2444 case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET:
2445 if (_scsih_scsi_lookup_find_by_target(ioc, id, channel))
2451 case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET:
2452 case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET:
2453 if (_scsih_scsi_lookup_find_by_lun(ioc, id, lun, channel))
2458 case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK:
2466 mpt2sas_scsih_clear_tm_flag(ioc, handle);
2467 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
2468 if (m_type == TM_MUTEX_ON)
2469 mutex_unlock(&ioc->tm_cmds.mutex);
2474 if (m_type == TM_MUTEX_ON)
2475 mutex_unlock(&ioc->tm_cmds.mutex);
2480 * _scsih_tm_display_info - displays info about the device
2481 * @ioc: per adapter struct
2482 * @scmd: pointer to scsi command object
2484 * Called by task management callback handlers.
2487 _scsih_tm_display_info(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd)
2489 struct scsi_target *starget = scmd->device->sdev_target;
2490 struct MPT2SAS_TARGET *priv_target = starget->hostdata;
2491 struct _sas_device *sas_device = NULL;
2492 unsigned long flags;
2493 char *device_str = NULL;
2497 if (ioc->hide_ir_msg)
2498 device_str = "WarpDrive";
2500 device_str = "volume";
2502 scsi_print_command(scmd);
2503 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
2504 starget_printk(KERN_INFO, starget, "%s handle(0x%04x), "
2505 "%s wwid(0x%016llx)\n", device_str, priv_target->handle,
2506 device_str, (unsigned long long)priv_target->sas_address);
2508 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2509 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
2510 priv_target->sas_address);
2512 if (priv_target->flags &
2513 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2514 starget_printk(KERN_INFO, starget,
2515 "volume handle(0x%04x), "
2516 "volume wwid(0x%016llx)\n",
2517 sas_device->volume_handle,
2518 (unsigned long long)sas_device->volume_wwid);
2520 starget_printk(KERN_INFO, starget,
2521 "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n",
2523 (unsigned long long)sas_device->sas_address,
2525 starget_printk(KERN_INFO, starget,
2526 "enclosure_logical_id(0x%016llx), slot(%d)\n",
2527 (unsigned long long)sas_device->enclosure_logical_id,
2530 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2535 * _scsih_abort - eh threads main abort routine
2536 * @scmd: pointer to scsi command object
2538 * Returns SUCCESS if command aborted else FAILED
2541 _scsih_abort(struct scsi_cmnd *scmd)
2543 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2544 struct MPT2SAS_DEVICE *sas_device_priv_data;
2549 sdev_printk(KERN_INFO, scmd->device, "attempting task abort! "
2550 "scmd(%p)\n", scmd);
2551 _scsih_tm_display_info(ioc, scmd);
2553 sas_device_priv_data = scmd->device->hostdata;
2554 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2555 sdev_printk(KERN_INFO, scmd->device, "device been deleted! "
2556 "scmd(%p)\n", scmd);
2557 scmd->result = DID_NO_CONNECT << 16;
2558 scmd->scsi_done(scmd);
2563 /* search for the command */
2564 smid = _scsih_scsi_lookup_find_by_scmd(ioc, scmd);
2566 scmd->result = DID_RESET << 16;
2571 /* for hidden raid components and volumes this is not supported */
2572 if (sas_device_priv_data->sas_target->flags &
2573 MPT_TARGET_FLAGS_RAID_COMPONENT ||
2574 sas_device_priv_data->sas_target->flags & MPT_TARGET_FLAGS_VOLUME) {
2575 scmd->result = DID_RESET << 16;
2580 mpt2sas_halt_firmware(ioc);
2582 handle = sas_device_priv_data->sas_target->handle;
2583 r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2584 scmd->device->id, scmd->device->lun,
2585 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30,
2586 scmd->serial_number, TM_MUTEX_ON);
2589 sdev_printk(KERN_INFO, scmd->device, "task abort: %s scmd(%p)\n",
2590 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2595 * _scsih_dev_reset - eh threads main device reset routine
2596 * @scmd: pointer to scsi command object
2598 * Returns SUCCESS if command aborted else FAILED
2601 _scsih_dev_reset(struct scsi_cmnd *scmd)
2603 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2604 struct MPT2SAS_DEVICE *sas_device_priv_data;
2605 struct _sas_device *sas_device;
2606 unsigned long flags;
2610 struct scsi_target *starget = scmd->device->sdev_target;
2612 starget_printk(KERN_INFO, starget, "attempting device reset! "
2613 "scmd(%p)\n", scmd);
2614 _scsih_tm_display_info(ioc, scmd);
2616 sas_device_priv_data = scmd->device->hostdata;
2617 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2618 starget_printk(KERN_INFO, starget, "device been deleted! "
2619 "scmd(%p)\n", scmd);
2620 scmd->result = DID_NO_CONNECT << 16;
2621 scmd->scsi_done(scmd);
2626 /* for hidden raid components obtain the volume_handle */
2628 if (sas_device_priv_data->sas_target->flags &
2629 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2630 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2631 sas_device = _scsih_sas_device_find_by_handle(ioc,
2632 sas_device_priv_data->sas_target->handle);
2634 handle = sas_device->volume_handle;
2635 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2637 handle = sas_device_priv_data->sas_target->handle;
2640 scmd->result = DID_RESET << 16;
2645 r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2646 scmd->device->id, scmd->device->lun,
2647 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, 0, 30, 0,
2651 sdev_printk(KERN_INFO, scmd->device, "device reset: %s scmd(%p)\n",
2652 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2657 * _scsih_target_reset - eh threads main target reset routine
2658 * @scmd: pointer to scsi command object
2660 * Returns SUCCESS if command aborted else FAILED
2663 _scsih_target_reset(struct scsi_cmnd *scmd)
2665 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2666 struct MPT2SAS_DEVICE *sas_device_priv_data;
2667 struct _sas_device *sas_device;
2668 unsigned long flags;
2671 struct scsi_target *starget = scmd->device->sdev_target;
2673 starget_printk(KERN_INFO, starget, "attempting target reset! "
2674 "scmd(%p)\n", scmd);
2675 _scsih_tm_display_info(ioc, scmd);
2677 sas_device_priv_data = scmd->device->hostdata;
2678 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2679 starget_printk(KERN_INFO, starget, "target been deleted! "
2680 "scmd(%p)\n", scmd);
2681 scmd->result = DID_NO_CONNECT << 16;
2682 scmd->scsi_done(scmd);
2687 /* for hidden raid components obtain the volume_handle */
2689 if (sas_device_priv_data->sas_target->flags &
2690 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2691 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2692 sas_device = _scsih_sas_device_find_by_handle(ioc,
2693 sas_device_priv_data->sas_target->handle);
2695 handle = sas_device->volume_handle;
2696 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2698 handle = sas_device_priv_data->sas_target->handle;
2701 scmd->result = DID_RESET << 16;
2706 r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2707 scmd->device->id, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0,
2708 30, 0, TM_MUTEX_ON);
2711 starget_printk(KERN_INFO, starget, "target reset: %s scmd(%p)\n",
2712 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2717 * _scsih_host_reset - eh threads main host reset routine
2718 * @scmd: pointer to scsi command object
2720 * Returns SUCCESS if command aborted else FAILED
2723 _scsih_host_reset(struct scsi_cmnd *scmd)
2725 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2728 printk(MPT2SAS_INFO_FMT "attempting host reset! scmd(%p)\n",
2730 scsi_print_command(scmd);
2732 retval = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2734 r = (retval < 0) ? FAILED : SUCCESS;
2735 printk(MPT2SAS_INFO_FMT "host reset: %s scmd(%p)\n",
2736 ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2742 * _scsih_fw_event_add - insert and queue up fw_event
2743 * @ioc: per adapter object
2744 * @fw_event: object describing the event
2745 * Context: This function will acquire ioc->fw_event_lock.
2747 * This adds the firmware event object into link list, then queues it up to
2748 * be processed from user context.
2753 _scsih_fw_event_add(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
2755 unsigned long flags;
2757 if (ioc->firmware_event_thread == NULL)
2760 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2761 list_add_tail(&fw_event->list, &ioc->fw_event_list);
2762 INIT_DELAYED_WORK(&fw_event->delayed_work, _firmware_event_work);
2763 queue_delayed_work(ioc->firmware_event_thread,
2764 &fw_event->delayed_work, 0);
2765 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2769 * _scsih_fw_event_free - delete fw_event
2770 * @ioc: per adapter object
2771 * @fw_event: object describing the event
2772 * Context: This function will acquire ioc->fw_event_lock.
2774 * This removes firmware event object from link list, frees associated memory.
2779 _scsih_fw_event_free(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work
2782 unsigned long flags;
2784 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2785 list_del(&fw_event->list);
2786 kfree(fw_event->event_data);
2788 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2793 * _scsih_error_recovery_delete_devices - remove devices not responding
2794 * @ioc: per adapter object
2799 _scsih_error_recovery_delete_devices(struct MPT2SAS_ADAPTER *ioc)
2801 struct fw_event_work *fw_event;
2803 if (ioc->is_driver_loading)
2806 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
2810 fw_event->event = MPT2SAS_REMOVE_UNRESPONDING_DEVICES;
2811 fw_event->ioc = ioc;
2812 _scsih_fw_event_add(ioc, fw_event);
2816 * mpt2sas_port_enable_complete - port enable completed (fake event)
2817 * @ioc: per adapter object
2822 mpt2sas_port_enable_complete(struct MPT2SAS_ADAPTER *ioc)
2824 struct fw_event_work *fw_event;
2826 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
2829 fw_event->event = MPT2SAS_PORT_ENABLE_COMPLETE;
2830 fw_event->ioc = ioc;
2831 _scsih_fw_event_add(ioc, fw_event);
2835 * _scsih_fw_event_cleanup_queue - cleanup event queue
2836 * @ioc: per adapter object
2838 * Walk the firmware event queue, either killing timers, or waiting
2839 * for outstanding events to complete
2844 _scsih_fw_event_cleanup_queue(struct MPT2SAS_ADAPTER *ioc)
2846 struct fw_event_work *fw_event, *next;
2848 if (list_empty(&ioc->fw_event_list) ||
2849 !ioc->firmware_event_thread || in_interrupt())
2852 list_for_each_entry_safe(fw_event, next, &ioc->fw_event_list, list) {
2853 if (cancel_delayed_work(&fw_event->delayed_work)) {
2854 _scsih_fw_event_free(ioc, fw_event);
2857 fw_event->cancel_pending_work = 1;
2862 * _scsih_ublock_io_all_device - unblock every device
2863 * @ioc: per adapter object
2865 * change the device state from block to running
2868 _scsih_ublock_io_all_device(struct MPT2SAS_ADAPTER *ioc)
2870 struct MPT2SAS_DEVICE *sas_device_priv_data;
2871 struct scsi_device *sdev;
2873 shost_for_each_device(sdev, ioc->shost) {
2874 sas_device_priv_data = sdev->hostdata;
2875 if (!sas_device_priv_data)
2877 if (!sas_device_priv_data->block)
2879 sas_device_priv_data->block = 0;
2880 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, "device_running, "
2882 sas_device_priv_data->sas_target->handle));
2883 scsi_internal_device_unblock(sdev);
2887 * _scsih_ublock_io_device - set the device state to SDEV_RUNNING
2888 * @ioc: per adapter object
2889 * @handle: device handle
2891 * During device pull we need to appropiately set the sdev state.
2894 _scsih_ublock_io_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2896 struct MPT2SAS_DEVICE *sas_device_priv_data;
2897 struct scsi_device *sdev;
2899 shost_for_each_device(sdev, ioc->shost) {
2900 sas_device_priv_data = sdev->hostdata;
2901 if (!sas_device_priv_data)
2903 if (!sas_device_priv_data->block)
2905 if (sas_device_priv_data->sas_target->handle == handle) {
2906 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
2907 MPT2SAS_INFO_FMT "SDEV_RUNNING: "
2908 "handle(0x%04x)\n", ioc->name, handle));
2909 sas_device_priv_data->block = 0;
2910 scsi_internal_device_unblock(sdev);
2916 * _scsih_block_io_all_device - set the device state to SDEV_BLOCK
2917 * @ioc: per adapter object
2918 * @handle: device handle
2920 * During device pull we need to appropiately set the sdev state.
2923 _scsih_block_io_all_device(struct MPT2SAS_ADAPTER *ioc)
2925 struct MPT2SAS_DEVICE *sas_device_priv_data;
2926 struct scsi_device *sdev;
2928 shost_for_each_device(sdev, ioc->shost) {
2929 sas_device_priv_data = sdev->hostdata;
2930 if (!sas_device_priv_data)
2932 if (sas_device_priv_data->block)
2934 sas_device_priv_data->block = 1;
2935 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, "device_blocked, "
2937 sas_device_priv_data->sas_target->handle));
2938 scsi_internal_device_block(sdev);
2944 * _scsih_block_io_device - set the device state to SDEV_BLOCK
2945 * @ioc: per adapter object
2946 * @handle: device handle
2948 * During device pull we need to appropiately set the sdev state.
2951 _scsih_block_io_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2953 struct MPT2SAS_DEVICE *sas_device_priv_data;
2954 struct scsi_device *sdev;
2956 shost_for_each_device(sdev, ioc->shost) {
2957 sas_device_priv_data = sdev->hostdata;
2958 if (!sas_device_priv_data)
2960 if (sas_device_priv_data->block)
2962 if (sas_device_priv_data->sas_target->handle == handle) {
2963 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
2964 MPT2SAS_INFO_FMT "SDEV_BLOCK: "
2965 "handle(0x%04x)\n", ioc->name, handle));
2966 sas_device_priv_data->block = 1;
2967 scsi_internal_device_block(sdev);
2973 * _scsih_block_io_to_children_attached_to_ex
2974 * @ioc: per adapter object
2975 * @sas_expander: the sas_device object
2977 * This routine set sdev state to SDEV_BLOCK for all devices
2978 * attached to this expander. This function called when expander is
2982 _scsih_block_io_to_children_attached_to_ex(struct MPT2SAS_ADAPTER *ioc,
2983 struct _sas_node *sas_expander)
2985 struct _sas_port *mpt2sas_port;
2986 struct _sas_device *sas_device;
2987 struct _sas_node *expander_sibling;
2988 unsigned long flags;
2993 list_for_each_entry(mpt2sas_port,
2994 &sas_expander->sas_port_list, port_list) {
2995 if (mpt2sas_port->remote_identify.device_type ==
2997 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2999 mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
3000 mpt2sas_port->remote_identify.sas_address);
3001 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3004 _scsih_block_io_device(ioc, sas_device->handle);
3008 list_for_each_entry(mpt2sas_port,
3009 &sas_expander->sas_port_list, port_list) {
3011 if (mpt2sas_port->remote_identify.device_type ==
3012 SAS_EDGE_EXPANDER_DEVICE ||
3013 mpt2sas_port->remote_identify.device_type ==
3014 SAS_FANOUT_EXPANDER_DEVICE) {
3016 spin_lock_irqsave(&ioc->sas_node_lock, flags);
3018 mpt2sas_scsih_expander_find_by_sas_address(
3019 ioc, mpt2sas_port->remote_identify.sas_address);
3020 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
3021 _scsih_block_io_to_children_attached_to_ex(ioc,
3028 * _scsih_block_io_to_children_attached_directly
3029 * @ioc: per adapter object
3030 * @event_data: topology change event data
3032 * This routine set sdev state to SDEV_BLOCK for all devices
3033 * direct attached during device pull.
3036 _scsih_block_io_to_children_attached_directly(struct MPT2SAS_ADAPTER *ioc,
3037 Mpi2EventDataSasTopologyChangeList_t *event_data)
3044 for (i = 0; i < event_data->NumEntries; i++) {
3045 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
3048 phy_number = event_data->StartPhyNum + i;
3049 reason_code = event_data->PHY[i].PhyStatus &
3050 MPI2_EVENT_SAS_TOPO_RC_MASK;
3051 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING)
3052 _scsih_block_io_device(ioc, handle);
3057 * _scsih_tm_tr_send - send task management request
3058 * @ioc: per adapter object
3059 * @handle: device handle
3060 * Context: interrupt time.
3062 * This code is to initiate the device removal handshake protocol
3063 * with controller firmware. This function will issue target reset
3064 * using high priority request queue. It will send a sas iounit
3065 * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
3067 * This is designed to send muliple task management request at the same
3068 * time to the fifo. If the fifo is full, we will append the request,
3069 * and process it in a future completion.
3072 _scsih_tm_tr_send(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3074 Mpi2SCSITaskManagementRequest_t *mpi_request;
3076 struct _sas_device *sas_device;
3077 struct MPT2SAS_TARGET *sas_target_priv_data = NULL;
3078 u64 sas_address = 0;
3079 unsigned long flags;
3080 struct _tr_list *delayed_tr;
3083 if (ioc->remove_host) {
3084 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host has been "
3085 "removed: handle(0x%04x)\n", __func__, ioc->name, handle));
3087 } else if (ioc->pci_error_recovery) {
3088 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host in pci "
3089 "error recovery: handle(0x%04x)\n", __func__, ioc->name,
3093 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
3094 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3095 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host is not "
3096 "operational: handle(0x%04x)\n", __func__, ioc->name,
3101 /* if PD, then return */
3102 if (test_bit(handle, ioc->pd_handles))
3105 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3106 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
3107 if (sas_device && sas_device->starget &&
3108 sas_device->starget->hostdata) {
3109 sas_target_priv_data = sas_device->starget->hostdata;
3110 sas_target_priv_data->deleted = 1;
3111 sas_address = sas_device->sas_address;
3113 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3115 if (sas_target_priv_data) {
3116 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "setting delete flag: "
3117 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, handle,
3118 (unsigned long long)sas_address));
3119 _scsih_ublock_io_device(ioc, handle);
3120 sas_target_priv_data->handle = MPT2SAS_INVALID_DEVICE_HANDLE;
3123 smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_tr_cb_idx);
3125 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3128 INIT_LIST_HEAD(&delayed_tr->list);
3129 delayed_tr->handle = handle;
3130 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
3131 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3132 "DELAYED:tr:handle(0x%04x), (open)\n",
3133 ioc->name, handle));
3137 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "tr_send:handle(0x%04x), "
3138 "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid,
3139 ioc->tm_tr_cb_idx));
3140 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3141 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
3142 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3143 mpi_request->DevHandle = cpu_to_le16(handle);
3144 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
3145 mpt2sas_base_put_smid_hi_priority(ioc, smid);
3151 * _scsih_sas_control_complete - completion routine
3152 * @ioc: per adapter object
3153 * @smid: system request message index
3154 * @msix_index: MSIX table index supplied by the OS
3155 * @reply: reply message frame(lower 32bit addr)
3156 * Context: interrupt time.
3158 * This is the sas iounit control completion routine.
3159 * This code is part of the code to initiate the device removal
3160 * handshake protocol with controller firmware.
3162 * Return 1 meaning mf should be freed from _base_interrupt
3163 * 0 means the mf is freed from this function.
3166 _scsih_sas_control_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid,
3167 u8 msix_index, u32 reply)
3169 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3170 Mpi2SasIoUnitControlReply_t *mpi_reply =
3171 mpt2sas_base_get_reply_virt_addr(ioc, reply);
3173 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3174 "sc_complete:handle(0x%04x), (open) "
3175 "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
3176 ioc->name, le16_to_cpu(mpi_reply->DevHandle), smid,
3177 le16_to_cpu(mpi_reply->IOCStatus),
3178 le32_to_cpu(mpi_reply->IOCLogInfo)));
3183 * _scsih_tm_tr_volume_send - send target reset request for volumes
3184 * @ioc: per adapter object
3185 * @handle: device handle
3186 * Context: interrupt time.
3188 * This is designed to send muliple task management request at the same
3189 * time to the fifo. If the fifo is full, we will append the request,
3190 * and process it in a future completion.
3193 _scsih_tm_tr_volume_send(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3195 Mpi2SCSITaskManagementRequest_t *mpi_request;
3197 struct _tr_list *delayed_tr;
3199 if (ioc->shost_recovery || ioc->remove_host ||
3200 ioc->pci_error_recovery) {
3201 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in "
3202 "progress!\n", __func__, ioc->name));
3206 smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_tr_volume_cb_idx);
3208 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3211 INIT_LIST_HEAD(&delayed_tr->list);
3212 delayed_tr->handle = handle;
3213 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_volume_list);
3214 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3215 "DELAYED:tr:handle(0x%04x), (open)\n",
3216 ioc->name, handle));
3220 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "tr_send:handle(0x%04x), "
3221 "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid,
3222 ioc->tm_tr_volume_cb_idx));
3223 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3224 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
3225 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3226 mpi_request->DevHandle = cpu_to_le16(handle);
3227 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
3228 mpt2sas_base_put_smid_hi_priority(ioc, smid);
3232 * _scsih_tm_volume_tr_complete - target reset completion
3233 * @ioc: per adapter object
3234 * @smid: system request message index
3235 * @msix_index: MSIX table index supplied by the OS
3236 * @reply: reply message frame(lower 32bit addr)
3237 * Context: interrupt time.
3239 * Return 1 meaning mf should be freed from _base_interrupt
3240 * 0 means the mf is freed from this function.
3243 _scsih_tm_volume_tr_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid,
3244 u8 msix_index, u32 reply)
3247 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
3248 Mpi2SCSITaskManagementReply_t *mpi_reply =
3249 mpt2sas_base_get_reply_virt_addr(ioc, reply);
3251 if (ioc->shost_recovery || ioc->remove_host ||
3252 ioc->pci_error_recovery) {
3253 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in "
3254 "progress!\n", __func__, ioc->name));
3258 mpi_request_tm = mpt2sas_base_get_msg_frame(ioc, smid);
3259 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3260 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3261 dewtprintk(ioc, printk("spurious interrupt: "
3262 "handle(0x%04x:0x%04x), smid(%d)!!!\n", handle,
3263 le16_to_cpu(mpi_reply->DevHandle), smid));
3267 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3268 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3269 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3270 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3271 le32_to_cpu(mpi_reply->IOCLogInfo),
3272 le32_to_cpu(mpi_reply->TerminationCount)));
3274 return _scsih_check_for_pending_tm(ioc, smid);
3278 * _scsih_tm_tr_complete -
3279 * @ioc: per adapter object
3280 * @smid: system request message index
3281 * @msix_index: MSIX table index supplied by the OS
3282 * @reply: reply message frame(lower 32bit addr)
3283 * Context: interrupt time.
3285 * This is the target reset completion routine.
3286 * This code is part of the code to initiate the device removal
3287 * handshake protocol with controller firmware.
3288 * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE)
3290 * Return 1 meaning mf should be freed from _base_interrupt
3291 * 0 means the mf is freed from this function.
3294 _scsih_tm_tr_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
3298 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
3299 Mpi2SCSITaskManagementReply_t *mpi_reply =
3300 mpt2sas_base_get_reply_virt_addr(ioc, reply);
3301 Mpi2SasIoUnitControlRequest_t *mpi_request;
3305 if (ioc->remove_host) {
3306 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host has been "
3307 "removed\n", __func__, ioc->name));
3309 } else if (ioc->pci_error_recovery) {
3310 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host in pci "
3311 "error recovery\n", __func__, ioc->name));
3314 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
3315 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3316 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host is not "
3317 "operational\n", __func__, ioc->name));
3321 mpi_request_tm = mpt2sas_base_get_msg_frame(ioc, smid);
3322 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3323 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3324 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "spurious interrupt: "
3325 "handle(0x%04x:0x%04x), smid(%d)!!!\n", ioc->name, handle,
3326 le16_to_cpu(mpi_reply->DevHandle), smid));
3330 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3331 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3332 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3333 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3334 le32_to_cpu(mpi_reply->IOCLogInfo),
3335 le32_to_cpu(mpi_reply->TerminationCount)));
3337 smid_sas_ctrl = mpt2sas_base_get_smid(ioc, ioc->tm_sas_control_cb_idx);
3338 if (!smid_sas_ctrl) {
3339 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3340 ioc->name, __func__);
3344 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "sc_send:handle(0x%04x), "
3345 "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid_sas_ctrl,
3346 ioc->tm_sas_control_cb_idx));
3347 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid_sas_ctrl);
3348 memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t));
3349 mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL;
3350 mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE;
3351 mpi_request->DevHandle = mpi_request_tm->DevHandle;
3352 mpt2sas_base_put_smid_default(ioc, smid_sas_ctrl);
3354 return _scsih_check_for_pending_tm(ioc, smid);
3358 * _scsih_check_for_pending_tm - check for pending task management
3359 * @ioc: per adapter object
3360 * @smid: system request message index
3362 * This will check delayed target reset list, and feed the
3365 * Return 1 meaning mf should be freed from _base_interrupt
3366 * 0 means the mf is freed from this function.
3369 _scsih_check_for_pending_tm(struct MPT2SAS_ADAPTER *ioc, u16 smid)
3371 struct _tr_list *delayed_tr;
3373 if (!list_empty(&ioc->delayed_tr_volume_list)) {
3374 delayed_tr = list_entry(ioc->delayed_tr_volume_list.next,
3375 struct _tr_list, list);
3376 mpt2sas_base_free_smid(ioc, smid);
3377 _scsih_tm_tr_volume_send(ioc, delayed_tr->handle);
3378 list_del(&delayed_tr->list);
3383 if (!list_empty(&ioc->delayed_tr_list)) {
3384 delayed_tr = list_entry(ioc->delayed_tr_list.next,
3385 struct _tr_list, list);
3386 mpt2sas_base_free_smid(ioc, smid);
3387 _scsih_tm_tr_send(ioc, delayed_tr->handle);
3388 list_del(&delayed_tr->list);
3397 * _scsih_check_topo_delete_events - sanity check on topo events
3398 * @ioc: per adapter object
3399 * @event_data: the event data payload
3401 * This routine added to better handle cable breaker.
3403 * This handles the case where driver receives multiple expander
3404 * add and delete events in a single shot. When there is a delete event
3405 * the routine will void any pending add events waiting in the event queue.
3410 _scsih_check_topo_delete_events(struct MPT2SAS_ADAPTER *ioc,
3411 Mpi2EventDataSasTopologyChangeList_t *event_data)
3413 struct fw_event_work *fw_event;
3414 Mpi2EventDataSasTopologyChangeList_t *local_event_data;
3415 u16 expander_handle;
3416 struct _sas_node *sas_expander;
3417 unsigned long flags;
3421 for (i = 0 ; i < event_data->NumEntries; i++) {
3422 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
3425 reason_code = event_data->PHY[i].PhyStatus &
3426 MPI2_EVENT_SAS_TOPO_RC_MASK;
3427 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING)
3428 _scsih_tm_tr_send(ioc, handle);
3431 expander_handle = le16_to_cpu(event_data->ExpanderDevHandle);
3432 if (expander_handle < ioc->sas_hba.num_phys) {
3433 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3437 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
3438 || event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING) {
3439 spin_lock_irqsave(&ioc->sas_node_lock, flags);
3440 sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc,
3442 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
3443 _scsih_block_io_to_children_attached_to_ex(ioc, sas_expander);
3444 } else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING)
3445 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3447 if (event_data->ExpStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING)
3450 /* mark ignore flag for pending events */
3451 spin_lock_irqsave(&ioc->fw_event_lock, flags);
3452 list_for_each_entry(fw_event, &ioc->fw_event_list, list) {
3453 if (fw_event->event != MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST ||
3456 local_event_data = fw_event->event_data;
3457 if (local_event_data->ExpStatus ==
3458 MPI2_EVENT_SAS_TOPO_ES_ADDED ||
3459 local_event_data->ExpStatus ==
3460 MPI2_EVENT_SAS_TOPO_ES_RESPONDING) {
3461 if (le16_to_cpu(local_event_data->ExpanderDevHandle) ==
3463 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3464 "setting ignoring flag\n", ioc->name));
3465 fw_event->ignore = 1;
3469 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
3473 * _scsih_set_volume_delete_flag - setting volume delete flag
3474 * @ioc: per adapter object
3475 * @handle: device handle
3481 _scsih_set_volume_delete_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3483 struct _raid_device *raid_device;
3484 struct MPT2SAS_TARGET *sas_target_priv_data;
3485 unsigned long flags;
3487 spin_lock_irqsave(&ioc->raid_device_lock, flags);
3488 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
3489 if (raid_device && raid_device->starget &&
3490 raid_device->starget->hostdata) {
3491 sas_target_priv_data =
3492 raid_device->starget->hostdata;
3493 sas_target_priv_data->deleted = 1;
3494 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3495 "setting delete flag: handle(0x%04x), "
3496 "wwid(0x%016llx)\n", ioc->name, handle,
3497 (unsigned long long) raid_device->wwid));
3499 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
3503 * _scsih_set_volume_handle_for_tr - set handle for target reset to volume
3504 * @handle: input handle
3505 * @a: handle for volume a
3506 * @b: handle for volume b
3508 * IR firmware only supports two raid volumes. The purpose of this
3509 * routine is to set the volume handle in either a or b. When the given
3510 * input handle is non-zero, or when a and b have not been set before.
3513 _scsih_set_volume_handle_for_tr(u16 handle, u16 *a, u16 *b)
3515 if (!handle || handle == *a || handle == *b)
3524 * _scsih_check_ir_config_unhide_events - check for UNHIDE events
3525 * @ioc: per adapter object
3526 * @event_data: the event data payload
3527 * Context: interrupt time.
3529 * This routine will send target reset to volume, followed by target
3530 * resets to the PDs. This is called when a PD has been removed, or
3531 * volume has been deleted or removed. When the target reset is sent
3532 * to volume, the PD target resets need to be queued to start upon
3533 * completion of the volume target reset.
3538 _scsih_check_ir_config_unhide_events(struct MPT2SAS_ADAPTER *ioc,
3539 Mpi2EventDataIrConfigChangeList_t *event_data)
3541 Mpi2EventIrConfigElement_t *element;
3543 u16 handle, volume_handle, a, b;
3544 struct _tr_list *delayed_tr;
3549 if (ioc->is_warpdrive)
3552 /* Volume Resets for Deleted or Removed */
3553 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3554 for (i = 0; i < event_data->NumElements; i++, element++) {
3555 if (element->ReasonCode ==
3556 MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED ||
3557 element->ReasonCode ==
3558 MPI2_EVENT_IR_CHANGE_RC_REMOVED) {
3559 volume_handle = le16_to_cpu(element->VolDevHandle);
3560 _scsih_set_volume_delete_flag(ioc, volume_handle);
3561 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3565 /* Volume Resets for UNHIDE events */
3566 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3567 for (i = 0; i < event_data->NumElements; i++, element++) {
3568 if (le32_to_cpu(event_data->Flags) &
3569 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG)
3571 if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_UNHIDE) {
3572 volume_handle = le16_to_cpu(element->VolDevHandle);
3573 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3578 _scsih_tm_tr_volume_send(ioc, a);
3580 _scsih_tm_tr_volume_send(ioc, b);
3582 /* PD target resets */
3583 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3584 for (i = 0; i < event_data->NumElements; i++, element++) {
3585 if (element->ReasonCode != MPI2_EVENT_IR_CHANGE_RC_UNHIDE)
3587 handle = le16_to_cpu(element->PhysDiskDevHandle);
3588 volume_handle = le16_to_cpu(element->VolDevHandle);
3589 clear_bit(handle, ioc->pd_handles);
3591 _scsih_tm_tr_send(ioc, handle);
3592 else if (volume_handle == a || volume_handle == b) {
3593 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3594 BUG_ON(!delayed_tr);
3595 INIT_LIST_HEAD(&delayed_tr->list);
3596 delayed_tr->handle = handle;
3597 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
3598 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3599 "DELAYED:tr:handle(0x%04x), (open)\n", ioc->name,
3602 _scsih_tm_tr_send(ioc, handle);
3608 * _scsih_check_volume_delete_events - set delete flag for volumes
3609 * @ioc: per adapter object
3610 * @event_data: the event data payload
3611 * Context: interrupt time.
3613 * This will handle the case when the cable connected to entire volume is
3614 * pulled. We will take care of setting the deleted flag so normal IO will
3620 _scsih_check_volume_delete_events(struct MPT2SAS_ADAPTER *ioc,
3621 Mpi2EventDataIrVolume_t *event_data)
3625 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
3627 state = le32_to_cpu(event_data->NewValue);
3628 if (state == MPI2_RAID_VOL_STATE_MISSING || state ==
3629 MPI2_RAID_VOL_STATE_FAILED)
3630 _scsih_set_volume_delete_flag(ioc,
3631 le16_to_cpu(event_data->VolDevHandle));
3635 * _scsih_flush_running_cmds - completing outstanding commands.
3636 * @ioc: per adapter object
3638 * The flushing out of all pending scmd commands following host reset,
3639 * where all IO is dropped to the floor.
3644 _scsih_flush_running_cmds(struct MPT2SAS_ADAPTER *ioc)
3646 struct scsi_cmnd *scmd;
3650 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
3651 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
3655 mpt2sas_base_free_smid(ioc, smid);
3656 scsi_dma_unmap(scmd);
3657 if (ioc->pci_error_recovery)
3658 scmd->result = DID_NO_CONNECT << 16;
3660 scmd->result = DID_RESET << 16;
3661 scmd->scsi_done(scmd);
3663 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "completing %d cmds\n",
3668 * _scsih_setup_eedp - setup MPI request for EEDP transfer
3669 * @scmd: pointer to scsi command object
3670 * @mpi_request: pointer to the SCSI_IO reqest message frame
3672 * Supporting protection 1 and 3.
3677 _scsih_setup_eedp(struct scsi_cmnd *scmd, Mpi2SCSIIORequest_t *mpi_request)
3680 unsigned char prot_op = scsi_get_prot_op(scmd);
3681 unsigned char prot_type = scsi_get_prot_type(scmd);
3683 if (prot_type == SCSI_PROT_DIF_TYPE0 || prot_op == SCSI_PROT_NORMAL)
3686 if (prot_op == SCSI_PROT_READ_STRIP)
3687 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP;
3688 else if (prot_op == SCSI_PROT_WRITE_INSERT)
3689 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_INSERT_OP;
3693 switch (prot_type) {
3694 case SCSI_PROT_DIF_TYPE1:
3695 case SCSI_PROT_DIF_TYPE2:
3698 * enable ref/guard checking
3699 * auto increment ref tag
3701 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG |
3702 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG |
3703 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
3704 mpi_request->CDB.EEDP32.PrimaryReferenceTag =
3705 cpu_to_be32(scsi_get_lba(scmd));
3708 case SCSI_PROT_DIF_TYPE3:
3711 * enable guard checking
3713 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
3716 mpi_request->EEDPBlockSize = cpu_to_le32(scmd->device->sector_size);
3717 mpi_request->EEDPFlags = cpu_to_le16(eedp_flags);
3721 * _scsih_eedp_error_handling - return sense code for EEDP errors
3722 * @scmd: pointer to scsi command object
3723 * @ioc_status: ioc status
3728 _scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status)
3734 switch (ioc_status) {
3735 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
3738 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
3741 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
3749 if (scmd->sc_data_direction == DMA_TO_DEVICE) {
3750 sk = ILLEGAL_REQUEST;
3751 host_byte = DID_ABORT;
3753 sk = ABORTED_COMMAND;
3757 scsi_build_sense_buffer(0, scmd->sense_buffer, sk, 0x10, ascq);
3758 scmd->result = DRIVER_SENSE << 24 | (host_byte << 16) |
3759 SAM_STAT_CHECK_CONDITION;
3763 * _scsih_scsi_direct_io_get - returns direct io flag
3764 * @ioc: per adapter object
3765 * @smid: system request message index
3767 * Returns the smid stored scmd pointer.
3770 _scsih_scsi_direct_io_get(struct MPT2SAS_ADAPTER *ioc, u16 smid)
3772 return ioc->scsi_lookup[smid - 1].direct_io;
3776 * _scsih_scsi_direct_io_set - sets direct io flag
3777 * @ioc: per adapter object
3778 * @smid: system request message index
3779 * @direct_io: Zero or non-zero value to set in the direct_io flag
3784 _scsih_scsi_direct_io_set(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 direct_io)
3786 ioc->scsi_lookup[smid - 1].direct_io = direct_io;
3791 * _scsih_setup_direct_io - setup MPI request for WARPDRIVE Direct I/O
3792 * @ioc: per adapter object
3793 * @scmd: pointer to scsi command object
3794 * @raid_device: pointer to raid device data structure
3795 * @mpi_request: pointer to the SCSI_IO reqest message frame
3796 * @smid: system request message index
3801 _scsih_setup_direct_io(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
3802 struct _raid_device *raid_device, Mpi2SCSIIORequest_t *mpi_request,
3805 u32 v_lba, p_lba, stripe_off, stripe_unit, column, io_size;
3806 u32 stripe_sz, stripe_exp;
3807 u8 num_pds, *cdb_ptr, *tmp_ptr, *lba_ptr1, *lba_ptr2;
3808 u8 cdb0 = scmd->cmnd[0];
3811 * Try Direct I/O to RAID memeber disks
3813 if (cdb0 == READ_16 || cdb0 == READ_10 ||
3814 cdb0 == WRITE_16 || cdb0 == WRITE_10) {
3815 cdb_ptr = mpi_request->CDB.CDB32;
3817 if ((cdb0 < READ_16) || !(cdb_ptr[2] | cdb_ptr[3] | cdb_ptr[4]
3819 io_size = scsi_bufflen(scmd) >> 9;
3820 /* get virtual lba */
3821 lba_ptr1 = lba_ptr2 = (cdb0 < READ_16) ? &cdb_ptr[2] :
3823 tmp_ptr = (u8 *)&v_lba + 3;
3824 *tmp_ptr-- = *lba_ptr1++;
3825 *tmp_ptr-- = *lba_ptr1++;
3826 *tmp_ptr-- = *lba_ptr1++;
3827 *tmp_ptr = *lba_ptr1;
3829 if (((u64)v_lba + (u64)io_size - 1) <=
3830 (u32)raid_device->max_lba) {
3831 stripe_sz = raid_device->stripe_sz;
3832 stripe_exp = raid_device->stripe_exponent;
3833 stripe_off = v_lba & (stripe_sz - 1);
3835 /* Check whether IO falls within a stripe */
3836 if ((stripe_off + io_size) <= stripe_sz) {
3837 num_pds = raid_device->num_pds;
3838 p_lba = v_lba >> stripe_exp;
3839 stripe_unit = p_lba / num_pds;
3840 column = p_lba % num_pds;
3841 p_lba = (stripe_unit << stripe_exp) +
3843 mpi_request->DevHandle =
3844 cpu_to_le16(raid_device->
3846 tmp_ptr = (u8 *)&p_lba + 3;
3847 *lba_ptr2++ = *tmp_ptr--;
3848 *lba_ptr2++ = *tmp_ptr--;
3849 *lba_ptr2++ = *tmp_ptr--;
3850 *lba_ptr2 = *tmp_ptr;
3852 * WD: To indicate this I/O is directI/O
3854 _scsih_scsi_direct_io_set(ioc, smid, 1);
3862 * _scsih_qcmd - main scsi request entry point
3863 * @scmd: pointer to scsi command object
3864 * @done: function pointer to be invoked on completion
3866 * The callback index is set inside `ioc->scsi_io_cb_idx`.
3868 * Returns 0 on success. If there's a failure, return either:
3869 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
3870 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
3873 _scsih_qcmd_lck(struct scsi_cmnd *scmd, void (*done)(struct scsi_cmnd *))
3875 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
3876 struct MPT2SAS_DEVICE *sas_device_priv_data;
3877 struct MPT2SAS_TARGET *sas_target_priv_data;
3878 struct _raid_device *raid_device;
3879 Mpi2SCSIIORequest_t *mpi_request;
3883 scmd->scsi_done = done;
3884 sas_device_priv_data = scmd->device->hostdata;
3885 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
3886 scmd->result = DID_NO_CONNECT << 16;
3887 scmd->scsi_done(scmd);
3891 if (ioc->pci_error_recovery || ioc->remove_host) {
3892 scmd->result = DID_NO_CONNECT << 16;
3893 scmd->scsi_done(scmd);
3897 sas_target_priv_data = sas_device_priv_data->sas_target;
3898 /* invalid device handle */
3899 if (sas_target_priv_data->handle == MPT2SAS_INVALID_DEVICE_HANDLE) {
3900 scmd->result = DID_NO_CONNECT << 16;
3901 scmd->scsi_done(scmd);
3905 /* host recovery or link resets sent via IOCTLs */
3906 if (ioc->shost_recovery || ioc->ioc_link_reset_in_progress)
3907 return SCSI_MLQUEUE_HOST_BUSY;
3908 /* device busy with task management */
3909 else if (sas_device_priv_data->block || sas_target_priv_data->tm_busy)
3910 return SCSI_MLQUEUE_DEVICE_BUSY;
3911 /* device has been deleted */
3912 else if (sas_target_priv_data->deleted) {
3913 scmd->result = DID_NO_CONNECT << 16;
3914 scmd->scsi_done(scmd);
3918 if (scmd->sc_data_direction == DMA_FROM_DEVICE)
3919 mpi_control = MPI2_SCSIIO_CONTROL_READ;
3920 else if (scmd->sc_data_direction == DMA_TO_DEVICE)
3921 mpi_control = MPI2_SCSIIO_CONTROL_WRITE;
3923 mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER;
3926 if (!(sas_device_priv_data->flags & MPT_DEVICE_FLAGS_INIT)) {
3927 if (scmd->device->tagged_supported) {
3928 if (scmd->device->ordered_tags)
3929 mpi_control |= MPI2_SCSIIO_CONTROL_ORDEREDQ;
3931 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
3933 /* MPI Revision I (UNIT = 0xA) - removed MPI2_SCSIIO_CONTROL_UNTAGGED */
3934 /* mpi_control |= MPI2_SCSIIO_CONTROL_UNTAGGED;
3936 mpi_control |= (0x500);
3939 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
3940 /* Make sure Device is not raid volume.
3941 * We do not expose raid functionality to upper layer for warpdrive.
3943 if (!ioc->is_warpdrive && !_scsih_is_raid(&scmd->device->sdev_gendev) &&
3944 sas_is_tlr_enabled(scmd->device) && scmd->cmd_len != 32)
3945 mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON;
3947 smid = mpt2sas_base_get_smid_scsiio(ioc, ioc->scsi_io_cb_idx, scmd);
3949 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3950 ioc->name, __func__);
3953 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3954 memset(mpi_request, 0, sizeof(Mpi2SCSIIORequest_t));
3955 _scsih_setup_eedp(scmd, mpi_request);
3956 if (scmd->cmd_len == 32)
3957 mpi_control |= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT;
3958 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
3959 if (sas_device_priv_data->sas_target->flags &
3960 MPT_TARGET_FLAGS_RAID_COMPONENT)
3961 mpi_request->Function = MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;
3963 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
3964 mpi_request->DevHandle =
3965 cpu_to_le16(sas_device_priv_data->sas_target->handle);
3966 mpi_request->DataLength = cpu_to_le32(scsi_bufflen(scmd));
3967 mpi_request->Control = cpu_to_le32(mpi_control);
3968 mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len);
3969 mpi_request->MsgFlags = MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR;
3970 mpi_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE;
3971 mpi_request->SenseBufferLowAddress =
3972 mpt2sas_base_get_sense_buffer_dma(ioc, smid);
3973 mpi_request->SGLOffset0 = offsetof(Mpi2SCSIIORequest_t, SGL) / 4;
3974 mpi_request->SGLFlags = cpu_to_le16(MPI2_SCSIIO_SGLFLAGS_TYPE_MPI +
3975 MPI2_SCSIIO_SGLFLAGS_SYSTEM_ADDR);
3976 mpi_request->VF_ID = 0; /* TODO */
3977 mpi_request->VP_ID = 0;
3978 int_to_scsilun(sas_device_priv_data->lun, (struct scsi_lun *)
3980 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
3982 if (!mpi_request->DataLength) {
3983 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request->SGL);
3985 if (_scsih_build_scatter_gather(ioc, scmd, smid)) {
3986 mpt2sas_base_free_smid(ioc, smid);
3991 raid_device = sas_target_priv_data->raid_device;
3992 if (raid_device && raid_device->direct_io_enabled)
3993 _scsih_setup_direct_io(ioc, scmd, raid_device, mpi_request,
3996 if (likely(mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST))
3997 mpt2sas_base_put_smid_scsi_io(ioc, smid,
3998 le16_to_cpu(mpi_request->DevHandle));
4000 mpt2sas_base_put_smid_default(ioc, smid);
4004 return SCSI_MLQUEUE_HOST_BUSY;
4007 static DEF_SCSI_QCMD(_scsih_qcmd)
4010 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
4011 * @sense_buffer: sense data returned by target
4012 * @data: normalized skey/asc/ascq
4017 _scsih_normalize_sense(char *sense_buffer, struct sense_info *data)
4019 if ((sense_buffer[0] & 0x7F) >= 0x72) {
4020 /* descriptor format */
4021 data->skey = sense_buffer[1] & 0x0F;
4022 data->asc = sense_buffer[2];
4023 data->ascq = sense_buffer[3];
4026 data->skey = sense_buffer[2] & 0x0F;
4027 data->asc = sense_buffer[12];
4028 data->ascq = sense_buffer[13];
4032 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4034 * _scsih_scsi_ioc_info - translated non-successful SCSI_IO request
4035 * @ioc: per adapter object
4036 * @scmd: pointer to scsi command object
4037 * @mpi_reply: reply mf payload returned from firmware
4039 * scsi_status - SCSI Status code returned from target device
4040 * scsi_state - state info associated with SCSI_IO determined by ioc
4041 * ioc_status - ioc supplied status info
4046 _scsih_scsi_ioc_info(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
4047 Mpi2SCSIIOReply_t *mpi_reply, u16 smid)
4051 u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) &
4052 MPI2_IOCSTATUS_MASK;
4053 u8 scsi_state = mpi_reply->SCSIState;
4054 u8 scsi_status = mpi_reply->SCSIStatus;
4055 char *desc_ioc_state = NULL;
4056 char *desc_scsi_status = NULL;
4057 char *desc_scsi_state = ioc->tmp_string;
4058 u32 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
4059 struct _sas_device *sas_device = NULL;
4060 unsigned long flags;
4061 struct scsi_target *starget = scmd->device->sdev_target;
4062 struct MPT2SAS_TARGET *priv_target = starget->hostdata;
4063 char *device_str = NULL;
4068 if (ioc->hide_ir_msg)
4069 device_str = "WarpDrive";
4071 device_str = "volume";
4073 if (log_info == 0x31170000)
4076 switch (ioc_status) {
4077 case MPI2_IOCSTATUS_SUCCESS:
4078 desc_ioc_state = "success";
4080 case MPI2_IOCSTATUS_INVALID_FUNCTION:
4081 desc_ioc_state = "invalid function";
4083 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
4084 desc_ioc_state = "scsi recovered error";
4086 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE:
4087 desc_ioc_state = "scsi invalid dev handle";
4089 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
4090 desc_ioc_state = "scsi device not there";
4092 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
4093 desc_ioc_state = "scsi data overrun";
4095 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
4096 desc_ioc_state = "scsi data underrun";
4098 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
4099 desc_ioc_state = "scsi io data error";
4101 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
4102 desc_ioc_state = "scsi protocol error";
4104 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
4105 desc_ioc_state = "scsi task terminated";
4107 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
4108 desc_ioc_state = "scsi residual mismatch";
4110 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
4111 desc_ioc_state = "scsi task mgmt failed";
4113 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
4114 desc_ioc_state = "scsi ioc terminated";
4116 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
4117 desc_ioc_state = "scsi ext terminated";
4119 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4120 desc_ioc_state = "eedp guard error";
4122 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4123 desc_ioc_state = "eedp ref tag error";
4125 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4126 desc_ioc_state = "eedp app tag error";
4129 desc_ioc_state = "unknown";
4133 switch (scsi_status) {
4134 case MPI2_SCSI_STATUS_GOOD:
4135 desc_scsi_status = "good";
4137 case MPI2_SCSI_STATUS_CHECK_CONDITION:
4138 desc_scsi_status = "check condition";
4140 case MPI2_SCSI_STATUS_CONDITION_MET:
4141 desc_scsi_status = "condition met";
4143 case MPI2_SCSI_STATUS_BUSY:
4144 desc_scsi_status = "busy";
4146 case MPI2_SCSI_STATUS_INTERMEDIATE:
4147 desc_scsi_status = "intermediate";
4149 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET:
4150 desc_scsi_status = "intermediate condmet";
4152 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT:
4153 desc_scsi_status = "reservation conflict";
4155 case MPI2_SCSI_STATUS_COMMAND_TERMINATED:
4156 desc_scsi_status = "command terminated";
4158 case MPI2_SCSI_STATUS_TASK_SET_FULL:
4159 desc_scsi_status = "task set full";
4161 case MPI2_SCSI_STATUS_ACA_ACTIVE:
4162 desc_scsi_status = "aca active";
4164 case MPI2_SCSI_STATUS_TASK_ABORTED:
4165 desc_scsi_status = "task aborted";
4168 desc_scsi_status = "unknown";
4172 desc_scsi_state[0] = '\0';
4174 desc_scsi_state = " ";
4175 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
4176 strcat(desc_scsi_state, "response info ");
4177 if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4178 strcat(desc_scsi_state, "state terminated ");
4179 if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS)
4180 strcat(desc_scsi_state, "no status ");
4181 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED)
4182 strcat(desc_scsi_state, "autosense failed ");
4183 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)
4184 strcat(desc_scsi_state, "autosense valid ");
4186 scsi_print_command(scmd);
4188 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
4189 printk(MPT2SAS_WARN_FMT "\t%s wwid(0x%016llx)\n", ioc->name,
4190 device_str, (unsigned long long)priv_target->sas_address);
4192 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4193 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
4194 priv_target->sas_address);
4196 printk(MPT2SAS_WARN_FMT "\tsas_address(0x%016llx), "
4197 "phy(%d)\n", ioc->name, sas_device->sas_address,
4199 printk(MPT2SAS_WARN_FMT
4200 "\tenclosure_logical_id(0x%016llx), slot(%d)\n",
4201 ioc->name, sas_device->enclosure_logical_id,
4204 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4207 printk(MPT2SAS_WARN_FMT "\thandle(0x%04x), ioc_status(%s)(0x%04x), "
4208 "smid(%d)\n", ioc->name, le16_to_cpu(mpi_reply->DevHandle),
4209 desc_ioc_state, ioc_status, smid);
4210 printk(MPT2SAS_WARN_FMT "\trequest_len(%d), underflow(%d), "
4211 "resid(%d)\n", ioc->name, scsi_bufflen(scmd), scmd->underflow,
4212 scsi_get_resid(scmd));
4213 printk(MPT2SAS_WARN_FMT "\ttag(%d), transfer_count(%d), "
4214 "sc->result(0x%08x)\n", ioc->name, le16_to_cpu(mpi_reply->TaskTag),
4215 le32_to_cpu(mpi_reply->TransferCount), scmd->result);
4216 printk(MPT2SAS_WARN_FMT "\tscsi_status(%s)(0x%02x), "
4217 "scsi_state(%s)(0x%02x)\n", ioc->name, desc_scsi_status,
4218 scsi_status, desc_scsi_state, scsi_state);
4220 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
4221 struct sense_info data;
4222 _scsih_normalize_sense(scmd->sense_buffer, &data);
4223 printk(MPT2SAS_WARN_FMT "\t[sense_key,asc,ascq]: "
4224 "[0x%02x,0x%02x,0x%02x], count(%d)\n", ioc->name, data.skey,
4225 data.asc, data.ascq, le32_to_cpu(mpi_reply->SenseCount));
4228 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) {
4229 response_info = le32_to_cpu(mpi_reply->ResponseInfo);
4230 response_bytes = (u8 *)&response_info;
4231 _scsih_response_code(ioc, response_bytes[0]);
4237 * _scsih_turn_on_fault_led - illuminate Fault LED
4238 * @ioc: per adapter object
4239 * @handle: device handle
4245 _scsih_turn_on_fault_led(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4247 Mpi2SepReply_t mpi_reply;
4248 Mpi2SepRequest_t mpi_request;
4250 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
4251 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
4252 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
4253 mpi_request.SlotStatus =
4254 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT);
4255 mpi_request.DevHandle = cpu_to_le16(handle);
4256 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS;
4257 if ((mpt2sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
4258 &mpi_request)) != 0) {
4259 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", ioc->name,
4260 __FILE__, __LINE__, __func__);
4264 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
4265 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "enclosure_processor: "
4266 "ioc_status (0x%04x), loginfo(0x%08x)\n", ioc->name,
4267 le16_to_cpu(mpi_reply.IOCStatus),
4268 le32_to_cpu(mpi_reply.IOCLogInfo)));
4274 * _scsih_send_event_to_turn_on_fault_led - fire delayed event
4275 * @ioc: per adapter object
4276 * @handle: device handle
4277 * Context: interrupt.
4282 _scsih_send_event_to_turn_on_fault_led(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4284 struct fw_event_work *fw_event;
4286 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
4289 fw_event->event = MPT2SAS_TURN_ON_FAULT_LED;
4290 fw_event->device_handle = handle;
4291 fw_event->ioc = ioc;
4292 _scsih_fw_event_add(ioc, fw_event);
4296 * _scsih_smart_predicted_fault - process smart errors
4297 * @ioc: per adapter object
4298 * @handle: device handle
4299 * Context: interrupt.
4304 _scsih_smart_predicted_fault(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4306 struct scsi_target *starget;
4307 struct MPT2SAS_TARGET *sas_target_priv_data;
4308 Mpi2EventNotificationReply_t *event_reply;
4309 Mpi2EventDataSasDeviceStatusChange_t *event_data;
4310 struct _sas_device *sas_device;
4312 unsigned long flags;
4314 /* only handle non-raid devices */
4315 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4316 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
4318 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4321 starget = sas_device->starget;
4322 sas_target_priv_data = starget->hostdata;
4324 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) ||
4325 ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))) {
4326 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4329 starget_printk(KERN_WARNING, starget, "predicted fault\n");
4330 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4332 if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM)
4333 _scsih_send_event_to_turn_on_fault_led(ioc, handle);
4335 /* insert into event log */
4336 sz = offsetof(Mpi2EventNotificationReply_t, EventData) +
4337 sizeof(Mpi2EventDataSasDeviceStatusChange_t);
4338 event_reply = kzalloc(sz, GFP_KERNEL);
4340 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4341 ioc->name, __FILE__, __LINE__, __func__);
4345 event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION;
4346 event_reply->Event =
4347 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE);
4348 event_reply->MsgLength = sz/4;
4349 event_reply->EventDataLength =
4350 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t)/4);
4351 event_data = (Mpi2EventDataSasDeviceStatusChange_t *)
4352 event_reply->EventData;
4353 event_data->ReasonCode = MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA;
4354 event_data->ASC = 0x5D;
4355 event_data->DevHandle = cpu_to_le16(handle);
4356 event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address);
4357 mpt2sas_ctl_add_to_event_log(ioc, event_reply);
4362 * _scsih_io_done - scsi request callback
4363 * @ioc: per adapter object
4364 * @smid: system request message index
4365 * @msix_index: MSIX table index supplied by the OS
4366 * @reply: reply message frame(lower 32bit addr)
4368 * Callback handler when using _scsih_qcmd.
4370 * Return 1 meaning mf should be freed from _base_interrupt
4371 * 0 means the mf is freed from this function.
4374 _scsih_io_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
4376 Mpi2SCSIIORequest_t *mpi_request;
4377 Mpi2SCSIIOReply_t *mpi_reply;
4378 struct scsi_cmnd *scmd;
4384 struct MPT2SAS_DEVICE *sas_device_priv_data;
4385 u32 response_code = 0;
4386 unsigned long flags;
4388 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
4389 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
4393 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
4395 if (mpi_reply == NULL) {
4396 scmd->result = DID_OK << 16;
4400 sas_device_priv_data = scmd->device->hostdata;
4401 if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
4402 sas_device_priv_data->sas_target->deleted) {
4403 scmd->result = DID_NO_CONNECT << 16;
4407 * WARPDRIVE: If direct_io is set then it is directIO,
4408 * the failed direct I/O should be redirected to volume
4410 if (_scsih_scsi_direct_io_get(ioc, smid)) {
4411 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
4412 ioc->scsi_lookup[smid - 1].scmd = scmd;
4413 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
4414 _scsih_scsi_direct_io_set(ioc, smid, 0);
4415 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
4416 mpi_request->DevHandle =
4417 cpu_to_le16(sas_device_priv_data->sas_target->handle);
4418 mpt2sas_base_put_smid_scsi_io(ioc, smid,
4419 sas_device_priv_data->sas_target->handle);
4424 /* turning off TLR */
4425 scsi_state = mpi_reply->SCSIState;
4426 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
4428 le32_to_cpu(mpi_reply->ResponseInfo) & 0xFF;
4429 if (!sas_device_priv_data->tlr_snoop_check) {
4430 sas_device_priv_data->tlr_snoop_check++;
4431 /* Make sure Device is not raid volume.
4432 * We do not expose raid functionality to upper layer for warpdrive.
4434 if (!ioc->is_warpdrive && !_scsih_is_raid(&scmd->device->sdev_gendev) &&
4435 sas_is_tlr_enabled(scmd->device) &&
4436 response_code == MPI2_SCSITASKMGMT_RSP_INVALID_FRAME) {
4437 sas_disable_tlr(scmd->device);
4438 sdev_printk(KERN_INFO, scmd->device, "TLR disabled\n");
4442 xfer_cnt = le32_to_cpu(mpi_reply->TransferCount);
4443 scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt);
4444 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
4445 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
4446 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
4449 ioc_status &= MPI2_IOCSTATUS_MASK;
4450 scsi_status = mpi_reply->SCSIStatus;
4452 if (ioc_status == MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 &&
4453 (scsi_status == MPI2_SCSI_STATUS_BUSY ||
4454 scsi_status == MPI2_SCSI_STATUS_RESERVATION_CONFLICT ||
4455 scsi_status == MPI2_SCSI_STATUS_TASK_SET_FULL)) {
4456 ioc_status = MPI2_IOCSTATUS_SUCCESS;
4459 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
4460 struct sense_info data;
4461 const void *sense_data = mpt2sas_base_get_sense_buffer(ioc,
4463 u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE,
4464 le32_to_cpu(mpi_reply->SenseCount));
4465 memcpy(scmd->sense_buffer, sense_data, sz);
4466 _scsih_normalize_sense(scmd->sense_buffer, &data);
4467 /* failure prediction threshold exceeded */
4468 if (data.asc == 0x5D)
4469 _scsih_smart_predicted_fault(ioc,
4470 le16_to_cpu(mpi_reply->DevHandle));
4473 switch (ioc_status) {
4474 case MPI2_IOCSTATUS_BUSY:
4475 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES:
4476 scmd->result = SAM_STAT_BUSY;
4479 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
4480 scmd->result = DID_NO_CONNECT << 16;
4483 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
4484 if (sas_device_priv_data->block) {
4485 scmd->result = DID_TRANSPORT_DISRUPTED << 16;
4488 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
4489 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
4490 scmd->result = DID_RESET << 16;
4493 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
4494 if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt))
4495 scmd->result = DID_SOFT_ERROR << 16;
4497 scmd->result = (DID_OK << 16) | scsi_status;
4500 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
4501 scmd->result = (DID_OK << 16) | scsi_status;
4503 if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID))
4506 if (xfer_cnt < scmd->underflow) {
4507 if (scsi_status == SAM_STAT_BUSY)
4508 scmd->result = SAM_STAT_BUSY;
4510 scmd->result = DID_SOFT_ERROR << 16;
4511 } else if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4512 MPI2_SCSI_STATE_NO_SCSI_STATUS))
4513 scmd->result = DID_SOFT_ERROR << 16;
4514 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4515 scmd->result = DID_RESET << 16;
4516 else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) {
4517 mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID;
4518 mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION;
4519 scmd->result = (DRIVER_SENSE << 24) |
4520 SAM_STAT_CHECK_CONDITION;
4521 scmd->sense_buffer[0] = 0x70;
4522 scmd->sense_buffer[2] = ILLEGAL_REQUEST;
4523 scmd->sense_buffer[12] = 0x20;
4524 scmd->sense_buffer[13] = 0;
4528 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
4529 scsi_set_resid(scmd, 0);
4530 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
4531 case MPI2_IOCSTATUS_SUCCESS:
4532 scmd->result = (DID_OK << 16) | scsi_status;
4533 if (response_code ==
4534 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME ||
4535 (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4536 MPI2_SCSI_STATE_NO_SCSI_STATUS)))
4537 scmd->result = DID_SOFT_ERROR << 16;
4538 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4539 scmd->result = DID_RESET << 16;
4542 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4543 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4544 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4545 _scsih_eedp_error_handling(scmd, ioc_status);
4547 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
4548 case MPI2_IOCSTATUS_INVALID_FUNCTION:
4549 case MPI2_IOCSTATUS_INVALID_SGL:
4550 case MPI2_IOCSTATUS_INTERNAL_ERROR:
4551 case MPI2_IOCSTATUS_INVALID_FIELD:
4552 case MPI2_IOCSTATUS_INVALID_STATE:
4553 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
4554 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
4556 scmd->result = DID_SOFT_ERROR << 16;
4561 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4562 if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY))
4563 _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid);
4567 scsi_dma_unmap(scmd);
4568 scmd->scsi_done(scmd);
4573 * _scsih_sas_host_refresh - refreshing sas host object contents
4574 * @ioc: per adapter object
4577 * During port enable, fw will send topology events for every device. Its
4578 * possible that the handles may change from the previous setting, so this
4579 * code keeping handles updating if changed.
4584 _scsih_sas_host_refresh(struct MPT2SAS_ADAPTER *ioc)
4589 Mpi2ConfigReply_t mpi_reply;
4590 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
4591 u16 attached_handle;
4594 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT
4595 "updating handles for sas_host(0x%016llx)\n",
4596 ioc->name, (unsigned long long)ioc->sas_hba.sas_address));
4598 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys
4599 * sizeof(Mpi2SasIOUnit0PhyData_t));
4600 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4601 if (!sas_iounit_pg0) {
4602 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4603 ioc->name, __FILE__, __LINE__, __func__);
4607 if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4608 sas_iounit_pg0, sz)) != 0)
4610 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
4611 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
4613 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
4614 link_rate = sas_iounit_pg0->PhyData[i].NegotiatedLinkRate >> 4;
4616 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4617 PhyData[0].ControllerDevHandle);
4618 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
4619 attached_handle = le16_to_cpu(sas_iounit_pg0->PhyData[i].
4621 if (attached_handle && link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
4622 link_rate = MPI2_SAS_NEG_LINK_RATE_1_5;
4623 mpt2sas_transport_update_links(ioc, ioc->sas_hba.sas_address,
4624 attached_handle, i, link_rate);
4627 kfree(sas_iounit_pg0);
4631 * _scsih_sas_host_add - create sas host object
4632 * @ioc: per adapter object
4634 * Creating host side data object, stored in ioc->sas_hba
4639 _scsih_sas_host_add(struct MPT2SAS_ADAPTER *ioc)
4642 Mpi2ConfigReply_t mpi_reply;
4643 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
4644 Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
4645 Mpi2SasPhyPage0_t phy_pg0;
4646 Mpi2SasDevicePage0_t sas_device_pg0;
4647 Mpi2SasEnclosurePage0_t enclosure_pg0;
4650 u16 device_missing_delay;
4652 mpt2sas_config_get_number_hba_phys(ioc, &ioc->sas_hba.num_phys);
4653 if (!ioc->sas_hba.num_phys) {
4654 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4655 ioc->name, __FILE__, __LINE__, __func__);
4659 /* sas_iounit page 0 */
4660 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys *
4661 sizeof(Mpi2SasIOUnit0PhyData_t));
4662 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4663 if (!sas_iounit_pg0) {
4664 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4665 ioc->name, __FILE__, __LINE__, __func__);
4668 if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4669 sas_iounit_pg0, sz))) {
4670 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4671 ioc->name, __FILE__, __LINE__, __func__);
4674 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4675 MPI2_IOCSTATUS_MASK;
4676 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4677 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4678 ioc->name, __FILE__, __LINE__, __func__);
4682 /* sas_iounit page 1 */
4683 sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys *
4684 sizeof(Mpi2SasIOUnit1PhyData_t));
4685 sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
4686 if (!sas_iounit_pg1) {
4687 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4688 ioc->name, __FILE__, __LINE__, __func__);
4691 if ((mpt2sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
4692 sas_iounit_pg1, sz))) {
4693 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4694 ioc->name, __FILE__, __LINE__, __func__);
4697 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4698 MPI2_IOCSTATUS_MASK;
4699 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4700 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4701 ioc->name, __FILE__, __LINE__, __func__);
4705 ioc->io_missing_delay =
4706 le16_to_cpu(sas_iounit_pg1->IODeviceMissingDelay);
4707 device_missing_delay =
4708 le16_to_cpu(sas_iounit_pg1->ReportDeviceMissingDelay);
4709 if (device_missing_delay & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16)
4710 ioc->device_missing_delay = (device_missing_delay &
4711 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16;
4713 ioc->device_missing_delay = device_missing_delay &
4714 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
4716 ioc->sas_hba.parent_dev = &ioc->shost->shost_gendev;
4717 ioc->sas_hba.phy = kcalloc(ioc->sas_hba.num_phys,
4718 sizeof(struct _sas_phy), GFP_KERNEL);
4719 if (!ioc->sas_hba.phy) {
4720 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4721 ioc->name, __FILE__, __LINE__, __func__);
4724 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
4725 if ((mpt2sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0,
4727 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4728 ioc->name, __FILE__, __LINE__, __func__);
4731 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4732 MPI2_IOCSTATUS_MASK;
4733 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4734 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4735 ioc->name, __FILE__, __LINE__, __func__);
4740 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4741 PhyData[0].ControllerDevHandle);
4742 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
4743 ioc->sas_hba.phy[i].phy_id = i;
4744 mpt2sas_transport_add_host_phy(ioc, &ioc->sas_hba.phy[i],
4745 phy_pg0, ioc->sas_hba.parent_dev);
4747 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
4748 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, ioc->sas_hba.handle))) {
4749 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4750 ioc->name, __FILE__, __LINE__, __func__);
4753 ioc->sas_hba.enclosure_handle =
4754 le16_to_cpu(sas_device_pg0.EnclosureHandle);
4755 ioc->sas_hba.sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
4756 printk(MPT2SAS_INFO_FMT "host_add: handle(0x%04x), "
4757 "sas_addr(0x%016llx), phys(%d)\n", ioc->name, ioc->sas_hba.handle,
4758 (unsigned long long) ioc->sas_hba.sas_address,
4759 ioc->sas_hba.num_phys) ;
4761 if (ioc->sas_hba.enclosure_handle) {
4762 if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply,
4764 MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
4765 ioc->sas_hba.enclosure_handle))) {
4766 ioc->sas_hba.enclosure_logical_id =
4767 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
4772 kfree(sas_iounit_pg1);
4773 kfree(sas_iounit_pg0);
4777 * _scsih_expander_add - creating expander object
4778 * @ioc: per adapter object
4779 * @handle: expander handle
4781 * Creating expander object, stored in ioc->sas_expander_list.
4783 * Return 0 for success, else error.
4786 _scsih_expander_add(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4788 struct _sas_node *sas_expander;
4789 Mpi2ConfigReply_t mpi_reply;
4790 Mpi2ExpanderPage0_t expander_pg0;
4791 Mpi2ExpanderPage1_t expander_pg1;
4792 Mpi2SasEnclosurePage0_t enclosure_pg0;
4795 u64 sas_address, sas_address_parent = 0;
4797 unsigned long flags;
4798 struct _sas_port *mpt2sas_port = NULL;
4804 if (ioc->shost_recovery || ioc->pci_error_recovery)
4807 if ((mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
4808 MPI2_SAS_EXPAND_PGAD_FORM_HNDL, handle))) {
4809 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4810 ioc->name, __FILE__, __LINE__, __func__);
4814 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4815 MPI2_IOCSTATUS_MASK;
4816 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4817 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4818 ioc->name, __FILE__, __LINE__, __func__);
4822 /* handle out of order topology events */
4823 parent_handle = le16_to_cpu(expander_pg0.ParentDevHandle);
4824 if (_scsih_get_sas_address(ioc, parent_handle, &sas_address_parent)
4826 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4827 ioc->name, __FILE__, __LINE__, __func__);
4830 if (sas_address_parent != ioc->sas_hba.sas_address) {
4831 spin_lock_irqsave(&ioc->sas_node_lock, flags);
4832 sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
4833 sas_address_parent);
4834 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4835 if (!sas_expander) {
4836 rc = _scsih_expander_add(ioc, parent_handle);
4842 spin_lock_irqsave(&ioc->sas_node_lock, flags);
4843 sas_address = le64_to_cpu(expander_pg0.SASAddress);
4844 sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
4846 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4851 sas_expander = kzalloc(sizeof(struct _sas_node),
4853 if (!sas_expander) {
4854 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4855 ioc->name, __FILE__, __LINE__, __func__);
4859 sas_expander->handle = handle;
4860 sas_expander->num_phys = expander_pg0.NumPhys;
4861 sas_expander->sas_address_parent = sas_address_parent;
4862 sas_expander->sas_address = sas_address;
4864 printk(MPT2SAS_INFO_FMT "expander_add: handle(0x%04x),"
4865 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc->name,
4866 handle, parent_handle, (unsigned long long)
4867 sas_expander->sas_address, sas_expander->num_phys);
4869 if (!sas_expander->num_phys)
4871 sas_expander->phy = kcalloc(sas_expander->num_phys,
4872 sizeof(struct _sas_phy), GFP_KERNEL);
4873 if (!sas_expander->phy) {
4874 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4875 ioc->name, __FILE__, __LINE__, __func__);
4880 INIT_LIST_HEAD(&sas_expander->sas_port_list);
4881 mpt2sas_port = mpt2sas_transport_port_add(ioc, handle,
4882 sas_address_parent);
4883 if (!mpt2sas_port) {
4884 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4885 ioc->name, __FILE__, __LINE__, __func__);
4889 sas_expander->parent_dev = &mpt2sas_port->rphy->dev;
4891 for (i = 0 ; i < sas_expander->num_phys ; i++) {
4892 if ((mpt2sas_config_get_expander_pg1(ioc, &mpi_reply,
4893 &expander_pg1, i, handle))) {
4894 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4895 ioc->name, __FILE__, __LINE__, __func__);
4899 sas_expander->phy[i].handle = handle;
4900 sas_expander->phy[i].phy_id = i;
4902 if ((mpt2sas_transport_add_expander_phy(ioc,
4903 &sas_expander->phy[i], expander_pg1,
4904 sas_expander->parent_dev))) {
4905 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4906 ioc->name, __FILE__, __LINE__, __func__);
4912 if (sas_expander->enclosure_handle) {
4913 if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply,
4914 &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
4915 sas_expander->enclosure_handle))) {
4916 sas_expander->enclosure_logical_id =
4917 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
4921 _scsih_expander_node_add(ioc, sas_expander);
4927 mpt2sas_transport_port_remove(ioc, sas_expander->sas_address,
4928 sas_address_parent);
4929 kfree(sas_expander);
4934 * _scsih_done - scsih callback handler.
4935 * @ioc: per adapter object
4936 * @smid: system request message index
4937 * @msix_index: MSIX table index supplied by the OS
4938 * @reply: reply message frame(lower 32bit addr)
4940 * Callback handler when sending internal generated message frames.
4941 * The callback index passed is `ioc->scsih_cb_idx`
4943 * Return 1 meaning mf should be freed from _base_interrupt
4944 * 0 means the mf is freed from this function.
4947 _scsih_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
4949 MPI2DefaultReply_t *mpi_reply;
4951 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
4952 if (ioc->scsih_cmds.status == MPT2_CMD_NOT_USED)
4954 if (ioc->scsih_cmds.smid != smid)
4956 ioc->scsih_cmds.status |= MPT2_CMD_COMPLETE;
4958 memcpy(ioc->scsih_cmds.reply, mpi_reply,
4959 mpi_reply->MsgLength*4);
4960 ioc->scsih_cmds.status |= MPT2_CMD_REPLY_VALID;
4962 ioc->scsih_cmds.status &= ~MPT2_CMD_PENDING;
4963 complete(&ioc->scsih_cmds.done);
4968 * mpt2sas_expander_remove - removing expander object
4969 * @ioc: per adapter object
4970 * @sas_address: expander sas_address
4975 mpt2sas_expander_remove(struct MPT2SAS_ADAPTER *ioc, u64 sas_address)
4977 struct _sas_node *sas_expander;
4978 unsigned long flags;
4980 if (ioc->shost_recovery)
4983 spin_lock_irqsave(&ioc->sas_node_lock, flags);
4984 sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
4986 if (!sas_expander) {
4987 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4990 list_del(&sas_expander->list);
4991 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4992 _scsih_expander_node_remove(ioc, sas_expander);
4996 * _scsih_check_access_status - check access flags
4997 * @ioc: per adapter object
4998 * @sas_address: sas address
4999 * @handle: sas device handle
5000 * @access_flags: errors returned during discovery of the device
5002 * Return 0 for success, else failure
5005 _scsih_check_access_status(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
5006 u16 handle, u8 access_status)
5011 switch (access_status) {
5012 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS:
5013 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION:
5016 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED:
5017 desc = "sata capability failed";
5019 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT:
5020 desc = "sata affiliation conflict";
5022 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE:
5023 desc = "route not addressable";
5025 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE:
5026 desc = "smp error not addressable";
5028 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED:
5029 desc = "device blocked";
5031 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED:
5032 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN:
5033 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT:
5034 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG:
5035 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION:
5036 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER:
5037 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN:
5038 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN:
5039 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN:
5040 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION:
5041 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE:
5042 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX:
5043 desc = "sata initialization failed";
5053 printk(MPT2SAS_ERR_FMT "discovery errors(%s): sas_address(0x%016llx), "
5054 "handle(0x%04x)\n", ioc->name, desc,
5055 (unsigned long long)sas_address, handle);
5060 _scsih_check_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
5062 Mpi2ConfigReply_t mpi_reply;
5063 Mpi2SasDevicePage0_t sas_device_pg0;
5064 struct _sas_device *sas_device;
5066 unsigned long flags;
5068 struct scsi_target *starget;
5069 struct MPT2SAS_TARGET *sas_target_priv_data;
5072 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5073 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle)))
5076 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
5077 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
5080 /* check if this is end device */
5081 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
5082 if (!(_scsih_is_end_device(device_info)))
5085 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5086 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
5087 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5091 printk(MPT2SAS_ERR_FMT "device is not present "
5092 "handle(0x%04x), no sas_device!!!\n", ioc->name, handle);
5093 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5097 if (unlikely(sas_device->handle != handle)) {
5098 starget = sas_device->starget;
5099 sas_target_priv_data = starget->hostdata;
5100 starget_printk(KERN_INFO, starget, "handle changed from(0x%04x)"
5101 " to (0x%04x)!!!\n", sas_device->handle, handle);
5102 sas_target_priv_data->handle = handle;
5103 sas_device->handle = handle;
5105 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5107 /* check if device is present */
5108 if (!(le16_to_cpu(sas_device_pg0.Flags) &
5109 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
5110 printk(MPT2SAS_ERR_FMT "device is not present "
5111 "handle(0x%04x), flags!!!\n", ioc->name, handle);
5115 /* check if there were any issues with discovery */
5116 if (_scsih_check_access_status(ioc, sas_address, handle,
5117 sas_device_pg0.AccessStatus))
5119 _scsih_ublock_io_device(ioc, handle);
5124 * _scsih_add_device - creating sas device object
5125 * @ioc: per adapter object
5126 * @handle: sas device handle
5127 * @phy_num: phy number end device attached to
5128 * @is_pd: is this hidden raid component
5130 * Creating end device object, stored in ioc->sas_device_list.
5132 * Returns 0 for success, non-zero for failure.
5135 _scsih_add_device(struct MPT2SAS_ADAPTER *ioc, u16 handle, u8 phy_num, u8 is_pd)
5137 Mpi2ConfigReply_t mpi_reply;
5138 Mpi2SasDevicePage0_t sas_device_pg0;
5139 Mpi2SasEnclosurePage0_t enclosure_pg0;
5140 struct _sas_device *sas_device;
5144 unsigned long flags;
5146 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5147 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
5148 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5149 ioc->name, __FILE__, __LINE__, __func__);
5153 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
5154 MPI2_IOCSTATUS_MASK;
5155 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5156 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5157 ioc->name, __FILE__, __LINE__, __func__);
5161 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
5163 /* check if device is present */
5164 if (!(le16_to_cpu(sas_device_pg0.Flags) &
5165 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
5166 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5167 ioc->name, __FILE__, __LINE__, __func__);
5168 printk(MPT2SAS_ERR_FMT "Flags = 0x%04x\n",
5169 ioc->name, le16_to_cpu(sas_device_pg0.Flags));
5173 /* check if there were any issues with discovery */
5174 if (_scsih_check_access_status(ioc, sas_address, handle,
5175 sas_device_pg0.AccessStatus))
5178 /* check if this is end device */
5179 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
5180 if (!(_scsih_is_end_device(device_info))) {
5181 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5182 ioc->name, __FILE__, __LINE__, __func__);
5187 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5188 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5190 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5195 sas_device = kzalloc(sizeof(struct _sas_device),
5198 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5199 ioc->name, __FILE__, __LINE__, __func__);
5203 sas_device->handle = handle;
5204 if (_scsih_get_sas_address(ioc, le16_to_cpu
5205 (sas_device_pg0.ParentDevHandle),
5206 &sas_device->sas_address_parent) != 0)
5207 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5208 ioc->name, __FILE__, __LINE__, __func__);
5209 sas_device->enclosure_handle =
5210 le16_to_cpu(sas_device_pg0.EnclosureHandle);
5212 le16_to_cpu(sas_device_pg0.Slot);
5213 sas_device->device_info = device_info;
5214 sas_device->sas_address = sas_address;
5215 sas_device->phy = sas_device_pg0.PhyNum;
5217 /* get enclosure_logical_id */
5218 if (sas_device->enclosure_handle && !(mpt2sas_config_get_enclosure_pg0(
5219 ioc, &mpi_reply, &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
5220 sas_device->enclosure_handle)))
5221 sas_device->enclosure_logical_id =
5222 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
5224 /* get device name */
5225 sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName);
5227 if (ioc->wait_for_discovery_to_complete)
5228 _scsih_sas_device_init_add(ioc, sas_device);
5230 _scsih_sas_device_add(ioc, sas_device);
5236 * _scsih_remove_device - removing sas device object
5237 * @ioc: per adapter object
5238 * @sas_device_delete: the sas_device object
5243 _scsih_remove_device(struct MPT2SAS_ADAPTER *ioc,
5244 struct _sas_device *sas_device)
5246 struct _sas_device sas_device_backup;
5247 struct MPT2SAS_TARGET *sas_target_priv_data;
5252 memcpy(&sas_device_backup, sas_device, sizeof(struct _sas_device));
5253 _scsih_sas_device_remove(ioc, sas_device);
5255 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter: "
5256 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
5257 sas_device_backup.handle, (unsigned long long)
5258 sas_device_backup.sas_address));
5260 if (sas_device_backup.starget && sas_device_backup.starget->hostdata) {
5261 sas_target_priv_data = sas_device_backup.starget->hostdata;
5262 sas_target_priv_data->deleted = 1;
5263 _scsih_ublock_io_device(ioc, sas_device_backup.handle);
5264 sas_target_priv_data->handle =
5265 MPT2SAS_INVALID_DEVICE_HANDLE;
5268 _scsih_ublock_io_device(ioc, sas_device_backup.handle);
5270 if (!ioc->hide_drives)
5271 mpt2sas_transport_port_remove(ioc,
5272 sas_device_backup.sas_address,
5273 sas_device_backup.sas_address_parent);
5275 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), sas_addr"
5276 "(0x%016llx)\n", ioc->name, sas_device_backup.handle,
5277 (unsigned long long) sas_device_backup.sas_address);
5279 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: exit: "
5280 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
5281 sas_device_backup.handle, (unsigned long long)
5282 sas_device_backup.sas_address));
5286 * mpt2sas_device_remove - removing device object
5287 * @ioc: per adapter object
5288 * @sas_address: expander sas_address
5293 mpt2sas_device_remove(struct MPT2SAS_ADAPTER *ioc, u64 sas_address)
5295 struct _sas_device *sas_device;
5296 unsigned long flags;
5298 if (ioc->shost_recovery)
5301 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5302 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5305 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5308 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5309 _scsih_remove_device(ioc, sas_device);
5312 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5314 * _scsih_sas_topology_change_event_debug - debug for topology event
5315 * @ioc: per adapter object
5316 * @event_data: event data payload
5320 _scsih_sas_topology_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
5321 Mpi2EventDataSasTopologyChangeList_t *event_data)
5327 char *status_str = NULL;
5328 u8 link_rate, prev_link_rate;
5330 switch (event_data->ExpStatus) {
5331 case MPI2_EVENT_SAS_TOPO_ES_ADDED:
5334 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING:
5335 status_str = "remove";
5337 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING:
5339 status_str = "responding";
5341 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING:
5342 status_str = "remove delay";
5345 status_str = "unknown status";
5348 printk(MPT2SAS_INFO_FMT "sas topology change: (%s)\n",
5349 ioc->name, status_str);
5350 printk(KERN_INFO "\thandle(0x%04x), enclosure_handle(0x%04x) "
5351 "start_phy(%02d), count(%d)\n",
5352 le16_to_cpu(event_data->ExpanderDevHandle),
5353 le16_to_cpu(event_data->EnclosureHandle),
5354 event_data->StartPhyNum, event_data->NumEntries);
5355 for (i = 0; i < event_data->NumEntries; i++) {
5356 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5359 phy_number = event_data->StartPhyNum + i;
5360 reason_code = event_data->PHY[i].PhyStatus &
5361 MPI2_EVENT_SAS_TOPO_RC_MASK;
5362 switch (reason_code) {
5363 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
5364 status_str = "target add";
5366 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
5367 status_str = "target remove";
5369 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING:
5370 status_str = "delay target remove";
5372 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
5373 status_str = "link rate change";
5375 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE:
5376 status_str = "target responding";
5379 status_str = "unknown";
5382 link_rate = event_data->PHY[i].LinkRate >> 4;
5383 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
5384 printk(KERN_INFO "\tphy(%02d), attached_handle(0x%04x): %s:"
5385 " link rate: new(0x%02x), old(0x%02x)\n", phy_number,
5386 handle, status_str, link_rate, prev_link_rate);
5393 * _scsih_sas_topology_change_event - handle topology changes
5394 * @ioc: per adapter object
5395 * @fw_event: The fw_event_work object
5400 _scsih_sas_topology_change_event(struct MPT2SAS_ADAPTER *ioc,
5401 struct fw_event_work *fw_event)
5404 u16 parent_handle, handle;
5406 u8 phy_number, max_phys;
5407 struct _sas_node *sas_expander;
5408 struct _sas_device *sas_device;
5410 unsigned long flags;
5411 u8 link_rate, prev_link_rate;
5412 Mpi2EventDataSasTopologyChangeList_t *event_data = fw_event->event_data;
5414 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5415 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5416 _scsih_sas_topology_change_event_debug(ioc, event_data);
5419 if (ioc->remove_host || ioc->pci_error_recovery)
5422 if (!ioc->sas_hba.num_phys)
5423 _scsih_sas_host_add(ioc);
5425 _scsih_sas_host_refresh(ioc);
5427 if (fw_event->ignore) {
5428 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "ignoring expander "
5429 "event\n", ioc->name));
5433 parent_handle = le16_to_cpu(event_data->ExpanderDevHandle);
5435 /* handle expander add */
5436 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_ADDED)
5437 if (_scsih_expander_add(ioc, parent_handle) != 0)
5440 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5441 sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc,
5443 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5445 sas_address = sas_expander->sas_address;
5446 max_phys = sas_expander->num_phys;
5447 } else if (parent_handle < ioc->sas_hba.num_phys) {
5448 sas_address = ioc->sas_hba.sas_address;
5449 max_phys = ioc->sas_hba.num_phys;
5453 /* handle siblings events */
5454 for (i = 0; i < event_data->NumEntries; i++) {
5455 if (fw_event->ignore) {
5456 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "ignoring "
5457 "expander event\n", ioc->name));
5460 if (ioc->shost_recovery || ioc->remove_host ||
5461 ioc->pci_error_recovery)
5463 phy_number = event_data->StartPhyNum + i;
5464 if (phy_number >= max_phys)
5466 reason_code = event_data->PHY[i].PhyStatus &
5467 MPI2_EVENT_SAS_TOPO_RC_MASK;
5468 if ((event_data->PHY[i].PhyStatus &
5469 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT) && (reason_code !=
5470 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING))
5472 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5475 link_rate = event_data->PHY[i].LinkRate >> 4;
5476 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
5477 switch (reason_code) {
5478 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
5480 if (ioc->shost_recovery)
5483 if (link_rate == prev_link_rate)
5486 mpt2sas_transport_update_links(ioc, sas_address,
5487 handle, phy_number, link_rate);
5489 if (link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
5492 _scsih_check_device(ioc, handle);
5494 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
5496 if (ioc->shost_recovery)
5499 mpt2sas_transport_update_links(ioc, sas_address,
5500 handle, phy_number, link_rate);
5502 _scsih_add_device(ioc, handle, phy_number, 0);
5504 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
5506 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5507 sas_device = _scsih_sas_device_find_by_handle(ioc,
5510 spin_unlock_irqrestore(&ioc->sas_device_lock,
5514 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5515 _scsih_remove_device(ioc, sas_device);
5520 /* handle expander removal */
5521 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING &&
5523 mpt2sas_expander_remove(ioc, sas_address);
5527 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5529 * _scsih_sas_device_status_change_event_debug - debug for device event
5530 * @event_data: event data payload
5536 _scsih_sas_device_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
5537 Mpi2EventDataSasDeviceStatusChange_t *event_data)
5539 char *reason_str = NULL;
5541 switch (event_data->ReasonCode) {
5542 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
5543 reason_str = "smart data";
5545 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED:
5546 reason_str = "unsupported device discovered";
5548 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
5549 reason_str = "internal device reset";
5551 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL:
5552 reason_str = "internal task abort";
5554 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL:
5555 reason_str = "internal task abort set";
5557 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL:
5558 reason_str = "internal clear task set";
5560 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL:
5561 reason_str = "internal query task";
5563 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE:
5564 reason_str = "sata init failure";
5566 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET:
5567 reason_str = "internal device reset complete";
5569 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL:
5570 reason_str = "internal task abort complete";
5572 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION:
5573 reason_str = "internal async notification";
5575 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY:
5576 reason_str = "expander reduced functionality";
5578 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY:
5579 reason_str = "expander reduced functionality complete";
5582 reason_str = "unknown reason";
5585 printk(MPT2SAS_INFO_FMT "device status change: (%s)\n"
5586 "\thandle(0x%04x), sas address(0x%016llx), tag(%d)",
5587 ioc->name, reason_str, le16_to_cpu(event_data->DevHandle),
5588 (unsigned long long)le64_to_cpu(event_data->SASAddress),
5589 le16_to_cpu(event_data->TaskTag));
5590 if (event_data->ReasonCode == MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA)
5591 printk(MPT2SAS_INFO_FMT ", ASC(0x%x), ASCQ(0x%x)\n", ioc->name,
5592 event_data->ASC, event_data->ASCQ);
5593 printk(KERN_INFO "\n");
5598 * _scsih_sas_device_status_change_event - handle device status change
5599 * @ioc: per adapter object
5600 * @fw_event: The fw_event_work object
5606 _scsih_sas_device_status_change_event(struct MPT2SAS_ADAPTER *ioc,
5607 struct fw_event_work *fw_event)
5609 struct MPT2SAS_TARGET *target_priv_data;
5610 struct _sas_device *sas_device;
5612 unsigned long flags;
5613 Mpi2EventDataSasDeviceStatusChange_t *event_data =
5614 fw_event->event_data;
5616 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5617 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5618 _scsih_sas_device_status_change_event_debug(ioc,
5622 /* In MPI Revision K (0xC), the internal device reset complete was
5623 * implemented, so avoid setting tm_busy flag for older firmware.
5625 if ((ioc->facts.HeaderVersion >> 8) < 0xC)
5628 if (event_data->ReasonCode !=
5629 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET &&
5630 event_data->ReasonCode !=
5631 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET)
5634 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5635 sas_address = le64_to_cpu(event_data->SASAddress);
5636 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5638 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5640 if (!sas_device || !sas_device->starget)
5643 target_priv_data = sas_device->starget->hostdata;
5644 if (!target_priv_data)
5647 if (event_data->ReasonCode ==
5648 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET)
5649 target_priv_data->tm_busy = 1;
5651 target_priv_data->tm_busy = 0;
5654 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5656 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure event
5657 * @ioc: per adapter object
5658 * @event_data: event data payload
5664 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
5665 Mpi2EventDataSasEnclDevStatusChange_t *event_data)
5667 char *reason_str = NULL;
5669 switch (event_data->ReasonCode) {
5670 case MPI2_EVENT_SAS_ENCL_RC_ADDED:
5671 reason_str = "enclosure add";
5673 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING:
5674 reason_str = "enclosure remove";
5677 reason_str = "unknown reason";
5681 printk(MPT2SAS_INFO_FMT "enclosure status change: (%s)\n"
5682 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
5683 " number slots(%d)\n", ioc->name, reason_str,
5684 le16_to_cpu(event_data->EnclosureHandle),
5685 (unsigned long long)le64_to_cpu(event_data->EnclosureLogicalID),
5686 le16_to_cpu(event_data->StartSlot));
5691 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
5692 * @ioc: per adapter object
5693 * @fw_event: The fw_event_work object
5699 _scsih_sas_enclosure_dev_status_change_event(struct MPT2SAS_ADAPTER *ioc,
5700 struct fw_event_work *fw_event)
5702 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5703 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5704 _scsih_sas_enclosure_dev_status_change_event_debug(ioc,
5705 fw_event->event_data);
5710 * _scsih_sas_broadcast_primative_event - handle broadcast events
5711 * @ioc: per adapter object
5712 * @fw_event: The fw_event_work object
5718 _scsih_sas_broadcast_primative_event(struct MPT2SAS_ADAPTER *ioc,
5719 struct fw_event_work *fw_event)
5721 struct scsi_cmnd *scmd;
5722 struct scsi_device *sdev;
5725 struct MPT2SAS_DEVICE *sas_device_priv_data;
5726 u32 termination_count;
5728 Mpi2SCSITaskManagementReply_t *mpi_reply;
5729 Mpi2EventDataSasBroadcastPrimitive_t *event_data = fw_event->event_data;
5731 unsigned long flags;
5734 u8 task_abort_retries;
5736 mutex_lock(&ioc->tm_cmds.mutex);
5737 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter: phy number(%d), "
5738 "width(%d)\n", ioc->name, __func__, event_data->PhyNum,
5739 event_data->PortWidth));
5741 _scsih_block_io_all_device(ioc);
5743 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5744 mpi_reply = ioc->tm_cmds.reply;
5745 broadcast_aen_retry:
5747 /* sanity checks for retrying this loop */
5748 if (max_retries++ == 5) {
5749 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: giving up\n",
5750 ioc->name, __func__));
5752 } else if (max_retries > 1)
5753 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: %d retry\n",
5754 ioc->name, __func__, max_retries - 1));
5756 termination_count = 0;
5758 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
5759 if (ioc->shost_recovery)
5761 scmd = _scsih_scsi_lookup_get(ioc, smid);
5764 sdev = scmd->device;
5765 sas_device_priv_data = sdev->hostdata;
5766 if (!sas_device_priv_data || !sas_device_priv_data->sas_target)
5768 /* skip hidden raid components */
5769 if (sas_device_priv_data->sas_target->flags &
5770 MPT_TARGET_FLAGS_RAID_COMPONENT)
5773 if (sas_device_priv_data->sas_target->flags &
5774 MPT_TARGET_FLAGS_VOLUME)
5777 handle = sas_device_priv_data->sas_target->handle;
5778 lun = sas_device_priv_data->lun;
5781 if (ioc->shost_recovery)
5784 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
5785 r = mpt2sas_scsih_issue_tm(ioc, handle, 0, 0, lun,
5786 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, smid, 30, 0,
5789 sdev_printk(KERN_WARNING, sdev,
5790 "mpt2sas_scsih_issue_tm: FAILED when sending "
5791 "QUERY_TASK: scmd(%p)\n", scmd);
5792 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5793 goto broadcast_aen_retry;
5795 ioc_status = le16_to_cpu(mpi_reply->IOCStatus)
5796 & MPI2_IOCSTATUS_MASK;
5797 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5798 sdev_printk(KERN_WARNING, sdev, "query task: FAILED "
5799 "with IOCSTATUS(0x%04x), scmd(%p)\n", ioc_status,
5801 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5802 goto broadcast_aen_retry;
5805 /* see if IO is still owned by IOC and target */
5806 if (mpi_reply->ResponseCode ==
5807 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED ||
5808 mpi_reply->ResponseCode ==
5809 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC) {
5810 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5813 task_abort_retries = 0;
5815 if (task_abort_retries++ == 60) {
5816 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
5817 "%s: ABORT_TASK: giving up\n", ioc->name,
5819 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5820 goto broadcast_aen_retry;
5823 if (ioc->shost_recovery)
5826 r = mpt2sas_scsih_issue_tm(ioc, handle, sdev->channel, sdev->id,
5827 sdev->lun, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30,
5828 scmd->serial_number, TM_MUTEX_OFF);
5830 sdev_printk(KERN_WARNING, sdev,
5831 "mpt2sas_scsih_issue_tm: ABORT_TASK: FAILED : "
5832 "scmd(%p)\n", scmd);
5836 if (task_abort_retries > 1)
5837 sdev_printk(KERN_WARNING, sdev,
5838 "mpt2sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):"
5840 task_abort_retries - 1, scmd);
5842 termination_count += le32_to_cpu(mpi_reply->TerminationCount);
5843 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5846 if (ioc->broadcast_aen_pending) {
5847 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: loop back due to"
5848 " pending AEN\n", ioc->name, __func__));
5849 ioc->broadcast_aen_pending = 0;
5850 goto broadcast_aen_retry;
5854 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
5857 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
5858 "%s - exit, query_count = %d termination_count = %d\n",
5859 ioc->name, __func__, query_count, termination_count));
5861 ioc->broadcast_aen_busy = 0;
5862 if (!ioc->shost_recovery)
5863 _scsih_ublock_io_all_device(ioc);
5864 mutex_unlock(&ioc->tm_cmds.mutex);
5868 * _scsih_sas_discovery_event - handle discovery events
5869 * @ioc: per adapter object
5870 * @fw_event: The fw_event_work object
5876 _scsih_sas_discovery_event(struct MPT2SAS_ADAPTER *ioc,
5877 struct fw_event_work *fw_event)
5879 Mpi2EventDataSasDiscovery_t *event_data = fw_event->event_data;
5881 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5882 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) {
5883 printk(MPT2SAS_INFO_FMT "discovery event: (%s)", ioc->name,
5884 (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ?
5886 if (event_data->DiscoveryStatus)
5887 printk("discovery_status(0x%08x)",
5888 le32_to_cpu(event_data->DiscoveryStatus));
5893 if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED &&
5894 !ioc->sas_hba.num_phys)
5895 _scsih_sas_host_add(ioc);
5899 * _scsih_reprobe_lun - reprobing lun
5900 * @sdev: scsi device struct
5901 * @no_uld_attach: sdev->no_uld_attach flag setting
5905 _scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach)
5909 sdev->no_uld_attach = no_uld_attach ? 1 : 0;
5910 sdev_printk(KERN_INFO, sdev, "%s raid component\n",
5911 sdev->no_uld_attach ? "hidding" : "exposing");
5912 rc = scsi_device_reprobe(sdev);
5916 * _scsih_reprobe_target - reprobing target
5917 * @starget: scsi target struct
5918 * @no_uld_attach: sdev->no_uld_attach flag setting
5920 * Note: no_uld_attach flag determines whether the disk device is attached
5921 * to block layer. A value of `1` means to not attach.
5924 _scsih_reprobe_target(struct scsi_target *starget, int no_uld_attach)
5926 struct MPT2SAS_TARGET *sas_target_priv_data;
5928 if (starget == NULL)
5930 sas_target_priv_data = starget->hostdata;
5932 sas_target_priv_data->flags |= MPT_TARGET_FLAGS_RAID_COMPONENT;
5934 sas_target_priv_data->flags &= ~MPT_TARGET_FLAGS_RAID_COMPONENT;
5936 starget_for_each_device(starget, no_uld_attach ? (void *)1 : NULL,
5937 _scsih_reprobe_lun);
5940 * _scsih_sas_volume_add - add new volume
5941 * @ioc: per adapter object
5942 * @element: IR config element data
5948 _scsih_sas_volume_add(struct MPT2SAS_ADAPTER *ioc,
5949 Mpi2EventIrConfigElement_t *element)
5951 struct _raid_device *raid_device;
5952 unsigned long flags;
5954 u16 handle = le16_to_cpu(element->VolDevHandle);
5957 mpt2sas_config_get_volume_wwid(ioc, handle, &wwid);
5959 printk(MPT2SAS_ERR_FMT
5960 "failure at %s:%d/%s()!\n", ioc->name,
5961 __FILE__, __LINE__, __func__);
5965 spin_lock_irqsave(&ioc->raid_device_lock, flags);
5966 raid_device = _scsih_raid_device_find_by_wwid(ioc, wwid);
5967 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
5972 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
5974 printk(MPT2SAS_ERR_FMT
5975 "failure at %s:%d/%s()!\n", ioc->name,
5976 __FILE__, __LINE__, __func__);
5980 raid_device->id = ioc->sas_id++;
5981 raid_device->channel = RAID_CHANNEL;
5982 raid_device->handle = handle;
5983 raid_device->wwid = wwid;
5984 _scsih_raid_device_add(ioc, raid_device);
5985 if (!ioc->wait_for_discovery_to_complete) {
5986 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
5987 raid_device->id, 0);
5989 _scsih_raid_device_remove(ioc, raid_device);
5991 _scsih_determine_boot_device(ioc, raid_device, 1);
5995 * _scsih_sas_volume_delete - delete volume
5996 * @ioc: per adapter object
5997 * @handle: volume device handle
6003 _scsih_sas_volume_delete(struct MPT2SAS_ADAPTER *ioc, u16 handle)
6005 struct _raid_device *raid_device;
6006 unsigned long flags;
6007 struct MPT2SAS_TARGET *sas_target_priv_data;
6009 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6010 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
6011 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6014 if (raid_device->starget) {
6015 sas_target_priv_data = raid_device->starget->hostdata;
6016 sas_target_priv_data->deleted = 1;
6017 scsi_remove_target(&raid_device->starget->dev);
6019 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), wwid"
6020 "(0x%016llx)\n", ioc->name, raid_device->handle,
6021 (unsigned long long) raid_device->wwid);
6022 _scsih_raid_device_remove(ioc, raid_device);
6026 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
6027 * @ioc: per adapter object
6028 * @element: IR config element data
6034 _scsih_sas_pd_expose(struct MPT2SAS_ADAPTER *ioc,
6035 Mpi2EventIrConfigElement_t *element)
6037 struct _sas_device *sas_device;
6038 unsigned long flags;
6039 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6041 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6042 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6043 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6047 /* exposing raid component */
6048 sas_device->volume_handle = 0;
6049 sas_device->volume_wwid = 0;
6050 clear_bit(handle, ioc->pd_handles);
6051 _scsih_reprobe_target(sas_device->starget, 0);
6055 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
6056 * @ioc: per adapter object
6057 * @element: IR config element data
6063 _scsih_sas_pd_hide(struct MPT2SAS_ADAPTER *ioc,
6064 Mpi2EventIrConfigElement_t *element)
6066 struct _sas_device *sas_device;
6067 unsigned long flags;
6068 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6070 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6071 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6072 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6076 /* hiding raid component */
6077 mpt2sas_config_get_volume_handle(ioc, handle,
6078 &sas_device->volume_handle);
6079 mpt2sas_config_get_volume_wwid(ioc, sas_device->volume_handle,
6080 &sas_device->volume_wwid);
6081 set_bit(handle, ioc->pd_handles);
6082 _scsih_reprobe_target(sas_device->starget, 1);
6087 * _scsih_sas_pd_delete - delete pd component
6088 * @ioc: per adapter object
6089 * @element: IR config element data
6095 _scsih_sas_pd_delete(struct MPT2SAS_ADAPTER *ioc,
6096 Mpi2EventIrConfigElement_t *element)
6098 struct _sas_device *sas_device;
6099 unsigned long flags;
6100 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6102 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6103 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6104 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6107 _scsih_remove_device(ioc, sas_device);
6111 * _scsih_sas_pd_add - remove pd component
6112 * @ioc: per adapter object
6113 * @element: IR config element data
6119 _scsih_sas_pd_add(struct MPT2SAS_ADAPTER *ioc,
6120 Mpi2EventIrConfigElement_t *element)
6122 struct _sas_device *sas_device;
6123 unsigned long flags;
6124 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6125 Mpi2ConfigReply_t mpi_reply;
6126 Mpi2SasDevicePage0_t sas_device_pg0;
6131 set_bit(handle, ioc->pd_handles);
6133 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6134 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6135 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6139 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
6140 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
6141 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6142 ioc->name, __FILE__, __LINE__, __func__);
6146 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6147 MPI2_IOCSTATUS_MASK;
6148 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6149 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6150 ioc->name, __FILE__, __LINE__, __func__);
6154 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6155 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
6156 mpt2sas_transport_update_links(ioc, sas_address, handle,
6157 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
6159 _scsih_add_device(ioc, handle, 0, 1);
6162 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6164 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
6165 * @ioc: per adapter object
6166 * @event_data: event data payload
6172 _scsih_sas_ir_config_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
6173 Mpi2EventDataIrConfigChangeList_t *event_data)
6175 Mpi2EventIrConfigElement_t *element;
6178 char *reason_str = NULL, *element_str = NULL;
6180 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
6182 printk(MPT2SAS_INFO_FMT "raid config change: (%s), elements(%d)\n",
6183 ioc->name, (le32_to_cpu(event_data->Flags) &
6184 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ?
6185 "foreign" : "native", event_data->NumElements);
6186 for (i = 0; i < event_data->NumElements; i++, element++) {
6187 switch (element->ReasonCode) {
6188 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
6191 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
6192 reason_str = "remove";
6194 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE:
6195 reason_str = "no change";
6197 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
6198 reason_str = "hide";
6200 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
6201 reason_str = "unhide";
6203 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
6204 reason_str = "volume_created";
6206 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
6207 reason_str = "volume_deleted";
6209 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
6210 reason_str = "pd_created";
6212 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
6213 reason_str = "pd_deleted";
6216 reason_str = "unknown reason";
6219 element_type = le16_to_cpu(element->ElementFlags) &
6220 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK;
6221 switch (element_type) {
6222 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT:
6223 element_str = "volume";
6225 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT:
6226 element_str = "phys disk";
6228 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT:
6229 element_str = "hot spare";
6232 element_str = "unknown element";
6235 printk(KERN_INFO "\t(%s:%s), vol handle(0x%04x), "
6236 "pd handle(0x%04x), pd num(0x%02x)\n", element_str,
6237 reason_str, le16_to_cpu(element->VolDevHandle),
6238 le16_to_cpu(element->PhysDiskDevHandle),
6239 element->PhysDiskNum);
6245 * _scsih_sas_ir_config_change_event - handle ir configuration change events
6246 * @ioc: per adapter object
6247 * @fw_event: The fw_event_work object
6253 _scsih_sas_ir_config_change_event(struct MPT2SAS_ADAPTER *ioc,
6254 struct fw_event_work *fw_event)
6256 Mpi2EventIrConfigElement_t *element;
6259 Mpi2EventDataIrConfigChangeList_t *event_data = fw_event->event_data;
6261 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6262 if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6263 && !ioc->hide_ir_msg)
6264 _scsih_sas_ir_config_change_event_debug(ioc, event_data);
6268 if (ioc->shost_recovery)
6271 foreign_config = (le32_to_cpu(event_data->Flags) &
6272 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0;
6274 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
6275 for (i = 0; i < event_data->NumElements; i++, element++) {
6277 switch (element->ReasonCode) {
6278 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
6279 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
6280 if (!foreign_config)
6281 _scsih_sas_volume_add(ioc, element);
6283 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
6284 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
6285 if (!foreign_config)
6286 _scsih_sas_volume_delete(ioc,
6287 le16_to_cpu(element->VolDevHandle));
6289 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
6290 if (!ioc->is_warpdrive)
6291 _scsih_sas_pd_hide(ioc, element);
6293 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
6294 if (!ioc->is_warpdrive)
6295 _scsih_sas_pd_expose(ioc, element);
6297 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
6298 if (!ioc->is_warpdrive)
6299 _scsih_sas_pd_add(ioc, element);
6301 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
6302 if (!ioc->is_warpdrive)
6303 _scsih_sas_pd_delete(ioc, element);
6310 * _scsih_sas_ir_volume_event - IR volume event
6311 * @ioc: per adapter object
6312 * @fw_event: The fw_event_work object
6318 _scsih_sas_ir_volume_event(struct MPT2SAS_ADAPTER *ioc,
6319 struct fw_event_work *fw_event)
6322 unsigned long flags;
6323 struct _raid_device *raid_device;
6327 Mpi2EventDataIrVolume_t *event_data = fw_event->event_data;
6329 if (ioc->shost_recovery)
6332 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
6335 handle = le16_to_cpu(event_data->VolDevHandle);
6336 state = le32_to_cpu(event_data->NewValue);
6337 if (!ioc->hide_ir_msg)
6338 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle(0x%04x), "
6339 "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle,
6340 le32_to_cpu(event_data->PreviousValue), state));
6343 case MPI2_RAID_VOL_STATE_MISSING:
6344 case MPI2_RAID_VOL_STATE_FAILED:
6345 _scsih_sas_volume_delete(ioc, handle);
6348 case MPI2_RAID_VOL_STATE_ONLINE:
6349 case MPI2_RAID_VOL_STATE_DEGRADED:
6350 case MPI2_RAID_VOL_STATE_OPTIMAL:
6352 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6353 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
6354 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6359 mpt2sas_config_get_volume_wwid(ioc, handle, &wwid);
6361 printk(MPT2SAS_ERR_FMT
6362 "failure at %s:%d/%s()!\n", ioc->name,
6363 __FILE__, __LINE__, __func__);
6367 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
6369 printk(MPT2SAS_ERR_FMT
6370 "failure at %s:%d/%s()!\n", ioc->name,
6371 __FILE__, __LINE__, __func__);
6375 raid_device->id = ioc->sas_id++;
6376 raid_device->channel = RAID_CHANNEL;
6377 raid_device->handle = handle;
6378 raid_device->wwid = wwid;
6379 _scsih_raid_device_add(ioc, raid_device);
6380 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
6381 raid_device->id, 0);
6383 _scsih_raid_device_remove(ioc, raid_device);
6386 case MPI2_RAID_VOL_STATE_INITIALIZING:
6393 * _scsih_sas_ir_physical_disk_event - PD event
6394 * @ioc: per adapter object
6395 * @fw_event: The fw_event_work object
6401 _scsih_sas_ir_physical_disk_event(struct MPT2SAS_ADAPTER *ioc,
6402 struct fw_event_work *fw_event)
6404 u16 handle, parent_handle;
6406 struct _sas_device *sas_device;
6407 unsigned long flags;
6408 Mpi2ConfigReply_t mpi_reply;
6409 Mpi2SasDevicePage0_t sas_device_pg0;
6411 Mpi2EventDataIrPhysicalDisk_t *event_data = fw_event->event_data;
6414 if (ioc->shost_recovery)
6417 if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED)
6420 handle = le16_to_cpu(event_data->PhysDiskDevHandle);
6421 state = le32_to_cpu(event_data->NewValue);
6423 if (!ioc->hide_ir_msg)
6424 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle(0x%04x), "
6425 "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle,
6426 le32_to_cpu(event_data->PreviousValue), state));
6429 case MPI2_RAID_PD_STATE_ONLINE:
6430 case MPI2_RAID_PD_STATE_DEGRADED:
6431 case MPI2_RAID_PD_STATE_REBUILDING:
6432 case MPI2_RAID_PD_STATE_OPTIMAL:
6433 case MPI2_RAID_PD_STATE_HOT_SPARE:
6435 if (!ioc->is_warpdrive)
6436 set_bit(handle, ioc->pd_handles);
6438 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6439 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6440 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6445 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6446 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
6448 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6449 ioc->name, __FILE__, __LINE__, __func__);
6453 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6454 MPI2_IOCSTATUS_MASK;
6455 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6456 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6457 ioc->name, __FILE__, __LINE__, __func__);
6461 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6462 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
6463 mpt2sas_transport_update_links(ioc, sas_address, handle,
6464 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
6466 _scsih_add_device(ioc, handle, 0, 1);
6470 case MPI2_RAID_PD_STATE_OFFLINE:
6471 case MPI2_RAID_PD_STATE_NOT_CONFIGURED:
6472 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE:
6478 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6480 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
6481 * @ioc: per adapter object
6482 * @event_data: event data payload
6488 _scsih_sas_ir_operation_status_event_debug(struct MPT2SAS_ADAPTER *ioc,
6489 Mpi2EventDataIrOperationStatus_t *event_data)
6491 char *reason_str = NULL;
6493 switch (event_data->RAIDOperation) {
6494 case MPI2_EVENT_IR_RAIDOP_RESYNC:
6495 reason_str = "resync";
6497 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION:
6498 reason_str = "online capacity expansion";
6500 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK:
6501 reason_str = "consistency check";
6503 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT:
6504 reason_str = "background init";
6506 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT:
6507 reason_str = "make data consistent";
6514 printk(MPT2SAS_INFO_FMT "raid operational status: (%s)"
6515 "\thandle(0x%04x), percent complete(%d)\n",
6516 ioc->name, reason_str,
6517 le16_to_cpu(event_data->VolDevHandle),
6518 event_data->PercentComplete);
6523 * _scsih_sas_ir_operation_status_event - handle RAID operation events
6524 * @ioc: per adapter object
6525 * @fw_event: The fw_event_work object
6531 _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
6532 struct fw_event_work *fw_event)
6534 Mpi2EventDataIrOperationStatus_t *event_data = fw_event->event_data;
6535 static struct _raid_device *raid_device;
6536 unsigned long flags;
6539 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6540 if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6541 && !ioc->hide_ir_msg)
6542 _scsih_sas_ir_operation_status_event_debug(ioc,
6546 /* code added for raid transport support */
6547 if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC) {
6549 handle = le16_to_cpu(event_data->VolDevHandle);
6551 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6552 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
6553 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6558 if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC)
6559 raid_device->percent_complete =
6560 event_data->PercentComplete;
6565 * _scsih_prep_device_scan - initialize parameters prior to device scan
6566 * @ioc: per adapter object
6568 * Set the deleted flag prior to device scan. If the device is found during
6569 * the scan, then we clear the deleted flag.
6572 _scsih_prep_device_scan(struct MPT2SAS_ADAPTER *ioc)
6574 struct MPT2SAS_DEVICE *sas_device_priv_data;
6575 struct scsi_device *sdev;
6577 shost_for_each_device(sdev, ioc->shost) {
6578 sas_device_priv_data = sdev->hostdata;
6579 if (sas_device_priv_data && sas_device_priv_data->sas_target)
6580 sas_device_priv_data->sas_target->deleted = 1;
6585 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
6586 * @ioc: per adapter object
6587 * @sas_address: sas address
6588 * @slot: enclosure slot id
6589 * @handle: device handle
6591 * After host reset, find out whether devices are still responding.
6592 * Used in _scsi_remove_unresponsive_sas_devices.
6597 _scsih_mark_responding_sas_device(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
6598 u16 slot, u16 handle)
6600 struct MPT2SAS_TARGET *sas_target_priv_data = NULL;
6601 struct scsi_target *starget;
6602 struct _sas_device *sas_device;
6603 unsigned long flags;
6605 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6606 list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
6607 if (sas_device->sas_address == sas_address &&
6608 sas_device->slot == slot) {
6609 sas_device->responding = 1;
6610 starget = sas_device->starget;
6611 if (starget && starget->hostdata) {
6612 sas_target_priv_data = starget->hostdata;
6613 sas_target_priv_data->tm_busy = 0;
6614 sas_target_priv_data->deleted = 0;
6616 sas_target_priv_data = NULL;
6618 starget_printk(KERN_INFO, starget,
6619 "handle(0x%04x), sas_addr(0x%016llx), "
6620 "enclosure logical id(0x%016llx), "
6621 "slot(%d)\n", handle,
6622 (unsigned long long)sas_device->sas_address,
6623 (unsigned long long)
6624 sas_device->enclosure_logical_id,
6626 if (sas_device->handle == handle)
6628 printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n",
6629 sas_device->handle);
6630 sas_device->handle = handle;
6631 if (sas_target_priv_data)
6632 sas_target_priv_data->handle = handle;
6637 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6641 * _scsih_search_responding_sas_devices -
6642 * @ioc: per adapter object
6644 * After host reset, find out whether devices are still responding.
6650 _scsih_search_responding_sas_devices(struct MPT2SAS_ADAPTER *ioc)
6652 Mpi2SasDevicePage0_t sas_device_pg0;
6653 Mpi2ConfigReply_t mpi_reply;
6660 printk(MPT2SAS_INFO_FMT "search for end-devices: start\n", ioc->name);
6662 if (list_empty(&ioc->sas_device_list))
6666 while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6667 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
6669 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6670 MPI2_IOCSTATUS_MASK;
6671 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
6673 handle = le16_to_cpu(sas_device_pg0.DevHandle);
6674 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
6675 if (!(_scsih_is_end_device(device_info)))
6677 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
6678 slot = le16_to_cpu(sas_device_pg0.Slot);
6679 _scsih_mark_responding_sas_device(ioc, sas_address, slot,
6683 printk(MPT2SAS_INFO_FMT "search for end-devices: complete\n",
6688 * _scsih_mark_responding_raid_device - mark a raid_device as responding
6689 * @ioc: per adapter object
6690 * @wwid: world wide identifier for raid volume
6691 * @handle: device handle
6693 * After host reset, find out whether devices are still responding.
6694 * Used in _scsi_remove_unresponsive_raid_devices.
6699 _scsih_mark_responding_raid_device(struct MPT2SAS_ADAPTER *ioc, u64 wwid,
6702 struct MPT2SAS_TARGET *sas_target_priv_data;
6703 struct scsi_target *starget;
6704 struct _raid_device *raid_device;
6705 unsigned long flags;
6707 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6708 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
6709 if (raid_device->wwid == wwid && raid_device->starget) {
6710 starget = raid_device->starget;
6711 if (starget && starget->hostdata) {
6712 sas_target_priv_data = starget->hostdata;
6713 sas_target_priv_data->deleted = 0;
6715 sas_target_priv_data = NULL;
6716 raid_device->responding = 1;
6717 starget_printk(KERN_INFO, raid_device->starget,
6718 "handle(0x%04x), wwid(0x%016llx)\n", handle,
6719 (unsigned long long)raid_device->wwid);
6721 * WARPDRIVE: The handles of the PDs might have changed
6722 * across the host reset so re-initialize the
6723 * required data for Direct IO
6725 _scsih_init_warpdrive_properties(ioc, raid_device);
6726 if (raid_device->handle == handle)
6728 printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n",
6729 raid_device->handle);
6730 raid_device->handle = handle;
6731 if (sas_target_priv_data)
6732 sas_target_priv_data->handle = handle;
6737 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6741 * _scsih_search_responding_raid_devices -
6742 * @ioc: per adapter object
6744 * After host reset, find out whether devices are still responding.
6750 _scsih_search_responding_raid_devices(struct MPT2SAS_ADAPTER *ioc)
6752 Mpi2RaidVolPage1_t volume_pg1;
6753 Mpi2RaidVolPage0_t volume_pg0;
6754 Mpi2RaidPhysDiskPage0_t pd_pg0;
6755 Mpi2ConfigReply_t mpi_reply;
6760 if (!ioc->ir_firmware)
6763 printk(MPT2SAS_INFO_FMT "search for raid volumes: start\n",
6766 if (list_empty(&ioc->raid_device_list))
6770 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
6771 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
6772 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6773 MPI2_IOCSTATUS_MASK;
6774 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
6776 handle = le16_to_cpu(volume_pg1.DevHandle);
6778 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
6779 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
6780 sizeof(Mpi2RaidVolPage0_t)))
6783 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
6784 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
6785 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED)
6786 _scsih_mark_responding_raid_device(ioc,
6787 le64_to_cpu(volume_pg1.WWID), handle);
6790 /* refresh the pd_handles */
6791 if (!ioc->is_warpdrive) {
6792 phys_disk_num = 0xFF;
6793 memset(ioc->pd_handles, 0, ioc->pd_handles_sz);
6794 while (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
6795 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
6797 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6798 MPI2_IOCSTATUS_MASK;
6799 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
6801 phys_disk_num = pd_pg0.PhysDiskNum;
6802 handle = le16_to_cpu(pd_pg0.DevHandle);
6803 set_bit(handle, ioc->pd_handles);
6807 printk(MPT2SAS_INFO_FMT "search for responding raid volumes: "
6808 "complete\n", ioc->name);
6812 * _scsih_mark_responding_expander - mark a expander as responding
6813 * @ioc: per adapter object
6814 * @sas_address: sas address
6817 * After host reset, find out whether devices are still responding.
6818 * Used in _scsi_remove_unresponsive_expanders.
6823 _scsih_mark_responding_expander(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
6826 struct _sas_node *sas_expander;
6827 unsigned long flags;
6830 spin_lock_irqsave(&ioc->sas_node_lock, flags);
6831 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
6832 if (sas_expander->sas_address != sas_address)
6834 sas_expander->responding = 1;
6835 if (sas_expander->handle == handle)
6837 printk(KERN_INFO "\texpander(0x%016llx): handle changed"
6838 " from(0x%04x) to (0x%04x)!!!\n",
6839 (unsigned long long)sas_expander->sas_address,
6840 sas_expander->handle, handle);
6841 sas_expander->handle = handle;
6842 for (i = 0 ; i < sas_expander->num_phys ; i++)
6843 sas_expander->phy[i].handle = handle;
6847 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
6851 * _scsih_search_responding_expanders -
6852 * @ioc: per adapter object
6854 * After host reset, find out whether devices are still responding.
6860 _scsih_search_responding_expanders(struct MPT2SAS_ADAPTER *ioc)
6862 Mpi2ExpanderPage0_t expander_pg0;
6863 Mpi2ConfigReply_t mpi_reply;
6868 printk(MPT2SAS_INFO_FMT "search for expanders: start\n", ioc->name);
6870 if (list_empty(&ioc->sas_expander_list))
6874 while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
6875 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
6877 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6878 MPI2_IOCSTATUS_MASK;
6879 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
6882 handle = le16_to_cpu(expander_pg0.DevHandle);
6883 sas_address = le64_to_cpu(expander_pg0.SASAddress);
6884 printk(KERN_INFO "\texpander present: handle(0x%04x), "
6885 "sas_addr(0x%016llx)\n", handle,
6886 (unsigned long long)sas_address);
6887 _scsih_mark_responding_expander(ioc, sas_address, handle);
6891 printk(MPT2SAS_INFO_FMT "search for expanders: complete\n", ioc->name);
6895 * _scsih_remove_unresponding_sas_devices - removing unresponding devices
6896 * @ioc: per adapter object
6901 _scsih_remove_unresponding_sas_devices(struct MPT2SAS_ADAPTER *ioc)
6903 struct _sas_device *sas_device, *sas_device_next;
6904 struct _sas_node *sas_expander;
6905 struct _raid_device *raid_device, *raid_device_next;
6907 printk(MPT2SAS_INFO_FMT "removing unresponding devices: start\n",
6910 list_for_each_entry_safe(sas_device, sas_device_next,
6911 &ioc->sas_device_list, list) {
6912 if (sas_device->responding) {
6913 sas_device->responding = 0;
6916 if (sas_device->starget)
6917 starget_printk(KERN_INFO, sas_device->starget,
6918 "removing: handle(0x%04x), sas_addr(0x%016llx), "
6919 "enclosure logical id(0x%016llx), slot(%d)\n",
6921 (unsigned long long)sas_device->sas_address,
6922 (unsigned long long)
6923 sas_device->enclosure_logical_id,
6925 _scsih_remove_device(ioc, sas_device);
6928 if (!ioc->ir_firmware)
6929 goto retry_expander_search;
6931 list_for_each_entry_safe(raid_device, raid_device_next,
6932 &ioc->raid_device_list, list) {
6933 if (raid_device->responding) {
6934 raid_device->responding = 0;
6937 if (raid_device->starget) {
6938 starget_printk(KERN_INFO, raid_device->starget,
6939 "removing: handle(0x%04x), wwid(0x%016llx)\n",
6940 raid_device->handle,
6941 (unsigned long long)raid_device->wwid);
6942 scsi_remove_target(&raid_device->starget->dev);
6944 _scsih_raid_device_remove(ioc, raid_device);
6947 retry_expander_search:
6948 sas_expander = NULL;
6949 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
6950 if (sas_expander->responding) {
6951 sas_expander->responding = 0;
6954 mpt2sas_expander_remove(ioc, sas_expander->sas_address);
6955 goto retry_expander_search;
6957 printk(MPT2SAS_INFO_FMT "removing unresponding devices: complete\n",
6959 /* unblock devices */
6960 _scsih_ublock_io_all_device(ioc);
6964 _scsih_refresh_expander_links(struct MPT2SAS_ADAPTER *ioc,
6965 struct _sas_node *sas_expander, u16 handle)
6967 Mpi2ExpanderPage1_t expander_pg1;
6968 Mpi2ConfigReply_t mpi_reply;
6971 for (i = 0 ; i < sas_expander->num_phys ; i++) {
6972 if ((mpt2sas_config_get_expander_pg1(ioc, &mpi_reply,
6973 &expander_pg1, i, handle))) {
6974 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6975 ioc->name, __FILE__, __LINE__, __func__);
6979 mpt2sas_transport_update_links(ioc, sas_expander->sas_address,
6980 le16_to_cpu(expander_pg1.AttachedDevHandle), i,
6981 expander_pg1.NegotiatedLinkRate >> 4);
6986 * _scsih_scan_for_devices_after_reset - scan for devices after host reset
6987 * @ioc: per adapter object
6992 _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
6994 Mpi2ExpanderPage0_t expander_pg0;
6995 Mpi2SasDevicePage0_t sas_device_pg0;
6996 Mpi2RaidVolPage1_t volume_pg1;
6997 Mpi2RaidVolPage0_t volume_pg0;
6998 Mpi2RaidPhysDiskPage0_t pd_pg0;
6999 Mpi2EventIrConfigElement_t element;
7000 Mpi2ConfigReply_t mpi_reply;
7003 u16 handle, parent_handle;
7005 struct _sas_device *sas_device;
7006 struct _sas_node *expander_device;
7007 static struct _raid_device *raid_device;
7009 printk(MPT2SAS_INFO_FMT "scan devices: start\n", ioc->name);
7011 _scsih_sas_host_refresh(ioc);
7015 while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
7016 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
7017 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7018 MPI2_IOCSTATUS_MASK;
7019 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
7021 handle = le16_to_cpu(expander_pg0.DevHandle);
7022 expander_device = mpt2sas_scsih_expander_find_by_sas_address(
7023 ioc, le64_to_cpu(expander_pg0.SASAddress));
7024 if (expander_device)
7025 _scsih_refresh_expander_links(ioc, expander_device,
7028 _scsih_expander_add(ioc, handle);
7031 if (!ioc->ir_firmware)
7035 phys_disk_num = 0xFF;
7036 while (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
7037 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
7039 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7040 MPI2_IOCSTATUS_MASK;
7041 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
7043 phys_disk_num = pd_pg0.PhysDiskNum;
7044 handle = le16_to_cpu(pd_pg0.DevHandle);
7045 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
7048 if (mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
7049 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
7052 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
7053 if (!_scsih_get_sas_address(ioc, parent_handle,
7055 mpt2sas_transport_update_links(ioc, sas_address,
7056 handle, sas_device_pg0.PhyNum,
7057 MPI2_SAS_NEG_LINK_RATE_1_5);
7058 set_bit(handle, ioc->pd_handles);
7059 _scsih_add_device(ioc, handle, 0, 1);
7065 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
7066 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
7067 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7068 MPI2_IOCSTATUS_MASK;
7069 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
7071 handle = le16_to_cpu(volume_pg1.DevHandle);
7072 raid_device = _scsih_raid_device_find_by_wwid(ioc,
7073 le64_to_cpu(volume_pg1.WWID));
7076 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
7077 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
7078 sizeof(Mpi2RaidVolPage0_t)))
7080 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
7081 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
7082 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) {
7083 memset(&element, 0, sizeof(Mpi2EventIrConfigElement_t));
7084 element.ReasonCode = MPI2_EVENT_IR_CHANGE_RC_ADDED;
7085 element.VolDevHandle = volume_pg1.DevHandle;
7086 _scsih_sas_volume_add(ioc, &element);
7094 while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
7095 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
7097 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7098 MPI2_IOCSTATUS_MASK;
7099 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
7101 handle = le16_to_cpu(sas_device_pg0.DevHandle);
7102 if (!(_scsih_is_end_device(
7103 le32_to_cpu(sas_device_pg0.DeviceInfo))))
7105 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
7106 le64_to_cpu(sas_device_pg0.SASAddress));
7109 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
7110 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) {
7111 mpt2sas_transport_update_links(ioc, sas_address, handle,
7112 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
7113 _scsih_add_device(ioc, handle, 0, 0);
7117 printk(MPT2SAS_INFO_FMT "scan devices: complete\n", ioc->name);
7122 * mpt2sas_scsih_reset_handler - reset callback handler (for scsih)
7123 * @ioc: per adapter object
7124 * @reset_phase: phase
7126 * The handler for doing any required cleanup or initialization.
7128 * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
7129 * MPT2_IOC_DONE_RESET
7134 mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase)
7136 switch (reset_phase) {
7137 case MPT2_IOC_PRE_RESET:
7138 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
7139 "MPT2_IOC_PRE_RESET\n", ioc->name, __func__));
7141 case MPT2_IOC_AFTER_RESET:
7142 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
7143 "MPT2_IOC_AFTER_RESET\n", ioc->name, __func__));
7144 if (ioc->scsih_cmds.status & MPT2_CMD_PENDING) {
7145 ioc->scsih_cmds.status |= MPT2_CMD_RESET;
7146 mpt2sas_base_free_smid(ioc, ioc->scsih_cmds.smid);
7147 complete(&ioc->scsih_cmds.done);
7149 if (ioc->tm_cmds.status & MPT2_CMD_PENDING) {
7150 ioc->tm_cmds.status |= MPT2_CMD_RESET;
7151 mpt2sas_base_free_smid(ioc, ioc->tm_cmds.smid);
7152 complete(&ioc->tm_cmds.done);
7154 _scsih_fw_event_cleanup_queue(ioc);
7155 _scsih_flush_running_cmds(ioc);
7157 case MPT2_IOC_DONE_RESET:
7158 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
7159 "MPT2_IOC_DONE_RESET\n", ioc->name, __func__));
7160 _scsih_sas_host_refresh(ioc);
7161 _scsih_prep_device_scan(ioc);
7162 _scsih_search_responding_sas_devices(ioc);
7163 _scsih_search_responding_raid_devices(ioc);
7164 _scsih_search_responding_expanders(ioc);
7165 if (!ioc->is_driver_loading) {
7166 _scsih_prep_device_scan(ioc);
7167 _scsih_search_responding_sas_devices(ioc);
7168 _scsih_search_responding_raid_devices(ioc);
7169 _scsih_search_responding_expanders(ioc);
7170 _scsih_error_recovery_delete_devices(ioc);
7177 * _firmware_event_work - delayed task for processing firmware events
7178 * @ioc: per adapter object
7179 * @work: equal to the fw_event_work object
7185 _firmware_event_work(struct work_struct *work)
7187 struct fw_event_work *fw_event = container_of(work,
7188 struct fw_event_work, delayed_work.work);
7189 struct MPT2SAS_ADAPTER *ioc = fw_event->ioc;
7191 /* the queue is being flushed so ignore this event */
7192 if (ioc->remove_host || fw_event->cancel_pending_work ||
7193 ioc->pci_error_recovery) {
7194 _scsih_fw_event_free(ioc, fw_event);
7198 switch (fw_event->event) {
7199 case MPT2SAS_REMOVE_UNRESPONDING_DEVICES:
7200 while (scsi_host_in_recovery(ioc->shost))
7202 _scsih_remove_unresponding_sas_devices(ioc);
7203 _scsih_scan_for_devices_after_reset(ioc);
7205 case MPT2SAS_PORT_ENABLE_COMPLETE:
7206 ioc->start_scan = 0;
7210 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "port enable: complete "
7211 "from worker thread\n", ioc->name));
7213 case MPT2SAS_TURN_ON_FAULT_LED:
7214 _scsih_turn_on_fault_led(ioc, fw_event->device_handle);
7216 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
7217 _scsih_sas_topology_change_event(ioc, fw_event);
7219 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
7220 _scsih_sas_device_status_change_event(ioc,
7223 case MPI2_EVENT_SAS_DISCOVERY:
7224 _scsih_sas_discovery_event(ioc,
7227 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
7228 _scsih_sas_broadcast_primative_event(ioc,
7231 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
7232 _scsih_sas_enclosure_dev_status_change_event(ioc,
7235 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
7236 _scsih_sas_ir_config_change_event(ioc, fw_event);
7238 case MPI2_EVENT_IR_VOLUME:
7239 _scsih_sas_ir_volume_event(ioc, fw_event);
7241 case MPI2_EVENT_IR_PHYSICAL_DISK:
7242 _scsih_sas_ir_physical_disk_event(ioc, fw_event);
7244 case MPI2_EVENT_IR_OPERATION_STATUS:
7245 _scsih_sas_ir_operation_status_event(ioc, fw_event);
7248 _scsih_fw_event_free(ioc, fw_event);
7252 * mpt2sas_scsih_event_callback - firmware event handler (called at ISR time)
7253 * @ioc: per adapter object
7254 * @msix_index: MSIX table index supplied by the OS
7255 * @reply: reply message frame(lower 32bit addr)
7256 * Context: interrupt.
7258 * This function merely adds a new work task into ioc->firmware_event_thread.
7259 * The tasks are worked from _firmware_event_work in user context.
7261 * Return 1 meaning mf should be freed from _base_interrupt
7262 * 0 means the mf is freed from this function.
7265 mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER *ioc, u8 msix_index,
7268 struct fw_event_work *fw_event;
7269 Mpi2EventNotificationReply_t *mpi_reply;
7273 /* events turned off due to host reset or driver unloading */
7274 if (ioc->remove_host || ioc->pci_error_recovery)
7277 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
7278 event = le16_to_cpu(mpi_reply->Event);
7282 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
7284 Mpi2EventDataSasBroadcastPrimitive_t *baen_data =
7285 (Mpi2EventDataSasBroadcastPrimitive_t *)
7286 mpi_reply->EventData;
7288 if (baen_data->Primitive !=
7289 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT)
7292 if (ioc->broadcast_aen_busy) {
7293 ioc->broadcast_aen_pending++;
7296 ioc->broadcast_aen_busy = 1;
7300 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
7301 _scsih_check_topo_delete_events(ioc,
7302 (Mpi2EventDataSasTopologyChangeList_t *)
7303 mpi_reply->EventData);
7305 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
7306 _scsih_check_ir_config_unhide_events(ioc,
7307 (Mpi2EventDataIrConfigChangeList_t *)
7308 mpi_reply->EventData);
7310 case MPI2_EVENT_IR_VOLUME:
7311 _scsih_check_volume_delete_events(ioc,
7312 (Mpi2EventDataIrVolume_t *)
7313 mpi_reply->EventData);
7315 case MPI2_EVENT_LOG_ENTRY_ADDED:
7317 Mpi2EventDataLogEntryAdded_t *log_entry;
7320 if (!ioc->is_warpdrive)
7323 log_entry = (Mpi2EventDataLogEntryAdded_t *)
7324 mpi_reply->EventData;
7325 log_code = (u32 *)log_entry->LogData;
7327 if (le16_to_cpu(log_entry->LogEntryQualifier)
7328 != MPT2_WARPDRIVE_LOGENTRY)
7331 switch (le32_to_cpu(*log_code)) {
7332 case MPT2_WARPDRIVE_LC_SSDT:
7333 printk(MPT2SAS_WARN_FMT "WarpDrive Warning: "
7334 "IO Throttling has occurred in the WarpDrive "
7335 "subsystem. Check WarpDrive documentation for "
7336 "additional details.\n", ioc->name);
7338 case MPT2_WARPDRIVE_LC_SSDLW:
7339 printk(MPT2SAS_WARN_FMT "WarpDrive Warning: "
7340 "Program/Erase Cycles for the WarpDrive subsystem "
7341 "in degraded range. Check WarpDrive documentation "
7342 "for additional details.\n", ioc->name);
7344 case MPT2_WARPDRIVE_LC_SSDLF:
7345 printk(MPT2SAS_ERR_FMT "WarpDrive Fatal Error: "
7346 "There are no Program/Erase Cycles for the "
7347 "WarpDrive subsystem. The storage device will be "
7348 "in read-only mode. Check WarpDrive documentation "
7349 "for additional details.\n", ioc->name);
7351 case MPT2_WARPDRIVE_LC_BRMF:
7352 printk(MPT2SAS_ERR_FMT "WarpDrive Fatal Error: "
7353 "The Backup Rail Monitor has failed on the "
7354 "WarpDrive subsystem. Check WarpDrive "
7355 "documentation for additional details.\n",
7362 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
7363 case MPI2_EVENT_IR_OPERATION_STATUS:
7364 case MPI2_EVENT_SAS_DISCOVERY:
7365 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
7366 case MPI2_EVENT_IR_PHYSICAL_DISK:
7369 default: /* ignore the rest */
7373 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
7375 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
7376 ioc->name, __FILE__, __LINE__, __func__);
7379 sz = le16_to_cpu(mpi_reply->EventDataLength) * 4;
7380 fw_event->event_data = kzalloc(sz, GFP_ATOMIC);
7381 if (!fw_event->event_data) {
7382 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
7383 ioc->name, __FILE__, __LINE__, __func__);
7388 memcpy(fw_event->event_data, mpi_reply->EventData,
7390 fw_event->ioc = ioc;
7391 fw_event->VF_ID = mpi_reply->VF_ID;
7392 fw_event->VP_ID = mpi_reply->VP_ID;
7393 fw_event->event = event;
7394 _scsih_fw_event_add(ioc, fw_event);
7398 /* shost template */
7399 static struct scsi_host_template scsih_driver_template = {
7400 .module = THIS_MODULE,
7401 .name = "Fusion MPT SAS Host",
7402 .proc_name = MPT2SAS_DRIVER_NAME,
7403 .queuecommand = _scsih_qcmd,
7404 .target_alloc = _scsih_target_alloc,
7405 .slave_alloc = _scsih_slave_alloc,
7406 .slave_configure = _scsih_slave_configure,
7407 .target_destroy = _scsih_target_destroy,
7408 .slave_destroy = _scsih_slave_destroy,
7409 .scan_finished = _scsih_scan_finished,
7410 .scan_start = _scsih_scan_start,
7411 .change_queue_depth = _scsih_change_queue_depth,
7412 .change_queue_type = _scsih_change_queue_type,
7413 .eh_abort_handler = _scsih_abort,
7414 .eh_device_reset_handler = _scsih_dev_reset,
7415 .eh_target_reset_handler = _scsih_target_reset,
7416 .eh_host_reset_handler = _scsih_host_reset,
7417 .bios_param = _scsih_bios_param,
7420 .sg_tablesize = MPT2SAS_SG_DEPTH,
7421 .max_sectors = 8192,
7423 .use_clustering = ENABLE_CLUSTERING,
7424 .shost_attrs = mpt2sas_host_attrs,
7425 .sdev_attrs = mpt2sas_dev_attrs,
7429 * _scsih_expander_node_remove - removing expander device from list.
7430 * @ioc: per adapter object
7431 * @sas_expander: the sas_device object
7432 * Context: Calling function should acquire ioc->sas_node_lock.
7434 * Removing object and freeing associated memory from the
7435 * ioc->sas_expander_list.
7440 _scsih_expander_node_remove(struct MPT2SAS_ADAPTER *ioc,
7441 struct _sas_node *sas_expander)
7443 struct _sas_port *mpt2sas_port, *next;
7445 /* remove sibling ports attached to this expander */
7446 list_for_each_entry_safe(mpt2sas_port, next,
7447 &sas_expander->sas_port_list, port_list) {
7448 if (ioc->shost_recovery)
7450 if (mpt2sas_port->remote_identify.device_type ==
7452 mpt2sas_device_remove(ioc,
7453 mpt2sas_port->remote_identify.sas_address);
7454 else if (mpt2sas_port->remote_identify.device_type ==
7455 SAS_EDGE_EXPANDER_DEVICE ||
7456 mpt2sas_port->remote_identify.device_type ==
7457 SAS_FANOUT_EXPANDER_DEVICE)
7458 mpt2sas_expander_remove(ioc,
7459 mpt2sas_port->remote_identify.sas_address);
7462 mpt2sas_transport_port_remove(ioc, sas_expander->sas_address,
7463 sas_expander->sas_address_parent);
7465 printk(MPT2SAS_INFO_FMT "expander_remove: handle"
7466 "(0x%04x), sas_addr(0x%016llx)\n", ioc->name,
7467 sas_expander->handle, (unsigned long long)
7468 sas_expander->sas_address);
7470 kfree(sas_expander->phy);
7471 kfree(sas_expander);
7475 * _scsih_ir_shutdown - IR shutdown notification
7476 * @ioc: per adapter object
7478 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
7479 * the host system is shutting down.
7484 _scsih_ir_shutdown(struct MPT2SAS_ADAPTER *ioc)
7486 Mpi2RaidActionRequest_t *mpi_request;
7487 Mpi2RaidActionReply_t *mpi_reply;
7490 /* is IR firmware build loaded ? */
7491 if (!ioc->ir_firmware)
7494 /* are there any volumes ? */
7495 if (list_empty(&ioc->raid_device_list))
7498 mutex_lock(&ioc->scsih_cmds.mutex);
7500 if (ioc->scsih_cmds.status != MPT2_CMD_NOT_USED) {
7501 printk(MPT2SAS_ERR_FMT "%s: scsih_cmd in use\n",
7502 ioc->name, __func__);
7505 ioc->scsih_cmds.status = MPT2_CMD_PENDING;
7507 smid = mpt2sas_base_get_smid(ioc, ioc->scsih_cb_idx);
7509 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
7510 ioc->name, __func__);
7511 ioc->scsih_cmds.status = MPT2_CMD_NOT_USED;
7515 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
7516 ioc->scsih_cmds.smid = smid;
7517 memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t));
7519 mpi_request->Function = MPI2_FUNCTION_RAID_ACTION;
7520 mpi_request->Action = MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED;
7522 if (!ioc->hide_ir_msg)
7523 printk(MPT2SAS_INFO_FMT "IR shutdown (sending)\n", ioc->name);
7524 init_completion(&ioc->scsih_cmds.done);
7525 mpt2sas_base_put_smid_default(ioc, smid);
7526 wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ);
7528 if (!(ioc->scsih_cmds.status & MPT2_CMD_COMPLETE)) {
7529 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
7530 ioc->name, __func__);
7534 if (ioc->scsih_cmds.status & MPT2_CMD_REPLY_VALID) {
7535 mpi_reply = ioc->scsih_cmds.reply;
7537 if (!ioc->hide_ir_msg)
7538 printk(MPT2SAS_INFO_FMT "IR shutdown (complete): "
7539 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7540 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
7541 le32_to_cpu(mpi_reply->IOCLogInfo));
7545 ioc->scsih_cmds.status = MPT2_CMD_NOT_USED;
7546 mutex_unlock(&ioc->scsih_cmds.mutex);
7550 * _scsih_shutdown - routine call during system shutdown
7551 * @pdev: PCI device struct
7556 _scsih_shutdown(struct pci_dev *pdev)
7558 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7559 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
7560 struct workqueue_struct *wq;
7561 unsigned long flags;
7563 ioc->remove_host = 1;
7564 _scsih_fw_event_cleanup_queue(ioc);
7566 spin_lock_irqsave(&ioc->fw_event_lock, flags);
7567 wq = ioc->firmware_event_thread;
7568 ioc->firmware_event_thread = NULL;
7569 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
7571 destroy_workqueue(wq);
7573 _scsih_ir_shutdown(ioc);
7574 mpt2sas_base_detach(ioc);
7578 * _scsih_remove - detach and remove add host
7579 * @pdev: PCI device struct
7581 * Routine called when unloading the driver.
7584 static void __devexit
7585 _scsih_remove(struct pci_dev *pdev)
7587 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7588 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
7589 struct _sas_port *mpt2sas_port, *next_port;
7590 struct _raid_device *raid_device, *next;
7591 struct MPT2SAS_TARGET *sas_target_priv_data;
7592 struct workqueue_struct *wq;
7593 unsigned long flags;
7595 ioc->remove_host = 1;
7596 _scsih_fw_event_cleanup_queue(ioc);
7598 spin_lock_irqsave(&ioc->fw_event_lock, flags);
7599 wq = ioc->firmware_event_thread;
7600 ioc->firmware_event_thread = NULL;
7601 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
7603 destroy_workqueue(wq);
7605 /* release all the volumes */
7606 _scsih_ir_shutdown(ioc);
7607 list_for_each_entry_safe(raid_device, next, &ioc->raid_device_list,
7609 if (raid_device->starget) {
7610 sas_target_priv_data =
7611 raid_device->starget->hostdata;
7612 sas_target_priv_data->deleted = 1;
7613 scsi_remove_target(&raid_device->starget->dev);
7615 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), wwid"
7616 "(0x%016llx)\n", ioc->name, raid_device->handle,
7617 (unsigned long long) raid_device->wwid);
7618 _scsih_raid_device_remove(ioc, raid_device);
7621 /* free ports attached to the sas_host */
7622 list_for_each_entry_safe(mpt2sas_port, next_port,
7623 &ioc->sas_hba.sas_port_list, port_list) {
7624 if (mpt2sas_port->remote_identify.device_type ==
7626 mpt2sas_device_remove(ioc,
7627 mpt2sas_port->remote_identify.sas_address);
7628 else if (mpt2sas_port->remote_identify.device_type ==
7629 SAS_EDGE_EXPANDER_DEVICE ||
7630 mpt2sas_port->remote_identify.device_type ==
7631 SAS_FANOUT_EXPANDER_DEVICE)
7632 mpt2sas_expander_remove(ioc,
7633 mpt2sas_port->remote_identify.sas_address);
7636 /* free phys attached to the sas_host */
7637 if (ioc->sas_hba.num_phys) {
7638 kfree(ioc->sas_hba.phy);
7639 ioc->sas_hba.phy = NULL;
7640 ioc->sas_hba.num_phys = 0;
7643 sas_remove_host(shost);
7644 mpt2sas_base_detach(ioc);
7645 list_del(&ioc->list);
7646 scsi_remove_host(shost);
7647 scsi_host_put(shost);
7651 * _scsih_probe_boot_devices - reports 1st device
7652 * @ioc: per adapter object
7654 * If specified in bios page 2, this routine reports the 1st
7655 * device scsi-ml or sas transport for persistent boot device
7656 * purposes. Please refer to function _scsih_determine_boot_device()
7659 _scsih_probe_boot_devices(struct MPT2SAS_ADAPTER *ioc)
7663 struct _sas_device *sas_device;
7664 struct _raid_device *raid_device;
7666 u64 sas_address_parent;
7668 unsigned long flags;
7671 /* no Bios, return immediately */
7672 if (!ioc->bios_pg3.BiosVersion)
7677 if (ioc->req_boot_device.device) {
7678 device = ioc->req_boot_device.device;
7679 is_raid = ioc->req_boot_device.is_raid;
7680 } else if (ioc->req_alt_boot_device.device) {
7681 device = ioc->req_alt_boot_device.device;
7682 is_raid = ioc->req_alt_boot_device.is_raid;
7683 } else if (ioc->current_boot_device.device) {
7684 device = ioc->current_boot_device.device;
7685 is_raid = ioc->current_boot_device.is_raid;
7692 raid_device = device;
7693 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
7694 raid_device->id, 0);
7696 _scsih_raid_device_remove(ioc, raid_device);
7698 sas_device = device;
7699 handle = sas_device->handle;
7700 sas_address_parent = sas_device->sas_address_parent;
7701 sas_address = sas_device->sas_address;
7702 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7703 list_move_tail(&sas_device->list, &ioc->sas_device_list);
7704 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7706 if (ioc->hide_drives)
7708 if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
7709 sas_device->sas_address_parent)) {
7710 _scsih_sas_device_remove(ioc, sas_device);
7711 } else if (!sas_device->starget) {
7712 if (!ioc->is_driver_loading)
7713 mpt2sas_transport_port_remove(ioc, sas_address,
7714 sas_address_parent);
7715 _scsih_sas_device_remove(ioc, sas_device);
7721 * _scsih_probe_raid - reporting raid volumes to scsi-ml
7722 * @ioc: per adapter object
7724 * Called during initial loading of the driver.
7727 _scsih_probe_raid(struct MPT2SAS_ADAPTER *ioc)
7729 struct _raid_device *raid_device, *raid_next;
7732 list_for_each_entry_safe(raid_device, raid_next,
7733 &ioc->raid_device_list, list) {
7734 if (raid_device->starget)
7736 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
7737 raid_device->id, 0);
7739 _scsih_raid_device_remove(ioc, raid_device);
7744 * _scsih_probe_sas - reporting sas devices to sas transport
7745 * @ioc: per adapter object
7747 * Called during initial loading of the driver.
7750 _scsih_probe_sas(struct MPT2SAS_ADAPTER *ioc)
7752 struct _sas_device *sas_device, *next;
7753 unsigned long flags;
7755 /* SAS Device List */
7756 list_for_each_entry_safe(sas_device, next, &ioc->sas_device_init_list,
7759 if (ioc->hide_drives)
7762 if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
7763 sas_device->sas_address_parent)) {
7764 list_del(&sas_device->list);
7767 } else if (!sas_device->starget) {
7768 if (!ioc->is_driver_loading)
7769 mpt2sas_transport_port_remove(ioc,
7770 sas_device->sas_address,
7771 sas_device->sas_address_parent);
7772 list_del(&sas_device->list);
7777 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7778 list_move_tail(&sas_device->list, &ioc->sas_device_list);
7779 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7784 * _scsih_probe_devices - probing for devices
7785 * @ioc: per adapter object
7787 * Called during initial loading of the driver.
7790 _scsih_probe_devices(struct MPT2SAS_ADAPTER *ioc)
7792 u16 volume_mapping_flags;
7794 if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR))
7795 return; /* return when IOC doesn't support initiator mode */
7797 _scsih_probe_boot_devices(ioc);
7799 if (ioc->ir_firmware) {
7800 volume_mapping_flags =
7801 le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) &
7802 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE;
7803 if (volume_mapping_flags ==
7804 MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING) {
7805 _scsih_probe_raid(ioc);
7806 _scsih_probe_sas(ioc);
7808 _scsih_probe_sas(ioc);
7809 _scsih_probe_raid(ioc);
7812 _scsih_probe_sas(ioc);
7817 * _scsih_scan_start - scsi lld callback for .scan_start
7818 * @shost: SCSI host pointer
7820 * The shost has the ability to discover targets on its own instead
7821 * of scanning the entire bus. In our implemention, we will kick off
7822 * firmware discovery.
7825 _scsih_scan_start(struct Scsi_Host *shost)
7827 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
7830 if (diag_buffer_enable != -1 && diag_buffer_enable != 0)
7831 mpt2sas_enable_diag_buffer(ioc, diag_buffer_enable);
7833 ioc->start_scan = 1;
7834 rc = mpt2sas_port_enable(ioc);
7837 printk(MPT2SAS_INFO_FMT "port enable: FAILED\n", ioc->name);
7841 * _scsih_scan_finished - scsi lld callback for .scan_finished
7842 * @shost: SCSI host pointer
7843 * @time: elapsed time of the scan in jiffies
7845 * This function will be called periodically until it returns 1 with the
7846 * scsi_host and the elapsed time of the scan in jiffies. In our implemention,
7847 * we wait for firmware discovery to complete, then return 1.
7850 _scsih_scan_finished(struct Scsi_Host *shost, unsigned long time)
7852 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
7854 if (time >= (300 * HZ)) {
7855 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
7856 printk(MPT2SAS_INFO_FMT "port enable: FAILED with timeout "
7857 "(timeout=300s)\n", ioc->name);
7858 ioc->is_driver_loading = 0;
7862 if (ioc->start_scan)
7865 if (ioc->start_scan_failed) {
7866 printk(MPT2SAS_INFO_FMT "port enable: FAILED with "
7867 "(ioc_status=0x%08x)\n", ioc->name, ioc->start_scan_failed);
7868 ioc->is_driver_loading = 0;
7869 ioc->wait_for_discovery_to_complete = 0;
7870 ioc->remove_host = 1;
7874 printk(MPT2SAS_INFO_FMT "port enable: SUCCESS\n", ioc->name);
7875 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
7877 if (ioc->wait_for_discovery_to_complete) {
7878 ioc->wait_for_discovery_to_complete = 0;
7879 _scsih_probe_devices(ioc);
7881 mpt2sas_base_start_watchdog(ioc);
7882 ioc->is_driver_loading = 0;
7888 * _scsih_probe - attach and add scsi host
7889 * @pdev: PCI device struct
7890 * @id: pci device id
7892 * Returns 0 success, anything else error.
7895 _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id)
7897 struct MPT2SAS_ADAPTER *ioc;
7898 struct Scsi_Host *shost;
7900 shost = scsi_host_alloc(&scsih_driver_template,
7901 sizeof(struct MPT2SAS_ADAPTER));
7905 /* init local params */
7906 ioc = shost_priv(shost);
7907 memset(ioc, 0, sizeof(struct MPT2SAS_ADAPTER));
7908 INIT_LIST_HEAD(&ioc->list);
7909 list_add_tail(&ioc->list, &mpt2sas_ioc_list);
7911 ioc->id = mpt_ids++;
7912 sprintf(ioc->name, "%s%d", MPT2SAS_DRIVER_NAME, ioc->id);
7914 if (id->device == MPI2_MFGPAGE_DEVID_SSS6200) {
7915 ioc->is_warpdrive = 1;
7916 ioc->hide_ir_msg = 1;
7918 ioc->mfg_pg10_hide_flag = MFG_PAGE10_EXPOSE_ALL_DISKS;
7919 ioc->scsi_io_cb_idx = scsi_io_cb_idx;
7920 ioc->tm_cb_idx = tm_cb_idx;
7921 ioc->ctl_cb_idx = ctl_cb_idx;
7922 ioc->base_cb_idx = base_cb_idx;
7923 ioc->port_enable_cb_idx = port_enable_cb_idx;
7924 ioc->transport_cb_idx = transport_cb_idx;
7925 ioc->scsih_cb_idx = scsih_cb_idx;
7926 ioc->config_cb_idx = config_cb_idx;
7927 ioc->tm_tr_cb_idx = tm_tr_cb_idx;
7928 ioc->tm_tr_volume_cb_idx = tm_tr_volume_cb_idx;
7929 ioc->tm_sas_control_cb_idx = tm_sas_control_cb_idx;
7930 ioc->logging_level = logging_level;
7931 /* misc semaphores and spin locks */
7932 mutex_init(&ioc->reset_in_progress_mutex);
7933 spin_lock_init(&ioc->ioc_reset_in_progress_lock);
7934 spin_lock_init(&ioc->scsi_lookup_lock);
7935 spin_lock_init(&ioc->sas_device_lock);
7936 spin_lock_init(&ioc->sas_node_lock);
7937 spin_lock_init(&ioc->fw_event_lock);
7938 spin_lock_init(&ioc->raid_device_lock);
7940 INIT_LIST_HEAD(&ioc->sas_device_list);
7941 INIT_LIST_HEAD(&ioc->sas_device_init_list);
7942 INIT_LIST_HEAD(&ioc->sas_expander_list);
7943 INIT_LIST_HEAD(&ioc->fw_event_list);
7944 INIT_LIST_HEAD(&ioc->raid_device_list);
7945 INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list);
7946 INIT_LIST_HEAD(&ioc->delayed_tr_list);
7947 INIT_LIST_HEAD(&ioc->delayed_tr_volume_list);
7949 /* init shost parameters */
7950 shost->max_cmd_len = 32;
7951 shost->max_lun = max_lun;
7952 shost->transportt = mpt2sas_transport_template;
7953 shost->unique_id = ioc->id;
7955 if (max_sectors != 0xFFFF) {
7956 if (max_sectors < 64) {
7957 shost->max_sectors = 64;
7958 printk(MPT2SAS_WARN_FMT "Invalid value %d passed "
7959 "for max_sectors, range is 64 to 8192. Assigning "
7960 "value of 64.\n", ioc->name, max_sectors);
7961 } else if (max_sectors > 8192) {
7962 shost->max_sectors = 8192;
7963 printk(MPT2SAS_WARN_FMT "Invalid value %d passed "
7964 "for max_sectors, range is 64 to 8192. Assigning "
7965 "default value of 8192.\n", ioc->name,
7968 shost->max_sectors = max_sectors & 0xFFFE;
7969 printk(MPT2SAS_INFO_FMT "The max_sectors value is "
7970 "set to %d\n", ioc->name, shost->max_sectors);
7974 if ((scsi_add_host(shost, &pdev->dev))) {
7975 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
7976 ioc->name, __FILE__, __LINE__, __func__);
7977 list_del(&ioc->list);
7978 goto out_add_shost_fail;
7981 scsi_host_set_prot(shost, SHOST_DIF_TYPE1_PROTECTION
7982 | SHOST_DIF_TYPE2_PROTECTION | SHOST_DIF_TYPE3_PROTECTION);
7983 scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC);
7986 snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name),
7987 "fw_event%d", ioc->id);
7988 ioc->firmware_event_thread = create_singlethread_workqueue(
7989 ioc->firmware_event_name);
7990 if (!ioc->firmware_event_thread) {
7991 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
7992 ioc->name, __FILE__, __LINE__, __func__);
7993 goto out_thread_fail;
7996 ioc->is_driver_loading = 1;
7997 if ((mpt2sas_base_attach(ioc))) {
7998 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
7999 ioc->name, __FILE__, __LINE__, __func__);
8000 goto out_attach_fail;
8003 scsi_scan_host(shost);
8004 if (ioc->is_warpdrive) {
8005 if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS)
8006 ioc->hide_drives = 0;
8007 else if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_HIDE_ALL_DISKS)
8008 ioc->hide_drives = 1;
8010 if (_scsih_get_num_volumes(ioc))
8011 ioc->hide_drives = 1;
8013 ioc->hide_drives = 0;
8016 ioc->hide_drives = 0;
8018 _scsih_probe_devices(ioc);
8022 destroy_workqueue(ioc->firmware_event_thread);
8024 list_del(&ioc->list);
8025 scsi_remove_host(shost);
8026 scsi_host_put(shost);
8033 * _scsih_suspend - power management suspend main entry point
8034 * @pdev: PCI device struct
8035 * @state: PM state change to (usually PCI_D3)
8037 * Returns 0 success, anything else error.
8040 _scsih_suspend(struct pci_dev *pdev, pm_message_t state)
8042 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8043 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8044 pci_power_t device_state;
8046 mpt2sas_base_stop_watchdog(ioc);
8047 scsi_block_requests(shost);
8048 device_state = pci_choose_state(pdev, state);
8049 printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, entering "
8050 "operating state [D%d]\n", ioc->name, pdev,
8051 pci_name(pdev), device_state);
8053 mpt2sas_base_free_resources(ioc);
8054 pci_save_state(pdev);
8055 pci_disable_device(pdev);
8056 pci_set_power_state(pdev, device_state);
8061 * _scsih_resume - power management resume main entry point
8062 * @pdev: PCI device struct
8064 * Returns 0 success, anything else error.
8067 _scsih_resume(struct pci_dev *pdev)
8069 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8070 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8071 pci_power_t device_state = pdev->current_state;
8074 printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, previous "
8075 "operating state [D%d]\n", ioc->name, pdev,
8076 pci_name(pdev), device_state);
8078 pci_set_power_state(pdev, PCI_D0);
8079 pci_enable_wake(pdev, PCI_D0, 0);
8080 pci_restore_state(pdev);
8082 r = mpt2sas_base_map_resources(ioc);
8086 mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, SOFT_RESET);
8087 scsi_unblock_requests(shost);
8088 mpt2sas_base_start_watchdog(ioc);
8091 #endif /* CONFIG_PM */
8094 * _scsih_pci_error_detected - Called when a PCI error is detected.
8095 * @pdev: PCI device struct
8096 * @state: PCI channel state
8098 * Description: Called when a PCI error is detected.
8101 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
8103 static pci_ers_result_t
8104 _scsih_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
8106 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8107 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8109 printk(MPT2SAS_INFO_FMT "PCI error: detected callback, state(%d)!!\n",
8113 case pci_channel_io_normal:
8114 return PCI_ERS_RESULT_CAN_RECOVER;
8115 case pci_channel_io_frozen:
8116 /* Fatal error, prepare for slot reset */
8117 ioc->pci_error_recovery = 1;
8118 scsi_block_requests(ioc->shost);
8119 mpt2sas_base_stop_watchdog(ioc);
8120 mpt2sas_base_free_resources(ioc);
8121 return PCI_ERS_RESULT_NEED_RESET;
8122 case pci_channel_io_perm_failure:
8123 /* Permanent error, prepare for device removal */
8124 ioc->pci_error_recovery = 1;
8125 mpt2sas_base_stop_watchdog(ioc);
8126 _scsih_flush_running_cmds(ioc);
8127 return PCI_ERS_RESULT_DISCONNECT;
8129 return PCI_ERS_RESULT_NEED_RESET;
8133 * _scsih_pci_slot_reset - Called when PCI slot has been reset.
8134 * @pdev: PCI device struct
8136 * Description: This routine is called by the pci error recovery
8137 * code after the PCI slot has been reset, just before we
8138 * should resume normal operations.
8140 static pci_ers_result_t
8141 _scsih_pci_slot_reset(struct pci_dev *pdev)
8143 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8144 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8147 printk(MPT2SAS_INFO_FMT "PCI error: slot reset callback!!\n",
8150 ioc->pci_error_recovery = 0;
8152 pci_restore_state(pdev);
8153 rc = mpt2sas_base_map_resources(ioc);
8155 return PCI_ERS_RESULT_DISCONNECT;
8158 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
8161 printk(MPT2SAS_WARN_FMT "hard reset: %s\n", ioc->name,
8162 (rc == 0) ? "success" : "failed");
8165 return PCI_ERS_RESULT_RECOVERED;
8167 return PCI_ERS_RESULT_DISCONNECT;
8171 * _scsih_pci_resume() - resume normal ops after PCI reset
8172 * @pdev: pointer to PCI device
8174 * Called when the error recovery driver tells us that its
8175 * OK to resume normal operation. Use completion to allow
8176 * halted scsi ops to resume.
8179 _scsih_pci_resume(struct pci_dev *pdev)
8181 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8182 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8184 printk(MPT2SAS_INFO_FMT "PCI error: resume callback!!\n", ioc->name);
8186 pci_cleanup_aer_uncorrect_error_status(pdev);
8187 mpt2sas_base_start_watchdog(ioc);
8188 scsi_unblock_requests(ioc->shost);
8192 * _scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
8193 * @pdev: pointer to PCI device
8195 static pci_ers_result_t
8196 _scsih_pci_mmio_enabled(struct pci_dev *pdev)
8198 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8199 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8201 printk(MPT2SAS_INFO_FMT "PCI error: mmio enabled callback!!\n",
8204 /* TODO - dump whatever for debugging purposes */
8206 /* Request a slot reset. */
8207 return PCI_ERS_RESULT_NEED_RESET;
8210 static struct pci_error_handlers _scsih_err_handler = {
8211 .error_detected = _scsih_pci_error_detected,
8212 .mmio_enabled = _scsih_pci_mmio_enabled,
8213 .slot_reset = _scsih_pci_slot_reset,
8214 .resume = _scsih_pci_resume,
8217 static struct pci_driver scsih_driver = {
8218 .name = MPT2SAS_DRIVER_NAME,
8219 .id_table = scsih_pci_table,
8220 .probe = _scsih_probe,
8221 .remove = __devexit_p(_scsih_remove),
8222 .shutdown = _scsih_shutdown,
8223 .err_handler = &_scsih_err_handler,
8225 .suspend = _scsih_suspend,
8226 .resume = _scsih_resume,
8230 /* raid transport support */
8231 static struct raid_function_template mpt2sas_raid_functions = {
8232 .cookie = &scsih_driver_template,
8233 .is_raid = _scsih_is_raid,
8234 .get_resync = _scsih_get_resync,
8235 .get_state = _scsih_get_state,
8239 * _scsih_init - main entry point for this driver.
8241 * Returns 0 success, anything else error.
8249 printk(KERN_INFO "%s version %s loaded\n", MPT2SAS_DRIVER_NAME,
8250 MPT2SAS_DRIVER_VERSION);
8252 mpt2sas_transport_template =
8253 sas_attach_transport(&mpt2sas_transport_functions);
8254 if (!mpt2sas_transport_template)
8256 /* raid transport support */
8257 mpt2sas_raid_template = raid_class_attach(&mpt2sas_raid_functions);
8258 if (!mpt2sas_raid_template) {
8259 sas_release_transport(mpt2sas_transport_template);
8263 mpt2sas_base_initialize_callback_handler();
8265 /* queuecommand callback hander */
8266 scsi_io_cb_idx = mpt2sas_base_register_callback_handler(_scsih_io_done);
8268 /* task management callback handler */
8269 tm_cb_idx = mpt2sas_base_register_callback_handler(_scsih_tm_done);
8271 /* base internal commands callback handler */
8272 base_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_base_done);
8273 port_enable_cb_idx = mpt2sas_base_register_callback_handler(
8274 mpt2sas_port_enable_done);
8276 /* transport internal commands callback handler */
8277 transport_cb_idx = mpt2sas_base_register_callback_handler(
8278 mpt2sas_transport_done);
8280 /* scsih internal commands callback handler */
8281 scsih_cb_idx = mpt2sas_base_register_callback_handler(_scsih_done);
8283 /* configuration page API internal commands callback handler */
8284 config_cb_idx = mpt2sas_base_register_callback_handler(
8285 mpt2sas_config_done);
8287 /* ctl module callback handler */
8288 ctl_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_ctl_done);
8290 tm_tr_cb_idx = mpt2sas_base_register_callback_handler(
8291 _scsih_tm_tr_complete);
8293 tm_tr_volume_cb_idx = mpt2sas_base_register_callback_handler(
8294 _scsih_tm_volume_tr_complete);
8296 tm_sas_control_cb_idx = mpt2sas_base_register_callback_handler(
8297 _scsih_sas_control_complete);
8301 error = pci_register_driver(&scsih_driver);
8303 /* raid transport support */
8304 raid_class_release(mpt2sas_raid_template);
8305 sas_release_transport(mpt2sas_transport_template);
8312 * _scsih_exit - exit point for this driver (when it is a module).
8314 * Returns 0 success, anything else error.
8319 printk(KERN_INFO "mpt2sas version %s unloading\n",
8320 MPT2SAS_DRIVER_VERSION);
8322 pci_unregister_driver(&scsih_driver);
8326 mpt2sas_base_release_callback_handler(scsi_io_cb_idx);
8327 mpt2sas_base_release_callback_handler(tm_cb_idx);
8328 mpt2sas_base_release_callback_handler(base_cb_idx);
8329 mpt2sas_base_release_callback_handler(port_enable_cb_idx);
8330 mpt2sas_base_release_callback_handler(transport_cb_idx);
8331 mpt2sas_base_release_callback_handler(scsih_cb_idx);
8332 mpt2sas_base_release_callback_handler(config_cb_idx);
8333 mpt2sas_base_release_callback_handler(ctl_cb_idx);
8335 mpt2sas_base_release_callback_handler(tm_tr_cb_idx);
8336 mpt2sas_base_release_callback_handler(tm_tr_volume_cb_idx);
8337 mpt2sas_base_release_callback_handler(tm_sas_control_cb_idx);
8339 /* raid transport support */
8340 raid_class_release(mpt2sas_raid_template);
8341 sas_release_transport(mpt2sas_transport_template);
8345 module_init(_scsih_init);
8346 module_exit(_scsih_exit);