2 * Scsi Host Layer for MPT (Message Passing Technology) based controllers
4 * This code is based on drivers/scsi/mpt2sas/mpt2_scsih.c
5 * Copyright (C) 2007-2009 LSI Corporation
6 * (mailto:DL-MPTFusionLinux@lsi.com)
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
19 * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
20 * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
21 * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
22 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
23 * solely responsible for determining the appropriateness of using and
24 * distributing the Program and assumes all risks associated with its
25 * exercise of rights under this Agreement, including but not limited to
26 * the risks and costs of program errors, damage to or loss of data,
27 * programs or equipment, and unavailability or interruption of operations.
29 * DISCLAIMER OF LIABILITY
30 * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
31 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
33 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
34 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
35 * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
36 * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
38 * You should have received a copy of the GNU General Public License
39 * along with this program; if not, write to the Free Software
40 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
44 #include <linux/version.h>
45 #include <linux/module.h>
46 #include <linux/kernel.h>
47 #include <linux/init.h>
48 #include <linux/errno.h>
49 #include <linux/blkdev.h>
50 #include <linux/sched.h>
51 #include <linux/workqueue.h>
52 #include <linux/delay.h>
53 #include <linux/pci.h>
54 #include <linux/interrupt.h>
55 #include <linux/raid_class.h>
57 #include "mpt2sas_base.h"
59 MODULE_AUTHOR(MPT2SAS_AUTHOR
);
60 MODULE_DESCRIPTION(MPT2SAS_DESCRIPTION
);
61 MODULE_LICENSE("GPL");
62 MODULE_VERSION(MPT2SAS_DRIVER_VERSION
);
64 #define RAID_CHANNEL 1
67 static void _scsih_expander_node_remove(struct MPT2SAS_ADAPTER
*ioc
,
68 struct _sas_node
*sas_expander
);
69 static void _firmware_event_work(struct work_struct
*work
);
71 /* global parameters */
72 LIST_HEAD(mpt2sas_ioc_list
);
74 /* local parameters */
75 static u8 scsi_io_cb_idx
= -1;
76 static u8 tm_cb_idx
= -1;
77 static u8 ctl_cb_idx
= -1;
78 static u8 base_cb_idx
= -1;
79 static u8 transport_cb_idx
= -1;
80 static u8 scsih_cb_idx
= -1;
81 static u8 config_cb_idx
= -1;
84 static u8 tm_tr_cb_idx
= -1 ;
85 static u8 tm_sas_control_cb_idx
= -1;
87 /* command line options */
88 static u32 logging_level
;
89 MODULE_PARM_DESC(logging_level
, " bits for enabling additional logging info "
92 /* scsi-mid layer global parmeter is max_report_luns, which is 511 */
93 #define MPT2SAS_MAX_LUN (16895)
94 static int max_lun
= MPT2SAS_MAX_LUN
;
95 module_param(max_lun
, int, 0);
96 MODULE_PARM_DESC(max_lun
, " max lun, default=16895 ");
99 * struct sense_info - common structure for obtaining sense keys
101 * @asc: additional sense code
102 * @ascq: additional sense code qualifier
112 * struct fw_event_work - firmware event struct
113 * @list: link list framework
114 * @work: work object (ioc->fault_reset_work_q)
115 * @ioc: per adapter object
116 * @VF_ID: virtual function id
117 * @VP_ID: virtual port id
118 * @host_reset_handling: handling events during host reset
119 * @ignore: flag meaning this event has been marked to ignore
120 * @event: firmware event MPI2_EVENT_XXX defined in mpt2_ioc.h
121 * @event_data: reply event data payload follows
123 * This object stored on ioc->fw_event_list.
125 struct fw_event_work
{
126 struct list_head list
;
127 struct work_struct work
;
128 struct MPT2SAS_ADAPTER
*ioc
;
131 u8 host_reset_handling
;
137 /* raid transport support */
138 static struct raid_template
*mpt2sas_raid_template
;
141 * struct _scsi_io_transfer - scsi io transfer
142 * @handle: sas device handle (assigned by firmware)
143 * @is_raid: flag set for hidden raid components
144 * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE,
145 * @data_length: data transfer length
146 * @data_dma: dma pointer to data
149 * @cdb_length: cdb length
151 * @timeout: timeout for this command
152 * @VF_ID: virtual function id
153 * @VP_ID: virtual port id
154 * @valid_reply: flag set for reply message
155 * @sense_length: sense length
156 * @ioc_status: ioc status
157 * @scsi_state: scsi state
158 * @scsi_status: scsi staus
159 * @log_info: log information
160 * @transfer_length: data length transfer when there is a reply message
162 * Used for sending internal scsi commands to devices within this module.
163 * Refer to _scsi_send_scsi_io().
165 struct _scsi_io_transfer
{
168 enum dma_data_direction dir
;
171 u8 sense
[SCSI_SENSE_BUFFERSIZE
];
179 /* the following bits are only valid when 'valid_reply = 1' */
189 * The pci device ids are defined in mpi/mpi2_cnfg.h.
191 static struct pci_device_id scsih_pci_table
[] = {
192 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2004
,
193 PCI_ANY_ID
, PCI_ANY_ID
},
195 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2008
,
196 PCI_ANY_ID
, PCI_ANY_ID
},
197 /* Liberator ~ 2108 */
198 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_1
,
199 PCI_ANY_ID
, PCI_ANY_ID
},
200 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_2
,
201 PCI_ANY_ID
, PCI_ANY_ID
},
202 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_3
,
203 PCI_ANY_ID
, PCI_ANY_ID
},
205 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2116_1
,
206 PCI_ANY_ID
, PCI_ANY_ID
},
207 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2116_2
,
208 PCI_ANY_ID
, PCI_ANY_ID
},
209 /* Thunderbolt ~ 2208 */
210 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_1
,
211 PCI_ANY_ID
, PCI_ANY_ID
},
212 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_2
,
213 PCI_ANY_ID
, PCI_ANY_ID
},
214 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_3
,
215 PCI_ANY_ID
, PCI_ANY_ID
},
216 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_4
,
217 PCI_ANY_ID
, PCI_ANY_ID
},
218 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_5
,
219 PCI_ANY_ID
, PCI_ANY_ID
},
220 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_6
,
221 PCI_ANY_ID
, PCI_ANY_ID
},
222 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_7
,
223 PCI_ANY_ID
, PCI_ANY_ID
},
224 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_8
,
225 PCI_ANY_ID
, PCI_ANY_ID
},
226 {0} /* Terminating entry */
228 MODULE_DEVICE_TABLE(pci
, scsih_pci_table
);
231 * _scsih_set_debug_level - global setting of ioc->logging_level.
233 * Note: The logging levels are defined in mpt2sas_debug.h.
236 _scsih_set_debug_level(const char *val
, struct kernel_param
*kp
)
238 int ret
= param_set_int(val
, kp
);
239 struct MPT2SAS_ADAPTER
*ioc
;
244 printk(KERN_INFO
"setting logging_level(0x%08x)\n", logging_level
);
245 list_for_each_entry(ioc
, &mpt2sas_ioc_list
, list
)
246 ioc
->logging_level
= logging_level
;
249 module_param_call(logging_level
, _scsih_set_debug_level
, param_get_int
,
250 &logging_level
, 0644);
253 * _scsih_srch_boot_sas_address - search based on sas_address
254 * @sas_address: sas address
255 * @boot_device: boot device object from bios page 2
257 * Returns 1 when there's a match, 0 means no match.
260 _scsih_srch_boot_sas_address(u64 sas_address
,
261 Mpi2BootDeviceSasWwid_t
*boot_device
)
263 return (sas_address
== le64_to_cpu(boot_device
->SASAddress
)) ? 1 : 0;
267 * _scsih_srch_boot_device_name - search based on device name
268 * @device_name: device name specified in INDENTIFY fram
269 * @boot_device: boot device object from bios page 2
271 * Returns 1 when there's a match, 0 means no match.
274 _scsih_srch_boot_device_name(u64 device_name
,
275 Mpi2BootDeviceDeviceName_t
*boot_device
)
277 return (device_name
== le64_to_cpu(boot_device
->DeviceName
)) ? 1 : 0;
281 * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot
282 * @enclosure_logical_id: enclosure logical id
283 * @slot_number: slot number
284 * @boot_device: boot device object from bios page 2
286 * Returns 1 when there's a match, 0 means no match.
289 _scsih_srch_boot_encl_slot(u64 enclosure_logical_id
, u16 slot_number
,
290 Mpi2BootDeviceEnclosureSlot_t
*boot_device
)
292 return (enclosure_logical_id
== le64_to_cpu(boot_device
->
293 EnclosureLogicalID
) && slot_number
== le16_to_cpu(boot_device
->
294 SlotNumber
)) ? 1 : 0;
298 * _scsih_is_boot_device - search for matching boot device.
299 * @sas_address: sas address
300 * @device_name: device name specified in INDENTIFY fram
301 * @enclosure_logical_id: enclosure logical id
302 * @slot_number: slot number
303 * @form: specifies boot device form
304 * @boot_device: boot device object from bios page 2
306 * Returns 1 when there's a match, 0 means no match.
309 _scsih_is_boot_device(u64 sas_address
, u64 device_name
,
310 u64 enclosure_logical_id
, u16 slot
, u8 form
,
311 Mpi2BiosPage2BootDevice_t
*boot_device
)
316 case MPI2_BIOSPAGE2_FORM_SAS_WWID
:
319 rc
= _scsih_srch_boot_sas_address(
320 sas_address
, &boot_device
->SasWwid
);
322 case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT
:
323 if (!enclosure_logical_id
)
325 rc
= _scsih_srch_boot_encl_slot(
326 enclosure_logical_id
,
327 slot
, &boot_device
->EnclosureSlot
);
329 case MPI2_BIOSPAGE2_FORM_DEVICE_NAME
:
332 rc
= _scsih_srch_boot_device_name(
333 device_name
, &boot_device
->DeviceName
);
335 case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED
:
343 * _scsih_get_sas_address - set the sas_address for given device handle
344 * @handle: device handle
345 * @sas_address: sas address
347 * Returns 0 success, non-zero when failure
350 _scsih_get_sas_address(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
,
353 Mpi2SasDevicePage0_t sas_device_pg0
;
354 Mpi2ConfigReply_t mpi_reply
;
357 if (handle
<= ioc
->sas_hba
.num_phys
) {
358 *sas_address
= ioc
->sas_hba
.sas_address
;
363 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
364 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
365 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
366 ioc
->name
, __FILE__
, __LINE__
, __func__
);
370 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
372 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
373 printk(MPT2SAS_ERR_FMT
"handle(0x%04x), ioc_status(0x%04x)"
374 "\nfailure at %s:%d/%s()!\n", ioc
->name
, handle
, ioc_status
,
375 __FILE__
, __LINE__
, __func__
);
379 *sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
384 * _scsih_determine_boot_device - determine boot device.
385 * @ioc: per adapter object
386 * @device: either sas_device or raid_device object
387 * @is_raid: [flag] 1 = raid object, 0 = sas object
389 * Determines whether this device should be first reported device to
390 * to scsi-ml or sas transport, this purpose is for persistant boot device.
391 * There are primary, alternate, and current entries in bios page 2. The order
392 * priority is primary, alternate, then current. This routine saves
393 * the corresponding device object and is_raid flag in the ioc object.
394 * The saved data to be used later in _scsih_probe_boot_devices().
397 _scsih_determine_boot_device(struct MPT2SAS_ADAPTER
*ioc
,
398 void *device
, u8 is_raid
)
400 struct _sas_device
*sas_device
;
401 struct _raid_device
*raid_device
;
404 u64 enclosure_logical_id
;
407 /* only process this function when driver loads */
408 if (!ioc
->wait_for_port_enable_to_complete
)
413 sas_address
= sas_device
->sas_address
;
414 device_name
= sas_device
->device_name
;
415 enclosure_logical_id
= sas_device
->enclosure_logical_id
;
416 slot
= sas_device
->slot
;
418 raid_device
= device
;
419 sas_address
= raid_device
->wwid
;
421 enclosure_logical_id
= 0;
425 if (!ioc
->req_boot_device
.device
) {
426 if (_scsih_is_boot_device(sas_address
, device_name
,
427 enclosure_logical_id
, slot
,
428 (ioc
->bios_pg2
.ReqBootDeviceForm
&
429 MPI2_BIOSPAGE2_FORM_MASK
),
430 &ioc
->bios_pg2
.RequestedBootDevice
)) {
431 dinitprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
432 "%s: req_boot_device(0x%016llx)\n",
434 (unsigned long long)sas_address
));
435 ioc
->req_boot_device
.device
= device
;
436 ioc
->req_boot_device
.is_raid
= is_raid
;
440 if (!ioc
->req_alt_boot_device
.device
) {
441 if (_scsih_is_boot_device(sas_address
, device_name
,
442 enclosure_logical_id
, slot
,
443 (ioc
->bios_pg2
.ReqAltBootDeviceForm
&
444 MPI2_BIOSPAGE2_FORM_MASK
),
445 &ioc
->bios_pg2
.RequestedAltBootDevice
)) {
446 dinitprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
447 "%s: req_alt_boot_device(0x%016llx)\n",
449 (unsigned long long)sas_address
));
450 ioc
->req_alt_boot_device
.device
= device
;
451 ioc
->req_alt_boot_device
.is_raid
= is_raid
;
455 if (!ioc
->current_boot_device
.device
) {
456 if (_scsih_is_boot_device(sas_address
, device_name
,
457 enclosure_logical_id
, slot
,
458 (ioc
->bios_pg2
.CurrentBootDeviceForm
&
459 MPI2_BIOSPAGE2_FORM_MASK
),
460 &ioc
->bios_pg2
.CurrentBootDevice
)) {
461 dinitprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
462 "%s: current_boot_device(0x%016llx)\n",
464 (unsigned long long)sas_address
));
465 ioc
->current_boot_device
.device
= device
;
466 ioc
->current_boot_device
.is_raid
= is_raid
;
472 * mpt2sas_scsih_sas_device_find_by_sas_address - sas device search
473 * @ioc: per adapter object
474 * @sas_address: sas address
475 * Context: Calling function should acquire ioc->sas_device_lock
477 * This searches for sas_device based on sas_address, then return sas_device
481 mpt2sas_scsih_sas_device_find_by_sas_address(struct MPT2SAS_ADAPTER
*ioc
,
484 struct _sas_device
*sas_device
, *r
;
487 /* check the sas_device_init_list */
488 list_for_each_entry(sas_device
, &ioc
->sas_device_init_list
,
490 if (sas_device
->sas_address
!= sas_address
)
496 /* then check the sas_device_list */
497 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
) {
498 if (sas_device
->sas_address
!= sas_address
)
508 * _scsih_sas_device_find_by_handle - sas device search
509 * @ioc: per adapter object
510 * @handle: sas device handle (assigned by firmware)
511 * Context: Calling function should acquire ioc->sas_device_lock
513 * This searches for sas_device based on sas_address, then return sas_device
516 static struct _sas_device
*
517 _scsih_sas_device_find_by_handle(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
519 struct _sas_device
*sas_device
, *r
;
522 if (ioc
->wait_for_port_enable_to_complete
) {
523 list_for_each_entry(sas_device
, &ioc
->sas_device_init_list
,
525 if (sas_device
->handle
!= handle
)
531 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
) {
532 if (sas_device
->handle
!= handle
)
544 * _scsih_sas_device_remove - remove sas_device from list.
545 * @ioc: per adapter object
546 * @sas_device: the sas_device object
547 * Context: This function will acquire ioc->sas_device_lock.
549 * Removing object and freeing associated memory from the ioc->sas_device_list.
552 _scsih_sas_device_remove(struct MPT2SAS_ADAPTER
*ioc
,
553 struct _sas_device
*sas_device
)
557 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
558 list_del(&sas_device
->list
);
559 memset(sas_device
, 0, sizeof(struct _sas_device
));
561 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
565 * _scsih_sas_device_add - insert sas_device to the list.
566 * @ioc: per adapter object
567 * @sas_device: the sas_device object
568 * Context: This function will acquire ioc->sas_device_lock.
570 * Adding new object to the ioc->sas_device_list.
573 _scsih_sas_device_add(struct MPT2SAS_ADAPTER
*ioc
,
574 struct _sas_device
*sas_device
)
578 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: handle"
579 "(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
, __func__
,
580 sas_device
->handle
, (unsigned long long)sas_device
->sas_address
));
582 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
583 list_add_tail(&sas_device
->list
, &ioc
->sas_device_list
);
584 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
586 if (!mpt2sas_transport_port_add(ioc
, sas_device
->handle
,
587 sas_device
->sas_address_parent
))
588 _scsih_sas_device_remove(ioc
, sas_device
);
592 * _scsih_sas_device_init_add - insert sas_device to the list.
593 * @ioc: per adapter object
594 * @sas_device: the sas_device object
595 * Context: This function will acquire ioc->sas_device_lock.
597 * Adding new object at driver load time to the ioc->sas_device_init_list.
600 _scsih_sas_device_init_add(struct MPT2SAS_ADAPTER
*ioc
,
601 struct _sas_device
*sas_device
)
605 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: handle"
606 "(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
, __func__
,
607 sas_device
->handle
, (unsigned long long)sas_device
->sas_address
));
609 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
610 list_add_tail(&sas_device
->list
, &ioc
->sas_device_init_list
);
611 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
612 _scsih_determine_boot_device(ioc
, sas_device
, 0);
616 * _scsih_raid_device_find_by_id - raid device search
617 * @ioc: per adapter object
618 * @id: sas device target id
619 * @channel: sas device channel
620 * Context: Calling function should acquire ioc->raid_device_lock
622 * This searches for raid_device based on target id, then return raid_device
625 static struct _raid_device
*
626 _scsih_raid_device_find_by_id(struct MPT2SAS_ADAPTER
*ioc
, int id
, int channel
)
628 struct _raid_device
*raid_device
, *r
;
631 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
632 if (raid_device
->id
== id
&& raid_device
->channel
== channel
) {
643 * _scsih_raid_device_find_by_handle - raid device search
644 * @ioc: per adapter object
645 * @handle: sas device handle (assigned by firmware)
646 * Context: Calling function should acquire ioc->raid_device_lock
648 * This searches for raid_device based on handle, then return raid_device
651 static struct _raid_device
*
652 _scsih_raid_device_find_by_handle(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
654 struct _raid_device
*raid_device
, *r
;
657 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
658 if (raid_device
->handle
!= handle
)
669 * _scsih_raid_device_find_by_wwid - raid device search
670 * @ioc: per adapter object
671 * @handle: sas device handle (assigned by firmware)
672 * Context: Calling function should acquire ioc->raid_device_lock
674 * This searches for raid_device based on wwid, then return raid_device
677 static struct _raid_device
*
678 _scsih_raid_device_find_by_wwid(struct MPT2SAS_ADAPTER
*ioc
, u64 wwid
)
680 struct _raid_device
*raid_device
, *r
;
683 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
684 if (raid_device
->wwid
!= wwid
)
695 * _scsih_raid_device_add - add raid_device object
696 * @ioc: per adapter object
697 * @raid_device: raid_device object
699 * This is added to the raid_device_list link list.
702 _scsih_raid_device_add(struct MPT2SAS_ADAPTER
*ioc
,
703 struct _raid_device
*raid_device
)
707 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: handle"
708 "(0x%04x), wwid(0x%016llx)\n", ioc
->name
, __func__
,
709 raid_device
->handle
, (unsigned long long)raid_device
->wwid
));
711 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
712 list_add_tail(&raid_device
->list
, &ioc
->raid_device_list
);
713 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
717 * _scsih_raid_device_remove - delete raid_device object
718 * @ioc: per adapter object
719 * @raid_device: raid_device object
721 * This is removed from the raid_device_list link list.
724 _scsih_raid_device_remove(struct MPT2SAS_ADAPTER
*ioc
,
725 struct _raid_device
*raid_device
)
729 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
730 list_del(&raid_device
->list
);
731 memset(raid_device
, 0, sizeof(struct _raid_device
));
733 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
737 * mpt2sas_scsih_expander_find_by_handle - expander device search
738 * @ioc: per adapter object
739 * @handle: expander handle (assigned by firmware)
740 * Context: Calling function should acquire ioc->sas_device_lock
742 * This searches for expander device based on handle, then returns the
746 mpt2sas_scsih_expander_find_by_handle(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
748 struct _sas_node
*sas_expander
, *r
;
751 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
752 if (sas_expander
->handle
!= handle
)
762 * mpt2sas_scsih_expander_find_by_sas_address - expander device search
763 * @ioc: per adapter object
764 * @sas_address: sas address
765 * Context: Calling function should acquire ioc->sas_node_lock.
767 * This searches for expander device based on sas_address, then returns the
771 mpt2sas_scsih_expander_find_by_sas_address(struct MPT2SAS_ADAPTER
*ioc
,
774 struct _sas_node
*sas_expander
, *r
;
777 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
778 if (sas_expander
->sas_address
!= sas_address
)
788 * _scsih_expander_node_add - insert expander device to the list.
789 * @ioc: per adapter object
790 * @sas_expander: the sas_device object
791 * Context: This function will acquire ioc->sas_node_lock.
793 * Adding new object to the ioc->sas_expander_list.
798 _scsih_expander_node_add(struct MPT2SAS_ADAPTER
*ioc
,
799 struct _sas_node
*sas_expander
)
803 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
804 list_add_tail(&sas_expander
->list
, &ioc
->sas_expander_list
);
805 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
809 * _scsih_is_end_device - determines if device is an end device
810 * @device_info: bitfield providing information about the device.
813 * Returns 1 if end device.
816 _scsih_is_end_device(u32 device_info
)
818 if (device_info
& MPI2_SAS_DEVICE_INFO_END_DEVICE
&&
819 ((device_info
& MPI2_SAS_DEVICE_INFO_SSP_TARGET
) |
820 (device_info
& MPI2_SAS_DEVICE_INFO_STP_TARGET
) |
821 (device_info
& MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)))
828 * mptscsih_get_scsi_lookup - returns scmd entry
829 * @ioc: per adapter object
830 * @smid: system request message index
832 * Returns the smid stored scmd pointer.
834 static struct scsi_cmnd
*
835 _scsih_scsi_lookup_get(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
837 return ioc
->scsi_lookup
[smid
- 1].scmd
;
841 * _scsih_scsi_lookup_find_by_scmd - scmd lookup
842 * @ioc: per adapter object
843 * @smid: system request message index
844 * @scmd: pointer to scsi command object
845 * Context: This function will acquire ioc->scsi_lookup_lock.
847 * This will search for a scmd pointer in the scsi_lookup array,
848 * returning the revelent smid. A returned value of zero means invalid.
851 _scsih_scsi_lookup_find_by_scmd(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_cmnd
858 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
860 for (i
= 0; i
< ioc
->scsiio_depth
; i
++) {
861 if (ioc
->scsi_lookup
[i
].scmd
== scmd
) {
862 smid
= ioc
->scsi_lookup
[i
].smid
;
867 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
872 * _scsih_scsi_lookup_find_by_target - search for matching channel:id
873 * @ioc: per adapter object
876 * Context: This function will acquire ioc->scsi_lookup_lock.
878 * This will search for a matching channel:id in the scsi_lookup array,
879 * returning 1 if found.
882 _scsih_scsi_lookup_find_by_target(struct MPT2SAS_ADAPTER
*ioc
, int id
,
889 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
891 for (i
= 0 ; i
< ioc
->scsiio_depth
; i
++) {
892 if (ioc
->scsi_lookup
[i
].scmd
&&
893 (ioc
->scsi_lookup
[i
].scmd
->device
->id
== id
&&
894 ioc
->scsi_lookup
[i
].scmd
->device
->channel
== channel
)) {
900 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
905 * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun
906 * @ioc: per adapter object
910 * Context: This function will acquire ioc->scsi_lookup_lock.
912 * This will search for a matching channel:id:lun in the scsi_lookup array,
913 * returning 1 if found.
916 _scsih_scsi_lookup_find_by_lun(struct MPT2SAS_ADAPTER
*ioc
, int id
,
917 unsigned int lun
, int channel
)
923 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
925 for (i
= 0 ; i
< ioc
->scsiio_depth
; i
++) {
926 if (ioc
->scsi_lookup
[i
].scmd
&&
927 (ioc
->scsi_lookup
[i
].scmd
->device
->id
== id
&&
928 ioc
->scsi_lookup
[i
].scmd
->device
->channel
== channel
&&
929 ioc
->scsi_lookup
[i
].scmd
->device
->lun
== lun
)) {
935 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
940 * _scsih_get_chain_buffer_dma - obtain block of chains (dma address)
941 * @ioc: per adapter object
942 * @smid: system request message index
944 * Returns phys pointer to chain buffer.
947 _scsih_get_chain_buffer_dma(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
949 return ioc
->chain_dma
+ ((smid
- 1) * (ioc
->request_sz
*
950 ioc
->chains_needed_per_io
));
954 * _scsih_get_chain_buffer - obtain block of chains assigned to a mf request
955 * @ioc: per adapter object
956 * @smid: system request message index
958 * Returns virt pointer to chain buffer.
961 _scsih_get_chain_buffer(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
963 return (void *)(ioc
->chain
+ ((smid
- 1) * (ioc
->request_sz
*
964 ioc
->chains_needed_per_io
)));
968 * _scsih_build_scatter_gather - main sg creation routine
969 * @ioc: per adapter object
970 * @scmd: scsi command
971 * @smid: system request message index
974 * The main routine that builds scatter gather table from a given
975 * scsi request sent via the .queuecommand main handler.
977 * Returns 0 success, anything else error
980 _scsih_build_scatter_gather(struct MPT2SAS_ADAPTER
*ioc
,
981 struct scsi_cmnd
*scmd
, u16 smid
)
983 Mpi2SCSIIORequest_t
*mpi_request
;
984 dma_addr_t chain_dma
;
985 struct scatterlist
*sg_scmd
;
986 void *sg_local
, *chain
;
993 u32 sgl_flags_last_element
;
994 u32 sgl_flags_end_buffer
;
996 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
998 /* init scatter gather flags */
999 sgl_flags
= MPI2_SGE_FLAGS_SIMPLE_ELEMENT
;
1000 if (scmd
->sc_data_direction
== DMA_TO_DEVICE
)
1001 sgl_flags
|= MPI2_SGE_FLAGS_HOST_TO_IOC
;
1002 sgl_flags_last_element
= (sgl_flags
| MPI2_SGE_FLAGS_LAST_ELEMENT
)
1003 << MPI2_SGE_FLAGS_SHIFT
;
1004 sgl_flags_end_buffer
= (sgl_flags
| MPI2_SGE_FLAGS_LAST_ELEMENT
|
1005 MPI2_SGE_FLAGS_END_OF_BUFFER
| MPI2_SGE_FLAGS_END_OF_LIST
)
1006 << MPI2_SGE_FLAGS_SHIFT
;
1007 sgl_flags
= sgl_flags
<< MPI2_SGE_FLAGS_SHIFT
;
1009 sg_scmd
= scsi_sglist(scmd
);
1010 sges_left
= scsi_dma_map(scmd
);
1012 sdev_printk(KERN_ERR
, scmd
->device
, "pci_map_sg"
1013 " failed: request for %d bytes!\n", scsi_bufflen(scmd
));
1017 sg_local
= &mpi_request
->SGL
;
1018 sges_in_segment
= ioc
->max_sges_in_main_message
;
1019 if (sges_left
<= sges_in_segment
)
1020 goto fill_in_last_segment
;
1022 mpi_request
->ChainOffset
= (offsetof(Mpi2SCSIIORequest_t
, SGL
) +
1023 (sges_in_segment
* ioc
->sge_size
))/4;
1025 /* fill in main message segment when there is a chain following */
1026 while (sges_in_segment
) {
1027 if (sges_in_segment
== 1)
1028 ioc
->base_add_sg_single(sg_local
,
1029 sgl_flags_last_element
| sg_dma_len(sg_scmd
),
1030 sg_dma_address(sg_scmd
));
1032 ioc
->base_add_sg_single(sg_local
, sgl_flags
|
1033 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
1034 sg_scmd
= sg_next(sg_scmd
);
1035 sg_local
+= ioc
->sge_size
;
1040 /* initializing the chain flags and pointers */
1041 chain_flags
= MPI2_SGE_FLAGS_CHAIN_ELEMENT
<< MPI2_SGE_FLAGS_SHIFT
;
1042 chain
= _scsih_get_chain_buffer(ioc
, smid
);
1043 chain_dma
= _scsih_get_chain_buffer_dma(ioc
, smid
);
1045 sges_in_segment
= (sges_left
<=
1046 ioc
->max_sges_in_chain_message
) ? sges_left
:
1047 ioc
->max_sges_in_chain_message
;
1048 chain_offset
= (sges_left
== sges_in_segment
) ?
1049 0 : (sges_in_segment
* ioc
->sge_size
)/4;
1050 chain_length
= sges_in_segment
* ioc
->sge_size
;
1052 chain_offset
= chain_offset
<<
1053 MPI2_SGE_CHAIN_OFFSET_SHIFT
;
1054 chain_length
+= ioc
->sge_size
;
1056 ioc
->base_add_sg_single(sg_local
, chain_flags
| chain_offset
|
1057 chain_length
, chain_dma
);
1060 goto fill_in_last_segment
;
1062 /* fill in chain segments */
1063 while (sges_in_segment
) {
1064 if (sges_in_segment
== 1)
1065 ioc
->base_add_sg_single(sg_local
,
1066 sgl_flags_last_element
|
1067 sg_dma_len(sg_scmd
),
1068 sg_dma_address(sg_scmd
));
1070 ioc
->base_add_sg_single(sg_local
, sgl_flags
|
1071 sg_dma_len(sg_scmd
),
1072 sg_dma_address(sg_scmd
));
1073 sg_scmd
= sg_next(sg_scmd
);
1074 sg_local
+= ioc
->sge_size
;
1079 chain_dma
+= ioc
->request_sz
;
1080 chain
+= ioc
->request_sz
;
1084 fill_in_last_segment
:
1086 /* fill the last segment */
1089 ioc
->base_add_sg_single(sg_local
, sgl_flags_end_buffer
|
1090 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
1092 ioc
->base_add_sg_single(sg_local
, sgl_flags
|
1093 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
1094 sg_scmd
= sg_next(sg_scmd
);
1095 sg_local
+= ioc
->sge_size
;
1103 * _scsih_change_queue_depth - setting device queue depth
1104 * @sdev: scsi device struct
1105 * @qdepth: requested queue depth
1106 * @reason: calling context
1108 * Returns queue depth.
1111 _scsih_change_queue_depth(struct scsi_device
*sdev
, int qdepth
, int reason
)
1113 struct Scsi_Host
*shost
= sdev
->host
;
1116 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1117 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1118 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1119 struct _sas_device
*sas_device
;
1120 unsigned long flags
;
1122 if (reason
!= SCSI_QDEPTH_DEFAULT
)
1125 max_depth
= shost
->can_queue
;
1127 /* limit max device queue for SATA to 32 */
1128 sas_device_priv_data
= sdev
->hostdata
;
1129 if (!sas_device_priv_data
)
1131 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
1132 if (!sas_target_priv_data
)
1134 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
))
1136 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1137 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1138 sas_device_priv_data
->sas_target
->sas_address
);
1139 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1140 if (sas_device
&& sas_device
->device_info
&
1141 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1142 max_depth
= MPT2SAS_SATA_QUEUE_DEPTH
;
1146 if (!sdev
->tagged_supported
)
1148 if (qdepth
> max_depth
)
1150 tag_type
= (qdepth
== 1) ? 0 : MSG_SIMPLE_TAG
;
1151 scsi_adjust_queue_depth(sdev
, tag_type
, qdepth
);
1153 if (sdev
->inquiry_len
> 7)
1154 sdev_printk(KERN_INFO
, sdev
, "qdepth(%d), tagged(%d), "
1155 "simple(%d), ordered(%d), scsi_level(%d), cmd_que(%d)\n",
1156 sdev
->queue_depth
, sdev
->tagged_supported
, sdev
->simple_tags
,
1157 sdev
->ordered_tags
, sdev
->scsi_level
,
1158 (sdev
->inquiry
[7] & 2) >> 1);
1160 return sdev
->queue_depth
;
1164 * _scsih_change_queue_type - changing device queue tag type
1165 * @sdev: scsi device struct
1166 * @tag_type: requested tag type
1168 * Returns queue tag type.
1171 _scsih_change_queue_type(struct scsi_device
*sdev
, int tag_type
)
1173 if (sdev
->tagged_supported
) {
1174 scsi_set_tag_type(sdev
, tag_type
);
1176 scsi_activate_tcq(sdev
, sdev
->queue_depth
);
1178 scsi_deactivate_tcq(sdev
, sdev
->queue_depth
);
1186 * _scsih_target_alloc - target add routine
1187 * @starget: scsi target struct
1189 * Returns 0 if ok. Any other return is assumed to be an error and
1190 * the device is ignored.
1193 _scsih_target_alloc(struct scsi_target
*starget
)
1195 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
1196 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1197 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1198 struct _sas_device
*sas_device
;
1199 struct _raid_device
*raid_device
;
1200 unsigned long flags
;
1201 struct sas_rphy
*rphy
;
1203 sas_target_priv_data
= kzalloc(sizeof(struct scsi_target
), GFP_KERNEL
);
1204 if (!sas_target_priv_data
)
1207 starget
->hostdata
= sas_target_priv_data
;
1208 sas_target_priv_data
->starget
= starget
;
1209 sas_target_priv_data
->handle
= MPT2SAS_INVALID_DEVICE_HANDLE
;
1212 if (starget
->channel
== RAID_CHANNEL
) {
1213 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1214 raid_device
= _scsih_raid_device_find_by_id(ioc
, starget
->id
,
1217 sas_target_priv_data
->handle
= raid_device
->handle
;
1218 sas_target_priv_data
->sas_address
= raid_device
->wwid
;
1219 sas_target_priv_data
->flags
|= MPT_TARGET_FLAGS_VOLUME
;
1220 raid_device
->starget
= starget
;
1222 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1226 /* sas/sata devices */
1227 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1228 rphy
= dev_to_rphy(starget
->dev
.parent
);
1229 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1230 rphy
->identify
.sas_address
);
1233 sas_target_priv_data
->handle
= sas_device
->handle
;
1234 sas_target_priv_data
->sas_address
= sas_device
->sas_address
;
1235 sas_device
->starget
= starget
;
1236 sas_device
->id
= starget
->id
;
1237 sas_device
->channel
= starget
->channel
;
1238 if (sas_device
->hidden_raid_component
)
1239 sas_target_priv_data
->flags
|=
1240 MPT_TARGET_FLAGS_RAID_COMPONENT
;
1242 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1248 * _scsih_target_destroy - target destroy routine
1249 * @starget: scsi target struct
1254 _scsih_target_destroy(struct scsi_target
*starget
)
1256 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
1257 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1258 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1259 struct _sas_device
*sas_device
;
1260 struct _raid_device
*raid_device
;
1261 unsigned long flags
;
1262 struct sas_rphy
*rphy
;
1264 sas_target_priv_data
= starget
->hostdata
;
1265 if (!sas_target_priv_data
)
1268 if (starget
->channel
== RAID_CHANNEL
) {
1269 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1270 raid_device
= _scsih_raid_device_find_by_id(ioc
, starget
->id
,
1273 raid_device
->starget
= NULL
;
1274 raid_device
->sdev
= NULL
;
1276 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1280 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1281 rphy
= dev_to_rphy(starget
->dev
.parent
);
1282 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1283 rphy
->identify
.sas_address
);
1284 if (sas_device
&& (sas_device
->starget
== starget
) &&
1285 (sas_device
->id
== starget
->id
) &&
1286 (sas_device
->channel
== starget
->channel
))
1287 sas_device
->starget
= NULL
;
1289 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1292 kfree(sas_target_priv_data
);
1293 starget
->hostdata
= NULL
;
1297 * _scsih_slave_alloc - device add routine
1298 * @sdev: scsi device struct
1300 * Returns 0 if ok. Any other return is assumed to be an error and
1301 * the device is ignored.
1304 _scsih_slave_alloc(struct scsi_device
*sdev
)
1306 struct Scsi_Host
*shost
;
1307 struct MPT2SAS_ADAPTER
*ioc
;
1308 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1309 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1310 struct scsi_target
*starget
;
1311 struct _raid_device
*raid_device
;
1312 unsigned long flags
;
1314 sas_device_priv_data
= kzalloc(sizeof(struct scsi_device
), GFP_KERNEL
);
1315 if (!sas_device_priv_data
)
1318 sas_device_priv_data
->lun
= sdev
->lun
;
1319 sas_device_priv_data
->flags
= MPT_DEVICE_FLAGS_INIT
;
1321 starget
= scsi_target(sdev
);
1322 sas_target_priv_data
= starget
->hostdata
;
1323 sas_target_priv_data
->num_luns
++;
1324 sas_device_priv_data
->sas_target
= sas_target_priv_data
;
1325 sdev
->hostdata
= sas_device_priv_data
;
1326 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
))
1327 sdev
->no_uld_attach
= 1;
1329 shost
= dev_to_shost(&starget
->dev
);
1330 ioc
= shost_priv(shost
);
1331 if (starget
->channel
== RAID_CHANNEL
) {
1332 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1333 raid_device
= _scsih_raid_device_find_by_id(ioc
,
1334 starget
->id
, starget
->channel
);
1336 raid_device
->sdev
= sdev
; /* raid is single lun */
1337 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1344 * _scsih_slave_destroy - device destroy routine
1345 * @sdev: scsi device struct
1350 _scsih_slave_destroy(struct scsi_device
*sdev
)
1352 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1353 struct scsi_target
*starget
;
1355 if (!sdev
->hostdata
)
1358 starget
= scsi_target(sdev
);
1359 sas_target_priv_data
= starget
->hostdata
;
1360 sas_target_priv_data
->num_luns
--;
1361 kfree(sdev
->hostdata
);
1362 sdev
->hostdata
= NULL
;
1366 * _scsih_display_sata_capabilities - sata capabilities
1367 * @ioc: per adapter object
1368 * @sas_device: the sas_device object
1369 * @sdev: scsi device struct
1372 _scsih_display_sata_capabilities(struct MPT2SAS_ADAPTER
*ioc
,
1373 struct _sas_device
*sas_device
, struct scsi_device
*sdev
)
1375 Mpi2ConfigReply_t mpi_reply
;
1376 Mpi2SasDevicePage0_t sas_device_pg0
;
1381 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
1382 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, sas_device
->handle
))) {
1383 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1384 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1388 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
1389 MPI2_IOCSTATUS_MASK
;
1390 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
1391 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1392 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1396 flags
= le16_to_cpu(sas_device_pg0
.Flags
);
1397 device_info
= le16_to_cpu(sas_device_pg0
.DeviceInfo
);
1399 sdev_printk(KERN_INFO
, sdev
,
1400 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1401 "sw_preserve(%s)\n",
1402 (device_info
& MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE
) ? "y" : "n",
1403 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED
) ? "y" : "n",
1404 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY
) ? "y" :
1406 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED
) ? "y" : "n",
1407 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED
) ? "y" : "n",
1408 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE
) ? "y" : "n");
1412 * _scsih_is_raid - return boolean indicating device is raid volume
1413 * @dev the device struct object
1416 _scsih_is_raid(struct device
*dev
)
1418 struct scsi_device
*sdev
= to_scsi_device(dev
);
1420 return (sdev
->channel
== RAID_CHANNEL
) ? 1 : 0;
1424 * _scsih_get_resync - get raid volume resync percent complete
1425 * @dev the device struct object
1428 _scsih_get_resync(struct device
*dev
)
1430 struct scsi_device
*sdev
= to_scsi_device(dev
);
1431 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
1432 static struct _raid_device
*raid_device
;
1433 unsigned long flags
;
1434 Mpi2RaidVolPage0_t vol_pg0
;
1435 Mpi2ConfigReply_t mpi_reply
;
1436 u32 volume_status_flags
;
1437 u8 percent_complete
= 0;
1439 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1440 raid_device
= _scsih_raid_device_find_by_id(ioc
, sdev
->id
,
1442 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1447 if (mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, &vol_pg0
,
1448 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, raid_device
->handle
,
1449 sizeof(Mpi2RaidVolPage0_t
))) {
1450 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1451 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1455 volume_status_flags
= le32_to_cpu(vol_pg0
.VolumeStatusFlags
);
1456 if (volume_status_flags
& MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS
)
1457 percent_complete
= raid_device
->percent_complete
;
1459 raid_set_resync(mpt2sas_raid_template
, dev
, percent_complete
);
1463 * _scsih_get_state - get raid volume level
1464 * @dev the device struct object
1467 _scsih_get_state(struct device
*dev
)
1469 struct scsi_device
*sdev
= to_scsi_device(dev
);
1470 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
1471 static struct _raid_device
*raid_device
;
1472 unsigned long flags
;
1473 Mpi2RaidVolPage0_t vol_pg0
;
1474 Mpi2ConfigReply_t mpi_reply
;
1476 enum raid_state state
= RAID_STATE_UNKNOWN
;
1478 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1479 raid_device
= _scsih_raid_device_find_by_id(ioc
, sdev
->id
,
1481 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1486 if (mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, &vol_pg0
,
1487 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, raid_device
->handle
,
1488 sizeof(Mpi2RaidVolPage0_t
))) {
1489 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1490 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1494 volstate
= le32_to_cpu(vol_pg0
.VolumeStatusFlags
);
1495 if (volstate
& MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS
) {
1496 state
= RAID_STATE_RESYNCING
;
1500 switch (vol_pg0
.VolumeState
) {
1501 case MPI2_RAID_VOL_STATE_OPTIMAL
:
1502 case MPI2_RAID_VOL_STATE_ONLINE
:
1503 state
= RAID_STATE_ACTIVE
;
1505 case MPI2_RAID_VOL_STATE_DEGRADED
:
1506 state
= RAID_STATE_DEGRADED
;
1508 case MPI2_RAID_VOL_STATE_FAILED
:
1509 case MPI2_RAID_VOL_STATE_MISSING
:
1510 state
= RAID_STATE_OFFLINE
;
1514 raid_set_state(mpt2sas_raid_template
, dev
, state
);
1518 * _scsih_set_level - set raid level
1519 * @sdev: scsi device struct
1520 * @raid_device: raid_device object
1523 _scsih_set_level(struct scsi_device
*sdev
, struct _raid_device
*raid_device
)
1525 enum raid_level level
= RAID_LEVEL_UNKNOWN
;
1527 switch (raid_device
->volume_type
) {
1528 case MPI2_RAID_VOL_TYPE_RAID0
:
1529 level
= RAID_LEVEL_0
;
1531 case MPI2_RAID_VOL_TYPE_RAID10
:
1532 level
= RAID_LEVEL_10
;
1534 case MPI2_RAID_VOL_TYPE_RAID1E
:
1535 level
= RAID_LEVEL_1E
;
1537 case MPI2_RAID_VOL_TYPE_RAID1
:
1538 level
= RAID_LEVEL_1
;
1542 raid_set_level(mpt2sas_raid_template
, &sdev
->sdev_gendev
, level
);
1546 * _scsih_get_volume_capabilities - volume capabilities
1547 * @ioc: per adapter object
1548 * @sas_device: the raid_device object
1551 _scsih_get_volume_capabilities(struct MPT2SAS_ADAPTER
*ioc
,
1552 struct _raid_device
*raid_device
)
1554 Mpi2RaidVolPage0_t
*vol_pg0
;
1555 Mpi2RaidPhysDiskPage0_t pd_pg0
;
1556 Mpi2SasDevicePage0_t sas_device_pg0
;
1557 Mpi2ConfigReply_t mpi_reply
;
1561 if ((mpt2sas_config_get_number_pds(ioc
, raid_device
->handle
,
1562 &num_pds
)) || !num_pds
) {
1563 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1564 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1568 raid_device
->num_pds
= num_pds
;
1569 sz
= offsetof(Mpi2RaidVolPage0_t
, PhysDisk
) + (num_pds
*
1570 sizeof(Mpi2RaidVol0PhysDisk_t
));
1571 vol_pg0
= kzalloc(sz
, GFP_KERNEL
);
1573 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1574 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1578 if ((mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, vol_pg0
,
1579 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, raid_device
->handle
, sz
))) {
1580 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1581 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1586 raid_device
->volume_type
= vol_pg0
->VolumeType
;
1588 /* figure out what the underlying devices are by
1589 * obtaining the device_info bits for the 1st device
1591 if (!(mpt2sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
1592 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM
,
1593 vol_pg0
->PhysDisk
[0].PhysDiskNum
))) {
1594 if (!(mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
1595 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
1596 le16_to_cpu(pd_pg0
.DevHandle
)))) {
1597 raid_device
->device_info
=
1598 le32_to_cpu(sas_device_pg0
.DeviceInfo
);
1606 * _scsih_enable_tlr - setting TLR flags
1607 * @ioc: per adapter object
1608 * @sdev: scsi device struct
1610 * Enabling Transaction Layer Retries for tape devices when
1611 * vpd page 0x90 is present
1615 _scsih_enable_tlr(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_device
*sdev
)
1618 if (sdev
->type
!= TYPE_TAPE
)
1621 if (!(ioc
->facts
.IOCCapabilities
& MPI2_IOCFACTS_CAPABILITY_TLR
))
1624 sas_enable_tlr(sdev
);
1625 sdev_printk(KERN_INFO
, sdev
, "TLR %s\n",
1626 sas_is_tlr_enabled(sdev
) ? "Enabled" : "Disabled");
1632 * _scsih_slave_configure - device configure routine.
1633 * @sdev: scsi device struct
1635 * Returns 0 if ok. Any other return is assumed to be an error and
1636 * the device is ignored.
1639 _scsih_slave_configure(struct scsi_device
*sdev
)
1641 struct Scsi_Host
*shost
= sdev
->host
;
1642 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1643 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1644 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1645 struct _sas_device
*sas_device
;
1646 struct _raid_device
*raid_device
;
1647 unsigned long flags
;
1654 sas_device_priv_data
= sdev
->hostdata
;
1655 sas_device_priv_data
->configured_lun
= 1;
1656 sas_device_priv_data
->flags
&= ~MPT_DEVICE_FLAGS_INIT
;
1657 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
1659 /* raid volume handling */
1660 if (sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
1662 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1663 raid_device
= _scsih_raid_device_find_by_handle(ioc
,
1664 sas_target_priv_data
->handle
);
1665 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1667 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1668 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1672 _scsih_get_volume_capabilities(ioc
, raid_device
);
1674 /* RAID Queue Depth Support
1675 * IS volume = underlying qdepth of drive type, either
1676 * MPT2SAS_SAS_QUEUE_DEPTH or MPT2SAS_SATA_QUEUE_DEPTH
1677 * IM/IME/R10 = 128 (MPT2SAS_RAID_QUEUE_DEPTH)
1679 if (raid_device
->device_info
&
1680 MPI2_SAS_DEVICE_INFO_SSP_TARGET
) {
1681 qdepth
= MPT2SAS_SAS_QUEUE_DEPTH
;
1684 qdepth
= MPT2SAS_SATA_QUEUE_DEPTH
;
1685 if (raid_device
->device_info
&
1686 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1692 switch (raid_device
->volume_type
) {
1693 case MPI2_RAID_VOL_TYPE_RAID0
:
1696 case MPI2_RAID_VOL_TYPE_RAID1E
:
1697 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
1698 if (ioc
->manu_pg10
.OEMIdentifier
&&
1699 (ioc
->manu_pg10
.GenericFlags0
&
1700 MFG10_GF0_R10_DISPLAY
) &&
1701 !(raid_device
->num_pds
% 2))
1706 case MPI2_RAID_VOL_TYPE_RAID1
:
1707 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
1710 case MPI2_RAID_VOL_TYPE_RAID10
:
1711 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
1714 case MPI2_RAID_VOL_TYPE_UNKNOWN
:
1716 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
1721 sdev_printk(KERN_INFO
, sdev
, "%s: "
1722 "handle(0x%04x), wwid(0x%016llx), pd_count(%d), type(%s)\n",
1723 r_level
, raid_device
->handle
,
1724 (unsigned long long)raid_device
->wwid
,
1725 raid_device
->num_pds
, ds
);
1726 _scsih_change_queue_depth(sdev
, qdepth
, SCSI_QDEPTH_DEFAULT
);
1727 /* raid transport support */
1728 _scsih_set_level(sdev
, raid_device
);
1732 /* non-raid handling */
1733 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1734 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1735 sas_device_priv_data
->sas_target
->sas_address
);
1736 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1738 if (sas_target_priv_data
->flags
&
1739 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
1740 mpt2sas_config_get_volume_handle(ioc
,
1741 sas_device
->handle
, &sas_device
->volume_handle
);
1742 mpt2sas_config_get_volume_wwid(ioc
,
1743 sas_device
->volume_handle
,
1744 &sas_device
->volume_wwid
);
1746 if (sas_device
->device_info
& MPI2_SAS_DEVICE_INFO_SSP_TARGET
) {
1747 qdepth
= MPT2SAS_SAS_QUEUE_DEPTH
;
1751 qdepth
= MPT2SAS_SATA_QUEUE_DEPTH
;
1752 if (sas_device
->device_info
&
1753 MPI2_SAS_DEVICE_INFO_STP_TARGET
)
1755 else if (sas_device
->device_info
&
1756 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1760 sdev_printk(KERN_INFO
, sdev
, "%s: handle(0x%04x), "
1761 "sas_addr(0x%016llx), device_name(0x%016llx)\n",
1762 ds
, sas_device
->handle
,
1763 (unsigned long long)sas_device
->sas_address
,
1764 (unsigned long long)sas_device
->device_name
);
1765 sdev_printk(KERN_INFO
, sdev
, "%s: "
1766 "enclosure_logical_id(0x%016llx), slot(%d)\n", ds
,
1767 (unsigned long long) sas_device
->enclosure_logical_id
,
1771 _scsih_display_sata_capabilities(ioc
, sas_device
, sdev
);
1774 _scsih_change_queue_depth(sdev
, qdepth
, SCSI_QDEPTH_DEFAULT
);
1777 sas_read_port_mode_page(sdev
);
1778 _scsih_enable_tlr(ioc
, sdev
);
1784 * _scsih_bios_param - fetch head, sector, cylinder info for a disk
1785 * @sdev: scsi device struct
1786 * @bdev: pointer to block device context
1787 * @capacity: device size (in 512 byte sectors)
1788 * @params: three element array to place output:
1789 * params[0] number of heads (max 255)
1790 * params[1] number of sectors (max 63)
1791 * params[2] number of cylinders
1796 _scsih_bios_param(struct scsi_device
*sdev
, struct block_device
*bdev
,
1797 sector_t capacity
, int params
[])
1807 dummy
= heads
* sectors
;
1808 cylinders
= capacity
;
1809 sector_div(cylinders
, dummy
);
1812 * Handle extended translation size for logical drives
1815 if ((ulong
)capacity
>= 0x200000) {
1818 dummy
= heads
* sectors
;
1819 cylinders
= capacity
;
1820 sector_div(cylinders
, dummy
);
1825 params
[1] = sectors
;
1826 params
[2] = cylinders
;
1832 * _scsih_response_code - translation of device response code
1833 * @ioc: per adapter object
1834 * @response_code: response code returned by the device
1839 _scsih_response_code(struct MPT2SAS_ADAPTER
*ioc
, u8 response_code
)
1843 switch (response_code
) {
1844 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE
:
1845 desc
= "task management request completed";
1847 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
:
1848 desc
= "invalid frame";
1850 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED
:
1851 desc
= "task management request not supported";
1853 case MPI2_SCSITASKMGMT_RSP_TM_FAILED
:
1854 desc
= "task management request failed";
1856 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
:
1857 desc
= "task management request succeeded";
1859 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN
:
1860 desc
= "invalid lun";
1863 desc
= "overlapped tag attempted";
1865 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
:
1866 desc
= "task queued, however not sent to target";
1872 printk(MPT2SAS_WARN_FMT
"response_code(0x%01x): %s\n",
1873 ioc
->name
, response_code
, desc
);
1877 * _scsih_tm_done - tm completion routine
1878 * @ioc: per adapter object
1879 * @smid: system request message index
1880 * @msix_index: MSIX table index supplied by the OS
1881 * @reply: reply message frame(lower 32bit addr)
1884 * The callback handler when using scsih_issue_tm.
1886 * Return 1 meaning mf should be freed from _base_interrupt
1887 * 0 means the mf is freed from this function.
1890 _scsih_tm_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
1892 MPI2DefaultReply_t
*mpi_reply
;
1894 if (ioc
->tm_cmds
.status
== MPT2_CMD_NOT_USED
)
1896 if (ioc
->tm_cmds
.smid
!= smid
)
1898 ioc
->tm_cmds
.status
|= MPT2_CMD_COMPLETE
;
1899 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
1901 memcpy(ioc
->tm_cmds
.reply
, mpi_reply
, mpi_reply
->MsgLength
*4);
1902 ioc
->tm_cmds
.status
|= MPT2_CMD_REPLY_VALID
;
1904 ioc
->tm_cmds
.status
&= ~MPT2_CMD_PENDING
;
1905 complete(&ioc
->tm_cmds
.done
);
1910 * mpt2sas_scsih_set_tm_flag - set per target tm_busy
1911 * @ioc: per adapter object
1912 * @handle: device handle
1914 * During taskmangement request, we need to freeze the device queue.
1917 mpt2sas_scsih_set_tm_flag(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
1919 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1920 struct scsi_device
*sdev
;
1923 shost_for_each_device(sdev
, ioc
->shost
) {
1926 sas_device_priv_data
= sdev
->hostdata
;
1927 if (!sas_device_priv_data
)
1929 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
1930 sas_device_priv_data
->sas_target
->tm_busy
= 1;
1932 ioc
->ignore_loginfos
= 1;
1938 * mpt2sas_scsih_clear_tm_flag - clear per target tm_busy
1939 * @ioc: per adapter object
1940 * @handle: device handle
1942 * During taskmangement request, we need to freeze the device queue.
1945 mpt2sas_scsih_clear_tm_flag(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
1947 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1948 struct scsi_device
*sdev
;
1951 shost_for_each_device(sdev
, ioc
->shost
) {
1954 sas_device_priv_data
= sdev
->hostdata
;
1955 if (!sas_device_priv_data
)
1957 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
1958 sas_device_priv_data
->sas_target
->tm_busy
= 0;
1960 ioc
->ignore_loginfos
= 0;
1966 * mpt2sas_scsih_issue_tm - main routine for sending tm requests
1967 * @ioc: per adapter struct
1968 * @device_handle: device handle
1970 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
1971 * @smid_task: smid assigned to the task
1972 * @timeout: timeout in seconds
1973 * Context: The calling function needs to acquire the tm_cmds.mutex
1975 * A generic API for sending task management requests to firmware.
1977 * The ioc->tm_cmds.status flag should be MPT2_CMD_NOT_USED before calling
1980 * The callback index is set inside `ioc->tm_cb_idx`.
1985 mpt2sas_scsih_issue_tm(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
, uint lun
,
1986 u8 type
, u16 smid_task
, ulong timeout
)
1988 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
1989 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
1992 unsigned long timeleft
;
1994 if (ioc
->tm_cmds
.status
!= MPT2_CMD_NOT_USED
) {
1995 printk(MPT2SAS_INFO_FMT
"%s: tm_cmd busy!!!\n",
1996 __func__
, ioc
->name
);
2000 if (ioc
->shost_recovery
) {
2001 printk(MPT2SAS_INFO_FMT
"%s: host reset in progress!\n",
2002 __func__
, ioc
->name
);
2006 ioc_state
= mpt2sas_base_get_iocstate(ioc
, 0);
2007 if (ioc_state
& MPI2_DOORBELL_USED
) {
2008 dhsprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"unexpected doorbell "
2009 "active!\n", ioc
->name
));
2010 goto issue_host_reset
;
2013 if ((ioc_state
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_FAULT
) {
2014 mpt2sas_base_fault_info(ioc
, ioc_state
&
2015 MPI2_DOORBELL_DATA_MASK
);
2016 goto issue_host_reset
;
2019 smid
= mpt2sas_base_get_smid_hpr(ioc
, ioc
->tm_cb_idx
);
2021 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
2022 ioc
->name
, __func__
);
2026 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"sending tm: handle(0x%04x),"
2027 " task_type(0x%02x), smid(%d)\n", ioc
->name
, handle
, type
,
2029 ioc
->tm_cmds
.status
= MPT2_CMD_PENDING
;
2030 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
2031 ioc
->tm_cmds
.smid
= smid
;
2032 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
2033 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
2034 mpi_request
->DevHandle
= cpu_to_le16(handle
);
2035 mpi_request
->TaskType
= type
;
2036 mpi_request
->TaskMID
= cpu_to_le16(smid_task
);
2037 mpi_request
->VP_ID
= 0; /* TODO */
2038 mpi_request
->VF_ID
= 0;
2039 int_to_scsilun(lun
, (struct scsi_lun
*)mpi_request
->LUN
);
2040 mpt2sas_scsih_set_tm_flag(ioc
, handle
);
2041 init_completion(&ioc
->tm_cmds
.done
);
2042 mpt2sas_base_put_smid_hi_priority(ioc
, smid
);
2043 timeleft
= wait_for_completion_timeout(&ioc
->tm_cmds
.done
, timeout
*HZ
);
2044 mpt2sas_scsih_clear_tm_flag(ioc
, handle
);
2045 if (!(ioc
->tm_cmds
.status
& MPT2_CMD_COMPLETE
)) {
2046 printk(MPT2SAS_ERR_FMT
"%s: timeout\n",
2047 ioc
->name
, __func__
);
2048 _debug_dump_mf(mpi_request
,
2049 sizeof(Mpi2SCSITaskManagementRequest_t
)/4);
2050 if (!(ioc
->tm_cmds
.status
& MPT2_CMD_RESET
))
2051 goto issue_host_reset
;
2054 if (ioc
->tm_cmds
.status
& MPT2_CMD_REPLY_VALID
) {
2055 mpi_reply
= ioc
->tm_cmds
.reply
;
2056 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"complete tm: "
2057 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
2058 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
2059 le32_to_cpu(mpi_reply
->IOCLogInfo
),
2060 le32_to_cpu(mpi_reply
->TerminationCount
)));
2061 if (ioc
->logging_level
& MPT_DEBUG_TM
)
2062 _scsih_response_code(ioc
, mpi_reply
->ResponseCode
);
2066 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
, FORCE_BIG_HAMMER
);
2070 * _scsih_abort - eh threads main abort routine
2071 * @sdev: scsi device struct
2073 * Returns SUCCESS if command aborted else FAILED
2076 _scsih_abort(struct scsi_cmnd
*scmd
)
2078 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2079 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2083 struct scsi_cmnd
*scmd_lookup
;
2085 printk(MPT2SAS_INFO_FMT
"attempting task abort! scmd(%p)\n",
2087 scsi_print_command(scmd
);
2089 sas_device_priv_data
= scmd
->device
->hostdata
;
2090 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2091 printk(MPT2SAS_INFO_FMT
"device been deleted! scmd(%p)\n",
2093 scmd
->result
= DID_NO_CONNECT
<< 16;
2094 scmd
->scsi_done(scmd
);
2099 /* search for the command */
2100 smid
= _scsih_scsi_lookup_find_by_scmd(ioc
, scmd
);
2102 scmd
->result
= DID_RESET
<< 16;
2107 /* for hidden raid components and volumes this is not supported */
2108 if (sas_device_priv_data
->sas_target
->flags
&
2109 MPT_TARGET_FLAGS_RAID_COMPONENT
||
2110 sas_device_priv_data
->sas_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
2111 scmd
->result
= DID_RESET
<< 16;
2116 mpt2sas_halt_firmware(ioc
);
2118 mutex_lock(&ioc
->tm_cmds
.mutex
);
2119 handle
= sas_device_priv_data
->sas_target
->handle
;
2120 mpt2sas_scsih_issue_tm(ioc
, handle
, sas_device_priv_data
->lun
,
2121 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
, smid
, 30);
2123 /* sanity check - see whether command actually completed */
2124 scmd_lookup
= _scsih_scsi_lookup_get(ioc
, smid
);
2125 if (scmd_lookup
&& (scmd_lookup
->serial_number
== scmd
->serial_number
))
2129 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
2130 mutex_unlock(&ioc
->tm_cmds
.mutex
);
2133 printk(MPT2SAS_INFO_FMT
"task abort: %s scmd(%p)\n",
2134 ioc
->name
, ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2139 * _scsih_dev_reset - eh threads main device reset routine
2140 * @sdev: scsi device struct
2142 * Returns SUCCESS if command aborted else FAILED
2145 _scsih_dev_reset(struct scsi_cmnd
*scmd
)
2147 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2148 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2149 struct _sas_device
*sas_device
;
2150 unsigned long flags
;
2154 printk(MPT2SAS_INFO_FMT
"attempting device reset! scmd(%p)\n",
2156 scsi_print_command(scmd
);
2158 sas_device_priv_data
= scmd
->device
->hostdata
;
2159 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2160 printk(MPT2SAS_INFO_FMT
"device been deleted! scmd(%p)\n",
2162 scmd
->result
= DID_NO_CONNECT
<< 16;
2163 scmd
->scsi_done(scmd
);
2168 /* for hidden raid components obtain the volume_handle */
2170 if (sas_device_priv_data
->sas_target
->flags
&
2171 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2172 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2173 sas_device
= _scsih_sas_device_find_by_handle(ioc
,
2174 sas_device_priv_data
->sas_target
->handle
);
2176 handle
= sas_device
->volume_handle
;
2177 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2179 handle
= sas_device_priv_data
->sas_target
->handle
;
2182 scmd
->result
= DID_RESET
<< 16;
2187 mutex_lock(&ioc
->tm_cmds
.mutex
);
2188 mpt2sas_scsih_issue_tm(ioc
, handle
, 0,
2189 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET
, scmd
->device
->lun
,
2193 * sanity check see whether all commands to this device been
2196 if (_scsih_scsi_lookup_find_by_lun(ioc
, scmd
->device
->id
,
2197 scmd
->device
->lun
, scmd
->device
->channel
))
2201 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
2202 mutex_unlock(&ioc
->tm_cmds
.mutex
);
2205 printk(MPT2SAS_INFO_FMT
"device reset: %s scmd(%p)\n",
2206 ioc
->name
, ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2211 * _scsih_target_reset - eh threads main target reset routine
2212 * @sdev: scsi device struct
2214 * Returns SUCCESS if command aborted else FAILED
2217 _scsih_target_reset(struct scsi_cmnd
*scmd
)
2219 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2220 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2221 struct _sas_device
*sas_device
;
2222 unsigned long flags
;
2226 printk(MPT2SAS_INFO_FMT
"attempting target reset! scmd(%p)\n",
2228 scsi_print_command(scmd
);
2230 sas_device_priv_data
= scmd
->device
->hostdata
;
2231 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2232 printk(MPT2SAS_INFO_FMT
"target been deleted! scmd(%p)\n",
2234 scmd
->result
= DID_NO_CONNECT
<< 16;
2235 scmd
->scsi_done(scmd
);
2240 /* for hidden raid components obtain the volume_handle */
2242 if (sas_device_priv_data
->sas_target
->flags
&
2243 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2244 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2245 sas_device
= _scsih_sas_device_find_by_handle(ioc
,
2246 sas_device_priv_data
->sas_target
->handle
);
2248 handle
= sas_device
->volume_handle
;
2249 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2251 handle
= sas_device_priv_data
->sas_target
->handle
;
2254 scmd
->result
= DID_RESET
<< 16;
2259 mutex_lock(&ioc
->tm_cmds
.mutex
);
2260 mpt2sas_scsih_issue_tm(ioc
, handle
, 0,
2261 MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
, 0, 30);
2264 * sanity check see whether all commands to this target been
2267 if (_scsih_scsi_lookup_find_by_target(ioc
, scmd
->device
->id
,
2268 scmd
->device
->channel
))
2272 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
2273 mutex_unlock(&ioc
->tm_cmds
.mutex
);
2276 printk(MPT2SAS_INFO_FMT
"target reset: %s scmd(%p)\n",
2277 ioc
->name
, ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2282 * _scsih_host_reset - eh threads main host reset routine
2283 * @sdev: scsi device struct
2285 * Returns SUCCESS if command aborted else FAILED
2288 _scsih_host_reset(struct scsi_cmnd
*scmd
)
2290 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2293 printk(MPT2SAS_INFO_FMT
"attempting host reset! scmd(%p)\n",
2295 scsi_print_command(scmd
);
2297 retval
= mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2299 r
= (retval
< 0) ? FAILED
: SUCCESS
;
2300 printk(MPT2SAS_INFO_FMT
"host reset: %s scmd(%p)\n",
2301 ioc
->name
, ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2307 * _scsih_fw_event_add - insert and queue up fw_event
2308 * @ioc: per adapter object
2309 * @fw_event: object describing the event
2310 * Context: This function will acquire ioc->fw_event_lock.
2312 * This adds the firmware event object into link list, then queues it up to
2313 * be processed from user context.
2318 _scsih_fw_event_add(struct MPT2SAS_ADAPTER
*ioc
, struct fw_event_work
*fw_event
)
2320 unsigned long flags
;
2322 if (ioc
->firmware_event_thread
== NULL
)
2325 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2326 list_add_tail(&fw_event
->list
, &ioc
->fw_event_list
);
2327 INIT_WORK(&fw_event
->work
, _firmware_event_work
);
2328 queue_work(ioc
->firmware_event_thread
, &fw_event
->work
);
2329 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2333 * _scsih_fw_event_free - delete fw_event
2334 * @ioc: per adapter object
2335 * @fw_event: object describing the event
2336 * Context: This function will acquire ioc->fw_event_lock.
2338 * This removes firmware event object from link list, frees associated memory.
2343 _scsih_fw_event_free(struct MPT2SAS_ADAPTER
*ioc
, struct fw_event_work
2346 unsigned long flags
;
2348 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2349 list_del(&fw_event
->list
);
2350 kfree(fw_event
->event_data
);
2352 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2356 * _scsih_fw_event_add - requeue an event
2357 * @ioc: per adapter object
2358 * @fw_event: object describing the event
2359 * Context: This function will acquire ioc->fw_event_lock.
2364 _scsih_fw_event_requeue(struct MPT2SAS_ADAPTER
*ioc
, struct fw_event_work
2365 *fw_event
, unsigned long delay
)
2367 unsigned long flags
;
2368 if (ioc
->firmware_event_thread
== NULL
)
2371 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2372 queue_work(ioc
->firmware_event_thread
, &fw_event
->work
);
2373 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2377 * _scsih_fw_event_off - turn flag off preventing event handling
2378 * @ioc: per adapter object
2380 * Used to prevent handling of firmware events during adapter reset
2386 _scsih_fw_event_off(struct MPT2SAS_ADAPTER
*ioc
)
2388 unsigned long flags
;
2390 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2391 ioc
->fw_events_off
= 1;
2392 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2397 * _scsih_fw_event_on - turn flag on allowing firmware event handling
2398 * @ioc: per adapter object
2403 _scsih_fw_event_on(struct MPT2SAS_ADAPTER
*ioc
)
2405 unsigned long flags
;
2407 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2408 ioc
->fw_events_off
= 0;
2409 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2413 * _scsih_ublock_io_device - set the device state to SDEV_RUNNING
2414 * @ioc: per adapter object
2415 * @handle: device handle
2417 * During device pull we need to appropiately set the sdev state.
2420 _scsih_ublock_io_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
2422 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2423 struct scsi_device
*sdev
;
2425 shost_for_each_device(sdev
, ioc
->shost
) {
2426 sas_device_priv_data
= sdev
->hostdata
;
2427 if (!sas_device_priv_data
)
2429 if (!sas_device_priv_data
->block
)
2431 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2432 dewtprintk(ioc
, sdev_printk(KERN_INFO
, sdev
,
2433 MPT2SAS_INFO_FMT
"SDEV_RUNNING: "
2434 "handle(0x%04x)\n", ioc
->name
, handle
));
2435 sas_device_priv_data
->block
= 0;
2436 scsi_internal_device_unblock(sdev
);
2442 * _scsih_block_io_device - set the device state to SDEV_BLOCK
2443 * @ioc: per adapter object
2444 * @handle: device handle
2446 * During device pull we need to appropiately set the sdev state.
2449 _scsih_block_io_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
2451 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2452 struct scsi_device
*sdev
;
2454 shost_for_each_device(sdev
, ioc
->shost
) {
2455 sas_device_priv_data
= sdev
->hostdata
;
2456 if (!sas_device_priv_data
)
2458 if (sas_device_priv_data
->block
)
2460 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2461 dewtprintk(ioc
, sdev_printk(KERN_INFO
, sdev
,
2462 MPT2SAS_INFO_FMT
"SDEV_BLOCK: "
2463 "handle(0x%04x)\n", ioc
->name
, handle
));
2464 sas_device_priv_data
->block
= 1;
2465 scsi_internal_device_block(sdev
);
2471 * _scsih_block_io_to_children_attached_to_ex
2472 * @ioc: per adapter object
2473 * @sas_expander: the sas_device object
2475 * This routine set sdev state to SDEV_BLOCK for all devices
2476 * attached to this expander. This function called when expander is
2480 _scsih_block_io_to_children_attached_to_ex(struct MPT2SAS_ADAPTER
*ioc
,
2481 struct _sas_node
*sas_expander
)
2483 struct _sas_port
*mpt2sas_port
;
2484 struct _sas_device
*sas_device
;
2485 struct _sas_node
*expander_sibling
;
2486 unsigned long flags
;
2491 list_for_each_entry(mpt2sas_port
,
2492 &sas_expander
->sas_port_list
, port_list
) {
2493 if (mpt2sas_port
->remote_identify
.device_type
==
2495 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2497 mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
2498 mpt2sas_port
->remote_identify
.sas_address
);
2499 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2502 _scsih_block_io_device(ioc
, sas_device
->handle
);
2506 list_for_each_entry(mpt2sas_port
,
2507 &sas_expander
->sas_port_list
, port_list
) {
2509 if (mpt2sas_port
->remote_identify
.device_type
==
2510 MPI2_SAS_DEVICE_INFO_EDGE_EXPANDER
||
2511 mpt2sas_port
->remote_identify
.device_type
==
2512 MPI2_SAS_DEVICE_INFO_FANOUT_EXPANDER
) {
2514 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
2516 mpt2sas_scsih_expander_find_by_sas_address(
2517 ioc
, mpt2sas_port
->remote_identify
.sas_address
);
2518 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
2519 _scsih_block_io_to_children_attached_to_ex(ioc
,
2526 * _scsih_block_io_to_children_attached_directly
2527 * @ioc: per adapter object
2528 * @event_data: topology change event data
2530 * This routine set sdev state to SDEV_BLOCK for all devices
2531 * direct attached during device pull.
2534 _scsih_block_io_to_children_attached_directly(struct MPT2SAS_ADAPTER
*ioc
,
2535 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
2542 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
2543 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
2546 phy_number
= event_data
->StartPhyNum
+ i
;
2547 reason_code
= event_data
->PHY
[i
].PhyStatus
&
2548 MPI2_EVENT_SAS_TOPO_RC_MASK
;
2549 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
)
2550 _scsih_block_io_device(ioc
, handle
);
2555 * _scsih_tm_tr_send - send task management request
2556 * @ioc: per adapter object
2557 * @handle: device handle
2558 * Context: interrupt time.
2560 * This code is to initiate the device removal handshake protocal
2561 * with controller firmware. This function will issue target reset
2562 * using high priority request queue. It will send a sas iounit
2563 * controll request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
2565 * This is designed to send muliple task management request at the same
2566 * time to the fifo. If the fifo is full, we will append the request,
2567 * and process it in a future completion.
2570 _scsih_tm_tr_send(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
2572 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
2573 struct MPT2SAS_TARGET
*sas_target_priv_data
;
2575 struct _sas_device
*sas_device
;
2576 unsigned long flags
;
2577 struct _tr_list
*delayed_tr
;
2579 if (ioc
->shost_recovery
) {
2580 printk(MPT2SAS_INFO_FMT
"%s: host reset in progress!\n",
2581 __func__
, ioc
->name
);
2585 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2586 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
2587 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2589 /* skip is hidden raid component */
2590 if (sas_device
&& sas_device
->hidden_raid_component
)
2593 smid
= mpt2sas_base_get_smid_hpr(ioc
, ioc
->tm_tr_cb_idx
);
2595 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
2598 INIT_LIST_HEAD(&delayed_tr
->list
);
2599 delayed_tr
->handle
= handle
;
2600 delayed_tr
->state
= MPT2SAS_REQ_SAS_CNTRL
;
2601 list_add_tail(&delayed_tr
->list
,
2602 &ioc
->delayed_tr_list
);
2603 if (sas_device
&& sas_device
->starget
) {
2604 dewtprintk(ioc
, starget_printk(KERN_INFO
,
2605 sas_device
->starget
, "DELAYED:tr:handle(0x%04x), "
2606 "(open)\n", handle
));
2608 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
2609 "DELAYED:tr:handle(0x%04x), (open)\n",
2610 ioc
->name
, handle
));
2616 sas_device
->state
|= MPTSAS_STATE_TR_SEND
;
2617 sas_device
->state
|= MPT2SAS_REQ_SAS_CNTRL
;
2618 if (sas_device
->starget
&& sas_device
->starget
->hostdata
) {
2619 sas_target_priv_data
= sas_device
->starget
->hostdata
;
2620 sas_target_priv_data
->tm_busy
= 1;
2621 dewtprintk(ioc
, starget_printk(KERN_INFO
,
2622 sas_device
->starget
, "tr:handle(0x%04x), (open)\n",
2626 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
2627 "tr:handle(0x%04x), (open)\n", ioc
->name
, handle
));
2630 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
2631 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
2632 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
2633 mpi_request
->DevHandle
= cpu_to_le16(handle
);
2634 mpi_request
->TaskType
= MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
;
2635 mpt2sas_base_put_smid_hi_priority(ioc
, smid
);
2641 * _scsih_sas_control_complete - completion routine
2642 * @ioc: per adapter object
2643 * @smid: system request message index
2644 * @msix_index: MSIX table index supplied by the OS
2645 * @reply: reply message frame(lower 32bit addr)
2646 * Context: interrupt time.
2648 * This is the sas iounit controll completion routine.
2649 * This code is part of the code to initiate the device removal
2650 * handshake protocal with controller firmware.
2652 * Return 1 meaning mf should be freed from _base_interrupt
2653 * 0 means the mf is freed from this function.
2656 _scsih_sas_control_complete(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
,
2657 u8 msix_index
, u32 reply
)
2659 unsigned long flags
;
2661 struct _sas_device
*sas_device
;
2662 Mpi2SasIoUnitControlReply_t
*mpi_reply
=
2663 mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
2665 handle
= le16_to_cpu(mpi_reply
->DevHandle
);
2667 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2668 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
2669 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2672 sas_device
->state
|= MPTSAS_STATE_CNTRL_COMPLETE
;
2673 if (sas_device
->starget
)
2674 dewtprintk(ioc
, starget_printk(KERN_INFO
,
2675 sas_device
->starget
,
2676 "sc_complete:handle(0x%04x), "
2677 "ioc_status(0x%04x), loginfo(0x%08x)\n",
2678 handle
, le16_to_cpu(mpi_reply
->IOCStatus
),
2679 le32_to_cpu(mpi_reply
->IOCLogInfo
)));
2681 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
2682 "sc_complete:handle(0x%04x), "
2683 "ioc_status(0x%04x), loginfo(0x%08x)\n",
2684 ioc
->name
, handle
, le16_to_cpu(mpi_reply
->IOCStatus
),
2685 le32_to_cpu(mpi_reply
->IOCLogInfo
)));
2692 * _scsih_tm_tr_complete -
2693 * @ioc: per adapter object
2694 * @smid: system request message index
2695 * @msix_index: MSIX table index supplied by the OS
2696 * @reply: reply message frame(lower 32bit addr)
2697 * Context: interrupt time.
2699 * This is the target reset completion routine.
2700 * This code is part of the code to initiate the device removal
2701 * handshake protocal with controller firmware.
2702 * It will send a sas iounit controll request (MPI2_SAS_OP_REMOVE_DEVICE)
2704 * Return 1 meaning mf should be freed from _base_interrupt
2705 * 0 means the mf is freed from this function.
2708 _scsih_tm_tr_complete(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
,
2711 unsigned long flags
;
2713 struct _sas_device
*sas_device
;
2714 Mpi2SCSITaskManagementReply_t
*mpi_reply
=
2715 mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
2716 Mpi2SasIoUnitControlRequest_t
*mpi_request
;
2718 struct MPT2SAS_TARGET
*sas_target_priv_data
;
2719 struct _tr_list
*delayed_tr
;
2722 handle
= le16_to_cpu(mpi_reply
->DevHandle
);
2723 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2724 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
2725 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2728 sas_device
->state
|= MPTSAS_STATE_TR_COMPLETE
;
2729 if (sas_device
->starget
) {
2730 dewtprintk(ioc
, starget_printk(KERN_INFO
,
2731 sas_device
->starget
, "tr_complete:handle(0x%04x), "
2732 "(%s) ioc_status(0x%04x), loginfo(0x%08x), "
2733 "completed(%d)\n", sas_device
->handle
,
2734 (sas_device
->state
& MPT2SAS_REQ_SAS_CNTRL
) ?
2736 le16_to_cpu(mpi_reply
->IOCStatus
),
2737 le32_to_cpu(mpi_reply
->IOCLogInfo
),
2738 le32_to_cpu(mpi_reply
->TerminationCount
)));
2739 if (sas_device
->starget
->hostdata
) {
2740 sas_target_priv_data
=
2741 sas_device
->starget
->hostdata
;
2742 sas_target_priv_data
->tm_busy
= 0;
2746 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
2747 "tr_complete:handle(0x%04x), (open) ioc_status(0x%04x), "
2748 "loginfo(0x%08x), completed(%d)\n", ioc
->name
,
2749 handle
, le16_to_cpu(mpi_reply
->IOCStatus
),
2750 le32_to_cpu(mpi_reply
->IOCLogInfo
),
2751 le32_to_cpu(mpi_reply
->TerminationCount
)));
2754 if (!list_empty(&ioc
->delayed_tr_list
)) {
2755 delayed_tr
= list_entry(ioc
->delayed_tr_list
.next
,
2756 struct _tr_list
, list
);
2757 mpt2sas_base_free_smid(ioc
, smid
);
2758 if (delayed_tr
->state
& MPT2SAS_REQ_SAS_CNTRL
)
2759 _scsih_tm_tr_send(ioc
, delayed_tr
->handle
);
2760 list_del(&delayed_tr
->list
);
2762 rc
= 0; /* tells base_interrupt not to free mf */
2766 if (sas_device
&& !(sas_device
->state
& MPT2SAS_REQ_SAS_CNTRL
))
2769 if (ioc
->shost_recovery
) {
2770 printk(MPT2SAS_INFO_FMT
"%s: host reset in progress!\n",
2771 __func__
, ioc
->name
);
2775 smid_sas_ctrl
= mpt2sas_base_get_smid(ioc
, ioc
->tm_sas_control_cb_idx
);
2776 if (!smid_sas_ctrl
) {
2777 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
2778 ioc
->name
, __func__
);
2783 sas_device
->state
|= MPTSAS_STATE_CNTRL_SEND
;
2785 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid_sas_ctrl
);
2786 memset(mpi_request
, 0, sizeof(Mpi2SasIoUnitControlRequest_t
));
2787 mpi_request
->Function
= MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
;
2788 mpi_request
->Operation
= MPI2_SAS_OP_REMOVE_DEVICE
;
2789 mpi_request
->DevHandle
= mpi_reply
->DevHandle
;
2790 mpt2sas_base_put_smid_default(ioc
, smid_sas_ctrl
);
2795 * _scsih_check_topo_delete_events - sanity check on topo events
2796 * @ioc: per adapter object
2797 * @event_data: the event data payload
2799 * This routine added to better handle cable breaker.
2801 * This handles the case where driver recieves multiple expander
2802 * add and delete events in a single shot. When there is a delete event
2803 * the routine will void any pending add events waiting in the event queue.
2808 _scsih_check_topo_delete_events(struct MPT2SAS_ADAPTER
*ioc
,
2809 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
2811 struct fw_event_work
*fw_event
;
2812 Mpi2EventDataSasTopologyChangeList_t
*local_event_data
;
2813 u16 expander_handle
;
2814 struct _sas_node
*sas_expander
;
2815 unsigned long flags
;
2819 for (i
= 0 ; i
< event_data
->NumEntries
; i
++) {
2820 if (event_data
->PHY
[i
].PhyStatus
&
2821 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT
)
2823 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
2826 reason_code
= event_data
->PHY
[i
].PhyStatus
&
2827 MPI2_EVENT_SAS_TOPO_RC_MASK
;
2828 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
)
2829 _scsih_tm_tr_send(ioc
, handle
);
2832 expander_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
2833 if (expander_handle
< ioc
->sas_hba
.num_phys
) {
2834 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
2838 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
2839 || event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
) {
2840 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
2841 sas_expander
= mpt2sas_scsih_expander_find_by_handle(ioc
,
2843 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
2844 _scsih_block_io_to_children_attached_to_ex(ioc
, sas_expander
);
2845 } else if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_RESPONDING
)
2846 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
2848 if (event_data
->ExpStatus
!= MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
)
2851 /* mark ignore flag for pending events */
2852 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2853 list_for_each_entry(fw_event
, &ioc
->fw_event_list
, list
) {
2854 if (fw_event
->event
!= MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
||
2857 local_event_data
= fw_event
->event_data
;
2858 if (local_event_data
->ExpStatus
==
2859 MPI2_EVENT_SAS_TOPO_ES_ADDED
||
2860 local_event_data
->ExpStatus
==
2861 MPI2_EVENT_SAS_TOPO_ES_RESPONDING
) {
2862 if (le16_to_cpu(local_event_data
->ExpanderDevHandle
) ==
2864 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
2865 "setting ignoring flag\n", ioc
->name
));
2866 fw_event
->ignore
= 1;
2870 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2874 * _scsih_flush_running_cmds - completing outstanding commands.
2875 * @ioc: per adapter object
2877 * The flushing out of all pending scmd commands following host reset,
2878 * where all IO is dropped to the floor.
2883 _scsih_flush_running_cmds(struct MPT2SAS_ADAPTER
*ioc
)
2885 struct scsi_cmnd
*scmd
;
2889 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
2890 scmd
= _scsih_scsi_lookup_get(ioc
, smid
);
2894 mpt2sas_base_free_smid(ioc
, smid
);
2895 scsi_dma_unmap(scmd
);
2896 scmd
->result
= DID_RESET
<< 16;
2897 scmd
->scsi_done(scmd
);
2899 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"completing %d cmds\n",
2904 * _scsih_setup_eedp - setup MPI request for EEDP transfer
2905 * @scmd: pointer to scsi command object
2906 * @mpi_request: pointer to the SCSI_IO reqest message frame
2908 * Supporting protection 1 and 3.
2913 _scsih_setup_eedp(struct scsi_cmnd
*scmd
, Mpi2SCSIIORequest_t
*mpi_request
)
2916 unsigned char prot_op
= scsi_get_prot_op(scmd
);
2917 unsigned char prot_type
= scsi_get_prot_type(scmd
);
2919 if (prot_type
== SCSI_PROT_DIF_TYPE0
||
2920 prot_type
== SCSI_PROT_DIF_TYPE2
||
2921 prot_op
== SCSI_PROT_NORMAL
)
2924 if (prot_op
== SCSI_PROT_READ_STRIP
)
2925 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP
;
2926 else if (prot_op
== SCSI_PROT_WRITE_INSERT
)
2927 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_INSERT_OP
;
2931 switch (prot_type
) {
2932 case SCSI_PROT_DIF_TYPE1
:
2935 * enable ref/guard checking
2936 * auto increment ref tag
2938 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG
|
2939 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG
|
2940 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
2941 mpi_request
->CDB
.EEDP32
.PrimaryReferenceTag
=
2942 cpu_to_be32(scsi_get_lba(scmd
));
2946 case SCSI_PROT_DIF_TYPE3
:
2949 * enable guard checking
2951 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
2954 mpi_request
->EEDPBlockSize
= cpu_to_le32(scmd
->device
->sector_size
);
2955 mpi_request
->EEDPFlags
= cpu_to_le16(eedp_flags
);
2959 * _scsih_eedp_error_handling - return sense code for EEDP errors
2960 * @scmd: pointer to scsi command object
2961 * @ioc_status: ioc status
2966 _scsih_eedp_error_handling(struct scsi_cmnd
*scmd
, u16 ioc_status
)
2972 switch (ioc_status
) {
2973 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
2976 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
2979 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
2987 if (scmd
->sc_data_direction
== DMA_TO_DEVICE
) {
2988 sk
= ILLEGAL_REQUEST
;
2989 host_byte
= DID_ABORT
;
2991 sk
= ABORTED_COMMAND
;
2995 scsi_build_sense_buffer(0, scmd
->sense_buffer
, sk
, 0x10, ascq
);
2996 scmd
->result
= DRIVER_SENSE
<< 24 | (host_byte
<< 16) |
2997 SAM_STAT_CHECK_CONDITION
;
3001 * _scsih_qcmd - main scsi request entry point
3002 * @scmd: pointer to scsi command object
3003 * @done: function pointer to be invoked on completion
3005 * The callback index is set inside `ioc->scsi_io_cb_idx`.
3007 * Returns 0 on success. If there's a failure, return either:
3008 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
3009 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
3012 _scsih_qcmd(struct scsi_cmnd
*scmd
, void (*done
)(struct scsi_cmnd
*))
3014 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
3015 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
3016 struct MPT2SAS_TARGET
*sas_target_priv_data
;
3017 Mpi2SCSIIORequest_t
*mpi_request
;
3021 scmd
->scsi_done
= done
;
3022 sas_device_priv_data
= scmd
->device
->hostdata
;
3023 if (!sas_device_priv_data
) {
3024 scmd
->result
= DID_NO_CONNECT
<< 16;
3025 scmd
->scsi_done(scmd
);
3029 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
3030 if (!sas_target_priv_data
|| sas_target_priv_data
->handle
==
3031 MPT2SAS_INVALID_DEVICE_HANDLE
|| sas_target_priv_data
->deleted
) {
3032 scmd
->result
= DID_NO_CONNECT
<< 16;
3033 scmd
->scsi_done(scmd
);
3037 /* see if we are busy with task managment stuff */
3038 if (sas_device_priv_data
->block
|| sas_target_priv_data
->tm_busy
)
3039 return SCSI_MLQUEUE_DEVICE_BUSY
;
3040 else if (ioc
->shost_recovery
|| ioc
->ioc_link_reset_in_progress
)
3041 return SCSI_MLQUEUE_HOST_BUSY
;
3043 if (scmd
->sc_data_direction
== DMA_FROM_DEVICE
)
3044 mpi_control
= MPI2_SCSIIO_CONTROL_READ
;
3045 else if (scmd
->sc_data_direction
== DMA_TO_DEVICE
)
3046 mpi_control
= MPI2_SCSIIO_CONTROL_WRITE
;
3048 mpi_control
= MPI2_SCSIIO_CONTROL_NODATATRANSFER
;
3051 if (!(sas_device_priv_data
->flags
& MPT_DEVICE_FLAGS_INIT
)) {
3052 if (scmd
->device
->tagged_supported
) {
3053 if (scmd
->device
->ordered_tags
)
3054 mpi_control
|= MPI2_SCSIIO_CONTROL_ORDEREDQ
;
3056 mpi_control
|= MPI2_SCSIIO_CONTROL_SIMPLEQ
;
3058 /* MPI Revision I (UNIT = 0xA) - removed MPI2_SCSIIO_CONTROL_UNTAGGED */
3059 /* mpi_control |= MPI2_SCSIIO_CONTROL_UNTAGGED;
3061 mpi_control
|= (0x500);
3064 mpi_control
|= MPI2_SCSIIO_CONTROL_SIMPLEQ
;
3065 /* Make sure Device is not raid volume */
3066 if (!_scsih_is_raid(&scmd
->device
->sdev_gendev
) &&
3067 sas_is_tlr_enabled(scmd
->device
))
3068 mpi_control
|= MPI2_SCSIIO_CONTROL_TLR_ON
;
3070 smid
= mpt2sas_base_get_smid_scsiio(ioc
, ioc
->scsi_io_cb_idx
, scmd
);
3072 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
3073 ioc
->name
, __func__
);
3076 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3077 memset(mpi_request
, 0, sizeof(Mpi2SCSIIORequest_t
));
3078 _scsih_setup_eedp(scmd
, mpi_request
);
3079 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
3080 if (sas_device_priv_data
->sas_target
->flags
&
3081 MPT_TARGET_FLAGS_RAID_COMPONENT
)
3082 mpi_request
->Function
= MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
;
3084 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
3085 mpi_request
->DevHandle
=
3086 cpu_to_le16(sas_device_priv_data
->sas_target
->handle
);
3087 mpi_request
->DataLength
= cpu_to_le32(scsi_bufflen(scmd
));
3088 mpi_request
->Control
= cpu_to_le32(mpi_control
);
3089 mpi_request
->IoFlags
= cpu_to_le16(scmd
->cmd_len
);
3090 mpi_request
->MsgFlags
= MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR
;
3091 mpi_request
->SenseBufferLength
= SCSI_SENSE_BUFFERSIZE
;
3092 mpi_request
->SenseBufferLowAddress
=
3093 mpt2sas_base_get_sense_buffer_dma(ioc
, smid
);
3094 mpi_request
->SGLOffset0
= offsetof(Mpi2SCSIIORequest_t
, SGL
) / 4;
3095 mpi_request
->SGLFlags
= cpu_to_le16(MPI2_SCSIIO_SGLFLAGS_TYPE_MPI
+
3096 MPI2_SCSIIO_SGLFLAGS_SYSTEM_ADDR
);
3097 mpi_request
->VF_ID
= 0; /* TODO */
3098 mpi_request
->VP_ID
= 0;
3099 int_to_scsilun(sas_device_priv_data
->lun
, (struct scsi_lun
*)
3101 memcpy(mpi_request
->CDB
.CDB32
, scmd
->cmnd
, scmd
->cmd_len
);
3103 if (!mpi_request
->DataLength
) {
3104 mpt2sas_base_build_zero_len_sge(ioc
, &mpi_request
->SGL
);
3106 if (_scsih_build_scatter_gather(ioc
, scmd
, smid
)) {
3107 mpt2sas_base_free_smid(ioc
, smid
);
3112 mpt2sas_base_put_smid_scsi_io(ioc
, smid
,
3113 sas_device_priv_data
->sas_target
->handle
);
3117 return SCSI_MLQUEUE_HOST_BUSY
;
3121 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
3122 * @sense_buffer: sense data returned by target
3123 * @data: normalized skey/asc/ascq
3128 _scsih_normalize_sense(char *sense_buffer
, struct sense_info
*data
)
3130 if ((sense_buffer
[0] & 0x7F) >= 0x72) {
3131 /* descriptor format */
3132 data
->skey
= sense_buffer
[1] & 0x0F;
3133 data
->asc
= sense_buffer
[2];
3134 data
->ascq
= sense_buffer
[3];
3137 data
->skey
= sense_buffer
[2] & 0x0F;
3138 data
->asc
= sense_buffer
[12];
3139 data
->ascq
= sense_buffer
[13];
3143 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3145 * _scsih_scsi_ioc_info - translated non-successfull SCSI_IO request
3146 * @ioc: per adapter object
3147 * @scmd: pointer to scsi command object
3148 * @mpi_reply: reply mf payload returned from firmware
3150 * scsi_status - SCSI Status code returned from target device
3151 * scsi_state - state info associated with SCSI_IO determined by ioc
3152 * ioc_status - ioc supplied status info
3157 _scsih_scsi_ioc_info(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
,
3158 Mpi2SCSIIOReply_t
*mpi_reply
, u16 smid
)
3162 u16 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) &
3163 MPI2_IOCSTATUS_MASK
;
3164 u8 scsi_state
= mpi_reply
->SCSIState
;
3165 u8 scsi_status
= mpi_reply
->SCSIStatus
;
3166 char *desc_ioc_state
= NULL
;
3167 char *desc_scsi_status
= NULL
;
3168 char *desc_scsi_state
= ioc
->tmp_string
;
3169 u32 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
3171 if (log_info
== 0x31170000)
3174 switch (ioc_status
) {
3175 case MPI2_IOCSTATUS_SUCCESS
:
3176 desc_ioc_state
= "success";
3178 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
3179 desc_ioc_state
= "invalid function";
3181 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
3182 desc_ioc_state
= "scsi recovered error";
3184 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE
:
3185 desc_ioc_state
= "scsi invalid dev handle";
3187 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
3188 desc_ioc_state
= "scsi device not there";
3190 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
3191 desc_ioc_state
= "scsi data overrun";
3193 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
3194 desc_ioc_state
= "scsi data underrun";
3196 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
3197 desc_ioc_state
= "scsi io data error";
3199 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
3200 desc_ioc_state
= "scsi protocol error";
3202 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
3203 desc_ioc_state
= "scsi task terminated";
3205 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
3206 desc_ioc_state
= "scsi residual mismatch";
3208 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
3209 desc_ioc_state
= "scsi task mgmt failed";
3211 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
3212 desc_ioc_state
= "scsi ioc terminated";
3214 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
3215 desc_ioc_state
= "scsi ext terminated";
3217 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
3218 desc_ioc_state
= "eedp guard error";
3220 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
3221 desc_ioc_state
= "eedp ref tag error";
3223 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
3224 desc_ioc_state
= "eedp app tag error";
3227 desc_ioc_state
= "unknown";
3231 switch (scsi_status
) {
3232 case MPI2_SCSI_STATUS_GOOD
:
3233 desc_scsi_status
= "good";
3235 case MPI2_SCSI_STATUS_CHECK_CONDITION
:
3236 desc_scsi_status
= "check condition";
3238 case MPI2_SCSI_STATUS_CONDITION_MET
:
3239 desc_scsi_status
= "condition met";
3241 case MPI2_SCSI_STATUS_BUSY
:
3242 desc_scsi_status
= "busy";
3244 case MPI2_SCSI_STATUS_INTERMEDIATE
:
3245 desc_scsi_status
= "intermediate";
3247 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET
:
3248 desc_scsi_status
= "intermediate condmet";
3250 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT
:
3251 desc_scsi_status
= "reservation conflict";
3253 case MPI2_SCSI_STATUS_COMMAND_TERMINATED
:
3254 desc_scsi_status
= "command terminated";
3256 case MPI2_SCSI_STATUS_TASK_SET_FULL
:
3257 desc_scsi_status
= "task set full";
3259 case MPI2_SCSI_STATUS_ACA_ACTIVE
:
3260 desc_scsi_status
= "aca active";
3262 case MPI2_SCSI_STATUS_TASK_ABORTED
:
3263 desc_scsi_status
= "task aborted";
3266 desc_scsi_status
= "unknown";
3270 desc_scsi_state
[0] = '\0';
3272 desc_scsi_state
= " ";
3273 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
3274 strcat(desc_scsi_state
, "response info ");
3275 if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
3276 strcat(desc_scsi_state
, "state terminated ");
3277 if (scsi_state
& MPI2_SCSI_STATE_NO_SCSI_STATUS
)
3278 strcat(desc_scsi_state
, "no status ");
3279 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_FAILED
)
3280 strcat(desc_scsi_state
, "autosense failed ");
3281 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
)
3282 strcat(desc_scsi_state
, "autosense valid ");
3284 scsi_print_command(scmd
);
3285 printk(MPT2SAS_WARN_FMT
"\tdev handle(0x%04x), "
3286 "ioc_status(%s)(0x%04x), smid(%d)\n", ioc
->name
,
3287 le16_to_cpu(mpi_reply
->DevHandle
), desc_ioc_state
,
3289 printk(MPT2SAS_WARN_FMT
"\trequest_len(%d), underflow(%d), "
3290 "resid(%d)\n", ioc
->name
, scsi_bufflen(scmd
), scmd
->underflow
,
3291 scsi_get_resid(scmd
));
3292 printk(MPT2SAS_WARN_FMT
"\ttag(%d), transfer_count(%d), "
3293 "sc->result(0x%08x)\n", ioc
->name
, le16_to_cpu(mpi_reply
->TaskTag
),
3294 le32_to_cpu(mpi_reply
->TransferCount
), scmd
->result
);
3295 printk(MPT2SAS_WARN_FMT
"\tscsi_status(%s)(0x%02x), "
3296 "scsi_state(%s)(0x%02x)\n", ioc
->name
, desc_scsi_status
,
3297 scsi_status
, desc_scsi_state
, scsi_state
);
3299 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
3300 struct sense_info data
;
3301 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
3302 printk(MPT2SAS_WARN_FMT
"\t[sense_key,asc,ascq]: "
3303 "[0x%02x,0x%02x,0x%02x]\n", ioc
->name
, data
.skey
,
3304 data
.asc
, data
.ascq
);
3307 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
) {
3308 response_info
= le32_to_cpu(mpi_reply
->ResponseInfo
);
3309 response_bytes
= (u8
*)&response_info
;
3310 _scsih_response_code(ioc
, response_bytes
[0]);
3316 * _scsih_smart_predicted_fault - illuminate Fault LED
3317 * @ioc: per adapter object
3318 * @handle: device handle
3323 _scsih_smart_predicted_fault(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
3325 Mpi2SepReply_t mpi_reply
;
3326 Mpi2SepRequest_t mpi_request
;
3327 struct scsi_target
*starget
;
3328 struct MPT2SAS_TARGET
*sas_target_priv_data
;
3329 Mpi2EventNotificationReply_t
*event_reply
;
3330 Mpi2EventDataSasDeviceStatusChange_t
*event_data
;
3331 struct _sas_device
*sas_device
;
3333 unsigned long flags
;
3335 /* only handle non-raid devices */
3336 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
3337 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
3339 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3342 starget
= sas_device
->starget
;
3343 sas_target_priv_data
= starget
->hostdata
;
3345 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
) ||
3346 ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
))) {
3347 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3350 starget_printk(KERN_WARNING
, starget
, "predicted fault\n");
3351 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3353 if (ioc
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_IBM
) {
3354 memset(&mpi_request
, 0, sizeof(Mpi2SepRequest_t
));
3355 mpi_request
.Function
= MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR
;
3356 mpi_request
.Action
= MPI2_SEP_REQ_ACTION_WRITE_STATUS
;
3357 mpi_request
.SlotStatus
=
3358 MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT
;
3359 mpi_request
.DevHandle
= cpu_to_le16(handle
);
3360 mpi_request
.Flags
= MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS
;
3361 if ((mpt2sas_base_scsi_enclosure_processor(ioc
, &mpi_reply
,
3362 &mpi_request
)) != 0) {
3363 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3364 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3368 if (mpi_reply
.IOCStatus
|| mpi_reply
.IOCLogInfo
) {
3369 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3370 "enclosure_processor: ioc_status (0x%04x), "
3371 "loginfo(0x%08x)\n", ioc
->name
,
3372 le16_to_cpu(mpi_reply
.IOCStatus
),
3373 le32_to_cpu(mpi_reply
.IOCLogInfo
)));
3378 /* insert into event log */
3379 sz
= offsetof(Mpi2EventNotificationReply_t
, EventData
) +
3380 sizeof(Mpi2EventDataSasDeviceStatusChange_t
);
3381 event_reply
= kzalloc(sz
, GFP_KERNEL
);
3383 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3384 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3388 event_reply
->Function
= MPI2_FUNCTION_EVENT_NOTIFICATION
;
3389 event_reply
->Event
=
3390 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
);
3391 event_reply
->MsgLength
= sz
/4;
3392 event_reply
->EventDataLength
=
3393 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t
)/4);
3394 event_data
= (Mpi2EventDataSasDeviceStatusChange_t
*)
3395 event_reply
->EventData
;
3396 event_data
->ReasonCode
= MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
;
3397 event_data
->ASC
= 0x5D;
3398 event_data
->DevHandle
= cpu_to_le16(handle
);
3399 event_data
->SASAddress
= cpu_to_le64(sas_target_priv_data
->sas_address
);
3400 mpt2sas_ctl_add_to_event_log(ioc
, event_reply
);
3405 * _scsih_io_done - scsi request callback
3406 * @ioc: per adapter object
3407 * @smid: system request message index
3408 * @msix_index: MSIX table index supplied by the OS
3409 * @reply: reply message frame(lower 32bit addr)
3411 * Callback handler when using _scsih_qcmd.
3413 * Return 1 meaning mf should be freed from _base_interrupt
3414 * 0 means the mf is freed from this function.
3417 _scsih_io_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
3419 Mpi2SCSIIORequest_t
*mpi_request
;
3420 Mpi2SCSIIOReply_t
*mpi_reply
;
3421 struct scsi_cmnd
*scmd
;
3427 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
3428 u32 response_code
= 0;
3430 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
3431 scmd
= _scsih_scsi_lookup_get(ioc
, smid
);
3435 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3437 if (mpi_reply
== NULL
) {
3438 scmd
->result
= DID_OK
<< 16;
3442 sas_device_priv_data
= scmd
->device
->hostdata
;
3443 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
||
3444 sas_device_priv_data
->sas_target
->deleted
) {
3445 scmd
->result
= DID_NO_CONNECT
<< 16;
3449 /* turning off TLR */
3450 scsi_state
= mpi_reply
->SCSIState
;
3451 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
3453 le32_to_cpu(mpi_reply
->ResponseInfo
) & 0xFF;
3454 if (!sas_device_priv_data
->tlr_snoop_check
) {
3455 sas_device_priv_data
->tlr_snoop_check
++;
3456 if (!_scsih_is_raid(&scmd
->device
->sdev_gendev
) &&
3457 sas_is_tlr_enabled(scmd
->device
) &&
3458 response_code
== MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
) {
3459 sas_disable_tlr(scmd
->device
);
3460 sdev_printk(KERN_INFO
, scmd
->device
, "TLR disabled\n");
3464 xfer_cnt
= le32_to_cpu(mpi_reply
->TransferCount
);
3465 scsi_set_resid(scmd
, scsi_bufflen(scmd
) - xfer_cnt
);
3466 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
);
3467 if (ioc_status
& MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE
)
3468 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
3471 ioc_status
&= MPI2_IOCSTATUS_MASK
;
3472 scsi_status
= mpi_reply
->SCSIStatus
;
3474 if (ioc_status
== MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
&& xfer_cnt
== 0 &&
3475 (scsi_status
== MPI2_SCSI_STATUS_BUSY
||
3476 scsi_status
== MPI2_SCSI_STATUS_RESERVATION_CONFLICT
||
3477 scsi_status
== MPI2_SCSI_STATUS_TASK_SET_FULL
)) {
3478 ioc_status
= MPI2_IOCSTATUS_SUCCESS
;
3481 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
3482 struct sense_info data
;
3483 const void *sense_data
= mpt2sas_base_get_sense_buffer(ioc
,
3485 u32 sz
= min_t(u32
, SCSI_SENSE_BUFFERSIZE
,
3486 le32_to_cpu(mpi_reply
->SenseCount
));
3487 memcpy(scmd
->sense_buffer
, sense_data
, sz
);
3488 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
3489 /* failure prediction threshold exceeded */
3490 if (data
.asc
== 0x5D)
3491 _scsih_smart_predicted_fault(ioc
,
3492 le16_to_cpu(mpi_reply
->DevHandle
));
3495 switch (ioc_status
) {
3496 case MPI2_IOCSTATUS_BUSY
:
3497 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES
:
3498 scmd
->result
= SAM_STAT_BUSY
;
3501 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
3502 scmd
->result
= DID_NO_CONNECT
<< 16;
3505 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
3506 if (sas_device_priv_data
->block
) {
3507 scmd
->result
= DID_TRANSPORT_DISRUPTED
<< 16;
3510 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
3511 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
3512 scmd
->result
= DID_RESET
<< 16;
3515 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
3516 if ((xfer_cnt
== 0) || (scmd
->underflow
> xfer_cnt
))
3517 scmd
->result
= DID_SOFT_ERROR
<< 16;
3519 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
3522 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
3523 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
3525 if ((scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
))
3528 if (xfer_cnt
< scmd
->underflow
) {
3529 if (scsi_status
== SAM_STAT_BUSY
)
3530 scmd
->result
= SAM_STAT_BUSY
;
3532 scmd
->result
= DID_SOFT_ERROR
<< 16;
3533 } else if (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
3534 MPI2_SCSI_STATE_NO_SCSI_STATUS
))
3535 scmd
->result
= DID_SOFT_ERROR
<< 16;
3536 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
3537 scmd
->result
= DID_RESET
<< 16;
3538 else if (!xfer_cnt
&& scmd
->cmnd
[0] == REPORT_LUNS
) {
3539 mpi_reply
->SCSIState
= MPI2_SCSI_STATE_AUTOSENSE_VALID
;
3540 mpi_reply
->SCSIStatus
= SAM_STAT_CHECK_CONDITION
;
3541 scmd
->result
= (DRIVER_SENSE
<< 24) |
3542 SAM_STAT_CHECK_CONDITION
;
3543 scmd
->sense_buffer
[0] = 0x70;
3544 scmd
->sense_buffer
[2] = ILLEGAL_REQUEST
;
3545 scmd
->sense_buffer
[12] = 0x20;
3546 scmd
->sense_buffer
[13] = 0;
3550 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
3551 scsi_set_resid(scmd
, 0);
3552 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
3553 case MPI2_IOCSTATUS_SUCCESS
:
3554 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
3555 if (response_code
==
3556 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
||
3557 (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
3558 MPI2_SCSI_STATE_NO_SCSI_STATUS
)))
3559 scmd
->result
= DID_SOFT_ERROR
<< 16;
3560 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
3561 scmd
->result
= DID_RESET
<< 16;
3564 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
3565 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
3566 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
3567 _scsih_eedp_error_handling(scmd
, ioc_status
);
3569 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
3570 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
3571 case MPI2_IOCSTATUS_INVALID_SGL
:
3572 case MPI2_IOCSTATUS_INTERNAL_ERROR
:
3573 case MPI2_IOCSTATUS_INVALID_FIELD
:
3574 case MPI2_IOCSTATUS_INVALID_STATE
:
3575 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
3576 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
3578 scmd
->result
= DID_SOFT_ERROR
<< 16;
3583 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3584 if (scmd
->result
&& (ioc
->logging_level
& MPT_DEBUG_REPLY
))
3585 _scsih_scsi_ioc_info(ioc
, scmd
, mpi_reply
, smid
);
3589 scsi_dma_unmap(scmd
);
3590 scmd
->scsi_done(scmd
);
3595 * _scsih_sas_host_refresh - refreshing sas host object contents
3596 * @ioc: per adapter object
3599 * During port enable, fw will send topology events for every device. Its
3600 * possible that the handles may change from the previous setting, so this
3601 * code keeping handles updating if changed.
3606 _scsih_sas_host_refresh(struct MPT2SAS_ADAPTER
*ioc
)
3611 Mpi2ConfigReply_t mpi_reply
;
3612 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
3613 u16 attached_handle
;
3615 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
3616 "updating handles for sas_host(0x%016llx)\n",
3617 ioc
->name
, (unsigned long long)ioc
->sas_hba
.sas_address
));
3619 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
3620 * sizeof(Mpi2SasIOUnit0PhyData_t
));
3621 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
3622 if (!sas_iounit_pg0
) {
3623 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3624 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3628 if ((mpt2sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
3629 sas_iounit_pg0
, sz
)) != 0)
3631 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
3632 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
3634 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
3636 ioc
->sas_hba
.handle
= le16_to_cpu(sas_iounit_pg0
->
3637 PhyData
[0].ControllerDevHandle
);
3638 ioc
->sas_hba
.phy
[i
].handle
= ioc
->sas_hba
.handle
;
3639 attached_handle
= le16_to_cpu(sas_iounit_pg0
->PhyData
[i
].
3641 mpt2sas_transport_update_links(ioc
, ioc
->sas_hba
.sas_address
,
3642 attached_handle
, i
, sas_iounit_pg0
->PhyData
[i
].
3643 NegotiatedLinkRate
>> 4);
3646 kfree(sas_iounit_pg0
);
3650 * _scsih_sas_host_add - create sas host object
3651 * @ioc: per adapter object
3653 * Creating host side data object, stored in ioc->sas_hba
3658 _scsih_sas_host_add(struct MPT2SAS_ADAPTER
*ioc
)
3661 Mpi2ConfigReply_t mpi_reply
;
3662 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
3663 Mpi2SasIOUnitPage1_t
*sas_iounit_pg1
= NULL
;
3664 Mpi2SasPhyPage0_t phy_pg0
;
3665 Mpi2SasDevicePage0_t sas_device_pg0
;
3666 Mpi2SasEnclosurePage0_t enclosure_pg0
;
3669 u16 device_missing_delay
;
3671 mpt2sas_config_get_number_hba_phys(ioc
, &ioc
->sas_hba
.num_phys
);
3672 if (!ioc
->sas_hba
.num_phys
) {
3673 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3674 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3678 /* sas_iounit page 0 */
3679 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
3680 sizeof(Mpi2SasIOUnit0PhyData_t
));
3681 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
3682 if (!sas_iounit_pg0
) {
3683 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3684 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3687 if ((mpt2sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
3688 sas_iounit_pg0
, sz
))) {
3689 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3690 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3693 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
3694 MPI2_IOCSTATUS_MASK
;
3695 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
3696 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3697 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3701 /* sas_iounit page 1 */
3702 sz
= offsetof(Mpi2SasIOUnitPage1_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
3703 sizeof(Mpi2SasIOUnit1PhyData_t
));
3704 sas_iounit_pg1
= kzalloc(sz
, GFP_KERNEL
);
3705 if (!sas_iounit_pg1
) {
3706 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3707 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3710 if ((mpt2sas_config_get_sas_iounit_pg1(ioc
, &mpi_reply
,
3711 sas_iounit_pg1
, sz
))) {
3712 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3713 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3716 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
3717 MPI2_IOCSTATUS_MASK
;
3718 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
3719 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3720 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3724 ioc
->io_missing_delay
=
3725 le16_to_cpu(sas_iounit_pg1
->IODeviceMissingDelay
);
3726 device_missing_delay
=
3727 le16_to_cpu(sas_iounit_pg1
->ReportDeviceMissingDelay
);
3728 if (device_missing_delay
& MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16
)
3729 ioc
->device_missing_delay
= (device_missing_delay
&
3730 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
) * 16;
3732 ioc
->device_missing_delay
= device_missing_delay
&
3733 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
;
3735 ioc
->sas_hba
.parent_dev
= &ioc
->shost
->shost_gendev
;
3736 ioc
->sas_hba
.phy
= kcalloc(ioc
->sas_hba
.num_phys
,
3737 sizeof(struct _sas_phy
), GFP_KERNEL
);
3738 if (!ioc
->sas_hba
.phy
) {
3739 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3740 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3743 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
3744 if ((mpt2sas_config_get_phy_pg0(ioc
, &mpi_reply
, &phy_pg0
,
3746 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3747 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3750 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
3751 MPI2_IOCSTATUS_MASK
;
3752 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
3753 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3754 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3759 ioc
->sas_hba
.handle
= le16_to_cpu(sas_iounit_pg0
->
3760 PhyData
[0].ControllerDevHandle
);
3761 ioc
->sas_hba
.phy
[i
].handle
= ioc
->sas_hba
.handle
;
3762 ioc
->sas_hba
.phy
[i
].phy_id
= i
;
3763 mpt2sas_transport_add_host_phy(ioc
, &ioc
->sas_hba
.phy
[i
],
3764 phy_pg0
, ioc
->sas_hba
.parent_dev
);
3766 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
3767 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, ioc
->sas_hba
.handle
))) {
3768 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3769 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3772 ioc
->sas_hba
.enclosure_handle
=
3773 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
3774 ioc
->sas_hba
.sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
3775 printk(MPT2SAS_INFO_FMT
"host_add: handle(0x%04x), "
3776 "sas_addr(0x%016llx), phys(%d)\n", ioc
->name
, ioc
->sas_hba
.handle
,
3777 (unsigned long long) ioc
->sas_hba
.sas_address
,
3778 ioc
->sas_hba
.num_phys
) ;
3780 if (ioc
->sas_hba
.enclosure_handle
) {
3781 if (!(mpt2sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
3783 MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
3784 ioc
->sas_hba
.enclosure_handle
))) {
3785 ioc
->sas_hba
.enclosure_logical_id
=
3786 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
3791 kfree(sas_iounit_pg1
);
3792 kfree(sas_iounit_pg0
);
3796 * _scsih_expander_add - creating expander object
3797 * @ioc: per adapter object
3798 * @handle: expander handle
3800 * Creating expander object, stored in ioc->sas_expander_list.
3802 * Return 0 for success, else error.
3805 _scsih_expander_add(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
3807 struct _sas_node
*sas_expander
;
3808 Mpi2ConfigReply_t mpi_reply
;
3809 Mpi2ExpanderPage0_t expander_pg0
;
3810 Mpi2ExpanderPage1_t expander_pg1
;
3811 Mpi2SasEnclosurePage0_t enclosure_pg0
;
3814 __le64 sas_address
, sas_address_parent
= 0;
3816 unsigned long flags
;
3817 struct _sas_port
*mpt2sas_port
= NULL
;
3823 if (ioc
->shost_recovery
)
3826 if ((mpt2sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
3827 MPI2_SAS_EXPAND_PGAD_FORM_HNDL
, handle
))) {
3828 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3829 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3833 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
3834 MPI2_IOCSTATUS_MASK
;
3835 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
3836 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3837 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3841 /* handle out of order topology events */
3842 parent_handle
= le16_to_cpu(expander_pg0
.ParentDevHandle
);
3843 if (_scsih_get_sas_address(ioc
, parent_handle
, &sas_address_parent
)
3845 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3846 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3849 if (sas_address_parent
!= ioc
->sas_hba
.sas_address
) {
3850 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
3851 sas_expander
= mpt2sas_scsih_expander_find_by_sas_address(ioc
,
3852 sas_address_parent
);
3853 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
3854 if (!sas_expander
) {
3855 rc
= _scsih_expander_add(ioc
, parent_handle
);
3861 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
3862 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
3863 sas_expander
= mpt2sas_scsih_expander_find_by_sas_address(ioc
,
3865 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
3870 sas_expander
= kzalloc(sizeof(struct _sas_node
),
3872 if (!sas_expander
) {
3873 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3874 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3878 sas_expander
->handle
= handle
;
3879 sas_expander
->num_phys
= expander_pg0
.NumPhys
;
3880 sas_expander
->sas_address_parent
= sas_address_parent
;
3881 sas_expander
->sas_address
= sas_address
;
3883 printk(MPT2SAS_INFO_FMT
"expander_add: handle(0x%04x),"
3884 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc
->name
,
3885 handle
, parent_handle
, (unsigned long long)
3886 sas_expander
->sas_address
, sas_expander
->num_phys
);
3888 if (!sas_expander
->num_phys
)
3890 sas_expander
->phy
= kcalloc(sas_expander
->num_phys
,
3891 sizeof(struct _sas_phy
), GFP_KERNEL
);
3892 if (!sas_expander
->phy
) {
3893 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3894 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3899 INIT_LIST_HEAD(&sas_expander
->sas_port_list
);
3900 mpt2sas_port
= mpt2sas_transport_port_add(ioc
, handle
,
3901 sas_address_parent
);
3902 if (!mpt2sas_port
) {
3903 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3904 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3908 sas_expander
->parent_dev
= &mpt2sas_port
->rphy
->dev
;
3910 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++) {
3911 if ((mpt2sas_config_get_expander_pg1(ioc
, &mpi_reply
,
3912 &expander_pg1
, i
, handle
))) {
3913 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3914 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3918 sas_expander
->phy
[i
].handle
= handle
;
3919 sas_expander
->phy
[i
].phy_id
= i
;
3921 if ((mpt2sas_transport_add_expander_phy(ioc
,
3922 &sas_expander
->phy
[i
], expander_pg1
,
3923 sas_expander
->parent_dev
))) {
3924 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3925 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3931 if (sas_expander
->enclosure_handle
) {
3932 if (!(mpt2sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
3933 &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
3934 sas_expander
->enclosure_handle
))) {
3935 sas_expander
->enclosure_logical_id
=
3936 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
3940 _scsih_expander_node_add(ioc
, sas_expander
);
3946 mpt2sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
3947 sas_address_parent
);
3948 kfree(sas_expander
);
3953 * _scsih_done - scsih callback handler.
3954 * @ioc: per adapter object
3955 * @smid: system request message index
3956 * @msix_index: MSIX table index supplied by the OS
3957 * @reply: reply message frame(lower 32bit addr)
3959 * Callback handler when sending internal generated message frames.
3960 * The callback index passed is `ioc->scsih_cb_idx`
3962 * Return 1 meaning mf should be freed from _base_interrupt
3963 * 0 means the mf is freed from this function.
3966 _scsih_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
3968 MPI2DefaultReply_t
*mpi_reply
;
3970 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
3971 if (ioc
->scsih_cmds
.status
== MPT2_CMD_NOT_USED
)
3973 if (ioc
->scsih_cmds
.smid
!= smid
)
3975 ioc
->scsih_cmds
.status
|= MPT2_CMD_COMPLETE
;
3977 memcpy(ioc
->scsih_cmds
.reply
, mpi_reply
,
3978 mpi_reply
->MsgLength
*4);
3979 ioc
->scsih_cmds
.status
|= MPT2_CMD_REPLY_VALID
;
3981 ioc
->scsih_cmds
.status
&= ~MPT2_CMD_PENDING
;
3982 complete(&ioc
->scsih_cmds
.done
);
3987 * _scsih_expander_remove - removing expander object
3988 * @ioc: per adapter object
3989 * @sas_address: expander sas_address
3994 _scsih_expander_remove(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
)
3996 struct _sas_node
*sas_expander
;
3997 unsigned long flags
;
3999 if (ioc
->shost_recovery
)
4002 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
4003 sas_expander
= mpt2sas_scsih_expander_find_by_sas_address(ioc
,
4005 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
4006 _scsih_expander_node_remove(ioc
, sas_expander
);
4010 * _scsih_add_device - creating sas device object
4011 * @ioc: per adapter object
4012 * @handle: sas device handle
4013 * @phy_num: phy number end device attached to
4014 * @is_pd: is this hidden raid component
4016 * Creating end device object, stored in ioc->sas_device_list.
4018 * Returns 0 for success, non-zero for failure.
4021 _scsih_add_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
, u8 phy_num
, u8 is_pd
)
4023 Mpi2ConfigReply_t mpi_reply
;
4024 Mpi2SasDevicePage0_t sas_device_pg0
;
4025 Mpi2SasEnclosurePage0_t enclosure_pg0
;
4026 struct _sas_device
*sas_device
;
4030 unsigned long flags
;
4032 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
4033 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
4034 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4035 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4039 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4040 MPI2_IOCSTATUS_MASK
;
4041 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4042 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4043 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4047 /* check if device is present */
4048 if (!(le16_to_cpu(sas_device_pg0
.Flags
) &
4049 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT
)) {
4050 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4051 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4052 printk(MPT2SAS_ERR_FMT
"Flags = 0x%04x\n",
4053 ioc
->name
, le16_to_cpu(sas_device_pg0
.Flags
));
4057 /* check if there were any issus with discovery */
4058 if (sas_device_pg0
.AccessStatus
==
4059 MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED
) {
4060 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4061 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4062 printk(MPT2SAS_ERR_FMT
"AccessStatus = 0x%02x\n",
4063 ioc
->name
, sas_device_pg0
.AccessStatus
);
4067 /* check if this is end device */
4068 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
4069 if (!(_scsih_is_end_device(device_info
))) {
4070 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4071 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4075 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
4077 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4078 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
4080 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4083 _scsih_ublock_io_device(ioc
, handle
);
4087 sas_device
= kzalloc(sizeof(struct _sas_device
),
4090 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4091 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4095 sas_device
->handle
= handle
;
4096 if (_scsih_get_sas_address(ioc
, le16_to_cpu
4097 (sas_device_pg0
.ParentDevHandle
),
4098 &sas_device
->sas_address_parent
) != 0)
4099 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4100 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4101 sas_device
->enclosure_handle
=
4102 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
4104 le16_to_cpu(sas_device_pg0
.Slot
);
4105 sas_device
->device_info
= device_info
;
4106 sas_device
->sas_address
= sas_address
;
4107 sas_device
->hidden_raid_component
= is_pd
;
4109 /* get enclosure_logical_id */
4110 if (sas_device
->enclosure_handle
&& !(mpt2sas_config_get_enclosure_pg0(
4111 ioc
, &mpi_reply
, &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
4112 sas_device
->enclosure_handle
)))
4113 sas_device
->enclosure_logical_id
=
4114 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
4116 /* get device name */
4117 sas_device
->device_name
= le64_to_cpu(sas_device_pg0
.DeviceName
);
4119 if (ioc
->wait_for_port_enable_to_complete
)
4120 _scsih_sas_device_init_add(ioc
, sas_device
);
4122 _scsih_sas_device_add(ioc
, sas_device
);
4128 * _scsih_remove_device - removing sas device object
4129 * @ioc: per adapter object
4130 * @sas_device: the sas_device object
4135 _scsih_remove_device(struct MPT2SAS_ADAPTER
*ioc
, struct _sas_device
4138 struct MPT2SAS_TARGET
*sas_target_priv_data
;
4139 Mpi2SasIoUnitControlReply_t mpi_reply
;
4140 Mpi2SasIoUnitControlRequest_t mpi_request
;
4141 u16 device_handle
, handle
;
4146 handle
= sas_device
->handle
;
4147 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: enter: handle(0x%04x),"
4148 " sas_addr(0x%016llx)\n", ioc
->name
, __func__
, handle
,
4149 (unsigned long long) sas_device
->sas_address
));
4151 if (sas_device
->starget
&& sas_device
->starget
->hostdata
) {
4152 sas_target_priv_data
= sas_device
->starget
->hostdata
;
4153 sas_target_priv_data
->deleted
= 1;
4156 if (ioc
->remove_host
|| ioc
->shost_recovery
|| !handle
)
4159 if ((sas_device
->state
& MPTSAS_STATE_TR_COMPLETE
)) {
4160 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"\tskip "
4161 "target_reset handle(0x%04x)\n", ioc
->name
,
4166 /* Target Reset to flush out all the outstanding IO */
4167 device_handle
= (sas_device
->hidden_raid_component
) ?
4168 sas_device
->volume_handle
: handle
;
4169 if (device_handle
) {
4170 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"issue target reset: "
4171 "handle(0x%04x)\n", ioc
->name
, device_handle
));
4172 mutex_lock(&ioc
->tm_cmds
.mutex
);
4173 mpt2sas_scsih_issue_tm(ioc
, device_handle
, 0,
4174 MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
, 0, 10);
4175 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
4176 mutex_unlock(&ioc
->tm_cmds
.mutex
);
4177 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"issue target reset "
4178 "done: handle(0x%04x)\n", ioc
->name
, device_handle
));
4179 if (ioc
->shost_recovery
)
4184 if ((sas_device
->state
& MPTSAS_STATE_CNTRL_COMPLETE
)) {
4185 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"\tskip "
4186 "sas_cntrl handle(0x%04x)\n", ioc
->name
, handle
));
4190 /* SAS_IO_UNIT_CNTR - send REMOVE_DEVICE */
4191 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"sas_iounit: handle"
4192 "(0x%04x)\n", ioc
->name
, handle
));
4193 memset(&mpi_request
, 0, sizeof(Mpi2SasIoUnitControlRequest_t
));
4194 mpi_request
.Function
= MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
;
4195 mpi_request
.Operation
= MPI2_SAS_OP_REMOVE_DEVICE
;
4196 mpi_request
.DevHandle
= handle
;
4197 mpi_request
.VF_ID
= 0; /* TODO */
4198 mpi_request
.VP_ID
= 0;
4199 if ((mpt2sas_base_sas_iounit_control(ioc
, &mpi_reply
,
4200 &mpi_request
)) != 0) {
4201 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4202 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4205 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"sas_iounit: ioc_status"
4206 "(0x%04x), loginfo(0x%08x)\n", ioc
->name
,
4207 le16_to_cpu(mpi_reply
.IOCStatus
),
4208 le32_to_cpu(mpi_reply
.IOCLogInfo
)));
4212 _scsih_ublock_io_device(ioc
, handle
);
4214 mpt2sas_transport_port_remove(ioc
, sas_device
->sas_address
,
4215 sas_device
->sas_address_parent
);
4217 printk(MPT2SAS_INFO_FMT
"removing handle(0x%04x), sas_addr"
4218 "(0x%016llx)\n", ioc
->name
, handle
,
4219 (unsigned long long) sas_device
->sas_address
);
4220 _scsih_sas_device_remove(ioc
, sas_device
);
4222 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: exit: handle"
4223 "(0x%04x)\n", ioc
->name
, __func__
, handle
));
4226 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4228 * _scsih_sas_topology_change_event_debug - debug for topology event
4229 * @ioc: per adapter object
4230 * @event_data: event data payload
4234 _scsih_sas_topology_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
4235 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
4241 char *status_str
= NULL
;
4242 u8 link_rate
, prev_link_rate
;
4244 switch (event_data
->ExpStatus
) {
4245 case MPI2_EVENT_SAS_TOPO_ES_ADDED
:
4248 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
:
4249 status_str
= "remove";
4251 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING
:
4253 status_str
= "responding";
4255 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
:
4256 status_str
= "remove delay";
4259 status_str
= "unknown status";
4262 printk(MPT2SAS_DEBUG_FMT
"sas topology change: (%s)\n",
4263 ioc
->name
, status_str
);
4264 printk(KERN_DEBUG
"\thandle(0x%04x), enclosure_handle(0x%04x) "
4265 "start_phy(%02d), count(%d)\n",
4266 le16_to_cpu(event_data
->ExpanderDevHandle
),
4267 le16_to_cpu(event_data
->EnclosureHandle
),
4268 event_data
->StartPhyNum
, event_data
->NumEntries
);
4269 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
4270 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
4273 phy_number
= event_data
->StartPhyNum
+ i
;
4274 reason_code
= event_data
->PHY
[i
].PhyStatus
&
4275 MPI2_EVENT_SAS_TOPO_RC_MASK
;
4276 switch (reason_code
) {
4277 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
4278 status_str
= "target add";
4280 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
4281 status_str
= "target remove";
4283 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
:
4284 status_str
= "delay target remove";
4286 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
4287 status_str
= "link rate change";
4289 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE
:
4290 status_str
= "target responding";
4293 status_str
= "unknown";
4296 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
4297 prev_link_rate
= event_data
->PHY
[i
].LinkRate
& 0xF;
4298 printk(KERN_DEBUG
"\tphy(%02d), attached_handle(0x%04x): %s:"
4299 " link rate: new(0x%02x), old(0x%02x)\n", phy_number
,
4300 handle
, status_str
, link_rate
, prev_link_rate
);
4307 * _scsih_sas_topology_change_event - handle topology changes
4308 * @ioc: per adapter object
4309 * @fw_event: The fw_event_work object
4314 _scsih_sas_topology_change_event(struct MPT2SAS_ADAPTER
*ioc
,
4315 struct fw_event_work
*fw_event
)
4318 u16 parent_handle
, handle
;
4321 struct _sas_node
*sas_expander
;
4322 struct _sas_device
*sas_device
;
4324 unsigned long flags
;
4325 u8 link_rate
, prev_link_rate
;
4326 Mpi2EventDataSasTopologyChangeList_t
*event_data
= fw_event
->event_data
;
4328 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4329 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
4330 _scsih_sas_topology_change_event_debug(ioc
, event_data
);
4333 if (ioc
->shost_recovery
)
4336 if (!ioc
->sas_hba
.num_phys
)
4337 _scsih_sas_host_add(ioc
);
4339 _scsih_sas_host_refresh(ioc
);
4341 if (fw_event
->ignore
) {
4342 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"ignoring expander "
4343 "event\n", ioc
->name
));
4347 parent_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
4349 /* handle expander add */
4350 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_ADDED
)
4351 if (_scsih_expander_add(ioc
, parent_handle
) != 0)
4354 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
4355 sas_expander
= mpt2sas_scsih_expander_find_by_handle(ioc
,
4357 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
4359 sas_address
= sas_expander
->sas_address
;
4360 else if (parent_handle
< ioc
->sas_hba
.num_phys
)
4361 sas_address
= ioc
->sas_hba
.sas_address
;
4365 /* handle siblings events */
4366 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
4367 if (fw_event
->ignore
) {
4368 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"ignoring "
4369 "expander event\n", ioc
->name
));
4372 if (ioc
->shost_recovery
)
4374 phy_number
= event_data
->StartPhyNum
+ i
;
4375 reason_code
= event_data
->PHY
[i
].PhyStatus
&
4376 MPI2_EVENT_SAS_TOPO_RC_MASK
;
4377 if ((event_data
->PHY
[i
].PhyStatus
&
4378 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT
) && (reason_code
!=
4379 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
))
4381 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
4384 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
4385 prev_link_rate
= event_data
->PHY
[i
].LinkRate
& 0xF;
4386 switch (reason_code
) {
4387 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
4389 if (link_rate
== prev_link_rate
)
4392 mpt2sas_transport_update_links(ioc
, sas_address
,
4393 handle
, phy_number
, link_rate
);
4395 if (link_rate
>= MPI2_SAS_NEG_LINK_RATE_1_5
)
4396 _scsih_ublock_io_device(ioc
, handle
);
4398 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
4400 mpt2sas_transport_update_links(ioc
, sas_address
,
4401 handle
, phy_number
, link_rate
);
4403 _scsih_add_device(ioc
, handle
, phy_number
, 0);
4405 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
4407 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4408 sas_device
= _scsih_sas_device_find_by_handle(ioc
,
4411 spin_unlock_irqrestore(&ioc
->sas_device_lock
,
4415 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4416 _scsih_remove_device(ioc
, sas_device
);
4421 /* handle expander removal */
4422 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
&&
4424 _scsih_expander_remove(ioc
, sas_address
);
4428 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4430 * _scsih_sas_device_status_change_event_debug - debug for device event
4431 * @event_data: event data payload
4437 _scsih_sas_device_status_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
4438 Mpi2EventDataSasDeviceStatusChange_t
*event_data
)
4440 char *reason_str
= NULL
;
4442 switch (event_data
->ReasonCode
) {
4443 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
:
4444 reason_str
= "smart data";
4446 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED
:
4447 reason_str
= "unsupported device discovered";
4449 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
:
4450 reason_str
= "internal device reset";
4452 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL
:
4453 reason_str
= "internal task abort";
4455 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL
:
4456 reason_str
= "internal task abort set";
4458 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL
:
4459 reason_str
= "internal clear task set";
4461 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL
:
4462 reason_str
= "internal query task";
4464 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE
:
4465 reason_str
= "sata init failure";
4467 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
:
4468 reason_str
= "internal device reset complete";
4470 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL
:
4471 reason_str
= "internal task abort complete";
4473 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION
:
4474 reason_str
= "internal async notification";
4476 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY
:
4477 reason_str
= "expander reduced functionality";
4479 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY
:
4480 reason_str
= "expander reduced functionality complete";
4483 reason_str
= "unknown reason";
4486 printk(MPT2SAS_DEBUG_FMT
"device status change: (%s)\n"
4487 "\thandle(0x%04x), sas address(0x%016llx)", ioc
->name
,
4488 reason_str
, le16_to_cpu(event_data
->DevHandle
),
4489 (unsigned long long)le64_to_cpu(event_data
->SASAddress
));
4490 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
)
4491 printk(MPT2SAS_DEBUG_FMT
", ASC(0x%x), ASCQ(0x%x)\n", ioc
->name
,
4492 event_data
->ASC
, event_data
->ASCQ
);
4493 printk(KERN_INFO
"\n");
4498 * _scsih_sas_device_status_change_event - handle device status change
4499 * @ioc: per adapter object
4500 * @fw_event: The fw_event_work object
4506 _scsih_sas_device_status_change_event(struct MPT2SAS_ADAPTER
*ioc
,
4507 struct fw_event_work
*fw_event
)
4509 struct MPT2SAS_TARGET
*target_priv_data
;
4510 struct _sas_device
*sas_device
;
4512 unsigned long flags
;
4513 Mpi2EventDataSasDeviceStatusChange_t
*event_data
=
4514 fw_event
->event_data
;
4516 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4517 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
4518 _scsih_sas_device_status_change_event_debug(ioc
,
4522 if (!(event_data
->ReasonCode
==
4523 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
&&
4524 event_data
->ReasonCode
==
4525 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
))
4528 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4529 sas_address
= le64_to_cpu(event_data
->SASAddress
);
4530 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
4532 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4534 if (!sas_device
|| !sas_device
->starget
)
4537 target_priv_data
= sas_device
->starget
->hostdata
;
4538 if (!target_priv_data
)
4541 if (event_data
->ReasonCode
==
4542 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
)
4543 target_priv_data
->tm_busy
= 1;
4545 target_priv_data
->tm_busy
= 0;
4548 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4550 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure event
4551 * @ioc: per adapter object
4552 * @event_data: event data payload
4558 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
4559 Mpi2EventDataSasEnclDevStatusChange_t
*event_data
)
4561 char *reason_str
= NULL
;
4563 switch (event_data
->ReasonCode
) {
4564 case MPI2_EVENT_SAS_ENCL_RC_ADDED
:
4565 reason_str
= "enclosure add";
4567 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING
:
4568 reason_str
= "enclosure remove";
4571 reason_str
= "unknown reason";
4575 printk(MPT2SAS_DEBUG_FMT
"enclosure status change: (%s)\n"
4576 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
4577 " number slots(%d)\n", ioc
->name
, reason_str
,
4578 le16_to_cpu(event_data
->EnclosureHandle
),
4579 (unsigned long long)le64_to_cpu(event_data
->EnclosureLogicalID
),
4580 le16_to_cpu(event_data
->StartSlot
));
4585 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
4586 * @ioc: per adapter object
4587 * @fw_event: The fw_event_work object
4593 _scsih_sas_enclosure_dev_status_change_event(struct MPT2SAS_ADAPTER
*ioc
,
4594 struct fw_event_work
*fw_event
)
4596 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4597 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
4598 _scsih_sas_enclosure_dev_status_change_event_debug(ioc
,
4599 fw_event
->event_data
);
4604 * _scsih_sas_broadcast_primative_event - handle broadcast events
4605 * @ioc: per adapter object
4606 * @fw_event: The fw_event_work object
4612 _scsih_sas_broadcast_primative_event(struct MPT2SAS_ADAPTER
*ioc
,
4613 struct fw_event_work
*fw_event
)
4615 struct scsi_cmnd
*scmd
;
4618 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
4619 u32 termination_count
;
4621 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
4622 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4623 Mpi2EventDataSasBroadcastPrimitive_t
*event_data
= fw_event
->event_data
;
4626 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"broadcast primative: "
4627 "phy number(%d), width(%d)\n", ioc
->name
, event_data
->PhyNum
,
4628 event_data
->PortWidth
));
4629 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: enter\n", ioc
->name
,
4632 mutex_lock(&ioc
->tm_cmds
.mutex
);
4633 termination_count
= 0;
4635 mpi_reply
= ioc
->tm_cmds
.reply
;
4636 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
4637 scmd
= _scsih_scsi_lookup_get(ioc
, smid
);
4640 sas_device_priv_data
= scmd
->device
->hostdata
;
4641 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
)
4643 /* skip hidden raid components */
4644 if (sas_device_priv_data
->sas_target
->flags
&
4645 MPT_TARGET_FLAGS_RAID_COMPONENT
)
4648 if (sas_device_priv_data
->sas_target
->flags
&
4649 MPT_TARGET_FLAGS_VOLUME
)
4652 handle
= sas_device_priv_data
->sas_target
->handle
;
4653 lun
= sas_device_priv_data
->lun
;
4656 mpt2sas_scsih_issue_tm(ioc
, handle
, lun
,
4657 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK
, smid
, 30);
4658 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
4659 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
)
4660 & MPI2_IOCSTATUS_MASK
;
4661 if ((ioc_status
== MPI2_IOCSTATUS_SUCCESS
) &&
4662 (mpi_reply
->ResponseCode
==
4663 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
||
4664 mpi_reply
->ResponseCode
==
4665 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
))
4668 mpt2sas_scsih_issue_tm(ioc
, handle
, lun
,
4669 MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET
, 0, 30);
4670 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
4671 termination_count
+= le32_to_cpu(mpi_reply
->TerminationCount
);
4673 ioc
->broadcast_aen_busy
= 0;
4674 mutex_unlock(&ioc
->tm_cmds
.mutex
);
4676 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
4677 "%s - exit, query_count = %d termination_count = %d\n",
4678 ioc
->name
, __func__
, query_count
, termination_count
));
4682 * _scsih_sas_discovery_event - handle discovery events
4683 * @ioc: per adapter object
4684 * @fw_event: The fw_event_work object
4690 _scsih_sas_discovery_event(struct MPT2SAS_ADAPTER
*ioc
,
4691 struct fw_event_work
*fw_event
)
4693 Mpi2EventDataSasDiscovery_t
*event_data
= fw_event
->event_data
;
4695 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4696 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
) {
4697 printk(MPT2SAS_DEBUG_FMT
"discovery event: (%s)", ioc
->name
,
4698 (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
) ?
4700 if (event_data
->DiscoveryStatus
)
4701 printk("discovery_status(0x%08x)",
4702 le32_to_cpu(event_data
->DiscoveryStatus
));
4707 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
&&
4708 !ioc
->sas_hba
.num_phys
)
4709 _scsih_sas_host_add(ioc
);
4713 * _scsih_reprobe_lun - reprobing lun
4714 * @sdev: scsi device struct
4715 * @no_uld_attach: sdev->no_uld_attach flag setting
4719 _scsih_reprobe_lun(struct scsi_device
*sdev
, void *no_uld_attach
)
4723 sdev
->no_uld_attach
= no_uld_attach
? 1 : 0;
4724 sdev_printk(KERN_INFO
, sdev
, "%s raid component\n",
4725 sdev
->no_uld_attach
? "hidding" : "exposing");
4726 rc
= scsi_device_reprobe(sdev
);
4730 * _scsih_reprobe_target - reprobing target
4731 * @starget: scsi target struct
4732 * @no_uld_attach: sdev->no_uld_attach flag setting
4734 * Note: no_uld_attach flag determines whether the disk device is attached
4735 * to block layer. A value of `1` means to not attach.
4738 _scsih_reprobe_target(struct scsi_target
*starget
, int no_uld_attach
)
4740 struct MPT2SAS_TARGET
*sas_target_priv_data
= starget
->hostdata
;
4743 sas_target_priv_data
->flags
|= MPT_TARGET_FLAGS_RAID_COMPONENT
;
4745 sas_target_priv_data
->flags
&= ~MPT_TARGET_FLAGS_RAID_COMPONENT
;
4747 starget_for_each_device(starget
, no_uld_attach
? (void *)1 : NULL
,
4748 _scsih_reprobe_lun
);
4751 * _scsih_sas_volume_add - add new volume
4752 * @ioc: per adapter object
4753 * @element: IR config element data
4759 _scsih_sas_volume_add(struct MPT2SAS_ADAPTER
*ioc
,
4760 Mpi2EventIrConfigElement_t
*element
)
4762 struct _raid_device
*raid_device
;
4763 unsigned long flags
;
4765 u16 handle
= le16_to_cpu(element
->VolDevHandle
);
4768 mpt2sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
4770 printk(MPT2SAS_ERR_FMT
4771 "failure at %s:%d/%s()!\n", ioc
->name
,
4772 __FILE__
, __LINE__
, __func__
);
4776 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
4777 raid_device
= _scsih_raid_device_find_by_wwid(ioc
, wwid
);
4778 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
4783 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
4785 printk(MPT2SAS_ERR_FMT
4786 "failure at %s:%d/%s()!\n", ioc
->name
,
4787 __FILE__
, __LINE__
, __func__
);
4791 raid_device
->id
= ioc
->sas_id
++;
4792 raid_device
->channel
= RAID_CHANNEL
;
4793 raid_device
->handle
= handle
;
4794 raid_device
->wwid
= wwid
;
4795 _scsih_raid_device_add(ioc
, raid_device
);
4796 if (!ioc
->wait_for_port_enable_to_complete
) {
4797 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
4798 raid_device
->id
, 0);
4800 _scsih_raid_device_remove(ioc
, raid_device
);
4802 _scsih_determine_boot_device(ioc
, raid_device
, 1);
4806 * _scsih_sas_volume_delete - delete volume
4807 * @ioc: per adapter object
4808 * @element: IR config element data
4814 _scsih_sas_volume_delete(struct MPT2SAS_ADAPTER
*ioc
,
4815 Mpi2EventIrConfigElement_t
*element
)
4817 struct _raid_device
*raid_device
;
4818 u16 handle
= le16_to_cpu(element
->VolDevHandle
);
4819 unsigned long flags
;
4820 struct MPT2SAS_TARGET
*sas_target_priv_data
;
4822 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
4823 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
4824 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
4827 if (raid_device
->starget
) {
4828 sas_target_priv_data
= raid_device
->starget
->hostdata
;
4829 sas_target_priv_data
->deleted
= 1;
4830 scsi_remove_target(&raid_device
->starget
->dev
);
4832 _scsih_raid_device_remove(ioc
, raid_device
);
4836 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
4837 * @ioc: per adapter object
4838 * @element: IR config element data
4844 _scsih_sas_pd_expose(struct MPT2SAS_ADAPTER
*ioc
,
4845 Mpi2EventIrConfigElement_t
*element
)
4847 struct _sas_device
*sas_device
;
4848 unsigned long flags
;
4849 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
4851 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4852 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
4853 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4857 /* exposing raid component */
4858 sas_device
->volume_handle
= 0;
4859 sas_device
->volume_wwid
= 0;
4860 sas_device
->hidden_raid_component
= 0;
4861 _scsih_reprobe_target(sas_device
->starget
, 0);
4865 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
4866 * @ioc: per adapter object
4867 * @element: IR config element data
4873 _scsih_sas_pd_hide(struct MPT2SAS_ADAPTER
*ioc
,
4874 Mpi2EventIrConfigElement_t
*element
)
4876 struct _sas_device
*sas_device
;
4877 unsigned long flags
;
4878 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
4880 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4881 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
4882 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4886 /* hiding raid component */
4887 mpt2sas_config_get_volume_handle(ioc
, handle
,
4888 &sas_device
->volume_handle
);
4889 mpt2sas_config_get_volume_wwid(ioc
, sas_device
->volume_handle
,
4890 &sas_device
->volume_wwid
);
4891 sas_device
->hidden_raid_component
= 1;
4892 _scsih_reprobe_target(sas_device
->starget
, 1);
4896 * _scsih_sas_pd_delete - delete pd component
4897 * @ioc: per adapter object
4898 * @element: IR config element data
4904 _scsih_sas_pd_delete(struct MPT2SAS_ADAPTER
*ioc
,
4905 Mpi2EventIrConfigElement_t
*element
)
4907 struct _sas_device
*sas_device
;
4908 unsigned long flags
;
4909 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
4911 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4912 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
4913 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4916 _scsih_remove_device(ioc
, sas_device
);
4920 * _scsih_sas_pd_add - remove pd component
4921 * @ioc: per adapter object
4922 * @element: IR config element data
4928 _scsih_sas_pd_add(struct MPT2SAS_ADAPTER
*ioc
,
4929 Mpi2EventIrConfigElement_t
*element
)
4931 struct _sas_device
*sas_device
;
4932 unsigned long flags
;
4933 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
4934 Mpi2ConfigReply_t mpi_reply
;
4935 Mpi2SasDevicePage0_t sas_device_pg0
;
4940 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4941 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
4942 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4944 sas_device
->hidden_raid_component
= 1;
4948 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
4949 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
4950 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4951 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4955 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4956 MPI2_IOCSTATUS_MASK
;
4957 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4958 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4959 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4963 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
4964 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
4965 mpt2sas_transport_update_links(ioc
, sas_address
, handle
,
4966 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
4968 _scsih_add_device(ioc
, handle
, 0, 1);
4971 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4973 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
4974 * @ioc: per adapter object
4975 * @event_data: event data payload
4981 _scsih_sas_ir_config_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
4982 Mpi2EventDataIrConfigChangeList_t
*event_data
)
4984 Mpi2EventIrConfigElement_t
*element
;
4987 char *reason_str
= NULL
, *element_str
= NULL
;
4989 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
4991 printk(MPT2SAS_DEBUG_FMT
"raid config change: (%s), elements(%d)\n",
4992 ioc
->name
, (le32_to_cpu(event_data
->Flags
) &
4993 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ?
4994 "foreign" : "native", event_data
->NumElements
);
4995 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
4996 switch (element
->ReasonCode
) {
4997 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
5000 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
5001 reason_str
= "remove";
5003 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE
:
5004 reason_str
= "no change";
5006 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
5007 reason_str
= "hide";
5009 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
5010 reason_str
= "unhide";
5012 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
5013 reason_str
= "volume_created";
5015 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
5016 reason_str
= "volume_deleted";
5018 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
5019 reason_str
= "pd_created";
5021 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
5022 reason_str
= "pd_deleted";
5025 reason_str
= "unknown reason";
5028 element_type
= le16_to_cpu(element
->ElementFlags
) &
5029 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK
;
5030 switch (element_type
) {
5031 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT
:
5032 element_str
= "volume";
5034 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT
:
5035 element_str
= "phys disk";
5037 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT
:
5038 element_str
= "hot spare";
5041 element_str
= "unknown element";
5044 printk(KERN_DEBUG
"\t(%s:%s), vol handle(0x%04x), "
5045 "pd handle(0x%04x), pd num(0x%02x)\n", element_str
,
5046 reason_str
, le16_to_cpu(element
->VolDevHandle
),
5047 le16_to_cpu(element
->PhysDiskDevHandle
),
5048 element
->PhysDiskNum
);
5054 * _scsih_sas_ir_config_change_event - handle ir configuration change events
5055 * @ioc: per adapter object
5056 * @fw_event: The fw_event_work object
5062 _scsih_sas_ir_config_change_event(struct MPT2SAS_ADAPTER
*ioc
,
5063 struct fw_event_work
*fw_event
)
5065 Mpi2EventIrConfigElement_t
*element
;
5068 Mpi2EventDataIrConfigChangeList_t
*event_data
= fw_event
->event_data
;
5070 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5071 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5072 _scsih_sas_ir_config_change_event_debug(ioc
, event_data
);
5075 foreign_config
= (le32_to_cpu(event_data
->Flags
) &
5076 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ? 1 : 0;
5078 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
5079 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
5081 switch (element
->ReasonCode
) {
5082 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
5083 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
5084 if (!foreign_config
)
5085 _scsih_sas_volume_add(ioc
, element
);
5087 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
5088 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
5089 if (!foreign_config
)
5090 _scsih_sas_volume_delete(ioc
, element
);
5092 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
5093 _scsih_sas_pd_hide(ioc
, element
);
5095 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
5096 _scsih_sas_pd_expose(ioc
, element
);
5098 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
5099 _scsih_sas_pd_add(ioc
, element
);
5101 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
5102 _scsih_sas_pd_delete(ioc
, element
);
5109 * _scsih_sas_ir_volume_event - IR volume event
5110 * @ioc: per adapter object
5111 * @fw_event: The fw_event_work object
5117 _scsih_sas_ir_volume_event(struct MPT2SAS_ADAPTER
*ioc
,
5118 struct fw_event_work
*fw_event
)
5121 unsigned long flags
;
5122 struct _raid_device
*raid_device
;
5126 struct MPT2SAS_TARGET
*sas_target_priv_data
;
5127 Mpi2EventDataIrVolume_t
*event_data
= fw_event
->event_data
;
5129 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED
)
5132 handle
= le16_to_cpu(event_data
->VolDevHandle
);
5133 state
= le32_to_cpu(event_data
->NewValue
);
5134 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: handle(0x%04x), "
5135 "old(0x%08x), new(0x%08x)\n", ioc
->name
, __func__
, handle
,
5136 le32_to_cpu(event_data
->PreviousValue
), state
));
5138 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5139 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
5140 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5143 case MPI2_RAID_VOL_STATE_MISSING
:
5144 case MPI2_RAID_VOL_STATE_FAILED
:
5147 if (raid_device
->starget
) {
5148 sas_target_priv_data
= raid_device
->starget
->hostdata
;
5149 sas_target_priv_data
->deleted
= 1;
5150 scsi_remove_target(&raid_device
->starget
->dev
);
5152 _scsih_raid_device_remove(ioc
, raid_device
);
5155 case MPI2_RAID_VOL_STATE_ONLINE
:
5156 case MPI2_RAID_VOL_STATE_DEGRADED
:
5157 case MPI2_RAID_VOL_STATE_OPTIMAL
:
5161 mpt2sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
5163 printk(MPT2SAS_ERR_FMT
5164 "failure at %s:%d/%s()!\n", ioc
->name
,
5165 __FILE__
, __LINE__
, __func__
);
5169 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
5171 printk(MPT2SAS_ERR_FMT
5172 "failure at %s:%d/%s()!\n", ioc
->name
,
5173 __FILE__
, __LINE__
, __func__
);
5177 raid_device
->id
= ioc
->sas_id
++;
5178 raid_device
->channel
= RAID_CHANNEL
;
5179 raid_device
->handle
= handle
;
5180 raid_device
->wwid
= wwid
;
5181 _scsih_raid_device_add(ioc
, raid_device
);
5182 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
5183 raid_device
->id
, 0);
5185 _scsih_raid_device_remove(ioc
, raid_device
);
5188 case MPI2_RAID_VOL_STATE_INITIALIZING
:
5195 * _scsih_sas_ir_physical_disk_event - PD event
5196 * @ioc: per adapter object
5197 * @fw_event: The fw_event_work object
5203 _scsih_sas_ir_physical_disk_event(struct MPT2SAS_ADAPTER
*ioc
,
5204 struct fw_event_work
*fw_event
)
5206 u16 handle
, parent_handle
;
5208 struct _sas_device
*sas_device
;
5209 unsigned long flags
;
5210 Mpi2ConfigReply_t mpi_reply
;
5211 Mpi2SasDevicePage0_t sas_device_pg0
;
5213 Mpi2EventDataIrPhysicalDisk_t
*event_data
= fw_event
->event_data
;
5216 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED
)
5219 handle
= le16_to_cpu(event_data
->PhysDiskDevHandle
);
5220 state
= le32_to_cpu(event_data
->NewValue
);
5222 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: handle(0x%04x), "
5223 "old(0x%08x), new(0x%08x)\n", ioc
->name
, __func__
, handle
,
5224 le32_to_cpu(event_data
->PreviousValue
), state
));
5226 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5227 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
5228 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5231 case MPI2_RAID_PD_STATE_ONLINE
:
5232 case MPI2_RAID_PD_STATE_DEGRADED
:
5233 case MPI2_RAID_PD_STATE_REBUILDING
:
5234 case MPI2_RAID_PD_STATE_OPTIMAL
:
5236 sas_device
->hidden_raid_component
= 1;
5240 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
5241 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
5243 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5244 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5248 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5249 MPI2_IOCSTATUS_MASK
;
5250 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5251 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5252 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5256 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
5257 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
5258 mpt2sas_transport_update_links(ioc
, sas_address
, handle
,
5259 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
5261 _scsih_add_device(ioc
, handle
, 0, 1);
5265 case MPI2_RAID_PD_STATE_OFFLINE
:
5266 case MPI2_RAID_PD_STATE_NOT_CONFIGURED
:
5267 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE
:
5268 case MPI2_RAID_PD_STATE_HOT_SPARE
:
5274 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5276 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
5277 * @ioc: per adapter object
5278 * @event_data: event data payload
5284 _scsih_sas_ir_operation_status_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
5285 Mpi2EventDataIrOperationStatus_t
*event_data
)
5287 char *reason_str
= NULL
;
5289 switch (event_data
->RAIDOperation
) {
5290 case MPI2_EVENT_IR_RAIDOP_RESYNC
:
5291 reason_str
= "resync";
5293 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION
:
5294 reason_str
= "online capacity expansion";
5296 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK
:
5297 reason_str
= "consistency check";
5299 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT
:
5300 reason_str
= "background init";
5302 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT
:
5303 reason_str
= "make data consistent";
5310 printk(MPT2SAS_INFO_FMT
"raid operational status: (%s)"
5311 "\thandle(0x%04x), percent complete(%d)\n",
5312 ioc
->name
, reason_str
,
5313 le16_to_cpu(event_data
->VolDevHandle
),
5314 event_data
->PercentComplete
);
5319 * _scsih_sas_ir_operation_status_event - handle RAID operation events
5320 * @ioc: per adapter object
5321 * @fw_event: The fw_event_work object
5327 _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER
*ioc
,
5328 struct fw_event_work
*fw_event
)
5330 Mpi2EventDataIrOperationStatus_t
*event_data
= fw_event
->event_data
;
5331 static struct _raid_device
*raid_device
;
5332 unsigned long flags
;
5335 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5336 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5337 _scsih_sas_ir_operation_status_event_debug(ioc
,
5341 /* code added for raid transport support */
5342 if (event_data
->RAIDOperation
== MPI2_EVENT_IR_RAIDOP_RESYNC
) {
5344 handle
= le16_to_cpu(event_data
->VolDevHandle
);
5346 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5347 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
5348 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5353 if (event_data
->RAIDOperation
== MPI2_EVENT_IR_RAIDOP_RESYNC
)
5354 raid_device
->percent_complete
=
5355 event_data
->PercentComplete
;
5360 * _scsih_task_set_full - handle task set full
5361 * @ioc: per adapter object
5362 * @fw_event: The fw_event_work object
5365 * Throttle back qdepth.
5368 _scsih_task_set_full(struct MPT2SAS_ADAPTER
*ioc
, struct fw_event_work
5371 unsigned long flags
;
5372 struct _sas_device
*sas_device
;
5373 static struct _raid_device
*raid_device
;
5374 struct scsi_device
*sdev
;
5380 Mpi2EventDataTaskSetFull_t
*event_data
= fw_event
->event_data
;
5382 current_depth
= le16_to_cpu(event_data
->CurrentDepth
);
5383 handle
= le16_to_cpu(event_data
->DevHandle
);
5384 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5385 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
5387 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5390 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5391 id
= sas_device
->id
;
5392 channel
= sas_device
->channel
;
5393 sas_address
= sas_device
->sas_address
;
5395 /* if hidden raid component, then change to volume characteristics */
5396 if (sas_device
->hidden_raid_component
&& sas_device
->volume_handle
) {
5397 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5398 raid_device
= _scsih_raid_device_find_by_handle(
5399 ioc
, sas_device
->volume_handle
);
5400 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5402 id
= raid_device
->id
;
5403 channel
= raid_device
->channel
;
5404 handle
= raid_device
->handle
;
5405 sas_address
= raid_device
->wwid
;
5409 if (ioc
->logging_level
& MPT_DEBUG_TASK_SET_FULL
)
5410 starget_printk(KERN_DEBUG
, sas_device
->starget
, "task set "
5411 "full: handle(0x%04x), sas_addr(0x%016llx), depth(%d)\n",
5412 handle
, (unsigned long long)sas_address
, current_depth
);
5414 shost_for_each_device(sdev
, ioc
->shost
) {
5415 if (sdev
->id
== id
&& sdev
->channel
== channel
) {
5416 if (current_depth
> sdev
->queue_depth
) {
5417 if (ioc
->logging_level
&
5418 MPT_DEBUG_TASK_SET_FULL
)
5419 sdev_printk(KERN_INFO
, sdev
, "strange "
5420 "observation, the queue depth is"
5421 " (%d) meanwhile fw queue depth "
5422 "is (%d)\n", sdev
->queue_depth
,
5426 depth
= scsi_track_queue_full(sdev
,
5429 sdev_printk(KERN_INFO
, sdev
, "Queue depth "
5430 "reduced to (%d)\n", depth
);
5432 sdev_printk(KERN_INFO
, sdev
, "Tagged Command "
5433 "Queueing is being disabled\n");
5434 else if (depth
== 0)
5435 if (ioc
->logging_level
&
5436 MPT_DEBUG_TASK_SET_FULL
)
5437 sdev_printk(KERN_INFO
, sdev
,
5438 "Queue depth not changed yet\n");
5444 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
5445 * @ioc: per adapter object
5446 * @sas_address: sas address
5447 * @slot: enclosure slot id
5448 * @handle: device handle
5450 * After host reset, find out whether devices are still responding.
5451 * Used in _scsi_remove_unresponsive_sas_devices.
5456 _scsih_mark_responding_sas_device(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
,
5457 u16 slot
, u16 handle
)
5459 struct MPT2SAS_TARGET
*sas_target_priv_data
;
5460 struct scsi_target
*starget
;
5461 struct _sas_device
*sas_device
;
5462 unsigned long flags
;
5464 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5465 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
) {
5466 if (sas_device
->sas_address
== sas_address
&&
5467 sas_device
->slot
== slot
&& sas_device
->starget
) {
5468 sas_device
->responding
= 1;
5469 sas_device
->state
= 0;
5470 starget
= sas_device
->starget
;
5471 sas_target_priv_data
= starget
->hostdata
;
5472 sas_target_priv_data
->tm_busy
= 0;
5473 starget_printk(KERN_INFO
, sas_device
->starget
,
5474 "handle(0x%04x), sas_addr(0x%016llx), enclosure "
5475 "logical id(0x%016llx), slot(%d)\n", handle
,
5476 (unsigned long long)sas_device
->sas_address
,
5477 (unsigned long long)
5478 sas_device
->enclosure_logical_id
,
5480 if (sas_device
->handle
== handle
)
5482 printk(KERN_INFO
"\thandle changed from(0x%04x)!!!\n",
5483 sas_device
->handle
);
5484 sas_device
->handle
= handle
;
5485 sas_target_priv_data
->handle
= handle
;
5490 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5494 * _scsih_search_responding_sas_devices -
5495 * @ioc: per adapter object
5497 * After host reset, find out whether devices are still responding.
5503 _scsih_search_responding_sas_devices(struct MPT2SAS_ADAPTER
*ioc
)
5505 Mpi2SasDevicePage0_t sas_device_pg0
;
5506 Mpi2ConfigReply_t mpi_reply
;
5513 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
, __func__
);
5515 if (list_empty(&ioc
->sas_device_list
))
5519 while (!(mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
5520 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
,
5522 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5523 MPI2_IOCSTATUS_MASK
;
5524 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
5526 handle
= le16_to_cpu(sas_device_pg0
.DevHandle
);
5527 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
5528 if (!(_scsih_is_end_device(device_info
)))
5530 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
5531 slot
= le16_to_cpu(sas_device_pg0
.Slot
);
5532 _scsih_mark_responding_sas_device(ioc
, sas_address
, slot
,
5538 * _scsih_mark_responding_raid_device - mark a raid_device as responding
5539 * @ioc: per adapter object
5540 * @wwid: world wide identifier for raid volume
5541 * @handle: device handle
5543 * After host reset, find out whether devices are still responding.
5544 * Used in _scsi_remove_unresponsive_raid_devices.
5549 _scsih_mark_responding_raid_device(struct MPT2SAS_ADAPTER
*ioc
, u64 wwid
,
5552 struct MPT2SAS_TARGET
*sas_target_priv_data
;
5553 struct scsi_target
*starget
;
5554 struct _raid_device
*raid_device
;
5555 unsigned long flags
;
5557 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5558 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
5559 if (raid_device
->wwid
== wwid
&& raid_device
->starget
) {
5560 raid_device
->responding
= 1;
5561 starget_printk(KERN_INFO
, raid_device
->starget
,
5562 "handle(0x%04x), wwid(0x%016llx)\n", handle
,
5563 (unsigned long long)raid_device
->wwid
);
5564 if (raid_device
->handle
== handle
)
5566 printk(KERN_INFO
"\thandle changed from(0x%04x)!!!\n",
5567 raid_device
->handle
);
5568 raid_device
->handle
= handle
;
5569 starget
= raid_device
->starget
;
5570 sas_target_priv_data
= starget
->hostdata
;
5571 sas_target_priv_data
->handle
= handle
;
5576 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5580 * _scsih_search_responding_raid_devices -
5581 * @ioc: per adapter object
5583 * After host reset, find out whether devices are still responding.
5589 _scsih_search_responding_raid_devices(struct MPT2SAS_ADAPTER
*ioc
)
5591 Mpi2RaidVolPage1_t volume_pg1
;
5592 Mpi2ConfigReply_t mpi_reply
;
5596 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
, __func__
);
5598 if (list_empty(&ioc
->raid_device_list
))
5602 while (!(mpt2sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
5603 &volume_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
5604 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5605 MPI2_IOCSTATUS_MASK
;
5606 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
5608 handle
= le16_to_cpu(volume_pg1
.DevHandle
);
5609 _scsih_mark_responding_raid_device(ioc
,
5610 le64_to_cpu(volume_pg1
.WWID
), handle
);
5615 * _scsih_mark_responding_expander - mark a expander as responding
5616 * @ioc: per adapter object
5617 * @sas_address: sas address
5620 * After host reset, find out whether devices are still responding.
5621 * Used in _scsi_remove_unresponsive_expanders.
5626 _scsih_mark_responding_expander(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
,
5629 struct _sas_node
*sas_expander
;
5630 unsigned long flags
;
5633 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5634 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
5635 if (sas_expander
->sas_address
!= sas_address
)
5637 sas_expander
->responding
= 1;
5638 if (sas_expander
->handle
== handle
)
5640 printk(KERN_INFO
"\texpander(0x%016llx): handle changed"
5641 " from(0x%04x) to (0x%04x)!!!\n",
5642 (unsigned long long)sas_expander
->sas_address
,
5643 sas_expander
->handle
, handle
);
5644 sas_expander
->handle
= handle
;
5645 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++)
5646 sas_expander
->phy
[i
].handle
= handle
;
5650 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5654 * _scsih_search_responding_expanders -
5655 * @ioc: per adapter object
5657 * After host reset, find out whether devices are still responding.
5663 _scsih_search_responding_expanders(struct MPT2SAS_ADAPTER
*ioc
)
5665 Mpi2ExpanderPage0_t expander_pg0
;
5666 Mpi2ConfigReply_t mpi_reply
;
5671 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
, __func__
);
5673 if (list_empty(&ioc
->sas_expander_list
))
5677 while (!(mpt2sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
5678 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL
, handle
))) {
5680 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5681 MPI2_IOCSTATUS_MASK
;
5682 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
5685 handle
= le16_to_cpu(expander_pg0
.DevHandle
);
5686 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
5687 printk(KERN_INFO
"\texpander present: handle(0x%04x), "
5688 "sas_addr(0x%016llx)\n", handle
,
5689 (unsigned long long)sas_address
);
5690 _scsih_mark_responding_expander(ioc
, sas_address
, handle
);
5696 * _scsih_remove_unresponding_devices - removing unresponding devices
5697 * @ioc: per adapter object
5702 _scsih_remove_unresponding_devices(struct MPT2SAS_ADAPTER
*ioc
)
5704 struct _sas_device
*sas_device
, *sas_device_next
;
5705 struct _sas_node
*sas_expander
;
5706 struct _raid_device
*raid_device
, *raid_device_next
;
5709 list_for_each_entry_safe(sas_device
, sas_device_next
,
5710 &ioc
->sas_device_list
, list
) {
5711 if (sas_device
->responding
) {
5712 sas_device
->responding
= 0;
5715 if (sas_device
->starget
)
5716 starget_printk(KERN_INFO
, sas_device
->starget
,
5717 "removing: handle(0x%04x), sas_addr(0x%016llx), "
5718 "enclosure logical id(0x%016llx), slot(%d)\n",
5720 (unsigned long long)sas_device
->sas_address
,
5721 (unsigned long long)
5722 sas_device
->enclosure_logical_id
,
5724 /* invalidate the device handle */
5725 sas_device
->handle
= 0;
5726 _scsih_remove_device(ioc
, sas_device
);
5729 list_for_each_entry_safe(raid_device
, raid_device_next
,
5730 &ioc
->raid_device_list
, list
) {
5731 if (raid_device
->responding
) {
5732 raid_device
->responding
= 0;
5735 if (raid_device
->starget
) {
5736 starget_printk(KERN_INFO
, raid_device
->starget
,
5737 "removing: handle(0x%04x), wwid(0x%016llx)\n",
5738 raid_device
->handle
,
5739 (unsigned long long)raid_device
->wwid
);
5740 scsi_remove_target(&raid_device
->starget
->dev
);
5742 _scsih_raid_device_remove(ioc
, raid_device
);
5745 retry_expander_search
:
5746 sas_expander
= NULL
;
5747 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
5748 if (sas_expander
->responding
) {
5749 sas_expander
->responding
= 0;
5752 _scsih_expander_remove(ioc
, sas_expander
->sas_address
);
5753 goto retry_expander_search
;
5758 * mpt2sas_scsih_reset_handler - reset callback handler (for scsih)
5759 * @ioc: per adapter object
5760 * @reset_phase: phase
5762 * The handler for doing any required cleanup or initialization.
5764 * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
5765 * MPT2_IOC_DONE_RESET
5770 mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER
*ioc
, int reset_phase
)
5772 switch (reset_phase
) {
5773 case MPT2_IOC_PRE_RESET
:
5774 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: "
5775 "MPT2_IOC_PRE_RESET\n", ioc
->name
, __func__
));
5776 _scsih_fw_event_off(ioc
);
5778 case MPT2_IOC_AFTER_RESET
:
5779 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: "
5780 "MPT2_IOC_AFTER_RESET\n", ioc
->name
, __func__
));
5781 if (ioc
->tm_cmds
.status
& MPT2_CMD_PENDING
) {
5782 ioc
->tm_cmds
.status
|= MPT2_CMD_RESET
;
5783 mpt2sas_base_free_smid(ioc
, ioc
->tm_cmds
.smid
);
5784 complete(&ioc
->tm_cmds
.done
);
5786 _scsih_fw_event_on(ioc
);
5787 _scsih_flush_running_cmds(ioc
);
5789 case MPT2_IOC_DONE_RESET
:
5790 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: "
5791 "MPT2_IOC_DONE_RESET\n", ioc
->name
, __func__
));
5792 _scsih_sas_host_refresh(ioc
);
5793 _scsih_search_responding_sas_devices(ioc
);
5794 _scsih_search_responding_raid_devices(ioc
);
5795 _scsih_search_responding_expanders(ioc
);
5797 case MPT2_IOC_RUNNING
:
5798 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: "
5799 "MPT2_IOC_RUNNING\n", ioc
->name
, __func__
));
5800 _scsih_remove_unresponding_devices(ioc
);
5806 * _firmware_event_work - delayed task for processing firmware events
5807 * @ioc: per adapter object
5808 * @work: equal to the fw_event_work object
5814 _firmware_event_work(struct work_struct
*work
)
5816 struct fw_event_work
*fw_event
= container_of(work
,
5817 struct fw_event_work
, work
);
5818 unsigned long flags
;
5819 struct MPT2SAS_ADAPTER
*ioc
= fw_event
->ioc
;
5821 /* the queue is being flushed so ignore this event */
5822 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
5823 if (ioc
->fw_events_off
|| ioc
->remove_host
) {
5824 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
5825 _scsih_fw_event_free(ioc
, fw_event
);
5828 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
5830 if (ioc
->shost_recovery
) {
5831 _scsih_fw_event_requeue(ioc
, fw_event
, 1000);
5835 switch (fw_event
->event
) {
5836 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
5837 _scsih_sas_topology_change_event(ioc
, fw_event
);
5839 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
5840 _scsih_sas_device_status_change_event(ioc
,
5843 case MPI2_EVENT_SAS_DISCOVERY
:
5844 _scsih_sas_discovery_event(ioc
,
5847 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
5848 _scsih_sas_broadcast_primative_event(ioc
,
5851 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
5852 _scsih_sas_enclosure_dev_status_change_event(ioc
,
5855 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
5856 _scsih_sas_ir_config_change_event(ioc
, fw_event
);
5858 case MPI2_EVENT_IR_VOLUME
:
5859 _scsih_sas_ir_volume_event(ioc
, fw_event
);
5861 case MPI2_EVENT_IR_PHYSICAL_DISK
:
5862 _scsih_sas_ir_physical_disk_event(ioc
, fw_event
);
5864 case MPI2_EVENT_IR_OPERATION_STATUS
:
5865 _scsih_sas_ir_operation_status_event(ioc
, fw_event
);
5867 case MPI2_EVENT_TASK_SET_FULL
:
5868 _scsih_task_set_full(ioc
, fw_event
);
5871 _scsih_fw_event_free(ioc
, fw_event
);
5875 * mpt2sas_scsih_event_callback - firmware event handler (called at ISR time)
5876 * @ioc: per adapter object
5877 * @msix_index: MSIX table index supplied by the OS
5878 * @reply: reply message frame(lower 32bit addr)
5879 * Context: interrupt.
5881 * This function merely adds a new work task into ioc->firmware_event_thread.
5882 * The tasks are worked from _firmware_event_work in user context.
5884 * Return 1 meaning mf should be freed from _base_interrupt
5885 * 0 means the mf is freed from this function.
5888 mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER
*ioc
, u8 msix_index
,
5891 struct fw_event_work
*fw_event
;
5892 Mpi2EventNotificationReply_t
*mpi_reply
;
5893 unsigned long flags
;
5896 /* events turned off due to host reset or driver unloading */
5897 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
5898 if (ioc
->fw_events_off
|| ioc
->remove_host
) {
5899 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
5902 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
5904 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
5905 event
= le16_to_cpu(mpi_reply
->Event
);
5909 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
5911 Mpi2EventDataSasBroadcastPrimitive_t
*baen_data
=
5912 (Mpi2EventDataSasBroadcastPrimitive_t
*)
5913 mpi_reply
->EventData
;
5915 if (baen_data
->Primitive
!=
5916 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT
||
5917 ioc
->broadcast_aen_busy
)
5919 ioc
->broadcast_aen_busy
= 1;
5923 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
5924 _scsih_check_topo_delete_events(ioc
,
5925 (Mpi2EventDataSasTopologyChangeList_t
*)
5926 mpi_reply
->EventData
);
5929 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
5930 case MPI2_EVENT_IR_OPERATION_STATUS
:
5931 case MPI2_EVENT_SAS_DISCOVERY
:
5932 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
5933 case MPI2_EVENT_IR_VOLUME
:
5934 case MPI2_EVENT_IR_PHYSICAL_DISK
:
5935 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
5936 case MPI2_EVENT_TASK_SET_FULL
:
5939 default: /* ignore the rest */
5943 fw_event
= kzalloc(sizeof(struct fw_event_work
), GFP_ATOMIC
);
5945 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5946 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5949 fw_event
->event_data
=
5950 kzalloc(mpi_reply
->EventDataLength
*4, GFP_ATOMIC
);
5951 if (!fw_event
->event_data
) {
5952 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5953 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5958 memcpy(fw_event
->event_data
, mpi_reply
->EventData
,
5959 mpi_reply
->EventDataLength
*4);
5960 fw_event
->ioc
= ioc
;
5961 fw_event
->VF_ID
= mpi_reply
->VF_ID
;
5962 fw_event
->VP_ID
= mpi_reply
->VP_ID
;
5963 fw_event
->event
= event
;
5964 _scsih_fw_event_add(ioc
, fw_event
);
5968 /* shost template */
5969 static struct scsi_host_template scsih_driver_template
= {
5970 .module
= THIS_MODULE
,
5971 .name
= "Fusion MPT SAS Host",
5972 .proc_name
= MPT2SAS_DRIVER_NAME
,
5973 .queuecommand
= _scsih_qcmd
,
5974 .target_alloc
= _scsih_target_alloc
,
5975 .slave_alloc
= _scsih_slave_alloc
,
5976 .slave_configure
= _scsih_slave_configure
,
5977 .target_destroy
= _scsih_target_destroy
,
5978 .slave_destroy
= _scsih_slave_destroy
,
5979 .change_queue_depth
= _scsih_change_queue_depth
,
5980 .change_queue_type
= _scsih_change_queue_type
,
5981 .eh_abort_handler
= _scsih_abort
,
5982 .eh_device_reset_handler
= _scsih_dev_reset
,
5983 .eh_target_reset_handler
= _scsih_target_reset
,
5984 .eh_host_reset_handler
= _scsih_host_reset
,
5985 .bios_param
= _scsih_bios_param
,
5988 .sg_tablesize
= MPT2SAS_SG_DEPTH
,
5989 .max_sectors
= 8192,
5991 .use_clustering
= ENABLE_CLUSTERING
,
5992 .shost_attrs
= mpt2sas_host_attrs
,
5993 .sdev_attrs
= mpt2sas_dev_attrs
,
5997 * _scsih_expander_node_remove - removing expander device from list.
5998 * @ioc: per adapter object
5999 * @sas_expander: the sas_device object
6000 * Context: Calling function should acquire ioc->sas_node_lock.
6002 * Removing object and freeing associated memory from the
6003 * ioc->sas_expander_list.
6008 _scsih_expander_node_remove(struct MPT2SAS_ADAPTER
*ioc
,
6009 struct _sas_node
*sas_expander
)
6011 struct _sas_port
*mpt2sas_port
;
6012 struct _sas_device
*sas_device
;
6013 struct _sas_node
*expander_sibling
;
6014 unsigned long flags
;
6019 /* remove sibling ports attached to this expander */
6020 retry_device_search
:
6021 list_for_each_entry(mpt2sas_port
,
6022 &sas_expander
->sas_port_list
, port_list
) {
6023 if (mpt2sas_port
->remote_identify
.device_type
==
6025 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6027 mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
6028 mpt2sas_port
->remote_identify
.sas_address
);
6029 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6032 _scsih_remove_device(ioc
, sas_device
);
6033 if (ioc
->shost_recovery
)
6035 goto retry_device_search
;
6039 retry_expander_search
:
6040 list_for_each_entry(mpt2sas_port
,
6041 &sas_expander
->sas_port_list
, port_list
) {
6043 if (mpt2sas_port
->remote_identify
.device_type
==
6044 MPI2_SAS_DEVICE_INFO_EDGE_EXPANDER
||
6045 mpt2sas_port
->remote_identify
.device_type
==
6046 MPI2_SAS_DEVICE_INFO_FANOUT_EXPANDER
) {
6048 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
6050 mpt2sas_scsih_expander_find_by_sas_address(
6051 ioc
, mpt2sas_port
->remote_identify
.sas_address
);
6052 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
6053 if (!expander_sibling
)
6055 _scsih_expander_remove(ioc
,
6056 expander_sibling
->sas_address
);
6057 if (ioc
->shost_recovery
)
6059 goto retry_expander_search
;
6063 mpt2sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
6064 sas_expander
->sas_address_parent
);
6066 printk(MPT2SAS_INFO_FMT
"expander_remove: handle"
6067 "(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
6068 sas_expander
->handle
, (unsigned long long)
6069 sas_expander
->sas_address
);
6071 list_del(&sas_expander
->list
);
6072 kfree(sas_expander
->phy
);
6073 kfree(sas_expander
);
6077 * _scsih_ir_shutdown - IR shutdown notification
6078 * @ioc: per adapter object
6080 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
6081 * the host system is shutting down.
6086 _scsih_ir_shutdown(struct MPT2SAS_ADAPTER
*ioc
)
6088 Mpi2RaidActionRequest_t
*mpi_request
;
6089 Mpi2RaidActionReply_t
*mpi_reply
;
6092 /* is IR firmware build loaded ? */
6093 if (!ioc
->ir_firmware
)
6096 /* are there any volumes ? */
6097 if (list_empty(&ioc
->raid_device_list
))
6100 mutex_lock(&ioc
->scsih_cmds
.mutex
);
6102 if (ioc
->scsih_cmds
.status
!= MPT2_CMD_NOT_USED
) {
6103 printk(MPT2SAS_ERR_FMT
"%s: scsih_cmd in use\n",
6104 ioc
->name
, __func__
);
6107 ioc
->scsih_cmds
.status
= MPT2_CMD_PENDING
;
6109 smid
= mpt2sas_base_get_smid(ioc
, ioc
->scsih_cb_idx
);
6111 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
6112 ioc
->name
, __func__
);
6113 ioc
->scsih_cmds
.status
= MPT2_CMD_NOT_USED
;
6117 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
6118 ioc
->scsih_cmds
.smid
= smid
;
6119 memset(mpi_request
, 0, sizeof(Mpi2RaidActionRequest_t
));
6121 mpi_request
->Function
= MPI2_FUNCTION_RAID_ACTION
;
6122 mpi_request
->Action
= MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED
;
6124 printk(MPT2SAS_INFO_FMT
"IR shutdown (sending)\n", ioc
->name
);
6125 init_completion(&ioc
->scsih_cmds
.done
);
6126 mpt2sas_base_put_smid_default(ioc
, smid
);
6127 wait_for_completion_timeout(&ioc
->scsih_cmds
.done
, 10*HZ
);
6129 if (!(ioc
->scsih_cmds
.status
& MPT2_CMD_COMPLETE
)) {
6130 printk(MPT2SAS_ERR_FMT
"%s: timeout\n",
6131 ioc
->name
, __func__
);
6135 if (ioc
->scsih_cmds
.status
& MPT2_CMD_REPLY_VALID
) {
6136 mpi_reply
= ioc
->scsih_cmds
.reply
;
6138 printk(MPT2SAS_INFO_FMT
"IR shutdown (complete): "
6139 "ioc_status(0x%04x), loginfo(0x%08x)\n",
6140 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
6141 le32_to_cpu(mpi_reply
->IOCLogInfo
));
6145 ioc
->scsih_cmds
.status
= MPT2_CMD_NOT_USED
;
6146 mutex_unlock(&ioc
->scsih_cmds
.mutex
);
6150 * _scsih_shutdown - routine call during system shutdown
6151 * @pdev: PCI device struct
6156 _scsih_shutdown(struct pci_dev
*pdev
)
6158 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6159 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
6161 _scsih_ir_shutdown(ioc
);
6162 mpt2sas_base_detach(ioc
);
6166 * _scsih_remove - detach and remove add host
6167 * @pdev: PCI device struct
6169 * Routine called when unloading the driver.
6172 static void __devexit
6173 _scsih_remove(struct pci_dev
*pdev
)
6175 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6176 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
6177 struct _sas_port
*mpt2sas_port
;
6178 struct _sas_device
*sas_device
;
6179 struct _sas_node
*expander_sibling
;
6180 struct _raid_device
*raid_device
, *next
;
6181 struct MPT2SAS_TARGET
*sas_target_priv_data
;
6182 struct workqueue_struct
*wq
;
6183 unsigned long flags
;
6185 ioc
->remove_host
= 1;
6186 _scsih_fw_event_off(ioc
);
6188 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
6189 wq
= ioc
->firmware_event_thread
;
6190 ioc
->firmware_event_thread
= NULL
;
6191 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
6193 destroy_workqueue(wq
);
6195 /* release all the volumes */
6196 list_for_each_entry_safe(raid_device
, next
, &ioc
->raid_device_list
,
6198 if (raid_device
->starget
) {
6199 sas_target_priv_data
=
6200 raid_device
->starget
->hostdata
;
6201 sas_target_priv_data
->deleted
= 1;
6202 scsi_remove_target(&raid_device
->starget
->dev
);
6204 printk(MPT2SAS_INFO_FMT
"removing handle(0x%04x), wwid"
6205 "(0x%016llx)\n", ioc
->name
, raid_device
->handle
,
6206 (unsigned long long) raid_device
->wwid
);
6207 _scsih_raid_device_remove(ioc
, raid_device
);
6210 /* free ports attached to the sas_host */
6212 list_for_each_entry(mpt2sas_port
,
6213 &ioc
->sas_hba
.sas_port_list
, port_list
) {
6214 if (mpt2sas_port
->remote_identify
.device_type
==
6217 mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
6218 mpt2sas_port
->remote_identify
.sas_address
);
6220 _scsih_remove_device(ioc
, sas_device
);
6225 mpt2sas_scsih_expander_find_by_sas_address(ioc
,
6226 mpt2sas_port
->remote_identify
.sas_address
);
6227 if (expander_sibling
) {
6228 _scsih_expander_remove(ioc
,
6229 expander_sibling
->sas_address
);
6235 /* free phys attached to the sas_host */
6236 if (ioc
->sas_hba
.num_phys
) {
6237 kfree(ioc
->sas_hba
.phy
);
6238 ioc
->sas_hba
.phy
= NULL
;
6239 ioc
->sas_hba
.num_phys
= 0;
6242 sas_remove_host(shost
);
6243 _scsih_shutdown(pdev
);
6244 list_del(&ioc
->list
);
6245 scsi_remove_host(shost
);
6246 scsi_host_put(shost
);
6250 * _scsih_probe_boot_devices - reports 1st device
6251 * @ioc: per adapter object
6253 * If specified in bios page 2, this routine reports the 1st
6254 * device scsi-ml or sas transport for persistent boot device
6255 * purposes. Please refer to function _scsih_determine_boot_device()
6258 _scsih_probe_boot_devices(struct MPT2SAS_ADAPTER
*ioc
)
6262 struct _sas_device
*sas_device
;
6263 struct _raid_device
*raid_device
;
6265 u64 sas_address_parent
;
6267 unsigned long flags
;
6271 if (ioc
->req_boot_device
.device
) {
6272 device
= ioc
->req_boot_device
.device
;
6273 is_raid
= ioc
->req_boot_device
.is_raid
;
6274 } else if (ioc
->req_alt_boot_device
.device
) {
6275 device
= ioc
->req_alt_boot_device
.device
;
6276 is_raid
= ioc
->req_alt_boot_device
.is_raid
;
6277 } else if (ioc
->current_boot_device
.device
) {
6278 device
= ioc
->current_boot_device
.device
;
6279 is_raid
= ioc
->current_boot_device
.is_raid
;
6286 raid_device
= device
;
6287 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
6288 raid_device
->id
, 0);
6290 _scsih_raid_device_remove(ioc
, raid_device
);
6292 sas_device
= device
;
6293 handle
= sas_device
->handle
;
6294 sas_address_parent
= sas_device
->sas_address_parent
;
6295 sas_address
= sas_device
->sas_address
;
6296 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6297 list_move_tail(&sas_device
->list
, &ioc
->sas_device_list
);
6298 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6299 if (!mpt2sas_transport_port_add(ioc
, sas_device
->handle
,
6300 sas_device
->sas_address_parent
)) {
6301 _scsih_sas_device_remove(ioc
, sas_device
);
6302 } else if (!sas_device
->starget
) {
6303 mpt2sas_transport_port_remove(ioc
, sas_address
,
6304 sas_address_parent
);
6305 _scsih_sas_device_remove(ioc
, sas_device
);
6311 * _scsih_probe_raid - reporting raid volumes to scsi-ml
6312 * @ioc: per adapter object
6314 * Called during initial loading of the driver.
6317 _scsih_probe_raid(struct MPT2SAS_ADAPTER
*ioc
)
6319 struct _raid_device
*raid_device
, *raid_next
;
6322 list_for_each_entry_safe(raid_device
, raid_next
,
6323 &ioc
->raid_device_list
, list
) {
6324 if (raid_device
->starget
)
6326 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
6327 raid_device
->id
, 0);
6329 _scsih_raid_device_remove(ioc
, raid_device
);
6334 * _scsih_probe_sas - reporting sas devices to sas transport
6335 * @ioc: per adapter object
6337 * Called during initial loading of the driver.
6340 _scsih_probe_sas(struct MPT2SAS_ADAPTER
*ioc
)
6342 struct _sas_device
*sas_device
, *next
;
6343 unsigned long flags
;
6345 /* SAS Device List */
6346 list_for_each_entry_safe(sas_device
, next
, &ioc
->sas_device_init_list
,
6348 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6349 list_move_tail(&sas_device
->list
, &ioc
->sas_device_list
);
6350 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6352 if (!mpt2sas_transport_port_add(ioc
, sas_device
->handle
,
6353 sas_device
->sas_address_parent
)) {
6354 _scsih_sas_device_remove(ioc
, sas_device
);
6355 } else if (!sas_device
->starget
) {
6356 mpt2sas_transport_port_remove(ioc
,
6357 sas_device
->sas_address
,
6358 sas_device
->sas_address_parent
);
6359 _scsih_sas_device_remove(ioc
, sas_device
);
6365 * _scsih_probe_devices - probing for devices
6366 * @ioc: per adapter object
6368 * Called during initial loading of the driver.
6371 _scsih_probe_devices(struct MPT2SAS_ADAPTER
*ioc
)
6373 u16 volume_mapping_flags
=
6374 le16_to_cpu(ioc
->ioc_pg8
.IRVolumeMappingFlags
) &
6375 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE
;
6377 if (!(ioc
->facts
.ProtocolFlags
& MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR
))
6378 return; /* return when IOC doesn't support initiator mode */
6380 _scsih_probe_boot_devices(ioc
);
6382 if (ioc
->ir_firmware
) {
6383 if ((volume_mapping_flags
&
6384 MPI2_IOCPAGE8_IRFLAGS_HIGH_VOLUME_MAPPING
)) {
6385 _scsih_probe_sas(ioc
);
6386 _scsih_probe_raid(ioc
);
6388 _scsih_probe_raid(ioc
);
6389 _scsih_probe_sas(ioc
);
6392 _scsih_probe_sas(ioc
);
6396 * _scsih_probe - attach and add scsi host
6397 * @pdev: PCI device struct
6398 * @id: pci device id
6400 * Returns 0 success, anything else error.
6403 _scsih_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
6405 struct MPT2SAS_ADAPTER
*ioc
;
6406 struct Scsi_Host
*shost
;
6408 shost
= scsi_host_alloc(&scsih_driver_template
,
6409 sizeof(struct MPT2SAS_ADAPTER
));
6413 /* init local params */
6414 ioc
= shost_priv(shost
);
6415 memset(ioc
, 0, sizeof(struct MPT2SAS_ADAPTER
));
6416 INIT_LIST_HEAD(&ioc
->list
);
6417 list_add_tail(&ioc
->list
, &mpt2sas_ioc_list
);
6419 ioc
->id
= mpt_ids
++;
6420 sprintf(ioc
->name
, "%s%d", MPT2SAS_DRIVER_NAME
, ioc
->id
);
6422 ioc
->scsi_io_cb_idx
= scsi_io_cb_idx
;
6423 ioc
->tm_cb_idx
= tm_cb_idx
;
6424 ioc
->ctl_cb_idx
= ctl_cb_idx
;
6425 ioc
->base_cb_idx
= base_cb_idx
;
6426 ioc
->transport_cb_idx
= transport_cb_idx
;
6427 ioc
->scsih_cb_idx
= scsih_cb_idx
;
6428 ioc
->config_cb_idx
= config_cb_idx
;
6429 ioc
->tm_tr_cb_idx
= tm_tr_cb_idx
;
6430 ioc
->tm_sas_control_cb_idx
= tm_sas_control_cb_idx
;
6431 ioc
->logging_level
= logging_level
;
6432 /* misc semaphores and spin locks */
6433 spin_lock_init(&ioc
->ioc_reset_in_progress_lock
);
6434 spin_lock_init(&ioc
->scsi_lookup_lock
);
6435 spin_lock_init(&ioc
->sas_device_lock
);
6436 spin_lock_init(&ioc
->sas_node_lock
);
6437 spin_lock_init(&ioc
->fw_event_lock
);
6438 spin_lock_init(&ioc
->raid_device_lock
);
6440 INIT_LIST_HEAD(&ioc
->sas_device_list
);
6441 INIT_LIST_HEAD(&ioc
->sas_device_init_list
);
6442 INIT_LIST_HEAD(&ioc
->sas_expander_list
);
6443 INIT_LIST_HEAD(&ioc
->fw_event_list
);
6444 INIT_LIST_HEAD(&ioc
->raid_device_list
);
6445 INIT_LIST_HEAD(&ioc
->sas_hba
.sas_port_list
);
6446 INIT_LIST_HEAD(&ioc
->delayed_tr_list
);
6448 /* init shost parameters */
6449 shost
->max_cmd_len
= 16;
6450 shost
->max_lun
= max_lun
;
6451 shost
->transportt
= mpt2sas_transport_template
;
6452 shost
->unique_id
= ioc
->id
;
6454 if ((scsi_add_host(shost
, &pdev
->dev
))) {
6455 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6456 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6457 list_del(&ioc
->list
);
6458 goto out_add_shost_fail
;
6461 scsi_host_set_prot(shost
, SHOST_DIF_TYPE1_PROTECTION
6462 | SHOST_DIF_TYPE3_PROTECTION
);
6463 scsi_host_set_guard(shost
, SHOST_DIX_GUARD_CRC
);
6466 snprintf(ioc
->firmware_event_name
, sizeof(ioc
->firmware_event_name
),
6467 "fw_event%d", ioc
->id
);
6468 ioc
->firmware_event_thread
= create_singlethread_workqueue(
6469 ioc
->firmware_event_name
);
6470 if (!ioc
->firmware_event_thread
) {
6471 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6472 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6473 goto out_thread_fail
;
6476 ioc
->wait_for_port_enable_to_complete
= 1;
6477 if ((mpt2sas_base_attach(ioc
))) {
6478 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6479 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6480 goto out_attach_fail
;
6483 ioc
->wait_for_port_enable_to_complete
= 0;
6484 _scsih_probe_devices(ioc
);
6488 destroy_workqueue(ioc
->firmware_event_thread
);
6490 list_del(&ioc
->list
);
6491 scsi_remove_host(shost
);
6498 * _scsih_suspend - power management suspend main entry point
6499 * @pdev: PCI device struct
6500 * @state: PM state change to (usually PCI_D3)
6502 * Returns 0 success, anything else error.
6505 _scsih_suspend(struct pci_dev
*pdev
, pm_message_t state
)
6507 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6508 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
6511 mpt2sas_base_stop_watchdog(ioc
);
6512 flush_scheduled_work();
6513 scsi_block_requests(shost
);
6514 device_state
= pci_choose_state(pdev
, state
);
6515 printk(MPT2SAS_INFO_FMT
"pdev=0x%p, slot=%s, entering "
6516 "operating state [D%d]\n", ioc
->name
, pdev
,
6517 pci_name(pdev
), device_state
);
6519 mpt2sas_base_free_resources(ioc
);
6520 pci_save_state(pdev
);
6521 pci_disable_device(pdev
);
6522 pci_set_power_state(pdev
, device_state
);
6527 * _scsih_resume - power management resume main entry point
6528 * @pdev: PCI device struct
6530 * Returns 0 success, anything else error.
6533 _scsih_resume(struct pci_dev
*pdev
)
6535 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6536 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
6537 u32 device_state
= pdev
->current_state
;
6540 printk(MPT2SAS_INFO_FMT
"pdev=0x%p, slot=%s, previous "
6541 "operating state [D%d]\n", ioc
->name
, pdev
,
6542 pci_name(pdev
), device_state
);
6544 pci_set_power_state(pdev
, PCI_D0
);
6545 pci_enable_wake(pdev
, PCI_D0
, 0);
6546 pci_restore_state(pdev
);
6548 r
= mpt2sas_base_map_resources(ioc
);
6552 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
, SOFT_RESET
);
6553 scsi_unblock_requests(shost
);
6554 mpt2sas_base_start_watchdog(ioc
);
6557 #endif /* CONFIG_PM */
6560 static struct pci_driver scsih_driver
= {
6561 .name
= MPT2SAS_DRIVER_NAME
,
6562 .id_table
= scsih_pci_table
,
6563 .probe
= _scsih_probe
,
6564 .remove
= __devexit_p(_scsih_remove
),
6565 .shutdown
= _scsih_shutdown
,
6567 .suspend
= _scsih_suspend
,
6568 .resume
= _scsih_resume
,
6572 /* raid transport support */
6573 static struct raid_function_template mpt2sas_raid_functions
= {
6574 .cookie
= &scsih_driver_template
,
6575 .is_raid
= _scsih_is_raid
,
6576 .get_resync
= _scsih_get_resync
,
6577 .get_state
= _scsih_get_state
,
6581 * _scsih_init - main entry point for this driver.
6583 * Returns 0 success, anything else error.
6591 printk(KERN_INFO
"%s version %s loaded\n", MPT2SAS_DRIVER_NAME
,
6592 MPT2SAS_DRIVER_VERSION
);
6594 mpt2sas_transport_template
=
6595 sas_attach_transport(&mpt2sas_transport_functions
);
6596 if (!mpt2sas_transport_template
)
6598 /* raid transport support */
6599 mpt2sas_raid_template
= raid_class_attach(&mpt2sas_raid_functions
);
6600 if (!mpt2sas_raid_template
) {
6601 sas_release_transport(mpt2sas_transport_template
);
6605 mpt2sas_base_initialize_callback_handler();
6607 /* queuecommand callback hander */
6608 scsi_io_cb_idx
= mpt2sas_base_register_callback_handler(_scsih_io_done
);
6610 /* task managment callback handler */
6611 tm_cb_idx
= mpt2sas_base_register_callback_handler(_scsih_tm_done
);
6613 /* base internal commands callback handler */
6614 base_cb_idx
= mpt2sas_base_register_callback_handler(mpt2sas_base_done
);
6616 /* transport internal commands callback handler */
6617 transport_cb_idx
= mpt2sas_base_register_callback_handler(
6618 mpt2sas_transport_done
);
6620 /* scsih internal commands callback handler */
6621 scsih_cb_idx
= mpt2sas_base_register_callback_handler(_scsih_done
);
6623 /* configuration page API internal commands callback handler */
6624 config_cb_idx
= mpt2sas_base_register_callback_handler(
6625 mpt2sas_config_done
);
6627 /* ctl module callback handler */
6628 ctl_cb_idx
= mpt2sas_base_register_callback_handler(mpt2sas_ctl_done
);
6630 tm_tr_cb_idx
= mpt2sas_base_register_callback_handler(
6631 _scsih_tm_tr_complete
);
6632 tm_sas_control_cb_idx
= mpt2sas_base_register_callback_handler(
6633 _scsih_sas_control_complete
);
6637 error
= pci_register_driver(&scsih_driver
);
6639 /* raid transport support */
6640 raid_class_release(mpt2sas_raid_template
);
6641 sas_release_transport(mpt2sas_transport_template
);
6648 * _scsih_exit - exit point for this driver (when it is a module).
6650 * Returns 0 success, anything else error.
6655 printk(KERN_INFO
"mpt2sas version %s unloading\n",
6656 MPT2SAS_DRIVER_VERSION
);
6658 pci_unregister_driver(&scsih_driver
);
6662 mpt2sas_base_release_callback_handler(scsi_io_cb_idx
);
6663 mpt2sas_base_release_callback_handler(tm_cb_idx
);
6664 mpt2sas_base_release_callback_handler(base_cb_idx
);
6665 mpt2sas_base_release_callback_handler(transport_cb_idx
);
6666 mpt2sas_base_release_callback_handler(scsih_cb_idx
);
6667 mpt2sas_base_release_callback_handler(config_cb_idx
);
6668 mpt2sas_base_release_callback_handler(ctl_cb_idx
);
6670 mpt2sas_base_release_callback_handler(tm_tr_cb_idx
);
6671 mpt2sas_base_release_callback_handler(tm_sas_control_cb_idx
);
6673 /* raid transport support */
6674 raid_class_release(mpt2sas_raid_template
);
6675 sas_release_transport(mpt2sas_transport_template
);
6679 module_init(_scsih_init
);
6680 module_exit(_scsih_exit
);