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>
56 #include "mpt2sas_base.h"
58 MODULE_AUTHOR(MPT2SAS_AUTHOR
);
59 MODULE_DESCRIPTION(MPT2SAS_DESCRIPTION
);
60 MODULE_LICENSE("GPL");
61 MODULE_VERSION(MPT2SAS_DRIVER_VERSION
);
63 #define RAID_CHANNEL 1
66 static void _scsih_expander_node_remove(struct MPT2SAS_ADAPTER
*ioc
,
67 struct _sas_node
*sas_expander
);
68 static void _firmware_event_work(struct work_struct
*work
);
70 /* global parameters */
71 LIST_HEAD(mpt2sas_ioc_list
);
73 /* local parameters */
74 static u8 scsi_io_cb_idx
= -1;
75 static u8 tm_cb_idx
= -1;
76 static u8 ctl_cb_idx
= -1;
77 static u8 base_cb_idx
= -1;
78 static u8 transport_cb_idx
= -1;
79 static u8 scsih_cb_idx
= -1;
80 static u8 config_cb_idx
= -1;
83 static u8 tm_tr_cb_idx
= -1 ;
84 static u8 tm_sas_control_cb_idx
= -1;
86 /* command line options */
87 static u32 logging_level
;
88 MODULE_PARM_DESC(logging_level
, " bits for enabling additional logging info "
91 /* scsi-mid layer global parmeter is max_report_luns, which is 511 */
92 #define MPT2SAS_MAX_LUN (16895)
93 static int max_lun
= MPT2SAS_MAX_LUN
;
94 module_param(max_lun
, int, 0);
95 MODULE_PARM_DESC(max_lun
, " max lun, default=16895 ");
98 * struct sense_info - common structure for obtaining sense keys
100 * @asc: additional sense code
101 * @ascq: additional sense code qualifier
111 * struct fw_event_work - firmware event struct
112 * @list: link list framework
113 * @work: work object (ioc->fault_reset_work_q)
114 * @ioc: per adapter object
115 * @VF_ID: virtual function id
116 * @VP_ID: virtual port id
117 * @host_reset_handling: handling events during host reset
118 * @ignore: flag meaning this event has been marked to ignore
119 * @event: firmware event MPI2_EVENT_XXX defined in mpt2_ioc.h
120 * @event_data: reply event data payload follows
122 * This object stored on ioc->fw_event_list.
124 struct fw_event_work
{
125 struct list_head list
;
126 struct work_struct work
;
127 struct MPT2SAS_ADAPTER
*ioc
;
130 u8 host_reset_handling
;
137 * struct _scsi_io_transfer - scsi io transfer
138 * @handle: sas device handle (assigned by firmware)
139 * @is_raid: flag set for hidden raid components
140 * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE,
141 * @data_length: data transfer length
142 * @data_dma: dma pointer to data
145 * @cdb_length: cdb length
147 * @timeout: timeout for this command
148 * @VF_ID: virtual function id
149 * @VP_ID: virtual port id
150 * @valid_reply: flag set for reply message
151 * @sense_length: sense length
152 * @ioc_status: ioc status
153 * @scsi_state: scsi state
154 * @scsi_status: scsi staus
155 * @log_info: log information
156 * @transfer_length: data length transfer when there is a reply message
158 * Used for sending internal scsi commands to devices within this module.
159 * Refer to _scsi_send_scsi_io().
161 struct _scsi_io_transfer
{
164 enum dma_data_direction dir
;
167 u8 sense
[SCSI_SENSE_BUFFERSIZE
];
175 /* the following bits are only valid when 'valid_reply = 1' */
185 * The pci device ids are defined in mpi/mpi2_cnfg.h.
187 static struct pci_device_id scsih_pci_table
[] = {
188 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2004
,
189 PCI_ANY_ID
, PCI_ANY_ID
},
191 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2008
,
192 PCI_ANY_ID
, PCI_ANY_ID
},
193 /* Liberator ~ 2108 */
194 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_1
,
195 PCI_ANY_ID
, PCI_ANY_ID
},
196 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_2
,
197 PCI_ANY_ID
, PCI_ANY_ID
},
198 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_3
,
199 PCI_ANY_ID
, PCI_ANY_ID
},
201 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2116_1
,
202 PCI_ANY_ID
, PCI_ANY_ID
},
203 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2116_2
,
204 PCI_ANY_ID
, PCI_ANY_ID
},
205 /* Thunderbolt ~ 2208 */
206 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_1
,
207 PCI_ANY_ID
, PCI_ANY_ID
},
208 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_2
,
209 PCI_ANY_ID
, PCI_ANY_ID
},
210 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_3
,
211 PCI_ANY_ID
, PCI_ANY_ID
},
212 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_4
,
213 PCI_ANY_ID
, PCI_ANY_ID
},
214 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_5
,
215 PCI_ANY_ID
, PCI_ANY_ID
},
216 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_6
,
217 PCI_ANY_ID
, PCI_ANY_ID
},
218 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_7
,
219 PCI_ANY_ID
, PCI_ANY_ID
},
220 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_8
,
221 PCI_ANY_ID
, PCI_ANY_ID
},
222 {0} /* Terminating entry */
224 MODULE_DEVICE_TABLE(pci
, scsih_pci_table
);
227 * _scsih_set_debug_level - global setting of ioc->logging_level.
229 * Note: The logging levels are defined in mpt2sas_debug.h.
232 _scsih_set_debug_level(const char *val
, struct kernel_param
*kp
)
234 int ret
= param_set_int(val
, kp
);
235 struct MPT2SAS_ADAPTER
*ioc
;
240 printk(KERN_INFO
"setting logging_level(0x%08x)\n", logging_level
);
241 list_for_each_entry(ioc
, &mpt2sas_ioc_list
, list
)
242 ioc
->logging_level
= logging_level
;
245 module_param_call(logging_level
, _scsih_set_debug_level
, param_get_int
,
246 &logging_level
, 0644);
249 * _scsih_srch_boot_sas_address - search based on sas_address
250 * @sas_address: sas address
251 * @boot_device: boot device object from bios page 2
253 * Returns 1 when there's a match, 0 means no match.
256 _scsih_srch_boot_sas_address(u64 sas_address
,
257 Mpi2BootDeviceSasWwid_t
*boot_device
)
259 return (sas_address
== le64_to_cpu(boot_device
->SASAddress
)) ? 1 : 0;
263 * _scsih_srch_boot_device_name - search based on device name
264 * @device_name: device name specified in INDENTIFY fram
265 * @boot_device: boot device object from bios page 2
267 * Returns 1 when there's a match, 0 means no match.
270 _scsih_srch_boot_device_name(u64 device_name
,
271 Mpi2BootDeviceDeviceName_t
*boot_device
)
273 return (device_name
== le64_to_cpu(boot_device
->DeviceName
)) ? 1 : 0;
277 * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot
278 * @enclosure_logical_id: enclosure logical id
279 * @slot_number: slot number
280 * @boot_device: boot device object from bios page 2
282 * Returns 1 when there's a match, 0 means no match.
285 _scsih_srch_boot_encl_slot(u64 enclosure_logical_id
, u16 slot_number
,
286 Mpi2BootDeviceEnclosureSlot_t
*boot_device
)
288 return (enclosure_logical_id
== le64_to_cpu(boot_device
->
289 EnclosureLogicalID
) && slot_number
== le16_to_cpu(boot_device
->
290 SlotNumber
)) ? 1 : 0;
294 * _scsih_is_boot_device - search for matching boot device.
295 * @sas_address: sas address
296 * @device_name: device name specified in INDENTIFY fram
297 * @enclosure_logical_id: enclosure logical id
298 * @slot_number: slot number
299 * @form: specifies boot device form
300 * @boot_device: boot device object from bios page 2
302 * Returns 1 when there's a match, 0 means no match.
305 _scsih_is_boot_device(u64 sas_address
, u64 device_name
,
306 u64 enclosure_logical_id
, u16 slot
, u8 form
,
307 Mpi2BiosPage2BootDevice_t
*boot_device
)
312 case MPI2_BIOSPAGE2_FORM_SAS_WWID
:
315 rc
= _scsih_srch_boot_sas_address(
316 sas_address
, &boot_device
->SasWwid
);
318 case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT
:
319 if (!enclosure_logical_id
)
321 rc
= _scsih_srch_boot_encl_slot(
322 enclosure_logical_id
,
323 slot
, &boot_device
->EnclosureSlot
);
325 case MPI2_BIOSPAGE2_FORM_DEVICE_NAME
:
328 rc
= _scsih_srch_boot_device_name(
329 device_name
, &boot_device
->DeviceName
);
331 case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED
:
339 * _scsih_get_sas_address - set the sas_address for given device handle
340 * @handle: device handle
341 * @sas_address: sas address
343 * Returns 0 success, non-zero when failure
346 _scsih_get_sas_address(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
,
349 Mpi2SasDevicePage0_t sas_device_pg0
;
350 Mpi2ConfigReply_t mpi_reply
;
353 if (handle
<= ioc
->sas_hba
.num_phys
) {
354 *sas_address
= ioc
->sas_hba
.sas_address
;
359 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
360 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
361 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
362 ioc
->name
, __FILE__
, __LINE__
, __func__
);
366 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
368 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
369 printk(MPT2SAS_ERR_FMT
"handle(0x%04x), ioc_status(0x%04x)"
370 "\nfailure at %s:%d/%s()!\n", ioc
->name
, handle
, ioc_status
,
371 __FILE__
, __LINE__
, __func__
);
375 *sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
380 * _scsih_determine_boot_device - determine boot device.
381 * @ioc: per adapter object
382 * @device: either sas_device or raid_device object
383 * @is_raid: [flag] 1 = raid object, 0 = sas object
385 * Determines whether this device should be first reported device to
386 * to scsi-ml or sas transport, this purpose is for persistant boot device.
387 * There are primary, alternate, and current entries in bios page 2. The order
388 * priority is primary, alternate, then current. This routine saves
389 * the corresponding device object and is_raid flag in the ioc object.
390 * The saved data to be used later in _scsih_probe_boot_devices().
393 _scsih_determine_boot_device(struct MPT2SAS_ADAPTER
*ioc
,
394 void *device
, u8 is_raid
)
396 struct _sas_device
*sas_device
;
397 struct _raid_device
*raid_device
;
400 u64 enclosure_logical_id
;
403 /* only process this function when driver loads */
404 if (!ioc
->wait_for_port_enable_to_complete
)
409 sas_address
= sas_device
->sas_address
;
410 device_name
= sas_device
->device_name
;
411 enclosure_logical_id
= sas_device
->enclosure_logical_id
;
412 slot
= sas_device
->slot
;
414 raid_device
= device
;
415 sas_address
= raid_device
->wwid
;
417 enclosure_logical_id
= 0;
421 if (!ioc
->req_boot_device
.device
) {
422 if (_scsih_is_boot_device(sas_address
, device_name
,
423 enclosure_logical_id
, slot
,
424 (ioc
->bios_pg2
.ReqBootDeviceForm
&
425 MPI2_BIOSPAGE2_FORM_MASK
),
426 &ioc
->bios_pg2
.RequestedBootDevice
)) {
427 dinitprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
428 "%s: req_boot_device(0x%016llx)\n",
430 (unsigned long long)sas_address
));
431 ioc
->req_boot_device
.device
= device
;
432 ioc
->req_boot_device
.is_raid
= is_raid
;
436 if (!ioc
->req_alt_boot_device
.device
) {
437 if (_scsih_is_boot_device(sas_address
, device_name
,
438 enclosure_logical_id
, slot
,
439 (ioc
->bios_pg2
.ReqAltBootDeviceForm
&
440 MPI2_BIOSPAGE2_FORM_MASK
),
441 &ioc
->bios_pg2
.RequestedAltBootDevice
)) {
442 dinitprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
443 "%s: req_alt_boot_device(0x%016llx)\n",
445 (unsigned long long)sas_address
));
446 ioc
->req_alt_boot_device
.device
= device
;
447 ioc
->req_alt_boot_device
.is_raid
= is_raid
;
451 if (!ioc
->current_boot_device
.device
) {
452 if (_scsih_is_boot_device(sas_address
, device_name
,
453 enclosure_logical_id
, slot
,
454 (ioc
->bios_pg2
.CurrentBootDeviceForm
&
455 MPI2_BIOSPAGE2_FORM_MASK
),
456 &ioc
->bios_pg2
.CurrentBootDevice
)) {
457 dinitprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
458 "%s: current_boot_device(0x%016llx)\n",
460 (unsigned long long)sas_address
));
461 ioc
->current_boot_device
.device
= device
;
462 ioc
->current_boot_device
.is_raid
= is_raid
;
468 * mpt2sas_scsih_sas_device_find_by_sas_address - sas device search
469 * @ioc: per adapter object
470 * @sas_address: sas address
471 * Context: Calling function should acquire ioc->sas_device_lock
473 * This searches for sas_device based on sas_address, then return sas_device
477 mpt2sas_scsih_sas_device_find_by_sas_address(struct MPT2SAS_ADAPTER
*ioc
,
480 struct _sas_device
*sas_device
, *r
;
483 /* check the sas_device_init_list */
484 list_for_each_entry(sas_device
, &ioc
->sas_device_init_list
,
486 if (sas_device
->sas_address
!= sas_address
)
492 /* then check the sas_device_list */
493 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
) {
494 if (sas_device
->sas_address
!= sas_address
)
504 * _scsih_sas_device_find_by_handle - sas device search
505 * @ioc: per adapter object
506 * @handle: sas device handle (assigned by firmware)
507 * Context: Calling function should acquire ioc->sas_device_lock
509 * This searches for sas_device based on sas_address, then return sas_device
512 static struct _sas_device
*
513 _scsih_sas_device_find_by_handle(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
515 struct _sas_device
*sas_device
, *r
;
518 if (ioc
->wait_for_port_enable_to_complete
) {
519 list_for_each_entry(sas_device
, &ioc
->sas_device_init_list
,
521 if (sas_device
->handle
!= handle
)
527 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
) {
528 if (sas_device
->handle
!= handle
)
540 * _scsih_sas_device_remove - remove sas_device from list.
541 * @ioc: per adapter object
542 * @sas_device: the sas_device object
543 * Context: This function will acquire ioc->sas_device_lock.
545 * Removing object and freeing associated memory from the ioc->sas_device_list.
548 _scsih_sas_device_remove(struct MPT2SAS_ADAPTER
*ioc
,
549 struct _sas_device
*sas_device
)
553 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
554 list_del(&sas_device
->list
);
555 memset(sas_device
, 0, sizeof(struct _sas_device
));
557 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
561 * _scsih_sas_device_add - insert sas_device to the list.
562 * @ioc: per adapter object
563 * @sas_device: the sas_device object
564 * Context: This function will acquire ioc->sas_device_lock.
566 * Adding new object to the ioc->sas_device_list.
569 _scsih_sas_device_add(struct MPT2SAS_ADAPTER
*ioc
,
570 struct _sas_device
*sas_device
)
574 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: handle"
575 "(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
, __func__
,
576 sas_device
->handle
, (unsigned long long)sas_device
->sas_address
));
578 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
579 list_add_tail(&sas_device
->list
, &ioc
->sas_device_list
);
580 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
582 if (!mpt2sas_transport_port_add(ioc
, sas_device
->handle
,
583 sas_device
->sas_address_parent
))
584 _scsih_sas_device_remove(ioc
, sas_device
);
588 * _scsih_sas_device_init_add - insert sas_device to the list.
589 * @ioc: per adapter object
590 * @sas_device: the sas_device object
591 * Context: This function will acquire ioc->sas_device_lock.
593 * Adding new object at driver load time to the ioc->sas_device_init_list.
596 _scsih_sas_device_init_add(struct MPT2SAS_ADAPTER
*ioc
,
597 struct _sas_device
*sas_device
)
601 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: handle"
602 "(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
, __func__
,
603 sas_device
->handle
, (unsigned long long)sas_device
->sas_address
));
605 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
606 list_add_tail(&sas_device
->list
, &ioc
->sas_device_init_list
);
607 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
608 _scsih_determine_boot_device(ioc
, sas_device
, 0);
612 * _scsih_raid_device_find_by_id - raid device search
613 * @ioc: per adapter object
614 * @id: sas device target id
615 * @channel: sas device channel
616 * Context: Calling function should acquire ioc->raid_device_lock
618 * This searches for raid_device based on target id, then return raid_device
621 static struct _raid_device
*
622 _scsih_raid_device_find_by_id(struct MPT2SAS_ADAPTER
*ioc
, int id
, int channel
)
624 struct _raid_device
*raid_device
, *r
;
627 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
628 if (raid_device
->id
== id
&& raid_device
->channel
== channel
) {
639 * _scsih_raid_device_find_by_handle - raid device search
640 * @ioc: per adapter object
641 * @handle: sas device handle (assigned by firmware)
642 * Context: Calling function should acquire ioc->raid_device_lock
644 * This searches for raid_device based on handle, then return raid_device
647 static struct _raid_device
*
648 _scsih_raid_device_find_by_handle(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
650 struct _raid_device
*raid_device
, *r
;
653 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
654 if (raid_device
->handle
!= handle
)
665 * _scsih_raid_device_find_by_wwid - raid device search
666 * @ioc: per adapter object
667 * @handle: sas device handle (assigned by firmware)
668 * Context: Calling function should acquire ioc->raid_device_lock
670 * This searches for raid_device based on wwid, then return raid_device
673 static struct _raid_device
*
674 _scsih_raid_device_find_by_wwid(struct MPT2SAS_ADAPTER
*ioc
, u64 wwid
)
676 struct _raid_device
*raid_device
, *r
;
679 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
680 if (raid_device
->wwid
!= wwid
)
691 * _scsih_raid_device_add - add raid_device object
692 * @ioc: per adapter object
693 * @raid_device: raid_device object
695 * This is added to the raid_device_list link list.
698 _scsih_raid_device_add(struct MPT2SAS_ADAPTER
*ioc
,
699 struct _raid_device
*raid_device
)
703 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: handle"
704 "(0x%04x), wwid(0x%016llx)\n", ioc
->name
, __func__
,
705 raid_device
->handle
, (unsigned long long)raid_device
->wwid
));
707 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
708 list_add_tail(&raid_device
->list
, &ioc
->raid_device_list
);
709 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
713 * _scsih_raid_device_remove - delete raid_device object
714 * @ioc: per adapter object
715 * @raid_device: raid_device object
717 * This is removed from the raid_device_list link list.
720 _scsih_raid_device_remove(struct MPT2SAS_ADAPTER
*ioc
,
721 struct _raid_device
*raid_device
)
725 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
726 list_del(&raid_device
->list
);
727 memset(raid_device
, 0, sizeof(struct _raid_device
));
729 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
733 * mpt2sas_scsih_expander_find_by_handle - expander device search
734 * @ioc: per adapter object
735 * @handle: expander handle (assigned by firmware)
736 * Context: Calling function should acquire ioc->sas_device_lock
738 * This searches for expander device based on handle, then returns the
742 mpt2sas_scsih_expander_find_by_handle(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
744 struct _sas_node
*sas_expander
, *r
;
747 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
748 if (sas_expander
->handle
!= handle
)
758 * mpt2sas_scsih_expander_find_by_sas_address - expander device search
759 * @ioc: per adapter object
760 * @sas_address: sas address
761 * Context: Calling function should acquire ioc->sas_node_lock.
763 * This searches for expander device based on sas_address, then returns the
767 mpt2sas_scsih_expander_find_by_sas_address(struct MPT2SAS_ADAPTER
*ioc
,
770 struct _sas_node
*sas_expander
, *r
;
773 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
774 if (sas_expander
->sas_address
!= sas_address
)
784 * _scsih_expander_node_add - insert expander device to the list.
785 * @ioc: per adapter object
786 * @sas_expander: the sas_device object
787 * Context: This function will acquire ioc->sas_node_lock.
789 * Adding new object to the ioc->sas_expander_list.
794 _scsih_expander_node_add(struct MPT2SAS_ADAPTER
*ioc
,
795 struct _sas_node
*sas_expander
)
799 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
800 list_add_tail(&sas_expander
->list
, &ioc
->sas_expander_list
);
801 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
805 * _scsih_is_end_device - determines if device is an end device
806 * @device_info: bitfield providing information about the device.
809 * Returns 1 if end device.
812 _scsih_is_end_device(u32 device_info
)
814 if (device_info
& MPI2_SAS_DEVICE_INFO_END_DEVICE
&&
815 ((device_info
& MPI2_SAS_DEVICE_INFO_SSP_TARGET
) |
816 (device_info
& MPI2_SAS_DEVICE_INFO_STP_TARGET
) |
817 (device_info
& MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)))
824 * mptscsih_get_scsi_lookup - returns scmd entry
825 * @ioc: per adapter object
826 * @smid: system request message index
828 * Returns the smid stored scmd pointer.
830 static struct scsi_cmnd
*
831 _scsih_scsi_lookup_get(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
833 return ioc
->scsi_lookup
[smid
- 1].scmd
;
837 * _scsih_scsi_lookup_find_by_scmd - scmd lookup
838 * @ioc: per adapter object
839 * @smid: system request message index
840 * @scmd: pointer to scsi command object
841 * Context: This function will acquire ioc->scsi_lookup_lock.
843 * This will search for a scmd pointer in the scsi_lookup array,
844 * returning the revelent smid. A returned value of zero means invalid.
847 _scsih_scsi_lookup_find_by_scmd(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_cmnd
854 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
856 for (i
= 0; i
< ioc
->scsiio_depth
; i
++) {
857 if (ioc
->scsi_lookup
[i
].scmd
== scmd
) {
858 smid
= ioc
->scsi_lookup
[i
].smid
;
863 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
868 * _scsih_scsi_lookup_find_by_target - search for matching channel:id
869 * @ioc: per adapter object
872 * Context: This function will acquire ioc->scsi_lookup_lock.
874 * This will search for a matching channel:id in the scsi_lookup array,
875 * returning 1 if found.
878 _scsih_scsi_lookup_find_by_target(struct MPT2SAS_ADAPTER
*ioc
, int id
,
885 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
887 for (i
= 0 ; i
< ioc
->scsiio_depth
; i
++) {
888 if (ioc
->scsi_lookup
[i
].scmd
&&
889 (ioc
->scsi_lookup
[i
].scmd
->device
->id
== id
&&
890 ioc
->scsi_lookup
[i
].scmd
->device
->channel
== channel
)) {
896 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
901 * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun
902 * @ioc: per adapter object
906 * Context: This function will acquire ioc->scsi_lookup_lock.
908 * This will search for a matching channel:id:lun in the scsi_lookup array,
909 * returning 1 if found.
912 _scsih_scsi_lookup_find_by_lun(struct MPT2SAS_ADAPTER
*ioc
, int id
,
913 unsigned int lun
, int channel
)
919 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
921 for (i
= 0 ; i
< ioc
->scsiio_depth
; i
++) {
922 if (ioc
->scsi_lookup
[i
].scmd
&&
923 (ioc
->scsi_lookup
[i
].scmd
->device
->id
== id
&&
924 ioc
->scsi_lookup
[i
].scmd
->device
->channel
== channel
&&
925 ioc
->scsi_lookup
[i
].scmd
->device
->lun
== lun
)) {
931 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
936 * _scsih_get_chain_buffer_dma - obtain block of chains (dma address)
937 * @ioc: per adapter object
938 * @smid: system request message index
940 * Returns phys pointer to chain buffer.
943 _scsih_get_chain_buffer_dma(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
945 return ioc
->chain_dma
+ ((smid
- 1) * (ioc
->request_sz
*
946 ioc
->chains_needed_per_io
));
950 * _scsih_get_chain_buffer - obtain block of chains assigned to a mf request
951 * @ioc: per adapter object
952 * @smid: system request message index
954 * Returns virt pointer to chain buffer.
957 _scsih_get_chain_buffer(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
959 return (void *)(ioc
->chain
+ ((smid
- 1) * (ioc
->request_sz
*
960 ioc
->chains_needed_per_io
)));
964 * _scsih_build_scatter_gather - main sg creation routine
965 * @ioc: per adapter object
966 * @scmd: scsi command
967 * @smid: system request message index
970 * The main routine that builds scatter gather table from a given
971 * scsi request sent via the .queuecommand main handler.
973 * Returns 0 success, anything else error
976 _scsih_build_scatter_gather(struct MPT2SAS_ADAPTER
*ioc
,
977 struct scsi_cmnd
*scmd
, u16 smid
)
979 Mpi2SCSIIORequest_t
*mpi_request
;
980 dma_addr_t chain_dma
;
981 struct scatterlist
*sg_scmd
;
982 void *sg_local
, *chain
;
989 u32 sgl_flags_last_element
;
990 u32 sgl_flags_end_buffer
;
992 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
994 /* init scatter gather flags */
995 sgl_flags
= MPI2_SGE_FLAGS_SIMPLE_ELEMENT
;
996 if (scmd
->sc_data_direction
== DMA_TO_DEVICE
)
997 sgl_flags
|= MPI2_SGE_FLAGS_HOST_TO_IOC
;
998 sgl_flags_last_element
= (sgl_flags
| MPI2_SGE_FLAGS_LAST_ELEMENT
)
999 << MPI2_SGE_FLAGS_SHIFT
;
1000 sgl_flags_end_buffer
= (sgl_flags
| MPI2_SGE_FLAGS_LAST_ELEMENT
|
1001 MPI2_SGE_FLAGS_END_OF_BUFFER
| MPI2_SGE_FLAGS_END_OF_LIST
)
1002 << MPI2_SGE_FLAGS_SHIFT
;
1003 sgl_flags
= sgl_flags
<< MPI2_SGE_FLAGS_SHIFT
;
1005 sg_scmd
= scsi_sglist(scmd
);
1006 sges_left
= scsi_dma_map(scmd
);
1008 sdev_printk(KERN_ERR
, scmd
->device
, "pci_map_sg"
1009 " failed: request for %d bytes!\n", scsi_bufflen(scmd
));
1013 sg_local
= &mpi_request
->SGL
;
1014 sges_in_segment
= ioc
->max_sges_in_main_message
;
1015 if (sges_left
<= sges_in_segment
)
1016 goto fill_in_last_segment
;
1018 mpi_request
->ChainOffset
= (offsetof(Mpi2SCSIIORequest_t
, SGL
) +
1019 (sges_in_segment
* ioc
->sge_size
))/4;
1021 /* fill in main message segment when there is a chain following */
1022 while (sges_in_segment
) {
1023 if (sges_in_segment
== 1)
1024 ioc
->base_add_sg_single(sg_local
,
1025 sgl_flags_last_element
| sg_dma_len(sg_scmd
),
1026 sg_dma_address(sg_scmd
));
1028 ioc
->base_add_sg_single(sg_local
, sgl_flags
|
1029 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
1030 sg_scmd
= sg_next(sg_scmd
);
1031 sg_local
+= ioc
->sge_size
;
1036 /* initializing the chain flags and pointers */
1037 chain_flags
= MPI2_SGE_FLAGS_CHAIN_ELEMENT
<< MPI2_SGE_FLAGS_SHIFT
;
1038 chain
= _scsih_get_chain_buffer(ioc
, smid
);
1039 chain_dma
= _scsih_get_chain_buffer_dma(ioc
, smid
);
1041 sges_in_segment
= (sges_left
<=
1042 ioc
->max_sges_in_chain_message
) ? sges_left
:
1043 ioc
->max_sges_in_chain_message
;
1044 chain_offset
= (sges_left
== sges_in_segment
) ?
1045 0 : (sges_in_segment
* ioc
->sge_size
)/4;
1046 chain_length
= sges_in_segment
* ioc
->sge_size
;
1048 chain_offset
= chain_offset
<<
1049 MPI2_SGE_CHAIN_OFFSET_SHIFT
;
1050 chain_length
+= ioc
->sge_size
;
1052 ioc
->base_add_sg_single(sg_local
, chain_flags
| chain_offset
|
1053 chain_length
, chain_dma
);
1056 goto fill_in_last_segment
;
1058 /* fill in chain segments */
1059 while (sges_in_segment
) {
1060 if (sges_in_segment
== 1)
1061 ioc
->base_add_sg_single(sg_local
,
1062 sgl_flags_last_element
|
1063 sg_dma_len(sg_scmd
),
1064 sg_dma_address(sg_scmd
));
1066 ioc
->base_add_sg_single(sg_local
, sgl_flags
|
1067 sg_dma_len(sg_scmd
),
1068 sg_dma_address(sg_scmd
));
1069 sg_scmd
= sg_next(sg_scmd
);
1070 sg_local
+= ioc
->sge_size
;
1075 chain_dma
+= ioc
->request_sz
;
1076 chain
+= ioc
->request_sz
;
1080 fill_in_last_segment
:
1082 /* fill the last segment */
1085 ioc
->base_add_sg_single(sg_local
, sgl_flags_end_buffer
|
1086 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
1088 ioc
->base_add_sg_single(sg_local
, sgl_flags
|
1089 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
1090 sg_scmd
= sg_next(sg_scmd
);
1091 sg_local
+= ioc
->sge_size
;
1099 * _scsih_change_queue_depth - setting device queue depth
1100 * @sdev: scsi device struct
1101 * @qdepth: requested queue depth
1102 * @reason: calling context
1104 * Returns queue depth.
1107 _scsih_change_queue_depth(struct scsi_device
*sdev
, int qdepth
, int reason
)
1109 struct Scsi_Host
*shost
= sdev
->host
;
1112 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1113 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1114 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1115 struct _sas_device
*sas_device
;
1116 unsigned long flags
;
1118 if (reason
!= SCSI_QDEPTH_DEFAULT
)
1121 max_depth
= shost
->can_queue
;
1123 /* limit max device queue for SATA to 32 */
1124 sas_device_priv_data
= sdev
->hostdata
;
1125 if (!sas_device_priv_data
)
1127 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
1128 if (!sas_target_priv_data
)
1130 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
))
1132 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1133 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1134 sas_device_priv_data
->sas_target
->sas_address
);
1135 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1136 if (sas_device
&& sas_device
->device_info
&
1137 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1138 max_depth
= MPT2SAS_SATA_QUEUE_DEPTH
;
1142 if (!sdev
->tagged_supported
)
1144 if (qdepth
> max_depth
)
1146 tag_type
= (qdepth
== 1) ? 0 : MSG_SIMPLE_TAG
;
1147 scsi_adjust_queue_depth(sdev
, tag_type
, qdepth
);
1149 if (sdev
->inquiry_len
> 7)
1150 sdev_printk(KERN_INFO
, sdev
, "qdepth(%d), tagged(%d), "
1151 "simple(%d), ordered(%d), scsi_level(%d), cmd_que(%d)\n",
1152 sdev
->queue_depth
, sdev
->tagged_supported
, sdev
->simple_tags
,
1153 sdev
->ordered_tags
, sdev
->scsi_level
,
1154 (sdev
->inquiry
[7] & 2) >> 1);
1156 return sdev
->queue_depth
;
1160 * _scsih_change_queue_type - changing device queue tag type
1161 * @sdev: scsi device struct
1162 * @tag_type: requested tag type
1164 * Returns queue tag type.
1167 _scsih_change_queue_type(struct scsi_device
*sdev
, int tag_type
)
1169 if (sdev
->tagged_supported
) {
1170 scsi_set_tag_type(sdev
, tag_type
);
1172 scsi_activate_tcq(sdev
, sdev
->queue_depth
);
1174 scsi_deactivate_tcq(sdev
, sdev
->queue_depth
);
1182 * _scsih_target_alloc - target add routine
1183 * @starget: scsi target struct
1185 * Returns 0 if ok. Any other return is assumed to be an error and
1186 * the device is ignored.
1189 _scsih_target_alloc(struct scsi_target
*starget
)
1191 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
1192 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1193 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1194 struct _sas_device
*sas_device
;
1195 struct _raid_device
*raid_device
;
1196 unsigned long flags
;
1197 struct sas_rphy
*rphy
;
1199 sas_target_priv_data
= kzalloc(sizeof(struct scsi_target
), GFP_KERNEL
);
1200 if (!sas_target_priv_data
)
1203 starget
->hostdata
= sas_target_priv_data
;
1204 sas_target_priv_data
->starget
= starget
;
1205 sas_target_priv_data
->handle
= MPT2SAS_INVALID_DEVICE_HANDLE
;
1208 if (starget
->channel
== RAID_CHANNEL
) {
1209 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1210 raid_device
= _scsih_raid_device_find_by_id(ioc
, starget
->id
,
1213 sas_target_priv_data
->handle
= raid_device
->handle
;
1214 sas_target_priv_data
->sas_address
= raid_device
->wwid
;
1215 sas_target_priv_data
->flags
|= MPT_TARGET_FLAGS_VOLUME
;
1216 raid_device
->starget
= starget
;
1218 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1222 /* sas/sata devices */
1223 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1224 rphy
= dev_to_rphy(starget
->dev
.parent
);
1225 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1226 rphy
->identify
.sas_address
);
1229 sas_target_priv_data
->handle
= sas_device
->handle
;
1230 sas_target_priv_data
->sas_address
= sas_device
->sas_address
;
1231 sas_device
->starget
= starget
;
1232 sas_device
->id
= starget
->id
;
1233 sas_device
->channel
= starget
->channel
;
1234 if (sas_device
->hidden_raid_component
)
1235 sas_target_priv_data
->flags
|=
1236 MPT_TARGET_FLAGS_RAID_COMPONENT
;
1238 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1244 * _scsih_target_destroy - target destroy routine
1245 * @starget: scsi target struct
1250 _scsih_target_destroy(struct scsi_target
*starget
)
1252 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
1253 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1254 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1255 struct _sas_device
*sas_device
;
1256 struct _raid_device
*raid_device
;
1257 unsigned long flags
;
1258 struct sas_rphy
*rphy
;
1260 sas_target_priv_data
= starget
->hostdata
;
1261 if (!sas_target_priv_data
)
1264 if (starget
->channel
== RAID_CHANNEL
) {
1265 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1266 raid_device
= _scsih_raid_device_find_by_id(ioc
, starget
->id
,
1269 raid_device
->starget
= NULL
;
1270 raid_device
->sdev
= NULL
;
1272 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1276 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1277 rphy
= dev_to_rphy(starget
->dev
.parent
);
1278 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1279 rphy
->identify
.sas_address
);
1280 if (sas_device
&& (sas_device
->starget
== starget
) &&
1281 (sas_device
->id
== starget
->id
) &&
1282 (sas_device
->channel
== starget
->channel
))
1283 sas_device
->starget
= NULL
;
1285 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1288 kfree(sas_target_priv_data
);
1289 starget
->hostdata
= NULL
;
1293 * _scsih_slave_alloc - device add routine
1294 * @sdev: scsi device struct
1296 * Returns 0 if ok. Any other return is assumed to be an error and
1297 * the device is ignored.
1300 _scsih_slave_alloc(struct scsi_device
*sdev
)
1302 struct Scsi_Host
*shost
;
1303 struct MPT2SAS_ADAPTER
*ioc
;
1304 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1305 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1306 struct scsi_target
*starget
;
1307 struct _raid_device
*raid_device
;
1308 struct _sas_device
*sas_device
;
1309 unsigned long flags
;
1311 sas_device_priv_data
= kzalloc(sizeof(struct scsi_device
), GFP_KERNEL
);
1312 if (!sas_device_priv_data
)
1315 sas_device_priv_data
->lun
= sdev
->lun
;
1316 sas_device_priv_data
->flags
= MPT_DEVICE_FLAGS_INIT
;
1318 starget
= scsi_target(sdev
);
1319 sas_target_priv_data
= starget
->hostdata
;
1320 sas_target_priv_data
->num_luns
++;
1321 sas_device_priv_data
->sas_target
= sas_target_priv_data
;
1322 sdev
->hostdata
= sas_device_priv_data
;
1323 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
))
1324 sdev
->no_uld_attach
= 1;
1326 shost
= dev_to_shost(&starget
->dev
);
1327 ioc
= shost_priv(shost
);
1328 if (starget
->channel
== RAID_CHANNEL
) {
1329 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1330 raid_device
= _scsih_raid_device_find_by_id(ioc
,
1331 starget
->id
, starget
->channel
);
1333 raid_device
->sdev
= sdev
; /* raid is single lun */
1334 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1336 /* set TLR bit for SSP devices */
1337 if (!(ioc
->facts
.IOCCapabilities
&
1338 MPI2_IOCFACTS_CAPABILITY_TLR
))
1340 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1341 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1342 sas_device_priv_data
->sas_target
->sas_address
);
1343 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1344 if (sas_device
&& sas_device
->device_info
&
1345 MPI2_SAS_DEVICE_INFO_SSP_TARGET
)
1346 sas_device_priv_data
->flags
|= MPT_DEVICE_TLR_ON
;
1354 * _scsih_slave_destroy - device destroy routine
1355 * @sdev: scsi device struct
1360 _scsih_slave_destroy(struct scsi_device
*sdev
)
1362 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1363 struct scsi_target
*starget
;
1365 if (!sdev
->hostdata
)
1368 starget
= scsi_target(sdev
);
1369 sas_target_priv_data
= starget
->hostdata
;
1370 sas_target_priv_data
->num_luns
--;
1371 kfree(sdev
->hostdata
);
1372 sdev
->hostdata
= NULL
;
1376 * _scsih_display_sata_capabilities - sata capabilities
1377 * @ioc: per adapter object
1378 * @sas_device: the sas_device object
1379 * @sdev: scsi device struct
1382 _scsih_display_sata_capabilities(struct MPT2SAS_ADAPTER
*ioc
,
1383 struct _sas_device
*sas_device
, struct scsi_device
*sdev
)
1385 Mpi2ConfigReply_t mpi_reply
;
1386 Mpi2SasDevicePage0_t sas_device_pg0
;
1391 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
1392 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, sas_device
->handle
))) {
1393 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1394 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1398 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
1399 MPI2_IOCSTATUS_MASK
;
1400 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
1401 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1402 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1406 flags
= le16_to_cpu(sas_device_pg0
.Flags
);
1407 device_info
= le16_to_cpu(sas_device_pg0
.DeviceInfo
);
1409 sdev_printk(KERN_INFO
, sdev
,
1410 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1411 "sw_preserve(%s)\n",
1412 (device_info
& MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE
) ? "y" : "n",
1413 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED
) ? "y" : "n",
1414 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY
) ? "y" :
1416 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED
) ? "y" : "n",
1417 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED
) ? "y" : "n",
1418 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE
) ? "y" : "n");
1422 * _scsih_get_volume_capabilities - volume capabilities
1423 * @ioc: per adapter object
1424 * @sas_device: the raid_device object
1427 _scsih_get_volume_capabilities(struct MPT2SAS_ADAPTER
*ioc
,
1428 struct _raid_device
*raid_device
)
1430 Mpi2RaidVolPage0_t
*vol_pg0
;
1431 Mpi2RaidPhysDiskPage0_t pd_pg0
;
1432 Mpi2SasDevicePage0_t sas_device_pg0
;
1433 Mpi2ConfigReply_t mpi_reply
;
1437 if ((mpt2sas_config_get_number_pds(ioc
, raid_device
->handle
,
1438 &num_pds
)) || !num_pds
) {
1439 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1440 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1444 raid_device
->num_pds
= num_pds
;
1445 sz
= offsetof(Mpi2RaidVolPage0_t
, PhysDisk
) + (num_pds
*
1446 sizeof(Mpi2RaidVol0PhysDisk_t
));
1447 vol_pg0
= kzalloc(sz
, GFP_KERNEL
);
1449 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1450 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1454 if ((mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, vol_pg0
,
1455 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, raid_device
->handle
, sz
))) {
1456 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1457 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1462 raid_device
->volume_type
= vol_pg0
->VolumeType
;
1464 /* figure out what the underlying devices are by
1465 * obtaining the device_info bits for the 1st device
1467 if (!(mpt2sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
1468 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM
,
1469 vol_pg0
->PhysDisk
[0].PhysDiskNum
))) {
1470 if (!(mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
1471 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
1472 le16_to_cpu(pd_pg0
.DevHandle
)))) {
1473 raid_device
->device_info
=
1474 le32_to_cpu(sas_device_pg0
.DeviceInfo
);
1482 * _scsih_slave_configure - device configure routine.
1483 * @sdev: scsi device struct
1485 * Returns 0 if ok. Any other return is assumed to be an error and
1486 * the device is ignored.
1489 _scsih_slave_configure(struct scsi_device
*sdev
)
1491 struct Scsi_Host
*shost
= sdev
->host
;
1492 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1493 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1494 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1495 struct _sas_device
*sas_device
;
1496 struct _raid_device
*raid_device
;
1497 unsigned long flags
;
1504 sas_device_priv_data
= sdev
->hostdata
;
1505 sas_device_priv_data
->configured_lun
= 1;
1506 sas_device_priv_data
->flags
&= ~MPT_DEVICE_FLAGS_INIT
;
1507 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
1509 /* raid volume handling */
1510 if (sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
1512 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1513 raid_device
= _scsih_raid_device_find_by_handle(ioc
,
1514 sas_target_priv_data
->handle
);
1515 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1517 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1518 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1522 _scsih_get_volume_capabilities(ioc
, raid_device
);
1524 /* RAID Queue Depth Support
1525 * IS volume = underlying qdepth of drive type, either
1526 * MPT2SAS_SAS_QUEUE_DEPTH or MPT2SAS_SATA_QUEUE_DEPTH
1527 * IM/IME/R10 = 128 (MPT2SAS_RAID_QUEUE_DEPTH)
1529 if (raid_device
->device_info
&
1530 MPI2_SAS_DEVICE_INFO_SSP_TARGET
) {
1531 qdepth
= MPT2SAS_SAS_QUEUE_DEPTH
;
1534 qdepth
= MPT2SAS_SATA_QUEUE_DEPTH
;
1535 if (raid_device
->device_info
&
1536 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1542 switch (raid_device
->volume_type
) {
1543 case MPI2_RAID_VOL_TYPE_RAID0
:
1546 case MPI2_RAID_VOL_TYPE_RAID1E
:
1547 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
1548 if (ioc
->manu_pg10
.OEMIdentifier
&&
1549 (ioc
->manu_pg10
.GenericFlags0
&
1550 MFG10_GF0_R10_DISPLAY
) &&
1551 !(raid_device
->num_pds
% 2))
1556 case MPI2_RAID_VOL_TYPE_RAID1
:
1557 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
1560 case MPI2_RAID_VOL_TYPE_RAID10
:
1561 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
1564 case MPI2_RAID_VOL_TYPE_UNKNOWN
:
1566 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
1571 sdev_printk(KERN_INFO
, sdev
, "%s: "
1572 "handle(0x%04x), wwid(0x%016llx), pd_count(%d), type(%s)\n",
1573 r_level
, raid_device
->handle
,
1574 (unsigned long long)raid_device
->wwid
,
1575 raid_device
->num_pds
, ds
);
1576 _scsih_change_queue_depth(sdev
, qdepth
, SCSI_QDEPTH_DEFAULT
);
1580 /* non-raid handling */
1581 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1582 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1583 sas_device_priv_data
->sas_target
->sas_address
);
1584 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1586 if (sas_target_priv_data
->flags
&
1587 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
1588 mpt2sas_config_get_volume_handle(ioc
,
1589 sas_device
->handle
, &sas_device
->volume_handle
);
1590 mpt2sas_config_get_volume_wwid(ioc
,
1591 sas_device
->volume_handle
,
1592 &sas_device
->volume_wwid
);
1594 if (sas_device
->device_info
& MPI2_SAS_DEVICE_INFO_SSP_TARGET
) {
1595 qdepth
= MPT2SAS_SAS_QUEUE_DEPTH
;
1599 qdepth
= MPT2SAS_SATA_QUEUE_DEPTH
;
1600 if (sas_device
->device_info
&
1601 MPI2_SAS_DEVICE_INFO_STP_TARGET
)
1603 else if (sas_device
->device_info
&
1604 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1608 sdev_printk(KERN_INFO
, sdev
, "%s: handle(0x%04x), "
1609 "sas_addr(0x%016llx), device_name(0x%016llx)\n",
1610 ds
, sas_device
->handle
,
1611 (unsigned long long)sas_device
->sas_address
,
1612 (unsigned long long)sas_device
->device_name
);
1613 sdev_printk(KERN_INFO
, sdev
, "%s: "
1614 "enclosure_logical_id(0x%016llx), slot(%d)\n", ds
,
1615 (unsigned long long) sas_device
->enclosure_logical_id
,
1619 _scsih_display_sata_capabilities(ioc
, sas_device
, sdev
);
1622 _scsih_change_queue_depth(sdev
, qdepth
, SCSI_QDEPTH_DEFAULT
);
1625 sas_read_port_mode_page(sdev
);
1630 * _scsih_bios_param - fetch head, sector, cylinder info for a disk
1631 * @sdev: scsi device struct
1632 * @bdev: pointer to block device context
1633 * @capacity: device size (in 512 byte sectors)
1634 * @params: three element array to place output:
1635 * params[0] number of heads (max 255)
1636 * params[1] number of sectors (max 63)
1637 * params[2] number of cylinders
1642 _scsih_bios_param(struct scsi_device
*sdev
, struct block_device
*bdev
,
1643 sector_t capacity
, int params
[])
1653 dummy
= heads
* sectors
;
1654 cylinders
= capacity
;
1655 sector_div(cylinders
, dummy
);
1658 * Handle extended translation size for logical drives
1661 if ((ulong
)capacity
>= 0x200000) {
1664 dummy
= heads
* sectors
;
1665 cylinders
= capacity
;
1666 sector_div(cylinders
, dummy
);
1671 params
[1] = sectors
;
1672 params
[2] = cylinders
;
1678 * _scsih_response_code - translation of device response code
1679 * @ioc: per adapter object
1680 * @response_code: response code returned by the device
1685 _scsih_response_code(struct MPT2SAS_ADAPTER
*ioc
, u8 response_code
)
1689 switch (response_code
) {
1690 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE
:
1691 desc
= "task management request completed";
1693 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
:
1694 desc
= "invalid frame";
1696 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED
:
1697 desc
= "task management request not supported";
1699 case MPI2_SCSITASKMGMT_RSP_TM_FAILED
:
1700 desc
= "task management request failed";
1702 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
:
1703 desc
= "task management request succeeded";
1705 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN
:
1706 desc
= "invalid lun";
1709 desc
= "overlapped tag attempted";
1711 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
:
1712 desc
= "task queued, however not sent to target";
1718 printk(MPT2SAS_WARN_FMT
"response_code(0x%01x): %s\n",
1719 ioc
->name
, response_code
, desc
);
1723 * _scsih_tm_done - tm completion routine
1724 * @ioc: per adapter object
1725 * @smid: system request message index
1726 * @msix_index: MSIX table index supplied by the OS
1727 * @reply: reply message frame(lower 32bit addr)
1730 * The callback handler when using scsih_issue_tm.
1732 * Return 1 meaning mf should be freed from _base_interrupt
1733 * 0 means the mf is freed from this function.
1736 _scsih_tm_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
1738 MPI2DefaultReply_t
*mpi_reply
;
1740 if (ioc
->tm_cmds
.status
== MPT2_CMD_NOT_USED
)
1742 if (ioc
->tm_cmds
.smid
!= smid
)
1744 ioc
->tm_cmds
.status
|= MPT2_CMD_COMPLETE
;
1745 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
1747 memcpy(ioc
->tm_cmds
.reply
, mpi_reply
, mpi_reply
->MsgLength
*4);
1748 ioc
->tm_cmds
.status
|= MPT2_CMD_REPLY_VALID
;
1750 ioc
->tm_cmds
.status
&= ~MPT2_CMD_PENDING
;
1751 complete(&ioc
->tm_cmds
.done
);
1756 * mpt2sas_scsih_set_tm_flag - set per target tm_busy
1757 * @ioc: per adapter object
1758 * @handle: device handle
1760 * During taskmangement request, we need to freeze the device queue.
1763 mpt2sas_scsih_set_tm_flag(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
1765 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1766 struct scsi_device
*sdev
;
1769 shost_for_each_device(sdev
, ioc
->shost
) {
1772 sas_device_priv_data
= sdev
->hostdata
;
1773 if (!sas_device_priv_data
)
1775 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
1776 sas_device_priv_data
->sas_target
->tm_busy
= 1;
1778 ioc
->ignore_loginfos
= 1;
1784 * mpt2sas_scsih_clear_tm_flag - clear per target tm_busy
1785 * @ioc: per adapter object
1786 * @handle: device handle
1788 * During taskmangement request, we need to freeze the device queue.
1791 mpt2sas_scsih_clear_tm_flag(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
1793 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1794 struct scsi_device
*sdev
;
1797 shost_for_each_device(sdev
, ioc
->shost
) {
1800 sas_device_priv_data
= sdev
->hostdata
;
1801 if (!sas_device_priv_data
)
1803 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
1804 sas_device_priv_data
->sas_target
->tm_busy
= 0;
1806 ioc
->ignore_loginfos
= 0;
1812 * mpt2sas_scsih_issue_tm - main routine for sending tm requests
1813 * @ioc: per adapter struct
1814 * @device_handle: device handle
1816 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
1817 * @smid_task: smid assigned to the task
1818 * @timeout: timeout in seconds
1819 * Context: The calling function needs to acquire the tm_cmds.mutex
1821 * A generic API for sending task management requests to firmware.
1823 * The ioc->tm_cmds.status flag should be MPT2_CMD_NOT_USED before calling
1826 * The callback index is set inside `ioc->tm_cb_idx`.
1831 mpt2sas_scsih_issue_tm(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
, uint lun
,
1832 u8 type
, u16 smid_task
, ulong timeout
)
1834 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
1835 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
1838 unsigned long timeleft
;
1840 if (ioc
->tm_cmds
.status
!= MPT2_CMD_NOT_USED
) {
1841 printk(MPT2SAS_INFO_FMT
"%s: tm_cmd busy!!!\n",
1842 __func__
, ioc
->name
);
1846 if (ioc
->shost_recovery
) {
1847 printk(MPT2SAS_INFO_FMT
"%s: host reset in progress!\n",
1848 __func__
, ioc
->name
);
1852 ioc_state
= mpt2sas_base_get_iocstate(ioc
, 0);
1853 if (ioc_state
& MPI2_DOORBELL_USED
) {
1854 dhsprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"unexpected doorbell "
1855 "active!\n", ioc
->name
));
1856 goto issue_host_reset
;
1859 if ((ioc_state
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_FAULT
) {
1860 mpt2sas_base_fault_info(ioc
, ioc_state
&
1861 MPI2_DOORBELL_DATA_MASK
);
1862 goto issue_host_reset
;
1865 smid
= mpt2sas_base_get_smid_hpr(ioc
, ioc
->tm_cb_idx
);
1867 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
1868 ioc
->name
, __func__
);
1872 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"sending tm: handle(0x%04x),"
1873 " task_type(0x%02x), smid(%d)\n", ioc
->name
, handle
, type
,
1875 ioc
->tm_cmds
.status
= MPT2_CMD_PENDING
;
1876 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
1877 ioc
->tm_cmds
.smid
= smid
;
1878 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
1879 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
1880 mpi_request
->DevHandle
= cpu_to_le16(handle
);
1881 mpi_request
->TaskType
= type
;
1882 mpi_request
->TaskMID
= cpu_to_le16(smid_task
);
1883 mpi_request
->VP_ID
= 0; /* TODO */
1884 mpi_request
->VF_ID
= 0;
1885 int_to_scsilun(lun
, (struct scsi_lun
*)mpi_request
->LUN
);
1886 mpt2sas_scsih_set_tm_flag(ioc
, handle
);
1887 init_completion(&ioc
->tm_cmds
.done
);
1888 mpt2sas_base_put_smid_hi_priority(ioc
, smid
);
1889 timeleft
= wait_for_completion_timeout(&ioc
->tm_cmds
.done
, timeout
*HZ
);
1890 mpt2sas_scsih_clear_tm_flag(ioc
, handle
);
1891 if (!(ioc
->tm_cmds
.status
& MPT2_CMD_COMPLETE
)) {
1892 printk(MPT2SAS_ERR_FMT
"%s: timeout\n",
1893 ioc
->name
, __func__
);
1894 _debug_dump_mf(mpi_request
,
1895 sizeof(Mpi2SCSITaskManagementRequest_t
)/4);
1896 if (!(ioc
->tm_cmds
.status
& MPT2_CMD_RESET
))
1897 goto issue_host_reset
;
1900 if (ioc
->tm_cmds
.status
& MPT2_CMD_REPLY_VALID
) {
1901 mpi_reply
= ioc
->tm_cmds
.reply
;
1902 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"complete tm: "
1903 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
1904 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
1905 le32_to_cpu(mpi_reply
->IOCLogInfo
),
1906 le32_to_cpu(mpi_reply
->TerminationCount
)));
1907 if (ioc
->logging_level
& MPT_DEBUG_TM
)
1908 _scsih_response_code(ioc
, mpi_reply
->ResponseCode
);
1912 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
, FORCE_BIG_HAMMER
);
1916 * _scsih_abort - eh threads main abort routine
1917 * @sdev: scsi device struct
1919 * Returns SUCCESS if command aborted else FAILED
1922 _scsih_abort(struct scsi_cmnd
*scmd
)
1924 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
1925 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1929 struct scsi_cmnd
*scmd_lookup
;
1931 printk(MPT2SAS_INFO_FMT
"attempting task abort! scmd(%p)\n",
1933 scsi_print_command(scmd
);
1935 sas_device_priv_data
= scmd
->device
->hostdata
;
1936 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
1937 printk(MPT2SAS_INFO_FMT
"device been deleted! scmd(%p)\n",
1939 scmd
->result
= DID_NO_CONNECT
<< 16;
1940 scmd
->scsi_done(scmd
);
1945 /* search for the command */
1946 smid
= _scsih_scsi_lookup_find_by_scmd(ioc
, scmd
);
1948 scmd
->result
= DID_RESET
<< 16;
1953 /* for hidden raid components and volumes this is not supported */
1954 if (sas_device_priv_data
->sas_target
->flags
&
1955 MPT_TARGET_FLAGS_RAID_COMPONENT
||
1956 sas_device_priv_data
->sas_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
1957 scmd
->result
= DID_RESET
<< 16;
1962 mpt2sas_halt_firmware(ioc
);
1964 mutex_lock(&ioc
->tm_cmds
.mutex
);
1965 handle
= sas_device_priv_data
->sas_target
->handle
;
1966 mpt2sas_scsih_issue_tm(ioc
, handle
, sas_device_priv_data
->lun
,
1967 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
, smid
, 30);
1969 /* sanity check - see whether command actually completed */
1970 scmd_lookup
= _scsih_scsi_lookup_get(ioc
, smid
);
1971 if (scmd_lookup
&& (scmd_lookup
->serial_number
== scmd
->serial_number
))
1975 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
1976 mutex_unlock(&ioc
->tm_cmds
.mutex
);
1979 printk(MPT2SAS_INFO_FMT
"task abort: %s scmd(%p)\n",
1980 ioc
->name
, ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
1985 * _scsih_dev_reset - eh threads main device reset routine
1986 * @sdev: scsi device struct
1988 * Returns SUCCESS if command aborted else FAILED
1991 _scsih_dev_reset(struct scsi_cmnd
*scmd
)
1993 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
1994 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1995 struct _sas_device
*sas_device
;
1996 unsigned long flags
;
2000 printk(MPT2SAS_INFO_FMT
"attempting device reset! scmd(%p)\n",
2002 scsi_print_command(scmd
);
2004 sas_device_priv_data
= scmd
->device
->hostdata
;
2005 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2006 printk(MPT2SAS_INFO_FMT
"device been deleted! scmd(%p)\n",
2008 scmd
->result
= DID_NO_CONNECT
<< 16;
2009 scmd
->scsi_done(scmd
);
2014 /* for hidden raid components obtain the volume_handle */
2016 if (sas_device_priv_data
->sas_target
->flags
&
2017 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2018 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2019 sas_device
= _scsih_sas_device_find_by_handle(ioc
,
2020 sas_device_priv_data
->sas_target
->handle
);
2022 handle
= sas_device
->volume_handle
;
2023 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2025 handle
= sas_device_priv_data
->sas_target
->handle
;
2028 scmd
->result
= DID_RESET
<< 16;
2033 mutex_lock(&ioc
->tm_cmds
.mutex
);
2034 mpt2sas_scsih_issue_tm(ioc
, handle
, 0,
2035 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET
, scmd
->device
->lun
,
2039 * sanity check see whether all commands to this device been
2042 if (_scsih_scsi_lookup_find_by_lun(ioc
, scmd
->device
->id
,
2043 scmd
->device
->lun
, scmd
->device
->channel
))
2047 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
2048 mutex_unlock(&ioc
->tm_cmds
.mutex
);
2051 printk(MPT2SAS_INFO_FMT
"device reset: %s scmd(%p)\n",
2052 ioc
->name
, ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2057 * _scsih_target_reset - eh threads main target reset routine
2058 * @sdev: scsi device struct
2060 * Returns SUCCESS if command aborted else FAILED
2063 _scsih_target_reset(struct scsi_cmnd
*scmd
)
2065 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2066 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2067 struct _sas_device
*sas_device
;
2068 unsigned long flags
;
2072 printk(MPT2SAS_INFO_FMT
"attempting target reset! scmd(%p)\n",
2074 scsi_print_command(scmd
);
2076 sas_device_priv_data
= scmd
->device
->hostdata
;
2077 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2078 printk(MPT2SAS_INFO_FMT
"target been deleted! scmd(%p)\n",
2080 scmd
->result
= DID_NO_CONNECT
<< 16;
2081 scmd
->scsi_done(scmd
);
2086 /* for hidden raid components obtain the volume_handle */
2088 if (sas_device_priv_data
->sas_target
->flags
&
2089 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2090 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2091 sas_device
= _scsih_sas_device_find_by_handle(ioc
,
2092 sas_device_priv_data
->sas_target
->handle
);
2094 handle
= sas_device
->volume_handle
;
2095 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2097 handle
= sas_device_priv_data
->sas_target
->handle
;
2100 scmd
->result
= DID_RESET
<< 16;
2105 mutex_lock(&ioc
->tm_cmds
.mutex
);
2106 mpt2sas_scsih_issue_tm(ioc
, handle
, 0,
2107 MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
, 0, 30);
2110 * sanity check see whether all commands to this target been
2113 if (_scsih_scsi_lookup_find_by_target(ioc
, scmd
->device
->id
,
2114 scmd
->device
->channel
))
2118 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
2119 mutex_unlock(&ioc
->tm_cmds
.mutex
);
2122 printk(MPT2SAS_INFO_FMT
"target reset: %s scmd(%p)\n",
2123 ioc
->name
, ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2128 * _scsih_host_reset - eh threads main host reset routine
2129 * @sdev: scsi device struct
2131 * Returns SUCCESS if command aborted else FAILED
2134 _scsih_host_reset(struct scsi_cmnd
*scmd
)
2136 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2139 printk(MPT2SAS_INFO_FMT
"attempting host reset! scmd(%p)\n",
2141 scsi_print_command(scmd
);
2143 retval
= mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2145 r
= (retval
< 0) ? FAILED
: SUCCESS
;
2146 printk(MPT2SAS_INFO_FMT
"host reset: %s scmd(%p)\n",
2147 ioc
->name
, ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2153 * _scsih_fw_event_add - insert and queue up fw_event
2154 * @ioc: per adapter object
2155 * @fw_event: object describing the event
2156 * Context: This function will acquire ioc->fw_event_lock.
2158 * This adds the firmware event object into link list, then queues it up to
2159 * be processed from user context.
2164 _scsih_fw_event_add(struct MPT2SAS_ADAPTER
*ioc
, struct fw_event_work
*fw_event
)
2166 unsigned long flags
;
2168 if (ioc
->firmware_event_thread
== NULL
)
2171 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2172 list_add_tail(&fw_event
->list
, &ioc
->fw_event_list
);
2173 INIT_WORK(&fw_event
->work
, _firmware_event_work
);
2174 queue_work(ioc
->firmware_event_thread
, &fw_event
->work
);
2175 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2179 * _scsih_fw_event_free - delete fw_event
2180 * @ioc: per adapter object
2181 * @fw_event: object describing the event
2182 * Context: This function will acquire ioc->fw_event_lock.
2184 * This removes firmware event object from link list, frees associated memory.
2189 _scsih_fw_event_free(struct MPT2SAS_ADAPTER
*ioc
, struct fw_event_work
2192 unsigned long flags
;
2194 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2195 list_del(&fw_event
->list
);
2196 kfree(fw_event
->event_data
);
2198 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2202 * _scsih_fw_event_add - requeue an event
2203 * @ioc: per adapter object
2204 * @fw_event: object describing the event
2205 * Context: This function will acquire ioc->fw_event_lock.
2210 _scsih_fw_event_requeue(struct MPT2SAS_ADAPTER
*ioc
, struct fw_event_work
2211 *fw_event
, unsigned long delay
)
2213 unsigned long flags
;
2214 if (ioc
->firmware_event_thread
== NULL
)
2217 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2218 queue_work(ioc
->firmware_event_thread
, &fw_event
->work
);
2219 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2223 * _scsih_fw_event_off - turn flag off preventing event handling
2224 * @ioc: per adapter object
2226 * Used to prevent handling of firmware events during adapter reset
2232 _scsih_fw_event_off(struct MPT2SAS_ADAPTER
*ioc
)
2234 unsigned long flags
;
2236 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2237 ioc
->fw_events_off
= 1;
2238 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2243 * _scsih_fw_event_on - turn flag on allowing firmware event handling
2244 * @ioc: per adapter object
2249 _scsih_fw_event_on(struct MPT2SAS_ADAPTER
*ioc
)
2251 unsigned long flags
;
2253 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2254 ioc
->fw_events_off
= 0;
2255 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2259 * _scsih_ublock_io_device - set the device state to SDEV_RUNNING
2260 * @ioc: per adapter object
2261 * @handle: device handle
2263 * During device pull we need to appropiately set the sdev state.
2266 _scsih_ublock_io_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
2268 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2269 struct scsi_device
*sdev
;
2271 shost_for_each_device(sdev
, ioc
->shost
) {
2272 sas_device_priv_data
= sdev
->hostdata
;
2273 if (!sas_device_priv_data
)
2275 if (!sas_device_priv_data
->block
)
2277 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2278 dewtprintk(ioc
, sdev_printk(KERN_INFO
, sdev
,
2279 MPT2SAS_INFO_FMT
"SDEV_RUNNING: "
2280 "handle(0x%04x)\n", ioc
->name
, handle
));
2281 sas_device_priv_data
->block
= 0;
2282 scsi_internal_device_unblock(sdev
);
2288 * _scsih_block_io_device - set the device state to SDEV_BLOCK
2289 * @ioc: per adapter object
2290 * @handle: device handle
2292 * During device pull we need to appropiately set the sdev state.
2295 _scsih_block_io_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
2297 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2298 struct scsi_device
*sdev
;
2300 shost_for_each_device(sdev
, ioc
->shost
) {
2301 sas_device_priv_data
= sdev
->hostdata
;
2302 if (!sas_device_priv_data
)
2304 if (sas_device_priv_data
->block
)
2306 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2307 dewtprintk(ioc
, sdev_printk(KERN_INFO
, sdev
,
2308 MPT2SAS_INFO_FMT
"SDEV_BLOCK: "
2309 "handle(0x%04x)\n", ioc
->name
, handle
));
2310 sas_device_priv_data
->block
= 1;
2311 scsi_internal_device_block(sdev
);
2317 * _scsih_block_io_to_children_attached_to_ex
2318 * @ioc: per adapter object
2319 * @sas_expander: the sas_device object
2321 * This routine set sdev state to SDEV_BLOCK for all devices
2322 * attached to this expander. This function called when expander is
2326 _scsih_block_io_to_children_attached_to_ex(struct MPT2SAS_ADAPTER
*ioc
,
2327 struct _sas_node
*sas_expander
)
2329 struct _sas_port
*mpt2sas_port
;
2330 struct _sas_device
*sas_device
;
2331 struct _sas_node
*expander_sibling
;
2332 unsigned long flags
;
2337 list_for_each_entry(mpt2sas_port
,
2338 &sas_expander
->sas_port_list
, port_list
) {
2339 if (mpt2sas_port
->remote_identify
.device_type
==
2341 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2343 mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
2344 mpt2sas_port
->remote_identify
.sas_address
);
2345 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2348 _scsih_block_io_device(ioc
, sas_device
->handle
);
2352 list_for_each_entry(mpt2sas_port
,
2353 &sas_expander
->sas_port_list
, port_list
) {
2355 if (mpt2sas_port
->remote_identify
.device_type
==
2356 MPI2_SAS_DEVICE_INFO_EDGE_EXPANDER
||
2357 mpt2sas_port
->remote_identify
.device_type
==
2358 MPI2_SAS_DEVICE_INFO_FANOUT_EXPANDER
) {
2360 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
2362 mpt2sas_scsih_expander_find_by_sas_address(
2363 ioc
, mpt2sas_port
->remote_identify
.sas_address
);
2364 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
2365 _scsih_block_io_to_children_attached_to_ex(ioc
,
2372 * _scsih_block_io_to_children_attached_directly
2373 * @ioc: per adapter object
2374 * @event_data: topology change event data
2376 * This routine set sdev state to SDEV_BLOCK for all devices
2377 * direct attached during device pull.
2380 _scsih_block_io_to_children_attached_directly(struct MPT2SAS_ADAPTER
*ioc
,
2381 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
2388 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
2389 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
2392 phy_number
= event_data
->StartPhyNum
+ i
;
2393 reason_code
= event_data
->PHY
[i
].PhyStatus
&
2394 MPI2_EVENT_SAS_TOPO_RC_MASK
;
2395 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
)
2396 _scsih_block_io_device(ioc
, handle
);
2401 * _scsih_tm_tr_send - send task management request
2402 * @ioc: per adapter object
2403 * @handle: device handle
2404 * Context: interrupt time.
2406 * This code is to initiate the device removal handshake protocal
2407 * with controller firmware. This function will issue target reset
2408 * using high priority request queue. It will send a sas iounit
2409 * controll request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
2411 * This is designed to send muliple task management request at the same
2412 * time to the fifo. If the fifo is full, we will append the request,
2413 * and process it in a future completion.
2416 _scsih_tm_tr_send(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
2418 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
2419 struct MPT2SAS_TARGET
*sas_target_priv_data
;
2421 struct _sas_device
*sas_device
;
2422 unsigned long flags
;
2423 struct _tr_list
*delayed_tr
;
2425 if (ioc
->shost_recovery
) {
2426 printk(MPT2SAS_INFO_FMT
"%s: host reset in progress!\n",
2427 __func__
, ioc
->name
);
2431 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2432 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
2433 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2435 /* skip is hidden raid component */
2436 if (sas_device
&& sas_device
->hidden_raid_component
)
2439 smid
= mpt2sas_base_get_smid_hpr(ioc
, ioc
->tm_tr_cb_idx
);
2441 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
2444 INIT_LIST_HEAD(&delayed_tr
->list
);
2445 delayed_tr
->handle
= handle
;
2446 delayed_tr
->state
= MPT2SAS_REQ_SAS_CNTRL
;
2447 list_add_tail(&delayed_tr
->list
,
2448 &ioc
->delayed_tr_list
);
2449 if (sas_device
&& sas_device
->starget
) {
2450 dewtprintk(ioc
, starget_printk(KERN_INFO
,
2451 sas_device
->starget
, "DELAYED:tr:handle(0x%04x), "
2452 "(open)\n", handle
));
2454 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
2455 "DELAYED:tr:handle(0x%04x), (open)\n",
2456 ioc
->name
, handle
));
2462 sas_device
->state
|= MPTSAS_STATE_TR_SEND
;
2463 sas_device
->state
|= MPT2SAS_REQ_SAS_CNTRL
;
2464 if (sas_device
->starget
&& sas_device
->starget
->hostdata
) {
2465 sas_target_priv_data
= sas_device
->starget
->hostdata
;
2466 sas_target_priv_data
->tm_busy
= 1;
2467 dewtprintk(ioc
, starget_printk(KERN_INFO
,
2468 sas_device
->starget
, "tr:handle(0x%04x), (open)\n",
2472 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
2473 "tr:handle(0x%04x), (open)\n", ioc
->name
, handle
));
2476 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
2477 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
2478 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
2479 mpi_request
->DevHandle
= cpu_to_le16(handle
);
2480 mpi_request
->TaskType
= MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
;
2481 mpt2sas_base_put_smid_hi_priority(ioc
, smid
);
2487 * _scsih_sas_control_complete - completion routine
2488 * @ioc: per adapter object
2489 * @smid: system request message index
2490 * @msix_index: MSIX table index supplied by the OS
2491 * @reply: reply message frame(lower 32bit addr)
2492 * Context: interrupt time.
2494 * This is the sas iounit controll completion routine.
2495 * This code is part of the code to initiate the device removal
2496 * handshake protocal with controller firmware.
2498 * Return 1 meaning mf should be freed from _base_interrupt
2499 * 0 means the mf is freed from this function.
2502 _scsih_sas_control_complete(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
,
2503 u8 msix_index
, u32 reply
)
2505 unsigned long flags
;
2507 struct _sas_device
*sas_device
;
2508 Mpi2SasIoUnitControlReply_t
*mpi_reply
=
2509 mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
2511 handle
= le16_to_cpu(mpi_reply
->DevHandle
);
2513 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2514 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
2515 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2518 sas_device
->state
|= MPTSAS_STATE_CNTRL_COMPLETE
;
2519 if (sas_device
->starget
)
2520 dewtprintk(ioc
, starget_printk(KERN_INFO
,
2521 sas_device
->starget
,
2522 "sc_complete:handle(0x%04x), "
2523 "ioc_status(0x%04x), loginfo(0x%08x)\n",
2524 handle
, le16_to_cpu(mpi_reply
->IOCStatus
),
2525 le32_to_cpu(mpi_reply
->IOCLogInfo
)));
2527 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
2528 "sc_complete:handle(0x%04x), "
2529 "ioc_status(0x%04x), loginfo(0x%08x)\n",
2530 ioc
->name
, handle
, le16_to_cpu(mpi_reply
->IOCStatus
),
2531 le32_to_cpu(mpi_reply
->IOCLogInfo
)));
2538 * _scsih_tm_tr_complete -
2539 * @ioc: per adapter object
2540 * @smid: system request message index
2541 * @msix_index: MSIX table index supplied by the OS
2542 * @reply: reply message frame(lower 32bit addr)
2543 * Context: interrupt time.
2545 * This is the target reset completion routine.
2546 * This code is part of the code to initiate the device removal
2547 * handshake protocal with controller firmware.
2548 * It will send a sas iounit controll request (MPI2_SAS_OP_REMOVE_DEVICE)
2550 * Return 1 meaning mf should be freed from _base_interrupt
2551 * 0 means the mf is freed from this function.
2554 _scsih_tm_tr_complete(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
,
2557 unsigned long flags
;
2559 struct _sas_device
*sas_device
;
2560 Mpi2SCSITaskManagementReply_t
*mpi_reply
=
2561 mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
2562 Mpi2SasIoUnitControlRequest_t
*mpi_request
;
2564 struct MPT2SAS_TARGET
*sas_target_priv_data
;
2565 struct _tr_list
*delayed_tr
;
2568 handle
= le16_to_cpu(mpi_reply
->DevHandle
);
2569 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2570 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
2571 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2574 sas_device
->state
|= MPTSAS_STATE_TR_COMPLETE
;
2575 if (sas_device
->starget
) {
2576 dewtprintk(ioc
, starget_printk(KERN_INFO
,
2577 sas_device
->starget
, "tr_complete:handle(0x%04x), "
2578 "(%s) ioc_status(0x%04x), loginfo(0x%08x), "
2579 "completed(%d)\n", sas_device
->handle
,
2580 (sas_device
->state
& MPT2SAS_REQ_SAS_CNTRL
) ?
2582 le16_to_cpu(mpi_reply
->IOCStatus
),
2583 le32_to_cpu(mpi_reply
->IOCLogInfo
),
2584 le32_to_cpu(mpi_reply
->TerminationCount
)));
2585 if (sas_device
->starget
->hostdata
) {
2586 sas_target_priv_data
=
2587 sas_device
->starget
->hostdata
;
2588 sas_target_priv_data
->tm_busy
= 0;
2592 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
2593 "tr_complete:handle(0x%04x), (open) ioc_status(0x%04x), "
2594 "loginfo(0x%08x), completed(%d)\n", ioc
->name
,
2595 handle
, le16_to_cpu(mpi_reply
->IOCStatus
),
2596 le32_to_cpu(mpi_reply
->IOCLogInfo
),
2597 le32_to_cpu(mpi_reply
->TerminationCount
)));
2600 if (!list_empty(&ioc
->delayed_tr_list
)) {
2601 delayed_tr
= list_entry(ioc
->delayed_tr_list
.next
,
2602 struct _tr_list
, list
);
2603 mpt2sas_base_free_smid(ioc
, smid
);
2604 if (delayed_tr
->state
& MPT2SAS_REQ_SAS_CNTRL
)
2605 _scsih_tm_tr_send(ioc
, delayed_tr
->handle
);
2606 list_del(&delayed_tr
->list
);
2608 rc
= 0; /* tells base_interrupt not to free mf */
2612 if (sas_device
&& !(sas_device
->state
& MPT2SAS_REQ_SAS_CNTRL
))
2615 if (ioc
->shost_recovery
) {
2616 printk(MPT2SAS_INFO_FMT
"%s: host reset in progress!\n",
2617 __func__
, ioc
->name
);
2621 smid_sas_ctrl
= mpt2sas_base_get_smid(ioc
, ioc
->tm_sas_control_cb_idx
);
2622 if (!smid_sas_ctrl
) {
2623 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
2624 ioc
->name
, __func__
);
2629 sas_device
->state
|= MPTSAS_STATE_CNTRL_SEND
;
2631 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid_sas_ctrl
);
2632 memset(mpi_request
, 0, sizeof(Mpi2SasIoUnitControlRequest_t
));
2633 mpi_request
->Function
= MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
;
2634 mpi_request
->Operation
= MPI2_SAS_OP_REMOVE_DEVICE
;
2635 mpi_request
->DevHandle
= mpi_reply
->DevHandle
;
2636 mpt2sas_base_put_smid_default(ioc
, smid_sas_ctrl
);
2641 * _scsih_check_topo_delete_events - sanity check on topo events
2642 * @ioc: per adapter object
2643 * @event_data: the event data payload
2645 * This routine added to better handle cable breaker.
2647 * This handles the case where driver recieves multiple expander
2648 * add and delete events in a single shot. When there is a delete event
2649 * the routine will void any pending add events waiting in the event queue.
2654 _scsih_check_topo_delete_events(struct MPT2SAS_ADAPTER
*ioc
,
2655 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
2657 struct fw_event_work
*fw_event
;
2658 Mpi2EventDataSasTopologyChangeList_t
*local_event_data
;
2659 u16 expander_handle
;
2660 struct _sas_node
*sas_expander
;
2661 unsigned long flags
;
2665 for (i
= 0 ; i
< event_data
->NumEntries
; i
++) {
2666 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
2669 reason_code
= event_data
->PHY
[i
].PhyStatus
&
2670 MPI2_EVENT_SAS_TOPO_RC_MASK
;
2671 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
)
2672 _scsih_tm_tr_send(ioc
, handle
);
2675 expander_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
2676 if (expander_handle
< ioc
->sas_hba
.num_phys
) {
2677 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
2681 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
2682 || event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
) {
2683 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
2684 sas_expander
= mpt2sas_scsih_expander_find_by_handle(ioc
,
2686 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
2687 _scsih_block_io_to_children_attached_to_ex(ioc
, sas_expander
);
2688 } else if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_RESPONDING
)
2689 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
2691 if (event_data
->ExpStatus
!= MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
)
2694 /* mark ignore flag for pending events */
2695 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2696 list_for_each_entry(fw_event
, &ioc
->fw_event_list
, list
) {
2697 if (fw_event
->event
!= MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
||
2700 local_event_data
= fw_event
->event_data
;
2701 if (local_event_data
->ExpStatus
==
2702 MPI2_EVENT_SAS_TOPO_ES_ADDED
||
2703 local_event_data
->ExpStatus
==
2704 MPI2_EVENT_SAS_TOPO_ES_RESPONDING
) {
2705 if (le16_to_cpu(local_event_data
->ExpanderDevHandle
) ==
2707 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
2708 "setting ignoring flag\n", ioc
->name
));
2709 fw_event
->ignore
= 1;
2713 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2717 * _scsih_flush_running_cmds - completing outstanding commands.
2718 * @ioc: per adapter object
2720 * The flushing out of all pending scmd commands following host reset,
2721 * where all IO is dropped to the floor.
2726 _scsih_flush_running_cmds(struct MPT2SAS_ADAPTER
*ioc
)
2728 struct scsi_cmnd
*scmd
;
2732 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
2733 scmd
= _scsih_scsi_lookup_get(ioc
, smid
);
2737 mpt2sas_base_free_smid(ioc
, smid
);
2738 scsi_dma_unmap(scmd
);
2739 scmd
->result
= DID_RESET
<< 16;
2740 scmd
->scsi_done(scmd
);
2742 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"completing %d cmds\n",
2747 * _scsih_setup_eedp - setup MPI request for EEDP transfer
2748 * @scmd: pointer to scsi command object
2749 * @mpi_request: pointer to the SCSI_IO reqest message frame
2751 * Supporting protection 1 and 3.
2756 _scsih_setup_eedp(struct scsi_cmnd
*scmd
, Mpi2SCSIIORequest_t
*mpi_request
)
2759 unsigned char prot_op
= scsi_get_prot_op(scmd
);
2760 unsigned char prot_type
= scsi_get_prot_type(scmd
);
2762 if (prot_type
== SCSI_PROT_DIF_TYPE0
||
2763 prot_type
== SCSI_PROT_DIF_TYPE2
||
2764 prot_op
== SCSI_PROT_NORMAL
)
2767 if (prot_op
== SCSI_PROT_READ_STRIP
)
2768 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP
;
2769 else if (prot_op
== SCSI_PROT_WRITE_INSERT
)
2770 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_INSERT_OP
;
2774 switch (prot_type
) {
2775 case SCSI_PROT_DIF_TYPE1
:
2778 * enable ref/guard checking
2779 * auto increment ref tag
2781 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG
|
2782 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG
|
2783 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
2784 mpi_request
->CDB
.EEDP32
.PrimaryReferenceTag
=
2785 cpu_to_be32(scsi_get_lba(scmd
));
2789 case SCSI_PROT_DIF_TYPE3
:
2792 * enable guard checking
2794 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
2797 mpi_request
->EEDPBlockSize
= cpu_to_le32(scmd
->device
->sector_size
);
2798 mpi_request
->EEDPFlags
= cpu_to_le16(eedp_flags
);
2802 * _scsih_eedp_error_handling - return sense code for EEDP errors
2803 * @scmd: pointer to scsi command object
2804 * @ioc_status: ioc status
2809 _scsih_eedp_error_handling(struct scsi_cmnd
*scmd
, u16 ioc_status
)
2815 switch (ioc_status
) {
2816 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
2819 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
2822 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
2830 if (scmd
->sc_data_direction
== DMA_TO_DEVICE
) {
2831 sk
= ILLEGAL_REQUEST
;
2832 host_byte
= DID_ABORT
;
2834 sk
= ABORTED_COMMAND
;
2838 scsi_build_sense_buffer(0, scmd
->sense_buffer
, sk
, 0x10, ascq
);
2839 scmd
->result
= DRIVER_SENSE
<< 24 | (host_byte
<< 16) |
2840 SAM_STAT_CHECK_CONDITION
;
2844 * _scsih_qcmd - main scsi request entry point
2845 * @scmd: pointer to scsi command object
2846 * @done: function pointer to be invoked on completion
2848 * The callback index is set inside `ioc->scsi_io_cb_idx`.
2850 * Returns 0 on success. If there's a failure, return either:
2851 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
2852 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
2855 _scsih_qcmd(struct scsi_cmnd
*scmd
, void (*done
)(struct scsi_cmnd
*))
2857 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2858 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2859 struct MPT2SAS_TARGET
*sas_target_priv_data
;
2860 Mpi2SCSIIORequest_t
*mpi_request
;
2864 scmd
->scsi_done
= done
;
2865 sas_device_priv_data
= scmd
->device
->hostdata
;
2866 if (!sas_device_priv_data
) {
2867 scmd
->result
= DID_NO_CONNECT
<< 16;
2868 scmd
->scsi_done(scmd
);
2872 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
2873 if (!sas_target_priv_data
|| sas_target_priv_data
->handle
==
2874 MPT2SAS_INVALID_DEVICE_HANDLE
|| sas_target_priv_data
->deleted
) {
2875 scmd
->result
= DID_NO_CONNECT
<< 16;
2876 scmd
->scsi_done(scmd
);
2880 /* see if we are busy with task managment stuff */
2881 if (sas_device_priv_data
->block
|| sas_target_priv_data
->tm_busy
)
2882 return SCSI_MLQUEUE_DEVICE_BUSY
;
2883 else if (ioc
->shost_recovery
|| ioc
->ioc_link_reset_in_progress
)
2884 return SCSI_MLQUEUE_HOST_BUSY
;
2886 if (scmd
->sc_data_direction
== DMA_FROM_DEVICE
)
2887 mpi_control
= MPI2_SCSIIO_CONTROL_READ
;
2888 else if (scmd
->sc_data_direction
== DMA_TO_DEVICE
)
2889 mpi_control
= MPI2_SCSIIO_CONTROL_WRITE
;
2891 mpi_control
= MPI2_SCSIIO_CONTROL_NODATATRANSFER
;
2894 if (!(sas_device_priv_data
->flags
& MPT_DEVICE_FLAGS_INIT
)) {
2895 if (scmd
->device
->tagged_supported
) {
2896 if (scmd
->device
->ordered_tags
)
2897 mpi_control
|= MPI2_SCSIIO_CONTROL_ORDEREDQ
;
2899 mpi_control
|= MPI2_SCSIIO_CONTROL_SIMPLEQ
;
2901 /* MPI Revision I (UNIT = 0xA) - removed MPI2_SCSIIO_CONTROL_UNTAGGED */
2902 /* mpi_control |= MPI2_SCSIIO_CONTROL_UNTAGGED;
2904 mpi_control
|= (0x500);
2907 mpi_control
|= MPI2_SCSIIO_CONTROL_SIMPLEQ
;
2909 if ((sas_device_priv_data
->flags
& MPT_DEVICE_TLR_ON
))
2910 mpi_control
|= MPI2_SCSIIO_CONTROL_TLR_ON
;
2912 smid
= mpt2sas_base_get_smid_scsiio(ioc
, ioc
->scsi_io_cb_idx
, scmd
);
2914 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
2915 ioc
->name
, __func__
);
2918 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
2919 memset(mpi_request
, 0, sizeof(Mpi2SCSIIORequest_t
));
2920 _scsih_setup_eedp(scmd
, mpi_request
);
2921 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
2922 if (sas_device_priv_data
->sas_target
->flags
&
2923 MPT_TARGET_FLAGS_RAID_COMPONENT
)
2924 mpi_request
->Function
= MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
;
2926 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
2927 mpi_request
->DevHandle
=
2928 cpu_to_le16(sas_device_priv_data
->sas_target
->handle
);
2929 mpi_request
->DataLength
= cpu_to_le32(scsi_bufflen(scmd
));
2930 mpi_request
->Control
= cpu_to_le32(mpi_control
);
2931 mpi_request
->IoFlags
= cpu_to_le16(scmd
->cmd_len
);
2932 mpi_request
->MsgFlags
= MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR
;
2933 mpi_request
->SenseBufferLength
= SCSI_SENSE_BUFFERSIZE
;
2934 mpi_request
->SenseBufferLowAddress
=
2935 mpt2sas_base_get_sense_buffer_dma(ioc
, smid
);
2936 mpi_request
->SGLOffset0
= offsetof(Mpi2SCSIIORequest_t
, SGL
) / 4;
2937 mpi_request
->SGLFlags
= cpu_to_le16(MPI2_SCSIIO_SGLFLAGS_TYPE_MPI
+
2938 MPI2_SCSIIO_SGLFLAGS_SYSTEM_ADDR
);
2939 mpi_request
->VF_ID
= 0; /* TODO */
2940 mpi_request
->VP_ID
= 0;
2941 int_to_scsilun(sas_device_priv_data
->lun
, (struct scsi_lun
*)
2943 memcpy(mpi_request
->CDB
.CDB32
, scmd
->cmnd
, scmd
->cmd_len
);
2945 if (!mpi_request
->DataLength
) {
2946 mpt2sas_base_build_zero_len_sge(ioc
, &mpi_request
->SGL
);
2948 if (_scsih_build_scatter_gather(ioc
, scmd
, smid
)) {
2949 mpt2sas_base_free_smid(ioc
, smid
);
2954 mpt2sas_base_put_smid_scsi_io(ioc
, smid
,
2955 sas_device_priv_data
->sas_target
->handle
);
2959 return SCSI_MLQUEUE_HOST_BUSY
;
2963 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
2964 * @sense_buffer: sense data returned by target
2965 * @data: normalized skey/asc/ascq
2970 _scsih_normalize_sense(char *sense_buffer
, struct sense_info
*data
)
2972 if ((sense_buffer
[0] & 0x7F) >= 0x72) {
2973 /* descriptor format */
2974 data
->skey
= sense_buffer
[1] & 0x0F;
2975 data
->asc
= sense_buffer
[2];
2976 data
->ascq
= sense_buffer
[3];
2979 data
->skey
= sense_buffer
[2] & 0x0F;
2980 data
->asc
= sense_buffer
[12];
2981 data
->ascq
= sense_buffer
[13];
2985 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
2987 * _scsih_scsi_ioc_info - translated non-successfull SCSI_IO request
2988 * @ioc: per adapter object
2989 * @scmd: pointer to scsi command object
2990 * @mpi_reply: reply mf payload returned from firmware
2992 * scsi_status - SCSI Status code returned from target device
2993 * scsi_state - state info associated with SCSI_IO determined by ioc
2994 * ioc_status - ioc supplied status info
2999 _scsih_scsi_ioc_info(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
,
3000 Mpi2SCSIIOReply_t
*mpi_reply
, u16 smid
)
3004 u16 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) &
3005 MPI2_IOCSTATUS_MASK
;
3006 u8 scsi_state
= mpi_reply
->SCSIState
;
3007 u8 scsi_status
= mpi_reply
->SCSIStatus
;
3008 char *desc_ioc_state
= NULL
;
3009 char *desc_scsi_status
= NULL
;
3010 char *desc_scsi_state
= ioc
->tmp_string
;
3011 u32 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
3013 if (log_info
== 0x31170000)
3016 switch (ioc_status
) {
3017 case MPI2_IOCSTATUS_SUCCESS
:
3018 desc_ioc_state
= "success";
3020 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
3021 desc_ioc_state
= "invalid function";
3023 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
3024 desc_ioc_state
= "scsi recovered error";
3026 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE
:
3027 desc_ioc_state
= "scsi invalid dev handle";
3029 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
3030 desc_ioc_state
= "scsi device not there";
3032 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
3033 desc_ioc_state
= "scsi data overrun";
3035 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
3036 desc_ioc_state
= "scsi data underrun";
3038 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
3039 desc_ioc_state
= "scsi io data error";
3041 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
3042 desc_ioc_state
= "scsi protocol error";
3044 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
3045 desc_ioc_state
= "scsi task terminated";
3047 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
3048 desc_ioc_state
= "scsi residual mismatch";
3050 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
3051 desc_ioc_state
= "scsi task mgmt failed";
3053 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
3054 desc_ioc_state
= "scsi ioc terminated";
3056 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
3057 desc_ioc_state
= "scsi ext terminated";
3059 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
3060 desc_ioc_state
= "eedp guard error";
3062 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
3063 desc_ioc_state
= "eedp ref tag error";
3065 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
3066 desc_ioc_state
= "eedp app tag error";
3069 desc_ioc_state
= "unknown";
3073 switch (scsi_status
) {
3074 case MPI2_SCSI_STATUS_GOOD
:
3075 desc_scsi_status
= "good";
3077 case MPI2_SCSI_STATUS_CHECK_CONDITION
:
3078 desc_scsi_status
= "check condition";
3080 case MPI2_SCSI_STATUS_CONDITION_MET
:
3081 desc_scsi_status
= "condition met";
3083 case MPI2_SCSI_STATUS_BUSY
:
3084 desc_scsi_status
= "busy";
3086 case MPI2_SCSI_STATUS_INTERMEDIATE
:
3087 desc_scsi_status
= "intermediate";
3089 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET
:
3090 desc_scsi_status
= "intermediate condmet";
3092 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT
:
3093 desc_scsi_status
= "reservation conflict";
3095 case MPI2_SCSI_STATUS_COMMAND_TERMINATED
:
3096 desc_scsi_status
= "command terminated";
3098 case MPI2_SCSI_STATUS_TASK_SET_FULL
:
3099 desc_scsi_status
= "task set full";
3101 case MPI2_SCSI_STATUS_ACA_ACTIVE
:
3102 desc_scsi_status
= "aca active";
3104 case MPI2_SCSI_STATUS_TASK_ABORTED
:
3105 desc_scsi_status
= "task aborted";
3108 desc_scsi_status
= "unknown";
3112 desc_scsi_state
[0] = '\0';
3114 desc_scsi_state
= " ";
3115 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
3116 strcat(desc_scsi_state
, "response info ");
3117 if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
3118 strcat(desc_scsi_state
, "state terminated ");
3119 if (scsi_state
& MPI2_SCSI_STATE_NO_SCSI_STATUS
)
3120 strcat(desc_scsi_state
, "no status ");
3121 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_FAILED
)
3122 strcat(desc_scsi_state
, "autosense failed ");
3123 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
)
3124 strcat(desc_scsi_state
, "autosense valid ");
3126 scsi_print_command(scmd
);
3127 printk(MPT2SAS_WARN_FMT
"\tdev handle(0x%04x), "
3128 "ioc_status(%s)(0x%04x), smid(%d)\n", ioc
->name
,
3129 le16_to_cpu(mpi_reply
->DevHandle
), desc_ioc_state
,
3131 printk(MPT2SAS_WARN_FMT
"\trequest_len(%d), underflow(%d), "
3132 "resid(%d)\n", ioc
->name
, scsi_bufflen(scmd
), scmd
->underflow
,
3133 scsi_get_resid(scmd
));
3134 printk(MPT2SAS_WARN_FMT
"\ttag(%d), transfer_count(%d), "
3135 "sc->result(0x%08x)\n", ioc
->name
, le16_to_cpu(mpi_reply
->TaskTag
),
3136 le32_to_cpu(mpi_reply
->TransferCount
), scmd
->result
);
3137 printk(MPT2SAS_WARN_FMT
"\tscsi_status(%s)(0x%02x), "
3138 "scsi_state(%s)(0x%02x)\n", ioc
->name
, desc_scsi_status
,
3139 scsi_status
, desc_scsi_state
, scsi_state
);
3141 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
3142 struct sense_info data
;
3143 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
3144 printk(MPT2SAS_WARN_FMT
"\t[sense_key,asc,ascq]: "
3145 "[0x%02x,0x%02x,0x%02x]\n", ioc
->name
, data
.skey
,
3146 data
.asc
, data
.ascq
);
3149 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
) {
3150 response_info
= le32_to_cpu(mpi_reply
->ResponseInfo
);
3151 response_bytes
= (u8
*)&response_info
;
3152 _scsih_response_code(ioc
, response_bytes
[0]);
3158 * _scsih_smart_predicted_fault - illuminate Fault LED
3159 * @ioc: per adapter object
3160 * @handle: device handle
3165 _scsih_smart_predicted_fault(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
3167 Mpi2SepReply_t mpi_reply
;
3168 Mpi2SepRequest_t mpi_request
;
3169 struct scsi_target
*starget
;
3170 struct MPT2SAS_TARGET
*sas_target_priv_data
;
3171 Mpi2EventNotificationReply_t
*event_reply
;
3172 Mpi2EventDataSasDeviceStatusChange_t
*event_data
;
3173 struct _sas_device
*sas_device
;
3175 unsigned long flags
;
3177 /* only handle non-raid devices */
3178 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
3179 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
3181 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3184 starget
= sas_device
->starget
;
3185 sas_target_priv_data
= starget
->hostdata
;
3187 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
) ||
3188 ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
))) {
3189 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3192 starget_printk(KERN_WARNING
, starget
, "predicted fault\n");
3193 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3195 if (ioc
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_IBM
) {
3196 memset(&mpi_request
, 0, sizeof(Mpi2SepRequest_t
));
3197 mpi_request
.Function
= MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR
;
3198 mpi_request
.Action
= MPI2_SEP_REQ_ACTION_WRITE_STATUS
;
3199 mpi_request
.SlotStatus
=
3200 MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT
;
3201 mpi_request
.DevHandle
= cpu_to_le16(handle
);
3202 mpi_request
.Flags
= MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS
;
3203 if ((mpt2sas_base_scsi_enclosure_processor(ioc
, &mpi_reply
,
3204 &mpi_request
)) != 0) {
3205 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3206 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3210 if (mpi_reply
.IOCStatus
|| mpi_reply
.IOCLogInfo
) {
3211 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3212 "enclosure_processor: ioc_status (0x%04x), "
3213 "loginfo(0x%08x)\n", ioc
->name
,
3214 le16_to_cpu(mpi_reply
.IOCStatus
),
3215 le32_to_cpu(mpi_reply
.IOCLogInfo
)));
3220 /* insert into event log */
3221 sz
= offsetof(Mpi2EventNotificationReply_t
, EventData
) +
3222 sizeof(Mpi2EventDataSasDeviceStatusChange_t
);
3223 event_reply
= kzalloc(sz
, GFP_KERNEL
);
3225 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3226 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3230 event_reply
->Function
= MPI2_FUNCTION_EVENT_NOTIFICATION
;
3231 event_reply
->Event
=
3232 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
);
3233 event_reply
->MsgLength
= sz
/4;
3234 event_reply
->EventDataLength
=
3235 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t
)/4);
3236 event_data
= (Mpi2EventDataSasDeviceStatusChange_t
*)
3237 event_reply
->EventData
;
3238 event_data
->ReasonCode
= MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
;
3239 event_data
->ASC
= 0x5D;
3240 event_data
->DevHandle
= cpu_to_le16(handle
);
3241 event_data
->SASAddress
= cpu_to_le64(sas_target_priv_data
->sas_address
);
3242 mpt2sas_ctl_add_to_event_log(ioc
, event_reply
);
3247 * _scsih_io_done - scsi request callback
3248 * @ioc: per adapter object
3249 * @smid: system request message index
3250 * @msix_index: MSIX table index supplied by the OS
3251 * @reply: reply message frame(lower 32bit addr)
3253 * Callback handler when using _scsih_qcmd.
3255 * Return 1 meaning mf should be freed from _base_interrupt
3256 * 0 means the mf is freed from this function.
3259 _scsih_io_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
3261 Mpi2SCSIIORequest_t
*mpi_request
;
3262 Mpi2SCSIIOReply_t
*mpi_reply
;
3263 struct scsi_cmnd
*scmd
;
3269 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
3270 u32 response_code
= 0;
3272 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
3273 scmd
= _scsih_scsi_lookup_get(ioc
, smid
);
3277 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3279 if (mpi_reply
== NULL
) {
3280 scmd
->result
= DID_OK
<< 16;
3284 sas_device_priv_data
= scmd
->device
->hostdata
;
3285 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
||
3286 sas_device_priv_data
->sas_target
->deleted
) {
3287 scmd
->result
= DID_NO_CONNECT
<< 16;
3291 /* turning off TLR */
3292 scsi_state
= mpi_reply
->SCSIState
;
3293 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
3295 le32_to_cpu(mpi_reply
->ResponseInfo
) & 0xFF;
3296 if (!sas_device_priv_data
->tlr_snoop_check
) {
3297 sas_device_priv_data
->tlr_snoop_check
++;
3298 if ((sas_device_priv_data
->flags
& MPT_DEVICE_TLR_ON
) &&
3299 response_code
== MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
)
3300 sas_device_priv_data
->flags
&=
3304 xfer_cnt
= le32_to_cpu(mpi_reply
->TransferCount
);
3305 scsi_set_resid(scmd
, scsi_bufflen(scmd
) - xfer_cnt
);
3306 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
);
3307 if (ioc_status
& MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE
)
3308 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
3311 ioc_status
&= MPI2_IOCSTATUS_MASK
;
3312 scsi_status
= mpi_reply
->SCSIStatus
;
3314 if (ioc_status
== MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
&& xfer_cnt
== 0 &&
3315 (scsi_status
== MPI2_SCSI_STATUS_BUSY
||
3316 scsi_status
== MPI2_SCSI_STATUS_RESERVATION_CONFLICT
||
3317 scsi_status
== MPI2_SCSI_STATUS_TASK_SET_FULL
)) {
3318 ioc_status
= MPI2_IOCSTATUS_SUCCESS
;
3321 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
3322 struct sense_info data
;
3323 const void *sense_data
= mpt2sas_base_get_sense_buffer(ioc
,
3325 u32 sz
= min_t(u32
, SCSI_SENSE_BUFFERSIZE
,
3326 le32_to_cpu(mpi_reply
->SenseCount
));
3327 memcpy(scmd
->sense_buffer
, sense_data
, sz
);
3328 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
3329 /* failure prediction threshold exceeded */
3330 if (data
.asc
== 0x5D)
3331 _scsih_smart_predicted_fault(ioc
,
3332 le16_to_cpu(mpi_reply
->DevHandle
));
3335 switch (ioc_status
) {
3336 case MPI2_IOCSTATUS_BUSY
:
3337 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES
:
3338 scmd
->result
= SAM_STAT_BUSY
;
3341 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
3342 scmd
->result
= DID_NO_CONNECT
<< 16;
3345 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
3346 if (sas_device_priv_data
->block
) {
3347 scmd
->result
= DID_TRANSPORT_DISRUPTED
<< 16;
3350 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
3351 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
3352 scmd
->result
= DID_RESET
<< 16;
3355 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
3356 if ((xfer_cnt
== 0) || (scmd
->underflow
> xfer_cnt
))
3357 scmd
->result
= DID_SOFT_ERROR
<< 16;
3359 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
3362 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
3363 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
3365 if ((scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
))
3368 if (xfer_cnt
< scmd
->underflow
) {
3369 if (scsi_status
== SAM_STAT_BUSY
)
3370 scmd
->result
= SAM_STAT_BUSY
;
3372 scmd
->result
= DID_SOFT_ERROR
<< 16;
3373 } else if (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
3374 MPI2_SCSI_STATE_NO_SCSI_STATUS
))
3375 scmd
->result
= DID_SOFT_ERROR
<< 16;
3376 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
3377 scmd
->result
= DID_RESET
<< 16;
3378 else if (!xfer_cnt
&& scmd
->cmnd
[0] == REPORT_LUNS
) {
3379 mpi_reply
->SCSIState
= MPI2_SCSI_STATE_AUTOSENSE_VALID
;
3380 mpi_reply
->SCSIStatus
= SAM_STAT_CHECK_CONDITION
;
3381 scmd
->result
= (DRIVER_SENSE
<< 24) |
3382 SAM_STAT_CHECK_CONDITION
;
3383 scmd
->sense_buffer
[0] = 0x70;
3384 scmd
->sense_buffer
[2] = ILLEGAL_REQUEST
;
3385 scmd
->sense_buffer
[12] = 0x20;
3386 scmd
->sense_buffer
[13] = 0;
3390 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
3391 scsi_set_resid(scmd
, 0);
3392 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
3393 case MPI2_IOCSTATUS_SUCCESS
:
3394 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
3395 if (response_code
==
3396 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
||
3397 (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
3398 MPI2_SCSI_STATE_NO_SCSI_STATUS
)))
3399 scmd
->result
= DID_SOFT_ERROR
<< 16;
3400 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
3401 scmd
->result
= DID_RESET
<< 16;
3404 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
3405 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
3406 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
3407 _scsih_eedp_error_handling(scmd
, ioc_status
);
3409 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
3410 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
3411 case MPI2_IOCSTATUS_INVALID_SGL
:
3412 case MPI2_IOCSTATUS_INTERNAL_ERROR
:
3413 case MPI2_IOCSTATUS_INVALID_FIELD
:
3414 case MPI2_IOCSTATUS_INVALID_STATE
:
3415 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
3416 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
3418 scmd
->result
= DID_SOFT_ERROR
<< 16;
3423 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3424 if (scmd
->result
&& (ioc
->logging_level
& MPT_DEBUG_REPLY
))
3425 _scsih_scsi_ioc_info(ioc
, scmd
, mpi_reply
, smid
);
3429 scsi_dma_unmap(scmd
);
3430 scmd
->scsi_done(scmd
);
3435 * _scsih_sas_host_refresh - refreshing sas host object contents
3436 * @ioc: per adapter object
3439 * During port enable, fw will send topology events for every device. Its
3440 * possible that the handles may change from the previous setting, so this
3441 * code keeping handles updating if changed.
3446 _scsih_sas_host_refresh(struct MPT2SAS_ADAPTER
*ioc
)
3451 Mpi2ConfigReply_t mpi_reply
;
3452 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
3453 u16 attached_handle
;
3455 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
3456 "updating handles for sas_host(0x%016llx)\n",
3457 ioc
->name
, (unsigned long long)ioc
->sas_hba
.sas_address
));
3459 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
3460 * sizeof(Mpi2SasIOUnit0PhyData_t
));
3461 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
3462 if (!sas_iounit_pg0
) {
3463 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3464 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3468 if ((mpt2sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
3469 sas_iounit_pg0
, sz
)) != 0)
3471 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
3472 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
3474 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
3476 ioc
->sas_hba
.handle
= le16_to_cpu(sas_iounit_pg0
->
3477 PhyData
[0].ControllerDevHandle
);
3478 ioc
->sas_hba
.phy
[i
].handle
= ioc
->sas_hba
.handle
;
3479 attached_handle
= le16_to_cpu(sas_iounit_pg0
->PhyData
[i
].
3481 mpt2sas_transport_update_links(ioc
, ioc
->sas_hba
.sas_address
,
3482 attached_handle
, i
, sas_iounit_pg0
->PhyData
[i
].
3483 NegotiatedLinkRate
>> 4);
3486 kfree(sas_iounit_pg0
);
3490 * _scsih_sas_host_add - create sas host object
3491 * @ioc: per adapter object
3493 * Creating host side data object, stored in ioc->sas_hba
3498 _scsih_sas_host_add(struct MPT2SAS_ADAPTER
*ioc
)
3501 Mpi2ConfigReply_t mpi_reply
;
3502 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
3503 Mpi2SasIOUnitPage1_t
*sas_iounit_pg1
= NULL
;
3504 Mpi2SasPhyPage0_t phy_pg0
;
3505 Mpi2SasDevicePage0_t sas_device_pg0
;
3506 Mpi2SasEnclosurePage0_t enclosure_pg0
;
3509 u16 device_missing_delay
;
3511 mpt2sas_config_get_number_hba_phys(ioc
, &ioc
->sas_hba
.num_phys
);
3512 if (!ioc
->sas_hba
.num_phys
) {
3513 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3514 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3518 /* sas_iounit page 0 */
3519 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
3520 sizeof(Mpi2SasIOUnit0PhyData_t
));
3521 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
3522 if (!sas_iounit_pg0
) {
3523 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3524 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3527 if ((mpt2sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
3528 sas_iounit_pg0
, sz
))) {
3529 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3530 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3533 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
3534 MPI2_IOCSTATUS_MASK
;
3535 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
3536 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3537 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3541 /* sas_iounit page 1 */
3542 sz
= offsetof(Mpi2SasIOUnitPage1_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
3543 sizeof(Mpi2SasIOUnit1PhyData_t
));
3544 sas_iounit_pg1
= kzalloc(sz
, GFP_KERNEL
);
3545 if (!sas_iounit_pg1
) {
3546 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3547 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3550 if ((mpt2sas_config_get_sas_iounit_pg1(ioc
, &mpi_reply
,
3551 sas_iounit_pg1
, sz
))) {
3552 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3553 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3556 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
3557 MPI2_IOCSTATUS_MASK
;
3558 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
3559 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3560 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3564 ioc
->io_missing_delay
=
3565 le16_to_cpu(sas_iounit_pg1
->IODeviceMissingDelay
);
3566 device_missing_delay
=
3567 le16_to_cpu(sas_iounit_pg1
->ReportDeviceMissingDelay
);
3568 if (device_missing_delay
& MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16
)
3569 ioc
->device_missing_delay
= (device_missing_delay
&
3570 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
) * 16;
3572 ioc
->device_missing_delay
= device_missing_delay
&
3573 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
;
3575 ioc
->sas_hba
.parent_dev
= &ioc
->shost
->shost_gendev
;
3576 ioc
->sas_hba
.phy
= kcalloc(ioc
->sas_hba
.num_phys
,
3577 sizeof(struct _sas_phy
), GFP_KERNEL
);
3578 if (!ioc
->sas_hba
.phy
) {
3579 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3580 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3583 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
3584 if ((mpt2sas_config_get_phy_pg0(ioc
, &mpi_reply
, &phy_pg0
,
3586 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3587 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3590 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
3591 MPI2_IOCSTATUS_MASK
;
3592 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
3593 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3594 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3599 ioc
->sas_hba
.handle
= le16_to_cpu(sas_iounit_pg0
->
3600 PhyData
[0].ControllerDevHandle
);
3601 ioc
->sas_hba
.phy
[i
].handle
= ioc
->sas_hba
.handle
;
3602 ioc
->sas_hba
.phy
[i
].phy_id
= i
;
3603 mpt2sas_transport_add_host_phy(ioc
, &ioc
->sas_hba
.phy
[i
],
3604 phy_pg0
, ioc
->sas_hba
.parent_dev
);
3606 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
3607 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, ioc
->sas_hba
.handle
))) {
3608 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3609 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3612 ioc
->sas_hba
.enclosure_handle
=
3613 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
3614 ioc
->sas_hba
.sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
3615 printk(MPT2SAS_INFO_FMT
"host_add: handle(0x%04x), "
3616 "sas_addr(0x%016llx), phys(%d)\n", ioc
->name
, ioc
->sas_hba
.handle
,
3617 (unsigned long long) ioc
->sas_hba
.sas_address
,
3618 ioc
->sas_hba
.num_phys
) ;
3620 if (ioc
->sas_hba
.enclosure_handle
) {
3621 if (!(mpt2sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
3623 MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
3624 ioc
->sas_hba
.enclosure_handle
))) {
3625 ioc
->sas_hba
.enclosure_logical_id
=
3626 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
3631 kfree(sas_iounit_pg1
);
3632 kfree(sas_iounit_pg0
);
3636 * _scsih_expander_add - creating expander object
3637 * @ioc: per adapter object
3638 * @handle: expander handle
3640 * Creating expander object, stored in ioc->sas_expander_list.
3642 * Return 0 for success, else error.
3645 _scsih_expander_add(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
3647 struct _sas_node
*sas_expander
;
3648 Mpi2ConfigReply_t mpi_reply
;
3649 Mpi2ExpanderPage0_t expander_pg0
;
3650 Mpi2ExpanderPage1_t expander_pg1
;
3651 Mpi2SasEnclosurePage0_t enclosure_pg0
;
3654 __le64 sas_address
, sas_address_parent
= 0;
3656 unsigned long flags
;
3657 struct _sas_port
*mpt2sas_port
= NULL
;
3663 if (ioc
->shost_recovery
)
3666 if ((mpt2sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
3667 MPI2_SAS_EXPAND_PGAD_FORM_HNDL
, handle
))) {
3668 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3669 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3673 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
3674 MPI2_IOCSTATUS_MASK
;
3675 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
3676 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3677 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3681 /* handle out of order topology events */
3682 parent_handle
= le16_to_cpu(expander_pg0
.ParentDevHandle
);
3683 if (_scsih_get_sas_address(ioc
, parent_handle
, &sas_address_parent
)
3685 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3686 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3689 if (sas_address_parent
!= ioc
->sas_hba
.sas_address
) {
3690 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
3691 sas_expander
= mpt2sas_scsih_expander_find_by_sas_address(ioc
,
3692 sas_address_parent
);
3693 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
3694 if (!sas_expander
) {
3695 rc
= _scsih_expander_add(ioc
, parent_handle
);
3701 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
3702 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
3703 sas_expander
= mpt2sas_scsih_expander_find_by_sas_address(ioc
,
3705 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
3710 sas_expander
= kzalloc(sizeof(struct _sas_node
),
3712 if (!sas_expander
) {
3713 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3714 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3718 sas_expander
->handle
= handle
;
3719 sas_expander
->num_phys
= expander_pg0
.NumPhys
;
3720 sas_expander
->sas_address_parent
= sas_address_parent
;
3721 sas_expander
->sas_address
= sas_address
;
3723 printk(MPT2SAS_INFO_FMT
"expander_add: handle(0x%04x),"
3724 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc
->name
,
3725 handle
, parent_handle
, (unsigned long long)
3726 sas_expander
->sas_address
, sas_expander
->num_phys
);
3728 if (!sas_expander
->num_phys
)
3730 sas_expander
->phy
= kcalloc(sas_expander
->num_phys
,
3731 sizeof(struct _sas_phy
), GFP_KERNEL
);
3732 if (!sas_expander
->phy
) {
3733 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3734 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3739 INIT_LIST_HEAD(&sas_expander
->sas_port_list
);
3740 mpt2sas_port
= mpt2sas_transport_port_add(ioc
, handle
,
3741 sas_address_parent
);
3742 if (!mpt2sas_port
) {
3743 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3744 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3748 sas_expander
->parent_dev
= &mpt2sas_port
->rphy
->dev
;
3750 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++) {
3751 if ((mpt2sas_config_get_expander_pg1(ioc
, &mpi_reply
,
3752 &expander_pg1
, i
, handle
))) {
3753 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3754 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3758 sas_expander
->phy
[i
].handle
= handle
;
3759 sas_expander
->phy
[i
].phy_id
= i
;
3761 if ((mpt2sas_transport_add_expander_phy(ioc
,
3762 &sas_expander
->phy
[i
], expander_pg1
,
3763 sas_expander
->parent_dev
))) {
3764 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3765 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3771 if (sas_expander
->enclosure_handle
) {
3772 if (!(mpt2sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
3773 &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
3774 sas_expander
->enclosure_handle
))) {
3775 sas_expander
->enclosure_logical_id
=
3776 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
3780 _scsih_expander_node_add(ioc
, sas_expander
);
3786 mpt2sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
3787 sas_address_parent
);
3788 kfree(sas_expander
);
3793 * _scsih_done - scsih callback handler.
3794 * @ioc: per adapter object
3795 * @smid: system request message index
3796 * @msix_index: MSIX table index supplied by the OS
3797 * @reply: reply message frame(lower 32bit addr)
3799 * Callback handler when sending internal generated message frames.
3800 * The callback index passed is `ioc->scsih_cb_idx`
3802 * Return 1 meaning mf should be freed from _base_interrupt
3803 * 0 means the mf is freed from this function.
3806 _scsih_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
3808 MPI2DefaultReply_t
*mpi_reply
;
3810 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
3811 if (ioc
->scsih_cmds
.status
== MPT2_CMD_NOT_USED
)
3813 if (ioc
->scsih_cmds
.smid
!= smid
)
3815 ioc
->scsih_cmds
.status
|= MPT2_CMD_COMPLETE
;
3817 memcpy(ioc
->scsih_cmds
.reply
, mpi_reply
,
3818 mpi_reply
->MsgLength
*4);
3819 ioc
->scsih_cmds
.status
|= MPT2_CMD_REPLY_VALID
;
3821 ioc
->scsih_cmds
.status
&= ~MPT2_CMD_PENDING
;
3822 complete(&ioc
->scsih_cmds
.done
);
3827 * _scsih_expander_remove - removing expander object
3828 * @ioc: per adapter object
3829 * @sas_address: expander sas_address
3834 _scsih_expander_remove(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
)
3836 struct _sas_node
*sas_expander
;
3837 unsigned long flags
;
3839 if (ioc
->shost_recovery
)
3842 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
3843 sas_expander
= mpt2sas_scsih_expander_find_by_sas_address(ioc
,
3845 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
3846 _scsih_expander_node_remove(ioc
, sas_expander
);
3850 * _scsih_add_device - creating sas device object
3851 * @ioc: per adapter object
3852 * @handle: sas device handle
3853 * @phy_num: phy number end device attached to
3854 * @is_pd: is this hidden raid component
3856 * Creating end device object, stored in ioc->sas_device_list.
3858 * Returns 0 for success, non-zero for failure.
3861 _scsih_add_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
, u8 phy_num
, u8 is_pd
)
3863 Mpi2ConfigReply_t mpi_reply
;
3864 Mpi2SasDevicePage0_t sas_device_pg0
;
3865 Mpi2SasEnclosurePage0_t enclosure_pg0
;
3866 struct _sas_device
*sas_device
;
3870 unsigned long flags
;
3872 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
3873 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
3874 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3875 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3879 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
3880 MPI2_IOCSTATUS_MASK
;
3881 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
3882 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3883 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3887 /* check if device is present */
3888 if (!(le16_to_cpu(sas_device_pg0
.Flags
) &
3889 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT
)) {
3890 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3891 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3892 printk(MPT2SAS_ERR_FMT
"Flags = 0x%04x\n",
3893 ioc
->name
, le16_to_cpu(sas_device_pg0
.Flags
));
3897 /* check if there were any issus with discovery */
3898 if (sas_device_pg0
.AccessStatus
==
3899 MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED
) {
3900 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3901 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3902 printk(MPT2SAS_ERR_FMT
"AccessStatus = 0x%02x\n",
3903 ioc
->name
, sas_device_pg0
.AccessStatus
);
3907 /* check if this is end device */
3908 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
3909 if (!(_scsih_is_end_device(device_info
))) {
3910 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3911 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3915 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
3917 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
3918 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
3920 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3923 _scsih_ublock_io_device(ioc
, handle
);
3927 sas_device
= kzalloc(sizeof(struct _sas_device
),
3930 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3931 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3935 sas_device
->handle
= handle
;
3936 if (_scsih_get_sas_address(ioc
, le16_to_cpu
3937 (sas_device_pg0
.ParentDevHandle
),
3938 &sas_device
->sas_address_parent
) != 0)
3939 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3940 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3941 sas_device
->enclosure_handle
=
3942 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
3944 le16_to_cpu(sas_device_pg0
.Slot
);
3945 sas_device
->device_info
= device_info
;
3946 sas_device
->sas_address
= sas_address
;
3947 sas_device
->hidden_raid_component
= is_pd
;
3949 /* get enclosure_logical_id */
3950 if (sas_device
->enclosure_handle
&& !(mpt2sas_config_get_enclosure_pg0(
3951 ioc
, &mpi_reply
, &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
3952 sas_device
->enclosure_handle
)))
3953 sas_device
->enclosure_logical_id
=
3954 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
3956 /* get device name */
3957 sas_device
->device_name
= le64_to_cpu(sas_device_pg0
.DeviceName
);
3959 if (ioc
->wait_for_port_enable_to_complete
)
3960 _scsih_sas_device_init_add(ioc
, sas_device
);
3962 _scsih_sas_device_add(ioc
, sas_device
);
3968 * _scsih_remove_device - removing sas device object
3969 * @ioc: per adapter object
3970 * @sas_device: the sas_device object
3975 _scsih_remove_device(struct MPT2SAS_ADAPTER
*ioc
, struct _sas_device
3978 struct MPT2SAS_TARGET
*sas_target_priv_data
;
3979 Mpi2SasIoUnitControlReply_t mpi_reply
;
3980 Mpi2SasIoUnitControlRequest_t mpi_request
;
3981 u16 device_handle
, handle
;
3986 handle
= sas_device
->handle
;
3987 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: enter: handle(0x%04x),"
3988 " sas_addr(0x%016llx)\n", ioc
->name
, __func__
, handle
,
3989 (unsigned long long) sas_device
->sas_address
));
3991 if (sas_device
->starget
&& sas_device
->starget
->hostdata
) {
3992 sas_target_priv_data
= sas_device
->starget
->hostdata
;
3993 sas_target_priv_data
->deleted
= 1;
3996 if (ioc
->remove_host
|| ioc
->shost_recovery
|| !handle
)
3999 if ((sas_device
->state
& MPTSAS_STATE_TR_COMPLETE
)) {
4000 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"\tskip "
4001 "target_reset handle(0x%04x)\n", ioc
->name
,
4006 /* Target Reset to flush out all the outstanding IO */
4007 device_handle
= (sas_device
->hidden_raid_component
) ?
4008 sas_device
->volume_handle
: handle
;
4009 if (device_handle
) {
4010 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"issue target reset: "
4011 "handle(0x%04x)\n", ioc
->name
, device_handle
));
4012 mutex_lock(&ioc
->tm_cmds
.mutex
);
4013 mpt2sas_scsih_issue_tm(ioc
, device_handle
, 0,
4014 MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
, 0, 10);
4015 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
4016 mutex_unlock(&ioc
->tm_cmds
.mutex
);
4017 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"issue target reset "
4018 "done: handle(0x%04x)\n", ioc
->name
, device_handle
));
4019 if (ioc
->shost_recovery
)
4024 if ((sas_device
->state
& MPTSAS_STATE_CNTRL_COMPLETE
)) {
4025 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"\tskip "
4026 "sas_cntrl handle(0x%04x)\n", ioc
->name
, handle
));
4030 /* SAS_IO_UNIT_CNTR - send REMOVE_DEVICE */
4031 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"sas_iounit: handle"
4032 "(0x%04x)\n", ioc
->name
, handle
));
4033 memset(&mpi_request
, 0, sizeof(Mpi2SasIoUnitControlRequest_t
));
4034 mpi_request
.Function
= MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
;
4035 mpi_request
.Operation
= MPI2_SAS_OP_REMOVE_DEVICE
;
4036 mpi_request
.DevHandle
= handle
;
4037 mpi_request
.VF_ID
= 0; /* TODO */
4038 mpi_request
.VP_ID
= 0;
4039 if ((mpt2sas_base_sas_iounit_control(ioc
, &mpi_reply
,
4040 &mpi_request
)) != 0) {
4041 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4042 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4045 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"sas_iounit: ioc_status"
4046 "(0x%04x), loginfo(0x%08x)\n", ioc
->name
,
4047 le16_to_cpu(mpi_reply
.IOCStatus
),
4048 le32_to_cpu(mpi_reply
.IOCLogInfo
)));
4052 _scsih_ublock_io_device(ioc
, handle
);
4054 mpt2sas_transport_port_remove(ioc
, sas_device
->sas_address
,
4055 sas_device
->sas_address_parent
);
4057 printk(MPT2SAS_INFO_FMT
"removing handle(0x%04x), sas_addr"
4058 "(0x%016llx)\n", ioc
->name
, handle
,
4059 (unsigned long long) sas_device
->sas_address
);
4060 _scsih_sas_device_remove(ioc
, sas_device
);
4062 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: exit: handle"
4063 "(0x%04x)\n", ioc
->name
, __func__
, handle
));
4066 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4068 * _scsih_sas_topology_change_event_debug - debug for topology event
4069 * @ioc: per adapter object
4070 * @event_data: event data payload
4074 _scsih_sas_topology_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
4075 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
4081 char *status_str
= NULL
;
4082 u8 link_rate
, prev_link_rate
;
4084 switch (event_data
->ExpStatus
) {
4085 case MPI2_EVENT_SAS_TOPO_ES_ADDED
:
4088 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
:
4089 status_str
= "remove";
4091 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING
:
4093 status_str
= "responding";
4095 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
:
4096 status_str
= "remove delay";
4099 status_str
= "unknown status";
4102 printk(MPT2SAS_DEBUG_FMT
"sas topology change: (%s)\n",
4103 ioc
->name
, status_str
);
4104 printk(KERN_DEBUG
"\thandle(0x%04x), enclosure_handle(0x%04x) "
4105 "start_phy(%02d), count(%d)\n",
4106 le16_to_cpu(event_data
->ExpanderDevHandle
),
4107 le16_to_cpu(event_data
->EnclosureHandle
),
4108 event_data
->StartPhyNum
, event_data
->NumEntries
);
4109 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
4110 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
4113 phy_number
= event_data
->StartPhyNum
+ i
;
4114 reason_code
= event_data
->PHY
[i
].PhyStatus
&
4115 MPI2_EVENT_SAS_TOPO_RC_MASK
;
4116 switch (reason_code
) {
4117 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
4118 status_str
= "target add";
4120 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
4121 status_str
= "target remove";
4123 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
:
4124 status_str
= "delay target remove";
4126 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
4127 status_str
= "link rate change";
4129 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE
:
4130 status_str
= "target responding";
4133 status_str
= "unknown";
4136 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
4137 prev_link_rate
= event_data
->PHY
[i
].LinkRate
& 0xF;
4138 printk(KERN_DEBUG
"\tphy(%02d), attached_handle(0x%04x): %s:"
4139 " link rate: new(0x%02x), old(0x%02x)\n", phy_number
,
4140 handle
, status_str
, link_rate
, prev_link_rate
);
4147 * _scsih_sas_topology_change_event - handle topology changes
4148 * @ioc: per adapter object
4149 * @fw_event: The fw_event_work object
4154 _scsih_sas_topology_change_event(struct MPT2SAS_ADAPTER
*ioc
,
4155 struct fw_event_work
*fw_event
)
4158 u16 parent_handle
, handle
;
4161 struct _sas_node
*sas_expander
;
4162 struct _sas_device
*sas_device
;
4164 unsigned long flags
;
4165 u8 link_rate
, prev_link_rate
;
4166 Mpi2EventDataSasTopologyChangeList_t
*event_data
= fw_event
->event_data
;
4168 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4169 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
4170 _scsih_sas_topology_change_event_debug(ioc
, event_data
);
4173 if (ioc
->shost_recovery
)
4176 if (!ioc
->sas_hba
.num_phys
)
4177 _scsih_sas_host_add(ioc
);
4179 _scsih_sas_host_refresh(ioc
);
4181 if (fw_event
->ignore
) {
4182 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"ignoring expander "
4183 "event\n", ioc
->name
));
4187 parent_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
4189 /* handle expander add */
4190 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_ADDED
)
4191 if (_scsih_expander_add(ioc
, parent_handle
) != 0)
4194 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
4195 sas_expander
= mpt2sas_scsih_expander_find_by_handle(ioc
,
4197 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
4199 sas_address
= sas_expander
->sas_address
;
4200 else if (parent_handle
< ioc
->sas_hba
.num_phys
)
4201 sas_address
= ioc
->sas_hba
.sas_address
;
4205 /* handle siblings events */
4206 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
4207 if (fw_event
->ignore
) {
4208 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"ignoring "
4209 "expander event\n", ioc
->name
));
4212 if (ioc
->shost_recovery
)
4214 phy_number
= event_data
->StartPhyNum
+ i
;
4215 reason_code
= event_data
->PHY
[i
].PhyStatus
&
4216 MPI2_EVENT_SAS_TOPO_RC_MASK
;
4217 if ((event_data
->PHY
[i
].PhyStatus
&
4218 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT
) && (reason_code
!=
4219 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
))
4221 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
4224 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
4225 prev_link_rate
= event_data
->PHY
[i
].LinkRate
& 0xF;
4226 switch (reason_code
) {
4227 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
4229 if (link_rate
== prev_link_rate
)
4232 mpt2sas_transport_update_links(ioc
, sas_address
,
4233 handle
, phy_number
, link_rate
);
4235 if (link_rate
>= MPI2_SAS_NEG_LINK_RATE_1_5
)
4236 _scsih_ublock_io_device(ioc
, handle
);
4238 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
4240 mpt2sas_transport_update_links(ioc
, sas_address
,
4241 handle
, phy_number
, link_rate
);
4243 _scsih_add_device(ioc
, handle
, phy_number
, 0);
4245 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
4247 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4248 sas_device
= _scsih_sas_device_find_by_handle(ioc
,
4251 spin_unlock_irqrestore(&ioc
->sas_device_lock
,
4255 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4256 _scsih_remove_device(ioc
, sas_device
);
4261 /* handle expander removal */
4262 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
&&
4264 _scsih_expander_remove(ioc
, sas_address
);
4268 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4270 * _scsih_sas_device_status_change_event_debug - debug for device event
4271 * @event_data: event data payload
4277 _scsih_sas_device_status_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
4278 Mpi2EventDataSasDeviceStatusChange_t
*event_data
)
4280 char *reason_str
= NULL
;
4282 switch (event_data
->ReasonCode
) {
4283 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
:
4284 reason_str
= "smart data";
4286 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED
:
4287 reason_str
= "unsupported device discovered";
4289 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
:
4290 reason_str
= "internal device reset";
4292 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL
:
4293 reason_str
= "internal task abort";
4295 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL
:
4296 reason_str
= "internal task abort set";
4298 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL
:
4299 reason_str
= "internal clear task set";
4301 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL
:
4302 reason_str
= "internal query task";
4304 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE
:
4305 reason_str
= "sata init failure";
4307 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
:
4308 reason_str
= "internal device reset complete";
4310 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL
:
4311 reason_str
= "internal task abort complete";
4313 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION
:
4314 reason_str
= "internal async notification";
4316 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY
:
4317 reason_str
= "expander reduced functionality";
4319 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY
:
4320 reason_str
= "expander reduced functionality complete";
4323 reason_str
= "unknown reason";
4326 printk(MPT2SAS_DEBUG_FMT
"device status change: (%s)\n"
4327 "\thandle(0x%04x), sas address(0x%016llx)", ioc
->name
,
4328 reason_str
, le16_to_cpu(event_data
->DevHandle
),
4329 (unsigned long long)le64_to_cpu(event_data
->SASAddress
));
4330 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
)
4331 printk(MPT2SAS_DEBUG_FMT
", ASC(0x%x), ASCQ(0x%x)\n", ioc
->name
,
4332 event_data
->ASC
, event_data
->ASCQ
);
4333 printk(KERN_INFO
"\n");
4338 * _scsih_sas_device_status_change_event - handle device status change
4339 * @ioc: per adapter object
4340 * @fw_event: The fw_event_work object
4346 _scsih_sas_device_status_change_event(struct MPT2SAS_ADAPTER
*ioc
,
4347 struct fw_event_work
*fw_event
)
4349 struct MPT2SAS_TARGET
*target_priv_data
;
4350 struct _sas_device
*sas_device
;
4352 unsigned long flags
;
4353 Mpi2EventDataSasDeviceStatusChange_t
*event_data
=
4354 fw_event
->event_data
;
4356 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4357 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
4358 _scsih_sas_device_status_change_event_debug(ioc
,
4362 if (!(event_data
->ReasonCode
==
4363 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
&&
4364 event_data
->ReasonCode
==
4365 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
))
4368 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4369 sas_address
= le64_to_cpu(event_data
->SASAddress
);
4370 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
4372 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4374 if (!sas_device
|| !sas_device
->starget
)
4377 target_priv_data
= sas_device
->starget
->hostdata
;
4378 if (!target_priv_data
)
4381 if (event_data
->ReasonCode
==
4382 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
)
4383 target_priv_data
->tm_busy
= 1;
4385 target_priv_data
->tm_busy
= 0;
4388 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4390 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure event
4391 * @ioc: per adapter object
4392 * @event_data: event data payload
4398 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
4399 Mpi2EventDataSasEnclDevStatusChange_t
*event_data
)
4401 char *reason_str
= NULL
;
4403 switch (event_data
->ReasonCode
) {
4404 case MPI2_EVENT_SAS_ENCL_RC_ADDED
:
4405 reason_str
= "enclosure add";
4407 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING
:
4408 reason_str
= "enclosure remove";
4411 reason_str
= "unknown reason";
4415 printk(MPT2SAS_DEBUG_FMT
"enclosure status change: (%s)\n"
4416 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
4417 " number slots(%d)\n", ioc
->name
, reason_str
,
4418 le16_to_cpu(event_data
->EnclosureHandle
),
4419 (unsigned long long)le64_to_cpu(event_data
->EnclosureLogicalID
),
4420 le16_to_cpu(event_data
->StartSlot
));
4425 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
4426 * @ioc: per adapter object
4427 * @fw_event: The fw_event_work object
4433 _scsih_sas_enclosure_dev_status_change_event(struct MPT2SAS_ADAPTER
*ioc
,
4434 struct fw_event_work
*fw_event
)
4436 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4437 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
4438 _scsih_sas_enclosure_dev_status_change_event_debug(ioc
,
4439 fw_event
->event_data
);
4444 * _scsih_sas_broadcast_primative_event - handle broadcast events
4445 * @ioc: per adapter object
4446 * @fw_event: The fw_event_work object
4452 _scsih_sas_broadcast_primative_event(struct MPT2SAS_ADAPTER
*ioc
,
4453 struct fw_event_work
*fw_event
)
4455 struct scsi_cmnd
*scmd
;
4458 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
4459 u32 termination_count
;
4461 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
4462 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4463 Mpi2EventDataSasBroadcastPrimitive_t
*event_data
= fw_event
->event_data
;
4466 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"broadcast primative: "
4467 "phy number(%d), width(%d)\n", ioc
->name
, event_data
->PhyNum
,
4468 event_data
->PortWidth
));
4469 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: enter\n", ioc
->name
,
4472 mutex_lock(&ioc
->tm_cmds
.mutex
);
4473 termination_count
= 0;
4475 mpi_reply
= ioc
->tm_cmds
.reply
;
4476 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
4477 scmd
= _scsih_scsi_lookup_get(ioc
, smid
);
4480 sas_device_priv_data
= scmd
->device
->hostdata
;
4481 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
)
4483 /* skip hidden raid components */
4484 if (sas_device_priv_data
->sas_target
->flags
&
4485 MPT_TARGET_FLAGS_RAID_COMPONENT
)
4488 if (sas_device_priv_data
->sas_target
->flags
&
4489 MPT_TARGET_FLAGS_VOLUME
)
4492 handle
= sas_device_priv_data
->sas_target
->handle
;
4493 lun
= sas_device_priv_data
->lun
;
4496 mpt2sas_scsih_issue_tm(ioc
, handle
, lun
,
4497 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK
, smid
, 30);
4498 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
4499 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
)
4500 & MPI2_IOCSTATUS_MASK
;
4501 if ((ioc_status
== MPI2_IOCSTATUS_SUCCESS
) &&
4502 (mpi_reply
->ResponseCode
==
4503 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
||
4504 mpi_reply
->ResponseCode
==
4505 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
))
4508 mpt2sas_scsih_issue_tm(ioc
, handle
, lun
,
4509 MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET
, 0, 30);
4510 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
4511 termination_count
+= le32_to_cpu(mpi_reply
->TerminationCount
);
4513 ioc
->broadcast_aen_busy
= 0;
4514 mutex_unlock(&ioc
->tm_cmds
.mutex
);
4516 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
4517 "%s - exit, query_count = %d termination_count = %d\n",
4518 ioc
->name
, __func__
, query_count
, termination_count
));
4522 * _scsih_sas_discovery_event - handle discovery events
4523 * @ioc: per adapter object
4524 * @fw_event: The fw_event_work object
4530 _scsih_sas_discovery_event(struct MPT2SAS_ADAPTER
*ioc
,
4531 struct fw_event_work
*fw_event
)
4533 Mpi2EventDataSasDiscovery_t
*event_data
= fw_event
->event_data
;
4535 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4536 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
) {
4537 printk(MPT2SAS_DEBUG_FMT
"discovery event: (%s)", ioc
->name
,
4538 (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
) ?
4540 if (event_data
->DiscoveryStatus
)
4541 printk("discovery_status(0x%08x)",
4542 le32_to_cpu(event_data
->DiscoveryStatus
));
4547 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
&&
4548 !ioc
->sas_hba
.num_phys
)
4549 _scsih_sas_host_add(ioc
);
4553 * _scsih_reprobe_lun - reprobing lun
4554 * @sdev: scsi device struct
4555 * @no_uld_attach: sdev->no_uld_attach flag setting
4559 _scsih_reprobe_lun(struct scsi_device
*sdev
, void *no_uld_attach
)
4563 sdev
->no_uld_attach
= no_uld_attach
? 1 : 0;
4564 sdev_printk(KERN_INFO
, sdev
, "%s raid component\n",
4565 sdev
->no_uld_attach
? "hidding" : "exposing");
4566 rc
= scsi_device_reprobe(sdev
);
4570 * _scsih_reprobe_target - reprobing target
4571 * @starget: scsi target struct
4572 * @no_uld_attach: sdev->no_uld_attach flag setting
4574 * Note: no_uld_attach flag determines whether the disk device is attached
4575 * to block layer. A value of `1` means to not attach.
4578 _scsih_reprobe_target(struct scsi_target
*starget
, int no_uld_attach
)
4580 struct MPT2SAS_TARGET
*sas_target_priv_data
= starget
->hostdata
;
4583 sas_target_priv_data
->flags
|= MPT_TARGET_FLAGS_RAID_COMPONENT
;
4585 sas_target_priv_data
->flags
&= ~MPT_TARGET_FLAGS_RAID_COMPONENT
;
4587 starget_for_each_device(starget
, no_uld_attach
? (void *)1 : NULL
,
4588 _scsih_reprobe_lun
);
4591 * _scsih_sas_volume_add - add new volume
4592 * @ioc: per adapter object
4593 * @element: IR config element data
4599 _scsih_sas_volume_add(struct MPT2SAS_ADAPTER
*ioc
,
4600 Mpi2EventIrConfigElement_t
*element
)
4602 struct _raid_device
*raid_device
;
4603 unsigned long flags
;
4605 u16 handle
= le16_to_cpu(element
->VolDevHandle
);
4608 mpt2sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
4610 printk(MPT2SAS_ERR_FMT
4611 "failure at %s:%d/%s()!\n", ioc
->name
,
4612 __FILE__
, __LINE__
, __func__
);
4616 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
4617 raid_device
= _scsih_raid_device_find_by_wwid(ioc
, wwid
);
4618 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
4623 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
4625 printk(MPT2SAS_ERR_FMT
4626 "failure at %s:%d/%s()!\n", ioc
->name
,
4627 __FILE__
, __LINE__
, __func__
);
4631 raid_device
->id
= ioc
->sas_id
++;
4632 raid_device
->channel
= RAID_CHANNEL
;
4633 raid_device
->handle
= handle
;
4634 raid_device
->wwid
= wwid
;
4635 _scsih_raid_device_add(ioc
, raid_device
);
4636 if (!ioc
->wait_for_port_enable_to_complete
) {
4637 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
4638 raid_device
->id
, 0);
4640 _scsih_raid_device_remove(ioc
, raid_device
);
4642 _scsih_determine_boot_device(ioc
, raid_device
, 1);
4646 * _scsih_sas_volume_delete - delete volume
4647 * @ioc: per adapter object
4648 * @element: IR config element data
4654 _scsih_sas_volume_delete(struct MPT2SAS_ADAPTER
*ioc
,
4655 Mpi2EventIrConfigElement_t
*element
)
4657 struct _raid_device
*raid_device
;
4658 u16 handle
= le16_to_cpu(element
->VolDevHandle
);
4659 unsigned long flags
;
4660 struct MPT2SAS_TARGET
*sas_target_priv_data
;
4662 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
4663 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
4664 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
4667 if (raid_device
->starget
) {
4668 sas_target_priv_data
= raid_device
->starget
->hostdata
;
4669 sas_target_priv_data
->deleted
= 1;
4670 scsi_remove_target(&raid_device
->starget
->dev
);
4672 _scsih_raid_device_remove(ioc
, raid_device
);
4676 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
4677 * @ioc: per adapter object
4678 * @element: IR config element data
4684 _scsih_sas_pd_expose(struct MPT2SAS_ADAPTER
*ioc
,
4685 Mpi2EventIrConfigElement_t
*element
)
4687 struct _sas_device
*sas_device
;
4688 unsigned long flags
;
4689 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
4691 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4692 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
4693 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4697 /* exposing raid component */
4698 sas_device
->volume_handle
= 0;
4699 sas_device
->volume_wwid
= 0;
4700 sas_device
->hidden_raid_component
= 0;
4701 _scsih_reprobe_target(sas_device
->starget
, 0);
4705 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
4706 * @ioc: per adapter object
4707 * @element: IR config element data
4713 _scsih_sas_pd_hide(struct MPT2SAS_ADAPTER
*ioc
,
4714 Mpi2EventIrConfigElement_t
*element
)
4716 struct _sas_device
*sas_device
;
4717 unsigned long flags
;
4718 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
4720 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4721 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
4722 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4726 /* hiding raid component */
4727 mpt2sas_config_get_volume_handle(ioc
, handle
,
4728 &sas_device
->volume_handle
);
4729 mpt2sas_config_get_volume_wwid(ioc
, sas_device
->volume_handle
,
4730 &sas_device
->volume_wwid
);
4731 sas_device
->hidden_raid_component
= 1;
4732 _scsih_reprobe_target(sas_device
->starget
, 1);
4736 * _scsih_sas_pd_delete - delete pd component
4737 * @ioc: per adapter object
4738 * @element: IR config element data
4744 _scsih_sas_pd_delete(struct MPT2SAS_ADAPTER
*ioc
,
4745 Mpi2EventIrConfigElement_t
*element
)
4747 struct _sas_device
*sas_device
;
4748 unsigned long flags
;
4749 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
4751 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4752 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
4753 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4756 _scsih_remove_device(ioc
, sas_device
);
4760 * _scsih_sas_pd_add - remove pd component
4761 * @ioc: per adapter object
4762 * @element: IR config element data
4768 _scsih_sas_pd_add(struct MPT2SAS_ADAPTER
*ioc
,
4769 Mpi2EventIrConfigElement_t
*element
)
4771 struct _sas_device
*sas_device
;
4772 unsigned long flags
;
4773 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
4774 Mpi2ConfigReply_t mpi_reply
;
4775 Mpi2SasDevicePage0_t sas_device_pg0
;
4780 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4781 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
4782 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4784 sas_device
->hidden_raid_component
= 1;
4788 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
4789 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
4790 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4791 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4795 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4796 MPI2_IOCSTATUS_MASK
;
4797 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4798 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4799 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4803 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
4804 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
4805 mpt2sas_transport_update_links(ioc
, sas_address
, handle
,
4806 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
4808 _scsih_add_device(ioc
, handle
, 0, 1);
4811 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4813 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
4814 * @ioc: per adapter object
4815 * @event_data: event data payload
4821 _scsih_sas_ir_config_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
4822 Mpi2EventDataIrConfigChangeList_t
*event_data
)
4824 Mpi2EventIrConfigElement_t
*element
;
4827 char *reason_str
= NULL
, *element_str
= NULL
;
4829 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
4831 printk(MPT2SAS_DEBUG_FMT
"raid config change: (%s), elements(%d)\n",
4832 ioc
->name
, (le32_to_cpu(event_data
->Flags
) &
4833 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ?
4834 "foreign" : "native", event_data
->NumElements
);
4835 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
4836 switch (element
->ReasonCode
) {
4837 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
4840 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
4841 reason_str
= "remove";
4843 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE
:
4844 reason_str
= "no change";
4846 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
4847 reason_str
= "hide";
4849 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
4850 reason_str
= "unhide";
4852 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
4853 reason_str
= "volume_created";
4855 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
4856 reason_str
= "volume_deleted";
4858 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
4859 reason_str
= "pd_created";
4861 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
4862 reason_str
= "pd_deleted";
4865 reason_str
= "unknown reason";
4868 element_type
= le16_to_cpu(element
->ElementFlags
) &
4869 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK
;
4870 switch (element_type
) {
4871 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT
:
4872 element_str
= "volume";
4874 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT
:
4875 element_str
= "phys disk";
4877 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT
:
4878 element_str
= "hot spare";
4881 element_str
= "unknown element";
4884 printk(KERN_DEBUG
"\t(%s:%s), vol handle(0x%04x), "
4885 "pd handle(0x%04x), pd num(0x%02x)\n", element_str
,
4886 reason_str
, le16_to_cpu(element
->VolDevHandle
),
4887 le16_to_cpu(element
->PhysDiskDevHandle
),
4888 element
->PhysDiskNum
);
4894 * _scsih_sas_ir_config_change_event - handle ir configuration change events
4895 * @ioc: per adapter object
4896 * @fw_event: The fw_event_work object
4902 _scsih_sas_ir_config_change_event(struct MPT2SAS_ADAPTER
*ioc
,
4903 struct fw_event_work
*fw_event
)
4905 Mpi2EventIrConfigElement_t
*element
;
4908 Mpi2EventDataIrConfigChangeList_t
*event_data
= fw_event
->event_data
;
4910 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4911 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
4912 _scsih_sas_ir_config_change_event_debug(ioc
, event_data
);
4915 foreign_config
= (le32_to_cpu(event_data
->Flags
) &
4916 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ? 1 : 0;
4918 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
4919 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
4921 switch (element
->ReasonCode
) {
4922 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
4923 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
4924 if (!foreign_config
)
4925 _scsih_sas_volume_add(ioc
, element
);
4927 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
4928 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
4929 if (!foreign_config
)
4930 _scsih_sas_volume_delete(ioc
, element
);
4932 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
4933 _scsih_sas_pd_hide(ioc
, element
);
4935 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
4936 _scsih_sas_pd_expose(ioc
, element
);
4938 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
4939 _scsih_sas_pd_add(ioc
, element
);
4941 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
4942 _scsih_sas_pd_delete(ioc
, element
);
4949 * _scsih_sas_ir_volume_event - IR volume event
4950 * @ioc: per adapter object
4951 * @fw_event: The fw_event_work object
4957 _scsih_sas_ir_volume_event(struct MPT2SAS_ADAPTER
*ioc
,
4958 struct fw_event_work
*fw_event
)
4961 unsigned long flags
;
4962 struct _raid_device
*raid_device
;
4966 struct MPT2SAS_TARGET
*sas_target_priv_data
;
4967 Mpi2EventDataIrVolume_t
*event_data
= fw_event
->event_data
;
4969 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED
)
4972 handle
= le16_to_cpu(event_data
->VolDevHandle
);
4973 state
= le32_to_cpu(event_data
->NewValue
);
4974 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: handle(0x%04x), "
4975 "old(0x%08x), new(0x%08x)\n", ioc
->name
, __func__
, handle
,
4976 le32_to_cpu(event_data
->PreviousValue
), state
));
4978 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
4979 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
4980 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
4983 case MPI2_RAID_VOL_STATE_MISSING
:
4984 case MPI2_RAID_VOL_STATE_FAILED
:
4987 if (raid_device
->starget
) {
4988 sas_target_priv_data
= raid_device
->starget
->hostdata
;
4989 sas_target_priv_data
->deleted
= 1;
4990 scsi_remove_target(&raid_device
->starget
->dev
);
4992 _scsih_raid_device_remove(ioc
, raid_device
);
4995 case MPI2_RAID_VOL_STATE_ONLINE
:
4996 case MPI2_RAID_VOL_STATE_DEGRADED
:
4997 case MPI2_RAID_VOL_STATE_OPTIMAL
:
5001 mpt2sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
5003 printk(MPT2SAS_ERR_FMT
5004 "failure at %s:%d/%s()!\n", ioc
->name
,
5005 __FILE__
, __LINE__
, __func__
);
5009 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
5011 printk(MPT2SAS_ERR_FMT
5012 "failure at %s:%d/%s()!\n", ioc
->name
,
5013 __FILE__
, __LINE__
, __func__
);
5017 raid_device
->id
= ioc
->sas_id
++;
5018 raid_device
->channel
= RAID_CHANNEL
;
5019 raid_device
->handle
= handle
;
5020 raid_device
->wwid
= wwid
;
5021 _scsih_raid_device_add(ioc
, raid_device
);
5022 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
5023 raid_device
->id
, 0);
5025 _scsih_raid_device_remove(ioc
, raid_device
);
5028 case MPI2_RAID_VOL_STATE_INITIALIZING
:
5035 * _scsih_sas_ir_physical_disk_event - PD event
5036 * @ioc: per adapter object
5037 * @fw_event: The fw_event_work object
5043 _scsih_sas_ir_physical_disk_event(struct MPT2SAS_ADAPTER
*ioc
,
5044 struct fw_event_work
*fw_event
)
5046 u16 handle
, parent_handle
;
5048 struct _sas_device
*sas_device
;
5049 unsigned long flags
;
5050 Mpi2ConfigReply_t mpi_reply
;
5051 Mpi2SasDevicePage0_t sas_device_pg0
;
5053 Mpi2EventDataIrPhysicalDisk_t
*event_data
= fw_event
->event_data
;
5056 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED
)
5059 handle
= le16_to_cpu(event_data
->PhysDiskDevHandle
);
5060 state
= le32_to_cpu(event_data
->NewValue
);
5062 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: handle(0x%04x), "
5063 "old(0x%08x), new(0x%08x)\n", ioc
->name
, __func__
, handle
,
5064 le32_to_cpu(event_data
->PreviousValue
), state
));
5066 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5067 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
5068 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5071 case MPI2_RAID_PD_STATE_ONLINE
:
5072 case MPI2_RAID_PD_STATE_DEGRADED
:
5073 case MPI2_RAID_PD_STATE_REBUILDING
:
5074 case MPI2_RAID_PD_STATE_OPTIMAL
:
5076 sas_device
->hidden_raid_component
= 1;
5080 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
5081 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
5083 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5084 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5088 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5089 MPI2_IOCSTATUS_MASK
;
5090 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5091 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5092 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5096 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
5097 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
5098 mpt2sas_transport_update_links(ioc
, sas_address
, handle
,
5099 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
5101 _scsih_add_device(ioc
, handle
, 0, 1);
5105 case MPI2_RAID_PD_STATE_OFFLINE
:
5106 case MPI2_RAID_PD_STATE_NOT_CONFIGURED
:
5107 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE
:
5108 case MPI2_RAID_PD_STATE_HOT_SPARE
:
5114 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5116 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
5117 * @ioc: per adapter object
5118 * @event_data: event data payload
5124 _scsih_sas_ir_operation_status_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
5125 Mpi2EventDataIrOperationStatus_t
*event_data
)
5127 char *reason_str
= NULL
;
5129 switch (event_data
->RAIDOperation
) {
5130 case MPI2_EVENT_IR_RAIDOP_RESYNC
:
5131 reason_str
= "resync";
5133 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION
:
5134 reason_str
= "online capacity expansion";
5136 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK
:
5137 reason_str
= "consistency check";
5139 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT
:
5140 reason_str
= "background init";
5142 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT
:
5143 reason_str
= "make data consistent";
5150 printk(MPT2SAS_INFO_FMT
"raid operational status: (%s)"
5151 "\thandle(0x%04x), percent complete(%d)\n",
5152 ioc
->name
, reason_str
,
5153 le16_to_cpu(event_data
->VolDevHandle
),
5154 event_data
->PercentComplete
);
5159 * _scsih_sas_ir_operation_status_event - handle RAID operation events
5160 * @ioc: per adapter object
5161 * @fw_event: The fw_event_work object
5167 _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER
*ioc
,
5168 struct fw_event_work
*fw_event
)
5170 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5171 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5172 _scsih_sas_ir_operation_status_event_debug(ioc
,
5173 fw_event
->event_data
);
5178 * _scsih_task_set_full - handle task set full
5179 * @ioc: per adapter object
5180 * @fw_event: The fw_event_work object
5183 * Throttle back qdepth.
5186 _scsih_task_set_full(struct MPT2SAS_ADAPTER
*ioc
, struct fw_event_work
5189 unsigned long flags
;
5190 struct _sas_device
*sas_device
;
5191 static struct _raid_device
*raid_device
;
5192 struct scsi_device
*sdev
;
5198 Mpi2EventDataTaskSetFull_t
*event_data
= fw_event
->event_data
;
5200 current_depth
= le16_to_cpu(event_data
->CurrentDepth
);
5201 handle
= le16_to_cpu(event_data
->DevHandle
);
5202 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5203 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
5205 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5208 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5209 id
= sas_device
->id
;
5210 channel
= sas_device
->channel
;
5211 sas_address
= sas_device
->sas_address
;
5213 /* if hidden raid component, then change to volume characteristics */
5214 if (sas_device
->hidden_raid_component
&& sas_device
->volume_handle
) {
5215 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5216 raid_device
= _scsih_raid_device_find_by_handle(
5217 ioc
, sas_device
->volume_handle
);
5218 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5220 id
= raid_device
->id
;
5221 channel
= raid_device
->channel
;
5222 handle
= raid_device
->handle
;
5223 sas_address
= raid_device
->wwid
;
5227 if (ioc
->logging_level
& MPT_DEBUG_TASK_SET_FULL
)
5228 starget_printk(KERN_DEBUG
, sas_device
->starget
, "task set "
5229 "full: handle(0x%04x), sas_addr(0x%016llx), depth(%d)\n",
5230 handle
, (unsigned long long)sas_address
, current_depth
);
5232 shost_for_each_device(sdev
, ioc
->shost
) {
5233 if (sdev
->id
== id
&& sdev
->channel
== channel
) {
5234 if (current_depth
> sdev
->queue_depth
) {
5235 if (ioc
->logging_level
&
5236 MPT_DEBUG_TASK_SET_FULL
)
5237 sdev_printk(KERN_INFO
, sdev
, "strange "
5238 "observation, the queue depth is"
5239 " (%d) meanwhile fw queue depth "
5240 "is (%d)\n", sdev
->queue_depth
,
5244 depth
= scsi_track_queue_full(sdev
,
5247 sdev_printk(KERN_INFO
, sdev
, "Queue depth "
5248 "reduced to (%d)\n", depth
);
5250 sdev_printk(KERN_INFO
, sdev
, "Tagged Command "
5251 "Queueing is being disabled\n");
5252 else if (depth
== 0)
5253 if (ioc
->logging_level
&
5254 MPT_DEBUG_TASK_SET_FULL
)
5255 sdev_printk(KERN_INFO
, sdev
,
5256 "Queue depth not changed yet\n");
5262 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
5263 * @ioc: per adapter object
5264 * @sas_address: sas address
5265 * @slot: enclosure slot id
5266 * @handle: device handle
5268 * After host reset, find out whether devices are still responding.
5269 * Used in _scsi_remove_unresponsive_sas_devices.
5274 _scsih_mark_responding_sas_device(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
,
5275 u16 slot
, u16 handle
)
5277 struct MPT2SAS_TARGET
*sas_target_priv_data
;
5278 struct scsi_target
*starget
;
5279 struct _sas_device
*sas_device
;
5280 unsigned long flags
;
5282 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5283 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
) {
5284 if (sas_device
->sas_address
== sas_address
&&
5285 sas_device
->slot
== slot
&& sas_device
->starget
) {
5286 sas_device
->responding
= 1;
5287 sas_device
->state
= 0;
5288 starget
= sas_device
->starget
;
5289 sas_target_priv_data
= starget
->hostdata
;
5290 sas_target_priv_data
->tm_busy
= 0;
5291 starget_printk(KERN_INFO
, sas_device
->starget
,
5292 "handle(0x%04x), sas_addr(0x%016llx), enclosure "
5293 "logical id(0x%016llx), slot(%d)\n", handle
,
5294 (unsigned long long)sas_device
->sas_address
,
5295 (unsigned long long)
5296 sas_device
->enclosure_logical_id
,
5298 if (sas_device
->handle
== handle
)
5300 printk(KERN_INFO
"\thandle changed from(0x%04x)!!!\n",
5301 sas_device
->handle
);
5302 sas_device
->handle
= handle
;
5303 sas_target_priv_data
->handle
= handle
;
5308 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5312 * _scsih_search_responding_sas_devices -
5313 * @ioc: per adapter object
5315 * After host reset, find out whether devices are still responding.
5321 _scsih_search_responding_sas_devices(struct MPT2SAS_ADAPTER
*ioc
)
5323 Mpi2SasDevicePage0_t sas_device_pg0
;
5324 Mpi2ConfigReply_t mpi_reply
;
5331 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
, __func__
);
5333 if (list_empty(&ioc
->sas_device_list
))
5337 while (!(mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
5338 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
,
5340 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5341 MPI2_IOCSTATUS_MASK
;
5342 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
5344 handle
= le16_to_cpu(sas_device_pg0
.DevHandle
);
5345 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
5346 if (!(_scsih_is_end_device(device_info
)))
5348 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
5349 slot
= le16_to_cpu(sas_device_pg0
.Slot
);
5350 _scsih_mark_responding_sas_device(ioc
, sas_address
, slot
,
5356 * _scsih_mark_responding_raid_device - mark a raid_device as responding
5357 * @ioc: per adapter object
5358 * @wwid: world wide identifier for raid volume
5359 * @handle: device handle
5361 * After host reset, find out whether devices are still responding.
5362 * Used in _scsi_remove_unresponsive_raid_devices.
5367 _scsih_mark_responding_raid_device(struct MPT2SAS_ADAPTER
*ioc
, u64 wwid
,
5370 struct MPT2SAS_TARGET
*sas_target_priv_data
;
5371 struct scsi_target
*starget
;
5372 struct _raid_device
*raid_device
;
5373 unsigned long flags
;
5375 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5376 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
5377 if (raid_device
->wwid
== wwid
&& raid_device
->starget
) {
5378 raid_device
->responding
= 1;
5379 starget_printk(KERN_INFO
, raid_device
->starget
,
5380 "handle(0x%04x), wwid(0x%016llx)\n", handle
,
5381 (unsigned long long)raid_device
->wwid
);
5382 if (raid_device
->handle
== handle
)
5384 printk(KERN_INFO
"\thandle changed from(0x%04x)!!!\n",
5385 raid_device
->handle
);
5386 raid_device
->handle
= handle
;
5387 starget
= raid_device
->starget
;
5388 sas_target_priv_data
= starget
->hostdata
;
5389 sas_target_priv_data
->handle
= handle
;
5394 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5398 * _scsih_search_responding_raid_devices -
5399 * @ioc: per adapter object
5401 * After host reset, find out whether devices are still responding.
5407 _scsih_search_responding_raid_devices(struct MPT2SAS_ADAPTER
*ioc
)
5409 Mpi2RaidVolPage1_t volume_pg1
;
5410 Mpi2ConfigReply_t mpi_reply
;
5414 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
, __func__
);
5416 if (list_empty(&ioc
->raid_device_list
))
5420 while (!(mpt2sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
5421 &volume_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
5422 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5423 MPI2_IOCSTATUS_MASK
;
5424 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
5426 handle
= le16_to_cpu(volume_pg1
.DevHandle
);
5427 _scsih_mark_responding_raid_device(ioc
,
5428 le64_to_cpu(volume_pg1
.WWID
), handle
);
5433 * _scsih_mark_responding_expander - mark a expander as responding
5434 * @ioc: per adapter object
5435 * @sas_address: sas address
5438 * After host reset, find out whether devices are still responding.
5439 * Used in _scsi_remove_unresponsive_expanders.
5444 _scsih_mark_responding_expander(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
,
5447 struct _sas_node
*sas_expander
;
5448 unsigned long flags
;
5451 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5452 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
5453 if (sas_expander
->sas_address
!= sas_address
)
5455 sas_expander
->responding
= 1;
5456 if (sas_expander
->handle
== handle
)
5458 printk(KERN_INFO
"\texpander(0x%016llx): handle changed"
5459 " from(0x%04x) to (0x%04x)!!!\n",
5460 (unsigned long long)sas_expander
->sas_address
,
5461 sas_expander
->handle
, handle
);
5462 sas_expander
->handle
= handle
;
5463 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++)
5464 sas_expander
->phy
[i
].handle
= handle
;
5468 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5472 * _scsih_search_responding_expanders -
5473 * @ioc: per adapter object
5475 * After host reset, find out whether devices are still responding.
5481 _scsih_search_responding_expanders(struct MPT2SAS_ADAPTER
*ioc
)
5483 Mpi2ExpanderPage0_t expander_pg0
;
5484 Mpi2ConfigReply_t mpi_reply
;
5489 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
, __func__
);
5491 if (list_empty(&ioc
->sas_expander_list
))
5495 while (!(mpt2sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
5496 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL
, handle
))) {
5498 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5499 MPI2_IOCSTATUS_MASK
;
5500 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
5503 handle
= le16_to_cpu(expander_pg0
.DevHandle
);
5504 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
5505 printk(KERN_INFO
"\texpander present: handle(0x%04x), "
5506 "sas_addr(0x%016llx)\n", handle
,
5507 (unsigned long long)sas_address
);
5508 _scsih_mark_responding_expander(ioc
, sas_address
, handle
);
5514 * _scsih_remove_unresponding_devices - removing unresponding devices
5515 * @ioc: per adapter object
5520 _scsih_remove_unresponding_devices(struct MPT2SAS_ADAPTER
*ioc
)
5522 struct _sas_device
*sas_device
, *sas_device_next
;
5523 struct _sas_node
*sas_expander
;
5524 struct _raid_device
*raid_device
, *raid_device_next
;
5527 list_for_each_entry_safe(sas_device
, sas_device_next
,
5528 &ioc
->sas_device_list
, list
) {
5529 if (sas_device
->responding
) {
5530 sas_device
->responding
= 0;
5533 if (sas_device
->starget
)
5534 starget_printk(KERN_INFO
, sas_device
->starget
,
5535 "removing: handle(0x%04x), sas_addr(0x%016llx), "
5536 "enclosure logical id(0x%016llx), slot(%d)\n",
5538 (unsigned long long)sas_device
->sas_address
,
5539 (unsigned long long)
5540 sas_device
->enclosure_logical_id
,
5542 /* invalidate the device handle */
5543 sas_device
->handle
= 0;
5544 _scsih_remove_device(ioc
, sas_device
);
5547 list_for_each_entry_safe(raid_device
, raid_device_next
,
5548 &ioc
->raid_device_list
, list
) {
5549 if (raid_device
->responding
) {
5550 raid_device
->responding
= 0;
5553 if (raid_device
->starget
) {
5554 starget_printk(KERN_INFO
, raid_device
->starget
,
5555 "removing: handle(0x%04x), wwid(0x%016llx)\n",
5556 raid_device
->handle
,
5557 (unsigned long long)raid_device
->wwid
);
5558 scsi_remove_target(&raid_device
->starget
->dev
);
5560 _scsih_raid_device_remove(ioc
, raid_device
);
5563 retry_expander_search
:
5564 sas_expander
= NULL
;
5565 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
5566 if (sas_expander
->responding
) {
5567 sas_expander
->responding
= 0;
5570 _scsih_expander_remove(ioc
, sas_expander
->sas_address
);
5571 goto retry_expander_search
;
5576 * mpt2sas_scsih_reset_handler - reset callback handler (for scsih)
5577 * @ioc: per adapter object
5578 * @reset_phase: phase
5580 * The handler for doing any required cleanup or initialization.
5582 * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
5583 * MPT2_IOC_DONE_RESET
5588 mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER
*ioc
, int reset_phase
)
5590 switch (reset_phase
) {
5591 case MPT2_IOC_PRE_RESET
:
5592 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: "
5593 "MPT2_IOC_PRE_RESET\n", ioc
->name
, __func__
));
5594 _scsih_fw_event_off(ioc
);
5596 case MPT2_IOC_AFTER_RESET
:
5597 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: "
5598 "MPT2_IOC_AFTER_RESET\n", ioc
->name
, __func__
));
5599 if (ioc
->tm_cmds
.status
& MPT2_CMD_PENDING
) {
5600 ioc
->tm_cmds
.status
|= MPT2_CMD_RESET
;
5601 mpt2sas_base_free_smid(ioc
, ioc
->tm_cmds
.smid
);
5602 complete(&ioc
->tm_cmds
.done
);
5604 _scsih_fw_event_on(ioc
);
5605 _scsih_flush_running_cmds(ioc
);
5607 case MPT2_IOC_DONE_RESET
:
5608 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: "
5609 "MPT2_IOC_DONE_RESET\n", ioc
->name
, __func__
));
5610 _scsih_sas_host_refresh(ioc
);
5611 _scsih_search_responding_sas_devices(ioc
);
5612 _scsih_search_responding_raid_devices(ioc
);
5613 _scsih_search_responding_expanders(ioc
);
5615 case MPT2_IOC_RUNNING
:
5616 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: "
5617 "MPT2_IOC_RUNNING\n", ioc
->name
, __func__
));
5618 _scsih_remove_unresponding_devices(ioc
);
5624 * _firmware_event_work - delayed task for processing firmware events
5625 * @ioc: per adapter object
5626 * @work: equal to the fw_event_work object
5632 _firmware_event_work(struct work_struct
*work
)
5634 struct fw_event_work
*fw_event
= container_of(work
,
5635 struct fw_event_work
, work
);
5636 unsigned long flags
;
5637 struct MPT2SAS_ADAPTER
*ioc
= fw_event
->ioc
;
5639 /* the queue is being flushed so ignore this event */
5640 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
5641 if (ioc
->fw_events_off
|| ioc
->remove_host
) {
5642 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
5643 _scsih_fw_event_free(ioc
, fw_event
);
5646 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
5648 if (ioc
->shost_recovery
) {
5649 _scsih_fw_event_requeue(ioc
, fw_event
, 1000);
5653 switch (fw_event
->event
) {
5654 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
5655 _scsih_sas_topology_change_event(ioc
, fw_event
);
5657 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
5658 _scsih_sas_device_status_change_event(ioc
,
5661 case MPI2_EVENT_SAS_DISCOVERY
:
5662 _scsih_sas_discovery_event(ioc
,
5665 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
5666 _scsih_sas_broadcast_primative_event(ioc
,
5669 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
5670 _scsih_sas_enclosure_dev_status_change_event(ioc
,
5673 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
5674 _scsih_sas_ir_config_change_event(ioc
, fw_event
);
5676 case MPI2_EVENT_IR_VOLUME
:
5677 _scsih_sas_ir_volume_event(ioc
, fw_event
);
5679 case MPI2_EVENT_IR_PHYSICAL_DISK
:
5680 _scsih_sas_ir_physical_disk_event(ioc
, fw_event
);
5682 case MPI2_EVENT_IR_OPERATION_STATUS
:
5683 _scsih_sas_ir_operation_status_event(ioc
, fw_event
);
5685 case MPI2_EVENT_TASK_SET_FULL
:
5686 _scsih_task_set_full(ioc
, fw_event
);
5689 _scsih_fw_event_free(ioc
, fw_event
);
5693 * mpt2sas_scsih_event_callback - firmware event handler (called at ISR time)
5694 * @ioc: per adapter object
5695 * @msix_index: MSIX table index supplied by the OS
5696 * @reply: reply message frame(lower 32bit addr)
5697 * Context: interrupt.
5699 * This function merely adds a new work task into ioc->firmware_event_thread.
5700 * The tasks are worked from _firmware_event_work in user context.
5702 * Return 1 meaning mf should be freed from _base_interrupt
5703 * 0 means the mf is freed from this function.
5706 mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER
*ioc
, u8 msix_index
,
5709 struct fw_event_work
*fw_event
;
5710 Mpi2EventNotificationReply_t
*mpi_reply
;
5711 unsigned long flags
;
5714 /* events turned off due to host reset or driver unloading */
5715 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
5716 if (ioc
->fw_events_off
|| ioc
->remove_host
) {
5717 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
5720 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
5722 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
5723 event
= le16_to_cpu(mpi_reply
->Event
);
5727 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
5729 Mpi2EventDataSasBroadcastPrimitive_t
*baen_data
=
5730 (Mpi2EventDataSasBroadcastPrimitive_t
*)
5731 mpi_reply
->EventData
;
5733 if (baen_data
->Primitive
!=
5734 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT
||
5735 ioc
->broadcast_aen_busy
)
5737 ioc
->broadcast_aen_busy
= 1;
5741 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
5742 _scsih_check_topo_delete_events(ioc
,
5743 (Mpi2EventDataSasTopologyChangeList_t
*)
5744 mpi_reply
->EventData
);
5747 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
5748 case MPI2_EVENT_IR_OPERATION_STATUS
:
5749 case MPI2_EVENT_SAS_DISCOVERY
:
5750 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
5751 case MPI2_EVENT_IR_VOLUME
:
5752 case MPI2_EVENT_IR_PHYSICAL_DISK
:
5753 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
5754 case MPI2_EVENT_TASK_SET_FULL
:
5757 default: /* ignore the rest */
5761 fw_event
= kzalloc(sizeof(struct fw_event_work
), GFP_ATOMIC
);
5763 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5764 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5767 fw_event
->event_data
=
5768 kzalloc(mpi_reply
->EventDataLength
*4, GFP_ATOMIC
);
5769 if (!fw_event
->event_data
) {
5770 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5771 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5776 memcpy(fw_event
->event_data
, mpi_reply
->EventData
,
5777 mpi_reply
->EventDataLength
*4);
5778 fw_event
->ioc
= ioc
;
5779 fw_event
->VF_ID
= mpi_reply
->VF_ID
;
5780 fw_event
->VP_ID
= mpi_reply
->VP_ID
;
5781 fw_event
->event
= event
;
5782 _scsih_fw_event_add(ioc
, fw_event
);
5786 /* shost template */
5787 static struct scsi_host_template scsih_driver_template
= {
5788 .module
= THIS_MODULE
,
5789 .name
= "Fusion MPT SAS Host",
5790 .proc_name
= MPT2SAS_DRIVER_NAME
,
5791 .queuecommand
= _scsih_qcmd
,
5792 .target_alloc
= _scsih_target_alloc
,
5793 .slave_alloc
= _scsih_slave_alloc
,
5794 .slave_configure
= _scsih_slave_configure
,
5795 .target_destroy
= _scsih_target_destroy
,
5796 .slave_destroy
= _scsih_slave_destroy
,
5797 .change_queue_depth
= _scsih_change_queue_depth
,
5798 .change_queue_type
= _scsih_change_queue_type
,
5799 .eh_abort_handler
= _scsih_abort
,
5800 .eh_device_reset_handler
= _scsih_dev_reset
,
5801 .eh_target_reset_handler
= _scsih_target_reset
,
5802 .eh_host_reset_handler
= _scsih_host_reset
,
5803 .bios_param
= _scsih_bios_param
,
5806 .sg_tablesize
= MPT2SAS_SG_DEPTH
,
5807 .max_sectors
= 8192,
5809 .use_clustering
= ENABLE_CLUSTERING
,
5810 .shost_attrs
= mpt2sas_host_attrs
,
5811 .sdev_attrs
= mpt2sas_dev_attrs
,
5815 * _scsih_expander_node_remove - removing expander device from list.
5816 * @ioc: per adapter object
5817 * @sas_expander: the sas_device object
5818 * Context: Calling function should acquire ioc->sas_node_lock.
5820 * Removing object and freeing associated memory from the
5821 * ioc->sas_expander_list.
5826 _scsih_expander_node_remove(struct MPT2SAS_ADAPTER
*ioc
,
5827 struct _sas_node
*sas_expander
)
5829 struct _sas_port
*mpt2sas_port
;
5830 struct _sas_device
*sas_device
;
5831 struct _sas_node
*expander_sibling
;
5832 unsigned long flags
;
5837 /* remove sibling ports attached to this expander */
5838 retry_device_search
:
5839 list_for_each_entry(mpt2sas_port
,
5840 &sas_expander
->sas_port_list
, port_list
) {
5841 if (mpt2sas_port
->remote_identify
.device_type
==
5843 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5845 mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
5846 mpt2sas_port
->remote_identify
.sas_address
);
5847 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5850 _scsih_remove_device(ioc
, sas_device
);
5851 if (ioc
->shost_recovery
)
5853 goto retry_device_search
;
5857 retry_expander_search
:
5858 list_for_each_entry(mpt2sas_port
,
5859 &sas_expander
->sas_port_list
, port_list
) {
5861 if (mpt2sas_port
->remote_identify
.device_type
==
5862 MPI2_SAS_DEVICE_INFO_EDGE_EXPANDER
||
5863 mpt2sas_port
->remote_identify
.device_type
==
5864 MPI2_SAS_DEVICE_INFO_FANOUT_EXPANDER
) {
5866 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5868 mpt2sas_scsih_expander_find_by_sas_address(
5869 ioc
, mpt2sas_port
->remote_identify
.sas_address
);
5870 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5871 if (!expander_sibling
)
5873 _scsih_expander_remove(ioc
,
5874 expander_sibling
->sas_address
);
5875 if (ioc
->shost_recovery
)
5877 goto retry_expander_search
;
5881 mpt2sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
5882 sas_expander
->sas_address_parent
);
5884 printk(MPT2SAS_INFO_FMT
"expander_remove: handle"
5885 "(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
5886 sas_expander
->handle
, (unsigned long long)
5887 sas_expander
->sas_address
);
5889 list_del(&sas_expander
->list
);
5890 kfree(sas_expander
->phy
);
5891 kfree(sas_expander
);
5895 * _scsih_ir_shutdown - IR shutdown notification
5896 * @ioc: per adapter object
5898 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
5899 * the host system is shutting down.
5904 _scsih_ir_shutdown(struct MPT2SAS_ADAPTER
*ioc
)
5906 Mpi2RaidActionRequest_t
*mpi_request
;
5907 Mpi2RaidActionReply_t
*mpi_reply
;
5910 /* is IR firmware build loaded ? */
5911 if (!ioc
->ir_firmware
)
5914 /* are there any volumes ? */
5915 if (list_empty(&ioc
->raid_device_list
))
5918 mutex_lock(&ioc
->scsih_cmds
.mutex
);
5920 if (ioc
->scsih_cmds
.status
!= MPT2_CMD_NOT_USED
) {
5921 printk(MPT2SAS_ERR_FMT
"%s: scsih_cmd in use\n",
5922 ioc
->name
, __func__
);
5925 ioc
->scsih_cmds
.status
= MPT2_CMD_PENDING
;
5927 smid
= mpt2sas_base_get_smid(ioc
, ioc
->scsih_cb_idx
);
5929 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
5930 ioc
->name
, __func__
);
5931 ioc
->scsih_cmds
.status
= MPT2_CMD_NOT_USED
;
5935 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
5936 ioc
->scsih_cmds
.smid
= smid
;
5937 memset(mpi_request
, 0, sizeof(Mpi2RaidActionRequest_t
));
5939 mpi_request
->Function
= MPI2_FUNCTION_RAID_ACTION
;
5940 mpi_request
->Action
= MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED
;
5942 printk(MPT2SAS_INFO_FMT
"IR shutdown (sending)\n", ioc
->name
);
5943 init_completion(&ioc
->scsih_cmds
.done
);
5944 mpt2sas_base_put_smid_default(ioc
, smid
);
5945 wait_for_completion_timeout(&ioc
->scsih_cmds
.done
, 10*HZ
);
5947 if (!(ioc
->scsih_cmds
.status
& MPT2_CMD_COMPLETE
)) {
5948 printk(MPT2SAS_ERR_FMT
"%s: timeout\n",
5949 ioc
->name
, __func__
);
5953 if (ioc
->scsih_cmds
.status
& MPT2_CMD_REPLY_VALID
) {
5954 mpi_reply
= ioc
->scsih_cmds
.reply
;
5956 printk(MPT2SAS_INFO_FMT
"IR shutdown (complete): "
5957 "ioc_status(0x%04x), loginfo(0x%08x)\n",
5958 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
5959 le32_to_cpu(mpi_reply
->IOCLogInfo
));
5963 ioc
->scsih_cmds
.status
= MPT2_CMD_NOT_USED
;
5964 mutex_unlock(&ioc
->scsih_cmds
.mutex
);
5968 * _scsih_shutdown - routine call during system shutdown
5969 * @pdev: PCI device struct
5974 _scsih_shutdown(struct pci_dev
*pdev
)
5976 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
5977 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
5979 _scsih_ir_shutdown(ioc
);
5980 mpt2sas_base_detach(ioc
);
5984 * _scsih_remove - detach and remove add host
5985 * @pdev: PCI device struct
5987 * Routine called when unloading the driver.
5990 static void __devexit
5991 _scsih_remove(struct pci_dev
*pdev
)
5993 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
5994 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
5995 struct _sas_port
*mpt2sas_port
;
5996 struct _sas_device
*sas_device
;
5997 struct _sas_node
*expander_sibling
;
5998 struct _raid_device
*raid_device
, *next
;
5999 struct MPT2SAS_TARGET
*sas_target_priv_data
;
6000 struct workqueue_struct
*wq
;
6001 unsigned long flags
;
6003 ioc
->remove_host
= 1;
6004 _scsih_fw_event_off(ioc
);
6006 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
6007 wq
= ioc
->firmware_event_thread
;
6008 ioc
->firmware_event_thread
= NULL
;
6009 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
6011 destroy_workqueue(wq
);
6013 /* release all the volumes */
6014 _scsih_ir_shutdown(ioc
);
6015 list_for_each_entry_safe(raid_device
, next
, &ioc
->raid_device_list
,
6017 if (raid_device
->starget
) {
6018 sas_target_priv_data
=
6019 raid_device
->starget
->hostdata
;
6020 sas_target_priv_data
->deleted
= 1;
6021 scsi_remove_target(&raid_device
->starget
->dev
);
6023 printk(MPT2SAS_INFO_FMT
"removing handle(0x%04x), wwid"
6024 "(0x%016llx)\n", ioc
->name
, raid_device
->handle
,
6025 (unsigned long long) raid_device
->wwid
);
6026 _scsih_raid_device_remove(ioc
, raid_device
);
6029 /* free ports attached to the sas_host */
6031 list_for_each_entry(mpt2sas_port
,
6032 &ioc
->sas_hba
.sas_port_list
, port_list
) {
6033 if (mpt2sas_port
->remote_identify
.device_type
==
6036 mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
6037 mpt2sas_port
->remote_identify
.sas_address
);
6039 _scsih_remove_device(ioc
, sas_device
);
6044 mpt2sas_scsih_expander_find_by_sas_address(ioc
,
6045 mpt2sas_port
->remote_identify
.sas_address
);
6046 if (expander_sibling
) {
6047 _scsih_expander_remove(ioc
,
6048 expander_sibling
->sas_address
);
6054 /* free phys attached to the sas_host */
6055 if (ioc
->sas_hba
.num_phys
) {
6056 kfree(ioc
->sas_hba
.phy
);
6057 ioc
->sas_hba
.phy
= NULL
;
6058 ioc
->sas_hba
.num_phys
= 0;
6061 sas_remove_host(shost
);
6062 _scsih_shutdown(pdev
);
6063 list_del(&ioc
->list
);
6064 scsi_remove_host(shost
);
6065 scsi_host_put(shost
);
6069 * _scsih_probe_boot_devices - reports 1st device
6070 * @ioc: per adapter object
6072 * If specified in bios page 2, this routine reports the 1st
6073 * device scsi-ml or sas transport for persistent boot device
6074 * purposes. Please refer to function _scsih_determine_boot_device()
6077 _scsih_probe_boot_devices(struct MPT2SAS_ADAPTER
*ioc
)
6081 struct _sas_device
*sas_device
;
6082 struct _raid_device
*raid_device
;
6084 u64 sas_address_parent
;
6086 unsigned long flags
;
6090 if (ioc
->req_boot_device
.device
) {
6091 device
= ioc
->req_boot_device
.device
;
6092 is_raid
= ioc
->req_boot_device
.is_raid
;
6093 } else if (ioc
->req_alt_boot_device
.device
) {
6094 device
= ioc
->req_alt_boot_device
.device
;
6095 is_raid
= ioc
->req_alt_boot_device
.is_raid
;
6096 } else if (ioc
->current_boot_device
.device
) {
6097 device
= ioc
->current_boot_device
.device
;
6098 is_raid
= ioc
->current_boot_device
.is_raid
;
6105 raid_device
= device
;
6106 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
6107 raid_device
->id
, 0);
6109 _scsih_raid_device_remove(ioc
, raid_device
);
6111 sas_device
= device
;
6112 handle
= sas_device
->handle
;
6113 sas_address_parent
= sas_device
->sas_address_parent
;
6114 sas_address
= sas_device
->sas_address
;
6115 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6116 list_move_tail(&sas_device
->list
, &ioc
->sas_device_list
);
6117 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6118 if (!mpt2sas_transport_port_add(ioc
, sas_device
->handle
,
6119 sas_device
->sas_address_parent
)) {
6120 _scsih_sas_device_remove(ioc
, sas_device
);
6121 } else if (!sas_device
->starget
) {
6122 mpt2sas_transport_port_remove(ioc
, sas_address
,
6123 sas_address_parent
);
6124 _scsih_sas_device_remove(ioc
, sas_device
);
6130 * _scsih_probe_raid - reporting raid volumes to scsi-ml
6131 * @ioc: per adapter object
6133 * Called during initial loading of the driver.
6136 _scsih_probe_raid(struct MPT2SAS_ADAPTER
*ioc
)
6138 struct _raid_device
*raid_device
, *raid_next
;
6141 list_for_each_entry_safe(raid_device
, raid_next
,
6142 &ioc
->raid_device_list
, list
) {
6143 if (raid_device
->starget
)
6145 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
6146 raid_device
->id
, 0);
6148 _scsih_raid_device_remove(ioc
, raid_device
);
6153 * _scsih_probe_sas - reporting sas devices to sas transport
6154 * @ioc: per adapter object
6156 * Called during initial loading of the driver.
6159 _scsih_probe_sas(struct MPT2SAS_ADAPTER
*ioc
)
6161 struct _sas_device
*sas_device
, *next
;
6162 unsigned long flags
;
6164 /* SAS Device List */
6165 list_for_each_entry_safe(sas_device
, next
, &ioc
->sas_device_init_list
,
6167 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6168 list_move_tail(&sas_device
->list
, &ioc
->sas_device_list
);
6169 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6171 if (!mpt2sas_transport_port_add(ioc
, sas_device
->handle
,
6172 sas_device
->sas_address_parent
)) {
6173 _scsih_sas_device_remove(ioc
, sas_device
);
6174 } else if (!sas_device
->starget
) {
6175 mpt2sas_transport_port_remove(ioc
,
6176 sas_device
->sas_address
,
6177 sas_device
->sas_address_parent
);
6178 _scsih_sas_device_remove(ioc
, sas_device
);
6184 * _scsih_probe_devices - probing for devices
6185 * @ioc: per adapter object
6187 * Called during initial loading of the driver.
6190 _scsih_probe_devices(struct MPT2SAS_ADAPTER
*ioc
)
6192 u16 volume_mapping_flags
=
6193 le16_to_cpu(ioc
->ioc_pg8
.IRVolumeMappingFlags
) &
6194 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE
;
6196 if (!(ioc
->facts
.ProtocolFlags
& MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR
))
6197 return; /* return when IOC doesn't support initiator mode */
6199 _scsih_probe_boot_devices(ioc
);
6201 if (ioc
->ir_firmware
) {
6202 if ((volume_mapping_flags
&
6203 MPI2_IOCPAGE8_IRFLAGS_HIGH_VOLUME_MAPPING
)) {
6204 _scsih_probe_sas(ioc
);
6205 _scsih_probe_raid(ioc
);
6207 _scsih_probe_raid(ioc
);
6208 _scsih_probe_sas(ioc
);
6211 _scsih_probe_sas(ioc
);
6215 * _scsih_probe - attach and add scsi host
6216 * @pdev: PCI device struct
6217 * @id: pci device id
6219 * Returns 0 success, anything else error.
6222 _scsih_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
6224 struct MPT2SAS_ADAPTER
*ioc
;
6225 struct Scsi_Host
*shost
;
6227 shost
= scsi_host_alloc(&scsih_driver_template
,
6228 sizeof(struct MPT2SAS_ADAPTER
));
6232 /* init local params */
6233 ioc
= shost_priv(shost
);
6234 memset(ioc
, 0, sizeof(struct MPT2SAS_ADAPTER
));
6235 INIT_LIST_HEAD(&ioc
->list
);
6236 list_add_tail(&ioc
->list
, &mpt2sas_ioc_list
);
6238 ioc
->id
= mpt_ids
++;
6239 sprintf(ioc
->name
, "%s%d", MPT2SAS_DRIVER_NAME
, ioc
->id
);
6241 ioc
->scsi_io_cb_idx
= scsi_io_cb_idx
;
6242 ioc
->tm_cb_idx
= tm_cb_idx
;
6243 ioc
->ctl_cb_idx
= ctl_cb_idx
;
6244 ioc
->base_cb_idx
= base_cb_idx
;
6245 ioc
->transport_cb_idx
= transport_cb_idx
;
6246 ioc
->scsih_cb_idx
= scsih_cb_idx
;
6247 ioc
->config_cb_idx
= config_cb_idx
;
6248 ioc
->tm_tr_cb_idx
= tm_tr_cb_idx
;
6249 ioc
->tm_sas_control_cb_idx
= tm_sas_control_cb_idx
;
6250 ioc
->logging_level
= logging_level
;
6251 /* misc semaphores and spin locks */
6252 spin_lock_init(&ioc
->ioc_reset_in_progress_lock
);
6253 spin_lock_init(&ioc
->scsi_lookup_lock
);
6254 spin_lock_init(&ioc
->sas_device_lock
);
6255 spin_lock_init(&ioc
->sas_node_lock
);
6256 spin_lock_init(&ioc
->fw_event_lock
);
6257 spin_lock_init(&ioc
->raid_device_lock
);
6259 INIT_LIST_HEAD(&ioc
->sas_device_list
);
6260 INIT_LIST_HEAD(&ioc
->sas_device_init_list
);
6261 INIT_LIST_HEAD(&ioc
->sas_expander_list
);
6262 INIT_LIST_HEAD(&ioc
->fw_event_list
);
6263 INIT_LIST_HEAD(&ioc
->raid_device_list
);
6264 INIT_LIST_HEAD(&ioc
->sas_hba
.sas_port_list
);
6265 INIT_LIST_HEAD(&ioc
->delayed_tr_list
);
6267 /* init shost parameters */
6268 shost
->max_cmd_len
= 16;
6269 shost
->max_lun
= max_lun
;
6270 shost
->transportt
= mpt2sas_transport_template
;
6271 shost
->unique_id
= ioc
->id
;
6273 if ((scsi_add_host(shost
, &pdev
->dev
))) {
6274 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6275 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6276 list_del(&ioc
->list
);
6277 goto out_add_shost_fail
;
6280 scsi_host_set_prot(shost
, SHOST_DIF_TYPE1_PROTECTION
6281 | SHOST_DIF_TYPE3_PROTECTION
);
6282 scsi_host_set_guard(shost
, SHOST_DIX_GUARD_CRC
);
6285 snprintf(ioc
->firmware_event_name
, sizeof(ioc
->firmware_event_name
),
6286 "fw_event%d", ioc
->id
);
6287 ioc
->firmware_event_thread
= create_singlethread_workqueue(
6288 ioc
->firmware_event_name
);
6289 if (!ioc
->firmware_event_thread
) {
6290 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6291 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6292 goto out_thread_fail
;
6295 ioc
->wait_for_port_enable_to_complete
= 1;
6296 if ((mpt2sas_base_attach(ioc
))) {
6297 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6298 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6299 goto out_attach_fail
;
6302 ioc
->wait_for_port_enable_to_complete
= 0;
6303 _scsih_probe_devices(ioc
);
6307 destroy_workqueue(ioc
->firmware_event_thread
);
6309 list_del(&ioc
->list
);
6310 scsi_remove_host(shost
);
6317 * _scsih_suspend - power management suspend main entry point
6318 * @pdev: PCI device struct
6319 * @state: PM state change to (usually PCI_D3)
6321 * Returns 0 success, anything else error.
6324 _scsih_suspend(struct pci_dev
*pdev
, pm_message_t state
)
6326 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6327 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
6330 mpt2sas_base_stop_watchdog(ioc
);
6331 flush_scheduled_work();
6332 scsi_block_requests(shost
);
6333 device_state
= pci_choose_state(pdev
, state
);
6334 printk(MPT2SAS_INFO_FMT
"pdev=0x%p, slot=%s, entering "
6335 "operating state [D%d]\n", ioc
->name
, pdev
,
6336 pci_name(pdev
), device_state
);
6338 mpt2sas_base_free_resources(ioc
);
6339 pci_save_state(pdev
);
6340 pci_disable_device(pdev
);
6341 pci_set_power_state(pdev
, device_state
);
6346 * _scsih_resume - power management resume main entry point
6347 * @pdev: PCI device struct
6349 * Returns 0 success, anything else error.
6352 _scsih_resume(struct pci_dev
*pdev
)
6354 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6355 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
6356 u32 device_state
= pdev
->current_state
;
6359 printk(MPT2SAS_INFO_FMT
"pdev=0x%p, slot=%s, previous "
6360 "operating state [D%d]\n", ioc
->name
, pdev
,
6361 pci_name(pdev
), device_state
);
6363 pci_set_power_state(pdev
, PCI_D0
);
6364 pci_enable_wake(pdev
, PCI_D0
, 0);
6365 pci_restore_state(pdev
);
6367 r
= mpt2sas_base_map_resources(ioc
);
6371 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
, SOFT_RESET
);
6372 scsi_unblock_requests(shost
);
6373 mpt2sas_base_start_watchdog(ioc
);
6376 #endif /* CONFIG_PM */
6379 static struct pci_driver scsih_driver
= {
6380 .name
= MPT2SAS_DRIVER_NAME
,
6381 .id_table
= scsih_pci_table
,
6382 .probe
= _scsih_probe
,
6383 .remove
= __devexit_p(_scsih_remove
),
6384 .shutdown
= _scsih_shutdown
,
6386 .suspend
= _scsih_suspend
,
6387 .resume
= _scsih_resume
,
6393 * _scsih_init - main entry point for this driver.
6395 * Returns 0 success, anything else error.
6403 printk(KERN_INFO
"%s version %s loaded\n", MPT2SAS_DRIVER_NAME
,
6404 MPT2SAS_DRIVER_VERSION
);
6406 mpt2sas_transport_template
=
6407 sas_attach_transport(&mpt2sas_transport_functions
);
6408 if (!mpt2sas_transport_template
)
6411 mpt2sas_base_initialize_callback_handler();
6413 /* queuecommand callback hander */
6414 scsi_io_cb_idx
= mpt2sas_base_register_callback_handler(_scsih_io_done
);
6416 /* task managment callback handler */
6417 tm_cb_idx
= mpt2sas_base_register_callback_handler(_scsih_tm_done
);
6419 /* base internal commands callback handler */
6420 base_cb_idx
= mpt2sas_base_register_callback_handler(mpt2sas_base_done
);
6422 /* transport internal commands callback handler */
6423 transport_cb_idx
= mpt2sas_base_register_callback_handler(
6424 mpt2sas_transport_done
);
6426 /* scsih internal commands callback handler */
6427 scsih_cb_idx
= mpt2sas_base_register_callback_handler(_scsih_done
);
6429 /* configuration page API internal commands callback handler */
6430 config_cb_idx
= mpt2sas_base_register_callback_handler(
6431 mpt2sas_config_done
);
6433 /* ctl module callback handler */
6434 ctl_cb_idx
= mpt2sas_base_register_callback_handler(mpt2sas_ctl_done
);
6436 tm_tr_cb_idx
= mpt2sas_base_register_callback_handler(
6437 _scsih_tm_tr_complete
);
6438 tm_sas_control_cb_idx
= mpt2sas_base_register_callback_handler(
6439 _scsih_sas_control_complete
);
6443 error
= pci_register_driver(&scsih_driver
);
6445 sas_release_transport(mpt2sas_transport_template
);
6451 * _scsih_exit - exit point for this driver (when it is a module).
6453 * Returns 0 success, anything else error.
6458 printk(KERN_INFO
"mpt2sas version %s unloading\n",
6459 MPT2SAS_DRIVER_VERSION
);
6461 pci_unregister_driver(&scsih_driver
);
6463 sas_release_transport(mpt2sas_transport_template
);
6464 mpt2sas_base_release_callback_handler(scsi_io_cb_idx
);
6465 mpt2sas_base_release_callback_handler(tm_cb_idx
);
6466 mpt2sas_base_release_callback_handler(base_cb_idx
);
6467 mpt2sas_base_release_callback_handler(transport_cb_idx
);
6468 mpt2sas_base_release_callback_handler(scsih_cb_idx
);
6469 mpt2sas_base_release_callback_handler(config_cb_idx
);
6470 mpt2sas_base_release_callback_handler(ctl_cb_idx
);
6472 mpt2sas_base_release_callback_handler(tm_tr_cb_idx
);
6473 mpt2sas_base_release_callback_handler(tm_sas_control_cb_idx
);
6478 module_init(_scsih_init
);
6479 module_exit(_scsih_exit
);