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_adjust_queue_depth - setting device queue depth
1106 * @sdev: scsi device struct
1107 * @qdepth: requested queue depth
1113 _scsih_adjust_queue_depth(struct scsi_device
*sdev
, int qdepth
)
1115 struct Scsi_Host
*shost
= sdev
->host
;
1117 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1118 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1119 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1120 struct _sas_device
*sas_device
;
1121 unsigned long flags
;
1123 max_depth
= shost
->can_queue
;
1125 /* limit max device queue for SATA to 32 */
1126 sas_device_priv_data
= sdev
->hostdata
;
1127 if (!sas_device_priv_data
)
1129 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
1130 if (!sas_target_priv_data
)
1132 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
))
1134 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1135 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1136 sas_device_priv_data
->sas_target
->sas_address
);
1137 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1138 if (sas_device
&& sas_device
->device_info
&
1139 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1140 max_depth
= MPT2SAS_SATA_QUEUE_DEPTH
;
1144 if (!sdev
->tagged_supported
)
1146 if (qdepth
> max_depth
)
1148 scsi_adjust_queue_depth(sdev
, scsi_get_tag_type(sdev
), qdepth
);
1152 * _scsih_change_queue_depth - setting device queue depth
1153 * @sdev: scsi device struct
1154 * @qdepth: requested queue depth
1155 * @reason: SCSI_QDEPTH_DEFAULT/SCSI_QDEPTH_QFULL/SCSI_QDEPTH_RAMP_UP
1156 * (see include/scsi/scsi_host.h for definition)
1158 * Returns queue depth.
1161 _scsih_change_queue_depth(struct scsi_device
*sdev
, int qdepth
, int reason
)
1163 if (reason
== SCSI_QDEPTH_DEFAULT
|| reason
== SCSI_QDEPTH_RAMP_UP
)
1164 _scsih_adjust_queue_depth(sdev
, qdepth
);
1165 else if (reason
== SCSI_QDEPTH_QFULL
)
1166 scsi_track_queue_full(sdev
, qdepth
);
1170 if (sdev
->inquiry_len
> 7)
1171 sdev_printk(KERN_INFO
, sdev
, "qdepth(%d), tagged(%d), "
1172 "simple(%d), ordered(%d), scsi_level(%d), cmd_que(%d)\n",
1173 sdev
->queue_depth
, sdev
->tagged_supported
, sdev
->simple_tags
,
1174 sdev
->ordered_tags
, sdev
->scsi_level
,
1175 (sdev
->inquiry
[7] & 2) >> 1);
1177 return sdev
->queue_depth
;
1181 * _scsih_change_queue_type - changing device queue tag type
1182 * @sdev: scsi device struct
1183 * @tag_type: requested tag type
1185 * Returns queue tag type.
1188 _scsih_change_queue_type(struct scsi_device
*sdev
, int tag_type
)
1190 if (sdev
->tagged_supported
) {
1191 scsi_set_tag_type(sdev
, tag_type
);
1193 scsi_activate_tcq(sdev
, sdev
->queue_depth
);
1195 scsi_deactivate_tcq(sdev
, sdev
->queue_depth
);
1203 * _scsih_target_alloc - target add routine
1204 * @starget: scsi target struct
1206 * Returns 0 if ok. Any other return is assumed to be an error and
1207 * the device is ignored.
1210 _scsih_target_alloc(struct scsi_target
*starget
)
1212 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
1213 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1214 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1215 struct _sas_device
*sas_device
;
1216 struct _raid_device
*raid_device
;
1217 unsigned long flags
;
1218 struct sas_rphy
*rphy
;
1220 sas_target_priv_data
= kzalloc(sizeof(struct scsi_target
), GFP_KERNEL
);
1221 if (!sas_target_priv_data
)
1224 starget
->hostdata
= sas_target_priv_data
;
1225 sas_target_priv_data
->starget
= starget
;
1226 sas_target_priv_data
->handle
= MPT2SAS_INVALID_DEVICE_HANDLE
;
1229 if (starget
->channel
== RAID_CHANNEL
) {
1230 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1231 raid_device
= _scsih_raid_device_find_by_id(ioc
, starget
->id
,
1234 sas_target_priv_data
->handle
= raid_device
->handle
;
1235 sas_target_priv_data
->sas_address
= raid_device
->wwid
;
1236 sas_target_priv_data
->flags
|= MPT_TARGET_FLAGS_VOLUME
;
1237 raid_device
->starget
= starget
;
1239 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1243 /* sas/sata devices */
1244 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1245 rphy
= dev_to_rphy(starget
->dev
.parent
);
1246 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1247 rphy
->identify
.sas_address
);
1250 sas_target_priv_data
->handle
= sas_device
->handle
;
1251 sas_target_priv_data
->sas_address
= sas_device
->sas_address
;
1252 sas_device
->starget
= starget
;
1253 sas_device
->id
= starget
->id
;
1254 sas_device
->channel
= starget
->channel
;
1255 if (test_bit(sas_device
->handle
, ioc
->pd_handles
))
1256 sas_target_priv_data
->flags
|=
1257 MPT_TARGET_FLAGS_RAID_COMPONENT
;
1259 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1265 * _scsih_target_destroy - target destroy routine
1266 * @starget: scsi target struct
1271 _scsih_target_destroy(struct scsi_target
*starget
)
1273 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
1274 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1275 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1276 struct _sas_device
*sas_device
;
1277 struct _raid_device
*raid_device
;
1278 unsigned long flags
;
1279 struct sas_rphy
*rphy
;
1281 sas_target_priv_data
= starget
->hostdata
;
1282 if (!sas_target_priv_data
)
1285 if (starget
->channel
== RAID_CHANNEL
) {
1286 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1287 raid_device
= _scsih_raid_device_find_by_id(ioc
, starget
->id
,
1290 raid_device
->starget
= NULL
;
1291 raid_device
->sdev
= NULL
;
1293 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1297 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1298 rphy
= dev_to_rphy(starget
->dev
.parent
);
1299 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1300 rphy
->identify
.sas_address
);
1301 if (sas_device
&& (sas_device
->starget
== starget
) &&
1302 (sas_device
->id
== starget
->id
) &&
1303 (sas_device
->channel
== starget
->channel
))
1304 sas_device
->starget
= NULL
;
1306 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1309 kfree(sas_target_priv_data
);
1310 starget
->hostdata
= NULL
;
1314 * _scsih_slave_alloc - device add routine
1315 * @sdev: scsi device struct
1317 * Returns 0 if ok. Any other return is assumed to be an error and
1318 * the device is ignored.
1321 _scsih_slave_alloc(struct scsi_device
*sdev
)
1323 struct Scsi_Host
*shost
;
1324 struct MPT2SAS_ADAPTER
*ioc
;
1325 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1326 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1327 struct scsi_target
*starget
;
1328 struct _raid_device
*raid_device
;
1329 unsigned long flags
;
1331 sas_device_priv_data
= kzalloc(sizeof(struct scsi_device
), GFP_KERNEL
);
1332 if (!sas_device_priv_data
)
1335 sas_device_priv_data
->lun
= sdev
->lun
;
1336 sas_device_priv_data
->flags
= MPT_DEVICE_FLAGS_INIT
;
1338 starget
= scsi_target(sdev
);
1339 sas_target_priv_data
= starget
->hostdata
;
1340 sas_target_priv_data
->num_luns
++;
1341 sas_device_priv_data
->sas_target
= sas_target_priv_data
;
1342 sdev
->hostdata
= sas_device_priv_data
;
1343 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
))
1344 sdev
->no_uld_attach
= 1;
1346 shost
= dev_to_shost(&starget
->dev
);
1347 ioc
= shost_priv(shost
);
1348 if (starget
->channel
== RAID_CHANNEL
) {
1349 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1350 raid_device
= _scsih_raid_device_find_by_id(ioc
,
1351 starget
->id
, starget
->channel
);
1353 raid_device
->sdev
= sdev
; /* raid is single lun */
1354 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1361 * _scsih_slave_destroy - device destroy routine
1362 * @sdev: scsi device struct
1367 _scsih_slave_destroy(struct scsi_device
*sdev
)
1369 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1370 struct scsi_target
*starget
;
1372 if (!sdev
->hostdata
)
1375 starget
= scsi_target(sdev
);
1376 sas_target_priv_data
= starget
->hostdata
;
1377 sas_target_priv_data
->num_luns
--;
1378 kfree(sdev
->hostdata
);
1379 sdev
->hostdata
= NULL
;
1383 * _scsih_display_sata_capabilities - sata capabilities
1384 * @ioc: per adapter object
1385 * @sas_device: the sas_device object
1386 * @sdev: scsi device struct
1389 _scsih_display_sata_capabilities(struct MPT2SAS_ADAPTER
*ioc
,
1390 struct _sas_device
*sas_device
, struct scsi_device
*sdev
)
1392 Mpi2ConfigReply_t mpi_reply
;
1393 Mpi2SasDevicePage0_t sas_device_pg0
;
1398 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
1399 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, sas_device
->handle
))) {
1400 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1401 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1405 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
1406 MPI2_IOCSTATUS_MASK
;
1407 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
1408 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1409 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1413 flags
= le16_to_cpu(sas_device_pg0
.Flags
);
1414 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
1416 sdev_printk(KERN_INFO
, sdev
,
1417 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1418 "sw_preserve(%s)\n",
1419 (device_info
& MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE
) ? "y" : "n",
1420 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED
) ? "y" : "n",
1421 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY
) ? "y" :
1423 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED
) ? "y" : "n",
1424 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED
) ? "y" : "n",
1425 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE
) ? "y" : "n");
1429 * _scsih_is_raid - return boolean indicating device is raid volume
1430 * @dev the device struct object
1433 _scsih_is_raid(struct device
*dev
)
1435 struct scsi_device
*sdev
= to_scsi_device(dev
);
1437 return (sdev
->channel
== RAID_CHANNEL
) ? 1 : 0;
1441 * _scsih_get_resync - get raid volume resync percent complete
1442 * @dev the device struct object
1445 _scsih_get_resync(struct device
*dev
)
1447 struct scsi_device
*sdev
= to_scsi_device(dev
);
1448 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
1449 static struct _raid_device
*raid_device
;
1450 unsigned long flags
;
1451 Mpi2RaidVolPage0_t vol_pg0
;
1452 Mpi2ConfigReply_t mpi_reply
;
1453 u32 volume_status_flags
;
1454 u8 percent_complete
= 0;
1456 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1457 raid_device
= _scsih_raid_device_find_by_id(ioc
, sdev
->id
,
1459 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1464 if (mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, &vol_pg0
,
1465 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, raid_device
->handle
,
1466 sizeof(Mpi2RaidVolPage0_t
))) {
1467 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1468 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1472 volume_status_flags
= le32_to_cpu(vol_pg0
.VolumeStatusFlags
);
1473 if (volume_status_flags
& MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS
)
1474 percent_complete
= raid_device
->percent_complete
;
1476 raid_set_resync(mpt2sas_raid_template
, dev
, percent_complete
);
1480 * _scsih_get_state - get raid volume level
1481 * @dev the device struct object
1484 _scsih_get_state(struct device
*dev
)
1486 struct scsi_device
*sdev
= to_scsi_device(dev
);
1487 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
1488 static struct _raid_device
*raid_device
;
1489 unsigned long flags
;
1490 Mpi2RaidVolPage0_t vol_pg0
;
1491 Mpi2ConfigReply_t mpi_reply
;
1493 enum raid_state state
= RAID_STATE_UNKNOWN
;
1495 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1496 raid_device
= _scsih_raid_device_find_by_id(ioc
, sdev
->id
,
1498 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1503 if (mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, &vol_pg0
,
1504 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, raid_device
->handle
,
1505 sizeof(Mpi2RaidVolPage0_t
))) {
1506 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1507 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1511 volstate
= le32_to_cpu(vol_pg0
.VolumeStatusFlags
);
1512 if (volstate
& MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS
) {
1513 state
= RAID_STATE_RESYNCING
;
1517 switch (vol_pg0
.VolumeState
) {
1518 case MPI2_RAID_VOL_STATE_OPTIMAL
:
1519 case MPI2_RAID_VOL_STATE_ONLINE
:
1520 state
= RAID_STATE_ACTIVE
;
1522 case MPI2_RAID_VOL_STATE_DEGRADED
:
1523 state
= RAID_STATE_DEGRADED
;
1525 case MPI2_RAID_VOL_STATE_FAILED
:
1526 case MPI2_RAID_VOL_STATE_MISSING
:
1527 state
= RAID_STATE_OFFLINE
;
1531 raid_set_state(mpt2sas_raid_template
, dev
, state
);
1535 * _scsih_set_level - set raid level
1536 * @sdev: scsi device struct
1537 * @raid_device: raid_device object
1540 _scsih_set_level(struct scsi_device
*sdev
, struct _raid_device
*raid_device
)
1542 enum raid_level level
= RAID_LEVEL_UNKNOWN
;
1544 switch (raid_device
->volume_type
) {
1545 case MPI2_RAID_VOL_TYPE_RAID0
:
1546 level
= RAID_LEVEL_0
;
1548 case MPI2_RAID_VOL_TYPE_RAID10
:
1549 level
= RAID_LEVEL_10
;
1551 case MPI2_RAID_VOL_TYPE_RAID1E
:
1552 level
= RAID_LEVEL_1E
;
1554 case MPI2_RAID_VOL_TYPE_RAID1
:
1555 level
= RAID_LEVEL_1
;
1559 raid_set_level(mpt2sas_raid_template
, &sdev
->sdev_gendev
, level
);
1563 * _scsih_get_volume_capabilities - volume capabilities
1564 * @ioc: per adapter object
1565 * @sas_device: the raid_device object
1568 _scsih_get_volume_capabilities(struct MPT2SAS_ADAPTER
*ioc
,
1569 struct _raid_device
*raid_device
)
1571 Mpi2RaidVolPage0_t
*vol_pg0
;
1572 Mpi2RaidPhysDiskPage0_t pd_pg0
;
1573 Mpi2SasDevicePage0_t sas_device_pg0
;
1574 Mpi2ConfigReply_t mpi_reply
;
1578 if ((mpt2sas_config_get_number_pds(ioc
, raid_device
->handle
,
1579 &num_pds
)) || !num_pds
) {
1580 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1581 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1585 raid_device
->num_pds
= num_pds
;
1586 sz
= offsetof(Mpi2RaidVolPage0_t
, PhysDisk
) + (num_pds
*
1587 sizeof(Mpi2RaidVol0PhysDisk_t
));
1588 vol_pg0
= kzalloc(sz
, GFP_KERNEL
);
1590 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1591 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1595 if ((mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, vol_pg0
,
1596 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, raid_device
->handle
, sz
))) {
1597 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1598 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1603 raid_device
->volume_type
= vol_pg0
->VolumeType
;
1605 /* figure out what the underlying devices are by
1606 * obtaining the device_info bits for the 1st device
1608 if (!(mpt2sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
1609 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM
,
1610 vol_pg0
->PhysDisk
[0].PhysDiskNum
))) {
1611 if (!(mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
1612 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
1613 le16_to_cpu(pd_pg0
.DevHandle
)))) {
1614 raid_device
->device_info
=
1615 le32_to_cpu(sas_device_pg0
.DeviceInfo
);
1623 * _scsih_enable_tlr - setting TLR flags
1624 * @ioc: per adapter object
1625 * @sdev: scsi device struct
1627 * Enabling Transaction Layer Retries for tape devices when
1628 * vpd page 0x90 is present
1632 _scsih_enable_tlr(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_device
*sdev
)
1635 if (sdev
->type
!= TYPE_TAPE
)
1638 if (!(ioc
->facts
.IOCCapabilities
& MPI2_IOCFACTS_CAPABILITY_TLR
))
1641 sas_enable_tlr(sdev
);
1642 sdev_printk(KERN_INFO
, sdev
, "TLR %s\n",
1643 sas_is_tlr_enabled(sdev
) ? "Enabled" : "Disabled");
1649 * _scsih_slave_configure - device configure routine.
1650 * @sdev: scsi device struct
1652 * Returns 0 if ok. Any other return is assumed to be an error and
1653 * the device is ignored.
1656 _scsih_slave_configure(struct scsi_device
*sdev
)
1658 struct Scsi_Host
*shost
= sdev
->host
;
1659 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1660 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1661 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1662 struct _sas_device
*sas_device
;
1663 struct _raid_device
*raid_device
;
1664 unsigned long flags
;
1671 sas_device_priv_data
= sdev
->hostdata
;
1672 sas_device_priv_data
->configured_lun
= 1;
1673 sas_device_priv_data
->flags
&= ~MPT_DEVICE_FLAGS_INIT
;
1674 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
1676 /* raid volume handling */
1677 if (sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
1679 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1680 raid_device
= _scsih_raid_device_find_by_handle(ioc
,
1681 sas_target_priv_data
->handle
);
1682 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1684 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1685 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1689 _scsih_get_volume_capabilities(ioc
, raid_device
);
1691 /* RAID Queue Depth Support
1692 * IS volume = underlying qdepth of drive type, either
1693 * MPT2SAS_SAS_QUEUE_DEPTH or MPT2SAS_SATA_QUEUE_DEPTH
1694 * IM/IME/R10 = 128 (MPT2SAS_RAID_QUEUE_DEPTH)
1696 if (raid_device
->device_info
&
1697 MPI2_SAS_DEVICE_INFO_SSP_TARGET
) {
1698 qdepth
= MPT2SAS_SAS_QUEUE_DEPTH
;
1701 qdepth
= MPT2SAS_SATA_QUEUE_DEPTH
;
1702 if (raid_device
->device_info
&
1703 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1709 switch (raid_device
->volume_type
) {
1710 case MPI2_RAID_VOL_TYPE_RAID0
:
1713 case MPI2_RAID_VOL_TYPE_RAID1E
:
1714 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
1715 if (ioc
->manu_pg10
.OEMIdentifier
&&
1716 (ioc
->manu_pg10
.GenericFlags0
&
1717 MFG10_GF0_R10_DISPLAY
) &&
1718 !(raid_device
->num_pds
% 2))
1723 case MPI2_RAID_VOL_TYPE_RAID1
:
1724 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
1727 case MPI2_RAID_VOL_TYPE_RAID10
:
1728 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
1731 case MPI2_RAID_VOL_TYPE_UNKNOWN
:
1733 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
1738 sdev_printk(KERN_INFO
, sdev
, "%s: "
1739 "handle(0x%04x), wwid(0x%016llx), pd_count(%d), type(%s)\n",
1740 r_level
, raid_device
->handle
,
1741 (unsigned long long)raid_device
->wwid
,
1742 raid_device
->num_pds
, ds
);
1743 _scsih_change_queue_depth(sdev
, qdepth
, SCSI_QDEPTH_DEFAULT
);
1744 /* raid transport support */
1745 _scsih_set_level(sdev
, raid_device
);
1749 /* non-raid handling */
1750 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1751 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1752 sas_device_priv_data
->sas_target
->sas_address
);
1753 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1755 if (sas_target_priv_data
->flags
&
1756 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
1757 mpt2sas_config_get_volume_handle(ioc
,
1758 sas_device
->handle
, &sas_device
->volume_handle
);
1759 mpt2sas_config_get_volume_wwid(ioc
,
1760 sas_device
->volume_handle
,
1761 &sas_device
->volume_wwid
);
1763 if (sas_device
->device_info
& MPI2_SAS_DEVICE_INFO_SSP_TARGET
) {
1764 qdepth
= MPT2SAS_SAS_QUEUE_DEPTH
;
1768 qdepth
= MPT2SAS_SATA_QUEUE_DEPTH
;
1769 if (sas_device
->device_info
&
1770 MPI2_SAS_DEVICE_INFO_STP_TARGET
)
1772 else if (sas_device
->device_info
&
1773 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1777 sdev_printk(KERN_INFO
, sdev
, "%s: handle(0x%04x), "
1778 "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n",
1779 ds
, sas_device
->handle
,
1780 (unsigned long long)sas_device
->sas_address
,
1782 (unsigned long long)sas_device
->device_name
);
1783 sdev_printk(KERN_INFO
, sdev
, "%s: "
1784 "enclosure_logical_id(0x%016llx), slot(%d)\n", ds
,
1785 (unsigned long long) sas_device
->enclosure_logical_id
,
1789 _scsih_display_sata_capabilities(ioc
, sas_device
, sdev
);
1792 _scsih_change_queue_depth(sdev
, qdepth
, SCSI_QDEPTH_DEFAULT
);
1795 sas_read_port_mode_page(sdev
);
1796 _scsih_enable_tlr(ioc
, sdev
);
1802 * _scsih_bios_param - fetch head, sector, cylinder info for a disk
1803 * @sdev: scsi device struct
1804 * @bdev: pointer to block device context
1805 * @capacity: device size (in 512 byte sectors)
1806 * @params: three element array to place output:
1807 * params[0] number of heads (max 255)
1808 * params[1] number of sectors (max 63)
1809 * params[2] number of cylinders
1814 _scsih_bios_param(struct scsi_device
*sdev
, struct block_device
*bdev
,
1815 sector_t capacity
, int params
[])
1825 dummy
= heads
* sectors
;
1826 cylinders
= capacity
;
1827 sector_div(cylinders
, dummy
);
1830 * Handle extended translation size for logical drives
1833 if ((ulong
)capacity
>= 0x200000) {
1836 dummy
= heads
* sectors
;
1837 cylinders
= capacity
;
1838 sector_div(cylinders
, dummy
);
1843 params
[1] = sectors
;
1844 params
[2] = cylinders
;
1850 * _scsih_response_code - translation of device response code
1851 * @ioc: per adapter object
1852 * @response_code: response code returned by the device
1857 _scsih_response_code(struct MPT2SAS_ADAPTER
*ioc
, u8 response_code
)
1861 switch (response_code
) {
1862 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE
:
1863 desc
= "task management request completed";
1865 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
:
1866 desc
= "invalid frame";
1868 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED
:
1869 desc
= "task management request not supported";
1871 case MPI2_SCSITASKMGMT_RSP_TM_FAILED
:
1872 desc
= "task management request failed";
1874 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
:
1875 desc
= "task management request succeeded";
1877 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN
:
1878 desc
= "invalid lun";
1881 desc
= "overlapped tag attempted";
1883 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
:
1884 desc
= "task queued, however not sent to target";
1890 printk(MPT2SAS_WARN_FMT
"response_code(0x%01x): %s\n",
1891 ioc
->name
, response_code
, desc
);
1895 * _scsih_tm_done - tm completion routine
1896 * @ioc: per adapter object
1897 * @smid: system request message index
1898 * @msix_index: MSIX table index supplied by the OS
1899 * @reply: reply message frame(lower 32bit addr)
1902 * The callback handler when using scsih_issue_tm.
1904 * Return 1 meaning mf should be freed from _base_interrupt
1905 * 0 means the mf is freed from this function.
1908 _scsih_tm_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
1910 MPI2DefaultReply_t
*mpi_reply
;
1912 if (ioc
->tm_cmds
.status
== MPT2_CMD_NOT_USED
)
1914 if (ioc
->tm_cmds
.smid
!= smid
)
1916 ioc
->tm_cmds
.status
|= MPT2_CMD_COMPLETE
;
1917 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
1919 memcpy(ioc
->tm_cmds
.reply
, mpi_reply
, mpi_reply
->MsgLength
*4);
1920 ioc
->tm_cmds
.status
|= MPT2_CMD_REPLY_VALID
;
1922 ioc
->tm_cmds
.status
&= ~MPT2_CMD_PENDING
;
1923 complete(&ioc
->tm_cmds
.done
);
1928 * mpt2sas_scsih_set_tm_flag - set per target tm_busy
1929 * @ioc: per adapter object
1930 * @handle: device handle
1932 * During taskmangement request, we need to freeze the device queue.
1935 mpt2sas_scsih_set_tm_flag(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
1937 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1938 struct scsi_device
*sdev
;
1941 shost_for_each_device(sdev
, ioc
->shost
) {
1944 sas_device_priv_data
= sdev
->hostdata
;
1945 if (!sas_device_priv_data
)
1947 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
1948 sas_device_priv_data
->sas_target
->tm_busy
= 1;
1950 ioc
->ignore_loginfos
= 1;
1956 * mpt2sas_scsih_clear_tm_flag - clear per target tm_busy
1957 * @ioc: per adapter object
1958 * @handle: device handle
1960 * During taskmangement request, we need to freeze the device queue.
1963 mpt2sas_scsih_clear_tm_flag(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
1965 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1966 struct scsi_device
*sdev
;
1969 shost_for_each_device(sdev
, ioc
->shost
) {
1972 sas_device_priv_data
= sdev
->hostdata
;
1973 if (!sas_device_priv_data
)
1975 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
1976 sas_device_priv_data
->sas_target
->tm_busy
= 0;
1978 ioc
->ignore_loginfos
= 0;
1985 * mpt2sas_scsih_issue_tm - main routine for sending tm requests
1986 * @ioc: per adapter struct
1987 * @device_handle: device handle
1988 * @channel: the channel assigned by the OS
1989 * @id: the id assigned by the OS
1991 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
1992 * @smid_task: smid assigned to the task
1993 * @timeout: timeout in seconds
1996 * A generic API for sending task management requests to firmware.
1998 * The callback index is set inside `ioc->tm_cb_idx`.
2000 * Return SUCCESS or FAILED.
2003 mpt2sas_scsih_issue_tm(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
, uint channel
,
2004 uint id
, uint lun
, u8 type
, u16 smid_task
, ulong timeout
,
2005 struct scsi_cmnd
*scmd
)
2007 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
2008 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
2011 unsigned long timeleft
;
2012 struct scsi_cmnd
*scmd_lookup
;
2015 mutex_lock(&ioc
->tm_cmds
.mutex
);
2016 if (ioc
->tm_cmds
.status
!= MPT2_CMD_NOT_USED
) {
2017 printk(MPT2SAS_INFO_FMT
"%s: tm_cmd busy!!!\n",
2018 __func__
, ioc
->name
);
2023 if (ioc
->shost_recovery
|| ioc
->remove_host
||
2024 ioc
->pci_error_recovery
) {
2025 printk(MPT2SAS_INFO_FMT
"%s: host reset in progress!\n",
2026 __func__
, ioc
->name
);
2031 ioc_state
= mpt2sas_base_get_iocstate(ioc
, 0);
2032 if (ioc_state
& MPI2_DOORBELL_USED
) {
2033 dhsprintk(ioc
, printk(MPT2SAS_INFO_FMT
"unexpected doorbell "
2034 "active!\n", ioc
->name
));
2035 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2041 if ((ioc_state
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_FAULT
) {
2042 mpt2sas_base_fault_info(ioc
, ioc_state
&
2043 MPI2_DOORBELL_DATA_MASK
);
2044 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2050 smid
= mpt2sas_base_get_smid_hpr(ioc
, ioc
->tm_cb_idx
);
2052 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
2053 ioc
->name
, __func__
);
2058 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"sending tm: handle(0x%04x),"
2059 " task_type(0x%02x), smid(%d)\n", ioc
->name
, handle
, type
,
2061 ioc
->tm_cmds
.status
= MPT2_CMD_PENDING
;
2062 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
2063 ioc
->tm_cmds
.smid
= smid
;
2064 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
2065 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
2066 mpi_request
->DevHandle
= cpu_to_le16(handle
);
2067 mpi_request
->TaskType
= type
;
2068 mpi_request
->TaskMID
= cpu_to_le16(smid_task
);
2069 int_to_scsilun(lun
, (struct scsi_lun
*)mpi_request
->LUN
);
2070 mpt2sas_scsih_set_tm_flag(ioc
, handle
);
2071 init_completion(&ioc
->tm_cmds
.done
);
2072 mpt2sas_base_put_smid_hi_priority(ioc
, smid
);
2073 timeleft
= wait_for_completion_timeout(&ioc
->tm_cmds
.done
, timeout
*HZ
);
2074 if (!(ioc
->tm_cmds
.status
& MPT2_CMD_COMPLETE
)) {
2075 printk(MPT2SAS_ERR_FMT
"%s: timeout\n",
2076 ioc
->name
, __func__
);
2077 _debug_dump_mf(mpi_request
,
2078 sizeof(Mpi2SCSITaskManagementRequest_t
)/4);
2079 if (!(ioc
->tm_cmds
.status
& MPT2_CMD_RESET
)) {
2080 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2083 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
2084 mpt2sas_scsih_clear_tm_flag(ioc
, handle
);
2089 if (ioc
->tm_cmds
.status
& MPT2_CMD_REPLY_VALID
) {
2090 mpi_reply
= ioc
->tm_cmds
.reply
;
2091 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"complete tm: "
2092 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
2093 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
2094 le32_to_cpu(mpi_reply
->IOCLogInfo
),
2095 le32_to_cpu(mpi_reply
->TerminationCount
)));
2096 if (ioc
->logging_level
& MPT_DEBUG_TM
) {
2097 _scsih_response_code(ioc
, mpi_reply
->ResponseCode
);
2098 if (mpi_reply
->IOCStatus
)
2099 _debug_dump_mf(mpi_request
,
2100 sizeof(Mpi2SCSITaskManagementRequest_t
)/4);
2105 * Check to see the commands were terminated.
2106 * This is only needed for eh callbacks, hence the scmd check.
2110 goto bypass_sanity_checks
;
2112 case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
:
2113 scmd_lookup
= _scsih_scsi_lookup_get(ioc
, smid_task
);
2114 if (scmd_lookup
&& (scmd_lookup
->serial_number
==
2115 scmd
->serial_number
))
2121 case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
:
2122 if (_scsih_scsi_lookup_find_by_target(ioc
, id
, channel
))
2128 case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET
:
2129 if (_scsih_scsi_lookup_find_by_lun(ioc
, id
, lun
, channel
))
2136 bypass_sanity_checks
:
2138 mpt2sas_scsih_clear_tm_flag(ioc
, handle
);
2139 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
2140 mutex_unlock(&ioc
->tm_cmds
.mutex
);
2145 mutex_unlock(&ioc
->tm_cmds
.mutex
);
2150 * _scsih_tm_display_info - displays info about the device
2151 * @ioc: per adapter struct
2152 * @scmd: pointer to scsi command object
2154 * Called by task management callback handlers.
2157 _scsih_tm_display_info(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
)
2159 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
2160 struct MPT2SAS_TARGET
*priv_target
= starget
->hostdata
;
2161 struct _sas_device
*sas_device
= NULL
;
2162 unsigned long flags
;
2167 scsi_print_command(scmd
);
2168 if (priv_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
2169 starget_printk(KERN_INFO
, starget
, "volume handle(0x%04x), "
2170 "volume wwid(0x%016llx)\n",
2171 priv_target
->handle
,
2172 (unsigned long long)priv_target
->sas_address
);
2174 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2175 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
2176 priv_target
->sas_address
);
2178 if (priv_target
->flags
&
2179 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2180 starget_printk(KERN_INFO
, starget
,
2181 "volume handle(0x%04x), "
2182 "volume wwid(0x%016llx)\n",
2183 sas_device
->volume_handle
,
2184 (unsigned long long)sas_device
->volume_wwid
);
2186 starget_printk(KERN_INFO
, starget
,
2187 "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n",
2189 (unsigned long long)sas_device
->sas_address
,
2191 starget_printk(KERN_INFO
, starget
,
2192 "enclosure_logical_id(0x%016llx), slot(%d)\n",
2193 (unsigned long long)sas_device
->enclosure_logical_id
,
2196 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2201 * _scsih_abort - eh threads main abort routine
2202 * @scmd: pointer to scsi command object
2204 * Returns SUCCESS if command aborted else FAILED
2207 _scsih_abort(struct scsi_cmnd
*scmd
)
2209 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2210 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2215 sdev_printk(KERN_INFO
, scmd
->device
, "attempting task abort! "
2216 "scmd(%p)\n", scmd
);
2217 _scsih_tm_display_info(ioc
, scmd
);
2219 sas_device_priv_data
= scmd
->device
->hostdata
;
2220 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2221 sdev_printk(KERN_INFO
, scmd
->device
, "device been deleted! "
2222 "scmd(%p)\n", scmd
);
2223 scmd
->result
= DID_NO_CONNECT
<< 16;
2224 scmd
->scsi_done(scmd
);
2229 /* search for the command */
2230 smid
= _scsih_scsi_lookup_find_by_scmd(ioc
, scmd
);
2232 scmd
->result
= DID_RESET
<< 16;
2237 /* for hidden raid components and volumes this is not supported */
2238 if (sas_device_priv_data
->sas_target
->flags
&
2239 MPT_TARGET_FLAGS_RAID_COMPONENT
||
2240 sas_device_priv_data
->sas_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
2241 scmd
->result
= DID_RESET
<< 16;
2246 mpt2sas_halt_firmware(ioc
);
2248 handle
= sas_device_priv_data
->sas_target
->handle
;
2249 r
= mpt2sas_scsih_issue_tm(ioc
, handle
, scmd
->device
->channel
,
2250 scmd
->device
->id
, scmd
->device
->lun
,
2251 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
, smid
, 30, scmd
);
2254 sdev_printk(KERN_INFO
, scmd
->device
, "task abort: %s scmd(%p)\n",
2255 ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2260 * _scsih_dev_reset - eh threads main device reset routine
2261 * @scmd: pointer to scsi command object
2263 * Returns SUCCESS if command aborted else FAILED
2266 _scsih_dev_reset(struct scsi_cmnd
*scmd
)
2268 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2269 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2270 struct _sas_device
*sas_device
;
2271 unsigned long flags
;
2275 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
2277 starget_printk(KERN_INFO
, starget
, "attempting device reset! "
2278 "scmd(%p)\n", scmd
);
2279 _scsih_tm_display_info(ioc
, scmd
);
2281 sas_device_priv_data
= scmd
->device
->hostdata
;
2282 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2283 starget_printk(KERN_INFO
, starget
, "device been deleted! "
2284 "scmd(%p)\n", scmd
);
2285 scmd
->result
= DID_NO_CONNECT
<< 16;
2286 scmd
->scsi_done(scmd
);
2291 /* for hidden raid components obtain the volume_handle */
2293 if (sas_device_priv_data
->sas_target
->flags
&
2294 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2295 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2296 sas_device
= _scsih_sas_device_find_by_handle(ioc
,
2297 sas_device_priv_data
->sas_target
->handle
);
2299 handle
= sas_device
->volume_handle
;
2300 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2302 handle
= sas_device_priv_data
->sas_target
->handle
;
2305 scmd
->result
= DID_RESET
<< 16;
2310 r
= mpt2sas_scsih_issue_tm(ioc
, handle
, scmd
->device
->channel
,
2311 scmd
->device
->id
, scmd
->device
->lun
,
2312 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET
, 0, 30, scmd
);
2315 sdev_printk(KERN_INFO
, scmd
->device
, "device reset: %s scmd(%p)\n",
2316 ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2321 * _scsih_target_reset - eh threads main target reset routine
2322 * @scmd: pointer to scsi command object
2324 * Returns SUCCESS if command aborted else FAILED
2327 _scsih_target_reset(struct scsi_cmnd
*scmd
)
2329 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2330 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2331 struct _sas_device
*sas_device
;
2332 unsigned long flags
;
2335 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
2337 starget_printk(KERN_INFO
, starget
, "attempting target reset! "
2338 "scmd(%p)\n", scmd
);
2339 _scsih_tm_display_info(ioc
, scmd
);
2341 sas_device_priv_data
= scmd
->device
->hostdata
;
2342 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2343 starget_printk(KERN_INFO
, starget
, "target been deleted! "
2344 "scmd(%p)\n", scmd
);
2345 scmd
->result
= DID_NO_CONNECT
<< 16;
2346 scmd
->scsi_done(scmd
);
2351 /* for hidden raid components obtain the volume_handle */
2353 if (sas_device_priv_data
->sas_target
->flags
&
2354 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2355 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2356 sas_device
= _scsih_sas_device_find_by_handle(ioc
,
2357 sas_device_priv_data
->sas_target
->handle
);
2359 handle
= sas_device
->volume_handle
;
2360 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2362 handle
= sas_device_priv_data
->sas_target
->handle
;
2365 scmd
->result
= DID_RESET
<< 16;
2370 r
= mpt2sas_scsih_issue_tm(ioc
, handle
, scmd
->device
->channel
,
2371 scmd
->device
->id
, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
, 0,
2375 starget_printk(KERN_INFO
, starget
, "target reset: %s scmd(%p)\n",
2376 ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2381 * _scsih_host_reset - eh threads main host reset routine
2382 * @scmd: pointer to scsi command object
2384 * Returns SUCCESS if command aborted else FAILED
2387 _scsih_host_reset(struct scsi_cmnd
*scmd
)
2389 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2392 printk(MPT2SAS_INFO_FMT
"attempting host reset! scmd(%p)\n",
2394 scsi_print_command(scmd
);
2396 retval
= mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2398 r
= (retval
< 0) ? FAILED
: SUCCESS
;
2399 printk(MPT2SAS_INFO_FMT
"host reset: %s scmd(%p)\n",
2400 ioc
->name
, ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2406 * _scsih_fw_event_add - insert and queue up fw_event
2407 * @ioc: per adapter object
2408 * @fw_event: object describing the event
2409 * Context: This function will acquire ioc->fw_event_lock.
2411 * This adds the firmware event object into link list, then queues it up to
2412 * be processed from user context.
2417 _scsih_fw_event_add(struct MPT2SAS_ADAPTER
*ioc
, struct fw_event_work
*fw_event
)
2419 unsigned long flags
;
2421 if (ioc
->firmware_event_thread
== NULL
)
2424 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2425 list_add_tail(&fw_event
->list
, &ioc
->fw_event_list
);
2426 INIT_DELAYED_WORK(&fw_event
->delayed_work
, _firmware_event_work
);
2427 queue_delayed_work(ioc
->firmware_event_thread
,
2428 &fw_event
->delayed_work
, 0);
2429 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2433 * _scsih_fw_event_free - delete fw_event
2434 * @ioc: per adapter object
2435 * @fw_event: object describing the event
2436 * Context: This function will acquire ioc->fw_event_lock.
2438 * This removes firmware event object from link list, frees associated memory.
2443 _scsih_fw_event_free(struct MPT2SAS_ADAPTER
*ioc
, struct fw_event_work
2446 unsigned long flags
;
2448 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2449 list_del(&fw_event
->list
);
2450 kfree(fw_event
->event_data
);
2452 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2457 * _scsih_queue_rescan - queue a topology rescan from user context
2458 * @ioc: per adapter object
2463 _scsih_queue_rescan(struct MPT2SAS_ADAPTER
*ioc
)
2465 struct fw_event_work
*fw_event
;
2467 if (ioc
->wait_for_port_enable_to_complete
)
2469 fw_event
= kzalloc(sizeof(struct fw_event_work
), GFP_ATOMIC
);
2472 fw_event
->event
= MPT2SAS_RESCAN_AFTER_HOST_RESET
;
2473 fw_event
->ioc
= ioc
;
2474 _scsih_fw_event_add(ioc
, fw_event
);
2478 * _scsih_fw_event_cleanup_queue - cleanup event queue
2479 * @ioc: per adapter object
2481 * Walk the firmware event queue, either killing timers, or waiting
2482 * for outstanding events to complete
2487 _scsih_fw_event_cleanup_queue(struct MPT2SAS_ADAPTER
*ioc
)
2489 struct fw_event_work
*fw_event
, *next
;
2491 if (list_empty(&ioc
->fw_event_list
) ||
2492 !ioc
->firmware_event_thread
|| in_interrupt())
2495 list_for_each_entry_safe(fw_event
, next
, &ioc
->fw_event_list
, list
) {
2496 if (cancel_delayed_work(&fw_event
->delayed_work
)) {
2497 _scsih_fw_event_free(ioc
, fw_event
);
2500 fw_event
->cancel_pending_work
= 1;
2505 * _scsih_ublock_io_device - set the device state to SDEV_RUNNING
2506 * @ioc: per adapter object
2507 * @handle: device handle
2509 * During device pull we need to appropiately set the sdev state.
2512 _scsih_ublock_io_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
2514 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2515 struct scsi_device
*sdev
;
2517 shost_for_each_device(sdev
, ioc
->shost
) {
2518 sas_device_priv_data
= sdev
->hostdata
;
2519 if (!sas_device_priv_data
)
2521 if (!sas_device_priv_data
->block
)
2523 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2524 dewtprintk(ioc
, sdev_printk(KERN_INFO
, sdev
,
2525 MPT2SAS_INFO_FMT
"SDEV_RUNNING: "
2526 "handle(0x%04x)\n", ioc
->name
, handle
));
2527 sas_device_priv_data
->block
= 0;
2528 scsi_internal_device_unblock(sdev
);
2534 * _scsih_block_io_device - set the device state to SDEV_BLOCK
2535 * @ioc: per adapter object
2536 * @handle: device handle
2538 * During device pull we need to appropiately set the sdev state.
2541 _scsih_block_io_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
2543 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2544 struct scsi_device
*sdev
;
2546 shost_for_each_device(sdev
, ioc
->shost
) {
2547 sas_device_priv_data
= sdev
->hostdata
;
2548 if (!sas_device_priv_data
)
2550 if (sas_device_priv_data
->block
)
2552 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2553 dewtprintk(ioc
, sdev_printk(KERN_INFO
, sdev
,
2554 MPT2SAS_INFO_FMT
"SDEV_BLOCK: "
2555 "handle(0x%04x)\n", ioc
->name
, handle
));
2556 sas_device_priv_data
->block
= 1;
2557 scsi_internal_device_block(sdev
);
2563 * _scsih_block_io_to_children_attached_to_ex
2564 * @ioc: per adapter object
2565 * @sas_expander: the sas_device object
2567 * This routine set sdev state to SDEV_BLOCK for all devices
2568 * attached to this expander. This function called when expander is
2572 _scsih_block_io_to_children_attached_to_ex(struct MPT2SAS_ADAPTER
*ioc
,
2573 struct _sas_node
*sas_expander
)
2575 struct _sas_port
*mpt2sas_port
;
2576 struct _sas_device
*sas_device
;
2577 struct _sas_node
*expander_sibling
;
2578 unsigned long flags
;
2583 list_for_each_entry(mpt2sas_port
,
2584 &sas_expander
->sas_port_list
, port_list
) {
2585 if (mpt2sas_port
->remote_identify
.device_type
==
2587 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2589 mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
2590 mpt2sas_port
->remote_identify
.sas_address
);
2591 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2594 _scsih_block_io_device(ioc
, sas_device
->handle
);
2598 list_for_each_entry(mpt2sas_port
,
2599 &sas_expander
->sas_port_list
, port_list
) {
2601 if (mpt2sas_port
->remote_identify
.device_type
==
2602 SAS_EDGE_EXPANDER_DEVICE
||
2603 mpt2sas_port
->remote_identify
.device_type
==
2604 SAS_FANOUT_EXPANDER_DEVICE
) {
2606 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
2608 mpt2sas_scsih_expander_find_by_sas_address(
2609 ioc
, mpt2sas_port
->remote_identify
.sas_address
);
2610 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
2611 _scsih_block_io_to_children_attached_to_ex(ioc
,
2618 * _scsih_block_io_to_children_attached_directly
2619 * @ioc: per adapter object
2620 * @event_data: topology change event data
2622 * This routine set sdev state to SDEV_BLOCK for all devices
2623 * direct attached during device pull.
2626 _scsih_block_io_to_children_attached_directly(struct MPT2SAS_ADAPTER
*ioc
,
2627 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
2634 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
2635 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
2638 phy_number
= event_data
->StartPhyNum
+ i
;
2639 reason_code
= event_data
->PHY
[i
].PhyStatus
&
2640 MPI2_EVENT_SAS_TOPO_RC_MASK
;
2641 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
)
2642 _scsih_block_io_device(ioc
, handle
);
2647 * _scsih_tm_tr_send - send task management request
2648 * @ioc: per adapter object
2649 * @handle: device handle
2650 * Context: interrupt time.
2652 * This code is to initiate the device removal handshake protocal
2653 * with controller firmware. This function will issue target reset
2654 * using high priority request queue. It will send a sas iounit
2655 * controll request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
2657 * This is designed to send muliple task management request at the same
2658 * time to the fifo. If the fifo is full, we will append the request,
2659 * and process it in a future completion.
2662 _scsih_tm_tr_send(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
2664 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
2666 struct _sas_device
*sas_device
;
2667 struct MPT2SAS_TARGET
*sas_target_priv_data
;
2668 unsigned long flags
;
2669 struct _tr_list
*delayed_tr
;
2671 if (ioc
->shost_recovery
|| ioc
->remove_host
||
2672 ioc
->pci_error_recovery
) {
2673 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host reset in "
2674 "progress!\n", __func__
, ioc
->name
));
2678 /* if PD, then return */
2679 if (test_bit(handle
, ioc
->pd_handles
))
2682 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2683 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
2684 if (sas_device
&& sas_device
->starget
&&
2685 sas_device
->starget
->hostdata
) {
2686 sas_target_priv_data
= sas_device
->starget
->hostdata
;
2687 sas_target_priv_data
->deleted
= 1;
2688 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
2689 "setting delete flag: handle(0x%04x), "
2690 "sas_addr(0x%016llx)\n", ioc
->name
, handle
,
2691 (unsigned long long) sas_device
->sas_address
));
2693 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2695 smid
= mpt2sas_base_get_smid_hpr(ioc
, ioc
->tm_tr_cb_idx
);
2697 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
2700 INIT_LIST_HEAD(&delayed_tr
->list
);
2701 delayed_tr
->handle
= handle
;
2702 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_list
);
2703 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
2704 "DELAYED:tr:handle(0x%04x), (open)\n",
2705 ioc
->name
, handle
));
2709 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"tr_send:handle(0x%04x), "
2710 "(open), smid(%d), cb(%d)\n", ioc
->name
, handle
, smid
,
2711 ioc
->tm_tr_cb_idx
));
2712 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
2713 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
2714 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
2715 mpi_request
->DevHandle
= cpu_to_le16(handle
);
2716 mpi_request
->TaskType
= MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
;
2717 mpt2sas_base_put_smid_hi_priority(ioc
, smid
);
2723 * _scsih_sas_control_complete - completion routine
2724 * @ioc: per adapter object
2725 * @smid: system request message index
2726 * @msix_index: MSIX table index supplied by the OS
2727 * @reply: reply message frame(lower 32bit addr)
2728 * Context: interrupt time.
2730 * This is the sas iounit controll completion routine.
2731 * This code is part of the code to initiate the device removal
2732 * handshake protocal with controller firmware.
2734 * Return 1 meaning mf should be freed from _base_interrupt
2735 * 0 means the mf is freed from this function.
2738 _scsih_sas_control_complete(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
,
2739 u8 msix_index
, u32 reply
)
2741 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
2742 Mpi2SasIoUnitControlReply_t
*mpi_reply
=
2743 mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
2745 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
2746 "sc_complete:handle(0x%04x), (open) "
2747 "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
2748 ioc
->name
, le16_to_cpu(mpi_reply
->DevHandle
), smid
,
2749 le16_to_cpu(mpi_reply
->IOCStatus
),
2750 le32_to_cpu(mpi_reply
->IOCLogInfo
)));
2755 * _scsih_tm_tr_volume_send - send target reset request for volumes
2756 * @ioc: per adapter object
2757 * @handle: device handle
2758 * Context: interrupt time.
2760 * This is designed to send muliple task management request at the same
2761 * time to the fifo. If the fifo is full, we will append the request,
2762 * and process it in a future completion.
2765 _scsih_tm_tr_volume_send(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
2767 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
2769 struct _tr_list
*delayed_tr
;
2771 if (ioc
->shost_recovery
|| ioc
->remove_host
||
2772 ioc
->pci_error_recovery
) {
2773 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host reset in "
2774 "progress!\n", __func__
, ioc
->name
));
2778 smid
= mpt2sas_base_get_smid_hpr(ioc
, ioc
->tm_tr_volume_cb_idx
);
2780 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
2783 INIT_LIST_HEAD(&delayed_tr
->list
);
2784 delayed_tr
->handle
= handle
;
2785 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_volume_list
);
2786 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
2787 "DELAYED:tr:handle(0x%04x), (open)\n",
2788 ioc
->name
, handle
));
2792 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"tr_send:handle(0x%04x), "
2793 "(open), smid(%d), cb(%d)\n", ioc
->name
, handle
, smid
,
2794 ioc
->tm_tr_volume_cb_idx
));
2795 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
2796 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
2797 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
2798 mpi_request
->DevHandle
= cpu_to_le16(handle
);
2799 mpi_request
->TaskType
= MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
;
2800 mpt2sas_base_put_smid_hi_priority(ioc
, smid
);
2804 * _scsih_tm_volume_tr_complete - target reset completion
2805 * @ioc: per adapter object
2806 * @smid: system request message index
2807 * @msix_index: MSIX table index supplied by the OS
2808 * @reply: reply message frame(lower 32bit addr)
2809 * Context: interrupt time.
2811 * Return 1 meaning mf should be freed from _base_interrupt
2812 * 0 means the mf is freed from this function.
2815 _scsih_tm_volume_tr_complete(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
,
2816 u8 msix_index
, u32 reply
)
2819 Mpi2SCSITaskManagementRequest_t
*mpi_request_tm
;
2820 Mpi2SCSITaskManagementReply_t
*mpi_reply
=
2821 mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
2823 if (ioc
->shost_recovery
|| ioc
->remove_host
||
2824 ioc
->pci_error_recovery
) {
2825 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host reset in "
2826 "progress!\n", __func__
, ioc
->name
));
2830 mpi_request_tm
= mpt2sas_base_get_msg_frame(ioc
, smid
);
2831 handle
= le16_to_cpu(mpi_request_tm
->DevHandle
);
2832 if (handle
!= le16_to_cpu(mpi_reply
->DevHandle
)) {
2833 dewtprintk(ioc
, printk("spurious interrupt: "
2834 "handle(0x%04x:0x%04x), smid(%d)!!!\n", handle
,
2835 le16_to_cpu(mpi_reply
->DevHandle
), smid
));
2839 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
2840 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
2841 "loginfo(0x%08x), completed(%d)\n", ioc
->name
,
2842 handle
, smid
, le16_to_cpu(mpi_reply
->IOCStatus
),
2843 le32_to_cpu(mpi_reply
->IOCLogInfo
),
2844 le32_to_cpu(mpi_reply
->TerminationCount
)));
2846 return _scsih_check_for_pending_tm(ioc
, smid
);
2850 * _scsih_tm_tr_complete -
2851 * @ioc: per adapter object
2852 * @smid: system request message index
2853 * @msix_index: MSIX table index supplied by the OS
2854 * @reply: reply message frame(lower 32bit addr)
2855 * Context: interrupt time.
2857 * This is the target reset completion routine.
2858 * This code is part of the code to initiate the device removal
2859 * handshake protocal with controller firmware.
2860 * It will send a sas iounit controll request (MPI2_SAS_OP_REMOVE_DEVICE)
2862 * Return 1 meaning mf should be freed from _base_interrupt
2863 * 0 means the mf is freed from this function.
2866 _scsih_tm_tr_complete(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
,
2870 Mpi2SCSITaskManagementRequest_t
*mpi_request_tm
;
2871 Mpi2SCSITaskManagementReply_t
*mpi_reply
=
2872 mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
2873 Mpi2SasIoUnitControlRequest_t
*mpi_request
;
2876 if (ioc
->shost_recovery
|| ioc
->remove_host
||
2877 ioc
->pci_error_recovery
) {
2878 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host reset in "
2879 "progress!\n", __func__
, ioc
->name
));
2883 mpi_request_tm
= mpt2sas_base_get_msg_frame(ioc
, smid
);
2884 handle
= le16_to_cpu(mpi_request_tm
->DevHandle
);
2885 if (handle
!= le16_to_cpu(mpi_reply
->DevHandle
)) {
2886 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"spurious interrupt: "
2887 "handle(0x%04x:0x%04x), smid(%d)!!!\n", ioc
->name
, handle
,
2888 le16_to_cpu(mpi_reply
->DevHandle
), smid
));
2892 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
2893 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
2894 "loginfo(0x%08x), completed(%d)\n", ioc
->name
,
2895 handle
, smid
, le16_to_cpu(mpi_reply
->IOCStatus
),
2896 le32_to_cpu(mpi_reply
->IOCLogInfo
),
2897 le32_to_cpu(mpi_reply
->TerminationCount
)));
2899 smid_sas_ctrl
= mpt2sas_base_get_smid(ioc
, ioc
->tm_sas_control_cb_idx
);
2900 if (!smid_sas_ctrl
) {
2901 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
2902 ioc
->name
, __func__
);
2906 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"sc_send:handle(0x%04x), "
2907 "(open), smid(%d), cb(%d)\n", ioc
->name
, handle
, smid_sas_ctrl
,
2908 ioc
->tm_sas_control_cb_idx
));
2909 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid_sas_ctrl
);
2910 memset(mpi_request
, 0, sizeof(Mpi2SasIoUnitControlRequest_t
));
2911 mpi_request
->Function
= MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
;
2912 mpi_request
->Operation
= MPI2_SAS_OP_REMOVE_DEVICE
;
2913 mpi_request
->DevHandle
= mpi_request_tm
->DevHandle
;
2914 mpt2sas_base_put_smid_default(ioc
, smid_sas_ctrl
);
2916 return _scsih_check_for_pending_tm(ioc
, smid
);
2920 * _scsih_check_for_pending_tm - check for pending task management
2921 * @ioc: per adapter object
2922 * @smid: system request message index
2924 * This will check delayed target reset list, and feed the
2927 * Return 1 meaning mf should be freed from _base_interrupt
2928 * 0 means the mf is freed from this function.
2931 _scsih_check_for_pending_tm(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
2933 struct _tr_list
*delayed_tr
;
2935 if (!list_empty(&ioc
->delayed_tr_volume_list
)) {
2936 delayed_tr
= list_entry(ioc
->delayed_tr_volume_list
.next
,
2937 struct _tr_list
, list
);
2938 mpt2sas_base_free_smid(ioc
, smid
);
2939 _scsih_tm_tr_volume_send(ioc
, delayed_tr
->handle
);
2940 list_del(&delayed_tr
->list
);
2945 if (!list_empty(&ioc
->delayed_tr_list
)) {
2946 delayed_tr
= list_entry(ioc
->delayed_tr_list
.next
,
2947 struct _tr_list
, list
);
2948 mpt2sas_base_free_smid(ioc
, smid
);
2949 _scsih_tm_tr_send(ioc
, delayed_tr
->handle
);
2950 list_del(&delayed_tr
->list
);
2959 * _scsih_check_topo_delete_events - sanity check on topo events
2960 * @ioc: per adapter object
2961 * @event_data: the event data payload
2963 * This routine added to better handle cable breaker.
2965 * This handles the case where driver recieves multiple expander
2966 * add and delete events in a single shot. When there is a delete event
2967 * the routine will void any pending add events waiting in the event queue.
2972 _scsih_check_topo_delete_events(struct MPT2SAS_ADAPTER
*ioc
,
2973 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
2975 struct fw_event_work
*fw_event
;
2976 Mpi2EventDataSasTopologyChangeList_t
*local_event_data
;
2977 u16 expander_handle
;
2978 struct _sas_node
*sas_expander
;
2979 unsigned long flags
;
2983 for (i
= 0 ; i
< event_data
->NumEntries
; i
++) {
2984 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
2987 reason_code
= event_data
->PHY
[i
].PhyStatus
&
2988 MPI2_EVENT_SAS_TOPO_RC_MASK
;
2989 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
)
2990 _scsih_tm_tr_send(ioc
, handle
);
2993 expander_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
2994 if (expander_handle
< ioc
->sas_hba
.num_phys
) {
2995 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
2999 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
3000 || event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
) {
3001 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
3002 sas_expander
= mpt2sas_scsih_expander_find_by_handle(ioc
,
3004 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
3005 _scsih_block_io_to_children_attached_to_ex(ioc
, sas_expander
);
3006 } else if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_RESPONDING
)
3007 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
3009 if (event_data
->ExpStatus
!= MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
)
3012 /* mark ignore flag for pending events */
3013 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
3014 list_for_each_entry(fw_event
, &ioc
->fw_event_list
, list
) {
3015 if (fw_event
->event
!= MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
||
3018 local_event_data
= fw_event
->event_data
;
3019 if (local_event_data
->ExpStatus
==
3020 MPI2_EVENT_SAS_TOPO_ES_ADDED
||
3021 local_event_data
->ExpStatus
==
3022 MPI2_EVENT_SAS_TOPO_ES_RESPONDING
) {
3023 if (le16_to_cpu(local_event_data
->ExpanderDevHandle
) ==
3025 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3026 "setting ignoring flag\n", ioc
->name
));
3027 fw_event
->ignore
= 1;
3031 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
3035 * _scsih_set_volume_delete_flag - setting volume delete flag
3036 * @ioc: per adapter object
3037 * @handle: device handle
3043 _scsih_set_volume_delete_flag(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
3045 struct _raid_device
*raid_device
;
3046 struct MPT2SAS_TARGET
*sas_target_priv_data
;
3047 unsigned long flags
;
3049 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
3050 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
3051 if (raid_device
&& raid_device
->starget
&&
3052 raid_device
->starget
->hostdata
) {
3053 sas_target_priv_data
=
3054 raid_device
->starget
->hostdata
;
3055 sas_target_priv_data
->deleted
= 1;
3056 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3057 "setting delete flag: handle(0x%04x), "
3058 "wwid(0x%016llx)\n", ioc
->name
, handle
,
3059 (unsigned long long) raid_device
->wwid
));
3061 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
3065 * _scsih_set_volume_handle_for_tr - set handle for target reset to volume
3066 * @handle: input handle
3067 * @a: handle for volume a
3068 * @b: handle for volume b
3070 * IR firmware only supports two raid volumes. The purpose of this
3071 * routine is to set the volume handle in either a or b. When the given
3072 * input handle is non-zero, or when a and b have not been set before.
3075 _scsih_set_volume_handle_for_tr(u16 handle
, u16
*a
, u16
*b
)
3077 if (!handle
|| handle
== *a
|| handle
== *b
)
3086 * _scsih_check_ir_config_unhide_events - check for UNHIDE events
3087 * @ioc: per adapter object
3088 * @event_data: the event data payload
3089 * Context: interrupt time.
3091 * This routine will send target reset to volume, followed by target
3092 * resets to the PDs. This is called when a PD has been removed, or
3093 * volume has been deleted or removed. When the target reset is sent
3094 * to volume, the PD target resets need to be queued to start upon
3095 * completion of the volume target reset.
3100 _scsih_check_ir_config_unhide_events(struct MPT2SAS_ADAPTER
*ioc
,
3101 Mpi2EventDataIrConfigChangeList_t
*event_data
)
3103 Mpi2EventIrConfigElement_t
*element
;
3105 u16 handle
, volume_handle
, a
, b
;
3106 struct _tr_list
*delayed_tr
;
3111 /* Volume Resets for Deleted or Removed */
3112 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
3113 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
3114 if (element
->ReasonCode
==
3115 MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
||
3116 element
->ReasonCode
==
3117 MPI2_EVENT_IR_CHANGE_RC_REMOVED
) {
3118 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
3119 _scsih_set_volume_delete_flag(ioc
, volume_handle
);
3120 _scsih_set_volume_handle_for_tr(volume_handle
, &a
, &b
);
3124 /* Volume Resets for UNHIDE events */
3125 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
3126 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
3127 if (le32_to_cpu(event_data
->Flags
) &
3128 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
)
3130 if (element
->ReasonCode
== MPI2_EVENT_IR_CHANGE_RC_UNHIDE
) {
3131 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
3132 _scsih_set_volume_handle_for_tr(volume_handle
, &a
, &b
);
3137 _scsih_tm_tr_volume_send(ioc
, a
);
3139 _scsih_tm_tr_volume_send(ioc
, b
);
3141 /* PD target resets */
3142 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
3143 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
3144 if (element
->ReasonCode
!= MPI2_EVENT_IR_CHANGE_RC_UNHIDE
)
3146 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
3147 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
3148 clear_bit(handle
, ioc
->pd_handles
);
3150 _scsih_tm_tr_send(ioc
, handle
);
3151 else if (volume_handle
== a
|| volume_handle
== b
) {
3152 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
3153 BUG_ON(!delayed_tr
);
3154 INIT_LIST_HEAD(&delayed_tr
->list
);
3155 delayed_tr
->handle
= handle
;
3156 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_list
);
3157 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3158 "DELAYED:tr:handle(0x%04x), (open)\n", ioc
->name
,
3161 _scsih_tm_tr_send(ioc
, handle
);
3167 * _scsih_check_volume_delete_events - set delete flag for volumes
3168 * @ioc: per adapter object
3169 * @event_data: the event data payload
3170 * Context: interrupt time.
3172 * This will handle the case when the cable connected to entire volume is
3173 * pulled. We will take care of setting the deleted flag so normal IO will
3179 _scsih_check_volume_delete_events(struct MPT2SAS_ADAPTER
*ioc
,
3180 Mpi2EventDataIrVolume_t
*event_data
)
3184 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED
)
3186 state
= le32_to_cpu(event_data
->NewValue
);
3187 if (state
== MPI2_RAID_VOL_STATE_MISSING
|| state
==
3188 MPI2_RAID_VOL_STATE_FAILED
)
3189 _scsih_set_volume_delete_flag(ioc
,
3190 le16_to_cpu(event_data
->VolDevHandle
));
3194 * _scsih_flush_running_cmds - completing outstanding commands.
3195 * @ioc: per adapter object
3197 * The flushing out of all pending scmd commands following host reset,
3198 * where all IO is dropped to the floor.
3203 _scsih_flush_running_cmds(struct MPT2SAS_ADAPTER
*ioc
)
3205 struct scsi_cmnd
*scmd
;
3209 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
3210 scmd
= _scsih_scsi_lookup_get(ioc
, smid
);
3214 mpt2sas_base_free_smid(ioc
, smid
);
3215 scsi_dma_unmap(scmd
);
3216 if (ioc
->pci_error_recovery
)
3217 scmd
->result
= DID_NO_CONNECT
<< 16;
3219 scmd
->result
= DID_RESET
<< 16;
3220 scmd
->scsi_done(scmd
);
3222 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"completing %d cmds\n",
3227 * _scsih_setup_eedp - setup MPI request for EEDP transfer
3228 * @scmd: pointer to scsi command object
3229 * @mpi_request: pointer to the SCSI_IO reqest message frame
3231 * Supporting protection 1 and 3.
3236 _scsih_setup_eedp(struct scsi_cmnd
*scmd
, Mpi2SCSIIORequest_t
*mpi_request
)
3239 unsigned char prot_op
= scsi_get_prot_op(scmd
);
3240 unsigned char prot_type
= scsi_get_prot_type(scmd
);
3242 if (prot_type
== SCSI_PROT_DIF_TYPE0
|| prot_op
== SCSI_PROT_NORMAL
)
3245 if (prot_op
== SCSI_PROT_READ_STRIP
)
3246 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP
;
3247 else if (prot_op
== SCSI_PROT_WRITE_INSERT
)
3248 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_INSERT_OP
;
3252 switch (prot_type
) {
3253 case SCSI_PROT_DIF_TYPE1
:
3256 * enable ref/guard checking
3257 * auto increment ref tag
3259 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG
|
3260 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG
|
3261 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
3262 mpi_request
->CDB
.EEDP32
.PrimaryReferenceTag
=
3263 cpu_to_be32(scsi_get_lba(scmd
));
3266 case SCSI_PROT_DIF_TYPE2
:
3268 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG
|
3269 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG
|
3270 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
3273 case SCSI_PROT_DIF_TYPE3
:
3276 * enable guard checking
3278 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
3281 mpi_request
->EEDPBlockSize
= cpu_to_le32(scmd
->device
->sector_size
);
3282 mpi_request
->EEDPFlags
= cpu_to_le16(eedp_flags
);
3286 * _scsih_eedp_error_handling - return sense code for EEDP errors
3287 * @scmd: pointer to scsi command object
3288 * @ioc_status: ioc status
3293 _scsih_eedp_error_handling(struct scsi_cmnd
*scmd
, u16 ioc_status
)
3299 switch (ioc_status
) {
3300 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
3303 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
3306 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
3314 if (scmd
->sc_data_direction
== DMA_TO_DEVICE
) {
3315 sk
= ILLEGAL_REQUEST
;
3316 host_byte
= DID_ABORT
;
3318 sk
= ABORTED_COMMAND
;
3322 scsi_build_sense_buffer(0, scmd
->sense_buffer
, sk
, 0x10, ascq
);
3323 scmd
->result
= DRIVER_SENSE
<< 24 | (host_byte
<< 16) |
3324 SAM_STAT_CHECK_CONDITION
;
3328 * _scsih_qcmd - main scsi request entry point
3329 * @scmd: pointer to scsi command object
3330 * @done: function pointer to be invoked on completion
3332 * The callback index is set inside `ioc->scsi_io_cb_idx`.
3334 * Returns 0 on success. If there's a failure, return either:
3335 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
3336 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
3339 _scsih_qcmd_lck(struct scsi_cmnd
*scmd
, void (*done
)(struct scsi_cmnd
*))
3341 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
3342 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
3343 struct MPT2SAS_TARGET
*sas_target_priv_data
;
3344 Mpi2SCSIIORequest_t
*mpi_request
;
3348 scmd
->scsi_done
= done
;
3349 sas_device_priv_data
= scmd
->device
->hostdata
;
3350 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
3351 scmd
->result
= DID_NO_CONNECT
<< 16;
3352 scmd
->scsi_done(scmd
);
3356 if (ioc
->pci_error_recovery
) {
3357 scmd
->result
= DID_NO_CONNECT
<< 16;
3358 scmd
->scsi_done(scmd
);
3362 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
3363 /* invalid device handle */
3364 if (sas_target_priv_data
->handle
== MPT2SAS_INVALID_DEVICE_HANDLE
) {
3365 scmd
->result
= DID_NO_CONNECT
<< 16;
3366 scmd
->scsi_done(scmd
);
3370 /* host recovery or link resets sent via IOCTLs */
3371 if (ioc
->shost_recovery
|| ioc
->ioc_link_reset_in_progress
)
3372 return SCSI_MLQUEUE_HOST_BUSY
;
3373 /* device busy with task management */
3374 else if (sas_device_priv_data
->block
|| sas_target_priv_data
->tm_busy
)
3375 return SCSI_MLQUEUE_DEVICE_BUSY
;
3376 /* device has been deleted */
3377 else if (sas_target_priv_data
->deleted
) {
3378 scmd
->result
= DID_NO_CONNECT
<< 16;
3379 scmd
->scsi_done(scmd
);
3383 if (scmd
->sc_data_direction
== DMA_FROM_DEVICE
)
3384 mpi_control
= MPI2_SCSIIO_CONTROL_READ
;
3385 else if (scmd
->sc_data_direction
== DMA_TO_DEVICE
)
3386 mpi_control
= MPI2_SCSIIO_CONTROL_WRITE
;
3388 mpi_control
= MPI2_SCSIIO_CONTROL_NODATATRANSFER
;
3391 if (!(sas_device_priv_data
->flags
& MPT_DEVICE_FLAGS_INIT
)) {
3392 if (scmd
->device
->tagged_supported
) {
3393 if (scmd
->device
->ordered_tags
)
3394 mpi_control
|= MPI2_SCSIIO_CONTROL_ORDEREDQ
;
3396 mpi_control
|= MPI2_SCSIIO_CONTROL_SIMPLEQ
;
3398 /* MPI Revision I (UNIT = 0xA) - removed MPI2_SCSIIO_CONTROL_UNTAGGED */
3399 /* mpi_control |= MPI2_SCSIIO_CONTROL_UNTAGGED;
3401 mpi_control
|= (0x500);
3404 mpi_control
|= MPI2_SCSIIO_CONTROL_SIMPLEQ
;
3405 /* Make sure Device is not raid volume */
3406 if (!_scsih_is_raid(&scmd
->device
->sdev_gendev
) &&
3407 sas_is_tlr_enabled(scmd
->device
) && scmd
->cmd_len
!= 32)
3408 mpi_control
|= MPI2_SCSIIO_CONTROL_TLR_ON
;
3410 smid
= mpt2sas_base_get_smid_scsiio(ioc
, ioc
->scsi_io_cb_idx
, scmd
);
3412 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
3413 ioc
->name
, __func__
);
3416 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3417 memset(mpi_request
, 0, sizeof(Mpi2SCSIIORequest_t
));
3418 _scsih_setup_eedp(scmd
, mpi_request
);
3419 if (scmd
->cmd_len
== 32)
3420 mpi_control
|= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT
;
3421 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
3422 if (sas_device_priv_data
->sas_target
->flags
&
3423 MPT_TARGET_FLAGS_RAID_COMPONENT
)
3424 mpi_request
->Function
= MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
;
3426 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
3427 mpi_request
->DevHandle
=
3428 cpu_to_le16(sas_device_priv_data
->sas_target
->handle
);
3429 mpi_request
->DataLength
= cpu_to_le32(scsi_bufflen(scmd
));
3430 mpi_request
->Control
= cpu_to_le32(mpi_control
);
3431 mpi_request
->IoFlags
= cpu_to_le16(scmd
->cmd_len
);
3432 mpi_request
->MsgFlags
= MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR
;
3433 mpi_request
->SenseBufferLength
= SCSI_SENSE_BUFFERSIZE
;
3434 mpi_request
->SenseBufferLowAddress
=
3435 mpt2sas_base_get_sense_buffer_dma(ioc
, smid
);
3436 mpi_request
->SGLOffset0
= offsetof(Mpi2SCSIIORequest_t
, SGL
) / 4;
3437 mpi_request
->SGLFlags
= cpu_to_le16(MPI2_SCSIIO_SGLFLAGS_TYPE_MPI
+
3438 MPI2_SCSIIO_SGLFLAGS_SYSTEM_ADDR
);
3439 mpi_request
->VF_ID
= 0; /* TODO */
3440 mpi_request
->VP_ID
= 0;
3441 int_to_scsilun(sas_device_priv_data
->lun
, (struct scsi_lun
*)
3443 memcpy(mpi_request
->CDB
.CDB32
, scmd
->cmnd
, scmd
->cmd_len
);
3445 if (!mpi_request
->DataLength
) {
3446 mpt2sas_base_build_zero_len_sge(ioc
, &mpi_request
->SGL
);
3448 if (_scsih_build_scatter_gather(ioc
, scmd
, smid
)) {
3449 mpt2sas_base_free_smid(ioc
, smid
);
3454 if (likely(mpi_request
->Function
== MPI2_FUNCTION_SCSI_IO_REQUEST
))
3455 mpt2sas_base_put_smid_scsi_io(ioc
, smid
,
3456 sas_device_priv_data
->sas_target
->handle
);
3458 mpt2sas_base_put_smid_default(ioc
, smid
);
3462 return SCSI_MLQUEUE_HOST_BUSY
;
3465 static DEF_SCSI_QCMD(_scsih_qcmd
)
3468 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
3469 * @sense_buffer: sense data returned by target
3470 * @data: normalized skey/asc/ascq
3475 _scsih_normalize_sense(char *sense_buffer
, struct sense_info
*data
)
3477 if ((sense_buffer
[0] & 0x7F) >= 0x72) {
3478 /* descriptor format */
3479 data
->skey
= sense_buffer
[1] & 0x0F;
3480 data
->asc
= sense_buffer
[2];
3481 data
->ascq
= sense_buffer
[3];
3484 data
->skey
= sense_buffer
[2] & 0x0F;
3485 data
->asc
= sense_buffer
[12];
3486 data
->ascq
= sense_buffer
[13];
3490 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3492 * _scsih_scsi_ioc_info - translated non-successfull SCSI_IO request
3493 * @ioc: per adapter object
3494 * @scmd: pointer to scsi command object
3495 * @mpi_reply: reply mf payload returned from firmware
3497 * scsi_status - SCSI Status code returned from target device
3498 * scsi_state - state info associated with SCSI_IO determined by ioc
3499 * ioc_status - ioc supplied status info
3504 _scsih_scsi_ioc_info(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
,
3505 Mpi2SCSIIOReply_t
*mpi_reply
, u16 smid
)
3509 u16 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) &
3510 MPI2_IOCSTATUS_MASK
;
3511 u8 scsi_state
= mpi_reply
->SCSIState
;
3512 u8 scsi_status
= mpi_reply
->SCSIStatus
;
3513 char *desc_ioc_state
= NULL
;
3514 char *desc_scsi_status
= NULL
;
3515 char *desc_scsi_state
= ioc
->tmp_string
;
3516 u32 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
3517 struct _sas_device
*sas_device
= NULL
;
3518 unsigned long flags
;
3519 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
3520 struct MPT2SAS_TARGET
*priv_target
= starget
->hostdata
;
3525 if (log_info
== 0x31170000)
3528 switch (ioc_status
) {
3529 case MPI2_IOCSTATUS_SUCCESS
:
3530 desc_ioc_state
= "success";
3532 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
3533 desc_ioc_state
= "invalid function";
3535 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
3536 desc_ioc_state
= "scsi recovered error";
3538 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE
:
3539 desc_ioc_state
= "scsi invalid dev handle";
3541 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
3542 desc_ioc_state
= "scsi device not there";
3544 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
3545 desc_ioc_state
= "scsi data overrun";
3547 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
3548 desc_ioc_state
= "scsi data underrun";
3550 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
3551 desc_ioc_state
= "scsi io data error";
3553 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
3554 desc_ioc_state
= "scsi protocol error";
3556 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
3557 desc_ioc_state
= "scsi task terminated";
3559 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
3560 desc_ioc_state
= "scsi residual mismatch";
3562 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
3563 desc_ioc_state
= "scsi task mgmt failed";
3565 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
3566 desc_ioc_state
= "scsi ioc terminated";
3568 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
3569 desc_ioc_state
= "scsi ext terminated";
3571 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
3572 desc_ioc_state
= "eedp guard error";
3574 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
3575 desc_ioc_state
= "eedp ref tag error";
3577 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
3578 desc_ioc_state
= "eedp app tag error";
3581 desc_ioc_state
= "unknown";
3585 switch (scsi_status
) {
3586 case MPI2_SCSI_STATUS_GOOD
:
3587 desc_scsi_status
= "good";
3589 case MPI2_SCSI_STATUS_CHECK_CONDITION
:
3590 desc_scsi_status
= "check condition";
3592 case MPI2_SCSI_STATUS_CONDITION_MET
:
3593 desc_scsi_status
= "condition met";
3595 case MPI2_SCSI_STATUS_BUSY
:
3596 desc_scsi_status
= "busy";
3598 case MPI2_SCSI_STATUS_INTERMEDIATE
:
3599 desc_scsi_status
= "intermediate";
3601 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET
:
3602 desc_scsi_status
= "intermediate condmet";
3604 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT
:
3605 desc_scsi_status
= "reservation conflict";
3607 case MPI2_SCSI_STATUS_COMMAND_TERMINATED
:
3608 desc_scsi_status
= "command terminated";
3610 case MPI2_SCSI_STATUS_TASK_SET_FULL
:
3611 desc_scsi_status
= "task set full";
3613 case MPI2_SCSI_STATUS_ACA_ACTIVE
:
3614 desc_scsi_status
= "aca active";
3616 case MPI2_SCSI_STATUS_TASK_ABORTED
:
3617 desc_scsi_status
= "task aborted";
3620 desc_scsi_status
= "unknown";
3624 desc_scsi_state
[0] = '\0';
3626 desc_scsi_state
= " ";
3627 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
3628 strcat(desc_scsi_state
, "response info ");
3629 if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
3630 strcat(desc_scsi_state
, "state terminated ");
3631 if (scsi_state
& MPI2_SCSI_STATE_NO_SCSI_STATUS
)
3632 strcat(desc_scsi_state
, "no status ");
3633 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_FAILED
)
3634 strcat(desc_scsi_state
, "autosense failed ");
3635 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
)
3636 strcat(desc_scsi_state
, "autosense valid ");
3638 scsi_print_command(scmd
);
3640 if (priv_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
3641 printk(MPT2SAS_WARN_FMT
"\tvolume wwid(0x%016llx)\n", ioc
->name
,
3642 (unsigned long long)priv_target
->sas_address
);
3644 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
3645 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
3646 priv_target
->sas_address
);
3648 printk(MPT2SAS_WARN_FMT
"\tsas_address(0x%016llx), "
3649 "phy(%d)\n", ioc
->name
, sas_device
->sas_address
,
3651 printk(MPT2SAS_WARN_FMT
3652 "\tenclosure_logical_id(0x%016llx), slot(%d)\n",
3653 ioc
->name
, sas_device
->enclosure_logical_id
,
3656 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3659 printk(MPT2SAS_WARN_FMT
"\thandle(0x%04x), ioc_status(%s)(0x%04x), "
3660 "smid(%d)\n", ioc
->name
, le16_to_cpu(mpi_reply
->DevHandle
),
3661 desc_ioc_state
, ioc_status
, smid
);
3662 printk(MPT2SAS_WARN_FMT
"\trequest_len(%d), underflow(%d), "
3663 "resid(%d)\n", ioc
->name
, scsi_bufflen(scmd
), scmd
->underflow
,
3664 scsi_get_resid(scmd
));
3665 printk(MPT2SAS_WARN_FMT
"\ttag(%d), transfer_count(%d), "
3666 "sc->result(0x%08x)\n", ioc
->name
, le16_to_cpu(mpi_reply
->TaskTag
),
3667 le32_to_cpu(mpi_reply
->TransferCount
), scmd
->result
);
3668 printk(MPT2SAS_WARN_FMT
"\tscsi_status(%s)(0x%02x), "
3669 "scsi_state(%s)(0x%02x)\n", ioc
->name
, desc_scsi_status
,
3670 scsi_status
, desc_scsi_state
, scsi_state
);
3672 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
3673 struct sense_info data
;
3674 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
3675 printk(MPT2SAS_WARN_FMT
"\t[sense_key,asc,ascq]: "
3676 "[0x%02x,0x%02x,0x%02x], count(%d)\n", ioc
->name
, data
.skey
,
3677 data
.asc
, data
.ascq
, le32_to_cpu(mpi_reply
->SenseCount
));
3680 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
) {
3681 response_info
= le32_to_cpu(mpi_reply
->ResponseInfo
);
3682 response_bytes
= (u8
*)&response_info
;
3683 _scsih_response_code(ioc
, response_bytes
[0]);
3689 * _scsih_smart_predicted_fault - illuminate Fault LED
3690 * @ioc: per adapter object
3691 * @handle: device handle
3696 _scsih_smart_predicted_fault(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
3698 Mpi2SepReply_t mpi_reply
;
3699 Mpi2SepRequest_t mpi_request
;
3700 struct scsi_target
*starget
;
3701 struct MPT2SAS_TARGET
*sas_target_priv_data
;
3702 Mpi2EventNotificationReply_t
*event_reply
;
3703 Mpi2EventDataSasDeviceStatusChange_t
*event_data
;
3704 struct _sas_device
*sas_device
;
3706 unsigned long flags
;
3708 /* only handle non-raid devices */
3709 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
3710 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
3712 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3715 starget
= sas_device
->starget
;
3716 sas_target_priv_data
= starget
->hostdata
;
3718 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
) ||
3719 ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
))) {
3720 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3723 starget_printk(KERN_WARNING
, starget
, "predicted fault\n");
3724 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3726 if (ioc
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_IBM
) {
3727 memset(&mpi_request
, 0, sizeof(Mpi2SepRequest_t
));
3728 mpi_request
.Function
= MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR
;
3729 mpi_request
.Action
= MPI2_SEP_REQ_ACTION_WRITE_STATUS
;
3730 mpi_request
.SlotStatus
=
3731 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT
);
3732 mpi_request
.DevHandle
= cpu_to_le16(handle
);
3733 mpi_request
.Flags
= MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS
;
3734 if ((mpt2sas_base_scsi_enclosure_processor(ioc
, &mpi_reply
,
3735 &mpi_request
)) != 0) {
3736 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3737 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3741 if (mpi_reply
.IOCStatus
|| mpi_reply
.IOCLogInfo
) {
3742 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3743 "enclosure_processor: ioc_status (0x%04x), "
3744 "loginfo(0x%08x)\n", ioc
->name
,
3745 le16_to_cpu(mpi_reply
.IOCStatus
),
3746 le32_to_cpu(mpi_reply
.IOCLogInfo
)));
3751 /* insert into event log */
3752 sz
= offsetof(Mpi2EventNotificationReply_t
, EventData
) +
3753 sizeof(Mpi2EventDataSasDeviceStatusChange_t
);
3754 event_reply
= kzalloc(sz
, GFP_KERNEL
);
3756 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3757 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3761 event_reply
->Function
= MPI2_FUNCTION_EVENT_NOTIFICATION
;
3762 event_reply
->Event
=
3763 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
);
3764 event_reply
->MsgLength
= sz
/4;
3765 event_reply
->EventDataLength
=
3766 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t
)/4);
3767 event_data
= (Mpi2EventDataSasDeviceStatusChange_t
*)
3768 event_reply
->EventData
;
3769 event_data
->ReasonCode
= MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
;
3770 event_data
->ASC
= 0x5D;
3771 event_data
->DevHandle
= cpu_to_le16(handle
);
3772 event_data
->SASAddress
= cpu_to_le64(sas_target_priv_data
->sas_address
);
3773 mpt2sas_ctl_add_to_event_log(ioc
, event_reply
);
3778 * _scsih_io_done - scsi request callback
3779 * @ioc: per adapter object
3780 * @smid: system request message index
3781 * @msix_index: MSIX table index supplied by the OS
3782 * @reply: reply message frame(lower 32bit addr)
3784 * Callback handler when using _scsih_qcmd.
3786 * Return 1 meaning mf should be freed from _base_interrupt
3787 * 0 means the mf is freed from this function.
3790 _scsih_io_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
3792 Mpi2SCSIIORequest_t
*mpi_request
;
3793 Mpi2SCSIIOReply_t
*mpi_reply
;
3794 struct scsi_cmnd
*scmd
;
3800 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
3801 u32 response_code
= 0;
3803 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
3804 scmd
= _scsih_scsi_lookup_get(ioc
, smid
);
3808 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3810 if (mpi_reply
== NULL
) {
3811 scmd
->result
= DID_OK
<< 16;
3815 sas_device_priv_data
= scmd
->device
->hostdata
;
3816 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
||
3817 sas_device_priv_data
->sas_target
->deleted
) {
3818 scmd
->result
= DID_NO_CONNECT
<< 16;
3822 /* turning off TLR */
3823 scsi_state
= mpi_reply
->SCSIState
;
3824 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
3826 le32_to_cpu(mpi_reply
->ResponseInfo
) & 0xFF;
3827 if (!sas_device_priv_data
->tlr_snoop_check
) {
3828 sas_device_priv_data
->tlr_snoop_check
++;
3829 if (!_scsih_is_raid(&scmd
->device
->sdev_gendev
) &&
3830 sas_is_tlr_enabled(scmd
->device
) &&
3831 response_code
== MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
) {
3832 sas_disable_tlr(scmd
->device
);
3833 sdev_printk(KERN_INFO
, scmd
->device
, "TLR disabled\n");
3837 xfer_cnt
= le32_to_cpu(mpi_reply
->TransferCount
);
3838 scsi_set_resid(scmd
, scsi_bufflen(scmd
) - xfer_cnt
);
3839 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
);
3840 if (ioc_status
& MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE
)
3841 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
3844 ioc_status
&= MPI2_IOCSTATUS_MASK
;
3845 scsi_status
= mpi_reply
->SCSIStatus
;
3847 if (ioc_status
== MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
&& xfer_cnt
== 0 &&
3848 (scsi_status
== MPI2_SCSI_STATUS_BUSY
||
3849 scsi_status
== MPI2_SCSI_STATUS_RESERVATION_CONFLICT
||
3850 scsi_status
== MPI2_SCSI_STATUS_TASK_SET_FULL
)) {
3851 ioc_status
= MPI2_IOCSTATUS_SUCCESS
;
3854 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
3855 struct sense_info data
;
3856 const void *sense_data
= mpt2sas_base_get_sense_buffer(ioc
,
3858 u32 sz
= min_t(u32
, SCSI_SENSE_BUFFERSIZE
,
3859 le32_to_cpu(mpi_reply
->SenseCount
));
3860 memcpy(scmd
->sense_buffer
, sense_data
, sz
);
3861 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
3862 /* failure prediction threshold exceeded */
3863 if (data
.asc
== 0x5D)
3864 _scsih_smart_predicted_fault(ioc
,
3865 le16_to_cpu(mpi_reply
->DevHandle
));
3868 switch (ioc_status
) {
3869 case MPI2_IOCSTATUS_BUSY
:
3870 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES
:
3871 scmd
->result
= SAM_STAT_BUSY
;
3874 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
3875 scmd
->result
= DID_NO_CONNECT
<< 16;
3878 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
3879 if (sas_device_priv_data
->block
) {
3880 scmd
->result
= DID_TRANSPORT_DISRUPTED
<< 16;
3883 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
3884 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
3885 scmd
->result
= DID_RESET
<< 16;
3888 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
3889 if ((xfer_cnt
== 0) || (scmd
->underflow
> xfer_cnt
))
3890 scmd
->result
= DID_SOFT_ERROR
<< 16;
3892 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
3895 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
3896 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
3898 if ((scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
))
3901 if (xfer_cnt
< scmd
->underflow
) {
3902 if (scsi_status
== SAM_STAT_BUSY
)
3903 scmd
->result
= SAM_STAT_BUSY
;
3905 scmd
->result
= DID_SOFT_ERROR
<< 16;
3906 } else if (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
3907 MPI2_SCSI_STATE_NO_SCSI_STATUS
))
3908 scmd
->result
= DID_SOFT_ERROR
<< 16;
3909 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
3910 scmd
->result
= DID_RESET
<< 16;
3911 else if (!xfer_cnt
&& scmd
->cmnd
[0] == REPORT_LUNS
) {
3912 mpi_reply
->SCSIState
= MPI2_SCSI_STATE_AUTOSENSE_VALID
;
3913 mpi_reply
->SCSIStatus
= SAM_STAT_CHECK_CONDITION
;
3914 scmd
->result
= (DRIVER_SENSE
<< 24) |
3915 SAM_STAT_CHECK_CONDITION
;
3916 scmd
->sense_buffer
[0] = 0x70;
3917 scmd
->sense_buffer
[2] = ILLEGAL_REQUEST
;
3918 scmd
->sense_buffer
[12] = 0x20;
3919 scmd
->sense_buffer
[13] = 0;
3923 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
3924 scsi_set_resid(scmd
, 0);
3925 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
3926 case MPI2_IOCSTATUS_SUCCESS
:
3927 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
3928 if (response_code
==
3929 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
||
3930 (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
3931 MPI2_SCSI_STATE_NO_SCSI_STATUS
)))
3932 scmd
->result
= DID_SOFT_ERROR
<< 16;
3933 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
3934 scmd
->result
= DID_RESET
<< 16;
3937 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
3938 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
3939 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
3940 _scsih_eedp_error_handling(scmd
, ioc_status
);
3942 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
3943 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
3944 case MPI2_IOCSTATUS_INVALID_SGL
:
3945 case MPI2_IOCSTATUS_INTERNAL_ERROR
:
3946 case MPI2_IOCSTATUS_INVALID_FIELD
:
3947 case MPI2_IOCSTATUS_INVALID_STATE
:
3948 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
3949 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
3951 scmd
->result
= DID_SOFT_ERROR
<< 16;
3956 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3957 if (scmd
->result
&& (ioc
->logging_level
& MPT_DEBUG_REPLY
))
3958 _scsih_scsi_ioc_info(ioc
, scmd
, mpi_reply
, smid
);
3962 scsi_dma_unmap(scmd
);
3963 scmd
->scsi_done(scmd
);
3968 * _scsih_sas_host_refresh - refreshing sas host object contents
3969 * @ioc: per adapter object
3972 * During port enable, fw will send topology events for every device. Its
3973 * possible that the handles may change from the previous setting, so this
3974 * code keeping handles updating if changed.
3979 _scsih_sas_host_refresh(struct MPT2SAS_ADAPTER
*ioc
)
3984 Mpi2ConfigReply_t mpi_reply
;
3985 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
3986 u16 attached_handle
;
3989 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
3990 "updating handles for sas_host(0x%016llx)\n",
3991 ioc
->name
, (unsigned long long)ioc
->sas_hba
.sas_address
));
3993 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
3994 * sizeof(Mpi2SasIOUnit0PhyData_t
));
3995 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
3996 if (!sas_iounit_pg0
) {
3997 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3998 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4002 if ((mpt2sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
4003 sas_iounit_pg0
, sz
)) != 0)
4005 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
4006 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
4008 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
4009 link_rate
= sas_iounit_pg0
->PhyData
[i
].NegotiatedLinkRate
>> 4;
4011 ioc
->sas_hba
.handle
= le16_to_cpu(sas_iounit_pg0
->
4012 PhyData
[0].ControllerDevHandle
);
4013 ioc
->sas_hba
.phy
[i
].handle
= ioc
->sas_hba
.handle
;
4014 attached_handle
= le16_to_cpu(sas_iounit_pg0
->PhyData
[i
].
4016 if (attached_handle
&& link_rate
< MPI2_SAS_NEG_LINK_RATE_1_5
)
4017 link_rate
= MPI2_SAS_NEG_LINK_RATE_1_5
;
4018 mpt2sas_transport_update_links(ioc
, ioc
->sas_hba
.sas_address
,
4019 attached_handle
, i
, link_rate
);
4022 kfree(sas_iounit_pg0
);
4026 * _scsih_sas_host_add - create sas host object
4027 * @ioc: per adapter object
4029 * Creating host side data object, stored in ioc->sas_hba
4034 _scsih_sas_host_add(struct MPT2SAS_ADAPTER
*ioc
)
4037 Mpi2ConfigReply_t mpi_reply
;
4038 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
4039 Mpi2SasIOUnitPage1_t
*sas_iounit_pg1
= NULL
;
4040 Mpi2SasPhyPage0_t phy_pg0
;
4041 Mpi2SasDevicePage0_t sas_device_pg0
;
4042 Mpi2SasEnclosurePage0_t enclosure_pg0
;
4045 u16 device_missing_delay
;
4047 mpt2sas_config_get_number_hba_phys(ioc
, &ioc
->sas_hba
.num_phys
);
4048 if (!ioc
->sas_hba
.num_phys
) {
4049 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4050 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4054 /* sas_iounit page 0 */
4055 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
4056 sizeof(Mpi2SasIOUnit0PhyData_t
));
4057 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
4058 if (!sas_iounit_pg0
) {
4059 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4060 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4063 if ((mpt2sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
4064 sas_iounit_pg0
, sz
))) {
4065 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4066 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4069 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4070 MPI2_IOCSTATUS_MASK
;
4071 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4072 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4073 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4077 /* sas_iounit page 1 */
4078 sz
= offsetof(Mpi2SasIOUnitPage1_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
4079 sizeof(Mpi2SasIOUnit1PhyData_t
));
4080 sas_iounit_pg1
= kzalloc(sz
, GFP_KERNEL
);
4081 if (!sas_iounit_pg1
) {
4082 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4083 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4086 if ((mpt2sas_config_get_sas_iounit_pg1(ioc
, &mpi_reply
,
4087 sas_iounit_pg1
, sz
))) {
4088 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4089 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4092 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4093 MPI2_IOCSTATUS_MASK
;
4094 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4095 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4096 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4100 ioc
->io_missing_delay
=
4101 le16_to_cpu(sas_iounit_pg1
->IODeviceMissingDelay
);
4102 device_missing_delay
=
4103 le16_to_cpu(sas_iounit_pg1
->ReportDeviceMissingDelay
);
4104 if (device_missing_delay
& MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16
)
4105 ioc
->device_missing_delay
= (device_missing_delay
&
4106 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
) * 16;
4108 ioc
->device_missing_delay
= device_missing_delay
&
4109 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
;
4111 ioc
->sas_hba
.parent_dev
= &ioc
->shost
->shost_gendev
;
4112 ioc
->sas_hba
.phy
= kcalloc(ioc
->sas_hba
.num_phys
,
4113 sizeof(struct _sas_phy
), GFP_KERNEL
);
4114 if (!ioc
->sas_hba
.phy
) {
4115 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4116 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4119 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
4120 if ((mpt2sas_config_get_phy_pg0(ioc
, &mpi_reply
, &phy_pg0
,
4122 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4123 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4126 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4127 MPI2_IOCSTATUS_MASK
;
4128 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4129 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4130 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4135 ioc
->sas_hba
.handle
= le16_to_cpu(sas_iounit_pg0
->
4136 PhyData
[0].ControllerDevHandle
);
4137 ioc
->sas_hba
.phy
[i
].handle
= ioc
->sas_hba
.handle
;
4138 ioc
->sas_hba
.phy
[i
].phy_id
= i
;
4139 mpt2sas_transport_add_host_phy(ioc
, &ioc
->sas_hba
.phy
[i
],
4140 phy_pg0
, ioc
->sas_hba
.parent_dev
);
4142 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
4143 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, ioc
->sas_hba
.handle
))) {
4144 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4145 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4148 ioc
->sas_hba
.enclosure_handle
=
4149 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
4150 ioc
->sas_hba
.sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
4151 printk(MPT2SAS_INFO_FMT
"host_add: handle(0x%04x), "
4152 "sas_addr(0x%016llx), phys(%d)\n", ioc
->name
, ioc
->sas_hba
.handle
,
4153 (unsigned long long) ioc
->sas_hba
.sas_address
,
4154 ioc
->sas_hba
.num_phys
) ;
4156 if (ioc
->sas_hba
.enclosure_handle
) {
4157 if (!(mpt2sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
4159 MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
4160 ioc
->sas_hba
.enclosure_handle
))) {
4161 ioc
->sas_hba
.enclosure_logical_id
=
4162 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
4167 kfree(sas_iounit_pg1
);
4168 kfree(sas_iounit_pg0
);
4172 * _scsih_expander_add - creating expander object
4173 * @ioc: per adapter object
4174 * @handle: expander handle
4176 * Creating expander object, stored in ioc->sas_expander_list.
4178 * Return 0 for success, else error.
4181 _scsih_expander_add(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
4183 struct _sas_node
*sas_expander
;
4184 Mpi2ConfigReply_t mpi_reply
;
4185 Mpi2ExpanderPage0_t expander_pg0
;
4186 Mpi2ExpanderPage1_t expander_pg1
;
4187 Mpi2SasEnclosurePage0_t enclosure_pg0
;
4190 __le64 sas_address
, sas_address_parent
= 0;
4192 unsigned long flags
;
4193 struct _sas_port
*mpt2sas_port
= NULL
;
4199 if (ioc
->shost_recovery
|| ioc
->pci_error_recovery
)
4202 if ((mpt2sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
4203 MPI2_SAS_EXPAND_PGAD_FORM_HNDL
, handle
))) {
4204 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4205 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4209 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4210 MPI2_IOCSTATUS_MASK
;
4211 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4212 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4213 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4217 /* handle out of order topology events */
4218 parent_handle
= le16_to_cpu(expander_pg0
.ParentDevHandle
);
4219 if (_scsih_get_sas_address(ioc
, parent_handle
, &sas_address_parent
)
4221 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4222 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4225 if (sas_address_parent
!= ioc
->sas_hba
.sas_address
) {
4226 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
4227 sas_expander
= mpt2sas_scsih_expander_find_by_sas_address(ioc
,
4228 sas_address_parent
);
4229 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
4230 if (!sas_expander
) {
4231 rc
= _scsih_expander_add(ioc
, parent_handle
);
4237 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
4238 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
4239 sas_expander
= mpt2sas_scsih_expander_find_by_sas_address(ioc
,
4241 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
4246 sas_expander
= kzalloc(sizeof(struct _sas_node
),
4248 if (!sas_expander
) {
4249 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4250 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4254 sas_expander
->handle
= handle
;
4255 sas_expander
->num_phys
= expander_pg0
.NumPhys
;
4256 sas_expander
->sas_address_parent
= sas_address_parent
;
4257 sas_expander
->sas_address
= sas_address
;
4259 printk(MPT2SAS_INFO_FMT
"expander_add: handle(0x%04x),"
4260 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc
->name
,
4261 handle
, parent_handle
, (unsigned long long)
4262 sas_expander
->sas_address
, sas_expander
->num_phys
);
4264 if (!sas_expander
->num_phys
)
4266 sas_expander
->phy
= kcalloc(sas_expander
->num_phys
,
4267 sizeof(struct _sas_phy
), GFP_KERNEL
);
4268 if (!sas_expander
->phy
) {
4269 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4270 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4275 INIT_LIST_HEAD(&sas_expander
->sas_port_list
);
4276 mpt2sas_port
= mpt2sas_transport_port_add(ioc
, handle
,
4277 sas_address_parent
);
4278 if (!mpt2sas_port
) {
4279 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4280 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4284 sas_expander
->parent_dev
= &mpt2sas_port
->rphy
->dev
;
4286 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++) {
4287 if ((mpt2sas_config_get_expander_pg1(ioc
, &mpi_reply
,
4288 &expander_pg1
, i
, handle
))) {
4289 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4290 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4294 sas_expander
->phy
[i
].handle
= handle
;
4295 sas_expander
->phy
[i
].phy_id
= i
;
4297 if ((mpt2sas_transport_add_expander_phy(ioc
,
4298 &sas_expander
->phy
[i
], expander_pg1
,
4299 sas_expander
->parent_dev
))) {
4300 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4301 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4307 if (sas_expander
->enclosure_handle
) {
4308 if (!(mpt2sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
4309 &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
4310 sas_expander
->enclosure_handle
))) {
4311 sas_expander
->enclosure_logical_id
=
4312 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
4316 _scsih_expander_node_add(ioc
, sas_expander
);
4322 mpt2sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
4323 sas_address_parent
);
4324 kfree(sas_expander
);
4329 * _scsih_done - scsih callback handler.
4330 * @ioc: per adapter object
4331 * @smid: system request message index
4332 * @msix_index: MSIX table index supplied by the OS
4333 * @reply: reply message frame(lower 32bit addr)
4335 * Callback handler when sending internal generated message frames.
4336 * The callback index passed is `ioc->scsih_cb_idx`
4338 * Return 1 meaning mf should be freed from _base_interrupt
4339 * 0 means the mf is freed from this function.
4342 _scsih_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
4344 MPI2DefaultReply_t
*mpi_reply
;
4346 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
4347 if (ioc
->scsih_cmds
.status
== MPT2_CMD_NOT_USED
)
4349 if (ioc
->scsih_cmds
.smid
!= smid
)
4351 ioc
->scsih_cmds
.status
|= MPT2_CMD_COMPLETE
;
4353 memcpy(ioc
->scsih_cmds
.reply
, mpi_reply
,
4354 mpi_reply
->MsgLength
*4);
4355 ioc
->scsih_cmds
.status
|= MPT2_CMD_REPLY_VALID
;
4357 ioc
->scsih_cmds
.status
&= ~MPT2_CMD_PENDING
;
4358 complete(&ioc
->scsih_cmds
.done
);
4363 * mpt2sas_expander_remove - removing expander object
4364 * @ioc: per adapter object
4365 * @sas_address: expander sas_address
4370 mpt2sas_expander_remove(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
)
4372 struct _sas_node
*sas_expander
;
4373 unsigned long flags
;
4375 if (ioc
->shost_recovery
)
4378 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
4379 sas_expander
= mpt2sas_scsih_expander_find_by_sas_address(ioc
,
4381 if (!sas_expander
) {
4382 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
4385 list_del(&sas_expander
->list
);
4386 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
4387 _scsih_expander_node_remove(ioc
, sas_expander
);
4391 * _scsih_check_access_status - check access flags
4392 * @ioc: per adapter object
4393 * @sas_address: sas address
4394 * @handle: sas device handle
4395 * @access_flags: errors returned during discovery of the device
4397 * Return 0 for success, else failure
4400 _scsih_check_access_status(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
,
4401 u16 handle
, u8 access_status
)
4406 switch (access_status
) {
4407 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS
:
4408 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION
:
4411 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED
:
4412 desc
= "sata capability failed";
4414 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT
:
4415 desc
= "sata affiliation conflict";
4417 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE
:
4418 desc
= "route not addressable";
4420 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE
:
4421 desc
= "smp error not addressable";
4423 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED
:
4424 desc
= "device blocked";
4426 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED
:
4427 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN
:
4428 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT
:
4429 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG
:
4430 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION
:
4431 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER
:
4432 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN
:
4433 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN
:
4434 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN
:
4435 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION
:
4436 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE
:
4437 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX
:
4438 desc
= "sata initialization failed";
4448 printk(MPT2SAS_ERR_FMT
"discovery errors(%s): sas_address(0x%016llx), "
4449 "handle(0x%04x)\n", ioc
->name
, desc
,
4450 (unsigned long long)sas_address
, handle
);
4455 _scsih_check_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
4457 Mpi2ConfigReply_t mpi_reply
;
4458 Mpi2SasDevicePage0_t sas_device_pg0
;
4459 struct _sas_device
*sas_device
;
4461 unsigned long flags
;
4463 struct scsi_target
*starget
;
4464 struct MPT2SAS_TARGET
*sas_target_priv_data
;
4467 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
4468 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
)))
4471 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
4472 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
4475 /* check if this is end device */
4476 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
4477 if (!(_scsih_is_end_device(device_info
)))
4480 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4481 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
4482 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
4486 printk(MPT2SAS_ERR_FMT
"device is not present "
4487 "handle(0x%04x), no sas_device!!!\n", ioc
->name
, handle
);
4488 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4492 if (unlikely(sas_device
->handle
!= handle
)) {
4493 starget
= sas_device
->starget
;
4494 sas_target_priv_data
= starget
->hostdata
;
4495 starget_printk(KERN_INFO
, starget
, "handle changed from(0x%04x)"
4496 " to (0x%04x)!!!\n", sas_device
->handle
, handle
);
4497 sas_target_priv_data
->handle
= handle
;
4498 sas_device
->handle
= handle
;
4500 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4502 /* check if device is present */
4503 if (!(le16_to_cpu(sas_device_pg0
.Flags
) &
4504 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT
)) {
4505 printk(MPT2SAS_ERR_FMT
"device is not present "
4506 "handle(0x%04x), flags!!!\n", ioc
->name
, handle
);
4510 /* check if there were any issues with discovery */
4511 if (_scsih_check_access_status(ioc
, sas_address
, handle
,
4512 sas_device_pg0
.AccessStatus
))
4514 _scsih_ublock_io_device(ioc
, handle
);
4519 * _scsih_add_device - creating sas device object
4520 * @ioc: per adapter object
4521 * @handle: sas device handle
4522 * @phy_num: phy number end device attached to
4523 * @is_pd: is this hidden raid component
4525 * Creating end device object, stored in ioc->sas_device_list.
4527 * Returns 0 for success, non-zero for failure.
4530 _scsih_add_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
, u8 phy_num
, u8 is_pd
)
4532 Mpi2ConfigReply_t mpi_reply
;
4533 Mpi2SasDevicePage0_t sas_device_pg0
;
4534 Mpi2SasEnclosurePage0_t enclosure_pg0
;
4535 struct _sas_device
*sas_device
;
4539 unsigned long flags
;
4541 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
4542 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
4543 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4544 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4548 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4549 MPI2_IOCSTATUS_MASK
;
4550 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4551 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4552 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4556 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
4558 /* check if device is present */
4559 if (!(le16_to_cpu(sas_device_pg0
.Flags
) &
4560 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT
)) {
4561 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4562 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4563 printk(MPT2SAS_ERR_FMT
"Flags = 0x%04x\n",
4564 ioc
->name
, le16_to_cpu(sas_device_pg0
.Flags
));
4568 /* check if there were any issues with discovery */
4569 if (_scsih_check_access_status(ioc
, sas_address
, handle
,
4570 sas_device_pg0
.AccessStatus
))
4573 /* check if this is end device */
4574 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
4575 if (!(_scsih_is_end_device(device_info
))) {
4576 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4577 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4582 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4583 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
4585 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4590 sas_device
= kzalloc(sizeof(struct _sas_device
),
4593 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4594 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4598 sas_device
->handle
= handle
;
4599 if (_scsih_get_sas_address(ioc
, le16_to_cpu
4600 (sas_device_pg0
.ParentDevHandle
),
4601 &sas_device
->sas_address_parent
) != 0)
4602 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4603 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4604 sas_device
->enclosure_handle
=
4605 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
4607 le16_to_cpu(sas_device_pg0
.Slot
);
4608 sas_device
->device_info
= device_info
;
4609 sas_device
->sas_address
= sas_address
;
4610 sas_device
->phy
= sas_device_pg0
.PhyNum
;
4612 /* get enclosure_logical_id */
4613 if (sas_device
->enclosure_handle
&& !(mpt2sas_config_get_enclosure_pg0(
4614 ioc
, &mpi_reply
, &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
4615 sas_device
->enclosure_handle
)))
4616 sas_device
->enclosure_logical_id
=
4617 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
4619 /* get device name */
4620 sas_device
->device_name
= le64_to_cpu(sas_device_pg0
.DeviceName
);
4622 if (ioc
->wait_for_port_enable_to_complete
)
4623 _scsih_sas_device_init_add(ioc
, sas_device
);
4625 _scsih_sas_device_add(ioc
, sas_device
);
4631 * _scsih_remove_device - removing sas device object
4632 * @ioc: per adapter object
4633 * @sas_device_delete: the sas_device object
4638 _scsih_remove_device(struct MPT2SAS_ADAPTER
*ioc
,
4639 struct _sas_device
*sas_device
)
4641 struct _sas_device sas_device_backup
;
4642 struct MPT2SAS_TARGET
*sas_target_priv_data
;
4647 memcpy(&sas_device_backup
, sas_device
, sizeof(struct _sas_device
));
4648 _scsih_sas_device_remove(ioc
, sas_device
);
4650 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: enter: "
4651 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
, __func__
,
4652 sas_device_backup
.handle
, (unsigned long long)
4653 sas_device_backup
.sas_address
));
4655 if (sas_device_backup
.starget
&& sas_device_backup
.starget
->hostdata
) {
4656 sas_target_priv_data
= sas_device_backup
.starget
->hostdata
;
4657 sas_target_priv_data
->deleted
= 1;
4660 _scsih_ublock_io_device(ioc
, sas_device_backup
.handle
);
4662 mpt2sas_transport_port_remove(ioc
, sas_device_backup
.sas_address
,
4663 sas_device_backup
.sas_address_parent
);
4665 printk(MPT2SAS_INFO_FMT
"removing handle(0x%04x), sas_addr"
4666 "(0x%016llx)\n", ioc
->name
, sas_device_backup
.handle
,
4667 (unsigned long long) sas_device_backup
.sas_address
);
4669 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: exit: "
4670 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
, __func__
,
4671 sas_device_backup
.handle
, (unsigned long long)
4672 sas_device_backup
.sas_address
));
4676 * mpt2sas_device_remove - removing device object
4677 * @ioc: per adapter object
4678 * @sas_address: expander sas_address
4683 mpt2sas_device_remove(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
)
4685 struct _sas_device
*sas_device
;
4686 unsigned long flags
;
4688 if (ioc
->shost_recovery
)
4691 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4692 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
4695 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4698 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4699 _scsih_remove_device(ioc
, sas_device
);
4702 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4704 * _scsih_sas_topology_change_event_debug - debug for topology event
4705 * @ioc: per adapter object
4706 * @event_data: event data payload
4710 _scsih_sas_topology_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
4711 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
4717 char *status_str
= NULL
;
4718 u8 link_rate
, prev_link_rate
;
4720 switch (event_data
->ExpStatus
) {
4721 case MPI2_EVENT_SAS_TOPO_ES_ADDED
:
4724 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
:
4725 status_str
= "remove";
4727 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING
:
4729 status_str
= "responding";
4731 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
:
4732 status_str
= "remove delay";
4735 status_str
= "unknown status";
4738 printk(MPT2SAS_INFO_FMT
"sas topology change: (%s)\n",
4739 ioc
->name
, status_str
);
4740 printk(KERN_INFO
"\thandle(0x%04x), enclosure_handle(0x%04x) "
4741 "start_phy(%02d), count(%d)\n",
4742 le16_to_cpu(event_data
->ExpanderDevHandle
),
4743 le16_to_cpu(event_data
->EnclosureHandle
),
4744 event_data
->StartPhyNum
, event_data
->NumEntries
);
4745 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
4746 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
4749 phy_number
= event_data
->StartPhyNum
+ i
;
4750 reason_code
= event_data
->PHY
[i
].PhyStatus
&
4751 MPI2_EVENT_SAS_TOPO_RC_MASK
;
4752 switch (reason_code
) {
4753 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
4754 status_str
= "target add";
4756 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
4757 status_str
= "target remove";
4759 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
:
4760 status_str
= "delay target remove";
4762 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
4763 status_str
= "link rate change";
4765 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE
:
4766 status_str
= "target responding";
4769 status_str
= "unknown";
4772 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
4773 prev_link_rate
= event_data
->PHY
[i
].LinkRate
& 0xF;
4774 printk(KERN_INFO
"\tphy(%02d), attached_handle(0x%04x): %s:"
4775 " link rate: new(0x%02x), old(0x%02x)\n", phy_number
,
4776 handle
, status_str
, link_rate
, prev_link_rate
);
4783 * _scsih_sas_topology_change_event - handle topology changes
4784 * @ioc: per adapter object
4785 * @fw_event: The fw_event_work object
4790 _scsih_sas_topology_change_event(struct MPT2SAS_ADAPTER
*ioc
,
4791 struct fw_event_work
*fw_event
)
4794 u16 parent_handle
, handle
;
4796 u8 phy_number
, max_phys
;
4797 struct _sas_node
*sas_expander
;
4798 struct _sas_device
*sas_device
;
4800 unsigned long flags
;
4801 u8 link_rate
, prev_link_rate
;
4802 Mpi2EventDataSasTopologyChangeList_t
*event_data
= fw_event
->event_data
;
4804 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4805 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
4806 _scsih_sas_topology_change_event_debug(ioc
, event_data
);
4809 if (ioc
->shost_recovery
|| ioc
->remove_host
|| ioc
->pci_error_recovery
)
4812 if (!ioc
->sas_hba
.num_phys
)
4813 _scsih_sas_host_add(ioc
);
4815 _scsih_sas_host_refresh(ioc
);
4817 if (fw_event
->ignore
) {
4818 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"ignoring expander "
4819 "event\n", ioc
->name
));
4823 parent_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
4825 /* handle expander add */
4826 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_ADDED
)
4827 if (_scsih_expander_add(ioc
, parent_handle
) != 0)
4830 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
4831 sas_expander
= mpt2sas_scsih_expander_find_by_handle(ioc
,
4833 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
4835 sas_address
= sas_expander
->sas_address
;
4836 max_phys
= sas_expander
->num_phys
;
4837 } else if (parent_handle
< ioc
->sas_hba
.num_phys
) {
4838 sas_address
= ioc
->sas_hba
.sas_address
;
4839 max_phys
= ioc
->sas_hba
.num_phys
;
4843 /* handle siblings events */
4844 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
4845 if (fw_event
->ignore
) {
4846 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"ignoring "
4847 "expander event\n", ioc
->name
));
4850 if (ioc
->shost_recovery
|| ioc
->remove_host
||
4851 ioc
->pci_error_recovery
)
4853 phy_number
= event_data
->StartPhyNum
+ i
;
4854 if (phy_number
>= max_phys
)
4856 reason_code
= event_data
->PHY
[i
].PhyStatus
&
4857 MPI2_EVENT_SAS_TOPO_RC_MASK
;
4858 if ((event_data
->PHY
[i
].PhyStatus
&
4859 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT
) && (reason_code
!=
4860 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
))
4862 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
4865 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
4866 prev_link_rate
= event_data
->PHY
[i
].LinkRate
& 0xF;
4867 switch (reason_code
) {
4868 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
4870 if (link_rate
== prev_link_rate
)
4873 mpt2sas_transport_update_links(ioc
, sas_address
,
4874 handle
, phy_number
, link_rate
);
4876 if (link_rate
< MPI2_SAS_NEG_LINK_RATE_1_5
)
4879 _scsih_check_device(ioc
, handle
);
4881 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
4883 mpt2sas_transport_update_links(ioc
, sas_address
,
4884 handle
, phy_number
, link_rate
);
4886 _scsih_add_device(ioc
, handle
, phy_number
, 0);
4888 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
4890 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4891 sas_device
= _scsih_sas_device_find_by_handle(ioc
,
4894 spin_unlock_irqrestore(&ioc
->sas_device_lock
,
4898 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4899 _scsih_remove_device(ioc
, sas_device
);
4904 /* handle expander removal */
4905 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
&&
4907 mpt2sas_expander_remove(ioc
, sas_address
);
4911 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4913 * _scsih_sas_device_status_change_event_debug - debug for device event
4914 * @event_data: event data payload
4920 _scsih_sas_device_status_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
4921 Mpi2EventDataSasDeviceStatusChange_t
*event_data
)
4923 char *reason_str
= NULL
;
4925 switch (event_data
->ReasonCode
) {
4926 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
:
4927 reason_str
= "smart data";
4929 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED
:
4930 reason_str
= "unsupported device discovered";
4932 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
:
4933 reason_str
= "internal device reset";
4935 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL
:
4936 reason_str
= "internal task abort";
4938 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL
:
4939 reason_str
= "internal task abort set";
4941 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL
:
4942 reason_str
= "internal clear task set";
4944 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL
:
4945 reason_str
= "internal query task";
4947 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE
:
4948 reason_str
= "sata init failure";
4950 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
:
4951 reason_str
= "internal device reset complete";
4953 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL
:
4954 reason_str
= "internal task abort complete";
4956 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION
:
4957 reason_str
= "internal async notification";
4959 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY
:
4960 reason_str
= "expander reduced functionality";
4962 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY
:
4963 reason_str
= "expander reduced functionality complete";
4966 reason_str
= "unknown reason";
4969 printk(MPT2SAS_INFO_FMT
"device status change: (%s)\n"
4970 "\thandle(0x%04x), sas address(0x%016llx)", ioc
->name
,
4971 reason_str
, le16_to_cpu(event_data
->DevHandle
),
4972 (unsigned long long)le64_to_cpu(event_data
->SASAddress
));
4973 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
)
4974 printk(MPT2SAS_INFO_FMT
", ASC(0x%x), ASCQ(0x%x)\n", ioc
->name
,
4975 event_data
->ASC
, event_data
->ASCQ
);
4976 printk(KERN_INFO
"\n");
4981 * _scsih_sas_device_status_change_event - handle device status change
4982 * @ioc: per adapter object
4983 * @fw_event: The fw_event_work object
4989 _scsih_sas_device_status_change_event(struct MPT2SAS_ADAPTER
*ioc
,
4990 struct fw_event_work
*fw_event
)
4992 struct MPT2SAS_TARGET
*target_priv_data
;
4993 struct _sas_device
*sas_device
;
4995 unsigned long flags
;
4996 Mpi2EventDataSasDeviceStatusChange_t
*event_data
=
4997 fw_event
->event_data
;
4999 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5000 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5001 _scsih_sas_device_status_change_event_debug(ioc
,
5005 if (event_data
->ReasonCode
!=
5006 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
&&
5007 event_data
->ReasonCode
!=
5008 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
)
5011 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5012 sas_address
= le64_to_cpu(event_data
->SASAddress
);
5013 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
5015 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5017 if (!sas_device
|| !sas_device
->starget
)
5020 target_priv_data
= sas_device
->starget
->hostdata
;
5021 if (!target_priv_data
)
5024 if (event_data
->ReasonCode
==
5025 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
)
5026 target_priv_data
->tm_busy
= 1;
5028 target_priv_data
->tm_busy
= 0;
5031 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5033 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure event
5034 * @ioc: per adapter object
5035 * @event_data: event data payload
5041 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
5042 Mpi2EventDataSasEnclDevStatusChange_t
*event_data
)
5044 char *reason_str
= NULL
;
5046 switch (event_data
->ReasonCode
) {
5047 case MPI2_EVENT_SAS_ENCL_RC_ADDED
:
5048 reason_str
= "enclosure add";
5050 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING
:
5051 reason_str
= "enclosure remove";
5054 reason_str
= "unknown reason";
5058 printk(MPT2SAS_INFO_FMT
"enclosure status change: (%s)\n"
5059 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
5060 " number slots(%d)\n", ioc
->name
, reason_str
,
5061 le16_to_cpu(event_data
->EnclosureHandle
),
5062 (unsigned long long)le64_to_cpu(event_data
->EnclosureLogicalID
),
5063 le16_to_cpu(event_data
->StartSlot
));
5068 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
5069 * @ioc: per adapter object
5070 * @fw_event: The fw_event_work object
5076 _scsih_sas_enclosure_dev_status_change_event(struct MPT2SAS_ADAPTER
*ioc
,
5077 struct fw_event_work
*fw_event
)
5079 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5080 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5081 _scsih_sas_enclosure_dev_status_change_event_debug(ioc
,
5082 fw_event
->event_data
);
5087 * _scsih_sas_broadcast_primative_event - handle broadcast events
5088 * @ioc: per adapter object
5089 * @fw_event: The fw_event_work object
5095 _scsih_sas_broadcast_primative_event(struct MPT2SAS_ADAPTER
*ioc
,
5096 struct fw_event_work
*fw_event
)
5098 struct scsi_cmnd
*scmd
;
5101 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
5102 u32 termination_count
;
5104 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
5105 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5106 Mpi2EventDataSasBroadcastPrimitive_t
*event_data
= fw_event
->event_data
;
5109 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"broadcast primative: "
5110 "phy number(%d), width(%d)\n", ioc
->name
, event_data
->PhyNum
,
5111 event_data
->PortWidth
));
5112 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: enter\n", ioc
->name
,
5115 termination_count
= 0;
5117 mpi_reply
= ioc
->tm_cmds
.reply
;
5118 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
5119 scmd
= _scsih_scsi_lookup_get(ioc
, smid
);
5122 sas_device_priv_data
= scmd
->device
->hostdata
;
5123 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
)
5125 /* skip hidden raid components */
5126 if (sas_device_priv_data
->sas_target
->flags
&
5127 MPT_TARGET_FLAGS_RAID_COMPONENT
)
5130 if (sas_device_priv_data
->sas_target
->flags
&
5131 MPT_TARGET_FLAGS_VOLUME
)
5134 handle
= sas_device_priv_data
->sas_target
->handle
;
5135 lun
= sas_device_priv_data
->lun
;
5138 mpt2sas_scsih_issue_tm(ioc
, handle
, 0, 0, lun
,
5139 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK
, smid
, 30, NULL
);
5140 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
5141 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
)
5142 & MPI2_IOCSTATUS_MASK
;
5143 if ((ioc_status
== MPI2_IOCSTATUS_SUCCESS
) &&
5144 (mpi_reply
->ResponseCode
==
5145 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
||
5146 mpi_reply
->ResponseCode
==
5147 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
))
5150 mpt2sas_scsih_issue_tm(ioc
, handle
, 0, 0, lun
,
5151 MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET
, 0, 30, NULL
);
5152 termination_count
+= le32_to_cpu(mpi_reply
->TerminationCount
);
5154 ioc
->broadcast_aen_busy
= 0;
5156 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
5157 "%s - exit, query_count = %d termination_count = %d\n",
5158 ioc
->name
, __func__
, query_count
, termination_count
));
5162 * _scsih_sas_discovery_event - handle discovery events
5163 * @ioc: per adapter object
5164 * @fw_event: The fw_event_work object
5170 _scsih_sas_discovery_event(struct MPT2SAS_ADAPTER
*ioc
,
5171 struct fw_event_work
*fw_event
)
5173 Mpi2EventDataSasDiscovery_t
*event_data
= fw_event
->event_data
;
5175 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5176 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
) {
5177 printk(MPT2SAS_INFO_FMT
"discovery event: (%s)", ioc
->name
,
5178 (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
) ?
5180 if (event_data
->DiscoveryStatus
)
5181 printk("discovery_status(0x%08x)",
5182 le32_to_cpu(event_data
->DiscoveryStatus
));
5187 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
&&
5188 !ioc
->sas_hba
.num_phys
)
5189 _scsih_sas_host_add(ioc
);
5193 * _scsih_reprobe_lun - reprobing lun
5194 * @sdev: scsi device struct
5195 * @no_uld_attach: sdev->no_uld_attach flag setting
5199 _scsih_reprobe_lun(struct scsi_device
*sdev
, void *no_uld_attach
)
5203 sdev
->no_uld_attach
= no_uld_attach
? 1 : 0;
5204 sdev_printk(KERN_INFO
, sdev
, "%s raid component\n",
5205 sdev
->no_uld_attach
? "hidding" : "exposing");
5206 rc
= scsi_device_reprobe(sdev
);
5210 * _scsih_reprobe_target - reprobing target
5211 * @starget: scsi target struct
5212 * @no_uld_attach: sdev->no_uld_attach flag setting
5214 * Note: no_uld_attach flag determines whether the disk device is attached
5215 * to block layer. A value of `1` means to not attach.
5218 _scsih_reprobe_target(struct scsi_target
*starget
, int no_uld_attach
)
5220 struct MPT2SAS_TARGET
*sas_target_priv_data
= starget
->hostdata
;
5223 sas_target_priv_data
->flags
|= MPT_TARGET_FLAGS_RAID_COMPONENT
;
5225 sas_target_priv_data
->flags
&= ~MPT_TARGET_FLAGS_RAID_COMPONENT
;
5227 starget_for_each_device(starget
, no_uld_attach
? (void *)1 : NULL
,
5228 _scsih_reprobe_lun
);
5231 * _scsih_sas_volume_add - add new volume
5232 * @ioc: per adapter object
5233 * @element: IR config element data
5239 _scsih_sas_volume_add(struct MPT2SAS_ADAPTER
*ioc
,
5240 Mpi2EventIrConfigElement_t
*element
)
5242 struct _raid_device
*raid_device
;
5243 unsigned long flags
;
5245 u16 handle
= le16_to_cpu(element
->VolDevHandle
);
5248 mpt2sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
5250 printk(MPT2SAS_ERR_FMT
5251 "failure at %s:%d/%s()!\n", ioc
->name
,
5252 __FILE__
, __LINE__
, __func__
);
5256 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5257 raid_device
= _scsih_raid_device_find_by_wwid(ioc
, wwid
);
5258 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5263 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
5265 printk(MPT2SAS_ERR_FMT
5266 "failure at %s:%d/%s()!\n", ioc
->name
,
5267 __FILE__
, __LINE__
, __func__
);
5271 raid_device
->id
= ioc
->sas_id
++;
5272 raid_device
->channel
= RAID_CHANNEL
;
5273 raid_device
->handle
= handle
;
5274 raid_device
->wwid
= wwid
;
5275 _scsih_raid_device_add(ioc
, raid_device
);
5276 if (!ioc
->wait_for_port_enable_to_complete
) {
5277 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
5278 raid_device
->id
, 0);
5280 _scsih_raid_device_remove(ioc
, raid_device
);
5282 _scsih_determine_boot_device(ioc
, raid_device
, 1);
5286 * _scsih_sas_volume_delete - delete volume
5287 * @ioc: per adapter object
5288 * @handle: volume device handle
5294 _scsih_sas_volume_delete(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
5296 struct _raid_device
*raid_device
;
5297 unsigned long flags
;
5298 struct MPT2SAS_TARGET
*sas_target_priv_data
;
5300 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5301 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
5302 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5305 if (raid_device
->starget
) {
5306 sas_target_priv_data
= raid_device
->starget
->hostdata
;
5307 sas_target_priv_data
->deleted
= 1;
5308 scsi_remove_target(&raid_device
->starget
->dev
);
5310 printk(MPT2SAS_INFO_FMT
"removing handle(0x%04x), wwid"
5311 "(0x%016llx)\n", ioc
->name
, raid_device
->handle
,
5312 (unsigned long long) raid_device
->wwid
);
5313 _scsih_raid_device_remove(ioc
, raid_device
);
5317 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
5318 * @ioc: per adapter object
5319 * @element: IR config element data
5325 _scsih_sas_pd_expose(struct MPT2SAS_ADAPTER
*ioc
,
5326 Mpi2EventIrConfigElement_t
*element
)
5328 struct _sas_device
*sas_device
;
5329 unsigned long flags
;
5330 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
5332 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5333 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
5334 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5338 /* exposing raid component */
5339 sas_device
->volume_handle
= 0;
5340 sas_device
->volume_wwid
= 0;
5341 clear_bit(handle
, ioc
->pd_handles
);
5342 _scsih_reprobe_target(sas_device
->starget
, 0);
5346 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
5347 * @ioc: per adapter object
5348 * @element: IR config element data
5354 _scsih_sas_pd_hide(struct MPT2SAS_ADAPTER
*ioc
,
5355 Mpi2EventIrConfigElement_t
*element
)
5357 struct _sas_device
*sas_device
;
5358 unsigned long flags
;
5359 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
5361 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5362 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
5363 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5367 /* hiding raid component */
5368 mpt2sas_config_get_volume_handle(ioc
, handle
,
5369 &sas_device
->volume_handle
);
5370 mpt2sas_config_get_volume_wwid(ioc
, sas_device
->volume_handle
,
5371 &sas_device
->volume_wwid
);
5372 set_bit(handle
, ioc
->pd_handles
);
5373 _scsih_reprobe_target(sas_device
->starget
, 1);
5377 * _scsih_sas_pd_delete - delete pd component
5378 * @ioc: per adapter object
5379 * @element: IR config element data
5385 _scsih_sas_pd_delete(struct MPT2SAS_ADAPTER
*ioc
,
5386 Mpi2EventIrConfigElement_t
*element
)
5388 struct _sas_device
*sas_device
;
5389 unsigned long flags
;
5390 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
5392 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5393 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
5394 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5397 _scsih_remove_device(ioc
, sas_device
);
5401 * _scsih_sas_pd_add - remove pd component
5402 * @ioc: per adapter object
5403 * @element: IR config element data
5409 _scsih_sas_pd_add(struct MPT2SAS_ADAPTER
*ioc
,
5410 Mpi2EventIrConfigElement_t
*element
)
5412 struct _sas_device
*sas_device
;
5413 unsigned long flags
;
5414 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
5415 Mpi2ConfigReply_t mpi_reply
;
5416 Mpi2SasDevicePage0_t sas_device_pg0
;
5421 set_bit(handle
, ioc
->pd_handles
);
5423 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5424 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
5425 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5429 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
5430 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
5431 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5432 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5436 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5437 MPI2_IOCSTATUS_MASK
;
5438 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5439 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5440 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5444 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
5445 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
5446 mpt2sas_transport_update_links(ioc
, sas_address
, handle
,
5447 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
5449 _scsih_add_device(ioc
, handle
, 0, 1);
5452 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5454 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
5455 * @ioc: per adapter object
5456 * @event_data: event data payload
5462 _scsih_sas_ir_config_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
5463 Mpi2EventDataIrConfigChangeList_t
*event_data
)
5465 Mpi2EventIrConfigElement_t
*element
;
5468 char *reason_str
= NULL
, *element_str
= NULL
;
5470 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
5472 printk(MPT2SAS_INFO_FMT
"raid config change: (%s), elements(%d)\n",
5473 ioc
->name
, (le32_to_cpu(event_data
->Flags
) &
5474 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ?
5475 "foreign" : "native", event_data
->NumElements
);
5476 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
5477 switch (element
->ReasonCode
) {
5478 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
5481 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
5482 reason_str
= "remove";
5484 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE
:
5485 reason_str
= "no change";
5487 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
5488 reason_str
= "hide";
5490 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
5491 reason_str
= "unhide";
5493 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
5494 reason_str
= "volume_created";
5496 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
5497 reason_str
= "volume_deleted";
5499 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
5500 reason_str
= "pd_created";
5502 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
5503 reason_str
= "pd_deleted";
5506 reason_str
= "unknown reason";
5509 element_type
= le16_to_cpu(element
->ElementFlags
) &
5510 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK
;
5511 switch (element_type
) {
5512 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT
:
5513 element_str
= "volume";
5515 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT
:
5516 element_str
= "phys disk";
5518 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT
:
5519 element_str
= "hot spare";
5522 element_str
= "unknown element";
5525 printk(KERN_INFO
"\t(%s:%s), vol handle(0x%04x), "
5526 "pd handle(0x%04x), pd num(0x%02x)\n", element_str
,
5527 reason_str
, le16_to_cpu(element
->VolDevHandle
),
5528 le16_to_cpu(element
->PhysDiskDevHandle
),
5529 element
->PhysDiskNum
);
5535 * _scsih_sas_ir_config_change_event - handle ir configuration change events
5536 * @ioc: per adapter object
5537 * @fw_event: The fw_event_work object
5543 _scsih_sas_ir_config_change_event(struct MPT2SAS_ADAPTER
*ioc
,
5544 struct fw_event_work
*fw_event
)
5546 Mpi2EventIrConfigElement_t
*element
;
5549 Mpi2EventDataIrConfigChangeList_t
*event_data
= fw_event
->event_data
;
5551 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5552 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5553 _scsih_sas_ir_config_change_event_debug(ioc
, event_data
);
5556 foreign_config
= (le32_to_cpu(event_data
->Flags
) &
5557 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ? 1 : 0;
5559 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
5560 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
5562 switch (element
->ReasonCode
) {
5563 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
5564 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
5565 if (!foreign_config
)
5566 _scsih_sas_volume_add(ioc
, element
);
5568 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
5569 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
5570 if (!foreign_config
)
5571 _scsih_sas_volume_delete(ioc
,
5572 le16_to_cpu(element
->VolDevHandle
));
5574 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
5575 _scsih_sas_pd_hide(ioc
, element
);
5577 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
5578 _scsih_sas_pd_expose(ioc
, element
);
5580 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
5581 _scsih_sas_pd_add(ioc
, element
);
5583 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
5584 _scsih_sas_pd_delete(ioc
, element
);
5591 * _scsih_sas_ir_volume_event - IR volume event
5592 * @ioc: per adapter object
5593 * @fw_event: The fw_event_work object
5599 _scsih_sas_ir_volume_event(struct MPT2SAS_ADAPTER
*ioc
,
5600 struct fw_event_work
*fw_event
)
5603 unsigned long flags
;
5604 struct _raid_device
*raid_device
;
5608 Mpi2EventDataIrVolume_t
*event_data
= fw_event
->event_data
;
5610 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED
)
5613 handle
= le16_to_cpu(event_data
->VolDevHandle
);
5614 state
= le32_to_cpu(event_data
->NewValue
);
5615 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: handle(0x%04x), "
5616 "old(0x%08x), new(0x%08x)\n", ioc
->name
, __func__
, handle
,
5617 le32_to_cpu(event_data
->PreviousValue
), state
));
5620 case MPI2_RAID_VOL_STATE_MISSING
:
5621 case MPI2_RAID_VOL_STATE_FAILED
:
5622 _scsih_sas_volume_delete(ioc
, handle
);
5625 case MPI2_RAID_VOL_STATE_ONLINE
:
5626 case MPI2_RAID_VOL_STATE_DEGRADED
:
5627 case MPI2_RAID_VOL_STATE_OPTIMAL
:
5629 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5630 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
5631 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5636 mpt2sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
5638 printk(MPT2SAS_ERR_FMT
5639 "failure at %s:%d/%s()!\n", ioc
->name
,
5640 __FILE__
, __LINE__
, __func__
);
5644 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
5646 printk(MPT2SAS_ERR_FMT
5647 "failure at %s:%d/%s()!\n", ioc
->name
,
5648 __FILE__
, __LINE__
, __func__
);
5652 raid_device
->id
= ioc
->sas_id
++;
5653 raid_device
->channel
= RAID_CHANNEL
;
5654 raid_device
->handle
= handle
;
5655 raid_device
->wwid
= wwid
;
5656 _scsih_raid_device_add(ioc
, raid_device
);
5657 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
5658 raid_device
->id
, 0);
5660 _scsih_raid_device_remove(ioc
, raid_device
);
5663 case MPI2_RAID_VOL_STATE_INITIALIZING
:
5670 * _scsih_sas_ir_physical_disk_event - PD event
5671 * @ioc: per adapter object
5672 * @fw_event: The fw_event_work object
5678 _scsih_sas_ir_physical_disk_event(struct MPT2SAS_ADAPTER
*ioc
,
5679 struct fw_event_work
*fw_event
)
5681 u16 handle
, parent_handle
;
5683 struct _sas_device
*sas_device
;
5684 unsigned long flags
;
5685 Mpi2ConfigReply_t mpi_reply
;
5686 Mpi2SasDevicePage0_t sas_device_pg0
;
5688 Mpi2EventDataIrPhysicalDisk_t
*event_data
= fw_event
->event_data
;
5691 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED
)
5694 handle
= le16_to_cpu(event_data
->PhysDiskDevHandle
);
5695 state
= le32_to_cpu(event_data
->NewValue
);
5697 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: handle(0x%04x), "
5698 "old(0x%08x), new(0x%08x)\n", ioc
->name
, __func__
, handle
,
5699 le32_to_cpu(event_data
->PreviousValue
), state
));
5702 case MPI2_RAID_PD_STATE_ONLINE
:
5703 case MPI2_RAID_PD_STATE_DEGRADED
:
5704 case MPI2_RAID_PD_STATE_REBUILDING
:
5705 case MPI2_RAID_PD_STATE_OPTIMAL
:
5706 case MPI2_RAID_PD_STATE_HOT_SPARE
:
5708 set_bit(handle
, ioc
->pd_handles
);
5710 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5711 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
5712 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5717 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
5718 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
5720 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5721 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5725 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5726 MPI2_IOCSTATUS_MASK
;
5727 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5728 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5729 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5733 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
5734 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
5735 mpt2sas_transport_update_links(ioc
, sas_address
, handle
,
5736 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
5738 _scsih_add_device(ioc
, handle
, 0, 1);
5742 case MPI2_RAID_PD_STATE_OFFLINE
:
5743 case MPI2_RAID_PD_STATE_NOT_CONFIGURED
:
5744 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE
:
5750 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5752 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
5753 * @ioc: per adapter object
5754 * @event_data: event data payload
5760 _scsih_sas_ir_operation_status_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
5761 Mpi2EventDataIrOperationStatus_t
*event_data
)
5763 char *reason_str
= NULL
;
5765 switch (event_data
->RAIDOperation
) {
5766 case MPI2_EVENT_IR_RAIDOP_RESYNC
:
5767 reason_str
= "resync";
5769 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION
:
5770 reason_str
= "online capacity expansion";
5772 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK
:
5773 reason_str
= "consistency check";
5775 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT
:
5776 reason_str
= "background init";
5778 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT
:
5779 reason_str
= "make data consistent";
5786 printk(MPT2SAS_INFO_FMT
"raid operational status: (%s)"
5787 "\thandle(0x%04x), percent complete(%d)\n",
5788 ioc
->name
, reason_str
,
5789 le16_to_cpu(event_data
->VolDevHandle
),
5790 event_data
->PercentComplete
);
5795 * _scsih_sas_ir_operation_status_event - handle RAID operation events
5796 * @ioc: per adapter object
5797 * @fw_event: The fw_event_work object
5803 _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER
*ioc
,
5804 struct fw_event_work
*fw_event
)
5806 Mpi2EventDataIrOperationStatus_t
*event_data
= fw_event
->event_data
;
5807 static struct _raid_device
*raid_device
;
5808 unsigned long flags
;
5811 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5812 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5813 _scsih_sas_ir_operation_status_event_debug(ioc
,
5817 /* code added for raid transport support */
5818 if (event_data
->RAIDOperation
== MPI2_EVENT_IR_RAIDOP_RESYNC
) {
5820 handle
= le16_to_cpu(event_data
->VolDevHandle
);
5822 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5823 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
5824 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5829 if (event_data
->RAIDOperation
== MPI2_EVENT_IR_RAIDOP_RESYNC
)
5830 raid_device
->percent_complete
=
5831 event_data
->PercentComplete
;
5836 * _scsih_prep_device_scan - initialize parameters prior to device scan
5837 * @ioc: per adapter object
5839 * Set the deleted flag prior to device scan. If the device is found during
5840 * the scan, then we clear the deleted flag.
5843 _scsih_prep_device_scan(struct MPT2SAS_ADAPTER
*ioc
)
5845 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
5846 struct scsi_device
*sdev
;
5848 shost_for_each_device(sdev
, ioc
->shost
) {
5849 sas_device_priv_data
= sdev
->hostdata
;
5850 if (sas_device_priv_data
&& sas_device_priv_data
->sas_target
)
5851 sas_device_priv_data
->sas_target
->deleted
= 1;
5856 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
5857 * @ioc: per adapter object
5858 * @sas_address: sas address
5859 * @slot: enclosure slot id
5860 * @handle: device handle
5862 * After host reset, find out whether devices are still responding.
5863 * Used in _scsi_remove_unresponsive_sas_devices.
5868 _scsih_mark_responding_sas_device(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
,
5869 u16 slot
, u16 handle
)
5871 struct MPT2SAS_TARGET
*sas_target_priv_data
;
5872 struct scsi_target
*starget
;
5873 struct _sas_device
*sas_device
;
5874 unsigned long flags
;
5876 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5877 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
) {
5878 if (sas_device
->sas_address
== sas_address
&&
5879 sas_device
->slot
== slot
&& sas_device
->starget
) {
5880 sas_device
->responding
= 1;
5881 starget
= sas_device
->starget
;
5882 if (starget
&& starget
->hostdata
) {
5883 sas_target_priv_data
= starget
->hostdata
;
5884 sas_target_priv_data
->tm_busy
= 0;
5885 sas_target_priv_data
->deleted
= 0;
5887 sas_target_priv_data
= NULL
;
5888 starget_printk(KERN_INFO
, sas_device
->starget
,
5889 "handle(0x%04x), sas_addr(0x%016llx), enclosure "
5890 "logical id(0x%016llx), slot(%d)\n", handle
,
5891 (unsigned long long)sas_device
->sas_address
,
5892 (unsigned long long)
5893 sas_device
->enclosure_logical_id
,
5895 if (sas_device
->handle
== handle
)
5897 printk(KERN_INFO
"\thandle changed from(0x%04x)!!!\n",
5898 sas_device
->handle
);
5899 sas_device
->handle
= handle
;
5900 if (sas_target_priv_data
)
5901 sas_target_priv_data
->handle
= handle
;
5906 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5910 * _scsih_search_responding_sas_devices -
5911 * @ioc: per adapter object
5913 * After host reset, find out whether devices are still responding.
5919 _scsih_search_responding_sas_devices(struct MPT2SAS_ADAPTER
*ioc
)
5921 Mpi2SasDevicePage0_t sas_device_pg0
;
5922 Mpi2ConfigReply_t mpi_reply
;
5929 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
, __func__
);
5931 if (list_empty(&ioc
->sas_device_list
))
5935 while (!(mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
5936 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
,
5938 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5939 MPI2_IOCSTATUS_MASK
;
5940 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
5942 handle
= le16_to_cpu(sas_device_pg0
.DevHandle
);
5943 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
5944 if (!(_scsih_is_end_device(device_info
)))
5946 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
5947 slot
= le16_to_cpu(sas_device_pg0
.Slot
);
5948 _scsih_mark_responding_sas_device(ioc
, sas_address
, slot
,
5954 * _scsih_mark_responding_raid_device - mark a raid_device as responding
5955 * @ioc: per adapter object
5956 * @wwid: world wide identifier for raid volume
5957 * @handle: device handle
5959 * After host reset, find out whether devices are still responding.
5960 * Used in _scsi_remove_unresponsive_raid_devices.
5965 _scsih_mark_responding_raid_device(struct MPT2SAS_ADAPTER
*ioc
, u64 wwid
,
5968 struct MPT2SAS_TARGET
*sas_target_priv_data
;
5969 struct scsi_target
*starget
;
5970 struct _raid_device
*raid_device
;
5971 unsigned long flags
;
5973 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5974 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
5975 if (raid_device
->wwid
== wwid
&& raid_device
->starget
) {
5976 starget
= raid_device
->starget
;
5977 if (starget
&& starget
->hostdata
) {
5978 sas_target_priv_data
= starget
->hostdata
;
5979 sas_target_priv_data
->deleted
= 0;
5981 sas_target_priv_data
= NULL
;
5982 raid_device
->responding
= 1;
5983 starget_printk(KERN_INFO
, raid_device
->starget
,
5984 "handle(0x%04x), wwid(0x%016llx)\n", handle
,
5985 (unsigned long long)raid_device
->wwid
);
5986 if (raid_device
->handle
== handle
)
5988 printk(KERN_INFO
"\thandle changed from(0x%04x)!!!\n",
5989 raid_device
->handle
);
5990 raid_device
->handle
= handle
;
5991 if (sas_target_priv_data
)
5992 sas_target_priv_data
->handle
= handle
;
5997 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6001 * _scsih_search_responding_raid_devices -
6002 * @ioc: per adapter object
6004 * After host reset, find out whether devices are still responding.
6010 _scsih_search_responding_raid_devices(struct MPT2SAS_ADAPTER
*ioc
)
6012 Mpi2RaidVolPage1_t volume_pg1
;
6013 Mpi2RaidVolPage0_t volume_pg0
;
6014 Mpi2RaidPhysDiskPage0_t pd_pg0
;
6015 Mpi2ConfigReply_t mpi_reply
;
6020 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
, __func__
);
6022 if (list_empty(&ioc
->raid_device_list
))
6026 while (!(mpt2sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
6027 &volume_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
6028 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6029 MPI2_IOCSTATUS_MASK
;
6030 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
6032 handle
= le16_to_cpu(volume_pg1
.DevHandle
);
6034 if (mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
,
6035 &volume_pg0
, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
6036 sizeof(Mpi2RaidVolPage0_t
)))
6039 if (volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_OPTIMAL
||
6040 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_ONLINE
||
6041 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_DEGRADED
)
6042 _scsih_mark_responding_raid_device(ioc
,
6043 le64_to_cpu(volume_pg1
.WWID
), handle
);
6046 /* refresh the pd_handles */
6047 phys_disk_num
= 0xFF;
6048 memset(ioc
->pd_handles
, 0, ioc
->pd_handles_sz
);
6049 while (!(mpt2sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
6050 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM
,
6052 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6053 MPI2_IOCSTATUS_MASK
;
6054 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
6056 phys_disk_num
= pd_pg0
.PhysDiskNum
;
6057 handle
= le16_to_cpu(pd_pg0
.DevHandle
);
6058 set_bit(handle
, ioc
->pd_handles
);
6063 * _scsih_mark_responding_expander - mark a expander as responding
6064 * @ioc: per adapter object
6065 * @sas_address: sas address
6068 * After host reset, find out whether devices are still responding.
6069 * Used in _scsi_remove_unresponsive_expanders.
6074 _scsih_mark_responding_expander(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
,
6077 struct _sas_node
*sas_expander
;
6078 unsigned long flags
;
6081 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
6082 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
6083 if (sas_expander
->sas_address
!= sas_address
)
6085 sas_expander
->responding
= 1;
6086 if (sas_expander
->handle
== handle
)
6088 printk(KERN_INFO
"\texpander(0x%016llx): handle changed"
6089 " from(0x%04x) to (0x%04x)!!!\n",
6090 (unsigned long long)sas_expander
->sas_address
,
6091 sas_expander
->handle
, handle
);
6092 sas_expander
->handle
= handle
;
6093 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++)
6094 sas_expander
->phy
[i
].handle
= handle
;
6098 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
6102 * _scsih_search_responding_expanders -
6103 * @ioc: per adapter object
6105 * After host reset, find out whether devices are still responding.
6111 _scsih_search_responding_expanders(struct MPT2SAS_ADAPTER
*ioc
)
6113 Mpi2ExpanderPage0_t expander_pg0
;
6114 Mpi2ConfigReply_t mpi_reply
;
6119 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
, __func__
);
6121 if (list_empty(&ioc
->sas_expander_list
))
6125 while (!(mpt2sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
6126 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL
, handle
))) {
6128 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6129 MPI2_IOCSTATUS_MASK
;
6130 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
6133 handle
= le16_to_cpu(expander_pg0
.DevHandle
);
6134 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
6135 printk(KERN_INFO
"\texpander present: handle(0x%04x), "
6136 "sas_addr(0x%016llx)\n", handle
,
6137 (unsigned long long)sas_address
);
6138 _scsih_mark_responding_expander(ioc
, sas_address
, handle
);
6144 * _scsih_remove_unresponding_sas_devices - removing unresponding devices
6145 * @ioc: per adapter object
6150 _scsih_remove_unresponding_sas_devices(struct MPT2SAS_ADAPTER
*ioc
)
6152 struct _sas_device
*sas_device
, *sas_device_next
;
6153 struct _sas_node
*sas_expander
;
6154 struct _raid_device
*raid_device
, *raid_device_next
;
6157 list_for_each_entry_safe(sas_device
, sas_device_next
,
6158 &ioc
->sas_device_list
, list
) {
6159 if (sas_device
->responding
) {
6160 sas_device
->responding
= 0;
6163 if (sas_device
->starget
)
6164 starget_printk(KERN_INFO
, sas_device
->starget
,
6165 "removing: handle(0x%04x), sas_addr(0x%016llx), "
6166 "enclosure logical id(0x%016llx), slot(%d)\n",
6168 (unsigned long long)sas_device
->sas_address
,
6169 (unsigned long long)
6170 sas_device
->enclosure_logical_id
,
6172 _scsih_remove_device(ioc
, sas_device
);
6175 list_for_each_entry_safe(raid_device
, raid_device_next
,
6176 &ioc
->raid_device_list
, list
) {
6177 if (raid_device
->responding
) {
6178 raid_device
->responding
= 0;
6181 if (raid_device
->starget
) {
6182 starget_printk(KERN_INFO
, raid_device
->starget
,
6183 "removing: handle(0x%04x), wwid(0x%016llx)\n",
6184 raid_device
->handle
,
6185 (unsigned long long)raid_device
->wwid
);
6186 scsi_remove_target(&raid_device
->starget
->dev
);
6188 _scsih_raid_device_remove(ioc
, raid_device
);
6191 retry_expander_search
:
6192 sas_expander
= NULL
;
6193 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
6194 if (sas_expander
->responding
) {
6195 sas_expander
->responding
= 0;
6198 mpt2sas_expander_remove(ioc
, sas_expander
->sas_address
);
6199 goto retry_expander_search
;
6204 * mpt2sas_scsih_reset_handler - reset callback handler (for scsih)
6205 * @ioc: per adapter object
6206 * @reset_phase: phase
6208 * The handler for doing any required cleanup or initialization.
6210 * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
6211 * MPT2_IOC_DONE_RESET
6216 mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER
*ioc
, int reset_phase
)
6218 switch (reset_phase
) {
6219 case MPT2_IOC_PRE_RESET
:
6220 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: "
6221 "MPT2_IOC_PRE_RESET\n", ioc
->name
, __func__
));
6223 case MPT2_IOC_AFTER_RESET
:
6224 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: "
6225 "MPT2_IOC_AFTER_RESET\n", ioc
->name
, __func__
));
6226 if (ioc
->scsih_cmds
.status
& MPT2_CMD_PENDING
) {
6227 ioc
->scsih_cmds
.status
|= MPT2_CMD_RESET
;
6228 mpt2sas_base_free_smid(ioc
, ioc
->scsih_cmds
.smid
);
6229 complete(&ioc
->scsih_cmds
.done
);
6231 if (ioc
->tm_cmds
.status
& MPT2_CMD_PENDING
) {
6232 ioc
->tm_cmds
.status
|= MPT2_CMD_RESET
;
6233 mpt2sas_base_free_smid(ioc
, ioc
->tm_cmds
.smid
);
6234 complete(&ioc
->tm_cmds
.done
);
6236 _scsih_fw_event_cleanup_queue(ioc
);
6237 _scsih_flush_running_cmds(ioc
);
6238 _scsih_queue_rescan(ioc
);
6240 case MPT2_IOC_DONE_RESET
:
6241 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: "
6242 "MPT2_IOC_DONE_RESET\n", ioc
->name
, __func__
));
6243 _scsih_sas_host_refresh(ioc
);
6244 _scsih_prep_device_scan(ioc
);
6245 _scsih_search_responding_sas_devices(ioc
);
6246 _scsih_search_responding_raid_devices(ioc
);
6247 _scsih_search_responding_expanders(ioc
);
6253 * _firmware_event_work - delayed task for processing firmware events
6254 * @ioc: per adapter object
6255 * @work: equal to the fw_event_work object
6261 _firmware_event_work(struct work_struct
*work
)
6263 struct fw_event_work
*fw_event
= container_of(work
,
6264 struct fw_event_work
, delayed_work
.work
);
6265 unsigned long flags
;
6266 struct MPT2SAS_ADAPTER
*ioc
= fw_event
->ioc
;
6268 /* the queue is being flushed so ignore this event */
6269 if (ioc
->remove_host
|| fw_event
->cancel_pending_work
||
6270 ioc
->pci_error_recovery
) {
6271 _scsih_fw_event_free(ioc
, fw_event
);
6275 if (fw_event
->event
== MPT2SAS_RESCAN_AFTER_HOST_RESET
) {
6276 _scsih_fw_event_free(ioc
, fw_event
);
6277 spin_lock_irqsave(&ioc
->ioc_reset_in_progress_lock
, flags
);
6278 if (ioc
->shost_recovery
) {
6279 init_completion(&ioc
->shost_recovery_done
);
6280 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
,
6282 wait_for_completion(&ioc
->shost_recovery_done
);
6284 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
,
6286 _scsih_remove_unresponding_sas_devices(ioc
);
6290 switch (fw_event
->event
) {
6291 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
6292 _scsih_sas_topology_change_event(ioc
, fw_event
);
6294 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
6295 _scsih_sas_device_status_change_event(ioc
,
6298 case MPI2_EVENT_SAS_DISCOVERY
:
6299 _scsih_sas_discovery_event(ioc
,
6302 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
6303 _scsih_sas_broadcast_primative_event(ioc
,
6306 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
6307 _scsih_sas_enclosure_dev_status_change_event(ioc
,
6310 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
6311 _scsih_sas_ir_config_change_event(ioc
, fw_event
);
6313 case MPI2_EVENT_IR_VOLUME
:
6314 _scsih_sas_ir_volume_event(ioc
, fw_event
);
6316 case MPI2_EVENT_IR_PHYSICAL_DISK
:
6317 _scsih_sas_ir_physical_disk_event(ioc
, fw_event
);
6319 case MPI2_EVENT_IR_OPERATION_STATUS
:
6320 _scsih_sas_ir_operation_status_event(ioc
, fw_event
);
6323 _scsih_fw_event_free(ioc
, fw_event
);
6327 * mpt2sas_scsih_event_callback - firmware event handler (called at ISR time)
6328 * @ioc: per adapter object
6329 * @msix_index: MSIX table index supplied by the OS
6330 * @reply: reply message frame(lower 32bit addr)
6331 * Context: interrupt.
6333 * This function merely adds a new work task into ioc->firmware_event_thread.
6334 * The tasks are worked from _firmware_event_work in user context.
6336 * Return 1 meaning mf should be freed from _base_interrupt
6337 * 0 means the mf is freed from this function.
6340 mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER
*ioc
, u8 msix_index
,
6343 struct fw_event_work
*fw_event
;
6344 Mpi2EventNotificationReply_t
*mpi_reply
;
6348 /* events turned off due to host reset or driver unloading */
6349 if (ioc
->remove_host
|| ioc
->pci_error_recovery
)
6352 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
6353 event
= le16_to_cpu(mpi_reply
->Event
);
6357 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
6359 Mpi2EventDataSasBroadcastPrimitive_t
*baen_data
=
6360 (Mpi2EventDataSasBroadcastPrimitive_t
*)
6361 mpi_reply
->EventData
;
6363 if (baen_data
->Primitive
!=
6364 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT
||
6365 ioc
->broadcast_aen_busy
)
6367 ioc
->broadcast_aen_busy
= 1;
6371 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
6372 _scsih_check_topo_delete_events(ioc
,
6373 (Mpi2EventDataSasTopologyChangeList_t
*)
6374 mpi_reply
->EventData
);
6376 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
6377 _scsih_check_ir_config_unhide_events(ioc
,
6378 (Mpi2EventDataIrConfigChangeList_t
*)
6379 mpi_reply
->EventData
);
6381 case MPI2_EVENT_IR_VOLUME
:
6382 _scsih_check_volume_delete_events(ioc
,
6383 (Mpi2EventDataIrVolume_t
*)
6384 mpi_reply
->EventData
);
6386 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
6387 case MPI2_EVENT_IR_OPERATION_STATUS
:
6388 case MPI2_EVENT_SAS_DISCOVERY
:
6389 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
6390 case MPI2_EVENT_IR_PHYSICAL_DISK
:
6393 default: /* ignore the rest */
6397 fw_event
= kzalloc(sizeof(struct fw_event_work
), GFP_ATOMIC
);
6399 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6400 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6403 sz
= le16_to_cpu(mpi_reply
->EventDataLength
) * 4;
6404 fw_event
->event_data
= kzalloc(sz
, GFP_ATOMIC
);
6405 if (!fw_event
->event_data
) {
6406 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6407 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6412 memcpy(fw_event
->event_data
, mpi_reply
->EventData
,
6414 fw_event
->ioc
= ioc
;
6415 fw_event
->VF_ID
= mpi_reply
->VF_ID
;
6416 fw_event
->VP_ID
= mpi_reply
->VP_ID
;
6417 fw_event
->event
= event
;
6418 _scsih_fw_event_add(ioc
, fw_event
);
6422 /* shost template */
6423 static struct scsi_host_template scsih_driver_template
= {
6424 .module
= THIS_MODULE
,
6425 .name
= "Fusion MPT SAS Host",
6426 .proc_name
= MPT2SAS_DRIVER_NAME
,
6427 .queuecommand
= _scsih_qcmd
,
6428 .target_alloc
= _scsih_target_alloc
,
6429 .slave_alloc
= _scsih_slave_alloc
,
6430 .slave_configure
= _scsih_slave_configure
,
6431 .target_destroy
= _scsih_target_destroy
,
6432 .slave_destroy
= _scsih_slave_destroy
,
6433 .change_queue_depth
= _scsih_change_queue_depth
,
6434 .change_queue_type
= _scsih_change_queue_type
,
6435 .eh_abort_handler
= _scsih_abort
,
6436 .eh_device_reset_handler
= _scsih_dev_reset
,
6437 .eh_target_reset_handler
= _scsih_target_reset
,
6438 .eh_host_reset_handler
= _scsih_host_reset
,
6439 .bios_param
= _scsih_bios_param
,
6442 .sg_tablesize
= MPT2SAS_SG_DEPTH
,
6443 .max_sectors
= 8192,
6445 .use_clustering
= ENABLE_CLUSTERING
,
6446 .shost_attrs
= mpt2sas_host_attrs
,
6447 .sdev_attrs
= mpt2sas_dev_attrs
,
6451 * _scsih_expander_node_remove - removing expander device from list.
6452 * @ioc: per adapter object
6453 * @sas_expander: the sas_device object
6454 * Context: Calling function should acquire ioc->sas_node_lock.
6456 * Removing object and freeing associated memory from the
6457 * ioc->sas_expander_list.
6462 _scsih_expander_node_remove(struct MPT2SAS_ADAPTER
*ioc
,
6463 struct _sas_node
*sas_expander
)
6465 struct _sas_port
*mpt2sas_port
, *next
;
6467 /* remove sibling ports attached to this expander */
6468 list_for_each_entry_safe(mpt2sas_port
, next
,
6469 &sas_expander
->sas_port_list
, port_list
) {
6470 if (ioc
->shost_recovery
)
6472 if (mpt2sas_port
->remote_identify
.device_type
==
6474 mpt2sas_device_remove(ioc
,
6475 mpt2sas_port
->remote_identify
.sas_address
);
6476 else if (mpt2sas_port
->remote_identify
.device_type
==
6477 SAS_EDGE_EXPANDER_DEVICE
||
6478 mpt2sas_port
->remote_identify
.device_type
==
6479 SAS_FANOUT_EXPANDER_DEVICE
)
6480 mpt2sas_expander_remove(ioc
,
6481 mpt2sas_port
->remote_identify
.sas_address
);
6484 mpt2sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
6485 sas_expander
->sas_address_parent
);
6487 printk(MPT2SAS_INFO_FMT
"expander_remove: handle"
6488 "(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
6489 sas_expander
->handle
, (unsigned long long)
6490 sas_expander
->sas_address
);
6492 kfree(sas_expander
->phy
);
6493 kfree(sas_expander
);
6497 * _scsih_ir_shutdown - IR shutdown notification
6498 * @ioc: per adapter object
6500 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
6501 * the host system is shutting down.
6506 _scsih_ir_shutdown(struct MPT2SAS_ADAPTER
*ioc
)
6508 Mpi2RaidActionRequest_t
*mpi_request
;
6509 Mpi2RaidActionReply_t
*mpi_reply
;
6512 /* is IR firmware build loaded ? */
6513 if (!ioc
->ir_firmware
)
6516 /* are there any volumes ? */
6517 if (list_empty(&ioc
->raid_device_list
))
6520 mutex_lock(&ioc
->scsih_cmds
.mutex
);
6522 if (ioc
->scsih_cmds
.status
!= MPT2_CMD_NOT_USED
) {
6523 printk(MPT2SAS_ERR_FMT
"%s: scsih_cmd in use\n",
6524 ioc
->name
, __func__
);
6527 ioc
->scsih_cmds
.status
= MPT2_CMD_PENDING
;
6529 smid
= mpt2sas_base_get_smid(ioc
, ioc
->scsih_cb_idx
);
6531 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
6532 ioc
->name
, __func__
);
6533 ioc
->scsih_cmds
.status
= MPT2_CMD_NOT_USED
;
6537 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
6538 ioc
->scsih_cmds
.smid
= smid
;
6539 memset(mpi_request
, 0, sizeof(Mpi2RaidActionRequest_t
));
6541 mpi_request
->Function
= MPI2_FUNCTION_RAID_ACTION
;
6542 mpi_request
->Action
= MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED
;
6544 printk(MPT2SAS_INFO_FMT
"IR shutdown (sending)\n", ioc
->name
);
6545 init_completion(&ioc
->scsih_cmds
.done
);
6546 mpt2sas_base_put_smid_default(ioc
, smid
);
6547 wait_for_completion_timeout(&ioc
->scsih_cmds
.done
, 10*HZ
);
6549 if (!(ioc
->scsih_cmds
.status
& MPT2_CMD_COMPLETE
)) {
6550 printk(MPT2SAS_ERR_FMT
"%s: timeout\n",
6551 ioc
->name
, __func__
);
6555 if (ioc
->scsih_cmds
.status
& MPT2_CMD_REPLY_VALID
) {
6556 mpi_reply
= ioc
->scsih_cmds
.reply
;
6558 printk(MPT2SAS_INFO_FMT
"IR shutdown (complete): "
6559 "ioc_status(0x%04x), loginfo(0x%08x)\n",
6560 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
6561 le32_to_cpu(mpi_reply
->IOCLogInfo
));
6565 ioc
->scsih_cmds
.status
= MPT2_CMD_NOT_USED
;
6566 mutex_unlock(&ioc
->scsih_cmds
.mutex
);
6570 * _scsih_shutdown - routine call during system shutdown
6571 * @pdev: PCI device struct
6576 _scsih_shutdown(struct pci_dev
*pdev
)
6578 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6579 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
6580 struct workqueue_struct
*wq
;
6581 unsigned long flags
;
6583 ioc
->remove_host
= 1;
6584 _scsih_fw_event_cleanup_queue(ioc
);
6586 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
6587 wq
= ioc
->firmware_event_thread
;
6588 ioc
->firmware_event_thread
= NULL
;
6589 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
6591 destroy_workqueue(wq
);
6593 _scsih_ir_shutdown(ioc
);
6594 mpt2sas_base_detach(ioc
);
6598 * _scsih_remove - detach and remove add host
6599 * @pdev: PCI device struct
6601 * Routine called when unloading the driver.
6604 static void __devexit
6605 _scsih_remove(struct pci_dev
*pdev
)
6607 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6608 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
6609 struct _sas_port
*mpt2sas_port
, *next_port
;
6610 struct _raid_device
*raid_device
, *next
;
6611 struct MPT2SAS_TARGET
*sas_target_priv_data
;
6612 struct workqueue_struct
*wq
;
6613 unsigned long flags
;
6615 ioc
->remove_host
= 1;
6616 _scsih_fw_event_cleanup_queue(ioc
);
6618 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
6619 wq
= ioc
->firmware_event_thread
;
6620 ioc
->firmware_event_thread
= NULL
;
6621 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
6623 destroy_workqueue(wq
);
6625 /* release all the volumes */
6626 list_for_each_entry_safe(raid_device
, next
, &ioc
->raid_device_list
,
6628 if (raid_device
->starget
) {
6629 sas_target_priv_data
=
6630 raid_device
->starget
->hostdata
;
6631 sas_target_priv_data
->deleted
= 1;
6632 scsi_remove_target(&raid_device
->starget
->dev
);
6634 printk(MPT2SAS_INFO_FMT
"removing handle(0x%04x), wwid"
6635 "(0x%016llx)\n", ioc
->name
, raid_device
->handle
,
6636 (unsigned long long) raid_device
->wwid
);
6637 _scsih_raid_device_remove(ioc
, raid_device
);
6640 /* free ports attached to the sas_host */
6641 list_for_each_entry_safe(mpt2sas_port
, next_port
,
6642 &ioc
->sas_hba
.sas_port_list
, port_list
) {
6643 if (mpt2sas_port
->remote_identify
.device_type
==
6645 mpt2sas_device_remove(ioc
,
6646 mpt2sas_port
->remote_identify
.sas_address
);
6647 else if (mpt2sas_port
->remote_identify
.device_type
==
6648 SAS_EDGE_EXPANDER_DEVICE
||
6649 mpt2sas_port
->remote_identify
.device_type
==
6650 SAS_FANOUT_EXPANDER_DEVICE
)
6651 mpt2sas_expander_remove(ioc
,
6652 mpt2sas_port
->remote_identify
.sas_address
);
6655 /* free phys attached to the sas_host */
6656 if (ioc
->sas_hba
.num_phys
) {
6657 kfree(ioc
->sas_hba
.phy
);
6658 ioc
->sas_hba
.phy
= NULL
;
6659 ioc
->sas_hba
.num_phys
= 0;
6662 sas_remove_host(shost
);
6663 _scsih_shutdown(pdev
);
6664 list_del(&ioc
->list
);
6665 scsi_remove_host(shost
);
6666 scsi_host_put(shost
);
6670 * _scsih_probe_boot_devices - reports 1st device
6671 * @ioc: per adapter object
6673 * If specified in bios page 2, this routine reports the 1st
6674 * device scsi-ml or sas transport for persistent boot device
6675 * purposes. Please refer to function _scsih_determine_boot_device()
6678 _scsih_probe_boot_devices(struct MPT2SAS_ADAPTER
*ioc
)
6682 struct _sas_device
*sas_device
;
6683 struct _raid_device
*raid_device
;
6685 u64 sas_address_parent
;
6687 unsigned long flags
;
6691 if (ioc
->req_boot_device
.device
) {
6692 device
= ioc
->req_boot_device
.device
;
6693 is_raid
= ioc
->req_boot_device
.is_raid
;
6694 } else if (ioc
->req_alt_boot_device
.device
) {
6695 device
= ioc
->req_alt_boot_device
.device
;
6696 is_raid
= ioc
->req_alt_boot_device
.is_raid
;
6697 } else if (ioc
->current_boot_device
.device
) {
6698 device
= ioc
->current_boot_device
.device
;
6699 is_raid
= ioc
->current_boot_device
.is_raid
;
6706 raid_device
= device
;
6707 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
6708 raid_device
->id
, 0);
6710 _scsih_raid_device_remove(ioc
, raid_device
);
6712 sas_device
= device
;
6713 handle
= sas_device
->handle
;
6714 sas_address_parent
= sas_device
->sas_address_parent
;
6715 sas_address
= sas_device
->sas_address
;
6716 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6717 list_move_tail(&sas_device
->list
, &ioc
->sas_device_list
);
6718 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6719 if (!mpt2sas_transport_port_add(ioc
, sas_device
->handle
,
6720 sas_device
->sas_address_parent
)) {
6721 _scsih_sas_device_remove(ioc
, sas_device
);
6722 } else if (!sas_device
->starget
) {
6723 mpt2sas_transport_port_remove(ioc
, sas_address
,
6724 sas_address_parent
);
6725 _scsih_sas_device_remove(ioc
, sas_device
);
6731 * _scsih_probe_raid - reporting raid volumes to scsi-ml
6732 * @ioc: per adapter object
6734 * Called during initial loading of the driver.
6737 _scsih_probe_raid(struct MPT2SAS_ADAPTER
*ioc
)
6739 struct _raid_device
*raid_device
, *raid_next
;
6742 list_for_each_entry_safe(raid_device
, raid_next
,
6743 &ioc
->raid_device_list
, list
) {
6744 if (raid_device
->starget
)
6746 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
6747 raid_device
->id
, 0);
6749 _scsih_raid_device_remove(ioc
, raid_device
);
6754 * _scsih_probe_sas - reporting sas devices to sas transport
6755 * @ioc: per adapter object
6757 * Called during initial loading of the driver.
6760 _scsih_probe_sas(struct MPT2SAS_ADAPTER
*ioc
)
6762 struct _sas_device
*sas_device
, *next
;
6763 unsigned long flags
;
6765 /* SAS Device List */
6766 list_for_each_entry_safe(sas_device
, next
, &ioc
->sas_device_init_list
,
6768 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6769 list_move_tail(&sas_device
->list
, &ioc
->sas_device_list
);
6770 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6772 if (!mpt2sas_transport_port_add(ioc
, sas_device
->handle
,
6773 sas_device
->sas_address_parent
)) {
6774 _scsih_sas_device_remove(ioc
, sas_device
);
6775 } else if (!sas_device
->starget
) {
6776 mpt2sas_transport_port_remove(ioc
,
6777 sas_device
->sas_address
,
6778 sas_device
->sas_address_parent
);
6779 _scsih_sas_device_remove(ioc
, sas_device
);
6785 * _scsih_probe_devices - probing for devices
6786 * @ioc: per adapter object
6788 * Called during initial loading of the driver.
6791 _scsih_probe_devices(struct MPT2SAS_ADAPTER
*ioc
)
6793 u16 volume_mapping_flags
=
6794 le16_to_cpu(ioc
->ioc_pg8
.IRVolumeMappingFlags
) &
6795 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE
;
6797 if (!(ioc
->facts
.ProtocolFlags
& MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR
))
6798 return; /* return when IOC doesn't support initiator mode */
6800 _scsih_probe_boot_devices(ioc
);
6802 if (ioc
->ir_firmware
) {
6803 if ((volume_mapping_flags
&
6804 MPI2_IOCPAGE8_IRFLAGS_HIGH_VOLUME_MAPPING
)) {
6805 _scsih_probe_sas(ioc
);
6806 _scsih_probe_raid(ioc
);
6808 _scsih_probe_raid(ioc
);
6809 _scsih_probe_sas(ioc
);
6812 _scsih_probe_sas(ioc
);
6816 * _scsih_probe - attach and add scsi host
6817 * @pdev: PCI device struct
6818 * @id: pci device id
6820 * Returns 0 success, anything else error.
6823 _scsih_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
6825 struct MPT2SAS_ADAPTER
*ioc
;
6826 struct Scsi_Host
*shost
;
6828 shost
= scsi_host_alloc(&scsih_driver_template
,
6829 sizeof(struct MPT2SAS_ADAPTER
));
6833 /* init local params */
6834 ioc
= shost_priv(shost
);
6835 memset(ioc
, 0, sizeof(struct MPT2SAS_ADAPTER
));
6836 INIT_LIST_HEAD(&ioc
->list
);
6837 list_add_tail(&ioc
->list
, &mpt2sas_ioc_list
);
6839 ioc
->id
= mpt_ids
++;
6840 sprintf(ioc
->name
, "%s%d", MPT2SAS_DRIVER_NAME
, ioc
->id
);
6842 ioc
->scsi_io_cb_idx
= scsi_io_cb_idx
;
6843 ioc
->tm_cb_idx
= tm_cb_idx
;
6844 ioc
->ctl_cb_idx
= ctl_cb_idx
;
6845 ioc
->base_cb_idx
= base_cb_idx
;
6846 ioc
->transport_cb_idx
= transport_cb_idx
;
6847 ioc
->scsih_cb_idx
= scsih_cb_idx
;
6848 ioc
->config_cb_idx
= config_cb_idx
;
6849 ioc
->tm_tr_cb_idx
= tm_tr_cb_idx
;
6850 ioc
->tm_tr_volume_cb_idx
= tm_tr_volume_cb_idx
;
6851 ioc
->tm_sas_control_cb_idx
= tm_sas_control_cb_idx
;
6852 ioc
->logging_level
= logging_level
;
6853 /* misc semaphores and spin locks */
6854 mutex_init(&ioc
->reset_in_progress_mutex
);
6855 spin_lock_init(&ioc
->ioc_reset_in_progress_lock
);
6856 spin_lock_init(&ioc
->scsi_lookup_lock
);
6857 spin_lock_init(&ioc
->sas_device_lock
);
6858 spin_lock_init(&ioc
->sas_node_lock
);
6859 spin_lock_init(&ioc
->fw_event_lock
);
6860 spin_lock_init(&ioc
->raid_device_lock
);
6862 INIT_LIST_HEAD(&ioc
->sas_device_list
);
6863 INIT_LIST_HEAD(&ioc
->sas_device_init_list
);
6864 INIT_LIST_HEAD(&ioc
->sas_expander_list
);
6865 INIT_LIST_HEAD(&ioc
->fw_event_list
);
6866 INIT_LIST_HEAD(&ioc
->raid_device_list
);
6867 INIT_LIST_HEAD(&ioc
->sas_hba
.sas_port_list
);
6868 INIT_LIST_HEAD(&ioc
->delayed_tr_list
);
6869 INIT_LIST_HEAD(&ioc
->delayed_tr_volume_list
);
6871 /* init shost parameters */
6872 shost
->max_cmd_len
= 32;
6873 shost
->max_lun
= max_lun
;
6874 shost
->transportt
= mpt2sas_transport_template
;
6875 shost
->unique_id
= ioc
->id
;
6877 if ((scsi_add_host(shost
, &pdev
->dev
))) {
6878 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6879 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6880 list_del(&ioc
->list
);
6881 goto out_add_shost_fail
;
6884 scsi_host_set_prot(shost
, SHOST_DIF_TYPE1_PROTECTION
6885 | SHOST_DIF_TYPE2_PROTECTION
| SHOST_DIF_TYPE3_PROTECTION
);
6886 scsi_host_set_guard(shost
, SHOST_DIX_GUARD_CRC
);
6889 snprintf(ioc
->firmware_event_name
, sizeof(ioc
->firmware_event_name
),
6890 "fw_event%d", ioc
->id
);
6891 ioc
->firmware_event_thread
= create_singlethread_workqueue(
6892 ioc
->firmware_event_name
);
6893 if (!ioc
->firmware_event_thread
) {
6894 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6895 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6896 goto out_thread_fail
;
6899 ioc
->wait_for_port_enable_to_complete
= 1;
6900 if ((mpt2sas_base_attach(ioc
))) {
6901 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6902 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6903 goto out_attach_fail
;
6906 ioc
->wait_for_port_enable_to_complete
= 0;
6907 _scsih_probe_devices(ioc
);
6911 destroy_workqueue(ioc
->firmware_event_thread
);
6913 list_del(&ioc
->list
);
6914 scsi_remove_host(shost
);
6921 * _scsih_suspend - power management suspend main entry point
6922 * @pdev: PCI device struct
6923 * @state: PM state change to (usually PCI_D3)
6925 * Returns 0 success, anything else error.
6928 _scsih_suspend(struct pci_dev
*pdev
, pm_message_t state
)
6930 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6931 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
6934 mpt2sas_base_stop_watchdog(ioc
);
6935 flush_scheduled_work();
6936 scsi_block_requests(shost
);
6937 device_state
= pci_choose_state(pdev
, state
);
6938 printk(MPT2SAS_INFO_FMT
"pdev=0x%p, slot=%s, entering "
6939 "operating state [D%d]\n", ioc
->name
, pdev
,
6940 pci_name(pdev
), device_state
);
6942 mpt2sas_base_free_resources(ioc
);
6943 pci_save_state(pdev
);
6944 pci_disable_device(pdev
);
6945 pci_set_power_state(pdev
, device_state
);
6950 * _scsih_resume - power management resume main entry point
6951 * @pdev: PCI device struct
6953 * Returns 0 success, anything else error.
6956 _scsih_resume(struct pci_dev
*pdev
)
6958 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6959 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
6960 u32 device_state
= pdev
->current_state
;
6963 printk(MPT2SAS_INFO_FMT
"pdev=0x%p, slot=%s, previous "
6964 "operating state [D%d]\n", ioc
->name
, pdev
,
6965 pci_name(pdev
), device_state
);
6967 pci_set_power_state(pdev
, PCI_D0
);
6968 pci_enable_wake(pdev
, PCI_D0
, 0);
6969 pci_restore_state(pdev
);
6971 r
= mpt2sas_base_map_resources(ioc
);
6975 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
, SOFT_RESET
);
6976 scsi_unblock_requests(shost
);
6977 mpt2sas_base_start_watchdog(ioc
);
6980 #endif /* CONFIG_PM */
6983 * _scsih_pci_error_detected - Called when a PCI error is detected.
6984 * @pdev: PCI device struct
6985 * @state: PCI channel state
6987 * Description: Called when a PCI error is detected.
6990 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
6992 static pci_ers_result_t
6993 _scsih_pci_error_detected(struct pci_dev
*pdev
, pci_channel_state_t state
)
6995 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6996 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
6998 printk(MPT2SAS_INFO_FMT
"PCI error: detected callback, state(%d)!!\n",
7002 case pci_channel_io_normal
:
7003 return PCI_ERS_RESULT_CAN_RECOVER
;
7004 case pci_channel_io_frozen
:
7005 /* Fatal error, prepare for slot reset */
7006 ioc
->pci_error_recovery
= 1;
7007 scsi_block_requests(ioc
->shost
);
7008 mpt2sas_base_stop_watchdog(ioc
);
7009 mpt2sas_base_free_resources(ioc
);
7010 return PCI_ERS_RESULT_NEED_RESET
;
7011 case pci_channel_io_perm_failure
:
7012 /* Permanent error, prepare for device removal */
7013 ioc
->pci_error_recovery
= 1;
7014 mpt2sas_base_stop_watchdog(ioc
);
7015 _scsih_flush_running_cmds(ioc
);
7016 return PCI_ERS_RESULT_DISCONNECT
;
7018 return PCI_ERS_RESULT_NEED_RESET
;
7022 * _scsih_pci_slot_reset - Called when PCI slot has been reset.
7023 * @pdev: PCI device struct
7025 * Description: This routine is called by the pci error recovery
7026 * code after the PCI slot has been reset, just before we
7027 * should resume normal operations.
7029 static pci_ers_result_t
7030 _scsih_pci_slot_reset(struct pci_dev
*pdev
)
7032 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
7033 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
7036 printk(MPT2SAS_INFO_FMT
"PCI error: slot reset callback!!\n",
7039 ioc
->pci_error_recovery
= 0;
7041 pci_restore_state(pdev
);
7042 rc
= mpt2sas_base_map_resources(ioc
);
7044 return PCI_ERS_RESULT_DISCONNECT
;
7047 rc
= mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
7050 printk(MPT2SAS_WARN_FMT
"hard reset: %s\n", ioc
->name
,
7051 (rc
== 0) ? "success" : "failed");
7054 return PCI_ERS_RESULT_RECOVERED
;
7056 return PCI_ERS_RESULT_DISCONNECT
;
7060 * _scsih_pci_resume() - resume normal ops after PCI reset
7061 * @pdev: pointer to PCI device
7063 * Called when the error recovery driver tells us that its
7064 * OK to resume normal operation. Use completion to allow
7065 * halted scsi ops to resume.
7068 _scsih_pci_resume(struct pci_dev
*pdev
)
7070 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
7071 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
7073 printk(MPT2SAS_INFO_FMT
"PCI error: resume callback!!\n", ioc
->name
);
7075 pci_cleanup_aer_uncorrect_error_status(pdev
);
7076 mpt2sas_base_start_watchdog(ioc
);
7077 scsi_unblock_requests(ioc
->shost
);
7081 * _scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
7082 * @pdev: pointer to PCI device
7084 static pci_ers_result_t
7085 _scsih_pci_mmio_enabled(struct pci_dev
*pdev
)
7087 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
7088 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
7090 printk(MPT2SAS_INFO_FMT
"PCI error: mmio enabled callback!!\n",
7093 /* TODO - dump whatever for debugging purposes */
7095 /* Request a slot reset. */
7096 return PCI_ERS_RESULT_NEED_RESET
;
7099 static struct pci_error_handlers _scsih_err_handler
= {
7100 .error_detected
= _scsih_pci_error_detected
,
7101 .mmio_enabled
= _scsih_pci_mmio_enabled
,
7102 .slot_reset
= _scsih_pci_slot_reset
,
7103 .resume
= _scsih_pci_resume
,
7106 static struct pci_driver scsih_driver
= {
7107 .name
= MPT2SAS_DRIVER_NAME
,
7108 .id_table
= scsih_pci_table
,
7109 .probe
= _scsih_probe
,
7110 .remove
= __devexit_p(_scsih_remove
),
7111 .shutdown
= _scsih_shutdown
,
7112 .err_handler
= &_scsih_err_handler
,
7114 .suspend
= _scsih_suspend
,
7115 .resume
= _scsih_resume
,
7119 /* raid transport support */
7120 static struct raid_function_template mpt2sas_raid_functions
= {
7121 .cookie
= &scsih_driver_template
,
7122 .is_raid
= _scsih_is_raid
,
7123 .get_resync
= _scsih_get_resync
,
7124 .get_state
= _scsih_get_state
,
7128 * _scsih_init - main entry point for this driver.
7130 * Returns 0 success, anything else error.
7138 printk(KERN_INFO
"%s version %s loaded\n", MPT2SAS_DRIVER_NAME
,
7139 MPT2SAS_DRIVER_VERSION
);
7141 mpt2sas_transport_template
=
7142 sas_attach_transport(&mpt2sas_transport_functions
);
7143 if (!mpt2sas_transport_template
)
7145 /* raid transport support */
7146 mpt2sas_raid_template
= raid_class_attach(&mpt2sas_raid_functions
);
7147 if (!mpt2sas_raid_template
) {
7148 sas_release_transport(mpt2sas_transport_template
);
7152 mpt2sas_base_initialize_callback_handler();
7154 /* queuecommand callback hander */
7155 scsi_io_cb_idx
= mpt2sas_base_register_callback_handler(_scsih_io_done
);
7157 /* task management callback handler */
7158 tm_cb_idx
= mpt2sas_base_register_callback_handler(_scsih_tm_done
);
7160 /* base internal commands callback handler */
7161 base_cb_idx
= mpt2sas_base_register_callback_handler(mpt2sas_base_done
);
7163 /* transport internal commands callback handler */
7164 transport_cb_idx
= mpt2sas_base_register_callback_handler(
7165 mpt2sas_transport_done
);
7167 /* scsih internal commands callback handler */
7168 scsih_cb_idx
= mpt2sas_base_register_callback_handler(_scsih_done
);
7170 /* configuration page API internal commands callback handler */
7171 config_cb_idx
= mpt2sas_base_register_callback_handler(
7172 mpt2sas_config_done
);
7174 /* ctl module callback handler */
7175 ctl_cb_idx
= mpt2sas_base_register_callback_handler(mpt2sas_ctl_done
);
7177 tm_tr_cb_idx
= mpt2sas_base_register_callback_handler(
7178 _scsih_tm_tr_complete
);
7180 tm_tr_volume_cb_idx
= mpt2sas_base_register_callback_handler(
7181 _scsih_tm_volume_tr_complete
);
7183 tm_sas_control_cb_idx
= mpt2sas_base_register_callback_handler(
7184 _scsih_sas_control_complete
);
7188 error
= pci_register_driver(&scsih_driver
);
7190 /* raid transport support */
7191 raid_class_release(mpt2sas_raid_template
);
7192 sas_release_transport(mpt2sas_transport_template
);
7199 * _scsih_exit - exit point for this driver (when it is a module).
7201 * Returns 0 success, anything else error.
7206 printk(KERN_INFO
"mpt2sas version %s unloading\n",
7207 MPT2SAS_DRIVER_VERSION
);
7209 pci_unregister_driver(&scsih_driver
);
7213 mpt2sas_base_release_callback_handler(scsi_io_cb_idx
);
7214 mpt2sas_base_release_callback_handler(tm_cb_idx
);
7215 mpt2sas_base_release_callback_handler(base_cb_idx
);
7216 mpt2sas_base_release_callback_handler(transport_cb_idx
);
7217 mpt2sas_base_release_callback_handler(scsih_cb_idx
);
7218 mpt2sas_base_release_callback_handler(config_cb_idx
);
7219 mpt2sas_base_release_callback_handler(ctl_cb_idx
);
7221 mpt2sas_base_release_callback_handler(tm_tr_cb_idx
);
7222 mpt2sas_base_release_callback_handler(tm_tr_volume_cb_idx
);
7223 mpt2sas_base_release_callback_handler(tm_sas_control_cb_idx
);
7225 /* raid transport support */
7226 raid_class_release(mpt2sas_raid_template
);
7227 sas_release_transport(mpt2sas_transport_template
);
7231 module_init(_scsih_init
);
7232 module_exit(_scsih_exit
);