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 target 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
, "target 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
;
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 else if (parent_handle
< ioc
->sas_hba
.num_phys
)
4840 sas_address
= ioc
->sas_hba
.sas_address
;
4844 /* handle siblings events */
4845 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
4846 if (fw_event
->ignore
) {
4847 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"ignoring "
4848 "expander event\n", ioc
->name
));
4851 if (ioc
->shost_recovery
|| ioc
->remove_host
||
4852 ioc
->pci_error_recovery
)
4854 phy_number
= event_data
->StartPhyNum
+ i
;
4855 reason_code
= event_data
->PHY
[i
].PhyStatus
&
4856 MPI2_EVENT_SAS_TOPO_RC_MASK
;
4857 if ((event_data
->PHY
[i
].PhyStatus
&
4858 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT
) && (reason_code
!=
4859 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
))
4861 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
4864 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
4865 prev_link_rate
= event_data
->PHY
[i
].LinkRate
& 0xF;
4866 switch (reason_code
) {
4867 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
4869 if (link_rate
== prev_link_rate
)
4872 mpt2sas_transport_update_links(ioc
, sas_address
,
4873 handle
, phy_number
, link_rate
);
4875 if (link_rate
< MPI2_SAS_NEG_LINK_RATE_1_5
)
4878 _scsih_check_device(ioc
, handle
);
4880 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
4882 mpt2sas_transport_update_links(ioc
, sas_address
,
4883 handle
, phy_number
, link_rate
);
4885 _scsih_add_device(ioc
, handle
, phy_number
, 0);
4887 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
4889 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4890 sas_device
= _scsih_sas_device_find_by_handle(ioc
,
4893 spin_unlock_irqrestore(&ioc
->sas_device_lock
,
4897 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4898 _scsih_remove_device(ioc
, sas_device
);
4903 /* handle expander removal */
4904 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
&&
4906 mpt2sas_expander_remove(ioc
, sas_address
);
4910 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4912 * _scsih_sas_device_status_change_event_debug - debug for device event
4913 * @event_data: event data payload
4919 _scsih_sas_device_status_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
4920 Mpi2EventDataSasDeviceStatusChange_t
*event_data
)
4922 char *reason_str
= NULL
;
4924 switch (event_data
->ReasonCode
) {
4925 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
:
4926 reason_str
= "smart data";
4928 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED
:
4929 reason_str
= "unsupported device discovered";
4931 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
:
4932 reason_str
= "internal device reset";
4934 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL
:
4935 reason_str
= "internal task abort";
4937 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL
:
4938 reason_str
= "internal task abort set";
4940 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL
:
4941 reason_str
= "internal clear task set";
4943 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL
:
4944 reason_str
= "internal query task";
4946 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE
:
4947 reason_str
= "sata init failure";
4949 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
:
4950 reason_str
= "internal device reset complete";
4952 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL
:
4953 reason_str
= "internal task abort complete";
4955 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION
:
4956 reason_str
= "internal async notification";
4958 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY
:
4959 reason_str
= "expander reduced functionality";
4961 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY
:
4962 reason_str
= "expander reduced functionality complete";
4965 reason_str
= "unknown reason";
4968 printk(MPT2SAS_INFO_FMT
"device status change: (%s)\n"
4969 "\thandle(0x%04x), sas address(0x%016llx)", ioc
->name
,
4970 reason_str
, le16_to_cpu(event_data
->DevHandle
),
4971 (unsigned long long)le64_to_cpu(event_data
->SASAddress
));
4972 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
)
4973 printk(MPT2SAS_INFO_FMT
", ASC(0x%x), ASCQ(0x%x)\n", ioc
->name
,
4974 event_data
->ASC
, event_data
->ASCQ
);
4975 printk(KERN_INFO
"\n");
4980 * _scsih_sas_device_status_change_event - handle device status change
4981 * @ioc: per adapter object
4982 * @fw_event: The fw_event_work object
4988 _scsih_sas_device_status_change_event(struct MPT2SAS_ADAPTER
*ioc
,
4989 struct fw_event_work
*fw_event
)
4991 struct MPT2SAS_TARGET
*target_priv_data
;
4992 struct _sas_device
*sas_device
;
4994 unsigned long flags
;
4995 Mpi2EventDataSasDeviceStatusChange_t
*event_data
=
4996 fw_event
->event_data
;
4998 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4999 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5000 _scsih_sas_device_status_change_event_debug(ioc
,
5004 if (event_data
->ReasonCode
!=
5005 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
&&
5006 event_data
->ReasonCode
!=
5007 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
)
5010 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5011 sas_address
= le64_to_cpu(event_data
->SASAddress
);
5012 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
5014 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5016 if (!sas_device
|| !sas_device
->starget
)
5019 target_priv_data
= sas_device
->starget
->hostdata
;
5020 if (!target_priv_data
)
5023 if (event_data
->ReasonCode
==
5024 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
)
5025 target_priv_data
->tm_busy
= 1;
5027 target_priv_data
->tm_busy
= 0;
5030 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5032 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure event
5033 * @ioc: per adapter object
5034 * @event_data: event data payload
5040 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
5041 Mpi2EventDataSasEnclDevStatusChange_t
*event_data
)
5043 char *reason_str
= NULL
;
5045 switch (event_data
->ReasonCode
) {
5046 case MPI2_EVENT_SAS_ENCL_RC_ADDED
:
5047 reason_str
= "enclosure add";
5049 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING
:
5050 reason_str
= "enclosure remove";
5053 reason_str
= "unknown reason";
5057 printk(MPT2SAS_INFO_FMT
"enclosure status change: (%s)\n"
5058 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
5059 " number slots(%d)\n", ioc
->name
, reason_str
,
5060 le16_to_cpu(event_data
->EnclosureHandle
),
5061 (unsigned long long)le64_to_cpu(event_data
->EnclosureLogicalID
),
5062 le16_to_cpu(event_data
->StartSlot
));
5067 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
5068 * @ioc: per adapter object
5069 * @fw_event: The fw_event_work object
5075 _scsih_sas_enclosure_dev_status_change_event(struct MPT2SAS_ADAPTER
*ioc
,
5076 struct fw_event_work
*fw_event
)
5078 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5079 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5080 _scsih_sas_enclosure_dev_status_change_event_debug(ioc
,
5081 fw_event
->event_data
);
5086 * _scsih_sas_broadcast_primative_event - handle broadcast events
5087 * @ioc: per adapter object
5088 * @fw_event: The fw_event_work object
5094 _scsih_sas_broadcast_primative_event(struct MPT2SAS_ADAPTER
*ioc
,
5095 struct fw_event_work
*fw_event
)
5097 struct scsi_cmnd
*scmd
;
5100 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
5101 u32 termination_count
;
5103 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
5104 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5105 Mpi2EventDataSasBroadcastPrimitive_t
*event_data
= fw_event
->event_data
;
5108 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"broadcast primative: "
5109 "phy number(%d), width(%d)\n", ioc
->name
, event_data
->PhyNum
,
5110 event_data
->PortWidth
));
5111 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: enter\n", ioc
->name
,
5114 termination_count
= 0;
5116 mpi_reply
= ioc
->tm_cmds
.reply
;
5117 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
5118 scmd
= _scsih_scsi_lookup_get(ioc
, smid
);
5121 sas_device_priv_data
= scmd
->device
->hostdata
;
5122 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
)
5124 /* skip hidden raid components */
5125 if (sas_device_priv_data
->sas_target
->flags
&
5126 MPT_TARGET_FLAGS_RAID_COMPONENT
)
5129 if (sas_device_priv_data
->sas_target
->flags
&
5130 MPT_TARGET_FLAGS_VOLUME
)
5133 handle
= sas_device_priv_data
->sas_target
->handle
;
5134 lun
= sas_device_priv_data
->lun
;
5137 mpt2sas_scsih_issue_tm(ioc
, handle
, 0, 0, lun
,
5138 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK
, smid
, 30, NULL
);
5139 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
5140 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
)
5141 & MPI2_IOCSTATUS_MASK
;
5142 if ((ioc_status
== MPI2_IOCSTATUS_SUCCESS
) &&
5143 (mpi_reply
->ResponseCode
==
5144 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
||
5145 mpi_reply
->ResponseCode
==
5146 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
))
5149 mpt2sas_scsih_issue_tm(ioc
, handle
, 0, 0, lun
,
5150 MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET
, 0, 30, NULL
);
5151 termination_count
+= le32_to_cpu(mpi_reply
->TerminationCount
);
5153 ioc
->broadcast_aen_busy
= 0;
5155 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
5156 "%s - exit, query_count = %d termination_count = %d\n",
5157 ioc
->name
, __func__
, query_count
, termination_count
));
5161 * _scsih_sas_discovery_event - handle discovery events
5162 * @ioc: per adapter object
5163 * @fw_event: The fw_event_work object
5169 _scsih_sas_discovery_event(struct MPT2SAS_ADAPTER
*ioc
,
5170 struct fw_event_work
*fw_event
)
5172 Mpi2EventDataSasDiscovery_t
*event_data
= fw_event
->event_data
;
5174 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5175 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
) {
5176 printk(MPT2SAS_INFO_FMT
"discovery event: (%s)", ioc
->name
,
5177 (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
) ?
5179 if (event_data
->DiscoveryStatus
)
5180 printk("discovery_status(0x%08x)",
5181 le32_to_cpu(event_data
->DiscoveryStatus
));
5186 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
&&
5187 !ioc
->sas_hba
.num_phys
)
5188 _scsih_sas_host_add(ioc
);
5192 * _scsih_reprobe_lun - reprobing lun
5193 * @sdev: scsi device struct
5194 * @no_uld_attach: sdev->no_uld_attach flag setting
5198 _scsih_reprobe_lun(struct scsi_device
*sdev
, void *no_uld_attach
)
5202 sdev
->no_uld_attach
= no_uld_attach
? 1 : 0;
5203 sdev_printk(KERN_INFO
, sdev
, "%s raid component\n",
5204 sdev
->no_uld_attach
? "hidding" : "exposing");
5205 rc
= scsi_device_reprobe(sdev
);
5209 * _scsih_reprobe_target - reprobing target
5210 * @starget: scsi target struct
5211 * @no_uld_attach: sdev->no_uld_attach flag setting
5213 * Note: no_uld_attach flag determines whether the disk device is attached
5214 * to block layer. A value of `1` means to not attach.
5217 _scsih_reprobe_target(struct scsi_target
*starget
, int no_uld_attach
)
5219 struct MPT2SAS_TARGET
*sas_target_priv_data
= starget
->hostdata
;
5222 sas_target_priv_data
->flags
|= MPT_TARGET_FLAGS_RAID_COMPONENT
;
5224 sas_target_priv_data
->flags
&= ~MPT_TARGET_FLAGS_RAID_COMPONENT
;
5226 starget_for_each_device(starget
, no_uld_attach
? (void *)1 : NULL
,
5227 _scsih_reprobe_lun
);
5230 * _scsih_sas_volume_add - add new volume
5231 * @ioc: per adapter object
5232 * @element: IR config element data
5238 _scsih_sas_volume_add(struct MPT2SAS_ADAPTER
*ioc
,
5239 Mpi2EventIrConfigElement_t
*element
)
5241 struct _raid_device
*raid_device
;
5242 unsigned long flags
;
5244 u16 handle
= le16_to_cpu(element
->VolDevHandle
);
5247 mpt2sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
5249 printk(MPT2SAS_ERR_FMT
5250 "failure at %s:%d/%s()!\n", ioc
->name
,
5251 __FILE__
, __LINE__
, __func__
);
5255 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5256 raid_device
= _scsih_raid_device_find_by_wwid(ioc
, wwid
);
5257 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5262 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
5264 printk(MPT2SAS_ERR_FMT
5265 "failure at %s:%d/%s()!\n", ioc
->name
,
5266 __FILE__
, __LINE__
, __func__
);
5270 raid_device
->id
= ioc
->sas_id
++;
5271 raid_device
->channel
= RAID_CHANNEL
;
5272 raid_device
->handle
= handle
;
5273 raid_device
->wwid
= wwid
;
5274 _scsih_raid_device_add(ioc
, raid_device
);
5275 if (!ioc
->wait_for_port_enable_to_complete
) {
5276 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
5277 raid_device
->id
, 0);
5279 _scsih_raid_device_remove(ioc
, raid_device
);
5281 _scsih_determine_boot_device(ioc
, raid_device
, 1);
5285 * _scsih_sas_volume_delete - delete volume
5286 * @ioc: per adapter object
5287 * @handle: volume device handle
5293 _scsih_sas_volume_delete(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
5295 struct _raid_device
*raid_device
;
5296 unsigned long flags
;
5297 struct MPT2SAS_TARGET
*sas_target_priv_data
;
5299 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5300 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
5301 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5304 if (raid_device
->starget
) {
5305 sas_target_priv_data
= raid_device
->starget
->hostdata
;
5306 sas_target_priv_data
->deleted
= 1;
5307 scsi_remove_target(&raid_device
->starget
->dev
);
5309 printk(MPT2SAS_INFO_FMT
"removing handle(0x%04x), wwid"
5310 "(0x%016llx)\n", ioc
->name
, raid_device
->handle
,
5311 (unsigned long long) raid_device
->wwid
);
5312 _scsih_raid_device_remove(ioc
, raid_device
);
5316 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
5317 * @ioc: per adapter object
5318 * @element: IR config element data
5324 _scsih_sas_pd_expose(struct MPT2SAS_ADAPTER
*ioc
,
5325 Mpi2EventIrConfigElement_t
*element
)
5327 struct _sas_device
*sas_device
;
5328 unsigned long flags
;
5329 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
5331 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5332 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
5333 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5337 /* exposing raid component */
5338 sas_device
->volume_handle
= 0;
5339 sas_device
->volume_wwid
= 0;
5340 clear_bit(handle
, ioc
->pd_handles
);
5341 _scsih_reprobe_target(sas_device
->starget
, 0);
5345 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
5346 * @ioc: per adapter object
5347 * @element: IR config element data
5353 _scsih_sas_pd_hide(struct MPT2SAS_ADAPTER
*ioc
,
5354 Mpi2EventIrConfigElement_t
*element
)
5356 struct _sas_device
*sas_device
;
5357 unsigned long flags
;
5358 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
5360 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5361 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
5362 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5366 /* hiding raid component */
5367 mpt2sas_config_get_volume_handle(ioc
, handle
,
5368 &sas_device
->volume_handle
);
5369 mpt2sas_config_get_volume_wwid(ioc
, sas_device
->volume_handle
,
5370 &sas_device
->volume_wwid
);
5371 set_bit(handle
, ioc
->pd_handles
);
5372 _scsih_reprobe_target(sas_device
->starget
, 1);
5376 * _scsih_sas_pd_delete - delete pd component
5377 * @ioc: per adapter object
5378 * @element: IR config element data
5384 _scsih_sas_pd_delete(struct MPT2SAS_ADAPTER
*ioc
,
5385 Mpi2EventIrConfigElement_t
*element
)
5387 struct _sas_device
*sas_device
;
5388 unsigned long flags
;
5389 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
5391 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5392 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
5393 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5396 _scsih_remove_device(ioc
, sas_device
);
5400 * _scsih_sas_pd_add - remove pd component
5401 * @ioc: per adapter object
5402 * @element: IR config element data
5408 _scsih_sas_pd_add(struct MPT2SAS_ADAPTER
*ioc
,
5409 Mpi2EventIrConfigElement_t
*element
)
5411 struct _sas_device
*sas_device
;
5412 unsigned long flags
;
5413 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
5414 Mpi2ConfigReply_t mpi_reply
;
5415 Mpi2SasDevicePage0_t sas_device_pg0
;
5420 set_bit(handle
, ioc
->pd_handles
);
5422 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5423 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
5424 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5428 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
5429 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
5430 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5431 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5435 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5436 MPI2_IOCSTATUS_MASK
;
5437 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5438 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5439 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5443 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
5444 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
5445 mpt2sas_transport_update_links(ioc
, sas_address
, handle
,
5446 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
5448 _scsih_add_device(ioc
, handle
, 0, 1);
5451 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5453 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
5454 * @ioc: per adapter object
5455 * @event_data: event data payload
5461 _scsih_sas_ir_config_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
5462 Mpi2EventDataIrConfigChangeList_t
*event_data
)
5464 Mpi2EventIrConfigElement_t
*element
;
5467 char *reason_str
= NULL
, *element_str
= NULL
;
5469 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
5471 printk(MPT2SAS_INFO_FMT
"raid config change: (%s), elements(%d)\n",
5472 ioc
->name
, (le32_to_cpu(event_data
->Flags
) &
5473 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ?
5474 "foreign" : "native", event_data
->NumElements
);
5475 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
5476 switch (element
->ReasonCode
) {
5477 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
5480 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
5481 reason_str
= "remove";
5483 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE
:
5484 reason_str
= "no change";
5486 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
5487 reason_str
= "hide";
5489 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
5490 reason_str
= "unhide";
5492 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
5493 reason_str
= "volume_created";
5495 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
5496 reason_str
= "volume_deleted";
5498 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
5499 reason_str
= "pd_created";
5501 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
5502 reason_str
= "pd_deleted";
5505 reason_str
= "unknown reason";
5508 element_type
= le16_to_cpu(element
->ElementFlags
) &
5509 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK
;
5510 switch (element_type
) {
5511 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT
:
5512 element_str
= "volume";
5514 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT
:
5515 element_str
= "phys disk";
5517 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT
:
5518 element_str
= "hot spare";
5521 element_str
= "unknown element";
5524 printk(KERN_INFO
"\t(%s:%s), vol handle(0x%04x), "
5525 "pd handle(0x%04x), pd num(0x%02x)\n", element_str
,
5526 reason_str
, le16_to_cpu(element
->VolDevHandle
),
5527 le16_to_cpu(element
->PhysDiskDevHandle
),
5528 element
->PhysDiskNum
);
5534 * _scsih_sas_ir_config_change_event - handle ir configuration change events
5535 * @ioc: per adapter object
5536 * @fw_event: The fw_event_work object
5542 _scsih_sas_ir_config_change_event(struct MPT2SAS_ADAPTER
*ioc
,
5543 struct fw_event_work
*fw_event
)
5545 Mpi2EventIrConfigElement_t
*element
;
5548 Mpi2EventDataIrConfigChangeList_t
*event_data
= fw_event
->event_data
;
5550 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5551 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5552 _scsih_sas_ir_config_change_event_debug(ioc
, event_data
);
5555 foreign_config
= (le32_to_cpu(event_data
->Flags
) &
5556 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ? 1 : 0;
5558 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
5559 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
5561 switch (element
->ReasonCode
) {
5562 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
5563 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
5564 if (!foreign_config
)
5565 _scsih_sas_volume_add(ioc
, element
);
5567 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
5568 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
5569 if (!foreign_config
)
5570 _scsih_sas_volume_delete(ioc
,
5571 le16_to_cpu(element
->VolDevHandle
));
5573 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
5574 _scsih_sas_pd_hide(ioc
, element
);
5576 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
5577 _scsih_sas_pd_expose(ioc
, element
);
5579 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
5580 _scsih_sas_pd_add(ioc
, element
);
5582 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
5583 _scsih_sas_pd_delete(ioc
, element
);
5590 * _scsih_sas_ir_volume_event - IR volume event
5591 * @ioc: per adapter object
5592 * @fw_event: The fw_event_work object
5598 _scsih_sas_ir_volume_event(struct MPT2SAS_ADAPTER
*ioc
,
5599 struct fw_event_work
*fw_event
)
5602 unsigned long flags
;
5603 struct _raid_device
*raid_device
;
5607 Mpi2EventDataIrVolume_t
*event_data
= fw_event
->event_data
;
5609 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED
)
5612 handle
= le16_to_cpu(event_data
->VolDevHandle
);
5613 state
= le32_to_cpu(event_data
->NewValue
);
5614 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: handle(0x%04x), "
5615 "old(0x%08x), new(0x%08x)\n", ioc
->name
, __func__
, handle
,
5616 le32_to_cpu(event_data
->PreviousValue
), state
));
5619 case MPI2_RAID_VOL_STATE_MISSING
:
5620 case MPI2_RAID_VOL_STATE_FAILED
:
5621 _scsih_sas_volume_delete(ioc
, handle
);
5624 case MPI2_RAID_VOL_STATE_ONLINE
:
5625 case MPI2_RAID_VOL_STATE_DEGRADED
:
5626 case MPI2_RAID_VOL_STATE_OPTIMAL
:
5628 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5629 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
5630 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5635 mpt2sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
5637 printk(MPT2SAS_ERR_FMT
5638 "failure at %s:%d/%s()!\n", ioc
->name
,
5639 __FILE__
, __LINE__
, __func__
);
5643 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
5645 printk(MPT2SAS_ERR_FMT
5646 "failure at %s:%d/%s()!\n", ioc
->name
,
5647 __FILE__
, __LINE__
, __func__
);
5651 raid_device
->id
= ioc
->sas_id
++;
5652 raid_device
->channel
= RAID_CHANNEL
;
5653 raid_device
->handle
= handle
;
5654 raid_device
->wwid
= wwid
;
5655 _scsih_raid_device_add(ioc
, raid_device
);
5656 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
5657 raid_device
->id
, 0);
5659 _scsih_raid_device_remove(ioc
, raid_device
);
5662 case MPI2_RAID_VOL_STATE_INITIALIZING
:
5669 * _scsih_sas_ir_physical_disk_event - PD event
5670 * @ioc: per adapter object
5671 * @fw_event: The fw_event_work object
5677 _scsih_sas_ir_physical_disk_event(struct MPT2SAS_ADAPTER
*ioc
,
5678 struct fw_event_work
*fw_event
)
5680 u16 handle
, parent_handle
;
5682 struct _sas_device
*sas_device
;
5683 unsigned long flags
;
5684 Mpi2ConfigReply_t mpi_reply
;
5685 Mpi2SasDevicePage0_t sas_device_pg0
;
5687 Mpi2EventDataIrPhysicalDisk_t
*event_data
= fw_event
->event_data
;
5690 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED
)
5693 handle
= le16_to_cpu(event_data
->PhysDiskDevHandle
);
5694 state
= le32_to_cpu(event_data
->NewValue
);
5696 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: handle(0x%04x), "
5697 "old(0x%08x), new(0x%08x)\n", ioc
->name
, __func__
, handle
,
5698 le32_to_cpu(event_data
->PreviousValue
), state
));
5701 case MPI2_RAID_PD_STATE_ONLINE
:
5702 case MPI2_RAID_PD_STATE_DEGRADED
:
5703 case MPI2_RAID_PD_STATE_REBUILDING
:
5704 case MPI2_RAID_PD_STATE_OPTIMAL
:
5705 case MPI2_RAID_PD_STATE_HOT_SPARE
:
5707 set_bit(handle
, ioc
->pd_handles
);
5709 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5710 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
5711 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5716 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
5717 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
5719 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5720 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5724 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5725 MPI2_IOCSTATUS_MASK
;
5726 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5727 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5728 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5732 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
5733 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
5734 mpt2sas_transport_update_links(ioc
, sas_address
, handle
,
5735 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
5737 _scsih_add_device(ioc
, handle
, 0, 1);
5741 case MPI2_RAID_PD_STATE_OFFLINE
:
5742 case MPI2_RAID_PD_STATE_NOT_CONFIGURED
:
5743 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE
:
5749 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5751 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
5752 * @ioc: per adapter object
5753 * @event_data: event data payload
5759 _scsih_sas_ir_operation_status_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
5760 Mpi2EventDataIrOperationStatus_t
*event_data
)
5762 char *reason_str
= NULL
;
5764 switch (event_data
->RAIDOperation
) {
5765 case MPI2_EVENT_IR_RAIDOP_RESYNC
:
5766 reason_str
= "resync";
5768 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION
:
5769 reason_str
= "online capacity expansion";
5771 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK
:
5772 reason_str
= "consistency check";
5774 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT
:
5775 reason_str
= "background init";
5777 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT
:
5778 reason_str
= "make data consistent";
5785 printk(MPT2SAS_INFO_FMT
"raid operational status: (%s)"
5786 "\thandle(0x%04x), percent complete(%d)\n",
5787 ioc
->name
, reason_str
,
5788 le16_to_cpu(event_data
->VolDevHandle
),
5789 event_data
->PercentComplete
);
5794 * _scsih_sas_ir_operation_status_event - handle RAID operation events
5795 * @ioc: per adapter object
5796 * @fw_event: The fw_event_work object
5802 _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER
*ioc
,
5803 struct fw_event_work
*fw_event
)
5805 Mpi2EventDataIrOperationStatus_t
*event_data
= fw_event
->event_data
;
5806 static struct _raid_device
*raid_device
;
5807 unsigned long flags
;
5810 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5811 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5812 _scsih_sas_ir_operation_status_event_debug(ioc
,
5816 /* code added for raid transport support */
5817 if (event_data
->RAIDOperation
== MPI2_EVENT_IR_RAIDOP_RESYNC
) {
5819 handle
= le16_to_cpu(event_data
->VolDevHandle
);
5821 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5822 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
5823 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5828 if (event_data
->RAIDOperation
== MPI2_EVENT_IR_RAIDOP_RESYNC
)
5829 raid_device
->percent_complete
=
5830 event_data
->PercentComplete
;
5835 * _scsih_prep_device_scan - initialize parameters prior to device scan
5836 * @ioc: per adapter object
5838 * Set the deleted flag prior to device scan. If the device is found during
5839 * the scan, then we clear the deleted flag.
5842 _scsih_prep_device_scan(struct MPT2SAS_ADAPTER
*ioc
)
5844 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
5845 struct scsi_device
*sdev
;
5847 shost_for_each_device(sdev
, ioc
->shost
) {
5848 sas_device_priv_data
= sdev
->hostdata
;
5849 if (sas_device_priv_data
&& sas_device_priv_data
->sas_target
)
5850 sas_device_priv_data
->sas_target
->deleted
= 1;
5855 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
5856 * @ioc: per adapter object
5857 * @sas_address: sas address
5858 * @slot: enclosure slot id
5859 * @handle: device handle
5861 * After host reset, find out whether devices are still responding.
5862 * Used in _scsi_remove_unresponsive_sas_devices.
5867 _scsih_mark_responding_sas_device(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
,
5868 u16 slot
, u16 handle
)
5870 struct MPT2SAS_TARGET
*sas_target_priv_data
;
5871 struct scsi_target
*starget
;
5872 struct _sas_device
*sas_device
;
5873 unsigned long flags
;
5875 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5876 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
) {
5877 if (sas_device
->sas_address
== sas_address
&&
5878 sas_device
->slot
== slot
&& sas_device
->starget
) {
5879 sas_device
->responding
= 1;
5880 starget
= sas_device
->starget
;
5881 if (starget
&& starget
->hostdata
) {
5882 sas_target_priv_data
= starget
->hostdata
;
5883 sas_target_priv_data
->tm_busy
= 0;
5884 sas_target_priv_data
->deleted
= 0;
5886 sas_target_priv_data
= NULL
;
5887 starget_printk(KERN_INFO
, sas_device
->starget
,
5888 "handle(0x%04x), sas_addr(0x%016llx), enclosure "
5889 "logical id(0x%016llx), slot(%d)\n", handle
,
5890 (unsigned long long)sas_device
->sas_address
,
5891 (unsigned long long)
5892 sas_device
->enclosure_logical_id
,
5894 if (sas_device
->handle
== handle
)
5896 printk(KERN_INFO
"\thandle changed from(0x%04x)!!!\n",
5897 sas_device
->handle
);
5898 sas_device
->handle
= handle
;
5899 if (sas_target_priv_data
)
5900 sas_target_priv_data
->handle
= handle
;
5905 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5909 * _scsih_search_responding_sas_devices -
5910 * @ioc: per adapter object
5912 * After host reset, find out whether devices are still responding.
5918 _scsih_search_responding_sas_devices(struct MPT2SAS_ADAPTER
*ioc
)
5920 Mpi2SasDevicePage0_t sas_device_pg0
;
5921 Mpi2ConfigReply_t mpi_reply
;
5928 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
, __func__
);
5930 if (list_empty(&ioc
->sas_device_list
))
5934 while (!(mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
5935 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
,
5937 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5938 MPI2_IOCSTATUS_MASK
;
5939 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
5941 handle
= le16_to_cpu(sas_device_pg0
.DevHandle
);
5942 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
5943 if (!(_scsih_is_end_device(device_info
)))
5945 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
5946 slot
= le16_to_cpu(sas_device_pg0
.Slot
);
5947 _scsih_mark_responding_sas_device(ioc
, sas_address
, slot
,
5953 * _scsih_mark_responding_raid_device - mark a raid_device as responding
5954 * @ioc: per adapter object
5955 * @wwid: world wide identifier for raid volume
5956 * @handle: device handle
5958 * After host reset, find out whether devices are still responding.
5959 * Used in _scsi_remove_unresponsive_raid_devices.
5964 _scsih_mark_responding_raid_device(struct MPT2SAS_ADAPTER
*ioc
, u64 wwid
,
5967 struct MPT2SAS_TARGET
*sas_target_priv_data
;
5968 struct scsi_target
*starget
;
5969 struct _raid_device
*raid_device
;
5970 unsigned long flags
;
5972 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5973 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
5974 if (raid_device
->wwid
== wwid
&& raid_device
->starget
) {
5975 starget
= raid_device
->starget
;
5976 if (starget
&& starget
->hostdata
) {
5977 sas_target_priv_data
= starget
->hostdata
;
5978 sas_target_priv_data
->deleted
= 0;
5980 sas_target_priv_data
= NULL
;
5981 raid_device
->responding
= 1;
5982 starget_printk(KERN_INFO
, raid_device
->starget
,
5983 "handle(0x%04x), wwid(0x%016llx)\n", handle
,
5984 (unsigned long long)raid_device
->wwid
);
5985 if (raid_device
->handle
== handle
)
5987 printk(KERN_INFO
"\thandle changed from(0x%04x)!!!\n",
5988 raid_device
->handle
);
5989 raid_device
->handle
= handle
;
5990 if (sas_target_priv_data
)
5991 sas_target_priv_data
->handle
= handle
;
5996 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6000 * _scsih_search_responding_raid_devices -
6001 * @ioc: per adapter object
6003 * After host reset, find out whether devices are still responding.
6009 _scsih_search_responding_raid_devices(struct MPT2SAS_ADAPTER
*ioc
)
6011 Mpi2RaidVolPage1_t volume_pg1
;
6012 Mpi2RaidVolPage0_t volume_pg0
;
6013 Mpi2RaidPhysDiskPage0_t pd_pg0
;
6014 Mpi2ConfigReply_t mpi_reply
;
6019 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
, __func__
);
6021 if (list_empty(&ioc
->raid_device_list
))
6025 while (!(mpt2sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
6026 &volume_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
6027 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6028 MPI2_IOCSTATUS_MASK
;
6029 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
6031 handle
= le16_to_cpu(volume_pg1
.DevHandle
);
6033 if (mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
,
6034 &volume_pg0
, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
6035 sizeof(Mpi2RaidVolPage0_t
)))
6038 if (volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_OPTIMAL
||
6039 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_ONLINE
||
6040 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_DEGRADED
)
6041 _scsih_mark_responding_raid_device(ioc
,
6042 le64_to_cpu(volume_pg1
.WWID
), handle
);
6045 /* refresh the pd_handles */
6046 phys_disk_num
= 0xFF;
6047 memset(ioc
->pd_handles
, 0, ioc
->pd_handles_sz
);
6048 while (!(mpt2sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
6049 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM
,
6051 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6052 MPI2_IOCSTATUS_MASK
;
6053 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
6055 phys_disk_num
= pd_pg0
.PhysDiskNum
;
6056 handle
= le16_to_cpu(pd_pg0
.DevHandle
);
6057 set_bit(handle
, ioc
->pd_handles
);
6062 * _scsih_mark_responding_expander - mark a expander as responding
6063 * @ioc: per adapter object
6064 * @sas_address: sas address
6067 * After host reset, find out whether devices are still responding.
6068 * Used in _scsi_remove_unresponsive_expanders.
6073 _scsih_mark_responding_expander(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
,
6076 struct _sas_node
*sas_expander
;
6077 unsigned long flags
;
6080 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
6081 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
6082 if (sas_expander
->sas_address
!= sas_address
)
6084 sas_expander
->responding
= 1;
6085 if (sas_expander
->handle
== handle
)
6087 printk(KERN_INFO
"\texpander(0x%016llx): handle changed"
6088 " from(0x%04x) to (0x%04x)!!!\n",
6089 (unsigned long long)sas_expander
->sas_address
,
6090 sas_expander
->handle
, handle
);
6091 sas_expander
->handle
= handle
;
6092 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++)
6093 sas_expander
->phy
[i
].handle
= handle
;
6097 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
6101 * _scsih_search_responding_expanders -
6102 * @ioc: per adapter object
6104 * After host reset, find out whether devices are still responding.
6110 _scsih_search_responding_expanders(struct MPT2SAS_ADAPTER
*ioc
)
6112 Mpi2ExpanderPage0_t expander_pg0
;
6113 Mpi2ConfigReply_t mpi_reply
;
6118 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
, __func__
);
6120 if (list_empty(&ioc
->sas_expander_list
))
6124 while (!(mpt2sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
6125 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL
, handle
))) {
6127 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6128 MPI2_IOCSTATUS_MASK
;
6129 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
6132 handle
= le16_to_cpu(expander_pg0
.DevHandle
);
6133 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
6134 printk(KERN_INFO
"\texpander present: handle(0x%04x), "
6135 "sas_addr(0x%016llx)\n", handle
,
6136 (unsigned long long)sas_address
);
6137 _scsih_mark_responding_expander(ioc
, sas_address
, handle
);
6143 * _scsih_remove_unresponding_sas_devices - removing unresponding devices
6144 * @ioc: per adapter object
6149 _scsih_remove_unresponding_sas_devices(struct MPT2SAS_ADAPTER
*ioc
)
6151 struct _sas_device
*sas_device
, *sas_device_next
;
6152 struct _sas_node
*sas_expander
;
6153 struct _raid_device
*raid_device
, *raid_device_next
;
6156 list_for_each_entry_safe(sas_device
, sas_device_next
,
6157 &ioc
->sas_device_list
, list
) {
6158 if (sas_device
->responding
) {
6159 sas_device
->responding
= 0;
6162 if (sas_device
->starget
)
6163 starget_printk(KERN_INFO
, sas_device
->starget
,
6164 "removing: handle(0x%04x), sas_addr(0x%016llx), "
6165 "enclosure logical id(0x%016llx), slot(%d)\n",
6167 (unsigned long long)sas_device
->sas_address
,
6168 (unsigned long long)
6169 sas_device
->enclosure_logical_id
,
6171 _scsih_remove_device(ioc
, sas_device
);
6174 list_for_each_entry_safe(raid_device
, raid_device_next
,
6175 &ioc
->raid_device_list
, list
) {
6176 if (raid_device
->responding
) {
6177 raid_device
->responding
= 0;
6180 if (raid_device
->starget
) {
6181 starget_printk(KERN_INFO
, raid_device
->starget
,
6182 "removing: handle(0x%04x), wwid(0x%016llx)\n",
6183 raid_device
->handle
,
6184 (unsigned long long)raid_device
->wwid
);
6185 scsi_remove_target(&raid_device
->starget
->dev
);
6187 _scsih_raid_device_remove(ioc
, raid_device
);
6190 retry_expander_search
:
6191 sas_expander
= NULL
;
6192 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
6193 if (sas_expander
->responding
) {
6194 sas_expander
->responding
= 0;
6197 mpt2sas_expander_remove(ioc
, sas_expander
->sas_address
);
6198 goto retry_expander_search
;
6203 * mpt2sas_scsih_reset_handler - reset callback handler (for scsih)
6204 * @ioc: per adapter object
6205 * @reset_phase: phase
6207 * The handler for doing any required cleanup or initialization.
6209 * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
6210 * MPT2_IOC_DONE_RESET
6215 mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER
*ioc
, int reset_phase
)
6217 switch (reset_phase
) {
6218 case MPT2_IOC_PRE_RESET
:
6219 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: "
6220 "MPT2_IOC_PRE_RESET\n", ioc
->name
, __func__
));
6222 case MPT2_IOC_AFTER_RESET
:
6223 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: "
6224 "MPT2_IOC_AFTER_RESET\n", ioc
->name
, __func__
));
6225 if (ioc
->scsih_cmds
.status
& MPT2_CMD_PENDING
) {
6226 ioc
->scsih_cmds
.status
|= MPT2_CMD_RESET
;
6227 mpt2sas_base_free_smid(ioc
, ioc
->scsih_cmds
.smid
);
6228 complete(&ioc
->scsih_cmds
.done
);
6230 if (ioc
->tm_cmds
.status
& MPT2_CMD_PENDING
) {
6231 ioc
->tm_cmds
.status
|= MPT2_CMD_RESET
;
6232 mpt2sas_base_free_smid(ioc
, ioc
->tm_cmds
.smid
);
6233 complete(&ioc
->tm_cmds
.done
);
6235 _scsih_fw_event_cleanup_queue(ioc
);
6236 _scsih_flush_running_cmds(ioc
);
6237 _scsih_queue_rescan(ioc
);
6239 case MPT2_IOC_DONE_RESET
:
6240 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: "
6241 "MPT2_IOC_DONE_RESET\n", ioc
->name
, __func__
));
6242 _scsih_sas_host_refresh(ioc
);
6243 _scsih_prep_device_scan(ioc
);
6244 _scsih_search_responding_sas_devices(ioc
);
6245 _scsih_search_responding_raid_devices(ioc
);
6246 _scsih_search_responding_expanders(ioc
);
6252 * _firmware_event_work - delayed task for processing firmware events
6253 * @ioc: per adapter object
6254 * @work: equal to the fw_event_work object
6260 _firmware_event_work(struct work_struct
*work
)
6262 struct fw_event_work
*fw_event
= container_of(work
,
6263 struct fw_event_work
, delayed_work
.work
);
6264 unsigned long flags
;
6265 struct MPT2SAS_ADAPTER
*ioc
= fw_event
->ioc
;
6267 /* the queue is being flushed so ignore this event */
6268 if (ioc
->remove_host
|| fw_event
->cancel_pending_work
||
6269 ioc
->pci_error_recovery
) {
6270 _scsih_fw_event_free(ioc
, fw_event
);
6274 if (fw_event
->event
== MPT2SAS_RESCAN_AFTER_HOST_RESET
) {
6275 _scsih_fw_event_free(ioc
, fw_event
);
6276 spin_lock_irqsave(&ioc
->ioc_reset_in_progress_lock
, flags
);
6277 if (ioc
->shost_recovery
) {
6278 init_completion(&ioc
->shost_recovery_done
);
6279 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
,
6281 wait_for_completion(&ioc
->shost_recovery_done
);
6283 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
,
6285 _scsih_remove_unresponding_sas_devices(ioc
);
6289 switch (fw_event
->event
) {
6290 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
6291 _scsih_sas_topology_change_event(ioc
, fw_event
);
6293 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
6294 _scsih_sas_device_status_change_event(ioc
,
6297 case MPI2_EVENT_SAS_DISCOVERY
:
6298 _scsih_sas_discovery_event(ioc
,
6301 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
6302 _scsih_sas_broadcast_primative_event(ioc
,
6305 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
6306 _scsih_sas_enclosure_dev_status_change_event(ioc
,
6309 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
6310 _scsih_sas_ir_config_change_event(ioc
, fw_event
);
6312 case MPI2_EVENT_IR_VOLUME
:
6313 _scsih_sas_ir_volume_event(ioc
, fw_event
);
6315 case MPI2_EVENT_IR_PHYSICAL_DISK
:
6316 _scsih_sas_ir_physical_disk_event(ioc
, fw_event
);
6318 case MPI2_EVENT_IR_OPERATION_STATUS
:
6319 _scsih_sas_ir_operation_status_event(ioc
, fw_event
);
6322 _scsih_fw_event_free(ioc
, fw_event
);
6326 * mpt2sas_scsih_event_callback - firmware event handler (called at ISR time)
6327 * @ioc: per adapter object
6328 * @msix_index: MSIX table index supplied by the OS
6329 * @reply: reply message frame(lower 32bit addr)
6330 * Context: interrupt.
6332 * This function merely adds a new work task into ioc->firmware_event_thread.
6333 * The tasks are worked from _firmware_event_work in user context.
6335 * Return 1 meaning mf should be freed from _base_interrupt
6336 * 0 means the mf is freed from this function.
6339 mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER
*ioc
, u8 msix_index
,
6342 struct fw_event_work
*fw_event
;
6343 Mpi2EventNotificationReply_t
*mpi_reply
;
6347 /* events turned off due to host reset or driver unloading */
6348 if (ioc
->remove_host
|| ioc
->pci_error_recovery
)
6351 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
6352 event
= le16_to_cpu(mpi_reply
->Event
);
6356 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
6358 Mpi2EventDataSasBroadcastPrimitive_t
*baen_data
=
6359 (Mpi2EventDataSasBroadcastPrimitive_t
*)
6360 mpi_reply
->EventData
;
6362 if (baen_data
->Primitive
!=
6363 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT
||
6364 ioc
->broadcast_aen_busy
)
6366 ioc
->broadcast_aen_busy
= 1;
6370 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
6371 _scsih_check_topo_delete_events(ioc
,
6372 (Mpi2EventDataSasTopologyChangeList_t
*)
6373 mpi_reply
->EventData
);
6375 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
6376 _scsih_check_ir_config_unhide_events(ioc
,
6377 (Mpi2EventDataIrConfigChangeList_t
*)
6378 mpi_reply
->EventData
);
6380 case MPI2_EVENT_IR_VOLUME
:
6381 _scsih_check_volume_delete_events(ioc
,
6382 (Mpi2EventDataIrVolume_t
*)
6383 mpi_reply
->EventData
);
6385 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
6386 case MPI2_EVENT_IR_OPERATION_STATUS
:
6387 case MPI2_EVENT_SAS_DISCOVERY
:
6388 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
6389 case MPI2_EVENT_IR_PHYSICAL_DISK
:
6392 default: /* ignore the rest */
6396 fw_event
= kzalloc(sizeof(struct fw_event_work
), GFP_ATOMIC
);
6398 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6399 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6402 sz
= le16_to_cpu(mpi_reply
->EventDataLength
) * 4;
6403 fw_event
->event_data
= kzalloc(sz
, GFP_ATOMIC
);
6404 if (!fw_event
->event_data
) {
6405 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6406 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6411 memcpy(fw_event
->event_data
, mpi_reply
->EventData
,
6413 fw_event
->ioc
= ioc
;
6414 fw_event
->VF_ID
= mpi_reply
->VF_ID
;
6415 fw_event
->VP_ID
= mpi_reply
->VP_ID
;
6416 fw_event
->event
= event
;
6417 _scsih_fw_event_add(ioc
, fw_event
);
6421 /* shost template */
6422 static struct scsi_host_template scsih_driver_template
= {
6423 .module
= THIS_MODULE
,
6424 .name
= "Fusion MPT SAS Host",
6425 .proc_name
= MPT2SAS_DRIVER_NAME
,
6426 .queuecommand
= _scsih_qcmd
,
6427 .target_alloc
= _scsih_target_alloc
,
6428 .slave_alloc
= _scsih_slave_alloc
,
6429 .slave_configure
= _scsih_slave_configure
,
6430 .target_destroy
= _scsih_target_destroy
,
6431 .slave_destroy
= _scsih_slave_destroy
,
6432 .change_queue_depth
= _scsih_change_queue_depth
,
6433 .change_queue_type
= _scsih_change_queue_type
,
6434 .eh_abort_handler
= _scsih_abort
,
6435 .eh_device_reset_handler
= _scsih_dev_reset
,
6436 .eh_target_reset_handler
= _scsih_target_reset
,
6437 .eh_host_reset_handler
= _scsih_host_reset
,
6438 .bios_param
= _scsih_bios_param
,
6441 .sg_tablesize
= MPT2SAS_SG_DEPTH
,
6442 .max_sectors
= 8192,
6444 .use_clustering
= ENABLE_CLUSTERING
,
6445 .shost_attrs
= mpt2sas_host_attrs
,
6446 .sdev_attrs
= mpt2sas_dev_attrs
,
6450 * _scsih_expander_node_remove - removing expander device from list.
6451 * @ioc: per adapter object
6452 * @sas_expander: the sas_device object
6453 * Context: Calling function should acquire ioc->sas_node_lock.
6455 * Removing object and freeing associated memory from the
6456 * ioc->sas_expander_list.
6461 _scsih_expander_node_remove(struct MPT2SAS_ADAPTER
*ioc
,
6462 struct _sas_node
*sas_expander
)
6464 struct _sas_port
*mpt2sas_port
, *next
;
6466 /* remove sibling ports attached to this expander */
6467 list_for_each_entry_safe(mpt2sas_port
, next
,
6468 &sas_expander
->sas_port_list
, port_list
) {
6469 if (ioc
->shost_recovery
)
6471 if (mpt2sas_port
->remote_identify
.device_type
==
6473 mpt2sas_device_remove(ioc
,
6474 mpt2sas_port
->remote_identify
.sas_address
);
6475 else if (mpt2sas_port
->remote_identify
.device_type
==
6476 SAS_EDGE_EXPANDER_DEVICE
||
6477 mpt2sas_port
->remote_identify
.device_type
==
6478 SAS_FANOUT_EXPANDER_DEVICE
)
6479 mpt2sas_expander_remove(ioc
,
6480 mpt2sas_port
->remote_identify
.sas_address
);
6483 mpt2sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
6484 sas_expander
->sas_address_parent
);
6486 printk(MPT2SAS_INFO_FMT
"expander_remove: handle"
6487 "(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
6488 sas_expander
->handle
, (unsigned long long)
6489 sas_expander
->sas_address
);
6491 kfree(sas_expander
->phy
);
6492 kfree(sas_expander
);
6496 * _scsih_ir_shutdown - IR shutdown notification
6497 * @ioc: per adapter object
6499 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
6500 * the host system is shutting down.
6505 _scsih_ir_shutdown(struct MPT2SAS_ADAPTER
*ioc
)
6507 Mpi2RaidActionRequest_t
*mpi_request
;
6508 Mpi2RaidActionReply_t
*mpi_reply
;
6511 /* is IR firmware build loaded ? */
6512 if (!ioc
->ir_firmware
)
6515 /* are there any volumes ? */
6516 if (list_empty(&ioc
->raid_device_list
))
6519 mutex_lock(&ioc
->scsih_cmds
.mutex
);
6521 if (ioc
->scsih_cmds
.status
!= MPT2_CMD_NOT_USED
) {
6522 printk(MPT2SAS_ERR_FMT
"%s: scsih_cmd in use\n",
6523 ioc
->name
, __func__
);
6526 ioc
->scsih_cmds
.status
= MPT2_CMD_PENDING
;
6528 smid
= mpt2sas_base_get_smid(ioc
, ioc
->scsih_cb_idx
);
6530 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
6531 ioc
->name
, __func__
);
6532 ioc
->scsih_cmds
.status
= MPT2_CMD_NOT_USED
;
6536 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
6537 ioc
->scsih_cmds
.smid
= smid
;
6538 memset(mpi_request
, 0, sizeof(Mpi2RaidActionRequest_t
));
6540 mpi_request
->Function
= MPI2_FUNCTION_RAID_ACTION
;
6541 mpi_request
->Action
= MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED
;
6543 printk(MPT2SAS_INFO_FMT
"IR shutdown (sending)\n", ioc
->name
);
6544 init_completion(&ioc
->scsih_cmds
.done
);
6545 mpt2sas_base_put_smid_default(ioc
, smid
);
6546 wait_for_completion_timeout(&ioc
->scsih_cmds
.done
, 10*HZ
);
6548 if (!(ioc
->scsih_cmds
.status
& MPT2_CMD_COMPLETE
)) {
6549 printk(MPT2SAS_ERR_FMT
"%s: timeout\n",
6550 ioc
->name
, __func__
);
6554 if (ioc
->scsih_cmds
.status
& MPT2_CMD_REPLY_VALID
) {
6555 mpi_reply
= ioc
->scsih_cmds
.reply
;
6557 printk(MPT2SAS_INFO_FMT
"IR shutdown (complete): "
6558 "ioc_status(0x%04x), loginfo(0x%08x)\n",
6559 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
6560 le32_to_cpu(mpi_reply
->IOCLogInfo
));
6564 ioc
->scsih_cmds
.status
= MPT2_CMD_NOT_USED
;
6565 mutex_unlock(&ioc
->scsih_cmds
.mutex
);
6569 * _scsih_shutdown - routine call during system shutdown
6570 * @pdev: PCI device struct
6575 _scsih_shutdown(struct pci_dev
*pdev
)
6577 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6578 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
6579 struct workqueue_struct
*wq
;
6580 unsigned long flags
;
6582 ioc
->remove_host
= 1;
6583 _scsih_fw_event_cleanup_queue(ioc
);
6585 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
6586 wq
= ioc
->firmware_event_thread
;
6587 ioc
->firmware_event_thread
= NULL
;
6588 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
6590 destroy_workqueue(wq
);
6592 _scsih_ir_shutdown(ioc
);
6593 mpt2sas_base_detach(ioc
);
6597 * _scsih_remove - detach and remove add host
6598 * @pdev: PCI device struct
6600 * Routine called when unloading the driver.
6603 static void __devexit
6604 _scsih_remove(struct pci_dev
*pdev
)
6606 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6607 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
6608 struct _sas_port
*mpt2sas_port
, *next_port
;
6609 struct _raid_device
*raid_device
, *next
;
6610 struct MPT2SAS_TARGET
*sas_target_priv_data
;
6611 struct workqueue_struct
*wq
;
6612 unsigned long flags
;
6614 ioc
->remove_host
= 1;
6615 _scsih_fw_event_cleanup_queue(ioc
);
6617 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
6618 wq
= ioc
->firmware_event_thread
;
6619 ioc
->firmware_event_thread
= NULL
;
6620 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
6622 destroy_workqueue(wq
);
6624 /* release all the volumes */
6625 list_for_each_entry_safe(raid_device
, next
, &ioc
->raid_device_list
,
6627 if (raid_device
->starget
) {
6628 sas_target_priv_data
=
6629 raid_device
->starget
->hostdata
;
6630 sas_target_priv_data
->deleted
= 1;
6631 scsi_remove_target(&raid_device
->starget
->dev
);
6633 printk(MPT2SAS_INFO_FMT
"removing handle(0x%04x), wwid"
6634 "(0x%016llx)\n", ioc
->name
, raid_device
->handle
,
6635 (unsigned long long) raid_device
->wwid
);
6636 _scsih_raid_device_remove(ioc
, raid_device
);
6639 /* free ports attached to the sas_host */
6640 list_for_each_entry_safe(mpt2sas_port
, next_port
,
6641 &ioc
->sas_hba
.sas_port_list
, port_list
) {
6642 if (mpt2sas_port
->remote_identify
.device_type
==
6644 mpt2sas_device_remove(ioc
,
6645 mpt2sas_port
->remote_identify
.sas_address
);
6646 else if (mpt2sas_port
->remote_identify
.device_type
==
6647 SAS_EDGE_EXPANDER_DEVICE
||
6648 mpt2sas_port
->remote_identify
.device_type
==
6649 SAS_FANOUT_EXPANDER_DEVICE
)
6650 mpt2sas_expander_remove(ioc
,
6651 mpt2sas_port
->remote_identify
.sas_address
);
6654 /* free phys attached to the sas_host */
6655 if (ioc
->sas_hba
.num_phys
) {
6656 kfree(ioc
->sas_hba
.phy
);
6657 ioc
->sas_hba
.phy
= NULL
;
6658 ioc
->sas_hba
.num_phys
= 0;
6661 sas_remove_host(shost
);
6662 _scsih_shutdown(pdev
);
6663 list_del(&ioc
->list
);
6664 scsi_remove_host(shost
);
6665 scsi_host_put(shost
);
6669 * _scsih_probe_boot_devices - reports 1st device
6670 * @ioc: per adapter object
6672 * If specified in bios page 2, this routine reports the 1st
6673 * device scsi-ml or sas transport for persistent boot device
6674 * purposes. Please refer to function _scsih_determine_boot_device()
6677 _scsih_probe_boot_devices(struct MPT2SAS_ADAPTER
*ioc
)
6681 struct _sas_device
*sas_device
;
6682 struct _raid_device
*raid_device
;
6684 u64 sas_address_parent
;
6686 unsigned long flags
;
6690 if (ioc
->req_boot_device
.device
) {
6691 device
= ioc
->req_boot_device
.device
;
6692 is_raid
= ioc
->req_boot_device
.is_raid
;
6693 } else if (ioc
->req_alt_boot_device
.device
) {
6694 device
= ioc
->req_alt_boot_device
.device
;
6695 is_raid
= ioc
->req_alt_boot_device
.is_raid
;
6696 } else if (ioc
->current_boot_device
.device
) {
6697 device
= ioc
->current_boot_device
.device
;
6698 is_raid
= ioc
->current_boot_device
.is_raid
;
6705 raid_device
= device
;
6706 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
6707 raid_device
->id
, 0);
6709 _scsih_raid_device_remove(ioc
, raid_device
);
6711 sas_device
= device
;
6712 handle
= sas_device
->handle
;
6713 sas_address_parent
= sas_device
->sas_address_parent
;
6714 sas_address
= sas_device
->sas_address
;
6715 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6716 list_move_tail(&sas_device
->list
, &ioc
->sas_device_list
);
6717 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6718 if (!mpt2sas_transport_port_add(ioc
, sas_device
->handle
,
6719 sas_device
->sas_address_parent
)) {
6720 _scsih_sas_device_remove(ioc
, sas_device
);
6721 } else if (!sas_device
->starget
) {
6722 mpt2sas_transport_port_remove(ioc
, sas_address
,
6723 sas_address_parent
);
6724 _scsih_sas_device_remove(ioc
, sas_device
);
6730 * _scsih_probe_raid - reporting raid volumes to scsi-ml
6731 * @ioc: per adapter object
6733 * Called during initial loading of the driver.
6736 _scsih_probe_raid(struct MPT2SAS_ADAPTER
*ioc
)
6738 struct _raid_device
*raid_device
, *raid_next
;
6741 list_for_each_entry_safe(raid_device
, raid_next
,
6742 &ioc
->raid_device_list
, list
) {
6743 if (raid_device
->starget
)
6745 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
6746 raid_device
->id
, 0);
6748 _scsih_raid_device_remove(ioc
, raid_device
);
6753 * _scsih_probe_sas - reporting sas devices to sas transport
6754 * @ioc: per adapter object
6756 * Called during initial loading of the driver.
6759 _scsih_probe_sas(struct MPT2SAS_ADAPTER
*ioc
)
6761 struct _sas_device
*sas_device
, *next
;
6762 unsigned long flags
;
6764 /* SAS Device List */
6765 list_for_each_entry_safe(sas_device
, next
, &ioc
->sas_device_init_list
,
6767 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6768 list_move_tail(&sas_device
->list
, &ioc
->sas_device_list
);
6769 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6771 if (!mpt2sas_transport_port_add(ioc
, sas_device
->handle
,
6772 sas_device
->sas_address_parent
)) {
6773 _scsih_sas_device_remove(ioc
, sas_device
);
6774 } else if (!sas_device
->starget
) {
6775 mpt2sas_transport_port_remove(ioc
,
6776 sas_device
->sas_address
,
6777 sas_device
->sas_address_parent
);
6778 _scsih_sas_device_remove(ioc
, sas_device
);
6784 * _scsih_probe_devices - probing for devices
6785 * @ioc: per adapter object
6787 * Called during initial loading of the driver.
6790 _scsih_probe_devices(struct MPT2SAS_ADAPTER
*ioc
)
6792 u16 volume_mapping_flags
=
6793 le16_to_cpu(ioc
->ioc_pg8
.IRVolumeMappingFlags
) &
6794 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE
;
6796 if (!(ioc
->facts
.ProtocolFlags
& MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR
))
6797 return; /* return when IOC doesn't support initiator mode */
6799 _scsih_probe_boot_devices(ioc
);
6801 if (ioc
->ir_firmware
) {
6802 if ((volume_mapping_flags
&
6803 MPI2_IOCPAGE8_IRFLAGS_HIGH_VOLUME_MAPPING
)) {
6804 _scsih_probe_sas(ioc
);
6805 _scsih_probe_raid(ioc
);
6807 _scsih_probe_raid(ioc
);
6808 _scsih_probe_sas(ioc
);
6811 _scsih_probe_sas(ioc
);
6815 * _scsih_probe - attach and add scsi host
6816 * @pdev: PCI device struct
6817 * @id: pci device id
6819 * Returns 0 success, anything else error.
6822 _scsih_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
6824 struct MPT2SAS_ADAPTER
*ioc
;
6825 struct Scsi_Host
*shost
;
6827 shost
= scsi_host_alloc(&scsih_driver_template
,
6828 sizeof(struct MPT2SAS_ADAPTER
));
6832 /* init local params */
6833 ioc
= shost_priv(shost
);
6834 memset(ioc
, 0, sizeof(struct MPT2SAS_ADAPTER
));
6835 INIT_LIST_HEAD(&ioc
->list
);
6836 list_add_tail(&ioc
->list
, &mpt2sas_ioc_list
);
6838 ioc
->id
= mpt_ids
++;
6839 sprintf(ioc
->name
, "%s%d", MPT2SAS_DRIVER_NAME
, ioc
->id
);
6841 ioc
->scsi_io_cb_idx
= scsi_io_cb_idx
;
6842 ioc
->tm_cb_idx
= tm_cb_idx
;
6843 ioc
->ctl_cb_idx
= ctl_cb_idx
;
6844 ioc
->base_cb_idx
= base_cb_idx
;
6845 ioc
->transport_cb_idx
= transport_cb_idx
;
6846 ioc
->scsih_cb_idx
= scsih_cb_idx
;
6847 ioc
->config_cb_idx
= config_cb_idx
;
6848 ioc
->tm_tr_cb_idx
= tm_tr_cb_idx
;
6849 ioc
->tm_tr_volume_cb_idx
= tm_tr_volume_cb_idx
;
6850 ioc
->tm_sas_control_cb_idx
= tm_sas_control_cb_idx
;
6851 ioc
->logging_level
= logging_level
;
6852 /* misc semaphores and spin locks */
6853 mutex_init(&ioc
->reset_in_progress_mutex
);
6854 spin_lock_init(&ioc
->ioc_reset_in_progress_lock
);
6855 spin_lock_init(&ioc
->scsi_lookup_lock
);
6856 spin_lock_init(&ioc
->sas_device_lock
);
6857 spin_lock_init(&ioc
->sas_node_lock
);
6858 spin_lock_init(&ioc
->fw_event_lock
);
6859 spin_lock_init(&ioc
->raid_device_lock
);
6861 INIT_LIST_HEAD(&ioc
->sas_device_list
);
6862 INIT_LIST_HEAD(&ioc
->sas_device_init_list
);
6863 INIT_LIST_HEAD(&ioc
->sas_expander_list
);
6864 INIT_LIST_HEAD(&ioc
->fw_event_list
);
6865 INIT_LIST_HEAD(&ioc
->raid_device_list
);
6866 INIT_LIST_HEAD(&ioc
->sas_hba
.sas_port_list
);
6867 INIT_LIST_HEAD(&ioc
->delayed_tr_list
);
6868 INIT_LIST_HEAD(&ioc
->delayed_tr_volume_list
);
6870 /* init shost parameters */
6871 shost
->max_cmd_len
= 32;
6872 shost
->max_lun
= max_lun
;
6873 shost
->transportt
= mpt2sas_transport_template
;
6874 shost
->unique_id
= ioc
->id
;
6876 if ((scsi_add_host(shost
, &pdev
->dev
))) {
6877 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6878 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6879 list_del(&ioc
->list
);
6880 goto out_add_shost_fail
;
6883 scsi_host_set_prot(shost
, SHOST_DIF_TYPE1_PROTECTION
6884 | SHOST_DIF_TYPE2_PROTECTION
| SHOST_DIF_TYPE3_PROTECTION
);
6885 scsi_host_set_guard(shost
, SHOST_DIX_GUARD_CRC
);
6888 snprintf(ioc
->firmware_event_name
, sizeof(ioc
->firmware_event_name
),
6889 "fw_event%d", ioc
->id
);
6890 ioc
->firmware_event_thread
= create_singlethread_workqueue(
6891 ioc
->firmware_event_name
);
6892 if (!ioc
->firmware_event_thread
) {
6893 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6894 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6895 goto out_thread_fail
;
6898 ioc
->wait_for_port_enable_to_complete
= 1;
6899 if ((mpt2sas_base_attach(ioc
))) {
6900 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6901 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6902 goto out_attach_fail
;
6905 ioc
->wait_for_port_enable_to_complete
= 0;
6906 _scsih_probe_devices(ioc
);
6910 destroy_workqueue(ioc
->firmware_event_thread
);
6912 list_del(&ioc
->list
);
6913 scsi_remove_host(shost
);
6920 * _scsih_suspend - power management suspend main entry point
6921 * @pdev: PCI device struct
6922 * @state: PM state change to (usually PCI_D3)
6924 * Returns 0 success, anything else error.
6927 _scsih_suspend(struct pci_dev
*pdev
, pm_message_t state
)
6929 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6930 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
6933 mpt2sas_base_stop_watchdog(ioc
);
6934 flush_scheduled_work();
6935 scsi_block_requests(shost
);
6936 device_state
= pci_choose_state(pdev
, state
);
6937 printk(MPT2SAS_INFO_FMT
"pdev=0x%p, slot=%s, entering "
6938 "operating state [D%d]\n", ioc
->name
, pdev
,
6939 pci_name(pdev
), device_state
);
6941 mpt2sas_base_free_resources(ioc
);
6942 pci_save_state(pdev
);
6943 pci_disable_device(pdev
);
6944 pci_set_power_state(pdev
, device_state
);
6949 * _scsih_resume - power management resume main entry point
6950 * @pdev: PCI device struct
6952 * Returns 0 success, anything else error.
6955 _scsih_resume(struct pci_dev
*pdev
)
6957 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6958 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
6959 u32 device_state
= pdev
->current_state
;
6962 printk(MPT2SAS_INFO_FMT
"pdev=0x%p, slot=%s, previous "
6963 "operating state [D%d]\n", ioc
->name
, pdev
,
6964 pci_name(pdev
), device_state
);
6966 pci_set_power_state(pdev
, PCI_D0
);
6967 pci_enable_wake(pdev
, PCI_D0
, 0);
6968 pci_restore_state(pdev
);
6970 r
= mpt2sas_base_map_resources(ioc
);
6974 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
, SOFT_RESET
);
6975 scsi_unblock_requests(shost
);
6976 mpt2sas_base_start_watchdog(ioc
);
6979 #endif /* CONFIG_PM */
6982 * _scsih_pci_error_detected - Called when a PCI error is detected.
6983 * @pdev: PCI device struct
6984 * @state: PCI channel state
6986 * Description: Called when a PCI error is detected.
6989 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
6991 static pci_ers_result_t
6992 _scsih_pci_error_detected(struct pci_dev
*pdev
, pci_channel_state_t state
)
6994 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6995 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
6997 printk(MPT2SAS_INFO_FMT
"PCI error: detected callback, state(%d)!!\n",
7001 case pci_channel_io_normal
:
7002 return PCI_ERS_RESULT_CAN_RECOVER
;
7003 case pci_channel_io_frozen
:
7004 /* Fatal error, prepare for slot reset */
7005 ioc
->pci_error_recovery
= 1;
7006 scsi_block_requests(ioc
->shost
);
7007 mpt2sas_base_stop_watchdog(ioc
);
7008 mpt2sas_base_free_resources(ioc
);
7009 return PCI_ERS_RESULT_NEED_RESET
;
7010 case pci_channel_io_perm_failure
:
7011 /* Permanent error, prepare for device removal */
7012 ioc
->pci_error_recovery
= 1;
7013 mpt2sas_base_stop_watchdog(ioc
);
7014 _scsih_flush_running_cmds(ioc
);
7015 return PCI_ERS_RESULT_DISCONNECT
;
7017 return PCI_ERS_RESULT_NEED_RESET
;
7021 * _scsih_pci_slot_reset - Called when PCI slot has been reset.
7022 * @pdev: PCI device struct
7024 * Description: This routine is called by the pci error recovery
7025 * code after the PCI slot has been reset, just before we
7026 * should resume normal operations.
7028 static pci_ers_result_t
7029 _scsih_pci_slot_reset(struct pci_dev
*pdev
)
7031 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
7032 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
7035 printk(MPT2SAS_INFO_FMT
"PCI error: slot reset callback!!\n",
7038 ioc
->pci_error_recovery
= 0;
7040 pci_restore_state(pdev
);
7041 rc
= mpt2sas_base_map_resources(ioc
);
7043 return PCI_ERS_RESULT_DISCONNECT
;
7046 rc
= mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
7049 printk(MPT2SAS_WARN_FMT
"hard reset: %s\n", ioc
->name
,
7050 (rc
== 0) ? "success" : "failed");
7053 return PCI_ERS_RESULT_RECOVERED
;
7055 return PCI_ERS_RESULT_DISCONNECT
;
7059 * _scsih_pci_resume() - resume normal ops after PCI reset
7060 * @pdev: pointer to PCI device
7062 * Called when the error recovery driver tells us that its
7063 * OK to resume normal operation. Use completion to allow
7064 * halted scsi ops to resume.
7067 _scsih_pci_resume(struct pci_dev
*pdev
)
7069 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
7070 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
7072 printk(MPT2SAS_INFO_FMT
"PCI error: resume callback!!\n", ioc
->name
);
7074 pci_cleanup_aer_uncorrect_error_status(pdev
);
7075 mpt2sas_base_start_watchdog(ioc
);
7076 scsi_unblock_requests(ioc
->shost
);
7080 * _scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
7081 * @pdev: pointer to PCI device
7083 static pci_ers_result_t
7084 _scsih_pci_mmio_enabled(struct pci_dev
*pdev
)
7086 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
7087 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
7089 printk(MPT2SAS_INFO_FMT
"PCI error: mmio enabled callback!!\n",
7092 /* TODO - dump whatever for debugging purposes */
7094 /* Request a slot reset. */
7095 return PCI_ERS_RESULT_NEED_RESET
;
7098 static struct pci_error_handlers _scsih_err_handler
= {
7099 .error_detected
= _scsih_pci_error_detected
,
7100 .mmio_enabled
= _scsih_pci_mmio_enabled
,
7101 .slot_reset
= _scsih_pci_slot_reset
,
7102 .resume
= _scsih_pci_resume
,
7105 static struct pci_driver scsih_driver
= {
7106 .name
= MPT2SAS_DRIVER_NAME
,
7107 .id_table
= scsih_pci_table
,
7108 .probe
= _scsih_probe
,
7109 .remove
= __devexit_p(_scsih_remove
),
7110 .shutdown
= _scsih_shutdown
,
7111 .err_handler
= &_scsih_err_handler
,
7113 .suspend
= _scsih_suspend
,
7114 .resume
= _scsih_resume
,
7118 /* raid transport support */
7119 static struct raid_function_template mpt2sas_raid_functions
= {
7120 .cookie
= &scsih_driver_template
,
7121 .is_raid
= _scsih_is_raid
,
7122 .get_resync
= _scsih_get_resync
,
7123 .get_state
= _scsih_get_state
,
7127 * _scsih_init - main entry point for this driver.
7129 * Returns 0 success, anything else error.
7137 printk(KERN_INFO
"%s version %s loaded\n", MPT2SAS_DRIVER_NAME
,
7138 MPT2SAS_DRIVER_VERSION
);
7140 mpt2sas_transport_template
=
7141 sas_attach_transport(&mpt2sas_transport_functions
);
7142 if (!mpt2sas_transport_template
)
7144 /* raid transport support */
7145 mpt2sas_raid_template
= raid_class_attach(&mpt2sas_raid_functions
);
7146 if (!mpt2sas_raid_template
) {
7147 sas_release_transport(mpt2sas_transport_template
);
7151 mpt2sas_base_initialize_callback_handler();
7153 /* queuecommand callback hander */
7154 scsi_io_cb_idx
= mpt2sas_base_register_callback_handler(_scsih_io_done
);
7156 /* task management callback handler */
7157 tm_cb_idx
= mpt2sas_base_register_callback_handler(_scsih_tm_done
);
7159 /* base internal commands callback handler */
7160 base_cb_idx
= mpt2sas_base_register_callback_handler(mpt2sas_base_done
);
7162 /* transport internal commands callback handler */
7163 transport_cb_idx
= mpt2sas_base_register_callback_handler(
7164 mpt2sas_transport_done
);
7166 /* scsih internal commands callback handler */
7167 scsih_cb_idx
= mpt2sas_base_register_callback_handler(_scsih_done
);
7169 /* configuration page API internal commands callback handler */
7170 config_cb_idx
= mpt2sas_base_register_callback_handler(
7171 mpt2sas_config_done
);
7173 /* ctl module callback handler */
7174 ctl_cb_idx
= mpt2sas_base_register_callback_handler(mpt2sas_ctl_done
);
7176 tm_tr_cb_idx
= mpt2sas_base_register_callback_handler(
7177 _scsih_tm_tr_complete
);
7179 tm_tr_volume_cb_idx
= mpt2sas_base_register_callback_handler(
7180 _scsih_tm_volume_tr_complete
);
7182 tm_sas_control_cb_idx
= mpt2sas_base_register_callback_handler(
7183 _scsih_sas_control_complete
);
7187 error
= pci_register_driver(&scsih_driver
);
7189 /* raid transport support */
7190 raid_class_release(mpt2sas_raid_template
);
7191 sas_release_transport(mpt2sas_transport_template
);
7198 * _scsih_exit - exit point for this driver (when it is a module).
7200 * Returns 0 success, anything else error.
7205 printk(KERN_INFO
"mpt2sas version %s unloading\n",
7206 MPT2SAS_DRIVER_VERSION
);
7208 pci_unregister_driver(&scsih_driver
);
7212 mpt2sas_base_release_callback_handler(scsi_io_cb_idx
);
7213 mpt2sas_base_release_callback_handler(tm_cb_idx
);
7214 mpt2sas_base_release_callback_handler(base_cb_idx
);
7215 mpt2sas_base_release_callback_handler(transport_cb_idx
);
7216 mpt2sas_base_release_callback_handler(scsih_cb_idx
);
7217 mpt2sas_base_release_callback_handler(config_cb_idx
);
7218 mpt2sas_base_release_callback_handler(ctl_cb_idx
);
7220 mpt2sas_base_release_callback_handler(tm_tr_cb_idx
);
7221 mpt2sas_base_release_callback_handler(tm_tr_volume_cb_idx
);
7222 mpt2sas_base_release_callback_handler(tm_sas_control_cb_idx
);
7224 /* raid transport support */
7225 raid_class_release(mpt2sas_raid_template
);
7226 sas_release_transport(mpt2sas_transport_template
);
7230 module_init(_scsih_init
);
7231 module_exit(_scsih_exit
);