2 * Scsi Host Layer for MPT (Message Passing Technology) based controllers
4 * This code is based on drivers/scsi/mpt2sas/mpt2_scsih.c
5 * Copyright (C) 2007-2010 LSI Corporation
6 * (mailto:DL-MPTFusionLinux@lsi.com)
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
19 * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
20 * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
21 * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
22 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
23 * solely responsible for determining the appropriateness of using and
24 * distributing the Program and assumes all risks associated with its
25 * exercise of rights under this Agreement, including but not limited to
26 * the risks and costs of program errors, damage to or loss of data,
27 * programs or equipment, and unavailability or interruption of operations.
29 * DISCLAIMER OF LIABILITY
30 * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
31 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
33 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
34 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
35 * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
36 * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
38 * You should have received a copy of the GNU General Public License
39 * along with this program; if not, write to the Free Software
40 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
44 #include <linux/version.h>
45 #include <linux/module.h>
46 #include <linux/kernel.h>
47 #include <linux/init.h>
48 #include <linux/errno.h>
49 #include <linux/blkdev.h>
50 #include <linux/sched.h>
51 #include <linux/workqueue.h>
52 #include <linux/delay.h>
53 #include <linux/pci.h>
54 #include <linux/interrupt.h>
55 #include <linux/aer.h>
56 #include <linux/raid_class.h>
57 #include <linux/slab.h>
59 #include "mpt2sas_base.h"
61 MODULE_AUTHOR(MPT2SAS_AUTHOR
);
62 MODULE_DESCRIPTION(MPT2SAS_DESCRIPTION
);
63 MODULE_LICENSE("GPL");
64 MODULE_VERSION(MPT2SAS_DRIVER_VERSION
);
66 #define RAID_CHANNEL 1
69 static void _scsih_expander_node_remove(struct MPT2SAS_ADAPTER
*ioc
,
70 struct _sas_node
*sas_expander
);
71 static void _firmware_event_work(struct work_struct
*work
);
73 static u8
_scsih_check_for_pending_tm(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
);
75 /* global parameters */
76 LIST_HEAD(mpt2sas_ioc_list
);
78 /* local parameters */
79 static u8 scsi_io_cb_idx
= -1;
80 static u8 tm_cb_idx
= -1;
81 static u8 ctl_cb_idx
= -1;
82 static u8 base_cb_idx
= -1;
83 static u8 transport_cb_idx
= -1;
84 static u8 scsih_cb_idx
= -1;
85 static u8 config_cb_idx
= -1;
88 static u8 tm_tr_cb_idx
= -1 ;
89 static u8 tm_tr_volume_cb_idx
= -1 ;
90 static u8 tm_sas_control_cb_idx
= -1;
92 /* command line options */
93 static u32 logging_level
;
94 MODULE_PARM_DESC(logging_level
, " bits for enabling additional logging info "
97 /* scsi-mid layer global parmeter is max_report_luns, which is 511 */
98 #define MPT2SAS_MAX_LUN (16895)
99 static int max_lun
= MPT2SAS_MAX_LUN
;
100 module_param(max_lun
, int, 0);
101 MODULE_PARM_DESC(max_lun
, " max lun, default=16895 ");
104 * struct sense_info - common structure for obtaining sense keys
106 * @asc: additional sense code
107 * @ascq: additional sense code qualifier
116 #define MPT2SAS_TURN_ON_FAULT_LED (0xFFFC)
117 #define MPT2SAS_RESCAN_AFTER_HOST_RESET (0xFFFF)
120 * struct fw_event_work - firmware event struct
121 * @list: link list framework
122 * @work: work object (ioc->fault_reset_work_q)
123 * @cancel_pending_work: flag set during reset handling
124 * @ioc: per adapter object
125 * @device_handle: device handle
126 * @VF_ID: virtual function id
127 * @VP_ID: virtual port id
128 * @ignore: flag meaning this event has been marked to ignore
129 * @event: firmware event MPI2_EVENT_XXX defined in mpt2_ioc.h
130 * @event_data: reply event data payload follows
132 * This object stored on ioc->fw_event_list.
134 struct fw_event_work
{
135 struct list_head list
;
136 u8 cancel_pending_work
;
137 struct delayed_work delayed_work
;
138 struct MPT2SAS_ADAPTER
*ioc
;
147 /* raid transport support */
148 static struct raid_template
*mpt2sas_raid_template
;
151 * struct _scsi_io_transfer - scsi io transfer
152 * @handle: sas device handle (assigned by firmware)
153 * @is_raid: flag set for hidden raid components
154 * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE,
155 * @data_length: data transfer length
156 * @data_dma: dma pointer to data
159 * @cdb_length: cdb length
161 * @timeout: timeout for this command
162 * @VF_ID: virtual function id
163 * @VP_ID: virtual port id
164 * @valid_reply: flag set for reply message
165 * @sense_length: sense length
166 * @ioc_status: ioc status
167 * @scsi_state: scsi state
168 * @scsi_status: scsi staus
169 * @log_info: log information
170 * @transfer_length: data length transfer when there is a reply message
172 * Used for sending internal scsi commands to devices within this module.
173 * Refer to _scsi_send_scsi_io().
175 struct _scsi_io_transfer
{
178 enum dma_data_direction dir
;
181 u8 sense
[SCSI_SENSE_BUFFERSIZE
];
189 /* the following bits are only valid when 'valid_reply = 1' */
199 * The pci device ids are defined in mpi/mpi2_cnfg.h.
201 static struct pci_device_id scsih_pci_table
[] = {
202 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2004
,
203 PCI_ANY_ID
, PCI_ANY_ID
},
205 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2008
,
206 PCI_ANY_ID
, PCI_ANY_ID
},
207 /* Liberator ~ 2108 */
208 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_1
,
209 PCI_ANY_ID
, PCI_ANY_ID
},
210 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_2
,
211 PCI_ANY_ID
, PCI_ANY_ID
},
212 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_3
,
213 PCI_ANY_ID
, PCI_ANY_ID
},
215 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2116_1
,
216 PCI_ANY_ID
, PCI_ANY_ID
},
217 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2116_2
,
218 PCI_ANY_ID
, PCI_ANY_ID
},
219 /* Thunderbolt ~ 2208 */
220 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_1
,
221 PCI_ANY_ID
, PCI_ANY_ID
},
222 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_2
,
223 PCI_ANY_ID
, PCI_ANY_ID
},
224 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_3
,
225 PCI_ANY_ID
, PCI_ANY_ID
},
226 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_4
,
227 PCI_ANY_ID
, PCI_ANY_ID
},
228 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_5
,
229 PCI_ANY_ID
, PCI_ANY_ID
},
230 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_6
,
231 PCI_ANY_ID
, PCI_ANY_ID
},
233 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2308_1
,
234 PCI_ANY_ID
, PCI_ANY_ID
},
235 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2308_2
,
236 PCI_ANY_ID
, PCI_ANY_ID
},
237 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2308_3
,
238 PCI_ANY_ID
, PCI_ANY_ID
},
239 {0} /* Terminating entry */
241 MODULE_DEVICE_TABLE(pci
, scsih_pci_table
);
244 * _scsih_set_debug_level - global setting of ioc->logging_level.
246 * Note: The logging levels are defined in mpt2sas_debug.h.
249 _scsih_set_debug_level(const char *val
, struct kernel_param
*kp
)
251 int ret
= param_set_int(val
, kp
);
252 struct MPT2SAS_ADAPTER
*ioc
;
257 printk(KERN_INFO
"setting logging_level(0x%08x)\n", logging_level
);
258 list_for_each_entry(ioc
, &mpt2sas_ioc_list
, list
)
259 ioc
->logging_level
= logging_level
;
262 module_param_call(logging_level
, _scsih_set_debug_level
, param_get_int
,
263 &logging_level
, 0644);
266 * _scsih_srch_boot_sas_address - search based on sas_address
267 * @sas_address: sas address
268 * @boot_device: boot device object from bios page 2
270 * Returns 1 when there's a match, 0 means no match.
273 _scsih_srch_boot_sas_address(u64 sas_address
,
274 Mpi2BootDeviceSasWwid_t
*boot_device
)
276 return (sas_address
== le64_to_cpu(boot_device
->SASAddress
)) ? 1 : 0;
280 * _scsih_srch_boot_device_name - search based on device name
281 * @device_name: device name specified in INDENTIFY fram
282 * @boot_device: boot device object from bios page 2
284 * Returns 1 when there's a match, 0 means no match.
287 _scsih_srch_boot_device_name(u64 device_name
,
288 Mpi2BootDeviceDeviceName_t
*boot_device
)
290 return (device_name
== le64_to_cpu(boot_device
->DeviceName
)) ? 1 : 0;
294 * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot
295 * @enclosure_logical_id: enclosure logical id
296 * @slot_number: slot number
297 * @boot_device: boot device object from bios page 2
299 * Returns 1 when there's a match, 0 means no match.
302 _scsih_srch_boot_encl_slot(u64 enclosure_logical_id
, u16 slot_number
,
303 Mpi2BootDeviceEnclosureSlot_t
*boot_device
)
305 return (enclosure_logical_id
== le64_to_cpu(boot_device
->
306 EnclosureLogicalID
) && slot_number
== le16_to_cpu(boot_device
->
307 SlotNumber
)) ? 1 : 0;
311 * _scsih_is_boot_device - search for matching boot device.
312 * @sas_address: sas address
313 * @device_name: device name specified in INDENTIFY fram
314 * @enclosure_logical_id: enclosure logical id
315 * @slot_number: slot number
316 * @form: specifies boot device form
317 * @boot_device: boot device object from bios page 2
319 * Returns 1 when there's a match, 0 means no match.
322 _scsih_is_boot_device(u64 sas_address
, u64 device_name
,
323 u64 enclosure_logical_id
, u16 slot
, u8 form
,
324 Mpi2BiosPage2BootDevice_t
*boot_device
)
329 case MPI2_BIOSPAGE2_FORM_SAS_WWID
:
332 rc
= _scsih_srch_boot_sas_address(
333 sas_address
, &boot_device
->SasWwid
);
335 case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT
:
336 if (!enclosure_logical_id
)
338 rc
= _scsih_srch_boot_encl_slot(
339 enclosure_logical_id
,
340 slot
, &boot_device
->EnclosureSlot
);
342 case MPI2_BIOSPAGE2_FORM_DEVICE_NAME
:
345 rc
= _scsih_srch_boot_device_name(
346 device_name
, &boot_device
->DeviceName
);
348 case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED
:
356 * _scsih_get_sas_address - set the sas_address for given device handle
357 * @handle: device handle
358 * @sas_address: sas address
360 * Returns 0 success, non-zero when failure
363 _scsih_get_sas_address(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
,
366 Mpi2SasDevicePage0_t sas_device_pg0
;
367 Mpi2ConfigReply_t mpi_reply
;
370 if (handle
<= ioc
->sas_hba
.num_phys
) {
371 *sas_address
= ioc
->sas_hba
.sas_address
;
376 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
377 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
378 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
379 ioc
->name
, __FILE__
, __LINE__
, __func__
);
383 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
385 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
386 printk(MPT2SAS_ERR_FMT
"handle(0x%04x), ioc_status(0x%04x)"
387 "\nfailure at %s:%d/%s()!\n", ioc
->name
, handle
, ioc_status
,
388 __FILE__
, __LINE__
, __func__
);
392 *sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
397 * _scsih_determine_boot_device - determine boot device.
398 * @ioc: per adapter object
399 * @device: either sas_device or raid_device object
400 * @is_raid: [flag] 1 = raid object, 0 = sas object
402 * Determines whether this device should be first reported device to
403 * to scsi-ml or sas transport, this purpose is for persistant boot device.
404 * There are primary, alternate, and current entries in bios page 2. The order
405 * priority is primary, alternate, then current. This routine saves
406 * the corresponding device object and is_raid flag in the ioc object.
407 * The saved data to be used later in _scsih_probe_boot_devices().
410 _scsih_determine_boot_device(struct MPT2SAS_ADAPTER
*ioc
,
411 void *device
, u8 is_raid
)
413 struct _sas_device
*sas_device
;
414 struct _raid_device
*raid_device
;
417 u64 enclosure_logical_id
;
420 /* only process this function when driver loads */
421 if (!ioc
->wait_for_port_enable_to_complete
)
426 sas_address
= sas_device
->sas_address
;
427 device_name
= sas_device
->device_name
;
428 enclosure_logical_id
= sas_device
->enclosure_logical_id
;
429 slot
= sas_device
->slot
;
431 raid_device
= device
;
432 sas_address
= raid_device
->wwid
;
434 enclosure_logical_id
= 0;
438 if (!ioc
->req_boot_device
.device
) {
439 if (_scsih_is_boot_device(sas_address
, device_name
,
440 enclosure_logical_id
, slot
,
441 (ioc
->bios_pg2
.ReqBootDeviceForm
&
442 MPI2_BIOSPAGE2_FORM_MASK
),
443 &ioc
->bios_pg2
.RequestedBootDevice
)) {
444 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
445 "%s: req_boot_device(0x%016llx)\n",
447 (unsigned long long)sas_address
));
448 ioc
->req_boot_device
.device
= device
;
449 ioc
->req_boot_device
.is_raid
= is_raid
;
453 if (!ioc
->req_alt_boot_device
.device
) {
454 if (_scsih_is_boot_device(sas_address
, device_name
,
455 enclosure_logical_id
, slot
,
456 (ioc
->bios_pg2
.ReqAltBootDeviceForm
&
457 MPI2_BIOSPAGE2_FORM_MASK
),
458 &ioc
->bios_pg2
.RequestedAltBootDevice
)) {
459 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
460 "%s: req_alt_boot_device(0x%016llx)\n",
462 (unsigned long long)sas_address
));
463 ioc
->req_alt_boot_device
.device
= device
;
464 ioc
->req_alt_boot_device
.is_raid
= is_raid
;
468 if (!ioc
->current_boot_device
.device
) {
469 if (_scsih_is_boot_device(sas_address
, device_name
,
470 enclosure_logical_id
, slot
,
471 (ioc
->bios_pg2
.CurrentBootDeviceForm
&
472 MPI2_BIOSPAGE2_FORM_MASK
),
473 &ioc
->bios_pg2
.CurrentBootDevice
)) {
474 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
475 "%s: current_boot_device(0x%016llx)\n",
477 (unsigned long long)sas_address
));
478 ioc
->current_boot_device
.device
= device
;
479 ioc
->current_boot_device
.is_raid
= is_raid
;
485 * mpt2sas_scsih_sas_device_find_by_sas_address - sas device search
486 * @ioc: per adapter object
487 * @sas_address: sas address
488 * Context: Calling function should acquire ioc->sas_device_lock
490 * This searches for sas_device based on sas_address, then return sas_device
494 mpt2sas_scsih_sas_device_find_by_sas_address(struct MPT2SAS_ADAPTER
*ioc
,
497 struct _sas_device
*sas_device
;
499 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
)
500 if (sas_device
->sas_address
== sas_address
)
503 list_for_each_entry(sas_device
, &ioc
->sas_device_init_list
, list
)
504 if (sas_device
->sas_address
== sas_address
)
511 * _scsih_sas_device_find_by_handle - sas device search
512 * @ioc: per adapter object
513 * @handle: sas device handle (assigned by firmware)
514 * Context: Calling function should acquire ioc->sas_device_lock
516 * This searches for sas_device based on sas_address, then return sas_device
519 static struct _sas_device
*
520 _scsih_sas_device_find_by_handle(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
522 struct _sas_device
*sas_device
;
524 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
)
525 if (sas_device
->handle
== handle
)
528 list_for_each_entry(sas_device
, &ioc
->sas_device_init_list
, list
)
529 if (sas_device
->handle
== handle
)
536 * _scsih_sas_device_remove - remove sas_device from list.
537 * @ioc: per adapter object
538 * @sas_device: the sas_device object
539 * Context: This function will acquire ioc->sas_device_lock.
541 * Removing object and freeing associated memory from the ioc->sas_device_list.
544 _scsih_sas_device_remove(struct MPT2SAS_ADAPTER
*ioc
,
545 struct _sas_device
*sas_device
)
552 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
553 if (mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
554 sas_device
->sas_address
)) {
555 list_del(&sas_device
->list
);
558 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
562 * _scsih_sas_device_add - insert sas_device to the list.
563 * @ioc: per adapter object
564 * @sas_device: the sas_device object
565 * Context: This function will acquire ioc->sas_device_lock.
567 * Adding new object to the ioc->sas_device_list.
570 _scsih_sas_device_add(struct MPT2SAS_ADAPTER
*ioc
,
571 struct _sas_device
*sas_device
)
575 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: handle"
576 "(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
, __func__
,
577 sas_device
->handle
, (unsigned long long)sas_device
->sas_address
));
579 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
580 list_add_tail(&sas_device
->list
, &ioc
->sas_device_list
);
581 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
583 if (!mpt2sas_transport_port_add(ioc
, sas_device
->handle
,
584 sas_device
->sas_address_parent
))
585 _scsih_sas_device_remove(ioc
, sas_device
);
589 * _scsih_sas_device_init_add - insert sas_device to the list.
590 * @ioc: per adapter object
591 * @sas_device: the sas_device object
592 * Context: This function will acquire ioc->sas_device_lock.
594 * Adding new object at driver load time to the ioc->sas_device_init_list.
597 _scsih_sas_device_init_add(struct MPT2SAS_ADAPTER
*ioc
,
598 struct _sas_device
*sas_device
)
602 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: handle"
603 "(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
, __func__
,
604 sas_device
->handle
, (unsigned long long)sas_device
->sas_address
));
606 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
607 list_add_tail(&sas_device
->list
, &ioc
->sas_device_init_list
);
608 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
609 _scsih_determine_boot_device(ioc
, sas_device
, 0);
613 * _scsih_raid_device_find_by_id - raid device search
614 * @ioc: per adapter object
615 * @id: sas device target id
616 * @channel: sas device channel
617 * Context: Calling function should acquire ioc->raid_device_lock
619 * This searches for raid_device based on target id, then return raid_device
622 static struct _raid_device
*
623 _scsih_raid_device_find_by_id(struct MPT2SAS_ADAPTER
*ioc
, int id
, int channel
)
625 struct _raid_device
*raid_device
, *r
;
628 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
629 if (raid_device
->id
== id
&& raid_device
->channel
== channel
) {
640 * _scsih_raid_device_find_by_handle - raid device search
641 * @ioc: per adapter object
642 * @handle: sas device handle (assigned by firmware)
643 * Context: Calling function should acquire ioc->raid_device_lock
645 * This searches for raid_device based on handle, then return raid_device
648 static struct _raid_device
*
649 _scsih_raid_device_find_by_handle(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
651 struct _raid_device
*raid_device
, *r
;
654 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
655 if (raid_device
->handle
!= handle
)
666 * _scsih_raid_device_find_by_wwid - raid device search
667 * @ioc: per adapter object
668 * @handle: sas device handle (assigned by firmware)
669 * Context: Calling function should acquire ioc->raid_device_lock
671 * This searches for raid_device based on wwid, then return raid_device
674 static struct _raid_device
*
675 _scsih_raid_device_find_by_wwid(struct MPT2SAS_ADAPTER
*ioc
, u64 wwid
)
677 struct _raid_device
*raid_device
, *r
;
680 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
681 if (raid_device
->wwid
!= wwid
)
692 * _scsih_raid_device_add - add raid_device object
693 * @ioc: per adapter object
694 * @raid_device: raid_device object
696 * This is added to the raid_device_list link list.
699 _scsih_raid_device_add(struct MPT2SAS_ADAPTER
*ioc
,
700 struct _raid_device
*raid_device
)
704 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: handle"
705 "(0x%04x), wwid(0x%016llx)\n", ioc
->name
, __func__
,
706 raid_device
->handle
, (unsigned long long)raid_device
->wwid
));
708 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
709 list_add_tail(&raid_device
->list
, &ioc
->raid_device_list
);
710 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
714 * _scsih_raid_device_remove - delete raid_device object
715 * @ioc: per adapter object
716 * @raid_device: raid_device object
718 * This is removed from the raid_device_list link list.
721 _scsih_raid_device_remove(struct MPT2SAS_ADAPTER
*ioc
,
722 struct _raid_device
*raid_device
)
726 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
727 list_del(&raid_device
->list
);
728 memset(raid_device
, 0, sizeof(struct _raid_device
));
730 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
734 * mpt2sas_scsih_expander_find_by_handle - expander device search
735 * @ioc: per adapter object
736 * @handle: expander handle (assigned by firmware)
737 * Context: Calling function should acquire ioc->sas_device_lock
739 * This searches for expander device based on handle, then returns the
743 mpt2sas_scsih_expander_find_by_handle(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
745 struct _sas_node
*sas_expander
, *r
;
748 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
749 if (sas_expander
->handle
!= handle
)
759 * mpt2sas_scsih_expander_find_by_sas_address - expander device search
760 * @ioc: per adapter object
761 * @sas_address: sas address
762 * Context: Calling function should acquire ioc->sas_node_lock.
764 * This searches for expander device based on sas_address, then returns the
768 mpt2sas_scsih_expander_find_by_sas_address(struct MPT2SAS_ADAPTER
*ioc
,
771 struct _sas_node
*sas_expander
, *r
;
774 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
775 if (sas_expander
->sas_address
!= sas_address
)
785 * _scsih_expander_node_add - insert expander device to the list.
786 * @ioc: per adapter object
787 * @sas_expander: the sas_device object
788 * Context: This function will acquire ioc->sas_node_lock.
790 * Adding new object to the ioc->sas_expander_list.
795 _scsih_expander_node_add(struct MPT2SAS_ADAPTER
*ioc
,
796 struct _sas_node
*sas_expander
)
800 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
801 list_add_tail(&sas_expander
->list
, &ioc
->sas_expander_list
);
802 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
806 * _scsih_is_end_device - determines if device is an end device
807 * @device_info: bitfield providing information about the device.
810 * Returns 1 if end device.
813 _scsih_is_end_device(u32 device_info
)
815 if (device_info
& MPI2_SAS_DEVICE_INFO_END_DEVICE
&&
816 ((device_info
& MPI2_SAS_DEVICE_INFO_SSP_TARGET
) |
817 (device_info
& MPI2_SAS_DEVICE_INFO_STP_TARGET
) |
818 (device_info
& MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)))
825 * _scsih_scsi_lookup_get - returns scmd entry
826 * @ioc: per adapter object
827 * @smid: system request message index
829 * Returns the smid stored scmd pointer.
831 static struct scsi_cmnd
*
832 _scsih_scsi_lookup_get(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
834 return ioc
->scsi_lookup
[smid
- 1].scmd
;
838 * _scsih_scsi_lookup_get_clear - returns scmd entry
839 * @ioc: per adapter object
840 * @smid: system request message index
842 * Returns the smid stored scmd pointer.
843 * Then will derefrence the stored scmd pointer.
845 static inline struct scsi_cmnd
*
846 _scsih_scsi_lookup_get_clear(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
849 struct scsi_cmnd
*scmd
;
851 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
852 scmd
= ioc
->scsi_lookup
[smid
- 1].scmd
;
853 ioc
->scsi_lookup
[smid
- 1].scmd
= NULL
;
854 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
860 * _scsih_scsi_lookup_find_by_scmd - scmd lookup
861 * @ioc: per adapter object
862 * @smid: system request message index
863 * @scmd: pointer to scsi command object
864 * Context: This function will acquire ioc->scsi_lookup_lock.
866 * This will search for a scmd pointer in the scsi_lookup array,
867 * returning the revelent smid. A returned value of zero means invalid.
870 _scsih_scsi_lookup_find_by_scmd(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_cmnd
877 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
879 for (i
= 0; i
< ioc
->scsiio_depth
; i
++) {
880 if (ioc
->scsi_lookup
[i
].scmd
== scmd
) {
881 smid
= ioc
->scsi_lookup
[i
].smid
;
886 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
891 * _scsih_scsi_lookup_find_by_target - search for matching channel:id
892 * @ioc: per adapter object
895 * Context: This function will acquire ioc->scsi_lookup_lock.
897 * This will search for a matching channel:id in the scsi_lookup array,
898 * returning 1 if found.
901 _scsih_scsi_lookup_find_by_target(struct MPT2SAS_ADAPTER
*ioc
, int id
,
908 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
910 for (i
= 0 ; i
< ioc
->scsiio_depth
; i
++) {
911 if (ioc
->scsi_lookup
[i
].scmd
&&
912 (ioc
->scsi_lookup
[i
].scmd
->device
->id
== id
&&
913 ioc
->scsi_lookup
[i
].scmd
->device
->channel
== channel
)) {
919 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
924 * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun
925 * @ioc: per adapter object
929 * Context: This function will acquire ioc->scsi_lookup_lock.
931 * This will search for a matching channel:id:lun in the scsi_lookup array,
932 * returning 1 if found.
935 _scsih_scsi_lookup_find_by_lun(struct MPT2SAS_ADAPTER
*ioc
, int id
,
936 unsigned int lun
, int channel
)
942 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
944 for (i
= 0 ; i
< ioc
->scsiio_depth
; i
++) {
945 if (ioc
->scsi_lookup
[i
].scmd
&&
946 (ioc
->scsi_lookup
[i
].scmd
->device
->id
== id
&&
947 ioc
->scsi_lookup
[i
].scmd
->device
->channel
== channel
&&
948 ioc
->scsi_lookup
[i
].scmd
->device
->lun
== lun
)) {
954 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
959 * _scsih_get_chain_buffer_tracker - obtain chain tracker
960 * @ioc: per adapter object
961 * @smid: smid associated to an IO request
963 * Returns chain tracker(from ioc->free_chain_list)
965 static struct chain_tracker
*
966 _scsih_get_chain_buffer_tracker(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
968 struct chain_tracker
*chain_req
;
971 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
972 if (list_empty(&ioc
->free_chain_list
)) {
973 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
974 printk(MPT2SAS_WARN_FMT
"chain buffers not available\n",
978 chain_req
= list_entry(ioc
->free_chain_list
.next
,
979 struct chain_tracker
, tracker_list
);
980 list_del_init(&chain_req
->tracker_list
);
981 list_add_tail(&chain_req
->tracker_list
,
982 &ioc
->scsi_lookup
[smid
- 1].chain_list
);
983 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
988 * _scsih_build_scatter_gather - main sg creation routine
989 * @ioc: per adapter object
990 * @scmd: scsi command
991 * @smid: system request message index
994 * The main routine that builds scatter gather table from a given
995 * scsi request sent via the .queuecommand main handler.
997 * Returns 0 success, anything else error
1000 _scsih_build_scatter_gather(struct MPT2SAS_ADAPTER
*ioc
,
1001 struct scsi_cmnd
*scmd
, u16 smid
)
1003 Mpi2SCSIIORequest_t
*mpi_request
;
1004 dma_addr_t chain_dma
;
1005 struct scatterlist
*sg_scmd
;
1006 void *sg_local
, *chain
;
1011 u32 sges_in_segment
;
1013 u32 sgl_flags_last_element
;
1014 u32 sgl_flags_end_buffer
;
1015 struct chain_tracker
*chain_req
;
1017 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
1019 /* init scatter gather flags */
1020 sgl_flags
= MPI2_SGE_FLAGS_SIMPLE_ELEMENT
;
1021 if (scmd
->sc_data_direction
== DMA_TO_DEVICE
)
1022 sgl_flags
|= MPI2_SGE_FLAGS_HOST_TO_IOC
;
1023 sgl_flags_last_element
= (sgl_flags
| MPI2_SGE_FLAGS_LAST_ELEMENT
)
1024 << MPI2_SGE_FLAGS_SHIFT
;
1025 sgl_flags_end_buffer
= (sgl_flags
| MPI2_SGE_FLAGS_LAST_ELEMENT
|
1026 MPI2_SGE_FLAGS_END_OF_BUFFER
| MPI2_SGE_FLAGS_END_OF_LIST
)
1027 << MPI2_SGE_FLAGS_SHIFT
;
1028 sgl_flags
= sgl_flags
<< MPI2_SGE_FLAGS_SHIFT
;
1030 sg_scmd
= scsi_sglist(scmd
);
1031 sges_left
= scsi_dma_map(scmd
);
1032 if (sges_left
< 0) {
1033 sdev_printk(KERN_ERR
, scmd
->device
, "pci_map_sg"
1034 " failed: request for %d bytes!\n", scsi_bufflen(scmd
));
1038 sg_local
= &mpi_request
->SGL
;
1039 sges_in_segment
= ioc
->max_sges_in_main_message
;
1040 if (sges_left
<= sges_in_segment
)
1041 goto fill_in_last_segment
;
1043 mpi_request
->ChainOffset
= (offsetof(Mpi2SCSIIORequest_t
, SGL
) +
1044 (sges_in_segment
* ioc
->sge_size
))/4;
1046 /* fill in main message segment when there is a chain following */
1047 while (sges_in_segment
) {
1048 if (sges_in_segment
== 1)
1049 ioc
->base_add_sg_single(sg_local
,
1050 sgl_flags_last_element
| sg_dma_len(sg_scmd
),
1051 sg_dma_address(sg_scmd
));
1053 ioc
->base_add_sg_single(sg_local
, sgl_flags
|
1054 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
1055 sg_scmd
= sg_next(sg_scmd
);
1056 sg_local
+= ioc
->sge_size
;
1061 /* initializing the chain flags and pointers */
1062 chain_flags
= MPI2_SGE_FLAGS_CHAIN_ELEMENT
<< MPI2_SGE_FLAGS_SHIFT
;
1063 chain_req
= _scsih_get_chain_buffer_tracker(ioc
, smid
);
1066 chain
= chain_req
->chain_buffer
;
1067 chain_dma
= chain_req
->chain_buffer_dma
;
1069 sges_in_segment
= (sges_left
<=
1070 ioc
->max_sges_in_chain_message
) ? sges_left
:
1071 ioc
->max_sges_in_chain_message
;
1072 chain_offset
= (sges_left
== sges_in_segment
) ?
1073 0 : (sges_in_segment
* ioc
->sge_size
)/4;
1074 chain_length
= sges_in_segment
* ioc
->sge_size
;
1076 chain_offset
= chain_offset
<<
1077 MPI2_SGE_CHAIN_OFFSET_SHIFT
;
1078 chain_length
+= ioc
->sge_size
;
1080 ioc
->base_add_sg_single(sg_local
, chain_flags
| chain_offset
|
1081 chain_length
, chain_dma
);
1084 goto fill_in_last_segment
;
1086 /* fill in chain segments */
1087 while (sges_in_segment
) {
1088 if (sges_in_segment
== 1)
1089 ioc
->base_add_sg_single(sg_local
,
1090 sgl_flags_last_element
|
1091 sg_dma_len(sg_scmd
),
1092 sg_dma_address(sg_scmd
));
1094 ioc
->base_add_sg_single(sg_local
, sgl_flags
|
1095 sg_dma_len(sg_scmd
),
1096 sg_dma_address(sg_scmd
));
1097 sg_scmd
= sg_next(sg_scmd
);
1098 sg_local
+= ioc
->sge_size
;
1103 chain_req
= _scsih_get_chain_buffer_tracker(ioc
, smid
);
1106 chain
= chain_req
->chain_buffer
;
1107 chain_dma
= chain_req
->chain_buffer_dma
;
1111 fill_in_last_segment
:
1113 /* fill the last segment */
1116 ioc
->base_add_sg_single(sg_local
, sgl_flags_end_buffer
|
1117 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
1119 ioc
->base_add_sg_single(sg_local
, sgl_flags
|
1120 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
1121 sg_scmd
= sg_next(sg_scmd
);
1122 sg_local
+= ioc
->sge_size
;
1130 * _scsih_adjust_queue_depth - setting device queue depth
1131 * @sdev: scsi device struct
1132 * @qdepth: requested queue depth
1138 _scsih_adjust_queue_depth(struct scsi_device
*sdev
, int qdepth
)
1140 struct Scsi_Host
*shost
= sdev
->host
;
1142 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1143 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1144 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1145 struct _sas_device
*sas_device
;
1146 unsigned long flags
;
1148 max_depth
= shost
->can_queue
;
1150 /* limit max device queue for SATA to 32 */
1151 sas_device_priv_data
= sdev
->hostdata
;
1152 if (!sas_device_priv_data
)
1154 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
1155 if (!sas_target_priv_data
)
1157 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
))
1159 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1160 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1161 sas_device_priv_data
->sas_target
->sas_address
);
1162 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1163 if (sas_device
&& sas_device
->device_info
&
1164 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1165 max_depth
= MPT2SAS_SATA_QUEUE_DEPTH
;
1169 if (!sdev
->tagged_supported
)
1171 if (qdepth
> max_depth
)
1173 scsi_adjust_queue_depth(sdev
, scsi_get_tag_type(sdev
), qdepth
);
1177 * _scsih_change_queue_depth - setting device queue depth
1178 * @sdev: scsi device struct
1179 * @qdepth: requested queue depth
1180 * @reason: SCSI_QDEPTH_DEFAULT/SCSI_QDEPTH_QFULL/SCSI_QDEPTH_RAMP_UP
1181 * (see include/scsi/scsi_host.h for definition)
1183 * Returns queue depth.
1186 _scsih_change_queue_depth(struct scsi_device
*sdev
, int qdepth
, int reason
)
1188 if (reason
== SCSI_QDEPTH_DEFAULT
|| reason
== SCSI_QDEPTH_RAMP_UP
)
1189 _scsih_adjust_queue_depth(sdev
, qdepth
);
1190 else if (reason
== SCSI_QDEPTH_QFULL
)
1191 scsi_track_queue_full(sdev
, qdepth
);
1195 if (sdev
->inquiry_len
> 7)
1196 sdev_printk(KERN_INFO
, sdev
, "qdepth(%d), tagged(%d), "
1197 "simple(%d), ordered(%d), scsi_level(%d), cmd_que(%d)\n",
1198 sdev
->queue_depth
, sdev
->tagged_supported
, sdev
->simple_tags
,
1199 sdev
->ordered_tags
, sdev
->scsi_level
,
1200 (sdev
->inquiry
[7] & 2) >> 1);
1202 return sdev
->queue_depth
;
1206 * _scsih_change_queue_type - changing device queue tag type
1207 * @sdev: scsi device struct
1208 * @tag_type: requested tag type
1210 * Returns queue tag type.
1213 _scsih_change_queue_type(struct scsi_device
*sdev
, int tag_type
)
1215 if (sdev
->tagged_supported
) {
1216 scsi_set_tag_type(sdev
, tag_type
);
1218 scsi_activate_tcq(sdev
, sdev
->queue_depth
);
1220 scsi_deactivate_tcq(sdev
, sdev
->queue_depth
);
1228 * _scsih_target_alloc - target add routine
1229 * @starget: scsi target struct
1231 * Returns 0 if ok. Any other return is assumed to be an error and
1232 * the device is ignored.
1235 _scsih_target_alloc(struct scsi_target
*starget
)
1237 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
1238 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1239 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1240 struct _sas_device
*sas_device
;
1241 struct _raid_device
*raid_device
;
1242 unsigned long flags
;
1243 struct sas_rphy
*rphy
;
1245 sas_target_priv_data
= kzalloc(sizeof(struct scsi_target
), GFP_KERNEL
);
1246 if (!sas_target_priv_data
)
1249 starget
->hostdata
= sas_target_priv_data
;
1250 sas_target_priv_data
->starget
= starget
;
1251 sas_target_priv_data
->handle
= MPT2SAS_INVALID_DEVICE_HANDLE
;
1254 if (starget
->channel
== RAID_CHANNEL
) {
1255 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1256 raid_device
= _scsih_raid_device_find_by_id(ioc
, starget
->id
,
1259 sas_target_priv_data
->handle
= raid_device
->handle
;
1260 sas_target_priv_data
->sas_address
= raid_device
->wwid
;
1261 sas_target_priv_data
->flags
|= MPT_TARGET_FLAGS_VOLUME
;
1262 raid_device
->starget
= starget
;
1264 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1268 /* sas/sata devices */
1269 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1270 rphy
= dev_to_rphy(starget
->dev
.parent
);
1271 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1272 rphy
->identify
.sas_address
);
1275 sas_target_priv_data
->handle
= sas_device
->handle
;
1276 sas_target_priv_data
->sas_address
= sas_device
->sas_address
;
1277 sas_device
->starget
= starget
;
1278 sas_device
->id
= starget
->id
;
1279 sas_device
->channel
= starget
->channel
;
1280 if (test_bit(sas_device
->handle
, ioc
->pd_handles
))
1281 sas_target_priv_data
->flags
|=
1282 MPT_TARGET_FLAGS_RAID_COMPONENT
;
1284 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1290 * _scsih_target_destroy - target destroy routine
1291 * @starget: scsi target struct
1296 _scsih_target_destroy(struct scsi_target
*starget
)
1298 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
1299 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1300 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1301 struct _sas_device
*sas_device
;
1302 struct _raid_device
*raid_device
;
1303 unsigned long flags
;
1304 struct sas_rphy
*rphy
;
1306 sas_target_priv_data
= starget
->hostdata
;
1307 if (!sas_target_priv_data
)
1310 if (starget
->channel
== RAID_CHANNEL
) {
1311 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1312 raid_device
= _scsih_raid_device_find_by_id(ioc
, starget
->id
,
1315 raid_device
->starget
= NULL
;
1316 raid_device
->sdev
= NULL
;
1318 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1322 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1323 rphy
= dev_to_rphy(starget
->dev
.parent
);
1324 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1325 rphy
->identify
.sas_address
);
1326 if (sas_device
&& (sas_device
->starget
== starget
) &&
1327 (sas_device
->id
== starget
->id
) &&
1328 (sas_device
->channel
== starget
->channel
))
1329 sas_device
->starget
= NULL
;
1331 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1334 kfree(sas_target_priv_data
);
1335 starget
->hostdata
= NULL
;
1339 * _scsih_slave_alloc - device add routine
1340 * @sdev: scsi device struct
1342 * Returns 0 if ok. Any other return is assumed to be an error and
1343 * the device is ignored.
1346 _scsih_slave_alloc(struct scsi_device
*sdev
)
1348 struct Scsi_Host
*shost
;
1349 struct MPT2SAS_ADAPTER
*ioc
;
1350 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1351 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1352 struct scsi_target
*starget
;
1353 struct _raid_device
*raid_device
;
1354 unsigned long flags
;
1356 sas_device_priv_data
= kzalloc(sizeof(struct scsi_device
), GFP_KERNEL
);
1357 if (!sas_device_priv_data
)
1360 sas_device_priv_data
->lun
= sdev
->lun
;
1361 sas_device_priv_data
->flags
= MPT_DEVICE_FLAGS_INIT
;
1363 starget
= scsi_target(sdev
);
1364 sas_target_priv_data
= starget
->hostdata
;
1365 sas_target_priv_data
->num_luns
++;
1366 sas_device_priv_data
->sas_target
= sas_target_priv_data
;
1367 sdev
->hostdata
= sas_device_priv_data
;
1368 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
))
1369 sdev
->no_uld_attach
= 1;
1371 shost
= dev_to_shost(&starget
->dev
);
1372 ioc
= shost_priv(shost
);
1373 if (starget
->channel
== RAID_CHANNEL
) {
1374 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1375 raid_device
= _scsih_raid_device_find_by_id(ioc
,
1376 starget
->id
, starget
->channel
);
1378 raid_device
->sdev
= sdev
; /* raid is single lun */
1379 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1386 * _scsih_slave_destroy - device destroy routine
1387 * @sdev: scsi device struct
1392 _scsih_slave_destroy(struct scsi_device
*sdev
)
1394 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1395 struct scsi_target
*starget
;
1397 if (!sdev
->hostdata
)
1400 starget
= scsi_target(sdev
);
1401 sas_target_priv_data
= starget
->hostdata
;
1402 sas_target_priv_data
->num_luns
--;
1403 kfree(sdev
->hostdata
);
1404 sdev
->hostdata
= NULL
;
1408 * _scsih_display_sata_capabilities - sata capabilities
1409 * @ioc: per adapter object
1410 * @sas_device: the sas_device object
1411 * @sdev: scsi device struct
1414 _scsih_display_sata_capabilities(struct MPT2SAS_ADAPTER
*ioc
,
1415 struct _sas_device
*sas_device
, struct scsi_device
*sdev
)
1417 Mpi2ConfigReply_t mpi_reply
;
1418 Mpi2SasDevicePage0_t sas_device_pg0
;
1423 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
1424 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, sas_device
->handle
))) {
1425 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1426 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1430 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
1431 MPI2_IOCSTATUS_MASK
;
1432 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
1433 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1434 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1438 flags
= le16_to_cpu(sas_device_pg0
.Flags
);
1439 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
1441 sdev_printk(KERN_INFO
, sdev
,
1442 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1443 "sw_preserve(%s)\n",
1444 (device_info
& MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE
) ? "y" : "n",
1445 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED
) ? "y" : "n",
1446 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY
) ? "y" :
1448 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED
) ? "y" : "n",
1449 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED
) ? "y" : "n",
1450 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE
) ? "y" : "n");
1454 * _scsih_is_raid - return boolean indicating device is raid volume
1455 * @dev the device struct object
1458 _scsih_is_raid(struct device
*dev
)
1460 struct scsi_device
*sdev
= to_scsi_device(dev
);
1462 return (sdev
->channel
== RAID_CHANNEL
) ? 1 : 0;
1466 * _scsih_get_resync - get raid volume resync percent complete
1467 * @dev the device struct object
1470 _scsih_get_resync(struct device
*dev
)
1472 struct scsi_device
*sdev
= to_scsi_device(dev
);
1473 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
1474 static struct _raid_device
*raid_device
;
1475 unsigned long flags
;
1476 Mpi2RaidVolPage0_t vol_pg0
;
1477 Mpi2ConfigReply_t mpi_reply
;
1478 u32 volume_status_flags
;
1479 u8 percent_complete
= 0;
1481 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1482 raid_device
= _scsih_raid_device_find_by_id(ioc
, sdev
->id
,
1484 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1489 if (mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, &vol_pg0
,
1490 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, raid_device
->handle
,
1491 sizeof(Mpi2RaidVolPage0_t
))) {
1492 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1493 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1497 volume_status_flags
= le32_to_cpu(vol_pg0
.VolumeStatusFlags
);
1498 if (volume_status_flags
& MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS
)
1499 percent_complete
= raid_device
->percent_complete
;
1501 raid_set_resync(mpt2sas_raid_template
, dev
, percent_complete
);
1505 * _scsih_get_state - get raid volume level
1506 * @dev the device struct object
1509 _scsih_get_state(struct device
*dev
)
1511 struct scsi_device
*sdev
= to_scsi_device(dev
);
1512 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
1513 static struct _raid_device
*raid_device
;
1514 unsigned long flags
;
1515 Mpi2RaidVolPage0_t vol_pg0
;
1516 Mpi2ConfigReply_t mpi_reply
;
1518 enum raid_state state
= RAID_STATE_UNKNOWN
;
1520 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1521 raid_device
= _scsih_raid_device_find_by_id(ioc
, sdev
->id
,
1523 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1528 if (mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, &vol_pg0
,
1529 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, raid_device
->handle
,
1530 sizeof(Mpi2RaidVolPage0_t
))) {
1531 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1532 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1536 volstate
= le32_to_cpu(vol_pg0
.VolumeStatusFlags
);
1537 if (volstate
& MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS
) {
1538 state
= RAID_STATE_RESYNCING
;
1542 switch (vol_pg0
.VolumeState
) {
1543 case MPI2_RAID_VOL_STATE_OPTIMAL
:
1544 case MPI2_RAID_VOL_STATE_ONLINE
:
1545 state
= RAID_STATE_ACTIVE
;
1547 case MPI2_RAID_VOL_STATE_DEGRADED
:
1548 state
= RAID_STATE_DEGRADED
;
1550 case MPI2_RAID_VOL_STATE_FAILED
:
1551 case MPI2_RAID_VOL_STATE_MISSING
:
1552 state
= RAID_STATE_OFFLINE
;
1556 raid_set_state(mpt2sas_raid_template
, dev
, state
);
1560 * _scsih_set_level - set raid level
1561 * @sdev: scsi device struct
1562 * @raid_device: raid_device object
1565 _scsih_set_level(struct scsi_device
*sdev
, struct _raid_device
*raid_device
)
1567 enum raid_level level
= RAID_LEVEL_UNKNOWN
;
1569 switch (raid_device
->volume_type
) {
1570 case MPI2_RAID_VOL_TYPE_RAID0
:
1571 level
= RAID_LEVEL_0
;
1573 case MPI2_RAID_VOL_TYPE_RAID10
:
1574 level
= RAID_LEVEL_10
;
1576 case MPI2_RAID_VOL_TYPE_RAID1E
:
1577 level
= RAID_LEVEL_1E
;
1579 case MPI2_RAID_VOL_TYPE_RAID1
:
1580 level
= RAID_LEVEL_1
;
1584 raid_set_level(mpt2sas_raid_template
, &sdev
->sdev_gendev
, level
);
1588 * _scsih_get_volume_capabilities - volume capabilities
1589 * @ioc: per adapter object
1590 * @sas_device: the raid_device object
1593 _scsih_get_volume_capabilities(struct MPT2SAS_ADAPTER
*ioc
,
1594 struct _raid_device
*raid_device
)
1596 Mpi2RaidVolPage0_t
*vol_pg0
;
1597 Mpi2RaidPhysDiskPage0_t pd_pg0
;
1598 Mpi2SasDevicePage0_t sas_device_pg0
;
1599 Mpi2ConfigReply_t mpi_reply
;
1603 if ((mpt2sas_config_get_number_pds(ioc
, raid_device
->handle
,
1604 &num_pds
)) || !num_pds
) {
1605 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1606 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1610 raid_device
->num_pds
= num_pds
;
1611 sz
= offsetof(Mpi2RaidVolPage0_t
, PhysDisk
) + (num_pds
*
1612 sizeof(Mpi2RaidVol0PhysDisk_t
));
1613 vol_pg0
= kzalloc(sz
, GFP_KERNEL
);
1615 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1616 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1620 if ((mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, vol_pg0
,
1621 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, raid_device
->handle
, sz
))) {
1622 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1623 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1628 raid_device
->volume_type
= vol_pg0
->VolumeType
;
1630 /* figure out what the underlying devices are by
1631 * obtaining the device_info bits for the 1st device
1633 if (!(mpt2sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
1634 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM
,
1635 vol_pg0
->PhysDisk
[0].PhysDiskNum
))) {
1636 if (!(mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
1637 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
1638 le16_to_cpu(pd_pg0
.DevHandle
)))) {
1639 raid_device
->device_info
=
1640 le32_to_cpu(sas_device_pg0
.DeviceInfo
);
1648 * _scsih_enable_tlr - setting TLR flags
1649 * @ioc: per adapter object
1650 * @sdev: scsi device struct
1652 * Enabling Transaction Layer Retries for tape devices when
1653 * vpd page 0x90 is present
1657 _scsih_enable_tlr(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_device
*sdev
)
1660 if (sdev
->type
!= TYPE_TAPE
)
1663 if (!(ioc
->facts
.IOCCapabilities
& MPI2_IOCFACTS_CAPABILITY_TLR
))
1666 sas_enable_tlr(sdev
);
1667 sdev_printk(KERN_INFO
, sdev
, "TLR %s\n",
1668 sas_is_tlr_enabled(sdev
) ? "Enabled" : "Disabled");
1674 * _scsih_slave_configure - device configure routine.
1675 * @sdev: scsi device struct
1677 * Returns 0 if ok. Any other return is assumed to be an error and
1678 * the device is ignored.
1681 _scsih_slave_configure(struct scsi_device
*sdev
)
1683 struct Scsi_Host
*shost
= sdev
->host
;
1684 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1685 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1686 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1687 struct _sas_device
*sas_device
;
1688 struct _raid_device
*raid_device
;
1689 unsigned long flags
;
1696 sas_device_priv_data
= sdev
->hostdata
;
1697 sas_device_priv_data
->configured_lun
= 1;
1698 sas_device_priv_data
->flags
&= ~MPT_DEVICE_FLAGS_INIT
;
1699 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
1701 /* raid volume handling */
1702 if (sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
1704 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1705 raid_device
= _scsih_raid_device_find_by_handle(ioc
,
1706 sas_target_priv_data
->handle
);
1707 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1709 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1710 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1714 _scsih_get_volume_capabilities(ioc
, raid_device
);
1716 /* RAID Queue Depth Support
1717 * IS volume = underlying qdepth of drive type, either
1718 * MPT2SAS_SAS_QUEUE_DEPTH or MPT2SAS_SATA_QUEUE_DEPTH
1719 * IM/IME/R10 = 128 (MPT2SAS_RAID_QUEUE_DEPTH)
1721 if (raid_device
->device_info
&
1722 MPI2_SAS_DEVICE_INFO_SSP_TARGET
) {
1723 qdepth
= MPT2SAS_SAS_QUEUE_DEPTH
;
1726 qdepth
= MPT2SAS_SATA_QUEUE_DEPTH
;
1727 if (raid_device
->device_info
&
1728 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1734 switch (raid_device
->volume_type
) {
1735 case MPI2_RAID_VOL_TYPE_RAID0
:
1738 case MPI2_RAID_VOL_TYPE_RAID1E
:
1739 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
1740 if (ioc
->manu_pg10
.OEMIdentifier
&&
1741 (ioc
->manu_pg10
.GenericFlags0
&
1742 MFG10_GF0_R10_DISPLAY
) &&
1743 !(raid_device
->num_pds
% 2))
1748 case MPI2_RAID_VOL_TYPE_RAID1
:
1749 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
1752 case MPI2_RAID_VOL_TYPE_RAID10
:
1753 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
1756 case MPI2_RAID_VOL_TYPE_UNKNOWN
:
1758 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
1763 sdev_printk(KERN_INFO
, sdev
, "%s: "
1764 "handle(0x%04x), wwid(0x%016llx), pd_count(%d), type(%s)\n",
1765 r_level
, raid_device
->handle
,
1766 (unsigned long long)raid_device
->wwid
,
1767 raid_device
->num_pds
, ds
);
1768 _scsih_change_queue_depth(sdev
, qdepth
, SCSI_QDEPTH_DEFAULT
);
1769 /* raid transport support */
1770 _scsih_set_level(sdev
, raid_device
);
1774 /* non-raid handling */
1775 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1776 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1777 sas_device_priv_data
->sas_target
->sas_address
);
1778 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1780 if (sas_target_priv_data
->flags
&
1781 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
1782 mpt2sas_config_get_volume_handle(ioc
,
1783 sas_device
->handle
, &sas_device
->volume_handle
);
1784 mpt2sas_config_get_volume_wwid(ioc
,
1785 sas_device
->volume_handle
,
1786 &sas_device
->volume_wwid
);
1788 if (sas_device
->device_info
& MPI2_SAS_DEVICE_INFO_SSP_TARGET
) {
1789 qdepth
= MPT2SAS_SAS_QUEUE_DEPTH
;
1793 qdepth
= MPT2SAS_SATA_QUEUE_DEPTH
;
1794 if (sas_device
->device_info
&
1795 MPI2_SAS_DEVICE_INFO_STP_TARGET
)
1797 else if (sas_device
->device_info
&
1798 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1802 sdev_printk(KERN_INFO
, sdev
, "%s: handle(0x%04x), "
1803 "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n",
1804 ds
, sas_device
->handle
,
1805 (unsigned long long)sas_device
->sas_address
,
1807 (unsigned long long)sas_device
->device_name
);
1808 sdev_printk(KERN_INFO
, sdev
, "%s: "
1809 "enclosure_logical_id(0x%016llx), slot(%d)\n", ds
,
1810 (unsigned long long) sas_device
->enclosure_logical_id
,
1814 _scsih_display_sata_capabilities(ioc
, sas_device
, sdev
);
1817 _scsih_change_queue_depth(sdev
, qdepth
, SCSI_QDEPTH_DEFAULT
);
1820 sas_read_port_mode_page(sdev
);
1821 _scsih_enable_tlr(ioc
, sdev
);
1827 * _scsih_bios_param - fetch head, sector, cylinder info for a disk
1828 * @sdev: scsi device struct
1829 * @bdev: pointer to block device context
1830 * @capacity: device size (in 512 byte sectors)
1831 * @params: three element array to place output:
1832 * params[0] number of heads (max 255)
1833 * params[1] number of sectors (max 63)
1834 * params[2] number of cylinders
1839 _scsih_bios_param(struct scsi_device
*sdev
, struct block_device
*bdev
,
1840 sector_t capacity
, int params
[])
1850 dummy
= heads
* sectors
;
1851 cylinders
= capacity
;
1852 sector_div(cylinders
, dummy
);
1855 * Handle extended translation size for logical drives
1858 if ((ulong
)capacity
>= 0x200000) {
1861 dummy
= heads
* sectors
;
1862 cylinders
= capacity
;
1863 sector_div(cylinders
, dummy
);
1868 params
[1] = sectors
;
1869 params
[2] = cylinders
;
1875 * _scsih_response_code - translation of device response code
1876 * @ioc: per adapter object
1877 * @response_code: response code returned by the device
1882 _scsih_response_code(struct MPT2SAS_ADAPTER
*ioc
, u8 response_code
)
1886 switch (response_code
) {
1887 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE
:
1888 desc
= "task management request completed";
1890 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
:
1891 desc
= "invalid frame";
1893 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED
:
1894 desc
= "task management request not supported";
1896 case MPI2_SCSITASKMGMT_RSP_TM_FAILED
:
1897 desc
= "task management request failed";
1899 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
:
1900 desc
= "task management request succeeded";
1902 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN
:
1903 desc
= "invalid lun";
1906 desc
= "overlapped tag attempted";
1908 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
:
1909 desc
= "task queued, however not sent to target";
1915 printk(MPT2SAS_WARN_FMT
"response_code(0x%01x): %s\n",
1916 ioc
->name
, response_code
, desc
);
1920 * _scsih_tm_done - tm completion routine
1921 * @ioc: per adapter object
1922 * @smid: system request message index
1923 * @msix_index: MSIX table index supplied by the OS
1924 * @reply: reply message frame(lower 32bit addr)
1927 * The callback handler when using scsih_issue_tm.
1929 * Return 1 meaning mf should be freed from _base_interrupt
1930 * 0 means the mf is freed from this function.
1933 _scsih_tm_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
1935 MPI2DefaultReply_t
*mpi_reply
;
1937 if (ioc
->tm_cmds
.status
== MPT2_CMD_NOT_USED
)
1939 if (ioc
->tm_cmds
.smid
!= smid
)
1941 ioc
->tm_cmds
.status
|= MPT2_CMD_COMPLETE
;
1942 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
1944 memcpy(ioc
->tm_cmds
.reply
, mpi_reply
, mpi_reply
->MsgLength
*4);
1945 ioc
->tm_cmds
.status
|= MPT2_CMD_REPLY_VALID
;
1947 ioc
->tm_cmds
.status
&= ~MPT2_CMD_PENDING
;
1948 complete(&ioc
->tm_cmds
.done
);
1953 * mpt2sas_scsih_set_tm_flag - set per target tm_busy
1954 * @ioc: per adapter object
1955 * @handle: device handle
1957 * During taskmangement request, we need to freeze the device queue.
1960 mpt2sas_scsih_set_tm_flag(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
1962 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1963 struct scsi_device
*sdev
;
1966 shost_for_each_device(sdev
, ioc
->shost
) {
1969 sas_device_priv_data
= sdev
->hostdata
;
1970 if (!sas_device_priv_data
)
1972 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
1973 sas_device_priv_data
->sas_target
->tm_busy
= 1;
1975 ioc
->ignore_loginfos
= 1;
1981 * mpt2sas_scsih_clear_tm_flag - clear per target tm_busy
1982 * @ioc: per adapter object
1983 * @handle: device handle
1985 * During taskmangement request, we need to freeze the device queue.
1988 mpt2sas_scsih_clear_tm_flag(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
1990 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1991 struct scsi_device
*sdev
;
1994 shost_for_each_device(sdev
, ioc
->shost
) {
1997 sas_device_priv_data
= sdev
->hostdata
;
1998 if (!sas_device_priv_data
)
2000 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2001 sas_device_priv_data
->sas_target
->tm_busy
= 0;
2003 ioc
->ignore_loginfos
= 0;
2010 * mpt2sas_scsih_issue_tm - main routine for sending tm requests
2011 * @ioc: per adapter struct
2012 * @device_handle: device handle
2013 * @channel: the channel assigned by the OS
2014 * @id: the id assigned by the OS
2016 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
2017 * @smid_task: smid assigned to the task
2018 * @timeout: timeout in seconds
2021 * A generic API for sending task management requests to firmware.
2023 * The callback index is set inside `ioc->tm_cb_idx`.
2025 * Return SUCCESS or FAILED.
2028 mpt2sas_scsih_issue_tm(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
, uint channel
,
2029 uint id
, uint lun
, u8 type
, u16 smid_task
, ulong timeout
,
2030 struct scsi_cmnd
*scmd
)
2032 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
2033 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
2036 unsigned long timeleft
;
2037 struct scsi_cmnd
*scmd_lookup
;
2040 mutex_lock(&ioc
->tm_cmds
.mutex
);
2041 if (ioc
->tm_cmds
.status
!= MPT2_CMD_NOT_USED
) {
2042 printk(MPT2SAS_INFO_FMT
"%s: tm_cmd busy!!!\n",
2043 __func__
, ioc
->name
);
2048 if (ioc
->shost_recovery
|| ioc
->remove_host
||
2049 ioc
->pci_error_recovery
) {
2050 printk(MPT2SAS_INFO_FMT
"%s: host reset in progress!\n",
2051 __func__
, ioc
->name
);
2056 ioc_state
= mpt2sas_base_get_iocstate(ioc
, 0);
2057 if (ioc_state
& MPI2_DOORBELL_USED
) {
2058 dhsprintk(ioc
, printk(MPT2SAS_INFO_FMT
"unexpected doorbell "
2059 "active!\n", ioc
->name
));
2060 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2066 if ((ioc_state
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_FAULT
) {
2067 mpt2sas_base_fault_info(ioc
, ioc_state
&
2068 MPI2_DOORBELL_DATA_MASK
);
2069 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2075 smid
= mpt2sas_base_get_smid_hpr(ioc
, ioc
->tm_cb_idx
);
2077 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
2078 ioc
->name
, __func__
);
2083 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"sending tm: handle(0x%04x),"
2084 " task_type(0x%02x), smid(%d)\n", ioc
->name
, handle
, type
,
2086 ioc
->tm_cmds
.status
= MPT2_CMD_PENDING
;
2087 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
2088 ioc
->tm_cmds
.smid
= smid
;
2089 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
2090 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
2091 mpi_request
->DevHandle
= cpu_to_le16(handle
);
2092 mpi_request
->TaskType
= type
;
2093 mpi_request
->TaskMID
= cpu_to_le16(smid_task
);
2094 int_to_scsilun(lun
, (struct scsi_lun
*)mpi_request
->LUN
);
2095 mpt2sas_scsih_set_tm_flag(ioc
, handle
);
2096 init_completion(&ioc
->tm_cmds
.done
);
2097 mpt2sas_base_put_smid_hi_priority(ioc
, smid
);
2098 timeleft
= wait_for_completion_timeout(&ioc
->tm_cmds
.done
, timeout
*HZ
);
2099 if (!(ioc
->tm_cmds
.status
& MPT2_CMD_COMPLETE
)) {
2100 printk(MPT2SAS_ERR_FMT
"%s: timeout\n",
2101 ioc
->name
, __func__
);
2102 _debug_dump_mf(mpi_request
,
2103 sizeof(Mpi2SCSITaskManagementRequest_t
)/4);
2104 if (!(ioc
->tm_cmds
.status
& MPT2_CMD_RESET
)) {
2105 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2108 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
2109 mpt2sas_scsih_clear_tm_flag(ioc
, handle
);
2114 if (ioc
->tm_cmds
.status
& MPT2_CMD_REPLY_VALID
) {
2115 mpi_reply
= ioc
->tm_cmds
.reply
;
2116 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"complete tm: "
2117 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
2118 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
2119 le32_to_cpu(mpi_reply
->IOCLogInfo
),
2120 le32_to_cpu(mpi_reply
->TerminationCount
)));
2121 if (ioc
->logging_level
& MPT_DEBUG_TM
) {
2122 _scsih_response_code(ioc
, mpi_reply
->ResponseCode
);
2123 if (mpi_reply
->IOCStatus
)
2124 _debug_dump_mf(mpi_request
,
2125 sizeof(Mpi2SCSITaskManagementRequest_t
)/4);
2130 * Check to see the commands were terminated.
2131 * This is only needed for eh callbacks, hence the scmd check.
2135 goto bypass_sanity_checks
;
2137 case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
:
2138 scmd_lookup
= _scsih_scsi_lookup_get(ioc
, smid_task
);
2139 if (scmd_lookup
&& (scmd_lookup
->serial_number
==
2140 scmd
->serial_number
))
2146 case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
:
2147 if (_scsih_scsi_lookup_find_by_target(ioc
, id
, channel
))
2153 case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET
:
2154 if (_scsih_scsi_lookup_find_by_lun(ioc
, id
, lun
, channel
))
2161 bypass_sanity_checks
:
2163 mpt2sas_scsih_clear_tm_flag(ioc
, handle
);
2164 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
2165 mutex_unlock(&ioc
->tm_cmds
.mutex
);
2170 mutex_unlock(&ioc
->tm_cmds
.mutex
);
2175 * _scsih_tm_display_info - displays info about the device
2176 * @ioc: per adapter struct
2177 * @scmd: pointer to scsi command object
2179 * Called by task management callback handlers.
2182 _scsih_tm_display_info(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
)
2184 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
2185 struct MPT2SAS_TARGET
*priv_target
= starget
->hostdata
;
2186 struct _sas_device
*sas_device
= NULL
;
2187 unsigned long flags
;
2192 scsi_print_command(scmd
);
2193 if (priv_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
2194 starget_printk(KERN_INFO
, starget
, "volume handle(0x%04x), "
2195 "volume wwid(0x%016llx)\n",
2196 priv_target
->handle
,
2197 (unsigned long long)priv_target
->sas_address
);
2199 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2200 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
2201 priv_target
->sas_address
);
2203 if (priv_target
->flags
&
2204 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2205 starget_printk(KERN_INFO
, starget
,
2206 "volume handle(0x%04x), "
2207 "volume wwid(0x%016llx)\n",
2208 sas_device
->volume_handle
,
2209 (unsigned long long)sas_device
->volume_wwid
);
2211 starget_printk(KERN_INFO
, starget
,
2212 "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n",
2214 (unsigned long long)sas_device
->sas_address
,
2216 starget_printk(KERN_INFO
, starget
,
2217 "enclosure_logical_id(0x%016llx), slot(%d)\n",
2218 (unsigned long long)sas_device
->enclosure_logical_id
,
2221 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2226 * _scsih_abort - eh threads main abort routine
2227 * @scmd: pointer to scsi command object
2229 * Returns SUCCESS if command aborted else FAILED
2232 _scsih_abort(struct scsi_cmnd
*scmd
)
2234 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2235 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2240 sdev_printk(KERN_INFO
, scmd
->device
, "attempting task abort! "
2241 "scmd(%p)\n", scmd
);
2242 _scsih_tm_display_info(ioc
, scmd
);
2244 sas_device_priv_data
= scmd
->device
->hostdata
;
2245 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2246 sdev_printk(KERN_INFO
, scmd
->device
, "device been deleted! "
2247 "scmd(%p)\n", scmd
);
2248 scmd
->result
= DID_NO_CONNECT
<< 16;
2249 scmd
->scsi_done(scmd
);
2254 /* search for the command */
2255 smid
= _scsih_scsi_lookup_find_by_scmd(ioc
, scmd
);
2257 scmd
->result
= DID_RESET
<< 16;
2262 /* for hidden raid components and volumes this is not supported */
2263 if (sas_device_priv_data
->sas_target
->flags
&
2264 MPT_TARGET_FLAGS_RAID_COMPONENT
||
2265 sas_device_priv_data
->sas_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
2266 scmd
->result
= DID_RESET
<< 16;
2271 mpt2sas_halt_firmware(ioc
);
2273 handle
= sas_device_priv_data
->sas_target
->handle
;
2274 r
= mpt2sas_scsih_issue_tm(ioc
, handle
, scmd
->device
->channel
,
2275 scmd
->device
->id
, scmd
->device
->lun
,
2276 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
, smid
, 30, scmd
);
2279 sdev_printk(KERN_INFO
, scmd
->device
, "task abort: %s scmd(%p)\n",
2280 ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2285 * _scsih_dev_reset - eh threads main device reset routine
2286 * @scmd: pointer to scsi command object
2288 * Returns SUCCESS if command aborted else FAILED
2291 _scsih_dev_reset(struct scsi_cmnd
*scmd
)
2293 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2294 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2295 struct _sas_device
*sas_device
;
2296 unsigned long flags
;
2300 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
2302 starget_printk(KERN_INFO
, starget
, "attempting device reset! "
2303 "scmd(%p)\n", scmd
);
2304 _scsih_tm_display_info(ioc
, scmd
);
2306 sas_device_priv_data
= scmd
->device
->hostdata
;
2307 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2308 starget_printk(KERN_INFO
, starget
, "device been deleted! "
2309 "scmd(%p)\n", scmd
);
2310 scmd
->result
= DID_NO_CONNECT
<< 16;
2311 scmd
->scsi_done(scmd
);
2316 /* for hidden raid components obtain the volume_handle */
2318 if (sas_device_priv_data
->sas_target
->flags
&
2319 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2320 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2321 sas_device
= _scsih_sas_device_find_by_handle(ioc
,
2322 sas_device_priv_data
->sas_target
->handle
);
2324 handle
= sas_device
->volume_handle
;
2325 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2327 handle
= sas_device_priv_data
->sas_target
->handle
;
2330 scmd
->result
= DID_RESET
<< 16;
2335 r
= mpt2sas_scsih_issue_tm(ioc
, handle
, scmd
->device
->channel
,
2336 scmd
->device
->id
, scmd
->device
->lun
,
2337 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET
, 0, 30, scmd
);
2340 sdev_printk(KERN_INFO
, scmd
->device
, "device reset: %s scmd(%p)\n",
2341 ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2346 * _scsih_target_reset - eh threads main target reset routine
2347 * @scmd: pointer to scsi command object
2349 * Returns SUCCESS if command aborted else FAILED
2352 _scsih_target_reset(struct scsi_cmnd
*scmd
)
2354 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2355 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2356 struct _sas_device
*sas_device
;
2357 unsigned long flags
;
2360 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
2362 starget_printk(KERN_INFO
, starget
, "attempting target reset! "
2363 "scmd(%p)\n", scmd
);
2364 _scsih_tm_display_info(ioc
, scmd
);
2366 sas_device_priv_data
= scmd
->device
->hostdata
;
2367 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2368 starget_printk(KERN_INFO
, starget
, "target been deleted! "
2369 "scmd(%p)\n", scmd
);
2370 scmd
->result
= DID_NO_CONNECT
<< 16;
2371 scmd
->scsi_done(scmd
);
2376 /* for hidden raid components obtain the volume_handle */
2378 if (sas_device_priv_data
->sas_target
->flags
&
2379 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2380 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2381 sas_device
= _scsih_sas_device_find_by_handle(ioc
,
2382 sas_device_priv_data
->sas_target
->handle
);
2384 handle
= sas_device
->volume_handle
;
2385 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2387 handle
= sas_device_priv_data
->sas_target
->handle
;
2390 scmd
->result
= DID_RESET
<< 16;
2395 r
= mpt2sas_scsih_issue_tm(ioc
, handle
, scmd
->device
->channel
,
2396 scmd
->device
->id
, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
, 0,
2400 starget_printk(KERN_INFO
, starget
, "target reset: %s scmd(%p)\n",
2401 ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2406 * _scsih_host_reset - eh threads main host reset routine
2407 * @scmd: pointer to scsi command object
2409 * Returns SUCCESS if command aborted else FAILED
2412 _scsih_host_reset(struct scsi_cmnd
*scmd
)
2414 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2417 printk(MPT2SAS_INFO_FMT
"attempting host reset! scmd(%p)\n",
2419 scsi_print_command(scmd
);
2421 retval
= mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2423 r
= (retval
< 0) ? FAILED
: SUCCESS
;
2424 printk(MPT2SAS_INFO_FMT
"host reset: %s scmd(%p)\n",
2425 ioc
->name
, ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2431 * _scsih_fw_event_add - insert and queue up fw_event
2432 * @ioc: per adapter object
2433 * @fw_event: object describing the event
2434 * Context: This function will acquire ioc->fw_event_lock.
2436 * This adds the firmware event object into link list, then queues it up to
2437 * be processed from user context.
2442 _scsih_fw_event_add(struct MPT2SAS_ADAPTER
*ioc
, struct fw_event_work
*fw_event
)
2444 unsigned long flags
;
2446 if (ioc
->firmware_event_thread
== NULL
)
2449 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2450 list_add_tail(&fw_event
->list
, &ioc
->fw_event_list
);
2451 INIT_DELAYED_WORK(&fw_event
->delayed_work
, _firmware_event_work
);
2452 queue_delayed_work(ioc
->firmware_event_thread
,
2453 &fw_event
->delayed_work
, 0);
2454 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2458 * _scsih_fw_event_free - delete fw_event
2459 * @ioc: per adapter object
2460 * @fw_event: object describing the event
2461 * Context: This function will acquire ioc->fw_event_lock.
2463 * This removes firmware event object from link list, frees associated memory.
2468 _scsih_fw_event_free(struct MPT2SAS_ADAPTER
*ioc
, struct fw_event_work
2471 unsigned long flags
;
2473 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2474 list_del(&fw_event
->list
);
2475 kfree(fw_event
->event_data
);
2477 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2482 * _scsih_queue_rescan - queue a topology rescan from user context
2483 * @ioc: per adapter object
2488 _scsih_queue_rescan(struct MPT2SAS_ADAPTER
*ioc
)
2490 struct fw_event_work
*fw_event
;
2492 if (ioc
->wait_for_port_enable_to_complete
)
2494 fw_event
= kzalloc(sizeof(struct fw_event_work
), GFP_ATOMIC
);
2497 fw_event
->event
= MPT2SAS_RESCAN_AFTER_HOST_RESET
;
2498 fw_event
->ioc
= ioc
;
2499 _scsih_fw_event_add(ioc
, fw_event
);
2503 * _scsih_fw_event_cleanup_queue - cleanup event queue
2504 * @ioc: per adapter object
2506 * Walk the firmware event queue, either killing timers, or waiting
2507 * for outstanding events to complete
2512 _scsih_fw_event_cleanup_queue(struct MPT2SAS_ADAPTER
*ioc
)
2514 struct fw_event_work
*fw_event
, *next
;
2516 if (list_empty(&ioc
->fw_event_list
) ||
2517 !ioc
->firmware_event_thread
|| in_interrupt())
2520 list_for_each_entry_safe(fw_event
, next
, &ioc
->fw_event_list
, list
) {
2521 if (cancel_delayed_work(&fw_event
->delayed_work
)) {
2522 _scsih_fw_event_free(ioc
, fw_event
);
2525 fw_event
->cancel_pending_work
= 1;
2530 * _scsih_ublock_io_device - set the device state to SDEV_RUNNING
2531 * @ioc: per adapter object
2532 * @handle: device handle
2534 * During device pull we need to appropiately set the sdev state.
2537 _scsih_ublock_io_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
2539 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2540 struct scsi_device
*sdev
;
2542 shost_for_each_device(sdev
, ioc
->shost
) {
2543 sas_device_priv_data
= sdev
->hostdata
;
2544 if (!sas_device_priv_data
)
2546 if (!sas_device_priv_data
->block
)
2548 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2549 dewtprintk(ioc
, sdev_printk(KERN_INFO
, sdev
,
2550 MPT2SAS_INFO_FMT
"SDEV_RUNNING: "
2551 "handle(0x%04x)\n", ioc
->name
, handle
));
2552 sas_device_priv_data
->block
= 0;
2553 scsi_internal_device_unblock(sdev
);
2559 * _scsih_block_io_device - set the device state to SDEV_BLOCK
2560 * @ioc: per adapter object
2561 * @handle: device handle
2563 * During device pull we need to appropiately set the sdev state.
2566 _scsih_block_io_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
2568 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2569 struct scsi_device
*sdev
;
2571 shost_for_each_device(sdev
, ioc
->shost
) {
2572 sas_device_priv_data
= sdev
->hostdata
;
2573 if (!sas_device_priv_data
)
2575 if (sas_device_priv_data
->block
)
2577 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2578 dewtprintk(ioc
, sdev_printk(KERN_INFO
, sdev
,
2579 MPT2SAS_INFO_FMT
"SDEV_BLOCK: "
2580 "handle(0x%04x)\n", ioc
->name
, handle
));
2581 sas_device_priv_data
->block
= 1;
2582 scsi_internal_device_block(sdev
);
2588 * _scsih_block_io_to_children_attached_to_ex
2589 * @ioc: per adapter object
2590 * @sas_expander: the sas_device object
2592 * This routine set sdev state to SDEV_BLOCK for all devices
2593 * attached to this expander. This function called when expander is
2597 _scsih_block_io_to_children_attached_to_ex(struct MPT2SAS_ADAPTER
*ioc
,
2598 struct _sas_node
*sas_expander
)
2600 struct _sas_port
*mpt2sas_port
;
2601 struct _sas_device
*sas_device
;
2602 struct _sas_node
*expander_sibling
;
2603 unsigned long flags
;
2608 list_for_each_entry(mpt2sas_port
,
2609 &sas_expander
->sas_port_list
, port_list
) {
2610 if (mpt2sas_port
->remote_identify
.device_type
==
2612 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2614 mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
2615 mpt2sas_port
->remote_identify
.sas_address
);
2616 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2619 _scsih_block_io_device(ioc
, sas_device
->handle
);
2623 list_for_each_entry(mpt2sas_port
,
2624 &sas_expander
->sas_port_list
, port_list
) {
2626 if (mpt2sas_port
->remote_identify
.device_type
==
2627 SAS_EDGE_EXPANDER_DEVICE
||
2628 mpt2sas_port
->remote_identify
.device_type
==
2629 SAS_FANOUT_EXPANDER_DEVICE
) {
2631 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
2633 mpt2sas_scsih_expander_find_by_sas_address(
2634 ioc
, mpt2sas_port
->remote_identify
.sas_address
);
2635 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
2636 _scsih_block_io_to_children_attached_to_ex(ioc
,
2643 * _scsih_block_io_to_children_attached_directly
2644 * @ioc: per adapter object
2645 * @event_data: topology change event data
2647 * This routine set sdev state to SDEV_BLOCK for all devices
2648 * direct attached during device pull.
2651 _scsih_block_io_to_children_attached_directly(struct MPT2SAS_ADAPTER
*ioc
,
2652 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
2659 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
2660 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
2663 phy_number
= event_data
->StartPhyNum
+ i
;
2664 reason_code
= event_data
->PHY
[i
].PhyStatus
&
2665 MPI2_EVENT_SAS_TOPO_RC_MASK
;
2666 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
)
2667 _scsih_block_io_device(ioc
, handle
);
2672 * _scsih_tm_tr_send - send task management request
2673 * @ioc: per adapter object
2674 * @handle: device handle
2675 * Context: interrupt time.
2677 * This code is to initiate the device removal handshake protocal
2678 * with controller firmware. This function will issue target reset
2679 * using high priority request queue. It will send a sas iounit
2680 * controll request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
2682 * This is designed to send muliple task management request at the same
2683 * time to the fifo. If the fifo is full, we will append the request,
2684 * and process it in a future completion.
2687 _scsih_tm_tr_send(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
2689 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
2691 struct _sas_device
*sas_device
;
2692 struct MPT2SAS_TARGET
*sas_target_priv_data
;
2693 unsigned long flags
;
2694 struct _tr_list
*delayed_tr
;
2696 if (ioc
->shost_recovery
|| ioc
->remove_host
||
2697 ioc
->pci_error_recovery
) {
2698 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host reset in "
2699 "progress!\n", __func__
, ioc
->name
));
2703 /* if PD, then return */
2704 if (test_bit(handle
, ioc
->pd_handles
))
2707 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2708 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
2709 if (sas_device
&& sas_device
->starget
&&
2710 sas_device
->starget
->hostdata
) {
2711 sas_target_priv_data
= sas_device
->starget
->hostdata
;
2712 sas_target_priv_data
->deleted
= 1;
2713 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
2714 "setting delete flag: handle(0x%04x), "
2715 "sas_addr(0x%016llx)\n", ioc
->name
, handle
,
2716 (unsigned long long) sas_device
->sas_address
));
2718 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2720 smid
= mpt2sas_base_get_smid_hpr(ioc
, ioc
->tm_tr_cb_idx
);
2722 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
2725 INIT_LIST_HEAD(&delayed_tr
->list
);
2726 delayed_tr
->handle
= handle
;
2727 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_list
);
2728 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
2729 "DELAYED:tr:handle(0x%04x), (open)\n",
2730 ioc
->name
, handle
));
2734 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"tr_send:handle(0x%04x), "
2735 "(open), smid(%d), cb(%d)\n", ioc
->name
, handle
, smid
,
2736 ioc
->tm_tr_cb_idx
));
2737 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
2738 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
2739 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
2740 mpi_request
->DevHandle
= cpu_to_le16(handle
);
2741 mpi_request
->TaskType
= MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
;
2742 mpt2sas_base_put_smid_hi_priority(ioc
, smid
);
2748 * _scsih_sas_control_complete - completion routine
2749 * @ioc: per adapter object
2750 * @smid: system request message index
2751 * @msix_index: MSIX table index supplied by the OS
2752 * @reply: reply message frame(lower 32bit addr)
2753 * Context: interrupt time.
2755 * This is the sas iounit controll completion routine.
2756 * This code is part of the code to initiate the device removal
2757 * handshake protocal with controller firmware.
2759 * Return 1 meaning mf should be freed from _base_interrupt
2760 * 0 means the mf is freed from this function.
2763 _scsih_sas_control_complete(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
,
2764 u8 msix_index
, u32 reply
)
2766 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
2767 Mpi2SasIoUnitControlReply_t
*mpi_reply
=
2768 mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
2770 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
2771 "sc_complete:handle(0x%04x), (open) "
2772 "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
2773 ioc
->name
, le16_to_cpu(mpi_reply
->DevHandle
), smid
,
2774 le16_to_cpu(mpi_reply
->IOCStatus
),
2775 le32_to_cpu(mpi_reply
->IOCLogInfo
)));
2780 * _scsih_tm_tr_volume_send - send target reset request for volumes
2781 * @ioc: per adapter object
2782 * @handle: device handle
2783 * Context: interrupt time.
2785 * This is designed to send muliple task management request at the same
2786 * time to the fifo. If the fifo is full, we will append the request,
2787 * and process it in a future completion.
2790 _scsih_tm_tr_volume_send(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
2792 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
2794 struct _tr_list
*delayed_tr
;
2796 if (ioc
->shost_recovery
|| ioc
->remove_host
||
2797 ioc
->pci_error_recovery
) {
2798 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host reset in "
2799 "progress!\n", __func__
, ioc
->name
));
2803 smid
= mpt2sas_base_get_smid_hpr(ioc
, ioc
->tm_tr_volume_cb_idx
);
2805 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
2808 INIT_LIST_HEAD(&delayed_tr
->list
);
2809 delayed_tr
->handle
= handle
;
2810 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_volume_list
);
2811 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
2812 "DELAYED:tr:handle(0x%04x), (open)\n",
2813 ioc
->name
, handle
));
2817 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"tr_send:handle(0x%04x), "
2818 "(open), smid(%d), cb(%d)\n", ioc
->name
, handle
, smid
,
2819 ioc
->tm_tr_volume_cb_idx
));
2820 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
2821 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
2822 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
2823 mpi_request
->DevHandle
= cpu_to_le16(handle
);
2824 mpi_request
->TaskType
= MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
;
2825 mpt2sas_base_put_smid_hi_priority(ioc
, smid
);
2829 * _scsih_tm_volume_tr_complete - target reset completion
2830 * @ioc: per adapter object
2831 * @smid: system request message index
2832 * @msix_index: MSIX table index supplied by the OS
2833 * @reply: reply message frame(lower 32bit addr)
2834 * Context: interrupt time.
2836 * Return 1 meaning mf should be freed from _base_interrupt
2837 * 0 means the mf is freed from this function.
2840 _scsih_tm_volume_tr_complete(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
,
2841 u8 msix_index
, u32 reply
)
2844 Mpi2SCSITaskManagementRequest_t
*mpi_request_tm
;
2845 Mpi2SCSITaskManagementReply_t
*mpi_reply
=
2846 mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
2848 if (ioc
->shost_recovery
|| ioc
->remove_host
||
2849 ioc
->pci_error_recovery
) {
2850 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host reset in "
2851 "progress!\n", __func__
, ioc
->name
));
2855 mpi_request_tm
= mpt2sas_base_get_msg_frame(ioc
, smid
);
2856 handle
= le16_to_cpu(mpi_request_tm
->DevHandle
);
2857 if (handle
!= le16_to_cpu(mpi_reply
->DevHandle
)) {
2858 dewtprintk(ioc
, printk("spurious interrupt: "
2859 "handle(0x%04x:0x%04x), smid(%d)!!!\n", handle
,
2860 le16_to_cpu(mpi_reply
->DevHandle
), smid
));
2864 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
2865 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
2866 "loginfo(0x%08x), completed(%d)\n", ioc
->name
,
2867 handle
, smid
, le16_to_cpu(mpi_reply
->IOCStatus
),
2868 le32_to_cpu(mpi_reply
->IOCLogInfo
),
2869 le32_to_cpu(mpi_reply
->TerminationCount
)));
2871 return _scsih_check_for_pending_tm(ioc
, smid
);
2875 * _scsih_tm_tr_complete -
2876 * @ioc: per adapter object
2877 * @smid: system request message index
2878 * @msix_index: MSIX table index supplied by the OS
2879 * @reply: reply message frame(lower 32bit addr)
2880 * Context: interrupt time.
2882 * This is the target reset completion routine.
2883 * This code is part of the code to initiate the device removal
2884 * handshake protocal with controller firmware.
2885 * It will send a sas iounit controll request (MPI2_SAS_OP_REMOVE_DEVICE)
2887 * Return 1 meaning mf should be freed from _base_interrupt
2888 * 0 means the mf is freed from this function.
2891 _scsih_tm_tr_complete(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
,
2895 Mpi2SCSITaskManagementRequest_t
*mpi_request_tm
;
2896 Mpi2SCSITaskManagementReply_t
*mpi_reply
=
2897 mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
2898 Mpi2SasIoUnitControlRequest_t
*mpi_request
;
2901 if (ioc
->shost_recovery
|| ioc
->remove_host
||
2902 ioc
->pci_error_recovery
) {
2903 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host reset in "
2904 "progress!\n", __func__
, ioc
->name
));
2908 mpi_request_tm
= mpt2sas_base_get_msg_frame(ioc
, smid
);
2909 handle
= le16_to_cpu(mpi_request_tm
->DevHandle
);
2910 if (handle
!= le16_to_cpu(mpi_reply
->DevHandle
)) {
2911 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"spurious interrupt: "
2912 "handle(0x%04x:0x%04x), smid(%d)!!!\n", ioc
->name
, handle
,
2913 le16_to_cpu(mpi_reply
->DevHandle
), smid
));
2917 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
2918 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
2919 "loginfo(0x%08x), completed(%d)\n", ioc
->name
,
2920 handle
, smid
, le16_to_cpu(mpi_reply
->IOCStatus
),
2921 le32_to_cpu(mpi_reply
->IOCLogInfo
),
2922 le32_to_cpu(mpi_reply
->TerminationCount
)));
2924 smid_sas_ctrl
= mpt2sas_base_get_smid(ioc
, ioc
->tm_sas_control_cb_idx
);
2925 if (!smid_sas_ctrl
) {
2926 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
2927 ioc
->name
, __func__
);
2931 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"sc_send:handle(0x%04x), "
2932 "(open), smid(%d), cb(%d)\n", ioc
->name
, handle
, smid_sas_ctrl
,
2933 ioc
->tm_sas_control_cb_idx
));
2934 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid_sas_ctrl
);
2935 memset(mpi_request
, 0, sizeof(Mpi2SasIoUnitControlRequest_t
));
2936 mpi_request
->Function
= MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
;
2937 mpi_request
->Operation
= MPI2_SAS_OP_REMOVE_DEVICE
;
2938 mpi_request
->DevHandle
= mpi_request_tm
->DevHandle
;
2939 mpt2sas_base_put_smid_default(ioc
, smid_sas_ctrl
);
2941 return _scsih_check_for_pending_tm(ioc
, smid
);
2945 * _scsih_check_for_pending_tm - check for pending task management
2946 * @ioc: per adapter object
2947 * @smid: system request message index
2949 * This will check delayed target reset list, and feed the
2952 * Return 1 meaning mf should be freed from _base_interrupt
2953 * 0 means the mf is freed from this function.
2956 _scsih_check_for_pending_tm(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
2958 struct _tr_list
*delayed_tr
;
2960 if (!list_empty(&ioc
->delayed_tr_volume_list
)) {
2961 delayed_tr
= list_entry(ioc
->delayed_tr_volume_list
.next
,
2962 struct _tr_list
, list
);
2963 mpt2sas_base_free_smid(ioc
, smid
);
2964 _scsih_tm_tr_volume_send(ioc
, delayed_tr
->handle
);
2965 list_del(&delayed_tr
->list
);
2970 if (!list_empty(&ioc
->delayed_tr_list
)) {
2971 delayed_tr
= list_entry(ioc
->delayed_tr_list
.next
,
2972 struct _tr_list
, list
);
2973 mpt2sas_base_free_smid(ioc
, smid
);
2974 _scsih_tm_tr_send(ioc
, delayed_tr
->handle
);
2975 list_del(&delayed_tr
->list
);
2984 * _scsih_check_topo_delete_events - sanity check on topo events
2985 * @ioc: per adapter object
2986 * @event_data: the event data payload
2988 * This routine added to better handle cable breaker.
2990 * This handles the case where driver recieves multiple expander
2991 * add and delete events in a single shot. When there is a delete event
2992 * the routine will void any pending add events waiting in the event queue.
2997 _scsih_check_topo_delete_events(struct MPT2SAS_ADAPTER
*ioc
,
2998 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
3000 struct fw_event_work
*fw_event
;
3001 Mpi2EventDataSasTopologyChangeList_t
*local_event_data
;
3002 u16 expander_handle
;
3003 struct _sas_node
*sas_expander
;
3004 unsigned long flags
;
3008 for (i
= 0 ; i
< event_data
->NumEntries
; i
++) {
3009 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
3012 reason_code
= event_data
->PHY
[i
].PhyStatus
&
3013 MPI2_EVENT_SAS_TOPO_RC_MASK
;
3014 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
)
3015 _scsih_tm_tr_send(ioc
, handle
);
3018 expander_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
3019 if (expander_handle
< ioc
->sas_hba
.num_phys
) {
3020 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
3024 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
3025 || event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
) {
3026 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
3027 sas_expander
= mpt2sas_scsih_expander_find_by_handle(ioc
,
3029 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
3030 _scsih_block_io_to_children_attached_to_ex(ioc
, sas_expander
);
3031 } else if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_RESPONDING
)
3032 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
3034 if (event_data
->ExpStatus
!= MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
)
3037 /* mark ignore flag for pending events */
3038 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
3039 list_for_each_entry(fw_event
, &ioc
->fw_event_list
, list
) {
3040 if (fw_event
->event
!= MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
||
3043 local_event_data
= fw_event
->event_data
;
3044 if (local_event_data
->ExpStatus
==
3045 MPI2_EVENT_SAS_TOPO_ES_ADDED
||
3046 local_event_data
->ExpStatus
==
3047 MPI2_EVENT_SAS_TOPO_ES_RESPONDING
) {
3048 if (le16_to_cpu(local_event_data
->ExpanderDevHandle
) ==
3050 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3051 "setting ignoring flag\n", ioc
->name
));
3052 fw_event
->ignore
= 1;
3056 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
3060 * _scsih_set_volume_delete_flag - setting volume delete flag
3061 * @ioc: per adapter object
3062 * @handle: device handle
3068 _scsih_set_volume_delete_flag(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
3070 struct _raid_device
*raid_device
;
3071 struct MPT2SAS_TARGET
*sas_target_priv_data
;
3072 unsigned long flags
;
3074 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
3075 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
3076 if (raid_device
&& raid_device
->starget
&&
3077 raid_device
->starget
->hostdata
) {
3078 sas_target_priv_data
=
3079 raid_device
->starget
->hostdata
;
3080 sas_target_priv_data
->deleted
= 1;
3081 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3082 "setting delete flag: handle(0x%04x), "
3083 "wwid(0x%016llx)\n", ioc
->name
, handle
,
3084 (unsigned long long) raid_device
->wwid
));
3086 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
3090 * _scsih_set_volume_handle_for_tr - set handle for target reset to volume
3091 * @handle: input handle
3092 * @a: handle for volume a
3093 * @b: handle for volume b
3095 * IR firmware only supports two raid volumes. The purpose of this
3096 * routine is to set the volume handle in either a or b. When the given
3097 * input handle is non-zero, or when a and b have not been set before.
3100 _scsih_set_volume_handle_for_tr(u16 handle
, u16
*a
, u16
*b
)
3102 if (!handle
|| handle
== *a
|| handle
== *b
)
3111 * _scsih_check_ir_config_unhide_events - check for UNHIDE events
3112 * @ioc: per adapter object
3113 * @event_data: the event data payload
3114 * Context: interrupt time.
3116 * This routine will send target reset to volume, followed by target
3117 * resets to the PDs. This is called when a PD has been removed, or
3118 * volume has been deleted or removed. When the target reset is sent
3119 * to volume, the PD target resets need to be queued to start upon
3120 * completion of the volume target reset.
3125 _scsih_check_ir_config_unhide_events(struct MPT2SAS_ADAPTER
*ioc
,
3126 Mpi2EventDataIrConfigChangeList_t
*event_data
)
3128 Mpi2EventIrConfigElement_t
*element
;
3130 u16 handle
, volume_handle
, a
, b
;
3131 struct _tr_list
*delayed_tr
;
3136 /* Volume Resets for Deleted or Removed */
3137 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
3138 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
3139 if (element
->ReasonCode
==
3140 MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
||
3141 element
->ReasonCode
==
3142 MPI2_EVENT_IR_CHANGE_RC_REMOVED
) {
3143 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
3144 _scsih_set_volume_delete_flag(ioc
, volume_handle
);
3145 _scsih_set_volume_handle_for_tr(volume_handle
, &a
, &b
);
3149 /* Volume Resets for UNHIDE events */
3150 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
3151 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
3152 if (le32_to_cpu(event_data
->Flags
) &
3153 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
)
3155 if (element
->ReasonCode
== MPI2_EVENT_IR_CHANGE_RC_UNHIDE
) {
3156 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
3157 _scsih_set_volume_handle_for_tr(volume_handle
, &a
, &b
);
3162 _scsih_tm_tr_volume_send(ioc
, a
);
3164 _scsih_tm_tr_volume_send(ioc
, b
);
3166 /* PD target resets */
3167 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
3168 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
3169 if (element
->ReasonCode
!= MPI2_EVENT_IR_CHANGE_RC_UNHIDE
)
3171 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
3172 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
3173 clear_bit(handle
, ioc
->pd_handles
);
3175 _scsih_tm_tr_send(ioc
, handle
);
3176 else if (volume_handle
== a
|| volume_handle
== b
) {
3177 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
3178 BUG_ON(!delayed_tr
);
3179 INIT_LIST_HEAD(&delayed_tr
->list
);
3180 delayed_tr
->handle
= handle
;
3181 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_list
);
3182 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3183 "DELAYED:tr:handle(0x%04x), (open)\n", ioc
->name
,
3186 _scsih_tm_tr_send(ioc
, handle
);
3192 * _scsih_check_volume_delete_events - set delete flag for volumes
3193 * @ioc: per adapter object
3194 * @event_data: the event data payload
3195 * Context: interrupt time.
3197 * This will handle the case when the cable connected to entire volume is
3198 * pulled. We will take care of setting the deleted flag so normal IO will
3204 _scsih_check_volume_delete_events(struct MPT2SAS_ADAPTER
*ioc
,
3205 Mpi2EventDataIrVolume_t
*event_data
)
3209 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED
)
3211 state
= le32_to_cpu(event_data
->NewValue
);
3212 if (state
== MPI2_RAID_VOL_STATE_MISSING
|| state
==
3213 MPI2_RAID_VOL_STATE_FAILED
)
3214 _scsih_set_volume_delete_flag(ioc
,
3215 le16_to_cpu(event_data
->VolDevHandle
));
3219 * _scsih_flush_running_cmds - completing outstanding commands.
3220 * @ioc: per adapter object
3222 * The flushing out of all pending scmd commands following host reset,
3223 * where all IO is dropped to the floor.
3228 _scsih_flush_running_cmds(struct MPT2SAS_ADAPTER
*ioc
)
3230 struct scsi_cmnd
*scmd
;
3234 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
3235 scmd
= _scsih_scsi_lookup_get_clear(ioc
, smid
);
3239 mpt2sas_base_free_smid(ioc
, smid
);
3240 scsi_dma_unmap(scmd
);
3241 if (ioc
->pci_error_recovery
)
3242 scmd
->result
= DID_NO_CONNECT
<< 16;
3244 scmd
->result
= DID_RESET
<< 16;
3245 scmd
->scsi_done(scmd
);
3247 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"completing %d cmds\n",
3252 * _scsih_setup_eedp - setup MPI request for EEDP transfer
3253 * @scmd: pointer to scsi command object
3254 * @mpi_request: pointer to the SCSI_IO reqest message frame
3256 * Supporting protection 1 and 3.
3261 _scsih_setup_eedp(struct scsi_cmnd
*scmd
, Mpi2SCSIIORequest_t
*mpi_request
)
3264 unsigned char prot_op
= scsi_get_prot_op(scmd
);
3265 unsigned char prot_type
= scsi_get_prot_type(scmd
);
3267 if (prot_type
== SCSI_PROT_DIF_TYPE0
|| prot_op
== SCSI_PROT_NORMAL
)
3270 if (prot_op
== SCSI_PROT_READ_STRIP
)
3271 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP
;
3272 else if (prot_op
== SCSI_PROT_WRITE_INSERT
)
3273 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_INSERT_OP
;
3277 switch (prot_type
) {
3278 case SCSI_PROT_DIF_TYPE1
:
3281 * enable ref/guard checking
3282 * auto increment ref tag
3284 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG
|
3285 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG
|
3286 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
3287 mpi_request
->CDB
.EEDP32
.PrimaryReferenceTag
=
3288 cpu_to_be32(scsi_get_lba(scmd
));
3291 case SCSI_PROT_DIF_TYPE2
:
3293 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG
|
3294 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG
|
3295 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
3298 case SCSI_PROT_DIF_TYPE3
:
3301 * enable guard checking
3303 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
3306 mpi_request
->EEDPBlockSize
= cpu_to_le32(scmd
->device
->sector_size
);
3307 mpi_request
->EEDPFlags
= cpu_to_le16(eedp_flags
);
3311 * _scsih_eedp_error_handling - return sense code for EEDP errors
3312 * @scmd: pointer to scsi command object
3313 * @ioc_status: ioc status
3318 _scsih_eedp_error_handling(struct scsi_cmnd
*scmd
, u16 ioc_status
)
3324 switch (ioc_status
) {
3325 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
3328 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
3331 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
3339 if (scmd
->sc_data_direction
== DMA_TO_DEVICE
) {
3340 sk
= ILLEGAL_REQUEST
;
3341 host_byte
= DID_ABORT
;
3343 sk
= ABORTED_COMMAND
;
3347 scsi_build_sense_buffer(0, scmd
->sense_buffer
, sk
, 0x10, ascq
);
3348 scmd
->result
= DRIVER_SENSE
<< 24 | (host_byte
<< 16) |
3349 SAM_STAT_CHECK_CONDITION
;
3353 * _scsih_qcmd - main scsi request entry point
3354 * @scmd: pointer to scsi command object
3355 * @done: function pointer to be invoked on completion
3357 * The callback index is set inside `ioc->scsi_io_cb_idx`.
3359 * Returns 0 on success. If there's a failure, return either:
3360 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
3361 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
3364 _scsih_qcmd_lck(struct scsi_cmnd
*scmd
, void (*done
)(struct scsi_cmnd
*))
3366 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
3367 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
3368 struct MPT2SAS_TARGET
*sas_target_priv_data
;
3369 Mpi2SCSIIORequest_t
*mpi_request
;
3373 scmd
->scsi_done
= done
;
3374 sas_device_priv_data
= scmd
->device
->hostdata
;
3375 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
3376 scmd
->result
= DID_NO_CONNECT
<< 16;
3377 scmd
->scsi_done(scmd
);
3381 if (ioc
->pci_error_recovery
) {
3382 scmd
->result
= DID_NO_CONNECT
<< 16;
3383 scmd
->scsi_done(scmd
);
3387 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
3388 /* invalid device handle */
3389 if (sas_target_priv_data
->handle
== MPT2SAS_INVALID_DEVICE_HANDLE
) {
3390 scmd
->result
= DID_NO_CONNECT
<< 16;
3391 scmd
->scsi_done(scmd
);
3395 /* host recovery or link resets sent via IOCTLs */
3396 if (ioc
->shost_recovery
|| ioc
->ioc_link_reset_in_progress
)
3397 return SCSI_MLQUEUE_HOST_BUSY
;
3398 /* device busy with task management */
3399 else if (sas_device_priv_data
->block
|| sas_target_priv_data
->tm_busy
)
3400 return SCSI_MLQUEUE_DEVICE_BUSY
;
3401 /* device has been deleted */
3402 else if (sas_target_priv_data
->deleted
) {
3403 scmd
->result
= DID_NO_CONNECT
<< 16;
3404 scmd
->scsi_done(scmd
);
3408 if (scmd
->sc_data_direction
== DMA_FROM_DEVICE
)
3409 mpi_control
= MPI2_SCSIIO_CONTROL_READ
;
3410 else if (scmd
->sc_data_direction
== DMA_TO_DEVICE
)
3411 mpi_control
= MPI2_SCSIIO_CONTROL_WRITE
;
3413 mpi_control
= MPI2_SCSIIO_CONTROL_NODATATRANSFER
;
3416 if (!(sas_device_priv_data
->flags
& MPT_DEVICE_FLAGS_INIT
)) {
3417 if (scmd
->device
->tagged_supported
) {
3418 if (scmd
->device
->ordered_tags
)
3419 mpi_control
|= MPI2_SCSIIO_CONTROL_ORDEREDQ
;
3421 mpi_control
|= MPI2_SCSIIO_CONTROL_SIMPLEQ
;
3423 /* MPI Revision I (UNIT = 0xA) - removed MPI2_SCSIIO_CONTROL_UNTAGGED */
3424 /* mpi_control |= MPI2_SCSIIO_CONTROL_UNTAGGED;
3426 mpi_control
|= (0x500);
3429 mpi_control
|= MPI2_SCSIIO_CONTROL_SIMPLEQ
;
3430 /* Make sure Device is not raid volume */
3431 if (!_scsih_is_raid(&scmd
->device
->sdev_gendev
) &&
3432 sas_is_tlr_enabled(scmd
->device
) && scmd
->cmd_len
!= 32)
3433 mpi_control
|= MPI2_SCSIIO_CONTROL_TLR_ON
;
3435 smid
= mpt2sas_base_get_smid_scsiio(ioc
, ioc
->scsi_io_cb_idx
, scmd
);
3437 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
3438 ioc
->name
, __func__
);
3441 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3442 memset(mpi_request
, 0, sizeof(Mpi2SCSIIORequest_t
));
3443 _scsih_setup_eedp(scmd
, mpi_request
);
3444 if (scmd
->cmd_len
== 32)
3445 mpi_control
|= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT
;
3446 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
3447 if (sas_device_priv_data
->sas_target
->flags
&
3448 MPT_TARGET_FLAGS_RAID_COMPONENT
)
3449 mpi_request
->Function
= MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
;
3451 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
3452 mpi_request
->DevHandle
=
3453 cpu_to_le16(sas_device_priv_data
->sas_target
->handle
);
3454 mpi_request
->DataLength
= cpu_to_le32(scsi_bufflen(scmd
));
3455 mpi_request
->Control
= cpu_to_le32(mpi_control
);
3456 mpi_request
->IoFlags
= cpu_to_le16(scmd
->cmd_len
);
3457 mpi_request
->MsgFlags
= MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR
;
3458 mpi_request
->SenseBufferLength
= SCSI_SENSE_BUFFERSIZE
;
3459 mpi_request
->SenseBufferLowAddress
=
3460 mpt2sas_base_get_sense_buffer_dma(ioc
, smid
);
3461 mpi_request
->SGLOffset0
= offsetof(Mpi2SCSIIORequest_t
, SGL
) / 4;
3462 mpi_request
->SGLFlags
= cpu_to_le16(MPI2_SCSIIO_SGLFLAGS_TYPE_MPI
+
3463 MPI2_SCSIIO_SGLFLAGS_SYSTEM_ADDR
);
3464 mpi_request
->VF_ID
= 0; /* TODO */
3465 mpi_request
->VP_ID
= 0;
3466 int_to_scsilun(sas_device_priv_data
->lun
, (struct scsi_lun
*)
3468 memcpy(mpi_request
->CDB
.CDB32
, scmd
->cmnd
, scmd
->cmd_len
);
3470 if (!mpi_request
->DataLength
) {
3471 mpt2sas_base_build_zero_len_sge(ioc
, &mpi_request
->SGL
);
3473 if (_scsih_build_scatter_gather(ioc
, scmd
, smid
)) {
3474 mpt2sas_base_free_smid(ioc
, smid
);
3479 if (likely(mpi_request
->Function
== MPI2_FUNCTION_SCSI_IO_REQUEST
))
3480 mpt2sas_base_put_smid_scsi_io(ioc
, smid
,
3481 sas_device_priv_data
->sas_target
->handle
);
3483 mpt2sas_base_put_smid_default(ioc
, smid
);
3487 return SCSI_MLQUEUE_HOST_BUSY
;
3490 static DEF_SCSI_QCMD(_scsih_qcmd
)
3493 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
3494 * @sense_buffer: sense data returned by target
3495 * @data: normalized skey/asc/ascq
3500 _scsih_normalize_sense(char *sense_buffer
, struct sense_info
*data
)
3502 if ((sense_buffer
[0] & 0x7F) >= 0x72) {
3503 /* descriptor format */
3504 data
->skey
= sense_buffer
[1] & 0x0F;
3505 data
->asc
= sense_buffer
[2];
3506 data
->ascq
= sense_buffer
[3];
3509 data
->skey
= sense_buffer
[2] & 0x0F;
3510 data
->asc
= sense_buffer
[12];
3511 data
->ascq
= sense_buffer
[13];
3515 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3517 * _scsih_scsi_ioc_info - translated non-successfull SCSI_IO request
3518 * @ioc: per adapter object
3519 * @scmd: pointer to scsi command object
3520 * @mpi_reply: reply mf payload returned from firmware
3522 * scsi_status - SCSI Status code returned from target device
3523 * scsi_state - state info associated with SCSI_IO determined by ioc
3524 * ioc_status - ioc supplied status info
3529 _scsih_scsi_ioc_info(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
,
3530 Mpi2SCSIIOReply_t
*mpi_reply
, u16 smid
)
3534 u16 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) &
3535 MPI2_IOCSTATUS_MASK
;
3536 u8 scsi_state
= mpi_reply
->SCSIState
;
3537 u8 scsi_status
= mpi_reply
->SCSIStatus
;
3538 char *desc_ioc_state
= NULL
;
3539 char *desc_scsi_status
= NULL
;
3540 char *desc_scsi_state
= ioc
->tmp_string
;
3541 u32 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
3542 struct _sas_device
*sas_device
= NULL
;
3543 unsigned long flags
;
3544 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
3545 struct MPT2SAS_TARGET
*priv_target
= starget
->hostdata
;
3550 if (log_info
== 0x31170000)
3553 switch (ioc_status
) {
3554 case MPI2_IOCSTATUS_SUCCESS
:
3555 desc_ioc_state
= "success";
3557 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
3558 desc_ioc_state
= "invalid function";
3560 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
3561 desc_ioc_state
= "scsi recovered error";
3563 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE
:
3564 desc_ioc_state
= "scsi invalid dev handle";
3566 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
3567 desc_ioc_state
= "scsi device not there";
3569 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
3570 desc_ioc_state
= "scsi data overrun";
3572 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
3573 desc_ioc_state
= "scsi data underrun";
3575 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
3576 desc_ioc_state
= "scsi io data error";
3578 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
3579 desc_ioc_state
= "scsi protocol error";
3581 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
3582 desc_ioc_state
= "scsi task terminated";
3584 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
3585 desc_ioc_state
= "scsi residual mismatch";
3587 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
3588 desc_ioc_state
= "scsi task mgmt failed";
3590 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
3591 desc_ioc_state
= "scsi ioc terminated";
3593 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
3594 desc_ioc_state
= "scsi ext terminated";
3596 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
3597 desc_ioc_state
= "eedp guard error";
3599 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
3600 desc_ioc_state
= "eedp ref tag error";
3602 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
3603 desc_ioc_state
= "eedp app tag error";
3606 desc_ioc_state
= "unknown";
3610 switch (scsi_status
) {
3611 case MPI2_SCSI_STATUS_GOOD
:
3612 desc_scsi_status
= "good";
3614 case MPI2_SCSI_STATUS_CHECK_CONDITION
:
3615 desc_scsi_status
= "check condition";
3617 case MPI2_SCSI_STATUS_CONDITION_MET
:
3618 desc_scsi_status
= "condition met";
3620 case MPI2_SCSI_STATUS_BUSY
:
3621 desc_scsi_status
= "busy";
3623 case MPI2_SCSI_STATUS_INTERMEDIATE
:
3624 desc_scsi_status
= "intermediate";
3626 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET
:
3627 desc_scsi_status
= "intermediate condmet";
3629 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT
:
3630 desc_scsi_status
= "reservation conflict";
3632 case MPI2_SCSI_STATUS_COMMAND_TERMINATED
:
3633 desc_scsi_status
= "command terminated";
3635 case MPI2_SCSI_STATUS_TASK_SET_FULL
:
3636 desc_scsi_status
= "task set full";
3638 case MPI2_SCSI_STATUS_ACA_ACTIVE
:
3639 desc_scsi_status
= "aca active";
3641 case MPI2_SCSI_STATUS_TASK_ABORTED
:
3642 desc_scsi_status
= "task aborted";
3645 desc_scsi_status
= "unknown";
3649 desc_scsi_state
[0] = '\0';
3651 desc_scsi_state
= " ";
3652 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
3653 strcat(desc_scsi_state
, "response info ");
3654 if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
3655 strcat(desc_scsi_state
, "state terminated ");
3656 if (scsi_state
& MPI2_SCSI_STATE_NO_SCSI_STATUS
)
3657 strcat(desc_scsi_state
, "no status ");
3658 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_FAILED
)
3659 strcat(desc_scsi_state
, "autosense failed ");
3660 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
)
3661 strcat(desc_scsi_state
, "autosense valid ");
3663 scsi_print_command(scmd
);
3665 if (priv_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
3666 printk(MPT2SAS_WARN_FMT
"\tvolume wwid(0x%016llx)\n", ioc
->name
,
3667 (unsigned long long)priv_target
->sas_address
);
3669 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
3670 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
3671 priv_target
->sas_address
);
3673 printk(MPT2SAS_WARN_FMT
"\tsas_address(0x%016llx), "
3674 "phy(%d)\n", ioc
->name
, sas_device
->sas_address
,
3676 printk(MPT2SAS_WARN_FMT
3677 "\tenclosure_logical_id(0x%016llx), slot(%d)\n",
3678 ioc
->name
, sas_device
->enclosure_logical_id
,
3681 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3684 printk(MPT2SAS_WARN_FMT
"\thandle(0x%04x), ioc_status(%s)(0x%04x), "
3685 "smid(%d)\n", ioc
->name
, le16_to_cpu(mpi_reply
->DevHandle
),
3686 desc_ioc_state
, ioc_status
, smid
);
3687 printk(MPT2SAS_WARN_FMT
"\trequest_len(%d), underflow(%d), "
3688 "resid(%d)\n", ioc
->name
, scsi_bufflen(scmd
), scmd
->underflow
,
3689 scsi_get_resid(scmd
));
3690 printk(MPT2SAS_WARN_FMT
"\ttag(%d), transfer_count(%d), "
3691 "sc->result(0x%08x)\n", ioc
->name
, le16_to_cpu(mpi_reply
->TaskTag
),
3692 le32_to_cpu(mpi_reply
->TransferCount
), scmd
->result
);
3693 printk(MPT2SAS_WARN_FMT
"\tscsi_status(%s)(0x%02x), "
3694 "scsi_state(%s)(0x%02x)\n", ioc
->name
, desc_scsi_status
,
3695 scsi_status
, desc_scsi_state
, scsi_state
);
3697 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
3698 struct sense_info data
;
3699 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
3700 printk(MPT2SAS_WARN_FMT
"\t[sense_key,asc,ascq]: "
3701 "[0x%02x,0x%02x,0x%02x], count(%d)\n", ioc
->name
, data
.skey
,
3702 data
.asc
, data
.ascq
, le32_to_cpu(mpi_reply
->SenseCount
));
3705 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
) {
3706 response_info
= le32_to_cpu(mpi_reply
->ResponseInfo
);
3707 response_bytes
= (u8
*)&response_info
;
3708 _scsih_response_code(ioc
, response_bytes
[0]);
3714 * _scsih_turn_on_fault_led - illuminate Fault LED
3715 * @ioc: per adapter object
3716 * @handle: device handle
3722 _scsih_turn_on_fault_led(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
3724 Mpi2SepReply_t mpi_reply
;
3725 Mpi2SepRequest_t mpi_request
;
3727 memset(&mpi_request
, 0, sizeof(Mpi2SepRequest_t
));
3728 mpi_request
.Function
= MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR
;
3729 mpi_request
.Action
= MPI2_SEP_REQ_ACTION_WRITE_STATUS
;
3730 mpi_request
.SlotStatus
=
3731 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT
);
3732 mpi_request
.DevHandle
= cpu_to_le16(handle
);
3733 mpi_request
.Flags
= MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS
;
3734 if ((mpt2sas_base_scsi_enclosure_processor(ioc
, &mpi_reply
,
3735 &mpi_request
)) != 0) {
3736 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n", ioc
->name
,
3737 __FILE__
, __LINE__
, __func__
);
3741 if (mpi_reply
.IOCStatus
|| mpi_reply
.IOCLogInfo
) {
3742 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"enclosure_processor: "
3743 "ioc_status (0x%04x), loginfo(0x%08x)\n", ioc
->name
,
3744 le16_to_cpu(mpi_reply
.IOCStatus
),
3745 le32_to_cpu(mpi_reply
.IOCLogInfo
)));
3751 * _scsih_send_event_to_turn_on_fault_led - fire delayed event
3752 * @ioc: per adapter object
3753 * @handle: device handle
3754 * Context: interrupt.
3759 _scsih_send_event_to_turn_on_fault_led(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
3761 struct fw_event_work
*fw_event
;
3763 fw_event
= kzalloc(sizeof(struct fw_event_work
), GFP_ATOMIC
);
3766 fw_event
->event
= MPT2SAS_TURN_ON_FAULT_LED
;
3767 fw_event
->device_handle
= handle
;
3768 fw_event
->ioc
= ioc
;
3769 _scsih_fw_event_add(ioc
, fw_event
);
3773 * _scsih_smart_predicted_fault - process smart errors
3774 * @ioc: per adapter object
3775 * @handle: device handle
3776 * Context: interrupt.
3781 _scsih_smart_predicted_fault(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
3783 struct scsi_target
*starget
;
3784 struct MPT2SAS_TARGET
*sas_target_priv_data
;
3785 Mpi2EventNotificationReply_t
*event_reply
;
3786 Mpi2EventDataSasDeviceStatusChange_t
*event_data
;
3787 struct _sas_device
*sas_device
;
3789 unsigned long flags
;
3791 /* only handle non-raid devices */
3792 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
3793 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
3795 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3798 starget
= sas_device
->starget
;
3799 sas_target_priv_data
= starget
->hostdata
;
3801 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
) ||
3802 ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
))) {
3803 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3806 starget_printk(KERN_WARNING
, starget
, "predicted fault\n");
3807 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3809 if (ioc
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_IBM
)
3810 _scsih_send_event_to_turn_on_fault_led(ioc
, handle
);
3812 /* insert into event log */
3813 sz
= offsetof(Mpi2EventNotificationReply_t
, EventData
) +
3814 sizeof(Mpi2EventDataSasDeviceStatusChange_t
);
3815 event_reply
= kzalloc(sz
, GFP_KERNEL
);
3817 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3818 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3822 event_reply
->Function
= MPI2_FUNCTION_EVENT_NOTIFICATION
;
3823 event_reply
->Event
=
3824 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
);
3825 event_reply
->MsgLength
= sz
/4;
3826 event_reply
->EventDataLength
=
3827 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t
)/4);
3828 event_data
= (Mpi2EventDataSasDeviceStatusChange_t
*)
3829 event_reply
->EventData
;
3830 event_data
->ReasonCode
= MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
;
3831 event_data
->ASC
= 0x5D;
3832 event_data
->DevHandle
= cpu_to_le16(handle
);
3833 event_data
->SASAddress
= cpu_to_le64(sas_target_priv_data
->sas_address
);
3834 mpt2sas_ctl_add_to_event_log(ioc
, event_reply
);
3839 * _scsih_io_done - scsi request callback
3840 * @ioc: per adapter object
3841 * @smid: system request message index
3842 * @msix_index: MSIX table index supplied by the OS
3843 * @reply: reply message frame(lower 32bit addr)
3845 * Callback handler when using _scsih_qcmd.
3847 * Return 1 meaning mf should be freed from _base_interrupt
3848 * 0 means the mf is freed from this function.
3851 _scsih_io_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
3853 Mpi2SCSIIORequest_t
*mpi_request
;
3854 Mpi2SCSIIOReply_t
*mpi_reply
;
3855 struct scsi_cmnd
*scmd
;
3861 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
3862 u32 response_code
= 0;
3864 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
3865 scmd
= _scsih_scsi_lookup_get_clear(ioc
, smid
);
3869 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3871 if (mpi_reply
== NULL
) {
3872 scmd
->result
= DID_OK
<< 16;
3876 sas_device_priv_data
= scmd
->device
->hostdata
;
3877 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
||
3878 sas_device_priv_data
->sas_target
->deleted
) {
3879 scmd
->result
= DID_NO_CONNECT
<< 16;
3883 /* turning off TLR */
3884 scsi_state
= mpi_reply
->SCSIState
;
3885 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
3887 le32_to_cpu(mpi_reply
->ResponseInfo
) & 0xFF;
3888 if (!sas_device_priv_data
->tlr_snoop_check
) {
3889 sas_device_priv_data
->tlr_snoop_check
++;
3890 if (!_scsih_is_raid(&scmd
->device
->sdev_gendev
) &&
3891 sas_is_tlr_enabled(scmd
->device
) &&
3892 response_code
== MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
) {
3893 sas_disable_tlr(scmd
->device
);
3894 sdev_printk(KERN_INFO
, scmd
->device
, "TLR disabled\n");
3898 xfer_cnt
= le32_to_cpu(mpi_reply
->TransferCount
);
3899 scsi_set_resid(scmd
, scsi_bufflen(scmd
) - xfer_cnt
);
3900 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
);
3901 if (ioc_status
& MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE
)
3902 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
3905 ioc_status
&= MPI2_IOCSTATUS_MASK
;
3906 scsi_status
= mpi_reply
->SCSIStatus
;
3908 if (ioc_status
== MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
&& xfer_cnt
== 0 &&
3909 (scsi_status
== MPI2_SCSI_STATUS_BUSY
||
3910 scsi_status
== MPI2_SCSI_STATUS_RESERVATION_CONFLICT
||
3911 scsi_status
== MPI2_SCSI_STATUS_TASK_SET_FULL
)) {
3912 ioc_status
= MPI2_IOCSTATUS_SUCCESS
;
3915 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
3916 struct sense_info data
;
3917 const void *sense_data
= mpt2sas_base_get_sense_buffer(ioc
,
3919 u32 sz
= min_t(u32
, SCSI_SENSE_BUFFERSIZE
,
3920 le32_to_cpu(mpi_reply
->SenseCount
));
3921 memcpy(scmd
->sense_buffer
, sense_data
, sz
);
3922 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
3923 /* failure prediction threshold exceeded */
3924 if (data
.asc
== 0x5D)
3925 _scsih_smart_predicted_fault(ioc
,
3926 le16_to_cpu(mpi_reply
->DevHandle
));
3929 switch (ioc_status
) {
3930 case MPI2_IOCSTATUS_BUSY
:
3931 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES
:
3932 scmd
->result
= SAM_STAT_BUSY
;
3935 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
3936 scmd
->result
= DID_NO_CONNECT
<< 16;
3939 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
3940 if (sas_device_priv_data
->block
) {
3941 scmd
->result
= DID_TRANSPORT_DISRUPTED
<< 16;
3944 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
3945 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
3946 scmd
->result
= DID_RESET
<< 16;
3949 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
3950 if ((xfer_cnt
== 0) || (scmd
->underflow
> xfer_cnt
))
3951 scmd
->result
= DID_SOFT_ERROR
<< 16;
3953 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
3956 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
3957 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
3959 if ((scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
))
3962 if (xfer_cnt
< scmd
->underflow
) {
3963 if (scsi_status
== SAM_STAT_BUSY
)
3964 scmd
->result
= SAM_STAT_BUSY
;
3966 scmd
->result
= DID_SOFT_ERROR
<< 16;
3967 } else if (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
3968 MPI2_SCSI_STATE_NO_SCSI_STATUS
))
3969 scmd
->result
= DID_SOFT_ERROR
<< 16;
3970 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
3971 scmd
->result
= DID_RESET
<< 16;
3972 else if (!xfer_cnt
&& scmd
->cmnd
[0] == REPORT_LUNS
) {
3973 mpi_reply
->SCSIState
= MPI2_SCSI_STATE_AUTOSENSE_VALID
;
3974 mpi_reply
->SCSIStatus
= SAM_STAT_CHECK_CONDITION
;
3975 scmd
->result
= (DRIVER_SENSE
<< 24) |
3976 SAM_STAT_CHECK_CONDITION
;
3977 scmd
->sense_buffer
[0] = 0x70;
3978 scmd
->sense_buffer
[2] = ILLEGAL_REQUEST
;
3979 scmd
->sense_buffer
[12] = 0x20;
3980 scmd
->sense_buffer
[13] = 0;
3984 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
3985 scsi_set_resid(scmd
, 0);
3986 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
3987 case MPI2_IOCSTATUS_SUCCESS
:
3988 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
3989 if (response_code
==
3990 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
||
3991 (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
3992 MPI2_SCSI_STATE_NO_SCSI_STATUS
)))
3993 scmd
->result
= DID_SOFT_ERROR
<< 16;
3994 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
3995 scmd
->result
= DID_RESET
<< 16;
3998 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
3999 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
4000 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
4001 _scsih_eedp_error_handling(scmd
, ioc_status
);
4003 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
4004 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
4005 case MPI2_IOCSTATUS_INVALID_SGL
:
4006 case MPI2_IOCSTATUS_INTERNAL_ERROR
:
4007 case MPI2_IOCSTATUS_INVALID_FIELD
:
4008 case MPI2_IOCSTATUS_INVALID_STATE
:
4009 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
4010 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
4012 scmd
->result
= DID_SOFT_ERROR
<< 16;
4017 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4018 if (scmd
->result
&& (ioc
->logging_level
& MPT_DEBUG_REPLY
))
4019 _scsih_scsi_ioc_info(ioc
, scmd
, mpi_reply
, smid
);
4023 scsi_dma_unmap(scmd
);
4024 scmd
->scsi_done(scmd
);
4029 * _scsih_sas_host_refresh - refreshing sas host object contents
4030 * @ioc: per adapter object
4033 * During port enable, fw will send topology events for every device. Its
4034 * possible that the handles may change from the previous setting, so this
4035 * code keeping handles updating if changed.
4040 _scsih_sas_host_refresh(struct MPT2SAS_ADAPTER
*ioc
)
4045 Mpi2ConfigReply_t mpi_reply
;
4046 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
4047 u16 attached_handle
;
4050 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
4051 "updating handles for sas_host(0x%016llx)\n",
4052 ioc
->name
, (unsigned long long)ioc
->sas_hba
.sas_address
));
4054 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
4055 * sizeof(Mpi2SasIOUnit0PhyData_t
));
4056 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
4057 if (!sas_iounit_pg0
) {
4058 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4059 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4063 if ((mpt2sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
4064 sas_iounit_pg0
, sz
)) != 0)
4066 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
4067 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
4069 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
4070 link_rate
= sas_iounit_pg0
->PhyData
[i
].NegotiatedLinkRate
>> 4;
4072 ioc
->sas_hba
.handle
= le16_to_cpu(sas_iounit_pg0
->
4073 PhyData
[0].ControllerDevHandle
);
4074 ioc
->sas_hba
.phy
[i
].handle
= ioc
->sas_hba
.handle
;
4075 attached_handle
= le16_to_cpu(sas_iounit_pg0
->PhyData
[i
].
4077 if (attached_handle
&& link_rate
< MPI2_SAS_NEG_LINK_RATE_1_5
)
4078 link_rate
= MPI2_SAS_NEG_LINK_RATE_1_5
;
4079 mpt2sas_transport_update_links(ioc
, ioc
->sas_hba
.sas_address
,
4080 attached_handle
, i
, link_rate
);
4083 kfree(sas_iounit_pg0
);
4087 * _scsih_sas_host_add - create sas host object
4088 * @ioc: per adapter object
4090 * Creating host side data object, stored in ioc->sas_hba
4095 _scsih_sas_host_add(struct MPT2SAS_ADAPTER
*ioc
)
4098 Mpi2ConfigReply_t mpi_reply
;
4099 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
4100 Mpi2SasIOUnitPage1_t
*sas_iounit_pg1
= NULL
;
4101 Mpi2SasPhyPage0_t phy_pg0
;
4102 Mpi2SasDevicePage0_t sas_device_pg0
;
4103 Mpi2SasEnclosurePage0_t enclosure_pg0
;
4106 u16 device_missing_delay
;
4108 mpt2sas_config_get_number_hba_phys(ioc
, &ioc
->sas_hba
.num_phys
);
4109 if (!ioc
->sas_hba
.num_phys
) {
4110 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4111 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4115 /* sas_iounit page 0 */
4116 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
4117 sizeof(Mpi2SasIOUnit0PhyData_t
));
4118 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
4119 if (!sas_iounit_pg0
) {
4120 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4121 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4124 if ((mpt2sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
4125 sas_iounit_pg0
, sz
))) {
4126 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4127 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4130 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4131 MPI2_IOCSTATUS_MASK
;
4132 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4133 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4134 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4138 /* sas_iounit page 1 */
4139 sz
= offsetof(Mpi2SasIOUnitPage1_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
4140 sizeof(Mpi2SasIOUnit1PhyData_t
));
4141 sas_iounit_pg1
= kzalloc(sz
, GFP_KERNEL
);
4142 if (!sas_iounit_pg1
) {
4143 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4144 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4147 if ((mpt2sas_config_get_sas_iounit_pg1(ioc
, &mpi_reply
,
4148 sas_iounit_pg1
, sz
))) {
4149 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4150 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4153 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4154 MPI2_IOCSTATUS_MASK
;
4155 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4156 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4157 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4161 ioc
->io_missing_delay
=
4162 le16_to_cpu(sas_iounit_pg1
->IODeviceMissingDelay
);
4163 device_missing_delay
=
4164 le16_to_cpu(sas_iounit_pg1
->ReportDeviceMissingDelay
);
4165 if (device_missing_delay
& MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16
)
4166 ioc
->device_missing_delay
= (device_missing_delay
&
4167 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
) * 16;
4169 ioc
->device_missing_delay
= device_missing_delay
&
4170 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
;
4172 ioc
->sas_hba
.parent_dev
= &ioc
->shost
->shost_gendev
;
4173 ioc
->sas_hba
.phy
= kcalloc(ioc
->sas_hba
.num_phys
,
4174 sizeof(struct _sas_phy
), GFP_KERNEL
);
4175 if (!ioc
->sas_hba
.phy
) {
4176 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4177 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4180 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
4181 if ((mpt2sas_config_get_phy_pg0(ioc
, &mpi_reply
, &phy_pg0
,
4183 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4184 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4187 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4188 MPI2_IOCSTATUS_MASK
;
4189 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4190 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4191 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4196 ioc
->sas_hba
.handle
= le16_to_cpu(sas_iounit_pg0
->
4197 PhyData
[0].ControllerDevHandle
);
4198 ioc
->sas_hba
.phy
[i
].handle
= ioc
->sas_hba
.handle
;
4199 ioc
->sas_hba
.phy
[i
].phy_id
= i
;
4200 mpt2sas_transport_add_host_phy(ioc
, &ioc
->sas_hba
.phy
[i
],
4201 phy_pg0
, ioc
->sas_hba
.parent_dev
);
4203 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
4204 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, ioc
->sas_hba
.handle
))) {
4205 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4206 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4209 ioc
->sas_hba
.enclosure_handle
=
4210 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
4211 ioc
->sas_hba
.sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
4212 printk(MPT2SAS_INFO_FMT
"host_add: handle(0x%04x), "
4213 "sas_addr(0x%016llx), phys(%d)\n", ioc
->name
, ioc
->sas_hba
.handle
,
4214 (unsigned long long) ioc
->sas_hba
.sas_address
,
4215 ioc
->sas_hba
.num_phys
) ;
4217 if (ioc
->sas_hba
.enclosure_handle
) {
4218 if (!(mpt2sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
4220 MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
4221 ioc
->sas_hba
.enclosure_handle
))) {
4222 ioc
->sas_hba
.enclosure_logical_id
=
4223 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
4228 kfree(sas_iounit_pg1
);
4229 kfree(sas_iounit_pg0
);
4233 * _scsih_expander_add - creating expander object
4234 * @ioc: per adapter object
4235 * @handle: expander handle
4237 * Creating expander object, stored in ioc->sas_expander_list.
4239 * Return 0 for success, else error.
4242 _scsih_expander_add(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
4244 struct _sas_node
*sas_expander
;
4245 Mpi2ConfigReply_t mpi_reply
;
4246 Mpi2ExpanderPage0_t expander_pg0
;
4247 Mpi2ExpanderPage1_t expander_pg1
;
4248 Mpi2SasEnclosurePage0_t enclosure_pg0
;
4251 __le64 sas_address
, sas_address_parent
= 0;
4253 unsigned long flags
;
4254 struct _sas_port
*mpt2sas_port
= NULL
;
4260 if (ioc
->shost_recovery
|| ioc
->pci_error_recovery
)
4263 if ((mpt2sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
4264 MPI2_SAS_EXPAND_PGAD_FORM_HNDL
, handle
))) {
4265 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4266 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4270 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4271 MPI2_IOCSTATUS_MASK
;
4272 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4273 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4274 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4278 /* handle out of order topology events */
4279 parent_handle
= le16_to_cpu(expander_pg0
.ParentDevHandle
);
4280 if (_scsih_get_sas_address(ioc
, parent_handle
, &sas_address_parent
)
4282 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4283 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4286 if (sas_address_parent
!= ioc
->sas_hba
.sas_address
) {
4287 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
4288 sas_expander
= mpt2sas_scsih_expander_find_by_sas_address(ioc
,
4289 sas_address_parent
);
4290 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
4291 if (!sas_expander
) {
4292 rc
= _scsih_expander_add(ioc
, parent_handle
);
4298 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
4299 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
4300 sas_expander
= mpt2sas_scsih_expander_find_by_sas_address(ioc
,
4302 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
4307 sas_expander
= kzalloc(sizeof(struct _sas_node
),
4309 if (!sas_expander
) {
4310 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4311 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4315 sas_expander
->handle
= handle
;
4316 sas_expander
->num_phys
= expander_pg0
.NumPhys
;
4317 sas_expander
->sas_address_parent
= sas_address_parent
;
4318 sas_expander
->sas_address
= sas_address
;
4320 printk(MPT2SAS_INFO_FMT
"expander_add: handle(0x%04x),"
4321 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc
->name
,
4322 handle
, parent_handle
, (unsigned long long)
4323 sas_expander
->sas_address
, sas_expander
->num_phys
);
4325 if (!sas_expander
->num_phys
)
4327 sas_expander
->phy
= kcalloc(sas_expander
->num_phys
,
4328 sizeof(struct _sas_phy
), GFP_KERNEL
);
4329 if (!sas_expander
->phy
) {
4330 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4331 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4336 INIT_LIST_HEAD(&sas_expander
->sas_port_list
);
4337 mpt2sas_port
= mpt2sas_transport_port_add(ioc
, handle
,
4338 sas_address_parent
);
4339 if (!mpt2sas_port
) {
4340 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4341 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4345 sas_expander
->parent_dev
= &mpt2sas_port
->rphy
->dev
;
4347 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++) {
4348 if ((mpt2sas_config_get_expander_pg1(ioc
, &mpi_reply
,
4349 &expander_pg1
, i
, handle
))) {
4350 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4351 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4355 sas_expander
->phy
[i
].handle
= handle
;
4356 sas_expander
->phy
[i
].phy_id
= i
;
4358 if ((mpt2sas_transport_add_expander_phy(ioc
,
4359 &sas_expander
->phy
[i
], expander_pg1
,
4360 sas_expander
->parent_dev
))) {
4361 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4362 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4368 if (sas_expander
->enclosure_handle
) {
4369 if (!(mpt2sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
4370 &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
4371 sas_expander
->enclosure_handle
))) {
4372 sas_expander
->enclosure_logical_id
=
4373 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
4377 _scsih_expander_node_add(ioc
, sas_expander
);
4383 mpt2sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
4384 sas_address_parent
);
4385 kfree(sas_expander
);
4390 * _scsih_done - scsih callback handler.
4391 * @ioc: per adapter object
4392 * @smid: system request message index
4393 * @msix_index: MSIX table index supplied by the OS
4394 * @reply: reply message frame(lower 32bit addr)
4396 * Callback handler when sending internal generated message frames.
4397 * The callback index passed is `ioc->scsih_cb_idx`
4399 * Return 1 meaning mf should be freed from _base_interrupt
4400 * 0 means the mf is freed from this function.
4403 _scsih_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
4405 MPI2DefaultReply_t
*mpi_reply
;
4407 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
4408 if (ioc
->scsih_cmds
.status
== MPT2_CMD_NOT_USED
)
4410 if (ioc
->scsih_cmds
.smid
!= smid
)
4412 ioc
->scsih_cmds
.status
|= MPT2_CMD_COMPLETE
;
4414 memcpy(ioc
->scsih_cmds
.reply
, mpi_reply
,
4415 mpi_reply
->MsgLength
*4);
4416 ioc
->scsih_cmds
.status
|= MPT2_CMD_REPLY_VALID
;
4418 ioc
->scsih_cmds
.status
&= ~MPT2_CMD_PENDING
;
4419 complete(&ioc
->scsih_cmds
.done
);
4424 * mpt2sas_expander_remove - removing expander object
4425 * @ioc: per adapter object
4426 * @sas_address: expander sas_address
4431 mpt2sas_expander_remove(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
)
4433 struct _sas_node
*sas_expander
;
4434 unsigned long flags
;
4436 if (ioc
->shost_recovery
)
4439 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
4440 sas_expander
= mpt2sas_scsih_expander_find_by_sas_address(ioc
,
4442 if (!sas_expander
) {
4443 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
4446 list_del(&sas_expander
->list
);
4447 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
4448 _scsih_expander_node_remove(ioc
, sas_expander
);
4452 * _scsih_check_access_status - check access flags
4453 * @ioc: per adapter object
4454 * @sas_address: sas address
4455 * @handle: sas device handle
4456 * @access_flags: errors returned during discovery of the device
4458 * Return 0 for success, else failure
4461 _scsih_check_access_status(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
,
4462 u16 handle
, u8 access_status
)
4467 switch (access_status
) {
4468 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS
:
4469 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION
:
4472 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED
:
4473 desc
= "sata capability failed";
4475 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT
:
4476 desc
= "sata affiliation conflict";
4478 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE
:
4479 desc
= "route not addressable";
4481 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE
:
4482 desc
= "smp error not addressable";
4484 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED
:
4485 desc
= "device blocked";
4487 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED
:
4488 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN
:
4489 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT
:
4490 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG
:
4491 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION
:
4492 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER
:
4493 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN
:
4494 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN
:
4495 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN
:
4496 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION
:
4497 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE
:
4498 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX
:
4499 desc
= "sata initialization failed";
4509 printk(MPT2SAS_ERR_FMT
"discovery errors(%s): sas_address(0x%016llx), "
4510 "handle(0x%04x)\n", ioc
->name
, desc
,
4511 (unsigned long long)sas_address
, handle
);
4516 _scsih_check_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
4518 Mpi2ConfigReply_t mpi_reply
;
4519 Mpi2SasDevicePage0_t sas_device_pg0
;
4520 struct _sas_device
*sas_device
;
4522 unsigned long flags
;
4524 struct scsi_target
*starget
;
4525 struct MPT2SAS_TARGET
*sas_target_priv_data
;
4528 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
4529 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
)))
4532 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
4533 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
4536 /* check if this is end device */
4537 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
4538 if (!(_scsih_is_end_device(device_info
)))
4541 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4542 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
4543 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
4547 printk(MPT2SAS_ERR_FMT
"device is not present "
4548 "handle(0x%04x), no sas_device!!!\n", ioc
->name
, handle
);
4549 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4553 if (unlikely(sas_device
->handle
!= handle
)) {
4554 starget
= sas_device
->starget
;
4555 sas_target_priv_data
= starget
->hostdata
;
4556 starget_printk(KERN_INFO
, starget
, "handle changed from(0x%04x)"
4557 " to (0x%04x)!!!\n", sas_device
->handle
, handle
);
4558 sas_target_priv_data
->handle
= handle
;
4559 sas_device
->handle
= handle
;
4561 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4563 /* check if device is present */
4564 if (!(le16_to_cpu(sas_device_pg0
.Flags
) &
4565 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT
)) {
4566 printk(MPT2SAS_ERR_FMT
"device is not present "
4567 "handle(0x%04x), flags!!!\n", ioc
->name
, handle
);
4571 /* check if there were any issues with discovery */
4572 if (_scsih_check_access_status(ioc
, sas_address
, handle
,
4573 sas_device_pg0
.AccessStatus
))
4575 _scsih_ublock_io_device(ioc
, handle
);
4580 * _scsih_add_device - creating sas device object
4581 * @ioc: per adapter object
4582 * @handle: sas device handle
4583 * @phy_num: phy number end device attached to
4584 * @is_pd: is this hidden raid component
4586 * Creating end device object, stored in ioc->sas_device_list.
4588 * Returns 0 for success, non-zero for failure.
4591 _scsih_add_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
, u8 phy_num
, u8 is_pd
)
4593 Mpi2ConfigReply_t mpi_reply
;
4594 Mpi2SasDevicePage0_t sas_device_pg0
;
4595 Mpi2SasEnclosurePage0_t enclosure_pg0
;
4596 struct _sas_device
*sas_device
;
4600 unsigned long flags
;
4602 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
4603 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
4604 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4605 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4609 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4610 MPI2_IOCSTATUS_MASK
;
4611 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4612 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4613 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4617 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
4619 /* check if device is present */
4620 if (!(le16_to_cpu(sas_device_pg0
.Flags
) &
4621 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT
)) {
4622 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4623 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4624 printk(MPT2SAS_ERR_FMT
"Flags = 0x%04x\n",
4625 ioc
->name
, le16_to_cpu(sas_device_pg0
.Flags
));
4629 /* check if there were any issues with discovery */
4630 if (_scsih_check_access_status(ioc
, sas_address
, handle
,
4631 sas_device_pg0
.AccessStatus
))
4634 /* check if this is end device */
4635 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
4636 if (!(_scsih_is_end_device(device_info
))) {
4637 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4638 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4643 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4644 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
4646 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4651 sas_device
= kzalloc(sizeof(struct _sas_device
),
4654 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4655 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4659 sas_device
->handle
= handle
;
4660 if (_scsih_get_sas_address(ioc
, le16_to_cpu
4661 (sas_device_pg0
.ParentDevHandle
),
4662 &sas_device
->sas_address_parent
) != 0)
4663 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4664 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4665 sas_device
->enclosure_handle
=
4666 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
4668 le16_to_cpu(sas_device_pg0
.Slot
);
4669 sas_device
->device_info
= device_info
;
4670 sas_device
->sas_address
= sas_address
;
4671 sas_device
->phy
= sas_device_pg0
.PhyNum
;
4673 /* get enclosure_logical_id */
4674 if (sas_device
->enclosure_handle
&& !(mpt2sas_config_get_enclosure_pg0(
4675 ioc
, &mpi_reply
, &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
4676 sas_device
->enclosure_handle
)))
4677 sas_device
->enclosure_logical_id
=
4678 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
4680 /* get device name */
4681 sas_device
->device_name
= le64_to_cpu(sas_device_pg0
.DeviceName
);
4683 if (ioc
->wait_for_port_enable_to_complete
)
4684 _scsih_sas_device_init_add(ioc
, sas_device
);
4686 _scsih_sas_device_add(ioc
, sas_device
);
4692 * _scsih_remove_device - removing sas device object
4693 * @ioc: per adapter object
4694 * @sas_device_delete: the sas_device object
4699 _scsih_remove_device(struct MPT2SAS_ADAPTER
*ioc
,
4700 struct _sas_device
*sas_device
)
4702 struct _sas_device sas_device_backup
;
4703 struct MPT2SAS_TARGET
*sas_target_priv_data
;
4708 memcpy(&sas_device_backup
, sas_device
, sizeof(struct _sas_device
));
4709 _scsih_sas_device_remove(ioc
, sas_device
);
4711 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: enter: "
4712 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
, __func__
,
4713 sas_device_backup
.handle
, (unsigned long long)
4714 sas_device_backup
.sas_address
));
4716 if (sas_device_backup
.starget
&& sas_device_backup
.starget
->hostdata
) {
4717 sas_target_priv_data
= sas_device_backup
.starget
->hostdata
;
4718 sas_target_priv_data
->deleted
= 1;
4721 _scsih_ublock_io_device(ioc
, sas_device_backup
.handle
);
4723 mpt2sas_transport_port_remove(ioc
, sas_device_backup
.sas_address
,
4724 sas_device_backup
.sas_address_parent
);
4726 printk(MPT2SAS_INFO_FMT
"removing handle(0x%04x), sas_addr"
4727 "(0x%016llx)\n", ioc
->name
, sas_device_backup
.handle
,
4728 (unsigned long long) sas_device_backup
.sas_address
);
4730 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: exit: "
4731 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
, __func__
,
4732 sas_device_backup
.handle
, (unsigned long long)
4733 sas_device_backup
.sas_address
));
4737 * mpt2sas_device_remove - removing device object
4738 * @ioc: per adapter object
4739 * @sas_address: expander sas_address
4744 mpt2sas_device_remove(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
)
4746 struct _sas_device
*sas_device
;
4747 unsigned long flags
;
4749 if (ioc
->shost_recovery
)
4752 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4753 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
4756 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4759 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4760 _scsih_remove_device(ioc
, sas_device
);
4763 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4765 * _scsih_sas_topology_change_event_debug - debug for topology event
4766 * @ioc: per adapter object
4767 * @event_data: event data payload
4771 _scsih_sas_topology_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
4772 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
4778 char *status_str
= NULL
;
4779 u8 link_rate
, prev_link_rate
;
4781 switch (event_data
->ExpStatus
) {
4782 case MPI2_EVENT_SAS_TOPO_ES_ADDED
:
4785 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
:
4786 status_str
= "remove";
4788 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING
:
4790 status_str
= "responding";
4792 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
:
4793 status_str
= "remove delay";
4796 status_str
= "unknown status";
4799 printk(MPT2SAS_INFO_FMT
"sas topology change: (%s)\n",
4800 ioc
->name
, status_str
);
4801 printk(KERN_INFO
"\thandle(0x%04x), enclosure_handle(0x%04x) "
4802 "start_phy(%02d), count(%d)\n",
4803 le16_to_cpu(event_data
->ExpanderDevHandle
),
4804 le16_to_cpu(event_data
->EnclosureHandle
),
4805 event_data
->StartPhyNum
, event_data
->NumEntries
);
4806 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
4807 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
4810 phy_number
= event_data
->StartPhyNum
+ i
;
4811 reason_code
= event_data
->PHY
[i
].PhyStatus
&
4812 MPI2_EVENT_SAS_TOPO_RC_MASK
;
4813 switch (reason_code
) {
4814 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
4815 status_str
= "target add";
4817 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
4818 status_str
= "target remove";
4820 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
:
4821 status_str
= "delay target remove";
4823 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
4824 status_str
= "link rate change";
4826 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE
:
4827 status_str
= "target responding";
4830 status_str
= "unknown";
4833 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
4834 prev_link_rate
= event_data
->PHY
[i
].LinkRate
& 0xF;
4835 printk(KERN_INFO
"\tphy(%02d), attached_handle(0x%04x): %s:"
4836 " link rate: new(0x%02x), old(0x%02x)\n", phy_number
,
4837 handle
, status_str
, link_rate
, prev_link_rate
);
4844 * _scsih_sas_topology_change_event - handle topology changes
4845 * @ioc: per adapter object
4846 * @fw_event: The fw_event_work object
4851 _scsih_sas_topology_change_event(struct MPT2SAS_ADAPTER
*ioc
,
4852 struct fw_event_work
*fw_event
)
4855 u16 parent_handle
, handle
;
4857 u8 phy_number
, max_phys
;
4858 struct _sas_node
*sas_expander
;
4859 struct _sas_device
*sas_device
;
4861 unsigned long flags
;
4862 u8 link_rate
, prev_link_rate
;
4863 Mpi2EventDataSasTopologyChangeList_t
*event_data
= fw_event
->event_data
;
4865 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4866 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
4867 _scsih_sas_topology_change_event_debug(ioc
, event_data
);
4870 if (ioc
->shost_recovery
|| ioc
->remove_host
|| ioc
->pci_error_recovery
)
4873 if (!ioc
->sas_hba
.num_phys
)
4874 _scsih_sas_host_add(ioc
);
4876 _scsih_sas_host_refresh(ioc
);
4878 if (fw_event
->ignore
) {
4879 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"ignoring expander "
4880 "event\n", ioc
->name
));
4884 parent_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
4886 /* handle expander add */
4887 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_ADDED
)
4888 if (_scsih_expander_add(ioc
, parent_handle
) != 0)
4891 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
4892 sas_expander
= mpt2sas_scsih_expander_find_by_handle(ioc
,
4894 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
4896 sas_address
= sas_expander
->sas_address
;
4897 max_phys
= sas_expander
->num_phys
;
4898 } else if (parent_handle
< ioc
->sas_hba
.num_phys
) {
4899 sas_address
= ioc
->sas_hba
.sas_address
;
4900 max_phys
= ioc
->sas_hba
.num_phys
;
4904 /* handle siblings events */
4905 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
4906 if (fw_event
->ignore
) {
4907 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"ignoring "
4908 "expander event\n", ioc
->name
));
4911 if (ioc
->shost_recovery
|| ioc
->remove_host
||
4912 ioc
->pci_error_recovery
)
4914 phy_number
= event_data
->StartPhyNum
+ i
;
4915 if (phy_number
>= max_phys
)
4917 reason_code
= event_data
->PHY
[i
].PhyStatus
&
4918 MPI2_EVENT_SAS_TOPO_RC_MASK
;
4919 if ((event_data
->PHY
[i
].PhyStatus
&
4920 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT
) && (reason_code
!=
4921 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
))
4923 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
4926 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
4927 prev_link_rate
= event_data
->PHY
[i
].LinkRate
& 0xF;
4928 switch (reason_code
) {
4929 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
4931 if (link_rate
== prev_link_rate
)
4934 mpt2sas_transport_update_links(ioc
, sas_address
,
4935 handle
, phy_number
, link_rate
);
4937 if (link_rate
< MPI2_SAS_NEG_LINK_RATE_1_5
)
4940 _scsih_check_device(ioc
, handle
);
4942 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
4944 mpt2sas_transport_update_links(ioc
, sas_address
,
4945 handle
, phy_number
, link_rate
);
4947 _scsih_add_device(ioc
, handle
, phy_number
, 0);
4949 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
4951 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4952 sas_device
= _scsih_sas_device_find_by_handle(ioc
,
4955 spin_unlock_irqrestore(&ioc
->sas_device_lock
,
4959 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4960 _scsih_remove_device(ioc
, sas_device
);
4965 /* handle expander removal */
4966 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
&&
4968 mpt2sas_expander_remove(ioc
, sas_address
);
4972 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4974 * _scsih_sas_device_status_change_event_debug - debug for device event
4975 * @event_data: event data payload
4981 _scsih_sas_device_status_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
4982 Mpi2EventDataSasDeviceStatusChange_t
*event_data
)
4984 char *reason_str
= NULL
;
4986 switch (event_data
->ReasonCode
) {
4987 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
:
4988 reason_str
= "smart data";
4990 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED
:
4991 reason_str
= "unsupported device discovered";
4993 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
:
4994 reason_str
= "internal device reset";
4996 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL
:
4997 reason_str
= "internal task abort";
4999 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL
:
5000 reason_str
= "internal task abort set";
5002 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL
:
5003 reason_str
= "internal clear task set";
5005 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL
:
5006 reason_str
= "internal query task";
5008 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE
:
5009 reason_str
= "sata init failure";
5011 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
:
5012 reason_str
= "internal device reset complete";
5014 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL
:
5015 reason_str
= "internal task abort complete";
5017 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION
:
5018 reason_str
= "internal async notification";
5020 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY
:
5021 reason_str
= "expander reduced functionality";
5023 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY
:
5024 reason_str
= "expander reduced functionality complete";
5027 reason_str
= "unknown reason";
5030 printk(MPT2SAS_INFO_FMT
"device status change: (%s)\n"
5031 "\thandle(0x%04x), sas address(0x%016llx)", ioc
->name
,
5032 reason_str
, le16_to_cpu(event_data
->DevHandle
),
5033 (unsigned long long)le64_to_cpu(event_data
->SASAddress
));
5034 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
)
5035 printk(MPT2SAS_INFO_FMT
", ASC(0x%x), ASCQ(0x%x)\n", ioc
->name
,
5036 event_data
->ASC
, event_data
->ASCQ
);
5037 printk(KERN_INFO
"\n");
5042 * _scsih_sas_device_status_change_event - handle device status change
5043 * @ioc: per adapter object
5044 * @fw_event: The fw_event_work object
5050 _scsih_sas_device_status_change_event(struct MPT2SAS_ADAPTER
*ioc
,
5051 struct fw_event_work
*fw_event
)
5053 struct MPT2SAS_TARGET
*target_priv_data
;
5054 struct _sas_device
*sas_device
;
5056 unsigned long flags
;
5057 Mpi2EventDataSasDeviceStatusChange_t
*event_data
=
5058 fw_event
->event_data
;
5060 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5061 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5062 _scsih_sas_device_status_change_event_debug(ioc
,
5066 /* In MPI Revision K (0xC), the internal device reset complete was
5067 * implemented, so avoid setting tm_busy flag for older firmware.
5069 if ((ioc
->facts
.HeaderVersion
>> 8) < 0xC)
5072 if (event_data
->ReasonCode
!=
5073 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
&&
5074 event_data
->ReasonCode
!=
5075 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
)
5078 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5079 sas_address
= le64_to_cpu(event_data
->SASAddress
);
5080 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
5082 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5084 if (!sas_device
|| !sas_device
->starget
)
5087 target_priv_data
= sas_device
->starget
->hostdata
;
5088 if (!target_priv_data
)
5091 if (event_data
->ReasonCode
==
5092 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
)
5093 target_priv_data
->tm_busy
= 1;
5095 target_priv_data
->tm_busy
= 0;
5098 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5100 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure event
5101 * @ioc: per adapter object
5102 * @event_data: event data payload
5108 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
5109 Mpi2EventDataSasEnclDevStatusChange_t
*event_data
)
5111 char *reason_str
= NULL
;
5113 switch (event_data
->ReasonCode
) {
5114 case MPI2_EVENT_SAS_ENCL_RC_ADDED
:
5115 reason_str
= "enclosure add";
5117 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING
:
5118 reason_str
= "enclosure remove";
5121 reason_str
= "unknown reason";
5125 printk(MPT2SAS_INFO_FMT
"enclosure status change: (%s)\n"
5126 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
5127 " number slots(%d)\n", ioc
->name
, reason_str
,
5128 le16_to_cpu(event_data
->EnclosureHandle
),
5129 (unsigned long long)le64_to_cpu(event_data
->EnclosureLogicalID
),
5130 le16_to_cpu(event_data
->StartSlot
));
5135 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
5136 * @ioc: per adapter object
5137 * @fw_event: The fw_event_work object
5143 _scsih_sas_enclosure_dev_status_change_event(struct MPT2SAS_ADAPTER
*ioc
,
5144 struct fw_event_work
*fw_event
)
5146 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5147 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5148 _scsih_sas_enclosure_dev_status_change_event_debug(ioc
,
5149 fw_event
->event_data
);
5154 * _scsih_sas_broadcast_primative_event - handle broadcast events
5155 * @ioc: per adapter object
5156 * @fw_event: The fw_event_work object
5162 _scsih_sas_broadcast_primative_event(struct MPT2SAS_ADAPTER
*ioc
,
5163 struct fw_event_work
*fw_event
)
5165 struct scsi_cmnd
*scmd
;
5166 struct scsi_device
*sdev
;
5169 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
5170 u32 termination_count
;
5172 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
5173 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5174 Mpi2EventDataSasBroadcastPrimitive_t
*event_data
= fw_event
->event_data
;
5177 unsigned long flags
;
5180 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"broadcast primative: "
5181 "phy number(%d), width(%d)\n", ioc
->name
, event_data
->PhyNum
,
5182 event_data
->PortWidth
));
5183 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: enter\n", ioc
->name
,
5186 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
5187 ioc
->broadcast_aen_busy
= 0;
5188 termination_count
= 0;
5190 mpi_reply
= ioc
->tm_cmds
.reply
;
5191 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
5192 scmd
= _scsih_scsi_lookup_get(ioc
, smid
);
5195 sdev
= scmd
->device
;
5196 sas_device_priv_data
= sdev
->hostdata
;
5197 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
)
5199 /* skip hidden raid components */
5200 if (sas_device_priv_data
->sas_target
->flags
&
5201 MPT_TARGET_FLAGS_RAID_COMPONENT
)
5204 if (sas_device_priv_data
->sas_target
->flags
&
5205 MPT_TARGET_FLAGS_VOLUME
)
5208 handle
= sas_device_priv_data
->sas_target
->handle
;
5209 lun
= sas_device_priv_data
->lun
;
5212 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
5213 mpt2sas_scsih_issue_tm(ioc
, handle
, 0, 0, lun
,
5214 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK
, smid
, 30, NULL
);
5215 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
5216 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
)
5217 & MPI2_IOCSTATUS_MASK
;
5218 if ((ioc_status
== MPI2_IOCSTATUS_SUCCESS
) &&
5219 (mpi_reply
->ResponseCode
==
5220 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
||
5221 mpi_reply
->ResponseCode
==
5222 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
)) {
5223 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
5226 r
= mpt2sas_scsih_issue_tm(ioc
, handle
, sdev
->channel
, sdev
->id
,
5227 sdev
->lun
, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
, smid
, 30,
5230 sdev_printk(KERN_WARNING
, sdev
, "task abort: FAILED "
5231 "scmd(%p)\n", scmd
);
5232 termination_count
+= le32_to_cpu(mpi_reply
->TerminationCount
);
5233 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
5235 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
5237 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
5238 "%s - exit, query_count = %d termination_count = %d\n",
5239 ioc
->name
, __func__
, query_count
, termination_count
));
5243 * _scsih_sas_discovery_event - handle discovery events
5244 * @ioc: per adapter object
5245 * @fw_event: The fw_event_work object
5251 _scsih_sas_discovery_event(struct MPT2SAS_ADAPTER
*ioc
,
5252 struct fw_event_work
*fw_event
)
5254 Mpi2EventDataSasDiscovery_t
*event_data
= fw_event
->event_data
;
5256 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5257 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
) {
5258 printk(MPT2SAS_INFO_FMT
"discovery event: (%s)", ioc
->name
,
5259 (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
) ?
5261 if (event_data
->DiscoveryStatus
)
5262 printk("discovery_status(0x%08x)",
5263 le32_to_cpu(event_data
->DiscoveryStatus
));
5268 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
&&
5269 !ioc
->sas_hba
.num_phys
)
5270 _scsih_sas_host_add(ioc
);
5274 * _scsih_reprobe_lun - reprobing lun
5275 * @sdev: scsi device struct
5276 * @no_uld_attach: sdev->no_uld_attach flag setting
5280 _scsih_reprobe_lun(struct scsi_device
*sdev
, void *no_uld_attach
)
5284 sdev
->no_uld_attach
= no_uld_attach
? 1 : 0;
5285 sdev_printk(KERN_INFO
, sdev
, "%s raid component\n",
5286 sdev
->no_uld_attach
? "hidding" : "exposing");
5287 rc
= scsi_device_reprobe(sdev
);
5291 * _scsih_reprobe_target - reprobing target
5292 * @starget: scsi target struct
5293 * @no_uld_attach: sdev->no_uld_attach flag setting
5295 * Note: no_uld_attach flag determines whether the disk device is attached
5296 * to block layer. A value of `1` means to not attach.
5299 _scsih_reprobe_target(struct scsi_target
*starget
, int no_uld_attach
)
5301 struct MPT2SAS_TARGET
*sas_target_priv_data
= starget
->hostdata
;
5304 sas_target_priv_data
->flags
|= MPT_TARGET_FLAGS_RAID_COMPONENT
;
5306 sas_target_priv_data
->flags
&= ~MPT_TARGET_FLAGS_RAID_COMPONENT
;
5308 starget_for_each_device(starget
, no_uld_attach
? (void *)1 : NULL
,
5309 _scsih_reprobe_lun
);
5312 * _scsih_sas_volume_add - add new volume
5313 * @ioc: per adapter object
5314 * @element: IR config element data
5320 _scsih_sas_volume_add(struct MPT2SAS_ADAPTER
*ioc
,
5321 Mpi2EventIrConfigElement_t
*element
)
5323 struct _raid_device
*raid_device
;
5324 unsigned long flags
;
5326 u16 handle
= le16_to_cpu(element
->VolDevHandle
);
5329 mpt2sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
5331 printk(MPT2SAS_ERR_FMT
5332 "failure at %s:%d/%s()!\n", ioc
->name
,
5333 __FILE__
, __LINE__
, __func__
);
5337 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5338 raid_device
= _scsih_raid_device_find_by_wwid(ioc
, wwid
);
5339 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5344 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
5346 printk(MPT2SAS_ERR_FMT
5347 "failure at %s:%d/%s()!\n", ioc
->name
,
5348 __FILE__
, __LINE__
, __func__
);
5352 raid_device
->id
= ioc
->sas_id
++;
5353 raid_device
->channel
= RAID_CHANNEL
;
5354 raid_device
->handle
= handle
;
5355 raid_device
->wwid
= wwid
;
5356 _scsih_raid_device_add(ioc
, raid_device
);
5357 if (!ioc
->wait_for_port_enable_to_complete
) {
5358 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
5359 raid_device
->id
, 0);
5361 _scsih_raid_device_remove(ioc
, raid_device
);
5363 _scsih_determine_boot_device(ioc
, raid_device
, 1);
5367 * _scsih_sas_volume_delete - delete volume
5368 * @ioc: per adapter object
5369 * @handle: volume device handle
5375 _scsih_sas_volume_delete(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
5377 struct _raid_device
*raid_device
;
5378 unsigned long flags
;
5379 struct MPT2SAS_TARGET
*sas_target_priv_data
;
5381 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5382 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
5383 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5386 if (raid_device
->starget
) {
5387 sas_target_priv_data
= raid_device
->starget
->hostdata
;
5388 sas_target_priv_data
->deleted
= 1;
5389 scsi_remove_target(&raid_device
->starget
->dev
);
5391 printk(MPT2SAS_INFO_FMT
"removing handle(0x%04x), wwid"
5392 "(0x%016llx)\n", ioc
->name
, raid_device
->handle
,
5393 (unsigned long long) raid_device
->wwid
);
5394 _scsih_raid_device_remove(ioc
, raid_device
);
5398 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
5399 * @ioc: per adapter object
5400 * @element: IR config element data
5406 _scsih_sas_pd_expose(struct MPT2SAS_ADAPTER
*ioc
,
5407 Mpi2EventIrConfigElement_t
*element
)
5409 struct _sas_device
*sas_device
;
5410 unsigned long flags
;
5411 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
5413 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5414 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
5415 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5419 /* exposing raid component */
5420 sas_device
->volume_handle
= 0;
5421 sas_device
->volume_wwid
= 0;
5422 clear_bit(handle
, ioc
->pd_handles
);
5423 _scsih_reprobe_target(sas_device
->starget
, 0);
5427 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
5428 * @ioc: per adapter object
5429 * @element: IR config element data
5435 _scsih_sas_pd_hide(struct MPT2SAS_ADAPTER
*ioc
,
5436 Mpi2EventIrConfigElement_t
*element
)
5438 struct _sas_device
*sas_device
;
5439 unsigned long flags
;
5440 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
5442 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5443 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
5444 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5448 /* hiding raid component */
5449 mpt2sas_config_get_volume_handle(ioc
, handle
,
5450 &sas_device
->volume_handle
);
5451 mpt2sas_config_get_volume_wwid(ioc
, sas_device
->volume_handle
,
5452 &sas_device
->volume_wwid
);
5453 set_bit(handle
, ioc
->pd_handles
);
5454 _scsih_reprobe_target(sas_device
->starget
, 1);
5458 * _scsih_sas_pd_delete - delete pd component
5459 * @ioc: per adapter object
5460 * @element: IR config element data
5466 _scsih_sas_pd_delete(struct MPT2SAS_ADAPTER
*ioc
,
5467 Mpi2EventIrConfigElement_t
*element
)
5469 struct _sas_device
*sas_device
;
5470 unsigned long flags
;
5471 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
5473 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5474 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
5475 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5478 _scsih_remove_device(ioc
, sas_device
);
5482 * _scsih_sas_pd_add - remove pd component
5483 * @ioc: per adapter object
5484 * @element: IR config element data
5490 _scsih_sas_pd_add(struct MPT2SAS_ADAPTER
*ioc
,
5491 Mpi2EventIrConfigElement_t
*element
)
5493 struct _sas_device
*sas_device
;
5494 unsigned long flags
;
5495 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
5496 Mpi2ConfigReply_t mpi_reply
;
5497 Mpi2SasDevicePage0_t sas_device_pg0
;
5502 set_bit(handle
, ioc
->pd_handles
);
5504 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5505 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
5506 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5510 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
5511 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
5512 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5513 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5517 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5518 MPI2_IOCSTATUS_MASK
;
5519 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5520 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5521 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5525 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
5526 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
5527 mpt2sas_transport_update_links(ioc
, sas_address
, handle
,
5528 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
5530 _scsih_add_device(ioc
, handle
, 0, 1);
5533 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5535 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
5536 * @ioc: per adapter object
5537 * @event_data: event data payload
5543 _scsih_sas_ir_config_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
5544 Mpi2EventDataIrConfigChangeList_t
*event_data
)
5546 Mpi2EventIrConfigElement_t
*element
;
5549 char *reason_str
= NULL
, *element_str
= NULL
;
5551 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
5553 printk(MPT2SAS_INFO_FMT
"raid config change: (%s), elements(%d)\n",
5554 ioc
->name
, (le32_to_cpu(event_data
->Flags
) &
5555 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ?
5556 "foreign" : "native", event_data
->NumElements
);
5557 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
5558 switch (element
->ReasonCode
) {
5559 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
5562 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
5563 reason_str
= "remove";
5565 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE
:
5566 reason_str
= "no change";
5568 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
5569 reason_str
= "hide";
5571 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
5572 reason_str
= "unhide";
5574 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
5575 reason_str
= "volume_created";
5577 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
5578 reason_str
= "volume_deleted";
5580 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
5581 reason_str
= "pd_created";
5583 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
5584 reason_str
= "pd_deleted";
5587 reason_str
= "unknown reason";
5590 element_type
= le16_to_cpu(element
->ElementFlags
) &
5591 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK
;
5592 switch (element_type
) {
5593 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT
:
5594 element_str
= "volume";
5596 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT
:
5597 element_str
= "phys disk";
5599 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT
:
5600 element_str
= "hot spare";
5603 element_str
= "unknown element";
5606 printk(KERN_INFO
"\t(%s:%s), vol handle(0x%04x), "
5607 "pd handle(0x%04x), pd num(0x%02x)\n", element_str
,
5608 reason_str
, le16_to_cpu(element
->VolDevHandle
),
5609 le16_to_cpu(element
->PhysDiskDevHandle
),
5610 element
->PhysDiskNum
);
5616 * _scsih_sas_ir_config_change_event - handle ir configuration change events
5617 * @ioc: per adapter object
5618 * @fw_event: The fw_event_work object
5624 _scsih_sas_ir_config_change_event(struct MPT2SAS_ADAPTER
*ioc
,
5625 struct fw_event_work
*fw_event
)
5627 Mpi2EventIrConfigElement_t
*element
;
5630 Mpi2EventDataIrConfigChangeList_t
*event_data
= fw_event
->event_data
;
5632 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5633 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5634 _scsih_sas_ir_config_change_event_debug(ioc
, event_data
);
5637 foreign_config
= (le32_to_cpu(event_data
->Flags
) &
5638 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ? 1 : 0;
5640 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
5641 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
5643 switch (element
->ReasonCode
) {
5644 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
5645 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
5646 if (!foreign_config
)
5647 _scsih_sas_volume_add(ioc
, element
);
5649 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
5650 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
5651 if (!foreign_config
)
5652 _scsih_sas_volume_delete(ioc
,
5653 le16_to_cpu(element
->VolDevHandle
));
5655 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
5656 _scsih_sas_pd_hide(ioc
, element
);
5658 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
5659 _scsih_sas_pd_expose(ioc
, element
);
5661 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
5662 _scsih_sas_pd_add(ioc
, element
);
5664 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
5665 _scsih_sas_pd_delete(ioc
, element
);
5672 * _scsih_sas_ir_volume_event - IR volume event
5673 * @ioc: per adapter object
5674 * @fw_event: The fw_event_work object
5680 _scsih_sas_ir_volume_event(struct MPT2SAS_ADAPTER
*ioc
,
5681 struct fw_event_work
*fw_event
)
5684 unsigned long flags
;
5685 struct _raid_device
*raid_device
;
5689 Mpi2EventDataIrVolume_t
*event_data
= fw_event
->event_data
;
5691 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED
)
5694 handle
= le16_to_cpu(event_data
->VolDevHandle
);
5695 state
= le32_to_cpu(event_data
->NewValue
);
5696 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: handle(0x%04x), "
5697 "old(0x%08x), new(0x%08x)\n", ioc
->name
, __func__
, handle
,
5698 le32_to_cpu(event_data
->PreviousValue
), state
));
5701 case MPI2_RAID_VOL_STATE_MISSING
:
5702 case MPI2_RAID_VOL_STATE_FAILED
:
5703 _scsih_sas_volume_delete(ioc
, handle
);
5706 case MPI2_RAID_VOL_STATE_ONLINE
:
5707 case MPI2_RAID_VOL_STATE_DEGRADED
:
5708 case MPI2_RAID_VOL_STATE_OPTIMAL
:
5710 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5711 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
5712 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5717 mpt2sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
5719 printk(MPT2SAS_ERR_FMT
5720 "failure at %s:%d/%s()!\n", ioc
->name
,
5721 __FILE__
, __LINE__
, __func__
);
5725 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
5727 printk(MPT2SAS_ERR_FMT
5728 "failure at %s:%d/%s()!\n", ioc
->name
,
5729 __FILE__
, __LINE__
, __func__
);
5733 raid_device
->id
= ioc
->sas_id
++;
5734 raid_device
->channel
= RAID_CHANNEL
;
5735 raid_device
->handle
= handle
;
5736 raid_device
->wwid
= wwid
;
5737 _scsih_raid_device_add(ioc
, raid_device
);
5738 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
5739 raid_device
->id
, 0);
5741 _scsih_raid_device_remove(ioc
, raid_device
);
5744 case MPI2_RAID_VOL_STATE_INITIALIZING
:
5751 * _scsih_sas_ir_physical_disk_event - PD event
5752 * @ioc: per adapter object
5753 * @fw_event: The fw_event_work object
5759 _scsih_sas_ir_physical_disk_event(struct MPT2SAS_ADAPTER
*ioc
,
5760 struct fw_event_work
*fw_event
)
5762 u16 handle
, parent_handle
;
5764 struct _sas_device
*sas_device
;
5765 unsigned long flags
;
5766 Mpi2ConfigReply_t mpi_reply
;
5767 Mpi2SasDevicePage0_t sas_device_pg0
;
5769 Mpi2EventDataIrPhysicalDisk_t
*event_data
= fw_event
->event_data
;
5772 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED
)
5775 handle
= le16_to_cpu(event_data
->PhysDiskDevHandle
);
5776 state
= le32_to_cpu(event_data
->NewValue
);
5778 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: handle(0x%04x), "
5779 "old(0x%08x), new(0x%08x)\n", ioc
->name
, __func__
, handle
,
5780 le32_to_cpu(event_data
->PreviousValue
), state
));
5783 case MPI2_RAID_PD_STATE_ONLINE
:
5784 case MPI2_RAID_PD_STATE_DEGRADED
:
5785 case MPI2_RAID_PD_STATE_REBUILDING
:
5786 case MPI2_RAID_PD_STATE_OPTIMAL
:
5787 case MPI2_RAID_PD_STATE_HOT_SPARE
:
5789 set_bit(handle
, ioc
->pd_handles
);
5791 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5792 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
5793 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5798 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
5799 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
5801 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5802 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5806 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5807 MPI2_IOCSTATUS_MASK
;
5808 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5809 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5810 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5814 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
5815 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
5816 mpt2sas_transport_update_links(ioc
, sas_address
, handle
,
5817 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
5819 _scsih_add_device(ioc
, handle
, 0, 1);
5823 case MPI2_RAID_PD_STATE_OFFLINE
:
5824 case MPI2_RAID_PD_STATE_NOT_CONFIGURED
:
5825 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE
:
5831 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5833 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
5834 * @ioc: per adapter object
5835 * @event_data: event data payload
5841 _scsih_sas_ir_operation_status_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
5842 Mpi2EventDataIrOperationStatus_t
*event_data
)
5844 char *reason_str
= NULL
;
5846 switch (event_data
->RAIDOperation
) {
5847 case MPI2_EVENT_IR_RAIDOP_RESYNC
:
5848 reason_str
= "resync";
5850 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION
:
5851 reason_str
= "online capacity expansion";
5853 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK
:
5854 reason_str
= "consistency check";
5856 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT
:
5857 reason_str
= "background init";
5859 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT
:
5860 reason_str
= "make data consistent";
5867 printk(MPT2SAS_INFO_FMT
"raid operational status: (%s)"
5868 "\thandle(0x%04x), percent complete(%d)\n",
5869 ioc
->name
, reason_str
,
5870 le16_to_cpu(event_data
->VolDevHandle
),
5871 event_data
->PercentComplete
);
5876 * _scsih_sas_ir_operation_status_event - handle RAID operation events
5877 * @ioc: per adapter object
5878 * @fw_event: The fw_event_work object
5884 _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER
*ioc
,
5885 struct fw_event_work
*fw_event
)
5887 Mpi2EventDataIrOperationStatus_t
*event_data
= fw_event
->event_data
;
5888 static struct _raid_device
*raid_device
;
5889 unsigned long flags
;
5892 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5893 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5894 _scsih_sas_ir_operation_status_event_debug(ioc
,
5898 /* code added for raid transport support */
5899 if (event_data
->RAIDOperation
== MPI2_EVENT_IR_RAIDOP_RESYNC
) {
5901 handle
= le16_to_cpu(event_data
->VolDevHandle
);
5903 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5904 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
5905 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5910 if (event_data
->RAIDOperation
== MPI2_EVENT_IR_RAIDOP_RESYNC
)
5911 raid_device
->percent_complete
=
5912 event_data
->PercentComplete
;
5917 * _scsih_prep_device_scan - initialize parameters prior to device scan
5918 * @ioc: per adapter object
5920 * Set the deleted flag prior to device scan. If the device is found during
5921 * the scan, then we clear the deleted flag.
5924 _scsih_prep_device_scan(struct MPT2SAS_ADAPTER
*ioc
)
5926 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
5927 struct scsi_device
*sdev
;
5929 shost_for_each_device(sdev
, ioc
->shost
) {
5930 sas_device_priv_data
= sdev
->hostdata
;
5931 if (sas_device_priv_data
&& sas_device_priv_data
->sas_target
)
5932 sas_device_priv_data
->sas_target
->deleted
= 1;
5937 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
5938 * @ioc: per adapter object
5939 * @sas_address: sas address
5940 * @slot: enclosure slot id
5941 * @handle: device handle
5943 * After host reset, find out whether devices are still responding.
5944 * Used in _scsi_remove_unresponsive_sas_devices.
5949 _scsih_mark_responding_sas_device(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
,
5950 u16 slot
, u16 handle
)
5952 struct MPT2SAS_TARGET
*sas_target_priv_data
;
5953 struct scsi_target
*starget
;
5954 struct _sas_device
*sas_device
;
5955 unsigned long flags
;
5957 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5958 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
) {
5959 if (sas_device
->sas_address
== sas_address
&&
5960 sas_device
->slot
== slot
&& sas_device
->starget
) {
5961 sas_device
->responding
= 1;
5962 starget
= sas_device
->starget
;
5963 if (starget
&& starget
->hostdata
) {
5964 sas_target_priv_data
= starget
->hostdata
;
5965 sas_target_priv_data
->tm_busy
= 0;
5966 sas_target_priv_data
->deleted
= 0;
5968 sas_target_priv_data
= NULL
;
5969 starget_printk(KERN_INFO
, sas_device
->starget
,
5970 "handle(0x%04x), sas_addr(0x%016llx), enclosure "
5971 "logical id(0x%016llx), slot(%d)\n", handle
,
5972 (unsigned long long)sas_device
->sas_address
,
5973 (unsigned long long)
5974 sas_device
->enclosure_logical_id
,
5976 if (sas_device
->handle
== handle
)
5978 printk(KERN_INFO
"\thandle changed from(0x%04x)!!!\n",
5979 sas_device
->handle
);
5980 sas_device
->handle
= handle
;
5981 if (sas_target_priv_data
)
5982 sas_target_priv_data
->handle
= handle
;
5987 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5991 * _scsih_search_responding_sas_devices -
5992 * @ioc: per adapter object
5994 * After host reset, find out whether devices are still responding.
6000 _scsih_search_responding_sas_devices(struct MPT2SAS_ADAPTER
*ioc
)
6002 Mpi2SasDevicePage0_t sas_device_pg0
;
6003 Mpi2ConfigReply_t mpi_reply
;
6010 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
, __func__
);
6012 if (list_empty(&ioc
->sas_device_list
))
6016 while (!(mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
6017 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
,
6019 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6020 MPI2_IOCSTATUS_MASK
;
6021 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
6023 handle
= le16_to_cpu(sas_device_pg0
.DevHandle
);
6024 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
6025 if (!(_scsih_is_end_device(device_info
)))
6027 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
6028 slot
= le16_to_cpu(sas_device_pg0
.Slot
);
6029 _scsih_mark_responding_sas_device(ioc
, sas_address
, slot
,
6035 * _scsih_mark_responding_raid_device - mark a raid_device as responding
6036 * @ioc: per adapter object
6037 * @wwid: world wide identifier for raid volume
6038 * @handle: device handle
6040 * After host reset, find out whether devices are still responding.
6041 * Used in _scsi_remove_unresponsive_raid_devices.
6046 _scsih_mark_responding_raid_device(struct MPT2SAS_ADAPTER
*ioc
, u64 wwid
,
6049 struct MPT2SAS_TARGET
*sas_target_priv_data
;
6050 struct scsi_target
*starget
;
6051 struct _raid_device
*raid_device
;
6052 unsigned long flags
;
6054 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6055 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
6056 if (raid_device
->wwid
== wwid
&& raid_device
->starget
) {
6057 starget
= raid_device
->starget
;
6058 if (starget
&& starget
->hostdata
) {
6059 sas_target_priv_data
= starget
->hostdata
;
6060 sas_target_priv_data
->deleted
= 0;
6062 sas_target_priv_data
= NULL
;
6063 raid_device
->responding
= 1;
6064 starget_printk(KERN_INFO
, raid_device
->starget
,
6065 "handle(0x%04x), wwid(0x%016llx)\n", handle
,
6066 (unsigned long long)raid_device
->wwid
);
6067 if (raid_device
->handle
== handle
)
6069 printk(KERN_INFO
"\thandle changed from(0x%04x)!!!\n",
6070 raid_device
->handle
);
6071 raid_device
->handle
= handle
;
6072 if (sas_target_priv_data
)
6073 sas_target_priv_data
->handle
= handle
;
6078 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6082 * _scsih_search_responding_raid_devices -
6083 * @ioc: per adapter object
6085 * After host reset, find out whether devices are still responding.
6091 _scsih_search_responding_raid_devices(struct MPT2SAS_ADAPTER
*ioc
)
6093 Mpi2RaidVolPage1_t volume_pg1
;
6094 Mpi2RaidVolPage0_t volume_pg0
;
6095 Mpi2RaidPhysDiskPage0_t pd_pg0
;
6096 Mpi2ConfigReply_t mpi_reply
;
6101 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
, __func__
);
6103 if (list_empty(&ioc
->raid_device_list
))
6107 while (!(mpt2sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
6108 &volume_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
6109 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6110 MPI2_IOCSTATUS_MASK
;
6111 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
6113 handle
= le16_to_cpu(volume_pg1
.DevHandle
);
6115 if (mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
,
6116 &volume_pg0
, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
6117 sizeof(Mpi2RaidVolPage0_t
)))
6120 if (volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_OPTIMAL
||
6121 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_ONLINE
||
6122 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_DEGRADED
)
6123 _scsih_mark_responding_raid_device(ioc
,
6124 le64_to_cpu(volume_pg1
.WWID
), handle
);
6127 /* refresh the pd_handles */
6128 phys_disk_num
= 0xFF;
6129 memset(ioc
->pd_handles
, 0, ioc
->pd_handles_sz
);
6130 while (!(mpt2sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
6131 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM
,
6133 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6134 MPI2_IOCSTATUS_MASK
;
6135 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
6137 phys_disk_num
= pd_pg0
.PhysDiskNum
;
6138 handle
= le16_to_cpu(pd_pg0
.DevHandle
);
6139 set_bit(handle
, ioc
->pd_handles
);
6144 * _scsih_mark_responding_expander - mark a expander as responding
6145 * @ioc: per adapter object
6146 * @sas_address: sas address
6149 * After host reset, find out whether devices are still responding.
6150 * Used in _scsi_remove_unresponsive_expanders.
6155 _scsih_mark_responding_expander(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
,
6158 struct _sas_node
*sas_expander
;
6159 unsigned long flags
;
6162 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
6163 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
6164 if (sas_expander
->sas_address
!= sas_address
)
6166 sas_expander
->responding
= 1;
6167 if (sas_expander
->handle
== handle
)
6169 printk(KERN_INFO
"\texpander(0x%016llx): handle changed"
6170 " from(0x%04x) to (0x%04x)!!!\n",
6171 (unsigned long long)sas_expander
->sas_address
,
6172 sas_expander
->handle
, handle
);
6173 sas_expander
->handle
= handle
;
6174 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++)
6175 sas_expander
->phy
[i
].handle
= handle
;
6179 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
6183 * _scsih_search_responding_expanders -
6184 * @ioc: per adapter object
6186 * After host reset, find out whether devices are still responding.
6192 _scsih_search_responding_expanders(struct MPT2SAS_ADAPTER
*ioc
)
6194 Mpi2ExpanderPage0_t expander_pg0
;
6195 Mpi2ConfigReply_t mpi_reply
;
6200 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
, __func__
);
6202 if (list_empty(&ioc
->sas_expander_list
))
6206 while (!(mpt2sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
6207 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL
, handle
))) {
6209 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6210 MPI2_IOCSTATUS_MASK
;
6211 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
6214 handle
= le16_to_cpu(expander_pg0
.DevHandle
);
6215 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
6216 printk(KERN_INFO
"\texpander present: handle(0x%04x), "
6217 "sas_addr(0x%016llx)\n", handle
,
6218 (unsigned long long)sas_address
);
6219 _scsih_mark_responding_expander(ioc
, sas_address
, handle
);
6225 * _scsih_remove_unresponding_sas_devices - removing unresponding devices
6226 * @ioc: per adapter object
6231 _scsih_remove_unresponding_sas_devices(struct MPT2SAS_ADAPTER
*ioc
)
6233 struct _sas_device
*sas_device
, *sas_device_next
;
6234 struct _sas_node
*sas_expander
;
6235 struct _raid_device
*raid_device
, *raid_device_next
;
6238 list_for_each_entry_safe(sas_device
, sas_device_next
,
6239 &ioc
->sas_device_list
, list
) {
6240 if (sas_device
->responding
) {
6241 sas_device
->responding
= 0;
6244 if (sas_device
->starget
)
6245 starget_printk(KERN_INFO
, sas_device
->starget
,
6246 "removing: handle(0x%04x), sas_addr(0x%016llx), "
6247 "enclosure logical id(0x%016llx), slot(%d)\n",
6249 (unsigned long long)sas_device
->sas_address
,
6250 (unsigned long long)
6251 sas_device
->enclosure_logical_id
,
6253 _scsih_remove_device(ioc
, sas_device
);
6256 list_for_each_entry_safe(raid_device
, raid_device_next
,
6257 &ioc
->raid_device_list
, list
) {
6258 if (raid_device
->responding
) {
6259 raid_device
->responding
= 0;
6262 if (raid_device
->starget
) {
6263 starget_printk(KERN_INFO
, raid_device
->starget
,
6264 "removing: handle(0x%04x), wwid(0x%016llx)\n",
6265 raid_device
->handle
,
6266 (unsigned long long)raid_device
->wwid
);
6267 scsi_remove_target(&raid_device
->starget
->dev
);
6269 _scsih_raid_device_remove(ioc
, raid_device
);
6272 retry_expander_search
:
6273 sas_expander
= NULL
;
6274 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
6275 if (sas_expander
->responding
) {
6276 sas_expander
->responding
= 0;
6279 mpt2sas_expander_remove(ioc
, sas_expander
->sas_address
);
6280 goto retry_expander_search
;
6285 * mpt2sas_scsih_reset_handler - reset callback handler (for scsih)
6286 * @ioc: per adapter object
6287 * @reset_phase: phase
6289 * The handler for doing any required cleanup or initialization.
6291 * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
6292 * MPT2_IOC_DONE_RESET
6297 mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER
*ioc
, int reset_phase
)
6299 switch (reset_phase
) {
6300 case MPT2_IOC_PRE_RESET
:
6301 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: "
6302 "MPT2_IOC_PRE_RESET\n", ioc
->name
, __func__
));
6304 case MPT2_IOC_AFTER_RESET
:
6305 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: "
6306 "MPT2_IOC_AFTER_RESET\n", ioc
->name
, __func__
));
6307 if (ioc
->scsih_cmds
.status
& MPT2_CMD_PENDING
) {
6308 ioc
->scsih_cmds
.status
|= MPT2_CMD_RESET
;
6309 mpt2sas_base_free_smid(ioc
, ioc
->scsih_cmds
.smid
);
6310 complete(&ioc
->scsih_cmds
.done
);
6312 if (ioc
->tm_cmds
.status
& MPT2_CMD_PENDING
) {
6313 ioc
->tm_cmds
.status
|= MPT2_CMD_RESET
;
6314 mpt2sas_base_free_smid(ioc
, ioc
->tm_cmds
.smid
);
6315 complete(&ioc
->tm_cmds
.done
);
6317 _scsih_fw_event_cleanup_queue(ioc
);
6318 _scsih_flush_running_cmds(ioc
);
6319 _scsih_queue_rescan(ioc
);
6321 case MPT2_IOC_DONE_RESET
:
6322 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: "
6323 "MPT2_IOC_DONE_RESET\n", ioc
->name
, __func__
));
6324 _scsih_sas_host_refresh(ioc
);
6325 _scsih_prep_device_scan(ioc
);
6326 _scsih_search_responding_sas_devices(ioc
);
6327 _scsih_search_responding_raid_devices(ioc
);
6328 _scsih_search_responding_expanders(ioc
);
6334 * _firmware_event_work - delayed task for processing firmware events
6335 * @ioc: per adapter object
6336 * @work: equal to the fw_event_work object
6342 _firmware_event_work(struct work_struct
*work
)
6344 struct fw_event_work
*fw_event
= container_of(work
,
6345 struct fw_event_work
, delayed_work
.work
);
6346 unsigned long flags
;
6347 struct MPT2SAS_ADAPTER
*ioc
= fw_event
->ioc
;
6349 /* the queue is being flushed so ignore this event */
6350 if (ioc
->remove_host
|| fw_event
->cancel_pending_work
||
6351 ioc
->pci_error_recovery
) {
6352 _scsih_fw_event_free(ioc
, fw_event
);
6356 if (fw_event
->event
== MPT2SAS_RESCAN_AFTER_HOST_RESET
) {
6357 _scsih_fw_event_free(ioc
, fw_event
);
6358 spin_lock_irqsave(&ioc
->ioc_reset_in_progress_lock
, flags
);
6359 if (ioc
->shost_recovery
) {
6360 init_completion(&ioc
->shost_recovery_done
);
6361 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
,
6363 wait_for_completion(&ioc
->shost_recovery_done
);
6365 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
,
6367 _scsih_remove_unresponding_sas_devices(ioc
);
6371 switch (fw_event
->event
) {
6372 case MPT2SAS_TURN_ON_FAULT_LED
:
6373 _scsih_turn_on_fault_led(ioc
, fw_event
->device_handle
);
6375 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
6376 _scsih_sas_topology_change_event(ioc
, fw_event
);
6378 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
6379 _scsih_sas_device_status_change_event(ioc
,
6382 case MPI2_EVENT_SAS_DISCOVERY
:
6383 _scsih_sas_discovery_event(ioc
,
6386 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
6387 _scsih_sas_broadcast_primative_event(ioc
,
6390 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
6391 _scsih_sas_enclosure_dev_status_change_event(ioc
,
6394 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
6395 _scsih_sas_ir_config_change_event(ioc
, fw_event
);
6397 case MPI2_EVENT_IR_VOLUME
:
6398 _scsih_sas_ir_volume_event(ioc
, fw_event
);
6400 case MPI2_EVENT_IR_PHYSICAL_DISK
:
6401 _scsih_sas_ir_physical_disk_event(ioc
, fw_event
);
6403 case MPI2_EVENT_IR_OPERATION_STATUS
:
6404 _scsih_sas_ir_operation_status_event(ioc
, fw_event
);
6407 _scsih_fw_event_free(ioc
, fw_event
);
6411 * mpt2sas_scsih_event_callback - firmware event handler (called at ISR time)
6412 * @ioc: per adapter object
6413 * @msix_index: MSIX table index supplied by the OS
6414 * @reply: reply message frame(lower 32bit addr)
6415 * Context: interrupt.
6417 * This function merely adds a new work task into ioc->firmware_event_thread.
6418 * The tasks are worked from _firmware_event_work in user context.
6420 * Return 1 meaning mf should be freed from _base_interrupt
6421 * 0 means the mf is freed from this function.
6424 mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER
*ioc
, u8 msix_index
,
6427 struct fw_event_work
*fw_event
;
6428 Mpi2EventNotificationReply_t
*mpi_reply
;
6432 /* events turned off due to host reset or driver unloading */
6433 if (ioc
->remove_host
|| ioc
->pci_error_recovery
)
6436 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
6437 event
= le16_to_cpu(mpi_reply
->Event
);
6441 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
6443 Mpi2EventDataSasBroadcastPrimitive_t
*baen_data
=
6444 (Mpi2EventDataSasBroadcastPrimitive_t
*)
6445 mpi_reply
->EventData
;
6447 if (baen_data
->Primitive
!=
6448 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT
||
6449 ioc
->broadcast_aen_busy
)
6451 ioc
->broadcast_aen_busy
= 1;
6455 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
6456 _scsih_check_topo_delete_events(ioc
,
6457 (Mpi2EventDataSasTopologyChangeList_t
*)
6458 mpi_reply
->EventData
);
6460 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
6461 _scsih_check_ir_config_unhide_events(ioc
,
6462 (Mpi2EventDataIrConfigChangeList_t
*)
6463 mpi_reply
->EventData
);
6465 case MPI2_EVENT_IR_VOLUME
:
6466 _scsih_check_volume_delete_events(ioc
,
6467 (Mpi2EventDataIrVolume_t
*)
6468 mpi_reply
->EventData
);
6470 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
6471 case MPI2_EVENT_IR_OPERATION_STATUS
:
6472 case MPI2_EVENT_SAS_DISCOVERY
:
6473 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
6474 case MPI2_EVENT_IR_PHYSICAL_DISK
:
6477 default: /* ignore the rest */
6481 fw_event
= kzalloc(sizeof(struct fw_event_work
), GFP_ATOMIC
);
6483 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6484 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6487 sz
= le16_to_cpu(mpi_reply
->EventDataLength
) * 4;
6488 fw_event
->event_data
= kzalloc(sz
, GFP_ATOMIC
);
6489 if (!fw_event
->event_data
) {
6490 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6491 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6496 memcpy(fw_event
->event_data
, mpi_reply
->EventData
,
6498 fw_event
->ioc
= ioc
;
6499 fw_event
->VF_ID
= mpi_reply
->VF_ID
;
6500 fw_event
->VP_ID
= mpi_reply
->VP_ID
;
6501 fw_event
->event
= event
;
6502 _scsih_fw_event_add(ioc
, fw_event
);
6506 /* shost template */
6507 static struct scsi_host_template scsih_driver_template
= {
6508 .module
= THIS_MODULE
,
6509 .name
= "Fusion MPT SAS Host",
6510 .proc_name
= MPT2SAS_DRIVER_NAME
,
6511 .queuecommand
= _scsih_qcmd
,
6512 .target_alloc
= _scsih_target_alloc
,
6513 .slave_alloc
= _scsih_slave_alloc
,
6514 .slave_configure
= _scsih_slave_configure
,
6515 .target_destroy
= _scsih_target_destroy
,
6516 .slave_destroy
= _scsih_slave_destroy
,
6517 .change_queue_depth
= _scsih_change_queue_depth
,
6518 .change_queue_type
= _scsih_change_queue_type
,
6519 .eh_abort_handler
= _scsih_abort
,
6520 .eh_device_reset_handler
= _scsih_dev_reset
,
6521 .eh_target_reset_handler
= _scsih_target_reset
,
6522 .eh_host_reset_handler
= _scsih_host_reset
,
6523 .bios_param
= _scsih_bios_param
,
6526 .sg_tablesize
= MPT2SAS_SG_DEPTH
,
6527 .max_sectors
= 8192,
6529 .use_clustering
= ENABLE_CLUSTERING
,
6530 .shost_attrs
= mpt2sas_host_attrs
,
6531 .sdev_attrs
= mpt2sas_dev_attrs
,
6535 * _scsih_expander_node_remove - removing expander device from list.
6536 * @ioc: per adapter object
6537 * @sas_expander: the sas_device object
6538 * Context: Calling function should acquire ioc->sas_node_lock.
6540 * Removing object and freeing associated memory from the
6541 * ioc->sas_expander_list.
6546 _scsih_expander_node_remove(struct MPT2SAS_ADAPTER
*ioc
,
6547 struct _sas_node
*sas_expander
)
6549 struct _sas_port
*mpt2sas_port
, *next
;
6551 /* remove sibling ports attached to this expander */
6552 list_for_each_entry_safe(mpt2sas_port
, next
,
6553 &sas_expander
->sas_port_list
, port_list
) {
6554 if (ioc
->shost_recovery
)
6556 if (mpt2sas_port
->remote_identify
.device_type
==
6558 mpt2sas_device_remove(ioc
,
6559 mpt2sas_port
->remote_identify
.sas_address
);
6560 else if (mpt2sas_port
->remote_identify
.device_type
==
6561 SAS_EDGE_EXPANDER_DEVICE
||
6562 mpt2sas_port
->remote_identify
.device_type
==
6563 SAS_FANOUT_EXPANDER_DEVICE
)
6564 mpt2sas_expander_remove(ioc
,
6565 mpt2sas_port
->remote_identify
.sas_address
);
6568 mpt2sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
6569 sas_expander
->sas_address_parent
);
6571 printk(MPT2SAS_INFO_FMT
"expander_remove: handle"
6572 "(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
6573 sas_expander
->handle
, (unsigned long long)
6574 sas_expander
->sas_address
);
6576 kfree(sas_expander
->phy
);
6577 kfree(sas_expander
);
6581 * _scsih_ir_shutdown - IR shutdown notification
6582 * @ioc: per adapter object
6584 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
6585 * the host system is shutting down.
6590 _scsih_ir_shutdown(struct MPT2SAS_ADAPTER
*ioc
)
6592 Mpi2RaidActionRequest_t
*mpi_request
;
6593 Mpi2RaidActionReply_t
*mpi_reply
;
6596 /* is IR firmware build loaded ? */
6597 if (!ioc
->ir_firmware
)
6600 /* are there any volumes ? */
6601 if (list_empty(&ioc
->raid_device_list
))
6604 mutex_lock(&ioc
->scsih_cmds
.mutex
);
6606 if (ioc
->scsih_cmds
.status
!= MPT2_CMD_NOT_USED
) {
6607 printk(MPT2SAS_ERR_FMT
"%s: scsih_cmd in use\n",
6608 ioc
->name
, __func__
);
6611 ioc
->scsih_cmds
.status
= MPT2_CMD_PENDING
;
6613 smid
= mpt2sas_base_get_smid(ioc
, ioc
->scsih_cb_idx
);
6615 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
6616 ioc
->name
, __func__
);
6617 ioc
->scsih_cmds
.status
= MPT2_CMD_NOT_USED
;
6621 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
6622 ioc
->scsih_cmds
.smid
= smid
;
6623 memset(mpi_request
, 0, sizeof(Mpi2RaidActionRequest_t
));
6625 mpi_request
->Function
= MPI2_FUNCTION_RAID_ACTION
;
6626 mpi_request
->Action
= MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED
;
6628 printk(MPT2SAS_INFO_FMT
"IR shutdown (sending)\n", ioc
->name
);
6629 init_completion(&ioc
->scsih_cmds
.done
);
6630 mpt2sas_base_put_smid_default(ioc
, smid
);
6631 wait_for_completion_timeout(&ioc
->scsih_cmds
.done
, 10*HZ
);
6633 if (!(ioc
->scsih_cmds
.status
& MPT2_CMD_COMPLETE
)) {
6634 printk(MPT2SAS_ERR_FMT
"%s: timeout\n",
6635 ioc
->name
, __func__
);
6639 if (ioc
->scsih_cmds
.status
& MPT2_CMD_REPLY_VALID
) {
6640 mpi_reply
= ioc
->scsih_cmds
.reply
;
6642 printk(MPT2SAS_INFO_FMT
"IR shutdown (complete): "
6643 "ioc_status(0x%04x), loginfo(0x%08x)\n",
6644 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
6645 le32_to_cpu(mpi_reply
->IOCLogInfo
));
6649 ioc
->scsih_cmds
.status
= MPT2_CMD_NOT_USED
;
6650 mutex_unlock(&ioc
->scsih_cmds
.mutex
);
6654 * _scsih_shutdown - routine call during system shutdown
6655 * @pdev: PCI device struct
6660 _scsih_shutdown(struct pci_dev
*pdev
)
6662 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6663 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
6664 struct workqueue_struct
*wq
;
6665 unsigned long flags
;
6667 ioc
->remove_host
= 1;
6668 _scsih_fw_event_cleanup_queue(ioc
);
6670 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
6671 wq
= ioc
->firmware_event_thread
;
6672 ioc
->firmware_event_thread
= NULL
;
6673 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
6675 destroy_workqueue(wq
);
6677 _scsih_ir_shutdown(ioc
);
6678 mpt2sas_base_detach(ioc
);
6682 * _scsih_remove - detach and remove add host
6683 * @pdev: PCI device struct
6685 * Routine called when unloading the driver.
6688 static void __devexit
6689 _scsih_remove(struct pci_dev
*pdev
)
6691 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6692 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
6693 struct _sas_port
*mpt2sas_port
, *next_port
;
6694 struct _raid_device
*raid_device
, *next
;
6695 struct MPT2SAS_TARGET
*sas_target_priv_data
;
6696 struct workqueue_struct
*wq
;
6697 unsigned long flags
;
6699 ioc
->remove_host
= 1;
6700 _scsih_fw_event_cleanup_queue(ioc
);
6702 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
6703 wq
= ioc
->firmware_event_thread
;
6704 ioc
->firmware_event_thread
= NULL
;
6705 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
6707 destroy_workqueue(wq
);
6709 /* release all the volumes */
6710 _scsih_ir_shutdown(ioc
);
6711 list_for_each_entry_safe(raid_device
, next
, &ioc
->raid_device_list
,
6713 if (raid_device
->starget
) {
6714 sas_target_priv_data
=
6715 raid_device
->starget
->hostdata
;
6716 sas_target_priv_data
->deleted
= 1;
6717 scsi_remove_target(&raid_device
->starget
->dev
);
6719 printk(MPT2SAS_INFO_FMT
"removing handle(0x%04x), wwid"
6720 "(0x%016llx)\n", ioc
->name
, raid_device
->handle
,
6721 (unsigned long long) raid_device
->wwid
);
6722 _scsih_raid_device_remove(ioc
, raid_device
);
6725 /* free ports attached to the sas_host */
6726 list_for_each_entry_safe(mpt2sas_port
, next_port
,
6727 &ioc
->sas_hba
.sas_port_list
, port_list
) {
6728 if (mpt2sas_port
->remote_identify
.device_type
==
6730 mpt2sas_device_remove(ioc
,
6731 mpt2sas_port
->remote_identify
.sas_address
);
6732 else if (mpt2sas_port
->remote_identify
.device_type
==
6733 SAS_EDGE_EXPANDER_DEVICE
||
6734 mpt2sas_port
->remote_identify
.device_type
==
6735 SAS_FANOUT_EXPANDER_DEVICE
)
6736 mpt2sas_expander_remove(ioc
,
6737 mpt2sas_port
->remote_identify
.sas_address
);
6740 /* free phys attached to the sas_host */
6741 if (ioc
->sas_hba
.num_phys
) {
6742 kfree(ioc
->sas_hba
.phy
);
6743 ioc
->sas_hba
.phy
= NULL
;
6744 ioc
->sas_hba
.num_phys
= 0;
6747 sas_remove_host(shost
);
6748 _scsih_shutdown(pdev
);
6749 list_del(&ioc
->list
);
6750 scsi_remove_host(shost
);
6751 scsi_host_put(shost
);
6755 * _scsih_probe_boot_devices - reports 1st device
6756 * @ioc: per adapter object
6758 * If specified in bios page 2, this routine reports the 1st
6759 * device scsi-ml or sas transport for persistent boot device
6760 * purposes. Please refer to function _scsih_determine_boot_device()
6763 _scsih_probe_boot_devices(struct MPT2SAS_ADAPTER
*ioc
)
6767 struct _sas_device
*sas_device
;
6768 struct _raid_device
*raid_device
;
6770 u64 sas_address_parent
;
6772 unsigned long flags
;
6776 if (ioc
->req_boot_device
.device
) {
6777 device
= ioc
->req_boot_device
.device
;
6778 is_raid
= ioc
->req_boot_device
.is_raid
;
6779 } else if (ioc
->req_alt_boot_device
.device
) {
6780 device
= ioc
->req_alt_boot_device
.device
;
6781 is_raid
= ioc
->req_alt_boot_device
.is_raid
;
6782 } else if (ioc
->current_boot_device
.device
) {
6783 device
= ioc
->current_boot_device
.device
;
6784 is_raid
= ioc
->current_boot_device
.is_raid
;
6791 raid_device
= device
;
6792 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
6793 raid_device
->id
, 0);
6795 _scsih_raid_device_remove(ioc
, raid_device
);
6797 sas_device
= device
;
6798 handle
= sas_device
->handle
;
6799 sas_address_parent
= sas_device
->sas_address_parent
;
6800 sas_address
= sas_device
->sas_address
;
6801 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6802 list_move_tail(&sas_device
->list
, &ioc
->sas_device_list
);
6803 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6804 if (!mpt2sas_transport_port_add(ioc
, sas_device
->handle
,
6805 sas_device
->sas_address_parent
)) {
6806 _scsih_sas_device_remove(ioc
, sas_device
);
6807 } else if (!sas_device
->starget
) {
6808 mpt2sas_transport_port_remove(ioc
, sas_address
,
6809 sas_address_parent
);
6810 _scsih_sas_device_remove(ioc
, sas_device
);
6816 * _scsih_probe_raid - reporting raid volumes to scsi-ml
6817 * @ioc: per adapter object
6819 * Called during initial loading of the driver.
6822 _scsih_probe_raid(struct MPT2SAS_ADAPTER
*ioc
)
6824 struct _raid_device
*raid_device
, *raid_next
;
6827 list_for_each_entry_safe(raid_device
, raid_next
,
6828 &ioc
->raid_device_list
, list
) {
6829 if (raid_device
->starget
)
6831 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
6832 raid_device
->id
, 0);
6834 _scsih_raid_device_remove(ioc
, raid_device
);
6839 * _scsih_probe_sas - reporting sas devices to sas transport
6840 * @ioc: per adapter object
6842 * Called during initial loading of the driver.
6845 _scsih_probe_sas(struct MPT2SAS_ADAPTER
*ioc
)
6847 struct _sas_device
*sas_device
, *next
;
6848 unsigned long flags
;
6850 /* SAS Device List */
6851 list_for_each_entry_safe(sas_device
, next
, &ioc
->sas_device_init_list
,
6853 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6854 list_move_tail(&sas_device
->list
, &ioc
->sas_device_list
);
6855 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6857 if (!mpt2sas_transport_port_add(ioc
, sas_device
->handle
,
6858 sas_device
->sas_address_parent
)) {
6859 _scsih_sas_device_remove(ioc
, sas_device
);
6860 } else if (!sas_device
->starget
) {
6861 mpt2sas_transport_port_remove(ioc
,
6862 sas_device
->sas_address
,
6863 sas_device
->sas_address_parent
);
6864 _scsih_sas_device_remove(ioc
, sas_device
);
6870 * _scsih_probe_devices - probing for devices
6871 * @ioc: per adapter object
6873 * Called during initial loading of the driver.
6876 _scsih_probe_devices(struct MPT2SAS_ADAPTER
*ioc
)
6878 u16 volume_mapping_flags
=
6879 le16_to_cpu(ioc
->ioc_pg8
.IRVolumeMappingFlags
) &
6880 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE
;
6882 if (!(ioc
->facts
.ProtocolFlags
& MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR
))
6883 return; /* return when IOC doesn't support initiator mode */
6885 _scsih_probe_boot_devices(ioc
);
6887 if (ioc
->ir_firmware
) {
6888 if ((volume_mapping_flags
&
6889 MPI2_IOCPAGE8_IRFLAGS_HIGH_VOLUME_MAPPING
)) {
6890 _scsih_probe_sas(ioc
);
6891 _scsih_probe_raid(ioc
);
6893 _scsih_probe_raid(ioc
);
6894 _scsih_probe_sas(ioc
);
6897 _scsih_probe_sas(ioc
);
6901 * _scsih_probe - attach and add scsi host
6902 * @pdev: PCI device struct
6903 * @id: pci device id
6905 * Returns 0 success, anything else error.
6908 _scsih_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
6910 struct MPT2SAS_ADAPTER
*ioc
;
6911 struct Scsi_Host
*shost
;
6913 shost
= scsi_host_alloc(&scsih_driver_template
,
6914 sizeof(struct MPT2SAS_ADAPTER
));
6918 /* init local params */
6919 ioc
= shost_priv(shost
);
6920 memset(ioc
, 0, sizeof(struct MPT2SAS_ADAPTER
));
6921 INIT_LIST_HEAD(&ioc
->list
);
6922 list_add_tail(&ioc
->list
, &mpt2sas_ioc_list
);
6924 ioc
->id
= mpt_ids
++;
6925 sprintf(ioc
->name
, "%s%d", MPT2SAS_DRIVER_NAME
, ioc
->id
);
6927 ioc
->scsi_io_cb_idx
= scsi_io_cb_idx
;
6928 ioc
->tm_cb_idx
= tm_cb_idx
;
6929 ioc
->ctl_cb_idx
= ctl_cb_idx
;
6930 ioc
->base_cb_idx
= base_cb_idx
;
6931 ioc
->transport_cb_idx
= transport_cb_idx
;
6932 ioc
->scsih_cb_idx
= scsih_cb_idx
;
6933 ioc
->config_cb_idx
= config_cb_idx
;
6934 ioc
->tm_tr_cb_idx
= tm_tr_cb_idx
;
6935 ioc
->tm_tr_volume_cb_idx
= tm_tr_volume_cb_idx
;
6936 ioc
->tm_sas_control_cb_idx
= tm_sas_control_cb_idx
;
6937 ioc
->logging_level
= logging_level
;
6938 /* misc semaphores and spin locks */
6939 mutex_init(&ioc
->reset_in_progress_mutex
);
6940 spin_lock_init(&ioc
->ioc_reset_in_progress_lock
);
6941 spin_lock_init(&ioc
->scsi_lookup_lock
);
6942 spin_lock_init(&ioc
->sas_device_lock
);
6943 spin_lock_init(&ioc
->sas_node_lock
);
6944 spin_lock_init(&ioc
->fw_event_lock
);
6945 spin_lock_init(&ioc
->raid_device_lock
);
6947 INIT_LIST_HEAD(&ioc
->sas_device_list
);
6948 INIT_LIST_HEAD(&ioc
->sas_device_init_list
);
6949 INIT_LIST_HEAD(&ioc
->sas_expander_list
);
6950 INIT_LIST_HEAD(&ioc
->fw_event_list
);
6951 INIT_LIST_HEAD(&ioc
->raid_device_list
);
6952 INIT_LIST_HEAD(&ioc
->sas_hba
.sas_port_list
);
6953 INIT_LIST_HEAD(&ioc
->delayed_tr_list
);
6954 INIT_LIST_HEAD(&ioc
->delayed_tr_volume_list
);
6956 /* init shost parameters */
6957 shost
->max_cmd_len
= 32;
6958 shost
->max_lun
= max_lun
;
6959 shost
->transportt
= mpt2sas_transport_template
;
6960 shost
->unique_id
= ioc
->id
;
6962 if ((scsi_add_host(shost
, &pdev
->dev
))) {
6963 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6964 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6965 list_del(&ioc
->list
);
6966 goto out_add_shost_fail
;
6969 scsi_host_set_prot(shost
, SHOST_DIF_TYPE1_PROTECTION
6970 | SHOST_DIF_TYPE2_PROTECTION
| SHOST_DIF_TYPE3_PROTECTION
);
6971 scsi_host_set_guard(shost
, SHOST_DIX_GUARD_CRC
);
6974 snprintf(ioc
->firmware_event_name
, sizeof(ioc
->firmware_event_name
),
6975 "fw_event%d", ioc
->id
);
6976 ioc
->firmware_event_thread
= create_singlethread_workqueue(
6977 ioc
->firmware_event_name
);
6978 if (!ioc
->firmware_event_thread
) {
6979 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6980 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6981 goto out_thread_fail
;
6984 ioc
->wait_for_port_enable_to_complete
= 1;
6985 if ((mpt2sas_base_attach(ioc
))) {
6986 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6987 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6988 goto out_attach_fail
;
6991 ioc
->wait_for_port_enable_to_complete
= 0;
6992 _scsih_probe_devices(ioc
);
6996 destroy_workqueue(ioc
->firmware_event_thread
);
6998 list_del(&ioc
->list
);
6999 scsi_remove_host(shost
);
7006 * _scsih_suspend - power management suspend main entry point
7007 * @pdev: PCI device struct
7008 * @state: PM state change to (usually PCI_D3)
7010 * Returns 0 success, anything else error.
7013 _scsih_suspend(struct pci_dev
*pdev
, pm_message_t state
)
7015 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
7016 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
7019 mpt2sas_base_stop_watchdog(ioc
);
7020 flush_scheduled_work();
7021 scsi_block_requests(shost
);
7022 device_state
= pci_choose_state(pdev
, state
);
7023 printk(MPT2SAS_INFO_FMT
"pdev=0x%p, slot=%s, entering "
7024 "operating state [D%d]\n", ioc
->name
, pdev
,
7025 pci_name(pdev
), device_state
);
7027 mpt2sas_base_free_resources(ioc
);
7028 pci_save_state(pdev
);
7029 pci_disable_device(pdev
);
7030 pci_set_power_state(pdev
, device_state
);
7035 * _scsih_resume - power management resume main entry point
7036 * @pdev: PCI device struct
7038 * Returns 0 success, anything else error.
7041 _scsih_resume(struct pci_dev
*pdev
)
7043 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
7044 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
7045 u32 device_state
= pdev
->current_state
;
7048 printk(MPT2SAS_INFO_FMT
"pdev=0x%p, slot=%s, previous "
7049 "operating state [D%d]\n", ioc
->name
, pdev
,
7050 pci_name(pdev
), device_state
);
7052 pci_set_power_state(pdev
, PCI_D0
);
7053 pci_enable_wake(pdev
, PCI_D0
, 0);
7054 pci_restore_state(pdev
);
7056 r
= mpt2sas_base_map_resources(ioc
);
7060 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
, SOFT_RESET
);
7061 scsi_unblock_requests(shost
);
7062 mpt2sas_base_start_watchdog(ioc
);
7065 #endif /* CONFIG_PM */
7068 * _scsih_pci_error_detected - Called when a PCI error is detected.
7069 * @pdev: PCI device struct
7070 * @state: PCI channel state
7072 * Description: Called when a PCI error is detected.
7075 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
7077 static pci_ers_result_t
7078 _scsih_pci_error_detected(struct pci_dev
*pdev
, pci_channel_state_t state
)
7080 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
7081 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
7083 printk(MPT2SAS_INFO_FMT
"PCI error: detected callback, state(%d)!!\n",
7087 case pci_channel_io_normal
:
7088 return PCI_ERS_RESULT_CAN_RECOVER
;
7089 case pci_channel_io_frozen
:
7090 /* Fatal error, prepare for slot reset */
7091 ioc
->pci_error_recovery
= 1;
7092 scsi_block_requests(ioc
->shost
);
7093 mpt2sas_base_stop_watchdog(ioc
);
7094 mpt2sas_base_free_resources(ioc
);
7095 return PCI_ERS_RESULT_NEED_RESET
;
7096 case pci_channel_io_perm_failure
:
7097 /* Permanent error, prepare for device removal */
7098 ioc
->pci_error_recovery
= 1;
7099 mpt2sas_base_stop_watchdog(ioc
);
7100 _scsih_flush_running_cmds(ioc
);
7101 return PCI_ERS_RESULT_DISCONNECT
;
7103 return PCI_ERS_RESULT_NEED_RESET
;
7107 * _scsih_pci_slot_reset - Called when PCI slot has been reset.
7108 * @pdev: PCI device struct
7110 * Description: This routine is called by the pci error recovery
7111 * code after the PCI slot has been reset, just before we
7112 * should resume normal operations.
7114 static pci_ers_result_t
7115 _scsih_pci_slot_reset(struct pci_dev
*pdev
)
7117 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
7118 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
7121 printk(MPT2SAS_INFO_FMT
"PCI error: slot reset callback!!\n",
7124 ioc
->pci_error_recovery
= 0;
7126 pci_restore_state(pdev
);
7127 rc
= mpt2sas_base_map_resources(ioc
);
7129 return PCI_ERS_RESULT_DISCONNECT
;
7132 rc
= mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
7135 printk(MPT2SAS_WARN_FMT
"hard reset: %s\n", ioc
->name
,
7136 (rc
== 0) ? "success" : "failed");
7139 return PCI_ERS_RESULT_RECOVERED
;
7141 return PCI_ERS_RESULT_DISCONNECT
;
7145 * _scsih_pci_resume() - resume normal ops after PCI reset
7146 * @pdev: pointer to PCI device
7148 * Called when the error recovery driver tells us that its
7149 * OK to resume normal operation. Use completion to allow
7150 * halted scsi ops to resume.
7153 _scsih_pci_resume(struct pci_dev
*pdev
)
7155 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
7156 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
7158 printk(MPT2SAS_INFO_FMT
"PCI error: resume callback!!\n", ioc
->name
);
7160 pci_cleanup_aer_uncorrect_error_status(pdev
);
7161 mpt2sas_base_start_watchdog(ioc
);
7162 scsi_unblock_requests(ioc
->shost
);
7166 * _scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
7167 * @pdev: pointer to PCI device
7169 static pci_ers_result_t
7170 _scsih_pci_mmio_enabled(struct pci_dev
*pdev
)
7172 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
7173 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
7175 printk(MPT2SAS_INFO_FMT
"PCI error: mmio enabled callback!!\n",
7178 /* TODO - dump whatever for debugging purposes */
7180 /* Request a slot reset. */
7181 return PCI_ERS_RESULT_NEED_RESET
;
7184 static struct pci_error_handlers _scsih_err_handler
= {
7185 .error_detected
= _scsih_pci_error_detected
,
7186 .mmio_enabled
= _scsih_pci_mmio_enabled
,
7187 .slot_reset
= _scsih_pci_slot_reset
,
7188 .resume
= _scsih_pci_resume
,
7191 static struct pci_driver scsih_driver
= {
7192 .name
= MPT2SAS_DRIVER_NAME
,
7193 .id_table
= scsih_pci_table
,
7194 .probe
= _scsih_probe
,
7195 .remove
= __devexit_p(_scsih_remove
),
7196 .shutdown
= _scsih_shutdown
,
7197 .err_handler
= &_scsih_err_handler
,
7199 .suspend
= _scsih_suspend
,
7200 .resume
= _scsih_resume
,
7204 /* raid transport support */
7205 static struct raid_function_template mpt2sas_raid_functions
= {
7206 .cookie
= &scsih_driver_template
,
7207 .is_raid
= _scsih_is_raid
,
7208 .get_resync
= _scsih_get_resync
,
7209 .get_state
= _scsih_get_state
,
7213 * _scsih_init - main entry point for this driver.
7215 * Returns 0 success, anything else error.
7223 printk(KERN_INFO
"%s version %s loaded\n", MPT2SAS_DRIVER_NAME
,
7224 MPT2SAS_DRIVER_VERSION
);
7226 mpt2sas_transport_template
=
7227 sas_attach_transport(&mpt2sas_transport_functions
);
7228 if (!mpt2sas_transport_template
)
7230 /* raid transport support */
7231 mpt2sas_raid_template
= raid_class_attach(&mpt2sas_raid_functions
);
7232 if (!mpt2sas_raid_template
) {
7233 sas_release_transport(mpt2sas_transport_template
);
7237 mpt2sas_base_initialize_callback_handler();
7239 /* queuecommand callback hander */
7240 scsi_io_cb_idx
= mpt2sas_base_register_callback_handler(_scsih_io_done
);
7242 /* task management callback handler */
7243 tm_cb_idx
= mpt2sas_base_register_callback_handler(_scsih_tm_done
);
7245 /* base internal commands callback handler */
7246 base_cb_idx
= mpt2sas_base_register_callback_handler(mpt2sas_base_done
);
7248 /* transport internal commands callback handler */
7249 transport_cb_idx
= mpt2sas_base_register_callback_handler(
7250 mpt2sas_transport_done
);
7252 /* scsih internal commands callback handler */
7253 scsih_cb_idx
= mpt2sas_base_register_callback_handler(_scsih_done
);
7255 /* configuration page API internal commands callback handler */
7256 config_cb_idx
= mpt2sas_base_register_callback_handler(
7257 mpt2sas_config_done
);
7259 /* ctl module callback handler */
7260 ctl_cb_idx
= mpt2sas_base_register_callback_handler(mpt2sas_ctl_done
);
7262 tm_tr_cb_idx
= mpt2sas_base_register_callback_handler(
7263 _scsih_tm_tr_complete
);
7265 tm_tr_volume_cb_idx
= mpt2sas_base_register_callback_handler(
7266 _scsih_tm_volume_tr_complete
);
7268 tm_sas_control_cb_idx
= mpt2sas_base_register_callback_handler(
7269 _scsih_sas_control_complete
);
7273 error
= pci_register_driver(&scsih_driver
);
7275 /* raid transport support */
7276 raid_class_release(mpt2sas_raid_template
);
7277 sas_release_transport(mpt2sas_transport_template
);
7284 * _scsih_exit - exit point for this driver (when it is a module).
7286 * Returns 0 success, anything else error.
7291 printk(KERN_INFO
"mpt2sas version %s unloading\n",
7292 MPT2SAS_DRIVER_VERSION
);
7294 pci_unregister_driver(&scsih_driver
);
7298 mpt2sas_base_release_callback_handler(scsi_io_cb_idx
);
7299 mpt2sas_base_release_callback_handler(tm_cb_idx
);
7300 mpt2sas_base_release_callback_handler(base_cb_idx
);
7301 mpt2sas_base_release_callback_handler(transport_cb_idx
);
7302 mpt2sas_base_release_callback_handler(scsih_cb_idx
);
7303 mpt2sas_base_release_callback_handler(config_cb_idx
);
7304 mpt2sas_base_release_callback_handler(ctl_cb_idx
);
7306 mpt2sas_base_release_callback_handler(tm_tr_cb_idx
);
7307 mpt2sas_base_release_callback_handler(tm_tr_volume_cb_idx
);
7308 mpt2sas_base_release_callback_handler(tm_sas_control_cb_idx
);
7310 /* raid transport support */
7311 raid_class_release(mpt2sas_raid_template
);
7312 sas_release_transport(mpt2sas_transport_template
);
7316 module_init(_scsih_init
);
7317 module_exit(_scsih_exit
);