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-2008 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>
56 #include "mpt2sas_base.h"
58 MODULE_AUTHOR(MPT2SAS_AUTHOR);
59 MODULE_DESCRIPTION(MPT2SAS_DESCRIPTION);
60 MODULE_LICENSE("GPL");
61 MODULE_VERSION(MPT2SAS_DRIVER_VERSION);
63 #define RAID_CHANNEL 1
66 static void _scsih_expander_node_remove(struct MPT2SAS_ADAPTER *ioc,
67 struct _sas_node *sas_expander);
68 static void _firmware_event_work(struct work_struct *work);
70 /* global parameters */
71 LIST_HEAD(mpt2sas_ioc_list);
73 /* local parameters */
74 static u8 scsi_io_cb_idx = -1;
75 static u8 tm_cb_idx = -1;
76 static u8 ctl_cb_idx = -1;
77 static u8 base_cb_idx = -1;
78 static u8 transport_cb_idx = -1;
79 static u8 config_cb_idx = -1;
82 /* command line options */
83 static u32 logging_level;
84 MODULE_PARM_DESC(logging_level, " bits for enabling additional logging info "
87 /* scsi-mid layer global parmeter is max_report_luns, which is 511 */
88 #define MPT2SAS_MAX_LUN (16895)
89 static int max_lun = MPT2SAS_MAX_LUN;
90 module_param(max_lun, int, 0);
91 MODULE_PARM_DESC(max_lun, " max lun, default=16895 ");
94 * struct sense_info - common structure for obtaining sense keys
96 * @asc: additional sense code
97 * @ascq: additional sense code qualifier
106 #define MPT2SAS_RESCAN_AFTER_HOST_RESET (0xFFFF)
108 * struct fw_event_work - firmware event struct
109 * @list: link list framework
110 * @work: work object (ioc->fault_reset_work_q)
111 * @ioc: per adapter object
112 * @VF_ID: virtual function id
113 * @host_reset_handling: handling events during host reset
114 * @ignore: flag meaning this event has been marked to ignore
115 * @event: firmware event MPI2_EVENT_XXX defined in mpt2_ioc.h
116 * @event_data: reply event data payload follows
118 * This object stored on ioc->fw_event_list.
120 struct fw_event_work {
121 struct list_head list;
122 struct delayed_work work;
123 struct MPT2SAS_ADAPTER *ioc;
125 u8 host_reset_handling;
132 * struct _scsi_io_transfer - scsi io transfer
133 * @handle: sas device handle (assigned by firmware)
134 * @is_raid: flag set for hidden raid components
135 * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE,
136 * @data_length: data transfer length
137 * @data_dma: dma pointer to data
140 * @cdb_length: cdb length
142 * @valid_reply: flag set for reply message
143 * @timeout: timeout for this command
144 * @sense_length: sense length
145 * @ioc_status: ioc status
146 * @scsi_state: scsi state
147 * @scsi_status: scsi staus
148 * @log_info: log information
149 * @transfer_length: data length transfer when there is a reply message
151 * Used for sending internal scsi commands to devices within this module.
152 * Refer to _scsi_send_scsi_io().
154 struct _scsi_io_transfer {
157 enum dma_data_direction dir;
160 u8 sense[SCSI_SENSE_BUFFERSIZE];
166 /* the following bits are only valid when 'valid_reply = 1' */
176 * The pci device ids are defined in mpi/mpi2_cnfg.h.
178 static struct pci_device_id scsih_pci_table[] = {
179 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2004,
180 PCI_ANY_ID, PCI_ANY_ID },
182 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2008,
183 PCI_ANY_ID, PCI_ANY_ID },
184 /* Liberator ~ 2108 */
185 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_1,
186 PCI_ANY_ID, PCI_ANY_ID },
187 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_2,
188 PCI_ANY_ID, PCI_ANY_ID },
189 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_3,
190 PCI_ANY_ID, PCI_ANY_ID },
191 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_1,
192 PCI_ANY_ID, PCI_ANY_ID },
193 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_2,
194 PCI_ANY_ID, PCI_ANY_ID },
195 {0} /* Terminating entry */
197 MODULE_DEVICE_TABLE(pci, scsih_pci_table);
200 * scsih_set_debug_level - global setting of ioc->logging_level.
202 * Note: The logging levels are defined in mpt2sas_debug.h.
205 scsih_set_debug_level(const char *val, struct kernel_param *kp)
207 int ret = param_set_int(val, kp);
208 struct MPT2SAS_ADAPTER *ioc;
213 printk(KERN_INFO "setting logging_level(0x%08x)\n", logging_level);
214 list_for_each_entry(ioc, &mpt2sas_ioc_list, list)
215 ioc->logging_level = logging_level;
218 module_param_call(logging_level, scsih_set_debug_level, param_get_int,
219 &logging_level, 0644);
222 * _scsih_srch_boot_sas_address - search based on sas_address
223 * @sas_address: sas address
224 * @boot_device: boot device object from bios page 2
226 * Returns 1 when there's a match, 0 means no match.
229 _scsih_srch_boot_sas_address(u64 sas_address,
230 Mpi2BootDeviceSasWwid_t *boot_device)
232 return (sas_address == le64_to_cpu(boot_device->SASAddress)) ? 1 : 0;
236 * _scsih_srch_boot_device_name - search based on device name
237 * @device_name: device name specified in INDENTIFY fram
238 * @boot_device: boot device object from bios page 2
240 * Returns 1 when there's a match, 0 means no match.
243 _scsih_srch_boot_device_name(u64 device_name,
244 Mpi2BootDeviceDeviceName_t *boot_device)
246 return (device_name == le64_to_cpu(boot_device->DeviceName)) ? 1 : 0;
250 * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot
251 * @enclosure_logical_id: enclosure logical id
252 * @slot_number: slot number
253 * @boot_device: boot device object from bios page 2
255 * Returns 1 when there's a match, 0 means no match.
258 _scsih_srch_boot_encl_slot(u64 enclosure_logical_id, u16 slot_number,
259 Mpi2BootDeviceEnclosureSlot_t *boot_device)
261 return (enclosure_logical_id == le64_to_cpu(boot_device->
262 EnclosureLogicalID) && slot_number == le16_to_cpu(boot_device->
263 SlotNumber)) ? 1 : 0;
267 * _scsih_is_boot_device - search for matching boot device.
268 * @sas_address: sas address
269 * @device_name: device name specified in INDENTIFY fram
270 * @enclosure_logical_id: enclosure logical id
271 * @slot_number: slot number
272 * @form: specifies boot device form
273 * @boot_device: boot device object from bios page 2
275 * Returns 1 when there's a match, 0 means no match.
278 _scsih_is_boot_device(u64 sas_address, u64 device_name,
279 u64 enclosure_logical_id, u16 slot, u8 form,
280 Mpi2BiosPage2BootDevice_t *boot_device)
285 case MPI2_BIOSPAGE2_FORM_SAS_WWID:
288 rc = _scsih_srch_boot_sas_address(
289 sas_address, &boot_device->SasWwid);
291 case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT:
292 if (!enclosure_logical_id)
294 rc = _scsih_srch_boot_encl_slot(
295 enclosure_logical_id,
296 slot, &boot_device->EnclosureSlot);
298 case MPI2_BIOSPAGE2_FORM_DEVICE_NAME:
301 rc = _scsih_srch_boot_device_name(
302 device_name, &boot_device->DeviceName);
304 case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED:
312 * _scsih_determine_boot_device - determine boot device.
313 * @ioc: per adapter object
314 * @device: either sas_device or raid_device object
315 * @is_raid: [flag] 1 = raid object, 0 = sas object
317 * Determines whether this device should be first reported device to
318 * to scsi-ml or sas transport, this purpose is for persistant boot device.
319 * There are primary, alternate, and current entries in bios page 2. The order
320 * priority is primary, alternate, then current. This routine saves
321 * the corresponding device object and is_raid flag in the ioc object.
322 * The saved data to be used later in _scsih_probe_boot_devices().
325 _scsih_determine_boot_device(struct MPT2SAS_ADAPTER *ioc,
326 void *device, u8 is_raid)
328 struct _sas_device *sas_device;
329 struct _raid_device *raid_device;
332 u64 enclosure_logical_id;
335 /* only process this function when driver loads */
336 if (!ioc->wait_for_port_enable_to_complete)
341 sas_address = sas_device->sas_address;
342 device_name = sas_device->device_name;
343 enclosure_logical_id = sas_device->enclosure_logical_id;
344 slot = sas_device->slot;
346 raid_device = device;
347 sas_address = raid_device->wwid;
349 enclosure_logical_id = 0;
353 if (!ioc->req_boot_device.device) {
354 if (_scsih_is_boot_device(sas_address, device_name,
355 enclosure_logical_id, slot,
356 (ioc->bios_pg2.ReqBootDeviceForm &
357 MPI2_BIOSPAGE2_FORM_MASK),
358 &ioc->bios_pg2.RequestedBootDevice)) {
359 dinitprintk(ioc, printk(MPT2SAS_DEBUG_FMT
360 "%s: req_boot_device(0x%016llx)\n",
362 (unsigned long long)sas_address));
363 ioc->req_boot_device.device = device;
364 ioc->req_boot_device.is_raid = is_raid;
368 if (!ioc->req_alt_boot_device.device) {
369 if (_scsih_is_boot_device(sas_address, device_name,
370 enclosure_logical_id, slot,
371 (ioc->bios_pg2.ReqAltBootDeviceForm &
372 MPI2_BIOSPAGE2_FORM_MASK),
373 &ioc->bios_pg2.RequestedAltBootDevice)) {
374 dinitprintk(ioc, printk(MPT2SAS_DEBUG_FMT
375 "%s: req_alt_boot_device(0x%016llx)\n",
377 (unsigned long long)sas_address));
378 ioc->req_alt_boot_device.device = device;
379 ioc->req_alt_boot_device.is_raid = is_raid;
383 if (!ioc->current_boot_device.device) {
384 if (_scsih_is_boot_device(sas_address, device_name,
385 enclosure_logical_id, slot,
386 (ioc->bios_pg2.CurrentBootDeviceForm &
387 MPI2_BIOSPAGE2_FORM_MASK),
388 &ioc->bios_pg2.CurrentBootDevice)) {
389 dinitprintk(ioc, printk(MPT2SAS_DEBUG_FMT
390 "%s: current_boot_device(0x%016llx)\n",
392 (unsigned long long)sas_address));
393 ioc->current_boot_device.device = device;
394 ioc->current_boot_device.is_raid = is_raid;
400 * mpt2sas_scsih_sas_device_find_by_sas_address - sas device search
401 * @ioc: per adapter object
402 * @sas_address: sas address
403 * Context: Calling function should acquire ioc->sas_device_lock
405 * This searches for sas_device based on sas_address, then return sas_device
409 mpt2sas_scsih_sas_device_find_by_sas_address(struct MPT2SAS_ADAPTER *ioc,
412 struct _sas_device *sas_device, *r;
415 /* check the sas_device_init_list */
416 list_for_each_entry(sas_device, &ioc->sas_device_init_list,
418 if (sas_device->sas_address != sas_address)
424 /* then check the sas_device_list */
425 list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
426 if (sas_device->sas_address != sas_address)
436 * _scsih_sas_device_find_by_handle - sas device search
437 * @ioc: per adapter object
438 * @handle: sas device handle (assigned by firmware)
439 * Context: Calling function should acquire ioc->sas_device_lock
441 * This searches for sas_device based on sas_address, then return sas_device
444 static struct _sas_device *
445 _scsih_sas_device_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
447 struct _sas_device *sas_device, *r;
450 if (ioc->wait_for_port_enable_to_complete) {
451 list_for_each_entry(sas_device, &ioc->sas_device_init_list,
453 if (sas_device->handle != handle)
459 list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
460 if (sas_device->handle != handle)
472 * _scsih_sas_device_remove - remove sas_device from list.
473 * @ioc: per adapter object
474 * @sas_device: the sas_device object
475 * Context: This function will acquire ioc->sas_device_lock.
477 * Removing object and freeing associated memory from the ioc->sas_device_list.
480 _scsih_sas_device_remove(struct MPT2SAS_ADAPTER *ioc,
481 struct _sas_device *sas_device)
485 spin_lock_irqsave(&ioc->sas_device_lock, flags);
486 list_del(&sas_device->list);
487 memset(sas_device, 0, sizeof(struct _sas_device));
489 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
493 * _scsih_sas_device_add - insert sas_device to the list.
494 * @ioc: per adapter object
495 * @sas_device: the sas_device object
496 * Context: This function will acquire ioc->sas_device_lock.
498 * Adding new object to the ioc->sas_device_list.
501 _scsih_sas_device_add(struct MPT2SAS_ADAPTER *ioc,
502 struct _sas_device *sas_device)
505 u16 handle, parent_handle;
508 dewtprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: handle"
509 "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
510 sas_device->handle, (unsigned long long)sas_device->sas_address));
512 spin_lock_irqsave(&ioc->sas_device_lock, flags);
513 list_add_tail(&sas_device->list, &ioc->sas_device_list);
514 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
516 handle = sas_device->handle;
517 parent_handle = sas_device->parent_handle;
518 sas_address = sas_device->sas_address;
519 if (!mpt2sas_transport_port_add(ioc, handle, parent_handle)) {
520 _scsih_sas_device_remove(ioc, sas_device);
521 } else if (!sas_device->starget) {
522 mpt2sas_transport_port_remove(ioc, sas_address, parent_handle);
523 _scsih_sas_device_remove(ioc, sas_device);
528 * _scsih_sas_device_init_add - insert sas_device to the list.
529 * @ioc: per adapter object
530 * @sas_device: the sas_device object
531 * Context: This function will acquire ioc->sas_device_lock.
533 * Adding new object at driver load time to the ioc->sas_device_init_list.
536 _scsih_sas_device_init_add(struct MPT2SAS_ADAPTER *ioc,
537 struct _sas_device *sas_device)
541 dewtprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: handle"
542 "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
543 sas_device->handle, (unsigned long long)sas_device->sas_address));
545 spin_lock_irqsave(&ioc->sas_device_lock, flags);
546 list_add_tail(&sas_device->list, &ioc->sas_device_init_list);
547 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
548 _scsih_determine_boot_device(ioc, sas_device, 0);
552 * mpt2sas_scsih_expander_find_by_handle - expander device search
553 * @ioc: per adapter object
554 * @handle: expander handle (assigned by firmware)
555 * Context: Calling function should acquire ioc->sas_device_lock
557 * This searches for expander device based on handle, then returns the
561 mpt2sas_scsih_expander_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
563 struct _sas_node *sas_expander, *r;
566 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
567 if (sas_expander->handle != handle)
577 * _scsih_raid_device_find_by_id - raid device search
578 * @ioc: per adapter object
579 * @id: sas device target id
580 * @channel: sas device channel
581 * Context: Calling function should acquire ioc->raid_device_lock
583 * This searches for raid_device based on target id, then return raid_device
586 static struct _raid_device *
587 _scsih_raid_device_find_by_id(struct MPT2SAS_ADAPTER *ioc, int id, int channel)
589 struct _raid_device *raid_device, *r;
592 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
593 if (raid_device->id == id && raid_device->channel == channel) {
604 * _scsih_raid_device_find_by_handle - raid device search
605 * @ioc: per adapter object
606 * @handle: sas device handle (assigned by firmware)
607 * Context: Calling function should acquire ioc->raid_device_lock
609 * This searches for raid_device based on handle, then return raid_device
612 static struct _raid_device *
613 _scsih_raid_device_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
615 struct _raid_device *raid_device, *r;
618 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
619 if (raid_device->handle != handle)
630 * _scsih_raid_device_find_by_wwid - raid device search
631 * @ioc: per adapter object
632 * @handle: sas device handle (assigned by firmware)
633 * Context: Calling function should acquire ioc->raid_device_lock
635 * This searches for raid_device based on wwid, then return raid_device
638 static struct _raid_device *
639 _scsih_raid_device_find_by_wwid(struct MPT2SAS_ADAPTER *ioc, u64 wwid)
641 struct _raid_device *raid_device, *r;
644 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
645 if (raid_device->wwid != wwid)
656 * _scsih_raid_device_add - add raid_device object
657 * @ioc: per adapter object
658 * @raid_device: raid_device object
660 * This is added to the raid_device_list link list.
663 _scsih_raid_device_add(struct MPT2SAS_ADAPTER *ioc,
664 struct _raid_device *raid_device)
668 dewtprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: handle"
669 "(0x%04x), wwid(0x%016llx)\n", ioc->name, __func__,
670 raid_device->handle, (unsigned long long)raid_device->wwid));
672 spin_lock_irqsave(&ioc->raid_device_lock, flags);
673 list_add_tail(&raid_device->list, &ioc->raid_device_list);
674 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
678 * _scsih_raid_device_remove - delete raid_device object
679 * @ioc: per adapter object
680 * @raid_device: raid_device object
682 * This is removed from the raid_device_list link list.
685 _scsih_raid_device_remove(struct MPT2SAS_ADAPTER *ioc,
686 struct _raid_device *raid_device)
690 spin_lock_irqsave(&ioc->raid_device_lock, flags);
691 list_del(&raid_device->list);
692 memset(raid_device, 0, sizeof(struct _raid_device));
694 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
698 * mpt2sas_scsih_expander_find_by_sas_address - expander device search
699 * @ioc: per adapter object
700 * @sas_address: sas address
701 * Context: Calling function should acquire ioc->sas_node_lock.
703 * This searches for expander device based on sas_address, then returns the
707 mpt2sas_scsih_expander_find_by_sas_address(struct MPT2SAS_ADAPTER *ioc,
710 struct _sas_node *sas_expander, *r;
713 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
714 if (sas_expander->sas_address != sas_address)
724 * _scsih_expander_node_add - insert expander device to the list.
725 * @ioc: per adapter object
726 * @sas_expander: the sas_device object
727 * Context: This function will acquire ioc->sas_node_lock.
729 * Adding new object to the ioc->sas_expander_list.
734 _scsih_expander_node_add(struct MPT2SAS_ADAPTER *ioc,
735 struct _sas_node *sas_expander)
739 spin_lock_irqsave(&ioc->sas_node_lock, flags);
740 list_add_tail(&sas_expander->list, &ioc->sas_expander_list);
741 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
745 * _scsih_is_end_device - determines if device is an end device
746 * @device_info: bitfield providing information about the device.
749 * Returns 1 if end device.
752 _scsih_is_end_device(u32 device_info)
754 if (device_info & MPI2_SAS_DEVICE_INFO_END_DEVICE &&
755 ((device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) |
756 (device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) |
757 (device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE)))
764 * _scsih_scsi_lookup_get - returns scmd entry
765 * @ioc: per adapter object
766 * @smid: system request message index
767 * Context: This function will acquire ioc->scsi_lookup_lock.
769 * Returns the smid stored scmd pointer.
771 static struct scsi_cmnd *
772 _scsih_scsi_lookup_get(struct MPT2SAS_ADAPTER *ioc, u16 smid)
775 struct scsi_cmnd *scmd;
777 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
778 scmd = ioc->scsi_lookup[smid - 1].scmd;
779 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
784 * mptscsih_getclear_scsi_lookup - returns scmd entry
785 * @ioc: per adapter object
786 * @smid: system request message index
787 * Context: This function will acquire ioc->scsi_lookup_lock.
789 * Returns the smid stored scmd pointer, as well as clearing the scmd pointer.
791 static struct scsi_cmnd *
792 _scsih_scsi_lookup_getclear(struct MPT2SAS_ADAPTER *ioc, u16 smid)
795 struct scsi_cmnd *scmd;
797 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
798 scmd = ioc->scsi_lookup[smid - 1].scmd;
799 ioc->scsi_lookup[smid - 1].scmd = NULL;
800 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
805 * _scsih_scsi_lookup_set - updates scmd entry in lookup
806 * @ioc: per adapter object
807 * @smid: system request message index
808 * @scmd: pointer to scsi command object
809 * Context: This function will acquire ioc->scsi_lookup_lock.
811 * This will save scmd pointer in the scsi_lookup array.
816 _scsih_scsi_lookup_set(struct MPT2SAS_ADAPTER *ioc, u16 smid,
817 struct scsi_cmnd *scmd)
821 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
822 ioc->scsi_lookup[smid - 1].scmd = scmd;
823 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
827 * _scsih_scsi_lookup_find_by_scmd - scmd lookup
828 * @ioc: per adapter object
829 * @smid: system request message index
830 * @scmd: pointer to scsi command object
831 * Context: This function will acquire ioc->scsi_lookup_lock.
833 * This will search for a scmd pointer in the scsi_lookup array,
834 * returning the revelent smid. A returned value of zero means invalid.
837 _scsih_scsi_lookup_find_by_scmd(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd
844 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
846 for (i = 0; i < ioc->request_depth; i++) {
847 if (ioc->scsi_lookup[i].scmd == scmd) {
853 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
858 * _scsih_scsi_lookup_find_by_target - search for matching channel:id
859 * @ioc: per adapter object
862 * Context: This function will acquire ioc->scsi_lookup_lock.
864 * This will search for a matching channel:id in the scsi_lookup array,
865 * returning 1 if found.
868 _scsih_scsi_lookup_find_by_target(struct MPT2SAS_ADAPTER *ioc, int id,
875 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
877 for (i = 0 ; i < ioc->request_depth; i++) {
878 if (ioc->scsi_lookup[i].scmd &&
879 (ioc->scsi_lookup[i].scmd->device->id == id &&
880 ioc->scsi_lookup[i].scmd->device->channel == channel)) {
886 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
891 * _scsih_get_chain_buffer_dma - obtain block of chains (dma address)
892 * @ioc: per adapter object
893 * @smid: system request message index
895 * Returns phys pointer to chain buffer.
898 _scsih_get_chain_buffer_dma(struct MPT2SAS_ADAPTER *ioc, u16 smid)
900 return ioc->chain_dma + ((smid - 1) * (ioc->request_sz *
901 ioc->chains_needed_per_io));
905 * _scsih_get_chain_buffer - obtain block of chains assigned to a mf request
906 * @ioc: per adapter object
907 * @smid: system request message index
909 * Returns virt pointer to chain buffer.
912 _scsih_get_chain_buffer(struct MPT2SAS_ADAPTER *ioc, u16 smid)
914 return (void *)(ioc->chain + ((smid - 1) * (ioc->request_sz *
915 ioc->chains_needed_per_io)));
919 * _scsih_build_scatter_gather - main sg creation routine
920 * @ioc: per adapter object
921 * @scmd: scsi command
922 * @smid: system request message index
925 * The main routine that builds scatter gather table from a given
926 * scsi request sent via the .queuecommand main handler.
928 * Returns 0 success, anything else error
931 _scsih_build_scatter_gather(struct MPT2SAS_ADAPTER *ioc,
932 struct scsi_cmnd *scmd, u16 smid)
934 Mpi2SCSIIORequest_t *mpi_request;
935 dma_addr_t chain_dma;
936 struct scatterlist *sg_scmd;
937 void *sg_local, *chain;
944 u32 sgl_flags_last_element;
945 u32 sgl_flags_end_buffer;
947 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
949 /* init scatter gather flags */
950 sgl_flags = MPI2_SGE_FLAGS_SIMPLE_ELEMENT;
951 if (scmd->sc_data_direction == DMA_TO_DEVICE)
952 sgl_flags |= MPI2_SGE_FLAGS_HOST_TO_IOC;
953 sgl_flags_last_element = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT)
954 << MPI2_SGE_FLAGS_SHIFT;
955 sgl_flags_end_buffer = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT |
956 MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_END_OF_LIST)
957 << MPI2_SGE_FLAGS_SHIFT;
958 sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT;
960 sg_scmd = scsi_sglist(scmd);
961 sges_left = scsi_dma_map(scmd);
963 sdev_printk(KERN_ERR, scmd->device, "pci_map_sg"
964 " failed: request for %d bytes!\n", scsi_bufflen(scmd));
968 sg_local = &mpi_request->SGL;
969 sges_in_segment = ioc->max_sges_in_main_message;
970 if (sges_left <= sges_in_segment)
971 goto fill_in_last_segment;
973 mpi_request->ChainOffset = (offsetof(Mpi2SCSIIORequest_t, SGL) +
974 (sges_in_segment * ioc->sge_size))/4;
976 /* fill in main message segment when there is a chain following */
977 while (sges_in_segment) {
978 if (sges_in_segment == 1)
979 ioc->base_add_sg_single(sg_local,
980 sgl_flags_last_element | sg_dma_len(sg_scmd),
981 sg_dma_address(sg_scmd));
983 ioc->base_add_sg_single(sg_local, sgl_flags |
984 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
985 sg_scmd = sg_next(sg_scmd);
986 sg_local += ioc->sge_size;
991 /* initializing the chain flags and pointers */
992 chain_flags = MPI2_SGE_FLAGS_CHAIN_ELEMENT << MPI2_SGE_FLAGS_SHIFT;
993 chain = _scsih_get_chain_buffer(ioc, smid);
994 chain_dma = _scsih_get_chain_buffer_dma(ioc, smid);
996 sges_in_segment = (sges_left <=
997 ioc->max_sges_in_chain_message) ? sges_left :
998 ioc->max_sges_in_chain_message;
999 chain_offset = (sges_left == sges_in_segment) ?
1000 0 : (sges_in_segment * ioc->sge_size)/4;
1001 chain_length = sges_in_segment * ioc->sge_size;
1003 chain_offset = chain_offset <<
1004 MPI2_SGE_CHAIN_OFFSET_SHIFT;
1005 chain_length += ioc->sge_size;
1007 ioc->base_add_sg_single(sg_local, chain_flags | chain_offset |
1008 chain_length, chain_dma);
1011 goto fill_in_last_segment;
1013 /* fill in chain segments */
1014 while (sges_in_segment) {
1015 if (sges_in_segment == 1)
1016 ioc->base_add_sg_single(sg_local,
1017 sgl_flags_last_element |
1018 sg_dma_len(sg_scmd),
1019 sg_dma_address(sg_scmd));
1021 ioc->base_add_sg_single(sg_local, sgl_flags |
1022 sg_dma_len(sg_scmd),
1023 sg_dma_address(sg_scmd));
1024 sg_scmd = sg_next(sg_scmd);
1025 sg_local += ioc->sge_size;
1030 chain_dma += ioc->request_sz;
1031 chain += ioc->request_sz;
1035 fill_in_last_segment:
1037 /* fill the last segment */
1040 ioc->base_add_sg_single(sg_local, sgl_flags_end_buffer |
1041 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
1043 ioc->base_add_sg_single(sg_local, sgl_flags |
1044 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
1045 sg_scmd = sg_next(sg_scmd);
1046 sg_local += ioc->sge_size;
1054 * scsih_change_queue_depth - setting device queue depth
1055 * @sdev: scsi device struct
1056 * @qdepth: requested queue depth
1058 * Returns queue depth.
1061 scsih_change_queue_depth(struct scsi_device *sdev, int qdepth)
1063 struct Scsi_Host *shost = sdev->host;
1067 max_depth = shost->can_queue;
1068 if (!sdev->tagged_supported)
1070 if (qdepth > max_depth)
1072 tag_type = (qdepth == 1) ? 0 : MSG_SIMPLE_TAG;
1073 scsi_adjust_queue_depth(sdev, tag_type, qdepth);
1075 if (sdev->inquiry_len > 7)
1076 sdev_printk(KERN_INFO, sdev, "qdepth(%d), tagged(%d), "
1077 "simple(%d), ordered(%d), scsi_level(%d), cmd_que(%d)\n",
1078 sdev->queue_depth, sdev->tagged_supported, sdev->simple_tags,
1079 sdev->ordered_tags, sdev->scsi_level,
1080 (sdev->inquiry[7] & 2) >> 1);
1082 return sdev->queue_depth;
1086 * scsih_change_queue_depth - changing device queue tag type
1087 * @sdev: scsi device struct
1088 * @tag_type: requested tag type
1090 * Returns queue tag type.
1093 scsih_change_queue_type(struct scsi_device *sdev, int tag_type)
1095 if (sdev->tagged_supported) {
1096 scsi_set_tag_type(sdev, tag_type);
1098 scsi_activate_tcq(sdev, sdev->queue_depth);
1100 scsi_deactivate_tcq(sdev, sdev->queue_depth);
1108 * scsih_target_alloc - target add routine
1109 * @starget: scsi target struct
1111 * Returns 0 if ok. Any other return is assumed to be an error and
1112 * the device is ignored.
1115 scsih_target_alloc(struct scsi_target *starget)
1117 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1118 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1119 struct MPT2SAS_TARGET *sas_target_priv_data;
1120 struct _sas_device *sas_device;
1121 struct _raid_device *raid_device;
1122 unsigned long flags;
1123 struct sas_rphy *rphy;
1125 sas_target_priv_data = kzalloc(sizeof(struct scsi_target), GFP_KERNEL);
1126 if (!sas_target_priv_data)
1129 starget->hostdata = sas_target_priv_data;
1130 sas_target_priv_data->starget = starget;
1131 sas_target_priv_data->handle = MPT2SAS_INVALID_DEVICE_HANDLE;
1134 if (starget->channel == RAID_CHANNEL) {
1135 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1136 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1139 sas_target_priv_data->handle = raid_device->handle;
1140 sas_target_priv_data->sas_address = raid_device->wwid;
1141 sas_target_priv_data->flags |= MPT_TARGET_FLAGS_VOLUME;
1142 raid_device->starget = starget;
1144 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1148 /* sas/sata devices */
1149 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1150 rphy = dev_to_rphy(starget->dev.parent);
1151 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1152 rphy->identify.sas_address);
1155 sas_target_priv_data->handle = sas_device->handle;
1156 sas_target_priv_data->sas_address = sas_device->sas_address;
1157 sas_device->starget = starget;
1158 sas_device->id = starget->id;
1159 sas_device->channel = starget->channel;
1160 if (sas_device->hidden_raid_component)
1161 sas_target_priv_data->flags |=
1162 MPT_TARGET_FLAGS_RAID_COMPONENT;
1164 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1170 * scsih_target_destroy - target destroy routine
1171 * @starget: scsi target struct
1176 scsih_target_destroy(struct scsi_target *starget)
1178 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1179 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1180 struct MPT2SAS_TARGET *sas_target_priv_data;
1181 struct _sas_device *sas_device;
1182 struct _raid_device *raid_device;
1183 unsigned long flags;
1184 struct sas_rphy *rphy;
1186 sas_target_priv_data = starget->hostdata;
1187 if (!sas_target_priv_data)
1190 if (starget->channel == RAID_CHANNEL) {
1191 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1192 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1195 raid_device->starget = NULL;
1196 raid_device->sdev = NULL;
1198 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1202 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1203 rphy = dev_to_rphy(starget->dev.parent);
1204 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1205 rphy->identify.sas_address);
1207 sas_device->starget = NULL;
1209 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1212 kfree(sas_target_priv_data);
1213 starget->hostdata = NULL;
1217 * scsih_slave_alloc - device add routine
1218 * @sdev: scsi device struct
1220 * Returns 0 if ok. Any other return is assumed to be an error and
1221 * the device is ignored.
1224 scsih_slave_alloc(struct scsi_device *sdev)
1226 struct Scsi_Host *shost;
1227 struct MPT2SAS_ADAPTER *ioc;
1228 struct MPT2SAS_TARGET *sas_target_priv_data;
1229 struct MPT2SAS_DEVICE *sas_device_priv_data;
1230 struct scsi_target *starget;
1231 struct _raid_device *raid_device;
1232 struct _sas_device *sas_device;
1233 unsigned long flags;
1235 sas_device_priv_data = kzalloc(sizeof(struct scsi_device), GFP_KERNEL);
1236 if (!sas_device_priv_data)
1239 sas_device_priv_data->lun = sdev->lun;
1240 sas_device_priv_data->flags = MPT_DEVICE_FLAGS_INIT;
1242 starget = scsi_target(sdev);
1243 sas_target_priv_data = starget->hostdata;
1244 sas_target_priv_data->num_luns++;
1245 sas_device_priv_data->sas_target = sas_target_priv_data;
1246 sdev->hostdata = sas_device_priv_data;
1247 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT))
1248 sdev->no_uld_attach = 1;
1250 shost = dev_to_shost(&starget->dev);
1251 ioc = shost_priv(shost);
1252 if (starget->channel == RAID_CHANNEL) {
1253 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1254 raid_device = _scsih_raid_device_find_by_id(ioc,
1255 starget->id, starget->channel);
1257 raid_device->sdev = sdev; /* raid is single lun */
1258 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1260 /* set TLR bit for SSP devices */
1261 if (!(ioc->facts.IOCCapabilities &
1262 MPI2_IOCFACTS_CAPABILITY_TLR))
1264 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1265 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1266 sas_device_priv_data->sas_target->sas_address);
1267 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1268 if (sas_device && sas_device->device_info &
1269 MPI2_SAS_DEVICE_INFO_SSP_TARGET)
1270 sas_device_priv_data->flags |= MPT_DEVICE_TLR_ON;
1278 * scsih_slave_destroy - device destroy routine
1279 * @sdev: scsi device struct
1284 scsih_slave_destroy(struct scsi_device *sdev)
1286 struct MPT2SAS_TARGET *sas_target_priv_data;
1287 struct scsi_target *starget;
1289 if (!sdev->hostdata)
1292 starget = scsi_target(sdev);
1293 sas_target_priv_data = starget->hostdata;
1294 sas_target_priv_data->num_luns--;
1295 kfree(sdev->hostdata);
1296 sdev->hostdata = NULL;
1300 * scsih_display_sata_capabilities - sata capabilities
1301 * @ioc: per adapter object
1302 * @sas_device: the sas_device object
1303 * @sdev: scsi device struct
1306 scsih_display_sata_capabilities(struct MPT2SAS_ADAPTER *ioc,
1307 struct _sas_device *sas_device, struct scsi_device *sdev)
1309 Mpi2ConfigReply_t mpi_reply;
1310 Mpi2SasDevicePage0_t sas_device_pg0;
1315 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
1316 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, sas_device->handle))) {
1317 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1318 ioc->name, __FILE__, __LINE__, __func__);
1322 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1323 MPI2_IOCSTATUS_MASK;
1324 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
1325 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1326 ioc->name, __FILE__, __LINE__, __func__);
1330 flags = le16_to_cpu(sas_device_pg0.Flags);
1331 device_info = le16_to_cpu(sas_device_pg0.DeviceInfo);
1333 sdev_printk(KERN_INFO, sdev,
1334 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1335 "sw_preserve(%s)\n",
1336 (device_info & MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE) ? "y" : "n",
1337 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED) ? "y" : "n",
1338 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY) ? "y" :
1340 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED) ? "y" : "n",
1341 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED) ? "y" : "n",
1342 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE) ? "y" : "n");
1346 * _scsih_get_volume_capabilities - volume capabilities
1347 * @ioc: per adapter object
1348 * @sas_device: the raid_device object
1351 _scsih_get_volume_capabilities(struct MPT2SAS_ADAPTER *ioc,
1352 struct _raid_device *raid_device)
1354 Mpi2RaidVolPage0_t *vol_pg0;
1355 Mpi2RaidPhysDiskPage0_t pd_pg0;
1356 Mpi2SasDevicePage0_t sas_device_pg0;
1357 Mpi2ConfigReply_t mpi_reply;
1361 if ((mpt2sas_config_get_number_pds(ioc, raid_device->handle,
1362 &num_pds)) || !num_pds) {
1363 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1364 ioc->name, __FILE__, __LINE__, __func__);
1368 raid_device->num_pds = num_pds;
1369 sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
1370 sizeof(Mpi2RaidVol0PhysDisk_t));
1371 vol_pg0 = kzalloc(sz, GFP_KERNEL);
1373 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1374 ioc->name, __FILE__, __LINE__, __func__);
1378 if ((mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
1379 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
1380 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1381 ioc->name, __FILE__, __LINE__, __func__);
1386 raid_device->volume_type = vol_pg0->VolumeType;
1388 /* figure out what the underlying devices are by
1389 * obtaining the device_info bits for the 1st device
1391 if (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
1392 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
1393 vol_pg0->PhysDisk[0].PhysDiskNum))) {
1394 if (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
1395 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
1396 le16_to_cpu(pd_pg0.DevHandle)))) {
1397 raid_device->device_info =
1398 le32_to_cpu(sas_device_pg0.DeviceInfo);
1406 * scsih_slave_configure - device configure routine.
1407 * @sdev: scsi device struct
1409 * Returns 0 if ok. Any other return is assumed to be an error and
1410 * the device is ignored.
1413 scsih_slave_configure(struct scsi_device *sdev)
1415 struct Scsi_Host *shost = sdev->host;
1416 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1417 struct MPT2SAS_DEVICE *sas_device_priv_data;
1418 struct MPT2SAS_TARGET *sas_target_priv_data;
1419 struct _sas_device *sas_device;
1420 struct _raid_device *raid_device;
1421 unsigned long flags;
1428 sas_device_priv_data = sdev->hostdata;
1429 sas_device_priv_data->configured_lun = 1;
1430 sas_device_priv_data->flags &= ~MPT_DEVICE_FLAGS_INIT;
1431 sas_target_priv_data = sas_device_priv_data->sas_target;
1433 /* raid volume handling */
1434 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME) {
1436 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1437 raid_device = _scsih_raid_device_find_by_handle(ioc,
1438 sas_target_priv_data->handle);
1439 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1441 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1442 ioc->name, __FILE__, __LINE__, __func__);
1446 _scsih_get_volume_capabilities(ioc, raid_device);
1448 /* RAID Queue Depth Support
1449 * IS volume = underlying qdepth of drive type, either
1450 * MPT2SAS_SAS_QUEUE_DEPTH or MPT2SAS_SATA_QUEUE_DEPTH
1451 * IM/IME/R10 = 128 (MPT2SAS_RAID_QUEUE_DEPTH)
1453 if (raid_device->device_info &
1454 MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
1455 qdepth = MPT2SAS_SAS_QUEUE_DEPTH;
1458 qdepth = MPT2SAS_SATA_QUEUE_DEPTH;
1459 if (raid_device->device_info &
1460 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1466 switch (raid_device->volume_type) {
1467 case MPI2_RAID_VOL_TYPE_RAID0:
1470 case MPI2_RAID_VOL_TYPE_RAID1E:
1471 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
1474 case MPI2_RAID_VOL_TYPE_RAID1:
1475 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
1478 case MPI2_RAID_VOL_TYPE_RAID10:
1479 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
1482 case MPI2_RAID_VOL_TYPE_UNKNOWN:
1484 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
1489 sdev_printk(KERN_INFO, sdev, "%s: "
1490 "handle(0x%04x), wwid(0x%016llx), pd_count(%d), type(%s)\n",
1491 r_level, raid_device->handle,
1492 (unsigned long long)raid_device->wwid,
1493 raid_device->num_pds, ds);
1494 scsih_change_queue_depth(sdev, qdepth);
1498 /* non-raid handling */
1499 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1500 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1501 sas_device_priv_data->sas_target->sas_address);
1502 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1504 if (sas_target_priv_data->flags &
1505 MPT_TARGET_FLAGS_RAID_COMPONENT) {
1506 mpt2sas_config_get_volume_handle(ioc,
1507 sas_device->handle, &sas_device->volume_handle);
1508 mpt2sas_config_get_volume_wwid(ioc,
1509 sas_device->volume_handle,
1510 &sas_device->volume_wwid);
1512 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
1513 qdepth = MPT2SAS_SAS_QUEUE_DEPTH;
1517 qdepth = MPT2SAS_SATA_QUEUE_DEPTH;
1518 if (sas_device->device_info &
1519 MPI2_SAS_DEVICE_INFO_STP_TARGET)
1521 else if (sas_device->device_info &
1522 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1526 sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), "
1527 "sas_addr(0x%016llx), device_name(0x%016llx)\n",
1528 ds, sas_device->handle,
1529 (unsigned long long)sas_device->sas_address,
1530 (unsigned long long)sas_device->device_name);
1531 sdev_printk(KERN_INFO, sdev, "%s: "
1532 "enclosure_logical_id(0x%016llx), slot(%d)\n", ds,
1533 (unsigned long long) sas_device->enclosure_logical_id,
1537 scsih_display_sata_capabilities(ioc, sas_device, sdev);
1540 scsih_change_queue_depth(sdev, qdepth);
1543 sas_read_port_mode_page(sdev);
1548 * scsih_bios_param - fetch head, sector, cylinder info for a disk
1549 * @sdev: scsi device struct
1550 * @bdev: pointer to block device context
1551 * @capacity: device size (in 512 byte sectors)
1552 * @params: three element array to place output:
1553 * params[0] number of heads (max 255)
1554 * params[1] number of sectors (max 63)
1555 * params[2] number of cylinders
1560 scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev,
1561 sector_t capacity, int params[])
1571 dummy = heads * sectors;
1572 cylinders = capacity;
1573 sector_div(cylinders, dummy);
1576 * Handle extended translation size for logical drives
1579 if ((ulong)capacity >= 0x200000) {
1582 dummy = heads * sectors;
1583 cylinders = capacity;
1584 sector_div(cylinders, dummy);
1589 params[1] = sectors;
1590 params[2] = cylinders;
1596 * _scsih_response_code - translation of device response code
1597 * @ioc: per adapter object
1598 * @response_code: response code returned by the device
1603 _scsih_response_code(struct MPT2SAS_ADAPTER *ioc, u8 response_code)
1607 switch (response_code) {
1608 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE:
1609 desc = "task management request completed";
1611 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME:
1612 desc = "invalid frame";
1614 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED:
1615 desc = "task management request not supported";
1617 case MPI2_SCSITASKMGMT_RSP_TM_FAILED:
1618 desc = "task management request failed";
1620 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED:
1621 desc = "task management request succeeded";
1623 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN:
1624 desc = "invalid lun";
1627 desc = "overlapped tag attempted";
1629 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC:
1630 desc = "task queued, however not sent to target";
1636 printk(MPT2SAS_WARN_FMT "response_code(0x%01x): %s\n",
1637 ioc->name, response_code, desc);
1641 * scsih_tm_done - tm completion routine
1642 * @ioc: per adapter object
1643 * @smid: system request message index
1644 * @VF_ID: virtual function id
1645 * @reply: reply message frame(lower 32bit addr)
1648 * The callback handler when using scsih_issue_tm.
1653 scsih_tm_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 VF_ID, u32 reply)
1655 MPI2DefaultReply_t *mpi_reply;
1657 if (ioc->tm_cmds.status == MPT2_CMD_NOT_USED)
1659 if (ioc->tm_cmds.smid != smid)
1661 ioc->tm_cmds.status |= MPT2_CMD_COMPLETE;
1662 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
1664 memcpy(ioc->tm_cmds.reply, mpi_reply, mpi_reply->MsgLength*4);
1665 ioc->tm_cmds.status |= MPT2_CMD_REPLY_VALID;
1667 ioc->tm_cmds.status &= ~MPT2_CMD_PENDING;
1668 complete(&ioc->tm_cmds.done);
1672 * mpt2sas_scsih_set_tm_flag - set per target tm_busy
1673 * @ioc: per adapter object
1674 * @handle: device handle
1676 * During taskmangement request, we need to freeze the device queue.
1679 mpt2sas_scsih_set_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
1681 struct MPT2SAS_DEVICE *sas_device_priv_data;
1682 struct scsi_device *sdev;
1685 shost_for_each_device(sdev, ioc->shost) {
1688 sas_device_priv_data = sdev->hostdata;
1689 if (!sas_device_priv_data)
1691 if (sas_device_priv_data->sas_target->handle == handle) {
1692 sas_device_priv_data->sas_target->tm_busy = 1;
1694 ioc->ignore_loginfos = 1;
1700 * mpt2sas_scsih_clear_tm_flag - clear per target tm_busy
1701 * @ioc: per adapter object
1702 * @handle: device handle
1704 * During taskmangement request, we need to freeze the device queue.
1707 mpt2sas_scsih_clear_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
1709 struct MPT2SAS_DEVICE *sas_device_priv_data;
1710 struct scsi_device *sdev;
1713 shost_for_each_device(sdev, ioc->shost) {
1716 sas_device_priv_data = sdev->hostdata;
1717 if (!sas_device_priv_data)
1719 if (sas_device_priv_data->sas_target->handle == handle) {
1720 sas_device_priv_data->sas_target->tm_busy = 0;
1722 ioc->ignore_loginfos = 0;
1728 * mpt2sas_scsih_issue_tm - main routine for sending tm requests
1729 * @ioc: per adapter struct
1730 * @device_handle: device handle
1732 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
1733 * @smid_task: smid assigned to the task
1734 * @timeout: timeout in seconds
1735 * Context: The calling function needs to acquire the tm_cmds.mutex
1737 * A generic API for sending task management requests to firmware.
1739 * The ioc->tm_cmds.status flag should be MPT2_CMD_NOT_USED before calling
1742 * The callback index is set inside `ioc->tm_cb_idx`.
1747 mpt2sas_scsih_issue_tm(struct MPT2SAS_ADAPTER *ioc, u16 handle, uint lun,
1748 u8 type, u16 smid_task, ulong timeout)
1750 Mpi2SCSITaskManagementRequest_t *mpi_request;
1751 Mpi2SCSITaskManagementReply_t *mpi_reply;
1754 unsigned long timeleft;
1756 unsigned long flags;
1758 spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags);
1759 if (ioc->tm_cmds.status != MPT2_CMD_NOT_USED ||
1760 ioc->shost_recovery) {
1761 spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags);
1762 printk(MPT2SAS_INFO_FMT "%s: host reset in progress!\n",
1763 __func__, ioc->name);
1766 spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags);
1768 ioc_state = mpt2sas_base_get_iocstate(ioc, 0);
1769 if (ioc_state & MPI2_DOORBELL_USED) {
1770 dhsprintk(ioc, printk(MPT2SAS_DEBUG_FMT "unexpected doorbell "
1771 "active!\n", ioc->name));
1772 goto issue_host_reset;
1775 if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) {
1776 mpt2sas_base_fault_info(ioc, ioc_state &
1777 MPI2_DOORBELL_DATA_MASK);
1778 goto issue_host_reset;
1781 smid = mpt2sas_base_get_smid(ioc, ioc->tm_cb_idx);
1783 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
1784 ioc->name, __func__);
1788 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "sending tm: handle(0x%04x),"
1789 " task_type(0x%02x), smid(%d)\n", ioc->name, handle, type, smid));
1790 ioc->tm_cmds.status = MPT2_CMD_PENDING;
1791 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
1792 ioc->tm_cmds.smid = smid;
1793 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
1794 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
1795 mpi_request->DevHandle = cpu_to_le16(handle);
1796 mpi_request->TaskType = type;
1797 mpi_request->TaskMID = cpu_to_le16(smid_task);
1798 int_to_scsilun(lun, (struct scsi_lun *)mpi_request->LUN);
1799 mpt2sas_scsih_set_tm_flag(ioc, handle);
1800 mpt2sas_base_put_smid_hi_priority(ioc, smid, VF_ID);
1801 timeleft = wait_for_completion_timeout(&ioc->tm_cmds.done, timeout*HZ);
1802 mpt2sas_scsih_clear_tm_flag(ioc, handle);
1803 if (!(ioc->tm_cmds.status & MPT2_CMD_COMPLETE)) {
1804 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
1805 ioc->name, __func__);
1806 _debug_dump_mf(mpi_request,
1807 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
1808 if (!(ioc->tm_cmds.status & MPT2_CMD_RESET))
1809 goto issue_host_reset;
1812 if (ioc->tm_cmds.status & MPT2_CMD_REPLY_VALID) {
1813 mpi_reply = ioc->tm_cmds.reply;
1814 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "complete tm: "
1815 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
1816 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
1817 le32_to_cpu(mpi_reply->IOCLogInfo),
1818 le32_to_cpu(mpi_reply->TerminationCount)));
1819 if (ioc->logging_level & MPT_DEBUG_TM)
1820 _scsih_response_code(ioc, mpi_reply->ResponseCode);
1824 mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, FORCE_BIG_HAMMER);
1828 * scsih_abort - eh threads main abort routine
1829 * @sdev: scsi device struct
1831 * Returns SUCCESS if command aborted else FAILED
1834 scsih_abort(struct scsi_cmnd *scmd)
1836 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
1837 struct MPT2SAS_DEVICE *sas_device_priv_data;
1841 struct scsi_cmnd *scmd_lookup;
1843 printk(MPT2SAS_INFO_FMT "attempting task abort! scmd(%p)\n",
1845 scsi_print_command(scmd);
1847 sas_device_priv_data = scmd->device->hostdata;
1848 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
1849 printk(MPT2SAS_INFO_FMT "device been deleted! scmd(%p)\n",
1851 scmd->result = DID_NO_CONNECT << 16;
1852 scmd->scsi_done(scmd);
1857 /* search for the command */
1858 smid = _scsih_scsi_lookup_find_by_scmd(ioc, scmd);
1860 scmd->result = DID_RESET << 16;
1865 /* for hidden raid components and volumes this is not supported */
1866 if (sas_device_priv_data->sas_target->flags &
1867 MPT_TARGET_FLAGS_RAID_COMPONENT ||
1868 sas_device_priv_data->sas_target->flags & MPT_TARGET_FLAGS_VOLUME) {
1869 scmd->result = DID_RESET << 16;
1874 mutex_lock(&ioc->tm_cmds.mutex);
1875 handle = sas_device_priv_data->sas_target->handle;
1876 mpt2sas_scsih_issue_tm(ioc, handle, sas_device_priv_data->lun,
1877 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30);
1879 /* sanity check - see whether command actually completed */
1880 scmd_lookup = _scsih_scsi_lookup_get(ioc, smid);
1881 if (scmd_lookup && (scmd_lookup->serial_number == scmd->serial_number))
1885 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
1886 mutex_unlock(&ioc->tm_cmds.mutex);
1889 printk(MPT2SAS_INFO_FMT "task abort: %s scmd(%p)\n",
1890 ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
1896 * scsih_dev_reset - eh threads main device reset routine
1897 * @sdev: scsi device struct
1899 * Returns SUCCESS if command aborted else FAILED
1902 scsih_dev_reset(struct scsi_cmnd *scmd)
1904 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
1905 struct MPT2SAS_DEVICE *sas_device_priv_data;
1906 struct _sas_device *sas_device;
1907 unsigned long flags;
1911 printk(MPT2SAS_INFO_FMT "attempting target reset! scmd(%p)\n",
1913 scsi_print_command(scmd);
1915 sas_device_priv_data = scmd->device->hostdata;
1916 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
1917 printk(MPT2SAS_INFO_FMT "device been deleted! scmd(%p)\n",
1919 scmd->result = DID_NO_CONNECT << 16;
1920 scmd->scsi_done(scmd);
1925 /* for hidden raid components obtain the volume_handle */
1927 if (sas_device_priv_data->sas_target->flags &
1928 MPT_TARGET_FLAGS_RAID_COMPONENT) {
1929 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1930 sas_device = _scsih_sas_device_find_by_handle(ioc,
1931 sas_device_priv_data->sas_target->handle);
1933 handle = sas_device->volume_handle;
1934 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1936 handle = sas_device_priv_data->sas_target->handle;
1939 scmd->result = DID_RESET << 16;
1944 mutex_lock(&ioc->tm_cmds.mutex);
1945 mpt2sas_scsih_issue_tm(ioc, handle, 0,
1946 MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0, 30);
1949 * sanity check see whether all commands to this target been
1952 if (_scsih_scsi_lookup_find_by_target(ioc, scmd->device->id,
1953 scmd->device->channel))
1957 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
1958 mutex_unlock(&ioc->tm_cmds.mutex);
1961 printk(MPT2SAS_INFO_FMT "target reset: %s scmd(%p)\n",
1962 ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
1967 * scsih_abort - eh threads main host reset routine
1968 * @sdev: scsi device struct
1970 * Returns SUCCESS if command aborted else FAILED
1973 scsih_host_reset(struct scsi_cmnd *scmd)
1975 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
1978 printk(MPT2SAS_INFO_FMT "attempting host reset! scmd(%p)\n",
1980 scsi_print_command(scmd);
1982 retval = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
1984 r = (retval < 0) ? FAILED : SUCCESS;
1985 printk(MPT2SAS_INFO_FMT "host reset: %s scmd(%p)\n",
1986 ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
1992 * _scsih_fw_event_add - insert and queue up fw_event
1993 * @ioc: per adapter object
1994 * @fw_event: object describing the event
1995 * Context: This function will acquire ioc->fw_event_lock.
1997 * This adds the firmware event object into link list, then queues it up to
1998 * be processed from user context.
2003 _scsih_fw_event_add(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
2005 unsigned long flags;
2007 if (ioc->firmware_event_thread == NULL)
2010 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2011 list_add_tail(&fw_event->list, &ioc->fw_event_list);
2012 INIT_DELAYED_WORK(&fw_event->work, _firmware_event_work);
2013 queue_delayed_work(ioc->firmware_event_thread, &fw_event->work, 1);
2014 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2018 * _scsih_fw_event_free - delete fw_event
2019 * @ioc: per adapter object
2020 * @fw_event: object describing the event
2021 * Context: This function will acquire ioc->fw_event_lock.
2023 * This removes firmware event object from link list, frees associated memory.
2028 _scsih_fw_event_free(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work
2031 unsigned long flags;
2033 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2034 list_del(&fw_event->list);
2035 kfree(fw_event->event_data);
2037 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2041 * _scsih_fw_event_add - requeue an event
2042 * @ioc: per adapter object
2043 * @fw_event: object describing the event
2044 * Context: This function will acquire ioc->fw_event_lock.
2049 _scsih_fw_event_requeue(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work
2050 *fw_event, unsigned long delay)
2052 unsigned long flags;
2053 if (ioc->firmware_event_thread == NULL)
2056 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2057 queue_delayed_work(ioc->firmware_event_thread, &fw_event->work, delay);
2058 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2062 * _scsih_fw_event_off - turn flag off preventing event handling
2063 * @ioc: per adapter object
2065 * Used to prevent handling of firmware events during adapter reset
2071 _scsih_fw_event_off(struct MPT2SAS_ADAPTER *ioc)
2073 unsigned long flags;
2075 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2076 ioc->fw_events_off = 1;
2077 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2082 * _scsih_fw_event_on - turn flag on allowing firmware event handling
2083 * @ioc: per adapter object
2088 _scsih_fw_event_on(struct MPT2SAS_ADAPTER *ioc)
2090 unsigned long flags;
2092 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2093 ioc->fw_events_off = 0;
2094 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2098 * _scsih_ublock_io_device - set the device state to SDEV_RUNNING
2099 * @ioc: per adapter object
2100 * @handle: device handle
2102 * During device pull we need to appropiately set the sdev state.
2105 _scsih_ublock_io_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2107 struct MPT2SAS_DEVICE *sas_device_priv_data;
2108 struct scsi_device *sdev;
2110 shost_for_each_device(sdev, ioc->shost) {
2111 sas_device_priv_data = sdev->hostdata;
2112 if (!sas_device_priv_data)
2114 if (!sas_device_priv_data->block)
2116 if (sas_device_priv_data->sas_target->handle == handle) {
2117 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
2118 MPT2SAS_INFO_FMT "SDEV_RUNNING: "
2119 "handle(0x%04x)\n", ioc->name, handle));
2120 sas_device_priv_data->block = 0;
2121 scsi_device_set_state(sdev, SDEV_RUNNING);
2127 * _scsih_block_io_device - set the device state to SDEV_BLOCK
2128 * @ioc: per adapter object
2129 * @handle: device handle
2131 * During device pull we need to appropiately set the sdev state.
2134 _scsih_block_io_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2136 struct MPT2SAS_DEVICE *sas_device_priv_data;
2137 struct scsi_device *sdev;
2139 shost_for_each_device(sdev, ioc->shost) {
2140 sas_device_priv_data = sdev->hostdata;
2141 if (!sas_device_priv_data)
2143 if (sas_device_priv_data->block)
2145 if (sas_device_priv_data->sas_target->handle == handle) {
2146 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
2147 MPT2SAS_INFO_FMT "SDEV_BLOCK: "
2148 "handle(0x%04x)\n", ioc->name, handle));
2149 sas_device_priv_data->block = 1;
2150 scsi_device_set_state(sdev, SDEV_BLOCK);
2156 * _scsih_block_io_to_children_attached_to_ex
2157 * @ioc: per adapter object
2158 * @sas_expander: the sas_device object
2160 * This routine set sdev state to SDEV_BLOCK for all devices
2161 * attached to this expander. This function called when expander is
2165 _scsih_block_io_to_children_attached_to_ex(struct MPT2SAS_ADAPTER *ioc,
2166 struct _sas_node *sas_expander)
2168 struct _sas_port *mpt2sas_port;
2169 struct _sas_device *sas_device;
2170 struct _sas_node *expander_sibling;
2171 unsigned long flags;
2176 list_for_each_entry(mpt2sas_port,
2177 &sas_expander->sas_port_list, port_list) {
2178 if (mpt2sas_port->remote_identify.device_type ==
2180 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2182 mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
2183 mpt2sas_port->remote_identify.sas_address);
2184 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2187 _scsih_block_io_device(ioc, sas_device->handle);
2191 list_for_each_entry(mpt2sas_port,
2192 &sas_expander->sas_port_list, port_list) {
2194 if (mpt2sas_port->remote_identify.device_type ==
2195 MPI2_SAS_DEVICE_INFO_EDGE_EXPANDER ||
2196 mpt2sas_port->remote_identify.device_type ==
2197 MPI2_SAS_DEVICE_INFO_FANOUT_EXPANDER) {
2199 spin_lock_irqsave(&ioc->sas_node_lock, flags);
2201 mpt2sas_scsih_expander_find_by_sas_address(
2202 ioc, mpt2sas_port->remote_identify.sas_address);
2203 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
2204 _scsih_block_io_to_children_attached_to_ex(ioc,
2211 * _scsih_block_io_to_children_attached_directly
2212 * @ioc: per adapter object
2213 * @event_data: topology change event data
2215 * This routine set sdev state to SDEV_BLOCK for all devices
2216 * direct attached during device pull.
2219 _scsih_block_io_to_children_attached_directly(struct MPT2SAS_ADAPTER *ioc,
2220 Mpi2EventDataSasTopologyChangeList_t *event_data)
2227 for (i = 0; i < event_data->NumEntries; i++) {
2228 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
2231 phy_number = event_data->StartPhyNum + i;
2232 reason_code = event_data->PHY[i].PhyStatus &
2233 MPI2_EVENT_SAS_TOPO_RC_MASK;
2234 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING)
2235 _scsih_block_io_device(ioc, handle);
2240 * _scsih_check_topo_delete_events - sanity check on topo events
2241 * @ioc: per adapter object
2242 * @event_data: the event data payload
2244 * This routine added to better handle cable breaker.
2246 * This handles the case where driver recieves multiple expander
2247 * add and delete events in a single shot. When there is a delete event
2248 * the routine will void any pending add events waiting in the event queue.
2253 _scsih_check_topo_delete_events(struct MPT2SAS_ADAPTER *ioc,
2254 Mpi2EventDataSasTopologyChangeList_t *event_data)
2256 struct fw_event_work *fw_event;
2257 Mpi2EventDataSasTopologyChangeList_t *local_event_data;
2258 u16 expander_handle;
2259 struct _sas_node *sas_expander;
2260 unsigned long flags;
2262 expander_handle = le16_to_cpu(event_data->ExpanderDevHandle);
2263 if (expander_handle < ioc->sas_hba.num_phys) {
2264 _scsih_block_io_to_children_attached_directly(ioc, event_data);
2268 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
2269 || event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING) {
2270 spin_lock_irqsave(&ioc->sas_node_lock, flags);
2271 sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc,
2273 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
2274 _scsih_block_io_to_children_attached_to_ex(ioc, sas_expander);
2275 } else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING)
2276 _scsih_block_io_to_children_attached_directly(ioc, event_data);
2278 if (event_data->ExpStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING)
2281 /* mark ignore flag for pending events */
2282 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2283 list_for_each_entry(fw_event, &ioc->fw_event_list, list) {
2284 if (fw_event->event != MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST ||
2287 local_event_data = fw_event->event_data;
2288 if (local_event_data->ExpStatus ==
2289 MPI2_EVENT_SAS_TOPO_ES_ADDED ||
2290 local_event_data->ExpStatus ==
2291 MPI2_EVENT_SAS_TOPO_ES_RESPONDING) {
2292 if (le16_to_cpu(local_event_data->ExpanderDevHandle) ==
2294 dewtprintk(ioc, printk(MPT2SAS_DEBUG_FMT
2295 "setting ignoring flag\n", ioc->name));
2296 fw_event->ignore = 1;
2300 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2304 * _scsih_queue_rescan - queue a topology rescan from user context
2305 * @ioc: per adapter object
2310 _scsih_queue_rescan(struct MPT2SAS_ADAPTER *ioc)
2312 struct fw_event_work *fw_event;
2314 if (ioc->wait_for_port_enable_to_complete)
2316 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
2319 fw_event->event = MPT2SAS_RESCAN_AFTER_HOST_RESET;
2320 fw_event->ioc = ioc;
2321 _scsih_fw_event_add(ioc, fw_event);
2325 * _scsih_flush_running_cmds - completing outstanding commands.
2326 * @ioc: per adapter object
2328 * The flushing out of all pending scmd commands following host reset,
2329 * where all IO is dropped to the floor.
2334 _scsih_flush_running_cmds(struct MPT2SAS_ADAPTER *ioc)
2336 struct scsi_cmnd *scmd;
2340 for (smid = 1; smid <= ioc->request_depth; smid++) {
2341 scmd = _scsih_scsi_lookup_getclear(ioc, smid);
2345 mpt2sas_base_free_smid(ioc, smid);
2346 scsi_dma_unmap(scmd);
2347 scmd->result = DID_RESET << 16;
2348 scmd->scsi_done(scmd);
2350 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "completing %d cmds\n",
2355 * mpt2sas_scsih_reset_handler - reset callback handler (for scsih)
2356 * @ioc: per adapter object
2357 * @reset_phase: phase
2359 * The handler for doing any required cleanup or initialization.
2361 * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
2362 * MPT2_IOC_DONE_RESET
2367 mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase)
2369 switch (reset_phase) {
2370 case MPT2_IOC_PRE_RESET:
2371 dtmprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: "
2372 "MPT2_IOC_PRE_RESET\n", ioc->name, __func__));
2373 _scsih_fw_event_off(ioc);
2375 case MPT2_IOC_AFTER_RESET:
2376 dtmprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: "
2377 "MPT2_IOC_AFTER_RESET\n", ioc->name, __func__));
2378 if (ioc->tm_cmds.status & MPT2_CMD_PENDING) {
2379 ioc->tm_cmds.status |= MPT2_CMD_RESET;
2380 mpt2sas_base_free_smid(ioc, ioc->tm_cmds.smid);
2381 complete(&ioc->tm_cmds.done);
2383 _scsih_fw_event_on(ioc);
2384 _scsih_flush_running_cmds(ioc);
2386 case MPT2_IOC_DONE_RESET:
2387 dtmprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: "
2388 "MPT2_IOC_DONE_RESET\n", ioc->name, __func__));
2389 _scsih_queue_rescan(ioc);
2395 * scsih_qcmd - main scsi request entry point
2396 * @scmd: pointer to scsi command object
2397 * @done: function pointer to be invoked on completion
2399 * The callback index is set inside `ioc->scsi_io_cb_idx`.
2401 * Returns 0 on success. If there's a failure, return either:
2402 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
2403 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
2406 scsih_qcmd(struct scsi_cmnd *scmd, void (*done)(struct scsi_cmnd *))
2408 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2409 struct MPT2SAS_DEVICE *sas_device_priv_data;
2410 struct MPT2SAS_TARGET *sas_target_priv_data;
2411 Mpi2SCSIIORequest_t *mpi_request;
2414 unsigned long flags;
2416 scmd->scsi_done = done;
2417 sas_device_priv_data = scmd->device->hostdata;
2418 if (!sas_device_priv_data) {
2419 scmd->result = DID_NO_CONNECT << 16;
2420 scmd->scsi_done(scmd);
2424 sas_target_priv_data = sas_device_priv_data->sas_target;
2425 if (!sas_target_priv_data || sas_target_priv_data->handle ==
2426 MPT2SAS_INVALID_DEVICE_HANDLE || sas_target_priv_data->deleted) {
2427 scmd->result = DID_NO_CONNECT << 16;
2428 scmd->scsi_done(scmd);
2432 /* see if we are busy with task managment stuff */
2433 spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags);
2434 if (sas_target_priv_data->tm_busy ||
2435 ioc->shost_recovery || ioc->ioc_link_reset_in_progress) {
2436 spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags);
2437 return SCSI_MLQUEUE_HOST_BUSY;
2439 spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags);
2441 if (scmd->sc_data_direction == DMA_FROM_DEVICE)
2442 mpi_control = MPI2_SCSIIO_CONTROL_READ;
2443 else if (scmd->sc_data_direction == DMA_TO_DEVICE)
2444 mpi_control = MPI2_SCSIIO_CONTROL_WRITE;
2446 mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER;
2449 if (!(sas_device_priv_data->flags & MPT_DEVICE_FLAGS_INIT)) {
2450 if (scmd->device->tagged_supported) {
2451 if (scmd->device->ordered_tags)
2452 mpi_control |= MPI2_SCSIIO_CONTROL_ORDEREDQ;
2454 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
2456 /* MPI Revision I (UNIT = 0xA) - removed MPI2_SCSIIO_CONTROL_UNTAGGED */
2457 /* mpi_control |= MPI2_SCSIIO_CONTROL_UNTAGGED;
2459 mpi_control |= (0x500);
2462 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
2464 if ((sas_device_priv_data->flags & MPT_DEVICE_TLR_ON))
2465 mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON;
2467 smid = mpt2sas_base_get_smid(ioc, ioc->scsi_io_cb_idx);
2469 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
2470 ioc->name, __func__);
2473 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
2474 memset(mpi_request, 0, sizeof(Mpi2SCSIIORequest_t));
2475 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
2476 if (sas_device_priv_data->sas_target->flags &
2477 MPT_TARGET_FLAGS_RAID_COMPONENT)
2478 mpi_request->Function = MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;
2480 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
2481 mpi_request->DevHandle =
2482 cpu_to_le16(sas_device_priv_data->sas_target->handle);
2483 mpi_request->DataLength = cpu_to_le32(scsi_bufflen(scmd));
2484 mpi_request->Control = cpu_to_le32(mpi_control);
2485 mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len);
2486 mpi_request->MsgFlags = MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR;
2487 mpi_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE;
2488 mpi_request->SenseBufferLowAddress =
2489 (u32)mpt2sas_base_get_sense_buffer_dma(ioc, smid);
2490 mpi_request->SGLOffset0 = offsetof(Mpi2SCSIIORequest_t, SGL) / 4;
2491 mpi_request->SGLFlags = cpu_to_le16(MPI2_SCSIIO_SGLFLAGS_TYPE_MPI +
2492 MPI2_SCSIIO_SGLFLAGS_SYSTEM_ADDR);
2494 int_to_scsilun(sas_device_priv_data->lun, (struct scsi_lun *)
2496 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
2498 if (!mpi_request->DataLength) {
2499 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request->SGL);
2501 if (_scsih_build_scatter_gather(ioc, scmd, smid)) {
2502 mpt2sas_base_free_smid(ioc, smid);
2507 _scsih_scsi_lookup_set(ioc, smid, scmd);
2508 mpt2sas_base_put_smid_scsi_io(ioc, smid, 0,
2509 sas_device_priv_data->sas_target->handle);
2513 return SCSI_MLQUEUE_HOST_BUSY;
2517 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
2518 * @sense_buffer: sense data returned by target
2519 * @data: normalized skey/asc/ascq
2524 _scsih_normalize_sense(char *sense_buffer, struct sense_info *data)
2526 if ((sense_buffer[0] & 0x7F) >= 0x72) {
2527 /* descriptor format */
2528 data->skey = sense_buffer[1] & 0x0F;
2529 data->asc = sense_buffer[2];
2530 data->ascq = sense_buffer[3];
2533 data->skey = sense_buffer[2] & 0x0F;
2534 data->asc = sense_buffer[12];
2535 data->ascq = sense_buffer[13];
2539 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
2541 * _scsih_scsi_ioc_info - translated non-succesfull SCSI_IO request
2542 * @ioc: per adapter object
2543 * @scmd: pointer to scsi command object
2544 * @mpi_reply: reply mf payload returned from firmware
2546 * scsi_status - SCSI Status code returned from target device
2547 * scsi_state - state info associated with SCSI_IO determined by ioc
2548 * ioc_status - ioc supplied status info
2553 _scsih_scsi_ioc_info(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
2554 Mpi2SCSIIOReply_t *mpi_reply, u16 smid)
2558 u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) &
2559 MPI2_IOCSTATUS_MASK;
2560 u8 scsi_state = mpi_reply->SCSIState;
2561 u8 scsi_status = mpi_reply->SCSIStatus;
2562 char *desc_ioc_state = NULL;
2563 char *desc_scsi_status = NULL;
2564 char *desc_scsi_state = ioc->tmp_string;
2566 switch (ioc_status) {
2567 case MPI2_IOCSTATUS_SUCCESS:
2568 desc_ioc_state = "success";
2570 case MPI2_IOCSTATUS_INVALID_FUNCTION:
2571 desc_ioc_state = "invalid function";
2573 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
2574 desc_ioc_state = "scsi recovered error";
2576 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE:
2577 desc_ioc_state = "scsi invalid dev handle";
2579 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
2580 desc_ioc_state = "scsi device not there";
2582 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
2583 desc_ioc_state = "scsi data overrun";
2585 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
2586 desc_ioc_state = "scsi data underrun";
2588 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
2589 desc_ioc_state = "scsi io data error";
2591 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
2592 desc_ioc_state = "scsi protocol error";
2594 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
2595 desc_ioc_state = "scsi task terminated";
2597 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
2598 desc_ioc_state = "scsi residual mismatch";
2600 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
2601 desc_ioc_state = "scsi task mgmt failed";
2603 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
2604 desc_ioc_state = "scsi ioc terminated";
2606 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
2607 desc_ioc_state = "scsi ext terminated";
2610 desc_ioc_state = "unknown";
2614 switch (scsi_status) {
2615 case MPI2_SCSI_STATUS_GOOD:
2616 desc_scsi_status = "good";
2618 case MPI2_SCSI_STATUS_CHECK_CONDITION:
2619 desc_scsi_status = "check condition";
2621 case MPI2_SCSI_STATUS_CONDITION_MET:
2622 desc_scsi_status = "condition met";
2624 case MPI2_SCSI_STATUS_BUSY:
2625 desc_scsi_status = "busy";
2627 case MPI2_SCSI_STATUS_INTERMEDIATE:
2628 desc_scsi_status = "intermediate";
2630 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET:
2631 desc_scsi_status = "intermediate condmet";
2633 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT:
2634 desc_scsi_status = "reservation conflict";
2636 case MPI2_SCSI_STATUS_COMMAND_TERMINATED:
2637 desc_scsi_status = "command terminated";
2639 case MPI2_SCSI_STATUS_TASK_SET_FULL:
2640 desc_scsi_status = "task set full";
2642 case MPI2_SCSI_STATUS_ACA_ACTIVE:
2643 desc_scsi_status = "aca active";
2645 case MPI2_SCSI_STATUS_TASK_ABORTED:
2646 desc_scsi_status = "task aborted";
2649 desc_scsi_status = "unknown";
2653 desc_scsi_state[0] = '\0';
2655 desc_scsi_state = " ";
2656 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
2657 strcat(desc_scsi_state, "response info ");
2658 if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
2659 strcat(desc_scsi_state, "state terminated ");
2660 if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS)
2661 strcat(desc_scsi_state, "no status ");
2662 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED)
2663 strcat(desc_scsi_state, "autosense failed ");
2664 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)
2665 strcat(desc_scsi_state, "autosense valid ");
2667 scsi_print_command(scmd);
2668 printk(MPT2SAS_WARN_FMT "\tdev handle(0x%04x), "
2669 "ioc_status(%s)(0x%04x), smid(%d)\n", ioc->name,
2670 le16_to_cpu(mpi_reply->DevHandle), desc_ioc_state,
2672 printk(MPT2SAS_WARN_FMT "\trequest_len(%d), underflow(%d), "
2673 "resid(%d)\n", ioc->name, scsi_bufflen(scmd), scmd->underflow,
2674 scsi_get_resid(scmd));
2675 printk(MPT2SAS_WARN_FMT "\ttag(%d), transfer_count(%d), "
2676 "sc->result(0x%08x)\n", ioc->name, le16_to_cpu(mpi_reply->TaskTag),
2677 le32_to_cpu(mpi_reply->TransferCount), scmd->result);
2678 printk(MPT2SAS_WARN_FMT "\tscsi_status(%s)(0x%02x), "
2679 "scsi_state(%s)(0x%02x)\n", ioc->name, desc_scsi_status,
2680 scsi_status, desc_scsi_state, scsi_state);
2682 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
2683 struct sense_info data;
2684 _scsih_normalize_sense(scmd->sense_buffer, &data);
2685 printk(MPT2SAS_WARN_FMT "\t[sense_key,asc,ascq]: "
2686 "[0x%02x,0x%02x,0x%02x]\n", ioc->name, data.skey,
2687 data.asc, data.ascq);
2690 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) {
2691 response_info = le32_to_cpu(mpi_reply->ResponseInfo);
2692 response_bytes = (u8 *)&response_info;
2693 _scsih_response_code(ioc, response_bytes[3]);
2699 * _scsih_smart_predicted_fault - illuminate Fault LED
2700 * @ioc: per adapter object
2701 * @handle: device handle
2706 _scsih_smart_predicted_fault(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2708 Mpi2SepReply_t mpi_reply;
2709 Mpi2SepRequest_t mpi_request;
2710 struct scsi_target *starget;
2711 struct MPT2SAS_TARGET *sas_target_priv_data;
2712 Mpi2EventNotificationReply_t *event_reply;
2713 Mpi2EventDataSasDeviceStatusChange_t *event_data;
2714 struct _sas_device *sas_device;
2716 unsigned long flags;
2718 /* only handle non-raid devices */
2719 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2720 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
2722 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2725 starget = sas_device->starget;
2726 sas_target_priv_data = starget->hostdata;
2728 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) ||
2729 ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))) {
2730 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2733 starget_printk(KERN_WARNING, starget, "predicted fault\n");
2734 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2736 if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM) {
2737 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
2738 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
2739 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
2740 mpi_request.SlotStatus =
2741 MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT;
2742 mpi_request.DevHandle = cpu_to_le16(handle);
2743 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS;
2744 if ((mpt2sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
2745 &mpi_request)) != 0) {
2746 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
2747 ioc->name, __FILE__, __LINE__, __func__);
2751 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
2752 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
2753 "enclosure_processor: ioc_status (0x%04x), "
2754 "loginfo(0x%08x)\n", ioc->name,
2755 le16_to_cpu(mpi_reply.IOCStatus),
2756 le32_to_cpu(mpi_reply.IOCLogInfo)));
2761 /* insert into event log */
2762 sz = offsetof(Mpi2EventNotificationReply_t, EventData) +
2763 sizeof(Mpi2EventDataSasDeviceStatusChange_t);
2764 event_reply = kzalloc(sz, GFP_KERNEL);
2766 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
2767 ioc->name, __FILE__, __LINE__, __func__);
2771 event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION;
2772 event_reply->Event =
2773 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE);
2774 event_reply->MsgLength = sz/4;
2775 event_reply->EventDataLength =
2776 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t)/4);
2777 event_data = (Mpi2EventDataSasDeviceStatusChange_t *)
2778 event_reply->EventData;
2779 event_data->ReasonCode = MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA;
2780 event_data->ASC = 0x5D;
2781 event_data->DevHandle = cpu_to_le16(handle);
2782 event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address);
2783 mpt2sas_ctl_add_to_event_log(ioc, event_reply);
2788 * scsih_io_done - scsi request callback
2789 * @ioc: per adapter object
2790 * @smid: system request message index
2791 * @VF_ID: virtual function id
2792 * @reply: reply message frame(lower 32bit addr)
2794 * Callback handler when using scsih_qcmd.
2799 scsih_io_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 VF_ID, u32 reply)
2801 Mpi2SCSIIORequest_t *mpi_request;
2802 Mpi2SCSIIOReply_t *mpi_reply;
2803 struct scsi_cmnd *scmd;
2809 struct MPT2SAS_DEVICE *sas_device_priv_data;
2812 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
2813 scmd = _scsih_scsi_lookup_getclear(ioc, smid);
2817 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
2819 if (mpi_reply == NULL) {
2820 scmd->result = DID_OK << 16;
2824 sas_device_priv_data = scmd->device->hostdata;
2825 if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
2826 sas_device_priv_data->sas_target->deleted) {
2827 scmd->result = DID_NO_CONNECT << 16;
2831 /* turning off TLR */
2832 if (!sas_device_priv_data->tlr_snoop_check) {
2833 sas_device_priv_data->tlr_snoop_check++;
2834 if (sas_device_priv_data->flags & MPT_DEVICE_TLR_ON) {
2835 response_code = (le32_to_cpu(mpi_reply->ResponseInfo)
2837 if (response_code ==
2838 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME)
2839 sas_device_priv_data->flags &=
2844 xfer_cnt = le32_to_cpu(mpi_reply->TransferCount);
2845 scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt);
2846 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
2847 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
2848 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
2851 ioc_status &= MPI2_IOCSTATUS_MASK;
2852 scsi_state = mpi_reply->SCSIState;
2853 scsi_status = mpi_reply->SCSIStatus;
2855 if (ioc_status == MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 &&
2856 (scsi_status == MPI2_SCSI_STATUS_BUSY ||
2857 scsi_status == MPI2_SCSI_STATUS_RESERVATION_CONFLICT ||
2858 scsi_status == MPI2_SCSI_STATUS_TASK_SET_FULL)) {
2859 ioc_status = MPI2_IOCSTATUS_SUCCESS;
2862 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
2863 struct sense_info data;
2864 const void *sense_data = mpt2sas_base_get_sense_buffer(ioc,
2866 memcpy(scmd->sense_buffer, sense_data,
2867 le32_to_cpu(mpi_reply->SenseCount));
2868 _scsih_normalize_sense(scmd->sense_buffer, &data);
2869 /* failure prediction threshold exceeded */
2870 if (data.asc == 0x5D)
2871 _scsih_smart_predicted_fault(ioc,
2872 le16_to_cpu(mpi_reply->DevHandle));
2875 switch (ioc_status) {
2876 case MPI2_IOCSTATUS_BUSY:
2877 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES:
2878 scmd->result = SAM_STAT_BUSY;
2881 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
2882 scmd->result = DID_NO_CONNECT << 16;
2885 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
2886 if (sas_device_priv_data->block) {
2887 scmd->result = (DID_BUS_BUSY << 16);
2891 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
2892 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
2893 scmd->result = DID_RESET << 16;
2896 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
2897 if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt))
2898 scmd->result = DID_SOFT_ERROR << 16;
2900 scmd->result = (DID_OK << 16) | scsi_status;
2903 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
2904 scmd->result = (DID_OK << 16) | scsi_status;
2906 if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID))
2909 if (xfer_cnt < scmd->underflow) {
2910 if (scsi_status == SAM_STAT_BUSY)
2911 scmd->result = SAM_STAT_BUSY;
2913 scmd->result = DID_SOFT_ERROR << 16;
2914 } else if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
2915 MPI2_SCSI_STATE_NO_SCSI_STATUS))
2916 scmd->result = DID_SOFT_ERROR << 16;
2917 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
2918 scmd->result = DID_RESET << 16;
2919 else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) {
2920 mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID;
2921 mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION;
2922 scmd->result = (DRIVER_SENSE << 24) |
2923 SAM_STAT_CHECK_CONDITION;
2924 scmd->sense_buffer[0] = 0x70;
2925 scmd->sense_buffer[2] = ILLEGAL_REQUEST;
2926 scmd->sense_buffer[12] = 0x20;
2927 scmd->sense_buffer[13] = 0;
2931 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
2932 scsi_set_resid(scmd, 0);
2933 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
2934 case MPI2_IOCSTATUS_SUCCESS:
2935 scmd->result = (DID_OK << 16) | scsi_status;
2936 if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
2937 MPI2_SCSI_STATE_NO_SCSI_STATUS))
2938 scmd->result = DID_SOFT_ERROR << 16;
2939 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
2940 scmd->result = DID_RESET << 16;
2943 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
2944 case MPI2_IOCSTATUS_INVALID_FUNCTION:
2945 case MPI2_IOCSTATUS_INVALID_SGL:
2946 case MPI2_IOCSTATUS_INTERNAL_ERROR:
2947 case MPI2_IOCSTATUS_INVALID_FIELD:
2948 case MPI2_IOCSTATUS_INVALID_STATE:
2949 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
2950 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
2952 scmd->result = DID_SOFT_ERROR << 16;
2957 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
2958 if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY))
2959 _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid);
2963 scsi_dma_unmap(scmd);
2964 scmd->scsi_done(scmd);
2968 * _scsih_link_change - process phy link changes
2969 * @ioc: per adapter object
2970 * @handle: phy handle
2971 * @attached_handle: valid for devices attached to link
2972 * @phy_number: phy number
2973 * @link_rate: new link rate
2979 _scsih_link_change(struct MPT2SAS_ADAPTER *ioc, u16 handle, u16 attached_handle,
2980 u8 phy_number, u8 link_rate)
2982 mpt2sas_transport_update_phy_link_change(ioc, handle, attached_handle,
2983 phy_number, link_rate);
2987 * _scsih_sas_host_refresh - refreshing sas host object contents
2988 * @ioc: per adapter object
2989 * @update: update link information
2992 * During port enable, fw will send topology events for every device. Its
2993 * possible that the handles may change from the previous setting, so this
2994 * code keeping handles updating if changed.
2999 _scsih_sas_host_refresh(struct MPT2SAS_ADAPTER *ioc, u8 update)
3004 Mpi2ConfigReply_t mpi_reply;
3005 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
3007 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT
3008 "updating handles for sas_host(0x%016llx)\n",
3009 ioc->name, (unsigned long long)ioc->sas_hba.sas_address));
3011 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys
3012 * sizeof(Mpi2SasIOUnit0PhyData_t));
3013 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
3014 if (!sas_iounit_pg0) {
3015 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3016 ioc->name, __FILE__, __LINE__, __func__);
3019 if (!(mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
3020 sas_iounit_pg0, sz))) {
3021 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
3022 MPI2_IOCSTATUS_MASK;
3023 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
3025 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
3026 ioc->sas_hba.phy[i].handle =
3027 le16_to_cpu(sas_iounit_pg0->PhyData[i].
3028 ControllerDevHandle);
3030 _scsih_link_change(ioc,
3031 ioc->sas_hba.phy[i].handle,
3032 le16_to_cpu(sas_iounit_pg0->PhyData[i].
3033 AttachedDevHandle), i,
3034 sas_iounit_pg0->PhyData[i].
3035 NegotiatedLinkRate >> 4);
3040 kfree(sas_iounit_pg0);
3044 * _scsih_sas_host_add - create sas host object
3045 * @ioc: per adapter object
3047 * Creating host side data object, stored in ioc->sas_hba
3052 _scsih_sas_host_add(struct MPT2SAS_ADAPTER *ioc)
3055 Mpi2ConfigReply_t mpi_reply;
3056 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
3057 Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
3058 Mpi2SasPhyPage0_t phy_pg0;
3059 Mpi2SasDevicePage0_t sas_device_pg0;
3060 Mpi2SasEnclosurePage0_t enclosure_pg0;
3063 u16 device_missing_delay;
3065 mpt2sas_config_get_number_hba_phys(ioc, &ioc->sas_hba.num_phys);
3066 if (!ioc->sas_hba.num_phys) {
3067 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3068 ioc->name, __FILE__, __LINE__, __func__);
3072 /* sas_iounit page 0 */
3073 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys *
3074 sizeof(Mpi2SasIOUnit0PhyData_t));
3075 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
3076 if (!sas_iounit_pg0) {
3077 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3078 ioc->name, __FILE__, __LINE__, __func__);
3081 if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
3082 sas_iounit_pg0, sz))) {
3083 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3084 ioc->name, __FILE__, __LINE__, __func__);
3087 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
3088 MPI2_IOCSTATUS_MASK;
3089 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
3090 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3091 ioc->name, __FILE__, __LINE__, __func__);
3095 /* sas_iounit page 1 */
3096 sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys *
3097 sizeof(Mpi2SasIOUnit1PhyData_t));
3098 sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
3099 if (!sas_iounit_pg1) {
3100 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3101 ioc->name, __FILE__, __LINE__, __func__);
3104 if ((mpt2sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
3105 sas_iounit_pg1, sz))) {
3106 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3107 ioc->name, __FILE__, __LINE__, __func__);
3110 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
3111 MPI2_IOCSTATUS_MASK;
3112 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
3113 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3114 ioc->name, __FILE__, __LINE__, __func__);
3118 ioc->io_missing_delay =
3119 le16_to_cpu(sas_iounit_pg1->IODeviceMissingDelay);
3120 device_missing_delay =
3121 le16_to_cpu(sas_iounit_pg1->ReportDeviceMissingDelay);
3122 if (device_missing_delay & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16)
3123 ioc->device_missing_delay = (device_missing_delay &
3124 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16;
3126 ioc->device_missing_delay = device_missing_delay &
3127 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
3129 ioc->sas_hba.parent_dev = &ioc->shost->shost_gendev;
3130 ioc->sas_hba.phy = kcalloc(ioc->sas_hba.num_phys,
3131 sizeof(struct _sas_phy), GFP_KERNEL);
3132 if (!ioc->sas_hba.phy) {
3133 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3134 ioc->name, __FILE__, __LINE__, __func__);
3137 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
3138 if ((mpt2sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0,
3140 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3141 ioc->name, __FILE__, __LINE__, __func__);
3144 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
3145 MPI2_IOCSTATUS_MASK;
3146 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
3147 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3148 ioc->name, __FILE__, __LINE__, __func__);
3151 ioc->sas_hba.phy[i].handle =
3152 le16_to_cpu(sas_iounit_pg0->PhyData[i].ControllerDevHandle);
3153 ioc->sas_hba.phy[i].phy_id = i;
3154 mpt2sas_transport_add_host_phy(ioc, &ioc->sas_hba.phy[i],
3155 phy_pg0, ioc->sas_hba.parent_dev);
3157 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
3158 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, ioc->sas_hba.phy[0].handle))) {
3159 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3160 ioc->name, __FILE__, __LINE__, __func__);
3163 ioc->sas_hba.handle = le16_to_cpu(sas_device_pg0.DevHandle);
3164 ioc->sas_hba.enclosure_handle =
3165 le16_to_cpu(sas_device_pg0.EnclosureHandle);
3166 ioc->sas_hba.sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
3167 printk(MPT2SAS_INFO_FMT "host_add: handle(0x%04x), "
3168 "sas_addr(0x%016llx), phys(%d)\n", ioc->name, ioc->sas_hba.handle,
3169 (unsigned long long) ioc->sas_hba.sas_address,
3170 ioc->sas_hba.num_phys) ;
3172 if (ioc->sas_hba.enclosure_handle) {
3173 if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply,
3175 MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
3176 ioc->sas_hba.enclosure_handle))) {
3177 ioc->sas_hba.enclosure_logical_id =
3178 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
3183 kfree(sas_iounit_pg1);
3184 kfree(sas_iounit_pg0);
3188 * _scsih_expander_add - creating expander object
3189 * @ioc: per adapter object
3190 * @handle: expander handle
3192 * Creating expander object, stored in ioc->sas_expander_list.
3194 * Return 0 for success, else error.
3197 _scsih_expander_add(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3199 struct _sas_node *sas_expander;
3200 Mpi2ConfigReply_t mpi_reply;
3201 Mpi2ExpanderPage0_t expander_pg0;
3202 Mpi2ExpanderPage1_t expander_pg1;
3203 Mpi2SasEnclosurePage0_t enclosure_pg0;
3208 unsigned long flags;
3209 struct _sas_port *mpt2sas_port;
3215 if ((mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
3216 MPI2_SAS_EXPAND_PGAD_FORM_HNDL, handle))) {
3217 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3218 ioc->name, __FILE__, __LINE__, __func__);
3222 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
3223 MPI2_IOCSTATUS_MASK;
3224 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
3225 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3226 ioc->name, __FILE__, __LINE__, __func__);
3230 /* handle out of order topology events */
3231 parent_handle = le16_to_cpu(expander_pg0.ParentDevHandle);
3232 if (parent_handle >= ioc->sas_hba.num_phys) {
3233 spin_lock_irqsave(&ioc->sas_node_lock, flags);
3234 sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc,
3236 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
3237 if (!sas_expander) {
3238 rc = _scsih_expander_add(ioc, parent_handle);
3244 sas_address = le64_to_cpu(expander_pg0.SASAddress);
3246 spin_lock_irqsave(&ioc->sas_node_lock, flags);
3247 sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
3249 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
3254 sas_expander = kzalloc(sizeof(struct _sas_node),
3256 if (!sas_expander) {
3257 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3258 ioc->name, __FILE__, __LINE__, __func__);
3262 sas_expander->handle = handle;
3263 sas_expander->num_phys = expander_pg0.NumPhys;
3264 sas_expander->parent_handle = parent_handle;
3265 sas_expander->enclosure_handle =
3266 le16_to_cpu(expander_pg0.EnclosureHandle);
3267 sas_expander->sas_address = sas_address;
3269 printk(MPT2SAS_INFO_FMT "expander_add: handle(0x%04x),"
3270 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc->name,
3271 handle, sas_expander->parent_handle, (unsigned long long)
3272 sas_expander->sas_address, sas_expander->num_phys);
3274 if (!sas_expander->num_phys)
3276 sas_expander->phy = kcalloc(sas_expander->num_phys,
3277 sizeof(struct _sas_phy), GFP_KERNEL);
3278 if (!sas_expander->phy) {
3279 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3280 ioc->name, __FILE__, __LINE__, __func__);
3285 INIT_LIST_HEAD(&sas_expander->sas_port_list);
3286 mpt2sas_port = mpt2sas_transport_port_add(ioc, handle,
3287 sas_expander->parent_handle);
3288 if (!mpt2sas_port) {
3289 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3290 ioc->name, __FILE__, __LINE__, __func__);
3294 sas_expander->parent_dev = &mpt2sas_port->rphy->dev;
3296 for (i = 0 ; i < sas_expander->num_phys ; i++) {
3297 if ((mpt2sas_config_get_expander_pg1(ioc, &mpi_reply,
3298 &expander_pg1, i, handle))) {
3299 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3300 ioc->name, __FILE__, __LINE__, __func__);
3303 sas_expander->phy[i].handle = handle;
3304 sas_expander->phy[i].phy_id = i;
3305 mpt2sas_transport_add_expander_phy(ioc, &sas_expander->phy[i],
3306 expander_pg1, sas_expander->parent_dev);
3309 if (sas_expander->enclosure_handle) {
3310 if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply,
3311 &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
3312 sas_expander->enclosure_handle))) {
3313 sas_expander->enclosure_logical_id =
3314 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
3318 _scsih_expander_node_add(ioc, sas_expander);
3324 kfree(sas_expander->phy);
3325 kfree(sas_expander);
3330 * _scsih_expander_remove - removing expander object
3331 * @ioc: per adapter object
3332 * @handle: expander handle
3337 _scsih_expander_remove(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3339 struct _sas_node *sas_expander;
3340 unsigned long flags;
3342 spin_lock_irqsave(&ioc->sas_node_lock, flags);
3343 sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc, handle);
3344 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
3345 _scsih_expander_node_remove(ioc, sas_expander);
3349 * _scsih_add_device - creating sas device object
3350 * @ioc: per adapter object
3351 * @handle: sas device handle
3352 * @phy_num: phy number end device attached to
3353 * @is_pd: is this hidden raid component
3355 * Creating end device object, stored in ioc->sas_device_list.
3357 * Returns 0 for success, non-zero for failure.
3360 _scsih_add_device(struct MPT2SAS_ADAPTER *ioc, u16 handle, u8 phy_num, u8 is_pd)
3362 Mpi2ConfigReply_t mpi_reply;
3363 Mpi2SasDevicePage0_t sas_device_pg0;
3364 Mpi2SasEnclosurePage0_t enclosure_pg0;
3365 struct _sas_device *sas_device;
3369 unsigned long flags;
3371 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
3372 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
3373 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3374 ioc->name, __FILE__, __LINE__, __func__);
3378 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
3379 MPI2_IOCSTATUS_MASK;
3380 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
3381 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3382 ioc->name, __FILE__, __LINE__, __func__);
3386 /* check if device is present */
3387 if (!(le16_to_cpu(sas_device_pg0.Flags) &
3388 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
3389 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3390 ioc->name, __FILE__, __LINE__, __func__);
3391 printk(MPT2SAS_ERR_FMT "Flags = 0x%04x\n",
3392 ioc->name, le16_to_cpu(sas_device_pg0.Flags));
3396 /* check if there were any issus with discovery */
3397 if (sas_device_pg0.AccessStatus ==
3398 MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED) {
3399 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3400 ioc->name, __FILE__, __LINE__, __func__);
3401 printk(MPT2SAS_ERR_FMT "AccessStatus = 0x%02x\n",
3402 ioc->name, sas_device_pg0.AccessStatus);
3406 /* check if this is end device */
3407 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
3408 if (!(_scsih_is_end_device(device_info))) {
3409 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3410 ioc->name, __FILE__, __LINE__, __func__);
3414 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
3416 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3417 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
3419 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3422 _scsih_ublock_io_device(ioc, handle);
3426 sas_device = kzalloc(sizeof(struct _sas_device),
3429 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3430 ioc->name, __FILE__, __LINE__, __func__);
3434 sas_device->handle = handle;
3435 sas_device->parent_handle =
3436 le16_to_cpu(sas_device_pg0.ParentDevHandle);
3437 sas_device->enclosure_handle =
3438 le16_to_cpu(sas_device_pg0.EnclosureHandle);
3440 le16_to_cpu(sas_device_pg0.Slot);
3441 sas_device->device_info = device_info;
3442 sas_device->sas_address = sas_address;
3443 sas_device->hidden_raid_component = is_pd;
3445 /* get enclosure_logical_id */
3446 if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply, &enclosure_pg0,
3447 MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
3448 sas_device->enclosure_handle))) {
3449 sas_device->enclosure_logical_id =
3450 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
3453 /* get device name */
3454 sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName);
3456 if (ioc->wait_for_port_enable_to_complete)
3457 _scsih_sas_device_init_add(ioc, sas_device);
3459 _scsih_sas_device_add(ioc, sas_device);
3465 * _scsih_remove_device - removing sas device object
3466 * @ioc: per adapter object
3467 * @handle: sas device handle
3472 _scsih_remove_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3474 struct MPT2SAS_TARGET *sas_target_priv_data;
3475 struct _sas_device *sas_device;
3476 unsigned long flags;
3477 Mpi2SasIoUnitControlReply_t mpi_reply;
3478 Mpi2SasIoUnitControlRequest_t mpi_request;
3481 /* lookup sas_device */
3482 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3483 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
3485 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3489 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter: handle"
3490 "(0x%04x)\n", ioc->name, __func__, handle));
3492 if (sas_device->starget && sas_device->starget->hostdata) {
3493 sas_target_priv_data = sas_device->starget->hostdata;
3494 sas_target_priv_data->deleted = 1;
3496 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3498 if (ioc->remove_host)
3501 /* Target Reset to flush out all the outstanding IO */
3502 device_handle = (sas_device->hidden_raid_component) ?
3503 sas_device->volume_handle : handle;
3504 if (device_handle) {
3505 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "issue target reset: "
3506 "handle(0x%04x)\n", ioc->name, device_handle));
3507 mutex_lock(&ioc->tm_cmds.mutex);
3508 mpt2sas_scsih_issue_tm(ioc, device_handle, 0,
3509 MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0, 10);
3510 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
3511 mutex_unlock(&ioc->tm_cmds.mutex);
3512 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "issue target reset "
3513 "done: handle(0x%04x)\n", ioc->name, device_handle));
3516 /* SAS_IO_UNIT_CNTR - send REMOVE_DEVICE */
3517 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "sas_iounit: handle"
3518 "(0x%04x)\n", ioc->name, handle));
3519 memset(&mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t));
3520 mpi_request.Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL;
3521 mpi_request.Operation = MPI2_SAS_OP_REMOVE_DEVICE;
3522 mpi_request.DevHandle = handle;
3523 mpi_request.VF_ID = 0;
3524 if ((mpt2sas_base_sas_iounit_control(ioc, &mpi_reply,
3525 &mpi_request)) != 0) {
3526 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3527 ioc->name, __FILE__, __LINE__, __func__);
3530 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "sas_iounit: ioc_status"
3531 "(0x%04x), loginfo(0x%08x)\n", ioc->name,
3532 le16_to_cpu(mpi_reply.IOCStatus),
3533 le32_to_cpu(mpi_reply.IOCLogInfo)));
3536 mpt2sas_transport_port_remove(ioc, sas_device->sas_address,
3537 sas_device->parent_handle);
3539 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), sas_addr"
3540 "(0x%016llx)\n", ioc->name, sas_device->handle,
3541 (unsigned long long) sas_device->sas_address);
3542 _scsih_sas_device_remove(ioc, sas_device);
3544 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: exit: handle"
3545 "(0x%04x)\n", ioc->name, __func__, handle));
3548 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3550 * _scsih_sas_topology_change_event_debug - debug for topology event
3551 * @ioc: per adapter object
3552 * @event_data: event data payload
3556 _scsih_sas_topology_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
3557 Mpi2EventDataSasTopologyChangeList_t *event_data)
3563 char *status_str = NULL;
3566 switch (event_data->ExpStatus) {
3567 case MPI2_EVENT_SAS_TOPO_ES_ADDED:
3570 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING:
3571 status_str = "remove";
3573 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING:
3574 status_str = "responding";
3576 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING:
3577 status_str = "remove delay";
3580 status_str = "unknown status";
3583 printk(MPT2SAS_DEBUG_FMT "sas topology change: (%s)\n",
3584 ioc->name, status_str);
3585 printk(KERN_DEBUG "\thandle(0x%04x), enclosure_handle(0x%04x) "
3586 "start_phy(%02d), count(%d)\n",
3587 le16_to_cpu(event_data->ExpanderDevHandle),
3588 le16_to_cpu(event_data->EnclosureHandle),
3589 event_data->StartPhyNum, event_data->NumEntries);
3590 for (i = 0; i < event_data->NumEntries; i++) {
3591 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
3594 phy_number = event_data->StartPhyNum + i;
3595 reason_code = event_data->PHY[i].PhyStatus &
3596 MPI2_EVENT_SAS_TOPO_RC_MASK;
3597 switch (reason_code) {
3598 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
3599 snprintf(link_rate, 25, ": add, link(0x%02x)",
3600 (event_data->PHY[i].LinkRate >> 4));
3601 status_str = link_rate;
3603 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
3604 status_str = ": remove";
3606 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING:
3607 status_str = ": remove_delay";
3609 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
3610 snprintf(link_rate, 25, ": link(0x%02x)",
3611 (event_data->PHY[i].LinkRate >> 4));
3612 status_str = link_rate;
3614 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE:
3615 status_str = ": responding";
3618 status_str = ": unknown";
3621 printk(KERN_DEBUG "\tphy(%02d), attached_handle(0x%04x)%s\n",
3622 phy_number, handle, status_str);
3628 * _scsih_sas_topology_change_event - handle topology changes
3629 * @ioc: per adapter object
3631 * @event_data: event data payload
3637 _scsih_sas_topology_change_event(struct MPT2SAS_ADAPTER *ioc, u8 VF_ID,
3638 Mpi2EventDataSasTopologyChangeList_t *event_data,
3639 struct fw_event_work *fw_event)
3642 u16 parent_handle, handle;
3645 struct _sas_node *sas_expander;
3646 unsigned long flags;
3649 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3650 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
3651 _scsih_sas_topology_change_event_debug(ioc, event_data);
3654 if (!ioc->sas_hba.num_phys)
3655 _scsih_sas_host_add(ioc);
3657 _scsih_sas_host_refresh(ioc, 0);
3659 if (fw_event->ignore) {
3660 dewtprintk(ioc, printk(MPT2SAS_DEBUG_FMT "ignoring expander "
3661 "event\n", ioc->name));
3665 parent_handle = le16_to_cpu(event_data->ExpanderDevHandle);
3667 /* handle expander add */
3668 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_ADDED)
3669 if (_scsih_expander_add(ioc, parent_handle) != 0)
3672 /* handle siblings events */
3673 for (i = 0; i < event_data->NumEntries; i++) {
3674 if (fw_event->ignore) {
3675 dewtprintk(ioc, printk(MPT2SAS_DEBUG_FMT "ignoring "
3676 "expander event\n", ioc->name));
3679 if (event_data->PHY[i].PhyStatus &
3680 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT)
3682 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
3685 phy_number = event_data->StartPhyNum + i;
3686 reason_code = event_data->PHY[i].PhyStatus &
3687 MPI2_EVENT_SAS_TOPO_RC_MASK;
3688 link_rate_ = event_data->PHY[i].LinkRate >> 4;
3689 switch (reason_code) {
3690 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
3691 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
3692 if (!parent_handle) {
3693 if (phy_number < ioc->sas_hba.num_phys)
3694 _scsih_link_change(ioc,
3695 ioc->sas_hba.phy[phy_number].handle,
3696 handle, phy_number, link_rate_);
3698 spin_lock_irqsave(&ioc->sas_node_lock, flags);
3700 mpt2sas_scsih_expander_find_by_handle(ioc,
3702 spin_unlock_irqrestore(&ioc->sas_node_lock,
3705 if (phy_number < sas_expander->num_phys)
3706 _scsih_link_change(ioc,
3708 phy[phy_number].handle,
3713 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED) {
3714 if (link_rate_ >= MPI2_SAS_NEG_LINK_RATE_1_5)
3715 _scsih_ublock_io_device(ioc, handle);
3717 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED) {
3718 if (link_rate_ < MPI2_SAS_NEG_LINK_RATE_1_5)
3720 _scsih_add_device(ioc, handle, phy_number, 0);
3723 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
3724 _scsih_remove_device(ioc, handle);
3729 /* handle expander removal */
3730 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING)
3731 _scsih_expander_remove(ioc, parent_handle);
3735 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3737 * _scsih_sas_device_status_change_event_debug - debug for device event
3738 * @event_data: event data payload
3744 _scsih_sas_device_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
3745 Mpi2EventDataSasDeviceStatusChange_t *event_data)
3747 char *reason_str = NULL;
3749 switch (event_data->ReasonCode) {
3750 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
3751 reason_str = "smart data";
3753 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED:
3754 reason_str = "unsupported device discovered";
3756 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
3757 reason_str = "internal device reset";
3759 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL:
3760 reason_str = "internal task abort";
3762 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL:
3763 reason_str = "internal task abort set";
3765 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL:
3766 reason_str = "internal clear task set";
3768 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL:
3769 reason_str = "internal query task";
3771 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE:
3772 reason_str = "sata init failure";
3774 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET:
3775 reason_str = "internal device reset complete";
3777 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL:
3778 reason_str = "internal task abort complete";
3780 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION:
3781 reason_str = "internal async notification";
3784 reason_str = "unknown reason";
3787 printk(MPT2SAS_DEBUG_FMT "device status change: (%s)\n"
3788 "\thandle(0x%04x), sas address(0x%016llx)", ioc->name,
3789 reason_str, le16_to_cpu(event_data->DevHandle),
3790 (unsigned long long)le64_to_cpu(event_data->SASAddress));
3791 if (event_data->ReasonCode == MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA)
3792 printk(MPT2SAS_DEBUG_FMT ", ASC(0x%x), ASCQ(0x%x)\n", ioc->name,
3793 event_data->ASC, event_data->ASCQ);
3794 printk(KERN_INFO "\n");
3799 * _scsih_sas_device_status_change_event - handle device status change
3800 * @ioc: per adapter object
3802 * @event_data: event data payload
3808 _scsih_sas_device_status_change_event(struct MPT2SAS_ADAPTER *ioc, u8 VF_ID,
3809 Mpi2EventDataSasDeviceStatusChange_t *event_data)
3811 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3812 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
3813 _scsih_sas_device_status_change_event_debug(ioc, event_data);
3817 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3819 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure event
3820 * @ioc: per adapter object
3821 * @event_data: event data payload
3827 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
3828 Mpi2EventDataSasEnclDevStatusChange_t *event_data)
3830 char *reason_str = NULL;
3832 switch (event_data->ReasonCode) {
3833 case MPI2_EVENT_SAS_ENCL_RC_ADDED:
3834 reason_str = "enclosure add";
3836 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING:
3837 reason_str = "enclosure remove";
3840 reason_str = "unknown reason";
3844 printk(MPT2SAS_DEBUG_FMT "enclosure status change: (%s)\n"
3845 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
3846 " number slots(%d)\n", ioc->name, reason_str,
3847 le16_to_cpu(event_data->EnclosureHandle),
3848 (unsigned long long)le64_to_cpu(event_data->EnclosureLogicalID),
3849 le16_to_cpu(event_data->StartSlot));
3854 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
3855 * @ioc: per adapter object
3857 * @event_data: event data payload
3863 _scsih_sas_enclosure_dev_status_change_event(struct MPT2SAS_ADAPTER *ioc,
3864 u8 VF_ID, Mpi2EventDataSasEnclDevStatusChange_t *event_data)
3866 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3867 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
3868 _scsih_sas_enclosure_dev_status_change_event_debug(ioc,
3874 * _scsih_sas_broadcast_primative_event - handle broadcast events
3875 * @ioc: per adapter object
3876 * @event_data: event data payload
3882 _scsih_sas_broadcast_primative_event(struct MPT2SAS_ADAPTER *ioc, u8 VF_ID,
3883 Mpi2EventDataSasBroadcastPrimitive_t *event_data)
3885 struct scsi_cmnd *scmd;
3888 struct MPT2SAS_DEVICE *sas_device_priv_data;
3889 u32 termination_count;
3891 Mpi2SCSITaskManagementReply_t *mpi_reply;
3893 dewtprintk(ioc, printk(MPT2SAS_DEBUG_FMT "broadcast primative: "
3894 "phy number(%d), width(%d)\n", ioc->name, event_data->PhyNum,
3895 event_data->PortWidth));
3897 dtmprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: enter\n", ioc->name,
3900 mutex_lock(&ioc->tm_cmds.mutex);
3901 termination_count = 0;
3903 mpi_reply = ioc->tm_cmds.reply;
3904 for (smid = 1; smid <= ioc->request_depth; smid++) {
3905 scmd = _scsih_scsi_lookup_get(ioc, smid);
3908 sas_device_priv_data = scmd->device->hostdata;
3909 if (!sas_device_priv_data || !sas_device_priv_data->sas_target)
3911 /* skip hidden raid components */
3912 if (sas_device_priv_data->sas_target->flags &
3913 MPT_TARGET_FLAGS_RAID_COMPONENT)
3916 if (sas_device_priv_data->sas_target->flags &
3917 MPT_TARGET_FLAGS_VOLUME)
3920 handle = sas_device_priv_data->sas_target->handle;
3921 lun = sas_device_priv_data->lun;
3924 mpt2sas_scsih_issue_tm(ioc, handle, lun,
3925 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, smid, 30);
3926 termination_count += le32_to_cpu(mpi_reply->TerminationCount);
3928 if ((mpi_reply->IOCStatus == MPI2_IOCSTATUS_SUCCESS) &&
3929 (mpi_reply->ResponseCode ==
3930 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED ||
3931 mpi_reply->ResponseCode ==
3932 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC))
3935 mpt2sas_scsih_issue_tm(ioc, handle, lun,
3936 MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET, smid, 30);
3937 termination_count += le32_to_cpu(mpi_reply->TerminationCount);
3939 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
3940 ioc->broadcast_aen_busy = 0;
3941 mutex_unlock(&ioc->tm_cmds.mutex);
3943 dtmprintk(ioc, printk(MPT2SAS_DEBUG_FMT
3944 "%s - exit, query_count = %d termination_count = %d\n",
3945 ioc->name, __func__, query_count, termination_count));
3949 * _scsih_sas_discovery_event - handle discovery events
3950 * @ioc: per adapter object
3951 * @event_data: event data payload
3957 _scsih_sas_discovery_event(struct MPT2SAS_ADAPTER *ioc, u8 VF_ID,
3958 Mpi2EventDataSasDiscovery_t *event_data)
3960 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3961 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) {
3962 printk(MPT2SAS_DEBUG_FMT "discovery event: (%s)", ioc->name,
3963 (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ?
3965 if (event_data->DiscoveryStatus)
3966 printk(MPT2SAS_DEBUG_FMT ", discovery_status(0x%08x)",
3967 ioc->name, le32_to_cpu(event_data->DiscoveryStatus));
3972 if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED &&
3973 !ioc->sas_hba.num_phys)
3974 _scsih_sas_host_add(ioc);
3978 * _scsih_reprobe_lun - reprobing lun
3979 * @sdev: scsi device struct
3980 * @no_uld_attach: sdev->no_uld_attach flag setting
3984 _scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach)
3988 sdev->no_uld_attach = no_uld_attach ? 1 : 0;
3989 sdev_printk(KERN_INFO, sdev, "%s raid component\n",
3990 sdev->no_uld_attach ? "hidding" : "exposing");
3991 rc = scsi_device_reprobe(sdev);
3995 * _scsih_reprobe_target - reprobing target
3996 * @starget: scsi target struct
3997 * @no_uld_attach: sdev->no_uld_attach flag setting
3999 * Note: no_uld_attach flag determines whether the disk device is attached
4000 * to block layer. A value of `1` means to not attach.
4003 _scsih_reprobe_target(struct scsi_target *starget, int no_uld_attach)
4005 struct MPT2SAS_TARGET *sas_target_priv_data = starget->hostdata;
4008 sas_target_priv_data->flags |= MPT_TARGET_FLAGS_RAID_COMPONENT;
4010 sas_target_priv_data->flags &= ~MPT_TARGET_FLAGS_RAID_COMPONENT;
4012 starget_for_each_device(starget, no_uld_attach ? (void *)1 : NULL,
4013 _scsih_reprobe_lun);
4016 * _scsih_sas_volume_add - add new volume
4017 * @ioc: per adapter object
4018 * @element: IR config element data
4024 _scsih_sas_volume_add(struct MPT2SAS_ADAPTER *ioc,
4025 Mpi2EventIrConfigElement_t *element)
4027 struct _raid_device *raid_device;
4028 unsigned long flags;
4030 u16 handle = le16_to_cpu(element->VolDevHandle);
4033 #if 0 /* RAID_HACKS */
4034 if (le32_to_cpu(event_data->Flags) &
4035 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG)
4039 mpt2sas_config_get_volume_wwid(ioc, handle, &wwid);
4041 printk(MPT2SAS_ERR_FMT
4042 "failure at %s:%d/%s()!\n", ioc->name,
4043 __FILE__, __LINE__, __func__);
4047 spin_lock_irqsave(&ioc->raid_device_lock, flags);
4048 raid_device = _scsih_raid_device_find_by_wwid(ioc, wwid);
4049 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
4054 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
4056 printk(MPT2SAS_ERR_FMT
4057 "failure at %s:%d/%s()!\n", ioc->name,
4058 __FILE__, __LINE__, __func__);
4062 raid_device->id = ioc->sas_id++;
4063 raid_device->channel = RAID_CHANNEL;
4064 raid_device->handle = handle;
4065 raid_device->wwid = wwid;
4066 _scsih_raid_device_add(ioc, raid_device);
4067 if (!ioc->wait_for_port_enable_to_complete) {
4068 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
4069 raid_device->id, 0);
4071 _scsih_raid_device_remove(ioc, raid_device);
4073 _scsih_determine_boot_device(ioc, raid_device, 1);
4077 * _scsih_sas_volume_delete - delete volume
4078 * @ioc: per adapter object
4079 * @element: IR config element data
4085 _scsih_sas_volume_delete(struct MPT2SAS_ADAPTER *ioc,
4086 Mpi2EventIrConfigElement_t *element)
4088 struct _raid_device *raid_device;
4089 u16 handle = le16_to_cpu(element->VolDevHandle);
4090 unsigned long flags;
4091 struct MPT2SAS_TARGET *sas_target_priv_data;
4093 #if 0 /* RAID_HACKS */
4094 if (le32_to_cpu(event_data->Flags) &
4095 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG)
4099 spin_lock_irqsave(&ioc->raid_device_lock, flags);
4100 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
4101 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
4104 if (raid_device->starget) {
4105 sas_target_priv_data = raid_device->starget->hostdata;
4106 sas_target_priv_data->deleted = 1;
4107 scsi_remove_target(&raid_device->starget->dev);
4109 _scsih_raid_device_remove(ioc, raid_device);
4113 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
4114 * @ioc: per adapter object
4115 * @element: IR config element data
4121 _scsih_sas_pd_expose(struct MPT2SAS_ADAPTER *ioc,
4122 Mpi2EventIrConfigElement_t *element)
4124 struct _sas_device *sas_device;
4125 unsigned long flags;
4126 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
4128 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4129 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
4130 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4134 /* exposing raid component */
4135 sas_device->volume_handle = 0;
4136 sas_device->volume_wwid = 0;
4137 sas_device->hidden_raid_component = 0;
4138 _scsih_reprobe_target(sas_device->starget, 0);
4142 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
4143 * @ioc: per adapter object
4144 * @element: IR config element data
4150 _scsih_sas_pd_hide(struct MPT2SAS_ADAPTER *ioc,
4151 Mpi2EventIrConfigElement_t *element)
4153 struct _sas_device *sas_device;
4154 unsigned long flags;
4155 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
4157 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4158 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
4159 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4163 /* hiding raid component */
4164 mpt2sas_config_get_volume_handle(ioc, handle,
4165 &sas_device->volume_handle);
4166 mpt2sas_config_get_volume_wwid(ioc, sas_device->volume_handle,
4167 &sas_device->volume_wwid);
4168 sas_device->hidden_raid_component = 1;
4169 _scsih_reprobe_target(sas_device->starget, 1);
4173 * _scsih_sas_pd_delete - delete pd component
4174 * @ioc: per adapter object
4175 * @element: IR config element data
4181 _scsih_sas_pd_delete(struct MPT2SAS_ADAPTER *ioc,
4182 Mpi2EventIrConfigElement_t *element)
4184 struct _sas_device *sas_device;
4185 unsigned long flags;
4186 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
4188 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4189 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
4190 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4193 _scsih_remove_device(ioc, handle);
4197 * _scsih_sas_pd_add - remove pd component
4198 * @ioc: per adapter object
4199 * @element: IR config element data
4205 _scsih_sas_pd_add(struct MPT2SAS_ADAPTER *ioc,
4206 Mpi2EventIrConfigElement_t *element)
4208 struct _sas_device *sas_device;
4209 unsigned long flags;
4210 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
4212 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4213 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
4214 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4216 sas_device->hidden_raid_component = 1;
4218 _scsih_add_device(ioc, handle, 0, 1);
4221 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4223 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
4224 * @ioc: per adapter object
4225 * @event_data: event data payload
4231 _scsih_sas_ir_config_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
4232 Mpi2EventDataIrConfigChangeList_t *event_data)
4234 Mpi2EventIrConfigElement_t *element;
4237 char *reason_str = NULL, *element_str = NULL;
4239 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
4241 printk(MPT2SAS_DEBUG_FMT "raid config change: (%s), elements(%d)\n",
4242 ioc->name, (le32_to_cpu(event_data->Flags) &
4243 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ?
4244 "foreign" : "native", event_data->NumElements);
4245 for (i = 0; i < event_data->NumElements; i++, element++) {
4246 switch (element->ReasonCode) {
4247 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
4250 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
4251 reason_str = "remove";
4253 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE:
4254 reason_str = "no change";
4256 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
4257 reason_str = "hide";
4259 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
4260 reason_str = "unhide";
4262 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
4263 reason_str = "volume_created";
4265 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
4266 reason_str = "volume_deleted";
4268 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
4269 reason_str = "pd_created";
4271 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
4272 reason_str = "pd_deleted";
4275 reason_str = "unknown reason";
4278 element_type = le16_to_cpu(element->ElementFlags) &
4279 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK;
4280 switch (element_type) {
4281 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT:
4282 element_str = "volume";
4284 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT:
4285 element_str = "phys disk";
4287 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT:
4288 element_str = "hot spare";
4291 element_str = "unknown element";
4294 printk(KERN_DEBUG "\t(%s:%s), vol handle(0x%04x), "
4295 "pd handle(0x%04x), pd num(0x%02x)\n", element_str,
4296 reason_str, le16_to_cpu(element->VolDevHandle),
4297 le16_to_cpu(element->PhysDiskDevHandle),
4298 element->PhysDiskNum);
4304 * _scsih_sas_ir_config_change_event - handle ir configuration change events
4305 * @ioc: per adapter object
4307 * @event_data: event data payload
4313 _scsih_sas_ir_config_change_event(struct MPT2SAS_ADAPTER *ioc, u8 VF_ID,
4314 Mpi2EventDataIrConfigChangeList_t *event_data)
4316 Mpi2EventIrConfigElement_t *element;
4319 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4320 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
4321 _scsih_sas_ir_config_change_event_debug(ioc, event_data);
4325 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
4326 for (i = 0; i < event_data->NumElements; i++, element++) {
4328 switch (element->ReasonCode) {
4329 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
4330 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
4331 _scsih_sas_volume_add(ioc, element);
4333 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
4334 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
4335 _scsih_sas_volume_delete(ioc, element);
4337 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
4338 _scsih_sas_pd_hide(ioc, element);
4340 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
4341 _scsih_sas_pd_expose(ioc, element);
4343 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
4344 _scsih_sas_pd_add(ioc, element);
4346 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
4347 _scsih_sas_pd_delete(ioc, element);
4354 * _scsih_sas_ir_volume_event - IR volume event
4355 * @ioc: per adapter object
4356 * @event_data: event data payload
4362 _scsih_sas_ir_volume_event(struct MPT2SAS_ADAPTER *ioc, u8 VF_ID,
4363 Mpi2EventDataIrVolume_t *event_data)
4366 unsigned long flags;
4367 struct _raid_device *raid_device;
4371 struct MPT2SAS_TARGET *sas_target_priv_data;
4373 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
4376 handle = le16_to_cpu(event_data->VolDevHandle);
4377 state = le32_to_cpu(event_data->NewValue);
4378 dewtprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: handle(0x%04x), "
4379 "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle,
4380 le32_to_cpu(event_data->PreviousValue), state));
4382 spin_lock_irqsave(&ioc->raid_device_lock, flags);
4383 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
4384 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
4387 case MPI2_RAID_VOL_STATE_MISSING:
4388 case MPI2_RAID_VOL_STATE_FAILED:
4391 if (raid_device->starget) {
4392 sas_target_priv_data = raid_device->starget->hostdata;
4393 sas_target_priv_data->deleted = 1;
4394 scsi_remove_target(&raid_device->starget->dev);
4396 _scsih_raid_device_remove(ioc, raid_device);
4399 case MPI2_RAID_VOL_STATE_ONLINE:
4400 case MPI2_RAID_VOL_STATE_DEGRADED:
4401 case MPI2_RAID_VOL_STATE_OPTIMAL:
4405 mpt2sas_config_get_volume_wwid(ioc, handle, &wwid);
4407 printk(MPT2SAS_ERR_FMT
4408 "failure at %s:%d/%s()!\n", ioc->name,
4409 __FILE__, __LINE__, __func__);
4413 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
4415 printk(MPT2SAS_ERR_FMT
4416 "failure at %s:%d/%s()!\n", ioc->name,
4417 __FILE__, __LINE__, __func__);
4421 raid_device->id = ioc->sas_id++;
4422 raid_device->channel = RAID_CHANNEL;
4423 raid_device->handle = handle;
4424 raid_device->wwid = wwid;
4425 _scsih_raid_device_add(ioc, raid_device);
4426 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
4427 raid_device->id, 0);
4429 _scsih_raid_device_remove(ioc, raid_device);
4432 case MPI2_RAID_VOL_STATE_INITIALIZING:
4439 * _scsih_sas_ir_physical_disk_event - PD event
4440 * @ioc: per adapter object
4441 * @event_data: event data payload
4447 _scsih_sas_ir_physical_disk_event(struct MPT2SAS_ADAPTER *ioc, u8 VF_ID,
4448 Mpi2EventDataIrPhysicalDisk_t *event_data)
4452 struct _sas_device *sas_device;
4453 unsigned long flags;
4455 if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED)
4458 handle = le16_to_cpu(event_data->PhysDiskDevHandle);
4459 state = le32_to_cpu(event_data->NewValue);
4461 dewtprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: handle(0x%04x), "
4462 "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle,
4463 le32_to_cpu(event_data->PreviousValue), state));
4465 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4466 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
4467 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4471 case MPI2_RAID_PD_STATE_OFFLINE:
4473 _scsih_remove_device(ioc, handle);
4476 case MPI2_RAID_PD_STATE_ONLINE:
4477 case MPI2_RAID_PD_STATE_DEGRADED:
4478 case MPI2_RAID_PD_STATE_REBUILDING:
4479 case MPI2_RAID_PD_STATE_OPTIMAL:
4481 sas_device->hidden_raid_component = 1;
4483 _scsih_add_device(ioc, handle, 0, 1);
4486 case MPI2_RAID_PD_STATE_NOT_CONFIGURED:
4487 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE:
4488 case MPI2_RAID_PD_STATE_HOT_SPARE:
4494 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4496 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
4497 * @ioc: per adapter object
4498 * @event_data: event data payload
4504 _scsih_sas_ir_operation_status_event_debug(struct MPT2SAS_ADAPTER *ioc,
4505 Mpi2EventDataIrOperationStatus_t *event_data)
4507 char *reason_str = NULL;
4509 switch (event_data->RAIDOperation) {
4510 case MPI2_EVENT_IR_RAIDOP_RESYNC:
4511 reason_str = "resync";
4513 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION:
4514 reason_str = "online capacity expansion";
4516 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK:
4517 reason_str = "consistency check";
4520 reason_str = "unknown reason";
4524 printk(MPT2SAS_INFO_FMT "raid operational status: (%s)"
4525 "\thandle(0x%04x), percent complete(%d)\n",
4526 ioc->name, reason_str,
4527 le16_to_cpu(event_data->VolDevHandle),
4528 event_data->PercentComplete);
4533 * _scsih_sas_ir_operation_status_event - handle RAID operation events
4534 * @ioc: per adapter object
4536 * @event_data: event data payload
4542 _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc, u8 VF_ID,
4543 Mpi2EventDataIrOperationStatus_t *event_data)
4545 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4546 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
4547 _scsih_sas_ir_operation_status_event_debug(ioc, event_data);
4552 * _scsih_task_set_full - handle task set full
4553 * @ioc: per adapter object
4554 * @event_data: event data payload
4557 * Throttle back qdepth.
4560 _scsih_task_set_full(struct MPT2SAS_ADAPTER *ioc, u8 VF_ID,
4561 Mpi2EventDataTaskSetFull_t *event_data)
4563 unsigned long flags;
4564 struct _sas_device *sas_device;
4565 static struct _raid_device *raid_device;
4566 struct scsi_device *sdev;
4573 current_depth = le16_to_cpu(event_data->CurrentDepth);
4574 handle = le16_to_cpu(event_data->DevHandle);
4575 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4576 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
4578 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4581 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4582 id = sas_device->id;
4583 channel = sas_device->channel;
4584 sas_address = sas_device->sas_address;
4586 /* if hidden raid component, then change to volume characteristics */
4587 if (sas_device->hidden_raid_component && sas_device->volume_handle) {
4588 spin_lock_irqsave(&ioc->raid_device_lock, flags);
4589 raid_device = _scsih_raid_device_find_by_handle(
4590 ioc, sas_device->volume_handle);
4591 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
4593 id = raid_device->id;
4594 channel = raid_device->channel;
4595 handle = raid_device->handle;
4596 sas_address = raid_device->wwid;
4600 if (ioc->logging_level & MPT_DEBUG_TASK_SET_FULL)
4601 starget_printk(KERN_DEBUG, sas_device->starget, "task set "
4602 "full: handle(0x%04x), sas_addr(0x%016llx), depth(%d)\n",
4603 handle, (unsigned long long)sas_address, current_depth);
4605 shost_for_each_device(sdev, ioc->shost) {
4606 if (sdev->id == id && sdev->channel == channel) {
4607 if (current_depth > sdev->queue_depth) {
4608 if (ioc->logging_level &
4609 MPT_DEBUG_TASK_SET_FULL)
4610 sdev_printk(KERN_INFO, sdev, "strange "
4611 "observation, the queue depth is"
4612 " (%d) meanwhile fw queue depth "
4613 "is (%d)\n", sdev->queue_depth,
4617 depth = scsi_track_queue_full(sdev,
4620 sdev_printk(KERN_INFO, sdev, "Queue depth "
4621 "reduced to (%d)\n", depth);
4623 sdev_printk(KERN_INFO, sdev, "Tagged Command "
4624 "Queueing is being disabled\n");
4625 else if (depth == 0)
4626 if (ioc->logging_level &
4627 MPT_DEBUG_TASK_SET_FULL)
4628 sdev_printk(KERN_INFO, sdev,
4629 "Queue depth not changed yet\n");
4635 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
4636 * @ioc: per adapter object
4637 * @sas_address: sas address
4638 * @slot: enclosure slot id
4639 * @handle: device handle
4641 * After host reset, find out whether devices are still responding.
4642 * Used in _scsi_remove_unresponsive_sas_devices.
4647 _scsih_mark_responding_sas_device(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
4648 u16 slot, u16 handle)
4650 struct MPT2SAS_TARGET *sas_target_priv_data;
4651 struct scsi_target *starget;
4652 struct _sas_device *sas_device;
4653 unsigned long flags;
4655 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4656 list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
4657 if (sas_device->sas_address == sas_address &&
4658 sas_device->slot == slot && sas_device->starget) {
4659 sas_device->responding = 1;
4660 starget_printk(KERN_INFO, sas_device->starget,
4661 "handle(0x%04x), sas_addr(0x%016llx), enclosure "
4662 "logical id(0x%016llx), slot(%d)\n", handle,
4663 (unsigned long long)sas_device->sas_address,
4664 (unsigned long long)
4665 sas_device->enclosure_logical_id,
4667 if (sas_device->handle == handle)
4669 printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n",
4670 sas_device->handle);
4671 sas_device->handle = handle;
4672 starget = sas_device->starget;
4673 sas_target_priv_data = starget->hostdata;
4674 sas_target_priv_data->handle = handle;
4679 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4683 * _scsih_search_responding_sas_devices -
4684 * @ioc: per adapter object
4686 * After host reset, find out whether devices are still responding.
4692 _scsih_search_responding_sas_devices(struct MPT2SAS_ADAPTER *ioc)
4694 Mpi2SasDevicePage0_t sas_device_pg0;
4695 Mpi2ConfigReply_t mpi_reply;
4702 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, __func__);
4704 if (list_empty(&ioc->sas_device_list))
4708 while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
4709 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
4711 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4712 MPI2_IOCSTATUS_MASK;
4713 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
4715 handle = le16_to_cpu(sas_device_pg0.DevHandle);
4716 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
4717 if (!(_scsih_is_end_device(device_info)))
4719 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
4720 slot = le16_to_cpu(sas_device_pg0.Slot);
4721 _scsih_mark_responding_sas_device(ioc, sas_address, slot,
4727 * _scsih_mark_responding_raid_device - mark a raid_device as responding
4728 * @ioc: per adapter object
4729 * @wwid: world wide identifier for raid volume
4730 * @handle: device handle
4732 * After host reset, find out whether devices are still responding.
4733 * Used in _scsi_remove_unresponsive_raid_devices.
4738 _scsih_mark_responding_raid_device(struct MPT2SAS_ADAPTER *ioc, u64 wwid,
4741 struct MPT2SAS_TARGET *sas_target_priv_data;
4742 struct scsi_target *starget;
4743 struct _raid_device *raid_device;
4744 unsigned long flags;
4746 spin_lock_irqsave(&ioc->raid_device_lock, flags);
4747 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
4748 if (raid_device->wwid == wwid && raid_device->starget) {
4749 raid_device->responding = 1;
4750 starget_printk(KERN_INFO, raid_device->starget,
4751 "handle(0x%04x), wwid(0x%016llx)\n", handle,
4752 (unsigned long long)raid_device->wwid);
4753 if (raid_device->handle == handle)
4755 printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n",
4756 raid_device->handle);
4757 raid_device->handle = handle;
4758 starget = raid_device->starget;
4759 sas_target_priv_data = starget->hostdata;
4760 sas_target_priv_data->handle = handle;
4765 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
4769 * _scsih_search_responding_raid_devices -
4770 * @ioc: per adapter object
4772 * After host reset, find out whether devices are still responding.
4778 _scsih_search_responding_raid_devices(struct MPT2SAS_ADAPTER *ioc)
4780 Mpi2RaidVolPage1_t volume_pg1;
4781 Mpi2ConfigReply_t mpi_reply;
4785 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, __func__);
4787 if (list_empty(&ioc->raid_device_list))
4791 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
4792 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
4793 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4794 MPI2_IOCSTATUS_MASK;
4795 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
4797 handle = le16_to_cpu(volume_pg1.DevHandle);
4798 _scsih_mark_responding_raid_device(ioc,
4799 le64_to_cpu(volume_pg1.WWID), handle);
4804 * _scsih_mark_responding_expander - mark a expander as responding
4805 * @ioc: per adapter object
4806 * @sas_address: sas address
4809 * After host reset, find out whether devices are still responding.
4810 * Used in _scsi_remove_unresponsive_expanders.
4815 _scsih_mark_responding_expander(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
4818 struct _sas_node *sas_expander;
4819 unsigned long flags;
4821 spin_lock_irqsave(&ioc->sas_node_lock, flags);
4822 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
4823 if (sas_expander->sas_address == sas_address) {
4824 sas_expander->responding = 1;
4825 if (sas_expander->handle != handle) {
4826 printk(KERN_INFO "old handle(0x%04x)\n",
4827 sas_expander->handle);
4828 sas_expander->handle = handle;
4834 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4838 * _scsih_search_responding_expanders -
4839 * @ioc: per adapter object
4841 * After host reset, find out whether devices are still responding.
4847 _scsih_search_responding_expanders(struct MPT2SAS_ADAPTER *ioc)
4849 Mpi2ExpanderPage0_t expander_pg0;
4850 Mpi2ConfigReply_t mpi_reply;
4855 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, __func__);
4857 if (list_empty(&ioc->sas_expander_list))
4861 while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
4862 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
4864 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4865 MPI2_IOCSTATUS_MASK;
4866 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
4869 handle = le16_to_cpu(expander_pg0.DevHandle);
4870 sas_address = le64_to_cpu(expander_pg0.SASAddress);
4871 printk(KERN_INFO "\texpander present: handle(0x%04x), "
4872 "sas_addr(0x%016llx)\n", handle,
4873 (unsigned long long)sas_address);
4874 _scsih_mark_responding_expander(ioc, sas_address, handle);
4880 * _scsih_remove_unresponding_devices - removing unresponding devices
4881 * @ioc: per adapter object
4886 _scsih_remove_unresponding_devices(struct MPT2SAS_ADAPTER *ioc)
4888 struct _sas_device *sas_device, *sas_device_next;
4889 struct _sas_node *sas_expander, *sas_expander_next;
4890 struct _raid_device *raid_device, *raid_device_next;
4891 unsigned long flags;
4893 _scsih_search_responding_sas_devices(ioc);
4894 _scsih_search_responding_raid_devices(ioc);
4895 _scsih_search_responding_expanders(ioc);
4897 spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags);
4898 ioc->shost_recovery = 0;
4899 if (ioc->shost->shost_state == SHOST_RECOVERY) {
4900 printk(MPT2SAS_INFO_FMT "putting controller into "
4901 "SHOST_RUNNING\n", ioc->name);
4902 scsi_host_set_state(ioc->shost, SHOST_RUNNING);
4904 spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags);
4906 list_for_each_entry_safe(sas_device, sas_device_next,
4907 &ioc->sas_device_list, list) {
4908 if (sas_device->responding) {
4909 sas_device->responding = 0;
4912 if (sas_device->starget)
4913 starget_printk(KERN_INFO, sas_device->starget,
4914 "removing: handle(0x%04x), sas_addr(0x%016llx), "
4915 "enclosure logical id(0x%016llx), slot(%d)\n",
4917 (unsigned long long)sas_device->sas_address,
4918 (unsigned long long)
4919 sas_device->enclosure_logical_id,
4921 _scsih_remove_device(ioc, sas_device->handle);
4924 list_for_each_entry_safe(raid_device, raid_device_next,
4925 &ioc->raid_device_list, list) {
4926 if (raid_device->responding) {
4927 raid_device->responding = 0;
4930 if (raid_device->starget) {
4931 starget_printk(KERN_INFO, raid_device->starget,
4932 "removing: handle(0x%04x), wwid(0x%016llx)\n",
4933 raid_device->handle,
4934 (unsigned long long)raid_device->wwid);
4935 scsi_remove_target(&raid_device->starget->dev);
4937 _scsih_raid_device_remove(ioc, raid_device);
4940 list_for_each_entry_safe(sas_expander, sas_expander_next,
4941 &ioc->sas_expander_list, list) {
4942 if (sas_expander->responding) {
4943 sas_expander->responding = 0;
4946 printk("\tremoving expander: handle(0x%04x), "
4947 " sas_addr(0x%016llx)\n", sas_expander->handle,
4948 (unsigned long long)sas_expander->sas_address);
4949 _scsih_expander_remove(ioc, sas_expander->handle);
4954 * _firmware_event_work - delayed task for processing firmware events
4955 * @ioc: per adapter object
4956 * @work: equal to the fw_event_work object
4962 _firmware_event_work(struct work_struct *work)
4964 struct fw_event_work *fw_event = container_of(work,
4965 struct fw_event_work, work.work);
4966 unsigned long flags;
4967 struct MPT2SAS_ADAPTER *ioc = fw_event->ioc;
4969 /* This is invoked by calling _scsih_queue_rescan(). */
4970 if (fw_event->event == MPT2SAS_RESCAN_AFTER_HOST_RESET) {
4971 _scsih_fw_event_free(ioc, fw_event);
4972 _scsih_sas_host_refresh(ioc, 1);
4973 _scsih_remove_unresponding_devices(ioc);
4977 /* the queue is being flushed so ignore this event */
4978 spin_lock_irqsave(&ioc->fw_event_lock, flags);
4979 if (ioc->fw_events_off || ioc->remove_host) {
4980 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
4981 _scsih_fw_event_free(ioc, fw_event);
4984 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
4986 spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags);
4987 if (ioc->shost_recovery) {
4988 spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags);
4989 _scsih_fw_event_requeue(ioc, fw_event, 1000);
4992 spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags);
4994 switch (fw_event->event) {
4995 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
4996 _scsih_sas_topology_change_event(ioc, fw_event->VF_ID,
4997 fw_event->event_data, fw_event);
4999 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
5000 _scsih_sas_device_status_change_event(ioc, fw_event->VF_ID,
5001 fw_event->event_data);
5003 case MPI2_EVENT_SAS_DISCOVERY:
5004 _scsih_sas_discovery_event(ioc, fw_event->VF_ID,
5005 fw_event->event_data);
5007 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
5008 _scsih_sas_broadcast_primative_event(ioc, fw_event->VF_ID,
5009 fw_event->event_data);
5011 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
5012 _scsih_sas_enclosure_dev_status_change_event(ioc,
5013 fw_event->VF_ID, fw_event->event_data);
5015 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
5016 _scsih_sas_ir_config_change_event(ioc, fw_event->VF_ID,
5017 fw_event->event_data);
5019 case MPI2_EVENT_IR_VOLUME:
5020 _scsih_sas_ir_volume_event(ioc, fw_event->VF_ID,
5021 fw_event->event_data);
5023 case MPI2_EVENT_IR_PHYSICAL_DISK:
5024 _scsih_sas_ir_physical_disk_event(ioc, fw_event->VF_ID,
5025 fw_event->event_data);
5027 case MPI2_EVENT_IR_OPERATION_STATUS:
5028 _scsih_sas_ir_operation_status_event(ioc, fw_event->VF_ID,
5029 fw_event->event_data);
5031 case MPI2_EVENT_TASK_SET_FULL:
5032 _scsih_task_set_full(ioc, fw_event->VF_ID,
5033 fw_event->event_data);
5036 _scsih_fw_event_free(ioc, fw_event);
5040 * mpt2sas_scsih_event_callback - firmware event handler (called at ISR time)
5041 * @ioc: per adapter object
5042 * @VF_ID: virtual function id
5043 * @reply: reply message frame(lower 32bit addr)
5044 * Context: interrupt.
5046 * This function merely adds a new work task into ioc->firmware_event_thread.
5047 * The tasks are worked from _firmware_event_work in user context.
5052 mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER *ioc, u8 VF_ID, u32 reply)
5054 struct fw_event_work *fw_event;
5055 Mpi2EventNotificationReply_t *mpi_reply;
5056 unsigned long flags;
5059 /* events turned off due to host reset or driver unloading */
5060 spin_lock_irqsave(&ioc->fw_event_lock, flags);
5061 if (ioc->fw_events_off || ioc->remove_host) {
5062 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
5065 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
5067 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
5068 event = le16_to_cpu(mpi_reply->Event);
5072 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
5074 Mpi2EventDataSasBroadcastPrimitive_t *baen_data =
5075 (Mpi2EventDataSasBroadcastPrimitive_t *)
5076 mpi_reply->EventData;
5078 if (baen_data->Primitive !=
5079 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT ||
5080 ioc->broadcast_aen_busy)
5082 ioc->broadcast_aen_busy = 1;
5086 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
5087 _scsih_check_topo_delete_events(ioc,
5088 (Mpi2EventDataSasTopologyChangeList_t *)
5089 mpi_reply->EventData);
5092 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
5093 case MPI2_EVENT_IR_OPERATION_STATUS:
5094 case MPI2_EVENT_SAS_DISCOVERY:
5095 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
5096 case MPI2_EVENT_IR_VOLUME:
5097 case MPI2_EVENT_IR_PHYSICAL_DISK:
5098 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
5099 case MPI2_EVENT_TASK_SET_FULL:
5102 default: /* ignore the rest */
5106 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
5108 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5109 ioc->name, __FILE__, __LINE__, __func__);
5112 fw_event->event_data =
5113 kzalloc(mpi_reply->EventDataLength*4, GFP_ATOMIC);
5114 if (!fw_event->event_data) {
5115 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5116 ioc->name, __FILE__, __LINE__, __func__);
5121 memcpy(fw_event->event_data, mpi_reply->EventData,
5122 mpi_reply->EventDataLength*4);
5123 fw_event->ioc = ioc;
5124 fw_event->VF_ID = VF_ID;
5125 fw_event->event = event;
5126 _scsih_fw_event_add(ioc, fw_event);
5129 /* shost template */
5130 static struct scsi_host_template scsih_driver_template = {
5131 .module = THIS_MODULE,
5132 .name = "Fusion MPT SAS Host",
5133 .proc_name = MPT2SAS_DRIVER_NAME,
5134 .queuecommand = scsih_qcmd,
5135 .target_alloc = scsih_target_alloc,
5136 .slave_alloc = scsih_slave_alloc,
5137 .slave_configure = scsih_slave_configure,
5138 .target_destroy = scsih_target_destroy,
5139 .slave_destroy = scsih_slave_destroy,
5140 .change_queue_depth = scsih_change_queue_depth,
5141 .change_queue_type = scsih_change_queue_type,
5142 .eh_abort_handler = scsih_abort,
5143 .eh_device_reset_handler = scsih_dev_reset,
5144 .eh_host_reset_handler = scsih_host_reset,
5145 .bios_param = scsih_bios_param,
5148 .sg_tablesize = MPT2SAS_SG_DEPTH,
5149 .max_sectors = 8192,
5151 .use_clustering = ENABLE_CLUSTERING,
5152 .shost_attrs = mpt2sas_host_attrs,
5153 .sdev_attrs = mpt2sas_dev_attrs,
5157 * _scsih_expander_node_remove - removing expander device from list.
5158 * @ioc: per adapter object
5159 * @sas_expander: the sas_device object
5160 * Context: Calling function should acquire ioc->sas_node_lock.
5162 * Removing object and freeing associated memory from the
5163 * ioc->sas_expander_list.
5168 _scsih_expander_node_remove(struct MPT2SAS_ADAPTER *ioc,
5169 struct _sas_node *sas_expander)
5171 struct _sas_port *mpt2sas_port;
5172 struct _sas_device *sas_device;
5173 struct _sas_node *expander_sibling;
5174 unsigned long flags;
5179 /* remove sibling ports attached to this expander */
5180 retry_device_search:
5181 list_for_each_entry(mpt2sas_port,
5182 &sas_expander->sas_port_list, port_list) {
5183 if (mpt2sas_port->remote_identify.device_type ==
5185 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5187 mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5188 mpt2sas_port->remote_identify.sas_address);
5189 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5192 _scsih_remove_device(ioc, sas_device->handle);
5193 goto retry_device_search;
5197 retry_expander_search:
5198 list_for_each_entry(mpt2sas_port,
5199 &sas_expander->sas_port_list, port_list) {
5201 if (mpt2sas_port->remote_identify.device_type ==
5202 MPI2_SAS_DEVICE_INFO_EDGE_EXPANDER ||
5203 mpt2sas_port->remote_identify.device_type ==
5204 MPI2_SAS_DEVICE_INFO_FANOUT_EXPANDER) {
5206 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5208 mpt2sas_scsih_expander_find_by_sas_address(
5209 ioc, mpt2sas_port->remote_identify.sas_address);
5210 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5211 if (!expander_sibling)
5213 _scsih_expander_remove(ioc, expander_sibling->handle);
5214 goto retry_expander_search;
5218 mpt2sas_transport_port_remove(ioc, sas_expander->sas_address,
5219 sas_expander->parent_handle);
5221 printk(MPT2SAS_INFO_FMT "expander_remove: handle"
5222 "(0x%04x), sas_addr(0x%016llx)\n", ioc->name,
5223 sas_expander->handle, (unsigned long long)
5224 sas_expander->sas_address);
5226 list_del(&sas_expander->list);
5227 kfree(sas_expander->phy);
5228 kfree(sas_expander);
5232 * scsih_remove - detach and remove add host
5233 * @pdev: PCI device struct
5237 static void __devexit
5238 scsih_remove(struct pci_dev *pdev)
5240 struct Scsi_Host *shost = pci_get_drvdata(pdev);
5241 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
5242 struct _sas_port *mpt2sas_port;
5243 struct _sas_device *sas_device;
5244 struct _sas_node *expander_sibling;
5245 struct workqueue_struct *wq;
5246 unsigned long flags;
5248 ioc->remove_host = 1;
5249 _scsih_fw_event_off(ioc);
5251 spin_lock_irqsave(&ioc->fw_event_lock, flags);
5252 wq = ioc->firmware_event_thread;
5253 ioc->firmware_event_thread = NULL;
5254 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
5256 destroy_workqueue(wq);
5258 /* free ports attached to the sas_host */
5260 list_for_each_entry(mpt2sas_port,
5261 &ioc->sas_hba.sas_port_list, port_list) {
5262 if (mpt2sas_port->remote_identify.device_type ==
5265 mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5266 mpt2sas_port->remote_identify.sas_address);
5268 _scsih_remove_device(ioc, sas_device->handle);
5273 mpt2sas_scsih_expander_find_by_sas_address(ioc,
5274 mpt2sas_port->remote_identify.sas_address);
5275 if (expander_sibling) {
5276 _scsih_expander_remove(ioc,
5277 expander_sibling->handle);
5283 /* free phys attached to the sas_host */
5284 if (ioc->sas_hba.num_phys) {
5285 kfree(ioc->sas_hba.phy);
5286 ioc->sas_hba.phy = NULL;
5287 ioc->sas_hba.num_phys = 0;
5290 sas_remove_host(shost);
5291 mpt2sas_base_detach(ioc);
5292 list_del(&ioc->list);
5293 scsi_remove_host(shost);
5294 scsi_host_put(shost);
5298 * _scsih_probe_boot_devices - reports 1st device
5299 * @ioc: per adapter object
5301 * If specified in bios page 2, this routine reports the 1st
5302 * device scsi-ml or sas transport for persistent boot device
5303 * purposes. Please refer to function _scsih_determine_boot_device()
5306 _scsih_probe_boot_devices(struct MPT2SAS_ADAPTER *ioc)
5310 struct _sas_device *sas_device;
5311 struct _raid_device *raid_device;
5312 u16 handle, parent_handle;
5314 unsigned long flags;
5318 if (ioc->req_boot_device.device) {
5319 device = ioc->req_boot_device.device;
5320 is_raid = ioc->req_boot_device.is_raid;
5321 } else if (ioc->req_alt_boot_device.device) {
5322 device = ioc->req_alt_boot_device.device;
5323 is_raid = ioc->req_alt_boot_device.is_raid;
5324 } else if (ioc->current_boot_device.device) {
5325 device = ioc->current_boot_device.device;
5326 is_raid = ioc->current_boot_device.is_raid;
5333 raid_device = device;
5334 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
5335 raid_device->id, 0);
5337 _scsih_raid_device_remove(ioc, raid_device);
5339 sas_device = device;
5340 handle = sas_device->handle;
5341 parent_handle = sas_device->parent_handle;
5342 sas_address = sas_device->sas_address;
5343 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5344 list_move_tail(&sas_device->list, &ioc->sas_device_list);
5345 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5346 if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
5347 sas_device->parent_handle)) {
5348 _scsih_sas_device_remove(ioc, sas_device);
5349 } else if (!sas_device->starget) {
5350 mpt2sas_transport_port_remove(ioc, sas_address,
5352 _scsih_sas_device_remove(ioc, sas_device);
5358 * _scsih_probe_raid - reporting raid volumes to scsi-ml
5359 * @ioc: per adapter object
5361 * Called during initial loading of the driver.
5364 _scsih_probe_raid(struct MPT2SAS_ADAPTER *ioc)
5366 struct _raid_device *raid_device, *raid_next;
5369 list_for_each_entry_safe(raid_device, raid_next,
5370 &ioc->raid_device_list, list) {
5371 if (raid_device->starget)
5373 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
5374 raid_device->id, 0);
5376 _scsih_raid_device_remove(ioc, raid_device);
5381 * _scsih_probe_sas - reporting raid volumes to sas transport
5382 * @ioc: per adapter object
5384 * Called during initial loading of the driver.
5387 _scsih_probe_sas(struct MPT2SAS_ADAPTER *ioc)
5389 struct _sas_device *sas_device, *next;
5390 unsigned long flags;
5391 u16 handle, parent_handle;
5394 /* SAS Device List */
5395 list_for_each_entry_safe(sas_device, next, &ioc->sas_device_init_list,
5397 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5398 list_move_tail(&sas_device->list, &ioc->sas_device_list);
5399 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5401 handle = sas_device->handle;
5402 parent_handle = sas_device->parent_handle;
5403 sas_address = sas_device->sas_address;
5404 if (!mpt2sas_transport_port_add(ioc, handle, parent_handle)) {
5405 _scsih_sas_device_remove(ioc, sas_device);
5406 } else if (!sas_device->starget) {
5407 mpt2sas_transport_port_remove(ioc, sas_address,
5409 _scsih_sas_device_remove(ioc, sas_device);
5415 * _scsih_probe_devices - probing for devices
5416 * @ioc: per adapter object
5418 * Called during initial loading of the driver.
5421 _scsih_probe_devices(struct MPT2SAS_ADAPTER *ioc)
5423 u16 volume_mapping_flags =
5424 le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) &
5425 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE;
5427 if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR))
5428 return; /* return when IOC doesn't support initiator mode */
5430 _scsih_probe_boot_devices(ioc);
5432 if (ioc->ir_firmware) {
5433 if ((volume_mapping_flags &
5434 MPI2_IOCPAGE8_IRFLAGS_HIGH_VOLUME_MAPPING)) {
5435 _scsih_probe_sas(ioc);
5436 _scsih_probe_raid(ioc);
5438 _scsih_probe_raid(ioc);
5439 _scsih_probe_sas(ioc);
5442 _scsih_probe_sas(ioc);
5446 * scsih_probe - attach and add scsi host
5447 * @pdev: PCI device struct
5448 * @id: pci device id
5450 * Returns 0 success, anything else error.
5453 scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id)
5455 struct MPT2SAS_ADAPTER *ioc;
5456 struct Scsi_Host *shost;
5458 shost = scsi_host_alloc(&scsih_driver_template,
5459 sizeof(struct MPT2SAS_ADAPTER));
5463 /* init local params */
5464 ioc = shost_priv(shost);
5465 memset(ioc, 0, sizeof(struct MPT2SAS_ADAPTER));
5466 INIT_LIST_HEAD(&ioc->list);
5467 list_add_tail(&ioc->list, &mpt2sas_ioc_list);
5469 ioc->id = mpt_ids++;
5470 sprintf(ioc->name, "%s%d", MPT2SAS_DRIVER_NAME, ioc->id);
5472 ioc->scsi_io_cb_idx = scsi_io_cb_idx;
5473 ioc->tm_cb_idx = tm_cb_idx;
5474 ioc->ctl_cb_idx = ctl_cb_idx;
5475 ioc->base_cb_idx = base_cb_idx;
5476 ioc->transport_cb_idx = transport_cb_idx;
5477 ioc->config_cb_idx = config_cb_idx;
5478 ioc->logging_level = logging_level;
5479 /* misc semaphores and spin locks */
5480 spin_lock_init(&ioc->ioc_reset_in_progress_lock);
5481 spin_lock_init(&ioc->scsi_lookup_lock);
5482 spin_lock_init(&ioc->sas_device_lock);
5483 spin_lock_init(&ioc->sas_node_lock);
5484 spin_lock_init(&ioc->fw_event_lock);
5485 spin_lock_init(&ioc->raid_device_lock);
5487 INIT_LIST_HEAD(&ioc->sas_device_list);
5488 INIT_LIST_HEAD(&ioc->sas_device_init_list);
5489 INIT_LIST_HEAD(&ioc->sas_expander_list);
5490 INIT_LIST_HEAD(&ioc->fw_event_list);
5491 INIT_LIST_HEAD(&ioc->raid_device_list);
5492 INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list);
5494 /* init shost parameters */
5495 shost->max_cmd_len = 16;
5496 shost->max_lun = max_lun;
5497 shost->transportt = mpt2sas_transport_template;
5498 shost->unique_id = ioc->id;
5500 if ((scsi_add_host(shost, &pdev->dev))) {
5501 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5502 ioc->name, __FILE__, __LINE__, __func__);
5503 list_del(&ioc->list);
5504 goto out_add_shost_fail;
5508 snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name),
5509 "fw_event%d", ioc->id);
5510 ioc->firmware_event_thread = create_singlethread_workqueue(
5511 ioc->firmware_event_name);
5512 if (!ioc->firmware_event_thread) {
5513 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5514 ioc->name, __FILE__, __LINE__, __func__);
5515 goto out_thread_fail;
5518 ioc->wait_for_port_enable_to_complete = 1;
5519 if ((mpt2sas_base_attach(ioc))) {
5520 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5521 ioc->name, __FILE__, __LINE__, __func__);
5522 goto out_attach_fail;
5525 ioc->wait_for_port_enable_to_complete = 0;
5526 _scsih_probe_devices(ioc);
5530 destroy_workqueue(ioc->firmware_event_thread);
5532 list_del(&ioc->list);
5533 scsi_remove_host(shost);
5540 * scsih_suspend - power management suspend main entry point
5541 * @pdev: PCI device struct
5542 * @state: PM state change to (usually PCI_D3)
5544 * Returns 0 success, anything else error.
5547 scsih_suspend(struct pci_dev *pdev, pm_message_t state)
5549 struct Scsi_Host *shost = pci_get_drvdata(pdev);
5550 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
5553 flush_scheduled_work();
5554 scsi_block_requests(shost);
5555 device_state = pci_choose_state(pdev, state);
5556 printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, entering "
5557 "operating state [D%d]\n", ioc->name, pdev,
5558 pci_name(pdev), device_state);
5560 mpt2sas_base_free_resources(ioc);
5561 pci_save_state(pdev);
5562 pci_disable_device(pdev);
5563 pci_set_power_state(pdev, device_state);
5568 * scsih_resume - power management resume main entry point
5569 * @pdev: PCI device struct
5571 * Returns 0 success, anything else error.
5574 scsih_resume(struct pci_dev *pdev)
5576 struct Scsi_Host *shost = pci_get_drvdata(pdev);
5577 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
5578 u32 device_state = pdev->current_state;
5581 printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, previous "
5582 "operating state [D%d]\n", ioc->name, pdev,
5583 pci_name(pdev), device_state);
5585 pci_set_power_state(pdev, PCI_D0);
5586 pci_enable_wake(pdev, PCI_D0, 0);
5587 pci_restore_state(pdev);
5589 r = mpt2sas_base_map_resources(ioc);
5593 mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, SOFT_RESET);
5594 scsi_unblock_requests(shost);
5597 #endif /* CONFIG_PM */
5600 static struct pci_driver scsih_driver = {
5601 .name = MPT2SAS_DRIVER_NAME,
5602 .id_table = scsih_pci_table,
5603 .probe = scsih_probe,
5604 .remove = __devexit_p(scsih_remove),
5606 .suspend = scsih_suspend,
5607 .resume = scsih_resume,
5613 * scsih_init - main entry point for this driver.
5615 * Returns 0 success, anything else error.
5623 printk(KERN_INFO "%s version %s loaded\n", MPT2SAS_DRIVER_NAME,
5624 MPT2SAS_DRIVER_VERSION);
5626 mpt2sas_transport_template =
5627 sas_attach_transport(&mpt2sas_transport_functions);
5628 if (!mpt2sas_transport_template)
5631 mpt2sas_base_initialize_callback_handler();
5633 /* queuecommand callback hander */
5634 scsi_io_cb_idx = mpt2sas_base_register_callback_handler(scsih_io_done);
5636 /* task managment callback handler */
5637 tm_cb_idx = mpt2sas_base_register_callback_handler(scsih_tm_done);
5639 /* base internal commands callback handler */
5640 base_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_base_done);
5642 /* transport internal commands callback handler */
5643 transport_cb_idx = mpt2sas_base_register_callback_handler(
5644 mpt2sas_transport_done);
5646 /* configuration page API internal commands callback handler */
5647 config_cb_idx = mpt2sas_base_register_callback_handler(
5648 mpt2sas_config_done);
5650 /* ctl module callback handler */
5651 ctl_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_ctl_done);
5655 error = pci_register_driver(&scsih_driver);
5657 sas_release_transport(mpt2sas_transport_template);
5663 * scsih_exit - exit point for this driver (when it is a module).
5665 * Returns 0 success, anything else error.
5670 printk(KERN_INFO "mpt2sas version %s unloading\n",
5671 MPT2SAS_DRIVER_VERSION);
5673 pci_unregister_driver(&scsih_driver);
5675 sas_release_transport(mpt2sas_transport_template);
5676 mpt2sas_base_release_callback_handler(scsi_io_cb_idx);
5677 mpt2sas_base_release_callback_handler(tm_cb_idx);
5678 mpt2sas_base_release_callback_handler(base_cb_idx);
5679 mpt2sas_base_release_callback_handler(transport_cb_idx);
5680 mpt2sas_base_release_callback_handler(config_cb_idx);
5681 mpt2sas_base_release_callback_handler(ctl_cb_idx);
5686 module_init(scsih_init);
5687 module_exit(scsih_exit);