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-2009 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/raid_class.h>
56 #include <linux/slab.h>
58 #include "mpt2sas_base.h"
60 MODULE_AUTHOR(MPT2SAS_AUTHOR
);
61 MODULE_DESCRIPTION(MPT2SAS_DESCRIPTION
);
62 MODULE_LICENSE("GPL");
63 MODULE_VERSION(MPT2SAS_DRIVER_VERSION
);
65 #define RAID_CHANNEL 1
68 static void _scsih_expander_node_remove(struct MPT2SAS_ADAPTER
*ioc
,
69 struct _sas_node
*sas_expander
);
70 static void _firmware_event_work(struct work_struct
*work
);
72 /* global parameters */
73 LIST_HEAD(mpt2sas_ioc_list
);
75 /* local parameters */
76 static u8 scsi_io_cb_idx
= -1;
77 static u8 tm_cb_idx
= -1;
78 static u8 ctl_cb_idx
= -1;
79 static u8 base_cb_idx
= -1;
80 static u8 transport_cb_idx
= -1;
81 static u8 scsih_cb_idx
= -1;
82 static u8 config_cb_idx
= -1;
85 static u8 tm_tr_cb_idx
= -1 ;
86 static u8 tm_sas_control_cb_idx
= -1;
88 /* command line options */
89 static u32 logging_level
;
90 MODULE_PARM_DESC(logging_level
, " bits for enabling additional logging info "
93 /* scsi-mid layer global parmeter is max_report_luns, which is 511 */
94 #define MPT2SAS_MAX_LUN (16895)
95 static int max_lun
= MPT2SAS_MAX_LUN
;
96 module_param(max_lun
, int, 0);
97 MODULE_PARM_DESC(max_lun
, " max lun, default=16895 ");
100 * struct sense_info - common structure for obtaining sense keys
102 * @asc: additional sense code
103 * @ascq: additional sense code qualifier
113 * struct fw_event_work - firmware event struct
114 * @list: link list framework
115 * @work: work object (ioc->fault_reset_work_q)
116 * @ioc: per adapter object
117 * @VF_ID: virtual function id
118 * @VP_ID: virtual port id
119 * @host_reset_handling: handling events during host reset
120 * @ignore: flag meaning this event has been marked to ignore
121 * @event: firmware event MPI2_EVENT_XXX defined in mpt2_ioc.h
122 * @event_data: reply event data payload follows
124 * This object stored on ioc->fw_event_list.
126 struct fw_event_work
{
127 struct list_head list
;
128 struct work_struct work
;
129 struct MPT2SAS_ADAPTER
*ioc
;
132 u8 host_reset_handling
;
138 /* raid transport support */
139 static struct raid_template
*mpt2sas_raid_template
;
142 * struct _scsi_io_transfer - scsi io transfer
143 * @handle: sas device handle (assigned by firmware)
144 * @is_raid: flag set for hidden raid components
145 * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE,
146 * @data_length: data transfer length
147 * @data_dma: dma pointer to data
150 * @cdb_length: cdb length
152 * @timeout: timeout for this command
153 * @VF_ID: virtual function id
154 * @VP_ID: virtual port id
155 * @valid_reply: flag set for reply message
156 * @sense_length: sense length
157 * @ioc_status: ioc status
158 * @scsi_state: scsi state
159 * @scsi_status: scsi staus
160 * @log_info: log information
161 * @transfer_length: data length transfer when there is a reply message
163 * Used for sending internal scsi commands to devices within this module.
164 * Refer to _scsi_send_scsi_io().
166 struct _scsi_io_transfer
{
169 enum dma_data_direction dir
;
172 u8 sense
[SCSI_SENSE_BUFFERSIZE
];
180 /* the following bits are only valid when 'valid_reply = 1' */
190 * The pci device ids are defined in mpi/mpi2_cnfg.h.
192 static struct pci_device_id scsih_pci_table
[] = {
193 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2004
,
194 PCI_ANY_ID
, PCI_ANY_ID
},
196 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2008
,
197 PCI_ANY_ID
, PCI_ANY_ID
},
198 /* Liberator ~ 2108 */
199 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_1
,
200 PCI_ANY_ID
, PCI_ANY_ID
},
201 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_2
,
202 PCI_ANY_ID
, PCI_ANY_ID
},
203 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_3
,
204 PCI_ANY_ID
, PCI_ANY_ID
},
206 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2116_1
,
207 PCI_ANY_ID
, PCI_ANY_ID
},
208 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2116_2
,
209 PCI_ANY_ID
, PCI_ANY_ID
},
210 /* Thunderbolt ~ 2208 */
211 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_1
,
212 PCI_ANY_ID
, PCI_ANY_ID
},
213 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_2
,
214 PCI_ANY_ID
, PCI_ANY_ID
},
215 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_3
,
216 PCI_ANY_ID
, PCI_ANY_ID
},
217 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_4
,
218 PCI_ANY_ID
, PCI_ANY_ID
},
219 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_5
,
220 PCI_ANY_ID
, PCI_ANY_ID
},
221 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_6
,
222 PCI_ANY_ID
, PCI_ANY_ID
},
223 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_7
,
224 PCI_ANY_ID
, PCI_ANY_ID
},
225 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_8
,
226 PCI_ANY_ID
, PCI_ANY_ID
},
227 {0} /* Terminating entry */
229 MODULE_DEVICE_TABLE(pci
, scsih_pci_table
);
232 * _scsih_set_debug_level - global setting of ioc->logging_level.
234 * Note: The logging levels are defined in mpt2sas_debug.h.
237 _scsih_set_debug_level(const char *val
, struct kernel_param
*kp
)
239 int ret
= param_set_int(val
, kp
);
240 struct MPT2SAS_ADAPTER
*ioc
;
245 printk(KERN_INFO
"setting logging_level(0x%08x)\n", logging_level
);
246 list_for_each_entry(ioc
, &mpt2sas_ioc_list
, list
)
247 ioc
->logging_level
= logging_level
;
250 module_param_call(logging_level
, _scsih_set_debug_level
, param_get_int
,
251 &logging_level
, 0644);
254 * _scsih_srch_boot_sas_address - search based on sas_address
255 * @sas_address: sas address
256 * @boot_device: boot device object from bios page 2
258 * Returns 1 when there's a match, 0 means no match.
261 _scsih_srch_boot_sas_address(u64 sas_address
,
262 Mpi2BootDeviceSasWwid_t
*boot_device
)
264 return (sas_address
== le64_to_cpu(boot_device
->SASAddress
)) ? 1 : 0;
268 * _scsih_srch_boot_device_name - search based on device name
269 * @device_name: device name specified in INDENTIFY fram
270 * @boot_device: boot device object from bios page 2
272 * Returns 1 when there's a match, 0 means no match.
275 _scsih_srch_boot_device_name(u64 device_name
,
276 Mpi2BootDeviceDeviceName_t
*boot_device
)
278 return (device_name
== le64_to_cpu(boot_device
->DeviceName
)) ? 1 : 0;
282 * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot
283 * @enclosure_logical_id: enclosure logical id
284 * @slot_number: slot number
285 * @boot_device: boot device object from bios page 2
287 * Returns 1 when there's a match, 0 means no match.
290 _scsih_srch_boot_encl_slot(u64 enclosure_logical_id
, u16 slot_number
,
291 Mpi2BootDeviceEnclosureSlot_t
*boot_device
)
293 return (enclosure_logical_id
== le64_to_cpu(boot_device
->
294 EnclosureLogicalID
) && slot_number
== le16_to_cpu(boot_device
->
295 SlotNumber
)) ? 1 : 0;
299 * _scsih_is_boot_device - search for matching boot device.
300 * @sas_address: sas address
301 * @device_name: device name specified in INDENTIFY fram
302 * @enclosure_logical_id: enclosure logical id
303 * @slot_number: slot number
304 * @form: specifies boot device form
305 * @boot_device: boot device object from bios page 2
307 * Returns 1 when there's a match, 0 means no match.
310 _scsih_is_boot_device(u64 sas_address
, u64 device_name
,
311 u64 enclosure_logical_id
, u16 slot
, u8 form
,
312 Mpi2BiosPage2BootDevice_t
*boot_device
)
317 case MPI2_BIOSPAGE2_FORM_SAS_WWID
:
320 rc
= _scsih_srch_boot_sas_address(
321 sas_address
, &boot_device
->SasWwid
);
323 case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT
:
324 if (!enclosure_logical_id
)
326 rc
= _scsih_srch_boot_encl_slot(
327 enclosure_logical_id
,
328 slot
, &boot_device
->EnclosureSlot
);
330 case MPI2_BIOSPAGE2_FORM_DEVICE_NAME
:
333 rc
= _scsih_srch_boot_device_name(
334 device_name
, &boot_device
->DeviceName
);
336 case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED
:
344 * _scsih_get_sas_address - set the sas_address for given device handle
345 * @handle: device handle
346 * @sas_address: sas address
348 * Returns 0 success, non-zero when failure
351 _scsih_get_sas_address(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
,
354 Mpi2SasDevicePage0_t sas_device_pg0
;
355 Mpi2ConfigReply_t mpi_reply
;
358 if (handle
<= ioc
->sas_hba
.num_phys
) {
359 *sas_address
= ioc
->sas_hba
.sas_address
;
364 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
365 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
366 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
367 ioc
->name
, __FILE__
, __LINE__
, __func__
);
371 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
373 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
374 printk(MPT2SAS_ERR_FMT
"handle(0x%04x), ioc_status(0x%04x)"
375 "\nfailure at %s:%d/%s()!\n", ioc
->name
, handle
, ioc_status
,
376 __FILE__
, __LINE__
, __func__
);
380 *sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
385 * _scsih_determine_boot_device - determine boot device.
386 * @ioc: per adapter object
387 * @device: either sas_device or raid_device object
388 * @is_raid: [flag] 1 = raid object, 0 = sas object
390 * Determines whether this device should be first reported device to
391 * to scsi-ml or sas transport, this purpose is for persistant boot device.
392 * There are primary, alternate, and current entries in bios page 2. The order
393 * priority is primary, alternate, then current. This routine saves
394 * the corresponding device object and is_raid flag in the ioc object.
395 * The saved data to be used later in _scsih_probe_boot_devices().
398 _scsih_determine_boot_device(struct MPT2SAS_ADAPTER
*ioc
,
399 void *device
, u8 is_raid
)
401 struct _sas_device
*sas_device
;
402 struct _raid_device
*raid_device
;
405 u64 enclosure_logical_id
;
408 /* only process this function when driver loads */
409 if (!ioc
->wait_for_port_enable_to_complete
)
414 sas_address
= sas_device
->sas_address
;
415 device_name
= sas_device
->device_name
;
416 enclosure_logical_id
= sas_device
->enclosure_logical_id
;
417 slot
= sas_device
->slot
;
419 raid_device
= device
;
420 sas_address
= raid_device
->wwid
;
422 enclosure_logical_id
= 0;
426 if (!ioc
->req_boot_device
.device
) {
427 if (_scsih_is_boot_device(sas_address
, device_name
,
428 enclosure_logical_id
, slot
,
429 (ioc
->bios_pg2
.ReqBootDeviceForm
&
430 MPI2_BIOSPAGE2_FORM_MASK
),
431 &ioc
->bios_pg2
.RequestedBootDevice
)) {
432 dinitprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
433 "%s: req_boot_device(0x%016llx)\n",
435 (unsigned long long)sas_address
));
436 ioc
->req_boot_device
.device
= device
;
437 ioc
->req_boot_device
.is_raid
= is_raid
;
441 if (!ioc
->req_alt_boot_device
.device
) {
442 if (_scsih_is_boot_device(sas_address
, device_name
,
443 enclosure_logical_id
, slot
,
444 (ioc
->bios_pg2
.ReqAltBootDeviceForm
&
445 MPI2_BIOSPAGE2_FORM_MASK
),
446 &ioc
->bios_pg2
.RequestedAltBootDevice
)) {
447 dinitprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
448 "%s: req_alt_boot_device(0x%016llx)\n",
450 (unsigned long long)sas_address
));
451 ioc
->req_alt_boot_device
.device
= device
;
452 ioc
->req_alt_boot_device
.is_raid
= is_raid
;
456 if (!ioc
->current_boot_device
.device
) {
457 if (_scsih_is_boot_device(sas_address
, device_name
,
458 enclosure_logical_id
, slot
,
459 (ioc
->bios_pg2
.CurrentBootDeviceForm
&
460 MPI2_BIOSPAGE2_FORM_MASK
),
461 &ioc
->bios_pg2
.CurrentBootDevice
)) {
462 dinitprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
463 "%s: current_boot_device(0x%016llx)\n",
465 (unsigned long long)sas_address
));
466 ioc
->current_boot_device
.device
= device
;
467 ioc
->current_boot_device
.is_raid
= is_raid
;
473 * mpt2sas_scsih_sas_device_find_by_sas_address - sas device search
474 * @ioc: per adapter object
475 * @sas_address: sas address
476 * Context: Calling function should acquire ioc->sas_device_lock
478 * This searches for sas_device based on sas_address, then return sas_device
482 mpt2sas_scsih_sas_device_find_by_sas_address(struct MPT2SAS_ADAPTER
*ioc
,
485 struct _sas_device
*sas_device
, *r
;
488 /* check the sas_device_init_list */
489 list_for_each_entry(sas_device
, &ioc
->sas_device_init_list
,
491 if (sas_device
->sas_address
!= sas_address
)
497 /* then check the sas_device_list */
498 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
) {
499 if (sas_device
->sas_address
!= sas_address
)
509 * _scsih_sas_device_find_by_handle - sas device search
510 * @ioc: per adapter object
511 * @handle: sas device handle (assigned by firmware)
512 * Context: Calling function should acquire ioc->sas_device_lock
514 * This searches for sas_device based on sas_address, then return sas_device
517 static struct _sas_device
*
518 _scsih_sas_device_find_by_handle(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
520 struct _sas_device
*sas_device
, *r
;
523 if (ioc
->wait_for_port_enable_to_complete
) {
524 list_for_each_entry(sas_device
, &ioc
->sas_device_init_list
,
526 if (sas_device
->handle
!= handle
)
532 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
) {
533 if (sas_device
->handle
!= handle
)
545 * _scsih_sas_device_remove - remove sas_device from list.
546 * @ioc: per adapter object
547 * @sas_device: the sas_device object
548 * Context: This function will acquire ioc->sas_device_lock.
550 * Removing object and freeing associated memory from the ioc->sas_device_list.
553 _scsih_sas_device_remove(struct MPT2SAS_ADAPTER
*ioc
,
554 struct _sas_device
*sas_device
)
558 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
559 list_del(&sas_device
->list
);
560 memset(sas_device
, 0, sizeof(struct _sas_device
));
562 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
566 * _scsih_sas_device_add - insert sas_device to the list.
567 * @ioc: per adapter object
568 * @sas_device: the sas_device object
569 * Context: This function will acquire ioc->sas_device_lock.
571 * Adding new object to the ioc->sas_device_list.
574 _scsih_sas_device_add(struct MPT2SAS_ADAPTER
*ioc
,
575 struct _sas_device
*sas_device
)
579 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: handle"
580 "(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
, __func__
,
581 sas_device
->handle
, (unsigned long long)sas_device
->sas_address
));
583 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
584 list_add_tail(&sas_device
->list
, &ioc
->sas_device_list
);
585 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
587 if (!mpt2sas_transport_port_add(ioc
, sas_device
->handle
,
588 sas_device
->sas_address_parent
))
589 _scsih_sas_device_remove(ioc
, sas_device
);
593 * _scsih_sas_device_init_add - insert sas_device to the list.
594 * @ioc: per adapter object
595 * @sas_device: the sas_device object
596 * Context: This function will acquire ioc->sas_device_lock.
598 * Adding new object at driver load time to the ioc->sas_device_init_list.
601 _scsih_sas_device_init_add(struct MPT2SAS_ADAPTER
*ioc
,
602 struct _sas_device
*sas_device
)
606 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: handle"
607 "(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
, __func__
,
608 sas_device
->handle
, (unsigned long long)sas_device
->sas_address
));
610 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
611 list_add_tail(&sas_device
->list
, &ioc
->sas_device_init_list
);
612 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
613 _scsih_determine_boot_device(ioc
, sas_device
, 0);
617 * _scsih_raid_device_find_by_id - raid device search
618 * @ioc: per adapter object
619 * @id: sas device target id
620 * @channel: sas device channel
621 * Context: Calling function should acquire ioc->raid_device_lock
623 * This searches for raid_device based on target id, then return raid_device
626 static struct _raid_device
*
627 _scsih_raid_device_find_by_id(struct MPT2SAS_ADAPTER
*ioc
, int id
, int channel
)
629 struct _raid_device
*raid_device
, *r
;
632 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
633 if (raid_device
->id
== id
&& raid_device
->channel
== channel
) {
644 * _scsih_raid_device_find_by_handle - raid device search
645 * @ioc: per adapter object
646 * @handle: sas device handle (assigned by firmware)
647 * Context: Calling function should acquire ioc->raid_device_lock
649 * This searches for raid_device based on handle, then return raid_device
652 static struct _raid_device
*
653 _scsih_raid_device_find_by_handle(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
655 struct _raid_device
*raid_device
, *r
;
658 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
659 if (raid_device
->handle
!= handle
)
670 * _scsih_raid_device_find_by_wwid - raid device search
671 * @ioc: per adapter object
672 * @handle: sas device handle (assigned by firmware)
673 * Context: Calling function should acquire ioc->raid_device_lock
675 * This searches for raid_device based on wwid, then return raid_device
678 static struct _raid_device
*
679 _scsih_raid_device_find_by_wwid(struct MPT2SAS_ADAPTER
*ioc
, u64 wwid
)
681 struct _raid_device
*raid_device
, *r
;
684 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
685 if (raid_device
->wwid
!= wwid
)
696 * _scsih_raid_device_add - add raid_device object
697 * @ioc: per adapter object
698 * @raid_device: raid_device object
700 * This is added to the raid_device_list link list.
703 _scsih_raid_device_add(struct MPT2SAS_ADAPTER
*ioc
,
704 struct _raid_device
*raid_device
)
708 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: handle"
709 "(0x%04x), wwid(0x%016llx)\n", ioc
->name
, __func__
,
710 raid_device
->handle
, (unsigned long long)raid_device
->wwid
));
712 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
713 list_add_tail(&raid_device
->list
, &ioc
->raid_device_list
);
714 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
718 * _scsih_raid_device_remove - delete raid_device object
719 * @ioc: per adapter object
720 * @raid_device: raid_device object
722 * This is removed from the raid_device_list link list.
725 _scsih_raid_device_remove(struct MPT2SAS_ADAPTER
*ioc
,
726 struct _raid_device
*raid_device
)
730 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
731 list_del(&raid_device
->list
);
732 memset(raid_device
, 0, sizeof(struct _raid_device
));
734 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
738 * mpt2sas_scsih_expander_find_by_handle - expander device search
739 * @ioc: per adapter object
740 * @handle: expander handle (assigned by firmware)
741 * Context: Calling function should acquire ioc->sas_device_lock
743 * This searches for expander device based on handle, then returns the
747 mpt2sas_scsih_expander_find_by_handle(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
749 struct _sas_node
*sas_expander
, *r
;
752 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
753 if (sas_expander
->handle
!= handle
)
763 * mpt2sas_scsih_expander_find_by_sas_address - expander device search
764 * @ioc: per adapter object
765 * @sas_address: sas address
766 * Context: Calling function should acquire ioc->sas_node_lock.
768 * This searches for expander device based on sas_address, then returns the
772 mpt2sas_scsih_expander_find_by_sas_address(struct MPT2SAS_ADAPTER
*ioc
,
775 struct _sas_node
*sas_expander
, *r
;
778 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
779 if (sas_expander
->sas_address
!= sas_address
)
789 * _scsih_expander_node_add - insert expander device to the list.
790 * @ioc: per adapter object
791 * @sas_expander: the sas_device object
792 * Context: This function will acquire ioc->sas_node_lock.
794 * Adding new object to the ioc->sas_expander_list.
799 _scsih_expander_node_add(struct MPT2SAS_ADAPTER
*ioc
,
800 struct _sas_node
*sas_expander
)
804 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
805 list_add_tail(&sas_expander
->list
, &ioc
->sas_expander_list
);
806 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
810 * _scsih_is_end_device - determines if device is an end device
811 * @device_info: bitfield providing information about the device.
814 * Returns 1 if end device.
817 _scsih_is_end_device(u32 device_info
)
819 if (device_info
& MPI2_SAS_DEVICE_INFO_END_DEVICE
&&
820 ((device_info
& MPI2_SAS_DEVICE_INFO_SSP_TARGET
) |
821 (device_info
& MPI2_SAS_DEVICE_INFO_STP_TARGET
) |
822 (device_info
& MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)))
829 * mptscsih_get_scsi_lookup - returns scmd entry
830 * @ioc: per adapter object
831 * @smid: system request message index
833 * Returns the smid stored scmd pointer.
835 static struct scsi_cmnd
*
836 _scsih_scsi_lookup_get(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
838 return ioc
->scsi_lookup
[smid
- 1].scmd
;
842 * _scsih_scsi_lookup_find_by_scmd - scmd lookup
843 * @ioc: per adapter object
844 * @smid: system request message index
845 * @scmd: pointer to scsi command object
846 * Context: This function will acquire ioc->scsi_lookup_lock.
848 * This will search for a scmd pointer in the scsi_lookup array,
849 * returning the revelent smid. A returned value of zero means invalid.
852 _scsih_scsi_lookup_find_by_scmd(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_cmnd
859 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
861 for (i
= 0; i
< ioc
->scsiio_depth
; i
++) {
862 if (ioc
->scsi_lookup
[i
].scmd
== scmd
) {
863 smid
= ioc
->scsi_lookup
[i
].smid
;
868 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
873 * _scsih_scsi_lookup_find_by_target - search for matching channel:id
874 * @ioc: per adapter object
877 * Context: This function will acquire ioc->scsi_lookup_lock.
879 * This will search for a matching channel:id in the scsi_lookup array,
880 * returning 1 if found.
883 _scsih_scsi_lookup_find_by_target(struct MPT2SAS_ADAPTER
*ioc
, int id
,
890 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
892 for (i
= 0 ; i
< ioc
->scsiio_depth
; i
++) {
893 if (ioc
->scsi_lookup
[i
].scmd
&&
894 (ioc
->scsi_lookup
[i
].scmd
->device
->id
== id
&&
895 ioc
->scsi_lookup
[i
].scmd
->device
->channel
== channel
)) {
901 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
906 * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun
907 * @ioc: per adapter object
911 * Context: This function will acquire ioc->scsi_lookup_lock.
913 * This will search for a matching channel:id:lun in the scsi_lookup array,
914 * returning 1 if found.
917 _scsih_scsi_lookup_find_by_lun(struct MPT2SAS_ADAPTER
*ioc
, int id
,
918 unsigned int lun
, int channel
)
924 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
926 for (i
= 0 ; i
< ioc
->scsiio_depth
; i
++) {
927 if (ioc
->scsi_lookup
[i
].scmd
&&
928 (ioc
->scsi_lookup
[i
].scmd
->device
->id
== id
&&
929 ioc
->scsi_lookup
[i
].scmd
->device
->channel
== channel
&&
930 ioc
->scsi_lookup
[i
].scmd
->device
->lun
== lun
)) {
936 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
941 * _scsih_get_chain_buffer_dma - obtain block of chains (dma address)
942 * @ioc: per adapter object
943 * @smid: system request message index
945 * Returns phys pointer to chain buffer.
948 _scsih_get_chain_buffer_dma(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
950 return ioc
->chain_dma
+ ((smid
- 1) * (ioc
->request_sz
*
951 ioc
->chains_needed_per_io
));
955 * _scsih_get_chain_buffer - obtain block of chains assigned to a mf request
956 * @ioc: per adapter object
957 * @smid: system request message index
959 * Returns virt pointer to chain buffer.
962 _scsih_get_chain_buffer(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
964 return (void *)(ioc
->chain
+ ((smid
- 1) * (ioc
->request_sz
*
965 ioc
->chains_needed_per_io
)));
969 * _scsih_build_scatter_gather - main sg creation routine
970 * @ioc: per adapter object
971 * @scmd: scsi command
972 * @smid: system request message index
975 * The main routine that builds scatter gather table from a given
976 * scsi request sent via the .queuecommand main handler.
978 * Returns 0 success, anything else error
981 _scsih_build_scatter_gather(struct MPT2SAS_ADAPTER
*ioc
,
982 struct scsi_cmnd
*scmd
, u16 smid
)
984 Mpi2SCSIIORequest_t
*mpi_request
;
985 dma_addr_t chain_dma
;
986 struct scatterlist
*sg_scmd
;
987 void *sg_local
, *chain
;
994 u32 sgl_flags_last_element
;
995 u32 sgl_flags_end_buffer
;
997 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
999 /* init scatter gather flags */
1000 sgl_flags
= MPI2_SGE_FLAGS_SIMPLE_ELEMENT
;
1001 if (scmd
->sc_data_direction
== DMA_TO_DEVICE
)
1002 sgl_flags
|= MPI2_SGE_FLAGS_HOST_TO_IOC
;
1003 sgl_flags_last_element
= (sgl_flags
| MPI2_SGE_FLAGS_LAST_ELEMENT
)
1004 << MPI2_SGE_FLAGS_SHIFT
;
1005 sgl_flags_end_buffer
= (sgl_flags
| MPI2_SGE_FLAGS_LAST_ELEMENT
|
1006 MPI2_SGE_FLAGS_END_OF_BUFFER
| MPI2_SGE_FLAGS_END_OF_LIST
)
1007 << MPI2_SGE_FLAGS_SHIFT
;
1008 sgl_flags
= sgl_flags
<< MPI2_SGE_FLAGS_SHIFT
;
1010 sg_scmd
= scsi_sglist(scmd
);
1011 sges_left
= scsi_dma_map(scmd
);
1013 sdev_printk(KERN_ERR
, scmd
->device
, "pci_map_sg"
1014 " failed: request for %d bytes!\n", scsi_bufflen(scmd
));
1018 sg_local
= &mpi_request
->SGL
;
1019 sges_in_segment
= ioc
->max_sges_in_main_message
;
1020 if (sges_left
<= sges_in_segment
)
1021 goto fill_in_last_segment
;
1023 mpi_request
->ChainOffset
= (offsetof(Mpi2SCSIIORequest_t
, SGL
) +
1024 (sges_in_segment
* ioc
->sge_size
))/4;
1026 /* fill in main message segment when there is a chain following */
1027 while (sges_in_segment
) {
1028 if (sges_in_segment
== 1)
1029 ioc
->base_add_sg_single(sg_local
,
1030 sgl_flags_last_element
| sg_dma_len(sg_scmd
),
1031 sg_dma_address(sg_scmd
));
1033 ioc
->base_add_sg_single(sg_local
, sgl_flags
|
1034 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
1035 sg_scmd
= sg_next(sg_scmd
);
1036 sg_local
+= ioc
->sge_size
;
1041 /* initializing the chain flags and pointers */
1042 chain_flags
= MPI2_SGE_FLAGS_CHAIN_ELEMENT
<< MPI2_SGE_FLAGS_SHIFT
;
1043 chain
= _scsih_get_chain_buffer(ioc
, smid
);
1044 chain_dma
= _scsih_get_chain_buffer_dma(ioc
, smid
);
1046 sges_in_segment
= (sges_left
<=
1047 ioc
->max_sges_in_chain_message
) ? sges_left
:
1048 ioc
->max_sges_in_chain_message
;
1049 chain_offset
= (sges_left
== sges_in_segment
) ?
1050 0 : (sges_in_segment
* ioc
->sge_size
)/4;
1051 chain_length
= sges_in_segment
* ioc
->sge_size
;
1053 chain_offset
= chain_offset
<<
1054 MPI2_SGE_CHAIN_OFFSET_SHIFT
;
1055 chain_length
+= ioc
->sge_size
;
1057 ioc
->base_add_sg_single(sg_local
, chain_flags
| chain_offset
|
1058 chain_length
, chain_dma
);
1061 goto fill_in_last_segment
;
1063 /* fill in chain segments */
1064 while (sges_in_segment
) {
1065 if (sges_in_segment
== 1)
1066 ioc
->base_add_sg_single(sg_local
,
1067 sgl_flags_last_element
|
1068 sg_dma_len(sg_scmd
),
1069 sg_dma_address(sg_scmd
));
1071 ioc
->base_add_sg_single(sg_local
, sgl_flags
|
1072 sg_dma_len(sg_scmd
),
1073 sg_dma_address(sg_scmd
));
1074 sg_scmd
= sg_next(sg_scmd
);
1075 sg_local
+= ioc
->sge_size
;
1080 chain_dma
+= ioc
->request_sz
;
1081 chain
+= ioc
->request_sz
;
1085 fill_in_last_segment
:
1087 /* fill the last segment */
1090 ioc
->base_add_sg_single(sg_local
, sgl_flags_end_buffer
|
1091 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
1093 ioc
->base_add_sg_single(sg_local
, sgl_flags
|
1094 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
1095 sg_scmd
= sg_next(sg_scmd
);
1096 sg_local
+= ioc
->sge_size
;
1104 * _scsih_change_queue_depth - setting device queue depth
1105 * @sdev: scsi device struct
1106 * @qdepth: requested queue depth
1107 * @reason: calling context
1109 * Returns queue depth.
1112 _scsih_change_queue_depth(struct scsi_device
*sdev
, int qdepth
, int reason
)
1114 struct Scsi_Host
*shost
= sdev
->host
;
1117 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1118 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1119 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1120 struct _sas_device
*sas_device
;
1121 unsigned long flags
;
1123 if (reason
!= SCSI_QDEPTH_DEFAULT
)
1126 max_depth
= shost
->can_queue
;
1128 /* limit max device queue for SATA to 32 */
1129 sas_device_priv_data
= sdev
->hostdata
;
1130 if (!sas_device_priv_data
)
1132 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
1133 if (!sas_target_priv_data
)
1135 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
))
1137 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1138 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1139 sas_device_priv_data
->sas_target
->sas_address
);
1140 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1141 if (sas_device
&& sas_device
->device_info
&
1142 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1143 max_depth
= MPT2SAS_SATA_QUEUE_DEPTH
;
1147 if (!sdev
->tagged_supported
)
1149 if (qdepth
> max_depth
)
1151 tag_type
= (qdepth
== 1) ? 0 : MSG_SIMPLE_TAG
;
1152 scsi_adjust_queue_depth(sdev
, tag_type
, qdepth
);
1154 if (sdev
->inquiry_len
> 7)
1155 sdev_printk(KERN_INFO
, sdev
, "qdepth(%d), tagged(%d), "
1156 "simple(%d), ordered(%d), scsi_level(%d), cmd_que(%d)\n",
1157 sdev
->queue_depth
, sdev
->tagged_supported
, sdev
->simple_tags
,
1158 sdev
->ordered_tags
, sdev
->scsi_level
,
1159 (sdev
->inquiry
[7] & 2) >> 1);
1161 return sdev
->queue_depth
;
1165 * _scsih_change_queue_type - changing device queue tag type
1166 * @sdev: scsi device struct
1167 * @tag_type: requested tag type
1169 * Returns queue tag type.
1172 _scsih_change_queue_type(struct scsi_device
*sdev
, int tag_type
)
1174 if (sdev
->tagged_supported
) {
1175 scsi_set_tag_type(sdev
, tag_type
);
1177 scsi_activate_tcq(sdev
, sdev
->queue_depth
);
1179 scsi_deactivate_tcq(sdev
, sdev
->queue_depth
);
1187 * _scsih_target_alloc - target add routine
1188 * @starget: scsi target struct
1190 * Returns 0 if ok. Any other return is assumed to be an error and
1191 * the device is ignored.
1194 _scsih_target_alloc(struct scsi_target
*starget
)
1196 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
1197 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1198 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1199 struct _sas_device
*sas_device
;
1200 struct _raid_device
*raid_device
;
1201 unsigned long flags
;
1202 struct sas_rphy
*rphy
;
1204 sas_target_priv_data
= kzalloc(sizeof(struct scsi_target
), GFP_KERNEL
);
1205 if (!sas_target_priv_data
)
1208 starget
->hostdata
= sas_target_priv_data
;
1209 sas_target_priv_data
->starget
= starget
;
1210 sas_target_priv_data
->handle
= MPT2SAS_INVALID_DEVICE_HANDLE
;
1213 if (starget
->channel
== RAID_CHANNEL
) {
1214 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1215 raid_device
= _scsih_raid_device_find_by_id(ioc
, starget
->id
,
1218 sas_target_priv_data
->handle
= raid_device
->handle
;
1219 sas_target_priv_data
->sas_address
= raid_device
->wwid
;
1220 sas_target_priv_data
->flags
|= MPT_TARGET_FLAGS_VOLUME
;
1221 raid_device
->starget
= starget
;
1223 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1227 /* sas/sata devices */
1228 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1229 rphy
= dev_to_rphy(starget
->dev
.parent
);
1230 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1231 rphy
->identify
.sas_address
);
1234 sas_target_priv_data
->handle
= sas_device
->handle
;
1235 sas_target_priv_data
->sas_address
= sas_device
->sas_address
;
1236 sas_device
->starget
= starget
;
1237 sas_device
->id
= starget
->id
;
1238 sas_device
->channel
= starget
->channel
;
1239 if (sas_device
->hidden_raid_component
)
1240 sas_target_priv_data
->flags
|=
1241 MPT_TARGET_FLAGS_RAID_COMPONENT
;
1243 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1249 * _scsih_target_destroy - target destroy routine
1250 * @starget: scsi target struct
1255 _scsih_target_destroy(struct scsi_target
*starget
)
1257 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
1258 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1259 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1260 struct _sas_device
*sas_device
;
1261 struct _raid_device
*raid_device
;
1262 unsigned long flags
;
1263 struct sas_rphy
*rphy
;
1265 sas_target_priv_data
= starget
->hostdata
;
1266 if (!sas_target_priv_data
)
1269 if (starget
->channel
== RAID_CHANNEL
) {
1270 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1271 raid_device
= _scsih_raid_device_find_by_id(ioc
, starget
->id
,
1274 raid_device
->starget
= NULL
;
1275 raid_device
->sdev
= NULL
;
1277 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1281 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1282 rphy
= dev_to_rphy(starget
->dev
.parent
);
1283 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1284 rphy
->identify
.sas_address
);
1285 if (sas_device
&& (sas_device
->starget
== starget
) &&
1286 (sas_device
->id
== starget
->id
) &&
1287 (sas_device
->channel
== starget
->channel
))
1288 sas_device
->starget
= NULL
;
1290 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1293 kfree(sas_target_priv_data
);
1294 starget
->hostdata
= NULL
;
1298 * _scsih_slave_alloc - device add routine
1299 * @sdev: scsi device struct
1301 * Returns 0 if ok. Any other return is assumed to be an error and
1302 * the device is ignored.
1305 _scsih_slave_alloc(struct scsi_device
*sdev
)
1307 struct Scsi_Host
*shost
;
1308 struct MPT2SAS_ADAPTER
*ioc
;
1309 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1310 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1311 struct scsi_target
*starget
;
1312 struct _raid_device
*raid_device
;
1313 unsigned long flags
;
1315 sas_device_priv_data
= kzalloc(sizeof(struct scsi_device
), GFP_KERNEL
);
1316 if (!sas_device_priv_data
)
1319 sas_device_priv_data
->lun
= sdev
->lun
;
1320 sas_device_priv_data
->flags
= MPT_DEVICE_FLAGS_INIT
;
1322 starget
= scsi_target(sdev
);
1323 sas_target_priv_data
= starget
->hostdata
;
1324 sas_target_priv_data
->num_luns
++;
1325 sas_device_priv_data
->sas_target
= sas_target_priv_data
;
1326 sdev
->hostdata
= sas_device_priv_data
;
1327 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
))
1328 sdev
->no_uld_attach
= 1;
1330 shost
= dev_to_shost(&starget
->dev
);
1331 ioc
= shost_priv(shost
);
1332 if (starget
->channel
== RAID_CHANNEL
) {
1333 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1334 raid_device
= _scsih_raid_device_find_by_id(ioc
,
1335 starget
->id
, starget
->channel
);
1337 raid_device
->sdev
= sdev
; /* raid is single lun */
1338 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1345 * _scsih_slave_destroy - device destroy routine
1346 * @sdev: scsi device struct
1351 _scsih_slave_destroy(struct scsi_device
*sdev
)
1353 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1354 struct scsi_target
*starget
;
1356 if (!sdev
->hostdata
)
1359 starget
= scsi_target(sdev
);
1360 sas_target_priv_data
= starget
->hostdata
;
1361 sas_target_priv_data
->num_luns
--;
1362 kfree(sdev
->hostdata
);
1363 sdev
->hostdata
= NULL
;
1367 * _scsih_display_sata_capabilities - sata capabilities
1368 * @ioc: per adapter object
1369 * @sas_device: the sas_device object
1370 * @sdev: scsi device struct
1373 _scsih_display_sata_capabilities(struct MPT2SAS_ADAPTER
*ioc
,
1374 struct _sas_device
*sas_device
, struct scsi_device
*sdev
)
1376 Mpi2ConfigReply_t mpi_reply
;
1377 Mpi2SasDevicePage0_t sas_device_pg0
;
1382 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
1383 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, sas_device
->handle
))) {
1384 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1385 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1389 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
1390 MPI2_IOCSTATUS_MASK
;
1391 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
1392 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1393 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1397 flags
= le16_to_cpu(sas_device_pg0
.Flags
);
1398 device_info
= le16_to_cpu(sas_device_pg0
.DeviceInfo
);
1400 sdev_printk(KERN_INFO
, sdev
,
1401 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1402 "sw_preserve(%s)\n",
1403 (device_info
& MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE
) ? "y" : "n",
1404 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED
) ? "y" : "n",
1405 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY
) ? "y" :
1407 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED
) ? "y" : "n",
1408 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED
) ? "y" : "n",
1409 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE
) ? "y" : "n");
1413 * _scsih_is_raid - return boolean indicating device is raid volume
1414 * @dev the device struct object
1417 _scsih_is_raid(struct device
*dev
)
1419 struct scsi_device
*sdev
= to_scsi_device(dev
);
1421 return (sdev
->channel
== RAID_CHANNEL
) ? 1 : 0;
1425 * _scsih_get_resync - get raid volume resync percent complete
1426 * @dev the device struct object
1429 _scsih_get_resync(struct device
*dev
)
1431 struct scsi_device
*sdev
= to_scsi_device(dev
);
1432 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
1433 static struct _raid_device
*raid_device
;
1434 unsigned long flags
;
1435 Mpi2RaidVolPage0_t vol_pg0
;
1436 Mpi2ConfigReply_t mpi_reply
;
1437 u32 volume_status_flags
;
1438 u8 percent_complete
= 0;
1440 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1441 raid_device
= _scsih_raid_device_find_by_id(ioc
, sdev
->id
,
1443 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1448 if (mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, &vol_pg0
,
1449 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, raid_device
->handle
,
1450 sizeof(Mpi2RaidVolPage0_t
))) {
1451 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1452 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1456 volume_status_flags
= le32_to_cpu(vol_pg0
.VolumeStatusFlags
);
1457 if (volume_status_flags
& MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS
)
1458 percent_complete
= raid_device
->percent_complete
;
1460 raid_set_resync(mpt2sas_raid_template
, dev
, percent_complete
);
1464 * _scsih_get_state - get raid volume level
1465 * @dev the device struct object
1468 _scsih_get_state(struct device
*dev
)
1470 struct scsi_device
*sdev
= to_scsi_device(dev
);
1471 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
1472 static struct _raid_device
*raid_device
;
1473 unsigned long flags
;
1474 Mpi2RaidVolPage0_t vol_pg0
;
1475 Mpi2ConfigReply_t mpi_reply
;
1477 enum raid_state state
= RAID_STATE_UNKNOWN
;
1479 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1480 raid_device
= _scsih_raid_device_find_by_id(ioc
, sdev
->id
,
1482 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1487 if (mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, &vol_pg0
,
1488 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, raid_device
->handle
,
1489 sizeof(Mpi2RaidVolPage0_t
))) {
1490 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1491 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1495 volstate
= le32_to_cpu(vol_pg0
.VolumeStatusFlags
);
1496 if (volstate
& MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS
) {
1497 state
= RAID_STATE_RESYNCING
;
1501 switch (vol_pg0
.VolumeState
) {
1502 case MPI2_RAID_VOL_STATE_OPTIMAL
:
1503 case MPI2_RAID_VOL_STATE_ONLINE
:
1504 state
= RAID_STATE_ACTIVE
;
1506 case MPI2_RAID_VOL_STATE_DEGRADED
:
1507 state
= RAID_STATE_DEGRADED
;
1509 case MPI2_RAID_VOL_STATE_FAILED
:
1510 case MPI2_RAID_VOL_STATE_MISSING
:
1511 state
= RAID_STATE_OFFLINE
;
1515 raid_set_state(mpt2sas_raid_template
, dev
, state
);
1519 * _scsih_set_level - set raid level
1520 * @sdev: scsi device struct
1521 * @raid_device: raid_device object
1524 _scsih_set_level(struct scsi_device
*sdev
, struct _raid_device
*raid_device
)
1526 enum raid_level level
= RAID_LEVEL_UNKNOWN
;
1528 switch (raid_device
->volume_type
) {
1529 case MPI2_RAID_VOL_TYPE_RAID0
:
1530 level
= RAID_LEVEL_0
;
1532 case MPI2_RAID_VOL_TYPE_RAID10
:
1533 level
= RAID_LEVEL_10
;
1535 case MPI2_RAID_VOL_TYPE_RAID1E
:
1536 level
= RAID_LEVEL_1E
;
1538 case MPI2_RAID_VOL_TYPE_RAID1
:
1539 level
= RAID_LEVEL_1
;
1543 raid_set_level(mpt2sas_raid_template
, &sdev
->sdev_gendev
, level
);
1547 * _scsih_get_volume_capabilities - volume capabilities
1548 * @ioc: per adapter object
1549 * @sas_device: the raid_device object
1552 _scsih_get_volume_capabilities(struct MPT2SAS_ADAPTER
*ioc
,
1553 struct _raid_device
*raid_device
)
1555 Mpi2RaidVolPage0_t
*vol_pg0
;
1556 Mpi2RaidPhysDiskPage0_t pd_pg0
;
1557 Mpi2SasDevicePage0_t sas_device_pg0
;
1558 Mpi2ConfigReply_t mpi_reply
;
1562 if ((mpt2sas_config_get_number_pds(ioc
, raid_device
->handle
,
1563 &num_pds
)) || !num_pds
) {
1564 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1565 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1569 raid_device
->num_pds
= num_pds
;
1570 sz
= offsetof(Mpi2RaidVolPage0_t
, PhysDisk
) + (num_pds
*
1571 sizeof(Mpi2RaidVol0PhysDisk_t
));
1572 vol_pg0
= kzalloc(sz
, GFP_KERNEL
);
1574 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1575 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1579 if ((mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, vol_pg0
,
1580 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, raid_device
->handle
, sz
))) {
1581 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1582 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1587 raid_device
->volume_type
= vol_pg0
->VolumeType
;
1589 /* figure out what the underlying devices are by
1590 * obtaining the device_info bits for the 1st device
1592 if (!(mpt2sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
1593 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM
,
1594 vol_pg0
->PhysDisk
[0].PhysDiskNum
))) {
1595 if (!(mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
1596 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
1597 le16_to_cpu(pd_pg0
.DevHandle
)))) {
1598 raid_device
->device_info
=
1599 le32_to_cpu(sas_device_pg0
.DeviceInfo
);
1607 * _scsih_enable_tlr - setting TLR flags
1608 * @ioc: per adapter object
1609 * @sdev: scsi device struct
1611 * Enabling Transaction Layer Retries for tape devices when
1612 * vpd page 0x90 is present
1616 _scsih_enable_tlr(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_device
*sdev
)
1619 if (sdev
->type
!= TYPE_TAPE
)
1622 if (!(ioc
->facts
.IOCCapabilities
& MPI2_IOCFACTS_CAPABILITY_TLR
))
1625 sas_enable_tlr(sdev
);
1626 sdev_printk(KERN_INFO
, sdev
, "TLR %s\n",
1627 sas_is_tlr_enabled(sdev
) ? "Enabled" : "Disabled");
1633 * _scsih_slave_configure - device configure routine.
1634 * @sdev: scsi device struct
1636 * Returns 0 if ok. Any other return is assumed to be an error and
1637 * the device is ignored.
1640 _scsih_slave_configure(struct scsi_device
*sdev
)
1642 struct Scsi_Host
*shost
= sdev
->host
;
1643 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1644 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1645 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1646 struct _sas_device
*sas_device
;
1647 struct _raid_device
*raid_device
;
1648 unsigned long flags
;
1655 sas_device_priv_data
= sdev
->hostdata
;
1656 sas_device_priv_data
->configured_lun
= 1;
1657 sas_device_priv_data
->flags
&= ~MPT_DEVICE_FLAGS_INIT
;
1658 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
1660 /* raid volume handling */
1661 if (sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
1663 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1664 raid_device
= _scsih_raid_device_find_by_handle(ioc
,
1665 sas_target_priv_data
->handle
);
1666 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1668 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1669 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1673 _scsih_get_volume_capabilities(ioc
, raid_device
);
1675 /* RAID Queue Depth Support
1676 * IS volume = underlying qdepth of drive type, either
1677 * MPT2SAS_SAS_QUEUE_DEPTH or MPT2SAS_SATA_QUEUE_DEPTH
1678 * IM/IME/R10 = 128 (MPT2SAS_RAID_QUEUE_DEPTH)
1680 if (raid_device
->device_info
&
1681 MPI2_SAS_DEVICE_INFO_SSP_TARGET
) {
1682 qdepth
= MPT2SAS_SAS_QUEUE_DEPTH
;
1685 qdepth
= MPT2SAS_SATA_QUEUE_DEPTH
;
1686 if (raid_device
->device_info
&
1687 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1693 switch (raid_device
->volume_type
) {
1694 case MPI2_RAID_VOL_TYPE_RAID0
:
1697 case MPI2_RAID_VOL_TYPE_RAID1E
:
1698 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
1699 if (ioc
->manu_pg10
.OEMIdentifier
&&
1700 (ioc
->manu_pg10
.GenericFlags0
&
1701 MFG10_GF0_R10_DISPLAY
) &&
1702 !(raid_device
->num_pds
% 2))
1707 case MPI2_RAID_VOL_TYPE_RAID1
:
1708 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
1711 case MPI2_RAID_VOL_TYPE_RAID10
:
1712 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
1715 case MPI2_RAID_VOL_TYPE_UNKNOWN
:
1717 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
1722 sdev_printk(KERN_INFO
, sdev
, "%s: "
1723 "handle(0x%04x), wwid(0x%016llx), pd_count(%d), type(%s)\n",
1724 r_level
, raid_device
->handle
,
1725 (unsigned long long)raid_device
->wwid
,
1726 raid_device
->num_pds
, ds
);
1727 _scsih_change_queue_depth(sdev
, qdepth
, SCSI_QDEPTH_DEFAULT
);
1728 /* raid transport support */
1729 _scsih_set_level(sdev
, raid_device
);
1733 /* non-raid handling */
1734 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1735 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1736 sas_device_priv_data
->sas_target
->sas_address
);
1737 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1739 if (sas_target_priv_data
->flags
&
1740 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
1741 mpt2sas_config_get_volume_handle(ioc
,
1742 sas_device
->handle
, &sas_device
->volume_handle
);
1743 mpt2sas_config_get_volume_wwid(ioc
,
1744 sas_device
->volume_handle
,
1745 &sas_device
->volume_wwid
);
1747 if (sas_device
->device_info
& MPI2_SAS_DEVICE_INFO_SSP_TARGET
) {
1748 qdepth
= MPT2SAS_SAS_QUEUE_DEPTH
;
1752 qdepth
= MPT2SAS_SATA_QUEUE_DEPTH
;
1753 if (sas_device
->device_info
&
1754 MPI2_SAS_DEVICE_INFO_STP_TARGET
)
1756 else if (sas_device
->device_info
&
1757 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1761 sdev_printk(KERN_INFO
, sdev
, "%s: handle(0x%04x), "
1762 "sas_addr(0x%016llx), device_name(0x%016llx)\n",
1763 ds
, sas_device
->handle
,
1764 (unsigned long long)sas_device
->sas_address
,
1765 (unsigned long long)sas_device
->device_name
);
1766 sdev_printk(KERN_INFO
, sdev
, "%s: "
1767 "enclosure_logical_id(0x%016llx), slot(%d)\n", ds
,
1768 (unsigned long long) sas_device
->enclosure_logical_id
,
1772 _scsih_display_sata_capabilities(ioc
, sas_device
, sdev
);
1775 _scsih_change_queue_depth(sdev
, qdepth
, SCSI_QDEPTH_DEFAULT
);
1778 sas_read_port_mode_page(sdev
);
1779 _scsih_enable_tlr(ioc
, sdev
);
1785 * _scsih_bios_param - fetch head, sector, cylinder info for a disk
1786 * @sdev: scsi device struct
1787 * @bdev: pointer to block device context
1788 * @capacity: device size (in 512 byte sectors)
1789 * @params: three element array to place output:
1790 * params[0] number of heads (max 255)
1791 * params[1] number of sectors (max 63)
1792 * params[2] number of cylinders
1797 _scsih_bios_param(struct scsi_device
*sdev
, struct block_device
*bdev
,
1798 sector_t capacity
, int params
[])
1808 dummy
= heads
* sectors
;
1809 cylinders
= capacity
;
1810 sector_div(cylinders
, dummy
);
1813 * Handle extended translation size for logical drives
1816 if ((ulong
)capacity
>= 0x200000) {
1819 dummy
= heads
* sectors
;
1820 cylinders
= capacity
;
1821 sector_div(cylinders
, dummy
);
1826 params
[1] = sectors
;
1827 params
[2] = cylinders
;
1833 * _scsih_response_code - translation of device response code
1834 * @ioc: per adapter object
1835 * @response_code: response code returned by the device
1840 _scsih_response_code(struct MPT2SAS_ADAPTER
*ioc
, u8 response_code
)
1844 switch (response_code
) {
1845 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE
:
1846 desc
= "task management request completed";
1848 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
:
1849 desc
= "invalid frame";
1851 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED
:
1852 desc
= "task management request not supported";
1854 case MPI2_SCSITASKMGMT_RSP_TM_FAILED
:
1855 desc
= "task management request failed";
1857 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
:
1858 desc
= "task management request succeeded";
1860 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN
:
1861 desc
= "invalid lun";
1864 desc
= "overlapped tag attempted";
1866 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
:
1867 desc
= "task queued, however not sent to target";
1873 printk(MPT2SAS_WARN_FMT
"response_code(0x%01x): %s\n",
1874 ioc
->name
, response_code
, desc
);
1878 * _scsih_tm_done - tm completion routine
1879 * @ioc: per adapter object
1880 * @smid: system request message index
1881 * @msix_index: MSIX table index supplied by the OS
1882 * @reply: reply message frame(lower 32bit addr)
1885 * The callback handler when using scsih_issue_tm.
1887 * Return 1 meaning mf should be freed from _base_interrupt
1888 * 0 means the mf is freed from this function.
1891 _scsih_tm_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
1893 MPI2DefaultReply_t
*mpi_reply
;
1895 if (ioc
->tm_cmds
.status
== MPT2_CMD_NOT_USED
)
1897 if (ioc
->tm_cmds
.smid
!= smid
)
1899 ioc
->tm_cmds
.status
|= MPT2_CMD_COMPLETE
;
1900 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
1902 memcpy(ioc
->tm_cmds
.reply
, mpi_reply
, mpi_reply
->MsgLength
*4);
1903 ioc
->tm_cmds
.status
|= MPT2_CMD_REPLY_VALID
;
1905 ioc
->tm_cmds
.status
&= ~MPT2_CMD_PENDING
;
1906 complete(&ioc
->tm_cmds
.done
);
1911 * mpt2sas_scsih_set_tm_flag - set per target tm_busy
1912 * @ioc: per adapter object
1913 * @handle: device handle
1915 * During taskmangement request, we need to freeze the device queue.
1918 mpt2sas_scsih_set_tm_flag(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
1920 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1921 struct scsi_device
*sdev
;
1924 shost_for_each_device(sdev
, ioc
->shost
) {
1927 sas_device_priv_data
= sdev
->hostdata
;
1928 if (!sas_device_priv_data
)
1930 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
1931 sas_device_priv_data
->sas_target
->tm_busy
= 1;
1933 ioc
->ignore_loginfos
= 1;
1939 * mpt2sas_scsih_clear_tm_flag - clear per target tm_busy
1940 * @ioc: per adapter object
1941 * @handle: device handle
1943 * During taskmangement request, we need to freeze the device queue.
1946 mpt2sas_scsih_clear_tm_flag(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
1948 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1949 struct scsi_device
*sdev
;
1952 shost_for_each_device(sdev
, ioc
->shost
) {
1955 sas_device_priv_data
= sdev
->hostdata
;
1956 if (!sas_device_priv_data
)
1958 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
1959 sas_device_priv_data
->sas_target
->tm_busy
= 0;
1961 ioc
->ignore_loginfos
= 0;
1967 * mpt2sas_scsih_issue_tm - main routine for sending tm requests
1968 * @ioc: per adapter struct
1969 * @device_handle: device handle
1971 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
1972 * @smid_task: smid assigned to the task
1973 * @timeout: timeout in seconds
1974 * Context: The calling function needs to acquire the tm_cmds.mutex
1976 * A generic API for sending task management requests to firmware.
1978 * The ioc->tm_cmds.status flag should be MPT2_CMD_NOT_USED before calling
1981 * The callback index is set inside `ioc->tm_cb_idx`.
1986 mpt2sas_scsih_issue_tm(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
, uint lun
,
1987 u8 type
, u16 smid_task
, ulong timeout
)
1989 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
1990 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
1993 unsigned long timeleft
;
1995 if (ioc
->tm_cmds
.status
!= MPT2_CMD_NOT_USED
) {
1996 printk(MPT2SAS_INFO_FMT
"%s: tm_cmd busy!!!\n",
1997 __func__
, ioc
->name
);
2001 if (ioc
->shost_recovery
) {
2002 printk(MPT2SAS_INFO_FMT
"%s: host reset in progress!\n",
2003 __func__
, ioc
->name
);
2007 ioc_state
= mpt2sas_base_get_iocstate(ioc
, 0);
2008 if (ioc_state
& MPI2_DOORBELL_USED
) {
2009 dhsprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"unexpected doorbell "
2010 "active!\n", ioc
->name
));
2011 goto issue_host_reset
;
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 goto issue_host_reset
;
2020 smid
= mpt2sas_base_get_smid_hpr(ioc
, ioc
->tm_cb_idx
);
2022 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
2023 ioc
->name
, __func__
);
2027 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"sending tm: handle(0x%04x),"
2028 " task_type(0x%02x), smid(%d)\n", ioc
->name
, handle
, type
,
2030 ioc
->tm_cmds
.status
= MPT2_CMD_PENDING
;
2031 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
2032 ioc
->tm_cmds
.smid
= smid
;
2033 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
2034 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
2035 mpi_request
->DevHandle
= cpu_to_le16(handle
);
2036 mpi_request
->TaskType
= type
;
2037 mpi_request
->TaskMID
= cpu_to_le16(smid_task
);
2038 mpi_request
->VP_ID
= 0; /* TODO */
2039 mpi_request
->VF_ID
= 0;
2040 int_to_scsilun(lun
, (struct scsi_lun
*)mpi_request
->LUN
);
2041 mpt2sas_scsih_set_tm_flag(ioc
, handle
);
2042 init_completion(&ioc
->tm_cmds
.done
);
2043 mpt2sas_base_put_smid_hi_priority(ioc
, smid
);
2044 timeleft
= wait_for_completion_timeout(&ioc
->tm_cmds
.done
, timeout
*HZ
);
2045 mpt2sas_scsih_clear_tm_flag(ioc
, handle
);
2046 if (!(ioc
->tm_cmds
.status
& MPT2_CMD_COMPLETE
)) {
2047 printk(MPT2SAS_ERR_FMT
"%s: timeout\n",
2048 ioc
->name
, __func__
);
2049 _debug_dump_mf(mpi_request
,
2050 sizeof(Mpi2SCSITaskManagementRequest_t
)/4);
2051 if (!(ioc
->tm_cmds
.status
& MPT2_CMD_RESET
))
2052 goto issue_host_reset
;
2055 if (ioc
->tm_cmds
.status
& MPT2_CMD_REPLY_VALID
) {
2056 mpi_reply
= ioc
->tm_cmds
.reply
;
2057 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"complete tm: "
2058 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
2059 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
2060 le32_to_cpu(mpi_reply
->IOCLogInfo
),
2061 le32_to_cpu(mpi_reply
->TerminationCount
)));
2062 if (ioc
->logging_level
& MPT_DEBUG_TM
)
2063 _scsih_response_code(ioc
, mpi_reply
->ResponseCode
);
2067 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
, FORCE_BIG_HAMMER
);
2071 * _scsih_abort - eh threads main abort routine
2072 * @sdev: scsi device struct
2074 * Returns SUCCESS if command aborted else FAILED
2077 _scsih_abort(struct scsi_cmnd
*scmd
)
2079 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2080 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2084 struct scsi_cmnd
*scmd_lookup
;
2086 printk(MPT2SAS_INFO_FMT
"attempting task abort! scmd(%p)\n",
2088 scsi_print_command(scmd
);
2090 sas_device_priv_data
= scmd
->device
->hostdata
;
2091 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2092 printk(MPT2SAS_INFO_FMT
"device been deleted! scmd(%p)\n",
2094 scmd
->result
= DID_NO_CONNECT
<< 16;
2095 scmd
->scsi_done(scmd
);
2100 /* search for the command */
2101 smid
= _scsih_scsi_lookup_find_by_scmd(ioc
, scmd
);
2103 scmd
->result
= DID_RESET
<< 16;
2108 /* for hidden raid components and volumes this is not supported */
2109 if (sas_device_priv_data
->sas_target
->flags
&
2110 MPT_TARGET_FLAGS_RAID_COMPONENT
||
2111 sas_device_priv_data
->sas_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
2112 scmd
->result
= DID_RESET
<< 16;
2117 mpt2sas_halt_firmware(ioc
);
2119 mutex_lock(&ioc
->tm_cmds
.mutex
);
2120 handle
= sas_device_priv_data
->sas_target
->handle
;
2121 mpt2sas_scsih_issue_tm(ioc
, handle
, sas_device_priv_data
->lun
,
2122 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
, smid
, 30);
2124 /* sanity check - see whether command actually completed */
2125 scmd_lookup
= _scsih_scsi_lookup_get(ioc
, smid
);
2126 if (scmd_lookup
&& (scmd_lookup
->serial_number
== scmd
->serial_number
))
2130 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
2131 mutex_unlock(&ioc
->tm_cmds
.mutex
);
2134 printk(MPT2SAS_INFO_FMT
"task abort: %s scmd(%p)\n",
2135 ioc
->name
, ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2140 * _scsih_dev_reset - eh threads main device reset routine
2141 * @sdev: scsi device struct
2143 * Returns SUCCESS if command aborted else FAILED
2146 _scsih_dev_reset(struct scsi_cmnd
*scmd
)
2148 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2149 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2150 struct _sas_device
*sas_device
;
2151 unsigned long flags
;
2155 printk(MPT2SAS_INFO_FMT
"attempting device reset! scmd(%p)\n",
2157 scsi_print_command(scmd
);
2159 sas_device_priv_data
= scmd
->device
->hostdata
;
2160 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2161 printk(MPT2SAS_INFO_FMT
"device been deleted! scmd(%p)\n",
2163 scmd
->result
= DID_NO_CONNECT
<< 16;
2164 scmd
->scsi_done(scmd
);
2169 /* for hidden raid components obtain the volume_handle */
2171 if (sas_device_priv_data
->sas_target
->flags
&
2172 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2173 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2174 sas_device
= _scsih_sas_device_find_by_handle(ioc
,
2175 sas_device_priv_data
->sas_target
->handle
);
2177 handle
= sas_device
->volume_handle
;
2178 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2180 handle
= sas_device_priv_data
->sas_target
->handle
;
2183 scmd
->result
= DID_RESET
<< 16;
2188 mutex_lock(&ioc
->tm_cmds
.mutex
);
2189 mpt2sas_scsih_issue_tm(ioc
, handle
, 0,
2190 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET
, scmd
->device
->lun
,
2194 * sanity check see whether all commands to this device been
2197 if (_scsih_scsi_lookup_find_by_lun(ioc
, scmd
->device
->id
,
2198 scmd
->device
->lun
, scmd
->device
->channel
))
2202 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
2203 mutex_unlock(&ioc
->tm_cmds
.mutex
);
2206 printk(MPT2SAS_INFO_FMT
"device reset: %s scmd(%p)\n",
2207 ioc
->name
, ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2212 * _scsih_target_reset - eh threads main target reset routine
2213 * @sdev: scsi device struct
2215 * Returns SUCCESS if command aborted else FAILED
2218 _scsih_target_reset(struct scsi_cmnd
*scmd
)
2220 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2221 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2222 struct _sas_device
*sas_device
;
2223 unsigned long flags
;
2227 printk(MPT2SAS_INFO_FMT
"attempting target reset! scmd(%p)\n",
2229 scsi_print_command(scmd
);
2231 sas_device_priv_data
= scmd
->device
->hostdata
;
2232 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2233 printk(MPT2SAS_INFO_FMT
"target been deleted! scmd(%p)\n",
2235 scmd
->result
= DID_NO_CONNECT
<< 16;
2236 scmd
->scsi_done(scmd
);
2241 /* for hidden raid components obtain the volume_handle */
2243 if (sas_device_priv_data
->sas_target
->flags
&
2244 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2245 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2246 sas_device
= _scsih_sas_device_find_by_handle(ioc
,
2247 sas_device_priv_data
->sas_target
->handle
);
2249 handle
= sas_device
->volume_handle
;
2250 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2252 handle
= sas_device_priv_data
->sas_target
->handle
;
2255 scmd
->result
= DID_RESET
<< 16;
2260 mutex_lock(&ioc
->tm_cmds
.mutex
);
2261 mpt2sas_scsih_issue_tm(ioc
, handle
, 0,
2262 MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
, 0, 30);
2265 * sanity check see whether all commands to this target been
2268 if (_scsih_scsi_lookup_find_by_target(ioc
, scmd
->device
->id
,
2269 scmd
->device
->channel
))
2273 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
2274 mutex_unlock(&ioc
->tm_cmds
.mutex
);
2277 printk(MPT2SAS_INFO_FMT
"target reset: %s scmd(%p)\n",
2278 ioc
->name
, ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2283 * _scsih_host_reset - eh threads main host reset routine
2284 * @sdev: scsi device struct
2286 * Returns SUCCESS if command aborted else FAILED
2289 _scsih_host_reset(struct scsi_cmnd
*scmd
)
2291 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2294 printk(MPT2SAS_INFO_FMT
"attempting host reset! scmd(%p)\n",
2296 scsi_print_command(scmd
);
2298 retval
= mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2300 r
= (retval
< 0) ? FAILED
: SUCCESS
;
2301 printk(MPT2SAS_INFO_FMT
"host reset: %s scmd(%p)\n",
2302 ioc
->name
, ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2308 * _scsih_fw_event_add - insert and queue up fw_event
2309 * @ioc: per adapter object
2310 * @fw_event: object describing the event
2311 * Context: This function will acquire ioc->fw_event_lock.
2313 * This adds the firmware event object into link list, then queues it up to
2314 * be processed from user context.
2319 _scsih_fw_event_add(struct MPT2SAS_ADAPTER
*ioc
, struct fw_event_work
*fw_event
)
2321 unsigned long flags
;
2323 if (ioc
->firmware_event_thread
== NULL
)
2326 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2327 list_add_tail(&fw_event
->list
, &ioc
->fw_event_list
);
2328 INIT_WORK(&fw_event
->work
, _firmware_event_work
);
2329 queue_work(ioc
->firmware_event_thread
, &fw_event
->work
);
2330 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2334 * _scsih_fw_event_free - delete fw_event
2335 * @ioc: per adapter object
2336 * @fw_event: object describing the event
2337 * Context: This function will acquire ioc->fw_event_lock.
2339 * This removes firmware event object from link list, frees associated memory.
2344 _scsih_fw_event_free(struct MPT2SAS_ADAPTER
*ioc
, struct fw_event_work
2347 unsigned long flags
;
2349 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2350 list_del(&fw_event
->list
);
2351 kfree(fw_event
->event_data
);
2353 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2357 * _scsih_fw_event_add - requeue an event
2358 * @ioc: per adapter object
2359 * @fw_event: object describing the event
2360 * Context: This function will acquire ioc->fw_event_lock.
2365 _scsih_fw_event_requeue(struct MPT2SAS_ADAPTER
*ioc
, struct fw_event_work
2366 *fw_event
, unsigned long delay
)
2368 unsigned long flags
;
2369 if (ioc
->firmware_event_thread
== NULL
)
2372 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2373 queue_work(ioc
->firmware_event_thread
, &fw_event
->work
);
2374 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2378 * _scsih_fw_event_off - turn flag off preventing event handling
2379 * @ioc: per adapter object
2381 * Used to prevent handling of firmware events during adapter reset
2387 _scsih_fw_event_off(struct MPT2SAS_ADAPTER
*ioc
)
2389 unsigned long flags
;
2391 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2392 ioc
->fw_events_off
= 1;
2393 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2398 * _scsih_fw_event_on - turn flag on allowing firmware event handling
2399 * @ioc: per adapter object
2404 _scsih_fw_event_on(struct MPT2SAS_ADAPTER
*ioc
)
2406 unsigned long flags
;
2408 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2409 ioc
->fw_events_off
= 0;
2410 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2414 * _scsih_ublock_io_device - set the device state to SDEV_RUNNING
2415 * @ioc: per adapter object
2416 * @handle: device handle
2418 * During device pull we need to appropiately set the sdev state.
2421 _scsih_ublock_io_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
2423 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2424 struct scsi_device
*sdev
;
2426 shost_for_each_device(sdev
, ioc
->shost
) {
2427 sas_device_priv_data
= sdev
->hostdata
;
2428 if (!sas_device_priv_data
)
2430 if (!sas_device_priv_data
->block
)
2432 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2433 dewtprintk(ioc
, sdev_printk(KERN_INFO
, sdev
,
2434 MPT2SAS_INFO_FMT
"SDEV_RUNNING: "
2435 "handle(0x%04x)\n", ioc
->name
, handle
));
2436 sas_device_priv_data
->block
= 0;
2437 scsi_internal_device_unblock(sdev
);
2443 * _scsih_block_io_device - set the device state to SDEV_BLOCK
2444 * @ioc: per adapter object
2445 * @handle: device handle
2447 * During device pull we need to appropiately set the sdev state.
2450 _scsih_block_io_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
2452 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2453 struct scsi_device
*sdev
;
2455 shost_for_each_device(sdev
, ioc
->shost
) {
2456 sas_device_priv_data
= sdev
->hostdata
;
2457 if (!sas_device_priv_data
)
2459 if (sas_device_priv_data
->block
)
2461 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2462 dewtprintk(ioc
, sdev_printk(KERN_INFO
, sdev
,
2463 MPT2SAS_INFO_FMT
"SDEV_BLOCK: "
2464 "handle(0x%04x)\n", ioc
->name
, handle
));
2465 sas_device_priv_data
->block
= 1;
2466 scsi_internal_device_block(sdev
);
2472 * _scsih_block_io_to_children_attached_to_ex
2473 * @ioc: per adapter object
2474 * @sas_expander: the sas_device object
2476 * This routine set sdev state to SDEV_BLOCK for all devices
2477 * attached to this expander. This function called when expander is
2481 _scsih_block_io_to_children_attached_to_ex(struct MPT2SAS_ADAPTER
*ioc
,
2482 struct _sas_node
*sas_expander
)
2484 struct _sas_port
*mpt2sas_port
;
2485 struct _sas_device
*sas_device
;
2486 struct _sas_node
*expander_sibling
;
2487 unsigned long flags
;
2492 list_for_each_entry(mpt2sas_port
,
2493 &sas_expander
->sas_port_list
, port_list
) {
2494 if (mpt2sas_port
->remote_identify
.device_type
==
2496 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2498 mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
2499 mpt2sas_port
->remote_identify
.sas_address
);
2500 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2503 _scsih_block_io_device(ioc
, sas_device
->handle
);
2507 list_for_each_entry(mpt2sas_port
,
2508 &sas_expander
->sas_port_list
, port_list
) {
2510 if (mpt2sas_port
->remote_identify
.device_type
==
2511 MPI2_SAS_DEVICE_INFO_EDGE_EXPANDER
||
2512 mpt2sas_port
->remote_identify
.device_type
==
2513 MPI2_SAS_DEVICE_INFO_FANOUT_EXPANDER
) {
2515 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
2517 mpt2sas_scsih_expander_find_by_sas_address(
2518 ioc
, mpt2sas_port
->remote_identify
.sas_address
);
2519 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
2520 _scsih_block_io_to_children_attached_to_ex(ioc
,
2527 * _scsih_block_io_to_children_attached_directly
2528 * @ioc: per adapter object
2529 * @event_data: topology change event data
2531 * This routine set sdev state to SDEV_BLOCK for all devices
2532 * direct attached during device pull.
2535 _scsih_block_io_to_children_attached_directly(struct MPT2SAS_ADAPTER
*ioc
,
2536 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
2543 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
2544 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
2547 phy_number
= event_data
->StartPhyNum
+ i
;
2548 reason_code
= event_data
->PHY
[i
].PhyStatus
&
2549 MPI2_EVENT_SAS_TOPO_RC_MASK
;
2550 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
)
2551 _scsih_block_io_device(ioc
, handle
);
2556 * _scsih_tm_tr_send - send task management request
2557 * @ioc: per adapter object
2558 * @handle: device handle
2559 * Context: interrupt time.
2561 * This code is to initiate the device removal handshake protocal
2562 * with controller firmware. This function will issue target reset
2563 * using high priority request queue. It will send a sas iounit
2564 * controll request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
2566 * This is designed to send muliple task management request at the same
2567 * time to the fifo. If the fifo is full, we will append the request,
2568 * and process it in a future completion.
2571 _scsih_tm_tr_send(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
2573 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
2574 struct MPT2SAS_TARGET
*sas_target_priv_data
;
2576 struct _sas_device
*sas_device
;
2577 unsigned long flags
;
2578 struct _tr_list
*delayed_tr
;
2580 if (ioc
->shost_recovery
) {
2581 printk(MPT2SAS_INFO_FMT
"%s: host reset in progress!\n",
2582 __func__
, ioc
->name
);
2586 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2587 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
2588 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2590 /* skip is hidden raid component */
2591 if (sas_device
&& sas_device
->hidden_raid_component
)
2594 smid
= mpt2sas_base_get_smid_hpr(ioc
, ioc
->tm_tr_cb_idx
);
2596 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
2599 INIT_LIST_HEAD(&delayed_tr
->list
);
2600 delayed_tr
->handle
= handle
;
2601 delayed_tr
->state
= MPT2SAS_REQ_SAS_CNTRL
;
2602 list_add_tail(&delayed_tr
->list
,
2603 &ioc
->delayed_tr_list
);
2604 if (sas_device
&& sas_device
->starget
) {
2605 dewtprintk(ioc
, starget_printk(KERN_INFO
,
2606 sas_device
->starget
, "DELAYED:tr:handle(0x%04x), "
2607 "(open)\n", handle
));
2609 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
2610 "DELAYED:tr:handle(0x%04x), (open)\n",
2611 ioc
->name
, handle
));
2617 sas_device
->state
|= MPTSAS_STATE_TR_SEND
;
2618 sas_device
->state
|= MPT2SAS_REQ_SAS_CNTRL
;
2619 if (sas_device
->starget
&& sas_device
->starget
->hostdata
) {
2620 sas_target_priv_data
= sas_device
->starget
->hostdata
;
2621 sas_target_priv_data
->tm_busy
= 1;
2622 dewtprintk(ioc
, starget_printk(KERN_INFO
,
2623 sas_device
->starget
, "tr:handle(0x%04x), (open)\n",
2627 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
2628 "tr:handle(0x%04x), (open)\n", ioc
->name
, handle
));
2631 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
2632 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
2633 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
2634 mpi_request
->DevHandle
= cpu_to_le16(handle
);
2635 mpi_request
->TaskType
= MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
;
2636 mpt2sas_base_put_smid_hi_priority(ioc
, smid
);
2642 * _scsih_sas_control_complete - completion routine
2643 * @ioc: per adapter object
2644 * @smid: system request message index
2645 * @msix_index: MSIX table index supplied by the OS
2646 * @reply: reply message frame(lower 32bit addr)
2647 * Context: interrupt time.
2649 * This is the sas iounit controll completion routine.
2650 * This code is part of the code to initiate the device removal
2651 * handshake protocal with controller firmware.
2653 * Return 1 meaning mf should be freed from _base_interrupt
2654 * 0 means the mf is freed from this function.
2657 _scsih_sas_control_complete(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
,
2658 u8 msix_index
, u32 reply
)
2660 unsigned long flags
;
2662 struct _sas_device
*sas_device
;
2663 Mpi2SasIoUnitControlReply_t
*mpi_reply
=
2664 mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
2666 handle
= le16_to_cpu(mpi_reply
->DevHandle
);
2668 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2669 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
2670 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2673 sas_device
->state
|= MPTSAS_STATE_CNTRL_COMPLETE
;
2674 if (sas_device
->starget
)
2675 dewtprintk(ioc
, starget_printk(KERN_INFO
,
2676 sas_device
->starget
,
2677 "sc_complete:handle(0x%04x), "
2678 "ioc_status(0x%04x), loginfo(0x%08x)\n",
2679 handle
, le16_to_cpu(mpi_reply
->IOCStatus
),
2680 le32_to_cpu(mpi_reply
->IOCLogInfo
)));
2682 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
2683 "sc_complete:handle(0x%04x), "
2684 "ioc_status(0x%04x), loginfo(0x%08x)\n",
2685 ioc
->name
, handle
, le16_to_cpu(mpi_reply
->IOCStatus
),
2686 le32_to_cpu(mpi_reply
->IOCLogInfo
)));
2693 * _scsih_tm_tr_complete -
2694 * @ioc: per adapter object
2695 * @smid: system request message index
2696 * @msix_index: MSIX table index supplied by the OS
2697 * @reply: reply message frame(lower 32bit addr)
2698 * Context: interrupt time.
2700 * This is the target reset completion routine.
2701 * This code is part of the code to initiate the device removal
2702 * handshake protocal with controller firmware.
2703 * It will send a sas iounit controll request (MPI2_SAS_OP_REMOVE_DEVICE)
2705 * Return 1 meaning mf should be freed from _base_interrupt
2706 * 0 means the mf is freed from this function.
2709 _scsih_tm_tr_complete(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
,
2712 unsigned long flags
;
2714 struct _sas_device
*sas_device
;
2715 Mpi2SCSITaskManagementReply_t
*mpi_reply
=
2716 mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
2717 Mpi2SasIoUnitControlRequest_t
*mpi_request
;
2719 struct MPT2SAS_TARGET
*sas_target_priv_data
;
2720 struct _tr_list
*delayed_tr
;
2723 handle
= le16_to_cpu(mpi_reply
->DevHandle
);
2724 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2725 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
2726 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2729 sas_device
->state
|= MPTSAS_STATE_TR_COMPLETE
;
2730 if (sas_device
->starget
) {
2731 dewtprintk(ioc
, starget_printk(KERN_INFO
,
2732 sas_device
->starget
, "tr_complete:handle(0x%04x), "
2733 "(%s) ioc_status(0x%04x), loginfo(0x%08x), "
2734 "completed(%d)\n", sas_device
->handle
,
2735 (sas_device
->state
& MPT2SAS_REQ_SAS_CNTRL
) ?
2737 le16_to_cpu(mpi_reply
->IOCStatus
),
2738 le32_to_cpu(mpi_reply
->IOCLogInfo
),
2739 le32_to_cpu(mpi_reply
->TerminationCount
)));
2740 if (sas_device
->starget
->hostdata
) {
2741 sas_target_priv_data
=
2742 sas_device
->starget
->hostdata
;
2743 sas_target_priv_data
->tm_busy
= 0;
2747 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
2748 "tr_complete:handle(0x%04x), (open) ioc_status(0x%04x), "
2749 "loginfo(0x%08x), completed(%d)\n", ioc
->name
,
2750 handle
, le16_to_cpu(mpi_reply
->IOCStatus
),
2751 le32_to_cpu(mpi_reply
->IOCLogInfo
),
2752 le32_to_cpu(mpi_reply
->TerminationCount
)));
2755 if (!list_empty(&ioc
->delayed_tr_list
)) {
2756 delayed_tr
= list_entry(ioc
->delayed_tr_list
.next
,
2757 struct _tr_list
, list
);
2758 mpt2sas_base_free_smid(ioc
, smid
);
2759 if (delayed_tr
->state
& MPT2SAS_REQ_SAS_CNTRL
)
2760 _scsih_tm_tr_send(ioc
, delayed_tr
->handle
);
2761 list_del(&delayed_tr
->list
);
2763 rc
= 0; /* tells base_interrupt not to free mf */
2767 if (sas_device
&& !(sas_device
->state
& MPT2SAS_REQ_SAS_CNTRL
))
2770 if (ioc
->shost_recovery
) {
2771 printk(MPT2SAS_INFO_FMT
"%s: host reset in progress!\n",
2772 __func__
, ioc
->name
);
2776 smid_sas_ctrl
= mpt2sas_base_get_smid(ioc
, ioc
->tm_sas_control_cb_idx
);
2777 if (!smid_sas_ctrl
) {
2778 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
2779 ioc
->name
, __func__
);
2784 sas_device
->state
|= MPTSAS_STATE_CNTRL_SEND
;
2786 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid_sas_ctrl
);
2787 memset(mpi_request
, 0, sizeof(Mpi2SasIoUnitControlRequest_t
));
2788 mpi_request
->Function
= MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
;
2789 mpi_request
->Operation
= MPI2_SAS_OP_REMOVE_DEVICE
;
2790 mpi_request
->DevHandle
= mpi_reply
->DevHandle
;
2791 mpt2sas_base_put_smid_default(ioc
, smid_sas_ctrl
);
2796 * _scsih_check_topo_delete_events - sanity check on topo events
2797 * @ioc: per adapter object
2798 * @event_data: the event data payload
2800 * This routine added to better handle cable breaker.
2802 * This handles the case where driver recieves multiple expander
2803 * add and delete events in a single shot. When there is a delete event
2804 * the routine will void any pending add events waiting in the event queue.
2809 _scsih_check_topo_delete_events(struct MPT2SAS_ADAPTER
*ioc
,
2810 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
2812 struct fw_event_work
*fw_event
;
2813 Mpi2EventDataSasTopologyChangeList_t
*local_event_data
;
2814 u16 expander_handle
;
2815 struct _sas_node
*sas_expander
;
2816 unsigned long flags
;
2820 for (i
= 0 ; i
< event_data
->NumEntries
; i
++) {
2821 if (event_data
->PHY
[i
].PhyStatus
&
2822 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT
)
2824 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
2827 reason_code
= event_data
->PHY
[i
].PhyStatus
&
2828 MPI2_EVENT_SAS_TOPO_RC_MASK
;
2829 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
)
2830 _scsih_tm_tr_send(ioc
, handle
);
2833 expander_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
2834 if (expander_handle
< ioc
->sas_hba
.num_phys
) {
2835 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
2839 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
2840 || event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
) {
2841 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
2842 sas_expander
= mpt2sas_scsih_expander_find_by_handle(ioc
,
2844 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
2845 _scsih_block_io_to_children_attached_to_ex(ioc
, sas_expander
);
2846 } else if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_RESPONDING
)
2847 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
2849 if (event_data
->ExpStatus
!= MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
)
2852 /* mark ignore flag for pending events */
2853 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2854 list_for_each_entry(fw_event
, &ioc
->fw_event_list
, list
) {
2855 if (fw_event
->event
!= MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
||
2858 local_event_data
= fw_event
->event_data
;
2859 if (local_event_data
->ExpStatus
==
2860 MPI2_EVENT_SAS_TOPO_ES_ADDED
||
2861 local_event_data
->ExpStatus
==
2862 MPI2_EVENT_SAS_TOPO_ES_RESPONDING
) {
2863 if (le16_to_cpu(local_event_data
->ExpanderDevHandle
) ==
2865 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
2866 "setting ignoring flag\n", ioc
->name
));
2867 fw_event
->ignore
= 1;
2871 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2875 * _scsih_flush_running_cmds - completing outstanding commands.
2876 * @ioc: per adapter object
2878 * The flushing out of all pending scmd commands following host reset,
2879 * where all IO is dropped to the floor.
2884 _scsih_flush_running_cmds(struct MPT2SAS_ADAPTER
*ioc
)
2886 struct scsi_cmnd
*scmd
;
2890 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
2891 scmd
= _scsih_scsi_lookup_get(ioc
, smid
);
2895 mpt2sas_base_free_smid(ioc
, smid
);
2896 scsi_dma_unmap(scmd
);
2897 scmd
->result
= DID_RESET
<< 16;
2898 scmd
->scsi_done(scmd
);
2900 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"completing %d cmds\n",
2905 * _scsih_setup_eedp - setup MPI request for EEDP transfer
2906 * @scmd: pointer to scsi command object
2907 * @mpi_request: pointer to the SCSI_IO reqest message frame
2909 * Supporting protection 1 and 3.
2914 _scsih_setup_eedp(struct scsi_cmnd
*scmd
, Mpi2SCSIIORequest_t
*mpi_request
)
2917 unsigned char prot_op
= scsi_get_prot_op(scmd
);
2918 unsigned char prot_type
= scsi_get_prot_type(scmd
);
2920 if (prot_type
== SCSI_PROT_DIF_TYPE0
||
2921 prot_type
== SCSI_PROT_DIF_TYPE2
||
2922 prot_op
== SCSI_PROT_NORMAL
)
2925 if (prot_op
== SCSI_PROT_READ_STRIP
)
2926 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP
;
2927 else if (prot_op
== SCSI_PROT_WRITE_INSERT
)
2928 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_INSERT_OP
;
2932 switch (prot_type
) {
2933 case SCSI_PROT_DIF_TYPE1
:
2936 * enable ref/guard checking
2937 * auto increment ref tag
2939 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG
|
2940 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG
|
2941 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
2942 mpi_request
->CDB
.EEDP32
.PrimaryReferenceTag
=
2943 cpu_to_be32(scsi_get_lba(scmd
));
2947 case SCSI_PROT_DIF_TYPE3
:
2950 * enable guard checking
2952 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
2955 mpi_request
->EEDPBlockSize
= cpu_to_le32(scmd
->device
->sector_size
);
2956 mpi_request
->EEDPFlags
= cpu_to_le16(eedp_flags
);
2960 * _scsih_eedp_error_handling - return sense code for EEDP errors
2961 * @scmd: pointer to scsi command object
2962 * @ioc_status: ioc status
2967 _scsih_eedp_error_handling(struct scsi_cmnd
*scmd
, u16 ioc_status
)
2973 switch (ioc_status
) {
2974 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
2977 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
2980 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
2988 if (scmd
->sc_data_direction
== DMA_TO_DEVICE
) {
2989 sk
= ILLEGAL_REQUEST
;
2990 host_byte
= DID_ABORT
;
2992 sk
= ABORTED_COMMAND
;
2996 scsi_build_sense_buffer(0, scmd
->sense_buffer
, sk
, 0x10, ascq
);
2997 scmd
->result
= DRIVER_SENSE
<< 24 | (host_byte
<< 16) |
2998 SAM_STAT_CHECK_CONDITION
;
3002 * _scsih_qcmd - main scsi request entry point
3003 * @scmd: pointer to scsi command object
3004 * @done: function pointer to be invoked on completion
3006 * The callback index is set inside `ioc->scsi_io_cb_idx`.
3008 * Returns 0 on success. If there's a failure, return either:
3009 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
3010 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
3013 _scsih_qcmd(struct scsi_cmnd
*scmd
, void (*done
)(struct scsi_cmnd
*))
3015 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
3016 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
3017 struct MPT2SAS_TARGET
*sas_target_priv_data
;
3018 Mpi2SCSIIORequest_t
*mpi_request
;
3022 scmd
->scsi_done
= done
;
3023 sas_device_priv_data
= scmd
->device
->hostdata
;
3024 if (!sas_device_priv_data
) {
3025 scmd
->result
= DID_NO_CONNECT
<< 16;
3026 scmd
->scsi_done(scmd
);
3030 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
3031 if (!sas_target_priv_data
|| sas_target_priv_data
->handle
==
3032 MPT2SAS_INVALID_DEVICE_HANDLE
|| sas_target_priv_data
->deleted
) {
3033 scmd
->result
= DID_NO_CONNECT
<< 16;
3034 scmd
->scsi_done(scmd
);
3038 /* see if we are busy with task managment stuff */
3039 if (sas_device_priv_data
->block
|| sas_target_priv_data
->tm_busy
)
3040 return SCSI_MLQUEUE_DEVICE_BUSY
;
3041 else if (ioc
->shost_recovery
|| ioc
->ioc_link_reset_in_progress
)
3042 return SCSI_MLQUEUE_HOST_BUSY
;
3044 if (scmd
->sc_data_direction
== DMA_FROM_DEVICE
)
3045 mpi_control
= MPI2_SCSIIO_CONTROL_READ
;
3046 else if (scmd
->sc_data_direction
== DMA_TO_DEVICE
)
3047 mpi_control
= MPI2_SCSIIO_CONTROL_WRITE
;
3049 mpi_control
= MPI2_SCSIIO_CONTROL_NODATATRANSFER
;
3052 if (!(sas_device_priv_data
->flags
& MPT_DEVICE_FLAGS_INIT
)) {
3053 if (scmd
->device
->tagged_supported
) {
3054 if (scmd
->device
->ordered_tags
)
3055 mpi_control
|= MPI2_SCSIIO_CONTROL_ORDEREDQ
;
3057 mpi_control
|= MPI2_SCSIIO_CONTROL_SIMPLEQ
;
3059 /* MPI Revision I (UNIT = 0xA) - removed MPI2_SCSIIO_CONTROL_UNTAGGED */
3060 /* mpi_control |= MPI2_SCSIIO_CONTROL_UNTAGGED;
3062 mpi_control
|= (0x500);
3065 mpi_control
|= MPI2_SCSIIO_CONTROL_SIMPLEQ
;
3066 /* Make sure Device is not raid volume */
3067 if (!_scsih_is_raid(&scmd
->device
->sdev_gendev
) &&
3068 sas_is_tlr_enabled(scmd
->device
))
3069 mpi_control
|= MPI2_SCSIIO_CONTROL_TLR_ON
;
3071 smid
= mpt2sas_base_get_smid_scsiio(ioc
, ioc
->scsi_io_cb_idx
, scmd
);
3073 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
3074 ioc
->name
, __func__
);
3077 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3078 memset(mpi_request
, 0, sizeof(Mpi2SCSIIORequest_t
));
3079 _scsih_setup_eedp(scmd
, mpi_request
);
3080 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
3081 if (sas_device_priv_data
->sas_target
->flags
&
3082 MPT_TARGET_FLAGS_RAID_COMPONENT
)
3083 mpi_request
->Function
= MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
;
3085 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
3086 mpi_request
->DevHandle
=
3087 cpu_to_le16(sas_device_priv_data
->sas_target
->handle
);
3088 mpi_request
->DataLength
= cpu_to_le32(scsi_bufflen(scmd
));
3089 mpi_request
->Control
= cpu_to_le32(mpi_control
);
3090 mpi_request
->IoFlags
= cpu_to_le16(scmd
->cmd_len
);
3091 mpi_request
->MsgFlags
= MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR
;
3092 mpi_request
->SenseBufferLength
= SCSI_SENSE_BUFFERSIZE
;
3093 mpi_request
->SenseBufferLowAddress
=
3094 mpt2sas_base_get_sense_buffer_dma(ioc
, smid
);
3095 mpi_request
->SGLOffset0
= offsetof(Mpi2SCSIIORequest_t
, SGL
) / 4;
3096 mpi_request
->SGLFlags
= cpu_to_le16(MPI2_SCSIIO_SGLFLAGS_TYPE_MPI
+
3097 MPI2_SCSIIO_SGLFLAGS_SYSTEM_ADDR
);
3098 mpi_request
->VF_ID
= 0; /* TODO */
3099 mpi_request
->VP_ID
= 0;
3100 int_to_scsilun(sas_device_priv_data
->lun
, (struct scsi_lun
*)
3102 memcpy(mpi_request
->CDB
.CDB32
, scmd
->cmnd
, scmd
->cmd_len
);
3104 if (!mpi_request
->DataLength
) {
3105 mpt2sas_base_build_zero_len_sge(ioc
, &mpi_request
->SGL
);
3107 if (_scsih_build_scatter_gather(ioc
, scmd
, smid
)) {
3108 mpt2sas_base_free_smid(ioc
, smid
);
3113 mpt2sas_base_put_smid_scsi_io(ioc
, smid
,
3114 sas_device_priv_data
->sas_target
->handle
);
3118 return SCSI_MLQUEUE_HOST_BUSY
;
3122 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
3123 * @sense_buffer: sense data returned by target
3124 * @data: normalized skey/asc/ascq
3129 _scsih_normalize_sense(char *sense_buffer
, struct sense_info
*data
)
3131 if ((sense_buffer
[0] & 0x7F) >= 0x72) {
3132 /* descriptor format */
3133 data
->skey
= sense_buffer
[1] & 0x0F;
3134 data
->asc
= sense_buffer
[2];
3135 data
->ascq
= sense_buffer
[3];
3138 data
->skey
= sense_buffer
[2] & 0x0F;
3139 data
->asc
= sense_buffer
[12];
3140 data
->ascq
= sense_buffer
[13];
3144 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3146 * _scsih_scsi_ioc_info - translated non-successfull SCSI_IO request
3147 * @ioc: per adapter object
3148 * @scmd: pointer to scsi command object
3149 * @mpi_reply: reply mf payload returned from firmware
3151 * scsi_status - SCSI Status code returned from target device
3152 * scsi_state - state info associated with SCSI_IO determined by ioc
3153 * ioc_status - ioc supplied status info
3158 _scsih_scsi_ioc_info(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
,
3159 Mpi2SCSIIOReply_t
*mpi_reply
, u16 smid
)
3163 u16 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) &
3164 MPI2_IOCSTATUS_MASK
;
3165 u8 scsi_state
= mpi_reply
->SCSIState
;
3166 u8 scsi_status
= mpi_reply
->SCSIStatus
;
3167 char *desc_ioc_state
= NULL
;
3168 char *desc_scsi_status
= NULL
;
3169 char *desc_scsi_state
= ioc
->tmp_string
;
3170 u32 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
3172 if (log_info
== 0x31170000)
3175 switch (ioc_status
) {
3176 case MPI2_IOCSTATUS_SUCCESS
:
3177 desc_ioc_state
= "success";
3179 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
3180 desc_ioc_state
= "invalid function";
3182 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
3183 desc_ioc_state
= "scsi recovered error";
3185 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE
:
3186 desc_ioc_state
= "scsi invalid dev handle";
3188 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
3189 desc_ioc_state
= "scsi device not there";
3191 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
3192 desc_ioc_state
= "scsi data overrun";
3194 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
3195 desc_ioc_state
= "scsi data underrun";
3197 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
3198 desc_ioc_state
= "scsi io data error";
3200 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
3201 desc_ioc_state
= "scsi protocol error";
3203 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
3204 desc_ioc_state
= "scsi task terminated";
3206 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
3207 desc_ioc_state
= "scsi residual mismatch";
3209 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
3210 desc_ioc_state
= "scsi task mgmt failed";
3212 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
3213 desc_ioc_state
= "scsi ioc terminated";
3215 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
3216 desc_ioc_state
= "scsi ext terminated";
3218 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
3219 desc_ioc_state
= "eedp guard error";
3221 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
3222 desc_ioc_state
= "eedp ref tag error";
3224 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
3225 desc_ioc_state
= "eedp app tag error";
3228 desc_ioc_state
= "unknown";
3232 switch (scsi_status
) {
3233 case MPI2_SCSI_STATUS_GOOD
:
3234 desc_scsi_status
= "good";
3236 case MPI2_SCSI_STATUS_CHECK_CONDITION
:
3237 desc_scsi_status
= "check condition";
3239 case MPI2_SCSI_STATUS_CONDITION_MET
:
3240 desc_scsi_status
= "condition met";
3242 case MPI2_SCSI_STATUS_BUSY
:
3243 desc_scsi_status
= "busy";
3245 case MPI2_SCSI_STATUS_INTERMEDIATE
:
3246 desc_scsi_status
= "intermediate";
3248 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET
:
3249 desc_scsi_status
= "intermediate condmet";
3251 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT
:
3252 desc_scsi_status
= "reservation conflict";
3254 case MPI2_SCSI_STATUS_COMMAND_TERMINATED
:
3255 desc_scsi_status
= "command terminated";
3257 case MPI2_SCSI_STATUS_TASK_SET_FULL
:
3258 desc_scsi_status
= "task set full";
3260 case MPI2_SCSI_STATUS_ACA_ACTIVE
:
3261 desc_scsi_status
= "aca active";
3263 case MPI2_SCSI_STATUS_TASK_ABORTED
:
3264 desc_scsi_status
= "task aborted";
3267 desc_scsi_status
= "unknown";
3271 desc_scsi_state
[0] = '\0';
3273 desc_scsi_state
= " ";
3274 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
3275 strcat(desc_scsi_state
, "response info ");
3276 if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
3277 strcat(desc_scsi_state
, "state terminated ");
3278 if (scsi_state
& MPI2_SCSI_STATE_NO_SCSI_STATUS
)
3279 strcat(desc_scsi_state
, "no status ");
3280 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_FAILED
)
3281 strcat(desc_scsi_state
, "autosense failed ");
3282 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
)
3283 strcat(desc_scsi_state
, "autosense valid ");
3285 scsi_print_command(scmd
);
3286 printk(MPT2SAS_WARN_FMT
"\tdev handle(0x%04x), "
3287 "ioc_status(%s)(0x%04x), smid(%d)\n", ioc
->name
,
3288 le16_to_cpu(mpi_reply
->DevHandle
), desc_ioc_state
,
3290 printk(MPT2SAS_WARN_FMT
"\trequest_len(%d), underflow(%d), "
3291 "resid(%d)\n", ioc
->name
, scsi_bufflen(scmd
), scmd
->underflow
,
3292 scsi_get_resid(scmd
));
3293 printk(MPT2SAS_WARN_FMT
"\ttag(%d), transfer_count(%d), "
3294 "sc->result(0x%08x)\n", ioc
->name
, le16_to_cpu(mpi_reply
->TaskTag
),
3295 le32_to_cpu(mpi_reply
->TransferCount
), scmd
->result
);
3296 printk(MPT2SAS_WARN_FMT
"\tscsi_status(%s)(0x%02x), "
3297 "scsi_state(%s)(0x%02x)\n", ioc
->name
, desc_scsi_status
,
3298 scsi_status
, desc_scsi_state
, scsi_state
);
3300 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
3301 struct sense_info data
;
3302 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
3303 printk(MPT2SAS_WARN_FMT
"\t[sense_key,asc,ascq]: "
3304 "[0x%02x,0x%02x,0x%02x]\n", ioc
->name
, data
.skey
,
3305 data
.asc
, data
.ascq
);
3308 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
) {
3309 response_info
= le32_to_cpu(mpi_reply
->ResponseInfo
);
3310 response_bytes
= (u8
*)&response_info
;
3311 _scsih_response_code(ioc
, response_bytes
[0]);
3317 * _scsih_smart_predicted_fault - illuminate Fault LED
3318 * @ioc: per adapter object
3319 * @handle: device handle
3324 _scsih_smart_predicted_fault(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
3326 Mpi2SepReply_t mpi_reply
;
3327 Mpi2SepRequest_t mpi_request
;
3328 struct scsi_target
*starget
;
3329 struct MPT2SAS_TARGET
*sas_target_priv_data
;
3330 Mpi2EventNotificationReply_t
*event_reply
;
3331 Mpi2EventDataSasDeviceStatusChange_t
*event_data
;
3332 struct _sas_device
*sas_device
;
3334 unsigned long flags
;
3336 /* only handle non-raid devices */
3337 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
3338 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
3340 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3343 starget
= sas_device
->starget
;
3344 sas_target_priv_data
= starget
->hostdata
;
3346 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
) ||
3347 ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
))) {
3348 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3351 starget_printk(KERN_WARNING
, starget
, "predicted fault\n");
3352 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3354 if (ioc
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_IBM
) {
3355 memset(&mpi_request
, 0, sizeof(Mpi2SepRequest_t
));
3356 mpi_request
.Function
= MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR
;
3357 mpi_request
.Action
= MPI2_SEP_REQ_ACTION_WRITE_STATUS
;
3358 mpi_request
.SlotStatus
=
3359 MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT
;
3360 mpi_request
.DevHandle
= cpu_to_le16(handle
);
3361 mpi_request
.Flags
= MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS
;
3362 if ((mpt2sas_base_scsi_enclosure_processor(ioc
, &mpi_reply
,
3363 &mpi_request
)) != 0) {
3364 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3365 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3369 if (mpi_reply
.IOCStatus
|| mpi_reply
.IOCLogInfo
) {
3370 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3371 "enclosure_processor: ioc_status (0x%04x), "
3372 "loginfo(0x%08x)\n", ioc
->name
,
3373 le16_to_cpu(mpi_reply
.IOCStatus
),
3374 le32_to_cpu(mpi_reply
.IOCLogInfo
)));
3379 /* insert into event log */
3380 sz
= offsetof(Mpi2EventNotificationReply_t
, EventData
) +
3381 sizeof(Mpi2EventDataSasDeviceStatusChange_t
);
3382 event_reply
= kzalloc(sz
, GFP_KERNEL
);
3384 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3385 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3389 event_reply
->Function
= MPI2_FUNCTION_EVENT_NOTIFICATION
;
3390 event_reply
->Event
=
3391 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
);
3392 event_reply
->MsgLength
= sz
/4;
3393 event_reply
->EventDataLength
=
3394 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t
)/4);
3395 event_data
= (Mpi2EventDataSasDeviceStatusChange_t
*)
3396 event_reply
->EventData
;
3397 event_data
->ReasonCode
= MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
;
3398 event_data
->ASC
= 0x5D;
3399 event_data
->DevHandle
= cpu_to_le16(handle
);
3400 event_data
->SASAddress
= cpu_to_le64(sas_target_priv_data
->sas_address
);
3401 mpt2sas_ctl_add_to_event_log(ioc
, event_reply
);
3406 * _scsih_io_done - scsi request callback
3407 * @ioc: per adapter object
3408 * @smid: system request message index
3409 * @msix_index: MSIX table index supplied by the OS
3410 * @reply: reply message frame(lower 32bit addr)
3412 * Callback handler when using _scsih_qcmd.
3414 * Return 1 meaning mf should be freed from _base_interrupt
3415 * 0 means the mf is freed from this function.
3418 _scsih_io_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
3420 Mpi2SCSIIORequest_t
*mpi_request
;
3421 Mpi2SCSIIOReply_t
*mpi_reply
;
3422 struct scsi_cmnd
*scmd
;
3428 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
3429 u32 response_code
= 0;
3431 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
3432 scmd
= _scsih_scsi_lookup_get(ioc
, smid
);
3436 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3438 if (mpi_reply
== NULL
) {
3439 scmd
->result
= DID_OK
<< 16;
3443 sas_device_priv_data
= scmd
->device
->hostdata
;
3444 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
||
3445 sas_device_priv_data
->sas_target
->deleted
) {
3446 scmd
->result
= DID_NO_CONNECT
<< 16;
3450 /* turning off TLR */
3451 scsi_state
= mpi_reply
->SCSIState
;
3452 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
3454 le32_to_cpu(mpi_reply
->ResponseInfo
) & 0xFF;
3455 if (!sas_device_priv_data
->tlr_snoop_check
) {
3456 sas_device_priv_data
->tlr_snoop_check
++;
3457 if (!_scsih_is_raid(&scmd
->device
->sdev_gendev
) &&
3458 sas_is_tlr_enabled(scmd
->device
) &&
3459 response_code
== MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
) {
3460 sas_disable_tlr(scmd
->device
);
3461 sdev_printk(KERN_INFO
, scmd
->device
, "TLR disabled\n");
3465 xfer_cnt
= le32_to_cpu(mpi_reply
->TransferCount
);
3466 scsi_set_resid(scmd
, scsi_bufflen(scmd
) - xfer_cnt
);
3467 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
);
3468 if (ioc_status
& MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE
)
3469 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
3472 ioc_status
&= MPI2_IOCSTATUS_MASK
;
3473 scsi_status
= mpi_reply
->SCSIStatus
;
3475 if (ioc_status
== MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
&& xfer_cnt
== 0 &&
3476 (scsi_status
== MPI2_SCSI_STATUS_BUSY
||
3477 scsi_status
== MPI2_SCSI_STATUS_RESERVATION_CONFLICT
||
3478 scsi_status
== MPI2_SCSI_STATUS_TASK_SET_FULL
)) {
3479 ioc_status
= MPI2_IOCSTATUS_SUCCESS
;
3482 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
3483 struct sense_info data
;
3484 const void *sense_data
= mpt2sas_base_get_sense_buffer(ioc
,
3486 u32 sz
= min_t(u32
, SCSI_SENSE_BUFFERSIZE
,
3487 le32_to_cpu(mpi_reply
->SenseCount
));
3488 memcpy(scmd
->sense_buffer
, sense_data
, sz
);
3489 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
3490 /* failure prediction threshold exceeded */
3491 if (data
.asc
== 0x5D)
3492 _scsih_smart_predicted_fault(ioc
,
3493 le16_to_cpu(mpi_reply
->DevHandle
));
3496 switch (ioc_status
) {
3497 case MPI2_IOCSTATUS_BUSY
:
3498 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES
:
3499 scmd
->result
= SAM_STAT_BUSY
;
3502 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
3503 scmd
->result
= DID_NO_CONNECT
<< 16;
3506 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
3507 if (sas_device_priv_data
->block
) {
3508 scmd
->result
= DID_TRANSPORT_DISRUPTED
<< 16;
3511 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
3512 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
3513 scmd
->result
= DID_RESET
<< 16;
3516 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
3517 if ((xfer_cnt
== 0) || (scmd
->underflow
> xfer_cnt
))
3518 scmd
->result
= DID_SOFT_ERROR
<< 16;
3520 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
3523 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
3524 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
3526 if ((scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
))
3529 if (xfer_cnt
< scmd
->underflow
) {
3530 if (scsi_status
== SAM_STAT_BUSY
)
3531 scmd
->result
= SAM_STAT_BUSY
;
3533 scmd
->result
= DID_SOFT_ERROR
<< 16;
3534 } else if (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;
3539 else if (!xfer_cnt
&& scmd
->cmnd
[0] == REPORT_LUNS
) {
3540 mpi_reply
->SCSIState
= MPI2_SCSI_STATE_AUTOSENSE_VALID
;
3541 mpi_reply
->SCSIStatus
= SAM_STAT_CHECK_CONDITION
;
3542 scmd
->result
= (DRIVER_SENSE
<< 24) |
3543 SAM_STAT_CHECK_CONDITION
;
3544 scmd
->sense_buffer
[0] = 0x70;
3545 scmd
->sense_buffer
[2] = ILLEGAL_REQUEST
;
3546 scmd
->sense_buffer
[12] = 0x20;
3547 scmd
->sense_buffer
[13] = 0;
3551 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
3552 scsi_set_resid(scmd
, 0);
3553 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
3554 case MPI2_IOCSTATUS_SUCCESS
:
3555 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
3556 if (response_code
==
3557 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
||
3558 (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
3559 MPI2_SCSI_STATE_NO_SCSI_STATUS
)))
3560 scmd
->result
= DID_SOFT_ERROR
<< 16;
3561 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
3562 scmd
->result
= DID_RESET
<< 16;
3565 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
3566 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
3567 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
3568 _scsih_eedp_error_handling(scmd
, ioc_status
);
3570 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
3571 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
3572 case MPI2_IOCSTATUS_INVALID_SGL
:
3573 case MPI2_IOCSTATUS_INTERNAL_ERROR
:
3574 case MPI2_IOCSTATUS_INVALID_FIELD
:
3575 case MPI2_IOCSTATUS_INVALID_STATE
:
3576 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
3577 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
3579 scmd
->result
= DID_SOFT_ERROR
<< 16;
3584 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3585 if (scmd
->result
&& (ioc
->logging_level
& MPT_DEBUG_REPLY
))
3586 _scsih_scsi_ioc_info(ioc
, scmd
, mpi_reply
, smid
);
3590 scsi_dma_unmap(scmd
);
3591 scmd
->scsi_done(scmd
);
3596 * _scsih_sas_host_refresh - refreshing sas host object contents
3597 * @ioc: per adapter object
3600 * During port enable, fw will send topology events for every device. Its
3601 * possible that the handles may change from the previous setting, so this
3602 * code keeping handles updating if changed.
3607 _scsih_sas_host_refresh(struct MPT2SAS_ADAPTER
*ioc
)
3612 Mpi2ConfigReply_t mpi_reply
;
3613 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
3614 u16 attached_handle
;
3616 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
3617 "updating handles for sas_host(0x%016llx)\n",
3618 ioc
->name
, (unsigned long long)ioc
->sas_hba
.sas_address
));
3620 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
3621 * sizeof(Mpi2SasIOUnit0PhyData_t
));
3622 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
3623 if (!sas_iounit_pg0
) {
3624 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3625 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3629 if ((mpt2sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
3630 sas_iounit_pg0
, sz
)) != 0)
3632 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
3633 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
3635 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
3637 ioc
->sas_hba
.handle
= le16_to_cpu(sas_iounit_pg0
->
3638 PhyData
[0].ControllerDevHandle
);
3639 ioc
->sas_hba
.phy
[i
].handle
= ioc
->sas_hba
.handle
;
3640 attached_handle
= le16_to_cpu(sas_iounit_pg0
->PhyData
[i
].
3642 mpt2sas_transport_update_links(ioc
, ioc
->sas_hba
.sas_address
,
3643 attached_handle
, i
, sas_iounit_pg0
->PhyData
[i
].
3644 NegotiatedLinkRate
>> 4);
3647 kfree(sas_iounit_pg0
);
3651 * _scsih_sas_host_add - create sas host object
3652 * @ioc: per adapter object
3654 * Creating host side data object, stored in ioc->sas_hba
3659 _scsih_sas_host_add(struct MPT2SAS_ADAPTER
*ioc
)
3662 Mpi2ConfigReply_t mpi_reply
;
3663 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
3664 Mpi2SasIOUnitPage1_t
*sas_iounit_pg1
= NULL
;
3665 Mpi2SasPhyPage0_t phy_pg0
;
3666 Mpi2SasDevicePage0_t sas_device_pg0
;
3667 Mpi2SasEnclosurePage0_t enclosure_pg0
;
3670 u16 device_missing_delay
;
3672 mpt2sas_config_get_number_hba_phys(ioc
, &ioc
->sas_hba
.num_phys
);
3673 if (!ioc
->sas_hba
.num_phys
) {
3674 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3675 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3679 /* sas_iounit page 0 */
3680 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
3681 sizeof(Mpi2SasIOUnit0PhyData_t
));
3682 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
3683 if (!sas_iounit_pg0
) {
3684 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3685 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3688 if ((mpt2sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
3689 sas_iounit_pg0
, sz
))) {
3690 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3691 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3694 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
3695 MPI2_IOCSTATUS_MASK
;
3696 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
3697 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3698 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3702 /* sas_iounit page 1 */
3703 sz
= offsetof(Mpi2SasIOUnitPage1_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
3704 sizeof(Mpi2SasIOUnit1PhyData_t
));
3705 sas_iounit_pg1
= kzalloc(sz
, GFP_KERNEL
);
3706 if (!sas_iounit_pg1
) {
3707 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3708 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3711 if ((mpt2sas_config_get_sas_iounit_pg1(ioc
, &mpi_reply
,
3712 sas_iounit_pg1
, sz
))) {
3713 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3714 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3717 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
3718 MPI2_IOCSTATUS_MASK
;
3719 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
3720 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3721 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3725 ioc
->io_missing_delay
=
3726 le16_to_cpu(sas_iounit_pg1
->IODeviceMissingDelay
);
3727 device_missing_delay
=
3728 le16_to_cpu(sas_iounit_pg1
->ReportDeviceMissingDelay
);
3729 if (device_missing_delay
& MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16
)
3730 ioc
->device_missing_delay
= (device_missing_delay
&
3731 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
) * 16;
3733 ioc
->device_missing_delay
= device_missing_delay
&
3734 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
;
3736 ioc
->sas_hba
.parent_dev
= &ioc
->shost
->shost_gendev
;
3737 ioc
->sas_hba
.phy
= kcalloc(ioc
->sas_hba
.num_phys
,
3738 sizeof(struct _sas_phy
), GFP_KERNEL
);
3739 if (!ioc
->sas_hba
.phy
) {
3740 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3741 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3744 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
3745 if ((mpt2sas_config_get_phy_pg0(ioc
, &mpi_reply
, &phy_pg0
,
3747 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3748 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3751 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
3752 MPI2_IOCSTATUS_MASK
;
3753 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
3754 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3755 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3760 ioc
->sas_hba
.handle
= le16_to_cpu(sas_iounit_pg0
->
3761 PhyData
[0].ControllerDevHandle
);
3762 ioc
->sas_hba
.phy
[i
].handle
= ioc
->sas_hba
.handle
;
3763 ioc
->sas_hba
.phy
[i
].phy_id
= i
;
3764 mpt2sas_transport_add_host_phy(ioc
, &ioc
->sas_hba
.phy
[i
],
3765 phy_pg0
, ioc
->sas_hba
.parent_dev
);
3767 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
3768 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, ioc
->sas_hba
.handle
))) {
3769 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3770 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3773 ioc
->sas_hba
.enclosure_handle
=
3774 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
3775 ioc
->sas_hba
.sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
3776 printk(MPT2SAS_INFO_FMT
"host_add: handle(0x%04x), "
3777 "sas_addr(0x%016llx), phys(%d)\n", ioc
->name
, ioc
->sas_hba
.handle
,
3778 (unsigned long long) ioc
->sas_hba
.sas_address
,
3779 ioc
->sas_hba
.num_phys
) ;
3781 if (ioc
->sas_hba
.enclosure_handle
) {
3782 if (!(mpt2sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
3784 MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
3785 ioc
->sas_hba
.enclosure_handle
))) {
3786 ioc
->sas_hba
.enclosure_logical_id
=
3787 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
3792 kfree(sas_iounit_pg1
);
3793 kfree(sas_iounit_pg0
);
3797 * _scsih_expander_add - creating expander object
3798 * @ioc: per adapter object
3799 * @handle: expander handle
3801 * Creating expander object, stored in ioc->sas_expander_list.
3803 * Return 0 for success, else error.
3806 _scsih_expander_add(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
3808 struct _sas_node
*sas_expander
;
3809 Mpi2ConfigReply_t mpi_reply
;
3810 Mpi2ExpanderPage0_t expander_pg0
;
3811 Mpi2ExpanderPage1_t expander_pg1
;
3812 Mpi2SasEnclosurePage0_t enclosure_pg0
;
3815 __le64 sas_address
, sas_address_parent
= 0;
3817 unsigned long flags
;
3818 struct _sas_port
*mpt2sas_port
= NULL
;
3824 if (ioc
->shost_recovery
)
3827 if ((mpt2sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
3828 MPI2_SAS_EXPAND_PGAD_FORM_HNDL
, handle
))) {
3829 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3830 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3834 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
3835 MPI2_IOCSTATUS_MASK
;
3836 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
3837 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3838 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3842 /* handle out of order topology events */
3843 parent_handle
= le16_to_cpu(expander_pg0
.ParentDevHandle
);
3844 if (_scsih_get_sas_address(ioc
, parent_handle
, &sas_address_parent
)
3846 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3847 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3850 if (sas_address_parent
!= ioc
->sas_hba
.sas_address
) {
3851 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
3852 sas_expander
= mpt2sas_scsih_expander_find_by_sas_address(ioc
,
3853 sas_address_parent
);
3854 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
3855 if (!sas_expander
) {
3856 rc
= _scsih_expander_add(ioc
, parent_handle
);
3862 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
3863 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
3864 sas_expander
= mpt2sas_scsih_expander_find_by_sas_address(ioc
,
3866 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
3871 sas_expander
= kzalloc(sizeof(struct _sas_node
),
3873 if (!sas_expander
) {
3874 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3875 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3879 sas_expander
->handle
= handle
;
3880 sas_expander
->num_phys
= expander_pg0
.NumPhys
;
3881 sas_expander
->sas_address_parent
= sas_address_parent
;
3882 sas_expander
->sas_address
= sas_address
;
3884 printk(MPT2SAS_INFO_FMT
"expander_add: handle(0x%04x),"
3885 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc
->name
,
3886 handle
, parent_handle
, (unsigned long long)
3887 sas_expander
->sas_address
, sas_expander
->num_phys
);
3889 if (!sas_expander
->num_phys
)
3891 sas_expander
->phy
= kcalloc(sas_expander
->num_phys
,
3892 sizeof(struct _sas_phy
), GFP_KERNEL
);
3893 if (!sas_expander
->phy
) {
3894 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3895 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3900 INIT_LIST_HEAD(&sas_expander
->sas_port_list
);
3901 mpt2sas_port
= mpt2sas_transport_port_add(ioc
, handle
,
3902 sas_address_parent
);
3903 if (!mpt2sas_port
) {
3904 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3905 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3909 sas_expander
->parent_dev
= &mpt2sas_port
->rphy
->dev
;
3911 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++) {
3912 if ((mpt2sas_config_get_expander_pg1(ioc
, &mpi_reply
,
3913 &expander_pg1
, i
, handle
))) {
3914 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3915 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3919 sas_expander
->phy
[i
].handle
= handle
;
3920 sas_expander
->phy
[i
].phy_id
= i
;
3922 if ((mpt2sas_transport_add_expander_phy(ioc
,
3923 &sas_expander
->phy
[i
], expander_pg1
,
3924 sas_expander
->parent_dev
))) {
3925 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3926 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3932 if (sas_expander
->enclosure_handle
) {
3933 if (!(mpt2sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
3934 &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
3935 sas_expander
->enclosure_handle
))) {
3936 sas_expander
->enclosure_logical_id
=
3937 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
3941 _scsih_expander_node_add(ioc
, sas_expander
);
3947 mpt2sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
3948 sas_address_parent
);
3949 kfree(sas_expander
);
3954 * _scsih_done - scsih callback handler.
3955 * @ioc: per adapter object
3956 * @smid: system request message index
3957 * @msix_index: MSIX table index supplied by the OS
3958 * @reply: reply message frame(lower 32bit addr)
3960 * Callback handler when sending internal generated message frames.
3961 * The callback index passed is `ioc->scsih_cb_idx`
3963 * Return 1 meaning mf should be freed from _base_interrupt
3964 * 0 means the mf is freed from this function.
3967 _scsih_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
3969 MPI2DefaultReply_t
*mpi_reply
;
3971 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
3972 if (ioc
->scsih_cmds
.status
== MPT2_CMD_NOT_USED
)
3974 if (ioc
->scsih_cmds
.smid
!= smid
)
3976 ioc
->scsih_cmds
.status
|= MPT2_CMD_COMPLETE
;
3978 memcpy(ioc
->scsih_cmds
.reply
, mpi_reply
,
3979 mpi_reply
->MsgLength
*4);
3980 ioc
->scsih_cmds
.status
|= MPT2_CMD_REPLY_VALID
;
3982 ioc
->scsih_cmds
.status
&= ~MPT2_CMD_PENDING
;
3983 complete(&ioc
->scsih_cmds
.done
);
3988 * _scsih_expander_remove - removing expander object
3989 * @ioc: per adapter object
3990 * @sas_address: expander sas_address
3995 _scsih_expander_remove(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
)
3997 struct _sas_node
*sas_expander
;
3998 unsigned long flags
;
4000 if (ioc
->shost_recovery
)
4003 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
4004 sas_expander
= mpt2sas_scsih_expander_find_by_sas_address(ioc
,
4006 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
4007 _scsih_expander_node_remove(ioc
, sas_expander
);
4011 * _scsih_add_device - creating sas device object
4012 * @ioc: per adapter object
4013 * @handle: sas device handle
4014 * @phy_num: phy number end device attached to
4015 * @is_pd: is this hidden raid component
4017 * Creating end device object, stored in ioc->sas_device_list.
4019 * Returns 0 for success, non-zero for failure.
4022 _scsih_add_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
, u8 phy_num
, u8 is_pd
)
4024 Mpi2ConfigReply_t mpi_reply
;
4025 Mpi2SasDevicePage0_t sas_device_pg0
;
4026 Mpi2SasEnclosurePage0_t enclosure_pg0
;
4027 struct _sas_device
*sas_device
;
4031 unsigned long flags
;
4033 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
4034 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
4035 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4036 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4040 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4041 MPI2_IOCSTATUS_MASK
;
4042 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4043 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4044 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4048 /* check if device is present */
4049 if (!(le16_to_cpu(sas_device_pg0
.Flags
) &
4050 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT
)) {
4051 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4052 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4053 printk(MPT2SAS_ERR_FMT
"Flags = 0x%04x\n",
4054 ioc
->name
, le16_to_cpu(sas_device_pg0
.Flags
));
4058 /* check if there were any issus with discovery */
4059 if (sas_device_pg0
.AccessStatus
==
4060 MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED
) {
4061 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4062 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4063 printk(MPT2SAS_ERR_FMT
"AccessStatus = 0x%02x\n",
4064 ioc
->name
, sas_device_pg0
.AccessStatus
);
4068 /* check if this is end device */
4069 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
4070 if (!(_scsih_is_end_device(device_info
))) {
4071 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4072 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4076 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
4078 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4079 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
4081 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4084 _scsih_ublock_io_device(ioc
, handle
);
4088 sas_device
= kzalloc(sizeof(struct _sas_device
),
4091 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4092 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4096 sas_device
->handle
= handle
;
4097 if (_scsih_get_sas_address(ioc
, le16_to_cpu
4098 (sas_device_pg0
.ParentDevHandle
),
4099 &sas_device
->sas_address_parent
) != 0)
4100 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4101 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4102 sas_device
->enclosure_handle
=
4103 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
4105 le16_to_cpu(sas_device_pg0
.Slot
);
4106 sas_device
->device_info
= device_info
;
4107 sas_device
->sas_address
= sas_address
;
4108 sas_device
->hidden_raid_component
= is_pd
;
4110 /* get enclosure_logical_id */
4111 if (sas_device
->enclosure_handle
&& !(mpt2sas_config_get_enclosure_pg0(
4112 ioc
, &mpi_reply
, &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
4113 sas_device
->enclosure_handle
)))
4114 sas_device
->enclosure_logical_id
=
4115 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
4117 /* get device name */
4118 sas_device
->device_name
= le64_to_cpu(sas_device_pg0
.DeviceName
);
4120 if (ioc
->wait_for_port_enable_to_complete
)
4121 _scsih_sas_device_init_add(ioc
, sas_device
);
4123 _scsih_sas_device_add(ioc
, sas_device
);
4129 * _scsih_remove_device - removing sas device object
4130 * @ioc: per adapter object
4131 * @sas_device: the sas_device object
4136 _scsih_remove_device(struct MPT2SAS_ADAPTER
*ioc
, struct _sas_device
4139 struct MPT2SAS_TARGET
*sas_target_priv_data
;
4140 Mpi2SasIoUnitControlReply_t mpi_reply
;
4141 Mpi2SasIoUnitControlRequest_t mpi_request
;
4142 u16 device_handle
, handle
;
4147 handle
= sas_device
->handle
;
4148 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: enter: handle(0x%04x),"
4149 " sas_addr(0x%016llx)\n", ioc
->name
, __func__
, handle
,
4150 (unsigned long long) sas_device
->sas_address
));
4152 if (sas_device
->starget
&& sas_device
->starget
->hostdata
) {
4153 sas_target_priv_data
= sas_device
->starget
->hostdata
;
4154 sas_target_priv_data
->deleted
= 1;
4157 if (ioc
->remove_host
|| ioc
->shost_recovery
|| !handle
)
4160 if ((sas_device
->state
& MPTSAS_STATE_TR_COMPLETE
)) {
4161 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"\tskip "
4162 "target_reset handle(0x%04x)\n", ioc
->name
,
4167 /* Target Reset to flush out all the outstanding IO */
4168 device_handle
= (sas_device
->hidden_raid_component
) ?
4169 sas_device
->volume_handle
: handle
;
4170 if (device_handle
) {
4171 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"issue target reset: "
4172 "handle(0x%04x)\n", ioc
->name
, device_handle
));
4173 mutex_lock(&ioc
->tm_cmds
.mutex
);
4174 mpt2sas_scsih_issue_tm(ioc
, device_handle
, 0,
4175 MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
, 0, 10);
4176 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
4177 mutex_unlock(&ioc
->tm_cmds
.mutex
);
4178 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"issue target reset "
4179 "done: handle(0x%04x)\n", ioc
->name
, device_handle
));
4180 if (ioc
->shost_recovery
)
4185 if ((sas_device
->state
& MPTSAS_STATE_CNTRL_COMPLETE
)) {
4186 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"\tskip "
4187 "sas_cntrl handle(0x%04x)\n", ioc
->name
, handle
));
4191 /* SAS_IO_UNIT_CNTR - send REMOVE_DEVICE */
4192 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"sas_iounit: handle"
4193 "(0x%04x)\n", ioc
->name
, handle
));
4194 memset(&mpi_request
, 0, sizeof(Mpi2SasIoUnitControlRequest_t
));
4195 mpi_request
.Function
= MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
;
4196 mpi_request
.Operation
= MPI2_SAS_OP_REMOVE_DEVICE
;
4197 mpi_request
.DevHandle
= handle
;
4198 mpi_request
.VF_ID
= 0; /* TODO */
4199 mpi_request
.VP_ID
= 0;
4200 if ((mpt2sas_base_sas_iounit_control(ioc
, &mpi_reply
,
4201 &mpi_request
)) != 0) {
4202 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4203 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4206 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"sas_iounit: ioc_status"
4207 "(0x%04x), loginfo(0x%08x)\n", ioc
->name
,
4208 le16_to_cpu(mpi_reply
.IOCStatus
),
4209 le32_to_cpu(mpi_reply
.IOCLogInfo
)));
4213 _scsih_ublock_io_device(ioc
, handle
);
4215 mpt2sas_transport_port_remove(ioc
, sas_device
->sas_address
,
4216 sas_device
->sas_address_parent
);
4218 printk(MPT2SAS_INFO_FMT
"removing handle(0x%04x), sas_addr"
4219 "(0x%016llx)\n", ioc
->name
, handle
,
4220 (unsigned long long) sas_device
->sas_address
);
4221 _scsih_sas_device_remove(ioc
, sas_device
);
4223 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: exit: handle"
4224 "(0x%04x)\n", ioc
->name
, __func__
, handle
));
4227 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4229 * _scsih_sas_topology_change_event_debug - debug for topology event
4230 * @ioc: per adapter object
4231 * @event_data: event data payload
4235 _scsih_sas_topology_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
4236 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
4242 char *status_str
= NULL
;
4243 u8 link_rate
, prev_link_rate
;
4245 switch (event_data
->ExpStatus
) {
4246 case MPI2_EVENT_SAS_TOPO_ES_ADDED
:
4249 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
:
4250 status_str
= "remove";
4252 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING
:
4254 status_str
= "responding";
4256 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
:
4257 status_str
= "remove delay";
4260 status_str
= "unknown status";
4263 printk(MPT2SAS_DEBUG_FMT
"sas topology change: (%s)\n",
4264 ioc
->name
, status_str
);
4265 printk(KERN_DEBUG
"\thandle(0x%04x), enclosure_handle(0x%04x) "
4266 "start_phy(%02d), count(%d)\n",
4267 le16_to_cpu(event_data
->ExpanderDevHandle
),
4268 le16_to_cpu(event_data
->EnclosureHandle
),
4269 event_data
->StartPhyNum
, event_data
->NumEntries
);
4270 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
4271 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
4274 phy_number
= event_data
->StartPhyNum
+ i
;
4275 reason_code
= event_data
->PHY
[i
].PhyStatus
&
4276 MPI2_EVENT_SAS_TOPO_RC_MASK
;
4277 switch (reason_code
) {
4278 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
4279 status_str
= "target add";
4281 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
4282 status_str
= "target remove";
4284 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
:
4285 status_str
= "delay target remove";
4287 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
4288 status_str
= "link rate change";
4290 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE
:
4291 status_str
= "target responding";
4294 status_str
= "unknown";
4297 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
4298 prev_link_rate
= event_data
->PHY
[i
].LinkRate
& 0xF;
4299 printk(KERN_DEBUG
"\tphy(%02d), attached_handle(0x%04x): %s:"
4300 " link rate: new(0x%02x), old(0x%02x)\n", phy_number
,
4301 handle
, status_str
, link_rate
, prev_link_rate
);
4308 * _scsih_sas_topology_change_event - handle topology changes
4309 * @ioc: per adapter object
4310 * @fw_event: The fw_event_work object
4315 _scsih_sas_topology_change_event(struct MPT2SAS_ADAPTER
*ioc
,
4316 struct fw_event_work
*fw_event
)
4319 u16 parent_handle
, handle
;
4322 struct _sas_node
*sas_expander
;
4323 struct _sas_device
*sas_device
;
4325 unsigned long flags
;
4326 u8 link_rate
, prev_link_rate
;
4327 Mpi2EventDataSasTopologyChangeList_t
*event_data
= fw_event
->event_data
;
4329 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4330 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
4331 _scsih_sas_topology_change_event_debug(ioc
, event_data
);
4334 if (ioc
->shost_recovery
)
4337 if (!ioc
->sas_hba
.num_phys
)
4338 _scsih_sas_host_add(ioc
);
4340 _scsih_sas_host_refresh(ioc
);
4342 if (fw_event
->ignore
) {
4343 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"ignoring expander "
4344 "event\n", ioc
->name
));
4348 parent_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
4350 /* handle expander add */
4351 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_ADDED
)
4352 if (_scsih_expander_add(ioc
, parent_handle
) != 0)
4355 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
4356 sas_expander
= mpt2sas_scsih_expander_find_by_handle(ioc
,
4358 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
4360 sas_address
= sas_expander
->sas_address
;
4361 else if (parent_handle
< ioc
->sas_hba
.num_phys
)
4362 sas_address
= ioc
->sas_hba
.sas_address
;
4366 /* handle siblings events */
4367 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
4368 if (fw_event
->ignore
) {
4369 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"ignoring "
4370 "expander event\n", ioc
->name
));
4373 if (ioc
->shost_recovery
)
4375 phy_number
= event_data
->StartPhyNum
+ i
;
4376 reason_code
= event_data
->PHY
[i
].PhyStatus
&
4377 MPI2_EVENT_SAS_TOPO_RC_MASK
;
4378 if ((event_data
->PHY
[i
].PhyStatus
&
4379 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT
) && (reason_code
!=
4380 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
))
4382 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
4385 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
4386 prev_link_rate
= event_data
->PHY
[i
].LinkRate
& 0xF;
4387 switch (reason_code
) {
4388 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
4390 if (link_rate
== prev_link_rate
)
4393 mpt2sas_transport_update_links(ioc
, sas_address
,
4394 handle
, phy_number
, link_rate
);
4396 if (link_rate
>= MPI2_SAS_NEG_LINK_RATE_1_5
)
4397 _scsih_ublock_io_device(ioc
, handle
);
4399 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
4401 mpt2sas_transport_update_links(ioc
, sas_address
,
4402 handle
, phy_number
, link_rate
);
4404 _scsih_add_device(ioc
, handle
, phy_number
, 0);
4406 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
4408 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4409 sas_device
= _scsih_sas_device_find_by_handle(ioc
,
4412 spin_unlock_irqrestore(&ioc
->sas_device_lock
,
4416 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4417 _scsih_remove_device(ioc
, sas_device
);
4422 /* handle expander removal */
4423 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
&&
4425 _scsih_expander_remove(ioc
, sas_address
);
4429 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4431 * _scsih_sas_device_status_change_event_debug - debug for device event
4432 * @event_data: event data payload
4438 _scsih_sas_device_status_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
4439 Mpi2EventDataSasDeviceStatusChange_t
*event_data
)
4441 char *reason_str
= NULL
;
4443 switch (event_data
->ReasonCode
) {
4444 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
:
4445 reason_str
= "smart data";
4447 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED
:
4448 reason_str
= "unsupported device discovered";
4450 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
:
4451 reason_str
= "internal device reset";
4453 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL
:
4454 reason_str
= "internal task abort";
4456 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL
:
4457 reason_str
= "internal task abort set";
4459 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL
:
4460 reason_str
= "internal clear task set";
4462 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL
:
4463 reason_str
= "internal query task";
4465 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE
:
4466 reason_str
= "sata init failure";
4468 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
:
4469 reason_str
= "internal device reset complete";
4471 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL
:
4472 reason_str
= "internal task abort complete";
4474 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION
:
4475 reason_str
= "internal async notification";
4477 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY
:
4478 reason_str
= "expander reduced functionality";
4480 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY
:
4481 reason_str
= "expander reduced functionality complete";
4484 reason_str
= "unknown reason";
4487 printk(MPT2SAS_DEBUG_FMT
"device status change: (%s)\n"
4488 "\thandle(0x%04x), sas address(0x%016llx)", ioc
->name
,
4489 reason_str
, le16_to_cpu(event_data
->DevHandle
),
4490 (unsigned long long)le64_to_cpu(event_data
->SASAddress
));
4491 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
)
4492 printk(MPT2SAS_DEBUG_FMT
", ASC(0x%x), ASCQ(0x%x)\n", ioc
->name
,
4493 event_data
->ASC
, event_data
->ASCQ
);
4494 printk(KERN_INFO
"\n");
4499 * _scsih_sas_device_status_change_event - handle device status change
4500 * @ioc: per adapter object
4501 * @fw_event: The fw_event_work object
4507 _scsih_sas_device_status_change_event(struct MPT2SAS_ADAPTER
*ioc
,
4508 struct fw_event_work
*fw_event
)
4510 struct MPT2SAS_TARGET
*target_priv_data
;
4511 struct _sas_device
*sas_device
;
4513 unsigned long flags
;
4514 Mpi2EventDataSasDeviceStatusChange_t
*event_data
=
4515 fw_event
->event_data
;
4517 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4518 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
4519 _scsih_sas_device_status_change_event_debug(ioc
,
4523 if (!(event_data
->ReasonCode
==
4524 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
&&
4525 event_data
->ReasonCode
==
4526 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
))
4529 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4530 sas_address
= le64_to_cpu(event_data
->SASAddress
);
4531 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
4533 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4535 if (!sas_device
|| !sas_device
->starget
)
4538 target_priv_data
= sas_device
->starget
->hostdata
;
4539 if (!target_priv_data
)
4542 if (event_data
->ReasonCode
==
4543 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
)
4544 target_priv_data
->tm_busy
= 1;
4546 target_priv_data
->tm_busy
= 0;
4549 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4551 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure event
4552 * @ioc: per adapter object
4553 * @event_data: event data payload
4559 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
4560 Mpi2EventDataSasEnclDevStatusChange_t
*event_data
)
4562 char *reason_str
= NULL
;
4564 switch (event_data
->ReasonCode
) {
4565 case MPI2_EVENT_SAS_ENCL_RC_ADDED
:
4566 reason_str
= "enclosure add";
4568 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING
:
4569 reason_str
= "enclosure remove";
4572 reason_str
= "unknown reason";
4576 printk(MPT2SAS_DEBUG_FMT
"enclosure status change: (%s)\n"
4577 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
4578 " number slots(%d)\n", ioc
->name
, reason_str
,
4579 le16_to_cpu(event_data
->EnclosureHandle
),
4580 (unsigned long long)le64_to_cpu(event_data
->EnclosureLogicalID
),
4581 le16_to_cpu(event_data
->StartSlot
));
4586 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
4587 * @ioc: per adapter object
4588 * @fw_event: The fw_event_work object
4594 _scsih_sas_enclosure_dev_status_change_event(struct MPT2SAS_ADAPTER
*ioc
,
4595 struct fw_event_work
*fw_event
)
4597 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4598 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
4599 _scsih_sas_enclosure_dev_status_change_event_debug(ioc
,
4600 fw_event
->event_data
);
4605 * _scsih_sas_broadcast_primative_event - handle broadcast events
4606 * @ioc: per adapter object
4607 * @fw_event: The fw_event_work object
4613 _scsih_sas_broadcast_primative_event(struct MPT2SAS_ADAPTER
*ioc
,
4614 struct fw_event_work
*fw_event
)
4616 struct scsi_cmnd
*scmd
;
4619 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
4620 u32 termination_count
;
4622 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
4623 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4624 Mpi2EventDataSasBroadcastPrimitive_t
*event_data
= fw_event
->event_data
;
4627 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"broadcast primative: "
4628 "phy number(%d), width(%d)\n", ioc
->name
, event_data
->PhyNum
,
4629 event_data
->PortWidth
));
4630 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: enter\n", ioc
->name
,
4633 mutex_lock(&ioc
->tm_cmds
.mutex
);
4634 termination_count
= 0;
4636 mpi_reply
= ioc
->tm_cmds
.reply
;
4637 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
4638 scmd
= _scsih_scsi_lookup_get(ioc
, smid
);
4641 sas_device_priv_data
= scmd
->device
->hostdata
;
4642 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
)
4644 /* skip hidden raid components */
4645 if (sas_device_priv_data
->sas_target
->flags
&
4646 MPT_TARGET_FLAGS_RAID_COMPONENT
)
4649 if (sas_device_priv_data
->sas_target
->flags
&
4650 MPT_TARGET_FLAGS_VOLUME
)
4653 handle
= sas_device_priv_data
->sas_target
->handle
;
4654 lun
= sas_device_priv_data
->lun
;
4657 mpt2sas_scsih_issue_tm(ioc
, handle
, lun
,
4658 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK
, smid
, 30);
4659 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
4660 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
)
4661 & MPI2_IOCSTATUS_MASK
;
4662 if ((ioc_status
== MPI2_IOCSTATUS_SUCCESS
) &&
4663 (mpi_reply
->ResponseCode
==
4664 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
||
4665 mpi_reply
->ResponseCode
==
4666 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
))
4669 mpt2sas_scsih_issue_tm(ioc
, handle
, lun
,
4670 MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET
, 0, 30);
4671 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
4672 termination_count
+= le32_to_cpu(mpi_reply
->TerminationCount
);
4674 ioc
->broadcast_aen_busy
= 0;
4675 mutex_unlock(&ioc
->tm_cmds
.mutex
);
4677 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
4678 "%s - exit, query_count = %d termination_count = %d\n",
4679 ioc
->name
, __func__
, query_count
, termination_count
));
4683 * _scsih_sas_discovery_event - handle discovery events
4684 * @ioc: per adapter object
4685 * @fw_event: The fw_event_work object
4691 _scsih_sas_discovery_event(struct MPT2SAS_ADAPTER
*ioc
,
4692 struct fw_event_work
*fw_event
)
4694 Mpi2EventDataSasDiscovery_t
*event_data
= fw_event
->event_data
;
4696 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4697 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
) {
4698 printk(MPT2SAS_DEBUG_FMT
"discovery event: (%s)", ioc
->name
,
4699 (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
) ?
4701 if (event_data
->DiscoveryStatus
)
4702 printk("discovery_status(0x%08x)",
4703 le32_to_cpu(event_data
->DiscoveryStatus
));
4708 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
&&
4709 !ioc
->sas_hba
.num_phys
)
4710 _scsih_sas_host_add(ioc
);
4714 * _scsih_reprobe_lun - reprobing lun
4715 * @sdev: scsi device struct
4716 * @no_uld_attach: sdev->no_uld_attach flag setting
4720 _scsih_reprobe_lun(struct scsi_device
*sdev
, void *no_uld_attach
)
4724 sdev
->no_uld_attach
= no_uld_attach
? 1 : 0;
4725 sdev_printk(KERN_INFO
, sdev
, "%s raid component\n",
4726 sdev
->no_uld_attach
? "hidding" : "exposing");
4727 rc
= scsi_device_reprobe(sdev
);
4731 * _scsih_reprobe_target - reprobing target
4732 * @starget: scsi target struct
4733 * @no_uld_attach: sdev->no_uld_attach flag setting
4735 * Note: no_uld_attach flag determines whether the disk device is attached
4736 * to block layer. A value of `1` means to not attach.
4739 _scsih_reprobe_target(struct scsi_target
*starget
, int no_uld_attach
)
4741 struct MPT2SAS_TARGET
*sas_target_priv_data
= starget
->hostdata
;
4744 sas_target_priv_data
->flags
|= MPT_TARGET_FLAGS_RAID_COMPONENT
;
4746 sas_target_priv_data
->flags
&= ~MPT_TARGET_FLAGS_RAID_COMPONENT
;
4748 starget_for_each_device(starget
, no_uld_attach
? (void *)1 : NULL
,
4749 _scsih_reprobe_lun
);
4752 * _scsih_sas_volume_add - add new volume
4753 * @ioc: per adapter object
4754 * @element: IR config element data
4760 _scsih_sas_volume_add(struct MPT2SAS_ADAPTER
*ioc
,
4761 Mpi2EventIrConfigElement_t
*element
)
4763 struct _raid_device
*raid_device
;
4764 unsigned long flags
;
4766 u16 handle
= le16_to_cpu(element
->VolDevHandle
);
4769 mpt2sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
4771 printk(MPT2SAS_ERR_FMT
4772 "failure at %s:%d/%s()!\n", ioc
->name
,
4773 __FILE__
, __LINE__
, __func__
);
4777 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
4778 raid_device
= _scsih_raid_device_find_by_wwid(ioc
, wwid
);
4779 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
4784 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
4786 printk(MPT2SAS_ERR_FMT
4787 "failure at %s:%d/%s()!\n", ioc
->name
,
4788 __FILE__
, __LINE__
, __func__
);
4792 raid_device
->id
= ioc
->sas_id
++;
4793 raid_device
->channel
= RAID_CHANNEL
;
4794 raid_device
->handle
= handle
;
4795 raid_device
->wwid
= wwid
;
4796 _scsih_raid_device_add(ioc
, raid_device
);
4797 if (!ioc
->wait_for_port_enable_to_complete
) {
4798 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
4799 raid_device
->id
, 0);
4801 _scsih_raid_device_remove(ioc
, raid_device
);
4803 _scsih_determine_boot_device(ioc
, raid_device
, 1);
4807 * _scsih_sas_volume_delete - delete volume
4808 * @ioc: per adapter object
4809 * @element: IR config element data
4815 _scsih_sas_volume_delete(struct MPT2SAS_ADAPTER
*ioc
,
4816 Mpi2EventIrConfigElement_t
*element
)
4818 struct _raid_device
*raid_device
;
4819 u16 handle
= le16_to_cpu(element
->VolDevHandle
);
4820 unsigned long flags
;
4821 struct MPT2SAS_TARGET
*sas_target_priv_data
;
4823 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
4824 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
4825 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
4828 if (raid_device
->starget
) {
4829 sas_target_priv_data
= raid_device
->starget
->hostdata
;
4830 sas_target_priv_data
->deleted
= 1;
4831 scsi_remove_target(&raid_device
->starget
->dev
);
4833 _scsih_raid_device_remove(ioc
, raid_device
);
4837 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
4838 * @ioc: per adapter object
4839 * @element: IR config element data
4845 _scsih_sas_pd_expose(struct MPT2SAS_ADAPTER
*ioc
,
4846 Mpi2EventIrConfigElement_t
*element
)
4848 struct _sas_device
*sas_device
;
4849 unsigned long flags
;
4850 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
4852 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4853 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
4854 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4858 /* exposing raid component */
4859 sas_device
->volume_handle
= 0;
4860 sas_device
->volume_wwid
= 0;
4861 sas_device
->hidden_raid_component
= 0;
4862 _scsih_reprobe_target(sas_device
->starget
, 0);
4866 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
4867 * @ioc: per adapter object
4868 * @element: IR config element data
4874 _scsih_sas_pd_hide(struct MPT2SAS_ADAPTER
*ioc
,
4875 Mpi2EventIrConfigElement_t
*element
)
4877 struct _sas_device
*sas_device
;
4878 unsigned long flags
;
4879 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
4881 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4882 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
4883 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4887 /* hiding raid component */
4888 mpt2sas_config_get_volume_handle(ioc
, handle
,
4889 &sas_device
->volume_handle
);
4890 mpt2sas_config_get_volume_wwid(ioc
, sas_device
->volume_handle
,
4891 &sas_device
->volume_wwid
);
4892 sas_device
->hidden_raid_component
= 1;
4893 _scsih_reprobe_target(sas_device
->starget
, 1);
4897 * _scsih_sas_pd_delete - delete pd component
4898 * @ioc: per adapter object
4899 * @element: IR config element data
4905 _scsih_sas_pd_delete(struct MPT2SAS_ADAPTER
*ioc
,
4906 Mpi2EventIrConfigElement_t
*element
)
4908 struct _sas_device
*sas_device
;
4909 unsigned long flags
;
4910 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
4912 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4913 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
4914 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4917 _scsih_remove_device(ioc
, sas_device
);
4921 * _scsih_sas_pd_add - remove pd component
4922 * @ioc: per adapter object
4923 * @element: IR config element data
4929 _scsih_sas_pd_add(struct MPT2SAS_ADAPTER
*ioc
,
4930 Mpi2EventIrConfigElement_t
*element
)
4932 struct _sas_device
*sas_device
;
4933 unsigned long flags
;
4934 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
4935 Mpi2ConfigReply_t mpi_reply
;
4936 Mpi2SasDevicePage0_t sas_device_pg0
;
4941 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4942 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
4943 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4945 sas_device
->hidden_raid_component
= 1;
4949 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
4950 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
4951 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4952 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4956 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4957 MPI2_IOCSTATUS_MASK
;
4958 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4959 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4960 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4964 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
4965 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
4966 mpt2sas_transport_update_links(ioc
, sas_address
, handle
,
4967 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
4969 _scsih_add_device(ioc
, handle
, 0, 1);
4972 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4974 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
4975 * @ioc: per adapter object
4976 * @event_data: event data payload
4982 _scsih_sas_ir_config_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
4983 Mpi2EventDataIrConfigChangeList_t
*event_data
)
4985 Mpi2EventIrConfigElement_t
*element
;
4988 char *reason_str
= NULL
, *element_str
= NULL
;
4990 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
4992 printk(MPT2SAS_DEBUG_FMT
"raid config change: (%s), elements(%d)\n",
4993 ioc
->name
, (le32_to_cpu(event_data
->Flags
) &
4994 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ?
4995 "foreign" : "native", event_data
->NumElements
);
4996 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
4997 switch (element
->ReasonCode
) {
4998 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
5001 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
5002 reason_str
= "remove";
5004 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE
:
5005 reason_str
= "no change";
5007 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
5008 reason_str
= "hide";
5010 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
5011 reason_str
= "unhide";
5013 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
5014 reason_str
= "volume_created";
5016 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
5017 reason_str
= "volume_deleted";
5019 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
5020 reason_str
= "pd_created";
5022 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
5023 reason_str
= "pd_deleted";
5026 reason_str
= "unknown reason";
5029 element_type
= le16_to_cpu(element
->ElementFlags
) &
5030 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK
;
5031 switch (element_type
) {
5032 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT
:
5033 element_str
= "volume";
5035 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT
:
5036 element_str
= "phys disk";
5038 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT
:
5039 element_str
= "hot spare";
5042 element_str
= "unknown element";
5045 printk(KERN_DEBUG
"\t(%s:%s), vol handle(0x%04x), "
5046 "pd handle(0x%04x), pd num(0x%02x)\n", element_str
,
5047 reason_str
, le16_to_cpu(element
->VolDevHandle
),
5048 le16_to_cpu(element
->PhysDiskDevHandle
),
5049 element
->PhysDiskNum
);
5055 * _scsih_sas_ir_config_change_event - handle ir configuration change events
5056 * @ioc: per adapter object
5057 * @fw_event: The fw_event_work object
5063 _scsih_sas_ir_config_change_event(struct MPT2SAS_ADAPTER
*ioc
,
5064 struct fw_event_work
*fw_event
)
5066 Mpi2EventIrConfigElement_t
*element
;
5069 Mpi2EventDataIrConfigChangeList_t
*event_data
= fw_event
->event_data
;
5071 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5072 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5073 _scsih_sas_ir_config_change_event_debug(ioc
, event_data
);
5076 foreign_config
= (le32_to_cpu(event_data
->Flags
) &
5077 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ? 1 : 0;
5079 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
5080 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
5082 switch (element
->ReasonCode
) {
5083 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
5084 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
5085 if (!foreign_config
)
5086 _scsih_sas_volume_add(ioc
, element
);
5088 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
5089 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
5090 if (!foreign_config
)
5091 _scsih_sas_volume_delete(ioc
, element
);
5093 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
5094 _scsih_sas_pd_hide(ioc
, element
);
5096 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
5097 _scsih_sas_pd_expose(ioc
, element
);
5099 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
5100 _scsih_sas_pd_add(ioc
, element
);
5102 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
5103 _scsih_sas_pd_delete(ioc
, element
);
5110 * _scsih_sas_ir_volume_event - IR volume event
5111 * @ioc: per adapter object
5112 * @fw_event: The fw_event_work object
5118 _scsih_sas_ir_volume_event(struct MPT2SAS_ADAPTER
*ioc
,
5119 struct fw_event_work
*fw_event
)
5122 unsigned long flags
;
5123 struct _raid_device
*raid_device
;
5127 struct MPT2SAS_TARGET
*sas_target_priv_data
;
5128 Mpi2EventDataIrVolume_t
*event_data
= fw_event
->event_data
;
5130 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED
)
5133 handle
= le16_to_cpu(event_data
->VolDevHandle
);
5134 state
= le32_to_cpu(event_data
->NewValue
);
5135 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: handle(0x%04x), "
5136 "old(0x%08x), new(0x%08x)\n", ioc
->name
, __func__
, handle
,
5137 le32_to_cpu(event_data
->PreviousValue
), state
));
5139 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5140 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
5141 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5144 case MPI2_RAID_VOL_STATE_MISSING
:
5145 case MPI2_RAID_VOL_STATE_FAILED
:
5148 if (raid_device
->starget
) {
5149 sas_target_priv_data
= raid_device
->starget
->hostdata
;
5150 sas_target_priv_data
->deleted
= 1;
5151 scsi_remove_target(&raid_device
->starget
->dev
);
5153 _scsih_raid_device_remove(ioc
, raid_device
);
5156 case MPI2_RAID_VOL_STATE_ONLINE
:
5157 case MPI2_RAID_VOL_STATE_DEGRADED
:
5158 case MPI2_RAID_VOL_STATE_OPTIMAL
:
5162 mpt2sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
5164 printk(MPT2SAS_ERR_FMT
5165 "failure at %s:%d/%s()!\n", ioc
->name
,
5166 __FILE__
, __LINE__
, __func__
);
5170 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
5172 printk(MPT2SAS_ERR_FMT
5173 "failure at %s:%d/%s()!\n", ioc
->name
,
5174 __FILE__
, __LINE__
, __func__
);
5178 raid_device
->id
= ioc
->sas_id
++;
5179 raid_device
->channel
= RAID_CHANNEL
;
5180 raid_device
->handle
= handle
;
5181 raid_device
->wwid
= wwid
;
5182 _scsih_raid_device_add(ioc
, raid_device
);
5183 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
5184 raid_device
->id
, 0);
5186 _scsih_raid_device_remove(ioc
, raid_device
);
5189 case MPI2_RAID_VOL_STATE_INITIALIZING
:
5196 * _scsih_sas_ir_physical_disk_event - PD event
5197 * @ioc: per adapter object
5198 * @fw_event: The fw_event_work object
5204 _scsih_sas_ir_physical_disk_event(struct MPT2SAS_ADAPTER
*ioc
,
5205 struct fw_event_work
*fw_event
)
5207 u16 handle
, parent_handle
;
5209 struct _sas_device
*sas_device
;
5210 unsigned long flags
;
5211 Mpi2ConfigReply_t mpi_reply
;
5212 Mpi2SasDevicePage0_t sas_device_pg0
;
5214 Mpi2EventDataIrPhysicalDisk_t
*event_data
= fw_event
->event_data
;
5217 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED
)
5220 handle
= le16_to_cpu(event_data
->PhysDiskDevHandle
);
5221 state
= le32_to_cpu(event_data
->NewValue
);
5223 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: handle(0x%04x), "
5224 "old(0x%08x), new(0x%08x)\n", ioc
->name
, __func__
, handle
,
5225 le32_to_cpu(event_data
->PreviousValue
), state
));
5227 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5228 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
5229 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5232 case MPI2_RAID_PD_STATE_ONLINE
:
5233 case MPI2_RAID_PD_STATE_DEGRADED
:
5234 case MPI2_RAID_PD_STATE_REBUILDING
:
5235 case MPI2_RAID_PD_STATE_OPTIMAL
:
5237 sas_device
->hidden_raid_component
= 1;
5241 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
5242 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
5244 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5245 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5249 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5250 MPI2_IOCSTATUS_MASK
;
5251 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5252 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5253 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5257 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
5258 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
5259 mpt2sas_transport_update_links(ioc
, sas_address
, handle
,
5260 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
5262 _scsih_add_device(ioc
, handle
, 0, 1);
5266 case MPI2_RAID_PD_STATE_OFFLINE
:
5267 case MPI2_RAID_PD_STATE_NOT_CONFIGURED
:
5268 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE
:
5269 case MPI2_RAID_PD_STATE_HOT_SPARE
:
5275 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5277 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
5278 * @ioc: per adapter object
5279 * @event_data: event data payload
5285 _scsih_sas_ir_operation_status_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
5286 Mpi2EventDataIrOperationStatus_t
*event_data
)
5288 char *reason_str
= NULL
;
5290 switch (event_data
->RAIDOperation
) {
5291 case MPI2_EVENT_IR_RAIDOP_RESYNC
:
5292 reason_str
= "resync";
5294 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION
:
5295 reason_str
= "online capacity expansion";
5297 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK
:
5298 reason_str
= "consistency check";
5300 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT
:
5301 reason_str
= "background init";
5303 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT
:
5304 reason_str
= "make data consistent";
5311 printk(MPT2SAS_INFO_FMT
"raid operational status: (%s)"
5312 "\thandle(0x%04x), percent complete(%d)\n",
5313 ioc
->name
, reason_str
,
5314 le16_to_cpu(event_data
->VolDevHandle
),
5315 event_data
->PercentComplete
);
5320 * _scsih_sas_ir_operation_status_event - handle RAID operation events
5321 * @ioc: per adapter object
5322 * @fw_event: The fw_event_work object
5328 _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER
*ioc
,
5329 struct fw_event_work
*fw_event
)
5331 Mpi2EventDataIrOperationStatus_t
*event_data
= fw_event
->event_data
;
5332 static struct _raid_device
*raid_device
;
5333 unsigned long flags
;
5336 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5337 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5338 _scsih_sas_ir_operation_status_event_debug(ioc
,
5342 /* code added for raid transport support */
5343 if (event_data
->RAIDOperation
== MPI2_EVENT_IR_RAIDOP_RESYNC
) {
5345 handle
= le16_to_cpu(event_data
->VolDevHandle
);
5347 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5348 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
5349 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5354 if (event_data
->RAIDOperation
== MPI2_EVENT_IR_RAIDOP_RESYNC
)
5355 raid_device
->percent_complete
=
5356 event_data
->PercentComplete
;
5361 * _scsih_task_set_full - handle task set full
5362 * @ioc: per adapter object
5363 * @fw_event: The fw_event_work object
5366 * Throttle back qdepth.
5369 _scsih_task_set_full(struct MPT2SAS_ADAPTER
*ioc
, struct fw_event_work
5372 unsigned long flags
;
5373 struct _sas_device
*sas_device
;
5374 static struct _raid_device
*raid_device
;
5375 struct scsi_device
*sdev
;
5381 Mpi2EventDataTaskSetFull_t
*event_data
= fw_event
->event_data
;
5383 current_depth
= le16_to_cpu(event_data
->CurrentDepth
);
5384 handle
= le16_to_cpu(event_data
->DevHandle
);
5385 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5386 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
5388 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5391 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5392 id
= sas_device
->id
;
5393 channel
= sas_device
->channel
;
5394 sas_address
= sas_device
->sas_address
;
5396 /* if hidden raid component, then change to volume characteristics */
5397 if (sas_device
->hidden_raid_component
&& sas_device
->volume_handle
) {
5398 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5399 raid_device
= _scsih_raid_device_find_by_handle(
5400 ioc
, sas_device
->volume_handle
);
5401 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5403 id
= raid_device
->id
;
5404 channel
= raid_device
->channel
;
5405 handle
= raid_device
->handle
;
5406 sas_address
= raid_device
->wwid
;
5410 if (ioc
->logging_level
& MPT_DEBUG_TASK_SET_FULL
)
5411 starget_printk(KERN_DEBUG
, sas_device
->starget
, "task set "
5412 "full: handle(0x%04x), sas_addr(0x%016llx), depth(%d)\n",
5413 handle
, (unsigned long long)sas_address
, current_depth
);
5415 shost_for_each_device(sdev
, ioc
->shost
) {
5416 if (sdev
->id
== id
&& sdev
->channel
== channel
) {
5417 if (current_depth
> sdev
->queue_depth
) {
5418 if (ioc
->logging_level
&
5419 MPT_DEBUG_TASK_SET_FULL
)
5420 sdev_printk(KERN_INFO
, sdev
, "strange "
5421 "observation, the queue depth is"
5422 " (%d) meanwhile fw queue depth "
5423 "is (%d)\n", sdev
->queue_depth
,
5427 depth
= scsi_track_queue_full(sdev
,
5430 sdev_printk(KERN_INFO
, sdev
, "Queue depth "
5431 "reduced to (%d)\n", depth
);
5433 sdev_printk(KERN_INFO
, sdev
, "Tagged Command "
5434 "Queueing is being disabled\n");
5435 else if (depth
== 0)
5436 if (ioc
->logging_level
&
5437 MPT_DEBUG_TASK_SET_FULL
)
5438 sdev_printk(KERN_INFO
, sdev
,
5439 "Queue depth not changed yet\n");
5445 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
5446 * @ioc: per adapter object
5447 * @sas_address: sas address
5448 * @slot: enclosure slot id
5449 * @handle: device handle
5451 * After host reset, find out whether devices are still responding.
5452 * Used in _scsi_remove_unresponsive_sas_devices.
5457 _scsih_mark_responding_sas_device(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
,
5458 u16 slot
, u16 handle
)
5460 struct MPT2SAS_TARGET
*sas_target_priv_data
;
5461 struct scsi_target
*starget
;
5462 struct _sas_device
*sas_device
;
5463 unsigned long flags
;
5465 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5466 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
) {
5467 if (sas_device
->sas_address
== sas_address
&&
5468 sas_device
->slot
== slot
&& sas_device
->starget
) {
5469 sas_device
->responding
= 1;
5470 sas_device
->state
= 0;
5471 starget
= sas_device
->starget
;
5472 sas_target_priv_data
= starget
->hostdata
;
5473 sas_target_priv_data
->tm_busy
= 0;
5474 starget_printk(KERN_INFO
, sas_device
->starget
,
5475 "handle(0x%04x), sas_addr(0x%016llx), enclosure "
5476 "logical id(0x%016llx), slot(%d)\n", handle
,
5477 (unsigned long long)sas_device
->sas_address
,
5478 (unsigned long long)
5479 sas_device
->enclosure_logical_id
,
5481 if (sas_device
->handle
== handle
)
5483 printk(KERN_INFO
"\thandle changed from(0x%04x)!!!\n",
5484 sas_device
->handle
);
5485 sas_device
->handle
= handle
;
5486 sas_target_priv_data
->handle
= handle
;
5491 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5495 * _scsih_search_responding_sas_devices -
5496 * @ioc: per adapter object
5498 * After host reset, find out whether devices are still responding.
5504 _scsih_search_responding_sas_devices(struct MPT2SAS_ADAPTER
*ioc
)
5506 Mpi2SasDevicePage0_t sas_device_pg0
;
5507 Mpi2ConfigReply_t mpi_reply
;
5514 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
, __func__
);
5516 if (list_empty(&ioc
->sas_device_list
))
5520 while (!(mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
5521 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
,
5523 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5524 MPI2_IOCSTATUS_MASK
;
5525 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
5527 handle
= le16_to_cpu(sas_device_pg0
.DevHandle
);
5528 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
5529 if (!(_scsih_is_end_device(device_info
)))
5531 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
5532 slot
= le16_to_cpu(sas_device_pg0
.Slot
);
5533 _scsih_mark_responding_sas_device(ioc
, sas_address
, slot
,
5539 * _scsih_mark_responding_raid_device - mark a raid_device as responding
5540 * @ioc: per adapter object
5541 * @wwid: world wide identifier for raid volume
5542 * @handle: device handle
5544 * After host reset, find out whether devices are still responding.
5545 * Used in _scsi_remove_unresponsive_raid_devices.
5550 _scsih_mark_responding_raid_device(struct MPT2SAS_ADAPTER
*ioc
, u64 wwid
,
5553 struct MPT2SAS_TARGET
*sas_target_priv_data
;
5554 struct scsi_target
*starget
;
5555 struct _raid_device
*raid_device
;
5556 unsigned long flags
;
5558 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5559 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
5560 if (raid_device
->wwid
== wwid
&& raid_device
->starget
) {
5561 raid_device
->responding
= 1;
5562 starget_printk(KERN_INFO
, raid_device
->starget
,
5563 "handle(0x%04x), wwid(0x%016llx)\n", handle
,
5564 (unsigned long long)raid_device
->wwid
);
5565 if (raid_device
->handle
== handle
)
5567 printk(KERN_INFO
"\thandle changed from(0x%04x)!!!\n",
5568 raid_device
->handle
);
5569 raid_device
->handle
= handle
;
5570 starget
= raid_device
->starget
;
5571 sas_target_priv_data
= starget
->hostdata
;
5572 sas_target_priv_data
->handle
= handle
;
5577 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5581 * _scsih_search_responding_raid_devices -
5582 * @ioc: per adapter object
5584 * After host reset, find out whether devices are still responding.
5590 _scsih_search_responding_raid_devices(struct MPT2SAS_ADAPTER
*ioc
)
5592 Mpi2RaidVolPage1_t volume_pg1
;
5593 Mpi2ConfigReply_t mpi_reply
;
5597 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
, __func__
);
5599 if (list_empty(&ioc
->raid_device_list
))
5603 while (!(mpt2sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
5604 &volume_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
5605 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5606 MPI2_IOCSTATUS_MASK
;
5607 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
5609 handle
= le16_to_cpu(volume_pg1
.DevHandle
);
5610 _scsih_mark_responding_raid_device(ioc
,
5611 le64_to_cpu(volume_pg1
.WWID
), handle
);
5616 * _scsih_mark_responding_expander - mark a expander as responding
5617 * @ioc: per adapter object
5618 * @sas_address: sas address
5621 * After host reset, find out whether devices are still responding.
5622 * Used in _scsi_remove_unresponsive_expanders.
5627 _scsih_mark_responding_expander(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
,
5630 struct _sas_node
*sas_expander
;
5631 unsigned long flags
;
5634 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5635 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
5636 if (sas_expander
->sas_address
!= sas_address
)
5638 sas_expander
->responding
= 1;
5639 if (sas_expander
->handle
== handle
)
5641 printk(KERN_INFO
"\texpander(0x%016llx): handle changed"
5642 " from(0x%04x) to (0x%04x)!!!\n",
5643 (unsigned long long)sas_expander
->sas_address
,
5644 sas_expander
->handle
, handle
);
5645 sas_expander
->handle
= handle
;
5646 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++)
5647 sas_expander
->phy
[i
].handle
= handle
;
5651 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5655 * _scsih_search_responding_expanders -
5656 * @ioc: per adapter object
5658 * After host reset, find out whether devices are still responding.
5664 _scsih_search_responding_expanders(struct MPT2SAS_ADAPTER
*ioc
)
5666 Mpi2ExpanderPage0_t expander_pg0
;
5667 Mpi2ConfigReply_t mpi_reply
;
5672 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
, __func__
);
5674 if (list_empty(&ioc
->sas_expander_list
))
5678 while (!(mpt2sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
5679 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL
, handle
))) {
5681 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5682 MPI2_IOCSTATUS_MASK
;
5683 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
5686 handle
= le16_to_cpu(expander_pg0
.DevHandle
);
5687 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
5688 printk(KERN_INFO
"\texpander present: handle(0x%04x), "
5689 "sas_addr(0x%016llx)\n", handle
,
5690 (unsigned long long)sas_address
);
5691 _scsih_mark_responding_expander(ioc
, sas_address
, handle
);
5697 * _scsih_remove_unresponding_devices - removing unresponding devices
5698 * @ioc: per adapter object
5703 _scsih_remove_unresponding_devices(struct MPT2SAS_ADAPTER
*ioc
)
5705 struct _sas_device
*sas_device
, *sas_device_next
;
5706 struct _sas_node
*sas_expander
;
5707 struct _raid_device
*raid_device
, *raid_device_next
;
5710 list_for_each_entry_safe(sas_device
, sas_device_next
,
5711 &ioc
->sas_device_list
, list
) {
5712 if (sas_device
->responding
) {
5713 sas_device
->responding
= 0;
5716 if (sas_device
->starget
)
5717 starget_printk(KERN_INFO
, sas_device
->starget
,
5718 "removing: handle(0x%04x), sas_addr(0x%016llx), "
5719 "enclosure logical id(0x%016llx), slot(%d)\n",
5721 (unsigned long long)sas_device
->sas_address
,
5722 (unsigned long long)
5723 sas_device
->enclosure_logical_id
,
5725 /* invalidate the device handle */
5726 sas_device
->handle
= 0;
5727 _scsih_remove_device(ioc
, sas_device
);
5730 list_for_each_entry_safe(raid_device
, raid_device_next
,
5731 &ioc
->raid_device_list
, list
) {
5732 if (raid_device
->responding
) {
5733 raid_device
->responding
= 0;
5736 if (raid_device
->starget
) {
5737 starget_printk(KERN_INFO
, raid_device
->starget
,
5738 "removing: handle(0x%04x), wwid(0x%016llx)\n",
5739 raid_device
->handle
,
5740 (unsigned long long)raid_device
->wwid
);
5741 scsi_remove_target(&raid_device
->starget
->dev
);
5743 _scsih_raid_device_remove(ioc
, raid_device
);
5746 retry_expander_search
:
5747 sas_expander
= NULL
;
5748 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
5749 if (sas_expander
->responding
) {
5750 sas_expander
->responding
= 0;
5753 _scsih_expander_remove(ioc
, sas_expander
->sas_address
);
5754 goto retry_expander_search
;
5759 * mpt2sas_scsih_reset_handler - reset callback handler (for scsih)
5760 * @ioc: per adapter object
5761 * @reset_phase: phase
5763 * The handler for doing any required cleanup or initialization.
5765 * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
5766 * MPT2_IOC_DONE_RESET
5771 mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER
*ioc
, int reset_phase
)
5773 switch (reset_phase
) {
5774 case MPT2_IOC_PRE_RESET
:
5775 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: "
5776 "MPT2_IOC_PRE_RESET\n", ioc
->name
, __func__
));
5777 _scsih_fw_event_off(ioc
);
5779 case MPT2_IOC_AFTER_RESET
:
5780 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: "
5781 "MPT2_IOC_AFTER_RESET\n", ioc
->name
, __func__
));
5782 if (ioc
->tm_cmds
.status
& MPT2_CMD_PENDING
) {
5783 ioc
->tm_cmds
.status
|= MPT2_CMD_RESET
;
5784 mpt2sas_base_free_smid(ioc
, ioc
->tm_cmds
.smid
);
5785 complete(&ioc
->tm_cmds
.done
);
5787 _scsih_fw_event_on(ioc
);
5788 _scsih_flush_running_cmds(ioc
);
5790 case MPT2_IOC_DONE_RESET
:
5791 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: "
5792 "MPT2_IOC_DONE_RESET\n", ioc
->name
, __func__
));
5793 _scsih_sas_host_refresh(ioc
);
5794 _scsih_search_responding_sas_devices(ioc
);
5795 _scsih_search_responding_raid_devices(ioc
);
5796 _scsih_search_responding_expanders(ioc
);
5798 case MPT2_IOC_RUNNING
:
5799 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: "
5800 "MPT2_IOC_RUNNING\n", ioc
->name
, __func__
));
5801 _scsih_remove_unresponding_devices(ioc
);
5807 * _firmware_event_work - delayed task for processing firmware events
5808 * @ioc: per adapter object
5809 * @work: equal to the fw_event_work object
5815 _firmware_event_work(struct work_struct
*work
)
5817 struct fw_event_work
*fw_event
= container_of(work
,
5818 struct fw_event_work
, work
);
5819 unsigned long flags
;
5820 struct MPT2SAS_ADAPTER
*ioc
= fw_event
->ioc
;
5822 /* the queue is being flushed so ignore this event */
5823 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
5824 if (ioc
->fw_events_off
|| ioc
->remove_host
) {
5825 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
5826 _scsih_fw_event_free(ioc
, fw_event
);
5829 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
5831 if (ioc
->shost_recovery
) {
5832 _scsih_fw_event_requeue(ioc
, fw_event
, 1000);
5836 switch (fw_event
->event
) {
5837 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
5838 _scsih_sas_topology_change_event(ioc
, fw_event
);
5840 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
5841 _scsih_sas_device_status_change_event(ioc
,
5844 case MPI2_EVENT_SAS_DISCOVERY
:
5845 _scsih_sas_discovery_event(ioc
,
5848 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
5849 _scsih_sas_broadcast_primative_event(ioc
,
5852 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
5853 _scsih_sas_enclosure_dev_status_change_event(ioc
,
5856 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
5857 _scsih_sas_ir_config_change_event(ioc
, fw_event
);
5859 case MPI2_EVENT_IR_VOLUME
:
5860 _scsih_sas_ir_volume_event(ioc
, fw_event
);
5862 case MPI2_EVENT_IR_PHYSICAL_DISK
:
5863 _scsih_sas_ir_physical_disk_event(ioc
, fw_event
);
5865 case MPI2_EVENT_IR_OPERATION_STATUS
:
5866 _scsih_sas_ir_operation_status_event(ioc
, fw_event
);
5868 case MPI2_EVENT_TASK_SET_FULL
:
5869 _scsih_task_set_full(ioc
, fw_event
);
5872 _scsih_fw_event_free(ioc
, fw_event
);
5876 * mpt2sas_scsih_event_callback - firmware event handler (called at ISR time)
5877 * @ioc: per adapter object
5878 * @msix_index: MSIX table index supplied by the OS
5879 * @reply: reply message frame(lower 32bit addr)
5880 * Context: interrupt.
5882 * This function merely adds a new work task into ioc->firmware_event_thread.
5883 * The tasks are worked from _firmware_event_work in user context.
5885 * Return 1 meaning mf should be freed from _base_interrupt
5886 * 0 means the mf is freed from this function.
5889 mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER
*ioc
, u8 msix_index
,
5892 struct fw_event_work
*fw_event
;
5893 Mpi2EventNotificationReply_t
*mpi_reply
;
5894 unsigned long flags
;
5897 /* events turned off due to host reset or driver unloading */
5898 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
5899 if (ioc
->fw_events_off
|| ioc
->remove_host
) {
5900 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
5903 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
5905 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
5906 event
= le16_to_cpu(mpi_reply
->Event
);
5910 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
5912 Mpi2EventDataSasBroadcastPrimitive_t
*baen_data
=
5913 (Mpi2EventDataSasBroadcastPrimitive_t
*)
5914 mpi_reply
->EventData
;
5916 if (baen_data
->Primitive
!=
5917 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT
||
5918 ioc
->broadcast_aen_busy
)
5920 ioc
->broadcast_aen_busy
= 1;
5924 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
5925 _scsih_check_topo_delete_events(ioc
,
5926 (Mpi2EventDataSasTopologyChangeList_t
*)
5927 mpi_reply
->EventData
);
5930 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
5931 case MPI2_EVENT_IR_OPERATION_STATUS
:
5932 case MPI2_EVENT_SAS_DISCOVERY
:
5933 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
5934 case MPI2_EVENT_IR_VOLUME
:
5935 case MPI2_EVENT_IR_PHYSICAL_DISK
:
5936 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
5937 case MPI2_EVENT_TASK_SET_FULL
:
5940 default: /* ignore the rest */
5944 fw_event
= kzalloc(sizeof(struct fw_event_work
), GFP_ATOMIC
);
5946 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5947 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5950 fw_event
->event_data
=
5951 kzalloc(mpi_reply
->EventDataLength
*4, GFP_ATOMIC
);
5952 if (!fw_event
->event_data
) {
5953 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5954 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5959 memcpy(fw_event
->event_data
, mpi_reply
->EventData
,
5960 mpi_reply
->EventDataLength
*4);
5961 fw_event
->ioc
= ioc
;
5962 fw_event
->VF_ID
= mpi_reply
->VF_ID
;
5963 fw_event
->VP_ID
= mpi_reply
->VP_ID
;
5964 fw_event
->event
= event
;
5965 _scsih_fw_event_add(ioc
, fw_event
);
5969 /* shost template */
5970 static struct scsi_host_template scsih_driver_template
= {
5971 .module
= THIS_MODULE
,
5972 .name
= "Fusion MPT SAS Host",
5973 .proc_name
= MPT2SAS_DRIVER_NAME
,
5974 .queuecommand
= _scsih_qcmd
,
5975 .target_alloc
= _scsih_target_alloc
,
5976 .slave_alloc
= _scsih_slave_alloc
,
5977 .slave_configure
= _scsih_slave_configure
,
5978 .target_destroy
= _scsih_target_destroy
,
5979 .slave_destroy
= _scsih_slave_destroy
,
5980 .change_queue_depth
= _scsih_change_queue_depth
,
5981 .change_queue_type
= _scsih_change_queue_type
,
5982 .eh_abort_handler
= _scsih_abort
,
5983 .eh_device_reset_handler
= _scsih_dev_reset
,
5984 .eh_target_reset_handler
= _scsih_target_reset
,
5985 .eh_host_reset_handler
= _scsih_host_reset
,
5986 .bios_param
= _scsih_bios_param
,
5989 .sg_tablesize
= MPT2SAS_SG_DEPTH
,
5990 .max_sectors
= 8192,
5992 .use_clustering
= ENABLE_CLUSTERING
,
5993 .shost_attrs
= mpt2sas_host_attrs
,
5994 .sdev_attrs
= mpt2sas_dev_attrs
,
5998 * _scsih_expander_node_remove - removing expander device from list.
5999 * @ioc: per adapter object
6000 * @sas_expander: the sas_device object
6001 * Context: Calling function should acquire ioc->sas_node_lock.
6003 * Removing object and freeing associated memory from the
6004 * ioc->sas_expander_list.
6009 _scsih_expander_node_remove(struct MPT2SAS_ADAPTER
*ioc
,
6010 struct _sas_node
*sas_expander
)
6012 struct _sas_port
*mpt2sas_port
;
6013 struct _sas_device
*sas_device
;
6014 struct _sas_node
*expander_sibling
;
6015 unsigned long flags
;
6020 /* remove sibling ports attached to this expander */
6021 retry_device_search
:
6022 list_for_each_entry(mpt2sas_port
,
6023 &sas_expander
->sas_port_list
, port_list
) {
6024 if (mpt2sas_port
->remote_identify
.device_type
==
6026 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6028 mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
6029 mpt2sas_port
->remote_identify
.sas_address
);
6030 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6033 _scsih_remove_device(ioc
, sas_device
);
6034 if (ioc
->shost_recovery
)
6036 goto retry_device_search
;
6040 retry_expander_search
:
6041 list_for_each_entry(mpt2sas_port
,
6042 &sas_expander
->sas_port_list
, port_list
) {
6044 if (mpt2sas_port
->remote_identify
.device_type
==
6045 MPI2_SAS_DEVICE_INFO_EDGE_EXPANDER
||
6046 mpt2sas_port
->remote_identify
.device_type
==
6047 MPI2_SAS_DEVICE_INFO_FANOUT_EXPANDER
) {
6049 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
6051 mpt2sas_scsih_expander_find_by_sas_address(
6052 ioc
, mpt2sas_port
->remote_identify
.sas_address
);
6053 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
6054 if (!expander_sibling
)
6056 _scsih_expander_remove(ioc
,
6057 expander_sibling
->sas_address
);
6058 if (ioc
->shost_recovery
)
6060 goto retry_expander_search
;
6064 mpt2sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
6065 sas_expander
->sas_address_parent
);
6067 printk(MPT2SAS_INFO_FMT
"expander_remove: handle"
6068 "(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
6069 sas_expander
->handle
, (unsigned long long)
6070 sas_expander
->sas_address
);
6072 list_del(&sas_expander
->list
);
6073 kfree(sas_expander
->phy
);
6074 kfree(sas_expander
);
6078 * _scsih_ir_shutdown - IR shutdown notification
6079 * @ioc: per adapter object
6081 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
6082 * the host system is shutting down.
6087 _scsih_ir_shutdown(struct MPT2SAS_ADAPTER
*ioc
)
6089 Mpi2RaidActionRequest_t
*mpi_request
;
6090 Mpi2RaidActionReply_t
*mpi_reply
;
6093 /* is IR firmware build loaded ? */
6094 if (!ioc
->ir_firmware
)
6097 /* are there any volumes ? */
6098 if (list_empty(&ioc
->raid_device_list
))
6101 mutex_lock(&ioc
->scsih_cmds
.mutex
);
6103 if (ioc
->scsih_cmds
.status
!= MPT2_CMD_NOT_USED
) {
6104 printk(MPT2SAS_ERR_FMT
"%s: scsih_cmd in use\n",
6105 ioc
->name
, __func__
);
6108 ioc
->scsih_cmds
.status
= MPT2_CMD_PENDING
;
6110 smid
= mpt2sas_base_get_smid(ioc
, ioc
->scsih_cb_idx
);
6112 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
6113 ioc
->name
, __func__
);
6114 ioc
->scsih_cmds
.status
= MPT2_CMD_NOT_USED
;
6118 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
6119 ioc
->scsih_cmds
.smid
= smid
;
6120 memset(mpi_request
, 0, sizeof(Mpi2RaidActionRequest_t
));
6122 mpi_request
->Function
= MPI2_FUNCTION_RAID_ACTION
;
6123 mpi_request
->Action
= MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED
;
6125 printk(MPT2SAS_INFO_FMT
"IR shutdown (sending)\n", ioc
->name
);
6126 init_completion(&ioc
->scsih_cmds
.done
);
6127 mpt2sas_base_put_smid_default(ioc
, smid
);
6128 wait_for_completion_timeout(&ioc
->scsih_cmds
.done
, 10*HZ
);
6130 if (!(ioc
->scsih_cmds
.status
& MPT2_CMD_COMPLETE
)) {
6131 printk(MPT2SAS_ERR_FMT
"%s: timeout\n",
6132 ioc
->name
, __func__
);
6136 if (ioc
->scsih_cmds
.status
& MPT2_CMD_REPLY_VALID
) {
6137 mpi_reply
= ioc
->scsih_cmds
.reply
;
6139 printk(MPT2SAS_INFO_FMT
"IR shutdown (complete): "
6140 "ioc_status(0x%04x), loginfo(0x%08x)\n",
6141 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
6142 le32_to_cpu(mpi_reply
->IOCLogInfo
));
6146 ioc
->scsih_cmds
.status
= MPT2_CMD_NOT_USED
;
6147 mutex_unlock(&ioc
->scsih_cmds
.mutex
);
6151 * _scsih_shutdown - routine call during system shutdown
6152 * @pdev: PCI device struct
6157 _scsih_shutdown(struct pci_dev
*pdev
)
6159 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6160 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
6162 _scsih_ir_shutdown(ioc
);
6163 mpt2sas_base_detach(ioc
);
6167 * _scsih_remove - detach and remove add host
6168 * @pdev: PCI device struct
6170 * Routine called when unloading the driver.
6173 static void __devexit
6174 _scsih_remove(struct pci_dev
*pdev
)
6176 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6177 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
6178 struct _sas_port
*mpt2sas_port
;
6179 struct _sas_device
*sas_device
;
6180 struct _sas_node
*expander_sibling
;
6181 struct _raid_device
*raid_device
, *next
;
6182 struct MPT2SAS_TARGET
*sas_target_priv_data
;
6183 struct workqueue_struct
*wq
;
6184 unsigned long flags
;
6186 ioc
->remove_host
= 1;
6187 _scsih_fw_event_off(ioc
);
6189 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
6190 wq
= ioc
->firmware_event_thread
;
6191 ioc
->firmware_event_thread
= NULL
;
6192 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
6194 destroy_workqueue(wq
);
6196 /* release all the volumes */
6197 list_for_each_entry_safe(raid_device
, next
, &ioc
->raid_device_list
,
6199 if (raid_device
->starget
) {
6200 sas_target_priv_data
=
6201 raid_device
->starget
->hostdata
;
6202 sas_target_priv_data
->deleted
= 1;
6203 scsi_remove_target(&raid_device
->starget
->dev
);
6205 printk(MPT2SAS_INFO_FMT
"removing handle(0x%04x), wwid"
6206 "(0x%016llx)\n", ioc
->name
, raid_device
->handle
,
6207 (unsigned long long) raid_device
->wwid
);
6208 _scsih_raid_device_remove(ioc
, raid_device
);
6211 /* free ports attached to the sas_host */
6213 list_for_each_entry(mpt2sas_port
,
6214 &ioc
->sas_hba
.sas_port_list
, port_list
) {
6215 if (mpt2sas_port
->remote_identify
.device_type
==
6218 mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
6219 mpt2sas_port
->remote_identify
.sas_address
);
6221 _scsih_remove_device(ioc
, sas_device
);
6226 mpt2sas_scsih_expander_find_by_sas_address(ioc
,
6227 mpt2sas_port
->remote_identify
.sas_address
);
6228 if (expander_sibling
) {
6229 _scsih_expander_remove(ioc
,
6230 expander_sibling
->sas_address
);
6236 /* free phys attached to the sas_host */
6237 if (ioc
->sas_hba
.num_phys
) {
6238 kfree(ioc
->sas_hba
.phy
);
6239 ioc
->sas_hba
.phy
= NULL
;
6240 ioc
->sas_hba
.num_phys
= 0;
6243 sas_remove_host(shost
);
6244 _scsih_shutdown(pdev
);
6245 list_del(&ioc
->list
);
6246 scsi_remove_host(shost
);
6247 scsi_host_put(shost
);
6251 * _scsih_probe_boot_devices - reports 1st device
6252 * @ioc: per adapter object
6254 * If specified in bios page 2, this routine reports the 1st
6255 * device scsi-ml or sas transport for persistent boot device
6256 * purposes. Please refer to function _scsih_determine_boot_device()
6259 _scsih_probe_boot_devices(struct MPT2SAS_ADAPTER
*ioc
)
6263 struct _sas_device
*sas_device
;
6264 struct _raid_device
*raid_device
;
6266 u64 sas_address_parent
;
6268 unsigned long flags
;
6272 if (ioc
->req_boot_device
.device
) {
6273 device
= ioc
->req_boot_device
.device
;
6274 is_raid
= ioc
->req_boot_device
.is_raid
;
6275 } else if (ioc
->req_alt_boot_device
.device
) {
6276 device
= ioc
->req_alt_boot_device
.device
;
6277 is_raid
= ioc
->req_alt_boot_device
.is_raid
;
6278 } else if (ioc
->current_boot_device
.device
) {
6279 device
= ioc
->current_boot_device
.device
;
6280 is_raid
= ioc
->current_boot_device
.is_raid
;
6287 raid_device
= device
;
6288 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
6289 raid_device
->id
, 0);
6291 _scsih_raid_device_remove(ioc
, raid_device
);
6293 sas_device
= device
;
6294 handle
= sas_device
->handle
;
6295 sas_address_parent
= sas_device
->sas_address_parent
;
6296 sas_address
= sas_device
->sas_address
;
6297 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6298 list_move_tail(&sas_device
->list
, &ioc
->sas_device_list
);
6299 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6300 if (!mpt2sas_transport_port_add(ioc
, sas_device
->handle
,
6301 sas_device
->sas_address_parent
)) {
6302 _scsih_sas_device_remove(ioc
, sas_device
);
6303 } else if (!sas_device
->starget
) {
6304 mpt2sas_transport_port_remove(ioc
, sas_address
,
6305 sas_address_parent
);
6306 _scsih_sas_device_remove(ioc
, sas_device
);
6312 * _scsih_probe_raid - reporting raid volumes to scsi-ml
6313 * @ioc: per adapter object
6315 * Called during initial loading of the driver.
6318 _scsih_probe_raid(struct MPT2SAS_ADAPTER
*ioc
)
6320 struct _raid_device
*raid_device
, *raid_next
;
6323 list_for_each_entry_safe(raid_device
, raid_next
,
6324 &ioc
->raid_device_list
, list
) {
6325 if (raid_device
->starget
)
6327 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
6328 raid_device
->id
, 0);
6330 _scsih_raid_device_remove(ioc
, raid_device
);
6335 * _scsih_probe_sas - reporting sas devices to sas transport
6336 * @ioc: per adapter object
6338 * Called during initial loading of the driver.
6341 _scsih_probe_sas(struct MPT2SAS_ADAPTER
*ioc
)
6343 struct _sas_device
*sas_device
, *next
;
6344 unsigned long flags
;
6346 /* SAS Device List */
6347 list_for_each_entry_safe(sas_device
, next
, &ioc
->sas_device_init_list
,
6349 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6350 list_move_tail(&sas_device
->list
, &ioc
->sas_device_list
);
6351 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6353 if (!mpt2sas_transport_port_add(ioc
, sas_device
->handle
,
6354 sas_device
->sas_address_parent
)) {
6355 _scsih_sas_device_remove(ioc
, sas_device
);
6356 } else if (!sas_device
->starget
) {
6357 mpt2sas_transport_port_remove(ioc
,
6358 sas_device
->sas_address
,
6359 sas_device
->sas_address_parent
);
6360 _scsih_sas_device_remove(ioc
, sas_device
);
6366 * _scsih_probe_devices - probing for devices
6367 * @ioc: per adapter object
6369 * Called during initial loading of the driver.
6372 _scsih_probe_devices(struct MPT2SAS_ADAPTER
*ioc
)
6374 u16 volume_mapping_flags
=
6375 le16_to_cpu(ioc
->ioc_pg8
.IRVolumeMappingFlags
) &
6376 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE
;
6378 if (!(ioc
->facts
.ProtocolFlags
& MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR
))
6379 return; /* return when IOC doesn't support initiator mode */
6381 _scsih_probe_boot_devices(ioc
);
6383 if (ioc
->ir_firmware
) {
6384 if ((volume_mapping_flags
&
6385 MPI2_IOCPAGE8_IRFLAGS_HIGH_VOLUME_MAPPING
)) {
6386 _scsih_probe_sas(ioc
);
6387 _scsih_probe_raid(ioc
);
6389 _scsih_probe_raid(ioc
);
6390 _scsih_probe_sas(ioc
);
6393 _scsih_probe_sas(ioc
);
6397 * _scsih_probe - attach and add scsi host
6398 * @pdev: PCI device struct
6399 * @id: pci device id
6401 * Returns 0 success, anything else error.
6404 _scsih_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
6406 struct MPT2SAS_ADAPTER
*ioc
;
6407 struct Scsi_Host
*shost
;
6409 shost
= scsi_host_alloc(&scsih_driver_template
,
6410 sizeof(struct MPT2SAS_ADAPTER
));
6414 /* init local params */
6415 ioc
= shost_priv(shost
);
6416 memset(ioc
, 0, sizeof(struct MPT2SAS_ADAPTER
));
6417 INIT_LIST_HEAD(&ioc
->list
);
6418 list_add_tail(&ioc
->list
, &mpt2sas_ioc_list
);
6420 ioc
->id
= mpt_ids
++;
6421 sprintf(ioc
->name
, "%s%d", MPT2SAS_DRIVER_NAME
, ioc
->id
);
6423 ioc
->scsi_io_cb_idx
= scsi_io_cb_idx
;
6424 ioc
->tm_cb_idx
= tm_cb_idx
;
6425 ioc
->ctl_cb_idx
= ctl_cb_idx
;
6426 ioc
->base_cb_idx
= base_cb_idx
;
6427 ioc
->transport_cb_idx
= transport_cb_idx
;
6428 ioc
->scsih_cb_idx
= scsih_cb_idx
;
6429 ioc
->config_cb_idx
= config_cb_idx
;
6430 ioc
->tm_tr_cb_idx
= tm_tr_cb_idx
;
6431 ioc
->tm_sas_control_cb_idx
= tm_sas_control_cb_idx
;
6432 ioc
->logging_level
= logging_level
;
6433 /* misc semaphores and spin locks */
6434 spin_lock_init(&ioc
->ioc_reset_in_progress_lock
);
6435 spin_lock_init(&ioc
->scsi_lookup_lock
);
6436 spin_lock_init(&ioc
->sas_device_lock
);
6437 spin_lock_init(&ioc
->sas_node_lock
);
6438 spin_lock_init(&ioc
->fw_event_lock
);
6439 spin_lock_init(&ioc
->raid_device_lock
);
6441 INIT_LIST_HEAD(&ioc
->sas_device_list
);
6442 INIT_LIST_HEAD(&ioc
->sas_device_init_list
);
6443 INIT_LIST_HEAD(&ioc
->sas_expander_list
);
6444 INIT_LIST_HEAD(&ioc
->fw_event_list
);
6445 INIT_LIST_HEAD(&ioc
->raid_device_list
);
6446 INIT_LIST_HEAD(&ioc
->sas_hba
.sas_port_list
);
6447 INIT_LIST_HEAD(&ioc
->delayed_tr_list
);
6449 /* init shost parameters */
6450 shost
->max_cmd_len
= 16;
6451 shost
->max_lun
= max_lun
;
6452 shost
->transportt
= mpt2sas_transport_template
;
6453 shost
->unique_id
= ioc
->id
;
6455 if ((scsi_add_host(shost
, &pdev
->dev
))) {
6456 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6457 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6458 list_del(&ioc
->list
);
6459 goto out_add_shost_fail
;
6462 scsi_host_set_prot(shost
, SHOST_DIF_TYPE1_PROTECTION
6463 | SHOST_DIF_TYPE3_PROTECTION
);
6464 scsi_host_set_guard(shost
, SHOST_DIX_GUARD_CRC
);
6467 snprintf(ioc
->firmware_event_name
, sizeof(ioc
->firmware_event_name
),
6468 "fw_event%d", ioc
->id
);
6469 ioc
->firmware_event_thread
= create_singlethread_workqueue(
6470 ioc
->firmware_event_name
);
6471 if (!ioc
->firmware_event_thread
) {
6472 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6473 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6474 goto out_thread_fail
;
6477 ioc
->wait_for_port_enable_to_complete
= 1;
6478 if ((mpt2sas_base_attach(ioc
))) {
6479 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6480 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6481 goto out_attach_fail
;
6484 ioc
->wait_for_port_enable_to_complete
= 0;
6485 _scsih_probe_devices(ioc
);
6489 destroy_workqueue(ioc
->firmware_event_thread
);
6491 list_del(&ioc
->list
);
6492 scsi_remove_host(shost
);
6499 * _scsih_suspend - power management suspend main entry point
6500 * @pdev: PCI device struct
6501 * @state: PM state change to (usually PCI_D3)
6503 * Returns 0 success, anything else error.
6506 _scsih_suspend(struct pci_dev
*pdev
, pm_message_t state
)
6508 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6509 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
6512 mpt2sas_base_stop_watchdog(ioc
);
6513 flush_scheduled_work();
6514 scsi_block_requests(shost
);
6515 device_state
= pci_choose_state(pdev
, state
);
6516 printk(MPT2SAS_INFO_FMT
"pdev=0x%p, slot=%s, entering "
6517 "operating state [D%d]\n", ioc
->name
, pdev
,
6518 pci_name(pdev
), device_state
);
6520 mpt2sas_base_free_resources(ioc
);
6521 pci_save_state(pdev
);
6522 pci_disable_device(pdev
);
6523 pci_set_power_state(pdev
, device_state
);
6528 * _scsih_resume - power management resume main entry point
6529 * @pdev: PCI device struct
6531 * Returns 0 success, anything else error.
6534 _scsih_resume(struct pci_dev
*pdev
)
6536 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6537 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
6538 u32 device_state
= pdev
->current_state
;
6541 printk(MPT2SAS_INFO_FMT
"pdev=0x%p, slot=%s, previous "
6542 "operating state [D%d]\n", ioc
->name
, pdev
,
6543 pci_name(pdev
), device_state
);
6545 pci_set_power_state(pdev
, PCI_D0
);
6546 pci_enable_wake(pdev
, PCI_D0
, 0);
6547 pci_restore_state(pdev
);
6549 r
= mpt2sas_base_map_resources(ioc
);
6553 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
, SOFT_RESET
);
6554 scsi_unblock_requests(shost
);
6555 mpt2sas_base_start_watchdog(ioc
);
6558 #endif /* CONFIG_PM */
6561 static struct pci_driver scsih_driver
= {
6562 .name
= MPT2SAS_DRIVER_NAME
,
6563 .id_table
= scsih_pci_table
,
6564 .probe
= _scsih_probe
,
6565 .remove
= __devexit_p(_scsih_remove
),
6566 .shutdown
= _scsih_shutdown
,
6568 .suspend
= _scsih_suspend
,
6569 .resume
= _scsih_resume
,
6573 /* raid transport support */
6574 static struct raid_function_template mpt2sas_raid_functions
= {
6575 .cookie
= &scsih_driver_template
,
6576 .is_raid
= _scsih_is_raid
,
6577 .get_resync
= _scsih_get_resync
,
6578 .get_state
= _scsih_get_state
,
6582 * _scsih_init - main entry point for this driver.
6584 * Returns 0 success, anything else error.
6592 printk(KERN_INFO
"%s version %s loaded\n", MPT2SAS_DRIVER_NAME
,
6593 MPT2SAS_DRIVER_VERSION
);
6595 mpt2sas_transport_template
=
6596 sas_attach_transport(&mpt2sas_transport_functions
);
6597 if (!mpt2sas_transport_template
)
6599 /* raid transport support */
6600 mpt2sas_raid_template
= raid_class_attach(&mpt2sas_raid_functions
);
6601 if (!mpt2sas_raid_template
) {
6602 sas_release_transport(mpt2sas_transport_template
);
6606 mpt2sas_base_initialize_callback_handler();
6608 /* queuecommand callback hander */
6609 scsi_io_cb_idx
= mpt2sas_base_register_callback_handler(_scsih_io_done
);
6611 /* task managment callback handler */
6612 tm_cb_idx
= mpt2sas_base_register_callback_handler(_scsih_tm_done
);
6614 /* base internal commands callback handler */
6615 base_cb_idx
= mpt2sas_base_register_callback_handler(mpt2sas_base_done
);
6617 /* transport internal commands callback handler */
6618 transport_cb_idx
= mpt2sas_base_register_callback_handler(
6619 mpt2sas_transport_done
);
6621 /* scsih internal commands callback handler */
6622 scsih_cb_idx
= mpt2sas_base_register_callback_handler(_scsih_done
);
6624 /* configuration page API internal commands callback handler */
6625 config_cb_idx
= mpt2sas_base_register_callback_handler(
6626 mpt2sas_config_done
);
6628 /* ctl module callback handler */
6629 ctl_cb_idx
= mpt2sas_base_register_callback_handler(mpt2sas_ctl_done
);
6631 tm_tr_cb_idx
= mpt2sas_base_register_callback_handler(
6632 _scsih_tm_tr_complete
);
6633 tm_sas_control_cb_idx
= mpt2sas_base_register_callback_handler(
6634 _scsih_sas_control_complete
);
6638 error
= pci_register_driver(&scsih_driver
);
6640 /* raid transport support */
6641 raid_class_release(mpt2sas_raid_template
);
6642 sas_release_transport(mpt2sas_transport_template
);
6649 * _scsih_exit - exit point for this driver (when it is a module).
6651 * Returns 0 success, anything else error.
6656 printk(KERN_INFO
"mpt2sas version %s unloading\n",
6657 MPT2SAS_DRIVER_VERSION
);
6659 pci_unregister_driver(&scsih_driver
);
6663 mpt2sas_base_release_callback_handler(scsi_io_cb_idx
);
6664 mpt2sas_base_release_callback_handler(tm_cb_idx
);
6665 mpt2sas_base_release_callback_handler(base_cb_idx
);
6666 mpt2sas_base_release_callback_handler(transport_cb_idx
);
6667 mpt2sas_base_release_callback_handler(scsih_cb_idx
);
6668 mpt2sas_base_release_callback_handler(config_cb_idx
);
6669 mpt2sas_base_release_callback_handler(ctl_cb_idx
);
6671 mpt2sas_base_release_callback_handler(tm_tr_cb_idx
);
6672 mpt2sas_base_release_callback_handler(tm_sas_control_cb_idx
);
6674 /* raid transport support */
6675 raid_class_release(mpt2sas_raid_template
);
6676 sas_release_transport(mpt2sas_transport_template
);
6680 module_init(_scsih_init
);
6681 module_exit(_scsih_exit
);