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-2008 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 /* command line options */
83 static u32 logging_level
;
84 MODULE_PARM_DESC(logging_level
, " bits for enabling additional logging info "
87 /* scsi-mid layer global parmeter is max_report_luns, which is 511 */
88 #define MPT2SAS_MAX_LUN (16895)
89 static int max_lun
= MPT2SAS_MAX_LUN
;
90 module_param(max_lun
, int, 0);
91 MODULE_PARM_DESC(max_lun
, " max lun, default=16895 ");
94 * struct sense_info - common structure for obtaining sense keys
96 * @asc: additional sense code
97 * @ascq: additional sense code qualifier
106 #define MPT2SAS_RESCAN_AFTER_HOST_RESET (0xFFFF)
108 * struct fw_event_work - firmware event struct
109 * @list: link list framework
110 * @work: work object (ioc->fault_reset_work_q)
111 * @ioc: per adapter object
112 * @VF_ID: virtual function id
113 * @host_reset_handling: handling events during host reset
114 * @ignore: flag meaning this event has been marked to ignore
115 * @event: firmware event MPI2_EVENT_XXX defined in mpt2_ioc.h
116 * @event_data: reply event data payload follows
118 * This object stored on ioc->fw_event_list.
120 struct fw_event_work
{
121 struct list_head list
;
122 struct work_struct work
;
123 struct MPT2SAS_ADAPTER
*ioc
;
125 u8 host_reset_handling
;
132 * struct _scsi_io_transfer - scsi io transfer
133 * @handle: sas device handle (assigned by firmware)
134 * @is_raid: flag set for hidden raid components
135 * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE,
136 * @data_length: data transfer length
137 * @data_dma: dma pointer to data
140 * @cdb_length: cdb length
142 * @valid_reply: flag set for reply message
143 * @timeout: timeout for this command
144 * @sense_length: sense length
145 * @ioc_status: ioc status
146 * @scsi_state: scsi state
147 * @scsi_status: scsi staus
148 * @log_info: log information
149 * @transfer_length: data length transfer when there is a reply message
151 * Used for sending internal scsi commands to devices within this module.
152 * Refer to _scsi_send_scsi_io().
154 struct _scsi_io_transfer
{
157 enum dma_data_direction dir
;
160 u8 sense
[SCSI_SENSE_BUFFERSIZE
];
166 /* the following bits are only valid when 'valid_reply = 1' */
176 * The pci device ids are defined in mpi/mpi2_cnfg.h.
178 static struct pci_device_id scsih_pci_table
[] = {
179 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2004
,
180 PCI_ANY_ID
, PCI_ANY_ID
},
182 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2008
,
183 PCI_ANY_ID
, PCI_ANY_ID
},
184 /* Liberator ~ 2108 */
185 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_1
,
186 PCI_ANY_ID
, PCI_ANY_ID
},
187 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_2
,
188 PCI_ANY_ID
, PCI_ANY_ID
},
189 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_3
,
190 PCI_ANY_ID
, PCI_ANY_ID
},
191 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2116_1
,
192 PCI_ANY_ID
, PCI_ANY_ID
},
193 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2116_2
,
194 PCI_ANY_ID
, PCI_ANY_ID
},
195 {0} /* Terminating entry */
197 MODULE_DEVICE_TABLE(pci
, scsih_pci_table
);
200 * scsih_set_debug_level - global setting of ioc->logging_level.
202 * Note: The logging levels are defined in mpt2sas_debug.h.
205 scsih_set_debug_level(const char *val
, struct kernel_param
*kp
)
207 int ret
= param_set_int(val
, kp
);
208 struct MPT2SAS_ADAPTER
*ioc
;
213 printk(KERN_INFO
"setting logging_level(0x%08x)\n", logging_level
);
214 list_for_each_entry(ioc
, &mpt2sas_ioc_list
, list
)
215 ioc
->logging_level
= logging_level
;
218 module_param_call(logging_level
, scsih_set_debug_level
, param_get_int
,
219 &logging_level
, 0644);
222 * _scsih_srch_boot_sas_address - search based on sas_address
223 * @sas_address: sas address
224 * @boot_device: boot device object from bios page 2
226 * Returns 1 when there's a match, 0 means no match.
229 _scsih_srch_boot_sas_address(u64 sas_address
,
230 Mpi2BootDeviceSasWwid_t
*boot_device
)
232 return (sas_address
== le64_to_cpu(boot_device
->SASAddress
)) ? 1 : 0;
236 * _scsih_srch_boot_device_name - search based on device name
237 * @device_name: device name specified in INDENTIFY fram
238 * @boot_device: boot device object from bios page 2
240 * Returns 1 when there's a match, 0 means no match.
243 _scsih_srch_boot_device_name(u64 device_name
,
244 Mpi2BootDeviceDeviceName_t
*boot_device
)
246 return (device_name
== le64_to_cpu(boot_device
->DeviceName
)) ? 1 : 0;
250 * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot
251 * @enclosure_logical_id: enclosure logical id
252 * @slot_number: slot number
253 * @boot_device: boot device object from bios page 2
255 * Returns 1 when there's a match, 0 means no match.
258 _scsih_srch_boot_encl_slot(u64 enclosure_logical_id
, u16 slot_number
,
259 Mpi2BootDeviceEnclosureSlot_t
*boot_device
)
261 return (enclosure_logical_id
== le64_to_cpu(boot_device
->
262 EnclosureLogicalID
) && slot_number
== le16_to_cpu(boot_device
->
263 SlotNumber
)) ? 1 : 0;
267 * _scsih_is_boot_device - search for matching boot device.
268 * @sas_address: sas address
269 * @device_name: device name specified in INDENTIFY fram
270 * @enclosure_logical_id: enclosure logical id
271 * @slot_number: slot number
272 * @form: specifies boot device form
273 * @boot_device: boot device object from bios page 2
275 * Returns 1 when there's a match, 0 means no match.
278 _scsih_is_boot_device(u64 sas_address
, u64 device_name
,
279 u64 enclosure_logical_id
, u16 slot
, u8 form
,
280 Mpi2BiosPage2BootDevice_t
*boot_device
)
285 case MPI2_BIOSPAGE2_FORM_SAS_WWID
:
288 rc
= _scsih_srch_boot_sas_address(
289 sas_address
, &boot_device
->SasWwid
);
291 case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT
:
292 if (!enclosure_logical_id
)
294 rc
= _scsih_srch_boot_encl_slot(
295 enclosure_logical_id
,
296 slot
, &boot_device
->EnclosureSlot
);
298 case MPI2_BIOSPAGE2_FORM_DEVICE_NAME
:
301 rc
= _scsih_srch_boot_device_name(
302 device_name
, &boot_device
->DeviceName
);
304 case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED
:
312 * _scsih_determine_boot_device - determine boot device.
313 * @ioc: per adapter object
314 * @device: either sas_device or raid_device object
315 * @is_raid: [flag] 1 = raid object, 0 = sas object
317 * Determines whether this device should be first reported device to
318 * to scsi-ml or sas transport, this purpose is for persistant boot device.
319 * There are primary, alternate, and current entries in bios page 2. The order
320 * priority is primary, alternate, then current. This routine saves
321 * the corresponding device object and is_raid flag in the ioc object.
322 * The saved data to be used later in _scsih_probe_boot_devices().
325 _scsih_determine_boot_device(struct MPT2SAS_ADAPTER
*ioc
,
326 void *device
, u8 is_raid
)
328 struct _sas_device
*sas_device
;
329 struct _raid_device
*raid_device
;
332 u64 enclosure_logical_id
;
335 /* only process this function when driver loads */
336 if (!ioc
->wait_for_port_enable_to_complete
)
341 sas_address
= sas_device
->sas_address
;
342 device_name
= sas_device
->device_name
;
343 enclosure_logical_id
= sas_device
->enclosure_logical_id
;
344 slot
= sas_device
->slot
;
346 raid_device
= device
;
347 sas_address
= raid_device
->wwid
;
349 enclosure_logical_id
= 0;
353 if (!ioc
->req_boot_device
.device
) {
354 if (_scsih_is_boot_device(sas_address
, device_name
,
355 enclosure_logical_id
, slot
,
356 (ioc
->bios_pg2
.ReqBootDeviceForm
&
357 MPI2_BIOSPAGE2_FORM_MASK
),
358 &ioc
->bios_pg2
.RequestedBootDevice
)) {
359 dinitprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
360 "%s: req_boot_device(0x%016llx)\n",
362 (unsigned long long)sas_address
));
363 ioc
->req_boot_device
.device
= device
;
364 ioc
->req_boot_device
.is_raid
= is_raid
;
368 if (!ioc
->req_alt_boot_device
.device
) {
369 if (_scsih_is_boot_device(sas_address
, device_name
,
370 enclosure_logical_id
, slot
,
371 (ioc
->bios_pg2
.ReqAltBootDeviceForm
&
372 MPI2_BIOSPAGE2_FORM_MASK
),
373 &ioc
->bios_pg2
.RequestedAltBootDevice
)) {
374 dinitprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
375 "%s: req_alt_boot_device(0x%016llx)\n",
377 (unsigned long long)sas_address
));
378 ioc
->req_alt_boot_device
.device
= device
;
379 ioc
->req_alt_boot_device
.is_raid
= is_raid
;
383 if (!ioc
->current_boot_device
.device
) {
384 if (_scsih_is_boot_device(sas_address
, device_name
,
385 enclosure_logical_id
, slot
,
386 (ioc
->bios_pg2
.CurrentBootDeviceForm
&
387 MPI2_BIOSPAGE2_FORM_MASK
),
388 &ioc
->bios_pg2
.CurrentBootDevice
)) {
389 dinitprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
390 "%s: current_boot_device(0x%016llx)\n",
392 (unsigned long long)sas_address
));
393 ioc
->current_boot_device
.device
= device
;
394 ioc
->current_boot_device
.is_raid
= is_raid
;
400 * mpt2sas_scsih_sas_device_find_by_sas_address - sas device search
401 * @ioc: per adapter object
402 * @sas_address: sas address
403 * Context: Calling function should acquire ioc->sas_device_lock
405 * This searches for sas_device based on sas_address, then return sas_device
409 mpt2sas_scsih_sas_device_find_by_sas_address(struct MPT2SAS_ADAPTER
*ioc
,
412 struct _sas_device
*sas_device
, *r
;
415 /* check the sas_device_init_list */
416 list_for_each_entry(sas_device
, &ioc
->sas_device_init_list
,
418 if (sas_device
->sas_address
!= sas_address
)
424 /* then check the sas_device_list */
425 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
) {
426 if (sas_device
->sas_address
!= sas_address
)
436 * _scsih_sas_device_find_by_handle - sas device search
437 * @ioc: per adapter object
438 * @handle: sas device handle (assigned by firmware)
439 * Context: Calling function should acquire ioc->sas_device_lock
441 * This searches for sas_device based on sas_address, then return sas_device
444 static struct _sas_device
*
445 _scsih_sas_device_find_by_handle(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
447 struct _sas_device
*sas_device
, *r
;
450 if (ioc
->wait_for_port_enable_to_complete
) {
451 list_for_each_entry(sas_device
, &ioc
->sas_device_init_list
,
453 if (sas_device
->handle
!= handle
)
459 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
) {
460 if (sas_device
->handle
!= handle
)
472 * _scsih_sas_device_remove - remove sas_device from list.
473 * @ioc: per adapter object
474 * @sas_device: the sas_device object
475 * Context: This function will acquire ioc->sas_device_lock.
477 * Removing object and freeing associated memory from the ioc->sas_device_list.
480 _scsih_sas_device_remove(struct MPT2SAS_ADAPTER
*ioc
,
481 struct _sas_device
*sas_device
)
485 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
486 list_del(&sas_device
->list
);
487 memset(sas_device
, 0, sizeof(struct _sas_device
));
489 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
493 * _scsih_sas_device_add - insert sas_device to the list.
494 * @ioc: per adapter object
495 * @sas_device: the sas_device object
496 * Context: This function will acquire ioc->sas_device_lock.
498 * Adding new object to the ioc->sas_device_list.
501 _scsih_sas_device_add(struct MPT2SAS_ADAPTER
*ioc
,
502 struct _sas_device
*sas_device
)
505 u16 handle
, parent_handle
;
508 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: handle"
509 "(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
, __func__
,
510 sas_device
->handle
, (unsigned long long)sas_device
->sas_address
));
512 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
513 list_add_tail(&sas_device
->list
, &ioc
->sas_device_list
);
514 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
516 handle
= sas_device
->handle
;
517 parent_handle
= sas_device
->parent_handle
;
518 sas_address
= sas_device
->sas_address
;
519 if (!mpt2sas_transport_port_add(ioc
, handle
, parent_handle
))
520 _scsih_sas_device_remove(ioc
, sas_device
);
524 * _scsih_sas_device_init_add - insert sas_device to the list.
525 * @ioc: per adapter object
526 * @sas_device: the sas_device object
527 * Context: This function will acquire ioc->sas_device_lock.
529 * Adding new object at driver load time to the ioc->sas_device_init_list.
532 _scsih_sas_device_init_add(struct MPT2SAS_ADAPTER
*ioc
,
533 struct _sas_device
*sas_device
)
537 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: handle"
538 "(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
, __func__
,
539 sas_device
->handle
, (unsigned long long)sas_device
->sas_address
));
541 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
542 list_add_tail(&sas_device
->list
, &ioc
->sas_device_init_list
);
543 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
544 _scsih_determine_boot_device(ioc
, sas_device
, 0);
548 * mpt2sas_scsih_expander_find_by_handle - expander device search
549 * @ioc: per adapter object
550 * @handle: expander handle (assigned by firmware)
551 * Context: Calling function should acquire ioc->sas_device_lock
553 * This searches for expander device based on handle, then returns the
557 mpt2sas_scsih_expander_find_by_handle(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
559 struct _sas_node
*sas_expander
, *r
;
562 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
563 if (sas_expander
->handle
!= handle
)
573 * _scsih_raid_device_find_by_id - raid device search
574 * @ioc: per adapter object
575 * @id: sas device target id
576 * @channel: sas device channel
577 * Context: Calling function should acquire ioc->raid_device_lock
579 * This searches for raid_device based on target id, then return raid_device
582 static struct _raid_device
*
583 _scsih_raid_device_find_by_id(struct MPT2SAS_ADAPTER
*ioc
, int id
, int channel
)
585 struct _raid_device
*raid_device
, *r
;
588 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
589 if (raid_device
->id
== id
&& raid_device
->channel
== channel
) {
600 * _scsih_raid_device_find_by_handle - raid device search
601 * @ioc: per adapter object
602 * @handle: sas device handle (assigned by firmware)
603 * Context: Calling function should acquire ioc->raid_device_lock
605 * This searches for raid_device based on handle, then return raid_device
608 static struct _raid_device
*
609 _scsih_raid_device_find_by_handle(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
611 struct _raid_device
*raid_device
, *r
;
614 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
615 if (raid_device
->handle
!= handle
)
626 * _scsih_raid_device_find_by_wwid - raid device search
627 * @ioc: per adapter object
628 * @handle: sas device handle (assigned by firmware)
629 * Context: Calling function should acquire ioc->raid_device_lock
631 * This searches for raid_device based on wwid, then return raid_device
634 static struct _raid_device
*
635 _scsih_raid_device_find_by_wwid(struct MPT2SAS_ADAPTER
*ioc
, u64 wwid
)
637 struct _raid_device
*raid_device
, *r
;
640 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
641 if (raid_device
->wwid
!= wwid
)
652 * _scsih_raid_device_add - add raid_device object
653 * @ioc: per adapter object
654 * @raid_device: raid_device object
656 * This is added to the raid_device_list link list.
659 _scsih_raid_device_add(struct MPT2SAS_ADAPTER
*ioc
,
660 struct _raid_device
*raid_device
)
664 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: handle"
665 "(0x%04x), wwid(0x%016llx)\n", ioc
->name
, __func__
,
666 raid_device
->handle
, (unsigned long long)raid_device
->wwid
));
668 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
669 list_add_tail(&raid_device
->list
, &ioc
->raid_device_list
);
670 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
674 * _scsih_raid_device_remove - delete raid_device object
675 * @ioc: per adapter object
676 * @raid_device: raid_device object
678 * This is removed from the raid_device_list link list.
681 _scsih_raid_device_remove(struct MPT2SAS_ADAPTER
*ioc
,
682 struct _raid_device
*raid_device
)
686 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
687 list_del(&raid_device
->list
);
688 memset(raid_device
, 0, sizeof(struct _raid_device
));
690 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
694 * mpt2sas_scsih_expander_find_by_sas_address - expander device search
695 * @ioc: per adapter object
696 * @sas_address: sas address
697 * Context: Calling function should acquire ioc->sas_node_lock.
699 * This searches for expander device based on sas_address, then returns the
703 mpt2sas_scsih_expander_find_by_sas_address(struct MPT2SAS_ADAPTER
*ioc
,
706 struct _sas_node
*sas_expander
, *r
;
709 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
710 if (sas_expander
->sas_address
!= sas_address
)
720 * _scsih_expander_node_add - insert expander device to the list.
721 * @ioc: per adapter object
722 * @sas_expander: the sas_device object
723 * Context: This function will acquire ioc->sas_node_lock.
725 * Adding new object to the ioc->sas_expander_list.
730 _scsih_expander_node_add(struct MPT2SAS_ADAPTER
*ioc
,
731 struct _sas_node
*sas_expander
)
735 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
736 list_add_tail(&sas_expander
->list
, &ioc
->sas_expander_list
);
737 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
741 * _scsih_is_end_device - determines if device is an end device
742 * @device_info: bitfield providing information about the device.
745 * Returns 1 if end device.
748 _scsih_is_end_device(u32 device_info
)
750 if (device_info
& MPI2_SAS_DEVICE_INFO_END_DEVICE
&&
751 ((device_info
& MPI2_SAS_DEVICE_INFO_SSP_TARGET
) |
752 (device_info
& MPI2_SAS_DEVICE_INFO_STP_TARGET
) |
753 (device_info
& MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)))
760 * _scsih_scsi_lookup_get - returns scmd entry
761 * @ioc: per adapter object
762 * @smid: system request message index
763 * Context: This function will acquire ioc->scsi_lookup_lock.
765 * Returns the smid stored scmd pointer.
767 static struct scsi_cmnd
*
768 _scsih_scsi_lookup_get(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
771 struct scsi_cmnd
*scmd
;
773 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
774 scmd
= ioc
->scsi_lookup
[smid
- 1].scmd
;
775 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
780 * mptscsih_getclear_scsi_lookup - returns scmd entry
781 * @ioc: per adapter object
782 * @smid: system request message index
783 * Context: This function will acquire ioc->scsi_lookup_lock.
785 * Returns the smid stored scmd pointer, as well as clearing the scmd pointer.
787 static struct scsi_cmnd
*
788 _scsih_scsi_lookup_getclear(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
791 struct scsi_cmnd
*scmd
;
793 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
794 scmd
= ioc
->scsi_lookup
[smid
- 1].scmd
;
795 ioc
->scsi_lookup
[smid
- 1].scmd
= NULL
;
796 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
801 * _scsih_scsi_lookup_set - updates scmd entry in lookup
802 * @ioc: per adapter object
803 * @smid: system request message index
804 * @scmd: pointer to scsi command object
805 * Context: This function will acquire ioc->scsi_lookup_lock.
807 * This will save scmd pointer in the scsi_lookup array.
812 _scsih_scsi_lookup_set(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
,
813 struct scsi_cmnd
*scmd
)
817 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
818 ioc
->scsi_lookup
[smid
- 1].scmd
= scmd
;
819 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
823 * _scsih_scsi_lookup_find_by_scmd - scmd lookup
824 * @ioc: per adapter object
825 * @smid: system request message index
826 * @scmd: pointer to scsi command object
827 * Context: This function will acquire ioc->scsi_lookup_lock.
829 * This will search for a scmd pointer in the scsi_lookup array,
830 * returning the revelent smid. A returned value of zero means invalid.
833 _scsih_scsi_lookup_find_by_scmd(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_cmnd
840 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
842 for (i
= 0; i
< ioc
->request_depth
; i
++) {
843 if (ioc
->scsi_lookup
[i
].scmd
== scmd
) {
849 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
854 * _scsih_scsi_lookup_find_by_target - search for matching channel:id
855 * @ioc: per adapter object
858 * Context: This function will acquire ioc->scsi_lookup_lock.
860 * This will search for a matching channel:id in the scsi_lookup array,
861 * returning 1 if found.
864 _scsih_scsi_lookup_find_by_target(struct MPT2SAS_ADAPTER
*ioc
, int id
,
871 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
873 for (i
= 0 ; i
< ioc
->request_depth
; i
++) {
874 if (ioc
->scsi_lookup
[i
].scmd
&&
875 (ioc
->scsi_lookup
[i
].scmd
->device
->id
== id
&&
876 ioc
->scsi_lookup
[i
].scmd
->device
->channel
== channel
)) {
882 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
887 * _scsih_get_chain_buffer_dma - obtain block of chains (dma address)
888 * @ioc: per adapter object
889 * @smid: system request message index
891 * Returns phys pointer to chain buffer.
894 _scsih_get_chain_buffer_dma(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
896 return ioc
->chain_dma
+ ((smid
- 1) * (ioc
->request_sz
*
897 ioc
->chains_needed_per_io
));
901 * _scsih_get_chain_buffer - obtain block of chains assigned to a mf request
902 * @ioc: per adapter object
903 * @smid: system request message index
905 * Returns virt pointer to chain buffer.
908 _scsih_get_chain_buffer(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
910 return (void *)(ioc
->chain
+ ((smid
- 1) * (ioc
->request_sz
*
911 ioc
->chains_needed_per_io
)));
915 * _scsih_build_scatter_gather - main sg creation routine
916 * @ioc: per adapter object
917 * @scmd: scsi command
918 * @smid: system request message index
921 * The main routine that builds scatter gather table from a given
922 * scsi request sent via the .queuecommand main handler.
924 * Returns 0 success, anything else error
927 _scsih_build_scatter_gather(struct MPT2SAS_ADAPTER
*ioc
,
928 struct scsi_cmnd
*scmd
, u16 smid
)
930 Mpi2SCSIIORequest_t
*mpi_request
;
931 dma_addr_t chain_dma
;
932 struct scatterlist
*sg_scmd
;
933 void *sg_local
, *chain
;
940 u32 sgl_flags_last_element
;
941 u32 sgl_flags_end_buffer
;
943 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
945 /* init scatter gather flags */
946 sgl_flags
= MPI2_SGE_FLAGS_SIMPLE_ELEMENT
;
947 if (scmd
->sc_data_direction
== DMA_TO_DEVICE
)
948 sgl_flags
|= MPI2_SGE_FLAGS_HOST_TO_IOC
;
949 sgl_flags_last_element
= (sgl_flags
| MPI2_SGE_FLAGS_LAST_ELEMENT
)
950 << MPI2_SGE_FLAGS_SHIFT
;
951 sgl_flags_end_buffer
= (sgl_flags
| MPI2_SGE_FLAGS_LAST_ELEMENT
|
952 MPI2_SGE_FLAGS_END_OF_BUFFER
| MPI2_SGE_FLAGS_END_OF_LIST
)
953 << MPI2_SGE_FLAGS_SHIFT
;
954 sgl_flags
= sgl_flags
<< MPI2_SGE_FLAGS_SHIFT
;
956 sg_scmd
= scsi_sglist(scmd
);
957 sges_left
= scsi_dma_map(scmd
);
959 sdev_printk(KERN_ERR
, scmd
->device
, "pci_map_sg"
960 " failed: request for %d bytes!\n", scsi_bufflen(scmd
));
964 sg_local
= &mpi_request
->SGL
;
965 sges_in_segment
= ioc
->max_sges_in_main_message
;
966 if (sges_left
<= sges_in_segment
)
967 goto fill_in_last_segment
;
969 mpi_request
->ChainOffset
= (offsetof(Mpi2SCSIIORequest_t
, SGL
) +
970 (sges_in_segment
* ioc
->sge_size
))/4;
972 /* fill in main message segment when there is a chain following */
973 while (sges_in_segment
) {
974 if (sges_in_segment
== 1)
975 ioc
->base_add_sg_single(sg_local
,
976 sgl_flags_last_element
| sg_dma_len(sg_scmd
),
977 sg_dma_address(sg_scmd
));
979 ioc
->base_add_sg_single(sg_local
, sgl_flags
|
980 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
981 sg_scmd
= sg_next(sg_scmd
);
982 sg_local
+= ioc
->sge_size
;
987 /* initializing the chain flags and pointers */
988 chain_flags
= MPI2_SGE_FLAGS_CHAIN_ELEMENT
<< MPI2_SGE_FLAGS_SHIFT
;
989 chain
= _scsih_get_chain_buffer(ioc
, smid
);
990 chain_dma
= _scsih_get_chain_buffer_dma(ioc
, smid
);
992 sges_in_segment
= (sges_left
<=
993 ioc
->max_sges_in_chain_message
) ? sges_left
:
994 ioc
->max_sges_in_chain_message
;
995 chain_offset
= (sges_left
== sges_in_segment
) ?
996 0 : (sges_in_segment
* ioc
->sge_size
)/4;
997 chain_length
= sges_in_segment
* ioc
->sge_size
;
999 chain_offset
= chain_offset
<<
1000 MPI2_SGE_CHAIN_OFFSET_SHIFT
;
1001 chain_length
+= ioc
->sge_size
;
1003 ioc
->base_add_sg_single(sg_local
, chain_flags
| chain_offset
|
1004 chain_length
, chain_dma
);
1007 goto fill_in_last_segment
;
1009 /* fill in chain segments */
1010 while (sges_in_segment
) {
1011 if (sges_in_segment
== 1)
1012 ioc
->base_add_sg_single(sg_local
,
1013 sgl_flags_last_element
|
1014 sg_dma_len(sg_scmd
),
1015 sg_dma_address(sg_scmd
));
1017 ioc
->base_add_sg_single(sg_local
, sgl_flags
|
1018 sg_dma_len(sg_scmd
),
1019 sg_dma_address(sg_scmd
));
1020 sg_scmd
= sg_next(sg_scmd
);
1021 sg_local
+= ioc
->sge_size
;
1026 chain_dma
+= ioc
->request_sz
;
1027 chain
+= ioc
->request_sz
;
1031 fill_in_last_segment
:
1033 /* fill the last segment */
1036 ioc
->base_add_sg_single(sg_local
, sgl_flags_end_buffer
|
1037 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
1039 ioc
->base_add_sg_single(sg_local
, sgl_flags
|
1040 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
1041 sg_scmd
= sg_next(sg_scmd
);
1042 sg_local
+= ioc
->sge_size
;
1050 * scsih_change_queue_depth - setting device queue depth
1051 * @sdev: scsi device struct
1052 * @qdepth: requested queue depth
1054 * Returns queue depth.
1057 scsih_change_queue_depth(struct scsi_device
*sdev
, int qdepth
)
1059 struct Scsi_Host
*shost
= sdev
->host
;
1063 max_depth
= shost
->can_queue
;
1064 if (!sdev
->tagged_supported
)
1066 if (qdepth
> max_depth
)
1068 tag_type
= (qdepth
== 1) ? 0 : MSG_SIMPLE_TAG
;
1069 scsi_adjust_queue_depth(sdev
, tag_type
, qdepth
);
1071 if (sdev
->inquiry_len
> 7)
1072 sdev_printk(KERN_INFO
, sdev
, "qdepth(%d), tagged(%d), "
1073 "simple(%d), ordered(%d), scsi_level(%d), cmd_que(%d)\n",
1074 sdev
->queue_depth
, sdev
->tagged_supported
, sdev
->simple_tags
,
1075 sdev
->ordered_tags
, sdev
->scsi_level
,
1076 (sdev
->inquiry
[7] & 2) >> 1);
1078 return sdev
->queue_depth
;
1082 * scsih_change_queue_depth - changing device queue tag type
1083 * @sdev: scsi device struct
1084 * @tag_type: requested tag type
1086 * Returns queue tag type.
1089 scsih_change_queue_type(struct scsi_device
*sdev
, int tag_type
)
1091 if (sdev
->tagged_supported
) {
1092 scsi_set_tag_type(sdev
, tag_type
);
1094 scsi_activate_tcq(sdev
, sdev
->queue_depth
);
1096 scsi_deactivate_tcq(sdev
, sdev
->queue_depth
);
1104 * scsih_target_alloc - target add routine
1105 * @starget: scsi target struct
1107 * Returns 0 if ok. Any other return is assumed to be an error and
1108 * the device is ignored.
1111 scsih_target_alloc(struct scsi_target
*starget
)
1113 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
1114 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1115 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1116 struct _sas_device
*sas_device
;
1117 struct _raid_device
*raid_device
;
1118 unsigned long flags
;
1119 struct sas_rphy
*rphy
;
1121 sas_target_priv_data
= kzalloc(sizeof(struct scsi_target
), GFP_KERNEL
);
1122 if (!sas_target_priv_data
)
1125 starget
->hostdata
= sas_target_priv_data
;
1126 sas_target_priv_data
->starget
= starget
;
1127 sas_target_priv_data
->handle
= MPT2SAS_INVALID_DEVICE_HANDLE
;
1130 if (starget
->channel
== RAID_CHANNEL
) {
1131 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1132 raid_device
= _scsih_raid_device_find_by_id(ioc
, starget
->id
,
1135 sas_target_priv_data
->handle
= raid_device
->handle
;
1136 sas_target_priv_data
->sas_address
= raid_device
->wwid
;
1137 sas_target_priv_data
->flags
|= MPT_TARGET_FLAGS_VOLUME
;
1138 raid_device
->starget
= starget
;
1140 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1144 /* sas/sata devices */
1145 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1146 rphy
= dev_to_rphy(starget
->dev
.parent
);
1147 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1148 rphy
->identify
.sas_address
);
1151 sas_target_priv_data
->handle
= sas_device
->handle
;
1152 sas_target_priv_data
->sas_address
= sas_device
->sas_address
;
1153 sas_device
->starget
= starget
;
1154 sas_device
->id
= starget
->id
;
1155 sas_device
->channel
= starget
->channel
;
1156 if (sas_device
->hidden_raid_component
)
1157 sas_target_priv_data
->flags
|=
1158 MPT_TARGET_FLAGS_RAID_COMPONENT
;
1160 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1166 * scsih_target_destroy - target destroy routine
1167 * @starget: scsi target struct
1172 scsih_target_destroy(struct scsi_target
*starget
)
1174 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
1175 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1176 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1177 struct _sas_device
*sas_device
;
1178 struct _raid_device
*raid_device
;
1179 unsigned long flags
;
1180 struct sas_rphy
*rphy
;
1182 sas_target_priv_data
= starget
->hostdata
;
1183 if (!sas_target_priv_data
)
1186 if (starget
->channel
== RAID_CHANNEL
) {
1187 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1188 raid_device
= _scsih_raid_device_find_by_id(ioc
, starget
->id
,
1191 raid_device
->starget
= NULL
;
1192 raid_device
->sdev
= NULL
;
1194 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1198 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1199 rphy
= dev_to_rphy(starget
->dev
.parent
);
1200 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1201 rphy
->identify
.sas_address
);
1202 if (sas_device
&& (sas_device
->starget
== starget
) &&
1203 (sas_device
->id
== starget
->id
) &&
1204 (sas_device
->channel
== starget
->channel
))
1205 sas_device
->starget
= NULL
;
1207 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1210 kfree(sas_target_priv_data
);
1211 starget
->hostdata
= NULL
;
1215 * scsih_slave_alloc - device add routine
1216 * @sdev: scsi device struct
1218 * Returns 0 if ok. Any other return is assumed to be an error and
1219 * the device is ignored.
1222 scsih_slave_alloc(struct scsi_device
*sdev
)
1224 struct Scsi_Host
*shost
;
1225 struct MPT2SAS_ADAPTER
*ioc
;
1226 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1227 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1228 struct scsi_target
*starget
;
1229 struct _raid_device
*raid_device
;
1230 struct _sas_device
*sas_device
;
1231 unsigned long flags
;
1233 sas_device_priv_data
= kzalloc(sizeof(struct scsi_device
), GFP_KERNEL
);
1234 if (!sas_device_priv_data
)
1237 sas_device_priv_data
->lun
= sdev
->lun
;
1238 sas_device_priv_data
->flags
= MPT_DEVICE_FLAGS_INIT
;
1240 starget
= scsi_target(sdev
);
1241 sas_target_priv_data
= starget
->hostdata
;
1242 sas_target_priv_data
->num_luns
++;
1243 sas_device_priv_data
->sas_target
= sas_target_priv_data
;
1244 sdev
->hostdata
= sas_device_priv_data
;
1245 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
))
1246 sdev
->no_uld_attach
= 1;
1248 shost
= dev_to_shost(&starget
->dev
);
1249 ioc
= shost_priv(shost
);
1250 if (starget
->channel
== RAID_CHANNEL
) {
1251 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1252 raid_device
= _scsih_raid_device_find_by_id(ioc
,
1253 starget
->id
, starget
->channel
);
1255 raid_device
->sdev
= sdev
; /* raid is single lun */
1256 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1258 /* set TLR bit for SSP devices */
1259 if (!(ioc
->facts
.IOCCapabilities
&
1260 MPI2_IOCFACTS_CAPABILITY_TLR
))
1262 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1263 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1264 sas_device_priv_data
->sas_target
->sas_address
);
1265 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1266 if (sas_device
&& sas_device
->device_info
&
1267 MPI2_SAS_DEVICE_INFO_SSP_TARGET
)
1268 sas_device_priv_data
->flags
|= MPT_DEVICE_TLR_ON
;
1276 * scsih_slave_destroy - device destroy routine
1277 * @sdev: scsi device struct
1282 scsih_slave_destroy(struct scsi_device
*sdev
)
1284 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1285 struct scsi_target
*starget
;
1287 if (!sdev
->hostdata
)
1290 starget
= scsi_target(sdev
);
1291 sas_target_priv_data
= starget
->hostdata
;
1292 sas_target_priv_data
->num_luns
--;
1293 kfree(sdev
->hostdata
);
1294 sdev
->hostdata
= NULL
;
1298 * scsih_display_sata_capabilities - sata capabilities
1299 * @ioc: per adapter object
1300 * @sas_device: the sas_device object
1301 * @sdev: scsi device struct
1304 scsih_display_sata_capabilities(struct MPT2SAS_ADAPTER
*ioc
,
1305 struct _sas_device
*sas_device
, struct scsi_device
*sdev
)
1307 Mpi2ConfigReply_t mpi_reply
;
1308 Mpi2SasDevicePage0_t sas_device_pg0
;
1313 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
1314 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, sas_device
->handle
))) {
1315 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1316 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1320 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
1321 MPI2_IOCSTATUS_MASK
;
1322 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
1323 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1324 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1328 flags
= le16_to_cpu(sas_device_pg0
.Flags
);
1329 device_info
= le16_to_cpu(sas_device_pg0
.DeviceInfo
);
1331 sdev_printk(KERN_INFO
, sdev
,
1332 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1333 "sw_preserve(%s)\n",
1334 (device_info
& MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE
) ? "y" : "n",
1335 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED
) ? "y" : "n",
1336 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY
) ? "y" :
1338 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED
) ? "y" : "n",
1339 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED
) ? "y" : "n",
1340 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE
) ? "y" : "n");
1344 * _scsih_get_volume_capabilities - volume capabilities
1345 * @ioc: per adapter object
1346 * @sas_device: the raid_device object
1349 _scsih_get_volume_capabilities(struct MPT2SAS_ADAPTER
*ioc
,
1350 struct _raid_device
*raid_device
)
1352 Mpi2RaidVolPage0_t
*vol_pg0
;
1353 Mpi2RaidPhysDiskPage0_t pd_pg0
;
1354 Mpi2SasDevicePage0_t sas_device_pg0
;
1355 Mpi2ConfigReply_t mpi_reply
;
1359 if ((mpt2sas_config_get_number_pds(ioc
, raid_device
->handle
,
1360 &num_pds
)) || !num_pds
) {
1361 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1362 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1366 raid_device
->num_pds
= num_pds
;
1367 sz
= offsetof(Mpi2RaidVolPage0_t
, PhysDisk
) + (num_pds
*
1368 sizeof(Mpi2RaidVol0PhysDisk_t
));
1369 vol_pg0
= kzalloc(sz
, GFP_KERNEL
);
1371 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1372 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1376 if ((mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, vol_pg0
,
1377 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, raid_device
->handle
, sz
))) {
1378 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1379 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1384 raid_device
->volume_type
= vol_pg0
->VolumeType
;
1386 /* figure out what the underlying devices are by
1387 * obtaining the device_info bits for the 1st device
1389 if (!(mpt2sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
1390 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM
,
1391 vol_pg0
->PhysDisk
[0].PhysDiskNum
))) {
1392 if (!(mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
1393 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
1394 le16_to_cpu(pd_pg0
.DevHandle
)))) {
1395 raid_device
->device_info
=
1396 le32_to_cpu(sas_device_pg0
.DeviceInfo
);
1404 * scsih_slave_configure - device configure routine.
1405 * @sdev: scsi device struct
1407 * Returns 0 if ok. Any other return is assumed to be an error and
1408 * the device is ignored.
1411 scsih_slave_configure(struct scsi_device
*sdev
)
1413 struct Scsi_Host
*shost
= sdev
->host
;
1414 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1415 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1416 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1417 struct _sas_device
*sas_device
;
1418 struct _raid_device
*raid_device
;
1419 unsigned long flags
;
1426 sas_device_priv_data
= sdev
->hostdata
;
1427 sas_device_priv_data
->configured_lun
= 1;
1428 sas_device_priv_data
->flags
&= ~MPT_DEVICE_FLAGS_INIT
;
1429 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
1431 /* raid volume handling */
1432 if (sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
1434 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1435 raid_device
= _scsih_raid_device_find_by_handle(ioc
,
1436 sas_target_priv_data
->handle
);
1437 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1439 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1440 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1444 _scsih_get_volume_capabilities(ioc
, raid_device
);
1446 /* RAID Queue Depth Support
1447 * IS volume = underlying qdepth of drive type, either
1448 * MPT2SAS_SAS_QUEUE_DEPTH or MPT2SAS_SATA_QUEUE_DEPTH
1449 * IM/IME/R10 = 128 (MPT2SAS_RAID_QUEUE_DEPTH)
1451 if (raid_device
->device_info
&
1452 MPI2_SAS_DEVICE_INFO_SSP_TARGET
) {
1453 qdepth
= MPT2SAS_SAS_QUEUE_DEPTH
;
1456 qdepth
= MPT2SAS_SATA_QUEUE_DEPTH
;
1457 if (raid_device
->device_info
&
1458 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1464 switch (raid_device
->volume_type
) {
1465 case MPI2_RAID_VOL_TYPE_RAID0
:
1468 case MPI2_RAID_VOL_TYPE_RAID1E
:
1469 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
1472 case MPI2_RAID_VOL_TYPE_RAID1
:
1473 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
1476 case MPI2_RAID_VOL_TYPE_RAID10
:
1477 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
1480 case MPI2_RAID_VOL_TYPE_UNKNOWN
:
1482 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
1487 sdev_printk(KERN_INFO
, sdev
, "%s: "
1488 "handle(0x%04x), wwid(0x%016llx), pd_count(%d), type(%s)\n",
1489 r_level
, raid_device
->handle
,
1490 (unsigned long long)raid_device
->wwid
,
1491 raid_device
->num_pds
, ds
);
1492 scsih_change_queue_depth(sdev
, qdepth
);
1496 /* non-raid handling */
1497 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1498 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1499 sas_device_priv_data
->sas_target
->sas_address
);
1500 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1502 if (sas_target_priv_data
->flags
&
1503 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
1504 mpt2sas_config_get_volume_handle(ioc
,
1505 sas_device
->handle
, &sas_device
->volume_handle
);
1506 mpt2sas_config_get_volume_wwid(ioc
,
1507 sas_device
->volume_handle
,
1508 &sas_device
->volume_wwid
);
1510 if (sas_device
->device_info
& MPI2_SAS_DEVICE_INFO_SSP_TARGET
) {
1511 qdepth
= MPT2SAS_SAS_QUEUE_DEPTH
;
1515 qdepth
= MPT2SAS_SATA_QUEUE_DEPTH
;
1516 if (sas_device
->device_info
&
1517 MPI2_SAS_DEVICE_INFO_STP_TARGET
)
1519 else if (sas_device
->device_info
&
1520 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1524 sdev_printk(KERN_INFO
, sdev
, "%s: handle(0x%04x), "
1525 "sas_addr(0x%016llx), device_name(0x%016llx)\n",
1526 ds
, sas_device
->handle
,
1527 (unsigned long long)sas_device
->sas_address
,
1528 (unsigned long long)sas_device
->device_name
);
1529 sdev_printk(KERN_INFO
, sdev
, "%s: "
1530 "enclosure_logical_id(0x%016llx), slot(%d)\n", ds
,
1531 (unsigned long long) sas_device
->enclosure_logical_id
,
1535 scsih_display_sata_capabilities(ioc
, sas_device
, sdev
);
1538 scsih_change_queue_depth(sdev
, qdepth
);
1541 sas_read_port_mode_page(sdev
);
1546 * scsih_bios_param - fetch head, sector, cylinder info for a disk
1547 * @sdev: scsi device struct
1548 * @bdev: pointer to block device context
1549 * @capacity: device size (in 512 byte sectors)
1550 * @params: three element array to place output:
1551 * params[0] number of heads (max 255)
1552 * params[1] number of sectors (max 63)
1553 * params[2] number of cylinders
1558 scsih_bios_param(struct scsi_device
*sdev
, struct block_device
*bdev
,
1559 sector_t capacity
, int params
[])
1569 dummy
= heads
* sectors
;
1570 cylinders
= capacity
;
1571 sector_div(cylinders
, dummy
);
1574 * Handle extended translation size for logical drives
1577 if ((ulong
)capacity
>= 0x200000) {
1580 dummy
= heads
* sectors
;
1581 cylinders
= capacity
;
1582 sector_div(cylinders
, dummy
);
1587 params
[1] = sectors
;
1588 params
[2] = cylinders
;
1594 * _scsih_response_code - translation of device response code
1595 * @ioc: per adapter object
1596 * @response_code: response code returned by the device
1601 _scsih_response_code(struct MPT2SAS_ADAPTER
*ioc
, u8 response_code
)
1605 switch (response_code
) {
1606 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE
:
1607 desc
= "task management request completed";
1609 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
:
1610 desc
= "invalid frame";
1612 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED
:
1613 desc
= "task management request not supported";
1615 case MPI2_SCSITASKMGMT_RSP_TM_FAILED
:
1616 desc
= "task management request failed";
1618 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
:
1619 desc
= "task management request succeeded";
1621 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN
:
1622 desc
= "invalid lun";
1625 desc
= "overlapped tag attempted";
1627 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
:
1628 desc
= "task queued, however not sent to target";
1634 printk(MPT2SAS_WARN_FMT
"response_code(0x%01x): %s\n",
1635 ioc
->name
, response_code
, desc
);
1639 * scsih_tm_done - tm completion routine
1640 * @ioc: per adapter object
1641 * @smid: system request message index
1642 * @VF_ID: virtual function id
1643 * @reply: reply message frame(lower 32bit addr)
1646 * The callback handler when using scsih_issue_tm.
1651 scsih_tm_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 VF_ID
, 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
);
1670 * mpt2sas_scsih_set_tm_flag - set per target tm_busy
1671 * @ioc: per adapter object
1672 * @handle: device handle
1674 * During taskmangement request, we need to freeze the device queue.
1677 mpt2sas_scsih_set_tm_flag(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
1679 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1680 struct scsi_device
*sdev
;
1683 shost_for_each_device(sdev
, ioc
->shost
) {
1686 sas_device_priv_data
= sdev
->hostdata
;
1687 if (!sas_device_priv_data
)
1689 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
1690 sas_device_priv_data
->sas_target
->tm_busy
= 1;
1692 ioc
->ignore_loginfos
= 1;
1698 * mpt2sas_scsih_clear_tm_flag - clear per target tm_busy
1699 * @ioc: per adapter object
1700 * @handle: device handle
1702 * During taskmangement request, we need to freeze the device queue.
1705 mpt2sas_scsih_clear_tm_flag(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
1707 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1708 struct scsi_device
*sdev
;
1711 shost_for_each_device(sdev
, ioc
->shost
) {
1714 sas_device_priv_data
= sdev
->hostdata
;
1715 if (!sas_device_priv_data
)
1717 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
1718 sas_device_priv_data
->sas_target
->tm_busy
= 0;
1720 ioc
->ignore_loginfos
= 0;
1726 * mpt2sas_scsih_issue_tm - main routine for sending tm requests
1727 * @ioc: per adapter struct
1728 * @device_handle: device handle
1730 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
1731 * @smid_task: smid assigned to the task
1732 * @timeout: timeout in seconds
1733 * Context: The calling function needs to acquire the tm_cmds.mutex
1735 * A generic API for sending task management requests to firmware.
1737 * The ioc->tm_cmds.status flag should be MPT2_CMD_NOT_USED before calling
1740 * The callback index is set inside `ioc->tm_cb_idx`.
1745 mpt2sas_scsih_issue_tm(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
, uint lun
,
1746 u8 type
, u16 smid_task
, ulong timeout
)
1748 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
1749 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
1752 unsigned long timeleft
;
1754 unsigned long flags
;
1756 spin_lock_irqsave(&ioc
->ioc_reset_in_progress_lock
, flags
);
1757 if (ioc
->tm_cmds
.status
!= MPT2_CMD_NOT_USED
||
1758 ioc
->shost_recovery
) {
1759 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
, flags
);
1760 printk(MPT2SAS_INFO_FMT
"%s: host reset in progress!\n",
1761 __func__
, ioc
->name
);
1764 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
, flags
);
1766 ioc_state
= mpt2sas_base_get_iocstate(ioc
, 0);
1767 if (ioc_state
& MPI2_DOORBELL_USED
) {
1768 dhsprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"unexpected doorbell "
1769 "active!\n", ioc
->name
));
1770 goto issue_host_reset
;
1773 if ((ioc_state
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_FAULT
) {
1774 mpt2sas_base_fault_info(ioc
, ioc_state
&
1775 MPI2_DOORBELL_DATA_MASK
);
1776 goto issue_host_reset
;
1779 smid
= mpt2sas_base_get_smid(ioc
, ioc
->tm_cb_idx
);
1781 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
1782 ioc
->name
, __func__
);
1786 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"sending tm: handle(0x%04x),"
1787 " task_type(0x%02x), smid(%d)\n", ioc
->name
, handle
, type
, smid
));
1788 ioc
->tm_cmds
.status
= MPT2_CMD_PENDING
;
1789 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
1790 ioc
->tm_cmds
.smid
= smid
;
1791 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
1792 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
1793 mpi_request
->DevHandle
= cpu_to_le16(handle
);
1794 mpi_request
->TaskType
= type
;
1795 mpi_request
->TaskMID
= cpu_to_le16(smid_task
);
1796 int_to_scsilun(lun
, (struct scsi_lun
*)mpi_request
->LUN
);
1797 mpt2sas_scsih_set_tm_flag(ioc
, handle
);
1798 mpt2sas_base_put_smid_hi_priority(ioc
, smid
, VF_ID
);
1799 timeleft
= wait_for_completion_timeout(&ioc
->tm_cmds
.done
, timeout
*HZ
);
1800 mpt2sas_scsih_clear_tm_flag(ioc
, handle
);
1801 if (!(ioc
->tm_cmds
.status
& MPT2_CMD_COMPLETE
)) {
1802 printk(MPT2SAS_ERR_FMT
"%s: timeout\n",
1803 ioc
->name
, __func__
);
1804 _debug_dump_mf(mpi_request
,
1805 sizeof(Mpi2SCSITaskManagementRequest_t
)/4);
1806 if (!(ioc
->tm_cmds
.status
& MPT2_CMD_RESET
))
1807 goto issue_host_reset
;
1810 if (ioc
->tm_cmds
.status
& MPT2_CMD_REPLY_VALID
) {
1811 mpi_reply
= ioc
->tm_cmds
.reply
;
1812 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"complete tm: "
1813 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
1814 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
1815 le32_to_cpu(mpi_reply
->IOCLogInfo
),
1816 le32_to_cpu(mpi_reply
->TerminationCount
)));
1817 if (ioc
->logging_level
& MPT_DEBUG_TM
)
1818 _scsih_response_code(ioc
, mpi_reply
->ResponseCode
);
1822 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
, FORCE_BIG_HAMMER
);
1826 * scsih_abort - eh threads main abort routine
1827 * @sdev: scsi device struct
1829 * Returns SUCCESS if command aborted else FAILED
1832 scsih_abort(struct scsi_cmnd
*scmd
)
1834 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
1835 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1839 struct scsi_cmnd
*scmd_lookup
;
1841 printk(MPT2SAS_INFO_FMT
"attempting task abort! scmd(%p)\n",
1843 scsi_print_command(scmd
);
1845 sas_device_priv_data
= scmd
->device
->hostdata
;
1846 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
1847 printk(MPT2SAS_INFO_FMT
"device been deleted! scmd(%p)\n",
1849 scmd
->result
= DID_NO_CONNECT
<< 16;
1850 scmd
->scsi_done(scmd
);
1855 /* search for the command */
1856 smid
= _scsih_scsi_lookup_find_by_scmd(ioc
, scmd
);
1858 scmd
->result
= DID_RESET
<< 16;
1863 /* for hidden raid components and volumes this is not supported */
1864 if (sas_device_priv_data
->sas_target
->flags
&
1865 MPT_TARGET_FLAGS_RAID_COMPONENT
||
1866 sas_device_priv_data
->sas_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
1867 scmd
->result
= DID_RESET
<< 16;
1872 mutex_lock(&ioc
->tm_cmds
.mutex
);
1873 handle
= sas_device_priv_data
->sas_target
->handle
;
1874 mpt2sas_scsih_issue_tm(ioc
, handle
, sas_device_priv_data
->lun
,
1875 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
, smid
, 30);
1877 /* sanity check - see whether command actually completed */
1878 scmd_lookup
= _scsih_scsi_lookup_get(ioc
, smid
);
1879 if (scmd_lookup
&& (scmd_lookup
->serial_number
== scmd
->serial_number
))
1883 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
1884 mutex_unlock(&ioc
->tm_cmds
.mutex
);
1887 printk(MPT2SAS_INFO_FMT
"task abort: %s scmd(%p)\n",
1888 ioc
->name
, ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
1894 * scsih_dev_reset - eh threads main device reset routine
1895 * @sdev: scsi device struct
1897 * Returns SUCCESS if command aborted else FAILED
1900 scsih_dev_reset(struct scsi_cmnd
*scmd
)
1902 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
1903 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1904 struct _sas_device
*sas_device
;
1905 unsigned long flags
;
1909 printk(MPT2SAS_INFO_FMT
"attempting target reset! scmd(%p)\n",
1911 scsi_print_command(scmd
);
1913 sas_device_priv_data
= scmd
->device
->hostdata
;
1914 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
1915 printk(MPT2SAS_INFO_FMT
"device been deleted! scmd(%p)\n",
1917 scmd
->result
= DID_NO_CONNECT
<< 16;
1918 scmd
->scsi_done(scmd
);
1923 /* for hidden raid components obtain the volume_handle */
1925 if (sas_device_priv_data
->sas_target
->flags
&
1926 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
1927 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1928 sas_device
= _scsih_sas_device_find_by_handle(ioc
,
1929 sas_device_priv_data
->sas_target
->handle
);
1931 handle
= sas_device
->volume_handle
;
1932 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1934 handle
= sas_device_priv_data
->sas_target
->handle
;
1937 scmd
->result
= DID_RESET
<< 16;
1942 mutex_lock(&ioc
->tm_cmds
.mutex
);
1943 mpt2sas_scsih_issue_tm(ioc
, handle
, 0,
1944 MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
, 0, 30);
1947 * sanity check see whether all commands to this target been
1950 if (_scsih_scsi_lookup_find_by_target(ioc
, scmd
->device
->id
,
1951 scmd
->device
->channel
))
1955 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
1956 mutex_unlock(&ioc
->tm_cmds
.mutex
);
1959 printk(MPT2SAS_INFO_FMT
"target reset: %s scmd(%p)\n",
1960 ioc
->name
, ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
1965 * scsih_abort - eh threads main host reset routine
1966 * @sdev: scsi device struct
1968 * Returns SUCCESS if command aborted else FAILED
1971 scsih_host_reset(struct scsi_cmnd
*scmd
)
1973 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
1976 printk(MPT2SAS_INFO_FMT
"attempting host reset! scmd(%p)\n",
1978 scsi_print_command(scmd
);
1980 retval
= mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
1982 r
= (retval
< 0) ? FAILED
: SUCCESS
;
1983 printk(MPT2SAS_INFO_FMT
"host reset: %s scmd(%p)\n",
1984 ioc
->name
, ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
1990 * _scsih_fw_event_add - insert and queue up fw_event
1991 * @ioc: per adapter object
1992 * @fw_event: object describing the event
1993 * Context: This function will acquire ioc->fw_event_lock.
1995 * This adds the firmware event object into link list, then queues it up to
1996 * be processed from user context.
2001 _scsih_fw_event_add(struct MPT2SAS_ADAPTER
*ioc
, struct fw_event_work
*fw_event
)
2003 unsigned long flags
;
2005 if (ioc
->firmware_event_thread
== NULL
)
2008 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2009 list_add_tail(&fw_event
->list
, &ioc
->fw_event_list
);
2010 INIT_WORK(&fw_event
->work
, _firmware_event_work
);
2011 queue_work(ioc
->firmware_event_thread
, &fw_event
->work
);
2012 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2016 * _scsih_fw_event_free - delete fw_event
2017 * @ioc: per adapter object
2018 * @fw_event: object describing the event
2019 * Context: This function will acquire ioc->fw_event_lock.
2021 * This removes firmware event object from link list, frees associated memory.
2026 _scsih_fw_event_free(struct MPT2SAS_ADAPTER
*ioc
, struct fw_event_work
2029 unsigned long flags
;
2031 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2032 list_del(&fw_event
->list
);
2033 kfree(fw_event
->event_data
);
2035 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2039 * _scsih_fw_event_add - requeue an event
2040 * @ioc: per adapter object
2041 * @fw_event: object describing the event
2042 * Context: This function will acquire ioc->fw_event_lock.
2047 _scsih_fw_event_requeue(struct MPT2SAS_ADAPTER
*ioc
, struct fw_event_work
2048 *fw_event
, unsigned long delay
)
2050 unsigned long flags
;
2051 if (ioc
->firmware_event_thread
== NULL
)
2054 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2055 queue_work(ioc
->firmware_event_thread
, &fw_event
->work
);
2056 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2060 * _scsih_fw_event_off - turn flag off preventing event handling
2061 * @ioc: per adapter object
2063 * Used to prevent handling of firmware events during adapter reset
2069 _scsih_fw_event_off(struct MPT2SAS_ADAPTER
*ioc
)
2071 unsigned long flags
;
2073 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2074 ioc
->fw_events_off
= 1;
2075 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2080 * _scsih_fw_event_on - turn flag on allowing firmware event handling
2081 * @ioc: per adapter object
2086 _scsih_fw_event_on(struct MPT2SAS_ADAPTER
*ioc
)
2088 unsigned long flags
;
2090 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2091 ioc
->fw_events_off
= 0;
2092 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2096 * _scsih_ublock_io_device - set the device state to SDEV_RUNNING
2097 * @ioc: per adapter object
2098 * @handle: device handle
2100 * During device pull we need to appropiately set the sdev state.
2103 _scsih_ublock_io_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
2105 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2106 struct scsi_device
*sdev
;
2108 shost_for_each_device(sdev
, ioc
->shost
) {
2109 sas_device_priv_data
= sdev
->hostdata
;
2110 if (!sas_device_priv_data
)
2112 if (!sas_device_priv_data
->block
)
2114 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2115 dewtprintk(ioc
, sdev_printk(KERN_INFO
, sdev
,
2116 MPT2SAS_INFO_FMT
"SDEV_RUNNING: "
2117 "handle(0x%04x)\n", ioc
->name
, handle
));
2118 sas_device_priv_data
->block
= 0;
2119 scsi_device_set_state(sdev
, SDEV_RUNNING
);
2125 * _scsih_block_io_device - set the device state to SDEV_BLOCK
2126 * @ioc: per adapter object
2127 * @handle: device handle
2129 * During device pull we need to appropiately set the sdev state.
2132 _scsih_block_io_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
2134 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2135 struct scsi_device
*sdev
;
2137 shost_for_each_device(sdev
, ioc
->shost
) {
2138 sas_device_priv_data
= sdev
->hostdata
;
2139 if (!sas_device_priv_data
)
2141 if (sas_device_priv_data
->block
)
2143 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2144 dewtprintk(ioc
, sdev_printk(KERN_INFO
, sdev
,
2145 MPT2SAS_INFO_FMT
"SDEV_BLOCK: "
2146 "handle(0x%04x)\n", ioc
->name
, handle
));
2147 sas_device_priv_data
->block
= 1;
2148 scsi_device_set_state(sdev
, SDEV_BLOCK
);
2154 * _scsih_block_io_to_children_attached_to_ex
2155 * @ioc: per adapter object
2156 * @sas_expander: the sas_device object
2158 * This routine set sdev state to SDEV_BLOCK for all devices
2159 * attached to this expander. This function called when expander is
2163 _scsih_block_io_to_children_attached_to_ex(struct MPT2SAS_ADAPTER
*ioc
,
2164 struct _sas_node
*sas_expander
)
2166 struct _sas_port
*mpt2sas_port
;
2167 struct _sas_device
*sas_device
;
2168 struct _sas_node
*expander_sibling
;
2169 unsigned long flags
;
2174 list_for_each_entry(mpt2sas_port
,
2175 &sas_expander
->sas_port_list
, port_list
) {
2176 if (mpt2sas_port
->remote_identify
.device_type
==
2178 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2180 mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
2181 mpt2sas_port
->remote_identify
.sas_address
);
2182 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2185 _scsih_block_io_device(ioc
, sas_device
->handle
);
2189 list_for_each_entry(mpt2sas_port
,
2190 &sas_expander
->sas_port_list
, port_list
) {
2192 if (mpt2sas_port
->remote_identify
.device_type
==
2193 MPI2_SAS_DEVICE_INFO_EDGE_EXPANDER
||
2194 mpt2sas_port
->remote_identify
.device_type
==
2195 MPI2_SAS_DEVICE_INFO_FANOUT_EXPANDER
) {
2197 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
2199 mpt2sas_scsih_expander_find_by_sas_address(
2200 ioc
, mpt2sas_port
->remote_identify
.sas_address
);
2201 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
2202 _scsih_block_io_to_children_attached_to_ex(ioc
,
2209 * _scsih_block_io_to_children_attached_directly
2210 * @ioc: per adapter object
2211 * @event_data: topology change event data
2213 * This routine set sdev state to SDEV_BLOCK for all devices
2214 * direct attached during device pull.
2217 _scsih_block_io_to_children_attached_directly(struct MPT2SAS_ADAPTER
*ioc
,
2218 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
2225 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
2226 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
2229 phy_number
= event_data
->StartPhyNum
+ i
;
2230 reason_code
= event_data
->PHY
[i
].PhyStatus
&
2231 MPI2_EVENT_SAS_TOPO_RC_MASK
;
2232 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
)
2233 _scsih_block_io_device(ioc
, handle
);
2238 * _scsih_check_topo_delete_events - sanity check on topo events
2239 * @ioc: per adapter object
2240 * @event_data: the event data payload
2242 * This routine added to better handle cable breaker.
2244 * This handles the case where driver recieves multiple expander
2245 * add and delete events in a single shot. When there is a delete event
2246 * the routine will void any pending add events waiting in the event queue.
2251 _scsih_check_topo_delete_events(struct MPT2SAS_ADAPTER
*ioc
,
2252 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
2254 struct fw_event_work
*fw_event
;
2255 Mpi2EventDataSasTopologyChangeList_t
*local_event_data
;
2256 u16 expander_handle
;
2257 struct _sas_node
*sas_expander
;
2258 unsigned long flags
;
2260 expander_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
2261 if (expander_handle
< ioc
->sas_hba
.num_phys
) {
2262 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
2266 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
2267 || event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
) {
2268 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
2269 sas_expander
= mpt2sas_scsih_expander_find_by_handle(ioc
,
2271 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
2272 _scsih_block_io_to_children_attached_to_ex(ioc
, sas_expander
);
2273 } else if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_RESPONDING
)
2274 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
2276 if (event_data
->ExpStatus
!= MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
)
2279 /* mark ignore flag for pending events */
2280 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2281 list_for_each_entry(fw_event
, &ioc
->fw_event_list
, list
) {
2282 if (fw_event
->event
!= MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
||
2285 local_event_data
= fw_event
->event_data
;
2286 if (local_event_data
->ExpStatus
==
2287 MPI2_EVENT_SAS_TOPO_ES_ADDED
||
2288 local_event_data
->ExpStatus
==
2289 MPI2_EVENT_SAS_TOPO_ES_RESPONDING
) {
2290 if (le16_to_cpu(local_event_data
->ExpanderDevHandle
) ==
2292 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
2293 "setting ignoring flag\n", ioc
->name
));
2294 fw_event
->ignore
= 1;
2298 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2302 * _scsih_queue_rescan - queue a topology rescan from user context
2303 * @ioc: per adapter object
2308 _scsih_queue_rescan(struct MPT2SAS_ADAPTER
*ioc
)
2310 struct fw_event_work
*fw_event
;
2312 if (ioc
->wait_for_port_enable_to_complete
)
2314 fw_event
= kzalloc(sizeof(struct fw_event_work
), GFP_ATOMIC
);
2317 fw_event
->event
= MPT2SAS_RESCAN_AFTER_HOST_RESET
;
2318 fw_event
->ioc
= ioc
;
2319 _scsih_fw_event_add(ioc
, fw_event
);
2323 * _scsih_flush_running_cmds - completing outstanding commands.
2324 * @ioc: per adapter object
2326 * The flushing out of all pending scmd commands following host reset,
2327 * where all IO is dropped to the floor.
2332 _scsih_flush_running_cmds(struct MPT2SAS_ADAPTER
*ioc
)
2334 struct scsi_cmnd
*scmd
;
2338 for (smid
= 1; smid
<= ioc
->request_depth
; smid
++) {
2339 scmd
= _scsih_scsi_lookup_getclear(ioc
, smid
);
2343 mpt2sas_base_free_smid(ioc
, smid
);
2344 scsi_dma_unmap(scmd
);
2345 scmd
->result
= DID_RESET
<< 16;
2346 scmd
->scsi_done(scmd
);
2348 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"completing %d cmds\n",
2353 * mpt2sas_scsih_reset_handler - reset callback handler (for scsih)
2354 * @ioc: per adapter object
2355 * @reset_phase: phase
2357 * The handler for doing any required cleanup or initialization.
2359 * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
2360 * MPT2_IOC_DONE_RESET
2365 mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER
*ioc
, int reset_phase
)
2367 switch (reset_phase
) {
2368 case MPT2_IOC_PRE_RESET
:
2369 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: "
2370 "MPT2_IOC_PRE_RESET\n", ioc
->name
, __func__
));
2371 _scsih_fw_event_off(ioc
);
2373 case MPT2_IOC_AFTER_RESET
:
2374 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: "
2375 "MPT2_IOC_AFTER_RESET\n", ioc
->name
, __func__
));
2376 if (ioc
->tm_cmds
.status
& MPT2_CMD_PENDING
) {
2377 ioc
->tm_cmds
.status
|= MPT2_CMD_RESET
;
2378 mpt2sas_base_free_smid(ioc
, ioc
->tm_cmds
.smid
);
2379 complete(&ioc
->tm_cmds
.done
);
2381 _scsih_fw_event_on(ioc
);
2382 _scsih_flush_running_cmds(ioc
);
2384 case MPT2_IOC_DONE_RESET
:
2385 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: "
2386 "MPT2_IOC_DONE_RESET\n", ioc
->name
, __func__
));
2387 _scsih_queue_rescan(ioc
);
2393 * scsih_qcmd - main scsi request entry point
2394 * @scmd: pointer to scsi command object
2395 * @done: function pointer to be invoked on completion
2397 * The callback index is set inside `ioc->scsi_io_cb_idx`.
2399 * Returns 0 on success. If there's a failure, return either:
2400 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
2401 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
2404 scsih_qcmd(struct scsi_cmnd
*scmd
, void (*done
)(struct scsi_cmnd
*))
2406 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2407 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2408 struct MPT2SAS_TARGET
*sas_target_priv_data
;
2409 Mpi2SCSIIORequest_t
*mpi_request
;
2412 unsigned long flags
;
2414 scmd
->scsi_done
= done
;
2415 sas_device_priv_data
= scmd
->device
->hostdata
;
2416 if (!sas_device_priv_data
) {
2417 scmd
->result
= DID_NO_CONNECT
<< 16;
2418 scmd
->scsi_done(scmd
);
2422 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
2423 if (!sas_target_priv_data
|| sas_target_priv_data
->handle
==
2424 MPT2SAS_INVALID_DEVICE_HANDLE
|| sas_target_priv_data
->deleted
) {
2425 scmd
->result
= DID_NO_CONNECT
<< 16;
2426 scmd
->scsi_done(scmd
);
2430 /* see if we are busy with task managment stuff */
2431 spin_lock_irqsave(&ioc
->ioc_reset_in_progress_lock
, flags
);
2432 if (sas_target_priv_data
->tm_busy
||
2433 ioc
->shost_recovery
|| ioc
->ioc_link_reset_in_progress
) {
2434 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
, flags
);
2435 return SCSI_MLQUEUE_HOST_BUSY
;
2437 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
, flags
);
2439 if (scmd
->sc_data_direction
== DMA_FROM_DEVICE
)
2440 mpi_control
= MPI2_SCSIIO_CONTROL_READ
;
2441 else if (scmd
->sc_data_direction
== DMA_TO_DEVICE
)
2442 mpi_control
= MPI2_SCSIIO_CONTROL_WRITE
;
2444 mpi_control
= MPI2_SCSIIO_CONTROL_NODATATRANSFER
;
2447 if (!(sas_device_priv_data
->flags
& MPT_DEVICE_FLAGS_INIT
)) {
2448 if (scmd
->device
->tagged_supported
) {
2449 if (scmd
->device
->ordered_tags
)
2450 mpi_control
|= MPI2_SCSIIO_CONTROL_ORDEREDQ
;
2452 mpi_control
|= MPI2_SCSIIO_CONTROL_SIMPLEQ
;
2454 /* MPI Revision I (UNIT = 0xA) - removed MPI2_SCSIIO_CONTROL_UNTAGGED */
2455 /* mpi_control |= MPI2_SCSIIO_CONTROL_UNTAGGED;
2457 mpi_control
|= (0x500);
2460 mpi_control
|= MPI2_SCSIIO_CONTROL_SIMPLEQ
;
2462 if ((sas_device_priv_data
->flags
& MPT_DEVICE_TLR_ON
))
2463 mpi_control
|= MPI2_SCSIIO_CONTROL_TLR_ON
;
2465 smid
= mpt2sas_base_get_smid(ioc
, ioc
->scsi_io_cb_idx
);
2467 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
2468 ioc
->name
, __func__
);
2471 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
2472 memset(mpi_request
, 0, sizeof(Mpi2SCSIIORequest_t
));
2473 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
2474 if (sas_device_priv_data
->sas_target
->flags
&
2475 MPT_TARGET_FLAGS_RAID_COMPONENT
)
2476 mpi_request
->Function
= MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
;
2478 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
2479 mpi_request
->DevHandle
=
2480 cpu_to_le16(sas_device_priv_data
->sas_target
->handle
);
2481 mpi_request
->DataLength
= cpu_to_le32(scsi_bufflen(scmd
));
2482 mpi_request
->Control
= cpu_to_le32(mpi_control
);
2483 mpi_request
->IoFlags
= cpu_to_le16(scmd
->cmd_len
);
2484 mpi_request
->MsgFlags
= MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR
;
2485 mpi_request
->SenseBufferLength
= SCSI_SENSE_BUFFERSIZE
;
2486 mpi_request
->SenseBufferLowAddress
=
2487 (u32
)mpt2sas_base_get_sense_buffer_dma(ioc
, smid
);
2488 mpi_request
->SGLOffset0
= offsetof(Mpi2SCSIIORequest_t
, SGL
) / 4;
2489 mpi_request
->SGLFlags
= cpu_to_le16(MPI2_SCSIIO_SGLFLAGS_TYPE_MPI
+
2490 MPI2_SCSIIO_SGLFLAGS_SYSTEM_ADDR
);
2492 int_to_scsilun(sas_device_priv_data
->lun
, (struct scsi_lun
*)
2494 memcpy(mpi_request
->CDB
.CDB32
, scmd
->cmnd
, scmd
->cmd_len
);
2496 if (!mpi_request
->DataLength
) {
2497 mpt2sas_base_build_zero_len_sge(ioc
, &mpi_request
->SGL
);
2499 if (_scsih_build_scatter_gather(ioc
, scmd
, smid
)) {
2500 mpt2sas_base_free_smid(ioc
, smid
);
2505 _scsih_scsi_lookup_set(ioc
, smid
, scmd
);
2506 mpt2sas_base_put_smid_scsi_io(ioc
, smid
, 0,
2507 sas_device_priv_data
->sas_target
->handle
);
2511 return SCSI_MLQUEUE_HOST_BUSY
;
2515 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
2516 * @sense_buffer: sense data returned by target
2517 * @data: normalized skey/asc/ascq
2522 _scsih_normalize_sense(char *sense_buffer
, struct sense_info
*data
)
2524 if ((sense_buffer
[0] & 0x7F) >= 0x72) {
2525 /* descriptor format */
2526 data
->skey
= sense_buffer
[1] & 0x0F;
2527 data
->asc
= sense_buffer
[2];
2528 data
->ascq
= sense_buffer
[3];
2531 data
->skey
= sense_buffer
[2] & 0x0F;
2532 data
->asc
= sense_buffer
[12];
2533 data
->ascq
= sense_buffer
[13];
2537 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
2539 * _scsih_scsi_ioc_info - translated non-succesfull SCSI_IO request
2540 * @ioc: per adapter object
2541 * @scmd: pointer to scsi command object
2542 * @mpi_reply: reply mf payload returned from firmware
2544 * scsi_status - SCSI Status code returned from target device
2545 * scsi_state - state info associated with SCSI_IO determined by ioc
2546 * ioc_status - ioc supplied status info
2551 _scsih_scsi_ioc_info(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
,
2552 Mpi2SCSIIOReply_t
*mpi_reply
, u16 smid
)
2556 u16 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) &
2557 MPI2_IOCSTATUS_MASK
;
2558 u8 scsi_state
= mpi_reply
->SCSIState
;
2559 u8 scsi_status
= mpi_reply
->SCSIStatus
;
2560 char *desc_ioc_state
= NULL
;
2561 char *desc_scsi_status
= NULL
;
2562 char *desc_scsi_state
= ioc
->tmp_string
;
2564 switch (ioc_status
) {
2565 case MPI2_IOCSTATUS_SUCCESS
:
2566 desc_ioc_state
= "success";
2568 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
2569 desc_ioc_state
= "invalid function";
2571 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
2572 desc_ioc_state
= "scsi recovered error";
2574 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE
:
2575 desc_ioc_state
= "scsi invalid dev handle";
2577 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
2578 desc_ioc_state
= "scsi device not there";
2580 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
2581 desc_ioc_state
= "scsi data overrun";
2583 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
2584 desc_ioc_state
= "scsi data underrun";
2586 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
2587 desc_ioc_state
= "scsi io data error";
2589 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
2590 desc_ioc_state
= "scsi protocol error";
2592 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
2593 desc_ioc_state
= "scsi task terminated";
2595 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
2596 desc_ioc_state
= "scsi residual mismatch";
2598 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
2599 desc_ioc_state
= "scsi task mgmt failed";
2601 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
2602 desc_ioc_state
= "scsi ioc terminated";
2604 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
2605 desc_ioc_state
= "scsi ext terminated";
2608 desc_ioc_state
= "unknown";
2612 switch (scsi_status
) {
2613 case MPI2_SCSI_STATUS_GOOD
:
2614 desc_scsi_status
= "good";
2616 case MPI2_SCSI_STATUS_CHECK_CONDITION
:
2617 desc_scsi_status
= "check condition";
2619 case MPI2_SCSI_STATUS_CONDITION_MET
:
2620 desc_scsi_status
= "condition met";
2622 case MPI2_SCSI_STATUS_BUSY
:
2623 desc_scsi_status
= "busy";
2625 case MPI2_SCSI_STATUS_INTERMEDIATE
:
2626 desc_scsi_status
= "intermediate";
2628 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET
:
2629 desc_scsi_status
= "intermediate condmet";
2631 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT
:
2632 desc_scsi_status
= "reservation conflict";
2634 case MPI2_SCSI_STATUS_COMMAND_TERMINATED
:
2635 desc_scsi_status
= "command terminated";
2637 case MPI2_SCSI_STATUS_TASK_SET_FULL
:
2638 desc_scsi_status
= "task set full";
2640 case MPI2_SCSI_STATUS_ACA_ACTIVE
:
2641 desc_scsi_status
= "aca active";
2643 case MPI2_SCSI_STATUS_TASK_ABORTED
:
2644 desc_scsi_status
= "task aborted";
2647 desc_scsi_status
= "unknown";
2651 desc_scsi_state
[0] = '\0';
2653 desc_scsi_state
= " ";
2654 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
2655 strcat(desc_scsi_state
, "response info ");
2656 if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
2657 strcat(desc_scsi_state
, "state terminated ");
2658 if (scsi_state
& MPI2_SCSI_STATE_NO_SCSI_STATUS
)
2659 strcat(desc_scsi_state
, "no status ");
2660 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_FAILED
)
2661 strcat(desc_scsi_state
, "autosense failed ");
2662 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
)
2663 strcat(desc_scsi_state
, "autosense valid ");
2665 scsi_print_command(scmd
);
2666 printk(MPT2SAS_WARN_FMT
"\tdev handle(0x%04x), "
2667 "ioc_status(%s)(0x%04x), smid(%d)\n", ioc
->name
,
2668 le16_to_cpu(mpi_reply
->DevHandle
), desc_ioc_state
,
2670 printk(MPT2SAS_WARN_FMT
"\trequest_len(%d), underflow(%d), "
2671 "resid(%d)\n", ioc
->name
, scsi_bufflen(scmd
), scmd
->underflow
,
2672 scsi_get_resid(scmd
));
2673 printk(MPT2SAS_WARN_FMT
"\ttag(%d), transfer_count(%d), "
2674 "sc->result(0x%08x)\n", ioc
->name
, le16_to_cpu(mpi_reply
->TaskTag
),
2675 le32_to_cpu(mpi_reply
->TransferCount
), scmd
->result
);
2676 printk(MPT2SAS_WARN_FMT
"\tscsi_status(%s)(0x%02x), "
2677 "scsi_state(%s)(0x%02x)\n", ioc
->name
, desc_scsi_status
,
2678 scsi_status
, desc_scsi_state
, scsi_state
);
2680 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
2681 struct sense_info data
;
2682 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
2683 printk(MPT2SAS_WARN_FMT
"\t[sense_key,asc,ascq]: "
2684 "[0x%02x,0x%02x,0x%02x]\n", ioc
->name
, data
.skey
,
2685 data
.asc
, data
.ascq
);
2688 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
) {
2689 response_info
= le32_to_cpu(mpi_reply
->ResponseInfo
);
2690 response_bytes
= (u8
*)&response_info
;
2691 _scsih_response_code(ioc
, response_bytes
[3]);
2697 * _scsih_smart_predicted_fault - illuminate Fault LED
2698 * @ioc: per adapter object
2699 * @handle: device handle
2704 _scsih_smart_predicted_fault(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
2706 Mpi2SepReply_t mpi_reply
;
2707 Mpi2SepRequest_t mpi_request
;
2708 struct scsi_target
*starget
;
2709 struct MPT2SAS_TARGET
*sas_target_priv_data
;
2710 Mpi2EventNotificationReply_t
*event_reply
;
2711 Mpi2EventDataSasDeviceStatusChange_t
*event_data
;
2712 struct _sas_device
*sas_device
;
2714 unsigned long flags
;
2716 /* only handle non-raid devices */
2717 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2718 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
2720 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2723 starget
= sas_device
->starget
;
2724 sas_target_priv_data
= starget
->hostdata
;
2726 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
) ||
2727 ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
))) {
2728 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2731 starget_printk(KERN_WARNING
, starget
, "predicted fault\n");
2732 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2734 if (ioc
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_IBM
) {
2735 memset(&mpi_request
, 0, sizeof(Mpi2SepRequest_t
));
2736 mpi_request
.Function
= MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR
;
2737 mpi_request
.Action
= MPI2_SEP_REQ_ACTION_WRITE_STATUS
;
2738 mpi_request
.SlotStatus
=
2739 MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT
;
2740 mpi_request
.DevHandle
= cpu_to_le16(handle
);
2741 mpi_request
.Flags
= MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS
;
2742 if ((mpt2sas_base_scsi_enclosure_processor(ioc
, &mpi_reply
,
2743 &mpi_request
)) != 0) {
2744 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
2745 ioc
->name
, __FILE__
, __LINE__
, __func__
);
2749 if (mpi_reply
.IOCStatus
|| mpi_reply
.IOCLogInfo
) {
2750 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
2751 "enclosure_processor: ioc_status (0x%04x), "
2752 "loginfo(0x%08x)\n", ioc
->name
,
2753 le16_to_cpu(mpi_reply
.IOCStatus
),
2754 le32_to_cpu(mpi_reply
.IOCLogInfo
)));
2759 /* insert into event log */
2760 sz
= offsetof(Mpi2EventNotificationReply_t
, EventData
) +
2761 sizeof(Mpi2EventDataSasDeviceStatusChange_t
);
2762 event_reply
= kzalloc(sz
, GFP_KERNEL
);
2764 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
2765 ioc
->name
, __FILE__
, __LINE__
, __func__
);
2769 event_reply
->Function
= MPI2_FUNCTION_EVENT_NOTIFICATION
;
2770 event_reply
->Event
=
2771 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
);
2772 event_reply
->MsgLength
= sz
/4;
2773 event_reply
->EventDataLength
=
2774 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t
)/4);
2775 event_data
= (Mpi2EventDataSasDeviceStatusChange_t
*)
2776 event_reply
->EventData
;
2777 event_data
->ReasonCode
= MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
;
2778 event_data
->ASC
= 0x5D;
2779 event_data
->DevHandle
= cpu_to_le16(handle
);
2780 event_data
->SASAddress
= cpu_to_le64(sas_target_priv_data
->sas_address
);
2781 mpt2sas_ctl_add_to_event_log(ioc
, event_reply
);
2786 * scsih_io_done - scsi request callback
2787 * @ioc: per adapter object
2788 * @smid: system request message index
2789 * @VF_ID: virtual function id
2790 * @reply: reply message frame(lower 32bit addr)
2792 * Callback handler when using scsih_qcmd.
2797 scsih_io_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 VF_ID
, u32 reply
)
2799 Mpi2SCSIIORequest_t
*mpi_request
;
2800 Mpi2SCSIIOReply_t
*mpi_reply
;
2801 struct scsi_cmnd
*scmd
;
2807 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2810 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
2811 scmd
= _scsih_scsi_lookup_getclear(ioc
, smid
);
2815 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
2817 if (mpi_reply
== NULL
) {
2818 scmd
->result
= DID_OK
<< 16;
2822 sas_device_priv_data
= scmd
->device
->hostdata
;
2823 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
||
2824 sas_device_priv_data
->sas_target
->deleted
) {
2825 scmd
->result
= DID_NO_CONNECT
<< 16;
2829 /* turning off TLR */
2830 if (!sas_device_priv_data
->tlr_snoop_check
) {
2831 sas_device_priv_data
->tlr_snoop_check
++;
2832 if (sas_device_priv_data
->flags
& MPT_DEVICE_TLR_ON
) {
2833 response_code
= (le32_to_cpu(mpi_reply
->ResponseInfo
)
2835 if (response_code
==
2836 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
)
2837 sas_device_priv_data
->flags
&=
2842 xfer_cnt
= le32_to_cpu(mpi_reply
->TransferCount
);
2843 scsi_set_resid(scmd
, scsi_bufflen(scmd
) - xfer_cnt
);
2844 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
);
2845 if (ioc_status
& MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE
)
2846 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
2849 ioc_status
&= MPI2_IOCSTATUS_MASK
;
2850 scsi_state
= mpi_reply
->SCSIState
;
2851 scsi_status
= mpi_reply
->SCSIStatus
;
2853 if (ioc_status
== MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
&& xfer_cnt
== 0 &&
2854 (scsi_status
== MPI2_SCSI_STATUS_BUSY
||
2855 scsi_status
== MPI2_SCSI_STATUS_RESERVATION_CONFLICT
||
2856 scsi_status
== MPI2_SCSI_STATUS_TASK_SET_FULL
)) {
2857 ioc_status
= MPI2_IOCSTATUS_SUCCESS
;
2860 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
2861 struct sense_info data
;
2862 const void *sense_data
= mpt2sas_base_get_sense_buffer(ioc
,
2864 u32 sz
= min_t(u32
, SCSI_SENSE_BUFFERSIZE
,
2865 le32_to_cpu(mpi_reply
->SenseCount
));
2866 memcpy(scmd
->sense_buffer
, sense_data
, sz
);
2867 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
2868 /* failure prediction threshold exceeded */
2869 if (data
.asc
== 0x5D)
2870 _scsih_smart_predicted_fault(ioc
,
2871 le16_to_cpu(mpi_reply
->DevHandle
));
2874 switch (ioc_status
) {
2875 case MPI2_IOCSTATUS_BUSY
:
2876 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES
:
2877 scmd
->result
= SAM_STAT_BUSY
;
2880 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
2881 scmd
->result
= DID_NO_CONNECT
<< 16;
2884 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
2885 if (sas_device_priv_data
->block
) {
2886 scmd
->result
= (DID_BUS_BUSY
<< 16);
2890 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
2891 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
2892 scmd
->result
= DID_RESET
<< 16;
2895 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
2896 if ((xfer_cnt
== 0) || (scmd
->underflow
> xfer_cnt
))
2897 scmd
->result
= DID_SOFT_ERROR
<< 16;
2899 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
2902 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
2903 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
2905 if ((scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
))
2908 if (xfer_cnt
< scmd
->underflow
) {
2909 if (scsi_status
== SAM_STAT_BUSY
)
2910 scmd
->result
= SAM_STAT_BUSY
;
2912 scmd
->result
= DID_SOFT_ERROR
<< 16;
2913 } else if (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
2914 MPI2_SCSI_STATE_NO_SCSI_STATUS
))
2915 scmd
->result
= DID_SOFT_ERROR
<< 16;
2916 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
2917 scmd
->result
= DID_RESET
<< 16;
2918 else if (!xfer_cnt
&& scmd
->cmnd
[0] == REPORT_LUNS
) {
2919 mpi_reply
->SCSIState
= MPI2_SCSI_STATE_AUTOSENSE_VALID
;
2920 mpi_reply
->SCSIStatus
= SAM_STAT_CHECK_CONDITION
;
2921 scmd
->result
= (DRIVER_SENSE
<< 24) |
2922 SAM_STAT_CHECK_CONDITION
;
2923 scmd
->sense_buffer
[0] = 0x70;
2924 scmd
->sense_buffer
[2] = ILLEGAL_REQUEST
;
2925 scmd
->sense_buffer
[12] = 0x20;
2926 scmd
->sense_buffer
[13] = 0;
2930 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
2931 scsi_set_resid(scmd
, 0);
2932 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
2933 case MPI2_IOCSTATUS_SUCCESS
:
2934 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
2935 if (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
2936 MPI2_SCSI_STATE_NO_SCSI_STATUS
))
2937 scmd
->result
= DID_SOFT_ERROR
<< 16;
2938 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
2939 scmd
->result
= DID_RESET
<< 16;
2942 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
2943 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
2944 case MPI2_IOCSTATUS_INVALID_SGL
:
2945 case MPI2_IOCSTATUS_INTERNAL_ERROR
:
2946 case MPI2_IOCSTATUS_INVALID_FIELD
:
2947 case MPI2_IOCSTATUS_INVALID_STATE
:
2948 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
2949 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
2951 scmd
->result
= DID_SOFT_ERROR
<< 16;
2956 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
2957 if (scmd
->result
&& (ioc
->logging_level
& MPT_DEBUG_REPLY
))
2958 _scsih_scsi_ioc_info(ioc
, scmd
, mpi_reply
, smid
);
2962 scsi_dma_unmap(scmd
);
2963 scmd
->scsi_done(scmd
);
2967 * _scsih_link_change - process phy link changes
2968 * @ioc: per adapter object
2969 * @handle: phy handle
2970 * @attached_handle: valid for devices attached to link
2971 * @phy_number: phy number
2972 * @link_rate: new link rate
2978 _scsih_link_change(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
, u16 attached_handle
,
2979 u8 phy_number
, u8 link_rate
)
2981 mpt2sas_transport_update_phy_link_change(ioc
, handle
, attached_handle
,
2982 phy_number
, link_rate
);
2986 * _scsih_sas_host_refresh - refreshing sas host object contents
2987 * @ioc: per adapter object
2988 * @update: update link information
2991 * During port enable, fw will send topology events for every device. Its
2992 * possible that the handles may change from the previous setting, so this
2993 * code keeping handles updating if changed.
2998 _scsih_sas_host_refresh(struct MPT2SAS_ADAPTER
*ioc
, u8 update
)
3003 Mpi2ConfigReply_t mpi_reply
;
3004 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
3006 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
3007 "updating handles for sas_host(0x%016llx)\n",
3008 ioc
->name
, (unsigned long long)ioc
->sas_hba
.sas_address
));
3010 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
3011 * sizeof(Mpi2SasIOUnit0PhyData_t
));
3012 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
3013 if (!sas_iounit_pg0
) {
3014 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3015 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3018 if (!(mpt2sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
3019 sas_iounit_pg0
, sz
))) {
3020 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
3021 MPI2_IOCSTATUS_MASK
;
3022 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
3024 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
3025 ioc
->sas_hba
.phy
[i
].handle
=
3026 le16_to_cpu(sas_iounit_pg0
->PhyData
[i
].
3027 ControllerDevHandle
);
3029 _scsih_link_change(ioc
,
3030 ioc
->sas_hba
.phy
[i
].handle
,
3031 le16_to_cpu(sas_iounit_pg0
->PhyData
[i
].
3032 AttachedDevHandle
), i
,
3033 sas_iounit_pg0
->PhyData
[i
].
3034 NegotiatedLinkRate
>> 4);
3039 kfree(sas_iounit_pg0
);
3043 * _scsih_sas_host_add - create sas host object
3044 * @ioc: per adapter object
3046 * Creating host side data object, stored in ioc->sas_hba
3051 _scsih_sas_host_add(struct MPT2SAS_ADAPTER
*ioc
)
3054 Mpi2ConfigReply_t mpi_reply
;
3055 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
3056 Mpi2SasIOUnitPage1_t
*sas_iounit_pg1
= NULL
;
3057 Mpi2SasPhyPage0_t phy_pg0
;
3058 Mpi2SasDevicePage0_t sas_device_pg0
;
3059 Mpi2SasEnclosurePage0_t enclosure_pg0
;
3062 u16 device_missing_delay
;
3064 mpt2sas_config_get_number_hba_phys(ioc
, &ioc
->sas_hba
.num_phys
);
3065 if (!ioc
->sas_hba
.num_phys
) {
3066 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3067 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3071 /* sas_iounit page 0 */
3072 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
3073 sizeof(Mpi2SasIOUnit0PhyData_t
));
3074 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
3075 if (!sas_iounit_pg0
) {
3076 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3077 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3080 if ((mpt2sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
3081 sas_iounit_pg0
, sz
))) {
3082 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3083 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3086 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
3087 MPI2_IOCSTATUS_MASK
;
3088 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
3089 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3090 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3094 /* sas_iounit page 1 */
3095 sz
= offsetof(Mpi2SasIOUnitPage1_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
3096 sizeof(Mpi2SasIOUnit1PhyData_t
));
3097 sas_iounit_pg1
= kzalloc(sz
, GFP_KERNEL
);
3098 if (!sas_iounit_pg1
) {
3099 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3100 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3103 if ((mpt2sas_config_get_sas_iounit_pg1(ioc
, &mpi_reply
,
3104 sas_iounit_pg1
, sz
))) {
3105 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3106 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3109 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
3110 MPI2_IOCSTATUS_MASK
;
3111 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
3112 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3113 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3117 ioc
->io_missing_delay
=
3118 le16_to_cpu(sas_iounit_pg1
->IODeviceMissingDelay
);
3119 device_missing_delay
=
3120 le16_to_cpu(sas_iounit_pg1
->ReportDeviceMissingDelay
);
3121 if (device_missing_delay
& MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16
)
3122 ioc
->device_missing_delay
= (device_missing_delay
&
3123 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
) * 16;
3125 ioc
->device_missing_delay
= device_missing_delay
&
3126 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
;
3128 ioc
->sas_hba
.parent_dev
= &ioc
->shost
->shost_gendev
;
3129 ioc
->sas_hba
.phy
= kcalloc(ioc
->sas_hba
.num_phys
,
3130 sizeof(struct _sas_phy
), GFP_KERNEL
);
3131 if (!ioc
->sas_hba
.phy
) {
3132 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3133 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3136 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
3137 if ((mpt2sas_config_get_phy_pg0(ioc
, &mpi_reply
, &phy_pg0
,
3139 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3140 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3143 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
3144 MPI2_IOCSTATUS_MASK
;
3145 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
3146 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3147 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3150 ioc
->sas_hba
.phy
[i
].handle
=
3151 le16_to_cpu(sas_iounit_pg0
->PhyData
[i
].ControllerDevHandle
);
3152 ioc
->sas_hba
.phy
[i
].phy_id
= i
;
3153 mpt2sas_transport_add_host_phy(ioc
, &ioc
->sas_hba
.phy
[i
],
3154 phy_pg0
, ioc
->sas_hba
.parent_dev
);
3156 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
3157 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, ioc
->sas_hba
.phy
[0].handle
))) {
3158 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3159 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3162 ioc
->sas_hba
.handle
= le16_to_cpu(sas_device_pg0
.DevHandle
);
3163 ioc
->sas_hba
.enclosure_handle
=
3164 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
3165 ioc
->sas_hba
.sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
3166 printk(MPT2SAS_INFO_FMT
"host_add: handle(0x%04x), "
3167 "sas_addr(0x%016llx), phys(%d)\n", ioc
->name
, ioc
->sas_hba
.handle
,
3168 (unsigned long long) ioc
->sas_hba
.sas_address
,
3169 ioc
->sas_hba
.num_phys
) ;
3171 if (ioc
->sas_hba
.enclosure_handle
) {
3172 if (!(mpt2sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
3174 MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
3175 ioc
->sas_hba
.enclosure_handle
))) {
3176 ioc
->sas_hba
.enclosure_logical_id
=
3177 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
3182 kfree(sas_iounit_pg1
);
3183 kfree(sas_iounit_pg0
);
3187 * _scsih_expander_add - creating expander object
3188 * @ioc: per adapter object
3189 * @handle: expander handle
3191 * Creating expander object, stored in ioc->sas_expander_list.
3193 * Return 0 for success, else error.
3196 _scsih_expander_add(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
3198 struct _sas_node
*sas_expander
;
3199 Mpi2ConfigReply_t mpi_reply
;
3200 Mpi2ExpanderPage0_t expander_pg0
;
3201 Mpi2ExpanderPage1_t expander_pg1
;
3202 Mpi2SasEnclosurePage0_t enclosure_pg0
;
3207 unsigned long flags
;
3208 struct _sas_port
*mpt2sas_port
;
3214 if ((mpt2sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
3215 MPI2_SAS_EXPAND_PGAD_FORM_HNDL
, handle
))) {
3216 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3217 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3221 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
3222 MPI2_IOCSTATUS_MASK
;
3223 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
3224 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3225 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3229 /* handle out of order topology events */
3230 parent_handle
= le16_to_cpu(expander_pg0
.ParentDevHandle
);
3231 if (parent_handle
>= ioc
->sas_hba
.num_phys
) {
3232 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
3233 sas_expander
= mpt2sas_scsih_expander_find_by_handle(ioc
,
3235 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
3236 if (!sas_expander
) {
3237 rc
= _scsih_expander_add(ioc
, parent_handle
);
3243 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
3245 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
3246 sas_expander
= mpt2sas_scsih_expander_find_by_sas_address(ioc
,
3248 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
3253 sas_expander
= kzalloc(sizeof(struct _sas_node
),
3255 if (!sas_expander
) {
3256 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3257 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3261 sas_expander
->handle
= handle
;
3262 sas_expander
->num_phys
= expander_pg0
.NumPhys
;
3263 sas_expander
->parent_handle
= parent_handle
;
3264 sas_expander
->enclosure_handle
=
3265 le16_to_cpu(expander_pg0
.EnclosureHandle
);
3266 sas_expander
->sas_address
= sas_address
;
3268 printk(MPT2SAS_INFO_FMT
"expander_add: handle(0x%04x),"
3269 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc
->name
,
3270 handle
, sas_expander
->parent_handle
, (unsigned long long)
3271 sas_expander
->sas_address
, sas_expander
->num_phys
);
3273 if (!sas_expander
->num_phys
)
3275 sas_expander
->phy
= kcalloc(sas_expander
->num_phys
,
3276 sizeof(struct _sas_phy
), GFP_KERNEL
);
3277 if (!sas_expander
->phy
) {
3278 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3279 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3284 INIT_LIST_HEAD(&sas_expander
->sas_port_list
);
3285 mpt2sas_port
= mpt2sas_transport_port_add(ioc
, handle
,
3286 sas_expander
->parent_handle
);
3287 if (!mpt2sas_port
) {
3288 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3289 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3293 sas_expander
->parent_dev
= &mpt2sas_port
->rphy
->dev
;
3295 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++) {
3296 if ((mpt2sas_config_get_expander_pg1(ioc
, &mpi_reply
,
3297 &expander_pg1
, i
, handle
))) {
3298 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3299 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3302 sas_expander
->phy
[i
].handle
= handle
;
3303 sas_expander
->phy
[i
].phy_id
= i
;
3304 mpt2sas_transport_add_expander_phy(ioc
, &sas_expander
->phy
[i
],
3305 expander_pg1
, sas_expander
->parent_dev
);
3308 if (sas_expander
->enclosure_handle
) {
3309 if (!(mpt2sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
3310 &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
3311 sas_expander
->enclosure_handle
))) {
3312 sas_expander
->enclosure_logical_id
=
3313 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
3317 _scsih_expander_node_add(ioc
, sas_expander
);
3323 kfree(sas_expander
->phy
);
3324 kfree(sas_expander
);
3329 * _scsih_expander_remove - removing expander object
3330 * @ioc: per adapter object
3331 * @handle: expander handle
3336 _scsih_expander_remove(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
3338 struct _sas_node
*sas_expander
;
3339 unsigned long flags
;
3341 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
3342 sas_expander
= mpt2sas_scsih_expander_find_by_handle(ioc
, handle
);
3343 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
3344 _scsih_expander_node_remove(ioc
, sas_expander
);
3348 * _scsih_add_device - creating sas device object
3349 * @ioc: per adapter object
3350 * @handle: sas device handle
3351 * @phy_num: phy number end device attached to
3352 * @is_pd: is this hidden raid component
3354 * Creating end device object, stored in ioc->sas_device_list.
3356 * Returns 0 for success, non-zero for failure.
3359 _scsih_add_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
, u8 phy_num
, u8 is_pd
)
3361 Mpi2ConfigReply_t mpi_reply
;
3362 Mpi2SasDevicePage0_t sas_device_pg0
;
3363 Mpi2SasEnclosurePage0_t enclosure_pg0
;
3364 struct _sas_device
*sas_device
;
3368 unsigned long flags
;
3370 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
3371 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
3372 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3373 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3377 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
3378 MPI2_IOCSTATUS_MASK
;
3379 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
3380 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3381 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3385 /* check if device is present */
3386 if (!(le16_to_cpu(sas_device_pg0
.Flags
) &
3387 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT
)) {
3388 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3389 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3390 printk(MPT2SAS_ERR_FMT
"Flags = 0x%04x\n",
3391 ioc
->name
, le16_to_cpu(sas_device_pg0
.Flags
));
3395 /* check if there were any issus with discovery */
3396 if (sas_device_pg0
.AccessStatus
==
3397 MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED
) {
3398 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3399 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3400 printk(MPT2SAS_ERR_FMT
"AccessStatus = 0x%02x\n",
3401 ioc
->name
, sas_device_pg0
.AccessStatus
);
3405 /* check if this is end device */
3406 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
3407 if (!(_scsih_is_end_device(device_info
))) {
3408 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3409 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3413 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
3415 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
3416 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
3418 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3421 _scsih_ublock_io_device(ioc
, handle
);
3425 sas_device
= kzalloc(sizeof(struct _sas_device
),
3428 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3429 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3433 sas_device
->handle
= handle
;
3434 sas_device
->parent_handle
=
3435 le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
3436 sas_device
->enclosure_handle
=
3437 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
3439 le16_to_cpu(sas_device_pg0
.Slot
);
3440 sas_device
->device_info
= device_info
;
3441 sas_device
->sas_address
= sas_address
;
3442 sas_device
->hidden_raid_component
= is_pd
;
3444 /* get enclosure_logical_id */
3445 if (!(mpt2sas_config_get_enclosure_pg0(ioc
, &mpi_reply
, &enclosure_pg0
,
3446 MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
3447 sas_device
->enclosure_handle
))) {
3448 sas_device
->enclosure_logical_id
=
3449 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
3452 /* get device name */
3453 sas_device
->device_name
= le64_to_cpu(sas_device_pg0
.DeviceName
);
3455 if (ioc
->wait_for_port_enable_to_complete
)
3456 _scsih_sas_device_init_add(ioc
, sas_device
);
3458 _scsih_sas_device_add(ioc
, sas_device
);
3464 * _scsih_remove_device - removing sas device object
3465 * @ioc: per adapter object
3466 * @handle: sas device handle
3471 _scsih_remove_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
3473 struct MPT2SAS_TARGET
*sas_target_priv_data
;
3474 struct _sas_device
*sas_device
;
3475 unsigned long flags
;
3476 Mpi2SasIoUnitControlReply_t mpi_reply
;
3477 Mpi2SasIoUnitControlRequest_t mpi_request
;
3480 /* lookup sas_device */
3481 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
3482 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
3484 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3488 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: enter: handle"
3489 "(0x%04x)\n", ioc
->name
, __func__
, handle
));
3491 if (sas_device
->starget
&& sas_device
->starget
->hostdata
) {
3492 sas_target_priv_data
= sas_device
->starget
->hostdata
;
3493 sas_target_priv_data
->deleted
= 1;
3495 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3497 if (ioc
->remove_host
)
3500 /* Target Reset to flush out all the outstanding IO */
3501 device_handle
= (sas_device
->hidden_raid_component
) ?
3502 sas_device
->volume_handle
: handle
;
3503 if (device_handle
) {
3504 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"issue target reset: "
3505 "handle(0x%04x)\n", ioc
->name
, device_handle
));
3506 mutex_lock(&ioc
->tm_cmds
.mutex
);
3507 mpt2sas_scsih_issue_tm(ioc
, device_handle
, 0,
3508 MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
, 0, 10);
3509 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
3510 mutex_unlock(&ioc
->tm_cmds
.mutex
);
3511 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"issue target reset "
3512 "done: handle(0x%04x)\n", ioc
->name
, device_handle
));
3515 /* SAS_IO_UNIT_CNTR - send REMOVE_DEVICE */
3516 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"sas_iounit: handle"
3517 "(0x%04x)\n", ioc
->name
, handle
));
3518 memset(&mpi_request
, 0, sizeof(Mpi2SasIoUnitControlRequest_t
));
3519 mpi_request
.Function
= MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
;
3520 mpi_request
.Operation
= MPI2_SAS_OP_REMOVE_DEVICE
;
3521 mpi_request
.DevHandle
= handle
;
3522 mpi_request
.VF_ID
= 0;
3523 if ((mpt2sas_base_sas_iounit_control(ioc
, &mpi_reply
,
3524 &mpi_request
)) != 0) {
3525 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3526 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3529 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"sas_iounit: ioc_status"
3530 "(0x%04x), loginfo(0x%08x)\n", ioc
->name
,
3531 le16_to_cpu(mpi_reply
.IOCStatus
),
3532 le32_to_cpu(mpi_reply
.IOCLogInfo
)));
3535 mpt2sas_transport_port_remove(ioc
, sas_device
->sas_address
,
3536 sas_device
->parent_handle
);
3538 printk(MPT2SAS_INFO_FMT
"removing handle(0x%04x), sas_addr"
3539 "(0x%016llx)\n", ioc
->name
, sas_device
->handle
,
3540 (unsigned long long) sas_device
->sas_address
);
3541 _scsih_sas_device_remove(ioc
, sas_device
);
3543 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: exit: handle"
3544 "(0x%04x)\n", ioc
->name
, __func__
, handle
));
3547 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3549 * _scsih_sas_topology_change_event_debug - debug for topology event
3550 * @ioc: per adapter object
3551 * @event_data: event data payload
3555 _scsih_sas_topology_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
3556 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
3562 char *status_str
= NULL
;
3565 switch (event_data
->ExpStatus
) {
3566 case MPI2_EVENT_SAS_TOPO_ES_ADDED
:
3569 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
:
3570 status_str
= "remove";
3572 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING
:
3573 status_str
= "responding";
3575 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
:
3576 status_str
= "remove delay";
3579 status_str
= "unknown status";
3582 printk(MPT2SAS_DEBUG_FMT
"sas topology change: (%s)\n",
3583 ioc
->name
, status_str
);
3584 printk(KERN_DEBUG
"\thandle(0x%04x), enclosure_handle(0x%04x) "
3585 "start_phy(%02d), count(%d)\n",
3586 le16_to_cpu(event_data
->ExpanderDevHandle
),
3587 le16_to_cpu(event_data
->EnclosureHandle
),
3588 event_data
->StartPhyNum
, event_data
->NumEntries
);
3589 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
3590 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
3593 phy_number
= event_data
->StartPhyNum
+ i
;
3594 reason_code
= event_data
->PHY
[i
].PhyStatus
&
3595 MPI2_EVENT_SAS_TOPO_RC_MASK
;
3596 switch (reason_code
) {
3597 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
3598 snprintf(link_rate
, 25, ": add, link(0x%02x)",
3599 (event_data
->PHY
[i
].LinkRate
>> 4));
3600 status_str
= link_rate
;
3602 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
3603 status_str
= ": remove";
3605 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
:
3606 status_str
= ": remove_delay";
3608 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
3609 snprintf(link_rate
, 25, ": link(0x%02x)",
3610 (event_data
->PHY
[i
].LinkRate
>> 4));
3611 status_str
= link_rate
;
3613 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE
:
3614 status_str
= ": responding";
3617 status_str
= ": unknown";
3620 printk(KERN_DEBUG
"\tphy(%02d), attached_handle(0x%04x)%s\n",
3621 phy_number
, handle
, status_str
);
3627 * _scsih_sas_topology_change_event - handle topology changes
3628 * @ioc: per adapter object
3630 * @event_data: event data payload
3636 _scsih_sas_topology_change_event(struct MPT2SAS_ADAPTER
*ioc
, u8 VF_ID
,
3637 Mpi2EventDataSasTopologyChangeList_t
*event_data
,
3638 struct fw_event_work
*fw_event
)
3641 u16 parent_handle
, handle
;
3644 struct _sas_node
*sas_expander
;
3645 unsigned long flags
;
3648 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3649 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
3650 _scsih_sas_topology_change_event_debug(ioc
, event_data
);
3653 if (!ioc
->sas_hba
.num_phys
)
3654 _scsih_sas_host_add(ioc
);
3656 _scsih_sas_host_refresh(ioc
, 0);
3658 if (fw_event
->ignore
) {
3659 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"ignoring expander "
3660 "event\n", ioc
->name
));
3664 parent_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
3666 /* handle expander add */
3667 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_ADDED
)
3668 if (_scsih_expander_add(ioc
, parent_handle
) != 0)
3671 /* handle siblings events */
3672 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
3673 if (fw_event
->ignore
) {
3674 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"ignoring "
3675 "expander event\n", ioc
->name
));
3678 if (event_data
->PHY
[i
].PhyStatus
&
3679 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT
)
3681 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
3684 phy_number
= event_data
->StartPhyNum
+ i
;
3685 reason_code
= event_data
->PHY
[i
].PhyStatus
&
3686 MPI2_EVENT_SAS_TOPO_RC_MASK
;
3687 link_rate_
= event_data
->PHY
[i
].LinkRate
>> 4;
3688 switch (reason_code
) {
3689 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
3690 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
3691 if (!parent_handle
) {
3692 if (phy_number
< ioc
->sas_hba
.num_phys
)
3693 _scsih_link_change(ioc
,
3694 ioc
->sas_hba
.phy
[phy_number
].handle
,
3695 handle
, phy_number
, link_rate_
);
3697 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
3699 mpt2sas_scsih_expander_find_by_handle(ioc
,
3701 spin_unlock_irqrestore(&ioc
->sas_node_lock
,
3704 if (phy_number
< sas_expander
->num_phys
)
3705 _scsih_link_change(ioc
,
3707 phy
[phy_number
].handle
,
3712 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
) {
3713 if (link_rate_
>= MPI2_SAS_NEG_LINK_RATE_1_5
)
3714 _scsih_ublock_io_device(ioc
, handle
);
3716 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
) {
3717 if (link_rate_
< MPI2_SAS_NEG_LINK_RATE_1_5
)
3719 _scsih_add_device(ioc
, handle
, phy_number
, 0);
3722 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
3723 _scsih_remove_device(ioc
, handle
);
3728 /* handle expander removal */
3729 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
)
3730 _scsih_expander_remove(ioc
, parent_handle
);
3734 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3736 * _scsih_sas_device_status_change_event_debug - debug for device event
3737 * @event_data: event data payload
3743 _scsih_sas_device_status_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
3744 Mpi2EventDataSasDeviceStatusChange_t
*event_data
)
3746 char *reason_str
= NULL
;
3748 switch (event_data
->ReasonCode
) {
3749 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
:
3750 reason_str
= "smart data";
3752 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED
:
3753 reason_str
= "unsupported device discovered";
3755 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
:
3756 reason_str
= "internal device reset";
3758 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL
:
3759 reason_str
= "internal task abort";
3761 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL
:
3762 reason_str
= "internal task abort set";
3764 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL
:
3765 reason_str
= "internal clear task set";
3767 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL
:
3768 reason_str
= "internal query task";
3770 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE
:
3771 reason_str
= "sata init failure";
3773 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
:
3774 reason_str
= "internal device reset complete";
3776 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL
:
3777 reason_str
= "internal task abort complete";
3779 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION
:
3780 reason_str
= "internal async notification";
3783 reason_str
= "unknown reason";
3786 printk(MPT2SAS_DEBUG_FMT
"device status change: (%s)\n"
3787 "\thandle(0x%04x), sas address(0x%016llx)", ioc
->name
,
3788 reason_str
, le16_to_cpu(event_data
->DevHandle
),
3789 (unsigned long long)le64_to_cpu(event_data
->SASAddress
));
3790 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
)
3791 printk(MPT2SAS_DEBUG_FMT
", ASC(0x%x), ASCQ(0x%x)\n", ioc
->name
,
3792 event_data
->ASC
, event_data
->ASCQ
);
3793 printk(KERN_INFO
"\n");
3798 * _scsih_sas_device_status_change_event - handle device status change
3799 * @ioc: per adapter object
3801 * @event_data: event data payload
3807 _scsih_sas_device_status_change_event(struct MPT2SAS_ADAPTER
*ioc
, u8 VF_ID
,
3808 Mpi2EventDataSasDeviceStatusChange_t
*event_data
)
3810 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3811 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
3812 _scsih_sas_device_status_change_event_debug(ioc
, event_data
);
3816 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3818 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure event
3819 * @ioc: per adapter object
3820 * @event_data: event data payload
3826 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
3827 Mpi2EventDataSasEnclDevStatusChange_t
*event_data
)
3829 char *reason_str
= NULL
;
3831 switch (event_data
->ReasonCode
) {
3832 case MPI2_EVENT_SAS_ENCL_RC_ADDED
:
3833 reason_str
= "enclosure add";
3835 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING
:
3836 reason_str
= "enclosure remove";
3839 reason_str
= "unknown reason";
3843 printk(MPT2SAS_DEBUG_FMT
"enclosure status change: (%s)\n"
3844 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
3845 " number slots(%d)\n", ioc
->name
, reason_str
,
3846 le16_to_cpu(event_data
->EnclosureHandle
),
3847 (unsigned long long)le64_to_cpu(event_data
->EnclosureLogicalID
),
3848 le16_to_cpu(event_data
->StartSlot
));
3853 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
3854 * @ioc: per adapter object
3856 * @event_data: event data payload
3862 _scsih_sas_enclosure_dev_status_change_event(struct MPT2SAS_ADAPTER
*ioc
,
3863 u8 VF_ID
, Mpi2EventDataSasEnclDevStatusChange_t
*event_data
)
3865 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3866 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
3867 _scsih_sas_enclosure_dev_status_change_event_debug(ioc
,
3873 * _scsih_sas_broadcast_primative_event - handle broadcast events
3874 * @ioc: per adapter object
3875 * @event_data: event data payload
3881 _scsih_sas_broadcast_primative_event(struct MPT2SAS_ADAPTER
*ioc
, u8 VF_ID
,
3882 Mpi2EventDataSasBroadcastPrimitive_t
*event_data
)
3884 struct scsi_cmnd
*scmd
;
3887 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
3888 u32 termination_count
;
3890 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
3892 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"broadcast primative: "
3893 "phy number(%d), width(%d)\n", ioc
->name
, event_data
->PhyNum
,
3894 event_data
->PortWidth
));
3896 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: enter\n", ioc
->name
,
3899 mutex_lock(&ioc
->tm_cmds
.mutex
);
3900 termination_count
= 0;
3902 mpi_reply
= ioc
->tm_cmds
.reply
;
3903 for (smid
= 1; smid
<= ioc
->request_depth
; smid
++) {
3904 scmd
= _scsih_scsi_lookup_get(ioc
, smid
);
3907 sas_device_priv_data
= scmd
->device
->hostdata
;
3908 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
)
3910 /* skip hidden raid components */
3911 if (sas_device_priv_data
->sas_target
->flags
&
3912 MPT_TARGET_FLAGS_RAID_COMPONENT
)
3915 if (sas_device_priv_data
->sas_target
->flags
&
3916 MPT_TARGET_FLAGS_VOLUME
)
3919 handle
= sas_device_priv_data
->sas_target
->handle
;
3920 lun
= sas_device_priv_data
->lun
;
3923 mpt2sas_scsih_issue_tm(ioc
, handle
, lun
,
3924 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK
, smid
, 30);
3925 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
3927 if ((mpi_reply
->IOCStatus
== MPI2_IOCSTATUS_SUCCESS
) &&
3928 (mpi_reply
->ResponseCode
==
3929 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
||
3930 mpi_reply
->ResponseCode
==
3931 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
))
3934 mpt2sas_scsih_issue_tm(ioc
, handle
, lun
,
3935 MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET
, 0, 30);
3936 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
3937 termination_count
+= le32_to_cpu(mpi_reply
->TerminationCount
);
3939 ioc
->broadcast_aen_busy
= 0;
3940 mutex_unlock(&ioc
->tm_cmds
.mutex
);
3942 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
3943 "%s - exit, query_count = %d termination_count = %d\n",
3944 ioc
->name
, __func__
, query_count
, termination_count
));
3948 * _scsih_sas_discovery_event - handle discovery events
3949 * @ioc: per adapter object
3950 * @event_data: event data payload
3956 _scsih_sas_discovery_event(struct MPT2SAS_ADAPTER
*ioc
, u8 VF_ID
,
3957 Mpi2EventDataSasDiscovery_t
*event_data
)
3959 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3960 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
) {
3961 printk(MPT2SAS_DEBUG_FMT
"discovery event: (%s)", ioc
->name
,
3962 (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
) ?
3964 if (event_data
->DiscoveryStatus
)
3965 printk(MPT2SAS_DEBUG_FMT
", discovery_status(0x%08x)",
3966 ioc
->name
, le32_to_cpu(event_data
->DiscoveryStatus
));
3971 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
&&
3972 !ioc
->sas_hba
.num_phys
)
3973 _scsih_sas_host_add(ioc
);
3977 * _scsih_reprobe_lun - reprobing lun
3978 * @sdev: scsi device struct
3979 * @no_uld_attach: sdev->no_uld_attach flag setting
3983 _scsih_reprobe_lun(struct scsi_device
*sdev
, void *no_uld_attach
)
3987 sdev
->no_uld_attach
= no_uld_attach
? 1 : 0;
3988 sdev_printk(KERN_INFO
, sdev
, "%s raid component\n",
3989 sdev
->no_uld_attach
? "hidding" : "exposing");
3990 rc
= scsi_device_reprobe(sdev
);
3994 * _scsih_reprobe_target - reprobing target
3995 * @starget: scsi target struct
3996 * @no_uld_attach: sdev->no_uld_attach flag setting
3998 * Note: no_uld_attach flag determines whether the disk device is attached
3999 * to block layer. A value of `1` means to not attach.
4002 _scsih_reprobe_target(struct scsi_target
*starget
, int no_uld_attach
)
4004 struct MPT2SAS_TARGET
*sas_target_priv_data
= starget
->hostdata
;
4007 sas_target_priv_data
->flags
|= MPT_TARGET_FLAGS_RAID_COMPONENT
;
4009 sas_target_priv_data
->flags
&= ~MPT_TARGET_FLAGS_RAID_COMPONENT
;
4011 starget_for_each_device(starget
, no_uld_attach
? (void *)1 : NULL
,
4012 _scsih_reprobe_lun
);
4015 * _scsih_sas_volume_add - add new volume
4016 * @ioc: per adapter object
4017 * @element: IR config element data
4023 _scsih_sas_volume_add(struct MPT2SAS_ADAPTER
*ioc
,
4024 Mpi2EventIrConfigElement_t
*element
)
4026 struct _raid_device
*raid_device
;
4027 unsigned long flags
;
4029 u16 handle
= le16_to_cpu(element
->VolDevHandle
);
4032 #if 0 /* RAID_HACKS */
4033 if (le32_to_cpu(event_data
->Flags
) &
4034 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
)
4038 mpt2sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
4040 printk(MPT2SAS_ERR_FMT
4041 "failure at %s:%d/%s()!\n", ioc
->name
,
4042 __FILE__
, __LINE__
, __func__
);
4046 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
4047 raid_device
= _scsih_raid_device_find_by_wwid(ioc
, wwid
);
4048 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
4053 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
4055 printk(MPT2SAS_ERR_FMT
4056 "failure at %s:%d/%s()!\n", ioc
->name
,
4057 __FILE__
, __LINE__
, __func__
);
4061 raid_device
->id
= ioc
->sas_id
++;
4062 raid_device
->channel
= RAID_CHANNEL
;
4063 raid_device
->handle
= handle
;
4064 raid_device
->wwid
= wwid
;
4065 _scsih_raid_device_add(ioc
, raid_device
);
4066 if (!ioc
->wait_for_port_enable_to_complete
) {
4067 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
4068 raid_device
->id
, 0);
4070 _scsih_raid_device_remove(ioc
, raid_device
);
4072 _scsih_determine_boot_device(ioc
, raid_device
, 1);
4076 * _scsih_sas_volume_delete - delete volume
4077 * @ioc: per adapter object
4078 * @element: IR config element data
4084 _scsih_sas_volume_delete(struct MPT2SAS_ADAPTER
*ioc
,
4085 Mpi2EventIrConfigElement_t
*element
)
4087 struct _raid_device
*raid_device
;
4088 u16 handle
= le16_to_cpu(element
->VolDevHandle
);
4089 unsigned long flags
;
4090 struct MPT2SAS_TARGET
*sas_target_priv_data
;
4092 #if 0 /* RAID_HACKS */
4093 if (le32_to_cpu(event_data
->Flags
) &
4094 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
)
4098 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
4099 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
4100 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
4103 if (raid_device
->starget
) {
4104 sas_target_priv_data
= raid_device
->starget
->hostdata
;
4105 sas_target_priv_data
->deleted
= 1;
4106 scsi_remove_target(&raid_device
->starget
->dev
);
4108 _scsih_raid_device_remove(ioc
, raid_device
);
4112 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
4113 * @ioc: per adapter object
4114 * @element: IR config element data
4120 _scsih_sas_pd_expose(struct MPT2SAS_ADAPTER
*ioc
,
4121 Mpi2EventIrConfigElement_t
*element
)
4123 struct _sas_device
*sas_device
;
4124 unsigned long flags
;
4125 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
4127 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4128 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
4129 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4133 /* exposing raid component */
4134 sas_device
->volume_handle
= 0;
4135 sas_device
->volume_wwid
= 0;
4136 sas_device
->hidden_raid_component
= 0;
4137 _scsih_reprobe_target(sas_device
->starget
, 0);
4141 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
4142 * @ioc: per adapter object
4143 * @element: IR config element data
4149 _scsih_sas_pd_hide(struct MPT2SAS_ADAPTER
*ioc
,
4150 Mpi2EventIrConfigElement_t
*element
)
4152 struct _sas_device
*sas_device
;
4153 unsigned long flags
;
4154 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
4156 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4157 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
4158 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4162 /* hiding raid component */
4163 mpt2sas_config_get_volume_handle(ioc
, handle
,
4164 &sas_device
->volume_handle
);
4165 mpt2sas_config_get_volume_wwid(ioc
, sas_device
->volume_handle
,
4166 &sas_device
->volume_wwid
);
4167 sas_device
->hidden_raid_component
= 1;
4168 _scsih_reprobe_target(sas_device
->starget
, 1);
4172 * _scsih_sas_pd_delete - delete pd component
4173 * @ioc: per adapter object
4174 * @element: IR config element data
4180 _scsih_sas_pd_delete(struct MPT2SAS_ADAPTER
*ioc
,
4181 Mpi2EventIrConfigElement_t
*element
)
4183 struct _sas_device
*sas_device
;
4184 unsigned long flags
;
4185 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
4187 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4188 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
4189 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4192 _scsih_remove_device(ioc
, handle
);
4196 * _scsih_sas_pd_add - remove pd component
4197 * @ioc: per adapter object
4198 * @element: IR config element data
4204 _scsih_sas_pd_add(struct MPT2SAS_ADAPTER
*ioc
,
4205 Mpi2EventIrConfigElement_t
*element
)
4207 struct _sas_device
*sas_device
;
4208 unsigned long flags
;
4209 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
4211 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4212 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
4213 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4215 sas_device
->hidden_raid_component
= 1;
4217 _scsih_add_device(ioc
, handle
, 0, 1);
4220 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4222 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
4223 * @ioc: per adapter object
4224 * @event_data: event data payload
4230 _scsih_sas_ir_config_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
4231 Mpi2EventDataIrConfigChangeList_t
*event_data
)
4233 Mpi2EventIrConfigElement_t
*element
;
4236 char *reason_str
= NULL
, *element_str
= NULL
;
4238 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
4240 printk(MPT2SAS_DEBUG_FMT
"raid config change: (%s), elements(%d)\n",
4241 ioc
->name
, (le32_to_cpu(event_data
->Flags
) &
4242 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ?
4243 "foreign" : "native", event_data
->NumElements
);
4244 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
4245 switch (element
->ReasonCode
) {
4246 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
4249 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
4250 reason_str
= "remove";
4252 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE
:
4253 reason_str
= "no change";
4255 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
4256 reason_str
= "hide";
4258 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
4259 reason_str
= "unhide";
4261 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
4262 reason_str
= "volume_created";
4264 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
4265 reason_str
= "volume_deleted";
4267 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
4268 reason_str
= "pd_created";
4270 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
4271 reason_str
= "pd_deleted";
4274 reason_str
= "unknown reason";
4277 element_type
= le16_to_cpu(element
->ElementFlags
) &
4278 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK
;
4279 switch (element_type
) {
4280 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT
:
4281 element_str
= "volume";
4283 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT
:
4284 element_str
= "phys disk";
4286 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT
:
4287 element_str
= "hot spare";
4290 element_str
= "unknown element";
4293 printk(KERN_DEBUG
"\t(%s:%s), vol handle(0x%04x), "
4294 "pd handle(0x%04x), pd num(0x%02x)\n", element_str
,
4295 reason_str
, le16_to_cpu(element
->VolDevHandle
),
4296 le16_to_cpu(element
->PhysDiskDevHandle
),
4297 element
->PhysDiskNum
);
4303 * _scsih_sas_ir_config_change_event - handle ir configuration change events
4304 * @ioc: per adapter object
4306 * @event_data: event data payload
4312 _scsih_sas_ir_config_change_event(struct MPT2SAS_ADAPTER
*ioc
, u8 VF_ID
,
4313 Mpi2EventDataIrConfigChangeList_t
*event_data
)
4315 Mpi2EventIrConfigElement_t
*element
;
4318 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4319 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
4320 _scsih_sas_ir_config_change_event_debug(ioc
, event_data
);
4324 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
4325 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
4327 switch (element
->ReasonCode
) {
4328 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
4329 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
4330 _scsih_sas_volume_add(ioc
, element
);
4332 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
4333 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
4334 _scsih_sas_volume_delete(ioc
, element
);
4336 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
4337 _scsih_sas_pd_hide(ioc
, element
);
4339 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
4340 _scsih_sas_pd_expose(ioc
, element
);
4342 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
4343 _scsih_sas_pd_add(ioc
, element
);
4345 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
4346 _scsih_sas_pd_delete(ioc
, element
);
4353 * _scsih_sas_ir_volume_event - IR volume event
4354 * @ioc: per adapter object
4355 * @event_data: event data payload
4361 _scsih_sas_ir_volume_event(struct MPT2SAS_ADAPTER
*ioc
, u8 VF_ID
,
4362 Mpi2EventDataIrVolume_t
*event_data
)
4365 unsigned long flags
;
4366 struct _raid_device
*raid_device
;
4370 struct MPT2SAS_TARGET
*sas_target_priv_data
;
4372 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED
)
4375 handle
= le16_to_cpu(event_data
->VolDevHandle
);
4376 state
= le32_to_cpu(event_data
->NewValue
);
4377 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: handle(0x%04x), "
4378 "old(0x%08x), new(0x%08x)\n", ioc
->name
, __func__
, handle
,
4379 le32_to_cpu(event_data
->PreviousValue
), state
));
4381 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
4382 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
4383 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
4386 case MPI2_RAID_VOL_STATE_MISSING
:
4387 case MPI2_RAID_VOL_STATE_FAILED
:
4390 if (raid_device
->starget
) {
4391 sas_target_priv_data
= raid_device
->starget
->hostdata
;
4392 sas_target_priv_data
->deleted
= 1;
4393 scsi_remove_target(&raid_device
->starget
->dev
);
4395 _scsih_raid_device_remove(ioc
, raid_device
);
4398 case MPI2_RAID_VOL_STATE_ONLINE
:
4399 case MPI2_RAID_VOL_STATE_DEGRADED
:
4400 case MPI2_RAID_VOL_STATE_OPTIMAL
:
4404 mpt2sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
4406 printk(MPT2SAS_ERR_FMT
4407 "failure at %s:%d/%s()!\n", ioc
->name
,
4408 __FILE__
, __LINE__
, __func__
);
4412 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
4414 printk(MPT2SAS_ERR_FMT
4415 "failure at %s:%d/%s()!\n", ioc
->name
,
4416 __FILE__
, __LINE__
, __func__
);
4420 raid_device
->id
= ioc
->sas_id
++;
4421 raid_device
->channel
= RAID_CHANNEL
;
4422 raid_device
->handle
= handle
;
4423 raid_device
->wwid
= wwid
;
4424 _scsih_raid_device_add(ioc
, raid_device
);
4425 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
4426 raid_device
->id
, 0);
4428 _scsih_raid_device_remove(ioc
, raid_device
);
4431 case MPI2_RAID_VOL_STATE_INITIALIZING
:
4438 * _scsih_sas_ir_physical_disk_event - PD event
4439 * @ioc: per adapter object
4440 * @event_data: event data payload
4446 _scsih_sas_ir_physical_disk_event(struct MPT2SAS_ADAPTER
*ioc
, u8 VF_ID
,
4447 Mpi2EventDataIrPhysicalDisk_t
*event_data
)
4451 struct _sas_device
*sas_device
;
4452 unsigned long flags
;
4454 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED
)
4457 handle
= le16_to_cpu(event_data
->PhysDiskDevHandle
);
4458 state
= le32_to_cpu(event_data
->NewValue
);
4460 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: handle(0x%04x), "
4461 "old(0x%08x), new(0x%08x)\n", ioc
->name
, __func__
, handle
,
4462 le32_to_cpu(event_data
->PreviousValue
), state
));
4464 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4465 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
4466 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4470 case MPI2_RAID_PD_STATE_OFFLINE
:
4472 _scsih_remove_device(ioc
, handle
);
4475 case MPI2_RAID_PD_STATE_ONLINE
:
4476 case MPI2_RAID_PD_STATE_DEGRADED
:
4477 case MPI2_RAID_PD_STATE_REBUILDING
:
4478 case MPI2_RAID_PD_STATE_OPTIMAL
:
4480 sas_device
->hidden_raid_component
= 1;
4482 _scsih_add_device(ioc
, handle
, 0, 1);
4485 case MPI2_RAID_PD_STATE_NOT_CONFIGURED
:
4486 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE
:
4487 case MPI2_RAID_PD_STATE_HOT_SPARE
:
4493 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4495 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
4496 * @ioc: per adapter object
4497 * @event_data: event data payload
4503 _scsih_sas_ir_operation_status_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
4504 Mpi2EventDataIrOperationStatus_t
*event_data
)
4506 char *reason_str
= NULL
;
4508 switch (event_data
->RAIDOperation
) {
4509 case MPI2_EVENT_IR_RAIDOP_RESYNC
:
4510 reason_str
= "resync";
4512 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION
:
4513 reason_str
= "online capacity expansion";
4515 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK
:
4516 reason_str
= "consistency check";
4519 reason_str
= "unknown reason";
4523 printk(MPT2SAS_INFO_FMT
"raid operational status: (%s)"
4524 "\thandle(0x%04x), percent complete(%d)\n",
4525 ioc
->name
, reason_str
,
4526 le16_to_cpu(event_data
->VolDevHandle
),
4527 event_data
->PercentComplete
);
4532 * _scsih_sas_ir_operation_status_event - handle RAID operation events
4533 * @ioc: per adapter object
4535 * @event_data: event data payload
4541 _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER
*ioc
, u8 VF_ID
,
4542 Mpi2EventDataIrOperationStatus_t
*event_data
)
4544 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4545 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
4546 _scsih_sas_ir_operation_status_event_debug(ioc
, event_data
);
4551 * _scsih_task_set_full - handle task set full
4552 * @ioc: per adapter object
4553 * @event_data: event data payload
4556 * Throttle back qdepth.
4559 _scsih_task_set_full(struct MPT2SAS_ADAPTER
*ioc
, u8 VF_ID
,
4560 Mpi2EventDataTaskSetFull_t
*event_data
)
4562 unsigned long flags
;
4563 struct _sas_device
*sas_device
;
4564 static struct _raid_device
*raid_device
;
4565 struct scsi_device
*sdev
;
4572 current_depth
= le16_to_cpu(event_data
->CurrentDepth
);
4573 handle
= le16_to_cpu(event_data
->DevHandle
);
4574 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4575 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
4577 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4580 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4581 id
= sas_device
->id
;
4582 channel
= sas_device
->channel
;
4583 sas_address
= sas_device
->sas_address
;
4585 /* if hidden raid component, then change to volume characteristics */
4586 if (sas_device
->hidden_raid_component
&& sas_device
->volume_handle
) {
4587 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
4588 raid_device
= _scsih_raid_device_find_by_handle(
4589 ioc
, sas_device
->volume_handle
);
4590 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
4592 id
= raid_device
->id
;
4593 channel
= raid_device
->channel
;
4594 handle
= raid_device
->handle
;
4595 sas_address
= raid_device
->wwid
;
4599 if (ioc
->logging_level
& MPT_DEBUG_TASK_SET_FULL
)
4600 starget_printk(KERN_DEBUG
, sas_device
->starget
, "task set "
4601 "full: handle(0x%04x), sas_addr(0x%016llx), depth(%d)\n",
4602 handle
, (unsigned long long)sas_address
, current_depth
);
4604 shost_for_each_device(sdev
, ioc
->shost
) {
4605 if (sdev
->id
== id
&& sdev
->channel
== channel
) {
4606 if (current_depth
> sdev
->queue_depth
) {
4607 if (ioc
->logging_level
&
4608 MPT_DEBUG_TASK_SET_FULL
)
4609 sdev_printk(KERN_INFO
, sdev
, "strange "
4610 "observation, the queue depth is"
4611 " (%d) meanwhile fw queue depth "
4612 "is (%d)\n", sdev
->queue_depth
,
4616 depth
= scsi_track_queue_full(sdev
,
4619 sdev_printk(KERN_INFO
, sdev
, "Queue depth "
4620 "reduced to (%d)\n", depth
);
4622 sdev_printk(KERN_INFO
, sdev
, "Tagged Command "
4623 "Queueing is being disabled\n");
4624 else if (depth
== 0)
4625 if (ioc
->logging_level
&
4626 MPT_DEBUG_TASK_SET_FULL
)
4627 sdev_printk(KERN_INFO
, sdev
,
4628 "Queue depth not changed yet\n");
4634 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
4635 * @ioc: per adapter object
4636 * @sas_address: sas address
4637 * @slot: enclosure slot id
4638 * @handle: device handle
4640 * After host reset, find out whether devices are still responding.
4641 * Used in _scsi_remove_unresponsive_sas_devices.
4646 _scsih_mark_responding_sas_device(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
,
4647 u16 slot
, u16 handle
)
4649 struct MPT2SAS_TARGET
*sas_target_priv_data
;
4650 struct scsi_target
*starget
;
4651 struct _sas_device
*sas_device
;
4652 unsigned long flags
;
4654 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4655 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
) {
4656 if (sas_device
->sas_address
== sas_address
&&
4657 sas_device
->slot
== slot
&& sas_device
->starget
) {
4658 sas_device
->responding
= 1;
4659 starget_printk(KERN_INFO
, sas_device
->starget
,
4660 "handle(0x%04x), sas_addr(0x%016llx), enclosure "
4661 "logical id(0x%016llx), slot(%d)\n", handle
,
4662 (unsigned long long)sas_device
->sas_address
,
4663 (unsigned long long)
4664 sas_device
->enclosure_logical_id
,
4666 if (sas_device
->handle
== handle
)
4668 printk(KERN_INFO
"\thandle changed from(0x%04x)!!!\n",
4669 sas_device
->handle
);
4670 sas_device
->handle
= handle
;
4671 starget
= sas_device
->starget
;
4672 sas_target_priv_data
= starget
->hostdata
;
4673 sas_target_priv_data
->handle
= handle
;
4678 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4682 * _scsih_search_responding_sas_devices -
4683 * @ioc: per adapter object
4685 * After host reset, find out whether devices are still responding.
4691 _scsih_search_responding_sas_devices(struct MPT2SAS_ADAPTER
*ioc
)
4693 Mpi2SasDevicePage0_t sas_device_pg0
;
4694 Mpi2ConfigReply_t mpi_reply
;
4701 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
, __func__
);
4703 if (list_empty(&ioc
->sas_device_list
))
4707 while (!(mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
4708 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
,
4710 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4711 MPI2_IOCSTATUS_MASK
;
4712 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
4714 handle
= le16_to_cpu(sas_device_pg0
.DevHandle
);
4715 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
4716 if (!(_scsih_is_end_device(device_info
)))
4718 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
4719 slot
= le16_to_cpu(sas_device_pg0
.Slot
);
4720 _scsih_mark_responding_sas_device(ioc
, sas_address
, slot
,
4726 * _scsih_mark_responding_raid_device - mark a raid_device as responding
4727 * @ioc: per adapter object
4728 * @wwid: world wide identifier for raid volume
4729 * @handle: device handle
4731 * After host reset, find out whether devices are still responding.
4732 * Used in _scsi_remove_unresponsive_raid_devices.
4737 _scsih_mark_responding_raid_device(struct MPT2SAS_ADAPTER
*ioc
, u64 wwid
,
4740 struct MPT2SAS_TARGET
*sas_target_priv_data
;
4741 struct scsi_target
*starget
;
4742 struct _raid_device
*raid_device
;
4743 unsigned long flags
;
4745 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
4746 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
4747 if (raid_device
->wwid
== wwid
&& raid_device
->starget
) {
4748 raid_device
->responding
= 1;
4749 starget_printk(KERN_INFO
, raid_device
->starget
,
4750 "handle(0x%04x), wwid(0x%016llx)\n", handle
,
4751 (unsigned long long)raid_device
->wwid
);
4752 if (raid_device
->handle
== handle
)
4754 printk(KERN_INFO
"\thandle changed from(0x%04x)!!!\n",
4755 raid_device
->handle
);
4756 raid_device
->handle
= handle
;
4757 starget
= raid_device
->starget
;
4758 sas_target_priv_data
= starget
->hostdata
;
4759 sas_target_priv_data
->handle
= handle
;
4764 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
4768 * _scsih_search_responding_raid_devices -
4769 * @ioc: per adapter object
4771 * After host reset, find out whether devices are still responding.
4777 _scsih_search_responding_raid_devices(struct MPT2SAS_ADAPTER
*ioc
)
4779 Mpi2RaidVolPage1_t volume_pg1
;
4780 Mpi2ConfigReply_t mpi_reply
;
4784 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
, __func__
);
4786 if (list_empty(&ioc
->raid_device_list
))
4790 while (!(mpt2sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
4791 &volume_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
4792 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4793 MPI2_IOCSTATUS_MASK
;
4794 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
4796 handle
= le16_to_cpu(volume_pg1
.DevHandle
);
4797 _scsih_mark_responding_raid_device(ioc
,
4798 le64_to_cpu(volume_pg1
.WWID
), handle
);
4803 * _scsih_mark_responding_expander - mark a expander as responding
4804 * @ioc: per adapter object
4805 * @sas_address: sas address
4808 * After host reset, find out whether devices are still responding.
4809 * Used in _scsi_remove_unresponsive_expanders.
4814 _scsih_mark_responding_expander(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
,
4817 struct _sas_node
*sas_expander
;
4818 unsigned long flags
;
4820 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
4821 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
4822 if (sas_expander
->sas_address
== sas_address
) {
4823 sas_expander
->responding
= 1;
4824 if (sas_expander
->handle
!= handle
) {
4825 printk(KERN_INFO
"old handle(0x%04x)\n",
4826 sas_expander
->handle
);
4827 sas_expander
->handle
= handle
;
4833 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
4837 * _scsih_search_responding_expanders -
4838 * @ioc: per adapter object
4840 * After host reset, find out whether devices are still responding.
4846 _scsih_search_responding_expanders(struct MPT2SAS_ADAPTER
*ioc
)
4848 Mpi2ExpanderPage0_t expander_pg0
;
4849 Mpi2ConfigReply_t mpi_reply
;
4854 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
, __func__
);
4856 if (list_empty(&ioc
->sas_expander_list
))
4860 while (!(mpt2sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
4861 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL
, handle
))) {
4863 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4864 MPI2_IOCSTATUS_MASK
;
4865 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
4868 handle
= le16_to_cpu(expander_pg0
.DevHandle
);
4869 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
4870 printk(KERN_INFO
"\texpander present: handle(0x%04x), "
4871 "sas_addr(0x%016llx)\n", handle
,
4872 (unsigned long long)sas_address
);
4873 _scsih_mark_responding_expander(ioc
, sas_address
, handle
);
4879 * _scsih_remove_unresponding_devices - removing unresponding devices
4880 * @ioc: per adapter object
4885 _scsih_remove_unresponding_devices(struct MPT2SAS_ADAPTER
*ioc
)
4887 struct _sas_device
*sas_device
, *sas_device_next
;
4888 struct _sas_node
*sas_expander
, *sas_expander_next
;
4889 struct _raid_device
*raid_device
, *raid_device_next
;
4890 unsigned long flags
;
4892 _scsih_search_responding_sas_devices(ioc
);
4893 _scsih_search_responding_raid_devices(ioc
);
4894 _scsih_search_responding_expanders(ioc
);
4896 spin_lock_irqsave(&ioc
->ioc_reset_in_progress_lock
, flags
);
4897 ioc
->shost_recovery
= 0;
4898 if (ioc
->shost
->shost_state
== SHOST_RECOVERY
) {
4899 printk(MPT2SAS_INFO_FMT
"putting controller into "
4900 "SHOST_RUNNING\n", ioc
->name
);
4901 scsi_host_set_state(ioc
->shost
, SHOST_RUNNING
);
4903 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
, flags
);
4905 list_for_each_entry_safe(sas_device
, sas_device_next
,
4906 &ioc
->sas_device_list
, list
) {
4907 if (sas_device
->responding
) {
4908 sas_device
->responding
= 0;
4911 if (sas_device
->starget
)
4912 starget_printk(KERN_INFO
, sas_device
->starget
,
4913 "removing: handle(0x%04x), sas_addr(0x%016llx), "
4914 "enclosure logical id(0x%016llx), slot(%d)\n",
4916 (unsigned long long)sas_device
->sas_address
,
4917 (unsigned long long)
4918 sas_device
->enclosure_logical_id
,
4920 _scsih_remove_device(ioc
, sas_device
->handle
);
4923 list_for_each_entry_safe(raid_device
, raid_device_next
,
4924 &ioc
->raid_device_list
, list
) {
4925 if (raid_device
->responding
) {
4926 raid_device
->responding
= 0;
4929 if (raid_device
->starget
) {
4930 starget_printk(KERN_INFO
, raid_device
->starget
,
4931 "removing: handle(0x%04x), wwid(0x%016llx)\n",
4932 raid_device
->handle
,
4933 (unsigned long long)raid_device
->wwid
);
4934 scsi_remove_target(&raid_device
->starget
->dev
);
4936 _scsih_raid_device_remove(ioc
, raid_device
);
4939 list_for_each_entry_safe(sas_expander
, sas_expander_next
,
4940 &ioc
->sas_expander_list
, list
) {
4941 if (sas_expander
->responding
) {
4942 sas_expander
->responding
= 0;
4945 printk("\tremoving expander: handle(0x%04x), "
4946 " sas_addr(0x%016llx)\n", sas_expander
->handle
,
4947 (unsigned long long)sas_expander
->sas_address
);
4948 _scsih_expander_remove(ioc
, sas_expander
->handle
);
4953 * _firmware_event_work - delayed task for processing firmware events
4954 * @ioc: per adapter object
4955 * @work: equal to the fw_event_work object
4961 _firmware_event_work(struct work_struct
*work
)
4963 struct fw_event_work
*fw_event
= container_of(work
,
4964 struct fw_event_work
, work
);
4965 unsigned long flags
;
4966 struct MPT2SAS_ADAPTER
*ioc
= fw_event
->ioc
;
4968 /* This is invoked by calling _scsih_queue_rescan(). */
4969 if (fw_event
->event
== MPT2SAS_RESCAN_AFTER_HOST_RESET
) {
4970 _scsih_fw_event_free(ioc
, fw_event
);
4971 _scsih_sas_host_refresh(ioc
, 1);
4972 _scsih_remove_unresponding_devices(ioc
);
4976 /* the queue is being flushed so ignore this event */
4977 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
4978 if (ioc
->fw_events_off
|| ioc
->remove_host
) {
4979 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
4980 _scsih_fw_event_free(ioc
, fw_event
);
4983 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
4985 spin_lock_irqsave(&ioc
->ioc_reset_in_progress_lock
, flags
);
4986 if (ioc
->shost_recovery
) {
4987 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
, flags
);
4988 _scsih_fw_event_requeue(ioc
, fw_event
, 1000);
4991 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
, flags
);
4993 switch (fw_event
->event
) {
4994 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
4995 _scsih_sas_topology_change_event(ioc
, fw_event
->VF_ID
,
4996 fw_event
->event_data
, fw_event
);
4998 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
4999 _scsih_sas_device_status_change_event(ioc
, fw_event
->VF_ID
,
5000 fw_event
->event_data
);
5002 case MPI2_EVENT_SAS_DISCOVERY
:
5003 _scsih_sas_discovery_event(ioc
, fw_event
->VF_ID
,
5004 fw_event
->event_data
);
5006 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
5007 _scsih_sas_broadcast_primative_event(ioc
, fw_event
->VF_ID
,
5008 fw_event
->event_data
);
5010 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
5011 _scsih_sas_enclosure_dev_status_change_event(ioc
,
5012 fw_event
->VF_ID
, fw_event
->event_data
);
5014 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
5015 _scsih_sas_ir_config_change_event(ioc
, fw_event
->VF_ID
,
5016 fw_event
->event_data
);
5018 case MPI2_EVENT_IR_VOLUME
:
5019 _scsih_sas_ir_volume_event(ioc
, fw_event
->VF_ID
,
5020 fw_event
->event_data
);
5022 case MPI2_EVENT_IR_PHYSICAL_DISK
:
5023 _scsih_sas_ir_physical_disk_event(ioc
, fw_event
->VF_ID
,
5024 fw_event
->event_data
);
5026 case MPI2_EVENT_IR_OPERATION_STATUS
:
5027 _scsih_sas_ir_operation_status_event(ioc
, fw_event
->VF_ID
,
5028 fw_event
->event_data
);
5030 case MPI2_EVENT_TASK_SET_FULL
:
5031 _scsih_task_set_full(ioc
, fw_event
->VF_ID
,
5032 fw_event
->event_data
);
5035 _scsih_fw_event_free(ioc
, fw_event
);
5039 * mpt2sas_scsih_event_callback - firmware event handler (called at ISR time)
5040 * @ioc: per adapter object
5041 * @VF_ID: virtual function id
5042 * @reply: reply message frame(lower 32bit addr)
5043 * Context: interrupt.
5045 * This function merely adds a new work task into ioc->firmware_event_thread.
5046 * The tasks are worked from _firmware_event_work in user context.
5051 mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER
*ioc
, u8 VF_ID
, u32 reply
)
5053 struct fw_event_work
*fw_event
;
5054 Mpi2EventNotificationReply_t
*mpi_reply
;
5055 unsigned long flags
;
5058 /* events turned off due to host reset or driver unloading */
5059 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
5060 if (ioc
->fw_events_off
|| ioc
->remove_host
) {
5061 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
5064 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
5066 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
5067 event
= le16_to_cpu(mpi_reply
->Event
);
5071 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
5073 Mpi2EventDataSasBroadcastPrimitive_t
*baen_data
=
5074 (Mpi2EventDataSasBroadcastPrimitive_t
*)
5075 mpi_reply
->EventData
;
5077 if (baen_data
->Primitive
!=
5078 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT
||
5079 ioc
->broadcast_aen_busy
)
5081 ioc
->broadcast_aen_busy
= 1;
5085 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
5086 _scsih_check_topo_delete_events(ioc
,
5087 (Mpi2EventDataSasTopologyChangeList_t
*)
5088 mpi_reply
->EventData
);
5091 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
5092 case MPI2_EVENT_IR_OPERATION_STATUS
:
5093 case MPI2_EVENT_SAS_DISCOVERY
:
5094 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
5095 case MPI2_EVENT_IR_VOLUME
:
5096 case MPI2_EVENT_IR_PHYSICAL_DISK
:
5097 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
5098 case MPI2_EVENT_TASK_SET_FULL
:
5101 default: /* ignore the rest */
5105 fw_event
= kzalloc(sizeof(struct fw_event_work
), GFP_ATOMIC
);
5107 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5108 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5111 fw_event
->event_data
=
5112 kzalloc(mpi_reply
->EventDataLength
*4, GFP_ATOMIC
);
5113 if (!fw_event
->event_data
) {
5114 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5115 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5120 memcpy(fw_event
->event_data
, mpi_reply
->EventData
,
5121 mpi_reply
->EventDataLength
*4);
5122 fw_event
->ioc
= ioc
;
5123 fw_event
->VF_ID
= VF_ID
;
5124 fw_event
->event
= event
;
5125 _scsih_fw_event_add(ioc
, fw_event
);
5128 /* shost template */
5129 static struct scsi_host_template scsih_driver_template
= {
5130 .module
= THIS_MODULE
,
5131 .name
= "Fusion MPT SAS Host",
5132 .proc_name
= MPT2SAS_DRIVER_NAME
,
5133 .queuecommand
= scsih_qcmd
,
5134 .target_alloc
= scsih_target_alloc
,
5135 .slave_alloc
= scsih_slave_alloc
,
5136 .slave_configure
= scsih_slave_configure
,
5137 .target_destroy
= scsih_target_destroy
,
5138 .slave_destroy
= scsih_slave_destroy
,
5139 .change_queue_depth
= scsih_change_queue_depth
,
5140 .change_queue_type
= scsih_change_queue_type
,
5141 .eh_abort_handler
= scsih_abort
,
5142 .eh_device_reset_handler
= scsih_dev_reset
,
5143 .eh_host_reset_handler
= scsih_host_reset
,
5144 .bios_param
= scsih_bios_param
,
5147 .sg_tablesize
= MPT2SAS_SG_DEPTH
,
5148 .max_sectors
= 8192,
5150 .use_clustering
= ENABLE_CLUSTERING
,
5151 .shost_attrs
= mpt2sas_host_attrs
,
5152 .sdev_attrs
= mpt2sas_dev_attrs
,
5156 * _scsih_expander_node_remove - removing expander device from list.
5157 * @ioc: per adapter object
5158 * @sas_expander: the sas_device object
5159 * Context: Calling function should acquire ioc->sas_node_lock.
5161 * Removing object and freeing associated memory from the
5162 * ioc->sas_expander_list.
5167 _scsih_expander_node_remove(struct MPT2SAS_ADAPTER
*ioc
,
5168 struct _sas_node
*sas_expander
)
5170 struct _sas_port
*mpt2sas_port
;
5171 struct _sas_device
*sas_device
;
5172 struct _sas_node
*expander_sibling
;
5173 unsigned long flags
;
5178 /* remove sibling ports attached to this expander */
5179 retry_device_search
:
5180 list_for_each_entry(mpt2sas_port
,
5181 &sas_expander
->sas_port_list
, port_list
) {
5182 if (mpt2sas_port
->remote_identify
.device_type
==
5184 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5186 mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
5187 mpt2sas_port
->remote_identify
.sas_address
);
5188 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5191 _scsih_remove_device(ioc
, sas_device
->handle
);
5192 goto retry_device_search
;
5196 retry_expander_search
:
5197 list_for_each_entry(mpt2sas_port
,
5198 &sas_expander
->sas_port_list
, port_list
) {
5200 if (mpt2sas_port
->remote_identify
.device_type
==
5201 MPI2_SAS_DEVICE_INFO_EDGE_EXPANDER
||
5202 mpt2sas_port
->remote_identify
.device_type
==
5203 MPI2_SAS_DEVICE_INFO_FANOUT_EXPANDER
) {
5205 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5207 mpt2sas_scsih_expander_find_by_sas_address(
5208 ioc
, mpt2sas_port
->remote_identify
.sas_address
);
5209 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5210 if (!expander_sibling
)
5212 _scsih_expander_remove(ioc
, expander_sibling
->handle
);
5213 goto retry_expander_search
;
5217 mpt2sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
5218 sas_expander
->parent_handle
);
5220 printk(MPT2SAS_INFO_FMT
"expander_remove: handle"
5221 "(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
5222 sas_expander
->handle
, (unsigned long long)
5223 sas_expander
->sas_address
);
5225 list_del(&sas_expander
->list
);
5226 kfree(sas_expander
->phy
);
5227 kfree(sas_expander
);
5231 * scsih_remove - detach and remove add host
5232 * @pdev: PCI device struct
5236 static void __devexit
5237 scsih_remove(struct pci_dev
*pdev
)
5239 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
5240 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
5241 struct _sas_port
*mpt2sas_port
;
5242 struct _sas_device
*sas_device
;
5243 struct _sas_node
*expander_sibling
;
5244 struct workqueue_struct
*wq
;
5245 unsigned long flags
;
5247 ioc
->remove_host
= 1;
5248 _scsih_fw_event_off(ioc
);
5250 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
5251 wq
= ioc
->firmware_event_thread
;
5252 ioc
->firmware_event_thread
= NULL
;
5253 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
5255 destroy_workqueue(wq
);
5257 /* free ports attached to the sas_host */
5259 list_for_each_entry(mpt2sas_port
,
5260 &ioc
->sas_hba
.sas_port_list
, port_list
) {
5261 if (mpt2sas_port
->remote_identify
.device_type
==
5264 mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
5265 mpt2sas_port
->remote_identify
.sas_address
);
5267 _scsih_remove_device(ioc
, sas_device
->handle
);
5272 mpt2sas_scsih_expander_find_by_sas_address(ioc
,
5273 mpt2sas_port
->remote_identify
.sas_address
);
5274 if (expander_sibling
) {
5275 _scsih_expander_remove(ioc
,
5276 expander_sibling
->handle
);
5282 /* free phys attached to the sas_host */
5283 if (ioc
->sas_hba
.num_phys
) {
5284 kfree(ioc
->sas_hba
.phy
);
5285 ioc
->sas_hba
.phy
= NULL
;
5286 ioc
->sas_hba
.num_phys
= 0;
5289 sas_remove_host(shost
);
5290 mpt2sas_base_detach(ioc
);
5291 list_del(&ioc
->list
);
5292 scsi_remove_host(shost
);
5293 scsi_host_put(shost
);
5297 * _scsih_probe_boot_devices - reports 1st device
5298 * @ioc: per adapter object
5300 * If specified in bios page 2, this routine reports the 1st
5301 * device scsi-ml or sas transport for persistent boot device
5302 * purposes. Please refer to function _scsih_determine_boot_device()
5305 _scsih_probe_boot_devices(struct MPT2SAS_ADAPTER
*ioc
)
5309 struct _sas_device
*sas_device
;
5310 struct _raid_device
*raid_device
;
5311 u16 handle
, parent_handle
;
5313 unsigned long flags
;
5317 if (ioc
->req_boot_device
.device
) {
5318 device
= ioc
->req_boot_device
.device
;
5319 is_raid
= ioc
->req_boot_device
.is_raid
;
5320 } else if (ioc
->req_alt_boot_device
.device
) {
5321 device
= ioc
->req_alt_boot_device
.device
;
5322 is_raid
= ioc
->req_alt_boot_device
.is_raid
;
5323 } else if (ioc
->current_boot_device
.device
) {
5324 device
= ioc
->current_boot_device
.device
;
5325 is_raid
= ioc
->current_boot_device
.is_raid
;
5332 raid_device
= device
;
5333 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
5334 raid_device
->id
, 0);
5336 _scsih_raid_device_remove(ioc
, raid_device
);
5338 sas_device
= device
;
5339 handle
= sas_device
->handle
;
5340 parent_handle
= sas_device
->parent_handle
;
5341 sas_address
= sas_device
->sas_address
;
5342 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5343 list_move_tail(&sas_device
->list
, &ioc
->sas_device_list
);
5344 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5345 if (!mpt2sas_transport_port_add(ioc
, sas_device
->handle
,
5346 sas_device
->parent_handle
)) {
5347 _scsih_sas_device_remove(ioc
, sas_device
);
5348 } else if (!sas_device
->starget
) {
5349 mpt2sas_transport_port_remove(ioc
, sas_address
,
5351 _scsih_sas_device_remove(ioc
, sas_device
);
5357 * _scsih_probe_raid - reporting raid volumes to scsi-ml
5358 * @ioc: per adapter object
5360 * Called during initial loading of the driver.
5363 _scsih_probe_raid(struct MPT2SAS_ADAPTER
*ioc
)
5365 struct _raid_device
*raid_device
, *raid_next
;
5368 list_for_each_entry_safe(raid_device
, raid_next
,
5369 &ioc
->raid_device_list
, list
) {
5370 if (raid_device
->starget
)
5372 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
5373 raid_device
->id
, 0);
5375 _scsih_raid_device_remove(ioc
, raid_device
);
5380 * _scsih_probe_sas - reporting raid volumes to sas transport
5381 * @ioc: per adapter object
5383 * Called during initial loading of the driver.
5386 _scsih_probe_sas(struct MPT2SAS_ADAPTER
*ioc
)
5388 struct _sas_device
*sas_device
, *next
;
5389 unsigned long flags
;
5390 u16 handle
, parent_handle
;
5393 /* SAS Device List */
5394 list_for_each_entry_safe(sas_device
, next
, &ioc
->sas_device_init_list
,
5396 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5397 list_move_tail(&sas_device
->list
, &ioc
->sas_device_list
);
5398 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5400 handle
= sas_device
->handle
;
5401 parent_handle
= sas_device
->parent_handle
;
5402 sas_address
= sas_device
->sas_address
;
5403 if (!mpt2sas_transport_port_add(ioc
, handle
, parent_handle
)) {
5404 _scsih_sas_device_remove(ioc
, sas_device
);
5405 } else if (!sas_device
->starget
) {
5406 mpt2sas_transport_port_remove(ioc
, sas_address
,
5408 _scsih_sas_device_remove(ioc
, sas_device
);
5414 * _scsih_probe_devices - probing for devices
5415 * @ioc: per adapter object
5417 * Called during initial loading of the driver.
5420 _scsih_probe_devices(struct MPT2SAS_ADAPTER
*ioc
)
5422 u16 volume_mapping_flags
=
5423 le16_to_cpu(ioc
->ioc_pg8
.IRVolumeMappingFlags
) &
5424 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE
;
5426 if (!(ioc
->facts
.ProtocolFlags
& MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR
))
5427 return; /* return when IOC doesn't support initiator mode */
5429 _scsih_probe_boot_devices(ioc
);
5431 if (ioc
->ir_firmware
) {
5432 if ((volume_mapping_flags
&
5433 MPI2_IOCPAGE8_IRFLAGS_HIGH_VOLUME_MAPPING
)) {
5434 _scsih_probe_sas(ioc
);
5435 _scsih_probe_raid(ioc
);
5437 _scsih_probe_raid(ioc
);
5438 _scsih_probe_sas(ioc
);
5441 _scsih_probe_sas(ioc
);
5445 * scsih_probe - attach and add scsi host
5446 * @pdev: PCI device struct
5447 * @id: pci device id
5449 * Returns 0 success, anything else error.
5452 scsih_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
5454 struct MPT2SAS_ADAPTER
*ioc
;
5455 struct Scsi_Host
*shost
;
5457 shost
= scsi_host_alloc(&scsih_driver_template
,
5458 sizeof(struct MPT2SAS_ADAPTER
));
5462 /* init local params */
5463 ioc
= shost_priv(shost
);
5464 memset(ioc
, 0, sizeof(struct MPT2SAS_ADAPTER
));
5465 INIT_LIST_HEAD(&ioc
->list
);
5466 list_add_tail(&ioc
->list
, &mpt2sas_ioc_list
);
5468 ioc
->id
= mpt_ids
++;
5469 sprintf(ioc
->name
, "%s%d", MPT2SAS_DRIVER_NAME
, ioc
->id
);
5471 ioc
->scsi_io_cb_idx
= scsi_io_cb_idx
;
5472 ioc
->tm_cb_idx
= tm_cb_idx
;
5473 ioc
->ctl_cb_idx
= ctl_cb_idx
;
5474 ioc
->base_cb_idx
= base_cb_idx
;
5475 ioc
->transport_cb_idx
= transport_cb_idx
;
5476 ioc
->config_cb_idx
= config_cb_idx
;
5477 ioc
->logging_level
= logging_level
;
5478 /* misc semaphores and spin locks */
5479 spin_lock_init(&ioc
->ioc_reset_in_progress_lock
);
5480 spin_lock_init(&ioc
->scsi_lookup_lock
);
5481 spin_lock_init(&ioc
->sas_device_lock
);
5482 spin_lock_init(&ioc
->sas_node_lock
);
5483 spin_lock_init(&ioc
->fw_event_lock
);
5484 spin_lock_init(&ioc
->raid_device_lock
);
5486 INIT_LIST_HEAD(&ioc
->sas_device_list
);
5487 INIT_LIST_HEAD(&ioc
->sas_device_init_list
);
5488 INIT_LIST_HEAD(&ioc
->sas_expander_list
);
5489 INIT_LIST_HEAD(&ioc
->fw_event_list
);
5490 INIT_LIST_HEAD(&ioc
->raid_device_list
);
5491 INIT_LIST_HEAD(&ioc
->sas_hba
.sas_port_list
);
5493 /* init shost parameters */
5494 shost
->max_cmd_len
= 16;
5495 shost
->max_lun
= max_lun
;
5496 shost
->transportt
= mpt2sas_transport_template
;
5497 shost
->unique_id
= ioc
->id
;
5499 if ((scsi_add_host(shost
, &pdev
->dev
))) {
5500 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5501 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5502 list_del(&ioc
->list
);
5503 goto out_add_shost_fail
;
5507 snprintf(ioc
->firmware_event_name
, sizeof(ioc
->firmware_event_name
),
5508 "fw_event%d", ioc
->id
);
5509 ioc
->firmware_event_thread
= create_singlethread_workqueue(
5510 ioc
->firmware_event_name
);
5511 if (!ioc
->firmware_event_thread
) {
5512 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5513 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5514 goto out_thread_fail
;
5517 ioc
->wait_for_port_enable_to_complete
= 1;
5518 if ((mpt2sas_base_attach(ioc
))) {
5519 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5520 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5521 goto out_attach_fail
;
5524 ioc
->wait_for_port_enable_to_complete
= 0;
5525 _scsih_probe_devices(ioc
);
5529 destroy_workqueue(ioc
->firmware_event_thread
);
5531 list_del(&ioc
->list
);
5532 scsi_remove_host(shost
);
5539 * scsih_suspend - power management suspend main entry point
5540 * @pdev: PCI device struct
5541 * @state: PM state change to (usually PCI_D3)
5543 * Returns 0 success, anything else error.
5546 scsih_suspend(struct pci_dev
*pdev
, pm_message_t state
)
5548 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
5549 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
5552 flush_scheduled_work();
5553 scsi_block_requests(shost
);
5554 device_state
= pci_choose_state(pdev
, state
);
5555 printk(MPT2SAS_INFO_FMT
"pdev=0x%p, slot=%s, entering "
5556 "operating state [D%d]\n", ioc
->name
, pdev
,
5557 pci_name(pdev
), device_state
);
5559 mpt2sas_base_free_resources(ioc
);
5560 pci_save_state(pdev
);
5561 pci_disable_device(pdev
);
5562 pci_set_power_state(pdev
, device_state
);
5567 * scsih_resume - power management resume main entry point
5568 * @pdev: PCI device struct
5570 * Returns 0 success, anything else error.
5573 scsih_resume(struct pci_dev
*pdev
)
5575 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
5576 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
5577 u32 device_state
= pdev
->current_state
;
5580 printk(MPT2SAS_INFO_FMT
"pdev=0x%p, slot=%s, previous "
5581 "operating state [D%d]\n", ioc
->name
, pdev
,
5582 pci_name(pdev
), device_state
);
5584 pci_set_power_state(pdev
, PCI_D0
);
5585 pci_enable_wake(pdev
, PCI_D0
, 0);
5586 pci_restore_state(pdev
);
5588 r
= mpt2sas_base_map_resources(ioc
);
5592 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
, SOFT_RESET
);
5593 scsi_unblock_requests(shost
);
5596 #endif /* CONFIG_PM */
5599 static struct pci_driver scsih_driver
= {
5600 .name
= MPT2SAS_DRIVER_NAME
,
5601 .id_table
= scsih_pci_table
,
5602 .probe
= scsih_probe
,
5603 .remove
= __devexit_p(scsih_remove
),
5605 .suspend
= scsih_suspend
,
5606 .resume
= scsih_resume
,
5612 * scsih_init - main entry point for this driver.
5614 * Returns 0 success, anything else error.
5622 printk(KERN_INFO
"%s version %s loaded\n", MPT2SAS_DRIVER_NAME
,
5623 MPT2SAS_DRIVER_VERSION
);
5625 mpt2sas_transport_template
=
5626 sas_attach_transport(&mpt2sas_transport_functions
);
5627 if (!mpt2sas_transport_template
)
5630 mpt2sas_base_initialize_callback_handler();
5632 /* queuecommand callback hander */
5633 scsi_io_cb_idx
= mpt2sas_base_register_callback_handler(scsih_io_done
);
5635 /* task managment callback handler */
5636 tm_cb_idx
= mpt2sas_base_register_callback_handler(scsih_tm_done
);
5638 /* base internal commands callback handler */
5639 base_cb_idx
= mpt2sas_base_register_callback_handler(mpt2sas_base_done
);
5641 /* transport internal commands callback handler */
5642 transport_cb_idx
= mpt2sas_base_register_callback_handler(
5643 mpt2sas_transport_done
);
5645 /* configuration page API internal commands callback handler */
5646 config_cb_idx
= mpt2sas_base_register_callback_handler(
5647 mpt2sas_config_done
);
5649 /* ctl module callback handler */
5650 ctl_cb_idx
= mpt2sas_base_register_callback_handler(mpt2sas_ctl_done
);
5654 error
= pci_register_driver(&scsih_driver
);
5656 sas_release_transport(mpt2sas_transport_template
);
5662 * scsih_exit - exit point for this driver (when it is a module).
5664 * Returns 0 success, anything else error.
5669 printk(KERN_INFO
"mpt2sas version %s unloading\n",
5670 MPT2SAS_DRIVER_VERSION
);
5672 pci_unregister_driver(&scsih_driver
);
5674 sas_release_transport(mpt2sas_transport_template
);
5675 mpt2sas_base_release_callback_handler(scsi_io_cb_idx
);
5676 mpt2sas_base_release_callback_handler(tm_cb_idx
);
5677 mpt2sas_base_release_callback_handler(base_cb_idx
);
5678 mpt2sas_base_release_callback_handler(transport_cb_idx
);
5679 mpt2sas_base_release_callback_handler(config_cb_idx
);
5680 mpt2sas_base_release_callback_handler(ctl_cb_idx
);
5685 module_init(scsih_init
);
5686 module_exit(scsih_exit
);