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_scsi_lookup_find_by_lun - search for matching channel:id:lun
888 * @ioc: per adapter object
892 * Context: This function will acquire ioc->scsi_lookup_lock.
894 * This will search for a matching channel:id:lun in the scsi_lookup array,
895 * returning 1 if found.
898 _scsih_scsi_lookup_find_by_lun(struct MPT2SAS_ADAPTER
*ioc
, int id
,
899 unsigned int lun
, int channel
)
905 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
907 for (i
= 0 ; i
< ioc
->request_depth
; i
++) {
908 if (ioc
->scsi_lookup
[i
].scmd
&&
909 (ioc
->scsi_lookup
[i
].scmd
->device
->id
== id
&&
910 ioc
->scsi_lookup
[i
].scmd
->device
->channel
== channel
&&
911 ioc
->scsi_lookup
[i
].scmd
->device
->lun
== lun
)) {
917 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
922 * _scsih_get_chain_buffer_dma - obtain block of chains (dma address)
923 * @ioc: per adapter object
924 * @smid: system request message index
926 * Returns phys pointer to chain buffer.
929 _scsih_get_chain_buffer_dma(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
931 return ioc
->chain_dma
+ ((smid
- 1) * (ioc
->request_sz
*
932 ioc
->chains_needed_per_io
));
936 * _scsih_get_chain_buffer - obtain block of chains assigned to a mf request
937 * @ioc: per adapter object
938 * @smid: system request message index
940 * Returns virt pointer to chain buffer.
943 _scsih_get_chain_buffer(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
945 return (void *)(ioc
->chain
+ ((smid
- 1) * (ioc
->request_sz
*
946 ioc
->chains_needed_per_io
)));
950 * _scsih_build_scatter_gather - main sg creation routine
951 * @ioc: per adapter object
952 * @scmd: scsi command
953 * @smid: system request message index
956 * The main routine that builds scatter gather table from a given
957 * scsi request sent via the .queuecommand main handler.
959 * Returns 0 success, anything else error
962 _scsih_build_scatter_gather(struct MPT2SAS_ADAPTER
*ioc
,
963 struct scsi_cmnd
*scmd
, u16 smid
)
965 Mpi2SCSIIORequest_t
*mpi_request
;
966 dma_addr_t chain_dma
;
967 struct scatterlist
*sg_scmd
;
968 void *sg_local
, *chain
;
975 u32 sgl_flags_last_element
;
976 u32 sgl_flags_end_buffer
;
978 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
980 /* init scatter gather flags */
981 sgl_flags
= MPI2_SGE_FLAGS_SIMPLE_ELEMENT
;
982 if (scmd
->sc_data_direction
== DMA_TO_DEVICE
)
983 sgl_flags
|= MPI2_SGE_FLAGS_HOST_TO_IOC
;
984 sgl_flags_last_element
= (sgl_flags
| MPI2_SGE_FLAGS_LAST_ELEMENT
)
985 << MPI2_SGE_FLAGS_SHIFT
;
986 sgl_flags_end_buffer
= (sgl_flags
| MPI2_SGE_FLAGS_LAST_ELEMENT
|
987 MPI2_SGE_FLAGS_END_OF_BUFFER
| MPI2_SGE_FLAGS_END_OF_LIST
)
988 << MPI2_SGE_FLAGS_SHIFT
;
989 sgl_flags
= sgl_flags
<< MPI2_SGE_FLAGS_SHIFT
;
991 sg_scmd
= scsi_sglist(scmd
);
992 sges_left
= scsi_dma_map(scmd
);
994 sdev_printk(KERN_ERR
, scmd
->device
, "pci_map_sg"
995 " failed: request for %d bytes!\n", scsi_bufflen(scmd
));
999 sg_local
= &mpi_request
->SGL
;
1000 sges_in_segment
= ioc
->max_sges_in_main_message
;
1001 if (sges_left
<= sges_in_segment
)
1002 goto fill_in_last_segment
;
1004 mpi_request
->ChainOffset
= (offsetof(Mpi2SCSIIORequest_t
, SGL
) +
1005 (sges_in_segment
* ioc
->sge_size
))/4;
1007 /* fill in main message segment when there is a chain following */
1008 while (sges_in_segment
) {
1009 if (sges_in_segment
== 1)
1010 ioc
->base_add_sg_single(sg_local
,
1011 sgl_flags_last_element
| sg_dma_len(sg_scmd
),
1012 sg_dma_address(sg_scmd
));
1014 ioc
->base_add_sg_single(sg_local
, sgl_flags
|
1015 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
1016 sg_scmd
= sg_next(sg_scmd
);
1017 sg_local
+= ioc
->sge_size
;
1022 /* initializing the chain flags and pointers */
1023 chain_flags
= MPI2_SGE_FLAGS_CHAIN_ELEMENT
<< MPI2_SGE_FLAGS_SHIFT
;
1024 chain
= _scsih_get_chain_buffer(ioc
, smid
);
1025 chain_dma
= _scsih_get_chain_buffer_dma(ioc
, smid
);
1027 sges_in_segment
= (sges_left
<=
1028 ioc
->max_sges_in_chain_message
) ? sges_left
:
1029 ioc
->max_sges_in_chain_message
;
1030 chain_offset
= (sges_left
== sges_in_segment
) ?
1031 0 : (sges_in_segment
* ioc
->sge_size
)/4;
1032 chain_length
= sges_in_segment
* ioc
->sge_size
;
1034 chain_offset
= chain_offset
<<
1035 MPI2_SGE_CHAIN_OFFSET_SHIFT
;
1036 chain_length
+= ioc
->sge_size
;
1038 ioc
->base_add_sg_single(sg_local
, chain_flags
| chain_offset
|
1039 chain_length
, chain_dma
);
1042 goto fill_in_last_segment
;
1044 /* fill in chain segments */
1045 while (sges_in_segment
) {
1046 if (sges_in_segment
== 1)
1047 ioc
->base_add_sg_single(sg_local
,
1048 sgl_flags_last_element
|
1049 sg_dma_len(sg_scmd
),
1050 sg_dma_address(sg_scmd
));
1052 ioc
->base_add_sg_single(sg_local
, sgl_flags
|
1053 sg_dma_len(sg_scmd
),
1054 sg_dma_address(sg_scmd
));
1055 sg_scmd
= sg_next(sg_scmd
);
1056 sg_local
+= ioc
->sge_size
;
1061 chain_dma
+= ioc
->request_sz
;
1062 chain
+= ioc
->request_sz
;
1066 fill_in_last_segment
:
1068 /* fill the last segment */
1071 ioc
->base_add_sg_single(sg_local
, sgl_flags_end_buffer
|
1072 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
1074 ioc
->base_add_sg_single(sg_local
, sgl_flags
|
1075 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
1076 sg_scmd
= sg_next(sg_scmd
);
1077 sg_local
+= ioc
->sge_size
;
1085 * _scsih_change_queue_depth - setting device queue depth
1086 * @sdev: scsi device struct
1087 * @qdepth: requested queue depth
1089 * Returns queue depth.
1092 _scsih_change_queue_depth(struct scsi_device
*sdev
, int qdepth
)
1094 struct Scsi_Host
*shost
= sdev
->host
;
1098 max_depth
= shost
->can_queue
;
1099 if (!sdev
->tagged_supported
)
1101 if (qdepth
> max_depth
)
1103 tag_type
= (qdepth
== 1) ? 0 : MSG_SIMPLE_TAG
;
1104 scsi_adjust_queue_depth(sdev
, tag_type
, qdepth
);
1106 if (sdev
->inquiry_len
> 7)
1107 sdev_printk(KERN_INFO
, sdev
, "qdepth(%d), tagged(%d), "
1108 "simple(%d), ordered(%d), scsi_level(%d), cmd_que(%d)\n",
1109 sdev
->queue_depth
, sdev
->tagged_supported
, sdev
->simple_tags
,
1110 sdev
->ordered_tags
, sdev
->scsi_level
,
1111 (sdev
->inquiry
[7] & 2) >> 1);
1113 return sdev
->queue_depth
;
1117 * _scsih_change_queue_depth - changing device queue tag type
1118 * @sdev: scsi device struct
1119 * @tag_type: requested tag type
1121 * Returns queue tag type.
1124 _scsih_change_queue_type(struct scsi_device
*sdev
, int tag_type
)
1126 if (sdev
->tagged_supported
) {
1127 scsi_set_tag_type(sdev
, tag_type
);
1129 scsi_activate_tcq(sdev
, sdev
->queue_depth
);
1131 scsi_deactivate_tcq(sdev
, sdev
->queue_depth
);
1139 * _scsih_target_alloc - target add routine
1140 * @starget: scsi target struct
1142 * Returns 0 if ok. Any other return is assumed to be an error and
1143 * the device is ignored.
1146 _scsih_target_alloc(struct scsi_target
*starget
)
1148 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
1149 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1150 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1151 struct _sas_device
*sas_device
;
1152 struct _raid_device
*raid_device
;
1153 unsigned long flags
;
1154 struct sas_rphy
*rphy
;
1156 sas_target_priv_data
= kzalloc(sizeof(struct scsi_target
), GFP_KERNEL
);
1157 if (!sas_target_priv_data
)
1160 starget
->hostdata
= sas_target_priv_data
;
1161 sas_target_priv_data
->starget
= starget
;
1162 sas_target_priv_data
->handle
= MPT2SAS_INVALID_DEVICE_HANDLE
;
1165 if (starget
->channel
== RAID_CHANNEL
) {
1166 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1167 raid_device
= _scsih_raid_device_find_by_id(ioc
, starget
->id
,
1170 sas_target_priv_data
->handle
= raid_device
->handle
;
1171 sas_target_priv_data
->sas_address
= raid_device
->wwid
;
1172 sas_target_priv_data
->flags
|= MPT_TARGET_FLAGS_VOLUME
;
1173 raid_device
->starget
= starget
;
1175 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1179 /* sas/sata devices */
1180 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1181 rphy
= dev_to_rphy(starget
->dev
.parent
);
1182 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1183 rphy
->identify
.sas_address
);
1186 sas_target_priv_data
->handle
= sas_device
->handle
;
1187 sas_target_priv_data
->sas_address
= sas_device
->sas_address
;
1188 sas_device
->starget
= starget
;
1189 sas_device
->id
= starget
->id
;
1190 sas_device
->channel
= starget
->channel
;
1191 if (sas_device
->hidden_raid_component
)
1192 sas_target_priv_data
->flags
|=
1193 MPT_TARGET_FLAGS_RAID_COMPONENT
;
1195 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1201 * _scsih_target_destroy - target destroy routine
1202 * @starget: scsi target struct
1207 _scsih_target_destroy(struct scsi_target
*starget
)
1209 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
1210 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1211 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1212 struct _sas_device
*sas_device
;
1213 struct _raid_device
*raid_device
;
1214 unsigned long flags
;
1215 struct sas_rphy
*rphy
;
1217 sas_target_priv_data
= starget
->hostdata
;
1218 if (!sas_target_priv_data
)
1221 if (starget
->channel
== RAID_CHANNEL
) {
1222 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1223 raid_device
= _scsih_raid_device_find_by_id(ioc
, starget
->id
,
1226 raid_device
->starget
= NULL
;
1227 raid_device
->sdev
= NULL
;
1229 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1233 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1234 rphy
= dev_to_rphy(starget
->dev
.parent
);
1235 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1236 rphy
->identify
.sas_address
);
1237 if (sas_device
&& (sas_device
->starget
== starget
) &&
1238 (sas_device
->id
== starget
->id
) &&
1239 (sas_device
->channel
== starget
->channel
))
1240 sas_device
->starget
= NULL
;
1242 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1245 kfree(sas_target_priv_data
);
1246 starget
->hostdata
= NULL
;
1250 * _scsih_slave_alloc - device add routine
1251 * @sdev: scsi device struct
1253 * Returns 0 if ok. Any other return is assumed to be an error and
1254 * the device is ignored.
1257 _scsih_slave_alloc(struct scsi_device
*sdev
)
1259 struct Scsi_Host
*shost
;
1260 struct MPT2SAS_ADAPTER
*ioc
;
1261 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1262 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1263 struct scsi_target
*starget
;
1264 struct _raid_device
*raid_device
;
1265 struct _sas_device
*sas_device
;
1266 unsigned long flags
;
1268 sas_device_priv_data
= kzalloc(sizeof(struct scsi_device
), GFP_KERNEL
);
1269 if (!sas_device_priv_data
)
1272 sas_device_priv_data
->lun
= sdev
->lun
;
1273 sas_device_priv_data
->flags
= MPT_DEVICE_FLAGS_INIT
;
1275 starget
= scsi_target(sdev
);
1276 sas_target_priv_data
= starget
->hostdata
;
1277 sas_target_priv_data
->num_luns
++;
1278 sas_device_priv_data
->sas_target
= sas_target_priv_data
;
1279 sdev
->hostdata
= sas_device_priv_data
;
1280 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
))
1281 sdev
->no_uld_attach
= 1;
1283 shost
= dev_to_shost(&starget
->dev
);
1284 ioc
= shost_priv(shost
);
1285 if (starget
->channel
== RAID_CHANNEL
) {
1286 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1287 raid_device
= _scsih_raid_device_find_by_id(ioc
,
1288 starget
->id
, starget
->channel
);
1290 raid_device
->sdev
= sdev
; /* raid is single lun */
1291 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1293 /* set TLR bit for SSP devices */
1294 if (!(ioc
->facts
.IOCCapabilities
&
1295 MPI2_IOCFACTS_CAPABILITY_TLR
))
1297 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1298 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1299 sas_device_priv_data
->sas_target
->sas_address
);
1300 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1301 if (sas_device
&& sas_device
->device_info
&
1302 MPI2_SAS_DEVICE_INFO_SSP_TARGET
)
1303 sas_device_priv_data
->flags
|= MPT_DEVICE_TLR_ON
;
1311 * _scsih_slave_destroy - device destroy routine
1312 * @sdev: scsi device struct
1317 _scsih_slave_destroy(struct scsi_device
*sdev
)
1319 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1320 struct scsi_target
*starget
;
1322 if (!sdev
->hostdata
)
1325 starget
= scsi_target(sdev
);
1326 sas_target_priv_data
= starget
->hostdata
;
1327 sas_target_priv_data
->num_luns
--;
1328 kfree(sdev
->hostdata
);
1329 sdev
->hostdata
= NULL
;
1333 * _scsih_display_sata_capabilities - sata capabilities
1334 * @ioc: per adapter object
1335 * @sas_device: the sas_device object
1336 * @sdev: scsi device struct
1339 _scsih_display_sata_capabilities(struct MPT2SAS_ADAPTER
*ioc
,
1340 struct _sas_device
*sas_device
, struct scsi_device
*sdev
)
1342 Mpi2ConfigReply_t mpi_reply
;
1343 Mpi2SasDevicePage0_t sas_device_pg0
;
1348 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
1349 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, sas_device
->handle
))) {
1350 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1351 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1355 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
1356 MPI2_IOCSTATUS_MASK
;
1357 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
1358 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1359 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1363 flags
= le16_to_cpu(sas_device_pg0
.Flags
);
1364 device_info
= le16_to_cpu(sas_device_pg0
.DeviceInfo
);
1366 sdev_printk(KERN_INFO
, sdev
,
1367 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1368 "sw_preserve(%s)\n",
1369 (device_info
& MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE
) ? "y" : "n",
1370 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED
) ? "y" : "n",
1371 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY
) ? "y" :
1373 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED
) ? "y" : "n",
1374 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED
) ? "y" : "n",
1375 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE
) ? "y" : "n");
1379 * _scsih_get_volume_capabilities - volume capabilities
1380 * @ioc: per adapter object
1381 * @sas_device: the raid_device object
1384 _scsih_get_volume_capabilities(struct MPT2SAS_ADAPTER
*ioc
,
1385 struct _raid_device
*raid_device
)
1387 Mpi2RaidVolPage0_t
*vol_pg0
;
1388 Mpi2RaidPhysDiskPage0_t pd_pg0
;
1389 Mpi2SasDevicePage0_t sas_device_pg0
;
1390 Mpi2ConfigReply_t mpi_reply
;
1394 if ((mpt2sas_config_get_number_pds(ioc
, raid_device
->handle
,
1395 &num_pds
)) || !num_pds
) {
1396 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1397 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1401 raid_device
->num_pds
= num_pds
;
1402 sz
= offsetof(Mpi2RaidVolPage0_t
, PhysDisk
) + (num_pds
*
1403 sizeof(Mpi2RaidVol0PhysDisk_t
));
1404 vol_pg0
= kzalloc(sz
, GFP_KERNEL
);
1406 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1407 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1411 if ((mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, vol_pg0
,
1412 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, raid_device
->handle
, sz
))) {
1413 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1414 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1419 raid_device
->volume_type
= vol_pg0
->VolumeType
;
1421 /* figure out what the underlying devices are by
1422 * obtaining the device_info bits for the 1st device
1424 if (!(mpt2sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
1425 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM
,
1426 vol_pg0
->PhysDisk
[0].PhysDiskNum
))) {
1427 if (!(mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
1428 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
1429 le16_to_cpu(pd_pg0
.DevHandle
)))) {
1430 raid_device
->device_info
=
1431 le32_to_cpu(sas_device_pg0
.DeviceInfo
);
1439 * _scsih_slave_configure - device configure routine.
1440 * @sdev: scsi device struct
1442 * Returns 0 if ok. Any other return is assumed to be an error and
1443 * the device is ignored.
1446 _scsih_slave_configure(struct scsi_device
*sdev
)
1448 struct Scsi_Host
*shost
= sdev
->host
;
1449 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1450 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1451 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1452 struct _sas_device
*sas_device
;
1453 struct _raid_device
*raid_device
;
1454 unsigned long flags
;
1461 sas_device_priv_data
= sdev
->hostdata
;
1462 sas_device_priv_data
->configured_lun
= 1;
1463 sas_device_priv_data
->flags
&= ~MPT_DEVICE_FLAGS_INIT
;
1464 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
1466 /* raid volume handling */
1467 if (sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
1469 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1470 raid_device
= _scsih_raid_device_find_by_handle(ioc
,
1471 sas_target_priv_data
->handle
);
1472 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1474 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1475 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1479 _scsih_get_volume_capabilities(ioc
, raid_device
);
1481 /* RAID Queue Depth Support
1482 * IS volume = underlying qdepth of drive type, either
1483 * MPT2SAS_SAS_QUEUE_DEPTH or MPT2SAS_SATA_QUEUE_DEPTH
1484 * IM/IME/R10 = 128 (MPT2SAS_RAID_QUEUE_DEPTH)
1486 if (raid_device
->device_info
&
1487 MPI2_SAS_DEVICE_INFO_SSP_TARGET
) {
1488 qdepth
= MPT2SAS_SAS_QUEUE_DEPTH
;
1491 qdepth
= MPT2SAS_SATA_QUEUE_DEPTH
;
1492 if (raid_device
->device_info
&
1493 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1499 switch (raid_device
->volume_type
) {
1500 case MPI2_RAID_VOL_TYPE_RAID0
:
1503 case MPI2_RAID_VOL_TYPE_RAID1E
:
1504 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
1507 case MPI2_RAID_VOL_TYPE_RAID1
:
1508 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
1511 case MPI2_RAID_VOL_TYPE_RAID10
:
1512 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
1515 case MPI2_RAID_VOL_TYPE_UNKNOWN
:
1517 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
1522 sdev_printk(KERN_INFO
, sdev
, "%s: "
1523 "handle(0x%04x), wwid(0x%016llx), pd_count(%d), type(%s)\n",
1524 r_level
, raid_device
->handle
,
1525 (unsigned long long)raid_device
->wwid
,
1526 raid_device
->num_pds
, ds
);
1527 _scsih_change_queue_depth(sdev
, qdepth
);
1531 /* non-raid handling */
1532 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1533 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1534 sas_device_priv_data
->sas_target
->sas_address
);
1535 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1537 if (sas_target_priv_data
->flags
&
1538 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
1539 mpt2sas_config_get_volume_handle(ioc
,
1540 sas_device
->handle
, &sas_device
->volume_handle
);
1541 mpt2sas_config_get_volume_wwid(ioc
,
1542 sas_device
->volume_handle
,
1543 &sas_device
->volume_wwid
);
1545 if (sas_device
->device_info
& MPI2_SAS_DEVICE_INFO_SSP_TARGET
) {
1546 qdepth
= MPT2SAS_SAS_QUEUE_DEPTH
;
1550 qdepth
= MPT2SAS_SATA_QUEUE_DEPTH
;
1551 if (sas_device
->device_info
&
1552 MPI2_SAS_DEVICE_INFO_STP_TARGET
)
1554 else if (sas_device
->device_info
&
1555 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1559 sdev_printk(KERN_INFO
, sdev
, "%s: handle(0x%04x), "
1560 "sas_addr(0x%016llx), device_name(0x%016llx)\n",
1561 ds
, sas_device
->handle
,
1562 (unsigned long long)sas_device
->sas_address
,
1563 (unsigned long long)sas_device
->device_name
);
1564 sdev_printk(KERN_INFO
, sdev
, "%s: "
1565 "enclosure_logical_id(0x%016llx), slot(%d)\n", ds
,
1566 (unsigned long long) sas_device
->enclosure_logical_id
,
1570 _scsih_display_sata_capabilities(ioc
, sas_device
, sdev
);
1573 _scsih_change_queue_depth(sdev
, qdepth
);
1576 sas_read_port_mode_page(sdev
);
1581 * _scsih_bios_param - fetch head, sector, cylinder info for a disk
1582 * @sdev: scsi device struct
1583 * @bdev: pointer to block device context
1584 * @capacity: device size (in 512 byte sectors)
1585 * @params: three element array to place output:
1586 * params[0] number of heads (max 255)
1587 * params[1] number of sectors (max 63)
1588 * params[2] number of cylinders
1593 _scsih_bios_param(struct scsi_device
*sdev
, struct block_device
*bdev
,
1594 sector_t capacity
, int params
[])
1604 dummy
= heads
* sectors
;
1605 cylinders
= capacity
;
1606 sector_div(cylinders
, dummy
);
1609 * Handle extended translation size for logical drives
1612 if ((ulong
)capacity
>= 0x200000) {
1615 dummy
= heads
* sectors
;
1616 cylinders
= capacity
;
1617 sector_div(cylinders
, dummy
);
1622 params
[1] = sectors
;
1623 params
[2] = cylinders
;
1629 * _scsih_response_code - translation of device response code
1630 * @ioc: per adapter object
1631 * @response_code: response code returned by the device
1636 _scsih_response_code(struct MPT2SAS_ADAPTER
*ioc
, u8 response_code
)
1640 switch (response_code
) {
1641 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE
:
1642 desc
= "task management request completed";
1644 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
:
1645 desc
= "invalid frame";
1647 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED
:
1648 desc
= "task management request not supported";
1650 case MPI2_SCSITASKMGMT_RSP_TM_FAILED
:
1651 desc
= "task management request failed";
1653 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
:
1654 desc
= "task management request succeeded";
1656 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN
:
1657 desc
= "invalid lun";
1660 desc
= "overlapped tag attempted";
1662 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
:
1663 desc
= "task queued, however not sent to target";
1669 printk(MPT2SAS_WARN_FMT
"response_code(0x%01x): %s\n",
1670 ioc
->name
, response_code
, desc
);
1674 * _scsih_tm_done - tm completion routine
1675 * @ioc: per adapter object
1676 * @smid: system request message index
1677 * @VF_ID: virtual function id
1678 * @reply: reply message frame(lower 32bit addr)
1681 * The callback handler when using scsih_issue_tm.
1686 _scsih_tm_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 VF_ID
, u32 reply
)
1688 MPI2DefaultReply_t
*mpi_reply
;
1690 if (ioc
->tm_cmds
.status
== MPT2_CMD_NOT_USED
)
1692 if (ioc
->tm_cmds
.smid
!= smid
)
1694 ioc
->tm_cmds
.status
|= MPT2_CMD_COMPLETE
;
1695 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
1697 memcpy(ioc
->tm_cmds
.reply
, mpi_reply
, mpi_reply
->MsgLength
*4);
1698 ioc
->tm_cmds
.status
|= MPT2_CMD_REPLY_VALID
;
1700 ioc
->tm_cmds
.status
&= ~MPT2_CMD_PENDING
;
1701 complete(&ioc
->tm_cmds
.done
);
1705 * mpt2sas_scsih_set_tm_flag - set per target tm_busy
1706 * @ioc: per adapter object
1707 * @handle: device handle
1709 * During taskmangement request, we need to freeze the device queue.
1712 mpt2sas_scsih_set_tm_flag(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
1714 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1715 struct scsi_device
*sdev
;
1718 shost_for_each_device(sdev
, ioc
->shost
) {
1721 sas_device_priv_data
= sdev
->hostdata
;
1722 if (!sas_device_priv_data
)
1724 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
1725 sas_device_priv_data
->sas_target
->tm_busy
= 1;
1727 ioc
->ignore_loginfos
= 1;
1733 * mpt2sas_scsih_clear_tm_flag - clear per target tm_busy
1734 * @ioc: per adapter object
1735 * @handle: device handle
1737 * During taskmangement request, we need to freeze the device queue.
1740 mpt2sas_scsih_clear_tm_flag(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
1742 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1743 struct scsi_device
*sdev
;
1746 shost_for_each_device(sdev
, ioc
->shost
) {
1749 sas_device_priv_data
= sdev
->hostdata
;
1750 if (!sas_device_priv_data
)
1752 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
1753 sas_device_priv_data
->sas_target
->tm_busy
= 0;
1755 ioc
->ignore_loginfos
= 0;
1761 * mpt2sas_scsih_issue_tm - main routine for sending tm requests
1762 * @ioc: per adapter struct
1763 * @device_handle: device handle
1765 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
1766 * @smid_task: smid assigned to the task
1767 * @timeout: timeout in seconds
1768 * Context: The calling function needs to acquire the tm_cmds.mutex
1770 * A generic API for sending task management requests to firmware.
1772 * The ioc->tm_cmds.status flag should be MPT2_CMD_NOT_USED before calling
1775 * The callback index is set inside `ioc->tm_cb_idx`.
1780 mpt2sas_scsih_issue_tm(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
, uint lun
,
1781 u8 type
, u16 smid_task
, ulong timeout
)
1783 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
1784 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
1787 unsigned long timeleft
;
1789 unsigned long flags
;
1791 spin_lock_irqsave(&ioc
->ioc_reset_in_progress_lock
, flags
);
1792 if (ioc
->tm_cmds
.status
!= MPT2_CMD_NOT_USED
||
1793 ioc
->shost_recovery
) {
1794 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
, flags
);
1795 printk(MPT2SAS_INFO_FMT
"%s: host reset in progress!\n",
1796 __func__
, ioc
->name
);
1799 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
, flags
);
1801 ioc_state
= mpt2sas_base_get_iocstate(ioc
, 0);
1802 if (ioc_state
& MPI2_DOORBELL_USED
) {
1803 dhsprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"unexpected doorbell "
1804 "active!\n", ioc
->name
));
1805 goto issue_host_reset
;
1808 if ((ioc_state
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_FAULT
) {
1809 mpt2sas_base_fault_info(ioc
, ioc_state
&
1810 MPI2_DOORBELL_DATA_MASK
);
1811 goto issue_host_reset
;
1814 smid
= mpt2sas_base_get_smid(ioc
, ioc
->tm_cb_idx
);
1816 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
1817 ioc
->name
, __func__
);
1821 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"sending tm: handle(0x%04x),"
1822 " task_type(0x%02x), smid(%d)\n", ioc
->name
, handle
, type
, smid
));
1823 ioc
->tm_cmds
.status
= MPT2_CMD_PENDING
;
1824 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
1825 ioc
->tm_cmds
.smid
= smid
;
1826 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
1827 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
1828 mpi_request
->DevHandle
= cpu_to_le16(handle
);
1829 mpi_request
->TaskType
= type
;
1830 mpi_request
->TaskMID
= cpu_to_le16(smid_task
);
1831 int_to_scsilun(lun
, (struct scsi_lun
*)mpi_request
->LUN
);
1832 mpt2sas_scsih_set_tm_flag(ioc
, handle
);
1833 mpt2sas_base_put_smid_hi_priority(ioc
, smid
, VF_ID
);
1834 timeleft
= wait_for_completion_timeout(&ioc
->tm_cmds
.done
, timeout
*HZ
);
1835 mpt2sas_scsih_clear_tm_flag(ioc
, handle
);
1836 if (!(ioc
->tm_cmds
.status
& MPT2_CMD_COMPLETE
)) {
1837 printk(MPT2SAS_ERR_FMT
"%s: timeout\n",
1838 ioc
->name
, __func__
);
1839 _debug_dump_mf(mpi_request
,
1840 sizeof(Mpi2SCSITaskManagementRequest_t
)/4);
1841 if (!(ioc
->tm_cmds
.status
& MPT2_CMD_RESET
))
1842 goto issue_host_reset
;
1845 if (ioc
->tm_cmds
.status
& MPT2_CMD_REPLY_VALID
) {
1846 mpi_reply
= ioc
->tm_cmds
.reply
;
1847 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"complete tm: "
1848 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
1849 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
1850 le32_to_cpu(mpi_reply
->IOCLogInfo
),
1851 le32_to_cpu(mpi_reply
->TerminationCount
)));
1852 if (ioc
->logging_level
& MPT_DEBUG_TM
)
1853 _scsih_response_code(ioc
, mpi_reply
->ResponseCode
);
1857 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
, FORCE_BIG_HAMMER
);
1861 * _scsih_abort - eh threads main abort routine
1862 * @sdev: scsi device struct
1864 * Returns SUCCESS if command aborted else FAILED
1867 _scsih_abort(struct scsi_cmnd
*scmd
)
1869 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
1870 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1874 struct scsi_cmnd
*scmd_lookup
;
1876 printk(MPT2SAS_INFO_FMT
"attempting task abort! scmd(%p)\n",
1878 scsi_print_command(scmd
);
1880 sas_device_priv_data
= scmd
->device
->hostdata
;
1881 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
1882 printk(MPT2SAS_INFO_FMT
"device been deleted! scmd(%p)\n",
1884 scmd
->result
= DID_NO_CONNECT
<< 16;
1885 scmd
->scsi_done(scmd
);
1890 /* search for the command */
1891 smid
= _scsih_scsi_lookup_find_by_scmd(ioc
, scmd
);
1893 scmd
->result
= DID_RESET
<< 16;
1898 /* for hidden raid components and volumes this is not supported */
1899 if (sas_device_priv_data
->sas_target
->flags
&
1900 MPT_TARGET_FLAGS_RAID_COMPONENT
||
1901 sas_device_priv_data
->sas_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
1902 scmd
->result
= DID_RESET
<< 16;
1907 mutex_lock(&ioc
->tm_cmds
.mutex
);
1908 handle
= sas_device_priv_data
->sas_target
->handle
;
1909 mpt2sas_scsih_issue_tm(ioc
, handle
, sas_device_priv_data
->lun
,
1910 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
, smid
, 30);
1912 /* sanity check - see whether command actually completed */
1913 scmd_lookup
= _scsih_scsi_lookup_get(ioc
, smid
);
1914 if (scmd_lookup
&& (scmd_lookup
->serial_number
== scmd
->serial_number
))
1918 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
1919 mutex_unlock(&ioc
->tm_cmds
.mutex
);
1922 printk(MPT2SAS_INFO_FMT
"task abort: %s scmd(%p)\n",
1923 ioc
->name
, ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
1928 * _scsih_dev_reset - eh threads main device reset routine
1929 * @sdev: scsi device struct
1931 * Returns SUCCESS if command aborted else FAILED
1934 _scsih_dev_reset(struct scsi_cmnd
*scmd
)
1936 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
1937 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1938 struct _sas_device
*sas_device
;
1939 unsigned long flags
;
1943 printk(MPT2SAS_INFO_FMT
"attempting device reset! scmd(%p)\n",
1945 scsi_print_command(scmd
);
1947 sas_device_priv_data
= scmd
->device
->hostdata
;
1948 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
1949 printk(MPT2SAS_INFO_FMT
"device been deleted! scmd(%p)\n",
1951 scmd
->result
= DID_NO_CONNECT
<< 16;
1952 scmd
->scsi_done(scmd
);
1957 /* for hidden raid components obtain the volume_handle */
1959 if (sas_device_priv_data
->sas_target
->flags
&
1960 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
1961 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1962 sas_device
= _scsih_sas_device_find_by_handle(ioc
,
1963 sas_device_priv_data
->sas_target
->handle
);
1965 handle
= sas_device
->volume_handle
;
1966 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1968 handle
= sas_device_priv_data
->sas_target
->handle
;
1971 scmd
->result
= DID_RESET
<< 16;
1976 mutex_lock(&ioc
->tm_cmds
.mutex
);
1977 mpt2sas_scsih_issue_tm(ioc
, handle
, 0,
1978 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET
, scmd
->device
->lun
,
1982 * sanity check see whether all commands to this device been
1985 if (_scsih_scsi_lookup_find_by_lun(ioc
, scmd
->device
->id
,
1986 scmd
->device
->lun
, scmd
->device
->channel
))
1990 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
1991 mutex_unlock(&ioc
->tm_cmds
.mutex
);
1994 printk(MPT2SAS_INFO_FMT
"device reset: %s scmd(%p)\n",
1995 ioc
->name
, ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2000 * _scsih_target_reset - eh threads main target reset routine
2001 * @sdev: scsi device struct
2003 * Returns SUCCESS if command aborted else FAILED
2006 _scsih_target_reset(struct scsi_cmnd
*scmd
)
2008 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2009 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2010 struct _sas_device
*sas_device
;
2011 unsigned long flags
;
2015 printk(MPT2SAS_INFO_FMT
"attempting target reset! scmd(%p)\n",
2017 scsi_print_command(scmd
);
2019 sas_device_priv_data
= scmd
->device
->hostdata
;
2020 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2021 printk(MPT2SAS_INFO_FMT
"target been deleted! scmd(%p)\n",
2023 scmd
->result
= DID_NO_CONNECT
<< 16;
2024 scmd
->scsi_done(scmd
);
2029 /* for hidden raid components obtain the volume_handle */
2031 if (sas_device_priv_data
->sas_target
->flags
&
2032 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2033 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2034 sas_device
= _scsih_sas_device_find_by_handle(ioc
,
2035 sas_device_priv_data
->sas_target
->handle
);
2037 handle
= sas_device
->volume_handle
;
2038 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2040 handle
= sas_device_priv_data
->sas_target
->handle
;
2043 scmd
->result
= DID_RESET
<< 16;
2048 mutex_lock(&ioc
->tm_cmds
.mutex
);
2049 mpt2sas_scsih_issue_tm(ioc
, handle
, 0,
2050 MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
, 0, 30);
2053 * sanity check see whether all commands to this target been
2056 if (_scsih_scsi_lookup_find_by_target(ioc
, scmd
->device
->id
,
2057 scmd
->device
->channel
))
2061 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
2062 mutex_unlock(&ioc
->tm_cmds
.mutex
);
2065 printk(MPT2SAS_INFO_FMT
"target reset: %s scmd(%p)\n",
2066 ioc
->name
, ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2071 * _scsih_abort - eh threads main host reset routine
2072 * @sdev: scsi device struct
2074 * Returns SUCCESS if command aborted else FAILED
2077 _scsih_host_reset(struct scsi_cmnd
*scmd
)
2079 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2082 printk(MPT2SAS_INFO_FMT
"attempting host reset! scmd(%p)\n",
2084 scsi_print_command(scmd
);
2086 retval
= mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2088 r
= (retval
< 0) ? FAILED
: SUCCESS
;
2089 printk(MPT2SAS_INFO_FMT
"host reset: %s scmd(%p)\n",
2090 ioc
->name
, ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2096 * _scsih_fw_event_add - insert and queue up fw_event
2097 * @ioc: per adapter object
2098 * @fw_event: object describing the event
2099 * Context: This function will acquire ioc->fw_event_lock.
2101 * This adds the firmware event object into link list, then queues it up to
2102 * be processed from user context.
2107 _scsih_fw_event_add(struct MPT2SAS_ADAPTER
*ioc
, struct fw_event_work
*fw_event
)
2109 unsigned long flags
;
2111 if (ioc
->firmware_event_thread
== NULL
)
2114 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2115 list_add_tail(&fw_event
->list
, &ioc
->fw_event_list
);
2116 INIT_WORK(&fw_event
->work
, _firmware_event_work
);
2117 queue_work(ioc
->firmware_event_thread
, &fw_event
->work
);
2118 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2122 * _scsih_fw_event_free - delete fw_event
2123 * @ioc: per adapter object
2124 * @fw_event: object describing the event
2125 * Context: This function will acquire ioc->fw_event_lock.
2127 * This removes firmware event object from link list, frees associated memory.
2132 _scsih_fw_event_free(struct MPT2SAS_ADAPTER
*ioc
, struct fw_event_work
2135 unsigned long flags
;
2137 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2138 list_del(&fw_event
->list
);
2139 kfree(fw_event
->event_data
);
2141 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2145 * _scsih_fw_event_add - requeue an event
2146 * @ioc: per adapter object
2147 * @fw_event: object describing the event
2148 * Context: This function will acquire ioc->fw_event_lock.
2153 _scsih_fw_event_requeue(struct MPT2SAS_ADAPTER
*ioc
, struct fw_event_work
2154 *fw_event
, unsigned long delay
)
2156 unsigned long flags
;
2157 if (ioc
->firmware_event_thread
== NULL
)
2160 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2161 queue_work(ioc
->firmware_event_thread
, &fw_event
->work
);
2162 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2166 * _scsih_fw_event_off - turn flag off preventing event handling
2167 * @ioc: per adapter object
2169 * Used to prevent handling of firmware events during adapter reset
2175 _scsih_fw_event_off(struct MPT2SAS_ADAPTER
*ioc
)
2177 unsigned long flags
;
2179 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2180 ioc
->fw_events_off
= 1;
2181 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2186 * _scsih_fw_event_on - turn flag on allowing firmware event handling
2187 * @ioc: per adapter object
2192 _scsih_fw_event_on(struct MPT2SAS_ADAPTER
*ioc
)
2194 unsigned long flags
;
2196 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2197 ioc
->fw_events_off
= 0;
2198 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2202 * _scsih_ublock_io_device - set the device state to SDEV_RUNNING
2203 * @ioc: per adapter object
2204 * @handle: device handle
2206 * During device pull we need to appropiately set the sdev state.
2209 _scsih_ublock_io_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
2211 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2212 struct scsi_device
*sdev
;
2214 shost_for_each_device(sdev
, ioc
->shost
) {
2215 sas_device_priv_data
= sdev
->hostdata
;
2216 if (!sas_device_priv_data
)
2218 if (!sas_device_priv_data
->block
)
2220 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2221 dewtprintk(ioc
, sdev_printk(KERN_INFO
, sdev
,
2222 MPT2SAS_INFO_FMT
"SDEV_RUNNING: "
2223 "handle(0x%04x)\n", ioc
->name
, handle
));
2224 sas_device_priv_data
->block
= 0;
2225 scsi_device_set_state(sdev
, SDEV_RUNNING
);
2231 * _scsih_block_io_device - set the device state to SDEV_BLOCK
2232 * @ioc: per adapter object
2233 * @handle: device handle
2235 * During device pull we need to appropiately set the sdev state.
2238 _scsih_block_io_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
2240 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2241 struct scsi_device
*sdev
;
2243 shost_for_each_device(sdev
, ioc
->shost
) {
2244 sas_device_priv_data
= sdev
->hostdata
;
2245 if (!sas_device_priv_data
)
2247 if (sas_device_priv_data
->block
)
2249 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2250 dewtprintk(ioc
, sdev_printk(KERN_INFO
, sdev
,
2251 MPT2SAS_INFO_FMT
"SDEV_BLOCK: "
2252 "handle(0x%04x)\n", ioc
->name
, handle
));
2253 sas_device_priv_data
->block
= 1;
2254 scsi_device_set_state(sdev
, SDEV_BLOCK
);
2260 * _scsih_block_io_to_children_attached_to_ex
2261 * @ioc: per adapter object
2262 * @sas_expander: the sas_device object
2264 * This routine set sdev state to SDEV_BLOCK for all devices
2265 * attached to this expander. This function called when expander is
2269 _scsih_block_io_to_children_attached_to_ex(struct MPT2SAS_ADAPTER
*ioc
,
2270 struct _sas_node
*sas_expander
)
2272 struct _sas_port
*mpt2sas_port
;
2273 struct _sas_device
*sas_device
;
2274 struct _sas_node
*expander_sibling
;
2275 unsigned long flags
;
2280 list_for_each_entry(mpt2sas_port
,
2281 &sas_expander
->sas_port_list
, port_list
) {
2282 if (mpt2sas_port
->remote_identify
.device_type
==
2284 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2286 mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
2287 mpt2sas_port
->remote_identify
.sas_address
);
2288 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2291 _scsih_block_io_device(ioc
, sas_device
->handle
);
2295 list_for_each_entry(mpt2sas_port
,
2296 &sas_expander
->sas_port_list
, port_list
) {
2298 if (mpt2sas_port
->remote_identify
.device_type
==
2299 MPI2_SAS_DEVICE_INFO_EDGE_EXPANDER
||
2300 mpt2sas_port
->remote_identify
.device_type
==
2301 MPI2_SAS_DEVICE_INFO_FANOUT_EXPANDER
) {
2303 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
2305 mpt2sas_scsih_expander_find_by_sas_address(
2306 ioc
, mpt2sas_port
->remote_identify
.sas_address
);
2307 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
2308 _scsih_block_io_to_children_attached_to_ex(ioc
,
2315 * _scsih_block_io_to_children_attached_directly
2316 * @ioc: per adapter object
2317 * @event_data: topology change event data
2319 * This routine set sdev state to SDEV_BLOCK for all devices
2320 * direct attached during device pull.
2323 _scsih_block_io_to_children_attached_directly(struct MPT2SAS_ADAPTER
*ioc
,
2324 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
2331 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
2332 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
2335 phy_number
= event_data
->StartPhyNum
+ i
;
2336 reason_code
= event_data
->PHY
[i
].PhyStatus
&
2337 MPI2_EVENT_SAS_TOPO_RC_MASK
;
2338 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
)
2339 _scsih_block_io_device(ioc
, handle
);
2344 * _scsih_check_topo_delete_events - sanity check on topo events
2345 * @ioc: per adapter object
2346 * @event_data: the event data payload
2348 * This routine added to better handle cable breaker.
2350 * This handles the case where driver recieves multiple expander
2351 * add and delete events in a single shot. When there is a delete event
2352 * the routine will void any pending add events waiting in the event queue.
2357 _scsih_check_topo_delete_events(struct MPT2SAS_ADAPTER
*ioc
,
2358 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
2360 struct fw_event_work
*fw_event
;
2361 Mpi2EventDataSasTopologyChangeList_t
*local_event_data
;
2362 u16 expander_handle
;
2363 struct _sas_node
*sas_expander
;
2364 unsigned long flags
;
2366 expander_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
2367 if (expander_handle
< ioc
->sas_hba
.num_phys
) {
2368 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
2372 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
2373 || event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
) {
2374 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
2375 sas_expander
= mpt2sas_scsih_expander_find_by_handle(ioc
,
2377 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
2378 _scsih_block_io_to_children_attached_to_ex(ioc
, sas_expander
);
2379 } else if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_RESPONDING
)
2380 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
2382 if (event_data
->ExpStatus
!= MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
)
2385 /* mark ignore flag for pending events */
2386 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2387 list_for_each_entry(fw_event
, &ioc
->fw_event_list
, list
) {
2388 if (fw_event
->event
!= MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
||
2391 local_event_data
= fw_event
->event_data
;
2392 if (local_event_data
->ExpStatus
==
2393 MPI2_EVENT_SAS_TOPO_ES_ADDED
||
2394 local_event_data
->ExpStatus
==
2395 MPI2_EVENT_SAS_TOPO_ES_RESPONDING
) {
2396 if (le16_to_cpu(local_event_data
->ExpanderDevHandle
) ==
2398 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
2399 "setting ignoring flag\n", ioc
->name
));
2400 fw_event
->ignore
= 1;
2404 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2408 * _scsih_queue_rescan - queue a topology rescan from user context
2409 * @ioc: per adapter object
2414 _scsih_queue_rescan(struct MPT2SAS_ADAPTER
*ioc
)
2416 struct fw_event_work
*fw_event
;
2418 if (ioc
->wait_for_port_enable_to_complete
)
2420 fw_event
= kzalloc(sizeof(struct fw_event_work
), GFP_ATOMIC
);
2423 fw_event
->event
= MPT2SAS_RESCAN_AFTER_HOST_RESET
;
2424 fw_event
->ioc
= ioc
;
2425 _scsih_fw_event_add(ioc
, fw_event
);
2429 * _scsih_flush_running_cmds - completing outstanding commands.
2430 * @ioc: per adapter object
2432 * The flushing out of all pending scmd commands following host reset,
2433 * where all IO is dropped to the floor.
2438 _scsih_flush_running_cmds(struct MPT2SAS_ADAPTER
*ioc
)
2440 struct scsi_cmnd
*scmd
;
2444 for (smid
= 1; smid
<= ioc
->request_depth
; smid
++) {
2445 scmd
= _scsih_scsi_lookup_getclear(ioc
, smid
);
2449 mpt2sas_base_free_smid(ioc
, smid
);
2450 scsi_dma_unmap(scmd
);
2451 scmd
->result
= DID_RESET
<< 16;
2452 scmd
->scsi_done(scmd
);
2454 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"completing %d cmds\n",
2459 * mpt2sas_scsih_reset_handler - reset callback handler (for scsih)
2460 * @ioc: per adapter object
2461 * @reset_phase: phase
2463 * The handler for doing any required cleanup or initialization.
2465 * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
2466 * MPT2_IOC_DONE_RESET
2471 mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER
*ioc
, int reset_phase
)
2473 switch (reset_phase
) {
2474 case MPT2_IOC_PRE_RESET
:
2475 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: "
2476 "MPT2_IOC_PRE_RESET\n", ioc
->name
, __func__
));
2477 _scsih_fw_event_off(ioc
);
2479 case MPT2_IOC_AFTER_RESET
:
2480 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: "
2481 "MPT2_IOC_AFTER_RESET\n", ioc
->name
, __func__
));
2482 if (ioc
->tm_cmds
.status
& MPT2_CMD_PENDING
) {
2483 ioc
->tm_cmds
.status
|= MPT2_CMD_RESET
;
2484 mpt2sas_base_free_smid(ioc
, ioc
->tm_cmds
.smid
);
2485 complete(&ioc
->tm_cmds
.done
);
2487 _scsih_fw_event_on(ioc
);
2488 _scsih_flush_running_cmds(ioc
);
2490 case MPT2_IOC_DONE_RESET
:
2491 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: "
2492 "MPT2_IOC_DONE_RESET\n", ioc
->name
, __func__
));
2493 _scsih_queue_rescan(ioc
);
2499 * _scsih_setup_eedp - setup MPI request for EEDP transfer
2500 * @scmd: pointer to scsi command object
2501 * @mpi_request: pointer to the SCSI_IO reqest message frame
2503 * Supporting protection 1 and 3.
2508 _scsih_setup_eedp(struct scsi_cmnd
*scmd
, Mpi2SCSIIORequest_t
*mpi_request
)
2511 unsigned char prot_op
= scsi_get_prot_op(scmd
);
2512 unsigned char prot_type
= scsi_get_prot_type(scmd
);
2514 if (prot_type
== SCSI_PROT_DIF_TYPE0
||
2515 prot_type
== SCSI_PROT_DIF_TYPE2
||
2516 prot_op
== SCSI_PROT_NORMAL
)
2519 if (prot_op
== SCSI_PROT_READ_STRIP
)
2520 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP
;
2521 else if (prot_op
== SCSI_PROT_WRITE_INSERT
)
2522 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_INSERT_OP
;
2526 mpi_request
->EEDPBlockSize
= scmd
->device
->sector_size
;
2528 switch (prot_type
) {
2529 case SCSI_PROT_DIF_TYPE1
:
2532 * enable ref/guard checking
2533 * auto increment ref tag
2535 mpi_request
->EEDPFlags
= eedp_flags
|
2536 MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG
|
2537 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG
|
2538 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
2539 mpi_request
->CDB
.EEDP32
.PrimaryReferenceTag
=
2540 cpu_to_be32(scsi_get_lba(scmd
));
2544 case SCSI_PROT_DIF_TYPE3
:
2547 * enable guard checking
2549 mpi_request
->EEDPFlags
= eedp_flags
|
2550 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
2557 * _scsih_eedp_error_handling - return sense code for EEDP errors
2558 * @scmd: pointer to scsi command object
2559 * @ioc_status: ioc status
2564 _scsih_eedp_error_handling(struct scsi_cmnd
*scmd
, u16 ioc_status
)
2570 switch (ioc_status
) {
2571 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
2574 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
2577 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
2585 if (scmd
->sc_data_direction
== DMA_TO_DEVICE
) {
2586 sk
= ILLEGAL_REQUEST
;
2587 host_byte
= DID_ABORT
;
2589 sk
= ABORTED_COMMAND
;
2593 scsi_build_sense_buffer(0, scmd
->sense_buffer
, sk
, 0x10, ascq
);
2594 scmd
->result
= DRIVER_SENSE
<< 24 | (host_byte
<< 16) |
2595 SAM_STAT_CHECK_CONDITION
;
2599 * _scsih_qcmd - main scsi request entry point
2600 * @scmd: pointer to scsi command object
2601 * @done: function pointer to be invoked on completion
2603 * The callback index is set inside `ioc->scsi_io_cb_idx`.
2605 * Returns 0 on success. If there's a failure, return either:
2606 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
2607 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
2610 _scsih_qcmd(struct scsi_cmnd
*scmd
, void (*done
)(struct scsi_cmnd
*))
2612 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2613 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2614 struct MPT2SAS_TARGET
*sas_target_priv_data
;
2615 Mpi2SCSIIORequest_t
*mpi_request
;
2618 unsigned long flags
;
2620 scmd
->scsi_done
= done
;
2621 sas_device_priv_data
= scmd
->device
->hostdata
;
2622 if (!sas_device_priv_data
) {
2623 scmd
->result
= DID_NO_CONNECT
<< 16;
2624 scmd
->scsi_done(scmd
);
2628 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
2629 if (!sas_target_priv_data
|| sas_target_priv_data
->handle
==
2630 MPT2SAS_INVALID_DEVICE_HANDLE
|| sas_target_priv_data
->deleted
) {
2631 scmd
->result
= DID_NO_CONNECT
<< 16;
2632 scmd
->scsi_done(scmd
);
2636 /* see if we are busy with task managment stuff */
2637 spin_lock_irqsave(&ioc
->ioc_reset_in_progress_lock
, flags
);
2638 if (sas_target_priv_data
->tm_busy
||
2639 ioc
->shost_recovery
|| ioc
->ioc_link_reset_in_progress
) {
2640 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
, flags
);
2641 return SCSI_MLQUEUE_HOST_BUSY
;
2643 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
, flags
);
2645 if (scmd
->sc_data_direction
== DMA_FROM_DEVICE
)
2646 mpi_control
= MPI2_SCSIIO_CONTROL_READ
;
2647 else if (scmd
->sc_data_direction
== DMA_TO_DEVICE
)
2648 mpi_control
= MPI2_SCSIIO_CONTROL_WRITE
;
2650 mpi_control
= MPI2_SCSIIO_CONTROL_NODATATRANSFER
;
2653 if (!(sas_device_priv_data
->flags
& MPT_DEVICE_FLAGS_INIT
)) {
2654 if (scmd
->device
->tagged_supported
) {
2655 if (scmd
->device
->ordered_tags
)
2656 mpi_control
|= MPI2_SCSIIO_CONTROL_ORDEREDQ
;
2658 mpi_control
|= MPI2_SCSIIO_CONTROL_SIMPLEQ
;
2660 /* MPI Revision I (UNIT = 0xA) - removed MPI2_SCSIIO_CONTROL_UNTAGGED */
2661 /* mpi_control |= MPI2_SCSIIO_CONTROL_UNTAGGED;
2663 mpi_control
|= (0x500);
2666 mpi_control
|= MPI2_SCSIIO_CONTROL_SIMPLEQ
;
2668 if ((sas_device_priv_data
->flags
& MPT_DEVICE_TLR_ON
))
2669 mpi_control
|= MPI2_SCSIIO_CONTROL_TLR_ON
;
2671 smid
= mpt2sas_base_get_smid(ioc
, ioc
->scsi_io_cb_idx
);
2673 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
2674 ioc
->name
, __func__
);
2677 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
2678 memset(mpi_request
, 0, sizeof(Mpi2SCSIIORequest_t
));
2679 _scsih_setup_eedp(scmd
, mpi_request
);
2680 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
2681 if (sas_device_priv_data
->sas_target
->flags
&
2682 MPT_TARGET_FLAGS_RAID_COMPONENT
)
2683 mpi_request
->Function
= MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
;
2685 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
2686 mpi_request
->DevHandle
=
2687 cpu_to_le16(sas_device_priv_data
->sas_target
->handle
);
2688 mpi_request
->DataLength
= cpu_to_le32(scsi_bufflen(scmd
));
2689 mpi_request
->Control
= cpu_to_le32(mpi_control
);
2690 mpi_request
->IoFlags
= cpu_to_le16(scmd
->cmd_len
);
2691 mpi_request
->MsgFlags
= MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR
;
2692 mpi_request
->SenseBufferLength
= SCSI_SENSE_BUFFERSIZE
;
2693 mpi_request
->SenseBufferLowAddress
=
2694 (u32
)mpt2sas_base_get_sense_buffer_dma(ioc
, smid
);
2695 mpi_request
->SGLOffset0
= offsetof(Mpi2SCSIIORequest_t
, SGL
) / 4;
2696 mpi_request
->SGLFlags
= cpu_to_le16(MPI2_SCSIIO_SGLFLAGS_TYPE_MPI
+
2697 MPI2_SCSIIO_SGLFLAGS_SYSTEM_ADDR
);
2699 int_to_scsilun(sas_device_priv_data
->lun
, (struct scsi_lun
*)
2701 memcpy(mpi_request
->CDB
.CDB32
, scmd
->cmnd
, scmd
->cmd_len
);
2703 if (!mpi_request
->DataLength
) {
2704 mpt2sas_base_build_zero_len_sge(ioc
, &mpi_request
->SGL
);
2706 if (_scsih_build_scatter_gather(ioc
, scmd
, smid
)) {
2707 mpt2sas_base_free_smid(ioc
, smid
);
2712 _scsih_scsi_lookup_set(ioc
, smid
, scmd
);
2713 mpt2sas_base_put_smid_scsi_io(ioc
, smid
, 0,
2714 sas_device_priv_data
->sas_target
->handle
);
2718 return SCSI_MLQUEUE_HOST_BUSY
;
2722 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
2723 * @sense_buffer: sense data returned by target
2724 * @data: normalized skey/asc/ascq
2729 _scsih_normalize_sense(char *sense_buffer
, struct sense_info
*data
)
2731 if ((sense_buffer
[0] & 0x7F) >= 0x72) {
2732 /* descriptor format */
2733 data
->skey
= sense_buffer
[1] & 0x0F;
2734 data
->asc
= sense_buffer
[2];
2735 data
->ascq
= sense_buffer
[3];
2738 data
->skey
= sense_buffer
[2] & 0x0F;
2739 data
->asc
= sense_buffer
[12];
2740 data
->ascq
= sense_buffer
[13];
2744 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
2746 * _scsih_scsi_ioc_info - translated non-succesfull SCSI_IO request
2747 * @ioc: per adapter object
2748 * @scmd: pointer to scsi command object
2749 * @mpi_reply: reply mf payload returned from firmware
2751 * scsi_status - SCSI Status code returned from target device
2752 * scsi_state - state info associated with SCSI_IO determined by ioc
2753 * ioc_status - ioc supplied status info
2758 _scsih_scsi_ioc_info(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
,
2759 Mpi2SCSIIOReply_t
*mpi_reply
, u16 smid
)
2763 u16 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) &
2764 MPI2_IOCSTATUS_MASK
;
2765 u8 scsi_state
= mpi_reply
->SCSIState
;
2766 u8 scsi_status
= mpi_reply
->SCSIStatus
;
2767 char *desc_ioc_state
= NULL
;
2768 char *desc_scsi_status
= NULL
;
2769 char *desc_scsi_state
= ioc
->tmp_string
;
2770 u32 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
2772 if (log_info
== 0x31170000)
2775 switch (ioc_status
) {
2776 case MPI2_IOCSTATUS_SUCCESS
:
2777 desc_ioc_state
= "success";
2779 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
2780 desc_ioc_state
= "invalid function";
2782 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
2783 desc_ioc_state
= "scsi recovered error";
2785 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE
:
2786 desc_ioc_state
= "scsi invalid dev handle";
2788 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
2789 desc_ioc_state
= "scsi device not there";
2791 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
2792 desc_ioc_state
= "scsi data overrun";
2794 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
2795 desc_ioc_state
= "scsi data underrun";
2797 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
2798 desc_ioc_state
= "scsi io data error";
2800 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
2801 desc_ioc_state
= "scsi protocol error";
2803 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
2804 desc_ioc_state
= "scsi task terminated";
2806 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
2807 desc_ioc_state
= "scsi residual mismatch";
2809 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
2810 desc_ioc_state
= "scsi task mgmt failed";
2812 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
2813 desc_ioc_state
= "scsi ioc terminated";
2815 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
2816 desc_ioc_state
= "scsi ext terminated";
2818 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
2819 desc_ioc_state
= "eedp guard error";
2821 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
2822 desc_ioc_state
= "eedp ref tag error";
2824 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
2825 desc_ioc_state
= "eedp app tag error";
2828 desc_ioc_state
= "unknown";
2832 switch (scsi_status
) {
2833 case MPI2_SCSI_STATUS_GOOD
:
2834 desc_scsi_status
= "good";
2836 case MPI2_SCSI_STATUS_CHECK_CONDITION
:
2837 desc_scsi_status
= "check condition";
2839 case MPI2_SCSI_STATUS_CONDITION_MET
:
2840 desc_scsi_status
= "condition met";
2842 case MPI2_SCSI_STATUS_BUSY
:
2843 desc_scsi_status
= "busy";
2845 case MPI2_SCSI_STATUS_INTERMEDIATE
:
2846 desc_scsi_status
= "intermediate";
2848 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET
:
2849 desc_scsi_status
= "intermediate condmet";
2851 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT
:
2852 desc_scsi_status
= "reservation conflict";
2854 case MPI2_SCSI_STATUS_COMMAND_TERMINATED
:
2855 desc_scsi_status
= "command terminated";
2857 case MPI2_SCSI_STATUS_TASK_SET_FULL
:
2858 desc_scsi_status
= "task set full";
2860 case MPI2_SCSI_STATUS_ACA_ACTIVE
:
2861 desc_scsi_status
= "aca active";
2863 case MPI2_SCSI_STATUS_TASK_ABORTED
:
2864 desc_scsi_status
= "task aborted";
2867 desc_scsi_status
= "unknown";
2871 desc_scsi_state
[0] = '\0';
2873 desc_scsi_state
= " ";
2874 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
2875 strcat(desc_scsi_state
, "response info ");
2876 if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
2877 strcat(desc_scsi_state
, "state terminated ");
2878 if (scsi_state
& MPI2_SCSI_STATE_NO_SCSI_STATUS
)
2879 strcat(desc_scsi_state
, "no status ");
2880 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_FAILED
)
2881 strcat(desc_scsi_state
, "autosense failed ");
2882 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
)
2883 strcat(desc_scsi_state
, "autosense valid ");
2885 scsi_print_command(scmd
);
2886 printk(MPT2SAS_WARN_FMT
"\tdev handle(0x%04x), "
2887 "ioc_status(%s)(0x%04x), smid(%d)\n", ioc
->name
,
2888 le16_to_cpu(mpi_reply
->DevHandle
), desc_ioc_state
,
2890 printk(MPT2SAS_WARN_FMT
"\trequest_len(%d), underflow(%d), "
2891 "resid(%d)\n", ioc
->name
, scsi_bufflen(scmd
), scmd
->underflow
,
2892 scsi_get_resid(scmd
));
2893 printk(MPT2SAS_WARN_FMT
"\ttag(%d), transfer_count(%d), "
2894 "sc->result(0x%08x)\n", ioc
->name
, le16_to_cpu(mpi_reply
->TaskTag
),
2895 le32_to_cpu(mpi_reply
->TransferCount
), scmd
->result
);
2896 printk(MPT2SAS_WARN_FMT
"\tscsi_status(%s)(0x%02x), "
2897 "scsi_state(%s)(0x%02x)\n", ioc
->name
, desc_scsi_status
,
2898 scsi_status
, desc_scsi_state
, scsi_state
);
2900 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
2901 struct sense_info data
;
2902 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
2903 printk(MPT2SAS_WARN_FMT
"\t[sense_key,asc,ascq]: "
2904 "[0x%02x,0x%02x,0x%02x]\n", ioc
->name
, data
.skey
,
2905 data
.asc
, data
.ascq
);
2908 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
) {
2909 response_info
= le32_to_cpu(mpi_reply
->ResponseInfo
);
2910 response_bytes
= (u8
*)&response_info
;
2911 _scsih_response_code(ioc
, response_bytes
[3]);
2917 * _scsih_smart_predicted_fault - illuminate Fault LED
2918 * @ioc: per adapter object
2919 * @handle: device handle
2924 _scsih_smart_predicted_fault(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
2926 Mpi2SepReply_t mpi_reply
;
2927 Mpi2SepRequest_t mpi_request
;
2928 struct scsi_target
*starget
;
2929 struct MPT2SAS_TARGET
*sas_target_priv_data
;
2930 Mpi2EventNotificationReply_t
*event_reply
;
2931 Mpi2EventDataSasDeviceStatusChange_t
*event_data
;
2932 struct _sas_device
*sas_device
;
2934 unsigned long flags
;
2936 /* only handle non-raid devices */
2937 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2938 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
2940 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2943 starget
= sas_device
->starget
;
2944 sas_target_priv_data
= starget
->hostdata
;
2946 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
) ||
2947 ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
))) {
2948 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2951 starget_printk(KERN_WARNING
, starget
, "predicted fault\n");
2952 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2954 if (ioc
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_IBM
) {
2955 memset(&mpi_request
, 0, sizeof(Mpi2SepRequest_t
));
2956 mpi_request
.Function
= MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR
;
2957 mpi_request
.Action
= MPI2_SEP_REQ_ACTION_WRITE_STATUS
;
2958 mpi_request
.SlotStatus
=
2959 MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT
;
2960 mpi_request
.DevHandle
= cpu_to_le16(handle
);
2961 mpi_request
.Flags
= MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS
;
2962 if ((mpt2sas_base_scsi_enclosure_processor(ioc
, &mpi_reply
,
2963 &mpi_request
)) != 0) {
2964 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
2965 ioc
->name
, __FILE__
, __LINE__
, __func__
);
2969 if (mpi_reply
.IOCStatus
|| mpi_reply
.IOCLogInfo
) {
2970 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
2971 "enclosure_processor: ioc_status (0x%04x), "
2972 "loginfo(0x%08x)\n", ioc
->name
,
2973 le16_to_cpu(mpi_reply
.IOCStatus
),
2974 le32_to_cpu(mpi_reply
.IOCLogInfo
)));
2979 /* insert into event log */
2980 sz
= offsetof(Mpi2EventNotificationReply_t
, EventData
) +
2981 sizeof(Mpi2EventDataSasDeviceStatusChange_t
);
2982 event_reply
= kzalloc(sz
, GFP_KERNEL
);
2984 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
2985 ioc
->name
, __FILE__
, __LINE__
, __func__
);
2989 event_reply
->Function
= MPI2_FUNCTION_EVENT_NOTIFICATION
;
2990 event_reply
->Event
=
2991 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
);
2992 event_reply
->MsgLength
= sz
/4;
2993 event_reply
->EventDataLength
=
2994 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t
)/4);
2995 event_data
= (Mpi2EventDataSasDeviceStatusChange_t
*)
2996 event_reply
->EventData
;
2997 event_data
->ReasonCode
= MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
;
2998 event_data
->ASC
= 0x5D;
2999 event_data
->DevHandle
= cpu_to_le16(handle
);
3000 event_data
->SASAddress
= cpu_to_le64(sas_target_priv_data
->sas_address
);
3001 mpt2sas_ctl_add_to_event_log(ioc
, event_reply
);
3006 * _scsih_io_done - scsi request callback
3007 * @ioc: per adapter object
3008 * @smid: system request message index
3009 * @VF_ID: virtual function id
3010 * @reply: reply message frame(lower 32bit addr)
3012 * Callback handler when using scsih_qcmd.
3017 _scsih_io_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 VF_ID
, u32 reply
)
3019 Mpi2SCSIIORequest_t
*mpi_request
;
3020 Mpi2SCSIIOReply_t
*mpi_reply
;
3021 struct scsi_cmnd
*scmd
;
3027 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
3030 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
3031 scmd
= _scsih_scsi_lookup_getclear(ioc
, smid
);
3035 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3037 if (mpi_reply
== NULL
) {
3038 scmd
->result
= DID_OK
<< 16;
3042 sas_device_priv_data
= scmd
->device
->hostdata
;
3043 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
||
3044 sas_device_priv_data
->sas_target
->deleted
) {
3045 scmd
->result
= DID_NO_CONNECT
<< 16;
3049 /* turning off TLR */
3050 if (!sas_device_priv_data
->tlr_snoop_check
) {
3051 sas_device_priv_data
->tlr_snoop_check
++;
3052 if (sas_device_priv_data
->flags
& MPT_DEVICE_TLR_ON
) {
3053 response_code
= (le32_to_cpu(mpi_reply
->ResponseInfo
)
3055 if (response_code
==
3056 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
)
3057 sas_device_priv_data
->flags
&=
3062 xfer_cnt
= le32_to_cpu(mpi_reply
->TransferCount
);
3063 scsi_set_resid(scmd
, scsi_bufflen(scmd
) - xfer_cnt
);
3064 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
);
3065 if (ioc_status
& MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE
)
3066 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
3069 ioc_status
&= MPI2_IOCSTATUS_MASK
;
3070 scsi_state
= mpi_reply
->SCSIState
;
3071 scsi_status
= mpi_reply
->SCSIStatus
;
3073 if (ioc_status
== MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
&& xfer_cnt
== 0 &&
3074 (scsi_status
== MPI2_SCSI_STATUS_BUSY
||
3075 scsi_status
== MPI2_SCSI_STATUS_RESERVATION_CONFLICT
||
3076 scsi_status
== MPI2_SCSI_STATUS_TASK_SET_FULL
)) {
3077 ioc_status
= MPI2_IOCSTATUS_SUCCESS
;
3080 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
3081 struct sense_info data
;
3082 const void *sense_data
= mpt2sas_base_get_sense_buffer(ioc
,
3084 u32 sz
= min_t(u32
, SCSI_SENSE_BUFFERSIZE
,
3085 le32_to_cpu(mpi_reply
->SenseCount
));
3086 memcpy(scmd
->sense_buffer
, sense_data
, sz
);
3087 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
3088 /* failure prediction threshold exceeded */
3089 if (data
.asc
== 0x5D)
3090 _scsih_smart_predicted_fault(ioc
,
3091 le16_to_cpu(mpi_reply
->DevHandle
));
3094 switch (ioc_status
) {
3095 case MPI2_IOCSTATUS_BUSY
:
3096 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES
:
3097 scmd
->result
= SAM_STAT_BUSY
;
3100 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
3101 scmd
->result
= DID_NO_CONNECT
<< 16;
3104 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
3105 if (sas_device_priv_data
->block
) {
3106 scmd
->result
= (DID_BUS_BUSY
<< 16);
3110 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
3111 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
3112 scmd
->result
= DID_RESET
<< 16;
3115 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
3116 if ((xfer_cnt
== 0) || (scmd
->underflow
> xfer_cnt
))
3117 scmd
->result
= DID_SOFT_ERROR
<< 16;
3119 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
3122 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
3123 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
3125 if ((scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
))
3128 if (xfer_cnt
< scmd
->underflow
) {
3129 if (scsi_status
== SAM_STAT_BUSY
)
3130 scmd
->result
= SAM_STAT_BUSY
;
3132 scmd
->result
= DID_SOFT_ERROR
<< 16;
3133 } else if (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
3134 MPI2_SCSI_STATE_NO_SCSI_STATUS
))
3135 scmd
->result
= DID_SOFT_ERROR
<< 16;
3136 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
3137 scmd
->result
= DID_RESET
<< 16;
3138 else if (!xfer_cnt
&& scmd
->cmnd
[0] == REPORT_LUNS
) {
3139 mpi_reply
->SCSIState
= MPI2_SCSI_STATE_AUTOSENSE_VALID
;
3140 mpi_reply
->SCSIStatus
= SAM_STAT_CHECK_CONDITION
;
3141 scmd
->result
= (DRIVER_SENSE
<< 24) |
3142 SAM_STAT_CHECK_CONDITION
;
3143 scmd
->sense_buffer
[0] = 0x70;
3144 scmd
->sense_buffer
[2] = ILLEGAL_REQUEST
;
3145 scmd
->sense_buffer
[12] = 0x20;
3146 scmd
->sense_buffer
[13] = 0;
3150 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
3151 scsi_set_resid(scmd
, 0);
3152 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
3153 case MPI2_IOCSTATUS_SUCCESS
:
3154 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
3155 if (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
3156 MPI2_SCSI_STATE_NO_SCSI_STATUS
))
3157 scmd
->result
= DID_SOFT_ERROR
<< 16;
3158 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
3159 scmd
->result
= DID_RESET
<< 16;
3162 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
3163 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
3164 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
3165 _scsih_eedp_error_handling(scmd
, ioc_status
);
3167 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
3168 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
3169 case MPI2_IOCSTATUS_INVALID_SGL
:
3170 case MPI2_IOCSTATUS_INTERNAL_ERROR
:
3171 case MPI2_IOCSTATUS_INVALID_FIELD
:
3172 case MPI2_IOCSTATUS_INVALID_STATE
:
3173 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
3174 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
3176 scmd
->result
= DID_SOFT_ERROR
<< 16;
3181 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3182 if (scmd
->result
&& (ioc
->logging_level
& MPT_DEBUG_REPLY
))
3183 _scsih_scsi_ioc_info(ioc
, scmd
, mpi_reply
, smid
);
3187 scsi_dma_unmap(scmd
);
3188 scmd
->scsi_done(scmd
);
3192 * _scsih_link_change - process phy link changes
3193 * @ioc: per adapter object
3194 * @handle: phy handle
3195 * @attached_handle: valid for devices attached to link
3196 * @phy_number: phy number
3197 * @link_rate: new link rate
3203 _scsih_link_change(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
, u16 attached_handle
,
3204 u8 phy_number
, u8 link_rate
)
3206 mpt2sas_transport_update_phy_link_change(ioc
, handle
, attached_handle
,
3207 phy_number
, link_rate
);
3211 * _scsih_sas_host_refresh - refreshing sas host object contents
3212 * @ioc: per adapter object
3213 * @update: update link information
3216 * During port enable, fw will send topology events for every device. Its
3217 * possible that the handles may change from the previous setting, so this
3218 * code keeping handles updating if changed.
3223 _scsih_sas_host_refresh(struct MPT2SAS_ADAPTER
*ioc
, u8 update
)
3228 Mpi2ConfigReply_t mpi_reply
;
3229 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
3231 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
3232 "updating handles for sas_host(0x%016llx)\n",
3233 ioc
->name
, (unsigned long long)ioc
->sas_hba
.sas_address
));
3235 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
3236 * sizeof(Mpi2SasIOUnit0PhyData_t
));
3237 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
3238 if (!sas_iounit_pg0
) {
3239 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3240 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3243 if (!(mpt2sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
3244 sas_iounit_pg0
, sz
))) {
3245 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
3246 MPI2_IOCSTATUS_MASK
;
3247 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
3249 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
3250 ioc
->sas_hba
.phy
[i
].handle
=
3251 le16_to_cpu(sas_iounit_pg0
->PhyData
[i
].
3252 ControllerDevHandle
);
3254 _scsih_link_change(ioc
,
3255 ioc
->sas_hba
.phy
[i
].handle
,
3256 le16_to_cpu(sas_iounit_pg0
->PhyData
[i
].
3257 AttachedDevHandle
), i
,
3258 sas_iounit_pg0
->PhyData
[i
].
3259 NegotiatedLinkRate
>> 4);
3264 kfree(sas_iounit_pg0
);
3268 * _scsih_sas_host_add - create sas host object
3269 * @ioc: per adapter object
3271 * Creating host side data object, stored in ioc->sas_hba
3276 _scsih_sas_host_add(struct MPT2SAS_ADAPTER
*ioc
)
3279 Mpi2ConfigReply_t mpi_reply
;
3280 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
3281 Mpi2SasIOUnitPage1_t
*sas_iounit_pg1
= NULL
;
3282 Mpi2SasPhyPage0_t phy_pg0
;
3283 Mpi2SasDevicePage0_t sas_device_pg0
;
3284 Mpi2SasEnclosurePage0_t enclosure_pg0
;
3287 u16 device_missing_delay
;
3289 mpt2sas_config_get_number_hba_phys(ioc
, &ioc
->sas_hba
.num_phys
);
3290 if (!ioc
->sas_hba
.num_phys
) {
3291 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3292 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3296 /* sas_iounit page 0 */
3297 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
3298 sizeof(Mpi2SasIOUnit0PhyData_t
));
3299 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
3300 if (!sas_iounit_pg0
) {
3301 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3302 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3305 if ((mpt2sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
3306 sas_iounit_pg0
, sz
))) {
3307 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3308 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3311 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
3312 MPI2_IOCSTATUS_MASK
;
3313 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
3314 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3315 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3319 /* sas_iounit page 1 */
3320 sz
= offsetof(Mpi2SasIOUnitPage1_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
3321 sizeof(Mpi2SasIOUnit1PhyData_t
));
3322 sas_iounit_pg1
= kzalloc(sz
, GFP_KERNEL
);
3323 if (!sas_iounit_pg1
) {
3324 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3325 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3328 if ((mpt2sas_config_get_sas_iounit_pg1(ioc
, &mpi_reply
,
3329 sas_iounit_pg1
, sz
))) {
3330 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3331 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3334 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
3335 MPI2_IOCSTATUS_MASK
;
3336 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
3337 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3338 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3342 ioc
->io_missing_delay
=
3343 le16_to_cpu(sas_iounit_pg1
->IODeviceMissingDelay
);
3344 device_missing_delay
=
3345 le16_to_cpu(sas_iounit_pg1
->ReportDeviceMissingDelay
);
3346 if (device_missing_delay
& MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16
)
3347 ioc
->device_missing_delay
= (device_missing_delay
&
3348 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
) * 16;
3350 ioc
->device_missing_delay
= device_missing_delay
&
3351 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
;
3353 ioc
->sas_hba
.parent_dev
= &ioc
->shost
->shost_gendev
;
3354 ioc
->sas_hba
.phy
= kcalloc(ioc
->sas_hba
.num_phys
,
3355 sizeof(struct _sas_phy
), GFP_KERNEL
);
3356 if (!ioc
->sas_hba
.phy
) {
3357 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3358 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3361 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
3362 if ((mpt2sas_config_get_phy_pg0(ioc
, &mpi_reply
, &phy_pg0
,
3364 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3365 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3368 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
3369 MPI2_IOCSTATUS_MASK
;
3370 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
3371 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3372 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3375 ioc
->sas_hba
.phy
[i
].handle
=
3376 le16_to_cpu(sas_iounit_pg0
->PhyData
[i
].ControllerDevHandle
);
3377 ioc
->sas_hba
.phy
[i
].phy_id
= i
;
3378 mpt2sas_transport_add_host_phy(ioc
, &ioc
->sas_hba
.phy
[i
],
3379 phy_pg0
, ioc
->sas_hba
.parent_dev
);
3381 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
3382 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, ioc
->sas_hba
.phy
[0].handle
))) {
3383 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3384 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3387 ioc
->sas_hba
.handle
= le16_to_cpu(sas_device_pg0
.DevHandle
);
3388 ioc
->sas_hba
.enclosure_handle
=
3389 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
3390 ioc
->sas_hba
.sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
3391 printk(MPT2SAS_INFO_FMT
"host_add: handle(0x%04x), "
3392 "sas_addr(0x%016llx), phys(%d)\n", ioc
->name
, ioc
->sas_hba
.handle
,
3393 (unsigned long long) ioc
->sas_hba
.sas_address
,
3394 ioc
->sas_hba
.num_phys
) ;
3396 if (ioc
->sas_hba
.enclosure_handle
) {
3397 if (!(mpt2sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
3399 MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
3400 ioc
->sas_hba
.enclosure_handle
))) {
3401 ioc
->sas_hba
.enclosure_logical_id
=
3402 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
3407 kfree(sas_iounit_pg1
);
3408 kfree(sas_iounit_pg0
);
3412 * _scsih_expander_add - creating expander object
3413 * @ioc: per adapter object
3414 * @handle: expander handle
3416 * Creating expander object, stored in ioc->sas_expander_list.
3418 * Return 0 for success, else error.
3421 _scsih_expander_add(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
3423 struct _sas_node
*sas_expander
;
3424 Mpi2ConfigReply_t mpi_reply
;
3425 Mpi2ExpanderPage0_t expander_pg0
;
3426 Mpi2ExpanderPage1_t expander_pg1
;
3427 Mpi2SasEnclosurePage0_t enclosure_pg0
;
3432 unsigned long flags
;
3433 struct _sas_port
*mpt2sas_port
= NULL
;
3439 if ((mpt2sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
3440 MPI2_SAS_EXPAND_PGAD_FORM_HNDL
, handle
))) {
3441 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3442 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3446 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
3447 MPI2_IOCSTATUS_MASK
;
3448 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
3449 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3450 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3454 /* handle out of order topology events */
3455 parent_handle
= le16_to_cpu(expander_pg0
.ParentDevHandle
);
3456 if (parent_handle
>= ioc
->sas_hba
.num_phys
) {
3457 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
3458 sas_expander
= mpt2sas_scsih_expander_find_by_handle(ioc
,
3460 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
3461 if (!sas_expander
) {
3462 rc
= _scsih_expander_add(ioc
, parent_handle
);
3468 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
3470 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
3471 sas_expander
= mpt2sas_scsih_expander_find_by_sas_address(ioc
,
3473 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
3478 sas_expander
= kzalloc(sizeof(struct _sas_node
),
3480 if (!sas_expander
) {
3481 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3482 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3486 sas_expander
->handle
= handle
;
3487 sas_expander
->num_phys
= expander_pg0
.NumPhys
;
3488 sas_expander
->parent_handle
= parent_handle
;
3489 sas_expander
->enclosure_handle
=
3490 le16_to_cpu(expander_pg0
.EnclosureHandle
);
3491 sas_expander
->sas_address
= sas_address
;
3493 printk(MPT2SAS_INFO_FMT
"expander_add: handle(0x%04x),"
3494 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc
->name
,
3495 handle
, sas_expander
->parent_handle
, (unsigned long long)
3496 sas_expander
->sas_address
, sas_expander
->num_phys
);
3498 if (!sas_expander
->num_phys
)
3500 sas_expander
->phy
= kcalloc(sas_expander
->num_phys
,
3501 sizeof(struct _sas_phy
), GFP_KERNEL
);
3502 if (!sas_expander
->phy
) {
3503 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3504 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3509 INIT_LIST_HEAD(&sas_expander
->sas_port_list
);
3510 mpt2sas_port
= mpt2sas_transport_port_add(ioc
, handle
,
3511 sas_expander
->parent_handle
);
3512 if (!mpt2sas_port
) {
3513 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3514 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3518 sas_expander
->parent_dev
= &mpt2sas_port
->rphy
->dev
;
3520 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++) {
3521 if ((mpt2sas_config_get_expander_pg1(ioc
, &mpi_reply
,
3522 &expander_pg1
, i
, handle
))) {
3523 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3524 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3528 sas_expander
->phy
[i
].handle
= handle
;
3529 sas_expander
->phy
[i
].phy_id
= i
;
3531 if ((mpt2sas_transport_add_expander_phy(ioc
,
3532 &sas_expander
->phy
[i
], expander_pg1
,
3533 sas_expander
->parent_dev
))) {
3534 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3535 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3541 if (sas_expander
->enclosure_handle
) {
3542 if (!(mpt2sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
3543 &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
3544 sas_expander
->enclosure_handle
))) {
3545 sas_expander
->enclosure_logical_id
=
3546 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
3550 _scsih_expander_node_add(ioc
, sas_expander
);
3556 mpt2sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
3557 sas_expander
->parent_handle
);
3558 kfree(sas_expander
);
3563 * _scsih_expander_remove - removing expander object
3564 * @ioc: per adapter object
3565 * @handle: expander handle
3570 _scsih_expander_remove(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
3572 struct _sas_node
*sas_expander
;
3573 unsigned long flags
;
3575 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
3576 sas_expander
= mpt2sas_scsih_expander_find_by_handle(ioc
, handle
);
3577 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
3578 _scsih_expander_node_remove(ioc
, sas_expander
);
3582 * _scsih_add_device - creating sas device object
3583 * @ioc: per adapter object
3584 * @handle: sas device handle
3585 * @phy_num: phy number end device attached to
3586 * @is_pd: is this hidden raid component
3588 * Creating end device object, stored in ioc->sas_device_list.
3590 * Returns 0 for success, non-zero for failure.
3593 _scsih_add_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
, u8 phy_num
, u8 is_pd
)
3595 Mpi2ConfigReply_t mpi_reply
;
3596 Mpi2SasDevicePage0_t sas_device_pg0
;
3597 Mpi2SasEnclosurePage0_t enclosure_pg0
;
3598 struct _sas_device
*sas_device
;
3602 unsigned long flags
;
3604 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
3605 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
3606 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3607 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3611 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
3612 MPI2_IOCSTATUS_MASK
;
3613 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
3614 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3615 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3619 /* check if device is present */
3620 if (!(le16_to_cpu(sas_device_pg0
.Flags
) &
3621 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT
)) {
3622 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3623 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3624 printk(MPT2SAS_ERR_FMT
"Flags = 0x%04x\n",
3625 ioc
->name
, le16_to_cpu(sas_device_pg0
.Flags
));
3629 /* check if there were any issus with discovery */
3630 if (sas_device_pg0
.AccessStatus
==
3631 MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED
) {
3632 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3633 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3634 printk(MPT2SAS_ERR_FMT
"AccessStatus = 0x%02x\n",
3635 ioc
->name
, sas_device_pg0
.AccessStatus
);
3639 /* check if this is end device */
3640 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
3641 if (!(_scsih_is_end_device(device_info
))) {
3642 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3643 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3647 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
3649 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
3650 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
3652 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3655 _scsih_ublock_io_device(ioc
, handle
);
3659 sas_device
= kzalloc(sizeof(struct _sas_device
),
3662 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3663 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3667 sas_device
->handle
= handle
;
3668 sas_device
->parent_handle
=
3669 le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
3670 sas_device
->enclosure_handle
=
3671 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
3673 le16_to_cpu(sas_device_pg0
.Slot
);
3674 sas_device
->device_info
= device_info
;
3675 sas_device
->sas_address
= sas_address
;
3676 sas_device
->hidden_raid_component
= is_pd
;
3678 /* get enclosure_logical_id */
3679 if (sas_device
->enclosure_handle
&& !(mpt2sas_config_get_enclosure_pg0(
3680 ioc
, &mpi_reply
, &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
3681 sas_device
->enclosure_handle
)))
3682 sas_device
->enclosure_logical_id
=
3683 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
3685 /* get device name */
3686 sas_device
->device_name
= le64_to_cpu(sas_device_pg0
.DeviceName
);
3688 if (ioc
->wait_for_port_enable_to_complete
)
3689 _scsih_sas_device_init_add(ioc
, sas_device
);
3691 _scsih_sas_device_add(ioc
, sas_device
);
3697 * _scsih_remove_device - removing sas device object
3698 * @ioc: per adapter object
3699 * @handle: sas device handle
3704 _scsih_remove_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
3706 struct MPT2SAS_TARGET
*sas_target_priv_data
;
3707 struct _sas_device
*sas_device
;
3708 unsigned long flags
;
3709 Mpi2SasIoUnitControlReply_t mpi_reply
;
3710 Mpi2SasIoUnitControlRequest_t mpi_request
;
3713 /* lookup sas_device */
3714 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
3715 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
3717 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3721 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: enter: handle"
3722 "(0x%04x)\n", ioc
->name
, __func__
, handle
));
3724 if (sas_device
->starget
&& sas_device
->starget
->hostdata
) {
3725 sas_target_priv_data
= sas_device
->starget
->hostdata
;
3726 sas_target_priv_data
->deleted
= 1;
3728 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3730 if (ioc
->remove_host
)
3733 /* Target Reset to flush out all the outstanding IO */
3734 device_handle
= (sas_device
->hidden_raid_component
) ?
3735 sas_device
->volume_handle
: handle
;
3736 if (device_handle
) {
3737 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"issue target reset: "
3738 "handle(0x%04x)\n", ioc
->name
, device_handle
));
3739 mutex_lock(&ioc
->tm_cmds
.mutex
);
3740 mpt2sas_scsih_issue_tm(ioc
, device_handle
, 0,
3741 MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
, 0, 10);
3742 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
3743 mutex_unlock(&ioc
->tm_cmds
.mutex
);
3744 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"issue target reset "
3745 "done: handle(0x%04x)\n", ioc
->name
, device_handle
));
3748 /* SAS_IO_UNIT_CNTR - send REMOVE_DEVICE */
3749 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"sas_iounit: handle"
3750 "(0x%04x)\n", ioc
->name
, handle
));
3751 memset(&mpi_request
, 0, sizeof(Mpi2SasIoUnitControlRequest_t
));
3752 mpi_request
.Function
= MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
;
3753 mpi_request
.Operation
= MPI2_SAS_OP_REMOVE_DEVICE
;
3754 mpi_request
.DevHandle
= handle
;
3755 mpi_request
.VF_ID
= 0;
3756 if ((mpt2sas_base_sas_iounit_control(ioc
, &mpi_reply
,
3757 &mpi_request
)) != 0) {
3758 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
3759 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3762 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"sas_iounit: ioc_status"
3763 "(0x%04x), loginfo(0x%08x)\n", ioc
->name
,
3764 le16_to_cpu(mpi_reply
.IOCStatus
),
3765 le32_to_cpu(mpi_reply
.IOCLogInfo
)));
3768 mpt2sas_transport_port_remove(ioc
, sas_device
->sas_address
,
3769 sas_device
->parent_handle
);
3771 printk(MPT2SAS_INFO_FMT
"removing handle(0x%04x), sas_addr"
3772 "(0x%016llx)\n", ioc
->name
, sas_device
->handle
,
3773 (unsigned long long) sas_device
->sas_address
);
3774 _scsih_sas_device_remove(ioc
, sas_device
);
3776 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: exit: handle"
3777 "(0x%04x)\n", ioc
->name
, __func__
, handle
));
3780 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3782 * _scsih_sas_topology_change_event_debug - debug for topology event
3783 * @ioc: per adapter object
3784 * @event_data: event data payload
3788 _scsih_sas_topology_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
3789 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
3795 char *status_str
= NULL
;
3798 switch (event_data
->ExpStatus
) {
3799 case MPI2_EVENT_SAS_TOPO_ES_ADDED
:
3802 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
:
3803 status_str
= "remove";
3805 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING
:
3806 status_str
= "responding";
3808 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
:
3809 status_str
= "remove delay";
3812 status_str
= "unknown status";
3815 printk(MPT2SAS_DEBUG_FMT
"sas topology change: (%s)\n",
3816 ioc
->name
, status_str
);
3817 printk(KERN_DEBUG
"\thandle(0x%04x), enclosure_handle(0x%04x) "
3818 "start_phy(%02d), count(%d)\n",
3819 le16_to_cpu(event_data
->ExpanderDevHandle
),
3820 le16_to_cpu(event_data
->EnclosureHandle
),
3821 event_data
->StartPhyNum
, event_data
->NumEntries
);
3822 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
3823 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
3826 phy_number
= event_data
->StartPhyNum
+ i
;
3827 reason_code
= event_data
->PHY
[i
].PhyStatus
&
3828 MPI2_EVENT_SAS_TOPO_RC_MASK
;
3829 switch (reason_code
) {
3830 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
3831 snprintf(link_rate
, 25, ": add, link(0x%02x)",
3832 (event_data
->PHY
[i
].LinkRate
>> 4));
3833 status_str
= link_rate
;
3835 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
3836 status_str
= ": remove";
3838 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
:
3839 status_str
= ": remove_delay";
3841 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
3842 snprintf(link_rate
, 25, ": link(0x%02x)",
3843 (event_data
->PHY
[i
].LinkRate
>> 4));
3844 status_str
= link_rate
;
3846 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE
:
3847 status_str
= ": responding";
3850 status_str
= ": unknown";
3853 printk(KERN_DEBUG
"\tphy(%02d), attached_handle(0x%04x)%s\n",
3854 phy_number
, handle
, status_str
);
3860 * _scsih_sas_topology_change_event - handle topology changes
3861 * @ioc: per adapter object
3863 * @event_data: event data payload
3869 _scsih_sas_topology_change_event(struct MPT2SAS_ADAPTER
*ioc
, u8 VF_ID
,
3870 Mpi2EventDataSasTopologyChangeList_t
*event_data
,
3871 struct fw_event_work
*fw_event
)
3874 u16 parent_handle
, handle
;
3877 struct _sas_node
*sas_expander
;
3878 unsigned long flags
;
3881 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3882 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
3883 _scsih_sas_topology_change_event_debug(ioc
, event_data
);
3886 if (!ioc
->sas_hba
.num_phys
)
3887 _scsih_sas_host_add(ioc
);
3889 _scsih_sas_host_refresh(ioc
, 0);
3891 if (fw_event
->ignore
) {
3892 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"ignoring expander "
3893 "event\n", ioc
->name
));
3897 parent_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
3899 /* handle expander add */
3900 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_ADDED
)
3901 if (_scsih_expander_add(ioc
, parent_handle
) != 0)
3904 /* handle siblings events */
3905 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
3906 if (fw_event
->ignore
) {
3907 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"ignoring "
3908 "expander event\n", ioc
->name
));
3911 if (event_data
->PHY
[i
].PhyStatus
&
3912 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT
)
3914 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
3917 phy_number
= event_data
->StartPhyNum
+ i
;
3918 reason_code
= event_data
->PHY
[i
].PhyStatus
&
3919 MPI2_EVENT_SAS_TOPO_RC_MASK
;
3920 link_rate_
= event_data
->PHY
[i
].LinkRate
>> 4;
3921 switch (reason_code
) {
3922 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
3923 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
3924 if (!parent_handle
) {
3925 if (phy_number
< ioc
->sas_hba
.num_phys
)
3926 _scsih_link_change(ioc
,
3927 ioc
->sas_hba
.phy
[phy_number
].handle
,
3928 handle
, phy_number
, link_rate_
);
3930 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
3932 mpt2sas_scsih_expander_find_by_handle(ioc
,
3934 spin_unlock_irqrestore(&ioc
->sas_node_lock
,
3937 if (phy_number
< sas_expander
->num_phys
)
3938 _scsih_link_change(ioc
,
3940 phy
[phy_number
].handle
,
3945 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
) {
3946 if (link_rate_
>= MPI2_SAS_NEG_LINK_RATE_1_5
)
3947 _scsih_ublock_io_device(ioc
, handle
);
3949 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
) {
3950 if (link_rate_
< MPI2_SAS_NEG_LINK_RATE_1_5
)
3952 _scsih_add_device(ioc
, handle
, phy_number
, 0);
3955 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
3956 _scsih_remove_device(ioc
, handle
);
3961 /* handle expander removal */
3962 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
)
3963 _scsih_expander_remove(ioc
, parent_handle
);
3967 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3969 * _scsih_sas_device_status_change_event_debug - debug for device event
3970 * @event_data: event data payload
3976 _scsih_sas_device_status_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
3977 Mpi2EventDataSasDeviceStatusChange_t
*event_data
)
3979 char *reason_str
= NULL
;
3981 switch (event_data
->ReasonCode
) {
3982 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
:
3983 reason_str
= "smart data";
3985 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED
:
3986 reason_str
= "unsupported device discovered";
3988 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
:
3989 reason_str
= "internal device reset";
3991 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL
:
3992 reason_str
= "internal task abort";
3994 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL
:
3995 reason_str
= "internal task abort set";
3997 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL
:
3998 reason_str
= "internal clear task set";
4000 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL
:
4001 reason_str
= "internal query task";
4003 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE
:
4004 reason_str
= "sata init failure";
4006 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
:
4007 reason_str
= "internal device reset complete";
4009 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL
:
4010 reason_str
= "internal task abort complete";
4012 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION
:
4013 reason_str
= "internal async notification";
4016 reason_str
= "unknown reason";
4019 printk(MPT2SAS_DEBUG_FMT
"device status change: (%s)\n"
4020 "\thandle(0x%04x), sas address(0x%016llx)", ioc
->name
,
4021 reason_str
, le16_to_cpu(event_data
->DevHandle
),
4022 (unsigned long long)le64_to_cpu(event_data
->SASAddress
));
4023 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
)
4024 printk(MPT2SAS_DEBUG_FMT
", ASC(0x%x), ASCQ(0x%x)\n", ioc
->name
,
4025 event_data
->ASC
, event_data
->ASCQ
);
4026 printk(KERN_INFO
"\n");
4031 * _scsih_sas_device_status_change_event - handle device status change
4032 * @ioc: per adapter object
4034 * @event_data: event data payload
4040 _scsih_sas_device_status_change_event(struct MPT2SAS_ADAPTER
*ioc
, u8 VF_ID
,
4041 Mpi2EventDataSasDeviceStatusChange_t
*event_data
)
4043 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4044 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
4045 _scsih_sas_device_status_change_event_debug(ioc
, event_data
);
4049 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4051 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure event
4052 * @ioc: per adapter object
4053 * @event_data: event data payload
4059 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
4060 Mpi2EventDataSasEnclDevStatusChange_t
*event_data
)
4062 char *reason_str
= NULL
;
4064 switch (event_data
->ReasonCode
) {
4065 case MPI2_EVENT_SAS_ENCL_RC_ADDED
:
4066 reason_str
= "enclosure add";
4068 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING
:
4069 reason_str
= "enclosure remove";
4072 reason_str
= "unknown reason";
4076 printk(MPT2SAS_DEBUG_FMT
"enclosure status change: (%s)\n"
4077 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
4078 " number slots(%d)\n", ioc
->name
, reason_str
,
4079 le16_to_cpu(event_data
->EnclosureHandle
),
4080 (unsigned long long)le64_to_cpu(event_data
->EnclosureLogicalID
),
4081 le16_to_cpu(event_data
->StartSlot
));
4086 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
4087 * @ioc: per adapter object
4089 * @event_data: event data payload
4095 _scsih_sas_enclosure_dev_status_change_event(struct MPT2SAS_ADAPTER
*ioc
,
4096 u8 VF_ID
, Mpi2EventDataSasEnclDevStatusChange_t
*event_data
)
4098 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4099 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
4100 _scsih_sas_enclosure_dev_status_change_event_debug(ioc
,
4106 * _scsih_sas_broadcast_primative_event - handle broadcast events
4107 * @ioc: per adapter object
4108 * @event_data: event data payload
4114 _scsih_sas_broadcast_primative_event(struct MPT2SAS_ADAPTER
*ioc
, u8 VF_ID
,
4115 Mpi2EventDataSasBroadcastPrimitive_t
*event_data
)
4117 struct scsi_cmnd
*scmd
;
4120 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
4121 u32 termination_count
;
4123 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
4125 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"broadcast primative: "
4126 "phy number(%d), width(%d)\n", ioc
->name
, event_data
->PhyNum
,
4127 event_data
->PortWidth
));
4129 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: enter\n", ioc
->name
,
4132 mutex_lock(&ioc
->tm_cmds
.mutex
);
4133 termination_count
= 0;
4135 mpi_reply
= ioc
->tm_cmds
.reply
;
4136 for (smid
= 1; smid
<= ioc
->request_depth
; smid
++) {
4137 scmd
= _scsih_scsi_lookup_get(ioc
, smid
);
4140 sas_device_priv_data
= scmd
->device
->hostdata
;
4141 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
)
4143 /* skip hidden raid components */
4144 if (sas_device_priv_data
->sas_target
->flags
&
4145 MPT_TARGET_FLAGS_RAID_COMPONENT
)
4148 if (sas_device_priv_data
->sas_target
->flags
&
4149 MPT_TARGET_FLAGS_VOLUME
)
4152 handle
= sas_device_priv_data
->sas_target
->handle
;
4153 lun
= sas_device_priv_data
->lun
;
4156 mpt2sas_scsih_issue_tm(ioc
, handle
, lun
,
4157 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK
, smid
, 30);
4158 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
4160 if ((mpi_reply
->IOCStatus
== MPI2_IOCSTATUS_SUCCESS
) &&
4161 (mpi_reply
->ResponseCode
==
4162 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
||
4163 mpi_reply
->ResponseCode
==
4164 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
))
4167 mpt2sas_scsih_issue_tm(ioc
, handle
, lun
,
4168 MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET
, 0, 30);
4169 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
4170 termination_count
+= le32_to_cpu(mpi_reply
->TerminationCount
);
4172 ioc
->broadcast_aen_busy
= 0;
4173 mutex_unlock(&ioc
->tm_cmds
.mutex
);
4175 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
4176 "%s - exit, query_count = %d termination_count = %d\n",
4177 ioc
->name
, __func__
, query_count
, termination_count
));
4181 * _scsih_sas_discovery_event - handle discovery events
4182 * @ioc: per adapter object
4183 * @event_data: event data payload
4189 _scsih_sas_discovery_event(struct MPT2SAS_ADAPTER
*ioc
, u8 VF_ID
,
4190 Mpi2EventDataSasDiscovery_t
*event_data
)
4192 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4193 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
) {
4194 printk(MPT2SAS_DEBUG_FMT
"discovery event: (%s)", ioc
->name
,
4195 (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
) ?
4197 if (event_data
->DiscoveryStatus
)
4198 printk(MPT2SAS_DEBUG_FMT
", discovery_status(0x%08x)",
4199 ioc
->name
, le32_to_cpu(event_data
->DiscoveryStatus
));
4204 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
&&
4205 !ioc
->sas_hba
.num_phys
)
4206 _scsih_sas_host_add(ioc
);
4210 * _scsih_reprobe_lun - reprobing lun
4211 * @sdev: scsi device struct
4212 * @no_uld_attach: sdev->no_uld_attach flag setting
4216 _scsih_reprobe_lun(struct scsi_device
*sdev
, void *no_uld_attach
)
4220 sdev
->no_uld_attach
= no_uld_attach
? 1 : 0;
4221 sdev_printk(KERN_INFO
, sdev
, "%s raid component\n",
4222 sdev
->no_uld_attach
? "hidding" : "exposing");
4223 rc
= scsi_device_reprobe(sdev
);
4227 * _scsih_reprobe_target - reprobing target
4228 * @starget: scsi target struct
4229 * @no_uld_attach: sdev->no_uld_attach flag setting
4231 * Note: no_uld_attach flag determines whether the disk device is attached
4232 * to block layer. A value of `1` means to not attach.
4235 _scsih_reprobe_target(struct scsi_target
*starget
, int no_uld_attach
)
4237 struct MPT2SAS_TARGET
*sas_target_priv_data
= starget
->hostdata
;
4240 sas_target_priv_data
->flags
|= MPT_TARGET_FLAGS_RAID_COMPONENT
;
4242 sas_target_priv_data
->flags
&= ~MPT_TARGET_FLAGS_RAID_COMPONENT
;
4244 starget_for_each_device(starget
, no_uld_attach
? (void *)1 : NULL
,
4245 _scsih_reprobe_lun
);
4248 * _scsih_sas_volume_add - add new volume
4249 * @ioc: per adapter object
4250 * @element: IR config element data
4256 _scsih_sas_volume_add(struct MPT2SAS_ADAPTER
*ioc
,
4257 Mpi2EventIrConfigElement_t
*element
)
4259 struct _raid_device
*raid_device
;
4260 unsigned long flags
;
4262 u16 handle
= le16_to_cpu(element
->VolDevHandle
);
4265 mpt2sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
4267 printk(MPT2SAS_ERR_FMT
4268 "failure at %s:%d/%s()!\n", ioc
->name
,
4269 __FILE__
, __LINE__
, __func__
);
4273 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
4274 raid_device
= _scsih_raid_device_find_by_wwid(ioc
, wwid
);
4275 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
4280 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
4282 printk(MPT2SAS_ERR_FMT
4283 "failure at %s:%d/%s()!\n", ioc
->name
,
4284 __FILE__
, __LINE__
, __func__
);
4288 raid_device
->id
= ioc
->sas_id
++;
4289 raid_device
->channel
= RAID_CHANNEL
;
4290 raid_device
->handle
= handle
;
4291 raid_device
->wwid
= wwid
;
4292 _scsih_raid_device_add(ioc
, raid_device
);
4293 if (!ioc
->wait_for_port_enable_to_complete
) {
4294 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
4295 raid_device
->id
, 0);
4297 _scsih_raid_device_remove(ioc
, raid_device
);
4299 _scsih_determine_boot_device(ioc
, raid_device
, 1);
4303 * _scsih_sas_volume_delete - delete volume
4304 * @ioc: per adapter object
4305 * @element: IR config element data
4311 _scsih_sas_volume_delete(struct MPT2SAS_ADAPTER
*ioc
,
4312 Mpi2EventIrConfigElement_t
*element
)
4314 struct _raid_device
*raid_device
;
4315 u16 handle
= le16_to_cpu(element
->VolDevHandle
);
4316 unsigned long flags
;
4317 struct MPT2SAS_TARGET
*sas_target_priv_data
;
4319 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
4320 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
4321 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
4324 if (raid_device
->starget
) {
4325 sas_target_priv_data
= raid_device
->starget
->hostdata
;
4326 sas_target_priv_data
->deleted
= 1;
4327 scsi_remove_target(&raid_device
->starget
->dev
);
4329 _scsih_raid_device_remove(ioc
, raid_device
);
4333 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
4334 * @ioc: per adapter object
4335 * @element: IR config element data
4341 _scsih_sas_pd_expose(struct MPT2SAS_ADAPTER
*ioc
,
4342 Mpi2EventIrConfigElement_t
*element
)
4344 struct _sas_device
*sas_device
;
4345 unsigned long flags
;
4346 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
4348 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4349 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
4350 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4354 /* exposing raid component */
4355 sas_device
->volume_handle
= 0;
4356 sas_device
->volume_wwid
= 0;
4357 sas_device
->hidden_raid_component
= 0;
4358 _scsih_reprobe_target(sas_device
->starget
, 0);
4362 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
4363 * @ioc: per adapter object
4364 * @element: IR config element data
4370 _scsih_sas_pd_hide(struct MPT2SAS_ADAPTER
*ioc
,
4371 Mpi2EventIrConfigElement_t
*element
)
4373 struct _sas_device
*sas_device
;
4374 unsigned long flags
;
4375 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
4377 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4378 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
4379 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4383 /* hiding raid component */
4384 mpt2sas_config_get_volume_handle(ioc
, handle
,
4385 &sas_device
->volume_handle
);
4386 mpt2sas_config_get_volume_wwid(ioc
, sas_device
->volume_handle
,
4387 &sas_device
->volume_wwid
);
4388 sas_device
->hidden_raid_component
= 1;
4389 _scsih_reprobe_target(sas_device
->starget
, 1);
4393 * _scsih_sas_pd_delete - delete pd component
4394 * @ioc: per adapter object
4395 * @element: IR config element data
4401 _scsih_sas_pd_delete(struct MPT2SAS_ADAPTER
*ioc
,
4402 Mpi2EventIrConfigElement_t
*element
)
4404 struct _sas_device
*sas_device
;
4405 unsigned long flags
;
4406 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
4408 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4409 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
4410 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4413 _scsih_remove_device(ioc
, handle
);
4417 * _scsih_sas_pd_add - remove pd component
4418 * @ioc: per adapter object
4419 * @element: IR config element data
4425 _scsih_sas_pd_add(struct MPT2SAS_ADAPTER
*ioc
,
4426 Mpi2EventIrConfigElement_t
*element
)
4428 struct _sas_device
*sas_device
;
4429 unsigned long flags
;
4430 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
4431 Mpi2ConfigReply_t mpi_reply
;
4432 Mpi2SasDevicePage0_t sas_device_pg0
;
4435 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4436 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
4437 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4439 sas_device
->hidden_raid_component
= 1;
4443 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
4444 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
4445 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4446 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4450 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4451 MPI2_IOCSTATUS_MASK
;
4452 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4453 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4454 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4458 _scsih_link_change(ioc
,
4459 le16_to_cpu(sas_device_pg0
.ParentDevHandle
),
4460 handle
, sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
4462 _scsih_add_device(ioc
, handle
, 0, 1);
4465 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4467 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
4468 * @ioc: per adapter object
4469 * @event_data: event data payload
4475 _scsih_sas_ir_config_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
4476 Mpi2EventDataIrConfigChangeList_t
*event_data
)
4478 Mpi2EventIrConfigElement_t
*element
;
4481 char *reason_str
= NULL
, *element_str
= NULL
;
4483 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
4485 printk(MPT2SAS_DEBUG_FMT
"raid config change: (%s), elements(%d)\n",
4486 ioc
->name
, (le32_to_cpu(event_data
->Flags
) &
4487 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ?
4488 "foreign" : "native", event_data
->NumElements
);
4489 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
4490 switch (element
->ReasonCode
) {
4491 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
4494 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
4495 reason_str
= "remove";
4497 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE
:
4498 reason_str
= "no change";
4500 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
4501 reason_str
= "hide";
4503 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
4504 reason_str
= "unhide";
4506 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
4507 reason_str
= "volume_created";
4509 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
4510 reason_str
= "volume_deleted";
4512 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
4513 reason_str
= "pd_created";
4515 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
4516 reason_str
= "pd_deleted";
4519 reason_str
= "unknown reason";
4522 element_type
= le16_to_cpu(element
->ElementFlags
) &
4523 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK
;
4524 switch (element_type
) {
4525 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT
:
4526 element_str
= "volume";
4528 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT
:
4529 element_str
= "phys disk";
4531 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT
:
4532 element_str
= "hot spare";
4535 element_str
= "unknown element";
4538 printk(KERN_DEBUG
"\t(%s:%s), vol handle(0x%04x), "
4539 "pd handle(0x%04x), pd num(0x%02x)\n", element_str
,
4540 reason_str
, le16_to_cpu(element
->VolDevHandle
),
4541 le16_to_cpu(element
->PhysDiskDevHandle
),
4542 element
->PhysDiskNum
);
4548 * _scsih_sas_ir_config_change_event - handle ir configuration change events
4549 * @ioc: per adapter object
4551 * @event_data: event data payload
4557 _scsih_sas_ir_config_change_event(struct MPT2SAS_ADAPTER
*ioc
, u8 VF_ID
,
4558 Mpi2EventDataIrConfigChangeList_t
*event_data
)
4560 Mpi2EventIrConfigElement_t
*element
;
4564 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4565 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
4566 _scsih_sas_ir_config_change_event_debug(ioc
, event_data
);
4569 foreign_config
= (le32_to_cpu(event_data
->Flags
) &
4570 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ? 1 : 0;
4572 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
4573 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
4575 switch (element
->ReasonCode
) {
4576 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
4577 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
4578 if (!foreign_config
)
4579 _scsih_sas_volume_add(ioc
, element
);
4581 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
4582 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
4583 if (!foreign_config
)
4584 _scsih_sas_volume_delete(ioc
, element
);
4586 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
4587 _scsih_sas_pd_hide(ioc
, element
);
4589 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
4590 _scsih_sas_pd_expose(ioc
, element
);
4592 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
4593 _scsih_sas_pd_add(ioc
, element
);
4595 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
4596 _scsih_sas_pd_delete(ioc
, element
);
4603 * _scsih_sas_ir_volume_event - IR volume event
4604 * @ioc: per adapter object
4605 * @event_data: event data payload
4611 _scsih_sas_ir_volume_event(struct MPT2SAS_ADAPTER
*ioc
, u8 VF_ID
,
4612 Mpi2EventDataIrVolume_t
*event_data
)
4615 unsigned long flags
;
4616 struct _raid_device
*raid_device
;
4620 struct MPT2SAS_TARGET
*sas_target_priv_data
;
4622 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED
)
4625 handle
= le16_to_cpu(event_data
->VolDevHandle
);
4626 state
= le32_to_cpu(event_data
->NewValue
);
4627 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: handle(0x%04x), "
4628 "old(0x%08x), new(0x%08x)\n", ioc
->name
, __func__
, handle
,
4629 le32_to_cpu(event_data
->PreviousValue
), state
));
4631 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
4632 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
4633 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
4636 case MPI2_RAID_VOL_STATE_MISSING
:
4637 case MPI2_RAID_VOL_STATE_FAILED
:
4640 if (raid_device
->starget
) {
4641 sas_target_priv_data
= raid_device
->starget
->hostdata
;
4642 sas_target_priv_data
->deleted
= 1;
4643 scsi_remove_target(&raid_device
->starget
->dev
);
4645 _scsih_raid_device_remove(ioc
, raid_device
);
4648 case MPI2_RAID_VOL_STATE_ONLINE
:
4649 case MPI2_RAID_VOL_STATE_DEGRADED
:
4650 case MPI2_RAID_VOL_STATE_OPTIMAL
:
4654 mpt2sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
4656 printk(MPT2SAS_ERR_FMT
4657 "failure at %s:%d/%s()!\n", ioc
->name
,
4658 __FILE__
, __LINE__
, __func__
);
4662 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
4664 printk(MPT2SAS_ERR_FMT
4665 "failure at %s:%d/%s()!\n", ioc
->name
,
4666 __FILE__
, __LINE__
, __func__
);
4670 raid_device
->id
= ioc
->sas_id
++;
4671 raid_device
->channel
= RAID_CHANNEL
;
4672 raid_device
->handle
= handle
;
4673 raid_device
->wwid
= wwid
;
4674 _scsih_raid_device_add(ioc
, raid_device
);
4675 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
4676 raid_device
->id
, 0);
4678 _scsih_raid_device_remove(ioc
, raid_device
);
4681 case MPI2_RAID_VOL_STATE_INITIALIZING
:
4688 * _scsih_sas_ir_physical_disk_event - PD event
4689 * @ioc: per adapter object
4690 * @event_data: event data payload
4696 _scsih_sas_ir_physical_disk_event(struct MPT2SAS_ADAPTER
*ioc
, u8 VF_ID
,
4697 Mpi2EventDataIrPhysicalDisk_t
*event_data
)
4701 struct _sas_device
*sas_device
;
4702 unsigned long flags
;
4703 Mpi2ConfigReply_t mpi_reply
;
4704 Mpi2SasDevicePage0_t sas_device_pg0
;
4707 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED
)
4710 handle
= le16_to_cpu(event_data
->PhysDiskDevHandle
);
4711 state
= le32_to_cpu(event_data
->NewValue
);
4713 dewtprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: handle(0x%04x), "
4714 "old(0x%08x), new(0x%08x)\n", ioc
->name
, __func__
, handle
,
4715 le32_to_cpu(event_data
->PreviousValue
), state
));
4717 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4718 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
4719 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4722 case MPI2_RAID_PD_STATE_ONLINE
:
4723 case MPI2_RAID_PD_STATE_DEGRADED
:
4724 case MPI2_RAID_PD_STATE_REBUILDING
:
4725 case MPI2_RAID_PD_STATE_OPTIMAL
:
4727 sas_device
->hidden_raid_component
= 1;
4731 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
4732 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
4734 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4735 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4739 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4740 MPI2_IOCSTATUS_MASK
;
4741 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4742 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4743 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4747 _scsih_link_change(ioc
,
4748 le16_to_cpu(sas_device_pg0
.ParentDevHandle
),
4749 handle
, sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
4751 _scsih_add_device(ioc
, handle
, 0, 1);
4755 case MPI2_RAID_PD_STATE_OFFLINE
:
4756 case MPI2_RAID_PD_STATE_NOT_CONFIGURED
:
4757 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE
:
4758 case MPI2_RAID_PD_STATE_HOT_SPARE
:
4764 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4766 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
4767 * @ioc: per adapter object
4768 * @event_data: event data payload
4774 _scsih_sas_ir_operation_status_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
4775 Mpi2EventDataIrOperationStatus_t
*event_data
)
4777 char *reason_str
= NULL
;
4779 switch (event_data
->RAIDOperation
) {
4780 case MPI2_EVENT_IR_RAIDOP_RESYNC
:
4781 reason_str
= "resync";
4783 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION
:
4784 reason_str
= "online capacity expansion";
4786 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK
:
4787 reason_str
= "consistency check";
4790 reason_str
= "unknown reason";
4794 printk(MPT2SAS_INFO_FMT
"raid operational status: (%s)"
4795 "\thandle(0x%04x), percent complete(%d)\n",
4796 ioc
->name
, reason_str
,
4797 le16_to_cpu(event_data
->VolDevHandle
),
4798 event_data
->PercentComplete
);
4803 * _scsih_sas_ir_operation_status_event - handle RAID operation events
4804 * @ioc: per adapter object
4806 * @event_data: event data payload
4812 _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER
*ioc
, u8 VF_ID
,
4813 Mpi2EventDataIrOperationStatus_t
*event_data
)
4815 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4816 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
4817 _scsih_sas_ir_operation_status_event_debug(ioc
, event_data
);
4822 * _scsih_task_set_full - handle task set full
4823 * @ioc: per adapter object
4824 * @event_data: event data payload
4827 * Throttle back qdepth.
4830 _scsih_task_set_full(struct MPT2SAS_ADAPTER
*ioc
, u8 VF_ID
,
4831 Mpi2EventDataTaskSetFull_t
*event_data
)
4833 unsigned long flags
;
4834 struct _sas_device
*sas_device
;
4835 static struct _raid_device
*raid_device
;
4836 struct scsi_device
*sdev
;
4843 current_depth
= le16_to_cpu(event_data
->CurrentDepth
);
4844 handle
= le16_to_cpu(event_data
->DevHandle
);
4845 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4846 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
4848 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4851 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4852 id
= sas_device
->id
;
4853 channel
= sas_device
->channel
;
4854 sas_address
= sas_device
->sas_address
;
4856 /* if hidden raid component, then change to volume characteristics */
4857 if (sas_device
->hidden_raid_component
&& sas_device
->volume_handle
) {
4858 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
4859 raid_device
= _scsih_raid_device_find_by_handle(
4860 ioc
, sas_device
->volume_handle
);
4861 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
4863 id
= raid_device
->id
;
4864 channel
= raid_device
->channel
;
4865 handle
= raid_device
->handle
;
4866 sas_address
= raid_device
->wwid
;
4870 if (ioc
->logging_level
& MPT_DEBUG_TASK_SET_FULL
)
4871 starget_printk(KERN_DEBUG
, sas_device
->starget
, "task set "
4872 "full: handle(0x%04x), sas_addr(0x%016llx), depth(%d)\n",
4873 handle
, (unsigned long long)sas_address
, current_depth
);
4875 shost_for_each_device(sdev
, ioc
->shost
) {
4876 if (sdev
->id
== id
&& sdev
->channel
== channel
) {
4877 if (current_depth
> sdev
->queue_depth
) {
4878 if (ioc
->logging_level
&
4879 MPT_DEBUG_TASK_SET_FULL
)
4880 sdev_printk(KERN_INFO
, sdev
, "strange "
4881 "observation, the queue depth is"
4882 " (%d) meanwhile fw queue depth "
4883 "is (%d)\n", sdev
->queue_depth
,
4887 depth
= scsi_track_queue_full(sdev
,
4890 sdev_printk(KERN_INFO
, sdev
, "Queue depth "
4891 "reduced to (%d)\n", depth
);
4893 sdev_printk(KERN_INFO
, sdev
, "Tagged Command "
4894 "Queueing is being disabled\n");
4895 else if (depth
== 0)
4896 if (ioc
->logging_level
&
4897 MPT_DEBUG_TASK_SET_FULL
)
4898 sdev_printk(KERN_INFO
, sdev
,
4899 "Queue depth not changed yet\n");
4905 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
4906 * @ioc: per adapter object
4907 * @sas_address: sas address
4908 * @slot: enclosure slot id
4909 * @handle: device handle
4911 * After host reset, find out whether devices are still responding.
4912 * Used in _scsi_remove_unresponsive_sas_devices.
4917 _scsih_mark_responding_sas_device(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
,
4918 u16 slot
, u16 handle
)
4920 struct MPT2SAS_TARGET
*sas_target_priv_data
;
4921 struct scsi_target
*starget
;
4922 struct _sas_device
*sas_device
;
4923 unsigned long flags
;
4925 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4926 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
) {
4927 if (sas_device
->sas_address
== sas_address
&&
4928 sas_device
->slot
== slot
&& sas_device
->starget
) {
4929 sas_device
->responding
= 1;
4930 starget_printk(KERN_INFO
, sas_device
->starget
,
4931 "handle(0x%04x), sas_addr(0x%016llx), enclosure "
4932 "logical id(0x%016llx), slot(%d)\n", handle
,
4933 (unsigned long long)sas_device
->sas_address
,
4934 (unsigned long long)
4935 sas_device
->enclosure_logical_id
,
4937 if (sas_device
->handle
== handle
)
4939 printk(KERN_INFO
"\thandle changed from(0x%04x)!!!\n",
4940 sas_device
->handle
);
4941 sas_device
->handle
= handle
;
4942 starget
= sas_device
->starget
;
4943 sas_target_priv_data
= starget
->hostdata
;
4944 sas_target_priv_data
->handle
= handle
;
4949 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4953 * _scsih_search_responding_sas_devices -
4954 * @ioc: per adapter object
4956 * After host reset, find out whether devices are still responding.
4962 _scsih_search_responding_sas_devices(struct MPT2SAS_ADAPTER
*ioc
)
4964 Mpi2SasDevicePage0_t sas_device_pg0
;
4965 Mpi2ConfigReply_t mpi_reply
;
4972 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
, __func__
);
4974 if (list_empty(&ioc
->sas_device_list
))
4978 while (!(mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
4979 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
,
4981 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4982 MPI2_IOCSTATUS_MASK
;
4983 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
4985 handle
= le16_to_cpu(sas_device_pg0
.DevHandle
);
4986 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
4987 if (!(_scsih_is_end_device(device_info
)))
4989 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
4990 slot
= le16_to_cpu(sas_device_pg0
.Slot
);
4991 _scsih_mark_responding_sas_device(ioc
, sas_address
, slot
,
4997 * _scsih_mark_responding_raid_device - mark a raid_device as responding
4998 * @ioc: per adapter object
4999 * @wwid: world wide identifier for raid volume
5000 * @handle: device handle
5002 * After host reset, find out whether devices are still responding.
5003 * Used in _scsi_remove_unresponsive_raid_devices.
5008 _scsih_mark_responding_raid_device(struct MPT2SAS_ADAPTER
*ioc
, u64 wwid
,
5011 struct MPT2SAS_TARGET
*sas_target_priv_data
;
5012 struct scsi_target
*starget
;
5013 struct _raid_device
*raid_device
;
5014 unsigned long flags
;
5016 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5017 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
5018 if (raid_device
->wwid
== wwid
&& raid_device
->starget
) {
5019 raid_device
->responding
= 1;
5020 starget_printk(KERN_INFO
, raid_device
->starget
,
5021 "handle(0x%04x), wwid(0x%016llx)\n", handle
,
5022 (unsigned long long)raid_device
->wwid
);
5023 if (raid_device
->handle
== handle
)
5025 printk(KERN_INFO
"\thandle changed from(0x%04x)!!!\n",
5026 raid_device
->handle
);
5027 raid_device
->handle
= handle
;
5028 starget
= raid_device
->starget
;
5029 sas_target_priv_data
= starget
->hostdata
;
5030 sas_target_priv_data
->handle
= handle
;
5035 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5039 * _scsih_search_responding_raid_devices -
5040 * @ioc: per adapter object
5042 * After host reset, find out whether devices are still responding.
5048 _scsih_search_responding_raid_devices(struct MPT2SAS_ADAPTER
*ioc
)
5050 Mpi2RaidVolPage1_t volume_pg1
;
5051 Mpi2ConfigReply_t mpi_reply
;
5055 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
, __func__
);
5057 if (list_empty(&ioc
->raid_device_list
))
5061 while (!(mpt2sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
5062 &volume_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
5063 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5064 MPI2_IOCSTATUS_MASK
;
5065 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
5067 handle
= le16_to_cpu(volume_pg1
.DevHandle
);
5068 _scsih_mark_responding_raid_device(ioc
,
5069 le64_to_cpu(volume_pg1
.WWID
), handle
);
5074 * _scsih_mark_responding_expander - mark a expander as responding
5075 * @ioc: per adapter object
5076 * @sas_address: sas address
5079 * After host reset, find out whether devices are still responding.
5080 * Used in _scsi_remove_unresponsive_expanders.
5085 _scsih_mark_responding_expander(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
,
5088 struct _sas_node
*sas_expander
;
5089 unsigned long flags
;
5091 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5092 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
5093 if (sas_expander
->sas_address
== sas_address
) {
5094 sas_expander
->responding
= 1;
5095 if (sas_expander
->handle
!= handle
) {
5096 printk(KERN_INFO
"old handle(0x%04x)\n",
5097 sas_expander
->handle
);
5098 sas_expander
->handle
= handle
;
5104 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5108 * _scsih_search_responding_expanders -
5109 * @ioc: per adapter object
5111 * After host reset, find out whether devices are still responding.
5117 _scsih_search_responding_expanders(struct MPT2SAS_ADAPTER
*ioc
)
5119 Mpi2ExpanderPage0_t expander_pg0
;
5120 Mpi2ConfigReply_t mpi_reply
;
5125 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
, __func__
);
5127 if (list_empty(&ioc
->sas_expander_list
))
5131 while (!(mpt2sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
5132 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL
, handle
))) {
5134 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5135 MPI2_IOCSTATUS_MASK
;
5136 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
5139 handle
= le16_to_cpu(expander_pg0
.DevHandle
);
5140 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
5141 printk(KERN_INFO
"\texpander present: handle(0x%04x), "
5142 "sas_addr(0x%016llx)\n", handle
,
5143 (unsigned long long)sas_address
);
5144 _scsih_mark_responding_expander(ioc
, sas_address
, handle
);
5150 * _scsih_remove_unresponding_devices - removing unresponding devices
5151 * @ioc: per adapter object
5156 _scsih_remove_unresponding_devices(struct MPT2SAS_ADAPTER
*ioc
)
5158 struct _sas_device
*sas_device
, *sas_device_next
;
5159 struct _sas_node
*sas_expander
, *sas_expander_next
;
5160 struct _raid_device
*raid_device
, *raid_device_next
;
5161 unsigned long flags
;
5163 _scsih_search_responding_sas_devices(ioc
);
5164 _scsih_search_responding_raid_devices(ioc
);
5165 _scsih_search_responding_expanders(ioc
);
5167 spin_lock_irqsave(&ioc
->ioc_reset_in_progress_lock
, flags
);
5168 ioc
->shost_recovery
= 0;
5169 if (ioc
->shost
->shost_state
== SHOST_RECOVERY
) {
5170 printk(MPT2SAS_INFO_FMT
"putting controller into "
5171 "SHOST_RUNNING\n", ioc
->name
);
5172 scsi_host_set_state(ioc
->shost
, SHOST_RUNNING
);
5174 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
, flags
);
5176 list_for_each_entry_safe(sas_device
, sas_device_next
,
5177 &ioc
->sas_device_list
, list
) {
5178 if (sas_device
->responding
) {
5179 sas_device
->responding
= 0;
5182 if (sas_device
->starget
)
5183 starget_printk(KERN_INFO
, sas_device
->starget
,
5184 "removing: handle(0x%04x), sas_addr(0x%016llx), "
5185 "enclosure logical id(0x%016llx), slot(%d)\n",
5187 (unsigned long long)sas_device
->sas_address
,
5188 (unsigned long long)
5189 sas_device
->enclosure_logical_id
,
5191 _scsih_remove_device(ioc
, sas_device
->handle
);
5194 list_for_each_entry_safe(raid_device
, raid_device_next
,
5195 &ioc
->raid_device_list
, list
) {
5196 if (raid_device
->responding
) {
5197 raid_device
->responding
= 0;
5200 if (raid_device
->starget
) {
5201 starget_printk(KERN_INFO
, raid_device
->starget
,
5202 "removing: handle(0x%04x), wwid(0x%016llx)\n",
5203 raid_device
->handle
,
5204 (unsigned long long)raid_device
->wwid
);
5205 scsi_remove_target(&raid_device
->starget
->dev
);
5207 _scsih_raid_device_remove(ioc
, raid_device
);
5210 list_for_each_entry_safe(sas_expander
, sas_expander_next
,
5211 &ioc
->sas_expander_list
, list
) {
5212 if (sas_expander
->responding
) {
5213 sas_expander
->responding
= 0;
5216 printk("\tremoving expander: handle(0x%04x), "
5217 " sas_addr(0x%016llx)\n", sas_expander
->handle
,
5218 (unsigned long long)sas_expander
->sas_address
);
5219 _scsih_expander_remove(ioc
, sas_expander
->handle
);
5224 * _firmware_event_work - delayed task for processing firmware events
5225 * @ioc: per adapter object
5226 * @work: equal to the fw_event_work object
5232 _firmware_event_work(struct work_struct
*work
)
5234 struct fw_event_work
*fw_event
= container_of(work
,
5235 struct fw_event_work
, work
);
5236 unsigned long flags
;
5237 struct MPT2SAS_ADAPTER
*ioc
= fw_event
->ioc
;
5239 /* This is invoked by calling _scsih_queue_rescan(). */
5240 if (fw_event
->event
== MPT2SAS_RESCAN_AFTER_HOST_RESET
) {
5241 _scsih_fw_event_free(ioc
, fw_event
);
5242 _scsih_sas_host_refresh(ioc
, 1);
5243 _scsih_remove_unresponding_devices(ioc
);
5247 /* the queue is being flushed so ignore this event */
5248 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
5249 if (ioc
->fw_events_off
|| ioc
->remove_host
) {
5250 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
5251 _scsih_fw_event_free(ioc
, fw_event
);
5254 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
5256 spin_lock_irqsave(&ioc
->ioc_reset_in_progress_lock
, flags
);
5257 if (ioc
->shost_recovery
) {
5258 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
, flags
);
5259 _scsih_fw_event_requeue(ioc
, fw_event
, 1000);
5262 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
, flags
);
5264 switch (fw_event
->event
) {
5265 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
5266 _scsih_sas_topology_change_event(ioc
, fw_event
->VF_ID
,
5267 fw_event
->event_data
, fw_event
);
5269 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
5270 _scsih_sas_device_status_change_event(ioc
, fw_event
->VF_ID
,
5271 fw_event
->event_data
);
5273 case MPI2_EVENT_SAS_DISCOVERY
:
5274 _scsih_sas_discovery_event(ioc
, fw_event
->VF_ID
,
5275 fw_event
->event_data
);
5277 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
5278 _scsih_sas_broadcast_primative_event(ioc
, fw_event
->VF_ID
,
5279 fw_event
->event_data
);
5281 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
5282 _scsih_sas_enclosure_dev_status_change_event(ioc
,
5283 fw_event
->VF_ID
, fw_event
->event_data
);
5285 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
5286 _scsih_sas_ir_config_change_event(ioc
, fw_event
->VF_ID
,
5287 fw_event
->event_data
);
5289 case MPI2_EVENT_IR_VOLUME
:
5290 _scsih_sas_ir_volume_event(ioc
, fw_event
->VF_ID
,
5291 fw_event
->event_data
);
5293 case MPI2_EVENT_IR_PHYSICAL_DISK
:
5294 _scsih_sas_ir_physical_disk_event(ioc
, fw_event
->VF_ID
,
5295 fw_event
->event_data
);
5297 case MPI2_EVENT_IR_OPERATION_STATUS
:
5298 _scsih_sas_ir_operation_status_event(ioc
, fw_event
->VF_ID
,
5299 fw_event
->event_data
);
5301 case MPI2_EVENT_TASK_SET_FULL
:
5302 _scsih_task_set_full(ioc
, fw_event
->VF_ID
,
5303 fw_event
->event_data
);
5306 _scsih_fw_event_free(ioc
, fw_event
);
5310 * mpt2sas_scsih_event_callback - firmware event handler (called at ISR time)
5311 * @ioc: per adapter object
5312 * @VF_ID: virtual function id
5313 * @reply: reply message frame(lower 32bit addr)
5314 * Context: interrupt.
5316 * This function merely adds a new work task into ioc->firmware_event_thread.
5317 * The tasks are worked from _firmware_event_work in user context.
5322 mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER
*ioc
, u8 VF_ID
, u32 reply
)
5324 struct fw_event_work
*fw_event
;
5325 Mpi2EventNotificationReply_t
*mpi_reply
;
5326 unsigned long flags
;
5329 /* events turned off due to host reset or driver unloading */
5330 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
5331 if (ioc
->fw_events_off
|| ioc
->remove_host
) {
5332 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
5335 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
5337 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
5338 event
= le16_to_cpu(mpi_reply
->Event
);
5342 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
5344 Mpi2EventDataSasBroadcastPrimitive_t
*baen_data
=
5345 (Mpi2EventDataSasBroadcastPrimitive_t
*)
5346 mpi_reply
->EventData
;
5348 if (baen_data
->Primitive
!=
5349 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT
||
5350 ioc
->broadcast_aen_busy
)
5352 ioc
->broadcast_aen_busy
= 1;
5356 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
5357 _scsih_check_topo_delete_events(ioc
,
5358 (Mpi2EventDataSasTopologyChangeList_t
*)
5359 mpi_reply
->EventData
);
5362 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
5363 case MPI2_EVENT_IR_OPERATION_STATUS
:
5364 case MPI2_EVENT_SAS_DISCOVERY
:
5365 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
5366 case MPI2_EVENT_IR_VOLUME
:
5367 case MPI2_EVENT_IR_PHYSICAL_DISK
:
5368 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
5369 case MPI2_EVENT_TASK_SET_FULL
:
5372 default: /* ignore the rest */
5376 fw_event
= kzalloc(sizeof(struct fw_event_work
), GFP_ATOMIC
);
5378 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5379 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5382 fw_event
->event_data
=
5383 kzalloc(mpi_reply
->EventDataLength
*4, GFP_ATOMIC
);
5384 if (!fw_event
->event_data
) {
5385 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5386 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5391 memcpy(fw_event
->event_data
, mpi_reply
->EventData
,
5392 mpi_reply
->EventDataLength
*4);
5393 fw_event
->ioc
= ioc
;
5394 fw_event
->VF_ID
= VF_ID
;
5395 fw_event
->event
= event
;
5396 _scsih_fw_event_add(ioc
, fw_event
);
5399 /* shost template */
5400 static struct scsi_host_template scsih_driver_template
= {
5401 .module
= THIS_MODULE
,
5402 .name
= "Fusion MPT SAS Host",
5403 .proc_name
= MPT2SAS_DRIVER_NAME
,
5404 .queuecommand
= _scsih_qcmd
,
5405 .target_alloc
= _scsih_target_alloc
,
5406 .slave_alloc
= _scsih_slave_alloc
,
5407 .slave_configure
= _scsih_slave_configure
,
5408 .target_destroy
= _scsih_target_destroy
,
5409 .slave_destroy
= _scsih_slave_destroy
,
5410 .change_queue_depth
= _scsih_change_queue_depth
,
5411 .change_queue_type
= _scsih_change_queue_type
,
5412 .eh_abort_handler
= _scsih_abort
,
5413 .eh_device_reset_handler
= _scsih_dev_reset
,
5414 .eh_target_reset_handler
= _scsih_target_reset
,
5415 .eh_host_reset_handler
= _scsih_host_reset
,
5416 .bios_param
= _scsih_bios_param
,
5419 .sg_tablesize
= MPT2SAS_SG_DEPTH
,
5420 .max_sectors
= 8192,
5422 .use_clustering
= ENABLE_CLUSTERING
,
5423 .shost_attrs
= mpt2sas_host_attrs
,
5424 .sdev_attrs
= mpt2sas_dev_attrs
,
5428 * _scsih_expander_node_remove - removing expander device from list.
5429 * @ioc: per adapter object
5430 * @sas_expander: the sas_device object
5431 * Context: Calling function should acquire ioc->sas_node_lock.
5433 * Removing object and freeing associated memory from the
5434 * ioc->sas_expander_list.
5439 _scsih_expander_node_remove(struct MPT2SAS_ADAPTER
*ioc
,
5440 struct _sas_node
*sas_expander
)
5442 struct _sas_port
*mpt2sas_port
;
5443 struct _sas_device
*sas_device
;
5444 struct _sas_node
*expander_sibling
;
5445 unsigned long flags
;
5450 /* remove sibling ports attached to this expander */
5451 retry_device_search
:
5452 list_for_each_entry(mpt2sas_port
,
5453 &sas_expander
->sas_port_list
, port_list
) {
5454 if (mpt2sas_port
->remote_identify
.device_type
==
5456 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5458 mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
5459 mpt2sas_port
->remote_identify
.sas_address
);
5460 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5463 _scsih_remove_device(ioc
, sas_device
->handle
);
5464 goto retry_device_search
;
5468 retry_expander_search
:
5469 list_for_each_entry(mpt2sas_port
,
5470 &sas_expander
->sas_port_list
, port_list
) {
5472 if (mpt2sas_port
->remote_identify
.device_type
==
5473 MPI2_SAS_DEVICE_INFO_EDGE_EXPANDER
||
5474 mpt2sas_port
->remote_identify
.device_type
==
5475 MPI2_SAS_DEVICE_INFO_FANOUT_EXPANDER
) {
5477 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5479 mpt2sas_scsih_expander_find_by_sas_address(
5480 ioc
, mpt2sas_port
->remote_identify
.sas_address
);
5481 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5482 if (!expander_sibling
)
5484 _scsih_expander_remove(ioc
, expander_sibling
->handle
);
5485 goto retry_expander_search
;
5489 mpt2sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
5490 sas_expander
->parent_handle
);
5492 printk(MPT2SAS_INFO_FMT
"expander_remove: handle"
5493 "(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
5494 sas_expander
->handle
, (unsigned long long)
5495 sas_expander
->sas_address
);
5497 list_del(&sas_expander
->list
);
5498 kfree(sas_expander
->phy
);
5499 kfree(sas_expander
);
5503 * _scsih_remove - detach and remove add host
5504 * @pdev: PCI device struct
5508 static void __devexit
5509 _scsih_remove(struct pci_dev
*pdev
)
5511 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
5512 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
5513 struct _sas_port
*mpt2sas_port
;
5514 struct _sas_device
*sas_device
;
5515 struct _sas_node
*expander_sibling
;
5516 struct workqueue_struct
*wq
;
5517 unsigned long flags
;
5519 ioc
->remove_host
= 1;
5520 _scsih_fw_event_off(ioc
);
5522 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
5523 wq
= ioc
->firmware_event_thread
;
5524 ioc
->firmware_event_thread
= NULL
;
5525 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
5527 destroy_workqueue(wq
);
5529 /* free ports attached to the sas_host */
5531 list_for_each_entry(mpt2sas_port
,
5532 &ioc
->sas_hba
.sas_port_list
, port_list
) {
5533 if (mpt2sas_port
->remote_identify
.device_type
==
5536 mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
5537 mpt2sas_port
->remote_identify
.sas_address
);
5539 _scsih_remove_device(ioc
, sas_device
->handle
);
5544 mpt2sas_scsih_expander_find_by_sas_address(ioc
,
5545 mpt2sas_port
->remote_identify
.sas_address
);
5546 if (expander_sibling
) {
5547 _scsih_expander_remove(ioc
,
5548 expander_sibling
->handle
);
5554 /* free phys attached to the sas_host */
5555 if (ioc
->sas_hba
.num_phys
) {
5556 kfree(ioc
->sas_hba
.phy
);
5557 ioc
->sas_hba
.phy
= NULL
;
5558 ioc
->sas_hba
.num_phys
= 0;
5561 sas_remove_host(shost
);
5562 mpt2sas_base_detach(ioc
);
5563 list_del(&ioc
->list
);
5564 scsi_remove_host(shost
);
5565 scsi_host_put(shost
);
5569 * _scsih_probe_boot_devices - reports 1st device
5570 * @ioc: per adapter object
5572 * If specified in bios page 2, this routine reports the 1st
5573 * device scsi-ml or sas transport for persistent boot device
5574 * purposes. Please refer to function _scsih_determine_boot_device()
5577 _scsih_probe_boot_devices(struct MPT2SAS_ADAPTER
*ioc
)
5581 struct _sas_device
*sas_device
;
5582 struct _raid_device
*raid_device
;
5583 u16 handle
, parent_handle
;
5585 unsigned long flags
;
5589 if (ioc
->req_boot_device
.device
) {
5590 device
= ioc
->req_boot_device
.device
;
5591 is_raid
= ioc
->req_boot_device
.is_raid
;
5592 } else if (ioc
->req_alt_boot_device
.device
) {
5593 device
= ioc
->req_alt_boot_device
.device
;
5594 is_raid
= ioc
->req_alt_boot_device
.is_raid
;
5595 } else if (ioc
->current_boot_device
.device
) {
5596 device
= ioc
->current_boot_device
.device
;
5597 is_raid
= ioc
->current_boot_device
.is_raid
;
5604 raid_device
= device
;
5605 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
5606 raid_device
->id
, 0);
5608 _scsih_raid_device_remove(ioc
, raid_device
);
5610 sas_device
= device
;
5611 handle
= sas_device
->handle
;
5612 parent_handle
= sas_device
->parent_handle
;
5613 sas_address
= sas_device
->sas_address
;
5614 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5615 list_move_tail(&sas_device
->list
, &ioc
->sas_device_list
);
5616 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5617 if (!mpt2sas_transport_port_add(ioc
, sas_device
->handle
,
5618 sas_device
->parent_handle
)) {
5619 _scsih_sas_device_remove(ioc
, sas_device
);
5620 } else if (!sas_device
->starget
) {
5621 mpt2sas_transport_port_remove(ioc
, sas_address
,
5623 _scsih_sas_device_remove(ioc
, sas_device
);
5629 * _scsih_probe_raid - reporting raid volumes to scsi-ml
5630 * @ioc: per adapter object
5632 * Called during initial loading of the driver.
5635 _scsih_probe_raid(struct MPT2SAS_ADAPTER
*ioc
)
5637 struct _raid_device
*raid_device
, *raid_next
;
5640 list_for_each_entry_safe(raid_device
, raid_next
,
5641 &ioc
->raid_device_list
, list
) {
5642 if (raid_device
->starget
)
5644 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
5645 raid_device
->id
, 0);
5647 _scsih_raid_device_remove(ioc
, raid_device
);
5652 * _scsih_probe_sas - reporting raid volumes to sas transport
5653 * @ioc: per adapter object
5655 * Called during initial loading of the driver.
5658 _scsih_probe_sas(struct MPT2SAS_ADAPTER
*ioc
)
5660 struct _sas_device
*sas_device
, *next
;
5661 unsigned long flags
;
5662 u16 handle
, parent_handle
;
5665 /* SAS Device List */
5666 list_for_each_entry_safe(sas_device
, next
, &ioc
->sas_device_init_list
,
5668 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5669 list_move_tail(&sas_device
->list
, &ioc
->sas_device_list
);
5670 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5672 handle
= sas_device
->handle
;
5673 parent_handle
= sas_device
->parent_handle
;
5674 sas_address
= sas_device
->sas_address
;
5675 if (!mpt2sas_transport_port_add(ioc
, handle
, parent_handle
)) {
5676 _scsih_sas_device_remove(ioc
, sas_device
);
5677 } else if (!sas_device
->starget
) {
5678 mpt2sas_transport_port_remove(ioc
, sas_address
,
5680 _scsih_sas_device_remove(ioc
, sas_device
);
5686 * _scsih_probe_devices - probing for devices
5687 * @ioc: per adapter object
5689 * Called during initial loading of the driver.
5692 _scsih_probe_devices(struct MPT2SAS_ADAPTER
*ioc
)
5694 u16 volume_mapping_flags
=
5695 le16_to_cpu(ioc
->ioc_pg8
.IRVolumeMappingFlags
) &
5696 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE
;
5698 if (!(ioc
->facts
.ProtocolFlags
& MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR
))
5699 return; /* return when IOC doesn't support initiator mode */
5701 _scsih_probe_boot_devices(ioc
);
5703 if (ioc
->ir_firmware
) {
5704 if ((volume_mapping_flags
&
5705 MPI2_IOCPAGE8_IRFLAGS_HIGH_VOLUME_MAPPING
)) {
5706 _scsih_probe_sas(ioc
);
5707 _scsih_probe_raid(ioc
);
5709 _scsih_probe_raid(ioc
);
5710 _scsih_probe_sas(ioc
);
5713 _scsih_probe_sas(ioc
);
5717 * _scsih_probe - attach and add scsi host
5718 * @pdev: PCI device struct
5719 * @id: pci device id
5721 * Returns 0 success, anything else error.
5724 _scsih_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
5726 struct MPT2SAS_ADAPTER
*ioc
;
5727 struct Scsi_Host
*shost
;
5729 shost
= scsi_host_alloc(&scsih_driver_template
,
5730 sizeof(struct MPT2SAS_ADAPTER
));
5734 /* init local params */
5735 ioc
= shost_priv(shost
);
5736 memset(ioc
, 0, sizeof(struct MPT2SAS_ADAPTER
));
5737 INIT_LIST_HEAD(&ioc
->list
);
5738 list_add_tail(&ioc
->list
, &mpt2sas_ioc_list
);
5740 ioc
->id
= mpt_ids
++;
5741 sprintf(ioc
->name
, "%s%d", MPT2SAS_DRIVER_NAME
, ioc
->id
);
5743 ioc
->scsi_io_cb_idx
= scsi_io_cb_idx
;
5744 ioc
->tm_cb_idx
= tm_cb_idx
;
5745 ioc
->ctl_cb_idx
= ctl_cb_idx
;
5746 ioc
->base_cb_idx
= base_cb_idx
;
5747 ioc
->transport_cb_idx
= transport_cb_idx
;
5748 ioc
->config_cb_idx
= config_cb_idx
;
5749 ioc
->logging_level
= logging_level
;
5750 /* misc semaphores and spin locks */
5751 spin_lock_init(&ioc
->ioc_reset_in_progress_lock
);
5752 spin_lock_init(&ioc
->scsi_lookup_lock
);
5753 spin_lock_init(&ioc
->sas_device_lock
);
5754 spin_lock_init(&ioc
->sas_node_lock
);
5755 spin_lock_init(&ioc
->fw_event_lock
);
5756 spin_lock_init(&ioc
->raid_device_lock
);
5758 INIT_LIST_HEAD(&ioc
->sas_device_list
);
5759 INIT_LIST_HEAD(&ioc
->sas_device_init_list
);
5760 INIT_LIST_HEAD(&ioc
->sas_expander_list
);
5761 INIT_LIST_HEAD(&ioc
->fw_event_list
);
5762 INIT_LIST_HEAD(&ioc
->raid_device_list
);
5763 INIT_LIST_HEAD(&ioc
->sas_hba
.sas_port_list
);
5765 /* init shost parameters */
5766 shost
->max_cmd_len
= 16;
5767 shost
->max_lun
= max_lun
;
5768 shost
->transportt
= mpt2sas_transport_template
;
5769 shost
->unique_id
= ioc
->id
;
5771 if ((scsi_add_host(shost
, &pdev
->dev
))) {
5772 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5773 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5774 list_del(&ioc
->list
);
5775 goto out_add_shost_fail
;
5778 scsi_host_set_prot(shost
, SHOST_DIF_TYPE1_PROTECTION
5779 | SHOST_DIF_TYPE3_PROTECTION
);
5782 snprintf(ioc
->firmware_event_name
, sizeof(ioc
->firmware_event_name
),
5783 "fw_event%d", ioc
->id
);
5784 ioc
->firmware_event_thread
= create_singlethread_workqueue(
5785 ioc
->firmware_event_name
);
5786 if (!ioc
->firmware_event_thread
) {
5787 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5788 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5789 goto out_thread_fail
;
5792 ioc
->wait_for_port_enable_to_complete
= 1;
5793 if ((mpt2sas_base_attach(ioc
))) {
5794 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5795 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5796 goto out_attach_fail
;
5799 ioc
->wait_for_port_enable_to_complete
= 0;
5800 _scsih_probe_devices(ioc
);
5804 destroy_workqueue(ioc
->firmware_event_thread
);
5806 list_del(&ioc
->list
);
5807 scsi_remove_host(shost
);
5814 * _scsih_suspend - power management suspend main entry point
5815 * @pdev: PCI device struct
5816 * @state: PM state change to (usually PCI_D3)
5818 * Returns 0 success, anything else error.
5821 _scsih_suspend(struct pci_dev
*pdev
, pm_message_t state
)
5823 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
5824 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
5827 mpt2sas_base_stop_watchdog(ioc
);
5828 flush_scheduled_work();
5829 scsi_block_requests(shost
);
5830 device_state
= pci_choose_state(pdev
, state
);
5831 printk(MPT2SAS_INFO_FMT
"pdev=0x%p, slot=%s, entering "
5832 "operating state [D%d]\n", ioc
->name
, pdev
,
5833 pci_name(pdev
), device_state
);
5835 mpt2sas_base_free_resources(ioc
);
5836 pci_save_state(pdev
);
5837 pci_disable_device(pdev
);
5838 pci_set_power_state(pdev
, device_state
);
5843 * _scsih_resume - power management resume main entry point
5844 * @pdev: PCI device struct
5846 * Returns 0 success, anything else error.
5849 _scsih_resume(struct pci_dev
*pdev
)
5851 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
5852 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
5853 u32 device_state
= pdev
->current_state
;
5856 printk(MPT2SAS_INFO_FMT
"pdev=0x%p, slot=%s, previous "
5857 "operating state [D%d]\n", ioc
->name
, pdev
,
5858 pci_name(pdev
), device_state
);
5860 pci_set_power_state(pdev
, PCI_D0
);
5861 pci_enable_wake(pdev
, PCI_D0
, 0);
5862 pci_restore_state(pdev
);
5864 r
= mpt2sas_base_map_resources(ioc
);
5868 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
, SOFT_RESET
);
5869 scsi_unblock_requests(shost
);
5870 mpt2sas_base_start_watchdog(ioc
);
5873 #endif /* CONFIG_PM */
5876 static struct pci_driver scsih_driver
= {
5877 .name
= MPT2SAS_DRIVER_NAME
,
5878 .id_table
= scsih_pci_table
,
5879 .probe
= _scsih_probe
,
5880 .remove
= __devexit_p(_scsih_remove
),
5882 .suspend
= _scsih_suspend
,
5883 .resume
= _scsih_resume
,
5889 * _scsih_init - main entry point for this driver.
5891 * Returns 0 success, anything else error.
5899 printk(KERN_INFO
"%s version %s loaded\n", MPT2SAS_DRIVER_NAME
,
5900 MPT2SAS_DRIVER_VERSION
);
5902 mpt2sas_transport_template
=
5903 sas_attach_transport(&mpt2sas_transport_functions
);
5904 if (!mpt2sas_transport_template
)
5907 mpt2sas_base_initialize_callback_handler();
5909 /* queuecommand callback hander */
5910 scsi_io_cb_idx
= mpt2sas_base_register_callback_handler(_scsih_io_done
);
5912 /* task managment callback handler */
5913 tm_cb_idx
= mpt2sas_base_register_callback_handler(_scsih_tm_done
);
5915 /* base internal commands callback handler */
5916 base_cb_idx
= mpt2sas_base_register_callback_handler(mpt2sas_base_done
);
5918 /* transport internal commands callback handler */
5919 transport_cb_idx
= mpt2sas_base_register_callback_handler(
5920 mpt2sas_transport_done
);
5922 /* configuration page API internal commands callback handler */
5923 config_cb_idx
= mpt2sas_base_register_callback_handler(
5924 mpt2sas_config_done
);
5926 /* ctl module callback handler */
5927 ctl_cb_idx
= mpt2sas_base_register_callback_handler(mpt2sas_ctl_done
);
5931 error
= pci_register_driver(&scsih_driver
);
5933 sas_release_transport(mpt2sas_transport_template
);
5939 * _scsih_exit - exit point for this driver (when it is a module).
5941 * Returns 0 success, anything else error.
5946 printk(KERN_INFO
"mpt2sas version %s unloading\n",
5947 MPT2SAS_DRIVER_VERSION
);
5949 pci_unregister_driver(&scsih_driver
);
5951 sas_release_transport(mpt2sas_transport_template
);
5952 mpt2sas_base_release_callback_handler(scsi_io_cb_idx
);
5953 mpt2sas_base_release_callback_handler(tm_cb_idx
);
5954 mpt2sas_base_release_callback_handler(base_cb_idx
);
5955 mpt2sas_base_release_callback_handler(transport_cb_idx
);
5956 mpt2sas_base_release_callback_handler(config_cb_idx
);
5957 mpt2sas_base_release_callback_handler(ctl_cb_idx
);
5962 module_init(_scsih_init
);
5963 module_exit(_scsih_exit
);