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-2009 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/raid_class.h>
56 #include <linux/slab.h>
58 #include "mpt2sas_base.h"
60 MODULE_AUTHOR(MPT2SAS_AUTHOR
);
61 MODULE_DESCRIPTION(MPT2SAS_DESCRIPTION
);
62 MODULE_LICENSE("GPL");
63 MODULE_VERSION(MPT2SAS_DRIVER_VERSION
);
65 #define RAID_CHANNEL 1
68 static void _scsih_expander_node_remove(struct MPT2SAS_ADAPTER
*ioc
,
69 struct _sas_node
*sas_expander
);
70 static void _firmware_event_work(struct work_struct
*work
);
72 /* global parameters */
73 LIST_HEAD(mpt2sas_ioc_list
);
75 /* local parameters */
76 static u8 scsi_io_cb_idx
= -1;
77 static u8 tm_cb_idx
= -1;
78 static u8 ctl_cb_idx
= -1;
79 static u8 base_cb_idx
= -1;
80 static u8 transport_cb_idx
= -1;
81 static u8 scsih_cb_idx
= -1;
82 static u8 config_cb_idx
= -1;
85 static u8 tm_tr_cb_idx
= -1 ;
86 static u8 tm_sas_control_cb_idx
= -1;
88 /* command line options */
89 static u32 logging_level
;
90 MODULE_PARM_DESC(logging_level
, " bits for enabling additional logging info "
93 /* scsi-mid layer global parmeter is max_report_luns, which is 511 */
94 #define MPT2SAS_MAX_LUN (16895)
95 static int max_lun
= MPT2SAS_MAX_LUN
;
96 module_param(max_lun
, int, 0);
97 MODULE_PARM_DESC(max_lun
, " max lun, default=16895 ");
100 * struct sense_info - common structure for obtaining sense keys
102 * @asc: additional sense code
103 * @ascq: additional sense code qualifier
112 #define MPT2SAS_RESCAN_AFTER_HOST_RESET (0xFFFF)
115 * struct fw_event_work - firmware event struct
116 * @list: link list framework
117 * @work: work object (ioc->fault_reset_work_q)
118 * @cancel_pending_work: flag set during reset handling
119 * @ioc: per adapter object
120 * @VF_ID: virtual function id
121 * @VP_ID: virtual port id
122 * @ignore: flag meaning this event has been marked to ignore
123 * @event: firmware event MPI2_EVENT_XXX defined in mpt2_ioc.h
124 * @event_data: reply event data payload follows
126 * This object stored on ioc->fw_event_list.
128 struct fw_event_work
{
129 struct list_head list
;
130 u8 cancel_pending_work
;
131 struct delayed_work delayed_work
;
132 struct MPT2SAS_ADAPTER
*ioc
;
140 /* raid transport support */
141 static struct raid_template
*mpt2sas_raid_template
;
144 * struct _scsi_io_transfer - scsi io transfer
145 * @handle: sas device handle (assigned by firmware)
146 * @is_raid: flag set for hidden raid components
147 * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE,
148 * @data_length: data transfer length
149 * @data_dma: dma pointer to data
152 * @cdb_length: cdb length
154 * @timeout: timeout for this command
155 * @VF_ID: virtual function id
156 * @VP_ID: virtual port id
157 * @valid_reply: flag set for reply message
158 * @sense_length: sense length
159 * @ioc_status: ioc status
160 * @scsi_state: scsi state
161 * @scsi_status: scsi staus
162 * @log_info: log information
163 * @transfer_length: data length transfer when there is a reply message
165 * Used for sending internal scsi commands to devices within this module.
166 * Refer to _scsi_send_scsi_io().
168 struct _scsi_io_transfer
{
171 enum dma_data_direction dir
;
174 u8 sense
[SCSI_SENSE_BUFFERSIZE
];
182 /* the following bits are only valid when 'valid_reply = 1' */
192 * The pci device ids are defined in mpi/mpi2_cnfg.h.
194 static struct pci_device_id scsih_pci_table
[] = {
195 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2004
,
196 PCI_ANY_ID
, PCI_ANY_ID
},
198 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2008
,
199 PCI_ANY_ID
, PCI_ANY_ID
},
200 /* Liberator ~ 2108 */
201 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_1
,
202 PCI_ANY_ID
, PCI_ANY_ID
},
203 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_2
,
204 PCI_ANY_ID
, PCI_ANY_ID
},
205 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_3
,
206 PCI_ANY_ID
, PCI_ANY_ID
},
208 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2116_1
,
209 PCI_ANY_ID
, PCI_ANY_ID
},
210 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2116_2
,
211 PCI_ANY_ID
, PCI_ANY_ID
},
212 /* Thunderbolt ~ 2208 */
213 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_1
,
214 PCI_ANY_ID
, PCI_ANY_ID
},
215 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_2
,
216 PCI_ANY_ID
, PCI_ANY_ID
},
217 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_3
,
218 PCI_ANY_ID
, PCI_ANY_ID
},
219 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_4
,
220 PCI_ANY_ID
, PCI_ANY_ID
},
221 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_5
,
222 PCI_ANY_ID
, PCI_ANY_ID
},
223 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_6
,
224 PCI_ANY_ID
, PCI_ANY_ID
},
225 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_7
,
226 PCI_ANY_ID
, PCI_ANY_ID
},
227 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_8
,
228 PCI_ANY_ID
, PCI_ANY_ID
},
229 {0} /* Terminating entry */
231 MODULE_DEVICE_TABLE(pci
, scsih_pci_table
);
234 * _scsih_set_debug_level - global setting of ioc->logging_level.
236 * Note: The logging levels are defined in mpt2sas_debug.h.
239 _scsih_set_debug_level(const char *val
, struct kernel_param
*kp
)
241 int ret
= param_set_int(val
, kp
);
242 struct MPT2SAS_ADAPTER
*ioc
;
247 printk(KERN_INFO
"setting logging_level(0x%08x)\n", logging_level
);
248 list_for_each_entry(ioc
, &mpt2sas_ioc_list
, list
)
249 ioc
->logging_level
= logging_level
;
252 module_param_call(logging_level
, _scsih_set_debug_level
, param_get_int
,
253 &logging_level
, 0644);
256 * _scsih_srch_boot_sas_address - search based on sas_address
257 * @sas_address: sas address
258 * @boot_device: boot device object from bios page 2
260 * Returns 1 when there's a match, 0 means no match.
263 _scsih_srch_boot_sas_address(u64 sas_address
,
264 Mpi2BootDeviceSasWwid_t
*boot_device
)
266 return (sas_address
== le64_to_cpu(boot_device
->SASAddress
)) ? 1 : 0;
270 * _scsih_srch_boot_device_name - search based on device name
271 * @device_name: device name specified in INDENTIFY fram
272 * @boot_device: boot device object from bios page 2
274 * Returns 1 when there's a match, 0 means no match.
277 _scsih_srch_boot_device_name(u64 device_name
,
278 Mpi2BootDeviceDeviceName_t
*boot_device
)
280 return (device_name
== le64_to_cpu(boot_device
->DeviceName
)) ? 1 : 0;
284 * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot
285 * @enclosure_logical_id: enclosure logical id
286 * @slot_number: slot number
287 * @boot_device: boot device object from bios page 2
289 * Returns 1 when there's a match, 0 means no match.
292 _scsih_srch_boot_encl_slot(u64 enclosure_logical_id
, u16 slot_number
,
293 Mpi2BootDeviceEnclosureSlot_t
*boot_device
)
295 return (enclosure_logical_id
== le64_to_cpu(boot_device
->
296 EnclosureLogicalID
) && slot_number
== le16_to_cpu(boot_device
->
297 SlotNumber
)) ? 1 : 0;
301 * _scsih_is_boot_device - search for matching boot device.
302 * @sas_address: sas address
303 * @device_name: device name specified in INDENTIFY fram
304 * @enclosure_logical_id: enclosure logical id
305 * @slot_number: slot number
306 * @form: specifies boot device form
307 * @boot_device: boot device object from bios page 2
309 * Returns 1 when there's a match, 0 means no match.
312 _scsih_is_boot_device(u64 sas_address
, u64 device_name
,
313 u64 enclosure_logical_id
, u16 slot
, u8 form
,
314 Mpi2BiosPage2BootDevice_t
*boot_device
)
319 case MPI2_BIOSPAGE2_FORM_SAS_WWID
:
322 rc
= _scsih_srch_boot_sas_address(
323 sas_address
, &boot_device
->SasWwid
);
325 case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT
:
326 if (!enclosure_logical_id
)
328 rc
= _scsih_srch_boot_encl_slot(
329 enclosure_logical_id
,
330 slot
, &boot_device
->EnclosureSlot
);
332 case MPI2_BIOSPAGE2_FORM_DEVICE_NAME
:
335 rc
= _scsih_srch_boot_device_name(
336 device_name
, &boot_device
->DeviceName
);
338 case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED
:
346 * _scsih_get_sas_address - set the sas_address for given device handle
347 * @handle: device handle
348 * @sas_address: sas address
350 * Returns 0 success, non-zero when failure
353 _scsih_get_sas_address(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
,
356 Mpi2SasDevicePage0_t sas_device_pg0
;
357 Mpi2ConfigReply_t mpi_reply
;
360 if (handle
<= ioc
->sas_hba
.num_phys
) {
361 *sas_address
= ioc
->sas_hba
.sas_address
;
366 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
367 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
368 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
369 ioc
->name
, __FILE__
, __LINE__
, __func__
);
373 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
375 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
376 printk(MPT2SAS_ERR_FMT
"handle(0x%04x), ioc_status(0x%04x)"
377 "\nfailure at %s:%d/%s()!\n", ioc
->name
, handle
, ioc_status
,
378 __FILE__
, __LINE__
, __func__
);
382 *sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
387 * _scsih_determine_boot_device - determine boot device.
388 * @ioc: per adapter object
389 * @device: either sas_device or raid_device object
390 * @is_raid: [flag] 1 = raid object, 0 = sas object
392 * Determines whether this device should be first reported device to
393 * to scsi-ml or sas transport, this purpose is for persistant boot device.
394 * There are primary, alternate, and current entries in bios page 2. The order
395 * priority is primary, alternate, then current. This routine saves
396 * the corresponding device object and is_raid flag in the ioc object.
397 * The saved data to be used later in _scsih_probe_boot_devices().
400 _scsih_determine_boot_device(struct MPT2SAS_ADAPTER
*ioc
,
401 void *device
, u8 is_raid
)
403 struct _sas_device
*sas_device
;
404 struct _raid_device
*raid_device
;
407 u64 enclosure_logical_id
;
410 /* only process this function when driver loads */
411 if (!ioc
->wait_for_port_enable_to_complete
)
416 sas_address
= sas_device
->sas_address
;
417 device_name
= sas_device
->device_name
;
418 enclosure_logical_id
= sas_device
->enclosure_logical_id
;
419 slot
= sas_device
->slot
;
421 raid_device
= device
;
422 sas_address
= raid_device
->wwid
;
424 enclosure_logical_id
= 0;
428 if (!ioc
->req_boot_device
.device
) {
429 if (_scsih_is_boot_device(sas_address
, device_name
,
430 enclosure_logical_id
, slot
,
431 (ioc
->bios_pg2
.ReqBootDeviceForm
&
432 MPI2_BIOSPAGE2_FORM_MASK
),
433 &ioc
->bios_pg2
.RequestedBootDevice
)) {
434 dinitprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
435 "%s: req_boot_device(0x%016llx)\n",
437 (unsigned long long)sas_address
));
438 ioc
->req_boot_device
.device
= device
;
439 ioc
->req_boot_device
.is_raid
= is_raid
;
443 if (!ioc
->req_alt_boot_device
.device
) {
444 if (_scsih_is_boot_device(sas_address
, device_name
,
445 enclosure_logical_id
, slot
,
446 (ioc
->bios_pg2
.ReqAltBootDeviceForm
&
447 MPI2_BIOSPAGE2_FORM_MASK
),
448 &ioc
->bios_pg2
.RequestedAltBootDevice
)) {
449 dinitprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
450 "%s: req_alt_boot_device(0x%016llx)\n",
452 (unsigned long long)sas_address
));
453 ioc
->req_alt_boot_device
.device
= device
;
454 ioc
->req_alt_boot_device
.is_raid
= is_raid
;
458 if (!ioc
->current_boot_device
.device
) {
459 if (_scsih_is_boot_device(sas_address
, device_name
,
460 enclosure_logical_id
, slot
,
461 (ioc
->bios_pg2
.CurrentBootDeviceForm
&
462 MPI2_BIOSPAGE2_FORM_MASK
),
463 &ioc
->bios_pg2
.CurrentBootDevice
)) {
464 dinitprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
465 "%s: current_boot_device(0x%016llx)\n",
467 (unsigned long long)sas_address
));
468 ioc
->current_boot_device
.device
= device
;
469 ioc
->current_boot_device
.is_raid
= is_raid
;
475 * mpt2sas_scsih_sas_device_find_by_sas_address - sas device search
476 * @ioc: per adapter object
477 * @sas_address: sas address
478 * Context: Calling function should acquire ioc->sas_device_lock
480 * This searches for sas_device based on sas_address, then return sas_device
484 mpt2sas_scsih_sas_device_find_by_sas_address(struct MPT2SAS_ADAPTER
*ioc
,
487 struct _sas_device
*sas_device
;
489 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
)
490 if (sas_device
->sas_address
== sas_address
)
493 list_for_each_entry(sas_device
, &ioc
->sas_device_init_list
, list
)
494 if (sas_device
->sas_address
== sas_address
)
501 * _scsih_sas_device_find_by_handle - sas device search
502 * @ioc: per adapter object
503 * @handle: sas device handle (assigned by firmware)
504 * Context: Calling function should acquire ioc->sas_device_lock
506 * This searches for sas_device based on sas_address, then return sas_device
509 static struct _sas_device
*
510 _scsih_sas_device_find_by_handle(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
512 struct _sas_device
*sas_device
;
514 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
)
515 if (sas_device
->handle
== handle
)
518 list_for_each_entry(sas_device
, &ioc
->sas_device_init_list
, list
)
519 if (sas_device
->handle
== handle
)
526 * _scsih_sas_device_remove - remove sas_device from list.
527 * @ioc: per adapter object
528 * @sas_device: the sas_device object
529 * Context: This function will acquire ioc->sas_device_lock.
531 * Removing object and freeing associated memory from the ioc->sas_device_list.
534 _scsih_sas_device_remove(struct MPT2SAS_ADAPTER
*ioc
,
535 struct _sas_device
*sas_device
)
539 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
540 list_del(&sas_device
->list
);
541 memset(sas_device
, 0, sizeof(struct _sas_device
));
543 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
547 * _scsih_sas_device_add - insert sas_device to the list.
548 * @ioc: per adapter object
549 * @sas_device: the sas_device object
550 * Context: This function will acquire ioc->sas_device_lock.
552 * Adding new object to the ioc->sas_device_list.
555 _scsih_sas_device_add(struct MPT2SAS_ADAPTER
*ioc
,
556 struct _sas_device
*sas_device
)
560 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: handle"
561 "(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
, __func__
,
562 sas_device
->handle
, (unsigned long long)sas_device
->sas_address
));
564 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
565 list_add_tail(&sas_device
->list
, &ioc
->sas_device_list
);
566 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
568 if (!mpt2sas_transport_port_add(ioc
, sas_device
->handle
,
569 sas_device
->sas_address_parent
))
570 _scsih_sas_device_remove(ioc
, sas_device
);
574 * _scsih_sas_device_init_add - insert sas_device to the list.
575 * @ioc: per adapter object
576 * @sas_device: the sas_device object
577 * Context: This function will acquire ioc->sas_device_lock.
579 * Adding new object at driver load time to the ioc->sas_device_init_list.
582 _scsih_sas_device_init_add(struct MPT2SAS_ADAPTER
*ioc
,
583 struct _sas_device
*sas_device
)
587 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: handle"
588 "(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
, __func__
,
589 sas_device
->handle
, (unsigned long long)sas_device
->sas_address
));
591 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
592 list_add_tail(&sas_device
->list
, &ioc
->sas_device_init_list
);
593 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
594 _scsih_determine_boot_device(ioc
, sas_device
, 0);
598 * _scsih_raid_device_find_by_id - raid device search
599 * @ioc: per adapter object
600 * @id: sas device target id
601 * @channel: sas device channel
602 * Context: Calling function should acquire ioc->raid_device_lock
604 * This searches for raid_device based on target id, then return raid_device
607 static struct _raid_device
*
608 _scsih_raid_device_find_by_id(struct MPT2SAS_ADAPTER
*ioc
, int id
, int channel
)
610 struct _raid_device
*raid_device
, *r
;
613 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
614 if (raid_device
->id
== id
&& raid_device
->channel
== channel
) {
625 * _scsih_raid_device_find_by_handle - raid device search
626 * @ioc: per adapter object
627 * @handle: sas device handle (assigned by firmware)
628 * Context: Calling function should acquire ioc->raid_device_lock
630 * This searches for raid_device based on handle, then return raid_device
633 static struct _raid_device
*
634 _scsih_raid_device_find_by_handle(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
636 struct _raid_device
*raid_device
, *r
;
639 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
640 if (raid_device
->handle
!= handle
)
651 * _scsih_raid_device_find_by_wwid - raid device search
652 * @ioc: per adapter object
653 * @handle: sas device handle (assigned by firmware)
654 * Context: Calling function should acquire ioc->raid_device_lock
656 * This searches for raid_device based on wwid, then return raid_device
659 static struct _raid_device
*
660 _scsih_raid_device_find_by_wwid(struct MPT2SAS_ADAPTER
*ioc
, u64 wwid
)
662 struct _raid_device
*raid_device
, *r
;
665 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
666 if (raid_device
->wwid
!= wwid
)
677 * _scsih_raid_device_add - add raid_device object
678 * @ioc: per adapter object
679 * @raid_device: raid_device object
681 * This is added to the raid_device_list link list.
684 _scsih_raid_device_add(struct MPT2SAS_ADAPTER
*ioc
,
685 struct _raid_device
*raid_device
)
689 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: handle"
690 "(0x%04x), wwid(0x%016llx)\n", ioc
->name
, __func__
,
691 raid_device
->handle
, (unsigned long long)raid_device
->wwid
));
693 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
694 list_add_tail(&raid_device
->list
, &ioc
->raid_device_list
);
695 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
699 * _scsih_raid_device_remove - delete raid_device object
700 * @ioc: per adapter object
701 * @raid_device: raid_device object
703 * This is removed from the raid_device_list link list.
706 _scsih_raid_device_remove(struct MPT2SAS_ADAPTER
*ioc
,
707 struct _raid_device
*raid_device
)
711 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
712 list_del(&raid_device
->list
);
713 memset(raid_device
, 0, sizeof(struct _raid_device
));
715 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
719 * mpt2sas_scsih_expander_find_by_handle - expander device search
720 * @ioc: per adapter object
721 * @handle: expander handle (assigned by firmware)
722 * Context: Calling function should acquire ioc->sas_device_lock
724 * This searches for expander device based on handle, then returns the
728 mpt2sas_scsih_expander_find_by_handle(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
730 struct _sas_node
*sas_expander
, *r
;
733 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
734 if (sas_expander
->handle
!= handle
)
744 * mpt2sas_scsih_expander_find_by_sas_address - expander device search
745 * @ioc: per adapter object
746 * @sas_address: sas address
747 * Context: Calling function should acquire ioc->sas_node_lock.
749 * This searches for expander device based on sas_address, then returns the
753 mpt2sas_scsih_expander_find_by_sas_address(struct MPT2SAS_ADAPTER
*ioc
,
756 struct _sas_node
*sas_expander
, *r
;
759 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
760 if (sas_expander
->sas_address
!= sas_address
)
770 * _scsih_expander_node_add - insert expander device to the list.
771 * @ioc: per adapter object
772 * @sas_expander: the sas_device object
773 * Context: This function will acquire ioc->sas_node_lock.
775 * Adding new object to the ioc->sas_expander_list.
780 _scsih_expander_node_add(struct MPT2SAS_ADAPTER
*ioc
,
781 struct _sas_node
*sas_expander
)
785 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
786 list_add_tail(&sas_expander
->list
, &ioc
->sas_expander_list
);
787 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
791 * _scsih_is_end_device - determines if device is an end device
792 * @device_info: bitfield providing information about the device.
795 * Returns 1 if end device.
798 _scsih_is_end_device(u32 device_info
)
800 if (device_info
& MPI2_SAS_DEVICE_INFO_END_DEVICE
&&
801 ((device_info
& MPI2_SAS_DEVICE_INFO_SSP_TARGET
) |
802 (device_info
& MPI2_SAS_DEVICE_INFO_STP_TARGET
) |
803 (device_info
& MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)))
810 * mptscsih_get_scsi_lookup - returns scmd entry
811 * @ioc: per adapter object
812 * @smid: system request message index
814 * Returns the smid stored scmd pointer.
816 static struct scsi_cmnd
*
817 _scsih_scsi_lookup_get(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
819 return ioc
->scsi_lookup
[smid
- 1].scmd
;
823 * _scsih_scsi_lookup_find_by_scmd - scmd lookup
824 * @ioc: per adapter object
825 * @smid: system request message index
826 * @scmd: pointer to scsi command object
827 * Context: This function will acquire ioc->scsi_lookup_lock.
829 * This will search for a scmd pointer in the scsi_lookup array,
830 * returning the revelent smid. A returned value of zero means invalid.
833 _scsih_scsi_lookup_find_by_scmd(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_cmnd
840 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
842 for (i
= 0; i
< ioc
->scsiio_depth
; i
++) {
843 if (ioc
->scsi_lookup
[i
].scmd
== scmd
) {
844 smid
= ioc
->scsi_lookup
[i
].smid
;
849 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
854 * _scsih_scsi_lookup_find_by_target - search for matching channel:id
855 * @ioc: per adapter object
858 * Context: This function will acquire ioc->scsi_lookup_lock.
860 * This will search for a matching channel:id in the scsi_lookup array,
861 * returning 1 if found.
864 _scsih_scsi_lookup_find_by_target(struct MPT2SAS_ADAPTER
*ioc
, int id
,
871 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
873 for (i
= 0 ; i
< ioc
->scsiio_depth
; i
++) {
874 if (ioc
->scsi_lookup
[i
].scmd
&&
875 (ioc
->scsi_lookup
[i
].scmd
->device
->id
== id
&&
876 ioc
->scsi_lookup
[i
].scmd
->device
->channel
== channel
)) {
882 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
887 * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun
888 * @ioc: per adapter object
892 * Context: This function will acquire ioc->scsi_lookup_lock.
894 * This will search for a matching channel:id:lun in the scsi_lookup array,
895 * returning 1 if found.
898 _scsih_scsi_lookup_find_by_lun(struct MPT2SAS_ADAPTER
*ioc
, int id
,
899 unsigned int lun
, int channel
)
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
&&
911 ioc
->scsi_lookup
[i
].scmd
->device
->lun
== lun
)) {
917 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
922 * _scsih_get_chain_buffer_dma - obtain block of chains (dma address)
923 * @ioc: per adapter object
924 * @smid: system request message index
926 * Returns phys pointer to chain buffer.
929 _scsih_get_chain_buffer_dma(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
931 return ioc
->chain_dma
+ ((smid
- 1) * (ioc
->request_sz
*
932 ioc
->chains_needed_per_io
));
936 * _scsih_get_chain_buffer - obtain block of chains assigned to a mf request
937 * @ioc: per adapter object
938 * @smid: system request message index
940 * Returns virt pointer to chain buffer.
943 _scsih_get_chain_buffer(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
945 return (void *)(ioc
->chain
+ ((smid
- 1) * (ioc
->request_sz
*
946 ioc
->chains_needed_per_io
)));
950 * _scsih_build_scatter_gather - main sg creation routine
951 * @ioc: per adapter object
952 * @scmd: scsi command
953 * @smid: system request message index
956 * The main routine that builds scatter gather table from a given
957 * scsi request sent via the .queuecommand main handler.
959 * Returns 0 success, anything else error
962 _scsih_build_scatter_gather(struct MPT2SAS_ADAPTER
*ioc
,
963 struct scsi_cmnd
*scmd
, u16 smid
)
965 Mpi2SCSIIORequest_t
*mpi_request
;
966 dma_addr_t chain_dma
;
967 struct scatterlist
*sg_scmd
;
968 void *sg_local
, *chain
;
975 u32 sgl_flags_last_element
;
976 u32 sgl_flags_end_buffer
;
978 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
980 /* init scatter gather flags */
981 sgl_flags
= MPI2_SGE_FLAGS_SIMPLE_ELEMENT
;
982 if (scmd
->sc_data_direction
== DMA_TO_DEVICE
)
983 sgl_flags
|= MPI2_SGE_FLAGS_HOST_TO_IOC
;
984 sgl_flags_last_element
= (sgl_flags
| MPI2_SGE_FLAGS_LAST_ELEMENT
)
985 << MPI2_SGE_FLAGS_SHIFT
;
986 sgl_flags_end_buffer
= (sgl_flags
| MPI2_SGE_FLAGS_LAST_ELEMENT
|
987 MPI2_SGE_FLAGS_END_OF_BUFFER
| MPI2_SGE_FLAGS_END_OF_LIST
)
988 << MPI2_SGE_FLAGS_SHIFT
;
989 sgl_flags
= sgl_flags
<< MPI2_SGE_FLAGS_SHIFT
;
991 sg_scmd
= scsi_sglist(scmd
);
992 sges_left
= scsi_dma_map(scmd
);
994 sdev_printk(KERN_ERR
, scmd
->device
, "pci_map_sg"
995 " failed: request for %d bytes!\n", scsi_bufflen(scmd
));
999 sg_local
= &mpi_request
->SGL
;
1000 sges_in_segment
= ioc
->max_sges_in_main_message
;
1001 if (sges_left
<= sges_in_segment
)
1002 goto fill_in_last_segment
;
1004 mpi_request
->ChainOffset
= (offsetof(Mpi2SCSIIORequest_t
, SGL
) +
1005 (sges_in_segment
* ioc
->sge_size
))/4;
1007 /* fill in main message segment when there is a chain following */
1008 while (sges_in_segment
) {
1009 if (sges_in_segment
== 1)
1010 ioc
->base_add_sg_single(sg_local
,
1011 sgl_flags_last_element
| sg_dma_len(sg_scmd
),
1012 sg_dma_address(sg_scmd
));
1014 ioc
->base_add_sg_single(sg_local
, sgl_flags
|
1015 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
1016 sg_scmd
= sg_next(sg_scmd
);
1017 sg_local
+= ioc
->sge_size
;
1022 /* initializing the chain flags and pointers */
1023 chain_flags
= MPI2_SGE_FLAGS_CHAIN_ELEMENT
<< MPI2_SGE_FLAGS_SHIFT
;
1024 chain
= _scsih_get_chain_buffer(ioc
, smid
);
1025 chain_dma
= _scsih_get_chain_buffer_dma(ioc
, smid
);
1027 sges_in_segment
= (sges_left
<=
1028 ioc
->max_sges_in_chain_message
) ? sges_left
:
1029 ioc
->max_sges_in_chain_message
;
1030 chain_offset
= (sges_left
== sges_in_segment
) ?
1031 0 : (sges_in_segment
* ioc
->sge_size
)/4;
1032 chain_length
= sges_in_segment
* ioc
->sge_size
;
1034 chain_offset
= chain_offset
<<
1035 MPI2_SGE_CHAIN_OFFSET_SHIFT
;
1036 chain_length
+= ioc
->sge_size
;
1038 ioc
->base_add_sg_single(sg_local
, chain_flags
| chain_offset
|
1039 chain_length
, chain_dma
);
1042 goto fill_in_last_segment
;
1044 /* fill in chain segments */
1045 while (sges_in_segment
) {
1046 if (sges_in_segment
== 1)
1047 ioc
->base_add_sg_single(sg_local
,
1048 sgl_flags_last_element
|
1049 sg_dma_len(sg_scmd
),
1050 sg_dma_address(sg_scmd
));
1052 ioc
->base_add_sg_single(sg_local
, sgl_flags
|
1053 sg_dma_len(sg_scmd
),
1054 sg_dma_address(sg_scmd
));
1055 sg_scmd
= sg_next(sg_scmd
);
1056 sg_local
+= ioc
->sge_size
;
1061 chain_dma
+= ioc
->request_sz
;
1062 chain
+= ioc
->request_sz
;
1066 fill_in_last_segment
:
1068 /* fill the last segment */
1071 ioc
->base_add_sg_single(sg_local
, sgl_flags_end_buffer
|
1072 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
1074 ioc
->base_add_sg_single(sg_local
, sgl_flags
|
1075 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
1076 sg_scmd
= sg_next(sg_scmd
);
1077 sg_local
+= ioc
->sge_size
;
1085 * _scsih_change_queue_depth - setting device queue depth
1086 * @sdev: scsi device struct
1087 * @qdepth: requested queue depth
1088 * @reason: calling context
1090 * Returns queue depth.
1093 _scsih_change_queue_depth(struct scsi_device
*sdev
, int qdepth
, int reason
)
1095 struct Scsi_Host
*shost
= sdev
->host
;
1098 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1099 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1100 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1101 struct _sas_device
*sas_device
;
1102 unsigned long flags
;
1104 if (reason
!= SCSI_QDEPTH_DEFAULT
)
1107 max_depth
= shost
->can_queue
;
1109 /* limit max device queue for SATA to 32 */
1110 sas_device_priv_data
= sdev
->hostdata
;
1111 if (!sas_device_priv_data
)
1113 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
1114 if (!sas_target_priv_data
)
1116 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
))
1118 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1119 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1120 sas_device_priv_data
->sas_target
->sas_address
);
1121 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1122 if (sas_device
&& sas_device
->device_info
&
1123 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1124 max_depth
= MPT2SAS_SATA_QUEUE_DEPTH
;
1128 if (!sdev
->tagged_supported
)
1130 if (qdepth
> max_depth
)
1132 tag_type
= (qdepth
== 1) ? 0 : MSG_SIMPLE_TAG
;
1133 scsi_adjust_queue_depth(sdev
, tag_type
, qdepth
);
1135 if (sdev
->inquiry_len
> 7)
1136 sdev_printk(KERN_INFO
, sdev
, "qdepth(%d), tagged(%d), "
1137 "simple(%d), ordered(%d), scsi_level(%d), cmd_que(%d)\n",
1138 sdev
->queue_depth
, sdev
->tagged_supported
, sdev
->simple_tags
,
1139 sdev
->ordered_tags
, sdev
->scsi_level
,
1140 (sdev
->inquiry
[7] & 2) >> 1);
1142 return sdev
->queue_depth
;
1146 * _scsih_change_queue_type - changing device queue tag type
1147 * @sdev: scsi device struct
1148 * @tag_type: requested tag type
1150 * Returns queue tag type.
1153 _scsih_change_queue_type(struct scsi_device
*sdev
, int tag_type
)
1155 if (sdev
->tagged_supported
) {
1156 scsi_set_tag_type(sdev
, tag_type
);
1158 scsi_activate_tcq(sdev
, sdev
->queue_depth
);
1160 scsi_deactivate_tcq(sdev
, sdev
->queue_depth
);
1168 * _scsih_target_alloc - target add routine
1169 * @starget: scsi target struct
1171 * Returns 0 if ok. Any other return is assumed to be an error and
1172 * the device is ignored.
1175 _scsih_target_alloc(struct scsi_target
*starget
)
1177 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
1178 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1179 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1180 struct _sas_device
*sas_device
;
1181 struct _raid_device
*raid_device
;
1182 unsigned long flags
;
1183 struct sas_rphy
*rphy
;
1185 sas_target_priv_data
= kzalloc(sizeof(struct scsi_target
), GFP_KERNEL
);
1186 if (!sas_target_priv_data
)
1189 starget
->hostdata
= sas_target_priv_data
;
1190 sas_target_priv_data
->starget
= starget
;
1191 sas_target_priv_data
->handle
= MPT2SAS_INVALID_DEVICE_HANDLE
;
1194 if (starget
->channel
== RAID_CHANNEL
) {
1195 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1196 raid_device
= _scsih_raid_device_find_by_id(ioc
, starget
->id
,
1199 sas_target_priv_data
->handle
= raid_device
->handle
;
1200 sas_target_priv_data
->sas_address
= raid_device
->wwid
;
1201 sas_target_priv_data
->flags
|= MPT_TARGET_FLAGS_VOLUME
;
1202 raid_device
->starget
= starget
;
1204 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1208 /* sas/sata devices */
1209 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1210 rphy
= dev_to_rphy(starget
->dev
.parent
);
1211 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1212 rphy
->identify
.sas_address
);
1215 sas_target_priv_data
->handle
= sas_device
->handle
;
1216 sas_target_priv_data
->sas_address
= sas_device
->sas_address
;
1217 sas_device
->starget
= starget
;
1218 sas_device
->id
= starget
->id
;
1219 sas_device
->channel
= starget
->channel
;
1220 if (sas_device
->hidden_raid_component
)
1221 sas_target_priv_data
->flags
|=
1222 MPT_TARGET_FLAGS_RAID_COMPONENT
;
1224 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1230 * _scsih_target_destroy - target destroy routine
1231 * @starget: scsi target struct
1236 _scsih_target_destroy(struct scsi_target
*starget
)
1238 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
1239 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1240 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1241 struct _sas_device
*sas_device
;
1242 struct _raid_device
*raid_device
;
1243 unsigned long flags
;
1244 struct sas_rphy
*rphy
;
1246 sas_target_priv_data
= starget
->hostdata
;
1247 if (!sas_target_priv_data
)
1250 if (starget
->channel
== RAID_CHANNEL
) {
1251 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1252 raid_device
= _scsih_raid_device_find_by_id(ioc
, starget
->id
,
1255 raid_device
->starget
= NULL
;
1256 raid_device
->sdev
= NULL
;
1258 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1262 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1263 rphy
= dev_to_rphy(starget
->dev
.parent
);
1264 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1265 rphy
->identify
.sas_address
);
1266 if (sas_device
&& (sas_device
->starget
== starget
) &&
1267 (sas_device
->id
== starget
->id
) &&
1268 (sas_device
->channel
== starget
->channel
))
1269 sas_device
->starget
= NULL
;
1271 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1274 kfree(sas_target_priv_data
);
1275 starget
->hostdata
= NULL
;
1279 * _scsih_slave_alloc - device add routine
1280 * @sdev: scsi device struct
1282 * Returns 0 if ok. Any other return is assumed to be an error and
1283 * the device is ignored.
1286 _scsih_slave_alloc(struct scsi_device
*sdev
)
1288 struct Scsi_Host
*shost
;
1289 struct MPT2SAS_ADAPTER
*ioc
;
1290 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1291 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1292 struct scsi_target
*starget
;
1293 struct _raid_device
*raid_device
;
1294 unsigned long flags
;
1296 sas_device_priv_data
= kzalloc(sizeof(struct scsi_device
), GFP_KERNEL
);
1297 if (!sas_device_priv_data
)
1300 sas_device_priv_data
->lun
= sdev
->lun
;
1301 sas_device_priv_data
->flags
= MPT_DEVICE_FLAGS_INIT
;
1303 starget
= scsi_target(sdev
);
1304 sas_target_priv_data
= starget
->hostdata
;
1305 sas_target_priv_data
->num_luns
++;
1306 sas_device_priv_data
->sas_target
= sas_target_priv_data
;
1307 sdev
->hostdata
= sas_device_priv_data
;
1308 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
))
1309 sdev
->no_uld_attach
= 1;
1311 shost
= dev_to_shost(&starget
->dev
);
1312 ioc
= shost_priv(shost
);
1313 if (starget
->channel
== RAID_CHANNEL
) {
1314 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1315 raid_device
= _scsih_raid_device_find_by_id(ioc
,
1316 starget
->id
, starget
->channel
);
1318 raid_device
->sdev
= sdev
; /* raid is single lun */
1319 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1326 * _scsih_slave_destroy - device destroy routine
1327 * @sdev: scsi device struct
1332 _scsih_slave_destroy(struct scsi_device
*sdev
)
1334 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1335 struct scsi_target
*starget
;
1337 if (!sdev
->hostdata
)
1340 starget
= scsi_target(sdev
);
1341 sas_target_priv_data
= starget
->hostdata
;
1342 sas_target_priv_data
->num_luns
--;
1343 kfree(sdev
->hostdata
);
1344 sdev
->hostdata
= NULL
;
1348 * _scsih_display_sata_capabilities - sata capabilities
1349 * @ioc: per adapter object
1350 * @sas_device: the sas_device object
1351 * @sdev: scsi device struct
1354 _scsih_display_sata_capabilities(struct MPT2SAS_ADAPTER
*ioc
,
1355 struct _sas_device
*sas_device
, struct scsi_device
*sdev
)
1357 Mpi2ConfigReply_t mpi_reply
;
1358 Mpi2SasDevicePage0_t sas_device_pg0
;
1363 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
1364 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, sas_device
->handle
))) {
1365 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1366 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1370 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
1371 MPI2_IOCSTATUS_MASK
;
1372 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
1373 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1374 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1378 flags
= le16_to_cpu(sas_device_pg0
.Flags
);
1379 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
1381 sdev_printk(KERN_INFO
, sdev
,
1382 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1383 "sw_preserve(%s)\n",
1384 (device_info
& MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE
) ? "y" : "n",
1385 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED
) ? "y" : "n",
1386 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY
) ? "y" :
1388 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED
) ? "y" : "n",
1389 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED
) ? "y" : "n",
1390 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE
) ? "y" : "n");
1394 * _scsih_is_raid - return boolean indicating device is raid volume
1395 * @dev the device struct object
1398 _scsih_is_raid(struct device
*dev
)
1400 struct scsi_device
*sdev
= to_scsi_device(dev
);
1402 return (sdev
->channel
== RAID_CHANNEL
) ? 1 : 0;
1406 * _scsih_get_resync - get raid volume resync percent complete
1407 * @dev the device struct object
1410 _scsih_get_resync(struct device
*dev
)
1412 struct scsi_device
*sdev
= to_scsi_device(dev
);
1413 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
1414 static struct _raid_device
*raid_device
;
1415 unsigned long flags
;
1416 Mpi2RaidVolPage0_t vol_pg0
;
1417 Mpi2ConfigReply_t mpi_reply
;
1418 u32 volume_status_flags
;
1419 u8 percent_complete
= 0;
1421 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1422 raid_device
= _scsih_raid_device_find_by_id(ioc
, sdev
->id
,
1424 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1429 if (mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, &vol_pg0
,
1430 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, raid_device
->handle
,
1431 sizeof(Mpi2RaidVolPage0_t
))) {
1432 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1433 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1437 volume_status_flags
= le32_to_cpu(vol_pg0
.VolumeStatusFlags
);
1438 if (volume_status_flags
& MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS
)
1439 percent_complete
= raid_device
->percent_complete
;
1441 raid_set_resync(mpt2sas_raid_template
, dev
, percent_complete
);
1445 * _scsih_get_state - get raid volume level
1446 * @dev the device struct object
1449 _scsih_get_state(struct device
*dev
)
1451 struct scsi_device
*sdev
= to_scsi_device(dev
);
1452 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
1453 static struct _raid_device
*raid_device
;
1454 unsigned long flags
;
1455 Mpi2RaidVolPage0_t vol_pg0
;
1456 Mpi2ConfigReply_t mpi_reply
;
1458 enum raid_state state
= RAID_STATE_UNKNOWN
;
1460 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1461 raid_device
= _scsih_raid_device_find_by_id(ioc
, sdev
->id
,
1463 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1468 if (mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, &vol_pg0
,
1469 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, raid_device
->handle
,
1470 sizeof(Mpi2RaidVolPage0_t
))) {
1471 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1472 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1476 volstate
= le32_to_cpu(vol_pg0
.VolumeStatusFlags
);
1477 if (volstate
& MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS
) {
1478 state
= RAID_STATE_RESYNCING
;
1482 switch (vol_pg0
.VolumeState
) {
1483 case MPI2_RAID_VOL_STATE_OPTIMAL
:
1484 case MPI2_RAID_VOL_STATE_ONLINE
:
1485 state
= RAID_STATE_ACTIVE
;
1487 case MPI2_RAID_VOL_STATE_DEGRADED
:
1488 state
= RAID_STATE_DEGRADED
;
1490 case MPI2_RAID_VOL_STATE_FAILED
:
1491 case MPI2_RAID_VOL_STATE_MISSING
:
1492 state
= RAID_STATE_OFFLINE
;
1496 raid_set_state(mpt2sas_raid_template
, dev
, state
);
1500 * _scsih_set_level - set raid level
1501 * @sdev: scsi device struct
1502 * @raid_device: raid_device object
1505 _scsih_set_level(struct scsi_device
*sdev
, struct _raid_device
*raid_device
)
1507 enum raid_level level
= RAID_LEVEL_UNKNOWN
;
1509 switch (raid_device
->volume_type
) {
1510 case MPI2_RAID_VOL_TYPE_RAID0
:
1511 level
= RAID_LEVEL_0
;
1513 case MPI2_RAID_VOL_TYPE_RAID10
:
1514 level
= RAID_LEVEL_10
;
1516 case MPI2_RAID_VOL_TYPE_RAID1E
:
1517 level
= RAID_LEVEL_1E
;
1519 case MPI2_RAID_VOL_TYPE_RAID1
:
1520 level
= RAID_LEVEL_1
;
1524 raid_set_level(mpt2sas_raid_template
, &sdev
->sdev_gendev
, level
);
1528 * _scsih_get_volume_capabilities - volume capabilities
1529 * @ioc: per adapter object
1530 * @sas_device: the raid_device object
1533 _scsih_get_volume_capabilities(struct MPT2SAS_ADAPTER
*ioc
,
1534 struct _raid_device
*raid_device
)
1536 Mpi2RaidVolPage0_t
*vol_pg0
;
1537 Mpi2RaidPhysDiskPage0_t pd_pg0
;
1538 Mpi2SasDevicePage0_t sas_device_pg0
;
1539 Mpi2ConfigReply_t mpi_reply
;
1543 if ((mpt2sas_config_get_number_pds(ioc
, raid_device
->handle
,
1544 &num_pds
)) || !num_pds
) {
1545 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1546 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1550 raid_device
->num_pds
= num_pds
;
1551 sz
= offsetof(Mpi2RaidVolPage0_t
, PhysDisk
) + (num_pds
*
1552 sizeof(Mpi2RaidVol0PhysDisk_t
));
1553 vol_pg0
= kzalloc(sz
, GFP_KERNEL
);
1555 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1556 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1560 if ((mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, vol_pg0
,
1561 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, raid_device
->handle
, sz
))) {
1562 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1563 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1568 raid_device
->volume_type
= vol_pg0
->VolumeType
;
1570 /* figure out what the underlying devices are by
1571 * obtaining the device_info bits for the 1st device
1573 if (!(mpt2sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
1574 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM
,
1575 vol_pg0
->PhysDisk
[0].PhysDiskNum
))) {
1576 if (!(mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
1577 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
1578 le16_to_cpu(pd_pg0
.DevHandle
)))) {
1579 raid_device
->device_info
=
1580 le32_to_cpu(sas_device_pg0
.DeviceInfo
);
1588 * _scsih_enable_tlr - setting TLR flags
1589 * @ioc: per adapter object
1590 * @sdev: scsi device struct
1592 * Enabling Transaction Layer Retries for tape devices when
1593 * vpd page 0x90 is present
1597 _scsih_enable_tlr(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_device
*sdev
)
1600 if (sdev
->type
!= TYPE_TAPE
)
1603 if (!(ioc
->facts
.IOCCapabilities
& MPI2_IOCFACTS_CAPABILITY_TLR
))
1606 sas_enable_tlr(sdev
);
1607 sdev_printk(KERN_INFO
, sdev
, "TLR %s\n",
1608 sas_is_tlr_enabled(sdev
) ? "Enabled" : "Disabled");
1614 * _scsih_slave_configure - device configure routine.
1615 * @sdev: scsi device struct
1617 * Returns 0 if ok. Any other return is assumed to be an error and
1618 * the device is ignored.
1621 _scsih_slave_configure(struct scsi_device
*sdev
)
1623 struct Scsi_Host
*shost
= sdev
->host
;
1624 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1625 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1626 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1627 struct _sas_device
*sas_device
;
1628 struct _raid_device
*raid_device
;
1629 unsigned long flags
;
1636 sas_device_priv_data
= sdev
->hostdata
;
1637 sas_device_priv_data
->configured_lun
= 1;
1638 sas_device_priv_data
->flags
&= ~MPT_DEVICE_FLAGS_INIT
;
1639 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
1641 /* raid volume handling */
1642 if (sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
1644 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1645 raid_device
= _scsih_raid_device_find_by_handle(ioc
,
1646 sas_target_priv_data
->handle
);
1647 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1649 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1650 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1654 _scsih_get_volume_capabilities(ioc
, raid_device
);
1656 /* RAID Queue Depth Support
1657 * IS volume = underlying qdepth of drive type, either
1658 * MPT2SAS_SAS_QUEUE_DEPTH or MPT2SAS_SATA_QUEUE_DEPTH
1659 * IM/IME/R10 = 128 (MPT2SAS_RAID_QUEUE_DEPTH)
1661 if (raid_device
->device_info
&
1662 MPI2_SAS_DEVICE_INFO_SSP_TARGET
) {
1663 qdepth
= MPT2SAS_SAS_QUEUE_DEPTH
;
1666 qdepth
= MPT2SAS_SATA_QUEUE_DEPTH
;
1667 if (raid_device
->device_info
&
1668 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1674 switch (raid_device
->volume_type
) {
1675 case MPI2_RAID_VOL_TYPE_RAID0
:
1678 case MPI2_RAID_VOL_TYPE_RAID1E
:
1679 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
1680 if (ioc
->manu_pg10
.OEMIdentifier
&&
1681 (ioc
->manu_pg10
.GenericFlags0
&
1682 MFG10_GF0_R10_DISPLAY
) &&
1683 !(raid_device
->num_pds
% 2))
1688 case MPI2_RAID_VOL_TYPE_RAID1
:
1689 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
1692 case MPI2_RAID_VOL_TYPE_RAID10
:
1693 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
1696 case MPI2_RAID_VOL_TYPE_UNKNOWN
:
1698 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
1703 sdev_printk(KERN_INFO
, sdev
, "%s: "
1704 "handle(0x%04x), wwid(0x%016llx), pd_count(%d), type(%s)\n",
1705 r_level
, raid_device
->handle
,
1706 (unsigned long long)raid_device
->wwid
,
1707 raid_device
->num_pds
, ds
);
1708 _scsih_change_queue_depth(sdev
, qdepth
, SCSI_QDEPTH_DEFAULT
);
1709 /* raid transport support */
1710 _scsih_set_level(sdev
, raid_device
);
1714 /* non-raid handling */
1715 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1716 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1717 sas_device_priv_data
->sas_target
->sas_address
);
1718 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1720 if (sas_target_priv_data
->flags
&
1721 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
1722 mpt2sas_config_get_volume_handle(ioc
,
1723 sas_device
->handle
, &sas_device
->volume_handle
);
1724 mpt2sas_config_get_volume_wwid(ioc
,
1725 sas_device
->volume_handle
,
1726 &sas_device
->volume_wwid
);
1728 if (sas_device
->device_info
& MPI2_SAS_DEVICE_INFO_SSP_TARGET
) {
1729 qdepth
= MPT2SAS_SAS_QUEUE_DEPTH
;
1733 qdepth
= MPT2SAS_SATA_QUEUE_DEPTH
;
1734 if (sas_device
->device_info
&
1735 MPI2_SAS_DEVICE_INFO_STP_TARGET
)
1737 else if (sas_device
->device_info
&
1738 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1742 sdev_printk(KERN_INFO
, sdev
, "%s: handle(0x%04x), "
1743 "sas_addr(0x%016llx), device_name(0x%016llx)\n",
1744 ds
, sas_device
->handle
,
1745 (unsigned long long)sas_device
->sas_address
,
1746 (unsigned long long)sas_device
->device_name
);
1747 sdev_printk(KERN_INFO
, sdev
, "%s: "
1748 "enclosure_logical_id(0x%016llx), slot(%d)\n", ds
,
1749 (unsigned long long) sas_device
->enclosure_logical_id
,
1753 _scsih_display_sata_capabilities(ioc
, sas_device
, sdev
);
1756 _scsih_change_queue_depth(sdev
, qdepth
, SCSI_QDEPTH_DEFAULT
);
1759 sas_read_port_mode_page(sdev
);
1760 _scsih_enable_tlr(ioc
, sdev
);
1766 * _scsih_bios_param - fetch head, sector, cylinder info for a disk
1767 * @sdev: scsi device struct
1768 * @bdev: pointer to block device context
1769 * @capacity: device size (in 512 byte sectors)
1770 * @params: three element array to place output:
1771 * params[0] number of heads (max 255)
1772 * params[1] number of sectors (max 63)
1773 * params[2] number of cylinders
1778 _scsih_bios_param(struct scsi_device
*sdev
, struct block_device
*bdev
,
1779 sector_t capacity
, int params
[])
1789 dummy
= heads
* sectors
;
1790 cylinders
= capacity
;
1791 sector_div(cylinders
, dummy
);
1794 * Handle extended translation size for logical drives
1797 if ((ulong
)capacity
>= 0x200000) {
1800 dummy
= heads
* sectors
;
1801 cylinders
= capacity
;
1802 sector_div(cylinders
, dummy
);
1807 params
[1] = sectors
;
1808 params
[2] = cylinders
;
1814 * _scsih_response_code - translation of device response code
1815 * @ioc: per adapter object
1816 * @response_code: response code returned by the device
1821 _scsih_response_code(struct MPT2SAS_ADAPTER
*ioc
, u8 response_code
)
1825 switch (response_code
) {
1826 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE
:
1827 desc
= "task management request completed";
1829 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
:
1830 desc
= "invalid frame";
1832 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED
:
1833 desc
= "task management request not supported";
1835 case MPI2_SCSITASKMGMT_RSP_TM_FAILED
:
1836 desc
= "task management request failed";
1838 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
:
1839 desc
= "task management request succeeded";
1841 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN
:
1842 desc
= "invalid lun";
1845 desc
= "overlapped tag attempted";
1847 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
:
1848 desc
= "task queued, however not sent to target";
1854 printk(MPT2SAS_WARN_FMT
"response_code(0x%01x): %s\n",
1855 ioc
->name
, response_code
, desc
);
1859 * _scsih_tm_done - tm completion routine
1860 * @ioc: per adapter object
1861 * @smid: system request message index
1862 * @msix_index: MSIX table index supplied by the OS
1863 * @reply: reply message frame(lower 32bit addr)
1866 * The callback handler when using scsih_issue_tm.
1868 * Return 1 meaning mf should be freed from _base_interrupt
1869 * 0 means the mf is freed from this function.
1872 _scsih_tm_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
1874 MPI2DefaultReply_t
*mpi_reply
;
1876 if (ioc
->tm_cmds
.status
== MPT2_CMD_NOT_USED
)
1878 if (ioc
->tm_cmds
.smid
!= smid
)
1880 ioc
->tm_cmds
.status
|= MPT2_CMD_COMPLETE
;
1881 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
1883 memcpy(ioc
->tm_cmds
.reply
, mpi_reply
, mpi_reply
->MsgLength
*4);
1884 ioc
->tm_cmds
.status
|= MPT2_CMD_REPLY_VALID
;
1886 ioc
->tm_cmds
.status
&= ~MPT2_CMD_PENDING
;
1887 complete(&ioc
->tm_cmds
.done
);
1892 * mpt2sas_scsih_set_tm_flag - set per target tm_busy
1893 * @ioc: per adapter object
1894 * @handle: device handle
1896 * During taskmangement request, we need to freeze the device queue.
1899 mpt2sas_scsih_set_tm_flag(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
1901 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1902 struct scsi_device
*sdev
;
1905 shost_for_each_device(sdev
, ioc
->shost
) {
1908 sas_device_priv_data
= sdev
->hostdata
;
1909 if (!sas_device_priv_data
)
1911 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
1912 sas_device_priv_data
->sas_target
->tm_busy
= 1;
1914 ioc
->ignore_loginfos
= 1;
1920 * mpt2sas_scsih_clear_tm_flag - clear per target tm_busy
1921 * @ioc: per adapter object
1922 * @handle: device handle
1924 * During taskmangement request, we need to freeze the device queue.
1927 mpt2sas_scsih_clear_tm_flag(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
1929 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1930 struct scsi_device
*sdev
;
1933 shost_for_each_device(sdev
, ioc
->shost
) {
1936 sas_device_priv_data
= sdev
->hostdata
;
1937 if (!sas_device_priv_data
)
1939 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
1940 sas_device_priv_data
->sas_target
->tm_busy
= 0;
1942 ioc
->ignore_loginfos
= 0;
1949 * mpt2sas_scsih_issue_tm - main routine for sending tm requests
1950 * @ioc: per adapter struct
1951 * @device_handle: device handle
1952 * @channel: the channel assigned by the OS
1953 * @id: the id assigned by the OS
1955 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
1956 * @smid_task: smid assigned to the task
1957 * @timeout: timeout in seconds
1960 * A generic API for sending task management requests to firmware.
1962 * The callback index is set inside `ioc->tm_cb_idx`.
1964 * Return SUCCESS or FAILED.
1967 mpt2sas_scsih_issue_tm(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
, uint channel
,
1968 uint id
, uint lun
, u8 type
, u16 smid_task
, ulong timeout
,
1969 struct scsi_cmnd
*scmd
)
1971 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
1972 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
1975 unsigned long timeleft
;
1976 struct scsi_cmnd
*scmd_lookup
;
1979 mutex_lock(&ioc
->tm_cmds
.mutex
);
1980 if (ioc
->tm_cmds
.status
!= MPT2_CMD_NOT_USED
) {
1981 printk(MPT2SAS_INFO_FMT
"%s: tm_cmd busy!!!\n",
1982 __func__
, ioc
->name
);
1987 if (ioc
->shost_recovery
|| ioc
->remove_host
) {
1988 printk(MPT2SAS_INFO_FMT
"%s: host reset in progress!\n",
1989 __func__
, ioc
->name
);
1994 ioc_state
= mpt2sas_base_get_iocstate(ioc
, 0);
1995 if (ioc_state
& MPI2_DOORBELL_USED
) {
1996 dhsprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"unexpected doorbell "
1997 "active!\n", ioc
->name
));
1998 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2004 if ((ioc_state
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_FAULT
) {
2005 mpt2sas_base_fault_info(ioc
, ioc_state
&
2006 MPI2_DOORBELL_DATA_MASK
);
2007 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2013 smid
= mpt2sas_base_get_smid_hpr(ioc
, ioc
->tm_cb_idx
);
2015 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
2016 ioc
->name
, __func__
);
2021 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"sending tm: handle(0x%04x),"
2022 " task_type(0x%02x), smid(%d)\n", ioc
->name
, handle
, type
,
2024 ioc
->tm_cmds
.status
= MPT2_CMD_PENDING
;
2025 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
2026 ioc
->tm_cmds
.smid
= smid
;
2027 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
2028 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
2029 mpi_request
->DevHandle
= cpu_to_le16(handle
);
2030 mpi_request
->TaskType
= type
;
2031 mpi_request
->TaskMID
= cpu_to_le16(smid_task
);
2032 int_to_scsilun(lun
, (struct scsi_lun
*)mpi_request
->LUN
);
2033 mpt2sas_scsih_set_tm_flag(ioc
, handle
);
2034 init_completion(&ioc
->tm_cmds
.done
);
2035 mpt2sas_base_put_smid_hi_priority(ioc
, smid
);
2036 timeleft
= wait_for_completion_timeout(&ioc
->tm_cmds
.done
, timeout
*HZ
);
2037 if (!(ioc
->tm_cmds
.status
& MPT2_CMD_COMPLETE
)) {
2038 printk(MPT2SAS_ERR_FMT
"%s: timeout\n",
2039 ioc
->name
, __func__
);
2040 _debug_dump_mf(mpi_request
,
2041 sizeof(Mpi2SCSITaskManagementRequest_t
)/4);
2042 if (!(ioc
->tm_cmds
.status
& MPT2_CMD_RESET
)) {
2043 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2046 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
2047 mpt2sas_scsih_clear_tm_flag(ioc
, handle
);
2052 if (ioc
->tm_cmds
.status
& MPT2_CMD_REPLY_VALID
) {
2053 mpi_reply
= ioc
->tm_cmds
.reply
;
2054 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"complete tm: "
2055 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
2056 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
2057 le32_to_cpu(mpi_reply
->IOCLogInfo
),
2058 le32_to_cpu(mpi_reply
->TerminationCount
)));
2059 if (ioc
->logging_level
& MPT_DEBUG_TM
) {
2060 _scsih_response_code(ioc
, mpi_reply
->ResponseCode
);
2061 if (mpi_reply
->IOCStatus
)
2062 _debug_dump_mf(mpi_request
,
2063 sizeof(Mpi2SCSITaskManagementRequest_t
)/4);
2068 * Check to see the commands were terminated.
2069 * This is only needed for eh callbacks, hence the scmd check.
2073 goto bypass_sanity_checks
;
2075 case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
:
2076 scmd_lookup
= _scsih_scsi_lookup_get(ioc
, smid_task
);
2077 if (scmd_lookup
&& (scmd_lookup
->serial_number
==
2078 scmd
->serial_number
))
2084 case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
:
2085 if (_scsih_scsi_lookup_find_by_target(ioc
, id
, channel
))
2091 case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET
:
2092 if (_scsih_scsi_lookup_find_by_lun(ioc
, id
, lun
, channel
))
2099 bypass_sanity_checks
:
2101 mpt2sas_scsih_clear_tm_flag(ioc
, handle
);
2102 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
2103 mutex_unlock(&ioc
->tm_cmds
.mutex
);
2108 mutex_unlock(&ioc
->tm_cmds
.mutex
);
2113 * _scsih_abort - eh threads main abort routine
2114 * @sdev: scsi device struct
2116 * Returns SUCCESS if command aborted else FAILED
2119 _scsih_abort(struct scsi_cmnd
*scmd
)
2121 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2122 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2127 printk(MPT2SAS_INFO_FMT
"attempting task abort! scmd(%p)\n",
2129 scsi_print_command(scmd
);
2131 sas_device_priv_data
= scmd
->device
->hostdata
;
2132 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2133 printk(MPT2SAS_INFO_FMT
"device been deleted! scmd(%p)\n",
2135 scmd
->result
= DID_NO_CONNECT
<< 16;
2136 scmd
->scsi_done(scmd
);
2141 /* search for the command */
2142 smid
= _scsih_scsi_lookup_find_by_scmd(ioc
, scmd
);
2144 scmd
->result
= DID_RESET
<< 16;
2149 /* for hidden raid components and volumes this is not supported */
2150 if (sas_device_priv_data
->sas_target
->flags
&
2151 MPT_TARGET_FLAGS_RAID_COMPONENT
||
2152 sas_device_priv_data
->sas_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
2153 scmd
->result
= DID_RESET
<< 16;
2158 mpt2sas_halt_firmware(ioc
);
2160 handle
= sas_device_priv_data
->sas_target
->handle
;
2161 r
= mpt2sas_scsih_issue_tm(ioc
, handle
, scmd
->device
->channel
,
2162 scmd
->device
->id
, scmd
->device
->lun
,
2163 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
, smid
, 30, scmd
);
2166 printk(MPT2SAS_INFO_FMT
"task abort: %s scmd(%p)\n",
2167 ioc
->name
, ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2172 * _scsih_dev_reset - eh threads main device reset routine
2173 * @sdev: scsi device struct
2175 * Returns SUCCESS if command aborted else FAILED
2178 _scsih_dev_reset(struct scsi_cmnd
*scmd
)
2180 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2181 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2182 struct _sas_device
*sas_device
;
2183 unsigned long flags
;
2187 printk(MPT2SAS_INFO_FMT
"attempting device reset! scmd(%p)\n",
2189 scsi_print_command(scmd
);
2191 sas_device_priv_data
= scmd
->device
->hostdata
;
2192 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2193 printk(MPT2SAS_INFO_FMT
"device been deleted! scmd(%p)\n",
2195 scmd
->result
= DID_NO_CONNECT
<< 16;
2196 scmd
->scsi_done(scmd
);
2201 /* for hidden raid components obtain the volume_handle */
2203 if (sas_device_priv_data
->sas_target
->flags
&
2204 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2205 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2206 sas_device
= _scsih_sas_device_find_by_handle(ioc
,
2207 sas_device_priv_data
->sas_target
->handle
);
2209 handle
= sas_device
->volume_handle
;
2210 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2212 handle
= sas_device_priv_data
->sas_target
->handle
;
2215 scmd
->result
= DID_RESET
<< 16;
2220 r
= mpt2sas_scsih_issue_tm(ioc
, handle
, scmd
->device
->channel
,
2221 scmd
->device
->id
, scmd
->device
->lun
,
2222 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET
, 0, 30, scmd
);
2225 printk(MPT2SAS_INFO_FMT
"device reset: %s scmd(%p)\n",
2226 ioc
->name
, ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2231 * _scsih_target_reset - eh threads main target reset routine
2232 * @sdev: scsi device struct
2234 * Returns SUCCESS if command aborted else FAILED
2237 _scsih_target_reset(struct scsi_cmnd
*scmd
)
2239 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2240 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2241 struct _sas_device
*sas_device
;
2242 unsigned long flags
;
2246 printk(MPT2SAS_INFO_FMT
"attempting target reset! scmd(%p)\n",
2248 scsi_print_command(scmd
);
2250 sas_device_priv_data
= scmd
->device
->hostdata
;
2251 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2252 printk(MPT2SAS_INFO_FMT
"target been deleted! scmd(%p)\n",
2254 scmd
->result
= DID_NO_CONNECT
<< 16;
2255 scmd
->scsi_done(scmd
);
2260 /* for hidden raid components obtain the volume_handle */
2262 if (sas_device_priv_data
->sas_target
->flags
&
2263 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2264 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2265 sas_device
= _scsih_sas_device_find_by_handle(ioc
,
2266 sas_device_priv_data
->sas_target
->handle
);
2268 handle
= sas_device
->volume_handle
;
2269 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2271 handle
= sas_device_priv_data
->sas_target
->handle
;
2274 scmd
->result
= DID_RESET
<< 16;
2279 r
= mpt2sas_scsih_issue_tm(ioc
, handle
, scmd
->device
->channel
,
2280 scmd
->device
->id
, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
, 0,
2284 printk(MPT2SAS_INFO_FMT
"target reset: %s scmd(%p)\n",
2285 ioc
->name
, ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2290 * _scsih_host_reset - eh threads main host reset routine
2291 * @sdev: scsi device struct
2293 * Returns SUCCESS if command aborted else FAILED
2296 _scsih_host_reset(struct scsi_cmnd
*scmd
)
2298 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2301 printk(MPT2SAS_INFO_FMT
"attempting host reset! scmd(%p)\n",
2303 scsi_print_command(scmd
);
2305 retval
= mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2307 r
= (retval
< 0) ? FAILED
: SUCCESS
;
2308 printk(MPT2SAS_INFO_FMT
"host reset: %s scmd(%p)\n",
2309 ioc
->name
, ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2315 * _scsih_fw_event_add - insert and queue up fw_event
2316 * @ioc: per adapter object
2317 * @fw_event: object describing the event
2318 * Context: This function will acquire ioc->fw_event_lock.
2320 * This adds the firmware event object into link list, then queues it up to
2321 * be processed from user context.
2326 _scsih_fw_event_add(struct MPT2SAS_ADAPTER
*ioc
, struct fw_event_work
*fw_event
)
2328 unsigned long flags
;
2330 if (ioc
->firmware_event_thread
== NULL
)
2333 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2334 list_add_tail(&fw_event
->list
, &ioc
->fw_event_list
);
2335 INIT_DELAYED_WORK(&fw_event
->delayed_work
, _firmware_event_work
);
2336 queue_delayed_work(ioc
->firmware_event_thread
,
2337 &fw_event
->delayed_work
, 0);
2338 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2342 * _scsih_fw_event_free - delete fw_event
2343 * @ioc: per adapter object
2344 * @fw_event: object describing the event
2345 * Context: This function will acquire ioc->fw_event_lock.
2347 * This removes firmware event object from link list, frees associated memory.
2352 _scsih_fw_event_free(struct MPT2SAS_ADAPTER
*ioc
, struct fw_event_work
2355 unsigned long flags
;
2357 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2358 list_del(&fw_event
->list
);
2359 kfree(fw_event
->event_data
);
2361 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2366 * _scsih_queue_rescan - queue a topology rescan from user context
2367 * @ioc: per adapter object
2372 _scsih_queue_rescan(struct MPT2SAS_ADAPTER
*ioc
)
2374 struct fw_event_work
*fw_event
;
2376 if (ioc
->wait_for_port_enable_to_complete
)
2378 fw_event
= kzalloc(sizeof(struct fw_event_work
), GFP_ATOMIC
);
2381 fw_event
->event
= MPT2SAS_RESCAN_AFTER_HOST_RESET
;
2382 fw_event
->ioc
= ioc
;
2383 _scsih_fw_event_add(ioc
, fw_event
);
2387 * _scsih_fw_event_cleanup_queue - cleanup event queue
2388 * @ioc: per adapter object
2390 * Walk the firmware event queue, either killing timers, or waiting
2391 * for outstanding events to complete
2396 _scsih_fw_event_cleanup_queue(struct MPT2SAS_ADAPTER
*ioc
)
2398 struct fw_event_work
*fw_event
, *next
;
2400 if (list_empty(&ioc
->fw_event_list
) ||
2401 !ioc
->firmware_event_thread
|| in_interrupt())
2404 list_for_each_entry_safe(fw_event
, next
, &ioc
->fw_event_list
, list
) {
2405 if (cancel_delayed_work(&fw_event
->delayed_work
)) {
2406 _scsih_fw_event_free(ioc
, fw_event
);
2409 fw_event
->cancel_pending_work
= 1;
2414 * _scsih_ublock_io_device - set the device state to SDEV_RUNNING
2415 * @ioc: per adapter object
2416 * @handle: device handle
2418 * During device pull we need to appropiately set the sdev state.
2421 _scsih_ublock_io_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
2423 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2424 struct scsi_device
*sdev
;
2426 shost_for_each_device(sdev
, ioc
->shost
) {
2427 sas_device_priv_data
= sdev
->hostdata
;
2428 if (!sas_device_priv_data
)
2430 if (!sas_device_priv_data
->block
)
2432 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2433 dewtprintk(ioc
, sdev_printk(KERN_INFO
, sdev
,
2434 MPT2SAS_INFO_FMT
"SDEV_RUNNING: "
2435 "handle(0x%04x)\n", ioc
->name
, handle
));
2436 sas_device_priv_data
->block
= 0;
2437 scsi_internal_device_unblock(sdev
);
2443 * _scsih_block_io_device - set the device state to SDEV_BLOCK
2444 * @ioc: per adapter object
2445 * @handle: device handle
2447 * During device pull we need to appropiately set the sdev state.
2450 _scsih_block_io_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
2452 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2453 struct scsi_device
*sdev
;
2455 shost_for_each_device(sdev
, ioc
->shost
) {
2456 sas_device_priv_data
= sdev
->hostdata
;
2457 if (!sas_device_priv_data
)
2459 if (sas_device_priv_data
->block
)
2461 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2462 dewtprintk(ioc
, sdev_printk(KERN_INFO
, sdev
,
2463 MPT2SAS_INFO_FMT
"SDEV_BLOCK: "
2464 "handle(0x%04x)\n", ioc
->name
, handle
));
2465 sas_device_priv_data
->block
= 1;
2466 scsi_internal_device_block(sdev
);
2472 * _scsih_block_io_to_children_attached_to_ex
2473 * @ioc: per adapter object
2474 * @sas_expander: the sas_device object
2476 * This routine set sdev state to SDEV_BLOCK for all devices
2477 * attached to this expander. This function called when expander is
2481 _scsih_block_io_to_children_attached_to_ex(struct MPT2SAS_ADAPTER
*ioc
,
2482 struct _sas_node
*sas_expander
)
2484 struct _sas_port
*mpt2sas_port
;
2485 struct _sas_device
*sas_device
;
2486 struct _sas_node
*expander_sibling
;
2487 unsigned long flags
;
2492 list_for_each_entry(mpt2sas_port
,
2493 &sas_expander
->sas_port_list
, port_list
) {
2494 if (mpt2sas_port
->remote_identify
.device_type
==
2496 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2498 mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
2499 mpt2sas_port
->remote_identify
.sas_address
);
2500 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2503 _scsih_block_io_device(ioc
, sas_device
->handle
);
2507 list_for_each_entry(mpt2sas_port
,
2508 &sas_expander
->sas_port_list
, port_list
) {
2510 if (mpt2sas_port
->remote_identify
.device_type
==
2511 MPI2_SAS_DEVICE_INFO_EDGE_EXPANDER
||
2512 mpt2sas_port
->remote_identify
.device_type
==
2513 MPI2_SAS_DEVICE_INFO_FANOUT_EXPANDER
) {
2515 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
2517 mpt2sas_scsih_expander_find_by_sas_address(
2518 ioc
, mpt2sas_port
->remote_identify
.sas_address
);
2519 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
2520 _scsih_block_io_to_children_attached_to_ex(ioc
,
2527 * _scsih_block_io_to_children_attached_directly
2528 * @ioc: per adapter object
2529 * @event_data: topology change event data
2531 * This routine set sdev state to SDEV_BLOCK for all devices
2532 * direct attached during device pull.
2535 _scsih_block_io_to_children_attached_directly(struct MPT2SAS_ADAPTER
*ioc
,
2536 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
2543 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
2544 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
2547 phy_number
= event_data
->StartPhyNum
+ i
;
2548 reason_code
= event_data
->PHY
[i
].PhyStatus
&
2549 MPI2_EVENT_SAS_TOPO_RC_MASK
;
2550 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
)
2551 _scsih_block_io_device(ioc
, handle
);
2556 * _scsih_tm_tr_send - send task management request
2557 * @ioc: per adapter object
2558 * @handle: device handle
2559 * Context: interrupt time.
2561 * This code is to initiate the device removal handshake protocal
2562 * with controller firmware. This function will issue target reset
2563 * using high priority request queue. It will send a sas iounit
2564 * controll request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
2566 * This is designed to send muliple task management request at the same
2567 * time to the fifo. If the fifo is full, we will append the request,
2568 * and process it in a future completion.
2571 _scsih_tm_tr_send(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
2573 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
2575 struct _sas_device
*sas_device
;
2576 unsigned long flags
;
2577 struct _tr_list
*delayed_tr
;
2579 if (ioc
->shost_recovery
|| ioc
->remove_host
) {
2580 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host reset in "
2581 "progress!\n", __func__
, ioc
->name
));
2585 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2586 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
2587 if (sas_device
&& sas_device
->hidden_raid_component
) {
2588 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2591 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2593 smid
= mpt2sas_base_get_smid_hpr(ioc
, ioc
->tm_tr_cb_idx
);
2595 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
2598 INIT_LIST_HEAD(&delayed_tr
->list
);
2599 delayed_tr
->handle
= handle
;
2600 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_list
);
2601 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
2602 "DELAYED:tr:handle(0x%04x), (open)\n",
2603 ioc
->name
, handle
));
2607 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"tr_send:handle(0x%04x), "
2608 "(open), smid(%d), cb(%d)\n", ioc
->name
, handle
, smid
,
2609 ioc
->tm_tr_cb_idx
));
2610 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
2611 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
2612 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
2613 mpi_request
->DevHandle
= cpu_to_le16(handle
);
2614 mpi_request
->TaskType
= MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
;
2615 mpt2sas_base_put_smid_hi_priority(ioc
, smid
);
2621 * _scsih_sas_control_complete - completion routine
2622 * @ioc: per adapter object
2623 * @smid: system request message index
2624 * @msix_index: MSIX table index supplied by the OS
2625 * @reply: reply message frame(lower 32bit addr)
2626 * Context: interrupt time.
2628 * This is the sas iounit controll completion routine.
2629 * This code is part of the code to initiate the device removal
2630 * handshake protocal with controller firmware.
2632 * Return 1 meaning mf should be freed from _base_interrupt
2633 * 0 means the mf is freed from this function.
2636 _scsih_sas_control_complete(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
,
2637 u8 msix_index
, u32 reply
)
2639 Mpi2SasIoUnitControlReply_t
*mpi_reply
=
2640 mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
2642 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
2643 "sc_complete:handle(0x%04x), (open) "
2644 "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
2645 ioc
->name
, le16_to_cpu(mpi_reply
->DevHandle
), smid
,
2646 le16_to_cpu(mpi_reply
->IOCStatus
),
2647 le32_to_cpu(mpi_reply
->IOCLogInfo
)));
2652 * _scsih_tm_tr_complete -
2653 * @ioc: per adapter object
2654 * @smid: system request message index
2655 * @msix_index: MSIX table index supplied by the OS
2656 * @reply: reply message frame(lower 32bit addr)
2657 * Context: interrupt time.
2659 * This is the target reset completion routine.
2660 * This code is part of the code to initiate the device removal
2661 * handshake protocal with controller firmware.
2662 * It will send a sas iounit controll request (MPI2_SAS_OP_REMOVE_DEVICE)
2664 * Return 1 meaning mf should be freed from _base_interrupt
2665 * 0 means the mf is freed from this function.
2668 _scsih_tm_tr_complete(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
,
2672 Mpi2SCSITaskManagementRequest_t
*mpi_request_tm
;
2673 Mpi2SCSITaskManagementReply_t
*mpi_reply
=
2674 mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
2675 Mpi2SasIoUnitControlRequest_t
*mpi_request
;
2677 struct _tr_list
*delayed_tr
;
2679 if (ioc
->shost_recovery
|| ioc
->remove_host
) {
2680 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host reset in "
2681 "progress!\n", __func__
, ioc
->name
));
2685 mpi_request_tm
= mpt2sas_base_get_msg_frame(ioc
, smid
);
2686 handle
= le16_to_cpu(mpi_request_tm
->DevHandle
);
2687 if (handle
!= le16_to_cpu(mpi_reply
->DevHandle
)) {
2688 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"spurious interrupt: "
2689 "handle(0x%04x:0x%04x), smid(%d)!!!\n", ioc
->name
, handle
,
2690 le16_to_cpu(mpi_reply
->DevHandle
), smid
));
2694 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
2695 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
2696 "loginfo(0x%08x), completed(%d)\n", ioc
->name
,
2697 handle
, smid
, le16_to_cpu(mpi_reply
->IOCStatus
),
2698 le32_to_cpu(mpi_reply
->IOCLogInfo
),
2699 le32_to_cpu(mpi_reply
->TerminationCount
)));
2701 smid_sas_ctrl
= mpt2sas_base_get_smid(ioc
, ioc
->tm_sas_control_cb_idx
);
2702 if (!smid_sas_ctrl
) {
2703 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
2704 ioc
->name
, __func__
);
2708 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"sc_send:handle(0x%04x), "
2709 "(open), smid(%d), cb(%d)\n", ioc
->name
, handle
, smid_sas_ctrl
,
2710 ioc
->tm_sas_control_cb_idx
));
2711 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid_sas_ctrl
);
2712 memset(mpi_request
, 0, sizeof(Mpi2SasIoUnitControlRequest_t
));
2713 mpi_request
->Function
= MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
;
2714 mpi_request
->Operation
= MPI2_SAS_OP_REMOVE_DEVICE
;
2715 mpi_request
->DevHandle
= mpi_request_tm
->DevHandle
;
2716 mpt2sas_base_put_smid_default(ioc
, smid_sas_ctrl
);
2718 if (!list_empty(&ioc
->delayed_tr_list
)) {
2719 delayed_tr
= list_entry(ioc
->delayed_tr_list
.next
,
2720 struct _tr_list
, list
);
2721 mpt2sas_base_free_smid(ioc
, smid
);
2722 _scsih_tm_tr_send(ioc
, delayed_tr
->handle
);
2723 list_del(&delayed_tr
->list
);
2725 return 0; /* tells base_interrupt not to free mf */
2731 * _scsih_check_topo_delete_events - sanity check on topo events
2732 * @ioc: per adapter object
2733 * @event_data: the event data payload
2735 * This routine added to better handle cable breaker.
2737 * This handles the case where driver recieves multiple expander
2738 * add and delete events in a single shot. When there is a delete event
2739 * the routine will void any pending add events waiting in the event queue.
2744 _scsih_check_topo_delete_events(struct MPT2SAS_ADAPTER
*ioc
,
2745 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
2747 struct fw_event_work
*fw_event
;
2748 Mpi2EventDataSasTopologyChangeList_t
*local_event_data
;
2749 u16 expander_handle
;
2750 struct _sas_node
*sas_expander
;
2751 unsigned long flags
;
2755 for (i
= 0 ; i
< event_data
->NumEntries
; i
++) {
2756 if (event_data
->PHY
[i
].PhyStatus
&
2757 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT
)
2759 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
2762 reason_code
= event_data
->PHY
[i
].PhyStatus
&
2763 MPI2_EVENT_SAS_TOPO_RC_MASK
;
2764 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
)
2765 _scsih_tm_tr_send(ioc
, handle
);
2768 expander_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
2769 if (expander_handle
< ioc
->sas_hba
.num_phys
) {
2770 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
2774 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
2775 || event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
) {
2776 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
2777 sas_expander
= mpt2sas_scsih_expander_find_by_handle(ioc
,
2779 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
2780 _scsih_block_io_to_children_attached_to_ex(ioc
, sas_expander
);
2781 } else if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_RESPONDING
)
2782 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
2784 if (event_data
->ExpStatus
!= MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
)
2787 /* mark ignore flag for pending events */
2788 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2789 list_for_each_entry(fw_event
, &ioc
->fw_event_list
, list
) {
2790 if (fw_event
->event
!= MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
||
2793 local_event_data
= fw_event
->event_data
;
2794 if (local_event_data
->ExpStatus
==
2795 MPI2_EVENT_SAS_TOPO_ES_ADDED
||
2796 local_event_data
->ExpStatus
==
2797 MPI2_EVENT_SAS_TOPO_ES_RESPONDING
) {
2798 if (le16_to_cpu(local_event_data
->ExpanderDevHandle
) ==
2800 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
2801 "setting ignoring flag\n", ioc
->name
));
2802 fw_event
->ignore
= 1;
2806 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2810 * _scsih_flush_running_cmds - completing outstanding commands.
2811 * @ioc: per adapter object
2813 * The flushing out of all pending scmd commands following host reset,
2814 * where all IO is dropped to the floor.
2819 _scsih_flush_running_cmds(struct MPT2SAS_ADAPTER
*ioc
)
2821 struct scsi_cmnd
*scmd
;
2825 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
2826 scmd
= _scsih_scsi_lookup_get(ioc
, smid
);
2830 mpt2sas_base_free_smid(ioc
, smid
);
2831 scsi_dma_unmap(scmd
);
2832 scmd
->result
= DID_RESET
<< 16;
2833 scmd
->scsi_done(scmd
);
2835 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"completing %d cmds\n",
2840 * _scsih_setup_eedp - setup MPI request for EEDP transfer
2841 * @scmd: pointer to scsi command object
2842 * @mpi_request: pointer to the SCSI_IO reqest message frame
2844 * Supporting protection 1 and 3.
2849 _scsih_setup_eedp(struct scsi_cmnd
*scmd
, Mpi2SCSIIORequest_t
*mpi_request
)
2852 unsigned char prot_op
= scsi_get_prot_op(scmd
);
2853 unsigned char prot_type
= scsi_get_prot_type(scmd
);
2855 if (prot_type
== SCSI_PROT_DIF_TYPE0
||
2856 prot_type
== SCSI_PROT_DIF_TYPE2
||
2857 prot_op
== SCSI_PROT_NORMAL
)
2860 if (prot_op
== SCSI_PROT_READ_STRIP
)
2861 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP
;
2862 else if (prot_op
== SCSI_PROT_WRITE_INSERT
)
2863 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_INSERT_OP
;
2867 switch (prot_type
) {
2868 case SCSI_PROT_DIF_TYPE1
:
2871 * enable ref/guard checking
2872 * auto increment ref tag
2874 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG
|
2875 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG
|
2876 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
2877 mpi_request
->CDB
.EEDP32
.PrimaryReferenceTag
=
2878 cpu_to_be32(scsi_get_lba(scmd
));
2882 case SCSI_PROT_DIF_TYPE3
:
2885 * enable guard checking
2887 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
2890 mpi_request
->EEDPBlockSize
= cpu_to_le32(scmd
->device
->sector_size
);
2891 mpi_request
->EEDPFlags
= cpu_to_le16(eedp_flags
);
2895 * _scsih_eedp_error_handling - return sense code for EEDP errors
2896 * @scmd: pointer to scsi command object
2897 * @ioc_status: ioc status
2902 _scsih_eedp_error_handling(struct scsi_cmnd
*scmd
, u16 ioc_status
)
2908 switch (ioc_status
) {
2909 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
2912 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
2915 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
2923 if (scmd
->sc_data_direction
== DMA_TO_DEVICE
) {
2924 sk
= ILLEGAL_REQUEST
;
2925 host_byte
= DID_ABORT
;
2927 sk
= ABORTED_COMMAND
;
2931 scsi_build_sense_buffer(0, scmd
->sense_buffer
, sk
, 0x10, ascq
);
2932 scmd
->result
= DRIVER_SENSE
<< 24 | (host_byte
<< 16) |
2933 SAM_STAT_CHECK_CONDITION
;
2937 * _scsih_qcmd - main scsi request entry point
2938 * @scmd: pointer to scsi command object
2939 * @done: function pointer to be invoked on completion
2941 * The callback index is set inside `ioc->scsi_io_cb_idx`.
2943 * Returns 0 on success. If there's a failure, return either:
2944 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
2945 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
2948 _scsih_qcmd(struct scsi_cmnd
*scmd
, void (*done
)(struct scsi_cmnd
*))
2950 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2951 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2952 struct MPT2SAS_TARGET
*sas_target_priv_data
;
2953 Mpi2SCSIIORequest_t
*mpi_request
;
2957 scmd
->scsi_done
= done
;
2958 sas_device_priv_data
= scmd
->device
->hostdata
;
2959 if (!sas_device_priv_data
) {
2960 scmd
->result
= DID_NO_CONNECT
<< 16;
2961 scmd
->scsi_done(scmd
);
2965 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
2966 if (!sas_target_priv_data
|| sas_target_priv_data
->handle
==
2967 MPT2SAS_INVALID_DEVICE_HANDLE
|| sas_target_priv_data
->deleted
) {
2968 scmd
->result
= DID_NO_CONNECT
<< 16;
2969 scmd
->scsi_done(scmd
);
2973 /* see if we are busy with task managment stuff */
2974 if (sas_device_priv_data
->block
|| sas_target_priv_data
->tm_busy
)
2975 return SCSI_MLQUEUE_DEVICE_BUSY
;
2976 else if (ioc
->shost_recovery
|| ioc
->ioc_link_reset_in_progress
)
2977 return SCSI_MLQUEUE_HOST_BUSY
;
2979 if (scmd
->sc_data_direction
== DMA_FROM_DEVICE
)
2980 mpi_control
= MPI2_SCSIIO_CONTROL_READ
;
2981 else if (scmd
->sc_data_direction
== DMA_TO_DEVICE
)
2982 mpi_control
= MPI2_SCSIIO_CONTROL_WRITE
;
2984 mpi_control
= MPI2_SCSIIO_CONTROL_NODATATRANSFER
;
2987 if (!(sas_device_priv_data
->flags
& MPT_DEVICE_FLAGS_INIT
)) {
2988 if (scmd
->device
->tagged_supported
) {
2989 if (scmd
->device
->ordered_tags
)
2990 mpi_control
|= MPI2_SCSIIO_CONTROL_ORDEREDQ
;
2992 mpi_control
|= MPI2_SCSIIO_CONTROL_SIMPLEQ
;
2994 /* MPI Revision I (UNIT = 0xA) - removed MPI2_SCSIIO_CONTROL_UNTAGGED */
2995 /* mpi_control |= MPI2_SCSIIO_CONTROL_UNTAGGED;
2997 mpi_control
|= (0x500);
3000 mpi_control
|= MPI2_SCSIIO_CONTROL_SIMPLEQ
;
3001 /* Make sure Device is not raid volume */
3002 if (!_scsih_is_raid(&scmd
->device
->sdev_gendev
) &&
3003 sas_is_tlr_enabled(scmd
->device
))
3004 mpi_control
|= MPI2_SCSIIO_CONTROL_TLR_ON
;
3006 smid
= mpt2sas_base_get_smid_scsiio(ioc
, ioc
->scsi_io_cb_idx
, scmd
);
3008 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
3009 ioc
->name
, __func__
);
3012 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3013 memset(mpi_request
, 0, sizeof(Mpi2SCSIIORequest_t
));
3014 _scsih_setup_eedp(scmd
, mpi_request
);
3015 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
3016 if (sas_device_priv_data
->sas_target
->flags
&
3017 MPT_TARGET_FLAGS_RAID_COMPONENT
)
3018 mpi_request
->Function
= MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
;
3020 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
3021 mpi_request
->DevHandle
=
3022 cpu_to_le16(sas_device_priv_data
->sas_target
->handle
);
3023 mpi_request
->DataLength
= cpu_to_le32(scsi_bufflen(scmd
));
3024 mpi_request
->Control
= cpu_to_le32(mpi_control
);
3025 mpi_request
->IoFlags
= cpu_to_le16(scmd
->cmd_len
);
3026 mpi_request
->MsgFlags
= MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR
;
3027 mpi_request
->SenseBufferLength
= SCSI_SENSE_BUFFERSIZE
;
3028 mpi_request
->SenseBufferLowAddress
=
3029 mpt2sas_base_get_sense_buffer_dma(ioc
, smid
);
3030 mpi_request
->SGLOffset0
= offsetof(Mpi2SCSIIORequest_t
, SGL
) / 4;
3031 mpi_request
->SGLFlags
= cpu_to_le16(MPI2_SCSIIO_SGLFLAGS_TYPE_MPI
+
3032 MPI2_SCSIIO_SGLFLAGS_SYSTEM_ADDR
);
3033 mpi_request
->VF_ID
= 0; /* TODO */
3034 mpi_request
->VP_ID
= 0;
3035 int_to_scsilun(sas_device_priv_data
->lun
, (struct scsi_lun
*)
3037 memcpy(mpi_request
->CDB
.CDB32
, scmd
->cmnd
, scmd
->cmd_len
);
3039 if (!mpi_request
->DataLength
) {
3040 mpt2sas_base_build_zero_len_sge(ioc
, &mpi_request
->SGL
);
3042 if (_scsih_build_scatter_gather(ioc
, scmd
, smid
)) {
3043 mpt2sas_base_free_smid(ioc
, smid
);
3048 mpt2sas_base_put_smid_scsi_io(ioc
, smid
,
3049 sas_device_priv_data
->sas_target
->handle
);
3053 return SCSI_MLQUEUE_HOST_BUSY
;
3057 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
3058 * @sense_buffer: sense data returned by target
3059 * @data: normalized skey/asc/ascq
3064 _scsih_normalize_sense(char *sense_buffer
, struct sense_info
*data
)
3066 if ((sense_buffer
[0] & 0x7F) >= 0x72) {
3067 /* descriptor format */
3068 data
->skey
= sense_buffer
[1] & 0x0F;
3069 data
->asc
= sense_buffer
[2];
3070 data
->ascq
= sense_buffer
[3];
3073 data
->skey
= sense_buffer
[2] & 0x0F;
3074 data
->asc
= sense_buffer
[12];
3075 data
->ascq
= sense_buffer
[13];
3079 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3081 * _scsih_scsi_ioc_info - translated non-successfull SCSI_IO request
3082 * @ioc: per adapter object
3083 * @scmd: pointer to scsi command object
3084 * @mpi_reply: reply mf payload returned from firmware
3086 * scsi_status - SCSI Status code returned from target device
3087 * scsi_state - state info associated with SCSI_IO determined by ioc
3088 * ioc_status - ioc supplied status info
3093 _scsih_scsi_ioc_info(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
,
3094 Mpi2SCSIIOReply_t
*mpi_reply
, u16 smid
)
3098 u16 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) &
3099 MPI2_IOCSTATUS_MASK
;
3100 u8 scsi_state
= mpi_reply
->SCSIState
;
3101 u8 scsi_status
= mpi_reply
->SCSIStatus
;
3102 char *desc_ioc_state
= NULL
;
3103 char *desc_scsi_status
= NULL
;
3104 char *desc_scsi_state
= ioc
->tmp_string
;
3105 u32 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
3107 if (log_info
== 0x31170000)
3110 switch (ioc_status
) {
3111 case MPI2_IOCSTATUS_SUCCESS
:
3112 desc_ioc_state
= "success";
3114 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
3115 desc_ioc_state
= "invalid function";
3117 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
3118 desc_ioc_state
= "scsi recovered error";
3120 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE
:
3121 desc_ioc_state
= "scsi invalid dev handle";
3123 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
3124 desc_ioc_state
= "scsi device not there";
3126 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
3127 desc_ioc_state
= "scsi data overrun";
3129 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
3130 desc_ioc_state
= "scsi data underrun";
3132 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
3133 desc_ioc_state
= "scsi io data error";
3135 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
3136 desc_ioc_state
= "scsi protocol error";
3138 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
3139 desc_ioc_state
= "scsi task terminated";
3141 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
3142 desc_ioc_state
= "scsi residual mismatch";
3144 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
3145 desc_ioc_state
= "scsi task mgmt failed";
3147 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
3148 desc_ioc_state
= "scsi ioc terminated";
3150 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
3151 desc_ioc_state
= "scsi ext terminated";
3153 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
3154 desc_ioc_state
= "eedp guard error";
3156 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
3157 desc_ioc_state
= "eedp ref tag error";
3159 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
3160 desc_ioc_state
= "eedp app tag error";
3163 desc_ioc_state
= "unknown";
3167 switch (scsi_status
) {
3168 case MPI2_SCSI_STATUS_GOOD
:
3169 desc_scsi_status
= "good";
3171 case MPI2_SCSI_STATUS_CHECK_CONDITION
:
3172 desc_scsi_status
= "check condition";
3174 case MPI2_SCSI_STATUS_CONDITION_MET
:
3175 desc_scsi_status
= "condition met";
3177 case MPI2_SCSI_STATUS_BUSY
:
3178 desc_scsi_status
= "busy";
3180 case MPI2_SCSI_STATUS_INTERMEDIATE
:
3181 desc_scsi_status
= "intermediate";
3183 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET
:
3184 desc_scsi_status
= "intermediate condmet";
3186 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT
:
3187 desc_scsi_status
= "reservation conflict";
3189 case MPI2_SCSI_STATUS_COMMAND_TERMINATED
:
3190 desc_scsi_status
= "command terminated";
3192 case MPI2_SCSI_STATUS_TASK_SET_FULL
:
3193 desc_scsi_status
= "task set full";
3195 case MPI2_SCSI_STATUS_ACA_ACTIVE
:
3196 desc_scsi_status
= "aca active";
3198 case MPI2_SCSI_STATUS_TASK_ABORTED
:
3199 desc_scsi_status
= "task aborted";
3202 desc_scsi_status
= "unknown";
3206 desc_scsi_state
[0] = '\0';
3208 desc_scsi_state
= " ";
3209 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
3210 strcat(desc_scsi_state
, "response info ");
3211 if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
3212 strcat(desc_scsi_state
, "state terminated ");
3213 if (scsi_state
& MPI2_SCSI_STATE_NO_SCSI_STATUS
)
3214 strcat(desc_scsi_state
, "no status ");
3215 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_FAILED
)
3216 strcat(desc_scsi_state
, "autosense failed ");
3217 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
)
3218 strcat(desc_scsi_state
, "autosense valid ");
3220 scsi_print_command(scmd
);
3221 printk(MPT2SAS_WARN_FMT
"\tdev handle(0x%04x), "
3222 "ioc_status(%s)(0x%04x), smid(%d)\n", ioc
->name
,
3223 le16_to_cpu(mpi_reply
->DevHandle
), desc_ioc_state
,
3225 printk(MPT2SAS_WARN_FMT
"\trequest_len(%d), underflow(%d), "
3226 "resid(%d)\n", ioc
->name
, scsi_bufflen(scmd
), scmd
->underflow
,
3227 scsi_get_resid(scmd
));
3228 printk(MPT2SAS_WARN_FMT
"\ttag(%d), transfer_count(%d), "
3229 "sc->result(0x%08x)\n", ioc
->name
, le16_to_cpu(mpi_reply
->TaskTag
),
3230 le32_to_cpu(mpi_reply
->TransferCount
), scmd
->result
);
3231 printk(MPT2SAS_WARN_FMT
"\tscsi_status(%s)(0x%02x), "
3232 "scsi_state(%s)(0x%02x)\n", ioc
->name
, desc_scsi_status
,
3233 scsi_status
, desc_scsi_state
, scsi_state
);
3235 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
3236 struct sense_info data
;
3237 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
3238 printk(MPT2SAS_WARN_FMT
"\t[sense_key,asc,ascq]: "
3239 "[0x%02x,0x%02x,0x%02x], count(%d)\n", ioc
->name
, data
.skey
,
3240 data
.asc
, data
.ascq
, le32_to_cpu(mpi_reply
->SenseCount
));
3243 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
) {
3244 response_info
= le32_to_cpu(mpi_reply
->ResponseInfo
);
3245 response_bytes
= (u8
*)&response_info
;
3246 _scsih_response_code(ioc
, response_bytes
[0]);
3252 * _scsih_smart_predicted_fault - illuminate Fault LED
3253 * @ioc: per adapter object
3254 * @handle: device handle
3259 _scsih_smart_predicted_fault(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
3261 Mpi2SepReply_t mpi_reply
;
3262 Mpi2SepRequest_t mpi_request
;
3263 struct scsi_target
*starget
;
3264 struct MPT2SAS_TARGET
*sas_target_priv_data
;
3265 Mpi2EventNotificationReply_t
*event_reply
;
3266 Mpi2EventDataSasDeviceStatusChange_t
*event_data
;
3267 struct _sas_device
*sas_device
;
3269 unsigned long flags
;
3271 /* only handle non-raid devices */
3272 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
3273 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
3275 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3278 starget
= sas_device
->starget
;
3279 sas_target_priv_data
= starget
->hostdata
;
3281 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
) ||
3282 ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
))) {
3283 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3286 starget_printk(KERN_WARNING
, starget
, "predicted fault\n");
3287 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3289 if (ioc
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_IBM
) {
3290 memset(&mpi_request
, 0, sizeof(Mpi2SepRequest_t
));
3291 mpi_request
.Function
= MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR
;
3292 mpi_request
.Action
= MPI2_SEP_REQ_ACTION_WRITE_STATUS
;
3293 mpi_request
.SlotStatus
=
3294 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT
);
3295 mpi_request
.DevHandle
= cpu_to_le16(handle
);
3296 mpi_request
.Flags
= MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS
;
3297 if ((mpt2sas_base_scsi_enclosure_processor(ioc
, &mpi_reply
,
3298 &mpi_request
)) != 0) {
3299 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3300 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3304 if (mpi_reply
.IOCStatus
|| mpi_reply
.IOCLogInfo
) {
3305 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3306 "enclosure_processor: ioc_status (0x%04x), "
3307 "loginfo(0x%08x)\n", ioc
->name
,
3308 le16_to_cpu(mpi_reply
.IOCStatus
),
3309 le32_to_cpu(mpi_reply
.IOCLogInfo
)));
3314 /* insert into event log */
3315 sz
= offsetof(Mpi2EventNotificationReply_t
, EventData
) +
3316 sizeof(Mpi2EventDataSasDeviceStatusChange_t
);
3317 event_reply
= kzalloc(sz
, GFP_KERNEL
);
3319 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3320 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3324 event_reply
->Function
= MPI2_FUNCTION_EVENT_NOTIFICATION
;
3325 event_reply
->Event
=
3326 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
);
3327 event_reply
->MsgLength
= sz
/4;
3328 event_reply
->EventDataLength
=
3329 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t
)/4);
3330 event_data
= (Mpi2EventDataSasDeviceStatusChange_t
*)
3331 event_reply
->EventData
;
3332 event_data
->ReasonCode
= MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
;
3333 event_data
->ASC
= 0x5D;
3334 event_data
->DevHandle
= cpu_to_le16(handle
);
3335 event_data
->SASAddress
= cpu_to_le64(sas_target_priv_data
->sas_address
);
3336 mpt2sas_ctl_add_to_event_log(ioc
, event_reply
);
3341 * _scsih_io_done - scsi request callback
3342 * @ioc: per adapter object
3343 * @smid: system request message index
3344 * @msix_index: MSIX table index supplied by the OS
3345 * @reply: reply message frame(lower 32bit addr)
3347 * Callback handler when using _scsih_qcmd.
3349 * Return 1 meaning mf should be freed from _base_interrupt
3350 * 0 means the mf is freed from this function.
3353 _scsih_io_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
3355 Mpi2SCSIIORequest_t
*mpi_request
;
3356 Mpi2SCSIIOReply_t
*mpi_reply
;
3357 struct scsi_cmnd
*scmd
;
3363 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
3364 u32 response_code
= 0;
3366 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
3367 scmd
= _scsih_scsi_lookup_get(ioc
, smid
);
3371 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3373 if (mpi_reply
== NULL
) {
3374 scmd
->result
= DID_OK
<< 16;
3378 sas_device_priv_data
= scmd
->device
->hostdata
;
3379 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
||
3380 sas_device_priv_data
->sas_target
->deleted
) {
3381 scmd
->result
= DID_NO_CONNECT
<< 16;
3385 /* turning off TLR */
3386 scsi_state
= mpi_reply
->SCSIState
;
3387 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
3389 le32_to_cpu(mpi_reply
->ResponseInfo
) & 0xFF;
3390 if (!sas_device_priv_data
->tlr_snoop_check
) {
3391 sas_device_priv_data
->tlr_snoop_check
++;
3392 if (!_scsih_is_raid(&scmd
->device
->sdev_gendev
) &&
3393 sas_is_tlr_enabled(scmd
->device
) &&
3394 response_code
== MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
) {
3395 sas_disable_tlr(scmd
->device
);
3396 sdev_printk(KERN_INFO
, scmd
->device
, "TLR disabled\n");
3400 xfer_cnt
= le32_to_cpu(mpi_reply
->TransferCount
);
3401 scsi_set_resid(scmd
, scsi_bufflen(scmd
) - xfer_cnt
);
3402 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
);
3403 if (ioc_status
& MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE
)
3404 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
3407 ioc_status
&= MPI2_IOCSTATUS_MASK
;
3408 scsi_status
= mpi_reply
->SCSIStatus
;
3410 if (ioc_status
== MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
&& xfer_cnt
== 0 &&
3411 (scsi_status
== MPI2_SCSI_STATUS_BUSY
||
3412 scsi_status
== MPI2_SCSI_STATUS_RESERVATION_CONFLICT
||
3413 scsi_status
== MPI2_SCSI_STATUS_TASK_SET_FULL
)) {
3414 ioc_status
= MPI2_IOCSTATUS_SUCCESS
;
3417 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
3418 struct sense_info data
;
3419 const void *sense_data
= mpt2sas_base_get_sense_buffer(ioc
,
3421 u32 sz
= min_t(u32
, SCSI_SENSE_BUFFERSIZE
,
3422 le32_to_cpu(mpi_reply
->SenseCount
));
3423 memcpy(scmd
->sense_buffer
, sense_data
, sz
);
3424 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
3425 /* failure prediction threshold exceeded */
3426 if (data
.asc
== 0x5D)
3427 _scsih_smart_predicted_fault(ioc
,
3428 le16_to_cpu(mpi_reply
->DevHandle
));
3431 switch (ioc_status
) {
3432 case MPI2_IOCSTATUS_BUSY
:
3433 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES
:
3434 scmd
->result
= SAM_STAT_BUSY
;
3437 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
3438 scmd
->result
= DID_NO_CONNECT
<< 16;
3441 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
3442 if (sas_device_priv_data
->block
) {
3443 scmd
->result
= DID_TRANSPORT_DISRUPTED
<< 16;
3446 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
3447 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
3448 scmd
->result
= DID_RESET
<< 16;
3451 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
3452 if ((xfer_cnt
== 0) || (scmd
->underflow
> xfer_cnt
))
3453 scmd
->result
= DID_SOFT_ERROR
<< 16;
3455 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
3458 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
3459 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
3461 if ((scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
))
3464 if (xfer_cnt
< scmd
->underflow
) {
3465 if (scsi_status
== SAM_STAT_BUSY
)
3466 scmd
->result
= SAM_STAT_BUSY
;
3468 scmd
->result
= DID_SOFT_ERROR
<< 16;
3469 } else if (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
3470 MPI2_SCSI_STATE_NO_SCSI_STATUS
))
3471 scmd
->result
= DID_SOFT_ERROR
<< 16;
3472 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
3473 scmd
->result
= DID_RESET
<< 16;
3474 else if (!xfer_cnt
&& scmd
->cmnd
[0] == REPORT_LUNS
) {
3475 mpi_reply
->SCSIState
= MPI2_SCSI_STATE_AUTOSENSE_VALID
;
3476 mpi_reply
->SCSIStatus
= SAM_STAT_CHECK_CONDITION
;
3477 scmd
->result
= (DRIVER_SENSE
<< 24) |
3478 SAM_STAT_CHECK_CONDITION
;
3479 scmd
->sense_buffer
[0] = 0x70;
3480 scmd
->sense_buffer
[2] = ILLEGAL_REQUEST
;
3481 scmd
->sense_buffer
[12] = 0x20;
3482 scmd
->sense_buffer
[13] = 0;
3486 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
3487 scsi_set_resid(scmd
, 0);
3488 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
3489 case MPI2_IOCSTATUS_SUCCESS
:
3490 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
3491 if (response_code
==
3492 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
||
3493 (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
3494 MPI2_SCSI_STATE_NO_SCSI_STATUS
)))
3495 scmd
->result
= DID_SOFT_ERROR
<< 16;
3496 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
3497 scmd
->result
= DID_RESET
<< 16;
3500 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
3501 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
3502 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
3503 _scsih_eedp_error_handling(scmd
, ioc_status
);
3505 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
3506 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
3507 case MPI2_IOCSTATUS_INVALID_SGL
:
3508 case MPI2_IOCSTATUS_INTERNAL_ERROR
:
3509 case MPI2_IOCSTATUS_INVALID_FIELD
:
3510 case MPI2_IOCSTATUS_INVALID_STATE
:
3511 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
3512 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
3514 scmd
->result
= DID_SOFT_ERROR
<< 16;
3519 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3520 if (scmd
->result
&& (ioc
->logging_level
& MPT_DEBUG_REPLY
))
3521 _scsih_scsi_ioc_info(ioc
, scmd
, mpi_reply
, smid
);
3525 scsi_dma_unmap(scmd
);
3526 scmd
->scsi_done(scmd
);
3531 * _scsih_sas_host_refresh - refreshing sas host object contents
3532 * @ioc: per adapter object
3535 * During port enable, fw will send topology events for every device. Its
3536 * possible that the handles may change from the previous setting, so this
3537 * code keeping handles updating if changed.
3542 _scsih_sas_host_refresh(struct MPT2SAS_ADAPTER
*ioc
)
3547 Mpi2ConfigReply_t mpi_reply
;
3548 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
3549 u16 attached_handle
;
3551 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
3552 "updating handles for sas_host(0x%016llx)\n",
3553 ioc
->name
, (unsigned long long)ioc
->sas_hba
.sas_address
));
3555 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
3556 * sizeof(Mpi2SasIOUnit0PhyData_t
));
3557 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
3558 if (!sas_iounit_pg0
) {
3559 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3560 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3564 if ((mpt2sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
3565 sas_iounit_pg0
, sz
)) != 0)
3567 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
3568 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
3570 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
3572 ioc
->sas_hba
.handle
= le16_to_cpu(sas_iounit_pg0
->
3573 PhyData
[0].ControllerDevHandle
);
3574 ioc
->sas_hba
.phy
[i
].handle
= ioc
->sas_hba
.handle
;
3575 attached_handle
= le16_to_cpu(sas_iounit_pg0
->PhyData
[i
].
3577 mpt2sas_transport_update_links(ioc
, ioc
->sas_hba
.sas_address
,
3578 attached_handle
, i
, sas_iounit_pg0
->PhyData
[i
].
3579 NegotiatedLinkRate
>> 4);
3582 kfree(sas_iounit_pg0
);
3586 * _scsih_sas_host_add - create sas host object
3587 * @ioc: per adapter object
3589 * Creating host side data object, stored in ioc->sas_hba
3594 _scsih_sas_host_add(struct MPT2SAS_ADAPTER
*ioc
)
3597 Mpi2ConfigReply_t mpi_reply
;
3598 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
3599 Mpi2SasIOUnitPage1_t
*sas_iounit_pg1
= NULL
;
3600 Mpi2SasPhyPage0_t phy_pg0
;
3601 Mpi2SasDevicePage0_t sas_device_pg0
;
3602 Mpi2SasEnclosurePage0_t enclosure_pg0
;
3605 u16 device_missing_delay
;
3607 mpt2sas_config_get_number_hba_phys(ioc
, &ioc
->sas_hba
.num_phys
);
3608 if (!ioc
->sas_hba
.num_phys
) {
3609 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3610 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3614 /* sas_iounit page 0 */
3615 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
3616 sizeof(Mpi2SasIOUnit0PhyData_t
));
3617 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
3618 if (!sas_iounit_pg0
) {
3619 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3620 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3623 if ((mpt2sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
3624 sas_iounit_pg0
, sz
))) {
3625 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3626 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3629 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
3630 MPI2_IOCSTATUS_MASK
;
3631 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
3632 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3633 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3637 /* sas_iounit page 1 */
3638 sz
= offsetof(Mpi2SasIOUnitPage1_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
3639 sizeof(Mpi2SasIOUnit1PhyData_t
));
3640 sas_iounit_pg1
= kzalloc(sz
, GFP_KERNEL
);
3641 if (!sas_iounit_pg1
) {
3642 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3643 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3646 if ((mpt2sas_config_get_sas_iounit_pg1(ioc
, &mpi_reply
,
3647 sas_iounit_pg1
, sz
))) {
3648 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3649 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3652 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
3653 MPI2_IOCSTATUS_MASK
;
3654 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
3655 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3656 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3660 ioc
->io_missing_delay
=
3661 le16_to_cpu(sas_iounit_pg1
->IODeviceMissingDelay
);
3662 device_missing_delay
=
3663 le16_to_cpu(sas_iounit_pg1
->ReportDeviceMissingDelay
);
3664 if (device_missing_delay
& MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16
)
3665 ioc
->device_missing_delay
= (device_missing_delay
&
3666 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
) * 16;
3668 ioc
->device_missing_delay
= device_missing_delay
&
3669 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
;
3671 ioc
->sas_hba
.parent_dev
= &ioc
->shost
->shost_gendev
;
3672 ioc
->sas_hba
.phy
= kcalloc(ioc
->sas_hba
.num_phys
,
3673 sizeof(struct _sas_phy
), GFP_KERNEL
);
3674 if (!ioc
->sas_hba
.phy
) {
3675 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3676 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3679 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
3680 if ((mpt2sas_config_get_phy_pg0(ioc
, &mpi_reply
, &phy_pg0
,
3682 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3683 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3686 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
3687 MPI2_IOCSTATUS_MASK
;
3688 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
3689 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3690 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3695 ioc
->sas_hba
.handle
= le16_to_cpu(sas_iounit_pg0
->
3696 PhyData
[0].ControllerDevHandle
);
3697 ioc
->sas_hba
.phy
[i
].handle
= ioc
->sas_hba
.handle
;
3698 ioc
->sas_hba
.phy
[i
].phy_id
= i
;
3699 mpt2sas_transport_add_host_phy(ioc
, &ioc
->sas_hba
.phy
[i
],
3700 phy_pg0
, ioc
->sas_hba
.parent_dev
);
3702 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
3703 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, ioc
->sas_hba
.handle
))) {
3704 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3705 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3708 ioc
->sas_hba
.enclosure_handle
=
3709 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
3710 ioc
->sas_hba
.sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
3711 printk(MPT2SAS_INFO_FMT
"host_add: handle(0x%04x), "
3712 "sas_addr(0x%016llx), phys(%d)\n", ioc
->name
, ioc
->sas_hba
.handle
,
3713 (unsigned long long) ioc
->sas_hba
.sas_address
,
3714 ioc
->sas_hba
.num_phys
) ;
3716 if (ioc
->sas_hba
.enclosure_handle
) {
3717 if (!(mpt2sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
3719 MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
3720 ioc
->sas_hba
.enclosure_handle
))) {
3721 ioc
->sas_hba
.enclosure_logical_id
=
3722 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
3727 kfree(sas_iounit_pg1
);
3728 kfree(sas_iounit_pg0
);
3732 * _scsih_expander_add - creating expander object
3733 * @ioc: per adapter object
3734 * @handle: expander handle
3736 * Creating expander object, stored in ioc->sas_expander_list.
3738 * Return 0 for success, else error.
3741 _scsih_expander_add(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
3743 struct _sas_node
*sas_expander
;
3744 Mpi2ConfigReply_t mpi_reply
;
3745 Mpi2ExpanderPage0_t expander_pg0
;
3746 Mpi2ExpanderPage1_t expander_pg1
;
3747 Mpi2SasEnclosurePage0_t enclosure_pg0
;
3750 __le64 sas_address
, sas_address_parent
= 0;
3752 unsigned long flags
;
3753 struct _sas_port
*mpt2sas_port
= NULL
;
3759 if (ioc
->shost_recovery
)
3762 if ((mpt2sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
3763 MPI2_SAS_EXPAND_PGAD_FORM_HNDL
, handle
))) {
3764 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3765 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3769 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
3770 MPI2_IOCSTATUS_MASK
;
3771 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
3772 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3773 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3777 /* handle out of order topology events */
3778 parent_handle
= le16_to_cpu(expander_pg0
.ParentDevHandle
);
3779 if (_scsih_get_sas_address(ioc
, parent_handle
, &sas_address_parent
)
3781 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3782 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3785 if (sas_address_parent
!= ioc
->sas_hba
.sas_address
) {
3786 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
3787 sas_expander
= mpt2sas_scsih_expander_find_by_sas_address(ioc
,
3788 sas_address_parent
);
3789 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
3790 if (!sas_expander
) {
3791 rc
= _scsih_expander_add(ioc
, parent_handle
);
3797 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
3798 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
3799 sas_expander
= mpt2sas_scsih_expander_find_by_sas_address(ioc
,
3801 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
3806 sas_expander
= kzalloc(sizeof(struct _sas_node
),
3808 if (!sas_expander
) {
3809 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3810 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3814 sas_expander
->handle
= handle
;
3815 sas_expander
->num_phys
= expander_pg0
.NumPhys
;
3816 sas_expander
->sas_address_parent
= sas_address_parent
;
3817 sas_expander
->sas_address
= sas_address
;
3819 printk(MPT2SAS_INFO_FMT
"expander_add: handle(0x%04x),"
3820 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc
->name
,
3821 handle
, parent_handle
, (unsigned long long)
3822 sas_expander
->sas_address
, sas_expander
->num_phys
);
3824 if (!sas_expander
->num_phys
)
3826 sas_expander
->phy
= kcalloc(sas_expander
->num_phys
,
3827 sizeof(struct _sas_phy
), GFP_KERNEL
);
3828 if (!sas_expander
->phy
) {
3829 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3830 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3835 INIT_LIST_HEAD(&sas_expander
->sas_port_list
);
3836 mpt2sas_port
= mpt2sas_transport_port_add(ioc
, handle
,
3837 sas_address_parent
);
3838 if (!mpt2sas_port
) {
3839 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3840 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3844 sas_expander
->parent_dev
= &mpt2sas_port
->rphy
->dev
;
3846 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++) {
3847 if ((mpt2sas_config_get_expander_pg1(ioc
, &mpi_reply
,
3848 &expander_pg1
, i
, handle
))) {
3849 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3850 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3854 sas_expander
->phy
[i
].handle
= handle
;
3855 sas_expander
->phy
[i
].phy_id
= i
;
3857 if ((mpt2sas_transport_add_expander_phy(ioc
,
3858 &sas_expander
->phy
[i
], expander_pg1
,
3859 sas_expander
->parent_dev
))) {
3860 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3861 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3867 if (sas_expander
->enclosure_handle
) {
3868 if (!(mpt2sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
3869 &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
3870 sas_expander
->enclosure_handle
))) {
3871 sas_expander
->enclosure_logical_id
=
3872 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
3876 _scsih_expander_node_add(ioc
, sas_expander
);
3882 mpt2sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
3883 sas_address_parent
);
3884 kfree(sas_expander
);
3889 * _scsih_done - scsih callback handler.
3890 * @ioc: per adapter object
3891 * @smid: system request message index
3892 * @msix_index: MSIX table index supplied by the OS
3893 * @reply: reply message frame(lower 32bit addr)
3895 * Callback handler when sending internal generated message frames.
3896 * The callback index passed is `ioc->scsih_cb_idx`
3898 * Return 1 meaning mf should be freed from _base_interrupt
3899 * 0 means the mf is freed from this function.
3902 _scsih_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
3904 MPI2DefaultReply_t
*mpi_reply
;
3906 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
3907 if (ioc
->scsih_cmds
.status
== MPT2_CMD_NOT_USED
)
3909 if (ioc
->scsih_cmds
.smid
!= smid
)
3911 ioc
->scsih_cmds
.status
|= MPT2_CMD_COMPLETE
;
3913 memcpy(ioc
->scsih_cmds
.reply
, mpi_reply
,
3914 mpi_reply
->MsgLength
*4);
3915 ioc
->scsih_cmds
.status
|= MPT2_CMD_REPLY_VALID
;
3917 ioc
->scsih_cmds
.status
&= ~MPT2_CMD_PENDING
;
3918 complete(&ioc
->scsih_cmds
.done
);
3923 * _scsih_expander_remove - removing expander object
3924 * @ioc: per adapter object
3925 * @sas_address: expander sas_address
3930 _scsih_expander_remove(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
)
3932 struct _sas_node
*sas_expander
;
3933 unsigned long flags
;
3935 if (ioc
->shost_recovery
)
3938 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
3939 sas_expander
= mpt2sas_scsih_expander_find_by_sas_address(ioc
,
3941 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
3942 _scsih_expander_node_remove(ioc
, sas_expander
);
3946 * _scsih_check_access_status - check access flags
3947 * @ioc: per adapter object
3948 * @sas_address: sas address
3949 * @handle: sas device handle
3950 * @access_flags: errors returned during discovery of the device
3952 * Return 0 for success, else failure
3955 _scsih_check_access_status(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
,
3956 u16 handle
, u8 access_status
)
3961 switch (access_status
) {
3962 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS
:
3963 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION
:
3966 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED
:
3967 desc
= "sata capability failed";
3969 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT
:
3970 desc
= "sata affiliation conflict";
3972 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE
:
3973 desc
= "route not addressable";
3975 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE
:
3976 desc
= "smp error not addressable";
3978 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED
:
3979 desc
= "device blocked";
3981 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED
:
3982 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN
:
3983 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT
:
3984 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG
:
3985 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION
:
3986 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER
:
3987 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN
:
3988 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN
:
3989 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN
:
3990 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION
:
3991 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE
:
3992 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX
:
3993 desc
= "sata initialization failed";
4003 printk(MPT2SAS_ERR_FMT
"discovery errors(%s): sas_address(0x%016llx), "
4004 "handle(0x%04x)\n", ioc
->name
, desc
,
4005 (unsigned long long)sas_address
, handle
);
4010 _scsih_check_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
4012 Mpi2ConfigReply_t mpi_reply
;
4013 Mpi2SasDevicePage0_t sas_device_pg0
;
4014 struct _sas_device
*sas_device
;
4016 unsigned long flags
;
4018 struct scsi_target
*starget
;
4019 struct MPT2SAS_TARGET
*sas_target_priv_data
;
4022 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
4023 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
)))
4026 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
4027 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
4030 /* check if this is end device */
4031 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
4032 if (!(_scsih_is_end_device(device_info
)))
4035 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4036 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
4037 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
4041 printk(MPT2SAS_ERR_FMT
"device is not present "
4042 "handle(0x%04x), no sas_device!!!\n", ioc
->name
, handle
);
4043 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4047 if (unlikely(sas_device
->handle
!= handle
)) {
4048 starget
= sas_device
->starget
;
4049 sas_target_priv_data
= starget
->hostdata
;
4050 starget_printk(KERN_INFO
, starget
, "handle changed from(0x%04x)"
4051 " to (0x%04x)!!!\n", sas_device
->handle
, handle
);
4052 sas_target_priv_data
->handle
= handle
;
4053 sas_device
->handle
= handle
;
4055 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4057 /* check if device is present */
4058 if (!(le16_to_cpu(sas_device_pg0
.Flags
) &
4059 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT
)) {
4060 printk(MPT2SAS_ERR_FMT
"device is not present "
4061 "handle(0x%04x), flags!!!\n", ioc
->name
, handle
);
4065 /* check if there were any issues with discovery */
4066 if (_scsih_check_access_status(ioc
, sas_address
, handle
,
4067 sas_device_pg0
.AccessStatus
))
4069 _scsih_ublock_io_device(ioc
, handle
);
4074 * _scsih_add_device - creating sas device object
4075 * @ioc: per adapter object
4076 * @handle: sas device handle
4077 * @phy_num: phy number end device attached to
4078 * @is_pd: is this hidden raid component
4080 * Creating end device object, stored in ioc->sas_device_list.
4082 * Returns 0 for success, non-zero for failure.
4085 _scsih_add_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
, u8 phy_num
, u8 is_pd
)
4087 Mpi2ConfigReply_t mpi_reply
;
4088 Mpi2SasDevicePage0_t sas_device_pg0
;
4089 Mpi2SasEnclosurePage0_t enclosure_pg0
;
4090 struct _sas_device
*sas_device
;
4094 unsigned long flags
;
4096 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
4097 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
4098 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4099 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4103 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4104 MPI2_IOCSTATUS_MASK
;
4105 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4106 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4107 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4111 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
4113 /* check if device is present */
4114 if (!(le16_to_cpu(sas_device_pg0
.Flags
) &
4115 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT
)) {
4116 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4117 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4118 printk(MPT2SAS_ERR_FMT
"Flags = 0x%04x\n",
4119 ioc
->name
, le16_to_cpu(sas_device_pg0
.Flags
));
4123 /* check if there were any issues with discovery */
4124 if (_scsih_check_access_status(ioc
, sas_address
, handle
,
4125 sas_device_pg0
.AccessStatus
))
4128 /* check if this is end device */
4129 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
4130 if (!(_scsih_is_end_device(device_info
))) {
4131 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4132 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4137 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4138 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
4140 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4145 sas_device
= kzalloc(sizeof(struct _sas_device
),
4148 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4149 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4153 sas_device
->handle
= handle
;
4154 if (_scsih_get_sas_address(ioc
, le16_to_cpu
4155 (sas_device_pg0
.ParentDevHandle
),
4156 &sas_device
->sas_address_parent
) != 0)
4157 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4158 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4159 sas_device
->enclosure_handle
=
4160 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
4162 le16_to_cpu(sas_device_pg0
.Slot
);
4163 sas_device
->device_info
= device_info
;
4164 sas_device
->sas_address
= sas_address
;
4165 sas_device
->hidden_raid_component
= is_pd
;
4167 /* get enclosure_logical_id */
4168 if (sas_device
->enclosure_handle
&& !(mpt2sas_config_get_enclosure_pg0(
4169 ioc
, &mpi_reply
, &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
4170 sas_device
->enclosure_handle
)))
4171 sas_device
->enclosure_logical_id
=
4172 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
4174 /* get device name */
4175 sas_device
->device_name
= le64_to_cpu(sas_device_pg0
.DeviceName
);
4177 if (ioc
->wait_for_port_enable_to_complete
)
4178 _scsih_sas_device_init_add(ioc
, sas_device
);
4180 _scsih_sas_device_add(ioc
, sas_device
);
4186 * _scsih_remove_pd_device - removing sas device pd object
4187 * @ioc: per adapter object
4188 * @sas_device_delete: the sas_device object
4190 * For hidden raid components, we do driver-fw handshake from
4191 * hotplug work threads.
4195 _scsih_remove_pd_device(struct MPT2SAS_ADAPTER
*ioc
, struct _sas_device
4198 Mpi2SasIoUnitControlReply_t mpi_reply
;
4199 Mpi2SasIoUnitControlRequest_t mpi_request
;
4200 u16 vol_handle
, handle
;
4202 handle
= sas_device
.handle
;
4203 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: enter: handle(0x%04x),"
4204 " sas_addr(0x%016llx)\n", ioc
->name
, __func__
, handle
,
4205 (unsigned long long) sas_device
.sas_address
));
4207 vol_handle
= sas_device
.volume_handle
;
4210 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"issue target reset: "
4211 "handle(0x%04x)\n", ioc
->name
, vol_handle
));
4212 mpt2sas_scsih_issue_tm(ioc
, vol_handle
, 0, 0, 0,
4213 MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
, 0, 30, NULL
);
4214 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"issue target reset "
4215 "done: handle(0x%04x)\n", ioc
->name
, vol_handle
));
4216 if (ioc
->shost_recovery
)
4219 /* SAS_IO_UNIT_CNTR - send REMOVE_DEVICE */
4220 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"sas_iounit: handle"
4221 "(0x%04x)\n", ioc
->name
, handle
));
4222 memset(&mpi_request
, 0, sizeof(Mpi2SasIoUnitControlRequest_t
));
4223 mpi_request
.Function
= MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
;
4224 mpi_request
.Operation
= MPI2_SAS_OP_REMOVE_DEVICE
;
4225 mpi_request
.DevHandle
= cpu_to_le16(handle
);
4226 if ((mpt2sas_base_sas_iounit_control(ioc
, &mpi_reply
,
4227 &mpi_request
)) != 0)
4228 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4229 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4231 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"sas_iounit: ioc_status"
4232 "(0x%04x), loginfo(0x%08x)\n", ioc
->name
,
4233 le16_to_cpu(mpi_reply
.IOCStatus
),
4234 le32_to_cpu(mpi_reply
.IOCLogInfo
)));
4236 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: exit: handle(0x%04x),"
4237 " sas_addr(0x%016llx)\n", ioc
->name
, __func__
, handle
,
4238 (unsigned long long) sas_device
.sas_address
));
4242 * _scsih_remove_device - removing sas device object
4243 * @ioc: per adapter object
4244 * @sas_device_delete: the sas_device object
4249 _scsih_remove_device(struct MPT2SAS_ADAPTER
*ioc
,
4250 struct _sas_device
*sas_device
)
4252 struct _sas_device sas_device_backup
;
4253 struct MPT2SAS_TARGET
*sas_target_priv_data
;
4258 memcpy(&sas_device_backup
, sas_device
, sizeof(struct _sas_device
));
4259 _scsih_sas_device_remove(ioc
, sas_device
);
4261 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: enter: "
4262 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
, __func__
,
4263 sas_device_backup
.handle
, (unsigned long long)
4264 sas_device_backup
.sas_address
));
4266 if (sas_device_backup
.starget
&& sas_device_backup
.starget
->hostdata
) {
4267 sas_target_priv_data
= sas_device_backup
.starget
->hostdata
;
4268 sas_target_priv_data
->deleted
= 1;
4271 if (sas_device_backup
.hidden_raid_component
)
4272 _scsih_remove_pd_device(ioc
, sas_device_backup
);
4274 _scsih_ublock_io_device(ioc
, sas_device_backup
.handle
);
4276 mpt2sas_transport_port_remove(ioc
, sas_device_backup
.sas_address
,
4277 sas_device_backup
.sas_address_parent
);
4279 printk(MPT2SAS_INFO_FMT
"removing handle(0x%04x), sas_addr"
4280 "(0x%016llx)\n", ioc
->name
, sas_device_backup
.handle
,
4281 (unsigned long long) sas_device_backup
.sas_address
);
4283 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: exit: "
4284 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
, __func__
,
4285 sas_device_backup
.handle
, (unsigned long long)
4286 sas_device_backup
.sas_address
));
4289 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4291 * _scsih_sas_topology_change_event_debug - debug for topology event
4292 * @ioc: per adapter object
4293 * @event_data: event data payload
4297 _scsih_sas_topology_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
4298 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
4304 char *status_str
= NULL
;
4305 u8 link_rate
, prev_link_rate
;
4307 switch (event_data
->ExpStatus
) {
4308 case MPI2_EVENT_SAS_TOPO_ES_ADDED
:
4311 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
:
4312 status_str
= "remove";
4314 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING
:
4316 status_str
= "responding";
4318 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
:
4319 status_str
= "remove delay";
4322 status_str
= "unknown status";
4325 printk(MPT2SAS_DEBUG_FMT
"sas topology change: (%s)\n",
4326 ioc
->name
, status_str
);
4327 printk(KERN_DEBUG
"\thandle(0x%04x), enclosure_handle(0x%04x) "
4328 "start_phy(%02d), count(%d)\n",
4329 le16_to_cpu(event_data
->ExpanderDevHandle
),
4330 le16_to_cpu(event_data
->EnclosureHandle
),
4331 event_data
->StartPhyNum
, event_data
->NumEntries
);
4332 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
4333 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
4336 phy_number
= event_data
->StartPhyNum
+ i
;
4337 reason_code
= event_data
->PHY
[i
].PhyStatus
&
4338 MPI2_EVENT_SAS_TOPO_RC_MASK
;
4339 switch (reason_code
) {
4340 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
4341 status_str
= "target add";
4343 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
4344 status_str
= "target remove";
4346 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
:
4347 status_str
= "delay target remove";
4349 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
4350 status_str
= "link rate change";
4352 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE
:
4353 status_str
= "target responding";
4356 status_str
= "unknown";
4359 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
4360 prev_link_rate
= event_data
->PHY
[i
].LinkRate
& 0xF;
4361 printk(KERN_DEBUG
"\tphy(%02d), attached_handle(0x%04x): %s:"
4362 " link rate: new(0x%02x), old(0x%02x)\n", phy_number
,
4363 handle
, status_str
, link_rate
, prev_link_rate
);
4370 * _scsih_sas_topology_change_event - handle topology changes
4371 * @ioc: per adapter object
4372 * @fw_event: The fw_event_work object
4377 _scsih_sas_topology_change_event(struct MPT2SAS_ADAPTER
*ioc
,
4378 struct fw_event_work
*fw_event
)
4381 u16 parent_handle
, handle
;
4384 struct _sas_node
*sas_expander
;
4385 struct _sas_device
*sas_device
;
4387 unsigned long flags
;
4388 u8 link_rate
, prev_link_rate
;
4389 Mpi2EventDataSasTopologyChangeList_t
*event_data
= fw_event
->event_data
;
4391 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4392 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
4393 _scsih_sas_topology_change_event_debug(ioc
, event_data
);
4396 if (ioc
->shost_recovery
|| ioc
->remove_host
)
4399 if (!ioc
->sas_hba
.num_phys
)
4400 _scsih_sas_host_add(ioc
);
4402 _scsih_sas_host_refresh(ioc
);
4404 if (fw_event
->ignore
) {
4405 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"ignoring expander "
4406 "event\n", ioc
->name
));
4410 parent_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
4412 /* handle expander add */
4413 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_ADDED
)
4414 if (_scsih_expander_add(ioc
, parent_handle
) != 0)
4417 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
4418 sas_expander
= mpt2sas_scsih_expander_find_by_handle(ioc
,
4420 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
4422 sas_address
= sas_expander
->sas_address
;
4423 else if (parent_handle
< ioc
->sas_hba
.num_phys
)
4424 sas_address
= ioc
->sas_hba
.sas_address
;
4428 /* handle siblings events */
4429 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
4430 if (fw_event
->ignore
) {
4431 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"ignoring "
4432 "expander event\n", ioc
->name
));
4435 if (ioc
->shost_recovery
|| ioc
->remove_host
)
4437 phy_number
= event_data
->StartPhyNum
+ i
;
4438 reason_code
= event_data
->PHY
[i
].PhyStatus
&
4439 MPI2_EVENT_SAS_TOPO_RC_MASK
;
4440 if ((event_data
->PHY
[i
].PhyStatus
&
4441 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT
) && (reason_code
!=
4442 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
))
4444 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
4447 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
4448 prev_link_rate
= event_data
->PHY
[i
].LinkRate
& 0xF;
4449 switch (reason_code
) {
4450 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
4452 if (link_rate
== prev_link_rate
)
4455 mpt2sas_transport_update_links(ioc
, sas_address
,
4456 handle
, phy_number
, link_rate
);
4458 if (link_rate
< MPI2_SAS_NEG_LINK_RATE_1_5
)
4461 _scsih_check_device(ioc
, handle
);
4463 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
4465 mpt2sas_transport_update_links(ioc
, sas_address
,
4466 handle
, phy_number
, link_rate
);
4468 _scsih_add_device(ioc
, handle
, phy_number
, 0);
4470 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
4472 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4473 sas_device
= _scsih_sas_device_find_by_handle(ioc
,
4476 spin_unlock_irqrestore(&ioc
->sas_device_lock
,
4480 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4481 _scsih_remove_device(ioc
, sas_device
);
4486 /* handle expander removal */
4487 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
&&
4489 _scsih_expander_remove(ioc
, sas_address
);
4493 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4495 * _scsih_sas_device_status_change_event_debug - debug for device event
4496 * @event_data: event data payload
4502 _scsih_sas_device_status_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
4503 Mpi2EventDataSasDeviceStatusChange_t
*event_data
)
4505 char *reason_str
= NULL
;
4507 switch (event_data
->ReasonCode
) {
4508 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
:
4509 reason_str
= "smart data";
4511 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED
:
4512 reason_str
= "unsupported device discovered";
4514 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
:
4515 reason_str
= "internal device reset";
4517 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL
:
4518 reason_str
= "internal task abort";
4520 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL
:
4521 reason_str
= "internal task abort set";
4523 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL
:
4524 reason_str
= "internal clear task set";
4526 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL
:
4527 reason_str
= "internal query task";
4529 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE
:
4530 reason_str
= "sata init failure";
4532 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
:
4533 reason_str
= "internal device reset complete";
4535 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL
:
4536 reason_str
= "internal task abort complete";
4538 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION
:
4539 reason_str
= "internal async notification";
4541 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY
:
4542 reason_str
= "expander reduced functionality";
4544 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY
:
4545 reason_str
= "expander reduced functionality complete";
4548 reason_str
= "unknown reason";
4551 printk(MPT2SAS_DEBUG_FMT
"device status change: (%s)\n"
4552 "\thandle(0x%04x), sas address(0x%016llx)", ioc
->name
,
4553 reason_str
, le16_to_cpu(event_data
->DevHandle
),
4554 (unsigned long long)le64_to_cpu(event_data
->SASAddress
));
4555 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
)
4556 printk(MPT2SAS_DEBUG_FMT
", ASC(0x%x), ASCQ(0x%x)\n", ioc
->name
,
4557 event_data
->ASC
, event_data
->ASCQ
);
4558 printk(KERN_INFO
"\n");
4563 * _scsih_sas_device_status_change_event - handle device status change
4564 * @ioc: per adapter object
4565 * @fw_event: The fw_event_work object
4571 _scsih_sas_device_status_change_event(struct MPT2SAS_ADAPTER
*ioc
,
4572 struct fw_event_work
*fw_event
)
4574 struct MPT2SAS_TARGET
*target_priv_data
;
4575 struct _sas_device
*sas_device
;
4577 unsigned long flags
;
4578 Mpi2EventDataSasDeviceStatusChange_t
*event_data
=
4579 fw_event
->event_data
;
4581 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4582 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
4583 _scsih_sas_device_status_change_event_debug(ioc
,
4587 if (event_data
->ReasonCode
!=
4588 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
&&
4589 event_data
->ReasonCode
!=
4590 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
)
4593 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4594 sas_address
= le64_to_cpu(event_data
->SASAddress
);
4595 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
4597 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4599 if (!sas_device
|| !sas_device
->starget
)
4602 target_priv_data
= sas_device
->starget
->hostdata
;
4603 if (!target_priv_data
)
4606 if (event_data
->ReasonCode
==
4607 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
)
4608 target_priv_data
->tm_busy
= 1;
4610 target_priv_data
->tm_busy
= 0;
4613 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4615 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure event
4616 * @ioc: per adapter object
4617 * @event_data: event data payload
4623 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
4624 Mpi2EventDataSasEnclDevStatusChange_t
*event_data
)
4626 char *reason_str
= NULL
;
4628 switch (event_data
->ReasonCode
) {
4629 case MPI2_EVENT_SAS_ENCL_RC_ADDED
:
4630 reason_str
= "enclosure add";
4632 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING
:
4633 reason_str
= "enclosure remove";
4636 reason_str
= "unknown reason";
4640 printk(MPT2SAS_DEBUG_FMT
"enclosure status change: (%s)\n"
4641 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
4642 " number slots(%d)\n", ioc
->name
, reason_str
,
4643 le16_to_cpu(event_data
->EnclosureHandle
),
4644 (unsigned long long)le64_to_cpu(event_data
->EnclosureLogicalID
),
4645 le16_to_cpu(event_data
->StartSlot
));
4650 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
4651 * @ioc: per adapter object
4652 * @fw_event: The fw_event_work object
4658 _scsih_sas_enclosure_dev_status_change_event(struct MPT2SAS_ADAPTER
*ioc
,
4659 struct fw_event_work
*fw_event
)
4661 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4662 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
4663 _scsih_sas_enclosure_dev_status_change_event_debug(ioc
,
4664 fw_event
->event_data
);
4669 * _scsih_sas_broadcast_primative_event - handle broadcast events
4670 * @ioc: per adapter object
4671 * @fw_event: The fw_event_work object
4677 _scsih_sas_broadcast_primative_event(struct MPT2SAS_ADAPTER
*ioc
,
4678 struct fw_event_work
*fw_event
)
4680 struct scsi_cmnd
*scmd
;
4683 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
4684 u32 termination_count
;
4686 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
4687 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4688 Mpi2EventDataSasBroadcastPrimitive_t
*event_data
= fw_event
->event_data
;
4691 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"broadcast primative: "
4692 "phy number(%d), width(%d)\n", ioc
->name
, event_data
->PhyNum
,
4693 event_data
->PortWidth
));
4694 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: enter\n", ioc
->name
,
4697 termination_count
= 0;
4699 mpi_reply
= ioc
->tm_cmds
.reply
;
4700 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
4701 scmd
= _scsih_scsi_lookup_get(ioc
, smid
);
4704 sas_device_priv_data
= scmd
->device
->hostdata
;
4705 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
)
4707 /* skip hidden raid components */
4708 if (sas_device_priv_data
->sas_target
->flags
&
4709 MPT_TARGET_FLAGS_RAID_COMPONENT
)
4712 if (sas_device_priv_data
->sas_target
->flags
&
4713 MPT_TARGET_FLAGS_VOLUME
)
4716 handle
= sas_device_priv_data
->sas_target
->handle
;
4717 lun
= sas_device_priv_data
->lun
;
4720 mpt2sas_scsih_issue_tm(ioc
, handle
, 0, 0, lun
,
4721 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK
, smid
, 30, NULL
);
4722 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
4723 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
)
4724 & MPI2_IOCSTATUS_MASK
;
4725 if ((ioc_status
== MPI2_IOCSTATUS_SUCCESS
) &&
4726 (mpi_reply
->ResponseCode
==
4727 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
||
4728 mpi_reply
->ResponseCode
==
4729 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
))
4732 mpt2sas_scsih_issue_tm(ioc
, handle
, 0, 0, lun
,
4733 MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET
, 0, 30, NULL
);
4734 termination_count
+= le32_to_cpu(mpi_reply
->TerminationCount
);
4736 ioc
->broadcast_aen_busy
= 0;
4738 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
4739 "%s - exit, query_count = %d termination_count = %d\n",
4740 ioc
->name
, __func__
, query_count
, termination_count
));
4744 * _scsih_sas_discovery_event - handle discovery events
4745 * @ioc: per adapter object
4746 * @fw_event: The fw_event_work object
4752 _scsih_sas_discovery_event(struct MPT2SAS_ADAPTER
*ioc
,
4753 struct fw_event_work
*fw_event
)
4755 Mpi2EventDataSasDiscovery_t
*event_data
= fw_event
->event_data
;
4757 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4758 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
) {
4759 printk(MPT2SAS_DEBUG_FMT
"discovery event: (%s)", ioc
->name
,
4760 (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
) ?
4762 if (event_data
->DiscoveryStatus
)
4763 printk("discovery_status(0x%08x)",
4764 le32_to_cpu(event_data
->DiscoveryStatus
));
4769 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
&&
4770 !ioc
->sas_hba
.num_phys
)
4771 _scsih_sas_host_add(ioc
);
4775 * _scsih_reprobe_lun - reprobing lun
4776 * @sdev: scsi device struct
4777 * @no_uld_attach: sdev->no_uld_attach flag setting
4781 _scsih_reprobe_lun(struct scsi_device
*sdev
, void *no_uld_attach
)
4785 sdev
->no_uld_attach
= no_uld_attach
? 1 : 0;
4786 sdev_printk(KERN_INFO
, sdev
, "%s raid component\n",
4787 sdev
->no_uld_attach
? "hidding" : "exposing");
4788 rc
= scsi_device_reprobe(sdev
);
4792 * _scsih_reprobe_target - reprobing target
4793 * @starget: scsi target struct
4794 * @no_uld_attach: sdev->no_uld_attach flag setting
4796 * Note: no_uld_attach flag determines whether the disk device is attached
4797 * to block layer. A value of `1` means to not attach.
4800 _scsih_reprobe_target(struct scsi_target
*starget
, int no_uld_attach
)
4802 struct MPT2SAS_TARGET
*sas_target_priv_data
= starget
->hostdata
;
4805 sas_target_priv_data
->flags
|= MPT_TARGET_FLAGS_RAID_COMPONENT
;
4807 sas_target_priv_data
->flags
&= ~MPT_TARGET_FLAGS_RAID_COMPONENT
;
4809 starget_for_each_device(starget
, no_uld_attach
? (void *)1 : NULL
,
4810 _scsih_reprobe_lun
);
4813 * _scsih_sas_volume_add - add new volume
4814 * @ioc: per adapter object
4815 * @element: IR config element data
4821 _scsih_sas_volume_add(struct MPT2SAS_ADAPTER
*ioc
,
4822 Mpi2EventIrConfigElement_t
*element
)
4824 struct _raid_device
*raid_device
;
4825 unsigned long flags
;
4827 u16 handle
= le16_to_cpu(element
->VolDevHandle
);
4830 mpt2sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
4832 printk(MPT2SAS_ERR_FMT
4833 "failure at %s:%d/%s()!\n", ioc
->name
,
4834 __FILE__
, __LINE__
, __func__
);
4838 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
4839 raid_device
= _scsih_raid_device_find_by_wwid(ioc
, wwid
);
4840 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
4845 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
4847 printk(MPT2SAS_ERR_FMT
4848 "failure at %s:%d/%s()!\n", ioc
->name
,
4849 __FILE__
, __LINE__
, __func__
);
4853 raid_device
->id
= ioc
->sas_id
++;
4854 raid_device
->channel
= RAID_CHANNEL
;
4855 raid_device
->handle
= handle
;
4856 raid_device
->wwid
= wwid
;
4857 _scsih_raid_device_add(ioc
, raid_device
);
4858 if (!ioc
->wait_for_port_enable_to_complete
) {
4859 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
4860 raid_device
->id
, 0);
4862 _scsih_raid_device_remove(ioc
, raid_device
);
4864 _scsih_determine_boot_device(ioc
, raid_device
, 1);
4868 * _scsih_sas_volume_delete - delete volume
4869 * @ioc: per adapter object
4870 * @element: IR config element data
4876 _scsih_sas_volume_delete(struct MPT2SAS_ADAPTER
*ioc
,
4877 Mpi2EventIrConfigElement_t
*element
)
4879 struct _raid_device
*raid_device
;
4880 u16 handle
= le16_to_cpu(element
->VolDevHandle
);
4881 unsigned long flags
;
4882 struct MPT2SAS_TARGET
*sas_target_priv_data
;
4884 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
4885 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
4886 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
4889 if (raid_device
->starget
) {
4890 sas_target_priv_data
= raid_device
->starget
->hostdata
;
4891 sas_target_priv_data
->deleted
= 1;
4892 scsi_remove_target(&raid_device
->starget
->dev
);
4894 _scsih_raid_device_remove(ioc
, raid_device
);
4898 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
4899 * @ioc: per adapter object
4900 * @element: IR config element data
4906 _scsih_sas_pd_expose(struct MPT2SAS_ADAPTER
*ioc
,
4907 Mpi2EventIrConfigElement_t
*element
)
4909 struct _sas_device
*sas_device
;
4910 unsigned long flags
;
4911 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
4913 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4914 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
4915 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4919 /* exposing raid component */
4920 sas_device
->volume_handle
= 0;
4921 sas_device
->volume_wwid
= 0;
4922 sas_device
->hidden_raid_component
= 0;
4923 _scsih_reprobe_target(sas_device
->starget
, 0);
4927 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
4928 * @ioc: per adapter object
4929 * @element: IR config element data
4935 _scsih_sas_pd_hide(struct MPT2SAS_ADAPTER
*ioc
,
4936 Mpi2EventIrConfigElement_t
*element
)
4938 struct _sas_device
*sas_device
;
4939 unsigned long flags
;
4940 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
4942 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4943 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
4944 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4948 /* hiding raid component */
4949 mpt2sas_config_get_volume_handle(ioc
, handle
,
4950 &sas_device
->volume_handle
);
4951 mpt2sas_config_get_volume_wwid(ioc
, sas_device
->volume_handle
,
4952 &sas_device
->volume_wwid
);
4953 sas_device
->hidden_raid_component
= 1;
4954 _scsih_reprobe_target(sas_device
->starget
, 1);
4958 * _scsih_sas_pd_delete - delete pd component
4959 * @ioc: per adapter object
4960 * @element: IR config element data
4966 _scsih_sas_pd_delete(struct MPT2SAS_ADAPTER
*ioc
,
4967 Mpi2EventIrConfigElement_t
*element
)
4969 struct _sas_device
*sas_device
;
4970 unsigned long flags
;
4971 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
4973 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4974 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
4975 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4978 _scsih_remove_device(ioc
, sas_device
);
4982 * _scsih_sas_pd_add - remove pd component
4983 * @ioc: per adapter object
4984 * @element: IR config element data
4990 _scsih_sas_pd_add(struct MPT2SAS_ADAPTER
*ioc
,
4991 Mpi2EventIrConfigElement_t
*element
)
4993 struct _sas_device
*sas_device
;
4994 unsigned long flags
;
4995 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
4996 Mpi2ConfigReply_t mpi_reply
;
4997 Mpi2SasDevicePage0_t sas_device_pg0
;
5002 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5003 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
5004 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5006 sas_device
->hidden_raid_component
= 1;
5010 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
5011 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
5012 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5013 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5017 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5018 MPI2_IOCSTATUS_MASK
;
5019 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5020 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5021 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5025 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
5026 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
5027 mpt2sas_transport_update_links(ioc
, sas_address
, handle
,
5028 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
5030 _scsih_add_device(ioc
, handle
, 0, 1);
5033 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5035 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
5036 * @ioc: per adapter object
5037 * @event_data: event data payload
5043 _scsih_sas_ir_config_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
5044 Mpi2EventDataIrConfigChangeList_t
*event_data
)
5046 Mpi2EventIrConfigElement_t
*element
;
5049 char *reason_str
= NULL
, *element_str
= NULL
;
5051 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
5053 printk(MPT2SAS_DEBUG_FMT
"raid config change: (%s), elements(%d)\n",
5054 ioc
->name
, (le32_to_cpu(event_data
->Flags
) &
5055 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ?
5056 "foreign" : "native", event_data
->NumElements
);
5057 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
5058 switch (element
->ReasonCode
) {
5059 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
5062 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
5063 reason_str
= "remove";
5065 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE
:
5066 reason_str
= "no change";
5068 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
5069 reason_str
= "hide";
5071 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
5072 reason_str
= "unhide";
5074 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
5075 reason_str
= "volume_created";
5077 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
5078 reason_str
= "volume_deleted";
5080 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
5081 reason_str
= "pd_created";
5083 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
5084 reason_str
= "pd_deleted";
5087 reason_str
= "unknown reason";
5090 element_type
= le16_to_cpu(element
->ElementFlags
) &
5091 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK
;
5092 switch (element_type
) {
5093 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT
:
5094 element_str
= "volume";
5096 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT
:
5097 element_str
= "phys disk";
5099 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT
:
5100 element_str
= "hot spare";
5103 element_str
= "unknown element";
5106 printk(KERN_DEBUG
"\t(%s:%s), vol handle(0x%04x), "
5107 "pd handle(0x%04x), pd num(0x%02x)\n", element_str
,
5108 reason_str
, le16_to_cpu(element
->VolDevHandle
),
5109 le16_to_cpu(element
->PhysDiskDevHandle
),
5110 element
->PhysDiskNum
);
5116 * _scsih_sas_ir_config_change_event - handle ir configuration change events
5117 * @ioc: per adapter object
5118 * @fw_event: The fw_event_work object
5124 _scsih_sas_ir_config_change_event(struct MPT2SAS_ADAPTER
*ioc
,
5125 struct fw_event_work
*fw_event
)
5127 Mpi2EventIrConfigElement_t
*element
;
5130 Mpi2EventDataIrConfigChangeList_t
*event_data
= fw_event
->event_data
;
5132 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5133 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5134 _scsih_sas_ir_config_change_event_debug(ioc
, event_data
);
5137 foreign_config
= (le32_to_cpu(event_data
->Flags
) &
5138 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ? 1 : 0;
5140 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
5141 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
5143 switch (element
->ReasonCode
) {
5144 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
5145 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
5146 if (!foreign_config
)
5147 _scsih_sas_volume_add(ioc
, element
);
5149 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
5150 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
5151 if (!foreign_config
)
5152 _scsih_sas_volume_delete(ioc
, element
);
5154 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
5155 _scsih_sas_pd_hide(ioc
, element
);
5157 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
5158 _scsih_sas_pd_expose(ioc
, element
);
5160 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
5161 _scsih_sas_pd_add(ioc
, element
);
5163 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
5164 _scsih_sas_pd_delete(ioc
, element
);
5171 * _scsih_sas_ir_volume_event - IR volume event
5172 * @ioc: per adapter object
5173 * @fw_event: The fw_event_work object
5179 _scsih_sas_ir_volume_event(struct MPT2SAS_ADAPTER
*ioc
,
5180 struct fw_event_work
*fw_event
)
5183 unsigned long flags
;
5184 struct _raid_device
*raid_device
;
5188 struct MPT2SAS_TARGET
*sas_target_priv_data
;
5189 Mpi2EventDataIrVolume_t
*event_data
= fw_event
->event_data
;
5191 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED
)
5194 handle
= le16_to_cpu(event_data
->VolDevHandle
);
5195 state
= le32_to_cpu(event_data
->NewValue
);
5196 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: handle(0x%04x), "
5197 "old(0x%08x), new(0x%08x)\n", ioc
->name
, __func__
, handle
,
5198 le32_to_cpu(event_data
->PreviousValue
), state
));
5200 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5201 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
5202 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5205 case MPI2_RAID_VOL_STATE_MISSING
:
5206 case MPI2_RAID_VOL_STATE_FAILED
:
5209 if (raid_device
->starget
) {
5210 sas_target_priv_data
= raid_device
->starget
->hostdata
;
5211 sas_target_priv_data
->deleted
= 1;
5212 scsi_remove_target(&raid_device
->starget
->dev
);
5214 _scsih_raid_device_remove(ioc
, raid_device
);
5217 case MPI2_RAID_VOL_STATE_ONLINE
:
5218 case MPI2_RAID_VOL_STATE_DEGRADED
:
5219 case MPI2_RAID_VOL_STATE_OPTIMAL
:
5223 mpt2sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
5225 printk(MPT2SAS_ERR_FMT
5226 "failure at %s:%d/%s()!\n", ioc
->name
,
5227 __FILE__
, __LINE__
, __func__
);
5231 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
5233 printk(MPT2SAS_ERR_FMT
5234 "failure at %s:%d/%s()!\n", ioc
->name
,
5235 __FILE__
, __LINE__
, __func__
);
5239 raid_device
->id
= ioc
->sas_id
++;
5240 raid_device
->channel
= RAID_CHANNEL
;
5241 raid_device
->handle
= handle
;
5242 raid_device
->wwid
= wwid
;
5243 _scsih_raid_device_add(ioc
, raid_device
);
5244 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
5245 raid_device
->id
, 0);
5247 _scsih_raid_device_remove(ioc
, raid_device
);
5250 case MPI2_RAID_VOL_STATE_INITIALIZING
:
5257 * _scsih_sas_ir_physical_disk_event - PD event
5258 * @ioc: per adapter object
5259 * @fw_event: The fw_event_work object
5265 _scsih_sas_ir_physical_disk_event(struct MPT2SAS_ADAPTER
*ioc
,
5266 struct fw_event_work
*fw_event
)
5268 u16 handle
, parent_handle
;
5270 struct _sas_device
*sas_device
;
5271 unsigned long flags
;
5272 Mpi2ConfigReply_t mpi_reply
;
5273 Mpi2SasDevicePage0_t sas_device_pg0
;
5275 Mpi2EventDataIrPhysicalDisk_t
*event_data
= fw_event
->event_data
;
5278 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED
)
5281 handle
= le16_to_cpu(event_data
->PhysDiskDevHandle
);
5282 state
= le32_to_cpu(event_data
->NewValue
);
5284 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: handle(0x%04x), "
5285 "old(0x%08x), new(0x%08x)\n", ioc
->name
, __func__
, handle
,
5286 le32_to_cpu(event_data
->PreviousValue
), state
));
5288 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5289 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
5290 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5293 case MPI2_RAID_PD_STATE_ONLINE
:
5294 case MPI2_RAID_PD_STATE_DEGRADED
:
5295 case MPI2_RAID_PD_STATE_REBUILDING
:
5296 case MPI2_RAID_PD_STATE_OPTIMAL
:
5298 sas_device
->hidden_raid_component
= 1;
5302 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
5303 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
5305 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5306 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5310 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5311 MPI2_IOCSTATUS_MASK
;
5312 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5313 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5314 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5318 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
5319 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
5320 mpt2sas_transport_update_links(ioc
, sas_address
, handle
,
5321 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
5323 _scsih_add_device(ioc
, handle
, 0, 1);
5327 case MPI2_RAID_PD_STATE_OFFLINE
:
5328 case MPI2_RAID_PD_STATE_NOT_CONFIGURED
:
5329 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE
:
5330 case MPI2_RAID_PD_STATE_HOT_SPARE
:
5336 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5338 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
5339 * @ioc: per adapter object
5340 * @event_data: event data payload
5346 _scsih_sas_ir_operation_status_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
5347 Mpi2EventDataIrOperationStatus_t
*event_data
)
5349 char *reason_str
= NULL
;
5351 switch (event_data
->RAIDOperation
) {
5352 case MPI2_EVENT_IR_RAIDOP_RESYNC
:
5353 reason_str
= "resync";
5355 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION
:
5356 reason_str
= "online capacity expansion";
5358 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK
:
5359 reason_str
= "consistency check";
5361 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT
:
5362 reason_str
= "background init";
5364 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT
:
5365 reason_str
= "make data consistent";
5372 printk(MPT2SAS_INFO_FMT
"raid operational status: (%s)"
5373 "\thandle(0x%04x), percent complete(%d)\n",
5374 ioc
->name
, reason_str
,
5375 le16_to_cpu(event_data
->VolDevHandle
),
5376 event_data
->PercentComplete
);
5381 * _scsih_sas_ir_operation_status_event - handle RAID operation events
5382 * @ioc: per adapter object
5383 * @fw_event: The fw_event_work object
5389 _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER
*ioc
,
5390 struct fw_event_work
*fw_event
)
5392 Mpi2EventDataIrOperationStatus_t
*event_data
= fw_event
->event_data
;
5393 static struct _raid_device
*raid_device
;
5394 unsigned long flags
;
5397 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5398 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5399 _scsih_sas_ir_operation_status_event_debug(ioc
,
5403 /* code added for raid transport support */
5404 if (event_data
->RAIDOperation
== MPI2_EVENT_IR_RAIDOP_RESYNC
) {
5406 handle
= le16_to_cpu(event_data
->VolDevHandle
);
5408 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5409 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
5410 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5415 if (event_data
->RAIDOperation
== MPI2_EVENT_IR_RAIDOP_RESYNC
)
5416 raid_device
->percent_complete
=
5417 event_data
->PercentComplete
;
5422 * _scsih_task_set_full - handle task set full
5423 * @ioc: per adapter object
5424 * @fw_event: The fw_event_work object
5427 * Throttle back qdepth.
5430 _scsih_task_set_full(struct MPT2SAS_ADAPTER
*ioc
, struct fw_event_work
5433 unsigned long flags
;
5434 struct _sas_device
*sas_device
;
5435 static struct _raid_device
*raid_device
;
5436 struct scsi_device
*sdev
;
5442 Mpi2EventDataTaskSetFull_t
*event_data
= fw_event
->event_data
;
5444 current_depth
= le16_to_cpu(event_data
->CurrentDepth
);
5445 handle
= le16_to_cpu(event_data
->DevHandle
);
5446 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5447 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
5449 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5452 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5453 id
= sas_device
->id
;
5454 channel
= sas_device
->channel
;
5455 sas_address
= sas_device
->sas_address
;
5457 /* if hidden raid component, then change to volume characteristics */
5458 if (sas_device
->hidden_raid_component
&& sas_device
->volume_handle
) {
5459 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5460 raid_device
= _scsih_raid_device_find_by_handle(
5461 ioc
, sas_device
->volume_handle
);
5462 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5464 id
= raid_device
->id
;
5465 channel
= raid_device
->channel
;
5466 handle
= raid_device
->handle
;
5467 sas_address
= raid_device
->wwid
;
5471 if (ioc
->logging_level
& MPT_DEBUG_TASK_SET_FULL
)
5472 starget_printk(KERN_DEBUG
, sas_device
->starget
, "task set "
5473 "full: handle(0x%04x), sas_addr(0x%016llx), depth(%d)\n",
5474 handle
, (unsigned long long)sas_address
, current_depth
);
5476 shost_for_each_device(sdev
, ioc
->shost
) {
5477 if (sdev
->id
== id
&& sdev
->channel
== channel
) {
5478 if (current_depth
> sdev
->queue_depth
) {
5479 if (ioc
->logging_level
&
5480 MPT_DEBUG_TASK_SET_FULL
)
5481 sdev_printk(KERN_INFO
, sdev
, "strange "
5482 "observation, the queue depth is"
5483 " (%d) meanwhile fw queue depth "
5484 "is (%d)\n", sdev
->queue_depth
,
5488 depth
= scsi_track_queue_full(sdev
,
5491 sdev_printk(KERN_INFO
, sdev
, "Queue depth "
5492 "reduced to (%d)\n", depth
);
5494 sdev_printk(KERN_INFO
, sdev
, "Tagged Command "
5495 "Queueing is being disabled\n");
5496 else if (depth
== 0)
5497 if (ioc
->logging_level
&
5498 MPT_DEBUG_TASK_SET_FULL
)
5499 sdev_printk(KERN_INFO
, sdev
,
5500 "Queue depth not changed yet\n");
5506 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
5507 * @ioc: per adapter object
5508 * @sas_address: sas address
5509 * @slot: enclosure slot id
5510 * @handle: device handle
5512 * After host reset, find out whether devices are still responding.
5513 * Used in _scsi_remove_unresponsive_sas_devices.
5518 _scsih_mark_responding_sas_device(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
,
5519 u16 slot
, u16 handle
)
5521 struct MPT2SAS_TARGET
*sas_target_priv_data
;
5522 struct scsi_target
*starget
;
5523 struct _sas_device
*sas_device
;
5524 unsigned long flags
;
5526 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5527 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
) {
5528 if (sas_device
->sas_address
== sas_address
&&
5529 sas_device
->slot
== slot
&& sas_device
->starget
) {
5530 sas_device
->responding
= 1;
5531 starget
= sas_device
->starget
;
5532 sas_target_priv_data
= starget
->hostdata
;
5533 sas_target_priv_data
->tm_busy
= 0;
5534 starget_printk(KERN_INFO
, sas_device
->starget
,
5535 "handle(0x%04x), sas_addr(0x%016llx), enclosure "
5536 "logical id(0x%016llx), slot(%d)\n", handle
,
5537 (unsigned long long)sas_device
->sas_address
,
5538 (unsigned long long)
5539 sas_device
->enclosure_logical_id
,
5541 if (sas_device
->handle
== handle
)
5543 printk(KERN_INFO
"\thandle changed from(0x%04x)!!!\n",
5544 sas_device
->handle
);
5545 sas_device
->handle
= handle
;
5546 sas_target_priv_data
->handle
= handle
;
5551 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5555 * _scsih_search_responding_sas_devices -
5556 * @ioc: per adapter object
5558 * After host reset, find out whether devices are still responding.
5564 _scsih_search_responding_sas_devices(struct MPT2SAS_ADAPTER
*ioc
)
5566 Mpi2SasDevicePage0_t sas_device_pg0
;
5567 Mpi2ConfigReply_t mpi_reply
;
5574 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
, __func__
);
5576 if (list_empty(&ioc
->sas_device_list
))
5580 while (!(mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
5581 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
,
5583 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5584 MPI2_IOCSTATUS_MASK
;
5585 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
5587 handle
= le16_to_cpu(sas_device_pg0
.DevHandle
);
5588 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
5589 if (!(_scsih_is_end_device(device_info
)))
5591 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
5592 slot
= le16_to_cpu(sas_device_pg0
.Slot
);
5593 _scsih_mark_responding_sas_device(ioc
, sas_address
, slot
,
5599 * _scsih_mark_responding_raid_device - mark a raid_device as responding
5600 * @ioc: per adapter object
5601 * @wwid: world wide identifier for raid volume
5602 * @handle: device handle
5604 * After host reset, find out whether devices are still responding.
5605 * Used in _scsi_remove_unresponsive_raid_devices.
5610 _scsih_mark_responding_raid_device(struct MPT2SAS_ADAPTER
*ioc
, u64 wwid
,
5613 struct MPT2SAS_TARGET
*sas_target_priv_data
;
5614 struct scsi_target
*starget
;
5615 struct _raid_device
*raid_device
;
5616 unsigned long flags
;
5618 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5619 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
5620 if (raid_device
->wwid
== wwid
&& raid_device
->starget
) {
5621 raid_device
->responding
= 1;
5622 starget_printk(KERN_INFO
, raid_device
->starget
,
5623 "handle(0x%04x), wwid(0x%016llx)\n", handle
,
5624 (unsigned long long)raid_device
->wwid
);
5625 if (raid_device
->handle
== handle
)
5627 printk(KERN_INFO
"\thandle changed from(0x%04x)!!!\n",
5628 raid_device
->handle
);
5629 raid_device
->handle
= handle
;
5630 starget
= raid_device
->starget
;
5631 sas_target_priv_data
= starget
->hostdata
;
5632 sas_target_priv_data
->handle
= handle
;
5637 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5641 * _scsih_search_responding_raid_devices -
5642 * @ioc: per adapter object
5644 * After host reset, find out whether devices are still responding.
5650 _scsih_search_responding_raid_devices(struct MPT2SAS_ADAPTER
*ioc
)
5652 Mpi2RaidVolPage1_t volume_pg1
;
5653 Mpi2ConfigReply_t mpi_reply
;
5657 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
, __func__
);
5659 if (list_empty(&ioc
->raid_device_list
))
5663 while (!(mpt2sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
5664 &volume_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
5665 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5666 MPI2_IOCSTATUS_MASK
;
5667 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
5669 handle
= le16_to_cpu(volume_pg1
.DevHandle
);
5670 _scsih_mark_responding_raid_device(ioc
,
5671 le64_to_cpu(volume_pg1
.WWID
), handle
);
5676 * _scsih_mark_responding_expander - mark a expander as responding
5677 * @ioc: per adapter object
5678 * @sas_address: sas address
5681 * After host reset, find out whether devices are still responding.
5682 * Used in _scsi_remove_unresponsive_expanders.
5687 _scsih_mark_responding_expander(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
,
5690 struct _sas_node
*sas_expander
;
5691 unsigned long flags
;
5694 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5695 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
5696 if (sas_expander
->sas_address
!= sas_address
)
5698 sas_expander
->responding
= 1;
5699 if (sas_expander
->handle
== handle
)
5701 printk(KERN_INFO
"\texpander(0x%016llx): handle changed"
5702 " from(0x%04x) to (0x%04x)!!!\n",
5703 (unsigned long long)sas_expander
->sas_address
,
5704 sas_expander
->handle
, handle
);
5705 sas_expander
->handle
= handle
;
5706 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++)
5707 sas_expander
->phy
[i
].handle
= handle
;
5711 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5715 * _scsih_search_responding_expanders -
5716 * @ioc: per adapter object
5718 * After host reset, find out whether devices are still responding.
5724 _scsih_search_responding_expanders(struct MPT2SAS_ADAPTER
*ioc
)
5726 Mpi2ExpanderPage0_t expander_pg0
;
5727 Mpi2ConfigReply_t mpi_reply
;
5732 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
, __func__
);
5734 if (list_empty(&ioc
->sas_expander_list
))
5738 while (!(mpt2sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
5739 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL
, handle
))) {
5741 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5742 MPI2_IOCSTATUS_MASK
;
5743 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
5746 handle
= le16_to_cpu(expander_pg0
.DevHandle
);
5747 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
5748 printk(KERN_INFO
"\texpander present: handle(0x%04x), "
5749 "sas_addr(0x%016llx)\n", handle
,
5750 (unsigned long long)sas_address
);
5751 _scsih_mark_responding_expander(ioc
, sas_address
, handle
);
5757 * _scsih_remove_unresponding_sas_devices - removing unresponding devices
5758 * @ioc: per adapter object
5763 _scsih_remove_unresponding_sas_devices(struct MPT2SAS_ADAPTER
*ioc
)
5765 struct _sas_device
*sas_device
, *sas_device_next
;
5766 struct _sas_node
*sas_expander
;
5767 struct _raid_device
*raid_device
, *raid_device_next
;
5770 list_for_each_entry_safe(sas_device
, sas_device_next
,
5771 &ioc
->sas_device_list
, list
) {
5772 if (sas_device
->responding
) {
5773 sas_device
->responding
= 0;
5776 if (sas_device
->starget
)
5777 starget_printk(KERN_INFO
, sas_device
->starget
,
5778 "removing: handle(0x%04x), sas_addr(0x%016llx), "
5779 "enclosure logical id(0x%016llx), slot(%d)\n",
5781 (unsigned long long)sas_device
->sas_address
,
5782 (unsigned long long)
5783 sas_device
->enclosure_logical_id
,
5785 _scsih_remove_device(ioc
, sas_device
);
5788 list_for_each_entry_safe(raid_device
, raid_device_next
,
5789 &ioc
->raid_device_list
, list
) {
5790 if (raid_device
->responding
) {
5791 raid_device
->responding
= 0;
5794 if (raid_device
->starget
) {
5795 starget_printk(KERN_INFO
, raid_device
->starget
,
5796 "removing: handle(0x%04x), wwid(0x%016llx)\n",
5797 raid_device
->handle
,
5798 (unsigned long long)raid_device
->wwid
);
5799 scsi_remove_target(&raid_device
->starget
->dev
);
5801 _scsih_raid_device_remove(ioc
, raid_device
);
5804 retry_expander_search
:
5805 sas_expander
= NULL
;
5806 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
5807 if (sas_expander
->responding
) {
5808 sas_expander
->responding
= 0;
5811 _scsih_expander_remove(ioc
, sas_expander
->sas_address
);
5812 goto retry_expander_search
;
5817 * mpt2sas_scsih_reset_handler - reset callback handler (for scsih)
5818 * @ioc: per adapter object
5819 * @reset_phase: phase
5821 * The handler for doing any required cleanup or initialization.
5823 * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
5824 * MPT2_IOC_DONE_RESET
5829 mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER
*ioc
, int reset_phase
)
5831 switch (reset_phase
) {
5832 case MPT2_IOC_PRE_RESET
:
5833 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: "
5834 "MPT2_IOC_PRE_RESET\n", ioc
->name
, __func__
));
5836 case MPT2_IOC_AFTER_RESET
:
5837 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: "
5838 "MPT2_IOC_AFTER_RESET\n", ioc
->name
, __func__
));
5839 if (ioc
->scsih_cmds
.status
& MPT2_CMD_PENDING
) {
5840 ioc
->scsih_cmds
.status
|= MPT2_CMD_RESET
;
5841 mpt2sas_base_free_smid(ioc
, ioc
->scsih_cmds
.smid
);
5842 complete(&ioc
->scsih_cmds
.done
);
5844 if (ioc
->tm_cmds
.status
& MPT2_CMD_PENDING
) {
5845 ioc
->tm_cmds
.status
|= MPT2_CMD_RESET
;
5846 mpt2sas_base_free_smid(ioc
, ioc
->tm_cmds
.smid
);
5847 complete(&ioc
->tm_cmds
.done
);
5849 _scsih_fw_event_cleanup_queue(ioc
);
5850 _scsih_flush_running_cmds(ioc
);
5851 _scsih_queue_rescan(ioc
);
5853 case MPT2_IOC_DONE_RESET
:
5854 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: "
5855 "MPT2_IOC_DONE_RESET\n", ioc
->name
, __func__
));
5856 _scsih_sas_host_refresh(ioc
);
5862 * _firmware_event_work - delayed task for processing firmware events
5863 * @ioc: per adapter object
5864 * @work: equal to the fw_event_work object
5870 _firmware_event_work(struct work_struct
*work
)
5872 struct fw_event_work
*fw_event
= container_of(work
,
5873 struct fw_event_work
, delayed_work
.work
);
5874 unsigned long flags
;
5875 struct MPT2SAS_ADAPTER
*ioc
= fw_event
->ioc
;
5877 /* the queue is being flushed so ignore this event */
5878 if (ioc
->remove_host
|| fw_event
->cancel_pending_work
) {
5879 _scsih_fw_event_free(ioc
, fw_event
);
5883 if (fw_event
->event
== MPT2SAS_RESCAN_AFTER_HOST_RESET
) {
5884 _scsih_fw_event_free(ioc
, fw_event
);
5885 spin_lock_irqsave(&ioc
->ioc_reset_in_progress_lock
, flags
);
5886 if (ioc
->shost_recovery
) {
5887 init_completion(&ioc
->shost_recovery_done
);
5888 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
,
5890 wait_for_completion(&ioc
->shost_recovery_done
);
5892 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
,
5894 _scsih_search_responding_sas_devices(ioc
);
5895 _scsih_search_responding_raid_devices(ioc
);
5896 _scsih_search_responding_expanders(ioc
);
5897 _scsih_remove_unresponding_sas_devices(ioc
);
5901 switch (fw_event
->event
) {
5902 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
5903 _scsih_sas_topology_change_event(ioc
, fw_event
);
5905 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
5906 _scsih_sas_device_status_change_event(ioc
,
5909 case MPI2_EVENT_SAS_DISCOVERY
:
5910 _scsih_sas_discovery_event(ioc
,
5913 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
5914 _scsih_sas_broadcast_primative_event(ioc
,
5917 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
5918 _scsih_sas_enclosure_dev_status_change_event(ioc
,
5921 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
5922 _scsih_sas_ir_config_change_event(ioc
, fw_event
);
5924 case MPI2_EVENT_IR_VOLUME
:
5925 _scsih_sas_ir_volume_event(ioc
, fw_event
);
5927 case MPI2_EVENT_IR_PHYSICAL_DISK
:
5928 _scsih_sas_ir_physical_disk_event(ioc
, fw_event
);
5930 case MPI2_EVENT_IR_OPERATION_STATUS
:
5931 _scsih_sas_ir_operation_status_event(ioc
, fw_event
);
5933 case MPI2_EVENT_TASK_SET_FULL
:
5934 _scsih_task_set_full(ioc
, fw_event
);
5937 _scsih_fw_event_free(ioc
, fw_event
);
5941 * mpt2sas_scsih_event_callback - firmware event handler (called at ISR time)
5942 * @ioc: per adapter object
5943 * @msix_index: MSIX table index supplied by the OS
5944 * @reply: reply message frame(lower 32bit addr)
5945 * Context: interrupt.
5947 * This function merely adds a new work task into ioc->firmware_event_thread.
5948 * The tasks are worked from _firmware_event_work in user context.
5950 * Return 1 meaning mf should be freed from _base_interrupt
5951 * 0 means the mf is freed from this function.
5954 mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER
*ioc
, u8 msix_index
,
5957 struct fw_event_work
*fw_event
;
5958 Mpi2EventNotificationReply_t
*mpi_reply
;
5962 /* events turned off due to host reset or driver unloading */
5963 if (ioc
->remove_host
)
5966 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
5967 event
= le16_to_cpu(mpi_reply
->Event
);
5971 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
5973 Mpi2EventDataSasBroadcastPrimitive_t
*baen_data
=
5974 (Mpi2EventDataSasBroadcastPrimitive_t
*)
5975 mpi_reply
->EventData
;
5977 if (baen_data
->Primitive
!=
5978 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT
||
5979 ioc
->broadcast_aen_busy
)
5981 ioc
->broadcast_aen_busy
= 1;
5985 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
5986 _scsih_check_topo_delete_events(ioc
,
5987 (Mpi2EventDataSasTopologyChangeList_t
*)
5988 mpi_reply
->EventData
);
5991 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
5992 case MPI2_EVENT_IR_OPERATION_STATUS
:
5993 case MPI2_EVENT_SAS_DISCOVERY
:
5994 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
5995 case MPI2_EVENT_IR_VOLUME
:
5996 case MPI2_EVENT_IR_PHYSICAL_DISK
:
5997 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
5998 case MPI2_EVENT_TASK_SET_FULL
:
6001 default: /* ignore the rest */
6005 fw_event
= kzalloc(sizeof(struct fw_event_work
), GFP_ATOMIC
);
6007 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6008 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6011 sz
= le16_to_cpu(mpi_reply
->EventDataLength
) * 4;
6012 fw_event
->event_data
= kzalloc(sz
, GFP_ATOMIC
);
6013 if (!fw_event
->event_data
) {
6014 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6015 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6020 memcpy(fw_event
->event_data
, mpi_reply
->EventData
,
6022 fw_event
->ioc
= ioc
;
6023 fw_event
->VF_ID
= mpi_reply
->VF_ID
;
6024 fw_event
->VP_ID
= mpi_reply
->VP_ID
;
6025 fw_event
->event
= event
;
6026 _scsih_fw_event_add(ioc
, fw_event
);
6030 /* shost template */
6031 static struct scsi_host_template scsih_driver_template
= {
6032 .module
= THIS_MODULE
,
6033 .name
= "Fusion MPT SAS Host",
6034 .proc_name
= MPT2SAS_DRIVER_NAME
,
6035 .queuecommand
= _scsih_qcmd
,
6036 .target_alloc
= _scsih_target_alloc
,
6037 .slave_alloc
= _scsih_slave_alloc
,
6038 .slave_configure
= _scsih_slave_configure
,
6039 .target_destroy
= _scsih_target_destroy
,
6040 .slave_destroy
= _scsih_slave_destroy
,
6041 .change_queue_depth
= _scsih_change_queue_depth
,
6042 .change_queue_type
= _scsih_change_queue_type
,
6043 .eh_abort_handler
= _scsih_abort
,
6044 .eh_device_reset_handler
= _scsih_dev_reset
,
6045 .eh_target_reset_handler
= _scsih_target_reset
,
6046 .eh_host_reset_handler
= _scsih_host_reset
,
6047 .bios_param
= _scsih_bios_param
,
6050 .sg_tablesize
= MPT2SAS_SG_DEPTH
,
6051 .max_sectors
= 8192,
6053 .use_clustering
= ENABLE_CLUSTERING
,
6054 .shost_attrs
= mpt2sas_host_attrs
,
6055 .sdev_attrs
= mpt2sas_dev_attrs
,
6059 * _scsih_expander_node_remove - removing expander device from list.
6060 * @ioc: per adapter object
6061 * @sas_expander: the sas_device object
6062 * Context: Calling function should acquire ioc->sas_node_lock.
6064 * Removing object and freeing associated memory from the
6065 * ioc->sas_expander_list.
6070 _scsih_expander_node_remove(struct MPT2SAS_ADAPTER
*ioc
,
6071 struct _sas_node
*sas_expander
)
6073 struct _sas_port
*mpt2sas_port
;
6074 struct _sas_device
*sas_device
;
6075 struct _sas_node
*expander_sibling
;
6076 unsigned long flags
;
6081 /* remove sibling ports attached to this expander */
6082 retry_device_search
:
6083 list_for_each_entry(mpt2sas_port
,
6084 &sas_expander
->sas_port_list
, port_list
) {
6085 if (mpt2sas_port
->remote_identify
.device_type
==
6087 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6089 mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
6090 mpt2sas_port
->remote_identify
.sas_address
);
6091 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6094 _scsih_remove_device(ioc
, sas_device
);
6095 if (ioc
->shost_recovery
)
6097 goto retry_device_search
;
6101 retry_expander_search
:
6102 list_for_each_entry(mpt2sas_port
,
6103 &sas_expander
->sas_port_list
, port_list
) {
6105 if (mpt2sas_port
->remote_identify
.device_type
==
6106 MPI2_SAS_DEVICE_INFO_EDGE_EXPANDER
||
6107 mpt2sas_port
->remote_identify
.device_type
==
6108 MPI2_SAS_DEVICE_INFO_FANOUT_EXPANDER
) {
6110 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
6112 mpt2sas_scsih_expander_find_by_sas_address(
6113 ioc
, mpt2sas_port
->remote_identify
.sas_address
);
6114 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
6115 if (!expander_sibling
)
6117 _scsih_expander_remove(ioc
,
6118 expander_sibling
->sas_address
);
6119 if (ioc
->shost_recovery
)
6121 goto retry_expander_search
;
6125 mpt2sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
6126 sas_expander
->sas_address_parent
);
6128 printk(MPT2SAS_INFO_FMT
"expander_remove: handle"
6129 "(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
6130 sas_expander
->handle
, (unsigned long long)
6131 sas_expander
->sas_address
);
6133 list_del(&sas_expander
->list
);
6134 kfree(sas_expander
->phy
);
6135 kfree(sas_expander
);
6139 * _scsih_ir_shutdown - IR shutdown notification
6140 * @ioc: per adapter object
6142 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
6143 * the host system is shutting down.
6148 _scsih_ir_shutdown(struct MPT2SAS_ADAPTER
*ioc
)
6150 Mpi2RaidActionRequest_t
*mpi_request
;
6151 Mpi2RaidActionReply_t
*mpi_reply
;
6154 /* is IR firmware build loaded ? */
6155 if (!ioc
->ir_firmware
)
6158 /* are there any volumes ? */
6159 if (list_empty(&ioc
->raid_device_list
))
6162 mutex_lock(&ioc
->scsih_cmds
.mutex
);
6164 if (ioc
->scsih_cmds
.status
!= MPT2_CMD_NOT_USED
) {
6165 printk(MPT2SAS_ERR_FMT
"%s: scsih_cmd in use\n",
6166 ioc
->name
, __func__
);
6169 ioc
->scsih_cmds
.status
= MPT2_CMD_PENDING
;
6171 smid
= mpt2sas_base_get_smid(ioc
, ioc
->scsih_cb_idx
);
6173 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
6174 ioc
->name
, __func__
);
6175 ioc
->scsih_cmds
.status
= MPT2_CMD_NOT_USED
;
6179 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
6180 ioc
->scsih_cmds
.smid
= smid
;
6181 memset(mpi_request
, 0, sizeof(Mpi2RaidActionRequest_t
));
6183 mpi_request
->Function
= MPI2_FUNCTION_RAID_ACTION
;
6184 mpi_request
->Action
= MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED
;
6186 printk(MPT2SAS_INFO_FMT
"IR shutdown (sending)\n", ioc
->name
);
6187 init_completion(&ioc
->scsih_cmds
.done
);
6188 mpt2sas_base_put_smid_default(ioc
, smid
);
6189 wait_for_completion_timeout(&ioc
->scsih_cmds
.done
, 10*HZ
);
6191 if (!(ioc
->scsih_cmds
.status
& MPT2_CMD_COMPLETE
)) {
6192 printk(MPT2SAS_ERR_FMT
"%s: timeout\n",
6193 ioc
->name
, __func__
);
6197 if (ioc
->scsih_cmds
.status
& MPT2_CMD_REPLY_VALID
) {
6198 mpi_reply
= ioc
->scsih_cmds
.reply
;
6200 printk(MPT2SAS_INFO_FMT
"IR shutdown (complete): "
6201 "ioc_status(0x%04x), loginfo(0x%08x)\n",
6202 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
6203 le32_to_cpu(mpi_reply
->IOCLogInfo
));
6207 ioc
->scsih_cmds
.status
= MPT2_CMD_NOT_USED
;
6208 mutex_unlock(&ioc
->scsih_cmds
.mutex
);
6212 * _scsih_shutdown - routine call during system shutdown
6213 * @pdev: PCI device struct
6218 _scsih_shutdown(struct pci_dev
*pdev
)
6220 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6221 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
6222 struct workqueue_struct
*wq
;
6223 unsigned long flags
;
6225 ioc
->remove_host
= 1;
6226 _scsih_fw_event_cleanup_queue(ioc
);
6228 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
6229 wq
= ioc
->firmware_event_thread
;
6230 ioc
->firmware_event_thread
= NULL
;
6231 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
6233 destroy_workqueue(wq
);
6235 _scsih_ir_shutdown(ioc
);
6236 mpt2sas_base_detach(ioc
);
6240 * _scsih_remove - detach and remove add host
6241 * @pdev: PCI device struct
6243 * Routine called when unloading the driver.
6246 static void __devexit
6247 _scsih_remove(struct pci_dev
*pdev
)
6249 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6250 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
6251 struct _sas_port
*mpt2sas_port
;
6252 struct _sas_device
*sas_device
;
6253 struct _sas_node
*expander_sibling
;
6254 struct _raid_device
*raid_device
, *next
;
6255 struct MPT2SAS_TARGET
*sas_target_priv_data
;
6256 struct workqueue_struct
*wq
;
6257 unsigned long flags
;
6259 ioc
->remove_host
= 1;
6260 _scsih_fw_event_cleanup_queue(ioc
);
6262 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
6263 wq
= ioc
->firmware_event_thread
;
6264 ioc
->firmware_event_thread
= NULL
;
6265 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
6267 destroy_workqueue(wq
);
6269 /* release all the volumes */
6270 list_for_each_entry_safe(raid_device
, next
, &ioc
->raid_device_list
,
6272 if (raid_device
->starget
) {
6273 sas_target_priv_data
=
6274 raid_device
->starget
->hostdata
;
6275 sas_target_priv_data
->deleted
= 1;
6276 scsi_remove_target(&raid_device
->starget
->dev
);
6278 printk(MPT2SAS_INFO_FMT
"removing handle(0x%04x), wwid"
6279 "(0x%016llx)\n", ioc
->name
, raid_device
->handle
,
6280 (unsigned long long) raid_device
->wwid
);
6281 _scsih_raid_device_remove(ioc
, raid_device
);
6284 /* free ports attached to the sas_host */
6286 list_for_each_entry(mpt2sas_port
,
6287 &ioc
->sas_hba
.sas_port_list
, port_list
) {
6288 if (mpt2sas_port
->remote_identify
.device_type
==
6291 mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
6292 mpt2sas_port
->remote_identify
.sas_address
);
6294 _scsih_remove_device(ioc
, sas_device
);
6299 mpt2sas_scsih_expander_find_by_sas_address(ioc
,
6300 mpt2sas_port
->remote_identify
.sas_address
);
6301 if (expander_sibling
) {
6302 _scsih_expander_remove(ioc
,
6303 expander_sibling
->sas_address
);
6309 /* free phys attached to the sas_host */
6310 if (ioc
->sas_hba
.num_phys
) {
6311 kfree(ioc
->sas_hba
.phy
);
6312 ioc
->sas_hba
.phy
= NULL
;
6313 ioc
->sas_hba
.num_phys
= 0;
6316 sas_remove_host(shost
);
6317 _scsih_shutdown(pdev
);
6318 list_del(&ioc
->list
);
6319 scsi_remove_host(shost
);
6320 scsi_host_put(shost
);
6324 * _scsih_probe_boot_devices - reports 1st device
6325 * @ioc: per adapter object
6327 * If specified in bios page 2, this routine reports the 1st
6328 * device scsi-ml or sas transport for persistent boot device
6329 * purposes. Please refer to function _scsih_determine_boot_device()
6332 _scsih_probe_boot_devices(struct MPT2SAS_ADAPTER
*ioc
)
6336 struct _sas_device
*sas_device
;
6337 struct _raid_device
*raid_device
;
6339 u64 sas_address_parent
;
6341 unsigned long flags
;
6345 if (ioc
->req_boot_device
.device
) {
6346 device
= ioc
->req_boot_device
.device
;
6347 is_raid
= ioc
->req_boot_device
.is_raid
;
6348 } else if (ioc
->req_alt_boot_device
.device
) {
6349 device
= ioc
->req_alt_boot_device
.device
;
6350 is_raid
= ioc
->req_alt_boot_device
.is_raid
;
6351 } else if (ioc
->current_boot_device
.device
) {
6352 device
= ioc
->current_boot_device
.device
;
6353 is_raid
= ioc
->current_boot_device
.is_raid
;
6360 raid_device
= device
;
6361 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
6362 raid_device
->id
, 0);
6364 _scsih_raid_device_remove(ioc
, raid_device
);
6366 sas_device
= device
;
6367 handle
= sas_device
->handle
;
6368 sas_address_parent
= sas_device
->sas_address_parent
;
6369 sas_address
= sas_device
->sas_address
;
6370 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6371 list_move_tail(&sas_device
->list
, &ioc
->sas_device_list
);
6372 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6373 if (!mpt2sas_transport_port_add(ioc
, sas_device
->handle
,
6374 sas_device
->sas_address_parent
)) {
6375 _scsih_sas_device_remove(ioc
, sas_device
);
6376 } else if (!sas_device
->starget
) {
6377 mpt2sas_transport_port_remove(ioc
, sas_address
,
6378 sas_address_parent
);
6379 _scsih_sas_device_remove(ioc
, sas_device
);
6385 * _scsih_probe_raid - reporting raid volumes to scsi-ml
6386 * @ioc: per adapter object
6388 * Called during initial loading of the driver.
6391 _scsih_probe_raid(struct MPT2SAS_ADAPTER
*ioc
)
6393 struct _raid_device
*raid_device
, *raid_next
;
6396 list_for_each_entry_safe(raid_device
, raid_next
,
6397 &ioc
->raid_device_list
, list
) {
6398 if (raid_device
->starget
)
6400 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
6401 raid_device
->id
, 0);
6403 _scsih_raid_device_remove(ioc
, raid_device
);
6408 * _scsih_probe_sas - reporting sas devices to sas transport
6409 * @ioc: per adapter object
6411 * Called during initial loading of the driver.
6414 _scsih_probe_sas(struct MPT2SAS_ADAPTER
*ioc
)
6416 struct _sas_device
*sas_device
, *next
;
6417 unsigned long flags
;
6419 /* SAS Device List */
6420 list_for_each_entry_safe(sas_device
, next
, &ioc
->sas_device_init_list
,
6422 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6423 list_move_tail(&sas_device
->list
, &ioc
->sas_device_list
);
6424 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6426 if (!mpt2sas_transport_port_add(ioc
, sas_device
->handle
,
6427 sas_device
->sas_address_parent
)) {
6428 _scsih_sas_device_remove(ioc
, sas_device
);
6429 } else if (!sas_device
->starget
) {
6430 mpt2sas_transport_port_remove(ioc
,
6431 sas_device
->sas_address
,
6432 sas_device
->sas_address_parent
);
6433 _scsih_sas_device_remove(ioc
, sas_device
);
6439 * _scsih_probe_devices - probing for devices
6440 * @ioc: per adapter object
6442 * Called during initial loading of the driver.
6445 _scsih_probe_devices(struct MPT2SAS_ADAPTER
*ioc
)
6447 u16 volume_mapping_flags
=
6448 le16_to_cpu(ioc
->ioc_pg8
.IRVolumeMappingFlags
) &
6449 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE
;
6451 if (!(ioc
->facts
.ProtocolFlags
& MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR
))
6452 return; /* return when IOC doesn't support initiator mode */
6454 _scsih_probe_boot_devices(ioc
);
6456 if (ioc
->ir_firmware
) {
6457 if ((volume_mapping_flags
&
6458 MPI2_IOCPAGE8_IRFLAGS_HIGH_VOLUME_MAPPING
)) {
6459 _scsih_probe_sas(ioc
);
6460 _scsih_probe_raid(ioc
);
6462 _scsih_probe_raid(ioc
);
6463 _scsih_probe_sas(ioc
);
6466 _scsih_probe_sas(ioc
);
6470 * _scsih_probe - attach and add scsi host
6471 * @pdev: PCI device struct
6472 * @id: pci device id
6474 * Returns 0 success, anything else error.
6477 _scsih_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
6479 struct MPT2SAS_ADAPTER
*ioc
;
6480 struct Scsi_Host
*shost
;
6482 shost
= scsi_host_alloc(&scsih_driver_template
,
6483 sizeof(struct MPT2SAS_ADAPTER
));
6487 /* init local params */
6488 ioc
= shost_priv(shost
);
6489 memset(ioc
, 0, sizeof(struct MPT2SAS_ADAPTER
));
6490 INIT_LIST_HEAD(&ioc
->list
);
6491 list_add_tail(&ioc
->list
, &mpt2sas_ioc_list
);
6493 ioc
->id
= mpt_ids
++;
6494 sprintf(ioc
->name
, "%s%d", MPT2SAS_DRIVER_NAME
, ioc
->id
);
6496 ioc
->scsi_io_cb_idx
= scsi_io_cb_idx
;
6497 ioc
->tm_cb_idx
= tm_cb_idx
;
6498 ioc
->ctl_cb_idx
= ctl_cb_idx
;
6499 ioc
->base_cb_idx
= base_cb_idx
;
6500 ioc
->transport_cb_idx
= transport_cb_idx
;
6501 ioc
->scsih_cb_idx
= scsih_cb_idx
;
6502 ioc
->config_cb_idx
= config_cb_idx
;
6503 ioc
->tm_tr_cb_idx
= tm_tr_cb_idx
;
6504 ioc
->tm_sas_control_cb_idx
= tm_sas_control_cb_idx
;
6505 ioc
->logging_level
= logging_level
;
6506 /* misc semaphores and spin locks */
6507 spin_lock_init(&ioc
->ioc_reset_in_progress_lock
);
6508 spin_lock_init(&ioc
->scsi_lookup_lock
);
6509 spin_lock_init(&ioc
->sas_device_lock
);
6510 spin_lock_init(&ioc
->sas_node_lock
);
6511 spin_lock_init(&ioc
->fw_event_lock
);
6512 spin_lock_init(&ioc
->raid_device_lock
);
6514 INIT_LIST_HEAD(&ioc
->sas_device_list
);
6515 INIT_LIST_HEAD(&ioc
->sas_device_init_list
);
6516 INIT_LIST_HEAD(&ioc
->sas_expander_list
);
6517 INIT_LIST_HEAD(&ioc
->fw_event_list
);
6518 INIT_LIST_HEAD(&ioc
->raid_device_list
);
6519 INIT_LIST_HEAD(&ioc
->sas_hba
.sas_port_list
);
6520 INIT_LIST_HEAD(&ioc
->delayed_tr_list
);
6522 /* init shost parameters */
6523 shost
->max_cmd_len
= 16;
6524 shost
->max_lun
= max_lun
;
6525 shost
->transportt
= mpt2sas_transport_template
;
6526 shost
->unique_id
= ioc
->id
;
6528 if ((scsi_add_host(shost
, &pdev
->dev
))) {
6529 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6530 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6531 list_del(&ioc
->list
);
6532 goto out_add_shost_fail
;
6535 scsi_host_set_prot(shost
, SHOST_DIF_TYPE1_PROTECTION
6536 | SHOST_DIF_TYPE3_PROTECTION
);
6537 scsi_host_set_guard(shost
, SHOST_DIX_GUARD_CRC
);
6540 snprintf(ioc
->firmware_event_name
, sizeof(ioc
->firmware_event_name
),
6541 "fw_event%d", ioc
->id
);
6542 ioc
->firmware_event_thread
= create_singlethread_workqueue(
6543 ioc
->firmware_event_name
);
6544 if (!ioc
->firmware_event_thread
) {
6545 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6546 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6547 goto out_thread_fail
;
6550 ioc
->wait_for_port_enable_to_complete
= 1;
6551 if ((mpt2sas_base_attach(ioc
))) {
6552 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6553 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6554 goto out_attach_fail
;
6557 ioc
->wait_for_port_enable_to_complete
= 0;
6558 _scsih_probe_devices(ioc
);
6562 destroy_workqueue(ioc
->firmware_event_thread
);
6564 list_del(&ioc
->list
);
6565 scsi_remove_host(shost
);
6572 * _scsih_suspend - power management suspend main entry point
6573 * @pdev: PCI device struct
6574 * @state: PM state change to (usually PCI_D3)
6576 * Returns 0 success, anything else error.
6579 _scsih_suspend(struct pci_dev
*pdev
, pm_message_t state
)
6581 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6582 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
6585 mpt2sas_base_stop_watchdog(ioc
);
6586 flush_scheduled_work();
6587 scsi_block_requests(shost
);
6588 device_state
= pci_choose_state(pdev
, state
);
6589 printk(MPT2SAS_INFO_FMT
"pdev=0x%p, slot=%s, entering "
6590 "operating state [D%d]\n", ioc
->name
, pdev
,
6591 pci_name(pdev
), device_state
);
6593 mpt2sas_base_free_resources(ioc
);
6594 pci_save_state(pdev
);
6595 pci_disable_device(pdev
);
6596 pci_set_power_state(pdev
, device_state
);
6601 * _scsih_resume - power management resume main entry point
6602 * @pdev: PCI device struct
6604 * Returns 0 success, anything else error.
6607 _scsih_resume(struct pci_dev
*pdev
)
6609 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6610 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
6611 u32 device_state
= pdev
->current_state
;
6614 printk(MPT2SAS_INFO_FMT
"pdev=0x%p, slot=%s, previous "
6615 "operating state [D%d]\n", ioc
->name
, pdev
,
6616 pci_name(pdev
), device_state
);
6618 pci_set_power_state(pdev
, PCI_D0
);
6619 pci_enable_wake(pdev
, PCI_D0
, 0);
6620 pci_restore_state(pdev
);
6622 r
= mpt2sas_base_map_resources(ioc
);
6626 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
, SOFT_RESET
);
6627 scsi_unblock_requests(shost
);
6628 mpt2sas_base_start_watchdog(ioc
);
6631 #endif /* CONFIG_PM */
6634 static struct pci_driver scsih_driver
= {
6635 .name
= MPT2SAS_DRIVER_NAME
,
6636 .id_table
= scsih_pci_table
,
6637 .probe
= _scsih_probe
,
6638 .remove
= __devexit_p(_scsih_remove
),
6639 .shutdown
= _scsih_shutdown
,
6641 .suspend
= _scsih_suspend
,
6642 .resume
= _scsih_resume
,
6646 /* raid transport support */
6647 static struct raid_function_template mpt2sas_raid_functions
= {
6648 .cookie
= &scsih_driver_template
,
6649 .is_raid
= _scsih_is_raid
,
6650 .get_resync
= _scsih_get_resync
,
6651 .get_state
= _scsih_get_state
,
6655 * _scsih_init - main entry point for this driver.
6657 * Returns 0 success, anything else error.
6665 printk(KERN_INFO
"%s version %s loaded\n", MPT2SAS_DRIVER_NAME
,
6666 MPT2SAS_DRIVER_VERSION
);
6668 mpt2sas_transport_template
=
6669 sas_attach_transport(&mpt2sas_transport_functions
);
6670 if (!mpt2sas_transport_template
)
6672 /* raid transport support */
6673 mpt2sas_raid_template
= raid_class_attach(&mpt2sas_raid_functions
);
6674 if (!mpt2sas_raid_template
) {
6675 sas_release_transport(mpt2sas_transport_template
);
6679 mpt2sas_base_initialize_callback_handler();
6681 /* queuecommand callback hander */
6682 scsi_io_cb_idx
= mpt2sas_base_register_callback_handler(_scsih_io_done
);
6684 /* task managment callback handler */
6685 tm_cb_idx
= mpt2sas_base_register_callback_handler(_scsih_tm_done
);
6687 /* base internal commands callback handler */
6688 base_cb_idx
= mpt2sas_base_register_callback_handler(mpt2sas_base_done
);
6690 /* transport internal commands callback handler */
6691 transport_cb_idx
= mpt2sas_base_register_callback_handler(
6692 mpt2sas_transport_done
);
6694 /* scsih internal commands callback handler */
6695 scsih_cb_idx
= mpt2sas_base_register_callback_handler(_scsih_done
);
6697 /* configuration page API internal commands callback handler */
6698 config_cb_idx
= mpt2sas_base_register_callback_handler(
6699 mpt2sas_config_done
);
6701 /* ctl module callback handler */
6702 ctl_cb_idx
= mpt2sas_base_register_callback_handler(mpt2sas_ctl_done
);
6704 tm_tr_cb_idx
= mpt2sas_base_register_callback_handler(
6705 _scsih_tm_tr_complete
);
6706 tm_sas_control_cb_idx
= mpt2sas_base_register_callback_handler(
6707 _scsih_sas_control_complete
);
6711 error
= pci_register_driver(&scsih_driver
);
6713 /* raid transport support */
6714 raid_class_release(mpt2sas_raid_template
);
6715 sas_release_transport(mpt2sas_transport_template
);
6722 * _scsih_exit - exit point for this driver (when it is a module).
6724 * Returns 0 success, anything else error.
6729 printk(KERN_INFO
"mpt2sas version %s unloading\n",
6730 MPT2SAS_DRIVER_VERSION
);
6732 pci_unregister_driver(&scsih_driver
);
6736 mpt2sas_base_release_callback_handler(scsi_io_cb_idx
);
6737 mpt2sas_base_release_callback_handler(tm_cb_idx
);
6738 mpt2sas_base_release_callback_handler(base_cb_idx
);
6739 mpt2sas_base_release_callback_handler(transport_cb_idx
);
6740 mpt2sas_base_release_callback_handler(scsih_cb_idx
);
6741 mpt2sas_base_release_callback_handler(config_cb_idx
);
6742 mpt2sas_base_release_callback_handler(ctl_cb_idx
);
6744 mpt2sas_base_release_callback_handler(tm_tr_cb_idx
);
6745 mpt2sas_base_release_callback_handler(tm_sas_control_cb_idx
);
6747 /* raid transport support */
6748 raid_class_release(mpt2sas_raid_template
);
6749 sas_release_transport(mpt2sas_transport_template
);
6753 module_init(_scsih_init
);
6754 module_exit(_scsih_exit
);