2 * linux/drivers/message/fusion/mptfc.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)
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 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
46 #include "linux_compat.h" /* linux-2.6 tweaks */
47 #include <linux/module.h>
48 #include <linux/kernel.h>
49 #include <linux/init.h>
50 #include <linux/errno.h>
51 #include <linux/kdev_t.h>
52 #include <linux/blkdev.h>
53 #include <linux/delay.h> /* for mdelay */
54 #include <linux/interrupt.h> /* needed for in_interrupt() proto */
55 #include <linux/reboot.h> /* notifier code */
56 #include <linux/sched.h>
57 #include <linux/workqueue.h>
58 #include <linux/sort.h>
60 #include <scsi/scsi.h>
61 #include <scsi/scsi_cmnd.h>
62 #include <scsi/scsi_device.h>
63 #include <scsi/scsi_host.h>
64 #include <scsi/scsi_tcq.h>
65 #include <scsi/scsi_transport_fc.h>
70 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
71 #define my_NAME "Fusion MPT FC Host driver"
72 #define my_VERSION MPT_LINUX_VERSION_COMMON
75 MODULE_AUTHOR(MODULEAUTHOR
);
76 MODULE_DESCRIPTION(my_NAME
);
77 MODULE_LICENSE("GPL");
79 /* Command line args */
80 #define MPTFC_DEV_LOSS_TMO (60)
81 static int mptfc_dev_loss_tmo
= MPTFC_DEV_LOSS_TMO
; /* reasonable default */
82 module_param(mptfc_dev_loss_tmo
, int, 0);
83 MODULE_PARM_DESC(mptfc_dev_loss_tmo
, " Initial time the driver programs the "
84 " transport to wait for an rport to "
85 " return following a device loss event."
88 static int mptfcDoneCtx
= -1;
89 static int mptfcTaskCtx
= -1;
90 static int mptfcInternalCtx
= -1; /* Used only for internal commands */
92 static int mptfc_target_alloc(struct scsi_target
*starget
);
93 static int mptfc_slave_alloc(struct scsi_device
*sdev
);
94 static int mptfc_qcmd(struct scsi_cmnd
*SCpnt
,
95 void (*done
)(struct scsi_cmnd
*));
96 static void mptfc_target_destroy(struct scsi_target
*starget
);
97 static void mptfc_set_rport_loss_tmo(struct fc_rport
*rport
, uint32_t timeout
);
98 static void __devexit
mptfc_remove(struct pci_dev
*pdev
);
100 static struct scsi_host_template mptfc_driver_template
= {
101 .module
= THIS_MODULE
,
102 .proc_name
= "mptfc",
103 .proc_info
= mptscsih_proc_info
,
104 .name
= "MPT FC Host",
105 .info
= mptscsih_info
,
106 .queuecommand
= mptfc_qcmd
,
107 .target_alloc
= mptfc_target_alloc
,
108 .slave_alloc
= mptfc_slave_alloc
,
109 .slave_configure
= mptscsih_slave_configure
,
110 .target_destroy
= mptfc_target_destroy
,
111 .slave_destroy
= mptscsih_slave_destroy
,
112 .change_queue_depth
= mptscsih_change_queue_depth
,
113 .eh_abort_handler
= mptscsih_abort
,
114 .eh_device_reset_handler
= mptscsih_dev_reset
,
115 .eh_bus_reset_handler
= mptscsih_bus_reset
,
116 .eh_host_reset_handler
= mptscsih_host_reset
,
117 .bios_param
= mptscsih_bios_param
,
118 .can_queue
= MPT_FC_CAN_QUEUE
,
120 .sg_tablesize
= MPT_SCSI_SG_DEPTH
,
123 .use_clustering
= ENABLE_CLUSTERING
,
126 /****************************************************************************
130 static struct pci_device_id mptfc_pci_table
[] = {
131 { PCI_VENDOR_ID_LSI_LOGIC
, MPI_MANUFACTPAGE_DEVICEID_FC909
,
132 PCI_ANY_ID
, PCI_ANY_ID
},
133 { PCI_VENDOR_ID_LSI_LOGIC
, MPI_MANUFACTPAGE_DEVICEID_FC919
,
134 PCI_ANY_ID
, PCI_ANY_ID
},
135 { PCI_VENDOR_ID_LSI_LOGIC
, MPI_MANUFACTPAGE_DEVICEID_FC929
,
136 PCI_ANY_ID
, PCI_ANY_ID
},
137 { PCI_VENDOR_ID_LSI_LOGIC
, MPI_MANUFACTPAGE_DEVICEID_FC919X
,
138 PCI_ANY_ID
, PCI_ANY_ID
},
139 { PCI_VENDOR_ID_LSI_LOGIC
, MPI_MANUFACTPAGE_DEVICEID_FC929X
,
140 PCI_ANY_ID
, PCI_ANY_ID
},
141 { PCI_VENDOR_ID_LSI_LOGIC
, MPI_MANUFACTPAGE_DEVICEID_FC939X
,
142 PCI_ANY_ID
, PCI_ANY_ID
},
143 { PCI_VENDOR_ID_LSI_LOGIC
, MPI_MANUFACTPAGE_DEVICEID_FC949X
,
144 PCI_ANY_ID
, PCI_ANY_ID
},
145 { PCI_VENDOR_ID_LSI_LOGIC
, MPI_MANUFACTPAGE_DEVICEID_FC949E
,
146 PCI_ANY_ID
, PCI_ANY_ID
},
147 {0} /* Terminating entry */
149 MODULE_DEVICE_TABLE(pci
, mptfc_pci_table
);
151 static struct scsi_transport_template
*mptfc_transport_template
= NULL
;
153 static struct fc_function_template mptfc_transport_functions
= {
154 .dd_fcrport_size
= 8,
155 .show_host_node_name
= 1,
156 .show_host_port_name
= 1,
157 .show_host_supported_classes
= 1,
158 .show_host_port_id
= 1,
159 .show_rport_supported_classes
= 1,
160 .show_starget_node_name
= 1,
161 .show_starget_port_name
= 1,
162 .show_starget_port_id
= 1,
163 .set_rport_dev_loss_tmo
= mptfc_set_rport_loss_tmo
,
164 .show_rport_dev_loss_tmo
= 1,
165 .show_host_supported_speeds
= 1,
166 .show_host_maxframe_size
= 1,
167 .show_host_speed
= 1,
168 .show_host_fabric_name
= 1,
169 .show_host_port_type
= 1,
170 .show_host_port_state
= 1,
171 .show_host_symbolic_name
= 1,
175 mptfc_set_rport_loss_tmo(struct fc_rport
*rport
, uint32_t timeout
)
178 rport
->dev_loss_tmo
= timeout
;
180 rport
->dev_loss_tmo
= mptfc_dev_loss_tmo
;
184 mptfc_FcDevPage0_cmp_func(const void *a
, const void *b
)
186 FCDevicePage0_t
**aa
= (FCDevicePage0_t
**)a
;
187 FCDevicePage0_t
**bb
= (FCDevicePage0_t
**)b
;
189 if ((*aa
)->CurrentBus
== (*bb
)->CurrentBus
) {
190 if ((*aa
)->CurrentTargetID
== (*bb
)->CurrentTargetID
)
192 if ((*aa
)->CurrentTargetID
< (*bb
)->CurrentTargetID
)
196 if ((*aa
)->CurrentBus
< (*bb
)->CurrentBus
)
202 mptfc_GetFcDevPage0(MPT_ADAPTER
*ioc
, int ioc_port
,
203 void(*func
)(MPT_ADAPTER
*ioc
,int channel
, FCDevicePage0_t
*arg
))
205 ConfigPageHeader_t hdr
;
207 FCDevicePage0_t
*ppage0_alloc
, *fc
;
208 dma_addr_t page0_dma
;
212 FCDevicePage0_t
*p0_array
=NULL
, *p_p0
;
213 FCDevicePage0_t
**pp0_array
=NULL
, **p_pp0
;
216 U32 port_id
= 0xffffff;
218 int max_bus
= ioc
->facts
.MaxBuses
;
219 int max_targ
= ioc
->facts
.MaxDevices
;
221 if (max_bus
== 0 || max_targ
== 0)
224 data_sz
= sizeof(FCDevicePage0_t
) * max_bus
* max_targ
;
225 p_p0
= p0_array
= kzalloc(data_sz
, GFP_KERNEL
);
229 data_sz
= sizeof(FCDevicePage0_t
*) * max_bus
* max_targ
;
230 p_pp0
= pp0_array
= kzalloc(data_sz
, GFP_KERNEL
);
235 /* Get FC Device Page 0 header */
239 hdr
.PageType
= MPI_CONFIG_PAGETYPE_FC_DEVICE
;
240 cfg
.cfghdr
.hdr
= &hdr
;
242 cfg
.action
= MPI_CONFIG_ACTION_PAGE_HEADER
;
244 cfg
.pageAddr
= port_id
;
247 if ((rc
= mpt_config(ioc
, &cfg
)) != 0)
250 if (hdr
.PageLength
<= 0)
253 data_sz
= hdr
.PageLength
* 4;
254 ppage0_alloc
= pci_alloc_consistent(ioc
->pcidev
, data_sz
,
260 cfg
.physAddr
= page0_dma
;
261 cfg
.action
= MPI_CONFIG_ACTION_PAGE_READ_CURRENT
;
263 if ((rc
= mpt_config(ioc
, &cfg
)) == 0) {
264 ppage0_alloc
->PortIdentifier
=
265 le32_to_cpu(ppage0_alloc
->PortIdentifier
);
267 ppage0_alloc
->WWNN
.Low
=
268 le32_to_cpu(ppage0_alloc
->WWNN
.Low
);
270 ppage0_alloc
->WWNN
.High
=
271 le32_to_cpu(ppage0_alloc
->WWNN
.High
);
273 ppage0_alloc
->WWPN
.Low
=
274 le32_to_cpu(ppage0_alloc
->WWPN
.Low
);
276 ppage0_alloc
->WWPN
.High
=
277 le32_to_cpu(ppage0_alloc
->WWPN
.High
);
279 ppage0_alloc
->BBCredit
=
280 le16_to_cpu(ppage0_alloc
->BBCredit
);
282 ppage0_alloc
->MaxRxFrameSize
=
283 le16_to_cpu(ppage0_alloc
->MaxRxFrameSize
);
285 port_id
= ppage0_alloc
->PortIdentifier
;
287 *p_p0
= *ppage0_alloc
; /* save data */
288 *p_pp0
++ = p_p0
++; /* save addr */
290 pci_free_consistent(ioc
->pcidev
, data_sz
,
291 (u8
*) ppage0_alloc
, page0_dma
);
295 } while (port_id
<= 0xff0000);
300 sort (pp0_array
, num_targ
, sizeof(FCDevicePage0_t
*),
301 mptfc_FcDevPage0_cmp_func
, NULL
);
302 /* call caller's func for each targ */
303 for (ii
= 0; ii
< num_targ
; ii
++) {
304 fc
= *(pp0_array
+ii
);
305 func(ioc
, ioc_port
, fc
);
316 mptfc_generate_rport_ids(FCDevicePage0_t
*pg0
, struct fc_rport_identifiers
*rid
)
318 /* not currently usable */
319 if (pg0
->Flags
& (MPI_FC_DEVICE_PAGE0_FLAGS_PLOGI_INVALID
|
320 MPI_FC_DEVICE_PAGE0_FLAGS_PRLI_INVALID
))
323 if (!(pg0
->Flags
& MPI_FC_DEVICE_PAGE0_FLAGS_TARGETID_BUS_VALID
))
326 if (!(pg0
->Protocol
& MPI_FC_DEVICE_PAGE0_PROT_FCP_TARGET
))
330 * board data structure already normalized to platform endianness
331 * shifted to avoid unaligned access on 64 bit architecture
333 rid
->node_name
= ((u64
)pg0
->WWNN
.High
) << 32 | (u64
)pg0
->WWNN
.Low
;
334 rid
->port_name
= ((u64
)pg0
->WWPN
.High
) << 32 | (u64
)pg0
->WWPN
.Low
;
335 rid
->port_id
= pg0
->PortIdentifier
;
336 rid
->roles
= FC_RPORT_ROLE_UNKNOWN
;
342 mptfc_register_dev(MPT_ADAPTER
*ioc
, int channel
, FCDevicePage0_t
*pg0
)
344 struct fc_rport_identifiers rport_ids
;
345 struct fc_rport
*rport
;
346 struct mptfc_rport_info
*ri
;
350 u32 roles
= FC_RPORT_ROLE_UNKNOWN
;
352 if (mptfc_generate_rport_ids(pg0
, &rport_ids
) < 0)
355 roles
|= FC_RPORT_ROLE_FCP_TARGET
;
356 if (pg0
->Protocol
& MPI_FC_DEVICE_PAGE0_PROT_FCP_INITIATOR
)
357 roles
|= FC_RPORT_ROLE_FCP_INITIATOR
;
359 /* scan list looking for a match */
360 list_for_each_entry(ri
, &ioc
->fc_rports
, list
) {
361 pn
= (u64
)ri
->pg0
.WWPN
.High
<< 32 | (u64
)ri
->pg0
.WWPN
.Low
;
362 if (pn
== rport_ids
.port_name
) { /* match */
363 list_move_tail(&ri
->list
, &ioc
->fc_rports
);
368 if (new_ri
) { /* allocate one */
369 ri
= kzalloc(sizeof(struct mptfc_rport_info
), GFP_KERNEL
);
372 list_add_tail(&ri
->list
, &ioc
->fc_rports
);
375 ri
->pg0
= *pg0
; /* add/update pg0 data */
376 ri
->flags
&= ~MPT_RPORT_INFO_FLAGS_MISSING
;
378 /* MPT_RPORT_INFO_FLAGS_REGISTERED - rport not previously deleted */
379 if (!(ri
->flags
& MPT_RPORT_INFO_FLAGS_REGISTERED
)) {
380 ri
->flags
|= MPT_RPORT_INFO_FLAGS_REGISTERED
;
381 rport
= fc_remote_port_add(ioc
->sh
, channel
, &rport_ids
);
384 if (new_ri
) /* may have been reset by user */
385 rport
->dev_loss_tmo
= mptfc_dev_loss_tmo
;
387 * if already mapped, remap here. If not mapped,
388 * target_alloc will allocate vtarget and map,
389 * slave_alloc will fill in vdev from vtarget.
392 vtarget
= ri
->starget
->hostdata
;
394 vtarget
->target_id
= pg0
->CurrentTargetID
;
395 vtarget
->bus_id
= pg0
->CurrentBus
;
398 *((struct mptfc_rport_info
**)rport
->dd_data
) = ri
;
399 /* scan will be scheduled once rport becomes a target */
400 fc_remote_port_rolechg(rport
,roles
);
402 pn
= (u64
)ri
->pg0
.WWPN
.High
<< 32 | (u64
)ri
->pg0
.WWPN
.Low
;
403 nn
= (u64
)ri
->pg0
.WWNN
.High
<< 32 | (u64
)ri
->pg0
.WWNN
.Low
;
404 dfcprintk ((MYIOC_s_INFO_FMT
405 "mptfc_reg_dev.%d: %x, %llx / %llx, tid %d, "
406 "rport tid %d, tmo %d\n",
410 (unsigned long long)nn
,
411 (unsigned long long)pn
,
412 pg0
->CurrentTargetID
,
413 ri
->rport
->scsi_target_id
,
414 ri
->rport
->dev_loss_tmo
));
424 * OS entry point to allow for host driver to free allocated memory
425 * Called if no device present or device being unloaded
428 mptfc_target_destroy(struct scsi_target
*starget
)
430 struct fc_rport
*rport
;
431 struct mptfc_rport_info
*ri
;
433 rport
= starget_to_rport(starget
);
435 ri
= *((struct mptfc_rport_info
**)rport
->dd_data
);
436 if (ri
) /* better be! */
439 if (starget
->hostdata
)
440 kfree(starget
->hostdata
);
441 starget
->hostdata
= NULL
;
445 * OS entry point to allow host driver to alloc memory
446 * for each scsi target. Called once per device the bus scan.
447 * Return non-zero if allocation fails.
450 mptfc_target_alloc(struct scsi_target
*starget
)
453 struct fc_rport
*rport
;
454 struct mptfc_rport_info
*ri
;
457 vtarget
= kzalloc(sizeof(VirtTarget
), GFP_KERNEL
);
460 starget
->hostdata
= vtarget
;
463 rport
= starget_to_rport(starget
);
465 ri
= *((struct mptfc_rport_info
**)rport
->dd_data
);
466 if (ri
) { /* better be! */
467 vtarget
->target_id
= ri
->pg0
.CurrentTargetID
;
468 vtarget
->bus_id
= ri
->pg0
.CurrentBus
;
469 ri
->starget
= starget
;
475 starget
->hostdata
= NULL
;
482 * OS entry point to allow host driver to alloc memory
483 * for each scsi device. Called once per device the bus scan.
484 * Return non-zero if allocation fails.
485 * Init memory once per LUN.
488 mptfc_slave_alloc(struct scsi_device
*sdev
)
493 struct scsi_target
*starget
;
494 struct fc_rport
*rport
;
497 starget
= scsi_target(sdev
);
498 rport
= starget_to_rport(starget
);
500 if (!rport
|| fc_remote_port_chkready(rport
))
503 hd
= (MPT_SCSI_HOST
*)sdev
->host
->hostdata
;
505 vdev
= kzalloc(sizeof(VirtDevice
), GFP_KERNEL
);
507 printk(MYIOC_s_ERR_FMT
"slave_alloc kmalloc(%zd) FAILED!\n",
508 hd
->ioc
->name
, sizeof(VirtDevice
));
513 sdev
->hostdata
= vdev
;
514 vtarget
= starget
->hostdata
;
516 if (vtarget
->num_luns
== 0) {
517 vtarget
->ioc_id
= hd
->ioc
->id
;
518 vtarget
->tflags
= MPT_TARGET_FLAGS_Q_YES
;
519 hd
->Targets
[sdev
->id
] = vtarget
;
522 vdev
->vtarget
= vtarget
;
523 vdev
->lun
= sdev
->lun
;
531 struct mptfc_rport_info
*ri
;
532 ri
= *((struct mptfc_rport_info
**)rport
->dd_data
);
533 pn
= (u64
)ri
->pg0
.WWPN
.High
<< 32 | (u64
)ri
->pg0
.WWPN
.Low
;
534 nn
= (u64
)ri
->pg0
.WWNN
.High
<< 32 | (u64
)ri
->pg0
.WWNN
.Low
;
535 dfcprintk ((MYIOC_s_INFO_FMT
536 "mptfc_slv_alloc.%d: num_luns %d, sdev.id %d, "
537 "CurrentTargetID %d, %x %llx %llx\n",
541 sdev
->id
, ri
->pg0
.CurrentTargetID
,
542 ri
->pg0
.PortIdentifier
,
543 (unsigned long long)pn
,
544 (unsigned long long)nn
));
552 mptfc_qcmd(struct scsi_cmnd
*SCpnt
, void (*done
)(struct scsi_cmnd
*))
554 struct mptfc_rport_info
*ri
;
555 struct fc_rport
*rport
= starget_to_rport(scsi_target(SCpnt
->device
));
558 err
= fc_remote_port_chkready(rport
);
565 /* dd_data is null until finished adding target */
566 ri
= *((struct mptfc_rport_info
**)rport
->dd_data
);
568 dfcprintk ((MYIOC_s_INFO_FMT
569 "mptfc_qcmd.%d: %d:%d, dd_data is null.\n",
570 ((MPT_SCSI_HOST
*) SCpnt
->device
->host
->hostdata
)->ioc
->name
,
571 ((MPT_SCSI_HOST
*) SCpnt
->device
->host
->hostdata
)->ioc
->sh
->host_no
,
572 SCpnt
->device
->id
,SCpnt
->device
->lun
));
573 SCpnt
->result
= DID_IMM_RETRY
<< 16;
578 err
= mptscsih_qcmd(SCpnt
,done
);
581 dfcprintk ((MYIOC_s_INFO_FMT
582 "mptfc_qcmd.%d: %d:%d, mptscsih_qcmd returns non-zero, (%x).\n",
583 ((MPT_SCSI_HOST
*) SCpnt
->device
->host
->hostdata
)->ioc
->name
,
584 ((MPT_SCSI_HOST
*) SCpnt
->device
->host
->hostdata
)->ioc
->sh
->host_no
,
585 SCpnt
->device
->id
,SCpnt
->device
->lun
,err
));
592 * mptfc_GetFcPortPage0 - Fetch FCPort config Page0.
593 * @ioc: Pointer to MPT_ADAPTER structure
594 * @portnum: IOC Port number
596 * Return: 0 for success
597 * -ENOMEM if no memory available
598 * -EPERM if not allowed due to ISR context
599 * -EAGAIN if no msg frames currently available
600 * -EFAULT for non-successful reply or no reply (timeout)
601 * -EINVAL portnum arg out of range (hardwired to two elements)
604 mptfc_GetFcPortPage0(MPT_ADAPTER
*ioc
, int portnum
)
606 ConfigPageHeader_t hdr
;
608 FCPortPage0_t
*ppage0_alloc
;
609 FCPortPage0_t
*pp0dest
;
610 dma_addr_t page0_dma
;
619 /* Get FCPort Page 0 header */
623 hdr
.PageType
= MPI_CONFIG_PAGETYPE_FC_PORT
;
624 cfg
.cfghdr
.hdr
= &hdr
;
626 cfg
.action
= MPI_CONFIG_ACTION_PAGE_HEADER
;
628 cfg
.pageAddr
= portnum
;
631 if ((rc
= mpt_config(ioc
, &cfg
)) != 0)
634 if (hdr
.PageLength
== 0)
637 data_sz
= hdr
.PageLength
* 4;
639 ppage0_alloc
= (FCPortPage0_t
*) pci_alloc_consistent(ioc
->pcidev
, data_sz
, &page0_dma
);
643 memset((u8
*)ppage0_alloc
, 0, data_sz
);
644 cfg
.physAddr
= page0_dma
;
645 cfg
.action
= MPI_CONFIG_ACTION_PAGE_READ_CURRENT
;
647 if ((rc
= mpt_config(ioc
, &cfg
)) == 0) {
649 pp0dest
= &ioc
->fc_port_page0
[portnum
];
650 copy_sz
= min_t(int, sizeof(FCPortPage0_t
), data_sz
);
651 memcpy(pp0dest
, ppage0_alloc
, copy_sz
);
654 * Normalize endianness of structure data,
655 * by byte-swapping all > 1 byte fields!
657 pp0dest
->Flags
= le32_to_cpu(pp0dest
->Flags
);
658 pp0dest
->PortIdentifier
= le32_to_cpu(pp0dest
->PortIdentifier
);
659 pp0dest
->WWNN
.Low
= le32_to_cpu(pp0dest
->WWNN
.Low
);
660 pp0dest
->WWNN
.High
= le32_to_cpu(pp0dest
->WWNN
.High
);
661 pp0dest
->WWPN
.Low
= le32_to_cpu(pp0dest
->WWPN
.Low
);
662 pp0dest
->WWPN
.High
= le32_to_cpu(pp0dest
->WWPN
.High
);
663 pp0dest
->SupportedServiceClass
= le32_to_cpu(pp0dest
->SupportedServiceClass
);
664 pp0dest
->SupportedSpeeds
= le32_to_cpu(pp0dest
->SupportedSpeeds
);
665 pp0dest
->CurrentSpeed
= le32_to_cpu(pp0dest
->CurrentSpeed
);
666 pp0dest
->MaxFrameSize
= le32_to_cpu(pp0dest
->MaxFrameSize
);
667 pp0dest
->FabricWWNN
.Low
= le32_to_cpu(pp0dest
->FabricWWNN
.Low
);
668 pp0dest
->FabricWWNN
.High
= le32_to_cpu(pp0dest
->FabricWWNN
.High
);
669 pp0dest
->FabricWWPN
.Low
= le32_to_cpu(pp0dest
->FabricWWPN
.Low
);
670 pp0dest
->FabricWWPN
.High
= le32_to_cpu(pp0dest
->FabricWWPN
.High
);
671 pp0dest
->DiscoveredPortsCount
= le32_to_cpu(pp0dest
->DiscoveredPortsCount
);
672 pp0dest
->MaxInitiators
= le32_to_cpu(pp0dest
->MaxInitiators
);
675 * if still doing discovery,
676 * hang loose a while until finished
678 if ((pp0dest
->PortState
== MPI_FCPORTPAGE0_PORTSTATE_UNKNOWN
) ||
679 (pp0dest
->PortState
== MPI_FCPORTPAGE0_PORTSTATE_ONLINE
&&
680 (pp0dest
->Flags
& MPI_FCPORTPAGE0_FLAGS_ATTACH_TYPE_MASK
)
681 == MPI_FCPORTPAGE0_FLAGS_ATTACH_NO_INIT
)) {
686 printk(MYIOC_s_INFO_FMT
"Firmware discovery not"
692 pci_free_consistent(ioc
->pcidev
, data_sz
, (u8
*) ppage0_alloc
, page0_dma
);
699 mptfc_WriteFcPortPage1(MPT_ADAPTER
*ioc
, int portnum
)
701 ConfigPageHeader_t hdr
;
708 if (!(ioc
->fc_data
.fc_port_page1
[portnum
].data
))
711 /* get fcport page 1 header */
715 hdr
.PageType
= MPI_CONFIG_PAGETYPE_FC_PORT
;
716 cfg
.cfghdr
.hdr
= &hdr
;
718 cfg
.action
= MPI_CONFIG_ACTION_PAGE_HEADER
;
720 cfg
.pageAddr
= portnum
;
723 if ((rc
= mpt_config(ioc
, &cfg
)) != 0)
726 if (hdr
.PageLength
== 0)
729 if (hdr
.PageLength
*4 != ioc
->fc_data
.fc_port_page1
[portnum
].pg_sz
)
732 cfg
.physAddr
= ioc
->fc_data
.fc_port_page1
[portnum
].dma
;
733 cfg
.action
= MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT
;
736 rc
= mpt_config(ioc
, &cfg
);
742 mptfc_GetFcPortPage1(MPT_ADAPTER
*ioc
, int portnum
)
744 ConfigPageHeader_t hdr
;
746 FCPortPage1_t
*page1_alloc
;
747 dma_addr_t page1_dma
;
754 /* get fcport page 1 header */
758 hdr
.PageType
= MPI_CONFIG_PAGETYPE_FC_PORT
;
759 cfg
.cfghdr
.hdr
= &hdr
;
761 cfg
.action
= MPI_CONFIG_ACTION_PAGE_HEADER
;
763 cfg
.pageAddr
= portnum
;
766 if ((rc
= mpt_config(ioc
, &cfg
)) != 0)
769 if (hdr
.PageLength
== 0)
774 if (ioc
->fc_data
.fc_port_page1
[portnum
].data
== NULL
) {
775 data_sz
= hdr
.PageLength
* 4;
776 if (data_sz
< sizeof(FCPortPage1_t
))
777 data_sz
= sizeof(FCPortPage1_t
);
779 page1_alloc
= (FCPortPage1_t
*) pci_alloc_consistent(ioc
->pcidev
,
786 page1_alloc
= ioc
->fc_data
.fc_port_page1
[portnum
].data
;
787 page1_dma
= ioc
->fc_data
.fc_port_page1
[portnum
].dma
;
788 data_sz
= ioc
->fc_data
.fc_port_page1
[portnum
].pg_sz
;
789 if (hdr
.PageLength
* 4 > data_sz
) {
790 ioc
->fc_data
.fc_port_page1
[portnum
].data
= NULL
;
791 pci_free_consistent(ioc
->pcidev
, data_sz
, (u8
*)
792 page1_alloc
, page1_dma
);
797 memset(page1_alloc
,0,data_sz
);
799 cfg
.physAddr
= page1_dma
;
800 cfg
.action
= MPI_CONFIG_ACTION_PAGE_READ_CURRENT
;
802 if ((rc
= mpt_config(ioc
, &cfg
)) == 0) {
803 ioc
->fc_data
.fc_port_page1
[portnum
].data
= page1_alloc
;
804 ioc
->fc_data
.fc_port_page1
[portnum
].pg_sz
= data_sz
;
805 ioc
->fc_data
.fc_port_page1
[portnum
].dma
= page1_dma
;
808 ioc
->fc_data
.fc_port_page1
[portnum
].data
= NULL
;
809 pci_free_consistent(ioc
->pcidev
, data_sz
, (u8
*)
810 page1_alloc
, page1_dma
);
817 mptfc_SetFcPortPage1_defaults(MPT_ADAPTER
*ioc
)
822 #define MPTFC_FW_DEVICE_TIMEOUT (1)
823 #define MPTFC_FW_IO_PEND_TIMEOUT (1)
824 #define ON_FLAGS (MPI_FCPORTPAGE1_FLAGS_IMMEDIATE_ERROR_REPLY)
825 #define OFF_FLAGS (MPI_FCPORTPAGE1_FLAGS_VERBOSE_RESCAN_EVENTS)
827 for (ii
=0; ii
<ioc
->facts
.NumberOfPorts
; ii
++) {
828 if (mptfc_GetFcPortPage1(ioc
, ii
) != 0)
830 pp1
= ioc
->fc_data
.fc_port_page1
[ii
].data
;
831 if ((pp1
->InitiatorDeviceTimeout
== MPTFC_FW_DEVICE_TIMEOUT
)
832 && (pp1
->InitiatorIoPendTimeout
== MPTFC_FW_IO_PEND_TIMEOUT
)
833 && ((pp1
->Flags
& ON_FLAGS
) == ON_FLAGS
)
834 && ((pp1
->Flags
& OFF_FLAGS
) == 0))
836 pp1
->InitiatorDeviceTimeout
= MPTFC_FW_DEVICE_TIMEOUT
;
837 pp1
->InitiatorIoPendTimeout
= MPTFC_FW_IO_PEND_TIMEOUT
;
838 pp1
->Flags
&= ~OFF_FLAGS
;
839 pp1
->Flags
|= ON_FLAGS
;
840 mptfc_WriteFcPortPage1(ioc
, ii
);
846 mptfc_init_host_attr(MPT_ADAPTER
*ioc
,int portnum
)
854 struct Scsi_Host
*sh
;
857 /* don't know what to do as only one scsi (fc) host was allocated */
861 pp0
= &ioc
->fc_port_page0
[portnum
];
864 sn
= fc_host_symbolic_name(sh
);
865 snprintf(sn
, FC_SYMBOLIC_NAME_SIZE
, "%s %s%08xh",
867 MPT_FW_REV_MAGIC_ID_STRING
,
868 ioc
->facts
.FWVersion
.Word
);
870 fc_host_tgtid_bind_type(sh
) = FC_TGTID_BIND_BY_WWPN
;
872 fc_host_maxframe_size(sh
) = pp0
->MaxFrameSize
;
874 fc_host_node_name(sh
) =
875 (u64
)pp0
->WWNN
.High
<< 32 | (u64
)pp0
->WWNN
.Low
;
877 fc_host_port_name(sh
) =
878 (u64
)pp0
->WWPN
.High
<< 32 | (u64
)pp0
->WWPN
.Low
;
880 fc_host_port_id(sh
) = pp0
->PortIdentifier
;
882 class = pp0
->SupportedServiceClass
;
883 if (class & MPI_FCPORTPAGE0_SUPPORT_CLASS_1
)
884 cos
|= FC_COS_CLASS1
;
885 if (class & MPI_FCPORTPAGE0_SUPPORT_CLASS_2
)
886 cos
|= FC_COS_CLASS2
;
887 if (class & MPI_FCPORTPAGE0_SUPPORT_CLASS_3
)
888 cos
|= FC_COS_CLASS3
;
889 fc_host_supported_classes(sh
) = cos
;
891 if (pp0
->CurrentSpeed
== MPI_FCPORTPAGE0_CURRENT_SPEED_1GBIT
)
892 speed
= FC_PORTSPEED_1GBIT
;
893 else if (pp0
->CurrentSpeed
== MPI_FCPORTPAGE0_CURRENT_SPEED_2GBIT
)
894 speed
= FC_PORTSPEED_2GBIT
;
895 else if (pp0
->CurrentSpeed
== MPI_FCPORTPAGE0_CURRENT_SPEED_4GBIT
)
896 speed
= FC_PORTSPEED_4GBIT
;
897 else if (pp0
->CurrentSpeed
== MPI_FCPORTPAGE0_CURRENT_SPEED_10GBIT
)
898 speed
= FC_PORTSPEED_10GBIT
;
900 speed
= FC_PORTSPEED_UNKNOWN
;
901 fc_host_speed(sh
) = speed
;
904 if (pp0
->SupportedSpeeds
& MPI_FCPORTPAGE0_SUPPORT_1GBIT_SPEED
)
905 speed
|= FC_PORTSPEED_1GBIT
;
906 if (pp0
->SupportedSpeeds
& MPI_FCPORTPAGE0_SUPPORT_2GBIT_SPEED
)
907 speed
|= FC_PORTSPEED_2GBIT
;
908 if (pp0
->SupportedSpeeds
& MPI_FCPORTPAGE0_SUPPORT_4GBIT_SPEED
)
909 speed
|= FC_PORTSPEED_4GBIT
;
910 if (pp0
->SupportedSpeeds
& MPI_FCPORTPAGE0_SUPPORT_10GBIT_SPEED
)
911 speed
|= FC_PORTSPEED_10GBIT
;
912 fc_host_supported_speeds(sh
) = speed
;
914 port_state
= FC_PORTSTATE_UNKNOWN
;
915 if (pp0
->PortState
== MPI_FCPORTPAGE0_PORTSTATE_ONLINE
)
916 port_state
= FC_PORTSTATE_ONLINE
;
917 else if (pp0
->PortState
== MPI_FCPORTPAGE0_PORTSTATE_OFFLINE
)
918 port_state
= FC_PORTSTATE_LINKDOWN
;
919 fc_host_port_state(sh
) = port_state
;
921 port_type
= FC_PORTTYPE_UNKNOWN
;
922 if (pp0
->Flags
& MPI_FCPORTPAGE0_FLAGS_ATTACH_POINT_TO_POINT
)
923 port_type
= FC_PORTTYPE_PTP
;
924 else if (pp0
->Flags
& MPI_FCPORTPAGE0_FLAGS_ATTACH_PRIVATE_LOOP
)
925 port_type
= FC_PORTTYPE_LPORT
;
926 else if (pp0
->Flags
& MPI_FCPORTPAGE0_FLAGS_ATTACH_PUBLIC_LOOP
)
927 port_type
= FC_PORTTYPE_NLPORT
;
928 else if (pp0
->Flags
& MPI_FCPORTPAGE0_FLAGS_ATTACH_FABRIC_DIRECT
)
929 port_type
= FC_PORTTYPE_NPORT
;
930 fc_host_port_type(sh
) = port_type
;
932 fc_host_fabric_name(sh
) =
933 (pp0
->Flags
& MPI_FCPORTPAGE0_FLAGS_FABRIC_WWN_VALID
) ?
934 (u64
) pp0
->FabricWWNN
.High
<< 32 | (u64
) pp0
->FabricWWPN
.Low
:
935 (u64
)pp0
->WWNN
.High
<< 32 | (u64
)pp0
->WWNN
.Low
;
940 mptfc_setup_reset(void *arg
)
942 MPT_ADAPTER
*ioc
= (MPT_ADAPTER
*)arg
;
944 struct mptfc_rport_info
*ri
;
946 /* reset about to happen, delete (block) all rports */
947 list_for_each_entry(ri
, &ioc
->fc_rports
, list
) {
948 if (ri
->flags
& MPT_RPORT_INFO_FLAGS_REGISTERED
) {
949 ri
->flags
&= ~MPT_RPORT_INFO_FLAGS_REGISTERED
;
950 fc_remote_port_delete(ri
->rport
); /* won't sleep */
953 pn
= (u64
)ri
->pg0
.WWPN
.High
<< 32 |
954 (u64
)ri
->pg0
.WWPN
.Low
;
955 dfcprintk ((MYIOC_s_INFO_FMT
956 "mptfc_setup_reset.%d: %llx deleted\n",
959 (unsigned long long)pn
));
965 mptfc_rescan_devices(void *arg
)
967 MPT_ADAPTER
*ioc
= (MPT_ADAPTER
*)arg
;
970 struct mptfc_rport_info
*ri
;
972 /* start by tagging all ports as missing */
973 list_for_each_entry(ri
, &ioc
->fc_rports
, list
) {
974 if (ri
->flags
& MPT_RPORT_INFO_FLAGS_REGISTERED
) {
975 ri
->flags
|= MPT_RPORT_INFO_FLAGS_MISSING
;
980 * now rescan devices known to adapter,
981 * will reregister existing rports
983 for (ii
=0; ii
< ioc
->facts
.NumberOfPorts
; ii
++) {
984 (void) mptfc_GetFcPortPage0(ioc
, ii
);
985 mptfc_init_host_attr(ioc
, ii
); /* refresh */
986 mptfc_GetFcDevPage0(ioc
, ii
, mptfc_register_dev
);
989 /* delete devices still missing */
990 list_for_each_entry(ri
, &ioc
->fc_rports
, list
) {
991 /* if newly missing, delete it */
992 if (ri
->flags
& MPT_RPORT_INFO_FLAGS_MISSING
) {
994 ri
->flags
&= ~(MPT_RPORT_INFO_FLAGS_REGISTERED
|
995 MPT_RPORT_INFO_FLAGS_MISSING
);
996 fc_remote_port_delete(ri
->rport
); /* won't sleep */
999 pn
= (u64
)ri
->pg0
.WWPN
.High
<< 32 |
1000 (u64
)ri
->pg0
.WWPN
.Low
;
1001 dfcprintk ((MYIOC_s_INFO_FMT
1002 "mptfc_rescan.%d: %llx deleted\n",
1005 (unsigned long long)pn
));
1011 mptfc_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
1013 struct Scsi_Host
*sh
;
1016 unsigned long flags
;
1024 if ((r
= mpt_attach(pdev
,id
)) != 0)
1027 ioc
= pci_get_drvdata(pdev
);
1028 ioc
->DoneCtx
= mptfcDoneCtx
;
1029 ioc
->TaskCtx
= mptfcTaskCtx
;
1030 ioc
->InternalCtx
= mptfcInternalCtx
;
1032 /* Added sanity check on readiness of the MPT adapter.
1034 if (ioc
->last_state
!= MPI_IOC_STATE_OPERATIONAL
) {
1035 printk(MYIOC_s_WARN_FMT
1036 "Skipping because it's not operational!\n",
1039 goto out_mptfc_probe
;
1043 printk(MYIOC_s_WARN_FMT
"Skipping because it's disabled!\n",
1046 goto out_mptfc_probe
;
1049 /* Sanity check - ensure at least 1 port is INITIATOR capable
1052 for (ii
=0; ii
< ioc
->facts
.NumberOfPorts
; ii
++) {
1053 if (ioc
->pfacts
[ii
].ProtocolFlags
&
1054 MPI_PORTFACTS_PROTOCOL_INITIATOR
)
1059 printk(MYIOC_s_WARN_FMT
1060 "Skipping ioc=%p because SCSI Initiator mode is NOT enabled!\n",
1065 sh
= scsi_host_alloc(&mptfc_driver_template
, sizeof(MPT_SCSI_HOST
));
1068 printk(MYIOC_s_WARN_FMT
1069 "Unable to register controller with SCSI subsystem\n",
1072 goto out_mptfc_probe
;
1075 spin_lock_init(&ioc
->fc_rescan_work_lock
);
1076 INIT_WORK(&ioc
->fc_rescan_work
, mptfc_rescan_devices
,(void *)ioc
);
1077 INIT_WORK(&ioc
->fc_setup_reset_work
, mptfc_setup_reset
, (void *)ioc
);
1079 spin_lock_irqsave(&ioc
->FreeQlock
, flags
);
1081 /* Attach the SCSI Host to the IOC structure
1089 /* set 16 byte cdb's */
1090 sh
->max_cmd_len
= 16;
1092 sh
->max_id
= MPT_MAX_FC_DEVICES
<256 ? MPT_MAX_FC_DEVICES
: 255;
1094 sh
->max_lun
= MPT_LAST_LUN
+ 1;
1095 sh
->max_channel
= 0;
1096 sh
->this_id
= ioc
->pfacts
[0].PortSCSIID
;
1100 sh
->unique_id
= ioc
->id
;
1102 /* Verify that we won't exceed the maximum
1103 * number of chain buffers
1104 * We can optimize: ZZ = req_sz/sizeof(SGE)
1106 * numSGE = 1 + (ZZ-1)*(maxChain -1) + ZZ
1107 * + (req_sz - 64)/sizeof(SGE)
1108 * A slightly different algorithm is required for
1111 scale
= ioc
->req_sz
/(sizeof(dma_addr_t
) + sizeof(u32
));
1112 if (sizeof(dma_addr_t
) == sizeof(u64
)) {
1113 numSGE
= (scale
- 1) *
1114 (ioc
->facts
.MaxChainDepth
-1) + scale
+
1115 (ioc
->req_sz
- 60) / (sizeof(dma_addr_t
) +
1118 numSGE
= 1 + (scale
- 1) *
1119 (ioc
->facts
.MaxChainDepth
-1) + scale
+
1120 (ioc
->req_sz
- 64) / (sizeof(dma_addr_t
) +
1124 if (numSGE
< sh
->sg_tablesize
) {
1125 /* Reset this value */
1126 dprintk((MYIOC_s_INFO_FMT
1127 "Resetting sg_tablesize to %d from %d\n",
1128 ioc
->name
, numSGE
, sh
->sg_tablesize
));
1129 sh
->sg_tablesize
= numSGE
;
1132 spin_unlock_irqrestore(&ioc
->FreeQlock
, flags
);
1134 hd
= (MPT_SCSI_HOST
*) sh
->hostdata
;
1137 /* SCSI needs scsi_cmnd lookup table!
1138 * (with size equal to req_depth*PtrSz!)
1140 hd
->ScsiLookup
= kcalloc(ioc
->req_depth
, sizeof(void *), GFP_ATOMIC
);
1141 if (!hd
->ScsiLookup
) {
1143 goto out_mptfc_probe
;
1146 dprintk((MYIOC_s_INFO_FMT
"ScsiLookup @ %p\n",
1147 ioc
->name
, hd
->ScsiLookup
));
1149 /* Allocate memory for the device structures.
1150 * A non-Null pointer at an offset
1151 * indicates a device exists.
1152 * max_id = 1 + maximum id (hosts.h)
1154 hd
->Targets
= kcalloc(sh
->max_id
, sizeof(void *), GFP_ATOMIC
);
1157 goto out_mptfc_probe
;
1160 dprintk((KERN_INFO
" vdev @ %p\n", hd
->Targets
));
1162 /* Clear the TM flags
1165 hd
->tmState
= TM_STATE_NONE
;
1166 hd
->resetPending
= 0;
1167 hd
->abortSCpnt
= NULL
;
1169 /* Clear the pointer used to store
1170 * single-threaded commands, i.e., those
1171 * issued during a bus scan, dv and
1172 * configuration pages.
1176 /* Initialize this SCSI Hosts' timers
1177 * To use, set the timer expires field
1180 init_timer(&hd
->timer
);
1181 hd
->timer
.data
= (unsigned long) hd
;
1182 hd
->timer
.function
= mptscsih_timer_expired
;
1184 init_waitqueue_head(&hd
->scandv_waitq
);
1185 hd
->scandv_wait_done
= 0;
1186 hd
->last_queue_full
= 0;
1188 sh
->transportt
= mptfc_transport_template
;
1189 error
= scsi_add_host (sh
, &ioc
->pcidev
->dev
);
1191 dprintk((KERN_ERR MYNAM
1192 "scsi_add_host failed\n"));
1193 goto out_mptfc_probe
;
1196 /* initialize workqueue */
1198 snprintf(ioc
->fc_rescan_work_q_name
, KOBJ_NAME_LEN
, "mptfc_wq_%d",
1200 ioc
->fc_rescan_work_q
=
1201 create_singlethread_workqueue(ioc
->fc_rescan_work_q_name
);
1202 if (!ioc
->fc_rescan_work_q
)
1203 goto out_mptfc_probe
;
1206 * Pre-fetch FC port WWN and stuff...
1207 * (FCPortPage0_t stuff)
1209 for (ii
=0; ii
< ioc
->facts
.NumberOfPorts
; ii
++) {
1210 (void) mptfc_GetFcPortPage0(ioc
, ii
);
1212 mptfc_SetFcPortPage1_defaults(ioc
);
1216 * by doing it via the workqueue, some locking is eliminated
1219 queue_work(ioc
->fc_rescan_work_q
, &ioc
->fc_rescan_work
);
1220 flush_workqueue(ioc
->fc_rescan_work_q
);
1226 mptscsih_remove(pdev
);
1230 static struct pci_driver mptfc_driver
= {
1232 .id_table
= mptfc_pci_table
,
1233 .probe
= mptfc_probe
,
1234 .remove
= __devexit_p(mptfc_remove
),
1235 .shutdown
= mptscsih_shutdown
,
1237 .suspend
= mptscsih_suspend
,
1238 .resume
= mptscsih_resume
,
1243 mptfc_event_process(MPT_ADAPTER
*ioc
, EventNotificationReply_t
*pEvReply
)
1246 u8 event
= le32_to_cpu(pEvReply
->Event
) & 0xFF;
1247 unsigned long flags
;
1250 devtverboseprintk((MYIOC_s_INFO_FMT
"MPT event (=%02Xh) routed to SCSI host driver!\n",
1253 if (ioc
->sh
== NULL
||
1254 ((hd
= (MPT_SCSI_HOST
*)ioc
->sh
->hostdata
) == NULL
))
1258 case MPI_EVENT_RESCAN
:
1259 spin_lock_irqsave(&ioc
->fc_rescan_work_lock
, flags
);
1260 if (ioc
->fc_rescan_work_q
) {
1261 queue_work(ioc
->fc_rescan_work_q
,
1262 &ioc
->fc_rescan_work
);
1264 spin_unlock_irqrestore(&ioc
->fc_rescan_work_lock
, flags
);
1267 rc
= mptscsih_event_process(ioc
,pEvReply
);
1274 mptfc_ioc_reset(MPT_ADAPTER
*ioc
, int reset_phase
)
1277 unsigned long flags
;
1279 rc
= mptscsih_ioc_reset(ioc
,reset_phase
);
1284 dtmprintk((KERN_WARNING MYNAM
1285 ": IOC %s_reset routed to FC host driver!\n",
1286 reset_phase
==MPT_IOC_SETUP_RESET
? "setup" : (
1287 reset_phase
==MPT_IOC_PRE_RESET
? "pre" : "post")));
1289 if (reset_phase
== MPT_IOC_SETUP_RESET
) {
1290 spin_lock_irqsave(&ioc
->fc_rescan_work_lock
, flags
);
1291 if (ioc
->fc_rescan_work_q
) {
1292 queue_work(ioc
->fc_rescan_work_q
,
1293 &ioc
->fc_setup_reset_work
);
1295 spin_unlock_irqrestore(&ioc
->fc_rescan_work_lock
, flags
);
1298 else if (reset_phase
== MPT_IOC_PRE_RESET
) {
1301 else { /* MPT_IOC_POST_RESET */
1302 mptfc_SetFcPortPage1_defaults(ioc
);
1303 spin_lock_irqsave(&ioc
->fc_rescan_work_lock
, flags
);
1304 if (ioc
->fc_rescan_work_q
) {
1305 queue_work(ioc
->fc_rescan_work_q
,
1306 &ioc
->fc_rescan_work
);
1308 spin_unlock_irqrestore(&ioc
->fc_rescan_work_lock
, flags
);
1313 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1315 * mptfc_init - Register MPT adapter(s) as SCSI host(s) with
1316 * linux scsi mid-layer.
1318 * Returns 0 for success, non-zero for failure.
1325 show_mptmod_ver(my_NAME
, my_VERSION
);
1327 /* sanity check module parameters */
1328 if (mptfc_dev_loss_tmo
<= 0)
1329 mptfc_dev_loss_tmo
= MPTFC_DEV_LOSS_TMO
;
1331 mptfc_transport_template
=
1332 fc_attach_transport(&mptfc_transport_functions
);
1334 if (!mptfc_transport_template
)
1337 mptfcDoneCtx
= mpt_register(mptscsih_io_done
, MPTFC_DRIVER
);
1338 mptfcTaskCtx
= mpt_register(mptscsih_taskmgmt_complete
, MPTFC_DRIVER
);
1339 mptfcInternalCtx
= mpt_register(mptscsih_scandv_complete
, MPTFC_DRIVER
);
1341 if (mpt_event_register(mptfcDoneCtx
, mptfc_event_process
) == 0) {
1342 devtverboseprintk((KERN_INFO MYNAM
1343 ": Registered for IOC event notifications\n"));
1346 if (mpt_reset_register(mptfcDoneCtx
, mptfc_ioc_reset
) == 0) {
1347 dprintk((KERN_INFO MYNAM
1348 ": Registered for IOC reset notifications\n"));
1351 error
= pci_register_driver(&mptfc_driver
);
1353 fc_release_transport(mptfc_transport_template
);
1358 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1360 * mptfc_remove - Removed fc infrastructure for devices
1361 * @pdev: Pointer to pci_dev structure
1364 static void __devexit
1365 mptfc_remove(struct pci_dev
*pdev
)
1367 MPT_ADAPTER
*ioc
= pci_get_drvdata(pdev
);
1368 struct mptfc_rport_info
*p
, *n
;
1369 struct workqueue_struct
*work_q
;
1370 unsigned long flags
;
1373 /* destroy workqueue */
1374 if ((work_q
=ioc
->fc_rescan_work_q
)) {
1375 spin_lock_irqsave(&ioc
->fc_rescan_work_lock
, flags
);
1376 ioc
->fc_rescan_work_q
= NULL
;
1377 spin_unlock_irqrestore(&ioc
->fc_rescan_work_lock
, flags
);
1378 destroy_workqueue(work_q
);
1381 fc_remove_host(ioc
->sh
);
1383 list_for_each_entry_safe(p
, n
, &ioc
->fc_rports
, list
) {
1388 for (ii
=0; ii
<ioc
->facts
.NumberOfPorts
; ii
++) {
1389 if (ioc
->fc_data
.fc_port_page1
[ii
].data
) {
1390 pci_free_consistent(ioc
->pcidev
,
1391 ioc
->fc_data
.fc_port_page1
[ii
].pg_sz
,
1392 (u8
*) ioc
->fc_data
.fc_port_page1
[ii
].data
,
1393 ioc
->fc_data
.fc_port_page1
[ii
].dma
);
1394 ioc
->fc_data
.fc_port_page1
[ii
].data
= NULL
;
1398 mptscsih_remove(pdev
);
1401 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1402 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1404 * mptfc_exit - Unregisters MPT adapter(s)
1410 pci_unregister_driver(&mptfc_driver
);
1411 fc_release_transport(mptfc_transport_template
);
1413 mpt_reset_deregister(mptfcDoneCtx
);
1414 dprintk((KERN_INFO MYNAM
1415 ": Deregistered for IOC reset notifications\n"));
1417 mpt_event_deregister(mptfcDoneCtx
);
1418 dprintk((KERN_INFO MYNAM
1419 ": Deregistered for IOC event notifications\n"));
1421 mpt_deregister(mptfcInternalCtx
);
1422 mpt_deregister(mptfcTaskCtx
);
1423 mpt_deregister(mptfcDoneCtx
);
1426 module_init(mptfc_init
);
1427 module_exit(mptfc_exit
);