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
)
540 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
541 list_del(&sas_device
->list
);
542 memset(sas_device
, 0, sizeof(struct _sas_device
));
544 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
548 * _scsih_sas_device_add - insert sas_device to the list.
549 * @ioc: per adapter object
550 * @sas_device: the sas_device object
551 * Context: This function will acquire ioc->sas_device_lock.
553 * Adding new object to the ioc->sas_device_list.
556 _scsih_sas_device_add(struct MPT2SAS_ADAPTER
*ioc
,
557 struct _sas_device
*sas_device
)
561 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: handle"
562 "(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
, __func__
,
563 sas_device
->handle
, (unsigned long long)sas_device
->sas_address
));
565 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
566 list_add_tail(&sas_device
->list
, &ioc
->sas_device_list
);
567 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
569 if (!mpt2sas_transport_port_add(ioc
, sas_device
->handle
,
570 sas_device
->sas_address_parent
))
571 _scsih_sas_device_remove(ioc
, sas_device
);
575 * _scsih_sas_device_init_add - insert sas_device to the list.
576 * @ioc: per adapter object
577 * @sas_device: the sas_device object
578 * Context: This function will acquire ioc->sas_device_lock.
580 * Adding new object at driver load time to the ioc->sas_device_init_list.
583 _scsih_sas_device_init_add(struct MPT2SAS_ADAPTER
*ioc
,
584 struct _sas_device
*sas_device
)
588 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: handle"
589 "(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
, __func__
,
590 sas_device
->handle
, (unsigned long long)sas_device
->sas_address
));
592 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
593 list_add_tail(&sas_device
->list
, &ioc
->sas_device_init_list
);
594 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
595 _scsih_determine_boot_device(ioc
, sas_device
, 0);
599 * _scsih_raid_device_find_by_id - raid device search
600 * @ioc: per adapter object
601 * @id: sas device target id
602 * @channel: sas device channel
603 * Context: Calling function should acquire ioc->raid_device_lock
605 * This searches for raid_device based on target id, then return raid_device
608 static struct _raid_device
*
609 _scsih_raid_device_find_by_id(struct MPT2SAS_ADAPTER
*ioc
, int id
, int channel
)
611 struct _raid_device
*raid_device
, *r
;
614 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
615 if (raid_device
->id
== id
&& raid_device
->channel
== channel
) {
626 * _scsih_raid_device_find_by_handle - raid device search
627 * @ioc: per adapter object
628 * @handle: sas device handle (assigned by firmware)
629 * Context: Calling function should acquire ioc->raid_device_lock
631 * This searches for raid_device based on handle, then return raid_device
634 static struct _raid_device
*
635 _scsih_raid_device_find_by_handle(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
637 struct _raid_device
*raid_device
, *r
;
640 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
641 if (raid_device
->handle
!= handle
)
652 * _scsih_raid_device_find_by_wwid - raid device search
653 * @ioc: per adapter object
654 * @handle: sas device handle (assigned by firmware)
655 * Context: Calling function should acquire ioc->raid_device_lock
657 * This searches for raid_device based on wwid, then return raid_device
660 static struct _raid_device
*
661 _scsih_raid_device_find_by_wwid(struct MPT2SAS_ADAPTER
*ioc
, u64 wwid
)
663 struct _raid_device
*raid_device
, *r
;
666 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
667 if (raid_device
->wwid
!= wwid
)
678 * _scsih_raid_device_add - add raid_device object
679 * @ioc: per adapter object
680 * @raid_device: raid_device object
682 * This is added to the raid_device_list link list.
685 _scsih_raid_device_add(struct MPT2SAS_ADAPTER
*ioc
,
686 struct _raid_device
*raid_device
)
690 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: handle"
691 "(0x%04x), wwid(0x%016llx)\n", ioc
->name
, __func__
,
692 raid_device
->handle
, (unsigned long long)raid_device
->wwid
));
694 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
695 list_add_tail(&raid_device
->list
, &ioc
->raid_device_list
);
696 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
700 * _scsih_raid_device_remove - delete raid_device object
701 * @ioc: per adapter object
702 * @raid_device: raid_device object
704 * This is removed from the raid_device_list link list.
707 _scsih_raid_device_remove(struct MPT2SAS_ADAPTER
*ioc
,
708 struct _raid_device
*raid_device
)
712 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
713 list_del(&raid_device
->list
);
714 memset(raid_device
, 0, sizeof(struct _raid_device
));
716 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
720 * mpt2sas_scsih_expander_find_by_handle - expander device search
721 * @ioc: per adapter object
722 * @handle: expander handle (assigned by firmware)
723 * Context: Calling function should acquire ioc->sas_device_lock
725 * This searches for expander device based on handle, then returns the
729 mpt2sas_scsih_expander_find_by_handle(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
731 struct _sas_node
*sas_expander
, *r
;
734 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
735 if (sas_expander
->handle
!= handle
)
745 * mpt2sas_scsih_expander_find_by_sas_address - expander device search
746 * @ioc: per adapter object
747 * @sas_address: sas address
748 * Context: Calling function should acquire ioc->sas_node_lock.
750 * This searches for expander device based on sas_address, then returns the
754 mpt2sas_scsih_expander_find_by_sas_address(struct MPT2SAS_ADAPTER
*ioc
,
757 struct _sas_node
*sas_expander
, *r
;
760 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
761 if (sas_expander
->sas_address
!= sas_address
)
771 * _scsih_expander_node_add - insert expander device to the list.
772 * @ioc: per adapter object
773 * @sas_expander: the sas_device object
774 * Context: This function will acquire ioc->sas_node_lock.
776 * Adding new object to the ioc->sas_expander_list.
781 _scsih_expander_node_add(struct MPT2SAS_ADAPTER
*ioc
,
782 struct _sas_node
*sas_expander
)
786 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
787 list_add_tail(&sas_expander
->list
, &ioc
->sas_expander_list
);
788 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
792 * _scsih_is_end_device - determines if device is an end device
793 * @device_info: bitfield providing information about the device.
796 * Returns 1 if end device.
799 _scsih_is_end_device(u32 device_info
)
801 if (device_info
& MPI2_SAS_DEVICE_INFO_END_DEVICE
&&
802 ((device_info
& MPI2_SAS_DEVICE_INFO_SSP_TARGET
) |
803 (device_info
& MPI2_SAS_DEVICE_INFO_STP_TARGET
) |
804 (device_info
& MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)))
811 * mptscsih_get_scsi_lookup - returns scmd entry
812 * @ioc: per adapter object
813 * @smid: system request message index
815 * Returns the smid stored scmd pointer.
817 static struct scsi_cmnd
*
818 _scsih_scsi_lookup_get(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
820 return ioc
->scsi_lookup
[smid
- 1].scmd
;
824 * _scsih_scsi_lookup_find_by_scmd - scmd lookup
825 * @ioc: per adapter object
826 * @smid: system request message index
827 * @scmd: pointer to scsi command object
828 * Context: This function will acquire ioc->scsi_lookup_lock.
830 * This will search for a scmd pointer in the scsi_lookup array,
831 * returning the revelent smid. A returned value of zero means invalid.
834 _scsih_scsi_lookup_find_by_scmd(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_cmnd
841 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
843 for (i
= 0; i
< ioc
->scsiio_depth
; i
++) {
844 if (ioc
->scsi_lookup
[i
].scmd
== scmd
) {
845 smid
= ioc
->scsi_lookup
[i
].smid
;
850 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
855 * _scsih_scsi_lookup_find_by_target - search for matching channel:id
856 * @ioc: per adapter object
859 * Context: This function will acquire ioc->scsi_lookup_lock.
861 * This will search for a matching channel:id in the scsi_lookup array,
862 * returning 1 if found.
865 _scsih_scsi_lookup_find_by_target(struct MPT2SAS_ADAPTER
*ioc
, int id
,
872 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
874 for (i
= 0 ; i
< ioc
->scsiio_depth
; i
++) {
875 if (ioc
->scsi_lookup
[i
].scmd
&&
876 (ioc
->scsi_lookup
[i
].scmd
->device
->id
== id
&&
877 ioc
->scsi_lookup
[i
].scmd
->device
->channel
== channel
)) {
883 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
888 * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun
889 * @ioc: per adapter object
893 * Context: This function will acquire ioc->scsi_lookup_lock.
895 * This will search for a matching channel:id:lun in the scsi_lookup array,
896 * returning 1 if found.
899 _scsih_scsi_lookup_find_by_lun(struct MPT2SAS_ADAPTER
*ioc
, int id
,
900 unsigned int lun
, int channel
)
906 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
908 for (i
= 0 ; i
< ioc
->scsiio_depth
; i
++) {
909 if (ioc
->scsi_lookup
[i
].scmd
&&
910 (ioc
->scsi_lookup
[i
].scmd
->device
->id
== id
&&
911 ioc
->scsi_lookup
[i
].scmd
->device
->channel
== channel
&&
912 ioc
->scsi_lookup
[i
].scmd
->device
->lun
== lun
)) {
918 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
923 * _scsih_get_chain_buffer_dma - obtain block of chains (dma address)
924 * @ioc: per adapter object
925 * @smid: system request message index
927 * Returns phys pointer to chain buffer.
930 _scsih_get_chain_buffer_dma(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
932 return ioc
->chain_dma
+ ((smid
- 1) * (ioc
->request_sz
*
933 ioc
->chains_needed_per_io
));
937 * _scsih_get_chain_buffer - obtain block of chains assigned to a mf request
938 * @ioc: per adapter object
939 * @smid: system request message index
941 * Returns virt pointer to chain buffer.
944 _scsih_get_chain_buffer(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
946 return (void *)(ioc
->chain
+ ((smid
- 1) * (ioc
->request_sz
*
947 ioc
->chains_needed_per_io
)));
951 * _scsih_build_scatter_gather - main sg creation routine
952 * @ioc: per adapter object
953 * @scmd: scsi command
954 * @smid: system request message index
957 * The main routine that builds scatter gather table from a given
958 * scsi request sent via the .queuecommand main handler.
960 * Returns 0 success, anything else error
963 _scsih_build_scatter_gather(struct MPT2SAS_ADAPTER
*ioc
,
964 struct scsi_cmnd
*scmd
, u16 smid
)
966 Mpi2SCSIIORequest_t
*mpi_request
;
967 dma_addr_t chain_dma
;
968 struct scatterlist
*sg_scmd
;
969 void *sg_local
, *chain
;
976 u32 sgl_flags_last_element
;
977 u32 sgl_flags_end_buffer
;
979 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
981 /* init scatter gather flags */
982 sgl_flags
= MPI2_SGE_FLAGS_SIMPLE_ELEMENT
;
983 if (scmd
->sc_data_direction
== DMA_TO_DEVICE
)
984 sgl_flags
|= MPI2_SGE_FLAGS_HOST_TO_IOC
;
985 sgl_flags_last_element
= (sgl_flags
| MPI2_SGE_FLAGS_LAST_ELEMENT
)
986 << MPI2_SGE_FLAGS_SHIFT
;
987 sgl_flags_end_buffer
= (sgl_flags
| MPI2_SGE_FLAGS_LAST_ELEMENT
|
988 MPI2_SGE_FLAGS_END_OF_BUFFER
| MPI2_SGE_FLAGS_END_OF_LIST
)
989 << MPI2_SGE_FLAGS_SHIFT
;
990 sgl_flags
= sgl_flags
<< MPI2_SGE_FLAGS_SHIFT
;
992 sg_scmd
= scsi_sglist(scmd
);
993 sges_left
= scsi_dma_map(scmd
);
995 sdev_printk(KERN_ERR
, scmd
->device
, "pci_map_sg"
996 " failed: request for %d bytes!\n", scsi_bufflen(scmd
));
1000 sg_local
= &mpi_request
->SGL
;
1001 sges_in_segment
= ioc
->max_sges_in_main_message
;
1002 if (sges_left
<= sges_in_segment
)
1003 goto fill_in_last_segment
;
1005 mpi_request
->ChainOffset
= (offsetof(Mpi2SCSIIORequest_t
, SGL
) +
1006 (sges_in_segment
* ioc
->sge_size
))/4;
1008 /* fill in main message segment when there is a chain following */
1009 while (sges_in_segment
) {
1010 if (sges_in_segment
== 1)
1011 ioc
->base_add_sg_single(sg_local
,
1012 sgl_flags_last_element
| sg_dma_len(sg_scmd
),
1013 sg_dma_address(sg_scmd
));
1015 ioc
->base_add_sg_single(sg_local
, sgl_flags
|
1016 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
1017 sg_scmd
= sg_next(sg_scmd
);
1018 sg_local
+= ioc
->sge_size
;
1023 /* initializing the chain flags and pointers */
1024 chain_flags
= MPI2_SGE_FLAGS_CHAIN_ELEMENT
<< MPI2_SGE_FLAGS_SHIFT
;
1025 chain
= _scsih_get_chain_buffer(ioc
, smid
);
1026 chain_dma
= _scsih_get_chain_buffer_dma(ioc
, smid
);
1028 sges_in_segment
= (sges_left
<=
1029 ioc
->max_sges_in_chain_message
) ? sges_left
:
1030 ioc
->max_sges_in_chain_message
;
1031 chain_offset
= (sges_left
== sges_in_segment
) ?
1032 0 : (sges_in_segment
* ioc
->sge_size
)/4;
1033 chain_length
= sges_in_segment
* ioc
->sge_size
;
1035 chain_offset
= chain_offset
<<
1036 MPI2_SGE_CHAIN_OFFSET_SHIFT
;
1037 chain_length
+= ioc
->sge_size
;
1039 ioc
->base_add_sg_single(sg_local
, chain_flags
| chain_offset
|
1040 chain_length
, chain_dma
);
1043 goto fill_in_last_segment
;
1045 /* fill in chain segments */
1046 while (sges_in_segment
) {
1047 if (sges_in_segment
== 1)
1048 ioc
->base_add_sg_single(sg_local
,
1049 sgl_flags_last_element
|
1050 sg_dma_len(sg_scmd
),
1051 sg_dma_address(sg_scmd
));
1053 ioc
->base_add_sg_single(sg_local
, sgl_flags
|
1054 sg_dma_len(sg_scmd
),
1055 sg_dma_address(sg_scmd
));
1056 sg_scmd
= sg_next(sg_scmd
);
1057 sg_local
+= ioc
->sge_size
;
1062 chain_dma
+= ioc
->request_sz
;
1063 chain
+= ioc
->request_sz
;
1067 fill_in_last_segment
:
1069 /* fill the last segment */
1072 ioc
->base_add_sg_single(sg_local
, sgl_flags_end_buffer
|
1073 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
1075 ioc
->base_add_sg_single(sg_local
, sgl_flags
|
1076 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
1077 sg_scmd
= sg_next(sg_scmd
);
1078 sg_local
+= ioc
->sge_size
;
1086 * _scsih_change_queue_depth - setting device queue depth
1087 * @sdev: scsi device struct
1088 * @qdepth: requested queue depth
1089 * @reason: calling context
1091 * Returns queue depth.
1094 _scsih_change_queue_depth(struct scsi_device
*sdev
, int qdepth
, int reason
)
1096 struct Scsi_Host
*shost
= sdev
->host
;
1099 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1100 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1101 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1102 struct _sas_device
*sas_device
;
1103 unsigned long flags
;
1105 if (reason
!= SCSI_QDEPTH_DEFAULT
)
1108 max_depth
= shost
->can_queue
;
1110 /* limit max device queue for SATA to 32 */
1111 sas_device_priv_data
= sdev
->hostdata
;
1112 if (!sas_device_priv_data
)
1114 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
1115 if (!sas_target_priv_data
)
1117 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
))
1119 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1120 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1121 sas_device_priv_data
->sas_target
->sas_address
);
1122 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1123 if (sas_device
&& sas_device
->device_info
&
1124 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1125 max_depth
= MPT2SAS_SATA_QUEUE_DEPTH
;
1129 if (!sdev
->tagged_supported
)
1131 if (qdepth
> max_depth
)
1133 tag_type
= (qdepth
== 1) ? 0 : MSG_SIMPLE_TAG
;
1134 scsi_adjust_queue_depth(sdev
, tag_type
, qdepth
);
1136 if (sdev
->inquiry_len
> 7)
1137 sdev_printk(KERN_INFO
, sdev
, "qdepth(%d), tagged(%d), "
1138 "simple(%d), ordered(%d), scsi_level(%d), cmd_que(%d)\n",
1139 sdev
->queue_depth
, sdev
->tagged_supported
, sdev
->simple_tags
,
1140 sdev
->ordered_tags
, sdev
->scsi_level
,
1141 (sdev
->inquiry
[7] & 2) >> 1);
1143 return sdev
->queue_depth
;
1147 * _scsih_change_queue_type - changing device queue tag type
1148 * @sdev: scsi device struct
1149 * @tag_type: requested tag type
1151 * Returns queue tag type.
1154 _scsih_change_queue_type(struct scsi_device
*sdev
, int tag_type
)
1156 if (sdev
->tagged_supported
) {
1157 scsi_set_tag_type(sdev
, tag_type
);
1159 scsi_activate_tcq(sdev
, sdev
->queue_depth
);
1161 scsi_deactivate_tcq(sdev
, sdev
->queue_depth
);
1169 * _scsih_target_alloc - target add routine
1170 * @starget: scsi target struct
1172 * Returns 0 if ok. Any other return is assumed to be an error and
1173 * the device is ignored.
1176 _scsih_target_alloc(struct scsi_target
*starget
)
1178 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
1179 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1180 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1181 struct _sas_device
*sas_device
;
1182 struct _raid_device
*raid_device
;
1183 unsigned long flags
;
1184 struct sas_rphy
*rphy
;
1186 sas_target_priv_data
= kzalloc(sizeof(struct scsi_target
), GFP_KERNEL
);
1187 if (!sas_target_priv_data
)
1190 starget
->hostdata
= sas_target_priv_data
;
1191 sas_target_priv_data
->starget
= starget
;
1192 sas_target_priv_data
->handle
= MPT2SAS_INVALID_DEVICE_HANDLE
;
1195 if (starget
->channel
== RAID_CHANNEL
) {
1196 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1197 raid_device
= _scsih_raid_device_find_by_id(ioc
, starget
->id
,
1200 sas_target_priv_data
->handle
= raid_device
->handle
;
1201 sas_target_priv_data
->sas_address
= raid_device
->wwid
;
1202 sas_target_priv_data
->flags
|= MPT_TARGET_FLAGS_VOLUME
;
1203 raid_device
->starget
= starget
;
1205 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1209 /* sas/sata devices */
1210 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1211 rphy
= dev_to_rphy(starget
->dev
.parent
);
1212 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1213 rphy
->identify
.sas_address
);
1216 sas_target_priv_data
->handle
= sas_device
->handle
;
1217 sas_target_priv_data
->sas_address
= sas_device
->sas_address
;
1218 sas_device
->starget
= starget
;
1219 sas_device
->id
= starget
->id
;
1220 sas_device
->channel
= starget
->channel
;
1221 if (sas_device
->hidden_raid_component
)
1222 sas_target_priv_data
->flags
|=
1223 MPT_TARGET_FLAGS_RAID_COMPONENT
;
1225 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1231 * _scsih_target_destroy - target destroy routine
1232 * @starget: scsi target struct
1237 _scsih_target_destroy(struct scsi_target
*starget
)
1239 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
1240 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1241 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1242 struct _sas_device
*sas_device
;
1243 struct _raid_device
*raid_device
;
1244 unsigned long flags
;
1245 struct sas_rphy
*rphy
;
1247 sas_target_priv_data
= starget
->hostdata
;
1248 if (!sas_target_priv_data
)
1251 if (starget
->channel
== RAID_CHANNEL
) {
1252 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1253 raid_device
= _scsih_raid_device_find_by_id(ioc
, starget
->id
,
1256 raid_device
->starget
= NULL
;
1257 raid_device
->sdev
= NULL
;
1259 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1263 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1264 rphy
= dev_to_rphy(starget
->dev
.parent
);
1265 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1266 rphy
->identify
.sas_address
);
1267 if (sas_device
&& (sas_device
->starget
== starget
) &&
1268 (sas_device
->id
== starget
->id
) &&
1269 (sas_device
->channel
== starget
->channel
))
1270 sas_device
->starget
= NULL
;
1272 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1275 kfree(sas_target_priv_data
);
1276 starget
->hostdata
= NULL
;
1280 * _scsih_slave_alloc - device add routine
1281 * @sdev: scsi device struct
1283 * Returns 0 if ok. Any other return is assumed to be an error and
1284 * the device is ignored.
1287 _scsih_slave_alloc(struct scsi_device
*sdev
)
1289 struct Scsi_Host
*shost
;
1290 struct MPT2SAS_ADAPTER
*ioc
;
1291 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1292 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1293 struct scsi_target
*starget
;
1294 struct _raid_device
*raid_device
;
1295 unsigned long flags
;
1297 sas_device_priv_data
= kzalloc(sizeof(struct scsi_device
), GFP_KERNEL
);
1298 if (!sas_device_priv_data
)
1301 sas_device_priv_data
->lun
= sdev
->lun
;
1302 sas_device_priv_data
->flags
= MPT_DEVICE_FLAGS_INIT
;
1304 starget
= scsi_target(sdev
);
1305 sas_target_priv_data
= starget
->hostdata
;
1306 sas_target_priv_data
->num_luns
++;
1307 sas_device_priv_data
->sas_target
= sas_target_priv_data
;
1308 sdev
->hostdata
= sas_device_priv_data
;
1309 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
))
1310 sdev
->no_uld_attach
= 1;
1312 shost
= dev_to_shost(&starget
->dev
);
1313 ioc
= shost_priv(shost
);
1314 if (starget
->channel
== RAID_CHANNEL
) {
1315 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1316 raid_device
= _scsih_raid_device_find_by_id(ioc
,
1317 starget
->id
, starget
->channel
);
1319 raid_device
->sdev
= sdev
; /* raid is single lun */
1320 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1327 * _scsih_slave_destroy - device destroy routine
1328 * @sdev: scsi device struct
1333 _scsih_slave_destroy(struct scsi_device
*sdev
)
1335 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1336 struct scsi_target
*starget
;
1338 if (!sdev
->hostdata
)
1341 starget
= scsi_target(sdev
);
1342 sas_target_priv_data
= starget
->hostdata
;
1343 sas_target_priv_data
->num_luns
--;
1344 kfree(sdev
->hostdata
);
1345 sdev
->hostdata
= NULL
;
1349 * _scsih_display_sata_capabilities - sata capabilities
1350 * @ioc: per adapter object
1351 * @sas_device: the sas_device object
1352 * @sdev: scsi device struct
1355 _scsih_display_sata_capabilities(struct MPT2SAS_ADAPTER
*ioc
,
1356 struct _sas_device
*sas_device
, struct scsi_device
*sdev
)
1358 Mpi2ConfigReply_t mpi_reply
;
1359 Mpi2SasDevicePage0_t sas_device_pg0
;
1364 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
1365 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, sas_device
->handle
))) {
1366 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1367 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1371 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
1372 MPI2_IOCSTATUS_MASK
;
1373 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
1374 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1375 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1379 flags
= le16_to_cpu(sas_device_pg0
.Flags
);
1380 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
1382 sdev_printk(KERN_INFO
, sdev
,
1383 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1384 "sw_preserve(%s)\n",
1385 (device_info
& MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE
) ? "y" : "n",
1386 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED
) ? "y" : "n",
1387 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY
) ? "y" :
1389 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED
) ? "y" : "n",
1390 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED
) ? "y" : "n",
1391 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE
) ? "y" : "n");
1395 * _scsih_is_raid - return boolean indicating device is raid volume
1396 * @dev the device struct object
1399 _scsih_is_raid(struct device
*dev
)
1401 struct scsi_device
*sdev
= to_scsi_device(dev
);
1403 return (sdev
->channel
== RAID_CHANNEL
) ? 1 : 0;
1407 * _scsih_get_resync - get raid volume resync percent complete
1408 * @dev the device struct object
1411 _scsih_get_resync(struct device
*dev
)
1413 struct scsi_device
*sdev
= to_scsi_device(dev
);
1414 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
1415 static struct _raid_device
*raid_device
;
1416 unsigned long flags
;
1417 Mpi2RaidVolPage0_t vol_pg0
;
1418 Mpi2ConfigReply_t mpi_reply
;
1419 u32 volume_status_flags
;
1420 u8 percent_complete
= 0;
1422 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1423 raid_device
= _scsih_raid_device_find_by_id(ioc
, sdev
->id
,
1425 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1430 if (mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, &vol_pg0
,
1431 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, raid_device
->handle
,
1432 sizeof(Mpi2RaidVolPage0_t
))) {
1433 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1434 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1438 volume_status_flags
= le32_to_cpu(vol_pg0
.VolumeStatusFlags
);
1439 if (volume_status_flags
& MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS
)
1440 percent_complete
= raid_device
->percent_complete
;
1442 raid_set_resync(mpt2sas_raid_template
, dev
, percent_complete
);
1446 * _scsih_get_state - get raid volume level
1447 * @dev the device struct object
1450 _scsih_get_state(struct device
*dev
)
1452 struct scsi_device
*sdev
= to_scsi_device(dev
);
1453 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
1454 static struct _raid_device
*raid_device
;
1455 unsigned long flags
;
1456 Mpi2RaidVolPage0_t vol_pg0
;
1457 Mpi2ConfigReply_t mpi_reply
;
1459 enum raid_state state
= RAID_STATE_UNKNOWN
;
1461 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1462 raid_device
= _scsih_raid_device_find_by_id(ioc
, sdev
->id
,
1464 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1469 if (mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, &vol_pg0
,
1470 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, raid_device
->handle
,
1471 sizeof(Mpi2RaidVolPage0_t
))) {
1472 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1473 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1477 volstate
= le32_to_cpu(vol_pg0
.VolumeStatusFlags
);
1478 if (volstate
& MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS
) {
1479 state
= RAID_STATE_RESYNCING
;
1483 switch (vol_pg0
.VolumeState
) {
1484 case MPI2_RAID_VOL_STATE_OPTIMAL
:
1485 case MPI2_RAID_VOL_STATE_ONLINE
:
1486 state
= RAID_STATE_ACTIVE
;
1488 case MPI2_RAID_VOL_STATE_DEGRADED
:
1489 state
= RAID_STATE_DEGRADED
;
1491 case MPI2_RAID_VOL_STATE_FAILED
:
1492 case MPI2_RAID_VOL_STATE_MISSING
:
1493 state
= RAID_STATE_OFFLINE
;
1497 raid_set_state(mpt2sas_raid_template
, dev
, state
);
1501 * _scsih_set_level - set raid level
1502 * @sdev: scsi device struct
1503 * @raid_device: raid_device object
1506 _scsih_set_level(struct scsi_device
*sdev
, struct _raid_device
*raid_device
)
1508 enum raid_level level
= RAID_LEVEL_UNKNOWN
;
1510 switch (raid_device
->volume_type
) {
1511 case MPI2_RAID_VOL_TYPE_RAID0
:
1512 level
= RAID_LEVEL_0
;
1514 case MPI2_RAID_VOL_TYPE_RAID10
:
1515 level
= RAID_LEVEL_10
;
1517 case MPI2_RAID_VOL_TYPE_RAID1E
:
1518 level
= RAID_LEVEL_1E
;
1520 case MPI2_RAID_VOL_TYPE_RAID1
:
1521 level
= RAID_LEVEL_1
;
1525 raid_set_level(mpt2sas_raid_template
, &sdev
->sdev_gendev
, level
);
1529 * _scsih_get_volume_capabilities - volume capabilities
1530 * @ioc: per adapter object
1531 * @sas_device: the raid_device object
1534 _scsih_get_volume_capabilities(struct MPT2SAS_ADAPTER
*ioc
,
1535 struct _raid_device
*raid_device
)
1537 Mpi2RaidVolPage0_t
*vol_pg0
;
1538 Mpi2RaidPhysDiskPage0_t pd_pg0
;
1539 Mpi2SasDevicePage0_t sas_device_pg0
;
1540 Mpi2ConfigReply_t mpi_reply
;
1544 if ((mpt2sas_config_get_number_pds(ioc
, raid_device
->handle
,
1545 &num_pds
)) || !num_pds
) {
1546 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1547 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1551 raid_device
->num_pds
= num_pds
;
1552 sz
= offsetof(Mpi2RaidVolPage0_t
, PhysDisk
) + (num_pds
*
1553 sizeof(Mpi2RaidVol0PhysDisk_t
));
1554 vol_pg0
= kzalloc(sz
, GFP_KERNEL
);
1556 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1557 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1561 if ((mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, vol_pg0
,
1562 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, raid_device
->handle
, sz
))) {
1563 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1564 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1569 raid_device
->volume_type
= vol_pg0
->VolumeType
;
1571 /* figure out what the underlying devices are by
1572 * obtaining the device_info bits for the 1st device
1574 if (!(mpt2sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
1575 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM
,
1576 vol_pg0
->PhysDisk
[0].PhysDiskNum
))) {
1577 if (!(mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
1578 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
1579 le16_to_cpu(pd_pg0
.DevHandle
)))) {
1580 raid_device
->device_info
=
1581 le32_to_cpu(sas_device_pg0
.DeviceInfo
);
1589 * _scsih_enable_tlr - setting TLR flags
1590 * @ioc: per adapter object
1591 * @sdev: scsi device struct
1593 * Enabling Transaction Layer Retries for tape devices when
1594 * vpd page 0x90 is present
1598 _scsih_enable_tlr(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_device
*sdev
)
1601 if (sdev
->type
!= TYPE_TAPE
)
1604 if (!(ioc
->facts
.IOCCapabilities
& MPI2_IOCFACTS_CAPABILITY_TLR
))
1607 sas_enable_tlr(sdev
);
1608 sdev_printk(KERN_INFO
, sdev
, "TLR %s\n",
1609 sas_is_tlr_enabled(sdev
) ? "Enabled" : "Disabled");
1615 * _scsih_slave_configure - device configure routine.
1616 * @sdev: scsi device struct
1618 * Returns 0 if ok. Any other return is assumed to be an error and
1619 * the device is ignored.
1622 _scsih_slave_configure(struct scsi_device
*sdev
)
1624 struct Scsi_Host
*shost
= sdev
->host
;
1625 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1626 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1627 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1628 struct _sas_device
*sas_device
;
1629 struct _raid_device
*raid_device
;
1630 unsigned long flags
;
1637 sas_device_priv_data
= sdev
->hostdata
;
1638 sas_device_priv_data
->configured_lun
= 1;
1639 sas_device_priv_data
->flags
&= ~MPT_DEVICE_FLAGS_INIT
;
1640 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
1642 /* raid volume handling */
1643 if (sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
1645 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1646 raid_device
= _scsih_raid_device_find_by_handle(ioc
,
1647 sas_target_priv_data
->handle
);
1648 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1650 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1651 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1655 _scsih_get_volume_capabilities(ioc
, raid_device
);
1657 /* RAID Queue Depth Support
1658 * IS volume = underlying qdepth of drive type, either
1659 * MPT2SAS_SAS_QUEUE_DEPTH or MPT2SAS_SATA_QUEUE_DEPTH
1660 * IM/IME/R10 = 128 (MPT2SAS_RAID_QUEUE_DEPTH)
1662 if (raid_device
->device_info
&
1663 MPI2_SAS_DEVICE_INFO_SSP_TARGET
) {
1664 qdepth
= MPT2SAS_SAS_QUEUE_DEPTH
;
1667 qdepth
= MPT2SAS_SATA_QUEUE_DEPTH
;
1668 if (raid_device
->device_info
&
1669 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1675 switch (raid_device
->volume_type
) {
1676 case MPI2_RAID_VOL_TYPE_RAID0
:
1679 case MPI2_RAID_VOL_TYPE_RAID1E
:
1680 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
1681 if (ioc
->manu_pg10
.OEMIdentifier
&&
1682 (ioc
->manu_pg10
.GenericFlags0
&
1683 MFG10_GF0_R10_DISPLAY
) &&
1684 !(raid_device
->num_pds
% 2))
1689 case MPI2_RAID_VOL_TYPE_RAID1
:
1690 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
1693 case MPI2_RAID_VOL_TYPE_RAID10
:
1694 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
1697 case MPI2_RAID_VOL_TYPE_UNKNOWN
:
1699 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
1704 sdev_printk(KERN_INFO
, sdev
, "%s: "
1705 "handle(0x%04x), wwid(0x%016llx), pd_count(%d), type(%s)\n",
1706 r_level
, raid_device
->handle
,
1707 (unsigned long long)raid_device
->wwid
,
1708 raid_device
->num_pds
, ds
);
1709 _scsih_change_queue_depth(sdev
, qdepth
, SCSI_QDEPTH_DEFAULT
);
1710 /* raid transport support */
1711 _scsih_set_level(sdev
, raid_device
);
1715 /* non-raid handling */
1716 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1717 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1718 sas_device_priv_data
->sas_target
->sas_address
);
1719 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1721 if (sas_target_priv_data
->flags
&
1722 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
1723 mpt2sas_config_get_volume_handle(ioc
,
1724 sas_device
->handle
, &sas_device
->volume_handle
);
1725 mpt2sas_config_get_volume_wwid(ioc
,
1726 sas_device
->volume_handle
,
1727 &sas_device
->volume_wwid
);
1729 if (sas_device
->device_info
& MPI2_SAS_DEVICE_INFO_SSP_TARGET
) {
1730 qdepth
= MPT2SAS_SAS_QUEUE_DEPTH
;
1734 qdepth
= MPT2SAS_SATA_QUEUE_DEPTH
;
1735 if (sas_device
->device_info
&
1736 MPI2_SAS_DEVICE_INFO_STP_TARGET
)
1738 else if (sas_device
->device_info
&
1739 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1743 sdev_printk(KERN_INFO
, sdev
, "%s: handle(0x%04x), "
1744 "sas_addr(0x%016llx), device_name(0x%016llx)\n",
1745 ds
, sas_device
->handle
,
1746 (unsigned long long)sas_device
->sas_address
,
1747 (unsigned long long)sas_device
->device_name
);
1748 sdev_printk(KERN_INFO
, sdev
, "%s: "
1749 "enclosure_logical_id(0x%016llx), slot(%d)\n", ds
,
1750 (unsigned long long) sas_device
->enclosure_logical_id
,
1754 _scsih_display_sata_capabilities(ioc
, sas_device
, sdev
);
1757 _scsih_change_queue_depth(sdev
, qdepth
, SCSI_QDEPTH_DEFAULT
);
1760 sas_read_port_mode_page(sdev
);
1761 _scsih_enable_tlr(ioc
, sdev
);
1767 * _scsih_bios_param - fetch head, sector, cylinder info for a disk
1768 * @sdev: scsi device struct
1769 * @bdev: pointer to block device context
1770 * @capacity: device size (in 512 byte sectors)
1771 * @params: three element array to place output:
1772 * params[0] number of heads (max 255)
1773 * params[1] number of sectors (max 63)
1774 * params[2] number of cylinders
1779 _scsih_bios_param(struct scsi_device
*sdev
, struct block_device
*bdev
,
1780 sector_t capacity
, int params
[])
1790 dummy
= heads
* sectors
;
1791 cylinders
= capacity
;
1792 sector_div(cylinders
, dummy
);
1795 * Handle extended translation size for logical drives
1798 if ((ulong
)capacity
>= 0x200000) {
1801 dummy
= heads
* sectors
;
1802 cylinders
= capacity
;
1803 sector_div(cylinders
, dummy
);
1808 params
[1] = sectors
;
1809 params
[2] = cylinders
;
1815 * _scsih_response_code - translation of device response code
1816 * @ioc: per adapter object
1817 * @response_code: response code returned by the device
1822 _scsih_response_code(struct MPT2SAS_ADAPTER
*ioc
, u8 response_code
)
1826 switch (response_code
) {
1827 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE
:
1828 desc
= "task management request completed";
1830 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
:
1831 desc
= "invalid frame";
1833 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED
:
1834 desc
= "task management request not supported";
1836 case MPI2_SCSITASKMGMT_RSP_TM_FAILED
:
1837 desc
= "task management request failed";
1839 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
:
1840 desc
= "task management request succeeded";
1842 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN
:
1843 desc
= "invalid lun";
1846 desc
= "overlapped tag attempted";
1848 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
:
1849 desc
= "task queued, however not sent to target";
1855 printk(MPT2SAS_WARN_FMT
"response_code(0x%01x): %s\n",
1856 ioc
->name
, response_code
, desc
);
1860 * _scsih_tm_done - tm completion routine
1861 * @ioc: per adapter object
1862 * @smid: system request message index
1863 * @msix_index: MSIX table index supplied by the OS
1864 * @reply: reply message frame(lower 32bit addr)
1867 * The callback handler when using scsih_issue_tm.
1869 * Return 1 meaning mf should be freed from _base_interrupt
1870 * 0 means the mf is freed from this function.
1873 _scsih_tm_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
1875 MPI2DefaultReply_t
*mpi_reply
;
1877 if (ioc
->tm_cmds
.status
== MPT2_CMD_NOT_USED
)
1879 if (ioc
->tm_cmds
.smid
!= smid
)
1881 ioc
->tm_cmds
.status
|= MPT2_CMD_COMPLETE
;
1882 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
1884 memcpy(ioc
->tm_cmds
.reply
, mpi_reply
, mpi_reply
->MsgLength
*4);
1885 ioc
->tm_cmds
.status
|= MPT2_CMD_REPLY_VALID
;
1887 ioc
->tm_cmds
.status
&= ~MPT2_CMD_PENDING
;
1888 complete(&ioc
->tm_cmds
.done
);
1893 * mpt2sas_scsih_set_tm_flag - set per target tm_busy
1894 * @ioc: per adapter object
1895 * @handle: device handle
1897 * During taskmangement request, we need to freeze the device queue.
1900 mpt2sas_scsih_set_tm_flag(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
1902 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1903 struct scsi_device
*sdev
;
1906 shost_for_each_device(sdev
, ioc
->shost
) {
1909 sas_device_priv_data
= sdev
->hostdata
;
1910 if (!sas_device_priv_data
)
1912 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
1913 sas_device_priv_data
->sas_target
->tm_busy
= 1;
1915 ioc
->ignore_loginfos
= 1;
1921 * mpt2sas_scsih_clear_tm_flag - clear per target tm_busy
1922 * @ioc: per adapter object
1923 * @handle: device handle
1925 * During taskmangement request, we need to freeze the device queue.
1928 mpt2sas_scsih_clear_tm_flag(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
1930 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1931 struct scsi_device
*sdev
;
1934 shost_for_each_device(sdev
, ioc
->shost
) {
1937 sas_device_priv_data
= sdev
->hostdata
;
1938 if (!sas_device_priv_data
)
1940 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
1941 sas_device_priv_data
->sas_target
->tm_busy
= 0;
1943 ioc
->ignore_loginfos
= 0;
1950 * mpt2sas_scsih_issue_tm - main routine for sending tm requests
1951 * @ioc: per adapter struct
1952 * @device_handle: device handle
1953 * @channel: the channel assigned by the OS
1954 * @id: the id assigned by the OS
1956 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
1957 * @smid_task: smid assigned to the task
1958 * @timeout: timeout in seconds
1961 * A generic API for sending task management requests to firmware.
1963 * The callback index is set inside `ioc->tm_cb_idx`.
1965 * Return SUCCESS or FAILED.
1968 mpt2sas_scsih_issue_tm(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
, uint channel
,
1969 uint id
, uint lun
, u8 type
, u16 smid_task
, ulong timeout
,
1970 struct scsi_cmnd
*scmd
)
1972 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
1973 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
1976 unsigned long timeleft
;
1977 struct scsi_cmnd
*scmd_lookup
;
1980 mutex_lock(&ioc
->tm_cmds
.mutex
);
1981 if (ioc
->tm_cmds
.status
!= MPT2_CMD_NOT_USED
) {
1982 printk(MPT2SAS_INFO_FMT
"%s: tm_cmd busy!!!\n",
1983 __func__
, ioc
->name
);
1988 if (ioc
->shost_recovery
|| ioc
->remove_host
) {
1989 printk(MPT2SAS_INFO_FMT
"%s: host reset in progress!\n",
1990 __func__
, ioc
->name
);
1995 ioc_state
= mpt2sas_base_get_iocstate(ioc
, 0);
1996 if (ioc_state
& MPI2_DOORBELL_USED
) {
1997 dhsprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"unexpected doorbell "
1998 "active!\n", ioc
->name
));
1999 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2005 if ((ioc_state
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_FAULT
) {
2006 mpt2sas_base_fault_info(ioc
, ioc_state
&
2007 MPI2_DOORBELL_DATA_MASK
);
2008 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2014 smid
= mpt2sas_base_get_smid_hpr(ioc
, ioc
->tm_cb_idx
);
2016 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
2017 ioc
->name
, __func__
);
2022 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"sending tm: handle(0x%04x),"
2023 " task_type(0x%02x), smid(%d)\n", ioc
->name
, handle
, type
,
2025 ioc
->tm_cmds
.status
= MPT2_CMD_PENDING
;
2026 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
2027 ioc
->tm_cmds
.smid
= smid
;
2028 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
2029 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
2030 mpi_request
->DevHandle
= cpu_to_le16(handle
);
2031 mpi_request
->TaskType
= type
;
2032 mpi_request
->TaskMID
= cpu_to_le16(smid_task
);
2033 int_to_scsilun(lun
, (struct scsi_lun
*)mpi_request
->LUN
);
2034 mpt2sas_scsih_set_tm_flag(ioc
, handle
);
2035 init_completion(&ioc
->tm_cmds
.done
);
2036 mpt2sas_base_put_smid_hi_priority(ioc
, smid
);
2037 timeleft
= wait_for_completion_timeout(&ioc
->tm_cmds
.done
, timeout
*HZ
);
2038 if (!(ioc
->tm_cmds
.status
& MPT2_CMD_COMPLETE
)) {
2039 printk(MPT2SAS_ERR_FMT
"%s: timeout\n",
2040 ioc
->name
, __func__
);
2041 _debug_dump_mf(mpi_request
,
2042 sizeof(Mpi2SCSITaskManagementRequest_t
)/4);
2043 if (!(ioc
->tm_cmds
.status
& MPT2_CMD_RESET
)) {
2044 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2047 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
2048 mpt2sas_scsih_clear_tm_flag(ioc
, handle
);
2053 if (ioc
->tm_cmds
.status
& MPT2_CMD_REPLY_VALID
) {
2054 mpi_reply
= ioc
->tm_cmds
.reply
;
2055 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"complete tm: "
2056 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
2057 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
2058 le32_to_cpu(mpi_reply
->IOCLogInfo
),
2059 le32_to_cpu(mpi_reply
->TerminationCount
)));
2060 if (ioc
->logging_level
& MPT_DEBUG_TM
) {
2061 _scsih_response_code(ioc
, mpi_reply
->ResponseCode
);
2062 if (mpi_reply
->IOCStatus
)
2063 _debug_dump_mf(mpi_request
,
2064 sizeof(Mpi2SCSITaskManagementRequest_t
)/4);
2069 * Check to see the commands were terminated.
2070 * This is only needed for eh callbacks, hence the scmd check.
2074 goto bypass_sanity_checks
;
2076 case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
:
2077 scmd_lookup
= _scsih_scsi_lookup_get(ioc
, smid_task
);
2078 if (scmd_lookup
&& (scmd_lookup
->serial_number
==
2079 scmd
->serial_number
))
2085 case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
:
2086 if (_scsih_scsi_lookup_find_by_target(ioc
, id
, channel
))
2092 case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET
:
2093 if (_scsih_scsi_lookup_find_by_lun(ioc
, id
, lun
, channel
))
2100 bypass_sanity_checks
:
2102 mpt2sas_scsih_clear_tm_flag(ioc
, handle
);
2103 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
2104 mutex_unlock(&ioc
->tm_cmds
.mutex
);
2109 mutex_unlock(&ioc
->tm_cmds
.mutex
);
2114 * _scsih_abort - eh threads main abort routine
2115 * @sdev: scsi device struct
2117 * Returns SUCCESS if command aborted else FAILED
2120 _scsih_abort(struct scsi_cmnd
*scmd
)
2122 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2123 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2128 printk(MPT2SAS_INFO_FMT
"attempting task abort! scmd(%p)\n",
2130 scsi_print_command(scmd
);
2132 sas_device_priv_data
= scmd
->device
->hostdata
;
2133 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2134 printk(MPT2SAS_INFO_FMT
"device been deleted! scmd(%p)\n",
2136 scmd
->result
= DID_NO_CONNECT
<< 16;
2137 scmd
->scsi_done(scmd
);
2142 /* search for the command */
2143 smid
= _scsih_scsi_lookup_find_by_scmd(ioc
, scmd
);
2145 scmd
->result
= DID_RESET
<< 16;
2150 /* for hidden raid components and volumes this is not supported */
2151 if (sas_device_priv_data
->sas_target
->flags
&
2152 MPT_TARGET_FLAGS_RAID_COMPONENT
||
2153 sas_device_priv_data
->sas_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
2154 scmd
->result
= DID_RESET
<< 16;
2159 mpt2sas_halt_firmware(ioc
);
2161 handle
= sas_device_priv_data
->sas_target
->handle
;
2162 r
= mpt2sas_scsih_issue_tm(ioc
, handle
, scmd
->device
->channel
,
2163 scmd
->device
->id
, scmd
->device
->lun
,
2164 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
, smid
, 30, scmd
);
2167 printk(MPT2SAS_INFO_FMT
"task abort: %s scmd(%p)\n",
2168 ioc
->name
, ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2173 * _scsih_dev_reset - eh threads main device reset routine
2174 * @sdev: scsi device struct
2176 * Returns SUCCESS if command aborted else FAILED
2179 _scsih_dev_reset(struct scsi_cmnd
*scmd
)
2181 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2182 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2183 struct _sas_device
*sas_device
;
2184 unsigned long flags
;
2188 printk(MPT2SAS_INFO_FMT
"attempting device reset! scmd(%p)\n",
2190 scsi_print_command(scmd
);
2192 sas_device_priv_data
= scmd
->device
->hostdata
;
2193 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2194 printk(MPT2SAS_INFO_FMT
"device been deleted! scmd(%p)\n",
2196 scmd
->result
= DID_NO_CONNECT
<< 16;
2197 scmd
->scsi_done(scmd
);
2202 /* for hidden raid components obtain the volume_handle */
2204 if (sas_device_priv_data
->sas_target
->flags
&
2205 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2206 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2207 sas_device
= _scsih_sas_device_find_by_handle(ioc
,
2208 sas_device_priv_data
->sas_target
->handle
);
2210 handle
= sas_device
->volume_handle
;
2211 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2213 handle
= sas_device_priv_data
->sas_target
->handle
;
2216 scmd
->result
= DID_RESET
<< 16;
2221 r
= mpt2sas_scsih_issue_tm(ioc
, handle
, scmd
->device
->channel
,
2222 scmd
->device
->id
, scmd
->device
->lun
,
2223 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET
, 0, 30, scmd
);
2226 printk(MPT2SAS_INFO_FMT
"device reset: %s scmd(%p)\n",
2227 ioc
->name
, ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2232 * _scsih_target_reset - eh threads main target reset routine
2233 * @sdev: scsi device struct
2235 * Returns SUCCESS if command aborted else FAILED
2238 _scsih_target_reset(struct scsi_cmnd
*scmd
)
2240 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2241 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2242 struct _sas_device
*sas_device
;
2243 unsigned long flags
;
2247 printk(MPT2SAS_INFO_FMT
"attempting target reset! scmd(%p)\n",
2249 scsi_print_command(scmd
);
2251 sas_device_priv_data
= scmd
->device
->hostdata
;
2252 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2253 printk(MPT2SAS_INFO_FMT
"target been deleted! scmd(%p)\n",
2255 scmd
->result
= DID_NO_CONNECT
<< 16;
2256 scmd
->scsi_done(scmd
);
2261 /* for hidden raid components obtain the volume_handle */
2263 if (sas_device_priv_data
->sas_target
->flags
&
2264 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2265 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2266 sas_device
= _scsih_sas_device_find_by_handle(ioc
,
2267 sas_device_priv_data
->sas_target
->handle
);
2269 handle
= sas_device
->volume_handle
;
2270 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2272 handle
= sas_device_priv_data
->sas_target
->handle
;
2275 scmd
->result
= DID_RESET
<< 16;
2280 r
= mpt2sas_scsih_issue_tm(ioc
, handle
, scmd
->device
->channel
,
2281 scmd
->device
->id
, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
, 0,
2285 printk(MPT2SAS_INFO_FMT
"target reset: %s scmd(%p)\n",
2286 ioc
->name
, ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2291 * _scsih_host_reset - eh threads main host reset routine
2292 * @sdev: scsi device struct
2294 * Returns SUCCESS if command aborted else FAILED
2297 _scsih_host_reset(struct scsi_cmnd
*scmd
)
2299 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2302 printk(MPT2SAS_INFO_FMT
"attempting host reset! scmd(%p)\n",
2304 scsi_print_command(scmd
);
2306 retval
= mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2308 r
= (retval
< 0) ? FAILED
: SUCCESS
;
2309 printk(MPT2SAS_INFO_FMT
"host reset: %s scmd(%p)\n",
2310 ioc
->name
, ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2316 * _scsih_fw_event_add - insert and queue up fw_event
2317 * @ioc: per adapter object
2318 * @fw_event: object describing the event
2319 * Context: This function will acquire ioc->fw_event_lock.
2321 * This adds the firmware event object into link list, then queues it up to
2322 * be processed from user context.
2327 _scsih_fw_event_add(struct MPT2SAS_ADAPTER
*ioc
, struct fw_event_work
*fw_event
)
2329 unsigned long flags
;
2331 if (ioc
->firmware_event_thread
== NULL
)
2334 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2335 list_add_tail(&fw_event
->list
, &ioc
->fw_event_list
);
2336 INIT_DELAYED_WORK(&fw_event
->delayed_work
, _firmware_event_work
);
2337 queue_delayed_work(ioc
->firmware_event_thread
,
2338 &fw_event
->delayed_work
, 0);
2339 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2343 * _scsih_fw_event_free - delete fw_event
2344 * @ioc: per adapter object
2345 * @fw_event: object describing the event
2346 * Context: This function will acquire ioc->fw_event_lock.
2348 * This removes firmware event object from link list, frees associated memory.
2353 _scsih_fw_event_free(struct MPT2SAS_ADAPTER
*ioc
, struct fw_event_work
2356 unsigned long flags
;
2358 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2359 list_del(&fw_event
->list
);
2360 kfree(fw_event
->event_data
);
2362 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2367 * _scsih_queue_rescan - queue a topology rescan from user context
2368 * @ioc: per adapter object
2373 _scsih_queue_rescan(struct MPT2SAS_ADAPTER
*ioc
)
2375 struct fw_event_work
*fw_event
;
2377 if (ioc
->wait_for_port_enable_to_complete
)
2379 fw_event
= kzalloc(sizeof(struct fw_event_work
), GFP_ATOMIC
);
2382 fw_event
->event
= MPT2SAS_RESCAN_AFTER_HOST_RESET
;
2383 fw_event
->ioc
= ioc
;
2384 _scsih_fw_event_add(ioc
, fw_event
);
2388 * _scsih_fw_event_cleanup_queue - cleanup event queue
2389 * @ioc: per adapter object
2391 * Walk the firmware event queue, either killing timers, or waiting
2392 * for outstanding events to complete
2397 _scsih_fw_event_cleanup_queue(struct MPT2SAS_ADAPTER
*ioc
)
2399 struct fw_event_work
*fw_event
, *next
;
2401 if (list_empty(&ioc
->fw_event_list
) ||
2402 !ioc
->firmware_event_thread
|| in_interrupt())
2405 list_for_each_entry_safe(fw_event
, next
, &ioc
->fw_event_list
, list
) {
2406 if (cancel_delayed_work(&fw_event
->delayed_work
)) {
2407 _scsih_fw_event_free(ioc
, fw_event
);
2410 fw_event
->cancel_pending_work
= 1;
2415 * _scsih_ublock_io_device - set the device state to SDEV_RUNNING
2416 * @ioc: per adapter object
2417 * @handle: device handle
2419 * During device pull we need to appropiately set the sdev state.
2422 _scsih_ublock_io_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
2424 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2425 struct scsi_device
*sdev
;
2427 shost_for_each_device(sdev
, ioc
->shost
) {
2428 sas_device_priv_data
= sdev
->hostdata
;
2429 if (!sas_device_priv_data
)
2431 if (!sas_device_priv_data
->block
)
2433 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2434 dewtprintk(ioc
, sdev_printk(KERN_INFO
, sdev
,
2435 MPT2SAS_INFO_FMT
"SDEV_RUNNING: "
2436 "handle(0x%04x)\n", ioc
->name
, handle
));
2437 sas_device_priv_data
->block
= 0;
2438 scsi_internal_device_unblock(sdev
);
2444 * _scsih_block_io_device - set the device state to SDEV_BLOCK
2445 * @ioc: per adapter object
2446 * @handle: device handle
2448 * During device pull we need to appropiately set the sdev state.
2451 _scsih_block_io_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
2453 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2454 struct scsi_device
*sdev
;
2456 shost_for_each_device(sdev
, ioc
->shost
) {
2457 sas_device_priv_data
= sdev
->hostdata
;
2458 if (!sas_device_priv_data
)
2460 if (sas_device_priv_data
->block
)
2462 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2463 dewtprintk(ioc
, sdev_printk(KERN_INFO
, sdev
,
2464 MPT2SAS_INFO_FMT
"SDEV_BLOCK: "
2465 "handle(0x%04x)\n", ioc
->name
, handle
));
2466 sas_device_priv_data
->block
= 1;
2467 scsi_internal_device_block(sdev
);
2473 * _scsih_block_io_to_children_attached_to_ex
2474 * @ioc: per adapter object
2475 * @sas_expander: the sas_device object
2477 * This routine set sdev state to SDEV_BLOCK for all devices
2478 * attached to this expander. This function called when expander is
2482 _scsih_block_io_to_children_attached_to_ex(struct MPT2SAS_ADAPTER
*ioc
,
2483 struct _sas_node
*sas_expander
)
2485 struct _sas_port
*mpt2sas_port
;
2486 struct _sas_device
*sas_device
;
2487 struct _sas_node
*expander_sibling
;
2488 unsigned long flags
;
2493 list_for_each_entry(mpt2sas_port
,
2494 &sas_expander
->sas_port_list
, port_list
) {
2495 if (mpt2sas_port
->remote_identify
.device_type
==
2497 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2499 mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
2500 mpt2sas_port
->remote_identify
.sas_address
);
2501 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2504 _scsih_block_io_device(ioc
, sas_device
->handle
);
2508 list_for_each_entry(mpt2sas_port
,
2509 &sas_expander
->sas_port_list
, port_list
) {
2511 if (mpt2sas_port
->remote_identify
.device_type
==
2512 MPI2_SAS_DEVICE_INFO_EDGE_EXPANDER
||
2513 mpt2sas_port
->remote_identify
.device_type
==
2514 MPI2_SAS_DEVICE_INFO_FANOUT_EXPANDER
) {
2516 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
2518 mpt2sas_scsih_expander_find_by_sas_address(
2519 ioc
, mpt2sas_port
->remote_identify
.sas_address
);
2520 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
2521 _scsih_block_io_to_children_attached_to_ex(ioc
,
2528 * _scsih_block_io_to_children_attached_directly
2529 * @ioc: per adapter object
2530 * @event_data: topology change event data
2532 * This routine set sdev state to SDEV_BLOCK for all devices
2533 * direct attached during device pull.
2536 _scsih_block_io_to_children_attached_directly(struct MPT2SAS_ADAPTER
*ioc
,
2537 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
2544 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
2545 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
2548 phy_number
= event_data
->StartPhyNum
+ i
;
2549 reason_code
= event_data
->PHY
[i
].PhyStatus
&
2550 MPI2_EVENT_SAS_TOPO_RC_MASK
;
2551 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
)
2552 _scsih_block_io_device(ioc
, handle
);
2557 * _scsih_tm_tr_send - send task management request
2558 * @ioc: per adapter object
2559 * @handle: device handle
2560 * Context: interrupt time.
2562 * This code is to initiate the device removal handshake protocal
2563 * with controller firmware. This function will issue target reset
2564 * using high priority request queue. It will send a sas iounit
2565 * controll request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
2567 * This is designed to send muliple task management request at the same
2568 * time to the fifo. If the fifo is full, we will append the request,
2569 * and process it in a future completion.
2572 _scsih_tm_tr_send(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
2574 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
2576 struct _sas_device
*sas_device
;
2577 unsigned long flags
;
2578 struct _tr_list
*delayed_tr
;
2580 if (ioc
->shost_recovery
|| ioc
->remove_host
) {
2581 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host reset in "
2582 "progress!\n", __func__
, ioc
->name
));
2586 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2587 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
2588 if (sas_device
&& sas_device
->hidden_raid_component
) {
2589 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2592 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2594 smid
= mpt2sas_base_get_smid_hpr(ioc
, ioc
->tm_tr_cb_idx
);
2596 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
2599 INIT_LIST_HEAD(&delayed_tr
->list
);
2600 delayed_tr
->handle
= handle
;
2601 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_list
);
2602 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
2603 "DELAYED:tr:handle(0x%04x), (open)\n",
2604 ioc
->name
, handle
));
2608 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"tr_send:handle(0x%04x), "
2609 "(open), smid(%d), cb(%d)\n", ioc
->name
, handle
, smid
,
2610 ioc
->tm_tr_cb_idx
));
2611 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
2612 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
2613 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
2614 mpi_request
->DevHandle
= cpu_to_le16(handle
);
2615 mpi_request
->TaskType
= MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
;
2616 mpt2sas_base_put_smid_hi_priority(ioc
, smid
);
2622 * _scsih_sas_control_complete - completion routine
2623 * @ioc: per adapter object
2624 * @smid: system request message index
2625 * @msix_index: MSIX table index supplied by the OS
2626 * @reply: reply message frame(lower 32bit addr)
2627 * Context: interrupt time.
2629 * This is the sas iounit controll completion routine.
2630 * This code is part of the code to initiate the device removal
2631 * handshake protocal with controller firmware.
2633 * Return 1 meaning mf should be freed from _base_interrupt
2634 * 0 means the mf is freed from this function.
2637 _scsih_sas_control_complete(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
,
2638 u8 msix_index
, u32 reply
)
2640 Mpi2SasIoUnitControlReply_t
*mpi_reply
=
2641 mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
2643 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
2644 "sc_complete:handle(0x%04x), (open) "
2645 "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
2646 ioc
->name
, le16_to_cpu(mpi_reply
->DevHandle
), smid
,
2647 le16_to_cpu(mpi_reply
->IOCStatus
),
2648 le32_to_cpu(mpi_reply
->IOCLogInfo
)));
2653 * _scsih_tm_tr_complete -
2654 * @ioc: per adapter object
2655 * @smid: system request message index
2656 * @msix_index: MSIX table index supplied by the OS
2657 * @reply: reply message frame(lower 32bit addr)
2658 * Context: interrupt time.
2660 * This is the target reset completion routine.
2661 * This code is part of the code to initiate the device removal
2662 * handshake protocal with controller firmware.
2663 * It will send a sas iounit controll request (MPI2_SAS_OP_REMOVE_DEVICE)
2665 * Return 1 meaning mf should be freed from _base_interrupt
2666 * 0 means the mf is freed from this function.
2669 _scsih_tm_tr_complete(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
,
2673 Mpi2SCSITaskManagementRequest_t
*mpi_request_tm
;
2674 Mpi2SCSITaskManagementReply_t
*mpi_reply
=
2675 mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
2676 Mpi2SasIoUnitControlRequest_t
*mpi_request
;
2678 struct _tr_list
*delayed_tr
;
2680 if (ioc
->shost_recovery
|| ioc
->remove_host
) {
2681 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host reset in "
2682 "progress!\n", __func__
, ioc
->name
));
2686 mpi_request_tm
= mpt2sas_base_get_msg_frame(ioc
, smid
);
2687 handle
= le16_to_cpu(mpi_request_tm
->DevHandle
);
2688 if (handle
!= le16_to_cpu(mpi_reply
->DevHandle
)) {
2689 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"spurious interrupt: "
2690 "handle(0x%04x:0x%04x), smid(%d)!!!\n", ioc
->name
, handle
,
2691 le16_to_cpu(mpi_reply
->DevHandle
), smid
));
2695 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
2696 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
2697 "loginfo(0x%08x), completed(%d)\n", ioc
->name
,
2698 handle
, smid
, le16_to_cpu(mpi_reply
->IOCStatus
),
2699 le32_to_cpu(mpi_reply
->IOCLogInfo
),
2700 le32_to_cpu(mpi_reply
->TerminationCount
)));
2702 smid_sas_ctrl
= mpt2sas_base_get_smid(ioc
, ioc
->tm_sas_control_cb_idx
);
2703 if (!smid_sas_ctrl
) {
2704 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
2705 ioc
->name
, __func__
);
2709 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"sc_send:handle(0x%04x), "
2710 "(open), smid(%d), cb(%d)\n", ioc
->name
, handle
, smid_sas_ctrl
,
2711 ioc
->tm_sas_control_cb_idx
));
2712 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid_sas_ctrl
);
2713 memset(mpi_request
, 0, sizeof(Mpi2SasIoUnitControlRequest_t
));
2714 mpi_request
->Function
= MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
;
2715 mpi_request
->Operation
= MPI2_SAS_OP_REMOVE_DEVICE
;
2716 mpi_request
->DevHandle
= mpi_request_tm
->DevHandle
;
2717 mpt2sas_base_put_smid_default(ioc
, smid_sas_ctrl
);
2719 if (!list_empty(&ioc
->delayed_tr_list
)) {
2720 delayed_tr
= list_entry(ioc
->delayed_tr_list
.next
,
2721 struct _tr_list
, list
);
2722 mpt2sas_base_free_smid(ioc
, smid
);
2723 _scsih_tm_tr_send(ioc
, delayed_tr
->handle
);
2724 list_del(&delayed_tr
->list
);
2726 return 0; /* tells base_interrupt not to free mf */
2732 * _scsih_check_topo_delete_events - sanity check on topo events
2733 * @ioc: per adapter object
2734 * @event_data: the event data payload
2736 * This routine added to better handle cable breaker.
2738 * This handles the case where driver recieves multiple expander
2739 * add and delete events in a single shot. When there is a delete event
2740 * the routine will void any pending add events waiting in the event queue.
2745 _scsih_check_topo_delete_events(struct MPT2SAS_ADAPTER
*ioc
,
2746 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
2748 struct fw_event_work
*fw_event
;
2749 Mpi2EventDataSasTopologyChangeList_t
*local_event_data
;
2750 u16 expander_handle
;
2751 struct _sas_node
*sas_expander
;
2752 unsigned long flags
;
2756 for (i
= 0 ; i
< event_data
->NumEntries
; i
++) {
2757 if (event_data
->PHY
[i
].PhyStatus
&
2758 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT
)
2760 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
2763 reason_code
= event_data
->PHY
[i
].PhyStatus
&
2764 MPI2_EVENT_SAS_TOPO_RC_MASK
;
2765 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
)
2766 _scsih_tm_tr_send(ioc
, handle
);
2769 expander_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
2770 if (expander_handle
< ioc
->sas_hba
.num_phys
) {
2771 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
2775 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
2776 || event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
) {
2777 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
2778 sas_expander
= mpt2sas_scsih_expander_find_by_handle(ioc
,
2780 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
2781 _scsih_block_io_to_children_attached_to_ex(ioc
, sas_expander
);
2782 } else if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_RESPONDING
)
2783 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
2785 if (event_data
->ExpStatus
!= MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
)
2788 /* mark ignore flag for pending events */
2789 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2790 list_for_each_entry(fw_event
, &ioc
->fw_event_list
, list
) {
2791 if (fw_event
->event
!= MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
||
2794 local_event_data
= fw_event
->event_data
;
2795 if (local_event_data
->ExpStatus
==
2796 MPI2_EVENT_SAS_TOPO_ES_ADDED
||
2797 local_event_data
->ExpStatus
==
2798 MPI2_EVENT_SAS_TOPO_ES_RESPONDING
) {
2799 if (le16_to_cpu(local_event_data
->ExpanderDevHandle
) ==
2801 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
2802 "setting ignoring flag\n", ioc
->name
));
2803 fw_event
->ignore
= 1;
2807 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2811 * _scsih_flush_running_cmds - completing outstanding commands.
2812 * @ioc: per adapter object
2814 * The flushing out of all pending scmd commands following host reset,
2815 * where all IO is dropped to the floor.
2820 _scsih_flush_running_cmds(struct MPT2SAS_ADAPTER
*ioc
)
2822 struct scsi_cmnd
*scmd
;
2826 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
2827 scmd
= _scsih_scsi_lookup_get(ioc
, smid
);
2831 mpt2sas_base_free_smid(ioc
, smid
);
2832 scsi_dma_unmap(scmd
);
2833 scmd
->result
= DID_RESET
<< 16;
2834 scmd
->scsi_done(scmd
);
2836 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"completing %d cmds\n",
2841 * _scsih_setup_eedp - setup MPI request for EEDP transfer
2842 * @scmd: pointer to scsi command object
2843 * @mpi_request: pointer to the SCSI_IO reqest message frame
2845 * Supporting protection 1 and 3.
2850 _scsih_setup_eedp(struct scsi_cmnd
*scmd
, Mpi2SCSIIORequest_t
*mpi_request
)
2853 unsigned char prot_op
= scsi_get_prot_op(scmd
);
2854 unsigned char prot_type
= scsi_get_prot_type(scmd
);
2856 if (prot_type
== SCSI_PROT_DIF_TYPE0
||
2857 prot_type
== SCSI_PROT_DIF_TYPE2
||
2858 prot_op
== SCSI_PROT_NORMAL
)
2861 if (prot_op
== SCSI_PROT_READ_STRIP
)
2862 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP
;
2863 else if (prot_op
== SCSI_PROT_WRITE_INSERT
)
2864 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_INSERT_OP
;
2868 switch (prot_type
) {
2869 case SCSI_PROT_DIF_TYPE1
:
2872 * enable ref/guard checking
2873 * auto increment ref tag
2875 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG
|
2876 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG
|
2877 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
2878 mpi_request
->CDB
.EEDP32
.PrimaryReferenceTag
=
2879 cpu_to_be32(scsi_get_lba(scmd
));
2883 case SCSI_PROT_DIF_TYPE3
:
2886 * enable guard checking
2888 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
2891 mpi_request
->EEDPBlockSize
= cpu_to_le32(scmd
->device
->sector_size
);
2892 mpi_request
->EEDPFlags
= cpu_to_le16(eedp_flags
);
2896 * _scsih_eedp_error_handling - return sense code for EEDP errors
2897 * @scmd: pointer to scsi command object
2898 * @ioc_status: ioc status
2903 _scsih_eedp_error_handling(struct scsi_cmnd
*scmd
, u16 ioc_status
)
2909 switch (ioc_status
) {
2910 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
2913 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
2916 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
2924 if (scmd
->sc_data_direction
== DMA_TO_DEVICE
) {
2925 sk
= ILLEGAL_REQUEST
;
2926 host_byte
= DID_ABORT
;
2928 sk
= ABORTED_COMMAND
;
2932 scsi_build_sense_buffer(0, scmd
->sense_buffer
, sk
, 0x10, ascq
);
2933 scmd
->result
= DRIVER_SENSE
<< 24 | (host_byte
<< 16) |
2934 SAM_STAT_CHECK_CONDITION
;
2938 * _scsih_qcmd - main scsi request entry point
2939 * @scmd: pointer to scsi command object
2940 * @done: function pointer to be invoked on completion
2942 * The callback index is set inside `ioc->scsi_io_cb_idx`.
2944 * Returns 0 on success. If there's a failure, return either:
2945 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
2946 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
2949 _scsih_qcmd(struct scsi_cmnd
*scmd
, void (*done
)(struct scsi_cmnd
*))
2951 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2952 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2953 struct MPT2SAS_TARGET
*sas_target_priv_data
;
2954 Mpi2SCSIIORequest_t
*mpi_request
;
2958 scmd
->scsi_done
= done
;
2959 sas_device_priv_data
= scmd
->device
->hostdata
;
2960 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2961 scmd
->result
= DID_NO_CONNECT
<< 16;
2962 scmd
->scsi_done(scmd
);
2966 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
2967 /* invalid device handle */
2968 if (sas_target_priv_data
->handle
== MPT2SAS_INVALID_DEVICE_HANDLE
) {
2969 scmd
->result
= DID_NO_CONNECT
<< 16;
2970 scmd
->scsi_done(scmd
);
2974 /* host recovery or link resets sent via IOCTLs */
2975 if (ioc
->shost_recovery
|| ioc
->ioc_link_reset_in_progress
)
2976 return SCSI_MLQUEUE_HOST_BUSY
;
2977 /* device busy with task managment */
2978 else if (sas_device_priv_data
->block
|| sas_target_priv_data
->tm_busy
)
2979 return SCSI_MLQUEUE_DEVICE_BUSY
;
2980 /* device has been deleted */
2981 else if (sas_target_priv_data
->deleted
) {
2982 scmd
->result
= DID_NO_CONNECT
<< 16;
2983 scmd
->scsi_done(scmd
);
2987 if (scmd
->sc_data_direction
== DMA_FROM_DEVICE
)
2988 mpi_control
= MPI2_SCSIIO_CONTROL_READ
;
2989 else if (scmd
->sc_data_direction
== DMA_TO_DEVICE
)
2990 mpi_control
= MPI2_SCSIIO_CONTROL_WRITE
;
2992 mpi_control
= MPI2_SCSIIO_CONTROL_NODATATRANSFER
;
2995 if (!(sas_device_priv_data
->flags
& MPT_DEVICE_FLAGS_INIT
)) {
2996 if (scmd
->device
->tagged_supported
) {
2997 if (scmd
->device
->ordered_tags
)
2998 mpi_control
|= MPI2_SCSIIO_CONTROL_ORDEREDQ
;
3000 mpi_control
|= MPI2_SCSIIO_CONTROL_SIMPLEQ
;
3002 /* MPI Revision I (UNIT = 0xA) - removed MPI2_SCSIIO_CONTROL_UNTAGGED */
3003 /* mpi_control |= MPI2_SCSIIO_CONTROL_UNTAGGED;
3005 mpi_control
|= (0x500);
3008 mpi_control
|= MPI2_SCSIIO_CONTROL_SIMPLEQ
;
3009 /* Make sure Device is not raid volume */
3010 if (!_scsih_is_raid(&scmd
->device
->sdev_gendev
) &&
3011 sas_is_tlr_enabled(scmd
->device
))
3012 mpi_control
|= MPI2_SCSIIO_CONTROL_TLR_ON
;
3014 smid
= mpt2sas_base_get_smid_scsiio(ioc
, ioc
->scsi_io_cb_idx
, scmd
);
3016 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
3017 ioc
->name
, __func__
);
3020 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3021 memset(mpi_request
, 0, sizeof(Mpi2SCSIIORequest_t
));
3022 _scsih_setup_eedp(scmd
, mpi_request
);
3023 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
3024 if (sas_device_priv_data
->sas_target
->flags
&
3025 MPT_TARGET_FLAGS_RAID_COMPONENT
)
3026 mpi_request
->Function
= MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
;
3028 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
3029 mpi_request
->DevHandle
=
3030 cpu_to_le16(sas_device_priv_data
->sas_target
->handle
);
3031 mpi_request
->DataLength
= cpu_to_le32(scsi_bufflen(scmd
));
3032 mpi_request
->Control
= cpu_to_le32(mpi_control
);
3033 mpi_request
->IoFlags
= cpu_to_le16(scmd
->cmd_len
);
3034 mpi_request
->MsgFlags
= MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR
;
3035 mpi_request
->SenseBufferLength
= SCSI_SENSE_BUFFERSIZE
;
3036 mpi_request
->SenseBufferLowAddress
=
3037 mpt2sas_base_get_sense_buffer_dma(ioc
, smid
);
3038 mpi_request
->SGLOffset0
= offsetof(Mpi2SCSIIORequest_t
, SGL
) / 4;
3039 mpi_request
->SGLFlags
= cpu_to_le16(MPI2_SCSIIO_SGLFLAGS_TYPE_MPI
+
3040 MPI2_SCSIIO_SGLFLAGS_SYSTEM_ADDR
);
3041 mpi_request
->VF_ID
= 0; /* TODO */
3042 mpi_request
->VP_ID
= 0;
3043 int_to_scsilun(sas_device_priv_data
->lun
, (struct scsi_lun
*)
3045 memcpy(mpi_request
->CDB
.CDB32
, scmd
->cmnd
, scmd
->cmd_len
);
3047 if (!mpi_request
->DataLength
) {
3048 mpt2sas_base_build_zero_len_sge(ioc
, &mpi_request
->SGL
);
3050 if (_scsih_build_scatter_gather(ioc
, scmd
, smid
)) {
3051 mpt2sas_base_free_smid(ioc
, smid
);
3056 if (likely(mpi_request
->Function
== MPI2_FUNCTION_SCSI_IO_REQUEST
))
3057 mpt2sas_base_put_smid_scsi_io(ioc
, smid
,
3058 sas_device_priv_data
->sas_target
->handle
);
3060 mpt2sas_base_put_smid_default(ioc
, smid
);
3064 return SCSI_MLQUEUE_HOST_BUSY
;
3068 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
3069 * @sense_buffer: sense data returned by target
3070 * @data: normalized skey/asc/ascq
3075 _scsih_normalize_sense(char *sense_buffer
, struct sense_info
*data
)
3077 if ((sense_buffer
[0] & 0x7F) >= 0x72) {
3078 /* descriptor format */
3079 data
->skey
= sense_buffer
[1] & 0x0F;
3080 data
->asc
= sense_buffer
[2];
3081 data
->ascq
= sense_buffer
[3];
3084 data
->skey
= sense_buffer
[2] & 0x0F;
3085 data
->asc
= sense_buffer
[12];
3086 data
->ascq
= sense_buffer
[13];
3090 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3092 * _scsih_scsi_ioc_info - translated non-successfull SCSI_IO request
3093 * @ioc: per adapter object
3094 * @scmd: pointer to scsi command object
3095 * @mpi_reply: reply mf payload returned from firmware
3097 * scsi_status - SCSI Status code returned from target device
3098 * scsi_state - state info associated with SCSI_IO determined by ioc
3099 * ioc_status - ioc supplied status info
3104 _scsih_scsi_ioc_info(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
,
3105 Mpi2SCSIIOReply_t
*mpi_reply
, u16 smid
)
3109 u16 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) &
3110 MPI2_IOCSTATUS_MASK
;
3111 u8 scsi_state
= mpi_reply
->SCSIState
;
3112 u8 scsi_status
= mpi_reply
->SCSIStatus
;
3113 char *desc_ioc_state
= NULL
;
3114 char *desc_scsi_status
= NULL
;
3115 char *desc_scsi_state
= ioc
->tmp_string
;
3116 u32 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
3118 if (log_info
== 0x31170000)
3121 switch (ioc_status
) {
3122 case MPI2_IOCSTATUS_SUCCESS
:
3123 desc_ioc_state
= "success";
3125 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
3126 desc_ioc_state
= "invalid function";
3128 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
3129 desc_ioc_state
= "scsi recovered error";
3131 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE
:
3132 desc_ioc_state
= "scsi invalid dev handle";
3134 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
3135 desc_ioc_state
= "scsi device not there";
3137 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
3138 desc_ioc_state
= "scsi data overrun";
3140 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
3141 desc_ioc_state
= "scsi data underrun";
3143 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
3144 desc_ioc_state
= "scsi io data error";
3146 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
3147 desc_ioc_state
= "scsi protocol error";
3149 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
3150 desc_ioc_state
= "scsi task terminated";
3152 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
3153 desc_ioc_state
= "scsi residual mismatch";
3155 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
3156 desc_ioc_state
= "scsi task mgmt failed";
3158 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
3159 desc_ioc_state
= "scsi ioc terminated";
3161 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
3162 desc_ioc_state
= "scsi ext terminated";
3164 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
3165 desc_ioc_state
= "eedp guard error";
3167 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
3168 desc_ioc_state
= "eedp ref tag error";
3170 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
3171 desc_ioc_state
= "eedp app tag error";
3174 desc_ioc_state
= "unknown";
3178 switch (scsi_status
) {
3179 case MPI2_SCSI_STATUS_GOOD
:
3180 desc_scsi_status
= "good";
3182 case MPI2_SCSI_STATUS_CHECK_CONDITION
:
3183 desc_scsi_status
= "check condition";
3185 case MPI2_SCSI_STATUS_CONDITION_MET
:
3186 desc_scsi_status
= "condition met";
3188 case MPI2_SCSI_STATUS_BUSY
:
3189 desc_scsi_status
= "busy";
3191 case MPI2_SCSI_STATUS_INTERMEDIATE
:
3192 desc_scsi_status
= "intermediate";
3194 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET
:
3195 desc_scsi_status
= "intermediate condmet";
3197 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT
:
3198 desc_scsi_status
= "reservation conflict";
3200 case MPI2_SCSI_STATUS_COMMAND_TERMINATED
:
3201 desc_scsi_status
= "command terminated";
3203 case MPI2_SCSI_STATUS_TASK_SET_FULL
:
3204 desc_scsi_status
= "task set full";
3206 case MPI2_SCSI_STATUS_ACA_ACTIVE
:
3207 desc_scsi_status
= "aca active";
3209 case MPI2_SCSI_STATUS_TASK_ABORTED
:
3210 desc_scsi_status
= "task aborted";
3213 desc_scsi_status
= "unknown";
3217 desc_scsi_state
[0] = '\0';
3219 desc_scsi_state
= " ";
3220 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
3221 strcat(desc_scsi_state
, "response info ");
3222 if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
3223 strcat(desc_scsi_state
, "state terminated ");
3224 if (scsi_state
& MPI2_SCSI_STATE_NO_SCSI_STATUS
)
3225 strcat(desc_scsi_state
, "no status ");
3226 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_FAILED
)
3227 strcat(desc_scsi_state
, "autosense failed ");
3228 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
)
3229 strcat(desc_scsi_state
, "autosense valid ");
3231 scsi_print_command(scmd
);
3232 printk(MPT2SAS_WARN_FMT
"\tdev handle(0x%04x), "
3233 "ioc_status(%s)(0x%04x), smid(%d)\n", ioc
->name
,
3234 le16_to_cpu(mpi_reply
->DevHandle
), desc_ioc_state
,
3236 printk(MPT2SAS_WARN_FMT
"\trequest_len(%d), underflow(%d), "
3237 "resid(%d)\n", ioc
->name
, scsi_bufflen(scmd
), scmd
->underflow
,
3238 scsi_get_resid(scmd
));
3239 printk(MPT2SAS_WARN_FMT
"\ttag(%d), transfer_count(%d), "
3240 "sc->result(0x%08x)\n", ioc
->name
, le16_to_cpu(mpi_reply
->TaskTag
),
3241 le32_to_cpu(mpi_reply
->TransferCount
), scmd
->result
);
3242 printk(MPT2SAS_WARN_FMT
"\tscsi_status(%s)(0x%02x), "
3243 "scsi_state(%s)(0x%02x)\n", ioc
->name
, desc_scsi_status
,
3244 scsi_status
, desc_scsi_state
, scsi_state
);
3246 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
3247 struct sense_info data
;
3248 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
3249 printk(MPT2SAS_WARN_FMT
"\t[sense_key,asc,ascq]: "
3250 "[0x%02x,0x%02x,0x%02x], count(%d)\n", ioc
->name
, data
.skey
,
3251 data
.asc
, data
.ascq
, le32_to_cpu(mpi_reply
->SenseCount
));
3254 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
) {
3255 response_info
= le32_to_cpu(mpi_reply
->ResponseInfo
);
3256 response_bytes
= (u8
*)&response_info
;
3257 _scsih_response_code(ioc
, response_bytes
[0]);
3263 * _scsih_smart_predicted_fault - illuminate Fault LED
3264 * @ioc: per adapter object
3265 * @handle: device handle
3270 _scsih_smart_predicted_fault(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
3272 Mpi2SepReply_t mpi_reply
;
3273 Mpi2SepRequest_t mpi_request
;
3274 struct scsi_target
*starget
;
3275 struct MPT2SAS_TARGET
*sas_target_priv_data
;
3276 Mpi2EventNotificationReply_t
*event_reply
;
3277 Mpi2EventDataSasDeviceStatusChange_t
*event_data
;
3278 struct _sas_device
*sas_device
;
3280 unsigned long flags
;
3282 /* only handle non-raid devices */
3283 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
3284 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
3286 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3289 starget
= sas_device
->starget
;
3290 sas_target_priv_data
= starget
->hostdata
;
3292 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
) ||
3293 ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
))) {
3294 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3297 starget_printk(KERN_WARNING
, starget
, "predicted fault\n");
3298 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3300 if (ioc
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_IBM
) {
3301 memset(&mpi_request
, 0, sizeof(Mpi2SepRequest_t
));
3302 mpi_request
.Function
= MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR
;
3303 mpi_request
.Action
= MPI2_SEP_REQ_ACTION_WRITE_STATUS
;
3304 mpi_request
.SlotStatus
=
3305 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT
);
3306 mpi_request
.DevHandle
= cpu_to_le16(handle
);
3307 mpi_request
.Flags
= MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS
;
3308 if ((mpt2sas_base_scsi_enclosure_processor(ioc
, &mpi_reply
,
3309 &mpi_request
)) != 0) {
3310 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3311 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3315 if (mpi_reply
.IOCStatus
|| mpi_reply
.IOCLogInfo
) {
3316 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3317 "enclosure_processor: ioc_status (0x%04x), "
3318 "loginfo(0x%08x)\n", ioc
->name
,
3319 le16_to_cpu(mpi_reply
.IOCStatus
),
3320 le32_to_cpu(mpi_reply
.IOCLogInfo
)));
3325 /* insert into event log */
3326 sz
= offsetof(Mpi2EventNotificationReply_t
, EventData
) +
3327 sizeof(Mpi2EventDataSasDeviceStatusChange_t
);
3328 event_reply
= kzalloc(sz
, GFP_KERNEL
);
3330 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3331 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3335 event_reply
->Function
= MPI2_FUNCTION_EVENT_NOTIFICATION
;
3336 event_reply
->Event
=
3337 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
);
3338 event_reply
->MsgLength
= sz
/4;
3339 event_reply
->EventDataLength
=
3340 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t
)/4);
3341 event_data
= (Mpi2EventDataSasDeviceStatusChange_t
*)
3342 event_reply
->EventData
;
3343 event_data
->ReasonCode
= MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
;
3344 event_data
->ASC
= 0x5D;
3345 event_data
->DevHandle
= cpu_to_le16(handle
);
3346 event_data
->SASAddress
= cpu_to_le64(sas_target_priv_data
->sas_address
);
3347 mpt2sas_ctl_add_to_event_log(ioc
, event_reply
);
3352 * _scsih_io_done - scsi request callback
3353 * @ioc: per adapter object
3354 * @smid: system request message index
3355 * @msix_index: MSIX table index supplied by the OS
3356 * @reply: reply message frame(lower 32bit addr)
3358 * Callback handler when using _scsih_qcmd.
3360 * Return 1 meaning mf should be freed from _base_interrupt
3361 * 0 means the mf is freed from this function.
3364 _scsih_io_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
3366 Mpi2SCSIIORequest_t
*mpi_request
;
3367 Mpi2SCSIIOReply_t
*mpi_reply
;
3368 struct scsi_cmnd
*scmd
;
3374 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
3375 u32 response_code
= 0;
3377 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
3378 scmd
= _scsih_scsi_lookup_get(ioc
, smid
);
3382 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3384 if (mpi_reply
== NULL
) {
3385 scmd
->result
= DID_OK
<< 16;
3389 sas_device_priv_data
= scmd
->device
->hostdata
;
3390 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
||
3391 sas_device_priv_data
->sas_target
->deleted
) {
3392 scmd
->result
= DID_NO_CONNECT
<< 16;
3396 /* turning off TLR */
3397 scsi_state
= mpi_reply
->SCSIState
;
3398 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
3400 le32_to_cpu(mpi_reply
->ResponseInfo
) & 0xFF;
3401 if (!sas_device_priv_data
->tlr_snoop_check
) {
3402 sas_device_priv_data
->tlr_snoop_check
++;
3403 if (!_scsih_is_raid(&scmd
->device
->sdev_gendev
) &&
3404 sas_is_tlr_enabled(scmd
->device
) &&
3405 response_code
== MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
) {
3406 sas_disable_tlr(scmd
->device
);
3407 sdev_printk(KERN_INFO
, scmd
->device
, "TLR disabled\n");
3411 xfer_cnt
= le32_to_cpu(mpi_reply
->TransferCount
);
3412 scsi_set_resid(scmd
, scsi_bufflen(scmd
) - xfer_cnt
);
3413 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
);
3414 if (ioc_status
& MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE
)
3415 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
3418 ioc_status
&= MPI2_IOCSTATUS_MASK
;
3419 scsi_status
= mpi_reply
->SCSIStatus
;
3421 if (ioc_status
== MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
&& xfer_cnt
== 0 &&
3422 (scsi_status
== MPI2_SCSI_STATUS_BUSY
||
3423 scsi_status
== MPI2_SCSI_STATUS_RESERVATION_CONFLICT
||
3424 scsi_status
== MPI2_SCSI_STATUS_TASK_SET_FULL
)) {
3425 ioc_status
= MPI2_IOCSTATUS_SUCCESS
;
3428 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
3429 struct sense_info data
;
3430 const void *sense_data
= mpt2sas_base_get_sense_buffer(ioc
,
3432 u32 sz
= min_t(u32
, SCSI_SENSE_BUFFERSIZE
,
3433 le32_to_cpu(mpi_reply
->SenseCount
));
3434 memcpy(scmd
->sense_buffer
, sense_data
, sz
);
3435 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
3436 /* failure prediction threshold exceeded */
3437 if (data
.asc
== 0x5D)
3438 _scsih_smart_predicted_fault(ioc
,
3439 le16_to_cpu(mpi_reply
->DevHandle
));
3442 switch (ioc_status
) {
3443 case MPI2_IOCSTATUS_BUSY
:
3444 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES
:
3445 scmd
->result
= SAM_STAT_BUSY
;
3448 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
3449 scmd
->result
= DID_NO_CONNECT
<< 16;
3452 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
3453 if (sas_device_priv_data
->block
) {
3454 scmd
->result
= DID_TRANSPORT_DISRUPTED
<< 16;
3457 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
3458 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
3459 scmd
->result
= DID_RESET
<< 16;
3462 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
3463 if ((xfer_cnt
== 0) || (scmd
->underflow
> xfer_cnt
))
3464 scmd
->result
= DID_SOFT_ERROR
<< 16;
3466 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
3469 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
3470 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
3472 if ((scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
))
3475 if (xfer_cnt
< scmd
->underflow
) {
3476 if (scsi_status
== SAM_STAT_BUSY
)
3477 scmd
->result
= SAM_STAT_BUSY
;
3479 scmd
->result
= DID_SOFT_ERROR
<< 16;
3480 } else if (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
3481 MPI2_SCSI_STATE_NO_SCSI_STATUS
))
3482 scmd
->result
= DID_SOFT_ERROR
<< 16;
3483 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
3484 scmd
->result
= DID_RESET
<< 16;
3485 else if (!xfer_cnt
&& scmd
->cmnd
[0] == REPORT_LUNS
) {
3486 mpi_reply
->SCSIState
= MPI2_SCSI_STATE_AUTOSENSE_VALID
;
3487 mpi_reply
->SCSIStatus
= SAM_STAT_CHECK_CONDITION
;
3488 scmd
->result
= (DRIVER_SENSE
<< 24) |
3489 SAM_STAT_CHECK_CONDITION
;
3490 scmd
->sense_buffer
[0] = 0x70;
3491 scmd
->sense_buffer
[2] = ILLEGAL_REQUEST
;
3492 scmd
->sense_buffer
[12] = 0x20;
3493 scmd
->sense_buffer
[13] = 0;
3497 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
3498 scsi_set_resid(scmd
, 0);
3499 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
3500 case MPI2_IOCSTATUS_SUCCESS
:
3501 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
3502 if (response_code
==
3503 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
||
3504 (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
3505 MPI2_SCSI_STATE_NO_SCSI_STATUS
)))
3506 scmd
->result
= DID_SOFT_ERROR
<< 16;
3507 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
3508 scmd
->result
= DID_RESET
<< 16;
3511 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
3512 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
3513 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
3514 _scsih_eedp_error_handling(scmd
, ioc_status
);
3516 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
3517 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
3518 case MPI2_IOCSTATUS_INVALID_SGL
:
3519 case MPI2_IOCSTATUS_INTERNAL_ERROR
:
3520 case MPI2_IOCSTATUS_INVALID_FIELD
:
3521 case MPI2_IOCSTATUS_INVALID_STATE
:
3522 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
3523 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
3525 scmd
->result
= DID_SOFT_ERROR
<< 16;
3530 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3531 if (scmd
->result
&& (ioc
->logging_level
& MPT_DEBUG_REPLY
))
3532 _scsih_scsi_ioc_info(ioc
, scmd
, mpi_reply
, smid
);
3536 scsi_dma_unmap(scmd
);
3537 scmd
->scsi_done(scmd
);
3542 * _scsih_sas_host_refresh - refreshing sas host object contents
3543 * @ioc: per adapter object
3546 * During port enable, fw will send topology events for every device. Its
3547 * possible that the handles may change from the previous setting, so this
3548 * code keeping handles updating if changed.
3553 _scsih_sas_host_refresh(struct MPT2SAS_ADAPTER
*ioc
)
3558 Mpi2ConfigReply_t mpi_reply
;
3559 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
3560 u16 attached_handle
;
3562 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
3563 "updating handles for sas_host(0x%016llx)\n",
3564 ioc
->name
, (unsigned long long)ioc
->sas_hba
.sas_address
));
3566 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
3567 * sizeof(Mpi2SasIOUnit0PhyData_t
));
3568 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
3569 if (!sas_iounit_pg0
) {
3570 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3571 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3575 if ((mpt2sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
3576 sas_iounit_pg0
, sz
)) != 0)
3578 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
3579 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
3581 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
3583 ioc
->sas_hba
.handle
= le16_to_cpu(sas_iounit_pg0
->
3584 PhyData
[0].ControllerDevHandle
);
3585 ioc
->sas_hba
.phy
[i
].handle
= ioc
->sas_hba
.handle
;
3586 attached_handle
= le16_to_cpu(sas_iounit_pg0
->PhyData
[i
].
3588 mpt2sas_transport_update_links(ioc
, ioc
->sas_hba
.sas_address
,
3589 attached_handle
, i
, sas_iounit_pg0
->PhyData
[i
].
3590 NegotiatedLinkRate
>> 4);
3593 kfree(sas_iounit_pg0
);
3597 * _scsih_sas_host_add - create sas host object
3598 * @ioc: per adapter object
3600 * Creating host side data object, stored in ioc->sas_hba
3605 _scsih_sas_host_add(struct MPT2SAS_ADAPTER
*ioc
)
3608 Mpi2ConfigReply_t mpi_reply
;
3609 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
3610 Mpi2SasIOUnitPage1_t
*sas_iounit_pg1
= NULL
;
3611 Mpi2SasPhyPage0_t phy_pg0
;
3612 Mpi2SasDevicePage0_t sas_device_pg0
;
3613 Mpi2SasEnclosurePage0_t enclosure_pg0
;
3616 u16 device_missing_delay
;
3618 mpt2sas_config_get_number_hba_phys(ioc
, &ioc
->sas_hba
.num_phys
);
3619 if (!ioc
->sas_hba
.num_phys
) {
3620 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3621 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3625 /* sas_iounit page 0 */
3626 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
3627 sizeof(Mpi2SasIOUnit0PhyData_t
));
3628 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
3629 if (!sas_iounit_pg0
) {
3630 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3631 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3634 if ((mpt2sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
3635 sas_iounit_pg0
, sz
))) {
3636 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3637 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3640 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
3641 MPI2_IOCSTATUS_MASK
;
3642 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
3643 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3644 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3648 /* sas_iounit page 1 */
3649 sz
= offsetof(Mpi2SasIOUnitPage1_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
3650 sizeof(Mpi2SasIOUnit1PhyData_t
));
3651 sas_iounit_pg1
= kzalloc(sz
, GFP_KERNEL
);
3652 if (!sas_iounit_pg1
) {
3653 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3654 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3657 if ((mpt2sas_config_get_sas_iounit_pg1(ioc
, &mpi_reply
,
3658 sas_iounit_pg1
, sz
))) {
3659 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3660 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3663 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
3664 MPI2_IOCSTATUS_MASK
;
3665 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
3666 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3667 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3671 ioc
->io_missing_delay
=
3672 le16_to_cpu(sas_iounit_pg1
->IODeviceMissingDelay
);
3673 device_missing_delay
=
3674 le16_to_cpu(sas_iounit_pg1
->ReportDeviceMissingDelay
);
3675 if (device_missing_delay
& MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16
)
3676 ioc
->device_missing_delay
= (device_missing_delay
&
3677 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
) * 16;
3679 ioc
->device_missing_delay
= device_missing_delay
&
3680 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
;
3682 ioc
->sas_hba
.parent_dev
= &ioc
->shost
->shost_gendev
;
3683 ioc
->sas_hba
.phy
= kcalloc(ioc
->sas_hba
.num_phys
,
3684 sizeof(struct _sas_phy
), GFP_KERNEL
);
3685 if (!ioc
->sas_hba
.phy
) {
3686 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3687 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3690 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
3691 if ((mpt2sas_config_get_phy_pg0(ioc
, &mpi_reply
, &phy_pg0
,
3693 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3694 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3697 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
3698 MPI2_IOCSTATUS_MASK
;
3699 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
3700 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3701 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3706 ioc
->sas_hba
.handle
= le16_to_cpu(sas_iounit_pg0
->
3707 PhyData
[0].ControllerDevHandle
);
3708 ioc
->sas_hba
.phy
[i
].handle
= ioc
->sas_hba
.handle
;
3709 ioc
->sas_hba
.phy
[i
].phy_id
= i
;
3710 mpt2sas_transport_add_host_phy(ioc
, &ioc
->sas_hba
.phy
[i
],
3711 phy_pg0
, ioc
->sas_hba
.parent_dev
);
3713 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
3714 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, ioc
->sas_hba
.handle
))) {
3715 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3716 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3719 ioc
->sas_hba
.enclosure_handle
=
3720 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
3721 ioc
->sas_hba
.sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
3722 printk(MPT2SAS_INFO_FMT
"host_add: handle(0x%04x), "
3723 "sas_addr(0x%016llx), phys(%d)\n", ioc
->name
, ioc
->sas_hba
.handle
,
3724 (unsigned long long) ioc
->sas_hba
.sas_address
,
3725 ioc
->sas_hba
.num_phys
) ;
3727 if (ioc
->sas_hba
.enclosure_handle
) {
3728 if (!(mpt2sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
3730 MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
3731 ioc
->sas_hba
.enclosure_handle
))) {
3732 ioc
->sas_hba
.enclosure_logical_id
=
3733 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
3738 kfree(sas_iounit_pg1
);
3739 kfree(sas_iounit_pg0
);
3743 * _scsih_expander_add - creating expander object
3744 * @ioc: per adapter object
3745 * @handle: expander handle
3747 * Creating expander object, stored in ioc->sas_expander_list.
3749 * Return 0 for success, else error.
3752 _scsih_expander_add(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
3754 struct _sas_node
*sas_expander
;
3755 Mpi2ConfigReply_t mpi_reply
;
3756 Mpi2ExpanderPage0_t expander_pg0
;
3757 Mpi2ExpanderPage1_t expander_pg1
;
3758 Mpi2SasEnclosurePage0_t enclosure_pg0
;
3761 __le64 sas_address
, sas_address_parent
= 0;
3763 unsigned long flags
;
3764 struct _sas_port
*mpt2sas_port
= NULL
;
3770 if (ioc
->shost_recovery
)
3773 if ((mpt2sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
3774 MPI2_SAS_EXPAND_PGAD_FORM_HNDL
, handle
))) {
3775 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3776 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3780 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
3781 MPI2_IOCSTATUS_MASK
;
3782 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
3783 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3784 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3788 /* handle out of order topology events */
3789 parent_handle
= le16_to_cpu(expander_pg0
.ParentDevHandle
);
3790 if (_scsih_get_sas_address(ioc
, parent_handle
, &sas_address_parent
)
3792 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3793 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3796 if (sas_address_parent
!= ioc
->sas_hba
.sas_address
) {
3797 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
3798 sas_expander
= mpt2sas_scsih_expander_find_by_sas_address(ioc
,
3799 sas_address_parent
);
3800 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
3801 if (!sas_expander
) {
3802 rc
= _scsih_expander_add(ioc
, parent_handle
);
3808 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
3809 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
3810 sas_expander
= mpt2sas_scsih_expander_find_by_sas_address(ioc
,
3812 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
3817 sas_expander
= kzalloc(sizeof(struct _sas_node
),
3819 if (!sas_expander
) {
3820 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3821 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3825 sas_expander
->handle
= handle
;
3826 sas_expander
->num_phys
= expander_pg0
.NumPhys
;
3827 sas_expander
->sas_address_parent
= sas_address_parent
;
3828 sas_expander
->sas_address
= sas_address
;
3830 printk(MPT2SAS_INFO_FMT
"expander_add: handle(0x%04x),"
3831 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc
->name
,
3832 handle
, parent_handle
, (unsigned long long)
3833 sas_expander
->sas_address
, sas_expander
->num_phys
);
3835 if (!sas_expander
->num_phys
)
3837 sas_expander
->phy
= kcalloc(sas_expander
->num_phys
,
3838 sizeof(struct _sas_phy
), GFP_KERNEL
);
3839 if (!sas_expander
->phy
) {
3840 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3841 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3846 INIT_LIST_HEAD(&sas_expander
->sas_port_list
);
3847 mpt2sas_port
= mpt2sas_transport_port_add(ioc
, handle
,
3848 sas_address_parent
);
3849 if (!mpt2sas_port
) {
3850 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3851 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3855 sas_expander
->parent_dev
= &mpt2sas_port
->rphy
->dev
;
3857 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++) {
3858 if ((mpt2sas_config_get_expander_pg1(ioc
, &mpi_reply
,
3859 &expander_pg1
, i
, handle
))) {
3860 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3861 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3865 sas_expander
->phy
[i
].handle
= handle
;
3866 sas_expander
->phy
[i
].phy_id
= i
;
3868 if ((mpt2sas_transport_add_expander_phy(ioc
,
3869 &sas_expander
->phy
[i
], expander_pg1
,
3870 sas_expander
->parent_dev
))) {
3871 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3872 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3878 if (sas_expander
->enclosure_handle
) {
3879 if (!(mpt2sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
3880 &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
3881 sas_expander
->enclosure_handle
))) {
3882 sas_expander
->enclosure_logical_id
=
3883 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
3887 _scsih_expander_node_add(ioc
, sas_expander
);
3893 mpt2sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
3894 sas_address_parent
);
3895 kfree(sas_expander
);
3900 * _scsih_done - scsih callback handler.
3901 * @ioc: per adapter object
3902 * @smid: system request message index
3903 * @msix_index: MSIX table index supplied by the OS
3904 * @reply: reply message frame(lower 32bit addr)
3906 * Callback handler when sending internal generated message frames.
3907 * The callback index passed is `ioc->scsih_cb_idx`
3909 * Return 1 meaning mf should be freed from _base_interrupt
3910 * 0 means the mf is freed from this function.
3913 _scsih_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
3915 MPI2DefaultReply_t
*mpi_reply
;
3917 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
3918 if (ioc
->scsih_cmds
.status
== MPT2_CMD_NOT_USED
)
3920 if (ioc
->scsih_cmds
.smid
!= smid
)
3922 ioc
->scsih_cmds
.status
|= MPT2_CMD_COMPLETE
;
3924 memcpy(ioc
->scsih_cmds
.reply
, mpi_reply
,
3925 mpi_reply
->MsgLength
*4);
3926 ioc
->scsih_cmds
.status
|= MPT2_CMD_REPLY_VALID
;
3928 ioc
->scsih_cmds
.status
&= ~MPT2_CMD_PENDING
;
3929 complete(&ioc
->scsih_cmds
.done
);
3934 * _scsih_expander_remove - removing expander object
3935 * @ioc: per adapter object
3936 * @sas_address: expander sas_address
3941 _scsih_expander_remove(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
)
3943 struct _sas_node
*sas_expander
;
3944 unsigned long flags
;
3946 if (ioc
->shost_recovery
)
3949 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
3950 sas_expander
= mpt2sas_scsih_expander_find_by_sas_address(ioc
,
3952 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
3953 _scsih_expander_node_remove(ioc
, sas_expander
);
3957 * _scsih_check_access_status - check access flags
3958 * @ioc: per adapter object
3959 * @sas_address: sas address
3960 * @handle: sas device handle
3961 * @access_flags: errors returned during discovery of the device
3963 * Return 0 for success, else failure
3966 _scsih_check_access_status(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
,
3967 u16 handle
, u8 access_status
)
3972 switch (access_status
) {
3973 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS
:
3974 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION
:
3977 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED
:
3978 desc
= "sata capability failed";
3980 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT
:
3981 desc
= "sata affiliation conflict";
3983 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE
:
3984 desc
= "route not addressable";
3986 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE
:
3987 desc
= "smp error not addressable";
3989 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED
:
3990 desc
= "device blocked";
3992 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED
:
3993 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN
:
3994 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT
:
3995 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG
:
3996 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION
:
3997 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER
:
3998 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN
:
3999 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN
:
4000 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN
:
4001 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION
:
4002 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE
:
4003 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX
:
4004 desc
= "sata initialization failed";
4014 printk(MPT2SAS_ERR_FMT
"discovery errors(%s): sas_address(0x%016llx), "
4015 "handle(0x%04x)\n", ioc
->name
, desc
,
4016 (unsigned long long)sas_address
, handle
);
4021 _scsih_check_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
4023 Mpi2ConfigReply_t mpi_reply
;
4024 Mpi2SasDevicePage0_t sas_device_pg0
;
4025 struct _sas_device
*sas_device
;
4027 unsigned long flags
;
4029 struct scsi_target
*starget
;
4030 struct MPT2SAS_TARGET
*sas_target_priv_data
;
4033 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
4034 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
)))
4037 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
4038 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
4041 /* check if this is end device */
4042 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
4043 if (!(_scsih_is_end_device(device_info
)))
4046 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4047 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
4048 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
4052 printk(MPT2SAS_ERR_FMT
"device is not present "
4053 "handle(0x%04x), no sas_device!!!\n", ioc
->name
, handle
);
4054 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4058 if (unlikely(sas_device
->handle
!= handle
)) {
4059 starget
= sas_device
->starget
;
4060 sas_target_priv_data
= starget
->hostdata
;
4061 starget_printk(KERN_INFO
, starget
, "handle changed from(0x%04x)"
4062 " to (0x%04x)!!!\n", sas_device
->handle
, handle
);
4063 sas_target_priv_data
->handle
= handle
;
4064 sas_device
->handle
= handle
;
4066 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4068 /* check if device is present */
4069 if (!(le16_to_cpu(sas_device_pg0
.Flags
) &
4070 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT
)) {
4071 printk(MPT2SAS_ERR_FMT
"device is not present "
4072 "handle(0x%04x), flags!!!\n", ioc
->name
, handle
);
4076 /* check if there were any issues with discovery */
4077 if (_scsih_check_access_status(ioc
, sas_address
, handle
,
4078 sas_device_pg0
.AccessStatus
))
4080 _scsih_ublock_io_device(ioc
, handle
);
4085 * _scsih_add_device - creating sas device object
4086 * @ioc: per adapter object
4087 * @handle: sas device handle
4088 * @phy_num: phy number end device attached to
4089 * @is_pd: is this hidden raid component
4091 * Creating end device object, stored in ioc->sas_device_list.
4093 * Returns 0 for success, non-zero for failure.
4096 _scsih_add_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
, u8 phy_num
, u8 is_pd
)
4098 Mpi2ConfigReply_t mpi_reply
;
4099 Mpi2SasDevicePage0_t sas_device_pg0
;
4100 Mpi2SasEnclosurePage0_t enclosure_pg0
;
4101 struct _sas_device
*sas_device
;
4105 unsigned long flags
;
4107 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
4108 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
4109 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4110 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4114 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4115 MPI2_IOCSTATUS_MASK
;
4116 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4117 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4118 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4122 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
4124 /* check if device is present */
4125 if (!(le16_to_cpu(sas_device_pg0
.Flags
) &
4126 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT
)) {
4127 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4128 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4129 printk(MPT2SAS_ERR_FMT
"Flags = 0x%04x\n",
4130 ioc
->name
, le16_to_cpu(sas_device_pg0
.Flags
));
4134 /* check if there were any issues with discovery */
4135 if (_scsih_check_access_status(ioc
, sas_address
, handle
,
4136 sas_device_pg0
.AccessStatus
))
4139 /* check if this is end device */
4140 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
4141 if (!(_scsih_is_end_device(device_info
))) {
4142 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4143 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4148 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4149 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
4151 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4156 sas_device
= kzalloc(sizeof(struct _sas_device
),
4159 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4160 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4164 sas_device
->handle
= handle
;
4165 if (_scsih_get_sas_address(ioc
, le16_to_cpu
4166 (sas_device_pg0
.ParentDevHandle
),
4167 &sas_device
->sas_address_parent
) != 0)
4168 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4169 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4170 sas_device
->enclosure_handle
=
4171 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
4173 le16_to_cpu(sas_device_pg0
.Slot
);
4174 sas_device
->device_info
= device_info
;
4175 sas_device
->sas_address
= sas_address
;
4176 sas_device
->hidden_raid_component
= is_pd
;
4178 /* get enclosure_logical_id */
4179 if (sas_device
->enclosure_handle
&& !(mpt2sas_config_get_enclosure_pg0(
4180 ioc
, &mpi_reply
, &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
4181 sas_device
->enclosure_handle
)))
4182 sas_device
->enclosure_logical_id
=
4183 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
4185 /* get device name */
4186 sas_device
->device_name
= le64_to_cpu(sas_device_pg0
.DeviceName
);
4188 if (ioc
->wait_for_port_enable_to_complete
)
4189 _scsih_sas_device_init_add(ioc
, sas_device
);
4191 _scsih_sas_device_add(ioc
, sas_device
);
4197 * _scsih_remove_pd_device - removing sas device pd object
4198 * @ioc: per adapter object
4199 * @sas_device_delete: the sas_device object
4201 * For hidden raid components, we do driver-fw handshake from
4202 * hotplug work threads.
4206 _scsih_remove_pd_device(struct MPT2SAS_ADAPTER
*ioc
, struct _sas_device
4209 Mpi2SasIoUnitControlReply_t mpi_reply
;
4210 Mpi2SasIoUnitControlRequest_t mpi_request
;
4211 u16 vol_handle
, handle
;
4213 handle
= sas_device
.handle
;
4214 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: enter: handle(0x%04x),"
4215 " sas_addr(0x%016llx)\n", ioc
->name
, __func__
, handle
,
4216 (unsigned long long) sas_device
.sas_address
));
4218 vol_handle
= sas_device
.volume_handle
;
4221 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"issue target reset: "
4222 "handle(0x%04x)\n", ioc
->name
, vol_handle
));
4223 mpt2sas_scsih_issue_tm(ioc
, vol_handle
, 0, 0, 0,
4224 MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
, 0, 30, NULL
);
4225 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"issue target reset "
4226 "done: handle(0x%04x)\n", ioc
->name
, vol_handle
));
4227 if (ioc
->shost_recovery
)
4230 /* SAS_IO_UNIT_CNTR - send REMOVE_DEVICE */
4231 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"sas_iounit: handle"
4232 "(0x%04x)\n", ioc
->name
, handle
));
4233 memset(&mpi_request
, 0, sizeof(Mpi2SasIoUnitControlRequest_t
));
4234 mpi_request
.Function
= MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
;
4235 mpi_request
.Operation
= MPI2_SAS_OP_REMOVE_DEVICE
;
4236 mpi_request
.DevHandle
= cpu_to_le16(handle
);
4237 if ((mpt2sas_base_sas_iounit_control(ioc
, &mpi_reply
,
4238 &mpi_request
)) != 0)
4239 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4240 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4242 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"sas_iounit: ioc_status"
4243 "(0x%04x), loginfo(0x%08x)\n", ioc
->name
,
4244 le16_to_cpu(mpi_reply
.IOCStatus
),
4245 le32_to_cpu(mpi_reply
.IOCLogInfo
)));
4247 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: exit: handle(0x%04x),"
4248 " sas_addr(0x%016llx)\n", ioc
->name
, __func__
, handle
,
4249 (unsigned long long) sas_device
.sas_address
));
4253 * _scsih_remove_device - removing sas device object
4254 * @ioc: per adapter object
4255 * @sas_device_delete: the sas_device object
4260 _scsih_remove_device(struct MPT2SAS_ADAPTER
*ioc
,
4261 struct _sas_device
*sas_device
)
4263 struct _sas_device sas_device_backup
;
4264 struct MPT2SAS_TARGET
*sas_target_priv_data
;
4269 memcpy(&sas_device_backup
, sas_device
, sizeof(struct _sas_device
));
4270 _scsih_sas_device_remove(ioc
, sas_device
);
4272 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: enter: "
4273 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
, __func__
,
4274 sas_device_backup
.handle
, (unsigned long long)
4275 sas_device_backup
.sas_address
));
4277 if (sas_device_backup
.starget
&& sas_device_backup
.starget
->hostdata
) {
4278 sas_target_priv_data
= sas_device_backup
.starget
->hostdata
;
4279 sas_target_priv_data
->deleted
= 1;
4282 if (sas_device_backup
.hidden_raid_component
)
4283 _scsih_remove_pd_device(ioc
, sas_device_backup
);
4285 _scsih_ublock_io_device(ioc
, sas_device_backup
.handle
);
4287 mpt2sas_transport_port_remove(ioc
, sas_device_backup
.sas_address
,
4288 sas_device_backup
.sas_address_parent
);
4290 printk(MPT2SAS_INFO_FMT
"removing handle(0x%04x), sas_addr"
4291 "(0x%016llx)\n", ioc
->name
, sas_device_backup
.handle
,
4292 (unsigned long long) sas_device_backup
.sas_address
);
4294 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: exit: "
4295 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
, __func__
,
4296 sas_device_backup
.handle
, (unsigned long long)
4297 sas_device_backup
.sas_address
));
4300 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4302 * _scsih_sas_topology_change_event_debug - debug for topology event
4303 * @ioc: per adapter object
4304 * @event_data: event data payload
4308 _scsih_sas_topology_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
4309 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
4315 char *status_str
= NULL
;
4316 u8 link_rate
, prev_link_rate
;
4318 switch (event_data
->ExpStatus
) {
4319 case MPI2_EVENT_SAS_TOPO_ES_ADDED
:
4322 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
:
4323 status_str
= "remove";
4325 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING
:
4327 status_str
= "responding";
4329 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
:
4330 status_str
= "remove delay";
4333 status_str
= "unknown status";
4336 printk(MPT2SAS_DEBUG_FMT
"sas topology change: (%s)\n",
4337 ioc
->name
, status_str
);
4338 printk(KERN_DEBUG
"\thandle(0x%04x), enclosure_handle(0x%04x) "
4339 "start_phy(%02d), count(%d)\n",
4340 le16_to_cpu(event_data
->ExpanderDevHandle
),
4341 le16_to_cpu(event_data
->EnclosureHandle
),
4342 event_data
->StartPhyNum
, event_data
->NumEntries
);
4343 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
4344 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
4347 phy_number
= event_data
->StartPhyNum
+ i
;
4348 reason_code
= event_data
->PHY
[i
].PhyStatus
&
4349 MPI2_EVENT_SAS_TOPO_RC_MASK
;
4350 switch (reason_code
) {
4351 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
4352 status_str
= "target add";
4354 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
4355 status_str
= "target remove";
4357 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
:
4358 status_str
= "delay target remove";
4360 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
4361 status_str
= "link rate change";
4363 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE
:
4364 status_str
= "target responding";
4367 status_str
= "unknown";
4370 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
4371 prev_link_rate
= event_data
->PHY
[i
].LinkRate
& 0xF;
4372 printk(KERN_DEBUG
"\tphy(%02d), attached_handle(0x%04x): %s:"
4373 " link rate: new(0x%02x), old(0x%02x)\n", phy_number
,
4374 handle
, status_str
, link_rate
, prev_link_rate
);
4381 * _scsih_sas_topology_change_event - handle topology changes
4382 * @ioc: per adapter object
4383 * @fw_event: The fw_event_work object
4388 _scsih_sas_topology_change_event(struct MPT2SAS_ADAPTER
*ioc
,
4389 struct fw_event_work
*fw_event
)
4392 u16 parent_handle
, handle
;
4395 struct _sas_node
*sas_expander
;
4396 struct _sas_device
*sas_device
;
4398 unsigned long flags
;
4399 u8 link_rate
, prev_link_rate
;
4400 Mpi2EventDataSasTopologyChangeList_t
*event_data
= fw_event
->event_data
;
4402 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4403 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
4404 _scsih_sas_topology_change_event_debug(ioc
, event_data
);
4407 if (ioc
->shost_recovery
|| ioc
->remove_host
)
4410 if (!ioc
->sas_hba
.num_phys
)
4411 _scsih_sas_host_add(ioc
);
4413 _scsih_sas_host_refresh(ioc
);
4415 if (fw_event
->ignore
) {
4416 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"ignoring expander "
4417 "event\n", ioc
->name
));
4421 parent_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
4423 /* handle expander add */
4424 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_ADDED
)
4425 if (_scsih_expander_add(ioc
, parent_handle
) != 0)
4428 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
4429 sas_expander
= mpt2sas_scsih_expander_find_by_handle(ioc
,
4431 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
4433 sas_address
= sas_expander
->sas_address
;
4434 else if (parent_handle
< ioc
->sas_hba
.num_phys
)
4435 sas_address
= ioc
->sas_hba
.sas_address
;
4439 /* handle siblings events */
4440 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
4441 if (fw_event
->ignore
) {
4442 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"ignoring "
4443 "expander event\n", ioc
->name
));
4446 if (ioc
->shost_recovery
|| ioc
->remove_host
)
4448 phy_number
= event_data
->StartPhyNum
+ i
;
4449 reason_code
= event_data
->PHY
[i
].PhyStatus
&
4450 MPI2_EVENT_SAS_TOPO_RC_MASK
;
4451 if ((event_data
->PHY
[i
].PhyStatus
&
4452 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT
) && (reason_code
!=
4453 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
))
4455 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
4458 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
4459 prev_link_rate
= event_data
->PHY
[i
].LinkRate
& 0xF;
4460 switch (reason_code
) {
4461 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
4463 if (link_rate
== prev_link_rate
)
4466 mpt2sas_transport_update_links(ioc
, sas_address
,
4467 handle
, phy_number
, link_rate
);
4469 if (link_rate
< MPI2_SAS_NEG_LINK_RATE_1_5
)
4472 _scsih_check_device(ioc
, handle
);
4474 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
4476 mpt2sas_transport_update_links(ioc
, sas_address
,
4477 handle
, phy_number
, link_rate
);
4479 _scsih_add_device(ioc
, handle
, phy_number
, 0);
4481 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
4483 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4484 sas_device
= _scsih_sas_device_find_by_handle(ioc
,
4487 spin_unlock_irqrestore(&ioc
->sas_device_lock
,
4491 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4492 _scsih_remove_device(ioc
, sas_device
);
4497 /* handle expander removal */
4498 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
&&
4500 _scsih_expander_remove(ioc
, sas_address
);
4504 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4506 * _scsih_sas_device_status_change_event_debug - debug for device event
4507 * @event_data: event data payload
4513 _scsih_sas_device_status_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
4514 Mpi2EventDataSasDeviceStatusChange_t
*event_data
)
4516 char *reason_str
= NULL
;
4518 switch (event_data
->ReasonCode
) {
4519 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
:
4520 reason_str
= "smart data";
4522 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED
:
4523 reason_str
= "unsupported device discovered";
4525 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
:
4526 reason_str
= "internal device reset";
4528 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL
:
4529 reason_str
= "internal task abort";
4531 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL
:
4532 reason_str
= "internal task abort set";
4534 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL
:
4535 reason_str
= "internal clear task set";
4537 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL
:
4538 reason_str
= "internal query task";
4540 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE
:
4541 reason_str
= "sata init failure";
4543 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
:
4544 reason_str
= "internal device reset complete";
4546 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL
:
4547 reason_str
= "internal task abort complete";
4549 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION
:
4550 reason_str
= "internal async notification";
4552 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY
:
4553 reason_str
= "expander reduced functionality";
4555 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY
:
4556 reason_str
= "expander reduced functionality complete";
4559 reason_str
= "unknown reason";
4562 printk(MPT2SAS_DEBUG_FMT
"device status change: (%s)\n"
4563 "\thandle(0x%04x), sas address(0x%016llx)", ioc
->name
,
4564 reason_str
, le16_to_cpu(event_data
->DevHandle
),
4565 (unsigned long long)le64_to_cpu(event_data
->SASAddress
));
4566 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
)
4567 printk(MPT2SAS_DEBUG_FMT
", ASC(0x%x), ASCQ(0x%x)\n", ioc
->name
,
4568 event_data
->ASC
, event_data
->ASCQ
);
4569 printk(KERN_INFO
"\n");
4574 * _scsih_sas_device_status_change_event - handle device status change
4575 * @ioc: per adapter object
4576 * @fw_event: The fw_event_work object
4582 _scsih_sas_device_status_change_event(struct MPT2SAS_ADAPTER
*ioc
,
4583 struct fw_event_work
*fw_event
)
4585 struct MPT2SAS_TARGET
*target_priv_data
;
4586 struct _sas_device
*sas_device
;
4588 unsigned long flags
;
4589 Mpi2EventDataSasDeviceStatusChange_t
*event_data
=
4590 fw_event
->event_data
;
4592 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4593 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
4594 _scsih_sas_device_status_change_event_debug(ioc
,
4598 if (event_data
->ReasonCode
!=
4599 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
&&
4600 event_data
->ReasonCode
!=
4601 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
)
4604 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4605 sas_address
= le64_to_cpu(event_data
->SASAddress
);
4606 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
4608 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4610 if (!sas_device
|| !sas_device
->starget
)
4613 target_priv_data
= sas_device
->starget
->hostdata
;
4614 if (!target_priv_data
)
4617 if (event_data
->ReasonCode
==
4618 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
)
4619 target_priv_data
->tm_busy
= 1;
4621 target_priv_data
->tm_busy
= 0;
4624 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4626 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure event
4627 * @ioc: per adapter object
4628 * @event_data: event data payload
4634 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
4635 Mpi2EventDataSasEnclDevStatusChange_t
*event_data
)
4637 char *reason_str
= NULL
;
4639 switch (event_data
->ReasonCode
) {
4640 case MPI2_EVENT_SAS_ENCL_RC_ADDED
:
4641 reason_str
= "enclosure add";
4643 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING
:
4644 reason_str
= "enclosure remove";
4647 reason_str
= "unknown reason";
4651 printk(MPT2SAS_DEBUG_FMT
"enclosure status change: (%s)\n"
4652 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
4653 " number slots(%d)\n", ioc
->name
, reason_str
,
4654 le16_to_cpu(event_data
->EnclosureHandle
),
4655 (unsigned long long)le64_to_cpu(event_data
->EnclosureLogicalID
),
4656 le16_to_cpu(event_data
->StartSlot
));
4661 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
4662 * @ioc: per adapter object
4663 * @fw_event: The fw_event_work object
4669 _scsih_sas_enclosure_dev_status_change_event(struct MPT2SAS_ADAPTER
*ioc
,
4670 struct fw_event_work
*fw_event
)
4672 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4673 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
4674 _scsih_sas_enclosure_dev_status_change_event_debug(ioc
,
4675 fw_event
->event_data
);
4680 * _scsih_sas_broadcast_primative_event - handle broadcast events
4681 * @ioc: per adapter object
4682 * @fw_event: The fw_event_work object
4688 _scsih_sas_broadcast_primative_event(struct MPT2SAS_ADAPTER
*ioc
,
4689 struct fw_event_work
*fw_event
)
4691 struct scsi_cmnd
*scmd
;
4694 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
4695 u32 termination_count
;
4697 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
4698 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4699 Mpi2EventDataSasBroadcastPrimitive_t
*event_data
= fw_event
->event_data
;
4702 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"broadcast primative: "
4703 "phy number(%d), width(%d)\n", ioc
->name
, event_data
->PhyNum
,
4704 event_data
->PortWidth
));
4705 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: enter\n", ioc
->name
,
4708 termination_count
= 0;
4710 mpi_reply
= ioc
->tm_cmds
.reply
;
4711 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
4712 scmd
= _scsih_scsi_lookup_get(ioc
, smid
);
4715 sas_device_priv_data
= scmd
->device
->hostdata
;
4716 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
)
4718 /* skip hidden raid components */
4719 if (sas_device_priv_data
->sas_target
->flags
&
4720 MPT_TARGET_FLAGS_RAID_COMPONENT
)
4723 if (sas_device_priv_data
->sas_target
->flags
&
4724 MPT_TARGET_FLAGS_VOLUME
)
4727 handle
= sas_device_priv_data
->sas_target
->handle
;
4728 lun
= sas_device_priv_data
->lun
;
4731 mpt2sas_scsih_issue_tm(ioc
, handle
, 0, 0, lun
,
4732 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK
, smid
, 30, NULL
);
4733 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
4734 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
)
4735 & MPI2_IOCSTATUS_MASK
;
4736 if ((ioc_status
== MPI2_IOCSTATUS_SUCCESS
) &&
4737 (mpi_reply
->ResponseCode
==
4738 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
||
4739 mpi_reply
->ResponseCode
==
4740 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
))
4743 mpt2sas_scsih_issue_tm(ioc
, handle
, 0, 0, lun
,
4744 MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET
, 0, 30, NULL
);
4745 termination_count
+= le32_to_cpu(mpi_reply
->TerminationCount
);
4747 ioc
->broadcast_aen_busy
= 0;
4749 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
4750 "%s - exit, query_count = %d termination_count = %d\n",
4751 ioc
->name
, __func__
, query_count
, termination_count
));
4755 * _scsih_sas_discovery_event - handle discovery events
4756 * @ioc: per adapter object
4757 * @fw_event: The fw_event_work object
4763 _scsih_sas_discovery_event(struct MPT2SAS_ADAPTER
*ioc
,
4764 struct fw_event_work
*fw_event
)
4766 Mpi2EventDataSasDiscovery_t
*event_data
= fw_event
->event_data
;
4768 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4769 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
) {
4770 printk(MPT2SAS_DEBUG_FMT
"discovery event: (%s)", ioc
->name
,
4771 (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
) ?
4773 if (event_data
->DiscoveryStatus
)
4774 printk("discovery_status(0x%08x)",
4775 le32_to_cpu(event_data
->DiscoveryStatus
));
4780 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
&&
4781 !ioc
->sas_hba
.num_phys
)
4782 _scsih_sas_host_add(ioc
);
4786 * _scsih_reprobe_lun - reprobing lun
4787 * @sdev: scsi device struct
4788 * @no_uld_attach: sdev->no_uld_attach flag setting
4792 _scsih_reprobe_lun(struct scsi_device
*sdev
, void *no_uld_attach
)
4796 sdev
->no_uld_attach
= no_uld_attach
? 1 : 0;
4797 sdev_printk(KERN_INFO
, sdev
, "%s raid component\n",
4798 sdev
->no_uld_attach
? "hidding" : "exposing");
4799 rc
= scsi_device_reprobe(sdev
);
4803 * _scsih_reprobe_target - reprobing target
4804 * @starget: scsi target struct
4805 * @no_uld_attach: sdev->no_uld_attach flag setting
4807 * Note: no_uld_attach flag determines whether the disk device is attached
4808 * to block layer. A value of `1` means to not attach.
4811 _scsih_reprobe_target(struct scsi_target
*starget
, int no_uld_attach
)
4813 struct MPT2SAS_TARGET
*sas_target_priv_data
= starget
->hostdata
;
4816 sas_target_priv_data
->flags
|= MPT_TARGET_FLAGS_RAID_COMPONENT
;
4818 sas_target_priv_data
->flags
&= ~MPT_TARGET_FLAGS_RAID_COMPONENT
;
4820 starget_for_each_device(starget
, no_uld_attach
? (void *)1 : NULL
,
4821 _scsih_reprobe_lun
);
4824 * _scsih_sas_volume_add - add new volume
4825 * @ioc: per adapter object
4826 * @element: IR config element data
4832 _scsih_sas_volume_add(struct MPT2SAS_ADAPTER
*ioc
,
4833 Mpi2EventIrConfigElement_t
*element
)
4835 struct _raid_device
*raid_device
;
4836 unsigned long flags
;
4838 u16 handle
= le16_to_cpu(element
->VolDevHandle
);
4841 mpt2sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
4843 printk(MPT2SAS_ERR_FMT
4844 "failure at %s:%d/%s()!\n", ioc
->name
,
4845 __FILE__
, __LINE__
, __func__
);
4849 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
4850 raid_device
= _scsih_raid_device_find_by_wwid(ioc
, wwid
);
4851 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
4856 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
4858 printk(MPT2SAS_ERR_FMT
4859 "failure at %s:%d/%s()!\n", ioc
->name
,
4860 __FILE__
, __LINE__
, __func__
);
4864 raid_device
->id
= ioc
->sas_id
++;
4865 raid_device
->channel
= RAID_CHANNEL
;
4866 raid_device
->handle
= handle
;
4867 raid_device
->wwid
= wwid
;
4868 _scsih_raid_device_add(ioc
, raid_device
);
4869 if (!ioc
->wait_for_port_enable_to_complete
) {
4870 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
4871 raid_device
->id
, 0);
4873 _scsih_raid_device_remove(ioc
, raid_device
);
4875 _scsih_determine_boot_device(ioc
, raid_device
, 1);
4879 * _scsih_sas_volume_delete - delete volume
4880 * @ioc: per adapter object
4881 * @element: IR config element data
4887 _scsih_sas_volume_delete(struct MPT2SAS_ADAPTER
*ioc
,
4888 Mpi2EventIrConfigElement_t
*element
)
4890 struct _raid_device
*raid_device
;
4891 u16 handle
= le16_to_cpu(element
->VolDevHandle
);
4892 unsigned long flags
;
4893 struct MPT2SAS_TARGET
*sas_target_priv_data
;
4895 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
4896 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
4897 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
4900 if (raid_device
->starget
) {
4901 sas_target_priv_data
= raid_device
->starget
->hostdata
;
4902 sas_target_priv_data
->deleted
= 1;
4903 scsi_remove_target(&raid_device
->starget
->dev
);
4905 _scsih_raid_device_remove(ioc
, raid_device
);
4909 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
4910 * @ioc: per adapter object
4911 * @element: IR config element data
4917 _scsih_sas_pd_expose(struct MPT2SAS_ADAPTER
*ioc
,
4918 Mpi2EventIrConfigElement_t
*element
)
4920 struct _sas_device
*sas_device
;
4921 unsigned long flags
;
4922 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
4924 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4925 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
4926 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4930 /* exposing raid component */
4931 sas_device
->volume_handle
= 0;
4932 sas_device
->volume_wwid
= 0;
4933 sas_device
->hidden_raid_component
= 0;
4934 _scsih_reprobe_target(sas_device
->starget
, 0);
4938 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
4939 * @ioc: per adapter object
4940 * @element: IR config element data
4946 _scsih_sas_pd_hide(struct MPT2SAS_ADAPTER
*ioc
,
4947 Mpi2EventIrConfigElement_t
*element
)
4949 struct _sas_device
*sas_device
;
4950 unsigned long flags
;
4951 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
4953 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4954 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
4955 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4959 /* hiding raid component */
4960 mpt2sas_config_get_volume_handle(ioc
, handle
,
4961 &sas_device
->volume_handle
);
4962 mpt2sas_config_get_volume_wwid(ioc
, sas_device
->volume_handle
,
4963 &sas_device
->volume_wwid
);
4964 sas_device
->hidden_raid_component
= 1;
4965 _scsih_reprobe_target(sas_device
->starget
, 1);
4969 * _scsih_sas_pd_delete - delete pd component
4970 * @ioc: per adapter object
4971 * @element: IR config element data
4977 _scsih_sas_pd_delete(struct MPT2SAS_ADAPTER
*ioc
,
4978 Mpi2EventIrConfigElement_t
*element
)
4980 struct _sas_device
*sas_device
;
4981 unsigned long flags
;
4982 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
4984 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4985 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
4986 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4989 _scsih_remove_device(ioc
, sas_device
);
4993 * _scsih_sas_pd_add - remove pd component
4994 * @ioc: per adapter object
4995 * @element: IR config element data
5001 _scsih_sas_pd_add(struct MPT2SAS_ADAPTER
*ioc
,
5002 Mpi2EventIrConfigElement_t
*element
)
5004 struct _sas_device
*sas_device
;
5005 unsigned long flags
;
5006 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
5007 Mpi2ConfigReply_t mpi_reply
;
5008 Mpi2SasDevicePage0_t sas_device_pg0
;
5013 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5014 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
5015 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5017 sas_device
->hidden_raid_component
= 1;
5021 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
5022 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
5023 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5024 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5028 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5029 MPI2_IOCSTATUS_MASK
;
5030 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5031 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5032 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5036 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
5037 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
5038 mpt2sas_transport_update_links(ioc
, sas_address
, handle
,
5039 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
5041 _scsih_add_device(ioc
, handle
, 0, 1);
5044 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5046 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
5047 * @ioc: per adapter object
5048 * @event_data: event data payload
5054 _scsih_sas_ir_config_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
5055 Mpi2EventDataIrConfigChangeList_t
*event_data
)
5057 Mpi2EventIrConfigElement_t
*element
;
5060 char *reason_str
= NULL
, *element_str
= NULL
;
5062 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
5064 printk(MPT2SAS_DEBUG_FMT
"raid config change: (%s), elements(%d)\n",
5065 ioc
->name
, (le32_to_cpu(event_data
->Flags
) &
5066 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ?
5067 "foreign" : "native", event_data
->NumElements
);
5068 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
5069 switch (element
->ReasonCode
) {
5070 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
5073 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
5074 reason_str
= "remove";
5076 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE
:
5077 reason_str
= "no change";
5079 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
5080 reason_str
= "hide";
5082 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
5083 reason_str
= "unhide";
5085 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
5086 reason_str
= "volume_created";
5088 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
5089 reason_str
= "volume_deleted";
5091 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
5092 reason_str
= "pd_created";
5094 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
5095 reason_str
= "pd_deleted";
5098 reason_str
= "unknown reason";
5101 element_type
= le16_to_cpu(element
->ElementFlags
) &
5102 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK
;
5103 switch (element_type
) {
5104 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT
:
5105 element_str
= "volume";
5107 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT
:
5108 element_str
= "phys disk";
5110 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT
:
5111 element_str
= "hot spare";
5114 element_str
= "unknown element";
5117 printk(KERN_DEBUG
"\t(%s:%s), vol handle(0x%04x), "
5118 "pd handle(0x%04x), pd num(0x%02x)\n", element_str
,
5119 reason_str
, le16_to_cpu(element
->VolDevHandle
),
5120 le16_to_cpu(element
->PhysDiskDevHandle
),
5121 element
->PhysDiskNum
);
5127 * _scsih_sas_ir_config_change_event - handle ir configuration change events
5128 * @ioc: per adapter object
5129 * @fw_event: The fw_event_work object
5135 _scsih_sas_ir_config_change_event(struct MPT2SAS_ADAPTER
*ioc
,
5136 struct fw_event_work
*fw_event
)
5138 Mpi2EventIrConfigElement_t
*element
;
5141 Mpi2EventDataIrConfigChangeList_t
*event_data
= fw_event
->event_data
;
5143 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5144 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5145 _scsih_sas_ir_config_change_event_debug(ioc
, event_data
);
5148 foreign_config
= (le32_to_cpu(event_data
->Flags
) &
5149 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ? 1 : 0;
5151 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
5152 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
5154 switch (element
->ReasonCode
) {
5155 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
5156 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
5157 if (!foreign_config
)
5158 _scsih_sas_volume_add(ioc
, element
);
5160 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
5161 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
5162 if (!foreign_config
)
5163 _scsih_sas_volume_delete(ioc
, element
);
5165 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
5166 _scsih_sas_pd_hide(ioc
, element
);
5168 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
5169 _scsih_sas_pd_expose(ioc
, element
);
5171 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
5172 _scsih_sas_pd_add(ioc
, element
);
5174 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
5175 _scsih_sas_pd_delete(ioc
, element
);
5182 * _scsih_sas_ir_volume_event - IR volume event
5183 * @ioc: per adapter object
5184 * @fw_event: The fw_event_work object
5190 _scsih_sas_ir_volume_event(struct MPT2SAS_ADAPTER
*ioc
,
5191 struct fw_event_work
*fw_event
)
5194 unsigned long flags
;
5195 struct _raid_device
*raid_device
;
5199 struct MPT2SAS_TARGET
*sas_target_priv_data
;
5200 Mpi2EventDataIrVolume_t
*event_data
= fw_event
->event_data
;
5202 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED
)
5205 handle
= le16_to_cpu(event_data
->VolDevHandle
);
5206 state
= le32_to_cpu(event_data
->NewValue
);
5207 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: handle(0x%04x), "
5208 "old(0x%08x), new(0x%08x)\n", ioc
->name
, __func__
, handle
,
5209 le32_to_cpu(event_data
->PreviousValue
), state
));
5211 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5212 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
5213 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5216 case MPI2_RAID_VOL_STATE_MISSING
:
5217 case MPI2_RAID_VOL_STATE_FAILED
:
5220 if (raid_device
->starget
) {
5221 sas_target_priv_data
= raid_device
->starget
->hostdata
;
5222 sas_target_priv_data
->deleted
= 1;
5223 scsi_remove_target(&raid_device
->starget
->dev
);
5225 _scsih_raid_device_remove(ioc
, raid_device
);
5228 case MPI2_RAID_VOL_STATE_ONLINE
:
5229 case MPI2_RAID_VOL_STATE_DEGRADED
:
5230 case MPI2_RAID_VOL_STATE_OPTIMAL
:
5234 mpt2sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
5236 printk(MPT2SAS_ERR_FMT
5237 "failure at %s:%d/%s()!\n", ioc
->name
,
5238 __FILE__
, __LINE__
, __func__
);
5242 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
5244 printk(MPT2SAS_ERR_FMT
5245 "failure at %s:%d/%s()!\n", ioc
->name
,
5246 __FILE__
, __LINE__
, __func__
);
5250 raid_device
->id
= ioc
->sas_id
++;
5251 raid_device
->channel
= RAID_CHANNEL
;
5252 raid_device
->handle
= handle
;
5253 raid_device
->wwid
= wwid
;
5254 _scsih_raid_device_add(ioc
, raid_device
);
5255 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
5256 raid_device
->id
, 0);
5258 _scsih_raid_device_remove(ioc
, raid_device
);
5261 case MPI2_RAID_VOL_STATE_INITIALIZING
:
5268 * _scsih_sas_ir_physical_disk_event - PD event
5269 * @ioc: per adapter object
5270 * @fw_event: The fw_event_work object
5276 _scsih_sas_ir_physical_disk_event(struct MPT2SAS_ADAPTER
*ioc
,
5277 struct fw_event_work
*fw_event
)
5279 u16 handle
, parent_handle
;
5281 struct _sas_device
*sas_device
;
5282 unsigned long flags
;
5283 Mpi2ConfigReply_t mpi_reply
;
5284 Mpi2SasDevicePage0_t sas_device_pg0
;
5286 Mpi2EventDataIrPhysicalDisk_t
*event_data
= fw_event
->event_data
;
5289 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED
)
5292 handle
= le16_to_cpu(event_data
->PhysDiskDevHandle
);
5293 state
= le32_to_cpu(event_data
->NewValue
);
5295 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: handle(0x%04x), "
5296 "old(0x%08x), new(0x%08x)\n", ioc
->name
, __func__
, handle
,
5297 le32_to_cpu(event_data
->PreviousValue
), state
));
5299 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5300 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
5301 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5304 case MPI2_RAID_PD_STATE_ONLINE
:
5305 case MPI2_RAID_PD_STATE_DEGRADED
:
5306 case MPI2_RAID_PD_STATE_REBUILDING
:
5307 case MPI2_RAID_PD_STATE_OPTIMAL
:
5309 sas_device
->hidden_raid_component
= 1;
5313 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
5314 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
5316 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5317 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5321 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5322 MPI2_IOCSTATUS_MASK
;
5323 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5324 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5325 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5329 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
5330 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
5331 mpt2sas_transport_update_links(ioc
, sas_address
, handle
,
5332 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
5334 _scsih_add_device(ioc
, handle
, 0, 1);
5338 case MPI2_RAID_PD_STATE_OFFLINE
:
5339 case MPI2_RAID_PD_STATE_NOT_CONFIGURED
:
5340 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE
:
5341 case MPI2_RAID_PD_STATE_HOT_SPARE
:
5347 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5349 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
5350 * @ioc: per adapter object
5351 * @event_data: event data payload
5357 _scsih_sas_ir_operation_status_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
5358 Mpi2EventDataIrOperationStatus_t
*event_data
)
5360 char *reason_str
= NULL
;
5362 switch (event_data
->RAIDOperation
) {
5363 case MPI2_EVENT_IR_RAIDOP_RESYNC
:
5364 reason_str
= "resync";
5366 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION
:
5367 reason_str
= "online capacity expansion";
5369 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK
:
5370 reason_str
= "consistency check";
5372 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT
:
5373 reason_str
= "background init";
5375 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT
:
5376 reason_str
= "make data consistent";
5383 printk(MPT2SAS_INFO_FMT
"raid operational status: (%s)"
5384 "\thandle(0x%04x), percent complete(%d)\n",
5385 ioc
->name
, reason_str
,
5386 le16_to_cpu(event_data
->VolDevHandle
),
5387 event_data
->PercentComplete
);
5392 * _scsih_sas_ir_operation_status_event - handle RAID operation events
5393 * @ioc: per adapter object
5394 * @fw_event: The fw_event_work object
5400 _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER
*ioc
,
5401 struct fw_event_work
*fw_event
)
5403 Mpi2EventDataIrOperationStatus_t
*event_data
= fw_event
->event_data
;
5404 static struct _raid_device
*raid_device
;
5405 unsigned long flags
;
5408 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5409 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5410 _scsih_sas_ir_operation_status_event_debug(ioc
,
5414 /* code added for raid transport support */
5415 if (event_data
->RAIDOperation
== MPI2_EVENT_IR_RAIDOP_RESYNC
) {
5417 handle
= le16_to_cpu(event_data
->VolDevHandle
);
5419 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5420 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
5421 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5426 if (event_data
->RAIDOperation
== MPI2_EVENT_IR_RAIDOP_RESYNC
)
5427 raid_device
->percent_complete
=
5428 event_data
->PercentComplete
;
5433 * _scsih_task_set_full - handle task set full
5434 * @ioc: per adapter object
5435 * @fw_event: The fw_event_work object
5438 * Throttle back qdepth.
5441 _scsih_task_set_full(struct MPT2SAS_ADAPTER
*ioc
, struct fw_event_work
5444 unsigned long flags
;
5445 struct _sas_device
*sas_device
;
5446 static struct _raid_device
*raid_device
;
5447 struct scsi_device
*sdev
;
5453 Mpi2EventDataTaskSetFull_t
*event_data
= fw_event
->event_data
;
5455 current_depth
= le16_to_cpu(event_data
->CurrentDepth
);
5456 handle
= le16_to_cpu(event_data
->DevHandle
);
5457 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5458 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
5460 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5463 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5464 id
= sas_device
->id
;
5465 channel
= sas_device
->channel
;
5466 sas_address
= sas_device
->sas_address
;
5468 /* if hidden raid component, then change to volume characteristics */
5469 if (sas_device
->hidden_raid_component
&& sas_device
->volume_handle
) {
5470 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5471 raid_device
= _scsih_raid_device_find_by_handle(
5472 ioc
, sas_device
->volume_handle
);
5473 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5475 id
= raid_device
->id
;
5476 channel
= raid_device
->channel
;
5477 handle
= raid_device
->handle
;
5478 sas_address
= raid_device
->wwid
;
5482 if (ioc
->logging_level
& MPT_DEBUG_TASK_SET_FULL
)
5483 starget_printk(KERN_DEBUG
, sas_device
->starget
, "task set "
5484 "full: handle(0x%04x), sas_addr(0x%016llx), depth(%d)\n",
5485 handle
, (unsigned long long)sas_address
, current_depth
);
5487 shost_for_each_device(sdev
, ioc
->shost
) {
5488 if (sdev
->id
== id
&& sdev
->channel
== channel
) {
5489 if (current_depth
> sdev
->queue_depth
) {
5490 if (ioc
->logging_level
&
5491 MPT_DEBUG_TASK_SET_FULL
)
5492 sdev_printk(KERN_INFO
, sdev
, "strange "
5493 "observation, the queue depth is"
5494 " (%d) meanwhile fw queue depth "
5495 "is (%d)\n", sdev
->queue_depth
,
5499 depth
= scsi_track_queue_full(sdev
,
5502 sdev_printk(KERN_INFO
, sdev
, "Queue depth "
5503 "reduced to (%d)\n", depth
);
5505 sdev_printk(KERN_INFO
, sdev
, "Tagged Command "
5506 "Queueing is being disabled\n");
5507 else if (depth
== 0)
5508 if (ioc
->logging_level
&
5509 MPT_DEBUG_TASK_SET_FULL
)
5510 sdev_printk(KERN_INFO
, sdev
,
5511 "Queue depth not changed yet\n");
5517 * _scsih_prep_device_scan - initialize parameters prior to device scan
5518 * @ioc: per adapter object
5520 * Set the deleted flag prior to device scan. If the device is found during
5521 * the scan, then we clear the deleted flag.
5524 _scsih_prep_device_scan(struct MPT2SAS_ADAPTER
*ioc
)
5526 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
5527 struct scsi_device
*sdev
;
5529 shost_for_each_device(sdev
, ioc
->shost
) {
5530 sas_device_priv_data
= sdev
->hostdata
;
5531 if (sas_device_priv_data
&& sas_device_priv_data
->sas_target
)
5532 sas_device_priv_data
->sas_target
->deleted
= 1;
5537 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
5538 * @ioc: per adapter object
5539 * @sas_address: sas address
5540 * @slot: enclosure slot id
5541 * @handle: device handle
5543 * After host reset, find out whether devices are still responding.
5544 * Used in _scsi_remove_unresponsive_sas_devices.
5549 _scsih_mark_responding_sas_device(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
,
5550 u16 slot
, u16 handle
)
5552 struct MPT2SAS_TARGET
*sas_target_priv_data
;
5553 struct scsi_target
*starget
;
5554 struct _sas_device
*sas_device
;
5555 unsigned long flags
;
5557 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5558 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
) {
5559 if (sas_device
->sas_address
== sas_address
&&
5560 sas_device
->slot
== slot
&& sas_device
->starget
) {
5561 sas_device
->responding
= 1;
5562 starget
= sas_device
->starget
;
5563 if (starget
&& starget
->hostdata
) {
5564 sas_target_priv_data
= starget
->hostdata
;
5565 sas_target_priv_data
->tm_busy
= 0;
5566 sas_target_priv_data
->deleted
= 0;
5568 sas_target_priv_data
= NULL
;
5569 starget_printk(KERN_INFO
, sas_device
->starget
,
5570 "handle(0x%04x), sas_addr(0x%016llx), enclosure "
5571 "logical id(0x%016llx), slot(%d)\n", handle
,
5572 (unsigned long long)sas_device
->sas_address
,
5573 (unsigned long long)
5574 sas_device
->enclosure_logical_id
,
5576 if (sas_device
->handle
== handle
)
5578 printk(KERN_INFO
"\thandle changed from(0x%04x)!!!\n",
5579 sas_device
->handle
);
5580 sas_device
->handle
= handle
;
5581 if (sas_target_priv_data
)
5582 sas_target_priv_data
->handle
= handle
;
5587 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5591 * _scsih_search_responding_sas_devices -
5592 * @ioc: per adapter object
5594 * After host reset, find out whether devices are still responding.
5600 _scsih_search_responding_sas_devices(struct MPT2SAS_ADAPTER
*ioc
)
5602 Mpi2SasDevicePage0_t sas_device_pg0
;
5603 Mpi2ConfigReply_t mpi_reply
;
5610 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
, __func__
);
5612 if (list_empty(&ioc
->sas_device_list
))
5616 while (!(mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
5617 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
,
5619 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5620 MPI2_IOCSTATUS_MASK
;
5621 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
5623 handle
= le16_to_cpu(sas_device_pg0
.DevHandle
);
5624 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
5625 if (!(_scsih_is_end_device(device_info
)))
5627 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
5628 slot
= le16_to_cpu(sas_device_pg0
.Slot
);
5629 _scsih_mark_responding_sas_device(ioc
, sas_address
, slot
,
5635 * _scsih_mark_responding_raid_device - mark a raid_device as responding
5636 * @ioc: per adapter object
5637 * @wwid: world wide identifier for raid volume
5638 * @handle: device handle
5640 * After host reset, find out whether devices are still responding.
5641 * Used in _scsi_remove_unresponsive_raid_devices.
5646 _scsih_mark_responding_raid_device(struct MPT2SAS_ADAPTER
*ioc
, u64 wwid
,
5649 struct MPT2SAS_TARGET
*sas_target_priv_data
;
5650 struct scsi_target
*starget
;
5651 struct _raid_device
*raid_device
;
5652 unsigned long flags
;
5654 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5655 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
5656 if (raid_device
->wwid
== wwid
&& raid_device
->starget
) {
5657 starget
= raid_device
->starget
;
5658 if (starget
&& starget
->hostdata
) {
5659 sas_target_priv_data
= starget
->hostdata
;
5660 sas_target_priv_data
->deleted
= 0;
5662 sas_target_priv_data
= NULL
;
5663 raid_device
->responding
= 1;
5664 starget_printk(KERN_INFO
, raid_device
->starget
,
5665 "handle(0x%04x), wwid(0x%016llx)\n", handle
,
5666 (unsigned long long)raid_device
->wwid
);
5667 if (raid_device
->handle
== handle
)
5669 printk(KERN_INFO
"\thandle changed from(0x%04x)!!!\n",
5670 raid_device
->handle
);
5671 raid_device
->handle
= handle
;
5672 if (sas_target_priv_data
)
5673 sas_target_priv_data
->handle
= handle
;
5678 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5682 * _scsih_search_responding_raid_devices -
5683 * @ioc: per adapter object
5685 * After host reset, find out whether devices are still responding.
5691 _scsih_search_responding_raid_devices(struct MPT2SAS_ADAPTER
*ioc
)
5693 Mpi2RaidVolPage1_t volume_pg1
;
5694 Mpi2ConfigReply_t mpi_reply
;
5698 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
, __func__
);
5700 if (list_empty(&ioc
->raid_device_list
))
5704 while (!(mpt2sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
5705 &volume_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
5706 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5707 MPI2_IOCSTATUS_MASK
;
5708 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
5710 handle
= le16_to_cpu(volume_pg1
.DevHandle
);
5711 _scsih_mark_responding_raid_device(ioc
,
5712 le64_to_cpu(volume_pg1
.WWID
), handle
);
5717 * _scsih_mark_responding_expander - mark a expander as responding
5718 * @ioc: per adapter object
5719 * @sas_address: sas address
5722 * After host reset, find out whether devices are still responding.
5723 * Used in _scsi_remove_unresponsive_expanders.
5728 _scsih_mark_responding_expander(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
,
5731 struct _sas_node
*sas_expander
;
5732 unsigned long flags
;
5735 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5736 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
5737 if (sas_expander
->sas_address
!= sas_address
)
5739 sas_expander
->responding
= 1;
5740 if (sas_expander
->handle
== handle
)
5742 printk(KERN_INFO
"\texpander(0x%016llx): handle changed"
5743 " from(0x%04x) to (0x%04x)!!!\n",
5744 (unsigned long long)sas_expander
->sas_address
,
5745 sas_expander
->handle
, handle
);
5746 sas_expander
->handle
= handle
;
5747 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++)
5748 sas_expander
->phy
[i
].handle
= handle
;
5752 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5756 * _scsih_search_responding_expanders -
5757 * @ioc: per adapter object
5759 * After host reset, find out whether devices are still responding.
5765 _scsih_search_responding_expanders(struct MPT2SAS_ADAPTER
*ioc
)
5767 Mpi2ExpanderPage0_t expander_pg0
;
5768 Mpi2ConfigReply_t mpi_reply
;
5773 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
, __func__
);
5775 if (list_empty(&ioc
->sas_expander_list
))
5779 while (!(mpt2sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
5780 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL
, handle
))) {
5782 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5783 MPI2_IOCSTATUS_MASK
;
5784 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
5787 handle
= le16_to_cpu(expander_pg0
.DevHandle
);
5788 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
5789 printk(KERN_INFO
"\texpander present: handle(0x%04x), "
5790 "sas_addr(0x%016llx)\n", handle
,
5791 (unsigned long long)sas_address
);
5792 _scsih_mark_responding_expander(ioc
, sas_address
, handle
);
5798 * _scsih_remove_unresponding_sas_devices - removing unresponding devices
5799 * @ioc: per adapter object
5804 _scsih_remove_unresponding_sas_devices(struct MPT2SAS_ADAPTER
*ioc
)
5806 struct _sas_device
*sas_device
, *sas_device_next
;
5807 struct _sas_node
*sas_expander
;
5808 struct _raid_device
*raid_device
, *raid_device_next
;
5811 list_for_each_entry_safe(sas_device
, sas_device_next
,
5812 &ioc
->sas_device_list
, list
) {
5813 if (sas_device
->responding
) {
5814 sas_device
->responding
= 0;
5817 if (sas_device
->starget
)
5818 starget_printk(KERN_INFO
, sas_device
->starget
,
5819 "removing: handle(0x%04x), sas_addr(0x%016llx), "
5820 "enclosure logical id(0x%016llx), slot(%d)\n",
5822 (unsigned long long)sas_device
->sas_address
,
5823 (unsigned long long)
5824 sas_device
->enclosure_logical_id
,
5826 _scsih_remove_device(ioc
, sas_device
);
5829 list_for_each_entry_safe(raid_device
, raid_device_next
,
5830 &ioc
->raid_device_list
, list
) {
5831 if (raid_device
->responding
) {
5832 raid_device
->responding
= 0;
5835 if (raid_device
->starget
) {
5836 starget_printk(KERN_INFO
, raid_device
->starget
,
5837 "removing: handle(0x%04x), wwid(0x%016llx)\n",
5838 raid_device
->handle
,
5839 (unsigned long long)raid_device
->wwid
);
5840 scsi_remove_target(&raid_device
->starget
->dev
);
5842 _scsih_raid_device_remove(ioc
, raid_device
);
5845 retry_expander_search
:
5846 sas_expander
= NULL
;
5847 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
5848 if (sas_expander
->responding
) {
5849 sas_expander
->responding
= 0;
5852 _scsih_expander_remove(ioc
, sas_expander
->sas_address
);
5853 goto retry_expander_search
;
5858 * mpt2sas_scsih_reset_handler - reset callback handler (for scsih)
5859 * @ioc: per adapter object
5860 * @reset_phase: phase
5862 * The handler for doing any required cleanup or initialization.
5864 * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
5865 * MPT2_IOC_DONE_RESET
5870 mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER
*ioc
, int reset_phase
)
5872 switch (reset_phase
) {
5873 case MPT2_IOC_PRE_RESET
:
5874 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: "
5875 "MPT2_IOC_PRE_RESET\n", ioc
->name
, __func__
));
5877 case MPT2_IOC_AFTER_RESET
:
5878 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: "
5879 "MPT2_IOC_AFTER_RESET\n", ioc
->name
, __func__
));
5880 if (ioc
->scsih_cmds
.status
& MPT2_CMD_PENDING
) {
5881 ioc
->scsih_cmds
.status
|= MPT2_CMD_RESET
;
5882 mpt2sas_base_free_smid(ioc
, ioc
->scsih_cmds
.smid
);
5883 complete(&ioc
->scsih_cmds
.done
);
5885 if (ioc
->tm_cmds
.status
& MPT2_CMD_PENDING
) {
5886 ioc
->tm_cmds
.status
|= MPT2_CMD_RESET
;
5887 mpt2sas_base_free_smid(ioc
, ioc
->tm_cmds
.smid
);
5888 complete(&ioc
->tm_cmds
.done
);
5890 _scsih_fw_event_cleanup_queue(ioc
);
5891 _scsih_flush_running_cmds(ioc
);
5892 _scsih_queue_rescan(ioc
);
5894 case MPT2_IOC_DONE_RESET
:
5895 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: "
5896 "MPT2_IOC_DONE_RESET\n", ioc
->name
, __func__
));
5897 _scsih_sas_host_refresh(ioc
);
5898 _scsih_prep_device_scan(ioc
);
5899 _scsih_search_responding_sas_devices(ioc
);
5900 _scsih_search_responding_raid_devices(ioc
);
5901 _scsih_search_responding_expanders(ioc
);
5907 * _firmware_event_work - delayed task for processing firmware events
5908 * @ioc: per adapter object
5909 * @work: equal to the fw_event_work object
5915 _firmware_event_work(struct work_struct
*work
)
5917 struct fw_event_work
*fw_event
= container_of(work
,
5918 struct fw_event_work
, delayed_work
.work
);
5919 unsigned long flags
;
5920 struct MPT2SAS_ADAPTER
*ioc
= fw_event
->ioc
;
5922 /* the queue is being flushed so ignore this event */
5923 if (ioc
->remove_host
|| fw_event
->cancel_pending_work
) {
5924 _scsih_fw_event_free(ioc
, fw_event
);
5928 if (fw_event
->event
== MPT2SAS_RESCAN_AFTER_HOST_RESET
) {
5929 _scsih_fw_event_free(ioc
, fw_event
);
5930 spin_lock_irqsave(&ioc
->ioc_reset_in_progress_lock
, flags
);
5931 if (ioc
->shost_recovery
) {
5932 init_completion(&ioc
->shost_recovery_done
);
5933 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
,
5935 wait_for_completion(&ioc
->shost_recovery_done
);
5937 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
,
5939 _scsih_remove_unresponding_sas_devices(ioc
);
5943 switch (fw_event
->event
) {
5944 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
5945 _scsih_sas_topology_change_event(ioc
, fw_event
);
5947 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
5948 _scsih_sas_device_status_change_event(ioc
,
5951 case MPI2_EVENT_SAS_DISCOVERY
:
5952 _scsih_sas_discovery_event(ioc
,
5955 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
5956 _scsih_sas_broadcast_primative_event(ioc
,
5959 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
5960 _scsih_sas_enclosure_dev_status_change_event(ioc
,
5963 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
5964 _scsih_sas_ir_config_change_event(ioc
, fw_event
);
5966 case MPI2_EVENT_IR_VOLUME
:
5967 _scsih_sas_ir_volume_event(ioc
, fw_event
);
5969 case MPI2_EVENT_IR_PHYSICAL_DISK
:
5970 _scsih_sas_ir_physical_disk_event(ioc
, fw_event
);
5972 case MPI2_EVENT_IR_OPERATION_STATUS
:
5973 _scsih_sas_ir_operation_status_event(ioc
, fw_event
);
5975 case MPI2_EVENT_TASK_SET_FULL
:
5976 _scsih_task_set_full(ioc
, fw_event
);
5979 _scsih_fw_event_free(ioc
, fw_event
);
5983 * mpt2sas_scsih_event_callback - firmware event handler (called at ISR time)
5984 * @ioc: per adapter object
5985 * @msix_index: MSIX table index supplied by the OS
5986 * @reply: reply message frame(lower 32bit addr)
5987 * Context: interrupt.
5989 * This function merely adds a new work task into ioc->firmware_event_thread.
5990 * The tasks are worked from _firmware_event_work in user context.
5992 * Return 1 meaning mf should be freed from _base_interrupt
5993 * 0 means the mf is freed from this function.
5996 mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER
*ioc
, u8 msix_index
,
5999 struct fw_event_work
*fw_event
;
6000 Mpi2EventNotificationReply_t
*mpi_reply
;
6004 /* events turned off due to host reset or driver unloading */
6005 if (ioc
->remove_host
)
6008 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
6009 event
= le16_to_cpu(mpi_reply
->Event
);
6013 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
6015 Mpi2EventDataSasBroadcastPrimitive_t
*baen_data
=
6016 (Mpi2EventDataSasBroadcastPrimitive_t
*)
6017 mpi_reply
->EventData
;
6019 if (baen_data
->Primitive
!=
6020 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT
||
6021 ioc
->broadcast_aen_busy
)
6023 ioc
->broadcast_aen_busy
= 1;
6027 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
6028 _scsih_check_topo_delete_events(ioc
,
6029 (Mpi2EventDataSasTopologyChangeList_t
*)
6030 mpi_reply
->EventData
);
6033 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
6034 case MPI2_EVENT_IR_OPERATION_STATUS
:
6035 case MPI2_EVENT_SAS_DISCOVERY
:
6036 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
6037 case MPI2_EVENT_IR_VOLUME
:
6038 case MPI2_EVENT_IR_PHYSICAL_DISK
:
6039 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
6040 case MPI2_EVENT_TASK_SET_FULL
:
6043 default: /* ignore the rest */
6047 fw_event
= kzalloc(sizeof(struct fw_event_work
), GFP_ATOMIC
);
6049 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6050 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6053 sz
= le16_to_cpu(mpi_reply
->EventDataLength
) * 4;
6054 fw_event
->event_data
= kzalloc(sz
, GFP_ATOMIC
);
6055 if (!fw_event
->event_data
) {
6056 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6057 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6062 memcpy(fw_event
->event_data
, mpi_reply
->EventData
,
6064 fw_event
->ioc
= ioc
;
6065 fw_event
->VF_ID
= mpi_reply
->VF_ID
;
6066 fw_event
->VP_ID
= mpi_reply
->VP_ID
;
6067 fw_event
->event
= event
;
6068 _scsih_fw_event_add(ioc
, fw_event
);
6072 /* shost template */
6073 static struct scsi_host_template scsih_driver_template
= {
6074 .module
= THIS_MODULE
,
6075 .name
= "Fusion MPT SAS Host",
6076 .proc_name
= MPT2SAS_DRIVER_NAME
,
6077 .queuecommand
= _scsih_qcmd
,
6078 .target_alloc
= _scsih_target_alloc
,
6079 .slave_alloc
= _scsih_slave_alloc
,
6080 .slave_configure
= _scsih_slave_configure
,
6081 .target_destroy
= _scsih_target_destroy
,
6082 .slave_destroy
= _scsih_slave_destroy
,
6083 .change_queue_depth
= _scsih_change_queue_depth
,
6084 .change_queue_type
= _scsih_change_queue_type
,
6085 .eh_abort_handler
= _scsih_abort
,
6086 .eh_device_reset_handler
= _scsih_dev_reset
,
6087 .eh_target_reset_handler
= _scsih_target_reset
,
6088 .eh_host_reset_handler
= _scsih_host_reset
,
6089 .bios_param
= _scsih_bios_param
,
6092 .sg_tablesize
= MPT2SAS_SG_DEPTH
,
6093 .max_sectors
= 8192,
6095 .use_clustering
= ENABLE_CLUSTERING
,
6096 .shost_attrs
= mpt2sas_host_attrs
,
6097 .sdev_attrs
= mpt2sas_dev_attrs
,
6101 * _scsih_expander_node_remove - removing expander device from list.
6102 * @ioc: per adapter object
6103 * @sas_expander: the sas_device object
6104 * Context: Calling function should acquire ioc->sas_node_lock.
6106 * Removing object and freeing associated memory from the
6107 * ioc->sas_expander_list.
6112 _scsih_expander_node_remove(struct MPT2SAS_ADAPTER
*ioc
,
6113 struct _sas_node
*sas_expander
)
6115 struct _sas_port
*mpt2sas_port
;
6116 struct _sas_device
*sas_device
;
6117 struct _sas_node
*expander_sibling
;
6118 unsigned long flags
;
6123 /* remove sibling ports attached to this expander */
6124 retry_device_search
:
6125 list_for_each_entry(mpt2sas_port
,
6126 &sas_expander
->sas_port_list
, port_list
) {
6127 if (mpt2sas_port
->remote_identify
.device_type
==
6129 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6131 mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
6132 mpt2sas_port
->remote_identify
.sas_address
);
6133 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6136 _scsih_remove_device(ioc
, sas_device
);
6137 if (ioc
->shost_recovery
)
6139 goto retry_device_search
;
6143 retry_expander_search
:
6144 list_for_each_entry(mpt2sas_port
,
6145 &sas_expander
->sas_port_list
, port_list
) {
6147 if (mpt2sas_port
->remote_identify
.device_type
==
6148 MPI2_SAS_DEVICE_INFO_EDGE_EXPANDER
||
6149 mpt2sas_port
->remote_identify
.device_type
==
6150 MPI2_SAS_DEVICE_INFO_FANOUT_EXPANDER
) {
6152 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
6154 mpt2sas_scsih_expander_find_by_sas_address(
6155 ioc
, mpt2sas_port
->remote_identify
.sas_address
);
6156 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
6157 if (!expander_sibling
)
6159 _scsih_expander_remove(ioc
,
6160 expander_sibling
->sas_address
);
6161 if (ioc
->shost_recovery
)
6163 goto retry_expander_search
;
6167 mpt2sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
6168 sas_expander
->sas_address_parent
);
6170 printk(MPT2SAS_INFO_FMT
"expander_remove: handle"
6171 "(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
6172 sas_expander
->handle
, (unsigned long long)
6173 sas_expander
->sas_address
);
6175 list_del(&sas_expander
->list
);
6176 kfree(sas_expander
->phy
);
6177 kfree(sas_expander
);
6181 * _scsih_ir_shutdown - IR shutdown notification
6182 * @ioc: per adapter object
6184 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
6185 * the host system is shutting down.
6190 _scsih_ir_shutdown(struct MPT2SAS_ADAPTER
*ioc
)
6192 Mpi2RaidActionRequest_t
*mpi_request
;
6193 Mpi2RaidActionReply_t
*mpi_reply
;
6196 /* is IR firmware build loaded ? */
6197 if (!ioc
->ir_firmware
)
6200 /* are there any volumes ? */
6201 if (list_empty(&ioc
->raid_device_list
))
6204 mutex_lock(&ioc
->scsih_cmds
.mutex
);
6206 if (ioc
->scsih_cmds
.status
!= MPT2_CMD_NOT_USED
) {
6207 printk(MPT2SAS_ERR_FMT
"%s: scsih_cmd in use\n",
6208 ioc
->name
, __func__
);
6211 ioc
->scsih_cmds
.status
= MPT2_CMD_PENDING
;
6213 smid
= mpt2sas_base_get_smid(ioc
, ioc
->scsih_cb_idx
);
6215 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
6216 ioc
->name
, __func__
);
6217 ioc
->scsih_cmds
.status
= MPT2_CMD_NOT_USED
;
6221 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
6222 ioc
->scsih_cmds
.smid
= smid
;
6223 memset(mpi_request
, 0, sizeof(Mpi2RaidActionRequest_t
));
6225 mpi_request
->Function
= MPI2_FUNCTION_RAID_ACTION
;
6226 mpi_request
->Action
= MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED
;
6228 printk(MPT2SAS_INFO_FMT
"IR shutdown (sending)\n", ioc
->name
);
6229 init_completion(&ioc
->scsih_cmds
.done
);
6230 mpt2sas_base_put_smid_default(ioc
, smid
);
6231 wait_for_completion_timeout(&ioc
->scsih_cmds
.done
, 10*HZ
);
6233 if (!(ioc
->scsih_cmds
.status
& MPT2_CMD_COMPLETE
)) {
6234 printk(MPT2SAS_ERR_FMT
"%s: timeout\n",
6235 ioc
->name
, __func__
);
6239 if (ioc
->scsih_cmds
.status
& MPT2_CMD_REPLY_VALID
) {
6240 mpi_reply
= ioc
->scsih_cmds
.reply
;
6242 printk(MPT2SAS_INFO_FMT
"IR shutdown (complete): "
6243 "ioc_status(0x%04x), loginfo(0x%08x)\n",
6244 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
6245 le32_to_cpu(mpi_reply
->IOCLogInfo
));
6249 ioc
->scsih_cmds
.status
= MPT2_CMD_NOT_USED
;
6250 mutex_unlock(&ioc
->scsih_cmds
.mutex
);
6254 * _scsih_shutdown - routine call during system shutdown
6255 * @pdev: PCI device struct
6260 _scsih_shutdown(struct pci_dev
*pdev
)
6262 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6263 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
6264 struct workqueue_struct
*wq
;
6265 unsigned long flags
;
6267 ioc
->remove_host
= 1;
6268 _scsih_fw_event_cleanup_queue(ioc
);
6270 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
6271 wq
= ioc
->firmware_event_thread
;
6272 ioc
->firmware_event_thread
= NULL
;
6273 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
6275 destroy_workqueue(wq
);
6277 _scsih_ir_shutdown(ioc
);
6278 mpt2sas_base_detach(ioc
);
6282 * _scsih_remove - detach and remove add host
6283 * @pdev: PCI device struct
6285 * Routine called when unloading the driver.
6288 static void __devexit
6289 _scsih_remove(struct pci_dev
*pdev
)
6291 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6292 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
6293 struct _sas_port
*mpt2sas_port
;
6294 struct _sas_device
*sas_device
;
6295 struct _sas_node
*expander_sibling
;
6296 struct _raid_device
*raid_device
, *next
;
6297 struct MPT2SAS_TARGET
*sas_target_priv_data
;
6298 struct workqueue_struct
*wq
;
6299 unsigned long flags
;
6301 ioc
->remove_host
= 1;
6302 _scsih_fw_event_cleanup_queue(ioc
);
6304 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
6305 wq
= ioc
->firmware_event_thread
;
6306 ioc
->firmware_event_thread
= NULL
;
6307 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
6309 destroy_workqueue(wq
);
6311 /* release all the volumes */
6312 list_for_each_entry_safe(raid_device
, next
, &ioc
->raid_device_list
,
6314 if (raid_device
->starget
) {
6315 sas_target_priv_data
=
6316 raid_device
->starget
->hostdata
;
6317 sas_target_priv_data
->deleted
= 1;
6318 scsi_remove_target(&raid_device
->starget
->dev
);
6320 printk(MPT2SAS_INFO_FMT
"removing handle(0x%04x), wwid"
6321 "(0x%016llx)\n", ioc
->name
, raid_device
->handle
,
6322 (unsigned long long) raid_device
->wwid
);
6323 _scsih_raid_device_remove(ioc
, raid_device
);
6326 /* free ports attached to the sas_host */
6328 list_for_each_entry(mpt2sas_port
,
6329 &ioc
->sas_hba
.sas_port_list
, port_list
) {
6330 if (mpt2sas_port
->remote_identify
.device_type
==
6333 mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
6334 mpt2sas_port
->remote_identify
.sas_address
);
6336 _scsih_remove_device(ioc
, sas_device
);
6341 mpt2sas_scsih_expander_find_by_sas_address(ioc
,
6342 mpt2sas_port
->remote_identify
.sas_address
);
6343 if (expander_sibling
) {
6344 _scsih_expander_remove(ioc
,
6345 expander_sibling
->sas_address
);
6351 /* free phys attached to the sas_host */
6352 if (ioc
->sas_hba
.num_phys
) {
6353 kfree(ioc
->sas_hba
.phy
);
6354 ioc
->sas_hba
.phy
= NULL
;
6355 ioc
->sas_hba
.num_phys
= 0;
6358 sas_remove_host(shost
);
6359 _scsih_shutdown(pdev
);
6360 list_del(&ioc
->list
);
6361 scsi_remove_host(shost
);
6362 scsi_host_put(shost
);
6366 * _scsih_probe_boot_devices - reports 1st device
6367 * @ioc: per adapter object
6369 * If specified in bios page 2, this routine reports the 1st
6370 * device scsi-ml or sas transport for persistent boot device
6371 * purposes. Please refer to function _scsih_determine_boot_device()
6374 _scsih_probe_boot_devices(struct MPT2SAS_ADAPTER
*ioc
)
6378 struct _sas_device
*sas_device
;
6379 struct _raid_device
*raid_device
;
6381 u64 sas_address_parent
;
6383 unsigned long flags
;
6387 if (ioc
->req_boot_device
.device
) {
6388 device
= ioc
->req_boot_device
.device
;
6389 is_raid
= ioc
->req_boot_device
.is_raid
;
6390 } else if (ioc
->req_alt_boot_device
.device
) {
6391 device
= ioc
->req_alt_boot_device
.device
;
6392 is_raid
= ioc
->req_alt_boot_device
.is_raid
;
6393 } else if (ioc
->current_boot_device
.device
) {
6394 device
= ioc
->current_boot_device
.device
;
6395 is_raid
= ioc
->current_boot_device
.is_raid
;
6402 raid_device
= device
;
6403 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
6404 raid_device
->id
, 0);
6406 _scsih_raid_device_remove(ioc
, raid_device
);
6408 sas_device
= device
;
6409 handle
= sas_device
->handle
;
6410 sas_address_parent
= sas_device
->sas_address_parent
;
6411 sas_address
= sas_device
->sas_address
;
6412 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6413 list_move_tail(&sas_device
->list
, &ioc
->sas_device_list
);
6414 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6415 if (!mpt2sas_transport_port_add(ioc
, sas_device
->handle
,
6416 sas_device
->sas_address_parent
)) {
6417 _scsih_sas_device_remove(ioc
, sas_device
);
6418 } else if (!sas_device
->starget
) {
6419 mpt2sas_transport_port_remove(ioc
, sas_address
,
6420 sas_address_parent
);
6421 _scsih_sas_device_remove(ioc
, sas_device
);
6427 * _scsih_probe_raid - reporting raid volumes to scsi-ml
6428 * @ioc: per adapter object
6430 * Called during initial loading of the driver.
6433 _scsih_probe_raid(struct MPT2SAS_ADAPTER
*ioc
)
6435 struct _raid_device
*raid_device
, *raid_next
;
6438 list_for_each_entry_safe(raid_device
, raid_next
,
6439 &ioc
->raid_device_list
, list
) {
6440 if (raid_device
->starget
)
6442 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
6443 raid_device
->id
, 0);
6445 _scsih_raid_device_remove(ioc
, raid_device
);
6450 * _scsih_probe_sas - reporting sas devices to sas transport
6451 * @ioc: per adapter object
6453 * Called during initial loading of the driver.
6456 _scsih_probe_sas(struct MPT2SAS_ADAPTER
*ioc
)
6458 struct _sas_device
*sas_device
, *next
;
6459 unsigned long flags
;
6461 /* SAS Device List */
6462 list_for_each_entry_safe(sas_device
, next
, &ioc
->sas_device_init_list
,
6464 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6465 list_move_tail(&sas_device
->list
, &ioc
->sas_device_list
);
6466 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6468 if (!mpt2sas_transport_port_add(ioc
, sas_device
->handle
,
6469 sas_device
->sas_address_parent
)) {
6470 _scsih_sas_device_remove(ioc
, sas_device
);
6471 } else if (!sas_device
->starget
) {
6472 mpt2sas_transport_port_remove(ioc
,
6473 sas_device
->sas_address
,
6474 sas_device
->sas_address_parent
);
6475 _scsih_sas_device_remove(ioc
, sas_device
);
6481 * _scsih_probe_devices - probing for devices
6482 * @ioc: per adapter object
6484 * Called during initial loading of the driver.
6487 _scsih_probe_devices(struct MPT2SAS_ADAPTER
*ioc
)
6489 u16 volume_mapping_flags
=
6490 le16_to_cpu(ioc
->ioc_pg8
.IRVolumeMappingFlags
) &
6491 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE
;
6493 if (!(ioc
->facts
.ProtocolFlags
& MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR
))
6494 return; /* return when IOC doesn't support initiator mode */
6496 _scsih_probe_boot_devices(ioc
);
6498 if (ioc
->ir_firmware
) {
6499 if ((volume_mapping_flags
&
6500 MPI2_IOCPAGE8_IRFLAGS_HIGH_VOLUME_MAPPING
)) {
6501 _scsih_probe_sas(ioc
);
6502 _scsih_probe_raid(ioc
);
6504 _scsih_probe_raid(ioc
);
6505 _scsih_probe_sas(ioc
);
6508 _scsih_probe_sas(ioc
);
6512 * _scsih_probe - attach and add scsi host
6513 * @pdev: PCI device struct
6514 * @id: pci device id
6516 * Returns 0 success, anything else error.
6519 _scsih_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
6521 struct MPT2SAS_ADAPTER
*ioc
;
6522 struct Scsi_Host
*shost
;
6524 shost
= scsi_host_alloc(&scsih_driver_template
,
6525 sizeof(struct MPT2SAS_ADAPTER
));
6529 /* init local params */
6530 ioc
= shost_priv(shost
);
6531 memset(ioc
, 0, sizeof(struct MPT2SAS_ADAPTER
));
6532 INIT_LIST_HEAD(&ioc
->list
);
6533 list_add_tail(&ioc
->list
, &mpt2sas_ioc_list
);
6535 ioc
->id
= mpt_ids
++;
6536 sprintf(ioc
->name
, "%s%d", MPT2SAS_DRIVER_NAME
, ioc
->id
);
6538 ioc
->scsi_io_cb_idx
= scsi_io_cb_idx
;
6539 ioc
->tm_cb_idx
= tm_cb_idx
;
6540 ioc
->ctl_cb_idx
= ctl_cb_idx
;
6541 ioc
->base_cb_idx
= base_cb_idx
;
6542 ioc
->transport_cb_idx
= transport_cb_idx
;
6543 ioc
->scsih_cb_idx
= scsih_cb_idx
;
6544 ioc
->config_cb_idx
= config_cb_idx
;
6545 ioc
->tm_tr_cb_idx
= tm_tr_cb_idx
;
6546 ioc
->tm_sas_control_cb_idx
= tm_sas_control_cb_idx
;
6547 ioc
->logging_level
= logging_level
;
6548 /* misc semaphores and spin locks */
6549 spin_lock_init(&ioc
->ioc_reset_in_progress_lock
);
6550 spin_lock_init(&ioc
->scsi_lookup_lock
);
6551 spin_lock_init(&ioc
->sas_device_lock
);
6552 spin_lock_init(&ioc
->sas_node_lock
);
6553 spin_lock_init(&ioc
->fw_event_lock
);
6554 spin_lock_init(&ioc
->raid_device_lock
);
6556 INIT_LIST_HEAD(&ioc
->sas_device_list
);
6557 INIT_LIST_HEAD(&ioc
->sas_device_init_list
);
6558 INIT_LIST_HEAD(&ioc
->sas_expander_list
);
6559 INIT_LIST_HEAD(&ioc
->fw_event_list
);
6560 INIT_LIST_HEAD(&ioc
->raid_device_list
);
6561 INIT_LIST_HEAD(&ioc
->sas_hba
.sas_port_list
);
6562 INIT_LIST_HEAD(&ioc
->delayed_tr_list
);
6564 /* init shost parameters */
6565 shost
->max_cmd_len
= 16;
6566 shost
->max_lun
= max_lun
;
6567 shost
->transportt
= mpt2sas_transport_template
;
6568 shost
->unique_id
= ioc
->id
;
6570 if ((scsi_add_host(shost
, &pdev
->dev
))) {
6571 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6572 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6573 list_del(&ioc
->list
);
6574 goto out_add_shost_fail
;
6577 scsi_host_set_prot(shost
, SHOST_DIF_TYPE1_PROTECTION
6578 | SHOST_DIF_TYPE3_PROTECTION
);
6579 scsi_host_set_guard(shost
, SHOST_DIX_GUARD_CRC
);
6582 snprintf(ioc
->firmware_event_name
, sizeof(ioc
->firmware_event_name
),
6583 "fw_event%d", ioc
->id
);
6584 ioc
->firmware_event_thread
= create_singlethread_workqueue(
6585 ioc
->firmware_event_name
);
6586 if (!ioc
->firmware_event_thread
) {
6587 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6588 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6589 goto out_thread_fail
;
6592 ioc
->wait_for_port_enable_to_complete
= 1;
6593 if ((mpt2sas_base_attach(ioc
))) {
6594 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6595 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6596 goto out_attach_fail
;
6599 ioc
->wait_for_port_enable_to_complete
= 0;
6600 _scsih_probe_devices(ioc
);
6604 destroy_workqueue(ioc
->firmware_event_thread
);
6606 list_del(&ioc
->list
);
6607 scsi_remove_host(shost
);
6614 * _scsih_suspend - power management suspend main entry point
6615 * @pdev: PCI device struct
6616 * @state: PM state change to (usually PCI_D3)
6618 * Returns 0 success, anything else error.
6621 _scsih_suspend(struct pci_dev
*pdev
, pm_message_t state
)
6623 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6624 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
6627 mpt2sas_base_stop_watchdog(ioc
);
6628 flush_scheduled_work();
6629 scsi_block_requests(shost
);
6630 device_state
= pci_choose_state(pdev
, state
);
6631 printk(MPT2SAS_INFO_FMT
"pdev=0x%p, slot=%s, entering "
6632 "operating state [D%d]\n", ioc
->name
, pdev
,
6633 pci_name(pdev
), device_state
);
6635 mpt2sas_base_free_resources(ioc
);
6636 pci_save_state(pdev
);
6637 pci_disable_device(pdev
);
6638 pci_set_power_state(pdev
, device_state
);
6643 * _scsih_resume - power management resume main entry point
6644 * @pdev: PCI device struct
6646 * Returns 0 success, anything else error.
6649 _scsih_resume(struct pci_dev
*pdev
)
6651 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6652 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
6653 u32 device_state
= pdev
->current_state
;
6656 printk(MPT2SAS_INFO_FMT
"pdev=0x%p, slot=%s, previous "
6657 "operating state [D%d]\n", ioc
->name
, pdev
,
6658 pci_name(pdev
), device_state
);
6660 pci_set_power_state(pdev
, PCI_D0
);
6661 pci_enable_wake(pdev
, PCI_D0
, 0);
6662 pci_restore_state(pdev
);
6664 r
= mpt2sas_base_map_resources(ioc
);
6668 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
, SOFT_RESET
);
6669 scsi_unblock_requests(shost
);
6670 mpt2sas_base_start_watchdog(ioc
);
6673 #endif /* CONFIG_PM */
6676 * _scsih_pci_error_detected - Called when a PCI error is detected.
6677 * @pdev: PCI device struct
6678 * @state: PCI channel state
6680 * Description: Called when a PCI error is detected.
6683 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
6685 static pci_ers_result_t
6686 _scsih_pci_error_detected(struct pci_dev
*pdev
, pci_channel_state_t state
)
6688 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6689 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
6691 printk(MPT2SAS_INFO_FMT
"PCI error: detected callback, state(%d)!!\n",
6695 case pci_channel_io_normal
:
6696 return PCI_ERS_RESULT_CAN_RECOVER
;
6697 case pci_channel_io_frozen
:
6698 scsi_block_requests(ioc
->shost
);
6699 mpt2sas_base_stop_watchdog(ioc
);
6700 mpt2sas_base_free_resources(ioc
);
6701 return PCI_ERS_RESULT_NEED_RESET
;
6702 case pci_channel_io_perm_failure
:
6703 _scsih_remove(pdev
);
6704 return PCI_ERS_RESULT_DISCONNECT
;
6706 return PCI_ERS_RESULT_NEED_RESET
;
6710 * _scsih_pci_slot_reset - Called when PCI slot has been reset.
6711 * @pdev: PCI device struct
6713 * Description: This routine is called by the pci error recovery
6714 * code after the PCI slot has been reset, just before we
6715 * should resume normal operations.
6717 static pci_ers_result_t
6718 _scsih_pci_slot_reset(struct pci_dev
*pdev
)
6720 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6721 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
6724 printk(MPT2SAS_INFO_FMT
"PCI error: slot reset callback!!\n",
6728 rc
= mpt2sas_base_map_resources(ioc
);
6730 return PCI_ERS_RESULT_DISCONNECT
;
6733 rc
= mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
6736 printk(MPT2SAS_WARN_FMT
"hard reset: %s\n", ioc
->name
,
6737 (rc
== 0) ? "success" : "failed");
6740 return PCI_ERS_RESULT_RECOVERED
;
6742 return PCI_ERS_RESULT_DISCONNECT
;
6746 * _scsih_pci_resume() - resume normal ops after PCI reset
6747 * @pdev: pointer to PCI device
6749 * Called when the error recovery driver tells us that its
6750 * OK to resume normal operation. Use completion to allow
6751 * halted scsi ops to resume.
6754 _scsih_pci_resume(struct pci_dev
*pdev
)
6756 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6757 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
6759 printk(MPT2SAS_INFO_FMT
"PCI error: resume callback!!\n", ioc
->name
);
6761 pci_cleanup_aer_uncorrect_error_status(pdev
);
6762 mpt2sas_base_start_watchdog(ioc
);
6763 scsi_unblock_requests(ioc
->shost
);
6767 * _scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
6768 * @pdev: pointer to PCI device
6770 static pci_ers_result_t
6771 _scsih_pci_mmio_enabled(struct pci_dev
*pdev
)
6773 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6774 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
6776 printk(MPT2SAS_INFO_FMT
"PCI error: mmio enabled callback!!\n",
6779 /* TODO - dump whatever for debugging purposes */
6781 /* Request a slot reset. */
6782 return PCI_ERS_RESULT_NEED_RESET
;
6785 static struct pci_error_handlers _scsih_err_handler
= {
6786 .error_detected
= _scsih_pci_error_detected
,
6787 .mmio_enabled
= _scsih_pci_mmio_enabled
,
6788 .slot_reset
= _scsih_pci_slot_reset
,
6789 .resume
= _scsih_pci_resume
,
6792 static struct pci_driver scsih_driver
= {
6793 .name
= MPT2SAS_DRIVER_NAME
,
6794 .id_table
= scsih_pci_table
,
6795 .probe
= _scsih_probe
,
6796 .remove
= __devexit_p(_scsih_remove
),
6797 .shutdown
= _scsih_shutdown
,
6798 .err_handler
= &_scsih_err_handler
,
6800 .suspend
= _scsih_suspend
,
6801 .resume
= _scsih_resume
,
6805 /* raid transport support */
6806 static struct raid_function_template mpt2sas_raid_functions
= {
6807 .cookie
= &scsih_driver_template
,
6808 .is_raid
= _scsih_is_raid
,
6809 .get_resync
= _scsih_get_resync
,
6810 .get_state
= _scsih_get_state
,
6814 * _scsih_init - main entry point for this driver.
6816 * Returns 0 success, anything else error.
6824 printk(KERN_INFO
"%s version %s loaded\n", MPT2SAS_DRIVER_NAME
,
6825 MPT2SAS_DRIVER_VERSION
);
6827 mpt2sas_transport_template
=
6828 sas_attach_transport(&mpt2sas_transport_functions
);
6829 if (!mpt2sas_transport_template
)
6831 /* raid transport support */
6832 mpt2sas_raid_template
= raid_class_attach(&mpt2sas_raid_functions
);
6833 if (!mpt2sas_raid_template
) {
6834 sas_release_transport(mpt2sas_transport_template
);
6838 mpt2sas_base_initialize_callback_handler();
6840 /* queuecommand callback hander */
6841 scsi_io_cb_idx
= mpt2sas_base_register_callback_handler(_scsih_io_done
);
6843 /* task managment callback handler */
6844 tm_cb_idx
= mpt2sas_base_register_callback_handler(_scsih_tm_done
);
6846 /* base internal commands callback handler */
6847 base_cb_idx
= mpt2sas_base_register_callback_handler(mpt2sas_base_done
);
6849 /* transport internal commands callback handler */
6850 transport_cb_idx
= mpt2sas_base_register_callback_handler(
6851 mpt2sas_transport_done
);
6853 /* scsih internal commands callback handler */
6854 scsih_cb_idx
= mpt2sas_base_register_callback_handler(_scsih_done
);
6856 /* configuration page API internal commands callback handler */
6857 config_cb_idx
= mpt2sas_base_register_callback_handler(
6858 mpt2sas_config_done
);
6860 /* ctl module callback handler */
6861 ctl_cb_idx
= mpt2sas_base_register_callback_handler(mpt2sas_ctl_done
);
6863 tm_tr_cb_idx
= mpt2sas_base_register_callback_handler(
6864 _scsih_tm_tr_complete
);
6865 tm_sas_control_cb_idx
= mpt2sas_base_register_callback_handler(
6866 _scsih_sas_control_complete
);
6870 error
= pci_register_driver(&scsih_driver
);
6872 /* raid transport support */
6873 raid_class_release(mpt2sas_raid_template
);
6874 sas_release_transport(mpt2sas_transport_template
);
6881 * _scsih_exit - exit point for this driver (when it is a module).
6883 * Returns 0 success, anything else error.
6888 printk(KERN_INFO
"mpt2sas version %s unloading\n",
6889 MPT2SAS_DRIVER_VERSION
);
6891 pci_unregister_driver(&scsih_driver
);
6895 mpt2sas_base_release_callback_handler(scsi_io_cb_idx
);
6896 mpt2sas_base_release_callback_handler(tm_cb_idx
);
6897 mpt2sas_base_release_callback_handler(base_cb_idx
);
6898 mpt2sas_base_release_callback_handler(transport_cb_idx
);
6899 mpt2sas_base_release_callback_handler(scsih_cb_idx
);
6900 mpt2sas_base_release_callback_handler(config_cb_idx
);
6901 mpt2sas_base_release_callback_handler(ctl_cb_idx
);
6903 mpt2sas_base_release_callback_handler(tm_tr_cb_idx
);
6904 mpt2sas_base_release_callback_handler(tm_sas_control_cb_idx
);
6906 /* raid transport support */
6907 raid_class_release(mpt2sas_raid_template
);
6908 sas_release_transport(mpt2sas_transport_template
);
6912 module_init(_scsih_init
);
6913 module_exit(_scsih_exit
);