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
= le16_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;
1948 * mpt2sas_scsih_issue_tm - main routine for sending tm requests
1949 * @ioc: per adapter struct
1950 * @device_handle: device handle
1952 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
1953 * @smid_task: smid assigned to the task
1954 * @timeout: timeout in seconds
1955 * Context: The calling function needs to acquire the tm_cmds.mutex
1957 * A generic API for sending task management requests to firmware.
1959 * The ioc->tm_cmds.status flag should be MPT2_CMD_NOT_USED before calling
1962 * The callback index is set inside `ioc->tm_cb_idx`.
1967 mpt2sas_scsih_issue_tm(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
, uint lun
,
1968 u8 type
, u16 smid_task
, ulong timeout
)
1970 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
1971 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
1974 unsigned long timeleft
;
1976 if (ioc
->tm_cmds
.status
!= MPT2_CMD_NOT_USED
) {
1977 printk(MPT2SAS_INFO_FMT
"%s: tm_cmd busy!!!\n",
1978 __func__
, ioc
->name
);
1982 if (ioc
->shost_recovery
) {
1983 printk(MPT2SAS_INFO_FMT
"%s: host reset in progress!\n",
1984 __func__
, ioc
->name
);
1988 ioc_state
= mpt2sas_base_get_iocstate(ioc
, 0);
1989 if (ioc_state
& MPI2_DOORBELL_USED
) {
1990 dhsprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"unexpected doorbell "
1991 "active!\n", ioc
->name
));
1992 goto issue_host_reset
;
1995 if ((ioc_state
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_FAULT
) {
1996 mpt2sas_base_fault_info(ioc
, ioc_state
&
1997 MPI2_DOORBELL_DATA_MASK
);
1998 goto issue_host_reset
;
2001 smid
= mpt2sas_base_get_smid_hpr(ioc
, ioc
->tm_cb_idx
);
2003 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
2004 ioc
->name
, __func__
);
2008 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"sending tm: handle(0x%04x),"
2009 " task_type(0x%02x), smid(%d)\n", ioc
->name
, handle
, type
,
2011 ioc
->tm_cmds
.status
= MPT2_CMD_PENDING
;
2012 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
2013 ioc
->tm_cmds
.smid
= smid
;
2014 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
2015 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
2016 mpi_request
->DevHandle
= cpu_to_le16(handle
);
2017 mpi_request
->TaskType
= type
;
2018 mpi_request
->TaskMID
= cpu_to_le16(smid_task
);
2019 mpi_request
->VP_ID
= 0; /* TODO */
2020 mpi_request
->VF_ID
= 0;
2021 int_to_scsilun(lun
, (struct scsi_lun
*)mpi_request
->LUN
);
2022 mpt2sas_scsih_set_tm_flag(ioc
, handle
);
2023 init_completion(&ioc
->tm_cmds
.done
);
2024 mpt2sas_base_put_smid_hi_priority(ioc
, smid
);
2025 timeleft
= wait_for_completion_timeout(&ioc
->tm_cmds
.done
, timeout
*HZ
);
2026 mpt2sas_scsih_clear_tm_flag(ioc
, handle
);
2027 if (!(ioc
->tm_cmds
.status
& MPT2_CMD_COMPLETE
)) {
2028 printk(MPT2SAS_ERR_FMT
"%s: timeout\n",
2029 ioc
->name
, __func__
);
2030 _debug_dump_mf(mpi_request
,
2031 sizeof(Mpi2SCSITaskManagementRequest_t
)/4);
2032 if (!(ioc
->tm_cmds
.status
& MPT2_CMD_RESET
))
2033 goto issue_host_reset
;
2036 if (ioc
->tm_cmds
.status
& MPT2_CMD_REPLY_VALID
) {
2037 mpi_reply
= ioc
->tm_cmds
.reply
;
2038 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"complete tm: "
2039 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
2040 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
2041 le32_to_cpu(mpi_reply
->IOCLogInfo
),
2042 le32_to_cpu(mpi_reply
->TerminationCount
)));
2043 if (ioc
->logging_level
& MPT_DEBUG_TM
)
2044 _scsih_response_code(ioc
, mpi_reply
->ResponseCode
);
2048 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
, FORCE_BIG_HAMMER
);
2052 * _scsih_abort - eh threads main abort routine
2053 * @sdev: scsi device struct
2055 * Returns SUCCESS if command aborted else FAILED
2058 _scsih_abort(struct scsi_cmnd
*scmd
)
2060 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2061 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2065 struct scsi_cmnd
*scmd_lookup
;
2067 printk(MPT2SAS_INFO_FMT
"attempting task abort! scmd(%p)\n",
2069 scsi_print_command(scmd
);
2071 sas_device_priv_data
= scmd
->device
->hostdata
;
2072 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2073 printk(MPT2SAS_INFO_FMT
"device been deleted! scmd(%p)\n",
2075 scmd
->result
= DID_NO_CONNECT
<< 16;
2076 scmd
->scsi_done(scmd
);
2081 /* search for the command */
2082 smid
= _scsih_scsi_lookup_find_by_scmd(ioc
, scmd
);
2084 scmd
->result
= DID_RESET
<< 16;
2089 /* for hidden raid components and volumes this is not supported */
2090 if (sas_device_priv_data
->sas_target
->flags
&
2091 MPT_TARGET_FLAGS_RAID_COMPONENT
||
2092 sas_device_priv_data
->sas_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
2093 scmd
->result
= DID_RESET
<< 16;
2098 mpt2sas_halt_firmware(ioc
);
2100 mutex_lock(&ioc
->tm_cmds
.mutex
);
2101 handle
= sas_device_priv_data
->sas_target
->handle
;
2102 mpt2sas_scsih_issue_tm(ioc
, handle
, sas_device_priv_data
->lun
,
2103 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
, smid
, 30);
2105 /* sanity check - see whether command actually completed */
2106 scmd_lookup
= _scsih_scsi_lookup_get(ioc
, smid
);
2107 if (scmd_lookup
&& (scmd_lookup
->serial_number
== scmd
->serial_number
))
2111 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
2112 mutex_unlock(&ioc
->tm_cmds
.mutex
);
2115 printk(MPT2SAS_INFO_FMT
"task abort: %s scmd(%p)\n",
2116 ioc
->name
, ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2121 * _scsih_dev_reset - eh threads main device reset routine
2122 * @sdev: scsi device struct
2124 * Returns SUCCESS if command aborted else FAILED
2127 _scsih_dev_reset(struct scsi_cmnd
*scmd
)
2129 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2130 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2131 struct _sas_device
*sas_device
;
2132 unsigned long flags
;
2136 printk(MPT2SAS_INFO_FMT
"attempting device reset! scmd(%p)\n",
2138 scsi_print_command(scmd
);
2140 sas_device_priv_data
= scmd
->device
->hostdata
;
2141 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2142 printk(MPT2SAS_INFO_FMT
"device been deleted! scmd(%p)\n",
2144 scmd
->result
= DID_NO_CONNECT
<< 16;
2145 scmd
->scsi_done(scmd
);
2150 /* for hidden raid components obtain the volume_handle */
2152 if (sas_device_priv_data
->sas_target
->flags
&
2153 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2154 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2155 sas_device
= _scsih_sas_device_find_by_handle(ioc
,
2156 sas_device_priv_data
->sas_target
->handle
);
2158 handle
= sas_device
->volume_handle
;
2159 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2161 handle
= sas_device_priv_data
->sas_target
->handle
;
2164 scmd
->result
= DID_RESET
<< 16;
2169 mutex_lock(&ioc
->tm_cmds
.mutex
);
2170 mpt2sas_scsih_issue_tm(ioc
, handle
, 0,
2171 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET
, scmd
->device
->lun
,
2175 * sanity check see whether all commands to this device been
2178 if (_scsih_scsi_lookup_find_by_lun(ioc
, scmd
->device
->id
,
2179 scmd
->device
->lun
, scmd
->device
->channel
))
2183 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
2184 mutex_unlock(&ioc
->tm_cmds
.mutex
);
2187 printk(MPT2SAS_INFO_FMT
"device reset: %s scmd(%p)\n",
2188 ioc
->name
, ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2193 * _scsih_target_reset - eh threads main target reset routine
2194 * @sdev: scsi device struct
2196 * Returns SUCCESS if command aborted else FAILED
2199 _scsih_target_reset(struct scsi_cmnd
*scmd
)
2201 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2202 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2203 struct _sas_device
*sas_device
;
2204 unsigned long flags
;
2208 printk(MPT2SAS_INFO_FMT
"attempting target reset! scmd(%p)\n",
2210 scsi_print_command(scmd
);
2212 sas_device_priv_data
= scmd
->device
->hostdata
;
2213 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2214 printk(MPT2SAS_INFO_FMT
"target been deleted! scmd(%p)\n",
2216 scmd
->result
= DID_NO_CONNECT
<< 16;
2217 scmd
->scsi_done(scmd
);
2222 /* for hidden raid components obtain the volume_handle */
2224 if (sas_device_priv_data
->sas_target
->flags
&
2225 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2226 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2227 sas_device
= _scsih_sas_device_find_by_handle(ioc
,
2228 sas_device_priv_data
->sas_target
->handle
);
2230 handle
= sas_device
->volume_handle
;
2231 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2233 handle
= sas_device_priv_data
->sas_target
->handle
;
2236 scmd
->result
= DID_RESET
<< 16;
2241 mutex_lock(&ioc
->tm_cmds
.mutex
);
2242 mpt2sas_scsih_issue_tm(ioc
, handle
, 0,
2243 MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
, 0, 30);
2246 * sanity check see whether all commands to this target been
2249 if (_scsih_scsi_lookup_find_by_target(ioc
, scmd
->device
->id
,
2250 scmd
->device
->channel
))
2254 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
2255 mutex_unlock(&ioc
->tm_cmds
.mutex
);
2258 printk(MPT2SAS_INFO_FMT
"target reset: %s scmd(%p)\n",
2259 ioc
->name
, ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2264 * _scsih_host_reset - eh threads main host reset routine
2265 * @sdev: scsi device struct
2267 * Returns SUCCESS if command aborted else FAILED
2270 _scsih_host_reset(struct scsi_cmnd
*scmd
)
2272 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2275 printk(MPT2SAS_INFO_FMT
"attempting host reset! scmd(%p)\n",
2277 scsi_print_command(scmd
);
2279 retval
= mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2281 r
= (retval
< 0) ? FAILED
: SUCCESS
;
2282 printk(MPT2SAS_INFO_FMT
"host reset: %s scmd(%p)\n",
2283 ioc
->name
, ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2289 * _scsih_fw_event_add - insert and queue up fw_event
2290 * @ioc: per adapter object
2291 * @fw_event: object describing the event
2292 * Context: This function will acquire ioc->fw_event_lock.
2294 * This adds the firmware event object into link list, then queues it up to
2295 * be processed from user context.
2300 _scsih_fw_event_add(struct MPT2SAS_ADAPTER
*ioc
, struct fw_event_work
*fw_event
)
2302 unsigned long flags
;
2304 if (ioc
->firmware_event_thread
== NULL
)
2307 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2308 list_add_tail(&fw_event
->list
, &ioc
->fw_event_list
);
2309 INIT_DELAYED_WORK(&fw_event
->delayed_work
, _firmware_event_work
);
2310 queue_delayed_work(ioc
->firmware_event_thread
,
2311 &fw_event
->delayed_work
, 0);
2312 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2316 * _scsih_fw_event_free - delete fw_event
2317 * @ioc: per adapter object
2318 * @fw_event: object describing the event
2319 * Context: This function will acquire ioc->fw_event_lock.
2321 * This removes firmware event object from link list, frees associated memory.
2326 _scsih_fw_event_free(struct MPT2SAS_ADAPTER
*ioc
, struct fw_event_work
2329 unsigned long flags
;
2331 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2332 list_del(&fw_event
->list
);
2333 kfree(fw_event
->event_data
);
2335 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2340 * _scsih_queue_rescan - queue a topology rescan from user context
2341 * @ioc: per adapter object
2346 _scsih_queue_rescan(struct MPT2SAS_ADAPTER
*ioc
)
2348 struct fw_event_work
*fw_event
;
2350 if (ioc
->wait_for_port_enable_to_complete
)
2352 fw_event
= kzalloc(sizeof(struct fw_event_work
), GFP_ATOMIC
);
2355 fw_event
->event
= MPT2SAS_RESCAN_AFTER_HOST_RESET
;
2356 fw_event
->ioc
= ioc
;
2357 _scsih_fw_event_add(ioc
, fw_event
);
2361 * _scsih_fw_event_cleanup_queue - cleanup event queue
2362 * @ioc: per adapter object
2364 * Walk the firmware event queue, either killing timers, or waiting
2365 * for outstanding events to complete
2370 _scsih_fw_event_cleanup_queue(struct MPT2SAS_ADAPTER
*ioc
)
2372 struct fw_event_work
*fw_event
, *next
;
2374 if (list_empty(&ioc
->fw_event_list
) ||
2375 !ioc
->firmware_event_thread
|| in_interrupt())
2378 list_for_each_entry_safe(fw_event
, next
, &ioc
->fw_event_list
, list
) {
2379 if (cancel_delayed_work(&fw_event
->delayed_work
)) {
2380 _scsih_fw_event_free(ioc
, fw_event
);
2383 fw_event
->cancel_pending_work
= 1;
2389 * _scsih_ublock_io_device - set the device state to SDEV_RUNNING
2390 * @ioc: per adapter object
2391 * @handle: device handle
2393 * During device pull we need to appropiately set the sdev state.
2396 _scsih_ublock_io_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
2398 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2399 struct scsi_device
*sdev
;
2401 shost_for_each_device(sdev
, ioc
->shost
) {
2402 sas_device_priv_data
= sdev
->hostdata
;
2403 if (!sas_device_priv_data
)
2405 if (!sas_device_priv_data
->block
)
2407 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2408 dewtprintk(ioc
, sdev_printk(KERN_INFO
, sdev
,
2409 MPT2SAS_INFO_FMT
"SDEV_RUNNING: "
2410 "handle(0x%04x)\n", ioc
->name
, handle
));
2411 sas_device_priv_data
->block
= 0;
2412 scsi_internal_device_unblock(sdev
);
2418 * _scsih_block_io_device - set the device state to SDEV_BLOCK
2419 * @ioc: per adapter object
2420 * @handle: device handle
2422 * During device pull we need to appropiately set the sdev state.
2425 _scsih_block_io_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
2427 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2428 struct scsi_device
*sdev
;
2430 shost_for_each_device(sdev
, ioc
->shost
) {
2431 sas_device_priv_data
= sdev
->hostdata
;
2432 if (!sas_device_priv_data
)
2434 if (sas_device_priv_data
->block
)
2436 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2437 dewtprintk(ioc
, sdev_printk(KERN_INFO
, sdev
,
2438 MPT2SAS_INFO_FMT
"SDEV_BLOCK: "
2439 "handle(0x%04x)\n", ioc
->name
, handle
));
2440 sas_device_priv_data
->block
= 1;
2441 scsi_internal_device_block(sdev
);
2447 * _scsih_block_io_to_children_attached_to_ex
2448 * @ioc: per adapter object
2449 * @sas_expander: the sas_device object
2451 * This routine set sdev state to SDEV_BLOCK for all devices
2452 * attached to this expander. This function called when expander is
2456 _scsih_block_io_to_children_attached_to_ex(struct MPT2SAS_ADAPTER
*ioc
,
2457 struct _sas_node
*sas_expander
)
2459 struct _sas_port
*mpt2sas_port
;
2460 struct _sas_device
*sas_device
;
2461 struct _sas_node
*expander_sibling
;
2462 unsigned long flags
;
2467 list_for_each_entry(mpt2sas_port
,
2468 &sas_expander
->sas_port_list
, port_list
) {
2469 if (mpt2sas_port
->remote_identify
.device_type
==
2471 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2473 mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
2474 mpt2sas_port
->remote_identify
.sas_address
);
2475 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2478 _scsih_block_io_device(ioc
, sas_device
->handle
);
2482 list_for_each_entry(mpt2sas_port
,
2483 &sas_expander
->sas_port_list
, port_list
) {
2485 if (mpt2sas_port
->remote_identify
.device_type
==
2486 MPI2_SAS_DEVICE_INFO_EDGE_EXPANDER
||
2487 mpt2sas_port
->remote_identify
.device_type
==
2488 MPI2_SAS_DEVICE_INFO_FANOUT_EXPANDER
) {
2490 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
2492 mpt2sas_scsih_expander_find_by_sas_address(
2493 ioc
, mpt2sas_port
->remote_identify
.sas_address
);
2494 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
2495 _scsih_block_io_to_children_attached_to_ex(ioc
,
2502 * _scsih_block_io_to_children_attached_directly
2503 * @ioc: per adapter object
2504 * @event_data: topology change event data
2506 * This routine set sdev state to SDEV_BLOCK for all devices
2507 * direct attached during device pull.
2510 _scsih_block_io_to_children_attached_directly(struct MPT2SAS_ADAPTER
*ioc
,
2511 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
2518 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
2519 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
2522 phy_number
= event_data
->StartPhyNum
+ i
;
2523 reason_code
= event_data
->PHY
[i
].PhyStatus
&
2524 MPI2_EVENT_SAS_TOPO_RC_MASK
;
2525 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
)
2526 _scsih_block_io_device(ioc
, handle
);
2531 * _scsih_tm_tr_send - send task management request
2532 * @ioc: per adapter object
2533 * @handle: device handle
2534 * Context: interrupt time.
2536 * This code is to initiate the device removal handshake protocal
2537 * with controller firmware. This function will issue target reset
2538 * using high priority request queue. It will send a sas iounit
2539 * controll request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
2541 * This is designed to send muliple task management request at the same
2542 * time to the fifo. If the fifo is full, we will append the request,
2543 * and process it in a future completion.
2546 _scsih_tm_tr_send(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
2548 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
2549 struct MPT2SAS_TARGET
*sas_target_priv_data
;
2551 struct _sas_device
*sas_device
;
2552 unsigned long flags
;
2553 struct _tr_list
*delayed_tr
;
2555 if (ioc
->shost_recovery
) {
2556 printk(MPT2SAS_INFO_FMT
"%s: host reset in progress!\n",
2557 __func__
, ioc
->name
);
2561 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2562 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
2563 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2565 /* skip is hidden raid component */
2566 if (sas_device
&& sas_device
->hidden_raid_component
)
2569 smid
= mpt2sas_base_get_smid_hpr(ioc
, ioc
->tm_tr_cb_idx
);
2571 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
2574 INIT_LIST_HEAD(&delayed_tr
->list
);
2575 delayed_tr
->handle
= handle
;
2576 delayed_tr
->state
= MPT2SAS_REQ_SAS_CNTRL
;
2577 list_add_tail(&delayed_tr
->list
,
2578 &ioc
->delayed_tr_list
);
2579 if (sas_device
&& sas_device
->starget
) {
2580 dewtprintk(ioc
, starget_printk(KERN_INFO
,
2581 sas_device
->starget
, "DELAYED:tr:handle(0x%04x), "
2582 "(open)\n", handle
));
2584 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
2585 "DELAYED:tr:handle(0x%04x), (open)\n",
2586 ioc
->name
, handle
));
2592 sas_device
->state
|= MPTSAS_STATE_TR_SEND
;
2593 sas_device
->state
|= MPT2SAS_REQ_SAS_CNTRL
;
2594 if (sas_device
->starget
&& sas_device
->starget
->hostdata
) {
2595 sas_target_priv_data
= sas_device
->starget
->hostdata
;
2596 sas_target_priv_data
->tm_busy
= 1;
2597 dewtprintk(ioc
, starget_printk(KERN_INFO
,
2598 sas_device
->starget
, "tr:handle(0x%04x), (open)\n",
2602 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
2603 "tr:handle(0x%04x), (open)\n", ioc
->name
, handle
));
2606 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
2607 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
2608 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
2609 mpi_request
->DevHandle
= cpu_to_le16(handle
);
2610 mpi_request
->TaskType
= MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
;
2611 mpt2sas_base_put_smid_hi_priority(ioc
, smid
);
2617 * _scsih_sas_control_complete - completion routine
2618 * @ioc: per adapter object
2619 * @smid: system request message index
2620 * @msix_index: MSIX table index supplied by the OS
2621 * @reply: reply message frame(lower 32bit addr)
2622 * Context: interrupt time.
2624 * This is the sas iounit controll completion routine.
2625 * This code is part of the code to initiate the device removal
2626 * handshake protocal with controller firmware.
2628 * Return 1 meaning mf should be freed from _base_interrupt
2629 * 0 means the mf is freed from this function.
2632 _scsih_sas_control_complete(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
,
2633 u8 msix_index
, u32 reply
)
2635 unsigned long flags
;
2637 struct _sas_device
*sas_device
;
2638 Mpi2SasIoUnitControlReply_t
*mpi_reply
=
2639 mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
2641 handle
= le16_to_cpu(mpi_reply
->DevHandle
);
2643 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2644 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
2645 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2648 sas_device
->state
|= MPTSAS_STATE_CNTRL_COMPLETE
;
2649 if (sas_device
->starget
)
2650 dewtprintk(ioc
, starget_printk(KERN_INFO
,
2651 sas_device
->starget
,
2652 "sc_complete:handle(0x%04x), "
2653 "ioc_status(0x%04x), loginfo(0x%08x)\n",
2654 handle
, le16_to_cpu(mpi_reply
->IOCStatus
),
2655 le32_to_cpu(mpi_reply
->IOCLogInfo
)));
2657 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
2658 "sc_complete:handle(0x%04x), "
2659 "ioc_status(0x%04x), loginfo(0x%08x)\n",
2660 ioc
->name
, handle
, le16_to_cpu(mpi_reply
->IOCStatus
),
2661 le32_to_cpu(mpi_reply
->IOCLogInfo
)));
2668 * _scsih_tm_tr_complete -
2669 * @ioc: per adapter object
2670 * @smid: system request message index
2671 * @msix_index: MSIX table index supplied by the OS
2672 * @reply: reply message frame(lower 32bit addr)
2673 * Context: interrupt time.
2675 * This is the target reset completion routine.
2676 * This code is part of the code to initiate the device removal
2677 * handshake protocal with controller firmware.
2678 * It will send a sas iounit controll request (MPI2_SAS_OP_REMOVE_DEVICE)
2680 * Return 1 meaning mf should be freed from _base_interrupt
2681 * 0 means the mf is freed from this function.
2684 _scsih_tm_tr_complete(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
,
2687 unsigned long flags
;
2689 struct _sas_device
*sas_device
;
2690 Mpi2SCSITaskManagementReply_t
*mpi_reply
=
2691 mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
2692 Mpi2SasIoUnitControlRequest_t
*mpi_request
;
2694 struct MPT2SAS_TARGET
*sas_target_priv_data
;
2695 struct _tr_list
*delayed_tr
;
2698 handle
= le16_to_cpu(mpi_reply
->DevHandle
);
2699 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2700 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
2701 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2704 sas_device
->state
|= MPTSAS_STATE_TR_COMPLETE
;
2705 if (sas_device
->starget
) {
2706 dewtprintk(ioc
, starget_printk(KERN_INFO
,
2707 sas_device
->starget
, "tr_complete:handle(0x%04x), "
2708 "(%s) ioc_status(0x%04x), loginfo(0x%08x), "
2709 "completed(%d)\n", sas_device
->handle
,
2710 (sas_device
->state
& MPT2SAS_REQ_SAS_CNTRL
) ?
2712 le16_to_cpu(mpi_reply
->IOCStatus
),
2713 le32_to_cpu(mpi_reply
->IOCLogInfo
),
2714 le32_to_cpu(mpi_reply
->TerminationCount
)));
2715 if (sas_device
->starget
->hostdata
) {
2716 sas_target_priv_data
=
2717 sas_device
->starget
->hostdata
;
2718 sas_target_priv_data
->tm_busy
= 0;
2722 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
2723 "tr_complete:handle(0x%04x), (open) ioc_status(0x%04x), "
2724 "loginfo(0x%08x), completed(%d)\n", ioc
->name
,
2725 handle
, le16_to_cpu(mpi_reply
->IOCStatus
),
2726 le32_to_cpu(mpi_reply
->IOCLogInfo
),
2727 le32_to_cpu(mpi_reply
->TerminationCount
)));
2730 if (!list_empty(&ioc
->delayed_tr_list
)) {
2731 delayed_tr
= list_entry(ioc
->delayed_tr_list
.next
,
2732 struct _tr_list
, list
);
2733 mpt2sas_base_free_smid(ioc
, smid
);
2734 if (delayed_tr
->state
& MPT2SAS_REQ_SAS_CNTRL
)
2735 _scsih_tm_tr_send(ioc
, delayed_tr
->handle
);
2736 list_del(&delayed_tr
->list
);
2738 rc
= 0; /* tells base_interrupt not to free mf */
2742 if (sas_device
&& !(sas_device
->state
& MPT2SAS_REQ_SAS_CNTRL
))
2745 if (ioc
->shost_recovery
) {
2746 printk(MPT2SAS_INFO_FMT
"%s: host reset in progress!\n",
2747 __func__
, ioc
->name
);
2751 smid_sas_ctrl
= mpt2sas_base_get_smid(ioc
, ioc
->tm_sas_control_cb_idx
);
2752 if (!smid_sas_ctrl
) {
2753 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
2754 ioc
->name
, __func__
);
2759 sas_device
->state
|= MPTSAS_STATE_CNTRL_SEND
;
2761 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid_sas_ctrl
);
2762 memset(mpi_request
, 0, sizeof(Mpi2SasIoUnitControlRequest_t
));
2763 mpi_request
->Function
= MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
;
2764 mpi_request
->Operation
= MPI2_SAS_OP_REMOVE_DEVICE
;
2765 mpi_request
->DevHandle
= mpi_reply
->DevHandle
;
2766 mpt2sas_base_put_smid_default(ioc
, smid_sas_ctrl
);
2771 * _scsih_check_topo_delete_events - sanity check on topo events
2772 * @ioc: per adapter object
2773 * @event_data: the event data payload
2775 * This routine added to better handle cable breaker.
2777 * This handles the case where driver recieves multiple expander
2778 * add and delete events in a single shot. When there is a delete event
2779 * the routine will void any pending add events waiting in the event queue.
2784 _scsih_check_topo_delete_events(struct MPT2SAS_ADAPTER
*ioc
,
2785 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
2787 struct fw_event_work
*fw_event
;
2788 Mpi2EventDataSasTopologyChangeList_t
*local_event_data
;
2789 u16 expander_handle
;
2790 struct _sas_node
*sas_expander
;
2791 unsigned long flags
;
2795 for (i
= 0 ; i
< event_data
->NumEntries
; i
++) {
2796 if (event_data
->PHY
[i
].PhyStatus
&
2797 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT
)
2799 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
2802 reason_code
= event_data
->PHY
[i
].PhyStatus
&
2803 MPI2_EVENT_SAS_TOPO_RC_MASK
;
2804 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
)
2805 _scsih_tm_tr_send(ioc
, handle
);
2808 expander_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
2809 if (expander_handle
< ioc
->sas_hba
.num_phys
) {
2810 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
2814 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
2815 || event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
) {
2816 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
2817 sas_expander
= mpt2sas_scsih_expander_find_by_handle(ioc
,
2819 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
2820 _scsih_block_io_to_children_attached_to_ex(ioc
, sas_expander
);
2821 } else if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_RESPONDING
)
2822 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
2824 if (event_data
->ExpStatus
!= MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
)
2827 /* mark ignore flag for pending events */
2828 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2829 list_for_each_entry(fw_event
, &ioc
->fw_event_list
, list
) {
2830 if (fw_event
->event
!= MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
||
2833 local_event_data
= fw_event
->event_data
;
2834 if (local_event_data
->ExpStatus
==
2835 MPI2_EVENT_SAS_TOPO_ES_ADDED
||
2836 local_event_data
->ExpStatus
==
2837 MPI2_EVENT_SAS_TOPO_ES_RESPONDING
) {
2838 if (le16_to_cpu(local_event_data
->ExpanderDevHandle
) ==
2840 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
2841 "setting ignoring flag\n", ioc
->name
));
2842 fw_event
->ignore
= 1;
2846 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2850 * _scsih_flush_running_cmds - completing outstanding commands.
2851 * @ioc: per adapter object
2853 * The flushing out of all pending scmd commands following host reset,
2854 * where all IO is dropped to the floor.
2859 _scsih_flush_running_cmds(struct MPT2SAS_ADAPTER
*ioc
)
2861 struct scsi_cmnd
*scmd
;
2865 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
2866 scmd
= _scsih_scsi_lookup_get(ioc
, smid
);
2870 mpt2sas_base_free_smid(ioc
, smid
);
2871 scsi_dma_unmap(scmd
);
2872 scmd
->result
= DID_RESET
<< 16;
2873 scmd
->scsi_done(scmd
);
2875 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"completing %d cmds\n",
2880 * _scsih_setup_eedp - setup MPI request for EEDP transfer
2881 * @scmd: pointer to scsi command object
2882 * @mpi_request: pointer to the SCSI_IO reqest message frame
2884 * Supporting protection 1 and 3.
2889 _scsih_setup_eedp(struct scsi_cmnd
*scmd
, Mpi2SCSIIORequest_t
*mpi_request
)
2892 unsigned char prot_op
= scsi_get_prot_op(scmd
);
2893 unsigned char prot_type
= scsi_get_prot_type(scmd
);
2895 if (prot_type
== SCSI_PROT_DIF_TYPE0
||
2896 prot_type
== SCSI_PROT_DIF_TYPE2
||
2897 prot_op
== SCSI_PROT_NORMAL
)
2900 if (prot_op
== SCSI_PROT_READ_STRIP
)
2901 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP
;
2902 else if (prot_op
== SCSI_PROT_WRITE_INSERT
)
2903 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_INSERT_OP
;
2907 switch (prot_type
) {
2908 case SCSI_PROT_DIF_TYPE1
:
2911 * enable ref/guard checking
2912 * auto increment ref tag
2914 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG
|
2915 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG
|
2916 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
2917 mpi_request
->CDB
.EEDP32
.PrimaryReferenceTag
=
2918 cpu_to_be32(scsi_get_lba(scmd
));
2922 case SCSI_PROT_DIF_TYPE3
:
2925 * enable guard checking
2927 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
2930 mpi_request
->EEDPBlockSize
= cpu_to_le32(scmd
->device
->sector_size
);
2931 mpi_request
->EEDPFlags
= cpu_to_le16(eedp_flags
);
2935 * _scsih_eedp_error_handling - return sense code for EEDP errors
2936 * @scmd: pointer to scsi command object
2937 * @ioc_status: ioc status
2942 _scsih_eedp_error_handling(struct scsi_cmnd
*scmd
, u16 ioc_status
)
2948 switch (ioc_status
) {
2949 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
2952 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
2955 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
2963 if (scmd
->sc_data_direction
== DMA_TO_DEVICE
) {
2964 sk
= ILLEGAL_REQUEST
;
2965 host_byte
= DID_ABORT
;
2967 sk
= ABORTED_COMMAND
;
2971 scsi_build_sense_buffer(0, scmd
->sense_buffer
, sk
, 0x10, ascq
);
2972 scmd
->result
= DRIVER_SENSE
<< 24 | (host_byte
<< 16) |
2973 SAM_STAT_CHECK_CONDITION
;
2977 * _scsih_qcmd - main scsi request entry point
2978 * @scmd: pointer to scsi command object
2979 * @done: function pointer to be invoked on completion
2981 * The callback index is set inside `ioc->scsi_io_cb_idx`.
2983 * Returns 0 on success. If there's a failure, return either:
2984 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
2985 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
2988 _scsih_qcmd(struct scsi_cmnd
*scmd
, void (*done
)(struct scsi_cmnd
*))
2990 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2991 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2992 struct MPT2SAS_TARGET
*sas_target_priv_data
;
2993 Mpi2SCSIIORequest_t
*mpi_request
;
2997 scmd
->scsi_done
= done
;
2998 sas_device_priv_data
= scmd
->device
->hostdata
;
2999 if (!sas_device_priv_data
) {
3000 scmd
->result
= DID_NO_CONNECT
<< 16;
3001 scmd
->scsi_done(scmd
);
3005 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
3006 if (!sas_target_priv_data
|| sas_target_priv_data
->handle
==
3007 MPT2SAS_INVALID_DEVICE_HANDLE
|| sas_target_priv_data
->deleted
) {
3008 scmd
->result
= DID_NO_CONNECT
<< 16;
3009 scmd
->scsi_done(scmd
);
3013 /* see if we are busy with task managment stuff */
3014 if (sas_device_priv_data
->block
|| sas_target_priv_data
->tm_busy
)
3015 return SCSI_MLQUEUE_DEVICE_BUSY
;
3016 else if (ioc
->shost_recovery
|| ioc
->ioc_link_reset_in_progress
)
3017 return SCSI_MLQUEUE_HOST_BUSY
;
3019 if (scmd
->sc_data_direction
== DMA_FROM_DEVICE
)
3020 mpi_control
= MPI2_SCSIIO_CONTROL_READ
;
3021 else if (scmd
->sc_data_direction
== DMA_TO_DEVICE
)
3022 mpi_control
= MPI2_SCSIIO_CONTROL_WRITE
;
3024 mpi_control
= MPI2_SCSIIO_CONTROL_NODATATRANSFER
;
3027 if (!(sas_device_priv_data
->flags
& MPT_DEVICE_FLAGS_INIT
)) {
3028 if (scmd
->device
->tagged_supported
) {
3029 if (scmd
->device
->ordered_tags
)
3030 mpi_control
|= MPI2_SCSIIO_CONTROL_ORDEREDQ
;
3032 mpi_control
|= MPI2_SCSIIO_CONTROL_SIMPLEQ
;
3034 /* MPI Revision I (UNIT = 0xA) - removed MPI2_SCSIIO_CONTROL_UNTAGGED */
3035 /* mpi_control |= MPI2_SCSIIO_CONTROL_UNTAGGED;
3037 mpi_control
|= (0x500);
3040 mpi_control
|= MPI2_SCSIIO_CONTROL_SIMPLEQ
;
3041 /* Make sure Device is not raid volume */
3042 if (!_scsih_is_raid(&scmd
->device
->sdev_gendev
) &&
3043 sas_is_tlr_enabled(scmd
->device
))
3044 mpi_control
|= MPI2_SCSIIO_CONTROL_TLR_ON
;
3046 smid
= mpt2sas_base_get_smid_scsiio(ioc
, ioc
->scsi_io_cb_idx
, scmd
);
3048 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
3049 ioc
->name
, __func__
);
3052 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3053 memset(mpi_request
, 0, sizeof(Mpi2SCSIIORequest_t
));
3054 _scsih_setup_eedp(scmd
, mpi_request
);
3055 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
3056 if (sas_device_priv_data
->sas_target
->flags
&
3057 MPT_TARGET_FLAGS_RAID_COMPONENT
)
3058 mpi_request
->Function
= MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
;
3060 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
3061 mpi_request
->DevHandle
=
3062 cpu_to_le16(sas_device_priv_data
->sas_target
->handle
);
3063 mpi_request
->DataLength
= cpu_to_le32(scsi_bufflen(scmd
));
3064 mpi_request
->Control
= cpu_to_le32(mpi_control
);
3065 mpi_request
->IoFlags
= cpu_to_le16(scmd
->cmd_len
);
3066 mpi_request
->MsgFlags
= MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR
;
3067 mpi_request
->SenseBufferLength
= SCSI_SENSE_BUFFERSIZE
;
3068 mpi_request
->SenseBufferLowAddress
=
3069 mpt2sas_base_get_sense_buffer_dma(ioc
, smid
);
3070 mpi_request
->SGLOffset0
= offsetof(Mpi2SCSIIORequest_t
, SGL
) / 4;
3071 mpi_request
->SGLFlags
= cpu_to_le16(MPI2_SCSIIO_SGLFLAGS_TYPE_MPI
+
3072 MPI2_SCSIIO_SGLFLAGS_SYSTEM_ADDR
);
3073 mpi_request
->VF_ID
= 0; /* TODO */
3074 mpi_request
->VP_ID
= 0;
3075 int_to_scsilun(sas_device_priv_data
->lun
, (struct scsi_lun
*)
3077 memcpy(mpi_request
->CDB
.CDB32
, scmd
->cmnd
, scmd
->cmd_len
);
3079 if (!mpi_request
->DataLength
) {
3080 mpt2sas_base_build_zero_len_sge(ioc
, &mpi_request
->SGL
);
3082 if (_scsih_build_scatter_gather(ioc
, scmd
, smid
)) {
3083 mpt2sas_base_free_smid(ioc
, smid
);
3088 mpt2sas_base_put_smid_scsi_io(ioc
, smid
,
3089 sas_device_priv_data
->sas_target
->handle
);
3093 return SCSI_MLQUEUE_HOST_BUSY
;
3097 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
3098 * @sense_buffer: sense data returned by target
3099 * @data: normalized skey/asc/ascq
3104 _scsih_normalize_sense(char *sense_buffer
, struct sense_info
*data
)
3106 if ((sense_buffer
[0] & 0x7F) >= 0x72) {
3107 /* descriptor format */
3108 data
->skey
= sense_buffer
[1] & 0x0F;
3109 data
->asc
= sense_buffer
[2];
3110 data
->ascq
= sense_buffer
[3];
3113 data
->skey
= sense_buffer
[2] & 0x0F;
3114 data
->asc
= sense_buffer
[12];
3115 data
->ascq
= sense_buffer
[13];
3119 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3121 * _scsih_scsi_ioc_info - translated non-successfull SCSI_IO request
3122 * @ioc: per adapter object
3123 * @scmd: pointer to scsi command object
3124 * @mpi_reply: reply mf payload returned from firmware
3126 * scsi_status - SCSI Status code returned from target device
3127 * scsi_state - state info associated with SCSI_IO determined by ioc
3128 * ioc_status - ioc supplied status info
3133 _scsih_scsi_ioc_info(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
,
3134 Mpi2SCSIIOReply_t
*mpi_reply
, u16 smid
)
3138 u16 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) &
3139 MPI2_IOCSTATUS_MASK
;
3140 u8 scsi_state
= mpi_reply
->SCSIState
;
3141 u8 scsi_status
= mpi_reply
->SCSIStatus
;
3142 char *desc_ioc_state
= NULL
;
3143 char *desc_scsi_status
= NULL
;
3144 char *desc_scsi_state
= ioc
->tmp_string
;
3145 u32 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
3147 if (log_info
== 0x31170000)
3150 switch (ioc_status
) {
3151 case MPI2_IOCSTATUS_SUCCESS
:
3152 desc_ioc_state
= "success";
3154 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
3155 desc_ioc_state
= "invalid function";
3157 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
3158 desc_ioc_state
= "scsi recovered error";
3160 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE
:
3161 desc_ioc_state
= "scsi invalid dev handle";
3163 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
3164 desc_ioc_state
= "scsi device not there";
3166 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
3167 desc_ioc_state
= "scsi data overrun";
3169 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
3170 desc_ioc_state
= "scsi data underrun";
3172 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
3173 desc_ioc_state
= "scsi io data error";
3175 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
3176 desc_ioc_state
= "scsi protocol error";
3178 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
3179 desc_ioc_state
= "scsi task terminated";
3181 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
3182 desc_ioc_state
= "scsi residual mismatch";
3184 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
3185 desc_ioc_state
= "scsi task mgmt failed";
3187 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
3188 desc_ioc_state
= "scsi ioc terminated";
3190 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
3191 desc_ioc_state
= "scsi ext terminated";
3193 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
3194 desc_ioc_state
= "eedp guard error";
3196 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
3197 desc_ioc_state
= "eedp ref tag error";
3199 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
3200 desc_ioc_state
= "eedp app tag error";
3203 desc_ioc_state
= "unknown";
3207 switch (scsi_status
) {
3208 case MPI2_SCSI_STATUS_GOOD
:
3209 desc_scsi_status
= "good";
3211 case MPI2_SCSI_STATUS_CHECK_CONDITION
:
3212 desc_scsi_status
= "check condition";
3214 case MPI2_SCSI_STATUS_CONDITION_MET
:
3215 desc_scsi_status
= "condition met";
3217 case MPI2_SCSI_STATUS_BUSY
:
3218 desc_scsi_status
= "busy";
3220 case MPI2_SCSI_STATUS_INTERMEDIATE
:
3221 desc_scsi_status
= "intermediate";
3223 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET
:
3224 desc_scsi_status
= "intermediate condmet";
3226 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT
:
3227 desc_scsi_status
= "reservation conflict";
3229 case MPI2_SCSI_STATUS_COMMAND_TERMINATED
:
3230 desc_scsi_status
= "command terminated";
3232 case MPI2_SCSI_STATUS_TASK_SET_FULL
:
3233 desc_scsi_status
= "task set full";
3235 case MPI2_SCSI_STATUS_ACA_ACTIVE
:
3236 desc_scsi_status
= "aca active";
3238 case MPI2_SCSI_STATUS_TASK_ABORTED
:
3239 desc_scsi_status
= "task aborted";
3242 desc_scsi_status
= "unknown";
3246 desc_scsi_state
[0] = '\0';
3248 desc_scsi_state
= " ";
3249 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
3250 strcat(desc_scsi_state
, "response info ");
3251 if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
3252 strcat(desc_scsi_state
, "state terminated ");
3253 if (scsi_state
& MPI2_SCSI_STATE_NO_SCSI_STATUS
)
3254 strcat(desc_scsi_state
, "no status ");
3255 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_FAILED
)
3256 strcat(desc_scsi_state
, "autosense failed ");
3257 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
)
3258 strcat(desc_scsi_state
, "autosense valid ");
3260 scsi_print_command(scmd
);
3261 printk(MPT2SAS_WARN_FMT
"\tdev handle(0x%04x), "
3262 "ioc_status(%s)(0x%04x), smid(%d)\n", ioc
->name
,
3263 le16_to_cpu(mpi_reply
->DevHandle
), desc_ioc_state
,
3265 printk(MPT2SAS_WARN_FMT
"\trequest_len(%d), underflow(%d), "
3266 "resid(%d)\n", ioc
->name
, scsi_bufflen(scmd
), scmd
->underflow
,
3267 scsi_get_resid(scmd
));
3268 printk(MPT2SAS_WARN_FMT
"\ttag(%d), transfer_count(%d), "
3269 "sc->result(0x%08x)\n", ioc
->name
, le16_to_cpu(mpi_reply
->TaskTag
),
3270 le32_to_cpu(mpi_reply
->TransferCount
), scmd
->result
);
3271 printk(MPT2SAS_WARN_FMT
"\tscsi_status(%s)(0x%02x), "
3272 "scsi_state(%s)(0x%02x)\n", ioc
->name
, desc_scsi_status
,
3273 scsi_status
, desc_scsi_state
, scsi_state
);
3275 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
3276 struct sense_info data
;
3277 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
3278 printk(MPT2SAS_WARN_FMT
"\t[sense_key,asc,ascq]: "
3279 "[0x%02x,0x%02x,0x%02x]\n", ioc
->name
, data
.skey
,
3280 data
.asc
, data
.ascq
);
3283 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
) {
3284 response_info
= le32_to_cpu(mpi_reply
->ResponseInfo
);
3285 response_bytes
= (u8
*)&response_info
;
3286 _scsih_response_code(ioc
, response_bytes
[0]);
3292 * _scsih_smart_predicted_fault - illuminate Fault LED
3293 * @ioc: per adapter object
3294 * @handle: device handle
3299 _scsih_smart_predicted_fault(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
3301 Mpi2SepReply_t mpi_reply
;
3302 Mpi2SepRequest_t mpi_request
;
3303 struct scsi_target
*starget
;
3304 struct MPT2SAS_TARGET
*sas_target_priv_data
;
3305 Mpi2EventNotificationReply_t
*event_reply
;
3306 Mpi2EventDataSasDeviceStatusChange_t
*event_data
;
3307 struct _sas_device
*sas_device
;
3309 unsigned long flags
;
3311 /* only handle non-raid devices */
3312 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
3313 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
3315 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3318 starget
= sas_device
->starget
;
3319 sas_target_priv_data
= starget
->hostdata
;
3321 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
) ||
3322 ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
))) {
3323 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3326 starget_printk(KERN_WARNING
, starget
, "predicted fault\n");
3327 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3329 if (ioc
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_IBM
) {
3330 memset(&mpi_request
, 0, sizeof(Mpi2SepRequest_t
));
3331 mpi_request
.Function
= MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR
;
3332 mpi_request
.Action
= MPI2_SEP_REQ_ACTION_WRITE_STATUS
;
3333 mpi_request
.SlotStatus
=
3334 MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT
;
3335 mpi_request
.DevHandle
= cpu_to_le16(handle
);
3336 mpi_request
.Flags
= MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS
;
3337 if ((mpt2sas_base_scsi_enclosure_processor(ioc
, &mpi_reply
,
3338 &mpi_request
)) != 0) {
3339 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3340 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3344 if (mpi_reply
.IOCStatus
|| mpi_reply
.IOCLogInfo
) {
3345 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3346 "enclosure_processor: ioc_status (0x%04x), "
3347 "loginfo(0x%08x)\n", ioc
->name
,
3348 le16_to_cpu(mpi_reply
.IOCStatus
),
3349 le32_to_cpu(mpi_reply
.IOCLogInfo
)));
3354 /* insert into event log */
3355 sz
= offsetof(Mpi2EventNotificationReply_t
, EventData
) +
3356 sizeof(Mpi2EventDataSasDeviceStatusChange_t
);
3357 event_reply
= kzalloc(sz
, GFP_KERNEL
);
3359 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3360 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3364 event_reply
->Function
= MPI2_FUNCTION_EVENT_NOTIFICATION
;
3365 event_reply
->Event
=
3366 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
);
3367 event_reply
->MsgLength
= sz
/4;
3368 event_reply
->EventDataLength
=
3369 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t
)/4);
3370 event_data
= (Mpi2EventDataSasDeviceStatusChange_t
*)
3371 event_reply
->EventData
;
3372 event_data
->ReasonCode
= MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
;
3373 event_data
->ASC
= 0x5D;
3374 event_data
->DevHandle
= cpu_to_le16(handle
);
3375 event_data
->SASAddress
= cpu_to_le64(sas_target_priv_data
->sas_address
);
3376 mpt2sas_ctl_add_to_event_log(ioc
, event_reply
);
3381 * _scsih_io_done - scsi request callback
3382 * @ioc: per adapter object
3383 * @smid: system request message index
3384 * @msix_index: MSIX table index supplied by the OS
3385 * @reply: reply message frame(lower 32bit addr)
3387 * Callback handler when using _scsih_qcmd.
3389 * Return 1 meaning mf should be freed from _base_interrupt
3390 * 0 means the mf is freed from this function.
3393 _scsih_io_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
3395 Mpi2SCSIIORequest_t
*mpi_request
;
3396 Mpi2SCSIIOReply_t
*mpi_reply
;
3397 struct scsi_cmnd
*scmd
;
3403 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
3404 u32 response_code
= 0;
3406 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
3407 scmd
= _scsih_scsi_lookup_get(ioc
, smid
);
3411 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3413 if (mpi_reply
== NULL
) {
3414 scmd
->result
= DID_OK
<< 16;
3418 sas_device_priv_data
= scmd
->device
->hostdata
;
3419 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
||
3420 sas_device_priv_data
->sas_target
->deleted
) {
3421 scmd
->result
= DID_NO_CONNECT
<< 16;
3425 /* turning off TLR */
3426 scsi_state
= mpi_reply
->SCSIState
;
3427 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
3429 le32_to_cpu(mpi_reply
->ResponseInfo
) & 0xFF;
3430 if (!sas_device_priv_data
->tlr_snoop_check
) {
3431 sas_device_priv_data
->tlr_snoop_check
++;
3432 if (!_scsih_is_raid(&scmd
->device
->sdev_gendev
) &&
3433 sas_is_tlr_enabled(scmd
->device
) &&
3434 response_code
== MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
) {
3435 sas_disable_tlr(scmd
->device
);
3436 sdev_printk(KERN_INFO
, scmd
->device
, "TLR disabled\n");
3440 xfer_cnt
= le32_to_cpu(mpi_reply
->TransferCount
);
3441 scsi_set_resid(scmd
, scsi_bufflen(scmd
) - xfer_cnt
);
3442 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
);
3443 if (ioc_status
& MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE
)
3444 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
3447 ioc_status
&= MPI2_IOCSTATUS_MASK
;
3448 scsi_status
= mpi_reply
->SCSIStatus
;
3450 if (ioc_status
== MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
&& xfer_cnt
== 0 &&
3451 (scsi_status
== MPI2_SCSI_STATUS_BUSY
||
3452 scsi_status
== MPI2_SCSI_STATUS_RESERVATION_CONFLICT
||
3453 scsi_status
== MPI2_SCSI_STATUS_TASK_SET_FULL
)) {
3454 ioc_status
= MPI2_IOCSTATUS_SUCCESS
;
3457 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
3458 struct sense_info data
;
3459 const void *sense_data
= mpt2sas_base_get_sense_buffer(ioc
,
3461 u32 sz
= min_t(u32
, SCSI_SENSE_BUFFERSIZE
,
3462 le32_to_cpu(mpi_reply
->SenseCount
));
3463 memcpy(scmd
->sense_buffer
, sense_data
, sz
);
3464 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
3465 /* failure prediction threshold exceeded */
3466 if (data
.asc
== 0x5D)
3467 _scsih_smart_predicted_fault(ioc
,
3468 le16_to_cpu(mpi_reply
->DevHandle
));
3471 switch (ioc_status
) {
3472 case MPI2_IOCSTATUS_BUSY
:
3473 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES
:
3474 scmd
->result
= SAM_STAT_BUSY
;
3477 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
3478 scmd
->result
= DID_NO_CONNECT
<< 16;
3481 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
3482 if (sas_device_priv_data
->block
) {
3483 scmd
->result
= DID_TRANSPORT_DISRUPTED
<< 16;
3486 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
3487 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
3488 scmd
->result
= DID_RESET
<< 16;
3491 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
3492 if ((xfer_cnt
== 0) || (scmd
->underflow
> xfer_cnt
))
3493 scmd
->result
= DID_SOFT_ERROR
<< 16;
3495 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
3498 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
3499 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
3501 if ((scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
))
3504 if (xfer_cnt
< scmd
->underflow
) {
3505 if (scsi_status
== SAM_STAT_BUSY
)
3506 scmd
->result
= SAM_STAT_BUSY
;
3508 scmd
->result
= DID_SOFT_ERROR
<< 16;
3509 } else if (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
3510 MPI2_SCSI_STATE_NO_SCSI_STATUS
))
3511 scmd
->result
= DID_SOFT_ERROR
<< 16;
3512 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
3513 scmd
->result
= DID_RESET
<< 16;
3514 else if (!xfer_cnt
&& scmd
->cmnd
[0] == REPORT_LUNS
) {
3515 mpi_reply
->SCSIState
= MPI2_SCSI_STATE_AUTOSENSE_VALID
;
3516 mpi_reply
->SCSIStatus
= SAM_STAT_CHECK_CONDITION
;
3517 scmd
->result
= (DRIVER_SENSE
<< 24) |
3518 SAM_STAT_CHECK_CONDITION
;
3519 scmd
->sense_buffer
[0] = 0x70;
3520 scmd
->sense_buffer
[2] = ILLEGAL_REQUEST
;
3521 scmd
->sense_buffer
[12] = 0x20;
3522 scmd
->sense_buffer
[13] = 0;
3526 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
3527 scsi_set_resid(scmd
, 0);
3528 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
3529 case MPI2_IOCSTATUS_SUCCESS
:
3530 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
3531 if (response_code
==
3532 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
||
3533 (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
3534 MPI2_SCSI_STATE_NO_SCSI_STATUS
)))
3535 scmd
->result
= DID_SOFT_ERROR
<< 16;
3536 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
3537 scmd
->result
= DID_RESET
<< 16;
3540 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
3541 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
3542 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
3543 _scsih_eedp_error_handling(scmd
, ioc_status
);
3545 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
3546 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
3547 case MPI2_IOCSTATUS_INVALID_SGL
:
3548 case MPI2_IOCSTATUS_INTERNAL_ERROR
:
3549 case MPI2_IOCSTATUS_INVALID_FIELD
:
3550 case MPI2_IOCSTATUS_INVALID_STATE
:
3551 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
3552 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
3554 scmd
->result
= DID_SOFT_ERROR
<< 16;
3559 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3560 if (scmd
->result
&& (ioc
->logging_level
& MPT_DEBUG_REPLY
))
3561 _scsih_scsi_ioc_info(ioc
, scmd
, mpi_reply
, smid
);
3565 scsi_dma_unmap(scmd
);
3566 scmd
->scsi_done(scmd
);
3571 * _scsih_sas_host_refresh - refreshing sas host object contents
3572 * @ioc: per adapter object
3575 * During port enable, fw will send topology events for every device. Its
3576 * possible that the handles may change from the previous setting, so this
3577 * code keeping handles updating if changed.
3582 _scsih_sas_host_refresh(struct MPT2SAS_ADAPTER
*ioc
)
3587 Mpi2ConfigReply_t mpi_reply
;
3588 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
3589 u16 attached_handle
;
3591 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
3592 "updating handles for sas_host(0x%016llx)\n",
3593 ioc
->name
, (unsigned long long)ioc
->sas_hba
.sas_address
));
3595 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
3596 * sizeof(Mpi2SasIOUnit0PhyData_t
));
3597 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
3598 if (!sas_iounit_pg0
) {
3599 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3600 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3604 if ((mpt2sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
3605 sas_iounit_pg0
, sz
)) != 0)
3607 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
3608 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
3610 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
3612 ioc
->sas_hba
.handle
= le16_to_cpu(sas_iounit_pg0
->
3613 PhyData
[0].ControllerDevHandle
);
3614 ioc
->sas_hba
.phy
[i
].handle
= ioc
->sas_hba
.handle
;
3615 attached_handle
= le16_to_cpu(sas_iounit_pg0
->PhyData
[i
].
3617 mpt2sas_transport_update_links(ioc
, ioc
->sas_hba
.sas_address
,
3618 attached_handle
, i
, sas_iounit_pg0
->PhyData
[i
].
3619 NegotiatedLinkRate
>> 4);
3622 kfree(sas_iounit_pg0
);
3626 * _scsih_sas_host_add - create sas host object
3627 * @ioc: per adapter object
3629 * Creating host side data object, stored in ioc->sas_hba
3634 _scsih_sas_host_add(struct MPT2SAS_ADAPTER
*ioc
)
3637 Mpi2ConfigReply_t mpi_reply
;
3638 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
3639 Mpi2SasIOUnitPage1_t
*sas_iounit_pg1
= NULL
;
3640 Mpi2SasPhyPage0_t phy_pg0
;
3641 Mpi2SasDevicePage0_t sas_device_pg0
;
3642 Mpi2SasEnclosurePage0_t enclosure_pg0
;
3645 u16 device_missing_delay
;
3647 mpt2sas_config_get_number_hba_phys(ioc
, &ioc
->sas_hba
.num_phys
);
3648 if (!ioc
->sas_hba
.num_phys
) {
3649 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3650 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3654 /* sas_iounit page 0 */
3655 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
3656 sizeof(Mpi2SasIOUnit0PhyData_t
));
3657 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
3658 if (!sas_iounit_pg0
) {
3659 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3660 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3663 if ((mpt2sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
3664 sas_iounit_pg0
, sz
))) {
3665 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3666 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3669 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
3670 MPI2_IOCSTATUS_MASK
;
3671 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
3672 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3673 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3677 /* sas_iounit page 1 */
3678 sz
= offsetof(Mpi2SasIOUnitPage1_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
3679 sizeof(Mpi2SasIOUnit1PhyData_t
));
3680 sas_iounit_pg1
= kzalloc(sz
, GFP_KERNEL
);
3681 if (!sas_iounit_pg1
) {
3682 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3683 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3686 if ((mpt2sas_config_get_sas_iounit_pg1(ioc
, &mpi_reply
,
3687 sas_iounit_pg1
, sz
))) {
3688 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3689 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3692 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
3693 MPI2_IOCSTATUS_MASK
;
3694 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
3695 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3696 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3700 ioc
->io_missing_delay
=
3701 le16_to_cpu(sas_iounit_pg1
->IODeviceMissingDelay
);
3702 device_missing_delay
=
3703 le16_to_cpu(sas_iounit_pg1
->ReportDeviceMissingDelay
);
3704 if (device_missing_delay
& MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16
)
3705 ioc
->device_missing_delay
= (device_missing_delay
&
3706 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
) * 16;
3708 ioc
->device_missing_delay
= device_missing_delay
&
3709 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
;
3711 ioc
->sas_hba
.parent_dev
= &ioc
->shost
->shost_gendev
;
3712 ioc
->sas_hba
.phy
= kcalloc(ioc
->sas_hba
.num_phys
,
3713 sizeof(struct _sas_phy
), GFP_KERNEL
);
3714 if (!ioc
->sas_hba
.phy
) {
3715 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3716 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3719 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
3720 if ((mpt2sas_config_get_phy_pg0(ioc
, &mpi_reply
, &phy_pg0
,
3722 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3723 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3726 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
3727 MPI2_IOCSTATUS_MASK
;
3728 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
3729 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3730 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3735 ioc
->sas_hba
.handle
= le16_to_cpu(sas_iounit_pg0
->
3736 PhyData
[0].ControllerDevHandle
);
3737 ioc
->sas_hba
.phy
[i
].handle
= ioc
->sas_hba
.handle
;
3738 ioc
->sas_hba
.phy
[i
].phy_id
= i
;
3739 mpt2sas_transport_add_host_phy(ioc
, &ioc
->sas_hba
.phy
[i
],
3740 phy_pg0
, ioc
->sas_hba
.parent_dev
);
3742 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
3743 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, ioc
->sas_hba
.handle
))) {
3744 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3745 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3748 ioc
->sas_hba
.enclosure_handle
=
3749 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
3750 ioc
->sas_hba
.sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
3751 printk(MPT2SAS_INFO_FMT
"host_add: handle(0x%04x), "
3752 "sas_addr(0x%016llx), phys(%d)\n", ioc
->name
, ioc
->sas_hba
.handle
,
3753 (unsigned long long) ioc
->sas_hba
.sas_address
,
3754 ioc
->sas_hba
.num_phys
) ;
3756 if (ioc
->sas_hba
.enclosure_handle
) {
3757 if (!(mpt2sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
3759 MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
3760 ioc
->sas_hba
.enclosure_handle
))) {
3761 ioc
->sas_hba
.enclosure_logical_id
=
3762 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
3767 kfree(sas_iounit_pg1
);
3768 kfree(sas_iounit_pg0
);
3772 * _scsih_expander_add - creating expander object
3773 * @ioc: per adapter object
3774 * @handle: expander handle
3776 * Creating expander object, stored in ioc->sas_expander_list.
3778 * Return 0 for success, else error.
3781 _scsih_expander_add(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
3783 struct _sas_node
*sas_expander
;
3784 Mpi2ConfigReply_t mpi_reply
;
3785 Mpi2ExpanderPage0_t expander_pg0
;
3786 Mpi2ExpanderPage1_t expander_pg1
;
3787 Mpi2SasEnclosurePage0_t enclosure_pg0
;
3790 __le64 sas_address
, sas_address_parent
= 0;
3792 unsigned long flags
;
3793 struct _sas_port
*mpt2sas_port
= NULL
;
3799 if (ioc
->shost_recovery
)
3802 if ((mpt2sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
3803 MPI2_SAS_EXPAND_PGAD_FORM_HNDL
, handle
))) {
3804 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3805 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3809 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
3810 MPI2_IOCSTATUS_MASK
;
3811 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
3812 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3813 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3817 /* handle out of order topology events */
3818 parent_handle
= le16_to_cpu(expander_pg0
.ParentDevHandle
);
3819 if (_scsih_get_sas_address(ioc
, parent_handle
, &sas_address_parent
)
3821 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3822 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3825 if (sas_address_parent
!= ioc
->sas_hba
.sas_address
) {
3826 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
3827 sas_expander
= mpt2sas_scsih_expander_find_by_sas_address(ioc
,
3828 sas_address_parent
);
3829 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
3830 if (!sas_expander
) {
3831 rc
= _scsih_expander_add(ioc
, parent_handle
);
3837 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
3838 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
3839 sas_expander
= mpt2sas_scsih_expander_find_by_sas_address(ioc
,
3841 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
3846 sas_expander
= kzalloc(sizeof(struct _sas_node
),
3848 if (!sas_expander
) {
3849 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3850 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3854 sas_expander
->handle
= handle
;
3855 sas_expander
->num_phys
= expander_pg0
.NumPhys
;
3856 sas_expander
->sas_address_parent
= sas_address_parent
;
3857 sas_expander
->sas_address
= sas_address
;
3859 printk(MPT2SAS_INFO_FMT
"expander_add: handle(0x%04x),"
3860 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc
->name
,
3861 handle
, parent_handle
, (unsigned long long)
3862 sas_expander
->sas_address
, sas_expander
->num_phys
);
3864 if (!sas_expander
->num_phys
)
3866 sas_expander
->phy
= kcalloc(sas_expander
->num_phys
,
3867 sizeof(struct _sas_phy
), GFP_KERNEL
);
3868 if (!sas_expander
->phy
) {
3869 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3870 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3875 INIT_LIST_HEAD(&sas_expander
->sas_port_list
);
3876 mpt2sas_port
= mpt2sas_transport_port_add(ioc
, handle
,
3877 sas_address_parent
);
3878 if (!mpt2sas_port
) {
3879 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3880 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3884 sas_expander
->parent_dev
= &mpt2sas_port
->rphy
->dev
;
3886 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++) {
3887 if ((mpt2sas_config_get_expander_pg1(ioc
, &mpi_reply
,
3888 &expander_pg1
, i
, handle
))) {
3889 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3890 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3894 sas_expander
->phy
[i
].handle
= handle
;
3895 sas_expander
->phy
[i
].phy_id
= i
;
3897 if ((mpt2sas_transport_add_expander_phy(ioc
,
3898 &sas_expander
->phy
[i
], expander_pg1
,
3899 sas_expander
->parent_dev
))) {
3900 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3901 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3907 if (sas_expander
->enclosure_handle
) {
3908 if (!(mpt2sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
3909 &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
3910 sas_expander
->enclosure_handle
))) {
3911 sas_expander
->enclosure_logical_id
=
3912 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
3916 _scsih_expander_node_add(ioc
, sas_expander
);
3922 mpt2sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
3923 sas_address_parent
);
3924 kfree(sas_expander
);
3929 * _scsih_done - scsih callback handler.
3930 * @ioc: per adapter object
3931 * @smid: system request message index
3932 * @msix_index: MSIX table index supplied by the OS
3933 * @reply: reply message frame(lower 32bit addr)
3935 * Callback handler when sending internal generated message frames.
3936 * The callback index passed is `ioc->scsih_cb_idx`
3938 * Return 1 meaning mf should be freed from _base_interrupt
3939 * 0 means the mf is freed from this function.
3942 _scsih_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
3944 MPI2DefaultReply_t
*mpi_reply
;
3946 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
3947 if (ioc
->scsih_cmds
.status
== MPT2_CMD_NOT_USED
)
3949 if (ioc
->scsih_cmds
.smid
!= smid
)
3951 ioc
->scsih_cmds
.status
|= MPT2_CMD_COMPLETE
;
3953 memcpy(ioc
->scsih_cmds
.reply
, mpi_reply
,
3954 mpi_reply
->MsgLength
*4);
3955 ioc
->scsih_cmds
.status
|= MPT2_CMD_REPLY_VALID
;
3957 ioc
->scsih_cmds
.status
&= ~MPT2_CMD_PENDING
;
3958 complete(&ioc
->scsih_cmds
.done
);
3963 * _scsih_expander_remove - removing expander object
3964 * @ioc: per adapter object
3965 * @sas_address: expander sas_address
3970 _scsih_expander_remove(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
)
3972 struct _sas_node
*sas_expander
;
3973 unsigned long flags
;
3975 if (ioc
->shost_recovery
)
3978 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
3979 sas_expander
= mpt2sas_scsih_expander_find_by_sas_address(ioc
,
3981 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
3982 _scsih_expander_node_remove(ioc
, sas_expander
);
3986 * _scsih_add_device - creating sas device object
3987 * @ioc: per adapter object
3988 * @handle: sas device handle
3989 * @phy_num: phy number end device attached to
3990 * @is_pd: is this hidden raid component
3992 * Creating end device object, stored in ioc->sas_device_list.
3994 * Returns 0 for success, non-zero for failure.
3997 _scsih_add_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
, u8 phy_num
, u8 is_pd
)
3999 Mpi2ConfigReply_t mpi_reply
;
4000 Mpi2SasDevicePage0_t sas_device_pg0
;
4001 Mpi2SasEnclosurePage0_t enclosure_pg0
;
4002 struct _sas_device
*sas_device
;
4006 unsigned long flags
;
4008 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
4009 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
4010 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4011 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4015 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4016 MPI2_IOCSTATUS_MASK
;
4017 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4018 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4019 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4023 /* check if device is present */
4024 if (!(le16_to_cpu(sas_device_pg0
.Flags
) &
4025 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT
)) {
4026 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4027 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4028 printk(MPT2SAS_ERR_FMT
"Flags = 0x%04x\n",
4029 ioc
->name
, le16_to_cpu(sas_device_pg0
.Flags
));
4033 /* check if there were any issus with discovery */
4034 if (sas_device_pg0
.AccessStatus
==
4035 MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED
) {
4036 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4037 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4038 printk(MPT2SAS_ERR_FMT
"AccessStatus = 0x%02x\n",
4039 ioc
->name
, sas_device_pg0
.AccessStatus
);
4043 /* check if this is end device */
4044 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
4045 if (!(_scsih_is_end_device(device_info
))) {
4046 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4047 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4051 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
4053 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4054 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
4056 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4059 _scsih_ublock_io_device(ioc
, handle
);
4063 sas_device
= kzalloc(sizeof(struct _sas_device
),
4066 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4067 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4071 sas_device
->handle
= handle
;
4072 if (_scsih_get_sas_address(ioc
, le16_to_cpu
4073 (sas_device_pg0
.ParentDevHandle
),
4074 &sas_device
->sas_address_parent
) != 0)
4075 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4076 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4077 sas_device
->enclosure_handle
=
4078 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
4080 le16_to_cpu(sas_device_pg0
.Slot
);
4081 sas_device
->device_info
= device_info
;
4082 sas_device
->sas_address
= sas_address
;
4083 sas_device
->hidden_raid_component
= is_pd
;
4085 /* get enclosure_logical_id */
4086 if (sas_device
->enclosure_handle
&& !(mpt2sas_config_get_enclosure_pg0(
4087 ioc
, &mpi_reply
, &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
4088 sas_device
->enclosure_handle
)))
4089 sas_device
->enclosure_logical_id
=
4090 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
4092 /* get device name */
4093 sas_device
->device_name
= le64_to_cpu(sas_device_pg0
.DeviceName
);
4095 if (ioc
->wait_for_port_enable_to_complete
)
4096 _scsih_sas_device_init_add(ioc
, sas_device
);
4098 _scsih_sas_device_add(ioc
, sas_device
);
4104 * _scsih_remove_device - removing sas device object
4105 * @ioc: per adapter object
4106 * @sas_device: the sas_device object
4111 _scsih_remove_device(struct MPT2SAS_ADAPTER
*ioc
, struct _sas_device
4114 struct MPT2SAS_TARGET
*sas_target_priv_data
;
4115 Mpi2SasIoUnitControlReply_t mpi_reply
;
4116 Mpi2SasIoUnitControlRequest_t mpi_request
;
4117 u16 device_handle
, handle
;
4122 handle
= sas_device
->handle
;
4123 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: enter: handle(0x%04x),"
4124 " sas_addr(0x%016llx)\n", ioc
->name
, __func__
, handle
,
4125 (unsigned long long) sas_device
->sas_address
));
4127 if (sas_device
->starget
&& sas_device
->starget
->hostdata
) {
4128 sas_target_priv_data
= sas_device
->starget
->hostdata
;
4129 sas_target_priv_data
->deleted
= 1;
4132 if (ioc
->remove_host
|| ioc
->shost_recovery
|| !handle
)
4135 if ((sas_device
->state
& MPTSAS_STATE_TR_COMPLETE
)) {
4136 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"\tskip "
4137 "target_reset handle(0x%04x)\n", ioc
->name
,
4142 /* Target Reset to flush out all the outstanding IO */
4143 device_handle
= (sas_device
->hidden_raid_component
) ?
4144 sas_device
->volume_handle
: handle
;
4145 if (device_handle
) {
4146 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"issue target reset: "
4147 "handle(0x%04x)\n", ioc
->name
, device_handle
));
4148 mutex_lock(&ioc
->tm_cmds
.mutex
);
4149 mpt2sas_scsih_issue_tm(ioc
, device_handle
, 0,
4150 MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
, 0, 10);
4151 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
4152 mutex_unlock(&ioc
->tm_cmds
.mutex
);
4153 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"issue target reset "
4154 "done: handle(0x%04x)\n", ioc
->name
, device_handle
));
4155 if (ioc
->shost_recovery
)
4160 if ((sas_device
->state
& MPTSAS_STATE_CNTRL_COMPLETE
)) {
4161 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"\tskip "
4162 "sas_cntrl handle(0x%04x)\n", ioc
->name
, handle
));
4166 /* SAS_IO_UNIT_CNTR - send REMOVE_DEVICE */
4167 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"sas_iounit: handle"
4168 "(0x%04x)\n", ioc
->name
, handle
));
4169 memset(&mpi_request
, 0, sizeof(Mpi2SasIoUnitControlRequest_t
));
4170 mpi_request
.Function
= MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
;
4171 mpi_request
.Operation
= MPI2_SAS_OP_REMOVE_DEVICE
;
4172 mpi_request
.DevHandle
= handle
;
4173 mpi_request
.VF_ID
= 0; /* TODO */
4174 mpi_request
.VP_ID
= 0;
4175 if ((mpt2sas_base_sas_iounit_control(ioc
, &mpi_reply
,
4176 &mpi_request
)) != 0) {
4177 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4178 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4181 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"sas_iounit: ioc_status"
4182 "(0x%04x), loginfo(0x%08x)\n", ioc
->name
,
4183 le16_to_cpu(mpi_reply
.IOCStatus
),
4184 le32_to_cpu(mpi_reply
.IOCLogInfo
)));
4188 _scsih_ublock_io_device(ioc
, handle
);
4190 mpt2sas_transport_port_remove(ioc
, sas_device
->sas_address
,
4191 sas_device
->sas_address_parent
);
4193 printk(MPT2SAS_INFO_FMT
"removing handle(0x%04x), sas_addr"
4194 "(0x%016llx)\n", ioc
->name
, handle
,
4195 (unsigned long long) sas_device
->sas_address
);
4196 _scsih_sas_device_remove(ioc
, sas_device
);
4198 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: exit: handle"
4199 "(0x%04x)\n", ioc
->name
, __func__
, handle
));
4202 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4204 * _scsih_sas_topology_change_event_debug - debug for topology event
4205 * @ioc: per adapter object
4206 * @event_data: event data payload
4210 _scsih_sas_topology_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
4211 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
4217 char *status_str
= NULL
;
4218 u8 link_rate
, prev_link_rate
;
4220 switch (event_data
->ExpStatus
) {
4221 case MPI2_EVENT_SAS_TOPO_ES_ADDED
:
4224 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
:
4225 status_str
= "remove";
4227 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING
:
4229 status_str
= "responding";
4231 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
:
4232 status_str
= "remove delay";
4235 status_str
= "unknown status";
4238 printk(MPT2SAS_DEBUG_FMT
"sas topology change: (%s)\n",
4239 ioc
->name
, status_str
);
4240 printk(KERN_DEBUG
"\thandle(0x%04x), enclosure_handle(0x%04x) "
4241 "start_phy(%02d), count(%d)\n",
4242 le16_to_cpu(event_data
->ExpanderDevHandle
),
4243 le16_to_cpu(event_data
->EnclosureHandle
),
4244 event_data
->StartPhyNum
, event_data
->NumEntries
);
4245 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
4246 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
4249 phy_number
= event_data
->StartPhyNum
+ i
;
4250 reason_code
= event_data
->PHY
[i
].PhyStatus
&
4251 MPI2_EVENT_SAS_TOPO_RC_MASK
;
4252 switch (reason_code
) {
4253 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
4254 status_str
= "target add";
4256 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
4257 status_str
= "target remove";
4259 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
:
4260 status_str
= "delay target remove";
4262 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
4263 status_str
= "link rate change";
4265 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE
:
4266 status_str
= "target responding";
4269 status_str
= "unknown";
4272 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
4273 prev_link_rate
= event_data
->PHY
[i
].LinkRate
& 0xF;
4274 printk(KERN_DEBUG
"\tphy(%02d), attached_handle(0x%04x): %s:"
4275 " link rate: new(0x%02x), old(0x%02x)\n", phy_number
,
4276 handle
, status_str
, link_rate
, prev_link_rate
);
4283 * _scsih_sas_topology_change_event - handle topology changes
4284 * @ioc: per adapter object
4285 * @fw_event: The fw_event_work object
4290 _scsih_sas_topology_change_event(struct MPT2SAS_ADAPTER
*ioc
,
4291 struct fw_event_work
*fw_event
)
4294 u16 parent_handle
, handle
;
4297 struct _sas_node
*sas_expander
;
4298 struct _sas_device
*sas_device
;
4300 unsigned long flags
;
4301 u8 link_rate
, prev_link_rate
;
4302 Mpi2EventDataSasTopologyChangeList_t
*event_data
= fw_event
->event_data
;
4304 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4305 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
4306 _scsih_sas_topology_change_event_debug(ioc
, event_data
);
4309 if (ioc
->shost_recovery
)
4312 if (!ioc
->sas_hba
.num_phys
)
4313 _scsih_sas_host_add(ioc
);
4315 _scsih_sas_host_refresh(ioc
);
4317 if (fw_event
->ignore
) {
4318 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"ignoring expander "
4319 "event\n", ioc
->name
));
4323 parent_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
4325 /* handle expander add */
4326 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_ADDED
)
4327 if (_scsih_expander_add(ioc
, parent_handle
) != 0)
4330 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
4331 sas_expander
= mpt2sas_scsih_expander_find_by_handle(ioc
,
4333 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
4335 sas_address
= sas_expander
->sas_address
;
4336 else if (parent_handle
< ioc
->sas_hba
.num_phys
)
4337 sas_address
= ioc
->sas_hba
.sas_address
;
4341 /* handle siblings events */
4342 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
4343 if (fw_event
->ignore
) {
4344 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"ignoring "
4345 "expander event\n", ioc
->name
));
4348 if (ioc
->shost_recovery
)
4350 phy_number
= event_data
->StartPhyNum
+ i
;
4351 reason_code
= event_data
->PHY
[i
].PhyStatus
&
4352 MPI2_EVENT_SAS_TOPO_RC_MASK
;
4353 if ((event_data
->PHY
[i
].PhyStatus
&
4354 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT
) && (reason_code
!=
4355 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
))
4357 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
4360 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
4361 prev_link_rate
= event_data
->PHY
[i
].LinkRate
& 0xF;
4362 switch (reason_code
) {
4363 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
4365 if (link_rate
== prev_link_rate
)
4368 mpt2sas_transport_update_links(ioc
, sas_address
,
4369 handle
, phy_number
, link_rate
);
4371 if (link_rate
>= MPI2_SAS_NEG_LINK_RATE_1_5
)
4372 _scsih_ublock_io_device(ioc
, handle
);
4374 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
4376 mpt2sas_transport_update_links(ioc
, sas_address
,
4377 handle
, phy_number
, link_rate
);
4379 _scsih_add_device(ioc
, handle
, phy_number
, 0);
4381 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
4383 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4384 sas_device
= _scsih_sas_device_find_by_handle(ioc
,
4387 spin_unlock_irqrestore(&ioc
->sas_device_lock
,
4391 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4392 _scsih_remove_device(ioc
, sas_device
);
4397 /* handle expander removal */
4398 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
&&
4400 _scsih_expander_remove(ioc
, sas_address
);
4404 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4406 * _scsih_sas_device_status_change_event_debug - debug for device event
4407 * @event_data: event data payload
4413 _scsih_sas_device_status_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
4414 Mpi2EventDataSasDeviceStatusChange_t
*event_data
)
4416 char *reason_str
= NULL
;
4418 switch (event_data
->ReasonCode
) {
4419 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
:
4420 reason_str
= "smart data";
4422 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED
:
4423 reason_str
= "unsupported device discovered";
4425 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
:
4426 reason_str
= "internal device reset";
4428 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL
:
4429 reason_str
= "internal task abort";
4431 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL
:
4432 reason_str
= "internal task abort set";
4434 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL
:
4435 reason_str
= "internal clear task set";
4437 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL
:
4438 reason_str
= "internal query task";
4440 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE
:
4441 reason_str
= "sata init failure";
4443 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
:
4444 reason_str
= "internal device reset complete";
4446 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL
:
4447 reason_str
= "internal task abort complete";
4449 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION
:
4450 reason_str
= "internal async notification";
4452 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY
:
4453 reason_str
= "expander reduced functionality";
4455 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY
:
4456 reason_str
= "expander reduced functionality complete";
4459 reason_str
= "unknown reason";
4462 printk(MPT2SAS_DEBUG_FMT
"device status change: (%s)\n"
4463 "\thandle(0x%04x), sas address(0x%016llx)", ioc
->name
,
4464 reason_str
, le16_to_cpu(event_data
->DevHandle
),
4465 (unsigned long long)le64_to_cpu(event_data
->SASAddress
));
4466 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
)
4467 printk(MPT2SAS_DEBUG_FMT
", ASC(0x%x), ASCQ(0x%x)\n", ioc
->name
,
4468 event_data
->ASC
, event_data
->ASCQ
);
4469 printk(KERN_INFO
"\n");
4474 * _scsih_sas_device_status_change_event - handle device status change
4475 * @ioc: per adapter object
4476 * @fw_event: The fw_event_work object
4482 _scsih_sas_device_status_change_event(struct MPT2SAS_ADAPTER
*ioc
,
4483 struct fw_event_work
*fw_event
)
4485 struct MPT2SAS_TARGET
*target_priv_data
;
4486 struct _sas_device
*sas_device
;
4488 unsigned long flags
;
4489 Mpi2EventDataSasDeviceStatusChange_t
*event_data
=
4490 fw_event
->event_data
;
4492 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4493 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
4494 _scsih_sas_device_status_change_event_debug(ioc
,
4498 if (!(event_data
->ReasonCode
==
4499 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
&&
4500 event_data
->ReasonCode
==
4501 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
))
4504 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4505 sas_address
= le64_to_cpu(event_data
->SASAddress
);
4506 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
4508 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4510 if (!sas_device
|| !sas_device
->starget
)
4513 target_priv_data
= sas_device
->starget
->hostdata
;
4514 if (!target_priv_data
)
4517 if (event_data
->ReasonCode
==
4518 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
)
4519 target_priv_data
->tm_busy
= 1;
4521 target_priv_data
->tm_busy
= 0;
4524 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4526 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure event
4527 * @ioc: per adapter object
4528 * @event_data: event data payload
4534 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
4535 Mpi2EventDataSasEnclDevStatusChange_t
*event_data
)
4537 char *reason_str
= NULL
;
4539 switch (event_data
->ReasonCode
) {
4540 case MPI2_EVENT_SAS_ENCL_RC_ADDED
:
4541 reason_str
= "enclosure add";
4543 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING
:
4544 reason_str
= "enclosure remove";
4547 reason_str
= "unknown reason";
4551 printk(MPT2SAS_DEBUG_FMT
"enclosure status change: (%s)\n"
4552 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
4553 " number slots(%d)\n", ioc
->name
, reason_str
,
4554 le16_to_cpu(event_data
->EnclosureHandle
),
4555 (unsigned long long)le64_to_cpu(event_data
->EnclosureLogicalID
),
4556 le16_to_cpu(event_data
->StartSlot
));
4561 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
4562 * @ioc: per adapter object
4563 * @fw_event: The fw_event_work object
4569 _scsih_sas_enclosure_dev_status_change_event(struct MPT2SAS_ADAPTER
*ioc
,
4570 struct fw_event_work
*fw_event
)
4572 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4573 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
4574 _scsih_sas_enclosure_dev_status_change_event_debug(ioc
,
4575 fw_event
->event_data
);
4580 * _scsih_sas_broadcast_primative_event - handle broadcast events
4581 * @ioc: per adapter object
4582 * @fw_event: The fw_event_work object
4588 _scsih_sas_broadcast_primative_event(struct MPT2SAS_ADAPTER
*ioc
,
4589 struct fw_event_work
*fw_event
)
4591 struct scsi_cmnd
*scmd
;
4594 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
4595 u32 termination_count
;
4597 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
4598 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4599 Mpi2EventDataSasBroadcastPrimitive_t
*event_data
= fw_event
->event_data
;
4602 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"broadcast primative: "
4603 "phy number(%d), width(%d)\n", ioc
->name
, event_data
->PhyNum
,
4604 event_data
->PortWidth
));
4605 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: enter\n", ioc
->name
,
4608 mutex_lock(&ioc
->tm_cmds
.mutex
);
4609 termination_count
= 0;
4611 mpi_reply
= ioc
->tm_cmds
.reply
;
4612 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
4613 scmd
= _scsih_scsi_lookup_get(ioc
, smid
);
4616 sas_device_priv_data
= scmd
->device
->hostdata
;
4617 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
)
4619 /* skip hidden raid components */
4620 if (sas_device_priv_data
->sas_target
->flags
&
4621 MPT_TARGET_FLAGS_RAID_COMPONENT
)
4624 if (sas_device_priv_data
->sas_target
->flags
&
4625 MPT_TARGET_FLAGS_VOLUME
)
4628 handle
= sas_device_priv_data
->sas_target
->handle
;
4629 lun
= sas_device_priv_data
->lun
;
4632 mpt2sas_scsih_issue_tm(ioc
, handle
, lun
,
4633 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK
, smid
, 30);
4634 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
4635 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
)
4636 & MPI2_IOCSTATUS_MASK
;
4637 if ((ioc_status
== MPI2_IOCSTATUS_SUCCESS
) &&
4638 (mpi_reply
->ResponseCode
==
4639 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
||
4640 mpi_reply
->ResponseCode
==
4641 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
))
4644 mpt2sas_scsih_issue_tm(ioc
, handle
, lun
,
4645 MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET
, 0, 30);
4646 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
4647 termination_count
+= le32_to_cpu(mpi_reply
->TerminationCount
);
4649 ioc
->broadcast_aen_busy
= 0;
4650 mutex_unlock(&ioc
->tm_cmds
.mutex
);
4652 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
4653 "%s - exit, query_count = %d termination_count = %d\n",
4654 ioc
->name
, __func__
, query_count
, termination_count
));
4658 * _scsih_sas_discovery_event - handle discovery events
4659 * @ioc: per adapter object
4660 * @fw_event: The fw_event_work object
4666 _scsih_sas_discovery_event(struct MPT2SAS_ADAPTER
*ioc
,
4667 struct fw_event_work
*fw_event
)
4669 Mpi2EventDataSasDiscovery_t
*event_data
= fw_event
->event_data
;
4671 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4672 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
) {
4673 printk(MPT2SAS_DEBUG_FMT
"discovery event: (%s)", ioc
->name
,
4674 (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
) ?
4676 if (event_data
->DiscoveryStatus
)
4677 printk("discovery_status(0x%08x)",
4678 le32_to_cpu(event_data
->DiscoveryStatus
));
4683 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
&&
4684 !ioc
->sas_hba
.num_phys
)
4685 _scsih_sas_host_add(ioc
);
4689 * _scsih_reprobe_lun - reprobing lun
4690 * @sdev: scsi device struct
4691 * @no_uld_attach: sdev->no_uld_attach flag setting
4695 _scsih_reprobe_lun(struct scsi_device
*sdev
, void *no_uld_attach
)
4699 sdev
->no_uld_attach
= no_uld_attach
? 1 : 0;
4700 sdev_printk(KERN_INFO
, sdev
, "%s raid component\n",
4701 sdev
->no_uld_attach
? "hidding" : "exposing");
4702 rc
= scsi_device_reprobe(sdev
);
4706 * _scsih_reprobe_target - reprobing target
4707 * @starget: scsi target struct
4708 * @no_uld_attach: sdev->no_uld_attach flag setting
4710 * Note: no_uld_attach flag determines whether the disk device is attached
4711 * to block layer. A value of `1` means to not attach.
4714 _scsih_reprobe_target(struct scsi_target
*starget
, int no_uld_attach
)
4716 struct MPT2SAS_TARGET
*sas_target_priv_data
= starget
->hostdata
;
4719 sas_target_priv_data
->flags
|= MPT_TARGET_FLAGS_RAID_COMPONENT
;
4721 sas_target_priv_data
->flags
&= ~MPT_TARGET_FLAGS_RAID_COMPONENT
;
4723 starget_for_each_device(starget
, no_uld_attach
? (void *)1 : NULL
,
4724 _scsih_reprobe_lun
);
4727 * _scsih_sas_volume_add - add new volume
4728 * @ioc: per adapter object
4729 * @element: IR config element data
4735 _scsih_sas_volume_add(struct MPT2SAS_ADAPTER
*ioc
,
4736 Mpi2EventIrConfigElement_t
*element
)
4738 struct _raid_device
*raid_device
;
4739 unsigned long flags
;
4741 u16 handle
= le16_to_cpu(element
->VolDevHandle
);
4744 mpt2sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
4746 printk(MPT2SAS_ERR_FMT
4747 "failure at %s:%d/%s()!\n", ioc
->name
,
4748 __FILE__
, __LINE__
, __func__
);
4752 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
4753 raid_device
= _scsih_raid_device_find_by_wwid(ioc
, wwid
);
4754 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
4759 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
4761 printk(MPT2SAS_ERR_FMT
4762 "failure at %s:%d/%s()!\n", ioc
->name
,
4763 __FILE__
, __LINE__
, __func__
);
4767 raid_device
->id
= ioc
->sas_id
++;
4768 raid_device
->channel
= RAID_CHANNEL
;
4769 raid_device
->handle
= handle
;
4770 raid_device
->wwid
= wwid
;
4771 _scsih_raid_device_add(ioc
, raid_device
);
4772 if (!ioc
->wait_for_port_enable_to_complete
) {
4773 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
4774 raid_device
->id
, 0);
4776 _scsih_raid_device_remove(ioc
, raid_device
);
4778 _scsih_determine_boot_device(ioc
, raid_device
, 1);
4782 * _scsih_sas_volume_delete - delete volume
4783 * @ioc: per adapter object
4784 * @element: IR config element data
4790 _scsih_sas_volume_delete(struct MPT2SAS_ADAPTER
*ioc
,
4791 Mpi2EventIrConfigElement_t
*element
)
4793 struct _raid_device
*raid_device
;
4794 u16 handle
= le16_to_cpu(element
->VolDevHandle
);
4795 unsigned long flags
;
4796 struct MPT2SAS_TARGET
*sas_target_priv_data
;
4798 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
4799 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
4800 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
4803 if (raid_device
->starget
) {
4804 sas_target_priv_data
= raid_device
->starget
->hostdata
;
4805 sas_target_priv_data
->deleted
= 1;
4806 scsi_remove_target(&raid_device
->starget
->dev
);
4808 _scsih_raid_device_remove(ioc
, raid_device
);
4812 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
4813 * @ioc: per adapter object
4814 * @element: IR config element data
4820 _scsih_sas_pd_expose(struct MPT2SAS_ADAPTER
*ioc
,
4821 Mpi2EventIrConfigElement_t
*element
)
4823 struct _sas_device
*sas_device
;
4824 unsigned long flags
;
4825 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
4827 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4828 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
4829 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4833 /* exposing raid component */
4834 sas_device
->volume_handle
= 0;
4835 sas_device
->volume_wwid
= 0;
4836 sas_device
->hidden_raid_component
= 0;
4837 _scsih_reprobe_target(sas_device
->starget
, 0);
4841 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
4842 * @ioc: per adapter object
4843 * @element: IR config element data
4849 _scsih_sas_pd_hide(struct MPT2SAS_ADAPTER
*ioc
,
4850 Mpi2EventIrConfigElement_t
*element
)
4852 struct _sas_device
*sas_device
;
4853 unsigned long flags
;
4854 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
4856 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4857 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
4858 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4862 /* hiding raid component */
4863 mpt2sas_config_get_volume_handle(ioc
, handle
,
4864 &sas_device
->volume_handle
);
4865 mpt2sas_config_get_volume_wwid(ioc
, sas_device
->volume_handle
,
4866 &sas_device
->volume_wwid
);
4867 sas_device
->hidden_raid_component
= 1;
4868 _scsih_reprobe_target(sas_device
->starget
, 1);
4872 * _scsih_sas_pd_delete - delete pd component
4873 * @ioc: per adapter object
4874 * @element: IR config element data
4880 _scsih_sas_pd_delete(struct MPT2SAS_ADAPTER
*ioc
,
4881 Mpi2EventIrConfigElement_t
*element
)
4883 struct _sas_device
*sas_device
;
4884 unsigned long flags
;
4885 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
4887 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4888 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
4889 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4892 _scsih_remove_device(ioc
, sas_device
);
4896 * _scsih_sas_pd_add - remove pd component
4897 * @ioc: per adapter object
4898 * @element: IR config element data
4904 _scsih_sas_pd_add(struct MPT2SAS_ADAPTER
*ioc
,
4905 Mpi2EventIrConfigElement_t
*element
)
4907 struct _sas_device
*sas_device
;
4908 unsigned long flags
;
4909 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
4910 Mpi2ConfigReply_t mpi_reply
;
4911 Mpi2SasDevicePage0_t sas_device_pg0
;
4916 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4917 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
4918 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4920 sas_device
->hidden_raid_component
= 1;
4924 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
4925 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
4926 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4927 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4931 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4932 MPI2_IOCSTATUS_MASK
;
4933 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4934 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4935 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4939 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
4940 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
4941 mpt2sas_transport_update_links(ioc
, sas_address
, handle
,
4942 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
4944 _scsih_add_device(ioc
, handle
, 0, 1);
4947 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4949 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
4950 * @ioc: per adapter object
4951 * @event_data: event data payload
4957 _scsih_sas_ir_config_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
4958 Mpi2EventDataIrConfigChangeList_t
*event_data
)
4960 Mpi2EventIrConfigElement_t
*element
;
4963 char *reason_str
= NULL
, *element_str
= NULL
;
4965 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
4967 printk(MPT2SAS_DEBUG_FMT
"raid config change: (%s), elements(%d)\n",
4968 ioc
->name
, (le32_to_cpu(event_data
->Flags
) &
4969 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ?
4970 "foreign" : "native", event_data
->NumElements
);
4971 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
4972 switch (element
->ReasonCode
) {
4973 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
4976 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
4977 reason_str
= "remove";
4979 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE
:
4980 reason_str
= "no change";
4982 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
4983 reason_str
= "hide";
4985 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
4986 reason_str
= "unhide";
4988 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
4989 reason_str
= "volume_created";
4991 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
4992 reason_str
= "volume_deleted";
4994 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
4995 reason_str
= "pd_created";
4997 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
4998 reason_str
= "pd_deleted";
5001 reason_str
= "unknown reason";
5004 element_type
= le16_to_cpu(element
->ElementFlags
) &
5005 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK
;
5006 switch (element_type
) {
5007 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT
:
5008 element_str
= "volume";
5010 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT
:
5011 element_str
= "phys disk";
5013 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT
:
5014 element_str
= "hot spare";
5017 element_str
= "unknown element";
5020 printk(KERN_DEBUG
"\t(%s:%s), vol handle(0x%04x), "
5021 "pd handle(0x%04x), pd num(0x%02x)\n", element_str
,
5022 reason_str
, le16_to_cpu(element
->VolDevHandle
),
5023 le16_to_cpu(element
->PhysDiskDevHandle
),
5024 element
->PhysDiskNum
);
5030 * _scsih_sas_ir_config_change_event - handle ir configuration change events
5031 * @ioc: per adapter object
5032 * @fw_event: The fw_event_work object
5038 _scsih_sas_ir_config_change_event(struct MPT2SAS_ADAPTER
*ioc
,
5039 struct fw_event_work
*fw_event
)
5041 Mpi2EventIrConfigElement_t
*element
;
5044 Mpi2EventDataIrConfigChangeList_t
*event_data
= fw_event
->event_data
;
5046 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5047 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5048 _scsih_sas_ir_config_change_event_debug(ioc
, event_data
);
5051 foreign_config
= (le32_to_cpu(event_data
->Flags
) &
5052 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ? 1 : 0;
5054 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
5055 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
5057 switch (element
->ReasonCode
) {
5058 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
5059 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
5060 if (!foreign_config
)
5061 _scsih_sas_volume_add(ioc
, element
);
5063 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
5064 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
5065 if (!foreign_config
)
5066 _scsih_sas_volume_delete(ioc
, element
);
5068 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
5069 _scsih_sas_pd_hide(ioc
, element
);
5071 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
5072 _scsih_sas_pd_expose(ioc
, element
);
5074 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
5075 _scsih_sas_pd_add(ioc
, element
);
5077 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
5078 _scsih_sas_pd_delete(ioc
, element
);
5085 * _scsih_sas_ir_volume_event - IR volume event
5086 * @ioc: per adapter object
5087 * @fw_event: The fw_event_work object
5093 _scsih_sas_ir_volume_event(struct MPT2SAS_ADAPTER
*ioc
,
5094 struct fw_event_work
*fw_event
)
5097 unsigned long flags
;
5098 struct _raid_device
*raid_device
;
5102 struct MPT2SAS_TARGET
*sas_target_priv_data
;
5103 Mpi2EventDataIrVolume_t
*event_data
= fw_event
->event_data
;
5105 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED
)
5108 handle
= le16_to_cpu(event_data
->VolDevHandle
);
5109 state
= le32_to_cpu(event_data
->NewValue
);
5110 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: handle(0x%04x), "
5111 "old(0x%08x), new(0x%08x)\n", ioc
->name
, __func__
, handle
,
5112 le32_to_cpu(event_data
->PreviousValue
), state
));
5114 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5115 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
5116 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5119 case MPI2_RAID_VOL_STATE_MISSING
:
5120 case MPI2_RAID_VOL_STATE_FAILED
:
5123 if (raid_device
->starget
) {
5124 sas_target_priv_data
= raid_device
->starget
->hostdata
;
5125 sas_target_priv_data
->deleted
= 1;
5126 scsi_remove_target(&raid_device
->starget
->dev
);
5128 _scsih_raid_device_remove(ioc
, raid_device
);
5131 case MPI2_RAID_VOL_STATE_ONLINE
:
5132 case MPI2_RAID_VOL_STATE_DEGRADED
:
5133 case MPI2_RAID_VOL_STATE_OPTIMAL
:
5137 mpt2sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
5139 printk(MPT2SAS_ERR_FMT
5140 "failure at %s:%d/%s()!\n", ioc
->name
,
5141 __FILE__
, __LINE__
, __func__
);
5145 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
5147 printk(MPT2SAS_ERR_FMT
5148 "failure at %s:%d/%s()!\n", ioc
->name
,
5149 __FILE__
, __LINE__
, __func__
);
5153 raid_device
->id
= ioc
->sas_id
++;
5154 raid_device
->channel
= RAID_CHANNEL
;
5155 raid_device
->handle
= handle
;
5156 raid_device
->wwid
= wwid
;
5157 _scsih_raid_device_add(ioc
, raid_device
);
5158 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
5159 raid_device
->id
, 0);
5161 _scsih_raid_device_remove(ioc
, raid_device
);
5164 case MPI2_RAID_VOL_STATE_INITIALIZING
:
5171 * _scsih_sas_ir_physical_disk_event - PD event
5172 * @ioc: per adapter object
5173 * @fw_event: The fw_event_work object
5179 _scsih_sas_ir_physical_disk_event(struct MPT2SAS_ADAPTER
*ioc
,
5180 struct fw_event_work
*fw_event
)
5182 u16 handle
, parent_handle
;
5184 struct _sas_device
*sas_device
;
5185 unsigned long flags
;
5186 Mpi2ConfigReply_t mpi_reply
;
5187 Mpi2SasDevicePage0_t sas_device_pg0
;
5189 Mpi2EventDataIrPhysicalDisk_t
*event_data
= fw_event
->event_data
;
5192 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED
)
5195 handle
= le16_to_cpu(event_data
->PhysDiskDevHandle
);
5196 state
= le32_to_cpu(event_data
->NewValue
);
5198 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: handle(0x%04x), "
5199 "old(0x%08x), new(0x%08x)\n", ioc
->name
, __func__
, handle
,
5200 le32_to_cpu(event_data
->PreviousValue
), state
));
5202 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5203 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
5204 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5207 case MPI2_RAID_PD_STATE_ONLINE
:
5208 case MPI2_RAID_PD_STATE_DEGRADED
:
5209 case MPI2_RAID_PD_STATE_REBUILDING
:
5210 case MPI2_RAID_PD_STATE_OPTIMAL
:
5212 sas_device
->hidden_raid_component
= 1;
5216 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
5217 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
5219 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5220 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5224 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5225 MPI2_IOCSTATUS_MASK
;
5226 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5227 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5228 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5232 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
5233 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
5234 mpt2sas_transport_update_links(ioc
, sas_address
, handle
,
5235 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
5237 _scsih_add_device(ioc
, handle
, 0, 1);
5241 case MPI2_RAID_PD_STATE_OFFLINE
:
5242 case MPI2_RAID_PD_STATE_NOT_CONFIGURED
:
5243 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE
:
5244 case MPI2_RAID_PD_STATE_HOT_SPARE
:
5250 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5252 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
5253 * @ioc: per adapter object
5254 * @event_data: event data payload
5260 _scsih_sas_ir_operation_status_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
5261 Mpi2EventDataIrOperationStatus_t
*event_data
)
5263 char *reason_str
= NULL
;
5265 switch (event_data
->RAIDOperation
) {
5266 case MPI2_EVENT_IR_RAIDOP_RESYNC
:
5267 reason_str
= "resync";
5269 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION
:
5270 reason_str
= "online capacity expansion";
5272 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK
:
5273 reason_str
= "consistency check";
5275 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT
:
5276 reason_str
= "background init";
5278 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT
:
5279 reason_str
= "make data consistent";
5286 printk(MPT2SAS_INFO_FMT
"raid operational status: (%s)"
5287 "\thandle(0x%04x), percent complete(%d)\n",
5288 ioc
->name
, reason_str
,
5289 le16_to_cpu(event_data
->VolDevHandle
),
5290 event_data
->PercentComplete
);
5295 * _scsih_sas_ir_operation_status_event - handle RAID operation events
5296 * @ioc: per adapter object
5297 * @fw_event: The fw_event_work object
5303 _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER
*ioc
,
5304 struct fw_event_work
*fw_event
)
5306 Mpi2EventDataIrOperationStatus_t
*event_data
= fw_event
->event_data
;
5307 static struct _raid_device
*raid_device
;
5308 unsigned long flags
;
5311 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5312 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5313 _scsih_sas_ir_operation_status_event_debug(ioc
,
5317 /* code added for raid transport support */
5318 if (event_data
->RAIDOperation
== MPI2_EVENT_IR_RAIDOP_RESYNC
) {
5320 handle
= le16_to_cpu(event_data
->VolDevHandle
);
5322 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5323 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
5324 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5329 if (event_data
->RAIDOperation
== MPI2_EVENT_IR_RAIDOP_RESYNC
)
5330 raid_device
->percent_complete
=
5331 event_data
->PercentComplete
;
5336 * _scsih_task_set_full - handle task set full
5337 * @ioc: per adapter object
5338 * @fw_event: The fw_event_work object
5341 * Throttle back qdepth.
5344 _scsih_task_set_full(struct MPT2SAS_ADAPTER
*ioc
, struct fw_event_work
5347 unsigned long flags
;
5348 struct _sas_device
*sas_device
;
5349 static struct _raid_device
*raid_device
;
5350 struct scsi_device
*sdev
;
5356 Mpi2EventDataTaskSetFull_t
*event_data
= fw_event
->event_data
;
5358 current_depth
= le16_to_cpu(event_data
->CurrentDepth
);
5359 handle
= le16_to_cpu(event_data
->DevHandle
);
5360 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5361 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
5363 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5366 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5367 id
= sas_device
->id
;
5368 channel
= sas_device
->channel
;
5369 sas_address
= sas_device
->sas_address
;
5371 /* if hidden raid component, then change to volume characteristics */
5372 if (sas_device
->hidden_raid_component
&& sas_device
->volume_handle
) {
5373 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5374 raid_device
= _scsih_raid_device_find_by_handle(
5375 ioc
, sas_device
->volume_handle
);
5376 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5378 id
= raid_device
->id
;
5379 channel
= raid_device
->channel
;
5380 handle
= raid_device
->handle
;
5381 sas_address
= raid_device
->wwid
;
5385 if (ioc
->logging_level
& MPT_DEBUG_TASK_SET_FULL
)
5386 starget_printk(KERN_DEBUG
, sas_device
->starget
, "task set "
5387 "full: handle(0x%04x), sas_addr(0x%016llx), depth(%d)\n",
5388 handle
, (unsigned long long)sas_address
, current_depth
);
5390 shost_for_each_device(sdev
, ioc
->shost
) {
5391 if (sdev
->id
== id
&& sdev
->channel
== channel
) {
5392 if (current_depth
> sdev
->queue_depth
) {
5393 if (ioc
->logging_level
&
5394 MPT_DEBUG_TASK_SET_FULL
)
5395 sdev_printk(KERN_INFO
, sdev
, "strange "
5396 "observation, the queue depth is"
5397 " (%d) meanwhile fw queue depth "
5398 "is (%d)\n", sdev
->queue_depth
,
5402 depth
= scsi_track_queue_full(sdev
,
5405 sdev_printk(KERN_INFO
, sdev
, "Queue depth "
5406 "reduced to (%d)\n", depth
);
5408 sdev_printk(KERN_INFO
, sdev
, "Tagged Command "
5409 "Queueing is being disabled\n");
5410 else if (depth
== 0)
5411 if (ioc
->logging_level
&
5412 MPT_DEBUG_TASK_SET_FULL
)
5413 sdev_printk(KERN_INFO
, sdev
,
5414 "Queue depth not changed yet\n");
5420 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
5421 * @ioc: per adapter object
5422 * @sas_address: sas address
5423 * @slot: enclosure slot id
5424 * @handle: device handle
5426 * After host reset, find out whether devices are still responding.
5427 * Used in _scsi_remove_unresponsive_sas_devices.
5432 _scsih_mark_responding_sas_device(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
,
5433 u16 slot
, u16 handle
)
5435 struct MPT2SAS_TARGET
*sas_target_priv_data
;
5436 struct scsi_target
*starget
;
5437 struct _sas_device
*sas_device
;
5438 unsigned long flags
;
5440 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5441 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
) {
5442 if (sas_device
->sas_address
== sas_address
&&
5443 sas_device
->slot
== slot
&& sas_device
->starget
) {
5444 sas_device
->responding
= 1;
5445 sas_device
->state
= 0;
5446 starget
= sas_device
->starget
;
5447 sas_target_priv_data
= starget
->hostdata
;
5448 sas_target_priv_data
->tm_busy
= 0;
5449 starget_printk(KERN_INFO
, sas_device
->starget
,
5450 "handle(0x%04x), sas_addr(0x%016llx), enclosure "
5451 "logical id(0x%016llx), slot(%d)\n", handle
,
5452 (unsigned long long)sas_device
->sas_address
,
5453 (unsigned long long)
5454 sas_device
->enclosure_logical_id
,
5456 if (sas_device
->handle
== handle
)
5458 printk(KERN_INFO
"\thandle changed from(0x%04x)!!!\n",
5459 sas_device
->handle
);
5460 sas_device
->handle
= handle
;
5461 sas_target_priv_data
->handle
= handle
;
5466 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5470 * _scsih_search_responding_sas_devices -
5471 * @ioc: per adapter object
5473 * After host reset, find out whether devices are still responding.
5479 _scsih_search_responding_sas_devices(struct MPT2SAS_ADAPTER
*ioc
)
5481 Mpi2SasDevicePage0_t sas_device_pg0
;
5482 Mpi2ConfigReply_t mpi_reply
;
5489 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
, __func__
);
5491 if (list_empty(&ioc
->sas_device_list
))
5495 while (!(mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
5496 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
,
5498 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5499 MPI2_IOCSTATUS_MASK
;
5500 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
5502 handle
= le16_to_cpu(sas_device_pg0
.DevHandle
);
5503 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
5504 if (!(_scsih_is_end_device(device_info
)))
5506 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
5507 slot
= le16_to_cpu(sas_device_pg0
.Slot
);
5508 _scsih_mark_responding_sas_device(ioc
, sas_address
, slot
,
5514 * _scsih_mark_responding_raid_device - mark a raid_device as responding
5515 * @ioc: per adapter object
5516 * @wwid: world wide identifier for raid volume
5517 * @handle: device handle
5519 * After host reset, find out whether devices are still responding.
5520 * Used in _scsi_remove_unresponsive_raid_devices.
5525 _scsih_mark_responding_raid_device(struct MPT2SAS_ADAPTER
*ioc
, u64 wwid
,
5528 struct MPT2SAS_TARGET
*sas_target_priv_data
;
5529 struct scsi_target
*starget
;
5530 struct _raid_device
*raid_device
;
5531 unsigned long flags
;
5533 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5534 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
5535 if (raid_device
->wwid
== wwid
&& raid_device
->starget
) {
5536 raid_device
->responding
= 1;
5537 starget_printk(KERN_INFO
, raid_device
->starget
,
5538 "handle(0x%04x), wwid(0x%016llx)\n", handle
,
5539 (unsigned long long)raid_device
->wwid
);
5540 if (raid_device
->handle
== handle
)
5542 printk(KERN_INFO
"\thandle changed from(0x%04x)!!!\n",
5543 raid_device
->handle
);
5544 raid_device
->handle
= handle
;
5545 starget
= raid_device
->starget
;
5546 sas_target_priv_data
= starget
->hostdata
;
5547 sas_target_priv_data
->handle
= handle
;
5552 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5556 * _scsih_search_responding_raid_devices -
5557 * @ioc: per adapter object
5559 * After host reset, find out whether devices are still responding.
5565 _scsih_search_responding_raid_devices(struct MPT2SAS_ADAPTER
*ioc
)
5567 Mpi2RaidVolPage1_t volume_pg1
;
5568 Mpi2ConfigReply_t mpi_reply
;
5572 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
, __func__
);
5574 if (list_empty(&ioc
->raid_device_list
))
5578 while (!(mpt2sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
5579 &volume_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
5580 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5581 MPI2_IOCSTATUS_MASK
;
5582 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
5584 handle
= le16_to_cpu(volume_pg1
.DevHandle
);
5585 _scsih_mark_responding_raid_device(ioc
,
5586 le64_to_cpu(volume_pg1
.WWID
), handle
);
5591 * _scsih_mark_responding_expander - mark a expander as responding
5592 * @ioc: per adapter object
5593 * @sas_address: sas address
5596 * After host reset, find out whether devices are still responding.
5597 * Used in _scsi_remove_unresponsive_expanders.
5602 _scsih_mark_responding_expander(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
,
5605 struct _sas_node
*sas_expander
;
5606 unsigned long flags
;
5609 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5610 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
5611 if (sas_expander
->sas_address
!= sas_address
)
5613 sas_expander
->responding
= 1;
5614 if (sas_expander
->handle
== handle
)
5616 printk(KERN_INFO
"\texpander(0x%016llx): handle changed"
5617 " from(0x%04x) to (0x%04x)!!!\n",
5618 (unsigned long long)sas_expander
->sas_address
,
5619 sas_expander
->handle
, handle
);
5620 sas_expander
->handle
= handle
;
5621 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++)
5622 sas_expander
->phy
[i
].handle
= handle
;
5626 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5630 * _scsih_search_responding_expanders -
5631 * @ioc: per adapter object
5633 * After host reset, find out whether devices are still responding.
5639 _scsih_search_responding_expanders(struct MPT2SAS_ADAPTER
*ioc
)
5641 Mpi2ExpanderPage0_t expander_pg0
;
5642 Mpi2ConfigReply_t mpi_reply
;
5647 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
, __func__
);
5649 if (list_empty(&ioc
->sas_expander_list
))
5653 while (!(mpt2sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
5654 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL
, handle
))) {
5656 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5657 MPI2_IOCSTATUS_MASK
;
5658 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
5661 handle
= le16_to_cpu(expander_pg0
.DevHandle
);
5662 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
5663 printk(KERN_INFO
"\texpander present: handle(0x%04x), "
5664 "sas_addr(0x%016llx)\n", handle
,
5665 (unsigned long long)sas_address
);
5666 _scsih_mark_responding_expander(ioc
, sas_address
, handle
);
5672 * _scsih_remove_unresponding_sas_devices - removing unresponding devices
5673 * @ioc: per adapter object
5678 _scsih_remove_unresponding_sas_devices(struct MPT2SAS_ADAPTER
*ioc
)
5680 struct _sas_device
*sas_device
, *sas_device_next
;
5681 struct _sas_node
*sas_expander
;
5682 struct _raid_device
*raid_device
, *raid_device_next
;
5685 list_for_each_entry_safe(sas_device
, sas_device_next
,
5686 &ioc
->sas_device_list
, list
) {
5687 if (sas_device
->responding
) {
5688 sas_device
->responding
= 0;
5691 if (sas_device
->starget
)
5692 starget_printk(KERN_INFO
, sas_device
->starget
,
5693 "removing: handle(0x%04x), sas_addr(0x%016llx), "
5694 "enclosure logical id(0x%016llx), slot(%d)\n",
5696 (unsigned long long)sas_device
->sas_address
,
5697 (unsigned long long)
5698 sas_device
->enclosure_logical_id
,
5700 /* invalidate the device handle */
5701 sas_device
->handle
= 0;
5702 _scsih_remove_device(ioc
, sas_device
);
5705 list_for_each_entry_safe(raid_device
, raid_device_next
,
5706 &ioc
->raid_device_list
, list
) {
5707 if (raid_device
->responding
) {
5708 raid_device
->responding
= 0;
5711 if (raid_device
->starget
) {
5712 starget_printk(KERN_INFO
, raid_device
->starget
,
5713 "removing: handle(0x%04x), wwid(0x%016llx)\n",
5714 raid_device
->handle
,
5715 (unsigned long long)raid_device
->wwid
);
5716 scsi_remove_target(&raid_device
->starget
->dev
);
5718 _scsih_raid_device_remove(ioc
, raid_device
);
5721 retry_expander_search
:
5722 sas_expander
= NULL
;
5723 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
5724 if (sas_expander
->responding
) {
5725 sas_expander
->responding
= 0;
5728 _scsih_expander_remove(ioc
, sas_expander
->sas_address
);
5729 goto retry_expander_search
;
5734 * mpt2sas_scsih_reset_handler - reset callback handler (for scsih)
5735 * @ioc: per adapter object
5736 * @reset_phase: phase
5738 * The handler for doing any required cleanup or initialization.
5740 * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
5741 * MPT2_IOC_DONE_RESET
5746 mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER
*ioc
, int reset_phase
)
5748 switch (reset_phase
) {
5749 case MPT2_IOC_PRE_RESET
:
5750 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: "
5751 "MPT2_IOC_PRE_RESET\n", ioc
->name
, __func__
));
5753 case MPT2_IOC_AFTER_RESET
:
5754 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: "
5755 "MPT2_IOC_AFTER_RESET\n", ioc
->name
, __func__
));
5756 if (ioc
->scsih_cmds
.status
& MPT2_CMD_PENDING
) {
5757 ioc
->scsih_cmds
.status
|= MPT2_CMD_RESET
;
5758 mpt2sas_base_free_smid(ioc
, ioc
->scsih_cmds
.smid
);
5759 complete(&ioc
->scsih_cmds
.done
);
5761 if (ioc
->tm_cmds
.status
& MPT2_CMD_PENDING
) {
5762 ioc
->tm_cmds
.status
|= MPT2_CMD_RESET
;
5763 mpt2sas_base_free_smid(ioc
, ioc
->tm_cmds
.smid
);
5764 complete(&ioc
->tm_cmds
.done
);
5766 _scsih_fw_event_cleanup_queue(ioc
);
5767 _scsih_flush_running_cmds(ioc
);
5768 _scsih_queue_rescan(ioc
);
5770 case MPT2_IOC_DONE_RESET
:
5771 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: "
5772 "MPT2_IOC_DONE_RESET\n", ioc
->name
, __func__
));
5773 _scsih_sas_host_refresh(ioc
);
5779 * _firmware_event_work - delayed task for processing firmware events
5780 * @ioc: per adapter object
5781 * @work: equal to the fw_event_work object
5787 _firmware_event_work(struct work_struct
*work
)
5789 struct fw_event_work
*fw_event
= container_of(work
,
5790 struct fw_event_work
, delayed_work
.work
);
5791 unsigned long flags
;
5792 struct MPT2SAS_ADAPTER
*ioc
= fw_event
->ioc
;
5794 /* the queue is being flushed so ignore this event */
5795 if (ioc
->remove_host
|| fw_event
->cancel_pending_work
) {
5796 _scsih_fw_event_free(ioc
, fw_event
);
5800 if (fw_event
->event
== MPT2SAS_RESCAN_AFTER_HOST_RESET
) {
5801 _scsih_fw_event_free(ioc
, fw_event
);
5802 spin_lock_irqsave(&ioc
->ioc_reset_in_progress_lock
, flags
);
5803 if (ioc
->shost_recovery
) {
5804 init_completion(&ioc
->shost_recovery_done
);
5805 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
,
5807 wait_for_completion(&ioc
->shost_recovery_done
);
5809 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
,
5811 _scsih_search_responding_sas_devices(ioc
);
5812 _scsih_search_responding_raid_devices(ioc
);
5813 _scsih_search_responding_expanders(ioc
);
5814 _scsih_remove_unresponding_sas_devices(ioc
);
5818 switch (fw_event
->event
) {
5819 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
5820 _scsih_sas_topology_change_event(ioc
, fw_event
);
5822 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
5823 _scsih_sas_device_status_change_event(ioc
,
5826 case MPI2_EVENT_SAS_DISCOVERY
:
5827 _scsih_sas_discovery_event(ioc
,
5830 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
5831 _scsih_sas_broadcast_primative_event(ioc
,
5834 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
5835 _scsih_sas_enclosure_dev_status_change_event(ioc
,
5838 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
5839 _scsih_sas_ir_config_change_event(ioc
, fw_event
);
5841 case MPI2_EVENT_IR_VOLUME
:
5842 _scsih_sas_ir_volume_event(ioc
, fw_event
);
5844 case MPI2_EVENT_IR_PHYSICAL_DISK
:
5845 _scsih_sas_ir_physical_disk_event(ioc
, fw_event
);
5847 case MPI2_EVENT_IR_OPERATION_STATUS
:
5848 _scsih_sas_ir_operation_status_event(ioc
, fw_event
);
5850 case MPI2_EVENT_TASK_SET_FULL
:
5851 _scsih_task_set_full(ioc
, fw_event
);
5854 _scsih_fw_event_free(ioc
, fw_event
);
5858 * mpt2sas_scsih_event_callback - firmware event handler (called at ISR time)
5859 * @ioc: per adapter object
5860 * @msix_index: MSIX table index supplied by the OS
5861 * @reply: reply message frame(lower 32bit addr)
5862 * Context: interrupt.
5864 * This function merely adds a new work task into ioc->firmware_event_thread.
5865 * The tasks are worked from _firmware_event_work in user context.
5867 * Return 1 meaning mf should be freed from _base_interrupt
5868 * 0 means the mf is freed from this function.
5871 mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER
*ioc
, u8 msix_index
,
5874 struct fw_event_work
*fw_event
;
5875 Mpi2EventNotificationReply_t
*mpi_reply
;
5878 /* events turned off due to host reset or driver unloading */
5879 if (ioc
->remove_host
)
5882 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
5883 event
= le16_to_cpu(mpi_reply
->Event
);
5887 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
5889 Mpi2EventDataSasBroadcastPrimitive_t
*baen_data
=
5890 (Mpi2EventDataSasBroadcastPrimitive_t
*)
5891 mpi_reply
->EventData
;
5893 if (baen_data
->Primitive
!=
5894 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT
||
5895 ioc
->broadcast_aen_busy
)
5897 ioc
->broadcast_aen_busy
= 1;
5901 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
5902 _scsih_check_topo_delete_events(ioc
,
5903 (Mpi2EventDataSasTopologyChangeList_t
*)
5904 mpi_reply
->EventData
);
5907 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
5908 case MPI2_EVENT_IR_OPERATION_STATUS
:
5909 case MPI2_EVENT_SAS_DISCOVERY
:
5910 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
5911 case MPI2_EVENT_IR_VOLUME
:
5912 case MPI2_EVENT_IR_PHYSICAL_DISK
:
5913 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
5914 case MPI2_EVENT_TASK_SET_FULL
:
5917 default: /* ignore the rest */
5921 fw_event
= kzalloc(sizeof(struct fw_event_work
), GFP_ATOMIC
);
5923 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5924 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5927 fw_event
->event_data
=
5928 kzalloc(mpi_reply
->EventDataLength
*4, GFP_ATOMIC
);
5929 if (!fw_event
->event_data
) {
5930 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5931 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5936 memcpy(fw_event
->event_data
, mpi_reply
->EventData
,
5937 mpi_reply
->EventDataLength
*4);
5938 fw_event
->ioc
= ioc
;
5939 fw_event
->VF_ID
= mpi_reply
->VF_ID
;
5940 fw_event
->VP_ID
= mpi_reply
->VP_ID
;
5941 fw_event
->event
= event
;
5942 _scsih_fw_event_add(ioc
, fw_event
);
5946 /* shost template */
5947 static struct scsi_host_template scsih_driver_template
= {
5948 .module
= THIS_MODULE
,
5949 .name
= "Fusion MPT SAS Host",
5950 .proc_name
= MPT2SAS_DRIVER_NAME
,
5951 .queuecommand
= _scsih_qcmd
,
5952 .target_alloc
= _scsih_target_alloc
,
5953 .slave_alloc
= _scsih_slave_alloc
,
5954 .slave_configure
= _scsih_slave_configure
,
5955 .target_destroy
= _scsih_target_destroy
,
5956 .slave_destroy
= _scsih_slave_destroy
,
5957 .change_queue_depth
= _scsih_change_queue_depth
,
5958 .change_queue_type
= _scsih_change_queue_type
,
5959 .eh_abort_handler
= _scsih_abort
,
5960 .eh_device_reset_handler
= _scsih_dev_reset
,
5961 .eh_target_reset_handler
= _scsih_target_reset
,
5962 .eh_host_reset_handler
= _scsih_host_reset
,
5963 .bios_param
= _scsih_bios_param
,
5966 .sg_tablesize
= MPT2SAS_SG_DEPTH
,
5967 .max_sectors
= 8192,
5969 .use_clustering
= ENABLE_CLUSTERING
,
5970 .shost_attrs
= mpt2sas_host_attrs
,
5971 .sdev_attrs
= mpt2sas_dev_attrs
,
5975 * _scsih_expander_node_remove - removing expander device from list.
5976 * @ioc: per adapter object
5977 * @sas_expander: the sas_device object
5978 * Context: Calling function should acquire ioc->sas_node_lock.
5980 * Removing object and freeing associated memory from the
5981 * ioc->sas_expander_list.
5986 _scsih_expander_node_remove(struct MPT2SAS_ADAPTER
*ioc
,
5987 struct _sas_node
*sas_expander
)
5989 struct _sas_port
*mpt2sas_port
;
5990 struct _sas_device
*sas_device
;
5991 struct _sas_node
*expander_sibling
;
5992 unsigned long flags
;
5997 /* remove sibling ports attached to this expander */
5998 retry_device_search
:
5999 list_for_each_entry(mpt2sas_port
,
6000 &sas_expander
->sas_port_list
, port_list
) {
6001 if (mpt2sas_port
->remote_identify
.device_type
==
6003 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6005 mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
6006 mpt2sas_port
->remote_identify
.sas_address
);
6007 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6010 _scsih_remove_device(ioc
, sas_device
);
6011 if (ioc
->shost_recovery
)
6013 goto retry_device_search
;
6017 retry_expander_search
:
6018 list_for_each_entry(mpt2sas_port
,
6019 &sas_expander
->sas_port_list
, port_list
) {
6021 if (mpt2sas_port
->remote_identify
.device_type
==
6022 MPI2_SAS_DEVICE_INFO_EDGE_EXPANDER
||
6023 mpt2sas_port
->remote_identify
.device_type
==
6024 MPI2_SAS_DEVICE_INFO_FANOUT_EXPANDER
) {
6026 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
6028 mpt2sas_scsih_expander_find_by_sas_address(
6029 ioc
, mpt2sas_port
->remote_identify
.sas_address
);
6030 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
6031 if (!expander_sibling
)
6033 _scsih_expander_remove(ioc
,
6034 expander_sibling
->sas_address
);
6035 if (ioc
->shost_recovery
)
6037 goto retry_expander_search
;
6041 mpt2sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
6042 sas_expander
->sas_address_parent
);
6044 printk(MPT2SAS_INFO_FMT
"expander_remove: handle"
6045 "(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
6046 sas_expander
->handle
, (unsigned long long)
6047 sas_expander
->sas_address
);
6049 list_del(&sas_expander
->list
);
6050 kfree(sas_expander
->phy
);
6051 kfree(sas_expander
);
6055 * _scsih_ir_shutdown - IR shutdown notification
6056 * @ioc: per adapter object
6058 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
6059 * the host system is shutting down.
6064 _scsih_ir_shutdown(struct MPT2SAS_ADAPTER
*ioc
)
6066 Mpi2RaidActionRequest_t
*mpi_request
;
6067 Mpi2RaidActionReply_t
*mpi_reply
;
6070 /* is IR firmware build loaded ? */
6071 if (!ioc
->ir_firmware
)
6074 /* are there any volumes ? */
6075 if (list_empty(&ioc
->raid_device_list
))
6078 mutex_lock(&ioc
->scsih_cmds
.mutex
);
6080 if (ioc
->scsih_cmds
.status
!= MPT2_CMD_NOT_USED
) {
6081 printk(MPT2SAS_ERR_FMT
"%s: scsih_cmd in use\n",
6082 ioc
->name
, __func__
);
6085 ioc
->scsih_cmds
.status
= MPT2_CMD_PENDING
;
6087 smid
= mpt2sas_base_get_smid(ioc
, ioc
->scsih_cb_idx
);
6089 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
6090 ioc
->name
, __func__
);
6091 ioc
->scsih_cmds
.status
= MPT2_CMD_NOT_USED
;
6095 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
6096 ioc
->scsih_cmds
.smid
= smid
;
6097 memset(mpi_request
, 0, sizeof(Mpi2RaidActionRequest_t
));
6099 mpi_request
->Function
= MPI2_FUNCTION_RAID_ACTION
;
6100 mpi_request
->Action
= MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED
;
6102 printk(MPT2SAS_INFO_FMT
"IR shutdown (sending)\n", ioc
->name
);
6103 init_completion(&ioc
->scsih_cmds
.done
);
6104 mpt2sas_base_put_smid_default(ioc
, smid
);
6105 wait_for_completion_timeout(&ioc
->scsih_cmds
.done
, 10*HZ
);
6107 if (!(ioc
->scsih_cmds
.status
& MPT2_CMD_COMPLETE
)) {
6108 printk(MPT2SAS_ERR_FMT
"%s: timeout\n",
6109 ioc
->name
, __func__
);
6113 if (ioc
->scsih_cmds
.status
& MPT2_CMD_REPLY_VALID
) {
6114 mpi_reply
= ioc
->scsih_cmds
.reply
;
6116 printk(MPT2SAS_INFO_FMT
"IR shutdown (complete): "
6117 "ioc_status(0x%04x), loginfo(0x%08x)\n",
6118 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
6119 le32_to_cpu(mpi_reply
->IOCLogInfo
));
6123 ioc
->scsih_cmds
.status
= MPT2_CMD_NOT_USED
;
6124 mutex_unlock(&ioc
->scsih_cmds
.mutex
);
6128 * _scsih_shutdown - routine call during system shutdown
6129 * @pdev: PCI device struct
6134 _scsih_shutdown(struct pci_dev
*pdev
)
6136 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6137 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
6138 struct workqueue_struct
*wq
;
6139 unsigned long flags
;
6141 ioc
->remove_host
= 1;
6142 _scsih_fw_event_cleanup_queue(ioc
);
6144 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
6145 wq
= ioc
->firmware_event_thread
;
6146 ioc
->firmware_event_thread
= NULL
;
6147 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
6149 destroy_workqueue(wq
);
6151 _scsih_ir_shutdown(ioc
);
6152 mpt2sas_base_detach(ioc
);
6156 * _scsih_remove - detach and remove add host
6157 * @pdev: PCI device struct
6159 * Routine called when unloading the driver.
6162 static void __devexit
6163 _scsih_remove(struct pci_dev
*pdev
)
6165 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6166 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
6167 struct _sas_port
*mpt2sas_port
;
6168 struct _sas_device
*sas_device
;
6169 struct _sas_node
*expander_sibling
;
6170 struct _raid_device
*raid_device
, *next
;
6171 struct MPT2SAS_TARGET
*sas_target_priv_data
;
6172 struct workqueue_struct
*wq
;
6173 unsigned long flags
;
6175 ioc
->remove_host
= 1;
6176 _scsih_fw_event_cleanup_queue(ioc
);
6178 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
6179 wq
= ioc
->firmware_event_thread
;
6180 ioc
->firmware_event_thread
= NULL
;
6181 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
6183 destroy_workqueue(wq
);
6185 /* release all the volumes */
6186 list_for_each_entry_safe(raid_device
, next
, &ioc
->raid_device_list
,
6188 if (raid_device
->starget
) {
6189 sas_target_priv_data
=
6190 raid_device
->starget
->hostdata
;
6191 sas_target_priv_data
->deleted
= 1;
6192 scsi_remove_target(&raid_device
->starget
->dev
);
6194 printk(MPT2SAS_INFO_FMT
"removing handle(0x%04x), wwid"
6195 "(0x%016llx)\n", ioc
->name
, raid_device
->handle
,
6196 (unsigned long long) raid_device
->wwid
);
6197 _scsih_raid_device_remove(ioc
, raid_device
);
6200 /* free ports attached to the sas_host */
6202 list_for_each_entry(mpt2sas_port
,
6203 &ioc
->sas_hba
.sas_port_list
, port_list
) {
6204 if (mpt2sas_port
->remote_identify
.device_type
==
6207 mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
6208 mpt2sas_port
->remote_identify
.sas_address
);
6210 _scsih_remove_device(ioc
, sas_device
);
6215 mpt2sas_scsih_expander_find_by_sas_address(ioc
,
6216 mpt2sas_port
->remote_identify
.sas_address
);
6217 if (expander_sibling
) {
6218 _scsih_expander_remove(ioc
,
6219 expander_sibling
->sas_address
);
6225 /* free phys attached to the sas_host */
6226 if (ioc
->sas_hba
.num_phys
) {
6227 kfree(ioc
->sas_hba
.phy
);
6228 ioc
->sas_hba
.phy
= NULL
;
6229 ioc
->sas_hba
.num_phys
= 0;
6232 sas_remove_host(shost
);
6233 _scsih_shutdown(pdev
);
6234 list_del(&ioc
->list
);
6235 scsi_remove_host(shost
);
6236 scsi_host_put(shost
);
6240 * _scsih_probe_boot_devices - reports 1st device
6241 * @ioc: per adapter object
6243 * If specified in bios page 2, this routine reports the 1st
6244 * device scsi-ml or sas transport for persistent boot device
6245 * purposes. Please refer to function _scsih_determine_boot_device()
6248 _scsih_probe_boot_devices(struct MPT2SAS_ADAPTER
*ioc
)
6252 struct _sas_device
*sas_device
;
6253 struct _raid_device
*raid_device
;
6255 u64 sas_address_parent
;
6257 unsigned long flags
;
6261 if (ioc
->req_boot_device
.device
) {
6262 device
= ioc
->req_boot_device
.device
;
6263 is_raid
= ioc
->req_boot_device
.is_raid
;
6264 } else if (ioc
->req_alt_boot_device
.device
) {
6265 device
= ioc
->req_alt_boot_device
.device
;
6266 is_raid
= ioc
->req_alt_boot_device
.is_raid
;
6267 } else if (ioc
->current_boot_device
.device
) {
6268 device
= ioc
->current_boot_device
.device
;
6269 is_raid
= ioc
->current_boot_device
.is_raid
;
6276 raid_device
= device
;
6277 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
6278 raid_device
->id
, 0);
6280 _scsih_raid_device_remove(ioc
, raid_device
);
6282 sas_device
= device
;
6283 handle
= sas_device
->handle
;
6284 sas_address_parent
= sas_device
->sas_address_parent
;
6285 sas_address
= sas_device
->sas_address
;
6286 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6287 list_move_tail(&sas_device
->list
, &ioc
->sas_device_list
);
6288 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6289 if (!mpt2sas_transport_port_add(ioc
, sas_device
->handle
,
6290 sas_device
->sas_address_parent
)) {
6291 _scsih_sas_device_remove(ioc
, sas_device
);
6292 } else if (!sas_device
->starget
) {
6293 mpt2sas_transport_port_remove(ioc
, sas_address
,
6294 sas_address_parent
);
6295 _scsih_sas_device_remove(ioc
, sas_device
);
6301 * _scsih_probe_raid - reporting raid volumes to scsi-ml
6302 * @ioc: per adapter object
6304 * Called during initial loading of the driver.
6307 _scsih_probe_raid(struct MPT2SAS_ADAPTER
*ioc
)
6309 struct _raid_device
*raid_device
, *raid_next
;
6312 list_for_each_entry_safe(raid_device
, raid_next
,
6313 &ioc
->raid_device_list
, list
) {
6314 if (raid_device
->starget
)
6316 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
6317 raid_device
->id
, 0);
6319 _scsih_raid_device_remove(ioc
, raid_device
);
6324 * _scsih_probe_sas - reporting sas devices to sas transport
6325 * @ioc: per adapter object
6327 * Called during initial loading of the driver.
6330 _scsih_probe_sas(struct MPT2SAS_ADAPTER
*ioc
)
6332 struct _sas_device
*sas_device
, *next
;
6333 unsigned long flags
;
6335 /* SAS Device List */
6336 list_for_each_entry_safe(sas_device
, next
, &ioc
->sas_device_init_list
,
6338 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6339 list_move_tail(&sas_device
->list
, &ioc
->sas_device_list
);
6340 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6342 if (!mpt2sas_transport_port_add(ioc
, sas_device
->handle
,
6343 sas_device
->sas_address_parent
)) {
6344 _scsih_sas_device_remove(ioc
, sas_device
);
6345 } else if (!sas_device
->starget
) {
6346 mpt2sas_transport_port_remove(ioc
,
6347 sas_device
->sas_address
,
6348 sas_device
->sas_address_parent
);
6349 _scsih_sas_device_remove(ioc
, sas_device
);
6355 * _scsih_probe_devices - probing for devices
6356 * @ioc: per adapter object
6358 * Called during initial loading of the driver.
6361 _scsih_probe_devices(struct MPT2SAS_ADAPTER
*ioc
)
6363 u16 volume_mapping_flags
=
6364 le16_to_cpu(ioc
->ioc_pg8
.IRVolumeMappingFlags
) &
6365 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE
;
6367 if (!(ioc
->facts
.ProtocolFlags
& MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR
))
6368 return; /* return when IOC doesn't support initiator mode */
6370 _scsih_probe_boot_devices(ioc
);
6372 if (ioc
->ir_firmware
) {
6373 if ((volume_mapping_flags
&
6374 MPI2_IOCPAGE8_IRFLAGS_HIGH_VOLUME_MAPPING
)) {
6375 _scsih_probe_sas(ioc
);
6376 _scsih_probe_raid(ioc
);
6378 _scsih_probe_raid(ioc
);
6379 _scsih_probe_sas(ioc
);
6382 _scsih_probe_sas(ioc
);
6386 * _scsih_probe - attach and add scsi host
6387 * @pdev: PCI device struct
6388 * @id: pci device id
6390 * Returns 0 success, anything else error.
6393 _scsih_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
6395 struct MPT2SAS_ADAPTER
*ioc
;
6396 struct Scsi_Host
*shost
;
6398 shost
= scsi_host_alloc(&scsih_driver_template
,
6399 sizeof(struct MPT2SAS_ADAPTER
));
6403 /* init local params */
6404 ioc
= shost_priv(shost
);
6405 memset(ioc
, 0, sizeof(struct MPT2SAS_ADAPTER
));
6406 INIT_LIST_HEAD(&ioc
->list
);
6407 list_add_tail(&ioc
->list
, &mpt2sas_ioc_list
);
6409 ioc
->id
= mpt_ids
++;
6410 sprintf(ioc
->name
, "%s%d", MPT2SAS_DRIVER_NAME
, ioc
->id
);
6412 ioc
->scsi_io_cb_idx
= scsi_io_cb_idx
;
6413 ioc
->tm_cb_idx
= tm_cb_idx
;
6414 ioc
->ctl_cb_idx
= ctl_cb_idx
;
6415 ioc
->base_cb_idx
= base_cb_idx
;
6416 ioc
->transport_cb_idx
= transport_cb_idx
;
6417 ioc
->scsih_cb_idx
= scsih_cb_idx
;
6418 ioc
->config_cb_idx
= config_cb_idx
;
6419 ioc
->tm_tr_cb_idx
= tm_tr_cb_idx
;
6420 ioc
->tm_sas_control_cb_idx
= tm_sas_control_cb_idx
;
6421 ioc
->logging_level
= logging_level
;
6422 /* misc semaphores and spin locks */
6423 spin_lock_init(&ioc
->ioc_reset_in_progress_lock
);
6424 spin_lock_init(&ioc
->scsi_lookup_lock
);
6425 spin_lock_init(&ioc
->sas_device_lock
);
6426 spin_lock_init(&ioc
->sas_node_lock
);
6427 spin_lock_init(&ioc
->fw_event_lock
);
6428 spin_lock_init(&ioc
->raid_device_lock
);
6430 INIT_LIST_HEAD(&ioc
->sas_device_list
);
6431 INIT_LIST_HEAD(&ioc
->sas_device_init_list
);
6432 INIT_LIST_HEAD(&ioc
->sas_expander_list
);
6433 INIT_LIST_HEAD(&ioc
->fw_event_list
);
6434 INIT_LIST_HEAD(&ioc
->raid_device_list
);
6435 INIT_LIST_HEAD(&ioc
->sas_hba
.sas_port_list
);
6436 INIT_LIST_HEAD(&ioc
->delayed_tr_list
);
6438 /* init shost parameters */
6439 shost
->max_cmd_len
= 16;
6440 shost
->max_lun
= max_lun
;
6441 shost
->transportt
= mpt2sas_transport_template
;
6442 shost
->unique_id
= ioc
->id
;
6444 if ((scsi_add_host(shost
, &pdev
->dev
))) {
6445 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6446 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6447 list_del(&ioc
->list
);
6448 goto out_add_shost_fail
;
6451 scsi_host_set_prot(shost
, SHOST_DIF_TYPE1_PROTECTION
6452 | SHOST_DIF_TYPE3_PROTECTION
);
6453 scsi_host_set_guard(shost
, SHOST_DIX_GUARD_CRC
);
6456 snprintf(ioc
->firmware_event_name
, sizeof(ioc
->firmware_event_name
),
6457 "fw_event%d", ioc
->id
);
6458 ioc
->firmware_event_thread
= create_singlethread_workqueue(
6459 ioc
->firmware_event_name
);
6460 if (!ioc
->firmware_event_thread
) {
6461 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6462 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6463 goto out_thread_fail
;
6466 ioc
->wait_for_port_enable_to_complete
= 1;
6467 if ((mpt2sas_base_attach(ioc
))) {
6468 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6469 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6470 goto out_attach_fail
;
6473 ioc
->wait_for_port_enable_to_complete
= 0;
6474 _scsih_probe_devices(ioc
);
6478 destroy_workqueue(ioc
->firmware_event_thread
);
6480 list_del(&ioc
->list
);
6481 scsi_remove_host(shost
);
6488 * _scsih_suspend - power management suspend main entry point
6489 * @pdev: PCI device struct
6490 * @state: PM state change to (usually PCI_D3)
6492 * Returns 0 success, anything else error.
6495 _scsih_suspend(struct pci_dev
*pdev
, pm_message_t state
)
6497 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6498 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
6501 mpt2sas_base_stop_watchdog(ioc
);
6502 flush_scheduled_work();
6503 scsi_block_requests(shost
);
6504 device_state
= pci_choose_state(pdev
, state
);
6505 printk(MPT2SAS_INFO_FMT
"pdev=0x%p, slot=%s, entering "
6506 "operating state [D%d]\n", ioc
->name
, pdev
,
6507 pci_name(pdev
), device_state
);
6509 mpt2sas_base_free_resources(ioc
);
6510 pci_save_state(pdev
);
6511 pci_disable_device(pdev
);
6512 pci_set_power_state(pdev
, device_state
);
6517 * _scsih_resume - power management resume main entry point
6518 * @pdev: PCI device struct
6520 * Returns 0 success, anything else error.
6523 _scsih_resume(struct pci_dev
*pdev
)
6525 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6526 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
6527 u32 device_state
= pdev
->current_state
;
6530 printk(MPT2SAS_INFO_FMT
"pdev=0x%p, slot=%s, previous "
6531 "operating state [D%d]\n", ioc
->name
, pdev
,
6532 pci_name(pdev
), device_state
);
6534 pci_set_power_state(pdev
, PCI_D0
);
6535 pci_enable_wake(pdev
, PCI_D0
, 0);
6536 pci_restore_state(pdev
);
6538 r
= mpt2sas_base_map_resources(ioc
);
6542 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
, SOFT_RESET
);
6543 scsi_unblock_requests(shost
);
6544 mpt2sas_base_start_watchdog(ioc
);
6547 #endif /* CONFIG_PM */
6550 static struct pci_driver scsih_driver
= {
6551 .name
= MPT2SAS_DRIVER_NAME
,
6552 .id_table
= scsih_pci_table
,
6553 .probe
= _scsih_probe
,
6554 .remove
= __devexit_p(_scsih_remove
),
6555 .shutdown
= _scsih_shutdown
,
6557 .suspend
= _scsih_suspend
,
6558 .resume
= _scsih_resume
,
6562 /* raid transport support */
6563 static struct raid_function_template mpt2sas_raid_functions
= {
6564 .cookie
= &scsih_driver_template
,
6565 .is_raid
= _scsih_is_raid
,
6566 .get_resync
= _scsih_get_resync
,
6567 .get_state
= _scsih_get_state
,
6571 * _scsih_init - main entry point for this driver.
6573 * Returns 0 success, anything else error.
6581 printk(KERN_INFO
"%s version %s loaded\n", MPT2SAS_DRIVER_NAME
,
6582 MPT2SAS_DRIVER_VERSION
);
6584 mpt2sas_transport_template
=
6585 sas_attach_transport(&mpt2sas_transport_functions
);
6586 if (!mpt2sas_transport_template
)
6588 /* raid transport support */
6589 mpt2sas_raid_template
= raid_class_attach(&mpt2sas_raid_functions
);
6590 if (!mpt2sas_raid_template
) {
6591 sas_release_transport(mpt2sas_transport_template
);
6595 mpt2sas_base_initialize_callback_handler();
6597 /* queuecommand callback hander */
6598 scsi_io_cb_idx
= mpt2sas_base_register_callback_handler(_scsih_io_done
);
6600 /* task managment callback handler */
6601 tm_cb_idx
= mpt2sas_base_register_callback_handler(_scsih_tm_done
);
6603 /* base internal commands callback handler */
6604 base_cb_idx
= mpt2sas_base_register_callback_handler(mpt2sas_base_done
);
6606 /* transport internal commands callback handler */
6607 transport_cb_idx
= mpt2sas_base_register_callback_handler(
6608 mpt2sas_transport_done
);
6610 /* scsih internal commands callback handler */
6611 scsih_cb_idx
= mpt2sas_base_register_callback_handler(_scsih_done
);
6613 /* configuration page API internal commands callback handler */
6614 config_cb_idx
= mpt2sas_base_register_callback_handler(
6615 mpt2sas_config_done
);
6617 /* ctl module callback handler */
6618 ctl_cb_idx
= mpt2sas_base_register_callback_handler(mpt2sas_ctl_done
);
6620 tm_tr_cb_idx
= mpt2sas_base_register_callback_handler(
6621 _scsih_tm_tr_complete
);
6622 tm_sas_control_cb_idx
= mpt2sas_base_register_callback_handler(
6623 _scsih_sas_control_complete
);
6627 error
= pci_register_driver(&scsih_driver
);
6629 /* raid transport support */
6630 raid_class_release(mpt2sas_raid_template
);
6631 sas_release_transport(mpt2sas_transport_template
);
6638 * _scsih_exit - exit point for this driver (when it is a module).
6640 * Returns 0 success, anything else error.
6645 printk(KERN_INFO
"mpt2sas version %s unloading\n",
6646 MPT2SAS_DRIVER_VERSION
);
6648 pci_unregister_driver(&scsih_driver
);
6652 mpt2sas_base_release_callback_handler(scsi_io_cb_idx
);
6653 mpt2sas_base_release_callback_handler(tm_cb_idx
);
6654 mpt2sas_base_release_callback_handler(base_cb_idx
);
6655 mpt2sas_base_release_callback_handler(transport_cb_idx
);
6656 mpt2sas_base_release_callback_handler(scsih_cb_idx
);
6657 mpt2sas_base_release_callback_handler(config_cb_idx
);
6658 mpt2sas_base_release_callback_handler(ctl_cb_idx
);
6660 mpt2sas_base_release_callback_handler(tm_tr_cb_idx
);
6661 mpt2sas_base_release_callback_handler(tm_sas_control_cb_idx
);
6663 /* raid transport support */
6664 raid_class_release(mpt2sas_raid_template
);
6665 sas_release_transport(mpt2sas_transport_template
);
6669 module_init(_scsih_init
);
6670 module_exit(_scsih_exit
);