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>
56 #include "mpt2sas_base.h"
58 MODULE_AUTHOR(MPT2SAS_AUTHOR
);
59 MODULE_DESCRIPTION(MPT2SAS_DESCRIPTION
);
60 MODULE_LICENSE("GPL");
61 MODULE_VERSION(MPT2SAS_DRIVER_VERSION
);
63 #define RAID_CHANNEL 1
66 static void _scsih_expander_node_remove(struct MPT2SAS_ADAPTER
*ioc
,
67 struct _sas_node
*sas_expander
);
68 static void _firmware_event_work(struct work_struct
*work
);
70 /* global parameters */
71 LIST_HEAD(mpt2sas_ioc_list
);
73 /* local parameters */
74 static u8 scsi_io_cb_idx
= -1;
75 static u8 tm_cb_idx
= -1;
76 static u8 ctl_cb_idx
= -1;
77 static u8 base_cb_idx
= -1;
78 static u8 transport_cb_idx
= -1;
79 static u8 config_cb_idx
= -1;
82 static u8 tm_tr_cb_idx
= -1 ;
83 static u8 tm_sas_control_cb_idx
= -1;
85 /* command line options */
86 static u32 logging_level
;
87 MODULE_PARM_DESC(logging_level
, " bits for enabling additional logging info "
90 /* scsi-mid layer global parmeter is max_report_luns, which is 511 */
91 #define MPT2SAS_MAX_LUN (16895)
92 static int max_lun
= MPT2SAS_MAX_LUN
;
93 module_param(max_lun
, int, 0);
94 MODULE_PARM_DESC(max_lun
, " max lun, default=16895 ");
97 * struct sense_info - common structure for obtaining sense keys
99 * @asc: additional sense code
100 * @ascq: additional sense code qualifier
110 * struct fw_event_work - firmware event struct
111 * @list: link list framework
112 * @work: work object (ioc->fault_reset_work_q)
113 * @ioc: per adapter object
114 * @VF_ID: virtual function id
115 * @VP_ID: virtual port id
116 * @host_reset_handling: handling events during host reset
117 * @ignore: flag meaning this event has been marked to ignore
118 * @event: firmware event MPI2_EVENT_XXX defined in mpt2_ioc.h
119 * @event_data: reply event data payload follows
121 * This object stored on ioc->fw_event_list.
123 struct fw_event_work
{
124 struct list_head list
;
125 struct work_struct work
;
126 struct MPT2SAS_ADAPTER
*ioc
;
129 u8 host_reset_handling
;
136 * struct _scsi_io_transfer - scsi io transfer
137 * @handle: sas device handle (assigned by firmware)
138 * @is_raid: flag set for hidden raid components
139 * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE,
140 * @data_length: data transfer length
141 * @data_dma: dma pointer to data
144 * @cdb_length: cdb length
146 * @timeout: timeout for this command
147 * @VF_ID: virtual function id
148 * @VP_ID: virtual port id
149 * @valid_reply: flag set for reply message
150 * @sense_length: sense length
151 * @ioc_status: ioc status
152 * @scsi_state: scsi state
153 * @scsi_status: scsi staus
154 * @log_info: log information
155 * @transfer_length: data length transfer when there is a reply message
157 * Used for sending internal scsi commands to devices within this module.
158 * Refer to _scsi_send_scsi_io().
160 struct _scsi_io_transfer
{
163 enum dma_data_direction dir
;
166 u8 sense
[SCSI_SENSE_BUFFERSIZE
];
174 /* the following bits are only valid when 'valid_reply = 1' */
184 * The pci device ids are defined in mpi/mpi2_cnfg.h.
186 static struct pci_device_id scsih_pci_table
[] = {
187 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2004
,
188 PCI_ANY_ID
, PCI_ANY_ID
},
190 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2008
,
191 PCI_ANY_ID
, PCI_ANY_ID
},
192 /* Liberator ~ 2108 */
193 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_1
,
194 PCI_ANY_ID
, PCI_ANY_ID
},
195 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_2
,
196 PCI_ANY_ID
, PCI_ANY_ID
},
197 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_3
,
198 PCI_ANY_ID
, PCI_ANY_ID
},
200 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2116_1
,
201 PCI_ANY_ID
, PCI_ANY_ID
},
202 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2116_2
,
203 PCI_ANY_ID
, PCI_ANY_ID
},
204 /* Thunderbolt ~ 2208 */
205 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_1
,
206 PCI_ANY_ID
, PCI_ANY_ID
},
207 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_2
,
208 PCI_ANY_ID
, PCI_ANY_ID
},
209 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_3
,
210 PCI_ANY_ID
, PCI_ANY_ID
},
211 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_4
,
212 PCI_ANY_ID
, PCI_ANY_ID
},
213 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_5
,
214 PCI_ANY_ID
, PCI_ANY_ID
},
215 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_6
,
216 PCI_ANY_ID
, PCI_ANY_ID
},
217 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_7
,
218 PCI_ANY_ID
, PCI_ANY_ID
},
219 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_8
,
220 PCI_ANY_ID
, PCI_ANY_ID
},
221 {0} /* Terminating entry */
223 MODULE_DEVICE_TABLE(pci
, scsih_pci_table
);
226 * _scsih_set_debug_level - global setting of ioc->logging_level.
228 * Note: The logging levels are defined in mpt2sas_debug.h.
231 _scsih_set_debug_level(const char *val
, struct kernel_param
*kp
)
233 int ret
= param_set_int(val
, kp
);
234 struct MPT2SAS_ADAPTER
*ioc
;
239 printk(KERN_INFO
"setting logging_level(0x%08x)\n", logging_level
);
240 list_for_each_entry(ioc
, &mpt2sas_ioc_list
, list
)
241 ioc
->logging_level
= logging_level
;
244 module_param_call(logging_level
, _scsih_set_debug_level
, param_get_int
,
245 &logging_level
, 0644);
248 * _scsih_srch_boot_sas_address - search based on sas_address
249 * @sas_address: sas address
250 * @boot_device: boot device object from bios page 2
252 * Returns 1 when there's a match, 0 means no match.
255 _scsih_srch_boot_sas_address(u64 sas_address
,
256 Mpi2BootDeviceSasWwid_t
*boot_device
)
258 return (sas_address
== le64_to_cpu(boot_device
->SASAddress
)) ? 1 : 0;
262 * _scsih_srch_boot_device_name - search based on device name
263 * @device_name: device name specified in INDENTIFY fram
264 * @boot_device: boot device object from bios page 2
266 * Returns 1 when there's a match, 0 means no match.
269 _scsih_srch_boot_device_name(u64 device_name
,
270 Mpi2BootDeviceDeviceName_t
*boot_device
)
272 return (device_name
== le64_to_cpu(boot_device
->DeviceName
)) ? 1 : 0;
276 * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot
277 * @enclosure_logical_id: enclosure logical id
278 * @slot_number: slot number
279 * @boot_device: boot device object from bios page 2
281 * Returns 1 when there's a match, 0 means no match.
284 _scsih_srch_boot_encl_slot(u64 enclosure_logical_id
, u16 slot_number
,
285 Mpi2BootDeviceEnclosureSlot_t
*boot_device
)
287 return (enclosure_logical_id
== le64_to_cpu(boot_device
->
288 EnclosureLogicalID
) && slot_number
== le16_to_cpu(boot_device
->
289 SlotNumber
)) ? 1 : 0;
293 * _scsih_is_boot_device - search for matching boot device.
294 * @sas_address: sas address
295 * @device_name: device name specified in INDENTIFY fram
296 * @enclosure_logical_id: enclosure logical id
297 * @slot_number: slot number
298 * @form: specifies boot device form
299 * @boot_device: boot device object from bios page 2
301 * Returns 1 when there's a match, 0 means no match.
304 _scsih_is_boot_device(u64 sas_address
, u64 device_name
,
305 u64 enclosure_logical_id
, u16 slot
, u8 form
,
306 Mpi2BiosPage2BootDevice_t
*boot_device
)
311 case MPI2_BIOSPAGE2_FORM_SAS_WWID
:
314 rc
= _scsih_srch_boot_sas_address(
315 sas_address
, &boot_device
->SasWwid
);
317 case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT
:
318 if (!enclosure_logical_id
)
320 rc
= _scsih_srch_boot_encl_slot(
321 enclosure_logical_id
,
322 slot
, &boot_device
->EnclosureSlot
);
324 case MPI2_BIOSPAGE2_FORM_DEVICE_NAME
:
327 rc
= _scsih_srch_boot_device_name(
328 device_name
, &boot_device
->DeviceName
);
330 case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED
:
338 * _scsih_determine_boot_device - determine boot device.
339 * @ioc: per adapter object
340 * @device: either sas_device or raid_device object
341 * @is_raid: [flag] 1 = raid object, 0 = sas object
343 * Determines whether this device should be first reported device to
344 * to scsi-ml or sas transport, this purpose is for persistant boot device.
345 * There are primary, alternate, and current entries in bios page 2. The order
346 * priority is primary, alternate, then current. This routine saves
347 * the corresponding device object and is_raid flag in the ioc object.
348 * The saved data to be used later in _scsih_probe_boot_devices().
351 _scsih_determine_boot_device(struct MPT2SAS_ADAPTER
*ioc
,
352 void *device
, u8 is_raid
)
354 struct _sas_device
*sas_device
;
355 struct _raid_device
*raid_device
;
358 u64 enclosure_logical_id
;
361 /* only process this function when driver loads */
362 if (!ioc
->wait_for_port_enable_to_complete
)
367 sas_address
= sas_device
->sas_address
;
368 device_name
= sas_device
->device_name
;
369 enclosure_logical_id
= sas_device
->enclosure_logical_id
;
370 slot
= sas_device
->slot
;
372 raid_device
= device
;
373 sas_address
= raid_device
->wwid
;
375 enclosure_logical_id
= 0;
379 if (!ioc
->req_boot_device
.device
) {
380 if (_scsih_is_boot_device(sas_address
, device_name
,
381 enclosure_logical_id
, slot
,
382 (ioc
->bios_pg2
.ReqBootDeviceForm
&
383 MPI2_BIOSPAGE2_FORM_MASK
),
384 &ioc
->bios_pg2
.RequestedBootDevice
)) {
385 dinitprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
386 "%s: req_boot_device(0x%016llx)\n",
388 (unsigned long long)sas_address
));
389 ioc
->req_boot_device
.device
= device
;
390 ioc
->req_boot_device
.is_raid
= is_raid
;
394 if (!ioc
->req_alt_boot_device
.device
) {
395 if (_scsih_is_boot_device(sas_address
, device_name
,
396 enclosure_logical_id
, slot
,
397 (ioc
->bios_pg2
.ReqAltBootDeviceForm
&
398 MPI2_BIOSPAGE2_FORM_MASK
),
399 &ioc
->bios_pg2
.RequestedAltBootDevice
)) {
400 dinitprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
401 "%s: req_alt_boot_device(0x%016llx)\n",
403 (unsigned long long)sas_address
));
404 ioc
->req_alt_boot_device
.device
= device
;
405 ioc
->req_alt_boot_device
.is_raid
= is_raid
;
409 if (!ioc
->current_boot_device
.device
) {
410 if (_scsih_is_boot_device(sas_address
, device_name
,
411 enclosure_logical_id
, slot
,
412 (ioc
->bios_pg2
.CurrentBootDeviceForm
&
413 MPI2_BIOSPAGE2_FORM_MASK
),
414 &ioc
->bios_pg2
.CurrentBootDevice
)) {
415 dinitprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
416 "%s: current_boot_device(0x%016llx)\n",
418 (unsigned long long)sas_address
));
419 ioc
->current_boot_device
.device
= device
;
420 ioc
->current_boot_device
.is_raid
= is_raid
;
426 * mpt2sas_scsih_sas_device_find_by_sas_address - sas device search
427 * @ioc: per adapter object
428 * @sas_address: sas address
429 * Context: Calling function should acquire ioc->sas_device_lock
431 * This searches for sas_device based on sas_address, then return sas_device
435 mpt2sas_scsih_sas_device_find_by_sas_address(struct MPT2SAS_ADAPTER
*ioc
,
438 struct _sas_device
*sas_device
, *r
;
441 /* check the sas_device_init_list */
442 list_for_each_entry(sas_device
, &ioc
->sas_device_init_list
,
444 if (sas_device
->sas_address
!= sas_address
)
450 /* then check the sas_device_list */
451 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
) {
452 if (sas_device
->sas_address
!= sas_address
)
462 * _scsih_sas_device_find_by_handle - sas device search
463 * @ioc: per adapter object
464 * @handle: sas device handle (assigned by firmware)
465 * Context: Calling function should acquire ioc->sas_device_lock
467 * This searches for sas_device based on sas_address, then return sas_device
470 static struct _sas_device
*
471 _scsih_sas_device_find_by_handle(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
473 struct _sas_device
*sas_device
, *r
;
476 if (ioc
->wait_for_port_enable_to_complete
) {
477 list_for_each_entry(sas_device
, &ioc
->sas_device_init_list
,
479 if (sas_device
->handle
!= handle
)
485 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
) {
486 if (sas_device
->handle
!= handle
)
498 * _scsih_sas_device_remove - remove sas_device from list.
499 * @ioc: per adapter object
500 * @sas_device: the sas_device object
501 * Context: This function will acquire ioc->sas_device_lock.
503 * Removing object and freeing associated memory from the ioc->sas_device_list.
506 _scsih_sas_device_remove(struct MPT2SAS_ADAPTER
*ioc
,
507 struct _sas_device
*sas_device
)
511 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
512 list_del(&sas_device
->list
);
513 memset(sas_device
, 0, sizeof(struct _sas_device
));
515 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
519 * _scsih_sas_device_add - insert sas_device to the list.
520 * @ioc: per adapter object
521 * @sas_device: the sas_device object
522 * Context: This function will acquire ioc->sas_device_lock.
524 * Adding new object to the ioc->sas_device_list.
527 _scsih_sas_device_add(struct MPT2SAS_ADAPTER
*ioc
,
528 struct _sas_device
*sas_device
)
531 u16 handle
, parent_handle
;
534 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: handle"
535 "(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
, __func__
,
536 sas_device
->handle
, (unsigned long long)sas_device
->sas_address
));
538 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
539 list_add_tail(&sas_device
->list
, &ioc
->sas_device_list
);
540 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
542 handle
= sas_device
->handle
;
543 parent_handle
= sas_device
->parent_handle
;
544 sas_address
= sas_device
->sas_address
;
545 if (!mpt2sas_transport_port_add(ioc
, handle
, parent_handle
))
546 _scsih_sas_device_remove(ioc
, sas_device
);
550 * _scsih_sas_device_init_add - insert sas_device to the list.
551 * @ioc: per adapter object
552 * @sas_device: the sas_device object
553 * Context: This function will acquire ioc->sas_device_lock.
555 * Adding new object at driver load time to the ioc->sas_device_init_list.
558 _scsih_sas_device_init_add(struct MPT2SAS_ADAPTER
*ioc
,
559 struct _sas_device
*sas_device
)
563 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: handle"
564 "(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
, __func__
,
565 sas_device
->handle
, (unsigned long long)sas_device
->sas_address
));
567 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
568 list_add_tail(&sas_device
->list
, &ioc
->sas_device_init_list
);
569 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
570 _scsih_determine_boot_device(ioc
, sas_device
, 0);
574 * mpt2sas_scsih_expander_find_by_handle - expander device search
575 * @ioc: per adapter object
576 * @handle: expander handle (assigned by firmware)
577 * Context: Calling function should acquire ioc->sas_device_lock
579 * This searches for expander device based on handle, then returns the
583 mpt2sas_scsih_expander_find_by_handle(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
585 struct _sas_node
*sas_expander
, *r
;
588 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
589 if (sas_expander
->handle
!= handle
)
599 * _scsih_raid_device_find_by_id - raid device search
600 * @ioc: per adapter object
601 * @id: sas device target id
602 * @channel: sas device channel
603 * Context: Calling function should acquire ioc->raid_device_lock
605 * This searches for raid_device based on target id, then return raid_device
608 static struct _raid_device
*
609 _scsih_raid_device_find_by_id(struct MPT2SAS_ADAPTER
*ioc
, int id
, int channel
)
611 struct _raid_device
*raid_device
, *r
;
614 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
615 if (raid_device
->id
== id
&& raid_device
->channel
== channel
) {
626 * _scsih_raid_device_find_by_handle - raid device search
627 * @ioc: per adapter object
628 * @handle: sas device handle (assigned by firmware)
629 * Context: Calling function should acquire ioc->raid_device_lock
631 * This searches for raid_device based on handle, then return raid_device
634 static struct _raid_device
*
635 _scsih_raid_device_find_by_handle(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
637 struct _raid_device
*raid_device
, *r
;
640 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
641 if (raid_device
->handle
!= handle
)
652 * _scsih_raid_device_find_by_wwid - raid device search
653 * @ioc: per adapter object
654 * @handle: sas device handle (assigned by firmware)
655 * Context: Calling function should acquire ioc->raid_device_lock
657 * This searches for raid_device based on wwid, then return raid_device
660 static struct _raid_device
*
661 _scsih_raid_device_find_by_wwid(struct MPT2SAS_ADAPTER
*ioc
, u64 wwid
)
663 struct _raid_device
*raid_device
, *r
;
666 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
667 if (raid_device
->wwid
!= wwid
)
678 * _scsih_raid_device_add - add raid_device object
679 * @ioc: per adapter object
680 * @raid_device: raid_device object
682 * This is added to the raid_device_list link list.
685 _scsih_raid_device_add(struct MPT2SAS_ADAPTER
*ioc
,
686 struct _raid_device
*raid_device
)
690 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: handle"
691 "(0x%04x), wwid(0x%016llx)\n", ioc
->name
, __func__
,
692 raid_device
->handle
, (unsigned long long)raid_device
->wwid
));
694 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
695 list_add_tail(&raid_device
->list
, &ioc
->raid_device_list
);
696 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
700 * _scsih_raid_device_remove - delete raid_device object
701 * @ioc: per adapter object
702 * @raid_device: raid_device object
704 * This is removed from the raid_device_list link list.
707 _scsih_raid_device_remove(struct MPT2SAS_ADAPTER
*ioc
,
708 struct _raid_device
*raid_device
)
712 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
713 list_del(&raid_device
->list
);
714 memset(raid_device
, 0, sizeof(struct _raid_device
));
716 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
720 * mpt2sas_scsih_expander_find_by_sas_address - expander device search
721 * @ioc: per adapter object
722 * @sas_address: sas address
723 * Context: Calling function should acquire ioc->sas_node_lock.
725 * This searches for expander device based on sas_address, then returns the
729 mpt2sas_scsih_expander_find_by_sas_address(struct MPT2SAS_ADAPTER
*ioc
,
732 struct _sas_node
*sas_expander
, *r
;
735 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
736 if (sas_expander
->sas_address
!= sas_address
)
746 * _scsih_expander_node_add - insert expander device to the list.
747 * @ioc: per adapter object
748 * @sas_expander: the sas_device object
749 * Context: This function will acquire ioc->sas_node_lock.
751 * Adding new object to the ioc->sas_expander_list.
756 _scsih_expander_node_add(struct MPT2SAS_ADAPTER
*ioc
,
757 struct _sas_node
*sas_expander
)
761 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
762 list_add_tail(&sas_expander
->list
, &ioc
->sas_expander_list
);
763 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
767 * _scsih_is_end_device - determines if device is an end device
768 * @device_info: bitfield providing information about the device.
771 * Returns 1 if end device.
774 _scsih_is_end_device(u32 device_info
)
776 if (device_info
& MPI2_SAS_DEVICE_INFO_END_DEVICE
&&
777 ((device_info
& MPI2_SAS_DEVICE_INFO_SSP_TARGET
) |
778 (device_info
& MPI2_SAS_DEVICE_INFO_STP_TARGET
) |
779 (device_info
& MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)))
786 * mptscsih_get_scsi_lookup - returns scmd entry
787 * @ioc: per adapter object
788 * @smid: system request message index
790 * Returns the smid stored scmd pointer.
792 static struct scsi_cmnd
*
793 _scsih_scsi_lookup_get(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
795 return ioc
->scsi_lookup
[smid
- 1].scmd
;
799 * _scsih_scsi_lookup_find_by_scmd - scmd lookup
800 * @ioc: per adapter object
801 * @smid: system request message index
802 * @scmd: pointer to scsi command object
803 * Context: This function will acquire ioc->scsi_lookup_lock.
805 * This will search for a scmd pointer in the scsi_lookup array,
806 * returning the revelent smid. A returned value of zero means invalid.
809 _scsih_scsi_lookup_find_by_scmd(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_cmnd
816 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
818 for (i
= 0; i
< ioc
->scsiio_depth
; i
++) {
819 if (ioc
->scsi_lookup
[i
].scmd
== scmd
) {
820 smid
= ioc
->scsi_lookup
[i
].smid
;
825 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
830 * _scsih_scsi_lookup_find_by_target - search for matching channel:id
831 * @ioc: per adapter object
834 * Context: This function will acquire ioc->scsi_lookup_lock.
836 * This will search for a matching channel:id in the scsi_lookup array,
837 * returning 1 if found.
840 _scsih_scsi_lookup_find_by_target(struct MPT2SAS_ADAPTER
*ioc
, int id
,
847 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
849 for (i
= 0 ; i
< ioc
->scsiio_depth
; i
++) {
850 if (ioc
->scsi_lookup
[i
].scmd
&&
851 (ioc
->scsi_lookup
[i
].scmd
->device
->id
== id
&&
852 ioc
->scsi_lookup
[i
].scmd
->device
->channel
== channel
)) {
858 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
863 * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun
864 * @ioc: per adapter object
868 * Context: This function will acquire ioc->scsi_lookup_lock.
870 * This will search for a matching channel:id:lun in the scsi_lookup array,
871 * returning 1 if found.
874 _scsih_scsi_lookup_find_by_lun(struct MPT2SAS_ADAPTER
*ioc
, int id
,
875 unsigned int lun
, int channel
)
881 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
883 for (i
= 0 ; i
< ioc
->scsiio_depth
; i
++) {
884 if (ioc
->scsi_lookup
[i
].scmd
&&
885 (ioc
->scsi_lookup
[i
].scmd
->device
->id
== id
&&
886 ioc
->scsi_lookup
[i
].scmd
->device
->channel
== channel
&&
887 ioc
->scsi_lookup
[i
].scmd
->device
->lun
== lun
)) {
893 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
898 * _scsih_get_chain_buffer_dma - obtain block of chains (dma address)
899 * @ioc: per adapter object
900 * @smid: system request message index
902 * Returns phys pointer to chain buffer.
905 _scsih_get_chain_buffer_dma(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
907 return ioc
->chain_dma
+ ((smid
- 1) * (ioc
->request_sz
*
908 ioc
->chains_needed_per_io
));
912 * _scsih_get_chain_buffer - obtain block of chains assigned to a mf request
913 * @ioc: per adapter object
914 * @smid: system request message index
916 * Returns virt pointer to chain buffer.
919 _scsih_get_chain_buffer(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
921 return (void *)(ioc
->chain
+ ((smid
- 1) * (ioc
->request_sz
*
922 ioc
->chains_needed_per_io
)));
926 * _scsih_build_scatter_gather - main sg creation routine
927 * @ioc: per adapter object
928 * @scmd: scsi command
929 * @smid: system request message index
932 * The main routine that builds scatter gather table from a given
933 * scsi request sent via the .queuecommand main handler.
935 * Returns 0 success, anything else error
938 _scsih_build_scatter_gather(struct MPT2SAS_ADAPTER
*ioc
,
939 struct scsi_cmnd
*scmd
, u16 smid
)
941 Mpi2SCSIIORequest_t
*mpi_request
;
942 dma_addr_t chain_dma
;
943 struct scatterlist
*sg_scmd
;
944 void *sg_local
, *chain
;
951 u32 sgl_flags_last_element
;
952 u32 sgl_flags_end_buffer
;
954 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
956 /* init scatter gather flags */
957 sgl_flags
= MPI2_SGE_FLAGS_SIMPLE_ELEMENT
;
958 if (scmd
->sc_data_direction
== DMA_TO_DEVICE
)
959 sgl_flags
|= MPI2_SGE_FLAGS_HOST_TO_IOC
;
960 sgl_flags_last_element
= (sgl_flags
| MPI2_SGE_FLAGS_LAST_ELEMENT
)
961 << MPI2_SGE_FLAGS_SHIFT
;
962 sgl_flags_end_buffer
= (sgl_flags
| MPI2_SGE_FLAGS_LAST_ELEMENT
|
963 MPI2_SGE_FLAGS_END_OF_BUFFER
| MPI2_SGE_FLAGS_END_OF_LIST
)
964 << MPI2_SGE_FLAGS_SHIFT
;
965 sgl_flags
= sgl_flags
<< MPI2_SGE_FLAGS_SHIFT
;
967 sg_scmd
= scsi_sglist(scmd
);
968 sges_left
= scsi_dma_map(scmd
);
970 sdev_printk(KERN_ERR
, scmd
->device
, "pci_map_sg"
971 " failed: request for %d bytes!\n", scsi_bufflen(scmd
));
975 sg_local
= &mpi_request
->SGL
;
976 sges_in_segment
= ioc
->max_sges_in_main_message
;
977 if (sges_left
<= sges_in_segment
)
978 goto fill_in_last_segment
;
980 mpi_request
->ChainOffset
= (offsetof(Mpi2SCSIIORequest_t
, SGL
) +
981 (sges_in_segment
* ioc
->sge_size
))/4;
983 /* fill in main message segment when there is a chain following */
984 while (sges_in_segment
) {
985 if (sges_in_segment
== 1)
986 ioc
->base_add_sg_single(sg_local
,
987 sgl_flags_last_element
| sg_dma_len(sg_scmd
),
988 sg_dma_address(sg_scmd
));
990 ioc
->base_add_sg_single(sg_local
, sgl_flags
|
991 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
992 sg_scmd
= sg_next(sg_scmd
);
993 sg_local
+= ioc
->sge_size
;
998 /* initializing the chain flags and pointers */
999 chain_flags
= MPI2_SGE_FLAGS_CHAIN_ELEMENT
<< MPI2_SGE_FLAGS_SHIFT
;
1000 chain
= _scsih_get_chain_buffer(ioc
, smid
);
1001 chain_dma
= _scsih_get_chain_buffer_dma(ioc
, smid
);
1003 sges_in_segment
= (sges_left
<=
1004 ioc
->max_sges_in_chain_message
) ? sges_left
:
1005 ioc
->max_sges_in_chain_message
;
1006 chain_offset
= (sges_left
== sges_in_segment
) ?
1007 0 : (sges_in_segment
* ioc
->sge_size
)/4;
1008 chain_length
= sges_in_segment
* ioc
->sge_size
;
1010 chain_offset
= chain_offset
<<
1011 MPI2_SGE_CHAIN_OFFSET_SHIFT
;
1012 chain_length
+= ioc
->sge_size
;
1014 ioc
->base_add_sg_single(sg_local
, chain_flags
| chain_offset
|
1015 chain_length
, chain_dma
);
1018 goto fill_in_last_segment
;
1020 /* fill in chain segments */
1021 while (sges_in_segment
) {
1022 if (sges_in_segment
== 1)
1023 ioc
->base_add_sg_single(sg_local
,
1024 sgl_flags_last_element
|
1025 sg_dma_len(sg_scmd
),
1026 sg_dma_address(sg_scmd
));
1028 ioc
->base_add_sg_single(sg_local
, sgl_flags
|
1029 sg_dma_len(sg_scmd
),
1030 sg_dma_address(sg_scmd
));
1031 sg_scmd
= sg_next(sg_scmd
);
1032 sg_local
+= ioc
->sge_size
;
1037 chain_dma
+= ioc
->request_sz
;
1038 chain
+= ioc
->request_sz
;
1042 fill_in_last_segment
:
1044 /* fill the last segment */
1047 ioc
->base_add_sg_single(sg_local
, sgl_flags_end_buffer
|
1048 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
1050 ioc
->base_add_sg_single(sg_local
, sgl_flags
|
1051 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
1052 sg_scmd
= sg_next(sg_scmd
);
1053 sg_local
+= ioc
->sge_size
;
1061 * _scsih_change_queue_depth - setting device queue depth
1062 * @sdev: scsi device struct
1063 * @qdepth: requested queue depth
1065 * Returns queue depth.
1068 _scsih_change_queue_depth(struct scsi_device
*sdev
, int qdepth
)
1070 struct Scsi_Host
*shost
= sdev
->host
;
1074 max_depth
= shost
->can_queue
;
1075 if (!sdev
->tagged_supported
)
1077 if (qdepth
> max_depth
)
1079 tag_type
= (qdepth
== 1) ? 0 : MSG_SIMPLE_TAG
;
1080 scsi_adjust_queue_depth(sdev
, tag_type
, qdepth
);
1082 if (sdev
->inquiry_len
> 7)
1083 sdev_printk(KERN_INFO
, sdev
, "qdepth(%d), tagged(%d), "
1084 "simple(%d), ordered(%d), scsi_level(%d), cmd_que(%d)\n",
1085 sdev
->queue_depth
, sdev
->tagged_supported
, sdev
->simple_tags
,
1086 sdev
->ordered_tags
, sdev
->scsi_level
,
1087 (sdev
->inquiry
[7] & 2) >> 1);
1089 return sdev
->queue_depth
;
1093 * _scsih_change_queue_type - changing device queue tag type
1094 * @sdev: scsi device struct
1095 * @tag_type: requested tag type
1097 * Returns queue tag type.
1100 _scsih_change_queue_type(struct scsi_device
*sdev
, int tag_type
)
1102 if (sdev
->tagged_supported
) {
1103 scsi_set_tag_type(sdev
, tag_type
);
1105 scsi_activate_tcq(sdev
, sdev
->queue_depth
);
1107 scsi_deactivate_tcq(sdev
, sdev
->queue_depth
);
1115 * _scsih_target_alloc - target add routine
1116 * @starget: scsi target struct
1118 * Returns 0 if ok. Any other return is assumed to be an error and
1119 * the device is ignored.
1122 _scsih_target_alloc(struct scsi_target
*starget
)
1124 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
1125 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1126 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1127 struct _sas_device
*sas_device
;
1128 struct _raid_device
*raid_device
;
1129 unsigned long flags
;
1130 struct sas_rphy
*rphy
;
1132 sas_target_priv_data
= kzalloc(sizeof(struct scsi_target
), GFP_KERNEL
);
1133 if (!sas_target_priv_data
)
1136 starget
->hostdata
= sas_target_priv_data
;
1137 sas_target_priv_data
->starget
= starget
;
1138 sas_target_priv_data
->handle
= MPT2SAS_INVALID_DEVICE_HANDLE
;
1141 if (starget
->channel
== RAID_CHANNEL
) {
1142 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1143 raid_device
= _scsih_raid_device_find_by_id(ioc
, starget
->id
,
1146 sas_target_priv_data
->handle
= raid_device
->handle
;
1147 sas_target_priv_data
->sas_address
= raid_device
->wwid
;
1148 sas_target_priv_data
->flags
|= MPT_TARGET_FLAGS_VOLUME
;
1149 raid_device
->starget
= starget
;
1151 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1155 /* sas/sata devices */
1156 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1157 rphy
= dev_to_rphy(starget
->dev
.parent
);
1158 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1159 rphy
->identify
.sas_address
);
1162 sas_target_priv_data
->handle
= sas_device
->handle
;
1163 sas_target_priv_data
->sas_address
= sas_device
->sas_address
;
1164 sas_device
->starget
= starget
;
1165 sas_device
->id
= starget
->id
;
1166 sas_device
->channel
= starget
->channel
;
1167 if (sas_device
->hidden_raid_component
)
1168 sas_target_priv_data
->flags
|=
1169 MPT_TARGET_FLAGS_RAID_COMPONENT
;
1171 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1177 * _scsih_target_destroy - target destroy routine
1178 * @starget: scsi target struct
1183 _scsih_target_destroy(struct scsi_target
*starget
)
1185 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
1186 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1187 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1188 struct _sas_device
*sas_device
;
1189 struct _raid_device
*raid_device
;
1190 unsigned long flags
;
1191 struct sas_rphy
*rphy
;
1193 sas_target_priv_data
= starget
->hostdata
;
1194 if (!sas_target_priv_data
)
1197 if (starget
->channel
== RAID_CHANNEL
) {
1198 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1199 raid_device
= _scsih_raid_device_find_by_id(ioc
, starget
->id
,
1202 raid_device
->starget
= NULL
;
1203 raid_device
->sdev
= NULL
;
1205 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1209 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1210 rphy
= dev_to_rphy(starget
->dev
.parent
);
1211 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1212 rphy
->identify
.sas_address
);
1213 if (sas_device
&& (sas_device
->starget
== starget
) &&
1214 (sas_device
->id
== starget
->id
) &&
1215 (sas_device
->channel
== starget
->channel
))
1216 sas_device
->starget
= NULL
;
1218 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1221 kfree(sas_target_priv_data
);
1222 starget
->hostdata
= NULL
;
1226 * _scsih_slave_alloc - device add routine
1227 * @sdev: scsi device struct
1229 * Returns 0 if ok. Any other return is assumed to be an error and
1230 * the device is ignored.
1233 _scsih_slave_alloc(struct scsi_device
*sdev
)
1235 struct Scsi_Host
*shost
;
1236 struct MPT2SAS_ADAPTER
*ioc
;
1237 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1238 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1239 struct scsi_target
*starget
;
1240 struct _raid_device
*raid_device
;
1241 struct _sas_device
*sas_device
;
1242 unsigned long flags
;
1244 sas_device_priv_data
= kzalloc(sizeof(struct scsi_device
), GFP_KERNEL
);
1245 if (!sas_device_priv_data
)
1248 sas_device_priv_data
->lun
= sdev
->lun
;
1249 sas_device_priv_data
->flags
= MPT_DEVICE_FLAGS_INIT
;
1251 starget
= scsi_target(sdev
);
1252 sas_target_priv_data
= starget
->hostdata
;
1253 sas_target_priv_data
->num_luns
++;
1254 sas_device_priv_data
->sas_target
= sas_target_priv_data
;
1255 sdev
->hostdata
= sas_device_priv_data
;
1256 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
))
1257 sdev
->no_uld_attach
= 1;
1259 shost
= dev_to_shost(&starget
->dev
);
1260 ioc
= shost_priv(shost
);
1261 if (starget
->channel
== RAID_CHANNEL
) {
1262 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1263 raid_device
= _scsih_raid_device_find_by_id(ioc
,
1264 starget
->id
, starget
->channel
);
1266 raid_device
->sdev
= sdev
; /* raid is single lun */
1267 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1269 /* set TLR bit for SSP devices */
1270 if (!(ioc
->facts
.IOCCapabilities
&
1271 MPI2_IOCFACTS_CAPABILITY_TLR
))
1273 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1274 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1275 sas_device_priv_data
->sas_target
->sas_address
);
1276 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1277 if (sas_device
&& sas_device
->device_info
&
1278 MPI2_SAS_DEVICE_INFO_SSP_TARGET
)
1279 sas_device_priv_data
->flags
|= MPT_DEVICE_TLR_ON
;
1287 * _scsih_slave_destroy - device destroy routine
1288 * @sdev: scsi device struct
1293 _scsih_slave_destroy(struct scsi_device
*sdev
)
1295 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1296 struct scsi_target
*starget
;
1298 if (!sdev
->hostdata
)
1301 starget
= scsi_target(sdev
);
1302 sas_target_priv_data
= starget
->hostdata
;
1303 sas_target_priv_data
->num_luns
--;
1304 kfree(sdev
->hostdata
);
1305 sdev
->hostdata
= NULL
;
1309 * _scsih_display_sata_capabilities - sata capabilities
1310 * @ioc: per adapter object
1311 * @sas_device: the sas_device object
1312 * @sdev: scsi device struct
1315 _scsih_display_sata_capabilities(struct MPT2SAS_ADAPTER
*ioc
,
1316 struct _sas_device
*sas_device
, struct scsi_device
*sdev
)
1318 Mpi2ConfigReply_t mpi_reply
;
1319 Mpi2SasDevicePage0_t sas_device_pg0
;
1324 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
1325 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, sas_device
->handle
))) {
1326 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1327 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1331 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
1332 MPI2_IOCSTATUS_MASK
;
1333 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
1334 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1335 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1339 flags
= le16_to_cpu(sas_device_pg0
.Flags
);
1340 device_info
= le16_to_cpu(sas_device_pg0
.DeviceInfo
);
1342 sdev_printk(KERN_INFO
, sdev
,
1343 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1344 "sw_preserve(%s)\n",
1345 (device_info
& MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE
) ? "y" : "n",
1346 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED
) ? "y" : "n",
1347 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY
) ? "y" :
1349 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED
) ? "y" : "n",
1350 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED
) ? "y" : "n",
1351 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE
) ? "y" : "n");
1355 * _scsih_get_volume_capabilities - volume capabilities
1356 * @ioc: per adapter object
1357 * @sas_device: the raid_device object
1360 _scsih_get_volume_capabilities(struct MPT2SAS_ADAPTER
*ioc
,
1361 struct _raid_device
*raid_device
)
1363 Mpi2RaidVolPage0_t
*vol_pg0
;
1364 Mpi2RaidPhysDiskPage0_t pd_pg0
;
1365 Mpi2SasDevicePage0_t sas_device_pg0
;
1366 Mpi2ConfigReply_t mpi_reply
;
1370 if ((mpt2sas_config_get_number_pds(ioc
, raid_device
->handle
,
1371 &num_pds
)) || !num_pds
) {
1372 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1373 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1377 raid_device
->num_pds
= num_pds
;
1378 sz
= offsetof(Mpi2RaidVolPage0_t
, PhysDisk
) + (num_pds
*
1379 sizeof(Mpi2RaidVol0PhysDisk_t
));
1380 vol_pg0
= kzalloc(sz
, GFP_KERNEL
);
1382 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1383 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1387 if ((mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, vol_pg0
,
1388 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, raid_device
->handle
, sz
))) {
1389 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1390 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1395 raid_device
->volume_type
= vol_pg0
->VolumeType
;
1397 /* figure out what the underlying devices are by
1398 * obtaining the device_info bits for the 1st device
1400 if (!(mpt2sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
1401 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM
,
1402 vol_pg0
->PhysDisk
[0].PhysDiskNum
))) {
1403 if (!(mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
1404 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
1405 le16_to_cpu(pd_pg0
.DevHandle
)))) {
1406 raid_device
->device_info
=
1407 le32_to_cpu(sas_device_pg0
.DeviceInfo
);
1415 * _scsih_slave_configure - device configure routine.
1416 * @sdev: scsi device struct
1418 * Returns 0 if ok. Any other return is assumed to be an error and
1419 * the device is ignored.
1422 _scsih_slave_configure(struct scsi_device
*sdev
)
1424 struct Scsi_Host
*shost
= sdev
->host
;
1425 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1426 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1427 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1428 struct _sas_device
*sas_device
;
1429 struct _raid_device
*raid_device
;
1430 unsigned long flags
;
1437 sas_device_priv_data
= sdev
->hostdata
;
1438 sas_device_priv_data
->configured_lun
= 1;
1439 sas_device_priv_data
->flags
&= ~MPT_DEVICE_FLAGS_INIT
;
1440 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
1442 /* raid volume handling */
1443 if (sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
1445 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1446 raid_device
= _scsih_raid_device_find_by_handle(ioc
,
1447 sas_target_priv_data
->handle
);
1448 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1450 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1451 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1455 _scsih_get_volume_capabilities(ioc
, raid_device
);
1457 /* RAID Queue Depth Support
1458 * IS volume = underlying qdepth of drive type, either
1459 * MPT2SAS_SAS_QUEUE_DEPTH or MPT2SAS_SATA_QUEUE_DEPTH
1460 * IM/IME/R10 = 128 (MPT2SAS_RAID_QUEUE_DEPTH)
1462 if (raid_device
->device_info
&
1463 MPI2_SAS_DEVICE_INFO_SSP_TARGET
) {
1464 qdepth
= MPT2SAS_SAS_QUEUE_DEPTH
;
1467 qdepth
= MPT2SAS_SATA_QUEUE_DEPTH
;
1468 if (raid_device
->device_info
&
1469 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1475 switch (raid_device
->volume_type
) {
1476 case MPI2_RAID_VOL_TYPE_RAID0
:
1479 case MPI2_RAID_VOL_TYPE_RAID1E
:
1480 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
1481 if (ioc
->manu_pg10
.OEMIdentifier
&&
1482 (ioc
->manu_pg10
.GenericFlags0
&
1483 MFG10_GF0_R10_DISPLAY
) &&
1484 !(raid_device
->num_pds
% 2))
1489 case MPI2_RAID_VOL_TYPE_RAID1
:
1490 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
1493 case MPI2_RAID_VOL_TYPE_RAID10
:
1494 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
1497 case MPI2_RAID_VOL_TYPE_UNKNOWN
:
1499 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
1504 sdev_printk(KERN_INFO
, sdev
, "%s: "
1505 "handle(0x%04x), wwid(0x%016llx), pd_count(%d), type(%s)\n",
1506 r_level
, raid_device
->handle
,
1507 (unsigned long long)raid_device
->wwid
,
1508 raid_device
->num_pds
, ds
);
1509 _scsih_change_queue_depth(sdev
, qdepth
);
1513 /* non-raid handling */
1514 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1515 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1516 sas_device_priv_data
->sas_target
->sas_address
);
1517 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1519 if (sas_target_priv_data
->flags
&
1520 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
1521 mpt2sas_config_get_volume_handle(ioc
,
1522 sas_device
->handle
, &sas_device
->volume_handle
);
1523 mpt2sas_config_get_volume_wwid(ioc
,
1524 sas_device
->volume_handle
,
1525 &sas_device
->volume_wwid
);
1527 if (sas_device
->device_info
& MPI2_SAS_DEVICE_INFO_SSP_TARGET
) {
1528 qdepth
= MPT2SAS_SAS_QUEUE_DEPTH
;
1532 qdepth
= MPT2SAS_SATA_QUEUE_DEPTH
;
1533 if (sas_device
->device_info
&
1534 MPI2_SAS_DEVICE_INFO_STP_TARGET
)
1536 else if (sas_device
->device_info
&
1537 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1541 sdev_printk(KERN_INFO
, sdev
, "%s: handle(0x%04x), "
1542 "sas_addr(0x%016llx), device_name(0x%016llx)\n",
1543 ds
, sas_device
->handle
,
1544 (unsigned long long)sas_device
->sas_address
,
1545 (unsigned long long)sas_device
->device_name
);
1546 sdev_printk(KERN_INFO
, sdev
, "%s: "
1547 "enclosure_logical_id(0x%016llx), slot(%d)\n", ds
,
1548 (unsigned long long) sas_device
->enclosure_logical_id
,
1552 _scsih_display_sata_capabilities(ioc
, sas_device
, sdev
);
1555 _scsih_change_queue_depth(sdev
, qdepth
);
1558 sas_read_port_mode_page(sdev
);
1563 * _scsih_bios_param - fetch head, sector, cylinder info for a disk
1564 * @sdev: scsi device struct
1565 * @bdev: pointer to block device context
1566 * @capacity: device size (in 512 byte sectors)
1567 * @params: three element array to place output:
1568 * params[0] number of heads (max 255)
1569 * params[1] number of sectors (max 63)
1570 * params[2] number of cylinders
1575 _scsih_bios_param(struct scsi_device
*sdev
, struct block_device
*bdev
,
1576 sector_t capacity
, int params
[])
1586 dummy
= heads
* sectors
;
1587 cylinders
= capacity
;
1588 sector_div(cylinders
, dummy
);
1591 * Handle extended translation size for logical drives
1594 if ((ulong
)capacity
>= 0x200000) {
1597 dummy
= heads
* sectors
;
1598 cylinders
= capacity
;
1599 sector_div(cylinders
, dummy
);
1604 params
[1] = sectors
;
1605 params
[2] = cylinders
;
1611 * _scsih_response_code - translation of device response code
1612 * @ioc: per adapter object
1613 * @response_code: response code returned by the device
1618 _scsih_response_code(struct MPT2SAS_ADAPTER
*ioc
, u8 response_code
)
1622 switch (response_code
) {
1623 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE
:
1624 desc
= "task management request completed";
1626 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
:
1627 desc
= "invalid frame";
1629 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED
:
1630 desc
= "task management request not supported";
1632 case MPI2_SCSITASKMGMT_RSP_TM_FAILED
:
1633 desc
= "task management request failed";
1635 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
:
1636 desc
= "task management request succeeded";
1638 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN
:
1639 desc
= "invalid lun";
1642 desc
= "overlapped tag attempted";
1644 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
:
1645 desc
= "task queued, however not sent to target";
1651 printk(MPT2SAS_WARN_FMT
"response_code(0x%01x): %s\n",
1652 ioc
->name
, response_code
, desc
);
1656 * _scsih_tm_done - tm completion routine
1657 * @ioc: per adapter object
1658 * @smid: system request message index
1659 * @msix_index: MSIX table index supplied by the OS
1660 * @reply: reply message frame(lower 32bit addr)
1663 * The callback handler when using scsih_issue_tm.
1665 * Return 1 meaning mf should be freed from _base_interrupt
1666 * 0 means the mf is freed from this function.
1669 _scsih_tm_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
1671 MPI2DefaultReply_t
*mpi_reply
;
1673 if (ioc
->tm_cmds
.status
== MPT2_CMD_NOT_USED
)
1675 if (ioc
->tm_cmds
.smid
!= smid
)
1677 ioc
->tm_cmds
.status
|= MPT2_CMD_COMPLETE
;
1678 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
1680 memcpy(ioc
->tm_cmds
.reply
, mpi_reply
, mpi_reply
->MsgLength
*4);
1681 ioc
->tm_cmds
.status
|= MPT2_CMD_REPLY_VALID
;
1683 ioc
->tm_cmds
.status
&= ~MPT2_CMD_PENDING
;
1684 complete(&ioc
->tm_cmds
.done
);
1689 * mpt2sas_scsih_set_tm_flag - set per target tm_busy
1690 * @ioc: per adapter object
1691 * @handle: device handle
1693 * During taskmangement request, we need to freeze the device queue.
1696 mpt2sas_scsih_set_tm_flag(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
1698 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1699 struct scsi_device
*sdev
;
1702 shost_for_each_device(sdev
, ioc
->shost
) {
1705 sas_device_priv_data
= sdev
->hostdata
;
1706 if (!sas_device_priv_data
)
1708 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
1709 sas_device_priv_data
->sas_target
->tm_busy
= 1;
1711 ioc
->ignore_loginfos
= 1;
1717 * mpt2sas_scsih_clear_tm_flag - clear per target tm_busy
1718 * @ioc: per adapter object
1719 * @handle: device handle
1721 * During taskmangement request, we need to freeze the device queue.
1724 mpt2sas_scsih_clear_tm_flag(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
1726 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1727 struct scsi_device
*sdev
;
1730 shost_for_each_device(sdev
, ioc
->shost
) {
1733 sas_device_priv_data
= sdev
->hostdata
;
1734 if (!sas_device_priv_data
)
1736 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
1737 sas_device_priv_data
->sas_target
->tm_busy
= 0;
1739 ioc
->ignore_loginfos
= 0;
1745 * mpt2sas_scsih_issue_tm - main routine for sending tm requests
1746 * @ioc: per adapter struct
1747 * @device_handle: device handle
1749 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
1750 * @smid_task: smid assigned to the task
1751 * @timeout: timeout in seconds
1752 * Context: The calling function needs to acquire the tm_cmds.mutex
1754 * A generic API for sending task management requests to firmware.
1756 * The ioc->tm_cmds.status flag should be MPT2_CMD_NOT_USED before calling
1759 * The callback index is set inside `ioc->tm_cb_idx`.
1764 mpt2sas_scsih_issue_tm(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
, uint lun
,
1765 u8 type
, u16 smid_task
, ulong timeout
)
1767 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
1768 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
1771 unsigned long timeleft
;
1773 if (ioc
->tm_cmds
.status
!= MPT2_CMD_NOT_USED
) {
1774 printk(MPT2SAS_INFO_FMT
"%s: tm_cmd busy!!!\n",
1775 __func__
, ioc
->name
);
1779 if (ioc
->shost_recovery
) {
1780 printk(MPT2SAS_INFO_FMT
"%s: host reset in progress!\n",
1781 __func__
, ioc
->name
);
1785 ioc_state
= mpt2sas_base_get_iocstate(ioc
, 0);
1786 if (ioc_state
& MPI2_DOORBELL_USED
) {
1787 dhsprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"unexpected doorbell "
1788 "active!\n", ioc
->name
));
1789 goto issue_host_reset
;
1792 if ((ioc_state
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_FAULT
) {
1793 mpt2sas_base_fault_info(ioc
, ioc_state
&
1794 MPI2_DOORBELL_DATA_MASK
);
1795 goto issue_host_reset
;
1798 smid
= mpt2sas_base_get_smid_hpr(ioc
, ioc
->tm_cb_idx
);
1800 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
1801 ioc
->name
, __func__
);
1805 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"sending tm: handle(0x%04x),"
1806 " task_type(0x%02x), smid(%d)\n", ioc
->name
, handle
, type
,
1808 ioc
->tm_cmds
.status
= MPT2_CMD_PENDING
;
1809 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
1810 ioc
->tm_cmds
.smid
= smid
;
1811 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
1812 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
1813 mpi_request
->DevHandle
= cpu_to_le16(handle
);
1814 mpi_request
->TaskType
= type
;
1815 mpi_request
->TaskMID
= cpu_to_le16(smid_task
);
1816 mpi_request
->VP_ID
= 0; /* TODO */
1817 mpi_request
->VF_ID
= 0;
1818 int_to_scsilun(lun
, (struct scsi_lun
*)mpi_request
->LUN
);
1819 mpt2sas_scsih_set_tm_flag(ioc
, handle
);
1820 init_completion(&ioc
->tm_cmds
.done
);
1821 mpt2sas_base_put_smid_hi_priority(ioc
, smid
);
1822 timeleft
= wait_for_completion_timeout(&ioc
->tm_cmds
.done
, timeout
*HZ
);
1823 mpt2sas_scsih_clear_tm_flag(ioc
, handle
);
1824 if (!(ioc
->tm_cmds
.status
& MPT2_CMD_COMPLETE
)) {
1825 printk(MPT2SAS_ERR_FMT
"%s: timeout\n",
1826 ioc
->name
, __func__
);
1827 _debug_dump_mf(mpi_request
,
1828 sizeof(Mpi2SCSITaskManagementRequest_t
)/4);
1829 if (!(ioc
->tm_cmds
.status
& MPT2_CMD_RESET
))
1830 goto issue_host_reset
;
1833 if (ioc
->tm_cmds
.status
& MPT2_CMD_REPLY_VALID
) {
1834 mpi_reply
= ioc
->tm_cmds
.reply
;
1835 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"complete tm: "
1836 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
1837 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
1838 le32_to_cpu(mpi_reply
->IOCLogInfo
),
1839 le32_to_cpu(mpi_reply
->TerminationCount
)));
1840 if (ioc
->logging_level
& MPT_DEBUG_TM
)
1841 _scsih_response_code(ioc
, mpi_reply
->ResponseCode
);
1845 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
, FORCE_BIG_HAMMER
);
1849 * _scsih_abort - eh threads main abort routine
1850 * @sdev: scsi device struct
1852 * Returns SUCCESS if command aborted else FAILED
1855 _scsih_abort(struct scsi_cmnd
*scmd
)
1857 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
1858 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1862 struct scsi_cmnd
*scmd_lookup
;
1864 printk(MPT2SAS_INFO_FMT
"attempting task abort! scmd(%p)\n",
1866 scsi_print_command(scmd
);
1868 sas_device_priv_data
= scmd
->device
->hostdata
;
1869 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
1870 printk(MPT2SAS_INFO_FMT
"device been deleted! scmd(%p)\n",
1872 scmd
->result
= DID_NO_CONNECT
<< 16;
1873 scmd
->scsi_done(scmd
);
1878 /* search for the command */
1879 smid
= _scsih_scsi_lookup_find_by_scmd(ioc
, scmd
);
1881 scmd
->result
= DID_RESET
<< 16;
1886 /* for hidden raid components and volumes this is not supported */
1887 if (sas_device_priv_data
->sas_target
->flags
&
1888 MPT_TARGET_FLAGS_RAID_COMPONENT
||
1889 sas_device_priv_data
->sas_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
1890 scmd
->result
= DID_RESET
<< 16;
1895 mutex_lock(&ioc
->tm_cmds
.mutex
);
1896 handle
= sas_device_priv_data
->sas_target
->handle
;
1897 mpt2sas_scsih_issue_tm(ioc
, handle
, sas_device_priv_data
->lun
,
1898 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
, smid
, 30);
1900 /* sanity check - see whether command actually completed */
1901 scmd_lookup
= _scsih_scsi_lookup_get(ioc
, smid
);
1902 if (scmd_lookup
&& (scmd_lookup
->serial_number
== scmd
->serial_number
))
1906 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
1907 mutex_unlock(&ioc
->tm_cmds
.mutex
);
1910 printk(MPT2SAS_INFO_FMT
"task abort: %s scmd(%p)\n",
1911 ioc
->name
, ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
1916 * _scsih_dev_reset - eh threads main device reset routine
1917 * @sdev: scsi device struct
1919 * Returns SUCCESS if command aborted else FAILED
1922 _scsih_dev_reset(struct scsi_cmnd
*scmd
)
1924 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
1925 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1926 struct _sas_device
*sas_device
;
1927 unsigned long flags
;
1931 printk(MPT2SAS_INFO_FMT
"attempting device reset! scmd(%p)\n",
1933 scsi_print_command(scmd
);
1935 sas_device_priv_data
= scmd
->device
->hostdata
;
1936 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
1937 printk(MPT2SAS_INFO_FMT
"device been deleted! scmd(%p)\n",
1939 scmd
->result
= DID_NO_CONNECT
<< 16;
1940 scmd
->scsi_done(scmd
);
1945 /* for hidden raid components obtain the volume_handle */
1947 if (sas_device_priv_data
->sas_target
->flags
&
1948 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
1949 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1950 sas_device
= _scsih_sas_device_find_by_handle(ioc
,
1951 sas_device_priv_data
->sas_target
->handle
);
1953 handle
= sas_device
->volume_handle
;
1954 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1956 handle
= sas_device_priv_data
->sas_target
->handle
;
1959 scmd
->result
= DID_RESET
<< 16;
1964 mutex_lock(&ioc
->tm_cmds
.mutex
);
1965 mpt2sas_scsih_issue_tm(ioc
, handle
, 0,
1966 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET
, scmd
->device
->lun
,
1970 * sanity check see whether all commands to this device been
1973 if (_scsih_scsi_lookup_find_by_lun(ioc
, scmd
->device
->id
,
1974 scmd
->device
->lun
, scmd
->device
->channel
))
1978 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
1979 mutex_unlock(&ioc
->tm_cmds
.mutex
);
1982 printk(MPT2SAS_INFO_FMT
"device reset: %s scmd(%p)\n",
1983 ioc
->name
, ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
1988 * _scsih_target_reset - eh threads main target reset routine
1989 * @sdev: scsi device struct
1991 * Returns SUCCESS if command aborted else FAILED
1994 _scsih_target_reset(struct scsi_cmnd
*scmd
)
1996 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
1997 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1998 struct _sas_device
*sas_device
;
1999 unsigned long flags
;
2003 printk(MPT2SAS_INFO_FMT
"attempting target reset! scmd(%p)\n",
2005 scsi_print_command(scmd
);
2007 sas_device_priv_data
= scmd
->device
->hostdata
;
2008 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2009 printk(MPT2SAS_INFO_FMT
"target been deleted! scmd(%p)\n",
2011 scmd
->result
= DID_NO_CONNECT
<< 16;
2012 scmd
->scsi_done(scmd
);
2017 /* for hidden raid components obtain the volume_handle */
2019 if (sas_device_priv_data
->sas_target
->flags
&
2020 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2021 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2022 sas_device
= _scsih_sas_device_find_by_handle(ioc
,
2023 sas_device_priv_data
->sas_target
->handle
);
2025 handle
= sas_device
->volume_handle
;
2026 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2028 handle
= sas_device_priv_data
->sas_target
->handle
;
2031 scmd
->result
= DID_RESET
<< 16;
2036 mutex_lock(&ioc
->tm_cmds
.mutex
);
2037 mpt2sas_scsih_issue_tm(ioc
, handle
, 0,
2038 MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
, 0, 30);
2041 * sanity check see whether all commands to this target been
2044 if (_scsih_scsi_lookup_find_by_target(ioc
, scmd
->device
->id
,
2045 scmd
->device
->channel
))
2049 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
2050 mutex_unlock(&ioc
->tm_cmds
.mutex
);
2053 printk(MPT2SAS_INFO_FMT
"target reset: %s scmd(%p)\n",
2054 ioc
->name
, ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2059 * _scsih_host_reset - eh threads main host reset routine
2060 * @sdev: scsi device struct
2062 * Returns SUCCESS if command aborted else FAILED
2065 _scsih_host_reset(struct scsi_cmnd
*scmd
)
2067 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2070 printk(MPT2SAS_INFO_FMT
"attempting host reset! scmd(%p)\n",
2072 scsi_print_command(scmd
);
2074 retval
= mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2076 r
= (retval
< 0) ? FAILED
: SUCCESS
;
2077 printk(MPT2SAS_INFO_FMT
"host reset: %s scmd(%p)\n",
2078 ioc
->name
, ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2084 * _scsih_fw_event_add - insert and queue up fw_event
2085 * @ioc: per adapter object
2086 * @fw_event: object describing the event
2087 * Context: This function will acquire ioc->fw_event_lock.
2089 * This adds the firmware event object into link list, then queues it up to
2090 * be processed from user context.
2095 _scsih_fw_event_add(struct MPT2SAS_ADAPTER
*ioc
, struct fw_event_work
*fw_event
)
2097 unsigned long flags
;
2099 if (ioc
->firmware_event_thread
== NULL
)
2102 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2103 list_add_tail(&fw_event
->list
, &ioc
->fw_event_list
);
2104 INIT_WORK(&fw_event
->work
, _firmware_event_work
);
2105 queue_work(ioc
->firmware_event_thread
, &fw_event
->work
);
2106 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2110 * _scsih_fw_event_free - delete fw_event
2111 * @ioc: per adapter object
2112 * @fw_event: object describing the event
2113 * Context: This function will acquire ioc->fw_event_lock.
2115 * This removes firmware event object from link list, frees associated memory.
2120 _scsih_fw_event_free(struct MPT2SAS_ADAPTER
*ioc
, struct fw_event_work
2123 unsigned long flags
;
2125 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2126 list_del(&fw_event
->list
);
2127 kfree(fw_event
->event_data
);
2129 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2133 * _scsih_fw_event_add - requeue an event
2134 * @ioc: per adapter object
2135 * @fw_event: object describing the event
2136 * Context: This function will acquire ioc->fw_event_lock.
2141 _scsih_fw_event_requeue(struct MPT2SAS_ADAPTER
*ioc
, struct fw_event_work
2142 *fw_event
, unsigned long delay
)
2144 unsigned long flags
;
2145 if (ioc
->firmware_event_thread
== NULL
)
2148 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2149 queue_work(ioc
->firmware_event_thread
, &fw_event
->work
);
2150 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2154 * _scsih_fw_event_off - turn flag off preventing event handling
2155 * @ioc: per adapter object
2157 * Used to prevent handling of firmware events during adapter reset
2163 _scsih_fw_event_off(struct MPT2SAS_ADAPTER
*ioc
)
2165 unsigned long flags
;
2167 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2168 ioc
->fw_events_off
= 1;
2169 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2174 * _scsih_fw_event_on - turn flag on allowing firmware event handling
2175 * @ioc: per adapter object
2180 _scsih_fw_event_on(struct MPT2SAS_ADAPTER
*ioc
)
2182 unsigned long flags
;
2184 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2185 ioc
->fw_events_off
= 0;
2186 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2190 * _scsih_ublock_io_device - set the device state to SDEV_RUNNING
2191 * @ioc: per adapter object
2192 * @handle: device handle
2194 * During device pull we need to appropiately set the sdev state.
2197 _scsih_ublock_io_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
2199 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2200 struct scsi_device
*sdev
;
2202 shost_for_each_device(sdev
, ioc
->shost
) {
2203 sas_device_priv_data
= sdev
->hostdata
;
2204 if (!sas_device_priv_data
)
2206 if (!sas_device_priv_data
->block
)
2208 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2209 dewtprintk(ioc
, sdev_printk(KERN_INFO
, sdev
,
2210 MPT2SAS_INFO_FMT
"SDEV_RUNNING: "
2211 "handle(0x%04x)\n", ioc
->name
, handle
));
2212 sas_device_priv_data
->block
= 0;
2213 scsi_internal_device_unblock(sdev
);
2219 * _scsih_block_io_device - set the device state to SDEV_BLOCK
2220 * @ioc: per adapter object
2221 * @handle: device handle
2223 * During device pull we need to appropiately set the sdev state.
2226 _scsih_block_io_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
2228 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2229 struct scsi_device
*sdev
;
2231 shost_for_each_device(sdev
, ioc
->shost
) {
2232 sas_device_priv_data
= sdev
->hostdata
;
2233 if (!sas_device_priv_data
)
2235 if (sas_device_priv_data
->block
)
2237 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2238 dewtprintk(ioc
, sdev_printk(KERN_INFO
, sdev
,
2239 MPT2SAS_INFO_FMT
"SDEV_BLOCK: "
2240 "handle(0x%04x)\n", ioc
->name
, handle
));
2241 sas_device_priv_data
->block
= 1;
2242 scsi_internal_device_block(sdev
);
2248 * _scsih_block_io_to_children_attached_to_ex
2249 * @ioc: per adapter object
2250 * @sas_expander: the sas_device object
2252 * This routine set sdev state to SDEV_BLOCK for all devices
2253 * attached to this expander. This function called when expander is
2257 _scsih_block_io_to_children_attached_to_ex(struct MPT2SAS_ADAPTER
*ioc
,
2258 struct _sas_node
*sas_expander
)
2260 struct _sas_port
*mpt2sas_port
;
2261 struct _sas_device
*sas_device
;
2262 struct _sas_node
*expander_sibling
;
2263 unsigned long flags
;
2268 list_for_each_entry(mpt2sas_port
,
2269 &sas_expander
->sas_port_list
, port_list
) {
2270 if (mpt2sas_port
->remote_identify
.device_type
==
2272 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2274 mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
2275 mpt2sas_port
->remote_identify
.sas_address
);
2276 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2279 _scsih_block_io_device(ioc
, sas_device
->handle
);
2283 list_for_each_entry(mpt2sas_port
,
2284 &sas_expander
->sas_port_list
, port_list
) {
2286 if (mpt2sas_port
->remote_identify
.device_type
==
2287 MPI2_SAS_DEVICE_INFO_EDGE_EXPANDER
||
2288 mpt2sas_port
->remote_identify
.device_type
==
2289 MPI2_SAS_DEVICE_INFO_FANOUT_EXPANDER
) {
2291 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
2293 mpt2sas_scsih_expander_find_by_sas_address(
2294 ioc
, mpt2sas_port
->remote_identify
.sas_address
);
2295 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
2296 _scsih_block_io_to_children_attached_to_ex(ioc
,
2303 * _scsih_block_io_to_children_attached_directly
2304 * @ioc: per adapter object
2305 * @event_data: topology change event data
2307 * This routine set sdev state to SDEV_BLOCK for all devices
2308 * direct attached during device pull.
2311 _scsih_block_io_to_children_attached_directly(struct MPT2SAS_ADAPTER
*ioc
,
2312 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
2320 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
2321 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
2324 phy_number
= event_data
->StartPhyNum
+ i
;
2325 reason_code
= event_data
->PHY
[i
].PhyStatus
&
2326 MPI2_EVENT_SAS_TOPO_RC_MASK
;
2327 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
)
2328 _scsih_block_io_device(ioc
, handle
);
2329 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
) {
2330 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
2331 if (link_rate
>= MPI2_SAS_NEG_LINK_RATE_1_5
)
2332 _scsih_ublock_io_device(ioc
, handle
);
2338 * _scsih_tm_tr_send - send task management request
2339 * @ioc: per adapter object
2340 * @handle: device handle
2341 * Context: interrupt time.
2343 * This code is to initiate the device removal handshake protocal
2344 * with controller firmware. This function will issue target reset
2345 * using high priority request queue. It will send a sas iounit
2346 * controll request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
2348 * This is designed to send muliple task management request at the same
2349 * time to the fifo. If the fifo is full, we will append the request,
2350 * and process it in a future completion.
2353 _scsih_tm_tr_send(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
2355 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
2356 struct MPT2SAS_TARGET
*sas_target_priv_data
;
2358 struct _sas_device
*sas_device
;
2359 unsigned long flags
;
2360 struct _tr_list
*delayed_tr
;
2362 if (ioc
->shost_recovery
) {
2363 printk(MPT2SAS_INFO_FMT
"%s: host reset in progress!\n",
2364 __func__
, ioc
->name
);
2368 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2369 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
2371 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2372 printk(MPT2SAS_ERR_FMT
"%s: failed finding sas_device\n",
2373 ioc
->name
, __func__
);
2376 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2378 /* skip is hidden raid component */
2379 if (sas_device
->hidden_raid_component
)
2382 smid
= mpt2sas_base_get_smid_hpr(ioc
, ioc
->tm_tr_cb_idx
);
2384 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
2387 INIT_LIST_HEAD(&delayed_tr
->list
);
2388 delayed_tr
->handle
= handle
;
2389 delayed_tr
->state
= MPT2SAS_REQ_SAS_CNTRL
;
2390 list_add_tail(&delayed_tr
->list
,
2391 &ioc
->delayed_tr_list
);
2392 if (sas_device
->starget
)
2393 dewtprintk(ioc
, starget_printk(KERN_INFO
,
2394 sas_device
->starget
, "DELAYED:tr:handle(0x%04x), "
2395 "(open)\n", sas_device
->handle
));
2399 if (sas_device
->starget
&& sas_device
->starget
->hostdata
) {
2400 sas_target_priv_data
= sas_device
->starget
->hostdata
;
2401 sas_target_priv_data
->tm_busy
= 1;
2402 dewtprintk(ioc
, starget_printk(KERN_INFO
, sas_device
->starget
,
2403 "tr:handle(0x%04x), (open)\n", sas_device
->handle
));
2406 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
2407 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
2408 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
2409 mpi_request
->DevHandle
= cpu_to_le16(handle
);
2410 mpi_request
->TaskType
= MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
;
2411 sas_device
->state
|= MPTSAS_STATE_TR_SEND
;
2412 sas_device
->state
|= MPT2SAS_REQ_SAS_CNTRL
;
2413 mpt2sas_base_put_smid_hi_priority(ioc
, smid
);
2419 * _scsih_sas_control_complete - completion routine
2420 * @ioc: per adapter object
2421 * @smid: system request message index
2422 * @msix_index: MSIX table index supplied by the OS
2423 * @reply: reply message frame(lower 32bit addr)
2424 * Context: interrupt time.
2426 * This is the sas iounit controll completion routine.
2427 * This code is part of the code to initiate the device removal
2428 * handshake protocal with controller firmware.
2430 * Return 1 meaning mf should be freed from _base_interrupt
2431 * 0 means the mf is freed from this function.
2434 _scsih_sas_control_complete(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
,
2435 u8 msix_index
, u32 reply
)
2437 unsigned long flags
;
2439 struct _sas_device
*sas_device
;
2440 Mpi2SasIoUnitControlReply_t
*mpi_reply
=
2441 mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
2443 handle
= le16_to_cpu(mpi_reply
->DevHandle
);
2445 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2446 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
2448 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2449 printk(MPT2SAS_ERR_FMT
"%s: failed finding sas_device\n",
2450 ioc
->name
, __func__
);
2453 sas_device
->state
|= MPTSAS_STATE_CNTRL_COMPLETE
;
2454 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2456 if (sas_device
->starget
)
2457 dewtprintk(ioc
, starget_printk(KERN_INFO
, sas_device
->starget
,
2458 "sc_complete:handle(0x%04x), "
2459 "ioc_status(0x%04x), loginfo(0x%08x)\n",
2460 handle
, le16_to_cpu(mpi_reply
->IOCStatus
),
2461 le32_to_cpu(mpi_reply
->IOCLogInfo
)));
2466 * _scsih_tm_tr_complete -
2467 * @ioc: per adapter object
2468 * @smid: system request message index
2469 * @msix_index: MSIX table index supplied by the OS
2470 * @reply: reply message frame(lower 32bit addr)
2471 * Context: interrupt time.
2473 * This is the target reset completion routine.
2474 * This code is part of the code to initiate the device removal
2475 * handshake protocal with controller firmware.
2476 * It will send a sas iounit controll request (MPI2_SAS_OP_REMOVE_DEVICE)
2478 * Return 1 meaning mf should be freed from _base_interrupt
2479 * 0 means the mf is freed from this function.
2482 _scsih_tm_tr_complete(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
,
2485 unsigned long flags
;
2487 struct _sas_device
*sas_device
;
2488 Mpi2SCSITaskManagementReply_t
*mpi_reply
=
2489 mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
2490 Mpi2SasIoUnitControlRequest_t
*mpi_request
;
2492 struct MPT2SAS_TARGET
*sas_target_priv_data
;
2493 struct _tr_list
*delayed_tr
;
2496 handle
= le16_to_cpu(mpi_reply
->DevHandle
);
2497 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2498 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
2500 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2501 printk(MPT2SAS_ERR_FMT
"%s: failed finding sas_device\n",
2502 ioc
->name
, __func__
);
2505 sas_device
->state
|= MPTSAS_STATE_TR_COMPLETE
;
2506 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2508 if (sas_device
->starget
)
2509 dewtprintk(ioc
, starget_printk(KERN_INFO
, sas_device
->starget
,
2510 "tr_complete:handle(0x%04x), (%s) ioc_status(0x%04x), "
2511 "loginfo(0x%08x), completed(%d)\n",
2512 sas_device
->handle
, (sas_device
->state
&
2513 MPT2SAS_REQ_SAS_CNTRL
) ? "open" : "active",
2514 le16_to_cpu(mpi_reply
->IOCStatus
),
2515 le32_to_cpu(mpi_reply
->IOCLogInfo
),
2516 le32_to_cpu(mpi_reply
->TerminationCount
)));
2518 if (sas_device
->starget
&& sas_device
->starget
->hostdata
) {
2519 sas_target_priv_data
= sas_device
->starget
->hostdata
;
2520 sas_target_priv_data
->tm_busy
= 0;
2523 if (!list_empty(&ioc
->delayed_tr_list
)) {
2524 delayed_tr
= list_entry(ioc
->delayed_tr_list
.next
,
2525 struct _tr_list
, list
);
2526 mpt2sas_base_free_smid(ioc
, smid
);
2527 if (delayed_tr
->state
& MPT2SAS_REQ_SAS_CNTRL
)
2528 _scsih_tm_tr_send(ioc
, delayed_tr
->handle
);
2529 list_del(&delayed_tr
->list
);
2531 rc
= 0; /* tells base_interrupt not to free mf */
2536 if (!(sas_device
->state
& MPT2SAS_REQ_SAS_CNTRL
))
2539 if (ioc
->shost_recovery
) {
2540 printk(MPT2SAS_INFO_FMT
"%s: host reset in progress!\n",
2541 __func__
, ioc
->name
);
2545 smid_sas_ctrl
= mpt2sas_base_get_smid(ioc
, ioc
->tm_sas_control_cb_idx
);
2546 if (!smid_sas_ctrl
) {
2547 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
2548 ioc
->name
, __func__
);
2552 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid_sas_ctrl
);
2553 memset(mpi_request
, 0, sizeof(Mpi2SasIoUnitControlRequest_t
));
2554 mpi_request
->Function
= MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
;
2555 mpi_request
->Operation
= MPI2_SAS_OP_REMOVE_DEVICE
;
2556 mpi_request
->DevHandle
= mpi_reply
->DevHandle
;
2557 sas_device
->state
|= MPTSAS_STATE_CNTRL_SEND
;
2558 mpt2sas_base_put_smid_default(ioc
, smid_sas_ctrl
);
2563 * _scsih_check_topo_delete_events - sanity check on topo events
2564 * @ioc: per adapter object
2565 * @event_data: the event data payload
2567 * This routine added to better handle cable breaker.
2569 * This handles the case where driver recieves multiple expander
2570 * add and delete events in a single shot. When there is a delete event
2571 * the routine will void any pending add events waiting in the event queue.
2576 _scsih_check_topo_delete_events(struct MPT2SAS_ADAPTER
*ioc
,
2577 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
2579 struct fw_event_work
*fw_event
;
2580 Mpi2EventDataSasTopologyChangeList_t
*local_event_data
;
2581 u16 expander_handle
;
2582 struct _sas_node
*sas_expander
;
2583 unsigned long flags
;
2587 for (i
= 0 ; i
< event_data
->NumEntries
; i
++) {
2588 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
2591 reason_code
= event_data
->PHY
[i
].PhyStatus
&
2592 MPI2_EVENT_SAS_TOPO_RC_MASK
;
2593 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
)
2594 _scsih_tm_tr_send(ioc
, handle
);
2597 expander_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
2598 if (expander_handle
< ioc
->sas_hba
.num_phys
) {
2599 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
2603 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
2604 || event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
) {
2605 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
2606 sas_expander
= mpt2sas_scsih_expander_find_by_handle(ioc
,
2608 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
2609 _scsih_block_io_to_children_attached_to_ex(ioc
, sas_expander
);
2610 } else if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_RESPONDING
)
2611 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
2613 if (event_data
->ExpStatus
!= MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
)
2616 /* mark ignore flag for pending events */
2617 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2618 list_for_each_entry(fw_event
, &ioc
->fw_event_list
, list
) {
2619 if (fw_event
->event
!= MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
||
2622 local_event_data
= fw_event
->event_data
;
2623 if (local_event_data
->ExpStatus
==
2624 MPI2_EVENT_SAS_TOPO_ES_ADDED
||
2625 local_event_data
->ExpStatus
==
2626 MPI2_EVENT_SAS_TOPO_ES_RESPONDING
) {
2627 if (le16_to_cpu(local_event_data
->ExpanderDevHandle
) ==
2629 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
2630 "setting ignoring flag\n", ioc
->name
));
2631 fw_event
->ignore
= 1;
2635 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2639 * _scsih_flush_running_cmds - completing outstanding commands.
2640 * @ioc: per adapter object
2642 * The flushing out of all pending scmd commands following host reset,
2643 * where all IO is dropped to the floor.
2648 _scsih_flush_running_cmds(struct MPT2SAS_ADAPTER
*ioc
)
2650 struct scsi_cmnd
*scmd
;
2654 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
2655 scmd
= _scsih_scsi_lookup_get(ioc
, smid
);
2659 mpt2sas_base_free_smid(ioc
, smid
);
2660 scsi_dma_unmap(scmd
);
2661 scmd
->result
= DID_RESET
<< 16;
2662 scmd
->scsi_done(scmd
);
2664 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"completing %d cmds\n",
2669 * _scsih_setup_eedp - setup MPI request for EEDP transfer
2670 * @scmd: pointer to scsi command object
2671 * @mpi_request: pointer to the SCSI_IO reqest message frame
2673 * Supporting protection 1 and 3.
2678 _scsih_setup_eedp(struct scsi_cmnd
*scmd
, Mpi2SCSIIORequest_t
*mpi_request
)
2681 unsigned char prot_op
= scsi_get_prot_op(scmd
);
2682 unsigned char prot_type
= scsi_get_prot_type(scmd
);
2684 if (prot_type
== SCSI_PROT_DIF_TYPE0
||
2685 prot_type
== SCSI_PROT_DIF_TYPE2
||
2686 prot_op
== SCSI_PROT_NORMAL
)
2689 if (prot_op
== SCSI_PROT_READ_STRIP
)
2690 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP
;
2691 else if (prot_op
== SCSI_PROT_WRITE_INSERT
)
2692 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_INSERT_OP
;
2696 mpi_request
->EEDPBlockSize
= scmd
->device
->sector_size
;
2698 switch (prot_type
) {
2699 case SCSI_PROT_DIF_TYPE1
:
2702 * enable ref/guard checking
2703 * auto increment ref tag
2705 mpi_request
->EEDPFlags
= eedp_flags
|
2706 MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG
|
2707 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG
|
2708 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
2709 mpi_request
->CDB
.EEDP32
.PrimaryReferenceTag
=
2710 cpu_to_be32(scsi_get_lba(scmd
));
2714 case SCSI_PROT_DIF_TYPE3
:
2717 * enable guard checking
2719 mpi_request
->EEDPFlags
= eedp_flags
|
2720 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
2727 * _scsih_eedp_error_handling - return sense code for EEDP errors
2728 * @scmd: pointer to scsi command object
2729 * @ioc_status: ioc status
2734 _scsih_eedp_error_handling(struct scsi_cmnd
*scmd
, u16 ioc_status
)
2740 switch (ioc_status
) {
2741 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
2744 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
2747 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
2755 if (scmd
->sc_data_direction
== DMA_TO_DEVICE
) {
2756 sk
= ILLEGAL_REQUEST
;
2757 host_byte
= DID_ABORT
;
2759 sk
= ABORTED_COMMAND
;
2763 scsi_build_sense_buffer(0, scmd
->sense_buffer
, sk
, 0x10, ascq
);
2764 scmd
->result
= DRIVER_SENSE
<< 24 | (host_byte
<< 16) |
2765 SAM_STAT_CHECK_CONDITION
;
2769 * _scsih_qcmd - main scsi request entry point
2770 * @scmd: pointer to scsi command object
2771 * @done: function pointer to be invoked on completion
2773 * The callback index is set inside `ioc->scsi_io_cb_idx`.
2775 * Returns 0 on success. If there's a failure, return either:
2776 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
2777 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
2780 _scsih_qcmd(struct scsi_cmnd
*scmd
, void (*done
)(struct scsi_cmnd
*))
2782 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2783 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2784 struct MPT2SAS_TARGET
*sas_target_priv_data
;
2785 Mpi2SCSIIORequest_t
*mpi_request
;
2789 scmd
->scsi_done
= done
;
2790 sas_device_priv_data
= scmd
->device
->hostdata
;
2791 if (!sas_device_priv_data
) {
2792 scmd
->result
= DID_NO_CONNECT
<< 16;
2793 scmd
->scsi_done(scmd
);
2797 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
2798 if (!sas_target_priv_data
|| sas_target_priv_data
->handle
==
2799 MPT2SAS_INVALID_DEVICE_HANDLE
|| sas_target_priv_data
->deleted
) {
2800 scmd
->result
= DID_NO_CONNECT
<< 16;
2801 scmd
->scsi_done(scmd
);
2805 /* see if we are busy with task managment stuff */
2806 if (sas_target_priv_data
->tm_busy
)
2807 return SCSI_MLQUEUE_DEVICE_BUSY
;
2808 else if (ioc
->shost_recovery
|| ioc
->ioc_link_reset_in_progress
)
2809 return SCSI_MLQUEUE_HOST_BUSY
;
2811 if (scmd
->sc_data_direction
== DMA_FROM_DEVICE
)
2812 mpi_control
= MPI2_SCSIIO_CONTROL_READ
;
2813 else if (scmd
->sc_data_direction
== DMA_TO_DEVICE
)
2814 mpi_control
= MPI2_SCSIIO_CONTROL_WRITE
;
2816 mpi_control
= MPI2_SCSIIO_CONTROL_NODATATRANSFER
;
2819 if (!(sas_device_priv_data
->flags
& MPT_DEVICE_FLAGS_INIT
)) {
2820 if (scmd
->device
->tagged_supported
) {
2821 if (scmd
->device
->ordered_tags
)
2822 mpi_control
|= MPI2_SCSIIO_CONTROL_ORDEREDQ
;
2824 mpi_control
|= MPI2_SCSIIO_CONTROL_SIMPLEQ
;
2826 /* MPI Revision I (UNIT = 0xA) - removed MPI2_SCSIIO_CONTROL_UNTAGGED */
2827 /* mpi_control |= MPI2_SCSIIO_CONTROL_UNTAGGED;
2829 mpi_control
|= (0x500);
2832 mpi_control
|= MPI2_SCSIIO_CONTROL_SIMPLEQ
;
2834 if ((sas_device_priv_data
->flags
& MPT_DEVICE_TLR_ON
))
2835 mpi_control
|= MPI2_SCSIIO_CONTROL_TLR_ON
;
2837 smid
= mpt2sas_base_get_smid_scsiio(ioc
, ioc
->scsi_io_cb_idx
, scmd
);
2839 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
2840 ioc
->name
, __func__
);
2843 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
2844 memset(mpi_request
, 0, sizeof(Mpi2SCSIIORequest_t
));
2845 _scsih_setup_eedp(scmd
, mpi_request
);
2846 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
2847 if (sas_device_priv_data
->sas_target
->flags
&
2848 MPT_TARGET_FLAGS_RAID_COMPONENT
)
2849 mpi_request
->Function
= MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
;
2851 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
2852 mpi_request
->DevHandle
=
2853 cpu_to_le16(sas_device_priv_data
->sas_target
->handle
);
2854 mpi_request
->DataLength
= cpu_to_le32(scsi_bufflen(scmd
));
2855 mpi_request
->Control
= cpu_to_le32(mpi_control
);
2856 mpi_request
->IoFlags
= cpu_to_le16(scmd
->cmd_len
);
2857 mpi_request
->MsgFlags
= MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR
;
2858 mpi_request
->SenseBufferLength
= SCSI_SENSE_BUFFERSIZE
;
2859 mpi_request
->SenseBufferLowAddress
=
2860 (u32
)mpt2sas_base_get_sense_buffer_dma(ioc
, smid
);
2861 mpi_request
->SGLOffset0
= offsetof(Mpi2SCSIIORequest_t
, SGL
) / 4;
2862 mpi_request
->SGLFlags
= cpu_to_le16(MPI2_SCSIIO_SGLFLAGS_TYPE_MPI
+
2863 MPI2_SCSIIO_SGLFLAGS_SYSTEM_ADDR
);
2864 mpi_request
->VF_ID
= 0; /* TODO */
2865 mpi_request
->VP_ID
= 0;
2866 int_to_scsilun(sas_device_priv_data
->lun
, (struct scsi_lun
*)
2868 memcpy(mpi_request
->CDB
.CDB32
, scmd
->cmnd
, scmd
->cmd_len
);
2870 if (!mpi_request
->DataLength
) {
2871 mpt2sas_base_build_zero_len_sge(ioc
, &mpi_request
->SGL
);
2873 if (_scsih_build_scatter_gather(ioc
, scmd
, smid
)) {
2874 mpt2sas_base_free_smid(ioc
, smid
);
2879 mpt2sas_base_put_smid_scsi_io(ioc
, smid
,
2880 sas_device_priv_data
->sas_target
->handle
);
2884 return SCSI_MLQUEUE_HOST_BUSY
;
2888 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
2889 * @sense_buffer: sense data returned by target
2890 * @data: normalized skey/asc/ascq
2895 _scsih_normalize_sense(char *sense_buffer
, struct sense_info
*data
)
2897 if ((sense_buffer
[0] & 0x7F) >= 0x72) {
2898 /* descriptor format */
2899 data
->skey
= sense_buffer
[1] & 0x0F;
2900 data
->asc
= sense_buffer
[2];
2901 data
->ascq
= sense_buffer
[3];
2904 data
->skey
= sense_buffer
[2] & 0x0F;
2905 data
->asc
= sense_buffer
[12];
2906 data
->ascq
= sense_buffer
[13];
2910 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
2912 * _scsih_scsi_ioc_info - translated non-succesfull SCSI_IO request
2913 * @ioc: per adapter object
2914 * @scmd: pointer to scsi command object
2915 * @mpi_reply: reply mf payload returned from firmware
2917 * scsi_status - SCSI Status code returned from target device
2918 * scsi_state - state info associated with SCSI_IO determined by ioc
2919 * ioc_status - ioc supplied status info
2924 _scsih_scsi_ioc_info(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
,
2925 Mpi2SCSIIOReply_t
*mpi_reply
, u16 smid
)
2929 u16 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) &
2930 MPI2_IOCSTATUS_MASK
;
2931 u8 scsi_state
= mpi_reply
->SCSIState
;
2932 u8 scsi_status
= mpi_reply
->SCSIStatus
;
2933 char *desc_ioc_state
= NULL
;
2934 char *desc_scsi_status
= NULL
;
2935 char *desc_scsi_state
= ioc
->tmp_string
;
2936 u32 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
2938 if (log_info
== 0x31170000)
2941 switch (ioc_status
) {
2942 case MPI2_IOCSTATUS_SUCCESS
:
2943 desc_ioc_state
= "success";
2945 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
2946 desc_ioc_state
= "invalid function";
2948 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
2949 desc_ioc_state
= "scsi recovered error";
2951 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE
:
2952 desc_ioc_state
= "scsi invalid dev handle";
2954 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
2955 desc_ioc_state
= "scsi device not there";
2957 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
2958 desc_ioc_state
= "scsi data overrun";
2960 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
2961 desc_ioc_state
= "scsi data underrun";
2963 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
2964 desc_ioc_state
= "scsi io data error";
2966 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
2967 desc_ioc_state
= "scsi protocol error";
2969 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
2970 desc_ioc_state
= "scsi task terminated";
2972 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
2973 desc_ioc_state
= "scsi residual mismatch";
2975 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
2976 desc_ioc_state
= "scsi task mgmt failed";
2978 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
2979 desc_ioc_state
= "scsi ioc terminated";
2981 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
2982 desc_ioc_state
= "scsi ext terminated";
2984 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
2985 desc_ioc_state
= "eedp guard error";
2987 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
2988 desc_ioc_state
= "eedp ref tag error";
2990 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
2991 desc_ioc_state
= "eedp app tag error";
2994 desc_ioc_state
= "unknown";
2998 switch (scsi_status
) {
2999 case MPI2_SCSI_STATUS_GOOD
:
3000 desc_scsi_status
= "good";
3002 case MPI2_SCSI_STATUS_CHECK_CONDITION
:
3003 desc_scsi_status
= "check condition";
3005 case MPI2_SCSI_STATUS_CONDITION_MET
:
3006 desc_scsi_status
= "condition met";
3008 case MPI2_SCSI_STATUS_BUSY
:
3009 desc_scsi_status
= "busy";
3011 case MPI2_SCSI_STATUS_INTERMEDIATE
:
3012 desc_scsi_status
= "intermediate";
3014 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET
:
3015 desc_scsi_status
= "intermediate condmet";
3017 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT
:
3018 desc_scsi_status
= "reservation conflict";
3020 case MPI2_SCSI_STATUS_COMMAND_TERMINATED
:
3021 desc_scsi_status
= "command terminated";
3023 case MPI2_SCSI_STATUS_TASK_SET_FULL
:
3024 desc_scsi_status
= "task set full";
3026 case MPI2_SCSI_STATUS_ACA_ACTIVE
:
3027 desc_scsi_status
= "aca active";
3029 case MPI2_SCSI_STATUS_TASK_ABORTED
:
3030 desc_scsi_status
= "task aborted";
3033 desc_scsi_status
= "unknown";
3037 desc_scsi_state
[0] = '\0';
3039 desc_scsi_state
= " ";
3040 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
3041 strcat(desc_scsi_state
, "response info ");
3042 if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
3043 strcat(desc_scsi_state
, "state terminated ");
3044 if (scsi_state
& MPI2_SCSI_STATE_NO_SCSI_STATUS
)
3045 strcat(desc_scsi_state
, "no status ");
3046 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_FAILED
)
3047 strcat(desc_scsi_state
, "autosense failed ");
3048 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
)
3049 strcat(desc_scsi_state
, "autosense valid ");
3051 scsi_print_command(scmd
);
3052 printk(MPT2SAS_WARN_FMT
"\tdev handle(0x%04x), "
3053 "ioc_status(%s)(0x%04x), smid(%d)\n", ioc
->name
,
3054 le16_to_cpu(mpi_reply
->DevHandle
), desc_ioc_state
,
3056 printk(MPT2SAS_WARN_FMT
"\trequest_len(%d), underflow(%d), "
3057 "resid(%d)\n", ioc
->name
, scsi_bufflen(scmd
), scmd
->underflow
,
3058 scsi_get_resid(scmd
));
3059 printk(MPT2SAS_WARN_FMT
"\ttag(%d), transfer_count(%d), "
3060 "sc->result(0x%08x)\n", ioc
->name
, le16_to_cpu(mpi_reply
->TaskTag
),
3061 le32_to_cpu(mpi_reply
->TransferCount
), scmd
->result
);
3062 printk(MPT2SAS_WARN_FMT
"\tscsi_status(%s)(0x%02x), "
3063 "scsi_state(%s)(0x%02x)\n", ioc
->name
, desc_scsi_status
,
3064 scsi_status
, desc_scsi_state
, scsi_state
);
3066 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
3067 struct sense_info data
;
3068 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
3069 printk(MPT2SAS_WARN_FMT
"\t[sense_key,asc,ascq]: "
3070 "[0x%02x,0x%02x,0x%02x]\n", ioc
->name
, data
.skey
,
3071 data
.asc
, data
.ascq
);
3074 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
) {
3075 response_info
= le32_to_cpu(mpi_reply
->ResponseInfo
);
3076 response_bytes
= (u8
*)&response_info
;
3077 _scsih_response_code(ioc
, response_bytes
[3]);
3083 * _scsih_smart_predicted_fault - illuminate Fault LED
3084 * @ioc: per adapter object
3085 * @handle: device handle
3090 _scsih_smart_predicted_fault(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
3092 Mpi2SepReply_t mpi_reply
;
3093 Mpi2SepRequest_t mpi_request
;
3094 struct scsi_target
*starget
;
3095 struct MPT2SAS_TARGET
*sas_target_priv_data
;
3096 Mpi2EventNotificationReply_t
*event_reply
;
3097 Mpi2EventDataSasDeviceStatusChange_t
*event_data
;
3098 struct _sas_device
*sas_device
;
3100 unsigned long flags
;
3102 /* only handle non-raid devices */
3103 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
3104 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
3106 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3109 starget
= sas_device
->starget
;
3110 sas_target_priv_data
= starget
->hostdata
;
3112 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
) ||
3113 ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
))) {
3114 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3117 starget_printk(KERN_WARNING
, starget
, "predicted fault\n");
3118 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3120 if (ioc
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_IBM
) {
3121 memset(&mpi_request
, 0, sizeof(Mpi2SepRequest_t
));
3122 mpi_request
.Function
= MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR
;
3123 mpi_request
.Action
= MPI2_SEP_REQ_ACTION_WRITE_STATUS
;
3124 mpi_request
.SlotStatus
=
3125 MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT
;
3126 mpi_request
.DevHandle
= cpu_to_le16(handle
);
3127 mpi_request
.Flags
= MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS
;
3128 if ((mpt2sas_base_scsi_enclosure_processor(ioc
, &mpi_reply
,
3129 &mpi_request
)) != 0) {
3130 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3131 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3135 if (mpi_reply
.IOCStatus
|| mpi_reply
.IOCLogInfo
) {
3136 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3137 "enclosure_processor: ioc_status (0x%04x), "
3138 "loginfo(0x%08x)\n", ioc
->name
,
3139 le16_to_cpu(mpi_reply
.IOCStatus
),
3140 le32_to_cpu(mpi_reply
.IOCLogInfo
)));
3145 /* insert into event log */
3146 sz
= offsetof(Mpi2EventNotificationReply_t
, EventData
) +
3147 sizeof(Mpi2EventDataSasDeviceStatusChange_t
);
3148 event_reply
= kzalloc(sz
, GFP_KERNEL
);
3150 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3151 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3155 event_reply
->Function
= MPI2_FUNCTION_EVENT_NOTIFICATION
;
3156 event_reply
->Event
=
3157 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
);
3158 event_reply
->MsgLength
= sz
/4;
3159 event_reply
->EventDataLength
=
3160 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t
)/4);
3161 event_data
= (Mpi2EventDataSasDeviceStatusChange_t
*)
3162 event_reply
->EventData
;
3163 event_data
->ReasonCode
= MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
;
3164 event_data
->ASC
= 0x5D;
3165 event_data
->DevHandle
= cpu_to_le16(handle
);
3166 event_data
->SASAddress
= cpu_to_le64(sas_target_priv_data
->sas_address
);
3167 mpt2sas_ctl_add_to_event_log(ioc
, event_reply
);
3172 * _scsih_io_done - scsi request callback
3173 * @ioc: per adapter object
3174 * @smid: system request message index
3175 * @msix_index: MSIX table index supplied by the OS
3176 * @reply: reply message frame(lower 32bit addr)
3178 * Callback handler when using _scsih_qcmd.
3180 * Return 1 meaning mf should be freed from _base_interrupt
3181 * 0 means the mf is freed from this function.
3184 _scsih_io_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
3186 Mpi2SCSIIORequest_t
*mpi_request
;
3187 Mpi2SCSIIOReply_t
*mpi_reply
;
3188 struct scsi_cmnd
*scmd
;
3194 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
3197 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
3198 scmd
= _scsih_scsi_lookup_get(ioc
, smid
);
3202 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3204 if (mpi_reply
== NULL
) {
3205 scmd
->result
= DID_OK
<< 16;
3209 sas_device_priv_data
= scmd
->device
->hostdata
;
3210 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
||
3211 sas_device_priv_data
->sas_target
->deleted
) {
3212 scmd
->result
= DID_NO_CONNECT
<< 16;
3216 /* turning off TLR */
3217 if (!sas_device_priv_data
->tlr_snoop_check
) {
3218 sas_device_priv_data
->tlr_snoop_check
++;
3219 if (sas_device_priv_data
->flags
& MPT_DEVICE_TLR_ON
) {
3220 response_code
= (le32_to_cpu(mpi_reply
->ResponseInfo
)
3222 if (response_code
==
3223 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
)
3224 sas_device_priv_data
->flags
&=
3229 xfer_cnt
= le32_to_cpu(mpi_reply
->TransferCount
);
3230 scsi_set_resid(scmd
, scsi_bufflen(scmd
) - xfer_cnt
);
3231 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
);
3232 if (ioc_status
& MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE
)
3233 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
3236 ioc_status
&= MPI2_IOCSTATUS_MASK
;
3237 scsi_state
= mpi_reply
->SCSIState
;
3238 scsi_status
= mpi_reply
->SCSIStatus
;
3240 if (ioc_status
== MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
&& xfer_cnt
== 0 &&
3241 (scsi_status
== MPI2_SCSI_STATUS_BUSY
||
3242 scsi_status
== MPI2_SCSI_STATUS_RESERVATION_CONFLICT
||
3243 scsi_status
== MPI2_SCSI_STATUS_TASK_SET_FULL
)) {
3244 ioc_status
= MPI2_IOCSTATUS_SUCCESS
;
3247 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
3248 struct sense_info data
;
3249 const void *sense_data
= mpt2sas_base_get_sense_buffer(ioc
,
3251 u32 sz
= min_t(u32
, SCSI_SENSE_BUFFERSIZE
,
3252 le32_to_cpu(mpi_reply
->SenseCount
));
3253 memcpy(scmd
->sense_buffer
, sense_data
, sz
);
3254 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
3255 /* failure prediction threshold exceeded */
3256 if (data
.asc
== 0x5D)
3257 _scsih_smart_predicted_fault(ioc
,
3258 le16_to_cpu(mpi_reply
->DevHandle
));
3261 switch (ioc_status
) {
3262 case MPI2_IOCSTATUS_BUSY
:
3263 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES
:
3264 scmd
->result
= SAM_STAT_BUSY
;
3267 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
3268 scmd
->result
= DID_NO_CONNECT
<< 16;
3271 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
3272 if (sas_device_priv_data
->block
) {
3273 scmd
->result
= (DID_BUS_BUSY
<< 16);
3277 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
3278 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
3279 scmd
->result
= DID_RESET
<< 16;
3282 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
3283 if ((xfer_cnt
== 0) || (scmd
->underflow
> xfer_cnt
))
3284 scmd
->result
= DID_SOFT_ERROR
<< 16;
3286 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
3289 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
3290 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
3292 if ((scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
))
3295 if (xfer_cnt
< scmd
->underflow
) {
3296 if (scsi_status
== SAM_STAT_BUSY
)
3297 scmd
->result
= SAM_STAT_BUSY
;
3299 scmd
->result
= DID_SOFT_ERROR
<< 16;
3300 } else if (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
3301 MPI2_SCSI_STATE_NO_SCSI_STATUS
))
3302 scmd
->result
= DID_SOFT_ERROR
<< 16;
3303 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
3304 scmd
->result
= DID_RESET
<< 16;
3305 else if (!xfer_cnt
&& scmd
->cmnd
[0] == REPORT_LUNS
) {
3306 mpi_reply
->SCSIState
= MPI2_SCSI_STATE_AUTOSENSE_VALID
;
3307 mpi_reply
->SCSIStatus
= SAM_STAT_CHECK_CONDITION
;
3308 scmd
->result
= (DRIVER_SENSE
<< 24) |
3309 SAM_STAT_CHECK_CONDITION
;
3310 scmd
->sense_buffer
[0] = 0x70;
3311 scmd
->sense_buffer
[2] = ILLEGAL_REQUEST
;
3312 scmd
->sense_buffer
[12] = 0x20;
3313 scmd
->sense_buffer
[13] = 0;
3317 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
3318 scsi_set_resid(scmd
, 0);
3319 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
3320 case MPI2_IOCSTATUS_SUCCESS
:
3321 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
3322 if (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
3323 MPI2_SCSI_STATE_NO_SCSI_STATUS
))
3324 scmd
->result
= DID_SOFT_ERROR
<< 16;
3325 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
3326 scmd
->result
= DID_RESET
<< 16;
3329 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
3330 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
3331 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
3332 _scsih_eedp_error_handling(scmd
, ioc_status
);
3334 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
3335 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
3336 case MPI2_IOCSTATUS_INVALID_SGL
:
3337 case MPI2_IOCSTATUS_INTERNAL_ERROR
:
3338 case MPI2_IOCSTATUS_INVALID_FIELD
:
3339 case MPI2_IOCSTATUS_INVALID_STATE
:
3340 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
3341 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
3343 scmd
->result
= DID_SOFT_ERROR
<< 16;
3348 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3349 if (scmd
->result
&& (ioc
->logging_level
& MPT_DEBUG_REPLY
))
3350 _scsih_scsi_ioc_info(ioc
, scmd
, mpi_reply
, smid
);
3354 scsi_dma_unmap(scmd
);
3355 scmd
->scsi_done(scmd
);
3360 * _scsih_sas_host_refresh - refreshing sas host object contents
3361 * @ioc: per adapter object
3362 * @update: update link information
3365 * During port enable, fw will send topology events for every device. Its
3366 * possible that the handles may change from the previous setting, so this
3367 * code keeping handles updating if changed.
3372 _scsih_sas_host_refresh(struct MPT2SAS_ADAPTER
*ioc
, u8 update
)
3377 Mpi2ConfigReply_t mpi_reply
;
3378 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
3380 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
3381 "updating handles for sas_host(0x%016llx)\n",
3382 ioc
->name
, (unsigned long long)ioc
->sas_hba
.sas_address
));
3384 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
3385 * sizeof(Mpi2SasIOUnit0PhyData_t
));
3386 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
3387 if (!sas_iounit_pg0
) {
3388 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3389 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3392 if (!(mpt2sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
3393 sas_iounit_pg0
, sz
))) {
3394 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
3395 MPI2_IOCSTATUS_MASK
;
3396 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
3398 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
3399 ioc
->sas_hba
.phy
[i
].handle
=
3400 le16_to_cpu(sas_iounit_pg0
->PhyData
[i
].
3401 ControllerDevHandle
);
3403 mpt2sas_transport_update_links(
3405 ioc
->sas_hba
.phy
[i
].handle
,
3406 le16_to_cpu(sas_iounit_pg0
->PhyData
[i
].
3407 AttachedDevHandle
), i
,
3408 sas_iounit_pg0
->PhyData
[i
].
3409 NegotiatedLinkRate
>> 4);
3414 kfree(sas_iounit_pg0
);
3418 * _scsih_sas_host_add - create sas host object
3419 * @ioc: per adapter object
3421 * Creating host side data object, stored in ioc->sas_hba
3426 _scsih_sas_host_add(struct MPT2SAS_ADAPTER
*ioc
)
3429 Mpi2ConfigReply_t mpi_reply
;
3430 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
3431 Mpi2SasIOUnitPage1_t
*sas_iounit_pg1
= NULL
;
3432 Mpi2SasPhyPage0_t phy_pg0
;
3433 Mpi2SasDevicePage0_t sas_device_pg0
;
3434 Mpi2SasEnclosurePage0_t enclosure_pg0
;
3437 u16 device_missing_delay
;
3439 mpt2sas_config_get_number_hba_phys(ioc
, &ioc
->sas_hba
.num_phys
);
3440 if (!ioc
->sas_hba
.num_phys
) {
3441 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3442 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3446 /* sas_iounit page 0 */
3447 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
3448 sizeof(Mpi2SasIOUnit0PhyData_t
));
3449 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
3450 if (!sas_iounit_pg0
) {
3451 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3452 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3455 if ((mpt2sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
3456 sas_iounit_pg0
, sz
))) {
3457 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3458 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3461 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
3462 MPI2_IOCSTATUS_MASK
;
3463 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
3464 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3465 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3469 /* sas_iounit page 1 */
3470 sz
= offsetof(Mpi2SasIOUnitPage1_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
3471 sizeof(Mpi2SasIOUnit1PhyData_t
));
3472 sas_iounit_pg1
= kzalloc(sz
, GFP_KERNEL
);
3473 if (!sas_iounit_pg1
) {
3474 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3475 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3478 if ((mpt2sas_config_get_sas_iounit_pg1(ioc
, &mpi_reply
,
3479 sas_iounit_pg1
, sz
))) {
3480 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3481 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3484 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
3485 MPI2_IOCSTATUS_MASK
;
3486 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
3487 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3488 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3492 ioc
->io_missing_delay
=
3493 le16_to_cpu(sas_iounit_pg1
->IODeviceMissingDelay
);
3494 device_missing_delay
=
3495 le16_to_cpu(sas_iounit_pg1
->ReportDeviceMissingDelay
);
3496 if (device_missing_delay
& MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16
)
3497 ioc
->device_missing_delay
= (device_missing_delay
&
3498 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
) * 16;
3500 ioc
->device_missing_delay
= device_missing_delay
&
3501 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
;
3503 ioc
->sas_hba
.parent_dev
= &ioc
->shost
->shost_gendev
;
3504 ioc
->sas_hba
.phy
= kcalloc(ioc
->sas_hba
.num_phys
,
3505 sizeof(struct _sas_phy
), GFP_KERNEL
);
3506 if (!ioc
->sas_hba
.phy
) {
3507 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3508 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3511 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
3512 if ((mpt2sas_config_get_phy_pg0(ioc
, &mpi_reply
, &phy_pg0
,
3514 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3515 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3518 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
3519 MPI2_IOCSTATUS_MASK
;
3520 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
3521 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3522 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3525 ioc
->sas_hba
.phy
[i
].handle
=
3526 le16_to_cpu(sas_iounit_pg0
->PhyData
[i
].ControllerDevHandle
);
3527 ioc
->sas_hba
.phy
[i
].phy_id
= i
;
3528 mpt2sas_transport_add_host_phy(ioc
, &ioc
->sas_hba
.phy
[i
],
3529 phy_pg0
, ioc
->sas_hba
.parent_dev
);
3531 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
3532 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, ioc
->sas_hba
.phy
[0].handle
))) {
3533 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3534 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3537 ioc
->sas_hba
.handle
= le16_to_cpu(sas_device_pg0
.DevHandle
);
3538 ioc
->sas_hba
.enclosure_handle
=
3539 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
3540 ioc
->sas_hba
.sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
3541 printk(MPT2SAS_INFO_FMT
"host_add: handle(0x%04x), "
3542 "sas_addr(0x%016llx), phys(%d)\n", ioc
->name
, ioc
->sas_hba
.handle
,
3543 (unsigned long long) ioc
->sas_hba
.sas_address
,
3544 ioc
->sas_hba
.num_phys
) ;
3546 if (ioc
->sas_hba
.enclosure_handle
) {
3547 if (!(mpt2sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
3549 MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
3550 ioc
->sas_hba
.enclosure_handle
))) {
3551 ioc
->sas_hba
.enclosure_logical_id
=
3552 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
3557 kfree(sas_iounit_pg1
);
3558 kfree(sas_iounit_pg0
);
3562 * _scsih_expander_add - creating expander object
3563 * @ioc: per adapter object
3564 * @handle: expander handle
3566 * Creating expander object, stored in ioc->sas_expander_list.
3568 * Return 0 for success, else error.
3571 _scsih_expander_add(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
3573 struct _sas_node
*sas_expander
;
3574 Mpi2ConfigReply_t mpi_reply
;
3575 Mpi2ExpanderPage0_t expander_pg0
;
3576 Mpi2ExpanderPage1_t expander_pg1
;
3577 Mpi2SasEnclosurePage0_t enclosure_pg0
;
3582 unsigned long flags
;
3583 struct _sas_port
*mpt2sas_port
= NULL
;
3589 if (ioc
->shost_recovery
)
3592 if ((mpt2sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
3593 MPI2_SAS_EXPAND_PGAD_FORM_HNDL
, handle
))) {
3594 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3595 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3599 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
3600 MPI2_IOCSTATUS_MASK
;
3601 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
3602 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3603 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3607 /* handle out of order topology events */
3608 parent_handle
= le16_to_cpu(expander_pg0
.ParentDevHandle
);
3609 if (parent_handle
>= ioc
->sas_hba
.num_phys
) {
3610 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
3611 sas_expander
= mpt2sas_scsih_expander_find_by_handle(ioc
,
3613 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
3614 if (!sas_expander
) {
3615 rc
= _scsih_expander_add(ioc
, parent_handle
);
3621 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
3622 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
3623 sas_expander
= mpt2sas_scsih_expander_find_by_sas_address(ioc
,
3625 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
3630 sas_expander
= kzalloc(sizeof(struct _sas_node
),
3632 if (!sas_expander
) {
3633 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3634 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3638 sas_expander
->handle
= handle
;
3639 sas_expander
->num_phys
= expander_pg0
.NumPhys
;
3640 sas_expander
->parent_handle
= parent_handle
;
3641 sas_expander
->enclosure_handle
=
3642 le16_to_cpu(expander_pg0
.EnclosureHandle
);
3643 sas_expander
->sas_address
= sas_address
;
3645 printk(MPT2SAS_INFO_FMT
"expander_add: handle(0x%04x),"
3646 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc
->name
,
3647 handle
, sas_expander
->parent_handle
, (unsigned long long)
3648 sas_expander
->sas_address
, sas_expander
->num_phys
);
3650 if (!sas_expander
->num_phys
)
3652 sas_expander
->phy
= kcalloc(sas_expander
->num_phys
,
3653 sizeof(struct _sas_phy
), GFP_KERNEL
);
3654 if (!sas_expander
->phy
) {
3655 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3656 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3661 INIT_LIST_HEAD(&sas_expander
->sas_port_list
);
3662 mpt2sas_port
= mpt2sas_transport_port_add(ioc
, handle
,
3663 sas_expander
->parent_handle
);
3664 if (!mpt2sas_port
) {
3665 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3666 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3670 sas_expander
->parent_dev
= &mpt2sas_port
->rphy
->dev
;
3672 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++) {
3673 if ((mpt2sas_config_get_expander_pg1(ioc
, &mpi_reply
,
3674 &expander_pg1
, i
, handle
))) {
3675 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3676 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3680 sas_expander
->phy
[i
].handle
= handle
;
3681 sas_expander
->phy
[i
].phy_id
= i
;
3683 if ((mpt2sas_transport_add_expander_phy(ioc
,
3684 &sas_expander
->phy
[i
], expander_pg1
,
3685 sas_expander
->parent_dev
))) {
3686 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3687 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3693 if (sas_expander
->enclosure_handle
) {
3694 if (!(mpt2sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
3695 &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
3696 sas_expander
->enclosure_handle
))) {
3697 sas_expander
->enclosure_logical_id
=
3698 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
3702 _scsih_expander_node_add(ioc
, sas_expander
);
3708 mpt2sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
3709 sas_expander
->parent_handle
);
3710 kfree(sas_expander
);
3715 * _scsih_expander_remove - removing expander object
3716 * @ioc: per adapter object
3717 * @handle: expander handle
3722 _scsih_expander_remove(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
3724 struct _sas_node
*sas_expander
;
3725 unsigned long flags
;
3727 if (ioc
->shost_recovery
)
3730 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
3731 sas_expander
= mpt2sas_scsih_expander_find_by_handle(ioc
, handle
);
3732 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
3733 _scsih_expander_node_remove(ioc
, sas_expander
);
3737 * _scsih_add_device - creating sas device object
3738 * @ioc: per adapter object
3739 * @handle: sas device handle
3740 * @phy_num: phy number end device attached to
3741 * @is_pd: is this hidden raid component
3743 * Creating end device object, stored in ioc->sas_device_list.
3745 * Returns 0 for success, non-zero for failure.
3748 _scsih_add_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
, u8 phy_num
, u8 is_pd
)
3750 Mpi2ConfigReply_t mpi_reply
;
3751 Mpi2SasDevicePage0_t sas_device_pg0
;
3752 Mpi2SasEnclosurePage0_t enclosure_pg0
;
3753 struct _sas_device
*sas_device
;
3757 unsigned long flags
;
3759 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
3760 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
3761 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3762 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3766 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
3767 MPI2_IOCSTATUS_MASK
;
3768 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
3769 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3770 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3774 /* check if device is present */
3775 if (!(le16_to_cpu(sas_device_pg0
.Flags
) &
3776 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT
)) {
3777 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3778 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3779 printk(MPT2SAS_ERR_FMT
"Flags = 0x%04x\n",
3780 ioc
->name
, le16_to_cpu(sas_device_pg0
.Flags
));
3784 /* check if there were any issus with discovery */
3785 if (sas_device_pg0
.AccessStatus
==
3786 MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED
) {
3787 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3788 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3789 printk(MPT2SAS_ERR_FMT
"AccessStatus = 0x%02x\n",
3790 ioc
->name
, sas_device_pg0
.AccessStatus
);
3794 /* check if this is end device */
3795 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
3796 if (!(_scsih_is_end_device(device_info
))) {
3797 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3798 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3802 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
3804 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
3805 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
3807 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3810 _scsih_ublock_io_device(ioc
, handle
);
3814 sas_device
= kzalloc(sizeof(struct _sas_device
),
3817 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3818 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3822 sas_device
->handle
= handle
;
3823 sas_device
->parent_handle
=
3824 le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
3825 sas_device
->enclosure_handle
=
3826 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
3828 le16_to_cpu(sas_device_pg0
.Slot
);
3829 sas_device
->device_info
= device_info
;
3830 sas_device
->sas_address
= sas_address
;
3831 sas_device
->hidden_raid_component
= is_pd
;
3833 /* get enclosure_logical_id */
3834 if (sas_device
->enclosure_handle
&& !(mpt2sas_config_get_enclosure_pg0(
3835 ioc
, &mpi_reply
, &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
3836 sas_device
->enclosure_handle
)))
3837 sas_device
->enclosure_logical_id
=
3838 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
3840 /* get device name */
3841 sas_device
->device_name
= le64_to_cpu(sas_device_pg0
.DeviceName
);
3843 if (ioc
->wait_for_port_enable_to_complete
)
3844 _scsih_sas_device_init_add(ioc
, sas_device
);
3846 _scsih_sas_device_add(ioc
, sas_device
);
3852 * _scsih_remove_device - removing sas device object
3853 * @ioc: per adapter object
3854 * @handle: sas device handle
3859 _scsih_remove_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
3861 struct MPT2SAS_TARGET
*sas_target_priv_data
;
3862 struct _sas_device
*sas_device
;
3863 unsigned long flags
;
3864 Mpi2SasIoUnitControlReply_t mpi_reply
;
3865 Mpi2SasIoUnitControlRequest_t mpi_request
;
3868 /* lookup sas_device */
3869 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
3870 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
3872 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3876 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: enter: handle"
3877 "(0x%04x)\n", ioc
->name
, __func__
, handle
));
3879 if (sas_device
->starget
&& sas_device
->starget
->hostdata
) {
3880 sas_target_priv_data
= sas_device
->starget
->hostdata
;
3881 sas_target_priv_data
->deleted
= 1;
3883 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3885 if (ioc
->remove_host
)
3888 if ((sas_device
->state
& MPTSAS_STATE_TR_COMPLETE
)) {
3889 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"\tskip "
3890 "target_reset handle(0x%04x)\n", ioc
->name
, handle
));
3894 /* Target Reset to flush out all the outstanding IO */
3895 device_handle
= (sas_device
->hidden_raid_component
) ?
3896 sas_device
->volume_handle
: handle
;
3897 if (device_handle
) {
3898 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"issue target reset: "
3899 "handle(0x%04x)\n", ioc
->name
, device_handle
));
3900 mutex_lock(&ioc
->tm_cmds
.mutex
);
3901 mpt2sas_scsih_issue_tm(ioc
, device_handle
, 0,
3902 MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
, 0, 10);
3903 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
3904 mutex_unlock(&ioc
->tm_cmds
.mutex
);
3905 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"issue target reset "
3906 "done: handle(0x%04x)\n", ioc
->name
, device_handle
));
3907 if (ioc
->shost_recovery
)
3912 if ((sas_device
->state
& MPTSAS_STATE_CNTRL_COMPLETE
)) {
3913 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"\tskip "
3914 "sas_cntrl handle(0x%04x)\n", ioc
->name
, handle
));
3918 /* SAS_IO_UNIT_CNTR - send REMOVE_DEVICE */
3919 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"sas_iounit: handle"
3920 "(0x%04x)\n", ioc
->name
, handle
));
3921 memset(&mpi_request
, 0, sizeof(Mpi2SasIoUnitControlRequest_t
));
3922 mpi_request
.Function
= MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
;
3923 mpi_request
.Operation
= MPI2_SAS_OP_REMOVE_DEVICE
;
3924 mpi_request
.DevHandle
= handle
;
3925 mpi_request
.VF_ID
= 0; /* TODO */
3926 mpi_request
.VP_ID
= 0;
3927 if ((mpt2sas_base_sas_iounit_control(ioc
, &mpi_reply
,
3928 &mpi_request
)) != 0) {
3929 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3930 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3933 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"sas_iounit: ioc_status"
3934 "(0x%04x), loginfo(0x%08x)\n", ioc
->name
,
3935 le16_to_cpu(mpi_reply
.IOCStatus
),
3936 le32_to_cpu(mpi_reply
.IOCLogInfo
)));
3940 _scsih_ublock_io_device(ioc
, handle
);
3942 mpt2sas_transport_port_remove(ioc
, sas_device
->sas_address
,
3943 sas_device
->parent_handle
);
3945 printk(MPT2SAS_INFO_FMT
"removing handle(0x%04x), sas_addr"
3946 "(0x%016llx)\n", ioc
->name
, sas_device
->handle
,
3947 (unsigned long long) sas_device
->sas_address
);
3948 _scsih_sas_device_remove(ioc
, sas_device
);
3950 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: exit: handle"
3951 "(0x%04x)\n", ioc
->name
, __func__
, handle
));
3954 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3956 * _scsih_sas_topology_change_event_debug - debug for topology event
3957 * @ioc: per adapter object
3958 * @event_data: event data payload
3962 _scsih_sas_topology_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
3963 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
3969 char *status_str
= NULL
;
3972 switch (event_data
->ExpStatus
) {
3973 case MPI2_EVENT_SAS_TOPO_ES_ADDED
:
3976 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
:
3977 status_str
= "remove";
3979 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING
:
3980 status_str
= "responding";
3982 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
:
3983 status_str
= "remove delay";
3986 status_str
= "unknown status";
3989 printk(MPT2SAS_DEBUG_FMT
"sas topology change: (%s)\n",
3990 ioc
->name
, status_str
);
3991 printk(KERN_DEBUG
"\thandle(0x%04x), enclosure_handle(0x%04x) "
3992 "start_phy(%02d), count(%d)\n",
3993 le16_to_cpu(event_data
->ExpanderDevHandle
),
3994 le16_to_cpu(event_data
->EnclosureHandle
),
3995 event_data
->StartPhyNum
, event_data
->NumEntries
);
3996 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
3997 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
4000 phy_number
= event_data
->StartPhyNum
+ i
;
4001 reason_code
= event_data
->PHY
[i
].PhyStatus
&
4002 MPI2_EVENT_SAS_TOPO_RC_MASK
;
4003 switch (reason_code
) {
4004 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
4005 snprintf(link_rate
, 25, ": add, link(0x%02x)",
4006 (event_data
->PHY
[i
].LinkRate
>> 4));
4007 status_str
= link_rate
;
4009 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
4010 status_str
= ": remove";
4012 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
:
4013 status_str
= ": remove_delay";
4015 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
4016 snprintf(link_rate
, 25, ": link(0x%02x)",
4017 (event_data
->PHY
[i
].LinkRate
>> 4));
4018 status_str
= link_rate
;
4020 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE
:
4021 status_str
= ": responding";
4024 status_str
= ": unknown";
4027 printk(KERN_DEBUG
"\tphy(%02d), attached_handle(0x%04x)%s\n",
4028 phy_number
, handle
, status_str
);
4034 * _scsih_sas_topology_change_event - handle topology changes
4035 * @ioc: per adapter object
4036 * @fw_event: The fw_event_work object
4041 _scsih_sas_topology_change_event(struct MPT2SAS_ADAPTER
*ioc
,
4042 struct fw_event_work
*fw_event
)
4045 u16 parent_handle
, handle
;
4048 struct _sas_node
*sas_expander
;
4049 unsigned long flags
;
4051 Mpi2EventDataSasTopologyChangeList_t
*event_data
= fw_event
->event_data
;
4053 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4054 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
4055 _scsih_sas_topology_change_event_debug(ioc
, event_data
);
4058 if (!ioc
->sas_hba
.num_phys
)
4059 _scsih_sas_host_add(ioc
);
4061 _scsih_sas_host_refresh(ioc
, 0);
4063 if (fw_event
->ignore
) {
4064 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"ignoring expander "
4065 "event\n", ioc
->name
));
4069 parent_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
4071 /* handle expander add */
4072 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_ADDED
)
4073 if (_scsih_expander_add(ioc
, parent_handle
) != 0)
4076 /* handle siblings events */
4077 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
4078 if (fw_event
->ignore
) {
4079 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"ignoring "
4080 "expander event\n", ioc
->name
));
4083 if (ioc
->shost_recovery
)
4085 phy_number
= event_data
->StartPhyNum
+ i
;
4086 reason_code
= event_data
->PHY
[i
].PhyStatus
&
4087 MPI2_EVENT_SAS_TOPO_RC_MASK
;
4088 if ((event_data
->PHY
[i
].PhyStatus
&
4089 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT
) && (reason_code
!=
4090 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
))
4092 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
4095 link_rate_
= event_data
->PHY
[i
].LinkRate
>> 4;
4096 switch (reason_code
) {
4097 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
4098 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
4099 if (!parent_handle
) {
4100 if (phy_number
< ioc
->sas_hba
.num_phys
)
4101 mpt2sas_transport_update_links(
4103 ioc
->sas_hba
.phy
[phy_number
].handle
,
4104 handle
, phy_number
, link_rate_
);
4106 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
4108 mpt2sas_scsih_expander_find_by_handle(ioc
,
4110 spin_unlock_irqrestore(&ioc
->sas_node_lock
,
4113 if (phy_number
< sas_expander
->num_phys
)
4114 mpt2sas_transport_update_links(
4117 phy
[phy_number
].handle
,
4122 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
) {
4123 if (link_rate_
< MPI2_SAS_NEG_LINK_RATE_1_5
)
4125 _scsih_add_device(ioc
, handle
, phy_number
, 0);
4128 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
4129 _scsih_remove_device(ioc
, handle
);
4134 /* handle expander removal */
4135 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
)
4136 _scsih_expander_remove(ioc
, parent_handle
);
4140 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4142 * _scsih_sas_device_status_change_event_debug - debug for device event
4143 * @event_data: event data payload
4149 _scsih_sas_device_status_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
4150 Mpi2EventDataSasDeviceStatusChange_t
*event_data
)
4152 char *reason_str
= NULL
;
4154 switch (event_data
->ReasonCode
) {
4155 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
:
4156 reason_str
= "smart data";
4158 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED
:
4159 reason_str
= "unsupported device discovered";
4161 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
:
4162 reason_str
= "internal device reset";
4164 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL
:
4165 reason_str
= "internal task abort";
4167 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL
:
4168 reason_str
= "internal task abort set";
4170 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL
:
4171 reason_str
= "internal clear task set";
4173 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL
:
4174 reason_str
= "internal query task";
4176 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE
:
4177 reason_str
= "sata init failure";
4179 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
:
4180 reason_str
= "internal device reset complete";
4182 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL
:
4183 reason_str
= "internal task abort complete";
4185 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION
:
4186 reason_str
= "internal async notification";
4189 reason_str
= "unknown reason";
4192 printk(MPT2SAS_DEBUG_FMT
"device status change: (%s)\n"
4193 "\thandle(0x%04x), sas address(0x%016llx)", ioc
->name
,
4194 reason_str
, le16_to_cpu(event_data
->DevHandle
),
4195 (unsigned long long)le64_to_cpu(event_data
->SASAddress
));
4196 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
)
4197 printk(MPT2SAS_DEBUG_FMT
", ASC(0x%x), ASCQ(0x%x)\n", ioc
->name
,
4198 event_data
->ASC
, event_data
->ASCQ
);
4199 printk(KERN_INFO
"\n");
4204 * _scsih_sas_device_status_change_event - handle device status change
4205 * @ioc: per adapter object
4206 * @fw_event: The fw_event_work object
4212 _scsih_sas_device_status_change_event(struct MPT2SAS_ADAPTER
*ioc
,
4213 struct fw_event_work
*fw_event
)
4215 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4216 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
4217 _scsih_sas_device_status_change_event_debug(ioc
,
4218 fw_event
->event_data
);
4222 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4224 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure event
4225 * @ioc: per adapter object
4226 * @event_data: event data payload
4232 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
4233 Mpi2EventDataSasEnclDevStatusChange_t
*event_data
)
4235 char *reason_str
= NULL
;
4237 switch (event_data
->ReasonCode
) {
4238 case MPI2_EVENT_SAS_ENCL_RC_ADDED
:
4239 reason_str
= "enclosure add";
4241 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING
:
4242 reason_str
= "enclosure remove";
4245 reason_str
= "unknown reason";
4249 printk(MPT2SAS_DEBUG_FMT
"enclosure status change: (%s)\n"
4250 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
4251 " number slots(%d)\n", ioc
->name
, reason_str
,
4252 le16_to_cpu(event_data
->EnclosureHandle
),
4253 (unsigned long long)le64_to_cpu(event_data
->EnclosureLogicalID
),
4254 le16_to_cpu(event_data
->StartSlot
));
4259 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
4260 * @ioc: per adapter object
4261 * @fw_event: The fw_event_work object
4267 _scsih_sas_enclosure_dev_status_change_event(struct MPT2SAS_ADAPTER
*ioc
,
4268 struct fw_event_work
*fw_event
)
4270 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4271 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
4272 _scsih_sas_enclosure_dev_status_change_event_debug(ioc
,
4273 fw_event
->event_data
);
4278 * _scsih_sas_broadcast_primative_event - handle broadcast events
4279 * @ioc: per adapter object
4280 * @fw_event: The fw_event_work object
4286 _scsih_sas_broadcast_primative_event(struct MPT2SAS_ADAPTER
*ioc
,
4287 struct fw_event_work
*fw_event
)
4289 struct scsi_cmnd
*scmd
;
4292 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
4293 u32 termination_count
;
4295 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
4296 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4297 Mpi2EventDataSasBroadcastPrimitive_t
*event_data
= fw_event
->event_data
;
4299 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"broadcast primative: "
4300 "phy number(%d), width(%d)\n", ioc
->name
, event_data
->PhyNum
,
4301 event_data
->PortWidth
));
4302 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: enter\n", ioc
->name
,
4305 mutex_lock(&ioc
->tm_cmds
.mutex
);
4306 termination_count
= 0;
4308 mpi_reply
= ioc
->tm_cmds
.reply
;
4309 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
4310 scmd
= _scsih_scsi_lookup_get(ioc
, smid
);
4313 sas_device_priv_data
= scmd
->device
->hostdata
;
4314 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
)
4316 /* skip hidden raid components */
4317 if (sas_device_priv_data
->sas_target
->flags
&
4318 MPT_TARGET_FLAGS_RAID_COMPONENT
)
4321 if (sas_device_priv_data
->sas_target
->flags
&
4322 MPT_TARGET_FLAGS_VOLUME
)
4325 handle
= sas_device_priv_data
->sas_target
->handle
;
4326 lun
= sas_device_priv_data
->lun
;
4329 mpt2sas_scsih_issue_tm(ioc
, handle
, lun
,
4330 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK
, smid
, 30);
4331 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
4333 if ((mpi_reply
->IOCStatus
== MPI2_IOCSTATUS_SUCCESS
) &&
4334 (mpi_reply
->ResponseCode
==
4335 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
||
4336 mpi_reply
->ResponseCode
==
4337 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
))
4340 mpt2sas_scsih_issue_tm(ioc
, handle
, lun
,
4341 MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET
, 0, 30);
4342 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
4343 termination_count
+= le32_to_cpu(mpi_reply
->TerminationCount
);
4345 ioc
->broadcast_aen_busy
= 0;
4346 mutex_unlock(&ioc
->tm_cmds
.mutex
);
4348 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
4349 "%s - exit, query_count = %d termination_count = %d\n",
4350 ioc
->name
, __func__
, query_count
, termination_count
));
4354 * _scsih_sas_discovery_event - handle discovery events
4355 * @ioc: per adapter object
4356 * @fw_event: The fw_event_work object
4362 _scsih_sas_discovery_event(struct MPT2SAS_ADAPTER
*ioc
,
4363 struct fw_event_work
*fw_event
)
4365 Mpi2EventDataSasDiscovery_t
*event_data
= fw_event
->event_data
;
4367 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4368 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
) {
4369 printk(MPT2SAS_DEBUG_FMT
"discovery event: (%s)", ioc
->name
,
4370 (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
) ?
4372 if (event_data
->DiscoveryStatus
)
4373 printk("discovery_status(0x%08x)",
4374 le32_to_cpu(event_data
->DiscoveryStatus
));
4379 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
&&
4380 !ioc
->sas_hba
.num_phys
)
4381 _scsih_sas_host_add(ioc
);
4385 * _scsih_reprobe_lun - reprobing lun
4386 * @sdev: scsi device struct
4387 * @no_uld_attach: sdev->no_uld_attach flag setting
4391 _scsih_reprobe_lun(struct scsi_device
*sdev
, void *no_uld_attach
)
4395 sdev
->no_uld_attach
= no_uld_attach
? 1 : 0;
4396 sdev_printk(KERN_INFO
, sdev
, "%s raid component\n",
4397 sdev
->no_uld_attach
? "hidding" : "exposing");
4398 rc
= scsi_device_reprobe(sdev
);
4402 * _scsih_reprobe_target - reprobing target
4403 * @starget: scsi target struct
4404 * @no_uld_attach: sdev->no_uld_attach flag setting
4406 * Note: no_uld_attach flag determines whether the disk device is attached
4407 * to block layer. A value of `1` means to not attach.
4410 _scsih_reprobe_target(struct scsi_target
*starget
, int no_uld_attach
)
4412 struct MPT2SAS_TARGET
*sas_target_priv_data
= starget
->hostdata
;
4415 sas_target_priv_data
->flags
|= MPT_TARGET_FLAGS_RAID_COMPONENT
;
4417 sas_target_priv_data
->flags
&= ~MPT_TARGET_FLAGS_RAID_COMPONENT
;
4419 starget_for_each_device(starget
, no_uld_attach
? (void *)1 : NULL
,
4420 _scsih_reprobe_lun
);
4423 * _scsih_sas_volume_add - add new volume
4424 * @ioc: per adapter object
4425 * @element: IR config element data
4431 _scsih_sas_volume_add(struct MPT2SAS_ADAPTER
*ioc
,
4432 Mpi2EventIrConfigElement_t
*element
)
4434 struct _raid_device
*raid_device
;
4435 unsigned long flags
;
4437 u16 handle
= le16_to_cpu(element
->VolDevHandle
);
4440 mpt2sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
4442 printk(MPT2SAS_ERR_FMT
4443 "failure at %s:%d/%s()!\n", ioc
->name
,
4444 __FILE__
, __LINE__
, __func__
);
4448 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
4449 raid_device
= _scsih_raid_device_find_by_wwid(ioc
, wwid
);
4450 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
4455 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
4457 printk(MPT2SAS_ERR_FMT
4458 "failure at %s:%d/%s()!\n", ioc
->name
,
4459 __FILE__
, __LINE__
, __func__
);
4463 raid_device
->id
= ioc
->sas_id
++;
4464 raid_device
->channel
= RAID_CHANNEL
;
4465 raid_device
->handle
= handle
;
4466 raid_device
->wwid
= wwid
;
4467 _scsih_raid_device_add(ioc
, raid_device
);
4468 if (!ioc
->wait_for_port_enable_to_complete
) {
4469 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
4470 raid_device
->id
, 0);
4472 _scsih_raid_device_remove(ioc
, raid_device
);
4474 _scsih_determine_boot_device(ioc
, raid_device
, 1);
4478 * _scsih_sas_volume_delete - delete volume
4479 * @ioc: per adapter object
4480 * @element: IR config element data
4486 _scsih_sas_volume_delete(struct MPT2SAS_ADAPTER
*ioc
,
4487 Mpi2EventIrConfigElement_t
*element
)
4489 struct _raid_device
*raid_device
;
4490 u16 handle
= le16_to_cpu(element
->VolDevHandle
);
4491 unsigned long flags
;
4492 struct MPT2SAS_TARGET
*sas_target_priv_data
;
4494 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
4495 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
4496 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
4499 if (raid_device
->starget
) {
4500 sas_target_priv_data
= raid_device
->starget
->hostdata
;
4501 sas_target_priv_data
->deleted
= 1;
4502 scsi_remove_target(&raid_device
->starget
->dev
);
4504 _scsih_raid_device_remove(ioc
, raid_device
);
4508 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
4509 * @ioc: per adapter object
4510 * @element: IR config element data
4516 _scsih_sas_pd_expose(struct MPT2SAS_ADAPTER
*ioc
,
4517 Mpi2EventIrConfigElement_t
*element
)
4519 struct _sas_device
*sas_device
;
4520 unsigned long flags
;
4521 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
4523 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4524 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
4525 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4529 /* exposing raid component */
4530 sas_device
->volume_handle
= 0;
4531 sas_device
->volume_wwid
= 0;
4532 sas_device
->hidden_raid_component
= 0;
4533 _scsih_reprobe_target(sas_device
->starget
, 0);
4537 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
4538 * @ioc: per adapter object
4539 * @element: IR config element data
4545 _scsih_sas_pd_hide(struct MPT2SAS_ADAPTER
*ioc
,
4546 Mpi2EventIrConfigElement_t
*element
)
4548 struct _sas_device
*sas_device
;
4549 unsigned long flags
;
4550 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
4552 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4553 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
4554 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4558 /* hiding raid component */
4559 mpt2sas_config_get_volume_handle(ioc
, handle
,
4560 &sas_device
->volume_handle
);
4561 mpt2sas_config_get_volume_wwid(ioc
, sas_device
->volume_handle
,
4562 &sas_device
->volume_wwid
);
4563 sas_device
->hidden_raid_component
= 1;
4564 _scsih_reprobe_target(sas_device
->starget
, 1);
4568 * _scsih_sas_pd_delete - delete pd component
4569 * @ioc: per adapter object
4570 * @element: IR config element data
4576 _scsih_sas_pd_delete(struct MPT2SAS_ADAPTER
*ioc
,
4577 Mpi2EventIrConfigElement_t
*element
)
4579 struct _sas_device
*sas_device
;
4580 unsigned long flags
;
4581 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
4583 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4584 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
4585 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4588 _scsih_remove_device(ioc
, handle
);
4592 * _scsih_sas_pd_add - remove pd component
4593 * @ioc: per adapter object
4594 * @element: IR config element data
4600 _scsih_sas_pd_add(struct MPT2SAS_ADAPTER
*ioc
,
4601 Mpi2EventIrConfigElement_t
*element
)
4603 struct _sas_device
*sas_device
;
4604 unsigned long flags
;
4605 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
4606 Mpi2ConfigReply_t mpi_reply
;
4607 Mpi2SasDevicePage0_t sas_device_pg0
;
4610 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4611 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
4612 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4614 sas_device
->hidden_raid_component
= 1;
4618 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
4619 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
4620 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4621 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4625 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4626 MPI2_IOCSTATUS_MASK
;
4627 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4628 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4629 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4633 mpt2sas_transport_update_links(ioc
,
4634 le16_to_cpu(sas_device_pg0
.ParentDevHandle
),
4635 handle
, sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
4637 _scsih_add_device(ioc
, handle
, 0, 1);
4640 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4642 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
4643 * @ioc: per adapter object
4644 * @event_data: event data payload
4650 _scsih_sas_ir_config_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
4651 Mpi2EventDataIrConfigChangeList_t
*event_data
)
4653 Mpi2EventIrConfigElement_t
*element
;
4656 char *reason_str
= NULL
, *element_str
= NULL
;
4658 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
4660 printk(MPT2SAS_DEBUG_FMT
"raid config change: (%s), elements(%d)\n",
4661 ioc
->name
, (le32_to_cpu(event_data
->Flags
) &
4662 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ?
4663 "foreign" : "native", event_data
->NumElements
);
4664 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
4665 switch (element
->ReasonCode
) {
4666 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
4669 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
4670 reason_str
= "remove";
4672 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE
:
4673 reason_str
= "no change";
4675 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
4676 reason_str
= "hide";
4678 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
4679 reason_str
= "unhide";
4681 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
4682 reason_str
= "volume_created";
4684 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
4685 reason_str
= "volume_deleted";
4687 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
4688 reason_str
= "pd_created";
4690 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
4691 reason_str
= "pd_deleted";
4694 reason_str
= "unknown reason";
4697 element_type
= le16_to_cpu(element
->ElementFlags
) &
4698 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK
;
4699 switch (element_type
) {
4700 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT
:
4701 element_str
= "volume";
4703 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT
:
4704 element_str
= "phys disk";
4706 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT
:
4707 element_str
= "hot spare";
4710 element_str
= "unknown element";
4713 printk(KERN_DEBUG
"\t(%s:%s), vol handle(0x%04x), "
4714 "pd handle(0x%04x), pd num(0x%02x)\n", element_str
,
4715 reason_str
, le16_to_cpu(element
->VolDevHandle
),
4716 le16_to_cpu(element
->PhysDiskDevHandle
),
4717 element
->PhysDiskNum
);
4723 * _scsih_sas_ir_config_change_event - handle ir configuration change events
4724 * @ioc: per adapter object
4725 * @fw_event: The fw_event_work object
4731 _scsih_sas_ir_config_change_event(struct MPT2SAS_ADAPTER
*ioc
,
4732 struct fw_event_work
*fw_event
)
4734 Mpi2EventIrConfigElement_t
*element
;
4737 Mpi2EventDataIrConfigChangeList_t
*event_data
= fw_event
->event_data
;
4739 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4740 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
4741 _scsih_sas_ir_config_change_event_debug(ioc
, event_data
);
4744 foreign_config
= (le32_to_cpu(event_data
->Flags
) &
4745 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ? 1 : 0;
4747 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
4748 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
4750 switch (element
->ReasonCode
) {
4751 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
4752 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
4753 if (!foreign_config
)
4754 _scsih_sas_volume_add(ioc
, element
);
4756 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
4757 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
4758 if (!foreign_config
)
4759 _scsih_sas_volume_delete(ioc
, element
);
4761 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
4762 _scsih_sas_pd_hide(ioc
, element
);
4764 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
4765 _scsih_sas_pd_expose(ioc
, element
);
4767 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
4768 _scsih_sas_pd_add(ioc
, element
);
4770 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
4771 _scsih_sas_pd_delete(ioc
, element
);
4778 * _scsih_sas_ir_volume_event - IR volume event
4779 * @ioc: per adapter object
4780 * @fw_event: The fw_event_work object
4786 _scsih_sas_ir_volume_event(struct MPT2SAS_ADAPTER
*ioc
,
4787 struct fw_event_work
*fw_event
)
4790 unsigned long flags
;
4791 struct _raid_device
*raid_device
;
4795 struct MPT2SAS_TARGET
*sas_target_priv_data
;
4796 Mpi2EventDataIrVolume_t
*event_data
= fw_event
->event_data
;
4798 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED
)
4801 handle
= le16_to_cpu(event_data
->VolDevHandle
);
4802 state
= le32_to_cpu(event_data
->NewValue
);
4803 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: handle(0x%04x), "
4804 "old(0x%08x), new(0x%08x)\n", ioc
->name
, __func__
, handle
,
4805 le32_to_cpu(event_data
->PreviousValue
), state
));
4807 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
4808 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
4809 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
4812 case MPI2_RAID_VOL_STATE_MISSING
:
4813 case MPI2_RAID_VOL_STATE_FAILED
:
4816 if (raid_device
->starget
) {
4817 sas_target_priv_data
= raid_device
->starget
->hostdata
;
4818 sas_target_priv_data
->deleted
= 1;
4819 scsi_remove_target(&raid_device
->starget
->dev
);
4821 _scsih_raid_device_remove(ioc
, raid_device
);
4824 case MPI2_RAID_VOL_STATE_ONLINE
:
4825 case MPI2_RAID_VOL_STATE_DEGRADED
:
4826 case MPI2_RAID_VOL_STATE_OPTIMAL
:
4830 mpt2sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
4832 printk(MPT2SAS_ERR_FMT
4833 "failure at %s:%d/%s()!\n", ioc
->name
,
4834 __FILE__
, __LINE__
, __func__
);
4838 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
4840 printk(MPT2SAS_ERR_FMT
4841 "failure at %s:%d/%s()!\n", ioc
->name
,
4842 __FILE__
, __LINE__
, __func__
);
4846 raid_device
->id
= ioc
->sas_id
++;
4847 raid_device
->channel
= RAID_CHANNEL
;
4848 raid_device
->handle
= handle
;
4849 raid_device
->wwid
= wwid
;
4850 _scsih_raid_device_add(ioc
, raid_device
);
4851 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
4852 raid_device
->id
, 0);
4854 _scsih_raid_device_remove(ioc
, raid_device
);
4857 case MPI2_RAID_VOL_STATE_INITIALIZING
:
4864 * _scsih_sas_ir_physical_disk_event - PD event
4865 * @ioc: per adapter object
4866 * @fw_event: The fw_event_work object
4872 _scsih_sas_ir_physical_disk_event(struct MPT2SAS_ADAPTER
*ioc
,
4873 struct fw_event_work
*fw_event
)
4877 struct _sas_device
*sas_device
;
4878 unsigned long flags
;
4879 Mpi2ConfigReply_t mpi_reply
;
4880 Mpi2SasDevicePage0_t sas_device_pg0
;
4882 Mpi2EventDataIrPhysicalDisk_t
*event_data
= fw_event
->event_data
;
4884 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED
)
4887 handle
= le16_to_cpu(event_data
->PhysDiskDevHandle
);
4888 state
= le32_to_cpu(event_data
->NewValue
);
4890 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: handle(0x%04x), "
4891 "old(0x%08x), new(0x%08x)\n", ioc
->name
, __func__
, handle
,
4892 le32_to_cpu(event_data
->PreviousValue
), state
));
4894 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4895 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
4896 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4899 case MPI2_RAID_PD_STATE_ONLINE
:
4900 case MPI2_RAID_PD_STATE_DEGRADED
:
4901 case MPI2_RAID_PD_STATE_REBUILDING
:
4902 case MPI2_RAID_PD_STATE_OPTIMAL
:
4904 sas_device
->hidden_raid_component
= 1;
4908 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
4909 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
4911 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4912 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4916 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4917 MPI2_IOCSTATUS_MASK
;
4918 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4919 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4920 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4924 mpt2sas_transport_update_links(ioc
,
4925 le16_to_cpu(sas_device_pg0
.ParentDevHandle
),
4926 handle
, sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
4928 _scsih_add_device(ioc
, handle
, 0, 1);
4932 case MPI2_RAID_PD_STATE_OFFLINE
:
4933 case MPI2_RAID_PD_STATE_NOT_CONFIGURED
:
4934 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE
:
4935 case MPI2_RAID_PD_STATE_HOT_SPARE
:
4941 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4943 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
4944 * @ioc: per adapter object
4945 * @event_data: event data payload
4951 _scsih_sas_ir_operation_status_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
4952 Mpi2EventDataIrOperationStatus_t
*event_data
)
4954 char *reason_str
= NULL
;
4956 switch (event_data
->RAIDOperation
) {
4957 case MPI2_EVENT_IR_RAIDOP_RESYNC
:
4958 reason_str
= "resync";
4960 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION
:
4961 reason_str
= "online capacity expansion";
4963 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK
:
4964 reason_str
= "consistency check";
4967 reason_str
= "unknown reason";
4971 printk(MPT2SAS_INFO_FMT
"raid operational status: (%s)"
4972 "\thandle(0x%04x), percent complete(%d)\n",
4973 ioc
->name
, reason_str
,
4974 le16_to_cpu(event_data
->VolDevHandle
),
4975 event_data
->PercentComplete
);
4980 * _scsih_sas_ir_operation_status_event - handle RAID operation events
4981 * @ioc: per adapter object
4982 * @fw_event: The fw_event_work object
4988 _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER
*ioc
,
4989 struct fw_event_work
*fw_event
)
4991 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4992 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
4993 _scsih_sas_ir_operation_status_event_debug(ioc
,
4994 fw_event
->event_data
);
4999 * _scsih_task_set_full - handle task set full
5000 * @ioc: per adapter object
5001 * @fw_event: The fw_event_work object
5004 * Throttle back qdepth.
5007 _scsih_task_set_full(struct MPT2SAS_ADAPTER
*ioc
, struct fw_event_work
5010 unsigned long flags
;
5011 struct _sas_device
*sas_device
;
5012 static struct _raid_device
*raid_device
;
5013 struct scsi_device
*sdev
;
5019 Mpi2EventDataTaskSetFull_t
*event_data
= fw_event
->event_data
;
5021 current_depth
= le16_to_cpu(event_data
->CurrentDepth
);
5022 handle
= le16_to_cpu(event_data
->DevHandle
);
5023 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5024 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
5026 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5029 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5030 id
= sas_device
->id
;
5031 channel
= sas_device
->channel
;
5032 sas_address
= sas_device
->sas_address
;
5034 /* if hidden raid component, then change to volume characteristics */
5035 if (sas_device
->hidden_raid_component
&& sas_device
->volume_handle
) {
5036 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5037 raid_device
= _scsih_raid_device_find_by_handle(
5038 ioc
, sas_device
->volume_handle
);
5039 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5041 id
= raid_device
->id
;
5042 channel
= raid_device
->channel
;
5043 handle
= raid_device
->handle
;
5044 sas_address
= raid_device
->wwid
;
5048 if (ioc
->logging_level
& MPT_DEBUG_TASK_SET_FULL
)
5049 starget_printk(KERN_DEBUG
, sas_device
->starget
, "task set "
5050 "full: handle(0x%04x), sas_addr(0x%016llx), depth(%d)\n",
5051 handle
, (unsigned long long)sas_address
, current_depth
);
5053 shost_for_each_device(sdev
, ioc
->shost
) {
5054 if (sdev
->id
== id
&& sdev
->channel
== channel
) {
5055 if (current_depth
> sdev
->queue_depth
) {
5056 if (ioc
->logging_level
&
5057 MPT_DEBUG_TASK_SET_FULL
)
5058 sdev_printk(KERN_INFO
, sdev
, "strange "
5059 "observation, the queue depth is"
5060 " (%d) meanwhile fw queue depth "
5061 "is (%d)\n", sdev
->queue_depth
,
5065 depth
= scsi_track_queue_full(sdev
,
5068 sdev_printk(KERN_INFO
, sdev
, "Queue depth "
5069 "reduced to (%d)\n", depth
);
5071 sdev_printk(KERN_INFO
, sdev
, "Tagged Command "
5072 "Queueing is being disabled\n");
5073 else if (depth
== 0)
5074 if (ioc
->logging_level
&
5075 MPT_DEBUG_TASK_SET_FULL
)
5076 sdev_printk(KERN_INFO
, sdev
,
5077 "Queue depth not changed yet\n");
5083 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
5084 * @ioc: per adapter object
5085 * @sas_address: sas address
5086 * @slot: enclosure slot id
5087 * @handle: device handle
5089 * After host reset, find out whether devices are still responding.
5090 * Used in _scsi_remove_unresponsive_sas_devices.
5095 _scsih_mark_responding_sas_device(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
,
5096 u16 slot
, u16 handle
)
5098 struct MPT2SAS_TARGET
*sas_target_priv_data
;
5099 struct scsi_target
*starget
;
5100 struct _sas_device
*sas_device
;
5101 unsigned long flags
;
5103 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5104 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
) {
5105 if (sas_device
->sas_address
== sas_address
&&
5106 sas_device
->slot
== slot
&& sas_device
->starget
) {
5107 sas_device
->responding
= 1;
5108 sas_device
->state
= 0;
5109 starget
= sas_device
->starget
;
5110 sas_target_priv_data
= starget
->hostdata
;
5111 sas_target_priv_data
->tm_busy
= 0;
5112 starget_printk(KERN_INFO
, sas_device
->starget
,
5113 "handle(0x%04x), sas_addr(0x%016llx), enclosure "
5114 "logical id(0x%016llx), slot(%d)\n", handle
,
5115 (unsigned long long)sas_device
->sas_address
,
5116 (unsigned long long)
5117 sas_device
->enclosure_logical_id
,
5119 if (sas_device
->handle
== handle
)
5121 printk(KERN_INFO
"\thandle changed from(0x%04x)!!!\n",
5122 sas_device
->handle
);
5123 sas_device
->handle
= handle
;
5124 sas_target_priv_data
->handle
= handle
;
5129 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5133 * _scsih_search_responding_sas_devices -
5134 * @ioc: per adapter object
5136 * After host reset, find out whether devices are still responding.
5142 _scsih_search_responding_sas_devices(struct MPT2SAS_ADAPTER
*ioc
)
5144 Mpi2SasDevicePage0_t sas_device_pg0
;
5145 Mpi2ConfigReply_t mpi_reply
;
5152 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
, __func__
);
5154 if (list_empty(&ioc
->sas_device_list
))
5158 while (!(mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
5159 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
,
5161 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5162 MPI2_IOCSTATUS_MASK
;
5163 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
5165 handle
= le16_to_cpu(sas_device_pg0
.DevHandle
);
5166 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
5167 if (!(_scsih_is_end_device(device_info
)))
5169 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
5170 slot
= le16_to_cpu(sas_device_pg0
.Slot
);
5171 _scsih_mark_responding_sas_device(ioc
, sas_address
, slot
,
5177 * _scsih_mark_responding_raid_device - mark a raid_device as responding
5178 * @ioc: per adapter object
5179 * @wwid: world wide identifier for raid volume
5180 * @handle: device handle
5182 * After host reset, find out whether devices are still responding.
5183 * Used in _scsi_remove_unresponsive_raid_devices.
5188 _scsih_mark_responding_raid_device(struct MPT2SAS_ADAPTER
*ioc
, u64 wwid
,
5191 struct MPT2SAS_TARGET
*sas_target_priv_data
;
5192 struct scsi_target
*starget
;
5193 struct _raid_device
*raid_device
;
5194 unsigned long flags
;
5196 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5197 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
5198 if (raid_device
->wwid
== wwid
&& raid_device
->starget
) {
5199 raid_device
->responding
= 1;
5200 starget_printk(KERN_INFO
, raid_device
->starget
,
5201 "handle(0x%04x), wwid(0x%016llx)\n", handle
,
5202 (unsigned long long)raid_device
->wwid
);
5203 if (raid_device
->handle
== handle
)
5205 printk(KERN_INFO
"\thandle changed from(0x%04x)!!!\n",
5206 raid_device
->handle
);
5207 raid_device
->handle
= handle
;
5208 starget
= raid_device
->starget
;
5209 sas_target_priv_data
= starget
->hostdata
;
5210 sas_target_priv_data
->handle
= handle
;
5215 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5219 * _scsih_search_responding_raid_devices -
5220 * @ioc: per adapter object
5222 * After host reset, find out whether devices are still responding.
5228 _scsih_search_responding_raid_devices(struct MPT2SAS_ADAPTER
*ioc
)
5230 Mpi2RaidVolPage1_t volume_pg1
;
5231 Mpi2ConfigReply_t mpi_reply
;
5235 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
, __func__
);
5237 if (list_empty(&ioc
->raid_device_list
))
5241 while (!(mpt2sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
5242 &volume_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
5243 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5244 MPI2_IOCSTATUS_MASK
;
5245 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
5247 handle
= le16_to_cpu(volume_pg1
.DevHandle
);
5248 _scsih_mark_responding_raid_device(ioc
,
5249 le64_to_cpu(volume_pg1
.WWID
), handle
);
5254 * _scsih_mark_responding_expander - mark a expander as responding
5255 * @ioc: per adapter object
5256 * @sas_address: sas address
5259 * After host reset, find out whether devices are still responding.
5260 * Used in _scsi_remove_unresponsive_expanders.
5265 _scsih_mark_responding_expander(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
,
5268 struct _sas_node
*sas_expander
;
5269 unsigned long flags
;
5271 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5272 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
5273 if (sas_expander
->sas_address
== sas_address
) {
5274 sas_expander
->responding
= 1;
5275 if (sas_expander
->handle
!= handle
) {
5276 printk(KERN_INFO
"old handle(0x%04x)\n",
5277 sas_expander
->handle
);
5278 sas_expander
->handle
= handle
;
5284 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5288 * _scsih_search_responding_expanders -
5289 * @ioc: per adapter object
5291 * After host reset, find out whether devices are still responding.
5297 _scsih_search_responding_expanders(struct MPT2SAS_ADAPTER
*ioc
)
5299 Mpi2ExpanderPage0_t expander_pg0
;
5300 Mpi2ConfigReply_t mpi_reply
;
5305 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
, __func__
);
5307 if (list_empty(&ioc
->sas_expander_list
))
5311 while (!(mpt2sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
5312 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL
, handle
))) {
5314 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5315 MPI2_IOCSTATUS_MASK
;
5316 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
5319 handle
= le16_to_cpu(expander_pg0
.DevHandle
);
5320 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
5321 printk(KERN_INFO
"\texpander present: handle(0x%04x), "
5322 "sas_addr(0x%016llx)\n", handle
,
5323 (unsigned long long)sas_address
);
5324 _scsih_mark_responding_expander(ioc
, sas_address
, handle
);
5330 * _scsih_remove_unresponding_devices - removing unresponding devices
5331 * @ioc: per adapter object
5336 _scsih_remove_unresponding_devices(struct MPT2SAS_ADAPTER
*ioc
)
5338 struct _sas_device
*sas_device
, *sas_device_next
;
5339 struct _sas_node
*sas_expander
;
5340 struct _raid_device
*raid_device
, *raid_device_next
;
5343 list_for_each_entry_safe(sas_device
, sas_device_next
,
5344 &ioc
->sas_device_list
, list
) {
5345 if (sas_device
->responding
) {
5346 sas_device
->responding
= 0;
5349 if (sas_device
->starget
)
5350 starget_printk(KERN_INFO
, sas_device
->starget
,
5351 "removing: handle(0x%04x), sas_addr(0x%016llx), "
5352 "enclosure logical id(0x%016llx), slot(%d)\n",
5354 (unsigned long long)sas_device
->sas_address
,
5355 (unsigned long long)
5356 sas_device
->enclosure_logical_id
,
5358 _scsih_remove_device(ioc
, sas_device
->handle
);
5361 list_for_each_entry_safe(raid_device
, raid_device_next
,
5362 &ioc
->raid_device_list
, list
) {
5363 if (raid_device
->responding
) {
5364 raid_device
->responding
= 0;
5367 if (raid_device
->starget
) {
5368 starget_printk(KERN_INFO
, raid_device
->starget
,
5369 "removing: handle(0x%04x), wwid(0x%016llx)\n",
5370 raid_device
->handle
,
5371 (unsigned long long)raid_device
->wwid
);
5372 scsi_remove_target(&raid_device
->starget
->dev
);
5374 _scsih_raid_device_remove(ioc
, raid_device
);
5377 retry_expander_search
:
5378 sas_expander
= NULL
;
5379 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
5380 if (sas_expander
->responding
) {
5381 sas_expander
->responding
= 0;
5384 _scsih_expander_remove(ioc
, sas_expander
->handle
);
5385 goto retry_expander_search
;
5390 * mpt2sas_scsih_reset_handler - reset callback handler (for scsih)
5391 * @ioc: per adapter object
5392 * @reset_phase: phase
5394 * The handler for doing any required cleanup or initialization.
5396 * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
5397 * MPT2_IOC_DONE_RESET
5402 mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER
*ioc
, int reset_phase
)
5404 switch (reset_phase
) {
5405 case MPT2_IOC_PRE_RESET
:
5406 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: "
5407 "MPT2_IOC_PRE_RESET\n", ioc
->name
, __func__
));
5408 _scsih_fw_event_off(ioc
);
5410 case MPT2_IOC_AFTER_RESET
:
5411 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: "
5412 "MPT2_IOC_AFTER_RESET\n", ioc
->name
, __func__
));
5413 if (ioc
->tm_cmds
.status
& MPT2_CMD_PENDING
) {
5414 ioc
->tm_cmds
.status
|= MPT2_CMD_RESET
;
5415 mpt2sas_base_free_smid(ioc
, ioc
->tm_cmds
.smid
);
5416 complete(&ioc
->tm_cmds
.done
);
5418 _scsih_fw_event_on(ioc
);
5419 _scsih_flush_running_cmds(ioc
);
5421 case MPT2_IOC_DONE_RESET
:
5422 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: "
5423 "MPT2_IOC_DONE_RESET\n", ioc
->name
, __func__
));
5424 _scsih_sas_host_refresh(ioc
, 0);
5425 _scsih_search_responding_sas_devices(ioc
);
5426 _scsih_search_responding_raid_devices(ioc
);
5427 _scsih_search_responding_expanders(ioc
);
5429 case MPT2_IOC_RUNNING
:
5430 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: "
5431 "MPT2_IOC_RUNNING\n", ioc
->name
, __func__
));
5432 _scsih_remove_unresponding_devices(ioc
);
5438 * _firmware_event_work - delayed task for processing firmware events
5439 * @ioc: per adapter object
5440 * @work: equal to the fw_event_work object
5446 _firmware_event_work(struct work_struct
*work
)
5448 struct fw_event_work
*fw_event
= container_of(work
,
5449 struct fw_event_work
, work
);
5450 unsigned long flags
;
5451 struct MPT2SAS_ADAPTER
*ioc
= fw_event
->ioc
;
5453 /* the queue is being flushed so ignore this event */
5454 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
5455 if (ioc
->fw_events_off
|| ioc
->remove_host
) {
5456 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
5457 _scsih_fw_event_free(ioc
, fw_event
);
5460 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
5462 if (ioc
->shost_recovery
) {
5463 _scsih_fw_event_requeue(ioc
, fw_event
, 1000);
5467 switch (fw_event
->event
) {
5468 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
5469 _scsih_sas_topology_change_event(ioc
, fw_event
);
5471 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
5472 _scsih_sas_device_status_change_event(ioc
,
5475 case MPI2_EVENT_SAS_DISCOVERY
:
5476 _scsih_sas_discovery_event(ioc
,
5479 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
5480 _scsih_sas_broadcast_primative_event(ioc
,
5483 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
5484 _scsih_sas_enclosure_dev_status_change_event(ioc
,
5487 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
5488 _scsih_sas_ir_config_change_event(ioc
, fw_event
);
5490 case MPI2_EVENT_IR_VOLUME
:
5491 _scsih_sas_ir_volume_event(ioc
, fw_event
);
5493 case MPI2_EVENT_IR_PHYSICAL_DISK
:
5494 _scsih_sas_ir_physical_disk_event(ioc
, fw_event
);
5496 case MPI2_EVENT_IR_OPERATION_STATUS
:
5497 _scsih_sas_ir_operation_status_event(ioc
, fw_event
);
5499 case MPI2_EVENT_TASK_SET_FULL
:
5500 _scsih_task_set_full(ioc
, fw_event
);
5503 _scsih_fw_event_free(ioc
, fw_event
);
5507 * mpt2sas_scsih_event_callback - firmware event handler (called at ISR time)
5508 * @ioc: per adapter object
5509 * @msix_index: MSIX table index supplied by the OS
5510 * @reply: reply message frame(lower 32bit addr)
5511 * Context: interrupt.
5513 * This function merely adds a new work task into ioc->firmware_event_thread.
5514 * The tasks are worked from _firmware_event_work in user context.
5516 * Return 1 meaning mf should be freed from _base_interrupt
5517 * 0 means the mf is freed from this function.
5520 mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER
*ioc
, u8 msix_index
,
5523 struct fw_event_work
*fw_event
;
5524 Mpi2EventNotificationReply_t
*mpi_reply
;
5525 unsigned long flags
;
5528 /* events turned off due to host reset or driver unloading */
5529 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
5530 if (ioc
->fw_events_off
|| ioc
->remove_host
) {
5531 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
5534 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
5536 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
5537 event
= le16_to_cpu(mpi_reply
->Event
);
5541 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
5543 Mpi2EventDataSasBroadcastPrimitive_t
*baen_data
=
5544 (Mpi2EventDataSasBroadcastPrimitive_t
*)
5545 mpi_reply
->EventData
;
5547 if (baen_data
->Primitive
!=
5548 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT
||
5549 ioc
->broadcast_aen_busy
)
5551 ioc
->broadcast_aen_busy
= 1;
5555 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
5556 _scsih_check_topo_delete_events(ioc
,
5557 (Mpi2EventDataSasTopologyChangeList_t
*)
5558 mpi_reply
->EventData
);
5561 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
5562 case MPI2_EVENT_IR_OPERATION_STATUS
:
5563 case MPI2_EVENT_SAS_DISCOVERY
:
5564 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
5565 case MPI2_EVENT_IR_VOLUME
:
5566 case MPI2_EVENT_IR_PHYSICAL_DISK
:
5567 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
5568 case MPI2_EVENT_TASK_SET_FULL
:
5571 default: /* ignore the rest */
5575 fw_event
= kzalloc(sizeof(struct fw_event_work
), GFP_ATOMIC
);
5577 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5578 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5581 fw_event
->event_data
=
5582 kzalloc(mpi_reply
->EventDataLength
*4, GFP_ATOMIC
);
5583 if (!fw_event
->event_data
) {
5584 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5585 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5590 memcpy(fw_event
->event_data
, mpi_reply
->EventData
,
5591 mpi_reply
->EventDataLength
*4);
5592 fw_event
->ioc
= ioc
;
5593 fw_event
->VF_ID
= mpi_reply
->VF_ID
;
5594 fw_event
->VP_ID
= mpi_reply
->VP_ID
;
5595 fw_event
->event
= event
;
5596 _scsih_fw_event_add(ioc
, fw_event
);
5600 /* shost template */
5601 static struct scsi_host_template scsih_driver_template
= {
5602 .module
= THIS_MODULE
,
5603 .name
= "Fusion MPT SAS Host",
5604 .proc_name
= MPT2SAS_DRIVER_NAME
,
5605 .queuecommand
= _scsih_qcmd
,
5606 .target_alloc
= _scsih_target_alloc
,
5607 .slave_alloc
= _scsih_slave_alloc
,
5608 .slave_configure
= _scsih_slave_configure
,
5609 .target_destroy
= _scsih_target_destroy
,
5610 .slave_destroy
= _scsih_slave_destroy
,
5611 .change_queue_depth
= _scsih_change_queue_depth
,
5612 .change_queue_type
= _scsih_change_queue_type
,
5613 .eh_abort_handler
= _scsih_abort
,
5614 .eh_device_reset_handler
= _scsih_dev_reset
,
5615 .eh_target_reset_handler
= _scsih_target_reset
,
5616 .eh_host_reset_handler
= _scsih_host_reset
,
5617 .bios_param
= _scsih_bios_param
,
5620 .sg_tablesize
= MPT2SAS_SG_DEPTH
,
5621 .max_sectors
= 8192,
5623 .use_clustering
= ENABLE_CLUSTERING
,
5624 .shost_attrs
= mpt2sas_host_attrs
,
5625 .sdev_attrs
= mpt2sas_dev_attrs
,
5629 * _scsih_expander_node_remove - removing expander device from list.
5630 * @ioc: per adapter object
5631 * @sas_expander: the sas_device object
5632 * Context: Calling function should acquire ioc->sas_node_lock.
5634 * Removing object and freeing associated memory from the
5635 * ioc->sas_expander_list.
5640 _scsih_expander_node_remove(struct MPT2SAS_ADAPTER
*ioc
,
5641 struct _sas_node
*sas_expander
)
5643 struct _sas_port
*mpt2sas_port
;
5644 struct _sas_device
*sas_device
;
5645 struct _sas_node
*expander_sibling
;
5646 unsigned long flags
;
5651 /* remove sibling ports attached to this expander */
5652 retry_device_search
:
5653 list_for_each_entry(mpt2sas_port
,
5654 &sas_expander
->sas_port_list
, port_list
) {
5655 if (mpt2sas_port
->remote_identify
.device_type
==
5657 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5659 mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
5660 mpt2sas_port
->remote_identify
.sas_address
);
5661 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5664 _scsih_remove_device(ioc
, sas_device
->handle
);
5665 if (ioc
->shost_recovery
)
5667 goto retry_device_search
;
5671 retry_expander_search
:
5672 list_for_each_entry(mpt2sas_port
,
5673 &sas_expander
->sas_port_list
, port_list
) {
5675 if (mpt2sas_port
->remote_identify
.device_type
==
5676 MPI2_SAS_DEVICE_INFO_EDGE_EXPANDER
||
5677 mpt2sas_port
->remote_identify
.device_type
==
5678 MPI2_SAS_DEVICE_INFO_FANOUT_EXPANDER
) {
5680 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5682 mpt2sas_scsih_expander_find_by_sas_address(
5683 ioc
, mpt2sas_port
->remote_identify
.sas_address
);
5684 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5685 if (!expander_sibling
)
5687 _scsih_expander_remove(ioc
, expander_sibling
->handle
);
5688 if (ioc
->shost_recovery
)
5690 goto retry_expander_search
;
5694 mpt2sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
5695 sas_expander
->parent_handle
);
5697 printk(MPT2SAS_INFO_FMT
"expander_remove: handle"
5698 "(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
5699 sas_expander
->handle
, (unsigned long long)
5700 sas_expander
->sas_address
);
5702 list_del(&sas_expander
->list
);
5703 kfree(sas_expander
->phy
);
5704 kfree(sas_expander
);
5708 * _scsih_remove - detach and remove add host
5709 * @pdev: PCI device struct
5713 static void __devexit
5714 _scsih_remove(struct pci_dev
*pdev
)
5716 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
5717 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
5718 struct _sas_port
*mpt2sas_port
;
5719 struct _sas_device
*sas_device
;
5720 struct _sas_node
*expander_sibling
;
5721 struct _raid_device
*raid_device
, *next
;
5722 struct MPT2SAS_TARGET
*sas_target_priv_data
;
5723 struct workqueue_struct
*wq
;
5724 unsigned long flags
;
5726 ioc
->remove_host
= 1;
5727 _scsih_fw_event_off(ioc
);
5729 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
5730 wq
= ioc
->firmware_event_thread
;
5731 ioc
->firmware_event_thread
= NULL
;
5732 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
5734 destroy_workqueue(wq
);
5736 /* release all the volumes */
5737 list_for_each_entry_safe(raid_device
, next
, &ioc
->raid_device_list
,
5739 if (raid_device
->starget
) {
5740 sas_target_priv_data
=
5741 raid_device
->starget
->hostdata
;
5742 sas_target_priv_data
->deleted
= 1;
5743 scsi_remove_target(&raid_device
->starget
->dev
);
5745 printk(MPT2SAS_INFO_FMT
"removing handle(0x%04x), wwid"
5746 "(0x%016llx)\n", ioc
->name
, raid_device
->handle
,
5747 (unsigned long long) raid_device
->wwid
);
5748 _scsih_raid_device_remove(ioc
, raid_device
);
5751 /* free ports attached to the sas_host */
5753 list_for_each_entry(mpt2sas_port
,
5754 &ioc
->sas_hba
.sas_port_list
, port_list
) {
5755 if (mpt2sas_port
->remote_identify
.device_type
==
5758 mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
5759 mpt2sas_port
->remote_identify
.sas_address
);
5761 _scsih_remove_device(ioc
, sas_device
->handle
);
5766 mpt2sas_scsih_expander_find_by_sas_address(ioc
,
5767 mpt2sas_port
->remote_identify
.sas_address
);
5768 if (expander_sibling
) {
5769 _scsih_expander_remove(ioc
,
5770 expander_sibling
->handle
);
5776 /* free phys attached to the sas_host */
5777 if (ioc
->sas_hba
.num_phys
) {
5778 kfree(ioc
->sas_hba
.phy
);
5779 ioc
->sas_hba
.phy
= NULL
;
5780 ioc
->sas_hba
.num_phys
= 0;
5783 sas_remove_host(shost
);
5784 mpt2sas_base_detach(ioc
);
5785 list_del(&ioc
->list
);
5786 scsi_remove_host(shost
);
5787 scsi_host_put(shost
);
5791 * _scsih_probe_boot_devices - reports 1st device
5792 * @ioc: per adapter object
5794 * If specified in bios page 2, this routine reports the 1st
5795 * device scsi-ml or sas transport for persistent boot device
5796 * purposes. Please refer to function _scsih_determine_boot_device()
5799 _scsih_probe_boot_devices(struct MPT2SAS_ADAPTER
*ioc
)
5803 struct _sas_device
*sas_device
;
5804 struct _raid_device
*raid_device
;
5805 u16 handle
, parent_handle
;
5807 unsigned long flags
;
5811 if (ioc
->req_boot_device
.device
) {
5812 device
= ioc
->req_boot_device
.device
;
5813 is_raid
= ioc
->req_boot_device
.is_raid
;
5814 } else if (ioc
->req_alt_boot_device
.device
) {
5815 device
= ioc
->req_alt_boot_device
.device
;
5816 is_raid
= ioc
->req_alt_boot_device
.is_raid
;
5817 } else if (ioc
->current_boot_device
.device
) {
5818 device
= ioc
->current_boot_device
.device
;
5819 is_raid
= ioc
->current_boot_device
.is_raid
;
5826 raid_device
= device
;
5827 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
5828 raid_device
->id
, 0);
5830 _scsih_raid_device_remove(ioc
, raid_device
);
5832 sas_device
= device
;
5833 handle
= sas_device
->handle
;
5834 parent_handle
= sas_device
->parent_handle
;
5835 sas_address
= sas_device
->sas_address
;
5836 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5837 list_move_tail(&sas_device
->list
, &ioc
->sas_device_list
);
5838 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5839 if (!mpt2sas_transport_port_add(ioc
, sas_device
->handle
,
5840 sas_device
->parent_handle
)) {
5841 _scsih_sas_device_remove(ioc
, sas_device
);
5842 } else if (!sas_device
->starget
) {
5843 mpt2sas_transport_port_remove(ioc
, sas_address
,
5845 _scsih_sas_device_remove(ioc
, sas_device
);
5851 * _scsih_probe_raid - reporting raid volumes to scsi-ml
5852 * @ioc: per adapter object
5854 * Called during initial loading of the driver.
5857 _scsih_probe_raid(struct MPT2SAS_ADAPTER
*ioc
)
5859 struct _raid_device
*raid_device
, *raid_next
;
5862 list_for_each_entry_safe(raid_device
, raid_next
,
5863 &ioc
->raid_device_list
, list
) {
5864 if (raid_device
->starget
)
5866 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
5867 raid_device
->id
, 0);
5869 _scsih_raid_device_remove(ioc
, raid_device
);
5874 * _scsih_probe_sas - reporting sas devices to sas transport
5875 * @ioc: per adapter object
5877 * Called during initial loading of the driver.
5880 _scsih_probe_sas(struct MPT2SAS_ADAPTER
*ioc
)
5882 struct _sas_device
*sas_device
, *next
;
5883 unsigned long flags
;
5884 u16 handle
, parent_handle
;
5887 /* SAS Device List */
5888 list_for_each_entry_safe(sas_device
, next
, &ioc
->sas_device_init_list
,
5890 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5891 list_move_tail(&sas_device
->list
, &ioc
->sas_device_list
);
5892 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5894 handle
= sas_device
->handle
;
5895 parent_handle
= sas_device
->parent_handle
;
5896 sas_address
= sas_device
->sas_address
;
5897 if (!mpt2sas_transport_port_add(ioc
, handle
, parent_handle
)) {
5898 _scsih_sas_device_remove(ioc
, sas_device
);
5899 } else if (!sas_device
->starget
) {
5900 mpt2sas_transport_port_remove(ioc
, sas_address
,
5902 _scsih_sas_device_remove(ioc
, sas_device
);
5908 * _scsih_probe_devices - probing for devices
5909 * @ioc: per adapter object
5911 * Called during initial loading of the driver.
5914 _scsih_probe_devices(struct MPT2SAS_ADAPTER
*ioc
)
5916 u16 volume_mapping_flags
=
5917 le16_to_cpu(ioc
->ioc_pg8
.IRVolumeMappingFlags
) &
5918 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE
;
5920 if (!(ioc
->facts
.ProtocolFlags
& MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR
))
5921 return; /* return when IOC doesn't support initiator mode */
5923 _scsih_probe_boot_devices(ioc
);
5925 if (ioc
->ir_firmware
) {
5926 if ((volume_mapping_flags
&
5927 MPI2_IOCPAGE8_IRFLAGS_HIGH_VOLUME_MAPPING
)) {
5928 _scsih_probe_sas(ioc
);
5929 _scsih_probe_raid(ioc
);
5931 _scsih_probe_raid(ioc
);
5932 _scsih_probe_sas(ioc
);
5935 _scsih_probe_sas(ioc
);
5939 * _scsih_probe - attach and add scsi host
5940 * @pdev: PCI device struct
5941 * @id: pci device id
5943 * Returns 0 success, anything else error.
5946 _scsih_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
5948 struct MPT2SAS_ADAPTER
*ioc
;
5949 struct Scsi_Host
*shost
;
5951 shost
= scsi_host_alloc(&scsih_driver_template
,
5952 sizeof(struct MPT2SAS_ADAPTER
));
5956 /* init local params */
5957 ioc
= shost_priv(shost
);
5958 memset(ioc
, 0, sizeof(struct MPT2SAS_ADAPTER
));
5959 INIT_LIST_HEAD(&ioc
->list
);
5960 list_add_tail(&ioc
->list
, &mpt2sas_ioc_list
);
5962 ioc
->id
= mpt_ids
++;
5963 sprintf(ioc
->name
, "%s%d", MPT2SAS_DRIVER_NAME
, ioc
->id
);
5965 ioc
->scsi_io_cb_idx
= scsi_io_cb_idx
;
5966 ioc
->tm_cb_idx
= tm_cb_idx
;
5967 ioc
->ctl_cb_idx
= ctl_cb_idx
;
5968 ioc
->base_cb_idx
= base_cb_idx
;
5969 ioc
->transport_cb_idx
= transport_cb_idx
;
5970 ioc
->config_cb_idx
= config_cb_idx
;
5971 ioc
->tm_tr_cb_idx
= tm_tr_cb_idx
;
5972 ioc
->tm_sas_control_cb_idx
= tm_sas_control_cb_idx
;
5973 ioc
->logging_level
= logging_level
;
5974 /* misc semaphores and spin locks */
5975 spin_lock_init(&ioc
->ioc_reset_in_progress_lock
);
5976 spin_lock_init(&ioc
->scsi_lookup_lock
);
5977 spin_lock_init(&ioc
->sas_device_lock
);
5978 spin_lock_init(&ioc
->sas_node_lock
);
5979 spin_lock_init(&ioc
->fw_event_lock
);
5980 spin_lock_init(&ioc
->raid_device_lock
);
5982 INIT_LIST_HEAD(&ioc
->sas_device_list
);
5983 INIT_LIST_HEAD(&ioc
->sas_device_init_list
);
5984 INIT_LIST_HEAD(&ioc
->sas_expander_list
);
5985 INIT_LIST_HEAD(&ioc
->fw_event_list
);
5986 INIT_LIST_HEAD(&ioc
->raid_device_list
);
5987 INIT_LIST_HEAD(&ioc
->sas_hba
.sas_port_list
);
5988 INIT_LIST_HEAD(&ioc
->delayed_tr_list
);
5990 /* init shost parameters */
5991 shost
->max_cmd_len
= 16;
5992 shost
->max_lun
= max_lun
;
5993 shost
->transportt
= mpt2sas_transport_template
;
5994 shost
->unique_id
= ioc
->id
;
5996 if ((scsi_add_host(shost
, &pdev
->dev
))) {
5997 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5998 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5999 list_del(&ioc
->list
);
6000 goto out_add_shost_fail
;
6003 scsi_host_set_prot(shost
, SHOST_DIF_TYPE1_PROTECTION
6004 | SHOST_DIF_TYPE3_PROTECTION
);
6005 scsi_host_set_guard(shost
, SHOST_DIX_GUARD_CRC
);
6008 snprintf(ioc
->firmware_event_name
, sizeof(ioc
->firmware_event_name
),
6009 "fw_event%d", ioc
->id
);
6010 ioc
->firmware_event_thread
= create_singlethread_workqueue(
6011 ioc
->firmware_event_name
);
6012 if (!ioc
->firmware_event_thread
) {
6013 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6014 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6015 goto out_thread_fail
;
6018 ioc
->wait_for_port_enable_to_complete
= 1;
6019 if ((mpt2sas_base_attach(ioc
))) {
6020 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6021 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6022 goto out_attach_fail
;
6025 ioc
->wait_for_port_enable_to_complete
= 0;
6026 _scsih_probe_devices(ioc
);
6030 destroy_workqueue(ioc
->firmware_event_thread
);
6032 list_del(&ioc
->list
);
6033 scsi_remove_host(shost
);
6040 * _scsih_suspend - power management suspend main entry point
6041 * @pdev: PCI device struct
6042 * @state: PM state change to (usually PCI_D3)
6044 * Returns 0 success, anything else error.
6047 _scsih_suspend(struct pci_dev
*pdev
, pm_message_t state
)
6049 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6050 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
6053 mpt2sas_base_stop_watchdog(ioc
);
6054 flush_scheduled_work();
6055 scsi_block_requests(shost
);
6056 device_state
= pci_choose_state(pdev
, state
);
6057 printk(MPT2SAS_INFO_FMT
"pdev=0x%p, slot=%s, entering "
6058 "operating state [D%d]\n", ioc
->name
, pdev
,
6059 pci_name(pdev
), device_state
);
6061 mpt2sas_base_free_resources(ioc
);
6062 pci_save_state(pdev
);
6063 pci_disable_device(pdev
);
6064 pci_set_power_state(pdev
, device_state
);
6069 * _scsih_resume - power management resume main entry point
6070 * @pdev: PCI device struct
6072 * Returns 0 success, anything else error.
6075 _scsih_resume(struct pci_dev
*pdev
)
6077 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6078 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
6079 u32 device_state
= pdev
->current_state
;
6082 printk(MPT2SAS_INFO_FMT
"pdev=0x%p, slot=%s, previous "
6083 "operating state [D%d]\n", ioc
->name
, pdev
,
6084 pci_name(pdev
), device_state
);
6086 pci_set_power_state(pdev
, PCI_D0
);
6087 pci_enable_wake(pdev
, PCI_D0
, 0);
6088 pci_restore_state(pdev
);
6090 r
= mpt2sas_base_map_resources(ioc
);
6094 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
, SOFT_RESET
);
6095 scsi_unblock_requests(shost
);
6096 mpt2sas_base_start_watchdog(ioc
);
6099 #endif /* CONFIG_PM */
6102 static struct pci_driver scsih_driver
= {
6103 .name
= MPT2SAS_DRIVER_NAME
,
6104 .id_table
= scsih_pci_table
,
6105 .probe
= _scsih_probe
,
6106 .remove
= __devexit_p(_scsih_remove
),
6108 .suspend
= _scsih_suspend
,
6109 .resume
= _scsih_resume
,
6115 * _scsih_init - main entry point for this driver.
6117 * Returns 0 success, anything else error.
6125 printk(KERN_INFO
"%s version %s loaded\n", MPT2SAS_DRIVER_NAME
,
6126 MPT2SAS_DRIVER_VERSION
);
6128 mpt2sas_transport_template
=
6129 sas_attach_transport(&mpt2sas_transport_functions
);
6130 if (!mpt2sas_transport_template
)
6133 mpt2sas_base_initialize_callback_handler();
6135 /* queuecommand callback hander */
6136 scsi_io_cb_idx
= mpt2sas_base_register_callback_handler(_scsih_io_done
);
6138 /* task managment callback handler */
6139 tm_cb_idx
= mpt2sas_base_register_callback_handler(_scsih_tm_done
);
6141 /* base internal commands callback handler */
6142 base_cb_idx
= mpt2sas_base_register_callback_handler(mpt2sas_base_done
);
6144 /* transport internal commands callback handler */
6145 transport_cb_idx
= mpt2sas_base_register_callback_handler(
6146 mpt2sas_transport_done
);
6148 /* configuration page API internal commands callback handler */
6149 config_cb_idx
= mpt2sas_base_register_callback_handler(
6150 mpt2sas_config_done
);
6152 /* ctl module callback handler */
6153 ctl_cb_idx
= mpt2sas_base_register_callback_handler(mpt2sas_ctl_done
);
6155 tm_tr_cb_idx
= mpt2sas_base_register_callback_handler(
6156 _scsih_tm_tr_complete
);
6157 tm_sas_control_cb_idx
= mpt2sas_base_register_callback_handler(
6158 _scsih_sas_control_complete
);
6162 error
= pci_register_driver(&scsih_driver
);
6164 sas_release_transport(mpt2sas_transport_template
);
6170 * _scsih_exit - exit point for this driver (when it is a module).
6172 * Returns 0 success, anything else error.
6177 printk(KERN_INFO
"mpt2sas version %s unloading\n",
6178 MPT2SAS_DRIVER_VERSION
);
6180 pci_unregister_driver(&scsih_driver
);
6182 sas_release_transport(mpt2sas_transport_template
);
6183 mpt2sas_base_release_callback_handler(scsi_io_cb_idx
);
6184 mpt2sas_base_release_callback_handler(tm_cb_idx
);
6185 mpt2sas_base_release_callback_handler(base_cb_idx
);
6186 mpt2sas_base_release_callback_handler(transport_cb_idx
);
6187 mpt2sas_base_release_callback_handler(config_cb_idx
);
6188 mpt2sas_base_release_callback_handler(ctl_cb_idx
);
6190 mpt2sas_base_release_callback_handler(tm_tr_cb_idx
);
6191 mpt2sas_base_release_callback_handler(tm_sas_control_cb_idx
);
6196 module_init(_scsih_init
);
6197 module_exit(_scsih_exit
);