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
},
199 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2116_1
,
200 PCI_ANY_ID
, PCI_ANY_ID
},
201 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2116_2
,
202 PCI_ANY_ID
, PCI_ANY_ID
},
203 {0} /* Terminating entry */
205 MODULE_DEVICE_TABLE(pci
, scsih_pci_table
);
208 * _scsih_set_debug_level - global setting of ioc->logging_level.
210 * Note: The logging levels are defined in mpt2sas_debug.h.
213 _scsih_set_debug_level(const char *val
, struct kernel_param
*kp
)
215 int ret
= param_set_int(val
, kp
);
216 struct MPT2SAS_ADAPTER
*ioc
;
221 printk(KERN_INFO
"setting logging_level(0x%08x)\n", logging_level
);
222 list_for_each_entry(ioc
, &mpt2sas_ioc_list
, list
)
223 ioc
->logging_level
= logging_level
;
226 module_param_call(logging_level
, _scsih_set_debug_level
, param_get_int
,
227 &logging_level
, 0644);
230 * _scsih_srch_boot_sas_address - search based on sas_address
231 * @sas_address: sas address
232 * @boot_device: boot device object from bios page 2
234 * Returns 1 when there's a match, 0 means no match.
237 _scsih_srch_boot_sas_address(u64 sas_address
,
238 Mpi2BootDeviceSasWwid_t
*boot_device
)
240 return (sas_address
== le64_to_cpu(boot_device
->SASAddress
)) ? 1 : 0;
244 * _scsih_srch_boot_device_name - search based on device name
245 * @device_name: device name specified in INDENTIFY fram
246 * @boot_device: boot device object from bios page 2
248 * Returns 1 when there's a match, 0 means no match.
251 _scsih_srch_boot_device_name(u64 device_name
,
252 Mpi2BootDeviceDeviceName_t
*boot_device
)
254 return (device_name
== le64_to_cpu(boot_device
->DeviceName
)) ? 1 : 0;
258 * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot
259 * @enclosure_logical_id: enclosure logical id
260 * @slot_number: slot number
261 * @boot_device: boot device object from bios page 2
263 * Returns 1 when there's a match, 0 means no match.
266 _scsih_srch_boot_encl_slot(u64 enclosure_logical_id
, u16 slot_number
,
267 Mpi2BootDeviceEnclosureSlot_t
*boot_device
)
269 return (enclosure_logical_id
== le64_to_cpu(boot_device
->
270 EnclosureLogicalID
) && slot_number
== le16_to_cpu(boot_device
->
271 SlotNumber
)) ? 1 : 0;
275 * _scsih_is_boot_device - search for matching boot device.
276 * @sas_address: sas address
277 * @device_name: device name specified in INDENTIFY fram
278 * @enclosure_logical_id: enclosure logical id
279 * @slot_number: slot number
280 * @form: specifies boot device form
281 * @boot_device: boot device object from bios page 2
283 * Returns 1 when there's a match, 0 means no match.
286 _scsih_is_boot_device(u64 sas_address
, u64 device_name
,
287 u64 enclosure_logical_id
, u16 slot
, u8 form
,
288 Mpi2BiosPage2BootDevice_t
*boot_device
)
293 case MPI2_BIOSPAGE2_FORM_SAS_WWID
:
296 rc
= _scsih_srch_boot_sas_address(
297 sas_address
, &boot_device
->SasWwid
);
299 case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT
:
300 if (!enclosure_logical_id
)
302 rc
= _scsih_srch_boot_encl_slot(
303 enclosure_logical_id
,
304 slot
, &boot_device
->EnclosureSlot
);
306 case MPI2_BIOSPAGE2_FORM_DEVICE_NAME
:
309 rc
= _scsih_srch_boot_device_name(
310 device_name
, &boot_device
->DeviceName
);
312 case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED
:
320 * _scsih_determine_boot_device - determine boot device.
321 * @ioc: per adapter object
322 * @device: either sas_device or raid_device object
323 * @is_raid: [flag] 1 = raid object, 0 = sas object
325 * Determines whether this device should be first reported device to
326 * to scsi-ml or sas transport, this purpose is for persistant boot device.
327 * There are primary, alternate, and current entries in bios page 2. The order
328 * priority is primary, alternate, then current. This routine saves
329 * the corresponding device object and is_raid flag in the ioc object.
330 * The saved data to be used later in _scsih_probe_boot_devices().
333 _scsih_determine_boot_device(struct MPT2SAS_ADAPTER
*ioc
,
334 void *device
, u8 is_raid
)
336 struct _sas_device
*sas_device
;
337 struct _raid_device
*raid_device
;
340 u64 enclosure_logical_id
;
343 /* only process this function when driver loads */
344 if (!ioc
->wait_for_port_enable_to_complete
)
349 sas_address
= sas_device
->sas_address
;
350 device_name
= sas_device
->device_name
;
351 enclosure_logical_id
= sas_device
->enclosure_logical_id
;
352 slot
= sas_device
->slot
;
354 raid_device
= device
;
355 sas_address
= raid_device
->wwid
;
357 enclosure_logical_id
= 0;
361 if (!ioc
->req_boot_device
.device
) {
362 if (_scsih_is_boot_device(sas_address
, device_name
,
363 enclosure_logical_id
, slot
,
364 (ioc
->bios_pg2
.ReqBootDeviceForm
&
365 MPI2_BIOSPAGE2_FORM_MASK
),
366 &ioc
->bios_pg2
.RequestedBootDevice
)) {
367 dinitprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
368 "%s: req_boot_device(0x%016llx)\n",
370 (unsigned long long)sas_address
));
371 ioc
->req_boot_device
.device
= device
;
372 ioc
->req_boot_device
.is_raid
= is_raid
;
376 if (!ioc
->req_alt_boot_device
.device
) {
377 if (_scsih_is_boot_device(sas_address
, device_name
,
378 enclosure_logical_id
, slot
,
379 (ioc
->bios_pg2
.ReqAltBootDeviceForm
&
380 MPI2_BIOSPAGE2_FORM_MASK
),
381 &ioc
->bios_pg2
.RequestedAltBootDevice
)) {
382 dinitprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
383 "%s: req_alt_boot_device(0x%016llx)\n",
385 (unsigned long long)sas_address
));
386 ioc
->req_alt_boot_device
.device
= device
;
387 ioc
->req_alt_boot_device
.is_raid
= is_raid
;
391 if (!ioc
->current_boot_device
.device
) {
392 if (_scsih_is_boot_device(sas_address
, device_name
,
393 enclosure_logical_id
, slot
,
394 (ioc
->bios_pg2
.CurrentBootDeviceForm
&
395 MPI2_BIOSPAGE2_FORM_MASK
),
396 &ioc
->bios_pg2
.CurrentBootDevice
)) {
397 dinitprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
398 "%s: current_boot_device(0x%016llx)\n",
400 (unsigned long long)sas_address
));
401 ioc
->current_boot_device
.device
= device
;
402 ioc
->current_boot_device
.is_raid
= is_raid
;
408 * mpt2sas_scsih_sas_device_find_by_sas_address - sas device search
409 * @ioc: per adapter object
410 * @sas_address: sas address
411 * Context: Calling function should acquire ioc->sas_device_lock
413 * This searches for sas_device based on sas_address, then return sas_device
417 mpt2sas_scsih_sas_device_find_by_sas_address(struct MPT2SAS_ADAPTER
*ioc
,
420 struct _sas_device
*sas_device
, *r
;
423 /* check the sas_device_init_list */
424 list_for_each_entry(sas_device
, &ioc
->sas_device_init_list
,
426 if (sas_device
->sas_address
!= sas_address
)
432 /* then check the sas_device_list */
433 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
) {
434 if (sas_device
->sas_address
!= sas_address
)
444 * _scsih_sas_device_find_by_handle - sas device search
445 * @ioc: per adapter object
446 * @handle: sas device handle (assigned by firmware)
447 * Context: Calling function should acquire ioc->sas_device_lock
449 * This searches for sas_device based on sas_address, then return sas_device
452 static struct _sas_device
*
453 _scsih_sas_device_find_by_handle(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
455 struct _sas_device
*sas_device
, *r
;
458 if (ioc
->wait_for_port_enable_to_complete
) {
459 list_for_each_entry(sas_device
, &ioc
->sas_device_init_list
,
461 if (sas_device
->handle
!= handle
)
467 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
) {
468 if (sas_device
->handle
!= handle
)
480 * _scsih_sas_device_remove - remove sas_device from list.
481 * @ioc: per adapter object
482 * @sas_device: the sas_device object
483 * Context: This function will acquire ioc->sas_device_lock.
485 * Removing object and freeing associated memory from the ioc->sas_device_list.
488 _scsih_sas_device_remove(struct MPT2SAS_ADAPTER
*ioc
,
489 struct _sas_device
*sas_device
)
493 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
494 list_del(&sas_device
->list
);
495 memset(sas_device
, 0, sizeof(struct _sas_device
));
497 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
501 * _scsih_sas_device_add - insert sas_device to the list.
502 * @ioc: per adapter object
503 * @sas_device: the sas_device object
504 * Context: This function will acquire ioc->sas_device_lock.
506 * Adding new object to the ioc->sas_device_list.
509 _scsih_sas_device_add(struct MPT2SAS_ADAPTER
*ioc
,
510 struct _sas_device
*sas_device
)
513 u16 handle
, parent_handle
;
516 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: handle"
517 "(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
, __func__
,
518 sas_device
->handle
, (unsigned long long)sas_device
->sas_address
));
520 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
521 list_add_tail(&sas_device
->list
, &ioc
->sas_device_list
);
522 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
524 handle
= sas_device
->handle
;
525 parent_handle
= sas_device
->parent_handle
;
526 sas_address
= sas_device
->sas_address
;
527 if (!mpt2sas_transport_port_add(ioc
, handle
, parent_handle
))
528 _scsih_sas_device_remove(ioc
, sas_device
);
532 * _scsih_sas_device_init_add - insert sas_device to the list.
533 * @ioc: per adapter object
534 * @sas_device: the sas_device object
535 * Context: This function will acquire ioc->sas_device_lock.
537 * Adding new object at driver load time to the ioc->sas_device_init_list.
540 _scsih_sas_device_init_add(struct MPT2SAS_ADAPTER
*ioc
,
541 struct _sas_device
*sas_device
)
545 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: handle"
546 "(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
, __func__
,
547 sas_device
->handle
, (unsigned long long)sas_device
->sas_address
));
549 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
550 list_add_tail(&sas_device
->list
, &ioc
->sas_device_init_list
);
551 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
552 _scsih_determine_boot_device(ioc
, sas_device
, 0);
556 * mpt2sas_scsih_expander_find_by_handle - expander device search
557 * @ioc: per adapter object
558 * @handle: expander handle (assigned by firmware)
559 * Context: Calling function should acquire ioc->sas_device_lock
561 * This searches for expander device based on handle, then returns the
565 mpt2sas_scsih_expander_find_by_handle(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
567 struct _sas_node
*sas_expander
, *r
;
570 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
571 if (sas_expander
->handle
!= handle
)
581 * _scsih_raid_device_find_by_id - raid device search
582 * @ioc: per adapter object
583 * @id: sas device target id
584 * @channel: sas device channel
585 * Context: Calling function should acquire ioc->raid_device_lock
587 * This searches for raid_device based on target id, then return raid_device
590 static struct _raid_device
*
591 _scsih_raid_device_find_by_id(struct MPT2SAS_ADAPTER
*ioc
, int id
, int channel
)
593 struct _raid_device
*raid_device
, *r
;
596 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
597 if (raid_device
->id
== id
&& raid_device
->channel
== channel
) {
608 * _scsih_raid_device_find_by_handle - raid device search
609 * @ioc: per adapter object
610 * @handle: sas device handle (assigned by firmware)
611 * Context: Calling function should acquire ioc->raid_device_lock
613 * This searches for raid_device based on handle, then return raid_device
616 static struct _raid_device
*
617 _scsih_raid_device_find_by_handle(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
619 struct _raid_device
*raid_device
, *r
;
622 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
623 if (raid_device
->handle
!= handle
)
634 * _scsih_raid_device_find_by_wwid - raid device search
635 * @ioc: per adapter object
636 * @handle: sas device handle (assigned by firmware)
637 * Context: Calling function should acquire ioc->raid_device_lock
639 * This searches for raid_device based on wwid, then return raid_device
642 static struct _raid_device
*
643 _scsih_raid_device_find_by_wwid(struct MPT2SAS_ADAPTER
*ioc
, u64 wwid
)
645 struct _raid_device
*raid_device
, *r
;
648 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
649 if (raid_device
->wwid
!= wwid
)
660 * _scsih_raid_device_add - add raid_device object
661 * @ioc: per adapter object
662 * @raid_device: raid_device object
664 * This is added to the raid_device_list link list.
667 _scsih_raid_device_add(struct MPT2SAS_ADAPTER
*ioc
,
668 struct _raid_device
*raid_device
)
672 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: handle"
673 "(0x%04x), wwid(0x%016llx)\n", ioc
->name
, __func__
,
674 raid_device
->handle
, (unsigned long long)raid_device
->wwid
));
676 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
677 list_add_tail(&raid_device
->list
, &ioc
->raid_device_list
);
678 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
682 * _scsih_raid_device_remove - delete raid_device object
683 * @ioc: per adapter object
684 * @raid_device: raid_device object
686 * This is removed from the raid_device_list link list.
689 _scsih_raid_device_remove(struct MPT2SAS_ADAPTER
*ioc
,
690 struct _raid_device
*raid_device
)
694 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
695 list_del(&raid_device
->list
);
696 memset(raid_device
, 0, sizeof(struct _raid_device
));
698 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
702 * mpt2sas_scsih_expander_find_by_sas_address - expander device search
703 * @ioc: per adapter object
704 * @sas_address: sas address
705 * Context: Calling function should acquire ioc->sas_node_lock.
707 * This searches for expander device based on sas_address, then returns the
711 mpt2sas_scsih_expander_find_by_sas_address(struct MPT2SAS_ADAPTER
*ioc
,
714 struct _sas_node
*sas_expander
, *r
;
717 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
718 if (sas_expander
->sas_address
!= sas_address
)
728 * _scsih_expander_node_add - insert expander device to the list.
729 * @ioc: per adapter object
730 * @sas_expander: the sas_device object
731 * Context: This function will acquire ioc->sas_node_lock.
733 * Adding new object to the ioc->sas_expander_list.
738 _scsih_expander_node_add(struct MPT2SAS_ADAPTER
*ioc
,
739 struct _sas_node
*sas_expander
)
743 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
744 list_add_tail(&sas_expander
->list
, &ioc
->sas_expander_list
);
745 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
749 * _scsih_is_end_device - determines if device is an end device
750 * @device_info: bitfield providing information about the device.
753 * Returns 1 if end device.
756 _scsih_is_end_device(u32 device_info
)
758 if (device_info
& MPI2_SAS_DEVICE_INFO_END_DEVICE
&&
759 ((device_info
& MPI2_SAS_DEVICE_INFO_SSP_TARGET
) |
760 (device_info
& MPI2_SAS_DEVICE_INFO_STP_TARGET
) |
761 (device_info
& MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)))
768 * mptscsih_get_scsi_lookup - returns scmd entry
769 * @ioc: per adapter object
770 * @smid: system request message index
772 * Returns the smid stored scmd pointer.
774 static struct scsi_cmnd
*
775 _scsih_scsi_lookup_get(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
777 return ioc
->scsi_lookup
[smid
- 1].scmd
;
781 * _scsih_scsi_lookup_find_by_scmd - scmd lookup
782 * @ioc: per adapter object
783 * @smid: system request message index
784 * @scmd: pointer to scsi command object
785 * Context: This function will acquire ioc->scsi_lookup_lock.
787 * This will search for a scmd pointer in the scsi_lookup array,
788 * returning the revelent smid. A returned value of zero means invalid.
791 _scsih_scsi_lookup_find_by_scmd(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_cmnd
798 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
800 for (i
= 0; i
< ioc
->scsiio_depth
; i
++) {
801 if (ioc
->scsi_lookup
[i
].scmd
== scmd
) {
802 smid
= ioc
->scsi_lookup
[i
].smid
;
807 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
812 * _scsih_scsi_lookup_find_by_target - search for matching channel:id
813 * @ioc: per adapter object
816 * Context: This function will acquire ioc->scsi_lookup_lock.
818 * This will search for a matching channel:id in the scsi_lookup array,
819 * returning 1 if found.
822 _scsih_scsi_lookup_find_by_target(struct MPT2SAS_ADAPTER
*ioc
, int id
,
829 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
831 for (i
= 0 ; i
< ioc
->scsiio_depth
; i
++) {
832 if (ioc
->scsi_lookup
[i
].scmd
&&
833 (ioc
->scsi_lookup
[i
].scmd
->device
->id
== id
&&
834 ioc
->scsi_lookup
[i
].scmd
->device
->channel
== channel
)) {
840 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
845 * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun
846 * @ioc: per adapter object
850 * Context: This function will acquire ioc->scsi_lookup_lock.
852 * This will search for a matching channel:id:lun in the scsi_lookup array,
853 * returning 1 if found.
856 _scsih_scsi_lookup_find_by_lun(struct MPT2SAS_ADAPTER
*ioc
, int id
,
857 unsigned int lun
, int channel
)
863 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
865 for (i
= 0 ; i
< ioc
->scsiio_depth
; i
++) {
866 if (ioc
->scsi_lookup
[i
].scmd
&&
867 (ioc
->scsi_lookup
[i
].scmd
->device
->id
== id
&&
868 ioc
->scsi_lookup
[i
].scmd
->device
->channel
== channel
&&
869 ioc
->scsi_lookup
[i
].scmd
->device
->lun
== lun
)) {
875 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
880 * _scsih_get_chain_buffer_dma - obtain block of chains (dma address)
881 * @ioc: per adapter object
882 * @smid: system request message index
884 * Returns phys pointer to chain buffer.
887 _scsih_get_chain_buffer_dma(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
889 return ioc
->chain_dma
+ ((smid
- 1) * (ioc
->request_sz
*
890 ioc
->chains_needed_per_io
));
894 * _scsih_get_chain_buffer - obtain block of chains assigned to a mf request
895 * @ioc: per adapter object
896 * @smid: system request message index
898 * Returns virt pointer to chain buffer.
901 _scsih_get_chain_buffer(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
903 return (void *)(ioc
->chain
+ ((smid
- 1) * (ioc
->request_sz
*
904 ioc
->chains_needed_per_io
)));
908 * _scsih_build_scatter_gather - main sg creation routine
909 * @ioc: per adapter object
910 * @scmd: scsi command
911 * @smid: system request message index
914 * The main routine that builds scatter gather table from a given
915 * scsi request sent via the .queuecommand main handler.
917 * Returns 0 success, anything else error
920 _scsih_build_scatter_gather(struct MPT2SAS_ADAPTER
*ioc
,
921 struct scsi_cmnd
*scmd
, u16 smid
)
923 Mpi2SCSIIORequest_t
*mpi_request
;
924 dma_addr_t chain_dma
;
925 struct scatterlist
*sg_scmd
;
926 void *sg_local
, *chain
;
933 u32 sgl_flags_last_element
;
934 u32 sgl_flags_end_buffer
;
936 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
938 /* init scatter gather flags */
939 sgl_flags
= MPI2_SGE_FLAGS_SIMPLE_ELEMENT
;
940 if (scmd
->sc_data_direction
== DMA_TO_DEVICE
)
941 sgl_flags
|= MPI2_SGE_FLAGS_HOST_TO_IOC
;
942 sgl_flags_last_element
= (sgl_flags
| MPI2_SGE_FLAGS_LAST_ELEMENT
)
943 << MPI2_SGE_FLAGS_SHIFT
;
944 sgl_flags_end_buffer
= (sgl_flags
| MPI2_SGE_FLAGS_LAST_ELEMENT
|
945 MPI2_SGE_FLAGS_END_OF_BUFFER
| MPI2_SGE_FLAGS_END_OF_LIST
)
946 << MPI2_SGE_FLAGS_SHIFT
;
947 sgl_flags
= sgl_flags
<< MPI2_SGE_FLAGS_SHIFT
;
949 sg_scmd
= scsi_sglist(scmd
);
950 sges_left
= scsi_dma_map(scmd
);
952 sdev_printk(KERN_ERR
, scmd
->device
, "pci_map_sg"
953 " failed: request for %d bytes!\n", scsi_bufflen(scmd
));
957 sg_local
= &mpi_request
->SGL
;
958 sges_in_segment
= ioc
->max_sges_in_main_message
;
959 if (sges_left
<= sges_in_segment
)
960 goto fill_in_last_segment
;
962 mpi_request
->ChainOffset
= (offsetof(Mpi2SCSIIORequest_t
, SGL
) +
963 (sges_in_segment
* ioc
->sge_size
))/4;
965 /* fill in main message segment when there is a chain following */
966 while (sges_in_segment
) {
967 if (sges_in_segment
== 1)
968 ioc
->base_add_sg_single(sg_local
,
969 sgl_flags_last_element
| sg_dma_len(sg_scmd
),
970 sg_dma_address(sg_scmd
));
972 ioc
->base_add_sg_single(sg_local
, sgl_flags
|
973 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
974 sg_scmd
= sg_next(sg_scmd
);
975 sg_local
+= ioc
->sge_size
;
980 /* initializing the chain flags and pointers */
981 chain_flags
= MPI2_SGE_FLAGS_CHAIN_ELEMENT
<< MPI2_SGE_FLAGS_SHIFT
;
982 chain
= _scsih_get_chain_buffer(ioc
, smid
);
983 chain_dma
= _scsih_get_chain_buffer_dma(ioc
, smid
);
985 sges_in_segment
= (sges_left
<=
986 ioc
->max_sges_in_chain_message
) ? sges_left
:
987 ioc
->max_sges_in_chain_message
;
988 chain_offset
= (sges_left
== sges_in_segment
) ?
989 0 : (sges_in_segment
* ioc
->sge_size
)/4;
990 chain_length
= sges_in_segment
* ioc
->sge_size
;
992 chain_offset
= chain_offset
<<
993 MPI2_SGE_CHAIN_OFFSET_SHIFT
;
994 chain_length
+= ioc
->sge_size
;
996 ioc
->base_add_sg_single(sg_local
, chain_flags
| chain_offset
|
997 chain_length
, chain_dma
);
1000 goto fill_in_last_segment
;
1002 /* fill in chain segments */
1003 while (sges_in_segment
) {
1004 if (sges_in_segment
== 1)
1005 ioc
->base_add_sg_single(sg_local
,
1006 sgl_flags_last_element
|
1007 sg_dma_len(sg_scmd
),
1008 sg_dma_address(sg_scmd
));
1010 ioc
->base_add_sg_single(sg_local
, sgl_flags
|
1011 sg_dma_len(sg_scmd
),
1012 sg_dma_address(sg_scmd
));
1013 sg_scmd
= sg_next(sg_scmd
);
1014 sg_local
+= ioc
->sge_size
;
1019 chain_dma
+= ioc
->request_sz
;
1020 chain
+= ioc
->request_sz
;
1024 fill_in_last_segment
:
1026 /* fill the last segment */
1029 ioc
->base_add_sg_single(sg_local
, sgl_flags_end_buffer
|
1030 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
1032 ioc
->base_add_sg_single(sg_local
, sgl_flags
|
1033 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
1034 sg_scmd
= sg_next(sg_scmd
);
1035 sg_local
+= ioc
->sge_size
;
1043 * _scsih_change_queue_depth - setting device queue depth
1044 * @sdev: scsi device struct
1045 * @qdepth: requested queue depth
1047 * Returns queue depth.
1050 _scsih_change_queue_depth(struct scsi_device
*sdev
, int qdepth
)
1052 struct Scsi_Host
*shost
= sdev
->host
;
1056 max_depth
= shost
->can_queue
;
1057 if (!sdev
->tagged_supported
)
1059 if (qdepth
> max_depth
)
1061 tag_type
= (qdepth
== 1) ? 0 : MSG_SIMPLE_TAG
;
1062 scsi_adjust_queue_depth(sdev
, tag_type
, qdepth
);
1064 if (sdev
->inquiry_len
> 7)
1065 sdev_printk(KERN_INFO
, sdev
, "qdepth(%d), tagged(%d), "
1066 "simple(%d), ordered(%d), scsi_level(%d), cmd_que(%d)\n",
1067 sdev
->queue_depth
, sdev
->tagged_supported
, sdev
->simple_tags
,
1068 sdev
->ordered_tags
, sdev
->scsi_level
,
1069 (sdev
->inquiry
[7] & 2) >> 1);
1071 return sdev
->queue_depth
;
1075 * _scsih_change_queue_type - changing device queue tag type
1076 * @sdev: scsi device struct
1077 * @tag_type: requested tag type
1079 * Returns queue tag type.
1082 _scsih_change_queue_type(struct scsi_device
*sdev
, int tag_type
)
1084 if (sdev
->tagged_supported
) {
1085 scsi_set_tag_type(sdev
, tag_type
);
1087 scsi_activate_tcq(sdev
, sdev
->queue_depth
);
1089 scsi_deactivate_tcq(sdev
, sdev
->queue_depth
);
1097 * _scsih_target_alloc - target add routine
1098 * @starget: scsi target struct
1100 * Returns 0 if ok. Any other return is assumed to be an error and
1101 * the device is ignored.
1104 _scsih_target_alloc(struct scsi_target
*starget
)
1106 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
1107 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1108 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1109 struct _sas_device
*sas_device
;
1110 struct _raid_device
*raid_device
;
1111 unsigned long flags
;
1112 struct sas_rphy
*rphy
;
1114 sas_target_priv_data
= kzalloc(sizeof(struct scsi_target
), GFP_KERNEL
);
1115 if (!sas_target_priv_data
)
1118 starget
->hostdata
= sas_target_priv_data
;
1119 sas_target_priv_data
->starget
= starget
;
1120 sas_target_priv_data
->handle
= MPT2SAS_INVALID_DEVICE_HANDLE
;
1123 if (starget
->channel
== RAID_CHANNEL
) {
1124 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1125 raid_device
= _scsih_raid_device_find_by_id(ioc
, starget
->id
,
1128 sas_target_priv_data
->handle
= raid_device
->handle
;
1129 sas_target_priv_data
->sas_address
= raid_device
->wwid
;
1130 sas_target_priv_data
->flags
|= MPT_TARGET_FLAGS_VOLUME
;
1131 raid_device
->starget
= starget
;
1133 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1137 /* sas/sata devices */
1138 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1139 rphy
= dev_to_rphy(starget
->dev
.parent
);
1140 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1141 rphy
->identify
.sas_address
);
1144 sas_target_priv_data
->handle
= sas_device
->handle
;
1145 sas_target_priv_data
->sas_address
= sas_device
->sas_address
;
1146 sas_device
->starget
= starget
;
1147 sas_device
->id
= starget
->id
;
1148 sas_device
->channel
= starget
->channel
;
1149 if (sas_device
->hidden_raid_component
)
1150 sas_target_priv_data
->flags
|=
1151 MPT_TARGET_FLAGS_RAID_COMPONENT
;
1153 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1159 * _scsih_target_destroy - target destroy routine
1160 * @starget: scsi target struct
1165 _scsih_target_destroy(struct scsi_target
*starget
)
1167 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
1168 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1169 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1170 struct _sas_device
*sas_device
;
1171 struct _raid_device
*raid_device
;
1172 unsigned long flags
;
1173 struct sas_rphy
*rphy
;
1175 sas_target_priv_data
= starget
->hostdata
;
1176 if (!sas_target_priv_data
)
1179 if (starget
->channel
== RAID_CHANNEL
) {
1180 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1181 raid_device
= _scsih_raid_device_find_by_id(ioc
, starget
->id
,
1184 raid_device
->starget
= NULL
;
1185 raid_device
->sdev
= NULL
;
1187 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1191 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1192 rphy
= dev_to_rphy(starget
->dev
.parent
);
1193 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1194 rphy
->identify
.sas_address
);
1195 if (sas_device
&& (sas_device
->starget
== starget
) &&
1196 (sas_device
->id
== starget
->id
) &&
1197 (sas_device
->channel
== starget
->channel
))
1198 sas_device
->starget
= NULL
;
1200 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1203 kfree(sas_target_priv_data
);
1204 starget
->hostdata
= NULL
;
1208 * _scsih_slave_alloc - device add routine
1209 * @sdev: scsi device struct
1211 * Returns 0 if ok. Any other return is assumed to be an error and
1212 * the device is ignored.
1215 _scsih_slave_alloc(struct scsi_device
*sdev
)
1217 struct Scsi_Host
*shost
;
1218 struct MPT2SAS_ADAPTER
*ioc
;
1219 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1220 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1221 struct scsi_target
*starget
;
1222 struct _raid_device
*raid_device
;
1223 struct _sas_device
*sas_device
;
1224 unsigned long flags
;
1226 sas_device_priv_data
= kzalloc(sizeof(struct scsi_device
), GFP_KERNEL
);
1227 if (!sas_device_priv_data
)
1230 sas_device_priv_data
->lun
= sdev
->lun
;
1231 sas_device_priv_data
->flags
= MPT_DEVICE_FLAGS_INIT
;
1233 starget
= scsi_target(sdev
);
1234 sas_target_priv_data
= starget
->hostdata
;
1235 sas_target_priv_data
->num_luns
++;
1236 sas_device_priv_data
->sas_target
= sas_target_priv_data
;
1237 sdev
->hostdata
= sas_device_priv_data
;
1238 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
))
1239 sdev
->no_uld_attach
= 1;
1241 shost
= dev_to_shost(&starget
->dev
);
1242 ioc
= shost_priv(shost
);
1243 if (starget
->channel
== RAID_CHANNEL
) {
1244 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1245 raid_device
= _scsih_raid_device_find_by_id(ioc
,
1246 starget
->id
, starget
->channel
);
1248 raid_device
->sdev
= sdev
; /* raid is single lun */
1249 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1251 /* set TLR bit for SSP devices */
1252 if (!(ioc
->facts
.IOCCapabilities
&
1253 MPI2_IOCFACTS_CAPABILITY_TLR
))
1255 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1256 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1257 sas_device_priv_data
->sas_target
->sas_address
);
1258 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1259 if (sas_device
&& sas_device
->device_info
&
1260 MPI2_SAS_DEVICE_INFO_SSP_TARGET
)
1261 sas_device_priv_data
->flags
|= MPT_DEVICE_TLR_ON
;
1269 * _scsih_slave_destroy - device destroy routine
1270 * @sdev: scsi device struct
1275 _scsih_slave_destroy(struct scsi_device
*sdev
)
1277 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1278 struct scsi_target
*starget
;
1280 if (!sdev
->hostdata
)
1283 starget
= scsi_target(sdev
);
1284 sas_target_priv_data
= starget
->hostdata
;
1285 sas_target_priv_data
->num_luns
--;
1286 kfree(sdev
->hostdata
);
1287 sdev
->hostdata
= NULL
;
1291 * _scsih_display_sata_capabilities - sata capabilities
1292 * @ioc: per adapter object
1293 * @sas_device: the sas_device object
1294 * @sdev: scsi device struct
1297 _scsih_display_sata_capabilities(struct MPT2SAS_ADAPTER
*ioc
,
1298 struct _sas_device
*sas_device
, struct scsi_device
*sdev
)
1300 Mpi2ConfigReply_t mpi_reply
;
1301 Mpi2SasDevicePage0_t sas_device_pg0
;
1306 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
1307 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, sas_device
->handle
))) {
1308 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1309 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1313 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
1314 MPI2_IOCSTATUS_MASK
;
1315 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
1316 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1317 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1321 flags
= le16_to_cpu(sas_device_pg0
.Flags
);
1322 device_info
= le16_to_cpu(sas_device_pg0
.DeviceInfo
);
1324 sdev_printk(KERN_INFO
, sdev
,
1325 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1326 "sw_preserve(%s)\n",
1327 (device_info
& MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE
) ? "y" : "n",
1328 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED
) ? "y" : "n",
1329 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY
) ? "y" :
1331 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED
) ? "y" : "n",
1332 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED
) ? "y" : "n",
1333 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE
) ? "y" : "n");
1337 * _scsih_get_volume_capabilities - volume capabilities
1338 * @ioc: per adapter object
1339 * @sas_device: the raid_device object
1342 _scsih_get_volume_capabilities(struct MPT2SAS_ADAPTER
*ioc
,
1343 struct _raid_device
*raid_device
)
1345 Mpi2RaidVolPage0_t
*vol_pg0
;
1346 Mpi2RaidPhysDiskPage0_t pd_pg0
;
1347 Mpi2SasDevicePage0_t sas_device_pg0
;
1348 Mpi2ConfigReply_t mpi_reply
;
1352 if ((mpt2sas_config_get_number_pds(ioc
, raid_device
->handle
,
1353 &num_pds
)) || !num_pds
) {
1354 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1355 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1359 raid_device
->num_pds
= num_pds
;
1360 sz
= offsetof(Mpi2RaidVolPage0_t
, PhysDisk
) + (num_pds
*
1361 sizeof(Mpi2RaidVol0PhysDisk_t
));
1362 vol_pg0
= kzalloc(sz
, GFP_KERNEL
);
1364 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1365 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1369 if ((mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, vol_pg0
,
1370 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, raid_device
->handle
, sz
))) {
1371 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1372 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1377 raid_device
->volume_type
= vol_pg0
->VolumeType
;
1379 /* figure out what the underlying devices are by
1380 * obtaining the device_info bits for the 1st device
1382 if (!(mpt2sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
1383 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM
,
1384 vol_pg0
->PhysDisk
[0].PhysDiskNum
))) {
1385 if (!(mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
1386 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
1387 le16_to_cpu(pd_pg0
.DevHandle
)))) {
1388 raid_device
->device_info
=
1389 le32_to_cpu(sas_device_pg0
.DeviceInfo
);
1397 * _scsih_slave_configure - device configure routine.
1398 * @sdev: scsi device struct
1400 * Returns 0 if ok. Any other return is assumed to be an error and
1401 * the device is ignored.
1404 _scsih_slave_configure(struct scsi_device
*sdev
)
1406 struct Scsi_Host
*shost
= sdev
->host
;
1407 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1408 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1409 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1410 struct _sas_device
*sas_device
;
1411 struct _raid_device
*raid_device
;
1412 unsigned long flags
;
1419 sas_device_priv_data
= sdev
->hostdata
;
1420 sas_device_priv_data
->configured_lun
= 1;
1421 sas_device_priv_data
->flags
&= ~MPT_DEVICE_FLAGS_INIT
;
1422 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
1424 /* raid volume handling */
1425 if (sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
1427 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1428 raid_device
= _scsih_raid_device_find_by_handle(ioc
,
1429 sas_target_priv_data
->handle
);
1430 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1432 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1433 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1437 _scsih_get_volume_capabilities(ioc
, raid_device
);
1439 /* RAID Queue Depth Support
1440 * IS volume = underlying qdepth of drive type, either
1441 * MPT2SAS_SAS_QUEUE_DEPTH or MPT2SAS_SATA_QUEUE_DEPTH
1442 * IM/IME/R10 = 128 (MPT2SAS_RAID_QUEUE_DEPTH)
1444 if (raid_device
->device_info
&
1445 MPI2_SAS_DEVICE_INFO_SSP_TARGET
) {
1446 qdepth
= MPT2SAS_SAS_QUEUE_DEPTH
;
1449 qdepth
= MPT2SAS_SATA_QUEUE_DEPTH
;
1450 if (raid_device
->device_info
&
1451 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1457 switch (raid_device
->volume_type
) {
1458 case MPI2_RAID_VOL_TYPE_RAID0
:
1461 case MPI2_RAID_VOL_TYPE_RAID1E
:
1462 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
1463 if (ioc
->manu_pg10
.OEMIdentifier
&&
1464 (ioc
->manu_pg10
.GenericFlags0
&
1465 MFG10_GF0_R10_DISPLAY
) &&
1466 !(raid_device
->num_pds
% 2))
1471 case MPI2_RAID_VOL_TYPE_RAID1
:
1472 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
1475 case MPI2_RAID_VOL_TYPE_RAID10
:
1476 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
1479 case MPI2_RAID_VOL_TYPE_UNKNOWN
:
1481 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
1486 sdev_printk(KERN_INFO
, sdev
, "%s: "
1487 "handle(0x%04x), wwid(0x%016llx), pd_count(%d), type(%s)\n",
1488 r_level
, raid_device
->handle
,
1489 (unsigned long long)raid_device
->wwid
,
1490 raid_device
->num_pds
, ds
);
1491 _scsih_change_queue_depth(sdev
, qdepth
);
1495 /* non-raid handling */
1496 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1497 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1498 sas_device_priv_data
->sas_target
->sas_address
);
1499 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1501 if (sas_target_priv_data
->flags
&
1502 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
1503 mpt2sas_config_get_volume_handle(ioc
,
1504 sas_device
->handle
, &sas_device
->volume_handle
);
1505 mpt2sas_config_get_volume_wwid(ioc
,
1506 sas_device
->volume_handle
,
1507 &sas_device
->volume_wwid
);
1509 if (sas_device
->device_info
& MPI2_SAS_DEVICE_INFO_SSP_TARGET
) {
1510 qdepth
= MPT2SAS_SAS_QUEUE_DEPTH
;
1514 qdepth
= MPT2SAS_SATA_QUEUE_DEPTH
;
1515 if (sas_device
->device_info
&
1516 MPI2_SAS_DEVICE_INFO_STP_TARGET
)
1518 else if (sas_device
->device_info
&
1519 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1523 sdev_printk(KERN_INFO
, sdev
, "%s: handle(0x%04x), "
1524 "sas_addr(0x%016llx), device_name(0x%016llx)\n",
1525 ds
, sas_device
->handle
,
1526 (unsigned long long)sas_device
->sas_address
,
1527 (unsigned long long)sas_device
->device_name
);
1528 sdev_printk(KERN_INFO
, sdev
, "%s: "
1529 "enclosure_logical_id(0x%016llx), slot(%d)\n", ds
,
1530 (unsigned long long) sas_device
->enclosure_logical_id
,
1534 _scsih_display_sata_capabilities(ioc
, sas_device
, sdev
);
1537 _scsih_change_queue_depth(sdev
, qdepth
);
1540 sas_read_port_mode_page(sdev
);
1545 * _scsih_bios_param - fetch head, sector, cylinder info for a disk
1546 * @sdev: scsi device struct
1547 * @bdev: pointer to block device context
1548 * @capacity: device size (in 512 byte sectors)
1549 * @params: three element array to place output:
1550 * params[0] number of heads (max 255)
1551 * params[1] number of sectors (max 63)
1552 * params[2] number of cylinders
1557 _scsih_bios_param(struct scsi_device
*sdev
, struct block_device
*bdev
,
1558 sector_t capacity
, int params
[])
1568 dummy
= heads
* sectors
;
1569 cylinders
= capacity
;
1570 sector_div(cylinders
, dummy
);
1573 * Handle extended translation size for logical drives
1576 if ((ulong
)capacity
>= 0x200000) {
1579 dummy
= heads
* sectors
;
1580 cylinders
= capacity
;
1581 sector_div(cylinders
, dummy
);
1586 params
[1] = sectors
;
1587 params
[2] = cylinders
;
1593 * _scsih_response_code - translation of device response code
1594 * @ioc: per adapter object
1595 * @response_code: response code returned by the device
1600 _scsih_response_code(struct MPT2SAS_ADAPTER
*ioc
, u8 response_code
)
1604 switch (response_code
) {
1605 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE
:
1606 desc
= "task management request completed";
1608 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
:
1609 desc
= "invalid frame";
1611 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED
:
1612 desc
= "task management request not supported";
1614 case MPI2_SCSITASKMGMT_RSP_TM_FAILED
:
1615 desc
= "task management request failed";
1617 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
:
1618 desc
= "task management request succeeded";
1620 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN
:
1621 desc
= "invalid lun";
1624 desc
= "overlapped tag attempted";
1626 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
:
1627 desc
= "task queued, however not sent to target";
1633 printk(MPT2SAS_WARN_FMT
"response_code(0x%01x): %s\n",
1634 ioc
->name
, response_code
, desc
);
1638 * _scsih_tm_done - tm completion routine
1639 * @ioc: per adapter object
1640 * @smid: system request message index
1641 * @msix_index: MSIX table index supplied by the OS
1642 * @reply: reply message frame(lower 32bit addr)
1645 * The callback handler when using scsih_issue_tm.
1647 * Return 1 meaning mf should be freed from _base_interrupt
1648 * 0 means the mf is freed from this function.
1651 _scsih_tm_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
1653 MPI2DefaultReply_t
*mpi_reply
;
1655 if (ioc
->tm_cmds
.status
== MPT2_CMD_NOT_USED
)
1657 if (ioc
->tm_cmds
.smid
!= smid
)
1659 ioc
->tm_cmds
.status
|= MPT2_CMD_COMPLETE
;
1660 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
1662 memcpy(ioc
->tm_cmds
.reply
, mpi_reply
, mpi_reply
->MsgLength
*4);
1663 ioc
->tm_cmds
.status
|= MPT2_CMD_REPLY_VALID
;
1665 ioc
->tm_cmds
.status
&= ~MPT2_CMD_PENDING
;
1666 complete(&ioc
->tm_cmds
.done
);
1671 * mpt2sas_scsih_set_tm_flag - set per target tm_busy
1672 * @ioc: per adapter object
1673 * @handle: device handle
1675 * During taskmangement request, we need to freeze the device queue.
1678 mpt2sas_scsih_set_tm_flag(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
1680 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1681 struct scsi_device
*sdev
;
1684 shost_for_each_device(sdev
, ioc
->shost
) {
1687 sas_device_priv_data
= sdev
->hostdata
;
1688 if (!sas_device_priv_data
)
1690 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
1691 sas_device_priv_data
->sas_target
->tm_busy
= 1;
1693 ioc
->ignore_loginfos
= 1;
1699 * mpt2sas_scsih_clear_tm_flag - clear per target tm_busy
1700 * @ioc: per adapter object
1701 * @handle: device handle
1703 * During taskmangement request, we need to freeze the device queue.
1706 mpt2sas_scsih_clear_tm_flag(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
1708 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1709 struct scsi_device
*sdev
;
1712 shost_for_each_device(sdev
, ioc
->shost
) {
1715 sas_device_priv_data
= sdev
->hostdata
;
1716 if (!sas_device_priv_data
)
1718 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
1719 sas_device_priv_data
->sas_target
->tm_busy
= 0;
1721 ioc
->ignore_loginfos
= 0;
1727 * mpt2sas_scsih_issue_tm - main routine for sending tm requests
1728 * @ioc: per adapter struct
1729 * @device_handle: device handle
1731 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
1732 * @smid_task: smid assigned to the task
1733 * @timeout: timeout in seconds
1734 * Context: The calling function needs to acquire the tm_cmds.mutex
1736 * A generic API for sending task management requests to firmware.
1738 * The ioc->tm_cmds.status flag should be MPT2_CMD_NOT_USED before calling
1741 * The callback index is set inside `ioc->tm_cb_idx`.
1746 mpt2sas_scsih_issue_tm(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
, uint lun
,
1747 u8 type
, u16 smid_task
, ulong timeout
)
1749 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
1750 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
1753 unsigned long timeleft
;
1755 if (ioc
->tm_cmds
.status
!= MPT2_CMD_NOT_USED
) {
1756 printk(MPT2SAS_INFO_FMT
"%s: tm_cmd busy!!!\n",
1757 __func__
, ioc
->name
);
1761 if (ioc
->shost_recovery
) {
1762 printk(MPT2SAS_INFO_FMT
"%s: host reset in progress!\n",
1763 __func__
, ioc
->name
);
1767 ioc_state
= mpt2sas_base_get_iocstate(ioc
, 0);
1768 if (ioc_state
& MPI2_DOORBELL_USED
) {
1769 dhsprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"unexpected doorbell "
1770 "active!\n", ioc
->name
));
1771 goto issue_host_reset
;
1774 if ((ioc_state
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_FAULT
) {
1775 mpt2sas_base_fault_info(ioc
, ioc_state
&
1776 MPI2_DOORBELL_DATA_MASK
);
1777 goto issue_host_reset
;
1780 smid
= mpt2sas_base_get_smid_hpr(ioc
, ioc
->tm_cb_idx
);
1782 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
1783 ioc
->name
, __func__
);
1787 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"sending tm: handle(0x%04x),"
1788 " task_type(0x%02x), smid(%d)\n", ioc
->name
, handle
, type
,
1790 ioc
->tm_cmds
.status
= MPT2_CMD_PENDING
;
1791 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
1792 ioc
->tm_cmds
.smid
= smid
;
1793 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
1794 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
1795 mpi_request
->DevHandle
= cpu_to_le16(handle
);
1796 mpi_request
->TaskType
= type
;
1797 mpi_request
->TaskMID
= cpu_to_le16(smid_task
);
1798 mpi_request
->VP_ID
= 0; /* TODO */
1799 mpi_request
->VF_ID
= 0;
1800 int_to_scsilun(lun
, (struct scsi_lun
*)mpi_request
->LUN
);
1801 mpt2sas_scsih_set_tm_flag(ioc
, handle
);
1802 init_completion(&ioc
->tm_cmds
.done
);
1803 mpt2sas_base_put_smid_hi_priority(ioc
, smid
);
1804 timeleft
= wait_for_completion_timeout(&ioc
->tm_cmds
.done
, timeout
*HZ
);
1805 mpt2sas_scsih_clear_tm_flag(ioc
, handle
);
1806 if (!(ioc
->tm_cmds
.status
& MPT2_CMD_COMPLETE
)) {
1807 printk(MPT2SAS_ERR_FMT
"%s: timeout\n",
1808 ioc
->name
, __func__
);
1809 _debug_dump_mf(mpi_request
,
1810 sizeof(Mpi2SCSITaskManagementRequest_t
)/4);
1811 if (!(ioc
->tm_cmds
.status
& MPT2_CMD_RESET
))
1812 goto issue_host_reset
;
1815 if (ioc
->tm_cmds
.status
& MPT2_CMD_REPLY_VALID
) {
1816 mpi_reply
= ioc
->tm_cmds
.reply
;
1817 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"complete tm: "
1818 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
1819 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
1820 le32_to_cpu(mpi_reply
->IOCLogInfo
),
1821 le32_to_cpu(mpi_reply
->TerminationCount
)));
1822 if (ioc
->logging_level
& MPT_DEBUG_TM
)
1823 _scsih_response_code(ioc
, mpi_reply
->ResponseCode
);
1827 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
, FORCE_BIG_HAMMER
);
1831 * _scsih_abort - eh threads main abort routine
1832 * @sdev: scsi device struct
1834 * Returns SUCCESS if command aborted else FAILED
1837 _scsih_abort(struct scsi_cmnd
*scmd
)
1839 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
1840 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1844 struct scsi_cmnd
*scmd_lookup
;
1846 printk(MPT2SAS_INFO_FMT
"attempting task abort! scmd(%p)\n",
1848 scsi_print_command(scmd
);
1850 sas_device_priv_data
= scmd
->device
->hostdata
;
1851 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
1852 printk(MPT2SAS_INFO_FMT
"device been deleted! scmd(%p)\n",
1854 scmd
->result
= DID_NO_CONNECT
<< 16;
1855 scmd
->scsi_done(scmd
);
1860 /* search for the command */
1861 smid
= _scsih_scsi_lookup_find_by_scmd(ioc
, scmd
);
1863 scmd
->result
= DID_RESET
<< 16;
1868 /* for hidden raid components and volumes this is not supported */
1869 if (sas_device_priv_data
->sas_target
->flags
&
1870 MPT_TARGET_FLAGS_RAID_COMPONENT
||
1871 sas_device_priv_data
->sas_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
1872 scmd
->result
= DID_RESET
<< 16;
1877 mutex_lock(&ioc
->tm_cmds
.mutex
);
1878 handle
= sas_device_priv_data
->sas_target
->handle
;
1879 mpt2sas_scsih_issue_tm(ioc
, handle
, sas_device_priv_data
->lun
,
1880 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
, smid
, 30);
1882 /* sanity check - see whether command actually completed */
1883 scmd_lookup
= _scsih_scsi_lookup_get(ioc
, smid
);
1884 if (scmd_lookup
&& (scmd_lookup
->serial_number
== scmd
->serial_number
))
1888 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
1889 mutex_unlock(&ioc
->tm_cmds
.mutex
);
1892 printk(MPT2SAS_INFO_FMT
"task abort: %s scmd(%p)\n",
1893 ioc
->name
, ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
1898 * _scsih_dev_reset - eh threads main device reset routine
1899 * @sdev: scsi device struct
1901 * Returns SUCCESS if command aborted else FAILED
1904 _scsih_dev_reset(struct scsi_cmnd
*scmd
)
1906 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
1907 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1908 struct _sas_device
*sas_device
;
1909 unsigned long flags
;
1913 printk(MPT2SAS_INFO_FMT
"attempting device reset! scmd(%p)\n",
1915 scsi_print_command(scmd
);
1917 sas_device_priv_data
= scmd
->device
->hostdata
;
1918 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
1919 printk(MPT2SAS_INFO_FMT
"device been deleted! scmd(%p)\n",
1921 scmd
->result
= DID_NO_CONNECT
<< 16;
1922 scmd
->scsi_done(scmd
);
1927 /* for hidden raid components obtain the volume_handle */
1929 if (sas_device_priv_data
->sas_target
->flags
&
1930 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
1931 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1932 sas_device
= _scsih_sas_device_find_by_handle(ioc
,
1933 sas_device_priv_data
->sas_target
->handle
);
1935 handle
= sas_device
->volume_handle
;
1936 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1938 handle
= sas_device_priv_data
->sas_target
->handle
;
1941 scmd
->result
= DID_RESET
<< 16;
1946 mutex_lock(&ioc
->tm_cmds
.mutex
);
1947 mpt2sas_scsih_issue_tm(ioc
, handle
, 0,
1948 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET
, scmd
->device
->lun
,
1952 * sanity check see whether all commands to this device been
1955 if (_scsih_scsi_lookup_find_by_lun(ioc
, scmd
->device
->id
,
1956 scmd
->device
->lun
, scmd
->device
->channel
))
1960 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
1961 mutex_unlock(&ioc
->tm_cmds
.mutex
);
1964 printk(MPT2SAS_INFO_FMT
"device reset: %s scmd(%p)\n",
1965 ioc
->name
, ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
1970 * _scsih_target_reset - eh threads main target reset routine
1971 * @sdev: scsi device struct
1973 * Returns SUCCESS if command aborted else FAILED
1976 _scsih_target_reset(struct scsi_cmnd
*scmd
)
1978 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
1979 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1980 struct _sas_device
*sas_device
;
1981 unsigned long flags
;
1985 printk(MPT2SAS_INFO_FMT
"attempting target reset! scmd(%p)\n",
1987 scsi_print_command(scmd
);
1989 sas_device_priv_data
= scmd
->device
->hostdata
;
1990 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
1991 printk(MPT2SAS_INFO_FMT
"target been deleted! scmd(%p)\n",
1993 scmd
->result
= DID_NO_CONNECT
<< 16;
1994 scmd
->scsi_done(scmd
);
1999 /* for hidden raid components obtain the volume_handle */
2001 if (sas_device_priv_data
->sas_target
->flags
&
2002 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2003 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2004 sas_device
= _scsih_sas_device_find_by_handle(ioc
,
2005 sas_device_priv_data
->sas_target
->handle
);
2007 handle
= sas_device
->volume_handle
;
2008 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2010 handle
= sas_device_priv_data
->sas_target
->handle
;
2013 scmd
->result
= DID_RESET
<< 16;
2018 mutex_lock(&ioc
->tm_cmds
.mutex
);
2019 mpt2sas_scsih_issue_tm(ioc
, handle
, 0,
2020 MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
, 0, 30);
2023 * sanity check see whether all commands to this target been
2026 if (_scsih_scsi_lookup_find_by_target(ioc
, scmd
->device
->id
,
2027 scmd
->device
->channel
))
2031 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
2032 mutex_unlock(&ioc
->tm_cmds
.mutex
);
2035 printk(MPT2SAS_INFO_FMT
"target reset: %s scmd(%p)\n",
2036 ioc
->name
, ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2041 * _scsih_host_reset - eh threads main host reset routine
2042 * @sdev: scsi device struct
2044 * Returns SUCCESS if command aborted else FAILED
2047 _scsih_host_reset(struct scsi_cmnd
*scmd
)
2049 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2052 printk(MPT2SAS_INFO_FMT
"attempting host reset! scmd(%p)\n",
2054 scsi_print_command(scmd
);
2056 retval
= mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2058 r
= (retval
< 0) ? FAILED
: SUCCESS
;
2059 printk(MPT2SAS_INFO_FMT
"host reset: %s scmd(%p)\n",
2060 ioc
->name
, ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2066 * _scsih_fw_event_add - insert and queue up fw_event
2067 * @ioc: per adapter object
2068 * @fw_event: object describing the event
2069 * Context: This function will acquire ioc->fw_event_lock.
2071 * This adds the firmware event object into link list, then queues it up to
2072 * be processed from user context.
2077 _scsih_fw_event_add(struct MPT2SAS_ADAPTER
*ioc
, struct fw_event_work
*fw_event
)
2079 unsigned long flags
;
2081 if (ioc
->firmware_event_thread
== NULL
)
2084 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2085 list_add_tail(&fw_event
->list
, &ioc
->fw_event_list
);
2086 INIT_WORK(&fw_event
->work
, _firmware_event_work
);
2087 queue_work(ioc
->firmware_event_thread
, &fw_event
->work
);
2088 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2092 * _scsih_fw_event_free - delete fw_event
2093 * @ioc: per adapter object
2094 * @fw_event: object describing the event
2095 * Context: This function will acquire ioc->fw_event_lock.
2097 * This removes firmware event object from link list, frees associated memory.
2102 _scsih_fw_event_free(struct MPT2SAS_ADAPTER
*ioc
, struct fw_event_work
2105 unsigned long flags
;
2107 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2108 list_del(&fw_event
->list
);
2109 kfree(fw_event
->event_data
);
2111 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2115 * _scsih_fw_event_add - requeue an event
2116 * @ioc: per adapter object
2117 * @fw_event: object describing the event
2118 * Context: This function will acquire ioc->fw_event_lock.
2123 _scsih_fw_event_requeue(struct MPT2SAS_ADAPTER
*ioc
, struct fw_event_work
2124 *fw_event
, unsigned long delay
)
2126 unsigned long flags
;
2127 if (ioc
->firmware_event_thread
== NULL
)
2130 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2131 queue_work(ioc
->firmware_event_thread
, &fw_event
->work
);
2132 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2136 * _scsih_fw_event_off - turn flag off preventing event handling
2137 * @ioc: per adapter object
2139 * Used to prevent handling of firmware events during adapter reset
2145 _scsih_fw_event_off(struct MPT2SAS_ADAPTER
*ioc
)
2147 unsigned long flags
;
2149 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2150 ioc
->fw_events_off
= 1;
2151 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2156 * _scsih_fw_event_on - turn flag on allowing firmware event handling
2157 * @ioc: per adapter object
2162 _scsih_fw_event_on(struct MPT2SAS_ADAPTER
*ioc
)
2164 unsigned long flags
;
2166 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2167 ioc
->fw_events_off
= 0;
2168 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2172 * _scsih_ublock_io_device - set the device state to SDEV_RUNNING
2173 * @ioc: per adapter object
2174 * @handle: device handle
2176 * During device pull we need to appropiately set the sdev state.
2179 _scsih_ublock_io_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
2181 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2182 struct scsi_device
*sdev
;
2184 shost_for_each_device(sdev
, ioc
->shost
) {
2185 sas_device_priv_data
= sdev
->hostdata
;
2186 if (!sas_device_priv_data
)
2188 if (!sas_device_priv_data
->block
)
2190 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2191 dewtprintk(ioc
, sdev_printk(KERN_INFO
, sdev
,
2192 MPT2SAS_INFO_FMT
"SDEV_RUNNING: "
2193 "handle(0x%04x)\n", ioc
->name
, handle
));
2194 sas_device_priv_data
->block
= 0;
2195 scsi_internal_device_unblock(sdev
);
2201 * _scsih_block_io_device - set the device state to SDEV_BLOCK
2202 * @ioc: per adapter object
2203 * @handle: device handle
2205 * During device pull we need to appropiately set the sdev state.
2208 _scsih_block_io_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
2210 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2211 struct scsi_device
*sdev
;
2213 shost_for_each_device(sdev
, ioc
->shost
) {
2214 sas_device_priv_data
= sdev
->hostdata
;
2215 if (!sas_device_priv_data
)
2217 if (sas_device_priv_data
->block
)
2219 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2220 dewtprintk(ioc
, sdev_printk(KERN_INFO
, sdev
,
2221 MPT2SAS_INFO_FMT
"SDEV_BLOCK: "
2222 "handle(0x%04x)\n", ioc
->name
, handle
));
2223 sas_device_priv_data
->block
= 1;
2224 scsi_internal_device_block(sdev
);
2230 * _scsih_block_io_to_children_attached_to_ex
2231 * @ioc: per adapter object
2232 * @sas_expander: the sas_device object
2234 * This routine set sdev state to SDEV_BLOCK for all devices
2235 * attached to this expander. This function called when expander is
2239 _scsih_block_io_to_children_attached_to_ex(struct MPT2SAS_ADAPTER
*ioc
,
2240 struct _sas_node
*sas_expander
)
2242 struct _sas_port
*mpt2sas_port
;
2243 struct _sas_device
*sas_device
;
2244 struct _sas_node
*expander_sibling
;
2245 unsigned long flags
;
2250 list_for_each_entry(mpt2sas_port
,
2251 &sas_expander
->sas_port_list
, port_list
) {
2252 if (mpt2sas_port
->remote_identify
.device_type
==
2254 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2256 mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
2257 mpt2sas_port
->remote_identify
.sas_address
);
2258 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2261 _scsih_block_io_device(ioc
, sas_device
->handle
);
2265 list_for_each_entry(mpt2sas_port
,
2266 &sas_expander
->sas_port_list
, port_list
) {
2268 if (mpt2sas_port
->remote_identify
.device_type
==
2269 MPI2_SAS_DEVICE_INFO_EDGE_EXPANDER
||
2270 mpt2sas_port
->remote_identify
.device_type
==
2271 MPI2_SAS_DEVICE_INFO_FANOUT_EXPANDER
) {
2273 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
2275 mpt2sas_scsih_expander_find_by_sas_address(
2276 ioc
, mpt2sas_port
->remote_identify
.sas_address
);
2277 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
2278 _scsih_block_io_to_children_attached_to_ex(ioc
,
2285 * _scsih_block_io_to_children_attached_directly
2286 * @ioc: per adapter object
2287 * @event_data: topology change event data
2289 * This routine set sdev state to SDEV_BLOCK for all devices
2290 * direct attached during device pull.
2293 _scsih_block_io_to_children_attached_directly(struct MPT2SAS_ADAPTER
*ioc
,
2294 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
2302 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
2303 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
2306 phy_number
= event_data
->StartPhyNum
+ i
;
2307 reason_code
= event_data
->PHY
[i
].PhyStatus
&
2308 MPI2_EVENT_SAS_TOPO_RC_MASK
;
2309 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
)
2310 _scsih_block_io_device(ioc
, handle
);
2311 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
) {
2312 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
2313 if (link_rate
>= MPI2_SAS_NEG_LINK_RATE_1_5
)
2314 _scsih_ublock_io_device(ioc
, handle
);
2320 * _scsih_tm_tr_send - send task management request
2321 * @ioc: per adapter object
2322 * @handle: device handle
2323 * Context: interrupt time.
2325 * This code is to initiate the device removal handshake protocal
2326 * with controller firmware. This function will issue target reset
2327 * using high priority request queue. It will send a sas iounit
2328 * controll request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
2330 * This is designed to send muliple task management request at the same
2331 * time to the fifo. If the fifo is full, we will append the request,
2332 * and process it in a future completion.
2335 _scsih_tm_tr_send(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
2337 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
2338 struct MPT2SAS_TARGET
*sas_target_priv_data
;
2340 struct _sas_device
*sas_device
;
2341 unsigned long flags
;
2342 struct _tr_list
*delayed_tr
;
2344 if (ioc
->shost_recovery
) {
2345 printk(MPT2SAS_INFO_FMT
"%s: host reset in progress!\n",
2346 __func__
, ioc
->name
);
2350 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2351 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
2353 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2354 printk(MPT2SAS_ERR_FMT
"%s: failed finding sas_device\n",
2355 ioc
->name
, __func__
);
2358 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2360 /* skip is hidden raid component */
2361 if (sas_device
->hidden_raid_component
)
2364 smid
= mpt2sas_base_get_smid_hpr(ioc
, ioc
->tm_tr_cb_idx
);
2366 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
2369 INIT_LIST_HEAD(&delayed_tr
->list
);
2370 delayed_tr
->handle
= handle
;
2371 delayed_tr
->state
= MPT2SAS_REQ_SAS_CNTRL
;
2372 list_add_tail(&delayed_tr
->list
,
2373 &ioc
->delayed_tr_list
);
2374 if (sas_device
->starget
)
2375 dewtprintk(ioc
, starget_printk(KERN_INFO
,
2376 sas_device
->starget
, "DELAYED:tr:handle(0x%04x), "
2377 "(open)\n", sas_device
->handle
));
2381 if (sas_device
->starget
&& sas_device
->starget
->hostdata
) {
2382 sas_target_priv_data
= sas_device
->starget
->hostdata
;
2383 sas_target_priv_data
->tm_busy
= 1;
2384 dewtprintk(ioc
, starget_printk(KERN_INFO
, sas_device
->starget
,
2385 "tr:handle(0x%04x), (open)\n", sas_device
->handle
));
2388 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
2389 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
2390 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
2391 mpi_request
->DevHandle
= cpu_to_le16(handle
);
2392 mpi_request
->TaskType
= MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
;
2393 sas_device
->state
|= MPTSAS_STATE_TR_SEND
;
2394 sas_device
->state
|= MPT2SAS_REQ_SAS_CNTRL
;
2395 mpt2sas_base_put_smid_hi_priority(ioc
, smid
);
2401 * _scsih_sas_control_complete - completion routine
2402 * @ioc: per adapter object
2403 * @smid: system request message index
2404 * @msix_index: MSIX table index supplied by the OS
2405 * @reply: reply message frame(lower 32bit addr)
2406 * Context: interrupt time.
2408 * This is the sas iounit controll completion routine.
2409 * This code is part of the code to initiate the device removal
2410 * handshake protocal with controller firmware.
2412 * Return 1 meaning mf should be freed from _base_interrupt
2413 * 0 means the mf is freed from this function.
2416 _scsih_sas_control_complete(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
,
2417 u8 msix_index
, u32 reply
)
2419 unsigned long flags
;
2421 struct _sas_device
*sas_device
;
2422 Mpi2SasIoUnitControlReply_t
*mpi_reply
=
2423 mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
2425 handle
= le16_to_cpu(mpi_reply
->DevHandle
);
2427 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2428 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
2430 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2431 printk(MPT2SAS_ERR_FMT
"%s: failed finding sas_device\n",
2432 ioc
->name
, __func__
);
2435 sas_device
->state
|= MPTSAS_STATE_CNTRL_COMPLETE
;
2436 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2438 if (sas_device
->starget
)
2439 dewtprintk(ioc
, starget_printk(KERN_INFO
, sas_device
->starget
,
2440 "sc_complete:handle(0x%04x), "
2441 "ioc_status(0x%04x), loginfo(0x%08x)\n",
2442 handle
, le16_to_cpu(mpi_reply
->IOCStatus
),
2443 le32_to_cpu(mpi_reply
->IOCLogInfo
)));
2448 * _scsih_tm_tr_complete -
2449 * @ioc: per adapter object
2450 * @smid: system request message index
2451 * @msix_index: MSIX table index supplied by the OS
2452 * @reply: reply message frame(lower 32bit addr)
2453 * Context: interrupt time.
2455 * This is the target reset completion routine.
2456 * This code is part of the code to initiate the device removal
2457 * handshake protocal with controller firmware.
2458 * It will send a sas iounit controll request (MPI2_SAS_OP_REMOVE_DEVICE)
2460 * Return 1 meaning mf should be freed from _base_interrupt
2461 * 0 means the mf is freed from this function.
2464 _scsih_tm_tr_complete(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
,
2467 unsigned long flags
;
2469 struct _sas_device
*sas_device
;
2470 Mpi2SCSITaskManagementReply_t
*mpi_reply
=
2471 mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
2472 Mpi2SasIoUnitControlRequest_t
*mpi_request
;
2474 struct MPT2SAS_TARGET
*sas_target_priv_data
;
2475 struct _tr_list
*delayed_tr
;
2478 handle
= le16_to_cpu(mpi_reply
->DevHandle
);
2479 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2480 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
2482 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2483 printk(MPT2SAS_ERR_FMT
"%s: failed finding sas_device\n",
2484 ioc
->name
, __func__
);
2487 sas_device
->state
|= MPTSAS_STATE_TR_COMPLETE
;
2488 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2490 if (sas_device
->starget
)
2491 dewtprintk(ioc
, starget_printk(KERN_INFO
, sas_device
->starget
,
2492 "tr_complete:handle(0x%04x), (%s) ioc_status(0x%04x), "
2493 "loginfo(0x%08x), completed(%d)\n",
2494 sas_device
->handle
, (sas_device
->state
&
2495 MPT2SAS_REQ_SAS_CNTRL
) ? "open" : "active",
2496 le16_to_cpu(mpi_reply
->IOCStatus
),
2497 le32_to_cpu(mpi_reply
->IOCLogInfo
),
2498 le32_to_cpu(mpi_reply
->TerminationCount
)));
2500 if (sas_device
->starget
&& sas_device
->starget
->hostdata
) {
2501 sas_target_priv_data
= sas_device
->starget
->hostdata
;
2502 sas_target_priv_data
->tm_busy
= 0;
2505 if (!list_empty(&ioc
->delayed_tr_list
)) {
2506 delayed_tr
= list_entry(ioc
->delayed_tr_list
.next
,
2507 struct _tr_list
, list
);
2508 mpt2sas_base_free_smid(ioc
, smid
);
2509 if (delayed_tr
->state
& MPT2SAS_REQ_SAS_CNTRL
)
2510 _scsih_tm_tr_send(ioc
, delayed_tr
->handle
);
2511 list_del(&delayed_tr
->list
);
2513 rc
= 0; /* tells base_interrupt not to free mf */
2518 if (!(sas_device
->state
& MPT2SAS_REQ_SAS_CNTRL
))
2521 if (ioc
->shost_recovery
) {
2522 printk(MPT2SAS_INFO_FMT
"%s: host reset in progress!\n",
2523 __func__
, ioc
->name
);
2527 smid_sas_ctrl
= mpt2sas_base_get_smid(ioc
, ioc
->tm_sas_control_cb_idx
);
2528 if (!smid_sas_ctrl
) {
2529 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
2530 ioc
->name
, __func__
);
2534 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid_sas_ctrl
);
2535 memset(mpi_request
, 0, sizeof(Mpi2SasIoUnitControlRequest_t
));
2536 mpi_request
->Function
= MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
;
2537 mpi_request
->Operation
= MPI2_SAS_OP_REMOVE_DEVICE
;
2538 mpi_request
->DevHandle
= mpi_reply
->DevHandle
;
2539 sas_device
->state
|= MPTSAS_STATE_CNTRL_SEND
;
2540 mpt2sas_base_put_smid_default(ioc
, smid_sas_ctrl
);
2545 * _scsih_check_topo_delete_events - sanity check on topo events
2546 * @ioc: per adapter object
2547 * @event_data: the event data payload
2549 * This routine added to better handle cable breaker.
2551 * This handles the case where driver recieves multiple expander
2552 * add and delete events in a single shot. When there is a delete event
2553 * the routine will void any pending add events waiting in the event queue.
2558 _scsih_check_topo_delete_events(struct MPT2SAS_ADAPTER
*ioc
,
2559 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
2561 struct fw_event_work
*fw_event
;
2562 Mpi2EventDataSasTopologyChangeList_t
*local_event_data
;
2563 u16 expander_handle
;
2564 struct _sas_node
*sas_expander
;
2565 unsigned long flags
;
2569 for (i
= 0 ; i
< event_data
->NumEntries
; i
++) {
2570 if (event_data
->PHY
[i
].PhyStatus
&
2571 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT
)
2573 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
2576 reason_code
= event_data
->PHY
[i
].PhyStatus
&
2577 MPI2_EVENT_SAS_TOPO_RC_MASK
;
2578 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
)
2579 _scsih_tm_tr_send(ioc
, handle
);
2582 expander_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
2583 if (expander_handle
< ioc
->sas_hba
.num_phys
) {
2584 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
2588 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
2589 || event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
) {
2590 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
2591 sas_expander
= mpt2sas_scsih_expander_find_by_handle(ioc
,
2593 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
2594 _scsih_block_io_to_children_attached_to_ex(ioc
, sas_expander
);
2595 } else if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_RESPONDING
)
2596 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
2598 if (event_data
->ExpStatus
!= MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
)
2601 /* mark ignore flag for pending events */
2602 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2603 list_for_each_entry(fw_event
, &ioc
->fw_event_list
, list
) {
2604 if (fw_event
->event
!= MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
||
2607 local_event_data
= fw_event
->event_data
;
2608 if (local_event_data
->ExpStatus
==
2609 MPI2_EVENT_SAS_TOPO_ES_ADDED
||
2610 local_event_data
->ExpStatus
==
2611 MPI2_EVENT_SAS_TOPO_ES_RESPONDING
) {
2612 if (le16_to_cpu(local_event_data
->ExpanderDevHandle
) ==
2614 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
2615 "setting ignoring flag\n", ioc
->name
));
2616 fw_event
->ignore
= 1;
2620 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2624 * _scsih_flush_running_cmds - completing outstanding commands.
2625 * @ioc: per adapter object
2627 * The flushing out of all pending scmd commands following host reset,
2628 * where all IO is dropped to the floor.
2633 _scsih_flush_running_cmds(struct MPT2SAS_ADAPTER
*ioc
)
2635 struct scsi_cmnd
*scmd
;
2639 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
2640 scmd
= _scsih_scsi_lookup_get(ioc
, smid
);
2644 mpt2sas_base_free_smid(ioc
, smid
);
2645 scsi_dma_unmap(scmd
);
2646 scmd
->result
= DID_RESET
<< 16;
2647 scmd
->scsi_done(scmd
);
2649 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"completing %d cmds\n",
2654 * _scsih_setup_eedp - setup MPI request for EEDP transfer
2655 * @scmd: pointer to scsi command object
2656 * @mpi_request: pointer to the SCSI_IO reqest message frame
2658 * Supporting protection 1 and 3.
2663 _scsih_setup_eedp(struct scsi_cmnd
*scmd
, Mpi2SCSIIORequest_t
*mpi_request
)
2666 unsigned char prot_op
= scsi_get_prot_op(scmd
);
2667 unsigned char prot_type
= scsi_get_prot_type(scmd
);
2669 if (prot_type
== SCSI_PROT_DIF_TYPE0
||
2670 prot_type
== SCSI_PROT_DIF_TYPE2
||
2671 prot_op
== SCSI_PROT_NORMAL
)
2674 if (prot_op
== SCSI_PROT_READ_STRIP
)
2675 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP
;
2676 else if (prot_op
== SCSI_PROT_WRITE_INSERT
)
2677 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_INSERT_OP
;
2681 mpi_request
->EEDPBlockSize
= scmd
->device
->sector_size
;
2683 switch (prot_type
) {
2684 case SCSI_PROT_DIF_TYPE1
:
2687 * enable ref/guard checking
2688 * auto increment ref tag
2690 mpi_request
->EEDPFlags
= eedp_flags
|
2691 MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG
|
2692 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG
|
2693 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
2694 mpi_request
->CDB
.EEDP32
.PrimaryReferenceTag
=
2695 cpu_to_be32(scsi_get_lba(scmd
));
2699 case SCSI_PROT_DIF_TYPE3
:
2702 * enable guard checking
2704 mpi_request
->EEDPFlags
= eedp_flags
|
2705 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
2712 * _scsih_eedp_error_handling - return sense code for EEDP errors
2713 * @scmd: pointer to scsi command object
2714 * @ioc_status: ioc status
2719 _scsih_eedp_error_handling(struct scsi_cmnd
*scmd
, u16 ioc_status
)
2725 switch (ioc_status
) {
2726 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
2729 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
2732 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
2740 if (scmd
->sc_data_direction
== DMA_TO_DEVICE
) {
2741 sk
= ILLEGAL_REQUEST
;
2742 host_byte
= DID_ABORT
;
2744 sk
= ABORTED_COMMAND
;
2748 scsi_build_sense_buffer(0, scmd
->sense_buffer
, sk
, 0x10, ascq
);
2749 scmd
->result
= DRIVER_SENSE
<< 24 | (host_byte
<< 16) |
2750 SAM_STAT_CHECK_CONDITION
;
2754 * _scsih_qcmd - main scsi request entry point
2755 * @scmd: pointer to scsi command object
2756 * @done: function pointer to be invoked on completion
2758 * The callback index is set inside `ioc->scsi_io_cb_idx`.
2760 * Returns 0 on success. If there's a failure, return either:
2761 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
2762 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
2765 _scsih_qcmd(struct scsi_cmnd
*scmd
, void (*done
)(struct scsi_cmnd
*))
2767 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2768 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2769 struct MPT2SAS_TARGET
*sas_target_priv_data
;
2770 Mpi2SCSIIORequest_t
*mpi_request
;
2774 scmd
->scsi_done
= done
;
2775 sas_device_priv_data
= scmd
->device
->hostdata
;
2776 if (!sas_device_priv_data
) {
2777 scmd
->result
= DID_NO_CONNECT
<< 16;
2778 scmd
->scsi_done(scmd
);
2782 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
2783 if (!sas_target_priv_data
|| sas_target_priv_data
->handle
==
2784 MPT2SAS_INVALID_DEVICE_HANDLE
|| sas_target_priv_data
->deleted
) {
2785 scmd
->result
= DID_NO_CONNECT
<< 16;
2786 scmd
->scsi_done(scmd
);
2790 /* see if we are busy with task managment stuff */
2791 if (sas_target_priv_data
->tm_busy
)
2792 return SCSI_MLQUEUE_DEVICE_BUSY
;
2793 else if (ioc
->shost_recovery
|| ioc
->ioc_link_reset_in_progress
)
2794 return SCSI_MLQUEUE_HOST_BUSY
;
2796 if (scmd
->sc_data_direction
== DMA_FROM_DEVICE
)
2797 mpi_control
= MPI2_SCSIIO_CONTROL_READ
;
2798 else if (scmd
->sc_data_direction
== DMA_TO_DEVICE
)
2799 mpi_control
= MPI2_SCSIIO_CONTROL_WRITE
;
2801 mpi_control
= MPI2_SCSIIO_CONTROL_NODATATRANSFER
;
2804 if (!(sas_device_priv_data
->flags
& MPT_DEVICE_FLAGS_INIT
)) {
2805 if (scmd
->device
->tagged_supported
) {
2806 if (scmd
->device
->ordered_tags
)
2807 mpi_control
|= MPI2_SCSIIO_CONTROL_ORDEREDQ
;
2809 mpi_control
|= MPI2_SCSIIO_CONTROL_SIMPLEQ
;
2811 /* MPI Revision I (UNIT = 0xA) - removed MPI2_SCSIIO_CONTROL_UNTAGGED */
2812 /* mpi_control |= MPI2_SCSIIO_CONTROL_UNTAGGED;
2814 mpi_control
|= (0x500);
2817 mpi_control
|= MPI2_SCSIIO_CONTROL_SIMPLEQ
;
2819 if ((sas_device_priv_data
->flags
& MPT_DEVICE_TLR_ON
))
2820 mpi_control
|= MPI2_SCSIIO_CONTROL_TLR_ON
;
2822 smid
= mpt2sas_base_get_smid_scsiio(ioc
, ioc
->scsi_io_cb_idx
, scmd
);
2824 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
2825 ioc
->name
, __func__
);
2828 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
2829 memset(mpi_request
, 0, sizeof(Mpi2SCSIIORequest_t
));
2830 _scsih_setup_eedp(scmd
, mpi_request
);
2831 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
2832 if (sas_device_priv_data
->sas_target
->flags
&
2833 MPT_TARGET_FLAGS_RAID_COMPONENT
)
2834 mpi_request
->Function
= MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
;
2836 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
2837 mpi_request
->DevHandle
=
2838 cpu_to_le16(sas_device_priv_data
->sas_target
->handle
);
2839 mpi_request
->DataLength
= cpu_to_le32(scsi_bufflen(scmd
));
2840 mpi_request
->Control
= cpu_to_le32(mpi_control
);
2841 mpi_request
->IoFlags
= cpu_to_le16(scmd
->cmd_len
);
2842 mpi_request
->MsgFlags
= MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR
;
2843 mpi_request
->SenseBufferLength
= SCSI_SENSE_BUFFERSIZE
;
2844 mpi_request
->SenseBufferLowAddress
=
2845 (u32
)mpt2sas_base_get_sense_buffer_dma(ioc
, smid
);
2846 mpi_request
->SGLOffset0
= offsetof(Mpi2SCSIIORequest_t
, SGL
) / 4;
2847 mpi_request
->SGLFlags
= cpu_to_le16(MPI2_SCSIIO_SGLFLAGS_TYPE_MPI
+
2848 MPI2_SCSIIO_SGLFLAGS_SYSTEM_ADDR
);
2849 mpi_request
->VF_ID
= 0; /* TODO */
2850 mpi_request
->VP_ID
= 0;
2851 int_to_scsilun(sas_device_priv_data
->lun
, (struct scsi_lun
*)
2853 memcpy(mpi_request
->CDB
.CDB32
, scmd
->cmnd
, scmd
->cmd_len
);
2855 if (!mpi_request
->DataLength
) {
2856 mpt2sas_base_build_zero_len_sge(ioc
, &mpi_request
->SGL
);
2858 if (_scsih_build_scatter_gather(ioc
, scmd
, smid
)) {
2859 mpt2sas_base_free_smid(ioc
, smid
);
2864 mpt2sas_base_put_smid_scsi_io(ioc
, smid
,
2865 sas_device_priv_data
->sas_target
->handle
);
2869 return SCSI_MLQUEUE_HOST_BUSY
;
2873 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
2874 * @sense_buffer: sense data returned by target
2875 * @data: normalized skey/asc/ascq
2880 _scsih_normalize_sense(char *sense_buffer
, struct sense_info
*data
)
2882 if ((sense_buffer
[0] & 0x7F) >= 0x72) {
2883 /* descriptor format */
2884 data
->skey
= sense_buffer
[1] & 0x0F;
2885 data
->asc
= sense_buffer
[2];
2886 data
->ascq
= sense_buffer
[3];
2889 data
->skey
= sense_buffer
[2] & 0x0F;
2890 data
->asc
= sense_buffer
[12];
2891 data
->ascq
= sense_buffer
[13];
2895 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
2897 * _scsih_scsi_ioc_info - translated non-succesfull SCSI_IO request
2898 * @ioc: per adapter object
2899 * @scmd: pointer to scsi command object
2900 * @mpi_reply: reply mf payload returned from firmware
2902 * scsi_status - SCSI Status code returned from target device
2903 * scsi_state - state info associated with SCSI_IO determined by ioc
2904 * ioc_status - ioc supplied status info
2909 _scsih_scsi_ioc_info(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
,
2910 Mpi2SCSIIOReply_t
*mpi_reply
, u16 smid
)
2914 u16 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) &
2915 MPI2_IOCSTATUS_MASK
;
2916 u8 scsi_state
= mpi_reply
->SCSIState
;
2917 u8 scsi_status
= mpi_reply
->SCSIStatus
;
2918 char *desc_ioc_state
= NULL
;
2919 char *desc_scsi_status
= NULL
;
2920 char *desc_scsi_state
= ioc
->tmp_string
;
2921 u32 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
2923 if (log_info
== 0x31170000)
2926 switch (ioc_status
) {
2927 case MPI2_IOCSTATUS_SUCCESS
:
2928 desc_ioc_state
= "success";
2930 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
2931 desc_ioc_state
= "invalid function";
2933 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
2934 desc_ioc_state
= "scsi recovered error";
2936 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE
:
2937 desc_ioc_state
= "scsi invalid dev handle";
2939 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
2940 desc_ioc_state
= "scsi device not there";
2942 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
2943 desc_ioc_state
= "scsi data overrun";
2945 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
2946 desc_ioc_state
= "scsi data underrun";
2948 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
2949 desc_ioc_state
= "scsi io data error";
2951 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
2952 desc_ioc_state
= "scsi protocol error";
2954 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
2955 desc_ioc_state
= "scsi task terminated";
2957 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
2958 desc_ioc_state
= "scsi residual mismatch";
2960 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
2961 desc_ioc_state
= "scsi task mgmt failed";
2963 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
2964 desc_ioc_state
= "scsi ioc terminated";
2966 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
2967 desc_ioc_state
= "scsi ext terminated";
2969 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
2970 desc_ioc_state
= "eedp guard error";
2972 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
2973 desc_ioc_state
= "eedp ref tag error";
2975 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
2976 desc_ioc_state
= "eedp app tag error";
2979 desc_ioc_state
= "unknown";
2983 switch (scsi_status
) {
2984 case MPI2_SCSI_STATUS_GOOD
:
2985 desc_scsi_status
= "good";
2987 case MPI2_SCSI_STATUS_CHECK_CONDITION
:
2988 desc_scsi_status
= "check condition";
2990 case MPI2_SCSI_STATUS_CONDITION_MET
:
2991 desc_scsi_status
= "condition met";
2993 case MPI2_SCSI_STATUS_BUSY
:
2994 desc_scsi_status
= "busy";
2996 case MPI2_SCSI_STATUS_INTERMEDIATE
:
2997 desc_scsi_status
= "intermediate";
2999 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET
:
3000 desc_scsi_status
= "intermediate condmet";
3002 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT
:
3003 desc_scsi_status
= "reservation conflict";
3005 case MPI2_SCSI_STATUS_COMMAND_TERMINATED
:
3006 desc_scsi_status
= "command terminated";
3008 case MPI2_SCSI_STATUS_TASK_SET_FULL
:
3009 desc_scsi_status
= "task set full";
3011 case MPI2_SCSI_STATUS_ACA_ACTIVE
:
3012 desc_scsi_status
= "aca active";
3014 case MPI2_SCSI_STATUS_TASK_ABORTED
:
3015 desc_scsi_status
= "task aborted";
3018 desc_scsi_status
= "unknown";
3022 desc_scsi_state
[0] = '\0';
3024 desc_scsi_state
= " ";
3025 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
3026 strcat(desc_scsi_state
, "response info ");
3027 if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
3028 strcat(desc_scsi_state
, "state terminated ");
3029 if (scsi_state
& MPI2_SCSI_STATE_NO_SCSI_STATUS
)
3030 strcat(desc_scsi_state
, "no status ");
3031 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_FAILED
)
3032 strcat(desc_scsi_state
, "autosense failed ");
3033 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
)
3034 strcat(desc_scsi_state
, "autosense valid ");
3036 scsi_print_command(scmd
);
3037 printk(MPT2SAS_WARN_FMT
"\tdev handle(0x%04x), "
3038 "ioc_status(%s)(0x%04x), smid(%d)\n", ioc
->name
,
3039 le16_to_cpu(mpi_reply
->DevHandle
), desc_ioc_state
,
3041 printk(MPT2SAS_WARN_FMT
"\trequest_len(%d), underflow(%d), "
3042 "resid(%d)\n", ioc
->name
, scsi_bufflen(scmd
), scmd
->underflow
,
3043 scsi_get_resid(scmd
));
3044 printk(MPT2SAS_WARN_FMT
"\ttag(%d), transfer_count(%d), "
3045 "sc->result(0x%08x)\n", ioc
->name
, le16_to_cpu(mpi_reply
->TaskTag
),
3046 le32_to_cpu(mpi_reply
->TransferCount
), scmd
->result
);
3047 printk(MPT2SAS_WARN_FMT
"\tscsi_status(%s)(0x%02x), "
3048 "scsi_state(%s)(0x%02x)\n", ioc
->name
, desc_scsi_status
,
3049 scsi_status
, desc_scsi_state
, scsi_state
);
3051 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
3052 struct sense_info data
;
3053 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
3054 printk(MPT2SAS_WARN_FMT
"\t[sense_key,asc,ascq]: "
3055 "[0x%02x,0x%02x,0x%02x]\n", ioc
->name
, data
.skey
,
3056 data
.asc
, data
.ascq
);
3059 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
) {
3060 response_info
= le32_to_cpu(mpi_reply
->ResponseInfo
);
3061 response_bytes
= (u8
*)&response_info
;
3062 _scsih_response_code(ioc
, response_bytes
[3]);
3068 * _scsih_smart_predicted_fault - illuminate Fault LED
3069 * @ioc: per adapter object
3070 * @handle: device handle
3075 _scsih_smart_predicted_fault(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
3077 Mpi2SepReply_t mpi_reply
;
3078 Mpi2SepRequest_t mpi_request
;
3079 struct scsi_target
*starget
;
3080 struct MPT2SAS_TARGET
*sas_target_priv_data
;
3081 Mpi2EventNotificationReply_t
*event_reply
;
3082 Mpi2EventDataSasDeviceStatusChange_t
*event_data
;
3083 struct _sas_device
*sas_device
;
3085 unsigned long flags
;
3087 /* only handle non-raid devices */
3088 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
3089 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
3091 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3094 starget
= sas_device
->starget
;
3095 sas_target_priv_data
= starget
->hostdata
;
3097 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
) ||
3098 ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
))) {
3099 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3102 starget_printk(KERN_WARNING
, starget
, "predicted fault\n");
3103 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3105 if (ioc
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_IBM
) {
3106 memset(&mpi_request
, 0, sizeof(Mpi2SepRequest_t
));
3107 mpi_request
.Function
= MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR
;
3108 mpi_request
.Action
= MPI2_SEP_REQ_ACTION_WRITE_STATUS
;
3109 mpi_request
.SlotStatus
=
3110 MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT
;
3111 mpi_request
.DevHandle
= cpu_to_le16(handle
);
3112 mpi_request
.Flags
= MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS
;
3113 if ((mpt2sas_base_scsi_enclosure_processor(ioc
, &mpi_reply
,
3114 &mpi_request
)) != 0) {
3115 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3116 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3120 if (mpi_reply
.IOCStatus
|| mpi_reply
.IOCLogInfo
) {
3121 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3122 "enclosure_processor: ioc_status (0x%04x), "
3123 "loginfo(0x%08x)\n", ioc
->name
,
3124 le16_to_cpu(mpi_reply
.IOCStatus
),
3125 le32_to_cpu(mpi_reply
.IOCLogInfo
)));
3130 /* insert into event log */
3131 sz
= offsetof(Mpi2EventNotificationReply_t
, EventData
) +
3132 sizeof(Mpi2EventDataSasDeviceStatusChange_t
);
3133 event_reply
= kzalloc(sz
, GFP_KERNEL
);
3135 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3136 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3140 event_reply
->Function
= MPI2_FUNCTION_EVENT_NOTIFICATION
;
3141 event_reply
->Event
=
3142 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
);
3143 event_reply
->MsgLength
= sz
/4;
3144 event_reply
->EventDataLength
=
3145 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t
)/4);
3146 event_data
= (Mpi2EventDataSasDeviceStatusChange_t
*)
3147 event_reply
->EventData
;
3148 event_data
->ReasonCode
= MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
;
3149 event_data
->ASC
= 0x5D;
3150 event_data
->DevHandle
= cpu_to_le16(handle
);
3151 event_data
->SASAddress
= cpu_to_le64(sas_target_priv_data
->sas_address
);
3152 mpt2sas_ctl_add_to_event_log(ioc
, event_reply
);
3157 * _scsih_io_done - scsi request callback
3158 * @ioc: per adapter object
3159 * @smid: system request message index
3160 * @msix_index: MSIX table index supplied by the OS
3161 * @reply: reply message frame(lower 32bit addr)
3163 * Callback handler when using _scsih_qcmd.
3165 * Return 1 meaning mf should be freed from _base_interrupt
3166 * 0 means the mf is freed from this function.
3169 _scsih_io_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
3171 Mpi2SCSIIORequest_t
*mpi_request
;
3172 Mpi2SCSIIOReply_t
*mpi_reply
;
3173 struct scsi_cmnd
*scmd
;
3179 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
3182 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
3183 scmd
= _scsih_scsi_lookup_get(ioc
, smid
);
3187 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3189 if (mpi_reply
== NULL
) {
3190 scmd
->result
= DID_OK
<< 16;
3194 sas_device_priv_data
= scmd
->device
->hostdata
;
3195 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
||
3196 sas_device_priv_data
->sas_target
->deleted
) {
3197 scmd
->result
= DID_NO_CONNECT
<< 16;
3201 /* turning off TLR */
3202 if (!sas_device_priv_data
->tlr_snoop_check
) {
3203 sas_device_priv_data
->tlr_snoop_check
++;
3204 if (sas_device_priv_data
->flags
& MPT_DEVICE_TLR_ON
) {
3205 response_code
= (le32_to_cpu(mpi_reply
->ResponseInfo
)
3207 if (response_code
==
3208 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
)
3209 sas_device_priv_data
->flags
&=
3214 xfer_cnt
= le32_to_cpu(mpi_reply
->TransferCount
);
3215 scsi_set_resid(scmd
, scsi_bufflen(scmd
) - xfer_cnt
);
3216 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
);
3217 if (ioc_status
& MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE
)
3218 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
3221 ioc_status
&= MPI2_IOCSTATUS_MASK
;
3222 scsi_state
= mpi_reply
->SCSIState
;
3223 scsi_status
= mpi_reply
->SCSIStatus
;
3225 if (ioc_status
== MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
&& xfer_cnt
== 0 &&
3226 (scsi_status
== MPI2_SCSI_STATUS_BUSY
||
3227 scsi_status
== MPI2_SCSI_STATUS_RESERVATION_CONFLICT
||
3228 scsi_status
== MPI2_SCSI_STATUS_TASK_SET_FULL
)) {
3229 ioc_status
= MPI2_IOCSTATUS_SUCCESS
;
3232 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
3233 struct sense_info data
;
3234 const void *sense_data
= mpt2sas_base_get_sense_buffer(ioc
,
3236 u32 sz
= min_t(u32
, SCSI_SENSE_BUFFERSIZE
,
3237 le32_to_cpu(mpi_reply
->SenseCount
));
3238 memcpy(scmd
->sense_buffer
, sense_data
, sz
);
3239 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
3240 /* failure prediction threshold exceeded */
3241 if (data
.asc
== 0x5D)
3242 _scsih_smart_predicted_fault(ioc
,
3243 le16_to_cpu(mpi_reply
->DevHandle
));
3246 switch (ioc_status
) {
3247 case MPI2_IOCSTATUS_BUSY
:
3248 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES
:
3249 scmd
->result
= SAM_STAT_BUSY
;
3252 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
3253 scmd
->result
= DID_NO_CONNECT
<< 16;
3256 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
3257 if (sas_device_priv_data
->block
) {
3258 scmd
->result
= (DID_BUS_BUSY
<< 16);
3262 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
3263 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
3264 scmd
->result
= DID_RESET
<< 16;
3267 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
3268 if ((xfer_cnt
== 0) || (scmd
->underflow
> xfer_cnt
))
3269 scmd
->result
= DID_SOFT_ERROR
<< 16;
3271 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
3274 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
3275 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
3277 if ((scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
))
3280 if (xfer_cnt
< scmd
->underflow
) {
3281 if (scsi_status
== SAM_STAT_BUSY
)
3282 scmd
->result
= SAM_STAT_BUSY
;
3284 scmd
->result
= DID_SOFT_ERROR
<< 16;
3285 } else if (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
3286 MPI2_SCSI_STATE_NO_SCSI_STATUS
))
3287 scmd
->result
= DID_SOFT_ERROR
<< 16;
3288 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
3289 scmd
->result
= DID_RESET
<< 16;
3290 else if (!xfer_cnt
&& scmd
->cmnd
[0] == REPORT_LUNS
) {
3291 mpi_reply
->SCSIState
= MPI2_SCSI_STATE_AUTOSENSE_VALID
;
3292 mpi_reply
->SCSIStatus
= SAM_STAT_CHECK_CONDITION
;
3293 scmd
->result
= (DRIVER_SENSE
<< 24) |
3294 SAM_STAT_CHECK_CONDITION
;
3295 scmd
->sense_buffer
[0] = 0x70;
3296 scmd
->sense_buffer
[2] = ILLEGAL_REQUEST
;
3297 scmd
->sense_buffer
[12] = 0x20;
3298 scmd
->sense_buffer
[13] = 0;
3302 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
3303 scsi_set_resid(scmd
, 0);
3304 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
3305 case MPI2_IOCSTATUS_SUCCESS
:
3306 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
3307 if (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
3308 MPI2_SCSI_STATE_NO_SCSI_STATUS
))
3309 scmd
->result
= DID_SOFT_ERROR
<< 16;
3310 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
3311 scmd
->result
= DID_RESET
<< 16;
3314 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
3315 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
3316 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
3317 _scsih_eedp_error_handling(scmd
, ioc_status
);
3319 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
3320 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
3321 case MPI2_IOCSTATUS_INVALID_SGL
:
3322 case MPI2_IOCSTATUS_INTERNAL_ERROR
:
3323 case MPI2_IOCSTATUS_INVALID_FIELD
:
3324 case MPI2_IOCSTATUS_INVALID_STATE
:
3325 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
3326 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
3328 scmd
->result
= DID_SOFT_ERROR
<< 16;
3333 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3334 if (scmd
->result
&& (ioc
->logging_level
& MPT_DEBUG_REPLY
))
3335 _scsih_scsi_ioc_info(ioc
, scmd
, mpi_reply
, smid
);
3339 scsi_dma_unmap(scmd
);
3340 scmd
->scsi_done(scmd
);
3345 * _scsih_sas_host_refresh - refreshing sas host object contents
3346 * @ioc: per adapter object
3347 * @update: update link information
3350 * During port enable, fw will send topology events for every device. Its
3351 * possible that the handles may change from the previous setting, so this
3352 * code keeping handles updating if changed.
3357 _scsih_sas_host_refresh(struct MPT2SAS_ADAPTER
*ioc
, u8 update
)
3362 Mpi2ConfigReply_t mpi_reply
;
3363 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
3365 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
3366 "updating handles for sas_host(0x%016llx)\n",
3367 ioc
->name
, (unsigned long long)ioc
->sas_hba
.sas_address
));
3369 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
3370 * sizeof(Mpi2SasIOUnit0PhyData_t
));
3371 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
3372 if (!sas_iounit_pg0
) {
3373 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3374 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3377 if (!(mpt2sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
3378 sas_iounit_pg0
, sz
))) {
3379 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
3380 MPI2_IOCSTATUS_MASK
;
3381 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
3383 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
3384 ioc
->sas_hba
.phy
[i
].handle
=
3385 le16_to_cpu(sas_iounit_pg0
->PhyData
[i
].
3386 ControllerDevHandle
);
3388 mpt2sas_transport_update_links(
3390 ioc
->sas_hba
.phy
[i
].handle
,
3391 le16_to_cpu(sas_iounit_pg0
->PhyData
[i
].
3392 AttachedDevHandle
), i
,
3393 sas_iounit_pg0
->PhyData
[i
].
3394 NegotiatedLinkRate
>> 4);
3399 kfree(sas_iounit_pg0
);
3403 * _scsih_sas_host_add - create sas host object
3404 * @ioc: per adapter object
3406 * Creating host side data object, stored in ioc->sas_hba
3411 _scsih_sas_host_add(struct MPT2SAS_ADAPTER
*ioc
)
3414 Mpi2ConfigReply_t mpi_reply
;
3415 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
3416 Mpi2SasIOUnitPage1_t
*sas_iounit_pg1
= NULL
;
3417 Mpi2SasPhyPage0_t phy_pg0
;
3418 Mpi2SasDevicePage0_t sas_device_pg0
;
3419 Mpi2SasEnclosurePage0_t enclosure_pg0
;
3422 u16 device_missing_delay
;
3424 mpt2sas_config_get_number_hba_phys(ioc
, &ioc
->sas_hba
.num_phys
);
3425 if (!ioc
->sas_hba
.num_phys
) {
3426 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3427 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3431 /* sas_iounit page 0 */
3432 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
3433 sizeof(Mpi2SasIOUnit0PhyData_t
));
3434 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
3435 if (!sas_iounit_pg0
) {
3436 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3437 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3440 if ((mpt2sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
3441 sas_iounit_pg0
, sz
))) {
3442 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3443 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3446 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
3447 MPI2_IOCSTATUS_MASK
;
3448 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
3449 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3450 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3454 /* sas_iounit page 1 */
3455 sz
= offsetof(Mpi2SasIOUnitPage1_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
3456 sizeof(Mpi2SasIOUnit1PhyData_t
));
3457 sas_iounit_pg1
= kzalloc(sz
, GFP_KERNEL
);
3458 if (!sas_iounit_pg1
) {
3459 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3460 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3463 if ((mpt2sas_config_get_sas_iounit_pg1(ioc
, &mpi_reply
,
3464 sas_iounit_pg1
, sz
))) {
3465 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3466 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3469 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
3470 MPI2_IOCSTATUS_MASK
;
3471 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
3472 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3473 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3477 ioc
->io_missing_delay
=
3478 le16_to_cpu(sas_iounit_pg1
->IODeviceMissingDelay
);
3479 device_missing_delay
=
3480 le16_to_cpu(sas_iounit_pg1
->ReportDeviceMissingDelay
);
3481 if (device_missing_delay
& MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16
)
3482 ioc
->device_missing_delay
= (device_missing_delay
&
3483 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
) * 16;
3485 ioc
->device_missing_delay
= device_missing_delay
&
3486 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
;
3488 ioc
->sas_hba
.parent_dev
= &ioc
->shost
->shost_gendev
;
3489 ioc
->sas_hba
.phy
= kcalloc(ioc
->sas_hba
.num_phys
,
3490 sizeof(struct _sas_phy
), GFP_KERNEL
);
3491 if (!ioc
->sas_hba
.phy
) {
3492 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3493 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3496 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
3497 if ((mpt2sas_config_get_phy_pg0(ioc
, &mpi_reply
, &phy_pg0
,
3499 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3500 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3503 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
3504 MPI2_IOCSTATUS_MASK
;
3505 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
3506 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3507 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3510 ioc
->sas_hba
.phy
[i
].handle
=
3511 le16_to_cpu(sas_iounit_pg0
->PhyData
[i
].ControllerDevHandle
);
3512 ioc
->sas_hba
.phy
[i
].phy_id
= i
;
3513 mpt2sas_transport_add_host_phy(ioc
, &ioc
->sas_hba
.phy
[i
],
3514 phy_pg0
, ioc
->sas_hba
.parent_dev
);
3516 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
3517 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, ioc
->sas_hba
.phy
[0].handle
))) {
3518 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3519 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3522 ioc
->sas_hba
.handle
= le16_to_cpu(sas_device_pg0
.DevHandle
);
3523 ioc
->sas_hba
.enclosure_handle
=
3524 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
3525 ioc
->sas_hba
.sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
3526 printk(MPT2SAS_INFO_FMT
"host_add: handle(0x%04x), "
3527 "sas_addr(0x%016llx), phys(%d)\n", ioc
->name
, ioc
->sas_hba
.handle
,
3528 (unsigned long long) ioc
->sas_hba
.sas_address
,
3529 ioc
->sas_hba
.num_phys
) ;
3531 if (ioc
->sas_hba
.enclosure_handle
) {
3532 if (!(mpt2sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
3534 MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
3535 ioc
->sas_hba
.enclosure_handle
))) {
3536 ioc
->sas_hba
.enclosure_logical_id
=
3537 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
3542 kfree(sas_iounit_pg1
);
3543 kfree(sas_iounit_pg0
);
3547 * _scsih_expander_add - creating expander object
3548 * @ioc: per adapter object
3549 * @handle: expander handle
3551 * Creating expander object, stored in ioc->sas_expander_list.
3553 * Return 0 for success, else error.
3556 _scsih_expander_add(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
3558 struct _sas_node
*sas_expander
;
3559 Mpi2ConfigReply_t mpi_reply
;
3560 Mpi2ExpanderPage0_t expander_pg0
;
3561 Mpi2ExpanderPage1_t expander_pg1
;
3562 Mpi2SasEnclosurePage0_t enclosure_pg0
;
3567 unsigned long flags
;
3568 struct _sas_port
*mpt2sas_port
= NULL
;
3574 if (ioc
->shost_recovery
)
3577 if ((mpt2sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
3578 MPI2_SAS_EXPAND_PGAD_FORM_HNDL
, handle
))) {
3579 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3580 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3584 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
3585 MPI2_IOCSTATUS_MASK
;
3586 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
3587 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3588 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3592 /* handle out of order topology events */
3593 parent_handle
= le16_to_cpu(expander_pg0
.ParentDevHandle
);
3594 if (parent_handle
>= ioc
->sas_hba
.num_phys
) {
3595 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
3596 sas_expander
= mpt2sas_scsih_expander_find_by_handle(ioc
,
3598 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
3599 if (!sas_expander
) {
3600 rc
= _scsih_expander_add(ioc
, parent_handle
);
3606 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
3607 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
3608 sas_expander
= mpt2sas_scsih_expander_find_by_sas_address(ioc
,
3610 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
3615 sas_expander
= kzalloc(sizeof(struct _sas_node
),
3617 if (!sas_expander
) {
3618 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3619 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3623 sas_expander
->handle
= handle
;
3624 sas_expander
->num_phys
= expander_pg0
.NumPhys
;
3625 sas_expander
->parent_handle
= parent_handle
;
3626 sas_expander
->enclosure_handle
=
3627 le16_to_cpu(expander_pg0
.EnclosureHandle
);
3628 sas_expander
->sas_address
= sas_address
;
3630 printk(MPT2SAS_INFO_FMT
"expander_add: handle(0x%04x),"
3631 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc
->name
,
3632 handle
, sas_expander
->parent_handle
, (unsigned long long)
3633 sas_expander
->sas_address
, sas_expander
->num_phys
);
3635 if (!sas_expander
->num_phys
)
3637 sas_expander
->phy
= kcalloc(sas_expander
->num_phys
,
3638 sizeof(struct _sas_phy
), GFP_KERNEL
);
3639 if (!sas_expander
->phy
) {
3640 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3641 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3646 INIT_LIST_HEAD(&sas_expander
->sas_port_list
);
3647 mpt2sas_port
= mpt2sas_transport_port_add(ioc
, handle
,
3648 sas_expander
->parent_handle
);
3649 if (!mpt2sas_port
) {
3650 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3651 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3655 sas_expander
->parent_dev
= &mpt2sas_port
->rphy
->dev
;
3657 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++) {
3658 if ((mpt2sas_config_get_expander_pg1(ioc
, &mpi_reply
,
3659 &expander_pg1
, i
, handle
))) {
3660 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3661 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3665 sas_expander
->phy
[i
].handle
= handle
;
3666 sas_expander
->phy
[i
].phy_id
= i
;
3668 if ((mpt2sas_transport_add_expander_phy(ioc
,
3669 &sas_expander
->phy
[i
], expander_pg1
,
3670 sas_expander
->parent_dev
))) {
3671 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3672 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3678 if (sas_expander
->enclosure_handle
) {
3679 if (!(mpt2sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
3680 &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
3681 sas_expander
->enclosure_handle
))) {
3682 sas_expander
->enclosure_logical_id
=
3683 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
3687 _scsih_expander_node_add(ioc
, sas_expander
);
3693 mpt2sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
3694 sas_expander
->parent_handle
);
3695 kfree(sas_expander
);
3700 * _scsih_expander_remove - removing expander object
3701 * @ioc: per adapter object
3702 * @handle: expander handle
3707 _scsih_expander_remove(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
3709 struct _sas_node
*sas_expander
;
3710 unsigned long flags
;
3712 if (ioc
->shost_recovery
)
3715 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
3716 sas_expander
= mpt2sas_scsih_expander_find_by_handle(ioc
, handle
);
3717 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
3718 _scsih_expander_node_remove(ioc
, sas_expander
);
3722 * _scsih_add_device - creating sas device object
3723 * @ioc: per adapter object
3724 * @handle: sas device handle
3725 * @phy_num: phy number end device attached to
3726 * @is_pd: is this hidden raid component
3728 * Creating end device object, stored in ioc->sas_device_list.
3730 * Returns 0 for success, non-zero for failure.
3733 _scsih_add_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
, u8 phy_num
, u8 is_pd
)
3735 Mpi2ConfigReply_t mpi_reply
;
3736 Mpi2SasDevicePage0_t sas_device_pg0
;
3737 Mpi2SasEnclosurePage0_t enclosure_pg0
;
3738 struct _sas_device
*sas_device
;
3742 unsigned long flags
;
3744 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
3745 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
3746 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3747 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3751 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
3752 MPI2_IOCSTATUS_MASK
;
3753 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
3754 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3755 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3759 /* check if device is present */
3760 if (!(le16_to_cpu(sas_device_pg0
.Flags
) &
3761 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT
)) {
3762 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3763 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3764 printk(MPT2SAS_ERR_FMT
"Flags = 0x%04x\n",
3765 ioc
->name
, le16_to_cpu(sas_device_pg0
.Flags
));
3769 /* check if there were any issus with discovery */
3770 if (sas_device_pg0
.AccessStatus
==
3771 MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED
) {
3772 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3773 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3774 printk(MPT2SAS_ERR_FMT
"AccessStatus = 0x%02x\n",
3775 ioc
->name
, sas_device_pg0
.AccessStatus
);
3779 /* check if this is end device */
3780 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
3781 if (!(_scsih_is_end_device(device_info
))) {
3782 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3783 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3787 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
3789 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
3790 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
3792 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3795 _scsih_ublock_io_device(ioc
, handle
);
3799 sas_device
= kzalloc(sizeof(struct _sas_device
),
3802 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3803 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3807 sas_device
->handle
= handle
;
3808 sas_device
->parent_handle
=
3809 le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
3810 sas_device
->enclosure_handle
=
3811 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
3813 le16_to_cpu(sas_device_pg0
.Slot
);
3814 sas_device
->device_info
= device_info
;
3815 sas_device
->sas_address
= sas_address
;
3816 sas_device
->hidden_raid_component
= is_pd
;
3818 /* get enclosure_logical_id */
3819 if (sas_device
->enclosure_handle
&& !(mpt2sas_config_get_enclosure_pg0(
3820 ioc
, &mpi_reply
, &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
3821 sas_device
->enclosure_handle
)))
3822 sas_device
->enclosure_logical_id
=
3823 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
3825 /* get device name */
3826 sas_device
->device_name
= le64_to_cpu(sas_device_pg0
.DeviceName
);
3828 if (ioc
->wait_for_port_enable_to_complete
)
3829 _scsih_sas_device_init_add(ioc
, sas_device
);
3831 _scsih_sas_device_add(ioc
, sas_device
);
3837 * _scsih_remove_device - removing sas device object
3838 * @ioc: per adapter object
3839 * @handle: sas device handle
3844 _scsih_remove_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
3846 struct MPT2SAS_TARGET
*sas_target_priv_data
;
3847 struct _sas_device
*sas_device
;
3848 unsigned long flags
;
3849 Mpi2SasIoUnitControlReply_t mpi_reply
;
3850 Mpi2SasIoUnitControlRequest_t mpi_request
;
3853 /* lookup sas_device */
3854 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
3855 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
3857 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3861 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: enter: handle"
3862 "(0x%04x)\n", ioc
->name
, __func__
, handle
));
3864 if (sas_device
->starget
&& sas_device
->starget
->hostdata
) {
3865 sas_target_priv_data
= sas_device
->starget
->hostdata
;
3866 sas_target_priv_data
->deleted
= 1;
3868 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3870 if (ioc
->remove_host
)
3873 if ((sas_device
->state
& MPTSAS_STATE_TR_COMPLETE
)) {
3874 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"\tskip "
3875 "target_reset handle(0x%04x)\n", ioc
->name
, handle
));
3879 /* Target Reset to flush out all the outstanding IO */
3880 device_handle
= (sas_device
->hidden_raid_component
) ?
3881 sas_device
->volume_handle
: handle
;
3882 if (device_handle
) {
3883 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"issue target reset: "
3884 "handle(0x%04x)\n", ioc
->name
, device_handle
));
3885 mutex_lock(&ioc
->tm_cmds
.mutex
);
3886 mpt2sas_scsih_issue_tm(ioc
, device_handle
, 0,
3887 MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
, 0, 10);
3888 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
3889 mutex_unlock(&ioc
->tm_cmds
.mutex
);
3890 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"issue target reset "
3891 "done: handle(0x%04x)\n", ioc
->name
, device_handle
));
3892 if (ioc
->shost_recovery
)
3897 if ((sas_device
->state
& MPTSAS_STATE_CNTRL_COMPLETE
)) {
3898 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"\tskip "
3899 "sas_cntrl handle(0x%04x)\n", ioc
->name
, handle
));
3903 /* SAS_IO_UNIT_CNTR - send REMOVE_DEVICE */
3904 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"sas_iounit: handle"
3905 "(0x%04x)\n", ioc
->name
, handle
));
3906 memset(&mpi_request
, 0, sizeof(Mpi2SasIoUnitControlRequest_t
));
3907 mpi_request
.Function
= MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
;
3908 mpi_request
.Operation
= MPI2_SAS_OP_REMOVE_DEVICE
;
3909 mpi_request
.DevHandle
= handle
;
3910 mpi_request
.VF_ID
= 0; /* TODO */
3911 mpi_request
.VP_ID
= 0;
3912 if ((mpt2sas_base_sas_iounit_control(ioc
, &mpi_reply
,
3913 &mpi_request
)) != 0) {
3914 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3915 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3918 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"sas_iounit: ioc_status"
3919 "(0x%04x), loginfo(0x%08x)\n", ioc
->name
,
3920 le16_to_cpu(mpi_reply
.IOCStatus
),
3921 le32_to_cpu(mpi_reply
.IOCLogInfo
)));
3925 _scsih_ublock_io_device(ioc
, handle
);
3927 mpt2sas_transport_port_remove(ioc
, sas_device
->sas_address
,
3928 sas_device
->parent_handle
);
3930 printk(MPT2SAS_INFO_FMT
"removing handle(0x%04x), sas_addr"
3931 "(0x%016llx)\n", ioc
->name
, sas_device
->handle
,
3932 (unsigned long long) sas_device
->sas_address
);
3933 _scsih_sas_device_remove(ioc
, sas_device
);
3935 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: exit: handle"
3936 "(0x%04x)\n", ioc
->name
, __func__
, handle
));
3939 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3941 * _scsih_sas_topology_change_event_debug - debug for topology event
3942 * @ioc: per adapter object
3943 * @event_data: event data payload
3947 _scsih_sas_topology_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
3948 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
3954 char *status_str
= NULL
;
3957 switch (event_data
->ExpStatus
) {
3958 case MPI2_EVENT_SAS_TOPO_ES_ADDED
:
3961 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
:
3962 status_str
= "remove";
3964 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING
:
3965 status_str
= "responding";
3967 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
:
3968 status_str
= "remove delay";
3971 status_str
= "unknown status";
3974 printk(MPT2SAS_DEBUG_FMT
"sas topology change: (%s)\n",
3975 ioc
->name
, status_str
);
3976 printk(KERN_DEBUG
"\thandle(0x%04x), enclosure_handle(0x%04x) "
3977 "start_phy(%02d), count(%d)\n",
3978 le16_to_cpu(event_data
->ExpanderDevHandle
),
3979 le16_to_cpu(event_data
->EnclosureHandle
),
3980 event_data
->StartPhyNum
, event_data
->NumEntries
);
3981 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
3982 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
3985 phy_number
= event_data
->StartPhyNum
+ i
;
3986 reason_code
= event_data
->PHY
[i
].PhyStatus
&
3987 MPI2_EVENT_SAS_TOPO_RC_MASK
;
3988 switch (reason_code
) {
3989 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
3990 snprintf(link_rate
, 25, ": add, link(0x%02x)",
3991 (event_data
->PHY
[i
].LinkRate
>> 4));
3992 status_str
= link_rate
;
3994 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
3995 status_str
= ": remove";
3997 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
:
3998 status_str
= ": remove_delay";
4000 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
4001 snprintf(link_rate
, 25, ": link(0x%02x)",
4002 (event_data
->PHY
[i
].LinkRate
>> 4));
4003 status_str
= link_rate
;
4005 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE
:
4006 status_str
= ": responding";
4009 status_str
= ": unknown";
4012 printk(KERN_DEBUG
"\tphy(%02d), attached_handle(0x%04x)%s\n",
4013 phy_number
, handle
, status_str
);
4019 * _scsih_sas_topology_change_event - handle topology changes
4020 * @ioc: per adapter object
4021 * @fw_event: The fw_event_work object
4026 _scsih_sas_topology_change_event(struct MPT2SAS_ADAPTER
*ioc
,
4027 struct fw_event_work
*fw_event
)
4030 u16 parent_handle
, handle
;
4033 struct _sas_node
*sas_expander
;
4034 unsigned long flags
;
4036 Mpi2EventDataSasTopologyChangeList_t
*event_data
= fw_event
->event_data
;
4038 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4039 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
4040 _scsih_sas_topology_change_event_debug(ioc
, event_data
);
4043 if (!ioc
->sas_hba
.num_phys
)
4044 _scsih_sas_host_add(ioc
);
4046 _scsih_sas_host_refresh(ioc
, 0);
4048 if (fw_event
->ignore
) {
4049 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"ignoring expander "
4050 "event\n", ioc
->name
));
4054 parent_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
4056 /* handle expander add */
4057 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_ADDED
)
4058 if (_scsih_expander_add(ioc
, parent_handle
) != 0)
4061 /* handle siblings events */
4062 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
4063 if (fw_event
->ignore
) {
4064 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"ignoring "
4065 "expander event\n", ioc
->name
));
4068 if (ioc
->shost_recovery
)
4070 phy_number
= event_data
->StartPhyNum
+ i
;
4071 reason_code
= event_data
->PHY
[i
].PhyStatus
&
4072 MPI2_EVENT_SAS_TOPO_RC_MASK
;
4073 if ((event_data
->PHY
[i
].PhyStatus
&
4074 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT
) && (reason_code
!=
4075 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
))
4077 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
4080 link_rate_
= event_data
->PHY
[i
].LinkRate
>> 4;
4081 switch (reason_code
) {
4082 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
4083 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
4084 if (!parent_handle
) {
4085 if (phy_number
< ioc
->sas_hba
.num_phys
)
4086 mpt2sas_transport_update_links(
4088 ioc
->sas_hba
.phy
[phy_number
].handle
,
4089 handle
, phy_number
, link_rate_
);
4091 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
4093 mpt2sas_scsih_expander_find_by_handle(ioc
,
4095 spin_unlock_irqrestore(&ioc
->sas_node_lock
,
4098 if (phy_number
< sas_expander
->num_phys
)
4099 mpt2sas_transport_update_links(
4102 phy
[phy_number
].handle
,
4107 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
) {
4108 if (link_rate_
< MPI2_SAS_NEG_LINK_RATE_1_5
)
4110 _scsih_add_device(ioc
, handle
, phy_number
, 0);
4113 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
4114 _scsih_remove_device(ioc
, handle
);
4119 /* handle expander removal */
4120 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
)
4121 _scsih_expander_remove(ioc
, parent_handle
);
4125 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4127 * _scsih_sas_device_status_change_event_debug - debug for device event
4128 * @event_data: event data payload
4134 _scsih_sas_device_status_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
4135 Mpi2EventDataSasDeviceStatusChange_t
*event_data
)
4137 char *reason_str
= NULL
;
4139 switch (event_data
->ReasonCode
) {
4140 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
:
4141 reason_str
= "smart data";
4143 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED
:
4144 reason_str
= "unsupported device discovered";
4146 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
:
4147 reason_str
= "internal device reset";
4149 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL
:
4150 reason_str
= "internal task abort";
4152 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL
:
4153 reason_str
= "internal task abort set";
4155 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL
:
4156 reason_str
= "internal clear task set";
4158 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL
:
4159 reason_str
= "internal query task";
4161 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE
:
4162 reason_str
= "sata init failure";
4164 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
:
4165 reason_str
= "internal device reset complete";
4167 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL
:
4168 reason_str
= "internal task abort complete";
4170 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION
:
4171 reason_str
= "internal async notification";
4174 reason_str
= "unknown reason";
4177 printk(MPT2SAS_DEBUG_FMT
"device status change: (%s)\n"
4178 "\thandle(0x%04x), sas address(0x%016llx)", ioc
->name
,
4179 reason_str
, le16_to_cpu(event_data
->DevHandle
),
4180 (unsigned long long)le64_to_cpu(event_data
->SASAddress
));
4181 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
)
4182 printk(MPT2SAS_DEBUG_FMT
", ASC(0x%x), ASCQ(0x%x)\n", ioc
->name
,
4183 event_data
->ASC
, event_data
->ASCQ
);
4184 printk(KERN_INFO
"\n");
4189 * _scsih_sas_device_status_change_event - handle device status change
4190 * @ioc: per adapter object
4191 * @fw_event: The fw_event_work object
4197 _scsih_sas_device_status_change_event(struct MPT2SAS_ADAPTER
*ioc
,
4198 struct fw_event_work
*fw_event
)
4200 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4201 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
4202 _scsih_sas_device_status_change_event_debug(ioc
,
4203 fw_event
->event_data
);
4207 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4209 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure event
4210 * @ioc: per adapter object
4211 * @event_data: event data payload
4217 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
4218 Mpi2EventDataSasEnclDevStatusChange_t
*event_data
)
4220 char *reason_str
= NULL
;
4222 switch (event_data
->ReasonCode
) {
4223 case MPI2_EVENT_SAS_ENCL_RC_ADDED
:
4224 reason_str
= "enclosure add";
4226 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING
:
4227 reason_str
= "enclosure remove";
4230 reason_str
= "unknown reason";
4234 printk(MPT2SAS_DEBUG_FMT
"enclosure status change: (%s)\n"
4235 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
4236 " number slots(%d)\n", ioc
->name
, reason_str
,
4237 le16_to_cpu(event_data
->EnclosureHandle
),
4238 (unsigned long long)le64_to_cpu(event_data
->EnclosureLogicalID
),
4239 le16_to_cpu(event_data
->StartSlot
));
4244 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
4245 * @ioc: per adapter object
4246 * @fw_event: The fw_event_work object
4252 _scsih_sas_enclosure_dev_status_change_event(struct MPT2SAS_ADAPTER
*ioc
,
4253 struct fw_event_work
*fw_event
)
4255 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4256 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
4257 _scsih_sas_enclosure_dev_status_change_event_debug(ioc
,
4258 fw_event
->event_data
);
4263 * _scsih_sas_broadcast_primative_event - handle broadcast events
4264 * @ioc: per adapter object
4265 * @fw_event: The fw_event_work object
4271 _scsih_sas_broadcast_primative_event(struct MPT2SAS_ADAPTER
*ioc
,
4272 struct fw_event_work
*fw_event
)
4274 struct scsi_cmnd
*scmd
;
4277 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
4278 u32 termination_count
;
4280 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
4281 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4282 Mpi2EventDataSasBroadcastPrimitive_t
*event_data
= fw_event
->event_data
;
4284 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"broadcast primative: "
4285 "phy number(%d), width(%d)\n", ioc
->name
, event_data
->PhyNum
,
4286 event_data
->PortWidth
));
4287 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: enter\n", ioc
->name
,
4290 mutex_lock(&ioc
->tm_cmds
.mutex
);
4291 termination_count
= 0;
4293 mpi_reply
= ioc
->tm_cmds
.reply
;
4294 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
4295 scmd
= _scsih_scsi_lookup_get(ioc
, smid
);
4298 sas_device_priv_data
= scmd
->device
->hostdata
;
4299 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
)
4301 /* skip hidden raid components */
4302 if (sas_device_priv_data
->sas_target
->flags
&
4303 MPT_TARGET_FLAGS_RAID_COMPONENT
)
4306 if (sas_device_priv_data
->sas_target
->flags
&
4307 MPT_TARGET_FLAGS_VOLUME
)
4310 handle
= sas_device_priv_data
->sas_target
->handle
;
4311 lun
= sas_device_priv_data
->lun
;
4314 mpt2sas_scsih_issue_tm(ioc
, handle
, lun
,
4315 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK
, smid
, 30);
4316 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
4318 if ((mpi_reply
->IOCStatus
== MPI2_IOCSTATUS_SUCCESS
) &&
4319 (mpi_reply
->ResponseCode
==
4320 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
||
4321 mpi_reply
->ResponseCode
==
4322 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
))
4325 mpt2sas_scsih_issue_tm(ioc
, handle
, lun
,
4326 MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET
, 0, 30);
4327 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
4328 termination_count
+= le32_to_cpu(mpi_reply
->TerminationCount
);
4330 ioc
->broadcast_aen_busy
= 0;
4331 mutex_unlock(&ioc
->tm_cmds
.mutex
);
4333 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
4334 "%s - exit, query_count = %d termination_count = %d\n",
4335 ioc
->name
, __func__
, query_count
, termination_count
));
4339 * _scsih_sas_discovery_event - handle discovery events
4340 * @ioc: per adapter object
4341 * @fw_event: The fw_event_work object
4347 _scsih_sas_discovery_event(struct MPT2SAS_ADAPTER
*ioc
,
4348 struct fw_event_work
*fw_event
)
4350 Mpi2EventDataSasDiscovery_t
*event_data
= fw_event
->event_data
;
4352 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4353 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
) {
4354 printk(MPT2SAS_DEBUG_FMT
"discovery event: (%s)", ioc
->name
,
4355 (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
) ?
4357 if (event_data
->DiscoveryStatus
)
4358 printk("discovery_status(0x%08x)",
4359 le32_to_cpu(event_data
->DiscoveryStatus
));
4364 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
&&
4365 !ioc
->sas_hba
.num_phys
)
4366 _scsih_sas_host_add(ioc
);
4370 * _scsih_reprobe_lun - reprobing lun
4371 * @sdev: scsi device struct
4372 * @no_uld_attach: sdev->no_uld_attach flag setting
4376 _scsih_reprobe_lun(struct scsi_device
*sdev
, void *no_uld_attach
)
4380 sdev
->no_uld_attach
= no_uld_attach
? 1 : 0;
4381 sdev_printk(KERN_INFO
, sdev
, "%s raid component\n",
4382 sdev
->no_uld_attach
? "hidding" : "exposing");
4383 rc
= scsi_device_reprobe(sdev
);
4387 * _scsih_reprobe_target - reprobing target
4388 * @starget: scsi target struct
4389 * @no_uld_attach: sdev->no_uld_attach flag setting
4391 * Note: no_uld_attach flag determines whether the disk device is attached
4392 * to block layer. A value of `1` means to not attach.
4395 _scsih_reprobe_target(struct scsi_target
*starget
, int no_uld_attach
)
4397 struct MPT2SAS_TARGET
*sas_target_priv_data
= starget
->hostdata
;
4400 sas_target_priv_data
->flags
|= MPT_TARGET_FLAGS_RAID_COMPONENT
;
4402 sas_target_priv_data
->flags
&= ~MPT_TARGET_FLAGS_RAID_COMPONENT
;
4404 starget_for_each_device(starget
, no_uld_attach
? (void *)1 : NULL
,
4405 _scsih_reprobe_lun
);
4408 * _scsih_sas_volume_add - add new volume
4409 * @ioc: per adapter object
4410 * @element: IR config element data
4416 _scsih_sas_volume_add(struct MPT2SAS_ADAPTER
*ioc
,
4417 Mpi2EventIrConfigElement_t
*element
)
4419 struct _raid_device
*raid_device
;
4420 unsigned long flags
;
4422 u16 handle
= le16_to_cpu(element
->VolDevHandle
);
4425 mpt2sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
4427 printk(MPT2SAS_ERR_FMT
4428 "failure at %s:%d/%s()!\n", ioc
->name
,
4429 __FILE__
, __LINE__
, __func__
);
4433 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
4434 raid_device
= _scsih_raid_device_find_by_wwid(ioc
, wwid
);
4435 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
4440 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
4442 printk(MPT2SAS_ERR_FMT
4443 "failure at %s:%d/%s()!\n", ioc
->name
,
4444 __FILE__
, __LINE__
, __func__
);
4448 raid_device
->id
= ioc
->sas_id
++;
4449 raid_device
->channel
= RAID_CHANNEL
;
4450 raid_device
->handle
= handle
;
4451 raid_device
->wwid
= wwid
;
4452 _scsih_raid_device_add(ioc
, raid_device
);
4453 if (!ioc
->wait_for_port_enable_to_complete
) {
4454 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
4455 raid_device
->id
, 0);
4457 _scsih_raid_device_remove(ioc
, raid_device
);
4459 _scsih_determine_boot_device(ioc
, raid_device
, 1);
4463 * _scsih_sas_volume_delete - delete volume
4464 * @ioc: per adapter object
4465 * @element: IR config element data
4471 _scsih_sas_volume_delete(struct MPT2SAS_ADAPTER
*ioc
,
4472 Mpi2EventIrConfigElement_t
*element
)
4474 struct _raid_device
*raid_device
;
4475 u16 handle
= le16_to_cpu(element
->VolDevHandle
);
4476 unsigned long flags
;
4477 struct MPT2SAS_TARGET
*sas_target_priv_data
;
4479 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
4480 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
4481 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
4484 if (raid_device
->starget
) {
4485 sas_target_priv_data
= raid_device
->starget
->hostdata
;
4486 sas_target_priv_data
->deleted
= 1;
4487 scsi_remove_target(&raid_device
->starget
->dev
);
4489 _scsih_raid_device_remove(ioc
, raid_device
);
4493 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
4494 * @ioc: per adapter object
4495 * @element: IR config element data
4501 _scsih_sas_pd_expose(struct MPT2SAS_ADAPTER
*ioc
,
4502 Mpi2EventIrConfigElement_t
*element
)
4504 struct _sas_device
*sas_device
;
4505 unsigned long flags
;
4506 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
4508 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4509 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
4510 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4514 /* exposing raid component */
4515 sas_device
->volume_handle
= 0;
4516 sas_device
->volume_wwid
= 0;
4517 sas_device
->hidden_raid_component
= 0;
4518 _scsih_reprobe_target(sas_device
->starget
, 0);
4522 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
4523 * @ioc: per adapter object
4524 * @element: IR config element data
4530 _scsih_sas_pd_hide(struct MPT2SAS_ADAPTER
*ioc
,
4531 Mpi2EventIrConfigElement_t
*element
)
4533 struct _sas_device
*sas_device
;
4534 unsigned long flags
;
4535 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
4537 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4538 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
4539 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4543 /* hiding raid component */
4544 mpt2sas_config_get_volume_handle(ioc
, handle
,
4545 &sas_device
->volume_handle
);
4546 mpt2sas_config_get_volume_wwid(ioc
, sas_device
->volume_handle
,
4547 &sas_device
->volume_wwid
);
4548 sas_device
->hidden_raid_component
= 1;
4549 _scsih_reprobe_target(sas_device
->starget
, 1);
4553 * _scsih_sas_pd_delete - delete pd component
4554 * @ioc: per adapter object
4555 * @element: IR config element data
4561 _scsih_sas_pd_delete(struct MPT2SAS_ADAPTER
*ioc
,
4562 Mpi2EventIrConfigElement_t
*element
)
4564 struct _sas_device
*sas_device
;
4565 unsigned long flags
;
4566 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
4568 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4569 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
4570 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4573 _scsih_remove_device(ioc
, handle
);
4577 * _scsih_sas_pd_add - remove pd component
4578 * @ioc: per adapter object
4579 * @element: IR config element data
4585 _scsih_sas_pd_add(struct MPT2SAS_ADAPTER
*ioc
,
4586 Mpi2EventIrConfigElement_t
*element
)
4588 struct _sas_device
*sas_device
;
4589 unsigned long flags
;
4590 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
4591 Mpi2ConfigReply_t mpi_reply
;
4592 Mpi2SasDevicePage0_t sas_device_pg0
;
4595 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4596 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
4597 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4599 sas_device
->hidden_raid_component
= 1;
4603 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
4604 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
4605 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4606 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4610 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4611 MPI2_IOCSTATUS_MASK
;
4612 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4613 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4614 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4618 mpt2sas_transport_update_links(ioc
,
4619 le16_to_cpu(sas_device_pg0
.ParentDevHandle
),
4620 handle
, sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
4622 _scsih_add_device(ioc
, handle
, 0, 1);
4625 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4627 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
4628 * @ioc: per adapter object
4629 * @event_data: event data payload
4635 _scsih_sas_ir_config_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
4636 Mpi2EventDataIrConfigChangeList_t
*event_data
)
4638 Mpi2EventIrConfigElement_t
*element
;
4641 char *reason_str
= NULL
, *element_str
= NULL
;
4643 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
4645 printk(MPT2SAS_DEBUG_FMT
"raid config change: (%s), elements(%d)\n",
4646 ioc
->name
, (le32_to_cpu(event_data
->Flags
) &
4647 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ?
4648 "foreign" : "native", event_data
->NumElements
);
4649 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
4650 switch (element
->ReasonCode
) {
4651 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
4654 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
4655 reason_str
= "remove";
4657 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE
:
4658 reason_str
= "no change";
4660 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
4661 reason_str
= "hide";
4663 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
4664 reason_str
= "unhide";
4666 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
4667 reason_str
= "volume_created";
4669 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
4670 reason_str
= "volume_deleted";
4672 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
4673 reason_str
= "pd_created";
4675 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
4676 reason_str
= "pd_deleted";
4679 reason_str
= "unknown reason";
4682 element_type
= le16_to_cpu(element
->ElementFlags
) &
4683 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK
;
4684 switch (element_type
) {
4685 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT
:
4686 element_str
= "volume";
4688 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT
:
4689 element_str
= "phys disk";
4691 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT
:
4692 element_str
= "hot spare";
4695 element_str
= "unknown element";
4698 printk(KERN_DEBUG
"\t(%s:%s), vol handle(0x%04x), "
4699 "pd handle(0x%04x), pd num(0x%02x)\n", element_str
,
4700 reason_str
, le16_to_cpu(element
->VolDevHandle
),
4701 le16_to_cpu(element
->PhysDiskDevHandle
),
4702 element
->PhysDiskNum
);
4708 * _scsih_sas_ir_config_change_event - handle ir configuration change events
4709 * @ioc: per adapter object
4710 * @fw_event: The fw_event_work object
4716 _scsih_sas_ir_config_change_event(struct MPT2SAS_ADAPTER
*ioc
,
4717 struct fw_event_work
*fw_event
)
4719 Mpi2EventIrConfigElement_t
*element
;
4722 Mpi2EventDataIrConfigChangeList_t
*event_data
= fw_event
->event_data
;
4724 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4725 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
4726 _scsih_sas_ir_config_change_event_debug(ioc
, event_data
);
4729 foreign_config
= (le32_to_cpu(event_data
->Flags
) &
4730 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ? 1 : 0;
4732 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
4733 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
4735 switch (element
->ReasonCode
) {
4736 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
4737 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
4738 if (!foreign_config
)
4739 _scsih_sas_volume_add(ioc
, element
);
4741 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
4742 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
4743 if (!foreign_config
)
4744 _scsih_sas_volume_delete(ioc
, element
);
4746 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
4747 _scsih_sas_pd_hide(ioc
, element
);
4749 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
4750 _scsih_sas_pd_expose(ioc
, element
);
4752 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
4753 _scsih_sas_pd_add(ioc
, element
);
4755 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
4756 _scsih_sas_pd_delete(ioc
, element
);
4763 * _scsih_sas_ir_volume_event - IR volume event
4764 * @ioc: per adapter object
4765 * @fw_event: The fw_event_work object
4771 _scsih_sas_ir_volume_event(struct MPT2SAS_ADAPTER
*ioc
,
4772 struct fw_event_work
*fw_event
)
4775 unsigned long flags
;
4776 struct _raid_device
*raid_device
;
4780 struct MPT2SAS_TARGET
*sas_target_priv_data
;
4781 Mpi2EventDataIrVolume_t
*event_data
= fw_event
->event_data
;
4783 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED
)
4786 handle
= le16_to_cpu(event_data
->VolDevHandle
);
4787 state
= le32_to_cpu(event_data
->NewValue
);
4788 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: handle(0x%04x), "
4789 "old(0x%08x), new(0x%08x)\n", ioc
->name
, __func__
, handle
,
4790 le32_to_cpu(event_data
->PreviousValue
), state
));
4792 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
4793 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
4794 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
4797 case MPI2_RAID_VOL_STATE_MISSING
:
4798 case MPI2_RAID_VOL_STATE_FAILED
:
4801 if (raid_device
->starget
) {
4802 sas_target_priv_data
= raid_device
->starget
->hostdata
;
4803 sas_target_priv_data
->deleted
= 1;
4804 scsi_remove_target(&raid_device
->starget
->dev
);
4806 _scsih_raid_device_remove(ioc
, raid_device
);
4809 case MPI2_RAID_VOL_STATE_ONLINE
:
4810 case MPI2_RAID_VOL_STATE_DEGRADED
:
4811 case MPI2_RAID_VOL_STATE_OPTIMAL
:
4815 mpt2sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
4817 printk(MPT2SAS_ERR_FMT
4818 "failure at %s:%d/%s()!\n", ioc
->name
,
4819 __FILE__
, __LINE__
, __func__
);
4823 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
4825 printk(MPT2SAS_ERR_FMT
4826 "failure at %s:%d/%s()!\n", ioc
->name
,
4827 __FILE__
, __LINE__
, __func__
);
4831 raid_device
->id
= ioc
->sas_id
++;
4832 raid_device
->channel
= RAID_CHANNEL
;
4833 raid_device
->handle
= handle
;
4834 raid_device
->wwid
= wwid
;
4835 _scsih_raid_device_add(ioc
, raid_device
);
4836 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
4837 raid_device
->id
, 0);
4839 _scsih_raid_device_remove(ioc
, raid_device
);
4842 case MPI2_RAID_VOL_STATE_INITIALIZING
:
4849 * _scsih_sas_ir_physical_disk_event - PD event
4850 * @ioc: per adapter object
4851 * @fw_event: The fw_event_work object
4857 _scsih_sas_ir_physical_disk_event(struct MPT2SAS_ADAPTER
*ioc
,
4858 struct fw_event_work
*fw_event
)
4862 struct _sas_device
*sas_device
;
4863 unsigned long flags
;
4864 Mpi2ConfigReply_t mpi_reply
;
4865 Mpi2SasDevicePage0_t sas_device_pg0
;
4867 Mpi2EventDataIrPhysicalDisk_t
*event_data
= fw_event
->event_data
;
4869 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED
)
4872 handle
= le16_to_cpu(event_data
->PhysDiskDevHandle
);
4873 state
= le32_to_cpu(event_data
->NewValue
);
4875 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: handle(0x%04x), "
4876 "old(0x%08x), new(0x%08x)\n", ioc
->name
, __func__
, handle
,
4877 le32_to_cpu(event_data
->PreviousValue
), state
));
4879 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4880 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
4881 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4884 case MPI2_RAID_PD_STATE_ONLINE
:
4885 case MPI2_RAID_PD_STATE_DEGRADED
:
4886 case MPI2_RAID_PD_STATE_REBUILDING
:
4887 case MPI2_RAID_PD_STATE_OPTIMAL
:
4889 sas_device
->hidden_raid_component
= 1;
4893 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
4894 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
4896 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4897 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4901 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4902 MPI2_IOCSTATUS_MASK
;
4903 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4904 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4905 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4909 mpt2sas_transport_update_links(ioc
,
4910 le16_to_cpu(sas_device_pg0
.ParentDevHandle
),
4911 handle
, sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
4913 _scsih_add_device(ioc
, handle
, 0, 1);
4917 case MPI2_RAID_PD_STATE_OFFLINE
:
4918 case MPI2_RAID_PD_STATE_NOT_CONFIGURED
:
4919 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE
:
4920 case MPI2_RAID_PD_STATE_HOT_SPARE
:
4926 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4928 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
4929 * @ioc: per adapter object
4930 * @event_data: event data payload
4936 _scsih_sas_ir_operation_status_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
4937 Mpi2EventDataIrOperationStatus_t
*event_data
)
4939 char *reason_str
= NULL
;
4941 switch (event_data
->RAIDOperation
) {
4942 case MPI2_EVENT_IR_RAIDOP_RESYNC
:
4943 reason_str
= "resync";
4945 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION
:
4946 reason_str
= "online capacity expansion";
4948 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK
:
4949 reason_str
= "consistency check";
4952 reason_str
= "unknown reason";
4956 printk(MPT2SAS_INFO_FMT
"raid operational status: (%s)"
4957 "\thandle(0x%04x), percent complete(%d)\n",
4958 ioc
->name
, reason_str
,
4959 le16_to_cpu(event_data
->VolDevHandle
),
4960 event_data
->PercentComplete
);
4965 * _scsih_sas_ir_operation_status_event - handle RAID operation events
4966 * @ioc: per adapter object
4967 * @fw_event: The fw_event_work object
4973 _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER
*ioc
,
4974 struct fw_event_work
*fw_event
)
4976 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4977 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
4978 _scsih_sas_ir_operation_status_event_debug(ioc
,
4979 fw_event
->event_data
);
4984 * _scsih_task_set_full - handle task set full
4985 * @ioc: per adapter object
4986 * @fw_event: The fw_event_work object
4989 * Throttle back qdepth.
4992 _scsih_task_set_full(struct MPT2SAS_ADAPTER
*ioc
, struct fw_event_work
4995 unsigned long flags
;
4996 struct _sas_device
*sas_device
;
4997 static struct _raid_device
*raid_device
;
4998 struct scsi_device
*sdev
;
5004 Mpi2EventDataTaskSetFull_t
*event_data
= fw_event
->event_data
;
5006 current_depth
= le16_to_cpu(event_data
->CurrentDepth
);
5007 handle
= le16_to_cpu(event_data
->DevHandle
);
5008 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5009 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
5011 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5014 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5015 id
= sas_device
->id
;
5016 channel
= sas_device
->channel
;
5017 sas_address
= sas_device
->sas_address
;
5019 /* if hidden raid component, then change to volume characteristics */
5020 if (sas_device
->hidden_raid_component
&& sas_device
->volume_handle
) {
5021 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5022 raid_device
= _scsih_raid_device_find_by_handle(
5023 ioc
, sas_device
->volume_handle
);
5024 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5026 id
= raid_device
->id
;
5027 channel
= raid_device
->channel
;
5028 handle
= raid_device
->handle
;
5029 sas_address
= raid_device
->wwid
;
5033 if (ioc
->logging_level
& MPT_DEBUG_TASK_SET_FULL
)
5034 starget_printk(KERN_DEBUG
, sas_device
->starget
, "task set "
5035 "full: handle(0x%04x), sas_addr(0x%016llx), depth(%d)\n",
5036 handle
, (unsigned long long)sas_address
, current_depth
);
5038 shost_for_each_device(sdev
, ioc
->shost
) {
5039 if (sdev
->id
== id
&& sdev
->channel
== channel
) {
5040 if (current_depth
> sdev
->queue_depth
) {
5041 if (ioc
->logging_level
&
5042 MPT_DEBUG_TASK_SET_FULL
)
5043 sdev_printk(KERN_INFO
, sdev
, "strange "
5044 "observation, the queue depth is"
5045 " (%d) meanwhile fw queue depth "
5046 "is (%d)\n", sdev
->queue_depth
,
5050 depth
= scsi_track_queue_full(sdev
,
5053 sdev_printk(KERN_INFO
, sdev
, "Queue depth "
5054 "reduced to (%d)\n", depth
);
5056 sdev_printk(KERN_INFO
, sdev
, "Tagged Command "
5057 "Queueing is being disabled\n");
5058 else if (depth
== 0)
5059 if (ioc
->logging_level
&
5060 MPT_DEBUG_TASK_SET_FULL
)
5061 sdev_printk(KERN_INFO
, sdev
,
5062 "Queue depth not changed yet\n");
5068 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
5069 * @ioc: per adapter object
5070 * @sas_address: sas address
5071 * @slot: enclosure slot id
5072 * @handle: device handle
5074 * After host reset, find out whether devices are still responding.
5075 * Used in _scsi_remove_unresponsive_sas_devices.
5080 _scsih_mark_responding_sas_device(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
,
5081 u16 slot
, u16 handle
)
5083 struct MPT2SAS_TARGET
*sas_target_priv_data
;
5084 struct scsi_target
*starget
;
5085 struct _sas_device
*sas_device
;
5086 unsigned long flags
;
5088 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5089 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
) {
5090 if (sas_device
->sas_address
== sas_address
&&
5091 sas_device
->slot
== slot
&& sas_device
->starget
) {
5092 sas_device
->responding
= 1;
5093 sas_device
->state
= 0;
5094 starget
= sas_device
->starget
;
5095 sas_target_priv_data
= starget
->hostdata
;
5096 sas_target_priv_data
->tm_busy
= 0;
5097 starget_printk(KERN_INFO
, sas_device
->starget
,
5098 "handle(0x%04x), sas_addr(0x%016llx), enclosure "
5099 "logical id(0x%016llx), slot(%d)\n", handle
,
5100 (unsigned long long)sas_device
->sas_address
,
5101 (unsigned long long)
5102 sas_device
->enclosure_logical_id
,
5104 if (sas_device
->handle
== handle
)
5106 printk(KERN_INFO
"\thandle changed from(0x%04x)!!!\n",
5107 sas_device
->handle
);
5108 sas_device
->handle
= handle
;
5109 sas_target_priv_data
->handle
= handle
;
5114 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5118 * _scsih_search_responding_sas_devices -
5119 * @ioc: per adapter object
5121 * After host reset, find out whether devices are still responding.
5127 _scsih_search_responding_sas_devices(struct MPT2SAS_ADAPTER
*ioc
)
5129 Mpi2SasDevicePage0_t sas_device_pg0
;
5130 Mpi2ConfigReply_t mpi_reply
;
5137 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
, __func__
);
5139 if (list_empty(&ioc
->sas_device_list
))
5143 while (!(mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
5144 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
,
5146 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5147 MPI2_IOCSTATUS_MASK
;
5148 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
5150 handle
= le16_to_cpu(sas_device_pg0
.DevHandle
);
5151 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
5152 if (!(_scsih_is_end_device(device_info
)))
5154 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
5155 slot
= le16_to_cpu(sas_device_pg0
.Slot
);
5156 _scsih_mark_responding_sas_device(ioc
, sas_address
, slot
,
5162 * _scsih_mark_responding_raid_device - mark a raid_device as responding
5163 * @ioc: per adapter object
5164 * @wwid: world wide identifier for raid volume
5165 * @handle: device handle
5167 * After host reset, find out whether devices are still responding.
5168 * Used in _scsi_remove_unresponsive_raid_devices.
5173 _scsih_mark_responding_raid_device(struct MPT2SAS_ADAPTER
*ioc
, u64 wwid
,
5176 struct MPT2SAS_TARGET
*sas_target_priv_data
;
5177 struct scsi_target
*starget
;
5178 struct _raid_device
*raid_device
;
5179 unsigned long flags
;
5181 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5182 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
5183 if (raid_device
->wwid
== wwid
&& raid_device
->starget
) {
5184 raid_device
->responding
= 1;
5185 starget_printk(KERN_INFO
, raid_device
->starget
,
5186 "handle(0x%04x), wwid(0x%016llx)\n", handle
,
5187 (unsigned long long)raid_device
->wwid
);
5188 if (raid_device
->handle
== handle
)
5190 printk(KERN_INFO
"\thandle changed from(0x%04x)!!!\n",
5191 raid_device
->handle
);
5192 raid_device
->handle
= handle
;
5193 starget
= raid_device
->starget
;
5194 sas_target_priv_data
= starget
->hostdata
;
5195 sas_target_priv_data
->handle
= handle
;
5200 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5204 * _scsih_search_responding_raid_devices -
5205 * @ioc: per adapter object
5207 * After host reset, find out whether devices are still responding.
5213 _scsih_search_responding_raid_devices(struct MPT2SAS_ADAPTER
*ioc
)
5215 Mpi2RaidVolPage1_t volume_pg1
;
5216 Mpi2ConfigReply_t mpi_reply
;
5220 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
, __func__
);
5222 if (list_empty(&ioc
->raid_device_list
))
5226 while (!(mpt2sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
5227 &volume_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
5228 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5229 MPI2_IOCSTATUS_MASK
;
5230 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
5232 handle
= le16_to_cpu(volume_pg1
.DevHandle
);
5233 _scsih_mark_responding_raid_device(ioc
,
5234 le64_to_cpu(volume_pg1
.WWID
), handle
);
5239 * _scsih_mark_responding_expander - mark a expander as responding
5240 * @ioc: per adapter object
5241 * @sas_address: sas address
5244 * After host reset, find out whether devices are still responding.
5245 * Used in _scsi_remove_unresponsive_expanders.
5250 _scsih_mark_responding_expander(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
,
5253 struct _sas_node
*sas_expander
;
5254 unsigned long flags
;
5256 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5257 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
5258 if (sas_expander
->sas_address
== sas_address
) {
5259 sas_expander
->responding
= 1;
5260 if (sas_expander
->handle
!= handle
) {
5261 printk(KERN_INFO
"old handle(0x%04x)\n",
5262 sas_expander
->handle
);
5263 sas_expander
->handle
= handle
;
5269 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5273 * _scsih_search_responding_expanders -
5274 * @ioc: per adapter object
5276 * After host reset, find out whether devices are still responding.
5282 _scsih_search_responding_expanders(struct MPT2SAS_ADAPTER
*ioc
)
5284 Mpi2ExpanderPage0_t expander_pg0
;
5285 Mpi2ConfigReply_t mpi_reply
;
5290 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
, __func__
);
5292 if (list_empty(&ioc
->sas_expander_list
))
5296 while (!(mpt2sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
5297 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL
, handle
))) {
5299 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5300 MPI2_IOCSTATUS_MASK
;
5301 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
5304 handle
= le16_to_cpu(expander_pg0
.DevHandle
);
5305 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
5306 printk(KERN_INFO
"\texpander present: handle(0x%04x), "
5307 "sas_addr(0x%016llx)\n", handle
,
5308 (unsigned long long)sas_address
);
5309 _scsih_mark_responding_expander(ioc
, sas_address
, handle
);
5315 * _scsih_remove_unresponding_devices - removing unresponding devices
5316 * @ioc: per adapter object
5321 _scsih_remove_unresponding_devices(struct MPT2SAS_ADAPTER
*ioc
)
5323 struct _sas_device
*sas_device
, *sas_device_next
;
5324 struct _sas_node
*sas_expander
;
5325 struct _raid_device
*raid_device
, *raid_device_next
;
5328 list_for_each_entry_safe(sas_device
, sas_device_next
,
5329 &ioc
->sas_device_list
, list
) {
5330 if (sas_device
->responding
) {
5331 sas_device
->responding
= 0;
5334 if (sas_device
->starget
)
5335 starget_printk(KERN_INFO
, sas_device
->starget
,
5336 "removing: handle(0x%04x), sas_addr(0x%016llx), "
5337 "enclosure logical id(0x%016llx), slot(%d)\n",
5339 (unsigned long long)sas_device
->sas_address
,
5340 (unsigned long long)
5341 sas_device
->enclosure_logical_id
,
5343 _scsih_remove_device(ioc
, sas_device
->handle
);
5346 list_for_each_entry_safe(raid_device
, raid_device_next
,
5347 &ioc
->raid_device_list
, list
) {
5348 if (raid_device
->responding
) {
5349 raid_device
->responding
= 0;
5352 if (raid_device
->starget
) {
5353 starget_printk(KERN_INFO
, raid_device
->starget
,
5354 "removing: handle(0x%04x), wwid(0x%016llx)\n",
5355 raid_device
->handle
,
5356 (unsigned long long)raid_device
->wwid
);
5357 scsi_remove_target(&raid_device
->starget
->dev
);
5359 _scsih_raid_device_remove(ioc
, raid_device
);
5362 retry_expander_search
:
5363 sas_expander
= NULL
;
5364 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
5365 if (sas_expander
->responding
) {
5366 sas_expander
->responding
= 0;
5369 _scsih_expander_remove(ioc
, sas_expander
->handle
);
5370 goto retry_expander_search
;
5375 * mpt2sas_scsih_reset_handler - reset callback handler (for scsih)
5376 * @ioc: per adapter object
5377 * @reset_phase: phase
5379 * The handler for doing any required cleanup or initialization.
5381 * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
5382 * MPT2_IOC_DONE_RESET
5387 mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER
*ioc
, int reset_phase
)
5389 switch (reset_phase
) {
5390 case MPT2_IOC_PRE_RESET
:
5391 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: "
5392 "MPT2_IOC_PRE_RESET\n", ioc
->name
, __func__
));
5393 _scsih_fw_event_off(ioc
);
5395 case MPT2_IOC_AFTER_RESET
:
5396 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: "
5397 "MPT2_IOC_AFTER_RESET\n", ioc
->name
, __func__
));
5398 if (ioc
->tm_cmds
.status
& MPT2_CMD_PENDING
) {
5399 ioc
->tm_cmds
.status
|= MPT2_CMD_RESET
;
5400 mpt2sas_base_free_smid(ioc
, ioc
->tm_cmds
.smid
);
5401 complete(&ioc
->tm_cmds
.done
);
5403 _scsih_fw_event_on(ioc
);
5404 _scsih_flush_running_cmds(ioc
);
5406 case MPT2_IOC_DONE_RESET
:
5407 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: "
5408 "MPT2_IOC_DONE_RESET\n", ioc
->name
, __func__
));
5409 _scsih_sas_host_refresh(ioc
, 0);
5410 _scsih_search_responding_sas_devices(ioc
);
5411 _scsih_search_responding_raid_devices(ioc
);
5412 _scsih_search_responding_expanders(ioc
);
5414 case MPT2_IOC_RUNNING
:
5415 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: "
5416 "MPT2_IOC_RUNNING\n", ioc
->name
, __func__
));
5417 _scsih_remove_unresponding_devices(ioc
);
5423 * _firmware_event_work - delayed task for processing firmware events
5424 * @ioc: per adapter object
5425 * @work: equal to the fw_event_work object
5431 _firmware_event_work(struct work_struct
*work
)
5433 struct fw_event_work
*fw_event
= container_of(work
,
5434 struct fw_event_work
, work
);
5435 unsigned long flags
;
5436 struct MPT2SAS_ADAPTER
*ioc
= fw_event
->ioc
;
5438 /* the queue is being flushed so ignore this event */
5439 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
5440 if (ioc
->fw_events_off
|| ioc
->remove_host
) {
5441 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
5442 _scsih_fw_event_free(ioc
, fw_event
);
5445 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
5447 if (ioc
->shost_recovery
) {
5448 _scsih_fw_event_requeue(ioc
, fw_event
, 1000);
5452 switch (fw_event
->event
) {
5453 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
5454 _scsih_sas_topology_change_event(ioc
, fw_event
);
5456 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
5457 _scsih_sas_device_status_change_event(ioc
,
5460 case MPI2_EVENT_SAS_DISCOVERY
:
5461 _scsih_sas_discovery_event(ioc
,
5464 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
5465 _scsih_sas_broadcast_primative_event(ioc
,
5468 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
5469 _scsih_sas_enclosure_dev_status_change_event(ioc
,
5472 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
5473 _scsih_sas_ir_config_change_event(ioc
, fw_event
);
5475 case MPI2_EVENT_IR_VOLUME
:
5476 _scsih_sas_ir_volume_event(ioc
, fw_event
);
5478 case MPI2_EVENT_IR_PHYSICAL_DISK
:
5479 _scsih_sas_ir_physical_disk_event(ioc
, fw_event
);
5481 case MPI2_EVENT_IR_OPERATION_STATUS
:
5482 _scsih_sas_ir_operation_status_event(ioc
, fw_event
);
5484 case MPI2_EVENT_TASK_SET_FULL
:
5485 _scsih_task_set_full(ioc
, fw_event
);
5488 _scsih_fw_event_free(ioc
, fw_event
);
5492 * mpt2sas_scsih_event_callback - firmware event handler (called at ISR time)
5493 * @ioc: per adapter object
5494 * @msix_index: MSIX table index supplied by the OS
5495 * @reply: reply message frame(lower 32bit addr)
5496 * Context: interrupt.
5498 * This function merely adds a new work task into ioc->firmware_event_thread.
5499 * The tasks are worked from _firmware_event_work in user context.
5501 * Return 1 meaning mf should be freed from _base_interrupt
5502 * 0 means the mf is freed from this function.
5505 mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER
*ioc
, u8 msix_index
,
5508 struct fw_event_work
*fw_event
;
5509 Mpi2EventNotificationReply_t
*mpi_reply
;
5510 unsigned long flags
;
5513 /* events turned off due to host reset or driver unloading */
5514 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
5515 if (ioc
->fw_events_off
|| ioc
->remove_host
) {
5516 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
5519 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
5521 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
5522 event
= le16_to_cpu(mpi_reply
->Event
);
5526 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
5528 Mpi2EventDataSasBroadcastPrimitive_t
*baen_data
=
5529 (Mpi2EventDataSasBroadcastPrimitive_t
*)
5530 mpi_reply
->EventData
;
5532 if (baen_data
->Primitive
!=
5533 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT
||
5534 ioc
->broadcast_aen_busy
)
5536 ioc
->broadcast_aen_busy
= 1;
5540 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
5541 _scsih_check_topo_delete_events(ioc
,
5542 (Mpi2EventDataSasTopologyChangeList_t
*)
5543 mpi_reply
->EventData
);
5546 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
5547 case MPI2_EVENT_IR_OPERATION_STATUS
:
5548 case MPI2_EVENT_SAS_DISCOVERY
:
5549 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
5550 case MPI2_EVENT_IR_VOLUME
:
5551 case MPI2_EVENT_IR_PHYSICAL_DISK
:
5552 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
5553 case MPI2_EVENT_TASK_SET_FULL
:
5556 default: /* ignore the rest */
5560 fw_event
= kzalloc(sizeof(struct fw_event_work
), GFP_ATOMIC
);
5562 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5563 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5566 fw_event
->event_data
=
5567 kzalloc(mpi_reply
->EventDataLength
*4, GFP_ATOMIC
);
5568 if (!fw_event
->event_data
) {
5569 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5570 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5575 memcpy(fw_event
->event_data
, mpi_reply
->EventData
,
5576 mpi_reply
->EventDataLength
*4);
5577 fw_event
->ioc
= ioc
;
5578 fw_event
->VF_ID
= mpi_reply
->VF_ID
;
5579 fw_event
->VP_ID
= mpi_reply
->VP_ID
;
5580 fw_event
->event
= event
;
5581 _scsih_fw_event_add(ioc
, fw_event
);
5585 /* shost template */
5586 static struct scsi_host_template scsih_driver_template
= {
5587 .module
= THIS_MODULE
,
5588 .name
= "Fusion MPT SAS Host",
5589 .proc_name
= MPT2SAS_DRIVER_NAME
,
5590 .queuecommand
= _scsih_qcmd
,
5591 .target_alloc
= _scsih_target_alloc
,
5592 .slave_alloc
= _scsih_slave_alloc
,
5593 .slave_configure
= _scsih_slave_configure
,
5594 .target_destroy
= _scsih_target_destroy
,
5595 .slave_destroy
= _scsih_slave_destroy
,
5596 .change_queue_depth
= _scsih_change_queue_depth
,
5597 .change_queue_type
= _scsih_change_queue_type
,
5598 .eh_abort_handler
= _scsih_abort
,
5599 .eh_device_reset_handler
= _scsih_dev_reset
,
5600 .eh_target_reset_handler
= _scsih_target_reset
,
5601 .eh_host_reset_handler
= _scsih_host_reset
,
5602 .bios_param
= _scsih_bios_param
,
5605 .sg_tablesize
= MPT2SAS_SG_DEPTH
,
5606 .max_sectors
= 8192,
5608 .use_clustering
= ENABLE_CLUSTERING
,
5609 .shost_attrs
= mpt2sas_host_attrs
,
5610 .sdev_attrs
= mpt2sas_dev_attrs
,
5614 * _scsih_expander_node_remove - removing expander device from list.
5615 * @ioc: per adapter object
5616 * @sas_expander: the sas_device object
5617 * Context: Calling function should acquire ioc->sas_node_lock.
5619 * Removing object and freeing associated memory from the
5620 * ioc->sas_expander_list.
5625 _scsih_expander_node_remove(struct MPT2SAS_ADAPTER
*ioc
,
5626 struct _sas_node
*sas_expander
)
5628 struct _sas_port
*mpt2sas_port
;
5629 struct _sas_device
*sas_device
;
5630 struct _sas_node
*expander_sibling
;
5631 unsigned long flags
;
5636 /* remove sibling ports attached to this expander */
5637 retry_device_search
:
5638 list_for_each_entry(mpt2sas_port
,
5639 &sas_expander
->sas_port_list
, port_list
) {
5640 if (mpt2sas_port
->remote_identify
.device_type
==
5642 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5644 mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
5645 mpt2sas_port
->remote_identify
.sas_address
);
5646 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5649 _scsih_remove_device(ioc
, sas_device
->handle
);
5650 if (ioc
->shost_recovery
)
5652 goto retry_device_search
;
5656 retry_expander_search
:
5657 list_for_each_entry(mpt2sas_port
,
5658 &sas_expander
->sas_port_list
, port_list
) {
5660 if (mpt2sas_port
->remote_identify
.device_type
==
5661 MPI2_SAS_DEVICE_INFO_EDGE_EXPANDER
||
5662 mpt2sas_port
->remote_identify
.device_type
==
5663 MPI2_SAS_DEVICE_INFO_FANOUT_EXPANDER
) {
5665 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5667 mpt2sas_scsih_expander_find_by_sas_address(
5668 ioc
, mpt2sas_port
->remote_identify
.sas_address
);
5669 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5670 if (!expander_sibling
)
5672 _scsih_expander_remove(ioc
, expander_sibling
->handle
);
5673 if (ioc
->shost_recovery
)
5675 goto retry_expander_search
;
5679 mpt2sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
5680 sas_expander
->parent_handle
);
5682 printk(MPT2SAS_INFO_FMT
"expander_remove: handle"
5683 "(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
5684 sas_expander
->handle
, (unsigned long long)
5685 sas_expander
->sas_address
);
5687 list_del(&sas_expander
->list
);
5688 kfree(sas_expander
->phy
);
5689 kfree(sas_expander
);
5693 * _scsih_remove - detach and remove add host
5694 * @pdev: PCI device struct
5698 static void __devexit
5699 _scsih_remove(struct pci_dev
*pdev
)
5701 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
5702 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
5703 struct _sas_port
*mpt2sas_port
;
5704 struct _sas_device
*sas_device
;
5705 struct _sas_node
*expander_sibling
;
5706 struct workqueue_struct
*wq
;
5707 unsigned long flags
;
5709 ioc
->remove_host
= 1;
5710 _scsih_fw_event_off(ioc
);
5712 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
5713 wq
= ioc
->firmware_event_thread
;
5714 ioc
->firmware_event_thread
= NULL
;
5715 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
5717 destroy_workqueue(wq
);
5719 /* free ports attached to the sas_host */
5721 list_for_each_entry(mpt2sas_port
,
5722 &ioc
->sas_hba
.sas_port_list
, port_list
) {
5723 if (mpt2sas_port
->remote_identify
.device_type
==
5726 mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
5727 mpt2sas_port
->remote_identify
.sas_address
);
5729 _scsih_remove_device(ioc
, sas_device
->handle
);
5734 mpt2sas_scsih_expander_find_by_sas_address(ioc
,
5735 mpt2sas_port
->remote_identify
.sas_address
);
5736 if (expander_sibling
) {
5737 _scsih_expander_remove(ioc
,
5738 expander_sibling
->handle
);
5744 /* free phys attached to the sas_host */
5745 if (ioc
->sas_hba
.num_phys
) {
5746 kfree(ioc
->sas_hba
.phy
);
5747 ioc
->sas_hba
.phy
= NULL
;
5748 ioc
->sas_hba
.num_phys
= 0;
5751 sas_remove_host(shost
);
5752 mpt2sas_base_detach(ioc
);
5753 list_del(&ioc
->list
);
5754 scsi_remove_host(shost
);
5755 scsi_host_put(shost
);
5759 * _scsih_probe_boot_devices - reports 1st device
5760 * @ioc: per adapter object
5762 * If specified in bios page 2, this routine reports the 1st
5763 * device scsi-ml or sas transport for persistent boot device
5764 * purposes. Please refer to function _scsih_determine_boot_device()
5767 _scsih_probe_boot_devices(struct MPT2SAS_ADAPTER
*ioc
)
5771 struct _sas_device
*sas_device
;
5772 struct _raid_device
*raid_device
;
5773 u16 handle
, parent_handle
;
5775 unsigned long flags
;
5779 if (ioc
->req_boot_device
.device
) {
5780 device
= ioc
->req_boot_device
.device
;
5781 is_raid
= ioc
->req_boot_device
.is_raid
;
5782 } else if (ioc
->req_alt_boot_device
.device
) {
5783 device
= ioc
->req_alt_boot_device
.device
;
5784 is_raid
= ioc
->req_alt_boot_device
.is_raid
;
5785 } else if (ioc
->current_boot_device
.device
) {
5786 device
= ioc
->current_boot_device
.device
;
5787 is_raid
= ioc
->current_boot_device
.is_raid
;
5794 raid_device
= device
;
5795 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
5796 raid_device
->id
, 0);
5798 _scsih_raid_device_remove(ioc
, raid_device
);
5800 sas_device
= device
;
5801 handle
= sas_device
->handle
;
5802 parent_handle
= sas_device
->parent_handle
;
5803 sas_address
= sas_device
->sas_address
;
5804 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5805 list_move_tail(&sas_device
->list
, &ioc
->sas_device_list
);
5806 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5807 if (!mpt2sas_transport_port_add(ioc
, sas_device
->handle
,
5808 sas_device
->parent_handle
)) {
5809 _scsih_sas_device_remove(ioc
, sas_device
);
5810 } else if (!sas_device
->starget
) {
5811 mpt2sas_transport_port_remove(ioc
, sas_address
,
5813 _scsih_sas_device_remove(ioc
, sas_device
);
5819 * _scsih_probe_raid - reporting raid volumes to scsi-ml
5820 * @ioc: per adapter object
5822 * Called during initial loading of the driver.
5825 _scsih_probe_raid(struct MPT2SAS_ADAPTER
*ioc
)
5827 struct _raid_device
*raid_device
, *raid_next
;
5830 list_for_each_entry_safe(raid_device
, raid_next
,
5831 &ioc
->raid_device_list
, list
) {
5832 if (raid_device
->starget
)
5834 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
5835 raid_device
->id
, 0);
5837 _scsih_raid_device_remove(ioc
, raid_device
);
5842 * _scsih_probe_sas - reporting sas devices to sas transport
5843 * @ioc: per adapter object
5845 * Called during initial loading of the driver.
5848 _scsih_probe_sas(struct MPT2SAS_ADAPTER
*ioc
)
5850 struct _sas_device
*sas_device
, *next
;
5851 unsigned long flags
;
5852 u16 handle
, parent_handle
;
5855 /* SAS Device List */
5856 list_for_each_entry_safe(sas_device
, next
, &ioc
->sas_device_init_list
,
5858 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5859 list_move_tail(&sas_device
->list
, &ioc
->sas_device_list
);
5860 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5862 handle
= sas_device
->handle
;
5863 parent_handle
= sas_device
->parent_handle
;
5864 sas_address
= sas_device
->sas_address
;
5865 if (!mpt2sas_transport_port_add(ioc
, handle
, parent_handle
)) {
5866 _scsih_sas_device_remove(ioc
, sas_device
);
5867 } else if (!sas_device
->starget
) {
5868 mpt2sas_transport_port_remove(ioc
, sas_address
,
5870 _scsih_sas_device_remove(ioc
, sas_device
);
5876 * _scsih_probe_devices - probing for devices
5877 * @ioc: per adapter object
5879 * Called during initial loading of the driver.
5882 _scsih_probe_devices(struct MPT2SAS_ADAPTER
*ioc
)
5884 u16 volume_mapping_flags
=
5885 le16_to_cpu(ioc
->ioc_pg8
.IRVolumeMappingFlags
) &
5886 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE
;
5888 if (!(ioc
->facts
.ProtocolFlags
& MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR
))
5889 return; /* return when IOC doesn't support initiator mode */
5891 _scsih_probe_boot_devices(ioc
);
5893 if (ioc
->ir_firmware
) {
5894 if ((volume_mapping_flags
&
5895 MPI2_IOCPAGE8_IRFLAGS_HIGH_VOLUME_MAPPING
)) {
5896 _scsih_probe_sas(ioc
);
5897 _scsih_probe_raid(ioc
);
5899 _scsih_probe_raid(ioc
);
5900 _scsih_probe_sas(ioc
);
5903 _scsih_probe_sas(ioc
);
5907 * _scsih_probe - attach and add scsi host
5908 * @pdev: PCI device struct
5909 * @id: pci device id
5911 * Returns 0 success, anything else error.
5914 _scsih_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
5916 struct MPT2SAS_ADAPTER
*ioc
;
5917 struct Scsi_Host
*shost
;
5919 shost
= scsi_host_alloc(&scsih_driver_template
,
5920 sizeof(struct MPT2SAS_ADAPTER
));
5924 /* init local params */
5925 ioc
= shost_priv(shost
);
5926 memset(ioc
, 0, sizeof(struct MPT2SAS_ADAPTER
));
5927 INIT_LIST_HEAD(&ioc
->list
);
5928 list_add_tail(&ioc
->list
, &mpt2sas_ioc_list
);
5930 ioc
->id
= mpt_ids
++;
5931 sprintf(ioc
->name
, "%s%d", MPT2SAS_DRIVER_NAME
, ioc
->id
);
5933 ioc
->scsi_io_cb_idx
= scsi_io_cb_idx
;
5934 ioc
->tm_cb_idx
= tm_cb_idx
;
5935 ioc
->ctl_cb_idx
= ctl_cb_idx
;
5936 ioc
->base_cb_idx
= base_cb_idx
;
5937 ioc
->transport_cb_idx
= transport_cb_idx
;
5938 ioc
->config_cb_idx
= config_cb_idx
;
5939 ioc
->tm_tr_cb_idx
= tm_tr_cb_idx
;
5940 ioc
->tm_sas_control_cb_idx
= tm_sas_control_cb_idx
;
5941 ioc
->logging_level
= logging_level
;
5942 /* misc semaphores and spin locks */
5943 spin_lock_init(&ioc
->ioc_reset_in_progress_lock
);
5944 spin_lock_init(&ioc
->scsi_lookup_lock
);
5945 spin_lock_init(&ioc
->sas_device_lock
);
5946 spin_lock_init(&ioc
->sas_node_lock
);
5947 spin_lock_init(&ioc
->fw_event_lock
);
5948 spin_lock_init(&ioc
->raid_device_lock
);
5950 INIT_LIST_HEAD(&ioc
->sas_device_list
);
5951 INIT_LIST_HEAD(&ioc
->sas_device_init_list
);
5952 INIT_LIST_HEAD(&ioc
->sas_expander_list
);
5953 INIT_LIST_HEAD(&ioc
->fw_event_list
);
5954 INIT_LIST_HEAD(&ioc
->raid_device_list
);
5955 INIT_LIST_HEAD(&ioc
->sas_hba
.sas_port_list
);
5956 INIT_LIST_HEAD(&ioc
->delayed_tr_list
);
5958 /* init shost parameters */
5959 shost
->max_cmd_len
= 16;
5960 shost
->max_lun
= max_lun
;
5961 shost
->transportt
= mpt2sas_transport_template
;
5962 shost
->unique_id
= ioc
->id
;
5964 if ((scsi_add_host(shost
, &pdev
->dev
))) {
5965 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5966 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5967 list_del(&ioc
->list
);
5968 goto out_add_shost_fail
;
5971 scsi_host_set_prot(shost
, SHOST_DIF_TYPE1_PROTECTION
5972 | SHOST_DIF_TYPE3_PROTECTION
);
5973 scsi_host_set_guard(shost
, SHOST_DIX_GUARD_CRC
);
5976 snprintf(ioc
->firmware_event_name
, sizeof(ioc
->firmware_event_name
),
5977 "fw_event%d", ioc
->id
);
5978 ioc
->firmware_event_thread
= create_singlethread_workqueue(
5979 ioc
->firmware_event_name
);
5980 if (!ioc
->firmware_event_thread
) {
5981 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5982 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5983 goto out_thread_fail
;
5986 ioc
->wait_for_port_enable_to_complete
= 1;
5987 if ((mpt2sas_base_attach(ioc
))) {
5988 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5989 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5990 goto out_attach_fail
;
5993 ioc
->wait_for_port_enable_to_complete
= 0;
5994 _scsih_probe_devices(ioc
);
5998 destroy_workqueue(ioc
->firmware_event_thread
);
6000 list_del(&ioc
->list
);
6001 scsi_remove_host(shost
);
6008 * _scsih_suspend - power management suspend main entry point
6009 * @pdev: PCI device struct
6010 * @state: PM state change to (usually PCI_D3)
6012 * Returns 0 success, anything else error.
6015 _scsih_suspend(struct pci_dev
*pdev
, pm_message_t state
)
6017 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6018 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
6021 mpt2sas_base_stop_watchdog(ioc
);
6022 flush_scheduled_work();
6023 scsi_block_requests(shost
);
6024 device_state
= pci_choose_state(pdev
, state
);
6025 printk(MPT2SAS_INFO_FMT
"pdev=0x%p, slot=%s, entering "
6026 "operating state [D%d]\n", ioc
->name
, pdev
,
6027 pci_name(pdev
), device_state
);
6029 mpt2sas_base_free_resources(ioc
);
6030 pci_save_state(pdev
);
6031 pci_disable_device(pdev
);
6032 pci_set_power_state(pdev
, device_state
);
6037 * _scsih_resume - power management resume main entry point
6038 * @pdev: PCI device struct
6040 * Returns 0 success, anything else error.
6043 _scsih_resume(struct pci_dev
*pdev
)
6045 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
6046 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
6047 u32 device_state
= pdev
->current_state
;
6050 printk(MPT2SAS_INFO_FMT
"pdev=0x%p, slot=%s, previous "
6051 "operating state [D%d]\n", ioc
->name
, pdev
,
6052 pci_name(pdev
), device_state
);
6054 pci_set_power_state(pdev
, PCI_D0
);
6055 pci_enable_wake(pdev
, PCI_D0
, 0);
6056 pci_restore_state(pdev
);
6058 r
= mpt2sas_base_map_resources(ioc
);
6062 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
, SOFT_RESET
);
6063 scsi_unblock_requests(shost
);
6064 mpt2sas_base_start_watchdog(ioc
);
6067 #endif /* CONFIG_PM */
6070 static struct pci_driver scsih_driver
= {
6071 .name
= MPT2SAS_DRIVER_NAME
,
6072 .id_table
= scsih_pci_table
,
6073 .probe
= _scsih_probe
,
6074 .remove
= __devexit_p(_scsih_remove
),
6076 .suspend
= _scsih_suspend
,
6077 .resume
= _scsih_resume
,
6083 * _scsih_init - main entry point for this driver.
6085 * Returns 0 success, anything else error.
6093 printk(KERN_INFO
"%s version %s loaded\n", MPT2SAS_DRIVER_NAME
,
6094 MPT2SAS_DRIVER_VERSION
);
6096 mpt2sas_transport_template
=
6097 sas_attach_transport(&mpt2sas_transport_functions
);
6098 if (!mpt2sas_transport_template
)
6101 mpt2sas_base_initialize_callback_handler();
6103 /* queuecommand callback hander */
6104 scsi_io_cb_idx
= mpt2sas_base_register_callback_handler(_scsih_io_done
);
6106 /* task managment callback handler */
6107 tm_cb_idx
= mpt2sas_base_register_callback_handler(_scsih_tm_done
);
6109 /* base internal commands callback handler */
6110 base_cb_idx
= mpt2sas_base_register_callback_handler(mpt2sas_base_done
);
6112 /* transport internal commands callback handler */
6113 transport_cb_idx
= mpt2sas_base_register_callback_handler(
6114 mpt2sas_transport_done
);
6116 /* configuration page API internal commands callback handler */
6117 config_cb_idx
= mpt2sas_base_register_callback_handler(
6118 mpt2sas_config_done
);
6120 /* ctl module callback handler */
6121 ctl_cb_idx
= mpt2sas_base_register_callback_handler(mpt2sas_ctl_done
);
6123 tm_tr_cb_idx
= mpt2sas_base_register_callback_handler(
6124 _scsih_tm_tr_complete
);
6125 tm_sas_control_cb_idx
= mpt2sas_base_register_callback_handler(
6126 _scsih_sas_control_complete
);
6130 error
= pci_register_driver(&scsih_driver
);
6132 sas_release_transport(mpt2sas_transport_template
);
6138 * _scsih_exit - exit point for this driver (when it is a module).
6140 * Returns 0 success, anything else error.
6145 printk(KERN_INFO
"mpt2sas version %s unloading\n",
6146 MPT2SAS_DRIVER_VERSION
);
6148 pci_unregister_driver(&scsih_driver
);
6150 sas_release_transport(mpt2sas_transport_template
);
6151 mpt2sas_base_release_callback_handler(scsi_io_cb_idx
);
6152 mpt2sas_base_release_callback_handler(tm_cb_idx
);
6153 mpt2sas_base_release_callback_handler(base_cb_idx
);
6154 mpt2sas_base_release_callback_handler(transport_cb_idx
);
6155 mpt2sas_base_release_callback_handler(config_cb_idx
);
6156 mpt2sas_base_release_callback_handler(ctl_cb_idx
);
6158 mpt2sas_base_release_callback_handler(tm_tr_cb_idx
);
6159 mpt2sas_base_release_callback_handler(tm_sas_control_cb_idx
);
6164 module_init(_scsih_init
);
6165 module_exit(_scsih_exit
);