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 if (event_data
->PHY
[i
].PhyStatus
&
2667 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT
)
2669 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
2672 reason_code
= event_data
->PHY
[i
].PhyStatus
&
2673 MPI2_EVENT_SAS_TOPO_RC_MASK
;
2674 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
)
2675 _scsih_tm_tr_send(ioc
, handle
);
2678 expander_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
2679 if (expander_handle
< ioc
->sas_hba
.num_phys
) {
2680 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
2684 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
2685 || event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
) {
2686 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
2687 sas_expander
= mpt2sas_scsih_expander_find_by_handle(ioc
,
2689 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
2690 _scsih_block_io_to_children_attached_to_ex(ioc
, sas_expander
);
2691 } else if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_RESPONDING
)
2692 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
2694 if (event_data
->ExpStatus
!= MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
)
2697 /* mark ignore flag for pending events */
2698 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2699 list_for_each_entry(fw_event
, &ioc
->fw_event_list
, list
) {
2700 if (fw_event
->event
!= MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
||
2703 local_event_data
= fw_event
->event_data
;
2704 if (local_event_data
->ExpStatus
==
2705 MPI2_EVENT_SAS_TOPO_ES_ADDED
||
2706 local_event_data
->ExpStatus
==
2707 MPI2_EVENT_SAS_TOPO_ES_RESPONDING
) {
2708 if (le16_to_cpu(local_event_data
->ExpanderDevHandle
) ==
2710 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
2711 "setting ignoring flag\n", ioc
->name
));
2712 fw_event
->ignore
= 1;
2716 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2720 * _scsih_flush_running_cmds - completing outstanding commands.
2721 * @ioc: per adapter object
2723 * The flushing out of all pending scmd commands following host reset,
2724 * where all IO is dropped to the floor.
2729 _scsih_flush_running_cmds(struct MPT2SAS_ADAPTER
*ioc
)
2731 struct scsi_cmnd
*scmd
;
2735 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
2736 scmd
= _scsih_scsi_lookup_get(ioc
, smid
);
2740 mpt2sas_base_free_smid(ioc
, smid
);
2741 scsi_dma_unmap(scmd
);
2742 scmd
->result
= DID_RESET
<< 16;
2743 scmd
->scsi_done(scmd
);
2745 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"completing %d cmds\n",
2750 * _scsih_setup_eedp - setup MPI request for EEDP transfer
2751 * @scmd: pointer to scsi command object
2752 * @mpi_request: pointer to the SCSI_IO reqest message frame
2754 * Supporting protection 1 and 3.
2759 _scsih_setup_eedp(struct scsi_cmnd
*scmd
, Mpi2SCSIIORequest_t
*mpi_request
)
2762 unsigned char prot_op
= scsi_get_prot_op(scmd
);
2763 unsigned char prot_type
= scsi_get_prot_type(scmd
);
2765 if (prot_type
== SCSI_PROT_DIF_TYPE0
||
2766 prot_type
== SCSI_PROT_DIF_TYPE2
||
2767 prot_op
== SCSI_PROT_NORMAL
)
2770 if (prot_op
== SCSI_PROT_READ_STRIP
)
2771 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP
;
2772 else if (prot_op
== SCSI_PROT_WRITE_INSERT
)
2773 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_INSERT_OP
;
2777 switch (prot_type
) {
2778 case SCSI_PROT_DIF_TYPE1
:
2781 * enable ref/guard checking
2782 * auto increment ref tag
2784 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG
|
2785 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG
|
2786 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
2787 mpi_request
->CDB
.EEDP32
.PrimaryReferenceTag
=
2788 cpu_to_be32(scsi_get_lba(scmd
));
2792 case SCSI_PROT_DIF_TYPE3
:
2795 * enable guard checking
2797 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
2800 mpi_request
->EEDPBlockSize
= cpu_to_le32(scmd
->device
->sector_size
);
2801 mpi_request
->EEDPFlags
= cpu_to_le16(eedp_flags
);
2805 * _scsih_eedp_error_handling - return sense code for EEDP errors
2806 * @scmd: pointer to scsi command object
2807 * @ioc_status: ioc status
2812 _scsih_eedp_error_handling(struct scsi_cmnd
*scmd
, u16 ioc_status
)
2818 switch (ioc_status
) {
2819 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
2822 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
2825 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
2833 if (scmd
->sc_data_direction
== DMA_TO_DEVICE
) {
2834 sk
= ILLEGAL_REQUEST
;
2835 host_byte
= DID_ABORT
;
2837 sk
= ABORTED_COMMAND
;
2841 scsi_build_sense_buffer(0, scmd
->sense_buffer
, sk
, 0x10, ascq
);
2842 scmd
->result
= DRIVER_SENSE
<< 24 | (host_byte
<< 16) |
2843 SAM_STAT_CHECK_CONDITION
;
2847 * _scsih_qcmd - main scsi request entry point
2848 * @scmd: pointer to scsi command object
2849 * @done: function pointer to be invoked on completion
2851 * The callback index is set inside `ioc->scsi_io_cb_idx`.
2853 * Returns 0 on success. If there's a failure, return either:
2854 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
2855 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
2858 _scsih_qcmd(struct scsi_cmnd
*scmd
, void (*done
)(struct scsi_cmnd
*))
2860 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2861 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2862 struct MPT2SAS_TARGET
*sas_target_priv_data
;
2863 Mpi2SCSIIORequest_t
*mpi_request
;
2867 scmd
->scsi_done
= done
;
2868 sas_device_priv_data
= scmd
->device
->hostdata
;
2869 if (!sas_device_priv_data
) {
2870 scmd
->result
= DID_NO_CONNECT
<< 16;
2871 scmd
->scsi_done(scmd
);
2875 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
2876 if (!sas_target_priv_data
|| sas_target_priv_data
->handle
==
2877 MPT2SAS_INVALID_DEVICE_HANDLE
|| sas_target_priv_data
->deleted
) {
2878 scmd
->result
= DID_NO_CONNECT
<< 16;
2879 scmd
->scsi_done(scmd
);
2883 /* see if we are busy with task managment stuff */
2884 if (sas_device_priv_data
->block
|| sas_target_priv_data
->tm_busy
)
2885 return SCSI_MLQUEUE_DEVICE_BUSY
;
2886 else if (ioc
->shost_recovery
|| ioc
->ioc_link_reset_in_progress
)
2887 return SCSI_MLQUEUE_HOST_BUSY
;
2889 if (scmd
->sc_data_direction
== DMA_FROM_DEVICE
)
2890 mpi_control
= MPI2_SCSIIO_CONTROL_READ
;
2891 else if (scmd
->sc_data_direction
== DMA_TO_DEVICE
)
2892 mpi_control
= MPI2_SCSIIO_CONTROL_WRITE
;
2894 mpi_control
= MPI2_SCSIIO_CONTROL_NODATATRANSFER
;
2897 if (!(sas_device_priv_data
->flags
& MPT_DEVICE_FLAGS_INIT
)) {
2898 if (scmd
->device
->tagged_supported
) {
2899 if (scmd
->device
->ordered_tags
)
2900 mpi_control
|= MPI2_SCSIIO_CONTROL_ORDEREDQ
;
2902 mpi_control
|= MPI2_SCSIIO_CONTROL_SIMPLEQ
;
2904 /* MPI Revision I (UNIT = 0xA) - removed MPI2_SCSIIO_CONTROL_UNTAGGED */
2905 /* mpi_control |= MPI2_SCSIIO_CONTROL_UNTAGGED;
2907 mpi_control
|= (0x500);
2910 mpi_control
|= MPI2_SCSIIO_CONTROL_SIMPLEQ
;
2912 if ((sas_device_priv_data
->flags
& MPT_DEVICE_TLR_ON
))
2913 mpi_control
|= MPI2_SCSIIO_CONTROL_TLR_ON
;
2915 smid
= mpt2sas_base_get_smid_scsiio(ioc
, ioc
->scsi_io_cb_idx
, scmd
);
2917 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
2918 ioc
->name
, __func__
);
2921 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
2922 memset(mpi_request
, 0, sizeof(Mpi2SCSIIORequest_t
));
2923 _scsih_setup_eedp(scmd
, mpi_request
);
2924 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
2925 if (sas_device_priv_data
->sas_target
->flags
&
2926 MPT_TARGET_FLAGS_RAID_COMPONENT
)
2927 mpi_request
->Function
= MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
;
2929 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
2930 mpi_request
->DevHandle
=
2931 cpu_to_le16(sas_device_priv_data
->sas_target
->handle
);
2932 mpi_request
->DataLength
= cpu_to_le32(scsi_bufflen(scmd
));
2933 mpi_request
->Control
= cpu_to_le32(mpi_control
);
2934 mpi_request
->IoFlags
= cpu_to_le16(scmd
->cmd_len
);
2935 mpi_request
->MsgFlags
= MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR
;
2936 mpi_request
->SenseBufferLength
= SCSI_SENSE_BUFFERSIZE
;
2937 mpi_request
->SenseBufferLowAddress
=
2938 mpt2sas_base_get_sense_buffer_dma(ioc
, smid
);
2939 mpi_request
->SGLOffset0
= offsetof(Mpi2SCSIIORequest_t
, SGL
) / 4;
2940 mpi_request
->SGLFlags
= cpu_to_le16(MPI2_SCSIIO_SGLFLAGS_TYPE_MPI
+
2941 MPI2_SCSIIO_SGLFLAGS_SYSTEM_ADDR
);
2942 mpi_request
->VF_ID
= 0; /* TODO */
2943 mpi_request
->VP_ID
= 0;
2944 int_to_scsilun(sas_device_priv_data
->lun
, (struct scsi_lun
*)
2946 memcpy(mpi_request
->CDB
.CDB32
, scmd
->cmnd
, scmd
->cmd_len
);
2948 if (!mpi_request
->DataLength
) {
2949 mpt2sas_base_build_zero_len_sge(ioc
, &mpi_request
->SGL
);
2951 if (_scsih_build_scatter_gather(ioc
, scmd
, smid
)) {
2952 mpt2sas_base_free_smid(ioc
, smid
);
2957 mpt2sas_base_put_smid_scsi_io(ioc
, smid
,
2958 sas_device_priv_data
->sas_target
->handle
);
2962 return SCSI_MLQUEUE_HOST_BUSY
;
2966 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
2967 * @sense_buffer: sense data returned by target
2968 * @data: normalized skey/asc/ascq
2973 _scsih_normalize_sense(char *sense_buffer
, struct sense_info
*data
)
2975 if ((sense_buffer
[0] & 0x7F) >= 0x72) {
2976 /* descriptor format */
2977 data
->skey
= sense_buffer
[1] & 0x0F;
2978 data
->asc
= sense_buffer
[2];
2979 data
->ascq
= sense_buffer
[3];
2982 data
->skey
= sense_buffer
[2] & 0x0F;
2983 data
->asc
= sense_buffer
[12];
2984 data
->ascq
= sense_buffer
[13];
2988 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
2990 * _scsih_scsi_ioc_info - translated non-successfull SCSI_IO request
2991 * @ioc: per adapter object
2992 * @scmd: pointer to scsi command object
2993 * @mpi_reply: reply mf payload returned from firmware
2995 * scsi_status - SCSI Status code returned from target device
2996 * scsi_state - state info associated with SCSI_IO determined by ioc
2997 * ioc_status - ioc supplied status info
3002 _scsih_scsi_ioc_info(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
,
3003 Mpi2SCSIIOReply_t
*mpi_reply
, u16 smid
)
3007 u16 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) &
3008 MPI2_IOCSTATUS_MASK
;
3009 u8 scsi_state
= mpi_reply
->SCSIState
;
3010 u8 scsi_status
= mpi_reply
->SCSIStatus
;
3011 char *desc_ioc_state
= NULL
;
3012 char *desc_scsi_status
= NULL
;
3013 char *desc_scsi_state
= ioc
->tmp_string
;
3014 u32 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
3016 if (log_info
== 0x31170000)
3019 switch (ioc_status
) {
3020 case MPI2_IOCSTATUS_SUCCESS
:
3021 desc_ioc_state
= "success";
3023 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
3024 desc_ioc_state
= "invalid function";
3026 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
3027 desc_ioc_state
= "scsi recovered error";
3029 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE
:
3030 desc_ioc_state
= "scsi invalid dev handle";
3032 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
3033 desc_ioc_state
= "scsi device not there";
3035 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
3036 desc_ioc_state
= "scsi data overrun";
3038 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
3039 desc_ioc_state
= "scsi data underrun";
3041 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
3042 desc_ioc_state
= "scsi io data error";
3044 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
3045 desc_ioc_state
= "scsi protocol error";
3047 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
3048 desc_ioc_state
= "scsi task terminated";
3050 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
3051 desc_ioc_state
= "scsi residual mismatch";
3053 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
3054 desc_ioc_state
= "scsi task mgmt failed";
3056 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
3057 desc_ioc_state
= "scsi ioc terminated";
3059 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
3060 desc_ioc_state
= "scsi ext terminated";
3062 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
3063 desc_ioc_state
= "eedp guard error";
3065 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
3066 desc_ioc_state
= "eedp ref tag error";
3068 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
3069 desc_ioc_state
= "eedp app tag error";
3072 desc_ioc_state
= "unknown";
3076 switch (scsi_status
) {
3077 case MPI2_SCSI_STATUS_GOOD
:
3078 desc_scsi_status
= "good";
3080 case MPI2_SCSI_STATUS_CHECK_CONDITION
:
3081 desc_scsi_status
= "check condition";
3083 case MPI2_SCSI_STATUS_CONDITION_MET
:
3084 desc_scsi_status
= "condition met";
3086 case MPI2_SCSI_STATUS_BUSY
:
3087 desc_scsi_status
= "busy";
3089 case MPI2_SCSI_STATUS_INTERMEDIATE
:
3090 desc_scsi_status
= "intermediate";
3092 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET
:
3093 desc_scsi_status
= "intermediate condmet";
3095 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT
:
3096 desc_scsi_status
= "reservation conflict";
3098 case MPI2_SCSI_STATUS_COMMAND_TERMINATED
:
3099 desc_scsi_status
= "command terminated";
3101 case MPI2_SCSI_STATUS_TASK_SET_FULL
:
3102 desc_scsi_status
= "task set full";
3104 case MPI2_SCSI_STATUS_ACA_ACTIVE
:
3105 desc_scsi_status
= "aca active";
3107 case MPI2_SCSI_STATUS_TASK_ABORTED
:
3108 desc_scsi_status
= "task aborted";
3111 desc_scsi_status
= "unknown";
3115 desc_scsi_state
[0] = '\0';
3117 desc_scsi_state
= " ";
3118 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
3119 strcat(desc_scsi_state
, "response info ");
3120 if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
3121 strcat(desc_scsi_state
, "state terminated ");
3122 if (scsi_state
& MPI2_SCSI_STATE_NO_SCSI_STATUS
)
3123 strcat(desc_scsi_state
, "no status ");
3124 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_FAILED
)
3125 strcat(desc_scsi_state
, "autosense failed ");
3126 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
)
3127 strcat(desc_scsi_state
, "autosense valid ");
3129 scsi_print_command(scmd
);
3130 printk(MPT2SAS_WARN_FMT
"\tdev handle(0x%04x), "
3131 "ioc_status(%s)(0x%04x), smid(%d)\n", ioc
->name
,
3132 le16_to_cpu(mpi_reply
->DevHandle
), desc_ioc_state
,
3134 printk(MPT2SAS_WARN_FMT
"\trequest_len(%d), underflow(%d), "
3135 "resid(%d)\n", ioc
->name
, scsi_bufflen(scmd
), scmd
->underflow
,
3136 scsi_get_resid(scmd
));
3137 printk(MPT2SAS_WARN_FMT
"\ttag(%d), transfer_count(%d), "
3138 "sc->result(0x%08x)\n", ioc
->name
, le16_to_cpu(mpi_reply
->TaskTag
),
3139 le32_to_cpu(mpi_reply
->TransferCount
), scmd
->result
);
3140 printk(MPT2SAS_WARN_FMT
"\tscsi_status(%s)(0x%02x), "
3141 "scsi_state(%s)(0x%02x)\n", ioc
->name
, desc_scsi_status
,
3142 scsi_status
, desc_scsi_state
, scsi_state
);
3144 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
3145 struct sense_info data
;
3146 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
3147 printk(MPT2SAS_WARN_FMT
"\t[sense_key,asc,ascq]: "
3148 "[0x%02x,0x%02x,0x%02x]\n", ioc
->name
, data
.skey
,
3149 data
.asc
, data
.ascq
);
3152 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
) {
3153 response_info
= le32_to_cpu(mpi_reply
->ResponseInfo
);
3154 response_bytes
= (u8
*)&response_info
;
3155 _scsih_response_code(ioc
, response_bytes
[0]);
3161 * _scsih_smart_predicted_fault - illuminate Fault LED
3162 * @ioc: per adapter object
3163 * @handle: device handle
3168 _scsih_smart_predicted_fault(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
3170 Mpi2SepReply_t mpi_reply
;
3171 Mpi2SepRequest_t mpi_request
;
3172 struct scsi_target
*starget
;
3173 struct MPT2SAS_TARGET
*sas_target_priv_data
;
3174 Mpi2EventNotificationReply_t
*event_reply
;
3175 Mpi2EventDataSasDeviceStatusChange_t
*event_data
;
3176 struct _sas_device
*sas_device
;
3178 unsigned long flags
;
3180 /* only handle non-raid devices */
3181 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
3182 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
3184 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3187 starget
= sas_device
->starget
;
3188 sas_target_priv_data
= starget
->hostdata
;
3190 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
) ||
3191 ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
))) {
3192 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3195 starget_printk(KERN_WARNING
, starget
, "predicted fault\n");
3196 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3198 if (ioc
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_IBM
) {
3199 memset(&mpi_request
, 0, sizeof(Mpi2SepRequest_t
));
3200 mpi_request
.Function
= MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR
;
3201 mpi_request
.Action
= MPI2_SEP_REQ_ACTION_WRITE_STATUS
;
3202 mpi_request
.SlotStatus
=
3203 MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT
;
3204 mpi_request
.DevHandle
= cpu_to_le16(handle
);
3205 mpi_request
.Flags
= MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS
;
3206 if ((mpt2sas_base_scsi_enclosure_processor(ioc
, &mpi_reply
,
3207 &mpi_request
)) != 0) {
3208 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3209 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3213 if (mpi_reply
.IOCStatus
|| mpi_reply
.IOCLogInfo
) {
3214 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3215 "enclosure_processor: ioc_status (0x%04x), "
3216 "loginfo(0x%08x)\n", ioc
->name
,
3217 le16_to_cpu(mpi_reply
.IOCStatus
),
3218 le32_to_cpu(mpi_reply
.IOCLogInfo
)));
3223 /* insert into event log */
3224 sz
= offsetof(Mpi2EventNotificationReply_t
, EventData
) +
3225 sizeof(Mpi2EventDataSasDeviceStatusChange_t
);
3226 event_reply
= kzalloc(sz
, GFP_KERNEL
);
3228 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3229 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3233 event_reply
->Function
= MPI2_FUNCTION_EVENT_NOTIFICATION
;
3234 event_reply
->Event
=
3235 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
);
3236 event_reply
->MsgLength
= sz
/4;
3237 event_reply
->EventDataLength
=
3238 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t
)/4);
3239 event_data
= (Mpi2EventDataSasDeviceStatusChange_t
*)
3240 event_reply
->EventData
;
3241 event_data
->ReasonCode
= MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
;
3242 event_data
->ASC
= 0x5D;
3243 event_data
->DevHandle
= cpu_to_le16(handle
);
3244 event_data
->SASAddress
= cpu_to_le64(sas_target_priv_data
->sas_address
);
3245 mpt2sas_ctl_add_to_event_log(ioc
, event_reply
);
3250 * _scsih_io_done - scsi request callback
3251 * @ioc: per adapter object
3252 * @smid: system request message index
3253 * @msix_index: MSIX table index supplied by the OS
3254 * @reply: reply message frame(lower 32bit addr)
3256 * Callback handler when using _scsih_qcmd.
3258 * Return 1 meaning mf should be freed from _base_interrupt
3259 * 0 means the mf is freed from this function.
3262 _scsih_io_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
3264 Mpi2SCSIIORequest_t
*mpi_request
;
3265 Mpi2SCSIIOReply_t
*mpi_reply
;
3266 struct scsi_cmnd
*scmd
;
3272 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
3273 u32 response_code
= 0;
3275 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
3276 scmd
= _scsih_scsi_lookup_get(ioc
, smid
);
3280 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3282 if (mpi_reply
== NULL
) {
3283 scmd
->result
= DID_OK
<< 16;
3287 sas_device_priv_data
= scmd
->device
->hostdata
;
3288 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
||
3289 sas_device_priv_data
->sas_target
->deleted
) {
3290 scmd
->result
= DID_NO_CONNECT
<< 16;
3294 /* turning off TLR */
3295 scsi_state
= mpi_reply
->SCSIState
;
3296 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
3298 le32_to_cpu(mpi_reply
->ResponseInfo
) & 0xFF;
3299 if (!sas_device_priv_data
->tlr_snoop_check
) {
3300 sas_device_priv_data
->tlr_snoop_check
++;
3301 if ((sas_device_priv_data
->flags
& MPT_DEVICE_TLR_ON
) &&
3302 response_code
== MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
)
3303 sas_device_priv_data
->flags
&=
3307 xfer_cnt
= le32_to_cpu(mpi_reply
->TransferCount
);
3308 scsi_set_resid(scmd
, scsi_bufflen(scmd
) - xfer_cnt
);
3309 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
);
3310 if (ioc_status
& MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE
)
3311 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
3314 ioc_status
&= MPI2_IOCSTATUS_MASK
;
3315 scsi_status
= mpi_reply
->SCSIStatus
;
3317 if (ioc_status
== MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
&& xfer_cnt
== 0 &&
3318 (scsi_status
== MPI2_SCSI_STATUS_BUSY
||
3319 scsi_status
== MPI2_SCSI_STATUS_RESERVATION_CONFLICT
||
3320 scsi_status
== MPI2_SCSI_STATUS_TASK_SET_FULL
)) {
3321 ioc_status
= MPI2_IOCSTATUS_SUCCESS
;
3324 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
3325 struct sense_info data
;
3326 const void *sense_data
= mpt2sas_base_get_sense_buffer(ioc
,
3328 u32 sz
= min_t(u32
, SCSI_SENSE_BUFFERSIZE
,
3329 le32_to_cpu(mpi_reply
->SenseCount
));
3330 memcpy(scmd
->sense_buffer
, sense_data
, sz
);
3331 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
3332 /* failure prediction threshold exceeded */
3333 if (data
.asc
== 0x5D)
3334 _scsih_smart_predicted_fault(ioc
,
3335 le16_to_cpu(mpi_reply
->DevHandle
));
3338 switch (ioc_status
) {
3339 case MPI2_IOCSTATUS_BUSY
:
3340 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES
:
3341 scmd
->result
= SAM_STAT_BUSY
;
3344 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
3345 scmd
->result
= DID_NO_CONNECT
<< 16;
3348 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
3349 if (sas_device_priv_data
->block
) {
3350 scmd
->result
= DID_TRANSPORT_DISRUPTED
<< 16;
3353 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
3354 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
3355 scmd
->result
= DID_RESET
<< 16;
3358 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
3359 if ((xfer_cnt
== 0) || (scmd
->underflow
> xfer_cnt
))
3360 scmd
->result
= DID_SOFT_ERROR
<< 16;
3362 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
3365 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
3366 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
3368 if ((scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
))
3371 if (xfer_cnt
< scmd
->underflow
) {
3372 if (scsi_status
== SAM_STAT_BUSY
)
3373 scmd
->result
= SAM_STAT_BUSY
;
3375 scmd
->result
= DID_SOFT_ERROR
<< 16;
3376 } else if (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
3377 MPI2_SCSI_STATE_NO_SCSI_STATUS
))
3378 scmd
->result
= DID_SOFT_ERROR
<< 16;
3379 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
3380 scmd
->result
= DID_RESET
<< 16;
3381 else if (!xfer_cnt
&& scmd
->cmnd
[0] == REPORT_LUNS
) {
3382 mpi_reply
->SCSIState
= MPI2_SCSI_STATE_AUTOSENSE_VALID
;
3383 mpi_reply
->SCSIStatus
= SAM_STAT_CHECK_CONDITION
;
3384 scmd
->result
= (DRIVER_SENSE
<< 24) |
3385 SAM_STAT_CHECK_CONDITION
;
3386 scmd
->sense_buffer
[0] = 0x70;
3387 scmd
->sense_buffer
[2] = ILLEGAL_REQUEST
;
3388 scmd
->sense_buffer
[12] = 0x20;
3389 scmd
->sense_buffer
[13] = 0;
3393 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
3394 scsi_set_resid(scmd
, 0);
3395 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
3396 case MPI2_IOCSTATUS_SUCCESS
:
3397 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
3398 if (response_code
==
3399 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
||
3400 (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
3401 MPI2_SCSI_STATE_NO_SCSI_STATUS
)))
3402 scmd
->result
= DID_SOFT_ERROR
<< 16;
3403 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
3404 scmd
->result
= DID_RESET
<< 16;
3407 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
3408 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
3409 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
3410 _scsih_eedp_error_handling(scmd
, ioc_status
);
3412 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
3413 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
3414 case MPI2_IOCSTATUS_INVALID_SGL
:
3415 case MPI2_IOCSTATUS_INTERNAL_ERROR
:
3416 case MPI2_IOCSTATUS_INVALID_FIELD
:
3417 case MPI2_IOCSTATUS_INVALID_STATE
:
3418 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
3419 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
3421 scmd
->result
= DID_SOFT_ERROR
<< 16;
3426 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3427 if (scmd
->result
&& (ioc
->logging_level
& MPT_DEBUG_REPLY
))
3428 _scsih_scsi_ioc_info(ioc
, scmd
, mpi_reply
, smid
);
3432 scsi_dma_unmap(scmd
);
3433 scmd
->scsi_done(scmd
);
3438 * _scsih_sas_host_refresh - refreshing sas host object contents
3439 * @ioc: per adapter object
3442 * During port enable, fw will send topology events for every device. Its
3443 * possible that the handles may change from the previous setting, so this
3444 * code keeping handles updating if changed.
3449 _scsih_sas_host_refresh(struct MPT2SAS_ADAPTER
*ioc
)
3454 Mpi2ConfigReply_t mpi_reply
;
3455 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
3456 u16 attached_handle
;
3458 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
3459 "updating handles for sas_host(0x%016llx)\n",
3460 ioc
->name
, (unsigned long long)ioc
->sas_hba
.sas_address
));
3462 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
3463 * sizeof(Mpi2SasIOUnit0PhyData_t
));
3464 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
3465 if (!sas_iounit_pg0
) {
3466 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3467 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3471 if ((mpt2sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
3472 sas_iounit_pg0
, sz
)) != 0)
3474 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
3475 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
3477 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
3479 ioc
->sas_hba
.handle
= le16_to_cpu(sas_iounit_pg0
->
3480 PhyData
[0].ControllerDevHandle
);
3481 ioc
->sas_hba
.phy
[i
].handle
= ioc
->sas_hba
.handle
;
3482 attached_handle
= le16_to_cpu(sas_iounit_pg0
->PhyData
[i
].
3484 mpt2sas_transport_update_links(ioc
, ioc
->sas_hba
.sas_address
,
3485 attached_handle
, i
, sas_iounit_pg0
->PhyData
[i
].
3486 NegotiatedLinkRate
>> 4);
3489 kfree(sas_iounit_pg0
);
3493 * _scsih_sas_host_add - create sas host object
3494 * @ioc: per adapter object
3496 * Creating host side data object, stored in ioc->sas_hba
3501 _scsih_sas_host_add(struct MPT2SAS_ADAPTER
*ioc
)
3504 Mpi2ConfigReply_t mpi_reply
;
3505 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
3506 Mpi2SasIOUnitPage1_t
*sas_iounit_pg1
= NULL
;
3507 Mpi2SasPhyPage0_t phy_pg0
;
3508 Mpi2SasDevicePage0_t sas_device_pg0
;
3509 Mpi2SasEnclosurePage0_t enclosure_pg0
;
3512 u16 device_missing_delay
;
3514 mpt2sas_config_get_number_hba_phys(ioc
, &ioc
->sas_hba
.num_phys
);
3515 if (!ioc
->sas_hba
.num_phys
) {
3516 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3517 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3521 /* sas_iounit page 0 */
3522 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
3523 sizeof(Mpi2SasIOUnit0PhyData_t
));
3524 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
3525 if (!sas_iounit_pg0
) {
3526 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3527 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3530 if ((mpt2sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
3531 sas_iounit_pg0
, sz
))) {
3532 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3533 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3536 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
3537 MPI2_IOCSTATUS_MASK
;
3538 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
3539 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3540 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3544 /* sas_iounit page 1 */
3545 sz
= offsetof(Mpi2SasIOUnitPage1_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
3546 sizeof(Mpi2SasIOUnit1PhyData_t
));
3547 sas_iounit_pg1
= kzalloc(sz
, GFP_KERNEL
);
3548 if (!sas_iounit_pg1
) {
3549 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3550 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3553 if ((mpt2sas_config_get_sas_iounit_pg1(ioc
, &mpi_reply
,
3554 sas_iounit_pg1
, sz
))) {
3555 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3556 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3559 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
3560 MPI2_IOCSTATUS_MASK
;
3561 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
3562 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3563 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3567 ioc
->io_missing_delay
=
3568 le16_to_cpu(sas_iounit_pg1
->IODeviceMissingDelay
);
3569 device_missing_delay
=
3570 le16_to_cpu(sas_iounit_pg1
->ReportDeviceMissingDelay
);
3571 if (device_missing_delay
& MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16
)
3572 ioc
->device_missing_delay
= (device_missing_delay
&
3573 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
) * 16;
3575 ioc
->device_missing_delay
= device_missing_delay
&
3576 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
;
3578 ioc
->sas_hba
.parent_dev
= &ioc
->shost
->shost_gendev
;
3579 ioc
->sas_hba
.phy
= kcalloc(ioc
->sas_hba
.num_phys
,
3580 sizeof(struct _sas_phy
), GFP_KERNEL
);
3581 if (!ioc
->sas_hba
.phy
) {
3582 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3583 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3586 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
3587 if ((mpt2sas_config_get_phy_pg0(ioc
, &mpi_reply
, &phy_pg0
,
3589 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3590 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3593 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
3594 MPI2_IOCSTATUS_MASK
;
3595 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
3596 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3597 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3602 ioc
->sas_hba
.handle
= le16_to_cpu(sas_iounit_pg0
->
3603 PhyData
[0].ControllerDevHandle
);
3604 ioc
->sas_hba
.phy
[i
].handle
= ioc
->sas_hba
.handle
;
3605 ioc
->sas_hba
.phy
[i
].phy_id
= i
;
3606 mpt2sas_transport_add_host_phy(ioc
, &ioc
->sas_hba
.phy
[i
],
3607 phy_pg0
, ioc
->sas_hba
.parent_dev
);
3609 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
3610 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, ioc
->sas_hba
.handle
))) {
3611 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3612 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3615 ioc
->sas_hba
.enclosure_handle
=
3616 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
3617 ioc
->sas_hba
.sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
3618 printk(MPT2SAS_INFO_FMT
"host_add: handle(0x%04x), "
3619 "sas_addr(0x%016llx), phys(%d)\n", ioc
->name
, ioc
->sas_hba
.handle
,
3620 (unsigned long long) ioc
->sas_hba
.sas_address
,
3621 ioc
->sas_hba
.num_phys
) ;
3623 if (ioc
->sas_hba
.enclosure_handle
) {
3624 if (!(mpt2sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
3626 MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
3627 ioc
->sas_hba
.enclosure_handle
))) {
3628 ioc
->sas_hba
.enclosure_logical_id
=
3629 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
3634 kfree(sas_iounit_pg1
);
3635 kfree(sas_iounit_pg0
);
3639 * _scsih_expander_add - creating expander object
3640 * @ioc: per adapter object
3641 * @handle: expander handle
3643 * Creating expander object, stored in ioc->sas_expander_list.
3645 * Return 0 for success, else error.
3648 _scsih_expander_add(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
3650 struct _sas_node
*sas_expander
;
3651 Mpi2ConfigReply_t mpi_reply
;
3652 Mpi2ExpanderPage0_t expander_pg0
;
3653 Mpi2ExpanderPage1_t expander_pg1
;
3654 Mpi2SasEnclosurePage0_t enclosure_pg0
;
3657 __le64 sas_address
, sas_address_parent
= 0;
3659 unsigned long flags
;
3660 struct _sas_port
*mpt2sas_port
= NULL
;
3666 if (ioc
->shost_recovery
)
3669 if ((mpt2sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
3670 MPI2_SAS_EXPAND_PGAD_FORM_HNDL
, handle
))) {
3671 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3672 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3676 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
3677 MPI2_IOCSTATUS_MASK
;
3678 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
3679 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3680 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3684 /* handle out of order topology events */
3685 parent_handle
= le16_to_cpu(expander_pg0
.ParentDevHandle
);
3686 if (_scsih_get_sas_address(ioc
, parent_handle
, &sas_address_parent
)
3688 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3689 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3692 if (sas_address_parent
!= ioc
->sas_hba
.sas_address
) {
3693 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
3694 sas_expander
= mpt2sas_scsih_expander_find_by_sas_address(ioc
,
3695 sas_address_parent
);
3696 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
3697 if (!sas_expander
) {
3698 rc
= _scsih_expander_add(ioc
, parent_handle
);
3704 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
3705 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
3706 sas_expander
= mpt2sas_scsih_expander_find_by_sas_address(ioc
,
3708 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
3713 sas_expander
= kzalloc(sizeof(struct _sas_node
),
3715 if (!sas_expander
) {
3716 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3717 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3721 sas_expander
->handle
= handle
;
3722 sas_expander
->num_phys
= expander_pg0
.NumPhys
;
3723 sas_expander
->sas_address_parent
= sas_address_parent
;
3724 sas_expander
->sas_address
= sas_address
;
3726 printk(MPT2SAS_INFO_FMT
"expander_add: handle(0x%04x),"
3727 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc
->name
,
3728 handle
, parent_handle
, (unsigned long long)
3729 sas_expander
->sas_address
, sas_expander
->num_phys
);
3731 if (!sas_expander
->num_phys
)
3733 sas_expander
->phy
= kcalloc(sas_expander
->num_phys
,
3734 sizeof(struct _sas_phy
), GFP_KERNEL
);
3735 if (!sas_expander
->phy
) {
3736 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3737 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3742 INIT_LIST_HEAD(&sas_expander
->sas_port_list
);
3743 mpt2sas_port
= mpt2sas_transport_port_add(ioc
, handle
,
3744 sas_address_parent
);
3745 if (!mpt2sas_port
) {
3746 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3747 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3751 sas_expander
->parent_dev
= &mpt2sas_port
->rphy
->dev
;
3753 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++) {
3754 if ((mpt2sas_config_get_expander_pg1(ioc
, &mpi_reply
,
3755 &expander_pg1
, i
, handle
))) {
3756 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3757 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3761 sas_expander
->phy
[i
].handle
= handle
;
3762 sas_expander
->phy
[i
].phy_id
= i
;
3764 if ((mpt2sas_transport_add_expander_phy(ioc
,
3765 &sas_expander
->phy
[i
], expander_pg1
,
3766 sas_expander
->parent_dev
))) {
3767 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3768 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3774 if (sas_expander
->enclosure_handle
) {
3775 if (!(mpt2sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
3776 &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
3777 sas_expander
->enclosure_handle
))) {
3778 sas_expander
->enclosure_logical_id
=
3779 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
3783 _scsih_expander_node_add(ioc
, sas_expander
);
3789 mpt2sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
3790 sas_address_parent
);
3791 kfree(sas_expander
);
3796 * _scsih_done - scsih callback handler.
3797 * @ioc: per adapter object
3798 * @smid: system request message index
3799 * @msix_index: MSIX table index supplied by the OS
3800 * @reply: reply message frame(lower 32bit addr)
3802 * Callback handler when sending internal generated message frames.
3803 * The callback index passed is `ioc->scsih_cb_idx`
3805 * Return 1 meaning mf should be freed from _base_interrupt
3806 * 0 means the mf is freed from this function.
3809 _scsih_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
3811 MPI2DefaultReply_t
*mpi_reply
;
3813 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
3814 if (ioc
->scsih_cmds
.status
== MPT2_CMD_NOT_USED
)
3816 if (ioc
->scsih_cmds
.smid
!= smid
)
3818 ioc
->scsih_cmds
.status
|= MPT2_CMD_COMPLETE
;
3820 memcpy(ioc
->scsih_cmds
.reply
, mpi_reply
,
3821 mpi_reply
->MsgLength
*4);
3822 ioc
->scsih_cmds
.status
|= MPT2_CMD_REPLY_VALID
;
3824 ioc
->scsih_cmds
.status
&= ~MPT2_CMD_PENDING
;
3825 complete(&ioc
->scsih_cmds
.done
);
3830 * _scsih_expander_remove - removing expander object
3831 * @ioc: per adapter object
3832 * @sas_address: expander sas_address
3837 _scsih_expander_remove(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
)
3839 struct _sas_node
*sas_expander
;
3840 unsigned long flags
;
3842 if (ioc
->shost_recovery
)
3845 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
3846 sas_expander
= mpt2sas_scsih_expander_find_by_sas_address(ioc
,
3848 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
3849 _scsih_expander_node_remove(ioc
, sas_expander
);
3853 * _scsih_add_device - creating sas device object
3854 * @ioc: per adapter object
3855 * @handle: sas device handle
3856 * @phy_num: phy number end device attached to
3857 * @is_pd: is this hidden raid component
3859 * Creating end device object, stored in ioc->sas_device_list.
3861 * Returns 0 for success, non-zero for failure.
3864 _scsih_add_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
, u8 phy_num
, u8 is_pd
)
3866 Mpi2ConfigReply_t mpi_reply
;
3867 Mpi2SasDevicePage0_t sas_device_pg0
;
3868 Mpi2SasEnclosurePage0_t enclosure_pg0
;
3869 struct _sas_device
*sas_device
;
3873 unsigned long flags
;
3875 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
3876 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
3877 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3878 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3882 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
3883 MPI2_IOCSTATUS_MASK
;
3884 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
3885 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3886 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3890 /* check if device is present */
3891 if (!(le16_to_cpu(sas_device_pg0
.Flags
) &
3892 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT
)) {
3893 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3894 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3895 printk(MPT2SAS_ERR_FMT
"Flags = 0x%04x\n",
3896 ioc
->name
, le16_to_cpu(sas_device_pg0
.Flags
));
3900 /* check if there were any issus with discovery */
3901 if (sas_device_pg0
.AccessStatus
==
3902 MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED
) {
3903 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3904 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3905 printk(MPT2SAS_ERR_FMT
"AccessStatus = 0x%02x\n",
3906 ioc
->name
, sas_device_pg0
.AccessStatus
);
3910 /* check if this is end device */
3911 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
3912 if (!(_scsih_is_end_device(device_info
))) {
3913 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3914 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3918 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
3920 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
3921 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
3923 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3926 _scsih_ublock_io_device(ioc
, handle
);
3930 sas_device
= kzalloc(sizeof(struct _sas_device
),
3933 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3934 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3938 sas_device
->handle
= handle
;
3939 if (_scsih_get_sas_address(ioc
, le16_to_cpu
3940 (sas_device_pg0
.ParentDevHandle
),
3941 &sas_device
->sas_address_parent
) != 0)
3942 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3943 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3944 sas_device
->enclosure_handle
=
3945 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
3947 le16_to_cpu(sas_device_pg0
.Slot
);
3948 sas_device
->device_info
= device_info
;
3949 sas_device
->sas_address
= sas_address
;
3950 sas_device
->hidden_raid_component
= is_pd
;
3952 /* get enclosure_logical_id */
3953 if (sas_device
->enclosure_handle
&& !(mpt2sas_config_get_enclosure_pg0(
3954 ioc
, &mpi_reply
, &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
3955 sas_device
->enclosure_handle
)))
3956 sas_device
->enclosure_logical_id
=
3957 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
3959 /* get device name */
3960 sas_device
->device_name
= le64_to_cpu(sas_device_pg0
.DeviceName
);
3962 if (ioc
->wait_for_port_enable_to_complete
)
3963 _scsih_sas_device_init_add(ioc
, sas_device
);
3965 _scsih_sas_device_add(ioc
, sas_device
);
3971 * _scsih_remove_device - removing sas device object
3972 * @ioc: per adapter object
3973 * @sas_device: the sas_device object
3978 _scsih_remove_device(struct MPT2SAS_ADAPTER
*ioc
, struct _sas_device
3981 struct MPT2SAS_TARGET
*sas_target_priv_data
;
3982 Mpi2SasIoUnitControlReply_t mpi_reply
;
3983 Mpi2SasIoUnitControlRequest_t mpi_request
;
3984 u16 device_handle
, handle
;
3989 handle
= sas_device
->handle
;
3990 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: enter: handle(0x%04x),"
3991 " sas_addr(0x%016llx)\n", ioc
->name
, __func__
, handle
,
3992 (unsigned long long) sas_device
->sas_address
));
3994 if (sas_device
->starget
&& sas_device
->starget
->hostdata
) {
3995 sas_target_priv_data
= sas_device
->starget
->hostdata
;
3996 sas_target_priv_data
->deleted
= 1;
3999 if (ioc
->remove_host
|| ioc
->shost_recovery
|| !handle
)
4002 if ((sas_device
->state
& MPTSAS_STATE_TR_COMPLETE
)) {
4003 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"\tskip "
4004 "target_reset handle(0x%04x)\n", ioc
->name
,
4009 /* Target Reset to flush out all the outstanding IO */
4010 device_handle
= (sas_device
->hidden_raid_component
) ?
4011 sas_device
->volume_handle
: handle
;
4012 if (device_handle
) {
4013 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"issue target reset: "
4014 "handle(0x%04x)\n", ioc
->name
, device_handle
));
4015 mutex_lock(&ioc
->tm_cmds
.mutex
);
4016 mpt2sas_scsih_issue_tm(ioc
, device_handle
, 0,
4017 MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
, 0, 10);
4018 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
4019 mutex_unlock(&ioc
->tm_cmds
.mutex
);
4020 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"issue target reset "
4021 "done: handle(0x%04x)\n", ioc
->name
, device_handle
));
4022 if (ioc
->shost_recovery
)
4027 if ((sas_device
->state
& MPTSAS_STATE_CNTRL_COMPLETE
)) {
4028 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"\tskip "
4029 "sas_cntrl handle(0x%04x)\n", ioc
->name
, handle
));
4033 /* SAS_IO_UNIT_CNTR - send REMOVE_DEVICE */
4034 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"sas_iounit: handle"
4035 "(0x%04x)\n", ioc
->name
, handle
));
4036 memset(&mpi_request
, 0, sizeof(Mpi2SasIoUnitControlRequest_t
));
4037 mpi_request
.Function
= MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
;
4038 mpi_request
.Operation
= MPI2_SAS_OP_REMOVE_DEVICE
;
4039 mpi_request
.DevHandle
= handle
;
4040 mpi_request
.VF_ID
= 0; /* TODO */
4041 mpi_request
.VP_ID
= 0;
4042 if ((mpt2sas_base_sas_iounit_control(ioc
, &mpi_reply
,
4043 &mpi_request
)) != 0) {
4044 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4045 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4048 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"sas_iounit: ioc_status"
4049 "(0x%04x), loginfo(0x%08x)\n", ioc
->name
,
4050 le16_to_cpu(mpi_reply
.IOCStatus
),
4051 le32_to_cpu(mpi_reply
.IOCLogInfo
)));
4055 _scsih_ublock_io_device(ioc
, handle
);
4057 mpt2sas_transport_port_remove(ioc
, sas_device
->sas_address
,
4058 sas_device
->sas_address_parent
);
4060 printk(MPT2SAS_INFO_FMT
"removing handle(0x%04x), sas_addr"
4061 "(0x%016llx)\n", ioc
->name
, handle
,
4062 (unsigned long long) sas_device
->sas_address
);
4063 _scsih_sas_device_remove(ioc
, sas_device
);
4065 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: exit: handle"
4066 "(0x%04x)\n", ioc
->name
, __func__
, handle
));
4069 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4071 * _scsih_sas_topology_change_event_debug - debug for topology event
4072 * @ioc: per adapter object
4073 * @event_data: event data payload
4077 _scsih_sas_topology_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
4078 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
4084 char *status_str
= NULL
;
4085 u8 link_rate
, prev_link_rate
;
4087 switch (event_data
->ExpStatus
) {
4088 case MPI2_EVENT_SAS_TOPO_ES_ADDED
:
4091 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
:
4092 status_str
= "remove";
4094 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING
:
4096 status_str
= "responding";
4098 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
:
4099 status_str
= "remove delay";
4102 status_str
= "unknown status";
4105 printk(MPT2SAS_DEBUG_FMT
"sas topology change: (%s)\n",
4106 ioc
->name
, status_str
);
4107 printk(KERN_DEBUG
"\thandle(0x%04x), enclosure_handle(0x%04x) "
4108 "start_phy(%02d), count(%d)\n",
4109 le16_to_cpu(event_data
->ExpanderDevHandle
),
4110 le16_to_cpu(event_data
->EnclosureHandle
),
4111 event_data
->StartPhyNum
, event_data
->NumEntries
);
4112 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
4113 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
4116 phy_number
= event_data
->StartPhyNum
+ i
;
4117 reason_code
= event_data
->PHY
[i
].PhyStatus
&
4118 MPI2_EVENT_SAS_TOPO_RC_MASK
;
4119 switch (reason_code
) {
4120 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
4121 status_str
= "target add";
4123 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
4124 status_str
= "target remove";
4126 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
:
4127 status_str
= "delay target remove";
4129 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
4130 status_str
= "link rate change";
4132 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE
:
4133 status_str
= "target responding";
4136 status_str
= "unknown";
4139 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
4140 prev_link_rate
= event_data
->PHY
[i
].LinkRate
& 0xF;
4141 printk(KERN_DEBUG
"\tphy(%02d), attached_handle(0x%04x): %s:"
4142 " link rate: new(0x%02x), old(0x%02x)\n", phy_number
,
4143 handle
, status_str
, link_rate
, prev_link_rate
);
4150 * _scsih_sas_topology_change_event - handle topology changes
4151 * @ioc: per adapter object
4152 * @fw_event: The fw_event_work object
4157 _scsih_sas_topology_change_event(struct MPT2SAS_ADAPTER
*ioc
,
4158 struct fw_event_work
*fw_event
)
4161 u16 parent_handle
, handle
;
4164 struct _sas_node
*sas_expander
;
4165 struct _sas_device
*sas_device
;
4167 unsigned long flags
;
4168 u8 link_rate
, prev_link_rate
;
4169 Mpi2EventDataSasTopologyChangeList_t
*event_data
= fw_event
->event_data
;
4171 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4172 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
4173 _scsih_sas_topology_change_event_debug(ioc
, event_data
);
4176 if (ioc
->shost_recovery
)
4179 if (!ioc
->sas_hba
.num_phys
)
4180 _scsih_sas_host_add(ioc
);
4182 _scsih_sas_host_refresh(ioc
);
4184 if (fw_event
->ignore
) {
4185 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"ignoring expander "
4186 "event\n", ioc
->name
));
4190 parent_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
4192 /* handle expander add */
4193 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_ADDED
)
4194 if (_scsih_expander_add(ioc
, parent_handle
) != 0)
4197 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
4198 sas_expander
= mpt2sas_scsih_expander_find_by_handle(ioc
,
4200 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
4202 sas_address
= sas_expander
->sas_address
;
4203 else if (parent_handle
< ioc
->sas_hba
.num_phys
)
4204 sas_address
= ioc
->sas_hba
.sas_address
;
4208 /* handle siblings events */
4209 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
4210 if (fw_event
->ignore
) {
4211 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"ignoring "
4212 "expander event\n", ioc
->name
));
4215 if (ioc
->shost_recovery
)
4217 phy_number
= event_data
->StartPhyNum
+ i
;
4218 reason_code
= event_data
->PHY
[i
].PhyStatus
&
4219 MPI2_EVENT_SAS_TOPO_RC_MASK
;
4220 if ((event_data
->PHY
[i
].PhyStatus
&
4221 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT
) && (reason_code
!=
4222 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
))
4224 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
4227 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
4228 prev_link_rate
= event_data
->PHY
[i
].LinkRate
& 0xF;
4229 switch (reason_code
) {
4230 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
4232 if (link_rate
== prev_link_rate
)
4235 mpt2sas_transport_update_links(ioc
, sas_address
,
4236 handle
, phy_number
, link_rate
);
4238 if (link_rate
>= MPI2_SAS_NEG_LINK_RATE_1_5
)
4239 _scsih_ublock_io_device(ioc
, handle
);
4241 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
4243 mpt2sas_transport_update_links(ioc
, sas_address
,
4244 handle
, phy_number
, link_rate
);
4246 _scsih_add_device(ioc
, handle
, phy_number
, 0);
4248 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
4250 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4251 sas_device
= _scsih_sas_device_find_by_handle(ioc
,
4254 spin_unlock_irqrestore(&ioc
->sas_device_lock
,
4258 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4259 _scsih_remove_device(ioc
, sas_device
);
4264 /* handle expander removal */
4265 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
&&
4267 _scsih_expander_remove(ioc
, sas_address
);
4271 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4273 * _scsih_sas_device_status_change_event_debug - debug for device event
4274 * @event_data: event data payload
4280 _scsih_sas_device_status_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
4281 Mpi2EventDataSasDeviceStatusChange_t
*event_data
)
4283 char *reason_str
= NULL
;
4285 switch (event_data
->ReasonCode
) {
4286 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
:
4287 reason_str
= "smart data";
4289 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED
:
4290 reason_str
= "unsupported device discovered";
4292 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
:
4293 reason_str
= "internal device reset";
4295 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL
:
4296 reason_str
= "internal task abort";
4298 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL
:
4299 reason_str
= "internal task abort set";
4301 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL
:
4302 reason_str
= "internal clear task set";
4304 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL
:
4305 reason_str
= "internal query task";
4307 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE
:
4308 reason_str
= "sata init failure";
4310 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
:
4311 reason_str
= "internal device reset complete";
4313 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL
:
4314 reason_str
= "internal task abort complete";
4316 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION
:
4317 reason_str
= "internal async notification";
4319 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY
:
4320 reason_str
= "expander reduced functionality";
4322 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY
:
4323 reason_str
= "expander reduced functionality complete";
4326 reason_str
= "unknown reason";
4329 printk(MPT2SAS_DEBUG_FMT
"device status change: (%s)\n"
4330 "\thandle(0x%04x), sas address(0x%016llx)", ioc
->name
,
4331 reason_str
, le16_to_cpu(event_data
->DevHandle
),
4332 (unsigned long long)le64_to_cpu(event_data
->SASAddress
));
4333 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
)
4334 printk(MPT2SAS_DEBUG_FMT
", ASC(0x%x), ASCQ(0x%x)\n", ioc
->name
,
4335 event_data
->ASC
, event_data
->ASCQ
);
4336 printk(KERN_INFO
"\n");
4341 * _scsih_sas_device_status_change_event - handle device status change
4342 * @ioc: per adapter object
4343 * @fw_event: The fw_event_work object
4349 _scsih_sas_device_status_change_event(struct MPT2SAS_ADAPTER
*ioc
,
4350 struct fw_event_work
*fw_event
)
4352 struct MPT2SAS_TARGET
*target_priv_data
;
4353 struct _sas_device
*sas_device
;
4355 unsigned long flags
;
4356 Mpi2EventDataSasDeviceStatusChange_t
*event_data
=
4357 fw_event
->event_data
;
4359 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4360 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
4361 _scsih_sas_device_status_change_event_debug(ioc
,
4365 if (!(event_data
->ReasonCode
==
4366 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
&&
4367 event_data
->ReasonCode
==
4368 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
))
4371 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4372 sas_address
= le64_to_cpu(event_data
->SASAddress
);
4373 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
4375 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4377 if (!sas_device
|| !sas_device
->starget
)
4380 target_priv_data
= sas_device
->starget
->hostdata
;
4381 if (!target_priv_data
)
4384 if (event_data
->ReasonCode
==
4385 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
)
4386 target_priv_data
->tm_busy
= 1;
4388 target_priv_data
->tm_busy
= 0;
4391 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4393 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure event
4394 * @ioc: per adapter object
4395 * @event_data: event data payload
4401 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
4402 Mpi2EventDataSasEnclDevStatusChange_t
*event_data
)
4404 char *reason_str
= NULL
;
4406 switch (event_data
->ReasonCode
) {
4407 case MPI2_EVENT_SAS_ENCL_RC_ADDED
:
4408 reason_str
= "enclosure add";
4410 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING
:
4411 reason_str
= "enclosure remove";
4414 reason_str
= "unknown reason";
4418 printk(MPT2SAS_DEBUG_FMT
"enclosure status change: (%s)\n"
4419 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
4420 " number slots(%d)\n", ioc
->name
, reason_str
,
4421 le16_to_cpu(event_data
->EnclosureHandle
),
4422 (unsigned long long)le64_to_cpu(event_data
->EnclosureLogicalID
),
4423 le16_to_cpu(event_data
->StartSlot
));
4428 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
4429 * @ioc: per adapter object
4430 * @fw_event: The fw_event_work object
4436 _scsih_sas_enclosure_dev_status_change_event(struct MPT2SAS_ADAPTER
*ioc
,
4437 struct fw_event_work
*fw_event
)
4439 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4440 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
4441 _scsih_sas_enclosure_dev_status_change_event_debug(ioc
,
4442 fw_event
->event_data
);
4447 * _scsih_sas_broadcast_primative_event - handle broadcast events
4448 * @ioc: per adapter object
4449 * @fw_event: The fw_event_work object
4455 _scsih_sas_broadcast_primative_event(struct MPT2SAS_ADAPTER
*ioc
,
4456 struct fw_event_work
*fw_event
)
4458 struct scsi_cmnd
*scmd
;
4461 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
4462 u32 termination_count
;
4464 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
4465 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4466 Mpi2EventDataSasBroadcastPrimitive_t
*event_data
= fw_event
->event_data
;
4469 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"broadcast primative: "
4470 "phy number(%d), width(%d)\n", ioc
->name
, event_data
->PhyNum
,
4471 event_data
->PortWidth
));
4472 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: enter\n", ioc
->name
,
4475 mutex_lock(&ioc
->tm_cmds
.mutex
);
4476 termination_count
= 0;
4478 mpi_reply
= ioc
->tm_cmds
.reply
;
4479 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
4480 scmd
= _scsih_scsi_lookup_get(ioc
, smid
);
4483 sas_device_priv_data
= scmd
->device
->hostdata
;
4484 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
)
4486 /* skip hidden raid components */
4487 if (sas_device_priv_data
->sas_target
->flags
&
4488 MPT_TARGET_FLAGS_RAID_COMPONENT
)
4491 if (sas_device_priv_data
->sas_target
->flags
&
4492 MPT_TARGET_FLAGS_VOLUME
)
4495 handle
= sas_device_priv_data
->sas_target
->handle
;
4496 lun
= sas_device_priv_data
->lun
;
4499 mpt2sas_scsih_issue_tm(ioc
, handle
, lun
,
4500 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK
, smid
, 30);
4501 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
4502 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
)
4503 & MPI2_IOCSTATUS_MASK
;
4504 if ((ioc_status
== MPI2_IOCSTATUS_SUCCESS
) &&
4505 (mpi_reply
->ResponseCode
==
4506 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
||
4507 mpi_reply
->ResponseCode
==
4508 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
))
4511 mpt2sas_scsih_issue_tm(ioc
, handle
, lun
,
4512 MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET
, 0, 30);
4513 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
4514 termination_count
+= le32_to_cpu(mpi_reply
->TerminationCount
);
4516 ioc
->broadcast_aen_busy
= 0;
4517 mutex_unlock(&ioc
->tm_cmds
.mutex
);
4519 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
4520 "%s - exit, query_count = %d termination_count = %d\n",
4521 ioc
->name
, __func__
, query_count
, termination_count
));
4525 * _scsih_sas_discovery_event - handle discovery events
4526 * @ioc: per adapter object
4527 * @fw_event: The fw_event_work object
4533 _scsih_sas_discovery_event(struct MPT2SAS_ADAPTER
*ioc
,
4534 struct fw_event_work
*fw_event
)
4536 Mpi2EventDataSasDiscovery_t
*event_data
= fw_event
->event_data
;
4538 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4539 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
) {
4540 printk(MPT2SAS_DEBUG_FMT
"discovery event: (%s)", ioc
->name
,
4541 (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
) ?
4543 if (event_data
->DiscoveryStatus
)
4544 printk("discovery_status(0x%08x)",
4545 le32_to_cpu(event_data
->DiscoveryStatus
));
4550 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
&&
4551 !ioc
->sas_hba
.num_phys
)
4552 _scsih_sas_host_add(ioc
);
4556 * _scsih_reprobe_lun - reprobing lun
4557 * @sdev: scsi device struct
4558 * @no_uld_attach: sdev->no_uld_attach flag setting
4562 _scsih_reprobe_lun(struct scsi_device
*sdev
, void *no_uld_attach
)
4566 sdev
->no_uld_attach
= no_uld_attach
? 1 : 0;
4567 sdev_printk(KERN_INFO
, sdev
, "%s raid component\n",
4568 sdev
->no_uld_attach
? "hidding" : "exposing");
4569 rc
= scsi_device_reprobe(sdev
);
4573 * _scsih_reprobe_target - reprobing target
4574 * @starget: scsi target struct
4575 * @no_uld_attach: sdev->no_uld_attach flag setting
4577 * Note: no_uld_attach flag determines whether the disk device is attached
4578 * to block layer. A value of `1` means to not attach.
4581 _scsih_reprobe_target(struct scsi_target
*starget
, int no_uld_attach
)
4583 struct MPT2SAS_TARGET
*sas_target_priv_data
= starget
->hostdata
;
4586 sas_target_priv_data
->flags
|= MPT_TARGET_FLAGS_RAID_COMPONENT
;
4588 sas_target_priv_data
->flags
&= ~MPT_TARGET_FLAGS_RAID_COMPONENT
;
4590 starget_for_each_device(starget
, no_uld_attach
? (void *)1 : NULL
,
4591 _scsih_reprobe_lun
);
4594 * _scsih_sas_volume_add - add new volume
4595 * @ioc: per adapter object
4596 * @element: IR config element data
4602 _scsih_sas_volume_add(struct MPT2SAS_ADAPTER
*ioc
,
4603 Mpi2EventIrConfigElement_t
*element
)
4605 struct _raid_device
*raid_device
;
4606 unsigned long flags
;
4608 u16 handle
= le16_to_cpu(element
->VolDevHandle
);
4611 mpt2sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
4613 printk(MPT2SAS_ERR_FMT
4614 "failure at %s:%d/%s()!\n", ioc
->name
,
4615 __FILE__
, __LINE__
, __func__
);
4619 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
4620 raid_device
= _scsih_raid_device_find_by_wwid(ioc
, wwid
);
4621 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
4626 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
4628 printk(MPT2SAS_ERR_FMT
4629 "failure at %s:%d/%s()!\n", ioc
->name
,
4630 __FILE__
, __LINE__
, __func__
);
4634 raid_device
->id
= ioc
->sas_id
++;
4635 raid_device
->channel
= RAID_CHANNEL
;
4636 raid_device
->handle
= handle
;
4637 raid_device
->wwid
= wwid
;
4638 _scsih_raid_device_add(ioc
, raid_device
);
4639 if (!ioc
->wait_for_port_enable_to_complete
) {
4640 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
4641 raid_device
->id
, 0);
4643 _scsih_raid_device_remove(ioc
, raid_device
);
4645 _scsih_determine_boot_device(ioc
, raid_device
, 1);
4649 * _scsih_sas_volume_delete - delete volume
4650 * @ioc: per adapter object
4651 * @element: IR config element data
4657 _scsih_sas_volume_delete(struct MPT2SAS_ADAPTER
*ioc
,
4658 Mpi2EventIrConfigElement_t
*element
)
4660 struct _raid_device
*raid_device
;
4661 u16 handle
= le16_to_cpu(element
->VolDevHandle
);
4662 unsigned long flags
;
4663 struct MPT2SAS_TARGET
*sas_target_priv_data
;
4665 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
4666 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
4667 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
4670 if (raid_device
->starget
) {
4671 sas_target_priv_data
= raid_device
->starget
->hostdata
;
4672 sas_target_priv_data
->deleted
= 1;
4673 scsi_remove_target(&raid_device
->starget
->dev
);
4675 _scsih_raid_device_remove(ioc
, raid_device
);
4679 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
4680 * @ioc: per adapter object
4681 * @element: IR config element data
4687 _scsih_sas_pd_expose(struct MPT2SAS_ADAPTER
*ioc
,
4688 Mpi2EventIrConfigElement_t
*element
)
4690 struct _sas_device
*sas_device
;
4691 unsigned long flags
;
4692 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
4694 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4695 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
4696 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4700 /* exposing raid component */
4701 sas_device
->volume_handle
= 0;
4702 sas_device
->volume_wwid
= 0;
4703 sas_device
->hidden_raid_component
= 0;
4704 _scsih_reprobe_target(sas_device
->starget
, 0);
4708 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
4709 * @ioc: per adapter object
4710 * @element: IR config element data
4716 _scsih_sas_pd_hide(struct MPT2SAS_ADAPTER
*ioc
,
4717 Mpi2EventIrConfigElement_t
*element
)
4719 struct _sas_device
*sas_device
;
4720 unsigned long flags
;
4721 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
4723 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4724 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
4725 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4729 /* hiding raid component */
4730 mpt2sas_config_get_volume_handle(ioc
, handle
,
4731 &sas_device
->volume_handle
);
4732 mpt2sas_config_get_volume_wwid(ioc
, sas_device
->volume_handle
,
4733 &sas_device
->volume_wwid
);
4734 sas_device
->hidden_raid_component
= 1;
4735 _scsih_reprobe_target(sas_device
->starget
, 1);
4739 * _scsih_sas_pd_delete - delete pd component
4740 * @ioc: per adapter object
4741 * @element: IR config element data
4747 _scsih_sas_pd_delete(struct MPT2SAS_ADAPTER
*ioc
,
4748 Mpi2EventIrConfigElement_t
*element
)
4750 struct _sas_device
*sas_device
;
4751 unsigned long flags
;
4752 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
4754 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4755 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
4756 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4759 _scsih_remove_device(ioc
, sas_device
);
4763 * _scsih_sas_pd_add - remove pd component
4764 * @ioc: per adapter object
4765 * @element: IR config element data
4771 _scsih_sas_pd_add(struct MPT2SAS_ADAPTER
*ioc
,
4772 Mpi2EventIrConfigElement_t
*element
)
4774 struct _sas_device
*sas_device
;
4775 unsigned long flags
;
4776 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
4777 Mpi2ConfigReply_t mpi_reply
;
4778 Mpi2SasDevicePage0_t sas_device_pg0
;
4783 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4784 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
4785 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4787 sas_device
->hidden_raid_component
= 1;
4791 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
4792 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
4793 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4794 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4798 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4799 MPI2_IOCSTATUS_MASK
;
4800 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4801 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4802 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4806 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
4807 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
4808 mpt2sas_transport_update_links(ioc
, sas_address
, handle
,
4809 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
4811 _scsih_add_device(ioc
, handle
, 0, 1);
4814 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4816 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
4817 * @ioc: per adapter object
4818 * @event_data: event data payload
4824 _scsih_sas_ir_config_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
4825 Mpi2EventDataIrConfigChangeList_t
*event_data
)
4827 Mpi2EventIrConfigElement_t
*element
;
4830 char *reason_str
= NULL
, *element_str
= NULL
;
4832 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
4834 printk(MPT2SAS_DEBUG_FMT
"raid config change: (%s), elements(%d)\n",
4835 ioc
->name
, (le32_to_cpu(event_data
->Flags
) &
4836 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ?
4837 "foreign" : "native", event_data
->NumElements
);
4838 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
4839 switch (element
->ReasonCode
) {
4840 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
4843 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
4844 reason_str
= "remove";
4846 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE
:
4847 reason_str
= "no change";
4849 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
4850 reason_str
= "hide";
4852 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
4853 reason_str
= "unhide";
4855 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
4856 reason_str
= "volume_created";
4858 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
4859 reason_str
= "volume_deleted";
4861 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
4862 reason_str
= "pd_created";
4864 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
4865 reason_str
= "pd_deleted";
4868 reason_str
= "unknown reason";
4871 element_type
= le16_to_cpu(element
->ElementFlags
) &
4872 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK
;
4873 switch (element_type
) {
4874 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT
:
4875 element_str
= "volume";
4877 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT
:
4878 element_str
= "phys disk";
4880 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT
:
4881 element_str
= "hot spare";
4884 element_str
= "unknown element";
4887 printk(KERN_DEBUG
"\t(%s:%s), vol handle(0x%04x), "
4888 "pd handle(0x%04x), pd num(0x%02x)\n", element_str
,
4889 reason_str
, le16_to_cpu(element
->VolDevHandle
),
4890 le16_to_cpu(element
->PhysDiskDevHandle
),
4891 element
->PhysDiskNum
);
4897 * _scsih_sas_ir_config_change_event - handle ir configuration change events
4898 * @ioc: per adapter object
4899 * @fw_event: The fw_event_work object
4905 _scsih_sas_ir_config_change_event(struct MPT2SAS_ADAPTER
*ioc
,
4906 struct fw_event_work
*fw_event
)
4908 Mpi2EventIrConfigElement_t
*element
;
4911 Mpi2EventDataIrConfigChangeList_t
*event_data
= fw_event
->event_data
;
4913 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4914 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
4915 _scsih_sas_ir_config_change_event_debug(ioc
, event_data
);
4918 foreign_config
= (le32_to_cpu(event_data
->Flags
) &
4919 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ? 1 : 0;
4921 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
4922 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
4924 switch (element
->ReasonCode
) {
4925 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
4926 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
4927 if (!foreign_config
)
4928 _scsih_sas_volume_add(ioc
, element
);
4930 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
4931 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
4932 if (!foreign_config
)
4933 _scsih_sas_volume_delete(ioc
, element
);
4935 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
4936 _scsih_sas_pd_hide(ioc
, element
);
4938 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
4939 _scsih_sas_pd_expose(ioc
, element
);
4941 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
4942 _scsih_sas_pd_add(ioc
, element
);
4944 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
4945 _scsih_sas_pd_delete(ioc
, element
);
4952 * _scsih_sas_ir_volume_event - IR volume event
4953 * @ioc: per adapter object
4954 * @fw_event: The fw_event_work object
4960 _scsih_sas_ir_volume_event(struct MPT2SAS_ADAPTER
*ioc
,
4961 struct fw_event_work
*fw_event
)
4964 unsigned long flags
;
4965 struct _raid_device
*raid_device
;
4969 struct MPT2SAS_TARGET
*sas_target_priv_data
;
4970 Mpi2EventDataIrVolume_t
*event_data
= fw_event
->event_data
;
4972 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED
)
4975 handle
= le16_to_cpu(event_data
->VolDevHandle
);
4976 state
= le32_to_cpu(event_data
->NewValue
);
4977 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: handle(0x%04x), "
4978 "old(0x%08x), new(0x%08x)\n", ioc
->name
, __func__
, handle
,
4979 le32_to_cpu(event_data
->PreviousValue
), state
));
4981 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
4982 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
4983 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
4986 case MPI2_RAID_VOL_STATE_MISSING
:
4987 case MPI2_RAID_VOL_STATE_FAILED
:
4990 if (raid_device
->starget
) {
4991 sas_target_priv_data
= raid_device
->starget
->hostdata
;
4992 sas_target_priv_data
->deleted
= 1;
4993 scsi_remove_target(&raid_device
->starget
->dev
);
4995 _scsih_raid_device_remove(ioc
, raid_device
);
4998 case MPI2_RAID_VOL_STATE_ONLINE
:
4999 case MPI2_RAID_VOL_STATE_DEGRADED
:
5000 case MPI2_RAID_VOL_STATE_OPTIMAL
:
5004 mpt2sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
5006 printk(MPT2SAS_ERR_FMT
5007 "failure at %s:%d/%s()!\n", ioc
->name
,
5008 __FILE__
, __LINE__
, __func__
);
5012 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
5014 printk(MPT2SAS_ERR_FMT
5015 "failure at %s:%d/%s()!\n", ioc
->name
,
5016 __FILE__
, __LINE__
, __func__
);
5020 raid_device
->id
= ioc
->sas_id
++;
5021 raid_device
->channel
= RAID_CHANNEL
;
5022 raid_device
->handle
= handle
;
5023 raid_device
->wwid
= wwid
;
5024 _scsih_raid_device_add(ioc
, raid_device
);
5025 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
5026 raid_device
->id
, 0);
5028 _scsih_raid_device_remove(ioc
, raid_device
);
5031 case MPI2_RAID_VOL_STATE_INITIALIZING
:
5038 * _scsih_sas_ir_physical_disk_event - PD event
5039 * @ioc: per adapter object
5040 * @fw_event: The fw_event_work object
5046 _scsih_sas_ir_physical_disk_event(struct MPT2SAS_ADAPTER
*ioc
,
5047 struct fw_event_work
*fw_event
)
5049 u16 handle
, parent_handle
;
5051 struct _sas_device
*sas_device
;
5052 unsigned long flags
;
5053 Mpi2ConfigReply_t mpi_reply
;
5054 Mpi2SasDevicePage0_t sas_device_pg0
;
5056 Mpi2EventDataIrPhysicalDisk_t
*event_data
= fw_event
->event_data
;
5059 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED
)
5062 handle
= le16_to_cpu(event_data
->PhysDiskDevHandle
);
5063 state
= le32_to_cpu(event_data
->NewValue
);
5065 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: handle(0x%04x), "
5066 "old(0x%08x), new(0x%08x)\n", ioc
->name
, __func__
, handle
,
5067 le32_to_cpu(event_data
->PreviousValue
), state
));
5069 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5070 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
5071 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5074 case MPI2_RAID_PD_STATE_ONLINE
:
5075 case MPI2_RAID_PD_STATE_DEGRADED
:
5076 case MPI2_RAID_PD_STATE_REBUILDING
:
5077 case MPI2_RAID_PD_STATE_OPTIMAL
:
5079 sas_device
->hidden_raid_component
= 1;
5083 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
5084 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
5086 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5087 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5091 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5092 MPI2_IOCSTATUS_MASK
;
5093 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5094 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5095 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5099 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
5100 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
5101 mpt2sas_transport_update_links(ioc
, sas_address
, handle
,
5102 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
5104 _scsih_add_device(ioc
, handle
, 0, 1);
5108 case MPI2_RAID_PD_STATE_OFFLINE
:
5109 case MPI2_RAID_PD_STATE_NOT_CONFIGURED
:
5110 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE
:
5111 case MPI2_RAID_PD_STATE_HOT_SPARE
:
5117 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5119 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
5120 * @ioc: per adapter object
5121 * @event_data: event data payload
5127 _scsih_sas_ir_operation_status_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
5128 Mpi2EventDataIrOperationStatus_t
*event_data
)
5130 char *reason_str
= NULL
;
5132 switch (event_data
->RAIDOperation
) {
5133 case MPI2_EVENT_IR_RAIDOP_RESYNC
:
5134 reason_str
= "resync";
5136 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION
:
5137 reason_str
= "online capacity expansion";
5139 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK
:
5140 reason_str
= "consistency check";
5142 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT
:
5143 reason_str
= "background init";
5145 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT
:
5146 reason_str
= "make data consistent";
5153 printk(MPT2SAS_INFO_FMT
"raid operational status: (%s)"
5154 "\thandle(0x%04x), percent complete(%d)\n",
5155 ioc
->name
, reason_str
,
5156 le16_to_cpu(event_data
->VolDevHandle
),
5157 event_data
->PercentComplete
);
5162 * _scsih_sas_ir_operation_status_event - handle RAID operation events
5163 * @ioc: per adapter object
5164 * @fw_event: The fw_event_work object
5170 _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER
*ioc
,
5171 struct fw_event_work
*fw_event
)
5173 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5174 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5175 _scsih_sas_ir_operation_status_event_debug(ioc
,
5176 fw_event
->event_data
);
5181 * _scsih_task_set_full - handle task set full
5182 * @ioc: per adapter object
5183 * @fw_event: The fw_event_work object
5186 * Throttle back qdepth.
5189 _scsih_task_set_full(struct MPT2SAS_ADAPTER
*ioc
, struct fw_event_work
5192 unsigned long flags
;
5193 struct _sas_device
*sas_device
;
5194 static struct _raid_device
*raid_device
;
5195 struct scsi_device
*sdev
;
5201 Mpi2EventDataTaskSetFull_t
*event_data
= fw_event
->event_data
;
5203 current_depth
= le16_to_cpu(event_data
->CurrentDepth
);
5204 handle
= le16_to_cpu(event_data
->DevHandle
);
5205 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5206 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
5208 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5211 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5212 id
= sas_device
->id
;
5213 channel
= sas_device
->channel
;
5214 sas_address
= sas_device
->sas_address
;
5216 /* if hidden raid component, then change to volume characteristics */
5217 if (sas_device
->hidden_raid_component
&& sas_device
->volume_handle
) {
5218 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5219 raid_device
= _scsih_raid_device_find_by_handle(
5220 ioc
, sas_device
->volume_handle
);
5221 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5223 id
= raid_device
->id
;
5224 channel
= raid_device
->channel
;
5225 handle
= raid_device
->handle
;
5226 sas_address
= raid_device
->wwid
;
5230 if (ioc
->logging_level
& MPT_DEBUG_TASK_SET_FULL
)
5231 starget_printk(KERN_DEBUG
, sas_device
->starget
, "task set "
5232 "full: handle(0x%04x), sas_addr(0x%016llx), depth(%d)\n",
5233 handle
, (unsigned long long)sas_address
, current_depth
);
5235 shost_for_each_device(sdev
, ioc
->shost
) {
5236 if (sdev
->id
== id
&& sdev
->channel
== channel
) {
5237 if (current_depth
> sdev
->queue_depth
) {
5238 if (ioc
->logging_level
&
5239 MPT_DEBUG_TASK_SET_FULL
)
5240 sdev_printk(KERN_INFO
, sdev
, "strange "
5241 "observation, the queue depth is"
5242 " (%d) meanwhile fw queue depth "
5243 "is (%d)\n", sdev
->queue_depth
,
5247 depth
= scsi_track_queue_full(sdev
,
5250 sdev_printk(KERN_INFO
, sdev
, "Queue depth "
5251 "reduced to (%d)\n", depth
);
5253 sdev_printk(KERN_INFO
, sdev
, "Tagged Command "
5254 "Queueing is being disabled\n");
5255 else if (depth
== 0)
5256 if (ioc
->logging_level
&
5257 MPT_DEBUG_TASK_SET_FULL
)
5258 sdev_printk(KERN_INFO
, sdev
,
5259 "Queue depth not changed yet\n");
5265 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
5266 * @ioc: per adapter object
5267 * @sas_address: sas address
5268 * @slot: enclosure slot id
5269 * @handle: device handle
5271 * After host reset, find out whether devices are still responding.
5272 * Used in _scsi_remove_unresponsive_sas_devices.
5277 _scsih_mark_responding_sas_device(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
,
5278 u16 slot
, u16 handle
)
5280 struct MPT2SAS_TARGET
*sas_target_priv_data
;
5281 struct scsi_target
*starget
;
5282 struct _sas_device
*sas_device
;
5283 unsigned long flags
;
5285 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5286 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
) {
5287 if (sas_device
->sas_address
== sas_address
&&
5288 sas_device
->slot
== slot
&& sas_device
->starget
) {
5289 sas_device
->responding
= 1;
5290 sas_device
->state
= 0;
5291 starget
= sas_device
->starget
;
5292 sas_target_priv_data
= starget
->hostdata
;
5293 sas_target_priv_data
->tm_busy
= 0;
5294 starget_printk(KERN_INFO
, sas_device
->starget
,
5295 "handle(0x%04x), sas_addr(0x%016llx), enclosure "
5296 "logical id(0x%016llx), slot(%d)\n", handle
,
5297 (unsigned long long)sas_device
->sas_address
,
5298 (unsigned long long)
5299 sas_device
->enclosure_logical_id
,
5301 if (sas_device
->handle
== handle
)
5303 printk(KERN_INFO
"\thandle changed from(0x%04x)!!!\n",
5304 sas_device
->handle
);
5305 sas_device
->handle
= handle
;
5306 sas_target_priv_data
->handle
= handle
;
5311 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5315 * _scsih_search_responding_sas_devices -
5316 * @ioc: per adapter object
5318 * After host reset, find out whether devices are still responding.
5324 _scsih_search_responding_sas_devices(struct MPT2SAS_ADAPTER
*ioc
)
5326 Mpi2SasDevicePage0_t sas_device_pg0
;
5327 Mpi2ConfigReply_t mpi_reply
;
5334 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
, __func__
);
5336 if (list_empty(&ioc
->sas_device_list
))
5340 while (!(mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
5341 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
,
5343 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5344 MPI2_IOCSTATUS_MASK
;
5345 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
5347 handle
= le16_to_cpu(sas_device_pg0
.DevHandle
);
5348 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
5349 if (!(_scsih_is_end_device(device_info
)))
5351 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
5352 slot
= le16_to_cpu(sas_device_pg0
.Slot
);
5353 _scsih_mark_responding_sas_device(ioc
, sas_address
, slot
,
5359 * _scsih_mark_responding_raid_device - mark a raid_device as responding
5360 * @ioc: per adapter object
5361 * @wwid: world wide identifier for raid volume
5362 * @handle: device handle
5364 * After host reset, find out whether devices are still responding.
5365 * Used in _scsi_remove_unresponsive_raid_devices.
5370 _scsih_mark_responding_raid_device(struct MPT2SAS_ADAPTER
*ioc
, u64 wwid
,
5373 struct MPT2SAS_TARGET
*sas_target_priv_data
;
5374 struct scsi_target
*starget
;
5375 struct _raid_device
*raid_device
;
5376 unsigned long flags
;
5378 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5379 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
5380 if (raid_device
->wwid
== wwid
&& raid_device
->starget
) {
5381 raid_device
->responding
= 1;
5382 starget_printk(KERN_INFO
, raid_device
->starget
,
5383 "handle(0x%04x), wwid(0x%016llx)\n", handle
,
5384 (unsigned long long)raid_device
->wwid
);
5385 if (raid_device
->handle
== handle
)
5387 printk(KERN_INFO
"\thandle changed from(0x%04x)!!!\n",
5388 raid_device
->handle
);
5389 raid_device
->handle
= handle
;
5390 starget
= raid_device
->starget
;
5391 sas_target_priv_data
= starget
->hostdata
;
5392 sas_target_priv_data
->handle
= handle
;
5397 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5401 * _scsih_search_responding_raid_devices -
5402 * @ioc: per adapter object
5404 * After host reset, find out whether devices are still responding.
5410 _scsih_search_responding_raid_devices(struct MPT2SAS_ADAPTER
*ioc
)
5412 Mpi2RaidVolPage1_t volume_pg1
;
5413 Mpi2ConfigReply_t mpi_reply
;
5417 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
, __func__
);
5419 if (list_empty(&ioc
->raid_device_list
))
5423 while (!(mpt2sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
5424 &volume_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
5425 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5426 MPI2_IOCSTATUS_MASK
;
5427 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
5429 handle
= le16_to_cpu(volume_pg1
.DevHandle
);
5430 _scsih_mark_responding_raid_device(ioc
,
5431 le64_to_cpu(volume_pg1
.WWID
), handle
);
5436 * _scsih_mark_responding_expander - mark a expander as responding
5437 * @ioc: per adapter object
5438 * @sas_address: sas address
5441 * After host reset, find out whether devices are still responding.
5442 * Used in _scsi_remove_unresponsive_expanders.
5447 _scsih_mark_responding_expander(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
,
5450 struct _sas_node
*sas_expander
;
5451 unsigned long flags
;
5454 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5455 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
5456 if (sas_expander
->sas_address
!= sas_address
)
5458 sas_expander
->responding
= 1;
5459 if (sas_expander
->handle
== handle
)
5461 printk(KERN_INFO
"\texpander(0x%016llx): handle changed"
5462 " from(0x%04x) to (0x%04x)!!!\n",
5463 (unsigned long long)sas_expander
->sas_address
,
5464 sas_expander
->handle
, handle
);
5465 sas_expander
->handle
= handle
;
5466 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++)
5467 sas_expander
->phy
[i
].handle
= handle
;
5471 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5475 * _scsih_search_responding_expanders -
5476 * @ioc: per adapter object
5478 * After host reset, find out whether devices are still responding.
5484 _scsih_search_responding_expanders(struct MPT2SAS_ADAPTER
*ioc
)
5486 Mpi2ExpanderPage0_t expander_pg0
;
5487 Mpi2ConfigReply_t mpi_reply
;
5492 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
, __func__
);
5494 if (list_empty(&ioc
->sas_expander_list
))
5498 while (!(mpt2sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
5499 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL
, handle
))) {
5501 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5502 MPI2_IOCSTATUS_MASK
;
5503 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
5506 handle
= le16_to_cpu(expander_pg0
.DevHandle
);
5507 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
5508 printk(KERN_INFO
"\texpander present: handle(0x%04x), "
5509 "sas_addr(0x%016llx)\n", handle
,
5510 (unsigned long long)sas_address
);
5511 _scsih_mark_responding_expander(ioc
, sas_address
, handle
);
5517 * _scsih_remove_unresponding_devices - removing unresponding devices
5518 * @ioc: per adapter object
5523 _scsih_remove_unresponding_devices(struct MPT2SAS_ADAPTER
*ioc
)
5525 struct _sas_device
*sas_device
, *sas_device_next
;
5526 struct _sas_node
*sas_expander
;
5527 struct _raid_device
*raid_device
, *raid_device_next
;
5530 list_for_each_entry_safe(sas_device
, sas_device_next
,
5531 &ioc
->sas_device_list
, list
) {
5532 if (sas_device
->responding
) {
5533 sas_device
->responding
= 0;
5536 if (sas_device
->starget
)
5537 starget_printk(KERN_INFO
, sas_device
->starget
,
5538 "removing: handle(0x%04x), sas_addr(0x%016llx), "
5539 "enclosure logical id(0x%016llx), slot(%d)\n",
5541 (unsigned long long)sas_device
->sas_address
,
5542 (unsigned long long)
5543 sas_device
->enclosure_logical_id
,
5545 /* invalidate the device handle */
5546 sas_device
->handle
= 0;
5547 _scsih_remove_device(ioc
, sas_device
);
5550 list_for_each_entry_safe(raid_device
, raid_device_next
,
5551 &ioc
->raid_device_list
, list
) {
5552 if (raid_device
->responding
) {
5553 raid_device
->responding
= 0;
5556 if (raid_device
->starget
) {
5557 starget_printk(KERN_INFO
, raid_device
->starget
,
5558 "removing: handle(0x%04x), wwid(0x%016llx)\n",
5559 raid_device
->handle
,
5560 (unsigned long long)raid_device
->wwid
);
5561 scsi_remove_target(&raid_device
->starget
->dev
);
5563 _scsih_raid_device_remove(ioc
, raid_device
);
5566 retry_expander_search
:
5567 sas_expander
= NULL
;
5568 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
5569 if (sas_expander
->responding
) {
5570 sas_expander
->responding
= 0;
5573 _scsih_expander_remove(ioc
, sas_expander
->sas_address
);
5574 goto retry_expander_search
;
5579 * mpt2sas_scsih_reset_handler - reset callback handler (for scsih)
5580 * @ioc: per adapter object
5581 * @reset_phase: phase
5583 * The handler for doing any required cleanup or initialization.
5585 * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
5586 * MPT2_IOC_DONE_RESET
5591 mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER
*ioc
, int reset_phase
)
5593 switch (reset_phase
) {
5594 case MPT2_IOC_PRE_RESET
:
5595 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: "
5596 "MPT2_IOC_PRE_RESET\n", ioc
->name
, __func__
));
5597 _scsih_fw_event_off(ioc
);
5599 case MPT2_IOC_AFTER_RESET
:
5600 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: "
5601 "MPT2_IOC_AFTER_RESET\n", ioc
->name
, __func__
));
5602 if (ioc
->tm_cmds
.status
& MPT2_CMD_PENDING
) {
5603 ioc
->tm_cmds
.status
|= MPT2_CMD_RESET
;
5604 mpt2sas_base_free_smid(ioc
, ioc
->tm_cmds
.smid
);
5605 complete(&ioc
->tm_cmds
.done
);
5607 _scsih_fw_event_on(ioc
);
5608 _scsih_flush_running_cmds(ioc
);
5610 case MPT2_IOC_DONE_RESET
:
5611 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: "
5612 "MPT2_IOC_DONE_RESET\n", ioc
->name
, __func__
));
5613 _scsih_sas_host_refresh(ioc
);
5614 _scsih_search_responding_sas_devices(ioc
);
5615 _scsih_search_responding_raid_devices(ioc
);
5616 _scsih_search_responding_expanders(ioc
);
5618 case MPT2_IOC_RUNNING
:
5619 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: "
5620 "MPT2_IOC_RUNNING\n", ioc
->name
, __func__
));
5621 _scsih_remove_unresponding_devices(ioc
);
5627 * _firmware_event_work - delayed task for processing firmware events
5628 * @ioc: per adapter object
5629 * @work: equal to the fw_event_work object
5635 _firmware_event_work(struct work_struct
*work
)
5637 struct fw_event_work
*fw_event
= container_of(work
,
5638 struct fw_event_work
, work
);
5639 unsigned long flags
;
5640 struct MPT2SAS_ADAPTER
*ioc
= fw_event
->ioc
;
5642 /* the queue is being flushed so ignore this event */
5643 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
5644 if (ioc
->fw_events_off
|| ioc
->remove_host
) {
5645 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
5646 _scsih_fw_event_free(ioc
, fw_event
);
5649 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
5651 if (ioc
->shost_recovery
) {
5652 _scsih_fw_event_requeue(ioc
, fw_event
, 1000);
5656 switch (fw_event
->event
) {
5657 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
5658 _scsih_sas_topology_change_event(ioc
, fw_event
);
5660 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
5661 _scsih_sas_device_status_change_event(ioc
,
5664 case MPI2_EVENT_SAS_DISCOVERY
:
5665 _scsih_sas_discovery_event(ioc
,
5668 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
5669 _scsih_sas_broadcast_primative_event(ioc
,
5672 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
5673 _scsih_sas_enclosure_dev_status_change_event(ioc
,
5676 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
5677 _scsih_sas_ir_config_change_event(ioc
, fw_event
);
5679 case MPI2_EVENT_IR_VOLUME
:
5680 _scsih_sas_ir_volume_event(ioc
, fw_event
);
5682 case MPI2_EVENT_IR_PHYSICAL_DISK
:
5683 _scsih_sas_ir_physical_disk_event(ioc
, fw_event
);
5685 case MPI2_EVENT_IR_OPERATION_STATUS
:
5686 _scsih_sas_ir_operation_status_event(ioc
, fw_event
);
5688 case MPI2_EVENT_TASK_SET_FULL
:
5689 _scsih_task_set_full(ioc
, fw_event
);
5692 _scsih_fw_event_free(ioc
, fw_event
);
5696 * mpt2sas_scsih_event_callback - firmware event handler (called at ISR time)
5697 * @ioc: per adapter object
5698 * @msix_index: MSIX table index supplied by the OS
5699 * @reply: reply message frame(lower 32bit addr)
5700 * Context: interrupt.
5702 * This function merely adds a new work task into ioc->firmware_event_thread.
5703 * The tasks are worked from _firmware_event_work in user context.
5705 * Return 1 meaning mf should be freed from _base_interrupt
5706 * 0 means the mf is freed from this function.
5709 mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER
*ioc
, u8 msix_index
,
5712 struct fw_event_work
*fw_event
;
5713 Mpi2EventNotificationReply_t
*mpi_reply
;
5714 unsigned long flags
;
5717 /* events turned off due to host reset or driver unloading */
5718 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
5719 if (ioc
->fw_events_off
|| ioc
->remove_host
) {
5720 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
5723 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
5725 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
5726 event
= le16_to_cpu(mpi_reply
->Event
);
5730 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
5732 Mpi2EventDataSasBroadcastPrimitive_t
*baen_data
=
5733 (Mpi2EventDataSasBroadcastPrimitive_t
*)
5734 mpi_reply
->EventData
;
5736 if (baen_data
->Primitive
!=
5737 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT
||
5738 ioc
->broadcast_aen_busy
)
5740 ioc
->broadcast_aen_busy
= 1;
5744 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
5745 _scsih_check_topo_delete_events(ioc
,
5746 (Mpi2EventDataSasTopologyChangeList_t
*)
5747 mpi_reply
->EventData
);
5750 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
5751 case MPI2_EVENT_IR_OPERATION_STATUS
:
5752 case MPI2_EVENT_SAS_DISCOVERY
:
5753 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
5754 case MPI2_EVENT_IR_VOLUME
:
5755 case MPI2_EVENT_IR_PHYSICAL_DISK
:
5756 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
5757 case MPI2_EVENT_TASK_SET_FULL
:
5760 default: /* ignore the rest */
5764 fw_event
= kzalloc(sizeof(struct fw_event_work
), GFP_ATOMIC
);
5766 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5767 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5770 fw_event
->event_data
=
5771 kzalloc(mpi_reply
->EventDataLength
*4, GFP_ATOMIC
);
5772 if (!fw_event
->event_data
) {
5773 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5774 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5779 memcpy(fw_event
->event_data
, mpi_reply
->EventData
,
5780 mpi_reply
->EventDataLength
*4);
5781 fw_event
->ioc
= ioc
;
5782 fw_event
->VF_ID
= mpi_reply
->VF_ID
;
5783 fw_event
->VP_ID
= mpi_reply
->VP_ID
;
5784 fw_event
->event
= event
;
5785 _scsih_fw_event_add(ioc
, fw_event
);
5789 /* shost template */
5790 static struct scsi_host_template scsih_driver_template
= {
5791 .module
= THIS_MODULE
,
5792 .name
= "Fusion MPT SAS Host",
5793 .proc_name
= MPT2SAS_DRIVER_NAME
,
5794 .queuecommand
= _scsih_qcmd
,
5795 .target_alloc
= _scsih_target_alloc
,
5796 .slave_alloc
= _scsih_slave_alloc
,
5797 .slave_configure
= _scsih_slave_configure
,
5798 .target_destroy
= _scsih_target_destroy
,
5799 .slave_destroy
= _scsih_slave_destroy
,
5800 .change_queue_depth
= _scsih_change_queue_depth
,
5801 .change_queue_type
= _scsih_change_queue_type
,
5802 .eh_abort_handler
= _scsih_abort
,
5803 .eh_device_reset_handler
= _scsih_dev_reset
,
5804 .eh_target_reset_handler
= _scsih_target_reset
,
5805 .eh_host_reset_handler
= _scsih_host_reset
,
5806 .bios_param
= _scsih_bios_param
,
5809 .sg_tablesize
= MPT2SAS_SG_DEPTH
,
5810 .max_sectors
= 8192,
5812 .use_clustering
= ENABLE_CLUSTERING
,
5813 .shost_attrs
= mpt2sas_host_attrs
,
5814 .sdev_attrs
= mpt2sas_dev_attrs
,
5818 * _scsih_expander_node_remove - removing expander device from list.
5819 * @ioc: per adapter object
5820 * @sas_expander: the sas_device object
5821 * Context: Calling function should acquire ioc->sas_node_lock.
5823 * Removing object and freeing associated memory from the
5824 * ioc->sas_expander_list.
5829 _scsih_expander_node_remove(struct MPT2SAS_ADAPTER
*ioc
,
5830 struct _sas_node
*sas_expander
)
5832 struct _sas_port
*mpt2sas_port
;
5833 struct _sas_device
*sas_device
;
5834 struct _sas_node
*expander_sibling
;
5835 unsigned long flags
;
5840 /* remove sibling ports attached to this expander */
5841 retry_device_search
:
5842 list_for_each_entry(mpt2sas_port
,
5843 &sas_expander
->sas_port_list
, port_list
) {
5844 if (mpt2sas_port
->remote_identify
.device_type
==
5846 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5848 mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
5849 mpt2sas_port
->remote_identify
.sas_address
);
5850 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5853 _scsih_remove_device(ioc
, sas_device
);
5854 if (ioc
->shost_recovery
)
5856 goto retry_device_search
;
5860 retry_expander_search
:
5861 list_for_each_entry(mpt2sas_port
,
5862 &sas_expander
->sas_port_list
, port_list
) {
5864 if (mpt2sas_port
->remote_identify
.device_type
==
5865 MPI2_SAS_DEVICE_INFO_EDGE_EXPANDER
||
5866 mpt2sas_port
->remote_identify
.device_type
==
5867 MPI2_SAS_DEVICE_INFO_FANOUT_EXPANDER
) {
5869 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5871 mpt2sas_scsih_expander_find_by_sas_address(
5872 ioc
, mpt2sas_port
->remote_identify
.sas_address
);
5873 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5874 if (!expander_sibling
)
5876 _scsih_expander_remove(ioc
,
5877 expander_sibling
->sas_address
);
5878 if (ioc
->shost_recovery
)
5880 goto retry_expander_search
;
5884 mpt2sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
5885 sas_expander
->sas_address_parent
);
5887 printk(MPT2SAS_INFO_FMT
"expander_remove: handle"
5888 "(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
5889 sas_expander
->handle
, (unsigned long long)
5890 sas_expander
->sas_address
);
5892 list_del(&sas_expander
->list
);
5893 kfree(sas_expander
->phy
);
5894 kfree(sas_expander
);
5898 * _scsih_ir_shutdown - IR shutdown notification
5899 * @ioc: per adapter object
5901 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
5902 * the host system is shutting down.
5907 _scsih_ir_shutdown(struct MPT2SAS_ADAPTER
*ioc
)
5909 Mpi2RaidActionRequest_t
*mpi_request
;
5910 Mpi2RaidActionReply_t
*mpi_reply
;
5913 /* is IR firmware build loaded ? */
5914 if (!ioc
->ir_firmware
)
5917 /* are there any volumes ? */
5918 if (list_empty(&ioc
->raid_device_list
))
5921 mutex_lock(&ioc
->scsih_cmds
.mutex
);
5923 if (ioc
->scsih_cmds
.status
!= MPT2_CMD_NOT_USED
) {
5924 printk(MPT2SAS_ERR_FMT
"%s: scsih_cmd in use\n",
5925 ioc
->name
, __func__
);
5928 ioc
->scsih_cmds
.status
= MPT2_CMD_PENDING
;
5930 smid
= mpt2sas_base_get_smid(ioc
, ioc
->scsih_cb_idx
);
5932 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
5933 ioc
->name
, __func__
);
5934 ioc
->scsih_cmds
.status
= MPT2_CMD_NOT_USED
;
5938 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
5939 ioc
->scsih_cmds
.smid
= smid
;
5940 memset(mpi_request
, 0, sizeof(Mpi2RaidActionRequest_t
));
5942 mpi_request
->Function
= MPI2_FUNCTION_RAID_ACTION
;
5943 mpi_request
->Action
= MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED
;
5945 printk(MPT2SAS_INFO_FMT
"IR shutdown (sending)\n", ioc
->name
);
5946 init_completion(&ioc
->scsih_cmds
.done
);
5947 mpt2sas_base_put_smid_default(ioc
, smid
);
5948 wait_for_completion_timeout(&ioc
->scsih_cmds
.done
, 10*HZ
);
5950 if (!(ioc
->scsih_cmds
.status
& MPT2_CMD_COMPLETE
)) {
5951 printk(MPT2SAS_ERR_FMT
"%s: timeout\n",
5952 ioc
->name
, __func__
);
5956 if (ioc
->scsih_cmds
.status
& MPT2_CMD_REPLY_VALID
) {
5957 mpi_reply
= ioc
->scsih_cmds
.reply
;
5959 printk(MPT2SAS_INFO_FMT
"IR shutdown (complete): "
5960 "ioc_status(0x%04x), loginfo(0x%08x)\n",
5961 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
5962 le32_to_cpu(mpi_reply
->IOCLogInfo
));
5966 ioc
->scsih_cmds
.status
= MPT2_CMD_NOT_USED
;
5967 mutex_unlock(&ioc
->scsih_cmds
.mutex
);
5971 * _scsih_shutdown - routine call during system shutdown
5972 * @pdev: PCI device struct
5977 _scsih_shutdown(struct pci_dev
*pdev
)
5979 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
5980 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
5982 _scsih_ir_shutdown(ioc
);
5983 mpt2sas_base_detach(ioc
);
5987 * _scsih_remove - detach and remove add host
5988 * @pdev: PCI device struct
5990 * Routine called when unloading the driver.
5993 static void __devexit
5994 _scsih_remove(struct pci_dev
*pdev
)
5996 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
5997 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
5998 struct _sas_port
*mpt2sas_port
;
5999 struct _sas_device
*sas_device
;
6000 struct _sas_node
*expander_sibling
;
6001 struct _raid_device
*raid_device
, *next
;
6002 struct MPT2SAS_TARGET
*sas_target_priv_data
;
6003 struct workqueue_struct
*wq
;
6004 unsigned long flags
;
6006 ioc
->remove_host
= 1;
6007 _scsih_fw_event_off(ioc
);
6009 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
6010 wq
= ioc
->firmware_event_thread
;
6011 ioc
->firmware_event_thread
= NULL
;
6012 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
6014 destroy_workqueue(wq
);
6016 /* release all the volumes */
6017 list_for_each_entry_safe(raid_device
, next
, &ioc
->raid_device_list
,
6019 if (raid_device
->starget
) {
6020 sas_target_priv_data
=
6021 raid_device
->starget
->hostdata
;
6022 sas_target_priv_data
->deleted
= 1;
6023 scsi_remove_target(&raid_device
->starget
->dev
);
6025 printk(MPT2SAS_INFO_FMT
"removing handle(0x%04x), wwid"
6026 "(0x%016llx)\n", ioc
->name
, raid_device
->handle
,
6027 (unsigned long long) raid_device
->wwid
);
6028 _scsih_raid_device_remove(ioc
, raid_device
);
6031 /* free ports attached to the sas_host */
6033 list_for_each_entry(mpt2sas_port
,
6034 &ioc
->sas_hba
.sas_port_list
, port_list
) {
6035 if (mpt2sas_port
->remote_identify
.device_type
==
6038 mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
6039 mpt2sas_port
->remote_identify
.sas_address
);
6041 _scsih_remove_device(ioc
, sas_device
);
6046 mpt2sas_scsih_expander_find_by_sas_address(ioc
,
6047 mpt2sas_port
->remote_identify
.sas_address
);
6048 if (expander_sibling
) {
6049 _scsih_expander_remove(ioc
,
6050 expander_sibling
->sas_address
);
6056 /* free phys attached to the sas_host */
6057 if (ioc
->sas_hba
.num_phys
) {
6058 kfree(ioc
->sas_hba
.phy
);
6059 ioc
->sas_hba
.phy
= NULL
;
6060 ioc
->sas_hba
.num_phys
= 0;
6063 sas_remove_host(shost
);
6064 _scsih_shutdown(pdev
);
6065 list_del(&ioc
->list
);
6066 scsi_remove_host(shost
);
6067 scsi_host_put(shost
);
6071 * _scsih_probe_boot_devices - reports 1st device
6072 * @ioc: per adapter object
6074 * If specified in bios page 2, this routine reports the 1st
6075 * device scsi-ml or sas transport for persistent boot device
6076 * purposes. Please refer to function _scsih_determine_boot_device()
6079 _scsih_probe_boot_devices(struct MPT2SAS_ADAPTER
*ioc
)
6083 struct _sas_device
*sas_device
;
6084 struct _raid_device
*raid_device
;
6086 u64 sas_address_parent
;
6088 unsigned long flags
;
6092 if (ioc
->req_boot_device
.device
) {
6093 device
= ioc
->req_boot_device
.device
;
6094 is_raid
= ioc
->req_boot_device
.is_raid
;
6095 } else if (ioc
->req_alt_boot_device
.device
) {
6096 device
= ioc
->req_alt_boot_device
.device
;
6097 is_raid
= ioc
->req_alt_boot_device
.is_raid
;
6098 } else if (ioc
->current_boot_device
.device
) {
6099 device
= ioc
->current_boot_device
.device
;
6100 is_raid
= ioc
->current_boot_device
.is_raid
;
6107 raid_device
= device
;
6108 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
6109 raid_device
->id
, 0);
6111 _scsih_raid_device_remove(ioc
, raid_device
);
6113 sas_device
= device
;
6114 handle
= sas_device
->handle
;
6115 sas_address_parent
= sas_device
->sas_address_parent
;
6116 sas_address
= sas_device
->sas_address
;
6117 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6118 list_move_tail(&sas_device
->list
, &ioc
->sas_device_list
);
6119 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6120 if (!mpt2sas_transport_port_add(ioc
, sas_device
->handle
,
6121 sas_device
->sas_address_parent
)) {
6122 _scsih_sas_device_remove(ioc
, sas_device
);
6123 } else if (!sas_device
->starget
) {
6124 mpt2sas_transport_port_remove(ioc
, sas_address
,
6125 sas_address_parent
);
6126 _scsih_sas_device_remove(ioc
, sas_device
);
6132 * _scsih_probe_raid - reporting raid volumes to scsi-ml
6133 * @ioc: per adapter object
6135 * Called during initial loading of the driver.
6138 _scsih_probe_raid(struct MPT2SAS_ADAPTER
*ioc
)
6140 struct _raid_device
*raid_device
, *raid_next
;
6143 list_for_each_entry_safe(raid_device
, raid_next
,
6144 &ioc
->raid_device_list
, list
) {
6145 if (raid_device
->starget
)
6147 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
6148 raid_device
->id
, 0);
6150 _scsih_raid_device_remove(ioc
, raid_device
);
6155 * _scsih_probe_sas - reporting sas devices to sas transport
6156 * @ioc: per adapter object
6158 * Called during initial loading of the driver.
6161 _scsih_probe_sas(struct MPT2SAS_ADAPTER
*ioc
)
6163 struct _sas_device
*sas_device
, *next
;
6164 unsigned long flags
;
6166 /* SAS Device List */
6167 list_for_each_entry_safe(sas_device
, next
, &ioc
->sas_device_init_list
,
6169 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6170 list_move_tail(&sas_device
->list
, &ioc
->sas_device_list
);
6171 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6173 if (!mpt2sas_transport_port_add(ioc
, sas_device
->handle
,
6174 sas_device
->sas_address_parent
)) {
6175 _scsih_sas_device_remove(ioc
, sas_device
);
6176 } else if (!sas_device
->starget
) {
6177 mpt2sas_transport_port_remove(ioc
,
6178 sas_device
->sas_address
,
6179 sas_device
->sas_address_parent
);
6180 _scsih_sas_device_remove(ioc
, sas_device
);
6186 * _scsih_probe_devices - probing for devices
6187 * @ioc: per adapter object
6189 * Called during initial loading of the driver.
6192 _scsih_probe_devices(struct MPT2SAS_ADAPTER
*ioc
)
6194 u16 volume_mapping_flags
=
6195 le16_to_cpu(ioc
->ioc_pg8
.IRVolumeMappingFlags
) &
6196 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE
;
6198 if (!(ioc
->facts
.ProtocolFlags
& MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR
))
6199 return; /* return when IOC doesn't support initiator mode */
6201 _scsih_probe_boot_devices(ioc
);
6203 if (ioc
->ir_firmware
) {
6204 if ((volume_mapping_flags
&
6205 MPI2_IOCPAGE8_IRFLAGS_HIGH_VOLUME_MAPPING
)) {
6206 _scsih_probe_sas(ioc
);
6207 _scsih_probe_raid(ioc
);
6209 _scsih_probe_raid(ioc
);
6210 _scsih_probe_sas(ioc
);
6213 _scsih_probe_sas(ioc
);
6217 * _scsih_probe - attach and add scsi host
6218 * @pdev: PCI device struct
6219 * @id: pci device id
6221 * Returns 0 success, anything else error.
6224 _scsih_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
6226 struct MPT2SAS_ADAPTER
*ioc
;
6227 struct Scsi_Host
*shost
;
6229 shost
= scsi_host_alloc(&scsih_driver_template
,
6230 sizeof(struct MPT2SAS_ADAPTER
));
6234 /* init local params */
6235 ioc
= shost_priv(shost
);
6236 memset(ioc
, 0, sizeof(struct MPT2SAS_ADAPTER
));
6237 INIT_LIST_HEAD(&ioc
->list
);
6238 list_add_tail(&ioc
->list
, &mpt2sas_ioc_list
);
6240 ioc
->id
= mpt_ids
++;
6241 sprintf(ioc
->name
, "%s%d", MPT2SAS_DRIVER_NAME
, ioc
->id
);
6243 ioc
->scsi_io_cb_idx
= scsi_io_cb_idx
;
6244 ioc
->tm_cb_idx
= tm_cb_idx
;
6245 ioc
->ctl_cb_idx
= ctl_cb_idx
;
6246 ioc
->base_cb_idx
= base_cb_idx
;
6247 ioc
->transport_cb_idx
= transport_cb_idx
;
6248 ioc
->scsih_cb_idx
= scsih_cb_idx
;
6249 ioc
->config_cb_idx
= config_cb_idx
;
6250 ioc
->tm_tr_cb_idx
= tm_tr_cb_idx
;
6251 ioc
->tm_sas_control_cb_idx
= tm_sas_control_cb_idx
;
6252 ioc
->logging_level
= logging_level
;
6253 /* misc semaphores and spin locks */
6254 spin_lock_init(&ioc
->ioc_reset_in_progress_lock
);
6255 spin_lock_init(&ioc
->scsi_lookup_lock
);
6256 spin_lock_init(&ioc
->sas_device_lock
);
6257 spin_lock_init(&ioc
->sas_node_lock
);
6258 spin_lock_init(&ioc
->fw_event_lock
);
6259 spin_lock_init(&ioc
->raid_device_lock
);
6261 INIT_LIST_HEAD(&ioc
->sas_device_list
);
6262 INIT_LIST_HEAD(&ioc
->sas_device_init_list
);
6263 INIT_LIST_HEAD(&ioc
->sas_expander_list
);
6264 INIT_LIST_HEAD(&ioc
->fw_event_list
);
6265 INIT_LIST_HEAD(&ioc
->raid_device_list
);
6266 INIT_LIST_HEAD(&ioc
->sas_hba
.sas_port_list
);
6267 INIT_LIST_HEAD(&ioc
->delayed_tr_list
);
6269 /* init shost parameters */
6270 shost
->max_cmd_len
= 16;
6271 shost
->max_lun
= max_lun
;
6272 shost
->transportt
= mpt2sas_transport_template
;
6273 shost
->unique_id
= ioc
->id
;
6275 if ((scsi_add_host(shost
, &pdev
->dev
))) {
6276 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6277 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6278 list_del(&ioc
->list
);
6279 goto out_add_shost_fail
;
6282 scsi_host_set_prot(shost
, SHOST_DIF_TYPE1_PROTECTION
6283 | SHOST_DIF_TYPE3_PROTECTION
);
6284 scsi_host_set_guard(shost
, SHOST_DIX_GUARD_CRC
);
6287 snprintf(ioc
->firmware_event_name
, sizeof(ioc
->firmware_event_name
),
6288 "fw_event%d", ioc
->id
);
6289 ioc
->firmware_event_thread
= create_singlethread_workqueue(
6290 ioc
->firmware_event_name
);
6291 if (!ioc
->firmware_event_thread
) {
6292 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6293 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6294 goto out_thread_fail
;
6297 ioc
->wait_for_port_enable_to_complete
= 1;
6298 if ((mpt2sas_base_attach(ioc
))) {
6299 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6300 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6301 goto out_attach_fail
;
6304 ioc
->wait_for_port_enable_to_complete
= 0;
6305 _scsih_probe_devices(ioc
);
6309 destroy_workqueue(ioc
->firmware_event_thread
);
6311 list_del(&ioc
->list
);
6312 scsi_remove_host(shost
);
6319 * _scsih_suspend - power management suspend main entry point
6320 * @pdev: PCI device struct
6321 * @state: PM state change to (usually PCI_D3)
6323 * Returns 0 success, anything else error.
6326 _scsih_suspend(struct pci_dev
*pdev
, pm_message_t state
)
6328 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6329 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
6332 mpt2sas_base_stop_watchdog(ioc
);
6333 flush_scheduled_work();
6334 scsi_block_requests(shost
);
6335 device_state
= pci_choose_state(pdev
, state
);
6336 printk(MPT2SAS_INFO_FMT
"pdev=0x%p, slot=%s, entering "
6337 "operating state [D%d]\n", ioc
->name
, pdev
,
6338 pci_name(pdev
), device_state
);
6340 mpt2sas_base_free_resources(ioc
);
6341 pci_save_state(pdev
);
6342 pci_disable_device(pdev
);
6343 pci_set_power_state(pdev
, device_state
);
6348 * _scsih_resume - power management resume main entry point
6349 * @pdev: PCI device struct
6351 * Returns 0 success, anything else error.
6354 _scsih_resume(struct pci_dev
*pdev
)
6356 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6357 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
6358 u32 device_state
= pdev
->current_state
;
6361 printk(MPT2SAS_INFO_FMT
"pdev=0x%p, slot=%s, previous "
6362 "operating state [D%d]\n", ioc
->name
, pdev
,
6363 pci_name(pdev
), device_state
);
6365 pci_set_power_state(pdev
, PCI_D0
);
6366 pci_enable_wake(pdev
, PCI_D0
, 0);
6367 pci_restore_state(pdev
);
6369 r
= mpt2sas_base_map_resources(ioc
);
6373 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
, SOFT_RESET
);
6374 scsi_unblock_requests(shost
);
6375 mpt2sas_base_start_watchdog(ioc
);
6378 #endif /* CONFIG_PM */
6381 static struct pci_driver scsih_driver
= {
6382 .name
= MPT2SAS_DRIVER_NAME
,
6383 .id_table
= scsih_pci_table
,
6384 .probe
= _scsih_probe
,
6385 .remove
= __devexit_p(_scsih_remove
),
6386 .shutdown
= _scsih_shutdown
,
6388 .suspend
= _scsih_suspend
,
6389 .resume
= _scsih_resume
,
6395 * _scsih_init - main entry point for this driver.
6397 * Returns 0 success, anything else error.
6405 printk(KERN_INFO
"%s version %s loaded\n", MPT2SAS_DRIVER_NAME
,
6406 MPT2SAS_DRIVER_VERSION
);
6408 mpt2sas_transport_template
=
6409 sas_attach_transport(&mpt2sas_transport_functions
);
6410 if (!mpt2sas_transport_template
)
6413 mpt2sas_base_initialize_callback_handler();
6415 /* queuecommand callback hander */
6416 scsi_io_cb_idx
= mpt2sas_base_register_callback_handler(_scsih_io_done
);
6418 /* task managment callback handler */
6419 tm_cb_idx
= mpt2sas_base_register_callback_handler(_scsih_tm_done
);
6421 /* base internal commands callback handler */
6422 base_cb_idx
= mpt2sas_base_register_callback_handler(mpt2sas_base_done
);
6424 /* transport internal commands callback handler */
6425 transport_cb_idx
= mpt2sas_base_register_callback_handler(
6426 mpt2sas_transport_done
);
6428 /* scsih internal commands callback handler */
6429 scsih_cb_idx
= mpt2sas_base_register_callback_handler(_scsih_done
);
6431 /* configuration page API internal commands callback handler */
6432 config_cb_idx
= mpt2sas_base_register_callback_handler(
6433 mpt2sas_config_done
);
6435 /* ctl module callback handler */
6436 ctl_cb_idx
= mpt2sas_base_register_callback_handler(mpt2sas_ctl_done
);
6438 tm_tr_cb_idx
= mpt2sas_base_register_callback_handler(
6439 _scsih_tm_tr_complete
);
6440 tm_sas_control_cb_idx
= mpt2sas_base_register_callback_handler(
6441 _scsih_sas_control_complete
);
6445 error
= pci_register_driver(&scsih_driver
);
6447 sas_release_transport(mpt2sas_transport_template
);
6453 * _scsih_exit - exit point for this driver (when it is a module).
6455 * Returns 0 success, anything else error.
6460 printk(KERN_INFO
"mpt2sas version %s unloading\n",
6461 MPT2SAS_DRIVER_VERSION
);
6463 pci_unregister_driver(&scsih_driver
);
6465 sas_release_transport(mpt2sas_transport_template
);
6466 mpt2sas_base_release_callback_handler(scsi_io_cb_idx
);
6467 mpt2sas_base_release_callback_handler(tm_cb_idx
);
6468 mpt2sas_base_release_callback_handler(base_cb_idx
);
6469 mpt2sas_base_release_callback_handler(transport_cb_idx
);
6470 mpt2sas_base_release_callback_handler(scsih_cb_idx
);
6471 mpt2sas_base_release_callback_handler(config_cb_idx
);
6472 mpt2sas_base_release_callback_handler(ctl_cb_idx
);
6474 mpt2sas_base_release_callback_handler(tm_tr_cb_idx
);
6475 mpt2sas_base_release_callback_handler(tm_sas_control_cb_idx
);
6480 module_init(_scsih_init
);
6481 module_exit(_scsih_exit
);