2 * Scsi Host Layer for MPT (Message Passing Technology) based controllers
4 * This code is based on drivers/scsi/mpt2sas/mpt2_scsih.c
5 * Copyright (C) 2007-2010 LSI Corporation
6 * (mailto:DL-MPTFusionLinux@lsi.com)
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
19 * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
20 * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
21 * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
22 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
23 * solely responsible for determining the appropriateness of using and
24 * distributing the Program and assumes all risks associated with its
25 * exercise of rights under this Agreement, including but not limited to
26 * the risks and costs of program errors, damage to or loss of data,
27 * programs or equipment, and unavailability or interruption of operations.
29 * DISCLAIMER OF LIABILITY
30 * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
31 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
33 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
34 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
35 * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
36 * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
38 * You should have received a copy of the GNU General Public License
39 * along with this program; if not, write to the Free Software
40 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
44 #include <linux/version.h>
45 #include <linux/module.h>
46 #include <linux/kernel.h>
47 #include <linux/init.h>
48 #include <linux/errno.h>
49 #include <linux/blkdev.h>
50 #include <linux/sched.h>
51 #include <linux/workqueue.h>
52 #include <linux/delay.h>
53 #include <linux/pci.h>
54 #include <linux/interrupt.h>
55 #include <linux/aer.h>
56 #include <linux/raid_class.h>
57 #include <linux/slab.h>
59 #include "mpt2sas_base.h"
61 MODULE_AUTHOR(MPT2SAS_AUTHOR
);
62 MODULE_DESCRIPTION(MPT2SAS_DESCRIPTION
);
63 MODULE_LICENSE("GPL");
64 MODULE_VERSION(MPT2SAS_DRIVER_VERSION
);
66 #define RAID_CHANNEL 1
69 static void _scsih_expander_node_remove(struct MPT2SAS_ADAPTER
*ioc
,
70 struct _sas_node
*sas_expander
);
71 static void _firmware_event_work(struct work_struct
*work
);
73 static u8
_scsih_check_for_pending_tm(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
);
75 /* global parameters */
76 LIST_HEAD(mpt2sas_ioc_list
);
78 /* local parameters */
79 static u8 scsi_io_cb_idx
= -1;
80 static u8 tm_cb_idx
= -1;
81 static u8 ctl_cb_idx
= -1;
82 static u8 base_cb_idx
= -1;
83 static u8 transport_cb_idx
= -1;
84 static u8 scsih_cb_idx
= -1;
85 static u8 config_cb_idx
= -1;
88 static u8 tm_tr_cb_idx
= -1 ;
89 static u8 tm_tr_volume_cb_idx
= -1 ;
90 static u8 tm_sas_control_cb_idx
= -1;
92 /* command line options */
93 static u32 logging_level
;
94 MODULE_PARM_DESC(logging_level
, " bits for enabling additional logging info "
97 /* scsi-mid layer global parmeter is max_report_luns, which is 511 */
98 #define MPT2SAS_MAX_LUN (16895)
99 static int max_lun
= MPT2SAS_MAX_LUN
;
100 module_param(max_lun
, int, 0);
101 MODULE_PARM_DESC(max_lun
, " max lun, default=16895 ");
104 * struct sense_info - common structure for obtaining sense keys
106 * @asc: additional sense code
107 * @ascq: additional sense code qualifier
116 #define MPT2SAS_RESCAN_AFTER_HOST_RESET (0xFFFF)
119 * struct fw_event_work - firmware event struct
120 * @list: link list framework
121 * @work: work object (ioc->fault_reset_work_q)
122 * @cancel_pending_work: flag set during reset handling
123 * @ioc: per adapter object
124 * @VF_ID: virtual function id
125 * @VP_ID: virtual port id
126 * @ignore: flag meaning this event has been marked to ignore
127 * @event: firmware event MPI2_EVENT_XXX defined in mpt2_ioc.h
128 * @event_data: reply event data payload follows
130 * This object stored on ioc->fw_event_list.
132 struct fw_event_work
{
133 struct list_head list
;
134 u8 cancel_pending_work
;
135 struct delayed_work delayed_work
;
136 struct MPT2SAS_ADAPTER
*ioc
;
144 /* raid transport support */
145 static struct raid_template
*mpt2sas_raid_template
;
148 * struct _scsi_io_transfer - scsi io transfer
149 * @handle: sas device handle (assigned by firmware)
150 * @is_raid: flag set for hidden raid components
151 * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE,
152 * @data_length: data transfer length
153 * @data_dma: dma pointer to data
156 * @cdb_length: cdb length
158 * @timeout: timeout for this command
159 * @VF_ID: virtual function id
160 * @VP_ID: virtual port id
161 * @valid_reply: flag set for reply message
162 * @sense_length: sense length
163 * @ioc_status: ioc status
164 * @scsi_state: scsi state
165 * @scsi_status: scsi staus
166 * @log_info: log information
167 * @transfer_length: data length transfer when there is a reply message
169 * Used for sending internal scsi commands to devices within this module.
170 * Refer to _scsi_send_scsi_io().
172 struct _scsi_io_transfer
{
175 enum dma_data_direction dir
;
178 u8 sense
[SCSI_SENSE_BUFFERSIZE
];
186 /* the following bits are only valid when 'valid_reply = 1' */
196 * The pci device ids are defined in mpi/mpi2_cnfg.h.
198 static struct pci_device_id scsih_pci_table
[] = {
199 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2004
,
200 PCI_ANY_ID
, PCI_ANY_ID
},
202 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2008
,
203 PCI_ANY_ID
, PCI_ANY_ID
},
204 /* Liberator ~ 2108 */
205 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_1
,
206 PCI_ANY_ID
, PCI_ANY_ID
},
207 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_2
,
208 PCI_ANY_ID
, PCI_ANY_ID
},
209 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_3
,
210 PCI_ANY_ID
, PCI_ANY_ID
},
212 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2116_1
,
213 PCI_ANY_ID
, PCI_ANY_ID
},
214 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2116_2
,
215 PCI_ANY_ID
, PCI_ANY_ID
},
216 /* Thunderbolt ~ 2208 */
217 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_1
,
218 PCI_ANY_ID
, PCI_ANY_ID
},
219 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_2
,
220 PCI_ANY_ID
, PCI_ANY_ID
},
221 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_3
,
222 PCI_ANY_ID
, PCI_ANY_ID
},
223 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_4
,
224 PCI_ANY_ID
, PCI_ANY_ID
},
225 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_5
,
226 PCI_ANY_ID
, PCI_ANY_ID
},
227 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_6
,
228 PCI_ANY_ID
, PCI_ANY_ID
},
230 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2308_1
,
231 PCI_ANY_ID
, PCI_ANY_ID
},
232 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2308_2
,
233 PCI_ANY_ID
, PCI_ANY_ID
},
234 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2308_3
,
235 PCI_ANY_ID
, PCI_ANY_ID
},
236 {0} /* Terminating entry */
238 MODULE_DEVICE_TABLE(pci
, scsih_pci_table
);
241 * _scsih_set_debug_level - global setting of ioc->logging_level.
243 * Note: The logging levels are defined in mpt2sas_debug.h.
246 _scsih_set_debug_level(const char *val
, struct kernel_param
*kp
)
248 int ret
= param_set_int(val
, kp
);
249 struct MPT2SAS_ADAPTER
*ioc
;
254 printk(KERN_INFO
"setting logging_level(0x%08x)\n", logging_level
);
255 list_for_each_entry(ioc
, &mpt2sas_ioc_list
, list
)
256 ioc
->logging_level
= logging_level
;
259 module_param_call(logging_level
, _scsih_set_debug_level
, param_get_int
,
260 &logging_level
, 0644);
263 * _scsih_srch_boot_sas_address - search based on sas_address
264 * @sas_address: sas address
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_sas_address(u64 sas_address
,
271 Mpi2BootDeviceSasWwid_t
*boot_device
)
273 return (sas_address
== le64_to_cpu(boot_device
->SASAddress
)) ? 1 : 0;
277 * _scsih_srch_boot_device_name - search based on device name
278 * @device_name: device name specified in INDENTIFY fram
279 * @boot_device: boot device object from bios page 2
281 * Returns 1 when there's a match, 0 means no match.
284 _scsih_srch_boot_device_name(u64 device_name
,
285 Mpi2BootDeviceDeviceName_t
*boot_device
)
287 return (device_name
== le64_to_cpu(boot_device
->DeviceName
)) ? 1 : 0;
291 * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot
292 * @enclosure_logical_id: enclosure logical id
293 * @slot_number: slot number
294 * @boot_device: boot device object from bios page 2
296 * Returns 1 when there's a match, 0 means no match.
299 _scsih_srch_boot_encl_slot(u64 enclosure_logical_id
, u16 slot_number
,
300 Mpi2BootDeviceEnclosureSlot_t
*boot_device
)
302 return (enclosure_logical_id
== le64_to_cpu(boot_device
->
303 EnclosureLogicalID
) && slot_number
== le16_to_cpu(boot_device
->
304 SlotNumber
)) ? 1 : 0;
308 * _scsih_is_boot_device - search for matching boot device.
309 * @sas_address: sas address
310 * @device_name: device name specified in INDENTIFY fram
311 * @enclosure_logical_id: enclosure logical id
312 * @slot_number: slot number
313 * @form: specifies boot device form
314 * @boot_device: boot device object from bios page 2
316 * Returns 1 when there's a match, 0 means no match.
319 _scsih_is_boot_device(u64 sas_address
, u64 device_name
,
320 u64 enclosure_logical_id
, u16 slot
, u8 form
,
321 Mpi2BiosPage2BootDevice_t
*boot_device
)
326 case MPI2_BIOSPAGE2_FORM_SAS_WWID
:
329 rc
= _scsih_srch_boot_sas_address(
330 sas_address
, &boot_device
->SasWwid
);
332 case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT
:
333 if (!enclosure_logical_id
)
335 rc
= _scsih_srch_boot_encl_slot(
336 enclosure_logical_id
,
337 slot
, &boot_device
->EnclosureSlot
);
339 case MPI2_BIOSPAGE2_FORM_DEVICE_NAME
:
342 rc
= _scsih_srch_boot_device_name(
343 device_name
, &boot_device
->DeviceName
);
345 case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED
:
353 * _scsih_get_sas_address - set the sas_address for given device handle
354 * @handle: device handle
355 * @sas_address: sas address
357 * Returns 0 success, non-zero when failure
360 _scsih_get_sas_address(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
,
363 Mpi2SasDevicePage0_t sas_device_pg0
;
364 Mpi2ConfigReply_t mpi_reply
;
367 if (handle
<= ioc
->sas_hba
.num_phys
) {
368 *sas_address
= ioc
->sas_hba
.sas_address
;
373 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
374 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
375 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
376 ioc
->name
, __FILE__
, __LINE__
, __func__
);
380 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
382 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
383 printk(MPT2SAS_ERR_FMT
"handle(0x%04x), ioc_status(0x%04x)"
384 "\nfailure at %s:%d/%s()!\n", ioc
->name
, handle
, ioc_status
,
385 __FILE__
, __LINE__
, __func__
);
389 *sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
394 * _scsih_determine_boot_device - determine boot device.
395 * @ioc: per adapter object
396 * @device: either sas_device or raid_device object
397 * @is_raid: [flag] 1 = raid object, 0 = sas object
399 * Determines whether this device should be first reported device to
400 * to scsi-ml or sas transport, this purpose is for persistant boot device.
401 * There are primary, alternate, and current entries in bios page 2. The order
402 * priority is primary, alternate, then current. This routine saves
403 * the corresponding device object and is_raid flag in the ioc object.
404 * The saved data to be used later in _scsih_probe_boot_devices().
407 _scsih_determine_boot_device(struct MPT2SAS_ADAPTER
*ioc
,
408 void *device
, u8 is_raid
)
410 struct _sas_device
*sas_device
;
411 struct _raid_device
*raid_device
;
414 u64 enclosure_logical_id
;
417 /* only process this function when driver loads */
418 if (!ioc
->wait_for_port_enable_to_complete
)
423 sas_address
= sas_device
->sas_address
;
424 device_name
= sas_device
->device_name
;
425 enclosure_logical_id
= sas_device
->enclosure_logical_id
;
426 slot
= sas_device
->slot
;
428 raid_device
= device
;
429 sas_address
= raid_device
->wwid
;
431 enclosure_logical_id
= 0;
435 if (!ioc
->req_boot_device
.device
) {
436 if (_scsih_is_boot_device(sas_address
, device_name
,
437 enclosure_logical_id
, slot
,
438 (ioc
->bios_pg2
.ReqBootDeviceForm
&
439 MPI2_BIOSPAGE2_FORM_MASK
),
440 &ioc
->bios_pg2
.RequestedBootDevice
)) {
441 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
442 "%s: req_boot_device(0x%016llx)\n",
444 (unsigned long long)sas_address
));
445 ioc
->req_boot_device
.device
= device
;
446 ioc
->req_boot_device
.is_raid
= is_raid
;
450 if (!ioc
->req_alt_boot_device
.device
) {
451 if (_scsih_is_boot_device(sas_address
, device_name
,
452 enclosure_logical_id
, slot
,
453 (ioc
->bios_pg2
.ReqAltBootDeviceForm
&
454 MPI2_BIOSPAGE2_FORM_MASK
),
455 &ioc
->bios_pg2
.RequestedAltBootDevice
)) {
456 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
457 "%s: req_alt_boot_device(0x%016llx)\n",
459 (unsigned long long)sas_address
));
460 ioc
->req_alt_boot_device
.device
= device
;
461 ioc
->req_alt_boot_device
.is_raid
= is_raid
;
465 if (!ioc
->current_boot_device
.device
) {
466 if (_scsih_is_boot_device(sas_address
, device_name
,
467 enclosure_logical_id
, slot
,
468 (ioc
->bios_pg2
.CurrentBootDeviceForm
&
469 MPI2_BIOSPAGE2_FORM_MASK
),
470 &ioc
->bios_pg2
.CurrentBootDevice
)) {
471 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
472 "%s: current_boot_device(0x%016llx)\n",
474 (unsigned long long)sas_address
));
475 ioc
->current_boot_device
.device
= device
;
476 ioc
->current_boot_device
.is_raid
= is_raid
;
482 * mpt2sas_scsih_sas_device_find_by_sas_address - sas device search
483 * @ioc: per adapter object
484 * @sas_address: sas address
485 * Context: Calling function should acquire ioc->sas_device_lock
487 * This searches for sas_device based on sas_address, then return sas_device
491 mpt2sas_scsih_sas_device_find_by_sas_address(struct MPT2SAS_ADAPTER
*ioc
,
494 struct _sas_device
*sas_device
;
496 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
)
497 if (sas_device
->sas_address
== sas_address
)
500 list_for_each_entry(sas_device
, &ioc
->sas_device_init_list
, list
)
501 if (sas_device
->sas_address
== sas_address
)
508 * _scsih_sas_device_find_by_handle - sas device search
509 * @ioc: per adapter object
510 * @handle: sas device handle (assigned by firmware)
511 * Context: Calling function should acquire ioc->sas_device_lock
513 * This searches for sas_device based on sas_address, then return sas_device
516 static struct _sas_device
*
517 _scsih_sas_device_find_by_handle(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
519 struct _sas_device
*sas_device
;
521 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
)
522 if (sas_device
->handle
== handle
)
525 list_for_each_entry(sas_device
, &ioc
->sas_device_init_list
, list
)
526 if (sas_device
->handle
== handle
)
533 * _scsih_sas_device_remove - remove sas_device from list.
534 * @ioc: per adapter object
535 * @sas_device: the sas_device object
536 * Context: This function will acquire ioc->sas_device_lock.
538 * Removing object and freeing associated memory from the ioc->sas_device_list.
541 _scsih_sas_device_remove(struct MPT2SAS_ADAPTER
*ioc
,
542 struct _sas_device
*sas_device
)
549 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
550 if (mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
551 sas_device
->sas_address
)) {
552 list_del(&sas_device
->list
);
555 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
559 * _scsih_sas_device_add - insert sas_device to the list.
560 * @ioc: per adapter object
561 * @sas_device: the sas_device object
562 * Context: This function will acquire ioc->sas_device_lock.
564 * Adding new object to the ioc->sas_device_list.
567 _scsih_sas_device_add(struct MPT2SAS_ADAPTER
*ioc
,
568 struct _sas_device
*sas_device
)
572 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: handle"
573 "(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
, __func__
,
574 sas_device
->handle
, (unsigned long long)sas_device
->sas_address
));
576 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
577 list_add_tail(&sas_device
->list
, &ioc
->sas_device_list
);
578 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
580 if (!mpt2sas_transport_port_add(ioc
, sas_device
->handle
,
581 sas_device
->sas_address_parent
))
582 _scsih_sas_device_remove(ioc
, sas_device
);
586 * _scsih_sas_device_init_add - insert sas_device to the list.
587 * @ioc: per adapter object
588 * @sas_device: the sas_device object
589 * Context: This function will acquire ioc->sas_device_lock.
591 * Adding new object at driver load time to the ioc->sas_device_init_list.
594 _scsih_sas_device_init_add(struct MPT2SAS_ADAPTER
*ioc
,
595 struct _sas_device
*sas_device
)
599 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: handle"
600 "(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
, __func__
,
601 sas_device
->handle
, (unsigned long long)sas_device
->sas_address
));
603 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
604 list_add_tail(&sas_device
->list
, &ioc
->sas_device_init_list
);
605 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
606 _scsih_determine_boot_device(ioc
, sas_device
, 0);
610 * _scsih_raid_device_find_by_id - raid device search
611 * @ioc: per adapter object
612 * @id: sas device target id
613 * @channel: sas device channel
614 * Context: Calling function should acquire ioc->raid_device_lock
616 * This searches for raid_device based on target id, then return raid_device
619 static struct _raid_device
*
620 _scsih_raid_device_find_by_id(struct MPT2SAS_ADAPTER
*ioc
, int id
, int channel
)
622 struct _raid_device
*raid_device
, *r
;
625 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
626 if (raid_device
->id
== id
&& raid_device
->channel
== channel
) {
637 * _scsih_raid_device_find_by_handle - raid device search
638 * @ioc: per adapter object
639 * @handle: sas device handle (assigned by firmware)
640 * Context: Calling function should acquire ioc->raid_device_lock
642 * This searches for raid_device based on handle, then return raid_device
645 static struct _raid_device
*
646 _scsih_raid_device_find_by_handle(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
648 struct _raid_device
*raid_device
, *r
;
651 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
652 if (raid_device
->handle
!= handle
)
663 * _scsih_raid_device_find_by_wwid - raid device search
664 * @ioc: per adapter object
665 * @handle: sas device handle (assigned by firmware)
666 * Context: Calling function should acquire ioc->raid_device_lock
668 * This searches for raid_device based on wwid, then return raid_device
671 static struct _raid_device
*
672 _scsih_raid_device_find_by_wwid(struct MPT2SAS_ADAPTER
*ioc
, u64 wwid
)
674 struct _raid_device
*raid_device
, *r
;
677 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
678 if (raid_device
->wwid
!= wwid
)
689 * _scsih_raid_device_add - add raid_device object
690 * @ioc: per adapter object
691 * @raid_device: raid_device object
693 * This is added to the raid_device_list link list.
696 _scsih_raid_device_add(struct MPT2SAS_ADAPTER
*ioc
,
697 struct _raid_device
*raid_device
)
701 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: handle"
702 "(0x%04x), wwid(0x%016llx)\n", ioc
->name
, __func__
,
703 raid_device
->handle
, (unsigned long long)raid_device
->wwid
));
705 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
706 list_add_tail(&raid_device
->list
, &ioc
->raid_device_list
);
707 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
711 * _scsih_raid_device_remove - delete raid_device object
712 * @ioc: per adapter object
713 * @raid_device: raid_device object
715 * This is removed from the raid_device_list link list.
718 _scsih_raid_device_remove(struct MPT2SAS_ADAPTER
*ioc
,
719 struct _raid_device
*raid_device
)
723 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
724 list_del(&raid_device
->list
);
725 memset(raid_device
, 0, sizeof(struct _raid_device
));
727 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
731 * mpt2sas_scsih_expander_find_by_handle - expander device search
732 * @ioc: per adapter object
733 * @handle: expander handle (assigned by firmware)
734 * Context: Calling function should acquire ioc->sas_device_lock
736 * This searches for expander device based on handle, then returns the
740 mpt2sas_scsih_expander_find_by_handle(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
742 struct _sas_node
*sas_expander
, *r
;
745 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
746 if (sas_expander
->handle
!= handle
)
756 * mpt2sas_scsih_expander_find_by_sas_address - expander device search
757 * @ioc: per adapter object
758 * @sas_address: sas address
759 * Context: Calling function should acquire ioc->sas_node_lock.
761 * This searches for expander device based on sas_address, then returns the
765 mpt2sas_scsih_expander_find_by_sas_address(struct MPT2SAS_ADAPTER
*ioc
,
768 struct _sas_node
*sas_expander
, *r
;
771 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
772 if (sas_expander
->sas_address
!= sas_address
)
782 * _scsih_expander_node_add - insert expander device to the list.
783 * @ioc: per adapter object
784 * @sas_expander: the sas_device object
785 * Context: This function will acquire ioc->sas_node_lock.
787 * Adding new object to the ioc->sas_expander_list.
792 _scsih_expander_node_add(struct MPT2SAS_ADAPTER
*ioc
,
793 struct _sas_node
*sas_expander
)
797 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
798 list_add_tail(&sas_expander
->list
, &ioc
->sas_expander_list
);
799 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
803 * _scsih_is_end_device - determines if device is an end device
804 * @device_info: bitfield providing information about the device.
807 * Returns 1 if end device.
810 _scsih_is_end_device(u32 device_info
)
812 if (device_info
& MPI2_SAS_DEVICE_INFO_END_DEVICE
&&
813 ((device_info
& MPI2_SAS_DEVICE_INFO_SSP_TARGET
) |
814 (device_info
& MPI2_SAS_DEVICE_INFO_STP_TARGET
) |
815 (device_info
& MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)))
822 * mptscsih_get_scsi_lookup - returns scmd entry
823 * @ioc: per adapter object
824 * @smid: system request message index
826 * Returns the smid stored scmd pointer.
828 static struct scsi_cmnd
*
829 _scsih_scsi_lookup_get(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
831 return ioc
->scsi_lookup
[smid
- 1].scmd
;
835 * _scsih_scsi_lookup_find_by_scmd - scmd lookup
836 * @ioc: per adapter object
837 * @smid: system request message index
838 * @scmd: pointer to scsi command object
839 * Context: This function will acquire ioc->scsi_lookup_lock.
841 * This will search for a scmd pointer in the scsi_lookup array,
842 * returning the revelent smid. A returned value of zero means invalid.
845 _scsih_scsi_lookup_find_by_scmd(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_cmnd
852 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
854 for (i
= 0; i
< ioc
->scsiio_depth
; i
++) {
855 if (ioc
->scsi_lookup
[i
].scmd
== scmd
) {
856 smid
= ioc
->scsi_lookup
[i
].smid
;
861 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
866 * _scsih_scsi_lookup_find_by_target - search for matching channel:id
867 * @ioc: per adapter object
870 * Context: This function will acquire ioc->scsi_lookup_lock.
872 * This will search for a matching channel:id in the scsi_lookup array,
873 * returning 1 if found.
876 _scsih_scsi_lookup_find_by_target(struct MPT2SAS_ADAPTER
*ioc
, int id
,
883 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
885 for (i
= 0 ; i
< ioc
->scsiio_depth
; i
++) {
886 if (ioc
->scsi_lookup
[i
].scmd
&&
887 (ioc
->scsi_lookup
[i
].scmd
->device
->id
== id
&&
888 ioc
->scsi_lookup
[i
].scmd
->device
->channel
== channel
)) {
894 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
899 * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun
900 * @ioc: per adapter object
904 * Context: This function will acquire ioc->scsi_lookup_lock.
906 * This will search for a matching channel:id:lun in the scsi_lookup array,
907 * returning 1 if found.
910 _scsih_scsi_lookup_find_by_lun(struct MPT2SAS_ADAPTER
*ioc
, int id
,
911 unsigned int lun
, int channel
)
917 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
919 for (i
= 0 ; i
< ioc
->scsiio_depth
; i
++) {
920 if (ioc
->scsi_lookup
[i
].scmd
&&
921 (ioc
->scsi_lookup
[i
].scmd
->device
->id
== id
&&
922 ioc
->scsi_lookup
[i
].scmd
->device
->channel
== channel
&&
923 ioc
->scsi_lookup
[i
].scmd
->device
->lun
== lun
)) {
929 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
934 * _scsih_get_chain_buffer_tracker - obtain chain tracker
935 * @ioc: per adapter object
936 * @smid: smid associated to an IO request
938 * Returns chain tracker(from ioc->free_chain_list)
940 static struct chain_tracker
*
941 _scsih_get_chain_buffer_tracker(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
943 struct chain_tracker
*chain_req
;
946 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
947 if (list_empty(&ioc
->free_chain_list
)) {
948 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
949 printk(MPT2SAS_WARN_FMT
"chain buffers not available\n",
953 chain_req
= list_entry(ioc
->free_chain_list
.next
,
954 struct chain_tracker
, tracker_list
);
955 list_del_init(&chain_req
->tracker_list
);
956 list_add_tail(&chain_req
->tracker_list
,
957 &ioc
->scsi_lookup
[smid
- 1].chain_list
);
958 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
963 * _scsih_build_scatter_gather - main sg creation routine
964 * @ioc: per adapter object
965 * @scmd: scsi command
966 * @smid: system request message index
969 * The main routine that builds scatter gather table from a given
970 * scsi request sent via the .queuecommand main handler.
972 * Returns 0 success, anything else error
975 _scsih_build_scatter_gather(struct MPT2SAS_ADAPTER
*ioc
,
976 struct scsi_cmnd
*scmd
, u16 smid
)
978 Mpi2SCSIIORequest_t
*mpi_request
;
979 dma_addr_t chain_dma
;
980 struct scatterlist
*sg_scmd
;
981 void *sg_local
, *chain
;
988 u32 sgl_flags_last_element
;
989 u32 sgl_flags_end_buffer
;
990 struct chain_tracker
*chain_req
;
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
);
1007 if (sges_left
< 0) {
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_req
= _scsih_get_chain_buffer_tracker(ioc
, smid
);
1041 chain
= chain_req
->chain_buffer
;
1042 chain_dma
= chain_req
->chain_buffer_dma
;
1044 sges_in_segment
= (sges_left
<=
1045 ioc
->max_sges_in_chain_message
) ? sges_left
:
1046 ioc
->max_sges_in_chain_message
;
1047 chain_offset
= (sges_left
== sges_in_segment
) ?
1048 0 : (sges_in_segment
* ioc
->sge_size
)/4;
1049 chain_length
= sges_in_segment
* ioc
->sge_size
;
1051 chain_offset
= chain_offset
<<
1052 MPI2_SGE_CHAIN_OFFSET_SHIFT
;
1053 chain_length
+= ioc
->sge_size
;
1055 ioc
->base_add_sg_single(sg_local
, chain_flags
| chain_offset
|
1056 chain_length
, chain_dma
);
1059 goto fill_in_last_segment
;
1061 /* fill in chain segments */
1062 while (sges_in_segment
) {
1063 if (sges_in_segment
== 1)
1064 ioc
->base_add_sg_single(sg_local
,
1065 sgl_flags_last_element
|
1066 sg_dma_len(sg_scmd
),
1067 sg_dma_address(sg_scmd
));
1069 ioc
->base_add_sg_single(sg_local
, sgl_flags
|
1070 sg_dma_len(sg_scmd
),
1071 sg_dma_address(sg_scmd
));
1072 sg_scmd
= sg_next(sg_scmd
);
1073 sg_local
+= ioc
->sge_size
;
1078 chain_req
= _scsih_get_chain_buffer_tracker(ioc
, smid
);
1081 chain
= chain_req
->chain_buffer
;
1082 chain_dma
= chain_req
->chain_buffer_dma
;
1086 fill_in_last_segment
:
1088 /* fill the last segment */
1091 ioc
->base_add_sg_single(sg_local
, sgl_flags_end_buffer
|
1092 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
1094 ioc
->base_add_sg_single(sg_local
, sgl_flags
|
1095 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
1096 sg_scmd
= sg_next(sg_scmd
);
1097 sg_local
+= ioc
->sge_size
;
1105 * _scsih_change_queue_depth - setting device queue depth
1106 * @sdev: scsi device struct
1107 * @qdepth: requested queue depth
1108 * @reason: calling context
1110 * Returns queue depth.
1113 _scsih_change_queue_depth(struct scsi_device
*sdev
, int qdepth
, int reason
)
1115 struct Scsi_Host
*shost
= sdev
->host
;
1118 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1119 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1120 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1121 struct _sas_device
*sas_device
;
1122 unsigned long flags
;
1124 if (reason
!= SCSI_QDEPTH_DEFAULT
)
1127 max_depth
= shost
->can_queue
;
1129 /* limit max device queue for SATA to 32 */
1130 sas_device_priv_data
= sdev
->hostdata
;
1131 if (!sas_device_priv_data
)
1133 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
1134 if (!sas_target_priv_data
)
1136 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
))
1138 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1139 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1140 sas_device_priv_data
->sas_target
->sas_address
);
1141 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1142 if (sas_device
&& sas_device
->device_info
&
1143 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1144 max_depth
= MPT2SAS_SATA_QUEUE_DEPTH
;
1148 if (!sdev
->tagged_supported
)
1150 if (qdepth
> max_depth
)
1152 tag_type
= (qdepth
== 1) ? 0 : MSG_SIMPLE_TAG
;
1153 scsi_adjust_queue_depth(sdev
, tag_type
, qdepth
);
1155 if (sdev
->inquiry_len
> 7)
1156 sdev_printk(KERN_INFO
, sdev
, "qdepth(%d), tagged(%d), "
1157 "simple(%d), ordered(%d), scsi_level(%d), cmd_que(%d)\n",
1158 sdev
->queue_depth
, sdev
->tagged_supported
, sdev
->simple_tags
,
1159 sdev
->ordered_tags
, sdev
->scsi_level
,
1160 (sdev
->inquiry
[7] & 2) >> 1);
1162 return sdev
->queue_depth
;
1166 * _scsih_change_queue_type - changing device queue tag type
1167 * @sdev: scsi device struct
1168 * @tag_type: requested tag type
1170 * Returns queue tag type.
1173 _scsih_change_queue_type(struct scsi_device
*sdev
, int tag_type
)
1175 if (sdev
->tagged_supported
) {
1176 scsi_set_tag_type(sdev
, tag_type
);
1178 scsi_activate_tcq(sdev
, sdev
->queue_depth
);
1180 scsi_deactivate_tcq(sdev
, sdev
->queue_depth
);
1188 * _scsih_target_alloc - target add routine
1189 * @starget: scsi target struct
1191 * Returns 0 if ok. Any other return is assumed to be an error and
1192 * the device is ignored.
1195 _scsih_target_alloc(struct scsi_target
*starget
)
1197 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
1198 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1199 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1200 struct _sas_device
*sas_device
;
1201 struct _raid_device
*raid_device
;
1202 unsigned long flags
;
1203 struct sas_rphy
*rphy
;
1205 sas_target_priv_data
= kzalloc(sizeof(struct scsi_target
), GFP_KERNEL
);
1206 if (!sas_target_priv_data
)
1209 starget
->hostdata
= sas_target_priv_data
;
1210 sas_target_priv_data
->starget
= starget
;
1211 sas_target_priv_data
->handle
= MPT2SAS_INVALID_DEVICE_HANDLE
;
1214 if (starget
->channel
== RAID_CHANNEL
) {
1215 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1216 raid_device
= _scsih_raid_device_find_by_id(ioc
, starget
->id
,
1219 sas_target_priv_data
->handle
= raid_device
->handle
;
1220 sas_target_priv_data
->sas_address
= raid_device
->wwid
;
1221 sas_target_priv_data
->flags
|= MPT_TARGET_FLAGS_VOLUME
;
1222 raid_device
->starget
= starget
;
1224 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1228 /* sas/sata devices */
1229 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1230 rphy
= dev_to_rphy(starget
->dev
.parent
);
1231 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1232 rphy
->identify
.sas_address
);
1235 sas_target_priv_data
->handle
= sas_device
->handle
;
1236 sas_target_priv_data
->sas_address
= sas_device
->sas_address
;
1237 sas_device
->starget
= starget
;
1238 sas_device
->id
= starget
->id
;
1239 sas_device
->channel
= starget
->channel
;
1240 if (test_bit(sas_device
->handle
, ioc
->pd_handles
))
1241 sas_target_priv_data
->flags
|=
1242 MPT_TARGET_FLAGS_RAID_COMPONENT
;
1244 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1250 * _scsih_target_destroy - target destroy routine
1251 * @starget: scsi target struct
1256 _scsih_target_destroy(struct scsi_target
*starget
)
1258 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
1259 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1260 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1261 struct _sas_device
*sas_device
;
1262 struct _raid_device
*raid_device
;
1263 unsigned long flags
;
1264 struct sas_rphy
*rphy
;
1266 sas_target_priv_data
= starget
->hostdata
;
1267 if (!sas_target_priv_data
)
1270 if (starget
->channel
== RAID_CHANNEL
) {
1271 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1272 raid_device
= _scsih_raid_device_find_by_id(ioc
, starget
->id
,
1275 raid_device
->starget
= NULL
;
1276 raid_device
->sdev
= NULL
;
1278 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1282 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1283 rphy
= dev_to_rphy(starget
->dev
.parent
);
1284 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1285 rphy
->identify
.sas_address
);
1286 if (sas_device
&& (sas_device
->starget
== starget
) &&
1287 (sas_device
->id
== starget
->id
) &&
1288 (sas_device
->channel
== starget
->channel
))
1289 sas_device
->starget
= NULL
;
1291 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1294 kfree(sas_target_priv_data
);
1295 starget
->hostdata
= NULL
;
1299 * _scsih_slave_alloc - device add routine
1300 * @sdev: scsi device struct
1302 * Returns 0 if ok. Any other return is assumed to be an error and
1303 * the device is ignored.
1306 _scsih_slave_alloc(struct scsi_device
*sdev
)
1308 struct Scsi_Host
*shost
;
1309 struct MPT2SAS_ADAPTER
*ioc
;
1310 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1311 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1312 struct scsi_target
*starget
;
1313 struct _raid_device
*raid_device
;
1314 unsigned long flags
;
1316 sas_device_priv_data
= kzalloc(sizeof(struct scsi_device
), GFP_KERNEL
);
1317 if (!sas_device_priv_data
)
1320 sas_device_priv_data
->lun
= sdev
->lun
;
1321 sas_device_priv_data
->flags
= MPT_DEVICE_FLAGS_INIT
;
1323 starget
= scsi_target(sdev
);
1324 sas_target_priv_data
= starget
->hostdata
;
1325 sas_target_priv_data
->num_luns
++;
1326 sas_device_priv_data
->sas_target
= sas_target_priv_data
;
1327 sdev
->hostdata
= sas_device_priv_data
;
1328 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
))
1329 sdev
->no_uld_attach
= 1;
1331 shost
= dev_to_shost(&starget
->dev
);
1332 ioc
= shost_priv(shost
);
1333 if (starget
->channel
== RAID_CHANNEL
) {
1334 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1335 raid_device
= _scsih_raid_device_find_by_id(ioc
,
1336 starget
->id
, starget
->channel
);
1338 raid_device
->sdev
= sdev
; /* raid is single lun */
1339 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1346 * _scsih_slave_destroy - device destroy routine
1347 * @sdev: scsi device struct
1352 _scsih_slave_destroy(struct scsi_device
*sdev
)
1354 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1355 struct scsi_target
*starget
;
1357 if (!sdev
->hostdata
)
1360 starget
= scsi_target(sdev
);
1361 sas_target_priv_data
= starget
->hostdata
;
1362 sas_target_priv_data
->num_luns
--;
1363 kfree(sdev
->hostdata
);
1364 sdev
->hostdata
= NULL
;
1368 * _scsih_display_sata_capabilities - sata capabilities
1369 * @ioc: per adapter object
1370 * @sas_device: the sas_device object
1371 * @sdev: scsi device struct
1374 _scsih_display_sata_capabilities(struct MPT2SAS_ADAPTER
*ioc
,
1375 struct _sas_device
*sas_device
, struct scsi_device
*sdev
)
1377 Mpi2ConfigReply_t mpi_reply
;
1378 Mpi2SasDevicePage0_t sas_device_pg0
;
1383 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
1384 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, sas_device
->handle
))) {
1385 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1386 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1390 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
1391 MPI2_IOCSTATUS_MASK
;
1392 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
1393 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1394 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1398 flags
= le16_to_cpu(sas_device_pg0
.Flags
);
1399 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
1401 sdev_printk(KERN_INFO
, sdev
,
1402 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1403 "sw_preserve(%s)\n",
1404 (device_info
& MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE
) ? "y" : "n",
1405 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED
) ? "y" : "n",
1406 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY
) ? "y" :
1408 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED
) ? "y" : "n",
1409 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED
) ? "y" : "n",
1410 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE
) ? "y" : "n");
1414 * _scsih_is_raid - return boolean indicating device is raid volume
1415 * @dev the device struct object
1418 _scsih_is_raid(struct device
*dev
)
1420 struct scsi_device
*sdev
= to_scsi_device(dev
);
1422 return (sdev
->channel
== RAID_CHANNEL
) ? 1 : 0;
1426 * _scsih_get_resync - get raid volume resync percent complete
1427 * @dev the device struct object
1430 _scsih_get_resync(struct device
*dev
)
1432 struct scsi_device
*sdev
= to_scsi_device(dev
);
1433 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
1434 static struct _raid_device
*raid_device
;
1435 unsigned long flags
;
1436 Mpi2RaidVolPage0_t vol_pg0
;
1437 Mpi2ConfigReply_t mpi_reply
;
1438 u32 volume_status_flags
;
1439 u8 percent_complete
= 0;
1441 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1442 raid_device
= _scsih_raid_device_find_by_id(ioc
, sdev
->id
,
1444 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1449 if (mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, &vol_pg0
,
1450 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, raid_device
->handle
,
1451 sizeof(Mpi2RaidVolPage0_t
))) {
1452 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1453 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1457 volume_status_flags
= le32_to_cpu(vol_pg0
.VolumeStatusFlags
);
1458 if (volume_status_flags
& MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS
)
1459 percent_complete
= raid_device
->percent_complete
;
1461 raid_set_resync(mpt2sas_raid_template
, dev
, percent_complete
);
1465 * _scsih_get_state - get raid volume level
1466 * @dev the device struct object
1469 _scsih_get_state(struct device
*dev
)
1471 struct scsi_device
*sdev
= to_scsi_device(dev
);
1472 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
1473 static struct _raid_device
*raid_device
;
1474 unsigned long flags
;
1475 Mpi2RaidVolPage0_t vol_pg0
;
1476 Mpi2ConfigReply_t mpi_reply
;
1478 enum raid_state state
= RAID_STATE_UNKNOWN
;
1480 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1481 raid_device
= _scsih_raid_device_find_by_id(ioc
, sdev
->id
,
1483 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1488 if (mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, &vol_pg0
,
1489 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, raid_device
->handle
,
1490 sizeof(Mpi2RaidVolPage0_t
))) {
1491 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1492 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1496 volstate
= le32_to_cpu(vol_pg0
.VolumeStatusFlags
);
1497 if (volstate
& MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS
) {
1498 state
= RAID_STATE_RESYNCING
;
1502 switch (vol_pg0
.VolumeState
) {
1503 case MPI2_RAID_VOL_STATE_OPTIMAL
:
1504 case MPI2_RAID_VOL_STATE_ONLINE
:
1505 state
= RAID_STATE_ACTIVE
;
1507 case MPI2_RAID_VOL_STATE_DEGRADED
:
1508 state
= RAID_STATE_DEGRADED
;
1510 case MPI2_RAID_VOL_STATE_FAILED
:
1511 case MPI2_RAID_VOL_STATE_MISSING
:
1512 state
= RAID_STATE_OFFLINE
;
1516 raid_set_state(mpt2sas_raid_template
, dev
, state
);
1520 * _scsih_set_level - set raid level
1521 * @sdev: scsi device struct
1522 * @raid_device: raid_device object
1525 _scsih_set_level(struct scsi_device
*sdev
, struct _raid_device
*raid_device
)
1527 enum raid_level level
= RAID_LEVEL_UNKNOWN
;
1529 switch (raid_device
->volume_type
) {
1530 case MPI2_RAID_VOL_TYPE_RAID0
:
1531 level
= RAID_LEVEL_0
;
1533 case MPI2_RAID_VOL_TYPE_RAID10
:
1534 level
= RAID_LEVEL_10
;
1536 case MPI2_RAID_VOL_TYPE_RAID1E
:
1537 level
= RAID_LEVEL_1E
;
1539 case MPI2_RAID_VOL_TYPE_RAID1
:
1540 level
= RAID_LEVEL_1
;
1544 raid_set_level(mpt2sas_raid_template
, &sdev
->sdev_gendev
, level
);
1548 * _scsih_get_volume_capabilities - volume capabilities
1549 * @ioc: per adapter object
1550 * @sas_device: the raid_device object
1553 _scsih_get_volume_capabilities(struct MPT2SAS_ADAPTER
*ioc
,
1554 struct _raid_device
*raid_device
)
1556 Mpi2RaidVolPage0_t
*vol_pg0
;
1557 Mpi2RaidPhysDiskPage0_t pd_pg0
;
1558 Mpi2SasDevicePage0_t sas_device_pg0
;
1559 Mpi2ConfigReply_t mpi_reply
;
1563 if ((mpt2sas_config_get_number_pds(ioc
, raid_device
->handle
,
1564 &num_pds
)) || !num_pds
) {
1565 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1566 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1570 raid_device
->num_pds
= num_pds
;
1571 sz
= offsetof(Mpi2RaidVolPage0_t
, PhysDisk
) + (num_pds
*
1572 sizeof(Mpi2RaidVol0PhysDisk_t
));
1573 vol_pg0
= kzalloc(sz
, GFP_KERNEL
);
1575 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1576 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1580 if ((mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, vol_pg0
,
1581 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, raid_device
->handle
, sz
))) {
1582 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1583 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1588 raid_device
->volume_type
= vol_pg0
->VolumeType
;
1590 /* figure out what the underlying devices are by
1591 * obtaining the device_info bits for the 1st device
1593 if (!(mpt2sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
1594 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM
,
1595 vol_pg0
->PhysDisk
[0].PhysDiskNum
))) {
1596 if (!(mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
1597 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
1598 le16_to_cpu(pd_pg0
.DevHandle
)))) {
1599 raid_device
->device_info
=
1600 le32_to_cpu(sas_device_pg0
.DeviceInfo
);
1608 * _scsih_enable_tlr - setting TLR flags
1609 * @ioc: per adapter object
1610 * @sdev: scsi device struct
1612 * Enabling Transaction Layer Retries for tape devices when
1613 * vpd page 0x90 is present
1617 _scsih_enable_tlr(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_device
*sdev
)
1620 if (sdev
->type
!= TYPE_TAPE
)
1623 if (!(ioc
->facts
.IOCCapabilities
& MPI2_IOCFACTS_CAPABILITY_TLR
))
1626 sas_enable_tlr(sdev
);
1627 sdev_printk(KERN_INFO
, sdev
, "TLR %s\n",
1628 sas_is_tlr_enabled(sdev
) ? "Enabled" : "Disabled");
1634 * _scsih_slave_configure - device configure routine.
1635 * @sdev: scsi device struct
1637 * Returns 0 if ok. Any other return is assumed to be an error and
1638 * the device is ignored.
1641 _scsih_slave_configure(struct scsi_device
*sdev
)
1643 struct Scsi_Host
*shost
= sdev
->host
;
1644 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1645 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1646 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1647 struct _sas_device
*sas_device
;
1648 struct _raid_device
*raid_device
;
1649 unsigned long flags
;
1656 sas_device_priv_data
= sdev
->hostdata
;
1657 sas_device_priv_data
->configured_lun
= 1;
1658 sas_device_priv_data
->flags
&= ~MPT_DEVICE_FLAGS_INIT
;
1659 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
1661 /* raid volume handling */
1662 if (sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
1664 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1665 raid_device
= _scsih_raid_device_find_by_handle(ioc
,
1666 sas_target_priv_data
->handle
);
1667 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1669 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1670 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1674 _scsih_get_volume_capabilities(ioc
, raid_device
);
1676 /* RAID Queue Depth Support
1677 * IS volume = underlying qdepth of drive type, either
1678 * MPT2SAS_SAS_QUEUE_DEPTH or MPT2SAS_SATA_QUEUE_DEPTH
1679 * IM/IME/R10 = 128 (MPT2SAS_RAID_QUEUE_DEPTH)
1681 if (raid_device
->device_info
&
1682 MPI2_SAS_DEVICE_INFO_SSP_TARGET
) {
1683 qdepth
= MPT2SAS_SAS_QUEUE_DEPTH
;
1686 qdepth
= MPT2SAS_SATA_QUEUE_DEPTH
;
1687 if (raid_device
->device_info
&
1688 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1694 switch (raid_device
->volume_type
) {
1695 case MPI2_RAID_VOL_TYPE_RAID0
:
1698 case MPI2_RAID_VOL_TYPE_RAID1E
:
1699 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
1700 if (ioc
->manu_pg10
.OEMIdentifier
&&
1701 (ioc
->manu_pg10
.GenericFlags0
&
1702 MFG10_GF0_R10_DISPLAY
) &&
1703 !(raid_device
->num_pds
% 2))
1708 case MPI2_RAID_VOL_TYPE_RAID1
:
1709 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
1712 case MPI2_RAID_VOL_TYPE_RAID10
:
1713 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
1716 case MPI2_RAID_VOL_TYPE_UNKNOWN
:
1718 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
1723 sdev_printk(KERN_INFO
, sdev
, "%s: "
1724 "handle(0x%04x), wwid(0x%016llx), pd_count(%d), type(%s)\n",
1725 r_level
, raid_device
->handle
,
1726 (unsigned long long)raid_device
->wwid
,
1727 raid_device
->num_pds
, ds
);
1728 _scsih_change_queue_depth(sdev
, qdepth
, SCSI_QDEPTH_DEFAULT
);
1729 /* raid transport support */
1730 _scsih_set_level(sdev
, raid_device
);
1734 /* non-raid handling */
1735 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1736 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1737 sas_device_priv_data
->sas_target
->sas_address
);
1738 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1740 if (sas_target_priv_data
->flags
&
1741 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
1742 mpt2sas_config_get_volume_handle(ioc
,
1743 sas_device
->handle
, &sas_device
->volume_handle
);
1744 mpt2sas_config_get_volume_wwid(ioc
,
1745 sas_device
->volume_handle
,
1746 &sas_device
->volume_wwid
);
1748 if (sas_device
->device_info
& MPI2_SAS_DEVICE_INFO_SSP_TARGET
) {
1749 qdepth
= MPT2SAS_SAS_QUEUE_DEPTH
;
1753 qdepth
= MPT2SAS_SATA_QUEUE_DEPTH
;
1754 if (sas_device
->device_info
&
1755 MPI2_SAS_DEVICE_INFO_STP_TARGET
)
1757 else if (sas_device
->device_info
&
1758 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1762 sdev_printk(KERN_INFO
, sdev
, "%s: handle(0x%04x), "
1763 "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n",
1764 ds
, sas_device
->handle
,
1765 (unsigned long long)sas_device
->sas_address
,
1767 (unsigned long long)sas_device
->device_name
);
1768 sdev_printk(KERN_INFO
, sdev
, "%s: "
1769 "enclosure_logical_id(0x%016llx), slot(%d)\n", ds
,
1770 (unsigned long long) sas_device
->enclosure_logical_id
,
1774 _scsih_display_sata_capabilities(ioc
, sas_device
, sdev
);
1777 _scsih_change_queue_depth(sdev
, qdepth
, SCSI_QDEPTH_DEFAULT
);
1780 sas_read_port_mode_page(sdev
);
1781 _scsih_enable_tlr(ioc
, sdev
);
1787 * _scsih_bios_param - fetch head, sector, cylinder info for a disk
1788 * @sdev: scsi device struct
1789 * @bdev: pointer to block device context
1790 * @capacity: device size (in 512 byte sectors)
1791 * @params: three element array to place output:
1792 * params[0] number of heads (max 255)
1793 * params[1] number of sectors (max 63)
1794 * params[2] number of cylinders
1799 _scsih_bios_param(struct scsi_device
*sdev
, struct block_device
*bdev
,
1800 sector_t capacity
, int params
[])
1810 dummy
= heads
* sectors
;
1811 cylinders
= capacity
;
1812 sector_div(cylinders
, dummy
);
1815 * Handle extended translation size for logical drives
1818 if ((ulong
)capacity
>= 0x200000) {
1821 dummy
= heads
* sectors
;
1822 cylinders
= capacity
;
1823 sector_div(cylinders
, dummy
);
1828 params
[1] = sectors
;
1829 params
[2] = cylinders
;
1835 * _scsih_response_code - translation of device response code
1836 * @ioc: per adapter object
1837 * @response_code: response code returned by the device
1842 _scsih_response_code(struct MPT2SAS_ADAPTER
*ioc
, u8 response_code
)
1846 switch (response_code
) {
1847 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE
:
1848 desc
= "task management request completed";
1850 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
:
1851 desc
= "invalid frame";
1853 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED
:
1854 desc
= "task management request not supported";
1856 case MPI2_SCSITASKMGMT_RSP_TM_FAILED
:
1857 desc
= "task management request failed";
1859 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
:
1860 desc
= "task management request succeeded";
1862 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN
:
1863 desc
= "invalid lun";
1866 desc
= "overlapped tag attempted";
1868 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
:
1869 desc
= "task queued, however not sent to target";
1875 printk(MPT2SAS_WARN_FMT
"response_code(0x%01x): %s\n",
1876 ioc
->name
, response_code
, desc
);
1880 * _scsih_tm_done - tm completion routine
1881 * @ioc: per adapter object
1882 * @smid: system request message index
1883 * @msix_index: MSIX table index supplied by the OS
1884 * @reply: reply message frame(lower 32bit addr)
1887 * The callback handler when using scsih_issue_tm.
1889 * Return 1 meaning mf should be freed from _base_interrupt
1890 * 0 means the mf is freed from this function.
1893 _scsih_tm_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
1895 MPI2DefaultReply_t
*mpi_reply
;
1897 if (ioc
->tm_cmds
.status
== MPT2_CMD_NOT_USED
)
1899 if (ioc
->tm_cmds
.smid
!= smid
)
1901 ioc
->tm_cmds
.status
|= MPT2_CMD_COMPLETE
;
1902 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
1904 memcpy(ioc
->tm_cmds
.reply
, mpi_reply
, mpi_reply
->MsgLength
*4);
1905 ioc
->tm_cmds
.status
|= MPT2_CMD_REPLY_VALID
;
1907 ioc
->tm_cmds
.status
&= ~MPT2_CMD_PENDING
;
1908 complete(&ioc
->tm_cmds
.done
);
1913 * mpt2sas_scsih_set_tm_flag - set per target tm_busy
1914 * @ioc: per adapter object
1915 * @handle: device handle
1917 * During taskmangement request, we need to freeze the device queue.
1920 mpt2sas_scsih_set_tm_flag(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
1922 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1923 struct scsi_device
*sdev
;
1926 shost_for_each_device(sdev
, ioc
->shost
) {
1929 sas_device_priv_data
= sdev
->hostdata
;
1930 if (!sas_device_priv_data
)
1932 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
1933 sas_device_priv_data
->sas_target
->tm_busy
= 1;
1935 ioc
->ignore_loginfos
= 1;
1941 * mpt2sas_scsih_clear_tm_flag - clear per target tm_busy
1942 * @ioc: per adapter object
1943 * @handle: device handle
1945 * During taskmangement request, we need to freeze the device queue.
1948 mpt2sas_scsih_clear_tm_flag(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
1950 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1951 struct scsi_device
*sdev
;
1954 shost_for_each_device(sdev
, ioc
->shost
) {
1957 sas_device_priv_data
= sdev
->hostdata
;
1958 if (!sas_device_priv_data
)
1960 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
1961 sas_device_priv_data
->sas_target
->tm_busy
= 0;
1963 ioc
->ignore_loginfos
= 0;
1970 * mpt2sas_scsih_issue_tm - main routine for sending tm requests
1971 * @ioc: per adapter struct
1972 * @device_handle: device handle
1973 * @channel: the channel assigned by the OS
1974 * @id: the id assigned by the OS
1976 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
1977 * @smid_task: smid assigned to the task
1978 * @timeout: timeout in seconds
1981 * A generic API for sending task management requests to firmware.
1983 * The callback index is set inside `ioc->tm_cb_idx`.
1985 * Return SUCCESS or FAILED.
1988 mpt2sas_scsih_issue_tm(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
, uint channel
,
1989 uint id
, uint lun
, u8 type
, u16 smid_task
, ulong timeout
,
1990 struct scsi_cmnd
*scmd
)
1992 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
1993 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
1996 unsigned long timeleft
;
1997 struct scsi_cmnd
*scmd_lookup
;
2000 mutex_lock(&ioc
->tm_cmds
.mutex
);
2001 if (ioc
->tm_cmds
.status
!= MPT2_CMD_NOT_USED
) {
2002 printk(MPT2SAS_INFO_FMT
"%s: tm_cmd busy!!!\n",
2003 __func__
, ioc
->name
);
2008 if (ioc
->shost_recovery
|| ioc
->remove_host
||
2009 ioc
->pci_error_recovery
) {
2010 printk(MPT2SAS_INFO_FMT
"%s: host reset in progress!\n",
2011 __func__
, ioc
->name
);
2016 ioc_state
= mpt2sas_base_get_iocstate(ioc
, 0);
2017 if (ioc_state
& MPI2_DOORBELL_USED
) {
2018 dhsprintk(ioc
, printk(MPT2SAS_INFO_FMT
"unexpected doorbell "
2019 "active!\n", ioc
->name
));
2020 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2026 if ((ioc_state
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_FAULT
) {
2027 mpt2sas_base_fault_info(ioc
, ioc_state
&
2028 MPI2_DOORBELL_DATA_MASK
);
2029 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2035 smid
= mpt2sas_base_get_smid_hpr(ioc
, ioc
->tm_cb_idx
);
2037 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
2038 ioc
->name
, __func__
);
2043 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"sending tm: handle(0x%04x),"
2044 " task_type(0x%02x), smid(%d)\n", ioc
->name
, handle
, type
,
2046 ioc
->tm_cmds
.status
= MPT2_CMD_PENDING
;
2047 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
2048 ioc
->tm_cmds
.smid
= smid
;
2049 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
2050 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
2051 mpi_request
->DevHandle
= cpu_to_le16(handle
);
2052 mpi_request
->TaskType
= type
;
2053 mpi_request
->TaskMID
= cpu_to_le16(smid_task
);
2054 int_to_scsilun(lun
, (struct scsi_lun
*)mpi_request
->LUN
);
2055 mpt2sas_scsih_set_tm_flag(ioc
, handle
);
2056 init_completion(&ioc
->tm_cmds
.done
);
2057 mpt2sas_base_put_smid_hi_priority(ioc
, smid
);
2058 timeleft
= wait_for_completion_timeout(&ioc
->tm_cmds
.done
, timeout
*HZ
);
2059 if (!(ioc
->tm_cmds
.status
& MPT2_CMD_COMPLETE
)) {
2060 printk(MPT2SAS_ERR_FMT
"%s: timeout\n",
2061 ioc
->name
, __func__
);
2062 _debug_dump_mf(mpi_request
,
2063 sizeof(Mpi2SCSITaskManagementRequest_t
)/4);
2064 if (!(ioc
->tm_cmds
.status
& MPT2_CMD_RESET
)) {
2065 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2068 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
2069 mpt2sas_scsih_clear_tm_flag(ioc
, handle
);
2074 if (ioc
->tm_cmds
.status
& MPT2_CMD_REPLY_VALID
) {
2075 mpi_reply
= ioc
->tm_cmds
.reply
;
2076 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"complete tm: "
2077 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
2078 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
2079 le32_to_cpu(mpi_reply
->IOCLogInfo
),
2080 le32_to_cpu(mpi_reply
->TerminationCount
)));
2081 if (ioc
->logging_level
& MPT_DEBUG_TM
) {
2082 _scsih_response_code(ioc
, mpi_reply
->ResponseCode
);
2083 if (mpi_reply
->IOCStatus
)
2084 _debug_dump_mf(mpi_request
,
2085 sizeof(Mpi2SCSITaskManagementRequest_t
)/4);
2090 * Check to see the commands were terminated.
2091 * This is only needed for eh callbacks, hence the scmd check.
2095 goto bypass_sanity_checks
;
2097 case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
:
2098 scmd_lookup
= _scsih_scsi_lookup_get(ioc
, smid_task
);
2099 if (scmd_lookup
&& (scmd_lookup
->serial_number
==
2100 scmd
->serial_number
))
2106 case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
:
2107 if (_scsih_scsi_lookup_find_by_target(ioc
, id
, channel
))
2113 case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET
:
2114 if (_scsih_scsi_lookup_find_by_lun(ioc
, id
, lun
, channel
))
2121 bypass_sanity_checks
:
2123 mpt2sas_scsih_clear_tm_flag(ioc
, handle
);
2124 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
2125 mutex_unlock(&ioc
->tm_cmds
.mutex
);
2130 mutex_unlock(&ioc
->tm_cmds
.mutex
);
2135 * _scsih_tm_display_info - displays info about the device
2136 * @ioc: per adapter struct
2137 * @scmd: pointer to scsi command object
2139 * Called by task management callback handlers.
2142 _scsih_tm_display_info(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
)
2144 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
2145 struct MPT2SAS_TARGET
*priv_target
= starget
->hostdata
;
2146 struct _sas_device
*sas_device
= NULL
;
2147 unsigned long flags
;
2152 scsi_print_command(scmd
);
2153 if (priv_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
2154 starget_printk(KERN_INFO
, starget
, "volume handle(0x%04x), "
2155 "volume wwid(0x%016llx)\n",
2156 priv_target
->handle
,
2157 (unsigned long long)priv_target
->sas_address
);
2159 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2160 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
2161 priv_target
->sas_address
);
2163 if (priv_target
->flags
&
2164 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2165 starget_printk(KERN_INFO
, starget
,
2166 "volume handle(0x%04x), "
2167 "volume wwid(0x%016llx)\n",
2168 sas_device
->volume_handle
,
2169 (unsigned long long)sas_device
->volume_wwid
);
2171 starget_printk(KERN_INFO
, starget
,
2172 "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n",
2174 (unsigned long long)sas_device
->sas_address
,
2176 starget_printk(KERN_INFO
, starget
,
2177 "enclosure_logical_id(0x%016llx), slot(%d)\n",
2178 (unsigned long long)sas_device
->enclosure_logical_id
,
2181 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2186 * _scsih_abort - eh threads main abort routine
2187 * @scmd: pointer to scsi command object
2189 * Returns SUCCESS if command aborted else FAILED
2192 _scsih_abort(struct scsi_cmnd
*scmd
)
2194 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2195 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2200 sdev_printk(KERN_INFO
, scmd
->device
, "attempting task abort! "
2201 "scmd(%p)\n", scmd
);
2202 _scsih_tm_display_info(ioc
, scmd
);
2204 sas_device_priv_data
= scmd
->device
->hostdata
;
2205 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2206 sdev_printk(KERN_INFO
, scmd
->device
, "device been deleted! "
2207 "scmd(%p)\n", scmd
);
2208 scmd
->result
= DID_NO_CONNECT
<< 16;
2209 scmd
->scsi_done(scmd
);
2214 /* search for the command */
2215 smid
= _scsih_scsi_lookup_find_by_scmd(ioc
, scmd
);
2217 scmd
->result
= DID_RESET
<< 16;
2222 /* for hidden raid components and volumes this is not supported */
2223 if (sas_device_priv_data
->sas_target
->flags
&
2224 MPT_TARGET_FLAGS_RAID_COMPONENT
||
2225 sas_device_priv_data
->sas_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
2226 scmd
->result
= DID_RESET
<< 16;
2231 mpt2sas_halt_firmware(ioc
);
2233 handle
= sas_device_priv_data
->sas_target
->handle
;
2234 r
= mpt2sas_scsih_issue_tm(ioc
, handle
, scmd
->device
->channel
,
2235 scmd
->device
->id
, scmd
->device
->lun
,
2236 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
, smid
, 30, scmd
);
2239 sdev_printk(KERN_INFO
, scmd
->device
, "task abort: %s scmd(%p)\n",
2240 ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2245 * _scsih_dev_reset - eh threads main device reset routine
2246 * @scmd: pointer to scsi command object
2248 * Returns SUCCESS if command aborted else FAILED
2251 _scsih_dev_reset(struct scsi_cmnd
*scmd
)
2253 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2254 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2255 struct _sas_device
*sas_device
;
2256 unsigned long flags
;
2260 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
2262 starget_printk(KERN_INFO
, starget
, "attempting target reset! "
2263 "scmd(%p)\n", scmd
);
2264 _scsih_tm_display_info(ioc
, scmd
);
2266 sas_device_priv_data
= scmd
->device
->hostdata
;
2267 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2268 starget_printk(KERN_INFO
, starget
, "target been deleted! "
2269 "scmd(%p)\n", scmd
);
2270 scmd
->result
= DID_NO_CONNECT
<< 16;
2271 scmd
->scsi_done(scmd
);
2276 /* for hidden raid components obtain the volume_handle */
2278 if (sas_device_priv_data
->sas_target
->flags
&
2279 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2280 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2281 sas_device
= _scsih_sas_device_find_by_handle(ioc
,
2282 sas_device_priv_data
->sas_target
->handle
);
2284 handle
= sas_device
->volume_handle
;
2285 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2287 handle
= sas_device_priv_data
->sas_target
->handle
;
2290 scmd
->result
= DID_RESET
<< 16;
2295 r
= mpt2sas_scsih_issue_tm(ioc
, handle
, scmd
->device
->channel
,
2296 scmd
->device
->id
, scmd
->device
->lun
,
2297 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET
, 0, 30, scmd
);
2300 sdev_printk(KERN_INFO
, scmd
->device
, "device reset: %s scmd(%p)\n",
2301 ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2306 * _scsih_target_reset - eh threads main target reset routine
2307 * @scmd: pointer to scsi command object
2309 * Returns SUCCESS if command aborted else FAILED
2312 _scsih_target_reset(struct scsi_cmnd
*scmd
)
2314 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2315 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2316 struct _sas_device
*sas_device
;
2317 unsigned long flags
;
2320 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
2322 starget_printk(KERN_INFO
, starget
, "attempting target reset! "
2323 "scmd(%p)\n", scmd
);
2324 _scsih_tm_display_info(ioc
, scmd
);
2326 sas_device_priv_data
= scmd
->device
->hostdata
;
2327 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2328 starget_printk(KERN_INFO
, starget
, "target been deleted! "
2329 "scmd(%p)\n", scmd
);
2330 scmd
->result
= DID_NO_CONNECT
<< 16;
2331 scmd
->scsi_done(scmd
);
2336 /* for hidden raid components obtain the volume_handle */
2338 if (sas_device_priv_data
->sas_target
->flags
&
2339 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2340 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2341 sas_device
= _scsih_sas_device_find_by_handle(ioc
,
2342 sas_device_priv_data
->sas_target
->handle
);
2344 handle
= sas_device
->volume_handle
;
2345 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2347 handle
= sas_device_priv_data
->sas_target
->handle
;
2350 scmd
->result
= DID_RESET
<< 16;
2355 r
= mpt2sas_scsih_issue_tm(ioc
, handle
, scmd
->device
->channel
,
2356 scmd
->device
->id
, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
, 0,
2360 starget_printk(KERN_INFO
, starget
, "target reset: %s scmd(%p)\n",
2361 ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2366 * _scsih_host_reset - eh threads main host reset routine
2367 * @scmd: pointer to scsi command object
2369 * Returns SUCCESS if command aborted else FAILED
2372 _scsih_host_reset(struct scsi_cmnd
*scmd
)
2374 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2377 printk(MPT2SAS_INFO_FMT
"attempting host reset! scmd(%p)\n",
2379 scsi_print_command(scmd
);
2381 retval
= mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2383 r
= (retval
< 0) ? FAILED
: SUCCESS
;
2384 printk(MPT2SAS_INFO_FMT
"host reset: %s scmd(%p)\n",
2385 ioc
->name
, ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2391 * _scsih_fw_event_add - insert and queue up fw_event
2392 * @ioc: per adapter object
2393 * @fw_event: object describing the event
2394 * Context: This function will acquire ioc->fw_event_lock.
2396 * This adds the firmware event object into link list, then queues it up to
2397 * be processed from user context.
2402 _scsih_fw_event_add(struct MPT2SAS_ADAPTER
*ioc
, struct fw_event_work
*fw_event
)
2404 unsigned long flags
;
2406 if (ioc
->firmware_event_thread
== NULL
)
2409 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2410 list_add_tail(&fw_event
->list
, &ioc
->fw_event_list
);
2411 INIT_DELAYED_WORK(&fw_event
->delayed_work
, _firmware_event_work
);
2412 queue_delayed_work(ioc
->firmware_event_thread
,
2413 &fw_event
->delayed_work
, 0);
2414 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2418 * _scsih_fw_event_free - delete fw_event
2419 * @ioc: per adapter object
2420 * @fw_event: object describing the event
2421 * Context: This function will acquire ioc->fw_event_lock.
2423 * This removes firmware event object from link list, frees associated memory.
2428 _scsih_fw_event_free(struct MPT2SAS_ADAPTER
*ioc
, struct fw_event_work
2431 unsigned long flags
;
2433 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2434 list_del(&fw_event
->list
);
2435 kfree(fw_event
->event_data
);
2437 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2442 * _scsih_queue_rescan - queue a topology rescan from user context
2443 * @ioc: per adapter object
2448 _scsih_queue_rescan(struct MPT2SAS_ADAPTER
*ioc
)
2450 struct fw_event_work
*fw_event
;
2452 if (ioc
->wait_for_port_enable_to_complete
)
2454 fw_event
= kzalloc(sizeof(struct fw_event_work
), GFP_ATOMIC
);
2457 fw_event
->event
= MPT2SAS_RESCAN_AFTER_HOST_RESET
;
2458 fw_event
->ioc
= ioc
;
2459 _scsih_fw_event_add(ioc
, fw_event
);
2463 * _scsih_fw_event_cleanup_queue - cleanup event queue
2464 * @ioc: per adapter object
2466 * Walk the firmware event queue, either killing timers, or waiting
2467 * for outstanding events to complete
2472 _scsih_fw_event_cleanup_queue(struct MPT2SAS_ADAPTER
*ioc
)
2474 struct fw_event_work
*fw_event
, *next
;
2476 if (list_empty(&ioc
->fw_event_list
) ||
2477 !ioc
->firmware_event_thread
|| in_interrupt())
2480 list_for_each_entry_safe(fw_event
, next
, &ioc
->fw_event_list
, list
) {
2481 if (cancel_delayed_work(&fw_event
->delayed_work
)) {
2482 _scsih_fw_event_free(ioc
, fw_event
);
2485 fw_event
->cancel_pending_work
= 1;
2490 * _scsih_ublock_io_device - set the device state to SDEV_RUNNING
2491 * @ioc: per adapter object
2492 * @handle: device handle
2494 * During device pull we need to appropiately set the sdev state.
2497 _scsih_ublock_io_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
2499 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2500 struct scsi_device
*sdev
;
2502 shost_for_each_device(sdev
, ioc
->shost
) {
2503 sas_device_priv_data
= sdev
->hostdata
;
2504 if (!sas_device_priv_data
)
2506 if (!sas_device_priv_data
->block
)
2508 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2509 dewtprintk(ioc
, sdev_printk(KERN_INFO
, sdev
,
2510 MPT2SAS_INFO_FMT
"SDEV_RUNNING: "
2511 "handle(0x%04x)\n", ioc
->name
, handle
));
2512 sas_device_priv_data
->block
= 0;
2513 scsi_internal_device_unblock(sdev
);
2519 * _scsih_block_io_device - set the device state to SDEV_BLOCK
2520 * @ioc: per adapter object
2521 * @handle: device handle
2523 * During device pull we need to appropiately set the sdev state.
2526 _scsih_block_io_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
2528 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2529 struct scsi_device
*sdev
;
2531 shost_for_each_device(sdev
, ioc
->shost
) {
2532 sas_device_priv_data
= sdev
->hostdata
;
2533 if (!sas_device_priv_data
)
2535 if (sas_device_priv_data
->block
)
2537 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2538 dewtprintk(ioc
, sdev_printk(KERN_INFO
, sdev
,
2539 MPT2SAS_INFO_FMT
"SDEV_BLOCK: "
2540 "handle(0x%04x)\n", ioc
->name
, handle
));
2541 sas_device_priv_data
->block
= 1;
2542 scsi_internal_device_block(sdev
);
2548 * _scsih_block_io_to_children_attached_to_ex
2549 * @ioc: per adapter object
2550 * @sas_expander: the sas_device object
2552 * This routine set sdev state to SDEV_BLOCK for all devices
2553 * attached to this expander. This function called when expander is
2557 _scsih_block_io_to_children_attached_to_ex(struct MPT2SAS_ADAPTER
*ioc
,
2558 struct _sas_node
*sas_expander
)
2560 struct _sas_port
*mpt2sas_port
;
2561 struct _sas_device
*sas_device
;
2562 struct _sas_node
*expander_sibling
;
2563 unsigned long flags
;
2568 list_for_each_entry(mpt2sas_port
,
2569 &sas_expander
->sas_port_list
, port_list
) {
2570 if (mpt2sas_port
->remote_identify
.device_type
==
2572 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2574 mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
2575 mpt2sas_port
->remote_identify
.sas_address
);
2576 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2579 _scsih_block_io_device(ioc
, sas_device
->handle
);
2583 list_for_each_entry(mpt2sas_port
,
2584 &sas_expander
->sas_port_list
, port_list
) {
2586 if (mpt2sas_port
->remote_identify
.device_type
==
2587 SAS_EDGE_EXPANDER_DEVICE
||
2588 mpt2sas_port
->remote_identify
.device_type
==
2589 SAS_FANOUT_EXPANDER_DEVICE
) {
2591 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
2593 mpt2sas_scsih_expander_find_by_sas_address(
2594 ioc
, mpt2sas_port
->remote_identify
.sas_address
);
2595 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
2596 _scsih_block_io_to_children_attached_to_ex(ioc
,
2603 * _scsih_block_io_to_children_attached_directly
2604 * @ioc: per adapter object
2605 * @event_data: topology change event data
2607 * This routine set sdev state to SDEV_BLOCK for all devices
2608 * direct attached during device pull.
2611 _scsih_block_io_to_children_attached_directly(struct MPT2SAS_ADAPTER
*ioc
,
2612 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
2619 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
2620 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
2623 phy_number
= event_data
->StartPhyNum
+ i
;
2624 reason_code
= event_data
->PHY
[i
].PhyStatus
&
2625 MPI2_EVENT_SAS_TOPO_RC_MASK
;
2626 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
)
2627 _scsih_block_io_device(ioc
, handle
);
2632 * _scsih_tm_tr_send - send task management request
2633 * @ioc: per adapter object
2634 * @handle: device handle
2635 * Context: interrupt time.
2637 * This code is to initiate the device removal handshake protocal
2638 * with controller firmware. This function will issue target reset
2639 * using high priority request queue. It will send a sas iounit
2640 * controll request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
2642 * This is designed to send muliple task management request at the same
2643 * time to the fifo. If the fifo is full, we will append the request,
2644 * and process it in a future completion.
2647 _scsih_tm_tr_send(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
2649 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
2651 struct _sas_device
*sas_device
;
2652 struct MPT2SAS_TARGET
*sas_target_priv_data
;
2653 unsigned long flags
;
2654 struct _tr_list
*delayed_tr
;
2656 if (ioc
->shost_recovery
|| ioc
->remove_host
||
2657 ioc
->pci_error_recovery
) {
2658 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host reset in "
2659 "progress!\n", __func__
, ioc
->name
));
2663 /* if PD, then return */
2664 if (test_bit(handle
, ioc
->pd_handles
))
2667 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2668 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
2669 if (sas_device
&& sas_device
->starget
&&
2670 sas_device
->starget
->hostdata
) {
2671 sas_target_priv_data
= sas_device
->starget
->hostdata
;
2672 sas_target_priv_data
->deleted
= 1;
2673 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
2674 "setting delete flag: handle(0x%04x), "
2675 "sas_addr(0x%016llx)\n", ioc
->name
, handle
,
2676 (unsigned long long) sas_device
->sas_address
));
2678 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2680 smid
= mpt2sas_base_get_smid_hpr(ioc
, ioc
->tm_tr_cb_idx
);
2682 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
2685 INIT_LIST_HEAD(&delayed_tr
->list
);
2686 delayed_tr
->handle
= handle
;
2687 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_list
);
2688 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
2689 "DELAYED:tr:handle(0x%04x), (open)\n",
2690 ioc
->name
, handle
));
2694 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"tr_send:handle(0x%04x), "
2695 "(open), smid(%d), cb(%d)\n", ioc
->name
, handle
, smid
,
2696 ioc
->tm_tr_cb_idx
));
2697 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
2698 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
2699 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
2700 mpi_request
->DevHandle
= cpu_to_le16(handle
);
2701 mpi_request
->TaskType
= MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
;
2702 mpt2sas_base_put_smid_hi_priority(ioc
, smid
);
2708 * _scsih_sas_control_complete - completion routine
2709 * @ioc: per adapter object
2710 * @smid: system request message index
2711 * @msix_index: MSIX table index supplied by the OS
2712 * @reply: reply message frame(lower 32bit addr)
2713 * Context: interrupt time.
2715 * This is the sas iounit controll completion routine.
2716 * This code is part of the code to initiate the device removal
2717 * handshake protocal with controller firmware.
2719 * Return 1 meaning mf should be freed from _base_interrupt
2720 * 0 means the mf is freed from this function.
2723 _scsih_sas_control_complete(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
,
2724 u8 msix_index
, u32 reply
)
2726 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
2727 Mpi2SasIoUnitControlReply_t
*mpi_reply
=
2728 mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
2730 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
2731 "sc_complete:handle(0x%04x), (open) "
2732 "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
2733 ioc
->name
, le16_to_cpu(mpi_reply
->DevHandle
), smid
,
2734 le16_to_cpu(mpi_reply
->IOCStatus
),
2735 le32_to_cpu(mpi_reply
->IOCLogInfo
)));
2740 * _scsih_tm_tr_volume_send - send target reset request for volumes
2741 * @ioc: per adapter object
2742 * @handle: device handle
2743 * Context: interrupt time.
2745 * This is designed to send muliple task management request at the same
2746 * time to the fifo. If the fifo is full, we will append the request,
2747 * and process it in a future completion.
2750 _scsih_tm_tr_volume_send(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
2752 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
2754 struct _tr_list
*delayed_tr
;
2756 if (ioc
->shost_recovery
|| ioc
->remove_host
||
2757 ioc
->pci_error_recovery
) {
2758 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host reset in "
2759 "progress!\n", __func__
, ioc
->name
));
2763 smid
= mpt2sas_base_get_smid_hpr(ioc
, ioc
->tm_tr_volume_cb_idx
);
2765 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
2768 INIT_LIST_HEAD(&delayed_tr
->list
);
2769 delayed_tr
->handle
= handle
;
2770 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_volume_list
);
2771 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
2772 "DELAYED:tr:handle(0x%04x), (open)\n",
2773 ioc
->name
, handle
));
2777 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"tr_send:handle(0x%04x), "
2778 "(open), smid(%d), cb(%d)\n", ioc
->name
, handle
, smid
,
2779 ioc
->tm_tr_volume_cb_idx
));
2780 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
2781 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
2782 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
2783 mpi_request
->DevHandle
= cpu_to_le16(handle
);
2784 mpi_request
->TaskType
= MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
;
2785 mpt2sas_base_put_smid_hi_priority(ioc
, smid
);
2789 * _scsih_tm_volume_tr_complete - target reset completion
2790 * @ioc: per adapter object
2791 * @smid: system request message index
2792 * @msix_index: MSIX table index supplied by the OS
2793 * @reply: reply message frame(lower 32bit addr)
2794 * Context: interrupt time.
2796 * Return 1 meaning mf should be freed from _base_interrupt
2797 * 0 means the mf is freed from this function.
2800 _scsih_tm_volume_tr_complete(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
,
2801 u8 msix_index
, u32 reply
)
2804 Mpi2SCSITaskManagementRequest_t
*mpi_request_tm
;
2805 Mpi2SCSITaskManagementReply_t
*mpi_reply
=
2806 mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
2808 if (ioc
->shost_recovery
|| ioc
->remove_host
||
2809 ioc
->pci_error_recovery
) {
2810 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host reset in "
2811 "progress!\n", __func__
, ioc
->name
));
2815 mpi_request_tm
= mpt2sas_base_get_msg_frame(ioc
, smid
);
2816 handle
= le16_to_cpu(mpi_request_tm
->DevHandle
);
2817 if (handle
!= le16_to_cpu(mpi_reply
->DevHandle
)) {
2818 dewtprintk(ioc
, printk("spurious interrupt: "
2819 "handle(0x%04x:0x%04x), smid(%d)!!!\n", handle
,
2820 le16_to_cpu(mpi_reply
->DevHandle
), smid
));
2824 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
2825 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
2826 "loginfo(0x%08x), completed(%d)\n", ioc
->name
,
2827 handle
, smid
, le16_to_cpu(mpi_reply
->IOCStatus
),
2828 le32_to_cpu(mpi_reply
->IOCLogInfo
),
2829 le32_to_cpu(mpi_reply
->TerminationCount
)));
2831 return _scsih_check_for_pending_tm(ioc
, smid
);
2835 * _scsih_tm_tr_complete -
2836 * @ioc: per adapter object
2837 * @smid: system request message index
2838 * @msix_index: MSIX table index supplied by the OS
2839 * @reply: reply message frame(lower 32bit addr)
2840 * Context: interrupt time.
2842 * This is the target reset completion routine.
2843 * This code is part of the code to initiate the device removal
2844 * handshake protocal with controller firmware.
2845 * It will send a sas iounit controll request (MPI2_SAS_OP_REMOVE_DEVICE)
2847 * Return 1 meaning mf should be freed from _base_interrupt
2848 * 0 means the mf is freed from this function.
2851 _scsih_tm_tr_complete(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
,
2855 Mpi2SCSITaskManagementRequest_t
*mpi_request_tm
;
2856 Mpi2SCSITaskManagementReply_t
*mpi_reply
=
2857 mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
2858 Mpi2SasIoUnitControlRequest_t
*mpi_request
;
2861 if (ioc
->shost_recovery
|| ioc
->remove_host
||
2862 ioc
->pci_error_recovery
) {
2863 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host reset in "
2864 "progress!\n", __func__
, ioc
->name
));
2868 mpi_request_tm
= mpt2sas_base_get_msg_frame(ioc
, smid
);
2869 handle
= le16_to_cpu(mpi_request_tm
->DevHandle
);
2870 if (handle
!= le16_to_cpu(mpi_reply
->DevHandle
)) {
2871 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"spurious interrupt: "
2872 "handle(0x%04x:0x%04x), smid(%d)!!!\n", ioc
->name
, handle
,
2873 le16_to_cpu(mpi_reply
->DevHandle
), smid
));
2877 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
2878 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
2879 "loginfo(0x%08x), completed(%d)\n", ioc
->name
,
2880 handle
, smid
, le16_to_cpu(mpi_reply
->IOCStatus
),
2881 le32_to_cpu(mpi_reply
->IOCLogInfo
),
2882 le32_to_cpu(mpi_reply
->TerminationCount
)));
2884 smid_sas_ctrl
= mpt2sas_base_get_smid(ioc
, ioc
->tm_sas_control_cb_idx
);
2885 if (!smid_sas_ctrl
) {
2886 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
2887 ioc
->name
, __func__
);
2891 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"sc_send:handle(0x%04x), "
2892 "(open), smid(%d), cb(%d)\n", ioc
->name
, handle
, smid_sas_ctrl
,
2893 ioc
->tm_sas_control_cb_idx
));
2894 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid_sas_ctrl
);
2895 memset(mpi_request
, 0, sizeof(Mpi2SasIoUnitControlRequest_t
));
2896 mpi_request
->Function
= MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
;
2897 mpi_request
->Operation
= MPI2_SAS_OP_REMOVE_DEVICE
;
2898 mpi_request
->DevHandle
= mpi_request_tm
->DevHandle
;
2899 mpt2sas_base_put_smid_default(ioc
, smid_sas_ctrl
);
2901 return _scsih_check_for_pending_tm(ioc
, smid
);
2905 * _scsih_check_for_pending_tm - check for pending task management
2906 * @ioc: per adapter object
2907 * @smid: system request message index
2909 * This will check delayed target reset list, and feed the
2912 * Return 1 meaning mf should be freed from _base_interrupt
2913 * 0 means the mf is freed from this function.
2916 _scsih_check_for_pending_tm(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
2918 struct _tr_list
*delayed_tr
;
2920 if (!list_empty(&ioc
->delayed_tr_volume_list
)) {
2921 delayed_tr
= list_entry(ioc
->delayed_tr_volume_list
.next
,
2922 struct _tr_list
, list
);
2923 mpt2sas_base_free_smid(ioc
, smid
);
2924 _scsih_tm_tr_volume_send(ioc
, delayed_tr
->handle
);
2925 list_del(&delayed_tr
->list
);
2930 if (!list_empty(&ioc
->delayed_tr_list
)) {
2931 delayed_tr
= list_entry(ioc
->delayed_tr_list
.next
,
2932 struct _tr_list
, list
);
2933 mpt2sas_base_free_smid(ioc
, smid
);
2934 _scsih_tm_tr_send(ioc
, delayed_tr
->handle
);
2935 list_del(&delayed_tr
->list
);
2944 * _scsih_check_topo_delete_events - sanity check on topo events
2945 * @ioc: per adapter object
2946 * @event_data: the event data payload
2948 * This routine added to better handle cable breaker.
2950 * This handles the case where driver recieves multiple expander
2951 * add and delete events in a single shot. When there is a delete event
2952 * the routine will void any pending add events waiting in the event queue.
2957 _scsih_check_topo_delete_events(struct MPT2SAS_ADAPTER
*ioc
,
2958 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
2960 struct fw_event_work
*fw_event
;
2961 Mpi2EventDataSasTopologyChangeList_t
*local_event_data
;
2962 u16 expander_handle
;
2963 struct _sas_node
*sas_expander
;
2964 unsigned long flags
;
2968 for (i
= 0 ; i
< event_data
->NumEntries
; i
++) {
2969 if (event_data
->PHY
[i
].PhyStatus
&
2970 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT
)
2972 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
2975 reason_code
= event_data
->PHY
[i
].PhyStatus
&
2976 MPI2_EVENT_SAS_TOPO_RC_MASK
;
2977 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
)
2978 _scsih_tm_tr_send(ioc
, handle
);
2981 expander_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
2982 if (expander_handle
< ioc
->sas_hba
.num_phys
) {
2983 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
2987 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
2988 || event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
) {
2989 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
2990 sas_expander
= mpt2sas_scsih_expander_find_by_handle(ioc
,
2992 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
2993 _scsih_block_io_to_children_attached_to_ex(ioc
, sas_expander
);
2994 } else if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_RESPONDING
)
2995 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
2997 if (event_data
->ExpStatus
!= MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
)
3000 /* mark ignore flag for pending events */
3001 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
3002 list_for_each_entry(fw_event
, &ioc
->fw_event_list
, list
) {
3003 if (fw_event
->event
!= MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
||
3006 local_event_data
= fw_event
->event_data
;
3007 if (local_event_data
->ExpStatus
==
3008 MPI2_EVENT_SAS_TOPO_ES_ADDED
||
3009 local_event_data
->ExpStatus
==
3010 MPI2_EVENT_SAS_TOPO_ES_RESPONDING
) {
3011 if (le16_to_cpu(local_event_data
->ExpanderDevHandle
) ==
3013 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3014 "setting ignoring flag\n", ioc
->name
));
3015 fw_event
->ignore
= 1;
3019 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
3023 * _scsih_set_volume_delete_flag - setting volume delete flag
3024 * @ioc: per adapter object
3025 * @handle: device handle
3031 _scsih_set_volume_delete_flag(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
3033 struct _raid_device
*raid_device
;
3034 struct MPT2SAS_TARGET
*sas_target_priv_data
;
3035 unsigned long flags
;
3037 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
3038 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
3039 if (raid_device
&& raid_device
->starget
&&
3040 raid_device
->starget
->hostdata
) {
3041 sas_target_priv_data
=
3042 raid_device
->starget
->hostdata
;
3043 sas_target_priv_data
->deleted
= 1;
3044 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3045 "setting delete flag: handle(0x%04x), "
3046 "wwid(0x%016llx)\n", ioc
->name
, handle
,
3047 (unsigned long long) raid_device
->wwid
));
3049 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
3053 * _scsih_set_volume_handle_for_tr - set handle for target reset to volume
3054 * @handle: input handle
3055 * @a: handle for volume a
3056 * @b: handle for volume b
3058 * IR firmware only supports two raid volumes. The purpose of this
3059 * routine is to set the volume handle in either a or b. When the given
3060 * input handle is non-zero, or when a and b have not been set before.
3063 _scsih_set_volume_handle_for_tr(u16 handle
, u16
*a
, u16
*b
)
3065 if (!handle
|| handle
== *a
|| handle
== *b
)
3074 * _scsih_check_ir_config_unhide_events - check for UNHIDE events
3075 * @ioc: per adapter object
3076 * @event_data: the event data payload
3077 * Context: interrupt time.
3079 * This routine will send target reset to volume, followed by target
3080 * resets to the PDs. This is called when a PD has been removed, or
3081 * volume has been deleted or removed. When the target reset is sent
3082 * to volume, the PD target resets need to be queued to start upon
3083 * completion of the volume target reset.
3088 _scsih_check_ir_config_unhide_events(struct MPT2SAS_ADAPTER
*ioc
,
3089 Mpi2EventDataIrConfigChangeList_t
*event_data
)
3091 Mpi2EventIrConfigElement_t
*element
;
3093 u16 handle
, volume_handle
, a
, b
;
3094 struct _tr_list
*delayed_tr
;
3099 /* Volume Resets for Deleted or Removed */
3100 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
3101 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
3102 if (element
->ReasonCode
==
3103 MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
||
3104 element
->ReasonCode
==
3105 MPI2_EVENT_IR_CHANGE_RC_REMOVED
) {
3106 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
3107 _scsih_set_volume_delete_flag(ioc
, volume_handle
);
3108 _scsih_set_volume_handle_for_tr(volume_handle
, &a
, &b
);
3112 /* Volume Resets for UNHIDE events */
3113 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
3114 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
3115 if (le32_to_cpu(event_data
->Flags
) &
3116 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
)
3118 if (element
->ReasonCode
== MPI2_EVENT_IR_CHANGE_RC_UNHIDE
) {
3119 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
3120 _scsih_set_volume_handle_for_tr(volume_handle
, &a
, &b
);
3125 _scsih_tm_tr_volume_send(ioc
, a
);
3127 _scsih_tm_tr_volume_send(ioc
, b
);
3129 /* PD target resets */
3130 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
3131 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
3132 if (element
->ReasonCode
!= MPI2_EVENT_IR_CHANGE_RC_UNHIDE
)
3134 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
3135 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
3136 clear_bit(handle
, ioc
->pd_handles
);
3138 _scsih_tm_tr_send(ioc
, handle
);
3139 else if (volume_handle
== a
|| volume_handle
== b
) {
3140 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
3141 BUG_ON(!delayed_tr
);
3142 INIT_LIST_HEAD(&delayed_tr
->list
);
3143 delayed_tr
->handle
= handle
;
3144 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_list
);
3145 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3146 "DELAYED:tr:handle(0x%04x), (open)\n", ioc
->name
,
3149 _scsih_tm_tr_send(ioc
, handle
);
3155 * _scsih_check_volume_delete_events - set delete flag for volumes
3156 * @ioc: per adapter object
3157 * @event_data: the event data payload
3158 * Context: interrupt time.
3160 * This will handle the case when the cable connected to entire volume is
3161 * pulled. We will take care of setting the deleted flag so normal IO will
3167 _scsih_check_volume_delete_events(struct MPT2SAS_ADAPTER
*ioc
,
3168 Mpi2EventDataIrVolume_t
*event_data
)
3172 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED
)
3174 state
= le32_to_cpu(event_data
->NewValue
);
3175 if (state
== MPI2_RAID_VOL_STATE_MISSING
|| state
==
3176 MPI2_RAID_VOL_STATE_FAILED
)
3177 _scsih_set_volume_delete_flag(ioc
,
3178 le16_to_cpu(event_data
->VolDevHandle
));
3182 * _scsih_flush_running_cmds - completing outstanding commands.
3183 * @ioc: per adapter object
3185 * The flushing out of all pending scmd commands following host reset,
3186 * where all IO is dropped to the floor.
3191 _scsih_flush_running_cmds(struct MPT2SAS_ADAPTER
*ioc
)
3193 struct scsi_cmnd
*scmd
;
3197 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
3198 scmd
= _scsih_scsi_lookup_get(ioc
, smid
);
3202 mpt2sas_base_free_smid(ioc
, smid
);
3203 scsi_dma_unmap(scmd
);
3204 if (ioc
->pci_error_recovery
)
3205 scmd
->result
= DID_NO_CONNECT
<< 16;
3207 scmd
->result
= DID_RESET
<< 16;
3208 scmd
->scsi_done(scmd
);
3210 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"completing %d cmds\n",
3215 * _scsih_setup_eedp - setup MPI request for EEDP transfer
3216 * @scmd: pointer to scsi command object
3217 * @mpi_request: pointer to the SCSI_IO reqest message frame
3219 * Supporting protection 1 and 3.
3224 _scsih_setup_eedp(struct scsi_cmnd
*scmd
, Mpi2SCSIIORequest_t
*mpi_request
)
3227 unsigned char prot_op
= scsi_get_prot_op(scmd
);
3228 unsigned char prot_type
= scsi_get_prot_type(scmd
);
3230 if (prot_type
== SCSI_PROT_DIF_TYPE0
|| prot_op
== SCSI_PROT_NORMAL
)
3233 if (prot_op
== SCSI_PROT_READ_STRIP
)
3234 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP
;
3235 else if (prot_op
== SCSI_PROT_WRITE_INSERT
)
3236 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_INSERT_OP
;
3240 switch (prot_type
) {
3241 case SCSI_PROT_DIF_TYPE1
:
3244 * enable ref/guard checking
3245 * auto increment ref tag
3247 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG
|
3248 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG
|
3249 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
3250 mpi_request
->CDB
.EEDP32
.PrimaryReferenceTag
=
3251 cpu_to_be32(scsi_get_lba(scmd
));
3254 case SCSI_PROT_DIF_TYPE2
:
3256 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG
|
3257 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG
|
3258 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
3261 case SCSI_PROT_DIF_TYPE3
:
3264 * enable guard checking
3266 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
3269 mpi_request
->EEDPBlockSize
= cpu_to_le32(scmd
->device
->sector_size
);
3270 mpi_request
->EEDPFlags
= cpu_to_le16(eedp_flags
);
3274 * _scsih_eedp_error_handling - return sense code for EEDP errors
3275 * @scmd: pointer to scsi command object
3276 * @ioc_status: ioc status
3281 _scsih_eedp_error_handling(struct scsi_cmnd
*scmd
, u16 ioc_status
)
3287 switch (ioc_status
) {
3288 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
3291 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
3294 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
3302 if (scmd
->sc_data_direction
== DMA_TO_DEVICE
) {
3303 sk
= ILLEGAL_REQUEST
;
3304 host_byte
= DID_ABORT
;
3306 sk
= ABORTED_COMMAND
;
3310 scsi_build_sense_buffer(0, scmd
->sense_buffer
, sk
, 0x10, ascq
);
3311 scmd
->result
= DRIVER_SENSE
<< 24 | (host_byte
<< 16) |
3312 SAM_STAT_CHECK_CONDITION
;
3316 * _scsih_qcmd - main scsi request entry point
3317 * @scmd: pointer to scsi command object
3318 * @done: function pointer to be invoked on completion
3320 * The callback index is set inside `ioc->scsi_io_cb_idx`.
3322 * Returns 0 on success. If there's a failure, return either:
3323 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
3324 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
3327 _scsih_qcmd_lck(struct scsi_cmnd
*scmd
, void (*done
)(struct scsi_cmnd
*))
3329 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
3330 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
3331 struct MPT2SAS_TARGET
*sas_target_priv_data
;
3332 Mpi2SCSIIORequest_t
*mpi_request
;
3336 scmd
->scsi_done
= done
;
3337 sas_device_priv_data
= scmd
->device
->hostdata
;
3338 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
3339 scmd
->result
= DID_NO_CONNECT
<< 16;
3340 scmd
->scsi_done(scmd
);
3344 if (ioc
->pci_error_recovery
) {
3345 scmd
->result
= DID_NO_CONNECT
<< 16;
3346 scmd
->scsi_done(scmd
);
3350 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
3351 /* invalid device handle */
3352 if (sas_target_priv_data
->handle
== MPT2SAS_INVALID_DEVICE_HANDLE
) {
3353 scmd
->result
= DID_NO_CONNECT
<< 16;
3354 scmd
->scsi_done(scmd
);
3358 /* host recovery or link resets sent via IOCTLs */
3359 if (ioc
->shost_recovery
|| ioc
->ioc_link_reset_in_progress
)
3360 return SCSI_MLQUEUE_HOST_BUSY
;
3361 /* device busy with task management */
3362 else if (sas_device_priv_data
->block
|| sas_target_priv_data
->tm_busy
)
3363 return SCSI_MLQUEUE_DEVICE_BUSY
;
3364 /* device has been deleted */
3365 else if (sas_target_priv_data
->deleted
) {
3366 scmd
->result
= DID_NO_CONNECT
<< 16;
3367 scmd
->scsi_done(scmd
);
3371 if (scmd
->sc_data_direction
== DMA_FROM_DEVICE
)
3372 mpi_control
= MPI2_SCSIIO_CONTROL_READ
;
3373 else if (scmd
->sc_data_direction
== DMA_TO_DEVICE
)
3374 mpi_control
= MPI2_SCSIIO_CONTROL_WRITE
;
3376 mpi_control
= MPI2_SCSIIO_CONTROL_NODATATRANSFER
;
3379 if (!(sas_device_priv_data
->flags
& MPT_DEVICE_FLAGS_INIT
)) {
3380 if (scmd
->device
->tagged_supported
) {
3381 if (scmd
->device
->ordered_tags
)
3382 mpi_control
|= MPI2_SCSIIO_CONTROL_ORDEREDQ
;
3384 mpi_control
|= MPI2_SCSIIO_CONTROL_SIMPLEQ
;
3386 /* MPI Revision I (UNIT = 0xA) - removed MPI2_SCSIIO_CONTROL_UNTAGGED */
3387 /* mpi_control |= MPI2_SCSIIO_CONTROL_UNTAGGED;
3389 mpi_control
|= (0x500);
3392 mpi_control
|= MPI2_SCSIIO_CONTROL_SIMPLEQ
;
3393 /* Make sure Device is not raid volume */
3394 if (!_scsih_is_raid(&scmd
->device
->sdev_gendev
) &&
3395 sas_is_tlr_enabled(scmd
->device
) && scmd
->cmd_len
!= 32)
3396 mpi_control
|= MPI2_SCSIIO_CONTROL_TLR_ON
;
3398 smid
= mpt2sas_base_get_smid_scsiio(ioc
, ioc
->scsi_io_cb_idx
, scmd
);
3400 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
3401 ioc
->name
, __func__
);
3404 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3405 memset(mpi_request
, 0, sizeof(Mpi2SCSIIORequest_t
));
3406 _scsih_setup_eedp(scmd
, mpi_request
);
3407 if (scmd
->cmd_len
== 32)
3408 mpi_control
|= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT
;
3409 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
3410 if (sas_device_priv_data
->sas_target
->flags
&
3411 MPT_TARGET_FLAGS_RAID_COMPONENT
)
3412 mpi_request
->Function
= MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
;
3414 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
3415 mpi_request
->DevHandle
=
3416 cpu_to_le16(sas_device_priv_data
->sas_target
->handle
);
3417 mpi_request
->DataLength
= cpu_to_le32(scsi_bufflen(scmd
));
3418 mpi_request
->Control
= cpu_to_le32(mpi_control
);
3419 mpi_request
->IoFlags
= cpu_to_le16(scmd
->cmd_len
);
3420 mpi_request
->MsgFlags
= MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR
;
3421 mpi_request
->SenseBufferLength
= SCSI_SENSE_BUFFERSIZE
;
3422 mpi_request
->SenseBufferLowAddress
=
3423 mpt2sas_base_get_sense_buffer_dma(ioc
, smid
);
3424 mpi_request
->SGLOffset0
= offsetof(Mpi2SCSIIORequest_t
, SGL
) / 4;
3425 mpi_request
->SGLFlags
= cpu_to_le16(MPI2_SCSIIO_SGLFLAGS_TYPE_MPI
+
3426 MPI2_SCSIIO_SGLFLAGS_SYSTEM_ADDR
);
3427 mpi_request
->VF_ID
= 0; /* TODO */
3428 mpi_request
->VP_ID
= 0;
3429 int_to_scsilun(sas_device_priv_data
->lun
, (struct scsi_lun
*)
3431 memcpy(mpi_request
->CDB
.CDB32
, scmd
->cmnd
, scmd
->cmd_len
);
3433 if (!mpi_request
->DataLength
) {
3434 mpt2sas_base_build_zero_len_sge(ioc
, &mpi_request
->SGL
);
3436 if (_scsih_build_scatter_gather(ioc
, scmd
, smid
)) {
3437 mpt2sas_base_free_smid(ioc
, smid
);
3442 if (likely(mpi_request
->Function
== MPI2_FUNCTION_SCSI_IO_REQUEST
))
3443 mpt2sas_base_put_smid_scsi_io(ioc
, smid
,
3444 sas_device_priv_data
->sas_target
->handle
);
3446 mpt2sas_base_put_smid_default(ioc
, smid
);
3450 return SCSI_MLQUEUE_HOST_BUSY
;
3453 static DEF_SCSI_QCMD(_scsih_qcmd
)
3456 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
3457 * @sense_buffer: sense data returned by target
3458 * @data: normalized skey/asc/ascq
3463 _scsih_normalize_sense(char *sense_buffer
, struct sense_info
*data
)
3465 if ((sense_buffer
[0] & 0x7F) >= 0x72) {
3466 /* descriptor format */
3467 data
->skey
= sense_buffer
[1] & 0x0F;
3468 data
->asc
= sense_buffer
[2];
3469 data
->ascq
= sense_buffer
[3];
3472 data
->skey
= sense_buffer
[2] & 0x0F;
3473 data
->asc
= sense_buffer
[12];
3474 data
->ascq
= sense_buffer
[13];
3478 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3480 * _scsih_scsi_ioc_info - translated non-successfull SCSI_IO request
3481 * @ioc: per adapter object
3482 * @scmd: pointer to scsi command object
3483 * @mpi_reply: reply mf payload returned from firmware
3485 * scsi_status - SCSI Status code returned from target device
3486 * scsi_state - state info associated with SCSI_IO determined by ioc
3487 * ioc_status - ioc supplied status info
3492 _scsih_scsi_ioc_info(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
,
3493 Mpi2SCSIIOReply_t
*mpi_reply
, u16 smid
)
3497 u16 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) &
3498 MPI2_IOCSTATUS_MASK
;
3499 u8 scsi_state
= mpi_reply
->SCSIState
;
3500 u8 scsi_status
= mpi_reply
->SCSIStatus
;
3501 char *desc_ioc_state
= NULL
;
3502 char *desc_scsi_status
= NULL
;
3503 char *desc_scsi_state
= ioc
->tmp_string
;
3504 u32 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
3505 struct _sas_device
*sas_device
= NULL
;
3506 unsigned long flags
;
3507 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
3508 struct MPT2SAS_TARGET
*priv_target
= starget
->hostdata
;
3513 if (log_info
== 0x31170000)
3516 switch (ioc_status
) {
3517 case MPI2_IOCSTATUS_SUCCESS
:
3518 desc_ioc_state
= "success";
3520 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
3521 desc_ioc_state
= "invalid function";
3523 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
3524 desc_ioc_state
= "scsi recovered error";
3526 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE
:
3527 desc_ioc_state
= "scsi invalid dev handle";
3529 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
3530 desc_ioc_state
= "scsi device not there";
3532 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
3533 desc_ioc_state
= "scsi data overrun";
3535 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
3536 desc_ioc_state
= "scsi data underrun";
3538 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
3539 desc_ioc_state
= "scsi io data error";
3541 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
3542 desc_ioc_state
= "scsi protocol error";
3544 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
3545 desc_ioc_state
= "scsi task terminated";
3547 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
3548 desc_ioc_state
= "scsi residual mismatch";
3550 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
3551 desc_ioc_state
= "scsi task mgmt failed";
3553 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
3554 desc_ioc_state
= "scsi ioc terminated";
3556 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
3557 desc_ioc_state
= "scsi ext terminated";
3559 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
3560 desc_ioc_state
= "eedp guard error";
3562 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
3563 desc_ioc_state
= "eedp ref tag error";
3565 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
3566 desc_ioc_state
= "eedp app tag error";
3569 desc_ioc_state
= "unknown";
3573 switch (scsi_status
) {
3574 case MPI2_SCSI_STATUS_GOOD
:
3575 desc_scsi_status
= "good";
3577 case MPI2_SCSI_STATUS_CHECK_CONDITION
:
3578 desc_scsi_status
= "check condition";
3580 case MPI2_SCSI_STATUS_CONDITION_MET
:
3581 desc_scsi_status
= "condition met";
3583 case MPI2_SCSI_STATUS_BUSY
:
3584 desc_scsi_status
= "busy";
3586 case MPI2_SCSI_STATUS_INTERMEDIATE
:
3587 desc_scsi_status
= "intermediate";
3589 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET
:
3590 desc_scsi_status
= "intermediate condmet";
3592 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT
:
3593 desc_scsi_status
= "reservation conflict";
3595 case MPI2_SCSI_STATUS_COMMAND_TERMINATED
:
3596 desc_scsi_status
= "command terminated";
3598 case MPI2_SCSI_STATUS_TASK_SET_FULL
:
3599 desc_scsi_status
= "task set full";
3601 case MPI2_SCSI_STATUS_ACA_ACTIVE
:
3602 desc_scsi_status
= "aca active";
3604 case MPI2_SCSI_STATUS_TASK_ABORTED
:
3605 desc_scsi_status
= "task aborted";
3608 desc_scsi_status
= "unknown";
3612 desc_scsi_state
[0] = '\0';
3614 desc_scsi_state
= " ";
3615 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
3616 strcat(desc_scsi_state
, "response info ");
3617 if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
3618 strcat(desc_scsi_state
, "state terminated ");
3619 if (scsi_state
& MPI2_SCSI_STATE_NO_SCSI_STATUS
)
3620 strcat(desc_scsi_state
, "no status ");
3621 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_FAILED
)
3622 strcat(desc_scsi_state
, "autosense failed ");
3623 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
)
3624 strcat(desc_scsi_state
, "autosense valid ");
3626 scsi_print_command(scmd
);
3628 if (priv_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
3629 printk(MPT2SAS_WARN_FMT
"\tvolume wwid(0x%016llx)\n", ioc
->name
,
3630 (unsigned long long)priv_target
->sas_address
);
3632 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
3633 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
3634 priv_target
->sas_address
);
3636 printk(MPT2SAS_WARN_FMT
"\tsas_address(0x%016llx), "
3637 "phy(%d)\n", ioc
->name
, sas_device
->sas_address
,
3639 printk(MPT2SAS_WARN_FMT
3640 "\tenclosure_logical_id(0x%016llx), slot(%d)\n",
3641 ioc
->name
, sas_device
->enclosure_logical_id
,
3644 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3647 printk(MPT2SAS_WARN_FMT
"\thandle(0x%04x), ioc_status(%s)(0x%04x), "
3648 "smid(%d)\n", ioc
->name
, le16_to_cpu(mpi_reply
->DevHandle
),
3649 desc_ioc_state
, ioc_status
, smid
);
3650 printk(MPT2SAS_WARN_FMT
"\trequest_len(%d), underflow(%d), "
3651 "resid(%d)\n", ioc
->name
, scsi_bufflen(scmd
), scmd
->underflow
,
3652 scsi_get_resid(scmd
));
3653 printk(MPT2SAS_WARN_FMT
"\ttag(%d), transfer_count(%d), "
3654 "sc->result(0x%08x)\n", ioc
->name
, le16_to_cpu(mpi_reply
->TaskTag
),
3655 le32_to_cpu(mpi_reply
->TransferCount
), scmd
->result
);
3656 printk(MPT2SAS_WARN_FMT
"\tscsi_status(%s)(0x%02x), "
3657 "scsi_state(%s)(0x%02x)\n", ioc
->name
, desc_scsi_status
,
3658 scsi_status
, desc_scsi_state
, scsi_state
);
3660 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
3661 struct sense_info data
;
3662 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
3663 printk(MPT2SAS_WARN_FMT
"\t[sense_key,asc,ascq]: "
3664 "[0x%02x,0x%02x,0x%02x], count(%d)\n", ioc
->name
, data
.skey
,
3665 data
.asc
, data
.ascq
, le32_to_cpu(mpi_reply
->SenseCount
));
3668 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
) {
3669 response_info
= le32_to_cpu(mpi_reply
->ResponseInfo
);
3670 response_bytes
= (u8
*)&response_info
;
3671 _scsih_response_code(ioc
, response_bytes
[0]);
3677 * _scsih_smart_predicted_fault - illuminate Fault LED
3678 * @ioc: per adapter object
3679 * @handle: device handle
3684 _scsih_smart_predicted_fault(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
3686 Mpi2SepReply_t mpi_reply
;
3687 Mpi2SepRequest_t mpi_request
;
3688 struct scsi_target
*starget
;
3689 struct MPT2SAS_TARGET
*sas_target_priv_data
;
3690 Mpi2EventNotificationReply_t
*event_reply
;
3691 Mpi2EventDataSasDeviceStatusChange_t
*event_data
;
3692 struct _sas_device
*sas_device
;
3694 unsigned long flags
;
3696 /* only handle non-raid devices */
3697 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
3698 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
3700 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3703 starget
= sas_device
->starget
;
3704 sas_target_priv_data
= starget
->hostdata
;
3706 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
) ||
3707 ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
))) {
3708 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3711 starget_printk(KERN_WARNING
, starget
, "predicted fault\n");
3712 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3714 if (ioc
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_IBM
) {
3715 memset(&mpi_request
, 0, sizeof(Mpi2SepRequest_t
));
3716 mpi_request
.Function
= MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR
;
3717 mpi_request
.Action
= MPI2_SEP_REQ_ACTION_WRITE_STATUS
;
3718 mpi_request
.SlotStatus
=
3719 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT
);
3720 mpi_request
.DevHandle
= cpu_to_le16(handle
);
3721 mpi_request
.Flags
= MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS
;
3722 if ((mpt2sas_base_scsi_enclosure_processor(ioc
, &mpi_reply
,
3723 &mpi_request
)) != 0) {
3724 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3725 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3729 if (mpi_reply
.IOCStatus
|| mpi_reply
.IOCLogInfo
) {
3730 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3731 "enclosure_processor: ioc_status (0x%04x), "
3732 "loginfo(0x%08x)\n", ioc
->name
,
3733 le16_to_cpu(mpi_reply
.IOCStatus
),
3734 le32_to_cpu(mpi_reply
.IOCLogInfo
)));
3739 /* insert into event log */
3740 sz
= offsetof(Mpi2EventNotificationReply_t
, EventData
) +
3741 sizeof(Mpi2EventDataSasDeviceStatusChange_t
);
3742 event_reply
= kzalloc(sz
, GFP_KERNEL
);
3744 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3745 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3749 event_reply
->Function
= MPI2_FUNCTION_EVENT_NOTIFICATION
;
3750 event_reply
->Event
=
3751 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
);
3752 event_reply
->MsgLength
= sz
/4;
3753 event_reply
->EventDataLength
=
3754 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t
)/4);
3755 event_data
= (Mpi2EventDataSasDeviceStatusChange_t
*)
3756 event_reply
->EventData
;
3757 event_data
->ReasonCode
= MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
;
3758 event_data
->ASC
= 0x5D;
3759 event_data
->DevHandle
= cpu_to_le16(handle
);
3760 event_data
->SASAddress
= cpu_to_le64(sas_target_priv_data
->sas_address
);
3761 mpt2sas_ctl_add_to_event_log(ioc
, event_reply
);
3766 * _scsih_io_done - scsi request callback
3767 * @ioc: per adapter object
3768 * @smid: system request message index
3769 * @msix_index: MSIX table index supplied by the OS
3770 * @reply: reply message frame(lower 32bit addr)
3772 * Callback handler when using _scsih_qcmd.
3774 * Return 1 meaning mf should be freed from _base_interrupt
3775 * 0 means the mf is freed from this function.
3778 _scsih_io_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
3780 Mpi2SCSIIORequest_t
*mpi_request
;
3781 Mpi2SCSIIOReply_t
*mpi_reply
;
3782 struct scsi_cmnd
*scmd
;
3788 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
3789 u32 response_code
= 0;
3791 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
3792 scmd
= _scsih_scsi_lookup_get(ioc
, smid
);
3796 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3798 if (mpi_reply
== NULL
) {
3799 scmd
->result
= DID_OK
<< 16;
3803 sas_device_priv_data
= scmd
->device
->hostdata
;
3804 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
||
3805 sas_device_priv_data
->sas_target
->deleted
) {
3806 scmd
->result
= DID_NO_CONNECT
<< 16;
3810 /* turning off TLR */
3811 scsi_state
= mpi_reply
->SCSIState
;
3812 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
3814 le32_to_cpu(mpi_reply
->ResponseInfo
) & 0xFF;
3815 if (!sas_device_priv_data
->tlr_snoop_check
) {
3816 sas_device_priv_data
->tlr_snoop_check
++;
3817 if (!_scsih_is_raid(&scmd
->device
->sdev_gendev
) &&
3818 sas_is_tlr_enabled(scmd
->device
) &&
3819 response_code
== MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
) {
3820 sas_disable_tlr(scmd
->device
);
3821 sdev_printk(KERN_INFO
, scmd
->device
, "TLR disabled\n");
3825 xfer_cnt
= le32_to_cpu(mpi_reply
->TransferCount
);
3826 scsi_set_resid(scmd
, scsi_bufflen(scmd
) - xfer_cnt
);
3827 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
);
3828 if (ioc_status
& MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE
)
3829 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
3832 ioc_status
&= MPI2_IOCSTATUS_MASK
;
3833 scsi_status
= mpi_reply
->SCSIStatus
;
3835 if (ioc_status
== MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
&& xfer_cnt
== 0 &&
3836 (scsi_status
== MPI2_SCSI_STATUS_BUSY
||
3837 scsi_status
== MPI2_SCSI_STATUS_RESERVATION_CONFLICT
||
3838 scsi_status
== MPI2_SCSI_STATUS_TASK_SET_FULL
)) {
3839 ioc_status
= MPI2_IOCSTATUS_SUCCESS
;
3842 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
3843 struct sense_info data
;
3844 const void *sense_data
= mpt2sas_base_get_sense_buffer(ioc
,
3846 u32 sz
= min_t(u32
, SCSI_SENSE_BUFFERSIZE
,
3847 le32_to_cpu(mpi_reply
->SenseCount
));
3848 memcpy(scmd
->sense_buffer
, sense_data
, sz
);
3849 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
3850 /* failure prediction threshold exceeded */
3851 if (data
.asc
== 0x5D)
3852 _scsih_smart_predicted_fault(ioc
,
3853 le16_to_cpu(mpi_reply
->DevHandle
));
3856 switch (ioc_status
) {
3857 case MPI2_IOCSTATUS_BUSY
:
3858 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES
:
3859 scmd
->result
= SAM_STAT_BUSY
;
3862 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
3863 scmd
->result
= DID_NO_CONNECT
<< 16;
3866 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
3867 if (sas_device_priv_data
->block
) {
3868 scmd
->result
= DID_TRANSPORT_DISRUPTED
<< 16;
3871 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
3872 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
3873 scmd
->result
= DID_RESET
<< 16;
3876 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
3877 if ((xfer_cnt
== 0) || (scmd
->underflow
> xfer_cnt
))
3878 scmd
->result
= DID_SOFT_ERROR
<< 16;
3880 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
3883 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
3884 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
3886 if ((scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
))
3889 if (xfer_cnt
< scmd
->underflow
) {
3890 if (scsi_status
== SAM_STAT_BUSY
)
3891 scmd
->result
= SAM_STAT_BUSY
;
3893 scmd
->result
= DID_SOFT_ERROR
<< 16;
3894 } else if (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
3895 MPI2_SCSI_STATE_NO_SCSI_STATUS
))
3896 scmd
->result
= DID_SOFT_ERROR
<< 16;
3897 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
3898 scmd
->result
= DID_RESET
<< 16;
3899 else if (!xfer_cnt
&& scmd
->cmnd
[0] == REPORT_LUNS
) {
3900 mpi_reply
->SCSIState
= MPI2_SCSI_STATE_AUTOSENSE_VALID
;
3901 mpi_reply
->SCSIStatus
= SAM_STAT_CHECK_CONDITION
;
3902 scmd
->result
= (DRIVER_SENSE
<< 24) |
3903 SAM_STAT_CHECK_CONDITION
;
3904 scmd
->sense_buffer
[0] = 0x70;
3905 scmd
->sense_buffer
[2] = ILLEGAL_REQUEST
;
3906 scmd
->sense_buffer
[12] = 0x20;
3907 scmd
->sense_buffer
[13] = 0;
3911 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
3912 scsi_set_resid(scmd
, 0);
3913 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
3914 case MPI2_IOCSTATUS_SUCCESS
:
3915 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
3916 if (response_code
==
3917 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
||
3918 (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
3919 MPI2_SCSI_STATE_NO_SCSI_STATUS
)))
3920 scmd
->result
= DID_SOFT_ERROR
<< 16;
3921 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
3922 scmd
->result
= DID_RESET
<< 16;
3925 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
3926 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
3927 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
3928 _scsih_eedp_error_handling(scmd
, ioc_status
);
3930 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
3931 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
3932 case MPI2_IOCSTATUS_INVALID_SGL
:
3933 case MPI2_IOCSTATUS_INTERNAL_ERROR
:
3934 case MPI2_IOCSTATUS_INVALID_FIELD
:
3935 case MPI2_IOCSTATUS_INVALID_STATE
:
3936 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
3937 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
3939 scmd
->result
= DID_SOFT_ERROR
<< 16;
3944 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3945 if (scmd
->result
&& (ioc
->logging_level
& MPT_DEBUG_REPLY
))
3946 _scsih_scsi_ioc_info(ioc
, scmd
, mpi_reply
, smid
);
3950 scsi_dma_unmap(scmd
);
3951 scmd
->scsi_done(scmd
);
3956 * _scsih_sas_host_refresh - refreshing sas host object contents
3957 * @ioc: per adapter object
3960 * During port enable, fw will send topology events for every device. Its
3961 * possible that the handles may change from the previous setting, so this
3962 * code keeping handles updating if changed.
3967 _scsih_sas_host_refresh(struct MPT2SAS_ADAPTER
*ioc
)
3972 Mpi2ConfigReply_t mpi_reply
;
3973 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
3974 u16 attached_handle
;
3977 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
3978 "updating handles for sas_host(0x%016llx)\n",
3979 ioc
->name
, (unsigned long long)ioc
->sas_hba
.sas_address
));
3981 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
3982 * sizeof(Mpi2SasIOUnit0PhyData_t
));
3983 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
3984 if (!sas_iounit_pg0
) {
3985 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3986 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3990 if ((mpt2sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
3991 sas_iounit_pg0
, sz
)) != 0)
3993 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
3994 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
3996 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
3997 link_rate
= sas_iounit_pg0
->PhyData
[i
].NegotiatedLinkRate
>> 4;
3999 ioc
->sas_hba
.handle
= le16_to_cpu(sas_iounit_pg0
->
4000 PhyData
[0].ControllerDevHandle
);
4001 ioc
->sas_hba
.phy
[i
].handle
= ioc
->sas_hba
.handle
;
4002 attached_handle
= le16_to_cpu(sas_iounit_pg0
->PhyData
[i
].
4004 if (attached_handle
&& link_rate
< MPI2_SAS_NEG_LINK_RATE_1_5
)
4005 link_rate
= MPI2_SAS_NEG_LINK_RATE_1_5
;
4006 mpt2sas_transport_update_links(ioc
, ioc
->sas_hba
.sas_address
,
4007 attached_handle
, i
, link_rate
);
4010 kfree(sas_iounit_pg0
);
4014 * _scsih_sas_host_add - create sas host object
4015 * @ioc: per adapter object
4017 * Creating host side data object, stored in ioc->sas_hba
4022 _scsih_sas_host_add(struct MPT2SAS_ADAPTER
*ioc
)
4025 Mpi2ConfigReply_t mpi_reply
;
4026 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
4027 Mpi2SasIOUnitPage1_t
*sas_iounit_pg1
= NULL
;
4028 Mpi2SasPhyPage0_t phy_pg0
;
4029 Mpi2SasDevicePage0_t sas_device_pg0
;
4030 Mpi2SasEnclosurePage0_t enclosure_pg0
;
4033 u16 device_missing_delay
;
4035 mpt2sas_config_get_number_hba_phys(ioc
, &ioc
->sas_hba
.num_phys
);
4036 if (!ioc
->sas_hba
.num_phys
) {
4037 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4038 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4042 /* sas_iounit page 0 */
4043 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
4044 sizeof(Mpi2SasIOUnit0PhyData_t
));
4045 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
4046 if (!sas_iounit_pg0
) {
4047 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4048 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4051 if ((mpt2sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
4052 sas_iounit_pg0
, sz
))) {
4053 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4054 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4057 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4058 MPI2_IOCSTATUS_MASK
;
4059 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4060 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4061 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4065 /* sas_iounit page 1 */
4066 sz
= offsetof(Mpi2SasIOUnitPage1_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
4067 sizeof(Mpi2SasIOUnit1PhyData_t
));
4068 sas_iounit_pg1
= kzalloc(sz
, GFP_KERNEL
);
4069 if (!sas_iounit_pg1
) {
4070 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4071 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4074 if ((mpt2sas_config_get_sas_iounit_pg1(ioc
, &mpi_reply
,
4075 sas_iounit_pg1
, sz
))) {
4076 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4077 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4080 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4081 MPI2_IOCSTATUS_MASK
;
4082 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4083 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4084 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4088 ioc
->io_missing_delay
=
4089 le16_to_cpu(sas_iounit_pg1
->IODeviceMissingDelay
);
4090 device_missing_delay
=
4091 le16_to_cpu(sas_iounit_pg1
->ReportDeviceMissingDelay
);
4092 if (device_missing_delay
& MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16
)
4093 ioc
->device_missing_delay
= (device_missing_delay
&
4094 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
) * 16;
4096 ioc
->device_missing_delay
= device_missing_delay
&
4097 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
;
4099 ioc
->sas_hba
.parent_dev
= &ioc
->shost
->shost_gendev
;
4100 ioc
->sas_hba
.phy
= kcalloc(ioc
->sas_hba
.num_phys
,
4101 sizeof(struct _sas_phy
), GFP_KERNEL
);
4102 if (!ioc
->sas_hba
.phy
) {
4103 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4104 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4107 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
4108 if ((mpt2sas_config_get_phy_pg0(ioc
, &mpi_reply
, &phy_pg0
,
4110 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4111 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4114 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4115 MPI2_IOCSTATUS_MASK
;
4116 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4117 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4118 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4123 ioc
->sas_hba
.handle
= le16_to_cpu(sas_iounit_pg0
->
4124 PhyData
[0].ControllerDevHandle
);
4125 ioc
->sas_hba
.phy
[i
].handle
= ioc
->sas_hba
.handle
;
4126 ioc
->sas_hba
.phy
[i
].phy_id
= i
;
4127 mpt2sas_transport_add_host_phy(ioc
, &ioc
->sas_hba
.phy
[i
],
4128 phy_pg0
, ioc
->sas_hba
.parent_dev
);
4130 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
4131 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, ioc
->sas_hba
.handle
))) {
4132 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4133 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4136 ioc
->sas_hba
.enclosure_handle
=
4137 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
4138 ioc
->sas_hba
.sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
4139 printk(MPT2SAS_INFO_FMT
"host_add: handle(0x%04x), "
4140 "sas_addr(0x%016llx), phys(%d)\n", ioc
->name
, ioc
->sas_hba
.handle
,
4141 (unsigned long long) ioc
->sas_hba
.sas_address
,
4142 ioc
->sas_hba
.num_phys
) ;
4144 if (ioc
->sas_hba
.enclosure_handle
) {
4145 if (!(mpt2sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
4147 MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
4148 ioc
->sas_hba
.enclosure_handle
))) {
4149 ioc
->sas_hba
.enclosure_logical_id
=
4150 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
4155 kfree(sas_iounit_pg1
);
4156 kfree(sas_iounit_pg0
);
4160 * _scsih_expander_add - creating expander object
4161 * @ioc: per adapter object
4162 * @handle: expander handle
4164 * Creating expander object, stored in ioc->sas_expander_list.
4166 * Return 0 for success, else error.
4169 _scsih_expander_add(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
4171 struct _sas_node
*sas_expander
;
4172 Mpi2ConfigReply_t mpi_reply
;
4173 Mpi2ExpanderPage0_t expander_pg0
;
4174 Mpi2ExpanderPage1_t expander_pg1
;
4175 Mpi2SasEnclosurePage0_t enclosure_pg0
;
4178 __le64 sas_address
, sas_address_parent
= 0;
4180 unsigned long flags
;
4181 struct _sas_port
*mpt2sas_port
= NULL
;
4187 if (ioc
->shost_recovery
|| ioc
->pci_error_recovery
)
4190 if ((mpt2sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
4191 MPI2_SAS_EXPAND_PGAD_FORM_HNDL
, handle
))) {
4192 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4193 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4197 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4198 MPI2_IOCSTATUS_MASK
;
4199 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4200 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4201 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4205 /* handle out of order topology events */
4206 parent_handle
= le16_to_cpu(expander_pg0
.ParentDevHandle
);
4207 if (_scsih_get_sas_address(ioc
, parent_handle
, &sas_address_parent
)
4209 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4210 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4213 if (sas_address_parent
!= ioc
->sas_hba
.sas_address
) {
4214 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
4215 sas_expander
= mpt2sas_scsih_expander_find_by_sas_address(ioc
,
4216 sas_address_parent
);
4217 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
4218 if (!sas_expander
) {
4219 rc
= _scsih_expander_add(ioc
, parent_handle
);
4225 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
4226 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
4227 sas_expander
= mpt2sas_scsih_expander_find_by_sas_address(ioc
,
4229 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
4234 sas_expander
= kzalloc(sizeof(struct _sas_node
),
4236 if (!sas_expander
) {
4237 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4238 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4242 sas_expander
->handle
= handle
;
4243 sas_expander
->num_phys
= expander_pg0
.NumPhys
;
4244 sas_expander
->sas_address_parent
= sas_address_parent
;
4245 sas_expander
->sas_address
= sas_address
;
4247 printk(MPT2SAS_INFO_FMT
"expander_add: handle(0x%04x),"
4248 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc
->name
,
4249 handle
, parent_handle
, (unsigned long long)
4250 sas_expander
->sas_address
, sas_expander
->num_phys
);
4252 if (!sas_expander
->num_phys
)
4254 sas_expander
->phy
= kcalloc(sas_expander
->num_phys
,
4255 sizeof(struct _sas_phy
), GFP_KERNEL
);
4256 if (!sas_expander
->phy
) {
4257 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4258 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4263 INIT_LIST_HEAD(&sas_expander
->sas_port_list
);
4264 mpt2sas_port
= mpt2sas_transport_port_add(ioc
, handle
,
4265 sas_address_parent
);
4266 if (!mpt2sas_port
) {
4267 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4268 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4272 sas_expander
->parent_dev
= &mpt2sas_port
->rphy
->dev
;
4274 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++) {
4275 if ((mpt2sas_config_get_expander_pg1(ioc
, &mpi_reply
,
4276 &expander_pg1
, i
, handle
))) {
4277 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4278 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4282 sas_expander
->phy
[i
].handle
= handle
;
4283 sas_expander
->phy
[i
].phy_id
= i
;
4285 if ((mpt2sas_transport_add_expander_phy(ioc
,
4286 &sas_expander
->phy
[i
], expander_pg1
,
4287 sas_expander
->parent_dev
))) {
4288 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4289 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4295 if (sas_expander
->enclosure_handle
) {
4296 if (!(mpt2sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
4297 &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
4298 sas_expander
->enclosure_handle
))) {
4299 sas_expander
->enclosure_logical_id
=
4300 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
4304 _scsih_expander_node_add(ioc
, sas_expander
);
4310 mpt2sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
4311 sas_address_parent
);
4312 kfree(sas_expander
);
4317 * _scsih_done - scsih callback handler.
4318 * @ioc: per adapter object
4319 * @smid: system request message index
4320 * @msix_index: MSIX table index supplied by the OS
4321 * @reply: reply message frame(lower 32bit addr)
4323 * Callback handler when sending internal generated message frames.
4324 * The callback index passed is `ioc->scsih_cb_idx`
4326 * Return 1 meaning mf should be freed from _base_interrupt
4327 * 0 means the mf is freed from this function.
4330 _scsih_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
4332 MPI2DefaultReply_t
*mpi_reply
;
4334 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
4335 if (ioc
->scsih_cmds
.status
== MPT2_CMD_NOT_USED
)
4337 if (ioc
->scsih_cmds
.smid
!= smid
)
4339 ioc
->scsih_cmds
.status
|= MPT2_CMD_COMPLETE
;
4341 memcpy(ioc
->scsih_cmds
.reply
, mpi_reply
,
4342 mpi_reply
->MsgLength
*4);
4343 ioc
->scsih_cmds
.status
|= MPT2_CMD_REPLY_VALID
;
4345 ioc
->scsih_cmds
.status
&= ~MPT2_CMD_PENDING
;
4346 complete(&ioc
->scsih_cmds
.done
);
4351 * mpt2sas_expander_remove - removing expander object
4352 * @ioc: per adapter object
4353 * @sas_address: expander sas_address
4358 mpt2sas_expander_remove(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
)
4360 struct _sas_node
*sas_expander
;
4361 unsigned long flags
;
4363 if (ioc
->shost_recovery
)
4366 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
4367 sas_expander
= mpt2sas_scsih_expander_find_by_sas_address(ioc
,
4369 if (!sas_expander
) {
4370 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
4373 list_del(&sas_expander
->list
);
4374 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
4375 _scsih_expander_node_remove(ioc
, sas_expander
);
4379 * _scsih_check_access_status - check access flags
4380 * @ioc: per adapter object
4381 * @sas_address: sas address
4382 * @handle: sas device handle
4383 * @access_flags: errors returned during discovery of the device
4385 * Return 0 for success, else failure
4388 _scsih_check_access_status(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
,
4389 u16 handle
, u8 access_status
)
4394 switch (access_status
) {
4395 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS
:
4396 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION
:
4399 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED
:
4400 desc
= "sata capability failed";
4402 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT
:
4403 desc
= "sata affiliation conflict";
4405 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE
:
4406 desc
= "route not addressable";
4408 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE
:
4409 desc
= "smp error not addressable";
4411 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED
:
4412 desc
= "device blocked";
4414 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED
:
4415 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN
:
4416 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT
:
4417 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG
:
4418 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION
:
4419 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER
:
4420 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN
:
4421 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN
:
4422 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN
:
4423 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION
:
4424 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE
:
4425 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX
:
4426 desc
= "sata initialization failed";
4436 printk(MPT2SAS_ERR_FMT
"discovery errors(%s): sas_address(0x%016llx), "
4437 "handle(0x%04x)\n", ioc
->name
, desc
,
4438 (unsigned long long)sas_address
, handle
);
4443 _scsih_check_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
4445 Mpi2ConfigReply_t mpi_reply
;
4446 Mpi2SasDevicePage0_t sas_device_pg0
;
4447 struct _sas_device
*sas_device
;
4449 unsigned long flags
;
4451 struct scsi_target
*starget
;
4452 struct MPT2SAS_TARGET
*sas_target_priv_data
;
4455 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
4456 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
)))
4459 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
4460 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
4463 /* check if this is end device */
4464 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
4465 if (!(_scsih_is_end_device(device_info
)))
4468 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4469 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
4470 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
4474 printk(MPT2SAS_ERR_FMT
"device is not present "
4475 "handle(0x%04x), no sas_device!!!\n", ioc
->name
, handle
);
4476 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4480 if (unlikely(sas_device
->handle
!= handle
)) {
4481 starget
= sas_device
->starget
;
4482 sas_target_priv_data
= starget
->hostdata
;
4483 starget_printk(KERN_INFO
, starget
, "handle changed from(0x%04x)"
4484 " to (0x%04x)!!!\n", sas_device
->handle
, handle
);
4485 sas_target_priv_data
->handle
= handle
;
4486 sas_device
->handle
= handle
;
4488 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4490 /* check if device is present */
4491 if (!(le16_to_cpu(sas_device_pg0
.Flags
) &
4492 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT
)) {
4493 printk(MPT2SAS_ERR_FMT
"device is not present "
4494 "handle(0x%04x), flags!!!\n", ioc
->name
, handle
);
4498 /* check if there were any issues with discovery */
4499 if (_scsih_check_access_status(ioc
, sas_address
, handle
,
4500 sas_device_pg0
.AccessStatus
))
4502 _scsih_ublock_io_device(ioc
, handle
);
4507 * _scsih_add_device - creating sas device object
4508 * @ioc: per adapter object
4509 * @handle: sas device handle
4510 * @phy_num: phy number end device attached to
4511 * @is_pd: is this hidden raid component
4513 * Creating end device object, stored in ioc->sas_device_list.
4515 * Returns 0 for success, non-zero for failure.
4518 _scsih_add_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
, u8 phy_num
, u8 is_pd
)
4520 Mpi2ConfigReply_t mpi_reply
;
4521 Mpi2SasDevicePage0_t sas_device_pg0
;
4522 Mpi2SasEnclosurePage0_t enclosure_pg0
;
4523 struct _sas_device
*sas_device
;
4527 unsigned long flags
;
4529 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
4530 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
4531 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4532 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4536 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4537 MPI2_IOCSTATUS_MASK
;
4538 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4539 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4540 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4544 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
4546 /* check if device is present */
4547 if (!(le16_to_cpu(sas_device_pg0
.Flags
) &
4548 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT
)) {
4549 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4550 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4551 printk(MPT2SAS_ERR_FMT
"Flags = 0x%04x\n",
4552 ioc
->name
, le16_to_cpu(sas_device_pg0
.Flags
));
4556 /* check if there were any issues with discovery */
4557 if (_scsih_check_access_status(ioc
, sas_address
, handle
,
4558 sas_device_pg0
.AccessStatus
))
4561 /* check if this is end device */
4562 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
4563 if (!(_scsih_is_end_device(device_info
))) {
4564 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4565 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4570 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4571 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
4573 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4578 sas_device
= kzalloc(sizeof(struct _sas_device
),
4581 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4582 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4586 sas_device
->handle
= handle
;
4587 if (_scsih_get_sas_address(ioc
, le16_to_cpu
4588 (sas_device_pg0
.ParentDevHandle
),
4589 &sas_device
->sas_address_parent
) != 0)
4590 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4591 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4592 sas_device
->enclosure_handle
=
4593 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
4595 le16_to_cpu(sas_device_pg0
.Slot
);
4596 sas_device
->device_info
= device_info
;
4597 sas_device
->sas_address
= sas_address
;
4598 sas_device
->phy
= sas_device_pg0
.PhyNum
;
4600 /* get enclosure_logical_id */
4601 if (sas_device
->enclosure_handle
&& !(mpt2sas_config_get_enclosure_pg0(
4602 ioc
, &mpi_reply
, &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
4603 sas_device
->enclosure_handle
)))
4604 sas_device
->enclosure_logical_id
=
4605 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
4607 /* get device name */
4608 sas_device
->device_name
= le64_to_cpu(sas_device_pg0
.DeviceName
);
4610 if (ioc
->wait_for_port_enable_to_complete
)
4611 _scsih_sas_device_init_add(ioc
, sas_device
);
4613 _scsih_sas_device_add(ioc
, sas_device
);
4619 * _scsih_remove_device - removing sas device object
4620 * @ioc: per adapter object
4621 * @sas_device_delete: the sas_device object
4626 _scsih_remove_device(struct MPT2SAS_ADAPTER
*ioc
,
4627 struct _sas_device
*sas_device
)
4629 struct _sas_device sas_device_backup
;
4630 struct MPT2SAS_TARGET
*sas_target_priv_data
;
4635 memcpy(&sas_device_backup
, sas_device
, sizeof(struct _sas_device
));
4636 _scsih_sas_device_remove(ioc
, sas_device
);
4638 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: enter: "
4639 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
, __func__
,
4640 sas_device_backup
.handle
, (unsigned long long)
4641 sas_device_backup
.sas_address
));
4643 if (sas_device_backup
.starget
&& sas_device_backup
.starget
->hostdata
) {
4644 sas_target_priv_data
= sas_device_backup
.starget
->hostdata
;
4645 sas_target_priv_data
->deleted
= 1;
4648 _scsih_ublock_io_device(ioc
, sas_device_backup
.handle
);
4650 mpt2sas_transport_port_remove(ioc
, sas_device_backup
.sas_address
,
4651 sas_device_backup
.sas_address_parent
);
4653 printk(MPT2SAS_INFO_FMT
"removing handle(0x%04x), sas_addr"
4654 "(0x%016llx)\n", ioc
->name
, sas_device_backup
.handle
,
4655 (unsigned long long) sas_device_backup
.sas_address
);
4657 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: exit: "
4658 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
, __func__
,
4659 sas_device_backup
.handle
, (unsigned long long)
4660 sas_device_backup
.sas_address
));
4664 * mpt2sas_device_remove - removing device object
4665 * @ioc: per adapter object
4666 * @sas_address: expander sas_address
4671 mpt2sas_device_remove(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
)
4673 struct _sas_device
*sas_device
;
4674 unsigned long flags
;
4676 if (ioc
->shost_recovery
)
4679 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4680 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
4683 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4686 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4687 _scsih_remove_device(ioc
, sas_device
);
4690 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4692 * _scsih_sas_topology_change_event_debug - debug for topology event
4693 * @ioc: per adapter object
4694 * @event_data: event data payload
4698 _scsih_sas_topology_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
4699 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
4705 char *status_str
= NULL
;
4706 u8 link_rate
, prev_link_rate
;
4708 switch (event_data
->ExpStatus
) {
4709 case MPI2_EVENT_SAS_TOPO_ES_ADDED
:
4712 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
:
4713 status_str
= "remove";
4715 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING
:
4717 status_str
= "responding";
4719 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
:
4720 status_str
= "remove delay";
4723 status_str
= "unknown status";
4726 printk(MPT2SAS_INFO_FMT
"sas topology change: (%s)\n",
4727 ioc
->name
, status_str
);
4728 printk(KERN_INFO
"\thandle(0x%04x), enclosure_handle(0x%04x) "
4729 "start_phy(%02d), count(%d)\n",
4730 le16_to_cpu(event_data
->ExpanderDevHandle
),
4731 le16_to_cpu(event_data
->EnclosureHandle
),
4732 event_data
->StartPhyNum
, event_data
->NumEntries
);
4733 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
4734 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
4737 phy_number
= event_data
->StartPhyNum
+ i
;
4738 reason_code
= event_data
->PHY
[i
].PhyStatus
&
4739 MPI2_EVENT_SAS_TOPO_RC_MASK
;
4740 switch (reason_code
) {
4741 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
4742 status_str
= "target add";
4744 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
4745 status_str
= "target remove";
4747 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
:
4748 status_str
= "delay target remove";
4750 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
4751 status_str
= "link rate change";
4753 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE
:
4754 status_str
= "target responding";
4757 status_str
= "unknown";
4760 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
4761 prev_link_rate
= event_data
->PHY
[i
].LinkRate
& 0xF;
4762 printk(KERN_INFO
"\tphy(%02d), attached_handle(0x%04x): %s:"
4763 " link rate: new(0x%02x), old(0x%02x)\n", phy_number
,
4764 handle
, status_str
, link_rate
, prev_link_rate
);
4771 * _scsih_sas_topology_change_event - handle topology changes
4772 * @ioc: per adapter object
4773 * @fw_event: The fw_event_work object
4778 _scsih_sas_topology_change_event(struct MPT2SAS_ADAPTER
*ioc
,
4779 struct fw_event_work
*fw_event
)
4782 u16 parent_handle
, handle
;
4785 struct _sas_node
*sas_expander
;
4786 struct _sas_device
*sas_device
;
4788 unsigned long flags
;
4789 u8 link_rate
, prev_link_rate
;
4790 Mpi2EventDataSasTopologyChangeList_t
*event_data
= fw_event
->event_data
;
4792 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4793 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
4794 _scsih_sas_topology_change_event_debug(ioc
, event_data
);
4797 if (ioc
->shost_recovery
|| ioc
->remove_host
|| ioc
->pci_error_recovery
)
4800 if (!ioc
->sas_hba
.num_phys
)
4801 _scsih_sas_host_add(ioc
);
4803 _scsih_sas_host_refresh(ioc
);
4805 if (fw_event
->ignore
) {
4806 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"ignoring expander "
4807 "event\n", ioc
->name
));
4811 parent_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
4813 /* handle expander add */
4814 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_ADDED
)
4815 if (_scsih_expander_add(ioc
, parent_handle
) != 0)
4818 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
4819 sas_expander
= mpt2sas_scsih_expander_find_by_handle(ioc
,
4821 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
4823 sas_address
= sas_expander
->sas_address
;
4824 else if (parent_handle
< ioc
->sas_hba
.num_phys
)
4825 sas_address
= ioc
->sas_hba
.sas_address
;
4829 /* handle siblings events */
4830 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
4831 if (fw_event
->ignore
) {
4832 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"ignoring "
4833 "expander event\n", ioc
->name
));
4836 if (ioc
->shost_recovery
|| ioc
->remove_host
||
4837 ioc
->pci_error_recovery
)
4839 phy_number
= event_data
->StartPhyNum
+ i
;
4840 reason_code
= event_data
->PHY
[i
].PhyStatus
&
4841 MPI2_EVENT_SAS_TOPO_RC_MASK
;
4842 if ((event_data
->PHY
[i
].PhyStatus
&
4843 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT
) && (reason_code
!=
4844 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
))
4846 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
4849 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
4850 prev_link_rate
= event_data
->PHY
[i
].LinkRate
& 0xF;
4851 switch (reason_code
) {
4852 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
4854 if (link_rate
== prev_link_rate
)
4857 mpt2sas_transport_update_links(ioc
, sas_address
,
4858 handle
, phy_number
, link_rate
);
4860 if (link_rate
< MPI2_SAS_NEG_LINK_RATE_1_5
)
4863 _scsih_check_device(ioc
, handle
);
4865 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
4867 mpt2sas_transport_update_links(ioc
, sas_address
,
4868 handle
, phy_number
, link_rate
);
4870 _scsih_add_device(ioc
, handle
, phy_number
, 0);
4872 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
4874 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4875 sas_device
= _scsih_sas_device_find_by_handle(ioc
,
4878 spin_unlock_irqrestore(&ioc
->sas_device_lock
,
4882 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4883 _scsih_remove_device(ioc
, sas_device
);
4888 /* handle expander removal */
4889 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
&&
4891 mpt2sas_expander_remove(ioc
, sas_address
);
4895 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4897 * _scsih_sas_device_status_change_event_debug - debug for device event
4898 * @event_data: event data payload
4904 _scsih_sas_device_status_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
4905 Mpi2EventDataSasDeviceStatusChange_t
*event_data
)
4907 char *reason_str
= NULL
;
4909 switch (event_data
->ReasonCode
) {
4910 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
:
4911 reason_str
= "smart data";
4913 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED
:
4914 reason_str
= "unsupported device discovered";
4916 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
:
4917 reason_str
= "internal device reset";
4919 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL
:
4920 reason_str
= "internal task abort";
4922 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL
:
4923 reason_str
= "internal task abort set";
4925 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL
:
4926 reason_str
= "internal clear task set";
4928 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL
:
4929 reason_str
= "internal query task";
4931 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE
:
4932 reason_str
= "sata init failure";
4934 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
:
4935 reason_str
= "internal device reset complete";
4937 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL
:
4938 reason_str
= "internal task abort complete";
4940 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION
:
4941 reason_str
= "internal async notification";
4943 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY
:
4944 reason_str
= "expander reduced functionality";
4946 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY
:
4947 reason_str
= "expander reduced functionality complete";
4950 reason_str
= "unknown reason";
4953 printk(MPT2SAS_INFO_FMT
"device status change: (%s)\n"
4954 "\thandle(0x%04x), sas address(0x%016llx)", ioc
->name
,
4955 reason_str
, le16_to_cpu(event_data
->DevHandle
),
4956 (unsigned long long)le64_to_cpu(event_data
->SASAddress
));
4957 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
)
4958 printk(MPT2SAS_INFO_FMT
", ASC(0x%x), ASCQ(0x%x)\n", ioc
->name
,
4959 event_data
->ASC
, event_data
->ASCQ
);
4960 printk(KERN_INFO
"\n");
4965 * _scsih_sas_device_status_change_event - handle device status change
4966 * @ioc: per adapter object
4967 * @fw_event: The fw_event_work object
4973 _scsih_sas_device_status_change_event(struct MPT2SAS_ADAPTER
*ioc
,
4974 struct fw_event_work
*fw_event
)
4976 struct MPT2SAS_TARGET
*target_priv_data
;
4977 struct _sas_device
*sas_device
;
4979 unsigned long flags
;
4980 Mpi2EventDataSasDeviceStatusChange_t
*event_data
=
4981 fw_event
->event_data
;
4983 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4984 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
4985 _scsih_sas_device_status_change_event_debug(ioc
,
4989 if (event_data
->ReasonCode
!=
4990 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
&&
4991 event_data
->ReasonCode
!=
4992 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
)
4995 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4996 sas_address
= le64_to_cpu(event_data
->SASAddress
);
4997 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
4999 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5001 if (!sas_device
|| !sas_device
->starget
)
5004 target_priv_data
= sas_device
->starget
->hostdata
;
5005 if (!target_priv_data
)
5008 if (event_data
->ReasonCode
==
5009 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
)
5010 target_priv_data
->tm_busy
= 1;
5012 target_priv_data
->tm_busy
= 0;
5015 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5017 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure event
5018 * @ioc: per adapter object
5019 * @event_data: event data payload
5025 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
5026 Mpi2EventDataSasEnclDevStatusChange_t
*event_data
)
5028 char *reason_str
= NULL
;
5030 switch (event_data
->ReasonCode
) {
5031 case MPI2_EVENT_SAS_ENCL_RC_ADDED
:
5032 reason_str
= "enclosure add";
5034 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING
:
5035 reason_str
= "enclosure remove";
5038 reason_str
= "unknown reason";
5042 printk(MPT2SAS_INFO_FMT
"enclosure status change: (%s)\n"
5043 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
5044 " number slots(%d)\n", ioc
->name
, reason_str
,
5045 le16_to_cpu(event_data
->EnclosureHandle
),
5046 (unsigned long long)le64_to_cpu(event_data
->EnclosureLogicalID
),
5047 le16_to_cpu(event_data
->StartSlot
));
5052 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
5053 * @ioc: per adapter object
5054 * @fw_event: The fw_event_work object
5060 _scsih_sas_enclosure_dev_status_change_event(struct MPT2SAS_ADAPTER
*ioc
,
5061 struct fw_event_work
*fw_event
)
5063 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5064 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5065 _scsih_sas_enclosure_dev_status_change_event_debug(ioc
,
5066 fw_event
->event_data
);
5071 * _scsih_sas_broadcast_primative_event - handle broadcast events
5072 * @ioc: per adapter object
5073 * @fw_event: The fw_event_work object
5079 _scsih_sas_broadcast_primative_event(struct MPT2SAS_ADAPTER
*ioc
,
5080 struct fw_event_work
*fw_event
)
5082 struct scsi_cmnd
*scmd
;
5085 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
5086 u32 termination_count
;
5088 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
5089 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5090 Mpi2EventDataSasBroadcastPrimitive_t
*event_data
= fw_event
->event_data
;
5093 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"broadcast primative: "
5094 "phy number(%d), width(%d)\n", ioc
->name
, event_data
->PhyNum
,
5095 event_data
->PortWidth
));
5096 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: enter\n", ioc
->name
,
5099 termination_count
= 0;
5101 mpi_reply
= ioc
->tm_cmds
.reply
;
5102 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
5103 scmd
= _scsih_scsi_lookup_get(ioc
, smid
);
5106 sas_device_priv_data
= scmd
->device
->hostdata
;
5107 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
)
5109 /* skip hidden raid components */
5110 if (sas_device_priv_data
->sas_target
->flags
&
5111 MPT_TARGET_FLAGS_RAID_COMPONENT
)
5114 if (sas_device_priv_data
->sas_target
->flags
&
5115 MPT_TARGET_FLAGS_VOLUME
)
5118 handle
= sas_device_priv_data
->sas_target
->handle
;
5119 lun
= sas_device_priv_data
->lun
;
5122 mpt2sas_scsih_issue_tm(ioc
, handle
, 0, 0, lun
,
5123 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK
, smid
, 30, NULL
);
5124 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
5125 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
)
5126 & MPI2_IOCSTATUS_MASK
;
5127 if ((ioc_status
== MPI2_IOCSTATUS_SUCCESS
) &&
5128 (mpi_reply
->ResponseCode
==
5129 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
||
5130 mpi_reply
->ResponseCode
==
5131 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
))
5134 mpt2sas_scsih_issue_tm(ioc
, handle
, 0, 0, lun
,
5135 MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET
, 0, 30, NULL
);
5136 termination_count
+= le32_to_cpu(mpi_reply
->TerminationCount
);
5138 ioc
->broadcast_aen_busy
= 0;
5140 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
5141 "%s - exit, query_count = %d termination_count = %d\n",
5142 ioc
->name
, __func__
, query_count
, termination_count
));
5146 * _scsih_sas_discovery_event - handle discovery events
5147 * @ioc: per adapter object
5148 * @fw_event: The fw_event_work object
5154 _scsih_sas_discovery_event(struct MPT2SAS_ADAPTER
*ioc
,
5155 struct fw_event_work
*fw_event
)
5157 Mpi2EventDataSasDiscovery_t
*event_data
= fw_event
->event_data
;
5159 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5160 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
) {
5161 printk(MPT2SAS_INFO_FMT
"discovery event: (%s)", ioc
->name
,
5162 (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
) ?
5164 if (event_data
->DiscoveryStatus
)
5165 printk("discovery_status(0x%08x)",
5166 le32_to_cpu(event_data
->DiscoveryStatus
));
5171 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
&&
5172 !ioc
->sas_hba
.num_phys
)
5173 _scsih_sas_host_add(ioc
);
5177 * _scsih_reprobe_lun - reprobing lun
5178 * @sdev: scsi device struct
5179 * @no_uld_attach: sdev->no_uld_attach flag setting
5183 _scsih_reprobe_lun(struct scsi_device
*sdev
, void *no_uld_attach
)
5187 sdev
->no_uld_attach
= no_uld_attach
? 1 : 0;
5188 sdev_printk(KERN_INFO
, sdev
, "%s raid component\n",
5189 sdev
->no_uld_attach
? "hidding" : "exposing");
5190 rc
= scsi_device_reprobe(sdev
);
5194 * _scsih_reprobe_target - reprobing target
5195 * @starget: scsi target struct
5196 * @no_uld_attach: sdev->no_uld_attach flag setting
5198 * Note: no_uld_attach flag determines whether the disk device is attached
5199 * to block layer. A value of `1` means to not attach.
5202 _scsih_reprobe_target(struct scsi_target
*starget
, int no_uld_attach
)
5204 struct MPT2SAS_TARGET
*sas_target_priv_data
= starget
->hostdata
;
5207 sas_target_priv_data
->flags
|= MPT_TARGET_FLAGS_RAID_COMPONENT
;
5209 sas_target_priv_data
->flags
&= ~MPT_TARGET_FLAGS_RAID_COMPONENT
;
5211 starget_for_each_device(starget
, no_uld_attach
? (void *)1 : NULL
,
5212 _scsih_reprobe_lun
);
5215 * _scsih_sas_volume_add - add new volume
5216 * @ioc: per adapter object
5217 * @element: IR config element data
5223 _scsih_sas_volume_add(struct MPT2SAS_ADAPTER
*ioc
,
5224 Mpi2EventIrConfigElement_t
*element
)
5226 struct _raid_device
*raid_device
;
5227 unsigned long flags
;
5229 u16 handle
= le16_to_cpu(element
->VolDevHandle
);
5232 mpt2sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
5234 printk(MPT2SAS_ERR_FMT
5235 "failure at %s:%d/%s()!\n", ioc
->name
,
5236 __FILE__
, __LINE__
, __func__
);
5240 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5241 raid_device
= _scsih_raid_device_find_by_wwid(ioc
, wwid
);
5242 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5247 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
5249 printk(MPT2SAS_ERR_FMT
5250 "failure at %s:%d/%s()!\n", ioc
->name
,
5251 __FILE__
, __LINE__
, __func__
);
5255 raid_device
->id
= ioc
->sas_id
++;
5256 raid_device
->channel
= RAID_CHANNEL
;
5257 raid_device
->handle
= handle
;
5258 raid_device
->wwid
= wwid
;
5259 _scsih_raid_device_add(ioc
, raid_device
);
5260 if (!ioc
->wait_for_port_enable_to_complete
) {
5261 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
5262 raid_device
->id
, 0);
5264 _scsih_raid_device_remove(ioc
, raid_device
);
5266 _scsih_determine_boot_device(ioc
, raid_device
, 1);
5270 * _scsih_sas_volume_delete - delete volume
5271 * @ioc: per adapter object
5272 * @handle: volume device handle
5278 _scsih_sas_volume_delete(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
5280 struct _raid_device
*raid_device
;
5281 unsigned long flags
;
5282 struct MPT2SAS_TARGET
*sas_target_priv_data
;
5284 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5285 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
5286 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5289 if (raid_device
->starget
) {
5290 sas_target_priv_data
= raid_device
->starget
->hostdata
;
5291 sas_target_priv_data
->deleted
= 1;
5292 scsi_remove_target(&raid_device
->starget
->dev
);
5294 printk(MPT2SAS_INFO_FMT
"removing handle(0x%04x), wwid"
5295 "(0x%016llx)\n", ioc
->name
, raid_device
->handle
,
5296 (unsigned long long) raid_device
->wwid
);
5297 _scsih_raid_device_remove(ioc
, raid_device
);
5301 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
5302 * @ioc: per adapter object
5303 * @element: IR config element data
5309 _scsih_sas_pd_expose(struct MPT2SAS_ADAPTER
*ioc
,
5310 Mpi2EventIrConfigElement_t
*element
)
5312 struct _sas_device
*sas_device
;
5313 unsigned long flags
;
5314 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
5316 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5317 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
5318 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5322 /* exposing raid component */
5323 sas_device
->volume_handle
= 0;
5324 sas_device
->volume_wwid
= 0;
5325 clear_bit(handle
, ioc
->pd_handles
);
5326 _scsih_reprobe_target(sas_device
->starget
, 0);
5330 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
5331 * @ioc: per adapter object
5332 * @element: IR config element data
5338 _scsih_sas_pd_hide(struct MPT2SAS_ADAPTER
*ioc
,
5339 Mpi2EventIrConfigElement_t
*element
)
5341 struct _sas_device
*sas_device
;
5342 unsigned long flags
;
5343 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
5345 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5346 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
5347 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5351 /* hiding raid component */
5352 mpt2sas_config_get_volume_handle(ioc
, handle
,
5353 &sas_device
->volume_handle
);
5354 mpt2sas_config_get_volume_wwid(ioc
, sas_device
->volume_handle
,
5355 &sas_device
->volume_wwid
);
5356 set_bit(handle
, ioc
->pd_handles
);
5357 _scsih_reprobe_target(sas_device
->starget
, 1);
5361 * _scsih_sas_pd_delete - delete pd component
5362 * @ioc: per adapter object
5363 * @element: IR config element data
5369 _scsih_sas_pd_delete(struct MPT2SAS_ADAPTER
*ioc
,
5370 Mpi2EventIrConfigElement_t
*element
)
5372 struct _sas_device
*sas_device
;
5373 unsigned long flags
;
5374 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
5376 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5377 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
5378 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5381 _scsih_remove_device(ioc
, sas_device
);
5385 * _scsih_sas_pd_add - remove pd component
5386 * @ioc: per adapter object
5387 * @element: IR config element data
5393 _scsih_sas_pd_add(struct MPT2SAS_ADAPTER
*ioc
,
5394 Mpi2EventIrConfigElement_t
*element
)
5396 struct _sas_device
*sas_device
;
5397 unsigned long flags
;
5398 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
5399 Mpi2ConfigReply_t mpi_reply
;
5400 Mpi2SasDevicePage0_t sas_device_pg0
;
5405 set_bit(handle
, ioc
->pd_handles
);
5407 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5408 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
5409 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5413 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
5414 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
5415 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5416 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5420 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5421 MPI2_IOCSTATUS_MASK
;
5422 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5423 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5424 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5428 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
5429 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
5430 mpt2sas_transport_update_links(ioc
, sas_address
, handle
,
5431 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
5433 _scsih_add_device(ioc
, handle
, 0, 1);
5436 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5438 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
5439 * @ioc: per adapter object
5440 * @event_data: event data payload
5446 _scsih_sas_ir_config_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
5447 Mpi2EventDataIrConfigChangeList_t
*event_data
)
5449 Mpi2EventIrConfigElement_t
*element
;
5452 char *reason_str
= NULL
, *element_str
= NULL
;
5454 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
5456 printk(MPT2SAS_INFO_FMT
"raid config change: (%s), elements(%d)\n",
5457 ioc
->name
, (le32_to_cpu(event_data
->Flags
) &
5458 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ?
5459 "foreign" : "native", event_data
->NumElements
);
5460 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
5461 switch (element
->ReasonCode
) {
5462 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
5465 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
5466 reason_str
= "remove";
5468 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE
:
5469 reason_str
= "no change";
5471 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
5472 reason_str
= "hide";
5474 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
5475 reason_str
= "unhide";
5477 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
5478 reason_str
= "volume_created";
5480 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
5481 reason_str
= "volume_deleted";
5483 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
5484 reason_str
= "pd_created";
5486 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
5487 reason_str
= "pd_deleted";
5490 reason_str
= "unknown reason";
5493 element_type
= le16_to_cpu(element
->ElementFlags
) &
5494 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK
;
5495 switch (element_type
) {
5496 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT
:
5497 element_str
= "volume";
5499 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT
:
5500 element_str
= "phys disk";
5502 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT
:
5503 element_str
= "hot spare";
5506 element_str
= "unknown element";
5509 printk(KERN_INFO
"\t(%s:%s), vol handle(0x%04x), "
5510 "pd handle(0x%04x), pd num(0x%02x)\n", element_str
,
5511 reason_str
, le16_to_cpu(element
->VolDevHandle
),
5512 le16_to_cpu(element
->PhysDiskDevHandle
),
5513 element
->PhysDiskNum
);
5519 * _scsih_sas_ir_config_change_event - handle ir configuration change events
5520 * @ioc: per adapter object
5521 * @fw_event: The fw_event_work object
5527 _scsih_sas_ir_config_change_event(struct MPT2SAS_ADAPTER
*ioc
,
5528 struct fw_event_work
*fw_event
)
5530 Mpi2EventIrConfigElement_t
*element
;
5533 Mpi2EventDataIrConfigChangeList_t
*event_data
= fw_event
->event_data
;
5535 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5536 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5537 _scsih_sas_ir_config_change_event_debug(ioc
, event_data
);
5540 foreign_config
= (le32_to_cpu(event_data
->Flags
) &
5541 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ? 1 : 0;
5543 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
5544 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
5546 switch (element
->ReasonCode
) {
5547 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
5548 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
5549 if (!foreign_config
)
5550 _scsih_sas_volume_add(ioc
, element
);
5552 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
5553 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
5554 if (!foreign_config
)
5555 _scsih_sas_volume_delete(ioc
,
5556 le16_to_cpu(element
->VolDevHandle
));
5558 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
5559 _scsih_sas_pd_hide(ioc
, element
);
5561 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
5562 _scsih_sas_pd_expose(ioc
, element
);
5564 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
5565 _scsih_sas_pd_add(ioc
, element
);
5567 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
5568 _scsih_sas_pd_delete(ioc
, element
);
5575 * _scsih_sas_ir_volume_event - IR volume event
5576 * @ioc: per adapter object
5577 * @fw_event: The fw_event_work object
5583 _scsih_sas_ir_volume_event(struct MPT2SAS_ADAPTER
*ioc
,
5584 struct fw_event_work
*fw_event
)
5587 unsigned long flags
;
5588 struct _raid_device
*raid_device
;
5592 Mpi2EventDataIrVolume_t
*event_data
= fw_event
->event_data
;
5594 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED
)
5597 handle
= le16_to_cpu(event_data
->VolDevHandle
);
5598 state
= le32_to_cpu(event_data
->NewValue
);
5599 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: handle(0x%04x), "
5600 "old(0x%08x), new(0x%08x)\n", ioc
->name
, __func__
, handle
,
5601 le32_to_cpu(event_data
->PreviousValue
), state
));
5604 case MPI2_RAID_VOL_STATE_MISSING
:
5605 case MPI2_RAID_VOL_STATE_FAILED
:
5606 _scsih_sas_volume_delete(ioc
, handle
);
5609 case MPI2_RAID_VOL_STATE_ONLINE
:
5610 case MPI2_RAID_VOL_STATE_DEGRADED
:
5611 case MPI2_RAID_VOL_STATE_OPTIMAL
:
5613 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5614 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
5615 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5620 mpt2sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
5622 printk(MPT2SAS_ERR_FMT
5623 "failure at %s:%d/%s()!\n", ioc
->name
,
5624 __FILE__
, __LINE__
, __func__
);
5628 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
5630 printk(MPT2SAS_ERR_FMT
5631 "failure at %s:%d/%s()!\n", ioc
->name
,
5632 __FILE__
, __LINE__
, __func__
);
5636 raid_device
->id
= ioc
->sas_id
++;
5637 raid_device
->channel
= RAID_CHANNEL
;
5638 raid_device
->handle
= handle
;
5639 raid_device
->wwid
= wwid
;
5640 _scsih_raid_device_add(ioc
, raid_device
);
5641 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
5642 raid_device
->id
, 0);
5644 _scsih_raid_device_remove(ioc
, raid_device
);
5647 case MPI2_RAID_VOL_STATE_INITIALIZING
:
5654 * _scsih_sas_ir_physical_disk_event - PD event
5655 * @ioc: per adapter object
5656 * @fw_event: The fw_event_work object
5662 _scsih_sas_ir_physical_disk_event(struct MPT2SAS_ADAPTER
*ioc
,
5663 struct fw_event_work
*fw_event
)
5665 u16 handle
, parent_handle
;
5667 struct _sas_device
*sas_device
;
5668 unsigned long flags
;
5669 Mpi2ConfigReply_t mpi_reply
;
5670 Mpi2SasDevicePage0_t sas_device_pg0
;
5672 Mpi2EventDataIrPhysicalDisk_t
*event_data
= fw_event
->event_data
;
5675 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED
)
5678 handle
= le16_to_cpu(event_data
->PhysDiskDevHandle
);
5679 state
= le32_to_cpu(event_data
->NewValue
);
5681 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: handle(0x%04x), "
5682 "old(0x%08x), new(0x%08x)\n", ioc
->name
, __func__
, handle
,
5683 le32_to_cpu(event_data
->PreviousValue
), state
));
5686 case MPI2_RAID_PD_STATE_ONLINE
:
5687 case MPI2_RAID_PD_STATE_DEGRADED
:
5688 case MPI2_RAID_PD_STATE_REBUILDING
:
5689 case MPI2_RAID_PD_STATE_OPTIMAL
:
5690 case MPI2_RAID_PD_STATE_HOT_SPARE
:
5692 set_bit(handle
, ioc
->pd_handles
);
5694 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5695 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
5696 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5701 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
5702 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
5704 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5705 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5709 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5710 MPI2_IOCSTATUS_MASK
;
5711 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5712 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5713 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5717 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
5718 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
5719 mpt2sas_transport_update_links(ioc
, sas_address
, handle
,
5720 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
5722 _scsih_add_device(ioc
, handle
, 0, 1);
5726 case MPI2_RAID_PD_STATE_OFFLINE
:
5727 case MPI2_RAID_PD_STATE_NOT_CONFIGURED
:
5728 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE
:
5734 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5736 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
5737 * @ioc: per adapter object
5738 * @event_data: event data payload
5744 _scsih_sas_ir_operation_status_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
5745 Mpi2EventDataIrOperationStatus_t
*event_data
)
5747 char *reason_str
= NULL
;
5749 switch (event_data
->RAIDOperation
) {
5750 case MPI2_EVENT_IR_RAIDOP_RESYNC
:
5751 reason_str
= "resync";
5753 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION
:
5754 reason_str
= "online capacity expansion";
5756 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK
:
5757 reason_str
= "consistency check";
5759 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT
:
5760 reason_str
= "background init";
5762 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT
:
5763 reason_str
= "make data consistent";
5770 printk(MPT2SAS_INFO_FMT
"raid operational status: (%s)"
5771 "\thandle(0x%04x), percent complete(%d)\n",
5772 ioc
->name
, reason_str
,
5773 le16_to_cpu(event_data
->VolDevHandle
),
5774 event_data
->PercentComplete
);
5779 * _scsih_sas_ir_operation_status_event - handle RAID operation events
5780 * @ioc: per adapter object
5781 * @fw_event: The fw_event_work object
5787 _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER
*ioc
,
5788 struct fw_event_work
*fw_event
)
5790 Mpi2EventDataIrOperationStatus_t
*event_data
= fw_event
->event_data
;
5791 static struct _raid_device
*raid_device
;
5792 unsigned long flags
;
5795 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5796 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5797 _scsih_sas_ir_operation_status_event_debug(ioc
,
5801 /* code added for raid transport support */
5802 if (event_data
->RAIDOperation
== MPI2_EVENT_IR_RAIDOP_RESYNC
) {
5804 handle
= le16_to_cpu(event_data
->VolDevHandle
);
5806 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5807 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
5808 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5813 if (event_data
->RAIDOperation
== MPI2_EVENT_IR_RAIDOP_RESYNC
)
5814 raid_device
->percent_complete
=
5815 event_data
->PercentComplete
;
5820 * _scsih_prep_device_scan - initialize parameters prior to device scan
5821 * @ioc: per adapter object
5823 * Set the deleted flag prior to device scan. If the device is found during
5824 * the scan, then we clear the deleted flag.
5827 _scsih_prep_device_scan(struct MPT2SAS_ADAPTER
*ioc
)
5829 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
5830 struct scsi_device
*sdev
;
5832 shost_for_each_device(sdev
, ioc
->shost
) {
5833 sas_device_priv_data
= sdev
->hostdata
;
5834 if (sas_device_priv_data
&& sas_device_priv_data
->sas_target
)
5835 sas_device_priv_data
->sas_target
->deleted
= 1;
5840 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
5841 * @ioc: per adapter object
5842 * @sas_address: sas address
5843 * @slot: enclosure slot id
5844 * @handle: device handle
5846 * After host reset, find out whether devices are still responding.
5847 * Used in _scsi_remove_unresponsive_sas_devices.
5852 _scsih_mark_responding_sas_device(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
,
5853 u16 slot
, u16 handle
)
5855 struct MPT2SAS_TARGET
*sas_target_priv_data
;
5856 struct scsi_target
*starget
;
5857 struct _sas_device
*sas_device
;
5858 unsigned long flags
;
5860 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5861 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
) {
5862 if (sas_device
->sas_address
== sas_address
&&
5863 sas_device
->slot
== slot
&& sas_device
->starget
) {
5864 sas_device
->responding
= 1;
5865 starget
= sas_device
->starget
;
5866 if (starget
&& starget
->hostdata
) {
5867 sas_target_priv_data
= starget
->hostdata
;
5868 sas_target_priv_data
->tm_busy
= 0;
5869 sas_target_priv_data
->deleted
= 0;
5871 sas_target_priv_data
= NULL
;
5872 starget_printk(KERN_INFO
, sas_device
->starget
,
5873 "handle(0x%04x), sas_addr(0x%016llx), enclosure "
5874 "logical id(0x%016llx), slot(%d)\n", handle
,
5875 (unsigned long long)sas_device
->sas_address
,
5876 (unsigned long long)
5877 sas_device
->enclosure_logical_id
,
5879 if (sas_device
->handle
== handle
)
5881 printk(KERN_INFO
"\thandle changed from(0x%04x)!!!\n",
5882 sas_device
->handle
);
5883 sas_device
->handle
= handle
;
5884 if (sas_target_priv_data
)
5885 sas_target_priv_data
->handle
= handle
;
5890 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5894 * _scsih_search_responding_sas_devices -
5895 * @ioc: per adapter object
5897 * After host reset, find out whether devices are still responding.
5903 _scsih_search_responding_sas_devices(struct MPT2SAS_ADAPTER
*ioc
)
5905 Mpi2SasDevicePage0_t sas_device_pg0
;
5906 Mpi2ConfigReply_t mpi_reply
;
5913 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
, __func__
);
5915 if (list_empty(&ioc
->sas_device_list
))
5919 while (!(mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
5920 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
,
5922 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5923 MPI2_IOCSTATUS_MASK
;
5924 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
5926 handle
= le16_to_cpu(sas_device_pg0
.DevHandle
);
5927 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
5928 if (!(_scsih_is_end_device(device_info
)))
5930 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
5931 slot
= le16_to_cpu(sas_device_pg0
.Slot
);
5932 _scsih_mark_responding_sas_device(ioc
, sas_address
, slot
,
5938 * _scsih_mark_responding_raid_device - mark a raid_device as responding
5939 * @ioc: per adapter object
5940 * @wwid: world wide identifier for raid volume
5941 * @handle: device handle
5943 * After host reset, find out whether devices are still responding.
5944 * Used in _scsi_remove_unresponsive_raid_devices.
5949 _scsih_mark_responding_raid_device(struct MPT2SAS_ADAPTER
*ioc
, u64 wwid
,
5952 struct MPT2SAS_TARGET
*sas_target_priv_data
;
5953 struct scsi_target
*starget
;
5954 struct _raid_device
*raid_device
;
5955 unsigned long flags
;
5957 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5958 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
5959 if (raid_device
->wwid
== wwid
&& raid_device
->starget
) {
5960 starget
= raid_device
->starget
;
5961 if (starget
&& starget
->hostdata
) {
5962 sas_target_priv_data
= starget
->hostdata
;
5963 sas_target_priv_data
->deleted
= 0;
5965 sas_target_priv_data
= NULL
;
5966 raid_device
->responding
= 1;
5967 starget_printk(KERN_INFO
, raid_device
->starget
,
5968 "handle(0x%04x), wwid(0x%016llx)\n", handle
,
5969 (unsigned long long)raid_device
->wwid
);
5970 if (raid_device
->handle
== handle
)
5972 printk(KERN_INFO
"\thandle changed from(0x%04x)!!!\n",
5973 raid_device
->handle
);
5974 raid_device
->handle
= handle
;
5975 if (sas_target_priv_data
)
5976 sas_target_priv_data
->handle
= handle
;
5981 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5985 * _scsih_search_responding_raid_devices -
5986 * @ioc: per adapter object
5988 * After host reset, find out whether devices are still responding.
5994 _scsih_search_responding_raid_devices(struct MPT2SAS_ADAPTER
*ioc
)
5996 Mpi2RaidVolPage1_t volume_pg1
;
5997 Mpi2RaidVolPage0_t volume_pg0
;
5998 Mpi2RaidPhysDiskPage0_t pd_pg0
;
5999 Mpi2ConfigReply_t mpi_reply
;
6004 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
, __func__
);
6006 if (list_empty(&ioc
->raid_device_list
))
6010 while (!(mpt2sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
6011 &volume_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
6012 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6013 MPI2_IOCSTATUS_MASK
;
6014 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
6016 handle
= le16_to_cpu(volume_pg1
.DevHandle
);
6018 if (mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
,
6019 &volume_pg0
, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
6020 sizeof(Mpi2RaidVolPage0_t
)))
6023 if (volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_OPTIMAL
||
6024 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_ONLINE
||
6025 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_DEGRADED
)
6026 _scsih_mark_responding_raid_device(ioc
,
6027 le64_to_cpu(volume_pg1
.WWID
), handle
);
6030 /* refresh the pd_handles */
6031 phys_disk_num
= 0xFF;
6032 memset(ioc
->pd_handles
, 0, ioc
->pd_handles_sz
);
6033 while (!(mpt2sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
6034 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM
,
6036 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6037 MPI2_IOCSTATUS_MASK
;
6038 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
6040 phys_disk_num
= pd_pg0
.PhysDiskNum
;
6041 handle
= le16_to_cpu(pd_pg0
.DevHandle
);
6042 set_bit(handle
, ioc
->pd_handles
);
6047 * _scsih_mark_responding_expander - mark a expander as responding
6048 * @ioc: per adapter object
6049 * @sas_address: sas address
6052 * After host reset, find out whether devices are still responding.
6053 * Used in _scsi_remove_unresponsive_expanders.
6058 _scsih_mark_responding_expander(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
,
6061 struct _sas_node
*sas_expander
;
6062 unsigned long flags
;
6065 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
6066 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
6067 if (sas_expander
->sas_address
!= sas_address
)
6069 sas_expander
->responding
= 1;
6070 if (sas_expander
->handle
== handle
)
6072 printk(KERN_INFO
"\texpander(0x%016llx): handle changed"
6073 " from(0x%04x) to (0x%04x)!!!\n",
6074 (unsigned long long)sas_expander
->sas_address
,
6075 sas_expander
->handle
, handle
);
6076 sas_expander
->handle
= handle
;
6077 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++)
6078 sas_expander
->phy
[i
].handle
= handle
;
6082 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
6086 * _scsih_search_responding_expanders -
6087 * @ioc: per adapter object
6089 * After host reset, find out whether devices are still responding.
6095 _scsih_search_responding_expanders(struct MPT2SAS_ADAPTER
*ioc
)
6097 Mpi2ExpanderPage0_t expander_pg0
;
6098 Mpi2ConfigReply_t mpi_reply
;
6103 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
, __func__
);
6105 if (list_empty(&ioc
->sas_expander_list
))
6109 while (!(mpt2sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
6110 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL
, handle
))) {
6112 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6113 MPI2_IOCSTATUS_MASK
;
6114 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
6117 handle
= le16_to_cpu(expander_pg0
.DevHandle
);
6118 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
6119 printk(KERN_INFO
"\texpander present: handle(0x%04x), "
6120 "sas_addr(0x%016llx)\n", handle
,
6121 (unsigned long long)sas_address
);
6122 _scsih_mark_responding_expander(ioc
, sas_address
, handle
);
6128 * _scsih_remove_unresponding_sas_devices - removing unresponding devices
6129 * @ioc: per adapter object
6134 _scsih_remove_unresponding_sas_devices(struct MPT2SAS_ADAPTER
*ioc
)
6136 struct _sas_device
*sas_device
, *sas_device_next
;
6137 struct _sas_node
*sas_expander
;
6138 struct _raid_device
*raid_device
, *raid_device_next
;
6141 list_for_each_entry_safe(sas_device
, sas_device_next
,
6142 &ioc
->sas_device_list
, list
) {
6143 if (sas_device
->responding
) {
6144 sas_device
->responding
= 0;
6147 if (sas_device
->starget
)
6148 starget_printk(KERN_INFO
, sas_device
->starget
,
6149 "removing: handle(0x%04x), sas_addr(0x%016llx), "
6150 "enclosure logical id(0x%016llx), slot(%d)\n",
6152 (unsigned long long)sas_device
->sas_address
,
6153 (unsigned long long)
6154 sas_device
->enclosure_logical_id
,
6156 _scsih_remove_device(ioc
, sas_device
);
6159 list_for_each_entry_safe(raid_device
, raid_device_next
,
6160 &ioc
->raid_device_list
, list
) {
6161 if (raid_device
->responding
) {
6162 raid_device
->responding
= 0;
6165 if (raid_device
->starget
) {
6166 starget_printk(KERN_INFO
, raid_device
->starget
,
6167 "removing: handle(0x%04x), wwid(0x%016llx)\n",
6168 raid_device
->handle
,
6169 (unsigned long long)raid_device
->wwid
);
6170 scsi_remove_target(&raid_device
->starget
->dev
);
6172 _scsih_raid_device_remove(ioc
, raid_device
);
6175 retry_expander_search
:
6176 sas_expander
= NULL
;
6177 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
6178 if (sas_expander
->responding
) {
6179 sas_expander
->responding
= 0;
6182 mpt2sas_expander_remove(ioc
, sas_expander
->sas_address
);
6183 goto retry_expander_search
;
6188 * mpt2sas_scsih_reset_handler - reset callback handler (for scsih)
6189 * @ioc: per adapter object
6190 * @reset_phase: phase
6192 * The handler for doing any required cleanup or initialization.
6194 * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
6195 * MPT2_IOC_DONE_RESET
6200 mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER
*ioc
, int reset_phase
)
6202 switch (reset_phase
) {
6203 case MPT2_IOC_PRE_RESET
:
6204 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: "
6205 "MPT2_IOC_PRE_RESET\n", ioc
->name
, __func__
));
6207 case MPT2_IOC_AFTER_RESET
:
6208 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: "
6209 "MPT2_IOC_AFTER_RESET\n", ioc
->name
, __func__
));
6210 if (ioc
->scsih_cmds
.status
& MPT2_CMD_PENDING
) {
6211 ioc
->scsih_cmds
.status
|= MPT2_CMD_RESET
;
6212 mpt2sas_base_free_smid(ioc
, ioc
->scsih_cmds
.smid
);
6213 complete(&ioc
->scsih_cmds
.done
);
6215 if (ioc
->tm_cmds
.status
& MPT2_CMD_PENDING
) {
6216 ioc
->tm_cmds
.status
|= MPT2_CMD_RESET
;
6217 mpt2sas_base_free_smid(ioc
, ioc
->tm_cmds
.smid
);
6218 complete(&ioc
->tm_cmds
.done
);
6220 _scsih_fw_event_cleanup_queue(ioc
);
6221 _scsih_flush_running_cmds(ioc
);
6222 _scsih_queue_rescan(ioc
);
6224 case MPT2_IOC_DONE_RESET
:
6225 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: "
6226 "MPT2_IOC_DONE_RESET\n", ioc
->name
, __func__
));
6227 _scsih_sas_host_refresh(ioc
);
6228 _scsih_prep_device_scan(ioc
);
6229 _scsih_search_responding_sas_devices(ioc
);
6230 _scsih_search_responding_raid_devices(ioc
);
6231 _scsih_search_responding_expanders(ioc
);
6237 * _firmware_event_work - delayed task for processing firmware events
6238 * @ioc: per adapter object
6239 * @work: equal to the fw_event_work object
6245 _firmware_event_work(struct work_struct
*work
)
6247 struct fw_event_work
*fw_event
= container_of(work
,
6248 struct fw_event_work
, delayed_work
.work
);
6249 unsigned long flags
;
6250 struct MPT2SAS_ADAPTER
*ioc
= fw_event
->ioc
;
6252 /* the queue is being flushed so ignore this event */
6253 if (ioc
->remove_host
|| fw_event
->cancel_pending_work
||
6254 ioc
->pci_error_recovery
) {
6255 _scsih_fw_event_free(ioc
, fw_event
);
6259 if (fw_event
->event
== MPT2SAS_RESCAN_AFTER_HOST_RESET
) {
6260 _scsih_fw_event_free(ioc
, fw_event
);
6261 spin_lock_irqsave(&ioc
->ioc_reset_in_progress_lock
, flags
);
6262 if (ioc
->shost_recovery
) {
6263 init_completion(&ioc
->shost_recovery_done
);
6264 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
,
6266 wait_for_completion(&ioc
->shost_recovery_done
);
6268 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
,
6270 _scsih_remove_unresponding_sas_devices(ioc
);
6274 switch (fw_event
->event
) {
6275 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
6276 _scsih_sas_topology_change_event(ioc
, fw_event
);
6278 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
6279 _scsih_sas_device_status_change_event(ioc
,
6282 case MPI2_EVENT_SAS_DISCOVERY
:
6283 _scsih_sas_discovery_event(ioc
,
6286 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
6287 _scsih_sas_broadcast_primative_event(ioc
,
6290 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
6291 _scsih_sas_enclosure_dev_status_change_event(ioc
,
6294 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
6295 _scsih_sas_ir_config_change_event(ioc
, fw_event
);
6297 case MPI2_EVENT_IR_VOLUME
:
6298 _scsih_sas_ir_volume_event(ioc
, fw_event
);
6300 case MPI2_EVENT_IR_PHYSICAL_DISK
:
6301 _scsih_sas_ir_physical_disk_event(ioc
, fw_event
);
6303 case MPI2_EVENT_IR_OPERATION_STATUS
:
6304 _scsih_sas_ir_operation_status_event(ioc
, fw_event
);
6307 _scsih_fw_event_free(ioc
, fw_event
);
6311 * mpt2sas_scsih_event_callback - firmware event handler (called at ISR time)
6312 * @ioc: per adapter object
6313 * @msix_index: MSIX table index supplied by the OS
6314 * @reply: reply message frame(lower 32bit addr)
6315 * Context: interrupt.
6317 * This function merely adds a new work task into ioc->firmware_event_thread.
6318 * The tasks are worked from _firmware_event_work in user context.
6320 * Return 1 meaning mf should be freed from _base_interrupt
6321 * 0 means the mf is freed from this function.
6324 mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER
*ioc
, u8 msix_index
,
6327 struct fw_event_work
*fw_event
;
6328 Mpi2EventNotificationReply_t
*mpi_reply
;
6332 /* events turned off due to host reset or driver unloading */
6333 if (ioc
->remove_host
|| ioc
->pci_error_recovery
)
6336 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
6337 event
= le16_to_cpu(mpi_reply
->Event
);
6341 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
6343 Mpi2EventDataSasBroadcastPrimitive_t
*baen_data
=
6344 (Mpi2EventDataSasBroadcastPrimitive_t
*)
6345 mpi_reply
->EventData
;
6347 if (baen_data
->Primitive
!=
6348 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT
||
6349 ioc
->broadcast_aen_busy
)
6351 ioc
->broadcast_aen_busy
= 1;
6355 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
6356 _scsih_check_topo_delete_events(ioc
,
6357 (Mpi2EventDataSasTopologyChangeList_t
*)
6358 mpi_reply
->EventData
);
6360 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
6361 _scsih_check_ir_config_unhide_events(ioc
,
6362 (Mpi2EventDataIrConfigChangeList_t
*)
6363 mpi_reply
->EventData
);
6365 case MPI2_EVENT_IR_VOLUME
:
6366 _scsih_check_volume_delete_events(ioc
,
6367 (Mpi2EventDataIrVolume_t
*)
6368 mpi_reply
->EventData
);
6370 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
6371 case MPI2_EVENT_IR_OPERATION_STATUS
:
6372 case MPI2_EVENT_SAS_DISCOVERY
:
6373 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
6374 case MPI2_EVENT_IR_PHYSICAL_DISK
:
6377 default: /* ignore the rest */
6381 fw_event
= kzalloc(sizeof(struct fw_event_work
), GFP_ATOMIC
);
6383 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6384 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6387 sz
= le16_to_cpu(mpi_reply
->EventDataLength
) * 4;
6388 fw_event
->event_data
= kzalloc(sz
, GFP_ATOMIC
);
6389 if (!fw_event
->event_data
) {
6390 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6391 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6396 memcpy(fw_event
->event_data
, mpi_reply
->EventData
,
6398 fw_event
->ioc
= ioc
;
6399 fw_event
->VF_ID
= mpi_reply
->VF_ID
;
6400 fw_event
->VP_ID
= mpi_reply
->VP_ID
;
6401 fw_event
->event
= event
;
6402 _scsih_fw_event_add(ioc
, fw_event
);
6406 /* shost template */
6407 static struct scsi_host_template scsih_driver_template
= {
6408 .module
= THIS_MODULE
,
6409 .name
= "Fusion MPT SAS Host",
6410 .proc_name
= MPT2SAS_DRIVER_NAME
,
6411 .queuecommand
= _scsih_qcmd
,
6412 .target_alloc
= _scsih_target_alloc
,
6413 .slave_alloc
= _scsih_slave_alloc
,
6414 .slave_configure
= _scsih_slave_configure
,
6415 .target_destroy
= _scsih_target_destroy
,
6416 .slave_destroy
= _scsih_slave_destroy
,
6417 .change_queue_depth
= _scsih_change_queue_depth
,
6418 .change_queue_type
= _scsih_change_queue_type
,
6419 .eh_abort_handler
= _scsih_abort
,
6420 .eh_device_reset_handler
= _scsih_dev_reset
,
6421 .eh_target_reset_handler
= _scsih_target_reset
,
6422 .eh_host_reset_handler
= _scsih_host_reset
,
6423 .bios_param
= _scsih_bios_param
,
6426 .sg_tablesize
= MPT2SAS_SG_DEPTH
,
6427 .max_sectors
= 8192,
6429 .use_clustering
= ENABLE_CLUSTERING
,
6430 .shost_attrs
= mpt2sas_host_attrs
,
6431 .sdev_attrs
= mpt2sas_dev_attrs
,
6435 * _scsih_expander_node_remove - removing expander device from list.
6436 * @ioc: per adapter object
6437 * @sas_expander: the sas_device object
6438 * Context: Calling function should acquire ioc->sas_node_lock.
6440 * Removing object and freeing associated memory from the
6441 * ioc->sas_expander_list.
6446 _scsih_expander_node_remove(struct MPT2SAS_ADAPTER
*ioc
,
6447 struct _sas_node
*sas_expander
)
6449 struct _sas_port
*mpt2sas_port
, *next
;
6451 /* remove sibling ports attached to this expander */
6452 list_for_each_entry_safe(mpt2sas_port
, next
,
6453 &sas_expander
->sas_port_list
, port_list
) {
6454 if (ioc
->shost_recovery
)
6456 if (mpt2sas_port
->remote_identify
.device_type
==
6458 mpt2sas_device_remove(ioc
,
6459 mpt2sas_port
->remote_identify
.sas_address
);
6460 else if (mpt2sas_port
->remote_identify
.device_type
==
6461 SAS_EDGE_EXPANDER_DEVICE
||
6462 mpt2sas_port
->remote_identify
.device_type
==
6463 SAS_FANOUT_EXPANDER_DEVICE
)
6464 mpt2sas_expander_remove(ioc
,
6465 mpt2sas_port
->remote_identify
.sas_address
);
6468 mpt2sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
6469 sas_expander
->sas_address_parent
);
6471 printk(MPT2SAS_INFO_FMT
"expander_remove: handle"
6472 "(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
6473 sas_expander
->handle
, (unsigned long long)
6474 sas_expander
->sas_address
);
6476 kfree(sas_expander
->phy
);
6477 kfree(sas_expander
);
6481 * _scsih_ir_shutdown - IR shutdown notification
6482 * @ioc: per adapter object
6484 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
6485 * the host system is shutting down.
6490 _scsih_ir_shutdown(struct MPT2SAS_ADAPTER
*ioc
)
6492 Mpi2RaidActionRequest_t
*mpi_request
;
6493 Mpi2RaidActionReply_t
*mpi_reply
;
6496 /* is IR firmware build loaded ? */
6497 if (!ioc
->ir_firmware
)
6500 /* are there any volumes ? */
6501 if (list_empty(&ioc
->raid_device_list
))
6504 mutex_lock(&ioc
->scsih_cmds
.mutex
);
6506 if (ioc
->scsih_cmds
.status
!= MPT2_CMD_NOT_USED
) {
6507 printk(MPT2SAS_ERR_FMT
"%s: scsih_cmd in use\n",
6508 ioc
->name
, __func__
);
6511 ioc
->scsih_cmds
.status
= MPT2_CMD_PENDING
;
6513 smid
= mpt2sas_base_get_smid(ioc
, ioc
->scsih_cb_idx
);
6515 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
6516 ioc
->name
, __func__
);
6517 ioc
->scsih_cmds
.status
= MPT2_CMD_NOT_USED
;
6521 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
6522 ioc
->scsih_cmds
.smid
= smid
;
6523 memset(mpi_request
, 0, sizeof(Mpi2RaidActionRequest_t
));
6525 mpi_request
->Function
= MPI2_FUNCTION_RAID_ACTION
;
6526 mpi_request
->Action
= MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED
;
6528 printk(MPT2SAS_INFO_FMT
"IR shutdown (sending)\n", ioc
->name
);
6529 init_completion(&ioc
->scsih_cmds
.done
);
6530 mpt2sas_base_put_smid_default(ioc
, smid
);
6531 wait_for_completion_timeout(&ioc
->scsih_cmds
.done
, 10*HZ
);
6533 if (!(ioc
->scsih_cmds
.status
& MPT2_CMD_COMPLETE
)) {
6534 printk(MPT2SAS_ERR_FMT
"%s: timeout\n",
6535 ioc
->name
, __func__
);
6539 if (ioc
->scsih_cmds
.status
& MPT2_CMD_REPLY_VALID
) {
6540 mpi_reply
= ioc
->scsih_cmds
.reply
;
6542 printk(MPT2SAS_INFO_FMT
"IR shutdown (complete): "
6543 "ioc_status(0x%04x), loginfo(0x%08x)\n",
6544 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
6545 le32_to_cpu(mpi_reply
->IOCLogInfo
));
6549 ioc
->scsih_cmds
.status
= MPT2_CMD_NOT_USED
;
6550 mutex_unlock(&ioc
->scsih_cmds
.mutex
);
6554 * _scsih_shutdown - routine call during system shutdown
6555 * @pdev: PCI device struct
6560 _scsih_shutdown(struct pci_dev
*pdev
)
6562 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6563 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
6564 struct workqueue_struct
*wq
;
6565 unsigned long flags
;
6567 ioc
->remove_host
= 1;
6568 _scsih_fw_event_cleanup_queue(ioc
);
6570 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
6571 wq
= ioc
->firmware_event_thread
;
6572 ioc
->firmware_event_thread
= NULL
;
6573 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
6575 destroy_workqueue(wq
);
6577 _scsih_ir_shutdown(ioc
);
6578 mpt2sas_base_detach(ioc
);
6582 * _scsih_remove - detach and remove add host
6583 * @pdev: PCI device struct
6585 * Routine called when unloading the driver.
6588 static void __devexit
6589 _scsih_remove(struct pci_dev
*pdev
)
6591 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6592 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
6593 struct _sas_port
*mpt2sas_port
, *next_port
;
6594 struct _raid_device
*raid_device
, *next
;
6595 struct MPT2SAS_TARGET
*sas_target_priv_data
;
6596 struct workqueue_struct
*wq
;
6597 unsigned long flags
;
6599 ioc
->remove_host
= 1;
6600 _scsih_fw_event_cleanup_queue(ioc
);
6602 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
6603 wq
= ioc
->firmware_event_thread
;
6604 ioc
->firmware_event_thread
= NULL
;
6605 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
6607 destroy_workqueue(wq
);
6609 /* release all the volumes */
6610 list_for_each_entry_safe(raid_device
, next
, &ioc
->raid_device_list
,
6612 if (raid_device
->starget
) {
6613 sas_target_priv_data
=
6614 raid_device
->starget
->hostdata
;
6615 sas_target_priv_data
->deleted
= 1;
6616 scsi_remove_target(&raid_device
->starget
->dev
);
6618 printk(MPT2SAS_INFO_FMT
"removing handle(0x%04x), wwid"
6619 "(0x%016llx)\n", ioc
->name
, raid_device
->handle
,
6620 (unsigned long long) raid_device
->wwid
);
6621 _scsih_raid_device_remove(ioc
, raid_device
);
6624 /* free ports attached to the sas_host */
6625 list_for_each_entry_safe(mpt2sas_port
, next_port
,
6626 &ioc
->sas_hba
.sas_port_list
, port_list
) {
6627 if (mpt2sas_port
->remote_identify
.device_type
==
6629 mpt2sas_device_remove(ioc
,
6630 mpt2sas_port
->remote_identify
.sas_address
);
6631 else if (mpt2sas_port
->remote_identify
.device_type
==
6632 SAS_EDGE_EXPANDER_DEVICE
||
6633 mpt2sas_port
->remote_identify
.device_type
==
6634 SAS_FANOUT_EXPANDER_DEVICE
)
6635 mpt2sas_expander_remove(ioc
,
6636 mpt2sas_port
->remote_identify
.sas_address
);
6639 /* free phys attached to the sas_host */
6640 if (ioc
->sas_hba
.num_phys
) {
6641 kfree(ioc
->sas_hba
.phy
);
6642 ioc
->sas_hba
.phy
= NULL
;
6643 ioc
->sas_hba
.num_phys
= 0;
6646 sas_remove_host(shost
);
6647 _scsih_shutdown(pdev
);
6648 list_del(&ioc
->list
);
6649 scsi_remove_host(shost
);
6650 scsi_host_put(shost
);
6654 * _scsih_probe_boot_devices - reports 1st device
6655 * @ioc: per adapter object
6657 * If specified in bios page 2, this routine reports the 1st
6658 * device scsi-ml or sas transport for persistent boot device
6659 * purposes. Please refer to function _scsih_determine_boot_device()
6662 _scsih_probe_boot_devices(struct MPT2SAS_ADAPTER
*ioc
)
6666 struct _sas_device
*sas_device
;
6667 struct _raid_device
*raid_device
;
6669 u64 sas_address_parent
;
6671 unsigned long flags
;
6675 if (ioc
->req_boot_device
.device
) {
6676 device
= ioc
->req_boot_device
.device
;
6677 is_raid
= ioc
->req_boot_device
.is_raid
;
6678 } else if (ioc
->req_alt_boot_device
.device
) {
6679 device
= ioc
->req_alt_boot_device
.device
;
6680 is_raid
= ioc
->req_alt_boot_device
.is_raid
;
6681 } else if (ioc
->current_boot_device
.device
) {
6682 device
= ioc
->current_boot_device
.device
;
6683 is_raid
= ioc
->current_boot_device
.is_raid
;
6690 raid_device
= device
;
6691 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
6692 raid_device
->id
, 0);
6694 _scsih_raid_device_remove(ioc
, raid_device
);
6696 sas_device
= device
;
6697 handle
= sas_device
->handle
;
6698 sas_address_parent
= sas_device
->sas_address_parent
;
6699 sas_address
= sas_device
->sas_address
;
6700 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6701 list_move_tail(&sas_device
->list
, &ioc
->sas_device_list
);
6702 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6703 if (!mpt2sas_transport_port_add(ioc
, sas_device
->handle
,
6704 sas_device
->sas_address_parent
)) {
6705 _scsih_sas_device_remove(ioc
, sas_device
);
6706 } else if (!sas_device
->starget
) {
6707 mpt2sas_transport_port_remove(ioc
, sas_address
,
6708 sas_address_parent
);
6709 _scsih_sas_device_remove(ioc
, sas_device
);
6715 * _scsih_probe_raid - reporting raid volumes to scsi-ml
6716 * @ioc: per adapter object
6718 * Called during initial loading of the driver.
6721 _scsih_probe_raid(struct MPT2SAS_ADAPTER
*ioc
)
6723 struct _raid_device
*raid_device
, *raid_next
;
6726 list_for_each_entry_safe(raid_device
, raid_next
,
6727 &ioc
->raid_device_list
, list
) {
6728 if (raid_device
->starget
)
6730 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
6731 raid_device
->id
, 0);
6733 _scsih_raid_device_remove(ioc
, raid_device
);
6738 * _scsih_probe_sas - reporting sas devices to sas transport
6739 * @ioc: per adapter object
6741 * Called during initial loading of the driver.
6744 _scsih_probe_sas(struct MPT2SAS_ADAPTER
*ioc
)
6746 struct _sas_device
*sas_device
, *next
;
6747 unsigned long flags
;
6749 /* SAS Device List */
6750 list_for_each_entry_safe(sas_device
, next
, &ioc
->sas_device_init_list
,
6752 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6753 list_move_tail(&sas_device
->list
, &ioc
->sas_device_list
);
6754 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6756 if (!mpt2sas_transport_port_add(ioc
, sas_device
->handle
,
6757 sas_device
->sas_address_parent
)) {
6758 _scsih_sas_device_remove(ioc
, sas_device
);
6759 } else if (!sas_device
->starget
) {
6760 mpt2sas_transport_port_remove(ioc
,
6761 sas_device
->sas_address
,
6762 sas_device
->sas_address_parent
);
6763 _scsih_sas_device_remove(ioc
, sas_device
);
6769 * _scsih_probe_devices - probing for devices
6770 * @ioc: per adapter object
6772 * Called during initial loading of the driver.
6775 _scsih_probe_devices(struct MPT2SAS_ADAPTER
*ioc
)
6777 u16 volume_mapping_flags
=
6778 le16_to_cpu(ioc
->ioc_pg8
.IRVolumeMappingFlags
) &
6779 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE
;
6781 if (!(ioc
->facts
.ProtocolFlags
& MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR
))
6782 return; /* return when IOC doesn't support initiator mode */
6784 _scsih_probe_boot_devices(ioc
);
6786 if (ioc
->ir_firmware
) {
6787 if ((volume_mapping_flags
&
6788 MPI2_IOCPAGE8_IRFLAGS_HIGH_VOLUME_MAPPING
)) {
6789 _scsih_probe_sas(ioc
);
6790 _scsih_probe_raid(ioc
);
6792 _scsih_probe_raid(ioc
);
6793 _scsih_probe_sas(ioc
);
6796 _scsih_probe_sas(ioc
);
6800 * _scsih_probe - attach and add scsi host
6801 * @pdev: PCI device struct
6802 * @id: pci device id
6804 * Returns 0 success, anything else error.
6807 _scsih_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
6809 struct MPT2SAS_ADAPTER
*ioc
;
6810 struct Scsi_Host
*shost
;
6812 shost
= scsi_host_alloc(&scsih_driver_template
,
6813 sizeof(struct MPT2SAS_ADAPTER
));
6817 /* init local params */
6818 ioc
= shost_priv(shost
);
6819 memset(ioc
, 0, sizeof(struct MPT2SAS_ADAPTER
));
6820 INIT_LIST_HEAD(&ioc
->list
);
6821 list_add_tail(&ioc
->list
, &mpt2sas_ioc_list
);
6823 ioc
->id
= mpt_ids
++;
6824 sprintf(ioc
->name
, "%s%d", MPT2SAS_DRIVER_NAME
, ioc
->id
);
6826 ioc
->scsi_io_cb_idx
= scsi_io_cb_idx
;
6827 ioc
->tm_cb_idx
= tm_cb_idx
;
6828 ioc
->ctl_cb_idx
= ctl_cb_idx
;
6829 ioc
->base_cb_idx
= base_cb_idx
;
6830 ioc
->transport_cb_idx
= transport_cb_idx
;
6831 ioc
->scsih_cb_idx
= scsih_cb_idx
;
6832 ioc
->config_cb_idx
= config_cb_idx
;
6833 ioc
->tm_tr_cb_idx
= tm_tr_cb_idx
;
6834 ioc
->tm_tr_volume_cb_idx
= tm_tr_volume_cb_idx
;
6835 ioc
->tm_sas_control_cb_idx
= tm_sas_control_cb_idx
;
6836 ioc
->logging_level
= logging_level
;
6837 /* misc semaphores and spin locks */
6838 mutex_init(&ioc
->reset_in_progress_mutex
);
6839 spin_lock_init(&ioc
->ioc_reset_in_progress_lock
);
6840 spin_lock_init(&ioc
->scsi_lookup_lock
);
6841 spin_lock_init(&ioc
->sas_device_lock
);
6842 spin_lock_init(&ioc
->sas_node_lock
);
6843 spin_lock_init(&ioc
->fw_event_lock
);
6844 spin_lock_init(&ioc
->raid_device_lock
);
6846 INIT_LIST_HEAD(&ioc
->sas_device_list
);
6847 INIT_LIST_HEAD(&ioc
->sas_device_init_list
);
6848 INIT_LIST_HEAD(&ioc
->sas_expander_list
);
6849 INIT_LIST_HEAD(&ioc
->fw_event_list
);
6850 INIT_LIST_HEAD(&ioc
->raid_device_list
);
6851 INIT_LIST_HEAD(&ioc
->sas_hba
.sas_port_list
);
6852 INIT_LIST_HEAD(&ioc
->delayed_tr_list
);
6853 INIT_LIST_HEAD(&ioc
->delayed_tr_volume_list
);
6855 /* init shost parameters */
6856 shost
->max_cmd_len
= 32;
6857 shost
->max_lun
= max_lun
;
6858 shost
->transportt
= mpt2sas_transport_template
;
6859 shost
->unique_id
= ioc
->id
;
6861 if ((scsi_add_host(shost
, &pdev
->dev
))) {
6862 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6863 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6864 list_del(&ioc
->list
);
6865 goto out_add_shost_fail
;
6868 scsi_host_set_prot(shost
, SHOST_DIF_TYPE1_PROTECTION
6869 | SHOST_DIF_TYPE2_PROTECTION
| SHOST_DIF_TYPE3_PROTECTION
);
6870 scsi_host_set_guard(shost
, SHOST_DIX_GUARD_CRC
);
6873 snprintf(ioc
->firmware_event_name
, sizeof(ioc
->firmware_event_name
),
6874 "fw_event%d", ioc
->id
);
6875 ioc
->firmware_event_thread
= create_singlethread_workqueue(
6876 ioc
->firmware_event_name
);
6877 if (!ioc
->firmware_event_thread
) {
6878 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6879 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6880 goto out_thread_fail
;
6883 ioc
->wait_for_port_enable_to_complete
= 1;
6884 if ((mpt2sas_base_attach(ioc
))) {
6885 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6886 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6887 goto out_attach_fail
;
6890 ioc
->wait_for_port_enable_to_complete
= 0;
6891 _scsih_probe_devices(ioc
);
6895 destroy_workqueue(ioc
->firmware_event_thread
);
6897 list_del(&ioc
->list
);
6898 scsi_remove_host(shost
);
6905 * _scsih_suspend - power management suspend main entry point
6906 * @pdev: PCI device struct
6907 * @state: PM state change to (usually PCI_D3)
6909 * Returns 0 success, anything else error.
6912 _scsih_suspend(struct pci_dev
*pdev
, pm_message_t state
)
6914 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6915 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
6918 mpt2sas_base_stop_watchdog(ioc
);
6919 flush_scheduled_work();
6920 scsi_block_requests(shost
);
6921 device_state
= pci_choose_state(pdev
, state
);
6922 printk(MPT2SAS_INFO_FMT
"pdev=0x%p, slot=%s, entering "
6923 "operating state [D%d]\n", ioc
->name
, pdev
,
6924 pci_name(pdev
), device_state
);
6926 mpt2sas_base_free_resources(ioc
);
6927 pci_save_state(pdev
);
6928 pci_disable_device(pdev
);
6929 pci_set_power_state(pdev
, device_state
);
6934 * _scsih_resume - power management resume main entry point
6935 * @pdev: PCI device struct
6937 * Returns 0 success, anything else error.
6940 _scsih_resume(struct pci_dev
*pdev
)
6942 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6943 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
6944 u32 device_state
= pdev
->current_state
;
6947 printk(MPT2SAS_INFO_FMT
"pdev=0x%p, slot=%s, previous "
6948 "operating state [D%d]\n", ioc
->name
, pdev
,
6949 pci_name(pdev
), device_state
);
6951 pci_set_power_state(pdev
, PCI_D0
);
6952 pci_enable_wake(pdev
, PCI_D0
, 0);
6953 pci_restore_state(pdev
);
6955 r
= mpt2sas_base_map_resources(ioc
);
6959 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
, SOFT_RESET
);
6960 scsi_unblock_requests(shost
);
6961 mpt2sas_base_start_watchdog(ioc
);
6964 #endif /* CONFIG_PM */
6967 * _scsih_pci_error_detected - Called when a PCI error is detected.
6968 * @pdev: PCI device struct
6969 * @state: PCI channel state
6971 * Description: Called when a PCI error is detected.
6974 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
6976 static pci_ers_result_t
6977 _scsih_pci_error_detected(struct pci_dev
*pdev
, pci_channel_state_t state
)
6979 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6980 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
6982 printk(MPT2SAS_INFO_FMT
"PCI error: detected callback, state(%d)!!\n",
6986 case pci_channel_io_normal
:
6987 return PCI_ERS_RESULT_CAN_RECOVER
;
6988 case pci_channel_io_frozen
:
6989 /* Fatal error, prepare for slot reset */
6990 ioc
->pci_error_recovery
= 1;
6991 scsi_block_requests(ioc
->shost
);
6992 mpt2sas_base_stop_watchdog(ioc
);
6993 mpt2sas_base_free_resources(ioc
);
6994 return PCI_ERS_RESULT_NEED_RESET
;
6995 case pci_channel_io_perm_failure
:
6996 /* Permanent error, prepare for device removal */
6997 ioc
->pci_error_recovery
= 1;
6998 mpt2sas_base_stop_watchdog(ioc
);
6999 _scsih_flush_running_cmds(ioc
);
7000 return PCI_ERS_RESULT_DISCONNECT
;
7002 return PCI_ERS_RESULT_NEED_RESET
;
7006 * _scsih_pci_slot_reset - Called when PCI slot has been reset.
7007 * @pdev: PCI device struct
7009 * Description: This routine is called by the pci error recovery
7010 * code after the PCI slot has been reset, just before we
7011 * should resume normal operations.
7013 static pci_ers_result_t
7014 _scsih_pci_slot_reset(struct pci_dev
*pdev
)
7016 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
7017 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
7020 printk(MPT2SAS_INFO_FMT
"PCI error: slot reset callback!!\n",
7023 ioc
->pci_error_recovery
= 0;
7025 pci_restore_state(pdev
);
7026 rc
= mpt2sas_base_map_resources(ioc
);
7028 return PCI_ERS_RESULT_DISCONNECT
;
7031 rc
= mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
7034 printk(MPT2SAS_WARN_FMT
"hard reset: %s\n", ioc
->name
,
7035 (rc
== 0) ? "success" : "failed");
7038 return PCI_ERS_RESULT_RECOVERED
;
7040 return PCI_ERS_RESULT_DISCONNECT
;
7044 * _scsih_pci_resume() - resume normal ops after PCI reset
7045 * @pdev: pointer to PCI device
7047 * Called when the error recovery driver tells us that its
7048 * OK to resume normal operation. Use completion to allow
7049 * halted scsi ops to resume.
7052 _scsih_pci_resume(struct pci_dev
*pdev
)
7054 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
7055 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
7057 printk(MPT2SAS_INFO_FMT
"PCI error: resume callback!!\n", ioc
->name
);
7059 pci_cleanup_aer_uncorrect_error_status(pdev
);
7060 mpt2sas_base_start_watchdog(ioc
);
7061 scsi_unblock_requests(ioc
->shost
);
7065 * _scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
7066 * @pdev: pointer to PCI device
7068 static pci_ers_result_t
7069 _scsih_pci_mmio_enabled(struct pci_dev
*pdev
)
7071 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
7072 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
7074 printk(MPT2SAS_INFO_FMT
"PCI error: mmio enabled callback!!\n",
7077 /* TODO - dump whatever for debugging purposes */
7079 /* Request a slot reset. */
7080 return PCI_ERS_RESULT_NEED_RESET
;
7083 static struct pci_error_handlers _scsih_err_handler
= {
7084 .error_detected
= _scsih_pci_error_detected
,
7085 .mmio_enabled
= _scsih_pci_mmio_enabled
,
7086 .slot_reset
= _scsih_pci_slot_reset
,
7087 .resume
= _scsih_pci_resume
,
7090 static struct pci_driver scsih_driver
= {
7091 .name
= MPT2SAS_DRIVER_NAME
,
7092 .id_table
= scsih_pci_table
,
7093 .probe
= _scsih_probe
,
7094 .remove
= __devexit_p(_scsih_remove
),
7095 .shutdown
= _scsih_shutdown
,
7096 .err_handler
= &_scsih_err_handler
,
7098 .suspend
= _scsih_suspend
,
7099 .resume
= _scsih_resume
,
7103 /* raid transport support */
7104 static struct raid_function_template mpt2sas_raid_functions
= {
7105 .cookie
= &scsih_driver_template
,
7106 .is_raid
= _scsih_is_raid
,
7107 .get_resync
= _scsih_get_resync
,
7108 .get_state
= _scsih_get_state
,
7112 * _scsih_init - main entry point for this driver.
7114 * Returns 0 success, anything else error.
7122 printk(KERN_INFO
"%s version %s loaded\n", MPT2SAS_DRIVER_NAME
,
7123 MPT2SAS_DRIVER_VERSION
);
7125 mpt2sas_transport_template
=
7126 sas_attach_transport(&mpt2sas_transport_functions
);
7127 if (!mpt2sas_transport_template
)
7129 /* raid transport support */
7130 mpt2sas_raid_template
= raid_class_attach(&mpt2sas_raid_functions
);
7131 if (!mpt2sas_raid_template
) {
7132 sas_release_transport(mpt2sas_transport_template
);
7136 mpt2sas_base_initialize_callback_handler();
7138 /* queuecommand callback hander */
7139 scsi_io_cb_idx
= mpt2sas_base_register_callback_handler(_scsih_io_done
);
7141 /* task management callback handler */
7142 tm_cb_idx
= mpt2sas_base_register_callback_handler(_scsih_tm_done
);
7144 /* base internal commands callback handler */
7145 base_cb_idx
= mpt2sas_base_register_callback_handler(mpt2sas_base_done
);
7147 /* transport internal commands callback handler */
7148 transport_cb_idx
= mpt2sas_base_register_callback_handler(
7149 mpt2sas_transport_done
);
7151 /* scsih internal commands callback handler */
7152 scsih_cb_idx
= mpt2sas_base_register_callback_handler(_scsih_done
);
7154 /* configuration page API internal commands callback handler */
7155 config_cb_idx
= mpt2sas_base_register_callback_handler(
7156 mpt2sas_config_done
);
7158 /* ctl module callback handler */
7159 ctl_cb_idx
= mpt2sas_base_register_callback_handler(mpt2sas_ctl_done
);
7161 tm_tr_cb_idx
= mpt2sas_base_register_callback_handler(
7162 _scsih_tm_tr_complete
);
7164 tm_tr_volume_cb_idx
= mpt2sas_base_register_callback_handler(
7165 _scsih_tm_volume_tr_complete
);
7167 tm_sas_control_cb_idx
= mpt2sas_base_register_callback_handler(
7168 _scsih_sas_control_complete
);
7172 error
= pci_register_driver(&scsih_driver
);
7174 /* raid transport support */
7175 raid_class_release(mpt2sas_raid_template
);
7176 sas_release_transport(mpt2sas_transport_template
);
7183 * _scsih_exit - exit point for this driver (when it is a module).
7185 * Returns 0 success, anything else error.
7190 printk(KERN_INFO
"mpt2sas version %s unloading\n",
7191 MPT2SAS_DRIVER_VERSION
);
7193 pci_unregister_driver(&scsih_driver
);
7197 mpt2sas_base_release_callback_handler(scsi_io_cb_idx
);
7198 mpt2sas_base_release_callback_handler(tm_cb_idx
);
7199 mpt2sas_base_release_callback_handler(base_cb_idx
);
7200 mpt2sas_base_release_callback_handler(transport_cb_idx
);
7201 mpt2sas_base_release_callback_handler(scsih_cb_idx
);
7202 mpt2sas_base_release_callback_handler(config_cb_idx
);
7203 mpt2sas_base_release_callback_handler(ctl_cb_idx
);
7205 mpt2sas_base_release_callback_handler(tm_tr_cb_idx
);
7206 mpt2sas_base_release_callback_handler(tm_tr_volume_cb_idx
);
7207 mpt2sas_base_release_callback_handler(tm_sas_control_cb_idx
);
7209 /* raid transport support */
7210 raid_class_release(mpt2sas_raid_template
);
7211 sas_release_transport(mpt2sas_transport_template
);
7215 module_init(_scsih_init
);
7216 module_exit(_scsih_exit
);