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 if (event_data
->PHY
[i
].PhyStatus
&
2985 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT
)
2987 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
2990 reason_code
= event_data
->PHY
[i
].PhyStatus
&
2991 MPI2_EVENT_SAS_TOPO_RC_MASK
;
2992 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
)
2993 _scsih_tm_tr_send(ioc
, handle
);
2996 expander_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
2997 if (expander_handle
< ioc
->sas_hba
.num_phys
) {
2998 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
3002 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
3003 || event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
) {
3004 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
3005 sas_expander
= mpt2sas_scsih_expander_find_by_handle(ioc
,
3007 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
3008 _scsih_block_io_to_children_attached_to_ex(ioc
, sas_expander
);
3009 } else if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_RESPONDING
)
3010 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
3012 if (event_data
->ExpStatus
!= MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
)
3015 /* mark ignore flag for pending events */
3016 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
3017 list_for_each_entry(fw_event
, &ioc
->fw_event_list
, list
) {
3018 if (fw_event
->event
!= MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
||
3021 local_event_data
= fw_event
->event_data
;
3022 if (local_event_data
->ExpStatus
==
3023 MPI2_EVENT_SAS_TOPO_ES_ADDED
||
3024 local_event_data
->ExpStatus
==
3025 MPI2_EVENT_SAS_TOPO_ES_RESPONDING
) {
3026 if (le16_to_cpu(local_event_data
->ExpanderDevHandle
) ==
3028 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3029 "setting ignoring flag\n", ioc
->name
));
3030 fw_event
->ignore
= 1;
3034 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
3038 * _scsih_set_volume_delete_flag - setting volume delete flag
3039 * @ioc: per adapter object
3040 * @handle: device handle
3046 _scsih_set_volume_delete_flag(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
3048 struct _raid_device
*raid_device
;
3049 struct MPT2SAS_TARGET
*sas_target_priv_data
;
3050 unsigned long flags
;
3052 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
3053 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
3054 if (raid_device
&& raid_device
->starget
&&
3055 raid_device
->starget
->hostdata
) {
3056 sas_target_priv_data
=
3057 raid_device
->starget
->hostdata
;
3058 sas_target_priv_data
->deleted
= 1;
3059 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3060 "setting delete flag: handle(0x%04x), "
3061 "wwid(0x%016llx)\n", ioc
->name
, handle
,
3062 (unsigned long long) raid_device
->wwid
));
3064 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
3068 * _scsih_set_volume_handle_for_tr - set handle for target reset to volume
3069 * @handle: input handle
3070 * @a: handle for volume a
3071 * @b: handle for volume b
3073 * IR firmware only supports two raid volumes. The purpose of this
3074 * routine is to set the volume handle in either a or b. When the given
3075 * input handle is non-zero, or when a and b have not been set before.
3078 _scsih_set_volume_handle_for_tr(u16 handle
, u16
*a
, u16
*b
)
3080 if (!handle
|| handle
== *a
|| handle
== *b
)
3089 * _scsih_check_ir_config_unhide_events - check for UNHIDE events
3090 * @ioc: per adapter object
3091 * @event_data: the event data payload
3092 * Context: interrupt time.
3094 * This routine will send target reset to volume, followed by target
3095 * resets to the PDs. This is called when a PD has been removed, or
3096 * volume has been deleted or removed. When the target reset is sent
3097 * to volume, the PD target resets need to be queued to start upon
3098 * completion of the volume target reset.
3103 _scsih_check_ir_config_unhide_events(struct MPT2SAS_ADAPTER
*ioc
,
3104 Mpi2EventDataIrConfigChangeList_t
*event_data
)
3106 Mpi2EventIrConfigElement_t
*element
;
3108 u16 handle
, volume_handle
, a
, b
;
3109 struct _tr_list
*delayed_tr
;
3114 /* Volume Resets for Deleted or Removed */
3115 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
3116 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
3117 if (element
->ReasonCode
==
3118 MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
||
3119 element
->ReasonCode
==
3120 MPI2_EVENT_IR_CHANGE_RC_REMOVED
) {
3121 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
3122 _scsih_set_volume_delete_flag(ioc
, volume_handle
);
3123 _scsih_set_volume_handle_for_tr(volume_handle
, &a
, &b
);
3127 /* Volume Resets for UNHIDE events */
3128 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
3129 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
3130 if (le32_to_cpu(event_data
->Flags
) &
3131 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
)
3133 if (element
->ReasonCode
== MPI2_EVENT_IR_CHANGE_RC_UNHIDE
) {
3134 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
3135 _scsih_set_volume_handle_for_tr(volume_handle
, &a
, &b
);
3140 _scsih_tm_tr_volume_send(ioc
, a
);
3142 _scsih_tm_tr_volume_send(ioc
, b
);
3144 /* PD target resets */
3145 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
3146 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
3147 if (element
->ReasonCode
!= MPI2_EVENT_IR_CHANGE_RC_UNHIDE
)
3149 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
3150 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
3151 clear_bit(handle
, ioc
->pd_handles
);
3153 _scsih_tm_tr_send(ioc
, handle
);
3154 else if (volume_handle
== a
|| volume_handle
== b
) {
3155 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
3156 BUG_ON(!delayed_tr
);
3157 INIT_LIST_HEAD(&delayed_tr
->list
);
3158 delayed_tr
->handle
= handle
;
3159 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_list
);
3160 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3161 "DELAYED:tr:handle(0x%04x), (open)\n", ioc
->name
,
3164 _scsih_tm_tr_send(ioc
, handle
);
3170 * _scsih_check_volume_delete_events - set delete flag for volumes
3171 * @ioc: per adapter object
3172 * @event_data: the event data payload
3173 * Context: interrupt time.
3175 * This will handle the case when the cable connected to entire volume is
3176 * pulled. We will take care of setting the deleted flag so normal IO will
3182 _scsih_check_volume_delete_events(struct MPT2SAS_ADAPTER
*ioc
,
3183 Mpi2EventDataIrVolume_t
*event_data
)
3187 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED
)
3189 state
= le32_to_cpu(event_data
->NewValue
);
3190 if (state
== MPI2_RAID_VOL_STATE_MISSING
|| state
==
3191 MPI2_RAID_VOL_STATE_FAILED
)
3192 _scsih_set_volume_delete_flag(ioc
,
3193 le16_to_cpu(event_data
->VolDevHandle
));
3197 * _scsih_flush_running_cmds - completing outstanding commands.
3198 * @ioc: per adapter object
3200 * The flushing out of all pending scmd commands following host reset,
3201 * where all IO is dropped to the floor.
3206 _scsih_flush_running_cmds(struct MPT2SAS_ADAPTER
*ioc
)
3208 struct scsi_cmnd
*scmd
;
3212 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
3213 scmd
= _scsih_scsi_lookup_get(ioc
, smid
);
3217 mpt2sas_base_free_smid(ioc
, smid
);
3218 scsi_dma_unmap(scmd
);
3219 if (ioc
->pci_error_recovery
)
3220 scmd
->result
= DID_NO_CONNECT
<< 16;
3222 scmd
->result
= DID_RESET
<< 16;
3223 scmd
->scsi_done(scmd
);
3225 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"completing %d cmds\n",
3230 * _scsih_setup_eedp - setup MPI request for EEDP transfer
3231 * @scmd: pointer to scsi command object
3232 * @mpi_request: pointer to the SCSI_IO reqest message frame
3234 * Supporting protection 1 and 3.
3239 _scsih_setup_eedp(struct scsi_cmnd
*scmd
, Mpi2SCSIIORequest_t
*mpi_request
)
3242 unsigned char prot_op
= scsi_get_prot_op(scmd
);
3243 unsigned char prot_type
= scsi_get_prot_type(scmd
);
3245 if (prot_type
== SCSI_PROT_DIF_TYPE0
|| prot_op
== SCSI_PROT_NORMAL
)
3248 if (prot_op
== SCSI_PROT_READ_STRIP
)
3249 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP
;
3250 else if (prot_op
== SCSI_PROT_WRITE_INSERT
)
3251 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_INSERT_OP
;
3255 switch (prot_type
) {
3256 case SCSI_PROT_DIF_TYPE1
:
3259 * enable ref/guard checking
3260 * auto increment ref tag
3262 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG
|
3263 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG
|
3264 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
3265 mpi_request
->CDB
.EEDP32
.PrimaryReferenceTag
=
3266 cpu_to_be32(scsi_get_lba(scmd
));
3269 case SCSI_PROT_DIF_TYPE2
:
3271 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG
|
3272 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG
|
3273 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
3276 case SCSI_PROT_DIF_TYPE3
:
3279 * enable guard checking
3281 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
3284 mpi_request
->EEDPBlockSize
= cpu_to_le32(scmd
->device
->sector_size
);
3285 mpi_request
->EEDPFlags
= cpu_to_le16(eedp_flags
);
3289 * _scsih_eedp_error_handling - return sense code for EEDP errors
3290 * @scmd: pointer to scsi command object
3291 * @ioc_status: ioc status
3296 _scsih_eedp_error_handling(struct scsi_cmnd
*scmd
, u16 ioc_status
)
3302 switch (ioc_status
) {
3303 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
3306 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
3309 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
3317 if (scmd
->sc_data_direction
== DMA_TO_DEVICE
) {
3318 sk
= ILLEGAL_REQUEST
;
3319 host_byte
= DID_ABORT
;
3321 sk
= ABORTED_COMMAND
;
3325 scsi_build_sense_buffer(0, scmd
->sense_buffer
, sk
, 0x10, ascq
);
3326 scmd
->result
= DRIVER_SENSE
<< 24 | (host_byte
<< 16) |
3327 SAM_STAT_CHECK_CONDITION
;
3331 * _scsih_qcmd - main scsi request entry point
3332 * @scmd: pointer to scsi command object
3333 * @done: function pointer to be invoked on completion
3335 * The callback index is set inside `ioc->scsi_io_cb_idx`.
3337 * Returns 0 on success. If there's a failure, return either:
3338 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
3339 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
3342 _scsih_qcmd_lck(struct scsi_cmnd
*scmd
, void (*done
)(struct scsi_cmnd
*))
3344 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
3345 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
3346 struct MPT2SAS_TARGET
*sas_target_priv_data
;
3347 Mpi2SCSIIORequest_t
*mpi_request
;
3351 scmd
->scsi_done
= done
;
3352 sas_device_priv_data
= scmd
->device
->hostdata
;
3353 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
3354 scmd
->result
= DID_NO_CONNECT
<< 16;
3355 scmd
->scsi_done(scmd
);
3359 if (ioc
->pci_error_recovery
) {
3360 scmd
->result
= DID_NO_CONNECT
<< 16;
3361 scmd
->scsi_done(scmd
);
3365 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
3366 /* invalid device handle */
3367 if (sas_target_priv_data
->handle
== MPT2SAS_INVALID_DEVICE_HANDLE
) {
3368 scmd
->result
= DID_NO_CONNECT
<< 16;
3369 scmd
->scsi_done(scmd
);
3373 /* host recovery or link resets sent via IOCTLs */
3374 if (ioc
->shost_recovery
|| ioc
->ioc_link_reset_in_progress
)
3375 return SCSI_MLQUEUE_HOST_BUSY
;
3376 /* device busy with task management */
3377 else if (sas_device_priv_data
->block
|| sas_target_priv_data
->tm_busy
)
3378 return SCSI_MLQUEUE_DEVICE_BUSY
;
3379 /* device has been deleted */
3380 else if (sas_target_priv_data
->deleted
) {
3381 scmd
->result
= DID_NO_CONNECT
<< 16;
3382 scmd
->scsi_done(scmd
);
3386 if (scmd
->sc_data_direction
== DMA_FROM_DEVICE
)
3387 mpi_control
= MPI2_SCSIIO_CONTROL_READ
;
3388 else if (scmd
->sc_data_direction
== DMA_TO_DEVICE
)
3389 mpi_control
= MPI2_SCSIIO_CONTROL_WRITE
;
3391 mpi_control
= MPI2_SCSIIO_CONTROL_NODATATRANSFER
;
3394 if (!(sas_device_priv_data
->flags
& MPT_DEVICE_FLAGS_INIT
)) {
3395 if (scmd
->device
->tagged_supported
) {
3396 if (scmd
->device
->ordered_tags
)
3397 mpi_control
|= MPI2_SCSIIO_CONTROL_ORDEREDQ
;
3399 mpi_control
|= MPI2_SCSIIO_CONTROL_SIMPLEQ
;
3401 /* MPI Revision I (UNIT = 0xA) - removed MPI2_SCSIIO_CONTROL_UNTAGGED */
3402 /* mpi_control |= MPI2_SCSIIO_CONTROL_UNTAGGED;
3404 mpi_control
|= (0x500);
3407 mpi_control
|= MPI2_SCSIIO_CONTROL_SIMPLEQ
;
3408 /* Make sure Device is not raid volume */
3409 if (!_scsih_is_raid(&scmd
->device
->sdev_gendev
) &&
3410 sas_is_tlr_enabled(scmd
->device
) && scmd
->cmd_len
!= 32)
3411 mpi_control
|= MPI2_SCSIIO_CONTROL_TLR_ON
;
3413 smid
= mpt2sas_base_get_smid_scsiio(ioc
, ioc
->scsi_io_cb_idx
, scmd
);
3415 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
3416 ioc
->name
, __func__
);
3419 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3420 memset(mpi_request
, 0, sizeof(Mpi2SCSIIORequest_t
));
3421 _scsih_setup_eedp(scmd
, mpi_request
);
3422 if (scmd
->cmd_len
== 32)
3423 mpi_control
|= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT
;
3424 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
3425 if (sas_device_priv_data
->sas_target
->flags
&
3426 MPT_TARGET_FLAGS_RAID_COMPONENT
)
3427 mpi_request
->Function
= MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
;
3429 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
3430 mpi_request
->DevHandle
=
3431 cpu_to_le16(sas_device_priv_data
->sas_target
->handle
);
3432 mpi_request
->DataLength
= cpu_to_le32(scsi_bufflen(scmd
));
3433 mpi_request
->Control
= cpu_to_le32(mpi_control
);
3434 mpi_request
->IoFlags
= cpu_to_le16(scmd
->cmd_len
);
3435 mpi_request
->MsgFlags
= MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR
;
3436 mpi_request
->SenseBufferLength
= SCSI_SENSE_BUFFERSIZE
;
3437 mpi_request
->SenseBufferLowAddress
=
3438 mpt2sas_base_get_sense_buffer_dma(ioc
, smid
);
3439 mpi_request
->SGLOffset0
= offsetof(Mpi2SCSIIORequest_t
, SGL
) / 4;
3440 mpi_request
->SGLFlags
= cpu_to_le16(MPI2_SCSIIO_SGLFLAGS_TYPE_MPI
+
3441 MPI2_SCSIIO_SGLFLAGS_SYSTEM_ADDR
);
3442 mpi_request
->VF_ID
= 0; /* TODO */
3443 mpi_request
->VP_ID
= 0;
3444 int_to_scsilun(sas_device_priv_data
->lun
, (struct scsi_lun
*)
3446 memcpy(mpi_request
->CDB
.CDB32
, scmd
->cmnd
, scmd
->cmd_len
);
3448 if (!mpi_request
->DataLength
) {
3449 mpt2sas_base_build_zero_len_sge(ioc
, &mpi_request
->SGL
);
3451 if (_scsih_build_scatter_gather(ioc
, scmd
, smid
)) {
3452 mpt2sas_base_free_smid(ioc
, smid
);
3457 if (likely(mpi_request
->Function
== MPI2_FUNCTION_SCSI_IO_REQUEST
))
3458 mpt2sas_base_put_smid_scsi_io(ioc
, smid
,
3459 sas_device_priv_data
->sas_target
->handle
);
3461 mpt2sas_base_put_smid_default(ioc
, smid
);
3465 return SCSI_MLQUEUE_HOST_BUSY
;
3468 static DEF_SCSI_QCMD(_scsih_qcmd
)
3471 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
3472 * @sense_buffer: sense data returned by target
3473 * @data: normalized skey/asc/ascq
3478 _scsih_normalize_sense(char *sense_buffer
, struct sense_info
*data
)
3480 if ((sense_buffer
[0] & 0x7F) >= 0x72) {
3481 /* descriptor format */
3482 data
->skey
= sense_buffer
[1] & 0x0F;
3483 data
->asc
= sense_buffer
[2];
3484 data
->ascq
= sense_buffer
[3];
3487 data
->skey
= sense_buffer
[2] & 0x0F;
3488 data
->asc
= sense_buffer
[12];
3489 data
->ascq
= sense_buffer
[13];
3493 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3495 * _scsih_scsi_ioc_info - translated non-successfull SCSI_IO request
3496 * @ioc: per adapter object
3497 * @scmd: pointer to scsi command object
3498 * @mpi_reply: reply mf payload returned from firmware
3500 * scsi_status - SCSI Status code returned from target device
3501 * scsi_state - state info associated with SCSI_IO determined by ioc
3502 * ioc_status - ioc supplied status info
3507 _scsih_scsi_ioc_info(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
,
3508 Mpi2SCSIIOReply_t
*mpi_reply
, u16 smid
)
3512 u16 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) &
3513 MPI2_IOCSTATUS_MASK
;
3514 u8 scsi_state
= mpi_reply
->SCSIState
;
3515 u8 scsi_status
= mpi_reply
->SCSIStatus
;
3516 char *desc_ioc_state
= NULL
;
3517 char *desc_scsi_status
= NULL
;
3518 char *desc_scsi_state
= ioc
->tmp_string
;
3519 u32 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
3520 struct _sas_device
*sas_device
= NULL
;
3521 unsigned long flags
;
3522 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
3523 struct MPT2SAS_TARGET
*priv_target
= starget
->hostdata
;
3528 if (log_info
== 0x31170000)
3531 switch (ioc_status
) {
3532 case MPI2_IOCSTATUS_SUCCESS
:
3533 desc_ioc_state
= "success";
3535 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
3536 desc_ioc_state
= "invalid function";
3538 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
3539 desc_ioc_state
= "scsi recovered error";
3541 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE
:
3542 desc_ioc_state
= "scsi invalid dev handle";
3544 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
3545 desc_ioc_state
= "scsi device not there";
3547 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
3548 desc_ioc_state
= "scsi data overrun";
3550 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
3551 desc_ioc_state
= "scsi data underrun";
3553 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
3554 desc_ioc_state
= "scsi io data error";
3556 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
3557 desc_ioc_state
= "scsi protocol error";
3559 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
3560 desc_ioc_state
= "scsi task terminated";
3562 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
3563 desc_ioc_state
= "scsi residual mismatch";
3565 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
3566 desc_ioc_state
= "scsi task mgmt failed";
3568 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
3569 desc_ioc_state
= "scsi ioc terminated";
3571 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
3572 desc_ioc_state
= "scsi ext terminated";
3574 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
3575 desc_ioc_state
= "eedp guard error";
3577 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
3578 desc_ioc_state
= "eedp ref tag error";
3580 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
3581 desc_ioc_state
= "eedp app tag error";
3584 desc_ioc_state
= "unknown";
3588 switch (scsi_status
) {
3589 case MPI2_SCSI_STATUS_GOOD
:
3590 desc_scsi_status
= "good";
3592 case MPI2_SCSI_STATUS_CHECK_CONDITION
:
3593 desc_scsi_status
= "check condition";
3595 case MPI2_SCSI_STATUS_CONDITION_MET
:
3596 desc_scsi_status
= "condition met";
3598 case MPI2_SCSI_STATUS_BUSY
:
3599 desc_scsi_status
= "busy";
3601 case MPI2_SCSI_STATUS_INTERMEDIATE
:
3602 desc_scsi_status
= "intermediate";
3604 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET
:
3605 desc_scsi_status
= "intermediate condmet";
3607 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT
:
3608 desc_scsi_status
= "reservation conflict";
3610 case MPI2_SCSI_STATUS_COMMAND_TERMINATED
:
3611 desc_scsi_status
= "command terminated";
3613 case MPI2_SCSI_STATUS_TASK_SET_FULL
:
3614 desc_scsi_status
= "task set full";
3616 case MPI2_SCSI_STATUS_ACA_ACTIVE
:
3617 desc_scsi_status
= "aca active";
3619 case MPI2_SCSI_STATUS_TASK_ABORTED
:
3620 desc_scsi_status
= "task aborted";
3623 desc_scsi_status
= "unknown";
3627 desc_scsi_state
[0] = '\0';
3629 desc_scsi_state
= " ";
3630 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
3631 strcat(desc_scsi_state
, "response info ");
3632 if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
3633 strcat(desc_scsi_state
, "state terminated ");
3634 if (scsi_state
& MPI2_SCSI_STATE_NO_SCSI_STATUS
)
3635 strcat(desc_scsi_state
, "no status ");
3636 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_FAILED
)
3637 strcat(desc_scsi_state
, "autosense failed ");
3638 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
)
3639 strcat(desc_scsi_state
, "autosense valid ");
3641 scsi_print_command(scmd
);
3643 if (priv_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
3644 printk(MPT2SAS_WARN_FMT
"\tvolume wwid(0x%016llx)\n", ioc
->name
,
3645 (unsigned long long)priv_target
->sas_address
);
3647 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
3648 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
3649 priv_target
->sas_address
);
3651 printk(MPT2SAS_WARN_FMT
"\tsas_address(0x%016llx), "
3652 "phy(%d)\n", ioc
->name
, sas_device
->sas_address
,
3654 printk(MPT2SAS_WARN_FMT
3655 "\tenclosure_logical_id(0x%016llx), slot(%d)\n",
3656 ioc
->name
, sas_device
->enclosure_logical_id
,
3659 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3662 printk(MPT2SAS_WARN_FMT
"\thandle(0x%04x), ioc_status(%s)(0x%04x), "
3663 "smid(%d)\n", ioc
->name
, le16_to_cpu(mpi_reply
->DevHandle
),
3664 desc_ioc_state
, ioc_status
, smid
);
3665 printk(MPT2SAS_WARN_FMT
"\trequest_len(%d), underflow(%d), "
3666 "resid(%d)\n", ioc
->name
, scsi_bufflen(scmd
), scmd
->underflow
,
3667 scsi_get_resid(scmd
));
3668 printk(MPT2SAS_WARN_FMT
"\ttag(%d), transfer_count(%d), "
3669 "sc->result(0x%08x)\n", ioc
->name
, le16_to_cpu(mpi_reply
->TaskTag
),
3670 le32_to_cpu(mpi_reply
->TransferCount
), scmd
->result
);
3671 printk(MPT2SAS_WARN_FMT
"\tscsi_status(%s)(0x%02x), "
3672 "scsi_state(%s)(0x%02x)\n", ioc
->name
, desc_scsi_status
,
3673 scsi_status
, desc_scsi_state
, scsi_state
);
3675 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
3676 struct sense_info data
;
3677 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
3678 printk(MPT2SAS_WARN_FMT
"\t[sense_key,asc,ascq]: "
3679 "[0x%02x,0x%02x,0x%02x], count(%d)\n", ioc
->name
, data
.skey
,
3680 data
.asc
, data
.ascq
, le32_to_cpu(mpi_reply
->SenseCount
));
3683 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
) {
3684 response_info
= le32_to_cpu(mpi_reply
->ResponseInfo
);
3685 response_bytes
= (u8
*)&response_info
;
3686 _scsih_response_code(ioc
, response_bytes
[0]);
3692 * _scsih_smart_predicted_fault - illuminate Fault LED
3693 * @ioc: per adapter object
3694 * @handle: device handle
3699 _scsih_smart_predicted_fault(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
3701 Mpi2SepReply_t mpi_reply
;
3702 Mpi2SepRequest_t mpi_request
;
3703 struct scsi_target
*starget
;
3704 struct MPT2SAS_TARGET
*sas_target_priv_data
;
3705 Mpi2EventNotificationReply_t
*event_reply
;
3706 Mpi2EventDataSasDeviceStatusChange_t
*event_data
;
3707 struct _sas_device
*sas_device
;
3709 unsigned long flags
;
3711 /* only handle non-raid devices */
3712 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
3713 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
3715 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3718 starget
= sas_device
->starget
;
3719 sas_target_priv_data
= starget
->hostdata
;
3721 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
) ||
3722 ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
))) {
3723 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3726 starget_printk(KERN_WARNING
, starget
, "predicted fault\n");
3727 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3729 if (ioc
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_IBM
) {
3730 memset(&mpi_request
, 0, sizeof(Mpi2SepRequest_t
));
3731 mpi_request
.Function
= MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR
;
3732 mpi_request
.Action
= MPI2_SEP_REQ_ACTION_WRITE_STATUS
;
3733 mpi_request
.SlotStatus
=
3734 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT
);
3735 mpi_request
.DevHandle
= cpu_to_le16(handle
);
3736 mpi_request
.Flags
= MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS
;
3737 if ((mpt2sas_base_scsi_enclosure_processor(ioc
, &mpi_reply
,
3738 &mpi_request
)) != 0) {
3739 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3740 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3744 if (mpi_reply
.IOCStatus
|| mpi_reply
.IOCLogInfo
) {
3745 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3746 "enclosure_processor: ioc_status (0x%04x), "
3747 "loginfo(0x%08x)\n", ioc
->name
,
3748 le16_to_cpu(mpi_reply
.IOCStatus
),
3749 le32_to_cpu(mpi_reply
.IOCLogInfo
)));
3754 /* insert into event log */
3755 sz
= offsetof(Mpi2EventNotificationReply_t
, EventData
) +
3756 sizeof(Mpi2EventDataSasDeviceStatusChange_t
);
3757 event_reply
= kzalloc(sz
, GFP_KERNEL
);
3759 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3760 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3764 event_reply
->Function
= MPI2_FUNCTION_EVENT_NOTIFICATION
;
3765 event_reply
->Event
=
3766 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
);
3767 event_reply
->MsgLength
= sz
/4;
3768 event_reply
->EventDataLength
=
3769 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t
)/4);
3770 event_data
= (Mpi2EventDataSasDeviceStatusChange_t
*)
3771 event_reply
->EventData
;
3772 event_data
->ReasonCode
= MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
;
3773 event_data
->ASC
= 0x5D;
3774 event_data
->DevHandle
= cpu_to_le16(handle
);
3775 event_data
->SASAddress
= cpu_to_le64(sas_target_priv_data
->sas_address
);
3776 mpt2sas_ctl_add_to_event_log(ioc
, event_reply
);
3781 * _scsih_io_done - scsi request callback
3782 * @ioc: per adapter object
3783 * @smid: system request message index
3784 * @msix_index: MSIX table index supplied by the OS
3785 * @reply: reply message frame(lower 32bit addr)
3787 * Callback handler when using _scsih_qcmd.
3789 * Return 1 meaning mf should be freed from _base_interrupt
3790 * 0 means the mf is freed from this function.
3793 _scsih_io_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
3795 Mpi2SCSIIORequest_t
*mpi_request
;
3796 Mpi2SCSIIOReply_t
*mpi_reply
;
3797 struct scsi_cmnd
*scmd
;
3803 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
3804 u32 response_code
= 0;
3806 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
3807 scmd
= _scsih_scsi_lookup_get(ioc
, smid
);
3811 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3813 if (mpi_reply
== NULL
) {
3814 scmd
->result
= DID_OK
<< 16;
3818 sas_device_priv_data
= scmd
->device
->hostdata
;
3819 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
||
3820 sas_device_priv_data
->sas_target
->deleted
) {
3821 scmd
->result
= DID_NO_CONNECT
<< 16;
3825 /* turning off TLR */
3826 scsi_state
= mpi_reply
->SCSIState
;
3827 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
3829 le32_to_cpu(mpi_reply
->ResponseInfo
) & 0xFF;
3830 if (!sas_device_priv_data
->tlr_snoop_check
) {
3831 sas_device_priv_data
->tlr_snoop_check
++;
3832 if (!_scsih_is_raid(&scmd
->device
->sdev_gendev
) &&
3833 sas_is_tlr_enabled(scmd
->device
) &&
3834 response_code
== MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
) {
3835 sas_disable_tlr(scmd
->device
);
3836 sdev_printk(KERN_INFO
, scmd
->device
, "TLR disabled\n");
3840 xfer_cnt
= le32_to_cpu(mpi_reply
->TransferCount
);
3841 scsi_set_resid(scmd
, scsi_bufflen(scmd
) - xfer_cnt
);
3842 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
);
3843 if (ioc_status
& MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE
)
3844 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
3847 ioc_status
&= MPI2_IOCSTATUS_MASK
;
3848 scsi_status
= mpi_reply
->SCSIStatus
;
3850 if (ioc_status
== MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
&& xfer_cnt
== 0 &&
3851 (scsi_status
== MPI2_SCSI_STATUS_BUSY
||
3852 scsi_status
== MPI2_SCSI_STATUS_RESERVATION_CONFLICT
||
3853 scsi_status
== MPI2_SCSI_STATUS_TASK_SET_FULL
)) {
3854 ioc_status
= MPI2_IOCSTATUS_SUCCESS
;
3857 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
3858 struct sense_info data
;
3859 const void *sense_data
= mpt2sas_base_get_sense_buffer(ioc
,
3861 u32 sz
= min_t(u32
, SCSI_SENSE_BUFFERSIZE
,
3862 le32_to_cpu(mpi_reply
->SenseCount
));
3863 memcpy(scmd
->sense_buffer
, sense_data
, sz
);
3864 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
3865 /* failure prediction threshold exceeded */
3866 if (data
.asc
== 0x5D)
3867 _scsih_smart_predicted_fault(ioc
,
3868 le16_to_cpu(mpi_reply
->DevHandle
));
3871 switch (ioc_status
) {
3872 case MPI2_IOCSTATUS_BUSY
:
3873 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES
:
3874 scmd
->result
= SAM_STAT_BUSY
;
3877 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
3878 scmd
->result
= DID_NO_CONNECT
<< 16;
3881 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
3882 if (sas_device_priv_data
->block
) {
3883 scmd
->result
= DID_TRANSPORT_DISRUPTED
<< 16;
3886 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
3887 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
3888 scmd
->result
= DID_RESET
<< 16;
3891 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
3892 if ((xfer_cnt
== 0) || (scmd
->underflow
> xfer_cnt
))
3893 scmd
->result
= DID_SOFT_ERROR
<< 16;
3895 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
3898 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
3899 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
3901 if ((scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
))
3904 if (xfer_cnt
< scmd
->underflow
) {
3905 if (scsi_status
== SAM_STAT_BUSY
)
3906 scmd
->result
= SAM_STAT_BUSY
;
3908 scmd
->result
= DID_SOFT_ERROR
<< 16;
3909 } else if (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
3910 MPI2_SCSI_STATE_NO_SCSI_STATUS
))
3911 scmd
->result
= DID_SOFT_ERROR
<< 16;
3912 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
3913 scmd
->result
= DID_RESET
<< 16;
3914 else if (!xfer_cnt
&& scmd
->cmnd
[0] == REPORT_LUNS
) {
3915 mpi_reply
->SCSIState
= MPI2_SCSI_STATE_AUTOSENSE_VALID
;
3916 mpi_reply
->SCSIStatus
= SAM_STAT_CHECK_CONDITION
;
3917 scmd
->result
= (DRIVER_SENSE
<< 24) |
3918 SAM_STAT_CHECK_CONDITION
;
3919 scmd
->sense_buffer
[0] = 0x70;
3920 scmd
->sense_buffer
[2] = ILLEGAL_REQUEST
;
3921 scmd
->sense_buffer
[12] = 0x20;
3922 scmd
->sense_buffer
[13] = 0;
3926 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
3927 scsi_set_resid(scmd
, 0);
3928 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
3929 case MPI2_IOCSTATUS_SUCCESS
:
3930 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
3931 if (response_code
==
3932 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
||
3933 (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
3934 MPI2_SCSI_STATE_NO_SCSI_STATUS
)))
3935 scmd
->result
= DID_SOFT_ERROR
<< 16;
3936 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
3937 scmd
->result
= DID_RESET
<< 16;
3940 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
3941 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
3942 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
3943 _scsih_eedp_error_handling(scmd
, ioc_status
);
3945 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
3946 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
3947 case MPI2_IOCSTATUS_INVALID_SGL
:
3948 case MPI2_IOCSTATUS_INTERNAL_ERROR
:
3949 case MPI2_IOCSTATUS_INVALID_FIELD
:
3950 case MPI2_IOCSTATUS_INVALID_STATE
:
3951 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
3952 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
3954 scmd
->result
= DID_SOFT_ERROR
<< 16;
3959 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3960 if (scmd
->result
&& (ioc
->logging_level
& MPT_DEBUG_REPLY
))
3961 _scsih_scsi_ioc_info(ioc
, scmd
, mpi_reply
, smid
);
3965 scsi_dma_unmap(scmd
);
3966 scmd
->scsi_done(scmd
);
3971 * _scsih_sas_host_refresh - refreshing sas host object contents
3972 * @ioc: per adapter object
3975 * During port enable, fw will send topology events for every device. Its
3976 * possible that the handles may change from the previous setting, so this
3977 * code keeping handles updating if changed.
3982 _scsih_sas_host_refresh(struct MPT2SAS_ADAPTER
*ioc
)
3987 Mpi2ConfigReply_t mpi_reply
;
3988 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
3989 u16 attached_handle
;
3992 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
3993 "updating handles for sas_host(0x%016llx)\n",
3994 ioc
->name
, (unsigned long long)ioc
->sas_hba
.sas_address
));
3996 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
3997 * sizeof(Mpi2SasIOUnit0PhyData_t
));
3998 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
3999 if (!sas_iounit_pg0
) {
4000 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4001 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4005 if ((mpt2sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
4006 sas_iounit_pg0
, sz
)) != 0)
4008 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
4009 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
4011 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
4012 link_rate
= sas_iounit_pg0
->PhyData
[i
].NegotiatedLinkRate
>> 4;
4014 ioc
->sas_hba
.handle
= le16_to_cpu(sas_iounit_pg0
->
4015 PhyData
[0].ControllerDevHandle
);
4016 ioc
->sas_hba
.phy
[i
].handle
= ioc
->sas_hba
.handle
;
4017 attached_handle
= le16_to_cpu(sas_iounit_pg0
->PhyData
[i
].
4019 if (attached_handle
&& link_rate
< MPI2_SAS_NEG_LINK_RATE_1_5
)
4020 link_rate
= MPI2_SAS_NEG_LINK_RATE_1_5
;
4021 mpt2sas_transport_update_links(ioc
, ioc
->sas_hba
.sas_address
,
4022 attached_handle
, i
, link_rate
);
4025 kfree(sas_iounit_pg0
);
4029 * _scsih_sas_host_add - create sas host object
4030 * @ioc: per adapter object
4032 * Creating host side data object, stored in ioc->sas_hba
4037 _scsih_sas_host_add(struct MPT2SAS_ADAPTER
*ioc
)
4040 Mpi2ConfigReply_t mpi_reply
;
4041 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
4042 Mpi2SasIOUnitPage1_t
*sas_iounit_pg1
= NULL
;
4043 Mpi2SasPhyPage0_t phy_pg0
;
4044 Mpi2SasDevicePage0_t sas_device_pg0
;
4045 Mpi2SasEnclosurePage0_t enclosure_pg0
;
4048 u16 device_missing_delay
;
4050 mpt2sas_config_get_number_hba_phys(ioc
, &ioc
->sas_hba
.num_phys
);
4051 if (!ioc
->sas_hba
.num_phys
) {
4052 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4053 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4057 /* sas_iounit page 0 */
4058 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
4059 sizeof(Mpi2SasIOUnit0PhyData_t
));
4060 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
4061 if (!sas_iounit_pg0
) {
4062 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4063 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4066 if ((mpt2sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
4067 sas_iounit_pg0
, sz
))) {
4068 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4069 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4072 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4073 MPI2_IOCSTATUS_MASK
;
4074 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4075 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4076 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4080 /* sas_iounit page 1 */
4081 sz
= offsetof(Mpi2SasIOUnitPage1_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
4082 sizeof(Mpi2SasIOUnit1PhyData_t
));
4083 sas_iounit_pg1
= kzalloc(sz
, GFP_KERNEL
);
4084 if (!sas_iounit_pg1
) {
4085 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4086 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4089 if ((mpt2sas_config_get_sas_iounit_pg1(ioc
, &mpi_reply
,
4090 sas_iounit_pg1
, sz
))) {
4091 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4092 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4095 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4096 MPI2_IOCSTATUS_MASK
;
4097 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4098 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4099 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4103 ioc
->io_missing_delay
=
4104 le16_to_cpu(sas_iounit_pg1
->IODeviceMissingDelay
);
4105 device_missing_delay
=
4106 le16_to_cpu(sas_iounit_pg1
->ReportDeviceMissingDelay
);
4107 if (device_missing_delay
& MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16
)
4108 ioc
->device_missing_delay
= (device_missing_delay
&
4109 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
) * 16;
4111 ioc
->device_missing_delay
= device_missing_delay
&
4112 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
;
4114 ioc
->sas_hba
.parent_dev
= &ioc
->shost
->shost_gendev
;
4115 ioc
->sas_hba
.phy
= kcalloc(ioc
->sas_hba
.num_phys
,
4116 sizeof(struct _sas_phy
), GFP_KERNEL
);
4117 if (!ioc
->sas_hba
.phy
) {
4118 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4119 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4122 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
4123 if ((mpt2sas_config_get_phy_pg0(ioc
, &mpi_reply
, &phy_pg0
,
4125 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4126 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4129 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4130 MPI2_IOCSTATUS_MASK
;
4131 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4132 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4133 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4138 ioc
->sas_hba
.handle
= le16_to_cpu(sas_iounit_pg0
->
4139 PhyData
[0].ControllerDevHandle
);
4140 ioc
->sas_hba
.phy
[i
].handle
= ioc
->sas_hba
.handle
;
4141 ioc
->sas_hba
.phy
[i
].phy_id
= i
;
4142 mpt2sas_transport_add_host_phy(ioc
, &ioc
->sas_hba
.phy
[i
],
4143 phy_pg0
, ioc
->sas_hba
.parent_dev
);
4145 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
4146 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, ioc
->sas_hba
.handle
))) {
4147 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4148 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4151 ioc
->sas_hba
.enclosure_handle
=
4152 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
4153 ioc
->sas_hba
.sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
4154 printk(MPT2SAS_INFO_FMT
"host_add: handle(0x%04x), "
4155 "sas_addr(0x%016llx), phys(%d)\n", ioc
->name
, ioc
->sas_hba
.handle
,
4156 (unsigned long long) ioc
->sas_hba
.sas_address
,
4157 ioc
->sas_hba
.num_phys
) ;
4159 if (ioc
->sas_hba
.enclosure_handle
) {
4160 if (!(mpt2sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
4162 MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
4163 ioc
->sas_hba
.enclosure_handle
))) {
4164 ioc
->sas_hba
.enclosure_logical_id
=
4165 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
4170 kfree(sas_iounit_pg1
);
4171 kfree(sas_iounit_pg0
);
4175 * _scsih_expander_add - creating expander object
4176 * @ioc: per adapter object
4177 * @handle: expander handle
4179 * Creating expander object, stored in ioc->sas_expander_list.
4181 * Return 0 for success, else error.
4184 _scsih_expander_add(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
4186 struct _sas_node
*sas_expander
;
4187 Mpi2ConfigReply_t mpi_reply
;
4188 Mpi2ExpanderPage0_t expander_pg0
;
4189 Mpi2ExpanderPage1_t expander_pg1
;
4190 Mpi2SasEnclosurePage0_t enclosure_pg0
;
4193 __le64 sas_address
, sas_address_parent
= 0;
4195 unsigned long flags
;
4196 struct _sas_port
*mpt2sas_port
= NULL
;
4202 if (ioc
->shost_recovery
|| ioc
->pci_error_recovery
)
4205 if ((mpt2sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
4206 MPI2_SAS_EXPAND_PGAD_FORM_HNDL
, handle
))) {
4207 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4208 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4212 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4213 MPI2_IOCSTATUS_MASK
;
4214 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4215 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4216 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4220 /* handle out of order topology events */
4221 parent_handle
= le16_to_cpu(expander_pg0
.ParentDevHandle
);
4222 if (_scsih_get_sas_address(ioc
, parent_handle
, &sas_address_parent
)
4224 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4225 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4228 if (sas_address_parent
!= ioc
->sas_hba
.sas_address
) {
4229 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
4230 sas_expander
= mpt2sas_scsih_expander_find_by_sas_address(ioc
,
4231 sas_address_parent
);
4232 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
4233 if (!sas_expander
) {
4234 rc
= _scsih_expander_add(ioc
, parent_handle
);
4240 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
4241 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
4242 sas_expander
= mpt2sas_scsih_expander_find_by_sas_address(ioc
,
4244 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
4249 sas_expander
= kzalloc(sizeof(struct _sas_node
),
4251 if (!sas_expander
) {
4252 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4253 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4257 sas_expander
->handle
= handle
;
4258 sas_expander
->num_phys
= expander_pg0
.NumPhys
;
4259 sas_expander
->sas_address_parent
= sas_address_parent
;
4260 sas_expander
->sas_address
= sas_address
;
4262 printk(MPT2SAS_INFO_FMT
"expander_add: handle(0x%04x),"
4263 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc
->name
,
4264 handle
, parent_handle
, (unsigned long long)
4265 sas_expander
->sas_address
, sas_expander
->num_phys
);
4267 if (!sas_expander
->num_phys
)
4269 sas_expander
->phy
= kcalloc(sas_expander
->num_phys
,
4270 sizeof(struct _sas_phy
), GFP_KERNEL
);
4271 if (!sas_expander
->phy
) {
4272 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4273 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4278 INIT_LIST_HEAD(&sas_expander
->sas_port_list
);
4279 mpt2sas_port
= mpt2sas_transport_port_add(ioc
, handle
,
4280 sas_address_parent
);
4281 if (!mpt2sas_port
) {
4282 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4283 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4287 sas_expander
->parent_dev
= &mpt2sas_port
->rphy
->dev
;
4289 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++) {
4290 if ((mpt2sas_config_get_expander_pg1(ioc
, &mpi_reply
,
4291 &expander_pg1
, i
, handle
))) {
4292 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4293 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4297 sas_expander
->phy
[i
].handle
= handle
;
4298 sas_expander
->phy
[i
].phy_id
= i
;
4300 if ((mpt2sas_transport_add_expander_phy(ioc
,
4301 &sas_expander
->phy
[i
], expander_pg1
,
4302 sas_expander
->parent_dev
))) {
4303 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4304 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4310 if (sas_expander
->enclosure_handle
) {
4311 if (!(mpt2sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
4312 &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
4313 sas_expander
->enclosure_handle
))) {
4314 sas_expander
->enclosure_logical_id
=
4315 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
4319 _scsih_expander_node_add(ioc
, sas_expander
);
4325 mpt2sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
4326 sas_address_parent
);
4327 kfree(sas_expander
);
4332 * _scsih_done - scsih callback handler.
4333 * @ioc: per adapter object
4334 * @smid: system request message index
4335 * @msix_index: MSIX table index supplied by the OS
4336 * @reply: reply message frame(lower 32bit addr)
4338 * Callback handler when sending internal generated message frames.
4339 * The callback index passed is `ioc->scsih_cb_idx`
4341 * Return 1 meaning mf should be freed from _base_interrupt
4342 * 0 means the mf is freed from this function.
4345 _scsih_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
4347 MPI2DefaultReply_t
*mpi_reply
;
4349 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
4350 if (ioc
->scsih_cmds
.status
== MPT2_CMD_NOT_USED
)
4352 if (ioc
->scsih_cmds
.smid
!= smid
)
4354 ioc
->scsih_cmds
.status
|= MPT2_CMD_COMPLETE
;
4356 memcpy(ioc
->scsih_cmds
.reply
, mpi_reply
,
4357 mpi_reply
->MsgLength
*4);
4358 ioc
->scsih_cmds
.status
|= MPT2_CMD_REPLY_VALID
;
4360 ioc
->scsih_cmds
.status
&= ~MPT2_CMD_PENDING
;
4361 complete(&ioc
->scsih_cmds
.done
);
4366 * mpt2sas_expander_remove - removing expander object
4367 * @ioc: per adapter object
4368 * @sas_address: expander sas_address
4373 mpt2sas_expander_remove(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
)
4375 struct _sas_node
*sas_expander
;
4376 unsigned long flags
;
4378 if (ioc
->shost_recovery
)
4381 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
4382 sas_expander
= mpt2sas_scsih_expander_find_by_sas_address(ioc
,
4384 if (!sas_expander
) {
4385 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
4388 list_del(&sas_expander
->list
);
4389 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
4390 _scsih_expander_node_remove(ioc
, sas_expander
);
4394 * _scsih_check_access_status - check access flags
4395 * @ioc: per adapter object
4396 * @sas_address: sas address
4397 * @handle: sas device handle
4398 * @access_flags: errors returned during discovery of the device
4400 * Return 0 for success, else failure
4403 _scsih_check_access_status(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
,
4404 u16 handle
, u8 access_status
)
4409 switch (access_status
) {
4410 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS
:
4411 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION
:
4414 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED
:
4415 desc
= "sata capability failed";
4417 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT
:
4418 desc
= "sata affiliation conflict";
4420 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE
:
4421 desc
= "route not addressable";
4423 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE
:
4424 desc
= "smp error not addressable";
4426 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED
:
4427 desc
= "device blocked";
4429 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED
:
4430 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN
:
4431 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT
:
4432 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG
:
4433 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION
:
4434 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER
:
4435 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN
:
4436 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN
:
4437 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN
:
4438 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION
:
4439 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE
:
4440 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX
:
4441 desc
= "sata initialization failed";
4451 printk(MPT2SAS_ERR_FMT
"discovery errors(%s): sas_address(0x%016llx), "
4452 "handle(0x%04x)\n", ioc
->name
, desc
,
4453 (unsigned long long)sas_address
, handle
);
4458 _scsih_check_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
4460 Mpi2ConfigReply_t mpi_reply
;
4461 Mpi2SasDevicePage0_t sas_device_pg0
;
4462 struct _sas_device
*sas_device
;
4464 unsigned long flags
;
4466 struct scsi_target
*starget
;
4467 struct MPT2SAS_TARGET
*sas_target_priv_data
;
4470 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
4471 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
)))
4474 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
4475 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
4478 /* check if this is end device */
4479 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
4480 if (!(_scsih_is_end_device(device_info
)))
4483 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4484 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
4485 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
4489 printk(MPT2SAS_ERR_FMT
"device is not present "
4490 "handle(0x%04x), no sas_device!!!\n", ioc
->name
, handle
);
4491 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4495 if (unlikely(sas_device
->handle
!= handle
)) {
4496 starget
= sas_device
->starget
;
4497 sas_target_priv_data
= starget
->hostdata
;
4498 starget_printk(KERN_INFO
, starget
, "handle changed from(0x%04x)"
4499 " to (0x%04x)!!!\n", sas_device
->handle
, handle
);
4500 sas_target_priv_data
->handle
= handle
;
4501 sas_device
->handle
= handle
;
4503 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4505 /* check if device is present */
4506 if (!(le16_to_cpu(sas_device_pg0
.Flags
) &
4507 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT
)) {
4508 printk(MPT2SAS_ERR_FMT
"device is not present "
4509 "handle(0x%04x), flags!!!\n", ioc
->name
, handle
);
4513 /* check if there were any issues with discovery */
4514 if (_scsih_check_access_status(ioc
, sas_address
, handle
,
4515 sas_device_pg0
.AccessStatus
))
4517 _scsih_ublock_io_device(ioc
, handle
);
4522 * _scsih_add_device - creating sas device object
4523 * @ioc: per adapter object
4524 * @handle: sas device handle
4525 * @phy_num: phy number end device attached to
4526 * @is_pd: is this hidden raid component
4528 * Creating end device object, stored in ioc->sas_device_list.
4530 * Returns 0 for success, non-zero for failure.
4533 _scsih_add_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
, u8 phy_num
, u8 is_pd
)
4535 Mpi2ConfigReply_t mpi_reply
;
4536 Mpi2SasDevicePage0_t sas_device_pg0
;
4537 Mpi2SasEnclosurePage0_t enclosure_pg0
;
4538 struct _sas_device
*sas_device
;
4542 unsigned long flags
;
4544 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
4545 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
4546 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4547 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4551 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4552 MPI2_IOCSTATUS_MASK
;
4553 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4554 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4555 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4559 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
4561 /* check if device is present */
4562 if (!(le16_to_cpu(sas_device_pg0
.Flags
) &
4563 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT
)) {
4564 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4565 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4566 printk(MPT2SAS_ERR_FMT
"Flags = 0x%04x\n",
4567 ioc
->name
, le16_to_cpu(sas_device_pg0
.Flags
));
4571 /* check if there were any issues with discovery */
4572 if (_scsih_check_access_status(ioc
, sas_address
, handle
,
4573 sas_device_pg0
.AccessStatus
))
4576 /* check if this is end device */
4577 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
4578 if (!(_scsih_is_end_device(device_info
))) {
4579 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4580 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4585 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4586 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
4588 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4593 sas_device
= kzalloc(sizeof(struct _sas_device
),
4596 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4597 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4601 sas_device
->handle
= handle
;
4602 if (_scsih_get_sas_address(ioc
, le16_to_cpu
4603 (sas_device_pg0
.ParentDevHandle
),
4604 &sas_device
->sas_address_parent
) != 0)
4605 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4606 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4607 sas_device
->enclosure_handle
=
4608 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
4610 le16_to_cpu(sas_device_pg0
.Slot
);
4611 sas_device
->device_info
= device_info
;
4612 sas_device
->sas_address
= sas_address
;
4613 sas_device
->phy
= sas_device_pg0
.PhyNum
;
4615 /* get enclosure_logical_id */
4616 if (sas_device
->enclosure_handle
&& !(mpt2sas_config_get_enclosure_pg0(
4617 ioc
, &mpi_reply
, &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
4618 sas_device
->enclosure_handle
)))
4619 sas_device
->enclosure_logical_id
=
4620 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
4622 /* get device name */
4623 sas_device
->device_name
= le64_to_cpu(sas_device_pg0
.DeviceName
);
4625 if (ioc
->wait_for_port_enable_to_complete
)
4626 _scsih_sas_device_init_add(ioc
, sas_device
);
4628 _scsih_sas_device_add(ioc
, sas_device
);
4634 * _scsih_remove_device - removing sas device object
4635 * @ioc: per adapter object
4636 * @sas_device_delete: the sas_device object
4641 _scsih_remove_device(struct MPT2SAS_ADAPTER
*ioc
,
4642 struct _sas_device
*sas_device
)
4644 struct _sas_device sas_device_backup
;
4645 struct MPT2SAS_TARGET
*sas_target_priv_data
;
4650 memcpy(&sas_device_backup
, sas_device
, sizeof(struct _sas_device
));
4651 _scsih_sas_device_remove(ioc
, sas_device
);
4653 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: enter: "
4654 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
, __func__
,
4655 sas_device_backup
.handle
, (unsigned long long)
4656 sas_device_backup
.sas_address
));
4658 if (sas_device_backup
.starget
&& sas_device_backup
.starget
->hostdata
) {
4659 sas_target_priv_data
= sas_device_backup
.starget
->hostdata
;
4660 sas_target_priv_data
->deleted
= 1;
4663 _scsih_ublock_io_device(ioc
, sas_device_backup
.handle
);
4665 mpt2sas_transport_port_remove(ioc
, sas_device_backup
.sas_address
,
4666 sas_device_backup
.sas_address_parent
);
4668 printk(MPT2SAS_INFO_FMT
"removing handle(0x%04x), sas_addr"
4669 "(0x%016llx)\n", ioc
->name
, sas_device_backup
.handle
,
4670 (unsigned long long) sas_device_backup
.sas_address
);
4672 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: exit: "
4673 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
, __func__
,
4674 sas_device_backup
.handle
, (unsigned long long)
4675 sas_device_backup
.sas_address
));
4679 * mpt2sas_device_remove - removing device object
4680 * @ioc: per adapter object
4681 * @sas_address: expander sas_address
4686 mpt2sas_device_remove(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
)
4688 struct _sas_device
*sas_device
;
4689 unsigned long flags
;
4691 if (ioc
->shost_recovery
)
4694 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4695 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
4698 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4701 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4702 _scsih_remove_device(ioc
, sas_device
);
4705 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4707 * _scsih_sas_topology_change_event_debug - debug for topology event
4708 * @ioc: per adapter object
4709 * @event_data: event data payload
4713 _scsih_sas_topology_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
4714 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
4720 char *status_str
= NULL
;
4721 u8 link_rate
, prev_link_rate
;
4723 switch (event_data
->ExpStatus
) {
4724 case MPI2_EVENT_SAS_TOPO_ES_ADDED
:
4727 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
:
4728 status_str
= "remove";
4730 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING
:
4732 status_str
= "responding";
4734 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
:
4735 status_str
= "remove delay";
4738 status_str
= "unknown status";
4741 printk(MPT2SAS_INFO_FMT
"sas topology change: (%s)\n",
4742 ioc
->name
, status_str
);
4743 printk(KERN_INFO
"\thandle(0x%04x), enclosure_handle(0x%04x) "
4744 "start_phy(%02d), count(%d)\n",
4745 le16_to_cpu(event_data
->ExpanderDevHandle
),
4746 le16_to_cpu(event_data
->EnclosureHandle
),
4747 event_data
->StartPhyNum
, event_data
->NumEntries
);
4748 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
4749 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
4752 phy_number
= event_data
->StartPhyNum
+ i
;
4753 reason_code
= event_data
->PHY
[i
].PhyStatus
&
4754 MPI2_EVENT_SAS_TOPO_RC_MASK
;
4755 switch (reason_code
) {
4756 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
4757 status_str
= "target add";
4759 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
4760 status_str
= "target remove";
4762 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
:
4763 status_str
= "delay target remove";
4765 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
4766 status_str
= "link rate change";
4768 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE
:
4769 status_str
= "target responding";
4772 status_str
= "unknown";
4775 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
4776 prev_link_rate
= event_data
->PHY
[i
].LinkRate
& 0xF;
4777 printk(KERN_INFO
"\tphy(%02d), attached_handle(0x%04x): %s:"
4778 " link rate: new(0x%02x), old(0x%02x)\n", phy_number
,
4779 handle
, status_str
, link_rate
, prev_link_rate
);
4786 * _scsih_sas_topology_change_event - handle topology changes
4787 * @ioc: per adapter object
4788 * @fw_event: The fw_event_work object
4793 _scsih_sas_topology_change_event(struct MPT2SAS_ADAPTER
*ioc
,
4794 struct fw_event_work
*fw_event
)
4797 u16 parent_handle
, handle
;
4799 u8 phy_number
, max_phys
;
4800 struct _sas_node
*sas_expander
;
4801 struct _sas_device
*sas_device
;
4803 unsigned long flags
;
4804 u8 link_rate
, prev_link_rate
;
4805 Mpi2EventDataSasTopologyChangeList_t
*event_data
= fw_event
->event_data
;
4807 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4808 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
4809 _scsih_sas_topology_change_event_debug(ioc
, event_data
);
4812 if (ioc
->shost_recovery
|| ioc
->remove_host
|| ioc
->pci_error_recovery
)
4815 if (!ioc
->sas_hba
.num_phys
)
4816 _scsih_sas_host_add(ioc
);
4818 _scsih_sas_host_refresh(ioc
);
4820 if (fw_event
->ignore
) {
4821 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"ignoring expander "
4822 "event\n", ioc
->name
));
4826 parent_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
4828 /* handle expander add */
4829 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_ADDED
)
4830 if (_scsih_expander_add(ioc
, parent_handle
) != 0)
4833 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
4834 sas_expander
= mpt2sas_scsih_expander_find_by_handle(ioc
,
4836 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
4838 sas_address
= sas_expander
->sas_address
;
4839 max_phys
= sas_expander
->num_phys
;
4840 } else if (parent_handle
< ioc
->sas_hba
.num_phys
) {
4841 sas_address
= ioc
->sas_hba
.sas_address
;
4842 max_phys
= ioc
->sas_hba
.num_phys
;
4846 /* handle siblings events */
4847 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
4848 if (fw_event
->ignore
) {
4849 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"ignoring "
4850 "expander event\n", ioc
->name
));
4853 if (ioc
->shost_recovery
|| ioc
->remove_host
||
4854 ioc
->pci_error_recovery
)
4856 phy_number
= event_data
->StartPhyNum
+ i
;
4857 if (phy_number
>= max_phys
)
4859 reason_code
= event_data
->PHY
[i
].PhyStatus
&
4860 MPI2_EVENT_SAS_TOPO_RC_MASK
;
4861 if ((event_data
->PHY
[i
].PhyStatus
&
4862 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT
) && (reason_code
!=
4863 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
))
4865 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
4868 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
4869 prev_link_rate
= event_data
->PHY
[i
].LinkRate
& 0xF;
4870 switch (reason_code
) {
4871 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
4873 if (link_rate
== prev_link_rate
)
4876 mpt2sas_transport_update_links(ioc
, sas_address
,
4877 handle
, phy_number
, link_rate
);
4879 if (link_rate
< MPI2_SAS_NEG_LINK_RATE_1_5
)
4882 _scsih_check_device(ioc
, handle
);
4884 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
4886 mpt2sas_transport_update_links(ioc
, sas_address
,
4887 handle
, phy_number
, link_rate
);
4889 _scsih_add_device(ioc
, handle
, phy_number
, 0);
4891 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
4893 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4894 sas_device
= _scsih_sas_device_find_by_handle(ioc
,
4897 spin_unlock_irqrestore(&ioc
->sas_device_lock
,
4901 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4902 _scsih_remove_device(ioc
, sas_device
);
4907 /* handle expander removal */
4908 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
&&
4910 mpt2sas_expander_remove(ioc
, sas_address
);
4914 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4916 * _scsih_sas_device_status_change_event_debug - debug for device event
4917 * @event_data: event data payload
4923 _scsih_sas_device_status_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
4924 Mpi2EventDataSasDeviceStatusChange_t
*event_data
)
4926 char *reason_str
= NULL
;
4928 switch (event_data
->ReasonCode
) {
4929 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
:
4930 reason_str
= "smart data";
4932 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED
:
4933 reason_str
= "unsupported device discovered";
4935 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
:
4936 reason_str
= "internal device reset";
4938 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL
:
4939 reason_str
= "internal task abort";
4941 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL
:
4942 reason_str
= "internal task abort set";
4944 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL
:
4945 reason_str
= "internal clear task set";
4947 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL
:
4948 reason_str
= "internal query task";
4950 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE
:
4951 reason_str
= "sata init failure";
4953 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
:
4954 reason_str
= "internal device reset complete";
4956 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL
:
4957 reason_str
= "internal task abort complete";
4959 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION
:
4960 reason_str
= "internal async notification";
4962 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY
:
4963 reason_str
= "expander reduced functionality";
4965 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY
:
4966 reason_str
= "expander reduced functionality complete";
4969 reason_str
= "unknown reason";
4972 printk(MPT2SAS_INFO_FMT
"device status change: (%s)\n"
4973 "\thandle(0x%04x), sas address(0x%016llx)", ioc
->name
,
4974 reason_str
, le16_to_cpu(event_data
->DevHandle
),
4975 (unsigned long long)le64_to_cpu(event_data
->SASAddress
));
4976 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
)
4977 printk(MPT2SAS_INFO_FMT
", ASC(0x%x), ASCQ(0x%x)\n", ioc
->name
,
4978 event_data
->ASC
, event_data
->ASCQ
);
4979 printk(KERN_INFO
"\n");
4984 * _scsih_sas_device_status_change_event - handle device status change
4985 * @ioc: per adapter object
4986 * @fw_event: The fw_event_work object
4992 _scsih_sas_device_status_change_event(struct MPT2SAS_ADAPTER
*ioc
,
4993 struct fw_event_work
*fw_event
)
4995 struct MPT2SAS_TARGET
*target_priv_data
;
4996 struct _sas_device
*sas_device
;
4998 unsigned long flags
;
4999 Mpi2EventDataSasDeviceStatusChange_t
*event_data
=
5000 fw_event
->event_data
;
5002 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5003 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5004 _scsih_sas_device_status_change_event_debug(ioc
,
5008 if (event_data
->ReasonCode
!=
5009 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
&&
5010 event_data
->ReasonCode
!=
5011 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
)
5014 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5015 sas_address
= le64_to_cpu(event_data
->SASAddress
);
5016 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
5018 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5020 if (!sas_device
|| !sas_device
->starget
)
5023 target_priv_data
= sas_device
->starget
->hostdata
;
5024 if (!target_priv_data
)
5027 if (event_data
->ReasonCode
==
5028 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
)
5029 target_priv_data
->tm_busy
= 1;
5031 target_priv_data
->tm_busy
= 0;
5034 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5036 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure event
5037 * @ioc: per adapter object
5038 * @event_data: event data payload
5044 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
5045 Mpi2EventDataSasEnclDevStatusChange_t
*event_data
)
5047 char *reason_str
= NULL
;
5049 switch (event_data
->ReasonCode
) {
5050 case MPI2_EVENT_SAS_ENCL_RC_ADDED
:
5051 reason_str
= "enclosure add";
5053 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING
:
5054 reason_str
= "enclosure remove";
5057 reason_str
= "unknown reason";
5061 printk(MPT2SAS_INFO_FMT
"enclosure status change: (%s)\n"
5062 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
5063 " number slots(%d)\n", ioc
->name
, reason_str
,
5064 le16_to_cpu(event_data
->EnclosureHandle
),
5065 (unsigned long long)le64_to_cpu(event_data
->EnclosureLogicalID
),
5066 le16_to_cpu(event_data
->StartSlot
));
5071 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
5072 * @ioc: per adapter object
5073 * @fw_event: The fw_event_work object
5079 _scsih_sas_enclosure_dev_status_change_event(struct MPT2SAS_ADAPTER
*ioc
,
5080 struct fw_event_work
*fw_event
)
5082 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5083 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5084 _scsih_sas_enclosure_dev_status_change_event_debug(ioc
,
5085 fw_event
->event_data
);
5090 * _scsih_sas_broadcast_primative_event - handle broadcast events
5091 * @ioc: per adapter object
5092 * @fw_event: The fw_event_work object
5098 _scsih_sas_broadcast_primative_event(struct MPT2SAS_ADAPTER
*ioc
,
5099 struct fw_event_work
*fw_event
)
5101 struct scsi_cmnd
*scmd
;
5104 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
5105 u32 termination_count
;
5107 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
5108 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5109 Mpi2EventDataSasBroadcastPrimitive_t
*event_data
= fw_event
->event_data
;
5112 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"broadcast primative: "
5113 "phy number(%d), width(%d)\n", ioc
->name
, event_data
->PhyNum
,
5114 event_data
->PortWidth
));
5115 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: enter\n", ioc
->name
,
5118 termination_count
= 0;
5120 mpi_reply
= ioc
->tm_cmds
.reply
;
5121 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
5122 scmd
= _scsih_scsi_lookup_get(ioc
, smid
);
5125 sas_device_priv_data
= scmd
->device
->hostdata
;
5126 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
)
5128 /* skip hidden raid components */
5129 if (sas_device_priv_data
->sas_target
->flags
&
5130 MPT_TARGET_FLAGS_RAID_COMPONENT
)
5133 if (sas_device_priv_data
->sas_target
->flags
&
5134 MPT_TARGET_FLAGS_VOLUME
)
5137 handle
= sas_device_priv_data
->sas_target
->handle
;
5138 lun
= sas_device_priv_data
->lun
;
5141 mpt2sas_scsih_issue_tm(ioc
, handle
, 0, 0, lun
,
5142 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK
, smid
, 30, NULL
);
5143 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
5144 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
)
5145 & MPI2_IOCSTATUS_MASK
;
5146 if ((ioc_status
== MPI2_IOCSTATUS_SUCCESS
) &&
5147 (mpi_reply
->ResponseCode
==
5148 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
||
5149 mpi_reply
->ResponseCode
==
5150 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
))
5153 mpt2sas_scsih_issue_tm(ioc
, handle
, 0, 0, lun
,
5154 MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET
, 0, 30, NULL
);
5155 termination_count
+= le32_to_cpu(mpi_reply
->TerminationCount
);
5157 ioc
->broadcast_aen_busy
= 0;
5159 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
5160 "%s - exit, query_count = %d termination_count = %d\n",
5161 ioc
->name
, __func__
, query_count
, termination_count
));
5165 * _scsih_sas_discovery_event - handle discovery events
5166 * @ioc: per adapter object
5167 * @fw_event: The fw_event_work object
5173 _scsih_sas_discovery_event(struct MPT2SAS_ADAPTER
*ioc
,
5174 struct fw_event_work
*fw_event
)
5176 Mpi2EventDataSasDiscovery_t
*event_data
= fw_event
->event_data
;
5178 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5179 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
) {
5180 printk(MPT2SAS_INFO_FMT
"discovery event: (%s)", ioc
->name
,
5181 (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
) ?
5183 if (event_data
->DiscoveryStatus
)
5184 printk("discovery_status(0x%08x)",
5185 le32_to_cpu(event_data
->DiscoveryStatus
));
5190 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
&&
5191 !ioc
->sas_hba
.num_phys
)
5192 _scsih_sas_host_add(ioc
);
5196 * _scsih_reprobe_lun - reprobing lun
5197 * @sdev: scsi device struct
5198 * @no_uld_attach: sdev->no_uld_attach flag setting
5202 _scsih_reprobe_lun(struct scsi_device
*sdev
, void *no_uld_attach
)
5206 sdev
->no_uld_attach
= no_uld_attach
? 1 : 0;
5207 sdev_printk(KERN_INFO
, sdev
, "%s raid component\n",
5208 sdev
->no_uld_attach
? "hidding" : "exposing");
5209 rc
= scsi_device_reprobe(sdev
);
5213 * _scsih_reprobe_target - reprobing target
5214 * @starget: scsi target struct
5215 * @no_uld_attach: sdev->no_uld_attach flag setting
5217 * Note: no_uld_attach flag determines whether the disk device is attached
5218 * to block layer. A value of `1` means to not attach.
5221 _scsih_reprobe_target(struct scsi_target
*starget
, int no_uld_attach
)
5223 struct MPT2SAS_TARGET
*sas_target_priv_data
= starget
->hostdata
;
5226 sas_target_priv_data
->flags
|= MPT_TARGET_FLAGS_RAID_COMPONENT
;
5228 sas_target_priv_data
->flags
&= ~MPT_TARGET_FLAGS_RAID_COMPONENT
;
5230 starget_for_each_device(starget
, no_uld_attach
? (void *)1 : NULL
,
5231 _scsih_reprobe_lun
);
5234 * _scsih_sas_volume_add - add new volume
5235 * @ioc: per adapter object
5236 * @element: IR config element data
5242 _scsih_sas_volume_add(struct MPT2SAS_ADAPTER
*ioc
,
5243 Mpi2EventIrConfigElement_t
*element
)
5245 struct _raid_device
*raid_device
;
5246 unsigned long flags
;
5248 u16 handle
= le16_to_cpu(element
->VolDevHandle
);
5251 mpt2sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
5253 printk(MPT2SAS_ERR_FMT
5254 "failure at %s:%d/%s()!\n", ioc
->name
,
5255 __FILE__
, __LINE__
, __func__
);
5259 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5260 raid_device
= _scsih_raid_device_find_by_wwid(ioc
, wwid
);
5261 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5266 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
5268 printk(MPT2SAS_ERR_FMT
5269 "failure at %s:%d/%s()!\n", ioc
->name
,
5270 __FILE__
, __LINE__
, __func__
);
5274 raid_device
->id
= ioc
->sas_id
++;
5275 raid_device
->channel
= RAID_CHANNEL
;
5276 raid_device
->handle
= handle
;
5277 raid_device
->wwid
= wwid
;
5278 _scsih_raid_device_add(ioc
, raid_device
);
5279 if (!ioc
->wait_for_port_enable_to_complete
) {
5280 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
5281 raid_device
->id
, 0);
5283 _scsih_raid_device_remove(ioc
, raid_device
);
5285 _scsih_determine_boot_device(ioc
, raid_device
, 1);
5289 * _scsih_sas_volume_delete - delete volume
5290 * @ioc: per adapter object
5291 * @handle: volume device handle
5297 _scsih_sas_volume_delete(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
5299 struct _raid_device
*raid_device
;
5300 unsigned long flags
;
5301 struct MPT2SAS_TARGET
*sas_target_priv_data
;
5303 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5304 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
5305 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5308 if (raid_device
->starget
) {
5309 sas_target_priv_data
= raid_device
->starget
->hostdata
;
5310 sas_target_priv_data
->deleted
= 1;
5311 scsi_remove_target(&raid_device
->starget
->dev
);
5313 printk(MPT2SAS_INFO_FMT
"removing handle(0x%04x), wwid"
5314 "(0x%016llx)\n", ioc
->name
, raid_device
->handle
,
5315 (unsigned long long) raid_device
->wwid
);
5316 _scsih_raid_device_remove(ioc
, raid_device
);
5320 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
5321 * @ioc: per adapter object
5322 * @element: IR config element data
5328 _scsih_sas_pd_expose(struct MPT2SAS_ADAPTER
*ioc
,
5329 Mpi2EventIrConfigElement_t
*element
)
5331 struct _sas_device
*sas_device
;
5332 unsigned long flags
;
5333 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
5335 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5336 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
5337 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5341 /* exposing raid component */
5342 sas_device
->volume_handle
= 0;
5343 sas_device
->volume_wwid
= 0;
5344 clear_bit(handle
, ioc
->pd_handles
);
5345 _scsih_reprobe_target(sas_device
->starget
, 0);
5349 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
5350 * @ioc: per adapter object
5351 * @element: IR config element data
5357 _scsih_sas_pd_hide(struct MPT2SAS_ADAPTER
*ioc
,
5358 Mpi2EventIrConfigElement_t
*element
)
5360 struct _sas_device
*sas_device
;
5361 unsigned long flags
;
5362 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
5364 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5365 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
5366 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5370 /* hiding raid component */
5371 mpt2sas_config_get_volume_handle(ioc
, handle
,
5372 &sas_device
->volume_handle
);
5373 mpt2sas_config_get_volume_wwid(ioc
, sas_device
->volume_handle
,
5374 &sas_device
->volume_wwid
);
5375 set_bit(handle
, ioc
->pd_handles
);
5376 _scsih_reprobe_target(sas_device
->starget
, 1);
5380 * _scsih_sas_pd_delete - delete pd component
5381 * @ioc: per adapter object
5382 * @element: IR config element data
5388 _scsih_sas_pd_delete(struct MPT2SAS_ADAPTER
*ioc
,
5389 Mpi2EventIrConfigElement_t
*element
)
5391 struct _sas_device
*sas_device
;
5392 unsigned long flags
;
5393 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
5395 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5396 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
5397 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5400 _scsih_remove_device(ioc
, sas_device
);
5404 * _scsih_sas_pd_add - remove pd component
5405 * @ioc: per adapter object
5406 * @element: IR config element data
5412 _scsih_sas_pd_add(struct MPT2SAS_ADAPTER
*ioc
,
5413 Mpi2EventIrConfigElement_t
*element
)
5415 struct _sas_device
*sas_device
;
5416 unsigned long flags
;
5417 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
5418 Mpi2ConfigReply_t mpi_reply
;
5419 Mpi2SasDevicePage0_t sas_device_pg0
;
5424 set_bit(handle
, ioc
->pd_handles
);
5426 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5427 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
5428 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5432 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
5433 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
5434 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5435 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5439 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5440 MPI2_IOCSTATUS_MASK
;
5441 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5442 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5443 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5447 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
5448 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
5449 mpt2sas_transport_update_links(ioc
, sas_address
, handle
,
5450 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
5452 _scsih_add_device(ioc
, handle
, 0, 1);
5455 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5457 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
5458 * @ioc: per adapter object
5459 * @event_data: event data payload
5465 _scsih_sas_ir_config_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
5466 Mpi2EventDataIrConfigChangeList_t
*event_data
)
5468 Mpi2EventIrConfigElement_t
*element
;
5471 char *reason_str
= NULL
, *element_str
= NULL
;
5473 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
5475 printk(MPT2SAS_INFO_FMT
"raid config change: (%s), elements(%d)\n",
5476 ioc
->name
, (le32_to_cpu(event_data
->Flags
) &
5477 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ?
5478 "foreign" : "native", event_data
->NumElements
);
5479 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
5480 switch (element
->ReasonCode
) {
5481 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
5484 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
5485 reason_str
= "remove";
5487 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE
:
5488 reason_str
= "no change";
5490 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
5491 reason_str
= "hide";
5493 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
5494 reason_str
= "unhide";
5496 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
5497 reason_str
= "volume_created";
5499 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
5500 reason_str
= "volume_deleted";
5502 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
5503 reason_str
= "pd_created";
5505 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
5506 reason_str
= "pd_deleted";
5509 reason_str
= "unknown reason";
5512 element_type
= le16_to_cpu(element
->ElementFlags
) &
5513 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK
;
5514 switch (element_type
) {
5515 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT
:
5516 element_str
= "volume";
5518 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT
:
5519 element_str
= "phys disk";
5521 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT
:
5522 element_str
= "hot spare";
5525 element_str
= "unknown element";
5528 printk(KERN_INFO
"\t(%s:%s), vol handle(0x%04x), "
5529 "pd handle(0x%04x), pd num(0x%02x)\n", element_str
,
5530 reason_str
, le16_to_cpu(element
->VolDevHandle
),
5531 le16_to_cpu(element
->PhysDiskDevHandle
),
5532 element
->PhysDiskNum
);
5538 * _scsih_sas_ir_config_change_event - handle ir configuration change events
5539 * @ioc: per adapter object
5540 * @fw_event: The fw_event_work object
5546 _scsih_sas_ir_config_change_event(struct MPT2SAS_ADAPTER
*ioc
,
5547 struct fw_event_work
*fw_event
)
5549 Mpi2EventIrConfigElement_t
*element
;
5552 Mpi2EventDataIrConfigChangeList_t
*event_data
= fw_event
->event_data
;
5554 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5555 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5556 _scsih_sas_ir_config_change_event_debug(ioc
, event_data
);
5559 foreign_config
= (le32_to_cpu(event_data
->Flags
) &
5560 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ? 1 : 0;
5562 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
5563 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
5565 switch (element
->ReasonCode
) {
5566 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
5567 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
5568 if (!foreign_config
)
5569 _scsih_sas_volume_add(ioc
, element
);
5571 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
5572 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
5573 if (!foreign_config
)
5574 _scsih_sas_volume_delete(ioc
,
5575 le16_to_cpu(element
->VolDevHandle
));
5577 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
5578 _scsih_sas_pd_hide(ioc
, element
);
5580 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
5581 _scsih_sas_pd_expose(ioc
, element
);
5583 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
5584 _scsih_sas_pd_add(ioc
, element
);
5586 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
5587 _scsih_sas_pd_delete(ioc
, element
);
5594 * _scsih_sas_ir_volume_event - IR volume event
5595 * @ioc: per adapter object
5596 * @fw_event: The fw_event_work object
5602 _scsih_sas_ir_volume_event(struct MPT2SAS_ADAPTER
*ioc
,
5603 struct fw_event_work
*fw_event
)
5606 unsigned long flags
;
5607 struct _raid_device
*raid_device
;
5611 Mpi2EventDataIrVolume_t
*event_data
= fw_event
->event_data
;
5613 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED
)
5616 handle
= le16_to_cpu(event_data
->VolDevHandle
);
5617 state
= le32_to_cpu(event_data
->NewValue
);
5618 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: handle(0x%04x), "
5619 "old(0x%08x), new(0x%08x)\n", ioc
->name
, __func__
, handle
,
5620 le32_to_cpu(event_data
->PreviousValue
), state
));
5623 case MPI2_RAID_VOL_STATE_MISSING
:
5624 case MPI2_RAID_VOL_STATE_FAILED
:
5625 _scsih_sas_volume_delete(ioc
, handle
);
5628 case MPI2_RAID_VOL_STATE_ONLINE
:
5629 case MPI2_RAID_VOL_STATE_DEGRADED
:
5630 case MPI2_RAID_VOL_STATE_OPTIMAL
:
5632 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5633 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
5634 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5639 mpt2sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
5641 printk(MPT2SAS_ERR_FMT
5642 "failure at %s:%d/%s()!\n", ioc
->name
,
5643 __FILE__
, __LINE__
, __func__
);
5647 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
5649 printk(MPT2SAS_ERR_FMT
5650 "failure at %s:%d/%s()!\n", ioc
->name
,
5651 __FILE__
, __LINE__
, __func__
);
5655 raid_device
->id
= ioc
->sas_id
++;
5656 raid_device
->channel
= RAID_CHANNEL
;
5657 raid_device
->handle
= handle
;
5658 raid_device
->wwid
= wwid
;
5659 _scsih_raid_device_add(ioc
, raid_device
);
5660 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
5661 raid_device
->id
, 0);
5663 _scsih_raid_device_remove(ioc
, raid_device
);
5666 case MPI2_RAID_VOL_STATE_INITIALIZING
:
5673 * _scsih_sas_ir_physical_disk_event - PD event
5674 * @ioc: per adapter object
5675 * @fw_event: The fw_event_work object
5681 _scsih_sas_ir_physical_disk_event(struct MPT2SAS_ADAPTER
*ioc
,
5682 struct fw_event_work
*fw_event
)
5684 u16 handle
, parent_handle
;
5686 struct _sas_device
*sas_device
;
5687 unsigned long flags
;
5688 Mpi2ConfigReply_t mpi_reply
;
5689 Mpi2SasDevicePage0_t sas_device_pg0
;
5691 Mpi2EventDataIrPhysicalDisk_t
*event_data
= fw_event
->event_data
;
5694 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED
)
5697 handle
= le16_to_cpu(event_data
->PhysDiskDevHandle
);
5698 state
= le32_to_cpu(event_data
->NewValue
);
5700 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: handle(0x%04x), "
5701 "old(0x%08x), new(0x%08x)\n", ioc
->name
, __func__
, handle
,
5702 le32_to_cpu(event_data
->PreviousValue
), state
));
5705 case MPI2_RAID_PD_STATE_ONLINE
:
5706 case MPI2_RAID_PD_STATE_DEGRADED
:
5707 case MPI2_RAID_PD_STATE_REBUILDING
:
5708 case MPI2_RAID_PD_STATE_OPTIMAL
:
5709 case MPI2_RAID_PD_STATE_HOT_SPARE
:
5711 set_bit(handle
, ioc
->pd_handles
);
5713 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5714 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
5715 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5720 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
5721 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
5723 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5724 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5728 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5729 MPI2_IOCSTATUS_MASK
;
5730 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5731 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5732 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5736 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
5737 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
5738 mpt2sas_transport_update_links(ioc
, sas_address
, handle
,
5739 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
5741 _scsih_add_device(ioc
, handle
, 0, 1);
5745 case MPI2_RAID_PD_STATE_OFFLINE
:
5746 case MPI2_RAID_PD_STATE_NOT_CONFIGURED
:
5747 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE
:
5753 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5755 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
5756 * @ioc: per adapter object
5757 * @event_data: event data payload
5763 _scsih_sas_ir_operation_status_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
5764 Mpi2EventDataIrOperationStatus_t
*event_data
)
5766 char *reason_str
= NULL
;
5768 switch (event_data
->RAIDOperation
) {
5769 case MPI2_EVENT_IR_RAIDOP_RESYNC
:
5770 reason_str
= "resync";
5772 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION
:
5773 reason_str
= "online capacity expansion";
5775 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK
:
5776 reason_str
= "consistency check";
5778 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT
:
5779 reason_str
= "background init";
5781 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT
:
5782 reason_str
= "make data consistent";
5789 printk(MPT2SAS_INFO_FMT
"raid operational status: (%s)"
5790 "\thandle(0x%04x), percent complete(%d)\n",
5791 ioc
->name
, reason_str
,
5792 le16_to_cpu(event_data
->VolDevHandle
),
5793 event_data
->PercentComplete
);
5798 * _scsih_sas_ir_operation_status_event - handle RAID operation events
5799 * @ioc: per adapter object
5800 * @fw_event: The fw_event_work object
5806 _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER
*ioc
,
5807 struct fw_event_work
*fw_event
)
5809 Mpi2EventDataIrOperationStatus_t
*event_data
= fw_event
->event_data
;
5810 static struct _raid_device
*raid_device
;
5811 unsigned long flags
;
5814 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5815 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5816 _scsih_sas_ir_operation_status_event_debug(ioc
,
5820 /* code added for raid transport support */
5821 if (event_data
->RAIDOperation
== MPI2_EVENT_IR_RAIDOP_RESYNC
) {
5823 handle
= le16_to_cpu(event_data
->VolDevHandle
);
5825 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5826 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
5827 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5832 if (event_data
->RAIDOperation
== MPI2_EVENT_IR_RAIDOP_RESYNC
)
5833 raid_device
->percent_complete
=
5834 event_data
->PercentComplete
;
5839 * _scsih_prep_device_scan - initialize parameters prior to device scan
5840 * @ioc: per adapter object
5842 * Set the deleted flag prior to device scan. If the device is found during
5843 * the scan, then we clear the deleted flag.
5846 _scsih_prep_device_scan(struct MPT2SAS_ADAPTER
*ioc
)
5848 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
5849 struct scsi_device
*sdev
;
5851 shost_for_each_device(sdev
, ioc
->shost
) {
5852 sas_device_priv_data
= sdev
->hostdata
;
5853 if (sas_device_priv_data
&& sas_device_priv_data
->sas_target
)
5854 sas_device_priv_data
->sas_target
->deleted
= 1;
5859 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
5860 * @ioc: per adapter object
5861 * @sas_address: sas address
5862 * @slot: enclosure slot id
5863 * @handle: device handle
5865 * After host reset, find out whether devices are still responding.
5866 * Used in _scsi_remove_unresponsive_sas_devices.
5871 _scsih_mark_responding_sas_device(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
,
5872 u16 slot
, u16 handle
)
5874 struct MPT2SAS_TARGET
*sas_target_priv_data
;
5875 struct scsi_target
*starget
;
5876 struct _sas_device
*sas_device
;
5877 unsigned long flags
;
5879 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5880 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
) {
5881 if (sas_device
->sas_address
== sas_address
&&
5882 sas_device
->slot
== slot
&& sas_device
->starget
) {
5883 sas_device
->responding
= 1;
5884 starget
= sas_device
->starget
;
5885 if (starget
&& starget
->hostdata
) {
5886 sas_target_priv_data
= starget
->hostdata
;
5887 sas_target_priv_data
->tm_busy
= 0;
5888 sas_target_priv_data
->deleted
= 0;
5890 sas_target_priv_data
= NULL
;
5891 starget_printk(KERN_INFO
, sas_device
->starget
,
5892 "handle(0x%04x), sas_addr(0x%016llx), enclosure "
5893 "logical id(0x%016llx), slot(%d)\n", handle
,
5894 (unsigned long long)sas_device
->sas_address
,
5895 (unsigned long long)
5896 sas_device
->enclosure_logical_id
,
5898 if (sas_device
->handle
== handle
)
5900 printk(KERN_INFO
"\thandle changed from(0x%04x)!!!\n",
5901 sas_device
->handle
);
5902 sas_device
->handle
= handle
;
5903 if (sas_target_priv_data
)
5904 sas_target_priv_data
->handle
= handle
;
5909 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5913 * _scsih_search_responding_sas_devices -
5914 * @ioc: per adapter object
5916 * After host reset, find out whether devices are still responding.
5922 _scsih_search_responding_sas_devices(struct MPT2SAS_ADAPTER
*ioc
)
5924 Mpi2SasDevicePage0_t sas_device_pg0
;
5925 Mpi2ConfigReply_t mpi_reply
;
5932 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
, __func__
);
5934 if (list_empty(&ioc
->sas_device_list
))
5938 while (!(mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
5939 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
,
5941 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5942 MPI2_IOCSTATUS_MASK
;
5943 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
5945 handle
= le16_to_cpu(sas_device_pg0
.DevHandle
);
5946 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
5947 if (!(_scsih_is_end_device(device_info
)))
5949 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
5950 slot
= le16_to_cpu(sas_device_pg0
.Slot
);
5951 _scsih_mark_responding_sas_device(ioc
, sas_address
, slot
,
5957 * _scsih_mark_responding_raid_device - mark a raid_device as responding
5958 * @ioc: per adapter object
5959 * @wwid: world wide identifier for raid volume
5960 * @handle: device handle
5962 * After host reset, find out whether devices are still responding.
5963 * Used in _scsi_remove_unresponsive_raid_devices.
5968 _scsih_mark_responding_raid_device(struct MPT2SAS_ADAPTER
*ioc
, u64 wwid
,
5971 struct MPT2SAS_TARGET
*sas_target_priv_data
;
5972 struct scsi_target
*starget
;
5973 struct _raid_device
*raid_device
;
5974 unsigned long flags
;
5976 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5977 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
5978 if (raid_device
->wwid
== wwid
&& raid_device
->starget
) {
5979 starget
= raid_device
->starget
;
5980 if (starget
&& starget
->hostdata
) {
5981 sas_target_priv_data
= starget
->hostdata
;
5982 sas_target_priv_data
->deleted
= 0;
5984 sas_target_priv_data
= NULL
;
5985 raid_device
->responding
= 1;
5986 starget_printk(KERN_INFO
, raid_device
->starget
,
5987 "handle(0x%04x), wwid(0x%016llx)\n", handle
,
5988 (unsigned long long)raid_device
->wwid
);
5989 if (raid_device
->handle
== handle
)
5991 printk(KERN_INFO
"\thandle changed from(0x%04x)!!!\n",
5992 raid_device
->handle
);
5993 raid_device
->handle
= handle
;
5994 if (sas_target_priv_data
)
5995 sas_target_priv_data
->handle
= handle
;
6000 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6004 * _scsih_search_responding_raid_devices -
6005 * @ioc: per adapter object
6007 * After host reset, find out whether devices are still responding.
6013 _scsih_search_responding_raid_devices(struct MPT2SAS_ADAPTER
*ioc
)
6015 Mpi2RaidVolPage1_t volume_pg1
;
6016 Mpi2RaidVolPage0_t volume_pg0
;
6017 Mpi2RaidPhysDiskPage0_t pd_pg0
;
6018 Mpi2ConfigReply_t mpi_reply
;
6023 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
, __func__
);
6025 if (list_empty(&ioc
->raid_device_list
))
6029 while (!(mpt2sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
6030 &volume_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
6031 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6032 MPI2_IOCSTATUS_MASK
;
6033 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
6035 handle
= le16_to_cpu(volume_pg1
.DevHandle
);
6037 if (mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
,
6038 &volume_pg0
, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
6039 sizeof(Mpi2RaidVolPage0_t
)))
6042 if (volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_OPTIMAL
||
6043 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_ONLINE
||
6044 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_DEGRADED
)
6045 _scsih_mark_responding_raid_device(ioc
,
6046 le64_to_cpu(volume_pg1
.WWID
), handle
);
6049 /* refresh the pd_handles */
6050 phys_disk_num
= 0xFF;
6051 memset(ioc
->pd_handles
, 0, ioc
->pd_handles_sz
);
6052 while (!(mpt2sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
6053 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM
,
6055 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6056 MPI2_IOCSTATUS_MASK
;
6057 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
6059 phys_disk_num
= pd_pg0
.PhysDiskNum
;
6060 handle
= le16_to_cpu(pd_pg0
.DevHandle
);
6061 set_bit(handle
, ioc
->pd_handles
);
6066 * _scsih_mark_responding_expander - mark a expander as responding
6067 * @ioc: per adapter object
6068 * @sas_address: sas address
6071 * After host reset, find out whether devices are still responding.
6072 * Used in _scsi_remove_unresponsive_expanders.
6077 _scsih_mark_responding_expander(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
,
6080 struct _sas_node
*sas_expander
;
6081 unsigned long flags
;
6084 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
6085 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
6086 if (sas_expander
->sas_address
!= sas_address
)
6088 sas_expander
->responding
= 1;
6089 if (sas_expander
->handle
== handle
)
6091 printk(KERN_INFO
"\texpander(0x%016llx): handle changed"
6092 " from(0x%04x) to (0x%04x)!!!\n",
6093 (unsigned long long)sas_expander
->sas_address
,
6094 sas_expander
->handle
, handle
);
6095 sas_expander
->handle
= handle
;
6096 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++)
6097 sas_expander
->phy
[i
].handle
= handle
;
6101 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
6105 * _scsih_search_responding_expanders -
6106 * @ioc: per adapter object
6108 * After host reset, find out whether devices are still responding.
6114 _scsih_search_responding_expanders(struct MPT2SAS_ADAPTER
*ioc
)
6116 Mpi2ExpanderPage0_t expander_pg0
;
6117 Mpi2ConfigReply_t mpi_reply
;
6122 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
, __func__
);
6124 if (list_empty(&ioc
->sas_expander_list
))
6128 while (!(mpt2sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
6129 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL
, handle
))) {
6131 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6132 MPI2_IOCSTATUS_MASK
;
6133 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
6136 handle
= le16_to_cpu(expander_pg0
.DevHandle
);
6137 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
6138 printk(KERN_INFO
"\texpander present: handle(0x%04x), "
6139 "sas_addr(0x%016llx)\n", handle
,
6140 (unsigned long long)sas_address
);
6141 _scsih_mark_responding_expander(ioc
, sas_address
, handle
);
6147 * _scsih_remove_unresponding_sas_devices - removing unresponding devices
6148 * @ioc: per adapter object
6153 _scsih_remove_unresponding_sas_devices(struct MPT2SAS_ADAPTER
*ioc
)
6155 struct _sas_device
*sas_device
, *sas_device_next
;
6156 struct _sas_node
*sas_expander
;
6157 struct _raid_device
*raid_device
, *raid_device_next
;
6160 list_for_each_entry_safe(sas_device
, sas_device_next
,
6161 &ioc
->sas_device_list
, list
) {
6162 if (sas_device
->responding
) {
6163 sas_device
->responding
= 0;
6166 if (sas_device
->starget
)
6167 starget_printk(KERN_INFO
, sas_device
->starget
,
6168 "removing: handle(0x%04x), sas_addr(0x%016llx), "
6169 "enclosure logical id(0x%016llx), slot(%d)\n",
6171 (unsigned long long)sas_device
->sas_address
,
6172 (unsigned long long)
6173 sas_device
->enclosure_logical_id
,
6175 _scsih_remove_device(ioc
, sas_device
);
6178 list_for_each_entry_safe(raid_device
, raid_device_next
,
6179 &ioc
->raid_device_list
, list
) {
6180 if (raid_device
->responding
) {
6181 raid_device
->responding
= 0;
6184 if (raid_device
->starget
) {
6185 starget_printk(KERN_INFO
, raid_device
->starget
,
6186 "removing: handle(0x%04x), wwid(0x%016llx)\n",
6187 raid_device
->handle
,
6188 (unsigned long long)raid_device
->wwid
);
6189 scsi_remove_target(&raid_device
->starget
->dev
);
6191 _scsih_raid_device_remove(ioc
, raid_device
);
6194 retry_expander_search
:
6195 sas_expander
= NULL
;
6196 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
6197 if (sas_expander
->responding
) {
6198 sas_expander
->responding
= 0;
6201 mpt2sas_expander_remove(ioc
, sas_expander
->sas_address
);
6202 goto retry_expander_search
;
6207 * mpt2sas_scsih_reset_handler - reset callback handler (for scsih)
6208 * @ioc: per adapter object
6209 * @reset_phase: phase
6211 * The handler for doing any required cleanup or initialization.
6213 * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
6214 * MPT2_IOC_DONE_RESET
6219 mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER
*ioc
, int reset_phase
)
6221 switch (reset_phase
) {
6222 case MPT2_IOC_PRE_RESET
:
6223 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: "
6224 "MPT2_IOC_PRE_RESET\n", ioc
->name
, __func__
));
6226 case MPT2_IOC_AFTER_RESET
:
6227 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: "
6228 "MPT2_IOC_AFTER_RESET\n", ioc
->name
, __func__
));
6229 if (ioc
->scsih_cmds
.status
& MPT2_CMD_PENDING
) {
6230 ioc
->scsih_cmds
.status
|= MPT2_CMD_RESET
;
6231 mpt2sas_base_free_smid(ioc
, ioc
->scsih_cmds
.smid
);
6232 complete(&ioc
->scsih_cmds
.done
);
6234 if (ioc
->tm_cmds
.status
& MPT2_CMD_PENDING
) {
6235 ioc
->tm_cmds
.status
|= MPT2_CMD_RESET
;
6236 mpt2sas_base_free_smid(ioc
, ioc
->tm_cmds
.smid
);
6237 complete(&ioc
->tm_cmds
.done
);
6239 _scsih_fw_event_cleanup_queue(ioc
);
6240 _scsih_flush_running_cmds(ioc
);
6241 _scsih_queue_rescan(ioc
);
6243 case MPT2_IOC_DONE_RESET
:
6244 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: "
6245 "MPT2_IOC_DONE_RESET\n", ioc
->name
, __func__
));
6246 _scsih_sas_host_refresh(ioc
);
6247 _scsih_prep_device_scan(ioc
);
6248 _scsih_search_responding_sas_devices(ioc
);
6249 _scsih_search_responding_raid_devices(ioc
);
6250 _scsih_search_responding_expanders(ioc
);
6256 * _firmware_event_work - delayed task for processing firmware events
6257 * @ioc: per adapter object
6258 * @work: equal to the fw_event_work object
6264 _firmware_event_work(struct work_struct
*work
)
6266 struct fw_event_work
*fw_event
= container_of(work
,
6267 struct fw_event_work
, delayed_work
.work
);
6268 unsigned long flags
;
6269 struct MPT2SAS_ADAPTER
*ioc
= fw_event
->ioc
;
6271 /* the queue is being flushed so ignore this event */
6272 if (ioc
->remove_host
|| fw_event
->cancel_pending_work
||
6273 ioc
->pci_error_recovery
) {
6274 _scsih_fw_event_free(ioc
, fw_event
);
6278 if (fw_event
->event
== MPT2SAS_RESCAN_AFTER_HOST_RESET
) {
6279 _scsih_fw_event_free(ioc
, fw_event
);
6280 spin_lock_irqsave(&ioc
->ioc_reset_in_progress_lock
, flags
);
6281 if (ioc
->shost_recovery
) {
6282 init_completion(&ioc
->shost_recovery_done
);
6283 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
,
6285 wait_for_completion(&ioc
->shost_recovery_done
);
6287 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
,
6289 _scsih_remove_unresponding_sas_devices(ioc
);
6293 switch (fw_event
->event
) {
6294 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
6295 _scsih_sas_topology_change_event(ioc
, fw_event
);
6297 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
6298 _scsih_sas_device_status_change_event(ioc
,
6301 case MPI2_EVENT_SAS_DISCOVERY
:
6302 _scsih_sas_discovery_event(ioc
,
6305 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
6306 _scsih_sas_broadcast_primative_event(ioc
,
6309 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
6310 _scsih_sas_enclosure_dev_status_change_event(ioc
,
6313 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
6314 _scsih_sas_ir_config_change_event(ioc
, fw_event
);
6316 case MPI2_EVENT_IR_VOLUME
:
6317 _scsih_sas_ir_volume_event(ioc
, fw_event
);
6319 case MPI2_EVENT_IR_PHYSICAL_DISK
:
6320 _scsih_sas_ir_physical_disk_event(ioc
, fw_event
);
6322 case MPI2_EVENT_IR_OPERATION_STATUS
:
6323 _scsih_sas_ir_operation_status_event(ioc
, fw_event
);
6326 _scsih_fw_event_free(ioc
, fw_event
);
6330 * mpt2sas_scsih_event_callback - firmware event handler (called at ISR time)
6331 * @ioc: per adapter object
6332 * @msix_index: MSIX table index supplied by the OS
6333 * @reply: reply message frame(lower 32bit addr)
6334 * Context: interrupt.
6336 * This function merely adds a new work task into ioc->firmware_event_thread.
6337 * The tasks are worked from _firmware_event_work in user context.
6339 * Return 1 meaning mf should be freed from _base_interrupt
6340 * 0 means the mf is freed from this function.
6343 mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER
*ioc
, u8 msix_index
,
6346 struct fw_event_work
*fw_event
;
6347 Mpi2EventNotificationReply_t
*mpi_reply
;
6351 /* events turned off due to host reset or driver unloading */
6352 if (ioc
->remove_host
|| ioc
->pci_error_recovery
)
6355 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
6356 event
= le16_to_cpu(mpi_reply
->Event
);
6360 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
6362 Mpi2EventDataSasBroadcastPrimitive_t
*baen_data
=
6363 (Mpi2EventDataSasBroadcastPrimitive_t
*)
6364 mpi_reply
->EventData
;
6366 if (baen_data
->Primitive
!=
6367 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT
||
6368 ioc
->broadcast_aen_busy
)
6370 ioc
->broadcast_aen_busy
= 1;
6374 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
6375 _scsih_check_topo_delete_events(ioc
,
6376 (Mpi2EventDataSasTopologyChangeList_t
*)
6377 mpi_reply
->EventData
);
6379 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
6380 _scsih_check_ir_config_unhide_events(ioc
,
6381 (Mpi2EventDataIrConfigChangeList_t
*)
6382 mpi_reply
->EventData
);
6384 case MPI2_EVENT_IR_VOLUME
:
6385 _scsih_check_volume_delete_events(ioc
,
6386 (Mpi2EventDataIrVolume_t
*)
6387 mpi_reply
->EventData
);
6389 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
6390 case MPI2_EVENT_IR_OPERATION_STATUS
:
6391 case MPI2_EVENT_SAS_DISCOVERY
:
6392 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
6393 case MPI2_EVENT_IR_PHYSICAL_DISK
:
6396 default: /* ignore the rest */
6400 fw_event
= kzalloc(sizeof(struct fw_event_work
), GFP_ATOMIC
);
6402 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6403 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6406 sz
= le16_to_cpu(mpi_reply
->EventDataLength
) * 4;
6407 fw_event
->event_data
= kzalloc(sz
, GFP_ATOMIC
);
6408 if (!fw_event
->event_data
) {
6409 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6410 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6415 memcpy(fw_event
->event_data
, mpi_reply
->EventData
,
6417 fw_event
->ioc
= ioc
;
6418 fw_event
->VF_ID
= mpi_reply
->VF_ID
;
6419 fw_event
->VP_ID
= mpi_reply
->VP_ID
;
6420 fw_event
->event
= event
;
6421 _scsih_fw_event_add(ioc
, fw_event
);
6425 /* shost template */
6426 static struct scsi_host_template scsih_driver_template
= {
6427 .module
= THIS_MODULE
,
6428 .name
= "Fusion MPT SAS Host",
6429 .proc_name
= MPT2SAS_DRIVER_NAME
,
6430 .queuecommand
= _scsih_qcmd
,
6431 .target_alloc
= _scsih_target_alloc
,
6432 .slave_alloc
= _scsih_slave_alloc
,
6433 .slave_configure
= _scsih_slave_configure
,
6434 .target_destroy
= _scsih_target_destroy
,
6435 .slave_destroy
= _scsih_slave_destroy
,
6436 .change_queue_depth
= _scsih_change_queue_depth
,
6437 .change_queue_type
= _scsih_change_queue_type
,
6438 .eh_abort_handler
= _scsih_abort
,
6439 .eh_device_reset_handler
= _scsih_dev_reset
,
6440 .eh_target_reset_handler
= _scsih_target_reset
,
6441 .eh_host_reset_handler
= _scsih_host_reset
,
6442 .bios_param
= _scsih_bios_param
,
6445 .sg_tablesize
= MPT2SAS_SG_DEPTH
,
6446 .max_sectors
= 8192,
6448 .use_clustering
= ENABLE_CLUSTERING
,
6449 .shost_attrs
= mpt2sas_host_attrs
,
6450 .sdev_attrs
= mpt2sas_dev_attrs
,
6454 * _scsih_expander_node_remove - removing expander device from list.
6455 * @ioc: per adapter object
6456 * @sas_expander: the sas_device object
6457 * Context: Calling function should acquire ioc->sas_node_lock.
6459 * Removing object and freeing associated memory from the
6460 * ioc->sas_expander_list.
6465 _scsih_expander_node_remove(struct MPT2SAS_ADAPTER
*ioc
,
6466 struct _sas_node
*sas_expander
)
6468 struct _sas_port
*mpt2sas_port
, *next
;
6470 /* remove sibling ports attached to this expander */
6471 list_for_each_entry_safe(mpt2sas_port
, next
,
6472 &sas_expander
->sas_port_list
, port_list
) {
6473 if (ioc
->shost_recovery
)
6475 if (mpt2sas_port
->remote_identify
.device_type
==
6477 mpt2sas_device_remove(ioc
,
6478 mpt2sas_port
->remote_identify
.sas_address
);
6479 else if (mpt2sas_port
->remote_identify
.device_type
==
6480 SAS_EDGE_EXPANDER_DEVICE
||
6481 mpt2sas_port
->remote_identify
.device_type
==
6482 SAS_FANOUT_EXPANDER_DEVICE
)
6483 mpt2sas_expander_remove(ioc
,
6484 mpt2sas_port
->remote_identify
.sas_address
);
6487 mpt2sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
6488 sas_expander
->sas_address_parent
);
6490 printk(MPT2SAS_INFO_FMT
"expander_remove: handle"
6491 "(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
6492 sas_expander
->handle
, (unsigned long long)
6493 sas_expander
->sas_address
);
6495 kfree(sas_expander
->phy
);
6496 kfree(sas_expander
);
6500 * _scsih_ir_shutdown - IR shutdown notification
6501 * @ioc: per adapter object
6503 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
6504 * the host system is shutting down.
6509 _scsih_ir_shutdown(struct MPT2SAS_ADAPTER
*ioc
)
6511 Mpi2RaidActionRequest_t
*mpi_request
;
6512 Mpi2RaidActionReply_t
*mpi_reply
;
6515 /* is IR firmware build loaded ? */
6516 if (!ioc
->ir_firmware
)
6519 /* are there any volumes ? */
6520 if (list_empty(&ioc
->raid_device_list
))
6523 mutex_lock(&ioc
->scsih_cmds
.mutex
);
6525 if (ioc
->scsih_cmds
.status
!= MPT2_CMD_NOT_USED
) {
6526 printk(MPT2SAS_ERR_FMT
"%s: scsih_cmd in use\n",
6527 ioc
->name
, __func__
);
6530 ioc
->scsih_cmds
.status
= MPT2_CMD_PENDING
;
6532 smid
= mpt2sas_base_get_smid(ioc
, ioc
->scsih_cb_idx
);
6534 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
6535 ioc
->name
, __func__
);
6536 ioc
->scsih_cmds
.status
= MPT2_CMD_NOT_USED
;
6540 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
6541 ioc
->scsih_cmds
.smid
= smid
;
6542 memset(mpi_request
, 0, sizeof(Mpi2RaidActionRequest_t
));
6544 mpi_request
->Function
= MPI2_FUNCTION_RAID_ACTION
;
6545 mpi_request
->Action
= MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED
;
6547 printk(MPT2SAS_INFO_FMT
"IR shutdown (sending)\n", ioc
->name
);
6548 init_completion(&ioc
->scsih_cmds
.done
);
6549 mpt2sas_base_put_smid_default(ioc
, smid
);
6550 wait_for_completion_timeout(&ioc
->scsih_cmds
.done
, 10*HZ
);
6552 if (!(ioc
->scsih_cmds
.status
& MPT2_CMD_COMPLETE
)) {
6553 printk(MPT2SAS_ERR_FMT
"%s: timeout\n",
6554 ioc
->name
, __func__
);
6558 if (ioc
->scsih_cmds
.status
& MPT2_CMD_REPLY_VALID
) {
6559 mpi_reply
= ioc
->scsih_cmds
.reply
;
6561 printk(MPT2SAS_INFO_FMT
"IR shutdown (complete): "
6562 "ioc_status(0x%04x), loginfo(0x%08x)\n",
6563 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
6564 le32_to_cpu(mpi_reply
->IOCLogInfo
));
6568 ioc
->scsih_cmds
.status
= MPT2_CMD_NOT_USED
;
6569 mutex_unlock(&ioc
->scsih_cmds
.mutex
);
6573 * _scsih_shutdown - routine call during system shutdown
6574 * @pdev: PCI device struct
6579 _scsih_shutdown(struct pci_dev
*pdev
)
6581 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6582 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
6583 struct workqueue_struct
*wq
;
6584 unsigned long flags
;
6586 ioc
->remove_host
= 1;
6587 _scsih_fw_event_cleanup_queue(ioc
);
6589 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
6590 wq
= ioc
->firmware_event_thread
;
6591 ioc
->firmware_event_thread
= NULL
;
6592 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
6594 destroy_workqueue(wq
);
6596 _scsih_ir_shutdown(ioc
);
6597 mpt2sas_base_detach(ioc
);
6601 * _scsih_remove - detach and remove add host
6602 * @pdev: PCI device struct
6604 * Routine called when unloading the driver.
6607 static void __devexit
6608 _scsih_remove(struct pci_dev
*pdev
)
6610 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6611 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
6612 struct _sas_port
*mpt2sas_port
, *next_port
;
6613 struct _raid_device
*raid_device
, *next
;
6614 struct MPT2SAS_TARGET
*sas_target_priv_data
;
6615 struct workqueue_struct
*wq
;
6616 unsigned long flags
;
6618 ioc
->remove_host
= 1;
6619 _scsih_fw_event_cleanup_queue(ioc
);
6621 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
6622 wq
= ioc
->firmware_event_thread
;
6623 ioc
->firmware_event_thread
= NULL
;
6624 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
6626 destroy_workqueue(wq
);
6628 /* release all the volumes */
6629 list_for_each_entry_safe(raid_device
, next
, &ioc
->raid_device_list
,
6631 if (raid_device
->starget
) {
6632 sas_target_priv_data
=
6633 raid_device
->starget
->hostdata
;
6634 sas_target_priv_data
->deleted
= 1;
6635 scsi_remove_target(&raid_device
->starget
->dev
);
6637 printk(MPT2SAS_INFO_FMT
"removing handle(0x%04x), wwid"
6638 "(0x%016llx)\n", ioc
->name
, raid_device
->handle
,
6639 (unsigned long long) raid_device
->wwid
);
6640 _scsih_raid_device_remove(ioc
, raid_device
);
6643 /* free ports attached to the sas_host */
6644 list_for_each_entry_safe(mpt2sas_port
, next_port
,
6645 &ioc
->sas_hba
.sas_port_list
, port_list
) {
6646 if (mpt2sas_port
->remote_identify
.device_type
==
6648 mpt2sas_device_remove(ioc
,
6649 mpt2sas_port
->remote_identify
.sas_address
);
6650 else if (mpt2sas_port
->remote_identify
.device_type
==
6651 SAS_EDGE_EXPANDER_DEVICE
||
6652 mpt2sas_port
->remote_identify
.device_type
==
6653 SAS_FANOUT_EXPANDER_DEVICE
)
6654 mpt2sas_expander_remove(ioc
,
6655 mpt2sas_port
->remote_identify
.sas_address
);
6658 /* free phys attached to the sas_host */
6659 if (ioc
->sas_hba
.num_phys
) {
6660 kfree(ioc
->sas_hba
.phy
);
6661 ioc
->sas_hba
.phy
= NULL
;
6662 ioc
->sas_hba
.num_phys
= 0;
6665 sas_remove_host(shost
);
6666 _scsih_shutdown(pdev
);
6667 list_del(&ioc
->list
);
6668 scsi_remove_host(shost
);
6669 scsi_host_put(shost
);
6673 * _scsih_probe_boot_devices - reports 1st device
6674 * @ioc: per adapter object
6676 * If specified in bios page 2, this routine reports the 1st
6677 * device scsi-ml or sas transport for persistent boot device
6678 * purposes. Please refer to function _scsih_determine_boot_device()
6681 _scsih_probe_boot_devices(struct MPT2SAS_ADAPTER
*ioc
)
6685 struct _sas_device
*sas_device
;
6686 struct _raid_device
*raid_device
;
6688 u64 sas_address_parent
;
6690 unsigned long flags
;
6694 if (ioc
->req_boot_device
.device
) {
6695 device
= ioc
->req_boot_device
.device
;
6696 is_raid
= ioc
->req_boot_device
.is_raid
;
6697 } else if (ioc
->req_alt_boot_device
.device
) {
6698 device
= ioc
->req_alt_boot_device
.device
;
6699 is_raid
= ioc
->req_alt_boot_device
.is_raid
;
6700 } else if (ioc
->current_boot_device
.device
) {
6701 device
= ioc
->current_boot_device
.device
;
6702 is_raid
= ioc
->current_boot_device
.is_raid
;
6709 raid_device
= device
;
6710 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
6711 raid_device
->id
, 0);
6713 _scsih_raid_device_remove(ioc
, raid_device
);
6715 sas_device
= device
;
6716 handle
= sas_device
->handle
;
6717 sas_address_parent
= sas_device
->sas_address_parent
;
6718 sas_address
= sas_device
->sas_address
;
6719 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6720 list_move_tail(&sas_device
->list
, &ioc
->sas_device_list
);
6721 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6722 if (!mpt2sas_transport_port_add(ioc
, sas_device
->handle
,
6723 sas_device
->sas_address_parent
)) {
6724 _scsih_sas_device_remove(ioc
, sas_device
);
6725 } else if (!sas_device
->starget
) {
6726 mpt2sas_transport_port_remove(ioc
, sas_address
,
6727 sas_address_parent
);
6728 _scsih_sas_device_remove(ioc
, sas_device
);
6734 * _scsih_probe_raid - reporting raid volumes to scsi-ml
6735 * @ioc: per adapter object
6737 * Called during initial loading of the driver.
6740 _scsih_probe_raid(struct MPT2SAS_ADAPTER
*ioc
)
6742 struct _raid_device
*raid_device
, *raid_next
;
6745 list_for_each_entry_safe(raid_device
, raid_next
,
6746 &ioc
->raid_device_list
, list
) {
6747 if (raid_device
->starget
)
6749 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
6750 raid_device
->id
, 0);
6752 _scsih_raid_device_remove(ioc
, raid_device
);
6757 * _scsih_probe_sas - reporting sas devices to sas transport
6758 * @ioc: per adapter object
6760 * Called during initial loading of the driver.
6763 _scsih_probe_sas(struct MPT2SAS_ADAPTER
*ioc
)
6765 struct _sas_device
*sas_device
, *next
;
6766 unsigned long flags
;
6768 /* SAS Device List */
6769 list_for_each_entry_safe(sas_device
, next
, &ioc
->sas_device_init_list
,
6771 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6772 list_move_tail(&sas_device
->list
, &ioc
->sas_device_list
);
6773 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6775 if (!mpt2sas_transport_port_add(ioc
, sas_device
->handle
,
6776 sas_device
->sas_address_parent
)) {
6777 _scsih_sas_device_remove(ioc
, sas_device
);
6778 } else if (!sas_device
->starget
) {
6779 mpt2sas_transport_port_remove(ioc
,
6780 sas_device
->sas_address
,
6781 sas_device
->sas_address_parent
);
6782 _scsih_sas_device_remove(ioc
, sas_device
);
6788 * _scsih_probe_devices - probing for devices
6789 * @ioc: per adapter object
6791 * Called during initial loading of the driver.
6794 _scsih_probe_devices(struct MPT2SAS_ADAPTER
*ioc
)
6796 u16 volume_mapping_flags
=
6797 le16_to_cpu(ioc
->ioc_pg8
.IRVolumeMappingFlags
) &
6798 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE
;
6800 if (!(ioc
->facts
.ProtocolFlags
& MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR
))
6801 return; /* return when IOC doesn't support initiator mode */
6803 _scsih_probe_boot_devices(ioc
);
6805 if (ioc
->ir_firmware
) {
6806 if ((volume_mapping_flags
&
6807 MPI2_IOCPAGE8_IRFLAGS_HIGH_VOLUME_MAPPING
)) {
6808 _scsih_probe_sas(ioc
);
6809 _scsih_probe_raid(ioc
);
6811 _scsih_probe_raid(ioc
);
6812 _scsih_probe_sas(ioc
);
6815 _scsih_probe_sas(ioc
);
6819 * _scsih_probe - attach and add scsi host
6820 * @pdev: PCI device struct
6821 * @id: pci device id
6823 * Returns 0 success, anything else error.
6826 _scsih_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
6828 struct MPT2SAS_ADAPTER
*ioc
;
6829 struct Scsi_Host
*shost
;
6831 shost
= scsi_host_alloc(&scsih_driver_template
,
6832 sizeof(struct MPT2SAS_ADAPTER
));
6836 /* init local params */
6837 ioc
= shost_priv(shost
);
6838 memset(ioc
, 0, sizeof(struct MPT2SAS_ADAPTER
));
6839 INIT_LIST_HEAD(&ioc
->list
);
6840 list_add_tail(&ioc
->list
, &mpt2sas_ioc_list
);
6842 ioc
->id
= mpt_ids
++;
6843 sprintf(ioc
->name
, "%s%d", MPT2SAS_DRIVER_NAME
, ioc
->id
);
6845 ioc
->scsi_io_cb_idx
= scsi_io_cb_idx
;
6846 ioc
->tm_cb_idx
= tm_cb_idx
;
6847 ioc
->ctl_cb_idx
= ctl_cb_idx
;
6848 ioc
->base_cb_idx
= base_cb_idx
;
6849 ioc
->transport_cb_idx
= transport_cb_idx
;
6850 ioc
->scsih_cb_idx
= scsih_cb_idx
;
6851 ioc
->config_cb_idx
= config_cb_idx
;
6852 ioc
->tm_tr_cb_idx
= tm_tr_cb_idx
;
6853 ioc
->tm_tr_volume_cb_idx
= tm_tr_volume_cb_idx
;
6854 ioc
->tm_sas_control_cb_idx
= tm_sas_control_cb_idx
;
6855 ioc
->logging_level
= logging_level
;
6856 /* misc semaphores and spin locks */
6857 mutex_init(&ioc
->reset_in_progress_mutex
);
6858 spin_lock_init(&ioc
->ioc_reset_in_progress_lock
);
6859 spin_lock_init(&ioc
->scsi_lookup_lock
);
6860 spin_lock_init(&ioc
->sas_device_lock
);
6861 spin_lock_init(&ioc
->sas_node_lock
);
6862 spin_lock_init(&ioc
->fw_event_lock
);
6863 spin_lock_init(&ioc
->raid_device_lock
);
6865 INIT_LIST_HEAD(&ioc
->sas_device_list
);
6866 INIT_LIST_HEAD(&ioc
->sas_device_init_list
);
6867 INIT_LIST_HEAD(&ioc
->sas_expander_list
);
6868 INIT_LIST_HEAD(&ioc
->fw_event_list
);
6869 INIT_LIST_HEAD(&ioc
->raid_device_list
);
6870 INIT_LIST_HEAD(&ioc
->sas_hba
.sas_port_list
);
6871 INIT_LIST_HEAD(&ioc
->delayed_tr_list
);
6872 INIT_LIST_HEAD(&ioc
->delayed_tr_volume_list
);
6874 /* init shost parameters */
6875 shost
->max_cmd_len
= 32;
6876 shost
->max_lun
= max_lun
;
6877 shost
->transportt
= mpt2sas_transport_template
;
6878 shost
->unique_id
= ioc
->id
;
6880 if ((scsi_add_host(shost
, &pdev
->dev
))) {
6881 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6882 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6883 list_del(&ioc
->list
);
6884 goto out_add_shost_fail
;
6887 scsi_host_set_prot(shost
, SHOST_DIF_TYPE1_PROTECTION
6888 | SHOST_DIF_TYPE2_PROTECTION
| SHOST_DIF_TYPE3_PROTECTION
);
6889 scsi_host_set_guard(shost
, SHOST_DIX_GUARD_CRC
);
6892 snprintf(ioc
->firmware_event_name
, sizeof(ioc
->firmware_event_name
),
6893 "fw_event%d", ioc
->id
);
6894 ioc
->firmware_event_thread
= create_singlethread_workqueue(
6895 ioc
->firmware_event_name
);
6896 if (!ioc
->firmware_event_thread
) {
6897 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6898 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6899 goto out_thread_fail
;
6902 ioc
->wait_for_port_enable_to_complete
= 1;
6903 if ((mpt2sas_base_attach(ioc
))) {
6904 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6905 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6906 goto out_attach_fail
;
6909 ioc
->wait_for_port_enable_to_complete
= 0;
6910 _scsih_probe_devices(ioc
);
6914 destroy_workqueue(ioc
->firmware_event_thread
);
6916 list_del(&ioc
->list
);
6917 scsi_remove_host(shost
);
6924 * _scsih_suspend - power management suspend main entry point
6925 * @pdev: PCI device struct
6926 * @state: PM state change to (usually PCI_D3)
6928 * Returns 0 success, anything else error.
6931 _scsih_suspend(struct pci_dev
*pdev
, pm_message_t state
)
6933 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6934 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
6937 mpt2sas_base_stop_watchdog(ioc
);
6938 flush_scheduled_work();
6939 scsi_block_requests(shost
);
6940 device_state
= pci_choose_state(pdev
, state
);
6941 printk(MPT2SAS_INFO_FMT
"pdev=0x%p, slot=%s, entering "
6942 "operating state [D%d]\n", ioc
->name
, pdev
,
6943 pci_name(pdev
), device_state
);
6945 mpt2sas_base_free_resources(ioc
);
6946 pci_save_state(pdev
);
6947 pci_disable_device(pdev
);
6948 pci_set_power_state(pdev
, device_state
);
6953 * _scsih_resume - power management resume main entry point
6954 * @pdev: PCI device struct
6956 * Returns 0 success, anything else error.
6959 _scsih_resume(struct pci_dev
*pdev
)
6961 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6962 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
6963 u32 device_state
= pdev
->current_state
;
6966 printk(MPT2SAS_INFO_FMT
"pdev=0x%p, slot=%s, previous "
6967 "operating state [D%d]\n", ioc
->name
, pdev
,
6968 pci_name(pdev
), device_state
);
6970 pci_set_power_state(pdev
, PCI_D0
);
6971 pci_enable_wake(pdev
, PCI_D0
, 0);
6972 pci_restore_state(pdev
);
6974 r
= mpt2sas_base_map_resources(ioc
);
6978 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
, SOFT_RESET
);
6979 scsi_unblock_requests(shost
);
6980 mpt2sas_base_start_watchdog(ioc
);
6983 #endif /* CONFIG_PM */
6986 * _scsih_pci_error_detected - Called when a PCI error is detected.
6987 * @pdev: PCI device struct
6988 * @state: PCI channel state
6990 * Description: Called when a PCI error is detected.
6993 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
6995 static pci_ers_result_t
6996 _scsih_pci_error_detected(struct pci_dev
*pdev
, pci_channel_state_t state
)
6998 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6999 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
7001 printk(MPT2SAS_INFO_FMT
"PCI error: detected callback, state(%d)!!\n",
7005 case pci_channel_io_normal
:
7006 return PCI_ERS_RESULT_CAN_RECOVER
;
7007 case pci_channel_io_frozen
:
7008 /* Fatal error, prepare for slot reset */
7009 ioc
->pci_error_recovery
= 1;
7010 scsi_block_requests(ioc
->shost
);
7011 mpt2sas_base_stop_watchdog(ioc
);
7012 mpt2sas_base_free_resources(ioc
);
7013 return PCI_ERS_RESULT_NEED_RESET
;
7014 case pci_channel_io_perm_failure
:
7015 /* Permanent error, prepare for device removal */
7016 ioc
->pci_error_recovery
= 1;
7017 mpt2sas_base_stop_watchdog(ioc
);
7018 _scsih_flush_running_cmds(ioc
);
7019 return PCI_ERS_RESULT_DISCONNECT
;
7021 return PCI_ERS_RESULT_NEED_RESET
;
7025 * _scsih_pci_slot_reset - Called when PCI slot has been reset.
7026 * @pdev: PCI device struct
7028 * Description: This routine is called by the pci error recovery
7029 * code after the PCI slot has been reset, just before we
7030 * should resume normal operations.
7032 static pci_ers_result_t
7033 _scsih_pci_slot_reset(struct pci_dev
*pdev
)
7035 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
7036 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
7039 printk(MPT2SAS_INFO_FMT
"PCI error: slot reset callback!!\n",
7042 ioc
->pci_error_recovery
= 0;
7044 pci_restore_state(pdev
);
7045 rc
= mpt2sas_base_map_resources(ioc
);
7047 return PCI_ERS_RESULT_DISCONNECT
;
7050 rc
= mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
7053 printk(MPT2SAS_WARN_FMT
"hard reset: %s\n", ioc
->name
,
7054 (rc
== 0) ? "success" : "failed");
7057 return PCI_ERS_RESULT_RECOVERED
;
7059 return PCI_ERS_RESULT_DISCONNECT
;
7063 * _scsih_pci_resume() - resume normal ops after PCI reset
7064 * @pdev: pointer to PCI device
7066 * Called when the error recovery driver tells us that its
7067 * OK to resume normal operation. Use completion to allow
7068 * halted scsi ops to resume.
7071 _scsih_pci_resume(struct pci_dev
*pdev
)
7073 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
7074 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
7076 printk(MPT2SAS_INFO_FMT
"PCI error: resume callback!!\n", ioc
->name
);
7078 pci_cleanup_aer_uncorrect_error_status(pdev
);
7079 mpt2sas_base_start_watchdog(ioc
);
7080 scsi_unblock_requests(ioc
->shost
);
7084 * _scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
7085 * @pdev: pointer to PCI device
7087 static pci_ers_result_t
7088 _scsih_pci_mmio_enabled(struct pci_dev
*pdev
)
7090 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
7091 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
7093 printk(MPT2SAS_INFO_FMT
"PCI error: mmio enabled callback!!\n",
7096 /* TODO - dump whatever for debugging purposes */
7098 /* Request a slot reset. */
7099 return PCI_ERS_RESULT_NEED_RESET
;
7102 static struct pci_error_handlers _scsih_err_handler
= {
7103 .error_detected
= _scsih_pci_error_detected
,
7104 .mmio_enabled
= _scsih_pci_mmio_enabled
,
7105 .slot_reset
= _scsih_pci_slot_reset
,
7106 .resume
= _scsih_pci_resume
,
7109 static struct pci_driver scsih_driver
= {
7110 .name
= MPT2SAS_DRIVER_NAME
,
7111 .id_table
= scsih_pci_table
,
7112 .probe
= _scsih_probe
,
7113 .remove
= __devexit_p(_scsih_remove
),
7114 .shutdown
= _scsih_shutdown
,
7115 .err_handler
= &_scsih_err_handler
,
7117 .suspend
= _scsih_suspend
,
7118 .resume
= _scsih_resume
,
7122 /* raid transport support */
7123 static struct raid_function_template mpt2sas_raid_functions
= {
7124 .cookie
= &scsih_driver_template
,
7125 .is_raid
= _scsih_is_raid
,
7126 .get_resync
= _scsih_get_resync
,
7127 .get_state
= _scsih_get_state
,
7131 * _scsih_init - main entry point for this driver.
7133 * Returns 0 success, anything else error.
7141 printk(KERN_INFO
"%s version %s loaded\n", MPT2SAS_DRIVER_NAME
,
7142 MPT2SAS_DRIVER_VERSION
);
7144 mpt2sas_transport_template
=
7145 sas_attach_transport(&mpt2sas_transport_functions
);
7146 if (!mpt2sas_transport_template
)
7148 /* raid transport support */
7149 mpt2sas_raid_template
= raid_class_attach(&mpt2sas_raid_functions
);
7150 if (!mpt2sas_raid_template
) {
7151 sas_release_transport(mpt2sas_transport_template
);
7155 mpt2sas_base_initialize_callback_handler();
7157 /* queuecommand callback hander */
7158 scsi_io_cb_idx
= mpt2sas_base_register_callback_handler(_scsih_io_done
);
7160 /* task management callback handler */
7161 tm_cb_idx
= mpt2sas_base_register_callback_handler(_scsih_tm_done
);
7163 /* base internal commands callback handler */
7164 base_cb_idx
= mpt2sas_base_register_callback_handler(mpt2sas_base_done
);
7166 /* transport internal commands callback handler */
7167 transport_cb_idx
= mpt2sas_base_register_callback_handler(
7168 mpt2sas_transport_done
);
7170 /* scsih internal commands callback handler */
7171 scsih_cb_idx
= mpt2sas_base_register_callback_handler(_scsih_done
);
7173 /* configuration page API internal commands callback handler */
7174 config_cb_idx
= mpt2sas_base_register_callback_handler(
7175 mpt2sas_config_done
);
7177 /* ctl module callback handler */
7178 ctl_cb_idx
= mpt2sas_base_register_callback_handler(mpt2sas_ctl_done
);
7180 tm_tr_cb_idx
= mpt2sas_base_register_callback_handler(
7181 _scsih_tm_tr_complete
);
7183 tm_tr_volume_cb_idx
= mpt2sas_base_register_callback_handler(
7184 _scsih_tm_volume_tr_complete
);
7186 tm_sas_control_cb_idx
= mpt2sas_base_register_callback_handler(
7187 _scsih_sas_control_complete
);
7191 error
= pci_register_driver(&scsih_driver
);
7193 /* raid transport support */
7194 raid_class_release(mpt2sas_raid_template
);
7195 sas_release_transport(mpt2sas_transport_template
);
7202 * _scsih_exit - exit point for this driver (when it is a module).
7204 * Returns 0 success, anything else error.
7209 printk(KERN_INFO
"mpt2sas version %s unloading\n",
7210 MPT2SAS_DRIVER_VERSION
);
7212 pci_unregister_driver(&scsih_driver
);
7216 mpt2sas_base_release_callback_handler(scsi_io_cb_idx
);
7217 mpt2sas_base_release_callback_handler(tm_cb_idx
);
7218 mpt2sas_base_release_callback_handler(base_cb_idx
);
7219 mpt2sas_base_release_callback_handler(transport_cb_idx
);
7220 mpt2sas_base_release_callback_handler(scsih_cb_idx
);
7221 mpt2sas_base_release_callback_handler(config_cb_idx
);
7222 mpt2sas_base_release_callback_handler(ctl_cb_idx
);
7224 mpt2sas_base_release_callback_handler(tm_tr_cb_idx
);
7225 mpt2sas_base_release_callback_handler(tm_tr_volume_cb_idx
);
7226 mpt2sas_base_release_callback_handler(tm_sas_control_cb_idx
);
7228 /* raid transport support */
7229 raid_class_release(mpt2sas_raid_template
);
7230 sas_release_transport(mpt2sas_transport_template
);
7234 module_init(_scsih_init
);
7235 module_exit(_scsih_exit
);