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 * _scsih_scsi_lookup_get - 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_get_clear - returns scmd entry
836 * @ioc: per adapter object
837 * @smid: system request message index
839 * Returns the smid stored scmd pointer.
840 * Then will derefrence the stored scmd pointer.
842 static inline struct scsi_cmnd
*
843 _scsih_scsi_lookup_get_clear(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
846 struct scsi_cmnd
*scmd
;
848 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
849 scmd
= ioc
->scsi_lookup
[smid
- 1].scmd
;
850 ioc
->scsi_lookup
[smid
- 1].scmd
= NULL
;
851 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
857 * _scsih_scsi_lookup_find_by_scmd - scmd lookup
858 * @ioc: per adapter object
859 * @smid: system request message index
860 * @scmd: pointer to scsi command object
861 * Context: This function will acquire ioc->scsi_lookup_lock.
863 * This will search for a scmd pointer in the scsi_lookup array,
864 * returning the revelent smid. A returned value of zero means invalid.
867 _scsih_scsi_lookup_find_by_scmd(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_cmnd
874 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
876 for (i
= 0; i
< ioc
->scsiio_depth
; i
++) {
877 if (ioc
->scsi_lookup
[i
].scmd
== scmd
) {
878 smid
= ioc
->scsi_lookup
[i
].smid
;
883 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
888 * _scsih_scsi_lookup_find_by_target - search for matching channel:id
889 * @ioc: per adapter object
892 * Context: This function will acquire ioc->scsi_lookup_lock.
894 * This will search for a matching channel:id in the scsi_lookup array,
895 * returning 1 if found.
898 _scsih_scsi_lookup_find_by_target(struct MPT2SAS_ADAPTER
*ioc
, int id
,
905 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
907 for (i
= 0 ; i
< ioc
->scsiio_depth
; i
++) {
908 if (ioc
->scsi_lookup
[i
].scmd
&&
909 (ioc
->scsi_lookup
[i
].scmd
->device
->id
== id
&&
910 ioc
->scsi_lookup
[i
].scmd
->device
->channel
== channel
)) {
916 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
921 * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun
922 * @ioc: per adapter object
926 * Context: This function will acquire ioc->scsi_lookup_lock.
928 * This will search for a matching channel:id:lun in the scsi_lookup array,
929 * returning 1 if found.
932 _scsih_scsi_lookup_find_by_lun(struct MPT2SAS_ADAPTER
*ioc
, int id
,
933 unsigned int lun
, int channel
)
939 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
941 for (i
= 0 ; i
< ioc
->scsiio_depth
; i
++) {
942 if (ioc
->scsi_lookup
[i
].scmd
&&
943 (ioc
->scsi_lookup
[i
].scmd
->device
->id
== id
&&
944 ioc
->scsi_lookup
[i
].scmd
->device
->channel
== channel
&&
945 ioc
->scsi_lookup
[i
].scmd
->device
->lun
== lun
)) {
951 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
956 * _scsih_get_chain_buffer_dma - obtain block of chains (dma address)
957 * @ioc: per adapter object
958 * @smid: system request message index
960 * Returns phys pointer to chain buffer.
963 _scsih_get_chain_buffer_dma(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
965 return ioc
->chain_dma
+ ((smid
- 1) * (ioc
->request_sz
*
966 ioc
->chains_needed_per_io
));
970 * _scsih_get_chain_buffer - obtain block of chains assigned to a mf request
971 * @ioc: per adapter object
972 * @smid: system request message index
974 * Returns virt pointer to chain buffer.
977 _scsih_get_chain_buffer(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
979 return (void *)(ioc
->chain
+ ((smid
- 1) * (ioc
->request_sz
*
980 ioc
->chains_needed_per_io
)));
984 * _scsih_build_scatter_gather - main sg creation routine
985 * @ioc: per adapter object
986 * @scmd: scsi command
987 * @smid: system request message index
990 * The main routine that builds scatter gather table from a given
991 * scsi request sent via the .queuecommand main handler.
993 * Returns 0 success, anything else error
996 _scsih_build_scatter_gather(struct MPT2SAS_ADAPTER
*ioc
,
997 struct scsi_cmnd
*scmd
, u16 smid
)
999 Mpi2SCSIIORequest_t
*mpi_request
;
1000 dma_addr_t chain_dma
;
1001 struct scatterlist
*sg_scmd
;
1002 void *sg_local
, *chain
;
1007 u32 sges_in_segment
;
1009 u32 sgl_flags_last_element
;
1010 u32 sgl_flags_end_buffer
;
1012 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
1014 /* init scatter gather flags */
1015 sgl_flags
= MPI2_SGE_FLAGS_SIMPLE_ELEMENT
;
1016 if (scmd
->sc_data_direction
== DMA_TO_DEVICE
)
1017 sgl_flags
|= MPI2_SGE_FLAGS_HOST_TO_IOC
;
1018 sgl_flags_last_element
= (sgl_flags
| MPI2_SGE_FLAGS_LAST_ELEMENT
)
1019 << MPI2_SGE_FLAGS_SHIFT
;
1020 sgl_flags_end_buffer
= (sgl_flags
| MPI2_SGE_FLAGS_LAST_ELEMENT
|
1021 MPI2_SGE_FLAGS_END_OF_BUFFER
| MPI2_SGE_FLAGS_END_OF_LIST
)
1022 << MPI2_SGE_FLAGS_SHIFT
;
1023 sgl_flags
= sgl_flags
<< MPI2_SGE_FLAGS_SHIFT
;
1025 sg_scmd
= scsi_sglist(scmd
);
1026 sges_left
= scsi_dma_map(scmd
);
1027 if (sges_left
< 0) {
1028 sdev_printk(KERN_ERR
, scmd
->device
, "pci_map_sg"
1029 " failed: request for %d bytes!\n", scsi_bufflen(scmd
));
1033 sg_local
= &mpi_request
->SGL
;
1034 sges_in_segment
= ioc
->max_sges_in_main_message
;
1035 if (sges_left
<= sges_in_segment
)
1036 goto fill_in_last_segment
;
1038 mpi_request
->ChainOffset
= (offsetof(Mpi2SCSIIORequest_t
, SGL
) +
1039 (sges_in_segment
* ioc
->sge_size
))/4;
1041 /* fill in main message segment when there is a chain following */
1042 while (sges_in_segment
) {
1043 if (sges_in_segment
== 1)
1044 ioc
->base_add_sg_single(sg_local
,
1045 sgl_flags_last_element
| sg_dma_len(sg_scmd
),
1046 sg_dma_address(sg_scmd
));
1048 ioc
->base_add_sg_single(sg_local
, sgl_flags
|
1049 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
1050 sg_scmd
= sg_next(sg_scmd
);
1051 sg_local
+= ioc
->sge_size
;
1056 /* initializing the chain flags and pointers */
1057 chain_flags
= MPI2_SGE_FLAGS_CHAIN_ELEMENT
<< MPI2_SGE_FLAGS_SHIFT
;
1058 chain
= _scsih_get_chain_buffer(ioc
, smid
);
1059 chain_dma
= _scsih_get_chain_buffer_dma(ioc
, smid
);
1061 sges_in_segment
= (sges_left
<=
1062 ioc
->max_sges_in_chain_message
) ? sges_left
:
1063 ioc
->max_sges_in_chain_message
;
1064 chain_offset
= (sges_left
== sges_in_segment
) ?
1065 0 : (sges_in_segment
* ioc
->sge_size
)/4;
1066 chain_length
= sges_in_segment
* ioc
->sge_size
;
1068 chain_offset
= chain_offset
<<
1069 MPI2_SGE_CHAIN_OFFSET_SHIFT
;
1070 chain_length
+= ioc
->sge_size
;
1072 ioc
->base_add_sg_single(sg_local
, chain_flags
| chain_offset
|
1073 chain_length
, chain_dma
);
1076 goto fill_in_last_segment
;
1078 /* fill in chain segments */
1079 while (sges_in_segment
) {
1080 if (sges_in_segment
== 1)
1081 ioc
->base_add_sg_single(sg_local
,
1082 sgl_flags_last_element
|
1083 sg_dma_len(sg_scmd
),
1084 sg_dma_address(sg_scmd
));
1086 ioc
->base_add_sg_single(sg_local
, sgl_flags
|
1087 sg_dma_len(sg_scmd
),
1088 sg_dma_address(sg_scmd
));
1089 sg_scmd
= sg_next(sg_scmd
);
1090 sg_local
+= ioc
->sge_size
;
1095 chain_dma
+= ioc
->request_sz
;
1096 chain
+= ioc
->request_sz
;
1100 fill_in_last_segment
:
1102 /* fill the last segment */
1105 ioc
->base_add_sg_single(sg_local
, sgl_flags_end_buffer
|
1106 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
1108 ioc
->base_add_sg_single(sg_local
, sgl_flags
|
1109 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
1110 sg_scmd
= sg_next(sg_scmd
);
1111 sg_local
+= ioc
->sge_size
;
1119 * _scsih_change_queue_depth - setting device queue depth
1120 * @sdev: scsi device struct
1121 * @qdepth: requested queue depth
1122 * @reason: calling context
1124 * Returns queue depth.
1127 _scsih_change_queue_depth(struct scsi_device
*sdev
, int qdepth
, int reason
)
1129 struct Scsi_Host
*shost
= sdev
->host
;
1132 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1133 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1134 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1135 struct _sas_device
*sas_device
;
1136 unsigned long flags
;
1138 if (reason
!= SCSI_QDEPTH_DEFAULT
)
1141 max_depth
= shost
->can_queue
;
1143 /* limit max device queue for SATA to 32 */
1144 sas_device_priv_data
= sdev
->hostdata
;
1145 if (!sas_device_priv_data
)
1147 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
1148 if (!sas_target_priv_data
)
1150 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
))
1152 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1153 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1154 sas_device_priv_data
->sas_target
->sas_address
);
1155 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1156 if (sas_device
&& sas_device
->device_info
&
1157 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1158 max_depth
= MPT2SAS_SATA_QUEUE_DEPTH
;
1162 if (!sdev
->tagged_supported
)
1164 if (qdepth
> max_depth
)
1166 tag_type
= (qdepth
== 1) ? 0 : MSG_SIMPLE_TAG
;
1167 scsi_adjust_queue_depth(sdev
, tag_type
, qdepth
);
1169 if (sdev
->inquiry_len
> 7)
1170 sdev_printk(KERN_INFO
, sdev
, "qdepth(%d), tagged(%d), "
1171 "simple(%d), ordered(%d), scsi_level(%d), cmd_que(%d)\n",
1172 sdev
->queue_depth
, sdev
->tagged_supported
, sdev
->simple_tags
,
1173 sdev
->ordered_tags
, sdev
->scsi_level
,
1174 (sdev
->inquiry
[7] & 2) >> 1);
1176 return sdev
->queue_depth
;
1180 * _scsih_change_queue_type - changing device queue tag type
1181 * @sdev: scsi device struct
1182 * @tag_type: requested tag type
1184 * Returns queue tag type.
1187 _scsih_change_queue_type(struct scsi_device
*sdev
, int tag_type
)
1189 if (sdev
->tagged_supported
) {
1190 scsi_set_tag_type(sdev
, tag_type
);
1192 scsi_activate_tcq(sdev
, sdev
->queue_depth
);
1194 scsi_deactivate_tcq(sdev
, sdev
->queue_depth
);
1202 * _scsih_target_alloc - target add routine
1203 * @starget: scsi target struct
1205 * Returns 0 if ok. Any other return is assumed to be an error and
1206 * the device is ignored.
1209 _scsih_target_alloc(struct scsi_target
*starget
)
1211 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
1212 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1213 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1214 struct _sas_device
*sas_device
;
1215 struct _raid_device
*raid_device
;
1216 unsigned long flags
;
1217 struct sas_rphy
*rphy
;
1219 sas_target_priv_data
= kzalloc(sizeof(struct scsi_target
), GFP_KERNEL
);
1220 if (!sas_target_priv_data
)
1223 starget
->hostdata
= sas_target_priv_data
;
1224 sas_target_priv_data
->starget
= starget
;
1225 sas_target_priv_data
->handle
= MPT2SAS_INVALID_DEVICE_HANDLE
;
1228 if (starget
->channel
== RAID_CHANNEL
) {
1229 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1230 raid_device
= _scsih_raid_device_find_by_id(ioc
, starget
->id
,
1233 sas_target_priv_data
->handle
= raid_device
->handle
;
1234 sas_target_priv_data
->sas_address
= raid_device
->wwid
;
1235 sas_target_priv_data
->flags
|= MPT_TARGET_FLAGS_VOLUME
;
1236 raid_device
->starget
= starget
;
1238 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1242 /* sas/sata devices */
1243 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1244 rphy
= dev_to_rphy(starget
->dev
.parent
);
1245 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1246 rphy
->identify
.sas_address
);
1249 sas_target_priv_data
->handle
= sas_device
->handle
;
1250 sas_target_priv_data
->sas_address
= sas_device
->sas_address
;
1251 sas_device
->starget
= starget
;
1252 sas_device
->id
= starget
->id
;
1253 sas_device
->channel
= starget
->channel
;
1254 if (test_bit(sas_device
->handle
, ioc
->pd_handles
))
1255 sas_target_priv_data
->flags
|=
1256 MPT_TARGET_FLAGS_RAID_COMPONENT
;
1258 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1264 * _scsih_target_destroy - target destroy routine
1265 * @starget: scsi target struct
1270 _scsih_target_destroy(struct scsi_target
*starget
)
1272 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
1273 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1274 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1275 struct _sas_device
*sas_device
;
1276 struct _raid_device
*raid_device
;
1277 unsigned long flags
;
1278 struct sas_rphy
*rphy
;
1280 sas_target_priv_data
= starget
->hostdata
;
1281 if (!sas_target_priv_data
)
1284 if (starget
->channel
== RAID_CHANNEL
) {
1285 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1286 raid_device
= _scsih_raid_device_find_by_id(ioc
, starget
->id
,
1289 raid_device
->starget
= NULL
;
1290 raid_device
->sdev
= NULL
;
1292 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1296 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1297 rphy
= dev_to_rphy(starget
->dev
.parent
);
1298 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1299 rphy
->identify
.sas_address
);
1300 if (sas_device
&& (sas_device
->starget
== starget
) &&
1301 (sas_device
->id
== starget
->id
) &&
1302 (sas_device
->channel
== starget
->channel
))
1303 sas_device
->starget
= NULL
;
1305 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1308 kfree(sas_target_priv_data
);
1309 starget
->hostdata
= NULL
;
1313 * _scsih_slave_alloc - device add routine
1314 * @sdev: scsi device struct
1316 * Returns 0 if ok. Any other return is assumed to be an error and
1317 * the device is ignored.
1320 _scsih_slave_alloc(struct scsi_device
*sdev
)
1322 struct Scsi_Host
*shost
;
1323 struct MPT2SAS_ADAPTER
*ioc
;
1324 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1325 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1326 struct scsi_target
*starget
;
1327 struct _raid_device
*raid_device
;
1328 unsigned long flags
;
1330 sas_device_priv_data
= kzalloc(sizeof(struct scsi_device
), GFP_KERNEL
);
1331 if (!sas_device_priv_data
)
1334 sas_device_priv_data
->lun
= sdev
->lun
;
1335 sas_device_priv_data
->flags
= MPT_DEVICE_FLAGS_INIT
;
1337 starget
= scsi_target(sdev
);
1338 sas_target_priv_data
= starget
->hostdata
;
1339 sas_target_priv_data
->num_luns
++;
1340 sas_device_priv_data
->sas_target
= sas_target_priv_data
;
1341 sdev
->hostdata
= sas_device_priv_data
;
1342 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
))
1343 sdev
->no_uld_attach
= 1;
1345 shost
= dev_to_shost(&starget
->dev
);
1346 ioc
= shost_priv(shost
);
1347 if (starget
->channel
== RAID_CHANNEL
) {
1348 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1349 raid_device
= _scsih_raid_device_find_by_id(ioc
,
1350 starget
->id
, starget
->channel
);
1352 raid_device
->sdev
= sdev
; /* raid is single lun */
1353 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1360 * _scsih_slave_destroy - device destroy routine
1361 * @sdev: scsi device struct
1366 _scsih_slave_destroy(struct scsi_device
*sdev
)
1368 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1369 struct scsi_target
*starget
;
1371 if (!sdev
->hostdata
)
1374 starget
= scsi_target(sdev
);
1375 sas_target_priv_data
= starget
->hostdata
;
1376 sas_target_priv_data
->num_luns
--;
1377 kfree(sdev
->hostdata
);
1378 sdev
->hostdata
= NULL
;
1382 * _scsih_display_sata_capabilities - sata capabilities
1383 * @ioc: per adapter object
1384 * @sas_device: the sas_device object
1385 * @sdev: scsi device struct
1388 _scsih_display_sata_capabilities(struct MPT2SAS_ADAPTER
*ioc
,
1389 struct _sas_device
*sas_device
, struct scsi_device
*sdev
)
1391 Mpi2ConfigReply_t mpi_reply
;
1392 Mpi2SasDevicePage0_t sas_device_pg0
;
1397 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
1398 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, sas_device
->handle
))) {
1399 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1400 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1404 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
1405 MPI2_IOCSTATUS_MASK
;
1406 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
1407 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1408 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1412 flags
= le16_to_cpu(sas_device_pg0
.Flags
);
1413 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
1415 sdev_printk(KERN_INFO
, sdev
,
1416 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1417 "sw_preserve(%s)\n",
1418 (device_info
& MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE
) ? "y" : "n",
1419 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED
) ? "y" : "n",
1420 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY
) ? "y" :
1422 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED
) ? "y" : "n",
1423 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED
) ? "y" : "n",
1424 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE
) ? "y" : "n");
1428 * _scsih_is_raid - return boolean indicating device is raid volume
1429 * @dev the device struct object
1432 _scsih_is_raid(struct device
*dev
)
1434 struct scsi_device
*sdev
= to_scsi_device(dev
);
1436 return (sdev
->channel
== RAID_CHANNEL
) ? 1 : 0;
1440 * _scsih_get_resync - get raid volume resync percent complete
1441 * @dev the device struct object
1444 _scsih_get_resync(struct device
*dev
)
1446 struct scsi_device
*sdev
= to_scsi_device(dev
);
1447 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
1448 static struct _raid_device
*raid_device
;
1449 unsigned long flags
;
1450 Mpi2RaidVolPage0_t vol_pg0
;
1451 Mpi2ConfigReply_t mpi_reply
;
1452 u32 volume_status_flags
;
1453 u8 percent_complete
= 0;
1455 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1456 raid_device
= _scsih_raid_device_find_by_id(ioc
, sdev
->id
,
1458 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1463 if (mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, &vol_pg0
,
1464 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, raid_device
->handle
,
1465 sizeof(Mpi2RaidVolPage0_t
))) {
1466 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1467 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1471 volume_status_flags
= le32_to_cpu(vol_pg0
.VolumeStatusFlags
);
1472 if (volume_status_flags
& MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS
)
1473 percent_complete
= raid_device
->percent_complete
;
1475 raid_set_resync(mpt2sas_raid_template
, dev
, percent_complete
);
1479 * _scsih_get_state - get raid volume level
1480 * @dev the device struct object
1483 _scsih_get_state(struct device
*dev
)
1485 struct scsi_device
*sdev
= to_scsi_device(dev
);
1486 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
1487 static struct _raid_device
*raid_device
;
1488 unsigned long flags
;
1489 Mpi2RaidVolPage0_t vol_pg0
;
1490 Mpi2ConfigReply_t mpi_reply
;
1492 enum raid_state state
= RAID_STATE_UNKNOWN
;
1494 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1495 raid_device
= _scsih_raid_device_find_by_id(ioc
, sdev
->id
,
1497 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1502 if (mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, &vol_pg0
,
1503 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, raid_device
->handle
,
1504 sizeof(Mpi2RaidVolPage0_t
))) {
1505 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1506 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1510 volstate
= le32_to_cpu(vol_pg0
.VolumeStatusFlags
);
1511 if (volstate
& MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS
) {
1512 state
= RAID_STATE_RESYNCING
;
1516 switch (vol_pg0
.VolumeState
) {
1517 case MPI2_RAID_VOL_STATE_OPTIMAL
:
1518 case MPI2_RAID_VOL_STATE_ONLINE
:
1519 state
= RAID_STATE_ACTIVE
;
1521 case MPI2_RAID_VOL_STATE_DEGRADED
:
1522 state
= RAID_STATE_DEGRADED
;
1524 case MPI2_RAID_VOL_STATE_FAILED
:
1525 case MPI2_RAID_VOL_STATE_MISSING
:
1526 state
= RAID_STATE_OFFLINE
;
1530 raid_set_state(mpt2sas_raid_template
, dev
, state
);
1534 * _scsih_set_level - set raid level
1535 * @sdev: scsi device struct
1536 * @raid_device: raid_device object
1539 _scsih_set_level(struct scsi_device
*sdev
, struct _raid_device
*raid_device
)
1541 enum raid_level level
= RAID_LEVEL_UNKNOWN
;
1543 switch (raid_device
->volume_type
) {
1544 case MPI2_RAID_VOL_TYPE_RAID0
:
1545 level
= RAID_LEVEL_0
;
1547 case MPI2_RAID_VOL_TYPE_RAID10
:
1548 level
= RAID_LEVEL_10
;
1550 case MPI2_RAID_VOL_TYPE_RAID1E
:
1551 level
= RAID_LEVEL_1E
;
1553 case MPI2_RAID_VOL_TYPE_RAID1
:
1554 level
= RAID_LEVEL_1
;
1558 raid_set_level(mpt2sas_raid_template
, &sdev
->sdev_gendev
, level
);
1562 * _scsih_get_volume_capabilities - volume capabilities
1563 * @ioc: per adapter object
1564 * @sas_device: the raid_device object
1567 _scsih_get_volume_capabilities(struct MPT2SAS_ADAPTER
*ioc
,
1568 struct _raid_device
*raid_device
)
1570 Mpi2RaidVolPage0_t
*vol_pg0
;
1571 Mpi2RaidPhysDiskPage0_t pd_pg0
;
1572 Mpi2SasDevicePage0_t sas_device_pg0
;
1573 Mpi2ConfigReply_t mpi_reply
;
1577 if ((mpt2sas_config_get_number_pds(ioc
, raid_device
->handle
,
1578 &num_pds
)) || !num_pds
) {
1579 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1580 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1584 raid_device
->num_pds
= num_pds
;
1585 sz
= offsetof(Mpi2RaidVolPage0_t
, PhysDisk
) + (num_pds
*
1586 sizeof(Mpi2RaidVol0PhysDisk_t
));
1587 vol_pg0
= kzalloc(sz
, GFP_KERNEL
);
1589 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1590 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1594 if ((mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, vol_pg0
,
1595 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, raid_device
->handle
, sz
))) {
1596 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1597 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1602 raid_device
->volume_type
= vol_pg0
->VolumeType
;
1604 /* figure out what the underlying devices are by
1605 * obtaining the device_info bits for the 1st device
1607 if (!(mpt2sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
1608 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM
,
1609 vol_pg0
->PhysDisk
[0].PhysDiskNum
))) {
1610 if (!(mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
1611 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
1612 le16_to_cpu(pd_pg0
.DevHandle
)))) {
1613 raid_device
->device_info
=
1614 le32_to_cpu(sas_device_pg0
.DeviceInfo
);
1622 * _scsih_enable_tlr - setting TLR flags
1623 * @ioc: per adapter object
1624 * @sdev: scsi device struct
1626 * Enabling Transaction Layer Retries for tape devices when
1627 * vpd page 0x90 is present
1631 _scsih_enable_tlr(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_device
*sdev
)
1634 if (sdev
->type
!= TYPE_TAPE
)
1637 if (!(ioc
->facts
.IOCCapabilities
& MPI2_IOCFACTS_CAPABILITY_TLR
))
1640 sas_enable_tlr(sdev
);
1641 sdev_printk(KERN_INFO
, sdev
, "TLR %s\n",
1642 sas_is_tlr_enabled(sdev
) ? "Enabled" : "Disabled");
1648 * _scsih_slave_configure - device configure routine.
1649 * @sdev: scsi device struct
1651 * Returns 0 if ok. Any other return is assumed to be an error and
1652 * the device is ignored.
1655 _scsih_slave_configure(struct scsi_device
*sdev
)
1657 struct Scsi_Host
*shost
= sdev
->host
;
1658 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1659 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1660 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1661 struct _sas_device
*sas_device
;
1662 struct _raid_device
*raid_device
;
1663 unsigned long flags
;
1670 sas_device_priv_data
= sdev
->hostdata
;
1671 sas_device_priv_data
->configured_lun
= 1;
1672 sas_device_priv_data
->flags
&= ~MPT_DEVICE_FLAGS_INIT
;
1673 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
1675 /* raid volume handling */
1676 if (sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
1678 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1679 raid_device
= _scsih_raid_device_find_by_handle(ioc
,
1680 sas_target_priv_data
->handle
);
1681 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1683 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1684 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1688 _scsih_get_volume_capabilities(ioc
, raid_device
);
1690 /* RAID Queue Depth Support
1691 * IS volume = underlying qdepth of drive type, either
1692 * MPT2SAS_SAS_QUEUE_DEPTH or MPT2SAS_SATA_QUEUE_DEPTH
1693 * IM/IME/R10 = 128 (MPT2SAS_RAID_QUEUE_DEPTH)
1695 if (raid_device
->device_info
&
1696 MPI2_SAS_DEVICE_INFO_SSP_TARGET
) {
1697 qdepth
= MPT2SAS_SAS_QUEUE_DEPTH
;
1700 qdepth
= MPT2SAS_SATA_QUEUE_DEPTH
;
1701 if (raid_device
->device_info
&
1702 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1708 switch (raid_device
->volume_type
) {
1709 case MPI2_RAID_VOL_TYPE_RAID0
:
1712 case MPI2_RAID_VOL_TYPE_RAID1E
:
1713 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
1714 if (ioc
->manu_pg10
.OEMIdentifier
&&
1715 (ioc
->manu_pg10
.GenericFlags0
&
1716 MFG10_GF0_R10_DISPLAY
) &&
1717 !(raid_device
->num_pds
% 2))
1722 case MPI2_RAID_VOL_TYPE_RAID1
:
1723 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
1726 case MPI2_RAID_VOL_TYPE_RAID10
:
1727 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
1730 case MPI2_RAID_VOL_TYPE_UNKNOWN
:
1732 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
1737 sdev_printk(KERN_INFO
, sdev
, "%s: "
1738 "handle(0x%04x), wwid(0x%016llx), pd_count(%d), type(%s)\n",
1739 r_level
, raid_device
->handle
,
1740 (unsigned long long)raid_device
->wwid
,
1741 raid_device
->num_pds
, ds
);
1742 _scsih_change_queue_depth(sdev
, qdepth
, SCSI_QDEPTH_DEFAULT
);
1743 /* raid transport support */
1744 _scsih_set_level(sdev
, raid_device
);
1748 /* non-raid handling */
1749 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1750 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1751 sas_device_priv_data
->sas_target
->sas_address
);
1752 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1754 if (sas_target_priv_data
->flags
&
1755 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
1756 mpt2sas_config_get_volume_handle(ioc
,
1757 sas_device
->handle
, &sas_device
->volume_handle
);
1758 mpt2sas_config_get_volume_wwid(ioc
,
1759 sas_device
->volume_handle
,
1760 &sas_device
->volume_wwid
);
1762 if (sas_device
->device_info
& MPI2_SAS_DEVICE_INFO_SSP_TARGET
) {
1763 qdepth
= MPT2SAS_SAS_QUEUE_DEPTH
;
1767 qdepth
= MPT2SAS_SATA_QUEUE_DEPTH
;
1768 if (sas_device
->device_info
&
1769 MPI2_SAS_DEVICE_INFO_STP_TARGET
)
1771 else if (sas_device
->device_info
&
1772 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1776 sdev_printk(KERN_INFO
, sdev
, "%s: handle(0x%04x), "
1777 "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n",
1778 ds
, sas_device
->handle
,
1779 (unsigned long long)sas_device
->sas_address
,
1781 (unsigned long long)sas_device
->device_name
);
1782 sdev_printk(KERN_INFO
, sdev
, "%s: "
1783 "enclosure_logical_id(0x%016llx), slot(%d)\n", ds
,
1784 (unsigned long long) sas_device
->enclosure_logical_id
,
1788 _scsih_display_sata_capabilities(ioc
, sas_device
, sdev
);
1791 _scsih_change_queue_depth(sdev
, qdepth
, SCSI_QDEPTH_DEFAULT
);
1794 sas_read_port_mode_page(sdev
);
1795 _scsih_enable_tlr(ioc
, sdev
);
1801 * _scsih_bios_param - fetch head, sector, cylinder info for a disk
1802 * @sdev: scsi device struct
1803 * @bdev: pointer to block device context
1804 * @capacity: device size (in 512 byte sectors)
1805 * @params: three element array to place output:
1806 * params[0] number of heads (max 255)
1807 * params[1] number of sectors (max 63)
1808 * params[2] number of cylinders
1813 _scsih_bios_param(struct scsi_device
*sdev
, struct block_device
*bdev
,
1814 sector_t capacity
, int params
[])
1824 dummy
= heads
* sectors
;
1825 cylinders
= capacity
;
1826 sector_div(cylinders
, dummy
);
1829 * Handle extended translation size for logical drives
1832 if ((ulong
)capacity
>= 0x200000) {
1835 dummy
= heads
* sectors
;
1836 cylinders
= capacity
;
1837 sector_div(cylinders
, dummy
);
1842 params
[1] = sectors
;
1843 params
[2] = cylinders
;
1849 * _scsih_response_code - translation of device response code
1850 * @ioc: per adapter object
1851 * @response_code: response code returned by the device
1856 _scsih_response_code(struct MPT2SAS_ADAPTER
*ioc
, u8 response_code
)
1860 switch (response_code
) {
1861 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE
:
1862 desc
= "task management request completed";
1864 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
:
1865 desc
= "invalid frame";
1867 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED
:
1868 desc
= "task management request not supported";
1870 case MPI2_SCSITASKMGMT_RSP_TM_FAILED
:
1871 desc
= "task management request failed";
1873 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
:
1874 desc
= "task management request succeeded";
1876 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN
:
1877 desc
= "invalid lun";
1880 desc
= "overlapped tag attempted";
1882 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
:
1883 desc
= "task queued, however not sent to target";
1889 printk(MPT2SAS_WARN_FMT
"response_code(0x%01x): %s\n",
1890 ioc
->name
, response_code
, desc
);
1894 * _scsih_tm_done - tm completion routine
1895 * @ioc: per adapter object
1896 * @smid: system request message index
1897 * @msix_index: MSIX table index supplied by the OS
1898 * @reply: reply message frame(lower 32bit addr)
1901 * The callback handler when using scsih_issue_tm.
1903 * Return 1 meaning mf should be freed from _base_interrupt
1904 * 0 means the mf is freed from this function.
1907 _scsih_tm_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
1909 MPI2DefaultReply_t
*mpi_reply
;
1911 if (ioc
->tm_cmds
.status
== MPT2_CMD_NOT_USED
)
1913 if (ioc
->tm_cmds
.smid
!= smid
)
1915 ioc
->tm_cmds
.status
|= MPT2_CMD_COMPLETE
;
1916 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
1918 memcpy(ioc
->tm_cmds
.reply
, mpi_reply
, mpi_reply
->MsgLength
*4);
1919 ioc
->tm_cmds
.status
|= MPT2_CMD_REPLY_VALID
;
1921 ioc
->tm_cmds
.status
&= ~MPT2_CMD_PENDING
;
1922 complete(&ioc
->tm_cmds
.done
);
1927 * mpt2sas_scsih_set_tm_flag - set per target tm_busy
1928 * @ioc: per adapter object
1929 * @handle: device handle
1931 * During taskmangement request, we need to freeze the device queue.
1934 mpt2sas_scsih_set_tm_flag(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
1936 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1937 struct scsi_device
*sdev
;
1940 shost_for_each_device(sdev
, ioc
->shost
) {
1943 sas_device_priv_data
= sdev
->hostdata
;
1944 if (!sas_device_priv_data
)
1946 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
1947 sas_device_priv_data
->sas_target
->tm_busy
= 1;
1949 ioc
->ignore_loginfos
= 1;
1955 * mpt2sas_scsih_clear_tm_flag - clear per target tm_busy
1956 * @ioc: per adapter object
1957 * @handle: device handle
1959 * During taskmangement request, we need to freeze the device queue.
1962 mpt2sas_scsih_clear_tm_flag(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
1964 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1965 struct scsi_device
*sdev
;
1968 shost_for_each_device(sdev
, ioc
->shost
) {
1971 sas_device_priv_data
= sdev
->hostdata
;
1972 if (!sas_device_priv_data
)
1974 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
1975 sas_device_priv_data
->sas_target
->tm_busy
= 0;
1977 ioc
->ignore_loginfos
= 0;
1984 * mpt2sas_scsih_issue_tm - main routine for sending tm requests
1985 * @ioc: per adapter struct
1986 * @device_handle: device handle
1987 * @channel: the channel assigned by the OS
1988 * @id: the id assigned by the OS
1990 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
1991 * @smid_task: smid assigned to the task
1992 * @timeout: timeout in seconds
1995 * A generic API for sending task management requests to firmware.
1997 * The callback index is set inside `ioc->tm_cb_idx`.
1999 * Return SUCCESS or FAILED.
2002 mpt2sas_scsih_issue_tm(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
, uint channel
,
2003 uint id
, uint lun
, u8 type
, u16 smid_task
, ulong timeout
,
2004 struct scsi_cmnd
*scmd
)
2006 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
2007 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
2010 unsigned long timeleft
;
2011 struct scsi_cmnd
*scmd_lookup
;
2014 mutex_lock(&ioc
->tm_cmds
.mutex
);
2015 if (ioc
->tm_cmds
.status
!= MPT2_CMD_NOT_USED
) {
2016 printk(MPT2SAS_INFO_FMT
"%s: tm_cmd busy!!!\n",
2017 __func__
, ioc
->name
);
2022 if (ioc
->shost_recovery
|| ioc
->remove_host
||
2023 ioc
->pci_error_recovery
) {
2024 printk(MPT2SAS_INFO_FMT
"%s: host reset in progress!\n",
2025 __func__
, ioc
->name
);
2030 ioc_state
= mpt2sas_base_get_iocstate(ioc
, 0);
2031 if (ioc_state
& MPI2_DOORBELL_USED
) {
2032 dhsprintk(ioc
, printk(MPT2SAS_INFO_FMT
"unexpected doorbell "
2033 "active!\n", ioc
->name
));
2034 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2040 if ((ioc_state
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_FAULT
) {
2041 mpt2sas_base_fault_info(ioc
, ioc_state
&
2042 MPI2_DOORBELL_DATA_MASK
);
2043 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2049 smid
= mpt2sas_base_get_smid_hpr(ioc
, ioc
->tm_cb_idx
);
2051 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
2052 ioc
->name
, __func__
);
2057 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"sending tm: handle(0x%04x),"
2058 " task_type(0x%02x), smid(%d)\n", ioc
->name
, handle
, type
,
2060 ioc
->tm_cmds
.status
= MPT2_CMD_PENDING
;
2061 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
2062 ioc
->tm_cmds
.smid
= smid
;
2063 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
2064 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
2065 mpi_request
->DevHandle
= cpu_to_le16(handle
);
2066 mpi_request
->TaskType
= type
;
2067 mpi_request
->TaskMID
= cpu_to_le16(smid_task
);
2068 int_to_scsilun(lun
, (struct scsi_lun
*)mpi_request
->LUN
);
2069 mpt2sas_scsih_set_tm_flag(ioc
, handle
);
2070 init_completion(&ioc
->tm_cmds
.done
);
2071 mpt2sas_base_put_smid_hi_priority(ioc
, smid
);
2072 timeleft
= wait_for_completion_timeout(&ioc
->tm_cmds
.done
, timeout
*HZ
);
2073 if (!(ioc
->tm_cmds
.status
& MPT2_CMD_COMPLETE
)) {
2074 printk(MPT2SAS_ERR_FMT
"%s: timeout\n",
2075 ioc
->name
, __func__
);
2076 _debug_dump_mf(mpi_request
,
2077 sizeof(Mpi2SCSITaskManagementRequest_t
)/4);
2078 if (!(ioc
->tm_cmds
.status
& MPT2_CMD_RESET
)) {
2079 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2082 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
2083 mpt2sas_scsih_clear_tm_flag(ioc
, handle
);
2088 if (ioc
->tm_cmds
.status
& MPT2_CMD_REPLY_VALID
) {
2089 mpi_reply
= ioc
->tm_cmds
.reply
;
2090 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"complete tm: "
2091 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
2092 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
2093 le32_to_cpu(mpi_reply
->IOCLogInfo
),
2094 le32_to_cpu(mpi_reply
->TerminationCount
)));
2095 if (ioc
->logging_level
& MPT_DEBUG_TM
) {
2096 _scsih_response_code(ioc
, mpi_reply
->ResponseCode
);
2097 if (mpi_reply
->IOCStatus
)
2098 _debug_dump_mf(mpi_request
,
2099 sizeof(Mpi2SCSITaskManagementRequest_t
)/4);
2104 * Check to see the commands were terminated.
2105 * This is only needed for eh callbacks, hence the scmd check.
2109 goto bypass_sanity_checks
;
2111 case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
:
2112 scmd_lookup
= _scsih_scsi_lookup_get(ioc
, smid_task
);
2113 if (scmd_lookup
&& (scmd_lookup
->serial_number
==
2114 scmd
->serial_number
))
2120 case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
:
2121 if (_scsih_scsi_lookup_find_by_target(ioc
, id
, channel
))
2127 case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET
:
2128 if (_scsih_scsi_lookup_find_by_lun(ioc
, id
, lun
, channel
))
2135 bypass_sanity_checks
:
2137 mpt2sas_scsih_clear_tm_flag(ioc
, handle
);
2138 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
2139 mutex_unlock(&ioc
->tm_cmds
.mutex
);
2144 mutex_unlock(&ioc
->tm_cmds
.mutex
);
2149 * _scsih_tm_display_info - displays info about the device
2150 * @ioc: per adapter struct
2151 * @scmd: pointer to scsi command object
2153 * Called by task management callback handlers.
2156 _scsih_tm_display_info(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
)
2158 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
2159 struct MPT2SAS_TARGET
*priv_target
= starget
->hostdata
;
2160 struct _sas_device
*sas_device
= NULL
;
2161 unsigned long flags
;
2166 scsi_print_command(scmd
);
2167 if (priv_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
2168 starget_printk(KERN_INFO
, starget
, "volume handle(0x%04x), "
2169 "volume wwid(0x%016llx)\n",
2170 priv_target
->handle
,
2171 (unsigned long long)priv_target
->sas_address
);
2173 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2174 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
2175 priv_target
->sas_address
);
2177 if (priv_target
->flags
&
2178 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2179 starget_printk(KERN_INFO
, starget
,
2180 "volume handle(0x%04x), "
2181 "volume wwid(0x%016llx)\n",
2182 sas_device
->volume_handle
,
2183 (unsigned long long)sas_device
->volume_wwid
);
2185 starget_printk(KERN_INFO
, starget
,
2186 "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n",
2188 (unsigned long long)sas_device
->sas_address
,
2190 starget_printk(KERN_INFO
, starget
,
2191 "enclosure_logical_id(0x%016llx), slot(%d)\n",
2192 (unsigned long long)sas_device
->enclosure_logical_id
,
2195 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2200 * _scsih_abort - eh threads main abort routine
2201 * @scmd: pointer to scsi command object
2203 * Returns SUCCESS if command aborted else FAILED
2206 _scsih_abort(struct scsi_cmnd
*scmd
)
2208 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2209 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2214 sdev_printk(KERN_INFO
, scmd
->device
, "attempting task abort! "
2215 "scmd(%p)\n", scmd
);
2216 _scsih_tm_display_info(ioc
, scmd
);
2218 sas_device_priv_data
= scmd
->device
->hostdata
;
2219 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2220 sdev_printk(KERN_INFO
, scmd
->device
, "device been deleted! "
2221 "scmd(%p)\n", scmd
);
2222 scmd
->result
= DID_NO_CONNECT
<< 16;
2223 scmd
->scsi_done(scmd
);
2228 /* search for the command */
2229 smid
= _scsih_scsi_lookup_find_by_scmd(ioc
, scmd
);
2231 scmd
->result
= DID_RESET
<< 16;
2236 /* for hidden raid components and volumes this is not supported */
2237 if (sas_device_priv_data
->sas_target
->flags
&
2238 MPT_TARGET_FLAGS_RAID_COMPONENT
||
2239 sas_device_priv_data
->sas_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
2240 scmd
->result
= DID_RESET
<< 16;
2245 mpt2sas_halt_firmware(ioc
);
2247 handle
= sas_device_priv_data
->sas_target
->handle
;
2248 r
= mpt2sas_scsih_issue_tm(ioc
, handle
, scmd
->device
->channel
,
2249 scmd
->device
->id
, scmd
->device
->lun
,
2250 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
, smid
, 30, scmd
);
2253 sdev_printk(KERN_INFO
, scmd
->device
, "task abort: %s scmd(%p)\n",
2254 ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2259 * _scsih_dev_reset - eh threads main device reset routine
2260 * @scmd: pointer to scsi command object
2262 * Returns SUCCESS if command aborted else FAILED
2265 _scsih_dev_reset(struct scsi_cmnd
*scmd
)
2267 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2268 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2269 struct _sas_device
*sas_device
;
2270 unsigned long flags
;
2274 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
2276 starget_printk(KERN_INFO
, starget
, "attempting target reset! "
2277 "scmd(%p)\n", scmd
);
2278 _scsih_tm_display_info(ioc
, scmd
);
2280 sas_device_priv_data
= scmd
->device
->hostdata
;
2281 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2282 starget_printk(KERN_INFO
, starget
, "target been deleted! "
2283 "scmd(%p)\n", scmd
);
2284 scmd
->result
= DID_NO_CONNECT
<< 16;
2285 scmd
->scsi_done(scmd
);
2290 /* for hidden raid components obtain the volume_handle */
2292 if (sas_device_priv_data
->sas_target
->flags
&
2293 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2294 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2295 sas_device
= _scsih_sas_device_find_by_handle(ioc
,
2296 sas_device_priv_data
->sas_target
->handle
);
2298 handle
= sas_device
->volume_handle
;
2299 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2301 handle
= sas_device_priv_data
->sas_target
->handle
;
2304 scmd
->result
= DID_RESET
<< 16;
2309 r
= mpt2sas_scsih_issue_tm(ioc
, handle
, scmd
->device
->channel
,
2310 scmd
->device
->id
, scmd
->device
->lun
,
2311 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET
, 0, 30, scmd
);
2314 sdev_printk(KERN_INFO
, scmd
->device
, "device reset: %s scmd(%p)\n",
2315 ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2320 * _scsih_target_reset - eh threads main target reset routine
2321 * @scmd: pointer to scsi command object
2323 * Returns SUCCESS if command aborted else FAILED
2326 _scsih_target_reset(struct scsi_cmnd
*scmd
)
2328 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2329 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2330 struct _sas_device
*sas_device
;
2331 unsigned long flags
;
2334 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
2336 starget_printk(KERN_INFO
, starget
, "attempting target reset! "
2337 "scmd(%p)\n", scmd
);
2338 _scsih_tm_display_info(ioc
, scmd
);
2340 sas_device_priv_data
= scmd
->device
->hostdata
;
2341 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2342 starget_printk(KERN_INFO
, starget
, "target been deleted! "
2343 "scmd(%p)\n", scmd
);
2344 scmd
->result
= DID_NO_CONNECT
<< 16;
2345 scmd
->scsi_done(scmd
);
2350 /* for hidden raid components obtain the volume_handle */
2352 if (sas_device_priv_data
->sas_target
->flags
&
2353 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2354 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2355 sas_device
= _scsih_sas_device_find_by_handle(ioc
,
2356 sas_device_priv_data
->sas_target
->handle
);
2358 handle
= sas_device
->volume_handle
;
2359 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2361 handle
= sas_device_priv_data
->sas_target
->handle
;
2364 scmd
->result
= DID_RESET
<< 16;
2369 r
= mpt2sas_scsih_issue_tm(ioc
, handle
, scmd
->device
->channel
,
2370 scmd
->device
->id
, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
, 0,
2374 starget_printk(KERN_INFO
, starget
, "target reset: %s scmd(%p)\n",
2375 ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2380 * _scsih_host_reset - eh threads main host reset routine
2381 * @scmd: pointer to scsi command object
2383 * Returns SUCCESS if command aborted else FAILED
2386 _scsih_host_reset(struct scsi_cmnd
*scmd
)
2388 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2391 printk(MPT2SAS_INFO_FMT
"attempting host reset! scmd(%p)\n",
2393 scsi_print_command(scmd
);
2395 retval
= mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2397 r
= (retval
< 0) ? FAILED
: SUCCESS
;
2398 printk(MPT2SAS_INFO_FMT
"host reset: %s scmd(%p)\n",
2399 ioc
->name
, ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2405 * _scsih_fw_event_add - insert and queue up fw_event
2406 * @ioc: per adapter object
2407 * @fw_event: object describing the event
2408 * Context: This function will acquire ioc->fw_event_lock.
2410 * This adds the firmware event object into link list, then queues it up to
2411 * be processed from user context.
2416 _scsih_fw_event_add(struct MPT2SAS_ADAPTER
*ioc
, struct fw_event_work
*fw_event
)
2418 unsigned long flags
;
2420 if (ioc
->firmware_event_thread
== NULL
)
2423 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2424 list_add_tail(&fw_event
->list
, &ioc
->fw_event_list
);
2425 INIT_DELAYED_WORK(&fw_event
->delayed_work
, _firmware_event_work
);
2426 queue_delayed_work(ioc
->firmware_event_thread
,
2427 &fw_event
->delayed_work
, 0);
2428 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2432 * _scsih_fw_event_free - delete fw_event
2433 * @ioc: per adapter object
2434 * @fw_event: object describing the event
2435 * Context: This function will acquire ioc->fw_event_lock.
2437 * This removes firmware event object from link list, frees associated memory.
2442 _scsih_fw_event_free(struct MPT2SAS_ADAPTER
*ioc
, struct fw_event_work
2445 unsigned long flags
;
2447 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2448 list_del(&fw_event
->list
);
2449 kfree(fw_event
->event_data
);
2451 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2456 * _scsih_queue_rescan - queue a topology rescan from user context
2457 * @ioc: per adapter object
2462 _scsih_queue_rescan(struct MPT2SAS_ADAPTER
*ioc
)
2464 struct fw_event_work
*fw_event
;
2466 if (ioc
->wait_for_port_enable_to_complete
)
2468 fw_event
= kzalloc(sizeof(struct fw_event_work
), GFP_ATOMIC
);
2471 fw_event
->event
= MPT2SAS_RESCAN_AFTER_HOST_RESET
;
2472 fw_event
->ioc
= ioc
;
2473 _scsih_fw_event_add(ioc
, fw_event
);
2477 * _scsih_fw_event_cleanup_queue - cleanup event queue
2478 * @ioc: per adapter object
2480 * Walk the firmware event queue, either killing timers, or waiting
2481 * for outstanding events to complete
2486 _scsih_fw_event_cleanup_queue(struct MPT2SAS_ADAPTER
*ioc
)
2488 struct fw_event_work
*fw_event
, *next
;
2490 if (list_empty(&ioc
->fw_event_list
) ||
2491 !ioc
->firmware_event_thread
|| in_interrupt())
2494 list_for_each_entry_safe(fw_event
, next
, &ioc
->fw_event_list
, list
) {
2495 if (cancel_delayed_work(&fw_event
->delayed_work
)) {
2496 _scsih_fw_event_free(ioc
, fw_event
);
2499 fw_event
->cancel_pending_work
= 1;
2504 * _scsih_ublock_io_device - set the device state to SDEV_RUNNING
2505 * @ioc: per adapter object
2506 * @handle: device handle
2508 * During device pull we need to appropiately set the sdev state.
2511 _scsih_ublock_io_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
2513 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2514 struct scsi_device
*sdev
;
2516 shost_for_each_device(sdev
, ioc
->shost
) {
2517 sas_device_priv_data
= sdev
->hostdata
;
2518 if (!sas_device_priv_data
)
2520 if (!sas_device_priv_data
->block
)
2522 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2523 dewtprintk(ioc
, sdev_printk(KERN_INFO
, sdev
,
2524 MPT2SAS_INFO_FMT
"SDEV_RUNNING: "
2525 "handle(0x%04x)\n", ioc
->name
, handle
));
2526 sas_device_priv_data
->block
= 0;
2527 scsi_internal_device_unblock(sdev
);
2533 * _scsih_block_io_device - set the device state to SDEV_BLOCK
2534 * @ioc: per adapter object
2535 * @handle: device handle
2537 * During device pull we need to appropiately set the sdev state.
2540 _scsih_block_io_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
2542 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2543 struct scsi_device
*sdev
;
2545 shost_for_each_device(sdev
, ioc
->shost
) {
2546 sas_device_priv_data
= sdev
->hostdata
;
2547 if (!sas_device_priv_data
)
2549 if (sas_device_priv_data
->block
)
2551 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2552 dewtprintk(ioc
, sdev_printk(KERN_INFO
, sdev
,
2553 MPT2SAS_INFO_FMT
"SDEV_BLOCK: "
2554 "handle(0x%04x)\n", ioc
->name
, handle
));
2555 sas_device_priv_data
->block
= 1;
2556 scsi_internal_device_block(sdev
);
2562 * _scsih_block_io_to_children_attached_to_ex
2563 * @ioc: per adapter object
2564 * @sas_expander: the sas_device object
2566 * This routine set sdev state to SDEV_BLOCK for all devices
2567 * attached to this expander. This function called when expander is
2571 _scsih_block_io_to_children_attached_to_ex(struct MPT2SAS_ADAPTER
*ioc
,
2572 struct _sas_node
*sas_expander
)
2574 struct _sas_port
*mpt2sas_port
;
2575 struct _sas_device
*sas_device
;
2576 struct _sas_node
*expander_sibling
;
2577 unsigned long flags
;
2582 list_for_each_entry(mpt2sas_port
,
2583 &sas_expander
->sas_port_list
, port_list
) {
2584 if (mpt2sas_port
->remote_identify
.device_type
==
2586 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2588 mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
2589 mpt2sas_port
->remote_identify
.sas_address
);
2590 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2593 _scsih_block_io_device(ioc
, sas_device
->handle
);
2597 list_for_each_entry(mpt2sas_port
,
2598 &sas_expander
->sas_port_list
, port_list
) {
2600 if (mpt2sas_port
->remote_identify
.device_type
==
2601 MPI2_SAS_DEVICE_INFO_EDGE_EXPANDER
||
2602 mpt2sas_port
->remote_identify
.device_type
==
2603 MPI2_SAS_DEVICE_INFO_FANOUT_EXPANDER
) {
2605 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
2607 mpt2sas_scsih_expander_find_by_sas_address(
2608 ioc
, mpt2sas_port
->remote_identify
.sas_address
);
2609 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
2610 _scsih_block_io_to_children_attached_to_ex(ioc
,
2617 * _scsih_block_io_to_children_attached_directly
2618 * @ioc: per adapter object
2619 * @event_data: topology change event data
2621 * This routine set sdev state to SDEV_BLOCK for all devices
2622 * direct attached during device pull.
2625 _scsih_block_io_to_children_attached_directly(struct MPT2SAS_ADAPTER
*ioc
,
2626 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
2633 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
2634 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
2637 phy_number
= event_data
->StartPhyNum
+ i
;
2638 reason_code
= event_data
->PHY
[i
].PhyStatus
&
2639 MPI2_EVENT_SAS_TOPO_RC_MASK
;
2640 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
)
2641 _scsih_block_io_device(ioc
, handle
);
2646 * _scsih_tm_tr_send - send task management request
2647 * @ioc: per adapter object
2648 * @handle: device handle
2649 * Context: interrupt time.
2651 * This code is to initiate the device removal handshake protocal
2652 * with controller firmware. This function will issue target reset
2653 * using high priority request queue. It will send a sas iounit
2654 * controll request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
2656 * This is designed to send muliple task management request at the same
2657 * time to the fifo. If the fifo is full, we will append the request,
2658 * and process it in a future completion.
2661 _scsih_tm_tr_send(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
2663 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
2665 struct _sas_device
*sas_device
;
2666 struct MPT2SAS_TARGET
*sas_target_priv_data
;
2667 unsigned long flags
;
2668 struct _tr_list
*delayed_tr
;
2670 if (ioc
->shost_recovery
|| ioc
->remove_host
||
2671 ioc
->pci_error_recovery
) {
2672 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host reset in "
2673 "progress!\n", __func__
, ioc
->name
));
2677 /* if PD, then return */
2678 if (test_bit(handle
, ioc
->pd_handles
))
2681 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2682 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
2683 if (sas_device
&& sas_device
->starget
&&
2684 sas_device
->starget
->hostdata
) {
2685 sas_target_priv_data
= sas_device
->starget
->hostdata
;
2686 sas_target_priv_data
->deleted
= 1;
2687 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
2688 "setting delete flag: handle(0x%04x), "
2689 "sas_addr(0x%016llx)\n", ioc
->name
, handle
,
2690 (unsigned long long) sas_device
->sas_address
));
2692 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2694 smid
= mpt2sas_base_get_smid_hpr(ioc
, ioc
->tm_tr_cb_idx
);
2696 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
2699 INIT_LIST_HEAD(&delayed_tr
->list
);
2700 delayed_tr
->handle
= handle
;
2701 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_list
);
2702 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
2703 "DELAYED:tr:handle(0x%04x), (open)\n",
2704 ioc
->name
, handle
));
2708 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"tr_send:handle(0x%04x), "
2709 "(open), smid(%d), cb(%d)\n", ioc
->name
, handle
, smid
,
2710 ioc
->tm_tr_cb_idx
));
2711 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
2712 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
2713 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
2714 mpi_request
->DevHandle
= cpu_to_le16(handle
);
2715 mpi_request
->TaskType
= MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
;
2716 mpt2sas_base_put_smid_hi_priority(ioc
, smid
);
2722 * _scsih_sas_control_complete - completion routine
2723 * @ioc: per adapter object
2724 * @smid: system request message index
2725 * @msix_index: MSIX table index supplied by the OS
2726 * @reply: reply message frame(lower 32bit addr)
2727 * Context: interrupt time.
2729 * This is the sas iounit controll completion routine.
2730 * This code is part of the code to initiate the device removal
2731 * handshake protocal with controller firmware.
2733 * Return 1 meaning mf should be freed from _base_interrupt
2734 * 0 means the mf is freed from this function.
2737 _scsih_sas_control_complete(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
,
2738 u8 msix_index
, u32 reply
)
2740 Mpi2SasIoUnitControlReply_t
*mpi_reply
=
2741 mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
2743 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
2744 "sc_complete:handle(0x%04x), (open) "
2745 "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
2746 ioc
->name
, le16_to_cpu(mpi_reply
->DevHandle
), smid
,
2747 le16_to_cpu(mpi_reply
->IOCStatus
),
2748 le32_to_cpu(mpi_reply
->IOCLogInfo
)));
2753 * _scsih_tm_tr_volume_send - send target reset request for volumes
2754 * @ioc: per adapter object
2755 * @handle: device handle
2756 * Context: interrupt time.
2758 * This is designed to send muliple task management request at the same
2759 * time to the fifo. If the fifo is full, we will append the request,
2760 * and process it in a future completion.
2763 _scsih_tm_tr_volume_send(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
2765 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
2767 struct _tr_list
*delayed_tr
;
2769 if (ioc
->shost_recovery
|| ioc
->remove_host
||
2770 ioc
->pci_error_recovery
) {
2771 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host reset in "
2772 "progress!\n", __func__
, ioc
->name
));
2776 smid
= mpt2sas_base_get_smid_hpr(ioc
, ioc
->tm_tr_volume_cb_idx
);
2778 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
2781 INIT_LIST_HEAD(&delayed_tr
->list
);
2782 delayed_tr
->handle
= handle
;
2783 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_volume_list
);
2784 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
2785 "DELAYED:tr:handle(0x%04x), (open)\n",
2786 ioc
->name
, handle
));
2790 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"tr_send:handle(0x%04x), "
2791 "(open), smid(%d), cb(%d)\n", ioc
->name
, handle
, smid
,
2792 ioc
->tm_tr_volume_cb_idx
));
2793 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
2794 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
2795 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
2796 mpi_request
->DevHandle
= cpu_to_le16(handle
);
2797 mpi_request
->TaskType
= MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
;
2798 mpt2sas_base_put_smid_hi_priority(ioc
, smid
);
2802 * _scsih_tm_volume_tr_complete - target reset completion
2803 * @ioc: per adapter object
2804 * @smid: system request message index
2805 * @msix_index: MSIX table index supplied by the OS
2806 * @reply: reply message frame(lower 32bit addr)
2807 * Context: interrupt time.
2809 * Return 1 meaning mf should be freed from _base_interrupt
2810 * 0 means the mf is freed from this function.
2813 _scsih_tm_volume_tr_complete(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
,
2814 u8 msix_index
, u32 reply
)
2817 Mpi2SCSITaskManagementRequest_t
*mpi_request_tm
;
2818 Mpi2SCSITaskManagementReply_t
*mpi_reply
=
2819 mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
2821 if (ioc
->shost_recovery
|| ioc
->remove_host
||
2822 ioc
->pci_error_recovery
) {
2823 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host reset in "
2824 "progress!\n", __func__
, ioc
->name
));
2828 mpi_request_tm
= mpt2sas_base_get_msg_frame(ioc
, smid
);
2829 handle
= le16_to_cpu(mpi_request_tm
->DevHandle
);
2830 if (handle
!= le16_to_cpu(mpi_reply
->DevHandle
)) {
2831 dewtprintk(ioc
, printk("spurious interrupt: "
2832 "handle(0x%04x:0x%04x), smid(%d)!!!\n", handle
,
2833 le16_to_cpu(mpi_reply
->DevHandle
), smid
));
2837 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
2838 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
2839 "loginfo(0x%08x), completed(%d)\n", ioc
->name
,
2840 handle
, smid
, le16_to_cpu(mpi_reply
->IOCStatus
),
2841 le32_to_cpu(mpi_reply
->IOCLogInfo
),
2842 le32_to_cpu(mpi_reply
->TerminationCount
)));
2844 return _scsih_check_for_pending_tm(ioc
, smid
);
2848 * _scsih_tm_tr_complete -
2849 * @ioc: per adapter object
2850 * @smid: system request message index
2851 * @msix_index: MSIX table index supplied by the OS
2852 * @reply: reply message frame(lower 32bit addr)
2853 * Context: interrupt time.
2855 * This is the target reset completion routine.
2856 * This code is part of the code to initiate the device removal
2857 * handshake protocal with controller firmware.
2858 * It will send a sas iounit controll request (MPI2_SAS_OP_REMOVE_DEVICE)
2860 * Return 1 meaning mf should be freed from _base_interrupt
2861 * 0 means the mf is freed from this function.
2864 _scsih_tm_tr_complete(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
,
2868 Mpi2SCSITaskManagementRequest_t
*mpi_request_tm
;
2869 Mpi2SCSITaskManagementReply_t
*mpi_reply
=
2870 mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
2871 Mpi2SasIoUnitControlRequest_t
*mpi_request
;
2874 if (ioc
->shost_recovery
|| ioc
->remove_host
||
2875 ioc
->pci_error_recovery
) {
2876 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host reset in "
2877 "progress!\n", __func__
, ioc
->name
));
2881 mpi_request_tm
= mpt2sas_base_get_msg_frame(ioc
, smid
);
2882 handle
= le16_to_cpu(mpi_request_tm
->DevHandle
);
2883 if (handle
!= le16_to_cpu(mpi_reply
->DevHandle
)) {
2884 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"spurious interrupt: "
2885 "handle(0x%04x:0x%04x), smid(%d)!!!\n", ioc
->name
, handle
,
2886 le16_to_cpu(mpi_reply
->DevHandle
), smid
));
2890 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
2891 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
2892 "loginfo(0x%08x), completed(%d)\n", ioc
->name
,
2893 handle
, smid
, le16_to_cpu(mpi_reply
->IOCStatus
),
2894 le32_to_cpu(mpi_reply
->IOCLogInfo
),
2895 le32_to_cpu(mpi_reply
->TerminationCount
)));
2897 smid_sas_ctrl
= mpt2sas_base_get_smid(ioc
, ioc
->tm_sas_control_cb_idx
);
2898 if (!smid_sas_ctrl
) {
2899 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
2900 ioc
->name
, __func__
);
2904 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"sc_send:handle(0x%04x), "
2905 "(open), smid(%d), cb(%d)\n", ioc
->name
, handle
, smid_sas_ctrl
,
2906 ioc
->tm_sas_control_cb_idx
));
2907 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid_sas_ctrl
);
2908 memset(mpi_request
, 0, sizeof(Mpi2SasIoUnitControlRequest_t
));
2909 mpi_request
->Function
= MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
;
2910 mpi_request
->Operation
= MPI2_SAS_OP_REMOVE_DEVICE
;
2911 mpi_request
->DevHandle
= mpi_request_tm
->DevHandle
;
2912 mpt2sas_base_put_smid_default(ioc
, smid_sas_ctrl
);
2914 return _scsih_check_for_pending_tm(ioc
, smid
);
2918 * _scsih_check_for_pending_tm - check for pending task management
2919 * @ioc: per adapter object
2920 * @smid: system request message index
2922 * This will check delayed target reset list, and feed the
2925 * Return 1 meaning mf should be freed from _base_interrupt
2926 * 0 means the mf is freed from this function.
2929 _scsih_check_for_pending_tm(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
2931 struct _tr_list
*delayed_tr
;
2933 if (!list_empty(&ioc
->delayed_tr_volume_list
)) {
2934 delayed_tr
= list_entry(ioc
->delayed_tr_volume_list
.next
,
2935 struct _tr_list
, list
);
2936 mpt2sas_base_free_smid(ioc
, smid
);
2937 _scsih_tm_tr_volume_send(ioc
, delayed_tr
->handle
);
2938 list_del(&delayed_tr
->list
);
2943 if (!list_empty(&ioc
->delayed_tr_list
)) {
2944 delayed_tr
= list_entry(ioc
->delayed_tr_list
.next
,
2945 struct _tr_list
, list
);
2946 mpt2sas_base_free_smid(ioc
, smid
);
2947 _scsih_tm_tr_send(ioc
, delayed_tr
->handle
);
2948 list_del(&delayed_tr
->list
);
2957 * _scsih_check_topo_delete_events - sanity check on topo events
2958 * @ioc: per adapter object
2959 * @event_data: the event data payload
2961 * This routine added to better handle cable breaker.
2963 * This handles the case where driver recieves multiple expander
2964 * add and delete events in a single shot. When there is a delete event
2965 * the routine will void any pending add events waiting in the event queue.
2970 _scsih_check_topo_delete_events(struct MPT2SAS_ADAPTER
*ioc
,
2971 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
2973 struct fw_event_work
*fw_event
;
2974 Mpi2EventDataSasTopologyChangeList_t
*local_event_data
;
2975 u16 expander_handle
;
2976 struct _sas_node
*sas_expander
;
2977 unsigned long flags
;
2981 for (i
= 0 ; i
< event_data
->NumEntries
; i
++) {
2982 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
2985 reason_code
= event_data
->PHY
[i
].PhyStatus
&
2986 MPI2_EVENT_SAS_TOPO_RC_MASK
;
2987 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
)
2988 _scsih_tm_tr_send(ioc
, handle
);
2991 expander_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
2992 if (expander_handle
< ioc
->sas_hba
.num_phys
) {
2993 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
2997 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
2998 || event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
) {
2999 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
3000 sas_expander
= mpt2sas_scsih_expander_find_by_handle(ioc
,
3002 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
3003 _scsih_block_io_to_children_attached_to_ex(ioc
, sas_expander
);
3004 } else if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_RESPONDING
)
3005 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
3007 if (event_data
->ExpStatus
!= MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
)
3010 /* mark ignore flag for pending events */
3011 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
3012 list_for_each_entry(fw_event
, &ioc
->fw_event_list
, list
) {
3013 if (fw_event
->event
!= MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
||
3016 local_event_data
= fw_event
->event_data
;
3017 if (local_event_data
->ExpStatus
==
3018 MPI2_EVENT_SAS_TOPO_ES_ADDED
||
3019 local_event_data
->ExpStatus
==
3020 MPI2_EVENT_SAS_TOPO_ES_RESPONDING
) {
3021 if (le16_to_cpu(local_event_data
->ExpanderDevHandle
) ==
3023 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3024 "setting ignoring flag\n", ioc
->name
));
3025 fw_event
->ignore
= 1;
3029 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
3033 * _scsih_set_volume_delete_flag - setting volume delete flag
3034 * @ioc: per adapter object
3035 * @handle: device handle
3041 _scsih_set_volume_delete_flag(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
3043 struct _raid_device
*raid_device
;
3044 struct MPT2SAS_TARGET
*sas_target_priv_data
;
3045 unsigned long flags
;
3047 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
3048 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
3049 if (raid_device
&& raid_device
->starget
&&
3050 raid_device
->starget
->hostdata
) {
3051 sas_target_priv_data
=
3052 raid_device
->starget
->hostdata
;
3053 sas_target_priv_data
->deleted
= 1;
3054 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3055 "setting delete flag: handle(0x%04x), "
3056 "wwid(0x%016llx)\n", ioc
->name
, handle
,
3057 (unsigned long long) raid_device
->wwid
));
3059 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
3063 * _scsih_set_volume_handle_for_tr - set handle for target reset to volume
3064 * @handle: input handle
3065 * @a: handle for volume a
3066 * @b: handle for volume b
3068 * IR firmware only supports two raid volumes. The purpose of this
3069 * routine is to set the volume handle in either a or b. When the given
3070 * input handle is non-zero, or when a and b have not been set before.
3073 _scsih_set_volume_handle_for_tr(u16 handle
, u16
*a
, u16
*b
)
3075 if (!handle
|| handle
== *a
|| handle
== *b
)
3084 * _scsih_check_ir_config_unhide_events - check for UNHIDE events
3085 * @ioc: per adapter object
3086 * @event_data: the event data payload
3087 * Context: interrupt time.
3089 * This routine will send target reset to volume, followed by target
3090 * resets to the PDs. This is called when a PD has been removed, or
3091 * volume has been deleted or removed. When the target reset is sent
3092 * to volume, the PD target resets need to be queued to start upon
3093 * completion of the volume target reset.
3098 _scsih_check_ir_config_unhide_events(struct MPT2SAS_ADAPTER
*ioc
,
3099 Mpi2EventDataIrConfigChangeList_t
*event_data
)
3101 Mpi2EventIrConfigElement_t
*element
;
3103 u16 handle
, volume_handle
, a
, b
;
3104 struct _tr_list
*delayed_tr
;
3109 /* Volume Resets for Deleted or Removed */
3110 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
3111 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
3112 if (element
->ReasonCode
==
3113 MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
||
3114 element
->ReasonCode
==
3115 MPI2_EVENT_IR_CHANGE_RC_REMOVED
) {
3116 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
3117 _scsih_set_volume_delete_flag(ioc
, volume_handle
);
3118 _scsih_set_volume_handle_for_tr(volume_handle
, &a
, &b
);
3122 /* Volume Resets for UNHIDE events */
3123 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
3124 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
3125 if (le32_to_cpu(event_data
->Flags
) &
3126 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
)
3128 if (element
->ReasonCode
== MPI2_EVENT_IR_CHANGE_RC_UNHIDE
) {
3129 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
3130 _scsih_set_volume_handle_for_tr(volume_handle
, &a
, &b
);
3135 _scsih_tm_tr_volume_send(ioc
, a
);
3137 _scsih_tm_tr_volume_send(ioc
, b
);
3139 /* PD target resets */
3140 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
3141 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
3142 if (element
->ReasonCode
!= MPI2_EVENT_IR_CHANGE_RC_UNHIDE
)
3144 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
3145 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
3146 clear_bit(handle
, ioc
->pd_handles
);
3148 _scsih_tm_tr_send(ioc
, handle
);
3149 else if (volume_handle
== a
|| volume_handle
== b
) {
3150 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
3151 BUG_ON(!delayed_tr
);
3152 INIT_LIST_HEAD(&delayed_tr
->list
);
3153 delayed_tr
->handle
= handle
;
3154 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_list
);
3155 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3156 "DELAYED:tr:handle(0x%04x), (open)\n", ioc
->name
,
3159 _scsih_tm_tr_send(ioc
, handle
);
3165 * _scsih_check_volume_delete_events - set delete flag for volumes
3166 * @ioc: per adapter object
3167 * @event_data: the event data payload
3168 * Context: interrupt time.
3170 * This will handle the case when the cable connected to entire volume is
3171 * pulled. We will take care of setting the deleted flag so normal IO will
3177 _scsih_check_volume_delete_events(struct MPT2SAS_ADAPTER
*ioc
,
3178 Mpi2EventDataIrVolume_t
*event_data
)
3182 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED
)
3184 state
= le32_to_cpu(event_data
->NewValue
);
3185 if (state
== MPI2_RAID_VOL_STATE_MISSING
|| state
==
3186 MPI2_RAID_VOL_STATE_FAILED
)
3187 _scsih_set_volume_delete_flag(ioc
,
3188 le16_to_cpu(event_data
->VolDevHandle
));
3192 * _scsih_flush_running_cmds - completing outstanding commands.
3193 * @ioc: per adapter object
3195 * The flushing out of all pending scmd commands following host reset,
3196 * where all IO is dropped to the floor.
3201 _scsih_flush_running_cmds(struct MPT2SAS_ADAPTER
*ioc
)
3203 struct scsi_cmnd
*scmd
;
3207 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
3208 scmd
= _scsih_scsi_lookup_get_clear(ioc
, smid
);
3212 mpt2sas_base_free_smid(ioc
, smid
);
3213 scsi_dma_unmap(scmd
);
3214 if (ioc
->pci_error_recovery
)
3215 scmd
->result
= DID_NO_CONNECT
<< 16;
3217 scmd
->result
= DID_RESET
<< 16;
3218 scmd
->scsi_done(scmd
);
3220 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"completing %d cmds\n",
3225 * _scsih_setup_eedp - setup MPI request for EEDP transfer
3226 * @scmd: pointer to scsi command object
3227 * @mpi_request: pointer to the SCSI_IO reqest message frame
3229 * Supporting protection 1 and 3.
3234 _scsih_setup_eedp(struct scsi_cmnd
*scmd
, Mpi2SCSIIORequest_t
*mpi_request
)
3237 unsigned char prot_op
= scsi_get_prot_op(scmd
);
3238 unsigned char prot_type
= scsi_get_prot_type(scmd
);
3240 if (prot_type
== SCSI_PROT_DIF_TYPE0
|| prot_op
== SCSI_PROT_NORMAL
)
3243 if (prot_op
== SCSI_PROT_READ_STRIP
)
3244 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP
;
3245 else if (prot_op
== SCSI_PROT_WRITE_INSERT
)
3246 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_INSERT_OP
;
3250 switch (prot_type
) {
3251 case SCSI_PROT_DIF_TYPE1
:
3254 * enable ref/guard checking
3255 * auto increment ref tag
3257 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG
|
3258 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG
|
3259 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
3260 mpi_request
->CDB
.EEDP32
.PrimaryReferenceTag
=
3261 cpu_to_be32(scsi_get_lba(scmd
));
3264 case SCSI_PROT_DIF_TYPE2
:
3266 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG
|
3267 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG
|
3268 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
3271 case SCSI_PROT_DIF_TYPE3
:
3274 * enable guard checking
3276 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
3279 mpi_request
->EEDPBlockSize
= cpu_to_le32(scmd
->device
->sector_size
);
3280 mpi_request
->EEDPFlags
= cpu_to_le16(eedp_flags
);
3284 * _scsih_eedp_error_handling - return sense code for EEDP errors
3285 * @scmd: pointer to scsi command object
3286 * @ioc_status: ioc status
3291 _scsih_eedp_error_handling(struct scsi_cmnd
*scmd
, u16 ioc_status
)
3297 switch (ioc_status
) {
3298 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
3301 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
3304 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
3312 if (scmd
->sc_data_direction
== DMA_TO_DEVICE
) {
3313 sk
= ILLEGAL_REQUEST
;
3314 host_byte
= DID_ABORT
;
3316 sk
= ABORTED_COMMAND
;
3320 scsi_build_sense_buffer(0, scmd
->sense_buffer
, sk
, 0x10, ascq
);
3321 scmd
->result
= DRIVER_SENSE
<< 24 | (host_byte
<< 16) |
3322 SAM_STAT_CHECK_CONDITION
;
3326 * _scsih_qcmd - main scsi request entry point
3327 * @scmd: pointer to scsi command object
3328 * @done: function pointer to be invoked on completion
3330 * The callback index is set inside `ioc->scsi_io_cb_idx`.
3332 * Returns 0 on success. If there's a failure, return either:
3333 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
3334 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
3337 _scsih_qcmd(struct scsi_cmnd
*scmd
, void (*done
)(struct scsi_cmnd
*))
3339 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
3340 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
3341 struct MPT2SAS_TARGET
*sas_target_priv_data
;
3342 Mpi2SCSIIORequest_t
*mpi_request
;
3346 scmd
->scsi_done
= done
;
3347 sas_device_priv_data
= scmd
->device
->hostdata
;
3348 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
3349 scmd
->result
= DID_NO_CONNECT
<< 16;
3350 scmd
->scsi_done(scmd
);
3354 if (ioc
->pci_error_recovery
) {
3355 scmd
->result
= DID_NO_CONNECT
<< 16;
3356 scmd
->scsi_done(scmd
);
3360 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
3361 /* invalid device handle */
3362 if (sas_target_priv_data
->handle
== MPT2SAS_INVALID_DEVICE_HANDLE
) {
3363 scmd
->result
= DID_NO_CONNECT
<< 16;
3364 scmd
->scsi_done(scmd
);
3368 /* host recovery or link resets sent via IOCTLs */
3369 if (ioc
->shost_recovery
|| ioc
->ioc_link_reset_in_progress
)
3370 return SCSI_MLQUEUE_HOST_BUSY
;
3371 /* device busy with task management */
3372 else if (sas_device_priv_data
->block
|| sas_target_priv_data
->tm_busy
)
3373 return SCSI_MLQUEUE_DEVICE_BUSY
;
3374 /* device has been deleted */
3375 else if (sas_target_priv_data
->deleted
) {
3376 scmd
->result
= DID_NO_CONNECT
<< 16;
3377 scmd
->scsi_done(scmd
);
3381 if (scmd
->sc_data_direction
== DMA_FROM_DEVICE
)
3382 mpi_control
= MPI2_SCSIIO_CONTROL_READ
;
3383 else if (scmd
->sc_data_direction
== DMA_TO_DEVICE
)
3384 mpi_control
= MPI2_SCSIIO_CONTROL_WRITE
;
3386 mpi_control
= MPI2_SCSIIO_CONTROL_NODATATRANSFER
;
3389 if (!(sas_device_priv_data
->flags
& MPT_DEVICE_FLAGS_INIT
)) {
3390 if (scmd
->device
->tagged_supported
) {
3391 if (scmd
->device
->ordered_tags
)
3392 mpi_control
|= MPI2_SCSIIO_CONTROL_ORDEREDQ
;
3394 mpi_control
|= MPI2_SCSIIO_CONTROL_SIMPLEQ
;
3396 /* MPI Revision I (UNIT = 0xA) - removed MPI2_SCSIIO_CONTROL_UNTAGGED */
3397 /* mpi_control |= MPI2_SCSIIO_CONTROL_UNTAGGED;
3399 mpi_control
|= (0x500);
3402 mpi_control
|= MPI2_SCSIIO_CONTROL_SIMPLEQ
;
3403 /* Make sure Device is not raid volume */
3404 if (!_scsih_is_raid(&scmd
->device
->sdev_gendev
) &&
3405 sas_is_tlr_enabled(scmd
->device
) && scmd
->cmd_len
!= 32)
3406 mpi_control
|= MPI2_SCSIIO_CONTROL_TLR_ON
;
3408 smid
= mpt2sas_base_get_smid_scsiio(ioc
, ioc
->scsi_io_cb_idx
, scmd
);
3410 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
3411 ioc
->name
, __func__
);
3414 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3415 memset(mpi_request
, 0, sizeof(Mpi2SCSIIORequest_t
));
3416 _scsih_setup_eedp(scmd
, mpi_request
);
3417 if (scmd
->cmd_len
== 32)
3418 mpi_control
|= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT
;
3419 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
3420 if (sas_device_priv_data
->sas_target
->flags
&
3421 MPT_TARGET_FLAGS_RAID_COMPONENT
)
3422 mpi_request
->Function
= MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
;
3424 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
3425 mpi_request
->DevHandle
=
3426 cpu_to_le16(sas_device_priv_data
->sas_target
->handle
);
3427 mpi_request
->DataLength
= cpu_to_le32(scsi_bufflen(scmd
));
3428 mpi_request
->Control
= cpu_to_le32(mpi_control
);
3429 mpi_request
->IoFlags
= cpu_to_le16(scmd
->cmd_len
);
3430 mpi_request
->MsgFlags
= MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR
;
3431 mpi_request
->SenseBufferLength
= SCSI_SENSE_BUFFERSIZE
;
3432 mpi_request
->SenseBufferLowAddress
=
3433 mpt2sas_base_get_sense_buffer_dma(ioc
, smid
);
3434 mpi_request
->SGLOffset0
= offsetof(Mpi2SCSIIORequest_t
, SGL
) / 4;
3435 mpi_request
->SGLFlags
= cpu_to_le16(MPI2_SCSIIO_SGLFLAGS_TYPE_MPI
+
3436 MPI2_SCSIIO_SGLFLAGS_SYSTEM_ADDR
);
3437 mpi_request
->VF_ID
= 0; /* TODO */
3438 mpi_request
->VP_ID
= 0;
3439 int_to_scsilun(sas_device_priv_data
->lun
, (struct scsi_lun
*)
3441 memcpy(mpi_request
->CDB
.CDB32
, scmd
->cmnd
, scmd
->cmd_len
);
3443 if (!mpi_request
->DataLength
) {
3444 mpt2sas_base_build_zero_len_sge(ioc
, &mpi_request
->SGL
);
3446 if (_scsih_build_scatter_gather(ioc
, scmd
, smid
)) {
3447 mpt2sas_base_free_smid(ioc
, smid
);
3452 if (likely(mpi_request
->Function
== MPI2_FUNCTION_SCSI_IO_REQUEST
))
3453 mpt2sas_base_put_smid_scsi_io(ioc
, smid
,
3454 sas_device_priv_data
->sas_target
->handle
);
3456 mpt2sas_base_put_smid_default(ioc
, smid
);
3460 return SCSI_MLQUEUE_HOST_BUSY
;
3464 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
3465 * @sense_buffer: sense data returned by target
3466 * @data: normalized skey/asc/ascq
3471 _scsih_normalize_sense(char *sense_buffer
, struct sense_info
*data
)
3473 if ((sense_buffer
[0] & 0x7F) >= 0x72) {
3474 /* descriptor format */
3475 data
->skey
= sense_buffer
[1] & 0x0F;
3476 data
->asc
= sense_buffer
[2];
3477 data
->ascq
= sense_buffer
[3];
3480 data
->skey
= sense_buffer
[2] & 0x0F;
3481 data
->asc
= sense_buffer
[12];
3482 data
->ascq
= sense_buffer
[13];
3486 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3488 * _scsih_scsi_ioc_info - translated non-successfull SCSI_IO request
3489 * @ioc: per adapter object
3490 * @scmd: pointer to scsi command object
3491 * @mpi_reply: reply mf payload returned from firmware
3493 * scsi_status - SCSI Status code returned from target device
3494 * scsi_state - state info associated with SCSI_IO determined by ioc
3495 * ioc_status - ioc supplied status info
3500 _scsih_scsi_ioc_info(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
,
3501 Mpi2SCSIIOReply_t
*mpi_reply
, u16 smid
)
3505 u16 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) &
3506 MPI2_IOCSTATUS_MASK
;
3507 u8 scsi_state
= mpi_reply
->SCSIState
;
3508 u8 scsi_status
= mpi_reply
->SCSIStatus
;
3509 char *desc_ioc_state
= NULL
;
3510 char *desc_scsi_status
= NULL
;
3511 char *desc_scsi_state
= ioc
->tmp_string
;
3512 u32 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
3513 struct _sas_device
*sas_device
= NULL
;
3514 unsigned long flags
;
3515 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
3516 struct MPT2SAS_TARGET
*priv_target
= starget
->hostdata
;
3521 if (log_info
== 0x31170000)
3524 switch (ioc_status
) {
3525 case MPI2_IOCSTATUS_SUCCESS
:
3526 desc_ioc_state
= "success";
3528 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
3529 desc_ioc_state
= "invalid function";
3531 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
3532 desc_ioc_state
= "scsi recovered error";
3534 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE
:
3535 desc_ioc_state
= "scsi invalid dev handle";
3537 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
3538 desc_ioc_state
= "scsi device not there";
3540 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
3541 desc_ioc_state
= "scsi data overrun";
3543 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
3544 desc_ioc_state
= "scsi data underrun";
3546 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
3547 desc_ioc_state
= "scsi io data error";
3549 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
3550 desc_ioc_state
= "scsi protocol error";
3552 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
3553 desc_ioc_state
= "scsi task terminated";
3555 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
3556 desc_ioc_state
= "scsi residual mismatch";
3558 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
3559 desc_ioc_state
= "scsi task mgmt failed";
3561 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
3562 desc_ioc_state
= "scsi ioc terminated";
3564 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
3565 desc_ioc_state
= "scsi ext terminated";
3567 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
3568 desc_ioc_state
= "eedp guard error";
3570 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
3571 desc_ioc_state
= "eedp ref tag error";
3573 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
3574 desc_ioc_state
= "eedp app tag error";
3577 desc_ioc_state
= "unknown";
3581 switch (scsi_status
) {
3582 case MPI2_SCSI_STATUS_GOOD
:
3583 desc_scsi_status
= "good";
3585 case MPI2_SCSI_STATUS_CHECK_CONDITION
:
3586 desc_scsi_status
= "check condition";
3588 case MPI2_SCSI_STATUS_CONDITION_MET
:
3589 desc_scsi_status
= "condition met";
3591 case MPI2_SCSI_STATUS_BUSY
:
3592 desc_scsi_status
= "busy";
3594 case MPI2_SCSI_STATUS_INTERMEDIATE
:
3595 desc_scsi_status
= "intermediate";
3597 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET
:
3598 desc_scsi_status
= "intermediate condmet";
3600 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT
:
3601 desc_scsi_status
= "reservation conflict";
3603 case MPI2_SCSI_STATUS_COMMAND_TERMINATED
:
3604 desc_scsi_status
= "command terminated";
3606 case MPI2_SCSI_STATUS_TASK_SET_FULL
:
3607 desc_scsi_status
= "task set full";
3609 case MPI2_SCSI_STATUS_ACA_ACTIVE
:
3610 desc_scsi_status
= "aca active";
3612 case MPI2_SCSI_STATUS_TASK_ABORTED
:
3613 desc_scsi_status
= "task aborted";
3616 desc_scsi_status
= "unknown";
3620 desc_scsi_state
[0] = '\0';
3622 desc_scsi_state
= " ";
3623 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
3624 strcat(desc_scsi_state
, "response info ");
3625 if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
3626 strcat(desc_scsi_state
, "state terminated ");
3627 if (scsi_state
& MPI2_SCSI_STATE_NO_SCSI_STATUS
)
3628 strcat(desc_scsi_state
, "no status ");
3629 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_FAILED
)
3630 strcat(desc_scsi_state
, "autosense failed ");
3631 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
)
3632 strcat(desc_scsi_state
, "autosense valid ");
3634 scsi_print_command(scmd
);
3636 if (priv_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
3637 printk(MPT2SAS_WARN_FMT
"\tvolume wwid(0x%016llx)\n", ioc
->name
,
3638 (unsigned long long)priv_target
->sas_address
);
3640 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
3641 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
3642 priv_target
->sas_address
);
3644 printk(MPT2SAS_WARN_FMT
"\tsas_address(0x%016llx), "
3645 "phy(%d)\n", ioc
->name
, sas_device
->sas_address
,
3647 printk(MPT2SAS_WARN_FMT
3648 "\tenclosure_logical_id(0x%016llx), slot(%d)\n",
3649 ioc
->name
, sas_device
->enclosure_logical_id
,
3652 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3655 printk(MPT2SAS_WARN_FMT
"\thandle(0x%04x), ioc_status(%s)(0x%04x), "
3656 "smid(%d)\n", ioc
->name
, le16_to_cpu(mpi_reply
->DevHandle
),
3657 desc_ioc_state
, ioc_status
, smid
);
3658 printk(MPT2SAS_WARN_FMT
"\trequest_len(%d), underflow(%d), "
3659 "resid(%d)\n", ioc
->name
, scsi_bufflen(scmd
), scmd
->underflow
,
3660 scsi_get_resid(scmd
));
3661 printk(MPT2SAS_WARN_FMT
"\ttag(%d), transfer_count(%d), "
3662 "sc->result(0x%08x)\n", ioc
->name
, le16_to_cpu(mpi_reply
->TaskTag
),
3663 le32_to_cpu(mpi_reply
->TransferCount
), scmd
->result
);
3664 printk(MPT2SAS_WARN_FMT
"\tscsi_status(%s)(0x%02x), "
3665 "scsi_state(%s)(0x%02x)\n", ioc
->name
, desc_scsi_status
,
3666 scsi_status
, desc_scsi_state
, scsi_state
);
3668 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
3669 struct sense_info data
;
3670 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
3671 printk(MPT2SAS_WARN_FMT
"\t[sense_key,asc,ascq]: "
3672 "[0x%02x,0x%02x,0x%02x], count(%d)\n", ioc
->name
, data
.skey
,
3673 data
.asc
, data
.ascq
, le32_to_cpu(mpi_reply
->SenseCount
));
3676 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
) {
3677 response_info
= le32_to_cpu(mpi_reply
->ResponseInfo
);
3678 response_bytes
= (u8
*)&response_info
;
3679 _scsih_response_code(ioc
, response_bytes
[0]);
3685 * _scsih_smart_predicted_fault - illuminate Fault LED
3686 * @ioc: per adapter object
3687 * @handle: device handle
3692 _scsih_smart_predicted_fault(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
3694 Mpi2SepReply_t mpi_reply
;
3695 Mpi2SepRequest_t mpi_request
;
3696 struct scsi_target
*starget
;
3697 struct MPT2SAS_TARGET
*sas_target_priv_data
;
3698 Mpi2EventNotificationReply_t
*event_reply
;
3699 Mpi2EventDataSasDeviceStatusChange_t
*event_data
;
3700 struct _sas_device
*sas_device
;
3702 unsigned long flags
;
3704 /* only handle non-raid devices */
3705 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
3706 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
3708 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3711 starget
= sas_device
->starget
;
3712 sas_target_priv_data
= starget
->hostdata
;
3714 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
) ||
3715 ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
))) {
3716 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3719 starget_printk(KERN_WARNING
, starget
, "predicted fault\n");
3720 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3722 if (ioc
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_IBM
) {
3723 memset(&mpi_request
, 0, sizeof(Mpi2SepRequest_t
));
3724 mpi_request
.Function
= MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR
;
3725 mpi_request
.Action
= MPI2_SEP_REQ_ACTION_WRITE_STATUS
;
3726 mpi_request
.SlotStatus
=
3727 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT
);
3728 mpi_request
.DevHandle
= cpu_to_le16(handle
);
3729 mpi_request
.Flags
= MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS
;
3730 if ((mpt2sas_base_scsi_enclosure_processor(ioc
, &mpi_reply
,
3731 &mpi_request
)) != 0) {
3732 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3733 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3737 if (mpi_reply
.IOCStatus
|| mpi_reply
.IOCLogInfo
) {
3738 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3739 "enclosure_processor: ioc_status (0x%04x), "
3740 "loginfo(0x%08x)\n", ioc
->name
,
3741 le16_to_cpu(mpi_reply
.IOCStatus
),
3742 le32_to_cpu(mpi_reply
.IOCLogInfo
)));
3747 /* insert into event log */
3748 sz
= offsetof(Mpi2EventNotificationReply_t
, EventData
) +
3749 sizeof(Mpi2EventDataSasDeviceStatusChange_t
);
3750 event_reply
= kzalloc(sz
, GFP_KERNEL
);
3752 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3753 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3757 event_reply
->Function
= MPI2_FUNCTION_EVENT_NOTIFICATION
;
3758 event_reply
->Event
=
3759 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
);
3760 event_reply
->MsgLength
= sz
/4;
3761 event_reply
->EventDataLength
=
3762 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t
)/4);
3763 event_data
= (Mpi2EventDataSasDeviceStatusChange_t
*)
3764 event_reply
->EventData
;
3765 event_data
->ReasonCode
= MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
;
3766 event_data
->ASC
= 0x5D;
3767 event_data
->DevHandle
= cpu_to_le16(handle
);
3768 event_data
->SASAddress
= cpu_to_le64(sas_target_priv_data
->sas_address
);
3769 mpt2sas_ctl_add_to_event_log(ioc
, event_reply
);
3774 * _scsih_io_done - scsi request callback
3775 * @ioc: per adapter object
3776 * @smid: system request message index
3777 * @msix_index: MSIX table index supplied by the OS
3778 * @reply: reply message frame(lower 32bit addr)
3780 * Callback handler when using _scsih_qcmd.
3782 * Return 1 meaning mf should be freed from _base_interrupt
3783 * 0 means the mf is freed from this function.
3786 _scsih_io_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
3788 Mpi2SCSIIORequest_t
*mpi_request
;
3789 Mpi2SCSIIOReply_t
*mpi_reply
;
3790 struct scsi_cmnd
*scmd
;
3796 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
3797 u32 response_code
= 0;
3799 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
3800 scmd
= _scsih_scsi_lookup_get_clear(ioc
, smid
);
3804 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3806 if (mpi_reply
== NULL
) {
3807 scmd
->result
= DID_OK
<< 16;
3811 sas_device_priv_data
= scmd
->device
->hostdata
;
3812 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
||
3813 sas_device_priv_data
->sas_target
->deleted
) {
3814 scmd
->result
= DID_NO_CONNECT
<< 16;
3818 /* turning off TLR */
3819 scsi_state
= mpi_reply
->SCSIState
;
3820 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
3822 le32_to_cpu(mpi_reply
->ResponseInfo
) & 0xFF;
3823 if (!sas_device_priv_data
->tlr_snoop_check
) {
3824 sas_device_priv_data
->tlr_snoop_check
++;
3825 if (!_scsih_is_raid(&scmd
->device
->sdev_gendev
) &&
3826 sas_is_tlr_enabled(scmd
->device
) &&
3827 response_code
== MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
) {
3828 sas_disable_tlr(scmd
->device
);
3829 sdev_printk(KERN_INFO
, scmd
->device
, "TLR disabled\n");
3833 xfer_cnt
= le32_to_cpu(mpi_reply
->TransferCount
);
3834 scsi_set_resid(scmd
, scsi_bufflen(scmd
) - xfer_cnt
);
3835 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
);
3836 if (ioc_status
& MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE
)
3837 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
3840 ioc_status
&= MPI2_IOCSTATUS_MASK
;
3841 scsi_status
= mpi_reply
->SCSIStatus
;
3843 if (ioc_status
== MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
&& xfer_cnt
== 0 &&
3844 (scsi_status
== MPI2_SCSI_STATUS_BUSY
||
3845 scsi_status
== MPI2_SCSI_STATUS_RESERVATION_CONFLICT
||
3846 scsi_status
== MPI2_SCSI_STATUS_TASK_SET_FULL
)) {
3847 ioc_status
= MPI2_IOCSTATUS_SUCCESS
;
3850 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
3851 struct sense_info data
;
3852 const void *sense_data
= mpt2sas_base_get_sense_buffer(ioc
,
3854 u32 sz
= min_t(u32
, SCSI_SENSE_BUFFERSIZE
,
3855 le32_to_cpu(mpi_reply
->SenseCount
));
3856 memcpy(scmd
->sense_buffer
, sense_data
, sz
);
3857 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
3858 /* failure prediction threshold exceeded */
3859 if (data
.asc
== 0x5D)
3860 _scsih_smart_predicted_fault(ioc
,
3861 le16_to_cpu(mpi_reply
->DevHandle
));
3864 switch (ioc_status
) {
3865 case MPI2_IOCSTATUS_BUSY
:
3866 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES
:
3867 scmd
->result
= SAM_STAT_BUSY
;
3870 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
3871 scmd
->result
= DID_NO_CONNECT
<< 16;
3874 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
3875 if (sas_device_priv_data
->block
) {
3876 scmd
->result
= DID_TRANSPORT_DISRUPTED
<< 16;
3879 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
3880 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
3881 scmd
->result
= DID_RESET
<< 16;
3884 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
3885 if ((xfer_cnt
== 0) || (scmd
->underflow
> xfer_cnt
))
3886 scmd
->result
= DID_SOFT_ERROR
<< 16;
3888 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
3891 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
3892 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
3894 if ((scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
))
3897 if (xfer_cnt
< scmd
->underflow
) {
3898 if (scsi_status
== SAM_STAT_BUSY
)
3899 scmd
->result
= SAM_STAT_BUSY
;
3901 scmd
->result
= DID_SOFT_ERROR
<< 16;
3902 } else if (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
3903 MPI2_SCSI_STATE_NO_SCSI_STATUS
))
3904 scmd
->result
= DID_SOFT_ERROR
<< 16;
3905 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
3906 scmd
->result
= DID_RESET
<< 16;
3907 else if (!xfer_cnt
&& scmd
->cmnd
[0] == REPORT_LUNS
) {
3908 mpi_reply
->SCSIState
= MPI2_SCSI_STATE_AUTOSENSE_VALID
;
3909 mpi_reply
->SCSIStatus
= SAM_STAT_CHECK_CONDITION
;
3910 scmd
->result
= (DRIVER_SENSE
<< 24) |
3911 SAM_STAT_CHECK_CONDITION
;
3912 scmd
->sense_buffer
[0] = 0x70;
3913 scmd
->sense_buffer
[2] = ILLEGAL_REQUEST
;
3914 scmd
->sense_buffer
[12] = 0x20;
3915 scmd
->sense_buffer
[13] = 0;
3919 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
3920 scsi_set_resid(scmd
, 0);
3921 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
3922 case MPI2_IOCSTATUS_SUCCESS
:
3923 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
3924 if (response_code
==
3925 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
||
3926 (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
3927 MPI2_SCSI_STATE_NO_SCSI_STATUS
)))
3928 scmd
->result
= DID_SOFT_ERROR
<< 16;
3929 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
3930 scmd
->result
= DID_RESET
<< 16;
3933 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
3934 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
3935 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
3936 _scsih_eedp_error_handling(scmd
, ioc_status
);
3938 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
3939 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
3940 case MPI2_IOCSTATUS_INVALID_SGL
:
3941 case MPI2_IOCSTATUS_INTERNAL_ERROR
:
3942 case MPI2_IOCSTATUS_INVALID_FIELD
:
3943 case MPI2_IOCSTATUS_INVALID_STATE
:
3944 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
3945 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
3947 scmd
->result
= DID_SOFT_ERROR
<< 16;
3952 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3953 if (scmd
->result
&& (ioc
->logging_level
& MPT_DEBUG_REPLY
))
3954 _scsih_scsi_ioc_info(ioc
, scmd
, mpi_reply
, smid
);
3958 scsi_dma_unmap(scmd
);
3959 scmd
->scsi_done(scmd
);
3964 * _scsih_sas_host_refresh - refreshing sas host object contents
3965 * @ioc: per adapter object
3968 * During port enable, fw will send topology events for every device. Its
3969 * possible that the handles may change from the previous setting, so this
3970 * code keeping handles updating if changed.
3975 _scsih_sas_host_refresh(struct MPT2SAS_ADAPTER
*ioc
)
3980 Mpi2ConfigReply_t mpi_reply
;
3981 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
3982 u16 attached_handle
;
3984 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
3985 "updating handles for sas_host(0x%016llx)\n",
3986 ioc
->name
, (unsigned long long)ioc
->sas_hba
.sas_address
));
3988 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
3989 * sizeof(Mpi2SasIOUnit0PhyData_t
));
3990 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
3991 if (!sas_iounit_pg0
) {
3992 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3993 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3997 if ((mpt2sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
3998 sas_iounit_pg0
, sz
)) != 0)
4000 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
4001 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
4003 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
4005 ioc
->sas_hba
.handle
= le16_to_cpu(sas_iounit_pg0
->
4006 PhyData
[0].ControllerDevHandle
);
4007 ioc
->sas_hba
.phy
[i
].handle
= ioc
->sas_hba
.handle
;
4008 attached_handle
= le16_to_cpu(sas_iounit_pg0
->PhyData
[i
].
4010 mpt2sas_transport_update_links(ioc
, ioc
->sas_hba
.sas_address
,
4011 attached_handle
, i
, sas_iounit_pg0
->PhyData
[i
].
4012 NegotiatedLinkRate
>> 4);
4015 kfree(sas_iounit_pg0
);
4019 * _scsih_sas_host_add - create sas host object
4020 * @ioc: per adapter object
4022 * Creating host side data object, stored in ioc->sas_hba
4027 _scsih_sas_host_add(struct MPT2SAS_ADAPTER
*ioc
)
4030 Mpi2ConfigReply_t mpi_reply
;
4031 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
4032 Mpi2SasIOUnitPage1_t
*sas_iounit_pg1
= NULL
;
4033 Mpi2SasPhyPage0_t phy_pg0
;
4034 Mpi2SasDevicePage0_t sas_device_pg0
;
4035 Mpi2SasEnclosurePage0_t enclosure_pg0
;
4038 u16 device_missing_delay
;
4040 mpt2sas_config_get_number_hba_phys(ioc
, &ioc
->sas_hba
.num_phys
);
4041 if (!ioc
->sas_hba
.num_phys
) {
4042 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4043 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4047 /* sas_iounit page 0 */
4048 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
4049 sizeof(Mpi2SasIOUnit0PhyData_t
));
4050 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
4051 if (!sas_iounit_pg0
) {
4052 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4053 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4056 if ((mpt2sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
4057 sas_iounit_pg0
, sz
))) {
4058 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4059 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4062 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4063 MPI2_IOCSTATUS_MASK
;
4064 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4065 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4066 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4070 /* sas_iounit page 1 */
4071 sz
= offsetof(Mpi2SasIOUnitPage1_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
4072 sizeof(Mpi2SasIOUnit1PhyData_t
));
4073 sas_iounit_pg1
= kzalloc(sz
, GFP_KERNEL
);
4074 if (!sas_iounit_pg1
) {
4075 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4076 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4079 if ((mpt2sas_config_get_sas_iounit_pg1(ioc
, &mpi_reply
,
4080 sas_iounit_pg1
, sz
))) {
4081 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4082 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4085 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4086 MPI2_IOCSTATUS_MASK
;
4087 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4088 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4089 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4093 ioc
->io_missing_delay
=
4094 le16_to_cpu(sas_iounit_pg1
->IODeviceMissingDelay
);
4095 device_missing_delay
=
4096 le16_to_cpu(sas_iounit_pg1
->ReportDeviceMissingDelay
);
4097 if (device_missing_delay
& MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16
)
4098 ioc
->device_missing_delay
= (device_missing_delay
&
4099 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
) * 16;
4101 ioc
->device_missing_delay
= device_missing_delay
&
4102 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
;
4104 ioc
->sas_hba
.parent_dev
= &ioc
->shost
->shost_gendev
;
4105 ioc
->sas_hba
.phy
= kcalloc(ioc
->sas_hba
.num_phys
,
4106 sizeof(struct _sas_phy
), GFP_KERNEL
);
4107 if (!ioc
->sas_hba
.phy
) {
4108 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4109 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4112 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
4113 if ((mpt2sas_config_get_phy_pg0(ioc
, &mpi_reply
, &phy_pg0
,
4115 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4116 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4119 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4120 MPI2_IOCSTATUS_MASK
;
4121 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4122 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4123 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4128 ioc
->sas_hba
.handle
= le16_to_cpu(sas_iounit_pg0
->
4129 PhyData
[0].ControllerDevHandle
);
4130 ioc
->sas_hba
.phy
[i
].handle
= ioc
->sas_hba
.handle
;
4131 ioc
->sas_hba
.phy
[i
].phy_id
= i
;
4132 mpt2sas_transport_add_host_phy(ioc
, &ioc
->sas_hba
.phy
[i
],
4133 phy_pg0
, ioc
->sas_hba
.parent_dev
);
4135 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
4136 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, ioc
->sas_hba
.handle
))) {
4137 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4138 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4141 ioc
->sas_hba
.enclosure_handle
=
4142 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
4143 ioc
->sas_hba
.sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
4144 printk(MPT2SAS_INFO_FMT
"host_add: handle(0x%04x), "
4145 "sas_addr(0x%016llx), phys(%d)\n", ioc
->name
, ioc
->sas_hba
.handle
,
4146 (unsigned long long) ioc
->sas_hba
.sas_address
,
4147 ioc
->sas_hba
.num_phys
) ;
4149 if (ioc
->sas_hba
.enclosure_handle
) {
4150 if (!(mpt2sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
4152 MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
4153 ioc
->sas_hba
.enclosure_handle
))) {
4154 ioc
->sas_hba
.enclosure_logical_id
=
4155 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
4160 kfree(sas_iounit_pg1
);
4161 kfree(sas_iounit_pg0
);
4165 * _scsih_expander_add - creating expander object
4166 * @ioc: per adapter object
4167 * @handle: expander handle
4169 * Creating expander object, stored in ioc->sas_expander_list.
4171 * Return 0 for success, else error.
4174 _scsih_expander_add(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
4176 struct _sas_node
*sas_expander
;
4177 Mpi2ConfigReply_t mpi_reply
;
4178 Mpi2ExpanderPage0_t expander_pg0
;
4179 Mpi2ExpanderPage1_t expander_pg1
;
4180 Mpi2SasEnclosurePage0_t enclosure_pg0
;
4183 __le64 sas_address
, sas_address_parent
= 0;
4185 unsigned long flags
;
4186 struct _sas_port
*mpt2sas_port
= NULL
;
4192 if (ioc
->shost_recovery
|| ioc
->pci_error_recovery
)
4195 if ((mpt2sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
4196 MPI2_SAS_EXPAND_PGAD_FORM_HNDL
, handle
))) {
4197 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4198 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4202 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4203 MPI2_IOCSTATUS_MASK
;
4204 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4205 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4206 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4210 /* handle out of order topology events */
4211 parent_handle
= le16_to_cpu(expander_pg0
.ParentDevHandle
);
4212 if (_scsih_get_sas_address(ioc
, parent_handle
, &sas_address_parent
)
4214 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4215 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4218 if (sas_address_parent
!= ioc
->sas_hba
.sas_address
) {
4219 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
4220 sas_expander
= mpt2sas_scsih_expander_find_by_sas_address(ioc
,
4221 sas_address_parent
);
4222 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
4223 if (!sas_expander
) {
4224 rc
= _scsih_expander_add(ioc
, parent_handle
);
4230 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
4231 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
4232 sas_expander
= mpt2sas_scsih_expander_find_by_sas_address(ioc
,
4234 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
4239 sas_expander
= kzalloc(sizeof(struct _sas_node
),
4241 if (!sas_expander
) {
4242 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4243 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4247 sas_expander
->handle
= handle
;
4248 sas_expander
->num_phys
= expander_pg0
.NumPhys
;
4249 sas_expander
->sas_address_parent
= sas_address_parent
;
4250 sas_expander
->sas_address
= sas_address
;
4252 printk(MPT2SAS_INFO_FMT
"expander_add: handle(0x%04x),"
4253 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc
->name
,
4254 handle
, parent_handle
, (unsigned long long)
4255 sas_expander
->sas_address
, sas_expander
->num_phys
);
4257 if (!sas_expander
->num_phys
)
4259 sas_expander
->phy
= kcalloc(sas_expander
->num_phys
,
4260 sizeof(struct _sas_phy
), GFP_KERNEL
);
4261 if (!sas_expander
->phy
) {
4262 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4263 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4268 INIT_LIST_HEAD(&sas_expander
->sas_port_list
);
4269 mpt2sas_port
= mpt2sas_transport_port_add(ioc
, handle
,
4270 sas_address_parent
);
4271 if (!mpt2sas_port
) {
4272 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4273 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4277 sas_expander
->parent_dev
= &mpt2sas_port
->rphy
->dev
;
4279 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++) {
4280 if ((mpt2sas_config_get_expander_pg1(ioc
, &mpi_reply
,
4281 &expander_pg1
, i
, handle
))) {
4282 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4283 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4287 sas_expander
->phy
[i
].handle
= handle
;
4288 sas_expander
->phy
[i
].phy_id
= i
;
4290 if ((mpt2sas_transport_add_expander_phy(ioc
,
4291 &sas_expander
->phy
[i
], expander_pg1
,
4292 sas_expander
->parent_dev
))) {
4293 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4294 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4300 if (sas_expander
->enclosure_handle
) {
4301 if (!(mpt2sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
4302 &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
4303 sas_expander
->enclosure_handle
))) {
4304 sas_expander
->enclosure_logical_id
=
4305 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
4309 _scsih_expander_node_add(ioc
, sas_expander
);
4315 mpt2sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
4316 sas_address_parent
);
4317 kfree(sas_expander
);
4322 * _scsih_done - scsih callback handler.
4323 * @ioc: per adapter object
4324 * @smid: system request message index
4325 * @msix_index: MSIX table index supplied by the OS
4326 * @reply: reply message frame(lower 32bit addr)
4328 * Callback handler when sending internal generated message frames.
4329 * The callback index passed is `ioc->scsih_cb_idx`
4331 * Return 1 meaning mf should be freed from _base_interrupt
4332 * 0 means the mf is freed from this function.
4335 _scsih_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
4337 MPI2DefaultReply_t
*mpi_reply
;
4339 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
4340 if (ioc
->scsih_cmds
.status
== MPT2_CMD_NOT_USED
)
4342 if (ioc
->scsih_cmds
.smid
!= smid
)
4344 ioc
->scsih_cmds
.status
|= MPT2_CMD_COMPLETE
;
4346 memcpy(ioc
->scsih_cmds
.reply
, mpi_reply
,
4347 mpi_reply
->MsgLength
*4);
4348 ioc
->scsih_cmds
.status
|= MPT2_CMD_REPLY_VALID
;
4350 ioc
->scsih_cmds
.status
&= ~MPT2_CMD_PENDING
;
4351 complete(&ioc
->scsih_cmds
.done
);
4356 * _scsih_expander_remove - removing expander object
4357 * @ioc: per adapter object
4358 * @sas_address: expander sas_address
4363 _scsih_expander_remove(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
)
4365 struct _sas_node
*sas_expander
;
4366 unsigned long flags
;
4368 if (ioc
->shost_recovery
)
4371 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
4372 sas_expander
= mpt2sas_scsih_expander_find_by_sas_address(ioc
,
4374 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
4375 _scsih_expander_node_remove(ioc
, sas_expander
);
4379 * _scsih_check_access_status - check access flags
4380 * @ioc: per adapter object
4381 * @sas_address: sas address
4382 * @handle: sas device handle
4383 * @access_flags: errors returned during discovery of the device
4385 * Return 0 for success, else failure
4388 _scsih_check_access_status(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
,
4389 u16 handle
, u8 access_status
)
4394 switch (access_status
) {
4395 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS
:
4396 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION
:
4399 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED
:
4400 desc
= "sata capability failed";
4402 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT
:
4403 desc
= "sata affiliation conflict";
4405 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE
:
4406 desc
= "route not addressable";
4408 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE
:
4409 desc
= "smp error not addressable";
4411 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED
:
4412 desc
= "device blocked";
4414 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED
:
4415 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN
:
4416 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT
:
4417 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG
:
4418 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION
:
4419 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER
:
4420 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN
:
4421 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN
:
4422 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN
:
4423 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION
:
4424 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE
:
4425 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX
:
4426 desc
= "sata initialization failed";
4436 printk(MPT2SAS_ERR_FMT
"discovery errors(%s): sas_address(0x%016llx), "
4437 "handle(0x%04x)\n", ioc
->name
, desc
,
4438 (unsigned long long)sas_address
, handle
);
4443 _scsih_check_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
4445 Mpi2ConfigReply_t mpi_reply
;
4446 Mpi2SasDevicePage0_t sas_device_pg0
;
4447 struct _sas_device
*sas_device
;
4449 unsigned long flags
;
4451 struct scsi_target
*starget
;
4452 struct MPT2SAS_TARGET
*sas_target_priv_data
;
4455 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
4456 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
)))
4459 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
4460 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
4463 /* check if this is end device */
4464 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
4465 if (!(_scsih_is_end_device(device_info
)))
4468 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4469 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
4470 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
4474 printk(MPT2SAS_ERR_FMT
"device is not present "
4475 "handle(0x%04x), no sas_device!!!\n", ioc
->name
, handle
);
4476 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4480 if (unlikely(sas_device
->handle
!= handle
)) {
4481 starget
= sas_device
->starget
;
4482 sas_target_priv_data
= starget
->hostdata
;
4483 starget_printk(KERN_INFO
, starget
, "handle changed from(0x%04x)"
4484 " to (0x%04x)!!!\n", sas_device
->handle
, handle
);
4485 sas_target_priv_data
->handle
= handle
;
4486 sas_device
->handle
= handle
;
4488 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4490 /* check if device is present */
4491 if (!(le16_to_cpu(sas_device_pg0
.Flags
) &
4492 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT
)) {
4493 printk(MPT2SAS_ERR_FMT
"device is not present "
4494 "handle(0x%04x), flags!!!\n", ioc
->name
, handle
);
4498 /* check if there were any issues with discovery */
4499 if (_scsih_check_access_status(ioc
, sas_address
, handle
,
4500 sas_device_pg0
.AccessStatus
))
4502 _scsih_ublock_io_device(ioc
, handle
);
4507 * _scsih_add_device - creating sas device object
4508 * @ioc: per adapter object
4509 * @handle: sas device handle
4510 * @phy_num: phy number end device attached to
4511 * @is_pd: is this hidden raid component
4513 * Creating end device object, stored in ioc->sas_device_list.
4515 * Returns 0 for success, non-zero for failure.
4518 _scsih_add_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
, u8 phy_num
, u8 is_pd
)
4520 Mpi2ConfigReply_t mpi_reply
;
4521 Mpi2SasDevicePage0_t sas_device_pg0
;
4522 Mpi2SasEnclosurePage0_t enclosure_pg0
;
4523 struct _sas_device
*sas_device
;
4527 unsigned long flags
;
4529 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
4530 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
4531 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4532 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4536 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4537 MPI2_IOCSTATUS_MASK
;
4538 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4539 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4540 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4544 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
4546 /* check if device is present */
4547 if (!(le16_to_cpu(sas_device_pg0
.Flags
) &
4548 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT
)) {
4549 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4550 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4551 printk(MPT2SAS_ERR_FMT
"Flags = 0x%04x\n",
4552 ioc
->name
, le16_to_cpu(sas_device_pg0
.Flags
));
4556 /* check if there were any issues with discovery */
4557 if (_scsih_check_access_status(ioc
, sas_address
, handle
,
4558 sas_device_pg0
.AccessStatus
))
4561 /* check if this is end device */
4562 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
4563 if (!(_scsih_is_end_device(device_info
))) {
4564 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4565 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4570 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4571 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
4573 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4578 sas_device
= kzalloc(sizeof(struct _sas_device
),
4581 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4582 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4586 sas_device
->handle
= handle
;
4587 if (_scsih_get_sas_address(ioc
, le16_to_cpu
4588 (sas_device_pg0
.ParentDevHandle
),
4589 &sas_device
->sas_address_parent
) != 0)
4590 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4591 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4592 sas_device
->enclosure_handle
=
4593 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
4595 le16_to_cpu(sas_device_pg0
.Slot
);
4596 sas_device
->device_info
= device_info
;
4597 sas_device
->sas_address
= sas_address
;
4598 sas_device
->phy
= sas_device_pg0
.PhyNum
;
4600 /* get enclosure_logical_id */
4601 if (sas_device
->enclosure_handle
&& !(mpt2sas_config_get_enclosure_pg0(
4602 ioc
, &mpi_reply
, &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
4603 sas_device
->enclosure_handle
)))
4604 sas_device
->enclosure_logical_id
=
4605 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
4607 /* get device name */
4608 sas_device
->device_name
= le64_to_cpu(sas_device_pg0
.DeviceName
);
4610 if (ioc
->wait_for_port_enable_to_complete
)
4611 _scsih_sas_device_init_add(ioc
, sas_device
);
4613 _scsih_sas_device_add(ioc
, sas_device
);
4619 * _scsih_remove_device - removing sas device object
4620 * @ioc: per adapter object
4621 * @sas_device_delete: the sas_device object
4626 _scsih_remove_device(struct MPT2SAS_ADAPTER
*ioc
,
4627 struct _sas_device
*sas_device
)
4629 struct _sas_device sas_device_backup
;
4630 struct MPT2SAS_TARGET
*sas_target_priv_data
;
4635 memcpy(&sas_device_backup
, sas_device
, sizeof(struct _sas_device
));
4636 _scsih_sas_device_remove(ioc
, sas_device
);
4638 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: enter: "
4639 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
, __func__
,
4640 sas_device_backup
.handle
, (unsigned long long)
4641 sas_device_backup
.sas_address
));
4643 if (sas_device_backup
.starget
&& sas_device_backup
.starget
->hostdata
) {
4644 sas_target_priv_data
= sas_device_backup
.starget
->hostdata
;
4645 sas_target_priv_data
->deleted
= 1;
4648 _scsih_ublock_io_device(ioc
, sas_device_backup
.handle
);
4650 mpt2sas_transport_port_remove(ioc
, sas_device_backup
.sas_address
,
4651 sas_device_backup
.sas_address_parent
);
4653 printk(MPT2SAS_INFO_FMT
"removing handle(0x%04x), sas_addr"
4654 "(0x%016llx)\n", ioc
->name
, sas_device_backup
.handle
,
4655 (unsigned long long) sas_device_backup
.sas_address
);
4657 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: exit: "
4658 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
, __func__
,
4659 sas_device_backup
.handle
, (unsigned long long)
4660 sas_device_backup
.sas_address
));
4663 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4665 * _scsih_sas_topology_change_event_debug - debug for topology event
4666 * @ioc: per adapter object
4667 * @event_data: event data payload
4671 _scsih_sas_topology_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
4672 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
4678 char *status_str
= NULL
;
4679 u8 link_rate
, prev_link_rate
;
4681 switch (event_data
->ExpStatus
) {
4682 case MPI2_EVENT_SAS_TOPO_ES_ADDED
:
4685 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
:
4686 status_str
= "remove";
4688 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING
:
4690 status_str
= "responding";
4692 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
:
4693 status_str
= "remove delay";
4696 status_str
= "unknown status";
4699 printk(MPT2SAS_INFO_FMT
"sas topology change: (%s)\n",
4700 ioc
->name
, status_str
);
4701 printk(KERN_INFO
"\thandle(0x%04x), enclosure_handle(0x%04x) "
4702 "start_phy(%02d), count(%d)\n",
4703 le16_to_cpu(event_data
->ExpanderDevHandle
),
4704 le16_to_cpu(event_data
->EnclosureHandle
),
4705 event_data
->StartPhyNum
, event_data
->NumEntries
);
4706 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
4707 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
4710 phy_number
= event_data
->StartPhyNum
+ i
;
4711 reason_code
= event_data
->PHY
[i
].PhyStatus
&
4712 MPI2_EVENT_SAS_TOPO_RC_MASK
;
4713 switch (reason_code
) {
4714 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
4715 status_str
= "target add";
4717 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
4718 status_str
= "target remove";
4720 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
:
4721 status_str
= "delay target remove";
4723 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
4724 status_str
= "link rate change";
4726 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE
:
4727 status_str
= "target responding";
4730 status_str
= "unknown";
4733 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
4734 prev_link_rate
= event_data
->PHY
[i
].LinkRate
& 0xF;
4735 printk(KERN_INFO
"\tphy(%02d), attached_handle(0x%04x): %s:"
4736 " link rate: new(0x%02x), old(0x%02x)\n", phy_number
,
4737 handle
, status_str
, link_rate
, prev_link_rate
);
4744 * _scsih_sas_topology_change_event - handle topology changes
4745 * @ioc: per adapter object
4746 * @fw_event: The fw_event_work object
4751 _scsih_sas_topology_change_event(struct MPT2SAS_ADAPTER
*ioc
,
4752 struct fw_event_work
*fw_event
)
4755 u16 parent_handle
, handle
;
4758 struct _sas_node
*sas_expander
;
4759 struct _sas_device
*sas_device
;
4761 unsigned long flags
;
4762 u8 link_rate
, prev_link_rate
;
4763 Mpi2EventDataSasTopologyChangeList_t
*event_data
= fw_event
->event_data
;
4765 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4766 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
4767 _scsih_sas_topology_change_event_debug(ioc
, event_data
);
4770 if (ioc
->shost_recovery
|| ioc
->remove_host
|| ioc
->pci_error_recovery
)
4773 if (!ioc
->sas_hba
.num_phys
)
4774 _scsih_sas_host_add(ioc
);
4776 _scsih_sas_host_refresh(ioc
);
4778 if (fw_event
->ignore
) {
4779 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"ignoring expander "
4780 "event\n", ioc
->name
));
4784 parent_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
4786 /* handle expander add */
4787 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_ADDED
)
4788 if (_scsih_expander_add(ioc
, parent_handle
) != 0)
4791 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
4792 sas_expander
= mpt2sas_scsih_expander_find_by_handle(ioc
,
4794 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
4796 sas_address
= sas_expander
->sas_address
;
4797 else if (parent_handle
< ioc
->sas_hba
.num_phys
)
4798 sas_address
= ioc
->sas_hba
.sas_address
;
4802 /* handle siblings events */
4803 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
4804 if (fw_event
->ignore
) {
4805 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"ignoring "
4806 "expander event\n", ioc
->name
));
4809 if (ioc
->shost_recovery
|| ioc
->remove_host
||
4810 ioc
->pci_error_recovery
)
4812 phy_number
= event_data
->StartPhyNum
+ i
;
4813 reason_code
= event_data
->PHY
[i
].PhyStatus
&
4814 MPI2_EVENT_SAS_TOPO_RC_MASK
;
4815 if ((event_data
->PHY
[i
].PhyStatus
&
4816 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT
) && (reason_code
!=
4817 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
))
4819 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
4822 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
4823 prev_link_rate
= event_data
->PHY
[i
].LinkRate
& 0xF;
4824 switch (reason_code
) {
4825 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
4827 if (link_rate
== prev_link_rate
)
4830 mpt2sas_transport_update_links(ioc
, sas_address
,
4831 handle
, phy_number
, link_rate
);
4833 if (link_rate
< MPI2_SAS_NEG_LINK_RATE_1_5
)
4836 _scsih_check_device(ioc
, handle
);
4838 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
4840 mpt2sas_transport_update_links(ioc
, sas_address
,
4841 handle
, phy_number
, link_rate
);
4843 _scsih_add_device(ioc
, handle
, phy_number
, 0);
4845 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
4847 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4848 sas_device
= _scsih_sas_device_find_by_handle(ioc
,
4851 spin_unlock_irqrestore(&ioc
->sas_device_lock
,
4855 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4856 _scsih_remove_device(ioc
, sas_device
);
4861 /* handle expander removal */
4862 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
&&
4864 _scsih_expander_remove(ioc
, sas_address
);
4868 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4870 * _scsih_sas_device_status_change_event_debug - debug for device event
4871 * @event_data: event data payload
4877 _scsih_sas_device_status_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
4878 Mpi2EventDataSasDeviceStatusChange_t
*event_data
)
4880 char *reason_str
= NULL
;
4882 switch (event_data
->ReasonCode
) {
4883 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
:
4884 reason_str
= "smart data";
4886 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED
:
4887 reason_str
= "unsupported device discovered";
4889 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
:
4890 reason_str
= "internal device reset";
4892 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL
:
4893 reason_str
= "internal task abort";
4895 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL
:
4896 reason_str
= "internal task abort set";
4898 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL
:
4899 reason_str
= "internal clear task set";
4901 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL
:
4902 reason_str
= "internal query task";
4904 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE
:
4905 reason_str
= "sata init failure";
4907 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
:
4908 reason_str
= "internal device reset complete";
4910 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL
:
4911 reason_str
= "internal task abort complete";
4913 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION
:
4914 reason_str
= "internal async notification";
4916 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY
:
4917 reason_str
= "expander reduced functionality";
4919 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY
:
4920 reason_str
= "expander reduced functionality complete";
4923 reason_str
= "unknown reason";
4926 printk(MPT2SAS_INFO_FMT
"device status change: (%s)\n"
4927 "\thandle(0x%04x), sas address(0x%016llx)", ioc
->name
,
4928 reason_str
, le16_to_cpu(event_data
->DevHandle
),
4929 (unsigned long long)le64_to_cpu(event_data
->SASAddress
));
4930 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
)
4931 printk(MPT2SAS_INFO_FMT
", ASC(0x%x), ASCQ(0x%x)\n", ioc
->name
,
4932 event_data
->ASC
, event_data
->ASCQ
);
4933 printk(KERN_INFO
"\n");
4938 * _scsih_sas_device_status_change_event - handle device status change
4939 * @ioc: per adapter object
4940 * @fw_event: The fw_event_work object
4946 _scsih_sas_device_status_change_event(struct MPT2SAS_ADAPTER
*ioc
,
4947 struct fw_event_work
*fw_event
)
4949 struct MPT2SAS_TARGET
*target_priv_data
;
4950 struct _sas_device
*sas_device
;
4952 unsigned long flags
;
4953 Mpi2EventDataSasDeviceStatusChange_t
*event_data
=
4954 fw_event
->event_data
;
4956 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4957 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
4958 _scsih_sas_device_status_change_event_debug(ioc
,
4962 /* In MPI Revision K (0xC), the internal device reset complete was
4963 * implemented, so avoid setting tm_busy flag for older firmware.
4965 if ((ioc
->facts
.HeaderVersion
>> 8) < 0xC)
4968 if (event_data
->ReasonCode
!=
4969 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
&&
4970 event_data
->ReasonCode
!=
4971 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
)
4974 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4975 sas_address
= le64_to_cpu(event_data
->SASAddress
);
4976 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
4978 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4980 if (!sas_device
|| !sas_device
->starget
)
4983 target_priv_data
= sas_device
->starget
->hostdata
;
4984 if (!target_priv_data
)
4987 if (event_data
->ReasonCode
==
4988 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
)
4989 target_priv_data
->tm_busy
= 1;
4991 target_priv_data
->tm_busy
= 0;
4994 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4996 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure event
4997 * @ioc: per adapter object
4998 * @event_data: event data payload
5004 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
5005 Mpi2EventDataSasEnclDevStatusChange_t
*event_data
)
5007 char *reason_str
= NULL
;
5009 switch (event_data
->ReasonCode
) {
5010 case MPI2_EVENT_SAS_ENCL_RC_ADDED
:
5011 reason_str
= "enclosure add";
5013 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING
:
5014 reason_str
= "enclosure remove";
5017 reason_str
= "unknown reason";
5021 printk(MPT2SAS_INFO_FMT
"enclosure status change: (%s)\n"
5022 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
5023 " number slots(%d)\n", ioc
->name
, reason_str
,
5024 le16_to_cpu(event_data
->EnclosureHandle
),
5025 (unsigned long long)le64_to_cpu(event_data
->EnclosureLogicalID
),
5026 le16_to_cpu(event_data
->StartSlot
));
5031 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
5032 * @ioc: per adapter object
5033 * @fw_event: The fw_event_work object
5039 _scsih_sas_enclosure_dev_status_change_event(struct MPT2SAS_ADAPTER
*ioc
,
5040 struct fw_event_work
*fw_event
)
5042 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5043 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5044 _scsih_sas_enclosure_dev_status_change_event_debug(ioc
,
5045 fw_event
->event_data
);
5050 * _scsih_sas_broadcast_primative_event - handle broadcast events
5051 * @ioc: per adapter object
5052 * @fw_event: The fw_event_work object
5058 _scsih_sas_broadcast_primative_event(struct MPT2SAS_ADAPTER
*ioc
,
5059 struct fw_event_work
*fw_event
)
5061 struct scsi_cmnd
*scmd
;
5062 struct scsi_device
*sdev
;
5065 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
5066 u32 termination_count
;
5068 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
5069 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5070 Mpi2EventDataSasBroadcastPrimitive_t
*event_data
= fw_event
->event_data
;
5073 unsigned long flags
;
5076 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"broadcast primative: "
5077 "phy number(%d), width(%d)\n", ioc
->name
, event_data
->PhyNum
,
5078 event_data
->PortWidth
));
5079 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: enter\n", ioc
->name
,
5082 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
5083 ioc
->broadcast_aen_busy
= 0;
5084 termination_count
= 0;
5086 mpi_reply
= ioc
->tm_cmds
.reply
;
5087 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
5088 scmd
= _scsih_scsi_lookup_get(ioc
, smid
);
5091 sdev
= scmd
->device
;
5092 sas_device_priv_data
= sdev
->hostdata
;
5093 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
)
5095 /* skip hidden raid components */
5096 if (sas_device_priv_data
->sas_target
->flags
&
5097 MPT_TARGET_FLAGS_RAID_COMPONENT
)
5100 if (sas_device_priv_data
->sas_target
->flags
&
5101 MPT_TARGET_FLAGS_VOLUME
)
5104 handle
= sas_device_priv_data
->sas_target
->handle
;
5105 lun
= sas_device_priv_data
->lun
;
5108 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
5109 mpt2sas_scsih_issue_tm(ioc
, handle
, 0, 0, lun
,
5110 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK
, smid
, 30, NULL
);
5111 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
5112 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
)
5113 & MPI2_IOCSTATUS_MASK
;
5114 if ((ioc_status
== MPI2_IOCSTATUS_SUCCESS
) &&
5115 (mpi_reply
->ResponseCode
==
5116 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
||
5117 mpi_reply
->ResponseCode
==
5118 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
)) {
5119 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
5122 r
= mpt2sas_scsih_issue_tm(ioc
, handle
, sdev
->channel
, sdev
->id
,
5123 sdev
->lun
, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
, smid
, 30,
5126 sdev_printk(KERN_WARNING
, sdev
, "task abort: FAILED "
5127 "scmd(%p)\n", scmd
);
5128 termination_count
+= le32_to_cpu(mpi_reply
->TerminationCount
);
5129 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
5131 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
5133 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
5134 "%s - exit, query_count = %d termination_count = %d\n",
5135 ioc
->name
, __func__
, query_count
, termination_count
));
5139 * _scsih_sas_discovery_event - handle discovery events
5140 * @ioc: per adapter object
5141 * @fw_event: The fw_event_work object
5147 _scsih_sas_discovery_event(struct MPT2SAS_ADAPTER
*ioc
,
5148 struct fw_event_work
*fw_event
)
5150 Mpi2EventDataSasDiscovery_t
*event_data
= fw_event
->event_data
;
5152 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5153 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
) {
5154 printk(MPT2SAS_INFO_FMT
"discovery event: (%s)", ioc
->name
,
5155 (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
) ?
5157 if (event_data
->DiscoveryStatus
)
5158 printk("discovery_status(0x%08x)",
5159 le32_to_cpu(event_data
->DiscoveryStatus
));
5164 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
&&
5165 !ioc
->sas_hba
.num_phys
)
5166 _scsih_sas_host_add(ioc
);
5170 * _scsih_reprobe_lun - reprobing lun
5171 * @sdev: scsi device struct
5172 * @no_uld_attach: sdev->no_uld_attach flag setting
5176 _scsih_reprobe_lun(struct scsi_device
*sdev
, void *no_uld_attach
)
5180 sdev
->no_uld_attach
= no_uld_attach
? 1 : 0;
5181 sdev_printk(KERN_INFO
, sdev
, "%s raid component\n",
5182 sdev
->no_uld_attach
? "hidding" : "exposing");
5183 rc
= scsi_device_reprobe(sdev
);
5187 * _scsih_reprobe_target - reprobing target
5188 * @starget: scsi target struct
5189 * @no_uld_attach: sdev->no_uld_attach flag setting
5191 * Note: no_uld_attach flag determines whether the disk device is attached
5192 * to block layer. A value of `1` means to not attach.
5195 _scsih_reprobe_target(struct scsi_target
*starget
, int no_uld_attach
)
5197 struct MPT2SAS_TARGET
*sas_target_priv_data
= starget
->hostdata
;
5200 sas_target_priv_data
->flags
|= MPT_TARGET_FLAGS_RAID_COMPONENT
;
5202 sas_target_priv_data
->flags
&= ~MPT_TARGET_FLAGS_RAID_COMPONENT
;
5204 starget_for_each_device(starget
, no_uld_attach
? (void *)1 : NULL
,
5205 _scsih_reprobe_lun
);
5208 * _scsih_sas_volume_add - add new volume
5209 * @ioc: per adapter object
5210 * @element: IR config element data
5216 _scsih_sas_volume_add(struct MPT2SAS_ADAPTER
*ioc
,
5217 Mpi2EventIrConfigElement_t
*element
)
5219 struct _raid_device
*raid_device
;
5220 unsigned long flags
;
5222 u16 handle
= le16_to_cpu(element
->VolDevHandle
);
5225 mpt2sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
5227 printk(MPT2SAS_ERR_FMT
5228 "failure at %s:%d/%s()!\n", ioc
->name
,
5229 __FILE__
, __LINE__
, __func__
);
5233 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5234 raid_device
= _scsih_raid_device_find_by_wwid(ioc
, wwid
);
5235 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5240 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
5242 printk(MPT2SAS_ERR_FMT
5243 "failure at %s:%d/%s()!\n", ioc
->name
,
5244 __FILE__
, __LINE__
, __func__
);
5248 raid_device
->id
= ioc
->sas_id
++;
5249 raid_device
->channel
= RAID_CHANNEL
;
5250 raid_device
->handle
= handle
;
5251 raid_device
->wwid
= wwid
;
5252 _scsih_raid_device_add(ioc
, raid_device
);
5253 if (!ioc
->wait_for_port_enable_to_complete
) {
5254 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
5255 raid_device
->id
, 0);
5257 _scsih_raid_device_remove(ioc
, raid_device
);
5259 _scsih_determine_boot_device(ioc
, raid_device
, 1);
5263 * _scsih_sas_volume_delete - delete volume
5264 * @ioc: per adapter object
5265 * @handle: volume device handle
5271 _scsih_sas_volume_delete(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
5273 struct _raid_device
*raid_device
;
5274 unsigned long flags
;
5275 struct MPT2SAS_TARGET
*sas_target_priv_data
;
5277 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5278 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
5279 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5282 if (raid_device
->starget
) {
5283 sas_target_priv_data
= raid_device
->starget
->hostdata
;
5284 sas_target_priv_data
->deleted
= 1;
5285 scsi_remove_target(&raid_device
->starget
->dev
);
5287 printk(MPT2SAS_INFO_FMT
"removing handle(0x%04x), wwid"
5288 "(0x%016llx)\n", ioc
->name
, raid_device
->handle
,
5289 (unsigned long long) raid_device
->wwid
);
5290 _scsih_raid_device_remove(ioc
, raid_device
);
5294 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
5295 * @ioc: per adapter object
5296 * @element: IR config element data
5302 _scsih_sas_pd_expose(struct MPT2SAS_ADAPTER
*ioc
,
5303 Mpi2EventIrConfigElement_t
*element
)
5305 struct _sas_device
*sas_device
;
5306 unsigned long flags
;
5307 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
5309 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5310 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
5311 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5315 /* exposing raid component */
5316 sas_device
->volume_handle
= 0;
5317 sas_device
->volume_wwid
= 0;
5318 clear_bit(handle
, ioc
->pd_handles
);
5319 _scsih_reprobe_target(sas_device
->starget
, 0);
5323 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
5324 * @ioc: per adapter object
5325 * @element: IR config element data
5331 _scsih_sas_pd_hide(struct MPT2SAS_ADAPTER
*ioc
,
5332 Mpi2EventIrConfigElement_t
*element
)
5334 struct _sas_device
*sas_device
;
5335 unsigned long flags
;
5336 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
5338 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5339 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
5340 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5344 /* hiding raid component */
5345 mpt2sas_config_get_volume_handle(ioc
, handle
,
5346 &sas_device
->volume_handle
);
5347 mpt2sas_config_get_volume_wwid(ioc
, sas_device
->volume_handle
,
5348 &sas_device
->volume_wwid
);
5349 set_bit(handle
, ioc
->pd_handles
);
5350 _scsih_reprobe_target(sas_device
->starget
, 1);
5354 * _scsih_sas_pd_delete - delete pd component
5355 * @ioc: per adapter object
5356 * @element: IR config element data
5362 _scsih_sas_pd_delete(struct MPT2SAS_ADAPTER
*ioc
,
5363 Mpi2EventIrConfigElement_t
*element
)
5365 struct _sas_device
*sas_device
;
5366 unsigned long flags
;
5367 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
5369 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5370 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
5371 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5374 _scsih_remove_device(ioc
, sas_device
);
5378 * _scsih_sas_pd_add - remove pd component
5379 * @ioc: per adapter object
5380 * @element: IR config element data
5386 _scsih_sas_pd_add(struct MPT2SAS_ADAPTER
*ioc
,
5387 Mpi2EventIrConfigElement_t
*element
)
5389 struct _sas_device
*sas_device
;
5390 unsigned long flags
;
5391 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
5392 Mpi2ConfigReply_t mpi_reply
;
5393 Mpi2SasDevicePage0_t sas_device_pg0
;
5398 set_bit(handle
, ioc
->pd_handles
);
5400 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5401 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
5402 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5406 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
5407 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
5408 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5409 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5413 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5414 MPI2_IOCSTATUS_MASK
;
5415 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5416 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5417 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5421 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
5422 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
5423 mpt2sas_transport_update_links(ioc
, sas_address
, handle
,
5424 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
5426 _scsih_add_device(ioc
, handle
, 0, 1);
5429 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5431 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
5432 * @ioc: per adapter object
5433 * @event_data: event data payload
5439 _scsih_sas_ir_config_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
5440 Mpi2EventDataIrConfigChangeList_t
*event_data
)
5442 Mpi2EventIrConfigElement_t
*element
;
5445 char *reason_str
= NULL
, *element_str
= NULL
;
5447 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
5449 printk(MPT2SAS_INFO_FMT
"raid config change: (%s), elements(%d)\n",
5450 ioc
->name
, (le32_to_cpu(event_data
->Flags
) &
5451 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ?
5452 "foreign" : "native", event_data
->NumElements
);
5453 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
5454 switch (element
->ReasonCode
) {
5455 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
5458 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
5459 reason_str
= "remove";
5461 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE
:
5462 reason_str
= "no change";
5464 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
5465 reason_str
= "hide";
5467 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
5468 reason_str
= "unhide";
5470 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
5471 reason_str
= "volume_created";
5473 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
5474 reason_str
= "volume_deleted";
5476 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
5477 reason_str
= "pd_created";
5479 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
5480 reason_str
= "pd_deleted";
5483 reason_str
= "unknown reason";
5486 element_type
= le16_to_cpu(element
->ElementFlags
) &
5487 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK
;
5488 switch (element_type
) {
5489 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT
:
5490 element_str
= "volume";
5492 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT
:
5493 element_str
= "phys disk";
5495 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT
:
5496 element_str
= "hot spare";
5499 element_str
= "unknown element";
5502 printk(KERN_INFO
"\t(%s:%s), vol handle(0x%04x), "
5503 "pd handle(0x%04x), pd num(0x%02x)\n", element_str
,
5504 reason_str
, le16_to_cpu(element
->VolDevHandle
),
5505 le16_to_cpu(element
->PhysDiskDevHandle
),
5506 element
->PhysDiskNum
);
5512 * _scsih_sas_ir_config_change_event - handle ir configuration change events
5513 * @ioc: per adapter object
5514 * @fw_event: The fw_event_work object
5520 _scsih_sas_ir_config_change_event(struct MPT2SAS_ADAPTER
*ioc
,
5521 struct fw_event_work
*fw_event
)
5523 Mpi2EventIrConfigElement_t
*element
;
5526 Mpi2EventDataIrConfigChangeList_t
*event_data
= fw_event
->event_data
;
5528 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5529 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5530 _scsih_sas_ir_config_change_event_debug(ioc
, event_data
);
5533 foreign_config
= (le32_to_cpu(event_data
->Flags
) &
5534 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ? 1 : 0;
5536 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
5537 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
5539 switch (element
->ReasonCode
) {
5540 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
5541 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
5542 if (!foreign_config
)
5543 _scsih_sas_volume_add(ioc
, element
);
5545 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
5546 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
5547 if (!foreign_config
)
5548 _scsih_sas_volume_delete(ioc
,
5549 le16_to_cpu(element
->VolDevHandle
));
5551 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
5552 _scsih_sas_pd_hide(ioc
, element
);
5554 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
5555 _scsih_sas_pd_expose(ioc
, element
);
5557 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
5558 _scsih_sas_pd_add(ioc
, element
);
5560 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
5561 _scsih_sas_pd_delete(ioc
, element
);
5568 * _scsih_sas_ir_volume_event - IR volume event
5569 * @ioc: per adapter object
5570 * @fw_event: The fw_event_work object
5576 _scsih_sas_ir_volume_event(struct MPT2SAS_ADAPTER
*ioc
,
5577 struct fw_event_work
*fw_event
)
5580 unsigned long flags
;
5581 struct _raid_device
*raid_device
;
5585 Mpi2EventDataIrVolume_t
*event_data
= fw_event
->event_data
;
5587 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED
)
5590 handle
= le16_to_cpu(event_data
->VolDevHandle
);
5591 state
= le32_to_cpu(event_data
->NewValue
);
5592 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: handle(0x%04x), "
5593 "old(0x%08x), new(0x%08x)\n", ioc
->name
, __func__
, handle
,
5594 le32_to_cpu(event_data
->PreviousValue
), state
));
5597 case MPI2_RAID_VOL_STATE_MISSING
:
5598 case MPI2_RAID_VOL_STATE_FAILED
:
5599 _scsih_sas_volume_delete(ioc
, handle
);
5602 case MPI2_RAID_VOL_STATE_ONLINE
:
5603 case MPI2_RAID_VOL_STATE_DEGRADED
:
5604 case MPI2_RAID_VOL_STATE_OPTIMAL
:
5606 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5607 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
5608 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5613 mpt2sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
5615 printk(MPT2SAS_ERR_FMT
5616 "failure at %s:%d/%s()!\n", ioc
->name
,
5617 __FILE__
, __LINE__
, __func__
);
5621 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
5623 printk(MPT2SAS_ERR_FMT
5624 "failure at %s:%d/%s()!\n", ioc
->name
,
5625 __FILE__
, __LINE__
, __func__
);
5629 raid_device
->id
= ioc
->sas_id
++;
5630 raid_device
->channel
= RAID_CHANNEL
;
5631 raid_device
->handle
= handle
;
5632 raid_device
->wwid
= wwid
;
5633 _scsih_raid_device_add(ioc
, raid_device
);
5634 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
5635 raid_device
->id
, 0);
5637 _scsih_raid_device_remove(ioc
, raid_device
);
5640 case MPI2_RAID_VOL_STATE_INITIALIZING
:
5647 * _scsih_sas_ir_physical_disk_event - PD event
5648 * @ioc: per adapter object
5649 * @fw_event: The fw_event_work object
5655 _scsih_sas_ir_physical_disk_event(struct MPT2SAS_ADAPTER
*ioc
,
5656 struct fw_event_work
*fw_event
)
5658 u16 handle
, parent_handle
;
5660 struct _sas_device
*sas_device
;
5661 unsigned long flags
;
5662 Mpi2ConfigReply_t mpi_reply
;
5663 Mpi2SasDevicePage0_t sas_device_pg0
;
5665 Mpi2EventDataIrPhysicalDisk_t
*event_data
= fw_event
->event_data
;
5668 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED
)
5671 handle
= le16_to_cpu(event_data
->PhysDiskDevHandle
);
5672 state
= le32_to_cpu(event_data
->NewValue
);
5674 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: handle(0x%04x), "
5675 "old(0x%08x), new(0x%08x)\n", ioc
->name
, __func__
, handle
,
5676 le32_to_cpu(event_data
->PreviousValue
), state
));
5679 case MPI2_RAID_PD_STATE_ONLINE
:
5680 case MPI2_RAID_PD_STATE_DEGRADED
:
5681 case MPI2_RAID_PD_STATE_REBUILDING
:
5682 case MPI2_RAID_PD_STATE_OPTIMAL
:
5683 case MPI2_RAID_PD_STATE_HOT_SPARE
:
5685 set_bit(handle
, ioc
->pd_handles
);
5687 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5688 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
5689 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5694 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
5695 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
5697 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5698 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5702 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5703 MPI2_IOCSTATUS_MASK
;
5704 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5705 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5706 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5710 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
5711 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
5712 mpt2sas_transport_update_links(ioc
, sas_address
, handle
,
5713 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
5715 _scsih_add_device(ioc
, handle
, 0, 1);
5719 case MPI2_RAID_PD_STATE_OFFLINE
:
5720 case MPI2_RAID_PD_STATE_NOT_CONFIGURED
:
5721 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE
:
5727 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5729 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
5730 * @ioc: per adapter object
5731 * @event_data: event data payload
5737 _scsih_sas_ir_operation_status_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
5738 Mpi2EventDataIrOperationStatus_t
*event_data
)
5740 char *reason_str
= NULL
;
5742 switch (event_data
->RAIDOperation
) {
5743 case MPI2_EVENT_IR_RAIDOP_RESYNC
:
5744 reason_str
= "resync";
5746 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION
:
5747 reason_str
= "online capacity expansion";
5749 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK
:
5750 reason_str
= "consistency check";
5752 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT
:
5753 reason_str
= "background init";
5755 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT
:
5756 reason_str
= "make data consistent";
5763 printk(MPT2SAS_INFO_FMT
"raid operational status: (%s)"
5764 "\thandle(0x%04x), percent complete(%d)\n",
5765 ioc
->name
, reason_str
,
5766 le16_to_cpu(event_data
->VolDevHandle
),
5767 event_data
->PercentComplete
);
5772 * _scsih_sas_ir_operation_status_event - handle RAID operation events
5773 * @ioc: per adapter object
5774 * @fw_event: The fw_event_work object
5780 _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER
*ioc
,
5781 struct fw_event_work
*fw_event
)
5783 Mpi2EventDataIrOperationStatus_t
*event_data
= fw_event
->event_data
;
5784 static struct _raid_device
*raid_device
;
5785 unsigned long flags
;
5788 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5789 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5790 _scsih_sas_ir_operation_status_event_debug(ioc
,
5794 /* code added for raid transport support */
5795 if (event_data
->RAIDOperation
== MPI2_EVENT_IR_RAIDOP_RESYNC
) {
5797 handle
= le16_to_cpu(event_data
->VolDevHandle
);
5799 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5800 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
5801 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5806 if (event_data
->RAIDOperation
== MPI2_EVENT_IR_RAIDOP_RESYNC
)
5807 raid_device
->percent_complete
=
5808 event_data
->PercentComplete
;
5813 * _scsih_task_set_full - handle task set full
5814 * @ioc: per adapter object
5815 * @fw_event: The fw_event_work object
5818 * Throttle back qdepth.
5821 _scsih_task_set_full(struct MPT2SAS_ADAPTER
*ioc
, struct fw_event_work
5824 unsigned long flags
;
5825 struct _sas_device
*sas_device
;
5826 static struct _raid_device
*raid_device
;
5827 struct scsi_device
*sdev
;
5833 Mpi2EventDataTaskSetFull_t
*event_data
= fw_event
->event_data
;
5835 current_depth
= le16_to_cpu(event_data
->CurrentDepth
);
5836 handle
= le16_to_cpu(event_data
->DevHandle
);
5837 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5838 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
5840 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5843 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5844 id
= sas_device
->id
;
5845 channel
= sas_device
->channel
;
5846 sas_address
= sas_device
->sas_address
;
5848 /* if hidden raid component, then change to volume characteristics */
5849 if (test_bit(handle
, ioc
->pd_handles
) && sas_device
->volume_handle
) {
5850 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5851 raid_device
= _scsih_raid_device_find_by_handle(
5852 ioc
, sas_device
->volume_handle
);
5853 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5855 id
= raid_device
->id
;
5856 channel
= raid_device
->channel
;
5857 handle
= raid_device
->handle
;
5858 sas_address
= raid_device
->wwid
;
5862 if (ioc
->logging_level
& MPT_DEBUG_TASK_SET_FULL
)
5863 starget_printk(KERN_INFO
, sas_device
->starget
, "task set "
5864 "full: handle(0x%04x), sas_addr(0x%016llx), depth(%d)\n",
5865 handle
, (unsigned long long)sas_address
, current_depth
);
5867 shost_for_each_device(sdev
, ioc
->shost
) {
5868 if (sdev
->id
== id
&& sdev
->channel
== channel
) {
5869 if (current_depth
> sdev
->queue_depth
) {
5870 if (ioc
->logging_level
&
5871 MPT_DEBUG_TASK_SET_FULL
)
5872 sdev_printk(KERN_INFO
, sdev
, "strange "
5873 "observation, the queue depth is"
5874 " (%d) meanwhile fw queue depth "
5875 "is (%d)\n", sdev
->queue_depth
,
5879 depth
= scsi_track_queue_full(sdev
,
5882 sdev_printk(KERN_INFO
, sdev
, "Queue depth "
5883 "reduced to (%d)\n", depth
);
5885 sdev_printk(KERN_INFO
, sdev
, "Tagged Command "
5886 "Queueing is being disabled\n");
5887 else if (depth
== 0)
5888 if (ioc
->logging_level
&
5889 MPT_DEBUG_TASK_SET_FULL
)
5890 sdev_printk(KERN_INFO
, sdev
,
5891 "Queue depth not changed yet\n");
5897 * _scsih_prep_device_scan - initialize parameters prior to device scan
5898 * @ioc: per adapter object
5900 * Set the deleted flag prior to device scan. If the device is found during
5901 * the scan, then we clear the deleted flag.
5904 _scsih_prep_device_scan(struct MPT2SAS_ADAPTER
*ioc
)
5906 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
5907 struct scsi_device
*sdev
;
5909 shost_for_each_device(sdev
, ioc
->shost
) {
5910 sas_device_priv_data
= sdev
->hostdata
;
5911 if (sas_device_priv_data
&& sas_device_priv_data
->sas_target
)
5912 sas_device_priv_data
->sas_target
->deleted
= 1;
5917 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
5918 * @ioc: per adapter object
5919 * @sas_address: sas address
5920 * @slot: enclosure slot id
5921 * @handle: device handle
5923 * After host reset, find out whether devices are still responding.
5924 * Used in _scsi_remove_unresponsive_sas_devices.
5929 _scsih_mark_responding_sas_device(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
,
5930 u16 slot
, u16 handle
)
5932 struct MPT2SAS_TARGET
*sas_target_priv_data
;
5933 struct scsi_target
*starget
;
5934 struct _sas_device
*sas_device
;
5935 unsigned long flags
;
5937 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5938 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
) {
5939 if (sas_device
->sas_address
== sas_address
&&
5940 sas_device
->slot
== slot
&& sas_device
->starget
) {
5941 sas_device
->responding
= 1;
5942 starget
= sas_device
->starget
;
5943 if (starget
&& starget
->hostdata
) {
5944 sas_target_priv_data
= starget
->hostdata
;
5945 sas_target_priv_data
->tm_busy
= 0;
5946 sas_target_priv_data
->deleted
= 0;
5948 sas_target_priv_data
= NULL
;
5949 starget_printk(KERN_INFO
, sas_device
->starget
,
5950 "handle(0x%04x), sas_addr(0x%016llx), enclosure "
5951 "logical id(0x%016llx), slot(%d)\n", handle
,
5952 (unsigned long long)sas_device
->sas_address
,
5953 (unsigned long long)
5954 sas_device
->enclosure_logical_id
,
5956 if (sas_device
->handle
== handle
)
5958 printk(KERN_INFO
"\thandle changed from(0x%04x)!!!\n",
5959 sas_device
->handle
);
5960 sas_device
->handle
= handle
;
5961 if (sas_target_priv_data
)
5962 sas_target_priv_data
->handle
= handle
;
5967 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5971 * _scsih_search_responding_sas_devices -
5972 * @ioc: per adapter object
5974 * After host reset, find out whether devices are still responding.
5980 _scsih_search_responding_sas_devices(struct MPT2SAS_ADAPTER
*ioc
)
5982 Mpi2SasDevicePage0_t sas_device_pg0
;
5983 Mpi2ConfigReply_t mpi_reply
;
5990 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
, __func__
);
5992 if (list_empty(&ioc
->sas_device_list
))
5996 while (!(mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
5997 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
,
5999 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6000 MPI2_IOCSTATUS_MASK
;
6001 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
6003 handle
= le16_to_cpu(sas_device_pg0
.DevHandle
);
6004 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
6005 if (!(_scsih_is_end_device(device_info
)))
6007 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
6008 slot
= le16_to_cpu(sas_device_pg0
.Slot
);
6009 _scsih_mark_responding_sas_device(ioc
, sas_address
, slot
,
6015 * _scsih_mark_responding_raid_device - mark a raid_device as responding
6016 * @ioc: per adapter object
6017 * @wwid: world wide identifier for raid volume
6018 * @handle: device handle
6020 * After host reset, find out whether devices are still responding.
6021 * Used in _scsi_remove_unresponsive_raid_devices.
6026 _scsih_mark_responding_raid_device(struct MPT2SAS_ADAPTER
*ioc
, u64 wwid
,
6029 struct MPT2SAS_TARGET
*sas_target_priv_data
;
6030 struct scsi_target
*starget
;
6031 struct _raid_device
*raid_device
;
6032 unsigned long flags
;
6034 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6035 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
6036 if (raid_device
->wwid
== wwid
&& raid_device
->starget
) {
6037 starget
= raid_device
->starget
;
6038 if (starget
&& starget
->hostdata
) {
6039 sas_target_priv_data
= starget
->hostdata
;
6040 sas_target_priv_data
->deleted
= 0;
6042 sas_target_priv_data
= NULL
;
6043 raid_device
->responding
= 1;
6044 starget_printk(KERN_INFO
, raid_device
->starget
,
6045 "handle(0x%04x), wwid(0x%016llx)\n", handle
,
6046 (unsigned long long)raid_device
->wwid
);
6047 if (raid_device
->handle
== handle
)
6049 printk(KERN_INFO
"\thandle changed from(0x%04x)!!!\n",
6050 raid_device
->handle
);
6051 raid_device
->handle
= handle
;
6052 if (sas_target_priv_data
)
6053 sas_target_priv_data
->handle
= handle
;
6058 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6062 * _scsih_search_responding_raid_devices -
6063 * @ioc: per adapter object
6065 * After host reset, find out whether devices are still responding.
6071 _scsih_search_responding_raid_devices(struct MPT2SAS_ADAPTER
*ioc
)
6073 Mpi2RaidVolPage1_t volume_pg1
;
6074 Mpi2RaidVolPage0_t volume_pg0
;
6075 Mpi2RaidPhysDiskPage0_t pd_pg0
;
6076 Mpi2ConfigReply_t mpi_reply
;
6081 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
, __func__
);
6083 if (list_empty(&ioc
->raid_device_list
))
6087 while (!(mpt2sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
6088 &volume_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
6089 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6090 MPI2_IOCSTATUS_MASK
;
6091 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
6093 handle
= le16_to_cpu(volume_pg1
.DevHandle
);
6095 if (mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
,
6096 &volume_pg0
, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
6097 sizeof(Mpi2RaidVolPage0_t
)))
6100 if (volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_OPTIMAL
||
6101 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_ONLINE
||
6102 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_DEGRADED
)
6103 _scsih_mark_responding_raid_device(ioc
,
6104 le64_to_cpu(volume_pg1
.WWID
), handle
);
6107 /* refresh the pd_handles */
6108 phys_disk_num
= 0xFF;
6109 memset(ioc
->pd_handles
, 0, ioc
->pd_handles_sz
);
6110 while (!(mpt2sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
6111 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM
,
6113 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6114 MPI2_IOCSTATUS_MASK
;
6115 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
6117 phys_disk_num
= pd_pg0
.PhysDiskNum
;
6118 handle
= le16_to_cpu(pd_pg0
.DevHandle
);
6119 set_bit(handle
, ioc
->pd_handles
);
6124 * _scsih_mark_responding_expander - mark a expander as responding
6125 * @ioc: per adapter object
6126 * @sas_address: sas address
6129 * After host reset, find out whether devices are still responding.
6130 * Used in _scsi_remove_unresponsive_expanders.
6135 _scsih_mark_responding_expander(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
,
6138 struct _sas_node
*sas_expander
;
6139 unsigned long flags
;
6142 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
6143 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
6144 if (sas_expander
->sas_address
!= sas_address
)
6146 sas_expander
->responding
= 1;
6147 if (sas_expander
->handle
== handle
)
6149 printk(KERN_INFO
"\texpander(0x%016llx): handle changed"
6150 " from(0x%04x) to (0x%04x)!!!\n",
6151 (unsigned long long)sas_expander
->sas_address
,
6152 sas_expander
->handle
, handle
);
6153 sas_expander
->handle
= handle
;
6154 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++)
6155 sas_expander
->phy
[i
].handle
= handle
;
6159 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
6163 * _scsih_search_responding_expanders -
6164 * @ioc: per adapter object
6166 * After host reset, find out whether devices are still responding.
6172 _scsih_search_responding_expanders(struct MPT2SAS_ADAPTER
*ioc
)
6174 Mpi2ExpanderPage0_t expander_pg0
;
6175 Mpi2ConfigReply_t mpi_reply
;
6180 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
, __func__
);
6182 if (list_empty(&ioc
->sas_expander_list
))
6186 while (!(mpt2sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
6187 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL
, handle
))) {
6189 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6190 MPI2_IOCSTATUS_MASK
;
6191 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
6194 handle
= le16_to_cpu(expander_pg0
.DevHandle
);
6195 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
6196 printk(KERN_INFO
"\texpander present: handle(0x%04x), "
6197 "sas_addr(0x%016llx)\n", handle
,
6198 (unsigned long long)sas_address
);
6199 _scsih_mark_responding_expander(ioc
, sas_address
, handle
);
6205 * _scsih_remove_unresponding_sas_devices - removing unresponding devices
6206 * @ioc: per adapter object
6211 _scsih_remove_unresponding_sas_devices(struct MPT2SAS_ADAPTER
*ioc
)
6213 struct _sas_device
*sas_device
, *sas_device_next
;
6214 struct _sas_node
*sas_expander
;
6215 struct _raid_device
*raid_device
, *raid_device_next
;
6218 list_for_each_entry_safe(sas_device
, sas_device_next
,
6219 &ioc
->sas_device_list
, list
) {
6220 if (sas_device
->responding
) {
6221 sas_device
->responding
= 0;
6224 if (sas_device
->starget
)
6225 starget_printk(KERN_INFO
, sas_device
->starget
,
6226 "removing: handle(0x%04x), sas_addr(0x%016llx), "
6227 "enclosure logical id(0x%016llx), slot(%d)\n",
6229 (unsigned long long)sas_device
->sas_address
,
6230 (unsigned long long)
6231 sas_device
->enclosure_logical_id
,
6233 _scsih_remove_device(ioc
, sas_device
);
6236 list_for_each_entry_safe(raid_device
, raid_device_next
,
6237 &ioc
->raid_device_list
, list
) {
6238 if (raid_device
->responding
) {
6239 raid_device
->responding
= 0;
6242 if (raid_device
->starget
) {
6243 starget_printk(KERN_INFO
, raid_device
->starget
,
6244 "removing: handle(0x%04x), wwid(0x%016llx)\n",
6245 raid_device
->handle
,
6246 (unsigned long long)raid_device
->wwid
);
6247 scsi_remove_target(&raid_device
->starget
->dev
);
6249 _scsih_raid_device_remove(ioc
, raid_device
);
6252 retry_expander_search
:
6253 sas_expander
= NULL
;
6254 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
6255 if (sas_expander
->responding
) {
6256 sas_expander
->responding
= 0;
6259 _scsih_expander_remove(ioc
, sas_expander
->sas_address
);
6260 goto retry_expander_search
;
6265 * mpt2sas_scsih_reset_handler - reset callback handler (for scsih)
6266 * @ioc: per adapter object
6267 * @reset_phase: phase
6269 * The handler for doing any required cleanup or initialization.
6271 * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
6272 * MPT2_IOC_DONE_RESET
6277 mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER
*ioc
, int reset_phase
)
6279 switch (reset_phase
) {
6280 case MPT2_IOC_PRE_RESET
:
6281 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: "
6282 "MPT2_IOC_PRE_RESET\n", ioc
->name
, __func__
));
6284 case MPT2_IOC_AFTER_RESET
:
6285 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: "
6286 "MPT2_IOC_AFTER_RESET\n", ioc
->name
, __func__
));
6287 if (ioc
->scsih_cmds
.status
& MPT2_CMD_PENDING
) {
6288 ioc
->scsih_cmds
.status
|= MPT2_CMD_RESET
;
6289 mpt2sas_base_free_smid(ioc
, ioc
->scsih_cmds
.smid
);
6290 complete(&ioc
->scsih_cmds
.done
);
6292 if (ioc
->tm_cmds
.status
& MPT2_CMD_PENDING
) {
6293 ioc
->tm_cmds
.status
|= MPT2_CMD_RESET
;
6294 mpt2sas_base_free_smid(ioc
, ioc
->tm_cmds
.smid
);
6295 complete(&ioc
->tm_cmds
.done
);
6297 _scsih_fw_event_cleanup_queue(ioc
);
6298 _scsih_flush_running_cmds(ioc
);
6299 _scsih_queue_rescan(ioc
);
6301 case MPT2_IOC_DONE_RESET
:
6302 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: "
6303 "MPT2_IOC_DONE_RESET\n", ioc
->name
, __func__
));
6304 _scsih_sas_host_refresh(ioc
);
6305 _scsih_prep_device_scan(ioc
);
6306 _scsih_search_responding_sas_devices(ioc
);
6307 _scsih_search_responding_raid_devices(ioc
);
6308 _scsih_search_responding_expanders(ioc
);
6314 * _firmware_event_work - delayed task for processing firmware events
6315 * @ioc: per adapter object
6316 * @work: equal to the fw_event_work object
6322 _firmware_event_work(struct work_struct
*work
)
6324 struct fw_event_work
*fw_event
= container_of(work
,
6325 struct fw_event_work
, delayed_work
.work
);
6326 unsigned long flags
;
6327 struct MPT2SAS_ADAPTER
*ioc
= fw_event
->ioc
;
6329 /* the queue is being flushed so ignore this event */
6330 if (ioc
->remove_host
|| fw_event
->cancel_pending_work
||
6331 ioc
->pci_error_recovery
) {
6332 _scsih_fw_event_free(ioc
, fw_event
);
6336 if (fw_event
->event
== MPT2SAS_RESCAN_AFTER_HOST_RESET
) {
6337 _scsih_fw_event_free(ioc
, fw_event
);
6338 spin_lock_irqsave(&ioc
->ioc_reset_in_progress_lock
, flags
);
6339 if (ioc
->shost_recovery
) {
6340 init_completion(&ioc
->shost_recovery_done
);
6341 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
,
6343 wait_for_completion(&ioc
->shost_recovery_done
);
6345 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
,
6347 _scsih_remove_unresponding_sas_devices(ioc
);
6351 switch (fw_event
->event
) {
6352 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
6353 _scsih_sas_topology_change_event(ioc
, fw_event
);
6355 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
6356 _scsih_sas_device_status_change_event(ioc
,
6359 case MPI2_EVENT_SAS_DISCOVERY
:
6360 _scsih_sas_discovery_event(ioc
,
6363 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
6364 _scsih_sas_broadcast_primative_event(ioc
,
6367 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
6368 _scsih_sas_enclosure_dev_status_change_event(ioc
,
6371 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
6372 _scsih_sas_ir_config_change_event(ioc
, fw_event
);
6374 case MPI2_EVENT_IR_VOLUME
:
6375 _scsih_sas_ir_volume_event(ioc
, fw_event
);
6377 case MPI2_EVENT_IR_PHYSICAL_DISK
:
6378 _scsih_sas_ir_physical_disk_event(ioc
, fw_event
);
6380 case MPI2_EVENT_IR_OPERATION_STATUS
:
6381 _scsih_sas_ir_operation_status_event(ioc
, fw_event
);
6383 case MPI2_EVENT_TASK_SET_FULL
:
6384 _scsih_task_set_full(ioc
, fw_event
);
6387 _scsih_fw_event_free(ioc
, fw_event
);
6391 * mpt2sas_scsih_event_callback - firmware event handler (called at ISR time)
6392 * @ioc: per adapter object
6393 * @msix_index: MSIX table index supplied by the OS
6394 * @reply: reply message frame(lower 32bit addr)
6395 * Context: interrupt.
6397 * This function merely adds a new work task into ioc->firmware_event_thread.
6398 * The tasks are worked from _firmware_event_work in user context.
6400 * Return 1 meaning mf should be freed from _base_interrupt
6401 * 0 means the mf is freed from this function.
6404 mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER
*ioc
, u8 msix_index
,
6407 struct fw_event_work
*fw_event
;
6408 Mpi2EventNotificationReply_t
*mpi_reply
;
6412 /* events turned off due to host reset or driver unloading */
6413 if (ioc
->remove_host
|| ioc
->pci_error_recovery
)
6416 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
6417 event
= le16_to_cpu(mpi_reply
->Event
);
6421 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
6423 Mpi2EventDataSasBroadcastPrimitive_t
*baen_data
=
6424 (Mpi2EventDataSasBroadcastPrimitive_t
*)
6425 mpi_reply
->EventData
;
6427 if (baen_data
->Primitive
!=
6428 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT
||
6429 ioc
->broadcast_aen_busy
)
6431 ioc
->broadcast_aen_busy
= 1;
6435 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
6436 _scsih_check_topo_delete_events(ioc
,
6437 (Mpi2EventDataSasTopologyChangeList_t
*)
6438 mpi_reply
->EventData
);
6440 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
6441 _scsih_check_ir_config_unhide_events(ioc
,
6442 (Mpi2EventDataIrConfigChangeList_t
*)
6443 mpi_reply
->EventData
);
6445 case MPI2_EVENT_IR_VOLUME
:
6446 _scsih_check_volume_delete_events(ioc
,
6447 (Mpi2EventDataIrVolume_t
*)
6448 mpi_reply
->EventData
);
6450 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
6451 case MPI2_EVENT_IR_OPERATION_STATUS
:
6452 case MPI2_EVENT_SAS_DISCOVERY
:
6453 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
6454 case MPI2_EVENT_IR_PHYSICAL_DISK
:
6455 case MPI2_EVENT_TASK_SET_FULL
:
6458 default: /* ignore the rest */
6462 fw_event
= kzalloc(sizeof(struct fw_event_work
), GFP_ATOMIC
);
6464 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6465 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6468 sz
= le16_to_cpu(mpi_reply
->EventDataLength
) * 4;
6469 fw_event
->event_data
= kzalloc(sz
, GFP_ATOMIC
);
6470 if (!fw_event
->event_data
) {
6471 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6472 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6477 memcpy(fw_event
->event_data
, mpi_reply
->EventData
,
6479 fw_event
->ioc
= ioc
;
6480 fw_event
->VF_ID
= mpi_reply
->VF_ID
;
6481 fw_event
->VP_ID
= mpi_reply
->VP_ID
;
6482 fw_event
->event
= event
;
6483 _scsih_fw_event_add(ioc
, fw_event
);
6487 /* shost template */
6488 static struct scsi_host_template scsih_driver_template
= {
6489 .module
= THIS_MODULE
,
6490 .name
= "Fusion MPT SAS Host",
6491 .proc_name
= MPT2SAS_DRIVER_NAME
,
6492 .queuecommand
= _scsih_qcmd
,
6493 .target_alloc
= _scsih_target_alloc
,
6494 .slave_alloc
= _scsih_slave_alloc
,
6495 .slave_configure
= _scsih_slave_configure
,
6496 .target_destroy
= _scsih_target_destroy
,
6497 .slave_destroy
= _scsih_slave_destroy
,
6498 .change_queue_depth
= _scsih_change_queue_depth
,
6499 .change_queue_type
= _scsih_change_queue_type
,
6500 .eh_abort_handler
= _scsih_abort
,
6501 .eh_device_reset_handler
= _scsih_dev_reset
,
6502 .eh_target_reset_handler
= _scsih_target_reset
,
6503 .eh_host_reset_handler
= _scsih_host_reset
,
6504 .bios_param
= _scsih_bios_param
,
6507 .sg_tablesize
= MPT2SAS_SG_DEPTH
,
6508 .max_sectors
= 8192,
6510 .use_clustering
= ENABLE_CLUSTERING
,
6511 .shost_attrs
= mpt2sas_host_attrs
,
6512 .sdev_attrs
= mpt2sas_dev_attrs
,
6516 * _scsih_expander_node_remove - removing expander device from list.
6517 * @ioc: per adapter object
6518 * @sas_expander: the sas_device object
6519 * Context: Calling function should acquire ioc->sas_node_lock.
6521 * Removing object and freeing associated memory from the
6522 * ioc->sas_expander_list.
6527 _scsih_expander_node_remove(struct MPT2SAS_ADAPTER
*ioc
,
6528 struct _sas_node
*sas_expander
)
6530 struct _sas_port
*mpt2sas_port
;
6531 struct _sas_device
*sas_device
;
6532 struct _sas_node
*expander_sibling
;
6533 unsigned long flags
;
6538 /* remove sibling ports attached to this expander */
6539 retry_device_search
:
6540 list_for_each_entry(mpt2sas_port
,
6541 &sas_expander
->sas_port_list
, port_list
) {
6542 if (mpt2sas_port
->remote_identify
.device_type
==
6544 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6546 mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
6547 mpt2sas_port
->remote_identify
.sas_address
);
6548 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6551 _scsih_remove_device(ioc
, sas_device
);
6552 if (ioc
->shost_recovery
)
6554 goto retry_device_search
;
6558 retry_expander_search
:
6559 list_for_each_entry(mpt2sas_port
,
6560 &sas_expander
->sas_port_list
, port_list
) {
6562 if (mpt2sas_port
->remote_identify
.device_type
==
6563 MPI2_SAS_DEVICE_INFO_EDGE_EXPANDER
||
6564 mpt2sas_port
->remote_identify
.device_type
==
6565 MPI2_SAS_DEVICE_INFO_FANOUT_EXPANDER
) {
6567 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
6569 mpt2sas_scsih_expander_find_by_sas_address(
6570 ioc
, mpt2sas_port
->remote_identify
.sas_address
);
6571 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
6572 if (!expander_sibling
)
6574 _scsih_expander_remove(ioc
,
6575 expander_sibling
->sas_address
);
6576 if (ioc
->shost_recovery
)
6578 goto retry_expander_search
;
6582 mpt2sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
6583 sas_expander
->sas_address_parent
);
6585 printk(MPT2SAS_INFO_FMT
"expander_remove: handle"
6586 "(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
6587 sas_expander
->handle
, (unsigned long long)
6588 sas_expander
->sas_address
);
6590 list_del(&sas_expander
->list
);
6591 kfree(sas_expander
->phy
);
6592 kfree(sas_expander
);
6596 * _scsih_ir_shutdown - IR shutdown notification
6597 * @ioc: per adapter object
6599 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
6600 * the host system is shutting down.
6605 _scsih_ir_shutdown(struct MPT2SAS_ADAPTER
*ioc
)
6607 Mpi2RaidActionRequest_t
*mpi_request
;
6608 Mpi2RaidActionReply_t
*mpi_reply
;
6611 /* is IR firmware build loaded ? */
6612 if (!ioc
->ir_firmware
)
6615 /* are there any volumes ? */
6616 if (list_empty(&ioc
->raid_device_list
))
6619 mutex_lock(&ioc
->scsih_cmds
.mutex
);
6621 if (ioc
->scsih_cmds
.status
!= MPT2_CMD_NOT_USED
) {
6622 printk(MPT2SAS_ERR_FMT
"%s: scsih_cmd in use\n",
6623 ioc
->name
, __func__
);
6626 ioc
->scsih_cmds
.status
= MPT2_CMD_PENDING
;
6628 smid
= mpt2sas_base_get_smid(ioc
, ioc
->scsih_cb_idx
);
6630 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
6631 ioc
->name
, __func__
);
6632 ioc
->scsih_cmds
.status
= MPT2_CMD_NOT_USED
;
6636 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
6637 ioc
->scsih_cmds
.smid
= smid
;
6638 memset(mpi_request
, 0, sizeof(Mpi2RaidActionRequest_t
));
6640 mpi_request
->Function
= MPI2_FUNCTION_RAID_ACTION
;
6641 mpi_request
->Action
= MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED
;
6643 printk(MPT2SAS_INFO_FMT
"IR shutdown (sending)\n", ioc
->name
);
6644 init_completion(&ioc
->scsih_cmds
.done
);
6645 mpt2sas_base_put_smid_default(ioc
, smid
);
6646 wait_for_completion_timeout(&ioc
->scsih_cmds
.done
, 10*HZ
);
6648 if (!(ioc
->scsih_cmds
.status
& MPT2_CMD_COMPLETE
)) {
6649 printk(MPT2SAS_ERR_FMT
"%s: timeout\n",
6650 ioc
->name
, __func__
);
6654 if (ioc
->scsih_cmds
.status
& MPT2_CMD_REPLY_VALID
) {
6655 mpi_reply
= ioc
->scsih_cmds
.reply
;
6657 printk(MPT2SAS_INFO_FMT
"IR shutdown (complete): "
6658 "ioc_status(0x%04x), loginfo(0x%08x)\n",
6659 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
6660 le32_to_cpu(mpi_reply
->IOCLogInfo
));
6664 ioc
->scsih_cmds
.status
= MPT2_CMD_NOT_USED
;
6665 mutex_unlock(&ioc
->scsih_cmds
.mutex
);
6669 * _scsih_shutdown - routine call during system shutdown
6670 * @pdev: PCI device struct
6675 _scsih_shutdown(struct pci_dev
*pdev
)
6677 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6678 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
6679 struct workqueue_struct
*wq
;
6680 unsigned long flags
;
6682 ioc
->remove_host
= 1;
6683 _scsih_fw_event_cleanup_queue(ioc
);
6685 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
6686 wq
= ioc
->firmware_event_thread
;
6687 ioc
->firmware_event_thread
= NULL
;
6688 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
6690 destroy_workqueue(wq
);
6692 _scsih_ir_shutdown(ioc
);
6693 mpt2sas_base_detach(ioc
);
6697 * _scsih_remove - detach and remove add host
6698 * @pdev: PCI device struct
6700 * Routine called when unloading the driver.
6703 static void __devexit
6704 _scsih_remove(struct pci_dev
*pdev
)
6706 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6707 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
6708 struct _sas_port
*mpt2sas_port
;
6709 struct _sas_device
*sas_device
;
6710 struct _sas_node
*expander_sibling
;
6711 struct _raid_device
*raid_device
, *next
;
6712 struct MPT2SAS_TARGET
*sas_target_priv_data
;
6713 struct workqueue_struct
*wq
;
6714 unsigned long flags
;
6716 ioc
->remove_host
= 1;
6717 _scsih_fw_event_cleanup_queue(ioc
);
6719 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
6720 wq
= ioc
->firmware_event_thread
;
6721 ioc
->firmware_event_thread
= NULL
;
6722 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
6724 destroy_workqueue(wq
);
6726 /* release all the volumes */
6727 _scsih_ir_shutdown(ioc
);
6728 list_for_each_entry_safe(raid_device
, next
, &ioc
->raid_device_list
,
6730 if (raid_device
->starget
) {
6731 sas_target_priv_data
=
6732 raid_device
->starget
->hostdata
;
6733 sas_target_priv_data
->deleted
= 1;
6734 scsi_remove_target(&raid_device
->starget
->dev
);
6736 printk(MPT2SAS_INFO_FMT
"removing handle(0x%04x), wwid"
6737 "(0x%016llx)\n", ioc
->name
, raid_device
->handle
,
6738 (unsigned long long) raid_device
->wwid
);
6739 _scsih_raid_device_remove(ioc
, raid_device
);
6742 /* free ports attached to the sas_host */
6744 list_for_each_entry(mpt2sas_port
,
6745 &ioc
->sas_hba
.sas_port_list
, port_list
) {
6746 if (mpt2sas_port
->remote_identify
.device_type
==
6749 mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
6750 mpt2sas_port
->remote_identify
.sas_address
);
6752 _scsih_remove_device(ioc
, sas_device
);
6757 mpt2sas_scsih_expander_find_by_sas_address(ioc
,
6758 mpt2sas_port
->remote_identify
.sas_address
);
6759 if (expander_sibling
) {
6760 _scsih_expander_remove(ioc
,
6761 expander_sibling
->sas_address
);
6767 /* free phys attached to the sas_host */
6768 if (ioc
->sas_hba
.num_phys
) {
6769 kfree(ioc
->sas_hba
.phy
);
6770 ioc
->sas_hba
.phy
= NULL
;
6771 ioc
->sas_hba
.num_phys
= 0;
6774 sas_remove_host(shost
);
6775 _scsih_shutdown(pdev
);
6776 list_del(&ioc
->list
);
6777 scsi_remove_host(shost
);
6778 scsi_host_put(shost
);
6782 * _scsih_probe_boot_devices - reports 1st device
6783 * @ioc: per adapter object
6785 * If specified in bios page 2, this routine reports the 1st
6786 * device scsi-ml or sas transport for persistent boot device
6787 * purposes. Please refer to function _scsih_determine_boot_device()
6790 _scsih_probe_boot_devices(struct MPT2SAS_ADAPTER
*ioc
)
6794 struct _sas_device
*sas_device
;
6795 struct _raid_device
*raid_device
;
6797 u64 sas_address_parent
;
6799 unsigned long flags
;
6803 if (ioc
->req_boot_device
.device
) {
6804 device
= ioc
->req_boot_device
.device
;
6805 is_raid
= ioc
->req_boot_device
.is_raid
;
6806 } else if (ioc
->req_alt_boot_device
.device
) {
6807 device
= ioc
->req_alt_boot_device
.device
;
6808 is_raid
= ioc
->req_alt_boot_device
.is_raid
;
6809 } else if (ioc
->current_boot_device
.device
) {
6810 device
= ioc
->current_boot_device
.device
;
6811 is_raid
= ioc
->current_boot_device
.is_raid
;
6818 raid_device
= device
;
6819 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
6820 raid_device
->id
, 0);
6822 _scsih_raid_device_remove(ioc
, raid_device
);
6824 sas_device
= device
;
6825 handle
= sas_device
->handle
;
6826 sas_address_parent
= sas_device
->sas_address_parent
;
6827 sas_address
= sas_device
->sas_address
;
6828 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6829 list_move_tail(&sas_device
->list
, &ioc
->sas_device_list
);
6830 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6831 if (!mpt2sas_transport_port_add(ioc
, sas_device
->handle
,
6832 sas_device
->sas_address_parent
)) {
6833 _scsih_sas_device_remove(ioc
, sas_device
);
6834 } else if (!sas_device
->starget
) {
6835 mpt2sas_transport_port_remove(ioc
, sas_address
,
6836 sas_address_parent
);
6837 _scsih_sas_device_remove(ioc
, sas_device
);
6843 * _scsih_probe_raid - reporting raid volumes to scsi-ml
6844 * @ioc: per adapter object
6846 * Called during initial loading of the driver.
6849 _scsih_probe_raid(struct MPT2SAS_ADAPTER
*ioc
)
6851 struct _raid_device
*raid_device
, *raid_next
;
6854 list_for_each_entry_safe(raid_device
, raid_next
,
6855 &ioc
->raid_device_list
, list
) {
6856 if (raid_device
->starget
)
6858 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
6859 raid_device
->id
, 0);
6861 _scsih_raid_device_remove(ioc
, raid_device
);
6866 * _scsih_probe_sas - reporting sas devices to sas transport
6867 * @ioc: per adapter object
6869 * Called during initial loading of the driver.
6872 _scsih_probe_sas(struct MPT2SAS_ADAPTER
*ioc
)
6874 struct _sas_device
*sas_device
, *next
;
6875 unsigned long flags
;
6877 /* SAS Device List */
6878 list_for_each_entry_safe(sas_device
, next
, &ioc
->sas_device_init_list
,
6880 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6881 list_move_tail(&sas_device
->list
, &ioc
->sas_device_list
);
6882 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6884 if (!mpt2sas_transport_port_add(ioc
, sas_device
->handle
,
6885 sas_device
->sas_address_parent
)) {
6886 _scsih_sas_device_remove(ioc
, sas_device
);
6887 } else if (!sas_device
->starget
) {
6888 mpt2sas_transport_port_remove(ioc
,
6889 sas_device
->sas_address
,
6890 sas_device
->sas_address_parent
);
6891 _scsih_sas_device_remove(ioc
, sas_device
);
6897 * _scsih_probe_devices - probing for devices
6898 * @ioc: per adapter object
6900 * Called during initial loading of the driver.
6903 _scsih_probe_devices(struct MPT2SAS_ADAPTER
*ioc
)
6905 u16 volume_mapping_flags
=
6906 le16_to_cpu(ioc
->ioc_pg8
.IRVolumeMappingFlags
) &
6907 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE
;
6909 if (!(ioc
->facts
.ProtocolFlags
& MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR
))
6910 return; /* return when IOC doesn't support initiator mode */
6912 _scsih_probe_boot_devices(ioc
);
6914 if (ioc
->ir_firmware
) {
6915 if ((volume_mapping_flags
&
6916 MPI2_IOCPAGE8_IRFLAGS_HIGH_VOLUME_MAPPING
)) {
6917 _scsih_probe_sas(ioc
);
6918 _scsih_probe_raid(ioc
);
6920 _scsih_probe_raid(ioc
);
6921 _scsih_probe_sas(ioc
);
6924 _scsih_probe_sas(ioc
);
6928 * _scsih_probe - attach and add scsi host
6929 * @pdev: PCI device struct
6930 * @id: pci device id
6932 * Returns 0 success, anything else error.
6935 _scsih_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
6937 struct MPT2SAS_ADAPTER
*ioc
;
6938 struct Scsi_Host
*shost
;
6940 shost
= scsi_host_alloc(&scsih_driver_template
,
6941 sizeof(struct MPT2SAS_ADAPTER
));
6945 /* init local params */
6946 ioc
= shost_priv(shost
);
6947 memset(ioc
, 0, sizeof(struct MPT2SAS_ADAPTER
));
6948 INIT_LIST_HEAD(&ioc
->list
);
6949 list_add_tail(&ioc
->list
, &mpt2sas_ioc_list
);
6951 ioc
->id
= mpt_ids
++;
6952 sprintf(ioc
->name
, "%s%d", MPT2SAS_DRIVER_NAME
, ioc
->id
);
6954 ioc
->scsi_io_cb_idx
= scsi_io_cb_idx
;
6955 ioc
->tm_cb_idx
= tm_cb_idx
;
6956 ioc
->ctl_cb_idx
= ctl_cb_idx
;
6957 ioc
->base_cb_idx
= base_cb_idx
;
6958 ioc
->transport_cb_idx
= transport_cb_idx
;
6959 ioc
->scsih_cb_idx
= scsih_cb_idx
;
6960 ioc
->config_cb_idx
= config_cb_idx
;
6961 ioc
->tm_tr_cb_idx
= tm_tr_cb_idx
;
6962 ioc
->tm_tr_volume_cb_idx
= tm_tr_volume_cb_idx
;
6963 ioc
->tm_sas_control_cb_idx
= tm_sas_control_cb_idx
;
6964 ioc
->logging_level
= logging_level
;
6965 /* misc semaphores and spin locks */
6966 mutex_init(&ioc
->reset_in_progress_mutex
);
6967 spin_lock_init(&ioc
->ioc_reset_in_progress_lock
);
6968 spin_lock_init(&ioc
->scsi_lookup_lock
);
6969 spin_lock_init(&ioc
->sas_device_lock
);
6970 spin_lock_init(&ioc
->sas_node_lock
);
6971 spin_lock_init(&ioc
->fw_event_lock
);
6972 spin_lock_init(&ioc
->raid_device_lock
);
6974 INIT_LIST_HEAD(&ioc
->sas_device_list
);
6975 INIT_LIST_HEAD(&ioc
->sas_device_init_list
);
6976 INIT_LIST_HEAD(&ioc
->sas_expander_list
);
6977 INIT_LIST_HEAD(&ioc
->fw_event_list
);
6978 INIT_LIST_HEAD(&ioc
->raid_device_list
);
6979 INIT_LIST_HEAD(&ioc
->sas_hba
.sas_port_list
);
6980 INIT_LIST_HEAD(&ioc
->delayed_tr_list
);
6981 INIT_LIST_HEAD(&ioc
->delayed_tr_volume_list
);
6983 /* init shost parameters */
6984 shost
->max_cmd_len
= 32;
6985 shost
->max_lun
= max_lun
;
6986 shost
->transportt
= mpt2sas_transport_template
;
6987 shost
->unique_id
= ioc
->id
;
6989 if ((scsi_add_host(shost
, &pdev
->dev
))) {
6990 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6991 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6992 list_del(&ioc
->list
);
6993 goto out_add_shost_fail
;
6996 scsi_host_set_prot(shost
, SHOST_DIF_TYPE1_PROTECTION
6997 | SHOST_DIF_TYPE2_PROTECTION
| SHOST_DIF_TYPE3_PROTECTION
);
6998 scsi_host_set_guard(shost
, SHOST_DIX_GUARD_CRC
);
7001 snprintf(ioc
->firmware_event_name
, sizeof(ioc
->firmware_event_name
),
7002 "fw_event%d", ioc
->id
);
7003 ioc
->firmware_event_thread
= create_singlethread_workqueue(
7004 ioc
->firmware_event_name
);
7005 if (!ioc
->firmware_event_thread
) {
7006 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
7007 ioc
->name
, __FILE__
, __LINE__
, __func__
);
7008 goto out_thread_fail
;
7011 ioc
->wait_for_port_enable_to_complete
= 1;
7012 if ((mpt2sas_base_attach(ioc
))) {
7013 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
7014 ioc
->name
, __FILE__
, __LINE__
, __func__
);
7015 goto out_attach_fail
;
7018 ioc
->wait_for_port_enable_to_complete
= 0;
7019 _scsih_probe_devices(ioc
);
7023 destroy_workqueue(ioc
->firmware_event_thread
);
7025 list_del(&ioc
->list
);
7026 scsi_remove_host(shost
);
7033 * _scsih_suspend - power management suspend main entry point
7034 * @pdev: PCI device struct
7035 * @state: PM state change to (usually PCI_D3)
7037 * Returns 0 success, anything else error.
7040 _scsih_suspend(struct pci_dev
*pdev
, pm_message_t state
)
7042 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
7043 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
7046 mpt2sas_base_stop_watchdog(ioc
);
7047 flush_scheduled_work();
7048 scsi_block_requests(shost
);
7049 device_state
= pci_choose_state(pdev
, state
);
7050 printk(MPT2SAS_INFO_FMT
"pdev=0x%p, slot=%s, entering "
7051 "operating state [D%d]\n", ioc
->name
, pdev
,
7052 pci_name(pdev
), device_state
);
7054 mpt2sas_base_free_resources(ioc
);
7055 pci_save_state(pdev
);
7056 pci_disable_device(pdev
);
7057 pci_set_power_state(pdev
, device_state
);
7062 * _scsih_resume - power management resume main entry point
7063 * @pdev: PCI device struct
7065 * Returns 0 success, anything else error.
7068 _scsih_resume(struct pci_dev
*pdev
)
7070 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
7071 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
7072 u32 device_state
= pdev
->current_state
;
7075 printk(MPT2SAS_INFO_FMT
"pdev=0x%p, slot=%s, previous "
7076 "operating state [D%d]\n", ioc
->name
, pdev
,
7077 pci_name(pdev
), device_state
);
7079 pci_set_power_state(pdev
, PCI_D0
);
7080 pci_enable_wake(pdev
, PCI_D0
, 0);
7081 pci_restore_state(pdev
);
7083 r
= mpt2sas_base_map_resources(ioc
);
7087 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
, SOFT_RESET
);
7088 scsi_unblock_requests(shost
);
7089 mpt2sas_base_start_watchdog(ioc
);
7092 #endif /* CONFIG_PM */
7095 * _scsih_pci_error_detected - Called when a PCI error is detected.
7096 * @pdev: PCI device struct
7097 * @state: PCI channel state
7099 * Description: Called when a PCI error is detected.
7102 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
7104 static pci_ers_result_t
7105 _scsih_pci_error_detected(struct pci_dev
*pdev
, pci_channel_state_t state
)
7107 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
7108 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
7110 printk(MPT2SAS_INFO_FMT
"PCI error: detected callback, state(%d)!!\n",
7114 case pci_channel_io_normal
:
7115 return PCI_ERS_RESULT_CAN_RECOVER
;
7116 case pci_channel_io_frozen
:
7117 /* Fatal error, prepare for slot reset */
7118 ioc
->pci_error_recovery
= 1;
7119 scsi_block_requests(ioc
->shost
);
7120 mpt2sas_base_stop_watchdog(ioc
);
7121 mpt2sas_base_free_resources(ioc
);
7122 return PCI_ERS_RESULT_NEED_RESET
;
7123 case pci_channel_io_perm_failure
:
7124 /* Permanent error, prepare for device removal */
7125 ioc
->pci_error_recovery
= 1;
7126 mpt2sas_base_stop_watchdog(ioc
);
7127 _scsih_flush_running_cmds(ioc
);
7128 return PCI_ERS_RESULT_DISCONNECT
;
7130 return PCI_ERS_RESULT_NEED_RESET
;
7134 * _scsih_pci_slot_reset - Called when PCI slot has been reset.
7135 * @pdev: PCI device struct
7137 * Description: This routine is called by the pci error recovery
7138 * code after the PCI slot has been reset, just before we
7139 * should resume normal operations.
7141 static pci_ers_result_t
7142 _scsih_pci_slot_reset(struct pci_dev
*pdev
)
7144 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
7145 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
7148 printk(MPT2SAS_INFO_FMT
"PCI error: slot reset callback!!\n",
7151 ioc
->pci_error_recovery
= 0;
7153 pci_restore_state(pdev
);
7154 rc
= mpt2sas_base_map_resources(ioc
);
7156 return PCI_ERS_RESULT_DISCONNECT
;
7159 rc
= mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
7162 printk(MPT2SAS_WARN_FMT
"hard reset: %s\n", ioc
->name
,
7163 (rc
== 0) ? "success" : "failed");
7166 return PCI_ERS_RESULT_RECOVERED
;
7168 return PCI_ERS_RESULT_DISCONNECT
;
7172 * _scsih_pci_resume() - resume normal ops after PCI reset
7173 * @pdev: pointer to PCI device
7175 * Called when the error recovery driver tells us that its
7176 * OK to resume normal operation. Use completion to allow
7177 * halted scsi ops to resume.
7180 _scsih_pci_resume(struct pci_dev
*pdev
)
7182 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
7183 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
7185 printk(MPT2SAS_INFO_FMT
"PCI error: resume callback!!\n", ioc
->name
);
7187 pci_cleanup_aer_uncorrect_error_status(pdev
);
7188 mpt2sas_base_start_watchdog(ioc
);
7189 scsi_unblock_requests(ioc
->shost
);
7193 * _scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
7194 * @pdev: pointer to PCI device
7196 static pci_ers_result_t
7197 _scsih_pci_mmio_enabled(struct pci_dev
*pdev
)
7199 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
7200 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
7202 printk(MPT2SAS_INFO_FMT
"PCI error: mmio enabled callback!!\n",
7205 /* TODO - dump whatever for debugging purposes */
7207 /* Request a slot reset. */
7208 return PCI_ERS_RESULT_NEED_RESET
;
7211 static struct pci_error_handlers _scsih_err_handler
= {
7212 .error_detected
= _scsih_pci_error_detected
,
7213 .mmio_enabled
= _scsih_pci_mmio_enabled
,
7214 .slot_reset
= _scsih_pci_slot_reset
,
7215 .resume
= _scsih_pci_resume
,
7218 static struct pci_driver scsih_driver
= {
7219 .name
= MPT2SAS_DRIVER_NAME
,
7220 .id_table
= scsih_pci_table
,
7221 .probe
= _scsih_probe
,
7222 .remove
= __devexit_p(_scsih_remove
),
7223 .shutdown
= _scsih_shutdown
,
7224 .err_handler
= &_scsih_err_handler
,
7226 .suspend
= _scsih_suspend
,
7227 .resume
= _scsih_resume
,
7231 /* raid transport support */
7232 static struct raid_function_template mpt2sas_raid_functions
= {
7233 .cookie
= &scsih_driver_template
,
7234 .is_raid
= _scsih_is_raid
,
7235 .get_resync
= _scsih_get_resync
,
7236 .get_state
= _scsih_get_state
,
7240 * _scsih_init - main entry point for this driver.
7242 * Returns 0 success, anything else error.
7250 printk(KERN_INFO
"%s version %s loaded\n", MPT2SAS_DRIVER_NAME
,
7251 MPT2SAS_DRIVER_VERSION
);
7253 mpt2sas_transport_template
=
7254 sas_attach_transport(&mpt2sas_transport_functions
);
7255 if (!mpt2sas_transport_template
)
7257 /* raid transport support */
7258 mpt2sas_raid_template
= raid_class_attach(&mpt2sas_raid_functions
);
7259 if (!mpt2sas_raid_template
) {
7260 sas_release_transport(mpt2sas_transport_template
);
7264 mpt2sas_base_initialize_callback_handler();
7266 /* queuecommand callback hander */
7267 scsi_io_cb_idx
= mpt2sas_base_register_callback_handler(_scsih_io_done
);
7269 /* task management callback handler */
7270 tm_cb_idx
= mpt2sas_base_register_callback_handler(_scsih_tm_done
);
7272 /* base internal commands callback handler */
7273 base_cb_idx
= mpt2sas_base_register_callback_handler(mpt2sas_base_done
);
7275 /* transport internal commands callback handler */
7276 transport_cb_idx
= mpt2sas_base_register_callback_handler(
7277 mpt2sas_transport_done
);
7279 /* scsih internal commands callback handler */
7280 scsih_cb_idx
= mpt2sas_base_register_callback_handler(_scsih_done
);
7282 /* configuration page API internal commands callback handler */
7283 config_cb_idx
= mpt2sas_base_register_callback_handler(
7284 mpt2sas_config_done
);
7286 /* ctl module callback handler */
7287 ctl_cb_idx
= mpt2sas_base_register_callback_handler(mpt2sas_ctl_done
);
7289 tm_tr_cb_idx
= mpt2sas_base_register_callback_handler(
7290 _scsih_tm_tr_complete
);
7292 tm_tr_volume_cb_idx
= mpt2sas_base_register_callback_handler(
7293 _scsih_tm_volume_tr_complete
);
7295 tm_sas_control_cb_idx
= mpt2sas_base_register_callback_handler(
7296 _scsih_sas_control_complete
);
7300 error
= pci_register_driver(&scsih_driver
);
7302 /* raid transport support */
7303 raid_class_release(mpt2sas_raid_template
);
7304 sas_release_transport(mpt2sas_transport_template
);
7311 * _scsih_exit - exit point for this driver (when it is a module).
7313 * Returns 0 success, anything else error.
7318 printk(KERN_INFO
"mpt2sas version %s unloading\n",
7319 MPT2SAS_DRIVER_VERSION
);
7321 pci_unregister_driver(&scsih_driver
);
7325 mpt2sas_base_release_callback_handler(scsi_io_cb_idx
);
7326 mpt2sas_base_release_callback_handler(tm_cb_idx
);
7327 mpt2sas_base_release_callback_handler(base_cb_idx
);
7328 mpt2sas_base_release_callback_handler(transport_cb_idx
);
7329 mpt2sas_base_release_callback_handler(scsih_cb_idx
);
7330 mpt2sas_base_release_callback_handler(config_cb_idx
);
7331 mpt2sas_base_release_callback_handler(ctl_cb_idx
);
7333 mpt2sas_base_release_callback_handler(tm_tr_cb_idx
);
7334 mpt2sas_base_release_callback_handler(tm_tr_volume_cb_idx
);
7335 mpt2sas_base_release_callback_handler(tm_sas_control_cb_idx
);
7337 /* raid transport support */
7338 raid_class_release(mpt2sas_raid_template
);
7339 sas_release_transport(mpt2sas_transport_template
);
7343 module_init(_scsih_init
);
7344 module_exit(_scsih_exit
);