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
107 * struct fw_event_work - firmware event struct
108 * @list: link list framework
109 * @work: work object (ioc->fault_reset_work_q)
110 * @ioc: per adapter object
111 * @VF_ID: virtual function id
112 * @host_reset_handling: handling events during host reset
113 * @ignore: flag meaning this event has been marked to ignore
114 * @event: firmware event MPI2_EVENT_XXX defined in mpt2_ioc.h
115 * @event_data: reply event data payload follows
117 * This object stored on ioc->fw_event_list.
119 struct fw_event_work {
120 struct list_head list;
121 struct work_struct work;
122 struct MPT2SAS_ADAPTER *ioc;
124 u8 host_reset_handling;
131 * struct _scsi_io_transfer - scsi io transfer
132 * @handle: sas device handle (assigned by firmware)
133 * @is_raid: flag set for hidden raid components
134 * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE,
135 * @data_length: data transfer length
136 * @data_dma: dma pointer to data
139 * @cdb_length: cdb length
141 * @valid_reply: flag set for reply message
142 * @timeout: timeout for this command
143 * @sense_length: sense length
144 * @ioc_status: ioc status
145 * @scsi_state: scsi state
146 * @scsi_status: scsi staus
147 * @log_info: log information
148 * @transfer_length: data length transfer when there is a reply message
150 * Used for sending internal scsi commands to devices within this module.
151 * Refer to _scsi_send_scsi_io().
153 struct _scsi_io_transfer {
156 enum dma_data_direction dir;
159 u8 sense[SCSI_SENSE_BUFFERSIZE];
165 /* the following bits are only valid when 'valid_reply = 1' */
175 * The pci device ids are defined in mpi/mpi2_cnfg.h.
177 static struct pci_device_id scsih_pci_table[] = {
178 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2004,
179 PCI_ANY_ID, PCI_ANY_ID },
181 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2008,
182 PCI_ANY_ID, PCI_ANY_ID },
183 /* Liberator ~ 2108 */
184 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_1,
185 PCI_ANY_ID, PCI_ANY_ID },
186 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_2,
187 PCI_ANY_ID, PCI_ANY_ID },
188 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_3,
189 PCI_ANY_ID, PCI_ANY_ID },
190 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_1,
191 PCI_ANY_ID, PCI_ANY_ID },
192 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_2,
193 PCI_ANY_ID, PCI_ANY_ID },
194 {0} /* Terminating entry */
196 MODULE_DEVICE_TABLE(pci, scsih_pci_table);
199 * _scsih_set_debug_level - global setting of ioc->logging_level.
201 * Note: The logging levels are defined in mpt2sas_debug.h.
204 _scsih_set_debug_level(const char *val, struct kernel_param *kp)
206 int ret = param_set_int(val, kp);
207 struct MPT2SAS_ADAPTER *ioc;
212 printk(KERN_INFO "setting logging_level(0x%08x)\n", logging_level);
213 list_for_each_entry(ioc, &mpt2sas_ioc_list, list)
214 ioc->logging_level = logging_level;
217 module_param_call(logging_level, _scsih_set_debug_level, param_get_int,
218 &logging_level, 0644);
221 * _scsih_srch_boot_sas_address - search based on sas_address
222 * @sas_address: sas address
223 * @boot_device: boot device object from bios page 2
225 * Returns 1 when there's a match, 0 means no match.
228 _scsih_srch_boot_sas_address(u64 sas_address,
229 Mpi2BootDeviceSasWwid_t *boot_device)
231 return (sas_address == le64_to_cpu(boot_device->SASAddress)) ? 1 : 0;
235 * _scsih_srch_boot_device_name - search based on device name
236 * @device_name: device name specified in INDENTIFY fram
237 * @boot_device: boot device object from bios page 2
239 * Returns 1 when there's a match, 0 means no match.
242 _scsih_srch_boot_device_name(u64 device_name,
243 Mpi2BootDeviceDeviceName_t *boot_device)
245 return (device_name == le64_to_cpu(boot_device->DeviceName)) ? 1 : 0;
249 * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot
250 * @enclosure_logical_id: enclosure logical id
251 * @slot_number: slot number
252 * @boot_device: boot device object from bios page 2
254 * Returns 1 when there's a match, 0 means no match.
257 _scsih_srch_boot_encl_slot(u64 enclosure_logical_id, u16 slot_number,
258 Mpi2BootDeviceEnclosureSlot_t *boot_device)
260 return (enclosure_logical_id == le64_to_cpu(boot_device->
261 EnclosureLogicalID) && slot_number == le16_to_cpu(boot_device->
262 SlotNumber)) ? 1 : 0;
266 * _scsih_is_boot_device - search for matching boot device.
267 * @sas_address: sas address
268 * @device_name: device name specified in INDENTIFY fram
269 * @enclosure_logical_id: enclosure logical id
270 * @slot_number: slot number
271 * @form: specifies boot device form
272 * @boot_device: boot device object from bios page 2
274 * Returns 1 when there's a match, 0 means no match.
277 _scsih_is_boot_device(u64 sas_address, u64 device_name,
278 u64 enclosure_logical_id, u16 slot, u8 form,
279 Mpi2BiosPage2BootDevice_t *boot_device)
284 case MPI2_BIOSPAGE2_FORM_SAS_WWID:
287 rc = _scsih_srch_boot_sas_address(
288 sas_address, &boot_device->SasWwid);
290 case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT:
291 if (!enclosure_logical_id)
293 rc = _scsih_srch_boot_encl_slot(
294 enclosure_logical_id,
295 slot, &boot_device->EnclosureSlot);
297 case MPI2_BIOSPAGE2_FORM_DEVICE_NAME:
300 rc = _scsih_srch_boot_device_name(
301 device_name, &boot_device->DeviceName);
303 case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED:
311 * _scsih_determine_boot_device - determine boot device.
312 * @ioc: per adapter object
313 * @device: either sas_device or raid_device object
314 * @is_raid: [flag] 1 = raid object, 0 = sas object
316 * Determines whether this device should be first reported device to
317 * to scsi-ml or sas transport, this purpose is for persistant boot device.
318 * There are primary, alternate, and current entries in bios page 2. The order
319 * priority is primary, alternate, then current. This routine saves
320 * the corresponding device object and is_raid flag in the ioc object.
321 * The saved data to be used later in _scsih_probe_boot_devices().
324 _scsih_determine_boot_device(struct MPT2SAS_ADAPTER *ioc,
325 void *device, u8 is_raid)
327 struct _sas_device *sas_device;
328 struct _raid_device *raid_device;
331 u64 enclosure_logical_id;
334 /* only process this function when driver loads */
335 if (!ioc->wait_for_port_enable_to_complete)
340 sas_address = sas_device->sas_address;
341 device_name = sas_device->device_name;
342 enclosure_logical_id = sas_device->enclosure_logical_id;
343 slot = sas_device->slot;
345 raid_device = device;
346 sas_address = raid_device->wwid;
348 enclosure_logical_id = 0;
352 if (!ioc->req_boot_device.device) {
353 if (_scsih_is_boot_device(sas_address, device_name,
354 enclosure_logical_id, slot,
355 (ioc->bios_pg2.ReqBootDeviceForm &
356 MPI2_BIOSPAGE2_FORM_MASK),
357 &ioc->bios_pg2.RequestedBootDevice)) {
358 dinitprintk(ioc, printk(MPT2SAS_DEBUG_FMT
359 "%s: req_boot_device(0x%016llx)\n",
361 (unsigned long long)sas_address));
362 ioc->req_boot_device.device = device;
363 ioc->req_boot_device.is_raid = is_raid;
367 if (!ioc->req_alt_boot_device.device) {
368 if (_scsih_is_boot_device(sas_address, device_name,
369 enclosure_logical_id, slot,
370 (ioc->bios_pg2.ReqAltBootDeviceForm &
371 MPI2_BIOSPAGE2_FORM_MASK),
372 &ioc->bios_pg2.RequestedAltBootDevice)) {
373 dinitprintk(ioc, printk(MPT2SAS_DEBUG_FMT
374 "%s: req_alt_boot_device(0x%016llx)\n",
376 (unsigned long long)sas_address));
377 ioc->req_alt_boot_device.device = device;
378 ioc->req_alt_boot_device.is_raid = is_raid;
382 if (!ioc->current_boot_device.device) {
383 if (_scsih_is_boot_device(sas_address, device_name,
384 enclosure_logical_id, slot,
385 (ioc->bios_pg2.CurrentBootDeviceForm &
386 MPI2_BIOSPAGE2_FORM_MASK),
387 &ioc->bios_pg2.CurrentBootDevice)) {
388 dinitprintk(ioc, printk(MPT2SAS_DEBUG_FMT
389 "%s: current_boot_device(0x%016llx)\n",
391 (unsigned long long)sas_address));
392 ioc->current_boot_device.device = device;
393 ioc->current_boot_device.is_raid = is_raid;
399 * mpt2sas_scsih_sas_device_find_by_sas_address - sas device search
400 * @ioc: per adapter object
401 * @sas_address: sas address
402 * Context: Calling function should acquire ioc->sas_device_lock
404 * This searches for sas_device based on sas_address, then return sas_device
408 mpt2sas_scsih_sas_device_find_by_sas_address(struct MPT2SAS_ADAPTER *ioc,
411 struct _sas_device *sas_device, *r;
414 /* check the sas_device_init_list */
415 list_for_each_entry(sas_device, &ioc->sas_device_init_list,
417 if (sas_device->sas_address != sas_address)
423 /* then check the sas_device_list */
424 list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
425 if (sas_device->sas_address != sas_address)
435 * _scsih_sas_device_find_by_handle - sas device search
436 * @ioc: per adapter object
437 * @handle: sas device handle (assigned by firmware)
438 * Context: Calling function should acquire ioc->sas_device_lock
440 * This searches for sas_device based on sas_address, then return sas_device
443 static struct _sas_device *
444 _scsih_sas_device_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
446 struct _sas_device *sas_device, *r;
449 if (ioc->wait_for_port_enable_to_complete) {
450 list_for_each_entry(sas_device, &ioc->sas_device_init_list,
452 if (sas_device->handle != handle)
458 list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
459 if (sas_device->handle != handle)
471 * _scsih_sas_device_remove - remove sas_device from list.
472 * @ioc: per adapter object
473 * @sas_device: the sas_device object
474 * Context: This function will acquire ioc->sas_device_lock.
476 * Removing object and freeing associated memory from the ioc->sas_device_list.
479 _scsih_sas_device_remove(struct MPT2SAS_ADAPTER *ioc,
480 struct _sas_device *sas_device)
484 spin_lock_irqsave(&ioc->sas_device_lock, flags);
485 list_del(&sas_device->list);
486 memset(sas_device, 0, sizeof(struct _sas_device));
488 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
492 * _scsih_sas_device_add - insert sas_device to the list.
493 * @ioc: per adapter object
494 * @sas_device: the sas_device object
495 * Context: This function will acquire ioc->sas_device_lock.
497 * Adding new object to the ioc->sas_device_list.
500 _scsih_sas_device_add(struct MPT2SAS_ADAPTER *ioc,
501 struct _sas_device *sas_device)
504 u16 handle, parent_handle;
507 dewtprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: handle"
508 "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
509 sas_device->handle, (unsigned long long)sas_device->sas_address));
511 spin_lock_irqsave(&ioc->sas_device_lock, flags);
512 list_add_tail(&sas_device->list, &ioc->sas_device_list);
513 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
515 handle = sas_device->handle;
516 parent_handle = sas_device->parent_handle;
517 sas_address = sas_device->sas_address;
518 if (!mpt2sas_transport_port_add(ioc, handle, parent_handle))
519 _scsih_sas_device_remove(ioc, sas_device);
523 * _scsih_sas_device_init_add - insert sas_device to the list.
524 * @ioc: per adapter object
525 * @sas_device: the sas_device object
526 * Context: This function will acquire ioc->sas_device_lock.
528 * Adding new object at driver load time to the ioc->sas_device_init_list.
531 _scsih_sas_device_init_add(struct MPT2SAS_ADAPTER *ioc,
532 struct _sas_device *sas_device)
536 dewtprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: handle"
537 "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
538 sas_device->handle, (unsigned long long)sas_device->sas_address));
540 spin_lock_irqsave(&ioc->sas_device_lock, flags);
541 list_add_tail(&sas_device->list, &ioc->sas_device_init_list);
542 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
543 _scsih_determine_boot_device(ioc, sas_device, 0);
547 * mpt2sas_scsih_expander_find_by_handle - expander device search
548 * @ioc: per adapter object
549 * @handle: expander handle (assigned by firmware)
550 * Context: Calling function should acquire ioc->sas_device_lock
552 * This searches for expander device based on handle, then returns the
556 mpt2sas_scsih_expander_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
558 struct _sas_node *sas_expander, *r;
561 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
562 if (sas_expander->handle != handle)
572 * _scsih_raid_device_find_by_id - raid device search
573 * @ioc: per adapter object
574 * @id: sas device target id
575 * @channel: sas device channel
576 * Context: Calling function should acquire ioc->raid_device_lock
578 * This searches for raid_device based on target id, then return raid_device
581 static struct _raid_device *
582 _scsih_raid_device_find_by_id(struct MPT2SAS_ADAPTER *ioc, int id, int channel)
584 struct _raid_device *raid_device, *r;
587 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
588 if (raid_device->id == id && raid_device->channel == channel) {
599 * _scsih_raid_device_find_by_handle - raid device search
600 * @ioc: per adapter object
601 * @handle: sas device handle (assigned by firmware)
602 * Context: Calling function should acquire ioc->raid_device_lock
604 * This searches for raid_device based on handle, then return raid_device
607 static struct _raid_device *
608 _scsih_raid_device_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
610 struct _raid_device *raid_device, *r;
613 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
614 if (raid_device->handle != handle)
625 * _scsih_raid_device_find_by_wwid - raid device search
626 * @ioc: per adapter object
627 * @handle: sas device handle (assigned by firmware)
628 * Context: Calling function should acquire ioc->raid_device_lock
630 * This searches for raid_device based on wwid, then return raid_device
633 static struct _raid_device *
634 _scsih_raid_device_find_by_wwid(struct MPT2SAS_ADAPTER *ioc, u64 wwid)
636 struct _raid_device *raid_device, *r;
639 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
640 if (raid_device->wwid != wwid)
651 * _scsih_raid_device_add - add raid_device object
652 * @ioc: per adapter object
653 * @raid_device: raid_device object
655 * This is added to the raid_device_list link list.
658 _scsih_raid_device_add(struct MPT2SAS_ADAPTER *ioc,
659 struct _raid_device *raid_device)
663 dewtprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: handle"
664 "(0x%04x), wwid(0x%016llx)\n", ioc->name, __func__,
665 raid_device->handle, (unsigned long long)raid_device->wwid));
667 spin_lock_irqsave(&ioc->raid_device_lock, flags);
668 list_add_tail(&raid_device->list, &ioc->raid_device_list);
669 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
673 * _scsih_raid_device_remove - delete raid_device object
674 * @ioc: per adapter object
675 * @raid_device: raid_device object
677 * This is removed from the raid_device_list link list.
680 _scsih_raid_device_remove(struct MPT2SAS_ADAPTER *ioc,
681 struct _raid_device *raid_device)
685 spin_lock_irqsave(&ioc->raid_device_lock, flags);
686 list_del(&raid_device->list);
687 memset(raid_device, 0, sizeof(struct _raid_device));
689 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
693 * mpt2sas_scsih_expander_find_by_sas_address - expander device search
694 * @ioc: per adapter object
695 * @sas_address: sas address
696 * Context: Calling function should acquire ioc->sas_node_lock.
698 * This searches for expander device based on sas_address, then returns the
702 mpt2sas_scsih_expander_find_by_sas_address(struct MPT2SAS_ADAPTER *ioc,
705 struct _sas_node *sas_expander, *r;
708 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
709 if (sas_expander->sas_address != sas_address)
719 * _scsih_expander_node_add - insert expander device to the list.
720 * @ioc: per adapter object
721 * @sas_expander: the sas_device object
722 * Context: This function will acquire ioc->sas_node_lock.
724 * Adding new object to the ioc->sas_expander_list.
729 _scsih_expander_node_add(struct MPT2SAS_ADAPTER *ioc,
730 struct _sas_node *sas_expander)
734 spin_lock_irqsave(&ioc->sas_node_lock, flags);
735 list_add_tail(&sas_expander->list, &ioc->sas_expander_list);
736 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
740 * _scsih_is_end_device - determines if device is an end device
741 * @device_info: bitfield providing information about the device.
744 * Returns 1 if end device.
747 _scsih_is_end_device(u32 device_info)
749 if (device_info & MPI2_SAS_DEVICE_INFO_END_DEVICE &&
750 ((device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) |
751 (device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) |
752 (device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE)))
759 * _scsih_scsi_lookup_get - returns scmd entry
760 * @ioc: per adapter object
761 * @smid: system request message index
762 * Context: This function will acquire ioc->scsi_lookup_lock.
764 * Returns the smid stored scmd pointer.
766 static struct scsi_cmnd *
767 _scsih_scsi_lookup_get(struct MPT2SAS_ADAPTER *ioc, u16 smid)
770 struct scsi_cmnd *scmd;
772 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
773 scmd = ioc->scsi_lookup[smid - 1].scmd;
774 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
779 * mptscsih_getclear_scsi_lookup - returns scmd entry
780 * @ioc: per adapter object
781 * @smid: system request message index
782 * Context: This function will acquire ioc->scsi_lookup_lock.
784 * Returns the smid stored scmd pointer, as well as clearing the scmd pointer.
786 static struct scsi_cmnd *
787 _scsih_scsi_lookup_getclear(struct MPT2SAS_ADAPTER *ioc, u16 smid)
790 struct scsi_cmnd *scmd;
792 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
793 scmd = ioc->scsi_lookup[smid - 1].scmd;
794 ioc->scsi_lookup[smid - 1].scmd = NULL;
795 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
800 * _scsih_scsi_lookup_set - updates scmd entry in lookup
801 * @ioc: per adapter object
802 * @smid: system request message index
803 * @scmd: pointer to scsi command object
804 * Context: This function will acquire ioc->scsi_lookup_lock.
806 * This will save scmd pointer in the scsi_lookup array.
811 _scsih_scsi_lookup_set(struct MPT2SAS_ADAPTER *ioc, u16 smid,
812 struct scsi_cmnd *scmd)
816 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
817 ioc->scsi_lookup[smid - 1].scmd = scmd;
818 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
822 * _scsih_scsi_lookup_find_by_scmd - scmd lookup
823 * @ioc: per adapter object
824 * @smid: system request message index
825 * @scmd: pointer to scsi command object
826 * Context: This function will acquire ioc->scsi_lookup_lock.
828 * This will search for a scmd pointer in the scsi_lookup array,
829 * returning the revelent smid. A returned value of zero means invalid.
832 _scsih_scsi_lookup_find_by_scmd(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd
839 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
841 for (i = 0; i < ioc->request_depth; i++) {
842 if (ioc->scsi_lookup[i].scmd == scmd) {
848 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
853 * _scsih_scsi_lookup_find_by_target - search for matching channel:id
854 * @ioc: per adapter object
857 * Context: This function will acquire ioc->scsi_lookup_lock.
859 * This will search for a matching channel:id in the scsi_lookup array,
860 * returning 1 if found.
863 _scsih_scsi_lookup_find_by_target(struct MPT2SAS_ADAPTER *ioc, int id,
870 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
872 for (i = 0 ; i < ioc->request_depth; i++) {
873 if (ioc->scsi_lookup[i].scmd &&
874 (ioc->scsi_lookup[i].scmd->device->id == id &&
875 ioc->scsi_lookup[i].scmd->device->channel == channel)) {
881 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
886 * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun
887 * @ioc: per adapter object
891 * Context: This function will acquire ioc->scsi_lookup_lock.
893 * This will search for a matching channel:id:lun in the scsi_lookup array,
894 * returning 1 if found.
897 _scsih_scsi_lookup_find_by_lun(struct MPT2SAS_ADAPTER *ioc, int id,
898 unsigned int lun, int channel)
904 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
906 for (i = 0 ; i < ioc->request_depth; i++) {
907 if (ioc->scsi_lookup[i].scmd &&
908 (ioc->scsi_lookup[i].scmd->device->id == id &&
909 ioc->scsi_lookup[i].scmd->device->channel == channel &&
910 ioc->scsi_lookup[i].scmd->device->lun == lun)) {
916 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
921 * _scsih_get_chain_buffer_dma - obtain block of chains (dma address)
922 * @ioc: per adapter object
923 * @smid: system request message index
925 * Returns phys pointer to chain buffer.
928 _scsih_get_chain_buffer_dma(struct MPT2SAS_ADAPTER *ioc, u16 smid)
930 return ioc->chain_dma + ((smid - 1) * (ioc->request_sz *
931 ioc->chains_needed_per_io));
935 * _scsih_get_chain_buffer - obtain block of chains assigned to a mf request
936 * @ioc: per adapter object
937 * @smid: system request message index
939 * Returns virt pointer to chain buffer.
942 _scsih_get_chain_buffer(struct MPT2SAS_ADAPTER *ioc, u16 smid)
944 return (void *)(ioc->chain + ((smid - 1) * (ioc->request_sz *
945 ioc->chains_needed_per_io)));
949 * _scsih_build_scatter_gather - main sg creation routine
950 * @ioc: per adapter object
951 * @scmd: scsi command
952 * @smid: system request message index
955 * The main routine that builds scatter gather table from a given
956 * scsi request sent via the .queuecommand main handler.
958 * Returns 0 success, anything else error
961 _scsih_build_scatter_gather(struct MPT2SAS_ADAPTER *ioc,
962 struct scsi_cmnd *scmd, u16 smid)
964 Mpi2SCSIIORequest_t *mpi_request;
965 dma_addr_t chain_dma;
966 struct scatterlist *sg_scmd;
967 void *sg_local, *chain;
974 u32 sgl_flags_last_element;
975 u32 sgl_flags_end_buffer;
977 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
979 /* init scatter gather flags */
980 sgl_flags = MPI2_SGE_FLAGS_SIMPLE_ELEMENT;
981 if (scmd->sc_data_direction == DMA_TO_DEVICE)
982 sgl_flags |= MPI2_SGE_FLAGS_HOST_TO_IOC;
983 sgl_flags_last_element = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT)
984 << MPI2_SGE_FLAGS_SHIFT;
985 sgl_flags_end_buffer = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT |
986 MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_END_OF_LIST)
987 << MPI2_SGE_FLAGS_SHIFT;
988 sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT;
990 sg_scmd = scsi_sglist(scmd);
991 sges_left = scsi_dma_map(scmd);
993 sdev_printk(KERN_ERR, scmd->device, "pci_map_sg"
994 " failed: request for %d bytes!\n", scsi_bufflen(scmd));
998 sg_local = &mpi_request->SGL;
999 sges_in_segment = ioc->max_sges_in_main_message;
1000 if (sges_left <= sges_in_segment)
1001 goto fill_in_last_segment;
1003 mpi_request->ChainOffset = (offsetof(Mpi2SCSIIORequest_t, SGL) +
1004 (sges_in_segment * ioc->sge_size))/4;
1006 /* fill in main message segment when there is a chain following */
1007 while (sges_in_segment) {
1008 if (sges_in_segment == 1)
1009 ioc->base_add_sg_single(sg_local,
1010 sgl_flags_last_element | sg_dma_len(sg_scmd),
1011 sg_dma_address(sg_scmd));
1013 ioc->base_add_sg_single(sg_local, sgl_flags |
1014 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
1015 sg_scmd = sg_next(sg_scmd);
1016 sg_local += ioc->sge_size;
1021 /* initializing the chain flags and pointers */
1022 chain_flags = MPI2_SGE_FLAGS_CHAIN_ELEMENT << MPI2_SGE_FLAGS_SHIFT;
1023 chain = _scsih_get_chain_buffer(ioc, smid);
1024 chain_dma = _scsih_get_chain_buffer_dma(ioc, smid);
1026 sges_in_segment = (sges_left <=
1027 ioc->max_sges_in_chain_message) ? sges_left :
1028 ioc->max_sges_in_chain_message;
1029 chain_offset = (sges_left == sges_in_segment) ?
1030 0 : (sges_in_segment * ioc->sge_size)/4;
1031 chain_length = sges_in_segment * ioc->sge_size;
1033 chain_offset = chain_offset <<
1034 MPI2_SGE_CHAIN_OFFSET_SHIFT;
1035 chain_length += ioc->sge_size;
1037 ioc->base_add_sg_single(sg_local, chain_flags | chain_offset |
1038 chain_length, chain_dma);
1041 goto fill_in_last_segment;
1043 /* fill in chain segments */
1044 while (sges_in_segment) {
1045 if (sges_in_segment == 1)
1046 ioc->base_add_sg_single(sg_local,
1047 sgl_flags_last_element |
1048 sg_dma_len(sg_scmd),
1049 sg_dma_address(sg_scmd));
1051 ioc->base_add_sg_single(sg_local, sgl_flags |
1052 sg_dma_len(sg_scmd),
1053 sg_dma_address(sg_scmd));
1054 sg_scmd = sg_next(sg_scmd);
1055 sg_local += ioc->sge_size;
1060 chain_dma += ioc->request_sz;
1061 chain += ioc->request_sz;
1065 fill_in_last_segment:
1067 /* fill the last segment */
1070 ioc->base_add_sg_single(sg_local, sgl_flags_end_buffer |
1071 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
1073 ioc->base_add_sg_single(sg_local, sgl_flags |
1074 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
1075 sg_scmd = sg_next(sg_scmd);
1076 sg_local += ioc->sge_size;
1084 * _scsih_change_queue_depth - setting device queue depth
1085 * @sdev: scsi device struct
1086 * @qdepth: requested queue depth
1088 * Returns queue depth.
1091 _scsih_change_queue_depth(struct scsi_device *sdev, int qdepth)
1093 struct Scsi_Host *shost = sdev->host;
1097 max_depth = shost->can_queue;
1098 if (!sdev->tagged_supported)
1100 if (qdepth > max_depth)
1102 tag_type = (qdepth == 1) ? 0 : MSG_SIMPLE_TAG;
1103 scsi_adjust_queue_depth(sdev, tag_type, qdepth);
1105 if (sdev->inquiry_len > 7)
1106 sdev_printk(KERN_INFO, sdev, "qdepth(%d), tagged(%d), "
1107 "simple(%d), ordered(%d), scsi_level(%d), cmd_que(%d)\n",
1108 sdev->queue_depth, sdev->tagged_supported, sdev->simple_tags,
1109 sdev->ordered_tags, sdev->scsi_level,
1110 (sdev->inquiry[7] & 2) >> 1);
1112 return sdev->queue_depth;
1116 * _scsih_change_queue_depth - changing device queue tag type
1117 * @sdev: scsi device struct
1118 * @tag_type: requested tag type
1120 * Returns queue tag type.
1123 _scsih_change_queue_type(struct scsi_device *sdev, int tag_type)
1125 if (sdev->tagged_supported) {
1126 scsi_set_tag_type(sdev, tag_type);
1128 scsi_activate_tcq(sdev, sdev->queue_depth);
1130 scsi_deactivate_tcq(sdev, sdev->queue_depth);
1138 * _scsih_target_alloc - target add routine
1139 * @starget: scsi target struct
1141 * Returns 0 if ok. Any other return is assumed to be an error and
1142 * the device is ignored.
1145 _scsih_target_alloc(struct scsi_target *starget)
1147 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1148 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1149 struct MPT2SAS_TARGET *sas_target_priv_data;
1150 struct _sas_device *sas_device;
1151 struct _raid_device *raid_device;
1152 unsigned long flags;
1153 struct sas_rphy *rphy;
1155 sas_target_priv_data = kzalloc(sizeof(struct scsi_target), GFP_KERNEL);
1156 if (!sas_target_priv_data)
1159 starget->hostdata = sas_target_priv_data;
1160 sas_target_priv_data->starget = starget;
1161 sas_target_priv_data->handle = MPT2SAS_INVALID_DEVICE_HANDLE;
1164 if (starget->channel == RAID_CHANNEL) {
1165 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1166 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1169 sas_target_priv_data->handle = raid_device->handle;
1170 sas_target_priv_data->sas_address = raid_device->wwid;
1171 sas_target_priv_data->flags |= MPT_TARGET_FLAGS_VOLUME;
1172 raid_device->starget = starget;
1174 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1178 /* sas/sata devices */
1179 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1180 rphy = dev_to_rphy(starget->dev.parent);
1181 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1182 rphy->identify.sas_address);
1185 sas_target_priv_data->handle = sas_device->handle;
1186 sas_target_priv_data->sas_address = sas_device->sas_address;
1187 sas_device->starget = starget;
1188 sas_device->id = starget->id;
1189 sas_device->channel = starget->channel;
1190 if (sas_device->hidden_raid_component)
1191 sas_target_priv_data->flags |=
1192 MPT_TARGET_FLAGS_RAID_COMPONENT;
1194 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1200 * _scsih_target_destroy - target destroy routine
1201 * @starget: scsi target struct
1206 _scsih_target_destroy(struct scsi_target *starget)
1208 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1209 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1210 struct MPT2SAS_TARGET *sas_target_priv_data;
1211 struct _sas_device *sas_device;
1212 struct _raid_device *raid_device;
1213 unsigned long flags;
1214 struct sas_rphy *rphy;
1216 sas_target_priv_data = starget->hostdata;
1217 if (!sas_target_priv_data)
1220 if (starget->channel == RAID_CHANNEL) {
1221 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1222 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1225 raid_device->starget = NULL;
1226 raid_device->sdev = NULL;
1228 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1232 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1233 rphy = dev_to_rphy(starget->dev.parent);
1234 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1235 rphy->identify.sas_address);
1236 if (sas_device && (sas_device->starget == starget) &&
1237 (sas_device->id == starget->id) &&
1238 (sas_device->channel == starget->channel))
1239 sas_device->starget = NULL;
1241 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1244 kfree(sas_target_priv_data);
1245 starget->hostdata = NULL;
1249 * _scsih_slave_alloc - device add routine
1250 * @sdev: scsi device struct
1252 * Returns 0 if ok. Any other return is assumed to be an error and
1253 * the device is ignored.
1256 _scsih_slave_alloc(struct scsi_device *sdev)
1258 struct Scsi_Host *shost;
1259 struct MPT2SAS_ADAPTER *ioc;
1260 struct MPT2SAS_TARGET *sas_target_priv_data;
1261 struct MPT2SAS_DEVICE *sas_device_priv_data;
1262 struct scsi_target *starget;
1263 struct _raid_device *raid_device;
1264 struct _sas_device *sas_device;
1265 unsigned long flags;
1267 sas_device_priv_data = kzalloc(sizeof(struct scsi_device), GFP_KERNEL);
1268 if (!sas_device_priv_data)
1271 sas_device_priv_data->lun = sdev->lun;
1272 sas_device_priv_data->flags = MPT_DEVICE_FLAGS_INIT;
1274 starget = scsi_target(sdev);
1275 sas_target_priv_data = starget->hostdata;
1276 sas_target_priv_data->num_luns++;
1277 sas_device_priv_data->sas_target = sas_target_priv_data;
1278 sdev->hostdata = sas_device_priv_data;
1279 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT))
1280 sdev->no_uld_attach = 1;
1282 shost = dev_to_shost(&starget->dev);
1283 ioc = shost_priv(shost);
1284 if (starget->channel == RAID_CHANNEL) {
1285 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1286 raid_device = _scsih_raid_device_find_by_id(ioc,
1287 starget->id, starget->channel);
1289 raid_device->sdev = sdev; /* raid is single lun */
1290 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1292 /* set TLR bit for SSP devices */
1293 if (!(ioc->facts.IOCCapabilities &
1294 MPI2_IOCFACTS_CAPABILITY_TLR))
1296 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1297 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1298 sas_device_priv_data->sas_target->sas_address);
1299 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1300 if (sas_device && sas_device->device_info &
1301 MPI2_SAS_DEVICE_INFO_SSP_TARGET)
1302 sas_device_priv_data->flags |= MPT_DEVICE_TLR_ON;
1310 * _scsih_slave_destroy - device destroy routine
1311 * @sdev: scsi device struct
1316 _scsih_slave_destroy(struct scsi_device *sdev)
1318 struct MPT2SAS_TARGET *sas_target_priv_data;
1319 struct scsi_target *starget;
1321 if (!sdev->hostdata)
1324 starget = scsi_target(sdev);
1325 sas_target_priv_data = starget->hostdata;
1326 sas_target_priv_data->num_luns--;
1327 kfree(sdev->hostdata);
1328 sdev->hostdata = NULL;
1332 * _scsih_display_sata_capabilities - sata capabilities
1333 * @ioc: per adapter object
1334 * @sas_device: the sas_device object
1335 * @sdev: scsi device struct
1338 _scsih_display_sata_capabilities(struct MPT2SAS_ADAPTER *ioc,
1339 struct _sas_device *sas_device, struct scsi_device *sdev)
1341 Mpi2ConfigReply_t mpi_reply;
1342 Mpi2SasDevicePage0_t sas_device_pg0;
1347 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
1348 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, sas_device->handle))) {
1349 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1350 ioc->name, __FILE__, __LINE__, __func__);
1354 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1355 MPI2_IOCSTATUS_MASK;
1356 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
1357 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1358 ioc->name, __FILE__, __LINE__, __func__);
1362 flags = le16_to_cpu(sas_device_pg0.Flags);
1363 device_info = le16_to_cpu(sas_device_pg0.DeviceInfo);
1365 sdev_printk(KERN_INFO, sdev,
1366 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1367 "sw_preserve(%s)\n",
1368 (device_info & MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE) ? "y" : "n",
1369 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED) ? "y" : "n",
1370 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY) ? "y" :
1372 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED) ? "y" : "n",
1373 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED) ? "y" : "n",
1374 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE) ? "y" : "n");
1378 * _scsih_get_volume_capabilities - volume capabilities
1379 * @ioc: per adapter object
1380 * @sas_device: the raid_device object
1383 _scsih_get_volume_capabilities(struct MPT2SAS_ADAPTER *ioc,
1384 struct _raid_device *raid_device)
1386 Mpi2RaidVolPage0_t *vol_pg0;
1387 Mpi2RaidPhysDiskPage0_t pd_pg0;
1388 Mpi2SasDevicePage0_t sas_device_pg0;
1389 Mpi2ConfigReply_t mpi_reply;
1393 if ((mpt2sas_config_get_number_pds(ioc, raid_device->handle,
1394 &num_pds)) || !num_pds) {
1395 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1396 ioc->name, __FILE__, __LINE__, __func__);
1400 raid_device->num_pds = num_pds;
1401 sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
1402 sizeof(Mpi2RaidVol0PhysDisk_t));
1403 vol_pg0 = kzalloc(sz, GFP_KERNEL);
1405 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1406 ioc->name, __FILE__, __LINE__, __func__);
1410 if ((mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
1411 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
1412 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1413 ioc->name, __FILE__, __LINE__, __func__);
1418 raid_device->volume_type = vol_pg0->VolumeType;
1420 /* figure out what the underlying devices are by
1421 * obtaining the device_info bits for the 1st device
1423 if (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
1424 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
1425 vol_pg0->PhysDisk[0].PhysDiskNum))) {
1426 if (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
1427 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
1428 le16_to_cpu(pd_pg0.DevHandle)))) {
1429 raid_device->device_info =
1430 le32_to_cpu(sas_device_pg0.DeviceInfo);
1438 * _scsih_slave_configure - device configure routine.
1439 * @sdev: scsi device struct
1441 * Returns 0 if ok. Any other return is assumed to be an error and
1442 * the device is ignored.
1445 _scsih_slave_configure(struct scsi_device *sdev)
1447 struct Scsi_Host *shost = sdev->host;
1448 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1449 struct MPT2SAS_DEVICE *sas_device_priv_data;
1450 struct MPT2SAS_TARGET *sas_target_priv_data;
1451 struct _sas_device *sas_device;
1452 struct _raid_device *raid_device;
1453 unsigned long flags;
1460 sas_device_priv_data = sdev->hostdata;
1461 sas_device_priv_data->configured_lun = 1;
1462 sas_device_priv_data->flags &= ~MPT_DEVICE_FLAGS_INIT;
1463 sas_target_priv_data = sas_device_priv_data->sas_target;
1465 /* raid volume handling */
1466 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME) {
1468 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1469 raid_device = _scsih_raid_device_find_by_handle(ioc,
1470 sas_target_priv_data->handle);
1471 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1473 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1474 ioc->name, __FILE__, __LINE__, __func__);
1478 _scsih_get_volume_capabilities(ioc, raid_device);
1480 /* RAID Queue Depth Support
1481 * IS volume = underlying qdepth of drive type, either
1482 * MPT2SAS_SAS_QUEUE_DEPTH or MPT2SAS_SATA_QUEUE_DEPTH
1483 * IM/IME/R10 = 128 (MPT2SAS_RAID_QUEUE_DEPTH)
1485 if (raid_device->device_info &
1486 MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
1487 qdepth = MPT2SAS_SAS_QUEUE_DEPTH;
1490 qdepth = MPT2SAS_SATA_QUEUE_DEPTH;
1491 if (raid_device->device_info &
1492 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1498 switch (raid_device->volume_type) {
1499 case MPI2_RAID_VOL_TYPE_RAID0:
1502 case MPI2_RAID_VOL_TYPE_RAID1E:
1503 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
1504 if (ioc->manu_pg10.OEMIdentifier &&
1505 (ioc->manu_pg10.GenericFlags0 &
1506 MFG10_GF0_R10_DISPLAY) &&
1507 !(raid_device->num_pds % 2))
1512 case MPI2_RAID_VOL_TYPE_RAID1:
1513 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
1516 case MPI2_RAID_VOL_TYPE_RAID10:
1517 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
1520 case MPI2_RAID_VOL_TYPE_UNKNOWN:
1522 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
1527 sdev_printk(KERN_INFO, sdev, "%s: "
1528 "handle(0x%04x), wwid(0x%016llx), pd_count(%d), type(%s)\n",
1529 r_level, raid_device->handle,
1530 (unsigned long long)raid_device->wwid,
1531 raid_device->num_pds, ds);
1532 _scsih_change_queue_depth(sdev, qdepth);
1536 /* non-raid handling */
1537 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1538 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1539 sas_device_priv_data->sas_target->sas_address);
1540 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1542 if (sas_target_priv_data->flags &
1543 MPT_TARGET_FLAGS_RAID_COMPONENT) {
1544 mpt2sas_config_get_volume_handle(ioc,
1545 sas_device->handle, &sas_device->volume_handle);
1546 mpt2sas_config_get_volume_wwid(ioc,
1547 sas_device->volume_handle,
1548 &sas_device->volume_wwid);
1550 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
1551 qdepth = MPT2SAS_SAS_QUEUE_DEPTH;
1555 qdepth = MPT2SAS_SATA_QUEUE_DEPTH;
1556 if (sas_device->device_info &
1557 MPI2_SAS_DEVICE_INFO_STP_TARGET)
1559 else if (sas_device->device_info &
1560 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1564 sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), "
1565 "sas_addr(0x%016llx), device_name(0x%016llx)\n",
1566 ds, sas_device->handle,
1567 (unsigned long long)sas_device->sas_address,
1568 (unsigned long long)sas_device->device_name);
1569 sdev_printk(KERN_INFO, sdev, "%s: "
1570 "enclosure_logical_id(0x%016llx), slot(%d)\n", ds,
1571 (unsigned long long) sas_device->enclosure_logical_id,
1575 _scsih_display_sata_capabilities(ioc, sas_device, sdev);
1578 _scsih_change_queue_depth(sdev, qdepth);
1581 sas_read_port_mode_page(sdev);
1586 * _scsih_bios_param - fetch head, sector, cylinder info for a disk
1587 * @sdev: scsi device struct
1588 * @bdev: pointer to block device context
1589 * @capacity: device size (in 512 byte sectors)
1590 * @params: three element array to place output:
1591 * params[0] number of heads (max 255)
1592 * params[1] number of sectors (max 63)
1593 * params[2] number of cylinders
1598 _scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev,
1599 sector_t capacity, int params[])
1609 dummy = heads * sectors;
1610 cylinders = capacity;
1611 sector_div(cylinders, dummy);
1614 * Handle extended translation size for logical drives
1617 if ((ulong)capacity >= 0x200000) {
1620 dummy = heads * sectors;
1621 cylinders = capacity;
1622 sector_div(cylinders, dummy);
1627 params[1] = sectors;
1628 params[2] = cylinders;
1634 * _scsih_response_code - translation of device response code
1635 * @ioc: per adapter object
1636 * @response_code: response code returned by the device
1641 _scsih_response_code(struct MPT2SAS_ADAPTER *ioc, u8 response_code)
1645 switch (response_code) {
1646 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE:
1647 desc = "task management request completed";
1649 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME:
1650 desc = "invalid frame";
1652 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED:
1653 desc = "task management request not supported";
1655 case MPI2_SCSITASKMGMT_RSP_TM_FAILED:
1656 desc = "task management request failed";
1658 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED:
1659 desc = "task management request succeeded";
1661 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN:
1662 desc = "invalid lun";
1665 desc = "overlapped tag attempted";
1667 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC:
1668 desc = "task queued, however not sent to target";
1674 printk(MPT2SAS_WARN_FMT "response_code(0x%01x): %s\n",
1675 ioc->name, response_code, desc);
1679 * _scsih_tm_done - tm completion routine
1680 * @ioc: per adapter object
1681 * @smid: system request message index
1682 * @VF_ID: virtual function id
1683 * @reply: reply message frame(lower 32bit addr)
1686 * The callback handler when using scsih_issue_tm.
1691 _scsih_tm_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 VF_ID, u32 reply)
1693 MPI2DefaultReply_t *mpi_reply;
1695 if (ioc->tm_cmds.status == MPT2_CMD_NOT_USED)
1697 if (ioc->tm_cmds.smid != smid)
1699 ioc->tm_cmds.status |= MPT2_CMD_COMPLETE;
1700 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
1702 memcpy(ioc->tm_cmds.reply, mpi_reply, mpi_reply->MsgLength*4);
1703 ioc->tm_cmds.status |= MPT2_CMD_REPLY_VALID;
1705 ioc->tm_cmds.status &= ~MPT2_CMD_PENDING;
1706 complete(&ioc->tm_cmds.done);
1710 * mpt2sas_scsih_set_tm_flag - set per target tm_busy
1711 * @ioc: per adapter object
1712 * @handle: device handle
1714 * During taskmangement request, we need to freeze the device queue.
1717 mpt2sas_scsih_set_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
1719 struct MPT2SAS_DEVICE *sas_device_priv_data;
1720 struct scsi_device *sdev;
1723 shost_for_each_device(sdev, ioc->shost) {
1726 sas_device_priv_data = sdev->hostdata;
1727 if (!sas_device_priv_data)
1729 if (sas_device_priv_data->sas_target->handle == handle) {
1730 sas_device_priv_data->sas_target->tm_busy = 1;
1732 ioc->ignore_loginfos = 1;
1738 * mpt2sas_scsih_clear_tm_flag - clear per target tm_busy
1739 * @ioc: per adapter object
1740 * @handle: device handle
1742 * During taskmangement request, we need to freeze the device queue.
1745 mpt2sas_scsih_clear_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
1747 struct MPT2SAS_DEVICE *sas_device_priv_data;
1748 struct scsi_device *sdev;
1751 shost_for_each_device(sdev, ioc->shost) {
1754 sas_device_priv_data = sdev->hostdata;
1755 if (!sas_device_priv_data)
1757 if (sas_device_priv_data->sas_target->handle == handle) {
1758 sas_device_priv_data->sas_target->tm_busy = 0;
1760 ioc->ignore_loginfos = 0;
1766 * mpt2sas_scsih_issue_tm - main routine for sending tm requests
1767 * @ioc: per adapter struct
1768 * @device_handle: device handle
1770 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
1771 * @smid_task: smid assigned to the task
1772 * @timeout: timeout in seconds
1773 * Context: The calling function needs to acquire the tm_cmds.mutex
1775 * A generic API for sending task management requests to firmware.
1777 * The ioc->tm_cmds.status flag should be MPT2_CMD_NOT_USED before calling
1780 * The callback index is set inside `ioc->tm_cb_idx`.
1785 mpt2sas_scsih_issue_tm(struct MPT2SAS_ADAPTER *ioc, u16 handle, uint lun,
1786 u8 type, u16 smid_task, ulong timeout)
1788 Mpi2SCSITaskManagementRequest_t *mpi_request;
1789 Mpi2SCSITaskManagementReply_t *mpi_reply;
1792 unsigned long timeleft;
1795 if (ioc->tm_cmds.status != MPT2_CMD_NOT_USED) {
1796 printk(MPT2SAS_INFO_FMT "%s: tm_cmd busy!!!\n",
1797 __func__, ioc->name);
1801 if (ioc->shost_recovery) {
1802 printk(MPT2SAS_INFO_FMT "%s: host reset in progress!\n",
1803 __func__, ioc->name);
1807 ioc_state = mpt2sas_base_get_iocstate(ioc, 0);
1808 if (ioc_state & MPI2_DOORBELL_USED) {
1809 dhsprintk(ioc, printk(MPT2SAS_DEBUG_FMT "unexpected doorbell "
1810 "active!\n", ioc->name));
1811 goto issue_host_reset;
1814 if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) {
1815 mpt2sas_base_fault_info(ioc, ioc_state &
1816 MPI2_DOORBELL_DATA_MASK);
1817 goto issue_host_reset;
1820 smid = mpt2sas_base_get_smid(ioc, ioc->tm_cb_idx);
1822 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
1823 ioc->name, __func__);
1827 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "sending tm: handle(0x%04x),"
1828 " task_type(0x%02x), smid(%d)\n", ioc->name, handle, type, smid));
1829 ioc->tm_cmds.status = MPT2_CMD_PENDING;
1830 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
1831 ioc->tm_cmds.smid = smid;
1832 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
1833 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
1834 mpi_request->DevHandle = cpu_to_le16(handle);
1835 mpi_request->TaskType = type;
1836 mpi_request->TaskMID = cpu_to_le16(smid_task);
1837 int_to_scsilun(lun, (struct scsi_lun *)mpi_request->LUN);
1838 mpt2sas_scsih_set_tm_flag(ioc, handle);
1839 mpt2sas_base_put_smid_hi_priority(ioc, smid, VF_ID);
1840 timeleft = wait_for_completion_timeout(&ioc->tm_cmds.done, timeout*HZ);
1841 mpt2sas_scsih_clear_tm_flag(ioc, handle);
1842 if (!(ioc->tm_cmds.status & MPT2_CMD_COMPLETE)) {
1843 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
1844 ioc->name, __func__);
1845 _debug_dump_mf(mpi_request,
1846 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
1847 if (!(ioc->tm_cmds.status & MPT2_CMD_RESET))
1848 goto issue_host_reset;
1851 if (ioc->tm_cmds.status & MPT2_CMD_REPLY_VALID) {
1852 mpi_reply = ioc->tm_cmds.reply;
1853 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "complete tm: "
1854 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
1855 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
1856 le32_to_cpu(mpi_reply->IOCLogInfo),
1857 le32_to_cpu(mpi_reply->TerminationCount)));
1858 if (ioc->logging_level & MPT_DEBUG_TM)
1859 _scsih_response_code(ioc, mpi_reply->ResponseCode);
1863 mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, FORCE_BIG_HAMMER);
1867 * _scsih_abort - eh threads main abort routine
1868 * @sdev: scsi device struct
1870 * Returns SUCCESS if command aborted else FAILED
1873 _scsih_abort(struct scsi_cmnd *scmd)
1875 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
1876 struct MPT2SAS_DEVICE *sas_device_priv_data;
1880 struct scsi_cmnd *scmd_lookup;
1882 printk(MPT2SAS_INFO_FMT "attempting task abort! scmd(%p)\n",
1884 scsi_print_command(scmd);
1886 sas_device_priv_data = scmd->device->hostdata;
1887 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
1888 printk(MPT2SAS_INFO_FMT "device been deleted! scmd(%p)\n",
1890 scmd->result = DID_NO_CONNECT << 16;
1891 scmd->scsi_done(scmd);
1896 /* search for the command */
1897 smid = _scsih_scsi_lookup_find_by_scmd(ioc, scmd);
1899 scmd->result = DID_RESET << 16;
1904 /* for hidden raid components and volumes this is not supported */
1905 if (sas_device_priv_data->sas_target->flags &
1906 MPT_TARGET_FLAGS_RAID_COMPONENT ||
1907 sas_device_priv_data->sas_target->flags & MPT_TARGET_FLAGS_VOLUME) {
1908 scmd->result = DID_RESET << 16;
1913 mutex_lock(&ioc->tm_cmds.mutex);
1914 handle = sas_device_priv_data->sas_target->handle;
1915 mpt2sas_scsih_issue_tm(ioc, handle, sas_device_priv_data->lun,
1916 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30);
1918 /* sanity check - see whether command actually completed */
1919 scmd_lookup = _scsih_scsi_lookup_get(ioc, smid);
1920 if (scmd_lookup && (scmd_lookup->serial_number == scmd->serial_number))
1924 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
1925 mutex_unlock(&ioc->tm_cmds.mutex);
1928 printk(MPT2SAS_INFO_FMT "task abort: %s scmd(%p)\n",
1929 ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
1934 * _scsih_dev_reset - eh threads main device reset routine
1935 * @sdev: scsi device struct
1937 * Returns SUCCESS if command aborted else FAILED
1940 _scsih_dev_reset(struct scsi_cmnd *scmd)
1942 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
1943 struct MPT2SAS_DEVICE *sas_device_priv_data;
1944 struct _sas_device *sas_device;
1945 unsigned long flags;
1949 printk(MPT2SAS_INFO_FMT "attempting device reset! scmd(%p)\n",
1951 scsi_print_command(scmd);
1953 sas_device_priv_data = scmd->device->hostdata;
1954 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
1955 printk(MPT2SAS_INFO_FMT "device been deleted! scmd(%p)\n",
1957 scmd->result = DID_NO_CONNECT << 16;
1958 scmd->scsi_done(scmd);
1963 /* for hidden raid components obtain the volume_handle */
1965 if (sas_device_priv_data->sas_target->flags &
1966 MPT_TARGET_FLAGS_RAID_COMPONENT) {
1967 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1968 sas_device = _scsih_sas_device_find_by_handle(ioc,
1969 sas_device_priv_data->sas_target->handle);
1971 handle = sas_device->volume_handle;
1972 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1974 handle = sas_device_priv_data->sas_target->handle;
1977 scmd->result = DID_RESET << 16;
1982 mutex_lock(&ioc->tm_cmds.mutex);
1983 mpt2sas_scsih_issue_tm(ioc, handle, 0,
1984 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, scmd->device->lun,
1988 * sanity check see whether all commands to this device been
1991 if (_scsih_scsi_lookup_find_by_lun(ioc, scmd->device->id,
1992 scmd->device->lun, scmd->device->channel))
1996 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
1997 mutex_unlock(&ioc->tm_cmds.mutex);
2000 printk(MPT2SAS_INFO_FMT "device reset: %s scmd(%p)\n",
2001 ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2006 * _scsih_target_reset - eh threads main target reset routine
2007 * @sdev: scsi device struct
2009 * Returns SUCCESS if command aborted else FAILED
2012 _scsih_target_reset(struct scsi_cmnd *scmd)
2014 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2015 struct MPT2SAS_DEVICE *sas_device_priv_data;
2016 struct _sas_device *sas_device;
2017 unsigned long flags;
2021 printk(MPT2SAS_INFO_FMT "attempting target reset! scmd(%p)\n",
2023 scsi_print_command(scmd);
2025 sas_device_priv_data = scmd->device->hostdata;
2026 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2027 printk(MPT2SAS_INFO_FMT "target been deleted! scmd(%p)\n",
2029 scmd->result = DID_NO_CONNECT << 16;
2030 scmd->scsi_done(scmd);
2035 /* for hidden raid components obtain the volume_handle */
2037 if (sas_device_priv_data->sas_target->flags &
2038 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2039 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2040 sas_device = _scsih_sas_device_find_by_handle(ioc,
2041 sas_device_priv_data->sas_target->handle);
2043 handle = sas_device->volume_handle;
2044 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2046 handle = sas_device_priv_data->sas_target->handle;
2049 scmd->result = DID_RESET << 16;
2054 mutex_lock(&ioc->tm_cmds.mutex);
2055 mpt2sas_scsih_issue_tm(ioc, handle, 0,
2056 MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0, 30);
2059 * sanity check see whether all commands to this target been
2062 if (_scsih_scsi_lookup_find_by_target(ioc, scmd->device->id,
2063 scmd->device->channel))
2067 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
2068 mutex_unlock(&ioc->tm_cmds.mutex);
2071 printk(MPT2SAS_INFO_FMT "target reset: %s scmd(%p)\n",
2072 ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2077 * _scsih_abort - eh threads main host reset routine
2078 * @sdev: scsi device struct
2080 * Returns SUCCESS if command aborted else FAILED
2083 _scsih_host_reset(struct scsi_cmnd *scmd)
2085 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2088 printk(MPT2SAS_INFO_FMT "attempting host reset! scmd(%p)\n",
2090 scsi_print_command(scmd);
2092 retval = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2094 r = (retval < 0) ? FAILED : SUCCESS;
2095 printk(MPT2SAS_INFO_FMT "host reset: %s scmd(%p)\n",
2096 ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2102 * _scsih_fw_event_add - insert and queue up fw_event
2103 * @ioc: per adapter object
2104 * @fw_event: object describing the event
2105 * Context: This function will acquire ioc->fw_event_lock.
2107 * This adds the firmware event object into link list, then queues it up to
2108 * be processed from user context.
2113 _scsih_fw_event_add(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
2115 unsigned long flags;
2117 if (ioc->firmware_event_thread == NULL)
2120 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2121 list_add_tail(&fw_event->list, &ioc->fw_event_list);
2122 INIT_WORK(&fw_event->work, _firmware_event_work);
2123 queue_work(ioc->firmware_event_thread, &fw_event->work);
2124 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2128 * _scsih_fw_event_free - delete fw_event
2129 * @ioc: per adapter object
2130 * @fw_event: object describing the event
2131 * Context: This function will acquire ioc->fw_event_lock.
2133 * This removes firmware event object from link list, frees associated memory.
2138 _scsih_fw_event_free(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work
2141 unsigned long flags;
2143 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2144 list_del(&fw_event->list);
2145 kfree(fw_event->event_data);
2147 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2151 * _scsih_fw_event_add - requeue an event
2152 * @ioc: per adapter object
2153 * @fw_event: object describing the event
2154 * Context: This function will acquire ioc->fw_event_lock.
2159 _scsih_fw_event_requeue(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work
2160 *fw_event, unsigned long delay)
2162 unsigned long flags;
2163 if (ioc->firmware_event_thread == NULL)
2166 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2167 queue_work(ioc->firmware_event_thread, &fw_event->work);
2168 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2172 * _scsih_fw_event_off - turn flag off preventing event handling
2173 * @ioc: per adapter object
2175 * Used to prevent handling of firmware events during adapter reset
2181 _scsih_fw_event_off(struct MPT2SAS_ADAPTER *ioc)
2183 unsigned long flags;
2185 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2186 ioc->fw_events_off = 1;
2187 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2192 * _scsih_fw_event_on - turn flag on allowing firmware event handling
2193 * @ioc: per adapter object
2198 _scsih_fw_event_on(struct MPT2SAS_ADAPTER *ioc)
2200 unsigned long flags;
2202 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2203 ioc->fw_events_off = 0;
2204 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2208 * _scsih_ublock_io_device - set the device state to SDEV_RUNNING
2209 * @ioc: per adapter object
2210 * @handle: device handle
2212 * During device pull we need to appropiately set the sdev state.
2215 _scsih_ublock_io_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2217 struct MPT2SAS_DEVICE *sas_device_priv_data;
2218 struct scsi_device *sdev;
2220 shost_for_each_device(sdev, ioc->shost) {
2221 sas_device_priv_data = sdev->hostdata;
2222 if (!sas_device_priv_data)
2224 if (!sas_device_priv_data->block)
2226 if (sas_device_priv_data->sas_target->handle == handle) {
2227 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
2228 MPT2SAS_INFO_FMT "SDEV_RUNNING: "
2229 "handle(0x%04x)\n", ioc->name, handle));
2230 sas_device_priv_data->block = 0;
2231 scsi_internal_device_unblock(sdev);
2237 * _scsih_block_io_device - set the device state to SDEV_BLOCK
2238 * @ioc: per adapter object
2239 * @handle: device handle
2241 * During device pull we need to appropiately set the sdev state.
2244 _scsih_block_io_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2246 struct MPT2SAS_DEVICE *sas_device_priv_data;
2247 struct scsi_device *sdev;
2249 shost_for_each_device(sdev, ioc->shost) {
2250 sas_device_priv_data = sdev->hostdata;
2251 if (!sas_device_priv_data)
2253 if (sas_device_priv_data->block)
2255 if (sas_device_priv_data->sas_target->handle == handle) {
2256 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
2257 MPT2SAS_INFO_FMT "SDEV_BLOCK: "
2258 "handle(0x%04x)\n", ioc->name, handle));
2259 sas_device_priv_data->block = 1;
2260 scsi_internal_device_block(sdev);
2266 * _scsih_block_io_to_children_attached_to_ex
2267 * @ioc: per adapter object
2268 * @sas_expander: the sas_device object
2270 * This routine set sdev state to SDEV_BLOCK for all devices
2271 * attached to this expander. This function called when expander is
2275 _scsih_block_io_to_children_attached_to_ex(struct MPT2SAS_ADAPTER *ioc,
2276 struct _sas_node *sas_expander)
2278 struct _sas_port *mpt2sas_port;
2279 struct _sas_device *sas_device;
2280 struct _sas_node *expander_sibling;
2281 unsigned long flags;
2286 list_for_each_entry(mpt2sas_port,
2287 &sas_expander->sas_port_list, port_list) {
2288 if (mpt2sas_port->remote_identify.device_type ==
2290 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2292 mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
2293 mpt2sas_port->remote_identify.sas_address);
2294 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2297 _scsih_block_io_device(ioc, sas_device->handle);
2301 list_for_each_entry(mpt2sas_port,
2302 &sas_expander->sas_port_list, port_list) {
2304 if (mpt2sas_port->remote_identify.device_type ==
2305 MPI2_SAS_DEVICE_INFO_EDGE_EXPANDER ||
2306 mpt2sas_port->remote_identify.device_type ==
2307 MPI2_SAS_DEVICE_INFO_FANOUT_EXPANDER) {
2309 spin_lock_irqsave(&ioc->sas_node_lock, flags);
2311 mpt2sas_scsih_expander_find_by_sas_address(
2312 ioc, mpt2sas_port->remote_identify.sas_address);
2313 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
2314 _scsih_block_io_to_children_attached_to_ex(ioc,
2321 * _scsih_block_io_to_children_attached_directly
2322 * @ioc: per adapter object
2323 * @event_data: topology change event data
2325 * This routine set sdev state to SDEV_BLOCK for all devices
2326 * direct attached during device pull.
2329 _scsih_block_io_to_children_attached_directly(struct MPT2SAS_ADAPTER *ioc,
2330 Mpi2EventDataSasTopologyChangeList_t *event_data)
2338 for (i = 0; i < event_data->NumEntries; i++) {
2339 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
2342 phy_number = event_data->StartPhyNum + i;
2343 reason_code = event_data->PHY[i].PhyStatus &
2344 MPI2_EVENT_SAS_TOPO_RC_MASK;
2345 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING)
2346 _scsih_block_io_device(ioc, handle);
2347 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED) {
2348 link_rate = event_data->PHY[i].LinkRate >> 4;
2349 if (link_rate >= MPI2_SAS_NEG_LINK_RATE_1_5)
2350 _scsih_ublock_io_device(ioc, handle);
2356 * _scsih_check_topo_delete_events - sanity check on topo events
2357 * @ioc: per adapter object
2358 * @event_data: the event data payload
2360 * This routine added to better handle cable breaker.
2362 * This handles the case where driver recieves multiple expander
2363 * add and delete events in a single shot. When there is a delete event
2364 * the routine will void any pending add events waiting in the event queue.
2369 _scsih_check_topo_delete_events(struct MPT2SAS_ADAPTER *ioc,
2370 Mpi2EventDataSasTopologyChangeList_t *event_data)
2372 struct fw_event_work *fw_event;
2373 Mpi2EventDataSasTopologyChangeList_t *local_event_data;
2374 u16 expander_handle;
2375 struct _sas_node *sas_expander;
2376 unsigned long flags;
2378 expander_handle = le16_to_cpu(event_data->ExpanderDevHandle);
2379 if (expander_handle < ioc->sas_hba.num_phys) {
2380 _scsih_block_io_to_children_attached_directly(ioc, event_data);
2384 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
2385 || event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING) {
2386 spin_lock_irqsave(&ioc->sas_node_lock, flags);
2387 sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc,
2389 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
2390 _scsih_block_io_to_children_attached_to_ex(ioc, sas_expander);
2391 } else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING)
2392 _scsih_block_io_to_children_attached_directly(ioc, event_data);
2394 if (event_data->ExpStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING)
2397 /* mark ignore flag for pending events */
2398 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2399 list_for_each_entry(fw_event, &ioc->fw_event_list, list) {
2400 if (fw_event->event != MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST ||
2403 local_event_data = fw_event->event_data;
2404 if (local_event_data->ExpStatus ==
2405 MPI2_EVENT_SAS_TOPO_ES_ADDED ||
2406 local_event_data->ExpStatus ==
2407 MPI2_EVENT_SAS_TOPO_ES_RESPONDING) {
2408 if (le16_to_cpu(local_event_data->ExpanderDevHandle) ==
2410 dewtprintk(ioc, printk(MPT2SAS_DEBUG_FMT
2411 "setting ignoring flag\n", ioc->name));
2412 fw_event->ignore = 1;
2416 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2420 * _scsih_flush_running_cmds - completing outstanding commands.
2421 * @ioc: per adapter object
2423 * The flushing out of all pending scmd commands following host reset,
2424 * where all IO is dropped to the floor.
2429 _scsih_flush_running_cmds(struct MPT2SAS_ADAPTER *ioc)
2431 struct scsi_cmnd *scmd;
2435 for (smid = 1; smid <= ioc->request_depth; smid++) {
2436 scmd = _scsih_scsi_lookup_getclear(ioc, smid);
2440 mpt2sas_base_free_smid(ioc, smid);
2441 scsi_dma_unmap(scmd);
2442 scmd->result = DID_RESET << 16;
2443 scmd->scsi_done(scmd);
2445 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "completing %d cmds\n",
2450 * _scsih_setup_eedp - setup MPI request for EEDP transfer
2451 * @scmd: pointer to scsi command object
2452 * @mpi_request: pointer to the SCSI_IO reqest message frame
2454 * Supporting protection 1 and 3.
2459 _scsih_setup_eedp(struct scsi_cmnd *scmd, Mpi2SCSIIORequest_t *mpi_request)
2462 unsigned char prot_op = scsi_get_prot_op(scmd);
2463 unsigned char prot_type = scsi_get_prot_type(scmd);
2465 if (prot_type == SCSI_PROT_DIF_TYPE0 ||
2466 prot_type == SCSI_PROT_DIF_TYPE2 ||
2467 prot_op == SCSI_PROT_NORMAL)
2470 if (prot_op == SCSI_PROT_READ_STRIP)
2471 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP;
2472 else if (prot_op == SCSI_PROT_WRITE_INSERT)
2473 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_INSERT_OP;
2477 mpi_request->EEDPBlockSize = scmd->device->sector_size;
2479 switch (prot_type) {
2480 case SCSI_PROT_DIF_TYPE1:
2483 * enable ref/guard checking
2484 * auto increment ref tag
2486 mpi_request->EEDPFlags = eedp_flags |
2487 MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG |
2488 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG |
2489 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
2490 mpi_request->CDB.EEDP32.PrimaryReferenceTag =
2491 cpu_to_be32(scsi_get_lba(scmd));
2495 case SCSI_PROT_DIF_TYPE3:
2498 * enable guard checking
2500 mpi_request->EEDPFlags = eedp_flags |
2501 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
2508 * _scsih_eedp_error_handling - return sense code for EEDP errors
2509 * @scmd: pointer to scsi command object
2510 * @ioc_status: ioc status
2515 _scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status)
2521 switch (ioc_status) {
2522 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
2525 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
2528 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
2536 if (scmd->sc_data_direction == DMA_TO_DEVICE) {
2537 sk = ILLEGAL_REQUEST;
2538 host_byte = DID_ABORT;
2540 sk = ABORTED_COMMAND;
2544 scsi_build_sense_buffer(0, scmd->sense_buffer, sk, 0x10, ascq);
2545 scmd->result = DRIVER_SENSE << 24 | (host_byte << 16) |
2546 SAM_STAT_CHECK_CONDITION;
2550 * _scsih_qcmd - main scsi request entry point
2551 * @scmd: pointer to scsi command object
2552 * @done: function pointer to be invoked on completion
2554 * The callback index is set inside `ioc->scsi_io_cb_idx`.
2556 * Returns 0 on success. If there's a failure, return either:
2557 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
2558 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
2561 _scsih_qcmd(struct scsi_cmnd *scmd, void (*done)(struct scsi_cmnd *))
2563 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2564 struct MPT2SAS_DEVICE *sas_device_priv_data;
2565 struct MPT2SAS_TARGET *sas_target_priv_data;
2566 Mpi2SCSIIORequest_t *mpi_request;
2570 scmd->scsi_done = done;
2571 sas_device_priv_data = scmd->device->hostdata;
2572 if (!sas_device_priv_data) {
2573 scmd->result = DID_NO_CONNECT << 16;
2574 scmd->scsi_done(scmd);
2578 sas_target_priv_data = sas_device_priv_data->sas_target;
2579 if (!sas_target_priv_data || sas_target_priv_data->handle ==
2580 MPT2SAS_INVALID_DEVICE_HANDLE || sas_target_priv_data->deleted) {
2581 scmd->result = DID_NO_CONNECT << 16;
2582 scmd->scsi_done(scmd);
2586 /* see if we are busy with task managment stuff */
2587 if (sas_target_priv_data->tm_busy)
2588 return SCSI_MLQUEUE_DEVICE_BUSY;
2589 else if (ioc->shost_recovery || ioc->ioc_link_reset_in_progress)
2590 return SCSI_MLQUEUE_HOST_BUSY;
2592 if (scmd->sc_data_direction == DMA_FROM_DEVICE)
2593 mpi_control = MPI2_SCSIIO_CONTROL_READ;
2594 else if (scmd->sc_data_direction == DMA_TO_DEVICE)
2595 mpi_control = MPI2_SCSIIO_CONTROL_WRITE;
2597 mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER;
2600 if (!(sas_device_priv_data->flags & MPT_DEVICE_FLAGS_INIT)) {
2601 if (scmd->device->tagged_supported) {
2602 if (scmd->device->ordered_tags)
2603 mpi_control |= MPI2_SCSIIO_CONTROL_ORDEREDQ;
2605 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
2607 /* MPI Revision I (UNIT = 0xA) - removed MPI2_SCSIIO_CONTROL_UNTAGGED */
2608 /* mpi_control |= MPI2_SCSIIO_CONTROL_UNTAGGED;
2610 mpi_control |= (0x500);
2613 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
2615 if ((sas_device_priv_data->flags & MPT_DEVICE_TLR_ON))
2616 mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON;
2618 smid = mpt2sas_base_get_smid(ioc, ioc->scsi_io_cb_idx);
2620 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
2621 ioc->name, __func__);
2624 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
2625 memset(mpi_request, 0, sizeof(Mpi2SCSIIORequest_t));
2626 _scsih_setup_eedp(scmd, mpi_request);
2627 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
2628 if (sas_device_priv_data->sas_target->flags &
2629 MPT_TARGET_FLAGS_RAID_COMPONENT)
2630 mpi_request->Function = MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;
2632 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
2633 mpi_request->DevHandle =
2634 cpu_to_le16(sas_device_priv_data->sas_target->handle);
2635 mpi_request->DataLength = cpu_to_le32(scsi_bufflen(scmd));
2636 mpi_request->Control = cpu_to_le32(mpi_control);
2637 mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len);
2638 mpi_request->MsgFlags = MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR;
2639 mpi_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE;
2640 mpi_request->SenseBufferLowAddress =
2641 (u32)mpt2sas_base_get_sense_buffer_dma(ioc, smid);
2642 mpi_request->SGLOffset0 = offsetof(Mpi2SCSIIORequest_t, SGL) / 4;
2643 mpi_request->SGLFlags = cpu_to_le16(MPI2_SCSIIO_SGLFLAGS_TYPE_MPI +
2644 MPI2_SCSIIO_SGLFLAGS_SYSTEM_ADDR);
2646 int_to_scsilun(sas_device_priv_data->lun, (struct scsi_lun *)
2648 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
2650 if (!mpi_request->DataLength) {
2651 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request->SGL);
2653 if (_scsih_build_scatter_gather(ioc, scmd, smid)) {
2654 mpt2sas_base_free_smid(ioc, smid);
2659 _scsih_scsi_lookup_set(ioc, smid, scmd);
2660 mpt2sas_base_put_smid_scsi_io(ioc, smid, 0,
2661 sas_device_priv_data->sas_target->handle);
2665 return SCSI_MLQUEUE_HOST_BUSY;
2669 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
2670 * @sense_buffer: sense data returned by target
2671 * @data: normalized skey/asc/ascq
2676 _scsih_normalize_sense(char *sense_buffer, struct sense_info *data)
2678 if ((sense_buffer[0] & 0x7F) >= 0x72) {
2679 /* descriptor format */
2680 data->skey = sense_buffer[1] & 0x0F;
2681 data->asc = sense_buffer[2];
2682 data->ascq = sense_buffer[3];
2685 data->skey = sense_buffer[2] & 0x0F;
2686 data->asc = sense_buffer[12];
2687 data->ascq = sense_buffer[13];
2691 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
2693 * _scsih_scsi_ioc_info - translated non-succesfull SCSI_IO request
2694 * @ioc: per adapter object
2695 * @scmd: pointer to scsi command object
2696 * @mpi_reply: reply mf payload returned from firmware
2698 * scsi_status - SCSI Status code returned from target device
2699 * scsi_state - state info associated with SCSI_IO determined by ioc
2700 * ioc_status - ioc supplied status info
2705 _scsih_scsi_ioc_info(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
2706 Mpi2SCSIIOReply_t *mpi_reply, u16 smid)
2710 u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) &
2711 MPI2_IOCSTATUS_MASK;
2712 u8 scsi_state = mpi_reply->SCSIState;
2713 u8 scsi_status = mpi_reply->SCSIStatus;
2714 char *desc_ioc_state = NULL;
2715 char *desc_scsi_status = NULL;
2716 char *desc_scsi_state = ioc->tmp_string;
2717 u32 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
2719 if (log_info == 0x31170000)
2722 switch (ioc_status) {
2723 case MPI2_IOCSTATUS_SUCCESS:
2724 desc_ioc_state = "success";
2726 case MPI2_IOCSTATUS_INVALID_FUNCTION:
2727 desc_ioc_state = "invalid function";
2729 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
2730 desc_ioc_state = "scsi recovered error";
2732 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE:
2733 desc_ioc_state = "scsi invalid dev handle";
2735 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
2736 desc_ioc_state = "scsi device not there";
2738 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
2739 desc_ioc_state = "scsi data overrun";
2741 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
2742 desc_ioc_state = "scsi data underrun";
2744 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
2745 desc_ioc_state = "scsi io data error";
2747 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
2748 desc_ioc_state = "scsi protocol error";
2750 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
2751 desc_ioc_state = "scsi task terminated";
2753 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
2754 desc_ioc_state = "scsi residual mismatch";
2756 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
2757 desc_ioc_state = "scsi task mgmt failed";
2759 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
2760 desc_ioc_state = "scsi ioc terminated";
2762 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
2763 desc_ioc_state = "scsi ext terminated";
2765 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
2766 desc_ioc_state = "eedp guard error";
2768 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
2769 desc_ioc_state = "eedp ref tag error";
2771 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
2772 desc_ioc_state = "eedp app tag error";
2775 desc_ioc_state = "unknown";
2779 switch (scsi_status) {
2780 case MPI2_SCSI_STATUS_GOOD:
2781 desc_scsi_status = "good";
2783 case MPI2_SCSI_STATUS_CHECK_CONDITION:
2784 desc_scsi_status = "check condition";
2786 case MPI2_SCSI_STATUS_CONDITION_MET:
2787 desc_scsi_status = "condition met";
2789 case MPI2_SCSI_STATUS_BUSY:
2790 desc_scsi_status = "busy";
2792 case MPI2_SCSI_STATUS_INTERMEDIATE:
2793 desc_scsi_status = "intermediate";
2795 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET:
2796 desc_scsi_status = "intermediate condmet";
2798 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT:
2799 desc_scsi_status = "reservation conflict";
2801 case MPI2_SCSI_STATUS_COMMAND_TERMINATED:
2802 desc_scsi_status = "command terminated";
2804 case MPI2_SCSI_STATUS_TASK_SET_FULL:
2805 desc_scsi_status = "task set full";
2807 case MPI2_SCSI_STATUS_ACA_ACTIVE:
2808 desc_scsi_status = "aca active";
2810 case MPI2_SCSI_STATUS_TASK_ABORTED:
2811 desc_scsi_status = "task aborted";
2814 desc_scsi_status = "unknown";
2818 desc_scsi_state[0] = '\0';
2820 desc_scsi_state = " ";
2821 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
2822 strcat(desc_scsi_state, "response info ");
2823 if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
2824 strcat(desc_scsi_state, "state terminated ");
2825 if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS)
2826 strcat(desc_scsi_state, "no status ");
2827 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED)
2828 strcat(desc_scsi_state, "autosense failed ");
2829 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)
2830 strcat(desc_scsi_state, "autosense valid ");
2832 scsi_print_command(scmd);
2833 printk(MPT2SAS_WARN_FMT "\tdev handle(0x%04x), "
2834 "ioc_status(%s)(0x%04x), smid(%d)\n", ioc->name,
2835 le16_to_cpu(mpi_reply->DevHandle), desc_ioc_state,
2837 printk(MPT2SAS_WARN_FMT "\trequest_len(%d), underflow(%d), "
2838 "resid(%d)\n", ioc->name, scsi_bufflen(scmd), scmd->underflow,
2839 scsi_get_resid(scmd));
2840 printk(MPT2SAS_WARN_FMT "\ttag(%d), transfer_count(%d), "
2841 "sc->result(0x%08x)\n", ioc->name, le16_to_cpu(mpi_reply->TaskTag),
2842 le32_to_cpu(mpi_reply->TransferCount), scmd->result);
2843 printk(MPT2SAS_WARN_FMT "\tscsi_status(%s)(0x%02x), "
2844 "scsi_state(%s)(0x%02x)\n", ioc->name, desc_scsi_status,
2845 scsi_status, desc_scsi_state, scsi_state);
2847 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
2848 struct sense_info data;
2849 _scsih_normalize_sense(scmd->sense_buffer, &data);
2850 printk(MPT2SAS_WARN_FMT "\t[sense_key,asc,ascq]: "
2851 "[0x%02x,0x%02x,0x%02x]\n", ioc->name, data.skey,
2852 data.asc, data.ascq);
2855 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) {
2856 response_info = le32_to_cpu(mpi_reply->ResponseInfo);
2857 response_bytes = (u8 *)&response_info;
2858 _scsih_response_code(ioc, response_bytes[3]);
2864 * _scsih_smart_predicted_fault - illuminate Fault LED
2865 * @ioc: per adapter object
2866 * @handle: device handle
2871 _scsih_smart_predicted_fault(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2873 Mpi2SepReply_t mpi_reply;
2874 Mpi2SepRequest_t mpi_request;
2875 struct scsi_target *starget;
2876 struct MPT2SAS_TARGET *sas_target_priv_data;
2877 Mpi2EventNotificationReply_t *event_reply;
2878 Mpi2EventDataSasDeviceStatusChange_t *event_data;
2879 struct _sas_device *sas_device;
2881 unsigned long flags;
2883 /* only handle non-raid devices */
2884 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2885 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
2887 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2890 starget = sas_device->starget;
2891 sas_target_priv_data = starget->hostdata;
2893 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) ||
2894 ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))) {
2895 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2898 starget_printk(KERN_WARNING, starget, "predicted fault\n");
2899 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2901 if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM) {
2902 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
2903 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
2904 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
2905 mpi_request.SlotStatus =
2906 MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT;
2907 mpi_request.DevHandle = cpu_to_le16(handle);
2908 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS;
2909 if ((mpt2sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
2910 &mpi_request)) != 0) {
2911 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
2912 ioc->name, __FILE__, __LINE__, __func__);
2916 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
2917 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
2918 "enclosure_processor: ioc_status (0x%04x), "
2919 "loginfo(0x%08x)\n", ioc->name,
2920 le16_to_cpu(mpi_reply.IOCStatus),
2921 le32_to_cpu(mpi_reply.IOCLogInfo)));
2926 /* insert into event log */
2927 sz = offsetof(Mpi2EventNotificationReply_t, EventData) +
2928 sizeof(Mpi2EventDataSasDeviceStatusChange_t);
2929 event_reply = kzalloc(sz, GFP_KERNEL);
2931 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
2932 ioc->name, __FILE__, __LINE__, __func__);
2936 event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION;
2937 event_reply->Event =
2938 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE);
2939 event_reply->MsgLength = sz/4;
2940 event_reply->EventDataLength =
2941 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t)/4);
2942 event_data = (Mpi2EventDataSasDeviceStatusChange_t *)
2943 event_reply->EventData;
2944 event_data->ReasonCode = MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA;
2945 event_data->ASC = 0x5D;
2946 event_data->DevHandle = cpu_to_le16(handle);
2947 event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address);
2948 mpt2sas_ctl_add_to_event_log(ioc, event_reply);
2953 * _scsih_io_done - scsi request callback
2954 * @ioc: per adapter object
2955 * @smid: system request message index
2956 * @VF_ID: virtual function id
2957 * @reply: reply message frame(lower 32bit addr)
2959 * Callback handler when using scsih_qcmd.
2964 _scsih_io_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 VF_ID, u32 reply)
2966 Mpi2SCSIIORequest_t *mpi_request;
2967 Mpi2SCSIIOReply_t *mpi_reply;
2968 struct scsi_cmnd *scmd;
2974 struct MPT2SAS_DEVICE *sas_device_priv_data;
2977 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
2978 scmd = _scsih_scsi_lookup_getclear(ioc, smid);
2982 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
2984 if (mpi_reply == NULL) {
2985 scmd->result = DID_OK << 16;
2989 sas_device_priv_data = scmd->device->hostdata;
2990 if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
2991 sas_device_priv_data->sas_target->deleted) {
2992 scmd->result = DID_NO_CONNECT << 16;
2996 /* turning off TLR */
2997 if (!sas_device_priv_data->tlr_snoop_check) {
2998 sas_device_priv_data->tlr_snoop_check++;
2999 if (sas_device_priv_data->flags & MPT_DEVICE_TLR_ON) {
3000 response_code = (le32_to_cpu(mpi_reply->ResponseInfo)
3002 if (response_code ==
3003 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME)
3004 sas_device_priv_data->flags &=
3009 xfer_cnt = le32_to_cpu(mpi_reply->TransferCount);
3010 scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt);
3011 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
3012 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
3013 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
3016 ioc_status &= MPI2_IOCSTATUS_MASK;
3017 scsi_state = mpi_reply->SCSIState;
3018 scsi_status = mpi_reply->SCSIStatus;
3020 if (ioc_status == MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 &&
3021 (scsi_status == MPI2_SCSI_STATUS_BUSY ||
3022 scsi_status == MPI2_SCSI_STATUS_RESERVATION_CONFLICT ||
3023 scsi_status == MPI2_SCSI_STATUS_TASK_SET_FULL)) {
3024 ioc_status = MPI2_IOCSTATUS_SUCCESS;
3027 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
3028 struct sense_info data;
3029 const void *sense_data = mpt2sas_base_get_sense_buffer(ioc,
3031 u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE,
3032 le32_to_cpu(mpi_reply->SenseCount));
3033 memcpy(scmd->sense_buffer, sense_data, sz);
3034 _scsih_normalize_sense(scmd->sense_buffer, &data);
3035 /* failure prediction threshold exceeded */
3036 if (data.asc == 0x5D)
3037 _scsih_smart_predicted_fault(ioc,
3038 le16_to_cpu(mpi_reply->DevHandle));
3041 switch (ioc_status) {
3042 case MPI2_IOCSTATUS_BUSY:
3043 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES:
3044 scmd->result = SAM_STAT_BUSY;
3047 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
3048 scmd->result = DID_NO_CONNECT << 16;
3051 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
3052 if (sas_device_priv_data->block) {
3053 scmd->result = (DID_BUS_BUSY << 16);
3057 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
3058 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
3059 scmd->result = DID_RESET << 16;
3062 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
3063 if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt))
3064 scmd->result = DID_SOFT_ERROR << 16;
3066 scmd->result = (DID_OK << 16) | scsi_status;
3069 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
3070 scmd->result = (DID_OK << 16) | scsi_status;
3072 if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID))
3075 if (xfer_cnt < scmd->underflow) {
3076 if (scsi_status == SAM_STAT_BUSY)
3077 scmd->result = SAM_STAT_BUSY;
3079 scmd->result = DID_SOFT_ERROR << 16;
3080 } else if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
3081 MPI2_SCSI_STATE_NO_SCSI_STATUS))
3082 scmd->result = DID_SOFT_ERROR << 16;
3083 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
3084 scmd->result = DID_RESET << 16;
3085 else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) {
3086 mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID;
3087 mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION;
3088 scmd->result = (DRIVER_SENSE << 24) |
3089 SAM_STAT_CHECK_CONDITION;
3090 scmd->sense_buffer[0] = 0x70;
3091 scmd->sense_buffer[2] = ILLEGAL_REQUEST;
3092 scmd->sense_buffer[12] = 0x20;
3093 scmd->sense_buffer[13] = 0;
3097 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
3098 scsi_set_resid(scmd, 0);
3099 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
3100 case MPI2_IOCSTATUS_SUCCESS:
3101 scmd->result = (DID_OK << 16) | scsi_status;
3102 if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
3103 MPI2_SCSI_STATE_NO_SCSI_STATUS))
3104 scmd->result = DID_SOFT_ERROR << 16;
3105 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
3106 scmd->result = DID_RESET << 16;
3109 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
3110 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
3111 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
3112 _scsih_eedp_error_handling(scmd, ioc_status);
3114 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
3115 case MPI2_IOCSTATUS_INVALID_FUNCTION:
3116 case MPI2_IOCSTATUS_INVALID_SGL:
3117 case MPI2_IOCSTATUS_INTERNAL_ERROR:
3118 case MPI2_IOCSTATUS_INVALID_FIELD:
3119 case MPI2_IOCSTATUS_INVALID_STATE:
3120 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
3121 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
3123 scmd->result = DID_SOFT_ERROR << 16;
3128 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3129 if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY))
3130 _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid);
3134 scsi_dma_unmap(scmd);
3135 scmd->scsi_done(scmd);
3139 * _scsih_sas_host_refresh - refreshing sas host object contents
3140 * @ioc: per adapter object
3141 * @update: update link information
3144 * During port enable, fw will send topology events for every device. Its
3145 * possible that the handles may change from the previous setting, so this
3146 * code keeping handles updating if changed.
3151 _scsih_sas_host_refresh(struct MPT2SAS_ADAPTER *ioc, u8 update)
3156 Mpi2ConfigReply_t mpi_reply;
3157 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
3159 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT
3160 "updating handles for sas_host(0x%016llx)\n",
3161 ioc->name, (unsigned long long)ioc->sas_hba.sas_address));
3163 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys
3164 * sizeof(Mpi2SasIOUnit0PhyData_t));
3165 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
3166 if (!sas_iounit_pg0) {
3167 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3168 ioc->name, __FILE__, __LINE__, __func__);
3171 if (!(mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
3172 sas_iounit_pg0, sz))) {
3173 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
3174 MPI2_IOCSTATUS_MASK;
3175 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
3177 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
3178 ioc->sas_hba.phy[i].handle =
3179 le16_to_cpu(sas_iounit_pg0->PhyData[i].
3180 ControllerDevHandle);
3182 mpt2sas_transport_update_links(
3184 ioc->sas_hba.phy[i].handle,
3185 le16_to_cpu(sas_iounit_pg0->PhyData[i].
3186 AttachedDevHandle), i,
3187 sas_iounit_pg0->PhyData[i].
3188 NegotiatedLinkRate >> 4);
3193 kfree(sas_iounit_pg0);
3197 * _scsih_sas_host_add - create sas host object
3198 * @ioc: per adapter object
3200 * Creating host side data object, stored in ioc->sas_hba
3205 _scsih_sas_host_add(struct MPT2SAS_ADAPTER *ioc)
3208 Mpi2ConfigReply_t mpi_reply;
3209 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
3210 Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
3211 Mpi2SasPhyPage0_t phy_pg0;
3212 Mpi2SasDevicePage0_t sas_device_pg0;
3213 Mpi2SasEnclosurePage0_t enclosure_pg0;
3216 u16 device_missing_delay;
3218 mpt2sas_config_get_number_hba_phys(ioc, &ioc->sas_hba.num_phys);
3219 if (!ioc->sas_hba.num_phys) {
3220 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3221 ioc->name, __FILE__, __LINE__, __func__);
3225 /* sas_iounit page 0 */
3226 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys *
3227 sizeof(Mpi2SasIOUnit0PhyData_t));
3228 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
3229 if (!sas_iounit_pg0) {
3230 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3231 ioc->name, __FILE__, __LINE__, __func__);
3234 if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
3235 sas_iounit_pg0, sz))) {
3236 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3237 ioc->name, __FILE__, __LINE__, __func__);
3240 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
3241 MPI2_IOCSTATUS_MASK;
3242 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
3243 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3244 ioc->name, __FILE__, __LINE__, __func__);
3248 /* sas_iounit page 1 */
3249 sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys *
3250 sizeof(Mpi2SasIOUnit1PhyData_t));
3251 sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
3252 if (!sas_iounit_pg1) {
3253 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3254 ioc->name, __FILE__, __LINE__, __func__);
3257 if ((mpt2sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
3258 sas_iounit_pg1, sz))) {
3259 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3260 ioc->name, __FILE__, __LINE__, __func__);
3263 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
3264 MPI2_IOCSTATUS_MASK;
3265 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
3266 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3267 ioc->name, __FILE__, __LINE__, __func__);
3271 ioc->io_missing_delay =
3272 le16_to_cpu(sas_iounit_pg1->IODeviceMissingDelay);
3273 device_missing_delay =
3274 le16_to_cpu(sas_iounit_pg1->ReportDeviceMissingDelay);
3275 if (device_missing_delay & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16)
3276 ioc->device_missing_delay = (device_missing_delay &
3277 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16;
3279 ioc->device_missing_delay = device_missing_delay &
3280 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
3282 ioc->sas_hba.parent_dev = &ioc->shost->shost_gendev;
3283 ioc->sas_hba.phy = kcalloc(ioc->sas_hba.num_phys,
3284 sizeof(struct _sas_phy), GFP_KERNEL);
3285 if (!ioc->sas_hba.phy) {
3286 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3287 ioc->name, __FILE__, __LINE__, __func__);
3290 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
3291 if ((mpt2sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0,
3293 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3294 ioc->name, __FILE__, __LINE__, __func__);
3297 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
3298 MPI2_IOCSTATUS_MASK;
3299 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
3300 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3301 ioc->name, __FILE__, __LINE__, __func__);
3304 ioc->sas_hba.phy[i].handle =
3305 le16_to_cpu(sas_iounit_pg0->PhyData[i].ControllerDevHandle);
3306 ioc->sas_hba.phy[i].phy_id = i;
3307 mpt2sas_transport_add_host_phy(ioc, &ioc->sas_hba.phy[i],
3308 phy_pg0, ioc->sas_hba.parent_dev);
3310 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
3311 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, ioc->sas_hba.phy[0].handle))) {
3312 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3313 ioc->name, __FILE__, __LINE__, __func__);
3316 ioc->sas_hba.handle = le16_to_cpu(sas_device_pg0.DevHandle);
3317 ioc->sas_hba.enclosure_handle =
3318 le16_to_cpu(sas_device_pg0.EnclosureHandle);
3319 ioc->sas_hba.sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
3320 printk(MPT2SAS_INFO_FMT "host_add: handle(0x%04x), "
3321 "sas_addr(0x%016llx), phys(%d)\n", ioc->name, ioc->sas_hba.handle,
3322 (unsigned long long) ioc->sas_hba.sas_address,
3323 ioc->sas_hba.num_phys) ;
3325 if (ioc->sas_hba.enclosure_handle) {
3326 if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply,
3328 MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
3329 ioc->sas_hba.enclosure_handle))) {
3330 ioc->sas_hba.enclosure_logical_id =
3331 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
3336 kfree(sas_iounit_pg1);
3337 kfree(sas_iounit_pg0);
3341 * _scsih_expander_add - creating expander object
3342 * @ioc: per adapter object
3343 * @handle: expander handle
3345 * Creating expander object, stored in ioc->sas_expander_list.
3347 * Return 0 for success, else error.
3350 _scsih_expander_add(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3352 struct _sas_node *sas_expander;
3353 Mpi2ConfigReply_t mpi_reply;
3354 Mpi2ExpanderPage0_t expander_pg0;
3355 Mpi2ExpanderPage1_t expander_pg1;
3356 Mpi2SasEnclosurePage0_t enclosure_pg0;
3361 unsigned long flags;
3362 struct _sas_port *mpt2sas_port = NULL;
3368 if (ioc->shost_recovery)
3371 if ((mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
3372 MPI2_SAS_EXPAND_PGAD_FORM_HNDL, handle))) {
3373 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3374 ioc->name, __FILE__, __LINE__, __func__);
3378 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
3379 MPI2_IOCSTATUS_MASK;
3380 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
3381 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3382 ioc->name, __FILE__, __LINE__, __func__);
3386 /* handle out of order topology events */
3387 parent_handle = le16_to_cpu(expander_pg0.ParentDevHandle);
3388 if (parent_handle >= ioc->sas_hba.num_phys) {
3389 spin_lock_irqsave(&ioc->sas_node_lock, flags);
3390 sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc,
3392 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
3393 if (!sas_expander) {
3394 rc = _scsih_expander_add(ioc, parent_handle);
3400 sas_address = le64_to_cpu(expander_pg0.SASAddress);
3402 spin_lock_irqsave(&ioc->sas_node_lock, flags);
3403 sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
3405 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
3410 sas_expander = kzalloc(sizeof(struct _sas_node),
3412 if (!sas_expander) {
3413 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3414 ioc->name, __FILE__, __LINE__, __func__);
3418 sas_expander->handle = handle;
3419 sas_expander->num_phys = expander_pg0.NumPhys;
3420 sas_expander->parent_handle = parent_handle;
3421 sas_expander->enclosure_handle =
3422 le16_to_cpu(expander_pg0.EnclosureHandle);
3423 sas_expander->sas_address = sas_address;
3425 printk(MPT2SAS_INFO_FMT "expander_add: handle(0x%04x),"
3426 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc->name,
3427 handle, sas_expander->parent_handle, (unsigned long long)
3428 sas_expander->sas_address, sas_expander->num_phys);
3430 if (!sas_expander->num_phys)
3432 sas_expander->phy = kcalloc(sas_expander->num_phys,
3433 sizeof(struct _sas_phy), GFP_KERNEL);
3434 if (!sas_expander->phy) {
3435 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3436 ioc->name, __FILE__, __LINE__, __func__);
3441 INIT_LIST_HEAD(&sas_expander->sas_port_list);
3442 mpt2sas_port = mpt2sas_transport_port_add(ioc, handle,
3443 sas_expander->parent_handle);
3444 if (!mpt2sas_port) {
3445 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3446 ioc->name, __FILE__, __LINE__, __func__);
3450 sas_expander->parent_dev = &mpt2sas_port->rphy->dev;
3452 for (i = 0 ; i < sas_expander->num_phys ; i++) {
3453 if ((mpt2sas_config_get_expander_pg1(ioc, &mpi_reply,
3454 &expander_pg1, i, handle))) {
3455 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3456 ioc->name, __FILE__, __LINE__, __func__);
3460 sas_expander->phy[i].handle = handle;
3461 sas_expander->phy[i].phy_id = i;
3463 if ((mpt2sas_transport_add_expander_phy(ioc,
3464 &sas_expander->phy[i], expander_pg1,
3465 sas_expander->parent_dev))) {
3466 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3467 ioc->name, __FILE__, __LINE__, __func__);
3473 if (sas_expander->enclosure_handle) {
3474 if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply,
3475 &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
3476 sas_expander->enclosure_handle))) {
3477 sas_expander->enclosure_logical_id =
3478 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
3482 _scsih_expander_node_add(ioc, sas_expander);
3488 mpt2sas_transport_port_remove(ioc, sas_expander->sas_address,
3489 sas_expander->parent_handle);
3490 kfree(sas_expander);
3495 * _scsih_expander_remove - removing expander object
3496 * @ioc: per adapter object
3497 * @handle: expander handle
3502 _scsih_expander_remove(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3504 struct _sas_node *sas_expander;
3505 unsigned long flags;
3507 if (ioc->shost_recovery)
3510 spin_lock_irqsave(&ioc->sas_node_lock, flags);
3511 sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc, handle);
3512 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
3513 _scsih_expander_node_remove(ioc, sas_expander);
3517 * _scsih_add_device - creating sas device object
3518 * @ioc: per adapter object
3519 * @handle: sas device handle
3520 * @phy_num: phy number end device attached to
3521 * @is_pd: is this hidden raid component
3523 * Creating end device object, stored in ioc->sas_device_list.
3525 * Returns 0 for success, non-zero for failure.
3528 _scsih_add_device(struct MPT2SAS_ADAPTER *ioc, u16 handle, u8 phy_num, u8 is_pd)
3530 Mpi2ConfigReply_t mpi_reply;
3531 Mpi2SasDevicePage0_t sas_device_pg0;
3532 Mpi2SasEnclosurePage0_t enclosure_pg0;
3533 struct _sas_device *sas_device;
3537 unsigned long flags;
3539 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
3540 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
3541 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3542 ioc->name, __FILE__, __LINE__, __func__);
3546 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
3547 MPI2_IOCSTATUS_MASK;
3548 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
3549 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3550 ioc->name, __FILE__, __LINE__, __func__);
3554 /* check if device is present */
3555 if (!(le16_to_cpu(sas_device_pg0.Flags) &
3556 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
3557 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3558 ioc->name, __FILE__, __LINE__, __func__);
3559 printk(MPT2SAS_ERR_FMT "Flags = 0x%04x\n",
3560 ioc->name, le16_to_cpu(sas_device_pg0.Flags));
3564 /* check if there were any issus with discovery */
3565 if (sas_device_pg0.AccessStatus ==
3566 MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED) {
3567 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3568 ioc->name, __FILE__, __LINE__, __func__);
3569 printk(MPT2SAS_ERR_FMT "AccessStatus = 0x%02x\n",
3570 ioc->name, sas_device_pg0.AccessStatus);
3574 /* check if this is end device */
3575 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
3576 if (!(_scsih_is_end_device(device_info))) {
3577 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3578 ioc->name, __FILE__, __LINE__, __func__);
3582 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
3584 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3585 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
3587 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3590 _scsih_ublock_io_device(ioc, handle);
3594 sas_device = kzalloc(sizeof(struct _sas_device),
3597 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3598 ioc->name, __FILE__, __LINE__, __func__);
3602 sas_device->handle = handle;
3603 sas_device->parent_handle =
3604 le16_to_cpu(sas_device_pg0.ParentDevHandle);
3605 sas_device->enclosure_handle =
3606 le16_to_cpu(sas_device_pg0.EnclosureHandle);
3608 le16_to_cpu(sas_device_pg0.Slot);
3609 sas_device->device_info = device_info;
3610 sas_device->sas_address = sas_address;
3611 sas_device->hidden_raid_component = is_pd;
3613 /* get enclosure_logical_id */
3614 if (sas_device->enclosure_handle && !(mpt2sas_config_get_enclosure_pg0(
3615 ioc, &mpi_reply, &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
3616 sas_device->enclosure_handle)))
3617 sas_device->enclosure_logical_id =
3618 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
3620 /* get device name */
3621 sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName);
3623 if (ioc->wait_for_port_enable_to_complete)
3624 _scsih_sas_device_init_add(ioc, sas_device);
3626 _scsih_sas_device_add(ioc, sas_device);
3632 * _scsih_remove_device - removing sas device object
3633 * @ioc: per adapter object
3634 * @handle: sas device handle
3639 _scsih_remove_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3641 struct MPT2SAS_TARGET *sas_target_priv_data;
3642 struct _sas_device *sas_device;
3643 unsigned long flags;
3644 Mpi2SasIoUnitControlReply_t mpi_reply;
3645 Mpi2SasIoUnitControlRequest_t mpi_request;
3648 /* lookup sas_device */
3649 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3650 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
3652 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3656 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter: handle"
3657 "(0x%04x)\n", ioc->name, __func__, handle));
3659 if (sas_device->starget && sas_device->starget->hostdata) {
3660 sas_target_priv_data = sas_device->starget->hostdata;
3661 sas_target_priv_data->deleted = 1;
3663 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3665 if (ioc->remove_host)
3668 /* Target Reset to flush out all the outstanding IO */
3669 device_handle = (sas_device->hidden_raid_component) ?
3670 sas_device->volume_handle : handle;
3671 if (device_handle) {
3672 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "issue target reset: "
3673 "handle(0x%04x)\n", ioc->name, device_handle));
3674 mutex_lock(&ioc->tm_cmds.mutex);
3675 mpt2sas_scsih_issue_tm(ioc, device_handle, 0,
3676 MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0, 10);
3677 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
3678 mutex_unlock(&ioc->tm_cmds.mutex);
3679 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "issue target reset "
3680 "done: handle(0x%04x)\n", ioc->name, device_handle));
3681 if (ioc->shost_recovery)
3685 /* SAS_IO_UNIT_CNTR - send REMOVE_DEVICE */
3686 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "sas_iounit: handle"
3687 "(0x%04x)\n", ioc->name, handle));
3688 memset(&mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t));
3689 mpi_request.Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL;
3690 mpi_request.Operation = MPI2_SAS_OP_REMOVE_DEVICE;
3691 mpi_request.DevHandle = handle;
3692 mpi_request.VF_ID = 0;
3693 if ((mpt2sas_base_sas_iounit_control(ioc, &mpi_reply,
3694 &mpi_request)) != 0) {
3695 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3696 ioc->name, __FILE__, __LINE__, __func__);
3699 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "sas_iounit: ioc_status"
3700 "(0x%04x), loginfo(0x%08x)\n", ioc->name,
3701 le16_to_cpu(mpi_reply.IOCStatus),
3702 le32_to_cpu(mpi_reply.IOCLogInfo)));
3706 _scsih_ublock_io_device(ioc, handle);
3708 mpt2sas_transport_port_remove(ioc, sas_device->sas_address,
3709 sas_device->parent_handle);
3711 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), sas_addr"
3712 "(0x%016llx)\n", ioc->name, sas_device->handle,
3713 (unsigned long long) sas_device->sas_address);
3714 _scsih_sas_device_remove(ioc, sas_device);
3716 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: exit: handle"
3717 "(0x%04x)\n", ioc->name, __func__, handle));
3720 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3722 * _scsih_sas_topology_change_event_debug - debug for topology event
3723 * @ioc: per adapter object
3724 * @event_data: event data payload
3728 _scsih_sas_topology_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
3729 Mpi2EventDataSasTopologyChangeList_t *event_data)
3735 char *status_str = NULL;
3738 switch (event_data->ExpStatus) {
3739 case MPI2_EVENT_SAS_TOPO_ES_ADDED:
3742 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING:
3743 status_str = "remove";
3745 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING:
3746 status_str = "responding";
3748 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING:
3749 status_str = "remove delay";
3752 status_str = "unknown status";
3755 printk(MPT2SAS_DEBUG_FMT "sas topology change: (%s)\n",
3756 ioc->name, status_str);
3757 printk(KERN_DEBUG "\thandle(0x%04x), enclosure_handle(0x%04x) "
3758 "start_phy(%02d), count(%d)\n",
3759 le16_to_cpu(event_data->ExpanderDevHandle),
3760 le16_to_cpu(event_data->EnclosureHandle),
3761 event_data->StartPhyNum, event_data->NumEntries);
3762 for (i = 0; i < event_data->NumEntries; i++) {
3763 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
3766 phy_number = event_data->StartPhyNum + i;
3767 reason_code = event_data->PHY[i].PhyStatus &
3768 MPI2_EVENT_SAS_TOPO_RC_MASK;
3769 switch (reason_code) {
3770 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
3771 snprintf(link_rate, 25, ": add, link(0x%02x)",
3772 (event_data->PHY[i].LinkRate >> 4));
3773 status_str = link_rate;
3775 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
3776 status_str = ": remove";
3778 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING:
3779 status_str = ": remove_delay";
3781 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
3782 snprintf(link_rate, 25, ": link(0x%02x)",
3783 (event_data->PHY[i].LinkRate >> 4));
3784 status_str = link_rate;
3786 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE:
3787 status_str = ": responding";
3790 status_str = ": unknown";
3793 printk(KERN_DEBUG "\tphy(%02d), attached_handle(0x%04x)%s\n",
3794 phy_number, handle, status_str);
3800 * _scsih_sas_topology_change_event - handle topology changes
3801 * @ioc: per adapter object
3803 * @event_data: event data payload
3809 _scsih_sas_topology_change_event(struct MPT2SAS_ADAPTER *ioc, u8 VF_ID,
3810 Mpi2EventDataSasTopologyChangeList_t *event_data,
3811 struct fw_event_work *fw_event)
3814 u16 parent_handle, handle;
3817 struct _sas_node *sas_expander;
3818 unsigned long flags;
3821 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3822 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
3823 _scsih_sas_topology_change_event_debug(ioc, event_data);
3826 if (!ioc->sas_hba.num_phys)
3827 _scsih_sas_host_add(ioc);
3829 _scsih_sas_host_refresh(ioc, 0);
3831 if (fw_event->ignore) {
3832 dewtprintk(ioc, printk(MPT2SAS_DEBUG_FMT "ignoring expander "
3833 "event\n", ioc->name));
3837 parent_handle = le16_to_cpu(event_data->ExpanderDevHandle);
3839 /* handle expander add */
3840 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_ADDED)
3841 if (_scsih_expander_add(ioc, parent_handle) != 0)
3844 /* handle siblings events */
3845 for (i = 0; i < event_data->NumEntries; i++) {
3846 if (fw_event->ignore) {
3847 dewtprintk(ioc, printk(MPT2SAS_DEBUG_FMT "ignoring "
3848 "expander event\n", ioc->name));
3851 if (ioc->shost_recovery)
3853 if (event_data->PHY[i].PhyStatus &
3854 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT)
3856 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
3859 phy_number = event_data->StartPhyNum + i;
3860 reason_code = event_data->PHY[i].PhyStatus &
3861 MPI2_EVENT_SAS_TOPO_RC_MASK;
3862 link_rate_ = event_data->PHY[i].LinkRate >> 4;
3863 switch (reason_code) {
3864 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
3865 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
3866 if (!parent_handle) {
3867 if (phy_number < ioc->sas_hba.num_phys)
3868 mpt2sas_transport_update_links(
3870 ioc->sas_hba.phy[phy_number].handle,
3871 handle, phy_number, link_rate_);
3873 spin_lock_irqsave(&ioc->sas_node_lock, flags);
3875 mpt2sas_scsih_expander_find_by_handle(ioc,
3877 spin_unlock_irqrestore(&ioc->sas_node_lock,
3880 if (phy_number < sas_expander->num_phys)
3881 mpt2sas_transport_update_links(
3884 phy[phy_number].handle,
3889 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED) {
3890 if (link_rate_ < MPI2_SAS_NEG_LINK_RATE_1_5)
3892 _scsih_add_device(ioc, handle, phy_number, 0);
3895 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
3896 _scsih_remove_device(ioc, handle);
3901 /* handle expander removal */
3902 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING)
3903 _scsih_expander_remove(ioc, parent_handle);
3907 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3909 * _scsih_sas_device_status_change_event_debug - debug for device event
3910 * @event_data: event data payload
3916 _scsih_sas_device_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
3917 Mpi2EventDataSasDeviceStatusChange_t *event_data)
3919 char *reason_str = NULL;
3921 switch (event_data->ReasonCode) {
3922 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
3923 reason_str = "smart data";
3925 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED:
3926 reason_str = "unsupported device discovered";
3928 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
3929 reason_str = "internal device reset";
3931 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL:
3932 reason_str = "internal task abort";
3934 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL:
3935 reason_str = "internal task abort set";
3937 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL:
3938 reason_str = "internal clear task set";
3940 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL:
3941 reason_str = "internal query task";
3943 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE:
3944 reason_str = "sata init failure";
3946 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET:
3947 reason_str = "internal device reset complete";
3949 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL:
3950 reason_str = "internal task abort complete";
3952 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION:
3953 reason_str = "internal async notification";
3956 reason_str = "unknown reason";
3959 printk(MPT2SAS_DEBUG_FMT "device status change: (%s)\n"
3960 "\thandle(0x%04x), sas address(0x%016llx)", ioc->name,
3961 reason_str, le16_to_cpu(event_data->DevHandle),
3962 (unsigned long long)le64_to_cpu(event_data->SASAddress));
3963 if (event_data->ReasonCode == MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA)
3964 printk(MPT2SAS_DEBUG_FMT ", ASC(0x%x), ASCQ(0x%x)\n", ioc->name,
3965 event_data->ASC, event_data->ASCQ);
3966 printk(KERN_INFO "\n");
3971 * _scsih_sas_device_status_change_event - handle device status change
3972 * @ioc: per adapter object
3974 * @event_data: event data payload
3980 _scsih_sas_device_status_change_event(struct MPT2SAS_ADAPTER *ioc, u8 VF_ID,
3981 Mpi2EventDataSasDeviceStatusChange_t *event_data)
3983 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3984 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
3985 _scsih_sas_device_status_change_event_debug(ioc, event_data);
3989 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3991 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure event
3992 * @ioc: per adapter object
3993 * @event_data: event data payload
3999 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
4000 Mpi2EventDataSasEnclDevStatusChange_t *event_data)
4002 char *reason_str = NULL;
4004 switch (event_data->ReasonCode) {
4005 case MPI2_EVENT_SAS_ENCL_RC_ADDED:
4006 reason_str = "enclosure add";
4008 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING:
4009 reason_str = "enclosure remove";
4012 reason_str = "unknown reason";
4016 printk(MPT2SAS_DEBUG_FMT "enclosure status change: (%s)\n"
4017 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
4018 " number slots(%d)\n", ioc->name, reason_str,
4019 le16_to_cpu(event_data->EnclosureHandle),
4020 (unsigned long long)le64_to_cpu(event_data->EnclosureLogicalID),
4021 le16_to_cpu(event_data->StartSlot));
4026 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
4027 * @ioc: per adapter object
4029 * @event_data: event data payload
4035 _scsih_sas_enclosure_dev_status_change_event(struct MPT2SAS_ADAPTER *ioc,
4036 u8 VF_ID, Mpi2EventDataSasEnclDevStatusChange_t *event_data)
4038 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4039 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
4040 _scsih_sas_enclosure_dev_status_change_event_debug(ioc,
4046 * _scsih_sas_broadcast_primative_event - handle broadcast events
4047 * @ioc: per adapter object
4048 * @event_data: event data payload
4054 _scsih_sas_broadcast_primative_event(struct MPT2SAS_ADAPTER *ioc, u8 VF_ID,
4055 Mpi2EventDataSasBroadcastPrimitive_t *event_data)
4057 struct scsi_cmnd *scmd;
4060 struct MPT2SAS_DEVICE *sas_device_priv_data;
4061 u32 termination_count;
4063 Mpi2SCSITaskManagementReply_t *mpi_reply;
4065 dewtprintk(ioc, printk(MPT2SAS_DEBUG_FMT "broadcast primative: "
4066 "phy number(%d), width(%d)\n", ioc->name, event_data->PhyNum,
4067 event_data->PortWidth));
4069 dtmprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: enter\n", ioc->name,
4072 mutex_lock(&ioc->tm_cmds.mutex);
4073 termination_count = 0;
4075 mpi_reply = ioc->tm_cmds.reply;
4076 for (smid = 1; smid <= ioc->request_depth; smid++) {
4077 scmd = _scsih_scsi_lookup_get(ioc, smid);
4080 sas_device_priv_data = scmd->device->hostdata;
4081 if (!sas_device_priv_data || !sas_device_priv_data->sas_target)
4083 /* skip hidden raid components */
4084 if (sas_device_priv_data->sas_target->flags &
4085 MPT_TARGET_FLAGS_RAID_COMPONENT)
4088 if (sas_device_priv_data->sas_target->flags &
4089 MPT_TARGET_FLAGS_VOLUME)
4092 handle = sas_device_priv_data->sas_target->handle;
4093 lun = sas_device_priv_data->lun;
4096 mpt2sas_scsih_issue_tm(ioc, handle, lun,
4097 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, smid, 30);
4098 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
4100 if ((mpi_reply->IOCStatus == MPI2_IOCSTATUS_SUCCESS) &&
4101 (mpi_reply->ResponseCode ==
4102 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED ||
4103 mpi_reply->ResponseCode ==
4104 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC))
4107 mpt2sas_scsih_issue_tm(ioc, handle, lun,
4108 MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET, 0, 30);
4109 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
4110 termination_count += le32_to_cpu(mpi_reply->TerminationCount);
4112 ioc->broadcast_aen_busy = 0;
4113 mutex_unlock(&ioc->tm_cmds.mutex);
4115 dtmprintk(ioc, printk(MPT2SAS_DEBUG_FMT
4116 "%s - exit, query_count = %d termination_count = %d\n",
4117 ioc->name, __func__, query_count, termination_count));
4121 * _scsih_sas_discovery_event - handle discovery events
4122 * @ioc: per adapter object
4123 * @event_data: event data payload
4129 _scsih_sas_discovery_event(struct MPT2SAS_ADAPTER *ioc, u8 VF_ID,
4130 Mpi2EventDataSasDiscovery_t *event_data)
4132 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4133 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) {
4134 printk(MPT2SAS_DEBUG_FMT "discovery event: (%s)", ioc->name,
4135 (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ?
4137 if (event_data->DiscoveryStatus)
4138 printk(MPT2SAS_DEBUG_FMT ", discovery_status(0x%08x)",
4139 ioc->name, le32_to_cpu(event_data->DiscoveryStatus));
4144 if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED &&
4145 !ioc->sas_hba.num_phys)
4146 _scsih_sas_host_add(ioc);
4150 * _scsih_reprobe_lun - reprobing lun
4151 * @sdev: scsi device struct
4152 * @no_uld_attach: sdev->no_uld_attach flag setting
4156 _scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach)
4160 sdev->no_uld_attach = no_uld_attach ? 1 : 0;
4161 sdev_printk(KERN_INFO, sdev, "%s raid component\n",
4162 sdev->no_uld_attach ? "hidding" : "exposing");
4163 rc = scsi_device_reprobe(sdev);
4167 * _scsih_reprobe_target - reprobing target
4168 * @starget: scsi target struct
4169 * @no_uld_attach: sdev->no_uld_attach flag setting
4171 * Note: no_uld_attach flag determines whether the disk device is attached
4172 * to block layer. A value of `1` means to not attach.
4175 _scsih_reprobe_target(struct scsi_target *starget, int no_uld_attach)
4177 struct MPT2SAS_TARGET *sas_target_priv_data = starget->hostdata;
4180 sas_target_priv_data->flags |= MPT_TARGET_FLAGS_RAID_COMPONENT;
4182 sas_target_priv_data->flags &= ~MPT_TARGET_FLAGS_RAID_COMPONENT;
4184 starget_for_each_device(starget, no_uld_attach ? (void *)1 : NULL,
4185 _scsih_reprobe_lun);
4188 * _scsih_sas_volume_add - add new volume
4189 * @ioc: per adapter object
4190 * @element: IR config element data
4196 _scsih_sas_volume_add(struct MPT2SAS_ADAPTER *ioc,
4197 Mpi2EventIrConfigElement_t *element)
4199 struct _raid_device *raid_device;
4200 unsigned long flags;
4202 u16 handle = le16_to_cpu(element->VolDevHandle);
4205 mpt2sas_config_get_volume_wwid(ioc, handle, &wwid);
4207 printk(MPT2SAS_ERR_FMT
4208 "failure at %s:%d/%s()!\n", ioc->name,
4209 __FILE__, __LINE__, __func__);
4213 spin_lock_irqsave(&ioc->raid_device_lock, flags);
4214 raid_device = _scsih_raid_device_find_by_wwid(ioc, wwid);
4215 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
4220 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
4222 printk(MPT2SAS_ERR_FMT
4223 "failure at %s:%d/%s()!\n", ioc->name,
4224 __FILE__, __LINE__, __func__);
4228 raid_device->id = ioc->sas_id++;
4229 raid_device->channel = RAID_CHANNEL;
4230 raid_device->handle = handle;
4231 raid_device->wwid = wwid;
4232 _scsih_raid_device_add(ioc, raid_device);
4233 if (!ioc->wait_for_port_enable_to_complete) {
4234 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
4235 raid_device->id, 0);
4237 _scsih_raid_device_remove(ioc, raid_device);
4239 _scsih_determine_boot_device(ioc, raid_device, 1);
4243 * _scsih_sas_volume_delete - delete volume
4244 * @ioc: per adapter object
4245 * @element: IR config element data
4251 _scsih_sas_volume_delete(struct MPT2SAS_ADAPTER *ioc,
4252 Mpi2EventIrConfigElement_t *element)
4254 struct _raid_device *raid_device;
4255 u16 handle = le16_to_cpu(element->VolDevHandle);
4256 unsigned long flags;
4257 struct MPT2SAS_TARGET *sas_target_priv_data;
4259 spin_lock_irqsave(&ioc->raid_device_lock, flags);
4260 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
4261 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
4264 if (raid_device->starget) {
4265 sas_target_priv_data = raid_device->starget->hostdata;
4266 sas_target_priv_data->deleted = 1;
4267 scsi_remove_target(&raid_device->starget->dev);
4269 _scsih_raid_device_remove(ioc, raid_device);
4273 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
4274 * @ioc: per adapter object
4275 * @element: IR config element data
4281 _scsih_sas_pd_expose(struct MPT2SAS_ADAPTER *ioc,
4282 Mpi2EventIrConfigElement_t *element)
4284 struct _sas_device *sas_device;
4285 unsigned long flags;
4286 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
4288 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4289 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
4290 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4294 /* exposing raid component */
4295 sas_device->volume_handle = 0;
4296 sas_device->volume_wwid = 0;
4297 sas_device->hidden_raid_component = 0;
4298 _scsih_reprobe_target(sas_device->starget, 0);
4302 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
4303 * @ioc: per adapter object
4304 * @element: IR config element data
4310 _scsih_sas_pd_hide(struct MPT2SAS_ADAPTER *ioc,
4311 Mpi2EventIrConfigElement_t *element)
4313 struct _sas_device *sas_device;
4314 unsigned long flags;
4315 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
4317 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4318 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
4319 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4323 /* hiding raid component */
4324 mpt2sas_config_get_volume_handle(ioc, handle,
4325 &sas_device->volume_handle);
4326 mpt2sas_config_get_volume_wwid(ioc, sas_device->volume_handle,
4327 &sas_device->volume_wwid);
4328 sas_device->hidden_raid_component = 1;
4329 _scsih_reprobe_target(sas_device->starget, 1);
4333 * _scsih_sas_pd_delete - delete pd component
4334 * @ioc: per adapter object
4335 * @element: IR config element data
4341 _scsih_sas_pd_delete(struct MPT2SAS_ADAPTER *ioc,
4342 Mpi2EventIrConfigElement_t *element)
4344 struct _sas_device *sas_device;
4345 unsigned long flags;
4346 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
4348 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4349 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
4350 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4353 _scsih_remove_device(ioc, handle);
4357 * _scsih_sas_pd_add - remove pd component
4358 * @ioc: per adapter object
4359 * @element: IR config element data
4365 _scsih_sas_pd_add(struct MPT2SAS_ADAPTER *ioc,
4366 Mpi2EventIrConfigElement_t *element)
4368 struct _sas_device *sas_device;
4369 unsigned long flags;
4370 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
4371 Mpi2ConfigReply_t mpi_reply;
4372 Mpi2SasDevicePage0_t sas_device_pg0;
4375 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4376 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
4377 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4379 sas_device->hidden_raid_component = 1;
4383 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
4384 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
4385 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4386 ioc->name, __FILE__, __LINE__, __func__);
4390 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4391 MPI2_IOCSTATUS_MASK;
4392 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4393 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4394 ioc->name, __FILE__, __LINE__, __func__);
4398 mpt2sas_transport_update_links(ioc,
4399 le16_to_cpu(sas_device_pg0.ParentDevHandle),
4400 handle, sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
4402 _scsih_add_device(ioc, handle, 0, 1);
4405 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4407 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
4408 * @ioc: per adapter object
4409 * @event_data: event data payload
4415 _scsih_sas_ir_config_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
4416 Mpi2EventDataIrConfigChangeList_t *event_data)
4418 Mpi2EventIrConfigElement_t *element;
4421 char *reason_str = NULL, *element_str = NULL;
4423 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
4425 printk(MPT2SAS_DEBUG_FMT "raid config change: (%s), elements(%d)\n",
4426 ioc->name, (le32_to_cpu(event_data->Flags) &
4427 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ?
4428 "foreign" : "native", event_data->NumElements);
4429 for (i = 0; i < event_data->NumElements; i++, element++) {
4430 switch (element->ReasonCode) {
4431 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
4434 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
4435 reason_str = "remove";
4437 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE:
4438 reason_str = "no change";
4440 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
4441 reason_str = "hide";
4443 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
4444 reason_str = "unhide";
4446 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
4447 reason_str = "volume_created";
4449 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
4450 reason_str = "volume_deleted";
4452 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
4453 reason_str = "pd_created";
4455 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
4456 reason_str = "pd_deleted";
4459 reason_str = "unknown reason";
4462 element_type = le16_to_cpu(element->ElementFlags) &
4463 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK;
4464 switch (element_type) {
4465 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT:
4466 element_str = "volume";
4468 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT:
4469 element_str = "phys disk";
4471 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT:
4472 element_str = "hot spare";
4475 element_str = "unknown element";
4478 printk(KERN_DEBUG "\t(%s:%s), vol handle(0x%04x), "
4479 "pd handle(0x%04x), pd num(0x%02x)\n", element_str,
4480 reason_str, le16_to_cpu(element->VolDevHandle),
4481 le16_to_cpu(element->PhysDiskDevHandle),
4482 element->PhysDiskNum);
4488 * _scsih_sas_ir_config_change_event - handle ir configuration change events
4489 * @ioc: per adapter object
4491 * @event_data: event data payload
4497 _scsih_sas_ir_config_change_event(struct MPT2SAS_ADAPTER *ioc, u8 VF_ID,
4498 Mpi2EventDataIrConfigChangeList_t *event_data)
4500 Mpi2EventIrConfigElement_t *element;
4504 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4505 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
4506 _scsih_sas_ir_config_change_event_debug(ioc, event_data);
4509 foreign_config = (le32_to_cpu(event_data->Flags) &
4510 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0;
4512 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
4513 for (i = 0; i < event_data->NumElements; i++, element++) {
4515 switch (element->ReasonCode) {
4516 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
4517 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
4518 if (!foreign_config)
4519 _scsih_sas_volume_add(ioc, element);
4521 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
4522 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
4523 if (!foreign_config)
4524 _scsih_sas_volume_delete(ioc, element);
4526 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
4527 _scsih_sas_pd_hide(ioc, element);
4529 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
4530 _scsih_sas_pd_expose(ioc, element);
4532 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
4533 _scsih_sas_pd_add(ioc, element);
4535 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
4536 _scsih_sas_pd_delete(ioc, element);
4543 * _scsih_sas_ir_volume_event - IR volume event
4544 * @ioc: per adapter object
4545 * @event_data: event data payload
4551 _scsih_sas_ir_volume_event(struct MPT2SAS_ADAPTER *ioc, u8 VF_ID,
4552 Mpi2EventDataIrVolume_t *event_data)
4555 unsigned long flags;
4556 struct _raid_device *raid_device;
4560 struct MPT2SAS_TARGET *sas_target_priv_data;
4562 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
4565 handle = le16_to_cpu(event_data->VolDevHandle);
4566 state = le32_to_cpu(event_data->NewValue);
4567 dewtprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: handle(0x%04x), "
4568 "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle,
4569 le32_to_cpu(event_data->PreviousValue), state));
4571 spin_lock_irqsave(&ioc->raid_device_lock, flags);
4572 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
4573 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
4576 case MPI2_RAID_VOL_STATE_MISSING:
4577 case MPI2_RAID_VOL_STATE_FAILED:
4580 if (raid_device->starget) {
4581 sas_target_priv_data = raid_device->starget->hostdata;
4582 sas_target_priv_data->deleted = 1;
4583 scsi_remove_target(&raid_device->starget->dev);
4585 _scsih_raid_device_remove(ioc, raid_device);
4588 case MPI2_RAID_VOL_STATE_ONLINE:
4589 case MPI2_RAID_VOL_STATE_DEGRADED:
4590 case MPI2_RAID_VOL_STATE_OPTIMAL:
4594 mpt2sas_config_get_volume_wwid(ioc, handle, &wwid);
4596 printk(MPT2SAS_ERR_FMT
4597 "failure at %s:%d/%s()!\n", ioc->name,
4598 __FILE__, __LINE__, __func__);
4602 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
4604 printk(MPT2SAS_ERR_FMT
4605 "failure at %s:%d/%s()!\n", ioc->name,
4606 __FILE__, __LINE__, __func__);
4610 raid_device->id = ioc->sas_id++;
4611 raid_device->channel = RAID_CHANNEL;
4612 raid_device->handle = handle;
4613 raid_device->wwid = wwid;
4614 _scsih_raid_device_add(ioc, raid_device);
4615 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
4616 raid_device->id, 0);
4618 _scsih_raid_device_remove(ioc, raid_device);
4621 case MPI2_RAID_VOL_STATE_INITIALIZING:
4628 * _scsih_sas_ir_physical_disk_event - PD event
4629 * @ioc: per adapter object
4630 * @event_data: event data payload
4636 _scsih_sas_ir_physical_disk_event(struct MPT2SAS_ADAPTER *ioc, u8 VF_ID,
4637 Mpi2EventDataIrPhysicalDisk_t *event_data)
4641 struct _sas_device *sas_device;
4642 unsigned long flags;
4643 Mpi2ConfigReply_t mpi_reply;
4644 Mpi2SasDevicePage0_t sas_device_pg0;
4647 if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED)
4650 handle = le16_to_cpu(event_data->PhysDiskDevHandle);
4651 state = le32_to_cpu(event_data->NewValue);
4653 dewtprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: handle(0x%04x), "
4654 "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle,
4655 le32_to_cpu(event_data->PreviousValue), state));
4657 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4658 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
4659 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4662 case MPI2_RAID_PD_STATE_ONLINE:
4663 case MPI2_RAID_PD_STATE_DEGRADED:
4664 case MPI2_RAID_PD_STATE_REBUILDING:
4665 case MPI2_RAID_PD_STATE_OPTIMAL:
4667 sas_device->hidden_raid_component = 1;
4671 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
4672 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
4674 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4675 ioc->name, __FILE__, __LINE__, __func__);
4679 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4680 MPI2_IOCSTATUS_MASK;
4681 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4682 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4683 ioc->name, __FILE__, __LINE__, __func__);
4687 mpt2sas_transport_update_links(ioc,
4688 le16_to_cpu(sas_device_pg0.ParentDevHandle),
4689 handle, sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
4691 _scsih_add_device(ioc, handle, 0, 1);
4695 case MPI2_RAID_PD_STATE_OFFLINE:
4696 case MPI2_RAID_PD_STATE_NOT_CONFIGURED:
4697 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE:
4698 case MPI2_RAID_PD_STATE_HOT_SPARE:
4704 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4706 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
4707 * @ioc: per adapter object
4708 * @event_data: event data payload
4714 _scsih_sas_ir_operation_status_event_debug(struct MPT2SAS_ADAPTER *ioc,
4715 Mpi2EventDataIrOperationStatus_t *event_data)
4717 char *reason_str = NULL;
4719 switch (event_data->RAIDOperation) {
4720 case MPI2_EVENT_IR_RAIDOP_RESYNC:
4721 reason_str = "resync";
4723 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION:
4724 reason_str = "online capacity expansion";
4726 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK:
4727 reason_str = "consistency check";
4730 reason_str = "unknown reason";
4734 printk(MPT2SAS_INFO_FMT "raid operational status: (%s)"
4735 "\thandle(0x%04x), percent complete(%d)\n",
4736 ioc->name, reason_str,
4737 le16_to_cpu(event_data->VolDevHandle),
4738 event_data->PercentComplete);
4743 * _scsih_sas_ir_operation_status_event - handle RAID operation events
4744 * @ioc: per adapter object
4746 * @event_data: event data payload
4752 _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc, u8 VF_ID,
4753 Mpi2EventDataIrOperationStatus_t *event_data)
4755 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4756 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
4757 _scsih_sas_ir_operation_status_event_debug(ioc, event_data);
4762 * _scsih_task_set_full - handle task set full
4763 * @ioc: per adapter object
4764 * @event_data: event data payload
4767 * Throttle back qdepth.
4770 _scsih_task_set_full(struct MPT2SAS_ADAPTER *ioc, u8 VF_ID,
4771 Mpi2EventDataTaskSetFull_t *event_data)
4773 unsigned long flags;
4774 struct _sas_device *sas_device;
4775 static struct _raid_device *raid_device;
4776 struct scsi_device *sdev;
4783 current_depth = le16_to_cpu(event_data->CurrentDepth);
4784 handle = le16_to_cpu(event_data->DevHandle);
4785 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4786 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
4788 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4791 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4792 id = sas_device->id;
4793 channel = sas_device->channel;
4794 sas_address = sas_device->sas_address;
4796 /* if hidden raid component, then change to volume characteristics */
4797 if (sas_device->hidden_raid_component && sas_device->volume_handle) {
4798 spin_lock_irqsave(&ioc->raid_device_lock, flags);
4799 raid_device = _scsih_raid_device_find_by_handle(
4800 ioc, sas_device->volume_handle);
4801 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
4803 id = raid_device->id;
4804 channel = raid_device->channel;
4805 handle = raid_device->handle;
4806 sas_address = raid_device->wwid;
4810 if (ioc->logging_level & MPT_DEBUG_TASK_SET_FULL)
4811 starget_printk(KERN_DEBUG, sas_device->starget, "task set "
4812 "full: handle(0x%04x), sas_addr(0x%016llx), depth(%d)\n",
4813 handle, (unsigned long long)sas_address, current_depth);
4815 shost_for_each_device(sdev, ioc->shost) {
4816 if (sdev->id == id && sdev->channel == channel) {
4817 if (current_depth > sdev->queue_depth) {
4818 if (ioc->logging_level &
4819 MPT_DEBUG_TASK_SET_FULL)
4820 sdev_printk(KERN_INFO, sdev, "strange "
4821 "observation, the queue depth is"
4822 " (%d) meanwhile fw queue depth "
4823 "is (%d)\n", sdev->queue_depth,
4827 depth = scsi_track_queue_full(sdev,
4830 sdev_printk(KERN_INFO, sdev, "Queue depth "
4831 "reduced to (%d)\n", depth);
4833 sdev_printk(KERN_INFO, sdev, "Tagged Command "
4834 "Queueing is being disabled\n");
4835 else if (depth == 0)
4836 if (ioc->logging_level &
4837 MPT_DEBUG_TASK_SET_FULL)
4838 sdev_printk(KERN_INFO, sdev,
4839 "Queue depth not changed yet\n");
4845 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
4846 * @ioc: per adapter object
4847 * @sas_address: sas address
4848 * @slot: enclosure slot id
4849 * @handle: device handle
4851 * After host reset, find out whether devices are still responding.
4852 * Used in _scsi_remove_unresponsive_sas_devices.
4857 _scsih_mark_responding_sas_device(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
4858 u16 slot, u16 handle)
4860 struct MPT2SAS_TARGET *sas_target_priv_data;
4861 struct scsi_target *starget;
4862 struct _sas_device *sas_device;
4863 unsigned long flags;
4865 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4866 list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
4867 if (sas_device->sas_address == sas_address &&
4868 sas_device->slot == slot && sas_device->starget) {
4869 sas_device->responding = 1;
4870 starget_printk(KERN_INFO, sas_device->starget,
4871 "handle(0x%04x), sas_addr(0x%016llx), enclosure "
4872 "logical id(0x%016llx), slot(%d)\n", handle,
4873 (unsigned long long)sas_device->sas_address,
4874 (unsigned long long)
4875 sas_device->enclosure_logical_id,
4877 if (sas_device->handle == handle)
4879 printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n",
4880 sas_device->handle);
4881 sas_device->handle = handle;
4882 starget = sas_device->starget;
4883 sas_target_priv_data = starget->hostdata;
4884 sas_target_priv_data->handle = handle;
4889 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4893 * _scsih_search_responding_sas_devices -
4894 * @ioc: per adapter object
4896 * After host reset, find out whether devices are still responding.
4902 _scsih_search_responding_sas_devices(struct MPT2SAS_ADAPTER *ioc)
4904 Mpi2SasDevicePage0_t sas_device_pg0;
4905 Mpi2ConfigReply_t mpi_reply;
4912 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, __func__);
4914 if (list_empty(&ioc->sas_device_list))
4918 while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
4919 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
4921 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4922 MPI2_IOCSTATUS_MASK;
4923 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
4925 handle = le16_to_cpu(sas_device_pg0.DevHandle);
4926 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
4927 if (!(_scsih_is_end_device(device_info)))
4929 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
4930 slot = le16_to_cpu(sas_device_pg0.Slot);
4931 _scsih_mark_responding_sas_device(ioc, sas_address, slot,
4937 * _scsih_mark_responding_raid_device - mark a raid_device as responding
4938 * @ioc: per adapter object
4939 * @wwid: world wide identifier for raid volume
4940 * @handle: device handle
4942 * After host reset, find out whether devices are still responding.
4943 * Used in _scsi_remove_unresponsive_raid_devices.
4948 _scsih_mark_responding_raid_device(struct MPT2SAS_ADAPTER *ioc, u64 wwid,
4951 struct MPT2SAS_TARGET *sas_target_priv_data;
4952 struct scsi_target *starget;
4953 struct _raid_device *raid_device;
4954 unsigned long flags;
4956 spin_lock_irqsave(&ioc->raid_device_lock, flags);
4957 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
4958 if (raid_device->wwid == wwid && raid_device->starget) {
4959 raid_device->responding = 1;
4960 starget_printk(KERN_INFO, raid_device->starget,
4961 "handle(0x%04x), wwid(0x%016llx)\n", handle,
4962 (unsigned long long)raid_device->wwid);
4963 if (raid_device->handle == handle)
4965 printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n",
4966 raid_device->handle);
4967 raid_device->handle = handle;
4968 starget = raid_device->starget;
4969 sas_target_priv_data = starget->hostdata;
4970 sas_target_priv_data->handle = handle;
4975 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
4979 * _scsih_search_responding_raid_devices -
4980 * @ioc: per adapter object
4982 * After host reset, find out whether devices are still responding.
4988 _scsih_search_responding_raid_devices(struct MPT2SAS_ADAPTER *ioc)
4990 Mpi2RaidVolPage1_t volume_pg1;
4991 Mpi2ConfigReply_t mpi_reply;
4995 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, __func__);
4997 if (list_empty(&ioc->raid_device_list))
5001 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
5002 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
5003 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
5004 MPI2_IOCSTATUS_MASK;
5005 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
5007 handle = le16_to_cpu(volume_pg1.DevHandle);
5008 _scsih_mark_responding_raid_device(ioc,
5009 le64_to_cpu(volume_pg1.WWID), handle);
5014 * _scsih_mark_responding_expander - mark a expander as responding
5015 * @ioc: per adapter object
5016 * @sas_address: sas address
5019 * After host reset, find out whether devices are still responding.
5020 * Used in _scsi_remove_unresponsive_expanders.
5025 _scsih_mark_responding_expander(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
5028 struct _sas_node *sas_expander;
5029 unsigned long flags;
5031 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5032 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
5033 if (sas_expander->sas_address == sas_address) {
5034 sas_expander->responding = 1;
5035 if (sas_expander->handle != handle) {
5036 printk(KERN_INFO "old handle(0x%04x)\n",
5037 sas_expander->handle);
5038 sas_expander->handle = handle;
5044 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5048 * _scsih_search_responding_expanders -
5049 * @ioc: per adapter object
5051 * After host reset, find out whether devices are still responding.
5057 _scsih_search_responding_expanders(struct MPT2SAS_ADAPTER *ioc)
5059 Mpi2ExpanderPage0_t expander_pg0;
5060 Mpi2ConfigReply_t mpi_reply;
5065 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, __func__);
5067 if (list_empty(&ioc->sas_expander_list))
5071 while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
5072 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
5074 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
5075 MPI2_IOCSTATUS_MASK;
5076 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
5079 handle = le16_to_cpu(expander_pg0.DevHandle);
5080 sas_address = le64_to_cpu(expander_pg0.SASAddress);
5081 printk(KERN_INFO "\texpander present: handle(0x%04x), "
5082 "sas_addr(0x%016llx)\n", handle,
5083 (unsigned long long)sas_address);
5084 _scsih_mark_responding_expander(ioc, sas_address, handle);
5090 * _scsih_remove_unresponding_devices - removing unresponding devices
5091 * @ioc: per adapter object
5096 _scsih_remove_unresponding_devices(struct MPT2SAS_ADAPTER *ioc)
5098 struct _sas_device *sas_device, *sas_device_next;
5099 struct _sas_node *sas_expander;
5100 struct _raid_device *raid_device, *raid_device_next;
5103 list_for_each_entry_safe(sas_device, sas_device_next,
5104 &ioc->sas_device_list, list) {
5105 if (sas_device->responding) {
5106 sas_device->responding = 0;
5109 if (sas_device->starget)
5110 starget_printk(KERN_INFO, sas_device->starget,
5111 "removing: handle(0x%04x), sas_addr(0x%016llx), "
5112 "enclosure logical id(0x%016llx), slot(%d)\n",
5114 (unsigned long long)sas_device->sas_address,
5115 (unsigned long long)
5116 sas_device->enclosure_logical_id,
5118 _scsih_remove_device(ioc, sas_device->handle);
5121 list_for_each_entry_safe(raid_device, raid_device_next,
5122 &ioc->raid_device_list, list) {
5123 if (raid_device->responding) {
5124 raid_device->responding = 0;
5127 if (raid_device->starget) {
5128 starget_printk(KERN_INFO, raid_device->starget,
5129 "removing: handle(0x%04x), wwid(0x%016llx)\n",
5130 raid_device->handle,
5131 (unsigned long long)raid_device->wwid);
5132 scsi_remove_target(&raid_device->starget->dev);
5134 _scsih_raid_device_remove(ioc, raid_device);
5137 retry_expander_search:
5138 sas_expander = NULL;
5139 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
5140 if (sas_expander->responding) {
5141 sas_expander->responding = 0;
5144 _scsih_expander_remove(ioc, sas_expander->handle);
5145 goto retry_expander_search;
5150 * mpt2sas_scsih_reset_handler - reset callback handler (for scsih)
5151 * @ioc: per adapter object
5152 * @reset_phase: phase
5154 * The handler for doing any required cleanup or initialization.
5156 * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
5157 * MPT2_IOC_DONE_RESET
5162 mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase)
5164 switch (reset_phase) {
5165 case MPT2_IOC_PRE_RESET:
5166 dtmprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: "
5167 "MPT2_IOC_PRE_RESET\n", ioc->name, __func__));
5168 _scsih_fw_event_off(ioc);
5170 case MPT2_IOC_AFTER_RESET:
5171 dtmprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: "
5172 "MPT2_IOC_AFTER_RESET\n", ioc->name, __func__));
5173 if (ioc->tm_cmds.status & MPT2_CMD_PENDING) {
5174 ioc->tm_cmds.status |= MPT2_CMD_RESET;
5175 mpt2sas_base_free_smid(ioc, ioc->tm_cmds.smid);
5176 complete(&ioc->tm_cmds.done);
5178 _scsih_fw_event_on(ioc);
5179 _scsih_flush_running_cmds(ioc);
5181 case MPT2_IOC_DONE_RESET:
5182 dtmprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: "
5183 "MPT2_IOC_DONE_RESET\n", ioc->name, __func__));
5184 _scsih_sas_host_refresh(ioc, 0);
5185 _scsih_search_responding_sas_devices(ioc);
5186 _scsih_search_responding_raid_devices(ioc);
5187 _scsih_search_responding_expanders(ioc);
5189 case MPT2_IOC_RUNNING:
5190 dtmprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: "
5191 "MPT2_IOC_RUNNING\n", ioc->name, __func__));
5192 _scsih_remove_unresponding_devices(ioc);
5198 * _firmware_event_work - delayed task for processing firmware events
5199 * @ioc: per adapter object
5200 * @work: equal to the fw_event_work object
5206 _firmware_event_work(struct work_struct *work)
5208 struct fw_event_work *fw_event = container_of(work,
5209 struct fw_event_work, work);
5210 unsigned long flags;
5211 struct MPT2SAS_ADAPTER *ioc = fw_event->ioc;
5213 /* the queue is being flushed so ignore this event */
5214 spin_lock_irqsave(&ioc->fw_event_lock, flags);
5215 if (ioc->fw_events_off || ioc->remove_host) {
5216 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
5217 _scsih_fw_event_free(ioc, fw_event);
5220 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
5222 if (ioc->shost_recovery) {
5223 _scsih_fw_event_requeue(ioc, fw_event, 1000);
5227 switch (fw_event->event) {
5228 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
5229 _scsih_sas_topology_change_event(ioc, fw_event->VF_ID,
5230 fw_event->event_data, fw_event);
5232 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
5233 _scsih_sas_device_status_change_event(ioc, fw_event->VF_ID,
5234 fw_event->event_data);
5236 case MPI2_EVENT_SAS_DISCOVERY:
5237 _scsih_sas_discovery_event(ioc, fw_event->VF_ID,
5238 fw_event->event_data);
5240 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
5241 _scsih_sas_broadcast_primative_event(ioc, fw_event->VF_ID,
5242 fw_event->event_data);
5244 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
5245 _scsih_sas_enclosure_dev_status_change_event(ioc,
5246 fw_event->VF_ID, fw_event->event_data);
5248 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
5249 _scsih_sas_ir_config_change_event(ioc, fw_event->VF_ID,
5250 fw_event->event_data);
5252 case MPI2_EVENT_IR_VOLUME:
5253 _scsih_sas_ir_volume_event(ioc, fw_event->VF_ID,
5254 fw_event->event_data);
5256 case MPI2_EVENT_IR_PHYSICAL_DISK:
5257 _scsih_sas_ir_physical_disk_event(ioc, fw_event->VF_ID,
5258 fw_event->event_data);
5260 case MPI2_EVENT_IR_OPERATION_STATUS:
5261 _scsih_sas_ir_operation_status_event(ioc, fw_event->VF_ID,
5262 fw_event->event_data);
5264 case MPI2_EVENT_TASK_SET_FULL:
5265 _scsih_task_set_full(ioc, fw_event->VF_ID,
5266 fw_event->event_data);
5269 _scsih_fw_event_free(ioc, fw_event);
5273 * mpt2sas_scsih_event_callback - firmware event handler (called at ISR time)
5274 * @ioc: per adapter object
5275 * @VF_ID: virtual function id
5276 * @reply: reply message frame(lower 32bit addr)
5277 * Context: interrupt.
5279 * This function merely adds a new work task into ioc->firmware_event_thread.
5280 * The tasks are worked from _firmware_event_work in user context.
5285 mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER *ioc, u8 VF_ID, u32 reply)
5287 struct fw_event_work *fw_event;
5288 Mpi2EventNotificationReply_t *mpi_reply;
5289 unsigned long flags;
5292 /* events turned off due to host reset or driver unloading */
5293 spin_lock_irqsave(&ioc->fw_event_lock, flags);
5294 if (ioc->fw_events_off || ioc->remove_host) {
5295 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
5298 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
5300 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
5301 event = le16_to_cpu(mpi_reply->Event);
5305 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
5307 Mpi2EventDataSasBroadcastPrimitive_t *baen_data =
5308 (Mpi2EventDataSasBroadcastPrimitive_t *)
5309 mpi_reply->EventData;
5311 if (baen_data->Primitive !=
5312 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT ||
5313 ioc->broadcast_aen_busy)
5315 ioc->broadcast_aen_busy = 1;
5319 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
5320 _scsih_check_topo_delete_events(ioc,
5321 (Mpi2EventDataSasTopologyChangeList_t *)
5322 mpi_reply->EventData);
5325 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
5326 case MPI2_EVENT_IR_OPERATION_STATUS:
5327 case MPI2_EVENT_SAS_DISCOVERY:
5328 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
5329 case MPI2_EVENT_IR_VOLUME:
5330 case MPI2_EVENT_IR_PHYSICAL_DISK:
5331 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
5332 case MPI2_EVENT_TASK_SET_FULL:
5335 default: /* ignore the rest */
5339 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
5341 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5342 ioc->name, __FILE__, __LINE__, __func__);
5345 fw_event->event_data =
5346 kzalloc(mpi_reply->EventDataLength*4, GFP_ATOMIC);
5347 if (!fw_event->event_data) {
5348 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5349 ioc->name, __FILE__, __LINE__, __func__);
5354 memcpy(fw_event->event_data, mpi_reply->EventData,
5355 mpi_reply->EventDataLength*4);
5356 fw_event->ioc = ioc;
5357 fw_event->VF_ID = VF_ID;
5358 fw_event->event = event;
5359 _scsih_fw_event_add(ioc, fw_event);
5362 /* shost template */
5363 static struct scsi_host_template scsih_driver_template = {
5364 .module = THIS_MODULE,
5365 .name = "Fusion MPT SAS Host",
5366 .proc_name = MPT2SAS_DRIVER_NAME,
5367 .queuecommand = _scsih_qcmd,
5368 .target_alloc = _scsih_target_alloc,
5369 .slave_alloc = _scsih_slave_alloc,
5370 .slave_configure = _scsih_slave_configure,
5371 .target_destroy = _scsih_target_destroy,
5372 .slave_destroy = _scsih_slave_destroy,
5373 .change_queue_depth = _scsih_change_queue_depth,
5374 .change_queue_type = _scsih_change_queue_type,
5375 .eh_abort_handler = _scsih_abort,
5376 .eh_device_reset_handler = _scsih_dev_reset,
5377 .eh_target_reset_handler = _scsih_target_reset,
5378 .eh_host_reset_handler = _scsih_host_reset,
5379 .bios_param = _scsih_bios_param,
5382 .sg_tablesize = MPT2SAS_SG_DEPTH,
5383 .max_sectors = 8192,
5385 .use_clustering = ENABLE_CLUSTERING,
5386 .shost_attrs = mpt2sas_host_attrs,
5387 .sdev_attrs = mpt2sas_dev_attrs,
5391 * _scsih_expander_node_remove - removing expander device from list.
5392 * @ioc: per adapter object
5393 * @sas_expander: the sas_device object
5394 * Context: Calling function should acquire ioc->sas_node_lock.
5396 * Removing object and freeing associated memory from the
5397 * ioc->sas_expander_list.
5402 _scsih_expander_node_remove(struct MPT2SAS_ADAPTER *ioc,
5403 struct _sas_node *sas_expander)
5405 struct _sas_port *mpt2sas_port;
5406 struct _sas_device *sas_device;
5407 struct _sas_node *expander_sibling;
5408 unsigned long flags;
5413 /* remove sibling ports attached to this expander */
5414 retry_device_search:
5415 list_for_each_entry(mpt2sas_port,
5416 &sas_expander->sas_port_list, port_list) {
5417 if (mpt2sas_port->remote_identify.device_type ==
5419 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5421 mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5422 mpt2sas_port->remote_identify.sas_address);
5423 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5426 _scsih_remove_device(ioc, sas_device->handle);
5427 if (ioc->shost_recovery)
5429 goto retry_device_search;
5433 retry_expander_search:
5434 list_for_each_entry(mpt2sas_port,
5435 &sas_expander->sas_port_list, port_list) {
5437 if (mpt2sas_port->remote_identify.device_type ==
5438 MPI2_SAS_DEVICE_INFO_EDGE_EXPANDER ||
5439 mpt2sas_port->remote_identify.device_type ==
5440 MPI2_SAS_DEVICE_INFO_FANOUT_EXPANDER) {
5442 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5444 mpt2sas_scsih_expander_find_by_sas_address(
5445 ioc, mpt2sas_port->remote_identify.sas_address);
5446 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5447 if (!expander_sibling)
5449 _scsih_expander_remove(ioc, expander_sibling->handle);
5450 if (ioc->shost_recovery)
5452 goto retry_expander_search;
5456 mpt2sas_transport_port_remove(ioc, sas_expander->sas_address,
5457 sas_expander->parent_handle);
5459 printk(MPT2SAS_INFO_FMT "expander_remove: handle"
5460 "(0x%04x), sas_addr(0x%016llx)\n", ioc->name,
5461 sas_expander->handle, (unsigned long long)
5462 sas_expander->sas_address);
5464 list_del(&sas_expander->list);
5465 kfree(sas_expander->phy);
5466 kfree(sas_expander);
5470 * _scsih_remove - detach and remove add host
5471 * @pdev: PCI device struct
5475 static void __devexit
5476 _scsih_remove(struct pci_dev *pdev)
5478 struct Scsi_Host *shost = pci_get_drvdata(pdev);
5479 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
5480 struct _sas_port *mpt2sas_port;
5481 struct _sas_device *sas_device;
5482 struct _sas_node *expander_sibling;
5483 struct workqueue_struct *wq;
5484 unsigned long flags;
5486 ioc->remove_host = 1;
5487 _scsih_fw_event_off(ioc);
5489 spin_lock_irqsave(&ioc->fw_event_lock, flags);
5490 wq = ioc->firmware_event_thread;
5491 ioc->firmware_event_thread = NULL;
5492 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
5494 destroy_workqueue(wq);
5496 /* free ports attached to the sas_host */
5498 list_for_each_entry(mpt2sas_port,
5499 &ioc->sas_hba.sas_port_list, port_list) {
5500 if (mpt2sas_port->remote_identify.device_type ==
5503 mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5504 mpt2sas_port->remote_identify.sas_address);
5506 _scsih_remove_device(ioc, sas_device->handle);
5511 mpt2sas_scsih_expander_find_by_sas_address(ioc,
5512 mpt2sas_port->remote_identify.sas_address);
5513 if (expander_sibling) {
5514 _scsih_expander_remove(ioc,
5515 expander_sibling->handle);
5521 /* free phys attached to the sas_host */
5522 if (ioc->sas_hba.num_phys) {
5523 kfree(ioc->sas_hba.phy);
5524 ioc->sas_hba.phy = NULL;
5525 ioc->sas_hba.num_phys = 0;
5528 sas_remove_host(shost);
5529 mpt2sas_base_detach(ioc);
5530 list_del(&ioc->list);
5531 scsi_remove_host(shost);
5532 scsi_host_put(shost);
5536 * _scsih_probe_boot_devices - reports 1st device
5537 * @ioc: per adapter object
5539 * If specified in bios page 2, this routine reports the 1st
5540 * device scsi-ml or sas transport for persistent boot device
5541 * purposes. Please refer to function _scsih_determine_boot_device()
5544 _scsih_probe_boot_devices(struct MPT2SAS_ADAPTER *ioc)
5548 struct _sas_device *sas_device;
5549 struct _raid_device *raid_device;
5550 u16 handle, parent_handle;
5552 unsigned long flags;
5556 if (ioc->req_boot_device.device) {
5557 device = ioc->req_boot_device.device;
5558 is_raid = ioc->req_boot_device.is_raid;
5559 } else if (ioc->req_alt_boot_device.device) {
5560 device = ioc->req_alt_boot_device.device;
5561 is_raid = ioc->req_alt_boot_device.is_raid;
5562 } else if (ioc->current_boot_device.device) {
5563 device = ioc->current_boot_device.device;
5564 is_raid = ioc->current_boot_device.is_raid;
5571 raid_device = device;
5572 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
5573 raid_device->id, 0);
5575 _scsih_raid_device_remove(ioc, raid_device);
5577 sas_device = device;
5578 handle = sas_device->handle;
5579 parent_handle = sas_device->parent_handle;
5580 sas_address = sas_device->sas_address;
5581 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5582 list_move_tail(&sas_device->list, &ioc->sas_device_list);
5583 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5584 if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
5585 sas_device->parent_handle)) {
5586 _scsih_sas_device_remove(ioc, sas_device);
5587 } else if (!sas_device->starget) {
5588 mpt2sas_transport_port_remove(ioc, sas_address,
5590 _scsih_sas_device_remove(ioc, sas_device);
5596 * _scsih_probe_raid - reporting raid volumes to scsi-ml
5597 * @ioc: per adapter object
5599 * Called during initial loading of the driver.
5602 _scsih_probe_raid(struct MPT2SAS_ADAPTER *ioc)
5604 struct _raid_device *raid_device, *raid_next;
5607 list_for_each_entry_safe(raid_device, raid_next,
5608 &ioc->raid_device_list, list) {
5609 if (raid_device->starget)
5611 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
5612 raid_device->id, 0);
5614 _scsih_raid_device_remove(ioc, raid_device);
5619 * _scsih_probe_sas - reporting raid volumes to sas transport
5620 * @ioc: per adapter object
5622 * Called during initial loading of the driver.
5625 _scsih_probe_sas(struct MPT2SAS_ADAPTER *ioc)
5627 struct _sas_device *sas_device, *next;
5628 unsigned long flags;
5629 u16 handle, parent_handle;
5632 /* SAS Device List */
5633 list_for_each_entry_safe(sas_device, next, &ioc->sas_device_init_list,
5635 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5636 list_move_tail(&sas_device->list, &ioc->sas_device_list);
5637 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5639 handle = sas_device->handle;
5640 parent_handle = sas_device->parent_handle;
5641 sas_address = sas_device->sas_address;
5642 if (!mpt2sas_transport_port_add(ioc, handle, parent_handle)) {
5643 _scsih_sas_device_remove(ioc, sas_device);
5644 } else if (!sas_device->starget) {
5645 mpt2sas_transport_port_remove(ioc, sas_address,
5647 _scsih_sas_device_remove(ioc, sas_device);
5653 * _scsih_probe_devices - probing for devices
5654 * @ioc: per adapter object
5656 * Called during initial loading of the driver.
5659 _scsih_probe_devices(struct MPT2SAS_ADAPTER *ioc)
5661 u16 volume_mapping_flags =
5662 le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) &
5663 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE;
5665 if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR))
5666 return; /* return when IOC doesn't support initiator mode */
5668 _scsih_probe_boot_devices(ioc);
5670 if (ioc->ir_firmware) {
5671 if ((volume_mapping_flags &
5672 MPI2_IOCPAGE8_IRFLAGS_HIGH_VOLUME_MAPPING)) {
5673 _scsih_probe_sas(ioc);
5674 _scsih_probe_raid(ioc);
5676 _scsih_probe_raid(ioc);
5677 _scsih_probe_sas(ioc);
5680 _scsih_probe_sas(ioc);
5684 * _scsih_probe - attach and add scsi host
5685 * @pdev: PCI device struct
5686 * @id: pci device id
5688 * Returns 0 success, anything else error.
5691 _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id)
5693 struct MPT2SAS_ADAPTER *ioc;
5694 struct Scsi_Host *shost;
5696 shost = scsi_host_alloc(&scsih_driver_template,
5697 sizeof(struct MPT2SAS_ADAPTER));
5701 /* init local params */
5702 ioc = shost_priv(shost);
5703 memset(ioc, 0, sizeof(struct MPT2SAS_ADAPTER));
5704 INIT_LIST_HEAD(&ioc->list);
5705 list_add_tail(&ioc->list, &mpt2sas_ioc_list);
5707 ioc->id = mpt_ids++;
5708 sprintf(ioc->name, "%s%d", MPT2SAS_DRIVER_NAME, ioc->id);
5710 ioc->scsi_io_cb_idx = scsi_io_cb_idx;
5711 ioc->tm_cb_idx = tm_cb_idx;
5712 ioc->ctl_cb_idx = ctl_cb_idx;
5713 ioc->base_cb_idx = base_cb_idx;
5714 ioc->transport_cb_idx = transport_cb_idx;
5715 ioc->config_cb_idx = config_cb_idx;
5716 ioc->logging_level = logging_level;
5717 /* misc semaphores and spin locks */
5718 spin_lock_init(&ioc->ioc_reset_in_progress_lock);
5719 spin_lock_init(&ioc->scsi_lookup_lock);
5720 spin_lock_init(&ioc->sas_device_lock);
5721 spin_lock_init(&ioc->sas_node_lock);
5722 spin_lock_init(&ioc->fw_event_lock);
5723 spin_lock_init(&ioc->raid_device_lock);
5725 INIT_LIST_HEAD(&ioc->sas_device_list);
5726 INIT_LIST_HEAD(&ioc->sas_device_init_list);
5727 INIT_LIST_HEAD(&ioc->sas_expander_list);
5728 INIT_LIST_HEAD(&ioc->fw_event_list);
5729 INIT_LIST_HEAD(&ioc->raid_device_list);
5730 INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list);
5732 /* init shost parameters */
5733 shost->max_cmd_len = 16;
5734 shost->max_lun = max_lun;
5735 shost->transportt = mpt2sas_transport_template;
5736 shost->unique_id = ioc->id;
5738 if ((scsi_add_host(shost, &pdev->dev))) {
5739 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5740 ioc->name, __FILE__, __LINE__, __func__);
5741 list_del(&ioc->list);
5742 goto out_add_shost_fail;
5745 scsi_host_set_prot(shost, SHOST_DIF_TYPE1_PROTECTION
5746 | SHOST_DIF_TYPE3_PROTECTION);
5749 snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name),
5750 "fw_event%d", ioc->id);
5751 ioc->firmware_event_thread = create_singlethread_workqueue(
5752 ioc->firmware_event_name);
5753 if (!ioc->firmware_event_thread) {
5754 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5755 ioc->name, __FILE__, __LINE__, __func__);
5756 goto out_thread_fail;
5759 ioc->wait_for_port_enable_to_complete = 1;
5760 if ((mpt2sas_base_attach(ioc))) {
5761 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5762 ioc->name, __FILE__, __LINE__, __func__);
5763 goto out_attach_fail;
5766 ioc->wait_for_port_enable_to_complete = 0;
5767 _scsih_probe_devices(ioc);
5771 destroy_workqueue(ioc->firmware_event_thread);
5773 list_del(&ioc->list);
5774 scsi_remove_host(shost);
5781 * _scsih_suspend - power management suspend main entry point
5782 * @pdev: PCI device struct
5783 * @state: PM state change to (usually PCI_D3)
5785 * Returns 0 success, anything else error.
5788 _scsih_suspend(struct pci_dev *pdev, pm_message_t state)
5790 struct Scsi_Host *shost = pci_get_drvdata(pdev);
5791 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
5794 mpt2sas_base_stop_watchdog(ioc);
5795 flush_scheduled_work();
5796 scsi_block_requests(shost);
5797 device_state = pci_choose_state(pdev, state);
5798 printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, entering "
5799 "operating state [D%d]\n", ioc->name, pdev,
5800 pci_name(pdev), device_state);
5802 mpt2sas_base_free_resources(ioc);
5803 pci_save_state(pdev);
5804 pci_disable_device(pdev);
5805 pci_set_power_state(pdev, device_state);
5810 * _scsih_resume - power management resume main entry point
5811 * @pdev: PCI device struct
5813 * Returns 0 success, anything else error.
5816 _scsih_resume(struct pci_dev *pdev)
5818 struct Scsi_Host *shost = pci_get_drvdata(pdev);
5819 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
5820 u32 device_state = pdev->current_state;
5823 printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, previous "
5824 "operating state [D%d]\n", ioc->name, pdev,
5825 pci_name(pdev), device_state);
5827 pci_set_power_state(pdev, PCI_D0);
5828 pci_enable_wake(pdev, PCI_D0, 0);
5829 pci_restore_state(pdev);
5831 r = mpt2sas_base_map_resources(ioc);
5835 mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, SOFT_RESET);
5836 scsi_unblock_requests(shost);
5837 mpt2sas_base_start_watchdog(ioc);
5840 #endif /* CONFIG_PM */
5843 static struct pci_driver scsih_driver = {
5844 .name = MPT2SAS_DRIVER_NAME,
5845 .id_table = scsih_pci_table,
5846 .probe = _scsih_probe,
5847 .remove = __devexit_p(_scsih_remove),
5849 .suspend = _scsih_suspend,
5850 .resume = _scsih_resume,
5856 * _scsih_init - main entry point for this driver.
5858 * Returns 0 success, anything else error.
5866 printk(KERN_INFO "%s version %s loaded\n", MPT2SAS_DRIVER_NAME,
5867 MPT2SAS_DRIVER_VERSION);
5869 mpt2sas_transport_template =
5870 sas_attach_transport(&mpt2sas_transport_functions);
5871 if (!mpt2sas_transport_template)
5874 mpt2sas_base_initialize_callback_handler();
5876 /* queuecommand callback hander */
5877 scsi_io_cb_idx = mpt2sas_base_register_callback_handler(_scsih_io_done);
5879 /* task managment callback handler */
5880 tm_cb_idx = mpt2sas_base_register_callback_handler(_scsih_tm_done);
5882 /* base internal commands callback handler */
5883 base_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_base_done);
5885 /* transport internal commands callback handler */
5886 transport_cb_idx = mpt2sas_base_register_callback_handler(
5887 mpt2sas_transport_done);
5889 /* configuration page API internal commands callback handler */
5890 config_cb_idx = mpt2sas_base_register_callback_handler(
5891 mpt2sas_config_done);
5893 /* ctl module callback handler */
5894 ctl_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_ctl_done);
5898 error = pci_register_driver(&scsih_driver);
5900 sas_release_transport(mpt2sas_transport_template);
5906 * _scsih_exit - exit point for this driver (when it is a module).
5908 * Returns 0 success, anything else error.
5913 printk(KERN_INFO "mpt2sas version %s unloading\n",
5914 MPT2SAS_DRIVER_VERSION);
5916 pci_unregister_driver(&scsih_driver);
5918 sas_release_transport(mpt2sas_transport_template);
5919 mpt2sas_base_release_callback_handler(scsi_io_cb_idx);
5920 mpt2sas_base_release_callback_handler(tm_cb_idx);
5921 mpt2sas_base_release_callback_handler(base_cb_idx);
5922 mpt2sas_base_release_callback_handler(transport_cb_idx);
5923 mpt2sas_base_release_callback_handler(config_cb_idx);
5924 mpt2sas_base_release_callback_handler(ctl_cb_idx);
5929 module_init(_scsih_init);
5930 module_exit(_scsih_exit);