2 * linux/drivers/message/fusion/mptsas.c
3 * For use with LSI Logic PCI chip/adapter(s)
4 * running LSI Logic Fusion MPT (Message Passing Technology) firmware.
6 * Copyright (c) 1999-2005 LSI Logic Corporation
7 * (mailto:mpt_linux_developer@lsil.com)
8 * Copyright (c) 2005-2006 Dell
10 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; version 2 of the License.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
22 THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
23 CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
24 LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
25 MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
26 solely responsible for determining the appropriateness of using and
27 distributing the Program and assumes all risks associated with its
28 exercise of rights under this Agreement, including but not limited to
29 the risks and costs of program errors, damage to or loss of data,
30 programs or equipment, and unavailability or interruption of operations.
32 DISCLAIMER OF LIABILITY
33 NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
34 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
35 DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
36 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
37 TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
38 USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
39 HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
41 You should have received a copy of the GNU General Public License
42 along with this program; if not, write to the Free Software
43 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
45 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
47 #include <linux/module.h>
48 #include <linux/kernel.h>
49 #include <linux/init.h>
50 #include <linux/errno.h>
51 #include <linux/sched.h>
52 #include <linux/workqueue.h>
53 #include <linux/delay.h> /* for mdelay */
55 #include <scsi/scsi.h>
56 #include <scsi/scsi_cmnd.h>
57 #include <scsi/scsi_device.h>
58 #include <scsi/scsi_host.h>
59 #include <scsi/scsi_transport_sas.h>
60 #include <scsi/scsi_dbg.h>
66 #define my_NAME "Fusion MPT SAS Host driver"
67 #define my_VERSION MPT_LINUX_VERSION_COMMON
68 #define MYNAM "mptsas"
70 MODULE_AUTHOR(MODULEAUTHOR
);
71 MODULE_DESCRIPTION(my_NAME
);
72 MODULE_LICENSE("GPL");
74 static int mpt_pq_filter
;
75 module_param(mpt_pq_filter
, int, 0);
76 MODULE_PARM_DESC(mpt_pq_filter
,
77 "Enable peripheral qualifier filter: enable=1 "
80 static int mpt_pt_clear
;
81 module_param(mpt_pt_clear
, int, 0);
82 MODULE_PARM_DESC(mpt_pt_clear
,
83 "Clear persistency table: enable=1 "
84 "(default=MPTSCSIH_PT_CLEAR=0)");
86 static int mptsasDoneCtx
= -1;
87 static int mptsasTaskCtx
= -1;
88 static int mptsasInternalCtx
= -1; /* Used only for internal commands */
89 static int mptsasMgmtCtx
= -1;
92 enum mptsas_hotplug_action
{
100 struct mptsas_hotplug_event
{
101 struct work_struct work
;
103 enum mptsas_hotplug_action event_type
;
112 u8 phys_disk_num_valid
;
115 struct mptsas_discovery_event
{
116 struct work_struct work
;
121 * SAS topology structures
123 * The MPT Fusion firmware interface spreads information about the
124 * SAS topology over many manufacture pages, thus we need some data
125 * structure to collect it and process it for the SAS transport class.
128 struct mptsas_devinfo
{
129 u16 handle
; /* unique id to address this device */
130 u16 handle_parent
; /* unique id to address parent device */
131 u16 handle_enclosure
; /* enclosure identifier of the enclosure */
132 u16 slot
; /* physical slot in enclosure */
133 u8 phy_id
; /* phy number of parent device */
134 u8 port_id
; /* sas physical port this device
136 u8 id
; /* logical target id of this device */
137 u8 channel
; /* logical bus number of this device */
138 u64 sas_address
; /* WWN of this device,
139 SATA is assigned by HBA,expander */
140 u32 device_info
; /* bitfield detailed info about this device */
144 * Specific details on ports, wide/narrow
146 struct mptsas_portinfo_details
{
147 u8 port_id
; /* port number provided to transport */
148 u16 num_phys
; /* number of phys belong to this port */
149 u64 phy_bitmask
; /* TODO, extend support for 255 phys */
150 struct sas_rphy
*rphy
; /* transport layer rphy object */
151 struct sas_port
*port
; /* transport layer port object */
152 struct scsi_target
*starget
;
153 struct mptsas_portinfo
*port_info
;
156 struct mptsas_phyinfo
{
157 u8 phy_id
; /* phy index */
158 u8 port_id
; /* firmware port identifier */
159 u8 negotiated_link_rate
; /* nego'd link rate for this phy */
160 u8 hw_link_rate
; /* hardware max/min phys link rate */
161 u8 programmed_link_rate
; /* programmed max/min phy link rate */
162 u8 sas_port_add_phy
; /* flag to request sas_port_add_phy*/
163 struct mptsas_devinfo identify
; /* point to phy device info */
164 struct mptsas_devinfo attached
; /* point to attached device info */
165 struct sas_phy
*phy
; /* transport layer phy object */
166 struct mptsas_portinfo
*portinfo
;
167 struct mptsas_portinfo_details
* port_details
;
170 struct mptsas_portinfo
{
171 struct list_head list
;
172 u16 handle
; /* unique id to address this */
173 u16 num_phys
; /* number of phys */
174 struct mptsas_phyinfo
*phy_info
;
177 struct mptsas_enclosure
{
178 u64 enclosure_logical_id
; /* The WWN for the enclosure */
179 u16 enclosure_handle
; /* unique id to address this */
180 u16 flags
; /* details enclosure management */
181 u16 num_slot
; /* num slots */
182 u16 start_slot
; /* first slot */
183 u8 start_id
; /* starting logical target id */
184 u8 start_channel
; /* starting logical channel id */
185 u8 sep_id
; /* SEP device logical target id */
186 u8 sep_channel
; /* SEP channel logical channel id */
190 static void mptsas_print_phy_data(MPI_SAS_IO_UNIT0_PHY_DATA
*phy_data
)
192 printk("---- IO UNIT PAGE 0 ------------\n");
193 printk("Handle=0x%X\n",
194 le16_to_cpu(phy_data
->AttachedDeviceHandle
));
195 printk("Controller Handle=0x%X\n",
196 le16_to_cpu(phy_data
->ControllerDevHandle
));
197 printk("Port=0x%X\n", phy_data
->Port
);
198 printk("Port Flags=0x%X\n", phy_data
->PortFlags
);
199 printk("PHY Flags=0x%X\n", phy_data
->PhyFlags
);
200 printk("Negotiated Link Rate=0x%X\n", phy_data
->NegotiatedLinkRate
);
201 printk("Controller PHY Device Info=0x%X\n",
202 le32_to_cpu(phy_data
->ControllerPhyDeviceInfo
));
203 printk("DiscoveryStatus=0x%X\n",
204 le32_to_cpu(phy_data
->DiscoveryStatus
));
208 static void mptsas_print_phy_pg0(SasPhyPage0_t
*pg0
)
212 memcpy(&sas_address
, &pg0
->SASAddress
, sizeof(__le64
));
214 printk("---- SAS PHY PAGE 0 ------------\n");
215 printk("Attached Device Handle=0x%X\n",
216 le16_to_cpu(pg0
->AttachedDevHandle
));
217 printk("SAS Address=0x%llX\n",
218 (unsigned long long)le64_to_cpu(sas_address
));
219 printk("Attached PHY Identifier=0x%X\n", pg0
->AttachedPhyIdentifier
);
220 printk("Attached Device Info=0x%X\n",
221 le32_to_cpu(pg0
->AttachedDeviceInfo
));
222 printk("Programmed Link Rate=0x%X\n", pg0
->ProgrammedLinkRate
);
223 printk("Change Count=0x%X\n", pg0
->ChangeCount
);
224 printk("PHY Info=0x%X\n", le32_to_cpu(pg0
->PhyInfo
));
228 static void mptsas_print_phy_pg1(SasPhyPage1_t
*pg1
)
230 printk("---- SAS PHY PAGE 1 ------------\n");
231 printk("Invalid Dword Count=0x%x\n", pg1
->InvalidDwordCount
);
232 printk("Running Disparity Error Count=0x%x\n",
233 pg1
->RunningDisparityErrorCount
);
234 printk("Loss Dword Synch Count=0x%x\n", pg1
->LossDwordSynchCount
);
235 printk("PHY Reset Problem Count=0x%x\n", pg1
->PhyResetProblemCount
);
239 static void mptsas_print_device_pg0(SasDevicePage0_t
*pg0
)
243 memcpy(&sas_address
, &pg0
->SASAddress
, sizeof(__le64
));
245 printk("---- SAS DEVICE PAGE 0 ---------\n");
246 printk("Handle=0x%X\n" ,le16_to_cpu(pg0
->DevHandle
));
247 printk("Parent Handle=0x%X\n" ,le16_to_cpu(pg0
->ParentDevHandle
));
248 printk("Enclosure Handle=0x%X\n", le16_to_cpu(pg0
->EnclosureHandle
));
249 printk("Slot=0x%X\n", le16_to_cpu(pg0
->Slot
));
250 printk("SAS Address=0x%llX\n", le64_to_cpu(sas_address
));
251 printk("Target ID=0x%X\n", pg0
->TargetID
);
252 printk("Bus=0x%X\n", pg0
->Bus
);
253 /* The PhyNum field specifies the PHY number of the parent
254 * device this device is linked to
256 printk("Parent Phy Num=0x%X\n", pg0
->PhyNum
);
257 printk("Access Status=0x%X\n", le16_to_cpu(pg0
->AccessStatus
));
258 printk("Device Info=0x%X\n", le32_to_cpu(pg0
->DeviceInfo
));
259 printk("Flags=0x%X\n", le16_to_cpu(pg0
->Flags
));
260 printk("Physical Port=0x%X\n", pg0
->PhysicalPort
);
264 static void mptsas_print_expander_pg1(SasExpanderPage1_t
*pg1
)
266 printk("---- SAS EXPANDER PAGE 1 ------------\n");
268 printk("Physical Port=0x%X\n", pg1
->PhysicalPort
);
269 printk("PHY Identifier=0x%X\n", pg1
->PhyIdentifier
);
270 printk("Negotiated Link Rate=0x%X\n", pg1
->NegotiatedLinkRate
);
271 printk("Programmed Link Rate=0x%X\n", pg1
->ProgrammedLinkRate
);
272 printk("Hardware Link Rate=0x%X\n", pg1
->HwLinkRate
);
273 printk("Owner Device Handle=0x%X\n",
274 le16_to_cpu(pg1
->OwnerDevHandle
));
275 printk("Attached Device Handle=0x%X\n",
276 le16_to_cpu(pg1
->AttachedDevHandle
));
279 #define mptsas_print_phy_data(phy_data) do { } while (0)
280 #define mptsas_print_phy_pg0(pg0) do { } while (0)
281 #define mptsas_print_phy_pg1(pg1) do { } while (0)
282 #define mptsas_print_device_pg0(pg0) do { } while (0)
283 #define mptsas_print_expander_pg1(pg1) do { } while (0)
286 static inline MPT_ADAPTER
*phy_to_ioc(struct sas_phy
*phy
)
288 struct Scsi_Host
*shost
= dev_to_shost(phy
->dev
.parent
);
289 return ((MPT_SCSI_HOST
*)shost
->hostdata
)->ioc
;
292 static inline MPT_ADAPTER
*rphy_to_ioc(struct sas_rphy
*rphy
)
294 struct Scsi_Host
*shost
= dev_to_shost(rphy
->dev
.parent
->parent
);
295 return ((MPT_SCSI_HOST
*)shost
->hostdata
)->ioc
;
299 * mptsas_find_portinfo_by_handle
301 * This function should be called with the sas_topology_mutex already held
303 static struct mptsas_portinfo
*
304 mptsas_find_portinfo_by_handle(MPT_ADAPTER
*ioc
, u16 handle
)
306 struct mptsas_portinfo
*port_info
, *rc
=NULL
;
309 list_for_each_entry(port_info
, &ioc
->sas_topology
, list
)
310 for (i
= 0; i
< port_info
->num_phys
; i
++)
311 if (port_info
->phy_info
[i
].identify
.handle
== handle
) {
320 * Returns true if there is a scsi end device
323 mptsas_is_end_device(struct mptsas_devinfo
* attached
)
325 if ((attached
->sas_address
) &&
326 (attached
->device_info
&
327 MPI_SAS_DEVICE_INFO_END_DEVICE
) &&
328 ((attached
->device_info
&
329 MPI_SAS_DEVICE_INFO_SSP_TARGET
) |
330 (attached
->device_info
&
331 MPI_SAS_DEVICE_INFO_STP_TARGET
) |
332 (attached
->device_info
&
333 MPI_SAS_DEVICE_INFO_SATA_DEVICE
)))
341 mptsas_port_delete(struct mptsas_portinfo_details
* port_details
)
343 struct mptsas_portinfo
*port_info
;
344 struct mptsas_phyinfo
*phy_info
;
350 port_info
= port_details
->port_info
;
351 phy_info
= port_info
->phy_info
;
353 dsaswideprintk((KERN_DEBUG
"%s: [%p]: port=%02d num_phys=%02d "
354 "bitmask=0x%016llX\n",
355 __FUNCTION__
, port_details
, port_details
->port_id
,
356 port_details
->num_phys
, port_details
->phy_bitmask
));
358 for (i
= 0; i
< port_info
->num_phys
; i
++, phy_info
++) {
359 if(phy_info
->port_details
!= port_details
)
361 memset(&phy_info
->attached
, 0, sizeof(struct mptsas_devinfo
));
362 phy_info
->port_details
= NULL
;
367 static inline struct sas_rphy
*
368 mptsas_get_rphy(struct mptsas_phyinfo
*phy_info
)
370 if (phy_info
->port_details
)
371 return phy_info
->port_details
->rphy
;
377 mptsas_set_rphy(struct mptsas_phyinfo
*phy_info
, struct sas_rphy
*rphy
)
379 if (phy_info
->port_details
) {
380 phy_info
->port_details
->rphy
= rphy
;
381 dsaswideprintk((KERN_DEBUG
"sas_rphy_add: rphy=%p\n", rphy
));
384 #ifdef MPT_DEBUG_SAS_WIDE
386 dev_printk(KERN_DEBUG
, &rphy
->dev
, "add:");
387 printk("rphy=%p release=%p\n",
388 rphy
, rphy
->dev
.release
);
393 static inline struct sas_port
*
394 mptsas_get_port(struct mptsas_phyinfo
*phy_info
)
396 if (phy_info
->port_details
)
397 return phy_info
->port_details
->port
;
403 mptsas_set_port(struct mptsas_phyinfo
*phy_info
, struct sas_port
*port
)
405 if (phy_info
->port_details
)
406 phy_info
->port_details
->port
= port
;
408 #ifdef MPT_DEBUG_SAS_WIDE
410 dev_printk(KERN_DEBUG
, &port
->dev
, "add: ");
411 printk("port=%p release=%p\n",
412 port
, port
->dev
.release
);
417 static inline struct scsi_target
*
418 mptsas_get_starget(struct mptsas_phyinfo
*phy_info
)
420 if (phy_info
->port_details
)
421 return phy_info
->port_details
->starget
;
427 mptsas_set_starget(struct mptsas_phyinfo
*phy_info
, struct scsi_target
*
430 if (phy_info
->port_details
)
431 phy_info
->port_details
->starget
= starget
;
436 * mptsas_setup_wide_ports
438 * Updates for new and existing narrow/wide port configuration
439 * in the sas_topology
442 mptsas_setup_wide_ports(MPT_ADAPTER
*ioc
, struct mptsas_portinfo
*port_info
)
444 struct mptsas_portinfo_details
* port_details
;
445 struct mptsas_phyinfo
*phy_info
, *phy_info_cmp
;
449 mutex_lock(&ioc
->sas_topology_mutex
);
451 phy_info
= port_info
->phy_info
;
452 for (i
= 0 ; i
< port_info
->num_phys
; i
++, phy_info
++) {
453 if (phy_info
->attached
.handle
)
455 port_details
= phy_info
->port_details
;
458 if (port_details
->num_phys
< 2)
461 * Removing a phy from a port, letting the last
462 * phy be removed by firmware events.
464 dsaswideprintk((KERN_DEBUG
465 "%s: [%p]: port=%d deleting phy = %d\n",
466 __FUNCTION__
, port_details
,
467 port_details
->port_id
, i
));
468 port_details
->num_phys
--;
469 port_details
->phy_bitmask
&= ~ (1 << phy_info
->phy_id
);
470 memset(&phy_info
->attached
, 0, sizeof(struct mptsas_devinfo
));
471 sas_port_delete_phy(port_details
->port
, phy_info
->phy
);
472 phy_info
->port_details
= NULL
;
476 * Populate and refresh the tree
478 phy_info
= port_info
->phy_info
;
479 for (i
= 0 ; i
< port_info
->num_phys
; i
++, phy_info
++) {
480 sas_address
= phy_info
->attached
.sas_address
;
481 dsaswideprintk((KERN_DEBUG
"phy_id=%d sas_address=0x%018llX\n",
485 port_details
= phy_info
->port_details
;
490 port_details
= kzalloc(sizeof(*port_details
),
494 port_details
->num_phys
= 1;
495 port_details
->port_info
= port_info
;
496 port_details
->port_id
= ioc
->port_serial_number
++;
497 if (phy_info
->phy_id
< 64 )
498 port_details
->phy_bitmask
|=
499 (1 << phy_info
->phy_id
);
500 phy_info
->sas_port_add_phy
=1;
501 dsaswideprintk((KERN_DEBUG
"\t\tForming port\n\t\t"
502 "phy_id=%d sas_address=0x%018llX\n",
504 phy_info
->port_details
= port_details
;
507 if (i
== port_info
->num_phys
- 1)
509 phy_info_cmp
= &port_info
->phy_info
[i
+ 1];
510 for (j
= i
+ 1 ; j
< port_info
->num_phys
; j
++,
512 if (!phy_info_cmp
->attached
.sas_address
)
514 if (sas_address
!= phy_info_cmp
->attached
.sas_address
)
516 if (phy_info_cmp
->port_details
== port_details
)
518 dsaswideprintk((KERN_DEBUG
519 "\t\tphy_id=%d sas_address=0x%018llX\n",
520 j
, phy_info_cmp
->attached
.sas_address
));
521 if (phy_info_cmp
->port_details
) {
523 mptsas_get_rphy(phy_info_cmp
);
525 mptsas_get_port(phy_info_cmp
);
526 port_details
->starget
=
527 mptsas_get_starget(phy_info_cmp
);
528 port_details
->port_id
=
529 phy_info_cmp
->port_details
->port_id
;
530 port_details
->num_phys
=
531 phy_info_cmp
->port_details
->num_phys
;
532 // port_info->port_serial_number--;
533 ioc
->port_serial_number
--;
534 if (!phy_info_cmp
->port_details
->num_phys
)
535 kfree(phy_info_cmp
->port_details
);
537 phy_info_cmp
->sas_port_add_phy
=1;
539 * Adding a phy to a port
541 phy_info_cmp
->port_details
= port_details
;
542 if (phy_info_cmp
->phy_id
< 64 )
543 port_details
->phy_bitmask
|=
544 (1 << phy_info_cmp
->phy_id
);
545 port_details
->num_phys
++;
551 #ifdef MPT_DEBUG_SAS_WIDE
552 for (i
= 0; i
< port_info
->num_phys
; i
++) {
553 port_details
= port_info
->phy_info
[i
].port_details
;
556 dsaswideprintk((KERN_DEBUG
557 "%s: [%p]: phy_id=%02d port_id=%02d num_phys=%02d "
558 "bitmask=0x%016llX\n",
560 port_details
, i
, port_details
->port_id
,
561 port_details
->num_phys
, port_details
->phy_bitmask
));
562 dsaswideprintk((KERN_DEBUG
"\t\tport = %p rphy=%p\n",
563 port_details
->port
, port_details
->rphy
));
565 dsaswideprintk((KERN_DEBUG
"\n"));
567 mutex_unlock(&ioc
->sas_topology_mutex
);
571 mptsas_target_reset(MPT_ADAPTER
*ioc
, VirtTarget
* vtarget
)
573 MPT_SCSI_HOST
*hd
= (MPT_SCSI_HOST
*)ioc
->sh
->hostdata
;
575 if (mptscsih_TMHandler(hd
,
576 MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET
,
577 vtarget
->bus_id
, vtarget
->target_id
, 0, 0, 5) < 0) {
579 hd
->tmState
= TM_STATE_NONE
;
580 printk(MYIOC_s_WARN_FMT
581 "Error processing TaskMgmt id=%d TARGET_RESET\n",
582 ioc
->name
, vtarget
->target_id
);
587 mptsas_sas_enclosure_pg0(MPT_ADAPTER
*ioc
, struct mptsas_enclosure
*enclosure
,
588 u32 form
, u32 form_specific
)
590 ConfigExtendedPageHeader_t hdr
;
592 SasEnclosurePage0_t
*buffer
;
593 dma_addr_t dma_handle
;
595 __le64 le_identifier
;
597 memset(&hdr
, 0, sizeof(hdr
));
598 hdr
.PageVersion
= MPI_SASENCLOSURE0_PAGEVERSION
;
600 hdr
.PageType
= MPI_CONFIG_PAGETYPE_EXTENDED
;
601 hdr
.ExtPageType
= MPI_CONFIG_EXTPAGETYPE_ENCLOSURE
;
603 cfg
.cfghdr
.ehdr
= &hdr
;
605 cfg
.pageAddr
= form
+ form_specific
;
606 cfg
.action
= MPI_CONFIG_ACTION_PAGE_HEADER
;
607 cfg
.dir
= 0; /* read */
610 error
= mpt_config(ioc
, &cfg
);
613 if (!hdr
.ExtPageLength
) {
618 buffer
= pci_alloc_consistent(ioc
->pcidev
, hdr
.ExtPageLength
* 4,
625 cfg
.physAddr
= dma_handle
;
626 cfg
.action
= MPI_CONFIG_ACTION_PAGE_READ_CURRENT
;
628 error
= mpt_config(ioc
, &cfg
);
630 goto out_free_consistent
;
632 /* save config data */
633 memcpy(&le_identifier
, &buffer
->EnclosureLogicalID
, sizeof(__le64
));
634 enclosure
->enclosure_logical_id
= le64_to_cpu(le_identifier
);
635 enclosure
->enclosure_handle
= le16_to_cpu(buffer
->EnclosureHandle
);
636 enclosure
->flags
= le16_to_cpu(buffer
->Flags
);
637 enclosure
->num_slot
= le16_to_cpu(buffer
->NumSlots
);
638 enclosure
->start_slot
= le16_to_cpu(buffer
->StartSlot
);
639 enclosure
->start_id
= buffer
->StartTargetID
;
640 enclosure
->start_channel
= buffer
->StartBus
;
641 enclosure
->sep_id
= buffer
->SEPTargetID
;
642 enclosure
->sep_channel
= buffer
->SEPBus
;
645 pci_free_consistent(ioc
->pcidev
, hdr
.ExtPageLength
* 4,
652 mptsas_slave_configure(struct scsi_device
*sdev
)
654 struct Scsi_Host
*host
= sdev
->host
;
655 MPT_SCSI_HOST
*hd
= (MPT_SCSI_HOST
*)host
->hostdata
;
658 * RAID volumes placed beyond the last expected port.
659 * Ignore sending sas mode pages in that case..
661 if (sdev
->channel
< hd
->ioc
->num_ports
)
662 sas_read_port_mode_page(sdev
);
664 return mptscsih_slave_configure(sdev
);
668 mptsas_target_alloc(struct scsi_target
*starget
)
670 struct Scsi_Host
*host
= dev_to_shost(&starget
->dev
);
671 MPT_SCSI_HOST
*hd
= (MPT_SCSI_HOST
*)host
->hostdata
;
675 struct sas_rphy
*rphy
;
676 struct mptsas_portinfo
*p
;
679 vtarget
= kzalloc(sizeof(VirtTarget
), GFP_KERNEL
);
683 vtarget
->starget
= starget
;
684 vtarget
->ioc_id
= hd
->ioc
->id
;
685 vtarget
->tflags
= MPT_TARGET_FLAGS_Q_YES
|MPT_TARGET_FLAGS_VALID_INQUIRY
;
687 target_id
= starget
->id
;
690 hd
->Targets
[target_id
] = vtarget
;
693 * RAID volumes placed beyond the last expected port.
695 if (starget
->channel
== hd
->ioc
->num_ports
)
698 rphy
= dev_to_rphy(starget
->dev
.parent
);
699 mutex_lock(&hd
->ioc
->sas_topology_mutex
);
700 list_for_each_entry(p
, &hd
->ioc
->sas_topology
, list
) {
701 for (i
= 0; i
< p
->num_phys
; i
++) {
702 if (p
->phy_info
[i
].attached
.sas_address
!=
703 rphy
->identify
.sas_address
)
705 target_id
= p
->phy_info
[i
].attached
.id
;
706 channel
= p
->phy_info
[i
].attached
.channel
;
707 mptsas_set_starget(&p
->phy_info
[i
], starget
);
710 * Exposing hidden raid components
712 if (mptscsih_is_phys_disk(hd
->ioc
, target_id
)) {
713 target_id
= mptscsih_raid_id_to_num(hd
,
716 MPT_TARGET_FLAGS_RAID_COMPONENT
;
718 mutex_unlock(&hd
->ioc
->sas_topology_mutex
);
722 mutex_unlock(&hd
->ioc
->sas_topology_mutex
);
728 vtarget
->target_id
= target_id
;
729 vtarget
->bus_id
= channel
;
730 starget
->hostdata
= vtarget
;
735 mptsas_target_destroy(struct scsi_target
*starget
)
737 struct Scsi_Host
*host
= dev_to_shost(&starget
->dev
);
738 MPT_SCSI_HOST
*hd
= (MPT_SCSI_HOST
*)host
->hostdata
;
739 struct sas_rphy
*rphy
;
740 struct mptsas_portinfo
*p
;
743 if (!starget
->hostdata
)
746 if (starget
->channel
== hd
->ioc
->num_ports
)
749 rphy
= dev_to_rphy(starget
->dev
.parent
);
750 list_for_each_entry(p
, &hd
->ioc
->sas_topology
, list
) {
751 for (i
= 0; i
< p
->num_phys
; i
++) {
752 if (p
->phy_info
[i
].attached
.sas_address
!=
753 rphy
->identify
.sas_address
)
755 mptsas_set_starget(&p
->phy_info
[i
], NULL
);
761 kfree(starget
->hostdata
);
762 starget
->hostdata
= NULL
;
767 mptsas_slave_alloc(struct scsi_device
*sdev
)
769 struct Scsi_Host
*host
= sdev
->host
;
770 MPT_SCSI_HOST
*hd
= (MPT_SCSI_HOST
*)host
->hostdata
;
771 struct sas_rphy
*rphy
;
772 struct mptsas_portinfo
*p
;
774 struct scsi_target
*starget
;
777 vdev
= kzalloc(sizeof(VirtDevice
), GFP_KERNEL
);
779 printk(MYIOC_s_ERR_FMT
"slave_alloc kzalloc(%zd) FAILED!\n",
780 hd
->ioc
->name
, sizeof(VirtDevice
));
783 starget
= scsi_target(sdev
);
784 vdev
->vtarget
= starget
->hostdata
;
787 * RAID volumes placed beyond the last expected port.
789 if (sdev
->channel
== hd
->ioc
->num_ports
)
792 rphy
= dev_to_rphy(sdev
->sdev_target
->dev
.parent
);
793 mutex_lock(&hd
->ioc
->sas_topology_mutex
);
794 list_for_each_entry(p
, &hd
->ioc
->sas_topology
, list
) {
795 for (i
= 0; i
< p
->num_phys
; i
++) {
796 if (p
->phy_info
[i
].attached
.sas_address
!=
797 rphy
->identify
.sas_address
)
799 vdev
->lun
= sdev
->lun
;
801 * Exposing hidden raid components
803 if (mptscsih_is_phys_disk(hd
->ioc
,
804 p
->phy_info
[i
].attached
.id
))
805 sdev
->no_uld_attach
= 1;
806 mutex_unlock(&hd
->ioc
->sas_topology_mutex
);
810 mutex_unlock(&hd
->ioc
->sas_topology_mutex
);
816 vdev
->vtarget
->num_luns
++;
817 sdev
->hostdata
= vdev
;
822 mptsas_qcmd(struct scsi_cmnd
*SCpnt
, void (*done
)(struct scsi_cmnd
*))
824 VirtDevice
*vdev
= SCpnt
->device
->hostdata
;
826 // scsi_print_command(SCpnt);
827 if (vdev
->vtarget
->deleted
) {
828 SCpnt
->result
= DID_NO_CONNECT
<< 16;
833 return mptscsih_qcmd(SCpnt
,done
);
837 static struct scsi_host_template mptsas_driver_template
= {
838 .module
= THIS_MODULE
,
839 .proc_name
= "mptsas",
840 .proc_info
= mptscsih_proc_info
,
841 .name
= "MPT SPI Host",
842 .info
= mptscsih_info
,
843 .queuecommand
= mptsas_qcmd
,
844 .target_alloc
= mptsas_target_alloc
,
845 .slave_alloc
= mptsas_slave_alloc
,
846 .slave_configure
= mptsas_slave_configure
,
847 .target_destroy
= mptsas_target_destroy
,
848 .slave_destroy
= mptscsih_slave_destroy
,
849 .change_queue_depth
= mptscsih_change_queue_depth
,
850 .eh_abort_handler
= mptscsih_abort
,
851 .eh_device_reset_handler
= mptscsih_dev_reset
,
852 .eh_bus_reset_handler
= mptscsih_bus_reset
,
853 .eh_host_reset_handler
= mptscsih_host_reset
,
854 .bios_param
= mptscsih_bios_param
,
855 .can_queue
= MPT_FC_CAN_QUEUE
,
857 .sg_tablesize
= MPT_SCSI_SG_DEPTH
,
860 .use_clustering
= ENABLE_CLUSTERING
,
863 static int mptsas_get_linkerrors(struct sas_phy
*phy
)
865 MPT_ADAPTER
*ioc
= phy_to_ioc(phy
);
866 ConfigExtendedPageHeader_t hdr
;
868 SasPhyPage1_t
*buffer
;
869 dma_addr_t dma_handle
;
872 hdr
.PageVersion
= MPI_SASPHY1_PAGEVERSION
;
873 hdr
.ExtPageLength
= 0;
874 hdr
.PageNumber
= 1 /* page number 1*/;
877 hdr
.PageType
= MPI_CONFIG_PAGETYPE_EXTENDED
;
878 hdr
.ExtPageType
= MPI_CONFIG_EXTPAGETYPE_SAS_PHY
;
880 cfg
.cfghdr
.ehdr
= &hdr
;
882 cfg
.pageAddr
= phy
->identify
.phy_identifier
;
883 cfg
.action
= MPI_CONFIG_ACTION_PAGE_HEADER
;
884 cfg
.dir
= 0; /* read */
887 error
= mpt_config(ioc
, &cfg
);
890 if (!hdr
.ExtPageLength
)
893 buffer
= pci_alloc_consistent(ioc
->pcidev
, hdr
.ExtPageLength
* 4,
898 cfg
.physAddr
= dma_handle
;
899 cfg
.action
= MPI_CONFIG_ACTION_PAGE_READ_CURRENT
;
901 error
= mpt_config(ioc
, &cfg
);
903 goto out_free_consistent
;
905 mptsas_print_phy_pg1(buffer
);
907 phy
->invalid_dword_count
= le32_to_cpu(buffer
->InvalidDwordCount
);
908 phy
->running_disparity_error_count
=
909 le32_to_cpu(buffer
->RunningDisparityErrorCount
);
910 phy
->loss_of_dword_sync_count
=
911 le32_to_cpu(buffer
->LossDwordSynchCount
);
912 phy
->phy_reset_problem_count
=
913 le32_to_cpu(buffer
->PhyResetProblemCount
);
916 pci_free_consistent(ioc
->pcidev
, hdr
.ExtPageLength
* 4,
921 static int mptsas_mgmt_done(MPT_ADAPTER
*ioc
, MPT_FRAME_HDR
*req
,
922 MPT_FRAME_HDR
*reply
)
924 ioc
->sas_mgmt
.status
|= MPT_SAS_MGMT_STATUS_COMMAND_GOOD
;
926 ioc
->sas_mgmt
.status
|= MPT_SAS_MGMT_STATUS_RF_VALID
;
927 memcpy(ioc
->sas_mgmt
.reply
, reply
,
928 min(ioc
->reply_sz
, 4 * reply
->u
.reply
.MsgLength
));
930 complete(&ioc
->sas_mgmt
.done
);
934 static int mptsas_phy_reset(struct sas_phy
*phy
, int hard_reset
)
936 MPT_ADAPTER
*ioc
= phy_to_ioc(phy
);
937 SasIoUnitControlRequest_t
*req
;
938 SasIoUnitControlReply_t
*reply
;
941 unsigned long timeleft
;
942 int error
= -ERESTARTSYS
;
944 /* not implemented for expanders */
945 if (phy
->identify
.target_port_protocols
& SAS_PROTOCOL_SMP
)
948 if (mutex_lock_interruptible(&ioc
->sas_mgmt
.mutex
))
951 mf
= mpt_get_msg_frame(mptsasMgmtCtx
, ioc
);
957 hdr
= (MPIHeader_t
*) mf
;
958 req
= (SasIoUnitControlRequest_t
*)mf
;
959 memset(req
, 0, sizeof(SasIoUnitControlRequest_t
));
960 req
->Function
= MPI_FUNCTION_SAS_IO_UNIT_CONTROL
;
961 req
->MsgContext
= hdr
->MsgContext
;
962 req
->Operation
= hard_reset
?
963 MPI_SAS_OP_PHY_HARD_RESET
: MPI_SAS_OP_PHY_LINK_RESET
;
964 req
->PhyNum
= phy
->identify
.phy_identifier
;
966 mpt_put_msg_frame(mptsasMgmtCtx
, ioc
, mf
);
968 timeleft
= wait_for_completion_timeout(&ioc
->sas_mgmt
.done
,
971 /* On timeout reset the board */
972 mpt_free_msg_frame(ioc
, mf
);
973 mpt_HardResetHandler(ioc
, CAN_SLEEP
);
978 /* a reply frame is expected */
979 if ((ioc
->sas_mgmt
.status
&
980 MPT_IOCTL_STATUS_RF_VALID
) == 0) {
985 /* process the completed Reply Message Frame */
986 reply
= (SasIoUnitControlReply_t
*)ioc
->sas_mgmt
.reply
;
987 if (reply
->IOCStatus
!= MPI_IOCSTATUS_SUCCESS
) {
988 printk("%s: IOCStatus=0x%X IOCLogInfo=0x%X\n",
999 mutex_unlock(&ioc
->sas_mgmt
.mutex
);
1005 mptsas_get_enclosure_identifier(struct sas_rphy
*rphy
, u64
*identifier
)
1007 MPT_ADAPTER
*ioc
= rphy_to_ioc(rphy
);
1009 struct mptsas_portinfo
*p
;
1010 struct mptsas_enclosure enclosure_info
;
1011 u64 enclosure_handle
;
1013 mutex_lock(&ioc
->sas_topology_mutex
);
1014 list_for_each_entry(p
, &ioc
->sas_topology
, list
) {
1015 for (i
= 0; i
< p
->num_phys
; i
++) {
1016 if (p
->phy_info
[i
].attached
.sas_address
==
1017 rphy
->identify
.sas_address
) {
1018 enclosure_handle
= p
->phy_info
[i
].
1019 attached
.handle_enclosure
;
1024 mutex_unlock(&ioc
->sas_topology_mutex
);
1028 mutex_unlock(&ioc
->sas_topology_mutex
);
1029 memset(&enclosure_info
, 0, sizeof(struct mptsas_enclosure
));
1030 error
= mptsas_sas_enclosure_pg0(ioc
, &enclosure_info
,
1031 (MPI_SAS_ENCLOS_PGAD_FORM_HANDLE
<<
1032 MPI_SAS_ENCLOS_PGAD_FORM_SHIFT
), enclosure_handle
);
1034 *identifier
= enclosure_info
.enclosure_logical_id
;
1039 mptsas_get_bay_identifier(struct sas_rphy
*rphy
)
1041 MPT_ADAPTER
*ioc
= rphy_to_ioc(rphy
);
1042 struct mptsas_portinfo
*p
;
1045 mutex_lock(&ioc
->sas_topology_mutex
);
1046 list_for_each_entry(p
, &ioc
->sas_topology
, list
) {
1047 for (i
= 0; i
< p
->num_phys
; i
++) {
1048 if (p
->phy_info
[i
].attached
.sas_address
==
1049 rphy
->identify
.sas_address
) {
1050 rc
= p
->phy_info
[i
].attached
.slot
;
1057 mutex_unlock(&ioc
->sas_topology_mutex
);
1061 static struct sas_function_template mptsas_transport_functions
= {
1062 .get_linkerrors
= mptsas_get_linkerrors
,
1063 .get_enclosure_identifier
= mptsas_get_enclosure_identifier
,
1064 .get_bay_identifier
= mptsas_get_bay_identifier
,
1065 .phy_reset
= mptsas_phy_reset
,
1068 static struct scsi_transport_template
*mptsas_transport_template
;
1071 mptsas_sas_io_unit_pg0(MPT_ADAPTER
*ioc
, struct mptsas_portinfo
*port_info
)
1073 ConfigExtendedPageHeader_t hdr
;
1075 SasIOUnitPage0_t
*buffer
;
1076 dma_addr_t dma_handle
;
1079 hdr
.PageVersion
= MPI_SASIOUNITPAGE0_PAGEVERSION
;
1080 hdr
.ExtPageLength
= 0;
1084 hdr
.PageType
= MPI_CONFIG_PAGETYPE_EXTENDED
;
1085 hdr
.ExtPageType
= MPI_CONFIG_EXTPAGETYPE_SAS_IO_UNIT
;
1087 cfg
.cfghdr
.ehdr
= &hdr
;
1090 cfg
.action
= MPI_CONFIG_ACTION_PAGE_HEADER
;
1091 cfg
.dir
= 0; /* read */
1094 error
= mpt_config(ioc
, &cfg
);
1097 if (!hdr
.ExtPageLength
) {
1102 buffer
= pci_alloc_consistent(ioc
->pcidev
, hdr
.ExtPageLength
* 4,
1109 cfg
.physAddr
= dma_handle
;
1110 cfg
.action
= MPI_CONFIG_ACTION_PAGE_READ_CURRENT
;
1112 error
= mpt_config(ioc
, &cfg
);
1114 goto out_free_consistent
;
1116 port_info
->num_phys
= buffer
->NumPhys
;
1117 port_info
->phy_info
= kcalloc(port_info
->num_phys
,
1118 sizeof(*port_info
->phy_info
),GFP_KERNEL
);
1119 if (!port_info
->phy_info
) {
1121 goto out_free_consistent
;
1124 if (port_info
->num_phys
)
1126 le16_to_cpu(buffer
->PhyData
[0].ControllerDevHandle
);
1127 for (i
= 0; i
< port_info
->num_phys
; i
++) {
1128 mptsas_print_phy_data(&buffer
->PhyData
[i
]);
1129 port_info
->phy_info
[i
].phy_id
= i
;
1130 port_info
->phy_info
[i
].port_id
=
1131 buffer
->PhyData
[i
].Port
;
1132 port_info
->phy_info
[i
].negotiated_link_rate
=
1133 buffer
->PhyData
[i
].NegotiatedLinkRate
;
1134 port_info
->phy_info
[i
].portinfo
= port_info
;
1137 out_free_consistent
:
1138 pci_free_consistent(ioc
->pcidev
, hdr
.ExtPageLength
* 4,
1139 buffer
, dma_handle
);
1145 mptsas_sas_phy_pg0(MPT_ADAPTER
*ioc
, struct mptsas_phyinfo
*phy_info
,
1146 u32 form
, u32 form_specific
)
1148 ConfigExtendedPageHeader_t hdr
;
1150 SasPhyPage0_t
*buffer
;
1151 dma_addr_t dma_handle
;
1154 hdr
.PageVersion
= MPI_SASPHY0_PAGEVERSION
;
1155 hdr
.ExtPageLength
= 0;
1159 hdr
.PageType
= MPI_CONFIG_PAGETYPE_EXTENDED
;
1160 hdr
.ExtPageType
= MPI_CONFIG_EXTPAGETYPE_SAS_PHY
;
1162 cfg
.cfghdr
.ehdr
= &hdr
;
1163 cfg
.dir
= 0; /* read */
1166 /* Get Phy Pg 0 for each Phy. */
1168 cfg
.pageAddr
= form
+ form_specific
;
1169 cfg
.action
= MPI_CONFIG_ACTION_PAGE_HEADER
;
1171 error
= mpt_config(ioc
, &cfg
);
1175 if (!hdr
.ExtPageLength
) {
1180 buffer
= pci_alloc_consistent(ioc
->pcidev
, hdr
.ExtPageLength
* 4,
1187 cfg
.physAddr
= dma_handle
;
1188 cfg
.action
= MPI_CONFIG_ACTION_PAGE_READ_CURRENT
;
1190 error
= mpt_config(ioc
, &cfg
);
1192 goto out_free_consistent
;
1194 mptsas_print_phy_pg0(buffer
);
1196 phy_info
->hw_link_rate
= buffer
->HwLinkRate
;
1197 phy_info
->programmed_link_rate
= buffer
->ProgrammedLinkRate
;
1198 phy_info
->identify
.handle
= le16_to_cpu(buffer
->OwnerDevHandle
);
1199 phy_info
->attached
.handle
= le16_to_cpu(buffer
->AttachedDevHandle
);
1201 out_free_consistent
:
1202 pci_free_consistent(ioc
->pcidev
, hdr
.ExtPageLength
* 4,
1203 buffer
, dma_handle
);
1209 mptsas_sas_device_pg0(MPT_ADAPTER
*ioc
, struct mptsas_devinfo
*device_info
,
1210 u32 form
, u32 form_specific
)
1212 ConfigExtendedPageHeader_t hdr
;
1214 SasDevicePage0_t
*buffer
;
1215 dma_addr_t dma_handle
;
1219 if (ioc
->sas_discovery_runtime
&&
1220 mptsas_is_end_device(device_info
))
1223 hdr
.PageVersion
= MPI_SASDEVICE0_PAGEVERSION
;
1224 hdr
.ExtPageLength
= 0;
1228 hdr
.PageType
= MPI_CONFIG_PAGETYPE_EXTENDED
;
1229 hdr
.ExtPageType
= MPI_CONFIG_EXTPAGETYPE_SAS_DEVICE
;
1231 cfg
.cfghdr
.ehdr
= &hdr
;
1232 cfg
.pageAddr
= form
+ form_specific
;
1234 cfg
.action
= MPI_CONFIG_ACTION_PAGE_HEADER
;
1235 cfg
.dir
= 0; /* read */
1238 memset(device_info
, 0, sizeof(struct mptsas_devinfo
));
1239 error
= mpt_config(ioc
, &cfg
);
1242 if (!hdr
.ExtPageLength
) {
1247 buffer
= pci_alloc_consistent(ioc
->pcidev
, hdr
.ExtPageLength
* 4,
1254 cfg
.physAddr
= dma_handle
;
1255 cfg
.action
= MPI_CONFIG_ACTION_PAGE_READ_CURRENT
;
1257 error
= mpt_config(ioc
, &cfg
);
1259 goto out_free_consistent
;
1261 mptsas_print_device_pg0(buffer
);
1263 device_info
->handle
= le16_to_cpu(buffer
->DevHandle
);
1264 device_info
->handle_parent
= le16_to_cpu(buffer
->ParentDevHandle
);
1265 device_info
->handle_enclosure
=
1266 le16_to_cpu(buffer
->EnclosureHandle
);
1267 device_info
->slot
= le16_to_cpu(buffer
->Slot
);
1268 device_info
->phy_id
= buffer
->PhyNum
;
1269 device_info
->port_id
= buffer
->PhysicalPort
;
1270 device_info
->id
= buffer
->TargetID
;
1271 device_info
->channel
= buffer
->Bus
;
1272 memcpy(&sas_address
, &buffer
->SASAddress
, sizeof(__le64
));
1273 device_info
->sas_address
= le64_to_cpu(sas_address
);
1274 device_info
->device_info
=
1275 le32_to_cpu(buffer
->DeviceInfo
);
1277 out_free_consistent
:
1278 pci_free_consistent(ioc
->pcidev
, hdr
.ExtPageLength
* 4,
1279 buffer
, dma_handle
);
1285 mptsas_sas_expander_pg0(MPT_ADAPTER
*ioc
, struct mptsas_portinfo
*port_info
,
1286 u32 form
, u32 form_specific
)
1288 ConfigExtendedPageHeader_t hdr
;
1290 SasExpanderPage0_t
*buffer
;
1291 dma_addr_t dma_handle
;
1294 hdr
.PageVersion
= MPI_SASEXPANDER0_PAGEVERSION
;
1295 hdr
.ExtPageLength
= 0;
1299 hdr
.PageType
= MPI_CONFIG_PAGETYPE_EXTENDED
;
1300 hdr
.ExtPageType
= MPI_CONFIG_EXTPAGETYPE_SAS_EXPANDER
;
1302 cfg
.cfghdr
.ehdr
= &hdr
;
1304 cfg
.pageAddr
= form
+ form_specific
;
1305 cfg
.action
= MPI_CONFIG_ACTION_PAGE_HEADER
;
1306 cfg
.dir
= 0; /* read */
1309 memset(port_info
, 0, sizeof(struct mptsas_portinfo
));
1310 error
= mpt_config(ioc
, &cfg
);
1314 if (!hdr
.ExtPageLength
) {
1319 buffer
= pci_alloc_consistent(ioc
->pcidev
, hdr
.ExtPageLength
* 4,
1326 cfg
.physAddr
= dma_handle
;
1327 cfg
.action
= MPI_CONFIG_ACTION_PAGE_READ_CURRENT
;
1329 error
= mpt_config(ioc
, &cfg
);
1331 goto out_free_consistent
;
1333 /* save config data */
1334 port_info
->num_phys
= buffer
->NumPhys
;
1335 port_info
->handle
= le16_to_cpu(buffer
->DevHandle
);
1336 port_info
->phy_info
= kcalloc(port_info
->num_phys
,
1337 sizeof(*port_info
->phy_info
),GFP_KERNEL
);
1338 if (!port_info
->phy_info
) {
1340 goto out_free_consistent
;
1343 for (i
= 0; i
< port_info
->num_phys
; i
++)
1344 port_info
->phy_info
[i
].portinfo
= port_info
;
1346 out_free_consistent
:
1347 pci_free_consistent(ioc
->pcidev
, hdr
.ExtPageLength
* 4,
1348 buffer
, dma_handle
);
1354 mptsas_sas_expander_pg1(MPT_ADAPTER
*ioc
, struct mptsas_phyinfo
*phy_info
,
1355 u32 form
, u32 form_specific
)
1357 ConfigExtendedPageHeader_t hdr
;
1359 SasExpanderPage1_t
*buffer
;
1360 dma_addr_t dma_handle
;
1363 if (ioc
->sas_discovery_runtime
&&
1364 mptsas_is_end_device(&phy_info
->attached
))
1367 hdr
.PageVersion
= MPI_SASEXPANDER0_PAGEVERSION
;
1368 hdr
.ExtPageLength
= 0;
1372 hdr
.PageType
= MPI_CONFIG_PAGETYPE_EXTENDED
;
1373 hdr
.ExtPageType
= MPI_CONFIG_EXTPAGETYPE_SAS_EXPANDER
;
1375 cfg
.cfghdr
.ehdr
= &hdr
;
1377 cfg
.pageAddr
= form
+ form_specific
;
1378 cfg
.action
= MPI_CONFIG_ACTION_PAGE_HEADER
;
1379 cfg
.dir
= 0; /* read */
1382 error
= mpt_config(ioc
, &cfg
);
1386 if (!hdr
.ExtPageLength
) {
1391 buffer
= pci_alloc_consistent(ioc
->pcidev
, hdr
.ExtPageLength
* 4,
1398 cfg
.physAddr
= dma_handle
;
1399 cfg
.action
= MPI_CONFIG_ACTION_PAGE_READ_CURRENT
;
1401 error
= mpt_config(ioc
, &cfg
);
1403 goto out_free_consistent
;
1406 mptsas_print_expander_pg1(buffer
);
1408 /* save config data */
1409 phy_info
->phy_id
= buffer
->PhyIdentifier
;
1410 phy_info
->port_id
= buffer
->PhysicalPort
;
1411 phy_info
->negotiated_link_rate
= buffer
->NegotiatedLinkRate
;
1412 phy_info
->programmed_link_rate
= buffer
->ProgrammedLinkRate
;
1413 phy_info
->hw_link_rate
= buffer
->HwLinkRate
;
1414 phy_info
->identify
.handle
= le16_to_cpu(buffer
->OwnerDevHandle
);
1415 phy_info
->attached
.handle
= le16_to_cpu(buffer
->AttachedDevHandle
);
1417 out_free_consistent
:
1418 pci_free_consistent(ioc
->pcidev
, hdr
.ExtPageLength
* 4,
1419 buffer
, dma_handle
);
1425 mptsas_parse_device_info(struct sas_identify
*identify
,
1426 struct mptsas_devinfo
*device_info
)
1430 identify
->sas_address
= device_info
->sas_address
;
1431 identify
->phy_identifier
= device_info
->phy_id
;
1434 * Fill in Phy Initiator Port Protocol.
1435 * Bits 6:3, more than one bit can be set, fall through cases.
1437 protocols
= device_info
->device_info
& 0x78;
1438 identify
->initiator_port_protocols
= 0;
1439 if (protocols
& MPI_SAS_DEVICE_INFO_SSP_INITIATOR
)
1440 identify
->initiator_port_protocols
|= SAS_PROTOCOL_SSP
;
1441 if (protocols
& MPI_SAS_DEVICE_INFO_STP_INITIATOR
)
1442 identify
->initiator_port_protocols
|= SAS_PROTOCOL_STP
;
1443 if (protocols
& MPI_SAS_DEVICE_INFO_SMP_INITIATOR
)
1444 identify
->initiator_port_protocols
|= SAS_PROTOCOL_SMP
;
1445 if (protocols
& MPI_SAS_DEVICE_INFO_SATA_HOST
)
1446 identify
->initiator_port_protocols
|= SAS_PROTOCOL_SATA
;
1449 * Fill in Phy Target Port Protocol.
1450 * Bits 10:7, more than one bit can be set, fall through cases.
1452 protocols
= device_info
->device_info
& 0x780;
1453 identify
->target_port_protocols
= 0;
1454 if (protocols
& MPI_SAS_DEVICE_INFO_SSP_TARGET
)
1455 identify
->target_port_protocols
|= SAS_PROTOCOL_SSP
;
1456 if (protocols
& MPI_SAS_DEVICE_INFO_STP_TARGET
)
1457 identify
->target_port_protocols
|= SAS_PROTOCOL_STP
;
1458 if (protocols
& MPI_SAS_DEVICE_INFO_SMP_TARGET
)
1459 identify
->target_port_protocols
|= SAS_PROTOCOL_SMP
;
1460 if (protocols
& MPI_SAS_DEVICE_INFO_SATA_DEVICE
)
1461 identify
->target_port_protocols
|= SAS_PROTOCOL_SATA
;
1464 * Fill in Attached device type.
1466 switch (device_info
->device_info
&
1467 MPI_SAS_DEVICE_INFO_MASK_DEVICE_TYPE
) {
1468 case MPI_SAS_DEVICE_INFO_NO_DEVICE
:
1469 identify
->device_type
= SAS_PHY_UNUSED
;
1471 case MPI_SAS_DEVICE_INFO_END_DEVICE
:
1472 identify
->device_type
= SAS_END_DEVICE
;
1474 case MPI_SAS_DEVICE_INFO_EDGE_EXPANDER
:
1475 identify
->device_type
= SAS_EDGE_EXPANDER_DEVICE
;
1477 case MPI_SAS_DEVICE_INFO_FANOUT_EXPANDER
:
1478 identify
->device_type
= SAS_FANOUT_EXPANDER_DEVICE
;
1483 static int mptsas_probe_one_phy(struct device
*dev
,
1484 struct mptsas_phyinfo
*phy_info
, int index
, int local
)
1487 struct sas_phy
*phy
;
1488 struct sas_port
*port
;
1496 if (!phy_info
->phy
) {
1497 phy
= sas_phy_alloc(dev
, index
);
1503 phy
= phy_info
->phy
;
1505 mptsas_parse_device_info(&phy
->identify
, &phy_info
->identify
);
1508 * Set Negotiated link rate.
1510 switch (phy_info
->negotiated_link_rate
) {
1511 case MPI_SAS_IOUNIT0_RATE_PHY_DISABLED
:
1512 phy
->negotiated_linkrate
= SAS_PHY_DISABLED
;
1514 case MPI_SAS_IOUNIT0_RATE_FAILED_SPEED_NEGOTIATION
:
1515 phy
->negotiated_linkrate
= SAS_LINK_RATE_FAILED
;
1517 case MPI_SAS_IOUNIT0_RATE_1_5
:
1518 phy
->negotiated_linkrate
= SAS_LINK_RATE_1_5_GBPS
;
1520 case MPI_SAS_IOUNIT0_RATE_3_0
:
1521 phy
->negotiated_linkrate
= SAS_LINK_RATE_3_0_GBPS
;
1523 case MPI_SAS_IOUNIT0_RATE_SATA_OOB_COMPLETE
:
1524 case MPI_SAS_IOUNIT0_RATE_UNKNOWN
:
1526 phy
->negotiated_linkrate
= SAS_LINK_RATE_UNKNOWN
;
1531 * Set Max hardware link rate.
1533 switch (phy_info
->hw_link_rate
& MPI_SAS_PHY0_PRATE_MAX_RATE_MASK
) {
1534 case MPI_SAS_PHY0_HWRATE_MAX_RATE_1_5
:
1535 phy
->maximum_linkrate_hw
= SAS_LINK_RATE_1_5_GBPS
;
1537 case MPI_SAS_PHY0_PRATE_MAX_RATE_3_0
:
1538 phy
->maximum_linkrate_hw
= SAS_LINK_RATE_3_0_GBPS
;
1545 * Set Max programmed link rate.
1547 switch (phy_info
->programmed_link_rate
&
1548 MPI_SAS_PHY0_PRATE_MAX_RATE_MASK
) {
1549 case MPI_SAS_PHY0_PRATE_MAX_RATE_1_5
:
1550 phy
->maximum_linkrate
= SAS_LINK_RATE_1_5_GBPS
;
1552 case MPI_SAS_PHY0_PRATE_MAX_RATE_3_0
:
1553 phy
->maximum_linkrate
= SAS_LINK_RATE_3_0_GBPS
;
1560 * Set Min hardware link rate.
1562 switch (phy_info
->hw_link_rate
& MPI_SAS_PHY0_HWRATE_MIN_RATE_MASK
) {
1563 case MPI_SAS_PHY0_HWRATE_MIN_RATE_1_5
:
1564 phy
->minimum_linkrate_hw
= SAS_LINK_RATE_1_5_GBPS
;
1566 case MPI_SAS_PHY0_PRATE_MIN_RATE_3_0
:
1567 phy
->minimum_linkrate_hw
= SAS_LINK_RATE_3_0_GBPS
;
1574 * Set Min programmed link rate.
1576 switch (phy_info
->programmed_link_rate
&
1577 MPI_SAS_PHY0_PRATE_MIN_RATE_MASK
) {
1578 case MPI_SAS_PHY0_PRATE_MIN_RATE_1_5
:
1579 phy
->minimum_linkrate
= SAS_LINK_RATE_1_5_GBPS
;
1581 case MPI_SAS_PHY0_PRATE_MIN_RATE_3_0
:
1582 phy
->minimum_linkrate
= SAS_LINK_RATE_3_0_GBPS
;
1588 if (!phy_info
->phy
) {
1591 phy
->local_attached
= 1;
1593 error
= sas_phy_add(phy
);
1598 phy_info
->phy
= phy
;
1601 if (!phy_info
->attached
.handle
||
1602 !phy_info
->port_details
)
1605 port
= mptsas_get_port(phy_info
);
1606 ioc
= phy_to_ioc(phy_info
->phy
);
1608 if (phy_info
->sas_port_add_phy
) {
1611 port
= sas_port_alloc(dev
,
1612 phy_info
->port_details
->port_id
);
1613 dsaswideprintk((KERN_DEBUG
1614 "sas_port_alloc: port=%p dev=%p port_id=%d\n",
1615 port
, dev
, phy_info
->port_details
->port_id
));
1620 error
= sas_port_add(port
);
1622 dfailprintk((MYIOC_s_ERR_FMT
1623 "%s: exit at line=%d\n", ioc
->name
,
1624 __FUNCTION__
, __LINE__
));
1627 mptsas_set_port(phy_info
, port
);
1629 dsaswideprintk((KERN_DEBUG
"sas_port_add_phy: phy_id=%d\n",
1631 sas_port_add_phy(port
, phy_info
->phy
);
1632 phy_info
->sas_port_add_phy
= 0;
1635 if (!mptsas_get_rphy(phy_info
) && port
&& !port
->rphy
) {
1637 struct sas_rphy
*rphy
;
1638 struct sas_identify identify
;
1641 * Let the hotplug_work thread handle processing
1642 * the adding/removing of devices that occur
1643 * after start of day.
1645 if (ioc
->sas_discovery_runtime
&&
1646 mptsas_is_end_device(&phy_info
->attached
))
1649 mptsas_parse_device_info(&identify
, &phy_info
->attached
);
1650 switch (identify
.device_type
) {
1651 case SAS_END_DEVICE
:
1652 rphy
= sas_end_device_alloc(port
);
1654 case SAS_EDGE_EXPANDER_DEVICE
:
1655 case SAS_FANOUT_EXPANDER_DEVICE
:
1656 rphy
= sas_expander_alloc(port
, identify
.device_type
);
1663 dfailprintk((MYIOC_s_ERR_FMT
1664 "%s: exit at line=%d\n", ioc
->name
,
1665 __FUNCTION__
, __LINE__
));
1669 rphy
->identify
= identify
;
1670 error
= sas_rphy_add(rphy
);
1672 dfailprintk((MYIOC_s_ERR_FMT
1673 "%s: exit at line=%d\n", ioc
->name
,
1674 __FUNCTION__
, __LINE__
));
1675 sas_rphy_free(rphy
);
1678 mptsas_set_rphy(phy_info
, rphy
);
1686 mptsas_probe_hba_phys(MPT_ADAPTER
*ioc
)
1688 struct mptsas_portinfo
*port_info
, *hba
;
1689 u32 handle
= 0xFFFF;
1690 int error
= -ENOMEM
, i
;
1692 hba
= kzalloc(sizeof(*port_info
), GFP_KERNEL
);
1696 error
= mptsas_sas_io_unit_pg0(ioc
, hba
);
1698 goto out_free_port_info
;
1700 mutex_lock(&ioc
->sas_topology_mutex
);
1701 port_info
= mptsas_find_portinfo_by_handle(ioc
, hba
->handle
);
1704 list_add_tail(&port_info
->list
, &ioc
->sas_topology
);
1706 port_info
->handle
= hba
->handle
;
1707 for (i
= 0; i
< hba
->num_phys
; i
++)
1708 port_info
->phy_info
[i
].negotiated_link_rate
=
1709 hba
->phy_info
[i
].negotiated_link_rate
;
1710 kfree(hba
->phy_info
);
1714 mutex_unlock(&ioc
->sas_topology_mutex
);
1715 ioc
->num_ports
= port_info
->num_phys
;
1717 for (i
= 0; i
< port_info
->num_phys
; i
++) {
1718 mptsas_sas_phy_pg0(ioc
, &port_info
->phy_info
[i
],
1719 (MPI_SAS_PHY_PGAD_FORM_PHY_NUMBER
<<
1720 MPI_SAS_PHY_PGAD_FORM_SHIFT
), i
);
1722 mptsas_sas_device_pg0(ioc
, &port_info
->phy_info
[i
].identify
,
1723 (MPI_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
<<
1724 MPI_SAS_DEVICE_PGAD_FORM_SHIFT
), handle
);
1725 port_info
->phy_info
[i
].identify
.phy_id
=
1726 port_info
->phy_info
[i
].phy_id
;
1727 handle
= port_info
->phy_info
[i
].identify
.handle
;
1729 if (port_info
->phy_info
[i
].attached
.handle
)
1730 mptsas_sas_device_pg0(ioc
,
1731 &port_info
->phy_info
[i
].attached
,
1732 (MPI_SAS_DEVICE_PGAD_FORM_HANDLE
<<
1733 MPI_SAS_DEVICE_PGAD_FORM_SHIFT
),
1734 port_info
->phy_info
[i
].attached
.handle
);
1737 mptsas_setup_wide_ports(ioc
, port_info
);
1739 for (i
= 0; i
< port_info
->num_phys
; i
++, ioc
->sas_index
++)
1740 mptsas_probe_one_phy(&ioc
->sh
->shost_gendev
,
1741 &port_info
->phy_info
[i
], ioc
->sas_index
, 1);
1752 mptsas_probe_expander_phys(MPT_ADAPTER
*ioc
, u32
*handle
)
1754 struct mptsas_portinfo
*port_info
, *p
, *ex
;
1755 struct device
*parent
;
1756 struct sas_rphy
*rphy
;
1757 int error
= -ENOMEM
, i
, j
;
1759 ex
= kzalloc(sizeof(*port_info
), GFP_KERNEL
);
1763 error
= mptsas_sas_expander_pg0(ioc
, ex
,
1764 (MPI_SAS_EXPAND_PGAD_FORM_GET_NEXT_HANDLE
<<
1765 MPI_SAS_EXPAND_PGAD_FORM_SHIFT
), *handle
);
1767 goto out_free_port_info
;
1769 *handle
= ex
->handle
;
1771 mutex_lock(&ioc
->sas_topology_mutex
);
1772 port_info
= mptsas_find_portinfo_by_handle(ioc
, *handle
);
1775 list_add_tail(&port_info
->list
, &ioc
->sas_topology
);
1777 port_info
->handle
= ex
->handle
;
1778 kfree(ex
->phy_info
);
1782 mutex_unlock(&ioc
->sas_topology_mutex
);
1784 for (i
= 0; i
< port_info
->num_phys
; i
++) {
1785 mptsas_sas_expander_pg1(ioc
, &port_info
->phy_info
[i
],
1786 (MPI_SAS_EXPAND_PGAD_FORM_HANDLE_PHY_NUM
<<
1787 MPI_SAS_EXPAND_PGAD_FORM_SHIFT
), (i
<< 16) + *handle
);
1789 if (port_info
->phy_info
[i
].identify
.handle
) {
1790 mptsas_sas_device_pg0(ioc
,
1791 &port_info
->phy_info
[i
].identify
,
1792 (MPI_SAS_DEVICE_PGAD_FORM_HANDLE
<<
1793 MPI_SAS_DEVICE_PGAD_FORM_SHIFT
),
1794 port_info
->phy_info
[i
].identify
.handle
);
1795 port_info
->phy_info
[i
].identify
.phy_id
=
1796 port_info
->phy_info
[i
].phy_id
;
1799 if (port_info
->phy_info
[i
].attached
.handle
) {
1800 mptsas_sas_device_pg0(ioc
,
1801 &port_info
->phy_info
[i
].attached
,
1802 (MPI_SAS_DEVICE_PGAD_FORM_HANDLE
<<
1803 MPI_SAS_DEVICE_PGAD_FORM_SHIFT
),
1804 port_info
->phy_info
[i
].attached
.handle
);
1805 port_info
->phy_info
[i
].attached
.phy_id
=
1806 port_info
->phy_info
[i
].phy_id
;
1810 parent
= &ioc
->sh
->shost_gendev
;
1811 for (i
= 0; i
< port_info
->num_phys
; i
++) {
1812 mutex_lock(&ioc
->sas_topology_mutex
);
1813 list_for_each_entry(p
, &ioc
->sas_topology
, list
) {
1814 for (j
= 0; j
< p
->num_phys
; j
++) {
1815 if (port_info
->phy_info
[i
].identify
.handle
!=
1816 p
->phy_info
[j
].attached
.handle
)
1818 rphy
= mptsas_get_rphy(&p
->phy_info
[j
]);
1819 parent
= &rphy
->dev
;
1822 mutex_unlock(&ioc
->sas_topology_mutex
);
1825 mptsas_setup_wide_ports(ioc
, port_info
);
1827 for (i
= 0; i
< port_info
->num_phys
; i
++, ioc
->sas_index
++)
1828 mptsas_probe_one_phy(parent
, &port_info
->phy_info
[i
],
1835 kfree(ex
->phy_info
);
1843 * mptsas_delete_expander_phys
1846 * This will traverse topology, and remove expanders
1847 * that are no longer present
1850 mptsas_delete_expander_phys(MPT_ADAPTER
*ioc
)
1852 struct mptsas_portinfo buffer
;
1853 struct mptsas_portinfo
*port_info
, *n
, *parent
;
1854 struct mptsas_phyinfo
*phy_info
;
1855 struct scsi_target
* starget
;
1856 VirtTarget
* vtarget
;
1857 struct sas_port
* port
;
1859 u64 expander_sas_address
;
1861 mutex_lock(&ioc
->sas_topology_mutex
);
1862 list_for_each_entry_safe(port_info
, n
, &ioc
->sas_topology
, list
) {
1864 if (port_info
->phy_info
&&
1865 (!(port_info
->phy_info
[0].identify
.device_info
&
1866 MPI_SAS_DEVICE_INFO_SMP_TARGET
)))
1869 if (mptsas_sas_expander_pg0(ioc
, &buffer
,
1870 (MPI_SAS_EXPAND_PGAD_FORM_HANDLE
<<
1871 MPI_SAS_EXPAND_PGAD_FORM_SHIFT
), port_info
->handle
)) {
1874 * Issue target reset to all child end devices
1875 * then mark them deleted to prevent further
1878 phy_info
= port_info
->phy_info
;
1879 for (i
= 0; i
< port_info
->num_phys
; i
++, phy_info
++) {
1880 starget
= mptsas_get_starget(phy_info
);
1883 vtarget
= starget
->hostdata
;
1884 if(vtarget
->deleted
)
1886 vtarget
->deleted
= 1;
1887 mptsas_target_reset(ioc
, vtarget
);
1888 sas_port_delete(mptsas_get_port(phy_info
));
1889 mptsas_port_delete(phy_info
->port_details
);
1893 * Obtain the port_info instance to the parent port
1895 parent
= mptsas_find_portinfo_by_handle(ioc
,
1896 port_info
->phy_info
[0].identify
.handle_parent
);
1901 expander_sas_address
=
1902 port_info
->phy_info
[0].identify
.sas_address
;
1905 * Delete rphys in the parent that point
1906 * to this expander. The transport layer will
1907 * cleanup all the children.
1909 phy_info
= parent
->phy_info
;
1910 for (i
= 0; i
< parent
->num_phys
; i
++, phy_info
++) {
1911 port
= mptsas_get_port(phy_info
);
1914 if (phy_info
->attached
.sas_address
!=
1915 expander_sas_address
)
1917 #ifdef MPT_DEBUG_SAS_WIDE
1918 dev_printk(KERN_DEBUG
, &port
->dev
, "delete\n");
1920 sas_port_delete(port
);
1921 mptsas_port_delete(phy_info
->port_details
);
1925 phy_info
= port_info
->phy_info
;
1926 for (i
= 0; i
< port_info
->num_phys
; i
++, phy_info
++)
1927 mptsas_port_delete(phy_info
->port_details
);
1929 list_del(&port_info
->list
);
1930 kfree(port_info
->phy_info
);
1934 * Free this memory allocated from inside
1935 * mptsas_sas_expander_pg0
1937 kfree(buffer
.phy_info
);
1939 mutex_unlock(&ioc
->sas_topology_mutex
);
1943 * Start of day discovery
1946 mptsas_scan_sas_topology(MPT_ADAPTER
*ioc
)
1948 u32 handle
= 0xFFFF;
1951 mutex_lock(&ioc
->sas_discovery_mutex
);
1952 mptsas_probe_hba_phys(ioc
);
1953 while (!mptsas_probe_expander_phys(ioc
, &handle
))
1956 Reporting RAID volumes.
1958 if (!ioc
->raid_data
.pIocPg2
)
1960 if (!ioc
->raid_data
.pIocPg2
->NumActiveVolumes
)
1962 for (i
=0; i
<ioc
->raid_data
.pIocPg2
->NumActiveVolumes
; i
++) {
1963 scsi_add_device(ioc
->sh
, ioc
->num_ports
,
1964 ioc
->raid_data
.pIocPg2
->RaidVolume
[i
].VolumeID
, 0);
1967 mutex_unlock(&ioc
->sas_discovery_mutex
);
1971 * Work queue thread to handle Runtime discovery
1972 * Mere purpose is the hot add/delete of expanders
1976 __mptsas_discovery_work(MPT_ADAPTER
*ioc
)
1978 u32 handle
= 0xFFFF;
1980 ioc
->sas_discovery_runtime
=1;
1981 mptsas_delete_expander_phys(ioc
);
1982 mptsas_probe_hba_phys(ioc
);
1983 while (!mptsas_probe_expander_phys(ioc
, &handle
))
1985 ioc
->sas_discovery_runtime
=0;
1989 * Work queue thread to handle Runtime discovery
1990 * Mere purpose is the hot add/delete of expanders
1994 mptsas_discovery_work(void * arg
)
1996 struct mptsas_discovery_event
*ev
= arg
;
1997 MPT_ADAPTER
*ioc
= ev
->ioc
;
1999 mutex_lock(&ioc
->sas_discovery_mutex
);
2000 __mptsas_discovery_work(ioc
);
2001 mutex_unlock(&ioc
->sas_discovery_mutex
);
2005 static struct mptsas_phyinfo
*
2006 mptsas_find_phyinfo_by_sas_address(MPT_ADAPTER
*ioc
, u64 sas_address
)
2008 struct mptsas_portinfo
*port_info
;
2009 struct mptsas_phyinfo
*phy_info
= NULL
;
2012 mutex_lock(&ioc
->sas_topology_mutex
);
2013 list_for_each_entry(port_info
, &ioc
->sas_topology
, list
) {
2014 for (i
= 0; i
< port_info
->num_phys
; i
++) {
2015 if (port_info
->phy_info
[i
].attached
.sas_address
2018 if (!mptsas_is_end_device(
2019 &port_info
->phy_info
[i
].attached
))
2021 phy_info
= &port_info
->phy_info
[i
];
2025 mutex_unlock(&ioc
->sas_topology_mutex
);
2029 static struct mptsas_phyinfo
*
2030 mptsas_find_phyinfo_by_target(MPT_ADAPTER
*ioc
, u32 id
)
2032 struct mptsas_portinfo
*port_info
;
2033 struct mptsas_phyinfo
*phy_info
= NULL
;
2036 mutex_lock(&ioc
->sas_topology_mutex
);
2037 list_for_each_entry(port_info
, &ioc
->sas_topology
, list
) {
2038 for (i
= 0; i
< port_info
->num_phys
; i
++) {
2039 if (port_info
->phy_info
[i
].attached
.id
!= id
)
2041 if (!mptsas_is_end_device(
2042 &port_info
->phy_info
[i
].attached
))
2044 phy_info
= &port_info
->phy_info
[i
];
2048 mutex_unlock(&ioc
->sas_topology_mutex
);
2053 * Work queue thread to clear the persitency table
2056 mptsas_persist_clear_table(void * arg
)
2058 MPT_ADAPTER
*ioc
= (MPT_ADAPTER
*)arg
;
2060 mptbase_sas_persist_operation(ioc
, MPI_SAS_OP_CLEAR_NOT_PRESENT
);
2064 mptsas_reprobe_lun(struct scsi_device
*sdev
, void *data
)
2066 sdev
->no_uld_attach
= data
? 1 : 0;
2067 scsi_device_reprobe(sdev
);
2071 mptsas_reprobe_target(struct scsi_target
*starget
, int uld_attach
)
2073 starget_for_each_device(starget
, uld_attach
? (void *)1 : NULL
,
2074 mptsas_reprobe_lun
);
2078 * Work queue thread to handle SAS hotplug events
2081 mptsas_hotplug_work(void *arg
)
2083 struct mptsas_hotplug_event
*ev
= arg
;
2084 MPT_ADAPTER
*ioc
= ev
->ioc
;
2085 struct mptsas_phyinfo
*phy_info
;
2086 struct sas_rphy
*rphy
;
2087 struct sas_port
*port
;
2088 struct scsi_device
*sdev
;
2089 struct scsi_target
* starget
;
2090 struct sas_identify identify
;
2092 struct mptsas_devinfo sas_device
;
2093 VirtTarget
*vtarget
;
2094 VirtDevice
*vdevice
;
2097 mutex_lock(&ioc
->sas_discovery_mutex
);
2098 switch (ev
->event_type
) {
2099 case MPTSAS_DEL_DEVICE
:
2101 phy_info
= mptsas_find_phyinfo_by_target(ioc
, ev
->id
);
2104 * Sanity checks, for non-existing phys and remote rphys.
2106 if (!phy_info
|| !phy_info
->port_details
) {
2107 dfailprintk((MYIOC_s_ERR_FMT
2108 "%s: exit at line=%d\n", ioc
->name
,
2109 __FUNCTION__
, __LINE__
));
2112 rphy
= mptsas_get_rphy(phy_info
);
2114 dfailprintk((MYIOC_s_ERR_FMT
2115 "%s: exit at line=%d\n", ioc
->name
,
2116 __FUNCTION__
, __LINE__
));
2119 port
= mptsas_get_port(phy_info
);
2121 dfailprintk((MYIOC_s_ERR_FMT
2122 "%s: exit at line=%d\n", ioc
->name
,
2123 __FUNCTION__
, __LINE__
));
2127 starget
= mptsas_get_starget(phy_info
);
2129 vtarget
= starget
->hostdata
;
2132 dfailprintk((MYIOC_s_ERR_FMT
2133 "%s: exit at line=%d\n", ioc
->name
,
2134 __FUNCTION__
, __LINE__
));
2139 * Handling RAID components
2141 if (ev
->phys_disk_num_valid
) {
2142 vtarget
->target_id
= ev
->phys_disk_num
;
2143 vtarget
->tflags
|= MPT_TARGET_FLAGS_RAID_COMPONENT
;
2144 mptsas_reprobe_target(starget
, 1);
2148 vtarget
->deleted
= 1;
2149 mptsas_target_reset(ioc
, vtarget
);
2152 if (phy_info
->attached
.device_info
& MPI_SAS_DEVICE_INFO_SSP_TARGET
)
2154 if (phy_info
->attached
.device_info
& MPI_SAS_DEVICE_INFO_STP_TARGET
)
2156 if (phy_info
->attached
.device_info
& MPI_SAS_DEVICE_INFO_SATA_DEVICE
)
2159 printk(MYIOC_s_INFO_FMT
2160 "removing %s device, channel %d, id %d, phy %d\n",
2161 ioc
->name
, ds
, ev
->channel
, ev
->id
, phy_info
->phy_id
);
2163 #ifdef MPT_DEBUG_SAS_WIDE
2164 dev_printk(KERN_DEBUG
, &port
->dev
, "delete\n");
2166 sas_port_delete(port
);
2167 mptsas_port_delete(phy_info
->port_details
);
2169 case MPTSAS_ADD_DEVICE
:
2171 if (ev
->phys_disk_num_valid
)
2172 mpt_findImVolumes(ioc
);
2175 * Refresh sas device pg0 data
2177 if (mptsas_sas_device_pg0(ioc
, &sas_device
,
2178 (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID
<<
2179 MPI_SAS_DEVICE_PGAD_FORM_SHIFT
), ev
->id
)) {
2180 dfailprintk((MYIOC_s_ERR_FMT
2181 "%s: exit at line=%d\n", ioc
->name
,
2182 __FUNCTION__
, __LINE__
));
2187 __mptsas_discovery_work(ioc
);
2189 phy_info
= mptsas_find_phyinfo_by_sas_address(ioc
,
2190 sas_device
.sas_address
);
2192 if (!phy_info
|| !phy_info
->port_details
) {
2193 dfailprintk((MYIOC_s_ERR_FMT
2194 "%s: exit at line=%d\n", ioc
->name
,
2195 __FUNCTION__
, __LINE__
));
2199 starget
= mptsas_get_starget(phy_info
);
2201 vtarget
= starget
->hostdata
;
2204 dfailprintk((MYIOC_s_ERR_FMT
2205 "%s: exit at line=%d\n", ioc
->name
,
2206 __FUNCTION__
, __LINE__
));
2210 * Handling RAID components
2212 if (vtarget
->tflags
& MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2213 vtarget
->tflags
&= ~MPT_TARGET_FLAGS_RAID_COMPONENT
;
2214 vtarget
->target_id
= ev
->id
;
2215 mptsas_reprobe_target(starget
, 0);
2220 if (mptsas_get_rphy(phy_info
)) {
2221 dfailprintk((MYIOC_s_ERR_FMT
2222 "%s: exit at line=%d\n", ioc
->name
,
2223 __FUNCTION__
, __LINE__
));
2226 port
= mptsas_get_port(phy_info
);
2228 dfailprintk((MYIOC_s_ERR_FMT
2229 "%s: exit at line=%d\n", ioc
->name
,
2230 __FUNCTION__
, __LINE__
));
2234 memcpy(&phy_info
->attached
, &sas_device
,
2235 sizeof(struct mptsas_devinfo
));
2237 if (phy_info
->attached
.device_info
& MPI_SAS_DEVICE_INFO_SSP_TARGET
)
2239 if (phy_info
->attached
.device_info
& MPI_SAS_DEVICE_INFO_STP_TARGET
)
2241 if (phy_info
->attached
.device_info
& MPI_SAS_DEVICE_INFO_SATA_DEVICE
)
2244 printk(MYIOC_s_INFO_FMT
2245 "attaching %s device, channel %d, id %d, phy %d\n",
2246 ioc
->name
, ds
, ev
->channel
, ev
->id
, ev
->phy_id
);
2248 mptsas_parse_device_info(&identify
, &phy_info
->attached
);
2249 rphy
= sas_end_device_alloc(port
);
2251 dfailprintk((MYIOC_s_ERR_FMT
2252 "%s: exit at line=%d\n", ioc
->name
,
2253 __FUNCTION__
, __LINE__
));
2254 break; /* non-fatal: an rphy can be added later */
2257 rphy
->identify
= identify
;
2258 if (sas_rphy_add(rphy
)) {
2259 dfailprintk((MYIOC_s_ERR_FMT
2260 "%s: exit at line=%d\n", ioc
->name
,
2261 __FUNCTION__
, __LINE__
));
2262 sas_rphy_free(rphy
);
2265 mptsas_set_rphy(phy_info
, rphy
);
2267 case MPTSAS_ADD_RAID
:
2268 sdev
= scsi_device_lookup(
2274 scsi_device_put(sdev
);
2277 printk(MYIOC_s_INFO_FMT
2278 "attaching raid volume, channel %d, id %d\n",
2279 ioc
->name
, ioc
->num_ports
, ev
->id
);
2280 scsi_add_device(ioc
->sh
,
2284 mpt_findImVolumes(ioc
);
2286 case MPTSAS_DEL_RAID
:
2287 sdev
= scsi_device_lookup(
2294 printk(MYIOC_s_INFO_FMT
2295 "removing raid volume, channel %d, id %d\n",
2296 ioc
->name
, ioc
->num_ports
, ev
->id
);
2297 vdevice
= sdev
->hostdata
;
2298 vdevice
->vtarget
->deleted
= 1;
2299 mptsas_target_reset(ioc
, vdevice
->vtarget
);
2300 scsi_remove_device(sdev
);
2301 scsi_device_put(sdev
);
2302 mpt_findImVolumes(ioc
);
2304 case MPTSAS_IGNORE_EVENT
:
2309 mutex_unlock(&ioc
->sas_discovery_mutex
);
2315 mptsas_send_sas_event(MPT_ADAPTER
*ioc
,
2316 EVENT_DATA_SAS_DEVICE_STATUS_CHANGE
*sas_event_data
)
2318 struct mptsas_hotplug_event
*ev
;
2319 u32 device_info
= le32_to_cpu(sas_event_data
->DeviceInfo
);
2323 (MPI_SAS_DEVICE_INFO_SSP_TARGET
|
2324 MPI_SAS_DEVICE_INFO_STP_TARGET
|
2325 MPI_SAS_DEVICE_INFO_SATA_DEVICE
)) == 0)
2328 switch (sas_event_data
->ReasonCode
) {
2329 case MPI_EVENT_SAS_DEV_STAT_RC_ADDED
:
2330 case MPI_EVENT_SAS_DEV_STAT_RC_NOT_RESPONDING
:
2331 ev
= kzalloc(sizeof(*ev
), GFP_ATOMIC
);
2333 printk(KERN_WARNING
"mptsas: lost hotplug event\n");
2337 INIT_WORK(&ev
->work
, mptsas_hotplug_work
, ev
);
2339 ev
->handle
= le16_to_cpu(sas_event_data
->DevHandle
);
2341 le16_to_cpu(sas_event_data
->ParentDevHandle
);
2342 ev
->channel
= sas_event_data
->Bus
;
2343 ev
->id
= sas_event_data
->TargetID
;
2344 ev
->phy_id
= sas_event_data
->PhyNum
;
2345 memcpy(&sas_address
, &sas_event_data
->SASAddress
,
2347 ev
->sas_address
= le64_to_cpu(sas_address
);
2348 ev
->device_info
= device_info
;
2350 if (sas_event_data
->ReasonCode
&
2351 MPI_EVENT_SAS_DEV_STAT_RC_ADDED
)
2352 ev
->event_type
= MPTSAS_ADD_DEVICE
;
2354 ev
->event_type
= MPTSAS_DEL_DEVICE
;
2355 schedule_work(&ev
->work
);
2357 case MPI_EVENT_SAS_DEV_STAT_RC_NO_PERSIST_ADDED
:
2359 * Persistent table is full.
2361 INIT_WORK(&ioc
->sas_persist_task
,
2362 mptsas_persist_clear_table
, (void *)ioc
);
2363 schedule_work(&ioc
->sas_persist_task
);
2365 case MPI_EVENT_SAS_DEV_STAT_RC_SMART_DATA
:
2367 case MPI_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
:
2375 mptsas_send_raid_event(MPT_ADAPTER
*ioc
,
2376 EVENT_DATA_RAID
*raid_event_data
)
2378 struct mptsas_hotplug_event
*ev
;
2379 int status
= le32_to_cpu(raid_event_data
->SettingsStatus
);
2380 int state
= (status
>> 8) & 0xff;
2382 if (ioc
->bus_type
!= SAS
)
2385 ev
= kzalloc(sizeof(*ev
), GFP_ATOMIC
);
2387 printk(KERN_WARNING
"mptsas: lost hotplug event\n");
2391 INIT_WORK(&ev
->work
, mptsas_hotplug_work
, ev
);
2393 ev
->id
= raid_event_data
->VolumeID
;
2394 ev
->event_type
= MPTSAS_IGNORE_EVENT
;
2396 switch (raid_event_data
->ReasonCode
) {
2397 case MPI_EVENT_RAID_RC_PHYSDISK_DELETED
:
2398 ev
->event_type
= MPTSAS_ADD_DEVICE
;
2400 case MPI_EVENT_RAID_RC_PHYSDISK_CREATED
:
2401 ioc
->raid_data
.isRaid
= 1;
2402 ev
->phys_disk_num_valid
= 1;
2403 ev
->phys_disk_num
= raid_event_data
->PhysDiskNum
;
2404 ev
->event_type
= MPTSAS_DEL_DEVICE
;
2406 case MPI_EVENT_RAID_RC_PHYSDISK_STATUS_CHANGED
:
2408 case MPI_PD_STATE_ONLINE
:
2409 ioc
->raid_data
.isRaid
= 1;
2410 ev
->phys_disk_num_valid
= 1;
2411 ev
->phys_disk_num
= raid_event_data
->PhysDiskNum
;
2412 ev
->event_type
= MPTSAS_ADD_DEVICE
;
2414 case MPI_PD_STATE_MISSING
:
2415 case MPI_PD_STATE_NOT_COMPATIBLE
:
2416 case MPI_PD_STATE_OFFLINE_AT_HOST_REQUEST
:
2417 case MPI_PD_STATE_FAILED_AT_HOST_REQUEST
:
2418 case MPI_PD_STATE_OFFLINE_FOR_ANOTHER_REASON
:
2419 ev
->event_type
= MPTSAS_DEL_DEVICE
;
2425 case MPI_EVENT_RAID_RC_VOLUME_DELETED
:
2426 ev
->event_type
= MPTSAS_DEL_RAID
;
2428 case MPI_EVENT_RAID_RC_VOLUME_CREATED
:
2429 ev
->event_type
= MPTSAS_ADD_RAID
;
2431 case MPI_EVENT_RAID_RC_VOLUME_STATUS_CHANGED
:
2433 case MPI_RAIDVOL0_STATUS_STATE_FAILED
:
2434 case MPI_RAIDVOL0_STATUS_STATE_MISSING
:
2435 ev
->event_type
= MPTSAS_DEL_RAID
;
2437 case MPI_RAIDVOL0_STATUS_STATE_OPTIMAL
:
2438 case MPI_RAIDVOL0_STATUS_STATE_DEGRADED
:
2439 ev
->event_type
= MPTSAS_ADD_RAID
;
2448 schedule_work(&ev
->work
);
2452 mptsas_send_discovery_event(MPT_ADAPTER
*ioc
,
2453 EVENT_DATA_SAS_DISCOVERY
*discovery_data
)
2455 struct mptsas_discovery_event
*ev
;
2460 * This flag will be non-zero when firmware
2461 * kicks off discovery, and return to zero
2462 * once its completed.
2464 if (discovery_data
->DiscoveryStatus
)
2467 ev
= kzalloc(sizeof(*ev
), GFP_ATOMIC
);
2470 INIT_WORK(&ev
->work
, mptsas_discovery_work
, ev
);
2472 schedule_work(&ev
->work
);
2477 mptsas_event_process(MPT_ADAPTER
*ioc
, EventNotificationReply_t
*reply
)
2480 u8 event
= le32_to_cpu(reply
->Event
) & 0xFF;
2486 * sas_discovery_ignore_events
2488 * This flag is to prevent anymore processing of
2489 * sas events once mptsas_remove function is called.
2491 if (ioc
->sas_discovery_ignore_events
) {
2492 rc
= mptscsih_event_process(ioc
, reply
);
2497 case MPI_EVENT_SAS_DEVICE_STATUS_CHANGE
:
2498 mptsas_send_sas_event(ioc
,
2499 (EVENT_DATA_SAS_DEVICE_STATUS_CHANGE
*)reply
->Data
);
2501 case MPI_EVENT_INTEGRATED_RAID
:
2502 mptsas_send_raid_event(ioc
,
2503 (EVENT_DATA_RAID
*)reply
->Data
);
2505 case MPI_EVENT_PERSISTENT_TABLE_FULL
:
2506 INIT_WORK(&ioc
->sas_persist_task
,
2507 mptsas_persist_clear_table
,
2509 schedule_work(&ioc
->sas_persist_task
);
2511 case MPI_EVENT_SAS_DISCOVERY
:
2512 mptsas_send_discovery_event(ioc
,
2513 (EVENT_DATA_SAS_DISCOVERY
*)reply
->Data
);
2516 rc
= mptscsih_event_process(ioc
, reply
);
2525 mptsas_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
2527 struct Scsi_Host
*sh
;
2530 unsigned long flags
;
2538 r
= mpt_attach(pdev
,id
);
2542 ioc
= pci_get_drvdata(pdev
);
2543 ioc
->DoneCtx
= mptsasDoneCtx
;
2544 ioc
->TaskCtx
= mptsasTaskCtx
;
2545 ioc
->InternalCtx
= mptsasInternalCtx
;
2547 /* Added sanity check on readiness of the MPT adapter.
2549 if (ioc
->last_state
!= MPI_IOC_STATE_OPERATIONAL
) {
2550 printk(MYIOC_s_WARN_FMT
2551 "Skipping because it's not operational!\n",
2554 goto out_mptsas_probe
;
2558 printk(MYIOC_s_WARN_FMT
"Skipping because it's disabled!\n",
2561 goto out_mptsas_probe
;
2564 /* Sanity check - ensure at least 1 port is INITIATOR capable
2567 for (ii
= 0; ii
< ioc
->facts
.NumberOfPorts
; ii
++) {
2568 if (ioc
->pfacts
[ii
].ProtocolFlags
&
2569 MPI_PORTFACTS_PROTOCOL_INITIATOR
)
2574 printk(MYIOC_s_WARN_FMT
2575 "Skipping ioc=%p because SCSI Initiator mode "
2576 "is NOT enabled!\n", ioc
->name
, ioc
);
2580 sh
= scsi_host_alloc(&mptsas_driver_template
, sizeof(MPT_SCSI_HOST
));
2582 printk(MYIOC_s_WARN_FMT
2583 "Unable to register controller with SCSI subsystem\n",
2586 goto out_mptsas_probe
;
2589 spin_lock_irqsave(&ioc
->FreeQlock
, flags
);
2591 /* Attach the SCSI Host to the IOC structure
2599 /* set 16 byte cdb's */
2600 sh
->max_cmd_len
= 16;
2602 sh
->max_id
= ioc
->pfacts
->MaxDevices
+ 1;
2604 sh
->transportt
= mptsas_transport_template
;
2606 sh
->max_lun
= MPT_LAST_LUN
+ 1;
2607 sh
->max_channel
= 0;
2608 sh
->this_id
= ioc
->pfacts
[0].PortSCSIID
;
2612 sh
->unique_id
= ioc
->id
;
2614 INIT_LIST_HEAD(&ioc
->sas_topology
);
2615 mutex_init(&ioc
->sas_topology_mutex
);
2616 mutex_init(&ioc
->sas_discovery_mutex
);
2617 mutex_init(&ioc
->sas_mgmt
.mutex
);
2618 init_completion(&ioc
->sas_mgmt
.done
);
2620 /* Verify that we won't exceed the maximum
2621 * number of chain buffers
2622 * We can optimize: ZZ = req_sz/sizeof(SGE)
2624 * numSGE = 1 + (ZZ-1)*(maxChain -1) + ZZ
2625 * + (req_sz - 64)/sizeof(SGE)
2626 * A slightly different algorithm is required for
2629 scale
= ioc
->req_sz
/(sizeof(dma_addr_t
) + sizeof(u32
));
2630 if (sizeof(dma_addr_t
) == sizeof(u64
)) {
2631 numSGE
= (scale
- 1) *
2632 (ioc
->facts
.MaxChainDepth
-1) + scale
+
2633 (ioc
->req_sz
- 60) / (sizeof(dma_addr_t
) +
2636 numSGE
= 1 + (scale
- 1) *
2637 (ioc
->facts
.MaxChainDepth
-1) + scale
+
2638 (ioc
->req_sz
- 64) / (sizeof(dma_addr_t
) +
2642 if (numSGE
< sh
->sg_tablesize
) {
2643 /* Reset this value */
2644 dprintk((MYIOC_s_INFO_FMT
2645 "Resetting sg_tablesize to %d from %d\n",
2646 ioc
->name
, numSGE
, sh
->sg_tablesize
));
2647 sh
->sg_tablesize
= numSGE
;
2650 spin_unlock_irqrestore(&ioc
->FreeQlock
, flags
);
2652 hd
= (MPT_SCSI_HOST
*) sh
->hostdata
;
2655 /* SCSI needs scsi_cmnd lookup table!
2656 * (with size equal to req_depth*PtrSz!)
2658 hd
->ScsiLookup
= kcalloc(ioc
->req_depth
, sizeof(void *), GFP_ATOMIC
);
2659 if (!hd
->ScsiLookup
) {
2661 goto out_mptsas_probe
;
2664 dprintk((MYIOC_s_INFO_FMT
"ScsiLookup @ %p\n",
2665 ioc
->name
, hd
->ScsiLookup
));
2667 /* Allocate memory for the device structures.
2668 * A non-Null pointer at an offset
2669 * indicates a device exists.
2670 * max_id = 1 + maximum id (hosts.h)
2672 hd
->Targets
= kcalloc(sh
->max_id
, sizeof(void *), GFP_ATOMIC
);
2675 goto out_mptsas_probe
;
2678 dprintk((KERN_INFO
" vtarget @ %p\n", hd
->Targets
));
2680 /* Clear the TM flags
2683 hd
->tmState
= TM_STATE_NONE
;
2684 hd
->resetPending
= 0;
2685 hd
->abortSCpnt
= NULL
;
2687 /* Clear the pointer used to store
2688 * single-threaded commands, i.e., those
2689 * issued during a bus scan, dv and
2690 * configuration pages.
2694 /* Initialize this SCSI Hosts' timers
2695 * To use, set the timer expires field
2698 init_timer(&hd
->timer
);
2699 hd
->timer
.data
= (unsigned long) hd
;
2700 hd
->timer
.function
= mptscsih_timer_expired
;
2702 hd
->mpt_pq_filter
= mpt_pq_filter
;
2703 ioc
->sas_data
.ptClear
= mpt_pt_clear
;
2705 if (ioc
->sas_data
.ptClear
==1) {
2706 mptbase_sas_persist_operation(
2707 ioc
, MPI_SAS_OP_CLEAR_ALL_PERSISTENT
);
2710 ddvprintk((MYIOC_s_INFO_FMT
2711 "mpt_pq_filter %x mpt_pq_filter %x\n",
2716 init_waitqueue_head(&hd
->scandv_waitq
);
2717 hd
->scandv_wait_done
= 0;
2718 hd
->last_queue_full
= 0;
2720 error
= scsi_add_host(sh
, &ioc
->pcidev
->dev
);
2722 dprintk((KERN_ERR MYNAM
2723 "scsi_add_host failed\n"));
2724 goto out_mptsas_probe
;
2727 mptsas_scan_sas_topology(ioc
);
2733 mptscsih_remove(pdev
);
2737 static void __devexit
mptsas_remove(struct pci_dev
*pdev
)
2739 MPT_ADAPTER
*ioc
= pci_get_drvdata(pdev
);
2740 struct mptsas_portinfo
*p
, *n
;
2743 ioc
->sas_discovery_ignore_events
=1;
2744 sas_remove_host(ioc
->sh
);
2746 mutex_lock(&ioc
->sas_topology_mutex
);
2747 list_for_each_entry_safe(p
, n
, &ioc
->sas_topology
, list
) {
2749 for (i
= 0 ; i
< p
->num_phys
; i
++)
2750 mptsas_port_delete(p
->phy_info
[i
].port_details
);
2754 mutex_unlock(&ioc
->sas_topology_mutex
);
2756 mptscsih_remove(pdev
);
2759 static struct pci_device_id mptsas_pci_table
[] = {
2760 { PCI_VENDOR_ID_LSI_LOGIC
, MPI_MANUFACTPAGE_DEVID_SAS1064
,
2761 PCI_ANY_ID
, PCI_ANY_ID
},
2762 { PCI_VENDOR_ID_LSI_LOGIC
, MPI_MANUFACTPAGE_DEVID_SAS1068
,
2763 PCI_ANY_ID
, PCI_ANY_ID
},
2764 { PCI_VENDOR_ID_LSI_LOGIC
, MPI_MANUFACTPAGE_DEVID_SAS1064E
,
2765 PCI_ANY_ID
, PCI_ANY_ID
},
2766 { PCI_VENDOR_ID_LSI_LOGIC
, MPI_MANUFACTPAGE_DEVID_SAS1068E
,
2767 PCI_ANY_ID
, PCI_ANY_ID
},
2768 { PCI_VENDOR_ID_LSI_LOGIC
, MPI_MANUFACTPAGE_DEVID_SAS1078
,
2769 PCI_ANY_ID
, PCI_ANY_ID
},
2770 {0} /* Terminating entry */
2772 MODULE_DEVICE_TABLE(pci
, mptsas_pci_table
);
2775 static struct pci_driver mptsas_driver
= {
2777 .id_table
= mptsas_pci_table
,
2778 .probe
= mptsas_probe
,
2779 .remove
= __devexit_p(mptsas_remove
),
2780 .shutdown
= mptscsih_shutdown
,
2782 .suspend
= mptscsih_suspend
,
2783 .resume
= mptscsih_resume
,
2790 show_mptmod_ver(my_NAME
, my_VERSION
);
2792 mptsas_transport_template
=
2793 sas_attach_transport(&mptsas_transport_functions
);
2794 if (!mptsas_transport_template
)
2797 mptsasDoneCtx
= mpt_register(mptscsih_io_done
, MPTSAS_DRIVER
);
2798 mptsasTaskCtx
= mpt_register(mptscsih_taskmgmt_complete
, MPTSAS_DRIVER
);
2800 mpt_register(mptscsih_scandv_complete
, MPTSAS_DRIVER
);
2801 mptsasMgmtCtx
= mpt_register(mptsas_mgmt_done
, MPTSAS_DRIVER
);
2803 if (mpt_event_register(mptsasDoneCtx
, mptsas_event_process
) == 0) {
2804 devtverboseprintk((KERN_INFO MYNAM
2805 ": Registered for IOC event notifications\n"));
2808 if (mpt_reset_register(mptsasDoneCtx
, mptscsih_ioc_reset
) == 0) {
2809 dprintk((KERN_INFO MYNAM
2810 ": Registered for IOC reset notifications\n"));
2813 return pci_register_driver(&mptsas_driver
);
2819 pci_unregister_driver(&mptsas_driver
);
2820 sas_release_transport(mptsas_transport_template
);
2822 mpt_reset_deregister(mptsasDoneCtx
);
2823 mpt_event_deregister(mptsasDoneCtx
);
2825 mpt_deregister(mptsasMgmtCtx
);
2826 mpt_deregister(mptsasInternalCtx
);
2827 mpt_deregister(mptsasTaskCtx
);
2828 mpt_deregister(mptsasDoneCtx
);
2831 module_init(mptsas_init
);
2832 module_exit(mptsas_exit
);