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
},
227 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2308_1
,
228 PCI_ANY_ID
, PCI_ANY_ID
},
229 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2308_2
,
230 PCI_ANY_ID
, PCI_ANY_ID
},
231 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2308_3
,
232 PCI_ANY_ID
, PCI_ANY_ID
},
233 {0} /* Terminating entry */
235 MODULE_DEVICE_TABLE(pci
, scsih_pci_table
);
238 * _scsih_set_debug_level - global setting of ioc->logging_level.
240 * Note: The logging levels are defined in mpt2sas_debug.h.
243 _scsih_set_debug_level(const char *val
, struct kernel_param
*kp
)
245 int ret
= param_set_int(val
, kp
);
246 struct MPT2SAS_ADAPTER
*ioc
;
251 printk(KERN_INFO
"setting logging_level(0x%08x)\n", logging_level
);
252 list_for_each_entry(ioc
, &mpt2sas_ioc_list
, list
)
253 ioc
->logging_level
= logging_level
;
256 module_param_call(logging_level
, _scsih_set_debug_level
, param_get_int
,
257 &logging_level
, 0644);
260 * _scsih_srch_boot_sas_address - search based on sas_address
261 * @sas_address: sas address
262 * @boot_device: boot device object from bios page 2
264 * Returns 1 when there's a match, 0 means no match.
267 _scsih_srch_boot_sas_address(u64 sas_address
,
268 Mpi2BootDeviceSasWwid_t
*boot_device
)
270 return (sas_address
== le64_to_cpu(boot_device
->SASAddress
)) ? 1 : 0;
274 * _scsih_srch_boot_device_name - search based on device name
275 * @device_name: device name specified in INDENTIFY fram
276 * @boot_device: boot device object from bios page 2
278 * Returns 1 when there's a match, 0 means no match.
281 _scsih_srch_boot_device_name(u64 device_name
,
282 Mpi2BootDeviceDeviceName_t
*boot_device
)
284 return (device_name
== le64_to_cpu(boot_device
->DeviceName
)) ? 1 : 0;
288 * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot
289 * @enclosure_logical_id: enclosure logical id
290 * @slot_number: slot number
291 * @boot_device: boot device object from bios page 2
293 * Returns 1 when there's a match, 0 means no match.
296 _scsih_srch_boot_encl_slot(u64 enclosure_logical_id
, u16 slot_number
,
297 Mpi2BootDeviceEnclosureSlot_t
*boot_device
)
299 return (enclosure_logical_id
== le64_to_cpu(boot_device
->
300 EnclosureLogicalID
) && slot_number
== le16_to_cpu(boot_device
->
301 SlotNumber
)) ? 1 : 0;
305 * _scsih_is_boot_device - search for matching boot device.
306 * @sas_address: sas address
307 * @device_name: device name specified in INDENTIFY fram
308 * @enclosure_logical_id: enclosure logical id
309 * @slot_number: slot number
310 * @form: specifies boot device form
311 * @boot_device: boot device object from bios page 2
313 * Returns 1 when there's a match, 0 means no match.
316 _scsih_is_boot_device(u64 sas_address
, u64 device_name
,
317 u64 enclosure_logical_id
, u16 slot
, u8 form
,
318 Mpi2BiosPage2BootDevice_t
*boot_device
)
323 case MPI2_BIOSPAGE2_FORM_SAS_WWID
:
326 rc
= _scsih_srch_boot_sas_address(
327 sas_address
, &boot_device
->SasWwid
);
329 case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT
:
330 if (!enclosure_logical_id
)
332 rc
= _scsih_srch_boot_encl_slot(
333 enclosure_logical_id
,
334 slot
, &boot_device
->EnclosureSlot
);
336 case MPI2_BIOSPAGE2_FORM_DEVICE_NAME
:
339 rc
= _scsih_srch_boot_device_name(
340 device_name
, &boot_device
->DeviceName
);
342 case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED
:
350 * _scsih_get_sas_address - set the sas_address for given device handle
351 * @handle: device handle
352 * @sas_address: sas address
354 * Returns 0 success, non-zero when failure
357 _scsih_get_sas_address(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
,
360 Mpi2SasDevicePage0_t sas_device_pg0
;
361 Mpi2ConfigReply_t mpi_reply
;
364 if (handle
<= ioc
->sas_hba
.num_phys
) {
365 *sas_address
= ioc
->sas_hba
.sas_address
;
370 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
371 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
372 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
373 ioc
->name
, __FILE__
, __LINE__
, __func__
);
377 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
379 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
380 printk(MPT2SAS_ERR_FMT
"handle(0x%04x), ioc_status(0x%04x)"
381 "\nfailure at %s:%d/%s()!\n", ioc
->name
, handle
, ioc_status
,
382 __FILE__
, __LINE__
, __func__
);
386 *sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
391 * _scsih_determine_boot_device - determine boot device.
392 * @ioc: per adapter object
393 * @device: either sas_device or raid_device object
394 * @is_raid: [flag] 1 = raid object, 0 = sas object
396 * Determines whether this device should be first reported device to
397 * to scsi-ml or sas transport, this purpose is for persistant boot device.
398 * There are primary, alternate, and current entries in bios page 2. The order
399 * priority is primary, alternate, then current. This routine saves
400 * the corresponding device object and is_raid flag in the ioc object.
401 * The saved data to be used later in _scsih_probe_boot_devices().
404 _scsih_determine_boot_device(struct MPT2SAS_ADAPTER
*ioc
,
405 void *device
, u8 is_raid
)
407 struct _sas_device
*sas_device
;
408 struct _raid_device
*raid_device
;
411 u64 enclosure_logical_id
;
414 /* only process this function when driver loads */
415 if (!ioc
->wait_for_port_enable_to_complete
)
420 sas_address
= sas_device
->sas_address
;
421 device_name
= sas_device
->device_name
;
422 enclosure_logical_id
= sas_device
->enclosure_logical_id
;
423 slot
= sas_device
->slot
;
425 raid_device
= device
;
426 sas_address
= raid_device
->wwid
;
428 enclosure_logical_id
= 0;
432 if (!ioc
->req_boot_device
.device
) {
433 if (_scsih_is_boot_device(sas_address
, device_name
,
434 enclosure_logical_id
, slot
,
435 (ioc
->bios_pg2
.ReqBootDeviceForm
&
436 MPI2_BIOSPAGE2_FORM_MASK
),
437 &ioc
->bios_pg2
.RequestedBootDevice
)) {
438 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
439 "%s: req_boot_device(0x%016llx)\n",
441 (unsigned long long)sas_address
));
442 ioc
->req_boot_device
.device
= device
;
443 ioc
->req_boot_device
.is_raid
= is_raid
;
447 if (!ioc
->req_alt_boot_device
.device
) {
448 if (_scsih_is_boot_device(sas_address
, device_name
,
449 enclosure_logical_id
, slot
,
450 (ioc
->bios_pg2
.ReqAltBootDeviceForm
&
451 MPI2_BIOSPAGE2_FORM_MASK
),
452 &ioc
->bios_pg2
.RequestedAltBootDevice
)) {
453 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
454 "%s: req_alt_boot_device(0x%016llx)\n",
456 (unsigned long long)sas_address
));
457 ioc
->req_alt_boot_device
.device
= device
;
458 ioc
->req_alt_boot_device
.is_raid
= is_raid
;
462 if (!ioc
->current_boot_device
.device
) {
463 if (_scsih_is_boot_device(sas_address
, device_name
,
464 enclosure_logical_id
, slot
,
465 (ioc
->bios_pg2
.CurrentBootDeviceForm
&
466 MPI2_BIOSPAGE2_FORM_MASK
),
467 &ioc
->bios_pg2
.CurrentBootDevice
)) {
468 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
469 "%s: current_boot_device(0x%016llx)\n",
471 (unsigned long long)sas_address
));
472 ioc
->current_boot_device
.device
= device
;
473 ioc
->current_boot_device
.is_raid
= is_raid
;
479 * mpt2sas_scsih_sas_device_find_by_sas_address - sas device search
480 * @ioc: per adapter object
481 * @sas_address: sas address
482 * Context: Calling function should acquire ioc->sas_device_lock
484 * This searches for sas_device based on sas_address, then return sas_device
488 mpt2sas_scsih_sas_device_find_by_sas_address(struct MPT2SAS_ADAPTER
*ioc
,
491 struct _sas_device
*sas_device
;
493 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
)
494 if (sas_device
->sas_address
== sas_address
)
497 list_for_each_entry(sas_device
, &ioc
->sas_device_init_list
, list
)
498 if (sas_device
->sas_address
== sas_address
)
505 * _scsih_sas_device_find_by_handle - sas device search
506 * @ioc: per adapter object
507 * @handle: sas device handle (assigned by firmware)
508 * Context: Calling function should acquire ioc->sas_device_lock
510 * This searches for sas_device based on sas_address, then return sas_device
513 static struct _sas_device
*
514 _scsih_sas_device_find_by_handle(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
516 struct _sas_device
*sas_device
;
518 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
)
519 if (sas_device
->handle
== handle
)
522 list_for_each_entry(sas_device
, &ioc
->sas_device_init_list
, list
)
523 if (sas_device
->handle
== handle
)
530 * _scsih_sas_device_remove - remove sas_device from list.
531 * @ioc: per adapter object
532 * @sas_device: the sas_device object
533 * Context: This function will acquire ioc->sas_device_lock.
535 * Removing object and freeing associated memory from the ioc->sas_device_list.
538 _scsih_sas_device_remove(struct MPT2SAS_ADAPTER
*ioc
,
539 struct _sas_device
*sas_device
)
546 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
547 if (mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
548 sas_device
->sas_address
)) {
549 list_del(&sas_device
->list
);
552 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
556 * _scsih_sas_device_add - insert sas_device to the list.
557 * @ioc: per adapter object
558 * @sas_device: the sas_device object
559 * Context: This function will acquire ioc->sas_device_lock.
561 * Adding new object to the ioc->sas_device_list.
564 _scsih_sas_device_add(struct MPT2SAS_ADAPTER
*ioc
,
565 struct _sas_device
*sas_device
)
569 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: handle"
570 "(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
, __func__
,
571 sas_device
->handle
, (unsigned long long)sas_device
->sas_address
));
573 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
574 list_add_tail(&sas_device
->list
, &ioc
->sas_device_list
);
575 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
577 if (!mpt2sas_transport_port_add(ioc
, sas_device
->handle
,
578 sas_device
->sas_address_parent
))
579 _scsih_sas_device_remove(ioc
, sas_device
);
583 * _scsih_sas_device_init_add - insert sas_device to the list.
584 * @ioc: per adapter object
585 * @sas_device: the sas_device object
586 * Context: This function will acquire ioc->sas_device_lock.
588 * Adding new object at driver load time to the ioc->sas_device_init_list.
591 _scsih_sas_device_init_add(struct MPT2SAS_ADAPTER
*ioc
,
592 struct _sas_device
*sas_device
)
596 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: handle"
597 "(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
, __func__
,
598 sas_device
->handle
, (unsigned long long)sas_device
->sas_address
));
600 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
601 list_add_tail(&sas_device
->list
, &ioc
->sas_device_init_list
);
602 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
603 _scsih_determine_boot_device(ioc
, sas_device
, 0);
607 * _scsih_raid_device_find_by_id - raid device search
608 * @ioc: per adapter object
609 * @id: sas device target id
610 * @channel: sas device channel
611 * Context: Calling function should acquire ioc->raid_device_lock
613 * This searches for raid_device based on target id, then return raid_device
616 static struct _raid_device
*
617 _scsih_raid_device_find_by_id(struct MPT2SAS_ADAPTER
*ioc
, int id
, int channel
)
619 struct _raid_device
*raid_device
, *r
;
622 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
623 if (raid_device
->id
== id
&& raid_device
->channel
== channel
) {
634 * _scsih_raid_device_find_by_handle - raid device search
635 * @ioc: per adapter object
636 * @handle: sas device handle (assigned by firmware)
637 * Context: Calling function should acquire ioc->raid_device_lock
639 * This searches for raid_device based on handle, then return raid_device
642 static struct _raid_device
*
643 _scsih_raid_device_find_by_handle(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
645 struct _raid_device
*raid_device
, *r
;
648 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
649 if (raid_device
->handle
!= handle
)
660 * _scsih_raid_device_find_by_wwid - raid device search
661 * @ioc: per adapter object
662 * @handle: sas device handle (assigned by firmware)
663 * Context: Calling function should acquire ioc->raid_device_lock
665 * This searches for raid_device based on wwid, then return raid_device
668 static struct _raid_device
*
669 _scsih_raid_device_find_by_wwid(struct MPT2SAS_ADAPTER
*ioc
, u64 wwid
)
671 struct _raid_device
*raid_device
, *r
;
674 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
675 if (raid_device
->wwid
!= wwid
)
686 * _scsih_raid_device_add - add raid_device object
687 * @ioc: per adapter object
688 * @raid_device: raid_device object
690 * This is added to the raid_device_list link list.
693 _scsih_raid_device_add(struct MPT2SAS_ADAPTER
*ioc
,
694 struct _raid_device
*raid_device
)
698 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: handle"
699 "(0x%04x), wwid(0x%016llx)\n", ioc
->name
, __func__
,
700 raid_device
->handle
, (unsigned long long)raid_device
->wwid
));
702 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
703 list_add_tail(&raid_device
->list
, &ioc
->raid_device_list
);
704 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
708 * _scsih_raid_device_remove - delete raid_device object
709 * @ioc: per adapter object
710 * @raid_device: raid_device object
712 * This is removed from the raid_device_list link list.
715 _scsih_raid_device_remove(struct MPT2SAS_ADAPTER
*ioc
,
716 struct _raid_device
*raid_device
)
720 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
721 list_del(&raid_device
->list
);
722 memset(raid_device
, 0, sizeof(struct _raid_device
));
724 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
728 * mpt2sas_scsih_expander_find_by_handle - expander device search
729 * @ioc: per adapter object
730 * @handle: expander handle (assigned by firmware)
731 * Context: Calling function should acquire ioc->sas_device_lock
733 * This searches for expander device based on handle, then returns the
737 mpt2sas_scsih_expander_find_by_handle(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
739 struct _sas_node
*sas_expander
, *r
;
742 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
743 if (sas_expander
->handle
!= handle
)
753 * mpt2sas_scsih_expander_find_by_sas_address - expander device search
754 * @ioc: per adapter object
755 * @sas_address: sas address
756 * Context: Calling function should acquire ioc->sas_node_lock.
758 * This searches for expander device based on sas_address, then returns the
762 mpt2sas_scsih_expander_find_by_sas_address(struct MPT2SAS_ADAPTER
*ioc
,
765 struct _sas_node
*sas_expander
, *r
;
768 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
769 if (sas_expander
->sas_address
!= sas_address
)
779 * _scsih_expander_node_add - insert expander device to the list.
780 * @ioc: per adapter object
781 * @sas_expander: the sas_device object
782 * Context: This function will acquire ioc->sas_node_lock.
784 * Adding new object to the ioc->sas_expander_list.
789 _scsih_expander_node_add(struct MPT2SAS_ADAPTER
*ioc
,
790 struct _sas_node
*sas_expander
)
794 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
795 list_add_tail(&sas_expander
->list
, &ioc
->sas_expander_list
);
796 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
800 * _scsih_is_end_device - determines if device is an end device
801 * @device_info: bitfield providing information about the device.
804 * Returns 1 if end device.
807 _scsih_is_end_device(u32 device_info
)
809 if (device_info
& MPI2_SAS_DEVICE_INFO_END_DEVICE
&&
810 ((device_info
& MPI2_SAS_DEVICE_INFO_SSP_TARGET
) |
811 (device_info
& MPI2_SAS_DEVICE_INFO_STP_TARGET
) |
812 (device_info
& MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)))
819 * mptscsih_get_scsi_lookup - returns scmd entry
820 * @ioc: per adapter object
821 * @smid: system request message index
823 * Returns the smid stored scmd pointer.
825 static struct scsi_cmnd
*
826 _scsih_scsi_lookup_get(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
828 return ioc
->scsi_lookup
[smid
- 1].scmd
;
832 * _scsih_scsi_lookup_find_by_scmd - scmd lookup
833 * @ioc: per adapter object
834 * @smid: system request message index
835 * @scmd: pointer to scsi command object
836 * Context: This function will acquire ioc->scsi_lookup_lock.
838 * This will search for a scmd pointer in the scsi_lookup array,
839 * returning the revelent smid. A returned value of zero means invalid.
842 _scsih_scsi_lookup_find_by_scmd(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_cmnd
849 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
851 for (i
= 0; i
< ioc
->scsiio_depth
; i
++) {
852 if (ioc
->scsi_lookup
[i
].scmd
== scmd
) {
853 smid
= ioc
->scsi_lookup
[i
].smid
;
858 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
863 * _scsih_scsi_lookup_find_by_target - search for matching channel:id
864 * @ioc: per adapter object
867 * Context: This function will acquire ioc->scsi_lookup_lock.
869 * This will search for a matching channel:id in the scsi_lookup array,
870 * returning 1 if found.
873 _scsih_scsi_lookup_find_by_target(struct MPT2SAS_ADAPTER
*ioc
, int id
,
880 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
882 for (i
= 0 ; i
< ioc
->scsiio_depth
; i
++) {
883 if (ioc
->scsi_lookup
[i
].scmd
&&
884 (ioc
->scsi_lookup
[i
].scmd
->device
->id
== id
&&
885 ioc
->scsi_lookup
[i
].scmd
->device
->channel
== channel
)) {
891 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
896 * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun
897 * @ioc: per adapter object
901 * Context: This function will acquire ioc->scsi_lookup_lock.
903 * This will search for a matching channel:id:lun in the scsi_lookup array,
904 * returning 1 if found.
907 _scsih_scsi_lookup_find_by_lun(struct MPT2SAS_ADAPTER
*ioc
, int id
,
908 unsigned int lun
, int channel
)
914 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
916 for (i
= 0 ; i
< ioc
->scsiio_depth
; i
++) {
917 if (ioc
->scsi_lookup
[i
].scmd
&&
918 (ioc
->scsi_lookup
[i
].scmd
->device
->id
== id
&&
919 ioc
->scsi_lookup
[i
].scmd
->device
->channel
== channel
&&
920 ioc
->scsi_lookup
[i
].scmd
->device
->lun
== lun
)) {
926 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
931 * _scsih_get_chain_buffer_dma - obtain block of chains (dma address)
932 * @ioc: per adapter object
933 * @smid: system request message index
935 * Returns phys pointer to chain buffer.
938 _scsih_get_chain_buffer_dma(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
940 return ioc
->chain_dma
+ ((smid
- 1) * (ioc
->request_sz
*
941 ioc
->chains_needed_per_io
));
945 * _scsih_get_chain_buffer - obtain block of chains assigned to a mf request
946 * @ioc: per adapter object
947 * @smid: system request message index
949 * Returns virt pointer to chain buffer.
952 _scsih_get_chain_buffer(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
954 return (void *)(ioc
->chain
+ ((smid
- 1) * (ioc
->request_sz
*
955 ioc
->chains_needed_per_io
)));
959 * _scsih_build_scatter_gather - main sg creation routine
960 * @ioc: per adapter object
961 * @scmd: scsi command
962 * @smid: system request message index
965 * The main routine that builds scatter gather table from a given
966 * scsi request sent via the .queuecommand main handler.
968 * Returns 0 success, anything else error
971 _scsih_build_scatter_gather(struct MPT2SAS_ADAPTER
*ioc
,
972 struct scsi_cmnd
*scmd
, u16 smid
)
974 Mpi2SCSIIORequest_t
*mpi_request
;
975 dma_addr_t chain_dma
;
976 struct scatterlist
*sg_scmd
;
977 void *sg_local
, *chain
;
984 u32 sgl_flags_last_element
;
985 u32 sgl_flags_end_buffer
;
987 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
989 /* init scatter gather flags */
990 sgl_flags
= MPI2_SGE_FLAGS_SIMPLE_ELEMENT
;
991 if (scmd
->sc_data_direction
== DMA_TO_DEVICE
)
992 sgl_flags
|= MPI2_SGE_FLAGS_HOST_TO_IOC
;
993 sgl_flags_last_element
= (sgl_flags
| MPI2_SGE_FLAGS_LAST_ELEMENT
)
994 << MPI2_SGE_FLAGS_SHIFT
;
995 sgl_flags_end_buffer
= (sgl_flags
| MPI2_SGE_FLAGS_LAST_ELEMENT
|
996 MPI2_SGE_FLAGS_END_OF_BUFFER
| MPI2_SGE_FLAGS_END_OF_LIST
)
997 << MPI2_SGE_FLAGS_SHIFT
;
998 sgl_flags
= sgl_flags
<< MPI2_SGE_FLAGS_SHIFT
;
1000 sg_scmd
= scsi_sglist(scmd
);
1001 sges_left
= scsi_dma_map(scmd
);
1002 if (sges_left
< 0) {
1003 sdev_printk(KERN_ERR
, scmd
->device
, "pci_map_sg"
1004 " failed: request for %d bytes!\n", scsi_bufflen(scmd
));
1008 sg_local
= &mpi_request
->SGL
;
1009 sges_in_segment
= ioc
->max_sges_in_main_message
;
1010 if (sges_left
<= sges_in_segment
)
1011 goto fill_in_last_segment
;
1013 mpi_request
->ChainOffset
= (offsetof(Mpi2SCSIIORequest_t
, SGL
) +
1014 (sges_in_segment
* ioc
->sge_size
))/4;
1016 /* fill in main message segment when there is a chain following */
1017 while (sges_in_segment
) {
1018 if (sges_in_segment
== 1)
1019 ioc
->base_add_sg_single(sg_local
,
1020 sgl_flags_last_element
| sg_dma_len(sg_scmd
),
1021 sg_dma_address(sg_scmd
));
1023 ioc
->base_add_sg_single(sg_local
, sgl_flags
|
1024 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
1025 sg_scmd
= sg_next(sg_scmd
);
1026 sg_local
+= ioc
->sge_size
;
1031 /* initializing the chain flags and pointers */
1032 chain_flags
= MPI2_SGE_FLAGS_CHAIN_ELEMENT
<< MPI2_SGE_FLAGS_SHIFT
;
1033 chain
= _scsih_get_chain_buffer(ioc
, smid
);
1034 chain_dma
= _scsih_get_chain_buffer_dma(ioc
, smid
);
1036 sges_in_segment
= (sges_left
<=
1037 ioc
->max_sges_in_chain_message
) ? sges_left
:
1038 ioc
->max_sges_in_chain_message
;
1039 chain_offset
= (sges_left
== sges_in_segment
) ?
1040 0 : (sges_in_segment
* ioc
->sge_size
)/4;
1041 chain_length
= sges_in_segment
* ioc
->sge_size
;
1043 chain_offset
= chain_offset
<<
1044 MPI2_SGE_CHAIN_OFFSET_SHIFT
;
1045 chain_length
+= ioc
->sge_size
;
1047 ioc
->base_add_sg_single(sg_local
, chain_flags
| chain_offset
|
1048 chain_length
, chain_dma
);
1051 goto fill_in_last_segment
;
1053 /* fill in chain segments */
1054 while (sges_in_segment
) {
1055 if (sges_in_segment
== 1)
1056 ioc
->base_add_sg_single(sg_local
,
1057 sgl_flags_last_element
|
1058 sg_dma_len(sg_scmd
),
1059 sg_dma_address(sg_scmd
));
1061 ioc
->base_add_sg_single(sg_local
, sgl_flags
|
1062 sg_dma_len(sg_scmd
),
1063 sg_dma_address(sg_scmd
));
1064 sg_scmd
= sg_next(sg_scmd
);
1065 sg_local
+= ioc
->sge_size
;
1070 chain_dma
+= ioc
->request_sz
;
1071 chain
+= ioc
->request_sz
;
1075 fill_in_last_segment
:
1077 /* fill the last segment */
1080 ioc
->base_add_sg_single(sg_local
, sgl_flags_end_buffer
|
1081 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
1083 ioc
->base_add_sg_single(sg_local
, sgl_flags
|
1084 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
1085 sg_scmd
= sg_next(sg_scmd
);
1086 sg_local
+= ioc
->sge_size
;
1094 * _scsih_change_queue_depth - setting device queue depth
1095 * @sdev: scsi device struct
1096 * @qdepth: requested queue depth
1097 * @reason: calling context
1099 * Returns queue depth.
1102 _scsih_change_queue_depth(struct scsi_device
*sdev
, int qdepth
, int reason
)
1104 struct Scsi_Host
*shost
= sdev
->host
;
1107 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1108 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1109 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1110 struct _sas_device
*sas_device
;
1111 unsigned long flags
;
1113 if (reason
!= SCSI_QDEPTH_DEFAULT
)
1116 max_depth
= shost
->can_queue
;
1118 /* limit max device queue for SATA to 32 */
1119 sas_device_priv_data
= sdev
->hostdata
;
1120 if (!sas_device_priv_data
)
1122 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
1123 if (!sas_target_priv_data
)
1125 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
))
1127 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1128 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1129 sas_device_priv_data
->sas_target
->sas_address
);
1130 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1131 if (sas_device
&& sas_device
->device_info
&
1132 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1133 max_depth
= MPT2SAS_SATA_QUEUE_DEPTH
;
1137 if (!sdev
->tagged_supported
)
1139 if (qdepth
> max_depth
)
1141 tag_type
= (qdepth
== 1) ? 0 : MSG_SIMPLE_TAG
;
1142 scsi_adjust_queue_depth(sdev
, tag_type
, qdepth
);
1144 if (sdev
->inquiry_len
> 7)
1145 sdev_printk(KERN_INFO
, sdev
, "qdepth(%d), tagged(%d), "
1146 "simple(%d), ordered(%d), scsi_level(%d), cmd_que(%d)\n",
1147 sdev
->queue_depth
, sdev
->tagged_supported
, sdev
->simple_tags
,
1148 sdev
->ordered_tags
, sdev
->scsi_level
,
1149 (sdev
->inquiry
[7] & 2) >> 1);
1151 return sdev
->queue_depth
;
1155 * _scsih_change_queue_type - changing device queue tag type
1156 * @sdev: scsi device struct
1157 * @tag_type: requested tag type
1159 * Returns queue tag type.
1162 _scsih_change_queue_type(struct scsi_device
*sdev
, int tag_type
)
1164 if (sdev
->tagged_supported
) {
1165 scsi_set_tag_type(sdev
, tag_type
);
1167 scsi_activate_tcq(sdev
, sdev
->queue_depth
);
1169 scsi_deactivate_tcq(sdev
, sdev
->queue_depth
);
1177 * _scsih_target_alloc - target add routine
1178 * @starget: scsi target struct
1180 * Returns 0 if ok. Any other return is assumed to be an error and
1181 * the device is ignored.
1184 _scsih_target_alloc(struct scsi_target
*starget
)
1186 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
1187 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1188 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1189 struct _sas_device
*sas_device
;
1190 struct _raid_device
*raid_device
;
1191 unsigned long flags
;
1192 struct sas_rphy
*rphy
;
1194 sas_target_priv_data
= kzalloc(sizeof(struct scsi_target
), GFP_KERNEL
);
1195 if (!sas_target_priv_data
)
1198 starget
->hostdata
= sas_target_priv_data
;
1199 sas_target_priv_data
->starget
= starget
;
1200 sas_target_priv_data
->handle
= MPT2SAS_INVALID_DEVICE_HANDLE
;
1203 if (starget
->channel
== RAID_CHANNEL
) {
1204 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1205 raid_device
= _scsih_raid_device_find_by_id(ioc
, starget
->id
,
1208 sas_target_priv_data
->handle
= raid_device
->handle
;
1209 sas_target_priv_data
->sas_address
= raid_device
->wwid
;
1210 sas_target_priv_data
->flags
|= MPT_TARGET_FLAGS_VOLUME
;
1211 raid_device
->starget
= starget
;
1213 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1217 /* sas/sata devices */
1218 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1219 rphy
= dev_to_rphy(starget
->dev
.parent
);
1220 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1221 rphy
->identify
.sas_address
);
1224 sas_target_priv_data
->handle
= sas_device
->handle
;
1225 sas_target_priv_data
->sas_address
= sas_device
->sas_address
;
1226 sas_device
->starget
= starget
;
1227 sas_device
->id
= starget
->id
;
1228 sas_device
->channel
= starget
->channel
;
1229 if (sas_device
->hidden_raid_component
)
1230 sas_target_priv_data
->flags
|=
1231 MPT_TARGET_FLAGS_RAID_COMPONENT
;
1233 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1239 * _scsih_target_destroy - target destroy routine
1240 * @starget: scsi target struct
1245 _scsih_target_destroy(struct scsi_target
*starget
)
1247 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
1248 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1249 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1250 struct _sas_device
*sas_device
;
1251 struct _raid_device
*raid_device
;
1252 unsigned long flags
;
1253 struct sas_rphy
*rphy
;
1255 sas_target_priv_data
= starget
->hostdata
;
1256 if (!sas_target_priv_data
)
1259 if (starget
->channel
== RAID_CHANNEL
) {
1260 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1261 raid_device
= _scsih_raid_device_find_by_id(ioc
, starget
->id
,
1264 raid_device
->starget
= NULL
;
1265 raid_device
->sdev
= NULL
;
1267 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1271 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1272 rphy
= dev_to_rphy(starget
->dev
.parent
);
1273 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1274 rphy
->identify
.sas_address
);
1275 if (sas_device
&& (sas_device
->starget
== starget
) &&
1276 (sas_device
->id
== starget
->id
) &&
1277 (sas_device
->channel
== starget
->channel
))
1278 sas_device
->starget
= NULL
;
1280 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1283 kfree(sas_target_priv_data
);
1284 starget
->hostdata
= NULL
;
1288 * _scsih_slave_alloc - device add routine
1289 * @sdev: scsi device struct
1291 * Returns 0 if ok. Any other return is assumed to be an error and
1292 * the device is ignored.
1295 _scsih_slave_alloc(struct scsi_device
*sdev
)
1297 struct Scsi_Host
*shost
;
1298 struct MPT2SAS_ADAPTER
*ioc
;
1299 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1300 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1301 struct scsi_target
*starget
;
1302 struct _raid_device
*raid_device
;
1303 unsigned long flags
;
1305 sas_device_priv_data
= kzalloc(sizeof(struct scsi_device
), GFP_KERNEL
);
1306 if (!sas_device_priv_data
)
1309 sas_device_priv_data
->lun
= sdev
->lun
;
1310 sas_device_priv_data
->flags
= MPT_DEVICE_FLAGS_INIT
;
1312 starget
= scsi_target(sdev
);
1313 sas_target_priv_data
= starget
->hostdata
;
1314 sas_target_priv_data
->num_luns
++;
1315 sas_device_priv_data
->sas_target
= sas_target_priv_data
;
1316 sdev
->hostdata
= sas_device_priv_data
;
1317 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
))
1318 sdev
->no_uld_attach
= 1;
1320 shost
= dev_to_shost(&starget
->dev
);
1321 ioc
= shost_priv(shost
);
1322 if (starget
->channel
== RAID_CHANNEL
) {
1323 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1324 raid_device
= _scsih_raid_device_find_by_id(ioc
,
1325 starget
->id
, starget
->channel
);
1327 raid_device
->sdev
= sdev
; /* raid is single lun */
1328 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1335 * _scsih_slave_destroy - device destroy routine
1336 * @sdev: scsi device struct
1341 _scsih_slave_destroy(struct scsi_device
*sdev
)
1343 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1344 struct scsi_target
*starget
;
1346 if (!sdev
->hostdata
)
1349 starget
= scsi_target(sdev
);
1350 sas_target_priv_data
= starget
->hostdata
;
1351 sas_target_priv_data
->num_luns
--;
1352 kfree(sdev
->hostdata
);
1353 sdev
->hostdata
= NULL
;
1357 * _scsih_display_sata_capabilities - sata capabilities
1358 * @ioc: per adapter object
1359 * @sas_device: the sas_device object
1360 * @sdev: scsi device struct
1363 _scsih_display_sata_capabilities(struct MPT2SAS_ADAPTER
*ioc
,
1364 struct _sas_device
*sas_device
, struct scsi_device
*sdev
)
1366 Mpi2ConfigReply_t mpi_reply
;
1367 Mpi2SasDevicePage0_t sas_device_pg0
;
1372 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
1373 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, sas_device
->handle
))) {
1374 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1375 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1379 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
1380 MPI2_IOCSTATUS_MASK
;
1381 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
1382 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1383 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1387 flags
= le16_to_cpu(sas_device_pg0
.Flags
);
1388 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
1390 sdev_printk(KERN_INFO
, sdev
,
1391 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1392 "sw_preserve(%s)\n",
1393 (device_info
& MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE
) ? "y" : "n",
1394 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED
) ? "y" : "n",
1395 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY
) ? "y" :
1397 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED
) ? "y" : "n",
1398 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED
) ? "y" : "n",
1399 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE
) ? "y" : "n");
1403 * _scsih_is_raid - return boolean indicating device is raid volume
1404 * @dev the device struct object
1407 _scsih_is_raid(struct device
*dev
)
1409 struct scsi_device
*sdev
= to_scsi_device(dev
);
1411 return (sdev
->channel
== RAID_CHANNEL
) ? 1 : 0;
1415 * _scsih_get_resync - get raid volume resync percent complete
1416 * @dev the device struct object
1419 _scsih_get_resync(struct device
*dev
)
1421 struct scsi_device
*sdev
= to_scsi_device(dev
);
1422 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
1423 static struct _raid_device
*raid_device
;
1424 unsigned long flags
;
1425 Mpi2RaidVolPage0_t vol_pg0
;
1426 Mpi2ConfigReply_t mpi_reply
;
1427 u32 volume_status_flags
;
1428 u8 percent_complete
= 0;
1430 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1431 raid_device
= _scsih_raid_device_find_by_id(ioc
, sdev
->id
,
1433 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1438 if (mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, &vol_pg0
,
1439 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, raid_device
->handle
,
1440 sizeof(Mpi2RaidVolPage0_t
))) {
1441 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1442 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1446 volume_status_flags
= le32_to_cpu(vol_pg0
.VolumeStatusFlags
);
1447 if (volume_status_flags
& MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS
)
1448 percent_complete
= raid_device
->percent_complete
;
1450 raid_set_resync(mpt2sas_raid_template
, dev
, percent_complete
);
1454 * _scsih_get_state - get raid volume level
1455 * @dev the device struct object
1458 _scsih_get_state(struct device
*dev
)
1460 struct scsi_device
*sdev
= to_scsi_device(dev
);
1461 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
1462 static struct _raid_device
*raid_device
;
1463 unsigned long flags
;
1464 Mpi2RaidVolPage0_t vol_pg0
;
1465 Mpi2ConfigReply_t mpi_reply
;
1467 enum raid_state state
= RAID_STATE_UNKNOWN
;
1469 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1470 raid_device
= _scsih_raid_device_find_by_id(ioc
, sdev
->id
,
1472 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1477 if (mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, &vol_pg0
,
1478 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, raid_device
->handle
,
1479 sizeof(Mpi2RaidVolPage0_t
))) {
1480 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1481 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1485 volstate
= le32_to_cpu(vol_pg0
.VolumeStatusFlags
);
1486 if (volstate
& MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS
) {
1487 state
= RAID_STATE_RESYNCING
;
1491 switch (vol_pg0
.VolumeState
) {
1492 case MPI2_RAID_VOL_STATE_OPTIMAL
:
1493 case MPI2_RAID_VOL_STATE_ONLINE
:
1494 state
= RAID_STATE_ACTIVE
;
1496 case MPI2_RAID_VOL_STATE_DEGRADED
:
1497 state
= RAID_STATE_DEGRADED
;
1499 case MPI2_RAID_VOL_STATE_FAILED
:
1500 case MPI2_RAID_VOL_STATE_MISSING
:
1501 state
= RAID_STATE_OFFLINE
;
1505 raid_set_state(mpt2sas_raid_template
, dev
, state
);
1509 * _scsih_set_level - set raid level
1510 * @sdev: scsi device struct
1511 * @raid_device: raid_device object
1514 _scsih_set_level(struct scsi_device
*sdev
, struct _raid_device
*raid_device
)
1516 enum raid_level level
= RAID_LEVEL_UNKNOWN
;
1518 switch (raid_device
->volume_type
) {
1519 case MPI2_RAID_VOL_TYPE_RAID0
:
1520 level
= RAID_LEVEL_0
;
1522 case MPI2_RAID_VOL_TYPE_RAID10
:
1523 level
= RAID_LEVEL_10
;
1525 case MPI2_RAID_VOL_TYPE_RAID1E
:
1526 level
= RAID_LEVEL_1E
;
1528 case MPI2_RAID_VOL_TYPE_RAID1
:
1529 level
= RAID_LEVEL_1
;
1533 raid_set_level(mpt2sas_raid_template
, &sdev
->sdev_gendev
, level
);
1537 * _scsih_get_volume_capabilities - volume capabilities
1538 * @ioc: per adapter object
1539 * @sas_device: the raid_device object
1542 _scsih_get_volume_capabilities(struct MPT2SAS_ADAPTER
*ioc
,
1543 struct _raid_device
*raid_device
)
1545 Mpi2RaidVolPage0_t
*vol_pg0
;
1546 Mpi2RaidPhysDiskPage0_t pd_pg0
;
1547 Mpi2SasDevicePage0_t sas_device_pg0
;
1548 Mpi2ConfigReply_t mpi_reply
;
1552 if ((mpt2sas_config_get_number_pds(ioc
, raid_device
->handle
,
1553 &num_pds
)) || !num_pds
) {
1554 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1555 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1559 raid_device
->num_pds
= num_pds
;
1560 sz
= offsetof(Mpi2RaidVolPage0_t
, PhysDisk
) + (num_pds
*
1561 sizeof(Mpi2RaidVol0PhysDisk_t
));
1562 vol_pg0
= kzalloc(sz
, GFP_KERNEL
);
1564 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1565 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1569 if ((mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, vol_pg0
,
1570 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, raid_device
->handle
, sz
))) {
1571 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1572 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1577 raid_device
->volume_type
= vol_pg0
->VolumeType
;
1579 /* figure out what the underlying devices are by
1580 * obtaining the device_info bits for the 1st device
1582 if (!(mpt2sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
1583 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM
,
1584 vol_pg0
->PhysDisk
[0].PhysDiskNum
))) {
1585 if (!(mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
1586 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
1587 le16_to_cpu(pd_pg0
.DevHandle
)))) {
1588 raid_device
->device_info
=
1589 le32_to_cpu(sas_device_pg0
.DeviceInfo
);
1597 * _scsih_enable_tlr - setting TLR flags
1598 * @ioc: per adapter object
1599 * @sdev: scsi device struct
1601 * Enabling Transaction Layer Retries for tape devices when
1602 * vpd page 0x90 is present
1606 _scsih_enable_tlr(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_device
*sdev
)
1609 if (sdev
->type
!= TYPE_TAPE
)
1612 if (!(ioc
->facts
.IOCCapabilities
& MPI2_IOCFACTS_CAPABILITY_TLR
))
1615 sas_enable_tlr(sdev
);
1616 sdev_printk(KERN_INFO
, sdev
, "TLR %s\n",
1617 sas_is_tlr_enabled(sdev
) ? "Enabled" : "Disabled");
1623 * _scsih_slave_configure - device configure routine.
1624 * @sdev: scsi device struct
1626 * Returns 0 if ok. Any other return is assumed to be an error and
1627 * the device is ignored.
1630 _scsih_slave_configure(struct scsi_device
*sdev
)
1632 struct Scsi_Host
*shost
= sdev
->host
;
1633 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1634 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1635 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1636 struct _sas_device
*sas_device
;
1637 struct _raid_device
*raid_device
;
1638 unsigned long flags
;
1645 sas_device_priv_data
= sdev
->hostdata
;
1646 sas_device_priv_data
->configured_lun
= 1;
1647 sas_device_priv_data
->flags
&= ~MPT_DEVICE_FLAGS_INIT
;
1648 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
1650 /* raid volume handling */
1651 if (sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
1653 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1654 raid_device
= _scsih_raid_device_find_by_handle(ioc
,
1655 sas_target_priv_data
->handle
);
1656 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1658 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1659 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1663 _scsih_get_volume_capabilities(ioc
, raid_device
);
1665 /* RAID Queue Depth Support
1666 * IS volume = underlying qdepth of drive type, either
1667 * MPT2SAS_SAS_QUEUE_DEPTH or MPT2SAS_SATA_QUEUE_DEPTH
1668 * IM/IME/R10 = 128 (MPT2SAS_RAID_QUEUE_DEPTH)
1670 if (raid_device
->device_info
&
1671 MPI2_SAS_DEVICE_INFO_SSP_TARGET
) {
1672 qdepth
= MPT2SAS_SAS_QUEUE_DEPTH
;
1675 qdepth
= MPT2SAS_SATA_QUEUE_DEPTH
;
1676 if (raid_device
->device_info
&
1677 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1683 switch (raid_device
->volume_type
) {
1684 case MPI2_RAID_VOL_TYPE_RAID0
:
1687 case MPI2_RAID_VOL_TYPE_RAID1E
:
1688 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
1689 if (ioc
->manu_pg10
.OEMIdentifier
&&
1690 (ioc
->manu_pg10
.GenericFlags0
&
1691 MFG10_GF0_R10_DISPLAY
) &&
1692 !(raid_device
->num_pds
% 2))
1697 case MPI2_RAID_VOL_TYPE_RAID1
:
1698 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
1701 case MPI2_RAID_VOL_TYPE_RAID10
:
1702 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
1705 case MPI2_RAID_VOL_TYPE_UNKNOWN
:
1707 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
1712 sdev_printk(KERN_INFO
, sdev
, "%s: "
1713 "handle(0x%04x), wwid(0x%016llx), pd_count(%d), type(%s)\n",
1714 r_level
, raid_device
->handle
,
1715 (unsigned long long)raid_device
->wwid
,
1716 raid_device
->num_pds
, ds
);
1717 _scsih_change_queue_depth(sdev
, qdepth
, SCSI_QDEPTH_DEFAULT
);
1718 /* raid transport support */
1719 _scsih_set_level(sdev
, raid_device
);
1723 /* non-raid handling */
1724 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1725 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1726 sas_device_priv_data
->sas_target
->sas_address
);
1727 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1729 if (sas_target_priv_data
->flags
&
1730 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
1731 mpt2sas_config_get_volume_handle(ioc
,
1732 sas_device
->handle
, &sas_device
->volume_handle
);
1733 mpt2sas_config_get_volume_wwid(ioc
,
1734 sas_device
->volume_handle
,
1735 &sas_device
->volume_wwid
);
1737 if (sas_device
->device_info
& MPI2_SAS_DEVICE_INFO_SSP_TARGET
) {
1738 qdepth
= MPT2SAS_SAS_QUEUE_DEPTH
;
1742 qdepth
= MPT2SAS_SATA_QUEUE_DEPTH
;
1743 if (sas_device
->device_info
&
1744 MPI2_SAS_DEVICE_INFO_STP_TARGET
)
1746 else if (sas_device
->device_info
&
1747 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1751 sdev_printk(KERN_INFO
, sdev
, "%s: handle(0x%04x), "
1752 "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n",
1753 ds
, sas_device
->handle
,
1754 (unsigned long long)sas_device
->sas_address
,
1756 (unsigned long long)sas_device
->device_name
);
1757 sdev_printk(KERN_INFO
, sdev
, "%s: "
1758 "enclosure_logical_id(0x%016llx), slot(%d)\n", ds
,
1759 (unsigned long long) sas_device
->enclosure_logical_id
,
1763 _scsih_display_sata_capabilities(ioc
, sas_device
, sdev
);
1766 _scsih_change_queue_depth(sdev
, qdepth
, SCSI_QDEPTH_DEFAULT
);
1769 sas_read_port_mode_page(sdev
);
1770 _scsih_enable_tlr(ioc
, sdev
);
1776 * _scsih_bios_param - fetch head, sector, cylinder info for a disk
1777 * @sdev: scsi device struct
1778 * @bdev: pointer to block device context
1779 * @capacity: device size (in 512 byte sectors)
1780 * @params: three element array to place output:
1781 * params[0] number of heads (max 255)
1782 * params[1] number of sectors (max 63)
1783 * params[2] number of cylinders
1788 _scsih_bios_param(struct scsi_device
*sdev
, struct block_device
*bdev
,
1789 sector_t capacity
, int params
[])
1799 dummy
= heads
* sectors
;
1800 cylinders
= capacity
;
1801 sector_div(cylinders
, dummy
);
1804 * Handle extended translation size for logical drives
1807 if ((ulong
)capacity
>= 0x200000) {
1810 dummy
= heads
* sectors
;
1811 cylinders
= capacity
;
1812 sector_div(cylinders
, dummy
);
1817 params
[1] = sectors
;
1818 params
[2] = cylinders
;
1824 * _scsih_response_code - translation of device response code
1825 * @ioc: per adapter object
1826 * @response_code: response code returned by the device
1831 _scsih_response_code(struct MPT2SAS_ADAPTER
*ioc
, u8 response_code
)
1835 switch (response_code
) {
1836 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE
:
1837 desc
= "task management request completed";
1839 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
:
1840 desc
= "invalid frame";
1842 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED
:
1843 desc
= "task management request not supported";
1845 case MPI2_SCSITASKMGMT_RSP_TM_FAILED
:
1846 desc
= "task management request failed";
1848 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
:
1849 desc
= "task management request succeeded";
1851 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN
:
1852 desc
= "invalid lun";
1855 desc
= "overlapped tag attempted";
1857 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
:
1858 desc
= "task queued, however not sent to target";
1864 printk(MPT2SAS_WARN_FMT
"response_code(0x%01x): %s\n",
1865 ioc
->name
, response_code
, desc
);
1869 * _scsih_tm_done - tm completion routine
1870 * @ioc: per adapter object
1871 * @smid: system request message index
1872 * @msix_index: MSIX table index supplied by the OS
1873 * @reply: reply message frame(lower 32bit addr)
1876 * The callback handler when using scsih_issue_tm.
1878 * Return 1 meaning mf should be freed from _base_interrupt
1879 * 0 means the mf is freed from this function.
1882 _scsih_tm_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
1884 MPI2DefaultReply_t
*mpi_reply
;
1886 if (ioc
->tm_cmds
.status
== MPT2_CMD_NOT_USED
)
1888 if (ioc
->tm_cmds
.smid
!= smid
)
1890 ioc
->tm_cmds
.status
|= MPT2_CMD_COMPLETE
;
1891 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
1893 memcpy(ioc
->tm_cmds
.reply
, mpi_reply
, mpi_reply
->MsgLength
*4);
1894 ioc
->tm_cmds
.status
|= MPT2_CMD_REPLY_VALID
;
1896 ioc
->tm_cmds
.status
&= ~MPT2_CMD_PENDING
;
1897 complete(&ioc
->tm_cmds
.done
);
1902 * mpt2sas_scsih_set_tm_flag - set per target tm_busy
1903 * @ioc: per adapter object
1904 * @handle: device handle
1906 * During taskmangement request, we need to freeze the device queue.
1909 mpt2sas_scsih_set_tm_flag(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
1911 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1912 struct scsi_device
*sdev
;
1915 shost_for_each_device(sdev
, ioc
->shost
) {
1918 sas_device_priv_data
= sdev
->hostdata
;
1919 if (!sas_device_priv_data
)
1921 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
1922 sas_device_priv_data
->sas_target
->tm_busy
= 1;
1924 ioc
->ignore_loginfos
= 1;
1930 * mpt2sas_scsih_clear_tm_flag - clear per target tm_busy
1931 * @ioc: per adapter object
1932 * @handle: device handle
1934 * During taskmangement request, we need to freeze the device queue.
1937 mpt2sas_scsih_clear_tm_flag(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
1939 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1940 struct scsi_device
*sdev
;
1943 shost_for_each_device(sdev
, ioc
->shost
) {
1946 sas_device_priv_data
= sdev
->hostdata
;
1947 if (!sas_device_priv_data
)
1949 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
1950 sas_device_priv_data
->sas_target
->tm_busy
= 0;
1952 ioc
->ignore_loginfos
= 0;
1959 * mpt2sas_scsih_issue_tm - main routine for sending tm requests
1960 * @ioc: per adapter struct
1961 * @device_handle: device handle
1962 * @channel: the channel assigned by the OS
1963 * @id: the id assigned by the OS
1965 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
1966 * @smid_task: smid assigned to the task
1967 * @timeout: timeout in seconds
1970 * A generic API for sending task management requests to firmware.
1972 * The callback index is set inside `ioc->tm_cb_idx`.
1974 * Return SUCCESS or FAILED.
1977 mpt2sas_scsih_issue_tm(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
, uint channel
,
1978 uint id
, uint lun
, u8 type
, u16 smid_task
, ulong timeout
,
1979 struct scsi_cmnd
*scmd
)
1981 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
1982 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
1985 unsigned long timeleft
;
1986 struct scsi_cmnd
*scmd_lookup
;
1989 mutex_lock(&ioc
->tm_cmds
.mutex
);
1990 if (ioc
->tm_cmds
.status
!= MPT2_CMD_NOT_USED
) {
1991 printk(MPT2SAS_INFO_FMT
"%s: tm_cmd busy!!!\n",
1992 __func__
, ioc
->name
);
1997 if (ioc
->shost_recovery
|| ioc
->remove_host
) {
1998 printk(MPT2SAS_INFO_FMT
"%s: host reset in progress!\n",
1999 __func__
, ioc
->name
);
2004 ioc_state
= mpt2sas_base_get_iocstate(ioc
, 0);
2005 if (ioc_state
& MPI2_DOORBELL_USED
) {
2006 dhsprintk(ioc
, printk(MPT2SAS_INFO_FMT
"unexpected doorbell "
2007 "active!\n", ioc
->name
));
2008 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2014 if ((ioc_state
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_FAULT
) {
2015 mpt2sas_base_fault_info(ioc
, ioc_state
&
2016 MPI2_DOORBELL_DATA_MASK
);
2017 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2023 smid
= mpt2sas_base_get_smid_hpr(ioc
, ioc
->tm_cb_idx
);
2025 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
2026 ioc
->name
, __func__
);
2031 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"sending tm: handle(0x%04x),"
2032 " task_type(0x%02x), smid(%d)\n", ioc
->name
, handle
, type
,
2034 ioc
->tm_cmds
.status
= MPT2_CMD_PENDING
;
2035 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
2036 ioc
->tm_cmds
.smid
= smid
;
2037 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
2038 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
2039 mpi_request
->DevHandle
= cpu_to_le16(handle
);
2040 mpi_request
->TaskType
= type
;
2041 mpi_request
->TaskMID
= cpu_to_le16(smid_task
);
2042 int_to_scsilun(lun
, (struct scsi_lun
*)mpi_request
->LUN
);
2043 mpt2sas_scsih_set_tm_flag(ioc
, handle
);
2044 init_completion(&ioc
->tm_cmds
.done
);
2045 mpt2sas_base_put_smid_hi_priority(ioc
, smid
);
2046 timeleft
= wait_for_completion_timeout(&ioc
->tm_cmds
.done
, timeout
*HZ
);
2047 if (!(ioc
->tm_cmds
.status
& MPT2_CMD_COMPLETE
)) {
2048 printk(MPT2SAS_ERR_FMT
"%s: timeout\n",
2049 ioc
->name
, __func__
);
2050 _debug_dump_mf(mpi_request
,
2051 sizeof(Mpi2SCSITaskManagementRequest_t
)/4);
2052 if (!(ioc
->tm_cmds
.status
& MPT2_CMD_RESET
)) {
2053 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2056 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
2057 mpt2sas_scsih_clear_tm_flag(ioc
, handle
);
2062 if (ioc
->tm_cmds
.status
& MPT2_CMD_REPLY_VALID
) {
2063 mpi_reply
= ioc
->tm_cmds
.reply
;
2064 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"complete tm: "
2065 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
2066 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
2067 le32_to_cpu(mpi_reply
->IOCLogInfo
),
2068 le32_to_cpu(mpi_reply
->TerminationCount
)));
2069 if (ioc
->logging_level
& MPT_DEBUG_TM
) {
2070 _scsih_response_code(ioc
, mpi_reply
->ResponseCode
);
2071 if (mpi_reply
->IOCStatus
)
2072 _debug_dump_mf(mpi_request
,
2073 sizeof(Mpi2SCSITaskManagementRequest_t
)/4);
2078 * Check to see the commands were terminated.
2079 * This is only needed for eh callbacks, hence the scmd check.
2083 goto bypass_sanity_checks
;
2085 case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
:
2086 scmd_lookup
= _scsih_scsi_lookup_get(ioc
, smid_task
);
2087 if (scmd_lookup
&& (scmd_lookup
->serial_number
==
2088 scmd
->serial_number
))
2094 case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
:
2095 if (_scsih_scsi_lookup_find_by_target(ioc
, id
, channel
))
2101 case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET
:
2102 if (_scsih_scsi_lookup_find_by_lun(ioc
, id
, lun
, channel
))
2109 bypass_sanity_checks
:
2111 mpt2sas_scsih_clear_tm_flag(ioc
, handle
);
2112 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
2113 mutex_unlock(&ioc
->tm_cmds
.mutex
);
2118 mutex_unlock(&ioc
->tm_cmds
.mutex
);
2123 * _scsih_abort - eh threads main abort routine
2124 * @sdev: scsi device struct
2126 * Returns SUCCESS if command aborted else FAILED
2129 _scsih_abort(struct scsi_cmnd
*scmd
)
2131 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2132 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2137 printk(MPT2SAS_INFO_FMT
"attempting task abort! scmd(%p)\n",
2139 scsi_print_command(scmd
);
2141 sas_device_priv_data
= scmd
->device
->hostdata
;
2142 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2143 printk(MPT2SAS_INFO_FMT
"device been deleted! scmd(%p)\n",
2145 scmd
->result
= DID_NO_CONNECT
<< 16;
2146 scmd
->scsi_done(scmd
);
2151 /* search for the command */
2152 smid
= _scsih_scsi_lookup_find_by_scmd(ioc
, scmd
);
2154 scmd
->result
= DID_RESET
<< 16;
2159 /* for hidden raid components and volumes this is not supported */
2160 if (sas_device_priv_data
->sas_target
->flags
&
2161 MPT_TARGET_FLAGS_RAID_COMPONENT
||
2162 sas_device_priv_data
->sas_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
2163 scmd
->result
= DID_RESET
<< 16;
2168 mpt2sas_halt_firmware(ioc
);
2170 handle
= sas_device_priv_data
->sas_target
->handle
;
2171 r
= mpt2sas_scsih_issue_tm(ioc
, handle
, scmd
->device
->channel
,
2172 scmd
->device
->id
, scmd
->device
->lun
,
2173 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
, smid
, 30, scmd
);
2176 printk(MPT2SAS_INFO_FMT
"task abort: %s scmd(%p)\n",
2177 ioc
->name
, ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2182 * _scsih_dev_reset - eh threads main device reset routine
2183 * @sdev: scsi device struct
2185 * Returns SUCCESS if command aborted else FAILED
2188 _scsih_dev_reset(struct scsi_cmnd
*scmd
)
2190 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2191 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2192 struct _sas_device
*sas_device
;
2193 unsigned long flags
;
2197 printk(MPT2SAS_INFO_FMT
"attempting device reset! scmd(%p)\n",
2199 scsi_print_command(scmd
);
2201 sas_device_priv_data
= scmd
->device
->hostdata
;
2202 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2203 printk(MPT2SAS_INFO_FMT
"device been deleted! scmd(%p)\n",
2205 scmd
->result
= DID_NO_CONNECT
<< 16;
2206 scmd
->scsi_done(scmd
);
2211 /* for hidden raid components obtain the volume_handle */
2213 if (sas_device_priv_data
->sas_target
->flags
&
2214 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2215 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2216 sas_device
= _scsih_sas_device_find_by_handle(ioc
,
2217 sas_device_priv_data
->sas_target
->handle
);
2219 handle
= sas_device
->volume_handle
;
2220 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2222 handle
= sas_device_priv_data
->sas_target
->handle
;
2225 scmd
->result
= DID_RESET
<< 16;
2230 r
= mpt2sas_scsih_issue_tm(ioc
, handle
, scmd
->device
->channel
,
2231 scmd
->device
->id
, scmd
->device
->lun
,
2232 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET
, 0, 30, scmd
);
2235 printk(MPT2SAS_INFO_FMT
"device reset: %s scmd(%p)\n",
2236 ioc
->name
, ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2241 * _scsih_target_reset - eh threads main target reset routine
2242 * @sdev: scsi device struct
2244 * Returns SUCCESS if command aborted else FAILED
2247 _scsih_target_reset(struct scsi_cmnd
*scmd
)
2249 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2250 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2251 struct _sas_device
*sas_device
;
2252 unsigned long flags
;
2256 printk(MPT2SAS_INFO_FMT
"attempting target reset! scmd(%p)\n",
2258 scsi_print_command(scmd
);
2260 sas_device_priv_data
= scmd
->device
->hostdata
;
2261 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2262 printk(MPT2SAS_INFO_FMT
"target been deleted! scmd(%p)\n",
2264 scmd
->result
= DID_NO_CONNECT
<< 16;
2265 scmd
->scsi_done(scmd
);
2270 /* for hidden raid components obtain the volume_handle */
2272 if (sas_device_priv_data
->sas_target
->flags
&
2273 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2274 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2275 sas_device
= _scsih_sas_device_find_by_handle(ioc
,
2276 sas_device_priv_data
->sas_target
->handle
);
2278 handle
= sas_device
->volume_handle
;
2279 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2281 handle
= sas_device_priv_data
->sas_target
->handle
;
2284 scmd
->result
= DID_RESET
<< 16;
2289 r
= mpt2sas_scsih_issue_tm(ioc
, handle
, scmd
->device
->channel
,
2290 scmd
->device
->id
, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
, 0,
2294 printk(MPT2SAS_INFO_FMT
"target reset: %s scmd(%p)\n",
2295 ioc
->name
, ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2300 * _scsih_host_reset - eh threads main host reset routine
2301 * @sdev: scsi device struct
2303 * Returns SUCCESS if command aborted else FAILED
2306 _scsih_host_reset(struct scsi_cmnd
*scmd
)
2308 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2311 printk(MPT2SAS_INFO_FMT
"attempting host reset! scmd(%p)\n",
2313 scsi_print_command(scmd
);
2315 retval
= mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2317 r
= (retval
< 0) ? FAILED
: SUCCESS
;
2318 printk(MPT2SAS_INFO_FMT
"host reset: %s scmd(%p)\n",
2319 ioc
->name
, ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2325 * _scsih_fw_event_add - insert and queue up fw_event
2326 * @ioc: per adapter object
2327 * @fw_event: object describing the event
2328 * Context: This function will acquire ioc->fw_event_lock.
2330 * This adds the firmware event object into link list, then queues it up to
2331 * be processed from user context.
2336 _scsih_fw_event_add(struct MPT2SAS_ADAPTER
*ioc
, struct fw_event_work
*fw_event
)
2338 unsigned long flags
;
2340 if (ioc
->firmware_event_thread
== NULL
)
2343 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2344 list_add_tail(&fw_event
->list
, &ioc
->fw_event_list
);
2345 INIT_DELAYED_WORK(&fw_event
->delayed_work
, _firmware_event_work
);
2346 queue_delayed_work(ioc
->firmware_event_thread
,
2347 &fw_event
->delayed_work
, 0);
2348 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2352 * _scsih_fw_event_free - delete fw_event
2353 * @ioc: per adapter object
2354 * @fw_event: object describing the event
2355 * Context: This function will acquire ioc->fw_event_lock.
2357 * This removes firmware event object from link list, frees associated memory.
2362 _scsih_fw_event_free(struct MPT2SAS_ADAPTER
*ioc
, struct fw_event_work
2365 unsigned long flags
;
2367 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2368 list_del(&fw_event
->list
);
2369 kfree(fw_event
->event_data
);
2371 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2376 * _scsih_queue_rescan - queue a topology rescan from user context
2377 * @ioc: per adapter object
2382 _scsih_queue_rescan(struct MPT2SAS_ADAPTER
*ioc
)
2384 struct fw_event_work
*fw_event
;
2386 if (ioc
->wait_for_port_enable_to_complete
)
2388 fw_event
= kzalloc(sizeof(struct fw_event_work
), GFP_ATOMIC
);
2391 fw_event
->event
= MPT2SAS_RESCAN_AFTER_HOST_RESET
;
2392 fw_event
->ioc
= ioc
;
2393 _scsih_fw_event_add(ioc
, fw_event
);
2397 * _scsih_fw_event_cleanup_queue - cleanup event queue
2398 * @ioc: per adapter object
2400 * Walk the firmware event queue, either killing timers, or waiting
2401 * for outstanding events to complete
2406 _scsih_fw_event_cleanup_queue(struct MPT2SAS_ADAPTER
*ioc
)
2408 struct fw_event_work
*fw_event
, *next
;
2410 if (list_empty(&ioc
->fw_event_list
) ||
2411 !ioc
->firmware_event_thread
|| in_interrupt())
2414 list_for_each_entry_safe(fw_event
, next
, &ioc
->fw_event_list
, list
) {
2415 if (cancel_delayed_work(&fw_event
->delayed_work
)) {
2416 _scsih_fw_event_free(ioc
, fw_event
);
2419 fw_event
->cancel_pending_work
= 1;
2424 * _scsih_ublock_io_device - set the device state to SDEV_RUNNING
2425 * @ioc: per adapter object
2426 * @handle: device handle
2428 * During device pull we need to appropiately set the sdev state.
2431 _scsih_ublock_io_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
2433 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2434 struct scsi_device
*sdev
;
2436 shost_for_each_device(sdev
, ioc
->shost
) {
2437 sas_device_priv_data
= sdev
->hostdata
;
2438 if (!sas_device_priv_data
)
2440 if (!sas_device_priv_data
->block
)
2442 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2443 dewtprintk(ioc
, sdev_printk(KERN_INFO
, sdev
,
2444 MPT2SAS_INFO_FMT
"SDEV_RUNNING: "
2445 "handle(0x%04x)\n", ioc
->name
, handle
));
2446 sas_device_priv_data
->block
= 0;
2447 scsi_internal_device_unblock(sdev
);
2453 * _scsih_block_io_device - set the device state to SDEV_BLOCK
2454 * @ioc: per adapter object
2455 * @handle: device handle
2457 * During device pull we need to appropiately set the sdev state.
2460 _scsih_block_io_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
2462 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2463 struct scsi_device
*sdev
;
2465 shost_for_each_device(sdev
, ioc
->shost
) {
2466 sas_device_priv_data
= sdev
->hostdata
;
2467 if (!sas_device_priv_data
)
2469 if (sas_device_priv_data
->block
)
2471 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2472 dewtprintk(ioc
, sdev_printk(KERN_INFO
, sdev
,
2473 MPT2SAS_INFO_FMT
"SDEV_BLOCK: "
2474 "handle(0x%04x)\n", ioc
->name
, handle
));
2475 sas_device_priv_data
->block
= 1;
2476 scsi_internal_device_block(sdev
);
2482 * _scsih_block_io_to_children_attached_to_ex
2483 * @ioc: per adapter object
2484 * @sas_expander: the sas_device object
2486 * This routine set sdev state to SDEV_BLOCK for all devices
2487 * attached to this expander. This function called when expander is
2491 _scsih_block_io_to_children_attached_to_ex(struct MPT2SAS_ADAPTER
*ioc
,
2492 struct _sas_node
*sas_expander
)
2494 struct _sas_port
*mpt2sas_port
;
2495 struct _sas_device
*sas_device
;
2496 struct _sas_node
*expander_sibling
;
2497 unsigned long flags
;
2502 list_for_each_entry(mpt2sas_port
,
2503 &sas_expander
->sas_port_list
, port_list
) {
2504 if (mpt2sas_port
->remote_identify
.device_type
==
2506 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2508 mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
2509 mpt2sas_port
->remote_identify
.sas_address
);
2510 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2513 _scsih_block_io_device(ioc
, sas_device
->handle
);
2517 list_for_each_entry(mpt2sas_port
,
2518 &sas_expander
->sas_port_list
, port_list
) {
2520 if (mpt2sas_port
->remote_identify
.device_type
==
2521 MPI2_SAS_DEVICE_INFO_EDGE_EXPANDER
||
2522 mpt2sas_port
->remote_identify
.device_type
==
2523 MPI2_SAS_DEVICE_INFO_FANOUT_EXPANDER
) {
2525 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
2527 mpt2sas_scsih_expander_find_by_sas_address(
2528 ioc
, mpt2sas_port
->remote_identify
.sas_address
);
2529 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
2530 _scsih_block_io_to_children_attached_to_ex(ioc
,
2537 * _scsih_block_io_to_children_attached_directly
2538 * @ioc: per adapter object
2539 * @event_data: topology change event data
2541 * This routine set sdev state to SDEV_BLOCK for all devices
2542 * direct attached during device pull.
2545 _scsih_block_io_to_children_attached_directly(struct MPT2SAS_ADAPTER
*ioc
,
2546 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
2553 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
2554 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
2557 phy_number
= event_data
->StartPhyNum
+ i
;
2558 reason_code
= event_data
->PHY
[i
].PhyStatus
&
2559 MPI2_EVENT_SAS_TOPO_RC_MASK
;
2560 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
)
2561 _scsih_block_io_device(ioc
, handle
);
2566 * _scsih_tm_tr_send - send task management request
2567 * @ioc: per adapter object
2568 * @handle: device handle
2569 * Context: interrupt time.
2571 * This code is to initiate the device removal handshake protocal
2572 * with controller firmware. This function will issue target reset
2573 * using high priority request queue. It will send a sas iounit
2574 * controll request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
2576 * This is designed to send muliple task management request at the same
2577 * time to the fifo. If the fifo is full, we will append the request,
2578 * and process it in a future completion.
2581 _scsih_tm_tr_send(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
2583 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
2585 struct _sas_device
*sas_device
;
2586 unsigned long flags
;
2587 struct _tr_list
*delayed_tr
;
2589 if (ioc
->shost_recovery
|| ioc
->remove_host
) {
2590 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host reset in "
2591 "progress!\n", __func__
, ioc
->name
));
2595 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2596 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
2597 if (sas_device
&& sas_device
->hidden_raid_component
) {
2598 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2601 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2603 smid
= mpt2sas_base_get_smid_hpr(ioc
, ioc
->tm_tr_cb_idx
);
2605 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
2608 INIT_LIST_HEAD(&delayed_tr
->list
);
2609 delayed_tr
->handle
= handle
;
2610 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_list
);
2611 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
2612 "DELAYED:tr:handle(0x%04x), (open)\n",
2613 ioc
->name
, handle
));
2617 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"tr_send:handle(0x%04x), "
2618 "(open), smid(%d), cb(%d)\n", ioc
->name
, handle
, smid
,
2619 ioc
->tm_tr_cb_idx
));
2620 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
2621 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
2622 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
2623 mpi_request
->DevHandle
= cpu_to_le16(handle
);
2624 mpi_request
->TaskType
= MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
;
2625 mpt2sas_base_put_smid_hi_priority(ioc
, smid
);
2631 * _scsih_sas_control_complete - completion routine
2632 * @ioc: per adapter object
2633 * @smid: system request message index
2634 * @msix_index: MSIX table index supplied by the OS
2635 * @reply: reply message frame(lower 32bit addr)
2636 * Context: interrupt time.
2638 * This is the sas iounit controll completion routine.
2639 * This code is part of the code to initiate the device removal
2640 * handshake protocal with controller firmware.
2642 * Return 1 meaning mf should be freed from _base_interrupt
2643 * 0 means the mf is freed from this function.
2646 _scsih_sas_control_complete(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
,
2647 u8 msix_index
, u32 reply
)
2649 Mpi2SasIoUnitControlReply_t
*mpi_reply
=
2650 mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
2652 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
2653 "sc_complete:handle(0x%04x), (open) "
2654 "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
2655 ioc
->name
, le16_to_cpu(mpi_reply
->DevHandle
), smid
,
2656 le16_to_cpu(mpi_reply
->IOCStatus
),
2657 le32_to_cpu(mpi_reply
->IOCLogInfo
)));
2662 * _scsih_tm_tr_complete -
2663 * @ioc: per adapter object
2664 * @smid: system request message index
2665 * @msix_index: MSIX table index supplied by the OS
2666 * @reply: reply message frame(lower 32bit addr)
2667 * Context: interrupt time.
2669 * This is the target reset completion routine.
2670 * This code is part of the code to initiate the device removal
2671 * handshake protocal with controller firmware.
2672 * It will send a sas iounit controll request (MPI2_SAS_OP_REMOVE_DEVICE)
2674 * Return 1 meaning mf should be freed from _base_interrupt
2675 * 0 means the mf is freed from this function.
2678 _scsih_tm_tr_complete(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
,
2682 Mpi2SCSITaskManagementRequest_t
*mpi_request_tm
;
2683 Mpi2SCSITaskManagementReply_t
*mpi_reply
=
2684 mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
2685 Mpi2SasIoUnitControlRequest_t
*mpi_request
;
2687 struct _tr_list
*delayed_tr
;
2689 if (ioc
->shost_recovery
|| ioc
->remove_host
) {
2690 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host reset in "
2691 "progress!\n", __func__
, ioc
->name
));
2695 mpi_request_tm
= mpt2sas_base_get_msg_frame(ioc
, smid
);
2696 handle
= le16_to_cpu(mpi_request_tm
->DevHandle
);
2697 if (handle
!= le16_to_cpu(mpi_reply
->DevHandle
)) {
2698 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"spurious interrupt: "
2699 "handle(0x%04x:0x%04x), smid(%d)!!!\n", ioc
->name
, handle
,
2700 le16_to_cpu(mpi_reply
->DevHandle
), smid
));
2704 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
2705 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
2706 "loginfo(0x%08x), completed(%d)\n", ioc
->name
,
2707 handle
, smid
, le16_to_cpu(mpi_reply
->IOCStatus
),
2708 le32_to_cpu(mpi_reply
->IOCLogInfo
),
2709 le32_to_cpu(mpi_reply
->TerminationCount
)));
2711 smid_sas_ctrl
= mpt2sas_base_get_smid(ioc
, ioc
->tm_sas_control_cb_idx
);
2712 if (!smid_sas_ctrl
) {
2713 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
2714 ioc
->name
, __func__
);
2718 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"sc_send:handle(0x%04x), "
2719 "(open), smid(%d), cb(%d)\n", ioc
->name
, handle
, smid_sas_ctrl
,
2720 ioc
->tm_sas_control_cb_idx
));
2721 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid_sas_ctrl
);
2722 memset(mpi_request
, 0, sizeof(Mpi2SasIoUnitControlRequest_t
));
2723 mpi_request
->Function
= MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
;
2724 mpi_request
->Operation
= MPI2_SAS_OP_REMOVE_DEVICE
;
2725 mpi_request
->DevHandle
= mpi_request_tm
->DevHandle
;
2726 mpt2sas_base_put_smid_default(ioc
, smid_sas_ctrl
);
2728 if (!list_empty(&ioc
->delayed_tr_list
)) {
2729 delayed_tr
= list_entry(ioc
->delayed_tr_list
.next
,
2730 struct _tr_list
, list
);
2731 mpt2sas_base_free_smid(ioc
, smid
);
2732 _scsih_tm_tr_send(ioc
, delayed_tr
->handle
);
2733 list_del(&delayed_tr
->list
);
2735 return 0; /* tells base_interrupt not to free mf */
2741 * _scsih_check_topo_delete_events - sanity check on topo events
2742 * @ioc: per adapter object
2743 * @event_data: the event data payload
2745 * This routine added to better handle cable breaker.
2747 * This handles the case where driver recieves multiple expander
2748 * add and delete events in a single shot. When there is a delete event
2749 * the routine will void any pending add events waiting in the event queue.
2754 _scsih_check_topo_delete_events(struct MPT2SAS_ADAPTER
*ioc
,
2755 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
2757 struct fw_event_work
*fw_event
;
2758 Mpi2EventDataSasTopologyChangeList_t
*local_event_data
;
2759 u16 expander_handle
;
2760 struct _sas_node
*sas_expander
;
2761 unsigned long flags
;
2765 for (i
= 0 ; i
< event_data
->NumEntries
; i
++) {
2766 if (event_data
->PHY
[i
].PhyStatus
&
2767 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT
)
2769 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
2772 reason_code
= event_data
->PHY
[i
].PhyStatus
&
2773 MPI2_EVENT_SAS_TOPO_RC_MASK
;
2774 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
)
2775 _scsih_tm_tr_send(ioc
, handle
);
2778 expander_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
2779 if (expander_handle
< ioc
->sas_hba
.num_phys
) {
2780 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
2784 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
2785 || event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
) {
2786 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
2787 sas_expander
= mpt2sas_scsih_expander_find_by_handle(ioc
,
2789 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
2790 _scsih_block_io_to_children_attached_to_ex(ioc
, sas_expander
);
2791 } else if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_RESPONDING
)
2792 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
2794 if (event_data
->ExpStatus
!= MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
)
2797 /* mark ignore flag for pending events */
2798 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2799 list_for_each_entry(fw_event
, &ioc
->fw_event_list
, list
) {
2800 if (fw_event
->event
!= MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
||
2803 local_event_data
= fw_event
->event_data
;
2804 if (local_event_data
->ExpStatus
==
2805 MPI2_EVENT_SAS_TOPO_ES_ADDED
||
2806 local_event_data
->ExpStatus
==
2807 MPI2_EVENT_SAS_TOPO_ES_RESPONDING
) {
2808 if (le16_to_cpu(local_event_data
->ExpanderDevHandle
) ==
2810 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
2811 "setting ignoring flag\n", ioc
->name
));
2812 fw_event
->ignore
= 1;
2816 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2820 * _scsih_flush_running_cmds - completing outstanding commands.
2821 * @ioc: per adapter object
2823 * The flushing out of all pending scmd commands following host reset,
2824 * where all IO is dropped to the floor.
2829 _scsih_flush_running_cmds(struct MPT2SAS_ADAPTER
*ioc
)
2831 struct scsi_cmnd
*scmd
;
2835 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
2836 scmd
= _scsih_scsi_lookup_get(ioc
, smid
);
2840 mpt2sas_base_free_smid(ioc
, smid
);
2841 scsi_dma_unmap(scmd
);
2842 scmd
->result
= DID_RESET
<< 16;
2843 scmd
->scsi_done(scmd
);
2845 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"completing %d cmds\n",
2850 * _scsih_setup_eedp - setup MPI request for EEDP transfer
2851 * @scmd: pointer to scsi command object
2852 * @mpi_request: pointer to the SCSI_IO reqest message frame
2854 * Supporting protection 1 and 3.
2859 _scsih_setup_eedp(struct scsi_cmnd
*scmd
, Mpi2SCSIIORequest_t
*mpi_request
)
2862 unsigned char prot_op
= scsi_get_prot_op(scmd
);
2863 unsigned char prot_type
= scsi_get_prot_type(scmd
);
2865 if (prot_type
== SCSI_PROT_DIF_TYPE0
|| prot_op
== SCSI_PROT_NORMAL
)
2868 if (prot_op
== SCSI_PROT_READ_STRIP
)
2869 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP
;
2870 else if (prot_op
== SCSI_PROT_WRITE_INSERT
)
2871 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_INSERT_OP
;
2875 switch (prot_type
) {
2876 case SCSI_PROT_DIF_TYPE1
:
2879 * enable ref/guard checking
2880 * auto increment ref tag
2882 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG
|
2883 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG
|
2884 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
2885 mpi_request
->CDB
.EEDP32
.PrimaryReferenceTag
=
2886 cpu_to_be32(scsi_get_lba(scmd
));
2889 case SCSI_PROT_DIF_TYPE2
:
2891 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG
|
2892 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG
|
2893 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
2896 case SCSI_PROT_DIF_TYPE3
:
2899 * enable guard checking
2901 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
2904 mpi_request
->EEDPBlockSize
= cpu_to_le32(scmd
->device
->sector_size
);
2905 mpi_request
->EEDPFlags
= cpu_to_le16(eedp_flags
);
2909 * _scsih_eedp_error_handling - return sense code for EEDP errors
2910 * @scmd: pointer to scsi command object
2911 * @ioc_status: ioc status
2916 _scsih_eedp_error_handling(struct scsi_cmnd
*scmd
, u16 ioc_status
)
2922 switch (ioc_status
) {
2923 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
2926 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
2929 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
2937 if (scmd
->sc_data_direction
== DMA_TO_DEVICE
) {
2938 sk
= ILLEGAL_REQUEST
;
2939 host_byte
= DID_ABORT
;
2941 sk
= ABORTED_COMMAND
;
2945 scsi_build_sense_buffer(0, scmd
->sense_buffer
, sk
, 0x10, ascq
);
2946 scmd
->result
= DRIVER_SENSE
<< 24 | (host_byte
<< 16) |
2947 SAM_STAT_CHECK_CONDITION
;
2951 * _scsih_qcmd - main scsi request entry point
2952 * @scmd: pointer to scsi command object
2953 * @done: function pointer to be invoked on completion
2955 * The callback index is set inside `ioc->scsi_io_cb_idx`.
2957 * Returns 0 on success. If there's a failure, return either:
2958 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
2959 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
2962 _scsih_qcmd(struct scsi_cmnd
*scmd
, void (*done
)(struct scsi_cmnd
*))
2964 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2965 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2966 struct MPT2SAS_TARGET
*sas_target_priv_data
;
2967 Mpi2SCSIIORequest_t
*mpi_request
;
2971 scmd
->scsi_done
= done
;
2972 sas_device_priv_data
= scmd
->device
->hostdata
;
2973 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2974 scmd
->result
= DID_NO_CONNECT
<< 16;
2975 scmd
->scsi_done(scmd
);
2979 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
2980 /* invalid device handle */
2981 if (sas_target_priv_data
->handle
== MPT2SAS_INVALID_DEVICE_HANDLE
) {
2982 scmd
->result
= DID_NO_CONNECT
<< 16;
2983 scmd
->scsi_done(scmd
);
2987 /* host recovery or link resets sent via IOCTLs */
2988 if (ioc
->shost_recovery
|| ioc
->ioc_link_reset_in_progress
)
2989 return SCSI_MLQUEUE_HOST_BUSY
;
2990 /* device busy with task managment */
2991 else if (sas_device_priv_data
->block
|| sas_target_priv_data
->tm_busy
)
2992 return SCSI_MLQUEUE_DEVICE_BUSY
;
2993 /* device has been deleted */
2994 else if (sas_target_priv_data
->deleted
) {
2995 scmd
->result
= DID_NO_CONNECT
<< 16;
2996 scmd
->scsi_done(scmd
);
3000 if (scmd
->sc_data_direction
== DMA_FROM_DEVICE
)
3001 mpi_control
= MPI2_SCSIIO_CONTROL_READ
;
3002 else if (scmd
->sc_data_direction
== DMA_TO_DEVICE
)
3003 mpi_control
= MPI2_SCSIIO_CONTROL_WRITE
;
3005 mpi_control
= MPI2_SCSIIO_CONTROL_NODATATRANSFER
;
3008 if (!(sas_device_priv_data
->flags
& MPT_DEVICE_FLAGS_INIT
)) {
3009 if (scmd
->device
->tagged_supported
) {
3010 if (scmd
->device
->ordered_tags
)
3011 mpi_control
|= MPI2_SCSIIO_CONTROL_ORDEREDQ
;
3013 mpi_control
|= MPI2_SCSIIO_CONTROL_SIMPLEQ
;
3015 /* MPI Revision I (UNIT = 0xA) - removed MPI2_SCSIIO_CONTROL_UNTAGGED */
3016 /* mpi_control |= MPI2_SCSIIO_CONTROL_UNTAGGED;
3018 mpi_control
|= (0x500);
3021 mpi_control
|= MPI2_SCSIIO_CONTROL_SIMPLEQ
;
3022 /* Make sure Device is not raid volume */
3023 if (!_scsih_is_raid(&scmd
->device
->sdev_gendev
) &&
3024 sas_is_tlr_enabled(scmd
->device
) && scmd
->cmd_len
!= 32)
3025 mpi_control
|= MPI2_SCSIIO_CONTROL_TLR_ON
;
3027 smid
= mpt2sas_base_get_smid_scsiio(ioc
, ioc
->scsi_io_cb_idx
, scmd
);
3029 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
3030 ioc
->name
, __func__
);
3033 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3034 memset(mpi_request
, 0, sizeof(Mpi2SCSIIORequest_t
));
3035 _scsih_setup_eedp(scmd
, mpi_request
);
3036 if (scmd
->cmd_len
== 32)
3037 mpi_control
|= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT
;
3038 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
3039 if (sas_device_priv_data
->sas_target
->flags
&
3040 MPT_TARGET_FLAGS_RAID_COMPONENT
)
3041 mpi_request
->Function
= MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
;
3043 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
3044 mpi_request
->DevHandle
=
3045 cpu_to_le16(sas_device_priv_data
->sas_target
->handle
);
3046 mpi_request
->DataLength
= cpu_to_le32(scsi_bufflen(scmd
));
3047 mpi_request
->Control
= cpu_to_le32(mpi_control
);
3048 mpi_request
->IoFlags
= cpu_to_le16(scmd
->cmd_len
);
3049 mpi_request
->MsgFlags
= MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR
;
3050 mpi_request
->SenseBufferLength
= SCSI_SENSE_BUFFERSIZE
;
3051 mpi_request
->SenseBufferLowAddress
=
3052 mpt2sas_base_get_sense_buffer_dma(ioc
, smid
);
3053 mpi_request
->SGLOffset0
= offsetof(Mpi2SCSIIORequest_t
, SGL
) / 4;
3054 mpi_request
->SGLFlags
= cpu_to_le16(MPI2_SCSIIO_SGLFLAGS_TYPE_MPI
+
3055 MPI2_SCSIIO_SGLFLAGS_SYSTEM_ADDR
);
3056 mpi_request
->VF_ID
= 0; /* TODO */
3057 mpi_request
->VP_ID
= 0;
3058 int_to_scsilun(sas_device_priv_data
->lun
, (struct scsi_lun
*)
3060 memcpy(mpi_request
->CDB
.CDB32
, scmd
->cmnd
, scmd
->cmd_len
);
3062 if (!mpi_request
->DataLength
) {
3063 mpt2sas_base_build_zero_len_sge(ioc
, &mpi_request
->SGL
);
3065 if (_scsih_build_scatter_gather(ioc
, scmd
, smid
)) {
3066 mpt2sas_base_free_smid(ioc
, smid
);
3071 if (likely(mpi_request
->Function
== MPI2_FUNCTION_SCSI_IO_REQUEST
))
3072 mpt2sas_base_put_smid_scsi_io(ioc
, smid
,
3073 sas_device_priv_data
->sas_target
->handle
);
3075 mpt2sas_base_put_smid_default(ioc
, smid
);
3079 return SCSI_MLQUEUE_HOST_BUSY
;
3083 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
3084 * @sense_buffer: sense data returned by target
3085 * @data: normalized skey/asc/ascq
3090 _scsih_normalize_sense(char *sense_buffer
, struct sense_info
*data
)
3092 if ((sense_buffer
[0] & 0x7F) >= 0x72) {
3093 /* descriptor format */
3094 data
->skey
= sense_buffer
[1] & 0x0F;
3095 data
->asc
= sense_buffer
[2];
3096 data
->ascq
= sense_buffer
[3];
3099 data
->skey
= sense_buffer
[2] & 0x0F;
3100 data
->asc
= sense_buffer
[12];
3101 data
->ascq
= sense_buffer
[13];
3105 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3107 * _scsih_scsi_ioc_info - translated non-successfull SCSI_IO request
3108 * @ioc: per adapter object
3109 * @scmd: pointer to scsi command object
3110 * @mpi_reply: reply mf payload returned from firmware
3112 * scsi_status - SCSI Status code returned from target device
3113 * scsi_state - state info associated with SCSI_IO determined by ioc
3114 * ioc_status - ioc supplied status info
3119 _scsih_scsi_ioc_info(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
,
3120 Mpi2SCSIIOReply_t
*mpi_reply
, u16 smid
)
3124 u16 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) &
3125 MPI2_IOCSTATUS_MASK
;
3126 u8 scsi_state
= mpi_reply
->SCSIState
;
3127 u8 scsi_status
= mpi_reply
->SCSIStatus
;
3128 char *desc_ioc_state
= NULL
;
3129 char *desc_scsi_status
= NULL
;
3130 char *desc_scsi_state
= ioc
->tmp_string
;
3131 u32 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
3132 struct _sas_device
*sas_device
= NULL
;
3133 unsigned long flags
;
3135 if (log_info
== 0x31170000)
3138 switch (ioc_status
) {
3139 case MPI2_IOCSTATUS_SUCCESS
:
3140 desc_ioc_state
= "success";
3142 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
3143 desc_ioc_state
= "invalid function";
3145 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
3146 desc_ioc_state
= "scsi recovered error";
3148 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE
:
3149 desc_ioc_state
= "scsi invalid dev handle";
3151 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
3152 desc_ioc_state
= "scsi device not there";
3154 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
3155 desc_ioc_state
= "scsi data overrun";
3157 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
3158 desc_ioc_state
= "scsi data underrun";
3160 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
3161 desc_ioc_state
= "scsi io data error";
3163 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
3164 desc_ioc_state
= "scsi protocol error";
3166 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
3167 desc_ioc_state
= "scsi task terminated";
3169 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
3170 desc_ioc_state
= "scsi residual mismatch";
3172 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
3173 desc_ioc_state
= "scsi task mgmt failed";
3175 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
3176 desc_ioc_state
= "scsi ioc terminated";
3178 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
3179 desc_ioc_state
= "scsi ext terminated";
3181 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
3182 desc_ioc_state
= "eedp guard error";
3184 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
3185 desc_ioc_state
= "eedp ref tag error";
3187 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
3188 desc_ioc_state
= "eedp app tag error";
3191 desc_ioc_state
= "unknown";
3195 switch (scsi_status
) {
3196 case MPI2_SCSI_STATUS_GOOD
:
3197 desc_scsi_status
= "good";
3199 case MPI2_SCSI_STATUS_CHECK_CONDITION
:
3200 desc_scsi_status
= "check condition";
3202 case MPI2_SCSI_STATUS_CONDITION_MET
:
3203 desc_scsi_status
= "condition met";
3205 case MPI2_SCSI_STATUS_BUSY
:
3206 desc_scsi_status
= "busy";
3208 case MPI2_SCSI_STATUS_INTERMEDIATE
:
3209 desc_scsi_status
= "intermediate";
3211 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET
:
3212 desc_scsi_status
= "intermediate condmet";
3214 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT
:
3215 desc_scsi_status
= "reservation conflict";
3217 case MPI2_SCSI_STATUS_COMMAND_TERMINATED
:
3218 desc_scsi_status
= "command terminated";
3220 case MPI2_SCSI_STATUS_TASK_SET_FULL
:
3221 desc_scsi_status
= "task set full";
3223 case MPI2_SCSI_STATUS_ACA_ACTIVE
:
3224 desc_scsi_status
= "aca active";
3226 case MPI2_SCSI_STATUS_TASK_ABORTED
:
3227 desc_scsi_status
= "task aborted";
3230 desc_scsi_status
= "unknown";
3234 desc_scsi_state
[0] = '\0';
3236 desc_scsi_state
= " ";
3237 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
3238 strcat(desc_scsi_state
, "response info ");
3239 if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
3240 strcat(desc_scsi_state
, "state terminated ");
3241 if (scsi_state
& MPI2_SCSI_STATE_NO_SCSI_STATUS
)
3242 strcat(desc_scsi_state
, "no status ");
3243 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_FAILED
)
3244 strcat(desc_scsi_state
, "autosense failed ");
3245 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
)
3246 strcat(desc_scsi_state
, "autosense valid ");
3248 scsi_print_command(scmd
);
3250 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
3251 sas_device
= _scsih_sas_device_find_by_handle(ioc
,
3252 le16_to_cpu(mpi_reply
->DevHandle
));
3254 printk(MPT2SAS_WARN_FMT
"\tsas_address(0x%016llx), phy(%d)\n",
3255 ioc
->name
, sas_device
->sas_address
, sas_device
->phy
);
3256 printk(MPT2SAS_WARN_FMT
"\tenclosure_logical_id(0x%016llx), "
3257 "slot(%d)\n", ioc
->name
, sas_device
->enclosure_logical_id
,
3260 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3262 printk(MPT2SAS_WARN_FMT
"\tdev handle(0x%04x), "
3263 "ioc_status(%s)(0x%04x), smid(%d)\n", ioc
->name
,
3264 le16_to_cpu(mpi_reply
->DevHandle
), desc_ioc_state
,
3266 printk(MPT2SAS_WARN_FMT
"\trequest_len(%d), underflow(%d), "
3267 "resid(%d)\n", ioc
->name
, scsi_bufflen(scmd
), scmd
->underflow
,
3268 scsi_get_resid(scmd
));
3269 printk(MPT2SAS_WARN_FMT
"\ttag(%d), transfer_count(%d), "
3270 "sc->result(0x%08x)\n", ioc
->name
, le16_to_cpu(mpi_reply
->TaskTag
),
3271 le32_to_cpu(mpi_reply
->TransferCount
), scmd
->result
);
3272 printk(MPT2SAS_WARN_FMT
"\tscsi_status(%s)(0x%02x), "
3273 "scsi_state(%s)(0x%02x)\n", ioc
->name
, desc_scsi_status
,
3274 scsi_status
, desc_scsi_state
, scsi_state
);
3276 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
3277 struct sense_info data
;
3278 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
3279 printk(MPT2SAS_WARN_FMT
"\t[sense_key,asc,ascq]: "
3280 "[0x%02x,0x%02x,0x%02x], count(%d)\n", ioc
->name
, data
.skey
,
3281 data
.asc
, data
.ascq
, le32_to_cpu(mpi_reply
->SenseCount
));
3284 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
) {
3285 response_info
= le32_to_cpu(mpi_reply
->ResponseInfo
);
3286 response_bytes
= (u8
*)&response_info
;
3287 _scsih_response_code(ioc
, response_bytes
[0]);
3293 * _scsih_smart_predicted_fault - illuminate Fault LED
3294 * @ioc: per adapter object
3295 * @handle: device handle
3300 _scsih_smart_predicted_fault(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
3302 Mpi2SepReply_t mpi_reply
;
3303 Mpi2SepRequest_t mpi_request
;
3304 struct scsi_target
*starget
;
3305 struct MPT2SAS_TARGET
*sas_target_priv_data
;
3306 Mpi2EventNotificationReply_t
*event_reply
;
3307 Mpi2EventDataSasDeviceStatusChange_t
*event_data
;
3308 struct _sas_device
*sas_device
;
3310 unsigned long flags
;
3312 /* only handle non-raid devices */
3313 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
3314 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
3316 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3319 starget
= sas_device
->starget
;
3320 sas_target_priv_data
= starget
->hostdata
;
3322 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
) ||
3323 ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
))) {
3324 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3327 starget_printk(KERN_WARNING
, starget
, "predicted fault\n");
3328 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3330 if (ioc
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_IBM
) {
3331 memset(&mpi_request
, 0, sizeof(Mpi2SepRequest_t
));
3332 mpi_request
.Function
= MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR
;
3333 mpi_request
.Action
= MPI2_SEP_REQ_ACTION_WRITE_STATUS
;
3334 mpi_request
.SlotStatus
=
3335 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT
);
3336 mpi_request
.DevHandle
= cpu_to_le16(handle
);
3337 mpi_request
.Flags
= MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS
;
3338 if ((mpt2sas_base_scsi_enclosure_processor(ioc
, &mpi_reply
,
3339 &mpi_request
)) != 0) {
3340 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3341 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3345 if (mpi_reply
.IOCStatus
|| mpi_reply
.IOCLogInfo
) {
3346 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3347 "enclosure_processor: ioc_status (0x%04x), "
3348 "loginfo(0x%08x)\n", ioc
->name
,
3349 le16_to_cpu(mpi_reply
.IOCStatus
),
3350 le32_to_cpu(mpi_reply
.IOCLogInfo
)));
3355 /* insert into event log */
3356 sz
= offsetof(Mpi2EventNotificationReply_t
, EventData
) +
3357 sizeof(Mpi2EventDataSasDeviceStatusChange_t
);
3358 event_reply
= kzalloc(sz
, GFP_KERNEL
);
3360 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3361 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3365 event_reply
->Function
= MPI2_FUNCTION_EVENT_NOTIFICATION
;
3366 event_reply
->Event
=
3367 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
);
3368 event_reply
->MsgLength
= sz
/4;
3369 event_reply
->EventDataLength
=
3370 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t
)/4);
3371 event_data
= (Mpi2EventDataSasDeviceStatusChange_t
*)
3372 event_reply
->EventData
;
3373 event_data
->ReasonCode
= MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
;
3374 event_data
->ASC
= 0x5D;
3375 event_data
->DevHandle
= cpu_to_le16(handle
);
3376 event_data
->SASAddress
= cpu_to_le64(sas_target_priv_data
->sas_address
);
3377 mpt2sas_ctl_add_to_event_log(ioc
, event_reply
);
3382 * _scsih_io_done - scsi request callback
3383 * @ioc: per adapter object
3384 * @smid: system request message index
3385 * @msix_index: MSIX table index supplied by the OS
3386 * @reply: reply message frame(lower 32bit addr)
3388 * Callback handler when using _scsih_qcmd.
3390 * Return 1 meaning mf should be freed from _base_interrupt
3391 * 0 means the mf is freed from this function.
3394 _scsih_io_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
3396 Mpi2SCSIIORequest_t
*mpi_request
;
3397 Mpi2SCSIIOReply_t
*mpi_reply
;
3398 struct scsi_cmnd
*scmd
;
3404 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
3405 u32 response_code
= 0;
3407 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
3408 scmd
= _scsih_scsi_lookup_get(ioc
, smid
);
3412 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3414 if (mpi_reply
== NULL
) {
3415 scmd
->result
= DID_OK
<< 16;
3419 sas_device_priv_data
= scmd
->device
->hostdata
;
3420 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
||
3421 sas_device_priv_data
->sas_target
->deleted
) {
3422 scmd
->result
= DID_NO_CONNECT
<< 16;
3426 /* turning off TLR */
3427 scsi_state
= mpi_reply
->SCSIState
;
3428 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
3430 le32_to_cpu(mpi_reply
->ResponseInfo
) & 0xFF;
3431 if (!sas_device_priv_data
->tlr_snoop_check
) {
3432 sas_device_priv_data
->tlr_snoop_check
++;
3433 if (!_scsih_is_raid(&scmd
->device
->sdev_gendev
) &&
3434 sas_is_tlr_enabled(scmd
->device
) &&
3435 response_code
== MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
) {
3436 sas_disable_tlr(scmd
->device
);
3437 sdev_printk(KERN_INFO
, scmd
->device
, "TLR disabled\n");
3441 xfer_cnt
= le32_to_cpu(mpi_reply
->TransferCount
);
3442 scsi_set_resid(scmd
, scsi_bufflen(scmd
) - xfer_cnt
);
3443 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
);
3444 if (ioc_status
& MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE
)
3445 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
3448 ioc_status
&= MPI2_IOCSTATUS_MASK
;
3449 scsi_status
= mpi_reply
->SCSIStatus
;
3451 if (ioc_status
== MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
&& xfer_cnt
== 0 &&
3452 (scsi_status
== MPI2_SCSI_STATUS_BUSY
||
3453 scsi_status
== MPI2_SCSI_STATUS_RESERVATION_CONFLICT
||
3454 scsi_status
== MPI2_SCSI_STATUS_TASK_SET_FULL
)) {
3455 ioc_status
= MPI2_IOCSTATUS_SUCCESS
;
3458 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
3459 struct sense_info data
;
3460 const void *sense_data
= mpt2sas_base_get_sense_buffer(ioc
,
3462 u32 sz
= min_t(u32
, SCSI_SENSE_BUFFERSIZE
,
3463 le32_to_cpu(mpi_reply
->SenseCount
));
3464 memcpy(scmd
->sense_buffer
, sense_data
, sz
);
3465 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
3466 /* failure prediction threshold exceeded */
3467 if (data
.asc
== 0x5D)
3468 _scsih_smart_predicted_fault(ioc
,
3469 le16_to_cpu(mpi_reply
->DevHandle
));
3472 switch (ioc_status
) {
3473 case MPI2_IOCSTATUS_BUSY
:
3474 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES
:
3475 scmd
->result
= SAM_STAT_BUSY
;
3478 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
3479 scmd
->result
= DID_NO_CONNECT
<< 16;
3482 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
3483 if (sas_device_priv_data
->block
) {
3484 scmd
->result
= DID_TRANSPORT_DISRUPTED
<< 16;
3487 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
3488 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
3489 scmd
->result
= DID_RESET
<< 16;
3492 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
3493 if ((xfer_cnt
== 0) || (scmd
->underflow
> xfer_cnt
))
3494 scmd
->result
= DID_SOFT_ERROR
<< 16;
3496 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
3499 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
3500 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
3502 if ((scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
))
3505 if (xfer_cnt
< scmd
->underflow
) {
3506 if (scsi_status
== SAM_STAT_BUSY
)
3507 scmd
->result
= SAM_STAT_BUSY
;
3509 scmd
->result
= DID_SOFT_ERROR
<< 16;
3510 } else if (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
3511 MPI2_SCSI_STATE_NO_SCSI_STATUS
))
3512 scmd
->result
= DID_SOFT_ERROR
<< 16;
3513 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
3514 scmd
->result
= DID_RESET
<< 16;
3515 else if (!xfer_cnt
&& scmd
->cmnd
[0] == REPORT_LUNS
) {
3516 mpi_reply
->SCSIState
= MPI2_SCSI_STATE_AUTOSENSE_VALID
;
3517 mpi_reply
->SCSIStatus
= SAM_STAT_CHECK_CONDITION
;
3518 scmd
->result
= (DRIVER_SENSE
<< 24) |
3519 SAM_STAT_CHECK_CONDITION
;
3520 scmd
->sense_buffer
[0] = 0x70;
3521 scmd
->sense_buffer
[2] = ILLEGAL_REQUEST
;
3522 scmd
->sense_buffer
[12] = 0x20;
3523 scmd
->sense_buffer
[13] = 0;
3527 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
3528 scsi_set_resid(scmd
, 0);
3529 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
3530 case MPI2_IOCSTATUS_SUCCESS
:
3531 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
3532 if (response_code
==
3533 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
||
3534 (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
3535 MPI2_SCSI_STATE_NO_SCSI_STATUS
)))
3536 scmd
->result
= DID_SOFT_ERROR
<< 16;
3537 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
3538 scmd
->result
= DID_RESET
<< 16;
3541 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
3542 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
3543 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
3544 _scsih_eedp_error_handling(scmd
, ioc_status
);
3546 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
3547 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
3548 case MPI2_IOCSTATUS_INVALID_SGL
:
3549 case MPI2_IOCSTATUS_INTERNAL_ERROR
:
3550 case MPI2_IOCSTATUS_INVALID_FIELD
:
3551 case MPI2_IOCSTATUS_INVALID_STATE
:
3552 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
3553 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
3555 scmd
->result
= DID_SOFT_ERROR
<< 16;
3560 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3561 if (scmd
->result
&& (ioc
->logging_level
& MPT_DEBUG_REPLY
))
3562 _scsih_scsi_ioc_info(ioc
, scmd
, mpi_reply
, smid
);
3566 scsi_dma_unmap(scmd
);
3567 scmd
->scsi_done(scmd
);
3572 * _scsih_sas_host_refresh - refreshing sas host object contents
3573 * @ioc: per adapter object
3576 * During port enable, fw will send topology events for every device. Its
3577 * possible that the handles may change from the previous setting, so this
3578 * code keeping handles updating if changed.
3583 _scsih_sas_host_refresh(struct MPT2SAS_ADAPTER
*ioc
)
3588 Mpi2ConfigReply_t mpi_reply
;
3589 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
3590 u16 attached_handle
;
3592 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
3593 "updating handles for sas_host(0x%016llx)\n",
3594 ioc
->name
, (unsigned long long)ioc
->sas_hba
.sas_address
));
3596 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
3597 * sizeof(Mpi2SasIOUnit0PhyData_t
));
3598 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
3599 if (!sas_iounit_pg0
) {
3600 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3601 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3605 if ((mpt2sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
3606 sas_iounit_pg0
, sz
)) != 0)
3608 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
3609 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
3611 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
3613 ioc
->sas_hba
.handle
= le16_to_cpu(sas_iounit_pg0
->
3614 PhyData
[0].ControllerDevHandle
);
3615 ioc
->sas_hba
.phy
[i
].handle
= ioc
->sas_hba
.handle
;
3616 attached_handle
= le16_to_cpu(sas_iounit_pg0
->PhyData
[i
].
3618 mpt2sas_transport_update_links(ioc
, ioc
->sas_hba
.sas_address
,
3619 attached_handle
, i
, sas_iounit_pg0
->PhyData
[i
].
3620 NegotiatedLinkRate
>> 4);
3623 kfree(sas_iounit_pg0
);
3627 * _scsih_sas_host_add - create sas host object
3628 * @ioc: per adapter object
3630 * Creating host side data object, stored in ioc->sas_hba
3635 _scsih_sas_host_add(struct MPT2SAS_ADAPTER
*ioc
)
3638 Mpi2ConfigReply_t mpi_reply
;
3639 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
3640 Mpi2SasIOUnitPage1_t
*sas_iounit_pg1
= NULL
;
3641 Mpi2SasPhyPage0_t phy_pg0
;
3642 Mpi2SasDevicePage0_t sas_device_pg0
;
3643 Mpi2SasEnclosurePage0_t enclosure_pg0
;
3646 u16 device_missing_delay
;
3648 mpt2sas_config_get_number_hba_phys(ioc
, &ioc
->sas_hba
.num_phys
);
3649 if (!ioc
->sas_hba
.num_phys
) {
3650 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3651 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3655 /* sas_iounit page 0 */
3656 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
3657 sizeof(Mpi2SasIOUnit0PhyData_t
));
3658 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
3659 if (!sas_iounit_pg0
) {
3660 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3661 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3664 if ((mpt2sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
3665 sas_iounit_pg0
, sz
))) {
3666 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3667 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3670 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
3671 MPI2_IOCSTATUS_MASK
;
3672 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
3673 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3674 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3678 /* sas_iounit page 1 */
3679 sz
= offsetof(Mpi2SasIOUnitPage1_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
3680 sizeof(Mpi2SasIOUnit1PhyData_t
));
3681 sas_iounit_pg1
= kzalloc(sz
, GFP_KERNEL
);
3682 if (!sas_iounit_pg1
) {
3683 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3684 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3687 if ((mpt2sas_config_get_sas_iounit_pg1(ioc
, &mpi_reply
,
3688 sas_iounit_pg1
, sz
))) {
3689 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3690 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3693 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
3694 MPI2_IOCSTATUS_MASK
;
3695 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
3696 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3697 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3701 ioc
->io_missing_delay
=
3702 le16_to_cpu(sas_iounit_pg1
->IODeviceMissingDelay
);
3703 device_missing_delay
=
3704 le16_to_cpu(sas_iounit_pg1
->ReportDeviceMissingDelay
);
3705 if (device_missing_delay
& MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16
)
3706 ioc
->device_missing_delay
= (device_missing_delay
&
3707 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
) * 16;
3709 ioc
->device_missing_delay
= device_missing_delay
&
3710 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
;
3712 ioc
->sas_hba
.parent_dev
= &ioc
->shost
->shost_gendev
;
3713 ioc
->sas_hba
.phy
= kcalloc(ioc
->sas_hba
.num_phys
,
3714 sizeof(struct _sas_phy
), GFP_KERNEL
);
3715 if (!ioc
->sas_hba
.phy
) {
3716 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3717 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3720 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
3721 if ((mpt2sas_config_get_phy_pg0(ioc
, &mpi_reply
, &phy_pg0
,
3723 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3724 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3727 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
3728 MPI2_IOCSTATUS_MASK
;
3729 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
3730 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3731 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3736 ioc
->sas_hba
.handle
= le16_to_cpu(sas_iounit_pg0
->
3737 PhyData
[0].ControllerDevHandle
);
3738 ioc
->sas_hba
.phy
[i
].handle
= ioc
->sas_hba
.handle
;
3739 ioc
->sas_hba
.phy
[i
].phy_id
= i
;
3740 mpt2sas_transport_add_host_phy(ioc
, &ioc
->sas_hba
.phy
[i
],
3741 phy_pg0
, ioc
->sas_hba
.parent_dev
);
3743 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
3744 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, ioc
->sas_hba
.handle
))) {
3745 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3746 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3749 ioc
->sas_hba
.enclosure_handle
=
3750 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
3751 ioc
->sas_hba
.sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
3752 printk(MPT2SAS_INFO_FMT
"host_add: handle(0x%04x), "
3753 "sas_addr(0x%016llx), phys(%d)\n", ioc
->name
, ioc
->sas_hba
.handle
,
3754 (unsigned long long) ioc
->sas_hba
.sas_address
,
3755 ioc
->sas_hba
.num_phys
) ;
3757 if (ioc
->sas_hba
.enclosure_handle
) {
3758 if (!(mpt2sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
3760 MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
3761 ioc
->sas_hba
.enclosure_handle
))) {
3762 ioc
->sas_hba
.enclosure_logical_id
=
3763 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
3768 kfree(sas_iounit_pg1
);
3769 kfree(sas_iounit_pg0
);
3773 * _scsih_expander_add - creating expander object
3774 * @ioc: per adapter object
3775 * @handle: expander handle
3777 * Creating expander object, stored in ioc->sas_expander_list.
3779 * Return 0 for success, else error.
3782 _scsih_expander_add(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
3784 struct _sas_node
*sas_expander
;
3785 Mpi2ConfigReply_t mpi_reply
;
3786 Mpi2ExpanderPage0_t expander_pg0
;
3787 Mpi2ExpanderPage1_t expander_pg1
;
3788 Mpi2SasEnclosurePage0_t enclosure_pg0
;
3791 __le64 sas_address
, sas_address_parent
= 0;
3793 unsigned long flags
;
3794 struct _sas_port
*mpt2sas_port
= NULL
;
3800 if (ioc
->shost_recovery
)
3803 if ((mpt2sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
3804 MPI2_SAS_EXPAND_PGAD_FORM_HNDL
, handle
))) {
3805 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3806 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3810 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
3811 MPI2_IOCSTATUS_MASK
;
3812 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
3813 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3814 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3818 /* handle out of order topology events */
3819 parent_handle
= le16_to_cpu(expander_pg0
.ParentDevHandle
);
3820 if (_scsih_get_sas_address(ioc
, parent_handle
, &sas_address_parent
)
3822 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3823 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3826 if (sas_address_parent
!= ioc
->sas_hba
.sas_address
) {
3827 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
3828 sas_expander
= mpt2sas_scsih_expander_find_by_sas_address(ioc
,
3829 sas_address_parent
);
3830 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
3831 if (!sas_expander
) {
3832 rc
= _scsih_expander_add(ioc
, parent_handle
);
3838 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
3839 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
3840 sas_expander
= mpt2sas_scsih_expander_find_by_sas_address(ioc
,
3842 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
3847 sas_expander
= kzalloc(sizeof(struct _sas_node
),
3849 if (!sas_expander
) {
3850 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3851 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3855 sas_expander
->handle
= handle
;
3856 sas_expander
->num_phys
= expander_pg0
.NumPhys
;
3857 sas_expander
->sas_address_parent
= sas_address_parent
;
3858 sas_expander
->sas_address
= sas_address
;
3860 printk(MPT2SAS_INFO_FMT
"expander_add: handle(0x%04x),"
3861 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc
->name
,
3862 handle
, parent_handle
, (unsigned long long)
3863 sas_expander
->sas_address
, sas_expander
->num_phys
);
3865 if (!sas_expander
->num_phys
)
3867 sas_expander
->phy
= kcalloc(sas_expander
->num_phys
,
3868 sizeof(struct _sas_phy
), GFP_KERNEL
);
3869 if (!sas_expander
->phy
) {
3870 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3871 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3876 INIT_LIST_HEAD(&sas_expander
->sas_port_list
);
3877 mpt2sas_port
= mpt2sas_transport_port_add(ioc
, handle
,
3878 sas_address_parent
);
3879 if (!mpt2sas_port
) {
3880 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3881 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3885 sas_expander
->parent_dev
= &mpt2sas_port
->rphy
->dev
;
3887 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++) {
3888 if ((mpt2sas_config_get_expander_pg1(ioc
, &mpi_reply
,
3889 &expander_pg1
, i
, handle
))) {
3890 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3891 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3895 sas_expander
->phy
[i
].handle
= handle
;
3896 sas_expander
->phy
[i
].phy_id
= i
;
3898 if ((mpt2sas_transport_add_expander_phy(ioc
,
3899 &sas_expander
->phy
[i
], expander_pg1
,
3900 sas_expander
->parent_dev
))) {
3901 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3902 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3908 if (sas_expander
->enclosure_handle
) {
3909 if (!(mpt2sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
3910 &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
3911 sas_expander
->enclosure_handle
))) {
3912 sas_expander
->enclosure_logical_id
=
3913 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
3917 _scsih_expander_node_add(ioc
, sas_expander
);
3923 mpt2sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
3924 sas_address_parent
);
3925 kfree(sas_expander
);
3930 * _scsih_done - scsih callback handler.
3931 * @ioc: per adapter object
3932 * @smid: system request message index
3933 * @msix_index: MSIX table index supplied by the OS
3934 * @reply: reply message frame(lower 32bit addr)
3936 * Callback handler when sending internal generated message frames.
3937 * The callback index passed is `ioc->scsih_cb_idx`
3939 * Return 1 meaning mf should be freed from _base_interrupt
3940 * 0 means the mf is freed from this function.
3943 _scsih_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
3945 MPI2DefaultReply_t
*mpi_reply
;
3947 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
3948 if (ioc
->scsih_cmds
.status
== MPT2_CMD_NOT_USED
)
3950 if (ioc
->scsih_cmds
.smid
!= smid
)
3952 ioc
->scsih_cmds
.status
|= MPT2_CMD_COMPLETE
;
3954 memcpy(ioc
->scsih_cmds
.reply
, mpi_reply
,
3955 mpi_reply
->MsgLength
*4);
3956 ioc
->scsih_cmds
.status
|= MPT2_CMD_REPLY_VALID
;
3958 ioc
->scsih_cmds
.status
&= ~MPT2_CMD_PENDING
;
3959 complete(&ioc
->scsih_cmds
.done
);
3964 * _scsih_expander_remove - removing expander object
3965 * @ioc: per adapter object
3966 * @sas_address: expander sas_address
3971 _scsih_expander_remove(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
)
3973 struct _sas_node
*sas_expander
;
3974 unsigned long flags
;
3976 if (ioc
->shost_recovery
)
3979 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
3980 sas_expander
= mpt2sas_scsih_expander_find_by_sas_address(ioc
,
3982 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
3983 _scsih_expander_node_remove(ioc
, sas_expander
);
3987 * _scsih_check_access_status - check access flags
3988 * @ioc: per adapter object
3989 * @sas_address: sas address
3990 * @handle: sas device handle
3991 * @access_flags: errors returned during discovery of the device
3993 * Return 0 for success, else failure
3996 _scsih_check_access_status(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
,
3997 u16 handle
, u8 access_status
)
4002 switch (access_status
) {
4003 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS
:
4004 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION
:
4007 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED
:
4008 desc
= "sata capability failed";
4010 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT
:
4011 desc
= "sata affiliation conflict";
4013 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE
:
4014 desc
= "route not addressable";
4016 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE
:
4017 desc
= "smp error not addressable";
4019 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED
:
4020 desc
= "device blocked";
4022 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED
:
4023 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN
:
4024 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT
:
4025 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG
:
4026 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION
:
4027 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER
:
4028 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN
:
4029 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN
:
4030 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN
:
4031 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION
:
4032 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE
:
4033 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX
:
4034 desc
= "sata initialization failed";
4044 printk(MPT2SAS_ERR_FMT
"discovery errors(%s): sas_address(0x%016llx), "
4045 "handle(0x%04x)\n", ioc
->name
, desc
,
4046 (unsigned long long)sas_address
, handle
);
4051 _scsih_check_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
4053 Mpi2ConfigReply_t mpi_reply
;
4054 Mpi2SasDevicePage0_t sas_device_pg0
;
4055 struct _sas_device
*sas_device
;
4057 unsigned long flags
;
4059 struct scsi_target
*starget
;
4060 struct MPT2SAS_TARGET
*sas_target_priv_data
;
4063 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
4064 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
)))
4067 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
4068 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
4071 /* check if this is end device */
4072 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
4073 if (!(_scsih_is_end_device(device_info
)))
4076 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4077 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
4078 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
4082 printk(MPT2SAS_ERR_FMT
"device is not present "
4083 "handle(0x%04x), no sas_device!!!\n", ioc
->name
, handle
);
4084 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4088 if (unlikely(sas_device
->handle
!= handle
)) {
4089 starget
= sas_device
->starget
;
4090 sas_target_priv_data
= starget
->hostdata
;
4091 starget_printk(KERN_INFO
, starget
, "handle changed from(0x%04x)"
4092 " to (0x%04x)!!!\n", sas_device
->handle
, handle
);
4093 sas_target_priv_data
->handle
= handle
;
4094 sas_device
->handle
= handle
;
4096 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4098 /* check if device is present */
4099 if (!(le16_to_cpu(sas_device_pg0
.Flags
) &
4100 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT
)) {
4101 printk(MPT2SAS_ERR_FMT
"device is not present "
4102 "handle(0x%04x), flags!!!\n", ioc
->name
, handle
);
4106 /* check if there were any issues with discovery */
4107 if (_scsih_check_access_status(ioc
, sas_address
, handle
,
4108 sas_device_pg0
.AccessStatus
))
4110 _scsih_ublock_io_device(ioc
, handle
);
4115 * _scsih_add_device - creating sas device object
4116 * @ioc: per adapter object
4117 * @handle: sas device handle
4118 * @phy_num: phy number end device attached to
4119 * @is_pd: is this hidden raid component
4121 * Creating end device object, stored in ioc->sas_device_list.
4123 * Returns 0 for success, non-zero for failure.
4126 _scsih_add_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
, u8 phy_num
, u8 is_pd
)
4128 Mpi2ConfigReply_t mpi_reply
;
4129 Mpi2SasDevicePage0_t sas_device_pg0
;
4130 Mpi2SasEnclosurePage0_t enclosure_pg0
;
4131 struct _sas_device
*sas_device
;
4135 unsigned long flags
;
4137 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
4138 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
4139 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4140 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4144 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4145 MPI2_IOCSTATUS_MASK
;
4146 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4147 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4148 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4152 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
4154 /* check if device is present */
4155 if (!(le16_to_cpu(sas_device_pg0
.Flags
) &
4156 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT
)) {
4157 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4158 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4159 printk(MPT2SAS_ERR_FMT
"Flags = 0x%04x\n",
4160 ioc
->name
, le16_to_cpu(sas_device_pg0
.Flags
));
4164 /* check if there were any issues with discovery */
4165 if (_scsih_check_access_status(ioc
, sas_address
, handle
,
4166 sas_device_pg0
.AccessStatus
))
4169 /* check if this is end device */
4170 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
4171 if (!(_scsih_is_end_device(device_info
))) {
4172 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4173 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4178 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4179 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
4181 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4186 sas_device
= kzalloc(sizeof(struct _sas_device
),
4189 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4190 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4194 sas_device
->handle
= handle
;
4195 if (_scsih_get_sas_address(ioc
, le16_to_cpu
4196 (sas_device_pg0
.ParentDevHandle
),
4197 &sas_device
->sas_address_parent
) != 0)
4198 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4199 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4200 sas_device
->enclosure_handle
=
4201 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
4203 le16_to_cpu(sas_device_pg0
.Slot
);
4204 sas_device
->device_info
= device_info
;
4205 sas_device
->sas_address
= sas_address
;
4206 sas_device
->phy
= sas_device_pg0
.PhyNum
;
4207 sas_device
->hidden_raid_component
= is_pd
;
4209 /* get enclosure_logical_id */
4210 if (sas_device
->enclosure_handle
&& !(mpt2sas_config_get_enclosure_pg0(
4211 ioc
, &mpi_reply
, &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
4212 sas_device
->enclosure_handle
)))
4213 sas_device
->enclosure_logical_id
=
4214 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
4216 /* get device name */
4217 sas_device
->device_name
= le64_to_cpu(sas_device_pg0
.DeviceName
);
4219 if (ioc
->wait_for_port_enable_to_complete
)
4220 _scsih_sas_device_init_add(ioc
, sas_device
);
4222 _scsih_sas_device_add(ioc
, sas_device
);
4228 * _scsih_remove_pd_device - removing sas device pd object
4229 * @ioc: per adapter object
4230 * @sas_device_delete: the sas_device object
4232 * For hidden raid components, we do driver-fw handshake from
4233 * hotplug work threads.
4237 _scsih_remove_pd_device(struct MPT2SAS_ADAPTER
*ioc
, struct _sas_device
4240 Mpi2SasIoUnitControlReply_t mpi_reply
;
4241 Mpi2SasIoUnitControlRequest_t mpi_request
;
4242 u16 vol_handle
, handle
;
4244 handle
= sas_device
.handle
;
4245 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: enter: handle(0x%04x),"
4246 " sas_addr(0x%016llx)\n", ioc
->name
, __func__
, handle
,
4247 (unsigned long long) sas_device
.sas_address
));
4249 vol_handle
= sas_device
.volume_handle
;
4252 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"issue target reset: "
4253 "handle(0x%04x)\n", ioc
->name
, vol_handle
));
4254 mpt2sas_scsih_issue_tm(ioc
, vol_handle
, 0, 0, 0,
4255 MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
, 0, 30, NULL
);
4256 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"issue target reset "
4257 "done: handle(0x%04x)\n", ioc
->name
, vol_handle
));
4258 if (ioc
->shost_recovery
)
4261 /* SAS_IO_UNIT_CNTR - send REMOVE_DEVICE */
4262 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"sas_iounit: handle"
4263 "(0x%04x)\n", ioc
->name
, handle
));
4264 memset(&mpi_request
, 0, sizeof(Mpi2SasIoUnitControlRequest_t
));
4265 mpi_request
.Function
= MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
;
4266 mpi_request
.Operation
= MPI2_SAS_OP_REMOVE_DEVICE
;
4267 mpi_request
.DevHandle
= cpu_to_le16(handle
);
4268 if ((mpt2sas_base_sas_iounit_control(ioc
, &mpi_reply
,
4269 &mpi_request
)) != 0)
4270 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4271 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4273 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"sas_iounit: ioc_status"
4274 "(0x%04x), loginfo(0x%08x)\n", ioc
->name
,
4275 le16_to_cpu(mpi_reply
.IOCStatus
),
4276 le32_to_cpu(mpi_reply
.IOCLogInfo
)));
4278 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: exit: handle(0x%04x),"
4279 " sas_addr(0x%016llx)\n", ioc
->name
, __func__
, handle
,
4280 (unsigned long long) sas_device
.sas_address
));
4284 * _scsih_remove_device - removing sas device object
4285 * @ioc: per adapter object
4286 * @sas_device_delete: the sas_device object
4291 _scsih_remove_device(struct MPT2SAS_ADAPTER
*ioc
,
4292 struct _sas_device
*sas_device
)
4294 struct _sas_device sas_device_backup
;
4295 struct MPT2SAS_TARGET
*sas_target_priv_data
;
4300 memcpy(&sas_device_backup
, sas_device
, sizeof(struct _sas_device
));
4301 _scsih_sas_device_remove(ioc
, sas_device
);
4303 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: enter: "
4304 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
, __func__
,
4305 sas_device_backup
.handle
, (unsigned long long)
4306 sas_device_backup
.sas_address
));
4308 if (sas_device_backup
.starget
&& sas_device_backup
.starget
->hostdata
) {
4309 sas_target_priv_data
= sas_device_backup
.starget
->hostdata
;
4310 sas_target_priv_data
->deleted
= 1;
4313 if (sas_device_backup
.hidden_raid_component
)
4314 _scsih_remove_pd_device(ioc
, sas_device_backup
);
4316 _scsih_ublock_io_device(ioc
, sas_device_backup
.handle
);
4318 mpt2sas_transport_port_remove(ioc
, sas_device_backup
.sas_address
,
4319 sas_device_backup
.sas_address_parent
);
4321 printk(MPT2SAS_INFO_FMT
"removing handle(0x%04x), sas_addr"
4322 "(0x%016llx)\n", ioc
->name
, sas_device_backup
.handle
,
4323 (unsigned long long) sas_device_backup
.sas_address
);
4325 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: exit: "
4326 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
, __func__
,
4327 sas_device_backup
.handle
, (unsigned long long)
4328 sas_device_backup
.sas_address
));
4331 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4333 * _scsih_sas_topology_change_event_debug - debug for topology event
4334 * @ioc: per adapter object
4335 * @event_data: event data payload
4339 _scsih_sas_topology_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
4340 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
4346 char *status_str
= NULL
;
4347 u8 link_rate
, prev_link_rate
;
4349 switch (event_data
->ExpStatus
) {
4350 case MPI2_EVENT_SAS_TOPO_ES_ADDED
:
4353 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
:
4354 status_str
= "remove";
4356 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING
:
4358 status_str
= "responding";
4360 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
:
4361 status_str
= "remove delay";
4364 status_str
= "unknown status";
4367 printk(MPT2SAS_INFO_FMT
"sas topology change: (%s)\n",
4368 ioc
->name
, status_str
);
4369 printk(KERN_INFO
"\thandle(0x%04x), enclosure_handle(0x%04x) "
4370 "start_phy(%02d), count(%d)\n",
4371 le16_to_cpu(event_data
->ExpanderDevHandle
),
4372 le16_to_cpu(event_data
->EnclosureHandle
),
4373 event_data
->StartPhyNum
, event_data
->NumEntries
);
4374 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
4375 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
4378 phy_number
= event_data
->StartPhyNum
+ i
;
4379 reason_code
= event_data
->PHY
[i
].PhyStatus
&
4380 MPI2_EVENT_SAS_TOPO_RC_MASK
;
4381 switch (reason_code
) {
4382 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
4383 status_str
= "target add";
4385 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
4386 status_str
= "target remove";
4388 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
:
4389 status_str
= "delay target remove";
4391 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
4392 status_str
= "link rate change";
4394 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE
:
4395 status_str
= "target responding";
4398 status_str
= "unknown";
4401 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
4402 prev_link_rate
= event_data
->PHY
[i
].LinkRate
& 0xF;
4403 printk(KERN_INFO
"\tphy(%02d), attached_handle(0x%04x): %s:"
4404 " link rate: new(0x%02x), old(0x%02x)\n", phy_number
,
4405 handle
, status_str
, link_rate
, prev_link_rate
);
4412 * _scsih_sas_topology_change_event - handle topology changes
4413 * @ioc: per adapter object
4414 * @fw_event: The fw_event_work object
4419 _scsih_sas_topology_change_event(struct MPT2SAS_ADAPTER
*ioc
,
4420 struct fw_event_work
*fw_event
)
4423 u16 parent_handle
, handle
;
4426 struct _sas_node
*sas_expander
;
4427 struct _sas_device
*sas_device
;
4429 unsigned long flags
;
4430 u8 link_rate
, prev_link_rate
;
4431 Mpi2EventDataSasTopologyChangeList_t
*event_data
= fw_event
->event_data
;
4433 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4434 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
4435 _scsih_sas_topology_change_event_debug(ioc
, event_data
);
4438 if (ioc
->shost_recovery
|| ioc
->remove_host
)
4441 if (!ioc
->sas_hba
.num_phys
)
4442 _scsih_sas_host_add(ioc
);
4444 _scsih_sas_host_refresh(ioc
);
4446 if (fw_event
->ignore
) {
4447 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"ignoring expander "
4448 "event\n", ioc
->name
));
4452 parent_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
4454 /* handle expander add */
4455 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_ADDED
)
4456 if (_scsih_expander_add(ioc
, parent_handle
) != 0)
4459 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
4460 sas_expander
= mpt2sas_scsih_expander_find_by_handle(ioc
,
4462 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
4464 sas_address
= sas_expander
->sas_address
;
4465 else if (parent_handle
< ioc
->sas_hba
.num_phys
)
4466 sas_address
= ioc
->sas_hba
.sas_address
;
4470 /* handle siblings events */
4471 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
4472 if (fw_event
->ignore
) {
4473 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"ignoring "
4474 "expander event\n", ioc
->name
));
4477 if (ioc
->shost_recovery
|| ioc
->remove_host
)
4479 phy_number
= event_data
->StartPhyNum
+ i
;
4480 reason_code
= event_data
->PHY
[i
].PhyStatus
&
4481 MPI2_EVENT_SAS_TOPO_RC_MASK
;
4482 if ((event_data
->PHY
[i
].PhyStatus
&
4483 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT
) && (reason_code
!=
4484 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
))
4486 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
4489 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
4490 prev_link_rate
= event_data
->PHY
[i
].LinkRate
& 0xF;
4491 switch (reason_code
) {
4492 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
4494 if (link_rate
== prev_link_rate
)
4497 mpt2sas_transport_update_links(ioc
, sas_address
,
4498 handle
, phy_number
, link_rate
);
4500 if (link_rate
< MPI2_SAS_NEG_LINK_RATE_1_5
)
4503 _scsih_check_device(ioc
, handle
);
4505 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
4507 mpt2sas_transport_update_links(ioc
, sas_address
,
4508 handle
, phy_number
, link_rate
);
4510 _scsih_add_device(ioc
, handle
, phy_number
, 0);
4512 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
4514 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4515 sas_device
= _scsih_sas_device_find_by_handle(ioc
,
4518 spin_unlock_irqrestore(&ioc
->sas_device_lock
,
4522 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4523 _scsih_remove_device(ioc
, sas_device
);
4528 /* handle expander removal */
4529 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
&&
4531 _scsih_expander_remove(ioc
, sas_address
);
4535 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4537 * _scsih_sas_device_status_change_event_debug - debug for device event
4538 * @event_data: event data payload
4544 _scsih_sas_device_status_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
4545 Mpi2EventDataSasDeviceStatusChange_t
*event_data
)
4547 char *reason_str
= NULL
;
4549 switch (event_data
->ReasonCode
) {
4550 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
:
4551 reason_str
= "smart data";
4553 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED
:
4554 reason_str
= "unsupported device discovered";
4556 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
:
4557 reason_str
= "internal device reset";
4559 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL
:
4560 reason_str
= "internal task abort";
4562 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL
:
4563 reason_str
= "internal task abort set";
4565 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL
:
4566 reason_str
= "internal clear task set";
4568 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL
:
4569 reason_str
= "internal query task";
4571 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE
:
4572 reason_str
= "sata init failure";
4574 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
:
4575 reason_str
= "internal device reset complete";
4577 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL
:
4578 reason_str
= "internal task abort complete";
4580 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION
:
4581 reason_str
= "internal async notification";
4583 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY
:
4584 reason_str
= "expander reduced functionality";
4586 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY
:
4587 reason_str
= "expander reduced functionality complete";
4590 reason_str
= "unknown reason";
4593 printk(MPT2SAS_INFO_FMT
"device status change: (%s)\n"
4594 "\thandle(0x%04x), sas address(0x%016llx)", ioc
->name
,
4595 reason_str
, le16_to_cpu(event_data
->DevHandle
),
4596 (unsigned long long)le64_to_cpu(event_data
->SASAddress
));
4597 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
)
4598 printk(MPT2SAS_INFO_FMT
", ASC(0x%x), ASCQ(0x%x)\n", ioc
->name
,
4599 event_data
->ASC
, event_data
->ASCQ
);
4600 printk(KERN_INFO
"\n");
4605 * _scsih_sas_device_status_change_event - handle device status change
4606 * @ioc: per adapter object
4607 * @fw_event: The fw_event_work object
4613 _scsih_sas_device_status_change_event(struct MPT2SAS_ADAPTER
*ioc
,
4614 struct fw_event_work
*fw_event
)
4616 struct MPT2SAS_TARGET
*target_priv_data
;
4617 struct _sas_device
*sas_device
;
4619 unsigned long flags
;
4620 Mpi2EventDataSasDeviceStatusChange_t
*event_data
=
4621 fw_event
->event_data
;
4623 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4624 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
4625 _scsih_sas_device_status_change_event_debug(ioc
,
4629 if (event_data
->ReasonCode
!=
4630 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
&&
4631 event_data
->ReasonCode
!=
4632 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
)
4635 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4636 sas_address
= le64_to_cpu(event_data
->SASAddress
);
4637 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
4639 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4641 if (!sas_device
|| !sas_device
->starget
)
4644 target_priv_data
= sas_device
->starget
->hostdata
;
4645 if (!target_priv_data
)
4648 if (event_data
->ReasonCode
==
4649 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
)
4650 target_priv_data
->tm_busy
= 1;
4652 target_priv_data
->tm_busy
= 0;
4655 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4657 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure event
4658 * @ioc: per adapter object
4659 * @event_data: event data payload
4665 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
4666 Mpi2EventDataSasEnclDevStatusChange_t
*event_data
)
4668 char *reason_str
= NULL
;
4670 switch (event_data
->ReasonCode
) {
4671 case MPI2_EVENT_SAS_ENCL_RC_ADDED
:
4672 reason_str
= "enclosure add";
4674 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING
:
4675 reason_str
= "enclosure remove";
4678 reason_str
= "unknown reason";
4682 printk(MPT2SAS_INFO_FMT
"enclosure status change: (%s)\n"
4683 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
4684 " number slots(%d)\n", ioc
->name
, reason_str
,
4685 le16_to_cpu(event_data
->EnclosureHandle
),
4686 (unsigned long long)le64_to_cpu(event_data
->EnclosureLogicalID
),
4687 le16_to_cpu(event_data
->StartSlot
));
4692 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
4693 * @ioc: per adapter object
4694 * @fw_event: The fw_event_work object
4700 _scsih_sas_enclosure_dev_status_change_event(struct MPT2SAS_ADAPTER
*ioc
,
4701 struct fw_event_work
*fw_event
)
4703 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4704 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
4705 _scsih_sas_enclosure_dev_status_change_event_debug(ioc
,
4706 fw_event
->event_data
);
4711 * _scsih_sas_broadcast_primative_event - handle broadcast events
4712 * @ioc: per adapter object
4713 * @fw_event: The fw_event_work object
4719 _scsih_sas_broadcast_primative_event(struct MPT2SAS_ADAPTER
*ioc
,
4720 struct fw_event_work
*fw_event
)
4722 struct scsi_cmnd
*scmd
;
4725 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
4726 u32 termination_count
;
4728 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
4729 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4730 Mpi2EventDataSasBroadcastPrimitive_t
*event_data
= fw_event
->event_data
;
4733 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"broadcast primative: "
4734 "phy number(%d), width(%d)\n", ioc
->name
, event_data
->PhyNum
,
4735 event_data
->PortWidth
));
4736 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: enter\n", ioc
->name
,
4739 termination_count
= 0;
4741 mpi_reply
= ioc
->tm_cmds
.reply
;
4742 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
4743 scmd
= _scsih_scsi_lookup_get(ioc
, smid
);
4746 sas_device_priv_data
= scmd
->device
->hostdata
;
4747 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
)
4749 /* skip hidden raid components */
4750 if (sas_device_priv_data
->sas_target
->flags
&
4751 MPT_TARGET_FLAGS_RAID_COMPONENT
)
4754 if (sas_device_priv_data
->sas_target
->flags
&
4755 MPT_TARGET_FLAGS_VOLUME
)
4758 handle
= sas_device_priv_data
->sas_target
->handle
;
4759 lun
= sas_device_priv_data
->lun
;
4762 mpt2sas_scsih_issue_tm(ioc
, handle
, 0, 0, lun
,
4763 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK
, smid
, 30, NULL
);
4764 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
4765 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
)
4766 & MPI2_IOCSTATUS_MASK
;
4767 if ((ioc_status
== MPI2_IOCSTATUS_SUCCESS
) &&
4768 (mpi_reply
->ResponseCode
==
4769 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
||
4770 mpi_reply
->ResponseCode
==
4771 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
))
4774 mpt2sas_scsih_issue_tm(ioc
, handle
, 0, 0, lun
,
4775 MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET
, 0, 30, NULL
);
4776 termination_count
+= le32_to_cpu(mpi_reply
->TerminationCount
);
4778 ioc
->broadcast_aen_busy
= 0;
4780 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
4781 "%s - exit, query_count = %d termination_count = %d\n",
4782 ioc
->name
, __func__
, query_count
, termination_count
));
4786 * _scsih_sas_discovery_event - handle discovery events
4787 * @ioc: per adapter object
4788 * @fw_event: The fw_event_work object
4794 _scsih_sas_discovery_event(struct MPT2SAS_ADAPTER
*ioc
,
4795 struct fw_event_work
*fw_event
)
4797 Mpi2EventDataSasDiscovery_t
*event_data
= fw_event
->event_data
;
4799 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4800 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
) {
4801 printk(MPT2SAS_INFO_FMT
"discovery event: (%s)", ioc
->name
,
4802 (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
) ?
4804 if (event_data
->DiscoveryStatus
)
4805 printk("discovery_status(0x%08x)",
4806 le32_to_cpu(event_data
->DiscoveryStatus
));
4811 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
&&
4812 !ioc
->sas_hba
.num_phys
)
4813 _scsih_sas_host_add(ioc
);
4817 * _scsih_reprobe_lun - reprobing lun
4818 * @sdev: scsi device struct
4819 * @no_uld_attach: sdev->no_uld_attach flag setting
4823 _scsih_reprobe_lun(struct scsi_device
*sdev
, void *no_uld_attach
)
4827 sdev
->no_uld_attach
= no_uld_attach
? 1 : 0;
4828 sdev_printk(KERN_INFO
, sdev
, "%s raid component\n",
4829 sdev
->no_uld_attach
? "hidding" : "exposing");
4830 rc
= scsi_device_reprobe(sdev
);
4834 * _scsih_reprobe_target - reprobing target
4835 * @starget: scsi target struct
4836 * @no_uld_attach: sdev->no_uld_attach flag setting
4838 * Note: no_uld_attach flag determines whether the disk device is attached
4839 * to block layer. A value of `1` means to not attach.
4842 _scsih_reprobe_target(struct scsi_target
*starget
, int no_uld_attach
)
4844 struct MPT2SAS_TARGET
*sas_target_priv_data
= starget
->hostdata
;
4847 sas_target_priv_data
->flags
|= MPT_TARGET_FLAGS_RAID_COMPONENT
;
4849 sas_target_priv_data
->flags
&= ~MPT_TARGET_FLAGS_RAID_COMPONENT
;
4851 starget_for_each_device(starget
, no_uld_attach
? (void *)1 : NULL
,
4852 _scsih_reprobe_lun
);
4855 * _scsih_sas_volume_add - add new volume
4856 * @ioc: per adapter object
4857 * @element: IR config element data
4863 _scsih_sas_volume_add(struct MPT2SAS_ADAPTER
*ioc
,
4864 Mpi2EventIrConfigElement_t
*element
)
4866 struct _raid_device
*raid_device
;
4867 unsigned long flags
;
4869 u16 handle
= le16_to_cpu(element
->VolDevHandle
);
4872 mpt2sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
4874 printk(MPT2SAS_ERR_FMT
4875 "failure at %s:%d/%s()!\n", ioc
->name
,
4876 __FILE__
, __LINE__
, __func__
);
4880 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
4881 raid_device
= _scsih_raid_device_find_by_wwid(ioc
, wwid
);
4882 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
4887 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
4889 printk(MPT2SAS_ERR_FMT
4890 "failure at %s:%d/%s()!\n", ioc
->name
,
4891 __FILE__
, __LINE__
, __func__
);
4895 raid_device
->id
= ioc
->sas_id
++;
4896 raid_device
->channel
= RAID_CHANNEL
;
4897 raid_device
->handle
= handle
;
4898 raid_device
->wwid
= wwid
;
4899 _scsih_raid_device_add(ioc
, raid_device
);
4900 if (!ioc
->wait_for_port_enable_to_complete
) {
4901 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
4902 raid_device
->id
, 0);
4904 _scsih_raid_device_remove(ioc
, raid_device
);
4906 _scsih_determine_boot_device(ioc
, raid_device
, 1);
4910 * _scsih_sas_volume_delete - delete volume
4911 * @ioc: per adapter object
4912 * @element: IR config element data
4918 _scsih_sas_volume_delete(struct MPT2SAS_ADAPTER
*ioc
,
4919 Mpi2EventIrConfigElement_t
*element
)
4921 struct _raid_device
*raid_device
;
4922 u16 handle
= le16_to_cpu(element
->VolDevHandle
);
4923 unsigned long flags
;
4924 struct MPT2SAS_TARGET
*sas_target_priv_data
;
4926 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
4927 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
4928 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
4931 if (raid_device
->starget
) {
4932 sas_target_priv_data
= raid_device
->starget
->hostdata
;
4933 sas_target_priv_data
->deleted
= 1;
4934 scsi_remove_target(&raid_device
->starget
->dev
);
4936 _scsih_raid_device_remove(ioc
, raid_device
);
4940 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
4941 * @ioc: per adapter object
4942 * @element: IR config element data
4948 _scsih_sas_pd_expose(struct MPT2SAS_ADAPTER
*ioc
,
4949 Mpi2EventIrConfigElement_t
*element
)
4951 struct _sas_device
*sas_device
;
4952 unsigned long flags
;
4953 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
4955 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4956 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
4957 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4961 /* exposing raid component */
4962 sas_device
->volume_handle
= 0;
4963 sas_device
->volume_wwid
= 0;
4964 sas_device
->hidden_raid_component
= 0;
4965 _scsih_reprobe_target(sas_device
->starget
, 0);
4969 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
4970 * @ioc: per adapter object
4971 * @element: IR config element data
4977 _scsih_sas_pd_hide(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
);
4990 /* hiding raid component */
4991 mpt2sas_config_get_volume_handle(ioc
, handle
,
4992 &sas_device
->volume_handle
);
4993 mpt2sas_config_get_volume_wwid(ioc
, sas_device
->volume_handle
,
4994 &sas_device
->volume_wwid
);
4995 sas_device
->hidden_raid_component
= 1;
4996 _scsih_reprobe_target(sas_device
->starget
, 1);
5000 * _scsih_sas_pd_delete - delete pd component
5001 * @ioc: per adapter object
5002 * @element: IR config element data
5008 _scsih_sas_pd_delete(struct MPT2SAS_ADAPTER
*ioc
,
5009 Mpi2EventIrConfigElement_t
*element
)
5011 struct _sas_device
*sas_device
;
5012 unsigned long flags
;
5013 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
5015 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5016 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
5017 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5020 _scsih_remove_device(ioc
, sas_device
);
5024 * _scsih_sas_pd_add - remove pd component
5025 * @ioc: per adapter object
5026 * @element: IR config element data
5032 _scsih_sas_pd_add(struct MPT2SAS_ADAPTER
*ioc
,
5033 Mpi2EventIrConfigElement_t
*element
)
5035 struct _sas_device
*sas_device
;
5036 unsigned long flags
;
5037 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
5038 Mpi2ConfigReply_t mpi_reply
;
5039 Mpi2SasDevicePage0_t sas_device_pg0
;
5044 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5045 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
5046 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5048 sas_device
->hidden_raid_component
= 1;
5052 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
5053 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
5054 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5055 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5059 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5060 MPI2_IOCSTATUS_MASK
;
5061 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5062 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5063 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5067 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
5068 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
5069 mpt2sas_transport_update_links(ioc
, sas_address
, handle
,
5070 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
5072 _scsih_add_device(ioc
, handle
, 0, 1);
5075 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5077 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
5078 * @ioc: per adapter object
5079 * @event_data: event data payload
5085 _scsih_sas_ir_config_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
5086 Mpi2EventDataIrConfigChangeList_t
*event_data
)
5088 Mpi2EventIrConfigElement_t
*element
;
5091 char *reason_str
= NULL
, *element_str
= NULL
;
5093 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
5095 printk(MPT2SAS_INFO_FMT
"raid config change: (%s), elements(%d)\n",
5096 ioc
->name
, (le32_to_cpu(event_data
->Flags
) &
5097 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ?
5098 "foreign" : "native", event_data
->NumElements
);
5099 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
5100 switch (element
->ReasonCode
) {
5101 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
5104 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
5105 reason_str
= "remove";
5107 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE
:
5108 reason_str
= "no change";
5110 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
5111 reason_str
= "hide";
5113 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
5114 reason_str
= "unhide";
5116 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
5117 reason_str
= "volume_created";
5119 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
5120 reason_str
= "volume_deleted";
5122 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
5123 reason_str
= "pd_created";
5125 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
5126 reason_str
= "pd_deleted";
5129 reason_str
= "unknown reason";
5132 element_type
= le16_to_cpu(element
->ElementFlags
) &
5133 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK
;
5134 switch (element_type
) {
5135 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT
:
5136 element_str
= "volume";
5138 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT
:
5139 element_str
= "phys disk";
5141 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT
:
5142 element_str
= "hot spare";
5145 element_str
= "unknown element";
5148 printk(KERN_INFO
"\t(%s:%s), vol handle(0x%04x), "
5149 "pd handle(0x%04x), pd num(0x%02x)\n", element_str
,
5150 reason_str
, le16_to_cpu(element
->VolDevHandle
),
5151 le16_to_cpu(element
->PhysDiskDevHandle
),
5152 element
->PhysDiskNum
);
5158 * _scsih_sas_ir_config_change_event - handle ir configuration change events
5159 * @ioc: per adapter object
5160 * @fw_event: The fw_event_work object
5166 _scsih_sas_ir_config_change_event(struct MPT2SAS_ADAPTER
*ioc
,
5167 struct fw_event_work
*fw_event
)
5169 Mpi2EventIrConfigElement_t
*element
;
5172 Mpi2EventDataIrConfigChangeList_t
*event_data
= fw_event
->event_data
;
5174 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5175 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5176 _scsih_sas_ir_config_change_event_debug(ioc
, event_data
);
5179 foreign_config
= (le32_to_cpu(event_data
->Flags
) &
5180 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ? 1 : 0;
5182 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
5183 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
5185 switch (element
->ReasonCode
) {
5186 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
5187 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
5188 if (!foreign_config
)
5189 _scsih_sas_volume_add(ioc
, element
);
5191 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
5192 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
5193 if (!foreign_config
)
5194 _scsih_sas_volume_delete(ioc
, element
);
5196 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
5197 _scsih_sas_pd_hide(ioc
, element
);
5199 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
5200 _scsih_sas_pd_expose(ioc
, element
);
5202 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
5203 _scsih_sas_pd_add(ioc
, element
);
5205 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
5206 _scsih_sas_pd_delete(ioc
, element
);
5213 * _scsih_sas_ir_volume_event - IR volume event
5214 * @ioc: per adapter object
5215 * @fw_event: The fw_event_work object
5221 _scsih_sas_ir_volume_event(struct MPT2SAS_ADAPTER
*ioc
,
5222 struct fw_event_work
*fw_event
)
5225 unsigned long flags
;
5226 struct _raid_device
*raid_device
;
5230 struct MPT2SAS_TARGET
*sas_target_priv_data
;
5231 Mpi2EventDataIrVolume_t
*event_data
= fw_event
->event_data
;
5233 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED
)
5236 handle
= le16_to_cpu(event_data
->VolDevHandle
);
5237 state
= le32_to_cpu(event_data
->NewValue
);
5238 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: handle(0x%04x), "
5239 "old(0x%08x), new(0x%08x)\n", ioc
->name
, __func__
, handle
,
5240 le32_to_cpu(event_data
->PreviousValue
), state
));
5242 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5243 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
5244 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5247 case MPI2_RAID_VOL_STATE_MISSING
:
5248 case MPI2_RAID_VOL_STATE_FAILED
:
5251 if (raid_device
->starget
) {
5252 sas_target_priv_data
= raid_device
->starget
->hostdata
;
5253 sas_target_priv_data
->deleted
= 1;
5254 scsi_remove_target(&raid_device
->starget
->dev
);
5256 _scsih_raid_device_remove(ioc
, raid_device
);
5259 case MPI2_RAID_VOL_STATE_ONLINE
:
5260 case MPI2_RAID_VOL_STATE_DEGRADED
:
5261 case MPI2_RAID_VOL_STATE_OPTIMAL
:
5265 mpt2sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
5267 printk(MPT2SAS_ERR_FMT
5268 "failure at %s:%d/%s()!\n", ioc
->name
,
5269 __FILE__
, __LINE__
, __func__
);
5273 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
5275 printk(MPT2SAS_ERR_FMT
5276 "failure at %s:%d/%s()!\n", ioc
->name
,
5277 __FILE__
, __LINE__
, __func__
);
5281 raid_device
->id
= ioc
->sas_id
++;
5282 raid_device
->channel
= RAID_CHANNEL
;
5283 raid_device
->handle
= handle
;
5284 raid_device
->wwid
= wwid
;
5285 _scsih_raid_device_add(ioc
, raid_device
);
5286 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
5287 raid_device
->id
, 0);
5289 _scsih_raid_device_remove(ioc
, raid_device
);
5292 case MPI2_RAID_VOL_STATE_INITIALIZING
:
5299 * _scsih_sas_ir_physical_disk_event - PD event
5300 * @ioc: per adapter object
5301 * @fw_event: The fw_event_work object
5307 _scsih_sas_ir_physical_disk_event(struct MPT2SAS_ADAPTER
*ioc
,
5308 struct fw_event_work
*fw_event
)
5310 u16 handle
, parent_handle
;
5312 struct _sas_device
*sas_device
;
5313 unsigned long flags
;
5314 Mpi2ConfigReply_t mpi_reply
;
5315 Mpi2SasDevicePage0_t sas_device_pg0
;
5317 Mpi2EventDataIrPhysicalDisk_t
*event_data
= fw_event
->event_data
;
5320 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED
)
5323 handle
= le16_to_cpu(event_data
->PhysDiskDevHandle
);
5324 state
= le32_to_cpu(event_data
->NewValue
);
5326 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: handle(0x%04x), "
5327 "old(0x%08x), new(0x%08x)\n", ioc
->name
, __func__
, handle
,
5328 le32_to_cpu(event_data
->PreviousValue
), state
));
5330 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5331 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
5332 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5335 case MPI2_RAID_PD_STATE_ONLINE
:
5336 case MPI2_RAID_PD_STATE_DEGRADED
:
5337 case MPI2_RAID_PD_STATE_REBUILDING
:
5338 case MPI2_RAID_PD_STATE_OPTIMAL
:
5340 sas_device
->hidden_raid_component
= 1;
5344 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
5345 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
5347 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5348 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5352 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5353 MPI2_IOCSTATUS_MASK
;
5354 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5355 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5356 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5360 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
5361 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
5362 mpt2sas_transport_update_links(ioc
, sas_address
, handle
,
5363 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
5365 _scsih_add_device(ioc
, handle
, 0, 1);
5369 case MPI2_RAID_PD_STATE_OFFLINE
:
5370 case MPI2_RAID_PD_STATE_NOT_CONFIGURED
:
5371 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE
:
5372 case MPI2_RAID_PD_STATE_HOT_SPARE
:
5378 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5380 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
5381 * @ioc: per adapter object
5382 * @event_data: event data payload
5388 _scsih_sas_ir_operation_status_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
5389 Mpi2EventDataIrOperationStatus_t
*event_data
)
5391 char *reason_str
= NULL
;
5393 switch (event_data
->RAIDOperation
) {
5394 case MPI2_EVENT_IR_RAIDOP_RESYNC
:
5395 reason_str
= "resync";
5397 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION
:
5398 reason_str
= "online capacity expansion";
5400 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK
:
5401 reason_str
= "consistency check";
5403 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT
:
5404 reason_str
= "background init";
5406 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT
:
5407 reason_str
= "make data consistent";
5414 printk(MPT2SAS_INFO_FMT
"raid operational status: (%s)"
5415 "\thandle(0x%04x), percent complete(%d)\n",
5416 ioc
->name
, reason_str
,
5417 le16_to_cpu(event_data
->VolDevHandle
),
5418 event_data
->PercentComplete
);
5423 * _scsih_sas_ir_operation_status_event - handle RAID operation events
5424 * @ioc: per adapter object
5425 * @fw_event: The fw_event_work object
5431 _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER
*ioc
,
5432 struct fw_event_work
*fw_event
)
5434 Mpi2EventDataIrOperationStatus_t
*event_data
= fw_event
->event_data
;
5435 static struct _raid_device
*raid_device
;
5436 unsigned long flags
;
5439 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5440 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5441 _scsih_sas_ir_operation_status_event_debug(ioc
,
5445 /* code added for raid transport support */
5446 if (event_data
->RAIDOperation
== MPI2_EVENT_IR_RAIDOP_RESYNC
) {
5448 handle
= le16_to_cpu(event_data
->VolDevHandle
);
5450 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5451 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
5452 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5457 if (event_data
->RAIDOperation
== MPI2_EVENT_IR_RAIDOP_RESYNC
)
5458 raid_device
->percent_complete
=
5459 event_data
->PercentComplete
;
5464 * _scsih_task_set_full - handle task set full
5465 * @ioc: per adapter object
5466 * @fw_event: The fw_event_work object
5469 * Throttle back qdepth.
5472 _scsih_task_set_full(struct MPT2SAS_ADAPTER
*ioc
, struct fw_event_work
5475 unsigned long flags
;
5476 struct _sas_device
*sas_device
;
5477 static struct _raid_device
*raid_device
;
5478 struct scsi_device
*sdev
;
5484 Mpi2EventDataTaskSetFull_t
*event_data
= fw_event
->event_data
;
5486 current_depth
= le16_to_cpu(event_data
->CurrentDepth
);
5487 handle
= le16_to_cpu(event_data
->DevHandle
);
5488 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5489 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
5491 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5494 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5495 id
= sas_device
->id
;
5496 channel
= sas_device
->channel
;
5497 sas_address
= sas_device
->sas_address
;
5499 /* if hidden raid component, then change to volume characteristics */
5500 if (sas_device
->hidden_raid_component
&& sas_device
->volume_handle
) {
5501 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5502 raid_device
= _scsih_raid_device_find_by_handle(
5503 ioc
, sas_device
->volume_handle
);
5504 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5506 id
= raid_device
->id
;
5507 channel
= raid_device
->channel
;
5508 handle
= raid_device
->handle
;
5509 sas_address
= raid_device
->wwid
;
5513 if (ioc
->logging_level
& MPT_DEBUG_TASK_SET_FULL
)
5514 starget_printk(KERN_INFO
, sas_device
->starget
, "task set "
5515 "full: handle(0x%04x), sas_addr(0x%016llx), depth(%d)\n",
5516 handle
, (unsigned long long)sas_address
, current_depth
);
5518 shost_for_each_device(sdev
, ioc
->shost
) {
5519 if (sdev
->id
== id
&& sdev
->channel
== channel
) {
5520 if (current_depth
> sdev
->queue_depth
) {
5521 if (ioc
->logging_level
&
5522 MPT_DEBUG_TASK_SET_FULL
)
5523 sdev_printk(KERN_INFO
, sdev
, "strange "
5524 "observation, the queue depth is"
5525 " (%d) meanwhile fw queue depth "
5526 "is (%d)\n", sdev
->queue_depth
,
5530 depth
= scsi_track_queue_full(sdev
,
5533 sdev_printk(KERN_INFO
, sdev
, "Queue depth "
5534 "reduced to (%d)\n", depth
);
5536 sdev_printk(KERN_INFO
, sdev
, "Tagged Command "
5537 "Queueing is being disabled\n");
5538 else if (depth
== 0)
5539 if (ioc
->logging_level
&
5540 MPT_DEBUG_TASK_SET_FULL
)
5541 sdev_printk(KERN_INFO
, sdev
,
5542 "Queue depth not changed yet\n");
5548 * _scsih_prep_device_scan - initialize parameters prior to device scan
5549 * @ioc: per adapter object
5551 * Set the deleted flag prior to device scan. If the device is found during
5552 * the scan, then we clear the deleted flag.
5555 _scsih_prep_device_scan(struct MPT2SAS_ADAPTER
*ioc
)
5557 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
5558 struct scsi_device
*sdev
;
5560 shost_for_each_device(sdev
, ioc
->shost
) {
5561 sas_device_priv_data
= sdev
->hostdata
;
5562 if (sas_device_priv_data
&& sas_device_priv_data
->sas_target
)
5563 sas_device_priv_data
->sas_target
->deleted
= 1;
5568 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
5569 * @ioc: per adapter object
5570 * @sas_address: sas address
5571 * @slot: enclosure slot id
5572 * @handle: device handle
5574 * After host reset, find out whether devices are still responding.
5575 * Used in _scsi_remove_unresponsive_sas_devices.
5580 _scsih_mark_responding_sas_device(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
,
5581 u16 slot
, u16 handle
)
5583 struct MPT2SAS_TARGET
*sas_target_priv_data
;
5584 struct scsi_target
*starget
;
5585 struct _sas_device
*sas_device
;
5586 unsigned long flags
;
5588 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5589 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
) {
5590 if (sas_device
->sas_address
== sas_address
&&
5591 sas_device
->slot
== slot
&& sas_device
->starget
) {
5592 sas_device
->responding
= 1;
5593 starget
= sas_device
->starget
;
5594 if (starget
&& starget
->hostdata
) {
5595 sas_target_priv_data
= starget
->hostdata
;
5596 sas_target_priv_data
->tm_busy
= 0;
5597 sas_target_priv_data
->deleted
= 0;
5599 sas_target_priv_data
= NULL
;
5600 starget_printk(KERN_INFO
, sas_device
->starget
,
5601 "handle(0x%04x), sas_addr(0x%016llx), enclosure "
5602 "logical id(0x%016llx), slot(%d)\n", handle
,
5603 (unsigned long long)sas_device
->sas_address
,
5604 (unsigned long long)
5605 sas_device
->enclosure_logical_id
,
5607 if (sas_device
->handle
== handle
)
5609 printk(KERN_INFO
"\thandle changed from(0x%04x)!!!\n",
5610 sas_device
->handle
);
5611 sas_device
->handle
= handle
;
5612 if (sas_target_priv_data
)
5613 sas_target_priv_data
->handle
= handle
;
5618 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5622 * _scsih_search_responding_sas_devices -
5623 * @ioc: per adapter object
5625 * After host reset, find out whether devices are still responding.
5631 _scsih_search_responding_sas_devices(struct MPT2SAS_ADAPTER
*ioc
)
5633 Mpi2SasDevicePage0_t sas_device_pg0
;
5634 Mpi2ConfigReply_t mpi_reply
;
5641 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
, __func__
);
5643 if (list_empty(&ioc
->sas_device_list
))
5647 while (!(mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
5648 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
,
5650 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5651 MPI2_IOCSTATUS_MASK
;
5652 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
5654 handle
= le16_to_cpu(sas_device_pg0
.DevHandle
);
5655 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
5656 if (!(_scsih_is_end_device(device_info
)))
5658 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
5659 slot
= le16_to_cpu(sas_device_pg0
.Slot
);
5660 _scsih_mark_responding_sas_device(ioc
, sas_address
, slot
,
5666 * _scsih_mark_responding_raid_device - mark a raid_device as responding
5667 * @ioc: per adapter object
5668 * @wwid: world wide identifier for raid volume
5669 * @handle: device handle
5671 * After host reset, find out whether devices are still responding.
5672 * Used in _scsi_remove_unresponsive_raid_devices.
5677 _scsih_mark_responding_raid_device(struct MPT2SAS_ADAPTER
*ioc
, u64 wwid
,
5680 struct MPT2SAS_TARGET
*sas_target_priv_data
;
5681 struct scsi_target
*starget
;
5682 struct _raid_device
*raid_device
;
5683 unsigned long flags
;
5685 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5686 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
5687 if (raid_device
->wwid
== wwid
&& raid_device
->starget
) {
5688 starget
= raid_device
->starget
;
5689 if (starget
&& starget
->hostdata
) {
5690 sas_target_priv_data
= starget
->hostdata
;
5691 sas_target_priv_data
->deleted
= 0;
5693 sas_target_priv_data
= NULL
;
5694 raid_device
->responding
= 1;
5695 starget_printk(KERN_INFO
, raid_device
->starget
,
5696 "handle(0x%04x), wwid(0x%016llx)\n", handle
,
5697 (unsigned long long)raid_device
->wwid
);
5698 if (raid_device
->handle
== handle
)
5700 printk(KERN_INFO
"\thandle changed from(0x%04x)!!!\n",
5701 raid_device
->handle
);
5702 raid_device
->handle
= handle
;
5703 if (sas_target_priv_data
)
5704 sas_target_priv_data
->handle
= handle
;
5709 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5713 * _scsih_search_responding_raid_devices -
5714 * @ioc: per adapter object
5716 * After host reset, find out whether devices are still responding.
5722 _scsih_search_responding_raid_devices(struct MPT2SAS_ADAPTER
*ioc
)
5724 Mpi2RaidVolPage1_t volume_pg1
;
5725 Mpi2ConfigReply_t mpi_reply
;
5729 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
, __func__
);
5731 if (list_empty(&ioc
->raid_device_list
))
5735 while (!(mpt2sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
5736 &volume_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
5737 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5738 MPI2_IOCSTATUS_MASK
;
5739 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
5741 handle
= le16_to_cpu(volume_pg1
.DevHandle
);
5742 _scsih_mark_responding_raid_device(ioc
,
5743 le64_to_cpu(volume_pg1
.WWID
), handle
);
5748 * _scsih_mark_responding_expander - mark a expander as responding
5749 * @ioc: per adapter object
5750 * @sas_address: sas address
5753 * After host reset, find out whether devices are still responding.
5754 * Used in _scsi_remove_unresponsive_expanders.
5759 _scsih_mark_responding_expander(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
,
5762 struct _sas_node
*sas_expander
;
5763 unsigned long flags
;
5766 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5767 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
5768 if (sas_expander
->sas_address
!= sas_address
)
5770 sas_expander
->responding
= 1;
5771 if (sas_expander
->handle
== handle
)
5773 printk(KERN_INFO
"\texpander(0x%016llx): handle changed"
5774 " from(0x%04x) to (0x%04x)!!!\n",
5775 (unsigned long long)sas_expander
->sas_address
,
5776 sas_expander
->handle
, handle
);
5777 sas_expander
->handle
= handle
;
5778 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++)
5779 sas_expander
->phy
[i
].handle
= handle
;
5783 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5787 * _scsih_search_responding_expanders -
5788 * @ioc: per adapter object
5790 * After host reset, find out whether devices are still responding.
5796 _scsih_search_responding_expanders(struct MPT2SAS_ADAPTER
*ioc
)
5798 Mpi2ExpanderPage0_t expander_pg0
;
5799 Mpi2ConfigReply_t mpi_reply
;
5804 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
, __func__
);
5806 if (list_empty(&ioc
->sas_expander_list
))
5810 while (!(mpt2sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
5811 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL
, handle
))) {
5813 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5814 MPI2_IOCSTATUS_MASK
;
5815 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
5818 handle
= le16_to_cpu(expander_pg0
.DevHandle
);
5819 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
5820 printk(KERN_INFO
"\texpander present: handle(0x%04x), "
5821 "sas_addr(0x%016llx)\n", handle
,
5822 (unsigned long long)sas_address
);
5823 _scsih_mark_responding_expander(ioc
, sas_address
, handle
);
5829 * _scsih_remove_unresponding_sas_devices - removing unresponding devices
5830 * @ioc: per adapter object
5835 _scsih_remove_unresponding_sas_devices(struct MPT2SAS_ADAPTER
*ioc
)
5837 struct _sas_device
*sas_device
, *sas_device_next
;
5838 struct _sas_node
*sas_expander
;
5839 struct _raid_device
*raid_device
, *raid_device_next
;
5842 list_for_each_entry_safe(sas_device
, sas_device_next
,
5843 &ioc
->sas_device_list
, list
) {
5844 if (sas_device
->responding
) {
5845 sas_device
->responding
= 0;
5848 if (sas_device
->starget
)
5849 starget_printk(KERN_INFO
, sas_device
->starget
,
5850 "removing: handle(0x%04x), sas_addr(0x%016llx), "
5851 "enclosure logical id(0x%016llx), slot(%d)\n",
5853 (unsigned long long)sas_device
->sas_address
,
5854 (unsigned long long)
5855 sas_device
->enclosure_logical_id
,
5857 _scsih_remove_device(ioc
, sas_device
);
5860 list_for_each_entry_safe(raid_device
, raid_device_next
,
5861 &ioc
->raid_device_list
, list
) {
5862 if (raid_device
->responding
) {
5863 raid_device
->responding
= 0;
5866 if (raid_device
->starget
) {
5867 starget_printk(KERN_INFO
, raid_device
->starget
,
5868 "removing: handle(0x%04x), wwid(0x%016llx)\n",
5869 raid_device
->handle
,
5870 (unsigned long long)raid_device
->wwid
);
5871 scsi_remove_target(&raid_device
->starget
->dev
);
5873 _scsih_raid_device_remove(ioc
, raid_device
);
5876 retry_expander_search
:
5877 sas_expander
= NULL
;
5878 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
5879 if (sas_expander
->responding
) {
5880 sas_expander
->responding
= 0;
5883 _scsih_expander_remove(ioc
, sas_expander
->sas_address
);
5884 goto retry_expander_search
;
5889 * mpt2sas_scsih_reset_handler - reset callback handler (for scsih)
5890 * @ioc: per adapter object
5891 * @reset_phase: phase
5893 * The handler for doing any required cleanup or initialization.
5895 * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
5896 * MPT2_IOC_DONE_RESET
5901 mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER
*ioc
, int reset_phase
)
5903 switch (reset_phase
) {
5904 case MPT2_IOC_PRE_RESET
:
5905 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: "
5906 "MPT2_IOC_PRE_RESET\n", ioc
->name
, __func__
));
5908 case MPT2_IOC_AFTER_RESET
:
5909 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: "
5910 "MPT2_IOC_AFTER_RESET\n", ioc
->name
, __func__
));
5911 if (ioc
->scsih_cmds
.status
& MPT2_CMD_PENDING
) {
5912 ioc
->scsih_cmds
.status
|= MPT2_CMD_RESET
;
5913 mpt2sas_base_free_smid(ioc
, ioc
->scsih_cmds
.smid
);
5914 complete(&ioc
->scsih_cmds
.done
);
5916 if (ioc
->tm_cmds
.status
& MPT2_CMD_PENDING
) {
5917 ioc
->tm_cmds
.status
|= MPT2_CMD_RESET
;
5918 mpt2sas_base_free_smid(ioc
, ioc
->tm_cmds
.smid
);
5919 complete(&ioc
->tm_cmds
.done
);
5921 _scsih_fw_event_cleanup_queue(ioc
);
5922 _scsih_flush_running_cmds(ioc
);
5923 _scsih_queue_rescan(ioc
);
5925 case MPT2_IOC_DONE_RESET
:
5926 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: "
5927 "MPT2_IOC_DONE_RESET\n", ioc
->name
, __func__
));
5928 _scsih_sas_host_refresh(ioc
);
5929 _scsih_prep_device_scan(ioc
);
5930 _scsih_search_responding_sas_devices(ioc
);
5931 _scsih_search_responding_raid_devices(ioc
);
5932 _scsih_search_responding_expanders(ioc
);
5938 * _firmware_event_work - delayed task for processing firmware events
5939 * @ioc: per adapter object
5940 * @work: equal to the fw_event_work object
5946 _firmware_event_work(struct work_struct
*work
)
5948 struct fw_event_work
*fw_event
= container_of(work
,
5949 struct fw_event_work
, delayed_work
.work
);
5950 unsigned long flags
;
5951 struct MPT2SAS_ADAPTER
*ioc
= fw_event
->ioc
;
5953 /* the queue is being flushed so ignore this event */
5954 if (ioc
->remove_host
|| fw_event
->cancel_pending_work
) {
5955 _scsih_fw_event_free(ioc
, fw_event
);
5959 if (fw_event
->event
== MPT2SAS_RESCAN_AFTER_HOST_RESET
) {
5960 _scsih_fw_event_free(ioc
, fw_event
);
5961 spin_lock_irqsave(&ioc
->ioc_reset_in_progress_lock
, flags
);
5962 if (ioc
->shost_recovery
) {
5963 init_completion(&ioc
->shost_recovery_done
);
5964 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
,
5966 wait_for_completion(&ioc
->shost_recovery_done
);
5968 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
,
5970 _scsih_remove_unresponding_sas_devices(ioc
);
5974 switch (fw_event
->event
) {
5975 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
5976 _scsih_sas_topology_change_event(ioc
, fw_event
);
5978 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
5979 _scsih_sas_device_status_change_event(ioc
,
5982 case MPI2_EVENT_SAS_DISCOVERY
:
5983 _scsih_sas_discovery_event(ioc
,
5986 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
5987 _scsih_sas_broadcast_primative_event(ioc
,
5990 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
5991 _scsih_sas_enclosure_dev_status_change_event(ioc
,
5994 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
5995 _scsih_sas_ir_config_change_event(ioc
, fw_event
);
5997 case MPI2_EVENT_IR_VOLUME
:
5998 _scsih_sas_ir_volume_event(ioc
, fw_event
);
6000 case MPI2_EVENT_IR_PHYSICAL_DISK
:
6001 _scsih_sas_ir_physical_disk_event(ioc
, fw_event
);
6003 case MPI2_EVENT_IR_OPERATION_STATUS
:
6004 _scsih_sas_ir_operation_status_event(ioc
, fw_event
);
6006 case MPI2_EVENT_TASK_SET_FULL
:
6007 _scsih_task_set_full(ioc
, fw_event
);
6010 _scsih_fw_event_free(ioc
, fw_event
);
6014 * mpt2sas_scsih_event_callback - firmware event handler (called at ISR time)
6015 * @ioc: per adapter object
6016 * @msix_index: MSIX table index supplied by the OS
6017 * @reply: reply message frame(lower 32bit addr)
6018 * Context: interrupt.
6020 * This function merely adds a new work task into ioc->firmware_event_thread.
6021 * The tasks are worked from _firmware_event_work in user context.
6023 * Return 1 meaning mf should be freed from _base_interrupt
6024 * 0 means the mf is freed from this function.
6027 mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER
*ioc
, u8 msix_index
,
6030 struct fw_event_work
*fw_event
;
6031 Mpi2EventNotificationReply_t
*mpi_reply
;
6035 /* events turned off due to host reset or driver unloading */
6036 if (ioc
->remove_host
)
6039 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
6040 event
= le16_to_cpu(mpi_reply
->Event
);
6044 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
6046 Mpi2EventDataSasBroadcastPrimitive_t
*baen_data
=
6047 (Mpi2EventDataSasBroadcastPrimitive_t
*)
6048 mpi_reply
->EventData
;
6050 if (baen_data
->Primitive
!=
6051 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT
||
6052 ioc
->broadcast_aen_busy
)
6054 ioc
->broadcast_aen_busy
= 1;
6058 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
6059 _scsih_check_topo_delete_events(ioc
,
6060 (Mpi2EventDataSasTopologyChangeList_t
*)
6061 mpi_reply
->EventData
);
6064 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
6065 case MPI2_EVENT_IR_OPERATION_STATUS
:
6066 case MPI2_EVENT_SAS_DISCOVERY
:
6067 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
6068 case MPI2_EVENT_IR_VOLUME
:
6069 case MPI2_EVENT_IR_PHYSICAL_DISK
:
6070 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
6071 case MPI2_EVENT_TASK_SET_FULL
:
6074 default: /* ignore the rest */
6078 fw_event
= kzalloc(sizeof(struct fw_event_work
), GFP_ATOMIC
);
6080 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6081 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6084 sz
= le16_to_cpu(mpi_reply
->EventDataLength
) * 4;
6085 fw_event
->event_data
= kzalloc(sz
, GFP_ATOMIC
);
6086 if (!fw_event
->event_data
) {
6087 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6088 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6093 memcpy(fw_event
->event_data
, mpi_reply
->EventData
,
6095 fw_event
->ioc
= ioc
;
6096 fw_event
->VF_ID
= mpi_reply
->VF_ID
;
6097 fw_event
->VP_ID
= mpi_reply
->VP_ID
;
6098 fw_event
->event
= event
;
6099 _scsih_fw_event_add(ioc
, fw_event
);
6103 /* shost template */
6104 static struct scsi_host_template scsih_driver_template
= {
6105 .module
= THIS_MODULE
,
6106 .name
= "Fusion MPT SAS Host",
6107 .proc_name
= MPT2SAS_DRIVER_NAME
,
6108 .queuecommand
= _scsih_qcmd
,
6109 .target_alloc
= _scsih_target_alloc
,
6110 .slave_alloc
= _scsih_slave_alloc
,
6111 .slave_configure
= _scsih_slave_configure
,
6112 .target_destroy
= _scsih_target_destroy
,
6113 .slave_destroy
= _scsih_slave_destroy
,
6114 .change_queue_depth
= _scsih_change_queue_depth
,
6115 .change_queue_type
= _scsih_change_queue_type
,
6116 .eh_abort_handler
= _scsih_abort
,
6117 .eh_device_reset_handler
= _scsih_dev_reset
,
6118 .eh_target_reset_handler
= _scsih_target_reset
,
6119 .eh_host_reset_handler
= _scsih_host_reset
,
6120 .bios_param
= _scsih_bios_param
,
6123 .sg_tablesize
= MPT2SAS_SG_DEPTH
,
6124 .max_sectors
= 8192,
6126 .use_clustering
= ENABLE_CLUSTERING
,
6127 .shost_attrs
= mpt2sas_host_attrs
,
6128 .sdev_attrs
= mpt2sas_dev_attrs
,
6132 * _scsih_expander_node_remove - removing expander device from list.
6133 * @ioc: per adapter object
6134 * @sas_expander: the sas_device object
6135 * Context: Calling function should acquire ioc->sas_node_lock.
6137 * Removing object and freeing associated memory from the
6138 * ioc->sas_expander_list.
6143 _scsih_expander_node_remove(struct MPT2SAS_ADAPTER
*ioc
,
6144 struct _sas_node
*sas_expander
)
6146 struct _sas_port
*mpt2sas_port
;
6147 struct _sas_device
*sas_device
;
6148 struct _sas_node
*expander_sibling
;
6149 unsigned long flags
;
6154 /* remove sibling ports attached to this expander */
6155 retry_device_search
:
6156 list_for_each_entry(mpt2sas_port
,
6157 &sas_expander
->sas_port_list
, port_list
) {
6158 if (mpt2sas_port
->remote_identify
.device_type
==
6160 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6162 mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
6163 mpt2sas_port
->remote_identify
.sas_address
);
6164 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6167 _scsih_remove_device(ioc
, sas_device
);
6168 if (ioc
->shost_recovery
)
6170 goto retry_device_search
;
6174 retry_expander_search
:
6175 list_for_each_entry(mpt2sas_port
,
6176 &sas_expander
->sas_port_list
, port_list
) {
6178 if (mpt2sas_port
->remote_identify
.device_type
==
6179 MPI2_SAS_DEVICE_INFO_EDGE_EXPANDER
||
6180 mpt2sas_port
->remote_identify
.device_type
==
6181 MPI2_SAS_DEVICE_INFO_FANOUT_EXPANDER
) {
6183 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
6185 mpt2sas_scsih_expander_find_by_sas_address(
6186 ioc
, mpt2sas_port
->remote_identify
.sas_address
);
6187 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
6188 if (!expander_sibling
)
6190 _scsih_expander_remove(ioc
,
6191 expander_sibling
->sas_address
);
6192 if (ioc
->shost_recovery
)
6194 goto retry_expander_search
;
6198 mpt2sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
6199 sas_expander
->sas_address_parent
);
6201 printk(MPT2SAS_INFO_FMT
"expander_remove: handle"
6202 "(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
6203 sas_expander
->handle
, (unsigned long long)
6204 sas_expander
->sas_address
);
6206 list_del(&sas_expander
->list
);
6207 kfree(sas_expander
->phy
);
6208 kfree(sas_expander
);
6212 * _scsih_ir_shutdown - IR shutdown notification
6213 * @ioc: per adapter object
6215 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
6216 * the host system is shutting down.
6221 _scsih_ir_shutdown(struct MPT2SAS_ADAPTER
*ioc
)
6223 Mpi2RaidActionRequest_t
*mpi_request
;
6224 Mpi2RaidActionReply_t
*mpi_reply
;
6227 /* is IR firmware build loaded ? */
6228 if (!ioc
->ir_firmware
)
6231 /* are there any volumes ? */
6232 if (list_empty(&ioc
->raid_device_list
))
6235 mutex_lock(&ioc
->scsih_cmds
.mutex
);
6237 if (ioc
->scsih_cmds
.status
!= MPT2_CMD_NOT_USED
) {
6238 printk(MPT2SAS_ERR_FMT
"%s: scsih_cmd in use\n",
6239 ioc
->name
, __func__
);
6242 ioc
->scsih_cmds
.status
= MPT2_CMD_PENDING
;
6244 smid
= mpt2sas_base_get_smid(ioc
, ioc
->scsih_cb_idx
);
6246 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
6247 ioc
->name
, __func__
);
6248 ioc
->scsih_cmds
.status
= MPT2_CMD_NOT_USED
;
6252 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
6253 ioc
->scsih_cmds
.smid
= smid
;
6254 memset(mpi_request
, 0, sizeof(Mpi2RaidActionRequest_t
));
6256 mpi_request
->Function
= MPI2_FUNCTION_RAID_ACTION
;
6257 mpi_request
->Action
= MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED
;
6259 printk(MPT2SAS_INFO_FMT
"IR shutdown (sending)\n", ioc
->name
);
6260 init_completion(&ioc
->scsih_cmds
.done
);
6261 mpt2sas_base_put_smid_default(ioc
, smid
);
6262 wait_for_completion_timeout(&ioc
->scsih_cmds
.done
, 10*HZ
);
6264 if (!(ioc
->scsih_cmds
.status
& MPT2_CMD_COMPLETE
)) {
6265 printk(MPT2SAS_ERR_FMT
"%s: timeout\n",
6266 ioc
->name
, __func__
);
6270 if (ioc
->scsih_cmds
.status
& MPT2_CMD_REPLY_VALID
) {
6271 mpi_reply
= ioc
->scsih_cmds
.reply
;
6273 printk(MPT2SAS_INFO_FMT
"IR shutdown (complete): "
6274 "ioc_status(0x%04x), loginfo(0x%08x)\n",
6275 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
6276 le32_to_cpu(mpi_reply
->IOCLogInfo
));
6280 ioc
->scsih_cmds
.status
= MPT2_CMD_NOT_USED
;
6281 mutex_unlock(&ioc
->scsih_cmds
.mutex
);
6285 * _scsih_shutdown - routine call during system shutdown
6286 * @pdev: PCI device struct
6291 _scsih_shutdown(struct pci_dev
*pdev
)
6293 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6294 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
6295 struct workqueue_struct
*wq
;
6296 unsigned long flags
;
6298 ioc
->remove_host
= 1;
6299 _scsih_fw_event_cleanup_queue(ioc
);
6301 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
6302 wq
= ioc
->firmware_event_thread
;
6303 ioc
->firmware_event_thread
= NULL
;
6304 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
6306 destroy_workqueue(wq
);
6308 _scsih_ir_shutdown(ioc
);
6309 mpt2sas_base_detach(ioc
);
6313 * _scsih_remove - detach and remove add host
6314 * @pdev: PCI device struct
6316 * Routine called when unloading the driver.
6319 static void __devexit
6320 _scsih_remove(struct pci_dev
*pdev
)
6322 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6323 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
6324 struct _sas_port
*mpt2sas_port
;
6325 struct _sas_device
*sas_device
;
6326 struct _sas_node
*expander_sibling
;
6327 struct _raid_device
*raid_device
, *next
;
6328 struct MPT2SAS_TARGET
*sas_target_priv_data
;
6329 struct workqueue_struct
*wq
;
6330 unsigned long flags
;
6332 ioc
->remove_host
= 1;
6333 _scsih_fw_event_cleanup_queue(ioc
);
6335 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
6336 wq
= ioc
->firmware_event_thread
;
6337 ioc
->firmware_event_thread
= NULL
;
6338 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
6340 destroy_workqueue(wq
);
6342 /* release all the volumes */
6343 list_for_each_entry_safe(raid_device
, next
, &ioc
->raid_device_list
,
6345 if (raid_device
->starget
) {
6346 sas_target_priv_data
=
6347 raid_device
->starget
->hostdata
;
6348 sas_target_priv_data
->deleted
= 1;
6349 scsi_remove_target(&raid_device
->starget
->dev
);
6351 printk(MPT2SAS_INFO_FMT
"removing handle(0x%04x), wwid"
6352 "(0x%016llx)\n", ioc
->name
, raid_device
->handle
,
6353 (unsigned long long) raid_device
->wwid
);
6354 _scsih_raid_device_remove(ioc
, raid_device
);
6357 /* free ports attached to the sas_host */
6359 list_for_each_entry(mpt2sas_port
,
6360 &ioc
->sas_hba
.sas_port_list
, port_list
) {
6361 if (mpt2sas_port
->remote_identify
.device_type
==
6364 mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
6365 mpt2sas_port
->remote_identify
.sas_address
);
6367 _scsih_remove_device(ioc
, sas_device
);
6372 mpt2sas_scsih_expander_find_by_sas_address(ioc
,
6373 mpt2sas_port
->remote_identify
.sas_address
);
6374 if (expander_sibling
) {
6375 _scsih_expander_remove(ioc
,
6376 expander_sibling
->sas_address
);
6382 /* free phys attached to the sas_host */
6383 if (ioc
->sas_hba
.num_phys
) {
6384 kfree(ioc
->sas_hba
.phy
);
6385 ioc
->sas_hba
.phy
= NULL
;
6386 ioc
->sas_hba
.num_phys
= 0;
6389 sas_remove_host(shost
);
6390 _scsih_shutdown(pdev
);
6391 list_del(&ioc
->list
);
6392 scsi_remove_host(shost
);
6393 scsi_host_put(shost
);
6397 * _scsih_probe_boot_devices - reports 1st device
6398 * @ioc: per adapter object
6400 * If specified in bios page 2, this routine reports the 1st
6401 * device scsi-ml or sas transport for persistent boot device
6402 * purposes. Please refer to function _scsih_determine_boot_device()
6405 _scsih_probe_boot_devices(struct MPT2SAS_ADAPTER
*ioc
)
6409 struct _sas_device
*sas_device
;
6410 struct _raid_device
*raid_device
;
6412 u64 sas_address_parent
;
6414 unsigned long flags
;
6418 if (ioc
->req_boot_device
.device
) {
6419 device
= ioc
->req_boot_device
.device
;
6420 is_raid
= ioc
->req_boot_device
.is_raid
;
6421 } else if (ioc
->req_alt_boot_device
.device
) {
6422 device
= ioc
->req_alt_boot_device
.device
;
6423 is_raid
= ioc
->req_alt_boot_device
.is_raid
;
6424 } else if (ioc
->current_boot_device
.device
) {
6425 device
= ioc
->current_boot_device
.device
;
6426 is_raid
= ioc
->current_boot_device
.is_raid
;
6433 raid_device
= device
;
6434 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
6435 raid_device
->id
, 0);
6437 _scsih_raid_device_remove(ioc
, raid_device
);
6439 sas_device
= device
;
6440 handle
= sas_device
->handle
;
6441 sas_address_parent
= sas_device
->sas_address_parent
;
6442 sas_address
= sas_device
->sas_address
;
6443 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6444 list_move_tail(&sas_device
->list
, &ioc
->sas_device_list
);
6445 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6446 if (!mpt2sas_transport_port_add(ioc
, sas_device
->handle
,
6447 sas_device
->sas_address_parent
)) {
6448 _scsih_sas_device_remove(ioc
, sas_device
);
6449 } else if (!sas_device
->starget
) {
6450 mpt2sas_transport_port_remove(ioc
, sas_address
,
6451 sas_address_parent
);
6452 _scsih_sas_device_remove(ioc
, sas_device
);
6458 * _scsih_probe_raid - reporting raid volumes to scsi-ml
6459 * @ioc: per adapter object
6461 * Called during initial loading of the driver.
6464 _scsih_probe_raid(struct MPT2SAS_ADAPTER
*ioc
)
6466 struct _raid_device
*raid_device
, *raid_next
;
6469 list_for_each_entry_safe(raid_device
, raid_next
,
6470 &ioc
->raid_device_list
, list
) {
6471 if (raid_device
->starget
)
6473 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
6474 raid_device
->id
, 0);
6476 _scsih_raid_device_remove(ioc
, raid_device
);
6481 * _scsih_probe_sas - reporting sas devices to sas transport
6482 * @ioc: per adapter object
6484 * Called during initial loading of the driver.
6487 _scsih_probe_sas(struct MPT2SAS_ADAPTER
*ioc
)
6489 struct _sas_device
*sas_device
, *next
;
6490 unsigned long flags
;
6492 /* SAS Device List */
6493 list_for_each_entry_safe(sas_device
, next
, &ioc
->sas_device_init_list
,
6495 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6496 list_move_tail(&sas_device
->list
, &ioc
->sas_device_list
);
6497 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6499 if (!mpt2sas_transport_port_add(ioc
, sas_device
->handle
,
6500 sas_device
->sas_address_parent
)) {
6501 _scsih_sas_device_remove(ioc
, sas_device
);
6502 } else if (!sas_device
->starget
) {
6503 mpt2sas_transport_port_remove(ioc
,
6504 sas_device
->sas_address
,
6505 sas_device
->sas_address_parent
);
6506 _scsih_sas_device_remove(ioc
, sas_device
);
6512 * _scsih_probe_devices - probing for devices
6513 * @ioc: per adapter object
6515 * Called during initial loading of the driver.
6518 _scsih_probe_devices(struct MPT2SAS_ADAPTER
*ioc
)
6520 u16 volume_mapping_flags
=
6521 le16_to_cpu(ioc
->ioc_pg8
.IRVolumeMappingFlags
) &
6522 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE
;
6524 if (!(ioc
->facts
.ProtocolFlags
& MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR
))
6525 return; /* return when IOC doesn't support initiator mode */
6527 _scsih_probe_boot_devices(ioc
);
6529 if (ioc
->ir_firmware
) {
6530 if ((volume_mapping_flags
&
6531 MPI2_IOCPAGE8_IRFLAGS_HIGH_VOLUME_MAPPING
)) {
6532 _scsih_probe_sas(ioc
);
6533 _scsih_probe_raid(ioc
);
6535 _scsih_probe_raid(ioc
);
6536 _scsih_probe_sas(ioc
);
6539 _scsih_probe_sas(ioc
);
6543 * _scsih_probe - attach and add scsi host
6544 * @pdev: PCI device struct
6545 * @id: pci device id
6547 * Returns 0 success, anything else error.
6550 _scsih_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
6552 struct MPT2SAS_ADAPTER
*ioc
;
6553 struct Scsi_Host
*shost
;
6555 shost
= scsi_host_alloc(&scsih_driver_template
,
6556 sizeof(struct MPT2SAS_ADAPTER
));
6560 /* init local params */
6561 ioc
= shost_priv(shost
);
6562 memset(ioc
, 0, sizeof(struct MPT2SAS_ADAPTER
));
6563 INIT_LIST_HEAD(&ioc
->list
);
6564 list_add_tail(&ioc
->list
, &mpt2sas_ioc_list
);
6566 ioc
->id
= mpt_ids
++;
6567 sprintf(ioc
->name
, "%s%d", MPT2SAS_DRIVER_NAME
, ioc
->id
);
6569 ioc
->scsi_io_cb_idx
= scsi_io_cb_idx
;
6570 ioc
->tm_cb_idx
= tm_cb_idx
;
6571 ioc
->ctl_cb_idx
= ctl_cb_idx
;
6572 ioc
->base_cb_idx
= base_cb_idx
;
6573 ioc
->transport_cb_idx
= transport_cb_idx
;
6574 ioc
->scsih_cb_idx
= scsih_cb_idx
;
6575 ioc
->config_cb_idx
= config_cb_idx
;
6576 ioc
->tm_tr_cb_idx
= tm_tr_cb_idx
;
6577 ioc
->tm_sas_control_cb_idx
= tm_sas_control_cb_idx
;
6578 ioc
->logging_level
= logging_level
;
6579 /* misc semaphores and spin locks */
6580 mutex_init(&ioc
->reset_in_progress_mutex
);
6581 spin_lock_init(&ioc
->ioc_reset_in_progress_lock
);
6582 spin_lock_init(&ioc
->scsi_lookup_lock
);
6583 spin_lock_init(&ioc
->sas_device_lock
);
6584 spin_lock_init(&ioc
->sas_node_lock
);
6585 spin_lock_init(&ioc
->fw_event_lock
);
6586 spin_lock_init(&ioc
->raid_device_lock
);
6588 INIT_LIST_HEAD(&ioc
->sas_device_list
);
6589 INIT_LIST_HEAD(&ioc
->sas_device_init_list
);
6590 INIT_LIST_HEAD(&ioc
->sas_expander_list
);
6591 INIT_LIST_HEAD(&ioc
->fw_event_list
);
6592 INIT_LIST_HEAD(&ioc
->raid_device_list
);
6593 INIT_LIST_HEAD(&ioc
->sas_hba
.sas_port_list
);
6594 INIT_LIST_HEAD(&ioc
->delayed_tr_list
);
6596 /* init shost parameters */
6597 shost
->max_cmd_len
= 32;
6598 shost
->max_lun
= max_lun
;
6599 shost
->transportt
= mpt2sas_transport_template
;
6600 shost
->unique_id
= ioc
->id
;
6602 if ((scsi_add_host(shost
, &pdev
->dev
))) {
6603 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6604 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6605 list_del(&ioc
->list
);
6606 goto out_add_shost_fail
;
6609 scsi_host_set_prot(shost
, SHOST_DIF_TYPE1_PROTECTION
6610 | SHOST_DIF_TYPE2_PROTECTION
| SHOST_DIF_TYPE3_PROTECTION
);
6611 scsi_host_set_guard(shost
, SHOST_DIX_GUARD_CRC
);
6614 snprintf(ioc
->firmware_event_name
, sizeof(ioc
->firmware_event_name
),
6615 "fw_event%d", ioc
->id
);
6616 ioc
->firmware_event_thread
= create_singlethread_workqueue(
6617 ioc
->firmware_event_name
);
6618 if (!ioc
->firmware_event_thread
) {
6619 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6620 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6621 goto out_thread_fail
;
6624 ioc
->wait_for_port_enable_to_complete
= 1;
6625 if ((mpt2sas_base_attach(ioc
))) {
6626 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6627 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6628 goto out_attach_fail
;
6631 ioc
->wait_for_port_enable_to_complete
= 0;
6632 _scsih_probe_devices(ioc
);
6636 destroy_workqueue(ioc
->firmware_event_thread
);
6638 list_del(&ioc
->list
);
6639 scsi_remove_host(shost
);
6646 * _scsih_suspend - power management suspend main entry point
6647 * @pdev: PCI device struct
6648 * @state: PM state change to (usually PCI_D3)
6650 * Returns 0 success, anything else error.
6653 _scsih_suspend(struct pci_dev
*pdev
, pm_message_t state
)
6655 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6656 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
6659 mpt2sas_base_stop_watchdog(ioc
);
6660 flush_scheduled_work();
6661 scsi_block_requests(shost
);
6662 device_state
= pci_choose_state(pdev
, state
);
6663 printk(MPT2SAS_INFO_FMT
"pdev=0x%p, slot=%s, entering "
6664 "operating state [D%d]\n", ioc
->name
, pdev
,
6665 pci_name(pdev
), device_state
);
6667 mpt2sas_base_free_resources(ioc
);
6668 pci_save_state(pdev
);
6669 pci_disable_device(pdev
);
6670 pci_set_power_state(pdev
, device_state
);
6675 * _scsih_resume - power management resume main entry point
6676 * @pdev: PCI device struct
6678 * Returns 0 success, anything else error.
6681 _scsih_resume(struct pci_dev
*pdev
)
6683 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6684 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
6685 u32 device_state
= pdev
->current_state
;
6688 printk(MPT2SAS_INFO_FMT
"pdev=0x%p, slot=%s, previous "
6689 "operating state [D%d]\n", ioc
->name
, pdev
,
6690 pci_name(pdev
), device_state
);
6692 pci_set_power_state(pdev
, PCI_D0
);
6693 pci_enable_wake(pdev
, PCI_D0
, 0);
6694 pci_restore_state(pdev
);
6696 r
= mpt2sas_base_map_resources(ioc
);
6700 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
, SOFT_RESET
);
6701 scsi_unblock_requests(shost
);
6702 mpt2sas_base_start_watchdog(ioc
);
6705 #endif /* CONFIG_PM */
6708 * _scsih_pci_error_detected - Called when a PCI error is detected.
6709 * @pdev: PCI device struct
6710 * @state: PCI channel state
6712 * Description: Called when a PCI error is detected.
6715 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
6717 static pci_ers_result_t
6718 _scsih_pci_error_detected(struct pci_dev
*pdev
, pci_channel_state_t state
)
6720 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6721 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
6723 printk(MPT2SAS_INFO_FMT
"PCI error: detected callback, state(%d)!!\n",
6727 case pci_channel_io_normal
:
6728 return PCI_ERS_RESULT_CAN_RECOVER
;
6729 case pci_channel_io_frozen
:
6730 scsi_block_requests(ioc
->shost
);
6731 mpt2sas_base_stop_watchdog(ioc
);
6732 mpt2sas_base_free_resources(ioc
);
6733 return PCI_ERS_RESULT_NEED_RESET
;
6734 case pci_channel_io_perm_failure
:
6735 _scsih_remove(pdev
);
6736 return PCI_ERS_RESULT_DISCONNECT
;
6738 return PCI_ERS_RESULT_NEED_RESET
;
6742 * _scsih_pci_slot_reset - Called when PCI slot has been reset.
6743 * @pdev: PCI device struct
6745 * Description: This routine is called by the pci error recovery
6746 * code after the PCI slot has been reset, just before we
6747 * should resume normal operations.
6749 static pci_ers_result_t
6750 _scsih_pci_slot_reset(struct pci_dev
*pdev
)
6752 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6753 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
6756 printk(MPT2SAS_INFO_FMT
"PCI error: slot reset callback!!\n",
6760 rc
= mpt2sas_base_map_resources(ioc
);
6762 return PCI_ERS_RESULT_DISCONNECT
;
6765 rc
= mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
6768 printk(MPT2SAS_WARN_FMT
"hard reset: %s\n", ioc
->name
,
6769 (rc
== 0) ? "success" : "failed");
6772 return PCI_ERS_RESULT_RECOVERED
;
6774 return PCI_ERS_RESULT_DISCONNECT
;
6778 * _scsih_pci_resume() - resume normal ops after PCI reset
6779 * @pdev: pointer to PCI device
6781 * Called when the error recovery driver tells us that its
6782 * OK to resume normal operation. Use completion to allow
6783 * halted scsi ops to resume.
6786 _scsih_pci_resume(struct pci_dev
*pdev
)
6788 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6789 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
6791 printk(MPT2SAS_INFO_FMT
"PCI error: resume callback!!\n", ioc
->name
);
6793 pci_cleanup_aer_uncorrect_error_status(pdev
);
6794 mpt2sas_base_start_watchdog(ioc
);
6795 scsi_unblock_requests(ioc
->shost
);
6799 * _scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
6800 * @pdev: pointer to PCI device
6802 static pci_ers_result_t
6803 _scsih_pci_mmio_enabled(struct pci_dev
*pdev
)
6805 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6806 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
6808 printk(MPT2SAS_INFO_FMT
"PCI error: mmio enabled callback!!\n",
6811 /* TODO - dump whatever for debugging purposes */
6813 /* Request a slot reset. */
6814 return PCI_ERS_RESULT_NEED_RESET
;
6817 static struct pci_error_handlers _scsih_err_handler
= {
6818 .error_detected
= _scsih_pci_error_detected
,
6819 .mmio_enabled
= _scsih_pci_mmio_enabled
,
6820 .slot_reset
= _scsih_pci_slot_reset
,
6821 .resume
= _scsih_pci_resume
,
6824 static struct pci_driver scsih_driver
= {
6825 .name
= MPT2SAS_DRIVER_NAME
,
6826 .id_table
= scsih_pci_table
,
6827 .probe
= _scsih_probe
,
6828 .remove
= __devexit_p(_scsih_remove
),
6829 .shutdown
= _scsih_shutdown
,
6830 .err_handler
= &_scsih_err_handler
,
6832 .suspend
= _scsih_suspend
,
6833 .resume
= _scsih_resume
,
6837 /* raid transport support */
6838 static struct raid_function_template mpt2sas_raid_functions
= {
6839 .cookie
= &scsih_driver_template
,
6840 .is_raid
= _scsih_is_raid
,
6841 .get_resync
= _scsih_get_resync
,
6842 .get_state
= _scsih_get_state
,
6846 * _scsih_init - main entry point for this driver.
6848 * Returns 0 success, anything else error.
6856 printk(KERN_INFO
"%s version %s loaded\n", MPT2SAS_DRIVER_NAME
,
6857 MPT2SAS_DRIVER_VERSION
);
6859 mpt2sas_transport_template
=
6860 sas_attach_transport(&mpt2sas_transport_functions
);
6861 if (!mpt2sas_transport_template
)
6863 /* raid transport support */
6864 mpt2sas_raid_template
= raid_class_attach(&mpt2sas_raid_functions
);
6865 if (!mpt2sas_raid_template
) {
6866 sas_release_transport(mpt2sas_transport_template
);
6870 mpt2sas_base_initialize_callback_handler();
6872 /* queuecommand callback hander */
6873 scsi_io_cb_idx
= mpt2sas_base_register_callback_handler(_scsih_io_done
);
6875 /* task managment callback handler */
6876 tm_cb_idx
= mpt2sas_base_register_callback_handler(_scsih_tm_done
);
6878 /* base internal commands callback handler */
6879 base_cb_idx
= mpt2sas_base_register_callback_handler(mpt2sas_base_done
);
6881 /* transport internal commands callback handler */
6882 transport_cb_idx
= mpt2sas_base_register_callback_handler(
6883 mpt2sas_transport_done
);
6885 /* scsih internal commands callback handler */
6886 scsih_cb_idx
= mpt2sas_base_register_callback_handler(_scsih_done
);
6888 /* configuration page API internal commands callback handler */
6889 config_cb_idx
= mpt2sas_base_register_callback_handler(
6890 mpt2sas_config_done
);
6892 /* ctl module callback handler */
6893 ctl_cb_idx
= mpt2sas_base_register_callback_handler(mpt2sas_ctl_done
);
6895 tm_tr_cb_idx
= mpt2sas_base_register_callback_handler(
6896 _scsih_tm_tr_complete
);
6897 tm_sas_control_cb_idx
= mpt2sas_base_register_callback_handler(
6898 _scsih_sas_control_complete
);
6902 error
= pci_register_driver(&scsih_driver
);
6904 /* raid transport support */
6905 raid_class_release(mpt2sas_raid_template
);
6906 sas_release_transport(mpt2sas_transport_template
);
6913 * _scsih_exit - exit point for this driver (when it is a module).
6915 * Returns 0 success, anything else error.
6920 printk(KERN_INFO
"mpt2sas version %s unloading\n",
6921 MPT2SAS_DRIVER_VERSION
);
6923 pci_unregister_driver(&scsih_driver
);
6927 mpt2sas_base_release_callback_handler(scsi_io_cb_idx
);
6928 mpt2sas_base_release_callback_handler(tm_cb_idx
);
6929 mpt2sas_base_release_callback_handler(base_cb_idx
);
6930 mpt2sas_base_release_callback_handler(transport_cb_idx
);
6931 mpt2sas_base_release_callback_handler(scsih_cb_idx
);
6932 mpt2sas_base_release_callback_handler(config_cb_idx
);
6933 mpt2sas_base_release_callback_handler(ctl_cb_idx
);
6935 mpt2sas_base_release_callback_handler(tm_tr_cb_idx
);
6936 mpt2sas_base_release_callback_handler(tm_sas_control_cb_idx
);
6938 /* raid transport support */
6939 raid_class_release(mpt2sas_raid_template
);
6940 sas_release_transport(mpt2sas_transport_template
);
6944 module_init(_scsih_init
);
6945 module_exit(_scsih_exit
);