2 * Scsi Host Layer for MPT (Message Passing Technology) based controllers
4 * This code is based on drivers/scsi/mpt2sas/mpt2_scsih.c
5 * Copyright (C) 2007-2010 LSI Corporation
6 * (mailto:DL-MPTFusionLinux@lsi.com)
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
19 * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
20 * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
21 * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
22 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
23 * solely responsible for determining the appropriateness of using and
24 * distributing the Program and assumes all risks associated with its
25 * exercise of rights under this Agreement, including but not limited to
26 * the risks and costs of program errors, damage to or loss of data,
27 * programs or equipment, and unavailability or interruption of operations.
29 * DISCLAIMER OF LIABILITY
30 * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
31 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
33 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
34 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
35 * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
36 * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
38 * You should have received a copy of the GNU General Public License
39 * along with this program; if not, write to the Free Software
40 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
44 #include <linux/version.h>
45 #include <linux/module.h>
46 #include <linux/kernel.h>
47 #include <linux/init.h>
48 #include <linux/errno.h>
49 #include <linux/blkdev.h>
50 #include <linux/sched.h>
51 #include <linux/workqueue.h>
52 #include <linux/delay.h>
53 #include <linux/pci.h>
54 #include <linux/interrupt.h>
55 #include <linux/aer.h>
56 #include <linux/raid_class.h>
57 #include <linux/slab.h>
59 #include "mpt2sas_base.h"
61 MODULE_AUTHOR(MPT2SAS_AUTHOR
);
62 MODULE_DESCRIPTION(MPT2SAS_DESCRIPTION
);
63 MODULE_LICENSE("GPL");
64 MODULE_VERSION(MPT2SAS_DRIVER_VERSION
);
66 #define RAID_CHANNEL 1
69 static void _scsih_expander_node_remove(struct MPT2SAS_ADAPTER
*ioc
,
70 struct _sas_node
*sas_expander
);
71 static void _firmware_event_work(struct work_struct
*work
);
73 /* global parameters */
74 LIST_HEAD(mpt2sas_ioc_list
);
76 /* local parameters */
77 static u8 scsi_io_cb_idx
= -1;
78 static u8 tm_cb_idx
= -1;
79 static u8 ctl_cb_idx
= -1;
80 static u8 base_cb_idx
= -1;
81 static u8 transport_cb_idx
= -1;
82 static u8 scsih_cb_idx
= -1;
83 static u8 config_cb_idx
= -1;
86 static u8 tm_tr_cb_idx
= -1 ;
87 static u8 tm_sas_control_cb_idx
= -1;
89 /* command line options */
90 static u32 logging_level
;
91 MODULE_PARM_DESC(logging_level
, " bits for enabling additional logging info "
94 /* scsi-mid layer global parmeter is max_report_luns, which is 511 */
95 #define MPT2SAS_MAX_LUN (16895)
96 static int max_lun
= MPT2SAS_MAX_LUN
;
97 module_param(max_lun
, int, 0);
98 MODULE_PARM_DESC(max_lun
, " max lun, default=16895 ");
101 * struct sense_info - common structure for obtaining sense keys
103 * @asc: additional sense code
104 * @ascq: additional sense code qualifier
113 #define MPT2SAS_RESCAN_AFTER_HOST_RESET (0xFFFF)
116 * struct fw_event_work - firmware event struct
117 * @list: link list framework
118 * @work: work object (ioc->fault_reset_work_q)
119 * @cancel_pending_work: flag set during reset handling
120 * @ioc: per adapter object
121 * @VF_ID: virtual function id
122 * @VP_ID: virtual port id
123 * @ignore: flag meaning this event has been marked to ignore
124 * @event: firmware event MPI2_EVENT_XXX defined in mpt2_ioc.h
125 * @event_data: reply event data payload follows
127 * This object stored on ioc->fw_event_list.
129 struct fw_event_work
{
130 struct list_head list
;
131 u8 cancel_pending_work
;
132 struct delayed_work delayed_work
;
133 struct MPT2SAS_ADAPTER
*ioc
;
141 /* raid transport support */
142 static struct raid_template
*mpt2sas_raid_template
;
145 * struct _scsi_io_transfer - scsi io transfer
146 * @handle: sas device handle (assigned by firmware)
147 * @is_raid: flag set for hidden raid components
148 * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE,
149 * @data_length: data transfer length
150 * @data_dma: dma pointer to data
153 * @cdb_length: cdb length
155 * @timeout: timeout for this command
156 * @VF_ID: virtual function id
157 * @VP_ID: virtual port id
158 * @valid_reply: flag set for reply message
159 * @sense_length: sense length
160 * @ioc_status: ioc status
161 * @scsi_state: scsi state
162 * @scsi_status: scsi staus
163 * @log_info: log information
164 * @transfer_length: data length transfer when there is a reply message
166 * Used for sending internal scsi commands to devices within this module.
167 * Refer to _scsi_send_scsi_io().
169 struct _scsi_io_transfer
{
172 enum dma_data_direction dir
;
175 u8 sense
[SCSI_SENSE_BUFFERSIZE
];
183 /* the following bits are only valid when 'valid_reply = 1' */
193 * The pci device ids are defined in mpi/mpi2_cnfg.h.
195 static struct pci_device_id scsih_pci_table
[] = {
196 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2004
,
197 PCI_ANY_ID
, PCI_ANY_ID
},
199 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2008
,
200 PCI_ANY_ID
, PCI_ANY_ID
},
201 /* Liberator ~ 2108 */
202 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_1
,
203 PCI_ANY_ID
, PCI_ANY_ID
},
204 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_2
,
205 PCI_ANY_ID
, PCI_ANY_ID
},
206 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_3
,
207 PCI_ANY_ID
, PCI_ANY_ID
},
209 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2116_1
,
210 PCI_ANY_ID
, PCI_ANY_ID
},
211 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2116_2
,
212 PCI_ANY_ID
, PCI_ANY_ID
},
213 /* Thunderbolt ~ 2208 */
214 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_1
,
215 PCI_ANY_ID
, PCI_ANY_ID
},
216 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_2
,
217 PCI_ANY_ID
, PCI_ANY_ID
},
218 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_3
,
219 PCI_ANY_ID
, PCI_ANY_ID
},
220 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_4
,
221 PCI_ANY_ID
, PCI_ANY_ID
},
222 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_5
,
223 PCI_ANY_ID
, PCI_ANY_ID
},
224 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_6
,
225 PCI_ANY_ID
, PCI_ANY_ID
},
226 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_7
,
227 PCI_ANY_ID
, PCI_ANY_ID
},
228 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_8
,
229 PCI_ANY_ID
, PCI_ANY_ID
},
230 {0} /* Terminating entry */
232 MODULE_DEVICE_TABLE(pci
, scsih_pci_table
);
235 * _scsih_set_debug_level - global setting of ioc->logging_level.
237 * Note: The logging levels are defined in mpt2sas_debug.h.
240 _scsih_set_debug_level(const char *val
, struct kernel_param
*kp
)
242 int ret
= param_set_int(val
, kp
);
243 struct MPT2SAS_ADAPTER
*ioc
;
248 printk(KERN_INFO
"setting logging_level(0x%08x)\n", logging_level
);
249 list_for_each_entry(ioc
, &mpt2sas_ioc_list
, list
)
250 ioc
->logging_level
= logging_level
;
253 module_param_call(logging_level
, _scsih_set_debug_level
, param_get_int
,
254 &logging_level
, 0644);
257 * _scsih_srch_boot_sas_address - search based on sas_address
258 * @sas_address: sas address
259 * @boot_device: boot device object from bios page 2
261 * Returns 1 when there's a match, 0 means no match.
264 _scsih_srch_boot_sas_address(u64 sas_address
,
265 Mpi2BootDeviceSasWwid_t
*boot_device
)
267 return (sas_address
== le64_to_cpu(boot_device
->SASAddress
)) ? 1 : 0;
271 * _scsih_srch_boot_device_name - search based on device name
272 * @device_name: device name specified in INDENTIFY fram
273 * @boot_device: boot device object from bios page 2
275 * Returns 1 when there's a match, 0 means no match.
278 _scsih_srch_boot_device_name(u64 device_name
,
279 Mpi2BootDeviceDeviceName_t
*boot_device
)
281 return (device_name
== le64_to_cpu(boot_device
->DeviceName
)) ? 1 : 0;
285 * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot
286 * @enclosure_logical_id: enclosure logical id
287 * @slot_number: slot number
288 * @boot_device: boot device object from bios page 2
290 * Returns 1 when there's a match, 0 means no match.
293 _scsih_srch_boot_encl_slot(u64 enclosure_logical_id
, u16 slot_number
,
294 Mpi2BootDeviceEnclosureSlot_t
*boot_device
)
296 return (enclosure_logical_id
== le64_to_cpu(boot_device
->
297 EnclosureLogicalID
) && slot_number
== le16_to_cpu(boot_device
->
298 SlotNumber
)) ? 1 : 0;
302 * _scsih_is_boot_device - search for matching boot device.
303 * @sas_address: sas address
304 * @device_name: device name specified in INDENTIFY fram
305 * @enclosure_logical_id: enclosure logical id
306 * @slot_number: slot number
307 * @form: specifies boot device form
308 * @boot_device: boot device object from bios page 2
310 * Returns 1 when there's a match, 0 means no match.
313 _scsih_is_boot_device(u64 sas_address
, u64 device_name
,
314 u64 enclosure_logical_id
, u16 slot
, u8 form
,
315 Mpi2BiosPage2BootDevice_t
*boot_device
)
320 case MPI2_BIOSPAGE2_FORM_SAS_WWID
:
323 rc
= _scsih_srch_boot_sas_address(
324 sas_address
, &boot_device
->SasWwid
);
326 case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT
:
327 if (!enclosure_logical_id
)
329 rc
= _scsih_srch_boot_encl_slot(
330 enclosure_logical_id
,
331 slot
, &boot_device
->EnclosureSlot
);
333 case MPI2_BIOSPAGE2_FORM_DEVICE_NAME
:
336 rc
= _scsih_srch_boot_device_name(
337 device_name
, &boot_device
->DeviceName
);
339 case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED
:
347 * _scsih_get_sas_address - set the sas_address for given device handle
348 * @handle: device handle
349 * @sas_address: sas address
351 * Returns 0 success, non-zero when failure
354 _scsih_get_sas_address(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
,
357 Mpi2SasDevicePage0_t sas_device_pg0
;
358 Mpi2ConfigReply_t mpi_reply
;
361 if (handle
<= ioc
->sas_hba
.num_phys
) {
362 *sas_address
= ioc
->sas_hba
.sas_address
;
367 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
368 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
369 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
370 ioc
->name
, __FILE__
, __LINE__
, __func__
);
374 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
376 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
377 printk(MPT2SAS_ERR_FMT
"handle(0x%04x), ioc_status(0x%04x)"
378 "\nfailure at %s:%d/%s()!\n", ioc
->name
, handle
, ioc_status
,
379 __FILE__
, __LINE__
, __func__
);
383 *sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
388 * _scsih_determine_boot_device - determine boot device.
389 * @ioc: per adapter object
390 * @device: either sas_device or raid_device object
391 * @is_raid: [flag] 1 = raid object, 0 = sas object
393 * Determines whether this device should be first reported device to
394 * to scsi-ml or sas transport, this purpose is for persistant boot device.
395 * There are primary, alternate, and current entries in bios page 2. The order
396 * priority is primary, alternate, then current. This routine saves
397 * the corresponding device object and is_raid flag in the ioc object.
398 * The saved data to be used later in _scsih_probe_boot_devices().
401 _scsih_determine_boot_device(struct MPT2SAS_ADAPTER
*ioc
,
402 void *device
, u8 is_raid
)
404 struct _sas_device
*sas_device
;
405 struct _raid_device
*raid_device
;
408 u64 enclosure_logical_id
;
411 /* only process this function when driver loads */
412 if (!ioc
->wait_for_port_enable_to_complete
)
417 sas_address
= sas_device
->sas_address
;
418 device_name
= sas_device
->device_name
;
419 enclosure_logical_id
= sas_device
->enclosure_logical_id
;
420 slot
= sas_device
->slot
;
422 raid_device
= device
;
423 sas_address
= raid_device
->wwid
;
425 enclosure_logical_id
= 0;
429 if (!ioc
->req_boot_device
.device
) {
430 if (_scsih_is_boot_device(sas_address
, device_name
,
431 enclosure_logical_id
, slot
,
432 (ioc
->bios_pg2
.ReqBootDeviceForm
&
433 MPI2_BIOSPAGE2_FORM_MASK
),
434 &ioc
->bios_pg2
.RequestedBootDevice
)) {
435 dinitprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
436 "%s: req_boot_device(0x%016llx)\n",
438 (unsigned long long)sas_address
));
439 ioc
->req_boot_device
.device
= device
;
440 ioc
->req_boot_device
.is_raid
= is_raid
;
444 if (!ioc
->req_alt_boot_device
.device
) {
445 if (_scsih_is_boot_device(sas_address
, device_name
,
446 enclosure_logical_id
, slot
,
447 (ioc
->bios_pg2
.ReqAltBootDeviceForm
&
448 MPI2_BIOSPAGE2_FORM_MASK
),
449 &ioc
->bios_pg2
.RequestedAltBootDevice
)) {
450 dinitprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
451 "%s: req_alt_boot_device(0x%016llx)\n",
453 (unsigned long long)sas_address
));
454 ioc
->req_alt_boot_device
.device
= device
;
455 ioc
->req_alt_boot_device
.is_raid
= is_raid
;
459 if (!ioc
->current_boot_device
.device
) {
460 if (_scsih_is_boot_device(sas_address
, device_name
,
461 enclosure_logical_id
, slot
,
462 (ioc
->bios_pg2
.CurrentBootDeviceForm
&
463 MPI2_BIOSPAGE2_FORM_MASK
),
464 &ioc
->bios_pg2
.CurrentBootDevice
)) {
465 dinitprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
466 "%s: current_boot_device(0x%016llx)\n",
468 (unsigned long long)sas_address
));
469 ioc
->current_boot_device
.device
= device
;
470 ioc
->current_boot_device
.is_raid
= is_raid
;
476 * mpt2sas_scsih_sas_device_find_by_sas_address - sas device search
477 * @ioc: per adapter object
478 * @sas_address: sas address
479 * Context: Calling function should acquire ioc->sas_device_lock
481 * This searches for sas_device based on sas_address, then return sas_device
485 mpt2sas_scsih_sas_device_find_by_sas_address(struct MPT2SAS_ADAPTER
*ioc
,
488 struct _sas_device
*sas_device
;
490 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
)
491 if (sas_device
->sas_address
== sas_address
)
494 list_for_each_entry(sas_device
, &ioc
->sas_device_init_list
, list
)
495 if (sas_device
->sas_address
== sas_address
)
502 * _scsih_sas_device_find_by_handle - sas device search
503 * @ioc: per adapter object
504 * @handle: sas device handle (assigned by firmware)
505 * Context: Calling function should acquire ioc->sas_device_lock
507 * This searches for sas_device based on sas_address, then return sas_device
510 static struct _sas_device
*
511 _scsih_sas_device_find_by_handle(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
513 struct _sas_device
*sas_device
;
515 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
)
516 if (sas_device
->handle
== handle
)
519 list_for_each_entry(sas_device
, &ioc
->sas_device_init_list
, list
)
520 if (sas_device
->handle
== handle
)
527 * _scsih_sas_device_remove - remove sas_device from list.
528 * @ioc: per adapter object
529 * @sas_device: the sas_device object
530 * Context: This function will acquire ioc->sas_device_lock.
532 * Removing object and freeing associated memory from the ioc->sas_device_list.
535 _scsih_sas_device_remove(struct MPT2SAS_ADAPTER
*ioc
,
536 struct _sas_device
*sas_device
)
543 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
544 if (mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
545 sas_device
->sas_address
)) {
546 list_del(&sas_device
->list
);
549 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
553 * _scsih_sas_device_add - insert sas_device to the list.
554 * @ioc: per adapter object
555 * @sas_device: the sas_device object
556 * Context: This function will acquire ioc->sas_device_lock.
558 * Adding new object to the ioc->sas_device_list.
561 _scsih_sas_device_add(struct MPT2SAS_ADAPTER
*ioc
,
562 struct _sas_device
*sas_device
)
566 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: handle"
567 "(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
, __func__
,
568 sas_device
->handle
, (unsigned long long)sas_device
->sas_address
));
570 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
571 list_add_tail(&sas_device
->list
, &ioc
->sas_device_list
);
572 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
574 if (!mpt2sas_transport_port_add(ioc
, sas_device
->handle
,
575 sas_device
->sas_address_parent
))
576 _scsih_sas_device_remove(ioc
, sas_device
);
580 * _scsih_sas_device_init_add - insert sas_device to the list.
581 * @ioc: per adapter object
582 * @sas_device: the sas_device object
583 * Context: This function will acquire ioc->sas_device_lock.
585 * Adding new object at driver load time to the ioc->sas_device_init_list.
588 _scsih_sas_device_init_add(struct MPT2SAS_ADAPTER
*ioc
,
589 struct _sas_device
*sas_device
)
593 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: handle"
594 "(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
, __func__
,
595 sas_device
->handle
, (unsigned long long)sas_device
->sas_address
));
597 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
598 list_add_tail(&sas_device
->list
, &ioc
->sas_device_init_list
);
599 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
600 _scsih_determine_boot_device(ioc
, sas_device
, 0);
604 * _scsih_raid_device_find_by_id - raid device search
605 * @ioc: per adapter object
606 * @id: sas device target id
607 * @channel: sas device channel
608 * Context: Calling function should acquire ioc->raid_device_lock
610 * This searches for raid_device based on target id, then return raid_device
613 static struct _raid_device
*
614 _scsih_raid_device_find_by_id(struct MPT2SAS_ADAPTER
*ioc
, int id
, int channel
)
616 struct _raid_device
*raid_device
, *r
;
619 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
620 if (raid_device
->id
== id
&& raid_device
->channel
== channel
) {
631 * _scsih_raid_device_find_by_handle - raid device search
632 * @ioc: per adapter object
633 * @handle: sas device handle (assigned by firmware)
634 * Context: Calling function should acquire ioc->raid_device_lock
636 * This searches for raid_device based on handle, then return raid_device
639 static struct _raid_device
*
640 _scsih_raid_device_find_by_handle(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
642 struct _raid_device
*raid_device
, *r
;
645 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
646 if (raid_device
->handle
!= handle
)
657 * _scsih_raid_device_find_by_wwid - raid device search
658 * @ioc: per adapter object
659 * @handle: sas device handle (assigned by firmware)
660 * Context: Calling function should acquire ioc->raid_device_lock
662 * This searches for raid_device based on wwid, then return raid_device
665 static struct _raid_device
*
666 _scsih_raid_device_find_by_wwid(struct MPT2SAS_ADAPTER
*ioc
, u64 wwid
)
668 struct _raid_device
*raid_device
, *r
;
671 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
672 if (raid_device
->wwid
!= wwid
)
683 * _scsih_raid_device_add - add raid_device object
684 * @ioc: per adapter object
685 * @raid_device: raid_device object
687 * This is added to the raid_device_list link list.
690 _scsih_raid_device_add(struct MPT2SAS_ADAPTER
*ioc
,
691 struct _raid_device
*raid_device
)
695 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: handle"
696 "(0x%04x), wwid(0x%016llx)\n", ioc
->name
, __func__
,
697 raid_device
->handle
, (unsigned long long)raid_device
->wwid
));
699 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
700 list_add_tail(&raid_device
->list
, &ioc
->raid_device_list
);
701 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
705 * _scsih_raid_device_remove - delete raid_device object
706 * @ioc: per adapter object
707 * @raid_device: raid_device object
709 * This is removed from the raid_device_list link list.
712 _scsih_raid_device_remove(struct MPT2SAS_ADAPTER
*ioc
,
713 struct _raid_device
*raid_device
)
717 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
718 list_del(&raid_device
->list
);
719 memset(raid_device
, 0, sizeof(struct _raid_device
));
721 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
725 * mpt2sas_scsih_expander_find_by_handle - expander device search
726 * @ioc: per adapter object
727 * @handle: expander handle (assigned by firmware)
728 * Context: Calling function should acquire ioc->sas_device_lock
730 * This searches for expander device based on handle, then returns the
734 mpt2sas_scsih_expander_find_by_handle(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
736 struct _sas_node
*sas_expander
, *r
;
739 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
740 if (sas_expander
->handle
!= handle
)
750 * mpt2sas_scsih_expander_find_by_sas_address - expander device search
751 * @ioc: per adapter object
752 * @sas_address: sas address
753 * Context: Calling function should acquire ioc->sas_node_lock.
755 * This searches for expander device based on sas_address, then returns the
759 mpt2sas_scsih_expander_find_by_sas_address(struct MPT2SAS_ADAPTER
*ioc
,
762 struct _sas_node
*sas_expander
, *r
;
765 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
766 if (sas_expander
->sas_address
!= sas_address
)
776 * _scsih_expander_node_add - insert expander device to the list.
777 * @ioc: per adapter object
778 * @sas_expander: the sas_device object
779 * Context: This function will acquire ioc->sas_node_lock.
781 * Adding new object to the ioc->sas_expander_list.
786 _scsih_expander_node_add(struct MPT2SAS_ADAPTER
*ioc
,
787 struct _sas_node
*sas_expander
)
791 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
792 list_add_tail(&sas_expander
->list
, &ioc
->sas_expander_list
);
793 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
797 * _scsih_is_end_device - determines if device is an end device
798 * @device_info: bitfield providing information about the device.
801 * Returns 1 if end device.
804 _scsih_is_end_device(u32 device_info
)
806 if (device_info
& MPI2_SAS_DEVICE_INFO_END_DEVICE
&&
807 ((device_info
& MPI2_SAS_DEVICE_INFO_SSP_TARGET
) |
808 (device_info
& MPI2_SAS_DEVICE_INFO_STP_TARGET
) |
809 (device_info
& MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)))
816 * mptscsih_get_scsi_lookup - returns scmd entry
817 * @ioc: per adapter object
818 * @smid: system request message index
820 * Returns the smid stored scmd pointer.
822 static struct scsi_cmnd
*
823 _scsih_scsi_lookup_get(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
825 return ioc
->scsi_lookup
[smid
- 1].scmd
;
829 * _scsih_scsi_lookup_find_by_scmd - scmd lookup
830 * @ioc: per adapter object
831 * @smid: system request message index
832 * @scmd: pointer to scsi command object
833 * Context: This function will acquire ioc->scsi_lookup_lock.
835 * This will search for a scmd pointer in the scsi_lookup array,
836 * returning the revelent smid. A returned value of zero means invalid.
839 _scsih_scsi_lookup_find_by_scmd(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_cmnd
846 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
848 for (i
= 0; i
< ioc
->scsiio_depth
; i
++) {
849 if (ioc
->scsi_lookup
[i
].scmd
== scmd
) {
850 smid
= ioc
->scsi_lookup
[i
].smid
;
855 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
860 * _scsih_scsi_lookup_find_by_target - search for matching channel:id
861 * @ioc: per adapter object
864 * Context: This function will acquire ioc->scsi_lookup_lock.
866 * This will search for a matching channel:id in the scsi_lookup array,
867 * returning 1 if found.
870 _scsih_scsi_lookup_find_by_target(struct MPT2SAS_ADAPTER
*ioc
, int id
,
877 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
879 for (i
= 0 ; i
< ioc
->scsiio_depth
; i
++) {
880 if (ioc
->scsi_lookup
[i
].scmd
&&
881 (ioc
->scsi_lookup
[i
].scmd
->device
->id
== id
&&
882 ioc
->scsi_lookup
[i
].scmd
->device
->channel
== channel
)) {
888 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
893 * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun
894 * @ioc: per adapter object
898 * Context: This function will acquire ioc->scsi_lookup_lock.
900 * This will search for a matching channel:id:lun in the scsi_lookup array,
901 * returning 1 if found.
904 _scsih_scsi_lookup_find_by_lun(struct MPT2SAS_ADAPTER
*ioc
, int id
,
905 unsigned int lun
, int channel
)
911 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
913 for (i
= 0 ; i
< ioc
->scsiio_depth
; i
++) {
914 if (ioc
->scsi_lookup
[i
].scmd
&&
915 (ioc
->scsi_lookup
[i
].scmd
->device
->id
== id
&&
916 ioc
->scsi_lookup
[i
].scmd
->device
->channel
== channel
&&
917 ioc
->scsi_lookup
[i
].scmd
->device
->lun
== lun
)) {
923 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
928 * _scsih_get_chain_buffer_dma - obtain block of chains (dma address)
929 * @ioc: per adapter object
930 * @smid: system request message index
932 * Returns phys pointer to chain buffer.
935 _scsih_get_chain_buffer_dma(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
937 return ioc
->chain_dma
+ ((smid
- 1) * (ioc
->request_sz
*
938 ioc
->chains_needed_per_io
));
942 * _scsih_get_chain_buffer - obtain block of chains assigned to a mf request
943 * @ioc: per adapter object
944 * @smid: system request message index
946 * Returns virt pointer to chain buffer.
949 _scsih_get_chain_buffer(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
951 return (void *)(ioc
->chain
+ ((smid
- 1) * (ioc
->request_sz
*
952 ioc
->chains_needed_per_io
)));
956 * _scsih_build_scatter_gather - main sg creation routine
957 * @ioc: per adapter object
958 * @scmd: scsi command
959 * @smid: system request message index
962 * The main routine that builds scatter gather table from a given
963 * scsi request sent via the .queuecommand main handler.
965 * Returns 0 success, anything else error
968 _scsih_build_scatter_gather(struct MPT2SAS_ADAPTER
*ioc
,
969 struct scsi_cmnd
*scmd
, u16 smid
)
971 Mpi2SCSIIORequest_t
*mpi_request
;
972 dma_addr_t chain_dma
;
973 struct scatterlist
*sg_scmd
;
974 void *sg_local
, *chain
;
981 u32 sgl_flags_last_element
;
982 u32 sgl_flags_end_buffer
;
984 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
986 /* init scatter gather flags */
987 sgl_flags
= MPI2_SGE_FLAGS_SIMPLE_ELEMENT
;
988 if (scmd
->sc_data_direction
== DMA_TO_DEVICE
)
989 sgl_flags
|= MPI2_SGE_FLAGS_HOST_TO_IOC
;
990 sgl_flags_last_element
= (sgl_flags
| MPI2_SGE_FLAGS_LAST_ELEMENT
)
991 << MPI2_SGE_FLAGS_SHIFT
;
992 sgl_flags_end_buffer
= (sgl_flags
| MPI2_SGE_FLAGS_LAST_ELEMENT
|
993 MPI2_SGE_FLAGS_END_OF_BUFFER
| MPI2_SGE_FLAGS_END_OF_LIST
)
994 << MPI2_SGE_FLAGS_SHIFT
;
995 sgl_flags
= sgl_flags
<< MPI2_SGE_FLAGS_SHIFT
;
997 sg_scmd
= scsi_sglist(scmd
);
998 sges_left
= scsi_dma_map(scmd
);
1000 sdev_printk(KERN_ERR
, scmd
->device
, "pci_map_sg"
1001 " failed: request for %d bytes!\n", scsi_bufflen(scmd
));
1005 sg_local
= &mpi_request
->SGL
;
1006 sges_in_segment
= ioc
->max_sges_in_main_message
;
1007 if (sges_left
<= sges_in_segment
)
1008 goto fill_in_last_segment
;
1010 mpi_request
->ChainOffset
= (offsetof(Mpi2SCSIIORequest_t
, SGL
) +
1011 (sges_in_segment
* ioc
->sge_size
))/4;
1013 /* fill in main message segment when there is a chain following */
1014 while (sges_in_segment
) {
1015 if (sges_in_segment
== 1)
1016 ioc
->base_add_sg_single(sg_local
,
1017 sgl_flags_last_element
| sg_dma_len(sg_scmd
),
1018 sg_dma_address(sg_scmd
));
1020 ioc
->base_add_sg_single(sg_local
, sgl_flags
|
1021 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
1022 sg_scmd
= sg_next(sg_scmd
);
1023 sg_local
+= ioc
->sge_size
;
1028 /* initializing the chain flags and pointers */
1029 chain_flags
= MPI2_SGE_FLAGS_CHAIN_ELEMENT
<< MPI2_SGE_FLAGS_SHIFT
;
1030 chain
= _scsih_get_chain_buffer(ioc
, smid
);
1031 chain_dma
= _scsih_get_chain_buffer_dma(ioc
, smid
);
1033 sges_in_segment
= (sges_left
<=
1034 ioc
->max_sges_in_chain_message
) ? sges_left
:
1035 ioc
->max_sges_in_chain_message
;
1036 chain_offset
= (sges_left
== sges_in_segment
) ?
1037 0 : (sges_in_segment
* ioc
->sge_size
)/4;
1038 chain_length
= sges_in_segment
* ioc
->sge_size
;
1040 chain_offset
= chain_offset
<<
1041 MPI2_SGE_CHAIN_OFFSET_SHIFT
;
1042 chain_length
+= ioc
->sge_size
;
1044 ioc
->base_add_sg_single(sg_local
, chain_flags
| chain_offset
|
1045 chain_length
, chain_dma
);
1048 goto fill_in_last_segment
;
1050 /* fill in chain segments */
1051 while (sges_in_segment
) {
1052 if (sges_in_segment
== 1)
1053 ioc
->base_add_sg_single(sg_local
,
1054 sgl_flags_last_element
|
1055 sg_dma_len(sg_scmd
),
1056 sg_dma_address(sg_scmd
));
1058 ioc
->base_add_sg_single(sg_local
, sgl_flags
|
1059 sg_dma_len(sg_scmd
),
1060 sg_dma_address(sg_scmd
));
1061 sg_scmd
= sg_next(sg_scmd
);
1062 sg_local
+= ioc
->sge_size
;
1067 chain_dma
+= ioc
->request_sz
;
1068 chain
+= ioc
->request_sz
;
1072 fill_in_last_segment
:
1074 /* fill the last segment */
1077 ioc
->base_add_sg_single(sg_local
, sgl_flags_end_buffer
|
1078 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
1080 ioc
->base_add_sg_single(sg_local
, sgl_flags
|
1081 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
1082 sg_scmd
= sg_next(sg_scmd
);
1083 sg_local
+= ioc
->sge_size
;
1091 * _scsih_change_queue_depth - setting device queue depth
1092 * @sdev: scsi device struct
1093 * @qdepth: requested queue depth
1094 * @reason: calling context
1096 * Returns queue depth.
1099 _scsih_change_queue_depth(struct scsi_device
*sdev
, int qdepth
, int reason
)
1101 struct Scsi_Host
*shost
= sdev
->host
;
1104 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1105 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1106 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1107 struct _sas_device
*sas_device
;
1108 unsigned long flags
;
1110 if (reason
!= SCSI_QDEPTH_DEFAULT
)
1113 max_depth
= shost
->can_queue
;
1115 /* limit max device queue for SATA to 32 */
1116 sas_device_priv_data
= sdev
->hostdata
;
1117 if (!sas_device_priv_data
)
1119 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
1120 if (!sas_target_priv_data
)
1122 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
))
1124 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1125 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1126 sas_device_priv_data
->sas_target
->sas_address
);
1127 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1128 if (sas_device
&& sas_device
->device_info
&
1129 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1130 max_depth
= MPT2SAS_SATA_QUEUE_DEPTH
;
1134 if (!sdev
->tagged_supported
)
1136 if (qdepth
> max_depth
)
1138 tag_type
= (qdepth
== 1) ? 0 : MSG_SIMPLE_TAG
;
1139 scsi_adjust_queue_depth(sdev
, tag_type
, qdepth
);
1141 if (sdev
->inquiry_len
> 7)
1142 sdev_printk(KERN_INFO
, sdev
, "qdepth(%d), tagged(%d), "
1143 "simple(%d), ordered(%d), scsi_level(%d), cmd_que(%d)\n",
1144 sdev
->queue_depth
, sdev
->tagged_supported
, sdev
->simple_tags
,
1145 sdev
->ordered_tags
, sdev
->scsi_level
,
1146 (sdev
->inquiry
[7] & 2) >> 1);
1148 return sdev
->queue_depth
;
1152 * _scsih_change_queue_type - changing device queue tag type
1153 * @sdev: scsi device struct
1154 * @tag_type: requested tag type
1156 * Returns queue tag type.
1159 _scsih_change_queue_type(struct scsi_device
*sdev
, int tag_type
)
1161 if (sdev
->tagged_supported
) {
1162 scsi_set_tag_type(sdev
, tag_type
);
1164 scsi_activate_tcq(sdev
, sdev
->queue_depth
);
1166 scsi_deactivate_tcq(sdev
, sdev
->queue_depth
);
1174 * _scsih_target_alloc - target add routine
1175 * @starget: scsi target struct
1177 * Returns 0 if ok. Any other return is assumed to be an error and
1178 * the device is ignored.
1181 _scsih_target_alloc(struct scsi_target
*starget
)
1183 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
1184 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1185 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1186 struct _sas_device
*sas_device
;
1187 struct _raid_device
*raid_device
;
1188 unsigned long flags
;
1189 struct sas_rphy
*rphy
;
1191 sas_target_priv_data
= kzalloc(sizeof(struct scsi_target
), GFP_KERNEL
);
1192 if (!sas_target_priv_data
)
1195 starget
->hostdata
= sas_target_priv_data
;
1196 sas_target_priv_data
->starget
= starget
;
1197 sas_target_priv_data
->handle
= MPT2SAS_INVALID_DEVICE_HANDLE
;
1200 if (starget
->channel
== RAID_CHANNEL
) {
1201 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1202 raid_device
= _scsih_raid_device_find_by_id(ioc
, starget
->id
,
1205 sas_target_priv_data
->handle
= raid_device
->handle
;
1206 sas_target_priv_data
->sas_address
= raid_device
->wwid
;
1207 sas_target_priv_data
->flags
|= MPT_TARGET_FLAGS_VOLUME
;
1208 raid_device
->starget
= starget
;
1210 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1214 /* sas/sata devices */
1215 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1216 rphy
= dev_to_rphy(starget
->dev
.parent
);
1217 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1218 rphy
->identify
.sas_address
);
1221 sas_target_priv_data
->handle
= sas_device
->handle
;
1222 sas_target_priv_data
->sas_address
= sas_device
->sas_address
;
1223 sas_device
->starget
= starget
;
1224 sas_device
->id
= starget
->id
;
1225 sas_device
->channel
= starget
->channel
;
1226 if (sas_device
->hidden_raid_component
)
1227 sas_target_priv_data
->flags
|=
1228 MPT_TARGET_FLAGS_RAID_COMPONENT
;
1230 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1236 * _scsih_target_destroy - target destroy routine
1237 * @starget: scsi target struct
1242 _scsih_target_destroy(struct scsi_target
*starget
)
1244 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
1245 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1246 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1247 struct _sas_device
*sas_device
;
1248 struct _raid_device
*raid_device
;
1249 unsigned long flags
;
1250 struct sas_rphy
*rphy
;
1252 sas_target_priv_data
= starget
->hostdata
;
1253 if (!sas_target_priv_data
)
1256 if (starget
->channel
== RAID_CHANNEL
) {
1257 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1258 raid_device
= _scsih_raid_device_find_by_id(ioc
, starget
->id
,
1261 raid_device
->starget
= NULL
;
1262 raid_device
->sdev
= NULL
;
1264 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1268 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1269 rphy
= dev_to_rphy(starget
->dev
.parent
);
1270 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1271 rphy
->identify
.sas_address
);
1272 if (sas_device
&& (sas_device
->starget
== starget
) &&
1273 (sas_device
->id
== starget
->id
) &&
1274 (sas_device
->channel
== starget
->channel
))
1275 sas_device
->starget
= NULL
;
1277 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1280 kfree(sas_target_priv_data
);
1281 starget
->hostdata
= NULL
;
1285 * _scsih_slave_alloc - device add routine
1286 * @sdev: scsi device struct
1288 * Returns 0 if ok. Any other return is assumed to be an error and
1289 * the device is ignored.
1292 _scsih_slave_alloc(struct scsi_device
*sdev
)
1294 struct Scsi_Host
*shost
;
1295 struct MPT2SAS_ADAPTER
*ioc
;
1296 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1297 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1298 struct scsi_target
*starget
;
1299 struct _raid_device
*raid_device
;
1300 unsigned long flags
;
1302 sas_device_priv_data
= kzalloc(sizeof(struct scsi_device
), GFP_KERNEL
);
1303 if (!sas_device_priv_data
)
1306 sas_device_priv_data
->lun
= sdev
->lun
;
1307 sas_device_priv_data
->flags
= MPT_DEVICE_FLAGS_INIT
;
1309 starget
= scsi_target(sdev
);
1310 sas_target_priv_data
= starget
->hostdata
;
1311 sas_target_priv_data
->num_luns
++;
1312 sas_device_priv_data
->sas_target
= sas_target_priv_data
;
1313 sdev
->hostdata
= sas_device_priv_data
;
1314 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
))
1315 sdev
->no_uld_attach
= 1;
1317 shost
= dev_to_shost(&starget
->dev
);
1318 ioc
= shost_priv(shost
);
1319 if (starget
->channel
== RAID_CHANNEL
) {
1320 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1321 raid_device
= _scsih_raid_device_find_by_id(ioc
,
1322 starget
->id
, starget
->channel
);
1324 raid_device
->sdev
= sdev
; /* raid is single lun */
1325 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1332 * _scsih_slave_destroy - device destroy routine
1333 * @sdev: scsi device struct
1338 _scsih_slave_destroy(struct scsi_device
*sdev
)
1340 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1341 struct scsi_target
*starget
;
1343 if (!sdev
->hostdata
)
1346 starget
= scsi_target(sdev
);
1347 sas_target_priv_data
= starget
->hostdata
;
1348 sas_target_priv_data
->num_luns
--;
1349 kfree(sdev
->hostdata
);
1350 sdev
->hostdata
= NULL
;
1354 * _scsih_display_sata_capabilities - sata capabilities
1355 * @ioc: per adapter object
1356 * @sas_device: the sas_device object
1357 * @sdev: scsi device struct
1360 _scsih_display_sata_capabilities(struct MPT2SAS_ADAPTER
*ioc
,
1361 struct _sas_device
*sas_device
, struct scsi_device
*sdev
)
1363 Mpi2ConfigReply_t mpi_reply
;
1364 Mpi2SasDevicePage0_t sas_device_pg0
;
1369 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
1370 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, sas_device
->handle
))) {
1371 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1372 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1376 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
1377 MPI2_IOCSTATUS_MASK
;
1378 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
1379 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1380 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1384 flags
= le16_to_cpu(sas_device_pg0
.Flags
);
1385 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
1387 sdev_printk(KERN_INFO
, sdev
,
1388 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1389 "sw_preserve(%s)\n",
1390 (device_info
& MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE
) ? "y" : "n",
1391 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED
) ? "y" : "n",
1392 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY
) ? "y" :
1394 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED
) ? "y" : "n",
1395 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED
) ? "y" : "n",
1396 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE
) ? "y" : "n");
1400 * _scsih_is_raid - return boolean indicating device is raid volume
1401 * @dev the device struct object
1404 _scsih_is_raid(struct device
*dev
)
1406 struct scsi_device
*sdev
= to_scsi_device(dev
);
1408 return (sdev
->channel
== RAID_CHANNEL
) ? 1 : 0;
1412 * _scsih_get_resync - get raid volume resync percent complete
1413 * @dev the device struct object
1416 _scsih_get_resync(struct device
*dev
)
1418 struct scsi_device
*sdev
= to_scsi_device(dev
);
1419 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
1420 static struct _raid_device
*raid_device
;
1421 unsigned long flags
;
1422 Mpi2RaidVolPage0_t vol_pg0
;
1423 Mpi2ConfigReply_t mpi_reply
;
1424 u32 volume_status_flags
;
1425 u8 percent_complete
= 0;
1427 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1428 raid_device
= _scsih_raid_device_find_by_id(ioc
, sdev
->id
,
1430 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1435 if (mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, &vol_pg0
,
1436 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, raid_device
->handle
,
1437 sizeof(Mpi2RaidVolPage0_t
))) {
1438 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1439 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1443 volume_status_flags
= le32_to_cpu(vol_pg0
.VolumeStatusFlags
);
1444 if (volume_status_flags
& MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS
)
1445 percent_complete
= raid_device
->percent_complete
;
1447 raid_set_resync(mpt2sas_raid_template
, dev
, percent_complete
);
1451 * _scsih_get_state - get raid volume level
1452 * @dev the device struct object
1455 _scsih_get_state(struct device
*dev
)
1457 struct scsi_device
*sdev
= to_scsi_device(dev
);
1458 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
1459 static struct _raid_device
*raid_device
;
1460 unsigned long flags
;
1461 Mpi2RaidVolPage0_t vol_pg0
;
1462 Mpi2ConfigReply_t mpi_reply
;
1464 enum raid_state state
= RAID_STATE_UNKNOWN
;
1466 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1467 raid_device
= _scsih_raid_device_find_by_id(ioc
, sdev
->id
,
1469 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1474 if (mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, &vol_pg0
,
1475 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, raid_device
->handle
,
1476 sizeof(Mpi2RaidVolPage0_t
))) {
1477 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1478 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1482 volstate
= le32_to_cpu(vol_pg0
.VolumeStatusFlags
);
1483 if (volstate
& MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS
) {
1484 state
= RAID_STATE_RESYNCING
;
1488 switch (vol_pg0
.VolumeState
) {
1489 case MPI2_RAID_VOL_STATE_OPTIMAL
:
1490 case MPI2_RAID_VOL_STATE_ONLINE
:
1491 state
= RAID_STATE_ACTIVE
;
1493 case MPI2_RAID_VOL_STATE_DEGRADED
:
1494 state
= RAID_STATE_DEGRADED
;
1496 case MPI2_RAID_VOL_STATE_FAILED
:
1497 case MPI2_RAID_VOL_STATE_MISSING
:
1498 state
= RAID_STATE_OFFLINE
;
1502 raid_set_state(mpt2sas_raid_template
, dev
, state
);
1506 * _scsih_set_level - set raid level
1507 * @sdev: scsi device struct
1508 * @raid_device: raid_device object
1511 _scsih_set_level(struct scsi_device
*sdev
, struct _raid_device
*raid_device
)
1513 enum raid_level level
= RAID_LEVEL_UNKNOWN
;
1515 switch (raid_device
->volume_type
) {
1516 case MPI2_RAID_VOL_TYPE_RAID0
:
1517 level
= RAID_LEVEL_0
;
1519 case MPI2_RAID_VOL_TYPE_RAID10
:
1520 level
= RAID_LEVEL_10
;
1522 case MPI2_RAID_VOL_TYPE_RAID1E
:
1523 level
= RAID_LEVEL_1E
;
1525 case MPI2_RAID_VOL_TYPE_RAID1
:
1526 level
= RAID_LEVEL_1
;
1530 raid_set_level(mpt2sas_raid_template
, &sdev
->sdev_gendev
, level
);
1534 * _scsih_get_volume_capabilities - volume capabilities
1535 * @ioc: per adapter object
1536 * @sas_device: the raid_device object
1539 _scsih_get_volume_capabilities(struct MPT2SAS_ADAPTER
*ioc
,
1540 struct _raid_device
*raid_device
)
1542 Mpi2RaidVolPage0_t
*vol_pg0
;
1543 Mpi2RaidPhysDiskPage0_t pd_pg0
;
1544 Mpi2SasDevicePage0_t sas_device_pg0
;
1545 Mpi2ConfigReply_t mpi_reply
;
1549 if ((mpt2sas_config_get_number_pds(ioc
, raid_device
->handle
,
1550 &num_pds
)) || !num_pds
) {
1551 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1552 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1556 raid_device
->num_pds
= num_pds
;
1557 sz
= offsetof(Mpi2RaidVolPage0_t
, PhysDisk
) + (num_pds
*
1558 sizeof(Mpi2RaidVol0PhysDisk_t
));
1559 vol_pg0
= kzalloc(sz
, GFP_KERNEL
);
1561 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1562 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1566 if ((mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, vol_pg0
,
1567 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, raid_device
->handle
, sz
))) {
1568 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1569 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1574 raid_device
->volume_type
= vol_pg0
->VolumeType
;
1576 /* figure out what the underlying devices are by
1577 * obtaining the device_info bits for the 1st device
1579 if (!(mpt2sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
1580 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM
,
1581 vol_pg0
->PhysDisk
[0].PhysDiskNum
))) {
1582 if (!(mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
1583 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
1584 le16_to_cpu(pd_pg0
.DevHandle
)))) {
1585 raid_device
->device_info
=
1586 le32_to_cpu(sas_device_pg0
.DeviceInfo
);
1594 * _scsih_enable_tlr - setting TLR flags
1595 * @ioc: per adapter object
1596 * @sdev: scsi device struct
1598 * Enabling Transaction Layer Retries for tape devices when
1599 * vpd page 0x90 is present
1603 _scsih_enable_tlr(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_device
*sdev
)
1606 if (sdev
->type
!= TYPE_TAPE
)
1609 if (!(ioc
->facts
.IOCCapabilities
& MPI2_IOCFACTS_CAPABILITY_TLR
))
1612 sas_enable_tlr(sdev
);
1613 sdev_printk(KERN_INFO
, sdev
, "TLR %s\n",
1614 sas_is_tlr_enabled(sdev
) ? "Enabled" : "Disabled");
1620 * _scsih_slave_configure - device configure routine.
1621 * @sdev: scsi device struct
1623 * Returns 0 if ok. Any other return is assumed to be an error and
1624 * the device is ignored.
1627 _scsih_slave_configure(struct scsi_device
*sdev
)
1629 struct Scsi_Host
*shost
= sdev
->host
;
1630 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1631 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1632 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1633 struct _sas_device
*sas_device
;
1634 struct _raid_device
*raid_device
;
1635 unsigned long flags
;
1642 sas_device_priv_data
= sdev
->hostdata
;
1643 sas_device_priv_data
->configured_lun
= 1;
1644 sas_device_priv_data
->flags
&= ~MPT_DEVICE_FLAGS_INIT
;
1645 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
1647 /* raid volume handling */
1648 if (sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
1650 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1651 raid_device
= _scsih_raid_device_find_by_handle(ioc
,
1652 sas_target_priv_data
->handle
);
1653 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1655 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1656 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1660 _scsih_get_volume_capabilities(ioc
, raid_device
);
1662 /* RAID Queue Depth Support
1663 * IS volume = underlying qdepth of drive type, either
1664 * MPT2SAS_SAS_QUEUE_DEPTH or MPT2SAS_SATA_QUEUE_DEPTH
1665 * IM/IME/R10 = 128 (MPT2SAS_RAID_QUEUE_DEPTH)
1667 if (raid_device
->device_info
&
1668 MPI2_SAS_DEVICE_INFO_SSP_TARGET
) {
1669 qdepth
= MPT2SAS_SAS_QUEUE_DEPTH
;
1672 qdepth
= MPT2SAS_SATA_QUEUE_DEPTH
;
1673 if (raid_device
->device_info
&
1674 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1680 switch (raid_device
->volume_type
) {
1681 case MPI2_RAID_VOL_TYPE_RAID0
:
1684 case MPI2_RAID_VOL_TYPE_RAID1E
:
1685 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
1686 if (ioc
->manu_pg10
.OEMIdentifier
&&
1687 (ioc
->manu_pg10
.GenericFlags0
&
1688 MFG10_GF0_R10_DISPLAY
) &&
1689 !(raid_device
->num_pds
% 2))
1694 case MPI2_RAID_VOL_TYPE_RAID1
:
1695 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
1698 case MPI2_RAID_VOL_TYPE_RAID10
:
1699 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
1702 case MPI2_RAID_VOL_TYPE_UNKNOWN
:
1704 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
1709 sdev_printk(KERN_INFO
, sdev
, "%s: "
1710 "handle(0x%04x), wwid(0x%016llx), pd_count(%d), type(%s)\n",
1711 r_level
, raid_device
->handle
,
1712 (unsigned long long)raid_device
->wwid
,
1713 raid_device
->num_pds
, ds
);
1714 _scsih_change_queue_depth(sdev
, qdepth
, SCSI_QDEPTH_DEFAULT
);
1715 /* raid transport support */
1716 _scsih_set_level(sdev
, raid_device
);
1720 /* non-raid handling */
1721 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1722 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1723 sas_device_priv_data
->sas_target
->sas_address
);
1724 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1726 if (sas_target_priv_data
->flags
&
1727 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
1728 mpt2sas_config_get_volume_handle(ioc
,
1729 sas_device
->handle
, &sas_device
->volume_handle
);
1730 mpt2sas_config_get_volume_wwid(ioc
,
1731 sas_device
->volume_handle
,
1732 &sas_device
->volume_wwid
);
1734 if (sas_device
->device_info
& MPI2_SAS_DEVICE_INFO_SSP_TARGET
) {
1735 qdepth
= MPT2SAS_SAS_QUEUE_DEPTH
;
1739 qdepth
= MPT2SAS_SATA_QUEUE_DEPTH
;
1740 if (sas_device
->device_info
&
1741 MPI2_SAS_DEVICE_INFO_STP_TARGET
)
1743 else if (sas_device
->device_info
&
1744 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1748 sdev_printk(KERN_INFO
, sdev
, "%s: handle(0x%04x), "
1749 "sas_addr(0x%016llx), device_name(0x%016llx)\n",
1750 ds
, sas_device
->handle
,
1751 (unsigned long long)sas_device
->sas_address
,
1752 (unsigned long long)sas_device
->device_name
);
1753 sdev_printk(KERN_INFO
, sdev
, "%s: "
1754 "enclosure_logical_id(0x%016llx), slot(%d)\n", ds
,
1755 (unsigned long long) sas_device
->enclosure_logical_id
,
1759 _scsih_display_sata_capabilities(ioc
, sas_device
, sdev
);
1762 _scsih_change_queue_depth(sdev
, qdepth
, SCSI_QDEPTH_DEFAULT
);
1765 sas_read_port_mode_page(sdev
);
1766 _scsih_enable_tlr(ioc
, sdev
);
1772 * _scsih_bios_param - fetch head, sector, cylinder info for a disk
1773 * @sdev: scsi device struct
1774 * @bdev: pointer to block device context
1775 * @capacity: device size (in 512 byte sectors)
1776 * @params: three element array to place output:
1777 * params[0] number of heads (max 255)
1778 * params[1] number of sectors (max 63)
1779 * params[2] number of cylinders
1784 _scsih_bios_param(struct scsi_device
*sdev
, struct block_device
*bdev
,
1785 sector_t capacity
, int params
[])
1795 dummy
= heads
* sectors
;
1796 cylinders
= capacity
;
1797 sector_div(cylinders
, dummy
);
1800 * Handle extended translation size for logical drives
1803 if ((ulong
)capacity
>= 0x200000) {
1806 dummy
= heads
* sectors
;
1807 cylinders
= capacity
;
1808 sector_div(cylinders
, dummy
);
1813 params
[1] = sectors
;
1814 params
[2] = cylinders
;
1820 * _scsih_response_code - translation of device response code
1821 * @ioc: per adapter object
1822 * @response_code: response code returned by the device
1827 _scsih_response_code(struct MPT2SAS_ADAPTER
*ioc
, u8 response_code
)
1831 switch (response_code
) {
1832 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE
:
1833 desc
= "task management request completed";
1835 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
:
1836 desc
= "invalid frame";
1838 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED
:
1839 desc
= "task management request not supported";
1841 case MPI2_SCSITASKMGMT_RSP_TM_FAILED
:
1842 desc
= "task management request failed";
1844 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
:
1845 desc
= "task management request succeeded";
1847 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN
:
1848 desc
= "invalid lun";
1851 desc
= "overlapped tag attempted";
1853 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
:
1854 desc
= "task queued, however not sent to target";
1860 printk(MPT2SAS_WARN_FMT
"response_code(0x%01x): %s\n",
1861 ioc
->name
, response_code
, desc
);
1865 * _scsih_tm_done - tm completion routine
1866 * @ioc: per adapter object
1867 * @smid: system request message index
1868 * @msix_index: MSIX table index supplied by the OS
1869 * @reply: reply message frame(lower 32bit addr)
1872 * The callback handler when using scsih_issue_tm.
1874 * Return 1 meaning mf should be freed from _base_interrupt
1875 * 0 means the mf is freed from this function.
1878 _scsih_tm_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
1880 MPI2DefaultReply_t
*mpi_reply
;
1882 if (ioc
->tm_cmds
.status
== MPT2_CMD_NOT_USED
)
1884 if (ioc
->tm_cmds
.smid
!= smid
)
1886 ioc
->tm_cmds
.status
|= MPT2_CMD_COMPLETE
;
1887 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
1889 memcpy(ioc
->tm_cmds
.reply
, mpi_reply
, mpi_reply
->MsgLength
*4);
1890 ioc
->tm_cmds
.status
|= MPT2_CMD_REPLY_VALID
;
1892 ioc
->tm_cmds
.status
&= ~MPT2_CMD_PENDING
;
1893 complete(&ioc
->tm_cmds
.done
);
1898 * mpt2sas_scsih_set_tm_flag - set per target tm_busy
1899 * @ioc: per adapter object
1900 * @handle: device handle
1902 * During taskmangement request, we need to freeze the device queue.
1905 mpt2sas_scsih_set_tm_flag(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
1907 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1908 struct scsi_device
*sdev
;
1911 shost_for_each_device(sdev
, ioc
->shost
) {
1914 sas_device_priv_data
= sdev
->hostdata
;
1915 if (!sas_device_priv_data
)
1917 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
1918 sas_device_priv_data
->sas_target
->tm_busy
= 1;
1920 ioc
->ignore_loginfos
= 1;
1926 * mpt2sas_scsih_clear_tm_flag - clear per target tm_busy
1927 * @ioc: per adapter object
1928 * @handle: device handle
1930 * During taskmangement request, we need to freeze the device queue.
1933 mpt2sas_scsih_clear_tm_flag(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
1935 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1936 struct scsi_device
*sdev
;
1939 shost_for_each_device(sdev
, ioc
->shost
) {
1942 sas_device_priv_data
= sdev
->hostdata
;
1943 if (!sas_device_priv_data
)
1945 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
1946 sas_device_priv_data
->sas_target
->tm_busy
= 0;
1948 ioc
->ignore_loginfos
= 0;
1955 * mpt2sas_scsih_issue_tm - main routine for sending tm requests
1956 * @ioc: per adapter struct
1957 * @device_handle: device handle
1958 * @channel: the channel assigned by the OS
1959 * @id: the id assigned by the OS
1961 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
1962 * @smid_task: smid assigned to the task
1963 * @timeout: timeout in seconds
1966 * A generic API for sending task management requests to firmware.
1968 * The callback index is set inside `ioc->tm_cb_idx`.
1970 * Return SUCCESS or FAILED.
1973 mpt2sas_scsih_issue_tm(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
, uint channel
,
1974 uint id
, uint lun
, u8 type
, u16 smid_task
, ulong timeout
,
1975 struct scsi_cmnd
*scmd
)
1977 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
1978 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
1981 unsigned long timeleft
;
1982 struct scsi_cmnd
*scmd_lookup
;
1985 mutex_lock(&ioc
->tm_cmds
.mutex
);
1986 if (ioc
->tm_cmds
.status
!= MPT2_CMD_NOT_USED
) {
1987 printk(MPT2SAS_INFO_FMT
"%s: tm_cmd busy!!!\n",
1988 __func__
, ioc
->name
);
1993 if (ioc
->shost_recovery
|| ioc
->remove_host
) {
1994 printk(MPT2SAS_INFO_FMT
"%s: host reset in progress!\n",
1995 __func__
, ioc
->name
);
2000 ioc_state
= mpt2sas_base_get_iocstate(ioc
, 0);
2001 if (ioc_state
& MPI2_DOORBELL_USED
) {
2002 dhsprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"unexpected doorbell "
2003 "active!\n", ioc
->name
));
2004 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2010 if ((ioc_state
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_FAULT
) {
2011 mpt2sas_base_fault_info(ioc
, ioc_state
&
2012 MPI2_DOORBELL_DATA_MASK
);
2013 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2019 smid
= mpt2sas_base_get_smid_hpr(ioc
, ioc
->tm_cb_idx
);
2021 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
2022 ioc
->name
, __func__
);
2027 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"sending tm: handle(0x%04x),"
2028 " task_type(0x%02x), smid(%d)\n", ioc
->name
, handle
, type
,
2030 ioc
->tm_cmds
.status
= MPT2_CMD_PENDING
;
2031 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
2032 ioc
->tm_cmds
.smid
= smid
;
2033 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
2034 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
2035 mpi_request
->DevHandle
= cpu_to_le16(handle
);
2036 mpi_request
->TaskType
= type
;
2037 mpi_request
->TaskMID
= cpu_to_le16(smid_task
);
2038 int_to_scsilun(lun
, (struct scsi_lun
*)mpi_request
->LUN
);
2039 mpt2sas_scsih_set_tm_flag(ioc
, handle
);
2040 init_completion(&ioc
->tm_cmds
.done
);
2041 mpt2sas_base_put_smid_hi_priority(ioc
, smid
);
2042 timeleft
= wait_for_completion_timeout(&ioc
->tm_cmds
.done
, timeout
*HZ
);
2043 if (!(ioc
->tm_cmds
.status
& MPT2_CMD_COMPLETE
)) {
2044 printk(MPT2SAS_ERR_FMT
"%s: timeout\n",
2045 ioc
->name
, __func__
);
2046 _debug_dump_mf(mpi_request
,
2047 sizeof(Mpi2SCSITaskManagementRequest_t
)/4);
2048 if (!(ioc
->tm_cmds
.status
& MPT2_CMD_RESET
)) {
2049 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2052 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
2053 mpt2sas_scsih_clear_tm_flag(ioc
, handle
);
2058 if (ioc
->tm_cmds
.status
& MPT2_CMD_REPLY_VALID
) {
2059 mpi_reply
= ioc
->tm_cmds
.reply
;
2060 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"complete tm: "
2061 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
2062 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
2063 le32_to_cpu(mpi_reply
->IOCLogInfo
),
2064 le32_to_cpu(mpi_reply
->TerminationCount
)));
2065 if (ioc
->logging_level
& MPT_DEBUG_TM
) {
2066 _scsih_response_code(ioc
, mpi_reply
->ResponseCode
);
2067 if (mpi_reply
->IOCStatus
)
2068 _debug_dump_mf(mpi_request
,
2069 sizeof(Mpi2SCSITaskManagementRequest_t
)/4);
2074 * Check to see the commands were terminated.
2075 * This is only needed for eh callbacks, hence the scmd check.
2079 goto bypass_sanity_checks
;
2081 case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
:
2082 scmd_lookup
= _scsih_scsi_lookup_get(ioc
, smid_task
);
2083 if (scmd_lookup
&& (scmd_lookup
->serial_number
==
2084 scmd
->serial_number
))
2090 case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
:
2091 if (_scsih_scsi_lookup_find_by_target(ioc
, id
, channel
))
2097 case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET
:
2098 if (_scsih_scsi_lookup_find_by_lun(ioc
, id
, lun
, channel
))
2105 bypass_sanity_checks
:
2107 mpt2sas_scsih_clear_tm_flag(ioc
, handle
);
2108 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
2109 mutex_unlock(&ioc
->tm_cmds
.mutex
);
2114 mutex_unlock(&ioc
->tm_cmds
.mutex
);
2119 * _scsih_abort - eh threads main abort routine
2120 * @sdev: scsi device struct
2122 * Returns SUCCESS if command aborted else FAILED
2125 _scsih_abort(struct scsi_cmnd
*scmd
)
2127 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2128 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2133 printk(MPT2SAS_INFO_FMT
"attempting task abort! scmd(%p)\n",
2135 scsi_print_command(scmd
);
2137 sas_device_priv_data
= scmd
->device
->hostdata
;
2138 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2139 printk(MPT2SAS_INFO_FMT
"device been deleted! scmd(%p)\n",
2141 scmd
->result
= DID_NO_CONNECT
<< 16;
2142 scmd
->scsi_done(scmd
);
2147 /* search for the command */
2148 smid
= _scsih_scsi_lookup_find_by_scmd(ioc
, scmd
);
2150 scmd
->result
= DID_RESET
<< 16;
2155 /* for hidden raid components and volumes this is not supported */
2156 if (sas_device_priv_data
->sas_target
->flags
&
2157 MPT_TARGET_FLAGS_RAID_COMPONENT
||
2158 sas_device_priv_data
->sas_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
2159 scmd
->result
= DID_RESET
<< 16;
2164 mpt2sas_halt_firmware(ioc
);
2166 handle
= sas_device_priv_data
->sas_target
->handle
;
2167 r
= mpt2sas_scsih_issue_tm(ioc
, handle
, scmd
->device
->channel
,
2168 scmd
->device
->id
, scmd
->device
->lun
,
2169 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
, smid
, 30, scmd
);
2172 printk(MPT2SAS_INFO_FMT
"task abort: %s scmd(%p)\n",
2173 ioc
->name
, ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2178 * _scsih_dev_reset - eh threads main device reset routine
2179 * @sdev: scsi device struct
2181 * Returns SUCCESS if command aborted else FAILED
2184 _scsih_dev_reset(struct scsi_cmnd
*scmd
)
2186 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2187 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2188 struct _sas_device
*sas_device
;
2189 unsigned long flags
;
2193 printk(MPT2SAS_INFO_FMT
"attempting device reset! scmd(%p)\n",
2195 scsi_print_command(scmd
);
2197 sas_device_priv_data
= scmd
->device
->hostdata
;
2198 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2199 printk(MPT2SAS_INFO_FMT
"device been deleted! scmd(%p)\n",
2201 scmd
->result
= DID_NO_CONNECT
<< 16;
2202 scmd
->scsi_done(scmd
);
2207 /* for hidden raid components obtain the volume_handle */
2209 if (sas_device_priv_data
->sas_target
->flags
&
2210 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2211 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2212 sas_device
= _scsih_sas_device_find_by_handle(ioc
,
2213 sas_device_priv_data
->sas_target
->handle
);
2215 handle
= sas_device
->volume_handle
;
2216 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2218 handle
= sas_device_priv_data
->sas_target
->handle
;
2221 scmd
->result
= DID_RESET
<< 16;
2226 r
= mpt2sas_scsih_issue_tm(ioc
, handle
, scmd
->device
->channel
,
2227 scmd
->device
->id
, scmd
->device
->lun
,
2228 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET
, 0, 30, scmd
);
2231 printk(MPT2SAS_INFO_FMT
"device reset: %s scmd(%p)\n",
2232 ioc
->name
, ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2237 * _scsih_target_reset - eh threads main target reset routine
2238 * @sdev: scsi device struct
2240 * Returns SUCCESS if command aborted else FAILED
2243 _scsih_target_reset(struct scsi_cmnd
*scmd
)
2245 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2246 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2247 struct _sas_device
*sas_device
;
2248 unsigned long flags
;
2252 printk(MPT2SAS_INFO_FMT
"attempting target reset! scmd(%p)\n",
2254 scsi_print_command(scmd
);
2256 sas_device_priv_data
= scmd
->device
->hostdata
;
2257 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2258 printk(MPT2SAS_INFO_FMT
"target been deleted! scmd(%p)\n",
2260 scmd
->result
= DID_NO_CONNECT
<< 16;
2261 scmd
->scsi_done(scmd
);
2266 /* for hidden raid components obtain the volume_handle */
2268 if (sas_device_priv_data
->sas_target
->flags
&
2269 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2270 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2271 sas_device
= _scsih_sas_device_find_by_handle(ioc
,
2272 sas_device_priv_data
->sas_target
->handle
);
2274 handle
= sas_device
->volume_handle
;
2275 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2277 handle
= sas_device_priv_data
->sas_target
->handle
;
2280 scmd
->result
= DID_RESET
<< 16;
2285 r
= mpt2sas_scsih_issue_tm(ioc
, handle
, scmd
->device
->channel
,
2286 scmd
->device
->id
, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
, 0,
2290 printk(MPT2SAS_INFO_FMT
"target reset: %s scmd(%p)\n",
2291 ioc
->name
, ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2296 * _scsih_host_reset - eh threads main host reset routine
2297 * @sdev: scsi device struct
2299 * Returns SUCCESS if command aborted else FAILED
2302 _scsih_host_reset(struct scsi_cmnd
*scmd
)
2304 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2307 printk(MPT2SAS_INFO_FMT
"attempting host reset! scmd(%p)\n",
2309 scsi_print_command(scmd
);
2311 retval
= mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2313 r
= (retval
< 0) ? FAILED
: SUCCESS
;
2314 printk(MPT2SAS_INFO_FMT
"host reset: %s scmd(%p)\n",
2315 ioc
->name
, ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2321 * _scsih_fw_event_add - insert and queue up fw_event
2322 * @ioc: per adapter object
2323 * @fw_event: object describing the event
2324 * Context: This function will acquire ioc->fw_event_lock.
2326 * This adds the firmware event object into link list, then queues it up to
2327 * be processed from user context.
2332 _scsih_fw_event_add(struct MPT2SAS_ADAPTER
*ioc
, struct fw_event_work
*fw_event
)
2334 unsigned long flags
;
2336 if (ioc
->firmware_event_thread
== NULL
)
2339 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2340 list_add_tail(&fw_event
->list
, &ioc
->fw_event_list
);
2341 INIT_DELAYED_WORK(&fw_event
->delayed_work
, _firmware_event_work
);
2342 queue_delayed_work(ioc
->firmware_event_thread
,
2343 &fw_event
->delayed_work
, 0);
2344 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2348 * _scsih_fw_event_free - delete fw_event
2349 * @ioc: per adapter object
2350 * @fw_event: object describing the event
2351 * Context: This function will acquire ioc->fw_event_lock.
2353 * This removes firmware event object from link list, frees associated memory.
2358 _scsih_fw_event_free(struct MPT2SAS_ADAPTER
*ioc
, struct fw_event_work
2361 unsigned long flags
;
2363 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2364 list_del(&fw_event
->list
);
2365 kfree(fw_event
->event_data
);
2367 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2372 * _scsih_queue_rescan - queue a topology rescan from user context
2373 * @ioc: per adapter object
2378 _scsih_queue_rescan(struct MPT2SAS_ADAPTER
*ioc
)
2380 struct fw_event_work
*fw_event
;
2382 if (ioc
->wait_for_port_enable_to_complete
)
2384 fw_event
= kzalloc(sizeof(struct fw_event_work
), GFP_ATOMIC
);
2387 fw_event
->event
= MPT2SAS_RESCAN_AFTER_HOST_RESET
;
2388 fw_event
->ioc
= ioc
;
2389 _scsih_fw_event_add(ioc
, fw_event
);
2393 * _scsih_fw_event_cleanup_queue - cleanup event queue
2394 * @ioc: per adapter object
2396 * Walk the firmware event queue, either killing timers, or waiting
2397 * for outstanding events to complete
2402 _scsih_fw_event_cleanup_queue(struct MPT2SAS_ADAPTER
*ioc
)
2404 struct fw_event_work
*fw_event
, *next
;
2406 if (list_empty(&ioc
->fw_event_list
) ||
2407 !ioc
->firmware_event_thread
|| in_interrupt())
2410 list_for_each_entry_safe(fw_event
, next
, &ioc
->fw_event_list
, list
) {
2411 if (cancel_delayed_work(&fw_event
->delayed_work
)) {
2412 _scsih_fw_event_free(ioc
, fw_event
);
2415 fw_event
->cancel_pending_work
= 1;
2420 * _scsih_ublock_io_device - set the device state to SDEV_RUNNING
2421 * @ioc: per adapter object
2422 * @handle: device handle
2424 * During device pull we need to appropiately set the sdev state.
2427 _scsih_ublock_io_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
2429 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2430 struct scsi_device
*sdev
;
2432 shost_for_each_device(sdev
, ioc
->shost
) {
2433 sas_device_priv_data
= sdev
->hostdata
;
2434 if (!sas_device_priv_data
)
2436 if (!sas_device_priv_data
->block
)
2438 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2439 dewtprintk(ioc
, sdev_printk(KERN_INFO
, sdev
,
2440 MPT2SAS_INFO_FMT
"SDEV_RUNNING: "
2441 "handle(0x%04x)\n", ioc
->name
, handle
));
2442 sas_device_priv_data
->block
= 0;
2443 scsi_internal_device_unblock(sdev
);
2449 * _scsih_block_io_device - set the device state to SDEV_BLOCK
2450 * @ioc: per adapter object
2451 * @handle: device handle
2453 * During device pull we need to appropiately set the sdev state.
2456 _scsih_block_io_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
2458 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2459 struct scsi_device
*sdev
;
2461 shost_for_each_device(sdev
, ioc
->shost
) {
2462 sas_device_priv_data
= sdev
->hostdata
;
2463 if (!sas_device_priv_data
)
2465 if (sas_device_priv_data
->block
)
2467 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2468 dewtprintk(ioc
, sdev_printk(KERN_INFO
, sdev
,
2469 MPT2SAS_INFO_FMT
"SDEV_BLOCK: "
2470 "handle(0x%04x)\n", ioc
->name
, handle
));
2471 sas_device_priv_data
->block
= 1;
2472 scsi_internal_device_block(sdev
);
2478 * _scsih_block_io_to_children_attached_to_ex
2479 * @ioc: per adapter object
2480 * @sas_expander: the sas_device object
2482 * This routine set sdev state to SDEV_BLOCK for all devices
2483 * attached to this expander. This function called when expander is
2487 _scsih_block_io_to_children_attached_to_ex(struct MPT2SAS_ADAPTER
*ioc
,
2488 struct _sas_node
*sas_expander
)
2490 struct _sas_port
*mpt2sas_port
;
2491 struct _sas_device
*sas_device
;
2492 struct _sas_node
*expander_sibling
;
2493 unsigned long flags
;
2498 list_for_each_entry(mpt2sas_port
,
2499 &sas_expander
->sas_port_list
, port_list
) {
2500 if (mpt2sas_port
->remote_identify
.device_type
==
2502 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2504 mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
2505 mpt2sas_port
->remote_identify
.sas_address
);
2506 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2509 _scsih_block_io_device(ioc
, sas_device
->handle
);
2513 list_for_each_entry(mpt2sas_port
,
2514 &sas_expander
->sas_port_list
, port_list
) {
2516 if (mpt2sas_port
->remote_identify
.device_type
==
2517 MPI2_SAS_DEVICE_INFO_EDGE_EXPANDER
||
2518 mpt2sas_port
->remote_identify
.device_type
==
2519 MPI2_SAS_DEVICE_INFO_FANOUT_EXPANDER
) {
2521 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
2523 mpt2sas_scsih_expander_find_by_sas_address(
2524 ioc
, mpt2sas_port
->remote_identify
.sas_address
);
2525 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
2526 _scsih_block_io_to_children_attached_to_ex(ioc
,
2533 * _scsih_block_io_to_children_attached_directly
2534 * @ioc: per adapter object
2535 * @event_data: topology change event data
2537 * This routine set sdev state to SDEV_BLOCK for all devices
2538 * direct attached during device pull.
2541 _scsih_block_io_to_children_attached_directly(struct MPT2SAS_ADAPTER
*ioc
,
2542 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
2549 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
2550 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
2553 phy_number
= event_data
->StartPhyNum
+ i
;
2554 reason_code
= event_data
->PHY
[i
].PhyStatus
&
2555 MPI2_EVENT_SAS_TOPO_RC_MASK
;
2556 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
)
2557 _scsih_block_io_device(ioc
, handle
);
2562 * _scsih_tm_tr_send - send task management request
2563 * @ioc: per adapter object
2564 * @handle: device handle
2565 * Context: interrupt time.
2567 * This code is to initiate the device removal handshake protocal
2568 * with controller firmware. This function will issue target reset
2569 * using high priority request queue. It will send a sas iounit
2570 * controll request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
2572 * This is designed to send muliple task management request at the same
2573 * time to the fifo. If the fifo is full, we will append the request,
2574 * and process it in a future completion.
2577 _scsih_tm_tr_send(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
2579 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
2581 struct _sas_device
*sas_device
;
2582 unsigned long flags
;
2583 struct _tr_list
*delayed_tr
;
2585 if (ioc
->shost_recovery
|| ioc
->remove_host
) {
2586 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host reset in "
2587 "progress!\n", __func__
, ioc
->name
));
2591 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2592 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
2593 if (sas_device
&& sas_device
->hidden_raid_component
) {
2594 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2597 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2599 smid
= mpt2sas_base_get_smid_hpr(ioc
, ioc
->tm_tr_cb_idx
);
2601 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
2604 INIT_LIST_HEAD(&delayed_tr
->list
);
2605 delayed_tr
->handle
= handle
;
2606 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_list
);
2607 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
2608 "DELAYED:tr:handle(0x%04x), (open)\n",
2609 ioc
->name
, handle
));
2613 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"tr_send:handle(0x%04x), "
2614 "(open), smid(%d), cb(%d)\n", ioc
->name
, handle
, smid
,
2615 ioc
->tm_tr_cb_idx
));
2616 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
2617 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
2618 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
2619 mpi_request
->DevHandle
= cpu_to_le16(handle
);
2620 mpi_request
->TaskType
= MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
;
2621 mpt2sas_base_put_smid_hi_priority(ioc
, smid
);
2627 * _scsih_sas_control_complete - completion routine
2628 * @ioc: per adapter object
2629 * @smid: system request message index
2630 * @msix_index: MSIX table index supplied by the OS
2631 * @reply: reply message frame(lower 32bit addr)
2632 * Context: interrupt time.
2634 * This is the sas iounit controll completion routine.
2635 * This code is part of the code to initiate the device removal
2636 * handshake protocal with controller firmware.
2638 * Return 1 meaning mf should be freed from _base_interrupt
2639 * 0 means the mf is freed from this function.
2642 _scsih_sas_control_complete(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
,
2643 u8 msix_index
, u32 reply
)
2645 Mpi2SasIoUnitControlReply_t
*mpi_reply
=
2646 mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
2648 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
2649 "sc_complete:handle(0x%04x), (open) "
2650 "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
2651 ioc
->name
, le16_to_cpu(mpi_reply
->DevHandle
), smid
,
2652 le16_to_cpu(mpi_reply
->IOCStatus
),
2653 le32_to_cpu(mpi_reply
->IOCLogInfo
)));
2658 * _scsih_tm_tr_complete -
2659 * @ioc: per adapter object
2660 * @smid: system request message index
2661 * @msix_index: MSIX table index supplied by the OS
2662 * @reply: reply message frame(lower 32bit addr)
2663 * Context: interrupt time.
2665 * This is the target reset completion routine.
2666 * This code is part of the code to initiate the device removal
2667 * handshake protocal with controller firmware.
2668 * It will send a sas iounit controll request (MPI2_SAS_OP_REMOVE_DEVICE)
2670 * Return 1 meaning mf should be freed from _base_interrupt
2671 * 0 means the mf is freed from this function.
2674 _scsih_tm_tr_complete(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
,
2678 Mpi2SCSITaskManagementRequest_t
*mpi_request_tm
;
2679 Mpi2SCSITaskManagementReply_t
*mpi_reply
=
2680 mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
2681 Mpi2SasIoUnitControlRequest_t
*mpi_request
;
2683 struct _tr_list
*delayed_tr
;
2685 if (ioc
->shost_recovery
|| ioc
->remove_host
) {
2686 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host reset in "
2687 "progress!\n", __func__
, ioc
->name
));
2691 mpi_request_tm
= mpt2sas_base_get_msg_frame(ioc
, smid
);
2692 handle
= le16_to_cpu(mpi_request_tm
->DevHandle
);
2693 if (handle
!= le16_to_cpu(mpi_reply
->DevHandle
)) {
2694 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"spurious interrupt: "
2695 "handle(0x%04x:0x%04x), smid(%d)!!!\n", ioc
->name
, handle
,
2696 le16_to_cpu(mpi_reply
->DevHandle
), smid
));
2700 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
2701 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
2702 "loginfo(0x%08x), completed(%d)\n", ioc
->name
,
2703 handle
, smid
, le16_to_cpu(mpi_reply
->IOCStatus
),
2704 le32_to_cpu(mpi_reply
->IOCLogInfo
),
2705 le32_to_cpu(mpi_reply
->TerminationCount
)));
2707 smid_sas_ctrl
= mpt2sas_base_get_smid(ioc
, ioc
->tm_sas_control_cb_idx
);
2708 if (!smid_sas_ctrl
) {
2709 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
2710 ioc
->name
, __func__
);
2714 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"sc_send:handle(0x%04x), "
2715 "(open), smid(%d), cb(%d)\n", ioc
->name
, handle
, smid_sas_ctrl
,
2716 ioc
->tm_sas_control_cb_idx
));
2717 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid_sas_ctrl
);
2718 memset(mpi_request
, 0, sizeof(Mpi2SasIoUnitControlRequest_t
));
2719 mpi_request
->Function
= MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
;
2720 mpi_request
->Operation
= MPI2_SAS_OP_REMOVE_DEVICE
;
2721 mpi_request
->DevHandle
= mpi_request_tm
->DevHandle
;
2722 mpt2sas_base_put_smid_default(ioc
, smid_sas_ctrl
);
2724 if (!list_empty(&ioc
->delayed_tr_list
)) {
2725 delayed_tr
= list_entry(ioc
->delayed_tr_list
.next
,
2726 struct _tr_list
, list
);
2727 mpt2sas_base_free_smid(ioc
, smid
);
2728 _scsih_tm_tr_send(ioc
, delayed_tr
->handle
);
2729 list_del(&delayed_tr
->list
);
2731 return 0; /* tells base_interrupt not to free mf */
2737 * _scsih_check_topo_delete_events - sanity check on topo events
2738 * @ioc: per adapter object
2739 * @event_data: the event data payload
2741 * This routine added to better handle cable breaker.
2743 * This handles the case where driver recieves multiple expander
2744 * add and delete events in a single shot. When there is a delete event
2745 * the routine will void any pending add events waiting in the event queue.
2750 _scsih_check_topo_delete_events(struct MPT2SAS_ADAPTER
*ioc
,
2751 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
2753 struct fw_event_work
*fw_event
;
2754 Mpi2EventDataSasTopologyChangeList_t
*local_event_data
;
2755 u16 expander_handle
;
2756 struct _sas_node
*sas_expander
;
2757 unsigned long flags
;
2761 for (i
= 0 ; i
< event_data
->NumEntries
; i
++) {
2762 if (event_data
->PHY
[i
].PhyStatus
&
2763 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT
)
2765 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
2768 reason_code
= event_data
->PHY
[i
].PhyStatus
&
2769 MPI2_EVENT_SAS_TOPO_RC_MASK
;
2770 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
)
2771 _scsih_tm_tr_send(ioc
, handle
);
2774 expander_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
2775 if (expander_handle
< ioc
->sas_hba
.num_phys
) {
2776 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
2780 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
2781 || event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
) {
2782 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
2783 sas_expander
= mpt2sas_scsih_expander_find_by_handle(ioc
,
2785 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
2786 _scsih_block_io_to_children_attached_to_ex(ioc
, sas_expander
);
2787 } else if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_RESPONDING
)
2788 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
2790 if (event_data
->ExpStatus
!= MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
)
2793 /* mark ignore flag for pending events */
2794 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2795 list_for_each_entry(fw_event
, &ioc
->fw_event_list
, list
) {
2796 if (fw_event
->event
!= MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
||
2799 local_event_data
= fw_event
->event_data
;
2800 if (local_event_data
->ExpStatus
==
2801 MPI2_EVENT_SAS_TOPO_ES_ADDED
||
2802 local_event_data
->ExpStatus
==
2803 MPI2_EVENT_SAS_TOPO_ES_RESPONDING
) {
2804 if (le16_to_cpu(local_event_data
->ExpanderDevHandle
) ==
2806 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
2807 "setting ignoring flag\n", ioc
->name
));
2808 fw_event
->ignore
= 1;
2812 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2816 * _scsih_flush_running_cmds - completing outstanding commands.
2817 * @ioc: per adapter object
2819 * The flushing out of all pending scmd commands following host reset,
2820 * where all IO is dropped to the floor.
2825 _scsih_flush_running_cmds(struct MPT2SAS_ADAPTER
*ioc
)
2827 struct scsi_cmnd
*scmd
;
2831 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
2832 scmd
= _scsih_scsi_lookup_get(ioc
, smid
);
2836 mpt2sas_base_free_smid(ioc
, smid
);
2837 scsi_dma_unmap(scmd
);
2838 scmd
->result
= DID_RESET
<< 16;
2839 scmd
->scsi_done(scmd
);
2841 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"completing %d cmds\n",
2846 * _scsih_setup_eedp - setup MPI request for EEDP transfer
2847 * @scmd: pointer to scsi command object
2848 * @mpi_request: pointer to the SCSI_IO reqest message frame
2850 * Supporting protection 1 and 3.
2855 _scsih_setup_eedp(struct scsi_cmnd
*scmd
, Mpi2SCSIIORequest_t
*mpi_request
)
2858 unsigned char prot_op
= scsi_get_prot_op(scmd
);
2859 unsigned char prot_type
= scsi_get_prot_type(scmd
);
2861 if (prot_type
== SCSI_PROT_DIF_TYPE0
||
2862 prot_type
== SCSI_PROT_DIF_TYPE2
||
2863 prot_op
== SCSI_PROT_NORMAL
)
2866 if (prot_op
== SCSI_PROT_READ_STRIP
)
2867 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP
;
2868 else if (prot_op
== SCSI_PROT_WRITE_INSERT
)
2869 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_INSERT_OP
;
2873 switch (prot_type
) {
2874 case SCSI_PROT_DIF_TYPE1
:
2877 * enable ref/guard checking
2878 * auto increment ref tag
2880 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG
|
2881 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG
|
2882 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
2883 mpi_request
->CDB
.EEDP32
.PrimaryReferenceTag
=
2884 cpu_to_be32(scsi_get_lba(scmd
));
2888 case SCSI_PROT_DIF_TYPE3
:
2891 * enable guard checking
2893 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
2896 mpi_request
->EEDPBlockSize
= cpu_to_le32(scmd
->device
->sector_size
);
2897 mpi_request
->EEDPFlags
= cpu_to_le16(eedp_flags
);
2901 * _scsih_eedp_error_handling - return sense code for EEDP errors
2902 * @scmd: pointer to scsi command object
2903 * @ioc_status: ioc status
2908 _scsih_eedp_error_handling(struct scsi_cmnd
*scmd
, u16 ioc_status
)
2914 switch (ioc_status
) {
2915 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
2918 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
2921 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
2929 if (scmd
->sc_data_direction
== DMA_TO_DEVICE
) {
2930 sk
= ILLEGAL_REQUEST
;
2931 host_byte
= DID_ABORT
;
2933 sk
= ABORTED_COMMAND
;
2937 scsi_build_sense_buffer(0, scmd
->sense_buffer
, sk
, 0x10, ascq
);
2938 scmd
->result
= DRIVER_SENSE
<< 24 | (host_byte
<< 16) |
2939 SAM_STAT_CHECK_CONDITION
;
2943 * _scsih_qcmd - main scsi request entry point
2944 * @scmd: pointer to scsi command object
2945 * @done: function pointer to be invoked on completion
2947 * The callback index is set inside `ioc->scsi_io_cb_idx`.
2949 * Returns 0 on success. If there's a failure, return either:
2950 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
2951 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
2954 _scsih_qcmd(struct scsi_cmnd
*scmd
, void (*done
)(struct scsi_cmnd
*))
2956 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2957 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2958 struct MPT2SAS_TARGET
*sas_target_priv_data
;
2959 Mpi2SCSIIORequest_t
*mpi_request
;
2963 scmd
->scsi_done
= done
;
2964 sas_device_priv_data
= scmd
->device
->hostdata
;
2965 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2966 scmd
->result
= DID_NO_CONNECT
<< 16;
2967 scmd
->scsi_done(scmd
);
2971 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
2972 /* invalid device handle */
2973 if (sas_target_priv_data
->handle
== MPT2SAS_INVALID_DEVICE_HANDLE
) {
2974 scmd
->result
= DID_NO_CONNECT
<< 16;
2975 scmd
->scsi_done(scmd
);
2979 /* host recovery or link resets sent via IOCTLs */
2980 if (ioc
->shost_recovery
|| ioc
->ioc_link_reset_in_progress
)
2981 return SCSI_MLQUEUE_HOST_BUSY
;
2982 /* device busy with task managment */
2983 else if (sas_device_priv_data
->block
|| sas_target_priv_data
->tm_busy
)
2984 return SCSI_MLQUEUE_DEVICE_BUSY
;
2985 /* device has been deleted */
2986 else if (sas_target_priv_data
->deleted
) {
2987 scmd
->result
= DID_NO_CONNECT
<< 16;
2988 scmd
->scsi_done(scmd
);
2992 if (scmd
->sc_data_direction
== DMA_FROM_DEVICE
)
2993 mpi_control
= MPI2_SCSIIO_CONTROL_READ
;
2994 else if (scmd
->sc_data_direction
== DMA_TO_DEVICE
)
2995 mpi_control
= MPI2_SCSIIO_CONTROL_WRITE
;
2997 mpi_control
= MPI2_SCSIIO_CONTROL_NODATATRANSFER
;
3000 if (!(sas_device_priv_data
->flags
& MPT_DEVICE_FLAGS_INIT
)) {
3001 if (scmd
->device
->tagged_supported
) {
3002 if (scmd
->device
->ordered_tags
)
3003 mpi_control
|= MPI2_SCSIIO_CONTROL_ORDEREDQ
;
3005 mpi_control
|= MPI2_SCSIIO_CONTROL_SIMPLEQ
;
3007 /* MPI Revision I (UNIT = 0xA) - removed MPI2_SCSIIO_CONTROL_UNTAGGED */
3008 /* mpi_control |= MPI2_SCSIIO_CONTROL_UNTAGGED;
3010 mpi_control
|= (0x500);
3013 mpi_control
|= MPI2_SCSIIO_CONTROL_SIMPLEQ
;
3014 /* Make sure Device is not raid volume */
3015 if (!_scsih_is_raid(&scmd
->device
->sdev_gendev
) &&
3016 sas_is_tlr_enabled(scmd
->device
))
3017 mpi_control
|= MPI2_SCSIIO_CONTROL_TLR_ON
;
3019 smid
= mpt2sas_base_get_smid_scsiio(ioc
, ioc
->scsi_io_cb_idx
, scmd
);
3021 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
3022 ioc
->name
, __func__
);
3025 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3026 memset(mpi_request
, 0, sizeof(Mpi2SCSIIORequest_t
));
3027 _scsih_setup_eedp(scmd
, mpi_request
);
3028 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
3029 if (sas_device_priv_data
->sas_target
->flags
&
3030 MPT_TARGET_FLAGS_RAID_COMPONENT
)
3031 mpi_request
->Function
= MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
;
3033 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
3034 mpi_request
->DevHandle
=
3035 cpu_to_le16(sas_device_priv_data
->sas_target
->handle
);
3036 mpi_request
->DataLength
= cpu_to_le32(scsi_bufflen(scmd
));
3037 mpi_request
->Control
= cpu_to_le32(mpi_control
);
3038 mpi_request
->IoFlags
= cpu_to_le16(scmd
->cmd_len
);
3039 mpi_request
->MsgFlags
= MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR
;
3040 mpi_request
->SenseBufferLength
= SCSI_SENSE_BUFFERSIZE
;
3041 mpi_request
->SenseBufferLowAddress
=
3042 mpt2sas_base_get_sense_buffer_dma(ioc
, smid
);
3043 mpi_request
->SGLOffset0
= offsetof(Mpi2SCSIIORequest_t
, SGL
) / 4;
3044 mpi_request
->SGLFlags
= cpu_to_le16(MPI2_SCSIIO_SGLFLAGS_TYPE_MPI
+
3045 MPI2_SCSIIO_SGLFLAGS_SYSTEM_ADDR
);
3046 mpi_request
->VF_ID
= 0; /* TODO */
3047 mpi_request
->VP_ID
= 0;
3048 int_to_scsilun(sas_device_priv_data
->lun
, (struct scsi_lun
*)
3050 memcpy(mpi_request
->CDB
.CDB32
, scmd
->cmnd
, scmd
->cmd_len
);
3052 if (!mpi_request
->DataLength
) {
3053 mpt2sas_base_build_zero_len_sge(ioc
, &mpi_request
->SGL
);
3055 if (_scsih_build_scatter_gather(ioc
, scmd
, smid
)) {
3056 mpt2sas_base_free_smid(ioc
, smid
);
3061 if (likely(mpi_request
->Function
== MPI2_FUNCTION_SCSI_IO_REQUEST
))
3062 mpt2sas_base_put_smid_scsi_io(ioc
, smid
,
3063 sas_device_priv_data
->sas_target
->handle
);
3065 mpt2sas_base_put_smid_default(ioc
, smid
);
3069 return SCSI_MLQUEUE_HOST_BUSY
;
3073 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
3074 * @sense_buffer: sense data returned by target
3075 * @data: normalized skey/asc/ascq
3080 _scsih_normalize_sense(char *sense_buffer
, struct sense_info
*data
)
3082 if ((sense_buffer
[0] & 0x7F) >= 0x72) {
3083 /* descriptor format */
3084 data
->skey
= sense_buffer
[1] & 0x0F;
3085 data
->asc
= sense_buffer
[2];
3086 data
->ascq
= sense_buffer
[3];
3089 data
->skey
= sense_buffer
[2] & 0x0F;
3090 data
->asc
= sense_buffer
[12];
3091 data
->ascq
= sense_buffer
[13];
3095 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3097 * _scsih_scsi_ioc_info - translated non-successfull SCSI_IO request
3098 * @ioc: per adapter object
3099 * @scmd: pointer to scsi command object
3100 * @mpi_reply: reply mf payload returned from firmware
3102 * scsi_status - SCSI Status code returned from target device
3103 * scsi_state - state info associated with SCSI_IO determined by ioc
3104 * ioc_status - ioc supplied status info
3109 _scsih_scsi_ioc_info(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
,
3110 Mpi2SCSIIOReply_t
*mpi_reply
, u16 smid
)
3114 u16 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) &
3115 MPI2_IOCSTATUS_MASK
;
3116 u8 scsi_state
= mpi_reply
->SCSIState
;
3117 u8 scsi_status
= mpi_reply
->SCSIStatus
;
3118 char *desc_ioc_state
= NULL
;
3119 char *desc_scsi_status
= NULL
;
3120 char *desc_scsi_state
= ioc
->tmp_string
;
3121 u32 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
3123 if (log_info
== 0x31170000)
3126 switch (ioc_status
) {
3127 case MPI2_IOCSTATUS_SUCCESS
:
3128 desc_ioc_state
= "success";
3130 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
3131 desc_ioc_state
= "invalid function";
3133 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
3134 desc_ioc_state
= "scsi recovered error";
3136 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE
:
3137 desc_ioc_state
= "scsi invalid dev handle";
3139 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
3140 desc_ioc_state
= "scsi device not there";
3142 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
3143 desc_ioc_state
= "scsi data overrun";
3145 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
3146 desc_ioc_state
= "scsi data underrun";
3148 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
3149 desc_ioc_state
= "scsi io data error";
3151 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
3152 desc_ioc_state
= "scsi protocol error";
3154 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
3155 desc_ioc_state
= "scsi task terminated";
3157 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
3158 desc_ioc_state
= "scsi residual mismatch";
3160 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
3161 desc_ioc_state
= "scsi task mgmt failed";
3163 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
3164 desc_ioc_state
= "scsi ioc terminated";
3166 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
3167 desc_ioc_state
= "scsi ext terminated";
3169 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
3170 desc_ioc_state
= "eedp guard error";
3172 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
3173 desc_ioc_state
= "eedp ref tag error";
3175 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
3176 desc_ioc_state
= "eedp app tag error";
3179 desc_ioc_state
= "unknown";
3183 switch (scsi_status
) {
3184 case MPI2_SCSI_STATUS_GOOD
:
3185 desc_scsi_status
= "good";
3187 case MPI2_SCSI_STATUS_CHECK_CONDITION
:
3188 desc_scsi_status
= "check condition";
3190 case MPI2_SCSI_STATUS_CONDITION_MET
:
3191 desc_scsi_status
= "condition met";
3193 case MPI2_SCSI_STATUS_BUSY
:
3194 desc_scsi_status
= "busy";
3196 case MPI2_SCSI_STATUS_INTERMEDIATE
:
3197 desc_scsi_status
= "intermediate";
3199 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET
:
3200 desc_scsi_status
= "intermediate condmet";
3202 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT
:
3203 desc_scsi_status
= "reservation conflict";
3205 case MPI2_SCSI_STATUS_COMMAND_TERMINATED
:
3206 desc_scsi_status
= "command terminated";
3208 case MPI2_SCSI_STATUS_TASK_SET_FULL
:
3209 desc_scsi_status
= "task set full";
3211 case MPI2_SCSI_STATUS_ACA_ACTIVE
:
3212 desc_scsi_status
= "aca active";
3214 case MPI2_SCSI_STATUS_TASK_ABORTED
:
3215 desc_scsi_status
= "task aborted";
3218 desc_scsi_status
= "unknown";
3222 desc_scsi_state
[0] = '\0';
3224 desc_scsi_state
= " ";
3225 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
3226 strcat(desc_scsi_state
, "response info ");
3227 if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
3228 strcat(desc_scsi_state
, "state terminated ");
3229 if (scsi_state
& MPI2_SCSI_STATE_NO_SCSI_STATUS
)
3230 strcat(desc_scsi_state
, "no status ");
3231 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_FAILED
)
3232 strcat(desc_scsi_state
, "autosense failed ");
3233 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
)
3234 strcat(desc_scsi_state
, "autosense valid ");
3236 scsi_print_command(scmd
);
3237 printk(MPT2SAS_WARN_FMT
"\tdev handle(0x%04x), "
3238 "ioc_status(%s)(0x%04x), smid(%d)\n", ioc
->name
,
3239 le16_to_cpu(mpi_reply
->DevHandle
), desc_ioc_state
,
3241 printk(MPT2SAS_WARN_FMT
"\trequest_len(%d), underflow(%d), "
3242 "resid(%d)\n", ioc
->name
, scsi_bufflen(scmd
), scmd
->underflow
,
3243 scsi_get_resid(scmd
));
3244 printk(MPT2SAS_WARN_FMT
"\ttag(%d), transfer_count(%d), "
3245 "sc->result(0x%08x)\n", ioc
->name
, le16_to_cpu(mpi_reply
->TaskTag
),
3246 le32_to_cpu(mpi_reply
->TransferCount
), scmd
->result
);
3247 printk(MPT2SAS_WARN_FMT
"\tscsi_status(%s)(0x%02x), "
3248 "scsi_state(%s)(0x%02x)\n", ioc
->name
, desc_scsi_status
,
3249 scsi_status
, desc_scsi_state
, scsi_state
);
3251 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
3252 struct sense_info data
;
3253 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
3254 printk(MPT2SAS_WARN_FMT
"\t[sense_key,asc,ascq]: "
3255 "[0x%02x,0x%02x,0x%02x], count(%d)\n", ioc
->name
, data
.skey
,
3256 data
.asc
, data
.ascq
, le32_to_cpu(mpi_reply
->SenseCount
));
3259 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
) {
3260 response_info
= le32_to_cpu(mpi_reply
->ResponseInfo
);
3261 response_bytes
= (u8
*)&response_info
;
3262 _scsih_response_code(ioc
, response_bytes
[0]);
3268 * _scsih_smart_predicted_fault - illuminate Fault LED
3269 * @ioc: per adapter object
3270 * @handle: device handle
3275 _scsih_smart_predicted_fault(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
3277 Mpi2SepReply_t mpi_reply
;
3278 Mpi2SepRequest_t mpi_request
;
3279 struct scsi_target
*starget
;
3280 struct MPT2SAS_TARGET
*sas_target_priv_data
;
3281 Mpi2EventNotificationReply_t
*event_reply
;
3282 Mpi2EventDataSasDeviceStatusChange_t
*event_data
;
3283 struct _sas_device
*sas_device
;
3285 unsigned long flags
;
3287 /* only handle non-raid devices */
3288 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
3289 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
3291 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3294 starget
= sas_device
->starget
;
3295 sas_target_priv_data
= starget
->hostdata
;
3297 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
) ||
3298 ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
))) {
3299 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3302 starget_printk(KERN_WARNING
, starget
, "predicted fault\n");
3303 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3305 if (ioc
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_IBM
) {
3306 memset(&mpi_request
, 0, sizeof(Mpi2SepRequest_t
));
3307 mpi_request
.Function
= MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR
;
3308 mpi_request
.Action
= MPI2_SEP_REQ_ACTION_WRITE_STATUS
;
3309 mpi_request
.SlotStatus
=
3310 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT
);
3311 mpi_request
.DevHandle
= cpu_to_le16(handle
);
3312 mpi_request
.Flags
= MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS
;
3313 if ((mpt2sas_base_scsi_enclosure_processor(ioc
, &mpi_reply
,
3314 &mpi_request
)) != 0) {
3315 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3316 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3320 if (mpi_reply
.IOCStatus
|| mpi_reply
.IOCLogInfo
) {
3321 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3322 "enclosure_processor: ioc_status (0x%04x), "
3323 "loginfo(0x%08x)\n", ioc
->name
,
3324 le16_to_cpu(mpi_reply
.IOCStatus
),
3325 le32_to_cpu(mpi_reply
.IOCLogInfo
)));
3330 /* insert into event log */
3331 sz
= offsetof(Mpi2EventNotificationReply_t
, EventData
) +
3332 sizeof(Mpi2EventDataSasDeviceStatusChange_t
);
3333 event_reply
= kzalloc(sz
, GFP_KERNEL
);
3335 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3336 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3340 event_reply
->Function
= MPI2_FUNCTION_EVENT_NOTIFICATION
;
3341 event_reply
->Event
=
3342 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
);
3343 event_reply
->MsgLength
= sz
/4;
3344 event_reply
->EventDataLength
=
3345 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t
)/4);
3346 event_data
= (Mpi2EventDataSasDeviceStatusChange_t
*)
3347 event_reply
->EventData
;
3348 event_data
->ReasonCode
= MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
;
3349 event_data
->ASC
= 0x5D;
3350 event_data
->DevHandle
= cpu_to_le16(handle
);
3351 event_data
->SASAddress
= cpu_to_le64(sas_target_priv_data
->sas_address
);
3352 mpt2sas_ctl_add_to_event_log(ioc
, event_reply
);
3357 * _scsih_io_done - scsi request callback
3358 * @ioc: per adapter object
3359 * @smid: system request message index
3360 * @msix_index: MSIX table index supplied by the OS
3361 * @reply: reply message frame(lower 32bit addr)
3363 * Callback handler when using _scsih_qcmd.
3365 * Return 1 meaning mf should be freed from _base_interrupt
3366 * 0 means the mf is freed from this function.
3369 _scsih_io_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
3371 Mpi2SCSIIORequest_t
*mpi_request
;
3372 Mpi2SCSIIOReply_t
*mpi_reply
;
3373 struct scsi_cmnd
*scmd
;
3379 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
3380 u32 response_code
= 0;
3382 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
3383 scmd
= _scsih_scsi_lookup_get(ioc
, smid
);
3387 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3389 if (mpi_reply
== NULL
) {
3390 scmd
->result
= DID_OK
<< 16;
3394 sas_device_priv_data
= scmd
->device
->hostdata
;
3395 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
||
3396 sas_device_priv_data
->sas_target
->deleted
) {
3397 scmd
->result
= DID_NO_CONNECT
<< 16;
3401 /* turning off TLR */
3402 scsi_state
= mpi_reply
->SCSIState
;
3403 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
3405 le32_to_cpu(mpi_reply
->ResponseInfo
) & 0xFF;
3406 if (!sas_device_priv_data
->tlr_snoop_check
) {
3407 sas_device_priv_data
->tlr_snoop_check
++;
3408 if (!_scsih_is_raid(&scmd
->device
->sdev_gendev
) &&
3409 sas_is_tlr_enabled(scmd
->device
) &&
3410 response_code
== MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
) {
3411 sas_disable_tlr(scmd
->device
);
3412 sdev_printk(KERN_INFO
, scmd
->device
, "TLR disabled\n");
3416 xfer_cnt
= le32_to_cpu(mpi_reply
->TransferCount
);
3417 scsi_set_resid(scmd
, scsi_bufflen(scmd
) - xfer_cnt
);
3418 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
);
3419 if (ioc_status
& MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE
)
3420 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
3423 ioc_status
&= MPI2_IOCSTATUS_MASK
;
3424 scsi_status
= mpi_reply
->SCSIStatus
;
3426 if (ioc_status
== MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
&& xfer_cnt
== 0 &&
3427 (scsi_status
== MPI2_SCSI_STATUS_BUSY
||
3428 scsi_status
== MPI2_SCSI_STATUS_RESERVATION_CONFLICT
||
3429 scsi_status
== MPI2_SCSI_STATUS_TASK_SET_FULL
)) {
3430 ioc_status
= MPI2_IOCSTATUS_SUCCESS
;
3433 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
3434 struct sense_info data
;
3435 const void *sense_data
= mpt2sas_base_get_sense_buffer(ioc
,
3437 u32 sz
= min_t(u32
, SCSI_SENSE_BUFFERSIZE
,
3438 le32_to_cpu(mpi_reply
->SenseCount
));
3439 memcpy(scmd
->sense_buffer
, sense_data
, sz
);
3440 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
3441 /* failure prediction threshold exceeded */
3442 if (data
.asc
== 0x5D)
3443 _scsih_smart_predicted_fault(ioc
,
3444 le16_to_cpu(mpi_reply
->DevHandle
));
3447 switch (ioc_status
) {
3448 case MPI2_IOCSTATUS_BUSY
:
3449 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES
:
3450 scmd
->result
= SAM_STAT_BUSY
;
3453 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
3454 scmd
->result
= DID_NO_CONNECT
<< 16;
3457 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
3458 if (sas_device_priv_data
->block
) {
3459 scmd
->result
= DID_TRANSPORT_DISRUPTED
<< 16;
3462 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
3463 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
3464 scmd
->result
= DID_RESET
<< 16;
3467 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
3468 if ((xfer_cnt
== 0) || (scmd
->underflow
> xfer_cnt
))
3469 scmd
->result
= DID_SOFT_ERROR
<< 16;
3471 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
3474 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
3475 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
3477 if ((scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
))
3480 if (xfer_cnt
< scmd
->underflow
) {
3481 if (scsi_status
== SAM_STAT_BUSY
)
3482 scmd
->result
= SAM_STAT_BUSY
;
3484 scmd
->result
= DID_SOFT_ERROR
<< 16;
3485 } else if (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
3486 MPI2_SCSI_STATE_NO_SCSI_STATUS
))
3487 scmd
->result
= DID_SOFT_ERROR
<< 16;
3488 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
3489 scmd
->result
= DID_RESET
<< 16;
3490 else if (!xfer_cnt
&& scmd
->cmnd
[0] == REPORT_LUNS
) {
3491 mpi_reply
->SCSIState
= MPI2_SCSI_STATE_AUTOSENSE_VALID
;
3492 mpi_reply
->SCSIStatus
= SAM_STAT_CHECK_CONDITION
;
3493 scmd
->result
= (DRIVER_SENSE
<< 24) |
3494 SAM_STAT_CHECK_CONDITION
;
3495 scmd
->sense_buffer
[0] = 0x70;
3496 scmd
->sense_buffer
[2] = ILLEGAL_REQUEST
;
3497 scmd
->sense_buffer
[12] = 0x20;
3498 scmd
->sense_buffer
[13] = 0;
3502 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
3503 scsi_set_resid(scmd
, 0);
3504 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
3505 case MPI2_IOCSTATUS_SUCCESS
:
3506 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
3507 if (response_code
==
3508 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
||
3509 (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
3510 MPI2_SCSI_STATE_NO_SCSI_STATUS
)))
3511 scmd
->result
= DID_SOFT_ERROR
<< 16;
3512 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
3513 scmd
->result
= DID_RESET
<< 16;
3516 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
3517 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
3518 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
3519 _scsih_eedp_error_handling(scmd
, ioc_status
);
3521 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
3522 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
3523 case MPI2_IOCSTATUS_INVALID_SGL
:
3524 case MPI2_IOCSTATUS_INTERNAL_ERROR
:
3525 case MPI2_IOCSTATUS_INVALID_FIELD
:
3526 case MPI2_IOCSTATUS_INVALID_STATE
:
3527 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
3528 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
3530 scmd
->result
= DID_SOFT_ERROR
<< 16;
3535 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3536 if (scmd
->result
&& (ioc
->logging_level
& MPT_DEBUG_REPLY
))
3537 _scsih_scsi_ioc_info(ioc
, scmd
, mpi_reply
, smid
);
3541 scsi_dma_unmap(scmd
);
3542 scmd
->scsi_done(scmd
);
3547 * _scsih_sas_host_refresh - refreshing sas host object contents
3548 * @ioc: per adapter object
3551 * During port enable, fw will send topology events for every device. Its
3552 * possible that the handles may change from the previous setting, so this
3553 * code keeping handles updating if changed.
3558 _scsih_sas_host_refresh(struct MPT2SAS_ADAPTER
*ioc
)
3563 Mpi2ConfigReply_t mpi_reply
;
3564 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
3565 u16 attached_handle
;
3567 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
3568 "updating handles for sas_host(0x%016llx)\n",
3569 ioc
->name
, (unsigned long long)ioc
->sas_hba
.sas_address
));
3571 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
3572 * sizeof(Mpi2SasIOUnit0PhyData_t
));
3573 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
3574 if (!sas_iounit_pg0
) {
3575 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3576 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3580 if ((mpt2sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
3581 sas_iounit_pg0
, sz
)) != 0)
3583 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
3584 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
3586 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
3588 ioc
->sas_hba
.handle
= le16_to_cpu(sas_iounit_pg0
->
3589 PhyData
[0].ControllerDevHandle
);
3590 ioc
->sas_hba
.phy
[i
].handle
= ioc
->sas_hba
.handle
;
3591 attached_handle
= le16_to_cpu(sas_iounit_pg0
->PhyData
[i
].
3593 mpt2sas_transport_update_links(ioc
, ioc
->sas_hba
.sas_address
,
3594 attached_handle
, i
, sas_iounit_pg0
->PhyData
[i
].
3595 NegotiatedLinkRate
>> 4);
3598 kfree(sas_iounit_pg0
);
3602 * _scsih_sas_host_add - create sas host object
3603 * @ioc: per adapter object
3605 * Creating host side data object, stored in ioc->sas_hba
3610 _scsih_sas_host_add(struct MPT2SAS_ADAPTER
*ioc
)
3613 Mpi2ConfigReply_t mpi_reply
;
3614 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
3615 Mpi2SasIOUnitPage1_t
*sas_iounit_pg1
= NULL
;
3616 Mpi2SasPhyPage0_t phy_pg0
;
3617 Mpi2SasDevicePage0_t sas_device_pg0
;
3618 Mpi2SasEnclosurePage0_t enclosure_pg0
;
3621 u16 device_missing_delay
;
3623 mpt2sas_config_get_number_hba_phys(ioc
, &ioc
->sas_hba
.num_phys
);
3624 if (!ioc
->sas_hba
.num_phys
) {
3625 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3626 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3630 /* sas_iounit page 0 */
3631 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
3632 sizeof(Mpi2SasIOUnit0PhyData_t
));
3633 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
3634 if (!sas_iounit_pg0
) {
3635 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3636 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3639 if ((mpt2sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
3640 sas_iounit_pg0
, sz
))) {
3641 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3642 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3645 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
3646 MPI2_IOCSTATUS_MASK
;
3647 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
3648 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3649 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3653 /* sas_iounit page 1 */
3654 sz
= offsetof(Mpi2SasIOUnitPage1_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
3655 sizeof(Mpi2SasIOUnit1PhyData_t
));
3656 sas_iounit_pg1
= kzalloc(sz
, GFP_KERNEL
);
3657 if (!sas_iounit_pg1
) {
3658 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3659 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3662 if ((mpt2sas_config_get_sas_iounit_pg1(ioc
, &mpi_reply
,
3663 sas_iounit_pg1
, sz
))) {
3664 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3665 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3668 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
3669 MPI2_IOCSTATUS_MASK
;
3670 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
3671 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3672 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3676 ioc
->io_missing_delay
=
3677 le16_to_cpu(sas_iounit_pg1
->IODeviceMissingDelay
);
3678 device_missing_delay
=
3679 le16_to_cpu(sas_iounit_pg1
->ReportDeviceMissingDelay
);
3680 if (device_missing_delay
& MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16
)
3681 ioc
->device_missing_delay
= (device_missing_delay
&
3682 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
) * 16;
3684 ioc
->device_missing_delay
= device_missing_delay
&
3685 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
;
3687 ioc
->sas_hba
.parent_dev
= &ioc
->shost
->shost_gendev
;
3688 ioc
->sas_hba
.phy
= kcalloc(ioc
->sas_hba
.num_phys
,
3689 sizeof(struct _sas_phy
), GFP_KERNEL
);
3690 if (!ioc
->sas_hba
.phy
) {
3691 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3692 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3695 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
3696 if ((mpt2sas_config_get_phy_pg0(ioc
, &mpi_reply
, &phy_pg0
,
3698 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3699 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3702 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
3703 MPI2_IOCSTATUS_MASK
;
3704 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
3705 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3706 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3711 ioc
->sas_hba
.handle
= le16_to_cpu(sas_iounit_pg0
->
3712 PhyData
[0].ControllerDevHandle
);
3713 ioc
->sas_hba
.phy
[i
].handle
= ioc
->sas_hba
.handle
;
3714 ioc
->sas_hba
.phy
[i
].phy_id
= i
;
3715 mpt2sas_transport_add_host_phy(ioc
, &ioc
->sas_hba
.phy
[i
],
3716 phy_pg0
, ioc
->sas_hba
.parent_dev
);
3718 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
3719 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, ioc
->sas_hba
.handle
))) {
3720 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3721 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3724 ioc
->sas_hba
.enclosure_handle
=
3725 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
3726 ioc
->sas_hba
.sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
3727 printk(MPT2SAS_INFO_FMT
"host_add: handle(0x%04x), "
3728 "sas_addr(0x%016llx), phys(%d)\n", ioc
->name
, ioc
->sas_hba
.handle
,
3729 (unsigned long long) ioc
->sas_hba
.sas_address
,
3730 ioc
->sas_hba
.num_phys
) ;
3732 if (ioc
->sas_hba
.enclosure_handle
) {
3733 if (!(mpt2sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
3735 MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
3736 ioc
->sas_hba
.enclosure_handle
))) {
3737 ioc
->sas_hba
.enclosure_logical_id
=
3738 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
3743 kfree(sas_iounit_pg1
);
3744 kfree(sas_iounit_pg0
);
3748 * _scsih_expander_add - creating expander object
3749 * @ioc: per adapter object
3750 * @handle: expander handle
3752 * Creating expander object, stored in ioc->sas_expander_list.
3754 * Return 0 for success, else error.
3757 _scsih_expander_add(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
3759 struct _sas_node
*sas_expander
;
3760 Mpi2ConfigReply_t mpi_reply
;
3761 Mpi2ExpanderPage0_t expander_pg0
;
3762 Mpi2ExpanderPage1_t expander_pg1
;
3763 Mpi2SasEnclosurePage0_t enclosure_pg0
;
3766 __le64 sas_address
, sas_address_parent
= 0;
3768 unsigned long flags
;
3769 struct _sas_port
*mpt2sas_port
= NULL
;
3775 if (ioc
->shost_recovery
)
3778 if ((mpt2sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
3779 MPI2_SAS_EXPAND_PGAD_FORM_HNDL
, handle
))) {
3780 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3781 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3785 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
3786 MPI2_IOCSTATUS_MASK
;
3787 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
3788 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3789 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3793 /* handle out of order topology events */
3794 parent_handle
= le16_to_cpu(expander_pg0
.ParentDevHandle
);
3795 if (_scsih_get_sas_address(ioc
, parent_handle
, &sas_address_parent
)
3797 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3798 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3801 if (sas_address_parent
!= ioc
->sas_hba
.sas_address
) {
3802 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
3803 sas_expander
= mpt2sas_scsih_expander_find_by_sas_address(ioc
,
3804 sas_address_parent
);
3805 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
3806 if (!sas_expander
) {
3807 rc
= _scsih_expander_add(ioc
, parent_handle
);
3813 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
3814 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
3815 sas_expander
= mpt2sas_scsih_expander_find_by_sas_address(ioc
,
3817 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
3822 sas_expander
= kzalloc(sizeof(struct _sas_node
),
3824 if (!sas_expander
) {
3825 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3826 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3830 sas_expander
->handle
= handle
;
3831 sas_expander
->num_phys
= expander_pg0
.NumPhys
;
3832 sas_expander
->sas_address_parent
= sas_address_parent
;
3833 sas_expander
->sas_address
= sas_address
;
3835 printk(MPT2SAS_INFO_FMT
"expander_add: handle(0x%04x),"
3836 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc
->name
,
3837 handle
, parent_handle
, (unsigned long long)
3838 sas_expander
->sas_address
, sas_expander
->num_phys
);
3840 if (!sas_expander
->num_phys
)
3842 sas_expander
->phy
= kcalloc(sas_expander
->num_phys
,
3843 sizeof(struct _sas_phy
), GFP_KERNEL
);
3844 if (!sas_expander
->phy
) {
3845 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3846 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3851 INIT_LIST_HEAD(&sas_expander
->sas_port_list
);
3852 mpt2sas_port
= mpt2sas_transport_port_add(ioc
, handle
,
3853 sas_address_parent
);
3854 if (!mpt2sas_port
) {
3855 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3856 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3860 sas_expander
->parent_dev
= &mpt2sas_port
->rphy
->dev
;
3862 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++) {
3863 if ((mpt2sas_config_get_expander_pg1(ioc
, &mpi_reply
,
3864 &expander_pg1
, i
, handle
))) {
3865 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3866 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3870 sas_expander
->phy
[i
].handle
= handle
;
3871 sas_expander
->phy
[i
].phy_id
= i
;
3873 if ((mpt2sas_transport_add_expander_phy(ioc
,
3874 &sas_expander
->phy
[i
], expander_pg1
,
3875 sas_expander
->parent_dev
))) {
3876 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3877 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3883 if (sas_expander
->enclosure_handle
) {
3884 if (!(mpt2sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
3885 &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
3886 sas_expander
->enclosure_handle
))) {
3887 sas_expander
->enclosure_logical_id
=
3888 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
3892 _scsih_expander_node_add(ioc
, sas_expander
);
3898 mpt2sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
3899 sas_address_parent
);
3900 kfree(sas_expander
);
3905 * _scsih_done - scsih callback handler.
3906 * @ioc: per adapter object
3907 * @smid: system request message index
3908 * @msix_index: MSIX table index supplied by the OS
3909 * @reply: reply message frame(lower 32bit addr)
3911 * Callback handler when sending internal generated message frames.
3912 * The callback index passed is `ioc->scsih_cb_idx`
3914 * Return 1 meaning mf should be freed from _base_interrupt
3915 * 0 means the mf is freed from this function.
3918 _scsih_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
3920 MPI2DefaultReply_t
*mpi_reply
;
3922 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
3923 if (ioc
->scsih_cmds
.status
== MPT2_CMD_NOT_USED
)
3925 if (ioc
->scsih_cmds
.smid
!= smid
)
3927 ioc
->scsih_cmds
.status
|= MPT2_CMD_COMPLETE
;
3929 memcpy(ioc
->scsih_cmds
.reply
, mpi_reply
,
3930 mpi_reply
->MsgLength
*4);
3931 ioc
->scsih_cmds
.status
|= MPT2_CMD_REPLY_VALID
;
3933 ioc
->scsih_cmds
.status
&= ~MPT2_CMD_PENDING
;
3934 complete(&ioc
->scsih_cmds
.done
);
3939 * _scsih_expander_remove - removing expander object
3940 * @ioc: per adapter object
3941 * @sas_address: expander sas_address
3946 _scsih_expander_remove(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
)
3948 struct _sas_node
*sas_expander
;
3949 unsigned long flags
;
3951 if (ioc
->shost_recovery
)
3954 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
3955 sas_expander
= mpt2sas_scsih_expander_find_by_sas_address(ioc
,
3957 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
3958 _scsih_expander_node_remove(ioc
, sas_expander
);
3962 * _scsih_check_access_status - check access flags
3963 * @ioc: per adapter object
3964 * @sas_address: sas address
3965 * @handle: sas device handle
3966 * @access_flags: errors returned during discovery of the device
3968 * Return 0 for success, else failure
3971 _scsih_check_access_status(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
,
3972 u16 handle
, u8 access_status
)
3977 switch (access_status
) {
3978 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS
:
3979 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION
:
3982 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED
:
3983 desc
= "sata capability failed";
3985 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT
:
3986 desc
= "sata affiliation conflict";
3988 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE
:
3989 desc
= "route not addressable";
3991 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE
:
3992 desc
= "smp error not addressable";
3994 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED
:
3995 desc
= "device blocked";
3997 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED
:
3998 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN
:
3999 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT
:
4000 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG
:
4001 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION
:
4002 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER
:
4003 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN
:
4004 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN
:
4005 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN
:
4006 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION
:
4007 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE
:
4008 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX
:
4009 desc
= "sata initialization failed";
4019 printk(MPT2SAS_ERR_FMT
"discovery errors(%s): sas_address(0x%016llx), "
4020 "handle(0x%04x)\n", ioc
->name
, desc
,
4021 (unsigned long long)sas_address
, handle
);
4026 _scsih_check_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
4028 Mpi2ConfigReply_t mpi_reply
;
4029 Mpi2SasDevicePage0_t sas_device_pg0
;
4030 struct _sas_device
*sas_device
;
4032 unsigned long flags
;
4034 struct scsi_target
*starget
;
4035 struct MPT2SAS_TARGET
*sas_target_priv_data
;
4038 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
4039 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
)))
4042 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
4043 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
4046 /* check if this is end device */
4047 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
4048 if (!(_scsih_is_end_device(device_info
)))
4051 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4052 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
4053 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
4057 printk(MPT2SAS_ERR_FMT
"device is not present "
4058 "handle(0x%04x), no sas_device!!!\n", ioc
->name
, handle
);
4059 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4063 if (unlikely(sas_device
->handle
!= handle
)) {
4064 starget
= sas_device
->starget
;
4065 sas_target_priv_data
= starget
->hostdata
;
4066 starget_printk(KERN_INFO
, starget
, "handle changed from(0x%04x)"
4067 " to (0x%04x)!!!\n", sas_device
->handle
, handle
);
4068 sas_target_priv_data
->handle
= handle
;
4069 sas_device
->handle
= handle
;
4071 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4073 /* check if device is present */
4074 if (!(le16_to_cpu(sas_device_pg0
.Flags
) &
4075 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT
)) {
4076 printk(MPT2SAS_ERR_FMT
"device is not present "
4077 "handle(0x%04x), flags!!!\n", ioc
->name
, handle
);
4081 /* check if there were any issues with discovery */
4082 if (_scsih_check_access_status(ioc
, sas_address
, handle
,
4083 sas_device_pg0
.AccessStatus
))
4085 _scsih_ublock_io_device(ioc
, handle
);
4090 * _scsih_add_device - creating sas device object
4091 * @ioc: per adapter object
4092 * @handle: sas device handle
4093 * @phy_num: phy number end device attached to
4094 * @is_pd: is this hidden raid component
4096 * Creating end device object, stored in ioc->sas_device_list.
4098 * Returns 0 for success, non-zero for failure.
4101 _scsih_add_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
, u8 phy_num
, u8 is_pd
)
4103 Mpi2ConfigReply_t mpi_reply
;
4104 Mpi2SasDevicePage0_t sas_device_pg0
;
4105 Mpi2SasEnclosurePage0_t enclosure_pg0
;
4106 struct _sas_device
*sas_device
;
4110 unsigned long flags
;
4112 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
4113 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
4114 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4115 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4119 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4120 MPI2_IOCSTATUS_MASK
;
4121 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4122 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4123 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4127 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
4129 /* check if device is present */
4130 if (!(le16_to_cpu(sas_device_pg0
.Flags
) &
4131 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT
)) {
4132 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4133 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4134 printk(MPT2SAS_ERR_FMT
"Flags = 0x%04x\n",
4135 ioc
->name
, le16_to_cpu(sas_device_pg0
.Flags
));
4139 /* check if there were any issues with discovery */
4140 if (_scsih_check_access_status(ioc
, sas_address
, handle
,
4141 sas_device_pg0
.AccessStatus
))
4144 /* check if this is end device */
4145 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
4146 if (!(_scsih_is_end_device(device_info
))) {
4147 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4148 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4153 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4154 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
4156 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4161 sas_device
= kzalloc(sizeof(struct _sas_device
),
4164 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4165 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4169 sas_device
->handle
= handle
;
4170 if (_scsih_get_sas_address(ioc
, le16_to_cpu
4171 (sas_device_pg0
.ParentDevHandle
),
4172 &sas_device
->sas_address_parent
) != 0)
4173 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4174 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4175 sas_device
->enclosure_handle
=
4176 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
4178 le16_to_cpu(sas_device_pg0
.Slot
);
4179 sas_device
->device_info
= device_info
;
4180 sas_device
->sas_address
= sas_address
;
4181 sas_device
->hidden_raid_component
= is_pd
;
4183 /* get enclosure_logical_id */
4184 if (sas_device
->enclosure_handle
&& !(mpt2sas_config_get_enclosure_pg0(
4185 ioc
, &mpi_reply
, &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
4186 sas_device
->enclosure_handle
)))
4187 sas_device
->enclosure_logical_id
=
4188 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
4190 /* get device name */
4191 sas_device
->device_name
= le64_to_cpu(sas_device_pg0
.DeviceName
);
4193 if (ioc
->wait_for_port_enable_to_complete
)
4194 _scsih_sas_device_init_add(ioc
, sas_device
);
4196 _scsih_sas_device_add(ioc
, sas_device
);
4202 * _scsih_remove_pd_device - removing sas device pd object
4203 * @ioc: per adapter object
4204 * @sas_device_delete: the sas_device object
4206 * For hidden raid components, we do driver-fw handshake from
4207 * hotplug work threads.
4211 _scsih_remove_pd_device(struct MPT2SAS_ADAPTER
*ioc
, struct _sas_device
4214 Mpi2SasIoUnitControlReply_t mpi_reply
;
4215 Mpi2SasIoUnitControlRequest_t mpi_request
;
4216 u16 vol_handle
, handle
;
4218 handle
= sas_device
.handle
;
4219 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: enter: handle(0x%04x),"
4220 " sas_addr(0x%016llx)\n", ioc
->name
, __func__
, handle
,
4221 (unsigned long long) sas_device
.sas_address
));
4223 vol_handle
= sas_device
.volume_handle
;
4226 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"issue target reset: "
4227 "handle(0x%04x)\n", ioc
->name
, vol_handle
));
4228 mpt2sas_scsih_issue_tm(ioc
, vol_handle
, 0, 0, 0,
4229 MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
, 0, 30, NULL
);
4230 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"issue target reset "
4231 "done: handle(0x%04x)\n", ioc
->name
, vol_handle
));
4232 if (ioc
->shost_recovery
)
4235 /* SAS_IO_UNIT_CNTR - send REMOVE_DEVICE */
4236 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"sas_iounit: handle"
4237 "(0x%04x)\n", ioc
->name
, handle
));
4238 memset(&mpi_request
, 0, sizeof(Mpi2SasIoUnitControlRequest_t
));
4239 mpi_request
.Function
= MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
;
4240 mpi_request
.Operation
= MPI2_SAS_OP_REMOVE_DEVICE
;
4241 mpi_request
.DevHandle
= cpu_to_le16(handle
);
4242 if ((mpt2sas_base_sas_iounit_control(ioc
, &mpi_reply
,
4243 &mpi_request
)) != 0)
4244 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4245 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4247 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"sas_iounit: ioc_status"
4248 "(0x%04x), loginfo(0x%08x)\n", ioc
->name
,
4249 le16_to_cpu(mpi_reply
.IOCStatus
),
4250 le32_to_cpu(mpi_reply
.IOCLogInfo
)));
4252 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: exit: handle(0x%04x),"
4253 " sas_addr(0x%016llx)\n", ioc
->name
, __func__
, handle
,
4254 (unsigned long long) sas_device
.sas_address
));
4258 * _scsih_remove_device - removing sas device object
4259 * @ioc: per adapter object
4260 * @sas_device_delete: the sas_device object
4265 _scsih_remove_device(struct MPT2SAS_ADAPTER
*ioc
,
4266 struct _sas_device
*sas_device
)
4268 struct _sas_device sas_device_backup
;
4269 struct MPT2SAS_TARGET
*sas_target_priv_data
;
4274 memcpy(&sas_device_backup
, sas_device
, sizeof(struct _sas_device
));
4275 _scsih_sas_device_remove(ioc
, sas_device
);
4277 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: enter: "
4278 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
, __func__
,
4279 sas_device_backup
.handle
, (unsigned long long)
4280 sas_device_backup
.sas_address
));
4282 if (sas_device_backup
.starget
&& sas_device_backup
.starget
->hostdata
) {
4283 sas_target_priv_data
= sas_device_backup
.starget
->hostdata
;
4284 sas_target_priv_data
->deleted
= 1;
4287 if (sas_device_backup
.hidden_raid_component
)
4288 _scsih_remove_pd_device(ioc
, sas_device_backup
);
4290 _scsih_ublock_io_device(ioc
, sas_device_backup
.handle
);
4292 mpt2sas_transport_port_remove(ioc
, sas_device_backup
.sas_address
,
4293 sas_device_backup
.sas_address_parent
);
4295 printk(MPT2SAS_INFO_FMT
"removing handle(0x%04x), sas_addr"
4296 "(0x%016llx)\n", ioc
->name
, sas_device_backup
.handle
,
4297 (unsigned long long) sas_device_backup
.sas_address
);
4299 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: exit: "
4300 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
, __func__
,
4301 sas_device_backup
.handle
, (unsigned long long)
4302 sas_device_backup
.sas_address
));
4305 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4307 * _scsih_sas_topology_change_event_debug - debug for topology event
4308 * @ioc: per adapter object
4309 * @event_data: event data payload
4313 _scsih_sas_topology_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
4314 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
4320 char *status_str
= NULL
;
4321 u8 link_rate
, prev_link_rate
;
4323 switch (event_data
->ExpStatus
) {
4324 case MPI2_EVENT_SAS_TOPO_ES_ADDED
:
4327 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
:
4328 status_str
= "remove";
4330 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING
:
4332 status_str
= "responding";
4334 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
:
4335 status_str
= "remove delay";
4338 status_str
= "unknown status";
4341 printk(MPT2SAS_DEBUG_FMT
"sas topology change: (%s)\n",
4342 ioc
->name
, status_str
);
4343 printk(KERN_DEBUG
"\thandle(0x%04x), enclosure_handle(0x%04x) "
4344 "start_phy(%02d), count(%d)\n",
4345 le16_to_cpu(event_data
->ExpanderDevHandle
),
4346 le16_to_cpu(event_data
->EnclosureHandle
),
4347 event_data
->StartPhyNum
, event_data
->NumEntries
);
4348 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
4349 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
4352 phy_number
= event_data
->StartPhyNum
+ i
;
4353 reason_code
= event_data
->PHY
[i
].PhyStatus
&
4354 MPI2_EVENT_SAS_TOPO_RC_MASK
;
4355 switch (reason_code
) {
4356 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
4357 status_str
= "target add";
4359 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
4360 status_str
= "target remove";
4362 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
:
4363 status_str
= "delay target remove";
4365 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
4366 status_str
= "link rate change";
4368 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE
:
4369 status_str
= "target responding";
4372 status_str
= "unknown";
4375 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
4376 prev_link_rate
= event_data
->PHY
[i
].LinkRate
& 0xF;
4377 printk(KERN_DEBUG
"\tphy(%02d), attached_handle(0x%04x): %s:"
4378 " link rate: new(0x%02x), old(0x%02x)\n", phy_number
,
4379 handle
, status_str
, link_rate
, prev_link_rate
);
4386 * _scsih_sas_topology_change_event - handle topology changes
4387 * @ioc: per adapter object
4388 * @fw_event: The fw_event_work object
4393 _scsih_sas_topology_change_event(struct MPT2SAS_ADAPTER
*ioc
,
4394 struct fw_event_work
*fw_event
)
4397 u16 parent_handle
, handle
;
4400 struct _sas_node
*sas_expander
;
4401 struct _sas_device
*sas_device
;
4403 unsigned long flags
;
4404 u8 link_rate
, prev_link_rate
;
4405 Mpi2EventDataSasTopologyChangeList_t
*event_data
= fw_event
->event_data
;
4407 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4408 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
4409 _scsih_sas_topology_change_event_debug(ioc
, event_data
);
4412 if (ioc
->shost_recovery
|| ioc
->remove_host
)
4415 if (!ioc
->sas_hba
.num_phys
)
4416 _scsih_sas_host_add(ioc
);
4418 _scsih_sas_host_refresh(ioc
);
4420 if (fw_event
->ignore
) {
4421 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"ignoring expander "
4422 "event\n", ioc
->name
));
4426 parent_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
4428 /* handle expander add */
4429 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_ADDED
)
4430 if (_scsih_expander_add(ioc
, parent_handle
) != 0)
4433 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
4434 sas_expander
= mpt2sas_scsih_expander_find_by_handle(ioc
,
4436 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
4438 sas_address
= sas_expander
->sas_address
;
4439 else if (parent_handle
< ioc
->sas_hba
.num_phys
)
4440 sas_address
= ioc
->sas_hba
.sas_address
;
4444 /* handle siblings events */
4445 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
4446 if (fw_event
->ignore
) {
4447 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"ignoring "
4448 "expander event\n", ioc
->name
));
4451 if (ioc
->shost_recovery
|| ioc
->remove_host
)
4453 phy_number
= event_data
->StartPhyNum
+ i
;
4454 reason_code
= event_data
->PHY
[i
].PhyStatus
&
4455 MPI2_EVENT_SAS_TOPO_RC_MASK
;
4456 if ((event_data
->PHY
[i
].PhyStatus
&
4457 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT
) && (reason_code
!=
4458 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
))
4460 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
4463 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
4464 prev_link_rate
= event_data
->PHY
[i
].LinkRate
& 0xF;
4465 switch (reason_code
) {
4466 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
4468 if (link_rate
== prev_link_rate
)
4471 mpt2sas_transport_update_links(ioc
, sas_address
,
4472 handle
, phy_number
, link_rate
);
4474 if (link_rate
< MPI2_SAS_NEG_LINK_RATE_1_5
)
4477 _scsih_check_device(ioc
, handle
);
4479 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
4481 mpt2sas_transport_update_links(ioc
, sas_address
,
4482 handle
, phy_number
, link_rate
);
4484 _scsih_add_device(ioc
, handle
, phy_number
, 0);
4486 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
4488 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4489 sas_device
= _scsih_sas_device_find_by_handle(ioc
,
4492 spin_unlock_irqrestore(&ioc
->sas_device_lock
,
4496 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4497 _scsih_remove_device(ioc
, sas_device
);
4502 /* handle expander removal */
4503 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
&&
4505 _scsih_expander_remove(ioc
, sas_address
);
4509 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4511 * _scsih_sas_device_status_change_event_debug - debug for device event
4512 * @event_data: event data payload
4518 _scsih_sas_device_status_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
4519 Mpi2EventDataSasDeviceStatusChange_t
*event_data
)
4521 char *reason_str
= NULL
;
4523 switch (event_data
->ReasonCode
) {
4524 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
:
4525 reason_str
= "smart data";
4527 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED
:
4528 reason_str
= "unsupported device discovered";
4530 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
:
4531 reason_str
= "internal device reset";
4533 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL
:
4534 reason_str
= "internal task abort";
4536 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL
:
4537 reason_str
= "internal task abort set";
4539 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL
:
4540 reason_str
= "internal clear task set";
4542 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL
:
4543 reason_str
= "internal query task";
4545 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE
:
4546 reason_str
= "sata init failure";
4548 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
:
4549 reason_str
= "internal device reset complete";
4551 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL
:
4552 reason_str
= "internal task abort complete";
4554 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION
:
4555 reason_str
= "internal async notification";
4557 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY
:
4558 reason_str
= "expander reduced functionality";
4560 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY
:
4561 reason_str
= "expander reduced functionality complete";
4564 reason_str
= "unknown reason";
4567 printk(MPT2SAS_DEBUG_FMT
"device status change: (%s)\n"
4568 "\thandle(0x%04x), sas address(0x%016llx)", ioc
->name
,
4569 reason_str
, le16_to_cpu(event_data
->DevHandle
),
4570 (unsigned long long)le64_to_cpu(event_data
->SASAddress
));
4571 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
)
4572 printk(MPT2SAS_DEBUG_FMT
", ASC(0x%x), ASCQ(0x%x)\n", ioc
->name
,
4573 event_data
->ASC
, event_data
->ASCQ
);
4574 printk(KERN_INFO
"\n");
4579 * _scsih_sas_device_status_change_event - handle device status change
4580 * @ioc: per adapter object
4581 * @fw_event: The fw_event_work object
4587 _scsih_sas_device_status_change_event(struct MPT2SAS_ADAPTER
*ioc
,
4588 struct fw_event_work
*fw_event
)
4590 struct MPT2SAS_TARGET
*target_priv_data
;
4591 struct _sas_device
*sas_device
;
4593 unsigned long flags
;
4594 Mpi2EventDataSasDeviceStatusChange_t
*event_data
=
4595 fw_event
->event_data
;
4597 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4598 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
4599 _scsih_sas_device_status_change_event_debug(ioc
,
4603 if (event_data
->ReasonCode
!=
4604 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
&&
4605 event_data
->ReasonCode
!=
4606 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
)
4609 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4610 sas_address
= le64_to_cpu(event_data
->SASAddress
);
4611 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
4613 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4615 if (!sas_device
|| !sas_device
->starget
)
4618 target_priv_data
= sas_device
->starget
->hostdata
;
4619 if (!target_priv_data
)
4622 if (event_data
->ReasonCode
==
4623 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
)
4624 target_priv_data
->tm_busy
= 1;
4626 target_priv_data
->tm_busy
= 0;
4629 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4631 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure event
4632 * @ioc: per adapter object
4633 * @event_data: event data payload
4639 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
4640 Mpi2EventDataSasEnclDevStatusChange_t
*event_data
)
4642 char *reason_str
= NULL
;
4644 switch (event_data
->ReasonCode
) {
4645 case MPI2_EVENT_SAS_ENCL_RC_ADDED
:
4646 reason_str
= "enclosure add";
4648 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING
:
4649 reason_str
= "enclosure remove";
4652 reason_str
= "unknown reason";
4656 printk(MPT2SAS_DEBUG_FMT
"enclosure status change: (%s)\n"
4657 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
4658 " number slots(%d)\n", ioc
->name
, reason_str
,
4659 le16_to_cpu(event_data
->EnclosureHandle
),
4660 (unsigned long long)le64_to_cpu(event_data
->EnclosureLogicalID
),
4661 le16_to_cpu(event_data
->StartSlot
));
4666 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
4667 * @ioc: per adapter object
4668 * @fw_event: The fw_event_work object
4674 _scsih_sas_enclosure_dev_status_change_event(struct MPT2SAS_ADAPTER
*ioc
,
4675 struct fw_event_work
*fw_event
)
4677 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4678 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
4679 _scsih_sas_enclosure_dev_status_change_event_debug(ioc
,
4680 fw_event
->event_data
);
4685 * _scsih_sas_broadcast_primative_event - handle broadcast events
4686 * @ioc: per adapter object
4687 * @fw_event: The fw_event_work object
4693 _scsih_sas_broadcast_primative_event(struct MPT2SAS_ADAPTER
*ioc
,
4694 struct fw_event_work
*fw_event
)
4696 struct scsi_cmnd
*scmd
;
4699 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
4700 u32 termination_count
;
4702 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
4703 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4704 Mpi2EventDataSasBroadcastPrimitive_t
*event_data
= fw_event
->event_data
;
4707 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"broadcast primative: "
4708 "phy number(%d), width(%d)\n", ioc
->name
, event_data
->PhyNum
,
4709 event_data
->PortWidth
));
4710 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: enter\n", ioc
->name
,
4713 termination_count
= 0;
4715 mpi_reply
= ioc
->tm_cmds
.reply
;
4716 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
4717 scmd
= _scsih_scsi_lookup_get(ioc
, smid
);
4720 sas_device_priv_data
= scmd
->device
->hostdata
;
4721 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
)
4723 /* skip hidden raid components */
4724 if (sas_device_priv_data
->sas_target
->flags
&
4725 MPT_TARGET_FLAGS_RAID_COMPONENT
)
4728 if (sas_device_priv_data
->sas_target
->flags
&
4729 MPT_TARGET_FLAGS_VOLUME
)
4732 handle
= sas_device_priv_data
->sas_target
->handle
;
4733 lun
= sas_device_priv_data
->lun
;
4736 mpt2sas_scsih_issue_tm(ioc
, handle
, 0, 0, lun
,
4737 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK
, smid
, 30, NULL
);
4738 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
4739 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
)
4740 & MPI2_IOCSTATUS_MASK
;
4741 if ((ioc_status
== MPI2_IOCSTATUS_SUCCESS
) &&
4742 (mpi_reply
->ResponseCode
==
4743 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
||
4744 mpi_reply
->ResponseCode
==
4745 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
))
4748 mpt2sas_scsih_issue_tm(ioc
, handle
, 0, 0, lun
,
4749 MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET
, 0, 30, NULL
);
4750 termination_count
+= le32_to_cpu(mpi_reply
->TerminationCount
);
4752 ioc
->broadcast_aen_busy
= 0;
4754 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
4755 "%s - exit, query_count = %d termination_count = %d\n",
4756 ioc
->name
, __func__
, query_count
, termination_count
));
4760 * _scsih_sas_discovery_event - handle discovery events
4761 * @ioc: per adapter object
4762 * @fw_event: The fw_event_work object
4768 _scsih_sas_discovery_event(struct MPT2SAS_ADAPTER
*ioc
,
4769 struct fw_event_work
*fw_event
)
4771 Mpi2EventDataSasDiscovery_t
*event_data
= fw_event
->event_data
;
4773 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4774 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
) {
4775 printk(MPT2SAS_DEBUG_FMT
"discovery event: (%s)", ioc
->name
,
4776 (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
) ?
4778 if (event_data
->DiscoveryStatus
)
4779 printk("discovery_status(0x%08x)",
4780 le32_to_cpu(event_data
->DiscoveryStatus
));
4785 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
&&
4786 !ioc
->sas_hba
.num_phys
)
4787 _scsih_sas_host_add(ioc
);
4791 * _scsih_reprobe_lun - reprobing lun
4792 * @sdev: scsi device struct
4793 * @no_uld_attach: sdev->no_uld_attach flag setting
4797 _scsih_reprobe_lun(struct scsi_device
*sdev
, void *no_uld_attach
)
4801 sdev
->no_uld_attach
= no_uld_attach
? 1 : 0;
4802 sdev_printk(KERN_INFO
, sdev
, "%s raid component\n",
4803 sdev
->no_uld_attach
? "hidding" : "exposing");
4804 rc
= scsi_device_reprobe(sdev
);
4808 * _scsih_reprobe_target - reprobing target
4809 * @starget: scsi target struct
4810 * @no_uld_attach: sdev->no_uld_attach flag setting
4812 * Note: no_uld_attach flag determines whether the disk device is attached
4813 * to block layer. A value of `1` means to not attach.
4816 _scsih_reprobe_target(struct scsi_target
*starget
, int no_uld_attach
)
4818 struct MPT2SAS_TARGET
*sas_target_priv_data
= starget
->hostdata
;
4821 sas_target_priv_data
->flags
|= MPT_TARGET_FLAGS_RAID_COMPONENT
;
4823 sas_target_priv_data
->flags
&= ~MPT_TARGET_FLAGS_RAID_COMPONENT
;
4825 starget_for_each_device(starget
, no_uld_attach
? (void *)1 : NULL
,
4826 _scsih_reprobe_lun
);
4829 * _scsih_sas_volume_add - add new volume
4830 * @ioc: per adapter object
4831 * @element: IR config element data
4837 _scsih_sas_volume_add(struct MPT2SAS_ADAPTER
*ioc
,
4838 Mpi2EventIrConfigElement_t
*element
)
4840 struct _raid_device
*raid_device
;
4841 unsigned long flags
;
4843 u16 handle
= le16_to_cpu(element
->VolDevHandle
);
4846 mpt2sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
4848 printk(MPT2SAS_ERR_FMT
4849 "failure at %s:%d/%s()!\n", ioc
->name
,
4850 __FILE__
, __LINE__
, __func__
);
4854 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
4855 raid_device
= _scsih_raid_device_find_by_wwid(ioc
, wwid
);
4856 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
4861 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
4863 printk(MPT2SAS_ERR_FMT
4864 "failure at %s:%d/%s()!\n", ioc
->name
,
4865 __FILE__
, __LINE__
, __func__
);
4869 raid_device
->id
= ioc
->sas_id
++;
4870 raid_device
->channel
= RAID_CHANNEL
;
4871 raid_device
->handle
= handle
;
4872 raid_device
->wwid
= wwid
;
4873 _scsih_raid_device_add(ioc
, raid_device
);
4874 if (!ioc
->wait_for_port_enable_to_complete
) {
4875 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
4876 raid_device
->id
, 0);
4878 _scsih_raid_device_remove(ioc
, raid_device
);
4880 _scsih_determine_boot_device(ioc
, raid_device
, 1);
4884 * _scsih_sas_volume_delete - delete volume
4885 * @ioc: per adapter object
4886 * @element: IR config element data
4892 _scsih_sas_volume_delete(struct MPT2SAS_ADAPTER
*ioc
,
4893 Mpi2EventIrConfigElement_t
*element
)
4895 struct _raid_device
*raid_device
;
4896 u16 handle
= le16_to_cpu(element
->VolDevHandle
);
4897 unsigned long flags
;
4898 struct MPT2SAS_TARGET
*sas_target_priv_data
;
4900 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
4901 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
4902 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
4905 if (raid_device
->starget
) {
4906 sas_target_priv_data
= raid_device
->starget
->hostdata
;
4907 sas_target_priv_data
->deleted
= 1;
4908 scsi_remove_target(&raid_device
->starget
->dev
);
4910 _scsih_raid_device_remove(ioc
, raid_device
);
4914 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
4915 * @ioc: per adapter object
4916 * @element: IR config element data
4922 _scsih_sas_pd_expose(struct MPT2SAS_ADAPTER
*ioc
,
4923 Mpi2EventIrConfigElement_t
*element
)
4925 struct _sas_device
*sas_device
;
4926 unsigned long flags
;
4927 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
4929 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4930 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
4931 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4935 /* exposing raid component */
4936 sas_device
->volume_handle
= 0;
4937 sas_device
->volume_wwid
= 0;
4938 sas_device
->hidden_raid_component
= 0;
4939 _scsih_reprobe_target(sas_device
->starget
, 0);
4943 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
4944 * @ioc: per adapter object
4945 * @element: IR config element data
4951 _scsih_sas_pd_hide(struct MPT2SAS_ADAPTER
*ioc
,
4952 Mpi2EventIrConfigElement_t
*element
)
4954 struct _sas_device
*sas_device
;
4955 unsigned long flags
;
4956 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
4958 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4959 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
4960 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4964 /* hiding raid component */
4965 mpt2sas_config_get_volume_handle(ioc
, handle
,
4966 &sas_device
->volume_handle
);
4967 mpt2sas_config_get_volume_wwid(ioc
, sas_device
->volume_handle
,
4968 &sas_device
->volume_wwid
);
4969 sas_device
->hidden_raid_component
= 1;
4970 _scsih_reprobe_target(sas_device
->starget
, 1);
4974 * _scsih_sas_pd_delete - delete pd component
4975 * @ioc: per adapter object
4976 * @element: IR config element data
4982 _scsih_sas_pd_delete(struct MPT2SAS_ADAPTER
*ioc
,
4983 Mpi2EventIrConfigElement_t
*element
)
4985 struct _sas_device
*sas_device
;
4986 unsigned long flags
;
4987 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
4989 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4990 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
4991 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4994 _scsih_remove_device(ioc
, sas_device
);
4998 * _scsih_sas_pd_add - remove pd component
4999 * @ioc: per adapter object
5000 * @element: IR config element data
5006 _scsih_sas_pd_add(struct MPT2SAS_ADAPTER
*ioc
,
5007 Mpi2EventIrConfigElement_t
*element
)
5009 struct _sas_device
*sas_device
;
5010 unsigned long flags
;
5011 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
5012 Mpi2ConfigReply_t mpi_reply
;
5013 Mpi2SasDevicePage0_t sas_device_pg0
;
5018 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5019 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
5020 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5022 sas_device
->hidden_raid_component
= 1;
5026 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
5027 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
5028 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5029 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5033 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5034 MPI2_IOCSTATUS_MASK
;
5035 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5036 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5037 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5041 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
5042 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
5043 mpt2sas_transport_update_links(ioc
, sas_address
, handle
,
5044 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
5046 _scsih_add_device(ioc
, handle
, 0, 1);
5049 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5051 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
5052 * @ioc: per adapter object
5053 * @event_data: event data payload
5059 _scsih_sas_ir_config_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
5060 Mpi2EventDataIrConfigChangeList_t
*event_data
)
5062 Mpi2EventIrConfigElement_t
*element
;
5065 char *reason_str
= NULL
, *element_str
= NULL
;
5067 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
5069 printk(MPT2SAS_DEBUG_FMT
"raid config change: (%s), elements(%d)\n",
5070 ioc
->name
, (le32_to_cpu(event_data
->Flags
) &
5071 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ?
5072 "foreign" : "native", event_data
->NumElements
);
5073 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
5074 switch (element
->ReasonCode
) {
5075 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
5078 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
5079 reason_str
= "remove";
5081 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE
:
5082 reason_str
= "no change";
5084 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
5085 reason_str
= "hide";
5087 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
5088 reason_str
= "unhide";
5090 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
5091 reason_str
= "volume_created";
5093 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
5094 reason_str
= "volume_deleted";
5096 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
5097 reason_str
= "pd_created";
5099 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
5100 reason_str
= "pd_deleted";
5103 reason_str
= "unknown reason";
5106 element_type
= le16_to_cpu(element
->ElementFlags
) &
5107 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK
;
5108 switch (element_type
) {
5109 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT
:
5110 element_str
= "volume";
5112 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT
:
5113 element_str
= "phys disk";
5115 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT
:
5116 element_str
= "hot spare";
5119 element_str
= "unknown element";
5122 printk(KERN_DEBUG
"\t(%s:%s), vol handle(0x%04x), "
5123 "pd handle(0x%04x), pd num(0x%02x)\n", element_str
,
5124 reason_str
, le16_to_cpu(element
->VolDevHandle
),
5125 le16_to_cpu(element
->PhysDiskDevHandle
),
5126 element
->PhysDiskNum
);
5132 * _scsih_sas_ir_config_change_event - handle ir configuration change events
5133 * @ioc: per adapter object
5134 * @fw_event: The fw_event_work object
5140 _scsih_sas_ir_config_change_event(struct MPT2SAS_ADAPTER
*ioc
,
5141 struct fw_event_work
*fw_event
)
5143 Mpi2EventIrConfigElement_t
*element
;
5146 Mpi2EventDataIrConfigChangeList_t
*event_data
= fw_event
->event_data
;
5148 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5149 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5150 _scsih_sas_ir_config_change_event_debug(ioc
, event_data
);
5153 foreign_config
= (le32_to_cpu(event_data
->Flags
) &
5154 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ? 1 : 0;
5156 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
5157 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
5159 switch (element
->ReasonCode
) {
5160 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
5161 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
5162 if (!foreign_config
)
5163 _scsih_sas_volume_add(ioc
, element
);
5165 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
5166 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
5167 if (!foreign_config
)
5168 _scsih_sas_volume_delete(ioc
, element
);
5170 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
5171 _scsih_sas_pd_hide(ioc
, element
);
5173 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
5174 _scsih_sas_pd_expose(ioc
, element
);
5176 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
5177 _scsih_sas_pd_add(ioc
, element
);
5179 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
5180 _scsih_sas_pd_delete(ioc
, element
);
5187 * _scsih_sas_ir_volume_event - IR volume event
5188 * @ioc: per adapter object
5189 * @fw_event: The fw_event_work object
5195 _scsih_sas_ir_volume_event(struct MPT2SAS_ADAPTER
*ioc
,
5196 struct fw_event_work
*fw_event
)
5199 unsigned long flags
;
5200 struct _raid_device
*raid_device
;
5204 struct MPT2SAS_TARGET
*sas_target_priv_data
;
5205 Mpi2EventDataIrVolume_t
*event_data
= fw_event
->event_data
;
5207 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED
)
5210 handle
= le16_to_cpu(event_data
->VolDevHandle
);
5211 state
= le32_to_cpu(event_data
->NewValue
);
5212 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: handle(0x%04x), "
5213 "old(0x%08x), new(0x%08x)\n", ioc
->name
, __func__
, handle
,
5214 le32_to_cpu(event_data
->PreviousValue
), state
));
5216 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5217 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
5218 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5221 case MPI2_RAID_VOL_STATE_MISSING
:
5222 case MPI2_RAID_VOL_STATE_FAILED
:
5225 if (raid_device
->starget
) {
5226 sas_target_priv_data
= raid_device
->starget
->hostdata
;
5227 sas_target_priv_data
->deleted
= 1;
5228 scsi_remove_target(&raid_device
->starget
->dev
);
5230 _scsih_raid_device_remove(ioc
, raid_device
);
5233 case MPI2_RAID_VOL_STATE_ONLINE
:
5234 case MPI2_RAID_VOL_STATE_DEGRADED
:
5235 case MPI2_RAID_VOL_STATE_OPTIMAL
:
5239 mpt2sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
5241 printk(MPT2SAS_ERR_FMT
5242 "failure at %s:%d/%s()!\n", ioc
->name
,
5243 __FILE__
, __LINE__
, __func__
);
5247 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
5249 printk(MPT2SAS_ERR_FMT
5250 "failure at %s:%d/%s()!\n", ioc
->name
,
5251 __FILE__
, __LINE__
, __func__
);
5255 raid_device
->id
= ioc
->sas_id
++;
5256 raid_device
->channel
= RAID_CHANNEL
;
5257 raid_device
->handle
= handle
;
5258 raid_device
->wwid
= wwid
;
5259 _scsih_raid_device_add(ioc
, raid_device
);
5260 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
5261 raid_device
->id
, 0);
5263 _scsih_raid_device_remove(ioc
, raid_device
);
5266 case MPI2_RAID_VOL_STATE_INITIALIZING
:
5273 * _scsih_sas_ir_physical_disk_event - PD event
5274 * @ioc: per adapter object
5275 * @fw_event: The fw_event_work object
5281 _scsih_sas_ir_physical_disk_event(struct MPT2SAS_ADAPTER
*ioc
,
5282 struct fw_event_work
*fw_event
)
5284 u16 handle
, parent_handle
;
5286 struct _sas_device
*sas_device
;
5287 unsigned long flags
;
5288 Mpi2ConfigReply_t mpi_reply
;
5289 Mpi2SasDevicePage0_t sas_device_pg0
;
5291 Mpi2EventDataIrPhysicalDisk_t
*event_data
= fw_event
->event_data
;
5294 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED
)
5297 handle
= le16_to_cpu(event_data
->PhysDiskDevHandle
);
5298 state
= le32_to_cpu(event_data
->NewValue
);
5300 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: handle(0x%04x), "
5301 "old(0x%08x), new(0x%08x)\n", ioc
->name
, __func__
, handle
,
5302 le32_to_cpu(event_data
->PreviousValue
), state
));
5304 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5305 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
5306 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5309 case MPI2_RAID_PD_STATE_ONLINE
:
5310 case MPI2_RAID_PD_STATE_DEGRADED
:
5311 case MPI2_RAID_PD_STATE_REBUILDING
:
5312 case MPI2_RAID_PD_STATE_OPTIMAL
:
5314 sas_device
->hidden_raid_component
= 1;
5318 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
5319 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
5321 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5322 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5326 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5327 MPI2_IOCSTATUS_MASK
;
5328 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5329 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5330 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5334 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
5335 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
5336 mpt2sas_transport_update_links(ioc
, sas_address
, handle
,
5337 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
5339 _scsih_add_device(ioc
, handle
, 0, 1);
5343 case MPI2_RAID_PD_STATE_OFFLINE
:
5344 case MPI2_RAID_PD_STATE_NOT_CONFIGURED
:
5345 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE
:
5346 case MPI2_RAID_PD_STATE_HOT_SPARE
:
5352 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5354 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
5355 * @ioc: per adapter object
5356 * @event_data: event data payload
5362 _scsih_sas_ir_operation_status_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
5363 Mpi2EventDataIrOperationStatus_t
*event_data
)
5365 char *reason_str
= NULL
;
5367 switch (event_data
->RAIDOperation
) {
5368 case MPI2_EVENT_IR_RAIDOP_RESYNC
:
5369 reason_str
= "resync";
5371 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION
:
5372 reason_str
= "online capacity expansion";
5374 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK
:
5375 reason_str
= "consistency check";
5377 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT
:
5378 reason_str
= "background init";
5380 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT
:
5381 reason_str
= "make data consistent";
5388 printk(MPT2SAS_INFO_FMT
"raid operational status: (%s)"
5389 "\thandle(0x%04x), percent complete(%d)\n",
5390 ioc
->name
, reason_str
,
5391 le16_to_cpu(event_data
->VolDevHandle
),
5392 event_data
->PercentComplete
);
5397 * _scsih_sas_ir_operation_status_event - handle RAID operation events
5398 * @ioc: per adapter object
5399 * @fw_event: The fw_event_work object
5405 _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER
*ioc
,
5406 struct fw_event_work
*fw_event
)
5408 Mpi2EventDataIrOperationStatus_t
*event_data
= fw_event
->event_data
;
5409 static struct _raid_device
*raid_device
;
5410 unsigned long flags
;
5413 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5414 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5415 _scsih_sas_ir_operation_status_event_debug(ioc
,
5419 /* code added for raid transport support */
5420 if (event_data
->RAIDOperation
== MPI2_EVENT_IR_RAIDOP_RESYNC
) {
5422 handle
= le16_to_cpu(event_data
->VolDevHandle
);
5424 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5425 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
5426 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5431 if (event_data
->RAIDOperation
== MPI2_EVENT_IR_RAIDOP_RESYNC
)
5432 raid_device
->percent_complete
=
5433 event_data
->PercentComplete
;
5438 * _scsih_task_set_full - handle task set full
5439 * @ioc: per adapter object
5440 * @fw_event: The fw_event_work object
5443 * Throttle back qdepth.
5446 _scsih_task_set_full(struct MPT2SAS_ADAPTER
*ioc
, struct fw_event_work
5449 unsigned long flags
;
5450 struct _sas_device
*sas_device
;
5451 static struct _raid_device
*raid_device
;
5452 struct scsi_device
*sdev
;
5458 Mpi2EventDataTaskSetFull_t
*event_data
= fw_event
->event_data
;
5460 current_depth
= le16_to_cpu(event_data
->CurrentDepth
);
5461 handle
= le16_to_cpu(event_data
->DevHandle
);
5462 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5463 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
5465 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5468 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5469 id
= sas_device
->id
;
5470 channel
= sas_device
->channel
;
5471 sas_address
= sas_device
->sas_address
;
5473 /* if hidden raid component, then change to volume characteristics */
5474 if (sas_device
->hidden_raid_component
&& sas_device
->volume_handle
) {
5475 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5476 raid_device
= _scsih_raid_device_find_by_handle(
5477 ioc
, sas_device
->volume_handle
);
5478 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5480 id
= raid_device
->id
;
5481 channel
= raid_device
->channel
;
5482 handle
= raid_device
->handle
;
5483 sas_address
= raid_device
->wwid
;
5487 if (ioc
->logging_level
& MPT_DEBUG_TASK_SET_FULL
)
5488 starget_printk(KERN_DEBUG
, sas_device
->starget
, "task set "
5489 "full: handle(0x%04x), sas_addr(0x%016llx), depth(%d)\n",
5490 handle
, (unsigned long long)sas_address
, current_depth
);
5492 shost_for_each_device(sdev
, ioc
->shost
) {
5493 if (sdev
->id
== id
&& sdev
->channel
== channel
) {
5494 if (current_depth
> sdev
->queue_depth
) {
5495 if (ioc
->logging_level
&
5496 MPT_DEBUG_TASK_SET_FULL
)
5497 sdev_printk(KERN_INFO
, sdev
, "strange "
5498 "observation, the queue depth is"
5499 " (%d) meanwhile fw queue depth "
5500 "is (%d)\n", sdev
->queue_depth
,
5504 depth
= scsi_track_queue_full(sdev
,
5507 sdev_printk(KERN_INFO
, sdev
, "Queue depth "
5508 "reduced to (%d)\n", depth
);
5510 sdev_printk(KERN_INFO
, sdev
, "Tagged Command "
5511 "Queueing is being disabled\n");
5512 else if (depth
== 0)
5513 if (ioc
->logging_level
&
5514 MPT_DEBUG_TASK_SET_FULL
)
5515 sdev_printk(KERN_INFO
, sdev
,
5516 "Queue depth not changed yet\n");
5522 * _scsih_prep_device_scan - initialize parameters prior to device scan
5523 * @ioc: per adapter object
5525 * Set the deleted flag prior to device scan. If the device is found during
5526 * the scan, then we clear the deleted flag.
5529 _scsih_prep_device_scan(struct MPT2SAS_ADAPTER
*ioc
)
5531 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
5532 struct scsi_device
*sdev
;
5534 shost_for_each_device(sdev
, ioc
->shost
) {
5535 sas_device_priv_data
= sdev
->hostdata
;
5536 if (sas_device_priv_data
&& sas_device_priv_data
->sas_target
)
5537 sas_device_priv_data
->sas_target
->deleted
= 1;
5542 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
5543 * @ioc: per adapter object
5544 * @sas_address: sas address
5545 * @slot: enclosure slot id
5546 * @handle: device handle
5548 * After host reset, find out whether devices are still responding.
5549 * Used in _scsi_remove_unresponsive_sas_devices.
5554 _scsih_mark_responding_sas_device(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
,
5555 u16 slot
, u16 handle
)
5557 struct MPT2SAS_TARGET
*sas_target_priv_data
;
5558 struct scsi_target
*starget
;
5559 struct _sas_device
*sas_device
;
5560 unsigned long flags
;
5562 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5563 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
) {
5564 if (sas_device
->sas_address
== sas_address
&&
5565 sas_device
->slot
== slot
&& sas_device
->starget
) {
5566 sas_device
->responding
= 1;
5567 starget
= sas_device
->starget
;
5568 if (starget
&& starget
->hostdata
) {
5569 sas_target_priv_data
= starget
->hostdata
;
5570 sas_target_priv_data
->tm_busy
= 0;
5571 sas_target_priv_data
->deleted
= 0;
5573 sas_target_priv_data
= NULL
;
5574 starget_printk(KERN_INFO
, sas_device
->starget
,
5575 "handle(0x%04x), sas_addr(0x%016llx), enclosure "
5576 "logical id(0x%016llx), slot(%d)\n", handle
,
5577 (unsigned long long)sas_device
->sas_address
,
5578 (unsigned long long)
5579 sas_device
->enclosure_logical_id
,
5581 if (sas_device
->handle
== handle
)
5583 printk(KERN_INFO
"\thandle changed from(0x%04x)!!!\n",
5584 sas_device
->handle
);
5585 sas_device
->handle
= handle
;
5586 if (sas_target_priv_data
)
5587 sas_target_priv_data
->handle
= handle
;
5592 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5596 * _scsih_search_responding_sas_devices -
5597 * @ioc: per adapter object
5599 * After host reset, find out whether devices are still responding.
5605 _scsih_search_responding_sas_devices(struct MPT2SAS_ADAPTER
*ioc
)
5607 Mpi2SasDevicePage0_t sas_device_pg0
;
5608 Mpi2ConfigReply_t mpi_reply
;
5615 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
, __func__
);
5617 if (list_empty(&ioc
->sas_device_list
))
5621 while (!(mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
5622 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
,
5624 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5625 MPI2_IOCSTATUS_MASK
;
5626 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
5628 handle
= le16_to_cpu(sas_device_pg0
.DevHandle
);
5629 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
5630 if (!(_scsih_is_end_device(device_info
)))
5632 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
5633 slot
= le16_to_cpu(sas_device_pg0
.Slot
);
5634 _scsih_mark_responding_sas_device(ioc
, sas_address
, slot
,
5640 * _scsih_mark_responding_raid_device - mark a raid_device as responding
5641 * @ioc: per adapter object
5642 * @wwid: world wide identifier for raid volume
5643 * @handle: device handle
5645 * After host reset, find out whether devices are still responding.
5646 * Used in _scsi_remove_unresponsive_raid_devices.
5651 _scsih_mark_responding_raid_device(struct MPT2SAS_ADAPTER
*ioc
, u64 wwid
,
5654 struct MPT2SAS_TARGET
*sas_target_priv_data
;
5655 struct scsi_target
*starget
;
5656 struct _raid_device
*raid_device
;
5657 unsigned long flags
;
5659 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5660 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
5661 if (raid_device
->wwid
== wwid
&& raid_device
->starget
) {
5662 starget
= raid_device
->starget
;
5663 if (starget
&& starget
->hostdata
) {
5664 sas_target_priv_data
= starget
->hostdata
;
5665 sas_target_priv_data
->deleted
= 0;
5667 sas_target_priv_data
= NULL
;
5668 raid_device
->responding
= 1;
5669 starget_printk(KERN_INFO
, raid_device
->starget
,
5670 "handle(0x%04x), wwid(0x%016llx)\n", handle
,
5671 (unsigned long long)raid_device
->wwid
);
5672 if (raid_device
->handle
== handle
)
5674 printk(KERN_INFO
"\thandle changed from(0x%04x)!!!\n",
5675 raid_device
->handle
);
5676 raid_device
->handle
= handle
;
5677 if (sas_target_priv_data
)
5678 sas_target_priv_data
->handle
= handle
;
5683 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5687 * _scsih_search_responding_raid_devices -
5688 * @ioc: per adapter object
5690 * After host reset, find out whether devices are still responding.
5696 _scsih_search_responding_raid_devices(struct MPT2SAS_ADAPTER
*ioc
)
5698 Mpi2RaidVolPage1_t volume_pg1
;
5699 Mpi2ConfigReply_t mpi_reply
;
5703 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
, __func__
);
5705 if (list_empty(&ioc
->raid_device_list
))
5709 while (!(mpt2sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
5710 &volume_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
5711 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5712 MPI2_IOCSTATUS_MASK
;
5713 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
5715 handle
= le16_to_cpu(volume_pg1
.DevHandle
);
5716 _scsih_mark_responding_raid_device(ioc
,
5717 le64_to_cpu(volume_pg1
.WWID
), handle
);
5722 * _scsih_mark_responding_expander - mark a expander as responding
5723 * @ioc: per adapter object
5724 * @sas_address: sas address
5727 * After host reset, find out whether devices are still responding.
5728 * Used in _scsi_remove_unresponsive_expanders.
5733 _scsih_mark_responding_expander(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
,
5736 struct _sas_node
*sas_expander
;
5737 unsigned long flags
;
5740 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5741 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
5742 if (sas_expander
->sas_address
!= sas_address
)
5744 sas_expander
->responding
= 1;
5745 if (sas_expander
->handle
== handle
)
5747 printk(KERN_INFO
"\texpander(0x%016llx): handle changed"
5748 " from(0x%04x) to (0x%04x)!!!\n",
5749 (unsigned long long)sas_expander
->sas_address
,
5750 sas_expander
->handle
, handle
);
5751 sas_expander
->handle
= handle
;
5752 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++)
5753 sas_expander
->phy
[i
].handle
= handle
;
5757 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5761 * _scsih_search_responding_expanders -
5762 * @ioc: per adapter object
5764 * After host reset, find out whether devices are still responding.
5770 _scsih_search_responding_expanders(struct MPT2SAS_ADAPTER
*ioc
)
5772 Mpi2ExpanderPage0_t expander_pg0
;
5773 Mpi2ConfigReply_t mpi_reply
;
5778 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
, __func__
);
5780 if (list_empty(&ioc
->sas_expander_list
))
5784 while (!(mpt2sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
5785 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL
, handle
))) {
5787 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5788 MPI2_IOCSTATUS_MASK
;
5789 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
5792 handle
= le16_to_cpu(expander_pg0
.DevHandle
);
5793 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
5794 printk(KERN_INFO
"\texpander present: handle(0x%04x), "
5795 "sas_addr(0x%016llx)\n", handle
,
5796 (unsigned long long)sas_address
);
5797 _scsih_mark_responding_expander(ioc
, sas_address
, handle
);
5803 * _scsih_remove_unresponding_sas_devices - removing unresponding devices
5804 * @ioc: per adapter object
5809 _scsih_remove_unresponding_sas_devices(struct MPT2SAS_ADAPTER
*ioc
)
5811 struct _sas_device
*sas_device
, *sas_device_next
;
5812 struct _sas_node
*sas_expander
;
5813 struct _raid_device
*raid_device
, *raid_device_next
;
5816 list_for_each_entry_safe(sas_device
, sas_device_next
,
5817 &ioc
->sas_device_list
, list
) {
5818 if (sas_device
->responding
) {
5819 sas_device
->responding
= 0;
5822 if (sas_device
->starget
)
5823 starget_printk(KERN_INFO
, sas_device
->starget
,
5824 "removing: handle(0x%04x), sas_addr(0x%016llx), "
5825 "enclosure logical id(0x%016llx), slot(%d)\n",
5827 (unsigned long long)sas_device
->sas_address
,
5828 (unsigned long long)
5829 sas_device
->enclosure_logical_id
,
5831 _scsih_remove_device(ioc
, sas_device
);
5834 list_for_each_entry_safe(raid_device
, raid_device_next
,
5835 &ioc
->raid_device_list
, list
) {
5836 if (raid_device
->responding
) {
5837 raid_device
->responding
= 0;
5840 if (raid_device
->starget
) {
5841 starget_printk(KERN_INFO
, raid_device
->starget
,
5842 "removing: handle(0x%04x), wwid(0x%016llx)\n",
5843 raid_device
->handle
,
5844 (unsigned long long)raid_device
->wwid
);
5845 scsi_remove_target(&raid_device
->starget
->dev
);
5847 _scsih_raid_device_remove(ioc
, raid_device
);
5850 retry_expander_search
:
5851 sas_expander
= NULL
;
5852 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
5853 if (sas_expander
->responding
) {
5854 sas_expander
->responding
= 0;
5857 _scsih_expander_remove(ioc
, sas_expander
->sas_address
);
5858 goto retry_expander_search
;
5863 * mpt2sas_scsih_reset_handler - reset callback handler (for scsih)
5864 * @ioc: per adapter object
5865 * @reset_phase: phase
5867 * The handler for doing any required cleanup or initialization.
5869 * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
5870 * MPT2_IOC_DONE_RESET
5875 mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER
*ioc
, int reset_phase
)
5877 switch (reset_phase
) {
5878 case MPT2_IOC_PRE_RESET
:
5879 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: "
5880 "MPT2_IOC_PRE_RESET\n", ioc
->name
, __func__
));
5882 case MPT2_IOC_AFTER_RESET
:
5883 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: "
5884 "MPT2_IOC_AFTER_RESET\n", ioc
->name
, __func__
));
5885 if (ioc
->scsih_cmds
.status
& MPT2_CMD_PENDING
) {
5886 ioc
->scsih_cmds
.status
|= MPT2_CMD_RESET
;
5887 mpt2sas_base_free_smid(ioc
, ioc
->scsih_cmds
.smid
);
5888 complete(&ioc
->scsih_cmds
.done
);
5890 if (ioc
->tm_cmds
.status
& MPT2_CMD_PENDING
) {
5891 ioc
->tm_cmds
.status
|= MPT2_CMD_RESET
;
5892 mpt2sas_base_free_smid(ioc
, ioc
->tm_cmds
.smid
);
5893 complete(&ioc
->tm_cmds
.done
);
5895 _scsih_fw_event_cleanup_queue(ioc
);
5896 _scsih_flush_running_cmds(ioc
);
5897 _scsih_queue_rescan(ioc
);
5899 case MPT2_IOC_DONE_RESET
:
5900 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: "
5901 "MPT2_IOC_DONE_RESET\n", ioc
->name
, __func__
));
5902 _scsih_sas_host_refresh(ioc
);
5903 _scsih_prep_device_scan(ioc
);
5904 _scsih_search_responding_sas_devices(ioc
);
5905 _scsih_search_responding_raid_devices(ioc
);
5906 _scsih_search_responding_expanders(ioc
);
5912 * _firmware_event_work - delayed task for processing firmware events
5913 * @ioc: per adapter object
5914 * @work: equal to the fw_event_work object
5920 _firmware_event_work(struct work_struct
*work
)
5922 struct fw_event_work
*fw_event
= container_of(work
,
5923 struct fw_event_work
, delayed_work
.work
);
5924 unsigned long flags
;
5925 struct MPT2SAS_ADAPTER
*ioc
= fw_event
->ioc
;
5927 /* the queue is being flushed so ignore this event */
5928 if (ioc
->remove_host
|| fw_event
->cancel_pending_work
) {
5929 _scsih_fw_event_free(ioc
, fw_event
);
5933 if (fw_event
->event
== MPT2SAS_RESCAN_AFTER_HOST_RESET
) {
5934 _scsih_fw_event_free(ioc
, fw_event
);
5935 spin_lock_irqsave(&ioc
->ioc_reset_in_progress_lock
, flags
);
5936 if (ioc
->shost_recovery
) {
5937 init_completion(&ioc
->shost_recovery_done
);
5938 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
,
5940 wait_for_completion(&ioc
->shost_recovery_done
);
5942 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
,
5944 _scsih_remove_unresponding_sas_devices(ioc
);
5948 switch (fw_event
->event
) {
5949 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
5950 _scsih_sas_topology_change_event(ioc
, fw_event
);
5952 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
5953 _scsih_sas_device_status_change_event(ioc
,
5956 case MPI2_EVENT_SAS_DISCOVERY
:
5957 _scsih_sas_discovery_event(ioc
,
5960 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
5961 _scsih_sas_broadcast_primative_event(ioc
,
5964 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
5965 _scsih_sas_enclosure_dev_status_change_event(ioc
,
5968 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
5969 _scsih_sas_ir_config_change_event(ioc
, fw_event
);
5971 case MPI2_EVENT_IR_VOLUME
:
5972 _scsih_sas_ir_volume_event(ioc
, fw_event
);
5974 case MPI2_EVENT_IR_PHYSICAL_DISK
:
5975 _scsih_sas_ir_physical_disk_event(ioc
, fw_event
);
5977 case MPI2_EVENT_IR_OPERATION_STATUS
:
5978 _scsih_sas_ir_operation_status_event(ioc
, fw_event
);
5980 case MPI2_EVENT_TASK_SET_FULL
:
5981 _scsih_task_set_full(ioc
, fw_event
);
5984 _scsih_fw_event_free(ioc
, fw_event
);
5988 * mpt2sas_scsih_event_callback - firmware event handler (called at ISR time)
5989 * @ioc: per adapter object
5990 * @msix_index: MSIX table index supplied by the OS
5991 * @reply: reply message frame(lower 32bit addr)
5992 * Context: interrupt.
5994 * This function merely adds a new work task into ioc->firmware_event_thread.
5995 * The tasks are worked from _firmware_event_work in user context.
5997 * Return 1 meaning mf should be freed from _base_interrupt
5998 * 0 means the mf is freed from this function.
6001 mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER
*ioc
, u8 msix_index
,
6004 struct fw_event_work
*fw_event
;
6005 Mpi2EventNotificationReply_t
*mpi_reply
;
6009 /* events turned off due to host reset or driver unloading */
6010 if (ioc
->remove_host
)
6013 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
6014 event
= le16_to_cpu(mpi_reply
->Event
);
6018 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
6020 Mpi2EventDataSasBroadcastPrimitive_t
*baen_data
=
6021 (Mpi2EventDataSasBroadcastPrimitive_t
*)
6022 mpi_reply
->EventData
;
6024 if (baen_data
->Primitive
!=
6025 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT
||
6026 ioc
->broadcast_aen_busy
)
6028 ioc
->broadcast_aen_busy
= 1;
6032 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
6033 _scsih_check_topo_delete_events(ioc
,
6034 (Mpi2EventDataSasTopologyChangeList_t
*)
6035 mpi_reply
->EventData
);
6038 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
6039 case MPI2_EVENT_IR_OPERATION_STATUS
:
6040 case MPI2_EVENT_SAS_DISCOVERY
:
6041 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
6042 case MPI2_EVENT_IR_VOLUME
:
6043 case MPI2_EVENT_IR_PHYSICAL_DISK
:
6044 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
6045 case MPI2_EVENT_TASK_SET_FULL
:
6048 default: /* ignore the rest */
6052 fw_event
= kzalloc(sizeof(struct fw_event_work
), GFP_ATOMIC
);
6054 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6055 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6058 sz
= le16_to_cpu(mpi_reply
->EventDataLength
) * 4;
6059 fw_event
->event_data
= kzalloc(sz
, GFP_ATOMIC
);
6060 if (!fw_event
->event_data
) {
6061 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6062 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6067 memcpy(fw_event
->event_data
, mpi_reply
->EventData
,
6069 fw_event
->ioc
= ioc
;
6070 fw_event
->VF_ID
= mpi_reply
->VF_ID
;
6071 fw_event
->VP_ID
= mpi_reply
->VP_ID
;
6072 fw_event
->event
= event
;
6073 _scsih_fw_event_add(ioc
, fw_event
);
6077 /* shost template */
6078 static struct scsi_host_template scsih_driver_template
= {
6079 .module
= THIS_MODULE
,
6080 .name
= "Fusion MPT SAS Host",
6081 .proc_name
= MPT2SAS_DRIVER_NAME
,
6082 .queuecommand
= _scsih_qcmd
,
6083 .target_alloc
= _scsih_target_alloc
,
6084 .slave_alloc
= _scsih_slave_alloc
,
6085 .slave_configure
= _scsih_slave_configure
,
6086 .target_destroy
= _scsih_target_destroy
,
6087 .slave_destroy
= _scsih_slave_destroy
,
6088 .change_queue_depth
= _scsih_change_queue_depth
,
6089 .change_queue_type
= _scsih_change_queue_type
,
6090 .eh_abort_handler
= _scsih_abort
,
6091 .eh_device_reset_handler
= _scsih_dev_reset
,
6092 .eh_target_reset_handler
= _scsih_target_reset
,
6093 .eh_host_reset_handler
= _scsih_host_reset
,
6094 .bios_param
= _scsih_bios_param
,
6097 .sg_tablesize
= MPT2SAS_SG_DEPTH
,
6098 .max_sectors
= 8192,
6100 .use_clustering
= ENABLE_CLUSTERING
,
6101 .shost_attrs
= mpt2sas_host_attrs
,
6102 .sdev_attrs
= mpt2sas_dev_attrs
,
6106 * _scsih_expander_node_remove - removing expander device from list.
6107 * @ioc: per adapter object
6108 * @sas_expander: the sas_device object
6109 * Context: Calling function should acquire ioc->sas_node_lock.
6111 * Removing object and freeing associated memory from the
6112 * ioc->sas_expander_list.
6117 _scsih_expander_node_remove(struct MPT2SAS_ADAPTER
*ioc
,
6118 struct _sas_node
*sas_expander
)
6120 struct _sas_port
*mpt2sas_port
;
6121 struct _sas_device
*sas_device
;
6122 struct _sas_node
*expander_sibling
;
6123 unsigned long flags
;
6128 /* remove sibling ports attached to this expander */
6129 retry_device_search
:
6130 list_for_each_entry(mpt2sas_port
,
6131 &sas_expander
->sas_port_list
, port_list
) {
6132 if (mpt2sas_port
->remote_identify
.device_type
==
6134 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6136 mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
6137 mpt2sas_port
->remote_identify
.sas_address
);
6138 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6141 _scsih_remove_device(ioc
, sas_device
);
6142 if (ioc
->shost_recovery
)
6144 goto retry_device_search
;
6148 retry_expander_search
:
6149 list_for_each_entry(mpt2sas_port
,
6150 &sas_expander
->sas_port_list
, port_list
) {
6152 if (mpt2sas_port
->remote_identify
.device_type
==
6153 MPI2_SAS_DEVICE_INFO_EDGE_EXPANDER
||
6154 mpt2sas_port
->remote_identify
.device_type
==
6155 MPI2_SAS_DEVICE_INFO_FANOUT_EXPANDER
) {
6157 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
6159 mpt2sas_scsih_expander_find_by_sas_address(
6160 ioc
, mpt2sas_port
->remote_identify
.sas_address
);
6161 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
6162 if (!expander_sibling
)
6164 _scsih_expander_remove(ioc
,
6165 expander_sibling
->sas_address
);
6166 if (ioc
->shost_recovery
)
6168 goto retry_expander_search
;
6172 mpt2sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
6173 sas_expander
->sas_address_parent
);
6175 printk(MPT2SAS_INFO_FMT
"expander_remove: handle"
6176 "(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
6177 sas_expander
->handle
, (unsigned long long)
6178 sas_expander
->sas_address
);
6180 list_del(&sas_expander
->list
);
6181 kfree(sas_expander
->phy
);
6182 kfree(sas_expander
);
6186 * _scsih_ir_shutdown - IR shutdown notification
6187 * @ioc: per adapter object
6189 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
6190 * the host system is shutting down.
6195 _scsih_ir_shutdown(struct MPT2SAS_ADAPTER
*ioc
)
6197 Mpi2RaidActionRequest_t
*mpi_request
;
6198 Mpi2RaidActionReply_t
*mpi_reply
;
6201 /* is IR firmware build loaded ? */
6202 if (!ioc
->ir_firmware
)
6205 /* are there any volumes ? */
6206 if (list_empty(&ioc
->raid_device_list
))
6209 mutex_lock(&ioc
->scsih_cmds
.mutex
);
6211 if (ioc
->scsih_cmds
.status
!= MPT2_CMD_NOT_USED
) {
6212 printk(MPT2SAS_ERR_FMT
"%s: scsih_cmd in use\n",
6213 ioc
->name
, __func__
);
6216 ioc
->scsih_cmds
.status
= MPT2_CMD_PENDING
;
6218 smid
= mpt2sas_base_get_smid(ioc
, ioc
->scsih_cb_idx
);
6220 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
6221 ioc
->name
, __func__
);
6222 ioc
->scsih_cmds
.status
= MPT2_CMD_NOT_USED
;
6226 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
6227 ioc
->scsih_cmds
.smid
= smid
;
6228 memset(mpi_request
, 0, sizeof(Mpi2RaidActionRequest_t
));
6230 mpi_request
->Function
= MPI2_FUNCTION_RAID_ACTION
;
6231 mpi_request
->Action
= MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED
;
6233 printk(MPT2SAS_INFO_FMT
"IR shutdown (sending)\n", ioc
->name
);
6234 init_completion(&ioc
->scsih_cmds
.done
);
6235 mpt2sas_base_put_smid_default(ioc
, smid
);
6236 wait_for_completion_timeout(&ioc
->scsih_cmds
.done
, 10*HZ
);
6238 if (!(ioc
->scsih_cmds
.status
& MPT2_CMD_COMPLETE
)) {
6239 printk(MPT2SAS_ERR_FMT
"%s: timeout\n",
6240 ioc
->name
, __func__
);
6244 if (ioc
->scsih_cmds
.status
& MPT2_CMD_REPLY_VALID
) {
6245 mpi_reply
= ioc
->scsih_cmds
.reply
;
6247 printk(MPT2SAS_INFO_FMT
"IR shutdown (complete): "
6248 "ioc_status(0x%04x), loginfo(0x%08x)\n",
6249 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
6250 le32_to_cpu(mpi_reply
->IOCLogInfo
));
6254 ioc
->scsih_cmds
.status
= MPT2_CMD_NOT_USED
;
6255 mutex_unlock(&ioc
->scsih_cmds
.mutex
);
6259 * _scsih_shutdown - routine call during system shutdown
6260 * @pdev: PCI device struct
6265 _scsih_shutdown(struct pci_dev
*pdev
)
6267 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6268 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
6269 struct workqueue_struct
*wq
;
6270 unsigned long flags
;
6272 ioc
->remove_host
= 1;
6273 _scsih_fw_event_cleanup_queue(ioc
);
6275 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
6276 wq
= ioc
->firmware_event_thread
;
6277 ioc
->firmware_event_thread
= NULL
;
6278 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
6280 destroy_workqueue(wq
);
6282 _scsih_ir_shutdown(ioc
);
6283 mpt2sas_base_detach(ioc
);
6287 * _scsih_remove - detach and remove add host
6288 * @pdev: PCI device struct
6290 * Routine called when unloading the driver.
6293 static void __devexit
6294 _scsih_remove(struct pci_dev
*pdev
)
6296 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6297 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
6298 struct _sas_port
*mpt2sas_port
;
6299 struct _sas_device
*sas_device
;
6300 struct _sas_node
*expander_sibling
;
6301 struct _raid_device
*raid_device
, *next
;
6302 struct MPT2SAS_TARGET
*sas_target_priv_data
;
6303 struct workqueue_struct
*wq
;
6304 unsigned long flags
;
6306 ioc
->remove_host
= 1;
6307 _scsih_fw_event_cleanup_queue(ioc
);
6309 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
6310 wq
= ioc
->firmware_event_thread
;
6311 ioc
->firmware_event_thread
= NULL
;
6312 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
6314 destroy_workqueue(wq
);
6316 /* release all the volumes */
6317 list_for_each_entry_safe(raid_device
, next
, &ioc
->raid_device_list
,
6319 if (raid_device
->starget
) {
6320 sas_target_priv_data
=
6321 raid_device
->starget
->hostdata
;
6322 sas_target_priv_data
->deleted
= 1;
6323 scsi_remove_target(&raid_device
->starget
->dev
);
6325 printk(MPT2SAS_INFO_FMT
"removing handle(0x%04x), wwid"
6326 "(0x%016llx)\n", ioc
->name
, raid_device
->handle
,
6327 (unsigned long long) raid_device
->wwid
);
6328 _scsih_raid_device_remove(ioc
, raid_device
);
6331 /* free ports attached to the sas_host */
6333 list_for_each_entry(mpt2sas_port
,
6334 &ioc
->sas_hba
.sas_port_list
, port_list
) {
6335 if (mpt2sas_port
->remote_identify
.device_type
==
6338 mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
6339 mpt2sas_port
->remote_identify
.sas_address
);
6341 _scsih_remove_device(ioc
, sas_device
);
6346 mpt2sas_scsih_expander_find_by_sas_address(ioc
,
6347 mpt2sas_port
->remote_identify
.sas_address
);
6348 if (expander_sibling
) {
6349 _scsih_expander_remove(ioc
,
6350 expander_sibling
->sas_address
);
6356 /* free phys attached to the sas_host */
6357 if (ioc
->sas_hba
.num_phys
) {
6358 kfree(ioc
->sas_hba
.phy
);
6359 ioc
->sas_hba
.phy
= NULL
;
6360 ioc
->sas_hba
.num_phys
= 0;
6363 sas_remove_host(shost
);
6364 _scsih_shutdown(pdev
);
6365 list_del(&ioc
->list
);
6366 scsi_remove_host(shost
);
6367 scsi_host_put(shost
);
6371 * _scsih_probe_boot_devices - reports 1st device
6372 * @ioc: per adapter object
6374 * If specified in bios page 2, this routine reports the 1st
6375 * device scsi-ml or sas transport for persistent boot device
6376 * purposes. Please refer to function _scsih_determine_boot_device()
6379 _scsih_probe_boot_devices(struct MPT2SAS_ADAPTER
*ioc
)
6383 struct _sas_device
*sas_device
;
6384 struct _raid_device
*raid_device
;
6386 u64 sas_address_parent
;
6388 unsigned long flags
;
6392 if (ioc
->req_boot_device
.device
) {
6393 device
= ioc
->req_boot_device
.device
;
6394 is_raid
= ioc
->req_boot_device
.is_raid
;
6395 } else if (ioc
->req_alt_boot_device
.device
) {
6396 device
= ioc
->req_alt_boot_device
.device
;
6397 is_raid
= ioc
->req_alt_boot_device
.is_raid
;
6398 } else if (ioc
->current_boot_device
.device
) {
6399 device
= ioc
->current_boot_device
.device
;
6400 is_raid
= ioc
->current_boot_device
.is_raid
;
6407 raid_device
= device
;
6408 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
6409 raid_device
->id
, 0);
6411 _scsih_raid_device_remove(ioc
, raid_device
);
6413 sas_device
= device
;
6414 handle
= sas_device
->handle
;
6415 sas_address_parent
= sas_device
->sas_address_parent
;
6416 sas_address
= sas_device
->sas_address
;
6417 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6418 list_move_tail(&sas_device
->list
, &ioc
->sas_device_list
);
6419 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6420 if (!mpt2sas_transport_port_add(ioc
, sas_device
->handle
,
6421 sas_device
->sas_address_parent
)) {
6422 _scsih_sas_device_remove(ioc
, sas_device
);
6423 } else if (!sas_device
->starget
) {
6424 mpt2sas_transport_port_remove(ioc
, sas_address
,
6425 sas_address_parent
);
6426 _scsih_sas_device_remove(ioc
, sas_device
);
6432 * _scsih_probe_raid - reporting raid volumes to scsi-ml
6433 * @ioc: per adapter object
6435 * Called during initial loading of the driver.
6438 _scsih_probe_raid(struct MPT2SAS_ADAPTER
*ioc
)
6440 struct _raid_device
*raid_device
, *raid_next
;
6443 list_for_each_entry_safe(raid_device
, raid_next
,
6444 &ioc
->raid_device_list
, list
) {
6445 if (raid_device
->starget
)
6447 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
6448 raid_device
->id
, 0);
6450 _scsih_raid_device_remove(ioc
, raid_device
);
6455 * _scsih_probe_sas - reporting sas devices to sas transport
6456 * @ioc: per adapter object
6458 * Called during initial loading of the driver.
6461 _scsih_probe_sas(struct MPT2SAS_ADAPTER
*ioc
)
6463 struct _sas_device
*sas_device
, *next
;
6464 unsigned long flags
;
6466 /* SAS Device List */
6467 list_for_each_entry_safe(sas_device
, next
, &ioc
->sas_device_init_list
,
6469 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6470 list_move_tail(&sas_device
->list
, &ioc
->sas_device_list
);
6471 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6473 if (!mpt2sas_transport_port_add(ioc
, sas_device
->handle
,
6474 sas_device
->sas_address_parent
)) {
6475 _scsih_sas_device_remove(ioc
, sas_device
);
6476 } else if (!sas_device
->starget
) {
6477 mpt2sas_transport_port_remove(ioc
,
6478 sas_device
->sas_address
,
6479 sas_device
->sas_address_parent
);
6480 _scsih_sas_device_remove(ioc
, sas_device
);
6486 * _scsih_probe_devices - probing for devices
6487 * @ioc: per adapter object
6489 * Called during initial loading of the driver.
6492 _scsih_probe_devices(struct MPT2SAS_ADAPTER
*ioc
)
6494 u16 volume_mapping_flags
=
6495 le16_to_cpu(ioc
->ioc_pg8
.IRVolumeMappingFlags
) &
6496 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE
;
6498 if (!(ioc
->facts
.ProtocolFlags
& MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR
))
6499 return; /* return when IOC doesn't support initiator mode */
6501 _scsih_probe_boot_devices(ioc
);
6503 if (ioc
->ir_firmware
) {
6504 if ((volume_mapping_flags
&
6505 MPI2_IOCPAGE8_IRFLAGS_HIGH_VOLUME_MAPPING
)) {
6506 _scsih_probe_sas(ioc
);
6507 _scsih_probe_raid(ioc
);
6509 _scsih_probe_raid(ioc
);
6510 _scsih_probe_sas(ioc
);
6513 _scsih_probe_sas(ioc
);
6517 * _scsih_probe - attach and add scsi host
6518 * @pdev: PCI device struct
6519 * @id: pci device id
6521 * Returns 0 success, anything else error.
6524 _scsih_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
6526 struct MPT2SAS_ADAPTER
*ioc
;
6527 struct Scsi_Host
*shost
;
6529 shost
= scsi_host_alloc(&scsih_driver_template
,
6530 sizeof(struct MPT2SAS_ADAPTER
));
6534 /* init local params */
6535 ioc
= shost_priv(shost
);
6536 memset(ioc
, 0, sizeof(struct MPT2SAS_ADAPTER
));
6537 INIT_LIST_HEAD(&ioc
->list
);
6538 list_add_tail(&ioc
->list
, &mpt2sas_ioc_list
);
6540 ioc
->id
= mpt_ids
++;
6541 sprintf(ioc
->name
, "%s%d", MPT2SAS_DRIVER_NAME
, ioc
->id
);
6543 ioc
->scsi_io_cb_idx
= scsi_io_cb_idx
;
6544 ioc
->tm_cb_idx
= tm_cb_idx
;
6545 ioc
->ctl_cb_idx
= ctl_cb_idx
;
6546 ioc
->base_cb_idx
= base_cb_idx
;
6547 ioc
->transport_cb_idx
= transport_cb_idx
;
6548 ioc
->scsih_cb_idx
= scsih_cb_idx
;
6549 ioc
->config_cb_idx
= config_cb_idx
;
6550 ioc
->tm_tr_cb_idx
= tm_tr_cb_idx
;
6551 ioc
->tm_sas_control_cb_idx
= tm_sas_control_cb_idx
;
6552 ioc
->logging_level
= logging_level
;
6553 /* misc semaphores and spin locks */
6554 spin_lock_init(&ioc
->ioc_reset_in_progress_lock
);
6555 spin_lock_init(&ioc
->scsi_lookup_lock
);
6556 spin_lock_init(&ioc
->sas_device_lock
);
6557 spin_lock_init(&ioc
->sas_node_lock
);
6558 spin_lock_init(&ioc
->fw_event_lock
);
6559 spin_lock_init(&ioc
->raid_device_lock
);
6561 INIT_LIST_HEAD(&ioc
->sas_device_list
);
6562 INIT_LIST_HEAD(&ioc
->sas_device_init_list
);
6563 INIT_LIST_HEAD(&ioc
->sas_expander_list
);
6564 INIT_LIST_HEAD(&ioc
->fw_event_list
);
6565 INIT_LIST_HEAD(&ioc
->raid_device_list
);
6566 INIT_LIST_HEAD(&ioc
->sas_hba
.sas_port_list
);
6567 INIT_LIST_HEAD(&ioc
->delayed_tr_list
);
6569 /* init shost parameters */
6570 shost
->max_cmd_len
= 16;
6571 shost
->max_lun
= max_lun
;
6572 shost
->transportt
= mpt2sas_transport_template
;
6573 shost
->unique_id
= ioc
->id
;
6575 if ((scsi_add_host(shost
, &pdev
->dev
))) {
6576 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6577 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6578 list_del(&ioc
->list
);
6579 goto out_add_shost_fail
;
6582 scsi_host_set_prot(shost
, SHOST_DIF_TYPE1_PROTECTION
6583 | SHOST_DIF_TYPE3_PROTECTION
);
6584 scsi_host_set_guard(shost
, SHOST_DIX_GUARD_CRC
);
6587 snprintf(ioc
->firmware_event_name
, sizeof(ioc
->firmware_event_name
),
6588 "fw_event%d", ioc
->id
);
6589 ioc
->firmware_event_thread
= create_singlethread_workqueue(
6590 ioc
->firmware_event_name
);
6591 if (!ioc
->firmware_event_thread
) {
6592 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6593 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6594 goto out_thread_fail
;
6597 ioc
->wait_for_port_enable_to_complete
= 1;
6598 if ((mpt2sas_base_attach(ioc
))) {
6599 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6600 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6601 goto out_attach_fail
;
6604 ioc
->wait_for_port_enable_to_complete
= 0;
6605 _scsih_probe_devices(ioc
);
6609 destroy_workqueue(ioc
->firmware_event_thread
);
6611 list_del(&ioc
->list
);
6612 scsi_remove_host(shost
);
6619 * _scsih_suspend - power management suspend main entry point
6620 * @pdev: PCI device struct
6621 * @state: PM state change to (usually PCI_D3)
6623 * Returns 0 success, anything else error.
6626 _scsih_suspend(struct pci_dev
*pdev
, pm_message_t state
)
6628 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6629 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
6632 mpt2sas_base_stop_watchdog(ioc
);
6633 flush_scheduled_work();
6634 scsi_block_requests(shost
);
6635 device_state
= pci_choose_state(pdev
, state
);
6636 printk(MPT2SAS_INFO_FMT
"pdev=0x%p, slot=%s, entering "
6637 "operating state [D%d]\n", ioc
->name
, pdev
,
6638 pci_name(pdev
), device_state
);
6640 mpt2sas_base_free_resources(ioc
);
6641 pci_save_state(pdev
);
6642 pci_disable_device(pdev
);
6643 pci_set_power_state(pdev
, device_state
);
6648 * _scsih_resume - power management resume main entry point
6649 * @pdev: PCI device struct
6651 * Returns 0 success, anything else error.
6654 _scsih_resume(struct pci_dev
*pdev
)
6656 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6657 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
6658 u32 device_state
= pdev
->current_state
;
6661 printk(MPT2SAS_INFO_FMT
"pdev=0x%p, slot=%s, previous "
6662 "operating state [D%d]\n", ioc
->name
, pdev
,
6663 pci_name(pdev
), device_state
);
6665 pci_set_power_state(pdev
, PCI_D0
);
6666 pci_enable_wake(pdev
, PCI_D0
, 0);
6667 pci_restore_state(pdev
);
6669 r
= mpt2sas_base_map_resources(ioc
);
6673 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
, SOFT_RESET
);
6674 scsi_unblock_requests(shost
);
6675 mpt2sas_base_start_watchdog(ioc
);
6678 #endif /* CONFIG_PM */
6681 * _scsih_pci_error_detected - Called when a PCI error is detected.
6682 * @pdev: PCI device struct
6683 * @state: PCI channel state
6685 * Description: Called when a PCI error is detected.
6688 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
6690 static pci_ers_result_t
6691 _scsih_pci_error_detected(struct pci_dev
*pdev
, pci_channel_state_t state
)
6693 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6694 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
6696 printk(MPT2SAS_INFO_FMT
"PCI error: detected callback, state(%d)!!\n",
6700 case pci_channel_io_normal
:
6701 return PCI_ERS_RESULT_CAN_RECOVER
;
6702 case pci_channel_io_frozen
:
6703 scsi_block_requests(ioc
->shost
);
6704 mpt2sas_base_stop_watchdog(ioc
);
6705 mpt2sas_base_free_resources(ioc
);
6706 return PCI_ERS_RESULT_NEED_RESET
;
6707 case pci_channel_io_perm_failure
:
6708 _scsih_remove(pdev
);
6709 return PCI_ERS_RESULT_DISCONNECT
;
6711 return PCI_ERS_RESULT_NEED_RESET
;
6715 * _scsih_pci_slot_reset - Called when PCI slot has been reset.
6716 * @pdev: PCI device struct
6718 * Description: This routine is called by the pci error recovery
6719 * code after the PCI slot has been reset, just before we
6720 * should resume normal operations.
6722 static pci_ers_result_t
6723 _scsih_pci_slot_reset(struct pci_dev
*pdev
)
6725 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6726 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
6729 printk(MPT2SAS_INFO_FMT
"PCI error: slot reset callback!!\n",
6733 rc
= mpt2sas_base_map_resources(ioc
);
6735 return PCI_ERS_RESULT_DISCONNECT
;
6738 rc
= mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
6741 printk(MPT2SAS_WARN_FMT
"hard reset: %s\n", ioc
->name
,
6742 (rc
== 0) ? "success" : "failed");
6745 return PCI_ERS_RESULT_RECOVERED
;
6747 return PCI_ERS_RESULT_DISCONNECT
;
6751 * _scsih_pci_resume() - resume normal ops after PCI reset
6752 * @pdev: pointer to PCI device
6754 * Called when the error recovery driver tells us that its
6755 * OK to resume normal operation. Use completion to allow
6756 * halted scsi ops to resume.
6759 _scsih_pci_resume(struct pci_dev
*pdev
)
6761 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6762 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
6764 printk(MPT2SAS_INFO_FMT
"PCI error: resume callback!!\n", ioc
->name
);
6766 pci_cleanup_aer_uncorrect_error_status(pdev
);
6767 mpt2sas_base_start_watchdog(ioc
);
6768 scsi_unblock_requests(ioc
->shost
);
6772 * _scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
6773 * @pdev: pointer to PCI device
6775 static pci_ers_result_t
6776 _scsih_pci_mmio_enabled(struct pci_dev
*pdev
)
6778 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6779 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
6781 printk(MPT2SAS_INFO_FMT
"PCI error: mmio enabled callback!!\n",
6784 /* TODO - dump whatever for debugging purposes */
6786 /* Request a slot reset. */
6787 return PCI_ERS_RESULT_NEED_RESET
;
6790 static struct pci_error_handlers _scsih_err_handler
= {
6791 .error_detected
= _scsih_pci_error_detected
,
6792 .mmio_enabled
= _scsih_pci_mmio_enabled
,
6793 .slot_reset
= _scsih_pci_slot_reset
,
6794 .resume
= _scsih_pci_resume
,
6797 static struct pci_driver scsih_driver
= {
6798 .name
= MPT2SAS_DRIVER_NAME
,
6799 .id_table
= scsih_pci_table
,
6800 .probe
= _scsih_probe
,
6801 .remove
= __devexit_p(_scsih_remove
),
6802 .shutdown
= _scsih_shutdown
,
6803 .err_handler
= &_scsih_err_handler
,
6805 .suspend
= _scsih_suspend
,
6806 .resume
= _scsih_resume
,
6810 /* raid transport support */
6811 static struct raid_function_template mpt2sas_raid_functions
= {
6812 .cookie
= &scsih_driver_template
,
6813 .is_raid
= _scsih_is_raid
,
6814 .get_resync
= _scsih_get_resync
,
6815 .get_state
= _scsih_get_state
,
6819 * _scsih_init - main entry point for this driver.
6821 * Returns 0 success, anything else error.
6829 printk(KERN_INFO
"%s version %s loaded\n", MPT2SAS_DRIVER_NAME
,
6830 MPT2SAS_DRIVER_VERSION
);
6832 mpt2sas_transport_template
=
6833 sas_attach_transport(&mpt2sas_transport_functions
);
6834 if (!mpt2sas_transport_template
)
6836 /* raid transport support */
6837 mpt2sas_raid_template
= raid_class_attach(&mpt2sas_raid_functions
);
6838 if (!mpt2sas_raid_template
) {
6839 sas_release_transport(mpt2sas_transport_template
);
6843 mpt2sas_base_initialize_callback_handler();
6845 /* queuecommand callback hander */
6846 scsi_io_cb_idx
= mpt2sas_base_register_callback_handler(_scsih_io_done
);
6848 /* task managment callback handler */
6849 tm_cb_idx
= mpt2sas_base_register_callback_handler(_scsih_tm_done
);
6851 /* base internal commands callback handler */
6852 base_cb_idx
= mpt2sas_base_register_callback_handler(mpt2sas_base_done
);
6854 /* transport internal commands callback handler */
6855 transport_cb_idx
= mpt2sas_base_register_callback_handler(
6856 mpt2sas_transport_done
);
6858 /* scsih internal commands callback handler */
6859 scsih_cb_idx
= mpt2sas_base_register_callback_handler(_scsih_done
);
6861 /* configuration page API internal commands callback handler */
6862 config_cb_idx
= mpt2sas_base_register_callback_handler(
6863 mpt2sas_config_done
);
6865 /* ctl module callback handler */
6866 ctl_cb_idx
= mpt2sas_base_register_callback_handler(mpt2sas_ctl_done
);
6868 tm_tr_cb_idx
= mpt2sas_base_register_callback_handler(
6869 _scsih_tm_tr_complete
);
6870 tm_sas_control_cb_idx
= mpt2sas_base_register_callback_handler(
6871 _scsih_sas_control_complete
);
6875 error
= pci_register_driver(&scsih_driver
);
6877 /* raid transport support */
6878 raid_class_release(mpt2sas_raid_template
);
6879 sas_release_transport(mpt2sas_transport_template
);
6886 * _scsih_exit - exit point for this driver (when it is a module).
6888 * Returns 0 success, anything else error.
6893 printk(KERN_INFO
"mpt2sas version %s unloading\n",
6894 MPT2SAS_DRIVER_VERSION
);
6896 pci_unregister_driver(&scsih_driver
);
6900 mpt2sas_base_release_callback_handler(scsi_io_cb_idx
);
6901 mpt2sas_base_release_callback_handler(tm_cb_idx
);
6902 mpt2sas_base_release_callback_handler(base_cb_idx
);
6903 mpt2sas_base_release_callback_handler(transport_cb_idx
);
6904 mpt2sas_base_release_callback_handler(scsih_cb_idx
);
6905 mpt2sas_base_release_callback_handler(config_cb_idx
);
6906 mpt2sas_base_release_callback_handler(ctl_cb_idx
);
6908 mpt2sas_base_release_callback_handler(tm_tr_cb_idx
);
6909 mpt2sas_base_release_callback_handler(tm_sas_control_cb_idx
);
6911 /* raid transport support */
6912 raid_class_release(mpt2sas_raid_template
);
6913 sas_release_transport(mpt2sas_transport_template
);
6917 module_init(_scsih_init
);
6918 module_exit(_scsih_exit
);