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 work_struct 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);
524 * _scsih_sas_device_init_add - insert sas_device to the list.
525 * @ioc: per adapter object
526 * @sas_device: the sas_device object
527 * Context: This function will acquire ioc->sas_device_lock.
529 * Adding new object at driver load time to the ioc->sas_device_init_list.
532 _scsih_sas_device_init_add(struct MPT2SAS_ADAPTER *ioc,
533 struct _sas_device *sas_device)
537 dewtprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: handle"
538 "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
539 sas_device->handle, (unsigned long long)sas_device->sas_address));
541 spin_lock_irqsave(&ioc->sas_device_lock, flags);
542 list_add_tail(&sas_device->list, &ioc->sas_device_init_list);
543 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
544 _scsih_determine_boot_device(ioc, sas_device, 0);
548 * mpt2sas_scsih_expander_find_by_handle - expander device search
549 * @ioc: per adapter object
550 * @handle: expander handle (assigned by firmware)
551 * Context: Calling function should acquire ioc->sas_device_lock
553 * This searches for expander device based on handle, then returns the
557 mpt2sas_scsih_expander_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
559 struct _sas_node *sas_expander, *r;
562 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
563 if (sas_expander->handle != handle)
573 * _scsih_raid_device_find_by_id - raid device search
574 * @ioc: per adapter object
575 * @id: sas device target id
576 * @channel: sas device channel
577 * Context: Calling function should acquire ioc->raid_device_lock
579 * This searches for raid_device based on target id, then return raid_device
582 static struct _raid_device *
583 _scsih_raid_device_find_by_id(struct MPT2SAS_ADAPTER *ioc, int id, int channel)
585 struct _raid_device *raid_device, *r;
588 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
589 if (raid_device->id == id && raid_device->channel == channel) {
600 * _scsih_raid_device_find_by_handle - raid device search
601 * @ioc: per adapter object
602 * @handle: sas device handle (assigned by firmware)
603 * Context: Calling function should acquire ioc->raid_device_lock
605 * This searches for raid_device based on handle, then return raid_device
608 static struct _raid_device *
609 _scsih_raid_device_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
611 struct _raid_device *raid_device, *r;
614 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
615 if (raid_device->handle != handle)
626 * _scsih_raid_device_find_by_wwid - raid device search
627 * @ioc: per adapter object
628 * @handle: sas device handle (assigned by firmware)
629 * Context: Calling function should acquire ioc->raid_device_lock
631 * This searches for raid_device based on wwid, then return raid_device
634 static struct _raid_device *
635 _scsih_raid_device_find_by_wwid(struct MPT2SAS_ADAPTER *ioc, u64 wwid)
637 struct _raid_device *raid_device, *r;
640 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
641 if (raid_device->wwid != wwid)
652 * _scsih_raid_device_add - add raid_device object
653 * @ioc: per adapter object
654 * @raid_device: raid_device object
656 * This is added to the raid_device_list link list.
659 _scsih_raid_device_add(struct MPT2SAS_ADAPTER *ioc,
660 struct _raid_device *raid_device)
664 dewtprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: handle"
665 "(0x%04x), wwid(0x%016llx)\n", ioc->name, __func__,
666 raid_device->handle, (unsigned long long)raid_device->wwid));
668 spin_lock_irqsave(&ioc->raid_device_lock, flags);
669 list_add_tail(&raid_device->list, &ioc->raid_device_list);
670 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
674 * _scsih_raid_device_remove - delete raid_device object
675 * @ioc: per adapter object
676 * @raid_device: raid_device object
678 * This is removed from the raid_device_list link list.
681 _scsih_raid_device_remove(struct MPT2SAS_ADAPTER *ioc,
682 struct _raid_device *raid_device)
686 spin_lock_irqsave(&ioc->raid_device_lock, flags);
687 list_del(&raid_device->list);
688 memset(raid_device, 0, sizeof(struct _raid_device));
690 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
694 * mpt2sas_scsih_expander_find_by_sas_address - expander device search
695 * @ioc: per adapter object
696 * @sas_address: sas address
697 * Context: Calling function should acquire ioc->sas_node_lock.
699 * This searches for expander device based on sas_address, then returns the
703 mpt2sas_scsih_expander_find_by_sas_address(struct MPT2SAS_ADAPTER *ioc,
706 struct _sas_node *sas_expander, *r;
709 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
710 if (sas_expander->sas_address != sas_address)
720 * _scsih_expander_node_add - insert expander device to the list.
721 * @ioc: per adapter object
722 * @sas_expander: the sas_device object
723 * Context: This function will acquire ioc->sas_node_lock.
725 * Adding new object to the ioc->sas_expander_list.
730 _scsih_expander_node_add(struct MPT2SAS_ADAPTER *ioc,
731 struct _sas_node *sas_expander)
735 spin_lock_irqsave(&ioc->sas_node_lock, flags);
736 list_add_tail(&sas_expander->list, &ioc->sas_expander_list);
737 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
741 * _scsih_is_end_device - determines if device is an end device
742 * @device_info: bitfield providing information about the device.
745 * Returns 1 if end device.
748 _scsih_is_end_device(u32 device_info)
750 if (device_info & MPI2_SAS_DEVICE_INFO_END_DEVICE &&
751 ((device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) |
752 (device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) |
753 (device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE)))
760 * _scsih_scsi_lookup_get - returns scmd entry
761 * @ioc: per adapter object
762 * @smid: system request message index
763 * Context: This function will acquire ioc->scsi_lookup_lock.
765 * Returns the smid stored scmd pointer.
767 static struct scsi_cmnd *
768 _scsih_scsi_lookup_get(struct MPT2SAS_ADAPTER *ioc, u16 smid)
771 struct scsi_cmnd *scmd;
773 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
774 scmd = ioc->scsi_lookup[smid - 1].scmd;
775 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
780 * mptscsih_getclear_scsi_lookup - returns scmd entry
781 * @ioc: per adapter object
782 * @smid: system request message index
783 * Context: This function will acquire ioc->scsi_lookup_lock.
785 * Returns the smid stored scmd pointer, as well as clearing the scmd pointer.
787 static struct scsi_cmnd *
788 _scsih_scsi_lookup_getclear(struct MPT2SAS_ADAPTER *ioc, u16 smid)
791 struct scsi_cmnd *scmd;
793 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
794 scmd = ioc->scsi_lookup[smid - 1].scmd;
795 ioc->scsi_lookup[smid - 1].scmd = NULL;
796 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
801 * _scsih_scsi_lookup_set - updates scmd entry in lookup
802 * @ioc: per adapter object
803 * @smid: system request message index
804 * @scmd: pointer to scsi command object
805 * Context: This function will acquire ioc->scsi_lookup_lock.
807 * This will save scmd pointer in the scsi_lookup array.
812 _scsih_scsi_lookup_set(struct MPT2SAS_ADAPTER *ioc, u16 smid,
813 struct scsi_cmnd *scmd)
817 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
818 ioc->scsi_lookup[smid - 1].scmd = scmd;
819 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
823 * _scsih_scsi_lookup_find_by_scmd - scmd lookup
824 * @ioc: per adapter object
825 * @smid: system request message index
826 * @scmd: pointer to scsi command object
827 * Context: This function will acquire ioc->scsi_lookup_lock.
829 * This will search for a scmd pointer in the scsi_lookup array,
830 * returning the revelent smid. A returned value of zero means invalid.
833 _scsih_scsi_lookup_find_by_scmd(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd
840 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
842 for (i = 0; i < ioc->request_depth; i++) {
843 if (ioc->scsi_lookup[i].scmd == scmd) {
849 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
854 * _scsih_scsi_lookup_find_by_target - search for matching channel:id
855 * @ioc: per adapter object
858 * Context: This function will acquire ioc->scsi_lookup_lock.
860 * This will search for a matching channel:id in the scsi_lookup array,
861 * returning 1 if found.
864 _scsih_scsi_lookup_find_by_target(struct MPT2SAS_ADAPTER *ioc, int id,
871 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
873 for (i = 0 ; i < ioc->request_depth; i++) {
874 if (ioc->scsi_lookup[i].scmd &&
875 (ioc->scsi_lookup[i].scmd->device->id == id &&
876 ioc->scsi_lookup[i].scmd->device->channel == channel)) {
882 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
887 * _scsih_get_chain_buffer_dma - obtain block of chains (dma address)
888 * @ioc: per adapter object
889 * @smid: system request message index
891 * Returns phys pointer to chain buffer.
894 _scsih_get_chain_buffer_dma(struct MPT2SAS_ADAPTER *ioc, u16 smid)
896 return ioc->chain_dma + ((smid - 1) * (ioc->request_sz *
897 ioc->chains_needed_per_io));
901 * _scsih_get_chain_buffer - obtain block of chains assigned to a mf request
902 * @ioc: per adapter object
903 * @smid: system request message index
905 * Returns virt pointer to chain buffer.
908 _scsih_get_chain_buffer(struct MPT2SAS_ADAPTER *ioc, u16 smid)
910 return (void *)(ioc->chain + ((smid - 1) * (ioc->request_sz *
911 ioc->chains_needed_per_io)));
915 * _scsih_build_scatter_gather - main sg creation routine
916 * @ioc: per adapter object
917 * @scmd: scsi command
918 * @smid: system request message index
921 * The main routine that builds scatter gather table from a given
922 * scsi request sent via the .queuecommand main handler.
924 * Returns 0 success, anything else error
927 _scsih_build_scatter_gather(struct MPT2SAS_ADAPTER *ioc,
928 struct scsi_cmnd *scmd, u16 smid)
930 Mpi2SCSIIORequest_t *mpi_request;
931 dma_addr_t chain_dma;
932 struct scatterlist *sg_scmd;
933 void *sg_local, *chain;
940 u32 sgl_flags_last_element;
941 u32 sgl_flags_end_buffer;
943 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
945 /* init scatter gather flags */
946 sgl_flags = MPI2_SGE_FLAGS_SIMPLE_ELEMENT;
947 if (scmd->sc_data_direction == DMA_TO_DEVICE)
948 sgl_flags |= MPI2_SGE_FLAGS_HOST_TO_IOC;
949 sgl_flags_last_element = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT)
950 << MPI2_SGE_FLAGS_SHIFT;
951 sgl_flags_end_buffer = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT |
952 MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_END_OF_LIST)
953 << MPI2_SGE_FLAGS_SHIFT;
954 sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT;
956 sg_scmd = scsi_sglist(scmd);
957 sges_left = scsi_dma_map(scmd);
959 sdev_printk(KERN_ERR, scmd->device, "pci_map_sg"
960 " failed: request for %d bytes!\n", scsi_bufflen(scmd));
964 sg_local = &mpi_request->SGL;
965 sges_in_segment = ioc->max_sges_in_main_message;
966 if (sges_left <= sges_in_segment)
967 goto fill_in_last_segment;
969 mpi_request->ChainOffset = (offsetof(Mpi2SCSIIORequest_t, SGL) +
970 (sges_in_segment * ioc->sge_size))/4;
972 /* fill in main message segment when there is a chain following */
973 while (sges_in_segment) {
974 if (sges_in_segment == 1)
975 ioc->base_add_sg_single(sg_local,
976 sgl_flags_last_element | sg_dma_len(sg_scmd),
977 sg_dma_address(sg_scmd));
979 ioc->base_add_sg_single(sg_local, sgl_flags |
980 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
981 sg_scmd = sg_next(sg_scmd);
982 sg_local += ioc->sge_size;
987 /* initializing the chain flags and pointers */
988 chain_flags = MPI2_SGE_FLAGS_CHAIN_ELEMENT << MPI2_SGE_FLAGS_SHIFT;
989 chain = _scsih_get_chain_buffer(ioc, smid);
990 chain_dma = _scsih_get_chain_buffer_dma(ioc, smid);
992 sges_in_segment = (sges_left <=
993 ioc->max_sges_in_chain_message) ? sges_left :
994 ioc->max_sges_in_chain_message;
995 chain_offset = (sges_left == sges_in_segment) ?
996 0 : (sges_in_segment * ioc->sge_size)/4;
997 chain_length = sges_in_segment * ioc->sge_size;
999 chain_offset = chain_offset <<
1000 MPI2_SGE_CHAIN_OFFSET_SHIFT;
1001 chain_length += ioc->sge_size;
1003 ioc->base_add_sg_single(sg_local, chain_flags | chain_offset |
1004 chain_length, chain_dma);
1007 goto fill_in_last_segment;
1009 /* fill in chain segments */
1010 while (sges_in_segment) {
1011 if (sges_in_segment == 1)
1012 ioc->base_add_sg_single(sg_local,
1013 sgl_flags_last_element |
1014 sg_dma_len(sg_scmd),
1015 sg_dma_address(sg_scmd));
1017 ioc->base_add_sg_single(sg_local, sgl_flags |
1018 sg_dma_len(sg_scmd),
1019 sg_dma_address(sg_scmd));
1020 sg_scmd = sg_next(sg_scmd);
1021 sg_local += ioc->sge_size;
1026 chain_dma += ioc->request_sz;
1027 chain += ioc->request_sz;
1031 fill_in_last_segment:
1033 /* fill the last segment */
1036 ioc->base_add_sg_single(sg_local, sgl_flags_end_buffer |
1037 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
1039 ioc->base_add_sg_single(sg_local, sgl_flags |
1040 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
1041 sg_scmd = sg_next(sg_scmd);
1042 sg_local += ioc->sge_size;
1050 * scsih_change_queue_depth - setting device queue depth
1051 * @sdev: scsi device struct
1052 * @qdepth: requested queue depth
1054 * Returns queue depth.
1057 scsih_change_queue_depth(struct scsi_device *sdev, int qdepth)
1059 struct Scsi_Host *shost = sdev->host;
1063 max_depth = shost->can_queue;
1064 if (!sdev->tagged_supported)
1066 if (qdepth > max_depth)
1068 tag_type = (qdepth == 1) ? 0 : MSG_SIMPLE_TAG;
1069 scsi_adjust_queue_depth(sdev, tag_type, qdepth);
1071 if (sdev->inquiry_len > 7)
1072 sdev_printk(KERN_INFO, sdev, "qdepth(%d), tagged(%d), "
1073 "simple(%d), ordered(%d), scsi_level(%d), cmd_que(%d)\n",
1074 sdev->queue_depth, sdev->tagged_supported, sdev->simple_tags,
1075 sdev->ordered_tags, sdev->scsi_level,
1076 (sdev->inquiry[7] & 2) >> 1);
1078 return sdev->queue_depth;
1082 * scsih_change_queue_depth - changing device queue tag type
1083 * @sdev: scsi device struct
1084 * @tag_type: requested tag type
1086 * Returns queue tag type.
1089 scsih_change_queue_type(struct scsi_device *sdev, int tag_type)
1091 if (sdev->tagged_supported) {
1092 scsi_set_tag_type(sdev, tag_type);
1094 scsi_activate_tcq(sdev, sdev->queue_depth);
1096 scsi_deactivate_tcq(sdev, sdev->queue_depth);
1104 * scsih_target_alloc - target add routine
1105 * @starget: scsi target struct
1107 * Returns 0 if ok. Any other return is assumed to be an error and
1108 * the device is ignored.
1111 scsih_target_alloc(struct scsi_target *starget)
1113 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1114 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1115 struct MPT2SAS_TARGET *sas_target_priv_data;
1116 struct _sas_device *sas_device;
1117 struct _raid_device *raid_device;
1118 unsigned long flags;
1119 struct sas_rphy *rphy;
1121 sas_target_priv_data = kzalloc(sizeof(struct scsi_target), GFP_KERNEL);
1122 if (!sas_target_priv_data)
1125 starget->hostdata = sas_target_priv_data;
1126 sas_target_priv_data->starget = starget;
1127 sas_target_priv_data->handle = MPT2SAS_INVALID_DEVICE_HANDLE;
1130 if (starget->channel == RAID_CHANNEL) {
1131 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1132 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1135 sas_target_priv_data->handle = raid_device->handle;
1136 sas_target_priv_data->sas_address = raid_device->wwid;
1137 sas_target_priv_data->flags |= MPT_TARGET_FLAGS_VOLUME;
1138 raid_device->starget = starget;
1140 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1144 /* sas/sata devices */
1145 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1146 rphy = dev_to_rphy(starget->dev.parent);
1147 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1148 rphy->identify.sas_address);
1151 sas_target_priv_data->handle = sas_device->handle;
1152 sas_target_priv_data->sas_address = sas_device->sas_address;
1153 sas_device->starget = starget;
1154 sas_device->id = starget->id;
1155 sas_device->channel = starget->channel;
1156 if (sas_device->hidden_raid_component)
1157 sas_target_priv_data->flags |=
1158 MPT_TARGET_FLAGS_RAID_COMPONENT;
1160 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1166 * scsih_target_destroy - target destroy routine
1167 * @starget: scsi target struct
1172 scsih_target_destroy(struct scsi_target *starget)
1174 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1175 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1176 struct MPT2SAS_TARGET *sas_target_priv_data;
1177 struct _sas_device *sas_device;
1178 struct _raid_device *raid_device;
1179 unsigned long flags;
1180 struct sas_rphy *rphy;
1182 sas_target_priv_data = starget->hostdata;
1183 if (!sas_target_priv_data)
1186 if (starget->channel == RAID_CHANNEL) {
1187 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1188 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1191 raid_device->starget = NULL;
1192 raid_device->sdev = NULL;
1194 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1198 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1199 rphy = dev_to_rphy(starget->dev.parent);
1200 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1201 rphy->identify.sas_address);
1202 if (sas_device && (sas_device->starget == starget) &&
1203 (sas_device->id == starget->id) &&
1204 (sas_device->channel == starget->channel))
1205 sas_device->starget = NULL;
1207 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1210 kfree(sas_target_priv_data);
1211 starget->hostdata = NULL;
1215 * scsih_slave_alloc - device add routine
1216 * @sdev: scsi device struct
1218 * Returns 0 if ok. Any other return is assumed to be an error and
1219 * the device is ignored.
1222 scsih_slave_alloc(struct scsi_device *sdev)
1224 struct Scsi_Host *shost;
1225 struct MPT2SAS_ADAPTER *ioc;
1226 struct MPT2SAS_TARGET *sas_target_priv_data;
1227 struct MPT2SAS_DEVICE *sas_device_priv_data;
1228 struct scsi_target *starget;
1229 struct _raid_device *raid_device;
1230 struct _sas_device *sas_device;
1231 unsigned long flags;
1233 sas_device_priv_data = kzalloc(sizeof(struct scsi_device), GFP_KERNEL);
1234 if (!sas_device_priv_data)
1237 sas_device_priv_data->lun = sdev->lun;
1238 sas_device_priv_data->flags = MPT_DEVICE_FLAGS_INIT;
1240 starget = scsi_target(sdev);
1241 sas_target_priv_data = starget->hostdata;
1242 sas_target_priv_data->num_luns++;
1243 sas_device_priv_data->sas_target = sas_target_priv_data;
1244 sdev->hostdata = sas_device_priv_data;
1245 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT))
1246 sdev->no_uld_attach = 1;
1248 shost = dev_to_shost(&starget->dev);
1249 ioc = shost_priv(shost);
1250 if (starget->channel == RAID_CHANNEL) {
1251 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1252 raid_device = _scsih_raid_device_find_by_id(ioc,
1253 starget->id, starget->channel);
1255 raid_device->sdev = sdev; /* raid is single lun */
1256 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1258 /* set TLR bit for SSP devices */
1259 if (!(ioc->facts.IOCCapabilities &
1260 MPI2_IOCFACTS_CAPABILITY_TLR))
1262 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1263 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1264 sas_device_priv_data->sas_target->sas_address);
1265 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1266 if (sas_device && sas_device->device_info &
1267 MPI2_SAS_DEVICE_INFO_SSP_TARGET)
1268 sas_device_priv_data->flags |= MPT_DEVICE_TLR_ON;
1276 * scsih_slave_destroy - device destroy routine
1277 * @sdev: scsi device struct
1282 scsih_slave_destroy(struct scsi_device *sdev)
1284 struct MPT2SAS_TARGET *sas_target_priv_data;
1285 struct scsi_target *starget;
1287 if (!sdev->hostdata)
1290 starget = scsi_target(sdev);
1291 sas_target_priv_data = starget->hostdata;
1292 sas_target_priv_data->num_luns--;
1293 kfree(sdev->hostdata);
1294 sdev->hostdata = NULL;
1298 * scsih_display_sata_capabilities - sata capabilities
1299 * @ioc: per adapter object
1300 * @sas_device: the sas_device object
1301 * @sdev: scsi device struct
1304 scsih_display_sata_capabilities(struct MPT2SAS_ADAPTER *ioc,
1305 struct _sas_device *sas_device, struct scsi_device *sdev)
1307 Mpi2ConfigReply_t mpi_reply;
1308 Mpi2SasDevicePage0_t sas_device_pg0;
1313 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
1314 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, sas_device->handle))) {
1315 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1316 ioc->name, __FILE__, __LINE__, __func__);
1320 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1321 MPI2_IOCSTATUS_MASK;
1322 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
1323 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1324 ioc->name, __FILE__, __LINE__, __func__);
1328 flags = le16_to_cpu(sas_device_pg0.Flags);
1329 device_info = le16_to_cpu(sas_device_pg0.DeviceInfo);
1331 sdev_printk(KERN_INFO, sdev,
1332 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1333 "sw_preserve(%s)\n",
1334 (device_info & MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE) ? "y" : "n",
1335 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED) ? "y" : "n",
1336 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY) ? "y" :
1338 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED) ? "y" : "n",
1339 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED) ? "y" : "n",
1340 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE) ? "y" : "n");
1344 * _scsih_get_volume_capabilities - volume capabilities
1345 * @ioc: per adapter object
1346 * @sas_device: the raid_device object
1349 _scsih_get_volume_capabilities(struct MPT2SAS_ADAPTER *ioc,
1350 struct _raid_device *raid_device)
1352 Mpi2RaidVolPage0_t *vol_pg0;
1353 Mpi2RaidPhysDiskPage0_t pd_pg0;
1354 Mpi2SasDevicePage0_t sas_device_pg0;
1355 Mpi2ConfigReply_t mpi_reply;
1359 if ((mpt2sas_config_get_number_pds(ioc, raid_device->handle,
1360 &num_pds)) || !num_pds) {
1361 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1362 ioc->name, __FILE__, __LINE__, __func__);
1366 raid_device->num_pds = num_pds;
1367 sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
1368 sizeof(Mpi2RaidVol0PhysDisk_t));
1369 vol_pg0 = kzalloc(sz, GFP_KERNEL);
1371 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1372 ioc->name, __FILE__, __LINE__, __func__);
1376 if ((mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
1377 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
1378 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1379 ioc->name, __FILE__, __LINE__, __func__);
1384 raid_device->volume_type = vol_pg0->VolumeType;
1386 /* figure out what the underlying devices are by
1387 * obtaining the device_info bits for the 1st device
1389 if (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
1390 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
1391 vol_pg0->PhysDisk[0].PhysDiskNum))) {
1392 if (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
1393 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
1394 le16_to_cpu(pd_pg0.DevHandle)))) {
1395 raid_device->device_info =
1396 le32_to_cpu(sas_device_pg0.DeviceInfo);
1404 * scsih_slave_configure - device configure routine.
1405 * @sdev: scsi device struct
1407 * Returns 0 if ok. Any other return is assumed to be an error and
1408 * the device is ignored.
1411 scsih_slave_configure(struct scsi_device *sdev)
1413 struct Scsi_Host *shost = sdev->host;
1414 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1415 struct MPT2SAS_DEVICE *sas_device_priv_data;
1416 struct MPT2SAS_TARGET *sas_target_priv_data;
1417 struct _sas_device *sas_device;
1418 struct _raid_device *raid_device;
1419 unsigned long flags;
1426 sas_device_priv_data = sdev->hostdata;
1427 sas_device_priv_data->configured_lun = 1;
1428 sas_device_priv_data->flags &= ~MPT_DEVICE_FLAGS_INIT;
1429 sas_target_priv_data = sas_device_priv_data->sas_target;
1431 /* raid volume handling */
1432 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME) {
1434 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1435 raid_device = _scsih_raid_device_find_by_handle(ioc,
1436 sas_target_priv_data->handle);
1437 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1439 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1440 ioc->name, __FILE__, __LINE__, __func__);
1444 _scsih_get_volume_capabilities(ioc, raid_device);
1446 /* RAID Queue Depth Support
1447 * IS volume = underlying qdepth of drive type, either
1448 * MPT2SAS_SAS_QUEUE_DEPTH or MPT2SAS_SATA_QUEUE_DEPTH
1449 * IM/IME/R10 = 128 (MPT2SAS_RAID_QUEUE_DEPTH)
1451 if (raid_device->device_info &
1452 MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
1453 qdepth = MPT2SAS_SAS_QUEUE_DEPTH;
1456 qdepth = MPT2SAS_SATA_QUEUE_DEPTH;
1457 if (raid_device->device_info &
1458 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1464 switch (raid_device->volume_type) {
1465 case MPI2_RAID_VOL_TYPE_RAID0:
1468 case MPI2_RAID_VOL_TYPE_RAID1E:
1469 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
1472 case MPI2_RAID_VOL_TYPE_RAID1:
1473 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
1476 case MPI2_RAID_VOL_TYPE_RAID10:
1477 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
1480 case MPI2_RAID_VOL_TYPE_UNKNOWN:
1482 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
1487 sdev_printk(KERN_INFO, sdev, "%s: "
1488 "handle(0x%04x), wwid(0x%016llx), pd_count(%d), type(%s)\n",
1489 r_level, raid_device->handle,
1490 (unsigned long long)raid_device->wwid,
1491 raid_device->num_pds, ds);
1492 scsih_change_queue_depth(sdev, qdepth);
1496 /* non-raid handling */
1497 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1498 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1499 sas_device_priv_data->sas_target->sas_address);
1500 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1502 if (sas_target_priv_data->flags &
1503 MPT_TARGET_FLAGS_RAID_COMPONENT) {
1504 mpt2sas_config_get_volume_handle(ioc,
1505 sas_device->handle, &sas_device->volume_handle);
1506 mpt2sas_config_get_volume_wwid(ioc,
1507 sas_device->volume_handle,
1508 &sas_device->volume_wwid);
1510 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
1511 qdepth = MPT2SAS_SAS_QUEUE_DEPTH;
1515 qdepth = MPT2SAS_SATA_QUEUE_DEPTH;
1516 if (sas_device->device_info &
1517 MPI2_SAS_DEVICE_INFO_STP_TARGET)
1519 else if (sas_device->device_info &
1520 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1524 sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), "
1525 "sas_addr(0x%016llx), device_name(0x%016llx)\n",
1526 ds, sas_device->handle,
1527 (unsigned long long)sas_device->sas_address,
1528 (unsigned long long)sas_device->device_name);
1529 sdev_printk(KERN_INFO, sdev, "%s: "
1530 "enclosure_logical_id(0x%016llx), slot(%d)\n", ds,
1531 (unsigned long long) sas_device->enclosure_logical_id,
1535 scsih_display_sata_capabilities(ioc, sas_device, sdev);
1538 scsih_change_queue_depth(sdev, qdepth);
1541 sas_read_port_mode_page(sdev);
1546 * scsih_bios_param - fetch head, sector, cylinder info for a disk
1547 * @sdev: scsi device struct
1548 * @bdev: pointer to block device context
1549 * @capacity: device size (in 512 byte sectors)
1550 * @params: three element array to place output:
1551 * params[0] number of heads (max 255)
1552 * params[1] number of sectors (max 63)
1553 * params[2] number of cylinders
1558 scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev,
1559 sector_t capacity, int params[])
1569 dummy = heads * sectors;
1570 cylinders = capacity;
1571 sector_div(cylinders, dummy);
1574 * Handle extended translation size for logical drives
1577 if ((ulong)capacity >= 0x200000) {
1580 dummy = heads * sectors;
1581 cylinders = capacity;
1582 sector_div(cylinders, dummy);
1587 params[1] = sectors;
1588 params[2] = cylinders;
1594 * _scsih_response_code - translation of device response code
1595 * @ioc: per adapter object
1596 * @response_code: response code returned by the device
1601 _scsih_response_code(struct MPT2SAS_ADAPTER *ioc, u8 response_code)
1605 switch (response_code) {
1606 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE:
1607 desc = "task management request completed";
1609 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME:
1610 desc = "invalid frame";
1612 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED:
1613 desc = "task management request not supported";
1615 case MPI2_SCSITASKMGMT_RSP_TM_FAILED:
1616 desc = "task management request failed";
1618 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED:
1619 desc = "task management request succeeded";
1621 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN:
1622 desc = "invalid lun";
1625 desc = "overlapped tag attempted";
1627 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC:
1628 desc = "task queued, however not sent to target";
1634 printk(MPT2SAS_WARN_FMT "response_code(0x%01x): %s\n",
1635 ioc->name, response_code, desc);
1639 * scsih_tm_done - tm completion routine
1640 * @ioc: per adapter object
1641 * @smid: system request message index
1642 * @VF_ID: virtual function id
1643 * @reply: reply message frame(lower 32bit addr)
1646 * The callback handler when using scsih_issue_tm.
1651 scsih_tm_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 VF_ID, u32 reply)
1653 MPI2DefaultReply_t *mpi_reply;
1655 if (ioc->tm_cmds.status == MPT2_CMD_NOT_USED)
1657 if (ioc->tm_cmds.smid != smid)
1659 ioc->tm_cmds.status |= MPT2_CMD_COMPLETE;
1660 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
1662 memcpy(ioc->tm_cmds.reply, mpi_reply, mpi_reply->MsgLength*4);
1663 ioc->tm_cmds.status |= MPT2_CMD_REPLY_VALID;
1665 ioc->tm_cmds.status &= ~MPT2_CMD_PENDING;
1666 complete(&ioc->tm_cmds.done);
1670 * mpt2sas_scsih_set_tm_flag - set per target tm_busy
1671 * @ioc: per adapter object
1672 * @handle: device handle
1674 * During taskmangement request, we need to freeze the device queue.
1677 mpt2sas_scsih_set_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
1679 struct MPT2SAS_DEVICE *sas_device_priv_data;
1680 struct scsi_device *sdev;
1683 shost_for_each_device(sdev, ioc->shost) {
1686 sas_device_priv_data = sdev->hostdata;
1687 if (!sas_device_priv_data)
1689 if (sas_device_priv_data->sas_target->handle == handle) {
1690 sas_device_priv_data->sas_target->tm_busy = 1;
1692 ioc->ignore_loginfos = 1;
1698 * mpt2sas_scsih_clear_tm_flag - clear per target tm_busy
1699 * @ioc: per adapter object
1700 * @handle: device handle
1702 * During taskmangement request, we need to freeze the device queue.
1705 mpt2sas_scsih_clear_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
1707 struct MPT2SAS_DEVICE *sas_device_priv_data;
1708 struct scsi_device *sdev;
1711 shost_for_each_device(sdev, ioc->shost) {
1714 sas_device_priv_data = sdev->hostdata;
1715 if (!sas_device_priv_data)
1717 if (sas_device_priv_data->sas_target->handle == handle) {
1718 sas_device_priv_data->sas_target->tm_busy = 0;
1720 ioc->ignore_loginfos = 0;
1726 * mpt2sas_scsih_issue_tm - main routine for sending tm requests
1727 * @ioc: per adapter struct
1728 * @device_handle: device handle
1730 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
1731 * @smid_task: smid assigned to the task
1732 * @timeout: timeout in seconds
1733 * Context: The calling function needs to acquire the tm_cmds.mutex
1735 * A generic API for sending task management requests to firmware.
1737 * The ioc->tm_cmds.status flag should be MPT2_CMD_NOT_USED before calling
1740 * The callback index is set inside `ioc->tm_cb_idx`.
1745 mpt2sas_scsih_issue_tm(struct MPT2SAS_ADAPTER *ioc, u16 handle, uint lun,
1746 u8 type, u16 smid_task, ulong timeout)
1748 Mpi2SCSITaskManagementRequest_t *mpi_request;
1749 Mpi2SCSITaskManagementReply_t *mpi_reply;
1752 unsigned long timeleft;
1754 unsigned long flags;
1756 spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags);
1757 if (ioc->tm_cmds.status != MPT2_CMD_NOT_USED ||
1758 ioc->shost_recovery) {
1759 spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags);
1760 printk(MPT2SAS_INFO_FMT "%s: host reset in progress!\n",
1761 __func__, ioc->name);
1764 spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags);
1766 ioc_state = mpt2sas_base_get_iocstate(ioc, 0);
1767 if (ioc_state & MPI2_DOORBELL_USED) {
1768 dhsprintk(ioc, printk(MPT2SAS_DEBUG_FMT "unexpected doorbell "
1769 "active!\n", ioc->name));
1770 goto issue_host_reset;
1773 if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) {
1774 mpt2sas_base_fault_info(ioc, ioc_state &
1775 MPI2_DOORBELL_DATA_MASK);
1776 goto issue_host_reset;
1779 smid = mpt2sas_base_get_smid(ioc, ioc->tm_cb_idx);
1781 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
1782 ioc->name, __func__);
1786 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "sending tm: handle(0x%04x),"
1787 " task_type(0x%02x), smid(%d)\n", ioc->name, handle, type, smid));
1788 ioc->tm_cmds.status = MPT2_CMD_PENDING;
1789 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
1790 ioc->tm_cmds.smid = smid;
1791 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
1792 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
1793 mpi_request->DevHandle = cpu_to_le16(handle);
1794 mpi_request->TaskType = type;
1795 mpi_request->TaskMID = cpu_to_le16(smid_task);
1796 int_to_scsilun(lun, (struct scsi_lun *)mpi_request->LUN);
1797 mpt2sas_scsih_set_tm_flag(ioc, handle);
1798 mpt2sas_base_put_smid_hi_priority(ioc, smid, VF_ID);
1799 timeleft = wait_for_completion_timeout(&ioc->tm_cmds.done, timeout*HZ);
1800 mpt2sas_scsih_clear_tm_flag(ioc, handle);
1801 if (!(ioc->tm_cmds.status & MPT2_CMD_COMPLETE)) {
1802 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
1803 ioc->name, __func__);
1804 _debug_dump_mf(mpi_request,
1805 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
1806 if (!(ioc->tm_cmds.status & MPT2_CMD_RESET))
1807 goto issue_host_reset;
1810 if (ioc->tm_cmds.status & MPT2_CMD_REPLY_VALID) {
1811 mpi_reply = ioc->tm_cmds.reply;
1812 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "complete tm: "
1813 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
1814 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
1815 le32_to_cpu(mpi_reply->IOCLogInfo),
1816 le32_to_cpu(mpi_reply->TerminationCount)));
1817 if (ioc->logging_level & MPT_DEBUG_TM)
1818 _scsih_response_code(ioc, mpi_reply->ResponseCode);
1822 mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, FORCE_BIG_HAMMER);
1826 * scsih_abort - eh threads main abort routine
1827 * @sdev: scsi device struct
1829 * Returns SUCCESS if command aborted else FAILED
1832 scsih_abort(struct scsi_cmnd *scmd)
1834 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
1835 struct MPT2SAS_DEVICE *sas_device_priv_data;
1839 struct scsi_cmnd *scmd_lookup;
1841 printk(MPT2SAS_INFO_FMT "attempting task abort! scmd(%p)\n",
1843 scsi_print_command(scmd);
1845 sas_device_priv_data = scmd->device->hostdata;
1846 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
1847 printk(MPT2SAS_INFO_FMT "device been deleted! scmd(%p)\n",
1849 scmd->result = DID_NO_CONNECT << 16;
1850 scmd->scsi_done(scmd);
1855 /* search for the command */
1856 smid = _scsih_scsi_lookup_find_by_scmd(ioc, scmd);
1858 scmd->result = DID_RESET << 16;
1863 /* for hidden raid components and volumes this is not supported */
1864 if (sas_device_priv_data->sas_target->flags &
1865 MPT_TARGET_FLAGS_RAID_COMPONENT ||
1866 sas_device_priv_data->sas_target->flags & MPT_TARGET_FLAGS_VOLUME) {
1867 scmd->result = DID_RESET << 16;
1872 mutex_lock(&ioc->tm_cmds.mutex);
1873 handle = sas_device_priv_data->sas_target->handle;
1874 mpt2sas_scsih_issue_tm(ioc, handle, sas_device_priv_data->lun,
1875 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30);
1877 /* sanity check - see whether command actually completed */
1878 scmd_lookup = _scsih_scsi_lookup_get(ioc, smid);
1879 if (scmd_lookup && (scmd_lookup->serial_number == scmd->serial_number))
1883 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
1884 mutex_unlock(&ioc->tm_cmds.mutex);
1887 printk(MPT2SAS_INFO_FMT "task abort: %s scmd(%p)\n",
1888 ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
1894 * scsih_dev_reset - eh threads main device reset routine
1895 * @sdev: scsi device struct
1897 * Returns SUCCESS if command aborted else FAILED
1900 scsih_dev_reset(struct scsi_cmnd *scmd)
1902 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
1903 struct MPT2SAS_DEVICE *sas_device_priv_data;
1904 struct _sas_device *sas_device;
1905 unsigned long flags;
1909 printk(MPT2SAS_INFO_FMT "attempting target reset! scmd(%p)\n",
1911 scsi_print_command(scmd);
1913 sas_device_priv_data = scmd->device->hostdata;
1914 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
1915 printk(MPT2SAS_INFO_FMT "device been deleted! scmd(%p)\n",
1917 scmd->result = DID_NO_CONNECT << 16;
1918 scmd->scsi_done(scmd);
1923 /* for hidden raid components obtain the volume_handle */
1925 if (sas_device_priv_data->sas_target->flags &
1926 MPT_TARGET_FLAGS_RAID_COMPONENT) {
1927 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1928 sas_device = _scsih_sas_device_find_by_handle(ioc,
1929 sas_device_priv_data->sas_target->handle);
1931 handle = sas_device->volume_handle;
1932 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1934 handle = sas_device_priv_data->sas_target->handle;
1937 scmd->result = DID_RESET << 16;
1942 mutex_lock(&ioc->tm_cmds.mutex);
1943 mpt2sas_scsih_issue_tm(ioc, handle, 0,
1944 MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0, 30);
1947 * sanity check see whether all commands to this target been
1950 if (_scsih_scsi_lookup_find_by_target(ioc, scmd->device->id,
1951 scmd->device->channel))
1955 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
1956 mutex_unlock(&ioc->tm_cmds.mutex);
1959 printk(MPT2SAS_INFO_FMT "target reset: %s scmd(%p)\n",
1960 ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
1965 * scsih_abort - eh threads main host reset routine
1966 * @sdev: scsi device struct
1968 * Returns SUCCESS if command aborted else FAILED
1971 scsih_host_reset(struct scsi_cmnd *scmd)
1973 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
1976 printk(MPT2SAS_INFO_FMT "attempting host reset! scmd(%p)\n",
1978 scsi_print_command(scmd);
1980 retval = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
1982 r = (retval < 0) ? FAILED : SUCCESS;
1983 printk(MPT2SAS_INFO_FMT "host reset: %s scmd(%p)\n",
1984 ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
1990 * _scsih_fw_event_add - insert and queue up fw_event
1991 * @ioc: per adapter object
1992 * @fw_event: object describing the event
1993 * Context: This function will acquire ioc->fw_event_lock.
1995 * This adds the firmware event object into link list, then queues it up to
1996 * be processed from user context.
2001 _scsih_fw_event_add(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
2003 unsigned long flags;
2005 if (ioc->firmware_event_thread == NULL)
2008 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2009 list_add_tail(&fw_event->list, &ioc->fw_event_list);
2010 INIT_WORK(&fw_event->work, _firmware_event_work);
2011 queue_work(ioc->firmware_event_thread, &fw_event->work);
2012 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2016 * _scsih_fw_event_free - delete fw_event
2017 * @ioc: per adapter object
2018 * @fw_event: object describing the event
2019 * Context: This function will acquire ioc->fw_event_lock.
2021 * This removes firmware event object from link list, frees associated memory.
2026 _scsih_fw_event_free(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work
2029 unsigned long flags;
2031 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2032 list_del(&fw_event->list);
2033 kfree(fw_event->event_data);
2035 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2039 * _scsih_fw_event_add - requeue an event
2040 * @ioc: per adapter object
2041 * @fw_event: object describing the event
2042 * Context: This function will acquire ioc->fw_event_lock.
2047 _scsih_fw_event_requeue(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work
2048 *fw_event, unsigned long delay)
2050 unsigned long flags;
2051 if (ioc->firmware_event_thread == NULL)
2054 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2055 queue_work(ioc->firmware_event_thread, &fw_event->work);
2056 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2060 * _scsih_fw_event_off - turn flag off preventing event handling
2061 * @ioc: per adapter object
2063 * Used to prevent handling of firmware events during adapter reset
2069 _scsih_fw_event_off(struct MPT2SAS_ADAPTER *ioc)
2071 unsigned long flags;
2073 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2074 ioc->fw_events_off = 1;
2075 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2080 * _scsih_fw_event_on - turn flag on allowing firmware event handling
2081 * @ioc: per adapter object
2086 _scsih_fw_event_on(struct MPT2SAS_ADAPTER *ioc)
2088 unsigned long flags;
2090 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2091 ioc->fw_events_off = 0;
2092 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2096 * _scsih_ublock_io_device - set the device state to SDEV_RUNNING
2097 * @ioc: per adapter object
2098 * @handle: device handle
2100 * During device pull we need to appropiately set the sdev state.
2103 _scsih_ublock_io_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2105 struct MPT2SAS_DEVICE *sas_device_priv_data;
2106 struct scsi_device *sdev;
2108 shost_for_each_device(sdev, ioc->shost) {
2109 sas_device_priv_data = sdev->hostdata;
2110 if (!sas_device_priv_data)
2112 if (!sas_device_priv_data->block)
2114 if (sas_device_priv_data->sas_target->handle == handle) {
2115 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
2116 MPT2SAS_INFO_FMT "SDEV_RUNNING: "
2117 "handle(0x%04x)\n", ioc->name, handle));
2118 sas_device_priv_data->block = 0;
2119 scsi_device_set_state(sdev, SDEV_RUNNING);
2125 * _scsih_block_io_device - set the device state to SDEV_BLOCK
2126 * @ioc: per adapter object
2127 * @handle: device handle
2129 * During device pull we need to appropiately set the sdev state.
2132 _scsih_block_io_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2134 struct MPT2SAS_DEVICE *sas_device_priv_data;
2135 struct scsi_device *sdev;
2137 shost_for_each_device(sdev, ioc->shost) {
2138 sas_device_priv_data = sdev->hostdata;
2139 if (!sas_device_priv_data)
2141 if (sas_device_priv_data->block)
2143 if (sas_device_priv_data->sas_target->handle == handle) {
2144 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
2145 MPT2SAS_INFO_FMT "SDEV_BLOCK: "
2146 "handle(0x%04x)\n", ioc->name, handle));
2147 sas_device_priv_data->block = 1;
2148 scsi_device_set_state(sdev, SDEV_BLOCK);
2154 * _scsih_block_io_to_children_attached_to_ex
2155 * @ioc: per adapter object
2156 * @sas_expander: the sas_device object
2158 * This routine set sdev state to SDEV_BLOCK for all devices
2159 * attached to this expander. This function called when expander is
2163 _scsih_block_io_to_children_attached_to_ex(struct MPT2SAS_ADAPTER *ioc,
2164 struct _sas_node *sas_expander)
2166 struct _sas_port *mpt2sas_port;
2167 struct _sas_device *sas_device;
2168 struct _sas_node *expander_sibling;
2169 unsigned long flags;
2174 list_for_each_entry(mpt2sas_port,
2175 &sas_expander->sas_port_list, port_list) {
2176 if (mpt2sas_port->remote_identify.device_type ==
2178 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2180 mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
2181 mpt2sas_port->remote_identify.sas_address);
2182 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2185 _scsih_block_io_device(ioc, sas_device->handle);
2189 list_for_each_entry(mpt2sas_port,
2190 &sas_expander->sas_port_list, port_list) {
2192 if (mpt2sas_port->remote_identify.device_type ==
2193 MPI2_SAS_DEVICE_INFO_EDGE_EXPANDER ||
2194 mpt2sas_port->remote_identify.device_type ==
2195 MPI2_SAS_DEVICE_INFO_FANOUT_EXPANDER) {
2197 spin_lock_irqsave(&ioc->sas_node_lock, flags);
2199 mpt2sas_scsih_expander_find_by_sas_address(
2200 ioc, mpt2sas_port->remote_identify.sas_address);
2201 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
2202 _scsih_block_io_to_children_attached_to_ex(ioc,
2209 * _scsih_block_io_to_children_attached_directly
2210 * @ioc: per adapter object
2211 * @event_data: topology change event data
2213 * This routine set sdev state to SDEV_BLOCK for all devices
2214 * direct attached during device pull.
2217 _scsih_block_io_to_children_attached_directly(struct MPT2SAS_ADAPTER *ioc,
2218 Mpi2EventDataSasTopologyChangeList_t *event_data)
2225 for (i = 0; i < event_data->NumEntries; i++) {
2226 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
2229 phy_number = event_data->StartPhyNum + i;
2230 reason_code = event_data->PHY[i].PhyStatus &
2231 MPI2_EVENT_SAS_TOPO_RC_MASK;
2232 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING)
2233 _scsih_block_io_device(ioc, handle);
2238 * _scsih_check_topo_delete_events - sanity check on topo events
2239 * @ioc: per adapter object
2240 * @event_data: the event data payload
2242 * This routine added to better handle cable breaker.
2244 * This handles the case where driver recieves multiple expander
2245 * add and delete events in a single shot. When there is a delete event
2246 * the routine will void any pending add events waiting in the event queue.
2251 _scsih_check_topo_delete_events(struct MPT2SAS_ADAPTER *ioc,
2252 Mpi2EventDataSasTopologyChangeList_t *event_data)
2254 struct fw_event_work *fw_event;
2255 Mpi2EventDataSasTopologyChangeList_t *local_event_data;
2256 u16 expander_handle;
2257 struct _sas_node *sas_expander;
2258 unsigned long flags;
2260 expander_handle = le16_to_cpu(event_data->ExpanderDevHandle);
2261 if (expander_handle < ioc->sas_hba.num_phys) {
2262 _scsih_block_io_to_children_attached_directly(ioc, event_data);
2266 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
2267 || event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING) {
2268 spin_lock_irqsave(&ioc->sas_node_lock, flags);
2269 sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc,
2271 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
2272 _scsih_block_io_to_children_attached_to_ex(ioc, sas_expander);
2273 } else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING)
2274 _scsih_block_io_to_children_attached_directly(ioc, event_data);
2276 if (event_data->ExpStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING)
2279 /* mark ignore flag for pending events */
2280 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2281 list_for_each_entry(fw_event, &ioc->fw_event_list, list) {
2282 if (fw_event->event != MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST ||
2285 local_event_data = fw_event->event_data;
2286 if (local_event_data->ExpStatus ==
2287 MPI2_EVENT_SAS_TOPO_ES_ADDED ||
2288 local_event_data->ExpStatus ==
2289 MPI2_EVENT_SAS_TOPO_ES_RESPONDING) {
2290 if (le16_to_cpu(local_event_data->ExpanderDevHandle) ==
2292 dewtprintk(ioc, printk(MPT2SAS_DEBUG_FMT
2293 "setting ignoring flag\n", ioc->name));
2294 fw_event->ignore = 1;
2298 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2302 * _scsih_queue_rescan - queue a topology rescan from user context
2303 * @ioc: per adapter object
2308 _scsih_queue_rescan(struct MPT2SAS_ADAPTER *ioc)
2310 struct fw_event_work *fw_event;
2312 if (ioc->wait_for_port_enable_to_complete)
2314 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
2317 fw_event->event = MPT2SAS_RESCAN_AFTER_HOST_RESET;
2318 fw_event->ioc = ioc;
2319 _scsih_fw_event_add(ioc, fw_event);
2323 * _scsih_flush_running_cmds - completing outstanding commands.
2324 * @ioc: per adapter object
2326 * The flushing out of all pending scmd commands following host reset,
2327 * where all IO is dropped to the floor.
2332 _scsih_flush_running_cmds(struct MPT2SAS_ADAPTER *ioc)
2334 struct scsi_cmnd *scmd;
2338 for (smid = 1; smid <= ioc->request_depth; smid++) {
2339 scmd = _scsih_scsi_lookup_getclear(ioc, smid);
2343 mpt2sas_base_free_smid(ioc, smid);
2344 scsi_dma_unmap(scmd);
2345 scmd->result = DID_RESET << 16;
2346 scmd->scsi_done(scmd);
2348 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "completing %d cmds\n",
2353 * mpt2sas_scsih_reset_handler - reset callback handler (for scsih)
2354 * @ioc: per adapter object
2355 * @reset_phase: phase
2357 * The handler for doing any required cleanup or initialization.
2359 * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
2360 * MPT2_IOC_DONE_RESET
2365 mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase)
2367 switch (reset_phase) {
2368 case MPT2_IOC_PRE_RESET:
2369 dtmprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: "
2370 "MPT2_IOC_PRE_RESET\n", ioc->name, __func__));
2371 _scsih_fw_event_off(ioc);
2373 case MPT2_IOC_AFTER_RESET:
2374 dtmprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: "
2375 "MPT2_IOC_AFTER_RESET\n", ioc->name, __func__));
2376 if (ioc->tm_cmds.status & MPT2_CMD_PENDING) {
2377 ioc->tm_cmds.status |= MPT2_CMD_RESET;
2378 mpt2sas_base_free_smid(ioc, ioc->tm_cmds.smid);
2379 complete(&ioc->tm_cmds.done);
2381 _scsih_fw_event_on(ioc);
2382 _scsih_flush_running_cmds(ioc);
2384 case MPT2_IOC_DONE_RESET:
2385 dtmprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: "
2386 "MPT2_IOC_DONE_RESET\n", ioc->name, __func__));
2387 _scsih_queue_rescan(ioc);
2393 * _scsih_setup_eedp - setup MPI request for EEDP transfer
2394 * @scmd: pointer to scsi command object
2395 * @mpi_request: pointer to the SCSI_IO reqest message frame
2397 * Supporting protection 1 and 3.
2402 _scsih_setup_eedp(struct scsi_cmnd *scmd, Mpi2SCSIIORequest_t *mpi_request)
2405 unsigned char prot_op = scsi_get_prot_op(scmd);
2406 unsigned char prot_type = scsi_get_prot_type(scmd);
2408 if (prot_type == SCSI_PROT_DIF_TYPE0 ||
2409 prot_type == SCSI_PROT_DIF_TYPE2 ||
2410 prot_op == SCSI_PROT_NORMAL)
2413 if (prot_op == SCSI_PROT_READ_STRIP)
2414 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP;
2415 else if (prot_op == SCSI_PROT_WRITE_INSERT)
2416 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_INSERT_OP;
2420 mpi_request->EEDPBlockSize = scmd->device->sector_size;
2422 switch (prot_type) {
2423 case SCSI_PROT_DIF_TYPE1:
2426 * enable ref/guard checking
2427 * auto increment ref tag
2429 mpi_request->EEDPFlags = eedp_flags |
2430 MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG |
2431 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG |
2432 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
2433 mpi_request->CDB.EEDP32.PrimaryReferenceTag =
2434 cpu_to_be32(scsi_get_lba(scmd));
2438 case SCSI_PROT_DIF_TYPE3:
2441 * enable guard checking
2443 mpi_request->EEDPFlags = eedp_flags |
2444 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
2451 * _scsih_eedp_error_handling - return sense code for EEDP errors
2452 * @scmd: pointer to scsi command object
2453 * @ioc_status: ioc status
2458 _scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status)
2464 switch (ioc_status) {
2465 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
2468 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
2471 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
2479 if (scmd->sc_data_direction == DMA_TO_DEVICE) {
2480 sk = ILLEGAL_REQUEST;
2481 host_byte = DID_ABORT;
2483 sk = ABORTED_COMMAND;
2487 scsi_build_sense_buffer(0, scmd->sense_buffer, sk, 0x10, ascq);
2488 scmd->result = DRIVER_SENSE << 24 | (host_byte << 16) |
2489 SAM_STAT_CHECK_CONDITION;
2493 * scsih_qcmd - main scsi request entry point
2494 * @scmd: pointer to scsi command object
2495 * @done: function pointer to be invoked on completion
2497 * The callback index is set inside `ioc->scsi_io_cb_idx`.
2499 * Returns 0 on success. If there's a failure, return either:
2500 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
2501 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
2504 scsih_qcmd(struct scsi_cmnd *scmd, void (*done)(struct scsi_cmnd *))
2506 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2507 struct MPT2SAS_DEVICE *sas_device_priv_data;
2508 struct MPT2SAS_TARGET *sas_target_priv_data;
2509 Mpi2SCSIIORequest_t *mpi_request;
2512 unsigned long flags;
2514 scmd->scsi_done = done;
2515 sas_device_priv_data = scmd->device->hostdata;
2516 if (!sas_device_priv_data) {
2517 scmd->result = DID_NO_CONNECT << 16;
2518 scmd->scsi_done(scmd);
2522 sas_target_priv_data = sas_device_priv_data->sas_target;
2523 if (!sas_target_priv_data || sas_target_priv_data->handle ==
2524 MPT2SAS_INVALID_DEVICE_HANDLE || sas_target_priv_data->deleted) {
2525 scmd->result = DID_NO_CONNECT << 16;
2526 scmd->scsi_done(scmd);
2530 /* see if we are busy with task managment stuff */
2531 spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags);
2532 if (sas_target_priv_data->tm_busy ||
2533 ioc->shost_recovery || ioc->ioc_link_reset_in_progress) {
2534 spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags);
2535 return SCSI_MLQUEUE_HOST_BUSY;
2537 spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags);
2539 if (scmd->sc_data_direction == DMA_FROM_DEVICE)
2540 mpi_control = MPI2_SCSIIO_CONTROL_READ;
2541 else if (scmd->sc_data_direction == DMA_TO_DEVICE)
2542 mpi_control = MPI2_SCSIIO_CONTROL_WRITE;
2544 mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER;
2547 if (!(sas_device_priv_data->flags & MPT_DEVICE_FLAGS_INIT)) {
2548 if (scmd->device->tagged_supported) {
2549 if (scmd->device->ordered_tags)
2550 mpi_control |= MPI2_SCSIIO_CONTROL_ORDEREDQ;
2552 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
2554 /* MPI Revision I (UNIT = 0xA) - removed MPI2_SCSIIO_CONTROL_UNTAGGED */
2555 /* mpi_control |= MPI2_SCSIIO_CONTROL_UNTAGGED;
2557 mpi_control |= (0x500);
2560 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
2562 if ((sas_device_priv_data->flags & MPT_DEVICE_TLR_ON))
2563 mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON;
2565 smid = mpt2sas_base_get_smid(ioc, ioc->scsi_io_cb_idx);
2567 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
2568 ioc->name, __func__);
2571 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
2572 memset(mpi_request, 0, sizeof(Mpi2SCSIIORequest_t));
2573 _scsih_setup_eedp(scmd, mpi_request);
2574 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
2575 if (sas_device_priv_data->sas_target->flags &
2576 MPT_TARGET_FLAGS_RAID_COMPONENT)
2577 mpi_request->Function = MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;
2579 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
2580 mpi_request->DevHandle =
2581 cpu_to_le16(sas_device_priv_data->sas_target->handle);
2582 mpi_request->DataLength = cpu_to_le32(scsi_bufflen(scmd));
2583 mpi_request->Control = cpu_to_le32(mpi_control);
2584 mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len);
2585 mpi_request->MsgFlags = MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR;
2586 mpi_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE;
2587 mpi_request->SenseBufferLowAddress =
2588 (u32)mpt2sas_base_get_sense_buffer_dma(ioc, smid);
2589 mpi_request->SGLOffset0 = offsetof(Mpi2SCSIIORequest_t, SGL) / 4;
2590 mpi_request->SGLFlags = cpu_to_le16(MPI2_SCSIIO_SGLFLAGS_TYPE_MPI +
2591 MPI2_SCSIIO_SGLFLAGS_SYSTEM_ADDR);
2593 int_to_scsilun(sas_device_priv_data->lun, (struct scsi_lun *)
2595 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
2597 if (!mpi_request->DataLength) {
2598 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request->SGL);
2600 if (_scsih_build_scatter_gather(ioc, scmd, smid)) {
2601 mpt2sas_base_free_smid(ioc, smid);
2606 _scsih_scsi_lookup_set(ioc, smid, scmd);
2607 mpt2sas_base_put_smid_scsi_io(ioc, smid, 0,
2608 sas_device_priv_data->sas_target->handle);
2612 return SCSI_MLQUEUE_HOST_BUSY;
2616 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
2617 * @sense_buffer: sense data returned by target
2618 * @data: normalized skey/asc/ascq
2623 _scsih_normalize_sense(char *sense_buffer, struct sense_info *data)
2625 if ((sense_buffer[0] & 0x7F) >= 0x72) {
2626 /* descriptor format */
2627 data->skey = sense_buffer[1] & 0x0F;
2628 data->asc = sense_buffer[2];
2629 data->ascq = sense_buffer[3];
2632 data->skey = sense_buffer[2] & 0x0F;
2633 data->asc = sense_buffer[12];
2634 data->ascq = sense_buffer[13];
2638 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
2640 * _scsih_scsi_ioc_info - translated non-succesfull SCSI_IO request
2641 * @ioc: per adapter object
2642 * @scmd: pointer to scsi command object
2643 * @mpi_reply: reply mf payload returned from firmware
2645 * scsi_status - SCSI Status code returned from target device
2646 * scsi_state - state info associated with SCSI_IO determined by ioc
2647 * ioc_status - ioc supplied status info
2652 _scsih_scsi_ioc_info(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
2653 Mpi2SCSIIOReply_t *mpi_reply, u16 smid)
2657 u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) &
2658 MPI2_IOCSTATUS_MASK;
2659 u8 scsi_state = mpi_reply->SCSIState;
2660 u8 scsi_status = mpi_reply->SCSIStatus;
2661 char *desc_ioc_state = NULL;
2662 char *desc_scsi_status = NULL;
2663 char *desc_scsi_state = ioc->tmp_string;
2665 switch (ioc_status) {
2666 case MPI2_IOCSTATUS_SUCCESS:
2667 desc_ioc_state = "success";
2669 case MPI2_IOCSTATUS_INVALID_FUNCTION:
2670 desc_ioc_state = "invalid function";
2672 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
2673 desc_ioc_state = "scsi recovered error";
2675 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE:
2676 desc_ioc_state = "scsi invalid dev handle";
2678 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
2679 desc_ioc_state = "scsi device not there";
2681 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
2682 desc_ioc_state = "scsi data overrun";
2684 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
2685 desc_ioc_state = "scsi data underrun";
2687 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
2688 desc_ioc_state = "scsi io data error";
2690 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
2691 desc_ioc_state = "scsi protocol error";
2693 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
2694 desc_ioc_state = "scsi task terminated";
2696 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
2697 desc_ioc_state = "scsi residual mismatch";
2699 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
2700 desc_ioc_state = "scsi task mgmt failed";
2702 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
2703 desc_ioc_state = "scsi ioc terminated";
2705 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
2706 desc_ioc_state = "scsi ext terminated";
2708 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
2709 desc_ioc_state = "eedp guard error";
2711 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
2712 desc_ioc_state = "eedp ref tag error";
2714 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
2715 desc_ioc_state = "eedp app tag error";
2718 desc_ioc_state = "unknown";
2722 switch (scsi_status) {
2723 case MPI2_SCSI_STATUS_GOOD:
2724 desc_scsi_status = "good";
2726 case MPI2_SCSI_STATUS_CHECK_CONDITION:
2727 desc_scsi_status = "check condition";
2729 case MPI2_SCSI_STATUS_CONDITION_MET:
2730 desc_scsi_status = "condition met";
2732 case MPI2_SCSI_STATUS_BUSY:
2733 desc_scsi_status = "busy";
2735 case MPI2_SCSI_STATUS_INTERMEDIATE:
2736 desc_scsi_status = "intermediate";
2738 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET:
2739 desc_scsi_status = "intermediate condmet";
2741 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT:
2742 desc_scsi_status = "reservation conflict";
2744 case MPI2_SCSI_STATUS_COMMAND_TERMINATED:
2745 desc_scsi_status = "command terminated";
2747 case MPI2_SCSI_STATUS_TASK_SET_FULL:
2748 desc_scsi_status = "task set full";
2750 case MPI2_SCSI_STATUS_ACA_ACTIVE:
2751 desc_scsi_status = "aca active";
2753 case MPI2_SCSI_STATUS_TASK_ABORTED:
2754 desc_scsi_status = "task aborted";
2757 desc_scsi_status = "unknown";
2761 desc_scsi_state[0] = '\0';
2763 desc_scsi_state = " ";
2764 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
2765 strcat(desc_scsi_state, "response info ");
2766 if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
2767 strcat(desc_scsi_state, "state terminated ");
2768 if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS)
2769 strcat(desc_scsi_state, "no status ");
2770 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED)
2771 strcat(desc_scsi_state, "autosense failed ");
2772 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)
2773 strcat(desc_scsi_state, "autosense valid ");
2775 scsi_print_command(scmd);
2776 printk(MPT2SAS_WARN_FMT "\tdev handle(0x%04x), "
2777 "ioc_status(%s)(0x%04x), smid(%d)\n", ioc->name,
2778 le16_to_cpu(mpi_reply->DevHandle), desc_ioc_state,
2780 printk(MPT2SAS_WARN_FMT "\trequest_len(%d), underflow(%d), "
2781 "resid(%d)\n", ioc->name, scsi_bufflen(scmd), scmd->underflow,
2782 scsi_get_resid(scmd));
2783 printk(MPT2SAS_WARN_FMT "\ttag(%d), transfer_count(%d), "
2784 "sc->result(0x%08x)\n", ioc->name, le16_to_cpu(mpi_reply->TaskTag),
2785 le32_to_cpu(mpi_reply->TransferCount), scmd->result);
2786 printk(MPT2SAS_WARN_FMT "\tscsi_status(%s)(0x%02x), "
2787 "scsi_state(%s)(0x%02x)\n", ioc->name, desc_scsi_status,
2788 scsi_status, desc_scsi_state, scsi_state);
2790 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
2791 struct sense_info data;
2792 _scsih_normalize_sense(scmd->sense_buffer, &data);
2793 printk(MPT2SAS_WARN_FMT "\t[sense_key,asc,ascq]: "
2794 "[0x%02x,0x%02x,0x%02x]\n", ioc->name, data.skey,
2795 data.asc, data.ascq);
2798 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) {
2799 response_info = le32_to_cpu(mpi_reply->ResponseInfo);
2800 response_bytes = (u8 *)&response_info;
2801 _scsih_response_code(ioc, response_bytes[3]);
2807 * _scsih_smart_predicted_fault - illuminate Fault LED
2808 * @ioc: per adapter object
2809 * @handle: device handle
2814 _scsih_smart_predicted_fault(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2816 Mpi2SepReply_t mpi_reply;
2817 Mpi2SepRequest_t mpi_request;
2818 struct scsi_target *starget;
2819 struct MPT2SAS_TARGET *sas_target_priv_data;
2820 Mpi2EventNotificationReply_t *event_reply;
2821 Mpi2EventDataSasDeviceStatusChange_t *event_data;
2822 struct _sas_device *sas_device;
2824 unsigned long flags;
2826 /* only handle non-raid devices */
2827 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2828 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
2830 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2833 starget = sas_device->starget;
2834 sas_target_priv_data = starget->hostdata;
2836 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) ||
2837 ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))) {
2838 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2841 starget_printk(KERN_WARNING, starget, "predicted fault\n");
2842 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2844 if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM) {
2845 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
2846 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
2847 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
2848 mpi_request.SlotStatus =
2849 MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT;
2850 mpi_request.DevHandle = cpu_to_le16(handle);
2851 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS;
2852 if ((mpt2sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
2853 &mpi_request)) != 0) {
2854 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
2855 ioc->name, __FILE__, __LINE__, __func__);
2859 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
2860 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
2861 "enclosure_processor: ioc_status (0x%04x), "
2862 "loginfo(0x%08x)\n", ioc->name,
2863 le16_to_cpu(mpi_reply.IOCStatus),
2864 le32_to_cpu(mpi_reply.IOCLogInfo)));
2869 /* insert into event log */
2870 sz = offsetof(Mpi2EventNotificationReply_t, EventData) +
2871 sizeof(Mpi2EventDataSasDeviceStatusChange_t);
2872 event_reply = kzalloc(sz, GFP_KERNEL);
2874 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
2875 ioc->name, __FILE__, __LINE__, __func__);
2879 event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION;
2880 event_reply->Event =
2881 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE);
2882 event_reply->MsgLength = sz/4;
2883 event_reply->EventDataLength =
2884 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t)/4);
2885 event_data = (Mpi2EventDataSasDeviceStatusChange_t *)
2886 event_reply->EventData;
2887 event_data->ReasonCode = MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA;
2888 event_data->ASC = 0x5D;
2889 event_data->DevHandle = cpu_to_le16(handle);
2890 event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address);
2891 mpt2sas_ctl_add_to_event_log(ioc, event_reply);
2896 * scsih_io_done - scsi request callback
2897 * @ioc: per adapter object
2898 * @smid: system request message index
2899 * @VF_ID: virtual function id
2900 * @reply: reply message frame(lower 32bit addr)
2902 * Callback handler when using scsih_qcmd.
2907 scsih_io_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 VF_ID, u32 reply)
2909 Mpi2SCSIIORequest_t *mpi_request;
2910 Mpi2SCSIIOReply_t *mpi_reply;
2911 struct scsi_cmnd *scmd;
2917 struct MPT2SAS_DEVICE *sas_device_priv_data;
2920 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
2921 scmd = _scsih_scsi_lookup_getclear(ioc, smid);
2925 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
2927 if (mpi_reply == NULL) {
2928 scmd->result = DID_OK << 16;
2932 sas_device_priv_data = scmd->device->hostdata;
2933 if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
2934 sas_device_priv_data->sas_target->deleted) {
2935 scmd->result = DID_NO_CONNECT << 16;
2939 /* turning off TLR */
2940 if (!sas_device_priv_data->tlr_snoop_check) {
2941 sas_device_priv_data->tlr_snoop_check++;
2942 if (sas_device_priv_data->flags & MPT_DEVICE_TLR_ON) {
2943 response_code = (le32_to_cpu(mpi_reply->ResponseInfo)
2945 if (response_code ==
2946 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME)
2947 sas_device_priv_data->flags &=
2952 xfer_cnt = le32_to_cpu(mpi_reply->TransferCount);
2953 scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt);
2954 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
2955 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
2956 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
2959 ioc_status &= MPI2_IOCSTATUS_MASK;
2960 scsi_state = mpi_reply->SCSIState;
2961 scsi_status = mpi_reply->SCSIStatus;
2963 if (ioc_status == MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 &&
2964 (scsi_status == MPI2_SCSI_STATUS_BUSY ||
2965 scsi_status == MPI2_SCSI_STATUS_RESERVATION_CONFLICT ||
2966 scsi_status == MPI2_SCSI_STATUS_TASK_SET_FULL)) {
2967 ioc_status = MPI2_IOCSTATUS_SUCCESS;
2970 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
2971 struct sense_info data;
2972 const void *sense_data = mpt2sas_base_get_sense_buffer(ioc,
2974 u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE,
2975 le32_to_cpu(mpi_reply->SenseCount));
2976 memcpy(scmd->sense_buffer, sense_data, sz);
2977 _scsih_normalize_sense(scmd->sense_buffer, &data);
2978 /* failure prediction threshold exceeded */
2979 if (data.asc == 0x5D)
2980 _scsih_smart_predicted_fault(ioc,
2981 le16_to_cpu(mpi_reply->DevHandle));
2984 switch (ioc_status) {
2985 case MPI2_IOCSTATUS_BUSY:
2986 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES:
2987 scmd->result = SAM_STAT_BUSY;
2990 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
2991 scmd->result = DID_NO_CONNECT << 16;
2994 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
2995 if (sas_device_priv_data->block) {
2996 scmd->result = (DID_BUS_BUSY << 16);
3000 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
3001 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
3002 scmd->result = DID_RESET << 16;
3005 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
3006 if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt))
3007 scmd->result = DID_SOFT_ERROR << 16;
3009 scmd->result = (DID_OK << 16) | scsi_status;
3012 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
3013 scmd->result = (DID_OK << 16) | scsi_status;
3015 if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID))
3018 if (xfer_cnt < scmd->underflow) {
3019 if (scsi_status == SAM_STAT_BUSY)
3020 scmd->result = SAM_STAT_BUSY;
3022 scmd->result = DID_SOFT_ERROR << 16;
3023 } else if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
3024 MPI2_SCSI_STATE_NO_SCSI_STATUS))
3025 scmd->result = DID_SOFT_ERROR << 16;
3026 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
3027 scmd->result = DID_RESET << 16;
3028 else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) {
3029 mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID;
3030 mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION;
3031 scmd->result = (DRIVER_SENSE << 24) |
3032 SAM_STAT_CHECK_CONDITION;
3033 scmd->sense_buffer[0] = 0x70;
3034 scmd->sense_buffer[2] = ILLEGAL_REQUEST;
3035 scmd->sense_buffer[12] = 0x20;
3036 scmd->sense_buffer[13] = 0;
3040 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
3041 scsi_set_resid(scmd, 0);
3042 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
3043 case MPI2_IOCSTATUS_SUCCESS:
3044 scmd->result = (DID_OK << 16) | scsi_status;
3045 if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
3046 MPI2_SCSI_STATE_NO_SCSI_STATUS))
3047 scmd->result = DID_SOFT_ERROR << 16;
3048 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
3049 scmd->result = DID_RESET << 16;
3052 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
3053 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
3054 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
3055 _scsih_eedp_error_handling(scmd, ioc_status);
3057 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
3058 case MPI2_IOCSTATUS_INVALID_FUNCTION:
3059 case MPI2_IOCSTATUS_INVALID_SGL:
3060 case MPI2_IOCSTATUS_INTERNAL_ERROR:
3061 case MPI2_IOCSTATUS_INVALID_FIELD:
3062 case MPI2_IOCSTATUS_INVALID_STATE:
3063 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
3064 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
3066 scmd->result = DID_SOFT_ERROR << 16;
3071 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3072 if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY))
3073 _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid);
3077 scsi_dma_unmap(scmd);
3078 scmd->scsi_done(scmd);
3082 * _scsih_link_change - process phy link changes
3083 * @ioc: per adapter object
3084 * @handle: phy handle
3085 * @attached_handle: valid for devices attached to link
3086 * @phy_number: phy number
3087 * @link_rate: new link rate
3093 _scsih_link_change(struct MPT2SAS_ADAPTER *ioc, u16 handle, u16 attached_handle,
3094 u8 phy_number, u8 link_rate)
3096 mpt2sas_transport_update_phy_link_change(ioc, handle, attached_handle,
3097 phy_number, link_rate);
3101 * _scsih_sas_host_refresh - refreshing sas host object contents
3102 * @ioc: per adapter object
3103 * @update: update link information
3106 * During port enable, fw will send topology events for every device. Its
3107 * possible that the handles may change from the previous setting, so this
3108 * code keeping handles updating if changed.
3113 _scsih_sas_host_refresh(struct MPT2SAS_ADAPTER *ioc, u8 update)
3118 Mpi2ConfigReply_t mpi_reply;
3119 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
3121 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT
3122 "updating handles for sas_host(0x%016llx)\n",
3123 ioc->name, (unsigned long long)ioc->sas_hba.sas_address));
3125 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys
3126 * sizeof(Mpi2SasIOUnit0PhyData_t));
3127 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
3128 if (!sas_iounit_pg0) {
3129 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3130 ioc->name, __FILE__, __LINE__, __func__);
3133 if (!(mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
3134 sas_iounit_pg0, sz))) {
3135 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
3136 MPI2_IOCSTATUS_MASK;
3137 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
3139 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
3140 ioc->sas_hba.phy[i].handle =
3141 le16_to_cpu(sas_iounit_pg0->PhyData[i].
3142 ControllerDevHandle);
3144 _scsih_link_change(ioc,
3145 ioc->sas_hba.phy[i].handle,
3146 le16_to_cpu(sas_iounit_pg0->PhyData[i].
3147 AttachedDevHandle), i,
3148 sas_iounit_pg0->PhyData[i].
3149 NegotiatedLinkRate >> 4);
3154 kfree(sas_iounit_pg0);
3158 * _scsih_sas_host_add - create sas host object
3159 * @ioc: per adapter object
3161 * Creating host side data object, stored in ioc->sas_hba
3166 _scsih_sas_host_add(struct MPT2SAS_ADAPTER *ioc)
3169 Mpi2ConfigReply_t mpi_reply;
3170 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
3171 Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
3172 Mpi2SasPhyPage0_t phy_pg0;
3173 Mpi2SasDevicePage0_t sas_device_pg0;
3174 Mpi2SasEnclosurePage0_t enclosure_pg0;
3177 u16 device_missing_delay;
3179 mpt2sas_config_get_number_hba_phys(ioc, &ioc->sas_hba.num_phys);
3180 if (!ioc->sas_hba.num_phys) {
3181 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3182 ioc->name, __FILE__, __LINE__, __func__);
3186 /* sas_iounit page 0 */
3187 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys *
3188 sizeof(Mpi2SasIOUnit0PhyData_t));
3189 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
3190 if (!sas_iounit_pg0) {
3191 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3192 ioc->name, __FILE__, __LINE__, __func__);
3195 if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
3196 sas_iounit_pg0, sz))) {
3197 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3198 ioc->name, __FILE__, __LINE__, __func__);
3201 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
3202 MPI2_IOCSTATUS_MASK;
3203 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
3204 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3205 ioc->name, __FILE__, __LINE__, __func__);
3209 /* sas_iounit page 1 */
3210 sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys *
3211 sizeof(Mpi2SasIOUnit1PhyData_t));
3212 sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
3213 if (!sas_iounit_pg1) {
3214 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3215 ioc->name, __FILE__, __LINE__, __func__);
3218 if ((mpt2sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
3219 sas_iounit_pg1, sz))) {
3220 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3221 ioc->name, __FILE__, __LINE__, __func__);
3224 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
3225 MPI2_IOCSTATUS_MASK;
3226 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
3227 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3228 ioc->name, __FILE__, __LINE__, __func__);
3232 ioc->io_missing_delay =
3233 le16_to_cpu(sas_iounit_pg1->IODeviceMissingDelay);
3234 device_missing_delay =
3235 le16_to_cpu(sas_iounit_pg1->ReportDeviceMissingDelay);
3236 if (device_missing_delay & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16)
3237 ioc->device_missing_delay = (device_missing_delay &
3238 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16;
3240 ioc->device_missing_delay = device_missing_delay &
3241 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
3243 ioc->sas_hba.parent_dev = &ioc->shost->shost_gendev;
3244 ioc->sas_hba.phy = kcalloc(ioc->sas_hba.num_phys,
3245 sizeof(struct _sas_phy), GFP_KERNEL);
3246 if (!ioc->sas_hba.phy) {
3247 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3248 ioc->name, __FILE__, __LINE__, __func__);
3251 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
3252 if ((mpt2sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0,
3254 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3255 ioc->name, __FILE__, __LINE__, __func__);
3258 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
3259 MPI2_IOCSTATUS_MASK;
3260 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
3261 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3262 ioc->name, __FILE__, __LINE__, __func__);
3265 ioc->sas_hba.phy[i].handle =
3266 le16_to_cpu(sas_iounit_pg0->PhyData[i].ControllerDevHandle);
3267 ioc->sas_hba.phy[i].phy_id = i;
3268 mpt2sas_transport_add_host_phy(ioc, &ioc->sas_hba.phy[i],
3269 phy_pg0, ioc->sas_hba.parent_dev);
3271 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
3272 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, ioc->sas_hba.phy[0].handle))) {
3273 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3274 ioc->name, __FILE__, __LINE__, __func__);
3277 ioc->sas_hba.handle = le16_to_cpu(sas_device_pg0.DevHandle);
3278 ioc->sas_hba.enclosure_handle =
3279 le16_to_cpu(sas_device_pg0.EnclosureHandle);
3280 ioc->sas_hba.sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
3281 printk(MPT2SAS_INFO_FMT "host_add: handle(0x%04x), "
3282 "sas_addr(0x%016llx), phys(%d)\n", ioc->name, ioc->sas_hba.handle,
3283 (unsigned long long) ioc->sas_hba.sas_address,
3284 ioc->sas_hba.num_phys) ;
3286 if (ioc->sas_hba.enclosure_handle) {
3287 if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply,
3289 MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
3290 ioc->sas_hba.enclosure_handle))) {
3291 ioc->sas_hba.enclosure_logical_id =
3292 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
3297 kfree(sas_iounit_pg1);
3298 kfree(sas_iounit_pg0);
3302 * _scsih_expander_add - creating expander object
3303 * @ioc: per adapter object
3304 * @handle: expander handle
3306 * Creating expander object, stored in ioc->sas_expander_list.
3308 * Return 0 for success, else error.
3311 _scsih_expander_add(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3313 struct _sas_node *sas_expander;
3314 Mpi2ConfigReply_t mpi_reply;
3315 Mpi2ExpanderPage0_t expander_pg0;
3316 Mpi2ExpanderPage1_t expander_pg1;
3317 Mpi2SasEnclosurePage0_t enclosure_pg0;
3322 unsigned long flags;
3323 struct _sas_port *mpt2sas_port;
3329 if ((mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
3330 MPI2_SAS_EXPAND_PGAD_FORM_HNDL, handle))) {
3331 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3332 ioc->name, __FILE__, __LINE__, __func__);
3336 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
3337 MPI2_IOCSTATUS_MASK;
3338 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
3339 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3340 ioc->name, __FILE__, __LINE__, __func__);
3344 /* handle out of order topology events */
3345 parent_handle = le16_to_cpu(expander_pg0.ParentDevHandle);
3346 if (parent_handle >= ioc->sas_hba.num_phys) {
3347 spin_lock_irqsave(&ioc->sas_node_lock, flags);
3348 sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc,
3350 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
3351 if (!sas_expander) {
3352 rc = _scsih_expander_add(ioc, parent_handle);
3358 sas_address = le64_to_cpu(expander_pg0.SASAddress);
3360 spin_lock_irqsave(&ioc->sas_node_lock, flags);
3361 sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
3363 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
3368 sas_expander = kzalloc(sizeof(struct _sas_node),
3370 if (!sas_expander) {
3371 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3372 ioc->name, __FILE__, __LINE__, __func__);
3376 sas_expander->handle = handle;
3377 sas_expander->num_phys = expander_pg0.NumPhys;
3378 sas_expander->parent_handle = parent_handle;
3379 sas_expander->enclosure_handle =
3380 le16_to_cpu(expander_pg0.EnclosureHandle);
3381 sas_expander->sas_address = sas_address;
3383 printk(MPT2SAS_INFO_FMT "expander_add: handle(0x%04x),"
3384 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc->name,
3385 handle, sas_expander->parent_handle, (unsigned long long)
3386 sas_expander->sas_address, sas_expander->num_phys);
3388 if (!sas_expander->num_phys)
3390 sas_expander->phy = kcalloc(sas_expander->num_phys,
3391 sizeof(struct _sas_phy), GFP_KERNEL);
3392 if (!sas_expander->phy) {
3393 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3394 ioc->name, __FILE__, __LINE__, __func__);
3399 INIT_LIST_HEAD(&sas_expander->sas_port_list);
3400 mpt2sas_port = mpt2sas_transport_port_add(ioc, handle,
3401 sas_expander->parent_handle);
3402 if (!mpt2sas_port) {
3403 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3404 ioc->name, __FILE__, __LINE__, __func__);
3408 sas_expander->parent_dev = &mpt2sas_port->rphy->dev;
3410 for (i = 0 ; i < sas_expander->num_phys ; i++) {
3411 if ((mpt2sas_config_get_expander_pg1(ioc, &mpi_reply,
3412 &expander_pg1, i, handle))) {
3413 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3414 ioc->name, __FILE__, __LINE__, __func__);
3417 sas_expander->phy[i].handle = handle;
3418 sas_expander->phy[i].phy_id = i;
3419 mpt2sas_transport_add_expander_phy(ioc, &sas_expander->phy[i],
3420 expander_pg1, sas_expander->parent_dev);
3423 if (sas_expander->enclosure_handle) {
3424 if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply,
3425 &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
3426 sas_expander->enclosure_handle))) {
3427 sas_expander->enclosure_logical_id =
3428 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
3432 _scsih_expander_node_add(ioc, sas_expander);
3438 kfree(sas_expander->phy);
3439 kfree(sas_expander);
3444 * _scsih_expander_remove - removing expander object
3445 * @ioc: per adapter object
3446 * @handle: expander handle
3451 _scsih_expander_remove(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3453 struct _sas_node *sas_expander;
3454 unsigned long flags;
3456 spin_lock_irqsave(&ioc->sas_node_lock, flags);
3457 sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc, handle);
3458 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
3459 _scsih_expander_node_remove(ioc, sas_expander);
3463 * _scsih_add_device - creating sas device object
3464 * @ioc: per adapter object
3465 * @handle: sas device handle
3466 * @phy_num: phy number end device attached to
3467 * @is_pd: is this hidden raid component
3469 * Creating end device object, stored in ioc->sas_device_list.
3471 * Returns 0 for success, non-zero for failure.
3474 _scsih_add_device(struct MPT2SAS_ADAPTER *ioc, u16 handle, u8 phy_num, u8 is_pd)
3476 Mpi2ConfigReply_t mpi_reply;
3477 Mpi2SasDevicePage0_t sas_device_pg0;
3478 Mpi2SasEnclosurePage0_t enclosure_pg0;
3479 struct _sas_device *sas_device;
3483 unsigned long flags;
3485 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
3486 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
3487 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3488 ioc->name, __FILE__, __LINE__, __func__);
3492 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
3493 MPI2_IOCSTATUS_MASK;
3494 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
3495 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3496 ioc->name, __FILE__, __LINE__, __func__);
3500 /* check if device is present */
3501 if (!(le16_to_cpu(sas_device_pg0.Flags) &
3502 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
3503 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3504 ioc->name, __FILE__, __LINE__, __func__);
3505 printk(MPT2SAS_ERR_FMT "Flags = 0x%04x\n",
3506 ioc->name, le16_to_cpu(sas_device_pg0.Flags));
3510 /* check if there were any issus with discovery */
3511 if (sas_device_pg0.AccessStatus ==
3512 MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED) {
3513 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3514 ioc->name, __FILE__, __LINE__, __func__);
3515 printk(MPT2SAS_ERR_FMT "AccessStatus = 0x%02x\n",
3516 ioc->name, sas_device_pg0.AccessStatus);
3520 /* check if this is end device */
3521 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
3522 if (!(_scsih_is_end_device(device_info))) {
3523 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3524 ioc->name, __FILE__, __LINE__, __func__);
3528 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
3530 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3531 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
3533 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3536 _scsih_ublock_io_device(ioc, handle);
3540 sas_device = kzalloc(sizeof(struct _sas_device),
3543 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3544 ioc->name, __FILE__, __LINE__, __func__);
3548 sas_device->handle = handle;
3549 sas_device->parent_handle =
3550 le16_to_cpu(sas_device_pg0.ParentDevHandle);
3551 sas_device->enclosure_handle =
3552 le16_to_cpu(sas_device_pg0.EnclosureHandle);
3554 le16_to_cpu(sas_device_pg0.Slot);
3555 sas_device->device_info = device_info;
3556 sas_device->sas_address = sas_address;
3557 sas_device->hidden_raid_component = is_pd;
3559 /* get enclosure_logical_id */
3560 if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply, &enclosure_pg0,
3561 MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
3562 sas_device->enclosure_handle))) {
3563 sas_device->enclosure_logical_id =
3564 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
3567 /* get device name */
3568 sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName);
3570 if (ioc->wait_for_port_enable_to_complete)
3571 _scsih_sas_device_init_add(ioc, sas_device);
3573 _scsih_sas_device_add(ioc, sas_device);
3579 * _scsih_remove_device - removing sas device object
3580 * @ioc: per adapter object
3581 * @handle: sas device handle
3586 _scsih_remove_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3588 struct MPT2SAS_TARGET *sas_target_priv_data;
3589 struct _sas_device *sas_device;
3590 unsigned long flags;
3591 Mpi2SasIoUnitControlReply_t mpi_reply;
3592 Mpi2SasIoUnitControlRequest_t mpi_request;
3595 /* lookup sas_device */
3596 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3597 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
3599 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3603 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter: handle"
3604 "(0x%04x)\n", ioc->name, __func__, handle));
3606 if (sas_device->starget && sas_device->starget->hostdata) {
3607 sas_target_priv_data = sas_device->starget->hostdata;
3608 sas_target_priv_data->deleted = 1;
3610 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3612 if (ioc->remove_host)
3615 /* Target Reset to flush out all the outstanding IO */
3616 device_handle = (sas_device->hidden_raid_component) ?
3617 sas_device->volume_handle : handle;
3618 if (device_handle) {
3619 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "issue target reset: "
3620 "handle(0x%04x)\n", ioc->name, device_handle));
3621 mutex_lock(&ioc->tm_cmds.mutex);
3622 mpt2sas_scsih_issue_tm(ioc, device_handle, 0,
3623 MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0, 10);
3624 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
3625 mutex_unlock(&ioc->tm_cmds.mutex);
3626 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "issue target reset "
3627 "done: handle(0x%04x)\n", ioc->name, device_handle));
3630 /* SAS_IO_UNIT_CNTR - send REMOVE_DEVICE */
3631 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "sas_iounit: handle"
3632 "(0x%04x)\n", ioc->name, handle));
3633 memset(&mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t));
3634 mpi_request.Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL;
3635 mpi_request.Operation = MPI2_SAS_OP_REMOVE_DEVICE;
3636 mpi_request.DevHandle = handle;
3637 mpi_request.VF_ID = 0;
3638 if ((mpt2sas_base_sas_iounit_control(ioc, &mpi_reply,
3639 &mpi_request)) != 0) {
3640 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3641 ioc->name, __FILE__, __LINE__, __func__);
3644 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "sas_iounit: ioc_status"
3645 "(0x%04x), loginfo(0x%08x)\n", ioc->name,
3646 le16_to_cpu(mpi_reply.IOCStatus),
3647 le32_to_cpu(mpi_reply.IOCLogInfo)));
3650 mpt2sas_transport_port_remove(ioc, sas_device->sas_address,
3651 sas_device->parent_handle);
3653 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), sas_addr"
3654 "(0x%016llx)\n", ioc->name, sas_device->handle,
3655 (unsigned long long) sas_device->sas_address);
3656 _scsih_sas_device_remove(ioc, sas_device);
3658 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: exit: handle"
3659 "(0x%04x)\n", ioc->name, __func__, handle));
3662 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3664 * _scsih_sas_topology_change_event_debug - debug for topology event
3665 * @ioc: per adapter object
3666 * @event_data: event data payload
3670 _scsih_sas_topology_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
3671 Mpi2EventDataSasTopologyChangeList_t *event_data)
3677 char *status_str = NULL;
3680 switch (event_data->ExpStatus) {
3681 case MPI2_EVENT_SAS_TOPO_ES_ADDED:
3684 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING:
3685 status_str = "remove";
3687 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING:
3688 status_str = "responding";
3690 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING:
3691 status_str = "remove delay";
3694 status_str = "unknown status";
3697 printk(MPT2SAS_DEBUG_FMT "sas topology change: (%s)\n",
3698 ioc->name, status_str);
3699 printk(KERN_DEBUG "\thandle(0x%04x), enclosure_handle(0x%04x) "
3700 "start_phy(%02d), count(%d)\n",
3701 le16_to_cpu(event_data->ExpanderDevHandle),
3702 le16_to_cpu(event_data->EnclosureHandle),
3703 event_data->StartPhyNum, event_data->NumEntries);
3704 for (i = 0; i < event_data->NumEntries; i++) {
3705 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
3708 phy_number = event_data->StartPhyNum + i;
3709 reason_code = event_data->PHY[i].PhyStatus &
3710 MPI2_EVENT_SAS_TOPO_RC_MASK;
3711 switch (reason_code) {
3712 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
3713 snprintf(link_rate, 25, ": add, link(0x%02x)",
3714 (event_data->PHY[i].LinkRate >> 4));
3715 status_str = link_rate;
3717 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
3718 status_str = ": remove";
3720 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING:
3721 status_str = ": remove_delay";
3723 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
3724 snprintf(link_rate, 25, ": link(0x%02x)",
3725 (event_data->PHY[i].LinkRate >> 4));
3726 status_str = link_rate;
3728 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE:
3729 status_str = ": responding";
3732 status_str = ": unknown";
3735 printk(KERN_DEBUG "\tphy(%02d), attached_handle(0x%04x)%s\n",
3736 phy_number, handle, status_str);
3742 * _scsih_sas_topology_change_event - handle topology changes
3743 * @ioc: per adapter object
3745 * @event_data: event data payload
3751 _scsih_sas_topology_change_event(struct MPT2SAS_ADAPTER *ioc, u8 VF_ID,
3752 Mpi2EventDataSasTopologyChangeList_t *event_data,
3753 struct fw_event_work *fw_event)
3756 u16 parent_handle, handle;
3759 struct _sas_node *sas_expander;
3760 unsigned long flags;
3763 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3764 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
3765 _scsih_sas_topology_change_event_debug(ioc, event_data);
3768 if (!ioc->sas_hba.num_phys)
3769 _scsih_sas_host_add(ioc);
3771 _scsih_sas_host_refresh(ioc, 0);
3773 if (fw_event->ignore) {
3774 dewtprintk(ioc, printk(MPT2SAS_DEBUG_FMT "ignoring expander "
3775 "event\n", ioc->name));
3779 parent_handle = le16_to_cpu(event_data->ExpanderDevHandle);
3781 /* handle expander add */
3782 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_ADDED)
3783 if (_scsih_expander_add(ioc, parent_handle) != 0)
3786 /* handle siblings events */
3787 for (i = 0; i < event_data->NumEntries; i++) {
3788 if (fw_event->ignore) {
3789 dewtprintk(ioc, printk(MPT2SAS_DEBUG_FMT "ignoring "
3790 "expander event\n", ioc->name));
3793 if (event_data->PHY[i].PhyStatus &
3794 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT)
3796 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
3799 phy_number = event_data->StartPhyNum + i;
3800 reason_code = event_data->PHY[i].PhyStatus &
3801 MPI2_EVENT_SAS_TOPO_RC_MASK;
3802 link_rate_ = event_data->PHY[i].LinkRate >> 4;
3803 switch (reason_code) {
3804 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
3805 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
3806 if (!parent_handle) {
3807 if (phy_number < ioc->sas_hba.num_phys)
3808 _scsih_link_change(ioc,
3809 ioc->sas_hba.phy[phy_number].handle,
3810 handle, phy_number, link_rate_);
3812 spin_lock_irqsave(&ioc->sas_node_lock, flags);
3814 mpt2sas_scsih_expander_find_by_handle(ioc,
3816 spin_unlock_irqrestore(&ioc->sas_node_lock,
3819 if (phy_number < sas_expander->num_phys)
3820 _scsih_link_change(ioc,
3822 phy[phy_number].handle,
3827 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED) {
3828 if (link_rate_ >= MPI2_SAS_NEG_LINK_RATE_1_5)
3829 _scsih_ublock_io_device(ioc, handle);
3831 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED) {
3832 if (link_rate_ < MPI2_SAS_NEG_LINK_RATE_1_5)
3834 _scsih_add_device(ioc, handle, phy_number, 0);
3837 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
3838 _scsih_remove_device(ioc, handle);
3843 /* handle expander removal */
3844 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING)
3845 _scsih_expander_remove(ioc, parent_handle);
3849 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3851 * _scsih_sas_device_status_change_event_debug - debug for device event
3852 * @event_data: event data payload
3858 _scsih_sas_device_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
3859 Mpi2EventDataSasDeviceStatusChange_t *event_data)
3861 char *reason_str = NULL;
3863 switch (event_data->ReasonCode) {
3864 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
3865 reason_str = "smart data";
3867 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED:
3868 reason_str = "unsupported device discovered";
3870 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
3871 reason_str = "internal device reset";
3873 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL:
3874 reason_str = "internal task abort";
3876 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL:
3877 reason_str = "internal task abort set";
3879 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL:
3880 reason_str = "internal clear task set";
3882 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL:
3883 reason_str = "internal query task";
3885 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE:
3886 reason_str = "sata init failure";
3888 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET:
3889 reason_str = "internal device reset complete";
3891 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL:
3892 reason_str = "internal task abort complete";
3894 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION:
3895 reason_str = "internal async notification";
3898 reason_str = "unknown reason";
3901 printk(MPT2SAS_DEBUG_FMT "device status change: (%s)\n"
3902 "\thandle(0x%04x), sas address(0x%016llx)", ioc->name,
3903 reason_str, le16_to_cpu(event_data->DevHandle),
3904 (unsigned long long)le64_to_cpu(event_data->SASAddress));
3905 if (event_data->ReasonCode == MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA)
3906 printk(MPT2SAS_DEBUG_FMT ", ASC(0x%x), ASCQ(0x%x)\n", ioc->name,
3907 event_data->ASC, event_data->ASCQ);
3908 printk(KERN_INFO "\n");
3913 * _scsih_sas_device_status_change_event - handle device status change
3914 * @ioc: per adapter object
3916 * @event_data: event data payload
3922 _scsih_sas_device_status_change_event(struct MPT2SAS_ADAPTER *ioc, u8 VF_ID,
3923 Mpi2EventDataSasDeviceStatusChange_t *event_data)
3925 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3926 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
3927 _scsih_sas_device_status_change_event_debug(ioc, event_data);
3931 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3933 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure event
3934 * @ioc: per adapter object
3935 * @event_data: event data payload
3941 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
3942 Mpi2EventDataSasEnclDevStatusChange_t *event_data)
3944 char *reason_str = NULL;
3946 switch (event_data->ReasonCode) {
3947 case MPI2_EVENT_SAS_ENCL_RC_ADDED:
3948 reason_str = "enclosure add";
3950 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING:
3951 reason_str = "enclosure remove";
3954 reason_str = "unknown reason";
3958 printk(MPT2SAS_DEBUG_FMT "enclosure status change: (%s)\n"
3959 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
3960 " number slots(%d)\n", ioc->name, reason_str,
3961 le16_to_cpu(event_data->EnclosureHandle),
3962 (unsigned long long)le64_to_cpu(event_data->EnclosureLogicalID),
3963 le16_to_cpu(event_data->StartSlot));
3968 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
3969 * @ioc: per adapter object
3971 * @event_data: event data payload
3977 _scsih_sas_enclosure_dev_status_change_event(struct MPT2SAS_ADAPTER *ioc,
3978 u8 VF_ID, Mpi2EventDataSasEnclDevStatusChange_t *event_data)
3980 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3981 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
3982 _scsih_sas_enclosure_dev_status_change_event_debug(ioc,
3988 * _scsih_sas_broadcast_primative_event - handle broadcast events
3989 * @ioc: per adapter object
3990 * @event_data: event data payload
3996 _scsih_sas_broadcast_primative_event(struct MPT2SAS_ADAPTER *ioc, u8 VF_ID,
3997 Mpi2EventDataSasBroadcastPrimitive_t *event_data)
3999 struct scsi_cmnd *scmd;
4002 struct MPT2SAS_DEVICE *sas_device_priv_data;
4003 u32 termination_count;
4005 Mpi2SCSITaskManagementReply_t *mpi_reply;
4007 dewtprintk(ioc, printk(MPT2SAS_DEBUG_FMT "broadcast primative: "
4008 "phy number(%d), width(%d)\n", ioc->name, event_data->PhyNum,
4009 event_data->PortWidth));
4011 dtmprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: enter\n", ioc->name,
4014 mutex_lock(&ioc->tm_cmds.mutex);
4015 termination_count = 0;
4017 mpi_reply = ioc->tm_cmds.reply;
4018 for (smid = 1; smid <= ioc->request_depth; smid++) {
4019 scmd = _scsih_scsi_lookup_get(ioc, smid);
4022 sas_device_priv_data = scmd->device->hostdata;
4023 if (!sas_device_priv_data || !sas_device_priv_data->sas_target)
4025 /* skip hidden raid components */
4026 if (sas_device_priv_data->sas_target->flags &
4027 MPT_TARGET_FLAGS_RAID_COMPONENT)
4030 if (sas_device_priv_data->sas_target->flags &
4031 MPT_TARGET_FLAGS_VOLUME)
4034 handle = sas_device_priv_data->sas_target->handle;
4035 lun = sas_device_priv_data->lun;
4038 mpt2sas_scsih_issue_tm(ioc, handle, lun,
4039 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, smid, 30);
4040 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
4042 if ((mpi_reply->IOCStatus == MPI2_IOCSTATUS_SUCCESS) &&
4043 (mpi_reply->ResponseCode ==
4044 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED ||
4045 mpi_reply->ResponseCode ==
4046 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC))
4049 mpt2sas_scsih_issue_tm(ioc, handle, lun,
4050 MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET, 0, 30);
4051 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
4052 termination_count += le32_to_cpu(mpi_reply->TerminationCount);
4054 ioc->broadcast_aen_busy = 0;
4055 mutex_unlock(&ioc->tm_cmds.mutex);
4057 dtmprintk(ioc, printk(MPT2SAS_DEBUG_FMT
4058 "%s - exit, query_count = %d termination_count = %d\n",
4059 ioc->name, __func__, query_count, termination_count));
4063 * _scsih_sas_discovery_event - handle discovery events
4064 * @ioc: per adapter object
4065 * @event_data: event data payload
4071 _scsih_sas_discovery_event(struct MPT2SAS_ADAPTER *ioc, u8 VF_ID,
4072 Mpi2EventDataSasDiscovery_t *event_data)
4074 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4075 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) {
4076 printk(MPT2SAS_DEBUG_FMT "discovery event: (%s)", ioc->name,
4077 (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ?
4079 if (event_data->DiscoveryStatus)
4080 printk(MPT2SAS_DEBUG_FMT ", discovery_status(0x%08x)",
4081 ioc->name, le32_to_cpu(event_data->DiscoveryStatus));
4086 if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED &&
4087 !ioc->sas_hba.num_phys)
4088 _scsih_sas_host_add(ioc);
4092 * _scsih_reprobe_lun - reprobing lun
4093 * @sdev: scsi device struct
4094 * @no_uld_attach: sdev->no_uld_attach flag setting
4098 _scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach)
4102 sdev->no_uld_attach = no_uld_attach ? 1 : 0;
4103 sdev_printk(KERN_INFO, sdev, "%s raid component\n",
4104 sdev->no_uld_attach ? "hidding" : "exposing");
4105 rc = scsi_device_reprobe(sdev);
4109 * _scsih_reprobe_target - reprobing target
4110 * @starget: scsi target struct
4111 * @no_uld_attach: sdev->no_uld_attach flag setting
4113 * Note: no_uld_attach flag determines whether the disk device is attached
4114 * to block layer. A value of `1` means to not attach.
4117 _scsih_reprobe_target(struct scsi_target *starget, int no_uld_attach)
4119 struct MPT2SAS_TARGET *sas_target_priv_data = starget->hostdata;
4122 sas_target_priv_data->flags |= MPT_TARGET_FLAGS_RAID_COMPONENT;
4124 sas_target_priv_data->flags &= ~MPT_TARGET_FLAGS_RAID_COMPONENT;
4126 starget_for_each_device(starget, no_uld_attach ? (void *)1 : NULL,
4127 _scsih_reprobe_lun);
4130 * _scsih_sas_volume_add - add new volume
4131 * @ioc: per adapter object
4132 * @element: IR config element data
4138 _scsih_sas_volume_add(struct MPT2SAS_ADAPTER *ioc,
4139 Mpi2EventIrConfigElement_t *element)
4141 struct _raid_device *raid_device;
4142 unsigned long flags;
4144 u16 handle = le16_to_cpu(element->VolDevHandle);
4147 #if 0 /* RAID_HACKS */
4148 if (le32_to_cpu(event_data->Flags) &
4149 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG)
4153 mpt2sas_config_get_volume_wwid(ioc, handle, &wwid);
4155 printk(MPT2SAS_ERR_FMT
4156 "failure at %s:%d/%s()!\n", ioc->name,
4157 __FILE__, __LINE__, __func__);
4161 spin_lock_irqsave(&ioc->raid_device_lock, flags);
4162 raid_device = _scsih_raid_device_find_by_wwid(ioc, wwid);
4163 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
4168 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
4170 printk(MPT2SAS_ERR_FMT
4171 "failure at %s:%d/%s()!\n", ioc->name,
4172 __FILE__, __LINE__, __func__);
4176 raid_device->id = ioc->sas_id++;
4177 raid_device->channel = RAID_CHANNEL;
4178 raid_device->handle = handle;
4179 raid_device->wwid = wwid;
4180 _scsih_raid_device_add(ioc, raid_device);
4181 if (!ioc->wait_for_port_enable_to_complete) {
4182 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
4183 raid_device->id, 0);
4185 _scsih_raid_device_remove(ioc, raid_device);
4187 _scsih_determine_boot_device(ioc, raid_device, 1);
4191 * _scsih_sas_volume_delete - delete volume
4192 * @ioc: per adapter object
4193 * @element: IR config element data
4199 _scsih_sas_volume_delete(struct MPT2SAS_ADAPTER *ioc,
4200 Mpi2EventIrConfigElement_t *element)
4202 struct _raid_device *raid_device;
4203 u16 handle = le16_to_cpu(element->VolDevHandle);
4204 unsigned long flags;
4205 struct MPT2SAS_TARGET *sas_target_priv_data;
4207 #if 0 /* RAID_HACKS */
4208 if (le32_to_cpu(event_data->Flags) &
4209 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG)
4213 spin_lock_irqsave(&ioc->raid_device_lock, flags);
4214 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
4215 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
4218 if (raid_device->starget) {
4219 sas_target_priv_data = raid_device->starget->hostdata;
4220 sas_target_priv_data->deleted = 1;
4221 scsi_remove_target(&raid_device->starget->dev);
4223 _scsih_raid_device_remove(ioc, raid_device);
4227 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
4228 * @ioc: per adapter object
4229 * @element: IR config element data
4235 _scsih_sas_pd_expose(struct MPT2SAS_ADAPTER *ioc,
4236 Mpi2EventIrConfigElement_t *element)
4238 struct _sas_device *sas_device;
4239 unsigned long flags;
4240 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
4242 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4243 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
4244 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4248 /* exposing raid component */
4249 sas_device->volume_handle = 0;
4250 sas_device->volume_wwid = 0;
4251 sas_device->hidden_raid_component = 0;
4252 _scsih_reprobe_target(sas_device->starget, 0);
4256 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
4257 * @ioc: per adapter object
4258 * @element: IR config element data
4264 _scsih_sas_pd_hide(struct MPT2SAS_ADAPTER *ioc,
4265 Mpi2EventIrConfigElement_t *element)
4267 struct _sas_device *sas_device;
4268 unsigned long flags;
4269 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
4271 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4272 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
4273 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4277 /* hiding raid component */
4278 mpt2sas_config_get_volume_handle(ioc, handle,
4279 &sas_device->volume_handle);
4280 mpt2sas_config_get_volume_wwid(ioc, sas_device->volume_handle,
4281 &sas_device->volume_wwid);
4282 sas_device->hidden_raid_component = 1;
4283 _scsih_reprobe_target(sas_device->starget, 1);
4287 * _scsih_sas_pd_delete - delete pd component
4288 * @ioc: per adapter object
4289 * @element: IR config element data
4295 _scsih_sas_pd_delete(struct MPT2SAS_ADAPTER *ioc,
4296 Mpi2EventIrConfigElement_t *element)
4298 struct _sas_device *sas_device;
4299 unsigned long flags;
4300 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
4302 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4303 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
4304 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4307 _scsih_remove_device(ioc, handle);
4311 * _scsih_sas_pd_add - remove pd component
4312 * @ioc: per adapter object
4313 * @element: IR config element data
4319 _scsih_sas_pd_add(struct MPT2SAS_ADAPTER *ioc,
4320 Mpi2EventIrConfigElement_t *element)
4322 struct _sas_device *sas_device;
4323 unsigned long flags;
4324 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
4326 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4327 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
4328 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4330 sas_device->hidden_raid_component = 1;
4332 _scsih_add_device(ioc, handle, 0, 1);
4335 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4337 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
4338 * @ioc: per adapter object
4339 * @event_data: event data payload
4345 _scsih_sas_ir_config_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
4346 Mpi2EventDataIrConfigChangeList_t *event_data)
4348 Mpi2EventIrConfigElement_t *element;
4351 char *reason_str = NULL, *element_str = NULL;
4353 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
4355 printk(MPT2SAS_DEBUG_FMT "raid config change: (%s), elements(%d)\n",
4356 ioc->name, (le32_to_cpu(event_data->Flags) &
4357 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ?
4358 "foreign" : "native", event_data->NumElements);
4359 for (i = 0; i < event_data->NumElements; i++, element++) {
4360 switch (element->ReasonCode) {
4361 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
4364 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
4365 reason_str = "remove";
4367 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE:
4368 reason_str = "no change";
4370 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
4371 reason_str = "hide";
4373 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
4374 reason_str = "unhide";
4376 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
4377 reason_str = "volume_created";
4379 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
4380 reason_str = "volume_deleted";
4382 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
4383 reason_str = "pd_created";
4385 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
4386 reason_str = "pd_deleted";
4389 reason_str = "unknown reason";
4392 element_type = le16_to_cpu(element->ElementFlags) &
4393 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK;
4394 switch (element_type) {
4395 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT:
4396 element_str = "volume";
4398 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT:
4399 element_str = "phys disk";
4401 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT:
4402 element_str = "hot spare";
4405 element_str = "unknown element";
4408 printk(KERN_DEBUG "\t(%s:%s), vol handle(0x%04x), "
4409 "pd handle(0x%04x), pd num(0x%02x)\n", element_str,
4410 reason_str, le16_to_cpu(element->VolDevHandle),
4411 le16_to_cpu(element->PhysDiskDevHandle),
4412 element->PhysDiskNum);
4418 * _scsih_sas_ir_config_change_event - handle ir configuration change events
4419 * @ioc: per adapter object
4421 * @event_data: event data payload
4427 _scsih_sas_ir_config_change_event(struct MPT2SAS_ADAPTER *ioc, u8 VF_ID,
4428 Mpi2EventDataIrConfigChangeList_t *event_data)
4430 Mpi2EventIrConfigElement_t *element;
4433 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4434 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
4435 _scsih_sas_ir_config_change_event_debug(ioc, event_data);
4439 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
4440 for (i = 0; i < event_data->NumElements; i++, element++) {
4442 switch (element->ReasonCode) {
4443 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
4444 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
4445 _scsih_sas_volume_add(ioc, element);
4447 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
4448 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
4449 _scsih_sas_volume_delete(ioc, element);
4451 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
4452 _scsih_sas_pd_hide(ioc, element);
4454 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
4455 _scsih_sas_pd_expose(ioc, element);
4457 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
4458 _scsih_sas_pd_add(ioc, element);
4460 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
4461 _scsih_sas_pd_delete(ioc, element);
4468 * _scsih_sas_ir_volume_event - IR volume event
4469 * @ioc: per adapter object
4470 * @event_data: event data payload
4476 _scsih_sas_ir_volume_event(struct MPT2SAS_ADAPTER *ioc, u8 VF_ID,
4477 Mpi2EventDataIrVolume_t *event_data)
4480 unsigned long flags;
4481 struct _raid_device *raid_device;
4485 struct MPT2SAS_TARGET *sas_target_priv_data;
4487 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
4490 handle = le16_to_cpu(event_data->VolDevHandle);
4491 state = le32_to_cpu(event_data->NewValue);
4492 dewtprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: handle(0x%04x), "
4493 "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle,
4494 le32_to_cpu(event_data->PreviousValue), state));
4496 spin_lock_irqsave(&ioc->raid_device_lock, flags);
4497 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
4498 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
4501 case MPI2_RAID_VOL_STATE_MISSING:
4502 case MPI2_RAID_VOL_STATE_FAILED:
4505 if (raid_device->starget) {
4506 sas_target_priv_data = raid_device->starget->hostdata;
4507 sas_target_priv_data->deleted = 1;
4508 scsi_remove_target(&raid_device->starget->dev);
4510 _scsih_raid_device_remove(ioc, raid_device);
4513 case MPI2_RAID_VOL_STATE_ONLINE:
4514 case MPI2_RAID_VOL_STATE_DEGRADED:
4515 case MPI2_RAID_VOL_STATE_OPTIMAL:
4519 mpt2sas_config_get_volume_wwid(ioc, handle, &wwid);
4521 printk(MPT2SAS_ERR_FMT
4522 "failure at %s:%d/%s()!\n", ioc->name,
4523 __FILE__, __LINE__, __func__);
4527 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
4529 printk(MPT2SAS_ERR_FMT
4530 "failure at %s:%d/%s()!\n", ioc->name,
4531 __FILE__, __LINE__, __func__);
4535 raid_device->id = ioc->sas_id++;
4536 raid_device->channel = RAID_CHANNEL;
4537 raid_device->handle = handle;
4538 raid_device->wwid = wwid;
4539 _scsih_raid_device_add(ioc, raid_device);
4540 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
4541 raid_device->id, 0);
4543 _scsih_raid_device_remove(ioc, raid_device);
4546 case MPI2_RAID_VOL_STATE_INITIALIZING:
4553 * _scsih_sas_ir_physical_disk_event - PD event
4554 * @ioc: per adapter object
4555 * @event_data: event data payload
4561 _scsih_sas_ir_physical_disk_event(struct MPT2SAS_ADAPTER *ioc, u8 VF_ID,
4562 Mpi2EventDataIrPhysicalDisk_t *event_data)
4566 struct _sas_device *sas_device;
4567 unsigned long flags;
4569 if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED)
4572 handle = le16_to_cpu(event_data->PhysDiskDevHandle);
4573 state = le32_to_cpu(event_data->NewValue);
4575 dewtprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: handle(0x%04x), "
4576 "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle,
4577 le32_to_cpu(event_data->PreviousValue), state));
4579 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4580 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
4581 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4585 case MPI2_RAID_PD_STATE_OFFLINE:
4587 _scsih_remove_device(ioc, handle);
4590 case MPI2_RAID_PD_STATE_ONLINE:
4591 case MPI2_RAID_PD_STATE_DEGRADED:
4592 case MPI2_RAID_PD_STATE_REBUILDING:
4593 case MPI2_RAID_PD_STATE_OPTIMAL:
4595 sas_device->hidden_raid_component = 1;
4597 _scsih_add_device(ioc, handle, 0, 1);
4600 case MPI2_RAID_PD_STATE_NOT_CONFIGURED:
4601 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE:
4602 case MPI2_RAID_PD_STATE_HOT_SPARE:
4608 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4610 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
4611 * @ioc: per adapter object
4612 * @event_data: event data payload
4618 _scsih_sas_ir_operation_status_event_debug(struct MPT2SAS_ADAPTER *ioc,
4619 Mpi2EventDataIrOperationStatus_t *event_data)
4621 char *reason_str = NULL;
4623 switch (event_data->RAIDOperation) {
4624 case MPI2_EVENT_IR_RAIDOP_RESYNC:
4625 reason_str = "resync";
4627 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION:
4628 reason_str = "online capacity expansion";
4630 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK:
4631 reason_str = "consistency check";
4634 reason_str = "unknown reason";
4638 printk(MPT2SAS_INFO_FMT "raid operational status: (%s)"
4639 "\thandle(0x%04x), percent complete(%d)\n",
4640 ioc->name, reason_str,
4641 le16_to_cpu(event_data->VolDevHandle),
4642 event_data->PercentComplete);
4647 * _scsih_sas_ir_operation_status_event - handle RAID operation events
4648 * @ioc: per adapter object
4650 * @event_data: event data payload
4656 _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc, u8 VF_ID,
4657 Mpi2EventDataIrOperationStatus_t *event_data)
4659 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4660 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
4661 _scsih_sas_ir_operation_status_event_debug(ioc, event_data);
4666 * _scsih_task_set_full - handle task set full
4667 * @ioc: per adapter object
4668 * @event_data: event data payload
4671 * Throttle back qdepth.
4674 _scsih_task_set_full(struct MPT2SAS_ADAPTER *ioc, u8 VF_ID,
4675 Mpi2EventDataTaskSetFull_t *event_data)
4677 unsigned long flags;
4678 struct _sas_device *sas_device;
4679 static struct _raid_device *raid_device;
4680 struct scsi_device *sdev;
4687 current_depth = le16_to_cpu(event_data->CurrentDepth);
4688 handle = le16_to_cpu(event_data->DevHandle);
4689 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4690 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
4692 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4695 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4696 id = sas_device->id;
4697 channel = sas_device->channel;
4698 sas_address = sas_device->sas_address;
4700 /* if hidden raid component, then change to volume characteristics */
4701 if (sas_device->hidden_raid_component && sas_device->volume_handle) {
4702 spin_lock_irqsave(&ioc->raid_device_lock, flags);
4703 raid_device = _scsih_raid_device_find_by_handle(
4704 ioc, sas_device->volume_handle);
4705 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
4707 id = raid_device->id;
4708 channel = raid_device->channel;
4709 handle = raid_device->handle;
4710 sas_address = raid_device->wwid;
4714 if (ioc->logging_level & MPT_DEBUG_TASK_SET_FULL)
4715 starget_printk(KERN_DEBUG, sas_device->starget, "task set "
4716 "full: handle(0x%04x), sas_addr(0x%016llx), depth(%d)\n",
4717 handle, (unsigned long long)sas_address, current_depth);
4719 shost_for_each_device(sdev, ioc->shost) {
4720 if (sdev->id == id && sdev->channel == channel) {
4721 if (current_depth > sdev->queue_depth) {
4722 if (ioc->logging_level &
4723 MPT_DEBUG_TASK_SET_FULL)
4724 sdev_printk(KERN_INFO, sdev, "strange "
4725 "observation, the queue depth is"
4726 " (%d) meanwhile fw queue depth "
4727 "is (%d)\n", sdev->queue_depth,
4731 depth = scsi_track_queue_full(sdev,
4734 sdev_printk(KERN_INFO, sdev, "Queue depth "
4735 "reduced to (%d)\n", depth);
4737 sdev_printk(KERN_INFO, sdev, "Tagged Command "
4738 "Queueing is being disabled\n");
4739 else if (depth == 0)
4740 if (ioc->logging_level &
4741 MPT_DEBUG_TASK_SET_FULL)
4742 sdev_printk(KERN_INFO, sdev,
4743 "Queue depth not changed yet\n");
4749 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
4750 * @ioc: per adapter object
4751 * @sas_address: sas address
4752 * @slot: enclosure slot id
4753 * @handle: device handle
4755 * After host reset, find out whether devices are still responding.
4756 * Used in _scsi_remove_unresponsive_sas_devices.
4761 _scsih_mark_responding_sas_device(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
4762 u16 slot, u16 handle)
4764 struct MPT2SAS_TARGET *sas_target_priv_data;
4765 struct scsi_target *starget;
4766 struct _sas_device *sas_device;
4767 unsigned long flags;
4769 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4770 list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
4771 if (sas_device->sas_address == sas_address &&
4772 sas_device->slot == slot && sas_device->starget) {
4773 sas_device->responding = 1;
4774 starget_printk(KERN_INFO, sas_device->starget,
4775 "handle(0x%04x), sas_addr(0x%016llx), enclosure "
4776 "logical id(0x%016llx), slot(%d)\n", handle,
4777 (unsigned long long)sas_device->sas_address,
4778 (unsigned long long)
4779 sas_device->enclosure_logical_id,
4781 if (sas_device->handle == handle)
4783 printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n",
4784 sas_device->handle);
4785 sas_device->handle = handle;
4786 starget = sas_device->starget;
4787 sas_target_priv_data = starget->hostdata;
4788 sas_target_priv_data->handle = handle;
4793 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4797 * _scsih_search_responding_sas_devices -
4798 * @ioc: per adapter object
4800 * After host reset, find out whether devices are still responding.
4806 _scsih_search_responding_sas_devices(struct MPT2SAS_ADAPTER *ioc)
4808 Mpi2SasDevicePage0_t sas_device_pg0;
4809 Mpi2ConfigReply_t mpi_reply;
4816 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, __func__);
4818 if (list_empty(&ioc->sas_device_list))
4822 while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
4823 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
4825 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4826 MPI2_IOCSTATUS_MASK;
4827 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
4829 handle = le16_to_cpu(sas_device_pg0.DevHandle);
4830 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
4831 if (!(_scsih_is_end_device(device_info)))
4833 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
4834 slot = le16_to_cpu(sas_device_pg0.Slot);
4835 _scsih_mark_responding_sas_device(ioc, sas_address, slot,
4841 * _scsih_mark_responding_raid_device - mark a raid_device as responding
4842 * @ioc: per adapter object
4843 * @wwid: world wide identifier for raid volume
4844 * @handle: device handle
4846 * After host reset, find out whether devices are still responding.
4847 * Used in _scsi_remove_unresponsive_raid_devices.
4852 _scsih_mark_responding_raid_device(struct MPT2SAS_ADAPTER *ioc, u64 wwid,
4855 struct MPT2SAS_TARGET *sas_target_priv_data;
4856 struct scsi_target *starget;
4857 struct _raid_device *raid_device;
4858 unsigned long flags;
4860 spin_lock_irqsave(&ioc->raid_device_lock, flags);
4861 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
4862 if (raid_device->wwid == wwid && raid_device->starget) {
4863 raid_device->responding = 1;
4864 starget_printk(KERN_INFO, raid_device->starget,
4865 "handle(0x%04x), wwid(0x%016llx)\n", handle,
4866 (unsigned long long)raid_device->wwid);
4867 if (raid_device->handle == handle)
4869 printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n",
4870 raid_device->handle);
4871 raid_device->handle = handle;
4872 starget = raid_device->starget;
4873 sas_target_priv_data = starget->hostdata;
4874 sas_target_priv_data->handle = handle;
4879 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
4883 * _scsih_search_responding_raid_devices -
4884 * @ioc: per adapter object
4886 * After host reset, find out whether devices are still responding.
4892 _scsih_search_responding_raid_devices(struct MPT2SAS_ADAPTER *ioc)
4894 Mpi2RaidVolPage1_t volume_pg1;
4895 Mpi2ConfigReply_t mpi_reply;
4899 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, __func__);
4901 if (list_empty(&ioc->raid_device_list))
4905 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
4906 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
4907 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4908 MPI2_IOCSTATUS_MASK;
4909 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
4911 handle = le16_to_cpu(volume_pg1.DevHandle);
4912 _scsih_mark_responding_raid_device(ioc,
4913 le64_to_cpu(volume_pg1.WWID), handle);
4918 * _scsih_mark_responding_expander - mark a expander as responding
4919 * @ioc: per adapter object
4920 * @sas_address: sas address
4923 * After host reset, find out whether devices are still responding.
4924 * Used in _scsi_remove_unresponsive_expanders.
4929 _scsih_mark_responding_expander(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
4932 struct _sas_node *sas_expander;
4933 unsigned long flags;
4935 spin_lock_irqsave(&ioc->sas_node_lock, flags);
4936 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
4937 if (sas_expander->sas_address == sas_address) {
4938 sas_expander->responding = 1;
4939 if (sas_expander->handle != handle) {
4940 printk(KERN_INFO "old handle(0x%04x)\n",
4941 sas_expander->handle);
4942 sas_expander->handle = handle;
4948 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4952 * _scsih_search_responding_expanders -
4953 * @ioc: per adapter object
4955 * After host reset, find out whether devices are still responding.
4961 _scsih_search_responding_expanders(struct MPT2SAS_ADAPTER *ioc)
4963 Mpi2ExpanderPage0_t expander_pg0;
4964 Mpi2ConfigReply_t mpi_reply;
4969 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, __func__);
4971 if (list_empty(&ioc->sas_expander_list))
4975 while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
4976 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
4978 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4979 MPI2_IOCSTATUS_MASK;
4980 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
4983 handle = le16_to_cpu(expander_pg0.DevHandle);
4984 sas_address = le64_to_cpu(expander_pg0.SASAddress);
4985 printk(KERN_INFO "\texpander present: handle(0x%04x), "
4986 "sas_addr(0x%016llx)\n", handle,
4987 (unsigned long long)sas_address);
4988 _scsih_mark_responding_expander(ioc, sas_address, handle);
4994 * _scsih_remove_unresponding_devices - removing unresponding devices
4995 * @ioc: per adapter object
5000 _scsih_remove_unresponding_devices(struct MPT2SAS_ADAPTER *ioc)
5002 struct _sas_device *sas_device, *sas_device_next;
5003 struct _sas_node *sas_expander, *sas_expander_next;
5004 struct _raid_device *raid_device, *raid_device_next;
5005 unsigned long flags;
5007 _scsih_search_responding_sas_devices(ioc);
5008 _scsih_search_responding_raid_devices(ioc);
5009 _scsih_search_responding_expanders(ioc);
5011 spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags);
5012 ioc->shost_recovery = 0;
5013 if (ioc->shost->shost_state == SHOST_RECOVERY) {
5014 printk(MPT2SAS_INFO_FMT "putting controller into "
5015 "SHOST_RUNNING\n", ioc->name);
5016 scsi_host_set_state(ioc->shost, SHOST_RUNNING);
5018 spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags);
5020 list_for_each_entry_safe(sas_device, sas_device_next,
5021 &ioc->sas_device_list, list) {
5022 if (sas_device->responding) {
5023 sas_device->responding = 0;
5026 if (sas_device->starget)
5027 starget_printk(KERN_INFO, sas_device->starget,
5028 "removing: handle(0x%04x), sas_addr(0x%016llx), "
5029 "enclosure logical id(0x%016llx), slot(%d)\n",
5031 (unsigned long long)sas_device->sas_address,
5032 (unsigned long long)
5033 sas_device->enclosure_logical_id,
5035 _scsih_remove_device(ioc, sas_device->handle);
5038 list_for_each_entry_safe(raid_device, raid_device_next,
5039 &ioc->raid_device_list, list) {
5040 if (raid_device->responding) {
5041 raid_device->responding = 0;
5044 if (raid_device->starget) {
5045 starget_printk(KERN_INFO, raid_device->starget,
5046 "removing: handle(0x%04x), wwid(0x%016llx)\n",
5047 raid_device->handle,
5048 (unsigned long long)raid_device->wwid);
5049 scsi_remove_target(&raid_device->starget->dev);
5051 _scsih_raid_device_remove(ioc, raid_device);
5054 list_for_each_entry_safe(sas_expander, sas_expander_next,
5055 &ioc->sas_expander_list, list) {
5056 if (sas_expander->responding) {
5057 sas_expander->responding = 0;
5060 printk("\tremoving expander: handle(0x%04x), "
5061 " sas_addr(0x%016llx)\n", sas_expander->handle,
5062 (unsigned long long)sas_expander->sas_address);
5063 _scsih_expander_remove(ioc, sas_expander->handle);
5068 * _firmware_event_work - delayed task for processing firmware events
5069 * @ioc: per adapter object
5070 * @work: equal to the fw_event_work object
5076 _firmware_event_work(struct work_struct *work)
5078 struct fw_event_work *fw_event = container_of(work,
5079 struct fw_event_work, work);
5080 unsigned long flags;
5081 struct MPT2SAS_ADAPTER *ioc = fw_event->ioc;
5083 /* This is invoked by calling _scsih_queue_rescan(). */
5084 if (fw_event->event == MPT2SAS_RESCAN_AFTER_HOST_RESET) {
5085 _scsih_fw_event_free(ioc, fw_event);
5086 _scsih_sas_host_refresh(ioc, 1);
5087 _scsih_remove_unresponding_devices(ioc);
5091 /* the queue is being flushed so ignore this event */
5092 spin_lock_irqsave(&ioc->fw_event_lock, flags);
5093 if (ioc->fw_events_off || ioc->remove_host) {
5094 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
5095 _scsih_fw_event_free(ioc, fw_event);
5098 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
5100 spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags);
5101 if (ioc->shost_recovery) {
5102 spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags);
5103 _scsih_fw_event_requeue(ioc, fw_event, 1000);
5106 spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags);
5108 switch (fw_event->event) {
5109 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
5110 _scsih_sas_topology_change_event(ioc, fw_event->VF_ID,
5111 fw_event->event_data, fw_event);
5113 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
5114 _scsih_sas_device_status_change_event(ioc, fw_event->VF_ID,
5115 fw_event->event_data);
5117 case MPI2_EVENT_SAS_DISCOVERY:
5118 _scsih_sas_discovery_event(ioc, fw_event->VF_ID,
5119 fw_event->event_data);
5121 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
5122 _scsih_sas_broadcast_primative_event(ioc, fw_event->VF_ID,
5123 fw_event->event_data);
5125 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
5126 _scsih_sas_enclosure_dev_status_change_event(ioc,
5127 fw_event->VF_ID, fw_event->event_data);
5129 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
5130 _scsih_sas_ir_config_change_event(ioc, fw_event->VF_ID,
5131 fw_event->event_data);
5133 case MPI2_EVENT_IR_VOLUME:
5134 _scsih_sas_ir_volume_event(ioc, fw_event->VF_ID,
5135 fw_event->event_data);
5137 case MPI2_EVENT_IR_PHYSICAL_DISK:
5138 _scsih_sas_ir_physical_disk_event(ioc, fw_event->VF_ID,
5139 fw_event->event_data);
5141 case MPI2_EVENT_IR_OPERATION_STATUS:
5142 _scsih_sas_ir_operation_status_event(ioc, fw_event->VF_ID,
5143 fw_event->event_data);
5145 case MPI2_EVENT_TASK_SET_FULL:
5146 _scsih_task_set_full(ioc, fw_event->VF_ID,
5147 fw_event->event_data);
5150 _scsih_fw_event_free(ioc, fw_event);
5154 * mpt2sas_scsih_event_callback - firmware event handler (called at ISR time)
5155 * @ioc: per adapter object
5156 * @VF_ID: virtual function id
5157 * @reply: reply message frame(lower 32bit addr)
5158 * Context: interrupt.
5160 * This function merely adds a new work task into ioc->firmware_event_thread.
5161 * The tasks are worked from _firmware_event_work in user context.
5166 mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER *ioc, u8 VF_ID, u32 reply)
5168 struct fw_event_work *fw_event;
5169 Mpi2EventNotificationReply_t *mpi_reply;
5170 unsigned long flags;
5173 /* events turned off due to host reset or driver unloading */
5174 spin_lock_irqsave(&ioc->fw_event_lock, flags);
5175 if (ioc->fw_events_off || ioc->remove_host) {
5176 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
5179 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
5181 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
5182 event = le16_to_cpu(mpi_reply->Event);
5186 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
5188 Mpi2EventDataSasBroadcastPrimitive_t *baen_data =
5189 (Mpi2EventDataSasBroadcastPrimitive_t *)
5190 mpi_reply->EventData;
5192 if (baen_data->Primitive !=
5193 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT ||
5194 ioc->broadcast_aen_busy)
5196 ioc->broadcast_aen_busy = 1;
5200 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
5201 _scsih_check_topo_delete_events(ioc,
5202 (Mpi2EventDataSasTopologyChangeList_t *)
5203 mpi_reply->EventData);
5206 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
5207 case MPI2_EVENT_IR_OPERATION_STATUS:
5208 case MPI2_EVENT_SAS_DISCOVERY:
5209 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
5210 case MPI2_EVENT_IR_VOLUME:
5211 case MPI2_EVENT_IR_PHYSICAL_DISK:
5212 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
5213 case MPI2_EVENT_TASK_SET_FULL:
5216 default: /* ignore the rest */
5220 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
5222 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5223 ioc->name, __FILE__, __LINE__, __func__);
5226 fw_event->event_data =
5227 kzalloc(mpi_reply->EventDataLength*4, GFP_ATOMIC);
5228 if (!fw_event->event_data) {
5229 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5230 ioc->name, __FILE__, __LINE__, __func__);
5235 memcpy(fw_event->event_data, mpi_reply->EventData,
5236 mpi_reply->EventDataLength*4);
5237 fw_event->ioc = ioc;
5238 fw_event->VF_ID = VF_ID;
5239 fw_event->event = event;
5240 _scsih_fw_event_add(ioc, fw_event);
5243 /* shost template */
5244 static struct scsi_host_template scsih_driver_template = {
5245 .module = THIS_MODULE,
5246 .name = "Fusion MPT SAS Host",
5247 .proc_name = MPT2SAS_DRIVER_NAME,
5248 .queuecommand = scsih_qcmd,
5249 .target_alloc = scsih_target_alloc,
5250 .slave_alloc = scsih_slave_alloc,
5251 .slave_configure = scsih_slave_configure,
5252 .target_destroy = scsih_target_destroy,
5253 .slave_destroy = scsih_slave_destroy,
5254 .change_queue_depth = scsih_change_queue_depth,
5255 .change_queue_type = scsih_change_queue_type,
5256 .eh_abort_handler = scsih_abort,
5257 .eh_device_reset_handler = scsih_dev_reset,
5258 .eh_host_reset_handler = scsih_host_reset,
5259 .bios_param = scsih_bios_param,
5262 .sg_tablesize = MPT2SAS_SG_DEPTH,
5263 .max_sectors = 8192,
5265 .use_clustering = ENABLE_CLUSTERING,
5266 .shost_attrs = mpt2sas_host_attrs,
5267 .sdev_attrs = mpt2sas_dev_attrs,
5271 * _scsih_expander_node_remove - removing expander device from list.
5272 * @ioc: per adapter object
5273 * @sas_expander: the sas_device object
5274 * Context: Calling function should acquire ioc->sas_node_lock.
5276 * Removing object and freeing associated memory from the
5277 * ioc->sas_expander_list.
5282 _scsih_expander_node_remove(struct MPT2SAS_ADAPTER *ioc,
5283 struct _sas_node *sas_expander)
5285 struct _sas_port *mpt2sas_port;
5286 struct _sas_device *sas_device;
5287 struct _sas_node *expander_sibling;
5288 unsigned long flags;
5293 /* remove sibling ports attached to this expander */
5294 retry_device_search:
5295 list_for_each_entry(mpt2sas_port,
5296 &sas_expander->sas_port_list, port_list) {
5297 if (mpt2sas_port->remote_identify.device_type ==
5299 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5301 mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5302 mpt2sas_port->remote_identify.sas_address);
5303 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5306 _scsih_remove_device(ioc, sas_device->handle);
5307 goto retry_device_search;
5311 retry_expander_search:
5312 list_for_each_entry(mpt2sas_port,
5313 &sas_expander->sas_port_list, port_list) {
5315 if (mpt2sas_port->remote_identify.device_type ==
5316 MPI2_SAS_DEVICE_INFO_EDGE_EXPANDER ||
5317 mpt2sas_port->remote_identify.device_type ==
5318 MPI2_SAS_DEVICE_INFO_FANOUT_EXPANDER) {
5320 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5322 mpt2sas_scsih_expander_find_by_sas_address(
5323 ioc, mpt2sas_port->remote_identify.sas_address);
5324 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5325 if (!expander_sibling)
5327 _scsih_expander_remove(ioc, expander_sibling->handle);
5328 goto retry_expander_search;
5332 mpt2sas_transport_port_remove(ioc, sas_expander->sas_address,
5333 sas_expander->parent_handle);
5335 printk(MPT2SAS_INFO_FMT "expander_remove: handle"
5336 "(0x%04x), sas_addr(0x%016llx)\n", ioc->name,
5337 sas_expander->handle, (unsigned long long)
5338 sas_expander->sas_address);
5340 list_del(&sas_expander->list);
5341 kfree(sas_expander->phy);
5342 kfree(sas_expander);
5346 * scsih_remove - detach and remove add host
5347 * @pdev: PCI device struct
5351 static void __devexit
5352 scsih_remove(struct pci_dev *pdev)
5354 struct Scsi_Host *shost = pci_get_drvdata(pdev);
5355 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
5356 struct _sas_port *mpt2sas_port;
5357 struct _sas_device *sas_device;
5358 struct _sas_node *expander_sibling;
5359 struct workqueue_struct *wq;
5360 unsigned long flags;
5362 ioc->remove_host = 1;
5363 _scsih_fw_event_off(ioc);
5365 spin_lock_irqsave(&ioc->fw_event_lock, flags);
5366 wq = ioc->firmware_event_thread;
5367 ioc->firmware_event_thread = NULL;
5368 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
5370 destroy_workqueue(wq);
5372 /* free ports attached to the sas_host */
5374 list_for_each_entry(mpt2sas_port,
5375 &ioc->sas_hba.sas_port_list, port_list) {
5376 if (mpt2sas_port->remote_identify.device_type ==
5379 mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5380 mpt2sas_port->remote_identify.sas_address);
5382 _scsih_remove_device(ioc, sas_device->handle);
5387 mpt2sas_scsih_expander_find_by_sas_address(ioc,
5388 mpt2sas_port->remote_identify.sas_address);
5389 if (expander_sibling) {
5390 _scsih_expander_remove(ioc,
5391 expander_sibling->handle);
5397 /* free phys attached to the sas_host */
5398 if (ioc->sas_hba.num_phys) {
5399 kfree(ioc->sas_hba.phy);
5400 ioc->sas_hba.phy = NULL;
5401 ioc->sas_hba.num_phys = 0;
5404 sas_remove_host(shost);
5405 mpt2sas_base_detach(ioc);
5406 list_del(&ioc->list);
5407 scsi_remove_host(shost);
5408 scsi_host_put(shost);
5412 * _scsih_probe_boot_devices - reports 1st device
5413 * @ioc: per adapter object
5415 * If specified in bios page 2, this routine reports the 1st
5416 * device scsi-ml or sas transport for persistent boot device
5417 * purposes. Please refer to function _scsih_determine_boot_device()
5420 _scsih_probe_boot_devices(struct MPT2SAS_ADAPTER *ioc)
5424 struct _sas_device *sas_device;
5425 struct _raid_device *raid_device;
5426 u16 handle, parent_handle;
5428 unsigned long flags;
5432 if (ioc->req_boot_device.device) {
5433 device = ioc->req_boot_device.device;
5434 is_raid = ioc->req_boot_device.is_raid;
5435 } else if (ioc->req_alt_boot_device.device) {
5436 device = ioc->req_alt_boot_device.device;
5437 is_raid = ioc->req_alt_boot_device.is_raid;
5438 } else if (ioc->current_boot_device.device) {
5439 device = ioc->current_boot_device.device;
5440 is_raid = ioc->current_boot_device.is_raid;
5447 raid_device = device;
5448 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
5449 raid_device->id, 0);
5451 _scsih_raid_device_remove(ioc, raid_device);
5453 sas_device = device;
5454 handle = sas_device->handle;
5455 parent_handle = sas_device->parent_handle;
5456 sas_address = sas_device->sas_address;
5457 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5458 list_move_tail(&sas_device->list, &ioc->sas_device_list);
5459 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5460 if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
5461 sas_device->parent_handle)) {
5462 _scsih_sas_device_remove(ioc, sas_device);
5463 } else if (!sas_device->starget) {
5464 mpt2sas_transport_port_remove(ioc, sas_address,
5466 _scsih_sas_device_remove(ioc, sas_device);
5472 * _scsih_probe_raid - reporting raid volumes to scsi-ml
5473 * @ioc: per adapter object
5475 * Called during initial loading of the driver.
5478 _scsih_probe_raid(struct MPT2SAS_ADAPTER *ioc)
5480 struct _raid_device *raid_device, *raid_next;
5483 list_for_each_entry_safe(raid_device, raid_next,
5484 &ioc->raid_device_list, list) {
5485 if (raid_device->starget)
5487 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
5488 raid_device->id, 0);
5490 _scsih_raid_device_remove(ioc, raid_device);
5495 * _scsih_probe_sas - reporting raid volumes to sas transport
5496 * @ioc: per adapter object
5498 * Called during initial loading of the driver.
5501 _scsih_probe_sas(struct MPT2SAS_ADAPTER *ioc)
5503 struct _sas_device *sas_device, *next;
5504 unsigned long flags;
5505 u16 handle, parent_handle;
5508 /* SAS Device List */
5509 list_for_each_entry_safe(sas_device, next, &ioc->sas_device_init_list,
5511 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5512 list_move_tail(&sas_device->list, &ioc->sas_device_list);
5513 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5515 handle = sas_device->handle;
5516 parent_handle = sas_device->parent_handle;
5517 sas_address = sas_device->sas_address;
5518 if (!mpt2sas_transport_port_add(ioc, handle, parent_handle)) {
5519 _scsih_sas_device_remove(ioc, sas_device);
5520 } else if (!sas_device->starget) {
5521 mpt2sas_transport_port_remove(ioc, sas_address,
5523 _scsih_sas_device_remove(ioc, sas_device);
5529 * _scsih_probe_devices - probing for devices
5530 * @ioc: per adapter object
5532 * Called during initial loading of the driver.
5535 _scsih_probe_devices(struct MPT2SAS_ADAPTER *ioc)
5537 u16 volume_mapping_flags =
5538 le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) &
5539 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE;
5541 if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR))
5542 return; /* return when IOC doesn't support initiator mode */
5544 _scsih_probe_boot_devices(ioc);
5546 if (ioc->ir_firmware) {
5547 if ((volume_mapping_flags &
5548 MPI2_IOCPAGE8_IRFLAGS_HIGH_VOLUME_MAPPING)) {
5549 _scsih_probe_sas(ioc);
5550 _scsih_probe_raid(ioc);
5552 _scsih_probe_raid(ioc);
5553 _scsih_probe_sas(ioc);
5556 _scsih_probe_sas(ioc);
5560 * scsih_probe - attach and add scsi host
5561 * @pdev: PCI device struct
5562 * @id: pci device id
5564 * Returns 0 success, anything else error.
5567 scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id)
5569 struct MPT2SAS_ADAPTER *ioc;
5570 struct Scsi_Host *shost;
5572 shost = scsi_host_alloc(&scsih_driver_template,
5573 sizeof(struct MPT2SAS_ADAPTER));
5577 /* init local params */
5578 ioc = shost_priv(shost);
5579 memset(ioc, 0, sizeof(struct MPT2SAS_ADAPTER));
5580 INIT_LIST_HEAD(&ioc->list);
5581 list_add_tail(&ioc->list, &mpt2sas_ioc_list);
5583 ioc->id = mpt_ids++;
5584 sprintf(ioc->name, "%s%d", MPT2SAS_DRIVER_NAME, ioc->id);
5586 ioc->scsi_io_cb_idx = scsi_io_cb_idx;
5587 ioc->tm_cb_idx = tm_cb_idx;
5588 ioc->ctl_cb_idx = ctl_cb_idx;
5589 ioc->base_cb_idx = base_cb_idx;
5590 ioc->transport_cb_idx = transport_cb_idx;
5591 ioc->config_cb_idx = config_cb_idx;
5592 ioc->logging_level = logging_level;
5593 /* misc semaphores and spin locks */
5594 spin_lock_init(&ioc->ioc_reset_in_progress_lock);
5595 spin_lock_init(&ioc->scsi_lookup_lock);
5596 spin_lock_init(&ioc->sas_device_lock);
5597 spin_lock_init(&ioc->sas_node_lock);
5598 spin_lock_init(&ioc->fw_event_lock);
5599 spin_lock_init(&ioc->raid_device_lock);
5601 INIT_LIST_HEAD(&ioc->sas_device_list);
5602 INIT_LIST_HEAD(&ioc->sas_device_init_list);
5603 INIT_LIST_HEAD(&ioc->sas_expander_list);
5604 INIT_LIST_HEAD(&ioc->fw_event_list);
5605 INIT_LIST_HEAD(&ioc->raid_device_list);
5606 INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list);
5608 /* init shost parameters */
5609 shost->max_cmd_len = 16;
5610 shost->max_lun = max_lun;
5611 shost->transportt = mpt2sas_transport_template;
5612 shost->unique_id = ioc->id;
5614 if ((scsi_add_host(shost, &pdev->dev))) {
5615 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5616 ioc->name, __FILE__, __LINE__, __func__);
5617 list_del(&ioc->list);
5618 goto out_add_shost_fail;
5621 scsi_host_set_prot(shost, SHOST_DIF_TYPE1_PROTECTION
5622 | SHOST_DIF_TYPE3_PROTECTION);
5625 snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name),
5626 "fw_event%d", ioc->id);
5627 ioc->firmware_event_thread = create_singlethread_workqueue(
5628 ioc->firmware_event_name);
5629 if (!ioc->firmware_event_thread) {
5630 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5631 ioc->name, __FILE__, __LINE__, __func__);
5632 goto out_thread_fail;
5635 ioc->wait_for_port_enable_to_complete = 1;
5636 if ((mpt2sas_base_attach(ioc))) {
5637 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5638 ioc->name, __FILE__, __LINE__, __func__);
5639 goto out_attach_fail;
5642 ioc->wait_for_port_enable_to_complete = 0;
5643 _scsih_probe_devices(ioc);
5647 destroy_workqueue(ioc->firmware_event_thread);
5649 list_del(&ioc->list);
5650 scsi_remove_host(shost);
5657 * scsih_suspend - power management suspend main entry point
5658 * @pdev: PCI device struct
5659 * @state: PM state change to (usually PCI_D3)
5661 * Returns 0 success, anything else error.
5664 scsih_suspend(struct pci_dev *pdev, pm_message_t state)
5666 struct Scsi_Host *shost = pci_get_drvdata(pdev);
5667 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
5670 flush_scheduled_work();
5671 scsi_block_requests(shost);
5672 device_state = pci_choose_state(pdev, state);
5673 printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, entering "
5674 "operating state [D%d]\n", ioc->name, pdev,
5675 pci_name(pdev), device_state);
5677 mpt2sas_base_free_resources(ioc);
5678 pci_save_state(pdev);
5679 pci_disable_device(pdev);
5680 pci_set_power_state(pdev, device_state);
5685 * scsih_resume - power management resume main entry point
5686 * @pdev: PCI device struct
5688 * Returns 0 success, anything else error.
5691 scsih_resume(struct pci_dev *pdev)
5693 struct Scsi_Host *shost = pci_get_drvdata(pdev);
5694 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
5695 u32 device_state = pdev->current_state;
5698 printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, previous "
5699 "operating state [D%d]\n", ioc->name, pdev,
5700 pci_name(pdev), device_state);
5702 pci_set_power_state(pdev, PCI_D0);
5703 pci_enable_wake(pdev, PCI_D0, 0);
5704 pci_restore_state(pdev);
5706 r = mpt2sas_base_map_resources(ioc);
5710 mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, SOFT_RESET);
5711 scsi_unblock_requests(shost);
5714 #endif /* CONFIG_PM */
5717 static struct pci_driver scsih_driver = {
5718 .name = MPT2SAS_DRIVER_NAME,
5719 .id_table = scsih_pci_table,
5720 .probe = scsih_probe,
5721 .remove = __devexit_p(scsih_remove),
5723 .suspend = scsih_suspend,
5724 .resume = scsih_resume,
5730 * scsih_init - main entry point for this driver.
5732 * Returns 0 success, anything else error.
5740 printk(KERN_INFO "%s version %s loaded\n", MPT2SAS_DRIVER_NAME,
5741 MPT2SAS_DRIVER_VERSION);
5743 mpt2sas_transport_template =
5744 sas_attach_transport(&mpt2sas_transport_functions);
5745 if (!mpt2sas_transport_template)
5748 mpt2sas_base_initialize_callback_handler();
5750 /* queuecommand callback hander */
5751 scsi_io_cb_idx = mpt2sas_base_register_callback_handler(scsih_io_done);
5753 /* task managment callback handler */
5754 tm_cb_idx = mpt2sas_base_register_callback_handler(scsih_tm_done);
5756 /* base internal commands callback handler */
5757 base_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_base_done);
5759 /* transport internal commands callback handler */
5760 transport_cb_idx = mpt2sas_base_register_callback_handler(
5761 mpt2sas_transport_done);
5763 /* configuration page API internal commands callback handler */
5764 config_cb_idx = mpt2sas_base_register_callback_handler(
5765 mpt2sas_config_done);
5767 /* ctl module callback handler */
5768 ctl_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_ctl_done);
5772 error = pci_register_driver(&scsih_driver);
5774 sas_release_transport(mpt2sas_transport_template);
5780 * scsih_exit - exit point for this driver (when it is a module).
5782 * Returns 0 success, anything else error.
5787 printk(KERN_INFO "mpt2sas version %s unloading\n",
5788 MPT2SAS_DRIVER_VERSION);
5790 pci_unregister_driver(&scsih_driver);
5792 sas_release_transport(mpt2sas_transport_template);
5793 mpt2sas_base_release_callback_handler(scsi_io_cb_idx);
5794 mpt2sas_base_release_callback_handler(tm_cb_idx);
5795 mpt2sas_base_release_callback_handler(base_cb_idx);
5796 mpt2sas_base_release_callback_handler(transport_cb_idx);
5797 mpt2sas_base_release_callback_handler(config_cb_idx);
5798 mpt2sas_base_release_callback_handler(ctl_cb_idx);
5803 module_init(scsih_init);
5804 module_exit(scsih_exit);