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/version.h>
45 #include <linux/module.h>
46 #include <linux/kernel.h>
47 #include <linux/init.h>
48 #include <linux/errno.h>
49 #include <linux/blkdev.h>
50 #include <linux/sched.h>
51 #include <linux/workqueue.h>
52 #include <linux/delay.h>
53 #include <linux/pci.h>
54 #include <linux/interrupt.h>
55 #include <linux/aer.h>
56 #include <linux/raid_class.h>
57 #include <linux/slab.h>
59 #include "mpt2sas_base.h"
61 MODULE_AUTHOR(MPT2SAS_AUTHOR);
62 MODULE_DESCRIPTION(MPT2SAS_DESCRIPTION);
63 MODULE_LICENSE("GPL");
64 MODULE_VERSION(MPT2SAS_DRIVER_VERSION);
66 #define RAID_CHANNEL 1
69 static void _scsih_expander_node_remove(struct MPT2SAS_ADAPTER *ioc,
70 struct _sas_node *sas_expander);
71 static void _firmware_event_work(struct work_struct *work);
73 static u8 _scsih_check_for_pending_tm(struct MPT2SAS_ADAPTER *ioc, u16 smid);
75 /* global parameters */
76 LIST_HEAD(mpt2sas_ioc_list);
78 /* local parameters */
79 static u8 scsi_io_cb_idx = -1;
80 static u8 tm_cb_idx = -1;
81 static u8 ctl_cb_idx = -1;
82 static u8 base_cb_idx = -1;
83 static u8 transport_cb_idx = -1;
84 static u8 scsih_cb_idx = -1;
85 static u8 config_cb_idx = -1;
88 static u8 tm_tr_cb_idx = -1 ;
89 static u8 tm_tr_volume_cb_idx = -1 ;
90 static u8 tm_sas_control_cb_idx = -1;
92 /* command line options */
93 static u32 logging_level;
94 MODULE_PARM_DESC(logging_level, " bits for enabling additional logging info "
97 /* scsi-mid layer global parmeter is max_report_luns, which is 511 */
98 #define MPT2SAS_MAX_LUN (16895)
99 static int max_lun = MPT2SAS_MAX_LUN;
100 module_param(max_lun, int, 0);
101 MODULE_PARM_DESC(max_lun, " max lun, default=16895 ");
104 * struct sense_info - common structure for obtaining sense keys
106 * @asc: additional sense code
107 * @ascq: additional sense code qualifier
116 #define MPT2SAS_TURN_ON_FAULT_LED (0xFFFC)
117 #define MPT2SAS_RESCAN_AFTER_HOST_RESET (0xFFFF)
120 * struct fw_event_work - firmware event struct
121 * @list: link list framework
122 * @work: work object (ioc->fault_reset_work_q)
123 * @cancel_pending_work: flag set during reset handling
124 * @ioc: per adapter object
125 * @device_handle: device handle
126 * @VF_ID: virtual function id
127 * @VP_ID: virtual port id
128 * @ignore: flag meaning this event has been marked to ignore
129 * @event: firmware event MPI2_EVENT_XXX defined in mpt2_ioc.h
130 * @event_data: reply event data payload follows
132 * This object stored on ioc->fw_event_list.
134 struct fw_event_work {
135 struct list_head list;
136 u8 cancel_pending_work;
137 struct delayed_work delayed_work;
138 struct MPT2SAS_ADAPTER *ioc;
147 /* raid transport support */
148 static struct raid_template *mpt2sas_raid_template;
151 * struct _scsi_io_transfer - scsi io transfer
152 * @handle: sas device handle (assigned by firmware)
153 * @is_raid: flag set for hidden raid components
154 * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE,
155 * @data_length: data transfer length
156 * @data_dma: dma pointer to data
159 * @cdb_length: cdb length
161 * @timeout: timeout for this command
162 * @VF_ID: virtual function id
163 * @VP_ID: virtual port id
164 * @valid_reply: flag set for reply message
165 * @sense_length: sense length
166 * @ioc_status: ioc status
167 * @scsi_state: scsi state
168 * @scsi_status: scsi staus
169 * @log_info: log information
170 * @transfer_length: data length transfer when there is a reply message
172 * Used for sending internal scsi commands to devices within this module.
173 * Refer to _scsi_send_scsi_io().
175 struct _scsi_io_transfer {
178 enum dma_data_direction dir;
181 u8 sense[SCSI_SENSE_BUFFERSIZE];
189 /* the following bits are only valid when 'valid_reply = 1' */
199 * The pci device ids are defined in mpi/mpi2_cnfg.h.
201 static struct pci_device_id scsih_pci_table[] = {
202 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2004,
203 PCI_ANY_ID, PCI_ANY_ID },
205 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2008,
206 PCI_ANY_ID, PCI_ANY_ID },
207 /* Liberator ~ 2108 */
208 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_1,
209 PCI_ANY_ID, PCI_ANY_ID },
210 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_2,
211 PCI_ANY_ID, PCI_ANY_ID },
212 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_3,
213 PCI_ANY_ID, PCI_ANY_ID },
215 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_1,
216 PCI_ANY_ID, PCI_ANY_ID },
217 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_2,
218 PCI_ANY_ID, PCI_ANY_ID },
219 /* Thunderbolt ~ 2208 */
220 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_1,
221 PCI_ANY_ID, PCI_ANY_ID },
222 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_2,
223 PCI_ANY_ID, PCI_ANY_ID },
224 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_3,
225 PCI_ANY_ID, PCI_ANY_ID },
226 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_4,
227 PCI_ANY_ID, PCI_ANY_ID },
228 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_5,
229 PCI_ANY_ID, PCI_ANY_ID },
230 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_6,
231 PCI_ANY_ID, PCI_ANY_ID },
233 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_1,
234 PCI_ANY_ID, PCI_ANY_ID },
235 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_2,
236 PCI_ANY_ID, PCI_ANY_ID },
237 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_3,
238 PCI_ANY_ID, PCI_ANY_ID },
240 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SSS6200,
241 PCI_ANY_ID, PCI_ANY_ID },
242 {0} /* Terminating entry */
244 MODULE_DEVICE_TABLE(pci, scsih_pci_table);
247 * _scsih_set_debug_level - global setting of ioc->logging_level.
249 * Note: The logging levels are defined in mpt2sas_debug.h.
252 _scsih_set_debug_level(const char *val, struct kernel_param *kp)
254 int ret = param_set_int(val, kp);
255 struct MPT2SAS_ADAPTER *ioc;
260 printk(KERN_INFO "setting logging_level(0x%08x)\n", logging_level);
261 list_for_each_entry(ioc, &mpt2sas_ioc_list, list)
262 ioc->logging_level = logging_level;
265 module_param_call(logging_level, _scsih_set_debug_level, param_get_int,
266 &logging_level, 0644);
269 * _scsih_srch_boot_sas_address - search based on sas_address
270 * @sas_address: sas address
271 * @boot_device: boot device object from bios page 2
273 * Returns 1 when there's a match, 0 means no match.
276 _scsih_srch_boot_sas_address(u64 sas_address,
277 Mpi2BootDeviceSasWwid_t *boot_device)
279 return (sas_address == le64_to_cpu(boot_device->SASAddress)) ? 1 : 0;
283 * _scsih_srch_boot_device_name - search based on device name
284 * @device_name: device name specified in INDENTIFY fram
285 * @boot_device: boot device object from bios page 2
287 * Returns 1 when there's a match, 0 means no match.
290 _scsih_srch_boot_device_name(u64 device_name,
291 Mpi2BootDeviceDeviceName_t *boot_device)
293 return (device_name == le64_to_cpu(boot_device->DeviceName)) ? 1 : 0;
297 * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot
298 * @enclosure_logical_id: enclosure logical id
299 * @slot_number: slot number
300 * @boot_device: boot device object from bios page 2
302 * Returns 1 when there's a match, 0 means no match.
305 _scsih_srch_boot_encl_slot(u64 enclosure_logical_id, u16 slot_number,
306 Mpi2BootDeviceEnclosureSlot_t *boot_device)
308 return (enclosure_logical_id == le64_to_cpu(boot_device->
309 EnclosureLogicalID) && slot_number == le16_to_cpu(boot_device->
310 SlotNumber)) ? 1 : 0;
314 * _scsih_is_boot_device - search for matching boot device.
315 * @sas_address: sas address
316 * @device_name: device name specified in INDENTIFY fram
317 * @enclosure_logical_id: enclosure logical id
318 * @slot_number: slot number
319 * @form: specifies boot device form
320 * @boot_device: boot device object from bios page 2
322 * Returns 1 when there's a match, 0 means no match.
325 _scsih_is_boot_device(u64 sas_address, u64 device_name,
326 u64 enclosure_logical_id, u16 slot, u8 form,
327 Mpi2BiosPage2BootDevice_t *boot_device)
332 case MPI2_BIOSPAGE2_FORM_SAS_WWID:
335 rc = _scsih_srch_boot_sas_address(
336 sas_address, &boot_device->SasWwid);
338 case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT:
339 if (!enclosure_logical_id)
341 rc = _scsih_srch_boot_encl_slot(
342 enclosure_logical_id,
343 slot, &boot_device->EnclosureSlot);
345 case MPI2_BIOSPAGE2_FORM_DEVICE_NAME:
348 rc = _scsih_srch_boot_device_name(
349 device_name, &boot_device->DeviceName);
351 case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED:
359 * _scsih_get_sas_address - set the sas_address for given device handle
360 * @handle: device handle
361 * @sas_address: sas address
363 * Returns 0 success, non-zero when failure
366 _scsih_get_sas_address(struct MPT2SAS_ADAPTER *ioc, u16 handle,
369 Mpi2SasDevicePage0_t sas_device_pg0;
370 Mpi2ConfigReply_t mpi_reply;
373 if (handle <= ioc->sas_hba.num_phys) {
374 *sas_address = ioc->sas_hba.sas_address;
379 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
380 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
381 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
382 ioc->name, __FILE__, __LINE__, __func__);
386 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
388 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
389 printk(MPT2SAS_ERR_FMT "handle(0x%04x), ioc_status(0x%04x)"
390 "\nfailure at %s:%d/%s()!\n", ioc->name, handle, ioc_status,
391 __FILE__, __LINE__, __func__);
395 *sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
400 * _scsih_determine_boot_device - determine boot device.
401 * @ioc: per adapter object
402 * @device: either sas_device or raid_device object
403 * @is_raid: [flag] 1 = raid object, 0 = sas object
405 * Determines whether this device should be first reported device to
406 * to scsi-ml or sas transport, this purpose is for persistent boot device.
407 * There are primary, alternate, and current entries in bios page 2. The order
408 * priority is primary, alternate, then current. This routine saves
409 * the corresponding device object and is_raid flag in the ioc object.
410 * The saved data to be used later in _scsih_probe_boot_devices().
413 _scsih_determine_boot_device(struct MPT2SAS_ADAPTER *ioc,
414 void *device, u8 is_raid)
416 struct _sas_device *sas_device;
417 struct _raid_device *raid_device;
420 u64 enclosure_logical_id;
423 /* only process this function when driver loads */
424 if (!ioc->wait_for_port_enable_to_complete)
429 sas_address = sas_device->sas_address;
430 device_name = sas_device->device_name;
431 enclosure_logical_id = sas_device->enclosure_logical_id;
432 slot = sas_device->slot;
434 raid_device = device;
435 sas_address = raid_device->wwid;
437 enclosure_logical_id = 0;
441 if (!ioc->req_boot_device.device) {
442 if (_scsih_is_boot_device(sas_address, device_name,
443 enclosure_logical_id, slot,
444 (ioc->bios_pg2.ReqBootDeviceForm &
445 MPI2_BIOSPAGE2_FORM_MASK),
446 &ioc->bios_pg2.RequestedBootDevice)) {
447 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT
448 "%s: req_boot_device(0x%016llx)\n",
450 (unsigned long long)sas_address));
451 ioc->req_boot_device.device = device;
452 ioc->req_boot_device.is_raid = is_raid;
456 if (!ioc->req_alt_boot_device.device) {
457 if (_scsih_is_boot_device(sas_address, device_name,
458 enclosure_logical_id, slot,
459 (ioc->bios_pg2.ReqAltBootDeviceForm &
460 MPI2_BIOSPAGE2_FORM_MASK),
461 &ioc->bios_pg2.RequestedAltBootDevice)) {
462 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT
463 "%s: req_alt_boot_device(0x%016llx)\n",
465 (unsigned long long)sas_address));
466 ioc->req_alt_boot_device.device = device;
467 ioc->req_alt_boot_device.is_raid = is_raid;
471 if (!ioc->current_boot_device.device) {
472 if (_scsih_is_boot_device(sas_address, device_name,
473 enclosure_logical_id, slot,
474 (ioc->bios_pg2.CurrentBootDeviceForm &
475 MPI2_BIOSPAGE2_FORM_MASK),
476 &ioc->bios_pg2.CurrentBootDevice)) {
477 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT
478 "%s: current_boot_device(0x%016llx)\n",
480 (unsigned long long)sas_address));
481 ioc->current_boot_device.device = device;
482 ioc->current_boot_device.is_raid = is_raid;
488 * mpt2sas_scsih_sas_device_find_by_sas_address - sas device search
489 * @ioc: per adapter object
490 * @sas_address: sas address
491 * Context: Calling function should acquire ioc->sas_device_lock
493 * This searches for sas_device based on sas_address, then return sas_device
497 mpt2sas_scsih_sas_device_find_by_sas_address(struct MPT2SAS_ADAPTER *ioc,
500 struct _sas_device *sas_device;
502 list_for_each_entry(sas_device, &ioc->sas_device_list, list)
503 if (sas_device->sas_address == sas_address)
506 list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
507 if (sas_device->sas_address == sas_address)
514 * _scsih_sas_device_find_by_handle - sas device search
515 * @ioc: per adapter object
516 * @handle: sas device handle (assigned by firmware)
517 * Context: Calling function should acquire ioc->sas_device_lock
519 * This searches for sas_device based on sas_address, then return sas_device
522 static struct _sas_device *
523 _scsih_sas_device_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
525 struct _sas_device *sas_device;
527 list_for_each_entry(sas_device, &ioc->sas_device_list, list)
528 if (sas_device->handle == handle)
531 list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
532 if (sas_device->handle == handle)
539 * _scsih_sas_device_remove - remove sas_device from list.
540 * @ioc: per adapter object
541 * @sas_device: the sas_device object
542 * Context: This function will acquire ioc->sas_device_lock.
544 * Removing object and freeing associated memory from the ioc->sas_device_list.
547 _scsih_sas_device_remove(struct MPT2SAS_ADAPTER *ioc,
548 struct _sas_device *sas_device)
555 spin_lock_irqsave(&ioc->sas_device_lock, flags);
556 if (mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
557 sas_device->sas_address)) {
558 list_del(&sas_device->list);
561 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
565 * _scsih_sas_device_add - insert sas_device to the list.
566 * @ioc: per adapter object
567 * @sas_device: the sas_device object
568 * Context: This function will acquire ioc->sas_device_lock.
570 * Adding new object to the ioc->sas_device_list.
573 _scsih_sas_device_add(struct MPT2SAS_ADAPTER *ioc,
574 struct _sas_device *sas_device)
578 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle"
579 "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
580 sas_device->handle, (unsigned long long)sas_device->sas_address));
582 spin_lock_irqsave(&ioc->sas_device_lock, flags);
583 list_add_tail(&sas_device->list, &ioc->sas_device_list);
584 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
586 if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
587 sas_device->sas_address_parent))
588 _scsih_sas_device_remove(ioc, sas_device);
592 * _scsih_sas_device_init_add - insert sas_device to the list.
593 * @ioc: per adapter object
594 * @sas_device: the sas_device object
595 * Context: This function will acquire ioc->sas_device_lock.
597 * Adding new object at driver load time to the ioc->sas_device_init_list.
600 _scsih_sas_device_init_add(struct MPT2SAS_ADAPTER *ioc,
601 struct _sas_device *sas_device)
605 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle"
606 "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
607 sas_device->handle, (unsigned long long)sas_device->sas_address));
609 spin_lock_irqsave(&ioc->sas_device_lock, flags);
610 list_add_tail(&sas_device->list, &ioc->sas_device_init_list);
611 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
612 _scsih_determine_boot_device(ioc, sas_device, 0);
616 * _scsih_raid_device_find_by_id - raid device search
617 * @ioc: per adapter object
618 * @id: sas device target id
619 * @channel: sas device channel
620 * Context: Calling function should acquire ioc->raid_device_lock
622 * This searches for raid_device based on target id, then return raid_device
625 static struct _raid_device *
626 _scsih_raid_device_find_by_id(struct MPT2SAS_ADAPTER *ioc, int id, int channel)
628 struct _raid_device *raid_device, *r;
631 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
632 if (raid_device->id == id && raid_device->channel == channel) {
643 * _scsih_raid_device_find_by_handle - raid device search
644 * @ioc: per adapter object
645 * @handle: sas device handle (assigned by firmware)
646 * Context: Calling function should acquire ioc->raid_device_lock
648 * This searches for raid_device based on handle, then return raid_device
651 static struct _raid_device *
652 _scsih_raid_device_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
654 struct _raid_device *raid_device, *r;
657 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
658 if (raid_device->handle != handle)
669 * _scsih_raid_device_find_by_wwid - raid device search
670 * @ioc: per adapter object
671 * @handle: sas device handle (assigned by firmware)
672 * Context: Calling function should acquire ioc->raid_device_lock
674 * This searches for raid_device based on wwid, then return raid_device
677 static struct _raid_device *
678 _scsih_raid_device_find_by_wwid(struct MPT2SAS_ADAPTER *ioc, u64 wwid)
680 struct _raid_device *raid_device, *r;
683 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
684 if (raid_device->wwid != wwid)
695 * _scsih_raid_device_add - add raid_device object
696 * @ioc: per adapter object
697 * @raid_device: raid_device object
699 * This is added to the raid_device_list link list.
702 _scsih_raid_device_add(struct MPT2SAS_ADAPTER *ioc,
703 struct _raid_device *raid_device)
707 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle"
708 "(0x%04x), wwid(0x%016llx)\n", ioc->name, __func__,
709 raid_device->handle, (unsigned long long)raid_device->wwid));
711 spin_lock_irqsave(&ioc->raid_device_lock, flags);
712 list_add_tail(&raid_device->list, &ioc->raid_device_list);
713 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
717 * _scsih_raid_device_remove - delete raid_device object
718 * @ioc: per adapter object
719 * @raid_device: raid_device object
721 * This is removed from the raid_device_list link list.
724 _scsih_raid_device_remove(struct MPT2SAS_ADAPTER *ioc,
725 struct _raid_device *raid_device)
729 spin_lock_irqsave(&ioc->raid_device_lock, flags);
730 list_del(&raid_device->list);
731 memset(raid_device, 0, sizeof(struct _raid_device));
733 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
737 * mpt2sas_scsih_expander_find_by_handle - expander device search
738 * @ioc: per adapter object
739 * @handle: expander handle (assigned by firmware)
740 * Context: Calling function should acquire ioc->sas_device_lock
742 * This searches for expander device based on handle, then returns the
746 mpt2sas_scsih_expander_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
748 struct _sas_node *sas_expander, *r;
751 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
752 if (sas_expander->handle != handle)
762 * mpt2sas_scsih_expander_find_by_sas_address - expander device search
763 * @ioc: per adapter object
764 * @sas_address: sas address
765 * Context: Calling function should acquire ioc->sas_node_lock.
767 * This searches for expander device based on sas_address, then returns the
771 mpt2sas_scsih_expander_find_by_sas_address(struct MPT2SAS_ADAPTER *ioc,
774 struct _sas_node *sas_expander, *r;
777 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
778 if (sas_expander->sas_address != sas_address)
788 * _scsih_expander_node_add - insert expander device to the list.
789 * @ioc: per adapter object
790 * @sas_expander: the sas_device object
791 * Context: This function will acquire ioc->sas_node_lock.
793 * Adding new object to the ioc->sas_expander_list.
798 _scsih_expander_node_add(struct MPT2SAS_ADAPTER *ioc,
799 struct _sas_node *sas_expander)
803 spin_lock_irqsave(&ioc->sas_node_lock, flags);
804 list_add_tail(&sas_expander->list, &ioc->sas_expander_list);
805 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
809 * _scsih_is_end_device - determines if device is an end device
810 * @device_info: bitfield providing information about the device.
813 * Returns 1 if end device.
816 _scsih_is_end_device(u32 device_info)
818 if (device_info & MPI2_SAS_DEVICE_INFO_END_DEVICE &&
819 ((device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) |
820 (device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) |
821 (device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE)))
828 * _scsih_scsi_lookup_get - returns scmd entry
829 * @ioc: per adapter object
830 * @smid: system request message index
832 * Returns the smid stored scmd pointer.
834 static struct scsi_cmnd *
835 _scsih_scsi_lookup_get(struct MPT2SAS_ADAPTER *ioc, u16 smid)
837 return ioc->scsi_lookup[smid - 1].scmd;
841 * _scsih_scsi_lookup_get_clear - returns scmd entry
842 * @ioc: per adapter object
843 * @smid: system request message index
845 * Returns the smid stored scmd pointer.
846 * Then will derefrence the stored scmd pointer.
848 static inline struct scsi_cmnd *
849 _scsih_scsi_lookup_get_clear(struct MPT2SAS_ADAPTER *ioc, u16 smid)
852 struct scsi_cmnd *scmd;
854 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
855 scmd = ioc->scsi_lookup[smid - 1].scmd;
856 ioc->scsi_lookup[smid - 1].scmd = NULL;
857 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
863 * _scsih_scsi_lookup_find_by_scmd - scmd lookup
864 * @ioc: per adapter object
865 * @smid: system request message index
866 * @scmd: pointer to scsi command object
867 * Context: This function will acquire ioc->scsi_lookup_lock.
869 * This will search for a scmd pointer in the scsi_lookup array,
870 * returning the revelent smid. A returned value of zero means invalid.
873 _scsih_scsi_lookup_find_by_scmd(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd
880 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
882 for (i = 0; i < ioc->scsiio_depth; i++) {
883 if (ioc->scsi_lookup[i].scmd == scmd) {
884 smid = ioc->scsi_lookup[i].smid;
889 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
894 * _scsih_scsi_lookup_find_by_target - search for matching channel:id
895 * @ioc: per adapter object
898 * Context: This function will acquire ioc->scsi_lookup_lock.
900 * This will search for a matching channel:id in the scsi_lookup array,
901 * returning 1 if found.
904 _scsih_scsi_lookup_find_by_target(struct MPT2SAS_ADAPTER *ioc, int id,
911 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
913 for (i = 0 ; i < ioc->scsiio_depth; i++) {
914 if (ioc->scsi_lookup[i].scmd &&
915 (ioc->scsi_lookup[i].scmd->device->id == id &&
916 ioc->scsi_lookup[i].scmd->device->channel == channel)) {
922 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
927 * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun
928 * @ioc: per adapter object
932 * Context: This function will acquire ioc->scsi_lookup_lock.
934 * This will search for a matching channel:id:lun in the scsi_lookup array,
935 * returning 1 if found.
938 _scsih_scsi_lookup_find_by_lun(struct MPT2SAS_ADAPTER *ioc, int id,
939 unsigned int lun, int channel)
945 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
947 for (i = 0 ; i < ioc->scsiio_depth; i++) {
948 if (ioc->scsi_lookup[i].scmd &&
949 (ioc->scsi_lookup[i].scmd->device->id == id &&
950 ioc->scsi_lookup[i].scmd->device->channel == channel &&
951 ioc->scsi_lookup[i].scmd->device->lun == lun)) {
957 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
962 * _scsih_get_chain_buffer_tracker - obtain chain tracker
963 * @ioc: per adapter object
964 * @smid: smid associated to an IO request
966 * Returns chain tracker(from ioc->free_chain_list)
968 static struct chain_tracker *
969 _scsih_get_chain_buffer_tracker(struct MPT2SAS_ADAPTER *ioc, u16 smid)
971 struct chain_tracker *chain_req;
974 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
975 if (list_empty(&ioc->free_chain_list)) {
976 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
977 printk(MPT2SAS_WARN_FMT "chain buffers not available\n",
981 chain_req = list_entry(ioc->free_chain_list.next,
982 struct chain_tracker, tracker_list);
983 list_del_init(&chain_req->tracker_list);
984 list_add_tail(&chain_req->tracker_list,
985 &ioc->scsi_lookup[smid - 1].chain_list);
986 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
991 * _scsih_build_scatter_gather - main sg creation routine
992 * @ioc: per adapter object
993 * @scmd: scsi command
994 * @smid: system request message index
997 * The main routine that builds scatter gather table from a given
998 * scsi request sent via the .queuecommand main handler.
1000 * Returns 0 success, anything else error
1003 _scsih_build_scatter_gather(struct MPT2SAS_ADAPTER *ioc,
1004 struct scsi_cmnd *scmd, u16 smid)
1006 Mpi2SCSIIORequest_t *mpi_request;
1007 dma_addr_t chain_dma;
1008 struct scatterlist *sg_scmd;
1009 void *sg_local, *chain;
1014 u32 sges_in_segment;
1016 u32 sgl_flags_last_element;
1017 u32 sgl_flags_end_buffer;
1018 struct chain_tracker *chain_req;
1020 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
1022 /* init scatter gather flags */
1023 sgl_flags = MPI2_SGE_FLAGS_SIMPLE_ELEMENT;
1024 if (scmd->sc_data_direction == DMA_TO_DEVICE)
1025 sgl_flags |= MPI2_SGE_FLAGS_HOST_TO_IOC;
1026 sgl_flags_last_element = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT)
1027 << MPI2_SGE_FLAGS_SHIFT;
1028 sgl_flags_end_buffer = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT |
1029 MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_END_OF_LIST)
1030 << MPI2_SGE_FLAGS_SHIFT;
1031 sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT;
1033 sg_scmd = scsi_sglist(scmd);
1034 sges_left = scsi_dma_map(scmd);
1035 if (sges_left < 0) {
1036 sdev_printk(KERN_ERR, scmd->device, "pci_map_sg"
1037 " failed: request for %d bytes!\n", scsi_bufflen(scmd));
1041 sg_local = &mpi_request->SGL;
1042 sges_in_segment = ioc->max_sges_in_main_message;
1043 if (sges_left <= sges_in_segment)
1044 goto fill_in_last_segment;
1046 mpi_request->ChainOffset = (offsetof(Mpi2SCSIIORequest_t, SGL) +
1047 (sges_in_segment * ioc->sge_size))/4;
1049 /* fill in main message segment when there is a chain following */
1050 while (sges_in_segment) {
1051 if (sges_in_segment == 1)
1052 ioc->base_add_sg_single(sg_local,
1053 sgl_flags_last_element | sg_dma_len(sg_scmd),
1054 sg_dma_address(sg_scmd));
1056 ioc->base_add_sg_single(sg_local, sgl_flags |
1057 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
1058 sg_scmd = sg_next(sg_scmd);
1059 sg_local += ioc->sge_size;
1064 /* initializing the chain flags and pointers */
1065 chain_flags = MPI2_SGE_FLAGS_CHAIN_ELEMENT << MPI2_SGE_FLAGS_SHIFT;
1066 chain_req = _scsih_get_chain_buffer_tracker(ioc, smid);
1069 chain = chain_req->chain_buffer;
1070 chain_dma = chain_req->chain_buffer_dma;
1072 sges_in_segment = (sges_left <=
1073 ioc->max_sges_in_chain_message) ? sges_left :
1074 ioc->max_sges_in_chain_message;
1075 chain_offset = (sges_left == sges_in_segment) ?
1076 0 : (sges_in_segment * ioc->sge_size)/4;
1077 chain_length = sges_in_segment * ioc->sge_size;
1079 chain_offset = chain_offset <<
1080 MPI2_SGE_CHAIN_OFFSET_SHIFT;
1081 chain_length += ioc->sge_size;
1083 ioc->base_add_sg_single(sg_local, chain_flags | chain_offset |
1084 chain_length, chain_dma);
1087 goto fill_in_last_segment;
1089 /* fill in chain segments */
1090 while (sges_in_segment) {
1091 if (sges_in_segment == 1)
1092 ioc->base_add_sg_single(sg_local,
1093 sgl_flags_last_element |
1094 sg_dma_len(sg_scmd),
1095 sg_dma_address(sg_scmd));
1097 ioc->base_add_sg_single(sg_local, sgl_flags |
1098 sg_dma_len(sg_scmd),
1099 sg_dma_address(sg_scmd));
1100 sg_scmd = sg_next(sg_scmd);
1101 sg_local += ioc->sge_size;
1106 chain_req = _scsih_get_chain_buffer_tracker(ioc, smid);
1109 chain = chain_req->chain_buffer;
1110 chain_dma = chain_req->chain_buffer_dma;
1114 fill_in_last_segment:
1116 /* fill the last segment */
1119 ioc->base_add_sg_single(sg_local, sgl_flags_end_buffer |
1120 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
1122 ioc->base_add_sg_single(sg_local, sgl_flags |
1123 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
1124 sg_scmd = sg_next(sg_scmd);
1125 sg_local += ioc->sge_size;
1133 * _scsih_adjust_queue_depth - setting device queue depth
1134 * @sdev: scsi device struct
1135 * @qdepth: requested queue depth
1141 _scsih_adjust_queue_depth(struct scsi_device *sdev, int qdepth)
1143 struct Scsi_Host *shost = sdev->host;
1145 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1146 struct MPT2SAS_DEVICE *sas_device_priv_data;
1147 struct MPT2SAS_TARGET *sas_target_priv_data;
1148 struct _sas_device *sas_device;
1149 unsigned long flags;
1151 max_depth = shost->can_queue;
1153 /* limit max device queue for SATA to 32 */
1154 sas_device_priv_data = sdev->hostdata;
1155 if (!sas_device_priv_data)
1157 sas_target_priv_data = sas_device_priv_data->sas_target;
1158 if (!sas_target_priv_data)
1160 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))
1162 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1163 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1164 sas_device_priv_data->sas_target->sas_address);
1165 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1166 if (sas_device && sas_device->device_info &
1167 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1168 max_depth = MPT2SAS_SATA_QUEUE_DEPTH;
1172 if (!sdev->tagged_supported)
1174 if (qdepth > max_depth)
1176 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
1180 * _scsih_change_queue_depth - setting device queue depth
1181 * @sdev: scsi device struct
1182 * @qdepth: requested queue depth
1183 * @reason: SCSI_QDEPTH_DEFAULT/SCSI_QDEPTH_QFULL/SCSI_QDEPTH_RAMP_UP
1184 * (see include/scsi/scsi_host.h for definition)
1186 * Returns queue depth.
1189 _scsih_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
1191 if (reason == SCSI_QDEPTH_DEFAULT || reason == SCSI_QDEPTH_RAMP_UP)
1192 _scsih_adjust_queue_depth(sdev, qdepth);
1193 else if (reason == SCSI_QDEPTH_QFULL)
1194 scsi_track_queue_full(sdev, qdepth);
1198 if (sdev->inquiry_len > 7)
1199 sdev_printk(KERN_INFO, sdev, "qdepth(%d), tagged(%d), "
1200 "simple(%d), ordered(%d), scsi_level(%d), cmd_que(%d)\n",
1201 sdev->queue_depth, sdev->tagged_supported, sdev->simple_tags,
1202 sdev->ordered_tags, sdev->scsi_level,
1203 (sdev->inquiry[7] & 2) >> 1);
1205 return sdev->queue_depth;
1209 * _scsih_change_queue_type - changing device queue tag type
1210 * @sdev: scsi device struct
1211 * @tag_type: requested tag type
1213 * Returns queue tag type.
1216 _scsih_change_queue_type(struct scsi_device *sdev, int tag_type)
1218 if (sdev->tagged_supported) {
1219 scsi_set_tag_type(sdev, tag_type);
1221 scsi_activate_tcq(sdev, sdev->queue_depth);
1223 scsi_deactivate_tcq(sdev, sdev->queue_depth);
1231 * _scsih_target_alloc - target add routine
1232 * @starget: scsi target struct
1234 * Returns 0 if ok. Any other return is assumed to be an error and
1235 * the device is ignored.
1238 _scsih_target_alloc(struct scsi_target *starget)
1240 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1241 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1242 struct MPT2SAS_TARGET *sas_target_priv_data;
1243 struct _sas_device *sas_device;
1244 struct _raid_device *raid_device;
1245 unsigned long flags;
1246 struct sas_rphy *rphy;
1248 sas_target_priv_data = kzalloc(sizeof(struct scsi_target), GFP_KERNEL);
1249 if (!sas_target_priv_data)
1252 starget->hostdata = sas_target_priv_data;
1253 sas_target_priv_data->starget = starget;
1254 sas_target_priv_data->handle = MPT2SAS_INVALID_DEVICE_HANDLE;
1257 if (starget->channel == RAID_CHANNEL) {
1258 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1259 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1262 sas_target_priv_data->handle = raid_device->handle;
1263 sas_target_priv_data->sas_address = raid_device->wwid;
1264 sas_target_priv_data->flags |= MPT_TARGET_FLAGS_VOLUME;
1265 sas_target_priv_data->raid_device = raid_device;
1266 raid_device->starget = starget;
1268 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1272 /* sas/sata devices */
1273 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1274 rphy = dev_to_rphy(starget->dev.parent);
1275 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1276 rphy->identify.sas_address);
1279 sas_target_priv_data->handle = sas_device->handle;
1280 sas_target_priv_data->sas_address = sas_device->sas_address;
1281 sas_device->starget = starget;
1282 sas_device->id = starget->id;
1283 sas_device->channel = starget->channel;
1284 if (test_bit(sas_device->handle, ioc->pd_handles))
1285 sas_target_priv_data->flags |=
1286 MPT_TARGET_FLAGS_RAID_COMPONENT;
1288 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1294 * _scsih_target_destroy - target destroy routine
1295 * @starget: scsi target struct
1300 _scsih_target_destroy(struct scsi_target *starget)
1302 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1303 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1304 struct MPT2SAS_TARGET *sas_target_priv_data;
1305 struct _sas_device *sas_device;
1306 struct _raid_device *raid_device;
1307 unsigned long flags;
1308 struct sas_rphy *rphy;
1310 sas_target_priv_data = starget->hostdata;
1311 if (!sas_target_priv_data)
1314 if (starget->channel == RAID_CHANNEL) {
1315 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1316 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1319 raid_device->starget = NULL;
1320 raid_device->sdev = NULL;
1322 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1326 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1327 rphy = dev_to_rphy(starget->dev.parent);
1328 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1329 rphy->identify.sas_address);
1330 if (sas_device && (sas_device->starget == starget) &&
1331 (sas_device->id == starget->id) &&
1332 (sas_device->channel == starget->channel))
1333 sas_device->starget = NULL;
1335 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1338 kfree(sas_target_priv_data);
1339 starget->hostdata = NULL;
1343 * _scsih_slave_alloc - device add routine
1344 * @sdev: scsi device struct
1346 * Returns 0 if ok. Any other return is assumed to be an error and
1347 * the device is ignored.
1350 _scsih_slave_alloc(struct scsi_device *sdev)
1352 struct Scsi_Host *shost;
1353 struct MPT2SAS_ADAPTER *ioc;
1354 struct MPT2SAS_TARGET *sas_target_priv_data;
1355 struct MPT2SAS_DEVICE *sas_device_priv_data;
1356 struct scsi_target *starget;
1357 struct _raid_device *raid_device;
1358 unsigned long flags;
1360 sas_device_priv_data = kzalloc(sizeof(struct scsi_device), GFP_KERNEL);
1361 if (!sas_device_priv_data)
1364 sas_device_priv_data->lun = sdev->lun;
1365 sas_device_priv_data->flags = MPT_DEVICE_FLAGS_INIT;
1367 starget = scsi_target(sdev);
1368 sas_target_priv_data = starget->hostdata;
1369 sas_target_priv_data->num_luns++;
1370 sas_device_priv_data->sas_target = sas_target_priv_data;
1371 sdev->hostdata = sas_device_priv_data;
1372 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT))
1373 sdev->no_uld_attach = 1;
1375 shost = dev_to_shost(&starget->dev);
1376 ioc = shost_priv(shost);
1377 if (starget->channel == RAID_CHANNEL) {
1378 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1379 raid_device = _scsih_raid_device_find_by_id(ioc,
1380 starget->id, starget->channel);
1382 raid_device->sdev = sdev; /* raid is single lun */
1383 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1390 * _scsih_slave_destroy - device destroy routine
1391 * @sdev: scsi device struct
1396 _scsih_slave_destroy(struct scsi_device *sdev)
1398 struct MPT2SAS_TARGET *sas_target_priv_data;
1399 struct scsi_target *starget;
1401 if (!sdev->hostdata)
1404 starget = scsi_target(sdev);
1405 sas_target_priv_data = starget->hostdata;
1406 sas_target_priv_data->num_luns--;
1407 kfree(sdev->hostdata);
1408 sdev->hostdata = NULL;
1412 * _scsih_display_sata_capabilities - sata capabilities
1413 * @ioc: per adapter object
1414 * @sas_device: the sas_device object
1415 * @sdev: scsi device struct
1418 _scsih_display_sata_capabilities(struct MPT2SAS_ADAPTER *ioc,
1419 struct _sas_device *sas_device, struct scsi_device *sdev)
1421 Mpi2ConfigReply_t mpi_reply;
1422 Mpi2SasDevicePage0_t sas_device_pg0;
1427 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
1428 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, sas_device->handle))) {
1429 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1430 ioc->name, __FILE__, __LINE__, __func__);
1434 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1435 MPI2_IOCSTATUS_MASK;
1436 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
1437 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1438 ioc->name, __FILE__, __LINE__, __func__);
1442 flags = le16_to_cpu(sas_device_pg0.Flags);
1443 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
1445 sdev_printk(KERN_INFO, sdev,
1446 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1447 "sw_preserve(%s)\n",
1448 (device_info & MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE) ? "y" : "n",
1449 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED) ? "y" : "n",
1450 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY) ? "y" :
1452 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED) ? "y" : "n",
1453 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED) ? "y" : "n",
1454 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE) ? "y" : "n");
1458 * _scsih_is_raid - return boolean indicating device is raid volume
1459 * @dev the device struct object
1462 _scsih_is_raid(struct device *dev)
1464 struct scsi_device *sdev = to_scsi_device(dev);
1465 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
1467 if (ioc->is_warpdrive)
1469 return (sdev->channel == RAID_CHANNEL) ? 1 : 0;
1473 * _scsih_get_resync - get raid volume resync percent complete
1474 * @dev the device struct object
1477 _scsih_get_resync(struct device *dev)
1479 struct scsi_device *sdev = to_scsi_device(dev);
1480 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
1481 static struct _raid_device *raid_device;
1482 unsigned long flags;
1483 Mpi2RaidVolPage0_t vol_pg0;
1484 Mpi2ConfigReply_t mpi_reply;
1485 u32 volume_status_flags;
1486 u8 percent_complete = 0;
1488 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1489 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1491 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1493 if (!raid_device || ioc->is_warpdrive)
1496 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
1497 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle,
1498 sizeof(Mpi2RaidVolPage0_t))) {
1499 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1500 ioc->name, __FILE__, __LINE__, __func__);
1504 volume_status_flags = le32_to_cpu(vol_pg0.VolumeStatusFlags);
1505 if (volume_status_flags & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS)
1506 percent_complete = raid_device->percent_complete;
1508 raid_set_resync(mpt2sas_raid_template, dev, percent_complete);
1512 * _scsih_get_state - get raid volume level
1513 * @dev the device struct object
1516 _scsih_get_state(struct device *dev)
1518 struct scsi_device *sdev = to_scsi_device(dev);
1519 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
1520 static struct _raid_device *raid_device;
1521 unsigned long flags;
1522 Mpi2RaidVolPage0_t vol_pg0;
1523 Mpi2ConfigReply_t mpi_reply;
1525 enum raid_state state = RAID_STATE_UNKNOWN;
1527 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1528 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1530 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1535 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
1536 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle,
1537 sizeof(Mpi2RaidVolPage0_t))) {
1538 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1539 ioc->name, __FILE__, __LINE__, __func__);
1543 volstate = le32_to_cpu(vol_pg0.VolumeStatusFlags);
1544 if (volstate & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS) {
1545 state = RAID_STATE_RESYNCING;
1549 switch (vol_pg0.VolumeState) {
1550 case MPI2_RAID_VOL_STATE_OPTIMAL:
1551 case MPI2_RAID_VOL_STATE_ONLINE:
1552 state = RAID_STATE_ACTIVE;
1554 case MPI2_RAID_VOL_STATE_DEGRADED:
1555 state = RAID_STATE_DEGRADED;
1557 case MPI2_RAID_VOL_STATE_FAILED:
1558 case MPI2_RAID_VOL_STATE_MISSING:
1559 state = RAID_STATE_OFFLINE;
1563 raid_set_state(mpt2sas_raid_template, dev, state);
1567 * _scsih_set_level - set raid level
1568 * @sdev: scsi device struct
1569 * @raid_device: raid_device object
1572 _scsih_set_level(struct scsi_device *sdev, struct _raid_device *raid_device)
1574 enum raid_level level = RAID_LEVEL_UNKNOWN;
1576 switch (raid_device->volume_type) {
1577 case MPI2_RAID_VOL_TYPE_RAID0:
1578 level = RAID_LEVEL_0;
1580 case MPI2_RAID_VOL_TYPE_RAID10:
1581 level = RAID_LEVEL_10;
1583 case MPI2_RAID_VOL_TYPE_RAID1E:
1584 level = RAID_LEVEL_1E;
1586 case MPI2_RAID_VOL_TYPE_RAID1:
1587 level = RAID_LEVEL_1;
1591 raid_set_level(mpt2sas_raid_template, &sdev->sdev_gendev, level);
1595 * _scsih_get_volume_capabilities - volume capabilities
1596 * @ioc: per adapter object
1597 * @sas_device: the raid_device object
1600 _scsih_get_volume_capabilities(struct MPT2SAS_ADAPTER *ioc,
1601 struct _raid_device *raid_device)
1603 Mpi2RaidVolPage0_t *vol_pg0;
1604 Mpi2RaidPhysDiskPage0_t pd_pg0;
1605 Mpi2SasDevicePage0_t sas_device_pg0;
1606 Mpi2ConfigReply_t mpi_reply;
1610 if ((mpt2sas_config_get_number_pds(ioc, raid_device->handle,
1611 &num_pds)) || !num_pds) {
1612 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1613 ioc->name, __FILE__, __LINE__, __func__);
1617 raid_device->num_pds = num_pds;
1618 sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
1619 sizeof(Mpi2RaidVol0PhysDisk_t));
1620 vol_pg0 = kzalloc(sz, GFP_KERNEL);
1622 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1623 ioc->name, __FILE__, __LINE__, __func__);
1627 if ((mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
1628 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
1629 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1630 ioc->name, __FILE__, __LINE__, __func__);
1635 raid_device->volume_type = vol_pg0->VolumeType;
1637 /* figure out what the underlying devices are by
1638 * obtaining the device_info bits for the 1st device
1640 if (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
1641 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
1642 vol_pg0->PhysDisk[0].PhysDiskNum))) {
1643 if (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
1644 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
1645 le16_to_cpu(pd_pg0.DevHandle)))) {
1646 raid_device->device_info =
1647 le32_to_cpu(sas_device_pg0.DeviceInfo);
1654 * _scsih_disable_ddio - Disable direct I/O for all the volumes
1655 * @ioc: per adapter object
1658 _scsih_disable_ddio(struct MPT2SAS_ADAPTER *ioc)
1660 Mpi2RaidVolPage1_t vol_pg1;
1661 Mpi2ConfigReply_t mpi_reply;
1662 struct _raid_device *raid_device;
1667 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
1668 &vol_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
1669 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1670 MPI2_IOCSTATUS_MASK;
1671 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
1673 handle = le16_to_cpu(vol_pg1.DevHandle);
1674 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
1676 raid_device->direct_io_enabled = 0;
1683 * _scsih_get_num_volumes - Get number of volumes in the ioc
1684 * @ioc: per adapter object
1687 _scsih_get_num_volumes(struct MPT2SAS_ADAPTER *ioc)
1689 Mpi2RaidVolPage1_t vol_pg1;
1690 Mpi2ConfigReply_t mpi_reply;
1696 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
1697 &vol_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
1698 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1699 MPI2_IOCSTATUS_MASK;
1700 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
1703 handle = le16_to_cpu(vol_pg1.DevHandle);
1710 * _scsih_init_warpdrive_properties - Set properties for warpdrive direct I/O.
1711 * @ioc: per adapter object
1712 * @raid_device: the raid_device object
1715 _scsih_init_warpdrive_properties(struct MPT2SAS_ADAPTER *ioc,
1716 struct _raid_device *raid_device)
1718 Mpi2RaidVolPage0_t *vol_pg0;
1719 Mpi2RaidPhysDiskPage0_t pd_pg0;
1720 Mpi2ConfigReply_t mpi_reply;
1723 u64 mb = 1024 * 1024;
1724 u64 tb_2 = 2 * mb * mb;
1729 if (!ioc->is_warpdrive)
1732 if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS) {
1733 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1734 "globally as drives are exposed\n", ioc->name);
1737 if (_scsih_get_num_volumes(ioc) > 1) {
1738 _scsih_disable_ddio(ioc);
1739 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1740 "globally as number of drives > 1\n", ioc->name);
1743 if ((mpt2sas_config_get_number_pds(ioc, raid_device->handle,
1744 &num_pds)) || !num_pds) {
1745 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1746 "Failure in computing number of drives\n", ioc->name);
1750 sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
1751 sizeof(Mpi2RaidVol0PhysDisk_t));
1752 vol_pg0 = kzalloc(sz, GFP_KERNEL);
1754 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1755 "Memory allocation failure for RVPG0\n", ioc->name);
1759 if ((mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
1760 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
1761 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1762 "Failure in retrieving RVPG0\n", ioc->name);
1768 * WARPDRIVE:If number of physical disks in a volume exceeds the max pds
1769 * assumed for WARPDRIVE, disable direct I/O
1771 if (num_pds > MPT_MAX_WARPDRIVE_PDS) {
1772 printk(MPT2SAS_WARN_FMT "WarpDrive : Direct IO is disabled "
1773 "for the drive with handle(0x%04x): num_mem=%d, "
1774 "max_mem_allowed=%d\n", ioc->name, raid_device->handle,
1775 num_pds, MPT_MAX_WARPDRIVE_PDS);
1779 for (count = 0; count < num_pds; count++) {
1780 if (mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
1781 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
1782 vol_pg0->PhysDisk[count].PhysDiskNum) ||
1783 pd_pg0.DevHandle == MPT2SAS_INVALID_DEVICE_HANDLE) {
1784 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is "
1785 "disabled for the drive with handle(0x%04x) member"
1786 "handle retrieval failed for member number=%d\n",
1787 ioc->name, raid_device->handle,
1788 vol_pg0->PhysDisk[count].PhysDiskNum);
1791 raid_device->pd_handle[count] = le16_to_cpu(pd_pg0.DevHandle);
1795 * Assumption for WD: Direct I/O is not supported if the volume is
1796 * not RAID0, if the stripe size is not 64KB, if the block size is
1797 * not 512 and if the volume size is >2TB
1799 if (raid_device->volume_type != MPI2_RAID_VOL_TYPE_RAID0 ||
1800 le16_to_cpu(vol_pg0->BlockSize) != 512) {
1801 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1802 "for the drive with handle(0x%04x): type=%d, "
1803 "s_sz=%uK, blk_size=%u\n", ioc->name,
1804 raid_device->handle, raid_device->volume_type,
1805 le32_to_cpu(vol_pg0->StripeSize)/2,
1806 le16_to_cpu(vol_pg0->BlockSize));
1810 capacity = (u64) le16_to_cpu(vol_pg0->BlockSize) *
1811 (le64_to_cpu(vol_pg0->MaxLBA) + 1);
1813 if (capacity > tb_2) {
1814 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1815 "for the drive with handle(0x%04x) since drive sz > 2TB\n",
1816 ioc->name, raid_device->handle);
1820 stripe_sz = le32_to_cpu(vol_pg0->StripeSize);
1822 for (i = 0; i < 32; i++) {
1829 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1830 "for the drive with handle(0x%04x) invalid stripe sz %uK\n",
1831 ioc->name, raid_device->handle,
1832 le32_to_cpu(vol_pg0->StripeSize)/2);
1835 raid_device->stripe_exponent = stripe_exp;
1836 raid_device->direct_io_enabled = 1;
1838 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is Enabled for the drive"
1839 " with handle(0x%04x)\n", ioc->name, raid_device->handle);
1841 * WARPDRIVE: Though the following fields are not used for direct IO,
1842 * stored for future purpose:
1844 raid_device->max_lba = le64_to_cpu(vol_pg0->MaxLBA);
1845 raid_device->stripe_sz = le32_to_cpu(vol_pg0->StripeSize);
1846 raid_device->block_sz = le16_to_cpu(vol_pg0->BlockSize);
1853 raid_device->direct_io_enabled = 0;
1854 for (count = 0; count < num_pds; count++)
1855 raid_device->pd_handle[count] = 0;
1861 * _scsih_enable_tlr - setting TLR flags
1862 * @ioc: per adapter object
1863 * @sdev: scsi device struct
1865 * Enabling Transaction Layer Retries for tape devices when
1866 * vpd page 0x90 is present
1870 _scsih_enable_tlr(struct MPT2SAS_ADAPTER *ioc, struct scsi_device *sdev)
1873 if (sdev->type != TYPE_TAPE)
1876 if (!(ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR))
1879 sas_enable_tlr(sdev);
1880 sdev_printk(KERN_INFO, sdev, "TLR %s\n",
1881 sas_is_tlr_enabled(sdev) ? "Enabled" : "Disabled");
1887 * _scsih_slave_configure - device configure routine.
1888 * @sdev: scsi device struct
1890 * Returns 0 if ok. Any other return is assumed to be an error and
1891 * the device is ignored.
1894 _scsih_slave_configure(struct scsi_device *sdev)
1896 struct Scsi_Host *shost = sdev->host;
1897 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1898 struct MPT2SAS_DEVICE *sas_device_priv_data;
1899 struct MPT2SAS_TARGET *sas_target_priv_data;
1900 struct _sas_device *sas_device;
1901 struct _raid_device *raid_device;
1902 unsigned long flags;
1909 sas_device_priv_data = sdev->hostdata;
1910 sas_device_priv_data->configured_lun = 1;
1911 sas_device_priv_data->flags &= ~MPT_DEVICE_FLAGS_INIT;
1912 sas_target_priv_data = sas_device_priv_data->sas_target;
1914 /* raid volume handling */
1915 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME) {
1917 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1918 raid_device = _scsih_raid_device_find_by_handle(ioc,
1919 sas_target_priv_data->handle);
1920 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1922 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1923 ioc->name, __FILE__, __LINE__, __func__);
1927 _scsih_get_volume_capabilities(ioc, raid_device);
1930 * WARPDRIVE: Initialize the required data for Direct IO
1932 _scsih_init_warpdrive_properties(ioc, raid_device);
1934 /* RAID Queue Depth Support
1935 * IS volume = underlying qdepth of drive type, either
1936 * MPT2SAS_SAS_QUEUE_DEPTH or MPT2SAS_SATA_QUEUE_DEPTH
1937 * IM/IME/R10 = 128 (MPT2SAS_RAID_QUEUE_DEPTH)
1939 if (raid_device->device_info &
1940 MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
1941 qdepth = MPT2SAS_SAS_QUEUE_DEPTH;
1944 qdepth = MPT2SAS_SATA_QUEUE_DEPTH;
1945 if (raid_device->device_info &
1946 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1952 switch (raid_device->volume_type) {
1953 case MPI2_RAID_VOL_TYPE_RAID0:
1956 case MPI2_RAID_VOL_TYPE_RAID1E:
1957 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
1958 if (ioc->manu_pg10.OEMIdentifier &&
1959 (ioc->manu_pg10.GenericFlags0 &
1960 MFG10_GF0_R10_DISPLAY) &&
1961 !(raid_device->num_pds % 2))
1966 case MPI2_RAID_VOL_TYPE_RAID1:
1967 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
1970 case MPI2_RAID_VOL_TYPE_RAID10:
1971 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
1974 case MPI2_RAID_VOL_TYPE_UNKNOWN:
1976 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
1981 if (!ioc->hide_ir_msg)
1982 sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), "
1983 "wwid(0x%016llx), pd_count(%d), type(%s)\n",
1984 r_level, raid_device->handle,
1985 (unsigned long long)raid_device->wwid,
1986 raid_device->num_pds, ds);
1987 _scsih_change_queue_depth(sdev, qdepth, SCSI_QDEPTH_DEFAULT);
1988 /* raid transport support */
1989 if (!ioc->is_warpdrive)
1990 _scsih_set_level(sdev, raid_device);
1994 /* non-raid handling */
1995 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1996 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1997 sas_device_priv_data->sas_target->sas_address);
1998 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2000 if (sas_target_priv_data->flags &
2001 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2002 mpt2sas_config_get_volume_handle(ioc,
2003 sas_device->handle, &sas_device->volume_handle);
2004 mpt2sas_config_get_volume_wwid(ioc,
2005 sas_device->volume_handle,
2006 &sas_device->volume_wwid);
2008 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
2009 qdepth = MPT2SAS_SAS_QUEUE_DEPTH;
2013 qdepth = MPT2SAS_SATA_QUEUE_DEPTH;
2014 if (sas_device->device_info &
2015 MPI2_SAS_DEVICE_INFO_STP_TARGET)
2017 else if (sas_device->device_info &
2018 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
2022 sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), "
2023 "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n",
2024 ds, sas_device->handle,
2025 (unsigned long long)sas_device->sas_address,
2027 (unsigned long long)sas_device->device_name);
2028 sdev_printk(KERN_INFO, sdev, "%s: "
2029 "enclosure_logical_id(0x%016llx), slot(%d)\n", ds,
2030 (unsigned long long) sas_device->enclosure_logical_id,
2034 _scsih_display_sata_capabilities(ioc, sas_device, sdev);
2037 _scsih_change_queue_depth(sdev, qdepth, SCSI_QDEPTH_DEFAULT);
2040 sas_read_port_mode_page(sdev);
2041 _scsih_enable_tlr(ioc, sdev);
2047 * _scsih_bios_param - fetch head, sector, cylinder info for a disk
2048 * @sdev: scsi device struct
2049 * @bdev: pointer to block device context
2050 * @capacity: device size (in 512 byte sectors)
2051 * @params: three element array to place output:
2052 * params[0] number of heads (max 255)
2053 * params[1] number of sectors (max 63)
2054 * params[2] number of cylinders
2059 _scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev,
2060 sector_t capacity, int params[])
2070 dummy = heads * sectors;
2071 cylinders = capacity;
2072 sector_div(cylinders, dummy);
2075 * Handle extended translation size for logical drives
2078 if ((ulong)capacity >= 0x200000) {
2081 dummy = heads * sectors;
2082 cylinders = capacity;
2083 sector_div(cylinders, dummy);
2088 params[1] = sectors;
2089 params[2] = cylinders;
2095 * _scsih_response_code - translation of device response code
2096 * @ioc: per adapter object
2097 * @response_code: response code returned by the device
2102 _scsih_response_code(struct MPT2SAS_ADAPTER *ioc, u8 response_code)
2106 switch (response_code) {
2107 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE:
2108 desc = "task management request completed";
2110 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME:
2111 desc = "invalid frame";
2113 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED:
2114 desc = "task management request not supported";
2116 case MPI2_SCSITASKMGMT_RSP_TM_FAILED:
2117 desc = "task management request failed";
2119 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED:
2120 desc = "task management request succeeded";
2122 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN:
2123 desc = "invalid lun";
2126 desc = "overlapped tag attempted";
2128 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC:
2129 desc = "task queued, however not sent to target";
2135 printk(MPT2SAS_WARN_FMT "response_code(0x%01x): %s\n",
2136 ioc->name, response_code, desc);
2140 * _scsih_tm_done - tm completion routine
2141 * @ioc: per adapter object
2142 * @smid: system request message index
2143 * @msix_index: MSIX table index supplied by the OS
2144 * @reply: reply message frame(lower 32bit addr)
2147 * The callback handler when using scsih_issue_tm.
2149 * Return 1 meaning mf should be freed from _base_interrupt
2150 * 0 means the mf is freed from this function.
2153 _scsih_tm_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
2155 MPI2DefaultReply_t *mpi_reply;
2157 if (ioc->tm_cmds.status == MPT2_CMD_NOT_USED)
2159 if (ioc->tm_cmds.smid != smid)
2161 ioc->tm_cmds.status |= MPT2_CMD_COMPLETE;
2162 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
2164 memcpy(ioc->tm_cmds.reply, mpi_reply, mpi_reply->MsgLength*4);
2165 ioc->tm_cmds.status |= MPT2_CMD_REPLY_VALID;
2167 ioc->tm_cmds.status &= ~MPT2_CMD_PENDING;
2168 complete(&ioc->tm_cmds.done);
2173 * mpt2sas_scsih_set_tm_flag - set per target tm_busy
2174 * @ioc: per adapter object
2175 * @handle: device handle
2177 * During taskmangement request, we need to freeze the device queue.
2180 mpt2sas_scsih_set_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2182 struct MPT2SAS_DEVICE *sas_device_priv_data;
2183 struct scsi_device *sdev;
2186 shost_for_each_device(sdev, ioc->shost) {
2189 sas_device_priv_data = sdev->hostdata;
2190 if (!sas_device_priv_data)
2192 if (sas_device_priv_data->sas_target->handle == handle) {
2193 sas_device_priv_data->sas_target->tm_busy = 1;
2195 ioc->ignore_loginfos = 1;
2201 * mpt2sas_scsih_clear_tm_flag - clear per target tm_busy
2202 * @ioc: per adapter object
2203 * @handle: device handle
2205 * During taskmangement request, we need to freeze the device queue.
2208 mpt2sas_scsih_clear_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2210 struct MPT2SAS_DEVICE *sas_device_priv_data;
2211 struct scsi_device *sdev;
2214 shost_for_each_device(sdev, ioc->shost) {
2217 sas_device_priv_data = sdev->hostdata;
2218 if (!sas_device_priv_data)
2220 if (sas_device_priv_data->sas_target->handle == handle) {
2221 sas_device_priv_data->sas_target->tm_busy = 0;
2223 ioc->ignore_loginfos = 0;
2230 * mpt2sas_scsih_issue_tm - main routine for sending tm requests
2231 * @ioc: per adapter struct
2232 * @device_handle: device handle
2233 * @channel: the channel assigned by the OS
2234 * @id: the id assigned by the OS
2236 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
2237 * @smid_task: smid assigned to the task
2238 * @timeout: timeout in seconds
2241 * A generic API for sending task management requests to firmware.
2243 * The callback index is set inside `ioc->tm_cb_idx`.
2245 * Return SUCCESS or FAILED.
2248 mpt2sas_scsih_issue_tm(struct MPT2SAS_ADAPTER *ioc, u16 handle, uint channel,
2249 uint id, uint lun, u8 type, u16 smid_task, ulong timeout,
2250 struct scsi_cmnd *scmd)
2252 Mpi2SCSITaskManagementRequest_t *mpi_request;
2253 Mpi2SCSITaskManagementReply_t *mpi_reply;
2256 unsigned long timeleft;
2257 struct scsi_cmnd *scmd_lookup;
2260 mutex_lock(&ioc->tm_cmds.mutex);
2261 if (ioc->tm_cmds.status != MPT2_CMD_NOT_USED) {
2262 printk(MPT2SAS_INFO_FMT "%s: tm_cmd busy!!!\n",
2263 __func__, ioc->name);
2268 if (ioc->shost_recovery || ioc->remove_host ||
2269 ioc->pci_error_recovery) {
2270 printk(MPT2SAS_INFO_FMT "%s: host reset in progress!\n",
2271 __func__, ioc->name);
2276 ioc_state = mpt2sas_base_get_iocstate(ioc, 0);
2277 if (ioc_state & MPI2_DOORBELL_USED) {
2278 dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "unexpected doorbell "
2279 "active!\n", ioc->name));
2280 mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2286 if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) {
2287 mpt2sas_base_fault_info(ioc, ioc_state &
2288 MPI2_DOORBELL_DATA_MASK);
2289 mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2295 smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_cb_idx);
2297 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
2298 ioc->name, __func__);
2303 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "sending tm: handle(0x%04x),"
2304 " task_type(0x%02x), smid(%d)\n", ioc->name, handle, type,
2306 ioc->tm_cmds.status = MPT2_CMD_PENDING;
2307 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
2308 ioc->tm_cmds.smid = smid;
2309 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
2310 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
2311 mpi_request->DevHandle = cpu_to_le16(handle);
2312 mpi_request->TaskType = type;
2313 mpi_request->TaskMID = cpu_to_le16(smid_task);
2314 int_to_scsilun(lun, (struct scsi_lun *)mpi_request->LUN);
2315 mpt2sas_scsih_set_tm_flag(ioc, handle);
2316 init_completion(&ioc->tm_cmds.done);
2317 mpt2sas_base_put_smid_hi_priority(ioc, smid);
2318 timeleft = wait_for_completion_timeout(&ioc->tm_cmds.done, timeout*HZ);
2319 if (!(ioc->tm_cmds.status & MPT2_CMD_COMPLETE)) {
2320 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
2321 ioc->name, __func__);
2322 _debug_dump_mf(mpi_request,
2323 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
2324 if (!(ioc->tm_cmds.status & MPT2_CMD_RESET)) {
2325 mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2328 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
2329 mpt2sas_scsih_clear_tm_flag(ioc, handle);
2334 if (ioc->tm_cmds.status & MPT2_CMD_REPLY_VALID) {
2335 mpi_reply = ioc->tm_cmds.reply;
2336 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "complete tm: "
2337 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
2338 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
2339 le32_to_cpu(mpi_reply->IOCLogInfo),
2340 le32_to_cpu(mpi_reply->TerminationCount)));
2341 if (ioc->logging_level & MPT_DEBUG_TM) {
2342 _scsih_response_code(ioc, mpi_reply->ResponseCode);
2343 if (mpi_reply->IOCStatus)
2344 _debug_dump_mf(mpi_request,
2345 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
2350 * Check to see the commands were terminated.
2351 * This is only needed for eh callbacks, hence the scmd check.
2355 goto bypass_sanity_checks;
2357 case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK:
2358 scmd_lookup = _scsih_scsi_lookup_get(ioc, smid_task);
2365 case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET:
2366 if (_scsih_scsi_lookup_find_by_target(ioc, id, channel))
2372 case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET:
2373 if (_scsih_scsi_lookup_find_by_lun(ioc, id, lun, channel))
2380 bypass_sanity_checks:
2382 mpt2sas_scsih_clear_tm_flag(ioc, handle);
2383 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
2384 mutex_unlock(&ioc->tm_cmds.mutex);
2389 mutex_unlock(&ioc->tm_cmds.mutex);
2394 * _scsih_tm_display_info - displays info about the device
2395 * @ioc: per adapter struct
2396 * @scmd: pointer to scsi command object
2398 * Called by task management callback handlers.
2401 _scsih_tm_display_info(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd)
2403 struct scsi_target *starget = scmd->device->sdev_target;
2404 struct MPT2SAS_TARGET *priv_target = starget->hostdata;
2405 struct _sas_device *sas_device = NULL;
2406 unsigned long flags;
2407 char *device_str = NULL;
2411 if (ioc->hide_ir_msg)
2412 device_str = "WarpDrive";
2414 device_str = "volume";
2416 scsi_print_command(scmd);
2417 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
2418 starget_printk(KERN_INFO, starget, "%s handle(0x%04x), "
2419 "%s wwid(0x%016llx)\n", device_str, priv_target->handle,
2420 device_str, (unsigned long long)priv_target->sas_address);
2422 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2423 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
2424 priv_target->sas_address);
2426 if (priv_target->flags &
2427 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2428 starget_printk(KERN_INFO, starget,
2429 "volume handle(0x%04x), "
2430 "volume wwid(0x%016llx)\n",
2431 sas_device->volume_handle,
2432 (unsigned long long)sas_device->volume_wwid);
2434 starget_printk(KERN_INFO, starget,
2435 "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n",
2437 (unsigned long long)sas_device->sas_address,
2439 starget_printk(KERN_INFO, starget,
2440 "enclosure_logical_id(0x%016llx), slot(%d)\n",
2441 (unsigned long long)sas_device->enclosure_logical_id,
2444 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2449 * _scsih_abort - eh threads main abort routine
2450 * @scmd: pointer to scsi command object
2452 * Returns SUCCESS if command aborted else FAILED
2455 _scsih_abort(struct scsi_cmnd *scmd)
2457 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2458 struct MPT2SAS_DEVICE *sas_device_priv_data;
2463 sdev_printk(KERN_INFO, scmd->device, "attempting task abort! "
2464 "scmd(%p)\n", scmd);
2465 _scsih_tm_display_info(ioc, scmd);
2467 sas_device_priv_data = scmd->device->hostdata;
2468 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2469 sdev_printk(KERN_INFO, scmd->device, "device been deleted! "
2470 "scmd(%p)\n", scmd);
2471 scmd->result = DID_NO_CONNECT << 16;
2472 scmd->scsi_done(scmd);
2477 /* search for the command */
2478 smid = _scsih_scsi_lookup_find_by_scmd(ioc, scmd);
2480 scmd->result = DID_RESET << 16;
2485 /* for hidden raid components and volumes this is not supported */
2486 if (sas_device_priv_data->sas_target->flags &
2487 MPT_TARGET_FLAGS_RAID_COMPONENT ||
2488 sas_device_priv_data->sas_target->flags & MPT_TARGET_FLAGS_VOLUME) {
2489 scmd->result = DID_RESET << 16;
2494 mpt2sas_halt_firmware(ioc);
2496 handle = sas_device_priv_data->sas_target->handle;
2497 r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2498 scmd->device->id, scmd->device->lun,
2499 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30, scmd);
2502 sdev_printk(KERN_INFO, scmd->device, "task abort: %s scmd(%p)\n",
2503 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2508 * _scsih_dev_reset - eh threads main device reset routine
2509 * @scmd: pointer to scsi command object
2511 * Returns SUCCESS if command aborted else FAILED
2514 _scsih_dev_reset(struct scsi_cmnd *scmd)
2516 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2517 struct MPT2SAS_DEVICE *sas_device_priv_data;
2518 struct _sas_device *sas_device;
2519 unsigned long flags;
2523 struct scsi_target *starget = scmd->device->sdev_target;
2525 starget_printk(KERN_INFO, starget, "attempting device reset! "
2526 "scmd(%p)\n", scmd);
2527 _scsih_tm_display_info(ioc, scmd);
2529 sas_device_priv_data = scmd->device->hostdata;
2530 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2531 starget_printk(KERN_INFO, starget, "device been deleted! "
2532 "scmd(%p)\n", scmd);
2533 scmd->result = DID_NO_CONNECT << 16;
2534 scmd->scsi_done(scmd);
2539 /* for hidden raid components obtain the volume_handle */
2541 if (sas_device_priv_data->sas_target->flags &
2542 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2543 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2544 sas_device = _scsih_sas_device_find_by_handle(ioc,
2545 sas_device_priv_data->sas_target->handle);
2547 handle = sas_device->volume_handle;
2548 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2550 handle = sas_device_priv_data->sas_target->handle;
2553 scmd->result = DID_RESET << 16;
2558 r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2559 scmd->device->id, scmd->device->lun,
2560 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, 0, 30, scmd);
2563 sdev_printk(KERN_INFO, scmd->device, "device reset: %s scmd(%p)\n",
2564 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2569 * _scsih_target_reset - eh threads main target reset routine
2570 * @scmd: pointer to scsi command object
2572 * Returns SUCCESS if command aborted else FAILED
2575 _scsih_target_reset(struct scsi_cmnd *scmd)
2577 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2578 struct MPT2SAS_DEVICE *sas_device_priv_data;
2579 struct _sas_device *sas_device;
2580 unsigned long flags;
2583 struct scsi_target *starget = scmd->device->sdev_target;
2585 starget_printk(KERN_INFO, starget, "attempting target reset! "
2586 "scmd(%p)\n", scmd);
2587 _scsih_tm_display_info(ioc, scmd);
2589 sas_device_priv_data = scmd->device->hostdata;
2590 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2591 starget_printk(KERN_INFO, starget, "target been deleted! "
2592 "scmd(%p)\n", scmd);
2593 scmd->result = DID_NO_CONNECT << 16;
2594 scmd->scsi_done(scmd);
2599 /* for hidden raid components obtain the volume_handle */
2601 if (sas_device_priv_data->sas_target->flags &
2602 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2603 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2604 sas_device = _scsih_sas_device_find_by_handle(ioc,
2605 sas_device_priv_data->sas_target->handle);
2607 handle = sas_device->volume_handle;
2608 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2610 handle = sas_device_priv_data->sas_target->handle;
2613 scmd->result = DID_RESET << 16;
2618 r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2619 scmd->device->id, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0,
2623 starget_printk(KERN_INFO, starget, "target reset: %s scmd(%p)\n",
2624 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2629 * _scsih_host_reset - eh threads main host reset routine
2630 * @scmd: pointer to scsi command object
2632 * Returns SUCCESS if command aborted else FAILED
2635 _scsih_host_reset(struct scsi_cmnd *scmd)
2637 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2640 printk(MPT2SAS_INFO_FMT "attempting host reset! scmd(%p)\n",
2642 scsi_print_command(scmd);
2644 retval = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2646 r = (retval < 0) ? FAILED : SUCCESS;
2647 printk(MPT2SAS_INFO_FMT "host reset: %s scmd(%p)\n",
2648 ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2654 * _scsih_fw_event_add - insert and queue up fw_event
2655 * @ioc: per adapter object
2656 * @fw_event: object describing the event
2657 * Context: This function will acquire ioc->fw_event_lock.
2659 * This adds the firmware event object into link list, then queues it up to
2660 * be processed from user context.
2665 _scsih_fw_event_add(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
2667 unsigned long flags;
2669 if (ioc->firmware_event_thread == NULL)
2672 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2673 list_add_tail(&fw_event->list, &ioc->fw_event_list);
2674 INIT_DELAYED_WORK(&fw_event->delayed_work, _firmware_event_work);
2675 queue_delayed_work(ioc->firmware_event_thread,
2676 &fw_event->delayed_work, 0);
2677 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2681 * _scsih_fw_event_free - delete fw_event
2682 * @ioc: per adapter object
2683 * @fw_event: object describing the event
2684 * Context: This function will acquire ioc->fw_event_lock.
2686 * This removes firmware event object from link list, frees associated memory.
2691 _scsih_fw_event_free(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work
2694 unsigned long flags;
2696 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2697 list_del(&fw_event->list);
2698 kfree(fw_event->event_data);
2700 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2705 * _scsih_queue_rescan - queue a topology rescan from user context
2706 * @ioc: per adapter object
2711 _scsih_queue_rescan(struct MPT2SAS_ADAPTER *ioc)
2713 struct fw_event_work *fw_event;
2715 if (ioc->wait_for_port_enable_to_complete)
2717 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
2720 fw_event->event = MPT2SAS_RESCAN_AFTER_HOST_RESET;
2721 fw_event->ioc = ioc;
2722 _scsih_fw_event_add(ioc, fw_event);
2726 * _scsih_fw_event_cleanup_queue - cleanup event queue
2727 * @ioc: per adapter object
2729 * Walk the firmware event queue, either killing timers, or waiting
2730 * for outstanding events to complete
2735 _scsih_fw_event_cleanup_queue(struct MPT2SAS_ADAPTER *ioc)
2737 struct fw_event_work *fw_event, *next;
2739 if (list_empty(&ioc->fw_event_list) ||
2740 !ioc->firmware_event_thread || in_interrupt())
2743 list_for_each_entry_safe(fw_event, next, &ioc->fw_event_list, list) {
2744 if (cancel_delayed_work(&fw_event->delayed_work)) {
2745 _scsih_fw_event_free(ioc, fw_event);
2748 fw_event->cancel_pending_work = 1;
2753 * _scsih_ublock_io_device - set the device state to SDEV_RUNNING
2754 * @ioc: per adapter object
2755 * @handle: device handle
2757 * During device pull we need to appropiately set the sdev state.
2760 _scsih_ublock_io_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2762 struct MPT2SAS_DEVICE *sas_device_priv_data;
2763 struct scsi_device *sdev;
2765 shost_for_each_device(sdev, ioc->shost) {
2766 sas_device_priv_data = sdev->hostdata;
2767 if (!sas_device_priv_data)
2769 if (!sas_device_priv_data->block)
2771 if (sas_device_priv_data->sas_target->handle == handle) {
2772 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
2773 MPT2SAS_INFO_FMT "SDEV_RUNNING: "
2774 "handle(0x%04x)\n", ioc->name, handle));
2775 sas_device_priv_data->block = 0;
2776 scsi_internal_device_unblock(sdev);
2782 * _scsih_block_io_device - set the device state to SDEV_BLOCK
2783 * @ioc: per adapter object
2784 * @handle: device handle
2786 * During device pull we need to appropiately set the sdev state.
2789 _scsih_block_io_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2791 struct MPT2SAS_DEVICE *sas_device_priv_data;
2792 struct scsi_device *sdev;
2794 shost_for_each_device(sdev, ioc->shost) {
2795 sas_device_priv_data = sdev->hostdata;
2796 if (!sas_device_priv_data)
2798 if (sas_device_priv_data->block)
2800 if (sas_device_priv_data->sas_target->handle == handle) {
2801 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
2802 MPT2SAS_INFO_FMT "SDEV_BLOCK: "
2803 "handle(0x%04x)\n", ioc->name, handle));
2804 sas_device_priv_data->block = 1;
2805 scsi_internal_device_block(sdev);
2811 * _scsih_block_io_to_children_attached_to_ex
2812 * @ioc: per adapter object
2813 * @sas_expander: the sas_device object
2815 * This routine set sdev state to SDEV_BLOCK for all devices
2816 * attached to this expander. This function called when expander is
2820 _scsih_block_io_to_children_attached_to_ex(struct MPT2SAS_ADAPTER *ioc,
2821 struct _sas_node *sas_expander)
2823 struct _sas_port *mpt2sas_port;
2824 struct _sas_device *sas_device;
2825 struct _sas_node *expander_sibling;
2826 unsigned long flags;
2831 list_for_each_entry(mpt2sas_port,
2832 &sas_expander->sas_port_list, port_list) {
2833 if (mpt2sas_port->remote_identify.device_type ==
2835 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2837 mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
2838 mpt2sas_port->remote_identify.sas_address);
2839 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2842 _scsih_block_io_device(ioc, sas_device->handle);
2846 list_for_each_entry(mpt2sas_port,
2847 &sas_expander->sas_port_list, port_list) {
2849 if (mpt2sas_port->remote_identify.device_type ==
2850 SAS_EDGE_EXPANDER_DEVICE ||
2851 mpt2sas_port->remote_identify.device_type ==
2852 SAS_FANOUT_EXPANDER_DEVICE) {
2854 spin_lock_irqsave(&ioc->sas_node_lock, flags);
2856 mpt2sas_scsih_expander_find_by_sas_address(
2857 ioc, mpt2sas_port->remote_identify.sas_address);
2858 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
2859 _scsih_block_io_to_children_attached_to_ex(ioc,
2866 * _scsih_block_io_to_children_attached_directly
2867 * @ioc: per adapter object
2868 * @event_data: topology change event data
2870 * This routine set sdev state to SDEV_BLOCK for all devices
2871 * direct attached during device pull.
2874 _scsih_block_io_to_children_attached_directly(struct MPT2SAS_ADAPTER *ioc,
2875 Mpi2EventDataSasTopologyChangeList_t *event_data)
2882 for (i = 0; i < event_data->NumEntries; i++) {
2883 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
2886 phy_number = event_data->StartPhyNum + i;
2887 reason_code = event_data->PHY[i].PhyStatus &
2888 MPI2_EVENT_SAS_TOPO_RC_MASK;
2889 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING)
2890 _scsih_block_io_device(ioc, handle);
2895 * _scsih_tm_tr_send - send task management request
2896 * @ioc: per adapter object
2897 * @handle: device handle
2898 * Context: interrupt time.
2900 * This code is to initiate the device removal handshake protocol
2901 * with controller firmware. This function will issue target reset
2902 * using high priority request queue. It will send a sas iounit
2903 * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
2905 * This is designed to send muliple task management request at the same
2906 * time to the fifo. If the fifo is full, we will append the request,
2907 * and process it in a future completion.
2910 _scsih_tm_tr_send(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2912 Mpi2SCSITaskManagementRequest_t *mpi_request;
2914 struct _sas_device *sas_device;
2915 struct MPT2SAS_TARGET *sas_target_priv_data;
2916 unsigned long flags;
2917 struct _tr_list *delayed_tr;
2919 if (ioc->shost_recovery || ioc->remove_host ||
2920 ioc->pci_error_recovery) {
2921 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in "
2922 "progress!\n", __func__, ioc->name));
2926 /* if PD, then return */
2927 if (test_bit(handle, ioc->pd_handles))
2930 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2931 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
2932 if (sas_device && sas_device->starget &&
2933 sas_device->starget->hostdata) {
2934 sas_target_priv_data = sas_device->starget->hostdata;
2935 sas_target_priv_data->deleted = 1;
2936 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
2937 "setting delete flag: handle(0x%04x), "
2938 "sas_addr(0x%016llx)\n", ioc->name, handle,
2939 (unsigned long long) sas_device->sas_address));
2941 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2943 smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_tr_cb_idx);
2945 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
2948 INIT_LIST_HEAD(&delayed_tr->list);
2949 delayed_tr->handle = handle;
2950 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
2951 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
2952 "DELAYED:tr:handle(0x%04x), (open)\n",
2953 ioc->name, handle));
2957 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "tr_send:handle(0x%04x), "
2958 "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid,
2959 ioc->tm_tr_cb_idx));
2960 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
2961 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
2962 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
2963 mpi_request->DevHandle = cpu_to_le16(handle);
2964 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
2965 mpt2sas_base_put_smid_hi_priority(ioc, smid);
2971 * _scsih_sas_control_complete - completion routine
2972 * @ioc: per adapter object
2973 * @smid: system request message index
2974 * @msix_index: MSIX table index supplied by the OS
2975 * @reply: reply message frame(lower 32bit addr)
2976 * Context: interrupt time.
2978 * This is the sas iounit control completion routine.
2979 * This code is part of the code to initiate the device removal
2980 * handshake protocol with controller firmware.
2982 * Return 1 meaning mf should be freed from _base_interrupt
2983 * 0 means the mf is freed from this function.
2986 _scsih_sas_control_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid,
2987 u8 msix_index, u32 reply)
2989 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
2990 Mpi2SasIoUnitControlReply_t *mpi_reply =
2991 mpt2sas_base_get_reply_virt_addr(ioc, reply);
2993 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
2994 "sc_complete:handle(0x%04x), (open) "
2995 "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
2996 ioc->name, le16_to_cpu(mpi_reply->DevHandle), smid,
2997 le16_to_cpu(mpi_reply->IOCStatus),
2998 le32_to_cpu(mpi_reply->IOCLogInfo)));
3003 * _scsih_tm_tr_volume_send - send target reset request for volumes
3004 * @ioc: per adapter object
3005 * @handle: device handle
3006 * Context: interrupt time.
3008 * This is designed to send muliple task management request at the same
3009 * time to the fifo. If the fifo is full, we will append the request,
3010 * and process it in a future completion.
3013 _scsih_tm_tr_volume_send(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3015 Mpi2SCSITaskManagementRequest_t *mpi_request;
3017 struct _tr_list *delayed_tr;
3019 if (ioc->shost_recovery || ioc->remove_host ||
3020 ioc->pci_error_recovery) {
3021 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in "
3022 "progress!\n", __func__, ioc->name));
3026 smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_tr_volume_cb_idx);
3028 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3031 INIT_LIST_HEAD(&delayed_tr->list);
3032 delayed_tr->handle = handle;
3033 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_volume_list);
3034 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3035 "DELAYED:tr:handle(0x%04x), (open)\n",
3036 ioc->name, handle));
3040 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "tr_send:handle(0x%04x), "
3041 "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid,
3042 ioc->tm_tr_volume_cb_idx));
3043 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3044 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
3045 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3046 mpi_request->DevHandle = cpu_to_le16(handle);
3047 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
3048 mpt2sas_base_put_smid_hi_priority(ioc, smid);
3052 * _scsih_tm_volume_tr_complete - target reset completion
3053 * @ioc: per adapter object
3054 * @smid: system request message index
3055 * @msix_index: MSIX table index supplied by the OS
3056 * @reply: reply message frame(lower 32bit addr)
3057 * Context: interrupt time.
3059 * Return 1 meaning mf should be freed from _base_interrupt
3060 * 0 means the mf is freed from this function.
3063 _scsih_tm_volume_tr_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid,
3064 u8 msix_index, u32 reply)
3067 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
3068 Mpi2SCSITaskManagementReply_t *mpi_reply =
3069 mpt2sas_base_get_reply_virt_addr(ioc, reply);
3071 if (ioc->shost_recovery || ioc->remove_host ||
3072 ioc->pci_error_recovery) {
3073 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in "
3074 "progress!\n", __func__, ioc->name));
3078 mpi_request_tm = mpt2sas_base_get_msg_frame(ioc, smid);
3079 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3080 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3081 dewtprintk(ioc, printk("spurious interrupt: "
3082 "handle(0x%04x:0x%04x), smid(%d)!!!\n", handle,
3083 le16_to_cpu(mpi_reply->DevHandle), smid));
3087 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3088 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3089 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3090 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3091 le32_to_cpu(mpi_reply->IOCLogInfo),
3092 le32_to_cpu(mpi_reply->TerminationCount)));
3094 return _scsih_check_for_pending_tm(ioc, smid);
3098 * _scsih_tm_tr_complete -
3099 * @ioc: per adapter object
3100 * @smid: system request message index
3101 * @msix_index: MSIX table index supplied by the OS
3102 * @reply: reply message frame(lower 32bit addr)
3103 * Context: interrupt time.
3105 * This is the target reset completion routine.
3106 * This code is part of the code to initiate the device removal
3107 * handshake protocol with controller firmware.
3108 * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE)
3110 * Return 1 meaning mf should be freed from _base_interrupt
3111 * 0 means the mf is freed from this function.
3114 _scsih_tm_tr_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
3118 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
3119 Mpi2SCSITaskManagementReply_t *mpi_reply =
3120 mpt2sas_base_get_reply_virt_addr(ioc, reply);
3121 Mpi2SasIoUnitControlRequest_t *mpi_request;
3124 if (ioc->shost_recovery || ioc->remove_host ||
3125 ioc->pci_error_recovery) {
3126 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in "
3127 "progress!\n", __func__, ioc->name));
3131 mpi_request_tm = mpt2sas_base_get_msg_frame(ioc, smid);
3132 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3133 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3134 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "spurious interrupt: "
3135 "handle(0x%04x:0x%04x), smid(%d)!!!\n", ioc->name, handle,
3136 le16_to_cpu(mpi_reply->DevHandle), smid));
3140 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3141 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3142 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3143 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3144 le32_to_cpu(mpi_reply->IOCLogInfo),
3145 le32_to_cpu(mpi_reply->TerminationCount)));
3147 smid_sas_ctrl = mpt2sas_base_get_smid(ioc, ioc->tm_sas_control_cb_idx);
3148 if (!smid_sas_ctrl) {
3149 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3150 ioc->name, __func__);
3154 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "sc_send:handle(0x%04x), "
3155 "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid_sas_ctrl,
3156 ioc->tm_sas_control_cb_idx));
3157 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid_sas_ctrl);
3158 memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t));
3159 mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL;
3160 mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE;
3161 mpi_request->DevHandle = mpi_request_tm->DevHandle;
3162 mpt2sas_base_put_smid_default(ioc, smid_sas_ctrl);
3164 return _scsih_check_for_pending_tm(ioc, smid);
3168 * _scsih_check_for_pending_tm - check for pending task management
3169 * @ioc: per adapter object
3170 * @smid: system request message index
3172 * This will check delayed target reset list, and feed the
3175 * Return 1 meaning mf should be freed from _base_interrupt
3176 * 0 means the mf is freed from this function.
3179 _scsih_check_for_pending_tm(struct MPT2SAS_ADAPTER *ioc, u16 smid)
3181 struct _tr_list *delayed_tr;
3183 if (!list_empty(&ioc->delayed_tr_volume_list)) {
3184 delayed_tr = list_entry(ioc->delayed_tr_volume_list.next,
3185 struct _tr_list, list);
3186 mpt2sas_base_free_smid(ioc, smid);
3187 _scsih_tm_tr_volume_send(ioc, delayed_tr->handle);
3188 list_del(&delayed_tr->list);
3193 if (!list_empty(&ioc->delayed_tr_list)) {
3194 delayed_tr = list_entry(ioc->delayed_tr_list.next,
3195 struct _tr_list, list);
3196 mpt2sas_base_free_smid(ioc, smid);
3197 _scsih_tm_tr_send(ioc, delayed_tr->handle);
3198 list_del(&delayed_tr->list);
3207 * _scsih_check_topo_delete_events - sanity check on topo events
3208 * @ioc: per adapter object
3209 * @event_data: the event data payload
3211 * This routine added to better handle cable breaker.
3213 * This handles the case where driver receives multiple expander
3214 * add and delete events in a single shot. When there is a delete event
3215 * the routine will void any pending add events waiting in the event queue.
3220 _scsih_check_topo_delete_events(struct MPT2SAS_ADAPTER *ioc,
3221 Mpi2EventDataSasTopologyChangeList_t *event_data)
3223 struct fw_event_work *fw_event;
3224 Mpi2EventDataSasTopologyChangeList_t *local_event_data;
3225 u16 expander_handle;
3226 struct _sas_node *sas_expander;
3227 unsigned long flags;
3231 for (i = 0 ; i < event_data->NumEntries; i++) {
3232 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
3235 reason_code = event_data->PHY[i].PhyStatus &
3236 MPI2_EVENT_SAS_TOPO_RC_MASK;
3237 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING)
3238 _scsih_tm_tr_send(ioc, handle);
3241 expander_handle = le16_to_cpu(event_data->ExpanderDevHandle);
3242 if (expander_handle < ioc->sas_hba.num_phys) {
3243 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3247 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
3248 || event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING) {
3249 spin_lock_irqsave(&ioc->sas_node_lock, flags);
3250 sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc,
3252 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
3253 _scsih_block_io_to_children_attached_to_ex(ioc, sas_expander);
3254 } else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING)
3255 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3257 if (event_data->ExpStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING)
3260 /* mark ignore flag for pending events */
3261 spin_lock_irqsave(&ioc->fw_event_lock, flags);
3262 list_for_each_entry(fw_event, &ioc->fw_event_list, list) {
3263 if (fw_event->event != MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST ||
3266 local_event_data = fw_event->event_data;
3267 if (local_event_data->ExpStatus ==
3268 MPI2_EVENT_SAS_TOPO_ES_ADDED ||
3269 local_event_data->ExpStatus ==
3270 MPI2_EVENT_SAS_TOPO_ES_RESPONDING) {
3271 if (le16_to_cpu(local_event_data->ExpanderDevHandle) ==
3273 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3274 "setting ignoring flag\n", ioc->name));
3275 fw_event->ignore = 1;
3279 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
3283 * _scsih_set_volume_delete_flag - setting volume delete flag
3284 * @ioc: per adapter object
3285 * @handle: device handle
3291 _scsih_set_volume_delete_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3293 struct _raid_device *raid_device;
3294 struct MPT2SAS_TARGET *sas_target_priv_data;
3295 unsigned long flags;
3297 spin_lock_irqsave(&ioc->raid_device_lock, flags);
3298 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
3299 if (raid_device && raid_device->starget &&
3300 raid_device->starget->hostdata) {
3301 sas_target_priv_data =
3302 raid_device->starget->hostdata;
3303 sas_target_priv_data->deleted = 1;
3304 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3305 "setting delete flag: handle(0x%04x), "
3306 "wwid(0x%016llx)\n", ioc->name, handle,
3307 (unsigned long long) raid_device->wwid));
3309 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
3313 * _scsih_set_volume_handle_for_tr - set handle for target reset to volume
3314 * @handle: input handle
3315 * @a: handle for volume a
3316 * @b: handle for volume b
3318 * IR firmware only supports two raid volumes. The purpose of this
3319 * routine is to set the volume handle in either a or b. When the given
3320 * input handle is non-zero, or when a and b have not been set before.
3323 _scsih_set_volume_handle_for_tr(u16 handle, u16 *a, u16 *b)
3325 if (!handle || handle == *a || handle == *b)
3334 * _scsih_check_ir_config_unhide_events - check for UNHIDE events
3335 * @ioc: per adapter object
3336 * @event_data: the event data payload
3337 * Context: interrupt time.
3339 * This routine will send target reset to volume, followed by target
3340 * resets to the PDs. This is called when a PD has been removed, or
3341 * volume has been deleted or removed. When the target reset is sent
3342 * to volume, the PD target resets need to be queued to start upon
3343 * completion of the volume target reset.
3348 _scsih_check_ir_config_unhide_events(struct MPT2SAS_ADAPTER *ioc,
3349 Mpi2EventDataIrConfigChangeList_t *event_data)
3351 Mpi2EventIrConfigElement_t *element;
3353 u16 handle, volume_handle, a, b;
3354 struct _tr_list *delayed_tr;
3359 if (ioc->is_warpdrive)
3362 /* Volume Resets for Deleted or Removed */
3363 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3364 for (i = 0; i < event_data->NumElements; i++, element++) {
3365 if (element->ReasonCode ==
3366 MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED ||
3367 element->ReasonCode ==
3368 MPI2_EVENT_IR_CHANGE_RC_REMOVED) {
3369 volume_handle = le16_to_cpu(element->VolDevHandle);
3370 _scsih_set_volume_delete_flag(ioc, volume_handle);
3371 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3375 /* Volume Resets for UNHIDE events */
3376 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3377 for (i = 0; i < event_data->NumElements; i++, element++) {
3378 if (le32_to_cpu(event_data->Flags) &
3379 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG)
3381 if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_UNHIDE) {
3382 volume_handle = le16_to_cpu(element->VolDevHandle);
3383 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3388 _scsih_tm_tr_volume_send(ioc, a);
3390 _scsih_tm_tr_volume_send(ioc, b);
3392 /* PD target resets */
3393 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3394 for (i = 0; i < event_data->NumElements; i++, element++) {
3395 if (element->ReasonCode != MPI2_EVENT_IR_CHANGE_RC_UNHIDE)
3397 handle = le16_to_cpu(element->PhysDiskDevHandle);
3398 volume_handle = le16_to_cpu(element->VolDevHandle);
3399 clear_bit(handle, ioc->pd_handles);
3401 _scsih_tm_tr_send(ioc, handle);
3402 else if (volume_handle == a || volume_handle == b) {
3403 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3404 BUG_ON(!delayed_tr);
3405 INIT_LIST_HEAD(&delayed_tr->list);
3406 delayed_tr->handle = handle;
3407 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
3408 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3409 "DELAYED:tr:handle(0x%04x), (open)\n", ioc->name,
3412 _scsih_tm_tr_send(ioc, handle);
3418 * _scsih_check_volume_delete_events - set delete flag for volumes
3419 * @ioc: per adapter object
3420 * @event_data: the event data payload
3421 * Context: interrupt time.
3423 * This will handle the case when the cable connected to entire volume is
3424 * pulled. We will take care of setting the deleted flag so normal IO will
3430 _scsih_check_volume_delete_events(struct MPT2SAS_ADAPTER *ioc,
3431 Mpi2EventDataIrVolume_t *event_data)
3435 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
3437 state = le32_to_cpu(event_data->NewValue);
3438 if (state == MPI2_RAID_VOL_STATE_MISSING || state ==
3439 MPI2_RAID_VOL_STATE_FAILED)
3440 _scsih_set_volume_delete_flag(ioc,
3441 le16_to_cpu(event_data->VolDevHandle));
3445 * _scsih_flush_running_cmds - completing outstanding commands.
3446 * @ioc: per adapter object
3448 * The flushing out of all pending scmd commands following host reset,
3449 * where all IO is dropped to the floor.
3454 _scsih_flush_running_cmds(struct MPT2SAS_ADAPTER *ioc)
3456 struct scsi_cmnd *scmd;
3460 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
3461 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
3465 mpt2sas_base_free_smid(ioc, smid);
3466 scsi_dma_unmap(scmd);
3467 if (ioc->pci_error_recovery)
3468 scmd->result = DID_NO_CONNECT << 16;
3470 scmd->result = DID_RESET << 16;
3471 scmd->scsi_done(scmd);
3473 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "completing %d cmds\n",
3478 * _scsih_setup_eedp - setup MPI request for EEDP transfer
3479 * @scmd: pointer to scsi command object
3480 * @mpi_request: pointer to the SCSI_IO reqest message frame
3482 * Supporting protection 1 and 3.
3487 _scsih_setup_eedp(struct scsi_cmnd *scmd, Mpi2SCSIIORequest_t *mpi_request)
3490 unsigned char prot_op = scsi_get_prot_op(scmd);
3491 unsigned char prot_type = scsi_get_prot_type(scmd);
3493 if (prot_type == SCSI_PROT_DIF_TYPE0 || prot_op == SCSI_PROT_NORMAL)
3496 if (prot_op == SCSI_PROT_READ_STRIP)
3497 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP;
3498 else if (prot_op == SCSI_PROT_WRITE_INSERT)
3499 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_INSERT_OP;
3503 switch (prot_type) {
3504 case SCSI_PROT_DIF_TYPE1:
3505 case SCSI_PROT_DIF_TYPE2:
3508 * enable ref/guard checking
3509 * auto increment ref tag
3511 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG |
3512 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG |
3513 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
3514 mpi_request->CDB.EEDP32.PrimaryReferenceTag =
3515 cpu_to_be32(scsi_get_lba(scmd));
3518 case SCSI_PROT_DIF_TYPE3:
3521 * enable guard checking
3523 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
3526 mpi_request->EEDPBlockSize = cpu_to_le32(scmd->device->sector_size);
3527 mpi_request->EEDPFlags = cpu_to_le16(eedp_flags);
3531 * _scsih_eedp_error_handling - return sense code for EEDP errors
3532 * @scmd: pointer to scsi command object
3533 * @ioc_status: ioc status
3538 _scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status)
3544 switch (ioc_status) {
3545 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
3548 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
3551 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
3559 if (scmd->sc_data_direction == DMA_TO_DEVICE) {
3560 sk = ILLEGAL_REQUEST;
3561 host_byte = DID_ABORT;
3563 sk = ABORTED_COMMAND;
3567 scsi_build_sense_buffer(0, scmd->sense_buffer, sk, 0x10, ascq);
3568 scmd->result = DRIVER_SENSE << 24 | (host_byte << 16) |
3569 SAM_STAT_CHECK_CONDITION;
3573 * _scsih_scsi_direct_io_get - returns direct io flag
3574 * @ioc: per adapter object
3575 * @smid: system request message index
3577 * Returns the smid stored scmd pointer.
3580 _scsih_scsi_direct_io_get(struct MPT2SAS_ADAPTER *ioc, u16 smid)
3582 return ioc->scsi_lookup[smid - 1].direct_io;
3586 * _scsih_scsi_direct_io_set - sets direct io flag
3587 * @ioc: per adapter object
3588 * @smid: system request message index
3589 * @direct_io: Zero or non-zero value to set in the direct_io flag
3594 _scsih_scsi_direct_io_set(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 direct_io)
3596 ioc->scsi_lookup[smid - 1].direct_io = direct_io;
3601 * _scsih_setup_direct_io - setup MPI request for WARPDRIVE Direct I/O
3602 * @ioc: per adapter object
3603 * @scmd: pointer to scsi command object
3604 * @raid_device: pointer to raid device data structure
3605 * @mpi_request: pointer to the SCSI_IO reqest message frame
3606 * @smid: system request message index
3611 _scsih_setup_direct_io(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
3612 struct _raid_device *raid_device, Mpi2SCSIIORequest_t *mpi_request,
3615 u32 v_lba, p_lba, stripe_off, stripe_unit, column, io_size;
3616 u32 stripe_sz, stripe_exp;
3617 u8 num_pds, *cdb_ptr, *tmp_ptr, *lba_ptr1, *lba_ptr2;
3618 u8 cdb0 = scmd->cmnd[0];
3621 * Try Direct I/O to RAID memeber disks
3623 if (cdb0 == READ_16 || cdb0 == READ_10 ||
3624 cdb0 == WRITE_16 || cdb0 == WRITE_10) {
3625 cdb_ptr = mpi_request->CDB.CDB32;
3627 if ((cdb0 < READ_16) || !(cdb_ptr[2] | cdb_ptr[3] | cdb_ptr[4]
3629 io_size = scsi_bufflen(scmd) >> 9;
3630 /* get virtual lba */
3631 lba_ptr1 = lba_ptr2 = (cdb0 < READ_16) ? &cdb_ptr[2] :
3633 tmp_ptr = (u8 *)&v_lba + 3;
3634 *tmp_ptr-- = *lba_ptr1++;
3635 *tmp_ptr-- = *lba_ptr1++;
3636 *tmp_ptr-- = *lba_ptr1++;
3637 *tmp_ptr = *lba_ptr1;
3639 if (((u64)v_lba + (u64)io_size - 1) <=
3640 (u32)raid_device->max_lba) {
3641 stripe_sz = raid_device->stripe_sz;
3642 stripe_exp = raid_device->stripe_exponent;
3643 stripe_off = v_lba & (stripe_sz - 1);
3645 /* Check whether IO falls within a stripe */
3646 if ((stripe_off + io_size) <= stripe_sz) {
3647 num_pds = raid_device->num_pds;
3648 p_lba = v_lba >> stripe_exp;
3649 stripe_unit = p_lba / num_pds;
3650 column = p_lba % num_pds;
3651 p_lba = (stripe_unit << stripe_exp) +
3653 mpi_request->DevHandle =
3654 cpu_to_le16(raid_device->
3656 tmp_ptr = (u8 *)&p_lba + 3;
3657 *lba_ptr2++ = *tmp_ptr--;
3658 *lba_ptr2++ = *tmp_ptr--;
3659 *lba_ptr2++ = *tmp_ptr--;
3660 *lba_ptr2 = *tmp_ptr;
3662 * WD: To indicate this I/O is directI/O
3664 _scsih_scsi_direct_io_set(ioc, smid, 1);
3672 * _scsih_qcmd - main scsi request entry point
3673 * @scmd: pointer to scsi command object
3674 * @done: function pointer to be invoked on completion
3676 * The callback index is set inside `ioc->scsi_io_cb_idx`.
3678 * Returns 0 on success. If there's a failure, return either:
3679 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
3680 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
3683 _scsih_qcmd_lck(struct scsi_cmnd *scmd, void (*done)(struct scsi_cmnd *))
3685 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
3686 struct MPT2SAS_DEVICE *sas_device_priv_data;
3687 struct MPT2SAS_TARGET *sas_target_priv_data;
3688 struct _raid_device *raid_device;
3689 Mpi2SCSIIORequest_t *mpi_request;
3693 scmd->scsi_done = done;
3694 sas_device_priv_data = scmd->device->hostdata;
3695 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
3696 scmd->result = DID_NO_CONNECT << 16;
3697 scmd->scsi_done(scmd);
3701 if (ioc->pci_error_recovery) {
3702 scmd->result = DID_NO_CONNECT << 16;
3703 scmd->scsi_done(scmd);
3707 sas_target_priv_data = sas_device_priv_data->sas_target;
3708 /* invalid device handle */
3709 if (sas_target_priv_data->handle == MPT2SAS_INVALID_DEVICE_HANDLE) {
3710 scmd->result = DID_NO_CONNECT << 16;
3711 scmd->scsi_done(scmd);
3715 /* host recovery or link resets sent via IOCTLs */
3716 if (ioc->shost_recovery || ioc->ioc_link_reset_in_progress)
3717 return SCSI_MLQUEUE_HOST_BUSY;
3718 /* device busy with task management */
3719 else if (sas_device_priv_data->block || sas_target_priv_data->tm_busy)
3720 return SCSI_MLQUEUE_DEVICE_BUSY;
3721 /* device has been deleted */
3722 else if (sas_target_priv_data->deleted) {
3723 scmd->result = DID_NO_CONNECT << 16;
3724 scmd->scsi_done(scmd);
3728 if (scmd->sc_data_direction == DMA_FROM_DEVICE)
3729 mpi_control = MPI2_SCSIIO_CONTROL_READ;
3730 else if (scmd->sc_data_direction == DMA_TO_DEVICE)
3731 mpi_control = MPI2_SCSIIO_CONTROL_WRITE;
3733 mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER;
3736 if (!(sas_device_priv_data->flags & MPT_DEVICE_FLAGS_INIT)) {
3737 if (scmd->device->tagged_supported) {
3738 if (scmd->device->ordered_tags)
3739 mpi_control |= MPI2_SCSIIO_CONTROL_ORDEREDQ;
3741 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
3743 /* MPI Revision I (UNIT = 0xA) - removed MPI2_SCSIIO_CONTROL_UNTAGGED */
3744 /* mpi_control |= MPI2_SCSIIO_CONTROL_UNTAGGED;
3746 mpi_control |= (0x500);
3749 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
3750 /* Make sure Device is not raid volume.
3751 * We do not expose raid functionality to upper layer for warpdrive.
3753 if (!ioc->is_warpdrive && !_scsih_is_raid(&scmd->device->sdev_gendev) &&
3754 sas_is_tlr_enabled(scmd->device) && scmd->cmd_len != 32)
3755 mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON;
3757 smid = mpt2sas_base_get_smid_scsiio(ioc, ioc->scsi_io_cb_idx, scmd);
3759 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3760 ioc->name, __func__);
3763 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3764 memset(mpi_request, 0, sizeof(Mpi2SCSIIORequest_t));
3765 _scsih_setup_eedp(scmd, mpi_request);
3766 if (scmd->cmd_len == 32)
3767 mpi_control |= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT;
3768 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
3769 if (sas_device_priv_data->sas_target->flags &
3770 MPT_TARGET_FLAGS_RAID_COMPONENT)
3771 mpi_request->Function = MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;
3773 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
3774 mpi_request->DevHandle =
3775 cpu_to_le16(sas_device_priv_data->sas_target->handle);
3776 mpi_request->DataLength = cpu_to_le32(scsi_bufflen(scmd));
3777 mpi_request->Control = cpu_to_le32(mpi_control);
3778 mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len);
3779 mpi_request->MsgFlags = MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR;
3780 mpi_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE;
3781 mpi_request->SenseBufferLowAddress =
3782 mpt2sas_base_get_sense_buffer_dma(ioc, smid);
3783 mpi_request->SGLOffset0 = offsetof(Mpi2SCSIIORequest_t, SGL) / 4;
3784 mpi_request->SGLFlags = cpu_to_le16(MPI2_SCSIIO_SGLFLAGS_TYPE_MPI +
3785 MPI2_SCSIIO_SGLFLAGS_SYSTEM_ADDR);
3786 mpi_request->VF_ID = 0; /* TODO */
3787 mpi_request->VP_ID = 0;
3788 int_to_scsilun(sas_device_priv_data->lun, (struct scsi_lun *)
3790 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
3792 if (!mpi_request->DataLength) {
3793 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request->SGL);
3795 if (_scsih_build_scatter_gather(ioc, scmd, smid)) {
3796 mpt2sas_base_free_smid(ioc, smid);
3801 raid_device = sas_target_priv_data->raid_device;
3802 if (raid_device && raid_device->direct_io_enabled)
3803 _scsih_setup_direct_io(ioc, scmd, raid_device, mpi_request,
3806 if (likely(mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST))
3807 mpt2sas_base_put_smid_scsi_io(ioc, smid,
3808 le16_to_cpu(mpi_request->DevHandle));
3810 mpt2sas_base_put_smid_default(ioc, smid);
3814 return SCSI_MLQUEUE_HOST_BUSY;
3817 static DEF_SCSI_QCMD(_scsih_qcmd)
3820 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
3821 * @sense_buffer: sense data returned by target
3822 * @data: normalized skey/asc/ascq
3827 _scsih_normalize_sense(char *sense_buffer, struct sense_info *data)
3829 if ((sense_buffer[0] & 0x7F) >= 0x72) {
3830 /* descriptor format */
3831 data->skey = sense_buffer[1] & 0x0F;
3832 data->asc = sense_buffer[2];
3833 data->ascq = sense_buffer[3];
3836 data->skey = sense_buffer[2] & 0x0F;
3837 data->asc = sense_buffer[12];
3838 data->ascq = sense_buffer[13];
3842 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3844 * _scsih_scsi_ioc_info - translated non-successful SCSI_IO request
3845 * @ioc: per adapter object
3846 * @scmd: pointer to scsi command object
3847 * @mpi_reply: reply mf payload returned from firmware
3849 * scsi_status - SCSI Status code returned from target device
3850 * scsi_state - state info associated with SCSI_IO determined by ioc
3851 * ioc_status - ioc supplied status info
3856 _scsih_scsi_ioc_info(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
3857 Mpi2SCSIIOReply_t *mpi_reply, u16 smid)
3861 u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) &
3862 MPI2_IOCSTATUS_MASK;
3863 u8 scsi_state = mpi_reply->SCSIState;
3864 u8 scsi_status = mpi_reply->SCSIStatus;
3865 char *desc_ioc_state = NULL;
3866 char *desc_scsi_status = NULL;
3867 char *desc_scsi_state = ioc->tmp_string;
3868 u32 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
3869 struct _sas_device *sas_device = NULL;
3870 unsigned long flags;
3871 struct scsi_target *starget = scmd->device->sdev_target;
3872 struct MPT2SAS_TARGET *priv_target = starget->hostdata;
3873 char *device_str = NULL;
3878 if (ioc->hide_ir_msg)
3879 device_str = "WarpDrive";
3881 device_str = "volume";
3883 if (log_info == 0x31170000)
3886 switch (ioc_status) {
3887 case MPI2_IOCSTATUS_SUCCESS:
3888 desc_ioc_state = "success";
3890 case MPI2_IOCSTATUS_INVALID_FUNCTION:
3891 desc_ioc_state = "invalid function";
3893 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
3894 desc_ioc_state = "scsi recovered error";
3896 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE:
3897 desc_ioc_state = "scsi invalid dev handle";
3899 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
3900 desc_ioc_state = "scsi device not there";
3902 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
3903 desc_ioc_state = "scsi data overrun";
3905 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
3906 desc_ioc_state = "scsi data underrun";
3908 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
3909 desc_ioc_state = "scsi io data error";
3911 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
3912 desc_ioc_state = "scsi protocol error";
3914 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
3915 desc_ioc_state = "scsi task terminated";
3917 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
3918 desc_ioc_state = "scsi residual mismatch";
3920 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
3921 desc_ioc_state = "scsi task mgmt failed";
3923 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
3924 desc_ioc_state = "scsi ioc terminated";
3926 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
3927 desc_ioc_state = "scsi ext terminated";
3929 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
3930 desc_ioc_state = "eedp guard error";
3932 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
3933 desc_ioc_state = "eedp ref tag error";
3935 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
3936 desc_ioc_state = "eedp app tag error";
3939 desc_ioc_state = "unknown";
3943 switch (scsi_status) {
3944 case MPI2_SCSI_STATUS_GOOD:
3945 desc_scsi_status = "good";
3947 case MPI2_SCSI_STATUS_CHECK_CONDITION:
3948 desc_scsi_status = "check condition";
3950 case MPI2_SCSI_STATUS_CONDITION_MET:
3951 desc_scsi_status = "condition met";
3953 case MPI2_SCSI_STATUS_BUSY:
3954 desc_scsi_status = "busy";
3956 case MPI2_SCSI_STATUS_INTERMEDIATE:
3957 desc_scsi_status = "intermediate";
3959 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET:
3960 desc_scsi_status = "intermediate condmet";
3962 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT:
3963 desc_scsi_status = "reservation conflict";
3965 case MPI2_SCSI_STATUS_COMMAND_TERMINATED:
3966 desc_scsi_status = "command terminated";
3968 case MPI2_SCSI_STATUS_TASK_SET_FULL:
3969 desc_scsi_status = "task set full";
3971 case MPI2_SCSI_STATUS_ACA_ACTIVE:
3972 desc_scsi_status = "aca active";
3974 case MPI2_SCSI_STATUS_TASK_ABORTED:
3975 desc_scsi_status = "task aborted";
3978 desc_scsi_status = "unknown";
3982 desc_scsi_state[0] = '\0';
3984 desc_scsi_state = " ";
3985 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
3986 strcat(desc_scsi_state, "response info ");
3987 if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
3988 strcat(desc_scsi_state, "state terminated ");
3989 if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS)
3990 strcat(desc_scsi_state, "no status ");
3991 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED)
3992 strcat(desc_scsi_state, "autosense failed ");
3993 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)
3994 strcat(desc_scsi_state, "autosense valid ");
3996 scsi_print_command(scmd);
3998 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
3999 printk(MPT2SAS_WARN_FMT "\t%s wwid(0x%016llx)\n", ioc->name,
4000 device_str, (unsigned long long)priv_target->sas_address);
4002 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4003 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
4004 priv_target->sas_address);
4006 printk(MPT2SAS_WARN_FMT "\tsas_address(0x%016llx), "
4007 "phy(%d)\n", ioc->name, sas_device->sas_address,
4009 printk(MPT2SAS_WARN_FMT
4010 "\tenclosure_logical_id(0x%016llx), slot(%d)\n",
4011 ioc->name, sas_device->enclosure_logical_id,
4014 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4017 printk(MPT2SAS_WARN_FMT "\thandle(0x%04x), ioc_status(%s)(0x%04x), "
4018 "smid(%d)\n", ioc->name, le16_to_cpu(mpi_reply->DevHandle),
4019 desc_ioc_state, ioc_status, smid);
4020 printk(MPT2SAS_WARN_FMT "\trequest_len(%d), underflow(%d), "
4021 "resid(%d)\n", ioc->name, scsi_bufflen(scmd), scmd->underflow,
4022 scsi_get_resid(scmd));
4023 printk(MPT2SAS_WARN_FMT "\ttag(%d), transfer_count(%d), "
4024 "sc->result(0x%08x)\n", ioc->name, le16_to_cpu(mpi_reply->TaskTag),
4025 le32_to_cpu(mpi_reply->TransferCount), scmd->result);
4026 printk(MPT2SAS_WARN_FMT "\tscsi_status(%s)(0x%02x), "
4027 "scsi_state(%s)(0x%02x)\n", ioc->name, desc_scsi_status,
4028 scsi_status, desc_scsi_state, scsi_state);
4030 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
4031 struct sense_info data;
4032 _scsih_normalize_sense(scmd->sense_buffer, &data);
4033 printk(MPT2SAS_WARN_FMT "\t[sense_key,asc,ascq]: "
4034 "[0x%02x,0x%02x,0x%02x], count(%d)\n", ioc->name, data.skey,
4035 data.asc, data.ascq, le32_to_cpu(mpi_reply->SenseCount));
4038 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) {
4039 response_info = le32_to_cpu(mpi_reply->ResponseInfo);
4040 response_bytes = (u8 *)&response_info;
4041 _scsih_response_code(ioc, response_bytes[0]);
4047 * _scsih_turn_on_fault_led - illuminate Fault LED
4048 * @ioc: per adapter object
4049 * @handle: device handle
4055 _scsih_turn_on_fault_led(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4057 Mpi2SepReply_t mpi_reply;
4058 Mpi2SepRequest_t mpi_request;
4060 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
4061 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
4062 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
4063 mpi_request.SlotStatus =
4064 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT);
4065 mpi_request.DevHandle = cpu_to_le16(handle);
4066 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS;
4067 if ((mpt2sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
4068 &mpi_request)) != 0) {
4069 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", ioc->name,
4070 __FILE__, __LINE__, __func__);
4074 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
4075 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "enclosure_processor: "
4076 "ioc_status (0x%04x), loginfo(0x%08x)\n", ioc->name,
4077 le16_to_cpu(mpi_reply.IOCStatus),
4078 le32_to_cpu(mpi_reply.IOCLogInfo)));
4084 * _scsih_send_event_to_turn_on_fault_led - fire delayed event
4085 * @ioc: per adapter object
4086 * @handle: device handle
4087 * Context: interrupt.
4092 _scsih_send_event_to_turn_on_fault_led(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4094 struct fw_event_work *fw_event;
4096 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
4099 fw_event->event = MPT2SAS_TURN_ON_FAULT_LED;
4100 fw_event->device_handle = handle;
4101 fw_event->ioc = ioc;
4102 _scsih_fw_event_add(ioc, fw_event);
4106 * _scsih_smart_predicted_fault - process smart errors
4107 * @ioc: per adapter object
4108 * @handle: device handle
4109 * Context: interrupt.
4114 _scsih_smart_predicted_fault(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4116 struct scsi_target *starget;
4117 struct MPT2SAS_TARGET *sas_target_priv_data;
4118 Mpi2EventNotificationReply_t *event_reply;
4119 Mpi2EventDataSasDeviceStatusChange_t *event_data;
4120 struct _sas_device *sas_device;
4122 unsigned long flags;
4124 /* only handle non-raid devices */
4125 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4126 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
4128 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4131 starget = sas_device->starget;
4132 sas_target_priv_data = starget->hostdata;
4134 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) ||
4135 ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))) {
4136 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4139 starget_printk(KERN_WARNING, starget, "predicted fault\n");
4140 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4142 if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM)
4143 _scsih_send_event_to_turn_on_fault_led(ioc, handle);
4145 /* insert into event log */
4146 sz = offsetof(Mpi2EventNotificationReply_t, EventData) +
4147 sizeof(Mpi2EventDataSasDeviceStatusChange_t);
4148 event_reply = kzalloc(sz, GFP_KERNEL);
4150 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4151 ioc->name, __FILE__, __LINE__, __func__);
4155 event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION;
4156 event_reply->Event =
4157 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE);
4158 event_reply->MsgLength = sz/4;
4159 event_reply->EventDataLength =
4160 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t)/4);
4161 event_data = (Mpi2EventDataSasDeviceStatusChange_t *)
4162 event_reply->EventData;
4163 event_data->ReasonCode = MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA;
4164 event_data->ASC = 0x5D;
4165 event_data->DevHandle = cpu_to_le16(handle);
4166 event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address);
4167 mpt2sas_ctl_add_to_event_log(ioc, event_reply);
4172 * _scsih_io_done - scsi request callback
4173 * @ioc: per adapter object
4174 * @smid: system request message index
4175 * @msix_index: MSIX table index supplied by the OS
4176 * @reply: reply message frame(lower 32bit addr)
4178 * Callback handler when using _scsih_qcmd.
4180 * Return 1 meaning mf should be freed from _base_interrupt
4181 * 0 means the mf is freed from this function.
4184 _scsih_io_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
4186 Mpi2SCSIIORequest_t *mpi_request;
4187 Mpi2SCSIIOReply_t *mpi_reply;
4188 struct scsi_cmnd *scmd;
4194 struct MPT2SAS_DEVICE *sas_device_priv_data;
4195 u32 response_code = 0;
4197 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
4198 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
4202 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
4204 if (mpi_reply == NULL) {
4205 scmd->result = DID_OK << 16;
4209 sas_device_priv_data = scmd->device->hostdata;
4210 if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
4211 sas_device_priv_data->sas_target->deleted) {
4212 scmd->result = DID_NO_CONNECT << 16;
4216 * WARPDRIVE: If direct_io is set then it is directIO,
4217 * the failed direct I/O should be redirected to volume
4219 if (_scsih_scsi_direct_io_get(ioc, smid)) {
4220 _scsih_scsi_direct_io_set(ioc, smid, 0);
4221 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
4222 mpi_request->DevHandle =
4223 cpu_to_le16(sas_device_priv_data->sas_target->handle);
4224 mpt2sas_base_put_smid_scsi_io(ioc, smid,
4225 sas_device_priv_data->sas_target->handle);
4230 /* turning off TLR */
4231 scsi_state = mpi_reply->SCSIState;
4232 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
4234 le32_to_cpu(mpi_reply->ResponseInfo) & 0xFF;
4235 if (!sas_device_priv_data->tlr_snoop_check) {
4236 sas_device_priv_data->tlr_snoop_check++;
4237 /* Make sure Device is not raid volume.
4238 * We do not expose raid functionality to upper layer for warpdrive.
4240 if (!ioc->is_warpdrive && !_scsih_is_raid(&scmd->device->sdev_gendev) &&
4241 sas_is_tlr_enabled(scmd->device) &&
4242 response_code == MPI2_SCSITASKMGMT_RSP_INVALID_FRAME) {
4243 sas_disable_tlr(scmd->device);
4244 sdev_printk(KERN_INFO, scmd->device, "TLR disabled\n");
4248 xfer_cnt = le32_to_cpu(mpi_reply->TransferCount);
4249 scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt);
4250 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
4251 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
4252 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
4255 ioc_status &= MPI2_IOCSTATUS_MASK;
4256 scsi_status = mpi_reply->SCSIStatus;
4258 if (ioc_status == MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 &&
4259 (scsi_status == MPI2_SCSI_STATUS_BUSY ||
4260 scsi_status == MPI2_SCSI_STATUS_RESERVATION_CONFLICT ||
4261 scsi_status == MPI2_SCSI_STATUS_TASK_SET_FULL)) {
4262 ioc_status = MPI2_IOCSTATUS_SUCCESS;
4265 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
4266 struct sense_info data;
4267 const void *sense_data = mpt2sas_base_get_sense_buffer(ioc,
4269 u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE,
4270 le32_to_cpu(mpi_reply->SenseCount));
4271 memcpy(scmd->sense_buffer, sense_data, sz);
4272 _scsih_normalize_sense(scmd->sense_buffer, &data);
4273 /* failure prediction threshold exceeded */
4274 if (data.asc == 0x5D)
4275 _scsih_smart_predicted_fault(ioc,
4276 le16_to_cpu(mpi_reply->DevHandle));
4279 switch (ioc_status) {
4280 case MPI2_IOCSTATUS_BUSY:
4281 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES:
4282 scmd->result = SAM_STAT_BUSY;
4285 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
4286 scmd->result = DID_NO_CONNECT << 16;
4289 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
4290 if (sas_device_priv_data->block) {
4291 scmd->result = DID_TRANSPORT_DISRUPTED << 16;
4294 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
4295 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
4296 scmd->result = DID_RESET << 16;
4299 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
4300 if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt))
4301 scmd->result = DID_SOFT_ERROR << 16;
4303 scmd->result = (DID_OK << 16) | scsi_status;
4306 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
4307 scmd->result = (DID_OK << 16) | scsi_status;
4309 if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID))
4312 if (xfer_cnt < scmd->underflow) {
4313 if (scsi_status == SAM_STAT_BUSY)
4314 scmd->result = SAM_STAT_BUSY;
4316 scmd->result = DID_SOFT_ERROR << 16;
4317 } else if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4318 MPI2_SCSI_STATE_NO_SCSI_STATUS))
4319 scmd->result = DID_SOFT_ERROR << 16;
4320 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4321 scmd->result = DID_RESET << 16;
4322 else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) {
4323 mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID;
4324 mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION;
4325 scmd->result = (DRIVER_SENSE << 24) |
4326 SAM_STAT_CHECK_CONDITION;
4327 scmd->sense_buffer[0] = 0x70;
4328 scmd->sense_buffer[2] = ILLEGAL_REQUEST;
4329 scmd->sense_buffer[12] = 0x20;
4330 scmd->sense_buffer[13] = 0;
4334 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
4335 scsi_set_resid(scmd, 0);
4336 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
4337 case MPI2_IOCSTATUS_SUCCESS:
4338 scmd->result = (DID_OK << 16) | scsi_status;
4339 if (response_code ==
4340 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME ||
4341 (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4342 MPI2_SCSI_STATE_NO_SCSI_STATUS)))
4343 scmd->result = DID_SOFT_ERROR << 16;
4344 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4345 scmd->result = DID_RESET << 16;
4348 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4349 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4350 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4351 _scsih_eedp_error_handling(scmd, ioc_status);
4353 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
4354 case MPI2_IOCSTATUS_INVALID_FUNCTION:
4355 case MPI2_IOCSTATUS_INVALID_SGL:
4356 case MPI2_IOCSTATUS_INTERNAL_ERROR:
4357 case MPI2_IOCSTATUS_INVALID_FIELD:
4358 case MPI2_IOCSTATUS_INVALID_STATE:
4359 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
4360 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
4362 scmd->result = DID_SOFT_ERROR << 16;
4367 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4368 if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY))
4369 _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid);
4373 scsi_dma_unmap(scmd);
4374 scmd->scsi_done(scmd);
4379 * _scsih_sas_host_refresh - refreshing sas host object contents
4380 * @ioc: per adapter object
4383 * During port enable, fw will send topology events for every device. Its
4384 * possible that the handles may change from the previous setting, so this
4385 * code keeping handles updating if changed.
4390 _scsih_sas_host_refresh(struct MPT2SAS_ADAPTER *ioc)
4395 Mpi2ConfigReply_t mpi_reply;
4396 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
4397 u16 attached_handle;
4400 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT
4401 "updating handles for sas_host(0x%016llx)\n",
4402 ioc->name, (unsigned long long)ioc->sas_hba.sas_address));
4404 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys
4405 * sizeof(Mpi2SasIOUnit0PhyData_t));
4406 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4407 if (!sas_iounit_pg0) {
4408 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4409 ioc->name, __FILE__, __LINE__, __func__);
4413 if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4414 sas_iounit_pg0, sz)) != 0)
4416 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
4417 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
4419 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
4420 link_rate = sas_iounit_pg0->PhyData[i].NegotiatedLinkRate >> 4;
4422 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4423 PhyData[0].ControllerDevHandle);
4424 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
4425 attached_handle = le16_to_cpu(sas_iounit_pg0->PhyData[i].
4427 if (attached_handle && link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
4428 link_rate = MPI2_SAS_NEG_LINK_RATE_1_5;
4429 mpt2sas_transport_update_links(ioc, ioc->sas_hba.sas_address,
4430 attached_handle, i, link_rate);
4433 kfree(sas_iounit_pg0);
4437 * _scsih_sas_host_add - create sas host object
4438 * @ioc: per adapter object
4440 * Creating host side data object, stored in ioc->sas_hba
4445 _scsih_sas_host_add(struct MPT2SAS_ADAPTER *ioc)
4448 Mpi2ConfigReply_t mpi_reply;
4449 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
4450 Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
4451 Mpi2SasPhyPage0_t phy_pg0;
4452 Mpi2SasDevicePage0_t sas_device_pg0;
4453 Mpi2SasEnclosurePage0_t enclosure_pg0;
4456 u16 device_missing_delay;
4458 mpt2sas_config_get_number_hba_phys(ioc, &ioc->sas_hba.num_phys);
4459 if (!ioc->sas_hba.num_phys) {
4460 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4461 ioc->name, __FILE__, __LINE__, __func__);
4465 /* sas_iounit page 0 */
4466 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys *
4467 sizeof(Mpi2SasIOUnit0PhyData_t));
4468 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4469 if (!sas_iounit_pg0) {
4470 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4471 ioc->name, __FILE__, __LINE__, __func__);
4474 if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4475 sas_iounit_pg0, sz))) {
4476 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4477 ioc->name, __FILE__, __LINE__, __func__);
4480 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4481 MPI2_IOCSTATUS_MASK;
4482 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4483 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4484 ioc->name, __FILE__, __LINE__, __func__);
4488 /* sas_iounit page 1 */
4489 sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys *
4490 sizeof(Mpi2SasIOUnit1PhyData_t));
4491 sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
4492 if (!sas_iounit_pg1) {
4493 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4494 ioc->name, __FILE__, __LINE__, __func__);
4497 if ((mpt2sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
4498 sas_iounit_pg1, sz))) {
4499 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4500 ioc->name, __FILE__, __LINE__, __func__);
4503 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4504 MPI2_IOCSTATUS_MASK;
4505 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4506 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4507 ioc->name, __FILE__, __LINE__, __func__);
4511 ioc->io_missing_delay =
4512 le16_to_cpu(sas_iounit_pg1->IODeviceMissingDelay);
4513 device_missing_delay =
4514 le16_to_cpu(sas_iounit_pg1->ReportDeviceMissingDelay);
4515 if (device_missing_delay & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16)
4516 ioc->device_missing_delay = (device_missing_delay &
4517 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16;
4519 ioc->device_missing_delay = device_missing_delay &
4520 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
4522 ioc->sas_hba.parent_dev = &ioc->shost->shost_gendev;
4523 ioc->sas_hba.phy = kcalloc(ioc->sas_hba.num_phys,
4524 sizeof(struct _sas_phy), GFP_KERNEL);
4525 if (!ioc->sas_hba.phy) {
4526 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4527 ioc->name, __FILE__, __LINE__, __func__);
4530 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
4531 if ((mpt2sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0,
4533 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4534 ioc->name, __FILE__, __LINE__, __func__);
4537 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4538 MPI2_IOCSTATUS_MASK;
4539 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4540 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4541 ioc->name, __FILE__, __LINE__, __func__);
4546 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4547 PhyData[0].ControllerDevHandle);
4548 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
4549 ioc->sas_hba.phy[i].phy_id = i;
4550 mpt2sas_transport_add_host_phy(ioc, &ioc->sas_hba.phy[i],
4551 phy_pg0, ioc->sas_hba.parent_dev);
4553 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
4554 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, ioc->sas_hba.handle))) {
4555 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4556 ioc->name, __FILE__, __LINE__, __func__);
4559 ioc->sas_hba.enclosure_handle =
4560 le16_to_cpu(sas_device_pg0.EnclosureHandle);
4561 ioc->sas_hba.sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
4562 printk(MPT2SAS_INFO_FMT "host_add: handle(0x%04x), "
4563 "sas_addr(0x%016llx), phys(%d)\n", ioc->name, ioc->sas_hba.handle,
4564 (unsigned long long) ioc->sas_hba.sas_address,
4565 ioc->sas_hba.num_phys) ;
4567 if (ioc->sas_hba.enclosure_handle) {
4568 if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply,
4570 MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
4571 ioc->sas_hba.enclosure_handle))) {
4572 ioc->sas_hba.enclosure_logical_id =
4573 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
4578 kfree(sas_iounit_pg1);
4579 kfree(sas_iounit_pg0);
4583 * _scsih_expander_add - creating expander object
4584 * @ioc: per adapter object
4585 * @handle: expander handle
4587 * Creating expander object, stored in ioc->sas_expander_list.
4589 * Return 0 for success, else error.
4592 _scsih_expander_add(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4594 struct _sas_node *sas_expander;
4595 Mpi2ConfigReply_t mpi_reply;
4596 Mpi2ExpanderPage0_t expander_pg0;
4597 Mpi2ExpanderPage1_t expander_pg1;
4598 Mpi2SasEnclosurePage0_t enclosure_pg0;
4601 __le64 sas_address, sas_address_parent = 0;
4603 unsigned long flags;
4604 struct _sas_port *mpt2sas_port = NULL;
4610 if (ioc->shost_recovery || ioc->pci_error_recovery)
4613 if ((mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
4614 MPI2_SAS_EXPAND_PGAD_FORM_HNDL, handle))) {
4615 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4616 ioc->name, __FILE__, __LINE__, __func__);
4620 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4621 MPI2_IOCSTATUS_MASK;
4622 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4623 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4624 ioc->name, __FILE__, __LINE__, __func__);
4628 /* handle out of order topology events */
4629 parent_handle = le16_to_cpu(expander_pg0.ParentDevHandle);
4630 if (_scsih_get_sas_address(ioc, parent_handle, &sas_address_parent)
4632 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4633 ioc->name, __FILE__, __LINE__, __func__);
4636 if (sas_address_parent != ioc->sas_hba.sas_address) {
4637 spin_lock_irqsave(&ioc->sas_node_lock, flags);
4638 sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
4639 sas_address_parent);
4640 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4641 if (!sas_expander) {
4642 rc = _scsih_expander_add(ioc, parent_handle);
4648 spin_lock_irqsave(&ioc->sas_node_lock, flags);
4649 sas_address = le64_to_cpu(expander_pg0.SASAddress);
4650 sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
4652 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4657 sas_expander = kzalloc(sizeof(struct _sas_node),
4659 if (!sas_expander) {
4660 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4661 ioc->name, __FILE__, __LINE__, __func__);
4665 sas_expander->handle = handle;
4666 sas_expander->num_phys = expander_pg0.NumPhys;
4667 sas_expander->sas_address_parent = sas_address_parent;
4668 sas_expander->sas_address = sas_address;
4670 printk(MPT2SAS_INFO_FMT "expander_add: handle(0x%04x),"
4671 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc->name,
4672 handle, parent_handle, (unsigned long long)
4673 sas_expander->sas_address, sas_expander->num_phys);
4675 if (!sas_expander->num_phys)
4677 sas_expander->phy = kcalloc(sas_expander->num_phys,
4678 sizeof(struct _sas_phy), GFP_KERNEL);
4679 if (!sas_expander->phy) {
4680 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4681 ioc->name, __FILE__, __LINE__, __func__);
4686 INIT_LIST_HEAD(&sas_expander->sas_port_list);
4687 mpt2sas_port = mpt2sas_transport_port_add(ioc, handle,
4688 sas_address_parent);
4689 if (!mpt2sas_port) {
4690 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4691 ioc->name, __FILE__, __LINE__, __func__);
4695 sas_expander->parent_dev = &mpt2sas_port->rphy->dev;
4697 for (i = 0 ; i < sas_expander->num_phys ; i++) {
4698 if ((mpt2sas_config_get_expander_pg1(ioc, &mpi_reply,
4699 &expander_pg1, i, handle))) {
4700 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4701 ioc->name, __FILE__, __LINE__, __func__);
4705 sas_expander->phy[i].handle = handle;
4706 sas_expander->phy[i].phy_id = i;
4708 if ((mpt2sas_transport_add_expander_phy(ioc,
4709 &sas_expander->phy[i], expander_pg1,
4710 sas_expander->parent_dev))) {
4711 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4712 ioc->name, __FILE__, __LINE__, __func__);
4718 if (sas_expander->enclosure_handle) {
4719 if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply,
4720 &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
4721 sas_expander->enclosure_handle))) {
4722 sas_expander->enclosure_logical_id =
4723 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
4727 _scsih_expander_node_add(ioc, sas_expander);
4733 mpt2sas_transport_port_remove(ioc, sas_expander->sas_address,
4734 sas_address_parent);
4735 kfree(sas_expander);
4740 * _scsih_done - scsih callback handler.
4741 * @ioc: per adapter object
4742 * @smid: system request message index
4743 * @msix_index: MSIX table index supplied by the OS
4744 * @reply: reply message frame(lower 32bit addr)
4746 * Callback handler when sending internal generated message frames.
4747 * The callback index passed is `ioc->scsih_cb_idx`
4749 * Return 1 meaning mf should be freed from _base_interrupt
4750 * 0 means the mf is freed from this function.
4753 _scsih_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
4755 MPI2DefaultReply_t *mpi_reply;
4757 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
4758 if (ioc->scsih_cmds.status == MPT2_CMD_NOT_USED)
4760 if (ioc->scsih_cmds.smid != smid)
4762 ioc->scsih_cmds.status |= MPT2_CMD_COMPLETE;
4764 memcpy(ioc->scsih_cmds.reply, mpi_reply,
4765 mpi_reply->MsgLength*4);
4766 ioc->scsih_cmds.status |= MPT2_CMD_REPLY_VALID;
4768 ioc->scsih_cmds.status &= ~MPT2_CMD_PENDING;
4769 complete(&ioc->scsih_cmds.done);
4774 * mpt2sas_expander_remove - removing expander object
4775 * @ioc: per adapter object
4776 * @sas_address: expander sas_address
4781 mpt2sas_expander_remove(struct MPT2SAS_ADAPTER *ioc, u64 sas_address)
4783 struct _sas_node *sas_expander;
4784 unsigned long flags;
4786 if (ioc->shost_recovery)
4789 spin_lock_irqsave(&ioc->sas_node_lock, flags);
4790 sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
4792 if (!sas_expander) {
4793 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4796 list_del(&sas_expander->list);
4797 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4798 _scsih_expander_node_remove(ioc, sas_expander);
4802 * _scsih_check_access_status - check access flags
4803 * @ioc: per adapter object
4804 * @sas_address: sas address
4805 * @handle: sas device handle
4806 * @access_flags: errors returned during discovery of the device
4808 * Return 0 for success, else failure
4811 _scsih_check_access_status(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
4812 u16 handle, u8 access_status)
4817 switch (access_status) {
4818 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS:
4819 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION:
4822 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED:
4823 desc = "sata capability failed";
4825 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT:
4826 desc = "sata affiliation conflict";
4828 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE:
4829 desc = "route not addressable";
4831 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE:
4832 desc = "smp error not addressable";
4834 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED:
4835 desc = "device blocked";
4837 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED:
4838 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN:
4839 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT:
4840 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG:
4841 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION:
4842 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER:
4843 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN:
4844 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN:
4845 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN:
4846 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION:
4847 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE:
4848 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX:
4849 desc = "sata initialization failed";
4859 printk(MPT2SAS_ERR_FMT "discovery errors(%s): sas_address(0x%016llx), "
4860 "handle(0x%04x)\n", ioc->name, desc,
4861 (unsigned long long)sas_address, handle);
4866 _scsih_check_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4868 Mpi2ConfigReply_t mpi_reply;
4869 Mpi2SasDevicePage0_t sas_device_pg0;
4870 struct _sas_device *sas_device;
4872 unsigned long flags;
4874 struct scsi_target *starget;
4875 struct MPT2SAS_TARGET *sas_target_priv_data;
4878 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
4879 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle)))
4882 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
4883 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
4886 /* check if this is end device */
4887 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
4888 if (!(_scsih_is_end_device(device_info)))
4891 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4892 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
4893 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
4897 printk(MPT2SAS_ERR_FMT "device is not present "
4898 "handle(0x%04x), no sas_device!!!\n", ioc->name, handle);
4899 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4903 if (unlikely(sas_device->handle != handle)) {
4904 starget = sas_device->starget;
4905 sas_target_priv_data = starget->hostdata;
4906 starget_printk(KERN_INFO, starget, "handle changed from(0x%04x)"
4907 " to (0x%04x)!!!\n", sas_device->handle, handle);
4908 sas_target_priv_data->handle = handle;
4909 sas_device->handle = handle;
4911 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4913 /* check if device is present */
4914 if (!(le16_to_cpu(sas_device_pg0.Flags) &
4915 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
4916 printk(MPT2SAS_ERR_FMT "device is not present "
4917 "handle(0x%04x), flags!!!\n", ioc->name, handle);
4921 /* check if there were any issues with discovery */
4922 if (_scsih_check_access_status(ioc, sas_address, handle,
4923 sas_device_pg0.AccessStatus))
4925 _scsih_ublock_io_device(ioc, handle);
4930 * _scsih_add_device - creating sas device object
4931 * @ioc: per adapter object
4932 * @handle: sas device handle
4933 * @phy_num: phy number end device attached to
4934 * @is_pd: is this hidden raid component
4936 * Creating end device object, stored in ioc->sas_device_list.
4938 * Returns 0 for success, non-zero for failure.
4941 _scsih_add_device(struct MPT2SAS_ADAPTER *ioc, u16 handle, u8 phy_num, u8 is_pd)
4943 Mpi2ConfigReply_t mpi_reply;
4944 Mpi2SasDevicePage0_t sas_device_pg0;
4945 Mpi2SasEnclosurePage0_t enclosure_pg0;
4946 struct _sas_device *sas_device;
4950 unsigned long flags;
4952 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
4953 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
4954 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4955 ioc->name, __FILE__, __LINE__, __func__);
4959 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4960 MPI2_IOCSTATUS_MASK;
4961 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4962 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4963 ioc->name, __FILE__, __LINE__, __func__);
4967 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
4969 /* check if device is present */
4970 if (!(le16_to_cpu(sas_device_pg0.Flags) &
4971 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
4972 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4973 ioc->name, __FILE__, __LINE__, __func__);
4974 printk(MPT2SAS_ERR_FMT "Flags = 0x%04x\n",
4975 ioc->name, le16_to_cpu(sas_device_pg0.Flags));
4979 /* check if there were any issues with discovery */
4980 if (_scsih_check_access_status(ioc, sas_address, handle,
4981 sas_device_pg0.AccessStatus))
4984 /* check if this is end device */
4985 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
4986 if (!(_scsih_is_end_device(device_info))) {
4987 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4988 ioc->name, __FILE__, __LINE__, __func__);
4993 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4994 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
4996 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5001 sas_device = kzalloc(sizeof(struct _sas_device),
5004 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5005 ioc->name, __FILE__, __LINE__, __func__);
5009 sas_device->handle = handle;
5010 if (_scsih_get_sas_address(ioc, le16_to_cpu
5011 (sas_device_pg0.ParentDevHandle),
5012 &sas_device->sas_address_parent) != 0)
5013 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5014 ioc->name, __FILE__, __LINE__, __func__);
5015 sas_device->enclosure_handle =
5016 le16_to_cpu(sas_device_pg0.EnclosureHandle);
5018 le16_to_cpu(sas_device_pg0.Slot);
5019 sas_device->device_info = device_info;
5020 sas_device->sas_address = sas_address;
5021 sas_device->phy = sas_device_pg0.PhyNum;
5023 /* get enclosure_logical_id */
5024 if (sas_device->enclosure_handle && !(mpt2sas_config_get_enclosure_pg0(
5025 ioc, &mpi_reply, &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
5026 sas_device->enclosure_handle)))
5027 sas_device->enclosure_logical_id =
5028 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
5030 /* get device name */
5031 sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName);
5033 if (ioc->wait_for_port_enable_to_complete)
5034 _scsih_sas_device_init_add(ioc, sas_device);
5036 _scsih_sas_device_add(ioc, sas_device);
5042 * _scsih_remove_device - removing sas device object
5043 * @ioc: per adapter object
5044 * @sas_device_delete: the sas_device object
5049 _scsih_remove_device(struct MPT2SAS_ADAPTER *ioc,
5050 struct _sas_device *sas_device)
5052 struct _sas_device sas_device_backup;
5053 struct MPT2SAS_TARGET *sas_target_priv_data;
5058 memcpy(&sas_device_backup, sas_device, sizeof(struct _sas_device));
5059 _scsih_sas_device_remove(ioc, sas_device);
5061 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter: "
5062 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
5063 sas_device_backup.handle, (unsigned long long)
5064 sas_device_backup.sas_address));
5066 if (sas_device_backup.starget && sas_device_backup.starget->hostdata) {
5067 sas_target_priv_data = sas_device_backup.starget->hostdata;
5068 sas_target_priv_data->deleted = 1;
5071 _scsih_ublock_io_device(ioc, sas_device_backup.handle);
5073 if (!ioc->hide_drives)
5074 mpt2sas_transport_port_remove(ioc,
5075 sas_device_backup.sas_address,
5076 sas_device_backup.sas_address_parent);
5078 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), sas_addr"
5079 "(0x%016llx)\n", ioc->name, sas_device_backup.handle,
5080 (unsigned long long) sas_device_backup.sas_address);
5082 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: exit: "
5083 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
5084 sas_device_backup.handle, (unsigned long long)
5085 sas_device_backup.sas_address));
5089 * mpt2sas_device_remove - removing device object
5090 * @ioc: per adapter object
5091 * @sas_address: expander sas_address
5096 mpt2sas_device_remove(struct MPT2SAS_ADAPTER *ioc, u64 sas_address)
5098 struct _sas_device *sas_device;
5099 unsigned long flags;
5101 if (ioc->shost_recovery)
5104 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5105 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5108 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5111 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5112 _scsih_remove_device(ioc, sas_device);
5115 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5117 * _scsih_sas_topology_change_event_debug - debug for topology event
5118 * @ioc: per adapter object
5119 * @event_data: event data payload
5123 _scsih_sas_topology_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
5124 Mpi2EventDataSasTopologyChangeList_t *event_data)
5130 char *status_str = NULL;
5131 u8 link_rate, prev_link_rate;
5133 switch (event_data->ExpStatus) {
5134 case MPI2_EVENT_SAS_TOPO_ES_ADDED:
5137 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING:
5138 status_str = "remove";
5140 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING:
5142 status_str = "responding";
5144 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING:
5145 status_str = "remove delay";
5148 status_str = "unknown status";
5151 printk(MPT2SAS_INFO_FMT "sas topology change: (%s)\n",
5152 ioc->name, status_str);
5153 printk(KERN_INFO "\thandle(0x%04x), enclosure_handle(0x%04x) "
5154 "start_phy(%02d), count(%d)\n",
5155 le16_to_cpu(event_data->ExpanderDevHandle),
5156 le16_to_cpu(event_data->EnclosureHandle),
5157 event_data->StartPhyNum, event_data->NumEntries);
5158 for (i = 0; i < event_data->NumEntries; i++) {
5159 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5162 phy_number = event_data->StartPhyNum + i;
5163 reason_code = event_data->PHY[i].PhyStatus &
5164 MPI2_EVENT_SAS_TOPO_RC_MASK;
5165 switch (reason_code) {
5166 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
5167 status_str = "target add";
5169 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
5170 status_str = "target remove";
5172 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING:
5173 status_str = "delay target remove";
5175 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
5176 status_str = "link rate change";
5178 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE:
5179 status_str = "target responding";
5182 status_str = "unknown";
5185 link_rate = event_data->PHY[i].LinkRate >> 4;
5186 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
5187 printk(KERN_INFO "\tphy(%02d), attached_handle(0x%04x): %s:"
5188 " link rate: new(0x%02x), old(0x%02x)\n", phy_number,
5189 handle, status_str, link_rate, prev_link_rate);
5196 * _scsih_sas_topology_change_event - handle topology changes
5197 * @ioc: per adapter object
5198 * @fw_event: The fw_event_work object
5203 _scsih_sas_topology_change_event(struct MPT2SAS_ADAPTER *ioc,
5204 struct fw_event_work *fw_event)
5207 u16 parent_handle, handle;
5209 u8 phy_number, max_phys;
5210 struct _sas_node *sas_expander;
5211 struct _sas_device *sas_device;
5213 unsigned long flags;
5214 u8 link_rate, prev_link_rate;
5215 Mpi2EventDataSasTopologyChangeList_t *event_data = fw_event->event_data;
5217 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5218 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5219 _scsih_sas_topology_change_event_debug(ioc, event_data);
5222 if (ioc->shost_recovery || ioc->remove_host || ioc->pci_error_recovery)
5225 if (!ioc->sas_hba.num_phys)
5226 _scsih_sas_host_add(ioc);
5228 _scsih_sas_host_refresh(ioc);
5230 if (fw_event->ignore) {
5231 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "ignoring expander "
5232 "event\n", ioc->name));
5236 parent_handle = le16_to_cpu(event_data->ExpanderDevHandle);
5238 /* handle expander add */
5239 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_ADDED)
5240 if (_scsih_expander_add(ioc, parent_handle) != 0)
5243 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5244 sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc,
5246 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5248 sas_address = sas_expander->sas_address;
5249 max_phys = sas_expander->num_phys;
5250 } else if (parent_handle < ioc->sas_hba.num_phys) {
5251 sas_address = ioc->sas_hba.sas_address;
5252 max_phys = ioc->sas_hba.num_phys;
5256 /* handle siblings events */
5257 for (i = 0; i < event_data->NumEntries; i++) {
5258 if (fw_event->ignore) {
5259 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "ignoring "
5260 "expander event\n", ioc->name));
5263 if (ioc->shost_recovery || ioc->remove_host ||
5264 ioc->pci_error_recovery)
5266 phy_number = event_data->StartPhyNum + i;
5267 if (phy_number >= max_phys)
5269 reason_code = event_data->PHY[i].PhyStatus &
5270 MPI2_EVENT_SAS_TOPO_RC_MASK;
5271 if ((event_data->PHY[i].PhyStatus &
5272 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT) && (reason_code !=
5273 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING))
5275 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5278 link_rate = event_data->PHY[i].LinkRate >> 4;
5279 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
5280 switch (reason_code) {
5281 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
5283 if (link_rate == prev_link_rate)
5286 mpt2sas_transport_update_links(ioc, sas_address,
5287 handle, phy_number, link_rate);
5289 if (link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
5292 _scsih_check_device(ioc, handle);
5294 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
5296 mpt2sas_transport_update_links(ioc, sas_address,
5297 handle, phy_number, link_rate);
5299 _scsih_add_device(ioc, handle, phy_number, 0);
5301 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
5303 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5304 sas_device = _scsih_sas_device_find_by_handle(ioc,
5307 spin_unlock_irqrestore(&ioc->sas_device_lock,
5311 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5312 _scsih_remove_device(ioc, sas_device);
5317 /* handle expander removal */
5318 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING &&
5320 mpt2sas_expander_remove(ioc, sas_address);
5324 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5326 * _scsih_sas_device_status_change_event_debug - debug for device event
5327 * @event_data: event data payload
5333 _scsih_sas_device_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
5334 Mpi2EventDataSasDeviceStatusChange_t *event_data)
5336 char *reason_str = NULL;
5338 switch (event_data->ReasonCode) {
5339 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
5340 reason_str = "smart data";
5342 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED:
5343 reason_str = "unsupported device discovered";
5345 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
5346 reason_str = "internal device reset";
5348 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL:
5349 reason_str = "internal task abort";
5351 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL:
5352 reason_str = "internal task abort set";
5354 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL:
5355 reason_str = "internal clear task set";
5357 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL:
5358 reason_str = "internal query task";
5360 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE:
5361 reason_str = "sata init failure";
5363 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET:
5364 reason_str = "internal device reset complete";
5366 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL:
5367 reason_str = "internal task abort complete";
5369 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION:
5370 reason_str = "internal async notification";
5372 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY:
5373 reason_str = "expander reduced functionality";
5375 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY:
5376 reason_str = "expander reduced functionality complete";
5379 reason_str = "unknown reason";
5382 printk(MPT2SAS_INFO_FMT "device status change: (%s)\n"
5383 "\thandle(0x%04x), sas address(0x%016llx)", ioc->name,
5384 reason_str, le16_to_cpu(event_data->DevHandle),
5385 (unsigned long long)le64_to_cpu(event_data->SASAddress));
5386 if (event_data->ReasonCode == MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA)
5387 printk(MPT2SAS_INFO_FMT ", ASC(0x%x), ASCQ(0x%x)\n", ioc->name,
5388 event_data->ASC, event_data->ASCQ);
5389 printk(KERN_INFO "\n");
5394 * _scsih_sas_device_status_change_event - handle device status change
5395 * @ioc: per adapter object
5396 * @fw_event: The fw_event_work object
5402 _scsih_sas_device_status_change_event(struct MPT2SAS_ADAPTER *ioc,
5403 struct fw_event_work *fw_event)
5405 struct MPT2SAS_TARGET *target_priv_data;
5406 struct _sas_device *sas_device;
5408 unsigned long flags;
5409 Mpi2EventDataSasDeviceStatusChange_t *event_data =
5410 fw_event->event_data;
5412 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5413 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5414 _scsih_sas_device_status_change_event_debug(ioc,
5418 /* In MPI Revision K (0xC), the internal device reset complete was
5419 * implemented, so avoid setting tm_busy flag for older firmware.
5421 if ((ioc->facts.HeaderVersion >> 8) < 0xC)
5424 if (event_data->ReasonCode !=
5425 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET &&
5426 event_data->ReasonCode !=
5427 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET)
5430 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5431 sas_address = le64_to_cpu(event_data->SASAddress);
5432 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5434 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5436 if (!sas_device || !sas_device->starget)
5439 target_priv_data = sas_device->starget->hostdata;
5440 if (!target_priv_data)
5443 if (event_data->ReasonCode ==
5444 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET)
5445 target_priv_data->tm_busy = 1;
5447 target_priv_data->tm_busy = 0;
5450 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5452 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure event
5453 * @ioc: per adapter object
5454 * @event_data: event data payload
5460 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
5461 Mpi2EventDataSasEnclDevStatusChange_t *event_data)
5463 char *reason_str = NULL;
5465 switch (event_data->ReasonCode) {
5466 case MPI2_EVENT_SAS_ENCL_RC_ADDED:
5467 reason_str = "enclosure add";
5469 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING:
5470 reason_str = "enclosure remove";
5473 reason_str = "unknown reason";
5477 printk(MPT2SAS_INFO_FMT "enclosure status change: (%s)\n"
5478 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
5479 " number slots(%d)\n", ioc->name, reason_str,
5480 le16_to_cpu(event_data->EnclosureHandle),
5481 (unsigned long long)le64_to_cpu(event_data->EnclosureLogicalID),
5482 le16_to_cpu(event_data->StartSlot));
5487 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
5488 * @ioc: per adapter object
5489 * @fw_event: The fw_event_work object
5495 _scsih_sas_enclosure_dev_status_change_event(struct MPT2SAS_ADAPTER *ioc,
5496 struct fw_event_work *fw_event)
5498 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5499 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5500 _scsih_sas_enclosure_dev_status_change_event_debug(ioc,
5501 fw_event->event_data);
5506 * _scsih_sas_broadcast_primative_event - handle broadcast events
5507 * @ioc: per adapter object
5508 * @fw_event: The fw_event_work object
5514 _scsih_sas_broadcast_primative_event(struct MPT2SAS_ADAPTER *ioc,
5515 struct fw_event_work *fw_event)
5517 struct scsi_cmnd *scmd;
5518 struct scsi_device *sdev;
5521 struct MPT2SAS_DEVICE *sas_device_priv_data;
5522 u32 termination_count;
5524 Mpi2SCSITaskManagementReply_t *mpi_reply;
5525 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5526 Mpi2EventDataSasBroadcastPrimitive_t *event_data = fw_event->event_data;
5529 unsigned long flags;
5532 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "broadcast primitive: "
5533 "phy number(%d), width(%d)\n", ioc->name, event_data->PhyNum,
5534 event_data->PortWidth));
5535 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter\n", ioc->name,
5538 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5539 ioc->broadcast_aen_busy = 0;
5540 termination_count = 0;
5542 mpi_reply = ioc->tm_cmds.reply;
5543 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
5544 scmd = _scsih_scsi_lookup_get(ioc, smid);
5547 sdev = scmd->device;
5548 sas_device_priv_data = sdev->hostdata;
5549 if (!sas_device_priv_data || !sas_device_priv_data->sas_target)
5551 /* skip hidden raid components */
5552 if (sas_device_priv_data->sas_target->flags &
5553 MPT_TARGET_FLAGS_RAID_COMPONENT)
5556 if (sas_device_priv_data->sas_target->flags &
5557 MPT_TARGET_FLAGS_VOLUME)
5560 handle = sas_device_priv_data->sas_target->handle;
5561 lun = sas_device_priv_data->lun;
5564 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
5565 mpt2sas_scsih_issue_tm(ioc, handle, 0, 0, lun,
5566 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, smid, 30, NULL);
5567 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
5568 ioc_status = le16_to_cpu(mpi_reply->IOCStatus)
5569 & MPI2_IOCSTATUS_MASK;
5570 if ((ioc_status == MPI2_IOCSTATUS_SUCCESS) &&
5571 (mpi_reply->ResponseCode ==
5572 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED ||
5573 mpi_reply->ResponseCode ==
5574 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC)) {
5575 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5578 r = mpt2sas_scsih_issue_tm(ioc, handle, sdev->channel, sdev->id,
5579 sdev->lun, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30,
5582 sdev_printk(KERN_WARNING, sdev, "task abort: FAILED "
5583 "scmd(%p)\n", scmd);
5584 termination_count += le32_to_cpu(mpi_reply->TerminationCount);
5585 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5587 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
5589 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT
5590 "%s - exit, query_count = %d termination_count = %d\n",
5591 ioc->name, __func__, query_count, termination_count));
5595 * _scsih_sas_discovery_event - handle discovery events
5596 * @ioc: per adapter object
5597 * @fw_event: The fw_event_work object
5603 _scsih_sas_discovery_event(struct MPT2SAS_ADAPTER *ioc,
5604 struct fw_event_work *fw_event)
5606 Mpi2EventDataSasDiscovery_t *event_data = fw_event->event_data;
5608 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5609 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) {
5610 printk(MPT2SAS_INFO_FMT "discovery event: (%s)", ioc->name,
5611 (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ?
5613 if (event_data->DiscoveryStatus)
5614 printk("discovery_status(0x%08x)",
5615 le32_to_cpu(event_data->DiscoveryStatus));
5620 if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED &&
5621 !ioc->sas_hba.num_phys)
5622 _scsih_sas_host_add(ioc);
5626 * _scsih_reprobe_lun - reprobing lun
5627 * @sdev: scsi device struct
5628 * @no_uld_attach: sdev->no_uld_attach flag setting
5632 _scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach)
5636 sdev->no_uld_attach = no_uld_attach ? 1 : 0;
5637 sdev_printk(KERN_INFO, sdev, "%s raid component\n",
5638 sdev->no_uld_attach ? "hidding" : "exposing");
5639 rc = scsi_device_reprobe(sdev);
5643 * _scsih_reprobe_target - reprobing target
5644 * @starget: scsi target struct
5645 * @no_uld_attach: sdev->no_uld_attach flag setting
5647 * Note: no_uld_attach flag determines whether the disk device is attached
5648 * to block layer. A value of `1` means to not attach.
5651 _scsih_reprobe_target(struct scsi_target *starget, int no_uld_attach)
5653 struct MPT2SAS_TARGET *sas_target_priv_data = starget->hostdata;
5656 sas_target_priv_data->flags |= MPT_TARGET_FLAGS_RAID_COMPONENT;
5658 sas_target_priv_data->flags &= ~MPT_TARGET_FLAGS_RAID_COMPONENT;
5660 starget_for_each_device(starget, no_uld_attach ? (void *)1 : NULL,
5661 _scsih_reprobe_lun);
5664 * _scsih_sas_volume_add - add new volume
5665 * @ioc: per adapter object
5666 * @element: IR config element data
5672 _scsih_sas_volume_add(struct MPT2SAS_ADAPTER *ioc,
5673 Mpi2EventIrConfigElement_t *element)
5675 struct _raid_device *raid_device;
5676 unsigned long flags;
5678 u16 handle = le16_to_cpu(element->VolDevHandle);
5681 mpt2sas_config_get_volume_wwid(ioc, handle, &wwid);
5683 printk(MPT2SAS_ERR_FMT
5684 "failure at %s:%d/%s()!\n", ioc->name,
5685 __FILE__, __LINE__, __func__);
5689 spin_lock_irqsave(&ioc->raid_device_lock, flags);
5690 raid_device = _scsih_raid_device_find_by_wwid(ioc, wwid);
5691 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
5696 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
5698 printk(MPT2SAS_ERR_FMT
5699 "failure at %s:%d/%s()!\n", ioc->name,
5700 __FILE__, __LINE__, __func__);
5704 raid_device->id = ioc->sas_id++;
5705 raid_device->channel = RAID_CHANNEL;
5706 raid_device->handle = handle;
5707 raid_device->wwid = wwid;
5708 _scsih_raid_device_add(ioc, raid_device);
5709 if (!ioc->wait_for_port_enable_to_complete) {
5710 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
5711 raid_device->id, 0);
5713 _scsih_raid_device_remove(ioc, raid_device);
5715 _scsih_determine_boot_device(ioc, raid_device, 1);
5719 * _scsih_sas_volume_delete - delete volume
5720 * @ioc: per adapter object
5721 * @handle: volume device handle
5727 _scsih_sas_volume_delete(struct MPT2SAS_ADAPTER *ioc, u16 handle)
5729 struct _raid_device *raid_device;
5730 unsigned long flags;
5731 struct MPT2SAS_TARGET *sas_target_priv_data;
5733 spin_lock_irqsave(&ioc->raid_device_lock, flags);
5734 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
5735 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
5738 if (raid_device->starget) {
5739 sas_target_priv_data = raid_device->starget->hostdata;
5740 sas_target_priv_data->deleted = 1;
5741 scsi_remove_target(&raid_device->starget->dev);
5743 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), wwid"
5744 "(0x%016llx)\n", ioc->name, raid_device->handle,
5745 (unsigned long long) raid_device->wwid);
5746 _scsih_raid_device_remove(ioc, raid_device);
5750 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
5751 * @ioc: per adapter object
5752 * @element: IR config element data
5758 _scsih_sas_pd_expose(struct MPT2SAS_ADAPTER *ioc,
5759 Mpi2EventIrConfigElement_t *element)
5761 struct _sas_device *sas_device;
5762 unsigned long flags;
5763 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
5765 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5766 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
5767 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5771 /* exposing raid component */
5772 sas_device->volume_handle = 0;
5773 sas_device->volume_wwid = 0;
5774 clear_bit(handle, ioc->pd_handles);
5775 _scsih_reprobe_target(sas_device->starget, 0);
5779 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
5780 * @ioc: per adapter object
5781 * @element: IR config element data
5787 _scsih_sas_pd_hide(struct MPT2SAS_ADAPTER *ioc,
5788 Mpi2EventIrConfigElement_t *element)
5790 struct _sas_device *sas_device;
5791 unsigned long flags;
5792 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
5794 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5795 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
5796 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5800 /* hiding raid component */
5801 mpt2sas_config_get_volume_handle(ioc, handle,
5802 &sas_device->volume_handle);
5803 mpt2sas_config_get_volume_wwid(ioc, sas_device->volume_handle,
5804 &sas_device->volume_wwid);
5805 set_bit(handle, ioc->pd_handles);
5806 _scsih_reprobe_target(sas_device->starget, 1);
5811 * _scsih_sas_pd_delete - delete pd component
5812 * @ioc: per adapter object
5813 * @element: IR config element data
5819 _scsih_sas_pd_delete(struct MPT2SAS_ADAPTER *ioc,
5820 Mpi2EventIrConfigElement_t *element)
5822 struct _sas_device *sas_device;
5823 unsigned long flags;
5824 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
5826 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5827 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
5828 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5831 _scsih_remove_device(ioc, sas_device);
5835 * _scsih_sas_pd_add - remove pd component
5836 * @ioc: per adapter object
5837 * @element: IR config element data
5843 _scsih_sas_pd_add(struct MPT2SAS_ADAPTER *ioc,
5844 Mpi2EventIrConfigElement_t *element)
5846 struct _sas_device *sas_device;
5847 unsigned long flags;
5848 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
5849 Mpi2ConfigReply_t mpi_reply;
5850 Mpi2SasDevicePage0_t sas_device_pg0;
5855 set_bit(handle, ioc->pd_handles);
5857 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5858 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
5859 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5863 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5864 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
5865 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5866 ioc->name, __FILE__, __LINE__, __func__);
5870 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
5871 MPI2_IOCSTATUS_MASK;
5872 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5873 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5874 ioc->name, __FILE__, __LINE__, __func__);
5878 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
5879 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
5880 mpt2sas_transport_update_links(ioc, sas_address, handle,
5881 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
5883 _scsih_add_device(ioc, handle, 0, 1);
5886 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5888 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
5889 * @ioc: per adapter object
5890 * @event_data: event data payload
5896 _scsih_sas_ir_config_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
5897 Mpi2EventDataIrConfigChangeList_t *event_data)
5899 Mpi2EventIrConfigElement_t *element;
5902 char *reason_str = NULL, *element_str = NULL;
5904 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
5906 printk(MPT2SAS_INFO_FMT "raid config change: (%s), elements(%d)\n",
5907 ioc->name, (le32_to_cpu(event_data->Flags) &
5908 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ?
5909 "foreign" : "native", event_data->NumElements);
5910 for (i = 0; i < event_data->NumElements; i++, element++) {
5911 switch (element->ReasonCode) {
5912 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
5915 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
5916 reason_str = "remove";
5918 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE:
5919 reason_str = "no change";
5921 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
5922 reason_str = "hide";
5924 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
5925 reason_str = "unhide";
5927 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
5928 reason_str = "volume_created";
5930 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
5931 reason_str = "volume_deleted";
5933 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
5934 reason_str = "pd_created";
5936 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
5937 reason_str = "pd_deleted";
5940 reason_str = "unknown reason";
5943 element_type = le16_to_cpu(element->ElementFlags) &
5944 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK;
5945 switch (element_type) {
5946 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT:
5947 element_str = "volume";
5949 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT:
5950 element_str = "phys disk";
5952 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT:
5953 element_str = "hot spare";
5956 element_str = "unknown element";
5959 printk(KERN_INFO "\t(%s:%s), vol handle(0x%04x), "
5960 "pd handle(0x%04x), pd num(0x%02x)\n", element_str,
5961 reason_str, le16_to_cpu(element->VolDevHandle),
5962 le16_to_cpu(element->PhysDiskDevHandle),
5963 element->PhysDiskNum);
5969 * _scsih_sas_ir_config_change_event - handle ir configuration change events
5970 * @ioc: per adapter object
5971 * @fw_event: The fw_event_work object
5977 _scsih_sas_ir_config_change_event(struct MPT2SAS_ADAPTER *ioc,
5978 struct fw_event_work *fw_event)
5980 Mpi2EventIrConfigElement_t *element;
5983 Mpi2EventDataIrConfigChangeList_t *event_data = fw_event->event_data;
5985 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5986 if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5987 && !ioc->hide_ir_msg)
5988 _scsih_sas_ir_config_change_event_debug(ioc, event_data);
5991 foreign_config = (le32_to_cpu(event_data->Flags) &
5992 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0;
5994 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
5995 for (i = 0; i < event_data->NumElements; i++, element++) {
5997 switch (element->ReasonCode) {
5998 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
5999 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
6000 if (!foreign_config)
6001 _scsih_sas_volume_add(ioc, element);
6003 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
6004 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
6005 if (!foreign_config)
6006 _scsih_sas_volume_delete(ioc,
6007 le16_to_cpu(element->VolDevHandle));
6009 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
6010 if (!ioc->is_warpdrive)
6011 _scsih_sas_pd_hide(ioc, element);
6013 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
6014 if (!ioc->is_warpdrive)
6015 _scsih_sas_pd_expose(ioc, element);
6017 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
6018 if (!ioc->is_warpdrive)
6019 _scsih_sas_pd_add(ioc, element);
6021 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
6022 if (!ioc->is_warpdrive)
6023 _scsih_sas_pd_delete(ioc, element);
6030 * _scsih_sas_ir_volume_event - IR volume event
6031 * @ioc: per adapter object
6032 * @fw_event: The fw_event_work object
6038 _scsih_sas_ir_volume_event(struct MPT2SAS_ADAPTER *ioc,
6039 struct fw_event_work *fw_event)
6042 unsigned long flags;
6043 struct _raid_device *raid_device;
6047 Mpi2EventDataIrVolume_t *event_data = fw_event->event_data;
6049 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
6052 handle = le16_to_cpu(event_data->VolDevHandle);
6053 state = le32_to_cpu(event_data->NewValue);
6054 if (!ioc->hide_ir_msg)
6055 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle(0x%04x), "
6056 "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle,
6057 le32_to_cpu(event_data->PreviousValue), state));
6060 case MPI2_RAID_VOL_STATE_MISSING:
6061 case MPI2_RAID_VOL_STATE_FAILED:
6062 _scsih_sas_volume_delete(ioc, handle);
6065 case MPI2_RAID_VOL_STATE_ONLINE:
6066 case MPI2_RAID_VOL_STATE_DEGRADED:
6067 case MPI2_RAID_VOL_STATE_OPTIMAL:
6069 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6070 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
6071 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6076 mpt2sas_config_get_volume_wwid(ioc, handle, &wwid);
6078 printk(MPT2SAS_ERR_FMT
6079 "failure at %s:%d/%s()!\n", ioc->name,
6080 __FILE__, __LINE__, __func__);
6084 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
6086 printk(MPT2SAS_ERR_FMT
6087 "failure at %s:%d/%s()!\n", ioc->name,
6088 __FILE__, __LINE__, __func__);
6092 raid_device->id = ioc->sas_id++;
6093 raid_device->channel = RAID_CHANNEL;
6094 raid_device->handle = handle;
6095 raid_device->wwid = wwid;
6096 _scsih_raid_device_add(ioc, raid_device);
6097 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
6098 raid_device->id, 0);
6100 _scsih_raid_device_remove(ioc, raid_device);
6103 case MPI2_RAID_VOL_STATE_INITIALIZING:
6110 * _scsih_sas_ir_physical_disk_event - PD event
6111 * @ioc: per adapter object
6112 * @fw_event: The fw_event_work object
6118 _scsih_sas_ir_physical_disk_event(struct MPT2SAS_ADAPTER *ioc,
6119 struct fw_event_work *fw_event)
6121 u16 handle, parent_handle;
6123 struct _sas_device *sas_device;
6124 unsigned long flags;
6125 Mpi2ConfigReply_t mpi_reply;
6126 Mpi2SasDevicePage0_t sas_device_pg0;
6128 Mpi2EventDataIrPhysicalDisk_t *event_data = fw_event->event_data;
6131 if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED)
6134 handle = le16_to_cpu(event_data->PhysDiskDevHandle);
6135 state = le32_to_cpu(event_data->NewValue);
6137 if (!ioc->hide_ir_msg)
6138 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle(0x%04x), "
6139 "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle,
6140 le32_to_cpu(event_data->PreviousValue), state));
6143 case MPI2_RAID_PD_STATE_ONLINE:
6144 case MPI2_RAID_PD_STATE_DEGRADED:
6145 case MPI2_RAID_PD_STATE_REBUILDING:
6146 case MPI2_RAID_PD_STATE_OPTIMAL:
6147 case MPI2_RAID_PD_STATE_HOT_SPARE:
6149 if (!ioc->is_warpdrive)
6150 set_bit(handle, ioc->pd_handles);
6152 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6153 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6154 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6159 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6160 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
6162 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6163 ioc->name, __FILE__, __LINE__, __func__);
6167 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6168 MPI2_IOCSTATUS_MASK;
6169 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6170 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6171 ioc->name, __FILE__, __LINE__, __func__);
6175 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6176 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
6177 mpt2sas_transport_update_links(ioc, sas_address, handle,
6178 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
6180 _scsih_add_device(ioc, handle, 0, 1);
6184 case MPI2_RAID_PD_STATE_OFFLINE:
6185 case MPI2_RAID_PD_STATE_NOT_CONFIGURED:
6186 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE:
6192 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6194 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
6195 * @ioc: per adapter object
6196 * @event_data: event data payload
6202 _scsih_sas_ir_operation_status_event_debug(struct MPT2SAS_ADAPTER *ioc,
6203 Mpi2EventDataIrOperationStatus_t *event_data)
6205 char *reason_str = NULL;
6207 switch (event_data->RAIDOperation) {
6208 case MPI2_EVENT_IR_RAIDOP_RESYNC:
6209 reason_str = "resync";
6211 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION:
6212 reason_str = "online capacity expansion";
6214 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK:
6215 reason_str = "consistency check";
6217 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT:
6218 reason_str = "background init";
6220 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT:
6221 reason_str = "make data consistent";
6228 printk(MPT2SAS_INFO_FMT "raid operational status: (%s)"
6229 "\thandle(0x%04x), percent complete(%d)\n",
6230 ioc->name, reason_str,
6231 le16_to_cpu(event_data->VolDevHandle),
6232 event_data->PercentComplete);
6237 * _scsih_sas_ir_operation_status_event - handle RAID operation events
6238 * @ioc: per adapter object
6239 * @fw_event: The fw_event_work object
6245 _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
6246 struct fw_event_work *fw_event)
6248 Mpi2EventDataIrOperationStatus_t *event_data = fw_event->event_data;
6249 static struct _raid_device *raid_device;
6250 unsigned long flags;
6253 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6254 if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6255 && !ioc->hide_ir_msg)
6256 _scsih_sas_ir_operation_status_event_debug(ioc,
6260 /* code added for raid transport support */
6261 if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC) {
6263 handle = le16_to_cpu(event_data->VolDevHandle);
6265 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6266 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
6267 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6272 if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC)
6273 raid_device->percent_complete =
6274 event_data->PercentComplete;
6279 * _scsih_prep_device_scan - initialize parameters prior to device scan
6280 * @ioc: per adapter object
6282 * Set the deleted flag prior to device scan. If the device is found during
6283 * the scan, then we clear the deleted flag.
6286 _scsih_prep_device_scan(struct MPT2SAS_ADAPTER *ioc)
6288 struct MPT2SAS_DEVICE *sas_device_priv_data;
6289 struct scsi_device *sdev;
6291 shost_for_each_device(sdev, ioc->shost) {
6292 sas_device_priv_data = sdev->hostdata;
6293 if (sas_device_priv_data && sas_device_priv_data->sas_target)
6294 sas_device_priv_data->sas_target->deleted = 1;
6299 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
6300 * @ioc: per adapter object
6301 * @sas_address: sas address
6302 * @slot: enclosure slot id
6303 * @handle: device handle
6305 * After host reset, find out whether devices are still responding.
6306 * Used in _scsi_remove_unresponsive_sas_devices.
6311 _scsih_mark_responding_sas_device(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
6312 u16 slot, u16 handle)
6314 struct MPT2SAS_TARGET *sas_target_priv_data = NULL;
6315 struct scsi_target *starget;
6316 struct _sas_device *sas_device;
6317 unsigned long flags;
6319 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6320 list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
6321 if (sas_device->sas_address == sas_address &&
6322 sas_device->slot == slot) {
6323 sas_device->responding = 1;
6324 starget = sas_device->starget;
6325 if (starget && starget->hostdata) {
6326 sas_target_priv_data = starget->hostdata;
6327 sas_target_priv_data->tm_busy = 0;
6328 sas_target_priv_data->deleted = 0;
6330 sas_target_priv_data = NULL;
6332 starget_printk(KERN_INFO, starget,
6333 "handle(0x%04x), sas_addr(0x%016llx), "
6334 "enclosure logical id(0x%016llx), "
6335 "slot(%d)\n", handle,
6336 (unsigned long long)sas_device->sas_address,
6337 (unsigned long long)
6338 sas_device->enclosure_logical_id,
6340 if (sas_device->handle == handle)
6342 printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n",
6343 sas_device->handle);
6344 sas_device->handle = handle;
6345 if (sas_target_priv_data)
6346 sas_target_priv_data->handle = handle;
6351 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6355 * _scsih_search_responding_sas_devices -
6356 * @ioc: per adapter object
6358 * After host reset, find out whether devices are still responding.
6364 _scsih_search_responding_sas_devices(struct MPT2SAS_ADAPTER *ioc)
6366 Mpi2SasDevicePage0_t sas_device_pg0;
6367 Mpi2ConfigReply_t mpi_reply;
6374 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, __func__);
6376 if (list_empty(&ioc->sas_device_list))
6380 while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6381 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
6383 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6384 MPI2_IOCSTATUS_MASK;
6385 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
6387 handle = le16_to_cpu(sas_device_pg0.DevHandle);
6388 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
6389 if (!(_scsih_is_end_device(device_info)))
6391 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
6392 slot = le16_to_cpu(sas_device_pg0.Slot);
6393 _scsih_mark_responding_sas_device(ioc, sas_address, slot,
6399 * _scsih_mark_responding_raid_device - mark a raid_device as responding
6400 * @ioc: per adapter object
6401 * @wwid: world wide identifier for raid volume
6402 * @handle: device handle
6404 * After host reset, find out whether devices are still responding.
6405 * Used in _scsi_remove_unresponsive_raid_devices.
6410 _scsih_mark_responding_raid_device(struct MPT2SAS_ADAPTER *ioc, u64 wwid,
6413 struct MPT2SAS_TARGET *sas_target_priv_data;
6414 struct scsi_target *starget;
6415 struct _raid_device *raid_device;
6416 unsigned long flags;
6418 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6419 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
6420 if (raid_device->wwid == wwid && raid_device->starget) {
6421 starget = raid_device->starget;
6422 if (starget && starget->hostdata) {
6423 sas_target_priv_data = starget->hostdata;
6424 sas_target_priv_data->deleted = 0;
6426 sas_target_priv_data = NULL;
6427 raid_device->responding = 1;
6428 starget_printk(KERN_INFO, raid_device->starget,
6429 "handle(0x%04x), wwid(0x%016llx)\n", handle,
6430 (unsigned long long)raid_device->wwid);
6432 * WARPDRIVE: The handles of the PDs might have changed
6433 * across the host reset so re-initialize the
6434 * required data for Direct IO
6436 _scsih_init_warpdrive_properties(ioc, raid_device);
6437 if (raid_device->handle == handle)
6439 printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n",
6440 raid_device->handle);
6441 raid_device->handle = handle;
6442 if (sas_target_priv_data)
6443 sas_target_priv_data->handle = handle;
6448 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6452 * _scsih_search_responding_raid_devices -
6453 * @ioc: per adapter object
6455 * After host reset, find out whether devices are still responding.
6461 _scsih_search_responding_raid_devices(struct MPT2SAS_ADAPTER *ioc)
6463 Mpi2RaidVolPage1_t volume_pg1;
6464 Mpi2RaidVolPage0_t volume_pg0;
6465 Mpi2RaidPhysDiskPage0_t pd_pg0;
6466 Mpi2ConfigReply_t mpi_reply;
6471 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, __func__);
6473 if (list_empty(&ioc->raid_device_list))
6477 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
6478 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
6479 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6480 MPI2_IOCSTATUS_MASK;
6481 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
6483 handle = le16_to_cpu(volume_pg1.DevHandle);
6485 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
6486 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
6487 sizeof(Mpi2RaidVolPage0_t)))
6490 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
6491 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
6492 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED)
6493 _scsih_mark_responding_raid_device(ioc,
6494 le64_to_cpu(volume_pg1.WWID), handle);
6497 /* refresh the pd_handles */
6498 if (!ioc->is_warpdrive) {
6499 phys_disk_num = 0xFF;
6500 memset(ioc->pd_handles, 0, ioc->pd_handles_sz);
6501 while (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
6502 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
6504 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6505 MPI2_IOCSTATUS_MASK;
6506 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
6508 phys_disk_num = pd_pg0.PhysDiskNum;
6509 handle = le16_to_cpu(pd_pg0.DevHandle);
6510 set_bit(handle, ioc->pd_handles);
6516 * _scsih_mark_responding_expander - mark a expander as responding
6517 * @ioc: per adapter object
6518 * @sas_address: sas address
6521 * After host reset, find out whether devices are still responding.
6522 * Used in _scsi_remove_unresponsive_expanders.
6527 _scsih_mark_responding_expander(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
6530 struct _sas_node *sas_expander;
6531 unsigned long flags;
6534 spin_lock_irqsave(&ioc->sas_node_lock, flags);
6535 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
6536 if (sas_expander->sas_address != sas_address)
6538 sas_expander->responding = 1;
6539 if (sas_expander->handle == handle)
6541 printk(KERN_INFO "\texpander(0x%016llx): handle changed"
6542 " from(0x%04x) to (0x%04x)!!!\n",
6543 (unsigned long long)sas_expander->sas_address,
6544 sas_expander->handle, handle);
6545 sas_expander->handle = handle;
6546 for (i = 0 ; i < sas_expander->num_phys ; i++)
6547 sas_expander->phy[i].handle = handle;
6551 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
6555 * _scsih_search_responding_expanders -
6556 * @ioc: per adapter object
6558 * After host reset, find out whether devices are still responding.
6564 _scsih_search_responding_expanders(struct MPT2SAS_ADAPTER *ioc)
6566 Mpi2ExpanderPage0_t expander_pg0;
6567 Mpi2ConfigReply_t mpi_reply;
6572 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, __func__);
6574 if (list_empty(&ioc->sas_expander_list))
6578 while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
6579 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
6581 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6582 MPI2_IOCSTATUS_MASK;
6583 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
6586 handle = le16_to_cpu(expander_pg0.DevHandle);
6587 sas_address = le64_to_cpu(expander_pg0.SASAddress);
6588 printk(KERN_INFO "\texpander present: handle(0x%04x), "
6589 "sas_addr(0x%016llx)\n", handle,
6590 (unsigned long long)sas_address);
6591 _scsih_mark_responding_expander(ioc, sas_address, handle);
6597 * _scsih_remove_unresponding_sas_devices - removing unresponding devices
6598 * @ioc: per adapter object
6603 _scsih_remove_unresponding_sas_devices(struct MPT2SAS_ADAPTER *ioc)
6605 struct _sas_device *sas_device, *sas_device_next;
6606 struct _sas_node *sas_expander;
6607 struct _raid_device *raid_device, *raid_device_next;
6610 list_for_each_entry_safe(sas_device, sas_device_next,
6611 &ioc->sas_device_list, list) {
6612 if (sas_device->responding) {
6613 sas_device->responding = 0;
6616 if (sas_device->starget)
6617 starget_printk(KERN_INFO, sas_device->starget,
6618 "removing: handle(0x%04x), sas_addr(0x%016llx), "
6619 "enclosure logical id(0x%016llx), slot(%d)\n",
6621 (unsigned long long)sas_device->sas_address,
6622 (unsigned long long)
6623 sas_device->enclosure_logical_id,
6625 _scsih_remove_device(ioc, sas_device);
6628 list_for_each_entry_safe(raid_device, raid_device_next,
6629 &ioc->raid_device_list, list) {
6630 if (raid_device->responding) {
6631 raid_device->responding = 0;
6634 if (raid_device->starget) {
6635 starget_printk(KERN_INFO, raid_device->starget,
6636 "removing: handle(0x%04x), wwid(0x%016llx)\n",
6637 raid_device->handle,
6638 (unsigned long long)raid_device->wwid);
6639 scsi_remove_target(&raid_device->starget->dev);
6641 _scsih_raid_device_remove(ioc, raid_device);
6644 retry_expander_search:
6645 sas_expander = NULL;
6646 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
6647 if (sas_expander->responding) {
6648 sas_expander->responding = 0;
6651 mpt2sas_expander_remove(ioc, sas_expander->sas_address);
6652 goto retry_expander_search;
6657 * _scsih_hide_unhide_sas_devices - add/remove device to/from OS
6658 * @ioc: per adapter object
6663 _scsih_hide_unhide_sas_devices(struct MPT2SAS_ADAPTER *ioc)
6665 struct _sas_device *sas_device, *sas_device_next;
6667 if (!ioc->is_warpdrive || ioc->mfg_pg10_hide_flag !=
6668 MFG_PAGE10_HIDE_IF_VOL_PRESENT)
6671 if (ioc->hide_drives) {
6672 if (_scsih_get_num_volumes(ioc))
6674 ioc->hide_drives = 0;
6675 list_for_each_entry_safe(sas_device, sas_device_next,
6676 &ioc->sas_device_list, list) {
6677 if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
6678 sas_device->sas_address_parent)) {
6679 _scsih_sas_device_remove(ioc, sas_device);
6680 } else if (!sas_device->starget) {
6681 mpt2sas_transport_port_remove(ioc,
6682 sas_device->sas_address,
6683 sas_device->sas_address_parent);
6684 _scsih_sas_device_remove(ioc, sas_device);
6688 if (!_scsih_get_num_volumes(ioc))
6690 ioc->hide_drives = 1;
6691 list_for_each_entry_safe(sas_device, sas_device_next,
6692 &ioc->sas_device_list, list) {
6693 mpt2sas_transport_port_remove(ioc,
6694 sas_device->sas_address,
6695 sas_device->sas_address_parent);
6701 * mpt2sas_scsih_reset_handler - reset callback handler (for scsih)
6702 * @ioc: per adapter object
6703 * @reset_phase: phase
6705 * The handler for doing any required cleanup or initialization.
6707 * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
6708 * MPT2_IOC_DONE_RESET
6713 mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase)
6715 switch (reset_phase) {
6716 case MPT2_IOC_PRE_RESET:
6717 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
6718 "MPT2_IOC_PRE_RESET\n", ioc->name, __func__));
6720 case MPT2_IOC_AFTER_RESET:
6721 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
6722 "MPT2_IOC_AFTER_RESET\n", ioc->name, __func__));
6723 if (ioc->scsih_cmds.status & MPT2_CMD_PENDING) {
6724 ioc->scsih_cmds.status |= MPT2_CMD_RESET;
6725 mpt2sas_base_free_smid(ioc, ioc->scsih_cmds.smid);
6726 complete(&ioc->scsih_cmds.done);
6728 if (ioc->tm_cmds.status & MPT2_CMD_PENDING) {
6729 ioc->tm_cmds.status |= MPT2_CMD_RESET;
6730 mpt2sas_base_free_smid(ioc, ioc->tm_cmds.smid);
6731 complete(&ioc->tm_cmds.done);
6733 _scsih_fw_event_cleanup_queue(ioc);
6734 _scsih_flush_running_cmds(ioc);
6735 _scsih_queue_rescan(ioc);
6737 case MPT2_IOC_DONE_RESET:
6738 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
6739 "MPT2_IOC_DONE_RESET\n", ioc->name, __func__));
6740 _scsih_sas_host_refresh(ioc);
6741 _scsih_prep_device_scan(ioc);
6742 _scsih_search_responding_sas_devices(ioc);
6743 _scsih_search_responding_raid_devices(ioc);
6744 _scsih_search_responding_expanders(ioc);
6750 * _firmware_event_work - delayed task for processing firmware events
6751 * @ioc: per adapter object
6752 * @work: equal to the fw_event_work object
6758 _firmware_event_work(struct work_struct *work)
6760 struct fw_event_work *fw_event = container_of(work,
6761 struct fw_event_work, delayed_work.work);
6762 unsigned long flags;
6763 struct MPT2SAS_ADAPTER *ioc = fw_event->ioc;
6765 /* the queue is being flushed so ignore this event */
6766 if (ioc->remove_host || fw_event->cancel_pending_work ||
6767 ioc->pci_error_recovery) {
6768 _scsih_fw_event_free(ioc, fw_event);
6772 if (fw_event->event == MPT2SAS_RESCAN_AFTER_HOST_RESET) {
6773 _scsih_fw_event_free(ioc, fw_event);
6774 spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags);
6775 if (ioc->shost_recovery) {
6776 init_completion(&ioc->shost_recovery_done);
6777 spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock,
6779 wait_for_completion(&ioc->shost_recovery_done);
6781 spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock,
6783 _scsih_remove_unresponding_sas_devices(ioc);
6784 _scsih_hide_unhide_sas_devices(ioc);
6788 switch (fw_event->event) {
6789 case MPT2SAS_TURN_ON_FAULT_LED:
6790 _scsih_turn_on_fault_led(ioc, fw_event->device_handle);
6792 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
6793 _scsih_sas_topology_change_event(ioc, fw_event);
6795 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
6796 _scsih_sas_device_status_change_event(ioc,
6799 case MPI2_EVENT_SAS_DISCOVERY:
6800 _scsih_sas_discovery_event(ioc,
6803 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
6804 _scsih_sas_broadcast_primative_event(ioc,
6807 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
6808 _scsih_sas_enclosure_dev_status_change_event(ioc,
6811 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
6812 _scsih_sas_ir_config_change_event(ioc, fw_event);
6814 case MPI2_EVENT_IR_VOLUME:
6815 _scsih_sas_ir_volume_event(ioc, fw_event);
6817 case MPI2_EVENT_IR_PHYSICAL_DISK:
6818 _scsih_sas_ir_physical_disk_event(ioc, fw_event);
6820 case MPI2_EVENT_IR_OPERATION_STATUS:
6821 _scsih_sas_ir_operation_status_event(ioc, fw_event);
6824 _scsih_fw_event_free(ioc, fw_event);
6828 * mpt2sas_scsih_event_callback - firmware event handler (called at ISR time)
6829 * @ioc: per adapter object
6830 * @msix_index: MSIX table index supplied by the OS
6831 * @reply: reply message frame(lower 32bit addr)
6832 * Context: interrupt.
6834 * This function merely adds a new work task into ioc->firmware_event_thread.
6835 * The tasks are worked from _firmware_event_work in user context.
6837 * Return 1 meaning mf should be freed from _base_interrupt
6838 * 0 means the mf is freed from this function.
6841 mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER *ioc, u8 msix_index,
6844 struct fw_event_work *fw_event;
6845 Mpi2EventNotificationReply_t *mpi_reply;
6849 /* events turned off due to host reset or driver unloading */
6850 if (ioc->remove_host || ioc->pci_error_recovery)
6853 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
6854 event = le16_to_cpu(mpi_reply->Event);
6858 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
6860 Mpi2EventDataSasBroadcastPrimitive_t *baen_data =
6861 (Mpi2EventDataSasBroadcastPrimitive_t *)
6862 mpi_reply->EventData;
6864 if (baen_data->Primitive !=
6865 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT ||
6866 ioc->broadcast_aen_busy)
6868 ioc->broadcast_aen_busy = 1;
6872 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
6873 _scsih_check_topo_delete_events(ioc,
6874 (Mpi2EventDataSasTopologyChangeList_t *)
6875 mpi_reply->EventData);
6877 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
6878 _scsih_check_ir_config_unhide_events(ioc,
6879 (Mpi2EventDataIrConfigChangeList_t *)
6880 mpi_reply->EventData);
6882 case MPI2_EVENT_IR_VOLUME:
6883 _scsih_check_volume_delete_events(ioc,
6884 (Mpi2EventDataIrVolume_t *)
6885 mpi_reply->EventData);
6887 case MPI2_EVENT_LOG_ENTRY_ADDED:
6889 Mpi2EventDataLogEntryAdded_t *log_entry;
6892 if (!ioc->is_warpdrive)
6895 log_entry = (Mpi2EventDataLogEntryAdded_t *)
6896 mpi_reply->EventData;
6897 log_code = (u32 *)log_entry->LogData;
6899 if (le16_to_cpu(log_entry->LogEntryQualifier)
6900 != MPT2_WARPDRIVE_LOGENTRY)
6903 switch (le32_to_cpu(*log_code)) {
6904 case MPT2_WARPDRIVE_LC_SSDT:
6905 printk(MPT2SAS_WARN_FMT "WarpDrive Warning: "
6906 "IO Throttling has occurred in the WarpDrive "
6907 "subsystem. Check WarpDrive documentation for "
6908 "additional details.\n", ioc->name);
6910 case MPT2_WARPDRIVE_LC_SSDLW:
6911 printk(MPT2SAS_WARN_FMT "WarpDrive Warning: "
6912 "Program/Erase Cycles for the WarpDrive subsystem "
6913 "in degraded range. Check WarpDrive documentation "
6914 "for additional details.\n", ioc->name);
6916 case MPT2_WARPDRIVE_LC_SSDLF:
6917 printk(MPT2SAS_ERR_FMT "WarpDrive Fatal Error: "
6918 "There are no Program/Erase Cycles for the "
6919 "WarpDrive subsystem. The storage device will be "
6920 "in read-only mode. Check WarpDrive documentation "
6921 "for additional details.\n", ioc->name);
6923 case MPT2_WARPDRIVE_LC_BRMF:
6924 printk(MPT2SAS_ERR_FMT "WarpDrive Fatal Error: "
6925 "The Backup Rail Monitor has failed on the "
6926 "WarpDrive subsystem. Check WarpDrive "
6927 "documentation for additional details.\n",
6934 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
6935 case MPI2_EVENT_IR_OPERATION_STATUS:
6936 case MPI2_EVENT_SAS_DISCOVERY:
6937 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
6938 case MPI2_EVENT_IR_PHYSICAL_DISK:
6941 default: /* ignore the rest */
6945 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
6947 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6948 ioc->name, __FILE__, __LINE__, __func__);
6951 sz = le16_to_cpu(mpi_reply->EventDataLength) * 4;
6952 fw_event->event_data = kzalloc(sz, GFP_ATOMIC);
6953 if (!fw_event->event_data) {
6954 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6955 ioc->name, __FILE__, __LINE__, __func__);
6960 memcpy(fw_event->event_data, mpi_reply->EventData,
6962 fw_event->ioc = ioc;
6963 fw_event->VF_ID = mpi_reply->VF_ID;
6964 fw_event->VP_ID = mpi_reply->VP_ID;
6965 fw_event->event = event;
6966 _scsih_fw_event_add(ioc, fw_event);
6970 /* shost template */
6971 static struct scsi_host_template scsih_driver_template = {
6972 .module = THIS_MODULE,
6973 .name = "Fusion MPT SAS Host",
6974 .proc_name = MPT2SAS_DRIVER_NAME,
6975 .queuecommand = _scsih_qcmd,
6976 .target_alloc = _scsih_target_alloc,
6977 .slave_alloc = _scsih_slave_alloc,
6978 .slave_configure = _scsih_slave_configure,
6979 .target_destroy = _scsih_target_destroy,
6980 .slave_destroy = _scsih_slave_destroy,
6981 .change_queue_depth = _scsih_change_queue_depth,
6982 .change_queue_type = _scsih_change_queue_type,
6983 .eh_abort_handler = _scsih_abort,
6984 .eh_device_reset_handler = _scsih_dev_reset,
6985 .eh_target_reset_handler = _scsih_target_reset,
6986 .eh_host_reset_handler = _scsih_host_reset,
6987 .bios_param = _scsih_bios_param,
6990 .sg_tablesize = MPT2SAS_SG_DEPTH,
6991 .max_sectors = 8192,
6993 .use_clustering = ENABLE_CLUSTERING,
6994 .shost_attrs = mpt2sas_host_attrs,
6995 .sdev_attrs = mpt2sas_dev_attrs,
6999 * _scsih_expander_node_remove - removing expander device from list.
7000 * @ioc: per adapter object
7001 * @sas_expander: the sas_device object
7002 * Context: Calling function should acquire ioc->sas_node_lock.
7004 * Removing object and freeing associated memory from the
7005 * ioc->sas_expander_list.
7010 _scsih_expander_node_remove(struct MPT2SAS_ADAPTER *ioc,
7011 struct _sas_node *sas_expander)
7013 struct _sas_port *mpt2sas_port, *next;
7015 /* remove sibling ports attached to this expander */
7016 list_for_each_entry_safe(mpt2sas_port, next,
7017 &sas_expander->sas_port_list, port_list) {
7018 if (ioc->shost_recovery)
7020 if (mpt2sas_port->remote_identify.device_type ==
7022 mpt2sas_device_remove(ioc,
7023 mpt2sas_port->remote_identify.sas_address);
7024 else if (mpt2sas_port->remote_identify.device_type ==
7025 SAS_EDGE_EXPANDER_DEVICE ||
7026 mpt2sas_port->remote_identify.device_type ==
7027 SAS_FANOUT_EXPANDER_DEVICE)
7028 mpt2sas_expander_remove(ioc,
7029 mpt2sas_port->remote_identify.sas_address);
7032 mpt2sas_transport_port_remove(ioc, sas_expander->sas_address,
7033 sas_expander->sas_address_parent);
7035 printk(MPT2SAS_INFO_FMT "expander_remove: handle"
7036 "(0x%04x), sas_addr(0x%016llx)\n", ioc->name,
7037 sas_expander->handle, (unsigned long long)
7038 sas_expander->sas_address);
7040 kfree(sas_expander->phy);
7041 kfree(sas_expander);
7045 * _scsih_ir_shutdown - IR shutdown notification
7046 * @ioc: per adapter object
7048 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
7049 * the host system is shutting down.
7054 _scsih_ir_shutdown(struct MPT2SAS_ADAPTER *ioc)
7056 Mpi2RaidActionRequest_t *mpi_request;
7057 Mpi2RaidActionReply_t *mpi_reply;
7060 /* is IR firmware build loaded ? */
7061 if (!ioc->ir_firmware)
7064 /* are there any volumes ? */
7065 if (list_empty(&ioc->raid_device_list))
7068 mutex_lock(&ioc->scsih_cmds.mutex);
7070 if (ioc->scsih_cmds.status != MPT2_CMD_NOT_USED) {
7071 printk(MPT2SAS_ERR_FMT "%s: scsih_cmd in use\n",
7072 ioc->name, __func__);
7075 ioc->scsih_cmds.status = MPT2_CMD_PENDING;
7077 smid = mpt2sas_base_get_smid(ioc, ioc->scsih_cb_idx);
7079 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
7080 ioc->name, __func__);
7081 ioc->scsih_cmds.status = MPT2_CMD_NOT_USED;
7085 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
7086 ioc->scsih_cmds.smid = smid;
7087 memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t));
7089 mpi_request->Function = MPI2_FUNCTION_RAID_ACTION;
7090 mpi_request->Action = MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED;
7092 if (!ioc->hide_ir_msg)
7093 printk(MPT2SAS_INFO_FMT "IR shutdown (sending)\n", ioc->name);
7094 init_completion(&ioc->scsih_cmds.done);
7095 mpt2sas_base_put_smid_default(ioc, smid);
7096 wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ);
7098 if (!(ioc->scsih_cmds.status & MPT2_CMD_COMPLETE)) {
7099 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
7100 ioc->name, __func__);
7104 if (ioc->scsih_cmds.status & MPT2_CMD_REPLY_VALID) {
7105 mpi_reply = ioc->scsih_cmds.reply;
7107 if (!ioc->hide_ir_msg)
7108 printk(MPT2SAS_INFO_FMT "IR shutdown (complete): "
7109 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7110 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
7111 le32_to_cpu(mpi_reply->IOCLogInfo));
7115 ioc->scsih_cmds.status = MPT2_CMD_NOT_USED;
7116 mutex_unlock(&ioc->scsih_cmds.mutex);
7120 * _scsih_shutdown - routine call during system shutdown
7121 * @pdev: PCI device struct
7126 _scsih_shutdown(struct pci_dev *pdev)
7128 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7129 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
7130 struct workqueue_struct *wq;
7131 unsigned long flags;
7133 ioc->remove_host = 1;
7134 _scsih_fw_event_cleanup_queue(ioc);
7136 spin_lock_irqsave(&ioc->fw_event_lock, flags);
7137 wq = ioc->firmware_event_thread;
7138 ioc->firmware_event_thread = NULL;
7139 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
7141 destroy_workqueue(wq);
7143 _scsih_ir_shutdown(ioc);
7144 mpt2sas_base_detach(ioc);
7148 * _scsih_remove - detach and remove add host
7149 * @pdev: PCI device struct
7151 * Routine called when unloading the driver.
7154 static void __devexit
7155 _scsih_remove(struct pci_dev *pdev)
7157 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7158 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
7159 struct _sas_port *mpt2sas_port, *next_port;
7160 struct _raid_device *raid_device, *next;
7161 struct MPT2SAS_TARGET *sas_target_priv_data;
7162 struct workqueue_struct *wq;
7163 unsigned long flags;
7165 ioc->remove_host = 1;
7166 _scsih_fw_event_cleanup_queue(ioc);
7168 spin_lock_irqsave(&ioc->fw_event_lock, flags);
7169 wq = ioc->firmware_event_thread;
7170 ioc->firmware_event_thread = NULL;
7171 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
7173 destroy_workqueue(wq);
7175 /* release all the volumes */
7176 _scsih_ir_shutdown(ioc);
7177 list_for_each_entry_safe(raid_device, next, &ioc->raid_device_list,
7179 if (raid_device->starget) {
7180 sas_target_priv_data =
7181 raid_device->starget->hostdata;
7182 sas_target_priv_data->deleted = 1;
7183 scsi_remove_target(&raid_device->starget->dev);
7185 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), wwid"
7186 "(0x%016llx)\n", ioc->name, raid_device->handle,
7187 (unsigned long long) raid_device->wwid);
7188 _scsih_raid_device_remove(ioc, raid_device);
7191 /* free ports attached to the sas_host */
7192 list_for_each_entry_safe(mpt2sas_port, next_port,
7193 &ioc->sas_hba.sas_port_list, port_list) {
7194 if (mpt2sas_port->remote_identify.device_type ==
7196 mpt2sas_device_remove(ioc,
7197 mpt2sas_port->remote_identify.sas_address);
7198 else if (mpt2sas_port->remote_identify.device_type ==
7199 SAS_EDGE_EXPANDER_DEVICE ||
7200 mpt2sas_port->remote_identify.device_type ==
7201 SAS_FANOUT_EXPANDER_DEVICE)
7202 mpt2sas_expander_remove(ioc,
7203 mpt2sas_port->remote_identify.sas_address);
7206 /* free phys attached to the sas_host */
7207 if (ioc->sas_hba.num_phys) {
7208 kfree(ioc->sas_hba.phy);
7209 ioc->sas_hba.phy = NULL;
7210 ioc->sas_hba.num_phys = 0;
7213 sas_remove_host(shost);
7214 _scsih_shutdown(pdev);
7215 list_del(&ioc->list);
7216 scsi_remove_host(shost);
7217 scsi_host_put(shost);
7221 * _scsih_probe_boot_devices - reports 1st device
7222 * @ioc: per adapter object
7224 * If specified in bios page 2, this routine reports the 1st
7225 * device scsi-ml or sas transport for persistent boot device
7226 * purposes. Please refer to function _scsih_determine_boot_device()
7229 _scsih_probe_boot_devices(struct MPT2SAS_ADAPTER *ioc)
7233 struct _sas_device *sas_device;
7234 struct _raid_device *raid_device;
7236 u64 sas_address_parent;
7238 unsigned long flags;
7242 if (ioc->req_boot_device.device) {
7243 device = ioc->req_boot_device.device;
7244 is_raid = ioc->req_boot_device.is_raid;
7245 } else if (ioc->req_alt_boot_device.device) {
7246 device = ioc->req_alt_boot_device.device;
7247 is_raid = ioc->req_alt_boot_device.is_raid;
7248 } else if (ioc->current_boot_device.device) {
7249 device = ioc->current_boot_device.device;
7250 is_raid = ioc->current_boot_device.is_raid;
7257 raid_device = device;
7258 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
7259 raid_device->id, 0);
7261 _scsih_raid_device_remove(ioc, raid_device);
7263 sas_device = device;
7264 handle = sas_device->handle;
7265 sas_address_parent = sas_device->sas_address_parent;
7266 sas_address = sas_device->sas_address;
7267 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7268 list_move_tail(&sas_device->list, &ioc->sas_device_list);
7269 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7271 if (ioc->hide_drives)
7273 if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
7274 sas_device->sas_address_parent)) {
7275 _scsih_sas_device_remove(ioc, sas_device);
7276 } else if (!sas_device->starget) {
7277 mpt2sas_transport_port_remove(ioc, sas_address,
7278 sas_address_parent);
7279 _scsih_sas_device_remove(ioc, sas_device);
7285 * _scsih_probe_raid - reporting raid volumes to scsi-ml
7286 * @ioc: per adapter object
7288 * Called during initial loading of the driver.
7291 _scsih_probe_raid(struct MPT2SAS_ADAPTER *ioc)
7293 struct _raid_device *raid_device, *raid_next;
7296 list_for_each_entry_safe(raid_device, raid_next,
7297 &ioc->raid_device_list, list) {
7298 if (raid_device->starget)
7300 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
7301 raid_device->id, 0);
7303 _scsih_raid_device_remove(ioc, raid_device);
7308 * _scsih_probe_sas - reporting sas devices to sas transport
7309 * @ioc: per adapter object
7311 * Called during initial loading of the driver.
7314 _scsih_probe_sas(struct MPT2SAS_ADAPTER *ioc)
7316 struct _sas_device *sas_device, *next;
7317 unsigned long flags;
7319 /* SAS Device List */
7320 list_for_each_entry_safe(sas_device, next, &ioc->sas_device_init_list,
7322 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7323 list_move_tail(&sas_device->list, &ioc->sas_device_list);
7324 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7326 if (ioc->hide_drives)
7329 if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
7330 sas_device->sas_address_parent)) {
7331 _scsih_sas_device_remove(ioc, sas_device);
7332 } else if (!sas_device->starget) {
7333 mpt2sas_transport_port_remove(ioc,
7334 sas_device->sas_address,
7335 sas_device->sas_address_parent);
7336 _scsih_sas_device_remove(ioc, sas_device);
7342 * _scsih_probe_devices - probing for devices
7343 * @ioc: per adapter object
7345 * Called during initial loading of the driver.
7348 _scsih_probe_devices(struct MPT2SAS_ADAPTER *ioc)
7350 u16 volume_mapping_flags =
7351 le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) &
7352 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE;
7354 if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR))
7355 return; /* return when IOC doesn't support initiator mode */
7357 _scsih_probe_boot_devices(ioc);
7359 if (ioc->ir_firmware) {
7360 if ((volume_mapping_flags &
7361 MPI2_IOCPAGE8_IRFLAGS_HIGH_VOLUME_MAPPING)) {
7362 _scsih_probe_sas(ioc);
7363 _scsih_probe_raid(ioc);
7365 _scsih_probe_raid(ioc);
7366 _scsih_probe_sas(ioc);
7369 _scsih_probe_sas(ioc);
7373 * _scsih_probe - attach and add scsi host
7374 * @pdev: PCI device struct
7375 * @id: pci device id
7377 * Returns 0 success, anything else error.
7380 _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id)
7382 struct MPT2SAS_ADAPTER *ioc;
7383 struct Scsi_Host *shost;
7385 shost = scsi_host_alloc(&scsih_driver_template,
7386 sizeof(struct MPT2SAS_ADAPTER));
7390 /* init local params */
7391 ioc = shost_priv(shost);
7392 memset(ioc, 0, sizeof(struct MPT2SAS_ADAPTER));
7393 INIT_LIST_HEAD(&ioc->list);
7394 list_add_tail(&ioc->list, &mpt2sas_ioc_list);
7396 ioc->id = mpt_ids++;
7397 sprintf(ioc->name, "%s%d", MPT2SAS_DRIVER_NAME, ioc->id);
7399 if (id->device == MPI2_MFGPAGE_DEVID_SSS6200) {
7400 ioc->is_warpdrive = 1;
7401 ioc->hide_ir_msg = 1;
7403 ioc->mfg_pg10_hide_flag = MFG_PAGE10_EXPOSE_ALL_DISKS;
7404 ioc->scsi_io_cb_idx = scsi_io_cb_idx;
7405 ioc->tm_cb_idx = tm_cb_idx;
7406 ioc->ctl_cb_idx = ctl_cb_idx;
7407 ioc->base_cb_idx = base_cb_idx;
7408 ioc->transport_cb_idx = transport_cb_idx;
7409 ioc->scsih_cb_idx = scsih_cb_idx;
7410 ioc->config_cb_idx = config_cb_idx;
7411 ioc->tm_tr_cb_idx = tm_tr_cb_idx;
7412 ioc->tm_tr_volume_cb_idx = tm_tr_volume_cb_idx;
7413 ioc->tm_sas_control_cb_idx = tm_sas_control_cb_idx;
7414 ioc->logging_level = logging_level;
7415 /* misc semaphores and spin locks */
7416 mutex_init(&ioc->reset_in_progress_mutex);
7417 spin_lock_init(&ioc->ioc_reset_in_progress_lock);
7418 spin_lock_init(&ioc->scsi_lookup_lock);
7419 spin_lock_init(&ioc->sas_device_lock);
7420 spin_lock_init(&ioc->sas_node_lock);
7421 spin_lock_init(&ioc->fw_event_lock);
7422 spin_lock_init(&ioc->raid_device_lock);
7424 INIT_LIST_HEAD(&ioc->sas_device_list);
7425 INIT_LIST_HEAD(&ioc->sas_device_init_list);
7426 INIT_LIST_HEAD(&ioc->sas_expander_list);
7427 INIT_LIST_HEAD(&ioc->fw_event_list);
7428 INIT_LIST_HEAD(&ioc->raid_device_list);
7429 INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list);
7430 INIT_LIST_HEAD(&ioc->delayed_tr_list);
7431 INIT_LIST_HEAD(&ioc->delayed_tr_volume_list);
7433 /* init shost parameters */
7434 shost->max_cmd_len = 32;
7435 shost->max_lun = max_lun;
7436 shost->transportt = mpt2sas_transport_template;
7437 shost->unique_id = ioc->id;
7439 if ((scsi_add_host(shost, &pdev->dev))) {
7440 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
7441 ioc->name, __FILE__, __LINE__, __func__);
7442 list_del(&ioc->list);
7443 goto out_add_shost_fail;
7446 scsi_host_set_prot(shost, SHOST_DIF_TYPE1_PROTECTION
7447 | SHOST_DIF_TYPE2_PROTECTION | SHOST_DIF_TYPE3_PROTECTION);
7448 scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC);
7451 snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name),
7452 "fw_event%d", ioc->id);
7453 ioc->firmware_event_thread = create_singlethread_workqueue(
7454 ioc->firmware_event_name);
7455 if (!ioc->firmware_event_thread) {
7456 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
7457 ioc->name, __FILE__, __LINE__, __func__);
7458 goto out_thread_fail;
7461 ioc->wait_for_port_enable_to_complete = 1;
7462 if ((mpt2sas_base_attach(ioc))) {
7463 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
7464 ioc->name, __FILE__, __LINE__, __func__);
7465 goto out_attach_fail;
7468 ioc->wait_for_port_enable_to_complete = 0;
7469 if (ioc->is_warpdrive) {
7470 if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS)
7471 ioc->hide_drives = 0;
7472 else if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_HIDE_ALL_DISKS)
7473 ioc->hide_drives = 1;
7475 if (_scsih_get_num_volumes(ioc))
7476 ioc->hide_drives = 1;
7478 ioc->hide_drives = 0;
7481 ioc->hide_drives = 0;
7483 _scsih_probe_devices(ioc);
7487 destroy_workqueue(ioc->firmware_event_thread);
7489 list_del(&ioc->list);
7490 scsi_remove_host(shost);
7497 * _scsih_suspend - power management suspend main entry point
7498 * @pdev: PCI device struct
7499 * @state: PM state change to (usually PCI_D3)
7501 * Returns 0 success, anything else error.
7504 _scsih_suspend(struct pci_dev *pdev, pm_message_t state)
7506 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7507 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
7510 mpt2sas_base_stop_watchdog(ioc);
7511 scsi_block_requests(shost);
7512 device_state = pci_choose_state(pdev, state);
7513 printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, entering "
7514 "operating state [D%d]\n", ioc->name, pdev,
7515 pci_name(pdev), device_state);
7517 mpt2sas_base_free_resources(ioc);
7518 pci_save_state(pdev);
7519 pci_disable_device(pdev);
7520 pci_set_power_state(pdev, device_state);
7525 * _scsih_resume - power management resume main entry point
7526 * @pdev: PCI device struct
7528 * Returns 0 success, anything else error.
7531 _scsih_resume(struct pci_dev *pdev)
7533 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7534 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
7535 u32 device_state = pdev->current_state;
7538 printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, previous "
7539 "operating state [D%d]\n", ioc->name, pdev,
7540 pci_name(pdev), device_state);
7542 pci_set_power_state(pdev, PCI_D0);
7543 pci_enable_wake(pdev, PCI_D0, 0);
7544 pci_restore_state(pdev);
7546 r = mpt2sas_base_map_resources(ioc);
7550 mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, SOFT_RESET);
7551 scsi_unblock_requests(shost);
7552 mpt2sas_base_start_watchdog(ioc);
7555 #endif /* CONFIG_PM */
7558 * _scsih_pci_error_detected - Called when a PCI error is detected.
7559 * @pdev: PCI device struct
7560 * @state: PCI channel state
7562 * Description: Called when a PCI error is detected.
7565 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
7567 static pci_ers_result_t
7568 _scsih_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
7570 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7571 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
7573 printk(MPT2SAS_INFO_FMT "PCI error: detected callback, state(%d)!!\n",
7577 case pci_channel_io_normal:
7578 return PCI_ERS_RESULT_CAN_RECOVER;
7579 case pci_channel_io_frozen:
7580 /* Fatal error, prepare for slot reset */
7581 ioc->pci_error_recovery = 1;
7582 scsi_block_requests(ioc->shost);
7583 mpt2sas_base_stop_watchdog(ioc);
7584 mpt2sas_base_free_resources(ioc);
7585 return PCI_ERS_RESULT_NEED_RESET;
7586 case pci_channel_io_perm_failure:
7587 /* Permanent error, prepare for device removal */
7588 ioc->pci_error_recovery = 1;
7589 mpt2sas_base_stop_watchdog(ioc);
7590 _scsih_flush_running_cmds(ioc);
7591 return PCI_ERS_RESULT_DISCONNECT;
7593 return PCI_ERS_RESULT_NEED_RESET;
7597 * _scsih_pci_slot_reset - Called when PCI slot has been reset.
7598 * @pdev: PCI device struct
7600 * Description: This routine is called by the pci error recovery
7601 * code after the PCI slot has been reset, just before we
7602 * should resume normal operations.
7604 static pci_ers_result_t
7605 _scsih_pci_slot_reset(struct pci_dev *pdev)
7607 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7608 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
7611 printk(MPT2SAS_INFO_FMT "PCI error: slot reset callback!!\n",
7614 ioc->pci_error_recovery = 0;
7616 pci_restore_state(pdev);
7617 rc = mpt2sas_base_map_resources(ioc);
7619 return PCI_ERS_RESULT_DISCONNECT;
7622 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
7625 printk(MPT2SAS_WARN_FMT "hard reset: %s\n", ioc->name,
7626 (rc == 0) ? "success" : "failed");
7629 return PCI_ERS_RESULT_RECOVERED;
7631 return PCI_ERS_RESULT_DISCONNECT;
7635 * _scsih_pci_resume() - resume normal ops after PCI reset
7636 * @pdev: pointer to PCI device
7638 * Called when the error recovery driver tells us that its
7639 * OK to resume normal operation. Use completion to allow
7640 * halted scsi ops to resume.
7643 _scsih_pci_resume(struct pci_dev *pdev)
7645 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7646 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
7648 printk(MPT2SAS_INFO_FMT "PCI error: resume callback!!\n", ioc->name);
7650 pci_cleanup_aer_uncorrect_error_status(pdev);
7651 mpt2sas_base_start_watchdog(ioc);
7652 scsi_unblock_requests(ioc->shost);
7656 * _scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
7657 * @pdev: pointer to PCI device
7659 static pci_ers_result_t
7660 _scsih_pci_mmio_enabled(struct pci_dev *pdev)
7662 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7663 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
7665 printk(MPT2SAS_INFO_FMT "PCI error: mmio enabled callback!!\n",
7668 /* TODO - dump whatever for debugging purposes */
7670 /* Request a slot reset. */
7671 return PCI_ERS_RESULT_NEED_RESET;
7674 static struct pci_error_handlers _scsih_err_handler = {
7675 .error_detected = _scsih_pci_error_detected,
7676 .mmio_enabled = _scsih_pci_mmio_enabled,
7677 .slot_reset = _scsih_pci_slot_reset,
7678 .resume = _scsih_pci_resume,
7681 static struct pci_driver scsih_driver = {
7682 .name = MPT2SAS_DRIVER_NAME,
7683 .id_table = scsih_pci_table,
7684 .probe = _scsih_probe,
7685 .remove = __devexit_p(_scsih_remove),
7686 .shutdown = _scsih_shutdown,
7687 .err_handler = &_scsih_err_handler,
7689 .suspend = _scsih_suspend,
7690 .resume = _scsih_resume,
7694 /* raid transport support */
7695 static struct raid_function_template mpt2sas_raid_functions = {
7696 .cookie = &scsih_driver_template,
7697 .is_raid = _scsih_is_raid,
7698 .get_resync = _scsih_get_resync,
7699 .get_state = _scsih_get_state,
7703 * _scsih_init - main entry point for this driver.
7705 * Returns 0 success, anything else error.
7713 printk(KERN_INFO "%s version %s loaded\n", MPT2SAS_DRIVER_NAME,
7714 MPT2SAS_DRIVER_VERSION);
7716 mpt2sas_transport_template =
7717 sas_attach_transport(&mpt2sas_transport_functions);
7718 if (!mpt2sas_transport_template)
7720 /* raid transport support */
7721 mpt2sas_raid_template = raid_class_attach(&mpt2sas_raid_functions);
7722 if (!mpt2sas_raid_template) {
7723 sas_release_transport(mpt2sas_transport_template);
7727 mpt2sas_base_initialize_callback_handler();
7729 /* queuecommand callback hander */
7730 scsi_io_cb_idx = mpt2sas_base_register_callback_handler(_scsih_io_done);
7732 /* task management callback handler */
7733 tm_cb_idx = mpt2sas_base_register_callback_handler(_scsih_tm_done);
7735 /* base internal commands callback handler */
7736 base_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_base_done);
7738 /* transport internal commands callback handler */
7739 transport_cb_idx = mpt2sas_base_register_callback_handler(
7740 mpt2sas_transport_done);
7742 /* scsih internal commands callback handler */
7743 scsih_cb_idx = mpt2sas_base_register_callback_handler(_scsih_done);
7745 /* configuration page API internal commands callback handler */
7746 config_cb_idx = mpt2sas_base_register_callback_handler(
7747 mpt2sas_config_done);
7749 /* ctl module callback handler */
7750 ctl_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_ctl_done);
7752 tm_tr_cb_idx = mpt2sas_base_register_callback_handler(
7753 _scsih_tm_tr_complete);
7755 tm_tr_volume_cb_idx = mpt2sas_base_register_callback_handler(
7756 _scsih_tm_volume_tr_complete);
7758 tm_sas_control_cb_idx = mpt2sas_base_register_callback_handler(
7759 _scsih_sas_control_complete);
7763 error = pci_register_driver(&scsih_driver);
7765 /* raid transport support */
7766 raid_class_release(mpt2sas_raid_template);
7767 sas_release_transport(mpt2sas_transport_template);
7774 * _scsih_exit - exit point for this driver (when it is a module).
7776 * Returns 0 success, anything else error.
7781 printk(KERN_INFO "mpt2sas version %s unloading\n",
7782 MPT2SAS_DRIVER_VERSION);
7784 pci_unregister_driver(&scsih_driver);
7788 mpt2sas_base_release_callback_handler(scsi_io_cb_idx);
7789 mpt2sas_base_release_callback_handler(tm_cb_idx);
7790 mpt2sas_base_release_callback_handler(base_cb_idx);
7791 mpt2sas_base_release_callback_handler(transport_cb_idx);
7792 mpt2sas_base_release_callback_handler(scsih_cb_idx);
7793 mpt2sas_base_release_callback_handler(config_cb_idx);
7794 mpt2sas_base_release_callback_handler(ctl_cb_idx);
7796 mpt2sas_base_release_callback_handler(tm_tr_cb_idx);
7797 mpt2sas_base_release_callback_handler(tm_tr_volume_cb_idx);
7798 mpt2sas_base_release_callback_handler(tm_sas_control_cb_idx);
7800 /* raid transport support */
7801 raid_class_release(mpt2sas_raid_template);
7802 sas_release_transport(mpt2sas_transport_template);
7806 module_init(_scsih_init);
7807 module_exit(_scsih_exit);