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)
2805 fw_event->event = MPT2SAS_REMOVE_UNRESPONDING_DEVICES;
2806 fw_event->ioc = ioc;
2807 _scsih_fw_event_add(ioc, fw_event);
2811 * mpt2sas_port_enable_complete - port enable completed (fake event)
2812 * @ioc: per adapter object
2817 mpt2sas_port_enable_complete(struct MPT2SAS_ADAPTER *ioc)
2819 struct fw_event_work *fw_event;
2821 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
2824 fw_event->event = MPT2SAS_PORT_ENABLE_COMPLETE;
2825 fw_event->ioc = ioc;
2826 _scsih_fw_event_add(ioc, fw_event);
2830 * _scsih_fw_event_cleanup_queue - cleanup event queue
2831 * @ioc: per adapter object
2833 * Walk the firmware event queue, either killing timers, or waiting
2834 * for outstanding events to complete
2839 _scsih_fw_event_cleanup_queue(struct MPT2SAS_ADAPTER *ioc)
2841 struct fw_event_work *fw_event, *next;
2843 if (list_empty(&ioc->fw_event_list) ||
2844 !ioc->firmware_event_thread || in_interrupt())
2847 list_for_each_entry_safe(fw_event, next, &ioc->fw_event_list, list) {
2848 if (cancel_delayed_work(&fw_event->delayed_work)) {
2849 _scsih_fw_event_free(ioc, fw_event);
2852 fw_event->cancel_pending_work = 1;
2857 * _scsih_ublock_io_all_device - unblock every device
2858 * @ioc: per adapter object
2860 * change the device state from block to running
2863 _scsih_ublock_io_all_device(struct MPT2SAS_ADAPTER *ioc)
2865 struct MPT2SAS_DEVICE *sas_device_priv_data;
2866 struct scsi_device *sdev;
2868 shost_for_each_device(sdev, ioc->shost) {
2869 sas_device_priv_data = sdev->hostdata;
2870 if (!sas_device_priv_data)
2872 if (!sas_device_priv_data->block)
2874 sas_device_priv_data->block = 0;
2875 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, "device_running, "
2877 sas_device_priv_data->sas_target->handle));
2878 scsi_internal_device_unblock(sdev);
2882 * _scsih_ublock_io_device - set the device state to SDEV_RUNNING
2883 * @ioc: per adapter object
2884 * @handle: device handle
2886 * During device pull we need to appropiately set the sdev state.
2889 _scsih_ublock_io_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2891 struct MPT2SAS_DEVICE *sas_device_priv_data;
2892 struct scsi_device *sdev;
2894 shost_for_each_device(sdev, ioc->shost) {
2895 sas_device_priv_data = sdev->hostdata;
2896 if (!sas_device_priv_data)
2898 if (!sas_device_priv_data->block)
2900 if (sas_device_priv_data->sas_target->handle == handle) {
2901 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
2902 MPT2SAS_INFO_FMT "SDEV_RUNNING: "
2903 "handle(0x%04x)\n", ioc->name, handle));
2904 sas_device_priv_data->block = 0;
2905 scsi_internal_device_unblock(sdev);
2911 * _scsih_block_io_all_device - set the device state to SDEV_BLOCK
2912 * @ioc: per adapter object
2913 * @handle: device handle
2915 * During device pull we need to appropiately set the sdev state.
2918 _scsih_block_io_all_device(struct MPT2SAS_ADAPTER *ioc)
2920 struct MPT2SAS_DEVICE *sas_device_priv_data;
2921 struct scsi_device *sdev;
2923 shost_for_each_device(sdev, ioc->shost) {
2924 sas_device_priv_data = sdev->hostdata;
2925 if (!sas_device_priv_data)
2927 if (sas_device_priv_data->block)
2929 sas_device_priv_data->block = 1;
2930 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, "device_blocked, "
2932 sas_device_priv_data->sas_target->handle));
2933 scsi_internal_device_block(sdev);
2939 * _scsih_block_io_device - set the device state to SDEV_BLOCK
2940 * @ioc: per adapter object
2941 * @handle: device handle
2943 * During device pull we need to appropiately set the sdev state.
2946 _scsih_block_io_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2948 struct MPT2SAS_DEVICE *sas_device_priv_data;
2949 struct scsi_device *sdev;
2951 shost_for_each_device(sdev, ioc->shost) {
2952 sas_device_priv_data = sdev->hostdata;
2953 if (!sas_device_priv_data)
2955 if (sas_device_priv_data->block)
2957 if (sas_device_priv_data->sas_target->handle == handle) {
2958 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
2959 MPT2SAS_INFO_FMT "SDEV_BLOCK: "
2960 "handle(0x%04x)\n", ioc->name, handle));
2961 sas_device_priv_data->block = 1;
2962 scsi_internal_device_block(sdev);
2968 * _scsih_block_io_to_children_attached_to_ex
2969 * @ioc: per adapter object
2970 * @sas_expander: the sas_device object
2972 * This routine set sdev state to SDEV_BLOCK for all devices
2973 * attached to this expander. This function called when expander is
2977 _scsih_block_io_to_children_attached_to_ex(struct MPT2SAS_ADAPTER *ioc,
2978 struct _sas_node *sas_expander)
2980 struct _sas_port *mpt2sas_port;
2981 struct _sas_device *sas_device;
2982 struct _sas_node *expander_sibling;
2983 unsigned long flags;
2988 list_for_each_entry(mpt2sas_port,
2989 &sas_expander->sas_port_list, port_list) {
2990 if (mpt2sas_port->remote_identify.device_type ==
2992 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2994 mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
2995 mpt2sas_port->remote_identify.sas_address);
2996 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2999 _scsih_block_io_device(ioc, sas_device->handle);
3003 list_for_each_entry(mpt2sas_port,
3004 &sas_expander->sas_port_list, port_list) {
3006 if (mpt2sas_port->remote_identify.device_type ==
3007 SAS_EDGE_EXPANDER_DEVICE ||
3008 mpt2sas_port->remote_identify.device_type ==
3009 SAS_FANOUT_EXPANDER_DEVICE) {
3011 spin_lock_irqsave(&ioc->sas_node_lock, flags);
3013 mpt2sas_scsih_expander_find_by_sas_address(
3014 ioc, mpt2sas_port->remote_identify.sas_address);
3015 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
3016 _scsih_block_io_to_children_attached_to_ex(ioc,
3023 * _scsih_block_io_to_children_attached_directly
3024 * @ioc: per adapter object
3025 * @event_data: topology change event data
3027 * This routine set sdev state to SDEV_BLOCK for all devices
3028 * direct attached during device pull.
3031 _scsih_block_io_to_children_attached_directly(struct MPT2SAS_ADAPTER *ioc,
3032 Mpi2EventDataSasTopologyChangeList_t *event_data)
3039 for (i = 0; i < event_data->NumEntries; i++) {
3040 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
3043 phy_number = event_data->StartPhyNum + i;
3044 reason_code = event_data->PHY[i].PhyStatus &
3045 MPI2_EVENT_SAS_TOPO_RC_MASK;
3046 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING)
3047 _scsih_block_io_device(ioc, handle);
3052 * _scsih_tm_tr_send - send task management request
3053 * @ioc: per adapter object
3054 * @handle: device handle
3055 * Context: interrupt time.
3057 * This code is to initiate the device removal handshake protocol
3058 * with controller firmware. This function will issue target reset
3059 * using high priority request queue. It will send a sas iounit
3060 * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
3062 * This is designed to send muliple task management request at the same
3063 * time to the fifo. If the fifo is full, we will append the request,
3064 * and process it in a future completion.
3067 _scsih_tm_tr_send(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3069 Mpi2SCSITaskManagementRequest_t *mpi_request;
3071 struct _sas_device *sas_device;
3072 struct MPT2SAS_TARGET *sas_target_priv_data = NULL;
3073 u64 sas_address = 0;
3074 unsigned long flags;
3075 struct _tr_list *delayed_tr;
3078 if (ioc->remove_host) {
3079 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host has been "
3080 "removed: handle(0x%04x)\n", __func__, ioc->name, handle));
3082 } else if (ioc->pci_error_recovery) {
3083 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host in pci "
3084 "error recovery: handle(0x%04x)\n", __func__, ioc->name,
3088 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
3089 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3090 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host is not "
3091 "operational: handle(0x%04x)\n", __func__, ioc->name,
3096 /* if PD, then return */
3097 if (test_bit(handle, ioc->pd_handles))
3100 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3101 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
3102 if (sas_device && sas_device->starget &&
3103 sas_device->starget->hostdata) {
3104 sas_target_priv_data = sas_device->starget->hostdata;
3105 sas_target_priv_data->deleted = 1;
3106 sas_address = sas_device->sas_address;
3108 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3110 if (sas_target_priv_data) {
3111 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "setting delete flag: "
3112 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, handle,
3113 (unsigned long long)sas_address));
3114 _scsih_ublock_io_device(ioc, handle);
3115 sas_target_priv_data->handle = MPT2SAS_INVALID_DEVICE_HANDLE;
3118 smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_tr_cb_idx);
3120 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3123 INIT_LIST_HEAD(&delayed_tr->list);
3124 delayed_tr->handle = handle;
3125 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
3126 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3127 "DELAYED:tr:handle(0x%04x), (open)\n",
3128 ioc->name, handle));
3132 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "tr_send:handle(0x%04x), "
3133 "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid,
3134 ioc->tm_tr_cb_idx));
3135 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3136 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
3137 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3138 mpi_request->DevHandle = cpu_to_le16(handle);
3139 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
3140 mpt2sas_base_put_smid_hi_priority(ioc, smid);
3146 * _scsih_sas_control_complete - completion routine
3147 * @ioc: per adapter object
3148 * @smid: system request message index
3149 * @msix_index: MSIX table index supplied by the OS
3150 * @reply: reply message frame(lower 32bit addr)
3151 * Context: interrupt time.
3153 * This is the sas iounit control completion routine.
3154 * This code is part of the code to initiate the device removal
3155 * handshake protocol with controller firmware.
3157 * Return 1 meaning mf should be freed from _base_interrupt
3158 * 0 means the mf is freed from this function.
3161 _scsih_sas_control_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid,
3162 u8 msix_index, u32 reply)
3164 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3165 Mpi2SasIoUnitControlReply_t *mpi_reply =
3166 mpt2sas_base_get_reply_virt_addr(ioc, reply);
3168 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3169 "sc_complete:handle(0x%04x), (open) "
3170 "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
3171 ioc->name, le16_to_cpu(mpi_reply->DevHandle), smid,
3172 le16_to_cpu(mpi_reply->IOCStatus),
3173 le32_to_cpu(mpi_reply->IOCLogInfo)));
3178 * _scsih_tm_tr_volume_send - send target reset request for volumes
3179 * @ioc: per adapter object
3180 * @handle: device handle
3181 * Context: interrupt time.
3183 * This is designed to send muliple task management request at the same
3184 * time to the fifo. If the fifo is full, we will append the request,
3185 * and process it in a future completion.
3188 _scsih_tm_tr_volume_send(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3190 Mpi2SCSITaskManagementRequest_t *mpi_request;
3192 struct _tr_list *delayed_tr;
3194 if (ioc->shost_recovery || ioc->remove_host ||
3195 ioc->pci_error_recovery) {
3196 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in "
3197 "progress!\n", __func__, ioc->name));
3201 smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_tr_volume_cb_idx);
3203 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3206 INIT_LIST_HEAD(&delayed_tr->list);
3207 delayed_tr->handle = handle;
3208 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_volume_list);
3209 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3210 "DELAYED:tr:handle(0x%04x), (open)\n",
3211 ioc->name, handle));
3215 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "tr_send:handle(0x%04x), "
3216 "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid,
3217 ioc->tm_tr_volume_cb_idx));
3218 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3219 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
3220 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3221 mpi_request->DevHandle = cpu_to_le16(handle);
3222 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
3223 mpt2sas_base_put_smid_hi_priority(ioc, smid);
3227 * _scsih_tm_volume_tr_complete - target reset completion
3228 * @ioc: per adapter object
3229 * @smid: system request message index
3230 * @msix_index: MSIX table index supplied by the OS
3231 * @reply: reply message frame(lower 32bit addr)
3232 * Context: interrupt time.
3234 * Return 1 meaning mf should be freed from _base_interrupt
3235 * 0 means the mf is freed from this function.
3238 _scsih_tm_volume_tr_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid,
3239 u8 msix_index, u32 reply)
3242 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
3243 Mpi2SCSITaskManagementReply_t *mpi_reply =
3244 mpt2sas_base_get_reply_virt_addr(ioc, reply);
3246 if (ioc->shost_recovery || ioc->remove_host ||
3247 ioc->pci_error_recovery) {
3248 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in "
3249 "progress!\n", __func__, ioc->name));
3253 mpi_request_tm = mpt2sas_base_get_msg_frame(ioc, smid);
3254 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3255 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3256 dewtprintk(ioc, printk("spurious interrupt: "
3257 "handle(0x%04x:0x%04x), smid(%d)!!!\n", handle,
3258 le16_to_cpu(mpi_reply->DevHandle), smid));
3262 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3263 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3264 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3265 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3266 le32_to_cpu(mpi_reply->IOCLogInfo),
3267 le32_to_cpu(mpi_reply->TerminationCount)));
3269 return _scsih_check_for_pending_tm(ioc, smid);
3273 * _scsih_tm_tr_complete -
3274 * @ioc: per adapter object
3275 * @smid: system request message index
3276 * @msix_index: MSIX table index supplied by the OS
3277 * @reply: reply message frame(lower 32bit addr)
3278 * Context: interrupt time.
3280 * This is the target reset completion routine.
3281 * This code is part of the code to initiate the device removal
3282 * handshake protocol with controller firmware.
3283 * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE)
3285 * Return 1 meaning mf should be freed from _base_interrupt
3286 * 0 means the mf is freed from this function.
3289 _scsih_tm_tr_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
3293 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
3294 Mpi2SCSITaskManagementReply_t *mpi_reply =
3295 mpt2sas_base_get_reply_virt_addr(ioc, reply);
3296 Mpi2SasIoUnitControlRequest_t *mpi_request;
3300 if (ioc->remove_host) {
3301 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host has been "
3302 "removed\n", __func__, ioc->name));
3304 } else if (ioc->pci_error_recovery) {
3305 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host in pci "
3306 "error recovery\n", __func__, ioc->name));
3309 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
3310 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3311 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host is not "
3312 "operational\n", __func__, ioc->name));
3316 mpi_request_tm = mpt2sas_base_get_msg_frame(ioc, smid);
3317 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3318 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3319 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "spurious interrupt: "
3320 "handle(0x%04x:0x%04x), smid(%d)!!!\n", ioc->name, handle,
3321 le16_to_cpu(mpi_reply->DevHandle), smid));
3325 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3326 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3327 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3328 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3329 le32_to_cpu(mpi_reply->IOCLogInfo),
3330 le32_to_cpu(mpi_reply->TerminationCount)));
3332 smid_sas_ctrl = mpt2sas_base_get_smid(ioc, ioc->tm_sas_control_cb_idx);
3333 if (!smid_sas_ctrl) {
3334 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3335 ioc->name, __func__);
3339 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "sc_send:handle(0x%04x), "
3340 "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid_sas_ctrl,
3341 ioc->tm_sas_control_cb_idx));
3342 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid_sas_ctrl);
3343 memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t));
3344 mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL;
3345 mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE;
3346 mpi_request->DevHandle = mpi_request_tm->DevHandle;
3347 mpt2sas_base_put_smid_default(ioc, smid_sas_ctrl);
3349 return _scsih_check_for_pending_tm(ioc, smid);
3353 * _scsih_check_for_pending_tm - check for pending task management
3354 * @ioc: per adapter object
3355 * @smid: system request message index
3357 * This will check delayed target reset list, and feed the
3360 * Return 1 meaning mf should be freed from _base_interrupt
3361 * 0 means the mf is freed from this function.
3364 _scsih_check_for_pending_tm(struct MPT2SAS_ADAPTER *ioc, u16 smid)
3366 struct _tr_list *delayed_tr;
3368 if (!list_empty(&ioc->delayed_tr_volume_list)) {
3369 delayed_tr = list_entry(ioc->delayed_tr_volume_list.next,
3370 struct _tr_list, list);
3371 mpt2sas_base_free_smid(ioc, smid);
3372 _scsih_tm_tr_volume_send(ioc, delayed_tr->handle);
3373 list_del(&delayed_tr->list);
3378 if (!list_empty(&ioc->delayed_tr_list)) {
3379 delayed_tr = list_entry(ioc->delayed_tr_list.next,
3380 struct _tr_list, list);
3381 mpt2sas_base_free_smid(ioc, smid);
3382 _scsih_tm_tr_send(ioc, delayed_tr->handle);
3383 list_del(&delayed_tr->list);
3392 * _scsih_check_topo_delete_events - sanity check on topo events
3393 * @ioc: per adapter object
3394 * @event_data: the event data payload
3396 * This routine added to better handle cable breaker.
3398 * This handles the case where driver receives multiple expander
3399 * add and delete events in a single shot. When there is a delete event
3400 * the routine will void any pending add events waiting in the event queue.
3405 _scsih_check_topo_delete_events(struct MPT2SAS_ADAPTER *ioc,
3406 Mpi2EventDataSasTopologyChangeList_t *event_data)
3408 struct fw_event_work *fw_event;
3409 Mpi2EventDataSasTopologyChangeList_t *local_event_data;
3410 u16 expander_handle;
3411 struct _sas_node *sas_expander;
3412 unsigned long flags;
3416 for (i = 0 ; i < event_data->NumEntries; i++) {
3417 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
3420 reason_code = event_data->PHY[i].PhyStatus &
3421 MPI2_EVENT_SAS_TOPO_RC_MASK;
3422 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING)
3423 _scsih_tm_tr_send(ioc, handle);
3426 expander_handle = le16_to_cpu(event_data->ExpanderDevHandle);
3427 if (expander_handle < ioc->sas_hba.num_phys) {
3428 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3432 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
3433 || event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING) {
3434 spin_lock_irqsave(&ioc->sas_node_lock, flags);
3435 sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc,
3437 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
3438 _scsih_block_io_to_children_attached_to_ex(ioc, sas_expander);
3439 } else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING)
3440 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3442 if (event_data->ExpStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING)
3445 /* mark ignore flag for pending events */
3446 spin_lock_irqsave(&ioc->fw_event_lock, flags);
3447 list_for_each_entry(fw_event, &ioc->fw_event_list, list) {
3448 if (fw_event->event != MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST ||
3451 local_event_data = fw_event->event_data;
3452 if (local_event_data->ExpStatus ==
3453 MPI2_EVENT_SAS_TOPO_ES_ADDED ||
3454 local_event_data->ExpStatus ==
3455 MPI2_EVENT_SAS_TOPO_ES_RESPONDING) {
3456 if (le16_to_cpu(local_event_data->ExpanderDevHandle) ==
3458 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3459 "setting ignoring flag\n", ioc->name));
3460 fw_event->ignore = 1;
3464 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
3468 * _scsih_set_volume_delete_flag - setting volume delete flag
3469 * @ioc: per adapter object
3470 * @handle: device handle
3476 _scsih_set_volume_delete_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3478 struct _raid_device *raid_device;
3479 struct MPT2SAS_TARGET *sas_target_priv_data;
3480 unsigned long flags;
3482 spin_lock_irqsave(&ioc->raid_device_lock, flags);
3483 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
3484 if (raid_device && raid_device->starget &&
3485 raid_device->starget->hostdata) {
3486 sas_target_priv_data =
3487 raid_device->starget->hostdata;
3488 sas_target_priv_data->deleted = 1;
3489 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3490 "setting delete flag: handle(0x%04x), "
3491 "wwid(0x%016llx)\n", ioc->name, handle,
3492 (unsigned long long) raid_device->wwid));
3494 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
3498 * _scsih_set_volume_handle_for_tr - set handle for target reset to volume
3499 * @handle: input handle
3500 * @a: handle for volume a
3501 * @b: handle for volume b
3503 * IR firmware only supports two raid volumes. The purpose of this
3504 * routine is to set the volume handle in either a or b. When the given
3505 * input handle is non-zero, or when a and b have not been set before.
3508 _scsih_set_volume_handle_for_tr(u16 handle, u16 *a, u16 *b)
3510 if (!handle || handle == *a || handle == *b)
3519 * _scsih_check_ir_config_unhide_events - check for UNHIDE events
3520 * @ioc: per adapter object
3521 * @event_data: the event data payload
3522 * Context: interrupt time.
3524 * This routine will send target reset to volume, followed by target
3525 * resets to the PDs. This is called when a PD has been removed, or
3526 * volume has been deleted or removed. When the target reset is sent
3527 * to volume, the PD target resets need to be queued to start upon
3528 * completion of the volume target reset.
3533 _scsih_check_ir_config_unhide_events(struct MPT2SAS_ADAPTER *ioc,
3534 Mpi2EventDataIrConfigChangeList_t *event_data)
3536 Mpi2EventIrConfigElement_t *element;
3538 u16 handle, volume_handle, a, b;
3539 struct _tr_list *delayed_tr;
3544 if (ioc->is_warpdrive)
3547 /* Volume Resets for Deleted or Removed */
3548 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3549 for (i = 0; i < event_data->NumElements; i++, element++) {
3550 if (element->ReasonCode ==
3551 MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED ||
3552 element->ReasonCode ==
3553 MPI2_EVENT_IR_CHANGE_RC_REMOVED) {
3554 volume_handle = le16_to_cpu(element->VolDevHandle);
3555 _scsih_set_volume_delete_flag(ioc, volume_handle);
3556 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3560 /* Volume Resets for UNHIDE events */
3561 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3562 for (i = 0; i < event_data->NumElements; i++, element++) {
3563 if (le32_to_cpu(event_data->Flags) &
3564 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG)
3566 if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_UNHIDE) {
3567 volume_handle = le16_to_cpu(element->VolDevHandle);
3568 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3573 _scsih_tm_tr_volume_send(ioc, a);
3575 _scsih_tm_tr_volume_send(ioc, b);
3577 /* PD target resets */
3578 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3579 for (i = 0; i < event_data->NumElements; i++, element++) {
3580 if (element->ReasonCode != MPI2_EVENT_IR_CHANGE_RC_UNHIDE)
3582 handle = le16_to_cpu(element->PhysDiskDevHandle);
3583 volume_handle = le16_to_cpu(element->VolDevHandle);
3584 clear_bit(handle, ioc->pd_handles);
3586 _scsih_tm_tr_send(ioc, handle);
3587 else if (volume_handle == a || volume_handle == b) {
3588 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3589 BUG_ON(!delayed_tr);
3590 INIT_LIST_HEAD(&delayed_tr->list);
3591 delayed_tr->handle = handle;
3592 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
3593 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3594 "DELAYED:tr:handle(0x%04x), (open)\n", ioc->name,
3597 _scsih_tm_tr_send(ioc, handle);
3603 * _scsih_check_volume_delete_events - set delete flag for volumes
3604 * @ioc: per adapter object
3605 * @event_data: the event data payload
3606 * Context: interrupt time.
3608 * This will handle the case when the cable connected to entire volume is
3609 * pulled. We will take care of setting the deleted flag so normal IO will
3615 _scsih_check_volume_delete_events(struct MPT2SAS_ADAPTER *ioc,
3616 Mpi2EventDataIrVolume_t *event_data)
3620 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
3622 state = le32_to_cpu(event_data->NewValue);
3623 if (state == MPI2_RAID_VOL_STATE_MISSING || state ==
3624 MPI2_RAID_VOL_STATE_FAILED)
3625 _scsih_set_volume_delete_flag(ioc,
3626 le16_to_cpu(event_data->VolDevHandle));
3630 * _scsih_flush_running_cmds - completing outstanding commands.
3631 * @ioc: per adapter object
3633 * The flushing out of all pending scmd commands following host reset,
3634 * where all IO is dropped to the floor.
3639 _scsih_flush_running_cmds(struct MPT2SAS_ADAPTER *ioc)
3641 struct scsi_cmnd *scmd;
3645 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
3646 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
3650 mpt2sas_base_free_smid(ioc, smid);
3651 scsi_dma_unmap(scmd);
3652 if (ioc->pci_error_recovery)
3653 scmd->result = DID_NO_CONNECT << 16;
3655 scmd->result = DID_RESET << 16;
3656 scmd->scsi_done(scmd);
3658 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "completing %d cmds\n",
3663 * _scsih_setup_eedp - setup MPI request for EEDP transfer
3664 * @scmd: pointer to scsi command object
3665 * @mpi_request: pointer to the SCSI_IO reqest message frame
3667 * Supporting protection 1 and 3.
3672 _scsih_setup_eedp(struct scsi_cmnd *scmd, Mpi2SCSIIORequest_t *mpi_request)
3675 unsigned char prot_op = scsi_get_prot_op(scmd);
3676 unsigned char prot_type = scsi_get_prot_type(scmd);
3678 if (prot_type == SCSI_PROT_DIF_TYPE0 || prot_op == SCSI_PROT_NORMAL)
3681 if (prot_op == SCSI_PROT_READ_STRIP)
3682 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP;
3683 else if (prot_op == SCSI_PROT_WRITE_INSERT)
3684 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_INSERT_OP;
3688 switch (prot_type) {
3689 case SCSI_PROT_DIF_TYPE1:
3690 case SCSI_PROT_DIF_TYPE2:
3693 * enable ref/guard checking
3694 * auto increment ref tag
3696 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG |
3697 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG |
3698 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
3699 mpi_request->CDB.EEDP32.PrimaryReferenceTag =
3700 cpu_to_be32(scsi_get_lba(scmd));
3703 case SCSI_PROT_DIF_TYPE3:
3706 * enable guard checking
3708 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
3711 mpi_request->EEDPBlockSize = cpu_to_le32(scmd->device->sector_size);
3712 mpi_request->EEDPFlags = cpu_to_le16(eedp_flags);
3716 * _scsih_eedp_error_handling - return sense code for EEDP errors
3717 * @scmd: pointer to scsi command object
3718 * @ioc_status: ioc status
3723 _scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status)
3729 switch (ioc_status) {
3730 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
3733 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
3736 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
3744 if (scmd->sc_data_direction == DMA_TO_DEVICE) {
3745 sk = ILLEGAL_REQUEST;
3746 host_byte = DID_ABORT;
3748 sk = ABORTED_COMMAND;
3752 scsi_build_sense_buffer(0, scmd->sense_buffer, sk, 0x10, ascq);
3753 scmd->result = DRIVER_SENSE << 24 | (host_byte << 16) |
3754 SAM_STAT_CHECK_CONDITION;
3758 * _scsih_scsi_direct_io_get - returns direct io flag
3759 * @ioc: per adapter object
3760 * @smid: system request message index
3762 * Returns the smid stored scmd pointer.
3765 _scsih_scsi_direct_io_get(struct MPT2SAS_ADAPTER *ioc, u16 smid)
3767 return ioc->scsi_lookup[smid - 1].direct_io;
3771 * _scsih_scsi_direct_io_set - sets direct io flag
3772 * @ioc: per adapter object
3773 * @smid: system request message index
3774 * @direct_io: Zero or non-zero value to set in the direct_io flag
3779 _scsih_scsi_direct_io_set(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 direct_io)
3781 ioc->scsi_lookup[smid - 1].direct_io = direct_io;
3786 * _scsih_setup_direct_io - setup MPI request for WARPDRIVE Direct I/O
3787 * @ioc: per adapter object
3788 * @scmd: pointer to scsi command object
3789 * @raid_device: pointer to raid device data structure
3790 * @mpi_request: pointer to the SCSI_IO reqest message frame
3791 * @smid: system request message index
3796 _scsih_setup_direct_io(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
3797 struct _raid_device *raid_device, Mpi2SCSIIORequest_t *mpi_request,
3800 u32 v_lba, p_lba, stripe_off, stripe_unit, column, io_size;
3801 u32 stripe_sz, stripe_exp;
3802 u8 num_pds, *cdb_ptr, *tmp_ptr, *lba_ptr1, *lba_ptr2;
3803 u8 cdb0 = scmd->cmnd[0];
3806 * Try Direct I/O to RAID memeber disks
3808 if (cdb0 == READ_16 || cdb0 == READ_10 ||
3809 cdb0 == WRITE_16 || cdb0 == WRITE_10) {
3810 cdb_ptr = mpi_request->CDB.CDB32;
3812 if ((cdb0 < READ_16) || !(cdb_ptr[2] | cdb_ptr[3] | cdb_ptr[4]
3814 io_size = scsi_bufflen(scmd) >> 9;
3815 /* get virtual lba */
3816 lba_ptr1 = lba_ptr2 = (cdb0 < READ_16) ? &cdb_ptr[2] :
3818 tmp_ptr = (u8 *)&v_lba + 3;
3819 *tmp_ptr-- = *lba_ptr1++;
3820 *tmp_ptr-- = *lba_ptr1++;
3821 *tmp_ptr-- = *lba_ptr1++;
3822 *tmp_ptr = *lba_ptr1;
3824 if (((u64)v_lba + (u64)io_size - 1) <=
3825 (u32)raid_device->max_lba) {
3826 stripe_sz = raid_device->stripe_sz;
3827 stripe_exp = raid_device->stripe_exponent;
3828 stripe_off = v_lba & (stripe_sz - 1);
3830 /* Check whether IO falls within a stripe */
3831 if ((stripe_off + io_size) <= stripe_sz) {
3832 num_pds = raid_device->num_pds;
3833 p_lba = v_lba >> stripe_exp;
3834 stripe_unit = p_lba / num_pds;
3835 column = p_lba % num_pds;
3836 p_lba = (stripe_unit << stripe_exp) +
3838 mpi_request->DevHandle =
3839 cpu_to_le16(raid_device->
3841 tmp_ptr = (u8 *)&p_lba + 3;
3842 *lba_ptr2++ = *tmp_ptr--;
3843 *lba_ptr2++ = *tmp_ptr--;
3844 *lba_ptr2++ = *tmp_ptr--;
3845 *lba_ptr2 = *tmp_ptr;
3847 * WD: To indicate this I/O is directI/O
3849 _scsih_scsi_direct_io_set(ioc, smid, 1);
3857 * _scsih_qcmd - main scsi request entry point
3858 * @scmd: pointer to scsi command object
3859 * @done: function pointer to be invoked on completion
3861 * The callback index is set inside `ioc->scsi_io_cb_idx`.
3863 * Returns 0 on success. If there's a failure, return either:
3864 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
3865 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
3868 _scsih_qcmd_lck(struct scsi_cmnd *scmd, void (*done)(struct scsi_cmnd *))
3870 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
3871 struct MPT2SAS_DEVICE *sas_device_priv_data;
3872 struct MPT2SAS_TARGET *sas_target_priv_data;
3873 struct _raid_device *raid_device;
3874 Mpi2SCSIIORequest_t *mpi_request;
3878 scmd->scsi_done = done;
3879 sas_device_priv_data = scmd->device->hostdata;
3880 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
3881 scmd->result = DID_NO_CONNECT << 16;
3882 scmd->scsi_done(scmd);
3886 if (ioc->pci_error_recovery || ioc->remove_host) {
3887 scmd->result = DID_NO_CONNECT << 16;
3888 scmd->scsi_done(scmd);
3892 sas_target_priv_data = sas_device_priv_data->sas_target;
3893 /* invalid device handle */
3894 if (sas_target_priv_data->handle == MPT2SAS_INVALID_DEVICE_HANDLE) {
3895 scmd->result = DID_NO_CONNECT << 16;
3896 scmd->scsi_done(scmd);
3900 /* host recovery or link resets sent via IOCTLs */
3901 if (ioc->shost_recovery || ioc->ioc_link_reset_in_progress)
3902 return SCSI_MLQUEUE_HOST_BUSY;
3903 /* device busy with task management */
3904 else if (sas_device_priv_data->block || sas_target_priv_data->tm_busy)
3905 return SCSI_MLQUEUE_DEVICE_BUSY;
3906 /* device has been deleted */
3907 else if (sas_target_priv_data->deleted) {
3908 scmd->result = DID_NO_CONNECT << 16;
3909 scmd->scsi_done(scmd);
3913 if (scmd->sc_data_direction == DMA_FROM_DEVICE)
3914 mpi_control = MPI2_SCSIIO_CONTROL_READ;
3915 else if (scmd->sc_data_direction == DMA_TO_DEVICE)
3916 mpi_control = MPI2_SCSIIO_CONTROL_WRITE;
3918 mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER;
3921 if (!(sas_device_priv_data->flags & MPT_DEVICE_FLAGS_INIT)) {
3922 if (scmd->device->tagged_supported) {
3923 if (scmd->device->ordered_tags)
3924 mpi_control |= MPI2_SCSIIO_CONTROL_ORDEREDQ;
3926 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
3928 /* MPI Revision I (UNIT = 0xA) - removed MPI2_SCSIIO_CONTROL_UNTAGGED */
3929 /* mpi_control |= MPI2_SCSIIO_CONTROL_UNTAGGED;
3931 mpi_control |= (0x500);
3934 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
3935 /* Make sure Device is not raid volume.
3936 * We do not expose raid functionality to upper layer for warpdrive.
3938 if (!ioc->is_warpdrive && !_scsih_is_raid(&scmd->device->sdev_gendev) &&
3939 sas_is_tlr_enabled(scmd->device) && scmd->cmd_len != 32)
3940 mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON;
3942 smid = mpt2sas_base_get_smid_scsiio(ioc, ioc->scsi_io_cb_idx, scmd);
3944 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3945 ioc->name, __func__);
3948 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3949 memset(mpi_request, 0, sizeof(Mpi2SCSIIORequest_t));
3950 _scsih_setup_eedp(scmd, mpi_request);
3951 if (scmd->cmd_len == 32)
3952 mpi_control |= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT;
3953 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
3954 if (sas_device_priv_data->sas_target->flags &
3955 MPT_TARGET_FLAGS_RAID_COMPONENT)
3956 mpi_request->Function = MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;
3958 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
3959 mpi_request->DevHandle =
3960 cpu_to_le16(sas_device_priv_data->sas_target->handle);
3961 mpi_request->DataLength = cpu_to_le32(scsi_bufflen(scmd));
3962 mpi_request->Control = cpu_to_le32(mpi_control);
3963 mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len);
3964 mpi_request->MsgFlags = MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR;
3965 mpi_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE;
3966 mpi_request->SenseBufferLowAddress =
3967 mpt2sas_base_get_sense_buffer_dma(ioc, smid);
3968 mpi_request->SGLOffset0 = offsetof(Mpi2SCSIIORequest_t, SGL) / 4;
3969 mpi_request->SGLFlags = cpu_to_le16(MPI2_SCSIIO_SGLFLAGS_TYPE_MPI +
3970 MPI2_SCSIIO_SGLFLAGS_SYSTEM_ADDR);
3971 mpi_request->VF_ID = 0; /* TODO */
3972 mpi_request->VP_ID = 0;
3973 int_to_scsilun(sas_device_priv_data->lun, (struct scsi_lun *)
3975 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
3977 if (!mpi_request->DataLength) {
3978 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request->SGL);
3980 if (_scsih_build_scatter_gather(ioc, scmd, smid)) {
3981 mpt2sas_base_free_smid(ioc, smid);
3986 raid_device = sas_target_priv_data->raid_device;
3987 if (raid_device && raid_device->direct_io_enabled)
3988 _scsih_setup_direct_io(ioc, scmd, raid_device, mpi_request,
3991 if (likely(mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST))
3992 mpt2sas_base_put_smid_scsi_io(ioc, smid,
3993 le16_to_cpu(mpi_request->DevHandle));
3995 mpt2sas_base_put_smid_default(ioc, smid);
3999 return SCSI_MLQUEUE_HOST_BUSY;
4002 static DEF_SCSI_QCMD(_scsih_qcmd)
4005 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
4006 * @sense_buffer: sense data returned by target
4007 * @data: normalized skey/asc/ascq
4012 _scsih_normalize_sense(char *sense_buffer, struct sense_info *data)
4014 if ((sense_buffer[0] & 0x7F) >= 0x72) {
4015 /* descriptor format */
4016 data->skey = sense_buffer[1] & 0x0F;
4017 data->asc = sense_buffer[2];
4018 data->ascq = sense_buffer[3];
4021 data->skey = sense_buffer[2] & 0x0F;
4022 data->asc = sense_buffer[12];
4023 data->ascq = sense_buffer[13];
4027 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4029 * _scsih_scsi_ioc_info - translated non-successful SCSI_IO request
4030 * @ioc: per adapter object
4031 * @scmd: pointer to scsi command object
4032 * @mpi_reply: reply mf payload returned from firmware
4034 * scsi_status - SCSI Status code returned from target device
4035 * scsi_state - state info associated with SCSI_IO determined by ioc
4036 * ioc_status - ioc supplied status info
4041 _scsih_scsi_ioc_info(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
4042 Mpi2SCSIIOReply_t *mpi_reply, u16 smid)
4046 u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) &
4047 MPI2_IOCSTATUS_MASK;
4048 u8 scsi_state = mpi_reply->SCSIState;
4049 u8 scsi_status = mpi_reply->SCSIStatus;
4050 char *desc_ioc_state = NULL;
4051 char *desc_scsi_status = NULL;
4052 char *desc_scsi_state = ioc->tmp_string;
4053 u32 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
4054 struct _sas_device *sas_device = NULL;
4055 unsigned long flags;
4056 struct scsi_target *starget = scmd->device->sdev_target;
4057 struct MPT2SAS_TARGET *priv_target = starget->hostdata;
4058 char *device_str = NULL;
4063 if (ioc->hide_ir_msg)
4064 device_str = "WarpDrive";
4066 device_str = "volume";
4068 if (log_info == 0x31170000)
4071 switch (ioc_status) {
4072 case MPI2_IOCSTATUS_SUCCESS:
4073 desc_ioc_state = "success";
4075 case MPI2_IOCSTATUS_INVALID_FUNCTION:
4076 desc_ioc_state = "invalid function";
4078 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
4079 desc_ioc_state = "scsi recovered error";
4081 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE:
4082 desc_ioc_state = "scsi invalid dev handle";
4084 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
4085 desc_ioc_state = "scsi device not there";
4087 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
4088 desc_ioc_state = "scsi data overrun";
4090 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
4091 desc_ioc_state = "scsi data underrun";
4093 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
4094 desc_ioc_state = "scsi io data error";
4096 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
4097 desc_ioc_state = "scsi protocol error";
4099 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
4100 desc_ioc_state = "scsi task terminated";
4102 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
4103 desc_ioc_state = "scsi residual mismatch";
4105 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
4106 desc_ioc_state = "scsi task mgmt failed";
4108 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
4109 desc_ioc_state = "scsi ioc terminated";
4111 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
4112 desc_ioc_state = "scsi ext terminated";
4114 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4115 desc_ioc_state = "eedp guard error";
4117 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4118 desc_ioc_state = "eedp ref tag error";
4120 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4121 desc_ioc_state = "eedp app tag error";
4124 desc_ioc_state = "unknown";
4128 switch (scsi_status) {
4129 case MPI2_SCSI_STATUS_GOOD:
4130 desc_scsi_status = "good";
4132 case MPI2_SCSI_STATUS_CHECK_CONDITION:
4133 desc_scsi_status = "check condition";
4135 case MPI2_SCSI_STATUS_CONDITION_MET:
4136 desc_scsi_status = "condition met";
4138 case MPI2_SCSI_STATUS_BUSY:
4139 desc_scsi_status = "busy";
4141 case MPI2_SCSI_STATUS_INTERMEDIATE:
4142 desc_scsi_status = "intermediate";
4144 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET:
4145 desc_scsi_status = "intermediate condmet";
4147 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT:
4148 desc_scsi_status = "reservation conflict";
4150 case MPI2_SCSI_STATUS_COMMAND_TERMINATED:
4151 desc_scsi_status = "command terminated";
4153 case MPI2_SCSI_STATUS_TASK_SET_FULL:
4154 desc_scsi_status = "task set full";
4156 case MPI2_SCSI_STATUS_ACA_ACTIVE:
4157 desc_scsi_status = "aca active";
4159 case MPI2_SCSI_STATUS_TASK_ABORTED:
4160 desc_scsi_status = "task aborted";
4163 desc_scsi_status = "unknown";
4167 desc_scsi_state[0] = '\0';
4169 desc_scsi_state = " ";
4170 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
4171 strcat(desc_scsi_state, "response info ");
4172 if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4173 strcat(desc_scsi_state, "state terminated ");
4174 if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS)
4175 strcat(desc_scsi_state, "no status ");
4176 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED)
4177 strcat(desc_scsi_state, "autosense failed ");
4178 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)
4179 strcat(desc_scsi_state, "autosense valid ");
4181 scsi_print_command(scmd);
4183 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
4184 printk(MPT2SAS_WARN_FMT "\t%s wwid(0x%016llx)\n", ioc->name,
4185 device_str, (unsigned long long)priv_target->sas_address);
4187 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4188 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
4189 priv_target->sas_address);
4191 printk(MPT2SAS_WARN_FMT "\tsas_address(0x%016llx), "
4192 "phy(%d)\n", ioc->name, sas_device->sas_address,
4194 printk(MPT2SAS_WARN_FMT
4195 "\tenclosure_logical_id(0x%016llx), slot(%d)\n",
4196 ioc->name, sas_device->enclosure_logical_id,
4199 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4202 printk(MPT2SAS_WARN_FMT "\thandle(0x%04x), ioc_status(%s)(0x%04x), "
4203 "smid(%d)\n", ioc->name, le16_to_cpu(mpi_reply->DevHandle),
4204 desc_ioc_state, ioc_status, smid);
4205 printk(MPT2SAS_WARN_FMT "\trequest_len(%d), underflow(%d), "
4206 "resid(%d)\n", ioc->name, scsi_bufflen(scmd), scmd->underflow,
4207 scsi_get_resid(scmd));
4208 printk(MPT2SAS_WARN_FMT "\ttag(%d), transfer_count(%d), "
4209 "sc->result(0x%08x)\n", ioc->name, le16_to_cpu(mpi_reply->TaskTag),
4210 le32_to_cpu(mpi_reply->TransferCount), scmd->result);
4211 printk(MPT2SAS_WARN_FMT "\tscsi_status(%s)(0x%02x), "
4212 "scsi_state(%s)(0x%02x)\n", ioc->name, desc_scsi_status,
4213 scsi_status, desc_scsi_state, scsi_state);
4215 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
4216 struct sense_info data;
4217 _scsih_normalize_sense(scmd->sense_buffer, &data);
4218 printk(MPT2SAS_WARN_FMT "\t[sense_key,asc,ascq]: "
4219 "[0x%02x,0x%02x,0x%02x], count(%d)\n", ioc->name, data.skey,
4220 data.asc, data.ascq, le32_to_cpu(mpi_reply->SenseCount));
4223 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) {
4224 response_info = le32_to_cpu(mpi_reply->ResponseInfo);
4225 response_bytes = (u8 *)&response_info;
4226 _scsih_response_code(ioc, response_bytes[0]);
4232 * _scsih_turn_on_fault_led - illuminate Fault LED
4233 * @ioc: per adapter object
4234 * @handle: device handle
4240 _scsih_turn_on_fault_led(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4242 Mpi2SepReply_t mpi_reply;
4243 Mpi2SepRequest_t mpi_request;
4245 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
4246 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
4247 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
4248 mpi_request.SlotStatus =
4249 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT);
4250 mpi_request.DevHandle = cpu_to_le16(handle);
4251 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS;
4252 if ((mpt2sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
4253 &mpi_request)) != 0) {
4254 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", ioc->name,
4255 __FILE__, __LINE__, __func__);
4259 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
4260 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "enclosure_processor: "
4261 "ioc_status (0x%04x), loginfo(0x%08x)\n", ioc->name,
4262 le16_to_cpu(mpi_reply.IOCStatus),
4263 le32_to_cpu(mpi_reply.IOCLogInfo)));
4269 * _scsih_send_event_to_turn_on_fault_led - fire delayed event
4270 * @ioc: per adapter object
4271 * @handle: device handle
4272 * Context: interrupt.
4277 _scsih_send_event_to_turn_on_fault_led(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4279 struct fw_event_work *fw_event;
4281 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
4284 fw_event->event = MPT2SAS_TURN_ON_FAULT_LED;
4285 fw_event->device_handle = handle;
4286 fw_event->ioc = ioc;
4287 _scsih_fw_event_add(ioc, fw_event);
4291 * _scsih_smart_predicted_fault - process smart errors
4292 * @ioc: per adapter object
4293 * @handle: device handle
4294 * Context: interrupt.
4299 _scsih_smart_predicted_fault(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4301 struct scsi_target *starget;
4302 struct MPT2SAS_TARGET *sas_target_priv_data;
4303 Mpi2EventNotificationReply_t *event_reply;
4304 Mpi2EventDataSasDeviceStatusChange_t *event_data;
4305 struct _sas_device *sas_device;
4307 unsigned long flags;
4309 /* only handle non-raid devices */
4310 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4311 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
4313 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4316 starget = sas_device->starget;
4317 sas_target_priv_data = starget->hostdata;
4319 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) ||
4320 ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))) {
4321 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4324 starget_printk(KERN_WARNING, starget, "predicted fault\n");
4325 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4327 if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM)
4328 _scsih_send_event_to_turn_on_fault_led(ioc, handle);
4330 /* insert into event log */
4331 sz = offsetof(Mpi2EventNotificationReply_t, EventData) +
4332 sizeof(Mpi2EventDataSasDeviceStatusChange_t);
4333 event_reply = kzalloc(sz, GFP_KERNEL);
4335 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4336 ioc->name, __FILE__, __LINE__, __func__);
4340 event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION;
4341 event_reply->Event =
4342 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE);
4343 event_reply->MsgLength = sz/4;
4344 event_reply->EventDataLength =
4345 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t)/4);
4346 event_data = (Mpi2EventDataSasDeviceStatusChange_t *)
4347 event_reply->EventData;
4348 event_data->ReasonCode = MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA;
4349 event_data->ASC = 0x5D;
4350 event_data->DevHandle = cpu_to_le16(handle);
4351 event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address);
4352 mpt2sas_ctl_add_to_event_log(ioc, event_reply);
4357 * _scsih_io_done - scsi request callback
4358 * @ioc: per adapter object
4359 * @smid: system request message index
4360 * @msix_index: MSIX table index supplied by the OS
4361 * @reply: reply message frame(lower 32bit addr)
4363 * Callback handler when using _scsih_qcmd.
4365 * Return 1 meaning mf should be freed from _base_interrupt
4366 * 0 means the mf is freed from this function.
4369 _scsih_io_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
4371 Mpi2SCSIIORequest_t *mpi_request;
4372 Mpi2SCSIIOReply_t *mpi_reply;
4373 struct scsi_cmnd *scmd;
4379 struct MPT2SAS_DEVICE *sas_device_priv_data;
4380 u32 response_code = 0;
4381 unsigned long flags;
4383 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
4384 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
4388 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
4390 if (mpi_reply == NULL) {
4391 scmd->result = DID_OK << 16;
4395 sas_device_priv_data = scmd->device->hostdata;
4396 if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
4397 sas_device_priv_data->sas_target->deleted) {
4398 scmd->result = DID_NO_CONNECT << 16;
4402 * WARPDRIVE: If direct_io is set then it is directIO,
4403 * the failed direct I/O should be redirected to volume
4405 if (_scsih_scsi_direct_io_get(ioc, smid)) {
4406 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
4407 ioc->scsi_lookup[smid - 1].scmd = scmd;
4408 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
4409 _scsih_scsi_direct_io_set(ioc, smid, 0);
4410 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
4411 mpi_request->DevHandle =
4412 cpu_to_le16(sas_device_priv_data->sas_target->handle);
4413 mpt2sas_base_put_smid_scsi_io(ioc, smid,
4414 sas_device_priv_data->sas_target->handle);
4419 /* turning off TLR */
4420 scsi_state = mpi_reply->SCSIState;
4421 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
4423 le32_to_cpu(mpi_reply->ResponseInfo) & 0xFF;
4424 if (!sas_device_priv_data->tlr_snoop_check) {
4425 sas_device_priv_data->tlr_snoop_check++;
4426 /* Make sure Device is not raid volume.
4427 * We do not expose raid functionality to upper layer for warpdrive.
4429 if (!ioc->is_warpdrive && !_scsih_is_raid(&scmd->device->sdev_gendev) &&
4430 sas_is_tlr_enabled(scmd->device) &&
4431 response_code == MPI2_SCSITASKMGMT_RSP_INVALID_FRAME) {
4432 sas_disable_tlr(scmd->device);
4433 sdev_printk(KERN_INFO, scmd->device, "TLR disabled\n");
4437 xfer_cnt = le32_to_cpu(mpi_reply->TransferCount);
4438 scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt);
4439 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
4440 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
4441 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
4444 ioc_status &= MPI2_IOCSTATUS_MASK;
4445 scsi_status = mpi_reply->SCSIStatus;
4447 if (ioc_status == MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 &&
4448 (scsi_status == MPI2_SCSI_STATUS_BUSY ||
4449 scsi_status == MPI2_SCSI_STATUS_RESERVATION_CONFLICT ||
4450 scsi_status == MPI2_SCSI_STATUS_TASK_SET_FULL)) {
4451 ioc_status = MPI2_IOCSTATUS_SUCCESS;
4454 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
4455 struct sense_info data;
4456 const void *sense_data = mpt2sas_base_get_sense_buffer(ioc,
4458 u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE,
4459 le32_to_cpu(mpi_reply->SenseCount));
4460 memcpy(scmd->sense_buffer, sense_data, sz);
4461 _scsih_normalize_sense(scmd->sense_buffer, &data);
4462 /* failure prediction threshold exceeded */
4463 if (data.asc == 0x5D)
4464 _scsih_smart_predicted_fault(ioc,
4465 le16_to_cpu(mpi_reply->DevHandle));
4468 switch (ioc_status) {
4469 case MPI2_IOCSTATUS_BUSY:
4470 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES:
4471 scmd->result = SAM_STAT_BUSY;
4474 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
4475 scmd->result = DID_NO_CONNECT << 16;
4478 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
4479 if (sas_device_priv_data->block) {
4480 scmd->result = DID_TRANSPORT_DISRUPTED << 16;
4483 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
4484 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
4485 scmd->result = DID_RESET << 16;
4488 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
4489 if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt))
4490 scmd->result = DID_SOFT_ERROR << 16;
4492 scmd->result = (DID_OK << 16) | scsi_status;
4495 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
4496 scmd->result = (DID_OK << 16) | scsi_status;
4498 if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID))
4501 if (xfer_cnt < scmd->underflow) {
4502 if (scsi_status == SAM_STAT_BUSY)
4503 scmd->result = SAM_STAT_BUSY;
4505 scmd->result = DID_SOFT_ERROR << 16;
4506 } else if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4507 MPI2_SCSI_STATE_NO_SCSI_STATUS))
4508 scmd->result = DID_SOFT_ERROR << 16;
4509 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4510 scmd->result = DID_RESET << 16;
4511 else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) {
4512 mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID;
4513 mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION;
4514 scmd->result = (DRIVER_SENSE << 24) |
4515 SAM_STAT_CHECK_CONDITION;
4516 scmd->sense_buffer[0] = 0x70;
4517 scmd->sense_buffer[2] = ILLEGAL_REQUEST;
4518 scmd->sense_buffer[12] = 0x20;
4519 scmd->sense_buffer[13] = 0;
4523 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
4524 scsi_set_resid(scmd, 0);
4525 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
4526 case MPI2_IOCSTATUS_SUCCESS:
4527 scmd->result = (DID_OK << 16) | scsi_status;
4528 if (response_code ==
4529 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME ||
4530 (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4531 MPI2_SCSI_STATE_NO_SCSI_STATUS)))
4532 scmd->result = DID_SOFT_ERROR << 16;
4533 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4534 scmd->result = DID_RESET << 16;
4537 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4538 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4539 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4540 _scsih_eedp_error_handling(scmd, ioc_status);
4542 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
4543 case MPI2_IOCSTATUS_INVALID_FUNCTION:
4544 case MPI2_IOCSTATUS_INVALID_SGL:
4545 case MPI2_IOCSTATUS_INTERNAL_ERROR:
4546 case MPI2_IOCSTATUS_INVALID_FIELD:
4547 case MPI2_IOCSTATUS_INVALID_STATE:
4548 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
4549 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
4551 scmd->result = DID_SOFT_ERROR << 16;
4556 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4557 if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY))
4558 _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid);
4562 scsi_dma_unmap(scmd);
4563 scmd->scsi_done(scmd);
4568 * _scsih_sas_host_refresh - refreshing sas host object contents
4569 * @ioc: per adapter object
4572 * During port enable, fw will send topology events for every device. Its
4573 * possible that the handles may change from the previous setting, so this
4574 * code keeping handles updating if changed.
4579 _scsih_sas_host_refresh(struct MPT2SAS_ADAPTER *ioc)
4584 Mpi2ConfigReply_t mpi_reply;
4585 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
4586 u16 attached_handle;
4589 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT
4590 "updating handles for sas_host(0x%016llx)\n",
4591 ioc->name, (unsigned long long)ioc->sas_hba.sas_address));
4593 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys
4594 * sizeof(Mpi2SasIOUnit0PhyData_t));
4595 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4596 if (!sas_iounit_pg0) {
4597 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4598 ioc->name, __FILE__, __LINE__, __func__);
4602 if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4603 sas_iounit_pg0, sz)) != 0)
4605 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
4606 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
4608 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
4609 link_rate = sas_iounit_pg0->PhyData[i].NegotiatedLinkRate >> 4;
4611 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4612 PhyData[0].ControllerDevHandle);
4613 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
4614 attached_handle = le16_to_cpu(sas_iounit_pg0->PhyData[i].
4616 if (attached_handle && link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
4617 link_rate = MPI2_SAS_NEG_LINK_RATE_1_5;
4618 mpt2sas_transport_update_links(ioc, ioc->sas_hba.sas_address,
4619 attached_handle, i, link_rate);
4622 kfree(sas_iounit_pg0);
4626 * _scsih_sas_host_add - create sas host object
4627 * @ioc: per adapter object
4629 * Creating host side data object, stored in ioc->sas_hba
4634 _scsih_sas_host_add(struct MPT2SAS_ADAPTER *ioc)
4637 Mpi2ConfigReply_t mpi_reply;
4638 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
4639 Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
4640 Mpi2SasPhyPage0_t phy_pg0;
4641 Mpi2SasDevicePage0_t sas_device_pg0;
4642 Mpi2SasEnclosurePage0_t enclosure_pg0;
4645 u16 device_missing_delay;
4647 mpt2sas_config_get_number_hba_phys(ioc, &ioc->sas_hba.num_phys);
4648 if (!ioc->sas_hba.num_phys) {
4649 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4650 ioc->name, __FILE__, __LINE__, __func__);
4654 /* sas_iounit page 0 */
4655 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys *
4656 sizeof(Mpi2SasIOUnit0PhyData_t));
4657 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4658 if (!sas_iounit_pg0) {
4659 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4660 ioc->name, __FILE__, __LINE__, __func__);
4663 if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4664 sas_iounit_pg0, sz))) {
4665 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4666 ioc->name, __FILE__, __LINE__, __func__);
4669 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4670 MPI2_IOCSTATUS_MASK;
4671 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4672 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4673 ioc->name, __FILE__, __LINE__, __func__);
4677 /* sas_iounit page 1 */
4678 sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys *
4679 sizeof(Mpi2SasIOUnit1PhyData_t));
4680 sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
4681 if (!sas_iounit_pg1) {
4682 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4683 ioc->name, __FILE__, __LINE__, __func__);
4686 if ((mpt2sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
4687 sas_iounit_pg1, sz))) {
4688 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4689 ioc->name, __FILE__, __LINE__, __func__);
4692 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4693 MPI2_IOCSTATUS_MASK;
4694 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4695 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4696 ioc->name, __FILE__, __LINE__, __func__);
4700 ioc->io_missing_delay =
4701 le16_to_cpu(sas_iounit_pg1->IODeviceMissingDelay);
4702 device_missing_delay =
4703 le16_to_cpu(sas_iounit_pg1->ReportDeviceMissingDelay);
4704 if (device_missing_delay & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16)
4705 ioc->device_missing_delay = (device_missing_delay &
4706 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16;
4708 ioc->device_missing_delay = device_missing_delay &
4709 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
4711 ioc->sas_hba.parent_dev = &ioc->shost->shost_gendev;
4712 ioc->sas_hba.phy = kcalloc(ioc->sas_hba.num_phys,
4713 sizeof(struct _sas_phy), GFP_KERNEL);
4714 if (!ioc->sas_hba.phy) {
4715 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4716 ioc->name, __FILE__, __LINE__, __func__);
4719 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
4720 if ((mpt2sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0,
4722 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4723 ioc->name, __FILE__, __LINE__, __func__);
4726 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4727 MPI2_IOCSTATUS_MASK;
4728 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4729 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4730 ioc->name, __FILE__, __LINE__, __func__);
4735 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4736 PhyData[0].ControllerDevHandle);
4737 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
4738 ioc->sas_hba.phy[i].phy_id = i;
4739 mpt2sas_transport_add_host_phy(ioc, &ioc->sas_hba.phy[i],
4740 phy_pg0, ioc->sas_hba.parent_dev);
4742 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
4743 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, ioc->sas_hba.handle))) {
4744 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4745 ioc->name, __FILE__, __LINE__, __func__);
4748 ioc->sas_hba.enclosure_handle =
4749 le16_to_cpu(sas_device_pg0.EnclosureHandle);
4750 ioc->sas_hba.sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
4751 printk(MPT2SAS_INFO_FMT "host_add: handle(0x%04x), "
4752 "sas_addr(0x%016llx), phys(%d)\n", ioc->name, ioc->sas_hba.handle,
4753 (unsigned long long) ioc->sas_hba.sas_address,
4754 ioc->sas_hba.num_phys) ;
4756 if (ioc->sas_hba.enclosure_handle) {
4757 if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply,
4759 MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
4760 ioc->sas_hba.enclosure_handle))) {
4761 ioc->sas_hba.enclosure_logical_id =
4762 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
4767 kfree(sas_iounit_pg1);
4768 kfree(sas_iounit_pg0);
4772 * _scsih_expander_add - creating expander object
4773 * @ioc: per adapter object
4774 * @handle: expander handle
4776 * Creating expander object, stored in ioc->sas_expander_list.
4778 * Return 0 for success, else error.
4781 _scsih_expander_add(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4783 struct _sas_node *sas_expander;
4784 Mpi2ConfigReply_t mpi_reply;
4785 Mpi2ExpanderPage0_t expander_pg0;
4786 Mpi2ExpanderPage1_t expander_pg1;
4787 Mpi2SasEnclosurePage0_t enclosure_pg0;
4790 u64 sas_address, sas_address_parent = 0;
4792 unsigned long flags;
4793 struct _sas_port *mpt2sas_port = NULL;
4799 if (ioc->shost_recovery || ioc->pci_error_recovery)
4802 if ((mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
4803 MPI2_SAS_EXPAND_PGAD_FORM_HNDL, handle))) {
4804 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4805 ioc->name, __FILE__, __LINE__, __func__);
4809 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4810 MPI2_IOCSTATUS_MASK;
4811 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4812 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4813 ioc->name, __FILE__, __LINE__, __func__);
4817 /* handle out of order topology events */
4818 parent_handle = le16_to_cpu(expander_pg0.ParentDevHandle);
4819 if (_scsih_get_sas_address(ioc, parent_handle, &sas_address_parent)
4821 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4822 ioc->name, __FILE__, __LINE__, __func__);
4825 if (sas_address_parent != ioc->sas_hba.sas_address) {
4826 spin_lock_irqsave(&ioc->sas_node_lock, flags);
4827 sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
4828 sas_address_parent);
4829 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4830 if (!sas_expander) {
4831 rc = _scsih_expander_add(ioc, parent_handle);
4837 spin_lock_irqsave(&ioc->sas_node_lock, flags);
4838 sas_address = le64_to_cpu(expander_pg0.SASAddress);
4839 sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
4841 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4846 sas_expander = kzalloc(sizeof(struct _sas_node),
4848 if (!sas_expander) {
4849 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4850 ioc->name, __FILE__, __LINE__, __func__);
4854 sas_expander->handle = handle;
4855 sas_expander->num_phys = expander_pg0.NumPhys;
4856 sas_expander->sas_address_parent = sas_address_parent;
4857 sas_expander->sas_address = sas_address;
4859 printk(MPT2SAS_INFO_FMT "expander_add: handle(0x%04x),"
4860 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc->name,
4861 handle, parent_handle, (unsigned long long)
4862 sas_expander->sas_address, sas_expander->num_phys);
4864 if (!sas_expander->num_phys)
4866 sas_expander->phy = kcalloc(sas_expander->num_phys,
4867 sizeof(struct _sas_phy), GFP_KERNEL);
4868 if (!sas_expander->phy) {
4869 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4870 ioc->name, __FILE__, __LINE__, __func__);
4875 INIT_LIST_HEAD(&sas_expander->sas_port_list);
4876 mpt2sas_port = mpt2sas_transport_port_add(ioc, handle,
4877 sas_address_parent);
4878 if (!mpt2sas_port) {
4879 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4880 ioc->name, __FILE__, __LINE__, __func__);
4884 sas_expander->parent_dev = &mpt2sas_port->rphy->dev;
4886 for (i = 0 ; i < sas_expander->num_phys ; i++) {
4887 if ((mpt2sas_config_get_expander_pg1(ioc, &mpi_reply,
4888 &expander_pg1, i, handle))) {
4889 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4890 ioc->name, __FILE__, __LINE__, __func__);
4894 sas_expander->phy[i].handle = handle;
4895 sas_expander->phy[i].phy_id = i;
4897 if ((mpt2sas_transport_add_expander_phy(ioc,
4898 &sas_expander->phy[i], expander_pg1,
4899 sas_expander->parent_dev))) {
4900 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4901 ioc->name, __FILE__, __LINE__, __func__);
4907 if (sas_expander->enclosure_handle) {
4908 if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply,
4909 &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
4910 sas_expander->enclosure_handle))) {
4911 sas_expander->enclosure_logical_id =
4912 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
4916 _scsih_expander_node_add(ioc, sas_expander);
4922 mpt2sas_transport_port_remove(ioc, sas_expander->sas_address,
4923 sas_address_parent);
4924 kfree(sas_expander);
4929 * _scsih_done - scsih callback handler.
4930 * @ioc: per adapter object
4931 * @smid: system request message index
4932 * @msix_index: MSIX table index supplied by the OS
4933 * @reply: reply message frame(lower 32bit addr)
4935 * Callback handler when sending internal generated message frames.
4936 * The callback index passed is `ioc->scsih_cb_idx`
4938 * Return 1 meaning mf should be freed from _base_interrupt
4939 * 0 means the mf is freed from this function.
4942 _scsih_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
4944 MPI2DefaultReply_t *mpi_reply;
4946 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
4947 if (ioc->scsih_cmds.status == MPT2_CMD_NOT_USED)
4949 if (ioc->scsih_cmds.smid != smid)
4951 ioc->scsih_cmds.status |= MPT2_CMD_COMPLETE;
4953 memcpy(ioc->scsih_cmds.reply, mpi_reply,
4954 mpi_reply->MsgLength*4);
4955 ioc->scsih_cmds.status |= MPT2_CMD_REPLY_VALID;
4957 ioc->scsih_cmds.status &= ~MPT2_CMD_PENDING;
4958 complete(&ioc->scsih_cmds.done);
4963 * mpt2sas_expander_remove - removing expander object
4964 * @ioc: per adapter object
4965 * @sas_address: expander sas_address
4970 mpt2sas_expander_remove(struct MPT2SAS_ADAPTER *ioc, u64 sas_address)
4972 struct _sas_node *sas_expander;
4973 unsigned long flags;
4975 if (ioc->shost_recovery)
4978 spin_lock_irqsave(&ioc->sas_node_lock, flags);
4979 sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
4981 if (!sas_expander) {
4982 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4985 list_del(&sas_expander->list);
4986 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4987 _scsih_expander_node_remove(ioc, sas_expander);
4991 * _scsih_check_access_status - check access flags
4992 * @ioc: per adapter object
4993 * @sas_address: sas address
4994 * @handle: sas device handle
4995 * @access_flags: errors returned during discovery of the device
4997 * Return 0 for success, else failure
5000 _scsih_check_access_status(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
5001 u16 handle, u8 access_status)
5006 switch (access_status) {
5007 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS:
5008 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION:
5011 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED:
5012 desc = "sata capability failed";
5014 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT:
5015 desc = "sata affiliation conflict";
5017 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE:
5018 desc = "route not addressable";
5020 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE:
5021 desc = "smp error not addressable";
5023 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED:
5024 desc = "device blocked";
5026 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED:
5027 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN:
5028 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT:
5029 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG:
5030 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION:
5031 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER:
5032 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN:
5033 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN:
5034 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN:
5035 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION:
5036 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE:
5037 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX:
5038 desc = "sata initialization failed";
5048 printk(MPT2SAS_ERR_FMT "discovery errors(%s): sas_address(0x%016llx), "
5049 "handle(0x%04x)\n", ioc->name, desc,
5050 (unsigned long long)sas_address, handle);
5055 _scsih_check_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
5057 Mpi2ConfigReply_t mpi_reply;
5058 Mpi2SasDevicePage0_t sas_device_pg0;
5059 struct _sas_device *sas_device;
5061 unsigned long flags;
5063 struct scsi_target *starget;
5064 struct MPT2SAS_TARGET *sas_target_priv_data;
5067 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5068 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle)))
5071 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
5072 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
5075 /* check if this is end device */
5076 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
5077 if (!(_scsih_is_end_device(device_info)))
5080 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5081 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
5082 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5086 printk(MPT2SAS_ERR_FMT "device is not present "
5087 "handle(0x%04x), no sas_device!!!\n", ioc->name, handle);
5088 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5092 if (unlikely(sas_device->handle != handle)) {
5093 starget = sas_device->starget;
5094 sas_target_priv_data = starget->hostdata;
5095 starget_printk(KERN_INFO, starget, "handle changed from(0x%04x)"
5096 " to (0x%04x)!!!\n", sas_device->handle, handle);
5097 sas_target_priv_data->handle = handle;
5098 sas_device->handle = handle;
5100 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5102 /* check if device is present */
5103 if (!(le16_to_cpu(sas_device_pg0.Flags) &
5104 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
5105 printk(MPT2SAS_ERR_FMT "device is not present "
5106 "handle(0x%04x), flags!!!\n", ioc->name, handle);
5110 /* check if there were any issues with discovery */
5111 if (_scsih_check_access_status(ioc, sas_address, handle,
5112 sas_device_pg0.AccessStatus))
5114 _scsih_ublock_io_device(ioc, handle);
5119 * _scsih_add_device - creating sas device object
5120 * @ioc: per adapter object
5121 * @handle: sas device handle
5122 * @phy_num: phy number end device attached to
5123 * @is_pd: is this hidden raid component
5125 * Creating end device object, stored in ioc->sas_device_list.
5127 * Returns 0 for success, non-zero for failure.
5130 _scsih_add_device(struct MPT2SAS_ADAPTER *ioc, u16 handle, u8 phy_num, u8 is_pd)
5132 Mpi2ConfigReply_t mpi_reply;
5133 Mpi2SasDevicePage0_t sas_device_pg0;
5134 Mpi2SasEnclosurePage0_t enclosure_pg0;
5135 struct _sas_device *sas_device;
5139 unsigned long flags;
5141 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5142 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
5143 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5144 ioc->name, __FILE__, __LINE__, __func__);
5148 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
5149 MPI2_IOCSTATUS_MASK;
5150 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5151 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5152 ioc->name, __FILE__, __LINE__, __func__);
5156 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
5158 /* check if device is present */
5159 if (!(le16_to_cpu(sas_device_pg0.Flags) &
5160 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
5161 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5162 ioc->name, __FILE__, __LINE__, __func__);
5163 printk(MPT2SAS_ERR_FMT "Flags = 0x%04x\n",
5164 ioc->name, le16_to_cpu(sas_device_pg0.Flags));
5168 /* check if there were any issues with discovery */
5169 if (_scsih_check_access_status(ioc, sas_address, handle,
5170 sas_device_pg0.AccessStatus))
5173 /* check if this is end device */
5174 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
5175 if (!(_scsih_is_end_device(device_info))) {
5176 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5177 ioc->name, __FILE__, __LINE__, __func__);
5182 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5183 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5185 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5190 sas_device = kzalloc(sizeof(struct _sas_device),
5193 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5194 ioc->name, __FILE__, __LINE__, __func__);
5198 sas_device->handle = handle;
5199 if (_scsih_get_sas_address(ioc, le16_to_cpu
5200 (sas_device_pg0.ParentDevHandle),
5201 &sas_device->sas_address_parent) != 0)
5202 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5203 ioc->name, __FILE__, __LINE__, __func__);
5204 sas_device->enclosure_handle =
5205 le16_to_cpu(sas_device_pg0.EnclosureHandle);
5207 le16_to_cpu(sas_device_pg0.Slot);
5208 sas_device->device_info = device_info;
5209 sas_device->sas_address = sas_address;
5210 sas_device->phy = sas_device_pg0.PhyNum;
5212 /* get enclosure_logical_id */
5213 if (sas_device->enclosure_handle && !(mpt2sas_config_get_enclosure_pg0(
5214 ioc, &mpi_reply, &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
5215 sas_device->enclosure_handle)))
5216 sas_device->enclosure_logical_id =
5217 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
5219 /* get device name */
5220 sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName);
5222 if (ioc->wait_for_discovery_to_complete)
5223 _scsih_sas_device_init_add(ioc, sas_device);
5225 _scsih_sas_device_add(ioc, sas_device);
5231 * _scsih_remove_device - removing sas device object
5232 * @ioc: per adapter object
5233 * @sas_device_delete: the sas_device object
5238 _scsih_remove_device(struct MPT2SAS_ADAPTER *ioc,
5239 struct _sas_device *sas_device)
5241 struct _sas_device sas_device_backup;
5242 struct MPT2SAS_TARGET *sas_target_priv_data;
5247 memcpy(&sas_device_backup, sas_device, sizeof(struct _sas_device));
5248 _scsih_sas_device_remove(ioc, sas_device);
5250 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter: "
5251 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
5252 sas_device_backup.handle, (unsigned long long)
5253 sas_device_backup.sas_address));
5255 if (sas_device_backup.starget && sas_device_backup.starget->hostdata) {
5256 sas_target_priv_data = sas_device_backup.starget->hostdata;
5257 sas_target_priv_data->deleted = 1;
5258 _scsih_ublock_io_device(ioc, sas_device_backup.handle);
5259 sas_target_priv_data->handle =
5260 MPT2SAS_INVALID_DEVICE_HANDLE;
5263 _scsih_ublock_io_device(ioc, sas_device_backup.handle);
5265 if (!ioc->hide_drives)
5266 mpt2sas_transport_port_remove(ioc,
5267 sas_device_backup.sas_address,
5268 sas_device_backup.sas_address_parent);
5270 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), sas_addr"
5271 "(0x%016llx)\n", ioc->name, sas_device_backup.handle,
5272 (unsigned long long) sas_device_backup.sas_address);
5274 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: exit: "
5275 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
5276 sas_device_backup.handle, (unsigned long long)
5277 sas_device_backup.sas_address));
5281 * mpt2sas_device_remove - removing device object
5282 * @ioc: per adapter object
5283 * @sas_address: expander sas_address
5288 mpt2sas_device_remove(struct MPT2SAS_ADAPTER *ioc, u64 sas_address)
5290 struct _sas_device *sas_device;
5291 unsigned long flags;
5293 if (ioc->shost_recovery)
5296 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5297 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5300 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5303 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5304 _scsih_remove_device(ioc, sas_device);
5307 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5309 * _scsih_sas_topology_change_event_debug - debug for topology event
5310 * @ioc: per adapter object
5311 * @event_data: event data payload
5315 _scsih_sas_topology_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
5316 Mpi2EventDataSasTopologyChangeList_t *event_data)
5322 char *status_str = NULL;
5323 u8 link_rate, prev_link_rate;
5325 switch (event_data->ExpStatus) {
5326 case MPI2_EVENT_SAS_TOPO_ES_ADDED:
5329 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING:
5330 status_str = "remove";
5332 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING:
5334 status_str = "responding";
5336 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING:
5337 status_str = "remove delay";
5340 status_str = "unknown status";
5343 printk(MPT2SAS_INFO_FMT "sas topology change: (%s)\n",
5344 ioc->name, status_str);
5345 printk(KERN_INFO "\thandle(0x%04x), enclosure_handle(0x%04x) "
5346 "start_phy(%02d), count(%d)\n",
5347 le16_to_cpu(event_data->ExpanderDevHandle),
5348 le16_to_cpu(event_data->EnclosureHandle),
5349 event_data->StartPhyNum, event_data->NumEntries);
5350 for (i = 0; i < event_data->NumEntries; i++) {
5351 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5354 phy_number = event_data->StartPhyNum + i;
5355 reason_code = event_data->PHY[i].PhyStatus &
5356 MPI2_EVENT_SAS_TOPO_RC_MASK;
5357 switch (reason_code) {
5358 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
5359 status_str = "target add";
5361 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
5362 status_str = "target remove";
5364 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING:
5365 status_str = "delay target remove";
5367 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
5368 status_str = "link rate change";
5370 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE:
5371 status_str = "target responding";
5374 status_str = "unknown";
5377 link_rate = event_data->PHY[i].LinkRate >> 4;
5378 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
5379 printk(KERN_INFO "\tphy(%02d), attached_handle(0x%04x): %s:"
5380 " link rate: new(0x%02x), old(0x%02x)\n", phy_number,
5381 handle, status_str, link_rate, prev_link_rate);
5388 * _scsih_sas_topology_change_event - handle topology changes
5389 * @ioc: per adapter object
5390 * @fw_event: The fw_event_work object
5395 _scsih_sas_topology_change_event(struct MPT2SAS_ADAPTER *ioc,
5396 struct fw_event_work *fw_event)
5399 u16 parent_handle, handle;
5401 u8 phy_number, max_phys;
5402 struct _sas_node *sas_expander;
5403 struct _sas_device *sas_device;
5405 unsigned long flags;
5406 u8 link_rate, prev_link_rate;
5407 Mpi2EventDataSasTopologyChangeList_t *event_data = fw_event->event_data;
5409 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5410 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5411 _scsih_sas_topology_change_event_debug(ioc, event_data);
5414 if (ioc->remove_host || ioc->pci_error_recovery)
5417 if (!ioc->sas_hba.num_phys)
5418 _scsih_sas_host_add(ioc);
5420 _scsih_sas_host_refresh(ioc);
5422 if (fw_event->ignore) {
5423 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "ignoring expander "
5424 "event\n", ioc->name));
5428 parent_handle = le16_to_cpu(event_data->ExpanderDevHandle);
5430 /* handle expander add */
5431 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_ADDED)
5432 if (_scsih_expander_add(ioc, parent_handle) != 0)
5435 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5436 sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc,
5438 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5440 sas_address = sas_expander->sas_address;
5441 max_phys = sas_expander->num_phys;
5442 } else if (parent_handle < ioc->sas_hba.num_phys) {
5443 sas_address = ioc->sas_hba.sas_address;
5444 max_phys = ioc->sas_hba.num_phys;
5448 /* handle siblings events */
5449 for (i = 0; i < event_data->NumEntries; i++) {
5450 if (fw_event->ignore) {
5451 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "ignoring "
5452 "expander event\n", ioc->name));
5455 if (ioc->shost_recovery || ioc->remove_host ||
5456 ioc->pci_error_recovery)
5458 phy_number = event_data->StartPhyNum + i;
5459 if (phy_number >= max_phys)
5461 reason_code = event_data->PHY[i].PhyStatus &
5462 MPI2_EVENT_SAS_TOPO_RC_MASK;
5463 if ((event_data->PHY[i].PhyStatus &
5464 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT) && (reason_code !=
5465 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING))
5467 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5470 link_rate = event_data->PHY[i].LinkRate >> 4;
5471 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
5472 switch (reason_code) {
5473 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
5475 if (ioc->shost_recovery)
5478 if (link_rate == prev_link_rate)
5481 mpt2sas_transport_update_links(ioc, sas_address,
5482 handle, phy_number, link_rate);
5484 if (link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
5487 _scsih_check_device(ioc, handle);
5489 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
5491 if (ioc->shost_recovery)
5494 mpt2sas_transport_update_links(ioc, sas_address,
5495 handle, phy_number, link_rate);
5497 _scsih_add_device(ioc, handle, phy_number, 0);
5499 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
5501 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5502 sas_device = _scsih_sas_device_find_by_handle(ioc,
5505 spin_unlock_irqrestore(&ioc->sas_device_lock,
5509 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5510 _scsih_remove_device(ioc, sas_device);
5515 /* handle expander removal */
5516 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING &&
5518 mpt2sas_expander_remove(ioc, sas_address);
5522 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5524 * _scsih_sas_device_status_change_event_debug - debug for device event
5525 * @event_data: event data payload
5531 _scsih_sas_device_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
5532 Mpi2EventDataSasDeviceStatusChange_t *event_data)
5534 char *reason_str = NULL;
5536 switch (event_data->ReasonCode) {
5537 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
5538 reason_str = "smart data";
5540 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED:
5541 reason_str = "unsupported device discovered";
5543 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
5544 reason_str = "internal device reset";
5546 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL:
5547 reason_str = "internal task abort";
5549 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL:
5550 reason_str = "internal task abort set";
5552 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL:
5553 reason_str = "internal clear task set";
5555 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL:
5556 reason_str = "internal query task";
5558 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE:
5559 reason_str = "sata init failure";
5561 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET:
5562 reason_str = "internal device reset complete";
5564 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL:
5565 reason_str = "internal task abort complete";
5567 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION:
5568 reason_str = "internal async notification";
5570 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY:
5571 reason_str = "expander reduced functionality";
5573 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY:
5574 reason_str = "expander reduced functionality complete";
5577 reason_str = "unknown reason";
5580 printk(MPT2SAS_INFO_FMT "device status change: (%s)\n"
5581 "\thandle(0x%04x), sas address(0x%016llx), tag(%d)",
5582 ioc->name, reason_str, le16_to_cpu(event_data->DevHandle),
5583 (unsigned long long)le64_to_cpu(event_data->SASAddress),
5584 le16_to_cpu(event_data->TaskTag));
5585 if (event_data->ReasonCode == MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA)
5586 printk(MPT2SAS_INFO_FMT ", ASC(0x%x), ASCQ(0x%x)\n", ioc->name,
5587 event_data->ASC, event_data->ASCQ);
5588 printk(KERN_INFO "\n");
5593 * _scsih_sas_device_status_change_event - handle device status change
5594 * @ioc: per adapter object
5595 * @fw_event: The fw_event_work object
5601 _scsih_sas_device_status_change_event(struct MPT2SAS_ADAPTER *ioc,
5602 struct fw_event_work *fw_event)
5604 struct MPT2SAS_TARGET *target_priv_data;
5605 struct _sas_device *sas_device;
5607 unsigned long flags;
5608 Mpi2EventDataSasDeviceStatusChange_t *event_data =
5609 fw_event->event_data;
5611 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5612 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5613 _scsih_sas_device_status_change_event_debug(ioc,
5617 /* In MPI Revision K (0xC), the internal device reset complete was
5618 * implemented, so avoid setting tm_busy flag for older firmware.
5620 if ((ioc->facts.HeaderVersion >> 8) < 0xC)
5623 if (event_data->ReasonCode !=
5624 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET &&
5625 event_data->ReasonCode !=
5626 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET)
5629 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5630 sas_address = le64_to_cpu(event_data->SASAddress);
5631 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5633 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5635 if (!sas_device || !sas_device->starget)
5638 target_priv_data = sas_device->starget->hostdata;
5639 if (!target_priv_data)
5642 if (event_data->ReasonCode ==
5643 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET)
5644 target_priv_data->tm_busy = 1;
5646 target_priv_data->tm_busy = 0;
5649 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5651 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure event
5652 * @ioc: per adapter object
5653 * @event_data: event data payload
5659 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
5660 Mpi2EventDataSasEnclDevStatusChange_t *event_data)
5662 char *reason_str = NULL;
5664 switch (event_data->ReasonCode) {
5665 case MPI2_EVENT_SAS_ENCL_RC_ADDED:
5666 reason_str = "enclosure add";
5668 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING:
5669 reason_str = "enclosure remove";
5672 reason_str = "unknown reason";
5676 printk(MPT2SAS_INFO_FMT "enclosure status change: (%s)\n"
5677 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
5678 " number slots(%d)\n", ioc->name, reason_str,
5679 le16_to_cpu(event_data->EnclosureHandle),
5680 (unsigned long long)le64_to_cpu(event_data->EnclosureLogicalID),
5681 le16_to_cpu(event_data->StartSlot));
5686 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
5687 * @ioc: per adapter object
5688 * @fw_event: The fw_event_work object
5694 _scsih_sas_enclosure_dev_status_change_event(struct MPT2SAS_ADAPTER *ioc,
5695 struct fw_event_work *fw_event)
5697 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5698 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5699 _scsih_sas_enclosure_dev_status_change_event_debug(ioc,
5700 fw_event->event_data);
5705 * _scsih_sas_broadcast_primative_event - handle broadcast events
5706 * @ioc: per adapter object
5707 * @fw_event: The fw_event_work object
5713 _scsih_sas_broadcast_primative_event(struct MPT2SAS_ADAPTER *ioc,
5714 struct fw_event_work *fw_event)
5716 struct scsi_cmnd *scmd;
5717 struct scsi_device *sdev;
5720 struct MPT2SAS_DEVICE *sas_device_priv_data;
5721 u32 termination_count;
5723 Mpi2SCSITaskManagementReply_t *mpi_reply;
5724 Mpi2EventDataSasBroadcastPrimitive_t *event_data = fw_event->event_data;
5726 unsigned long flags;
5729 u8 task_abort_retries;
5731 mutex_lock(&ioc->tm_cmds.mutex);
5732 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter: phy number(%d), "
5733 "width(%d)\n", ioc->name, __func__, event_data->PhyNum,
5734 event_data->PortWidth));
5736 _scsih_block_io_all_device(ioc);
5738 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5739 mpi_reply = ioc->tm_cmds.reply;
5740 broadcast_aen_retry:
5742 /* sanity checks for retrying this loop */
5743 if (max_retries++ == 5) {
5744 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: giving up\n",
5745 ioc->name, __func__));
5747 } else if (max_retries > 1)
5748 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: %d retry\n",
5749 ioc->name, __func__, max_retries - 1));
5751 termination_count = 0;
5753 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
5754 if (ioc->shost_recovery)
5756 scmd = _scsih_scsi_lookup_get(ioc, smid);
5759 sdev = scmd->device;
5760 sas_device_priv_data = sdev->hostdata;
5761 if (!sas_device_priv_data || !sas_device_priv_data->sas_target)
5763 /* skip hidden raid components */
5764 if (sas_device_priv_data->sas_target->flags &
5765 MPT_TARGET_FLAGS_RAID_COMPONENT)
5768 if (sas_device_priv_data->sas_target->flags &
5769 MPT_TARGET_FLAGS_VOLUME)
5772 handle = sas_device_priv_data->sas_target->handle;
5773 lun = sas_device_priv_data->lun;
5776 if (ioc->shost_recovery)
5779 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
5780 r = mpt2sas_scsih_issue_tm(ioc, handle, 0, 0, lun,
5781 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, smid, 30, 0,
5784 sdev_printk(KERN_WARNING, sdev,
5785 "mpt2sas_scsih_issue_tm: FAILED when sending "
5786 "QUERY_TASK: scmd(%p)\n", scmd);
5787 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5788 goto broadcast_aen_retry;
5790 ioc_status = le16_to_cpu(mpi_reply->IOCStatus)
5791 & MPI2_IOCSTATUS_MASK;
5792 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5793 sdev_printk(KERN_WARNING, sdev, "query task: FAILED "
5794 "with IOCSTATUS(0x%04x), scmd(%p)\n", ioc_status,
5796 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5797 goto broadcast_aen_retry;
5800 /* see if IO is still owned by IOC and target */
5801 if (mpi_reply->ResponseCode ==
5802 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED ||
5803 mpi_reply->ResponseCode ==
5804 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC) {
5805 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5808 task_abort_retries = 0;
5810 if (task_abort_retries++ == 60) {
5811 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
5812 "%s: ABORT_TASK: giving up\n", ioc->name,
5814 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5815 goto broadcast_aen_retry;
5818 if (ioc->shost_recovery)
5821 r = mpt2sas_scsih_issue_tm(ioc, handle, sdev->channel, sdev->id,
5822 sdev->lun, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30,
5823 scmd->serial_number, TM_MUTEX_OFF);
5825 sdev_printk(KERN_WARNING, sdev,
5826 "mpt2sas_scsih_issue_tm: ABORT_TASK: FAILED : "
5827 "scmd(%p)\n", scmd);
5831 if (task_abort_retries > 1)
5832 sdev_printk(KERN_WARNING, sdev,
5833 "mpt2sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):"
5835 task_abort_retries - 1, scmd);
5837 termination_count += le32_to_cpu(mpi_reply->TerminationCount);
5838 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5841 if (ioc->broadcast_aen_pending) {
5842 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: loop back due to"
5843 " pending AEN\n", ioc->name, __func__));
5844 ioc->broadcast_aen_pending = 0;
5845 goto broadcast_aen_retry;
5849 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
5852 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
5853 "%s - exit, query_count = %d termination_count = %d\n",
5854 ioc->name, __func__, query_count, termination_count));
5856 ioc->broadcast_aen_busy = 0;
5857 if (!ioc->shost_recovery)
5858 _scsih_ublock_io_all_device(ioc);
5859 mutex_unlock(&ioc->tm_cmds.mutex);
5863 * _scsih_sas_discovery_event - handle discovery events
5864 * @ioc: per adapter object
5865 * @fw_event: The fw_event_work object
5871 _scsih_sas_discovery_event(struct MPT2SAS_ADAPTER *ioc,
5872 struct fw_event_work *fw_event)
5874 Mpi2EventDataSasDiscovery_t *event_data = fw_event->event_data;
5876 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5877 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) {
5878 printk(MPT2SAS_INFO_FMT "discovery event: (%s)", ioc->name,
5879 (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ?
5881 if (event_data->DiscoveryStatus)
5882 printk("discovery_status(0x%08x)",
5883 le32_to_cpu(event_data->DiscoveryStatus));
5888 if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED &&
5889 !ioc->sas_hba.num_phys)
5890 _scsih_sas_host_add(ioc);
5894 * _scsih_reprobe_lun - reprobing lun
5895 * @sdev: scsi device struct
5896 * @no_uld_attach: sdev->no_uld_attach flag setting
5900 _scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach)
5904 sdev->no_uld_attach = no_uld_attach ? 1 : 0;
5905 sdev_printk(KERN_INFO, sdev, "%s raid component\n",
5906 sdev->no_uld_attach ? "hidding" : "exposing");
5907 rc = scsi_device_reprobe(sdev);
5911 * _scsih_reprobe_target - reprobing target
5912 * @starget: scsi target struct
5913 * @no_uld_attach: sdev->no_uld_attach flag setting
5915 * Note: no_uld_attach flag determines whether the disk device is attached
5916 * to block layer. A value of `1` means to not attach.
5919 _scsih_reprobe_target(struct scsi_target *starget, int no_uld_attach)
5921 struct MPT2SAS_TARGET *sas_target_priv_data;
5923 if (starget == NULL)
5925 sas_target_priv_data = starget->hostdata;
5927 sas_target_priv_data->flags |= MPT_TARGET_FLAGS_RAID_COMPONENT;
5929 sas_target_priv_data->flags &= ~MPT_TARGET_FLAGS_RAID_COMPONENT;
5931 starget_for_each_device(starget, no_uld_attach ? (void *)1 : NULL,
5932 _scsih_reprobe_lun);
5935 * _scsih_sas_volume_add - add new volume
5936 * @ioc: per adapter object
5937 * @element: IR config element data
5943 _scsih_sas_volume_add(struct MPT2SAS_ADAPTER *ioc,
5944 Mpi2EventIrConfigElement_t *element)
5946 struct _raid_device *raid_device;
5947 unsigned long flags;
5949 u16 handle = le16_to_cpu(element->VolDevHandle);
5952 mpt2sas_config_get_volume_wwid(ioc, handle, &wwid);
5954 printk(MPT2SAS_ERR_FMT
5955 "failure at %s:%d/%s()!\n", ioc->name,
5956 __FILE__, __LINE__, __func__);
5960 spin_lock_irqsave(&ioc->raid_device_lock, flags);
5961 raid_device = _scsih_raid_device_find_by_wwid(ioc, wwid);
5962 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
5967 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
5969 printk(MPT2SAS_ERR_FMT
5970 "failure at %s:%d/%s()!\n", ioc->name,
5971 __FILE__, __LINE__, __func__);
5975 raid_device->id = ioc->sas_id++;
5976 raid_device->channel = RAID_CHANNEL;
5977 raid_device->handle = handle;
5978 raid_device->wwid = wwid;
5979 _scsih_raid_device_add(ioc, raid_device);
5980 if (!ioc->wait_for_discovery_to_complete) {
5981 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
5982 raid_device->id, 0);
5984 _scsih_raid_device_remove(ioc, raid_device);
5986 _scsih_determine_boot_device(ioc, raid_device, 1);
5990 * _scsih_sas_volume_delete - delete volume
5991 * @ioc: per adapter object
5992 * @handle: volume device handle
5998 _scsih_sas_volume_delete(struct MPT2SAS_ADAPTER *ioc, u16 handle)
6000 struct _raid_device *raid_device;
6001 unsigned long flags;
6002 struct MPT2SAS_TARGET *sas_target_priv_data;
6004 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6005 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
6006 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6009 if (raid_device->starget) {
6010 sas_target_priv_data = raid_device->starget->hostdata;
6011 sas_target_priv_data->deleted = 1;
6012 scsi_remove_target(&raid_device->starget->dev);
6014 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), wwid"
6015 "(0x%016llx)\n", ioc->name, raid_device->handle,
6016 (unsigned long long) raid_device->wwid);
6017 _scsih_raid_device_remove(ioc, raid_device);
6021 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
6022 * @ioc: per adapter object
6023 * @element: IR config element data
6029 _scsih_sas_pd_expose(struct MPT2SAS_ADAPTER *ioc,
6030 Mpi2EventIrConfigElement_t *element)
6032 struct _sas_device *sas_device;
6033 unsigned long flags;
6034 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6036 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6037 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6038 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6042 /* exposing raid component */
6043 sas_device->volume_handle = 0;
6044 sas_device->volume_wwid = 0;
6045 clear_bit(handle, ioc->pd_handles);
6046 _scsih_reprobe_target(sas_device->starget, 0);
6050 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
6051 * @ioc: per adapter object
6052 * @element: IR config element data
6058 _scsih_sas_pd_hide(struct MPT2SAS_ADAPTER *ioc,
6059 Mpi2EventIrConfigElement_t *element)
6061 struct _sas_device *sas_device;
6062 unsigned long flags;
6063 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6065 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6066 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6067 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6071 /* hiding raid component */
6072 mpt2sas_config_get_volume_handle(ioc, handle,
6073 &sas_device->volume_handle);
6074 mpt2sas_config_get_volume_wwid(ioc, sas_device->volume_handle,
6075 &sas_device->volume_wwid);
6076 set_bit(handle, ioc->pd_handles);
6077 _scsih_reprobe_target(sas_device->starget, 1);
6082 * _scsih_sas_pd_delete - delete pd component
6083 * @ioc: per adapter object
6084 * @element: IR config element data
6090 _scsih_sas_pd_delete(struct MPT2SAS_ADAPTER *ioc,
6091 Mpi2EventIrConfigElement_t *element)
6093 struct _sas_device *sas_device;
6094 unsigned long flags;
6095 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6097 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6098 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6099 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6102 _scsih_remove_device(ioc, sas_device);
6106 * _scsih_sas_pd_add - remove pd component
6107 * @ioc: per adapter object
6108 * @element: IR config element data
6114 _scsih_sas_pd_add(struct MPT2SAS_ADAPTER *ioc,
6115 Mpi2EventIrConfigElement_t *element)
6117 struct _sas_device *sas_device;
6118 unsigned long flags;
6119 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6120 Mpi2ConfigReply_t mpi_reply;
6121 Mpi2SasDevicePage0_t sas_device_pg0;
6126 set_bit(handle, ioc->pd_handles);
6128 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6129 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6130 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6134 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
6135 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
6136 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6137 ioc->name, __FILE__, __LINE__, __func__);
6141 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6142 MPI2_IOCSTATUS_MASK;
6143 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6144 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6145 ioc->name, __FILE__, __LINE__, __func__);
6149 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6150 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
6151 mpt2sas_transport_update_links(ioc, sas_address, handle,
6152 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
6154 _scsih_add_device(ioc, handle, 0, 1);
6157 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6159 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
6160 * @ioc: per adapter object
6161 * @event_data: event data payload
6167 _scsih_sas_ir_config_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
6168 Mpi2EventDataIrConfigChangeList_t *event_data)
6170 Mpi2EventIrConfigElement_t *element;
6173 char *reason_str = NULL, *element_str = NULL;
6175 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
6177 printk(MPT2SAS_INFO_FMT "raid config change: (%s), elements(%d)\n",
6178 ioc->name, (le32_to_cpu(event_data->Flags) &
6179 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ?
6180 "foreign" : "native", event_data->NumElements);
6181 for (i = 0; i < event_data->NumElements; i++, element++) {
6182 switch (element->ReasonCode) {
6183 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
6186 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
6187 reason_str = "remove";
6189 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE:
6190 reason_str = "no change";
6192 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
6193 reason_str = "hide";
6195 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
6196 reason_str = "unhide";
6198 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
6199 reason_str = "volume_created";
6201 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
6202 reason_str = "volume_deleted";
6204 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
6205 reason_str = "pd_created";
6207 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
6208 reason_str = "pd_deleted";
6211 reason_str = "unknown reason";
6214 element_type = le16_to_cpu(element->ElementFlags) &
6215 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK;
6216 switch (element_type) {
6217 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT:
6218 element_str = "volume";
6220 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT:
6221 element_str = "phys disk";
6223 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT:
6224 element_str = "hot spare";
6227 element_str = "unknown element";
6230 printk(KERN_INFO "\t(%s:%s), vol handle(0x%04x), "
6231 "pd handle(0x%04x), pd num(0x%02x)\n", element_str,
6232 reason_str, le16_to_cpu(element->VolDevHandle),
6233 le16_to_cpu(element->PhysDiskDevHandle),
6234 element->PhysDiskNum);
6240 * _scsih_sas_ir_config_change_event - handle ir configuration change events
6241 * @ioc: per adapter object
6242 * @fw_event: The fw_event_work object
6248 _scsih_sas_ir_config_change_event(struct MPT2SAS_ADAPTER *ioc,
6249 struct fw_event_work *fw_event)
6251 Mpi2EventIrConfigElement_t *element;
6254 Mpi2EventDataIrConfigChangeList_t *event_data = fw_event->event_data;
6256 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6257 if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6258 && !ioc->hide_ir_msg)
6259 _scsih_sas_ir_config_change_event_debug(ioc, event_data);
6263 if (ioc->shost_recovery)
6266 foreign_config = (le32_to_cpu(event_data->Flags) &
6267 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0;
6269 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
6270 for (i = 0; i < event_data->NumElements; i++, element++) {
6272 switch (element->ReasonCode) {
6273 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
6274 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
6275 if (!foreign_config)
6276 _scsih_sas_volume_add(ioc, element);
6278 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
6279 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
6280 if (!foreign_config)
6281 _scsih_sas_volume_delete(ioc,
6282 le16_to_cpu(element->VolDevHandle));
6284 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
6285 if (!ioc->is_warpdrive)
6286 _scsih_sas_pd_hide(ioc, element);
6288 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
6289 if (!ioc->is_warpdrive)
6290 _scsih_sas_pd_expose(ioc, element);
6292 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
6293 if (!ioc->is_warpdrive)
6294 _scsih_sas_pd_add(ioc, element);
6296 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
6297 if (!ioc->is_warpdrive)
6298 _scsih_sas_pd_delete(ioc, element);
6305 * _scsih_sas_ir_volume_event - IR volume event
6306 * @ioc: per adapter object
6307 * @fw_event: The fw_event_work object
6313 _scsih_sas_ir_volume_event(struct MPT2SAS_ADAPTER *ioc,
6314 struct fw_event_work *fw_event)
6317 unsigned long flags;
6318 struct _raid_device *raid_device;
6322 Mpi2EventDataIrVolume_t *event_data = fw_event->event_data;
6324 if (ioc->shost_recovery)
6327 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
6330 handle = le16_to_cpu(event_data->VolDevHandle);
6331 state = le32_to_cpu(event_data->NewValue);
6332 if (!ioc->hide_ir_msg)
6333 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle(0x%04x), "
6334 "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle,
6335 le32_to_cpu(event_data->PreviousValue), state));
6338 case MPI2_RAID_VOL_STATE_MISSING:
6339 case MPI2_RAID_VOL_STATE_FAILED:
6340 _scsih_sas_volume_delete(ioc, handle);
6343 case MPI2_RAID_VOL_STATE_ONLINE:
6344 case MPI2_RAID_VOL_STATE_DEGRADED:
6345 case MPI2_RAID_VOL_STATE_OPTIMAL:
6347 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6348 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
6349 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6354 mpt2sas_config_get_volume_wwid(ioc, handle, &wwid);
6356 printk(MPT2SAS_ERR_FMT
6357 "failure at %s:%d/%s()!\n", ioc->name,
6358 __FILE__, __LINE__, __func__);
6362 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
6364 printk(MPT2SAS_ERR_FMT
6365 "failure at %s:%d/%s()!\n", ioc->name,
6366 __FILE__, __LINE__, __func__);
6370 raid_device->id = ioc->sas_id++;
6371 raid_device->channel = RAID_CHANNEL;
6372 raid_device->handle = handle;
6373 raid_device->wwid = wwid;
6374 _scsih_raid_device_add(ioc, raid_device);
6375 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
6376 raid_device->id, 0);
6378 _scsih_raid_device_remove(ioc, raid_device);
6381 case MPI2_RAID_VOL_STATE_INITIALIZING:
6388 * _scsih_sas_ir_physical_disk_event - PD event
6389 * @ioc: per adapter object
6390 * @fw_event: The fw_event_work object
6396 _scsih_sas_ir_physical_disk_event(struct MPT2SAS_ADAPTER *ioc,
6397 struct fw_event_work *fw_event)
6399 u16 handle, parent_handle;
6401 struct _sas_device *sas_device;
6402 unsigned long flags;
6403 Mpi2ConfigReply_t mpi_reply;
6404 Mpi2SasDevicePage0_t sas_device_pg0;
6406 Mpi2EventDataIrPhysicalDisk_t *event_data = fw_event->event_data;
6409 if (ioc->shost_recovery)
6412 if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED)
6415 handle = le16_to_cpu(event_data->PhysDiskDevHandle);
6416 state = le32_to_cpu(event_data->NewValue);
6418 if (!ioc->hide_ir_msg)
6419 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle(0x%04x), "
6420 "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle,
6421 le32_to_cpu(event_data->PreviousValue), state));
6424 case MPI2_RAID_PD_STATE_ONLINE:
6425 case MPI2_RAID_PD_STATE_DEGRADED:
6426 case MPI2_RAID_PD_STATE_REBUILDING:
6427 case MPI2_RAID_PD_STATE_OPTIMAL:
6428 case MPI2_RAID_PD_STATE_HOT_SPARE:
6430 if (!ioc->is_warpdrive)
6431 set_bit(handle, ioc->pd_handles);
6433 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6434 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6435 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6440 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6441 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
6443 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6444 ioc->name, __FILE__, __LINE__, __func__);
6448 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6449 MPI2_IOCSTATUS_MASK;
6450 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6451 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6452 ioc->name, __FILE__, __LINE__, __func__);
6456 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6457 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
6458 mpt2sas_transport_update_links(ioc, sas_address, handle,
6459 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
6461 _scsih_add_device(ioc, handle, 0, 1);
6465 case MPI2_RAID_PD_STATE_OFFLINE:
6466 case MPI2_RAID_PD_STATE_NOT_CONFIGURED:
6467 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE:
6473 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6475 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
6476 * @ioc: per adapter object
6477 * @event_data: event data payload
6483 _scsih_sas_ir_operation_status_event_debug(struct MPT2SAS_ADAPTER *ioc,
6484 Mpi2EventDataIrOperationStatus_t *event_data)
6486 char *reason_str = NULL;
6488 switch (event_data->RAIDOperation) {
6489 case MPI2_EVENT_IR_RAIDOP_RESYNC:
6490 reason_str = "resync";
6492 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION:
6493 reason_str = "online capacity expansion";
6495 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK:
6496 reason_str = "consistency check";
6498 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT:
6499 reason_str = "background init";
6501 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT:
6502 reason_str = "make data consistent";
6509 printk(MPT2SAS_INFO_FMT "raid operational status: (%s)"
6510 "\thandle(0x%04x), percent complete(%d)\n",
6511 ioc->name, reason_str,
6512 le16_to_cpu(event_data->VolDevHandle),
6513 event_data->PercentComplete);
6518 * _scsih_sas_ir_operation_status_event - handle RAID operation events
6519 * @ioc: per adapter object
6520 * @fw_event: The fw_event_work object
6526 _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
6527 struct fw_event_work *fw_event)
6529 Mpi2EventDataIrOperationStatus_t *event_data = fw_event->event_data;
6530 static struct _raid_device *raid_device;
6531 unsigned long flags;
6534 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6535 if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6536 && !ioc->hide_ir_msg)
6537 _scsih_sas_ir_operation_status_event_debug(ioc,
6541 /* code added for raid transport support */
6542 if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC) {
6544 handle = le16_to_cpu(event_data->VolDevHandle);
6546 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6547 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
6548 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6553 if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC)
6554 raid_device->percent_complete =
6555 event_data->PercentComplete;
6560 * _scsih_prep_device_scan - initialize parameters prior to device scan
6561 * @ioc: per adapter object
6563 * Set the deleted flag prior to device scan. If the device is found during
6564 * the scan, then we clear the deleted flag.
6567 _scsih_prep_device_scan(struct MPT2SAS_ADAPTER *ioc)
6569 struct MPT2SAS_DEVICE *sas_device_priv_data;
6570 struct scsi_device *sdev;
6572 shost_for_each_device(sdev, ioc->shost) {
6573 sas_device_priv_data = sdev->hostdata;
6574 if (sas_device_priv_data && sas_device_priv_data->sas_target)
6575 sas_device_priv_data->sas_target->deleted = 1;
6580 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
6581 * @ioc: per adapter object
6582 * @sas_address: sas address
6583 * @slot: enclosure slot id
6584 * @handle: device handle
6586 * After host reset, find out whether devices are still responding.
6587 * Used in _scsi_remove_unresponsive_sas_devices.
6592 _scsih_mark_responding_sas_device(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
6593 u16 slot, u16 handle)
6595 struct MPT2SAS_TARGET *sas_target_priv_data = NULL;
6596 struct scsi_target *starget;
6597 struct _sas_device *sas_device;
6598 unsigned long flags;
6600 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6601 list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
6602 if (sas_device->sas_address == sas_address &&
6603 sas_device->slot == slot) {
6604 sas_device->responding = 1;
6605 starget = sas_device->starget;
6606 if (starget && starget->hostdata) {
6607 sas_target_priv_data = starget->hostdata;
6608 sas_target_priv_data->tm_busy = 0;
6609 sas_target_priv_data->deleted = 0;
6611 sas_target_priv_data = NULL;
6613 starget_printk(KERN_INFO, starget,
6614 "handle(0x%04x), sas_addr(0x%016llx), "
6615 "enclosure logical id(0x%016llx), "
6616 "slot(%d)\n", handle,
6617 (unsigned long long)sas_device->sas_address,
6618 (unsigned long long)
6619 sas_device->enclosure_logical_id,
6621 if (sas_device->handle == handle)
6623 printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n",
6624 sas_device->handle);
6625 sas_device->handle = handle;
6626 if (sas_target_priv_data)
6627 sas_target_priv_data->handle = handle;
6632 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6636 * _scsih_search_responding_sas_devices -
6637 * @ioc: per adapter object
6639 * After host reset, find out whether devices are still responding.
6645 _scsih_search_responding_sas_devices(struct MPT2SAS_ADAPTER *ioc)
6647 Mpi2SasDevicePage0_t sas_device_pg0;
6648 Mpi2ConfigReply_t mpi_reply;
6655 printk(MPT2SAS_INFO_FMT "search for end-devices: start\n", ioc->name);
6657 if (list_empty(&ioc->sas_device_list))
6661 while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6662 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
6664 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6665 MPI2_IOCSTATUS_MASK;
6666 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
6668 handle = le16_to_cpu(sas_device_pg0.DevHandle);
6669 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
6670 if (!(_scsih_is_end_device(device_info)))
6672 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
6673 slot = le16_to_cpu(sas_device_pg0.Slot);
6674 _scsih_mark_responding_sas_device(ioc, sas_address, slot,
6678 printk(MPT2SAS_INFO_FMT "search for end-devices: complete\n",
6683 * _scsih_mark_responding_raid_device - mark a raid_device as responding
6684 * @ioc: per adapter object
6685 * @wwid: world wide identifier for raid volume
6686 * @handle: device handle
6688 * After host reset, find out whether devices are still responding.
6689 * Used in _scsi_remove_unresponsive_raid_devices.
6694 _scsih_mark_responding_raid_device(struct MPT2SAS_ADAPTER *ioc, u64 wwid,
6697 struct MPT2SAS_TARGET *sas_target_priv_data;
6698 struct scsi_target *starget;
6699 struct _raid_device *raid_device;
6700 unsigned long flags;
6702 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6703 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
6704 if (raid_device->wwid == wwid && raid_device->starget) {
6705 starget = raid_device->starget;
6706 if (starget && starget->hostdata) {
6707 sas_target_priv_data = starget->hostdata;
6708 sas_target_priv_data->deleted = 0;
6710 sas_target_priv_data = NULL;
6711 raid_device->responding = 1;
6712 starget_printk(KERN_INFO, raid_device->starget,
6713 "handle(0x%04x), wwid(0x%016llx)\n", handle,
6714 (unsigned long long)raid_device->wwid);
6716 * WARPDRIVE: The handles of the PDs might have changed
6717 * across the host reset so re-initialize the
6718 * required data for Direct IO
6720 _scsih_init_warpdrive_properties(ioc, raid_device);
6721 if (raid_device->handle == handle)
6723 printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n",
6724 raid_device->handle);
6725 raid_device->handle = handle;
6726 if (sas_target_priv_data)
6727 sas_target_priv_data->handle = handle;
6732 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6736 * _scsih_search_responding_raid_devices -
6737 * @ioc: per adapter object
6739 * After host reset, find out whether devices are still responding.
6745 _scsih_search_responding_raid_devices(struct MPT2SAS_ADAPTER *ioc)
6747 Mpi2RaidVolPage1_t volume_pg1;
6748 Mpi2RaidVolPage0_t volume_pg0;
6749 Mpi2RaidPhysDiskPage0_t pd_pg0;
6750 Mpi2ConfigReply_t mpi_reply;
6755 if (!ioc->ir_firmware)
6758 printk(MPT2SAS_INFO_FMT "search for raid volumes: start\n",
6761 if (list_empty(&ioc->raid_device_list))
6765 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
6766 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
6767 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6768 MPI2_IOCSTATUS_MASK;
6769 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
6771 handle = le16_to_cpu(volume_pg1.DevHandle);
6773 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
6774 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
6775 sizeof(Mpi2RaidVolPage0_t)))
6778 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
6779 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
6780 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED)
6781 _scsih_mark_responding_raid_device(ioc,
6782 le64_to_cpu(volume_pg1.WWID), handle);
6785 /* refresh the pd_handles */
6786 if (!ioc->is_warpdrive) {
6787 phys_disk_num = 0xFF;
6788 memset(ioc->pd_handles, 0, ioc->pd_handles_sz);
6789 while (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
6790 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
6792 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6793 MPI2_IOCSTATUS_MASK;
6794 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
6796 phys_disk_num = pd_pg0.PhysDiskNum;
6797 handle = le16_to_cpu(pd_pg0.DevHandle);
6798 set_bit(handle, ioc->pd_handles);
6802 printk(MPT2SAS_INFO_FMT "search for responding raid volumes: "
6803 "complete\n", ioc->name);
6807 * _scsih_mark_responding_expander - mark a expander as responding
6808 * @ioc: per adapter object
6809 * @sas_address: sas address
6812 * After host reset, find out whether devices are still responding.
6813 * Used in _scsi_remove_unresponsive_expanders.
6818 _scsih_mark_responding_expander(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
6821 struct _sas_node *sas_expander;
6822 unsigned long flags;
6825 spin_lock_irqsave(&ioc->sas_node_lock, flags);
6826 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
6827 if (sas_expander->sas_address != sas_address)
6829 sas_expander->responding = 1;
6830 if (sas_expander->handle == handle)
6832 printk(KERN_INFO "\texpander(0x%016llx): handle changed"
6833 " from(0x%04x) to (0x%04x)!!!\n",
6834 (unsigned long long)sas_expander->sas_address,
6835 sas_expander->handle, handle);
6836 sas_expander->handle = handle;
6837 for (i = 0 ; i < sas_expander->num_phys ; i++)
6838 sas_expander->phy[i].handle = handle;
6842 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
6846 * _scsih_search_responding_expanders -
6847 * @ioc: per adapter object
6849 * After host reset, find out whether devices are still responding.
6855 _scsih_search_responding_expanders(struct MPT2SAS_ADAPTER *ioc)
6857 Mpi2ExpanderPage0_t expander_pg0;
6858 Mpi2ConfigReply_t mpi_reply;
6863 printk(MPT2SAS_INFO_FMT "search for expanders: start\n", ioc->name);
6865 if (list_empty(&ioc->sas_expander_list))
6869 while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
6870 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
6872 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6873 MPI2_IOCSTATUS_MASK;
6874 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
6877 handle = le16_to_cpu(expander_pg0.DevHandle);
6878 sas_address = le64_to_cpu(expander_pg0.SASAddress);
6879 printk(KERN_INFO "\texpander present: handle(0x%04x), "
6880 "sas_addr(0x%016llx)\n", handle,
6881 (unsigned long long)sas_address);
6882 _scsih_mark_responding_expander(ioc, sas_address, handle);
6886 printk(MPT2SAS_INFO_FMT "search for expanders: complete\n", ioc->name);
6890 * _scsih_remove_unresponding_sas_devices - removing unresponding devices
6891 * @ioc: per adapter object
6896 _scsih_remove_unresponding_sas_devices(struct MPT2SAS_ADAPTER *ioc)
6898 struct _sas_device *sas_device, *sas_device_next;
6899 struct _sas_node *sas_expander;
6900 struct _raid_device *raid_device, *raid_device_next;
6902 printk(MPT2SAS_INFO_FMT "removing unresponding devices: start\n",
6905 list_for_each_entry_safe(sas_device, sas_device_next,
6906 &ioc->sas_device_list, list) {
6907 if (sas_device->responding) {
6908 sas_device->responding = 0;
6911 if (sas_device->starget)
6912 starget_printk(KERN_INFO, sas_device->starget,
6913 "removing: handle(0x%04x), sas_addr(0x%016llx), "
6914 "enclosure logical id(0x%016llx), slot(%d)\n",
6916 (unsigned long long)sas_device->sas_address,
6917 (unsigned long long)
6918 sas_device->enclosure_logical_id,
6920 _scsih_remove_device(ioc, sas_device);
6923 if (!ioc->ir_firmware)
6924 goto retry_expander_search;
6926 list_for_each_entry_safe(raid_device, raid_device_next,
6927 &ioc->raid_device_list, list) {
6928 if (raid_device->responding) {
6929 raid_device->responding = 0;
6932 if (raid_device->starget) {
6933 starget_printk(KERN_INFO, raid_device->starget,
6934 "removing: handle(0x%04x), wwid(0x%016llx)\n",
6935 raid_device->handle,
6936 (unsigned long long)raid_device->wwid);
6937 scsi_remove_target(&raid_device->starget->dev);
6939 _scsih_raid_device_remove(ioc, raid_device);
6942 retry_expander_search:
6943 sas_expander = NULL;
6944 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
6945 if (sas_expander->responding) {
6946 sas_expander->responding = 0;
6949 mpt2sas_expander_remove(ioc, sas_expander->sas_address);
6950 goto retry_expander_search;
6952 printk(MPT2SAS_INFO_FMT "removing unresponding devices: complete\n",
6954 /* unblock devices */
6955 _scsih_ublock_io_all_device(ioc);
6959 _scsih_refresh_expander_links(struct MPT2SAS_ADAPTER *ioc,
6960 struct _sas_node *sas_expander, u16 handle)
6962 Mpi2ExpanderPage1_t expander_pg1;
6963 Mpi2ConfigReply_t mpi_reply;
6966 for (i = 0 ; i < sas_expander->num_phys ; i++) {
6967 if ((mpt2sas_config_get_expander_pg1(ioc, &mpi_reply,
6968 &expander_pg1, i, handle))) {
6969 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6970 ioc->name, __FILE__, __LINE__, __func__);
6974 mpt2sas_transport_update_links(ioc, sas_expander->sas_address,
6975 le16_to_cpu(expander_pg1.AttachedDevHandle), i,
6976 expander_pg1.NegotiatedLinkRate >> 4);
6981 * _scsih_scan_for_devices_after_reset - scan for devices after host reset
6982 * @ioc: per adapter object
6987 _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
6989 Mpi2ExpanderPage0_t expander_pg0;
6990 Mpi2SasDevicePage0_t sas_device_pg0;
6991 Mpi2RaidVolPage1_t volume_pg1;
6992 Mpi2RaidVolPage0_t volume_pg0;
6993 Mpi2RaidPhysDiskPage0_t pd_pg0;
6994 Mpi2EventIrConfigElement_t element;
6995 Mpi2ConfigReply_t mpi_reply;
6998 u16 handle, parent_handle;
7000 struct _sas_device *sas_device;
7001 struct _sas_node *expander_device;
7002 static struct _raid_device *raid_device;
7004 printk(MPT2SAS_INFO_FMT "scan devices: start\n", ioc->name);
7006 _scsih_sas_host_refresh(ioc);
7010 while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
7011 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
7012 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7013 MPI2_IOCSTATUS_MASK;
7014 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
7016 handle = le16_to_cpu(expander_pg0.DevHandle);
7017 expander_device = mpt2sas_scsih_expander_find_by_sas_address(
7018 ioc, le64_to_cpu(expander_pg0.SASAddress));
7019 if (expander_device)
7020 _scsih_refresh_expander_links(ioc, expander_device,
7023 _scsih_expander_add(ioc, handle);
7026 if (!ioc->ir_firmware)
7030 phys_disk_num = 0xFF;
7031 while (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
7032 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
7034 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7035 MPI2_IOCSTATUS_MASK;
7036 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
7038 phys_disk_num = pd_pg0.PhysDiskNum;
7039 handle = le16_to_cpu(pd_pg0.DevHandle);
7040 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
7043 if (mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
7044 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
7047 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
7048 if (!_scsih_get_sas_address(ioc, parent_handle,
7050 mpt2sas_transport_update_links(ioc, sas_address,
7051 handle, sas_device_pg0.PhyNum,
7052 MPI2_SAS_NEG_LINK_RATE_1_5);
7053 set_bit(handle, ioc->pd_handles);
7054 _scsih_add_device(ioc, handle, 0, 1);
7060 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
7061 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
7062 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7063 MPI2_IOCSTATUS_MASK;
7064 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
7066 handle = le16_to_cpu(volume_pg1.DevHandle);
7067 raid_device = _scsih_raid_device_find_by_wwid(ioc,
7068 le64_to_cpu(volume_pg1.WWID));
7071 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
7072 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
7073 sizeof(Mpi2RaidVolPage0_t)))
7075 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
7076 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
7077 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) {
7078 memset(&element, 0, sizeof(Mpi2EventIrConfigElement_t));
7079 element.ReasonCode = MPI2_EVENT_IR_CHANGE_RC_ADDED;
7080 element.VolDevHandle = volume_pg1.DevHandle;
7081 _scsih_sas_volume_add(ioc, &element);
7089 while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
7090 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
7092 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7093 MPI2_IOCSTATUS_MASK;
7094 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
7096 handle = le16_to_cpu(sas_device_pg0.DevHandle);
7097 if (!(_scsih_is_end_device(
7098 le32_to_cpu(sas_device_pg0.DeviceInfo))))
7100 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
7101 le64_to_cpu(sas_device_pg0.SASAddress));
7104 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
7105 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) {
7106 mpt2sas_transport_update_links(ioc, sas_address, handle,
7107 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
7108 _scsih_add_device(ioc, handle, 0, 0);
7112 printk(MPT2SAS_INFO_FMT "scan devices: complete\n", ioc->name);
7117 * mpt2sas_scsih_reset_handler - reset callback handler (for scsih)
7118 * @ioc: per adapter object
7119 * @reset_phase: phase
7121 * The handler for doing any required cleanup or initialization.
7123 * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
7124 * MPT2_IOC_DONE_RESET
7129 mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase)
7131 switch (reset_phase) {
7132 case MPT2_IOC_PRE_RESET:
7133 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
7134 "MPT2_IOC_PRE_RESET\n", ioc->name, __func__));
7136 case MPT2_IOC_AFTER_RESET:
7137 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
7138 "MPT2_IOC_AFTER_RESET\n", ioc->name, __func__));
7139 if (ioc->scsih_cmds.status & MPT2_CMD_PENDING) {
7140 ioc->scsih_cmds.status |= MPT2_CMD_RESET;
7141 mpt2sas_base_free_smid(ioc, ioc->scsih_cmds.smid);
7142 complete(&ioc->scsih_cmds.done);
7144 if (ioc->tm_cmds.status & MPT2_CMD_PENDING) {
7145 ioc->tm_cmds.status |= MPT2_CMD_RESET;
7146 mpt2sas_base_free_smid(ioc, ioc->tm_cmds.smid);
7147 complete(&ioc->tm_cmds.done);
7149 _scsih_fw_event_cleanup_queue(ioc);
7150 _scsih_flush_running_cmds(ioc);
7152 case MPT2_IOC_DONE_RESET:
7153 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
7154 "MPT2_IOC_DONE_RESET\n", ioc->name, __func__));
7155 _scsih_sas_host_refresh(ioc);
7156 _scsih_prep_device_scan(ioc);
7157 _scsih_search_responding_sas_devices(ioc);
7158 _scsih_search_responding_raid_devices(ioc);
7159 _scsih_search_responding_expanders(ioc);
7160 if (!ioc->is_driver_loading) {
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 _scsih_error_recovery_delete_devices(ioc);
7172 * _firmware_event_work - delayed task for processing firmware events
7173 * @ioc: per adapter object
7174 * @work: equal to the fw_event_work object
7180 _firmware_event_work(struct work_struct *work)
7182 struct fw_event_work *fw_event = container_of(work,
7183 struct fw_event_work, delayed_work.work);
7184 struct MPT2SAS_ADAPTER *ioc = fw_event->ioc;
7186 /* the queue is being flushed so ignore this event */
7187 if (ioc->remove_host || fw_event->cancel_pending_work ||
7188 ioc->pci_error_recovery) {
7189 _scsih_fw_event_free(ioc, fw_event);
7193 switch (fw_event->event) {
7194 case MPT2SAS_REMOVE_UNRESPONDING_DEVICES:
7195 while (scsi_host_in_recovery(ioc->shost))
7197 _scsih_remove_unresponding_sas_devices(ioc);
7198 _scsih_scan_for_devices_after_reset(ioc);
7200 case MPT2SAS_PORT_ENABLE_COMPLETE:
7201 ioc->start_scan = 0;
7205 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "port enable: complete "
7206 "from worker thread\n", ioc->name));
7208 case MPT2SAS_TURN_ON_FAULT_LED:
7209 _scsih_turn_on_fault_led(ioc, fw_event->device_handle);
7211 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
7212 _scsih_sas_topology_change_event(ioc, fw_event);
7214 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
7215 _scsih_sas_device_status_change_event(ioc,
7218 case MPI2_EVENT_SAS_DISCOVERY:
7219 _scsih_sas_discovery_event(ioc,
7222 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
7223 _scsih_sas_broadcast_primative_event(ioc,
7226 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
7227 _scsih_sas_enclosure_dev_status_change_event(ioc,
7230 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
7231 _scsih_sas_ir_config_change_event(ioc, fw_event);
7233 case MPI2_EVENT_IR_VOLUME:
7234 _scsih_sas_ir_volume_event(ioc, fw_event);
7236 case MPI2_EVENT_IR_PHYSICAL_DISK:
7237 _scsih_sas_ir_physical_disk_event(ioc, fw_event);
7239 case MPI2_EVENT_IR_OPERATION_STATUS:
7240 _scsih_sas_ir_operation_status_event(ioc, fw_event);
7243 _scsih_fw_event_free(ioc, fw_event);
7247 * mpt2sas_scsih_event_callback - firmware event handler (called at ISR time)
7248 * @ioc: per adapter object
7249 * @msix_index: MSIX table index supplied by the OS
7250 * @reply: reply message frame(lower 32bit addr)
7251 * Context: interrupt.
7253 * This function merely adds a new work task into ioc->firmware_event_thread.
7254 * The tasks are worked from _firmware_event_work in user context.
7256 * Return 1 meaning mf should be freed from _base_interrupt
7257 * 0 means the mf is freed from this function.
7260 mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER *ioc, u8 msix_index,
7263 struct fw_event_work *fw_event;
7264 Mpi2EventNotificationReply_t *mpi_reply;
7268 /* events turned off due to host reset or driver unloading */
7269 if (ioc->remove_host || ioc->pci_error_recovery)
7272 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
7273 event = le16_to_cpu(mpi_reply->Event);
7277 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
7279 Mpi2EventDataSasBroadcastPrimitive_t *baen_data =
7280 (Mpi2EventDataSasBroadcastPrimitive_t *)
7281 mpi_reply->EventData;
7283 if (baen_data->Primitive !=
7284 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT)
7287 if (ioc->broadcast_aen_busy) {
7288 ioc->broadcast_aen_pending++;
7291 ioc->broadcast_aen_busy = 1;
7295 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
7296 _scsih_check_topo_delete_events(ioc,
7297 (Mpi2EventDataSasTopologyChangeList_t *)
7298 mpi_reply->EventData);
7300 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
7301 _scsih_check_ir_config_unhide_events(ioc,
7302 (Mpi2EventDataIrConfigChangeList_t *)
7303 mpi_reply->EventData);
7305 case MPI2_EVENT_IR_VOLUME:
7306 _scsih_check_volume_delete_events(ioc,
7307 (Mpi2EventDataIrVolume_t *)
7308 mpi_reply->EventData);
7310 case MPI2_EVENT_LOG_ENTRY_ADDED:
7312 Mpi2EventDataLogEntryAdded_t *log_entry;
7315 if (!ioc->is_warpdrive)
7318 log_entry = (Mpi2EventDataLogEntryAdded_t *)
7319 mpi_reply->EventData;
7320 log_code = (u32 *)log_entry->LogData;
7322 if (le16_to_cpu(log_entry->LogEntryQualifier)
7323 != MPT2_WARPDRIVE_LOGENTRY)
7326 switch (le32_to_cpu(*log_code)) {
7327 case MPT2_WARPDRIVE_LC_SSDT:
7328 printk(MPT2SAS_WARN_FMT "WarpDrive Warning: "
7329 "IO Throttling has occurred in the WarpDrive "
7330 "subsystem. Check WarpDrive documentation for "
7331 "additional details.\n", ioc->name);
7333 case MPT2_WARPDRIVE_LC_SSDLW:
7334 printk(MPT2SAS_WARN_FMT "WarpDrive Warning: "
7335 "Program/Erase Cycles for the WarpDrive subsystem "
7336 "in degraded range. Check WarpDrive documentation "
7337 "for additional details.\n", ioc->name);
7339 case MPT2_WARPDRIVE_LC_SSDLF:
7340 printk(MPT2SAS_ERR_FMT "WarpDrive Fatal Error: "
7341 "There are no Program/Erase Cycles for the "
7342 "WarpDrive subsystem. The storage device will be "
7343 "in read-only mode. Check WarpDrive documentation "
7344 "for additional details.\n", ioc->name);
7346 case MPT2_WARPDRIVE_LC_BRMF:
7347 printk(MPT2SAS_ERR_FMT "WarpDrive Fatal Error: "
7348 "The Backup Rail Monitor has failed on the "
7349 "WarpDrive subsystem. Check WarpDrive "
7350 "documentation for additional details.\n",
7357 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
7358 case MPI2_EVENT_IR_OPERATION_STATUS:
7359 case MPI2_EVENT_SAS_DISCOVERY:
7360 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
7361 case MPI2_EVENT_IR_PHYSICAL_DISK:
7364 default: /* ignore the rest */
7368 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
7370 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
7371 ioc->name, __FILE__, __LINE__, __func__);
7374 sz = le16_to_cpu(mpi_reply->EventDataLength) * 4;
7375 fw_event->event_data = kzalloc(sz, GFP_ATOMIC);
7376 if (!fw_event->event_data) {
7377 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
7378 ioc->name, __FILE__, __LINE__, __func__);
7383 memcpy(fw_event->event_data, mpi_reply->EventData,
7385 fw_event->ioc = ioc;
7386 fw_event->VF_ID = mpi_reply->VF_ID;
7387 fw_event->VP_ID = mpi_reply->VP_ID;
7388 fw_event->event = event;
7389 _scsih_fw_event_add(ioc, fw_event);
7393 /* shost template */
7394 static struct scsi_host_template scsih_driver_template = {
7395 .module = THIS_MODULE,
7396 .name = "Fusion MPT SAS Host",
7397 .proc_name = MPT2SAS_DRIVER_NAME,
7398 .queuecommand = _scsih_qcmd,
7399 .target_alloc = _scsih_target_alloc,
7400 .slave_alloc = _scsih_slave_alloc,
7401 .slave_configure = _scsih_slave_configure,
7402 .target_destroy = _scsih_target_destroy,
7403 .slave_destroy = _scsih_slave_destroy,
7404 .scan_finished = _scsih_scan_finished,
7405 .scan_start = _scsih_scan_start,
7406 .change_queue_depth = _scsih_change_queue_depth,
7407 .change_queue_type = _scsih_change_queue_type,
7408 .eh_abort_handler = _scsih_abort,
7409 .eh_device_reset_handler = _scsih_dev_reset,
7410 .eh_target_reset_handler = _scsih_target_reset,
7411 .eh_host_reset_handler = _scsih_host_reset,
7412 .bios_param = _scsih_bios_param,
7415 .sg_tablesize = MPT2SAS_SG_DEPTH,
7416 .max_sectors = 8192,
7418 .use_clustering = ENABLE_CLUSTERING,
7419 .shost_attrs = mpt2sas_host_attrs,
7420 .sdev_attrs = mpt2sas_dev_attrs,
7424 * _scsih_expander_node_remove - removing expander device from list.
7425 * @ioc: per adapter object
7426 * @sas_expander: the sas_device object
7427 * Context: Calling function should acquire ioc->sas_node_lock.
7429 * Removing object and freeing associated memory from the
7430 * ioc->sas_expander_list.
7435 _scsih_expander_node_remove(struct MPT2SAS_ADAPTER *ioc,
7436 struct _sas_node *sas_expander)
7438 struct _sas_port *mpt2sas_port, *next;
7440 /* remove sibling ports attached to this expander */
7441 list_for_each_entry_safe(mpt2sas_port, next,
7442 &sas_expander->sas_port_list, port_list) {
7443 if (ioc->shost_recovery)
7445 if (mpt2sas_port->remote_identify.device_type ==
7447 mpt2sas_device_remove(ioc,
7448 mpt2sas_port->remote_identify.sas_address);
7449 else if (mpt2sas_port->remote_identify.device_type ==
7450 SAS_EDGE_EXPANDER_DEVICE ||
7451 mpt2sas_port->remote_identify.device_type ==
7452 SAS_FANOUT_EXPANDER_DEVICE)
7453 mpt2sas_expander_remove(ioc,
7454 mpt2sas_port->remote_identify.sas_address);
7457 mpt2sas_transport_port_remove(ioc, sas_expander->sas_address,
7458 sas_expander->sas_address_parent);
7460 printk(MPT2SAS_INFO_FMT "expander_remove: handle"
7461 "(0x%04x), sas_addr(0x%016llx)\n", ioc->name,
7462 sas_expander->handle, (unsigned long long)
7463 sas_expander->sas_address);
7465 kfree(sas_expander->phy);
7466 kfree(sas_expander);
7470 * _scsih_ir_shutdown - IR shutdown notification
7471 * @ioc: per adapter object
7473 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
7474 * the host system is shutting down.
7479 _scsih_ir_shutdown(struct MPT2SAS_ADAPTER *ioc)
7481 Mpi2RaidActionRequest_t *mpi_request;
7482 Mpi2RaidActionReply_t *mpi_reply;
7485 /* is IR firmware build loaded ? */
7486 if (!ioc->ir_firmware)
7489 /* are there any volumes ? */
7490 if (list_empty(&ioc->raid_device_list))
7493 mutex_lock(&ioc->scsih_cmds.mutex);
7495 if (ioc->scsih_cmds.status != MPT2_CMD_NOT_USED) {
7496 printk(MPT2SAS_ERR_FMT "%s: scsih_cmd in use\n",
7497 ioc->name, __func__);
7500 ioc->scsih_cmds.status = MPT2_CMD_PENDING;
7502 smid = mpt2sas_base_get_smid(ioc, ioc->scsih_cb_idx);
7504 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
7505 ioc->name, __func__);
7506 ioc->scsih_cmds.status = MPT2_CMD_NOT_USED;
7510 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
7511 ioc->scsih_cmds.smid = smid;
7512 memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t));
7514 mpi_request->Function = MPI2_FUNCTION_RAID_ACTION;
7515 mpi_request->Action = MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED;
7517 if (!ioc->hide_ir_msg)
7518 printk(MPT2SAS_INFO_FMT "IR shutdown (sending)\n", ioc->name);
7519 init_completion(&ioc->scsih_cmds.done);
7520 mpt2sas_base_put_smid_default(ioc, smid);
7521 wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ);
7523 if (!(ioc->scsih_cmds.status & MPT2_CMD_COMPLETE)) {
7524 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
7525 ioc->name, __func__);
7529 if (ioc->scsih_cmds.status & MPT2_CMD_REPLY_VALID) {
7530 mpi_reply = ioc->scsih_cmds.reply;
7532 if (!ioc->hide_ir_msg)
7533 printk(MPT2SAS_INFO_FMT "IR shutdown (complete): "
7534 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7535 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
7536 le32_to_cpu(mpi_reply->IOCLogInfo));
7540 ioc->scsih_cmds.status = MPT2_CMD_NOT_USED;
7541 mutex_unlock(&ioc->scsih_cmds.mutex);
7545 * _scsih_shutdown - routine call during system shutdown
7546 * @pdev: PCI device struct
7551 _scsih_shutdown(struct pci_dev *pdev)
7553 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7554 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
7555 struct workqueue_struct *wq;
7556 unsigned long flags;
7558 ioc->remove_host = 1;
7559 _scsih_fw_event_cleanup_queue(ioc);
7561 spin_lock_irqsave(&ioc->fw_event_lock, flags);
7562 wq = ioc->firmware_event_thread;
7563 ioc->firmware_event_thread = NULL;
7564 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
7566 destroy_workqueue(wq);
7568 _scsih_ir_shutdown(ioc);
7569 mpt2sas_base_detach(ioc);
7573 * _scsih_remove - detach and remove add host
7574 * @pdev: PCI device struct
7576 * Routine called when unloading the driver.
7579 static void __devexit
7580 _scsih_remove(struct pci_dev *pdev)
7582 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7583 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
7584 struct _sas_port *mpt2sas_port, *next_port;
7585 struct _raid_device *raid_device, *next;
7586 struct MPT2SAS_TARGET *sas_target_priv_data;
7587 struct workqueue_struct *wq;
7588 unsigned long flags;
7590 ioc->remove_host = 1;
7591 _scsih_fw_event_cleanup_queue(ioc);
7593 spin_lock_irqsave(&ioc->fw_event_lock, flags);
7594 wq = ioc->firmware_event_thread;
7595 ioc->firmware_event_thread = NULL;
7596 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
7598 destroy_workqueue(wq);
7600 /* release all the volumes */
7601 _scsih_ir_shutdown(ioc);
7602 list_for_each_entry_safe(raid_device, next, &ioc->raid_device_list,
7604 if (raid_device->starget) {
7605 sas_target_priv_data =
7606 raid_device->starget->hostdata;
7607 sas_target_priv_data->deleted = 1;
7608 scsi_remove_target(&raid_device->starget->dev);
7610 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), wwid"
7611 "(0x%016llx)\n", ioc->name, raid_device->handle,
7612 (unsigned long long) raid_device->wwid);
7613 _scsih_raid_device_remove(ioc, raid_device);
7616 /* free ports attached to the sas_host */
7617 list_for_each_entry_safe(mpt2sas_port, next_port,
7618 &ioc->sas_hba.sas_port_list, port_list) {
7619 if (mpt2sas_port->remote_identify.device_type ==
7621 mpt2sas_device_remove(ioc,
7622 mpt2sas_port->remote_identify.sas_address);
7623 else if (mpt2sas_port->remote_identify.device_type ==
7624 SAS_EDGE_EXPANDER_DEVICE ||
7625 mpt2sas_port->remote_identify.device_type ==
7626 SAS_FANOUT_EXPANDER_DEVICE)
7627 mpt2sas_expander_remove(ioc,
7628 mpt2sas_port->remote_identify.sas_address);
7631 /* free phys attached to the sas_host */
7632 if (ioc->sas_hba.num_phys) {
7633 kfree(ioc->sas_hba.phy);
7634 ioc->sas_hba.phy = NULL;
7635 ioc->sas_hba.num_phys = 0;
7638 sas_remove_host(shost);
7639 mpt2sas_base_detach(ioc);
7640 list_del(&ioc->list);
7641 scsi_remove_host(shost);
7642 scsi_host_put(shost);
7646 * _scsih_probe_boot_devices - reports 1st device
7647 * @ioc: per adapter object
7649 * If specified in bios page 2, this routine reports the 1st
7650 * device scsi-ml or sas transport for persistent boot device
7651 * purposes. Please refer to function _scsih_determine_boot_device()
7654 _scsih_probe_boot_devices(struct MPT2SAS_ADAPTER *ioc)
7658 struct _sas_device *sas_device;
7659 struct _raid_device *raid_device;
7661 u64 sas_address_parent;
7663 unsigned long flags;
7666 /* no Bios, return immediately */
7667 if (!ioc->bios_pg3.BiosVersion)
7672 if (ioc->req_boot_device.device) {
7673 device = ioc->req_boot_device.device;
7674 is_raid = ioc->req_boot_device.is_raid;
7675 } else if (ioc->req_alt_boot_device.device) {
7676 device = ioc->req_alt_boot_device.device;
7677 is_raid = ioc->req_alt_boot_device.is_raid;
7678 } else if (ioc->current_boot_device.device) {
7679 device = ioc->current_boot_device.device;
7680 is_raid = ioc->current_boot_device.is_raid;
7687 raid_device = device;
7688 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
7689 raid_device->id, 0);
7691 _scsih_raid_device_remove(ioc, raid_device);
7693 sas_device = device;
7694 handle = sas_device->handle;
7695 sas_address_parent = sas_device->sas_address_parent;
7696 sas_address = sas_device->sas_address;
7697 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7698 list_move_tail(&sas_device->list, &ioc->sas_device_list);
7699 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7701 if (ioc->hide_drives)
7703 if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
7704 sas_device->sas_address_parent)) {
7705 _scsih_sas_device_remove(ioc, sas_device);
7706 } else if (!sas_device->starget) {
7707 if (!ioc->is_driver_loading)
7708 mpt2sas_transport_port_remove(ioc, sas_address,
7709 sas_address_parent);
7710 _scsih_sas_device_remove(ioc, sas_device);
7716 * _scsih_probe_raid - reporting raid volumes to scsi-ml
7717 * @ioc: per adapter object
7719 * Called during initial loading of the driver.
7722 _scsih_probe_raid(struct MPT2SAS_ADAPTER *ioc)
7724 struct _raid_device *raid_device, *raid_next;
7727 list_for_each_entry_safe(raid_device, raid_next,
7728 &ioc->raid_device_list, list) {
7729 if (raid_device->starget)
7731 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
7732 raid_device->id, 0);
7734 _scsih_raid_device_remove(ioc, raid_device);
7739 * _scsih_probe_sas - reporting sas devices to sas transport
7740 * @ioc: per adapter object
7742 * Called during initial loading of the driver.
7745 _scsih_probe_sas(struct MPT2SAS_ADAPTER *ioc)
7747 struct _sas_device *sas_device, *next;
7748 unsigned long flags;
7750 /* SAS Device List */
7751 list_for_each_entry_safe(sas_device, next, &ioc->sas_device_init_list,
7754 if (ioc->hide_drives)
7757 if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
7758 sas_device->sas_address_parent)) {
7759 list_del(&sas_device->list);
7762 } else if (!sas_device->starget) {
7763 if (!ioc->is_driver_loading)
7764 mpt2sas_transport_port_remove(ioc,
7765 sas_device->sas_address,
7766 sas_device->sas_address_parent);
7767 list_del(&sas_device->list);
7772 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7773 list_move_tail(&sas_device->list, &ioc->sas_device_list);
7774 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7779 * _scsih_probe_devices - probing for devices
7780 * @ioc: per adapter object
7782 * Called during initial loading of the driver.
7785 _scsih_probe_devices(struct MPT2SAS_ADAPTER *ioc)
7787 u16 volume_mapping_flags;
7789 if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR))
7790 return; /* return when IOC doesn't support initiator mode */
7792 _scsih_probe_boot_devices(ioc);
7794 if (ioc->ir_firmware) {
7795 volume_mapping_flags =
7796 le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) &
7797 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE;
7798 if (volume_mapping_flags ==
7799 MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING) {
7800 _scsih_probe_raid(ioc);
7801 _scsih_probe_sas(ioc);
7803 _scsih_probe_sas(ioc);
7804 _scsih_probe_raid(ioc);
7807 _scsih_probe_sas(ioc);
7812 * _scsih_scan_start - scsi lld callback for .scan_start
7813 * @shost: SCSI host pointer
7815 * The shost has the ability to discover targets on its own instead
7816 * of scanning the entire bus. In our implemention, we will kick off
7817 * firmware discovery.
7820 _scsih_scan_start(struct Scsi_Host *shost)
7822 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
7825 if (diag_buffer_enable != -1 && diag_buffer_enable != 0)
7826 mpt2sas_enable_diag_buffer(ioc, diag_buffer_enable);
7828 ioc->start_scan = 1;
7829 rc = mpt2sas_port_enable(ioc);
7832 printk(MPT2SAS_INFO_FMT "port enable: FAILED\n", ioc->name);
7836 * _scsih_scan_finished - scsi lld callback for .scan_finished
7837 * @shost: SCSI host pointer
7838 * @time: elapsed time of the scan in jiffies
7840 * This function will be called periodically until it returns 1 with the
7841 * scsi_host and the elapsed time of the scan in jiffies. In our implemention,
7842 * we wait for firmware discovery to complete, then return 1.
7845 _scsih_scan_finished(struct Scsi_Host *shost, unsigned long time)
7847 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
7849 if (time >= (300 * HZ)) {
7850 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
7851 printk(MPT2SAS_INFO_FMT "port enable: FAILED with timeout "
7852 "(timeout=300s)\n", ioc->name);
7853 ioc->is_driver_loading = 0;
7857 if (ioc->start_scan)
7860 if (ioc->start_scan_failed) {
7861 printk(MPT2SAS_INFO_FMT "port enable: FAILED with "
7862 "(ioc_status=0x%08x)\n", ioc->name, ioc->start_scan_failed);
7863 ioc->is_driver_loading = 0;
7864 ioc->wait_for_discovery_to_complete = 0;
7865 ioc->remove_host = 1;
7869 printk(MPT2SAS_INFO_FMT "port enable: SUCCESS\n", ioc->name);
7870 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
7872 if (ioc->wait_for_discovery_to_complete) {
7873 ioc->wait_for_discovery_to_complete = 0;
7874 _scsih_probe_devices(ioc);
7876 mpt2sas_base_start_watchdog(ioc);
7877 ioc->is_driver_loading = 0;
7883 * _scsih_probe - attach and add scsi host
7884 * @pdev: PCI device struct
7885 * @id: pci device id
7887 * Returns 0 success, anything else error.
7890 _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id)
7892 struct MPT2SAS_ADAPTER *ioc;
7893 struct Scsi_Host *shost;
7895 shost = scsi_host_alloc(&scsih_driver_template,
7896 sizeof(struct MPT2SAS_ADAPTER));
7900 /* init local params */
7901 ioc = shost_priv(shost);
7902 memset(ioc, 0, sizeof(struct MPT2SAS_ADAPTER));
7903 INIT_LIST_HEAD(&ioc->list);
7904 list_add_tail(&ioc->list, &mpt2sas_ioc_list);
7906 ioc->id = mpt_ids++;
7907 sprintf(ioc->name, "%s%d", MPT2SAS_DRIVER_NAME, ioc->id);
7909 if (id->device == MPI2_MFGPAGE_DEVID_SSS6200) {
7910 ioc->is_warpdrive = 1;
7911 ioc->hide_ir_msg = 1;
7913 ioc->mfg_pg10_hide_flag = MFG_PAGE10_EXPOSE_ALL_DISKS;
7914 ioc->scsi_io_cb_idx = scsi_io_cb_idx;
7915 ioc->tm_cb_idx = tm_cb_idx;
7916 ioc->ctl_cb_idx = ctl_cb_idx;
7917 ioc->base_cb_idx = base_cb_idx;
7918 ioc->port_enable_cb_idx = port_enable_cb_idx;
7919 ioc->transport_cb_idx = transport_cb_idx;
7920 ioc->scsih_cb_idx = scsih_cb_idx;
7921 ioc->config_cb_idx = config_cb_idx;
7922 ioc->tm_tr_cb_idx = tm_tr_cb_idx;
7923 ioc->tm_tr_volume_cb_idx = tm_tr_volume_cb_idx;
7924 ioc->tm_sas_control_cb_idx = tm_sas_control_cb_idx;
7925 ioc->logging_level = logging_level;
7926 /* misc semaphores and spin locks */
7927 mutex_init(&ioc->reset_in_progress_mutex);
7928 spin_lock_init(&ioc->ioc_reset_in_progress_lock);
7929 spin_lock_init(&ioc->scsi_lookup_lock);
7930 spin_lock_init(&ioc->sas_device_lock);
7931 spin_lock_init(&ioc->sas_node_lock);
7932 spin_lock_init(&ioc->fw_event_lock);
7933 spin_lock_init(&ioc->raid_device_lock);
7935 INIT_LIST_HEAD(&ioc->sas_device_list);
7936 INIT_LIST_HEAD(&ioc->sas_device_init_list);
7937 INIT_LIST_HEAD(&ioc->sas_expander_list);
7938 INIT_LIST_HEAD(&ioc->fw_event_list);
7939 INIT_LIST_HEAD(&ioc->raid_device_list);
7940 INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list);
7941 INIT_LIST_HEAD(&ioc->delayed_tr_list);
7942 INIT_LIST_HEAD(&ioc->delayed_tr_volume_list);
7944 /* init shost parameters */
7945 shost->max_cmd_len = 32;
7946 shost->max_lun = max_lun;
7947 shost->transportt = mpt2sas_transport_template;
7948 shost->unique_id = ioc->id;
7950 if (max_sectors != 0xFFFF) {
7951 if (max_sectors < 64) {
7952 shost->max_sectors = 64;
7953 printk(MPT2SAS_WARN_FMT "Invalid value %d passed "
7954 "for max_sectors, range is 64 to 8192. Assigning "
7955 "value of 64.\n", ioc->name, max_sectors);
7956 } else if (max_sectors > 8192) {
7957 shost->max_sectors = 8192;
7958 printk(MPT2SAS_WARN_FMT "Invalid value %d passed "
7959 "for max_sectors, range is 64 to 8192. Assigning "
7960 "default value of 8192.\n", ioc->name,
7963 shost->max_sectors = max_sectors & 0xFFFE;
7964 printk(MPT2SAS_INFO_FMT "The max_sectors value is "
7965 "set to %d\n", ioc->name, shost->max_sectors);
7969 if ((scsi_add_host(shost, &pdev->dev))) {
7970 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
7971 ioc->name, __FILE__, __LINE__, __func__);
7972 list_del(&ioc->list);
7973 goto out_add_shost_fail;
7976 scsi_host_set_prot(shost, SHOST_DIF_TYPE1_PROTECTION
7977 | SHOST_DIF_TYPE2_PROTECTION | SHOST_DIF_TYPE3_PROTECTION);
7978 scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC);
7981 snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name),
7982 "fw_event%d", ioc->id);
7983 ioc->firmware_event_thread = create_singlethread_workqueue(
7984 ioc->firmware_event_name);
7985 if (!ioc->firmware_event_thread) {
7986 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
7987 ioc->name, __FILE__, __LINE__, __func__);
7988 goto out_thread_fail;
7991 ioc->is_driver_loading = 1;
7992 if ((mpt2sas_base_attach(ioc))) {
7993 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
7994 ioc->name, __FILE__, __LINE__, __func__);
7995 goto out_attach_fail;
7998 scsi_scan_host(shost);
7999 if (ioc->is_warpdrive) {
8000 if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS)
8001 ioc->hide_drives = 0;
8002 else if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_HIDE_ALL_DISKS)
8003 ioc->hide_drives = 1;
8005 if (_scsih_get_num_volumes(ioc))
8006 ioc->hide_drives = 1;
8008 ioc->hide_drives = 0;
8011 ioc->hide_drives = 0;
8013 _scsih_probe_devices(ioc);
8017 destroy_workqueue(ioc->firmware_event_thread);
8019 list_del(&ioc->list);
8020 scsi_remove_host(shost);
8021 scsi_host_put(shost);
8028 * _scsih_suspend - power management suspend main entry point
8029 * @pdev: PCI device struct
8030 * @state: PM state change to (usually PCI_D3)
8032 * Returns 0 success, anything else error.
8035 _scsih_suspend(struct pci_dev *pdev, pm_message_t state)
8037 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8038 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8039 pci_power_t device_state;
8041 mpt2sas_base_stop_watchdog(ioc);
8042 scsi_block_requests(shost);
8043 device_state = pci_choose_state(pdev, state);
8044 printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, entering "
8045 "operating state [D%d]\n", ioc->name, pdev,
8046 pci_name(pdev), device_state);
8048 mpt2sas_base_free_resources(ioc);
8049 pci_save_state(pdev);
8050 pci_disable_device(pdev);
8051 pci_set_power_state(pdev, device_state);
8056 * _scsih_resume - power management resume main entry point
8057 * @pdev: PCI device struct
8059 * Returns 0 success, anything else error.
8062 _scsih_resume(struct pci_dev *pdev)
8064 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8065 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8066 pci_power_t device_state = pdev->current_state;
8069 printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, previous "
8070 "operating state [D%d]\n", ioc->name, pdev,
8071 pci_name(pdev), device_state);
8073 pci_set_power_state(pdev, PCI_D0);
8074 pci_enable_wake(pdev, PCI_D0, 0);
8075 pci_restore_state(pdev);
8077 r = mpt2sas_base_map_resources(ioc);
8081 mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, SOFT_RESET);
8082 scsi_unblock_requests(shost);
8083 mpt2sas_base_start_watchdog(ioc);
8086 #endif /* CONFIG_PM */
8089 * _scsih_pci_error_detected - Called when a PCI error is detected.
8090 * @pdev: PCI device struct
8091 * @state: PCI channel state
8093 * Description: Called when a PCI error is detected.
8096 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
8098 static pci_ers_result_t
8099 _scsih_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
8101 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8102 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8104 printk(MPT2SAS_INFO_FMT "PCI error: detected callback, state(%d)!!\n",
8108 case pci_channel_io_normal:
8109 return PCI_ERS_RESULT_CAN_RECOVER;
8110 case pci_channel_io_frozen:
8111 /* Fatal error, prepare for slot reset */
8112 ioc->pci_error_recovery = 1;
8113 scsi_block_requests(ioc->shost);
8114 mpt2sas_base_stop_watchdog(ioc);
8115 mpt2sas_base_free_resources(ioc);
8116 return PCI_ERS_RESULT_NEED_RESET;
8117 case pci_channel_io_perm_failure:
8118 /* Permanent error, prepare for device removal */
8119 ioc->pci_error_recovery = 1;
8120 mpt2sas_base_stop_watchdog(ioc);
8121 _scsih_flush_running_cmds(ioc);
8122 return PCI_ERS_RESULT_DISCONNECT;
8124 return PCI_ERS_RESULT_NEED_RESET;
8128 * _scsih_pci_slot_reset - Called when PCI slot has been reset.
8129 * @pdev: PCI device struct
8131 * Description: This routine is called by the pci error recovery
8132 * code after the PCI slot has been reset, just before we
8133 * should resume normal operations.
8135 static pci_ers_result_t
8136 _scsih_pci_slot_reset(struct pci_dev *pdev)
8138 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8139 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8142 printk(MPT2SAS_INFO_FMT "PCI error: slot reset callback!!\n",
8145 ioc->pci_error_recovery = 0;
8147 pci_restore_state(pdev);
8148 rc = mpt2sas_base_map_resources(ioc);
8150 return PCI_ERS_RESULT_DISCONNECT;
8153 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
8156 printk(MPT2SAS_WARN_FMT "hard reset: %s\n", ioc->name,
8157 (rc == 0) ? "success" : "failed");
8160 return PCI_ERS_RESULT_RECOVERED;
8162 return PCI_ERS_RESULT_DISCONNECT;
8166 * _scsih_pci_resume() - resume normal ops after PCI reset
8167 * @pdev: pointer to PCI device
8169 * Called when the error recovery driver tells us that its
8170 * OK to resume normal operation. Use completion to allow
8171 * halted scsi ops to resume.
8174 _scsih_pci_resume(struct pci_dev *pdev)
8176 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8177 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8179 printk(MPT2SAS_INFO_FMT "PCI error: resume callback!!\n", ioc->name);
8181 pci_cleanup_aer_uncorrect_error_status(pdev);
8182 mpt2sas_base_start_watchdog(ioc);
8183 scsi_unblock_requests(ioc->shost);
8187 * _scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
8188 * @pdev: pointer to PCI device
8190 static pci_ers_result_t
8191 _scsih_pci_mmio_enabled(struct pci_dev *pdev)
8193 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8194 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8196 printk(MPT2SAS_INFO_FMT "PCI error: mmio enabled callback!!\n",
8199 /* TODO - dump whatever for debugging purposes */
8201 /* Request a slot reset. */
8202 return PCI_ERS_RESULT_NEED_RESET;
8205 static struct pci_error_handlers _scsih_err_handler = {
8206 .error_detected = _scsih_pci_error_detected,
8207 .mmio_enabled = _scsih_pci_mmio_enabled,
8208 .slot_reset = _scsih_pci_slot_reset,
8209 .resume = _scsih_pci_resume,
8212 static struct pci_driver scsih_driver = {
8213 .name = MPT2SAS_DRIVER_NAME,
8214 .id_table = scsih_pci_table,
8215 .probe = _scsih_probe,
8216 .remove = __devexit_p(_scsih_remove),
8217 .shutdown = _scsih_shutdown,
8218 .err_handler = &_scsih_err_handler,
8220 .suspend = _scsih_suspend,
8221 .resume = _scsih_resume,
8225 /* raid transport support */
8226 static struct raid_function_template mpt2sas_raid_functions = {
8227 .cookie = &scsih_driver_template,
8228 .is_raid = _scsih_is_raid,
8229 .get_resync = _scsih_get_resync,
8230 .get_state = _scsih_get_state,
8234 * _scsih_init - main entry point for this driver.
8236 * Returns 0 success, anything else error.
8244 printk(KERN_INFO "%s version %s loaded\n", MPT2SAS_DRIVER_NAME,
8245 MPT2SAS_DRIVER_VERSION);
8247 mpt2sas_transport_template =
8248 sas_attach_transport(&mpt2sas_transport_functions);
8249 if (!mpt2sas_transport_template)
8251 /* raid transport support */
8252 mpt2sas_raid_template = raid_class_attach(&mpt2sas_raid_functions);
8253 if (!mpt2sas_raid_template) {
8254 sas_release_transport(mpt2sas_transport_template);
8258 mpt2sas_base_initialize_callback_handler();
8260 /* queuecommand callback hander */
8261 scsi_io_cb_idx = mpt2sas_base_register_callback_handler(_scsih_io_done);
8263 /* task management callback handler */
8264 tm_cb_idx = mpt2sas_base_register_callback_handler(_scsih_tm_done);
8266 /* base internal commands callback handler */
8267 base_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_base_done);
8268 port_enable_cb_idx = mpt2sas_base_register_callback_handler(
8269 mpt2sas_port_enable_done);
8271 /* transport internal commands callback handler */
8272 transport_cb_idx = mpt2sas_base_register_callback_handler(
8273 mpt2sas_transport_done);
8275 /* scsih internal commands callback handler */
8276 scsih_cb_idx = mpt2sas_base_register_callback_handler(_scsih_done);
8278 /* configuration page API internal commands callback handler */
8279 config_cb_idx = mpt2sas_base_register_callback_handler(
8280 mpt2sas_config_done);
8282 /* ctl module callback handler */
8283 ctl_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_ctl_done);
8285 tm_tr_cb_idx = mpt2sas_base_register_callback_handler(
8286 _scsih_tm_tr_complete);
8288 tm_tr_volume_cb_idx = mpt2sas_base_register_callback_handler(
8289 _scsih_tm_volume_tr_complete);
8291 tm_sas_control_cb_idx = mpt2sas_base_register_callback_handler(
8292 _scsih_sas_control_complete);
8296 error = pci_register_driver(&scsih_driver);
8298 /* raid transport support */
8299 raid_class_release(mpt2sas_raid_template);
8300 sas_release_transport(mpt2sas_transport_template);
8307 * _scsih_exit - exit point for this driver (when it is a module).
8309 * Returns 0 success, anything else error.
8314 printk(KERN_INFO "mpt2sas version %s unloading\n",
8315 MPT2SAS_DRIVER_VERSION);
8317 pci_unregister_driver(&scsih_driver);
8321 mpt2sas_base_release_callback_handler(scsi_io_cb_idx);
8322 mpt2sas_base_release_callback_handler(tm_cb_idx);
8323 mpt2sas_base_release_callback_handler(base_cb_idx);
8324 mpt2sas_base_release_callback_handler(port_enable_cb_idx);
8325 mpt2sas_base_release_callback_handler(transport_cb_idx);
8326 mpt2sas_base_release_callback_handler(scsih_cb_idx);
8327 mpt2sas_base_release_callback_handler(config_cb_idx);
8328 mpt2sas_base_release_callback_handler(ctl_cb_idx);
8330 mpt2sas_base_release_callback_handler(tm_tr_cb_idx);
8331 mpt2sas_base_release_callback_handler(tm_tr_volume_cb_idx);
8332 mpt2sas_base_release_callback_handler(tm_sas_control_cb_idx);
8334 /* raid transport support */
8335 raid_class_release(mpt2sas_raid_template);
8336 sas_release_transport(mpt2sas_transport_template);
8340 module_init(_scsih_init);
8341 module_exit(_scsih_exit);