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 static int missing_delay[2] = {-1, -1};
105 module_param_array(missing_delay, int, NULL, 0);
106 MODULE_PARM_DESC(missing_delay, " device missing delay , io missing delay");
108 /* scsi-mid layer global parmeter is max_report_luns, which is 511 */
109 #define MPT2SAS_MAX_LUN (16895)
110 static int max_lun = MPT2SAS_MAX_LUN;
111 module_param(max_lun, int, 0);
112 MODULE_PARM_DESC(max_lun, " max lun, default=16895 ");
114 /* diag_buffer_enable is bitwise
116 * bit 1 set = SNAPSHOT
117 * bit 2 set = EXTENDED
119 * Either bit can be set, or both
121 static int diag_buffer_enable = -1;
122 module_param(diag_buffer_enable, int, 0);
123 MODULE_PARM_DESC(diag_buffer_enable, " post diag buffers "
124 "(TRACE=1/SNAPSHOT=2/EXTENDED=4/default=0)");
127 * struct sense_info - common structure for obtaining sense keys
129 * @asc: additional sense code
130 * @ascq: additional sense code qualifier
139 #define MPT2SAS_TURN_ON_FAULT_LED (0xFFFC)
140 #define MPT2SAS_PORT_ENABLE_COMPLETE (0xFFFD)
141 #define MPT2SAS_REMOVE_UNRESPONDING_DEVICES (0xFFFF)
143 * struct fw_event_work - firmware event struct
144 * @list: link list framework
145 * @work: work object (ioc->fault_reset_work_q)
146 * @cancel_pending_work: flag set during reset handling
147 * @ioc: per adapter object
148 * @device_handle: device handle
149 * @VF_ID: virtual function id
150 * @VP_ID: virtual port id
151 * @ignore: flag meaning this event has been marked to ignore
152 * @event: firmware event MPI2_EVENT_XXX defined in mpt2_ioc.h
153 * @event_data: reply event data payload follows
155 * This object stored on ioc->fw_event_list.
157 struct fw_event_work {
158 struct list_head list;
159 u8 cancel_pending_work;
160 struct delayed_work delayed_work;
161 struct MPT2SAS_ADAPTER *ioc;
170 /* raid transport support */
171 static struct raid_template *mpt2sas_raid_template;
174 * struct _scsi_io_transfer - scsi io transfer
175 * @handle: sas device handle (assigned by firmware)
176 * @is_raid: flag set for hidden raid components
177 * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE,
178 * @data_length: data transfer length
179 * @data_dma: dma pointer to data
182 * @cdb_length: cdb length
184 * @timeout: timeout for this command
185 * @VF_ID: virtual function id
186 * @VP_ID: virtual port id
187 * @valid_reply: flag set for reply message
188 * @sense_length: sense length
189 * @ioc_status: ioc status
190 * @scsi_state: scsi state
191 * @scsi_status: scsi staus
192 * @log_info: log information
193 * @transfer_length: data length transfer when there is a reply message
195 * Used for sending internal scsi commands to devices within this module.
196 * Refer to _scsi_send_scsi_io().
198 struct _scsi_io_transfer {
201 enum dma_data_direction dir;
204 u8 sense[SCSI_SENSE_BUFFERSIZE];
212 /* the following bits are only valid when 'valid_reply = 1' */
222 * The pci device ids are defined in mpi/mpi2_cnfg.h.
224 static struct pci_device_id scsih_pci_table[] = {
225 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2004,
226 PCI_ANY_ID, PCI_ANY_ID },
228 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2008,
229 PCI_ANY_ID, PCI_ANY_ID },
230 /* Liberator ~ 2108 */
231 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_1,
232 PCI_ANY_ID, PCI_ANY_ID },
233 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_2,
234 PCI_ANY_ID, PCI_ANY_ID },
235 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_3,
236 PCI_ANY_ID, PCI_ANY_ID },
238 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_1,
239 PCI_ANY_ID, PCI_ANY_ID },
240 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_2,
241 PCI_ANY_ID, PCI_ANY_ID },
242 /* Thunderbolt ~ 2208 */
243 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_1,
244 PCI_ANY_ID, PCI_ANY_ID },
245 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_2,
246 PCI_ANY_ID, PCI_ANY_ID },
247 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_3,
248 PCI_ANY_ID, PCI_ANY_ID },
249 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_4,
250 PCI_ANY_ID, PCI_ANY_ID },
251 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_5,
252 PCI_ANY_ID, PCI_ANY_ID },
253 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_6,
254 PCI_ANY_ID, PCI_ANY_ID },
256 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_1,
257 PCI_ANY_ID, PCI_ANY_ID },
258 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_2,
259 PCI_ANY_ID, PCI_ANY_ID },
260 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_3,
261 PCI_ANY_ID, PCI_ANY_ID },
263 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SSS6200,
264 PCI_ANY_ID, PCI_ANY_ID },
265 {0} /* Terminating entry */
267 MODULE_DEVICE_TABLE(pci, scsih_pci_table);
270 * _scsih_set_debug_level - global setting of ioc->logging_level.
272 * Note: The logging levels are defined in mpt2sas_debug.h.
275 _scsih_set_debug_level(const char *val, struct kernel_param *kp)
277 int ret = param_set_int(val, kp);
278 struct MPT2SAS_ADAPTER *ioc;
283 printk(KERN_INFO "setting logging_level(0x%08x)\n", logging_level);
284 list_for_each_entry(ioc, &mpt2sas_ioc_list, list)
285 ioc->logging_level = logging_level;
288 module_param_call(logging_level, _scsih_set_debug_level, param_get_int,
289 &logging_level, 0644);
292 * _scsih_srch_boot_sas_address - search based on sas_address
293 * @sas_address: sas address
294 * @boot_device: boot device object from bios page 2
296 * Returns 1 when there's a match, 0 means no match.
299 _scsih_srch_boot_sas_address(u64 sas_address,
300 Mpi2BootDeviceSasWwid_t *boot_device)
302 return (sas_address == le64_to_cpu(boot_device->SASAddress)) ? 1 : 0;
306 * _scsih_srch_boot_device_name - search based on device name
307 * @device_name: device name specified in INDENTIFY fram
308 * @boot_device: boot device object from bios page 2
310 * Returns 1 when there's a match, 0 means no match.
313 _scsih_srch_boot_device_name(u64 device_name,
314 Mpi2BootDeviceDeviceName_t *boot_device)
316 return (device_name == le64_to_cpu(boot_device->DeviceName)) ? 1 : 0;
320 * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot
321 * @enclosure_logical_id: enclosure logical id
322 * @slot_number: slot number
323 * @boot_device: boot device object from bios page 2
325 * Returns 1 when there's a match, 0 means no match.
328 _scsih_srch_boot_encl_slot(u64 enclosure_logical_id, u16 slot_number,
329 Mpi2BootDeviceEnclosureSlot_t *boot_device)
331 return (enclosure_logical_id == le64_to_cpu(boot_device->
332 EnclosureLogicalID) && slot_number == le16_to_cpu(boot_device->
333 SlotNumber)) ? 1 : 0;
337 * _scsih_is_boot_device - search for matching boot device.
338 * @sas_address: sas address
339 * @device_name: device name specified in INDENTIFY fram
340 * @enclosure_logical_id: enclosure logical id
341 * @slot_number: slot number
342 * @form: specifies boot device form
343 * @boot_device: boot device object from bios page 2
345 * Returns 1 when there's a match, 0 means no match.
348 _scsih_is_boot_device(u64 sas_address, u64 device_name,
349 u64 enclosure_logical_id, u16 slot, u8 form,
350 Mpi2BiosPage2BootDevice_t *boot_device)
355 case MPI2_BIOSPAGE2_FORM_SAS_WWID:
358 rc = _scsih_srch_boot_sas_address(
359 sas_address, &boot_device->SasWwid);
361 case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT:
362 if (!enclosure_logical_id)
364 rc = _scsih_srch_boot_encl_slot(
365 enclosure_logical_id,
366 slot, &boot_device->EnclosureSlot);
368 case MPI2_BIOSPAGE2_FORM_DEVICE_NAME:
371 rc = _scsih_srch_boot_device_name(
372 device_name, &boot_device->DeviceName);
374 case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED:
382 * _scsih_get_sas_address - set the sas_address for given device handle
383 * @handle: device handle
384 * @sas_address: sas address
386 * Returns 0 success, non-zero when failure
389 _scsih_get_sas_address(struct MPT2SAS_ADAPTER *ioc, u16 handle,
392 Mpi2SasDevicePage0_t sas_device_pg0;
393 Mpi2ConfigReply_t mpi_reply;
397 if (handle <= ioc->sas_hba.num_phys) {
398 *sas_address = ioc->sas_hba.sas_address;
402 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
403 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
404 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", ioc->name,
405 __FILE__, __LINE__, __func__);
409 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
410 if (ioc_status == MPI2_IOCSTATUS_SUCCESS) {
411 *sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
415 /* we hit this becuase the given parent handle doesn't exist */
416 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
418 /* else error case */
419 printk(MPT2SAS_ERR_FMT "handle(0x%04x), ioc_status(0x%04x), "
420 "failure at %s:%d/%s()!\n", ioc->name, handle, ioc_status,
421 __FILE__, __LINE__, __func__);
426 * _scsih_determine_boot_device - determine boot device.
427 * @ioc: per adapter object
428 * @device: either sas_device or raid_device object
429 * @is_raid: [flag] 1 = raid object, 0 = sas object
431 * Determines whether this device should be first reported device to
432 * to scsi-ml or sas transport, this purpose is for persistent boot device.
433 * There are primary, alternate, and current entries in bios page 2. The order
434 * priority is primary, alternate, then current. This routine saves
435 * the corresponding device object and is_raid flag in the ioc object.
436 * The saved data to be used later in _scsih_probe_boot_devices().
439 _scsih_determine_boot_device(struct MPT2SAS_ADAPTER *ioc,
440 void *device, u8 is_raid)
442 struct _sas_device *sas_device;
443 struct _raid_device *raid_device;
446 u64 enclosure_logical_id;
449 /* only process this function when driver loads */
450 if (!ioc->is_driver_loading)
453 /* no Bios, return immediately */
454 if (!ioc->bios_pg3.BiosVersion)
459 sas_address = sas_device->sas_address;
460 device_name = sas_device->device_name;
461 enclosure_logical_id = sas_device->enclosure_logical_id;
462 slot = sas_device->slot;
464 raid_device = device;
465 sas_address = raid_device->wwid;
467 enclosure_logical_id = 0;
471 if (!ioc->req_boot_device.device) {
472 if (_scsih_is_boot_device(sas_address, device_name,
473 enclosure_logical_id, slot,
474 (ioc->bios_pg2.ReqBootDeviceForm &
475 MPI2_BIOSPAGE2_FORM_MASK),
476 &ioc->bios_pg2.RequestedBootDevice)) {
477 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT
478 "%s: req_boot_device(0x%016llx)\n",
480 (unsigned long long)sas_address));
481 ioc->req_boot_device.device = device;
482 ioc->req_boot_device.is_raid = is_raid;
486 if (!ioc->req_alt_boot_device.device) {
487 if (_scsih_is_boot_device(sas_address, device_name,
488 enclosure_logical_id, slot,
489 (ioc->bios_pg2.ReqAltBootDeviceForm &
490 MPI2_BIOSPAGE2_FORM_MASK),
491 &ioc->bios_pg2.RequestedAltBootDevice)) {
492 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT
493 "%s: req_alt_boot_device(0x%016llx)\n",
495 (unsigned long long)sas_address));
496 ioc->req_alt_boot_device.device = device;
497 ioc->req_alt_boot_device.is_raid = is_raid;
501 if (!ioc->current_boot_device.device) {
502 if (_scsih_is_boot_device(sas_address, device_name,
503 enclosure_logical_id, slot,
504 (ioc->bios_pg2.CurrentBootDeviceForm &
505 MPI2_BIOSPAGE2_FORM_MASK),
506 &ioc->bios_pg2.CurrentBootDevice)) {
507 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT
508 "%s: current_boot_device(0x%016llx)\n",
510 (unsigned long long)sas_address));
511 ioc->current_boot_device.device = device;
512 ioc->current_boot_device.is_raid = is_raid;
518 * mpt2sas_scsih_sas_device_find_by_sas_address - sas device search
519 * @ioc: per adapter object
520 * @sas_address: sas address
521 * Context: Calling function should acquire ioc->sas_device_lock
523 * This searches for sas_device based on sas_address, then return sas_device
527 mpt2sas_scsih_sas_device_find_by_sas_address(struct MPT2SAS_ADAPTER *ioc,
530 struct _sas_device *sas_device;
532 list_for_each_entry(sas_device, &ioc->sas_device_list, list)
533 if (sas_device->sas_address == sas_address)
536 list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
537 if (sas_device->sas_address == sas_address)
544 * _scsih_sas_device_find_by_handle - sas device search
545 * @ioc: per adapter object
546 * @handle: sas device handle (assigned by firmware)
547 * Context: Calling function should acquire ioc->sas_device_lock
549 * This searches for sas_device based on sas_address, then return sas_device
552 static struct _sas_device *
553 _scsih_sas_device_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
555 struct _sas_device *sas_device;
557 list_for_each_entry(sas_device, &ioc->sas_device_list, list)
558 if (sas_device->handle == handle)
561 list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
562 if (sas_device->handle == handle)
569 * _scsih_sas_device_remove - remove sas_device from list.
570 * @ioc: per adapter object
571 * @sas_device: the sas_device object
572 * Context: This function will acquire ioc->sas_device_lock.
574 * Removing object and freeing associated memory from the ioc->sas_device_list.
577 _scsih_sas_device_remove(struct MPT2SAS_ADAPTER *ioc,
578 struct _sas_device *sas_device)
585 spin_lock_irqsave(&ioc->sas_device_lock, flags);
586 if (mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
587 sas_device->sas_address)) {
588 list_del(&sas_device->list);
591 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
595 * _scsih_sas_device_add - insert sas_device to the list.
596 * @ioc: per adapter object
597 * @sas_device: the sas_device object
598 * Context: This function will acquire ioc->sas_device_lock.
600 * Adding new object to the ioc->sas_device_list.
603 _scsih_sas_device_add(struct MPT2SAS_ADAPTER *ioc,
604 struct _sas_device *sas_device)
608 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle"
609 "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
610 sas_device->handle, (unsigned long long)sas_device->sas_address));
612 spin_lock_irqsave(&ioc->sas_device_lock, flags);
613 list_add_tail(&sas_device->list, &ioc->sas_device_list);
614 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
616 if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
617 sas_device->sas_address_parent)) {
618 _scsih_sas_device_remove(ioc, sas_device);
619 } else if (!sas_device->starget) {
620 if (!ioc->is_driver_loading)
621 mpt2sas_transport_port_remove(ioc,
622 sas_device->sas_address,
623 sas_device->sas_address_parent);
624 _scsih_sas_device_remove(ioc, sas_device);
629 * _scsih_sas_device_init_add - insert sas_device to the list.
630 * @ioc: per adapter object
631 * @sas_device: the sas_device object
632 * Context: This function will acquire ioc->sas_device_lock.
634 * Adding new object at driver load time to the ioc->sas_device_init_list.
637 _scsih_sas_device_init_add(struct MPT2SAS_ADAPTER *ioc,
638 struct _sas_device *sas_device)
642 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle"
643 "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
644 sas_device->handle, (unsigned long long)sas_device->sas_address));
646 spin_lock_irqsave(&ioc->sas_device_lock, flags);
647 list_add_tail(&sas_device->list, &ioc->sas_device_init_list);
648 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
649 _scsih_determine_boot_device(ioc, sas_device, 0);
653 * _scsih_raid_device_find_by_id - raid device search
654 * @ioc: per adapter object
655 * @id: sas device target id
656 * @channel: sas device channel
657 * Context: Calling function should acquire ioc->raid_device_lock
659 * This searches for raid_device based on target id, then return raid_device
662 static struct _raid_device *
663 _scsih_raid_device_find_by_id(struct MPT2SAS_ADAPTER *ioc, int id, int channel)
665 struct _raid_device *raid_device, *r;
668 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
669 if (raid_device->id == id && raid_device->channel == channel) {
680 * _scsih_raid_device_find_by_handle - raid device search
681 * @ioc: per adapter object
682 * @handle: sas device handle (assigned by firmware)
683 * Context: Calling function should acquire ioc->raid_device_lock
685 * This searches for raid_device based on handle, then return raid_device
688 static struct _raid_device *
689 _scsih_raid_device_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
691 struct _raid_device *raid_device, *r;
694 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
695 if (raid_device->handle != handle)
706 * _scsih_raid_device_find_by_wwid - raid device search
707 * @ioc: per adapter object
708 * @handle: sas device handle (assigned by firmware)
709 * Context: Calling function should acquire ioc->raid_device_lock
711 * This searches for raid_device based on wwid, then return raid_device
714 static struct _raid_device *
715 _scsih_raid_device_find_by_wwid(struct MPT2SAS_ADAPTER *ioc, u64 wwid)
717 struct _raid_device *raid_device, *r;
720 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
721 if (raid_device->wwid != wwid)
732 * _scsih_raid_device_add - add raid_device object
733 * @ioc: per adapter object
734 * @raid_device: raid_device object
736 * This is added to the raid_device_list link list.
739 _scsih_raid_device_add(struct MPT2SAS_ADAPTER *ioc,
740 struct _raid_device *raid_device)
744 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle"
745 "(0x%04x), wwid(0x%016llx)\n", ioc->name, __func__,
746 raid_device->handle, (unsigned long long)raid_device->wwid));
748 spin_lock_irqsave(&ioc->raid_device_lock, flags);
749 list_add_tail(&raid_device->list, &ioc->raid_device_list);
750 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
754 * _scsih_raid_device_remove - delete raid_device object
755 * @ioc: per adapter object
756 * @raid_device: raid_device object
758 * This is removed from the raid_device_list link list.
761 _scsih_raid_device_remove(struct MPT2SAS_ADAPTER *ioc,
762 struct _raid_device *raid_device)
766 spin_lock_irqsave(&ioc->raid_device_lock, flags);
767 list_del(&raid_device->list);
768 memset(raid_device, 0, sizeof(struct _raid_device));
770 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
774 * mpt2sas_scsih_expander_find_by_handle - expander device search
775 * @ioc: per adapter object
776 * @handle: expander handle (assigned by firmware)
777 * Context: Calling function should acquire ioc->sas_device_lock
779 * This searches for expander device based on handle, then returns the
783 mpt2sas_scsih_expander_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
785 struct _sas_node *sas_expander, *r;
788 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
789 if (sas_expander->handle != handle)
799 * mpt2sas_scsih_expander_find_by_sas_address - expander device search
800 * @ioc: per adapter object
801 * @sas_address: sas address
802 * Context: Calling function should acquire ioc->sas_node_lock.
804 * This searches for expander device based on sas_address, then returns the
808 mpt2sas_scsih_expander_find_by_sas_address(struct MPT2SAS_ADAPTER *ioc,
811 struct _sas_node *sas_expander, *r;
814 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
815 if (sas_expander->sas_address != sas_address)
825 * _scsih_expander_node_add - insert expander device to the list.
826 * @ioc: per adapter object
827 * @sas_expander: the sas_device object
828 * Context: This function will acquire ioc->sas_node_lock.
830 * Adding new object to the ioc->sas_expander_list.
835 _scsih_expander_node_add(struct MPT2SAS_ADAPTER *ioc,
836 struct _sas_node *sas_expander)
840 spin_lock_irqsave(&ioc->sas_node_lock, flags);
841 list_add_tail(&sas_expander->list, &ioc->sas_expander_list);
842 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
846 * _scsih_is_end_device - determines if device is an end device
847 * @device_info: bitfield providing information about the device.
850 * Returns 1 if end device.
853 _scsih_is_end_device(u32 device_info)
855 if (device_info & MPI2_SAS_DEVICE_INFO_END_DEVICE &&
856 ((device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) |
857 (device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) |
858 (device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE)))
865 * _scsih_scsi_lookup_get - returns scmd entry
866 * @ioc: per adapter object
867 * @smid: system request message index
869 * Returns the smid stored scmd pointer.
871 static struct scsi_cmnd *
872 _scsih_scsi_lookup_get(struct MPT2SAS_ADAPTER *ioc, u16 smid)
874 return ioc->scsi_lookup[smid - 1].scmd;
878 * _scsih_scsi_lookup_get_clear - returns scmd entry
879 * @ioc: per adapter object
880 * @smid: system request message index
882 * Returns the smid stored scmd pointer.
883 * Then will derefrence the stored scmd pointer.
885 static inline struct scsi_cmnd *
886 _scsih_scsi_lookup_get_clear(struct MPT2SAS_ADAPTER *ioc, u16 smid)
889 struct scsi_cmnd *scmd;
891 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
892 scmd = ioc->scsi_lookup[smid - 1].scmd;
893 ioc->scsi_lookup[smid - 1].scmd = NULL;
894 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
900 * _scsih_scsi_lookup_find_by_scmd - scmd lookup
901 * @ioc: per adapter object
902 * @smid: system request message index
903 * @scmd: pointer to scsi command object
904 * Context: This function will acquire ioc->scsi_lookup_lock.
906 * This will search for a scmd pointer in the scsi_lookup array,
907 * returning the revelent smid. A returned value of zero means invalid.
910 _scsih_scsi_lookup_find_by_scmd(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd
917 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
919 for (i = 0; i < ioc->scsiio_depth; i++) {
920 if (ioc->scsi_lookup[i].scmd == scmd) {
921 smid = ioc->scsi_lookup[i].smid;
926 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
931 * _scsih_scsi_lookup_find_by_target - search for matching channel:id
932 * @ioc: per adapter object
935 * Context: This function will acquire ioc->scsi_lookup_lock.
937 * This will search for a matching channel:id in the scsi_lookup array,
938 * returning 1 if found.
941 _scsih_scsi_lookup_find_by_target(struct MPT2SAS_ADAPTER *ioc, int id,
948 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
950 for (i = 0 ; i < ioc->scsiio_depth; i++) {
951 if (ioc->scsi_lookup[i].scmd &&
952 (ioc->scsi_lookup[i].scmd->device->id == id &&
953 ioc->scsi_lookup[i].scmd->device->channel == channel)) {
959 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
964 * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun
965 * @ioc: per adapter object
969 * Context: This function will acquire ioc->scsi_lookup_lock.
971 * This will search for a matching channel:id:lun in the scsi_lookup array,
972 * returning 1 if found.
975 _scsih_scsi_lookup_find_by_lun(struct MPT2SAS_ADAPTER *ioc, int id,
976 unsigned int lun, int channel)
982 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
984 for (i = 0 ; i < ioc->scsiio_depth; i++) {
985 if (ioc->scsi_lookup[i].scmd &&
986 (ioc->scsi_lookup[i].scmd->device->id == id &&
987 ioc->scsi_lookup[i].scmd->device->channel == channel &&
988 ioc->scsi_lookup[i].scmd->device->lun == lun)) {
994 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
999 * _scsih_get_chain_buffer_tracker - obtain chain tracker
1000 * @ioc: per adapter object
1001 * @smid: smid associated to an IO request
1003 * Returns chain tracker(from ioc->free_chain_list)
1005 static struct chain_tracker *
1006 _scsih_get_chain_buffer_tracker(struct MPT2SAS_ADAPTER *ioc, u16 smid)
1008 struct chain_tracker *chain_req;
1009 unsigned long flags;
1011 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1012 if (list_empty(&ioc->free_chain_list)) {
1013 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1014 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT "chain buffers not "
1015 "available\n", ioc->name));
1018 chain_req = list_entry(ioc->free_chain_list.next,
1019 struct chain_tracker, tracker_list);
1020 list_del_init(&chain_req->tracker_list);
1021 list_add_tail(&chain_req->tracker_list,
1022 &ioc->scsi_lookup[smid - 1].chain_list);
1023 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1028 * _scsih_build_scatter_gather - main sg creation routine
1029 * @ioc: per adapter object
1030 * @scmd: scsi command
1031 * @smid: system request message index
1034 * The main routine that builds scatter gather table from a given
1035 * scsi request sent via the .queuecommand main handler.
1037 * Returns 0 success, anything else error
1040 _scsih_build_scatter_gather(struct MPT2SAS_ADAPTER *ioc,
1041 struct scsi_cmnd *scmd, u16 smid)
1043 Mpi2SCSIIORequest_t *mpi_request;
1044 dma_addr_t chain_dma;
1045 struct scatterlist *sg_scmd;
1046 void *sg_local, *chain;
1051 u32 sges_in_segment;
1053 u32 sgl_flags_last_element;
1054 u32 sgl_flags_end_buffer;
1055 struct chain_tracker *chain_req;
1057 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
1059 /* init scatter gather flags */
1060 sgl_flags = MPI2_SGE_FLAGS_SIMPLE_ELEMENT;
1061 if (scmd->sc_data_direction == DMA_TO_DEVICE)
1062 sgl_flags |= MPI2_SGE_FLAGS_HOST_TO_IOC;
1063 sgl_flags_last_element = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT)
1064 << MPI2_SGE_FLAGS_SHIFT;
1065 sgl_flags_end_buffer = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT |
1066 MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_END_OF_LIST)
1067 << MPI2_SGE_FLAGS_SHIFT;
1068 sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT;
1070 sg_scmd = scsi_sglist(scmd);
1071 sges_left = scsi_dma_map(scmd);
1072 if (sges_left < 0) {
1073 sdev_printk(KERN_ERR, scmd->device, "pci_map_sg"
1074 " failed: request for %d bytes!\n", scsi_bufflen(scmd));
1078 sg_local = &mpi_request->SGL;
1079 sges_in_segment = ioc->max_sges_in_main_message;
1080 if (sges_left <= sges_in_segment)
1081 goto fill_in_last_segment;
1083 mpi_request->ChainOffset = (offsetof(Mpi2SCSIIORequest_t, SGL) +
1084 (sges_in_segment * ioc->sge_size))/4;
1086 /* fill in main message segment when there is a chain following */
1087 while (sges_in_segment) {
1088 if (sges_in_segment == 1)
1089 ioc->base_add_sg_single(sg_local,
1090 sgl_flags_last_element | sg_dma_len(sg_scmd),
1091 sg_dma_address(sg_scmd));
1093 ioc->base_add_sg_single(sg_local, sgl_flags |
1094 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
1095 sg_scmd = sg_next(sg_scmd);
1096 sg_local += ioc->sge_size;
1101 /* initializing the chain flags and pointers */
1102 chain_flags = MPI2_SGE_FLAGS_CHAIN_ELEMENT << MPI2_SGE_FLAGS_SHIFT;
1103 chain_req = _scsih_get_chain_buffer_tracker(ioc, smid);
1106 chain = chain_req->chain_buffer;
1107 chain_dma = chain_req->chain_buffer_dma;
1109 sges_in_segment = (sges_left <=
1110 ioc->max_sges_in_chain_message) ? sges_left :
1111 ioc->max_sges_in_chain_message;
1112 chain_offset = (sges_left == sges_in_segment) ?
1113 0 : (sges_in_segment * ioc->sge_size)/4;
1114 chain_length = sges_in_segment * ioc->sge_size;
1116 chain_offset = chain_offset <<
1117 MPI2_SGE_CHAIN_OFFSET_SHIFT;
1118 chain_length += ioc->sge_size;
1120 ioc->base_add_sg_single(sg_local, chain_flags | chain_offset |
1121 chain_length, chain_dma);
1124 goto fill_in_last_segment;
1126 /* fill in chain segments */
1127 while (sges_in_segment) {
1128 if (sges_in_segment == 1)
1129 ioc->base_add_sg_single(sg_local,
1130 sgl_flags_last_element |
1131 sg_dma_len(sg_scmd),
1132 sg_dma_address(sg_scmd));
1134 ioc->base_add_sg_single(sg_local, sgl_flags |
1135 sg_dma_len(sg_scmd),
1136 sg_dma_address(sg_scmd));
1137 sg_scmd = sg_next(sg_scmd);
1138 sg_local += ioc->sge_size;
1143 chain_req = _scsih_get_chain_buffer_tracker(ioc, smid);
1146 chain = chain_req->chain_buffer;
1147 chain_dma = chain_req->chain_buffer_dma;
1151 fill_in_last_segment:
1153 /* fill the last segment */
1156 ioc->base_add_sg_single(sg_local, sgl_flags_end_buffer |
1157 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
1159 ioc->base_add_sg_single(sg_local, sgl_flags |
1160 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
1161 sg_scmd = sg_next(sg_scmd);
1162 sg_local += ioc->sge_size;
1170 * _scsih_adjust_queue_depth - setting device queue depth
1171 * @sdev: scsi device struct
1172 * @qdepth: requested queue depth
1178 _scsih_adjust_queue_depth(struct scsi_device *sdev, int qdepth)
1180 struct Scsi_Host *shost = sdev->host;
1182 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1183 struct MPT2SAS_DEVICE *sas_device_priv_data;
1184 struct MPT2SAS_TARGET *sas_target_priv_data;
1185 struct _sas_device *sas_device;
1186 unsigned long flags;
1188 max_depth = shost->can_queue;
1190 /* limit max device queue for SATA to 32 */
1191 sas_device_priv_data = sdev->hostdata;
1192 if (!sas_device_priv_data)
1194 sas_target_priv_data = sas_device_priv_data->sas_target;
1195 if (!sas_target_priv_data)
1197 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))
1199 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1200 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1201 sas_device_priv_data->sas_target->sas_address);
1202 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1203 if (sas_device && sas_device->device_info &
1204 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1205 max_depth = MPT2SAS_SATA_QUEUE_DEPTH;
1209 if (!sdev->tagged_supported)
1211 if (qdepth > max_depth)
1213 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
1217 * _scsih_change_queue_depth - setting device queue depth
1218 * @sdev: scsi device struct
1219 * @qdepth: requested queue depth
1220 * @reason: SCSI_QDEPTH_DEFAULT/SCSI_QDEPTH_QFULL/SCSI_QDEPTH_RAMP_UP
1221 * (see include/scsi/scsi_host.h for definition)
1223 * Returns queue depth.
1226 _scsih_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
1228 if (reason == SCSI_QDEPTH_DEFAULT || reason == SCSI_QDEPTH_RAMP_UP)
1229 _scsih_adjust_queue_depth(sdev, qdepth);
1230 else if (reason == SCSI_QDEPTH_QFULL)
1231 scsi_track_queue_full(sdev, qdepth);
1235 if (sdev->inquiry_len > 7)
1236 sdev_printk(KERN_INFO, sdev, "qdepth(%d), tagged(%d), "
1237 "simple(%d), ordered(%d), scsi_level(%d), cmd_que(%d)\n",
1238 sdev->queue_depth, sdev->tagged_supported, sdev->simple_tags,
1239 sdev->ordered_tags, sdev->scsi_level,
1240 (sdev->inquiry[7] & 2) >> 1);
1242 return sdev->queue_depth;
1246 * _scsih_change_queue_type - changing device queue tag type
1247 * @sdev: scsi device struct
1248 * @tag_type: requested tag type
1250 * Returns queue tag type.
1253 _scsih_change_queue_type(struct scsi_device *sdev, int tag_type)
1255 if (sdev->tagged_supported) {
1256 scsi_set_tag_type(sdev, tag_type);
1258 scsi_activate_tcq(sdev, sdev->queue_depth);
1260 scsi_deactivate_tcq(sdev, sdev->queue_depth);
1268 * _scsih_target_alloc - target add routine
1269 * @starget: scsi target struct
1271 * Returns 0 if ok. Any other return is assumed to be an error and
1272 * the device is ignored.
1275 _scsih_target_alloc(struct scsi_target *starget)
1277 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1278 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1279 struct MPT2SAS_TARGET *sas_target_priv_data;
1280 struct _sas_device *sas_device;
1281 struct _raid_device *raid_device;
1282 unsigned long flags;
1283 struct sas_rphy *rphy;
1285 sas_target_priv_data = kzalloc(sizeof(struct scsi_target), GFP_KERNEL);
1286 if (!sas_target_priv_data)
1289 starget->hostdata = sas_target_priv_data;
1290 sas_target_priv_data->starget = starget;
1291 sas_target_priv_data->handle = MPT2SAS_INVALID_DEVICE_HANDLE;
1294 if (starget->channel == RAID_CHANNEL) {
1295 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1296 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1299 sas_target_priv_data->handle = raid_device->handle;
1300 sas_target_priv_data->sas_address = raid_device->wwid;
1301 sas_target_priv_data->flags |= MPT_TARGET_FLAGS_VOLUME;
1302 sas_target_priv_data->raid_device = raid_device;
1303 raid_device->starget = starget;
1305 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1309 /* sas/sata devices */
1310 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1311 rphy = dev_to_rphy(starget->dev.parent);
1312 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1313 rphy->identify.sas_address);
1316 sas_target_priv_data->handle = sas_device->handle;
1317 sas_target_priv_data->sas_address = sas_device->sas_address;
1318 sas_device->starget = starget;
1319 sas_device->id = starget->id;
1320 sas_device->channel = starget->channel;
1321 if (test_bit(sas_device->handle, ioc->pd_handles))
1322 sas_target_priv_data->flags |=
1323 MPT_TARGET_FLAGS_RAID_COMPONENT;
1325 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1331 * _scsih_target_destroy - target destroy routine
1332 * @starget: scsi target struct
1337 _scsih_target_destroy(struct scsi_target *starget)
1339 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1340 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1341 struct MPT2SAS_TARGET *sas_target_priv_data;
1342 struct _sas_device *sas_device;
1343 struct _raid_device *raid_device;
1344 unsigned long flags;
1345 struct sas_rphy *rphy;
1347 sas_target_priv_data = starget->hostdata;
1348 if (!sas_target_priv_data)
1351 if (starget->channel == RAID_CHANNEL) {
1352 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1353 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1356 raid_device->starget = NULL;
1357 raid_device->sdev = NULL;
1359 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1363 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1364 rphy = dev_to_rphy(starget->dev.parent);
1365 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1366 rphy->identify.sas_address);
1367 if (sas_device && (sas_device->starget == starget) &&
1368 (sas_device->id == starget->id) &&
1369 (sas_device->channel == starget->channel))
1370 sas_device->starget = NULL;
1372 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1375 kfree(sas_target_priv_data);
1376 starget->hostdata = NULL;
1380 * _scsih_slave_alloc - device add routine
1381 * @sdev: scsi device struct
1383 * Returns 0 if ok. Any other return is assumed to be an error and
1384 * the device is ignored.
1387 _scsih_slave_alloc(struct scsi_device *sdev)
1389 struct Scsi_Host *shost;
1390 struct MPT2SAS_ADAPTER *ioc;
1391 struct MPT2SAS_TARGET *sas_target_priv_data;
1392 struct MPT2SAS_DEVICE *sas_device_priv_data;
1393 struct scsi_target *starget;
1394 struct _raid_device *raid_device;
1395 unsigned long flags;
1397 sas_device_priv_data = kzalloc(sizeof(struct scsi_device), GFP_KERNEL);
1398 if (!sas_device_priv_data)
1401 sas_device_priv_data->lun = sdev->lun;
1402 sas_device_priv_data->flags = MPT_DEVICE_FLAGS_INIT;
1404 starget = scsi_target(sdev);
1405 sas_target_priv_data = starget->hostdata;
1406 sas_target_priv_data->num_luns++;
1407 sas_device_priv_data->sas_target = sas_target_priv_data;
1408 sdev->hostdata = sas_device_priv_data;
1409 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT))
1410 sdev->no_uld_attach = 1;
1412 shost = dev_to_shost(&starget->dev);
1413 ioc = shost_priv(shost);
1414 if (starget->channel == RAID_CHANNEL) {
1415 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1416 raid_device = _scsih_raid_device_find_by_id(ioc,
1417 starget->id, starget->channel);
1419 raid_device->sdev = sdev; /* raid is single lun */
1420 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1427 * _scsih_slave_destroy - device destroy routine
1428 * @sdev: scsi device struct
1433 _scsih_slave_destroy(struct scsi_device *sdev)
1435 struct MPT2SAS_TARGET *sas_target_priv_data;
1436 struct scsi_target *starget;
1437 struct Scsi_Host *shost;
1438 struct MPT2SAS_ADAPTER *ioc;
1439 struct _sas_device *sas_device;
1440 unsigned long flags;
1442 if (!sdev->hostdata)
1445 starget = scsi_target(sdev);
1446 sas_target_priv_data = starget->hostdata;
1447 sas_target_priv_data->num_luns--;
1449 shost = dev_to_shost(&starget->dev);
1450 ioc = shost_priv(shost);
1452 if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) {
1453 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1454 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1455 sas_target_priv_data->sas_address);
1457 sas_device->starget = NULL;
1458 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1461 kfree(sdev->hostdata);
1462 sdev->hostdata = NULL;
1466 * _scsih_display_sata_capabilities - sata capabilities
1467 * @ioc: per adapter object
1468 * @sas_device: the sas_device object
1469 * @sdev: scsi device struct
1472 _scsih_display_sata_capabilities(struct MPT2SAS_ADAPTER *ioc,
1473 struct _sas_device *sas_device, struct scsi_device *sdev)
1475 Mpi2ConfigReply_t mpi_reply;
1476 Mpi2SasDevicePage0_t sas_device_pg0;
1481 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
1482 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, sas_device->handle))) {
1483 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1484 ioc->name, __FILE__, __LINE__, __func__);
1488 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1489 MPI2_IOCSTATUS_MASK;
1490 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
1491 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1492 ioc->name, __FILE__, __LINE__, __func__);
1496 flags = le16_to_cpu(sas_device_pg0.Flags);
1497 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
1499 sdev_printk(KERN_INFO, sdev,
1500 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1501 "sw_preserve(%s)\n",
1502 (device_info & MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE) ? "y" : "n",
1503 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED) ? "y" : "n",
1504 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY) ? "y" :
1506 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED) ? "y" : "n",
1507 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED) ? "y" : "n",
1508 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE) ? "y" : "n");
1512 * _scsih_is_raid - return boolean indicating device is raid volume
1513 * @dev the device struct object
1516 _scsih_is_raid(struct device *dev)
1518 struct scsi_device *sdev = to_scsi_device(dev);
1519 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
1521 if (ioc->is_warpdrive)
1523 return (sdev->channel == RAID_CHANNEL) ? 1 : 0;
1527 * _scsih_get_resync - get raid volume resync percent complete
1528 * @dev the device struct object
1531 _scsih_get_resync(struct device *dev)
1533 struct scsi_device *sdev = to_scsi_device(dev);
1534 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
1535 static struct _raid_device *raid_device;
1536 unsigned long flags;
1537 Mpi2RaidVolPage0_t vol_pg0;
1538 Mpi2ConfigReply_t mpi_reply;
1539 u32 volume_status_flags;
1540 u8 percent_complete = 0;
1542 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1543 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1545 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1547 if (!raid_device || ioc->is_warpdrive)
1550 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
1551 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle,
1552 sizeof(Mpi2RaidVolPage0_t))) {
1553 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1554 ioc->name, __FILE__, __LINE__, __func__);
1558 volume_status_flags = le32_to_cpu(vol_pg0.VolumeStatusFlags);
1559 if (volume_status_flags & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS)
1560 percent_complete = raid_device->percent_complete;
1562 raid_set_resync(mpt2sas_raid_template, dev, percent_complete);
1566 * _scsih_get_state - get raid volume level
1567 * @dev the device struct object
1570 _scsih_get_state(struct device *dev)
1572 struct scsi_device *sdev = to_scsi_device(dev);
1573 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
1574 static struct _raid_device *raid_device;
1575 unsigned long flags;
1576 Mpi2RaidVolPage0_t vol_pg0;
1577 Mpi2ConfigReply_t mpi_reply;
1579 enum raid_state state = RAID_STATE_UNKNOWN;
1581 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1582 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1584 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1589 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
1590 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle,
1591 sizeof(Mpi2RaidVolPage0_t))) {
1592 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1593 ioc->name, __FILE__, __LINE__, __func__);
1597 volstate = le32_to_cpu(vol_pg0.VolumeStatusFlags);
1598 if (volstate & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS) {
1599 state = RAID_STATE_RESYNCING;
1603 switch (vol_pg0.VolumeState) {
1604 case MPI2_RAID_VOL_STATE_OPTIMAL:
1605 case MPI2_RAID_VOL_STATE_ONLINE:
1606 state = RAID_STATE_ACTIVE;
1608 case MPI2_RAID_VOL_STATE_DEGRADED:
1609 state = RAID_STATE_DEGRADED;
1611 case MPI2_RAID_VOL_STATE_FAILED:
1612 case MPI2_RAID_VOL_STATE_MISSING:
1613 state = RAID_STATE_OFFLINE;
1617 raid_set_state(mpt2sas_raid_template, dev, state);
1621 * _scsih_set_level - set raid level
1622 * @sdev: scsi device struct
1623 * @raid_device: raid_device object
1626 _scsih_set_level(struct scsi_device *sdev, struct _raid_device *raid_device)
1628 enum raid_level level = RAID_LEVEL_UNKNOWN;
1630 switch (raid_device->volume_type) {
1631 case MPI2_RAID_VOL_TYPE_RAID0:
1632 level = RAID_LEVEL_0;
1634 case MPI2_RAID_VOL_TYPE_RAID10:
1635 level = RAID_LEVEL_10;
1637 case MPI2_RAID_VOL_TYPE_RAID1E:
1638 level = RAID_LEVEL_1E;
1640 case MPI2_RAID_VOL_TYPE_RAID1:
1641 level = RAID_LEVEL_1;
1645 raid_set_level(mpt2sas_raid_template, &sdev->sdev_gendev, level);
1649 * _scsih_get_volume_capabilities - volume capabilities
1650 * @ioc: per adapter object
1651 * @sas_device: the raid_device object
1653 * Returns 0 for success, else 1
1656 _scsih_get_volume_capabilities(struct MPT2SAS_ADAPTER *ioc,
1657 struct _raid_device *raid_device)
1659 Mpi2RaidVolPage0_t *vol_pg0;
1660 Mpi2RaidPhysDiskPage0_t pd_pg0;
1661 Mpi2SasDevicePage0_t sas_device_pg0;
1662 Mpi2ConfigReply_t mpi_reply;
1666 if ((mpt2sas_config_get_number_pds(ioc, raid_device->handle,
1667 &num_pds)) || !num_pds) {
1668 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
1669 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1674 raid_device->num_pds = num_pds;
1675 sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
1676 sizeof(Mpi2RaidVol0PhysDisk_t));
1677 vol_pg0 = kzalloc(sz, GFP_KERNEL);
1679 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
1680 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1685 if ((mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
1686 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
1687 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
1688 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1694 raid_device->volume_type = vol_pg0->VolumeType;
1696 /* figure out what the underlying devices are by
1697 * obtaining the device_info bits for the 1st device
1699 if (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
1700 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
1701 vol_pg0->PhysDisk[0].PhysDiskNum))) {
1702 if (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
1703 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
1704 le16_to_cpu(pd_pg0.DevHandle)))) {
1705 raid_device->device_info =
1706 le32_to_cpu(sas_device_pg0.DeviceInfo);
1714 * _scsih_disable_ddio - Disable direct I/O for all the volumes
1715 * @ioc: per adapter object
1718 _scsih_disable_ddio(struct MPT2SAS_ADAPTER *ioc)
1720 Mpi2RaidVolPage1_t vol_pg1;
1721 Mpi2ConfigReply_t mpi_reply;
1722 struct _raid_device *raid_device;
1727 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
1728 &vol_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
1729 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1730 MPI2_IOCSTATUS_MASK;
1731 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
1733 handle = le16_to_cpu(vol_pg1.DevHandle);
1734 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
1736 raid_device->direct_io_enabled = 0;
1743 * _scsih_get_num_volumes - Get number of volumes in the ioc
1744 * @ioc: per adapter object
1747 _scsih_get_num_volumes(struct MPT2SAS_ADAPTER *ioc)
1749 Mpi2RaidVolPage1_t vol_pg1;
1750 Mpi2ConfigReply_t mpi_reply;
1756 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
1757 &vol_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
1758 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1759 MPI2_IOCSTATUS_MASK;
1760 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
1763 handle = le16_to_cpu(vol_pg1.DevHandle);
1770 * _scsih_init_warpdrive_properties - Set properties for warpdrive direct I/O.
1771 * @ioc: per adapter object
1772 * @raid_device: the raid_device object
1775 _scsih_init_warpdrive_properties(struct MPT2SAS_ADAPTER *ioc,
1776 struct _raid_device *raid_device)
1778 Mpi2RaidVolPage0_t *vol_pg0;
1779 Mpi2RaidPhysDiskPage0_t pd_pg0;
1780 Mpi2ConfigReply_t mpi_reply;
1783 u64 mb = 1024 * 1024;
1784 u64 tb_2 = 2 * mb * mb;
1789 if (!ioc->is_warpdrive)
1792 if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS) {
1793 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1794 "globally as drives are exposed\n", ioc->name);
1797 if (_scsih_get_num_volumes(ioc) > 1) {
1798 _scsih_disable_ddio(ioc);
1799 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1800 "globally as number of drives > 1\n", ioc->name);
1803 if ((mpt2sas_config_get_number_pds(ioc, raid_device->handle,
1804 &num_pds)) || !num_pds) {
1805 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1806 "Failure in computing number of drives\n", ioc->name);
1810 sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
1811 sizeof(Mpi2RaidVol0PhysDisk_t));
1812 vol_pg0 = kzalloc(sz, GFP_KERNEL);
1814 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1815 "Memory allocation failure for RVPG0\n", ioc->name);
1819 if ((mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
1820 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
1821 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1822 "Failure in retrieving RVPG0\n", ioc->name);
1828 * WARPDRIVE:If number of physical disks in a volume exceeds the max pds
1829 * assumed for WARPDRIVE, disable direct I/O
1831 if (num_pds > MPT_MAX_WARPDRIVE_PDS) {
1832 printk(MPT2SAS_WARN_FMT "WarpDrive : Direct IO is disabled "
1833 "for the drive with handle(0x%04x): num_mem=%d, "
1834 "max_mem_allowed=%d\n", ioc->name, raid_device->handle,
1835 num_pds, MPT_MAX_WARPDRIVE_PDS);
1839 for (count = 0; count < num_pds; count++) {
1840 if (mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
1841 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
1842 vol_pg0->PhysDisk[count].PhysDiskNum) ||
1843 pd_pg0.DevHandle == MPT2SAS_INVALID_DEVICE_HANDLE) {
1844 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is "
1845 "disabled for the drive with handle(0x%04x) member"
1846 "handle retrieval failed for member number=%d\n",
1847 ioc->name, raid_device->handle,
1848 vol_pg0->PhysDisk[count].PhysDiskNum);
1851 raid_device->pd_handle[count] = le16_to_cpu(pd_pg0.DevHandle);
1855 * Assumption for WD: Direct I/O is not supported if the volume is
1856 * not RAID0, if the stripe size is not 64KB, if the block size is
1857 * not 512 and if the volume size is >2TB
1859 if (raid_device->volume_type != MPI2_RAID_VOL_TYPE_RAID0 ||
1860 le16_to_cpu(vol_pg0->BlockSize) != 512) {
1861 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1862 "for the drive with handle(0x%04x): type=%d, "
1863 "s_sz=%uK, blk_size=%u\n", ioc->name,
1864 raid_device->handle, raid_device->volume_type,
1865 le32_to_cpu(vol_pg0->StripeSize)/2,
1866 le16_to_cpu(vol_pg0->BlockSize));
1870 capacity = (u64) le16_to_cpu(vol_pg0->BlockSize) *
1871 (le64_to_cpu(vol_pg0->MaxLBA) + 1);
1873 if (capacity > tb_2) {
1874 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1875 "for the drive with handle(0x%04x) since drive sz > 2TB\n",
1876 ioc->name, raid_device->handle);
1880 stripe_sz = le32_to_cpu(vol_pg0->StripeSize);
1882 for (i = 0; i < 32; i++) {
1889 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1890 "for the drive with handle(0x%04x) invalid stripe sz %uK\n",
1891 ioc->name, raid_device->handle,
1892 le32_to_cpu(vol_pg0->StripeSize)/2);
1895 raid_device->stripe_exponent = stripe_exp;
1896 raid_device->direct_io_enabled = 1;
1898 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is Enabled for the drive"
1899 " with handle(0x%04x)\n", ioc->name, raid_device->handle);
1901 * WARPDRIVE: Though the following fields are not used for direct IO,
1902 * stored for future purpose:
1904 raid_device->max_lba = le64_to_cpu(vol_pg0->MaxLBA);
1905 raid_device->stripe_sz = le32_to_cpu(vol_pg0->StripeSize);
1906 raid_device->block_sz = le16_to_cpu(vol_pg0->BlockSize);
1913 raid_device->direct_io_enabled = 0;
1914 for (count = 0; count < num_pds; count++)
1915 raid_device->pd_handle[count] = 0;
1921 * _scsih_enable_tlr - setting TLR flags
1922 * @ioc: per adapter object
1923 * @sdev: scsi device struct
1925 * Enabling Transaction Layer Retries for tape devices when
1926 * vpd page 0x90 is present
1930 _scsih_enable_tlr(struct MPT2SAS_ADAPTER *ioc, struct scsi_device *sdev)
1933 if (sdev->type != TYPE_TAPE)
1936 if (!(ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR))
1939 sas_enable_tlr(sdev);
1940 sdev_printk(KERN_INFO, sdev, "TLR %s\n",
1941 sas_is_tlr_enabled(sdev) ? "Enabled" : "Disabled");
1947 * _scsih_slave_configure - device configure routine.
1948 * @sdev: scsi device struct
1950 * Returns 0 if ok. Any other return is assumed to be an error and
1951 * the device is ignored.
1954 _scsih_slave_configure(struct scsi_device *sdev)
1956 struct Scsi_Host *shost = sdev->host;
1957 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1958 struct MPT2SAS_DEVICE *sas_device_priv_data;
1959 struct MPT2SAS_TARGET *sas_target_priv_data;
1960 struct _sas_device *sas_device;
1961 struct _raid_device *raid_device;
1962 unsigned long flags;
1969 sas_device_priv_data = sdev->hostdata;
1970 sas_device_priv_data->configured_lun = 1;
1971 sas_device_priv_data->flags &= ~MPT_DEVICE_FLAGS_INIT;
1972 sas_target_priv_data = sas_device_priv_data->sas_target;
1974 /* raid volume handling */
1975 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME) {
1977 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1978 raid_device = _scsih_raid_device_find_by_handle(ioc,
1979 sas_target_priv_data->handle);
1980 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1982 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
1983 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
1984 __LINE__, __func__));
1988 _scsih_get_volume_capabilities(ioc, raid_device);
1990 if (_scsih_get_volume_capabilities(ioc, raid_device)) {
1991 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
1992 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
1993 __LINE__, __func__));
1997 * WARPDRIVE: Initialize the required data for Direct IO
1999 _scsih_init_warpdrive_properties(ioc, raid_device);
2001 /* RAID Queue Depth Support
2002 * IS volume = underlying qdepth of drive type, either
2003 * MPT2SAS_SAS_QUEUE_DEPTH or MPT2SAS_SATA_QUEUE_DEPTH
2004 * IM/IME/R10 = 128 (MPT2SAS_RAID_QUEUE_DEPTH)
2006 if (raid_device->device_info &
2007 MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
2008 qdepth = MPT2SAS_SAS_QUEUE_DEPTH;
2011 qdepth = MPT2SAS_SATA_QUEUE_DEPTH;
2012 if (raid_device->device_info &
2013 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
2019 switch (raid_device->volume_type) {
2020 case MPI2_RAID_VOL_TYPE_RAID0:
2023 case MPI2_RAID_VOL_TYPE_RAID1E:
2024 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
2025 if (ioc->manu_pg10.OEMIdentifier &&
2026 (le32_to_cpu(ioc->manu_pg10.GenericFlags0) &
2027 MFG10_GF0_R10_DISPLAY) &&
2028 !(raid_device->num_pds % 2))
2033 case MPI2_RAID_VOL_TYPE_RAID1:
2034 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
2037 case MPI2_RAID_VOL_TYPE_RAID10:
2038 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
2041 case MPI2_RAID_VOL_TYPE_UNKNOWN:
2043 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
2048 if (!ioc->hide_ir_msg)
2049 sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), "
2050 "wwid(0x%016llx), pd_count(%d), type(%s)\n",
2051 r_level, raid_device->handle,
2052 (unsigned long long)raid_device->wwid,
2053 raid_device->num_pds, ds);
2054 _scsih_change_queue_depth(sdev, qdepth, SCSI_QDEPTH_DEFAULT);
2055 /* raid transport support */
2056 if (!ioc->is_warpdrive)
2057 _scsih_set_level(sdev, raid_device);
2061 /* non-raid handling */
2062 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2063 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
2064 sas_device_priv_data->sas_target->sas_address);
2065 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2067 if (sas_target_priv_data->flags &
2068 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2069 if (mpt2sas_config_get_volume_handle(ioc,
2070 sas_device->handle, &sas_device->volume_handle)) {
2071 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
2072 "failure at %s:%d/%s()!\n", ioc->name,
2073 __FILE__, __LINE__, __func__));
2076 if (sas_device->volume_handle &&
2077 mpt2sas_config_get_volume_wwid(ioc,
2078 sas_device->volume_handle,
2079 &sas_device->volume_wwid)) {
2080 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
2081 "failure at %s:%d/%s()!\n", ioc->name,
2082 __FILE__, __LINE__, __func__));
2086 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
2087 qdepth = MPT2SAS_SAS_QUEUE_DEPTH;
2091 qdepth = MPT2SAS_SATA_QUEUE_DEPTH;
2092 if (sas_device->device_info &
2093 MPI2_SAS_DEVICE_INFO_STP_TARGET)
2095 else if (sas_device->device_info &
2096 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
2100 sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), "
2101 "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n",
2102 ds, sas_device->handle,
2103 (unsigned long long)sas_device->sas_address,
2105 (unsigned long long)sas_device->device_name);
2106 sdev_printk(KERN_INFO, sdev, "%s: "
2107 "enclosure_logical_id(0x%016llx), slot(%d)\n", ds,
2108 (unsigned long long) sas_device->enclosure_logical_id,
2112 _scsih_display_sata_capabilities(ioc, sas_device, sdev);
2114 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
2115 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
2120 _scsih_change_queue_depth(sdev, qdepth, SCSI_QDEPTH_DEFAULT);
2123 sas_read_port_mode_page(sdev);
2124 _scsih_enable_tlr(ioc, sdev);
2130 * _scsih_bios_param - fetch head, sector, cylinder info for a disk
2131 * @sdev: scsi device struct
2132 * @bdev: pointer to block device context
2133 * @capacity: device size (in 512 byte sectors)
2134 * @params: three element array to place output:
2135 * params[0] number of heads (max 255)
2136 * params[1] number of sectors (max 63)
2137 * params[2] number of cylinders
2142 _scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev,
2143 sector_t capacity, int params[])
2153 dummy = heads * sectors;
2154 cylinders = capacity;
2155 sector_div(cylinders, dummy);
2158 * Handle extended translation size for logical drives
2161 if ((ulong)capacity >= 0x200000) {
2164 dummy = heads * sectors;
2165 cylinders = capacity;
2166 sector_div(cylinders, dummy);
2171 params[1] = sectors;
2172 params[2] = cylinders;
2178 * _scsih_response_code - translation of device response code
2179 * @ioc: per adapter object
2180 * @response_code: response code returned by the device
2185 _scsih_response_code(struct MPT2SAS_ADAPTER *ioc, u8 response_code)
2189 switch (response_code) {
2190 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE:
2191 desc = "task management request completed";
2193 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME:
2194 desc = "invalid frame";
2196 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED:
2197 desc = "task management request not supported";
2199 case MPI2_SCSITASKMGMT_RSP_TM_FAILED:
2200 desc = "task management request failed";
2202 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED:
2203 desc = "task management request succeeded";
2205 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN:
2206 desc = "invalid lun";
2209 desc = "overlapped tag attempted";
2211 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC:
2212 desc = "task queued, however not sent to target";
2218 printk(MPT2SAS_WARN_FMT "response_code(0x%01x): %s\n",
2219 ioc->name, response_code, desc);
2223 * _scsih_tm_done - tm completion routine
2224 * @ioc: per adapter object
2225 * @smid: system request message index
2226 * @msix_index: MSIX table index supplied by the OS
2227 * @reply: reply message frame(lower 32bit addr)
2230 * The callback handler when using scsih_issue_tm.
2232 * Return 1 meaning mf should be freed from _base_interrupt
2233 * 0 means the mf is freed from this function.
2236 _scsih_tm_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
2238 MPI2DefaultReply_t *mpi_reply;
2240 if (ioc->tm_cmds.status == MPT2_CMD_NOT_USED)
2242 if (ioc->tm_cmds.smid != smid)
2244 mpt2sas_base_flush_reply_queues(ioc);
2245 ioc->tm_cmds.status |= MPT2_CMD_COMPLETE;
2246 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
2248 memcpy(ioc->tm_cmds.reply, mpi_reply, mpi_reply->MsgLength*4);
2249 ioc->tm_cmds.status |= MPT2_CMD_REPLY_VALID;
2251 ioc->tm_cmds.status &= ~MPT2_CMD_PENDING;
2252 complete(&ioc->tm_cmds.done);
2257 * mpt2sas_scsih_set_tm_flag - set per target tm_busy
2258 * @ioc: per adapter object
2259 * @handle: device handle
2261 * During taskmangement request, we need to freeze the device queue.
2264 mpt2sas_scsih_set_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2266 struct MPT2SAS_DEVICE *sas_device_priv_data;
2267 struct scsi_device *sdev;
2270 shost_for_each_device(sdev, ioc->shost) {
2273 sas_device_priv_data = sdev->hostdata;
2274 if (!sas_device_priv_data)
2276 if (sas_device_priv_data->sas_target->handle == handle) {
2277 sas_device_priv_data->sas_target->tm_busy = 1;
2279 ioc->ignore_loginfos = 1;
2285 * mpt2sas_scsih_clear_tm_flag - clear per target tm_busy
2286 * @ioc: per adapter object
2287 * @handle: device handle
2289 * During taskmangement request, we need to freeze the device queue.
2292 mpt2sas_scsih_clear_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2294 struct MPT2SAS_DEVICE *sas_device_priv_data;
2295 struct scsi_device *sdev;
2298 shost_for_each_device(sdev, ioc->shost) {
2301 sas_device_priv_data = sdev->hostdata;
2302 if (!sas_device_priv_data)
2304 if (sas_device_priv_data->sas_target->handle == handle) {
2305 sas_device_priv_data->sas_target->tm_busy = 0;
2307 ioc->ignore_loginfos = 0;
2314 * mpt2sas_scsih_issue_tm - main routine for sending tm requests
2315 * @ioc: per adapter struct
2316 * @device_handle: device handle
2317 * @channel: the channel assigned by the OS
2318 * @id: the id assigned by the OS
2320 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
2321 * @smid_task: smid assigned to the task
2322 * @timeout: timeout in seconds
2323 * @serial_number: the serial_number from scmd
2324 * @m_type: TM_MUTEX_ON or TM_MUTEX_OFF
2327 * A generic API for sending task management requests to firmware.
2329 * The callback index is set inside `ioc->tm_cb_idx`.
2331 * Return SUCCESS or FAILED.
2334 mpt2sas_scsih_issue_tm(struct MPT2SAS_ADAPTER *ioc, u16 handle, uint channel,
2335 uint id, uint lun, u8 type, u16 smid_task, ulong timeout,
2336 unsigned long serial_number, enum mutex_type m_type)
2338 Mpi2SCSITaskManagementRequest_t *mpi_request;
2339 Mpi2SCSITaskManagementReply_t *mpi_reply;
2342 unsigned long timeleft;
2343 struct scsiio_tracker *scsi_lookup = NULL;
2346 if (m_type == TM_MUTEX_ON)
2347 mutex_lock(&ioc->tm_cmds.mutex);
2348 if (ioc->tm_cmds.status != MPT2_CMD_NOT_USED) {
2349 printk(MPT2SAS_INFO_FMT "%s: tm_cmd busy!!!\n",
2350 __func__, ioc->name);
2355 if (ioc->shost_recovery || ioc->remove_host ||
2356 ioc->pci_error_recovery) {
2357 printk(MPT2SAS_INFO_FMT "%s: host reset in progress!\n",
2358 __func__, ioc->name);
2363 ioc_state = mpt2sas_base_get_iocstate(ioc, 0);
2364 if (ioc_state & MPI2_DOORBELL_USED) {
2365 dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "unexpected doorbell "
2366 "active!\n", ioc->name));
2367 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2369 rc = (!rc) ? SUCCESS : FAILED;
2373 if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) {
2374 mpt2sas_base_fault_info(ioc, ioc_state &
2375 MPI2_DOORBELL_DATA_MASK);
2376 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2378 rc = (!rc) ? SUCCESS : FAILED;
2382 smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_cb_idx);
2384 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
2385 ioc->name, __func__);
2390 if (type == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK)
2391 scsi_lookup = &ioc->scsi_lookup[smid_task - 1];
2393 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "sending tm: handle(0x%04x),"
2394 " task_type(0x%02x), smid(%d)\n", ioc->name, handle, type,
2396 ioc->tm_cmds.status = MPT2_CMD_PENDING;
2397 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
2398 ioc->tm_cmds.smid = smid;
2399 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
2400 memset(ioc->tm_cmds.reply, 0, sizeof(Mpi2SCSITaskManagementReply_t));
2401 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
2402 mpi_request->DevHandle = cpu_to_le16(handle);
2403 mpi_request->TaskType = type;
2404 mpi_request->TaskMID = cpu_to_le16(smid_task);
2405 int_to_scsilun(lun, (struct scsi_lun *)mpi_request->LUN);
2406 mpt2sas_scsih_set_tm_flag(ioc, handle);
2407 init_completion(&ioc->tm_cmds.done);
2408 mpt2sas_base_put_smid_hi_priority(ioc, smid);
2409 timeleft = wait_for_completion_timeout(&ioc->tm_cmds.done, timeout*HZ);
2410 if (!(ioc->tm_cmds.status & MPT2_CMD_COMPLETE)) {
2411 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
2412 ioc->name, __func__);
2413 _debug_dump_mf(mpi_request,
2414 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
2415 if (!(ioc->tm_cmds.status & MPT2_CMD_RESET)) {
2416 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2418 rc = (!rc) ? SUCCESS : FAILED;
2419 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
2420 mpt2sas_scsih_clear_tm_flag(ioc, handle);
2425 if (ioc->tm_cmds.status & MPT2_CMD_REPLY_VALID) {
2426 mpi_reply = ioc->tm_cmds.reply;
2427 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "complete tm: "
2428 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
2429 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
2430 le32_to_cpu(mpi_reply->IOCLogInfo),
2431 le32_to_cpu(mpi_reply->TerminationCount)));
2432 if (ioc->logging_level & MPT_DEBUG_TM) {
2433 _scsih_response_code(ioc, mpi_reply->ResponseCode);
2434 if (mpi_reply->IOCStatus)
2435 _debug_dump_mf(mpi_request,
2436 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
2441 case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK:
2443 if (scsi_lookup->scmd == NULL)
2448 case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET:
2449 if (_scsih_scsi_lookup_find_by_target(ioc, id, channel))
2455 case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET:
2456 case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET:
2457 if (_scsih_scsi_lookup_find_by_lun(ioc, id, lun, channel))
2462 case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK:
2470 mpt2sas_scsih_clear_tm_flag(ioc, handle);
2471 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
2472 if (m_type == TM_MUTEX_ON)
2473 mutex_unlock(&ioc->tm_cmds.mutex);
2478 if (m_type == TM_MUTEX_ON)
2479 mutex_unlock(&ioc->tm_cmds.mutex);
2484 * _scsih_tm_display_info - displays info about the device
2485 * @ioc: per adapter struct
2486 * @scmd: pointer to scsi command object
2488 * Called by task management callback handlers.
2491 _scsih_tm_display_info(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd)
2493 struct scsi_target *starget = scmd->device->sdev_target;
2494 struct MPT2SAS_TARGET *priv_target = starget->hostdata;
2495 struct _sas_device *sas_device = NULL;
2496 unsigned long flags;
2497 char *device_str = NULL;
2501 if (ioc->hide_ir_msg)
2502 device_str = "WarpDrive";
2504 device_str = "volume";
2506 scsi_print_command(scmd);
2507 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
2508 starget_printk(KERN_INFO, starget, "%s handle(0x%04x), "
2509 "%s wwid(0x%016llx)\n", device_str, priv_target->handle,
2510 device_str, (unsigned long long)priv_target->sas_address);
2512 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2513 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
2514 priv_target->sas_address);
2516 if (priv_target->flags &
2517 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2518 starget_printk(KERN_INFO, starget,
2519 "volume handle(0x%04x), "
2520 "volume wwid(0x%016llx)\n",
2521 sas_device->volume_handle,
2522 (unsigned long long)sas_device->volume_wwid);
2524 starget_printk(KERN_INFO, starget,
2525 "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n",
2527 (unsigned long long)sas_device->sas_address,
2529 starget_printk(KERN_INFO, starget,
2530 "enclosure_logical_id(0x%016llx), slot(%d)\n",
2531 (unsigned long long)sas_device->enclosure_logical_id,
2534 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2539 * _scsih_abort - eh threads main abort routine
2540 * @scmd: pointer to scsi command object
2542 * Returns SUCCESS if command aborted else FAILED
2545 _scsih_abort(struct scsi_cmnd *scmd)
2547 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2548 struct MPT2SAS_DEVICE *sas_device_priv_data;
2553 sdev_printk(KERN_INFO, scmd->device, "attempting task abort! "
2554 "scmd(%p)\n", scmd);
2555 _scsih_tm_display_info(ioc, scmd);
2557 sas_device_priv_data = scmd->device->hostdata;
2558 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2559 sdev_printk(KERN_INFO, scmd->device, "device been deleted! "
2560 "scmd(%p)\n", scmd);
2561 scmd->result = DID_NO_CONNECT << 16;
2562 scmd->scsi_done(scmd);
2567 /* search for the command */
2568 smid = _scsih_scsi_lookup_find_by_scmd(ioc, scmd);
2570 scmd->result = DID_RESET << 16;
2575 /* for hidden raid components and volumes this is not supported */
2576 if (sas_device_priv_data->sas_target->flags &
2577 MPT_TARGET_FLAGS_RAID_COMPONENT ||
2578 sas_device_priv_data->sas_target->flags & MPT_TARGET_FLAGS_VOLUME) {
2579 scmd->result = DID_RESET << 16;
2584 mpt2sas_halt_firmware(ioc);
2586 handle = sas_device_priv_data->sas_target->handle;
2587 r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2588 scmd->device->id, scmd->device->lun,
2589 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30,
2590 scmd->serial_number, TM_MUTEX_ON);
2593 sdev_printk(KERN_INFO, scmd->device, "task abort: %s scmd(%p)\n",
2594 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2599 * _scsih_dev_reset - eh threads main device reset routine
2600 * @scmd: pointer to scsi command object
2602 * Returns SUCCESS if command aborted else FAILED
2605 _scsih_dev_reset(struct scsi_cmnd *scmd)
2607 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2608 struct MPT2SAS_DEVICE *sas_device_priv_data;
2609 struct _sas_device *sas_device;
2610 unsigned long flags;
2614 struct scsi_target *starget = scmd->device->sdev_target;
2616 starget_printk(KERN_INFO, starget, "attempting device reset! "
2617 "scmd(%p)\n", scmd);
2618 _scsih_tm_display_info(ioc, scmd);
2620 sas_device_priv_data = scmd->device->hostdata;
2621 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2622 starget_printk(KERN_INFO, starget, "device been deleted! "
2623 "scmd(%p)\n", scmd);
2624 scmd->result = DID_NO_CONNECT << 16;
2625 scmd->scsi_done(scmd);
2630 /* for hidden raid components obtain the volume_handle */
2632 if (sas_device_priv_data->sas_target->flags &
2633 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2634 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2635 sas_device = _scsih_sas_device_find_by_handle(ioc,
2636 sas_device_priv_data->sas_target->handle);
2638 handle = sas_device->volume_handle;
2639 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2641 handle = sas_device_priv_data->sas_target->handle;
2644 scmd->result = DID_RESET << 16;
2649 r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2650 scmd->device->id, scmd->device->lun,
2651 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, 0, 30, 0,
2655 sdev_printk(KERN_INFO, scmd->device, "device reset: %s scmd(%p)\n",
2656 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2661 * _scsih_target_reset - eh threads main target reset routine
2662 * @scmd: pointer to scsi command object
2664 * Returns SUCCESS if command aborted else FAILED
2667 _scsih_target_reset(struct scsi_cmnd *scmd)
2669 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2670 struct MPT2SAS_DEVICE *sas_device_priv_data;
2671 struct _sas_device *sas_device;
2672 unsigned long flags;
2675 struct scsi_target *starget = scmd->device->sdev_target;
2677 starget_printk(KERN_INFO, starget, "attempting target reset! "
2678 "scmd(%p)\n", scmd);
2679 _scsih_tm_display_info(ioc, scmd);
2681 sas_device_priv_data = scmd->device->hostdata;
2682 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2683 starget_printk(KERN_INFO, starget, "target been deleted! "
2684 "scmd(%p)\n", scmd);
2685 scmd->result = DID_NO_CONNECT << 16;
2686 scmd->scsi_done(scmd);
2691 /* for hidden raid components obtain the volume_handle */
2693 if (sas_device_priv_data->sas_target->flags &
2694 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2695 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2696 sas_device = _scsih_sas_device_find_by_handle(ioc,
2697 sas_device_priv_data->sas_target->handle);
2699 handle = sas_device->volume_handle;
2700 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2702 handle = sas_device_priv_data->sas_target->handle;
2705 scmd->result = DID_RESET << 16;
2710 r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2711 scmd->device->id, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0,
2712 30, 0, TM_MUTEX_ON);
2715 starget_printk(KERN_INFO, starget, "target reset: %s scmd(%p)\n",
2716 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2721 * _scsih_host_reset - eh threads main host reset routine
2722 * @scmd: pointer to scsi command object
2724 * Returns SUCCESS if command aborted else FAILED
2727 _scsih_host_reset(struct scsi_cmnd *scmd)
2729 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2732 printk(MPT2SAS_INFO_FMT "attempting host reset! scmd(%p)\n",
2734 scsi_print_command(scmd);
2736 retval = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2738 r = (retval < 0) ? FAILED : SUCCESS;
2739 printk(MPT2SAS_INFO_FMT "host reset: %s scmd(%p)\n",
2740 ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2746 * _scsih_fw_event_add - insert and queue up fw_event
2747 * @ioc: per adapter object
2748 * @fw_event: object describing the event
2749 * Context: This function will acquire ioc->fw_event_lock.
2751 * This adds the firmware event object into link list, then queues it up to
2752 * be processed from user context.
2757 _scsih_fw_event_add(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
2759 unsigned long flags;
2761 if (ioc->firmware_event_thread == NULL)
2764 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2765 list_add_tail(&fw_event->list, &ioc->fw_event_list);
2766 INIT_DELAYED_WORK(&fw_event->delayed_work, _firmware_event_work);
2767 queue_delayed_work(ioc->firmware_event_thread,
2768 &fw_event->delayed_work, 0);
2769 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2773 * _scsih_fw_event_free - delete fw_event
2774 * @ioc: per adapter object
2775 * @fw_event: object describing the event
2776 * Context: This function will acquire ioc->fw_event_lock.
2778 * This removes firmware event object from link list, frees associated memory.
2783 _scsih_fw_event_free(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work
2786 unsigned long flags;
2788 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2789 list_del(&fw_event->list);
2790 kfree(fw_event->event_data);
2792 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2797 * _scsih_error_recovery_delete_devices - remove devices not responding
2798 * @ioc: per adapter object
2803 _scsih_error_recovery_delete_devices(struct MPT2SAS_ADAPTER *ioc)
2805 struct fw_event_work *fw_event;
2807 if (ioc->is_driver_loading)
2810 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
2814 fw_event->event = MPT2SAS_REMOVE_UNRESPONDING_DEVICES;
2815 fw_event->ioc = ioc;
2816 _scsih_fw_event_add(ioc, fw_event);
2820 * mpt2sas_port_enable_complete - port enable completed (fake event)
2821 * @ioc: per adapter object
2826 mpt2sas_port_enable_complete(struct MPT2SAS_ADAPTER *ioc)
2828 struct fw_event_work *fw_event;
2830 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
2833 fw_event->event = MPT2SAS_PORT_ENABLE_COMPLETE;
2834 fw_event->ioc = ioc;
2835 _scsih_fw_event_add(ioc, fw_event);
2839 * _scsih_fw_event_cleanup_queue - cleanup event queue
2840 * @ioc: per adapter object
2842 * Walk the firmware event queue, either killing timers, or waiting
2843 * for outstanding events to complete
2848 _scsih_fw_event_cleanup_queue(struct MPT2SAS_ADAPTER *ioc)
2850 struct fw_event_work *fw_event, *next;
2852 if (list_empty(&ioc->fw_event_list) ||
2853 !ioc->firmware_event_thread || in_interrupt())
2856 list_for_each_entry_safe(fw_event, next, &ioc->fw_event_list, list) {
2857 if (cancel_delayed_work(&fw_event->delayed_work)) {
2858 _scsih_fw_event_free(ioc, fw_event);
2861 fw_event->cancel_pending_work = 1;
2866 * _scsih_ublock_io_all_device - unblock every device
2867 * @ioc: per adapter object
2869 * change the device state from block to running
2872 _scsih_ublock_io_all_device(struct MPT2SAS_ADAPTER *ioc)
2874 struct MPT2SAS_DEVICE *sas_device_priv_data;
2875 struct scsi_device *sdev;
2877 shost_for_each_device(sdev, ioc->shost) {
2878 sas_device_priv_data = sdev->hostdata;
2879 if (!sas_device_priv_data)
2881 if (!sas_device_priv_data->block)
2883 sas_device_priv_data->block = 0;
2884 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, "device_running, "
2886 sas_device_priv_data->sas_target->handle));
2887 scsi_internal_device_unblock(sdev);
2891 * _scsih_ublock_io_device - set the device state to SDEV_RUNNING
2892 * @ioc: per adapter object
2893 * @handle: device handle
2895 * During device pull we need to appropiately set the sdev state.
2898 _scsih_ublock_io_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2900 struct MPT2SAS_DEVICE *sas_device_priv_data;
2901 struct scsi_device *sdev;
2903 shost_for_each_device(sdev, ioc->shost) {
2904 sas_device_priv_data = sdev->hostdata;
2905 if (!sas_device_priv_data)
2907 if (!sas_device_priv_data->block)
2909 if (sas_device_priv_data->sas_target->handle == handle) {
2910 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
2911 MPT2SAS_INFO_FMT "SDEV_RUNNING: "
2912 "handle(0x%04x)\n", ioc->name, handle));
2913 sas_device_priv_data->block = 0;
2914 scsi_internal_device_unblock(sdev);
2920 * _scsih_block_io_all_device - set the device state to SDEV_BLOCK
2921 * @ioc: per adapter object
2922 * @handle: device handle
2924 * During device pull we need to appropiately set the sdev state.
2927 _scsih_block_io_all_device(struct MPT2SAS_ADAPTER *ioc)
2929 struct MPT2SAS_DEVICE *sas_device_priv_data;
2930 struct scsi_device *sdev;
2932 shost_for_each_device(sdev, ioc->shost) {
2933 sas_device_priv_data = sdev->hostdata;
2934 if (!sas_device_priv_data)
2936 if (sas_device_priv_data->block)
2938 sas_device_priv_data->block = 1;
2939 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, "device_blocked, "
2941 sas_device_priv_data->sas_target->handle));
2942 scsi_internal_device_block(sdev);
2948 * _scsih_block_io_device - set the device state to SDEV_BLOCK
2949 * @ioc: per adapter object
2950 * @handle: device handle
2952 * During device pull we need to appropiately set the sdev state.
2955 _scsih_block_io_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2957 struct MPT2SAS_DEVICE *sas_device_priv_data;
2958 struct scsi_device *sdev;
2960 shost_for_each_device(sdev, ioc->shost) {
2961 sas_device_priv_data = sdev->hostdata;
2962 if (!sas_device_priv_data)
2964 if (sas_device_priv_data->block)
2966 if (sas_device_priv_data->sas_target->handle == handle) {
2967 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
2968 MPT2SAS_INFO_FMT "SDEV_BLOCK: "
2969 "handle(0x%04x)\n", ioc->name, handle));
2970 sas_device_priv_data->block = 1;
2971 scsi_internal_device_block(sdev);
2977 * _scsih_block_io_to_children_attached_to_ex
2978 * @ioc: per adapter object
2979 * @sas_expander: the sas_device object
2981 * This routine set sdev state to SDEV_BLOCK for all devices
2982 * attached to this expander. This function called when expander is
2986 _scsih_block_io_to_children_attached_to_ex(struct MPT2SAS_ADAPTER *ioc,
2987 struct _sas_node *sas_expander)
2989 struct _sas_port *mpt2sas_port;
2990 struct _sas_device *sas_device;
2991 struct _sas_node *expander_sibling;
2992 unsigned long flags;
2997 list_for_each_entry(mpt2sas_port,
2998 &sas_expander->sas_port_list, port_list) {
2999 if (mpt2sas_port->remote_identify.device_type ==
3001 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3003 mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
3004 mpt2sas_port->remote_identify.sas_address);
3005 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3008 _scsih_block_io_device(ioc, sas_device->handle);
3012 list_for_each_entry(mpt2sas_port,
3013 &sas_expander->sas_port_list, port_list) {
3015 if (mpt2sas_port->remote_identify.device_type ==
3016 SAS_EDGE_EXPANDER_DEVICE ||
3017 mpt2sas_port->remote_identify.device_type ==
3018 SAS_FANOUT_EXPANDER_DEVICE) {
3020 spin_lock_irqsave(&ioc->sas_node_lock, flags);
3022 mpt2sas_scsih_expander_find_by_sas_address(
3023 ioc, mpt2sas_port->remote_identify.sas_address);
3024 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
3025 _scsih_block_io_to_children_attached_to_ex(ioc,
3032 * _scsih_block_io_to_children_attached_directly
3033 * @ioc: per adapter object
3034 * @event_data: topology change event data
3036 * This routine set sdev state to SDEV_BLOCK for all devices
3037 * direct attached during device pull.
3040 _scsih_block_io_to_children_attached_directly(struct MPT2SAS_ADAPTER *ioc,
3041 Mpi2EventDataSasTopologyChangeList_t *event_data)
3048 for (i = 0; i < event_data->NumEntries; i++) {
3049 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
3052 phy_number = event_data->StartPhyNum + i;
3053 reason_code = event_data->PHY[i].PhyStatus &
3054 MPI2_EVENT_SAS_TOPO_RC_MASK;
3055 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING)
3056 _scsih_block_io_device(ioc, handle);
3061 * _scsih_tm_tr_send - send task management request
3062 * @ioc: per adapter object
3063 * @handle: device handle
3064 * Context: interrupt time.
3066 * This code is to initiate the device removal handshake protocol
3067 * with controller firmware. This function will issue target reset
3068 * using high priority request queue. It will send a sas iounit
3069 * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
3071 * This is designed to send muliple task management request at the same
3072 * time to the fifo. If the fifo is full, we will append the request,
3073 * and process it in a future completion.
3076 _scsih_tm_tr_send(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3078 Mpi2SCSITaskManagementRequest_t *mpi_request;
3080 struct _sas_device *sas_device;
3081 struct MPT2SAS_TARGET *sas_target_priv_data = NULL;
3082 u64 sas_address = 0;
3083 unsigned long flags;
3084 struct _tr_list *delayed_tr;
3087 if (ioc->remove_host) {
3088 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host has been "
3089 "removed: handle(0x%04x)\n", __func__, ioc->name, handle));
3091 } else if (ioc->pci_error_recovery) {
3092 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host in pci "
3093 "error recovery: handle(0x%04x)\n", __func__, ioc->name,
3097 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
3098 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3099 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host is not "
3100 "operational: handle(0x%04x)\n", __func__, ioc->name,
3105 /* if PD, then return */
3106 if (test_bit(handle, ioc->pd_handles))
3109 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3110 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
3111 if (sas_device && sas_device->starget &&
3112 sas_device->starget->hostdata) {
3113 sas_target_priv_data = sas_device->starget->hostdata;
3114 sas_target_priv_data->deleted = 1;
3115 sas_address = sas_device->sas_address;
3117 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3119 if (sas_target_priv_data) {
3120 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "setting delete flag: "
3121 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, handle,
3122 (unsigned long long)sas_address));
3123 _scsih_ublock_io_device(ioc, handle);
3124 sas_target_priv_data->handle = MPT2SAS_INVALID_DEVICE_HANDLE;
3127 smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_tr_cb_idx);
3129 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3132 INIT_LIST_HEAD(&delayed_tr->list);
3133 delayed_tr->handle = handle;
3134 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
3135 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3136 "DELAYED:tr:handle(0x%04x), (open)\n",
3137 ioc->name, handle));
3141 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "tr_send:handle(0x%04x), "
3142 "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid,
3143 ioc->tm_tr_cb_idx));
3144 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3145 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
3146 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3147 mpi_request->DevHandle = cpu_to_le16(handle);
3148 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
3149 mpt2sas_base_put_smid_hi_priority(ioc, smid);
3155 * _scsih_sas_control_complete - completion routine
3156 * @ioc: per adapter object
3157 * @smid: system request message index
3158 * @msix_index: MSIX table index supplied by the OS
3159 * @reply: reply message frame(lower 32bit addr)
3160 * Context: interrupt time.
3162 * This is the sas iounit control completion routine.
3163 * This code is part of the code to initiate the device removal
3164 * handshake protocol with controller firmware.
3166 * Return 1 meaning mf should be freed from _base_interrupt
3167 * 0 means the mf is freed from this function.
3170 _scsih_sas_control_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid,
3171 u8 msix_index, u32 reply)
3173 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3174 Mpi2SasIoUnitControlReply_t *mpi_reply =
3175 mpt2sas_base_get_reply_virt_addr(ioc, reply);
3177 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3178 "sc_complete:handle(0x%04x), (open) "
3179 "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
3180 ioc->name, le16_to_cpu(mpi_reply->DevHandle), smid,
3181 le16_to_cpu(mpi_reply->IOCStatus),
3182 le32_to_cpu(mpi_reply->IOCLogInfo)));
3187 * _scsih_tm_tr_volume_send - send target reset request for volumes
3188 * @ioc: per adapter object
3189 * @handle: device handle
3190 * Context: interrupt time.
3192 * This is designed to send muliple task management request at the same
3193 * time to the fifo. If the fifo is full, we will append the request,
3194 * and process it in a future completion.
3197 _scsih_tm_tr_volume_send(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3199 Mpi2SCSITaskManagementRequest_t *mpi_request;
3201 struct _tr_list *delayed_tr;
3203 if (ioc->shost_recovery || ioc->remove_host ||
3204 ioc->pci_error_recovery) {
3205 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in "
3206 "progress!\n", __func__, ioc->name));
3210 smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_tr_volume_cb_idx);
3212 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3215 INIT_LIST_HEAD(&delayed_tr->list);
3216 delayed_tr->handle = handle;
3217 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_volume_list);
3218 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3219 "DELAYED:tr:handle(0x%04x), (open)\n",
3220 ioc->name, handle));
3224 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "tr_send:handle(0x%04x), "
3225 "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid,
3226 ioc->tm_tr_volume_cb_idx));
3227 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3228 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
3229 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3230 mpi_request->DevHandle = cpu_to_le16(handle);
3231 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
3232 mpt2sas_base_put_smid_hi_priority(ioc, smid);
3236 * _scsih_tm_volume_tr_complete - target reset completion
3237 * @ioc: per adapter object
3238 * @smid: system request message index
3239 * @msix_index: MSIX table index supplied by the OS
3240 * @reply: reply message frame(lower 32bit addr)
3241 * Context: interrupt time.
3243 * Return 1 meaning mf should be freed from _base_interrupt
3244 * 0 means the mf is freed from this function.
3247 _scsih_tm_volume_tr_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid,
3248 u8 msix_index, u32 reply)
3251 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
3252 Mpi2SCSITaskManagementReply_t *mpi_reply =
3253 mpt2sas_base_get_reply_virt_addr(ioc, reply);
3255 if (ioc->shost_recovery || ioc->remove_host ||
3256 ioc->pci_error_recovery) {
3257 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in "
3258 "progress!\n", __func__, ioc->name));
3262 mpi_request_tm = mpt2sas_base_get_msg_frame(ioc, smid);
3263 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3264 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3265 dewtprintk(ioc, printk("spurious interrupt: "
3266 "handle(0x%04x:0x%04x), smid(%d)!!!\n", handle,
3267 le16_to_cpu(mpi_reply->DevHandle), smid));
3271 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3272 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3273 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3274 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3275 le32_to_cpu(mpi_reply->IOCLogInfo),
3276 le32_to_cpu(mpi_reply->TerminationCount)));
3278 return _scsih_check_for_pending_tm(ioc, smid);
3282 * _scsih_tm_tr_complete -
3283 * @ioc: per adapter object
3284 * @smid: system request message index
3285 * @msix_index: MSIX table index supplied by the OS
3286 * @reply: reply message frame(lower 32bit addr)
3287 * Context: interrupt time.
3289 * This is the target reset completion routine.
3290 * This code is part of the code to initiate the device removal
3291 * handshake protocol with controller firmware.
3292 * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE)
3294 * Return 1 meaning mf should be freed from _base_interrupt
3295 * 0 means the mf is freed from this function.
3298 _scsih_tm_tr_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
3302 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
3303 Mpi2SCSITaskManagementReply_t *mpi_reply =
3304 mpt2sas_base_get_reply_virt_addr(ioc, reply);
3305 Mpi2SasIoUnitControlRequest_t *mpi_request;
3309 if (ioc->remove_host) {
3310 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host has been "
3311 "removed\n", __func__, ioc->name));
3313 } else if (ioc->pci_error_recovery) {
3314 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host in pci "
3315 "error recovery\n", __func__, ioc->name));
3318 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
3319 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3320 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host is not "
3321 "operational\n", __func__, ioc->name));
3325 mpi_request_tm = mpt2sas_base_get_msg_frame(ioc, smid);
3326 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3327 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3328 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "spurious interrupt: "
3329 "handle(0x%04x:0x%04x), smid(%d)!!!\n", ioc->name, handle,
3330 le16_to_cpu(mpi_reply->DevHandle), smid));
3334 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3335 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3336 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3337 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3338 le32_to_cpu(mpi_reply->IOCLogInfo),
3339 le32_to_cpu(mpi_reply->TerminationCount)));
3341 smid_sas_ctrl = mpt2sas_base_get_smid(ioc, ioc->tm_sas_control_cb_idx);
3342 if (!smid_sas_ctrl) {
3343 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3344 ioc->name, __func__);
3348 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "sc_send:handle(0x%04x), "
3349 "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid_sas_ctrl,
3350 ioc->tm_sas_control_cb_idx));
3351 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid_sas_ctrl);
3352 memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t));
3353 mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL;
3354 mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE;
3355 mpi_request->DevHandle = mpi_request_tm->DevHandle;
3356 mpt2sas_base_put_smid_default(ioc, smid_sas_ctrl);
3358 return _scsih_check_for_pending_tm(ioc, smid);
3362 * _scsih_check_for_pending_tm - check for pending task management
3363 * @ioc: per adapter object
3364 * @smid: system request message index
3366 * This will check delayed target reset list, and feed the
3369 * Return 1 meaning mf should be freed from _base_interrupt
3370 * 0 means the mf is freed from this function.
3373 _scsih_check_for_pending_tm(struct MPT2SAS_ADAPTER *ioc, u16 smid)
3375 struct _tr_list *delayed_tr;
3377 if (!list_empty(&ioc->delayed_tr_volume_list)) {
3378 delayed_tr = list_entry(ioc->delayed_tr_volume_list.next,
3379 struct _tr_list, list);
3380 mpt2sas_base_free_smid(ioc, smid);
3381 _scsih_tm_tr_volume_send(ioc, delayed_tr->handle);
3382 list_del(&delayed_tr->list);
3387 if (!list_empty(&ioc->delayed_tr_list)) {
3388 delayed_tr = list_entry(ioc->delayed_tr_list.next,
3389 struct _tr_list, list);
3390 mpt2sas_base_free_smid(ioc, smid);
3391 _scsih_tm_tr_send(ioc, delayed_tr->handle);
3392 list_del(&delayed_tr->list);
3401 * _scsih_check_topo_delete_events - sanity check on topo events
3402 * @ioc: per adapter object
3403 * @event_data: the event data payload
3405 * This routine added to better handle cable breaker.
3407 * This handles the case where driver receives multiple expander
3408 * add and delete events in a single shot. When there is a delete event
3409 * the routine will void any pending add events waiting in the event queue.
3414 _scsih_check_topo_delete_events(struct MPT2SAS_ADAPTER *ioc,
3415 Mpi2EventDataSasTopologyChangeList_t *event_data)
3417 struct fw_event_work *fw_event;
3418 Mpi2EventDataSasTopologyChangeList_t *local_event_data;
3419 u16 expander_handle;
3420 struct _sas_node *sas_expander;
3421 unsigned long flags;
3425 for (i = 0 ; i < event_data->NumEntries; i++) {
3426 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
3429 reason_code = event_data->PHY[i].PhyStatus &
3430 MPI2_EVENT_SAS_TOPO_RC_MASK;
3431 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING)
3432 _scsih_tm_tr_send(ioc, handle);
3435 expander_handle = le16_to_cpu(event_data->ExpanderDevHandle);
3436 if (expander_handle < ioc->sas_hba.num_phys) {
3437 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3441 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
3442 || event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING) {
3443 spin_lock_irqsave(&ioc->sas_node_lock, flags);
3444 sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc,
3446 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
3447 _scsih_block_io_to_children_attached_to_ex(ioc, sas_expander);
3448 } else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING)
3449 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3451 if (event_data->ExpStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING)
3454 /* mark ignore flag for pending events */
3455 spin_lock_irqsave(&ioc->fw_event_lock, flags);
3456 list_for_each_entry(fw_event, &ioc->fw_event_list, list) {
3457 if (fw_event->event != MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST ||
3460 local_event_data = fw_event->event_data;
3461 if (local_event_data->ExpStatus ==
3462 MPI2_EVENT_SAS_TOPO_ES_ADDED ||
3463 local_event_data->ExpStatus ==
3464 MPI2_EVENT_SAS_TOPO_ES_RESPONDING) {
3465 if (le16_to_cpu(local_event_data->ExpanderDevHandle) ==
3467 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3468 "setting ignoring flag\n", ioc->name));
3469 fw_event->ignore = 1;
3473 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
3477 * _scsih_set_volume_delete_flag - setting volume delete flag
3478 * @ioc: per adapter object
3479 * @handle: device handle
3485 _scsih_set_volume_delete_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3487 struct _raid_device *raid_device;
3488 struct MPT2SAS_TARGET *sas_target_priv_data;
3489 unsigned long flags;
3491 spin_lock_irqsave(&ioc->raid_device_lock, flags);
3492 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
3493 if (raid_device && raid_device->starget &&
3494 raid_device->starget->hostdata) {
3495 sas_target_priv_data =
3496 raid_device->starget->hostdata;
3497 sas_target_priv_data->deleted = 1;
3498 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3499 "setting delete flag: handle(0x%04x), "
3500 "wwid(0x%016llx)\n", ioc->name, handle,
3501 (unsigned long long) raid_device->wwid));
3503 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
3507 * _scsih_set_volume_handle_for_tr - set handle for target reset to volume
3508 * @handle: input handle
3509 * @a: handle for volume a
3510 * @b: handle for volume b
3512 * IR firmware only supports two raid volumes. The purpose of this
3513 * routine is to set the volume handle in either a or b. When the given
3514 * input handle is non-zero, or when a and b have not been set before.
3517 _scsih_set_volume_handle_for_tr(u16 handle, u16 *a, u16 *b)
3519 if (!handle || handle == *a || handle == *b)
3528 * _scsih_check_ir_config_unhide_events - check for UNHIDE events
3529 * @ioc: per adapter object
3530 * @event_data: the event data payload
3531 * Context: interrupt time.
3533 * This routine will send target reset to volume, followed by target
3534 * resets to the PDs. This is called when a PD has been removed, or
3535 * volume has been deleted or removed. When the target reset is sent
3536 * to volume, the PD target resets need to be queued to start upon
3537 * completion of the volume target reset.
3542 _scsih_check_ir_config_unhide_events(struct MPT2SAS_ADAPTER *ioc,
3543 Mpi2EventDataIrConfigChangeList_t *event_data)
3545 Mpi2EventIrConfigElement_t *element;
3547 u16 handle, volume_handle, a, b;
3548 struct _tr_list *delayed_tr;
3553 if (ioc->is_warpdrive)
3556 /* Volume Resets for Deleted or Removed */
3557 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3558 for (i = 0; i < event_data->NumElements; i++, element++) {
3559 if (element->ReasonCode ==
3560 MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED ||
3561 element->ReasonCode ==
3562 MPI2_EVENT_IR_CHANGE_RC_REMOVED) {
3563 volume_handle = le16_to_cpu(element->VolDevHandle);
3564 _scsih_set_volume_delete_flag(ioc, volume_handle);
3565 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3569 /* Volume Resets for UNHIDE events */
3570 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3571 for (i = 0; i < event_data->NumElements; i++, element++) {
3572 if (le32_to_cpu(event_data->Flags) &
3573 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG)
3575 if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_UNHIDE) {
3576 volume_handle = le16_to_cpu(element->VolDevHandle);
3577 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3582 _scsih_tm_tr_volume_send(ioc, a);
3584 _scsih_tm_tr_volume_send(ioc, b);
3586 /* PD target resets */
3587 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3588 for (i = 0; i < event_data->NumElements; i++, element++) {
3589 if (element->ReasonCode != MPI2_EVENT_IR_CHANGE_RC_UNHIDE)
3591 handle = le16_to_cpu(element->PhysDiskDevHandle);
3592 volume_handle = le16_to_cpu(element->VolDevHandle);
3593 clear_bit(handle, ioc->pd_handles);
3595 _scsih_tm_tr_send(ioc, handle);
3596 else if (volume_handle == a || volume_handle == b) {
3597 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3598 BUG_ON(!delayed_tr);
3599 INIT_LIST_HEAD(&delayed_tr->list);
3600 delayed_tr->handle = handle;
3601 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
3602 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3603 "DELAYED:tr:handle(0x%04x), (open)\n", ioc->name,
3606 _scsih_tm_tr_send(ioc, handle);
3612 * _scsih_check_volume_delete_events - set delete flag for volumes
3613 * @ioc: per adapter object
3614 * @event_data: the event data payload
3615 * Context: interrupt time.
3617 * This will handle the case when the cable connected to entire volume is
3618 * pulled. We will take care of setting the deleted flag so normal IO will
3624 _scsih_check_volume_delete_events(struct MPT2SAS_ADAPTER *ioc,
3625 Mpi2EventDataIrVolume_t *event_data)
3629 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
3631 state = le32_to_cpu(event_data->NewValue);
3632 if (state == MPI2_RAID_VOL_STATE_MISSING || state ==
3633 MPI2_RAID_VOL_STATE_FAILED)
3634 _scsih_set_volume_delete_flag(ioc,
3635 le16_to_cpu(event_data->VolDevHandle));
3639 * _scsih_flush_running_cmds - completing outstanding commands.
3640 * @ioc: per adapter object
3642 * The flushing out of all pending scmd commands following host reset,
3643 * where all IO is dropped to the floor.
3648 _scsih_flush_running_cmds(struct MPT2SAS_ADAPTER *ioc)
3650 struct scsi_cmnd *scmd;
3654 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
3655 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
3659 mpt2sas_base_free_smid(ioc, smid);
3660 scsi_dma_unmap(scmd);
3661 if (ioc->pci_error_recovery)
3662 scmd->result = DID_NO_CONNECT << 16;
3664 scmd->result = DID_RESET << 16;
3665 scmd->scsi_done(scmd);
3667 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "completing %d cmds\n",
3672 * _scsih_setup_eedp - setup MPI request for EEDP transfer
3673 * @scmd: pointer to scsi command object
3674 * @mpi_request: pointer to the SCSI_IO reqest message frame
3676 * Supporting protection 1 and 3.
3681 _scsih_setup_eedp(struct scsi_cmnd *scmd, Mpi2SCSIIORequest_t *mpi_request)
3684 unsigned char prot_op = scsi_get_prot_op(scmd);
3685 unsigned char prot_type = scsi_get_prot_type(scmd);
3687 if (prot_type == SCSI_PROT_DIF_TYPE0 || prot_op == SCSI_PROT_NORMAL)
3690 if (prot_op == SCSI_PROT_READ_STRIP)
3691 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP;
3692 else if (prot_op == SCSI_PROT_WRITE_INSERT)
3693 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_INSERT_OP;
3697 switch (prot_type) {
3698 case SCSI_PROT_DIF_TYPE1:
3699 case SCSI_PROT_DIF_TYPE2:
3702 * enable ref/guard checking
3703 * auto increment ref tag
3705 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG |
3706 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG |
3707 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
3708 mpi_request->CDB.EEDP32.PrimaryReferenceTag =
3709 cpu_to_be32(scsi_get_lba(scmd));
3712 case SCSI_PROT_DIF_TYPE3:
3715 * enable guard checking
3717 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
3720 mpi_request->EEDPBlockSize = cpu_to_le32(scmd->device->sector_size);
3721 mpi_request->EEDPFlags = cpu_to_le16(eedp_flags);
3725 * _scsih_eedp_error_handling - return sense code for EEDP errors
3726 * @scmd: pointer to scsi command object
3727 * @ioc_status: ioc status
3732 _scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status)
3738 switch (ioc_status) {
3739 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
3742 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
3745 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
3753 if (scmd->sc_data_direction == DMA_TO_DEVICE) {
3754 sk = ILLEGAL_REQUEST;
3755 host_byte = DID_ABORT;
3757 sk = ABORTED_COMMAND;
3761 scsi_build_sense_buffer(0, scmd->sense_buffer, sk, 0x10, ascq);
3762 scmd->result = DRIVER_SENSE << 24 | (host_byte << 16) |
3763 SAM_STAT_CHECK_CONDITION;
3767 * _scsih_scsi_direct_io_get - returns direct io flag
3768 * @ioc: per adapter object
3769 * @smid: system request message index
3771 * Returns the smid stored scmd pointer.
3774 _scsih_scsi_direct_io_get(struct MPT2SAS_ADAPTER *ioc, u16 smid)
3776 return ioc->scsi_lookup[smid - 1].direct_io;
3780 * _scsih_scsi_direct_io_set - sets direct io flag
3781 * @ioc: per adapter object
3782 * @smid: system request message index
3783 * @direct_io: Zero or non-zero value to set in the direct_io flag
3788 _scsih_scsi_direct_io_set(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 direct_io)
3790 ioc->scsi_lookup[smid - 1].direct_io = direct_io;
3795 * _scsih_setup_direct_io - setup MPI request for WARPDRIVE Direct I/O
3796 * @ioc: per adapter object
3797 * @scmd: pointer to scsi command object
3798 * @raid_device: pointer to raid device data structure
3799 * @mpi_request: pointer to the SCSI_IO reqest message frame
3800 * @smid: system request message index
3805 _scsih_setup_direct_io(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
3806 struct _raid_device *raid_device, Mpi2SCSIIORequest_t *mpi_request,
3809 u32 v_lba, p_lba, stripe_off, stripe_unit, column, io_size;
3810 u32 stripe_sz, stripe_exp;
3811 u8 num_pds, *cdb_ptr, *tmp_ptr, *lba_ptr1, *lba_ptr2;
3812 u8 cdb0 = scmd->cmnd[0];
3815 * Try Direct I/O to RAID memeber disks
3817 if (cdb0 == READ_16 || cdb0 == READ_10 ||
3818 cdb0 == WRITE_16 || cdb0 == WRITE_10) {
3819 cdb_ptr = mpi_request->CDB.CDB32;
3821 if ((cdb0 < READ_16) || !(cdb_ptr[2] | cdb_ptr[3] | cdb_ptr[4]
3823 io_size = scsi_bufflen(scmd) >> 9;
3824 /* get virtual lba */
3825 lba_ptr1 = lba_ptr2 = (cdb0 < READ_16) ? &cdb_ptr[2] :
3827 tmp_ptr = (u8 *)&v_lba + 3;
3828 *tmp_ptr-- = *lba_ptr1++;
3829 *tmp_ptr-- = *lba_ptr1++;
3830 *tmp_ptr-- = *lba_ptr1++;
3831 *tmp_ptr = *lba_ptr1;
3833 if (((u64)v_lba + (u64)io_size - 1) <=
3834 (u32)raid_device->max_lba) {
3835 stripe_sz = raid_device->stripe_sz;
3836 stripe_exp = raid_device->stripe_exponent;
3837 stripe_off = v_lba & (stripe_sz - 1);
3839 /* Check whether IO falls within a stripe */
3840 if ((stripe_off + io_size) <= stripe_sz) {
3841 num_pds = raid_device->num_pds;
3842 p_lba = v_lba >> stripe_exp;
3843 stripe_unit = p_lba / num_pds;
3844 column = p_lba % num_pds;
3845 p_lba = (stripe_unit << stripe_exp) +
3847 mpi_request->DevHandle =
3848 cpu_to_le16(raid_device->
3850 tmp_ptr = (u8 *)&p_lba + 3;
3851 *lba_ptr2++ = *tmp_ptr--;
3852 *lba_ptr2++ = *tmp_ptr--;
3853 *lba_ptr2++ = *tmp_ptr--;
3854 *lba_ptr2 = *tmp_ptr;
3856 * WD: To indicate this I/O is directI/O
3858 _scsih_scsi_direct_io_set(ioc, smid, 1);
3866 * _scsih_qcmd - main scsi request entry point
3867 * @scmd: pointer to scsi command object
3868 * @done: function pointer to be invoked on completion
3870 * The callback index is set inside `ioc->scsi_io_cb_idx`.
3872 * Returns 0 on success. If there's a failure, return either:
3873 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
3874 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
3877 _scsih_qcmd_lck(struct scsi_cmnd *scmd, void (*done)(struct scsi_cmnd *))
3879 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
3880 struct MPT2SAS_DEVICE *sas_device_priv_data;
3881 struct MPT2SAS_TARGET *sas_target_priv_data;
3882 struct _raid_device *raid_device;
3883 Mpi2SCSIIORequest_t *mpi_request;
3887 scmd->scsi_done = done;
3888 sas_device_priv_data = scmd->device->hostdata;
3889 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
3890 scmd->result = DID_NO_CONNECT << 16;
3891 scmd->scsi_done(scmd);
3895 if (ioc->pci_error_recovery || ioc->remove_host) {
3896 scmd->result = DID_NO_CONNECT << 16;
3897 scmd->scsi_done(scmd);
3901 sas_target_priv_data = sas_device_priv_data->sas_target;
3902 /* invalid device handle */
3903 if (sas_target_priv_data->handle == MPT2SAS_INVALID_DEVICE_HANDLE) {
3904 scmd->result = DID_NO_CONNECT << 16;
3905 scmd->scsi_done(scmd);
3909 /* host recovery or link resets sent via IOCTLs */
3910 if (ioc->shost_recovery || ioc->ioc_link_reset_in_progress)
3911 return SCSI_MLQUEUE_HOST_BUSY;
3912 /* device busy with task management */
3913 else if (sas_device_priv_data->block || sas_target_priv_data->tm_busy)
3914 return SCSI_MLQUEUE_DEVICE_BUSY;
3915 /* device has been deleted */
3916 else if (sas_target_priv_data->deleted) {
3917 scmd->result = DID_NO_CONNECT << 16;
3918 scmd->scsi_done(scmd);
3922 if (scmd->sc_data_direction == DMA_FROM_DEVICE)
3923 mpi_control = MPI2_SCSIIO_CONTROL_READ;
3924 else if (scmd->sc_data_direction == DMA_TO_DEVICE)
3925 mpi_control = MPI2_SCSIIO_CONTROL_WRITE;
3927 mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER;
3930 if (!(sas_device_priv_data->flags & MPT_DEVICE_FLAGS_INIT)) {
3931 if (scmd->device->tagged_supported) {
3932 if (scmd->device->ordered_tags)
3933 mpi_control |= MPI2_SCSIIO_CONTROL_ORDEREDQ;
3935 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
3937 /* MPI Revision I (UNIT = 0xA) - removed MPI2_SCSIIO_CONTROL_UNTAGGED */
3938 /* mpi_control |= MPI2_SCSIIO_CONTROL_UNTAGGED;
3940 mpi_control |= (0x500);
3943 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
3944 /* Make sure Device is not raid volume.
3945 * We do not expose raid functionality to upper layer for warpdrive.
3947 if (!ioc->is_warpdrive && !_scsih_is_raid(&scmd->device->sdev_gendev) &&
3948 sas_is_tlr_enabled(scmd->device) && scmd->cmd_len != 32)
3949 mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON;
3951 smid = mpt2sas_base_get_smid_scsiio(ioc, ioc->scsi_io_cb_idx, scmd);
3953 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3954 ioc->name, __func__);
3957 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3958 memset(mpi_request, 0, sizeof(Mpi2SCSIIORequest_t));
3959 _scsih_setup_eedp(scmd, mpi_request);
3960 if (scmd->cmd_len == 32)
3961 mpi_control |= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT;
3962 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
3963 if (sas_device_priv_data->sas_target->flags &
3964 MPT_TARGET_FLAGS_RAID_COMPONENT)
3965 mpi_request->Function = MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;
3967 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
3968 mpi_request->DevHandle =
3969 cpu_to_le16(sas_device_priv_data->sas_target->handle);
3970 mpi_request->DataLength = cpu_to_le32(scsi_bufflen(scmd));
3971 mpi_request->Control = cpu_to_le32(mpi_control);
3972 mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len);
3973 mpi_request->MsgFlags = MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR;
3974 mpi_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE;
3975 mpi_request->SenseBufferLowAddress =
3976 mpt2sas_base_get_sense_buffer_dma(ioc, smid);
3977 mpi_request->SGLOffset0 = offsetof(Mpi2SCSIIORequest_t, SGL) / 4;
3978 mpi_request->SGLFlags = cpu_to_le16(MPI2_SCSIIO_SGLFLAGS_TYPE_MPI +
3979 MPI2_SCSIIO_SGLFLAGS_SYSTEM_ADDR);
3980 mpi_request->VF_ID = 0; /* TODO */
3981 mpi_request->VP_ID = 0;
3982 int_to_scsilun(sas_device_priv_data->lun, (struct scsi_lun *)
3984 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
3986 if (!mpi_request->DataLength) {
3987 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request->SGL);
3989 if (_scsih_build_scatter_gather(ioc, scmd, smid)) {
3990 mpt2sas_base_free_smid(ioc, smid);
3995 raid_device = sas_target_priv_data->raid_device;
3996 if (raid_device && raid_device->direct_io_enabled)
3997 _scsih_setup_direct_io(ioc, scmd, raid_device, mpi_request,
4000 if (likely(mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST))
4001 mpt2sas_base_put_smid_scsi_io(ioc, smid,
4002 le16_to_cpu(mpi_request->DevHandle));
4004 mpt2sas_base_put_smid_default(ioc, smid);
4008 return SCSI_MLQUEUE_HOST_BUSY;
4011 static DEF_SCSI_QCMD(_scsih_qcmd)
4014 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
4015 * @sense_buffer: sense data returned by target
4016 * @data: normalized skey/asc/ascq
4021 _scsih_normalize_sense(char *sense_buffer, struct sense_info *data)
4023 if ((sense_buffer[0] & 0x7F) >= 0x72) {
4024 /* descriptor format */
4025 data->skey = sense_buffer[1] & 0x0F;
4026 data->asc = sense_buffer[2];
4027 data->ascq = sense_buffer[3];
4030 data->skey = sense_buffer[2] & 0x0F;
4031 data->asc = sense_buffer[12];
4032 data->ascq = sense_buffer[13];
4036 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4038 * _scsih_scsi_ioc_info - translated non-successful SCSI_IO request
4039 * @ioc: per adapter object
4040 * @scmd: pointer to scsi command object
4041 * @mpi_reply: reply mf payload returned from firmware
4043 * scsi_status - SCSI Status code returned from target device
4044 * scsi_state - state info associated with SCSI_IO determined by ioc
4045 * ioc_status - ioc supplied status info
4050 _scsih_scsi_ioc_info(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
4051 Mpi2SCSIIOReply_t *mpi_reply, u16 smid)
4055 u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) &
4056 MPI2_IOCSTATUS_MASK;
4057 u8 scsi_state = mpi_reply->SCSIState;
4058 u8 scsi_status = mpi_reply->SCSIStatus;
4059 char *desc_ioc_state = NULL;
4060 char *desc_scsi_status = NULL;
4061 char *desc_scsi_state = ioc->tmp_string;
4062 u32 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
4063 struct _sas_device *sas_device = NULL;
4064 unsigned long flags;
4065 struct scsi_target *starget = scmd->device->sdev_target;
4066 struct MPT2SAS_TARGET *priv_target = starget->hostdata;
4067 char *device_str = NULL;
4072 if (ioc->hide_ir_msg)
4073 device_str = "WarpDrive";
4075 device_str = "volume";
4077 if (log_info == 0x31170000)
4080 switch (ioc_status) {
4081 case MPI2_IOCSTATUS_SUCCESS:
4082 desc_ioc_state = "success";
4084 case MPI2_IOCSTATUS_INVALID_FUNCTION:
4085 desc_ioc_state = "invalid function";
4087 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
4088 desc_ioc_state = "scsi recovered error";
4090 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE:
4091 desc_ioc_state = "scsi invalid dev handle";
4093 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
4094 desc_ioc_state = "scsi device not there";
4096 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
4097 desc_ioc_state = "scsi data overrun";
4099 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
4100 desc_ioc_state = "scsi data underrun";
4102 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
4103 desc_ioc_state = "scsi io data error";
4105 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
4106 desc_ioc_state = "scsi protocol error";
4108 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
4109 desc_ioc_state = "scsi task terminated";
4111 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
4112 desc_ioc_state = "scsi residual mismatch";
4114 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
4115 desc_ioc_state = "scsi task mgmt failed";
4117 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
4118 desc_ioc_state = "scsi ioc terminated";
4120 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
4121 desc_ioc_state = "scsi ext terminated";
4123 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4124 desc_ioc_state = "eedp guard error";
4126 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4127 desc_ioc_state = "eedp ref tag error";
4129 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4130 desc_ioc_state = "eedp app tag error";
4133 desc_ioc_state = "unknown";
4137 switch (scsi_status) {
4138 case MPI2_SCSI_STATUS_GOOD:
4139 desc_scsi_status = "good";
4141 case MPI2_SCSI_STATUS_CHECK_CONDITION:
4142 desc_scsi_status = "check condition";
4144 case MPI2_SCSI_STATUS_CONDITION_MET:
4145 desc_scsi_status = "condition met";
4147 case MPI2_SCSI_STATUS_BUSY:
4148 desc_scsi_status = "busy";
4150 case MPI2_SCSI_STATUS_INTERMEDIATE:
4151 desc_scsi_status = "intermediate";
4153 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET:
4154 desc_scsi_status = "intermediate condmet";
4156 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT:
4157 desc_scsi_status = "reservation conflict";
4159 case MPI2_SCSI_STATUS_COMMAND_TERMINATED:
4160 desc_scsi_status = "command terminated";
4162 case MPI2_SCSI_STATUS_TASK_SET_FULL:
4163 desc_scsi_status = "task set full";
4165 case MPI2_SCSI_STATUS_ACA_ACTIVE:
4166 desc_scsi_status = "aca active";
4168 case MPI2_SCSI_STATUS_TASK_ABORTED:
4169 desc_scsi_status = "task aborted";
4172 desc_scsi_status = "unknown";
4176 desc_scsi_state[0] = '\0';
4178 desc_scsi_state = " ";
4179 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
4180 strcat(desc_scsi_state, "response info ");
4181 if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4182 strcat(desc_scsi_state, "state terminated ");
4183 if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS)
4184 strcat(desc_scsi_state, "no status ");
4185 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED)
4186 strcat(desc_scsi_state, "autosense failed ");
4187 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)
4188 strcat(desc_scsi_state, "autosense valid ");
4190 scsi_print_command(scmd);
4192 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
4193 printk(MPT2SAS_WARN_FMT "\t%s wwid(0x%016llx)\n", ioc->name,
4194 device_str, (unsigned long long)priv_target->sas_address);
4196 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4197 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
4198 priv_target->sas_address);
4200 printk(MPT2SAS_WARN_FMT "\tsas_address(0x%016llx), "
4201 "phy(%d)\n", ioc->name, sas_device->sas_address,
4203 printk(MPT2SAS_WARN_FMT
4204 "\tenclosure_logical_id(0x%016llx), slot(%d)\n",
4205 ioc->name, sas_device->enclosure_logical_id,
4208 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4211 printk(MPT2SAS_WARN_FMT "\thandle(0x%04x), ioc_status(%s)(0x%04x), "
4212 "smid(%d)\n", ioc->name, le16_to_cpu(mpi_reply->DevHandle),
4213 desc_ioc_state, ioc_status, smid);
4214 printk(MPT2SAS_WARN_FMT "\trequest_len(%d), underflow(%d), "
4215 "resid(%d)\n", ioc->name, scsi_bufflen(scmd), scmd->underflow,
4216 scsi_get_resid(scmd));
4217 printk(MPT2SAS_WARN_FMT "\ttag(%d), transfer_count(%d), "
4218 "sc->result(0x%08x)\n", ioc->name, le16_to_cpu(mpi_reply->TaskTag),
4219 le32_to_cpu(mpi_reply->TransferCount), scmd->result);
4220 printk(MPT2SAS_WARN_FMT "\tscsi_status(%s)(0x%02x), "
4221 "scsi_state(%s)(0x%02x)\n", ioc->name, desc_scsi_status,
4222 scsi_status, desc_scsi_state, scsi_state);
4224 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
4225 struct sense_info data;
4226 _scsih_normalize_sense(scmd->sense_buffer, &data);
4227 printk(MPT2SAS_WARN_FMT "\t[sense_key,asc,ascq]: "
4228 "[0x%02x,0x%02x,0x%02x], count(%d)\n", ioc->name, data.skey,
4229 data.asc, data.ascq, le32_to_cpu(mpi_reply->SenseCount));
4232 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) {
4233 response_info = le32_to_cpu(mpi_reply->ResponseInfo);
4234 response_bytes = (u8 *)&response_info;
4235 _scsih_response_code(ioc, response_bytes[0]);
4241 * _scsih_turn_on_fault_led - illuminate Fault LED
4242 * @ioc: per adapter object
4243 * @handle: device handle
4249 _scsih_turn_on_fault_led(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4251 Mpi2SepReply_t mpi_reply;
4252 Mpi2SepRequest_t mpi_request;
4254 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
4255 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
4256 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
4257 mpi_request.SlotStatus =
4258 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT);
4259 mpi_request.DevHandle = cpu_to_le16(handle);
4260 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS;
4261 if ((mpt2sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
4262 &mpi_request)) != 0) {
4263 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", ioc->name,
4264 __FILE__, __LINE__, __func__);
4268 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
4269 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "enclosure_processor: "
4270 "ioc_status (0x%04x), loginfo(0x%08x)\n", ioc->name,
4271 le16_to_cpu(mpi_reply.IOCStatus),
4272 le32_to_cpu(mpi_reply.IOCLogInfo)));
4278 * _scsih_send_event_to_turn_on_fault_led - fire delayed event
4279 * @ioc: per adapter object
4280 * @handle: device handle
4281 * Context: interrupt.
4286 _scsih_send_event_to_turn_on_fault_led(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4288 struct fw_event_work *fw_event;
4290 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
4293 fw_event->event = MPT2SAS_TURN_ON_FAULT_LED;
4294 fw_event->device_handle = handle;
4295 fw_event->ioc = ioc;
4296 _scsih_fw_event_add(ioc, fw_event);
4300 * _scsih_smart_predicted_fault - process smart errors
4301 * @ioc: per adapter object
4302 * @handle: device handle
4303 * Context: interrupt.
4308 _scsih_smart_predicted_fault(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4310 struct scsi_target *starget;
4311 struct MPT2SAS_TARGET *sas_target_priv_data;
4312 Mpi2EventNotificationReply_t *event_reply;
4313 Mpi2EventDataSasDeviceStatusChange_t *event_data;
4314 struct _sas_device *sas_device;
4316 unsigned long flags;
4318 /* only handle non-raid devices */
4319 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4320 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
4322 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4325 starget = sas_device->starget;
4326 sas_target_priv_data = starget->hostdata;
4328 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) ||
4329 ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))) {
4330 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4333 starget_printk(KERN_WARNING, starget, "predicted fault\n");
4334 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4336 if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM)
4337 _scsih_send_event_to_turn_on_fault_led(ioc, handle);
4339 /* insert into event log */
4340 sz = offsetof(Mpi2EventNotificationReply_t, EventData) +
4341 sizeof(Mpi2EventDataSasDeviceStatusChange_t);
4342 event_reply = kzalloc(sz, GFP_ATOMIC);
4344 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4345 ioc->name, __FILE__, __LINE__, __func__);
4349 event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION;
4350 event_reply->Event =
4351 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE);
4352 event_reply->MsgLength = sz/4;
4353 event_reply->EventDataLength =
4354 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t)/4);
4355 event_data = (Mpi2EventDataSasDeviceStatusChange_t *)
4356 event_reply->EventData;
4357 event_data->ReasonCode = MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA;
4358 event_data->ASC = 0x5D;
4359 event_data->DevHandle = cpu_to_le16(handle);
4360 event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address);
4361 mpt2sas_ctl_add_to_event_log(ioc, event_reply);
4366 * _scsih_io_done - scsi request callback
4367 * @ioc: per adapter object
4368 * @smid: system request message index
4369 * @msix_index: MSIX table index supplied by the OS
4370 * @reply: reply message frame(lower 32bit addr)
4372 * Callback handler when using _scsih_qcmd.
4374 * Return 1 meaning mf should be freed from _base_interrupt
4375 * 0 means the mf is freed from this function.
4378 _scsih_io_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
4380 Mpi2SCSIIORequest_t *mpi_request;
4381 Mpi2SCSIIOReply_t *mpi_reply;
4382 struct scsi_cmnd *scmd;
4388 struct MPT2SAS_DEVICE *sas_device_priv_data;
4389 u32 response_code = 0;
4390 unsigned long flags;
4392 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
4393 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
4397 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
4399 if (mpi_reply == NULL) {
4400 scmd->result = DID_OK << 16;
4404 sas_device_priv_data = scmd->device->hostdata;
4405 if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
4406 sas_device_priv_data->sas_target->deleted) {
4407 scmd->result = DID_NO_CONNECT << 16;
4411 * WARPDRIVE: If direct_io is set then it is directIO,
4412 * the failed direct I/O should be redirected to volume
4414 if (_scsih_scsi_direct_io_get(ioc, smid)) {
4415 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
4416 ioc->scsi_lookup[smid - 1].scmd = scmd;
4417 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
4418 _scsih_scsi_direct_io_set(ioc, smid, 0);
4419 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
4420 mpi_request->DevHandle =
4421 cpu_to_le16(sas_device_priv_data->sas_target->handle);
4422 mpt2sas_base_put_smid_scsi_io(ioc, smid,
4423 sas_device_priv_data->sas_target->handle);
4428 /* turning off TLR */
4429 scsi_state = mpi_reply->SCSIState;
4430 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
4432 le32_to_cpu(mpi_reply->ResponseInfo) & 0xFF;
4433 if (!sas_device_priv_data->tlr_snoop_check) {
4434 sas_device_priv_data->tlr_snoop_check++;
4435 /* Make sure Device is not raid volume.
4436 * We do not expose raid functionality to upper layer for warpdrive.
4438 if (!ioc->is_warpdrive && !_scsih_is_raid(&scmd->device->sdev_gendev) &&
4439 sas_is_tlr_enabled(scmd->device) &&
4440 response_code == MPI2_SCSITASKMGMT_RSP_INVALID_FRAME) {
4441 sas_disable_tlr(scmd->device);
4442 sdev_printk(KERN_INFO, scmd->device, "TLR disabled\n");
4446 xfer_cnt = le32_to_cpu(mpi_reply->TransferCount);
4447 scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt);
4448 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
4449 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
4450 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
4453 ioc_status &= MPI2_IOCSTATUS_MASK;
4454 scsi_status = mpi_reply->SCSIStatus;
4456 if (ioc_status == MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 &&
4457 (scsi_status == MPI2_SCSI_STATUS_BUSY ||
4458 scsi_status == MPI2_SCSI_STATUS_RESERVATION_CONFLICT ||
4459 scsi_status == MPI2_SCSI_STATUS_TASK_SET_FULL)) {
4460 ioc_status = MPI2_IOCSTATUS_SUCCESS;
4463 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
4464 struct sense_info data;
4465 const void *sense_data = mpt2sas_base_get_sense_buffer(ioc,
4467 u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE,
4468 le32_to_cpu(mpi_reply->SenseCount));
4469 memcpy(scmd->sense_buffer, sense_data, sz);
4470 _scsih_normalize_sense(scmd->sense_buffer, &data);
4471 /* failure prediction threshold exceeded */
4472 if (data.asc == 0x5D)
4473 _scsih_smart_predicted_fault(ioc,
4474 le16_to_cpu(mpi_reply->DevHandle));
4477 switch (ioc_status) {
4478 case MPI2_IOCSTATUS_BUSY:
4479 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES:
4480 scmd->result = SAM_STAT_BUSY;
4483 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
4484 scmd->result = DID_NO_CONNECT << 16;
4487 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
4488 if (sas_device_priv_data->block) {
4489 scmd->result = DID_TRANSPORT_DISRUPTED << 16;
4492 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
4493 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
4494 scmd->result = DID_RESET << 16;
4497 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
4498 if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt))
4499 scmd->result = DID_SOFT_ERROR << 16;
4501 scmd->result = (DID_OK << 16) | scsi_status;
4504 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
4505 scmd->result = (DID_OK << 16) | scsi_status;
4507 if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID))
4510 if (xfer_cnt < scmd->underflow) {
4511 if (scsi_status == SAM_STAT_BUSY)
4512 scmd->result = SAM_STAT_BUSY;
4514 scmd->result = DID_SOFT_ERROR << 16;
4515 } else if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4516 MPI2_SCSI_STATE_NO_SCSI_STATUS))
4517 scmd->result = DID_SOFT_ERROR << 16;
4518 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4519 scmd->result = DID_RESET << 16;
4520 else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) {
4521 mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID;
4522 mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION;
4523 scmd->result = (DRIVER_SENSE << 24) |
4524 SAM_STAT_CHECK_CONDITION;
4525 scmd->sense_buffer[0] = 0x70;
4526 scmd->sense_buffer[2] = ILLEGAL_REQUEST;
4527 scmd->sense_buffer[12] = 0x20;
4528 scmd->sense_buffer[13] = 0;
4532 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
4533 scsi_set_resid(scmd, 0);
4534 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
4535 case MPI2_IOCSTATUS_SUCCESS:
4536 scmd->result = (DID_OK << 16) | scsi_status;
4537 if (response_code ==
4538 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME ||
4539 (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4540 MPI2_SCSI_STATE_NO_SCSI_STATUS)))
4541 scmd->result = DID_SOFT_ERROR << 16;
4542 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4543 scmd->result = DID_RESET << 16;
4546 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4547 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4548 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4549 _scsih_eedp_error_handling(scmd, ioc_status);
4551 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
4552 case MPI2_IOCSTATUS_INVALID_FUNCTION:
4553 case MPI2_IOCSTATUS_INVALID_SGL:
4554 case MPI2_IOCSTATUS_INTERNAL_ERROR:
4555 case MPI2_IOCSTATUS_INVALID_FIELD:
4556 case MPI2_IOCSTATUS_INVALID_STATE:
4557 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
4558 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
4560 scmd->result = DID_SOFT_ERROR << 16;
4565 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4566 if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY))
4567 _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid);
4571 scsi_dma_unmap(scmd);
4572 scmd->scsi_done(scmd);
4577 * _scsih_sas_host_refresh - refreshing sas host object contents
4578 * @ioc: per adapter object
4581 * During port enable, fw will send topology events for every device. Its
4582 * possible that the handles may change from the previous setting, so this
4583 * code keeping handles updating if changed.
4588 _scsih_sas_host_refresh(struct MPT2SAS_ADAPTER *ioc)
4593 Mpi2ConfigReply_t mpi_reply;
4594 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
4595 u16 attached_handle;
4598 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT
4599 "updating handles for sas_host(0x%016llx)\n",
4600 ioc->name, (unsigned long long)ioc->sas_hba.sas_address));
4602 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys
4603 * sizeof(Mpi2SasIOUnit0PhyData_t));
4604 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4605 if (!sas_iounit_pg0) {
4606 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4607 ioc->name, __FILE__, __LINE__, __func__);
4611 if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4612 sas_iounit_pg0, sz)) != 0)
4614 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
4615 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
4617 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
4618 link_rate = sas_iounit_pg0->PhyData[i].NegotiatedLinkRate >> 4;
4620 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4621 PhyData[0].ControllerDevHandle);
4622 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
4623 attached_handle = le16_to_cpu(sas_iounit_pg0->PhyData[i].
4625 if (attached_handle && link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
4626 link_rate = MPI2_SAS_NEG_LINK_RATE_1_5;
4627 mpt2sas_transport_update_links(ioc, ioc->sas_hba.sas_address,
4628 attached_handle, i, link_rate);
4631 kfree(sas_iounit_pg0);
4635 * _scsih_sas_host_add - create sas host object
4636 * @ioc: per adapter object
4638 * Creating host side data object, stored in ioc->sas_hba
4643 _scsih_sas_host_add(struct MPT2SAS_ADAPTER *ioc)
4646 Mpi2ConfigReply_t mpi_reply;
4647 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
4648 Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
4649 Mpi2SasPhyPage0_t phy_pg0;
4650 Mpi2SasDevicePage0_t sas_device_pg0;
4651 Mpi2SasEnclosurePage0_t enclosure_pg0;
4654 u16 device_missing_delay;
4656 mpt2sas_config_get_number_hba_phys(ioc, &ioc->sas_hba.num_phys);
4657 if (!ioc->sas_hba.num_phys) {
4658 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4659 ioc->name, __FILE__, __LINE__, __func__);
4663 /* sas_iounit page 0 */
4664 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys *
4665 sizeof(Mpi2SasIOUnit0PhyData_t));
4666 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4667 if (!sas_iounit_pg0) {
4668 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4669 ioc->name, __FILE__, __LINE__, __func__);
4672 if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4673 sas_iounit_pg0, sz))) {
4674 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4675 ioc->name, __FILE__, __LINE__, __func__);
4678 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4679 MPI2_IOCSTATUS_MASK;
4680 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4681 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4682 ioc->name, __FILE__, __LINE__, __func__);
4686 /* sas_iounit page 1 */
4687 sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys *
4688 sizeof(Mpi2SasIOUnit1PhyData_t));
4689 sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
4690 if (!sas_iounit_pg1) {
4691 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4692 ioc->name, __FILE__, __LINE__, __func__);
4695 if ((mpt2sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
4696 sas_iounit_pg1, sz))) {
4697 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4698 ioc->name, __FILE__, __LINE__, __func__);
4701 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4702 MPI2_IOCSTATUS_MASK;
4703 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4704 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4705 ioc->name, __FILE__, __LINE__, __func__);
4709 ioc->io_missing_delay =
4710 le16_to_cpu(sas_iounit_pg1->IODeviceMissingDelay);
4711 device_missing_delay =
4712 le16_to_cpu(sas_iounit_pg1->ReportDeviceMissingDelay);
4713 if (device_missing_delay & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16)
4714 ioc->device_missing_delay = (device_missing_delay &
4715 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16;
4717 ioc->device_missing_delay = device_missing_delay &
4718 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
4720 ioc->sas_hba.parent_dev = &ioc->shost->shost_gendev;
4721 ioc->sas_hba.phy = kcalloc(ioc->sas_hba.num_phys,
4722 sizeof(struct _sas_phy), GFP_KERNEL);
4723 if (!ioc->sas_hba.phy) {
4724 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4725 ioc->name, __FILE__, __LINE__, __func__);
4728 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
4729 if ((mpt2sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0,
4731 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4732 ioc->name, __FILE__, __LINE__, __func__);
4735 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4736 MPI2_IOCSTATUS_MASK;
4737 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4738 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4739 ioc->name, __FILE__, __LINE__, __func__);
4744 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4745 PhyData[0].ControllerDevHandle);
4746 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
4747 ioc->sas_hba.phy[i].phy_id = i;
4748 mpt2sas_transport_add_host_phy(ioc, &ioc->sas_hba.phy[i],
4749 phy_pg0, ioc->sas_hba.parent_dev);
4751 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
4752 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, ioc->sas_hba.handle))) {
4753 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4754 ioc->name, __FILE__, __LINE__, __func__);
4757 ioc->sas_hba.enclosure_handle =
4758 le16_to_cpu(sas_device_pg0.EnclosureHandle);
4759 ioc->sas_hba.sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
4760 printk(MPT2SAS_INFO_FMT "host_add: handle(0x%04x), "
4761 "sas_addr(0x%016llx), phys(%d)\n", ioc->name, ioc->sas_hba.handle,
4762 (unsigned long long) ioc->sas_hba.sas_address,
4763 ioc->sas_hba.num_phys) ;
4765 if (ioc->sas_hba.enclosure_handle) {
4766 if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply,
4768 MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
4769 ioc->sas_hba.enclosure_handle))) {
4770 ioc->sas_hba.enclosure_logical_id =
4771 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
4776 kfree(sas_iounit_pg1);
4777 kfree(sas_iounit_pg0);
4781 * _scsih_expander_add - creating expander object
4782 * @ioc: per adapter object
4783 * @handle: expander handle
4785 * Creating expander object, stored in ioc->sas_expander_list.
4787 * Return 0 for success, else error.
4790 _scsih_expander_add(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4792 struct _sas_node *sas_expander;
4793 Mpi2ConfigReply_t mpi_reply;
4794 Mpi2ExpanderPage0_t expander_pg0;
4795 Mpi2ExpanderPage1_t expander_pg1;
4796 Mpi2SasEnclosurePage0_t enclosure_pg0;
4799 u64 sas_address, sas_address_parent = 0;
4801 unsigned long flags;
4802 struct _sas_port *mpt2sas_port = NULL;
4808 if (ioc->shost_recovery || ioc->pci_error_recovery)
4811 if ((mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
4812 MPI2_SAS_EXPAND_PGAD_FORM_HNDL, handle))) {
4813 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4814 ioc->name, __FILE__, __LINE__, __func__);
4818 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4819 MPI2_IOCSTATUS_MASK;
4820 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4821 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4822 ioc->name, __FILE__, __LINE__, __func__);
4826 /* handle out of order topology events */
4827 parent_handle = le16_to_cpu(expander_pg0.ParentDevHandle);
4828 if (_scsih_get_sas_address(ioc, parent_handle, &sas_address_parent)
4830 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4831 ioc->name, __FILE__, __LINE__, __func__);
4834 if (sas_address_parent != ioc->sas_hba.sas_address) {
4835 spin_lock_irqsave(&ioc->sas_node_lock, flags);
4836 sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
4837 sas_address_parent);
4838 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4839 if (!sas_expander) {
4840 rc = _scsih_expander_add(ioc, parent_handle);
4846 spin_lock_irqsave(&ioc->sas_node_lock, flags);
4847 sas_address = le64_to_cpu(expander_pg0.SASAddress);
4848 sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
4850 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4855 sas_expander = kzalloc(sizeof(struct _sas_node),
4857 if (!sas_expander) {
4858 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4859 ioc->name, __FILE__, __LINE__, __func__);
4863 sas_expander->handle = handle;
4864 sas_expander->num_phys = expander_pg0.NumPhys;
4865 sas_expander->sas_address_parent = sas_address_parent;
4866 sas_expander->sas_address = sas_address;
4868 printk(MPT2SAS_INFO_FMT "expander_add: handle(0x%04x),"
4869 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc->name,
4870 handle, parent_handle, (unsigned long long)
4871 sas_expander->sas_address, sas_expander->num_phys);
4873 if (!sas_expander->num_phys)
4875 sas_expander->phy = kcalloc(sas_expander->num_phys,
4876 sizeof(struct _sas_phy), GFP_KERNEL);
4877 if (!sas_expander->phy) {
4878 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4879 ioc->name, __FILE__, __LINE__, __func__);
4884 INIT_LIST_HEAD(&sas_expander->sas_port_list);
4885 mpt2sas_port = mpt2sas_transport_port_add(ioc, handle,
4886 sas_address_parent);
4887 if (!mpt2sas_port) {
4888 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4889 ioc->name, __FILE__, __LINE__, __func__);
4893 sas_expander->parent_dev = &mpt2sas_port->rphy->dev;
4895 for (i = 0 ; i < sas_expander->num_phys ; i++) {
4896 if ((mpt2sas_config_get_expander_pg1(ioc, &mpi_reply,
4897 &expander_pg1, i, handle))) {
4898 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4899 ioc->name, __FILE__, __LINE__, __func__);
4903 sas_expander->phy[i].handle = handle;
4904 sas_expander->phy[i].phy_id = i;
4906 if ((mpt2sas_transport_add_expander_phy(ioc,
4907 &sas_expander->phy[i], expander_pg1,
4908 sas_expander->parent_dev))) {
4909 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4910 ioc->name, __FILE__, __LINE__, __func__);
4916 if (sas_expander->enclosure_handle) {
4917 if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply,
4918 &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
4919 sas_expander->enclosure_handle))) {
4920 sas_expander->enclosure_logical_id =
4921 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
4925 _scsih_expander_node_add(ioc, sas_expander);
4931 mpt2sas_transport_port_remove(ioc, sas_expander->sas_address,
4932 sas_address_parent);
4933 kfree(sas_expander);
4938 * _scsih_done - scsih callback handler.
4939 * @ioc: per adapter object
4940 * @smid: system request message index
4941 * @msix_index: MSIX table index supplied by the OS
4942 * @reply: reply message frame(lower 32bit addr)
4944 * Callback handler when sending internal generated message frames.
4945 * The callback index passed is `ioc->scsih_cb_idx`
4947 * Return 1 meaning mf should be freed from _base_interrupt
4948 * 0 means the mf is freed from this function.
4951 _scsih_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
4953 MPI2DefaultReply_t *mpi_reply;
4955 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
4956 if (ioc->scsih_cmds.status == MPT2_CMD_NOT_USED)
4958 if (ioc->scsih_cmds.smid != smid)
4960 ioc->scsih_cmds.status |= MPT2_CMD_COMPLETE;
4962 memcpy(ioc->scsih_cmds.reply, mpi_reply,
4963 mpi_reply->MsgLength*4);
4964 ioc->scsih_cmds.status |= MPT2_CMD_REPLY_VALID;
4966 ioc->scsih_cmds.status &= ~MPT2_CMD_PENDING;
4967 complete(&ioc->scsih_cmds.done);
4972 * mpt2sas_expander_remove - removing expander object
4973 * @ioc: per adapter object
4974 * @sas_address: expander sas_address
4979 mpt2sas_expander_remove(struct MPT2SAS_ADAPTER *ioc, u64 sas_address)
4981 struct _sas_node *sas_expander;
4982 unsigned long flags;
4984 if (ioc->shost_recovery)
4987 spin_lock_irqsave(&ioc->sas_node_lock, flags);
4988 sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
4990 if (!sas_expander) {
4991 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4994 list_del(&sas_expander->list);
4995 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4996 _scsih_expander_node_remove(ioc, sas_expander);
5000 * _scsih_check_access_status - check access flags
5001 * @ioc: per adapter object
5002 * @sas_address: sas address
5003 * @handle: sas device handle
5004 * @access_flags: errors returned during discovery of the device
5006 * Return 0 for success, else failure
5009 _scsih_check_access_status(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
5010 u16 handle, u8 access_status)
5015 switch (access_status) {
5016 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS:
5017 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION:
5020 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED:
5021 desc = "sata capability failed";
5023 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT:
5024 desc = "sata affiliation conflict";
5026 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE:
5027 desc = "route not addressable";
5029 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE:
5030 desc = "smp error not addressable";
5032 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED:
5033 desc = "device blocked";
5035 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED:
5036 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN:
5037 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT:
5038 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG:
5039 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION:
5040 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER:
5041 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN:
5042 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN:
5043 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN:
5044 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION:
5045 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE:
5046 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX:
5047 desc = "sata initialization failed";
5057 printk(MPT2SAS_ERR_FMT "discovery errors(%s): sas_address(0x%016llx), "
5058 "handle(0x%04x)\n", ioc->name, desc,
5059 (unsigned long long)sas_address, handle);
5064 _scsih_check_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
5066 Mpi2ConfigReply_t mpi_reply;
5067 Mpi2SasDevicePage0_t sas_device_pg0;
5068 struct _sas_device *sas_device;
5070 unsigned long flags;
5072 struct scsi_target *starget;
5073 struct MPT2SAS_TARGET *sas_target_priv_data;
5076 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5077 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle)))
5080 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
5081 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
5084 /* check if this is end device */
5085 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
5086 if (!(_scsih_is_end_device(device_info)))
5089 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5090 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
5091 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5095 printk(MPT2SAS_ERR_FMT "device is not present "
5096 "handle(0x%04x), no sas_device!!!\n", ioc->name, handle);
5097 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5101 if (unlikely(sas_device->handle != handle)) {
5102 starget = sas_device->starget;
5103 sas_target_priv_data = starget->hostdata;
5104 starget_printk(KERN_INFO, starget, "handle changed from(0x%04x)"
5105 " to (0x%04x)!!!\n", sas_device->handle, handle);
5106 sas_target_priv_data->handle = handle;
5107 sas_device->handle = handle;
5109 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5111 /* check if device is present */
5112 if (!(le16_to_cpu(sas_device_pg0.Flags) &
5113 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
5114 printk(MPT2SAS_ERR_FMT "device is not present "
5115 "handle(0x%04x), flags!!!\n", ioc->name, handle);
5119 /* check if there were any issues with discovery */
5120 if (_scsih_check_access_status(ioc, sas_address, handle,
5121 sas_device_pg0.AccessStatus))
5123 _scsih_ublock_io_device(ioc, handle);
5128 * _scsih_add_device - creating sas device object
5129 * @ioc: per adapter object
5130 * @handle: sas device handle
5131 * @phy_num: phy number end device attached to
5132 * @is_pd: is this hidden raid component
5134 * Creating end device object, stored in ioc->sas_device_list.
5136 * Returns 0 for success, non-zero for failure.
5139 _scsih_add_device(struct MPT2SAS_ADAPTER *ioc, u16 handle, u8 phy_num, u8 is_pd)
5141 Mpi2ConfigReply_t mpi_reply;
5142 Mpi2SasDevicePage0_t sas_device_pg0;
5143 Mpi2SasEnclosurePage0_t enclosure_pg0;
5144 struct _sas_device *sas_device;
5148 unsigned long flags;
5150 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5151 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
5152 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5153 ioc->name, __FILE__, __LINE__, __func__);
5157 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
5158 MPI2_IOCSTATUS_MASK;
5159 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5160 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5161 ioc->name, __FILE__, __LINE__, __func__);
5165 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
5167 /* check if device is present */
5168 if (!(le16_to_cpu(sas_device_pg0.Flags) &
5169 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
5170 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5171 ioc->name, __FILE__, __LINE__, __func__);
5172 printk(MPT2SAS_ERR_FMT "Flags = 0x%04x\n",
5173 ioc->name, le16_to_cpu(sas_device_pg0.Flags));
5177 /* check if there were any issues with discovery */
5178 if (_scsih_check_access_status(ioc, sas_address, handle,
5179 sas_device_pg0.AccessStatus))
5182 /* check if this is end device */
5183 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
5184 if (!(_scsih_is_end_device(device_info))) {
5185 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5186 ioc->name, __FILE__, __LINE__, __func__);
5191 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5192 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5194 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5199 sas_device = kzalloc(sizeof(struct _sas_device),
5202 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5203 ioc->name, __FILE__, __LINE__, __func__);
5207 sas_device->handle = handle;
5208 if (_scsih_get_sas_address(ioc, le16_to_cpu
5209 (sas_device_pg0.ParentDevHandle),
5210 &sas_device->sas_address_parent) != 0)
5211 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5212 ioc->name, __FILE__, __LINE__, __func__);
5213 sas_device->enclosure_handle =
5214 le16_to_cpu(sas_device_pg0.EnclosureHandle);
5216 le16_to_cpu(sas_device_pg0.Slot);
5217 sas_device->device_info = device_info;
5218 sas_device->sas_address = sas_address;
5219 sas_device->phy = sas_device_pg0.PhyNum;
5221 /* get enclosure_logical_id */
5222 if (sas_device->enclosure_handle && !(mpt2sas_config_get_enclosure_pg0(
5223 ioc, &mpi_reply, &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
5224 sas_device->enclosure_handle)))
5225 sas_device->enclosure_logical_id =
5226 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
5228 /* get device name */
5229 sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName);
5231 if (ioc->wait_for_discovery_to_complete)
5232 _scsih_sas_device_init_add(ioc, sas_device);
5234 _scsih_sas_device_add(ioc, sas_device);
5240 * _scsih_remove_device - removing sas device object
5241 * @ioc: per adapter object
5242 * @sas_device_delete: the sas_device object
5247 _scsih_remove_device(struct MPT2SAS_ADAPTER *ioc,
5248 struct _sas_device *sas_device)
5250 struct _sas_device sas_device_backup;
5251 struct MPT2SAS_TARGET *sas_target_priv_data;
5256 memcpy(&sas_device_backup, sas_device, sizeof(struct _sas_device));
5257 _scsih_sas_device_remove(ioc, sas_device);
5259 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter: "
5260 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
5261 sas_device_backup.handle, (unsigned long long)
5262 sas_device_backup.sas_address));
5264 if (sas_device_backup.starget && sas_device_backup.starget->hostdata) {
5265 sas_target_priv_data = sas_device_backup.starget->hostdata;
5266 sas_target_priv_data->deleted = 1;
5267 _scsih_ublock_io_device(ioc, sas_device_backup.handle);
5268 sas_target_priv_data->handle =
5269 MPT2SAS_INVALID_DEVICE_HANDLE;
5272 _scsih_ublock_io_device(ioc, sas_device_backup.handle);
5274 if (!ioc->hide_drives)
5275 mpt2sas_transport_port_remove(ioc,
5276 sas_device_backup.sas_address,
5277 sas_device_backup.sas_address_parent);
5279 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), sas_addr"
5280 "(0x%016llx)\n", ioc->name, sas_device_backup.handle,
5281 (unsigned long long) sas_device_backup.sas_address);
5283 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: exit: "
5284 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
5285 sas_device_backup.handle, (unsigned long long)
5286 sas_device_backup.sas_address));
5290 * mpt2sas_device_remove - removing device object
5291 * @ioc: per adapter object
5292 * @sas_address: expander sas_address
5297 mpt2sas_device_remove(struct MPT2SAS_ADAPTER *ioc, u64 sas_address)
5299 struct _sas_device *sas_device;
5300 unsigned long flags;
5302 if (ioc->shost_recovery)
5305 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5306 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5309 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5312 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5313 _scsih_remove_device(ioc, sas_device);
5316 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5318 * _scsih_sas_topology_change_event_debug - debug for topology event
5319 * @ioc: per adapter object
5320 * @event_data: event data payload
5324 _scsih_sas_topology_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
5325 Mpi2EventDataSasTopologyChangeList_t *event_data)
5331 char *status_str = NULL;
5332 u8 link_rate, prev_link_rate;
5334 switch (event_data->ExpStatus) {
5335 case MPI2_EVENT_SAS_TOPO_ES_ADDED:
5338 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING:
5339 status_str = "remove";
5341 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING:
5343 status_str = "responding";
5345 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING:
5346 status_str = "remove delay";
5349 status_str = "unknown status";
5352 printk(MPT2SAS_INFO_FMT "sas topology change: (%s)\n",
5353 ioc->name, status_str);
5354 printk(KERN_INFO "\thandle(0x%04x), enclosure_handle(0x%04x) "
5355 "start_phy(%02d), count(%d)\n",
5356 le16_to_cpu(event_data->ExpanderDevHandle),
5357 le16_to_cpu(event_data->EnclosureHandle),
5358 event_data->StartPhyNum, event_data->NumEntries);
5359 for (i = 0; i < event_data->NumEntries; i++) {
5360 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5363 phy_number = event_data->StartPhyNum + i;
5364 reason_code = event_data->PHY[i].PhyStatus &
5365 MPI2_EVENT_SAS_TOPO_RC_MASK;
5366 switch (reason_code) {
5367 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
5368 status_str = "target add";
5370 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
5371 status_str = "target remove";
5373 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING:
5374 status_str = "delay target remove";
5376 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
5377 status_str = "link rate change";
5379 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE:
5380 status_str = "target responding";
5383 status_str = "unknown";
5386 link_rate = event_data->PHY[i].LinkRate >> 4;
5387 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
5388 printk(KERN_INFO "\tphy(%02d), attached_handle(0x%04x): %s:"
5389 " link rate: new(0x%02x), old(0x%02x)\n", phy_number,
5390 handle, status_str, link_rate, prev_link_rate);
5397 * _scsih_sas_topology_change_event - handle topology changes
5398 * @ioc: per adapter object
5399 * @fw_event: The fw_event_work object
5404 _scsih_sas_topology_change_event(struct MPT2SAS_ADAPTER *ioc,
5405 struct fw_event_work *fw_event)
5408 u16 parent_handle, handle;
5410 u8 phy_number, max_phys;
5411 struct _sas_node *sas_expander;
5412 struct _sas_device *sas_device;
5414 unsigned long flags;
5415 u8 link_rate, prev_link_rate;
5416 Mpi2EventDataSasTopologyChangeList_t *event_data = fw_event->event_data;
5418 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5419 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5420 _scsih_sas_topology_change_event_debug(ioc, event_data);
5423 if (ioc->remove_host || ioc->pci_error_recovery)
5426 if (!ioc->sas_hba.num_phys)
5427 _scsih_sas_host_add(ioc);
5429 _scsih_sas_host_refresh(ioc);
5431 if (fw_event->ignore) {
5432 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "ignoring expander "
5433 "event\n", ioc->name));
5437 parent_handle = le16_to_cpu(event_data->ExpanderDevHandle);
5439 /* handle expander add */
5440 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_ADDED)
5441 if (_scsih_expander_add(ioc, parent_handle) != 0)
5444 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5445 sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc,
5447 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5449 sas_address = sas_expander->sas_address;
5450 max_phys = sas_expander->num_phys;
5451 } else if (parent_handle < ioc->sas_hba.num_phys) {
5452 sas_address = ioc->sas_hba.sas_address;
5453 max_phys = ioc->sas_hba.num_phys;
5457 /* handle siblings events */
5458 for (i = 0; i < event_data->NumEntries; i++) {
5459 if (fw_event->ignore) {
5460 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "ignoring "
5461 "expander event\n", ioc->name));
5464 if (ioc->shost_recovery || ioc->remove_host ||
5465 ioc->pci_error_recovery)
5467 phy_number = event_data->StartPhyNum + i;
5468 if (phy_number >= max_phys)
5470 reason_code = event_data->PHY[i].PhyStatus &
5471 MPI2_EVENT_SAS_TOPO_RC_MASK;
5472 if ((event_data->PHY[i].PhyStatus &
5473 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT) && (reason_code !=
5474 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING))
5476 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5479 link_rate = event_data->PHY[i].LinkRate >> 4;
5480 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
5481 switch (reason_code) {
5482 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
5484 if (ioc->shost_recovery)
5487 if (link_rate == prev_link_rate)
5490 mpt2sas_transport_update_links(ioc, sas_address,
5491 handle, phy_number, link_rate);
5493 if (link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
5496 _scsih_check_device(ioc, handle);
5498 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
5500 if (ioc->shost_recovery)
5503 mpt2sas_transport_update_links(ioc, sas_address,
5504 handle, phy_number, link_rate);
5506 _scsih_add_device(ioc, handle, phy_number, 0);
5508 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
5510 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5511 sas_device = _scsih_sas_device_find_by_handle(ioc,
5514 spin_unlock_irqrestore(&ioc->sas_device_lock,
5518 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5519 _scsih_remove_device(ioc, sas_device);
5524 /* handle expander removal */
5525 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING &&
5527 mpt2sas_expander_remove(ioc, sas_address);
5531 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5533 * _scsih_sas_device_status_change_event_debug - debug for device event
5534 * @event_data: event data payload
5540 _scsih_sas_device_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
5541 Mpi2EventDataSasDeviceStatusChange_t *event_data)
5543 char *reason_str = NULL;
5545 switch (event_data->ReasonCode) {
5546 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
5547 reason_str = "smart data";
5549 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED:
5550 reason_str = "unsupported device discovered";
5552 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
5553 reason_str = "internal device reset";
5555 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL:
5556 reason_str = "internal task abort";
5558 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL:
5559 reason_str = "internal task abort set";
5561 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL:
5562 reason_str = "internal clear task set";
5564 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL:
5565 reason_str = "internal query task";
5567 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE:
5568 reason_str = "sata init failure";
5570 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET:
5571 reason_str = "internal device reset complete";
5573 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL:
5574 reason_str = "internal task abort complete";
5576 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION:
5577 reason_str = "internal async notification";
5579 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY:
5580 reason_str = "expander reduced functionality";
5582 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY:
5583 reason_str = "expander reduced functionality complete";
5586 reason_str = "unknown reason";
5589 printk(MPT2SAS_INFO_FMT "device status change: (%s)\n"
5590 "\thandle(0x%04x), sas address(0x%016llx), tag(%d)",
5591 ioc->name, reason_str, le16_to_cpu(event_data->DevHandle),
5592 (unsigned long long)le64_to_cpu(event_data->SASAddress),
5593 le16_to_cpu(event_data->TaskTag));
5594 if (event_data->ReasonCode == MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA)
5595 printk(MPT2SAS_INFO_FMT ", ASC(0x%x), ASCQ(0x%x)\n", ioc->name,
5596 event_data->ASC, event_data->ASCQ);
5597 printk(KERN_INFO "\n");
5602 * _scsih_sas_device_status_change_event - handle device status change
5603 * @ioc: per adapter object
5604 * @fw_event: The fw_event_work object
5610 _scsih_sas_device_status_change_event(struct MPT2SAS_ADAPTER *ioc,
5611 struct fw_event_work *fw_event)
5613 struct MPT2SAS_TARGET *target_priv_data;
5614 struct _sas_device *sas_device;
5616 unsigned long flags;
5617 Mpi2EventDataSasDeviceStatusChange_t *event_data =
5618 fw_event->event_data;
5620 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5621 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5622 _scsih_sas_device_status_change_event_debug(ioc,
5626 /* In MPI Revision K (0xC), the internal device reset complete was
5627 * implemented, so avoid setting tm_busy flag for older firmware.
5629 if ((ioc->facts.HeaderVersion >> 8) < 0xC)
5632 if (event_data->ReasonCode !=
5633 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET &&
5634 event_data->ReasonCode !=
5635 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET)
5638 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5639 sas_address = le64_to_cpu(event_data->SASAddress);
5640 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5642 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5644 if (!sas_device || !sas_device->starget)
5647 target_priv_data = sas_device->starget->hostdata;
5648 if (!target_priv_data)
5651 if (event_data->ReasonCode ==
5652 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET)
5653 target_priv_data->tm_busy = 1;
5655 target_priv_data->tm_busy = 0;
5658 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5660 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure event
5661 * @ioc: per adapter object
5662 * @event_data: event data payload
5668 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
5669 Mpi2EventDataSasEnclDevStatusChange_t *event_data)
5671 char *reason_str = NULL;
5673 switch (event_data->ReasonCode) {
5674 case MPI2_EVENT_SAS_ENCL_RC_ADDED:
5675 reason_str = "enclosure add";
5677 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING:
5678 reason_str = "enclosure remove";
5681 reason_str = "unknown reason";
5685 printk(MPT2SAS_INFO_FMT "enclosure status change: (%s)\n"
5686 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
5687 " number slots(%d)\n", ioc->name, reason_str,
5688 le16_to_cpu(event_data->EnclosureHandle),
5689 (unsigned long long)le64_to_cpu(event_data->EnclosureLogicalID),
5690 le16_to_cpu(event_data->StartSlot));
5695 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
5696 * @ioc: per adapter object
5697 * @fw_event: The fw_event_work object
5703 _scsih_sas_enclosure_dev_status_change_event(struct MPT2SAS_ADAPTER *ioc,
5704 struct fw_event_work *fw_event)
5706 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5707 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5708 _scsih_sas_enclosure_dev_status_change_event_debug(ioc,
5709 fw_event->event_data);
5714 * _scsih_sas_broadcast_primative_event - handle broadcast events
5715 * @ioc: per adapter object
5716 * @fw_event: The fw_event_work object
5722 _scsih_sas_broadcast_primative_event(struct MPT2SAS_ADAPTER *ioc,
5723 struct fw_event_work *fw_event)
5725 struct scsi_cmnd *scmd;
5726 struct scsi_device *sdev;
5729 struct MPT2SAS_DEVICE *sas_device_priv_data;
5730 u32 termination_count;
5732 Mpi2SCSITaskManagementReply_t *mpi_reply;
5733 Mpi2EventDataSasBroadcastPrimitive_t *event_data = fw_event->event_data;
5735 unsigned long flags;
5738 u8 task_abort_retries;
5740 mutex_lock(&ioc->tm_cmds.mutex);
5741 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter: phy number(%d), "
5742 "width(%d)\n", ioc->name, __func__, event_data->PhyNum,
5743 event_data->PortWidth));
5745 _scsih_block_io_all_device(ioc);
5747 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5748 mpi_reply = ioc->tm_cmds.reply;
5749 broadcast_aen_retry:
5751 /* sanity checks for retrying this loop */
5752 if (max_retries++ == 5) {
5753 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: giving up\n",
5754 ioc->name, __func__));
5756 } else if (max_retries > 1)
5757 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: %d retry\n",
5758 ioc->name, __func__, max_retries - 1));
5760 termination_count = 0;
5762 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
5763 if (ioc->shost_recovery)
5765 scmd = _scsih_scsi_lookup_get(ioc, smid);
5768 sdev = scmd->device;
5769 sas_device_priv_data = sdev->hostdata;
5770 if (!sas_device_priv_data || !sas_device_priv_data->sas_target)
5772 /* skip hidden raid components */
5773 if (sas_device_priv_data->sas_target->flags &
5774 MPT_TARGET_FLAGS_RAID_COMPONENT)
5777 if (sas_device_priv_data->sas_target->flags &
5778 MPT_TARGET_FLAGS_VOLUME)
5781 handle = sas_device_priv_data->sas_target->handle;
5782 lun = sas_device_priv_data->lun;
5785 if (ioc->shost_recovery)
5788 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
5789 r = mpt2sas_scsih_issue_tm(ioc, handle, 0, 0, lun,
5790 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, smid, 30, 0,
5793 sdev_printk(KERN_WARNING, sdev,
5794 "mpt2sas_scsih_issue_tm: FAILED when sending "
5795 "QUERY_TASK: scmd(%p)\n", scmd);
5796 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5797 goto broadcast_aen_retry;
5799 ioc_status = le16_to_cpu(mpi_reply->IOCStatus)
5800 & MPI2_IOCSTATUS_MASK;
5801 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5802 sdev_printk(KERN_WARNING, sdev, "query task: FAILED "
5803 "with IOCSTATUS(0x%04x), scmd(%p)\n", ioc_status,
5805 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5806 goto broadcast_aen_retry;
5809 /* see if IO is still owned by IOC and target */
5810 if (mpi_reply->ResponseCode ==
5811 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED ||
5812 mpi_reply->ResponseCode ==
5813 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC) {
5814 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5817 task_abort_retries = 0;
5819 if (task_abort_retries++ == 60) {
5820 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
5821 "%s: ABORT_TASK: giving up\n", ioc->name,
5823 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5824 goto broadcast_aen_retry;
5827 if (ioc->shost_recovery)
5830 r = mpt2sas_scsih_issue_tm(ioc, handle, sdev->channel, sdev->id,
5831 sdev->lun, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30,
5832 scmd->serial_number, TM_MUTEX_OFF);
5834 sdev_printk(KERN_WARNING, sdev,
5835 "mpt2sas_scsih_issue_tm: ABORT_TASK: FAILED : "
5836 "scmd(%p)\n", scmd);
5840 if (task_abort_retries > 1)
5841 sdev_printk(KERN_WARNING, sdev,
5842 "mpt2sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):"
5844 task_abort_retries - 1, scmd);
5846 termination_count += le32_to_cpu(mpi_reply->TerminationCount);
5847 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5850 if (ioc->broadcast_aen_pending) {
5851 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: loop back due to"
5852 " pending AEN\n", ioc->name, __func__));
5853 ioc->broadcast_aen_pending = 0;
5854 goto broadcast_aen_retry;
5858 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
5861 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
5862 "%s - exit, query_count = %d termination_count = %d\n",
5863 ioc->name, __func__, query_count, termination_count));
5865 ioc->broadcast_aen_busy = 0;
5866 if (!ioc->shost_recovery)
5867 _scsih_ublock_io_all_device(ioc);
5868 mutex_unlock(&ioc->tm_cmds.mutex);
5872 * _scsih_sas_discovery_event - handle discovery events
5873 * @ioc: per adapter object
5874 * @fw_event: The fw_event_work object
5880 _scsih_sas_discovery_event(struct MPT2SAS_ADAPTER *ioc,
5881 struct fw_event_work *fw_event)
5883 Mpi2EventDataSasDiscovery_t *event_data = fw_event->event_data;
5885 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5886 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) {
5887 printk(MPT2SAS_INFO_FMT "discovery event: (%s)", ioc->name,
5888 (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ?
5890 if (event_data->DiscoveryStatus)
5891 printk("discovery_status(0x%08x)",
5892 le32_to_cpu(event_data->DiscoveryStatus));
5897 if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED &&
5898 !ioc->sas_hba.num_phys)
5899 _scsih_sas_host_add(ioc);
5903 * _scsih_reprobe_lun - reprobing lun
5904 * @sdev: scsi device struct
5905 * @no_uld_attach: sdev->no_uld_attach flag setting
5909 _scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach)
5913 sdev->no_uld_attach = no_uld_attach ? 1 : 0;
5914 sdev_printk(KERN_INFO, sdev, "%s raid component\n",
5915 sdev->no_uld_attach ? "hidding" : "exposing");
5916 rc = scsi_device_reprobe(sdev);
5920 * _scsih_reprobe_target - reprobing target
5921 * @starget: scsi target struct
5922 * @no_uld_attach: sdev->no_uld_attach flag setting
5924 * Note: no_uld_attach flag determines whether the disk device is attached
5925 * to block layer. A value of `1` means to not attach.
5928 _scsih_reprobe_target(struct scsi_target *starget, int no_uld_attach)
5930 struct MPT2SAS_TARGET *sas_target_priv_data;
5932 if (starget == NULL)
5934 sas_target_priv_data = starget->hostdata;
5936 sas_target_priv_data->flags |= MPT_TARGET_FLAGS_RAID_COMPONENT;
5938 sas_target_priv_data->flags &= ~MPT_TARGET_FLAGS_RAID_COMPONENT;
5940 starget_for_each_device(starget, no_uld_attach ? (void *)1 : NULL,
5941 _scsih_reprobe_lun);
5944 * _scsih_sas_volume_add - add new volume
5945 * @ioc: per adapter object
5946 * @element: IR config element data
5952 _scsih_sas_volume_add(struct MPT2SAS_ADAPTER *ioc,
5953 Mpi2EventIrConfigElement_t *element)
5955 struct _raid_device *raid_device;
5956 unsigned long flags;
5958 u16 handle = le16_to_cpu(element->VolDevHandle);
5961 mpt2sas_config_get_volume_wwid(ioc, handle, &wwid);
5963 printk(MPT2SAS_ERR_FMT
5964 "failure at %s:%d/%s()!\n", ioc->name,
5965 __FILE__, __LINE__, __func__);
5969 spin_lock_irqsave(&ioc->raid_device_lock, flags);
5970 raid_device = _scsih_raid_device_find_by_wwid(ioc, wwid);
5971 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
5976 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
5978 printk(MPT2SAS_ERR_FMT
5979 "failure at %s:%d/%s()!\n", ioc->name,
5980 __FILE__, __LINE__, __func__);
5984 raid_device->id = ioc->sas_id++;
5985 raid_device->channel = RAID_CHANNEL;
5986 raid_device->handle = handle;
5987 raid_device->wwid = wwid;
5988 _scsih_raid_device_add(ioc, raid_device);
5989 if (!ioc->wait_for_discovery_to_complete) {
5990 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
5991 raid_device->id, 0);
5993 _scsih_raid_device_remove(ioc, raid_device);
5995 _scsih_determine_boot_device(ioc, raid_device, 1);
5999 * _scsih_sas_volume_delete - delete volume
6000 * @ioc: per adapter object
6001 * @handle: volume device handle
6007 _scsih_sas_volume_delete(struct MPT2SAS_ADAPTER *ioc, u16 handle)
6009 struct _raid_device *raid_device;
6010 unsigned long flags;
6011 struct MPT2SAS_TARGET *sas_target_priv_data;
6013 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6014 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
6015 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6018 if (raid_device->starget) {
6019 sas_target_priv_data = raid_device->starget->hostdata;
6020 sas_target_priv_data->deleted = 1;
6021 scsi_remove_target(&raid_device->starget->dev);
6023 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), wwid"
6024 "(0x%016llx)\n", ioc->name, raid_device->handle,
6025 (unsigned long long) raid_device->wwid);
6026 _scsih_raid_device_remove(ioc, raid_device);
6030 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
6031 * @ioc: per adapter object
6032 * @element: IR config element data
6038 _scsih_sas_pd_expose(struct MPT2SAS_ADAPTER *ioc,
6039 Mpi2EventIrConfigElement_t *element)
6041 struct _sas_device *sas_device;
6042 unsigned long flags;
6043 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6045 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6046 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6047 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6051 /* exposing raid component */
6052 sas_device->volume_handle = 0;
6053 sas_device->volume_wwid = 0;
6054 clear_bit(handle, ioc->pd_handles);
6055 _scsih_reprobe_target(sas_device->starget, 0);
6059 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
6060 * @ioc: per adapter object
6061 * @element: IR config element data
6067 _scsih_sas_pd_hide(struct MPT2SAS_ADAPTER *ioc,
6068 Mpi2EventIrConfigElement_t *element)
6070 struct _sas_device *sas_device;
6071 unsigned long flags;
6072 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6074 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6075 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6076 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6080 /* hiding raid component */
6081 mpt2sas_config_get_volume_handle(ioc, handle,
6082 &sas_device->volume_handle);
6083 mpt2sas_config_get_volume_wwid(ioc, sas_device->volume_handle,
6084 &sas_device->volume_wwid);
6085 set_bit(handle, ioc->pd_handles);
6086 _scsih_reprobe_target(sas_device->starget, 1);
6091 * _scsih_sas_pd_delete - delete pd component
6092 * @ioc: per adapter object
6093 * @element: IR config element data
6099 _scsih_sas_pd_delete(struct MPT2SAS_ADAPTER *ioc,
6100 Mpi2EventIrConfigElement_t *element)
6102 struct _sas_device *sas_device;
6103 unsigned long flags;
6104 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6106 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6107 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6108 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6111 _scsih_remove_device(ioc, sas_device);
6115 * _scsih_sas_pd_add - remove pd component
6116 * @ioc: per adapter object
6117 * @element: IR config element data
6123 _scsih_sas_pd_add(struct MPT2SAS_ADAPTER *ioc,
6124 Mpi2EventIrConfigElement_t *element)
6126 struct _sas_device *sas_device;
6127 unsigned long flags;
6128 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6129 Mpi2ConfigReply_t mpi_reply;
6130 Mpi2SasDevicePage0_t sas_device_pg0;
6135 set_bit(handle, ioc->pd_handles);
6137 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6138 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6139 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6143 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
6144 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
6145 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6146 ioc->name, __FILE__, __LINE__, __func__);
6150 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6151 MPI2_IOCSTATUS_MASK;
6152 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6153 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6154 ioc->name, __FILE__, __LINE__, __func__);
6158 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6159 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
6160 mpt2sas_transport_update_links(ioc, sas_address, handle,
6161 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
6163 _scsih_add_device(ioc, handle, 0, 1);
6166 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6168 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
6169 * @ioc: per adapter object
6170 * @event_data: event data payload
6176 _scsih_sas_ir_config_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
6177 Mpi2EventDataIrConfigChangeList_t *event_data)
6179 Mpi2EventIrConfigElement_t *element;
6182 char *reason_str = NULL, *element_str = NULL;
6184 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
6186 printk(MPT2SAS_INFO_FMT "raid config change: (%s), elements(%d)\n",
6187 ioc->name, (le32_to_cpu(event_data->Flags) &
6188 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ?
6189 "foreign" : "native", event_data->NumElements);
6190 for (i = 0; i < event_data->NumElements; i++, element++) {
6191 switch (element->ReasonCode) {
6192 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
6195 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
6196 reason_str = "remove";
6198 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE:
6199 reason_str = "no change";
6201 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
6202 reason_str = "hide";
6204 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
6205 reason_str = "unhide";
6207 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
6208 reason_str = "volume_created";
6210 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
6211 reason_str = "volume_deleted";
6213 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
6214 reason_str = "pd_created";
6216 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
6217 reason_str = "pd_deleted";
6220 reason_str = "unknown reason";
6223 element_type = le16_to_cpu(element->ElementFlags) &
6224 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK;
6225 switch (element_type) {
6226 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT:
6227 element_str = "volume";
6229 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT:
6230 element_str = "phys disk";
6232 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT:
6233 element_str = "hot spare";
6236 element_str = "unknown element";
6239 printk(KERN_INFO "\t(%s:%s), vol handle(0x%04x), "
6240 "pd handle(0x%04x), pd num(0x%02x)\n", element_str,
6241 reason_str, le16_to_cpu(element->VolDevHandle),
6242 le16_to_cpu(element->PhysDiskDevHandle),
6243 element->PhysDiskNum);
6249 * _scsih_sas_ir_config_change_event - handle ir configuration change events
6250 * @ioc: per adapter object
6251 * @fw_event: The fw_event_work object
6257 _scsih_sas_ir_config_change_event(struct MPT2SAS_ADAPTER *ioc,
6258 struct fw_event_work *fw_event)
6260 Mpi2EventIrConfigElement_t *element;
6263 Mpi2EventDataIrConfigChangeList_t *event_data = fw_event->event_data;
6265 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6266 if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6267 && !ioc->hide_ir_msg)
6268 _scsih_sas_ir_config_change_event_debug(ioc, event_data);
6272 if (ioc->shost_recovery)
6275 foreign_config = (le32_to_cpu(event_data->Flags) &
6276 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0;
6278 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
6279 for (i = 0; i < event_data->NumElements; i++, element++) {
6281 switch (element->ReasonCode) {
6282 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
6283 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
6284 if (!foreign_config)
6285 _scsih_sas_volume_add(ioc, element);
6287 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
6288 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
6289 if (!foreign_config)
6290 _scsih_sas_volume_delete(ioc,
6291 le16_to_cpu(element->VolDevHandle));
6293 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
6294 if (!ioc->is_warpdrive)
6295 _scsih_sas_pd_hide(ioc, element);
6297 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
6298 if (!ioc->is_warpdrive)
6299 _scsih_sas_pd_expose(ioc, element);
6301 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
6302 if (!ioc->is_warpdrive)
6303 _scsih_sas_pd_add(ioc, element);
6305 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
6306 if (!ioc->is_warpdrive)
6307 _scsih_sas_pd_delete(ioc, element);
6314 * _scsih_sas_ir_volume_event - IR volume event
6315 * @ioc: per adapter object
6316 * @fw_event: The fw_event_work object
6322 _scsih_sas_ir_volume_event(struct MPT2SAS_ADAPTER *ioc,
6323 struct fw_event_work *fw_event)
6326 unsigned long flags;
6327 struct _raid_device *raid_device;
6331 Mpi2EventDataIrVolume_t *event_data = fw_event->event_data;
6333 if (ioc->shost_recovery)
6336 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
6339 handle = le16_to_cpu(event_data->VolDevHandle);
6340 state = le32_to_cpu(event_data->NewValue);
6341 if (!ioc->hide_ir_msg)
6342 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle(0x%04x), "
6343 "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle,
6344 le32_to_cpu(event_data->PreviousValue), state));
6347 case MPI2_RAID_VOL_STATE_MISSING:
6348 case MPI2_RAID_VOL_STATE_FAILED:
6349 _scsih_sas_volume_delete(ioc, handle);
6352 case MPI2_RAID_VOL_STATE_ONLINE:
6353 case MPI2_RAID_VOL_STATE_DEGRADED:
6354 case MPI2_RAID_VOL_STATE_OPTIMAL:
6356 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6357 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
6358 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6363 mpt2sas_config_get_volume_wwid(ioc, handle, &wwid);
6365 printk(MPT2SAS_ERR_FMT
6366 "failure at %s:%d/%s()!\n", ioc->name,
6367 __FILE__, __LINE__, __func__);
6371 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
6373 printk(MPT2SAS_ERR_FMT
6374 "failure at %s:%d/%s()!\n", ioc->name,
6375 __FILE__, __LINE__, __func__);
6379 raid_device->id = ioc->sas_id++;
6380 raid_device->channel = RAID_CHANNEL;
6381 raid_device->handle = handle;
6382 raid_device->wwid = wwid;
6383 _scsih_raid_device_add(ioc, raid_device);
6384 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
6385 raid_device->id, 0);
6387 _scsih_raid_device_remove(ioc, raid_device);
6390 case MPI2_RAID_VOL_STATE_INITIALIZING:
6397 * _scsih_sas_ir_physical_disk_event - PD event
6398 * @ioc: per adapter object
6399 * @fw_event: The fw_event_work object
6405 _scsih_sas_ir_physical_disk_event(struct MPT2SAS_ADAPTER *ioc,
6406 struct fw_event_work *fw_event)
6408 u16 handle, parent_handle;
6410 struct _sas_device *sas_device;
6411 unsigned long flags;
6412 Mpi2ConfigReply_t mpi_reply;
6413 Mpi2SasDevicePage0_t sas_device_pg0;
6415 Mpi2EventDataIrPhysicalDisk_t *event_data = fw_event->event_data;
6418 if (ioc->shost_recovery)
6421 if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED)
6424 handle = le16_to_cpu(event_data->PhysDiskDevHandle);
6425 state = le32_to_cpu(event_data->NewValue);
6427 if (!ioc->hide_ir_msg)
6428 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle(0x%04x), "
6429 "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle,
6430 le32_to_cpu(event_data->PreviousValue), state));
6433 case MPI2_RAID_PD_STATE_ONLINE:
6434 case MPI2_RAID_PD_STATE_DEGRADED:
6435 case MPI2_RAID_PD_STATE_REBUILDING:
6436 case MPI2_RAID_PD_STATE_OPTIMAL:
6437 case MPI2_RAID_PD_STATE_HOT_SPARE:
6439 if (!ioc->is_warpdrive)
6440 set_bit(handle, ioc->pd_handles);
6442 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6443 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6444 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6449 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6450 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
6452 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6453 ioc->name, __FILE__, __LINE__, __func__);
6457 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6458 MPI2_IOCSTATUS_MASK;
6459 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6460 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6461 ioc->name, __FILE__, __LINE__, __func__);
6465 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6466 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
6467 mpt2sas_transport_update_links(ioc, sas_address, handle,
6468 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
6470 _scsih_add_device(ioc, handle, 0, 1);
6474 case MPI2_RAID_PD_STATE_OFFLINE:
6475 case MPI2_RAID_PD_STATE_NOT_CONFIGURED:
6476 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE:
6482 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6484 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
6485 * @ioc: per adapter object
6486 * @event_data: event data payload
6492 _scsih_sas_ir_operation_status_event_debug(struct MPT2SAS_ADAPTER *ioc,
6493 Mpi2EventDataIrOperationStatus_t *event_data)
6495 char *reason_str = NULL;
6497 switch (event_data->RAIDOperation) {
6498 case MPI2_EVENT_IR_RAIDOP_RESYNC:
6499 reason_str = "resync";
6501 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION:
6502 reason_str = "online capacity expansion";
6504 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK:
6505 reason_str = "consistency check";
6507 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT:
6508 reason_str = "background init";
6510 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT:
6511 reason_str = "make data consistent";
6518 printk(MPT2SAS_INFO_FMT "raid operational status: (%s)"
6519 "\thandle(0x%04x), percent complete(%d)\n",
6520 ioc->name, reason_str,
6521 le16_to_cpu(event_data->VolDevHandle),
6522 event_data->PercentComplete);
6527 * _scsih_sas_ir_operation_status_event - handle RAID operation events
6528 * @ioc: per adapter object
6529 * @fw_event: The fw_event_work object
6535 _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
6536 struct fw_event_work *fw_event)
6538 Mpi2EventDataIrOperationStatus_t *event_data = fw_event->event_data;
6539 static struct _raid_device *raid_device;
6540 unsigned long flags;
6543 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6544 if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6545 && !ioc->hide_ir_msg)
6546 _scsih_sas_ir_operation_status_event_debug(ioc,
6550 /* code added for raid transport support */
6551 if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC) {
6553 handle = le16_to_cpu(event_data->VolDevHandle);
6555 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6556 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
6557 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6562 if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC)
6563 raid_device->percent_complete =
6564 event_data->PercentComplete;
6569 * _scsih_prep_device_scan - initialize parameters prior to device scan
6570 * @ioc: per adapter object
6572 * Set the deleted flag prior to device scan. If the device is found during
6573 * the scan, then we clear the deleted flag.
6576 _scsih_prep_device_scan(struct MPT2SAS_ADAPTER *ioc)
6578 struct MPT2SAS_DEVICE *sas_device_priv_data;
6579 struct scsi_device *sdev;
6581 shost_for_each_device(sdev, ioc->shost) {
6582 sas_device_priv_data = sdev->hostdata;
6583 if (sas_device_priv_data && sas_device_priv_data->sas_target)
6584 sas_device_priv_data->sas_target->deleted = 1;
6589 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
6590 * @ioc: per adapter object
6591 * @sas_address: sas address
6592 * @slot: enclosure slot id
6593 * @handle: device handle
6595 * After host reset, find out whether devices are still responding.
6596 * Used in _scsi_remove_unresponsive_sas_devices.
6601 _scsih_mark_responding_sas_device(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
6602 u16 slot, u16 handle)
6604 struct MPT2SAS_TARGET *sas_target_priv_data = NULL;
6605 struct scsi_target *starget;
6606 struct _sas_device *sas_device;
6607 unsigned long flags;
6609 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6610 list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
6611 if (sas_device->sas_address == sas_address &&
6612 sas_device->slot == slot) {
6613 sas_device->responding = 1;
6614 starget = sas_device->starget;
6615 if (starget && starget->hostdata) {
6616 sas_target_priv_data = starget->hostdata;
6617 sas_target_priv_data->tm_busy = 0;
6618 sas_target_priv_data->deleted = 0;
6620 sas_target_priv_data = NULL;
6622 starget_printk(KERN_INFO, starget,
6623 "handle(0x%04x), sas_addr(0x%016llx), "
6624 "enclosure logical id(0x%016llx), "
6625 "slot(%d)\n", handle,
6626 (unsigned long long)sas_device->sas_address,
6627 (unsigned long long)
6628 sas_device->enclosure_logical_id,
6630 if (sas_device->handle == handle)
6632 printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n",
6633 sas_device->handle);
6634 sas_device->handle = handle;
6635 if (sas_target_priv_data)
6636 sas_target_priv_data->handle = handle;
6641 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6645 * _scsih_search_responding_sas_devices -
6646 * @ioc: per adapter object
6648 * After host reset, find out whether devices are still responding.
6654 _scsih_search_responding_sas_devices(struct MPT2SAS_ADAPTER *ioc)
6656 Mpi2SasDevicePage0_t sas_device_pg0;
6657 Mpi2ConfigReply_t mpi_reply;
6664 printk(MPT2SAS_INFO_FMT "search for end-devices: start\n", ioc->name);
6666 if (list_empty(&ioc->sas_device_list))
6670 while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6671 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
6673 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6674 MPI2_IOCSTATUS_MASK;
6675 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
6677 handle = le16_to_cpu(sas_device_pg0.DevHandle);
6678 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
6679 if (!(_scsih_is_end_device(device_info)))
6681 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
6682 slot = le16_to_cpu(sas_device_pg0.Slot);
6683 _scsih_mark_responding_sas_device(ioc, sas_address, slot,
6687 printk(MPT2SAS_INFO_FMT "search for end-devices: complete\n",
6692 * _scsih_mark_responding_raid_device - mark a raid_device as responding
6693 * @ioc: per adapter object
6694 * @wwid: world wide identifier for raid volume
6695 * @handle: device handle
6697 * After host reset, find out whether devices are still responding.
6698 * Used in _scsi_remove_unresponsive_raid_devices.
6703 _scsih_mark_responding_raid_device(struct MPT2SAS_ADAPTER *ioc, u64 wwid,
6706 struct MPT2SAS_TARGET *sas_target_priv_data;
6707 struct scsi_target *starget;
6708 struct _raid_device *raid_device;
6709 unsigned long flags;
6711 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6712 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
6713 if (raid_device->wwid == wwid && raid_device->starget) {
6714 starget = raid_device->starget;
6715 if (starget && starget->hostdata) {
6716 sas_target_priv_data = starget->hostdata;
6717 sas_target_priv_data->deleted = 0;
6719 sas_target_priv_data = NULL;
6720 raid_device->responding = 1;
6721 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6722 starget_printk(KERN_INFO, raid_device->starget,
6723 "handle(0x%04x), wwid(0x%016llx)\n", handle,
6724 (unsigned long long)raid_device->wwid);
6726 * WARPDRIVE: The handles of the PDs might have changed
6727 * across the host reset so re-initialize the
6728 * required data for Direct IO
6730 _scsih_init_warpdrive_properties(ioc, raid_device);
6731 if (raid_device->handle == handle)
6733 printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n",
6734 raid_device->handle);
6735 raid_device->handle = handle;
6736 if (sas_target_priv_data)
6737 sas_target_priv_data->handle = handle;
6742 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6746 * _scsih_search_responding_raid_devices -
6747 * @ioc: per adapter object
6749 * After host reset, find out whether devices are still responding.
6755 _scsih_search_responding_raid_devices(struct MPT2SAS_ADAPTER *ioc)
6757 Mpi2RaidVolPage1_t volume_pg1;
6758 Mpi2RaidVolPage0_t volume_pg0;
6759 Mpi2RaidPhysDiskPage0_t pd_pg0;
6760 Mpi2ConfigReply_t mpi_reply;
6765 if (!ioc->ir_firmware)
6768 printk(MPT2SAS_INFO_FMT "search for raid volumes: start\n",
6771 if (list_empty(&ioc->raid_device_list))
6775 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
6776 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
6777 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6778 MPI2_IOCSTATUS_MASK;
6779 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
6781 handle = le16_to_cpu(volume_pg1.DevHandle);
6783 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
6784 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
6785 sizeof(Mpi2RaidVolPage0_t)))
6788 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
6789 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
6790 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED)
6791 _scsih_mark_responding_raid_device(ioc,
6792 le64_to_cpu(volume_pg1.WWID), handle);
6795 /* refresh the pd_handles */
6796 if (!ioc->is_warpdrive) {
6797 phys_disk_num = 0xFF;
6798 memset(ioc->pd_handles, 0, ioc->pd_handles_sz);
6799 while (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
6800 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
6802 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6803 MPI2_IOCSTATUS_MASK;
6804 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
6806 phys_disk_num = pd_pg0.PhysDiskNum;
6807 handle = le16_to_cpu(pd_pg0.DevHandle);
6808 set_bit(handle, ioc->pd_handles);
6812 printk(MPT2SAS_INFO_FMT "search for responding raid volumes: "
6813 "complete\n", ioc->name);
6817 * _scsih_mark_responding_expander - mark a expander as responding
6818 * @ioc: per adapter object
6819 * @sas_address: sas address
6822 * After host reset, find out whether devices are still responding.
6823 * Used in _scsi_remove_unresponsive_expanders.
6828 _scsih_mark_responding_expander(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
6831 struct _sas_node *sas_expander;
6832 unsigned long flags;
6835 spin_lock_irqsave(&ioc->sas_node_lock, flags);
6836 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
6837 if (sas_expander->sas_address != sas_address)
6839 sas_expander->responding = 1;
6840 if (sas_expander->handle == handle)
6842 printk(KERN_INFO "\texpander(0x%016llx): handle changed"
6843 " from(0x%04x) to (0x%04x)!!!\n",
6844 (unsigned long long)sas_expander->sas_address,
6845 sas_expander->handle, handle);
6846 sas_expander->handle = handle;
6847 for (i = 0 ; i < sas_expander->num_phys ; i++)
6848 sas_expander->phy[i].handle = handle;
6852 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
6856 * _scsih_search_responding_expanders -
6857 * @ioc: per adapter object
6859 * After host reset, find out whether devices are still responding.
6865 _scsih_search_responding_expanders(struct MPT2SAS_ADAPTER *ioc)
6867 Mpi2ExpanderPage0_t expander_pg0;
6868 Mpi2ConfigReply_t mpi_reply;
6873 printk(MPT2SAS_INFO_FMT "search for expanders: start\n", ioc->name);
6875 if (list_empty(&ioc->sas_expander_list))
6879 while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
6880 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
6882 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6883 MPI2_IOCSTATUS_MASK;
6884 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
6887 handle = le16_to_cpu(expander_pg0.DevHandle);
6888 sas_address = le64_to_cpu(expander_pg0.SASAddress);
6889 printk(KERN_INFO "\texpander present: handle(0x%04x), "
6890 "sas_addr(0x%016llx)\n", handle,
6891 (unsigned long long)sas_address);
6892 _scsih_mark_responding_expander(ioc, sas_address, handle);
6896 printk(MPT2SAS_INFO_FMT "search for expanders: complete\n", ioc->name);
6900 * _scsih_remove_unresponding_sas_devices - removing unresponding devices
6901 * @ioc: per adapter object
6906 _scsih_remove_unresponding_sas_devices(struct MPT2SAS_ADAPTER *ioc)
6908 struct _sas_device *sas_device, *sas_device_next;
6909 struct _sas_node *sas_expander;
6910 struct _raid_device *raid_device, *raid_device_next;
6912 printk(MPT2SAS_INFO_FMT "removing unresponding devices: start\n",
6915 list_for_each_entry_safe(sas_device, sas_device_next,
6916 &ioc->sas_device_list, list) {
6917 if (sas_device->responding) {
6918 sas_device->responding = 0;
6921 if (sas_device->starget)
6922 starget_printk(KERN_INFO, sas_device->starget,
6923 "removing: handle(0x%04x), sas_addr(0x%016llx), "
6924 "enclosure logical id(0x%016llx), slot(%d)\n",
6926 (unsigned long long)sas_device->sas_address,
6927 (unsigned long long)
6928 sas_device->enclosure_logical_id,
6930 _scsih_remove_device(ioc, sas_device);
6933 if (!ioc->ir_firmware)
6934 goto retry_expander_search;
6936 list_for_each_entry_safe(raid_device, raid_device_next,
6937 &ioc->raid_device_list, list) {
6938 if (raid_device->responding) {
6939 raid_device->responding = 0;
6942 if (raid_device->starget) {
6943 starget_printk(KERN_INFO, raid_device->starget,
6944 "removing: handle(0x%04x), wwid(0x%016llx)\n",
6945 raid_device->handle,
6946 (unsigned long long)raid_device->wwid);
6947 scsi_remove_target(&raid_device->starget->dev);
6949 _scsih_raid_device_remove(ioc, raid_device);
6952 retry_expander_search:
6953 sas_expander = NULL;
6954 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
6955 if (sas_expander->responding) {
6956 sas_expander->responding = 0;
6959 mpt2sas_expander_remove(ioc, sas_expander->sas_address);
6960 goto retry_expander_search;
6962 printk(MPT2SAS_INFO_FMT "removing unresponding devices: complete\n",
6964 /* unblock devices */
6965 _scsih_ublock_io_all_device(ioc);
6969 _scsih_refresh_expander_links(struct MPT2SAS_ADAPTER *ioc,
6970 struct _sas_node *sas_expander, u16 handle)
6972 Mpi2ExpanderPage1_t expander_pg1;
6973 Mpi2ConfigReply_t mpi_reply;
6976 for (i = 0 ; i < sas_expander->num_phys ; i++) {
6977 if ((mpt2sas_config_get_expander_pg1(ioc, &mpi_reply,
6978 &expander_pg1, i, handle))) {
6979 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6980 ioc->name, __FILE__, __LINE__, __func__);
6984 mpt2sas_transport_update_links(ioc, sas_expander->sas_address,
6985 le16_to_cpu(expander_pg1.AttachedDevHandle), i,
6986 expander_pg1.NegotiatedLinkRate >> 4);
6991 * _scsih_scan_for_devices_after_reset - scan for devices after host reset
6992 * @ioc: per adapter object
6997 _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
6999 Mpi2ExpanderPage0_t expander_pg0;
7000 Mpi2SasDevicePage0_t sas_device_pg0;
7001 Mpi2RaidVolPage1_t volume_pg1;
7002 Mpi2RaidVolPage0_t volume_pg0;
7003 Mpi2RaidPhysDiskPage0_t pd_pg0;
7004 Mpi2EventIrConfigElement_t element;
7005 Mpi2ConfigReply_t mpi_reply;
7008 u16 handle, parent_handle;
7010 struct _sas_device *sas_device;
7011 struct _sas_node *expander_device;
7012 static struct _raid_device *raid_device;
7014 printk(MPT2SAS_INFO_FMT "scan devices: start\n", ioc->name);
7016 _scsih_sas_host_refresh(ioc);
7020 while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
7021 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
7022 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7023 MPI2_IOCSTATUS_MASK;
7024 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
7026 handle = le16_to_cpu(expander_pg0.DevHandle);
7027 expander_device = mpt2sas_scsih_expander_find_by_sas_address(
7028 ioc, le64_to_cpu(expander_pg0.SASAddress));
7029 if (expander_device)
7030 _scsih_refresh_expander_links(ioc, expander_device,
7033 _scsih_expander_add(ioc, handle);
7036 if (!ioc->ir_firmware)
7040 phys_disk_num = 0xFF;
7041 while (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
7042 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
7044 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7045 MPI2_IOCSTATUS_MASK;
7046 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
7048 phys_disk_num = pd_pg0.PhysDiskNum;
7049 handle = le16_to_cpu(pd_pg0.DevHandle);
7050 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
7053 if (mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
7054 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
7057 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
7058 if (!_scsih_get_sas_address(ioc, parent_handle,
7060 mpt2sas_transport_update_links(ioc, sas_address,
7061 handle, sas_device_pg0.PhyNum,
7062 MPI2_SAS_NEG_LINK_RATE_1_5);
7063 set_bit(handle, ioc->pd_handles);
7064 _scsih_add_device(ioc, handle, 0, 1);
7070 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
7071 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
7072 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7073 MPI2_IOCSTATUS_MASK;
7074 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
7076 handle = le16_to_cpu(volume_pg1.DevHandle);
7077 raid_device = _scsih_raid_device_find_by_wwid(ioc,
7078 le64_to_cpu(volume_pg1.WWID));
7081 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
7082 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
7083 sizeof(Mpi2RaidVolPage0_t)))
7085 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
7086 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
7087 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) {
7088 memset(&element, 0, sizeof(Mpi2EventIrConfigElement_t));
7089 element.ReasonCode = MPI2_EVENT_IR_CHANGE_RC_ADDED;
7090 element.VolDevHandle = volume_pg1.DevHandle;
7091 _scsih_sas_volume_add(ioc, &element);
7099 while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
7100 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
7102 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7103 MPI2_IOCSTATUS_MASK;
7104 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
7106 handle = le16_to_cpu(sas_device_pg0.DevHandle);
7107 if (!(_scsih_is_end_device(
7108 le32_to_cpu(sas_device_pg0.DeviceInfo))))
7110 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
7111 le64_to_cpu(sas_device_pg0.SASAddress));
7114 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
7115 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) {
7116 mpt2sas_transport_update_links(ioc, sas_address, handle,
7117 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
7118 _scsih_add_device(ioc, handle, 0, 0);
7122 printk(MPT2SAS_INFO_FMT "scan devices: complete\n", ioc->name);
7127 * mpt2sas_scsih_reset_handler - reset callback handler (for scsih)
7128 * @ioc: per adapter object
7129 * @reset_phase: phase
7131 * The handler for doing any required cleanup or initialization.
7133 * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
7134 * MPT2_IOC_DONE_RESET
7139 mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase)
7141 switch (reset_phase) {
7142 case MPT2_IOC_PRE_RESET:
7143 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
7144 "MPT2_IOC_PRE_RESET\n", ioc->name, __func__));
7146 case MPT2_IOC_AFTER_RESET:
7147 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
7148 "MPT2_IOC_AFTER_RESET\n", ioc->name, __func__));
7149 if (ioc->scsih_cmds.status & MPT2_CMD_PENDING) {
7150 ioc->scsih_cmds.status |= MPT2_CMD_RESET;
7151 mpt2sas_base_free_smid(ioc, ioc->scsih_cmds.smid);
7152 complete(&ioc->scsih_cmds.done);
7154 if (ioc->tm_cmds.status & MPT2_CMD_PENDING) {
7155 ioc->tm_cmds.status |= MPT2_CMD_RESET;
7156 mpt2sas_base_free_smid(ioc, ioc->tm_cmds.smid);
7157 complete(&ioc->tm_cmds.done);
7159 _scsih_fw_event_cleanup_queue(ioc);
7160 _scsih_flush_running_cmds(ioc);
7162 case MPT2_IOC_DONE_RESET:
7163 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
7164 "MPT2_IOC_DONE_RESET\n", ioc->name, __func__));
7165 _scsih_sas_host_refresh(ioc);
7166 _scsih_prep_device_scan(ioc);
7167 _scsih_search_responding_sas_devices(ioc);
7168 _scsih_search_responding_raid_devices(ioc);
7169 _scsih_search_responding_expanders(ioc);
7170 if (!ioc->is_driver_loading) {
7171 _scsih_prep_device_scan(ioc);
7172 _scsih_search_responding_sas_devices(ioc);
7173 _scsih_search_responding_raid_devices(ioc);
7174 _scsih_search_responding_expanders(ioc);
7175 _scsih_error_recovery_delete_devices(ioc);
7182 * _firmware_event_work - delayed task for processing firmware events
7183 * @ioc: per adapter object
7184 * @work: equal to the fw_event_work object
7190 _firmware_event_work(struct work_struct *work)
7192 struct fw_event_work *fw_event = container_of(work,
7193 struct fw_event_work, delayed_work.work);
7194 struct MPT2SAS_ADAPTER *ioc = fw_event->ioc;
7196 /* the queue is being flushed so ignore this event */
7197 if (ioc->remove_host || fw_event->cancel_pending_work ||
7198 ioc->pci_error_recovery) {
7199 _scsih_fw_event_free(ioc, fw_event);
7203 switch (fw_event->event) {
7204 case MPT2SAS_REMOVE_UNRESPONDING_DEVICES:
7205 while (scsi_host_in_recovery(ioc->shost))
7207 _scsih_remove_unresponding_sas_devices(ioc);
7208 _scsih_scan_for_devices_after_reset(ioc);
7210 case MPT2SAS_PORT_ENABLE_COMPLETE:
7211 ioc->start_scan = 0;
7213 if (missing_delay[0] != -1 && missing_delay[1] != -1)
7214 mpt2sas_base_update_missing_delay(ioc, missing_delay[0],
7217 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "port enable: complete "
7218 "from worker thread\n", ioc->name));
7220 case MPT2SAS_TURN_ON_FAULT_LED:
7221 _scsih_turn_on_fault_led(ioc, fw_event->device_handle);
7223 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
7224 _scsih_sas_topology_change_event(ioc, fw_event);
7226 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
7227 _scsih_sas_device_status_change_event(ioc,
7230 case MPI2_EVENT_SAS_DISCOVERY:
7231 _scsih_sas_discovery_event(ioc,
7234 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
7235 _scsih_sas_broadcast_primative_event(ioc,
7238 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
7239 _scsih_sas_enclosure_dev_status_change_event(ioc,
7242 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
7243 _scsih_sas_ir_config_change_event(ioc, fw_event);
7245 case MPI2_EVENT_IR_VOLUME:
7246 _scsih_sas_ir_volume_event(ioc, fw_event);
7248 case MPI2_EVENT_IR_PHYSICAL_DISK:
7249 _scsih_sas_ir_physical_disk_event(ioc, fw_event);
7251 case MPI2_EVENT_IR_OPERATION_STATUS:
7252 _scsih_sas_ir_operation_status_event(ioc, fw_event);
7255 _scsih_fw_event_free(ioc, fw_event);
7259 * mpt2sas_scsih_event_callback - firmware event handler (called at ISR time)
7260 * @ioc: per adapter object
7261 * @msix_index: MSIX table index supplied by the OS
7262 * @reply: reply message frame(lower 32bit addr)
7263 * Context: interrupt.
7265 * This function merely adds a new work task into ioc->firmware_event_thread.
7266 * The tasks are worked from _firmware_event_work in user context.
7268 * Return 1 meaning mf should be freed from _base_interrupt
7269 * 0 means the mf is freed from this function.
7272 mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER *ioc, u8 msix_index,
7275 struct fw_event_work *fw_event;
7276 Mpi2EventNotificationReply_t *mpi_reply;
7280 /* events turned off due to host reset or driver unloading */
7281 if (ioc->remove_host || ioc->pci_error_recovery)
7284 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
7285 event = le16_to_cpu(mpi_reply->Event);
7289 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
7291 Mpi2EventDataSasBroadcastPrimitive_t *baen_data =
7292 (Mpi2EventDataSasBroadcastPrimitive_t *)
7293 mpi_reply->EventData;
7295 if (baen_data->Primitive !=
7296 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT)
7299 if (ioc->broadcast_aen_busy) {
7300 ioc->broadcast_aen_pending++;
7303 ioc->broadcast_aen_busy = 1;
7307 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
7308 _scsih_check_topo_delete_events(ioc,
7309 (Mpi2EventDataSasTopologyChangeList_t *)
7310 mpi_reply->EventData);
7312 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
7313 _scsih_check_ir_config_unhide_events(ioc,
7314 (Mpi2EventDataIrConfigChangeList_t *)
7315 mpi_reply->EventData);
7317 case MPI2_EVENT_IR_VOLUME:
7318 _scsih_check_volume_delete_events(ioc,
7319 (Mpi2EventDataIrVolume_t *)
7320 mpi_reply->EventData);
7322 case MPI2_EVENT_LOG_ENTRY_ADDED:
7324 Mpi2EventDataLogEntryAdded_t *log_entry;
7327 if (!ioc->is_warpdrive)
7330 log_entry = (Mpi2EventDataLogEntryAdded_t *)
7331 mpi_reply->EventData;
7332 log_code = (u32 *)log_entry->LogData;
7334 if (le16_to_cpu(log_entry->LogEntryQualifier)
7335 != MPT2_WARPDRIVE_LOGENTRY)
7338 switch (le32_to_cpu(*log_code)) {
7339 case MPT2_WARPDRIVE_LC_SSDT:
7340 printk(MPT2SAS_WARN_FMT "WarpDrive Warning: "
7341 "IO Throttling has occurred in the WarpDrive "
7342 "subsystem. Check WarpDrive documentation for "
7343 "additional details.\n", ioc->name);
7345 case MPT2_WARPDRIVE_LC_SSDLW:
7346 printk(MPT2SAS_WARN_FMT "WarpDrive Warning: "
7347 "Program/Erase Cycles for the WarpDrive subsystem "
7348 "in degraded range. Check WarpDrive documentation "
7349 "for additional details.\n", ioc->name);
7351 case MPT2_WARPDRIVE_LC_SSDLF:
7352 printk(MPT2SAS_ERR_FMT "WarpDrive Fatal Error: "
7353 "There are no Program/Erase Cycles for the "
7354 "WarpDrive subsystem. The storage device will be "
7355 "in read-only mode. Check WarpDrive documentation "
7356 "for additional details.\n", ioc->name);
7358 case MPT2_WARPDRIVE_LC_BRMF:
7359 printk(MPT2SAS_ERR_FMT "WarpDrive Fatal Error: "
7360 "The Backup Rail Monitor has failed on the "
7361 "WarpDrive subsystem. Check WarpDrive "
7362 "documentation for additional details.\n",
7369 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
7370 case MPI2_EVENT_IR_OPERATION_STATUS:
7371 case MPI2_EVENT_SAS_DISCOVERY:
7372 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
7373 case MPI2_EVENT_IR_PHYSICAL_DISK:
7376 default: /* ignore the rest */
7380 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
7382 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
7383 ioc->name, __FILE__, __LINE__, __func__);
7386 sz = le16_to_cpu(mpi_reply->EventDataLength) * 4;
7387 fw_event->event_data = kzalloc(sz, GFP_ATOMIC);
7388 if (!fw_event->event_data) {
7389 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
7390 ioc->name, __FILE__, __LINE__, __func__);
7395 memcpy(fw_event->event_data, mpi_reply->EventData,
7397 fw_event->ioc = ioc;
7398 fw_event->VF_ID = mpi_reply->VF_ID;
7399 fw_event->VP_ID = mpi_reply->VP_ID;
7400 fw_event->event = event;
7401 _scsih_fw_event_add(ioc, fw_event);
7405 /* shost template */
7406 static struct scsi_host_template scsih_driver_template = {
7407 .module = THIS_MODULE,
7408 .name = "Fusion MPT SAS Host",
7409 .proc_name = MPT2SAS_DRIVER_NAME,
7410 .queuecommand = _scsih_qcmd,
7411 .target_alloc = _scsih_target_alloc,
7412 .slave_alloc = _scsih_slave_alloc,
7413 .slave_configure = _scsih_slave_configure,
7414 .target_destroy = _scsih_target_destroy,
7415 .slave_destroy = _scsih_slave_destroy,
7416 .scan_finished = _scsih_scan_finished,
7417 .scan_start = _scsih_scan_start,
7418 .change_queue_depth = _scsih_change_queue_depth,
7419 .change_queue_type = _scsih_change_queue_type,
7420 .eh_abort_handler = _scsih_abort,
7421 .eh_device_reset_handler = _scsih_dev_reset,
7422 .eh_target_reset_handler = _scsih_target_reset,
7423 .eh_host_reset_handler = _scsih_host_reset,
7424 .bios_param = _scsih_bios_param,
7427 .sg_tablesize = MPT2SAS_SG_DEPTH,
7428 .max_sectors = 8192,
7430 .use_clustering = ENABLE_CLUSTERING,
7431 .shost_attrs = mpt2sas_host_attrs,
7432 .sdev_attrs = mpt2sas_dev_attrs,
7436 * _scsih_expander_node_remove - removing expander device from list.
7437 * @ioc: per adapter object
7438 * @sas_expander: the sas_device object
7439 * Context: Calling function should acquire ioc->sas_node_lock.
7441 * Removing object and freeing associated memory from the
7442 * ioc->sas_expander_list.
7447 _scsih_expander_node_remove(struct MPT2SAS_ADAPTER *ioc,
7448 struct _sas_node *sas_expander)
7450 struct _sas_port *mpt2sas_port, *next;
7452 /* remove sibling ports attached to this expander */
7453 list_for_each_entry_safe(mpt2sas_port, next,
7454 &sas_expander->sas_port_list, port_list) {
7455 if (ioc->shost_recovery)
7457 if (mpt2sas_port->remote_identify.device_type ==
7459 mpt2sas_device_remove(ioc,
7460 mpt2sas_port->remote_identify.sas_address);
7461 else if (mpt2sas_port->remote_identify.device_type ==
7462 SAS_EDGE_EXPANDER_DEVICE ||
7463 mpt2sas_port->remote_identify.device_type ==
7464 SAS_FANOUT_EXPANDER_DEVICE)
7465 mpt2sas_expander_remove(ioc,
7466 mpt2sas_port->remote_identify.sas_address);
7469 mpt2sas_transport_port_remove(ioc, sas_expander->sas_address,
7470 sas_expander->sas_address_parent);
7472 printk(MPT2SAS_INFO_FMT "expander_remove: handle"
7473 "(0x%04x), sas_addr(0x%016llx)\n", ioc->name,
7474 sas_expander->handle, (unsigned long long)
7475 sas_expander->sas_address);
7477 kfree(sas_expander->phy);
7478 kfree(sas_expander);
7482 * _scsih_ir_shutdown - IR shutdown notification
7483 * @ioc: per adapter object
7485 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
7486 * the host system is shutting down.
7491 _scsih_ir_shutdown(struct MPT2SAS_ADAPTER *ioc)
7493 Mpi2RaidActionRequest_t *mpi_request;
7494 Mpi2RaidActionReply_t *mpi_reply;
7497 /* is IR firmware build loaded ? */
7498 if (!ioc->ir_firmware)
7501 /* are there any volumes ? */
7502 if (list_empty(&ioc->raid_device_list))
7505 mutex_lock(&ioc->scsih_cmds.mutex);
7507 if (ioc->scsih_cmds.status != MPT2_CMD_NOT_USED) {
7508 printk(MPT2SAS_ERR_FMT "%s: scsih_cmd in use\n",
7509 ioc->name, __func__);
7512 ioc->scsih_cmds.status = MPT2_CMD_PENDING;
7514 smid = mpt2sas_base_get_smid(ioc, ioc->scsih_cb_idx);
7516 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
7517 ioc->name, __func__);
7518 ioc->scsih_cmds.status = MPT2_CMD_NOT_USED;
7522 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
7523 ioc->scsih_cmds.smid = smid;
7524 memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t));
7526 mpi_request->Function = MPI2_FUNCTION_RAID_ACTION;
7527 mpi_request->Action = MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED;
7529 if (!ioc->hide_ir_msg)
7530 printk(MPT2SAS_INFO_FMT "IR shutdown (sending)\n", ioc->name);
7531 init_completion(&ioc->scsih_cmds.done);
7532 mpt2sas_base_put_smid_default(ioc, smid);
7533 wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ);
7535 if (!(ioc->scsih_cmds.status & MPT2_CMD_COMPLETE)) {
7536 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
7537 ioc->name, __func__);
7541 if (ioc->scsih_cmds.status & MPT2_CMD_REPLY_VALID) {
7542 mpi_reply = ioc->scsih_cmds.reply;
7544 if (!ioc->hide_ir_msg)
7545 printk(MPT2SAS_INFO_FMT "IR shutdown (complete): "
7546 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7547 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
7548 le32_to_cpu(mpi_reply->IOCLogInfo));
7552 ioc->scsih_cmds.status = MPT2_CMD_NOT_USED;
7553 mutex_unlock(&ioc->scsih_cmds.mutex);
7557 * _scsih_shutdown - routine call during system shutdown
7558 * @pdev: PCI device struct
7563 _scsih_shutdown(struct pci_dev *pdev)
7565 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7566 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
7567 struct workqueue_struct *wq;
7568 unsigned long flags;
7570 ioc->remove_host = 1;
7571 _scsih_fw_event_cleanup_queue(ioc);
7573 spin_lock_irqsave(&ioc->fw_event_lock, flags);
7574 wq = ioc->firmware_event_thread;
7575 ioc->firmware_event_thread = NULL;
7576 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
7578 destroy_workqueue(wq);
7580 _scsih_ir_shutdown(ioc);
7581 mpt2sas_base_detach(ioc);
7585 * _scsih_remove - detach and remove add host
7586 * @pdev: PCI device struct
7588 * Routine called when unloading the driver.
7591 static void __devexit
7592 _scsih_remove(struct pci_dev *pdev)
7594 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7595 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
7596 struct _sas_port *mpt2sas_port, *next_port;
7597 struct _raid_device *raid_device, *next;
7598 struct MPT2SAS_TARGET *sas_target_priv_data;
7599 struct workqueue_struct *wq;
7600 unsigned long flags;
7602 ioc->remove_host = 1;
7603 _scsih_fw_event_cleanup_queue(ioc);
7605 spin_lock_irqsave(&ioc->fw_event_lock, flags);
7606 wq = ioc->firmware_event_thread;
7607 ioc->firmware_event_thread = NULL;
7608 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
7610 destroy_workqueue(wq);
7612 /* release all the volumes */
7613 _scsih_ir_shutdown(ioc);
7614 list_for_each_entry_safe(raid_device, next, &ioc->raid_device_list,
7616 if (raid_device->starget) {
7617 sas_target_priv_data =
7618 raid_device->starget->hostdata;
7619 sas_target_priv_data->deleted = 1;
7620 scsi_remove_target(&raid_device->starget->dev);
7622 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), wwid"
7623 "(0x%016llx)\n", ioc->name, raid_device->handle,
7624 (unsigned long long) raid_device->wwid);
7625 _scsih_raid_device_remove(ioc, raid_device);
7628 /* free ports attached to the sas_host */
7629 list_for_each_entry_safe(mpt2sas_port, next_port,
7630 &ioc->sas_hba.sas_port_list, port_list) {
7631 if (mpt2sas_port->remote_identify.device_type ==
7633 mpt2sas_device_remove(ioc,
7634 mpt2sas_port->remote_identify.sas_address);
7635 else if (mpt2sas_port->remote_identify.device_type ==
7636 SAS_EDGE_EXPANDER_DEVICE ||
7637 mpt2sas_port->remote_identify.device_type ==
7638 SAS_FANOUT_EXPANDER_DEVICE)
7639 mpt2sas_expander_remove(ioc,
7640 mpt2sas_port->remote_identify.sas_address);
7643 /* free phys attached to the sas_host */
7644 if (ioc->sas_hba.num_phys) {
7645 kfree(ioc->sas_hba.phy);
7646 ioc->sas_hba.phy = NULL;
7647 ioc->sas_hba.num_phys = 0;
7650 sas_remove_host(shost);
7651 mpt2sas_base_detach(ioc);
7652 list_del(&ioc->list);
7653 scsi_remove_host(shost);
7654 scsi_host_put(shost);
7658 * _scsih_probe_boot_devices - reports 1st device
7659 * @ioc: per adapter object
7661 * If specified in bios page 2, this routine reports the 1st
7662 * device scsi-ml or sas transport for persistent boot device
7663 * purposes. Please refer to function _scsih_determine_boot_device()
7666 _scsih_probe_boot_devices(struct MPT2SAS_ADAPTER *ioc)
7670 struct _sas_device *sas_device;
7671 struct _raid_device *raid_device;
7673 u64 sas_address_parent;
7675 unsigned long flags;
7678 /* no Bios, return immediately */
7679 if (!ioc->bios_pg3.BiosVersion)
7684 if (ioc->req_boot_device.device) {
7685 device = ioc->req_boot_device.device;
7686 is_raid = ioc->req_boot_device.is_raid;
7687 } else if (ioc->req_alt_boot_device.device) {
7688 device = ioc->req_alt_boot_device.device;
7689 is_raid = ioc->req_alt_boot_device.is_raid;
7690 } else if (ioc->current_boot_device.device) {
7691 device = ioc->current_boot_device.device;
7692 is_raid = ioc->current_boot_device.is_raid;
7699 raid_device = device;
7700 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
7701 raid_device->id, 0);
7703 _scsih_raid_device_remove(ioc, raid_device);
7705 sas_device = device;
7706 handle = sas_device->handle;
7707 sas_address_parent = sas_device->sas_address_parent;
7708 sas_address = sas_device->sas_address;
7709 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7710 list_move_tail(&sas_device->list, &ioc->sas_device_list);
7711 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7713 if (ioc->hide_drives)
7715 if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
7716 sas_device->sas_address_parent)) {
7717 _scsih_sas_device_remove(ioc, sas_device);
7718 } else if (!sas_device->starget) {
7719 if (!ioc->is_driver_loading)
7720 mpt2sas_transport_port_remove(ioc, sas_address,
7721 sas_address_parent);
7722 _scsih_sas_device_remove(ioc, sas_device);
7728 * _scsih_probe_raid - reporting raid volumes to scsi-ml
7729 * @ioc: per adapter object
7731 * Called during initial loading of the driver.
7734 _scsih_probe_raid(struct MPT2SAS_ADAPTER *ioc)
7736 struct _raid_device *raid_device, *raid_next;
7739 list_for_each_entry_safe(raid_device, raid_next,
7740 &ioc->raid_device_list, list) {
7741 if (raid_device->starget)
7743 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
7744 raid_device->id, 0);
7746 _scsih_raid_device_remove(ioc, raid_device);
7751 * _scsih_probe_sas - reporting sas devices to sas transport
7752 * @ioc: per adapter object
7754 * Called during initial loading of the driver.
7757 _scsih_probe_sas(struct MPT2SAS_ADAPTER *ioc)
7759 struct _sas_device *sas_device, *next;
7760 unsigned long flags;
7762 /* SAS Device List */
7763 list_for_each_entry_safe(sas_device, next, &ioc->sas_device_init_list,
7766 if (ioc->hide_drives)
7769 if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
7770 sas_device->sas_address_parent)) {
7771 list_del(&sas_device->list);
7774 } else if (!sas_device->starget) {
7775 if (!ioc->is_driver_loading)
7776 mpt2sas_transport_port_remove(ioc,
7777 sas_device->sas_address,
7778 sas_device->sas_address_parent);
7779 list_del(&sas_device->list);
7784 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7785 list_move_tail(&sas_device->list, &ioc->sas_device_list);
7786 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7791 * _scsih_probe_devices - probing for devices
7792 * @ioc: per adapter object
7794 * Called during initial loading of the driver.
7797 _scsih_probe_devices(struct MPT2SAS_ADAPTER *ioc)
7799 u16 volume_mapping_flags;
7801 if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR))
7802 return; /* return when IOC doesn't support initiator mode */
7804 _scsih_probe_boot_devices(ioc);
7806 if (ioc->ir_firmware) {
7807 volume_mapping_flags =
7808 le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) &
7809 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE;
7810 if (volume_mapping_flags ==
7811 MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING) {
7812 _scsih_probe_raid(ioc);
7813 _scsih_probe_sas(ioc);
7815 _scsih_probe_sas(ioc);
7816 _scsih_probe_raid(ioc);
7819 _scsih_probe_sas(ioc);
7824 * _scsih_scan_start - scsi lld callback for .scan_start
7825 * @shost: SCSI host pointer
7827 * The shost has the ability to discover targets on its own instead
7828 * of scanning the entire bus. In our implemention, we will kick off
7829 * firmware discovery.
7832 _scsih_scan_start(struct Scsi_Host *shost)
7834 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
7837 if (diag_buffer_enable != -1 && diag_buffer_enable != 0)
7838 mpt2sas_enable_diag_buffer(ioc, diag_buffer_enable);
7840 ioc->start_scan = 1;
7841 rc = mpt2sas_port_enable(ioc);
7844 printk(MPT2SAS_INFO_FMT "port enable: FAILED\n", ioc->name);
7848 * _scsih_scan_finished - scsi lld callback for .scan_finished
7849 * @shost: SCSI host pointer
7850 * @time: elapsed time of the scan in jiffies
7852 * This function will be called periodically until it returns 1 with the
7853 * scsi_host and the elapsed time of the scan in jiffies. In our implemention,
7854 * we wait for firmware discovery to complete, then return 1.
7857 _scsih_scan_finished(struct Scsi_Host *shost, unsigned long time)
7859 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
7861 if (time >= (300 * HZ)) {
7862 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
7863 printk(MPT2SAS_INFO_FMT "port enable: FAILED with timeout "
7864 "(timeout=300s)\n", ioc->name);
7865 ioc->is_driver_loading = 0;
7869 if (ioc->start_scan)
7872 if (ioc->start_scan_failed) {
7873 printk(MPT2SAS_INFO_FMT "port enable: FAILED with "
7874 "(ioc_status=0x%08x)\n", ioc->name, ioc->start_scan_failed);
7875 ioc->is_driver_loading = 0;
7876 ioc->wait_for_discovery_to_complete = 0;
7877 ioc->remove_host = 1;
7881 printk(MPT2SAS_INFO_FMT "port enable: SUCCESS\n", ioc->name);
7882 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
7884 if (ioc->wait_for_discovery_to_complete) {
7885 ioc->wait_for_discovery_to_complete = 0;
7886 _scsih_probe_devices(ioc);
7888 mpt2sas_base_start_watchdog(ioc);
7889 ioc->is_driver_loading = 0;
7895 * _scsih_probe - attach and add scsi host
7896 * @pdev: PCI device struct
7897 * @id: pci device id
7899 * Returns 0 success, anything else error.
7902 _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id)
7904 struct MPT2SAS_ADAPTER *ioc;
7905 struct Scsi_Host *shost;
7907 shost = scsi_host_alloc(&scsih_driver_template,
7908 sizeof(struct MPT2SAS_ADAPTER));
7912 /* init local params */
7913 ioc = shost_priv(shost);
7914 memset(ioc, 0, sizeof(struct MPT2SAS_ADAPTER));
7915 INIT_LIST_HEAD(&ioc->list);
7916 list_add_tail(&ioc->list, &mpt2sas_ioc_list);
7918 ioc->id = mpt_ids++;
7919 sprintf(ioc->name, "%s%d", MPT2SAS_DRIVER_NAME, ioc->id);
7921 if (id->device == MPI2_MFGPAGE_DEVID_SSS6200) {
7922 ioc->is_warpdrive = 1;
7923 ioc->hide_ir_msg = 1;
7925 ioc->mfg_pg10_hide_flag = MFG_PAGE10_EXPOSE_ALL_DISKS;
7926 ioc->scsi_io_cb_idx = scsi_io_cb_idx;
7927 ioc->tm_cb_idx = tm_cb_idx;
7928 ioc->ctl_cb_idx = ctl_cb_idx;
7929 ioc->base_cb_idx = base_cb_idx;
7930 ioc->port_enable_cb_idx = port_enable_cb_idx;
7931 ioc->transport_cb_idx = transport_cb_idx;
7932 ioc->scsih_cb_idx = scsih_cb_idx;
7933 ioc->config_cb_idx = config_cb_idx;
7934 ioc->tm_tr_cb_idx = tm_tr_cb_idx;
7935 ioc->tm_tr_volume_cb_idx = tm_tr_volume_cb_idx;
7936 ioc->tm_sas_control_cb_idx = tm_sas_control_cb_idx;
7937 ioc->logging_level = logging_level;
7938 /* misc semaphores and spin locks */
7939 mutex_init(&ioc->reset_in_progress_mutex);
7940 spin_lock_init(&ioc->ioc_reset_in_progress_lock);
7941 spin_lock_init(&ioc->scsi_lookup_lock);
7942 spin_lock_init(&ioc->sas_device_lock);
7943 spin_lock_init(&ioc->sas_node_lock);
7944 spin_lock_init(&ioc->fw_event_lock);
7945 spin_lock_init(&ioc->raid_device_lock);
7947 INIT_LIST_HEAD(&ioc->sas_device_list);
7948 INIT_LIST_HEAD(&ioc->sas_device_init_list);
7949 INIT_LIST_HEAD(&ioc->sas_expander_list);
7950 INIT_LIST_HEAD(&ioc->fw_event_list);
7951 INIT_LIST_HEAD(&ioc->raid_device_list);
7952 INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list);
7953 INIT_LIST_HEAD(&ioc->delayed_tr_list);
7954 INIT_LIST_HEAD(&ioc->delayed_tr_volume_list);
7956 /* init shost parameters */
7957 shost->max_cmd_len = 32;
7958 shost->max_lun = max_lun;
7959 shost->transportt = mpt2sas_transport_template;
7960 shost->unique_id = ioc->id;
7962 if (max_sectors != 0xFFFF) {
7963 if (max_sectors < 64) {
7964 shost->max_sectors = 64;
7965 printk(MPT2SAS_WARN_FMT "Invalid value %d passed "
7966 "for max_sectors, range is 64 to 8192. Assigning "
7967 "value of 64.\n", ioc->name, max_sectors);
7968 } else if (max_sectors > 8192) {
7969 shost->max_sectors = 8192;
7970 printk(MPT2SAS_WARN_FMT "Invalid value %d passed "
7971 "for max_sectors, range is 64 to 8192. Assigning "
7972 "default value of 8192.\n", ioc->name,
7975 shost->max_sectors = max_sectors & 0xFFFE;
7976 printk(MPT2SAS_INFO_FMT "The max_sectors value is "
7977 "set to %d\n", ioc->name, shost->max_sectors);
7981 if ((scsi_add_host(shost, &pdev->dev))) {
7982 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
7983 ioc->name, __FILE__, __LINE__, __func__);
7984 list_del(&ioc->list);
7985 goto out_add_shost_fail;
7988 scsi_host_set_prot(shost, SHOST_DIF_TYPE1_PROTECTION
7989 | SHOST_DIF_TYPE2_PROTECTION | SHOST_DIF_TYPE3_PROTECTION);
7990 scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC);
7993 snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name),
7994 "fw_event%d", ioc->id);
7995 ioc->firmware_event_thread = create_singlethread_workqueue(
7996 ioc->firmware_event_name);
7997 if (!ioc->firmware_event_thread) {
7998 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
7999 ioc->name, __FILE__, __LINE__, __func__);
8000 goto out_thread_fail;
8003 ioc->is_driver_loading = 1;
8004 if ((mpt2sas_base_attach(ioc))) {
8005 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
8006 ioc->name, __FILE__, __LINE__, __func__);
8007 goto out_attach_fail;
8010 if (ioc->is_warpdrive) {
8011 if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS)
8012 ioc->hide_drives = 0;
8013 else if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_HIDE_ALL_DISKS)
8014 ioc->hide_drives = 1;
8016 if (_scsih_get_num_volumes(ioc))
8017 ioc->hide_drives = 1;
8019 ioc->hide_drives = 0;
8022 ioc->hide_drives = 0;
8023 scsi_scan_host(shost);
8028 destroy_workqueue(ioc->firmware_event_thread);
8030 list_del(&ioc->list);
8031 scsi_remove_host(shost);
8032 scsi_host_put(shost);
8039 * _scsih_suspend - power management suspend main entry point
8040 * @pdev: PCI device struct
8041 * @state: PM state change to (usually PCI_D3)
8043 * Returns 0 success, anything else error.
8046 _scsih_suspend(struct pci_dev *pdev, pm_message_t state)
8048 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8049 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8050 pci_power_t device_state;
8052 mpt2sas_base_stop_watchdog(ioc);
8053 scsi_block_requests(shost);
8054 device_state = pci_choose_state(pdev, state);
8055 printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, entering "
8056 "operating state [D%d]\n", ioc->name, pdev,
8057 pci_name(pdev), device_state);
8059 mpt2sas_base_free_resources(ioc);
8060 pci_save_state(pdev);
8061 pci_disable_device(pdev);
8062 pci_set_power_state(pdev, device_state);
8067 * _scsih_resume - power management resume main entry point
8068 * @pdev: PCI device struct
8070 * Returns 0 success, anything else error.
8073 _scsih_resume(struct pci_dev *pdev)
8075 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8076 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8077 pci_power_t device_state = pdev->current_state;
8080 printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, previous "
8081 "operating state [D%d]\n", ioc->name, pdev,
8082 pci_name(pdev), device_state);
8084 pci_set_power_state(pdev, PCI_D0);
8085 pci_enable_wake(pdev, PCI_D0, 0);
8086 pci_restore_state(pdev);
8088 r = mpt2sas_base_map_resources(ioc);
8092 mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, SOFT_RESET);
8093 scsi_unblock_requests(shost);
8094 mpt2sas_base_start_watchdog(ioc);
8097 #endif /* CONFIG_PM */
8100 * _scsih_pci_error_detected - Called when a PCI error is detected.
8101 * @pdev: PCI device struct
8102 * @state: PCI channel state
8104 * Description: Called when a PCI error is detected.
8107 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
8109 static pci_ers_result_t
8110 _scsih_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
8112 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8113 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8115 printk(MPT2SAS_INFO_FMT "PCI error: detected callback, state(%d)!!\n",
8119 case pci_channel_io_normal:
8120 return PCI_ERS_RESULT_CAN_RECOVER;
8121 case pci_channel_io_frozen:
8122 /* Fatal error, prepare for slot reset */
8123 ioc->pci_error_recovery = 1;
8124 scsi_block_requests(ioc->shost);
8125 mpt2sas_base_stop_watchdog(ioc);
8126 mpt2sas_base_free_resources(ioc);
8127 return PCI_ERS_RESULT_NEED_RESET;
8128 case pci_channel_io_perm_failure:
8129 /* Permanent error, prepare for device removal */
8130 ioc->pci_error_recovery = 1;
8131 mpt2sas_base_stop_watchdog(ioc);
8132 _scsih_flush_running_cmds(ioc);
8133 return PCI_ERS_RESULT_DISCONNECT;
8135 return PCI_ERS_RESULT_NEED_RESET;
8139 * _scsih_pci_slot_reset - Called when PCI slot has been reset.
8140 * @pdev: PCI device struct
8142 * Description: This routine is called by the pci error recovery
8143 * code after the PCI slot has been reset, just before we
8144 * should resume normal operations.
8146 static pci_ers_result_t
8147 _scsih_pci_slot_reset(struct pci_dev *pdev)
8149 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8150 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8153 printk(MPT2SAS_INFO_FMT "PCI error: slot reset callback!!\n",
8156 ioc->pci_error_recovery = 0;
8158 pci_restore_state(pdev);
8159 rc = mpt2sas_base_map_resources(ioc);
8161 return PCI_ERS_RESULT_DISCONNECT;
8164 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
8167 printk(MPT2SAS_WARN_FMT "hard reset: %s\n", ioc->name,
8168 (rc == 0) ? "success" : "failed");
8171 return PCI_ERS_RESULT_RECOVERED;
8173 return PCI_ERS_RESULT_DISCONNECT;
8177 * _scsih_pci_resume() - resume normal ops after PCI reset
8178 * @pdev: pointer to PCI device
8180 * Called when the error recovery driver tells us that its
8181 * OK to resume normal operation. Use completion to allow
8182 * halted scsi ops to resume.
8185 _scsih_pci_resume(struct pci_dev *pdev)
8187 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8188 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8190 printk(MPT2SAS_INFO_FMT "PCI error: resume callback!!\n", ioc->name);
8192 pci_cleanup_aer_uncorrect_error_status(pdev);
8193 mpt2sas_base_start_watchdog(ioc);
8194 scsi_unblock_requests(ioc->shost);
8198 * _scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
8199 * @pdev: pointer to PCI device
8201 static pci_ers_result_t
8202 _scsih_pci_mmio_enabled(struct pci_dev *pdev)
8204 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8205 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8207 printk(MPT2SAS_INFO_FMT "PCI error: mmio enabled callback!!\n",
8210 /* TODO - dump whatever for debugging purposes */
8212 /* Request a slot reset. */
8213 return PCI_ERS_RESULT_NEED_RESET;
8216 static struct pci_error_handlers _scsih_err_handler = {
8217 .error_detected = _scsih_pci_error_detected,
8218 .mmio_enabled = _scsih_pci_mmio_enabled,
8219 .slot_reset = _scsih_pci_slot_reset,
8220 .resume = _scsih_pci_resume,
8223 static struct pci_driver scsih_driver = {
8224 .name = MPT2SAS_DRIVER_NAME,
8225 .id_table = scsih_pci_table,
8226 .probe = _scsih_probe,
8227 .remove = __devexit_p(_scsih_remove),
8228 .shutdown = _scsih_shutdown,
8229 .err_handler = &_scsih_err_handler,
8231 .suspend = _scsih_suspend,
8232 .resume = _scsih_resume,
8236 /* raid transport support */
8237 static struct raid_function_template mpt2sas_raid_functions = {
8238 .cookie = &scsih_driver_template,
8239 .is_raid = _scsih_is_raid,
8240 .get_resync = _scsih_get_resync,
8241 .get_state = _scsih_get_state,
8245 * _scsih_init - main entry point for this driver.
8247 * Returns 0 success, anything else error.
8255 printk(KERN_INFO "%s version %s loaded\n", MPT2SAS_DRIVER_NAME,
8256 MPT2SAS_DRIVER_VERSION);
8258 mpt2sas_transport_template =
8259 sas_attach_transport(&mpt2sas_transport_functions);
8260 if (!mpt2sas_transport_template)
8262 /* raid transport support */
8263 mpt2sas_raid_template = raid_class_attach(&mpt2sas_raid_functions);
8264 if (!mpt2sas_raid_template) {
8265 sas_release_transport(mpt2sas_transport_template);
8269 mpt2sas_base_initialize_callback_handler();
8271 /* queuecommand callback hander */
8272 scsi_io_cb_idx = mpt2sas_base_register_callback_handler(_scsih_io_done);
8274 /* task management callback handler */
8275 tm_cb_idx = mpt2sas_base_register_callback_handler(_scsih_tm_done);
8277 /* base internal commands callback handler */
8278 base_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_base_done);
8279 port_enable_cb_idx = mpt2sas_base_register_callback_handler(
8280 mpt2sas_port_enable_done);
8282 /* transport internal commands callback handler */
8283 transport_cb_idx = mpt2sas_base_register_callback_handler(
8284 mpt2sas_transport_done);
8286 /* scsih internal commands callback handler */
8287 scsih_cb_idx = mpt2sas_base_register_callback_handler(_scsih_done);
8289 /* configuration page API internal commands callback handler */
8290 config_cb_idx = mpt2sas_base_register_callback_handler(
8291 mpt2sas_config_done);
8293 /* ctl module callback handler */
8294 ctl_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_ctl_done);
8296 tm_tr_cb_idx = mpt2sas_base_register_callback_handler(
8297 _scsih_tm_tr_complete);
8299 tm_tr_volume_cb_idx = mpt2sas_base_register_callback_handler(
8300 _scsih_tm_volume_tr_complete);
8302 tm_sas_control_cb_idx = mpt2sas_base_register_callback_handler(
8303 _scsih_sas_control_complete);
8307 error = pci_register_driver(&scsih_driver);
8309 /* raid transport support */
8310 raid_class_release(mpt2sas_raid_template);
8311 sas_release_transport(mpt2sas_transport_template);
8318 * _scsih_exit - exit point for this driver (when it is a module).
8320 * Returns 0 success, anything else error.
8325 printk(KERN_INFO "mpt2sas version %s unloading\n",
8326 MPT2SAS_DRIVER_VERSION);
8328 pci_unregister_driver(&scsih_driver);
8332 mpt2sas_base_release_callback_handler(scsi_io_cb_idx);
8333 mpt2sas_base_release_callback_handler(tm_cb_idx);
8334 mpt2sas_base_release_callback_handler(base_cb_idx);
8335 mpt2sas_base_release_callback_handler(port_enable_cb_idx);
8336 mpt2sas_base_release_callback_handler(transport_cb_idx);
8337 mpt2sas_base_release_callback_handler(scsih_cb_idx);
8338 mpt2sas_base_release_callback_handler(config_cb_idx);
8339 mpt2sas_base_release_callback_handler(ctl_cb_idx);
8341 mpt2sas_base_release_callback_handler(tm_tr_cb_idx);
8342 mpt2sas_base_release_callback_handler(tm_tr_volume_cb_idx);
8343 mpt2sas_base_release_callback_handler(tm_sas_control_cb_idx);
8345 /* raid transport support */
8346 raid_class_release(mpt2sas_raid_template);
8347 sas_release_transport(mpt2sas_transport_template);
8351 module_init(_scsih_init);
8352 module_exit(_scsih_exit);