xref: /openbmc/linux/drivers/message/fusion/mptfc.c (revision 914c2d8e597798d62c2e0a3cba737bf6f611eecf)
12496af39SMoore, Eric Dean  /*
22496af39SMoore, Eric Dean   *  linux/drivers/message/fusion/mptfc.c
32496af39SMoore, Eric Dean   *      For use with LSI Logic PCI chip/adapter(s)
42496af39SMoore, Eric Dean   *      running LSI Logic Fusion MPT (Message Passing Technology) firmware.
52496af39SMoore, Eric Dean   *
62496af39SMoore, Eric Dean   *  Copyright (c) 1999-2005 LSI Logic Corporation
72496af39SMoore, Eric Dean   *  (mailto:mpt_linux_developer@lsil.com)
82496af39SMoore, Eric Dean   *
92496af39SMoore, Eric Dean   */
102496af39SMoore, Eric Dean  /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
112496af39SMoore, Eric Dean  /*
122496af39SMoore, Eric Dean      This program is free software; you can redistribute it and/or modify
132496af39SMoore, Eric Dean      it under the terms of the GNU General Public License as published by
142496af39SMoore, Eric Dean      the Free Software Foundation; version 2 of the License.
152496af39SMoore, Eric Dean  
162496af39SMoore, Eric Dean      This program is distributed in the hope that it will be useful,
172496af39SMoore, Eric Dean      but WITHOUT ANY WARRANTY; without even the implied warranty of
182496af39SMoore, Eric Dean      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
192496af39SMoore, Eric Dean      GNU General Public License for more details.
202496af39SMoore, Eric Dean  
212496af39SMoore, Eric Dean      NO WARRANTY
222496af39SMoore, Eric Dean      THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
232496af39SMoore, Eric Dean      CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
242496af39SMoore, Eric Dean      LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
252496af39SMoore, Eric Dean      MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
262496af39SMoore, Eric Dean      solely responsible for determining the appropriateness of using and
272496af39SMoore, Eric Dean      distributing the Program and assumes all risks associated with its
282496af39SMoore, Eric Dean      exercise of rights under this Agreement, including but not limited to
292496af39SMoore, Eric Dean      the risks and costs of program errors, damage to or loss of data,
302496af39SMoore, Eric Dean      programs or equipment, and unavailability or interruption of operations.
312496af39SMoore, Eric Dean  
322496af39SMoore, Eric Dean      DISCLAIMER OF LIABILITY
332496af39SMoore, Eric Dean      NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
342496af39SMoore, Eric Dean      DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
352496af39SMoore, Eric Dean      DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
362496af39SMoore, Eric Dean      ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
372496af39SMoore, Eric Dean      TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
382496af39SMoore, Eric Dean      USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
392496af39SMoore, Eric Dean      HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
402496af39SMoore, Eric Dean  
412496af39SMoore, Eric Dean      You should have received a copy of the GNU General Public License
422496af39SMoore, Eric Dean      along with this program; if not, write to the Free Software
432496af39SMoore, Eric Dean      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
442496af39SMoore, Eric Dean  */
452496af39SMoore, Eric Dean  /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
462496af39SMoore, Eric Dean  #include "linux_compat.h"	/* linux-2.6 tweaks */
472496af39SMoore, Eric Dean  #include <linux/module.h>
482496af39SMoore, Eric Dean  #include <linux/kernel.h>
492496af39SMoore, Eric Dean  #include <linux/init.h>
502496af39SMoore, Eric Dean  #include <linux/errno.h>
512496af39SMoore, Eric Dean  #include <linux/kdev_t.h>
522496af39SMoore, Eric Dean  #include <linux/blkdev.h>
532496af39SMoore, Eric Dean  #include <linux/delay.h>	/* for mdelay */
542496af39SMoore, Eric Dean  #include <linux/interrupt.h>	/* needed for in_interrupt() proto */
552496af39SMoore, Eric Dean  #include <linux/reboot.h>	/* notifier code */
562496af39SMoore, Eric Dean  #include <linux/sched.h>
572496af39SMoore, Eric Dean  #include <linux/workqueue.h>
5805e8ec17SMichael Reed #include <linux/sort.h>
592496af39SMoore, Eric Dean  
602496af39SMoore, Eric Dean  #include <scsi/scsi.h>
612496af39SMoore, Eric Dean  #include <scsi/scsi_cmnd.h>
622496af39SMoore, Eric Dean  #include <scsi/scsi_device.h>
632496af39SMoore, Eric Dean  #include <scsi/scsi_host.h>
642496af39SMoore, Eric Dean  #include <scsi/scsi_tcq.h>
6505e8ec17SMichael Reed #include <scsi/scsi_transport_fc.h>
662496af39SMoore, Eric Dean  
672496af39SMoore, Eric Dean  #include "mptbase.h"
682496af39SMoore, Eric Dean  #include "mptscsih.h"
692496af39SMoore, Eric Dean  
702496af39SMoore, Eric Dean  /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
712496af39SMoore, Eric Dean  #define my_NAME		"Fusion MPT FC Host driver"
722496af39SMoore, Eric Dean  #define my_VERSION	MPT_LINUX_VERSION_COMMON
732496af39SMoore, Eric Dean  #define MYNAM		"mptfc"
742496af39SMoore, Eric Dean  
752496af39SMoore, Eric Dean  MODULE_AUTHOR(MODULEAUTHOR);
762496af39SMoore, Eric Dean  MODULE_DESCRIPTION(my_NAME);
772496af39SMoore, Eric Dean  MODULE_LICENSE("GPL");
782496af39SMoore, Eric Dean  
792496af39SMoore, Eric Dean  /* Command line args */
802496af39SMoore, Eric Dean  static int mpt_pq_filter = 0;
812496af39SMoore, Eric Dean  module_param(mpt_pq_filter, int, 0);
822496af39SMoore, Eric Dean  MODULE_PARM_DESC(mpt_pq_filter, " Enable peripheral qualifier filter: enable=1  (default=0)");
832496af39SMoore, Eric Dean  
8405e8ec17SMichael Reed #define MPTFC_DEV_LOSS_TMO (60)
8505e8ec17SMichael Reed static int mptfc_dev_loss_tmo = MPTFC_DEV_LOSS_TMO;	/* reasonable default */
8605e8ec17SMichael Reed module_param(mptfc_dev_loss_tmo, int, 0);
8705e8ec17SMichael Reed MODULE_PARM_DESC(mptfc_dev_loss_tmo, " Initial time the driver programs the "
8805e8ec17SMichael Reed     				     " transport to wait for an rport to "
8905e8ec17SMichael Reed 				     " return following a device loss event."
9005e8ec17SMichael Reed 				     "  Default=60.");
9105e8ec17SMichael Reed 
922496af39SMoore, Eric Dean  static int	mptfcDoneCtx = -1;
932496af39SMoore, Eric Dean  static int	mptfcTaskCtx = -1;
942496af39SMoore, Eric Dean  static int	mptfcInternalCtx = -1; /* Used only for internal commands */
952496af39SMoore, Eric Dean  
963bc7bf1dSMichael Reed static int mptfc_target_alloc(struct scsi_target *starget);
973bc7bf1dSMichael Reed static int mptfc_slave_alloc(struct scsi_device *sdev);
9805e8ec17SMichael Reed static int mptfc_qcmd(struct scsi_cmnd *SCpnt,
9905e8ec17SMichael Reed 		      void (*done)(struct scsi_cmnd *));
1003bc7bf1dSMichael Reed static void mptfc_target_destroy(struct scsi_target *starget);
10105e8ec17SMichael Reed static void mptfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout);
10205e8ec17SMichael Reed static void __devexit mptfc_remove(struct pci_dev *pdev);
10305e8ec17SMichael Reed 
1042496af39SMoore, Eric Dean  static struct scsi_host_template mptfc_driver_template = {
105f78496daSMoore, Eric Dean 	.module				= THIS_MODULE,
1062496af39SMoore, Eric Dean  	.proc_name			= "mptfc",
1072496af39SMoore, Eric Dean  	.proc_info			= mptscsih_proc_info,
1082496af39SMoore, Eric Dean  	.name				= "MPT FC Host",
1092496af39SMoore, Eric Dean  	.info				= mptscsih_info,
11005e8ec17SMichael Reed 	.queuecommand			= mptfc_qcmd,
1113bc7bf1dSMichael Reed 	.target_alloc			= mptfc_target_alloc,
11205e8ec17SMichael Reed 	.slave_alloc			= mptfc_slave_alloc,
1132496af39SMoore, Eric Dean  	.slave_configure		= mptscsih_slave_configure,
1143bc7bf1dSMichael Reed 	.target_destroy			= mptfc_target_destroy,
1152496af39SMoore, Eric Dean  	.slave_destroy			= mptscsih_slave_destroy,
1166e3815baSMoore, Eric Dean 	.change_queue_depth 		= mptscsih_change_queue_depth,
1172496af39SMoore, Eric Dean  	.eh_abort_handler		= mptscsih_abort,
1182496af39SMoore, Eric Dean  	.eh_device_reset_handler	= mptscsih_dev_reset,
1192496af39SMoore, Eric Dean  	.eh_bus_reset_handler		= mptscsih_bus_reset,
1202496af39SMoore, Eric Dean  	.eh_host_reset_handler		= mptscsih_host_reset,
1212496af39SMoore, Eric Dean  	.bios_param			= mptscsih_bios_param,
1222496af39SMoore, Eric Dean  	.can_queue			= MPT_FC_CAN_QUEUE,
1232496af39SMoore, Eric Dean  	.this_id			= -1,
1242496af39SMoore, Eric Dean  	.sg_tablesize			= MPT_SCSI_SG_DEPTH,
1252496af39SMoore, Eric Dean  	.max_sectors			= 8192,
1262496af39SMoore, Eric Dean  	.cmd_per_lun			= 7,
1272496af39SMoore, Eric Dean  	.use_clustering			= ENABLE_CLUSTERING,
1282496af39SMoore, Eric Dean  };
1292496af39SMoore, Eric Dean  
1302496af39SMoore, Eric Dean  /****************************************************************************
1312496af39SMoore, Eric Dean   * Supported hardware
1322496af39SMoore, Eric Dean   */
1332496af39SMoore, Eric Dean  
1342496af39SMoore, Eric Dean  static struct pci_device_id mptfc_pci_table[] = {
1352496af39SMoore, Eric Dean  	{ PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_FC909,
1362496af39SMoore, Eric Dean  		PCI_ANY_ID, PCI_ANY_ID },
1372496af39SMoore, Eric Dean  	{ PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_FC919,
1382496af39SMoore, Eric Dean  		PCI_ANY_ID, PCI_ANY_ID },
1392496af39SMoore, Eric Dean  	{ PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_FC929,
1402496af39SMoore, Eric Dean  		PCI_ANY_ID, PCI_ANY_ID },
1412496af39SMoore, Eric Dean  	{ PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_FC919X,
1422496af39SMoore, Eric Dean  		PCI_ANY_ID, PCI_ANY_ID },
1432496af39SMoore, Eric Dean  	{ PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_FC929X,
1442496af39SMoore, Eric Dean  		PCI_ANY_ID, PCI_ANY_ID },
1453fadc59dSMoore, Eric Dean  	{ PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_FC939X,
1463fadc59dSMoore, Eric Dean  		PCI_ANY_ID, PCI_ANY_ID },
1473fadc59dSMoore, Eric Dean  	{ PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_FC949X,
1483fadc59dSMoore, Eric Dean  		PCI_ANY_ID, PCI_ANY_ID },
1496d5b0c31SMoore, Eric 	{ PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_FC949ES,
1506d5b0c31SMoore, Eric 		PCI_ANY_ID, PCI_ANY_ID },
1512496af39SMoore, Eric Dean  	{0}	/* Terminating entry */
1522496af39SMoore, Eric Dean  };
1532496af39SMoore, Eric Dean  MODULE_DEVICE_TABLE(pci, mptfc_pci_table);
1542496af39SMoore, Eric Dean  
15505e8ec17SMichael Reed static struct scsi_transport_template *mptfc_transport_template = NULL;
15605e8ec17SMichael Reed 
15703fbcbcdSAdrian Bunk static struct fc_function_template mptfc_transport_functions = {
15805e8ec17SMichael Reed 	.dd_fcrport_size = 8,
15905e8ec17SMichael Reed 	.show_host_node_name = 1,
16005e8ec17SMichael Reed 	.show_host_port_name = 1,
16105e8ec17SMichael Reed 	.show_host_supported_classes = 1,
16205e8ec17SMichael Reed 	.show_host_port_id = 1,
16305e8ec17SMichael Reed 	.show_rport_supported_classes = 1,
16405e8ec17SMichael Reed 	.show_starget_node_name = 1,
16505e8ec17SMichael Reed 	.show_starget_port_name = 1,
16605e8ec17SMichael Reed 	.show_starget_port_id = 1,
16705e8ec17SMichael Reed 	.set_rport_dev_loss_tmo = mptfc_set_rport_loss_tmo,
16805e8ec17SMichael Reed 	.show_rport_dev_loss_tmo = 1,
16905e8ec17SMichael Reed 
17005e8ec17SMichael Reed };
17105e8ec17SMichael Reed 
17205e8ec17SMichael Reed /* FIXME! values controlling firmware RESCAN event
17305e8ec17SMichael Reed  * need to be set low to allow dev_loss_tmo to
17405e8ec17SMichael Reed  * work as expected.  Currently, firmware doesn't
17505e8ec17SMichael Reed  * notify driver of RESCAN event until some number
17605e8ec17SMichael Reed  * of seconds elapse.  This value can be set via
17705e8ec17SMichael Reed  * lsiutil.
1782496af39SMoore, Eric Dean   */
17905e8ec17SMichael Reed static void
18005e8ec17SMichael Reed mptfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
18105e8ec17SMichael Reed {
18205e8ec17SMichael Reed 	if (timeout > 0)
18305e8ec17SMichael Reed 		rport->dev_loss_tmo = timeout;
18405e8ec17SMichael Reed 	else
18505e8ec17SMichael Reed 		rport->dev_loss_tmo = mptfc_dev_loss_tmo;
18605e8ec17SMichael Reed }
18705e8ec17SMichael Reed 
18805e8ec17SMichael Reed static int
18905e8ec17SMichael Reed mptfc_FcDevPage0_cmp_func(const void *a, const void *b)
19005e8ec17SMichael Reed {
19105e8ec17SMichael Reed 	FCDevicePage0_t **aa = (FCDevicePage0_t **)a;
19205e8ec17SMichael Reed 	FCDevicePage0_t **bb = (FCDevicePage0_t **)b;
19305e8ec17SMichael Reed 
19405e8ec17SMichael Reed 	if ((*aa)->CurrentBus == (*bb)->CurrentBus) {
19505e8ec17SMichael Reed 		if ((*aa)->CurrentTargetID == (*bb)->CurrentTargetID)
19605e8ec17SMichael Reed 			return 0;
19705e8ec17SMichael Reed 		if ((*aa)->CurrentTargetID < (*bb)->CurrentTargetID)
19805e8ec17SMichael Reed 			return -1;
19905e8ec17SMichael Reed 		return 1;
20005e8ec17SMichael Reed 	}
20105e8ec17SMichael Reed 	if ((*aa)->CurrentBus < (*bb)->CurrentBus)
20205e8ec17SMichael Reed 		return -1;
20305e8ec17SMichael Reed 	return 1;
20405e8ec17SMichael Reed }
20505e8ec17SMichael Reed 
20605e8ec17SMichael Reed static int
20705e8ec17SMichael Reed mptfc_GetFcDevPage0(MPT_ADAPTER *ioc, int ioc_port,
20805e8ec17SMichael Reed 	void(*func)(MPT_ADAPTER *ioc,int channel, FCDevicePage0_t *arg))
20905e8ec17SMichael Reed {
21005e8ec17SMichael Reed 	ConfigPageHeader_t	 hdr;
21105e8ec17SMichael Reed 	CONFIGPARMS		 cfg;
21205e8ec17SMichael Reed 	FCDevicePage0_t		*ppage0_alloc, *fc;
21305e8ec17SMichael Reed 	dma_addr_t		 page0_dma;
21405e8ec17SMichael Reed 	int			 data_sz;
21505e8ec17SMichael Reed 	int			 ii;
21605e8ec17SMichael Reed 
21705e8ec17SMichael Reed 	FCDevicePage0_t		*p0_array=NULL, *p_p0;
21805e8ec17SMichael Reed 	FCDevicePage0_t		**pp0_array=NULL, **p_pp0;
21905e8ec17SMichael Reed 
22005e8ec17SMichael Reed 	int			 rc = -ENOMEM;
22105e8ec17SMichael Reed 	U32			 port_id = 0xffffff;
22205e8ec17SMichael Reed 	int			 num_targ = 0;
22305e8ec17SMichael Reed 	int			 max_bus = ioc->facts.MaxBuses;
22405e8ec17SMichael Reed 	int			 max_targ = ioc->facts.MaxDevices;
22505e8ec17SMichael Reed 
22605e8ec17SMichael Reed 	if (max_bus == 0 || max_targ == 0)
22705e8ec17SMichael Reed 		goto out;
22805e8ec17SMichael Reed 
22905e8ec17SMichael Reed 	data_sz = sizeof(FCDevicePage0_t) * max_bus * max_targ;
23005e8ec17SMichael Reed 	p_p0 = p0_array =  kzalloc(data_sz, GFP_KERNEL);
23105e8ec17SMichael Reed 	if (!p0_array)
23205e8ec17SMichael Reed 		goto out;
23305e8ec17SMichael Reed 
23405e8ec17SMichael Reed 	data_sz = sizeof(FCDevicePage0_t *) * max_bus * max_targ;
23505e8ec17SMichael Reed 	p_pp0 = pp0_array = kzalloc(data_sz, GFP_KERNEL);
23605e8ec17SMichael Reed 	if (!pp0_array)
23705e8ec17SMichael Reed 		goto out;
23805e8ec17SMichael Reed 
23905e8ec17SMichael Reed 	do {
24005e8ec17SMichael Reed 		/* Get FC Device Page 0 header */
24105e8ec17SMichael Reed 		hdr.PageVersion = 0;
24205e8ec17SMichael Reed 		hdr.PageLength = 0;
24305e8ec17SMichael Reed 		hdr.PageNumber = 0;
24405e8ec17SMichael Reed 		hdr.PageType = MPI_CONFIG_PAGETYPE_FC_DEVICE;
24505e8ec17SMichael Reed 		cfg.cfghdr.hdr = &hdr;
24605e8ec17SMichael Reed 		cfg.physAddr = -1;
24705e8ec17SMichael Reed 		cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
24805e8ec17SMichael Reed 		cfg.dir = 0;
24905e8ec17SMichael Reed 		cfg.pageAddr = port_id;
25005e8ec17SMichael Reed 		cfg.timeout = 0;
25105e8ec17SMichael Reed 
25205e8ec17SMichael Reed 		if ((rc = mpt_config(ioc, &cfg)) != 0)
25305e8ec17SMichael Reed 			break;
25405e8ec17SMichael Reed 
25505e8ec17SMichael Reed 		if (hdr.PageLength <= 0)
25605e8ec17SMichael Reed 			break;
25705e8ec17SMichael Reed 
25805e8ec17SMichael Reed 		data_sz = hdr.PageLength * 4;
25905e8ec17SMichael Reed 		ppage0_alloc = pci_alloc_consistent(ioc->pcidev, data_sz,
26005e8ec17SMichael Reed 		    					&page0_dma);
26105e8ec17SMichael Reed 		rc = -ENOMEM;
26205e8ec17SMichael Reed 		if (!ppage0_alloc)
26305e8ec17SMichael Reed 			break;
26405e8ec17SMichael Reed 
26505e8ec17SMichael Reed 		cfg.physAddr = page0_dma;
26605e8ec17SMichael Reed 		cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
26705e8ec17SMichael Reed 
26805e8ec17SMichael Reed 		if ((rc = mpt_config(ioc, &cfg)) == 0) {
26905e8ec17SMichael Reed 			ppage0_alloc->PortIdentifier =
27005e8ec17SMichael Reed 				le32_to_cpu(ppage0_alloc->PortIdentifier);
27105e8ec17SMichael Reed 
27205e8ec17SMichael Reed 			ppage0_alloc->WWNN.Low =
27305e8ec17SMichael Reed 				le32_to_cpu(ppage0_alloc->WWNN.Low);
27405e8ec17SMichael Reed 
27505e8ec17SMichael Reed 			ppage0_alloc->WWNN.High =
27605e8ec17SMichael Reed 				le32_to_cpu(ppage0_alloc->WWNN.High);
27705e8ec17SMichael Reed 
27805e8ec17SMichael Reed 			ppage0_alloc->WWPN.Low =
27905e8ec17SMichael Reed 				le32_to_cpu(ppage0_alloc->WWPN.Low);
28005e8ec17SMichael Reed 
28105e8ec17SMichael Reed 			ppage0_alloc->WWPN.High =
28205e8ec17SMichael Reed 				le32_to_cpu(ppage0_alloc->WWPN.High);
28305e8ec17SMichael Reed 
28405e8ec17SMichael Reed 			ppage0_alloc->BBCredit =
28505e8ec17SMichael Reed 				le16_to_cpu(ppage0_alloc->BBCredit);
28605e8ec17SMichael Reed 
28705e8ec17SMichael Reed 			ppage0_alloc->MaxRxFrameSize =
28805e8ec17SMichael Reed 				le16_to_cpu(ppage0_alloc->MaxRxFrameSize);
28905e8ec17SMichael Reed 
29005e8ec17SMichael Reed 			port_id = ppage0_alloc->PortIdentifier;
29105e8ec17SMichael Reed 			num_targ++;
29205e8ec17SMichael Reed 			*p_p0 = *ppage0_alloc;	/* save data */
29305e8ec17SMichael Reed 			*p_pp0++ = p_p0++;	/* save addr */
29405e8ec17SMichael Reed 		}
29505e8ec17SMichael Reed 		pci_free_consistent(ioc->pcidev, data_sz,
29605e8ec17SMichael Reed 		    			(u8 *) ppage0_alloc, page0_dma);
29705e8ec17SMichael Reed 		if (rc != 0)
29805e8ec17SMichael Reed 			break;
29905e8ec17SMichael Reed 
30005e8ec17SMichael Reed 	} while (port_id <= 0xff0000);
30105e8ec17SMichael Reed 
30205e8ec17SMichael Reed 	if (num_targ) {
30305e8ec17SMichael Reed 		/* sort array */
30405e8ec17SMichael Reed 		if (num_targ > 1)
30505e8ec17SMichael Reed 			sort (pp0_array, num_targ, sizeof(FCDevicePage0_t *),
30605e8ec17SMichael Reed 				mptfc_FcDevPage0_cmp_func, NULL);
30705e8ec17SMichael Reed 		/* call caller's func for each targ */
30805e8ec17SMichael Reed 		for (ii = 0; ii < num_targ;  ii++) {
30905e8ec17SMichael Reed 			fc = *(pp0_array+ii);
31005e8ec17SMichael Reed 			func(ioc, ioc_port, fc);
31105e8ec17SMichael Reed 		}
31205e8ec17SMichael Reed 	}
31305e8ec17SMichael Reed 
31405e8ec17SMichael Reed  out:
31505e8ec17SMichael Reed 	if (pp0_array)
31605e8ec17SMichael Reed 		kfree(pp0_array);
31705e8ec17SMichael Reed 	if (p0_array)
31805e8ec17SMichael Reed 		kfree(p0_array);
31905e8ec17SMichael Reed 	return rc;
32005e8ec17SMichael Reed }
32105e8ec17SMichael Reed 
32205e8ec17SMichael Reed static int
32305e8ec17SMichael Reed mptfc_generate_rport_ids(FCDevicePage0_t *pg0, struct fc_rport_identifiers *rid)
32405e8ec17SMichael Reed {
32505e8ec17SMichael Reed 	/* not currently usable */
32605e8ec17SMichael Reed 	if (pg0->Flags & (MPI_FC_DEVICE_PAGE0_FLAGS_PLOGI_INVALID |
32705e8ec17SMichael Reed 			  MPI_FC_DEVICE_PAGE0_FLAGS_PRLI_INVALID))
32805e8ec17SMichael Reed 		return -1;
32905e8ec17SMichael Reed 
33005e8ec17SMichael Reed 	if (!(pg0->Flags & MPI_FC_DEVICE_PAGE0_FLAGS_TARGETID_BUS_VALID))
33105e8ec17SMichael Reed 		return -1;
33205e8ec17SMichael Reed 
33305e8ec17SMichael Reed 	if (!(pg0->Protocol & MPI_FC_DEVICE_PAGE0_PROT_FCP_TARGET))
33405e8ec17SMichael Reed 		return -1;
33505e8ec17SMichael Reed 
33605e8ec17SMichael Reed 	/*
33705e8ec17SMichael Reed 	 * board data structure already normalized to platform endianness
33805e8ec17SMichael Reed 	 * shifted to avoid unaligned access on 64 bit architecture
33905e8ec17SMichael Reed 	 */
34005e8ec17SMichael Reed 	rid->node_name = ((u64)pg0->WWNN.High) << 32 | (u64)pg0->WWNN.Low;
34105e8ec17SMichael Reed 	rid->port_name = ((u64)pg0->WWPN.High) << 32 | (u64)pg0->WWPN.Low;
34205e8ec17SMichael Reed 	rid->port_id =   pg0->PortIdentifier;
34305e8ec17SMichael Reed 	rid->roles = FC_RPORT_ROLE_UNKNOWN;
34405e8ec17SMichael Reed 	rid->roles |= FC_RPORT_ROLE_FCP_TARGET;
34505e8ec17SMichael Reed 	if (pg0->Protocol & MPI_FC_DEVICE_PAGE0_PROT_FCP_INITIATOR)
34605e8ec17SMichael Reed 		rid->roles |= FC_RPORT_ROLE_FCP_INITIATOR;
34705e8ec17SMichael Reed 
34805e8ec17SMichael Reed 	return 0;
34905e8ec17SMichael Reed }
35005e8ec17SMichael Reed 
35105e8ec17SMichael Reed static void
35205e8ec17SMichael Reed mptfc_register_dev(MPT_ADAPTER *ioc, int channel, FCDevicePage0_t *pg0)
35305e8ec17SMichael Reed {
35405e8ec17SMichael Reed 	struct fc_rport_identifiers rport_ids;
35505e8ec17SMichael Reed 	struct fc_rport		*rport;
35605e8ec17SMichael Reed 	struct mptfc_rport_info	*ri;
3573bc7bf1dSMichael Reed 	int			new_ri = 1;
3583bc7bf1dSMichael Reed 	u64			pn;
35905e8ec17SMichael Reed 	unsigned long		flags;
3603bc7bf1dSMichael Reed 	VirtTarget		*vtarget;
36105e8ec17SMichael Reed 
36205e8ec17SMichael Reed 	if (mptfc_generate_rport_ids(pg0, &rport_ids) < 0)
36305e8ec17SMichael Reed 		return;
36405e8ec17SMichael Reed 
36505e8ec17SMichael Reed 	/* scan list looking for a match */
36605e8ec17SMichael Reed 	spin_lock_irqsave(&ioc->fc_rport_lock, flags);
36705e8ec17SMichael Reed 	list_for_each_entry(ri, &ioc->fc_rports, list) {
3683bc7bf1dSMichael Reed 		pn = (u64)ri->pg0.WWPN.High << 32 | (u64)ri->pg0.WWPN.Low;
3693bc7bf1dSMichael Reed 		if (pn == rport_ids.port_name) {	/* match */
37005e8ec17SMichael Reed 			list_move_tail(&ri->list, &ioc->fc_rports);
3713bc7bf1dSMichael Reed 			new_ri = 0;
37205e8ec17SMichael Reed 			break;
37305e8ec17SMichael Reed 		}
37405e8ec17SMichael Reed 	}
3753bc7bf1dSMichael Reed 	if (new_ri) {	/* allocate one */
37605e8ec17SMichael Reed 		spin_unlock_irqrestore(&ioc->fc_rport_lock, flags);
37705e8ec17SMichael Reed 		ri = kzalloc(sizeof(struct mptfc_rport_info), GFP_KERNEL);
37805e8ec17SMichael Reed 		if (!ri)
37905e8ec17SMichael Reed 			return;
38005e8ec17SMichael Reed 		spin_lock_irqsave(&ioc->fc_rport_lock, flags);
38105e8ec17SMichael Reed 		list_add_tail(&ri->list, &ioc->fc_rports);
38205e8ec17SMichael Reed 	}
38305e8ec17SMichael Reed 
38405e8ec17SMichael Reed 	ri->pg0 = *pg0;	/* add/update pg0 data */
38505e8ec17SMichael Reed 	ri->flags &= ~MPT_RPORT_INFO_FLAGS_MISSING;
38605e8ec17SMichael Reed 
3873bc7bf1dSMichael Reed 	/* MPT_RPORT_INFO_FLAGS_REGISTERED - rport not previously deleted */
38805e8ec17SMichael Reed 	if (!(ri->flags & MPT_RPORT_INFO_FLAGS_REGISTERED)) {
38905e8ec17SMichael Reed 		ri->flags |= MPT_RPORT_INFO_FLAGS_REGISTERED;
39005e8ec17SMichael Reed 		spin_unlock_irqrestore(&ioc->fc_rport_lock, flags);
39105e8ec17SMichael Reed 		rport = fc_remote_port_add(ioc->sh, channel, &rport_ids);
39205e8ec17SMichael Reed 		spin_lock_irqsave(&ioc->fc_rport_lock, flags);
39305e8ec17SMichael Reed 		if (rport) {
39405e8ec17SMichael Reed 			ri->rport = rport;
3953bc7bf1dSMichael Reed 			if (new_ri) /* may have been reset by user */
39605e8ec17SMichael Reed 				rport->dev_loss_tmo = mptfc_dev_loss_tmo;
3973bc7bf1dSMichael Reed 			*((struct mptfc_rport_info **)rport->dd_data) = ri;
39805e8ec17SMichael Reed 			/*
39905e8ec17SMichael Reed 			 * if already mapped, remap here.  If not mapped,
4003bc7bf1dSMichael Reed 			 * target_alloc will allocate vtarget and map,
4013bc7bf1dSMichael Reed 			 * slave_alloc will fill in vdev from vtarget.
40205e8ec17SMichael Reed 			 */
4033bc7bf1dSMichael Reed 			if (ri->starget) {
4043bc7bf1dSMichael Reed 				vtarget = ri->starget->hostdata;
4053bc7bf1dSMichael Reed 				if (vtarget) {
4063bc7bf1dSMichael Reed 					vtarget->target_id = pg0->CurrentTargetID;
4073bc7bf1dSMichael Reed 					vtarget->bus_id = pg0->CurrentBus;
40805e8ec17SMichael Reed 				}
4093bc7bf1dSMichael Reed 				ri->remap_needed = 0;
4103bc7bf1dSMichael Reed 			}
4113bc7bf1dSMichael Reed 			dfcprintk ((MYIOC_s_INFO_FMT
4123bc7bf1dSMichael Reed 				"mptfc_reg_dev.%d: %x, %llx / %llx, tid %d, "
41305e8ec17SMichael Reed 				"rport tid %d, tmo %d\n",
4143bc7bf1dSMichael Reed 					ioc->name,
415*914c2d8eSMoore, Eric 					ioc->sh->host_no,
41605e8ec17SMichael Reed 					pg0->PortIdentifier,
41705e8ec17SMichael Reed 					pg0->WWNN,
41805e8ec17SMichael Reed 					pg0->WWPN,
41905e8ec17SMichael Reed 					pg0->CurrentTargetID,
42005e8ec17SMichael Reed 					ri->rport->scsi_target_id,
4213bc7bf1dSMichael Reed 					ri->rport->dev_loss_tmo));
42205e8ec17SMichael Reed 		} else {
42305e8ec17SMichael Reed 			list_del(&ri->list);
42405e8ec17SMichael Reed 			kfree(ri);
42505e8ec17SMichael Reed 			ri = NULL;
42605e8ec17SMichael Reed 		}
42705e8ec17SMichael Reed 	}
42805e8ec17SMichael Reed 	spin_unlock_irqrestore(&ioc->fc_rport_lock,flags);
42905e8ec17SMichael Reed 
43005e8ec17SMichael Reed }
43105e8ec17SMichael Reed 
43205e8ec17SMichael Reed /*
4333bc7bf1dSMichael Reed  *	OS entry point to allow for host driver to free allocated memory
4343bc7bf1dSMichael Reed  *	Called if no device present or device being unloaded
4353bc7bf1dSMichael Reed  */
4363bc7bf1dSMichael Reed static void
4373bc7bf1dSMichael Reed mptfc_target_destroy(struct scsi_target *starget)
4383bc7bf1dSMichael Reed {
4393bc7bf1dSMichael Reed 	struct fc_rport		*rport;
4403bc7bf1dSMichael Reed 	struct mptfc_rport_info *ri;
4413bc7bf1dSMichael Reed 
4423bc7bf1dSMichael Reed 	rport = starget_to_rport(starget);
4433bc7bf1dSMichael Reed 	if (rport) {
4443bc7bf1dSMichael Reed 		ri = *((struct mptfc_rport_info **)rport->dd_data);
4453bc7bf1dSMichael Reed 		if (ri)	/* better be! */
4463bc7bf1dSMichael Reed 			ri->starget = NULL;
4473bc7bf1dSMichael Reed 	}
4483bc7bf1dSMichael Reed 	if (starget->hostdata)
4493bc7bf1dSMichael Reed 		kfree(starget->hostdata);
4503bc7bf1dSMichael Reed 	starget->hostdata = NULL;
4513bc7bf1dSMichael Reed }
4523bc7bf1dSMichael Reed 
4533bc7bf1dSMichael Reed /*
4543bc7bf1dSMichael Reed  *	OS entry point to allow host driver to alloc memory
4553bc7bf1dSMichael Reed  *	for each scsi target. Called once per device the bus scan.
4563bc7bf1dSMichael Reed  *	Return non-zero if allocation fails.
4573bc7bf1dSMichael Reed  */
4583bc7bf1dSMichael Reed static int
4593bc7bf1dSMichael Reed mptfc_target_alloc(struct scsi_target *starget)
4603bc7bf1dSMichael Reed {
4613bc7bf1dSMichael Reed 	VirtTarget		*vtarget;
4623bc7bf1dSMichael Reed 	struct fc_rport		*rport;
4633bc7bf1dSMichael Reed 	struct mptfc_rport_info *ri;
4643bc7bf1dSMichael Reed 	int			rc;
4653bc7bf1dSMichael Reed 
4663bc7bf1dSMichael Reed 	vtarget = kzalloc(sizeof(VirtTarget), GFP_KERNEL);
4673bc7bf1dSMichael Reed 	if (!vtarget)
4683bc7bf1dSMichael Reed 		return -ENOMEM;
4693bc7bf1dSMichael Reed 	starget->hostdata = vtarget;
4703bc7bf1dSMichael Reed 
4713bc7bf1dSMichael Reed 	rc = -ENODEV;
4723bc7bf1dSMichael Reed 	rport = starget_to_rport(starget);
4733bc7bf1dSMichael Reed 	if (rport) {
4743bc7bf1dSMichael Reed 		ri = *((struct mptfc_rport_info **)rport->dd_data);
4753bc7bf1dSMichael Reed 		if (ri) {	/* better be! */
4763bc7bf1dSMichael Reed 			vtarget->target_id = ri->pg0.CurrentTargetID;
4773bc7bf1dSMichael Reed 			vtarget->bus_id = ri->pg0.CurrentBus;
4783bc7bf1dSMichael Reed 			ri->starget = starget;
4793bc7bf1dSMichael Reed 			ri->remap_needed = 0;
4803bc7bf1dSMichael Reed 			rc = 0;
4813bc7bf1dSMichael Reed 		}
4823bc7bf1dSMichael Reed 	}
4833bc7bf1dSMichael Reed 	if (rc != 0) {
4843bc7bf1dSMichael Reed 		kfree(vtarget);
4853bc7bf1dSMichael Reed 		starget->hostdata = NULL;
4863bc7bf1dSMichael Reed 	}
4873bc7bf1dSMichael Reed 
4883bc7bf1dSMichael Reed 	return rc;
4893bc7bf1dSMichael Reed }
4903bc7bf1dSMichael Reed 
4913bc7bf1dSMichael Reed /*
49205e8ec17SMichael Reed  *	OS entry point to allow host driver to alloc memory
49305e8ec17SMichael Reed  *	for each scsi device. Called once per device the bus scan.
49405e8ec17SMichael Reed  *	Return non-zero if allocation fails.
49505e8ec17SMichael Reed  *	Init memory once per LUN.
49605e8ec17SMichael Reed  */
49703fbcbcdSAdrian Bunk static int
49805e8ec17SMichael Reed mptfc_slave_alloc(struct scsi_device *sdev)
49905e8ec17SMichael Reed {
50005e8ec17SMichael Reed 	MPT_SCSI_HOST		*hd;
50105e8ec17SMichael Reed 	VirtTarget		*vtarget;
50205e8ec17SMichael Reed 	VirtDevice		*vdev;
50305e8ec17SMichael Reed 	struct scsi_target	*starget;
50405e8ec17SMichael Reed 	struct fc_rport		*rport;
50505e8ec17SMichael Reed 	unsigned long		flags;
50605e8ec17SMichael Reed 
50705e8ec17SMichael Reed 
50805e8ec17SMichael Reed 	rport = starget_to_rport(scsi_target(sdev));
50905e8ec17SMichael Reed 
51005e8ec17SMichael Reed 	if (!rport || fc_remote_port_chkready(rport))
51105e8ec17SMichael Reed 		return -ENXIO;
51205e8ec17SMichael Reed 
51305e8ec17SMichael Reed 	hd = (MPT_SCSI_HOST *)sdev->host->hostdata;
51405e8ec17SMichael Reed 
5153bc7bf1dSMichael Reed 	vdev = kzalloc(sizeof(VirtDevice), GFP_KERNEL);
51605e8ec17SMichael Reed 	if (!vdev) {
51705e8ec17SMichael Reed 		printk(MYIOC_s_ERR_FMT "slave_alloc kmalloc(%zd) FAILED!\n",
51805e8ec17SMichael Reed 				hd->ioc->name, sizeof(VirtDevice));
51905e8ec17SMichael Reed 		return -ENOMEM;
52005e8ec17SMichael Reed 	}
52105e8ec17SMichael Reed 
52205e8ec17SMichael Reed 	spin_lock_irqsave(&hd->ioc->fc_rport_lock,flags);
52305e8ec17SMichael Reed 
52405e8ec17SMichael Reed 	sdev->hostdata = vdev;
52505e8ec17SMichael Reed 	starget = scsi_target(sdev);
52605e8ec17SMichael Reed 	vtarget = starget->hostdata;
5273bc7bf1dSMichael Reed 
52805e8ec17SMichael Reed 	if (vtarget->num_luns == 0) {
5293bc7bf1dSMichael Reed 		vtarget->ioc_id = hd->ioc->id;
53005e8ec17SMichael Reed 		vtarget->tflags = MPT_TARGET_FLAGS_Q_YES |
53105e8ec17SMichael Reed 		    		  MPT_TARGET_FLAGS_VALID_INQUIRY;
53205e8ec17SMichael Reed 		hd->Targets[sdev->id] = vtarget;
53305e8ec17SMichael Reed 	}
53405e8ec17SMichael Reed 
53505e8ec17SMichael Reed 	vdev->vtarget = vtarget;
53605e8ec17SMichael Reed 	vdev->lun = sdev->lun;
53705e8ec17SMichael Reed 
53805e8ec17SMichael Reed 	spin_unlock_irqrestore(&hd->ioc->fc_rport_lock,flags);
53905e8ec17SMichael Reed 
54005e8ec17SMichael Reed 	vtarget->num_luns++;
54105e8ec17SMichael Reed 
542*914c2d8eSMoore, Eric #ifdef DMPT_DEBUG_FC
543*914c2d8eSMoore, Eric 	 {
544*914c2d8eSMoore, Eric 	struct mptfc_rport_info *ri;
545*914c2d8eSMoore, Eric 	ri = *((struct mptfc_rport_info **)rport->dd_data);
5463bc7bf1dSMichael Reed 	dfcprintk ((MYIOC_s_INFO_FMT
5473bc7bf1dSMichael Reed 		"mptfc_slv_alloc.%d: num_luns %d, sdev.id %d, "
54805e8ec17SMichael Reed 	        "CurrentTargetID %d, %x %llx %llx\n",
549*914c2d8eSMoore, Eric 		hd->ioc->name,
55005e8ec17SMichael Reed 		sdev->host->host_no,
55105e8ec17SMichael Reed 		vtarget->num_luns,
55205e8ec17SMichael Reed 		sdev->id, ri->pg0.CurrentTargetID,
5533bc7bf1dSMichael Reed 		ri->pg0.PortIdentifier, ri->pg0.WWPN, ri->pg0.WWNN));
554*914c2d8eSMoore, Eric 	}
555*914c2d8eSMoore, Eric #endif
55605e8ec17SMichael Reed 
55705e8ec17SMichael Reed 	return 0;
55805e8ec17SMichael Reed }
55905e8ec17SMichael Reed 
56005e8ec17SMichael Reed static int
56105e8ec17SMichael Reed mptfc_qcmd(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *))
56205e8ec17SMichael Reed {
5633bc7bf1dSMichael Reed 	struct mptfc_rport_info	*ri;
56405e8ec17SMichael Reed 	struct fc_rport	*rport = starget_to_rport(scsi_target(SCpnt->device));
56505e8ec17SMichael Reed 	int		err;
56605e8ec17SMichael Reed 
56705e8ec17SMichael Reed 	err = fc_remote_port_chkready(rport);
56805e8ec17SMichael Reed 	if (unlikely(err)) {
56905e8ec17SMichael Reed 		SCpnt->result = err;
57005e8ec17SMichael Reed 		done(SCpnt);
57105e8ec17SMichael Reed 		return 0;
57205e8ec17SMichael Reed 	}
5733bc7bf1dSMichael Reed 	ri = *((struct mptfc_rport_info **)rport->dd_data);
5743bc7bf1dSMichael Reed 	if (unlikely(ri->remap_needed))
5753bc7bf1dSMichael Reed 		return SCSI_MLQUEUE_HOST_BUSY;
5763bc7bf1dSMichael Reed 
57705e8ec17SMichael Reed 	return mptscsih_qcmd(SCpnt,done);
57805e8ec17SMichael Reed }
57905e8ec17SMichael Reed 
58005e8ec17SMichael Reed static void
58105e8ec17SMichael Reed mptfc_init_host_attr(MPT_ADAPTER *ioc,int portnum)
58205e8ec17SMichael Reed {
58305e8ec17SMichael Reed 	unsigned class = 0, cos = 0;
58405e8ec17SMichael Reed 
58505e8ec17SMichael Reed 	/* don't know what to do as only one scsi (fc) host was allocated */
58605e8ec17SMichael Reed 	if (portnum != 0)
58705e8ec17SMichael Reed 		return;
58805e8ec17SMichael Reed 
58905e8ec17SMichael Reed 	class = ioc->fc_port_page0[portnum].SupportedServiceClass;
59005e8ec17SMichael Reed 	if (class & MPI_FCPORTPAGE0_SUPPORT_CLASS_1)
59105e8ec17SMichael Reed 		cos |= FC_COS_CLASS1;
59205e8ec17SMichael Reed 	if (class & MPI_FCPORTPAGE0_SUPPORT_CLASS_2)
59305e8ec17SMichael Reed 		cos |= FC_COS_CLASS2;
59405e8ec17SMichael Reed 	if (class & MPI_FCPORTPAGE0_SUPPORT_CLASS_3)
59505e8ec17SMichael Reed 		cos |= FC_COS_CLASS3;
59605e8ec17SMichael Reed 
59705e8ec17SMichael Reed 	fc_host_node_name(ioc->sh) =
59805e8ec17SMichael Reed 	    	(u64)ioc->fc_port_page0[portnum].WWNN.High << 32
59905e8ec17SMichael Reed 		    | (u64)ioc->fc_port_page0[portnum].WWNN.Low;
60005e8ec17SMichael Reed 
60105e8ec17SMichael Reed 	fc_host_port_name(ioc->sh) =
60205e8ec17SMichael Reed 	    	(u64)ioc->fc_port_page0[portnum].WWPN.High << 32
60305e8ec17SMichael Reed 		    | (u64)ioc->fc_port_page0[portnum].WWPN.Low;
60405e8ec17SMichael Reed 
60505e8ec17SMichael Reed 	fc_host_port_id(ioc->sh) = ioc->fc_port_page0[portnum].PortIdentifier;
60605e8ec17SMichael Reed 
60705e8ec17SMichael Reed 	fc_host_supported_classes(ioc->sh) = cos;
60805e8ec17SMichael Reed 
60905e8ec17SMichael Reed 	fc_host_tgtid_bind_type(ioc->sh) = FC_TGTID_BIND_BY_WWPN;
61005e8ec17SMichael Reed }
61105e8ec17SMichael Reed 
61205e8ec17SMichael Reed static void
61305e8ec17SMichael Reed mptfc_rescan_devices(void *arg)
61405e8ec17SMichael Reed {
61505e8ec17SMichael Reed 	MPT_ADAPTER		*ioc = (MPT_ADAPTER *)arg;
61605e8ec17SMichael Reed 	int			ii;
61705e8ec17SMichael Reed 	int			work_to_do;
61805e8ec17SMichael Reed 	unsigned long		flags;
61905e8ec17SMichael Reed 	struct mptfc_rport_info *ri;
62005e8ec17SMichael Reed 
62105e8ec17SMichael Reed 	do {
62205e8ec17SMichael Reed 		/* start by tagging all ports as missing */
62305e8ec17SMichael Reed 		spin_lock_irqsave(&ioc->fc_rport_lock,flags);
62405e8ec17SMichael Reed 		list_for_each_entry(ri, &ioc->fc_rports, list) {
62505e8ec17SMichael Reed 			if (ri->flags & MPT_RPORT_INFO_FLAGS_REGISTERED) {
62605e8ec17SMichael Reed 				ri->flags |= MPT_RPORT_INFO_FLAGS_MISSING;
62705e8ec17SMichael Reed 			}
62805e8ec17SMichael Reed 		}
62905e8ec17SMichael Reed 		spin_unlock_irqrestore(&ioc->fc_rport_lock,flags);
63005e8ec17SMichael Reed 
63105e8ec17SMichael Reed 		/*
63205e8ec17SMichael Reed 		 * now rescan devices known to adapter,
63305e8ec17SMichael Reed 		 * will reregister existing rports
63405e8ec17SMichael Reed 		 */
63505e8ec17SMichael Reed 		for (ii=0; ii < ioc->facts.NumberOfPorts; ii++) {
63605e8ec17SMichael Reed 			(void) mptbase_GetFcPortPage0(ioc, ii);
63705e8ec17SMichael Reed 			mptfc_init_host_attr(ioc,ii);	/* refresh */
63805e8ec17SMichael Reed 			mptfc_GetFcDevPage0(ioc,ii,mptfc_register_dev);
63905e8ec17SMichael Reed 		}
64005e8ec17SMichael Reed 
64105e8ec17SMichael Reed 		/* delete devices still missing */
64205e8ec17SMichael Reed 		spin_lock_irqsave(&ioc->fc_rport_lock, flags);
64305e8ec17SMichael Reed 		list_for_each_entry(ri, &ioc->fc_rports, list) {
64405e8ec17SMichael Reed 			/* if newly missing, delete it */
64505e8ec17SMichael Reed 			if ((ri->flags & (MPT_RPORT_INFO_FLAGS_REGISTERED |
64605e8ec17SMichael Reed 					  MPT_RPORT_INFO_FLAGS_MISSING))
64705e8ec17SMichael Reed 			  == (MPT_RPORT_INFO_FLAGS_REGISTERED |
64805e8ec17SMichael Reed 			      MPT_RPORT_INFO_FLAGS_MISSING)) {
64905e8ec17SMichael Reed 
65005e8ec17SMichael Reed 				ri->flags &= ~(MPT_RPORT_INFO_FLAGS_REGISTERED|
65105e8ec17SMichael Reed 					       MPT_RPORT_INFO_FLAGS_MISSING);
6523bc7bf1dSMichael Reed 				ri->remap_needed = 1;
65305e8ec17SMichael Reed 				fc_remote_port_delete(ri->rport);
65405e8ec17SMichael Reed 				/*
65505e8ec17SMichael Reed 				 * remote port not really deleted 'cause
65605e8ec17SMichael Reed 				 * binding is by WWPN and driver only
6573bc7bf1dSMichael Reed 				 * registers FCP_TARGETs but cannot trust
6583bc7bf1dSMichael Reed 				 * data structures.
65905e8ec17SMichael Reed 				 */
6603bc7bf1dSMichael Reed 				ri->rport = NULL;
6613bc7bf1dSMichael Reed 				dfcprintk ((MYIOC_s_INFO_FMT
6623bc7bf1dSMichael Reed 					"mptfc_rescan.%d: %llx deleted\n",
6633bc7bf1dSMichael Reed 					ioc->name,
6643bc7bf1dSMichael Reed 					ioc->sh->host_no,
6653bc7bf1dSMichael Reed 					ri->pg0.WWPN));
66605e8ec17SMichael Reed 			}
66705e8ec17SMichael Reed 		}
66805e8ec17SMichael Reed 		spin_unlock_irqrestore(&ioc->fc_rport_lock,flags);
66905e8ec17SMichael Reed 
67005e8ec17SMichael Reed 		/*
67105e8ec17SMichael Reed 		 * allow multiple passes as target state
67205e8ec17SMichael Reed 		 * might have changed during scan
67305e8ec17SMichael Reed 		 */
67405e8ec17SMichael Reed 		spin_lock_irqsave(&ioc->fc_rescan_work_lock, flags);
67505e8ec17SMichael Reed 		if (ioc->fc_rescan_work_count > 2) 	/* only need one more */
67605e8ec17SMichael Reed 			ioc->fc_rescan_work_count = 2;
67705e8ec17SMichael Reed 		work_to_do = --ioc->fc_rescan_work_count;
67805e8ec17SMichael Reed 		spin_unlock_irqrestore(&ioc->fc_rescan_work_lock, flags);
67905e8ec17SMichael Reed 	} while (work_to_do);
68005e8ec17SMichael Reed }
68105e8ec17SMichael Reed 
6822496af39SMoore, Eric Dean  static int
6832496af39SMoore, Eric Dean  mptfc_probe(struct pci_dev *pdev, const struct pci_device_id *id)
6842496af39SMoore, Eric Dean  {
6852496af39SMoore, Eric Dean  	struct Scsi_Host	*sh;
6862496af39SMoore, Eric Dean  	MPT_SCSI_HOST		*hd;
6872496af39SMoore, Eric Dean  	MPT_ADAPTER 		*ioc;
6882496af39SMoore, Eric Dean  	unsigned long		 flags;
6891ca00bb7SChristoph Hellwig 	int			 ii;
6902496af39SMoore, Eric Dean  	int			 numSGE = 0;
6912496af39SMoore, Eric Dean  	int			 scale;
6922496af39SMoore, Eric Dean  	int			 ioc_cap;
6932496af39SMoore, Eric Dean  	int			error=0;
6942496af39SMoore, Eric Dean  	int			r;
6952496af39SMoore, Eric Dean  
6962496af39SMoore, Eric Dean  	if ((r = mpt_attach(pdev,id)) != 0)
6972496af39SMoore, Eric Dean  		return r;
6982496af39SMoore, Eric Dean  
6992496af39SMoore, Eric Dean  	ioc = pci_get_drvdata(pdev);
700d335cc38SMoore, Eric Dean  	ioc->DoneCtx = mptfcDoneCtx;
701d335cc38SMoore, Eric Dean  	ioc->TaskCtx = mptfcTaskCtx;
702d335cc38SMoore, Eric Dean  	ioc->InternalCtx = mptfcInternalCtx;
7032496af39SMoore, Eric Dean  
7042496af39SMoore, Eric Dean  	/*  Added sanity check on readiness of the MPT adapter.
7052496af39SMoore, Eric Dean  	 */
7062496af39SMoore, Eric Dean  	if (ioc->last_state != MPI_IOC_STATE_OPERATIONAL) {
7072496af39SMoore, Eric Dean  		printk(MYIOC_s_WARN_FMT
7082496af39SMoore, Eric Dean  		  "Skipping because it's not operational!\n",
7092496af39SMoore, Eric Dean  		  ioc->name);
7107acec1e7SMoore, Eric Dean 		error = -ENODEV;
7117acec1e7SMoore, Eric Dean 		goto out_mptfc_probe;
7122496af39SMoore, Eric Dean  	}
7132496af39SMoore, Eric Dean  
7142496af39SMoore, Eric Dean  	if (!ioc->active) {
7152496af39SMoore, Eric Dean  		printk(MYIOC_s_WARN_FMT "Skipping because it's disabled!\n",
7162496af39SMoore, Eric Dean  		  ioc->name);
7177acec1e7SMoore, Eric Dean 		error = -ENODEV;
7187acec1e7SMoore, Eric Dean 		goto out_mptfc_probe;
7192496af39SMoore, Eric Dean  	}
7202496af39SMoore, Eric Dean  
7212496af39SMoore, Eric Dean  	/*  Sanity check - ensure at least 1 port is INITIATOR capable
7222496af39SMoore, Eric Dean  	 */
7232496af39SMoore, Eric Dean  	ioc_cap = 0;
7242496af39SMoore, Eric Dean  	for (ii=0; ii < ioc->facts.NumberOfPorts; ii++) {
7252496af39SMoore, Eric Dean  		if (ioc->pfacts[ii].ProtocolFlags &
7262496af39SMoore, Eric Dean  		    MPI_PORTFACTS_PROTOCOL_INITIATOR)
7272496af39SMoore, Eric Dean  			ioc_cap ++;
7282496af39SMoore, Eric Dean  	}
7292496af39SMoore, Eric Dean  
7302496af39SMoore, Eric Dean  	if (!ioc_cap) {
7312496af39SMoore, Eric Dean  		printk(MYIOC_s_WARN_FMT
7322496af39SMoore, Eric Dean  			"Skipping ioc=%p because SCSI Initiator mode is NOT enabled!\n",
7332496af39SMoore, Eric Dean  			ioc->name, ioc);
73405e8ec17SMichael Reed 		return -ENODEV;
7352496af39SMoore, Eric Dean  	}
7362496af39SMoore, Eric Dean  
7372496af39SMoore, Eric Dean  	sh = scsi_host_alloc(&mptfc_driver_template, sizeof(MPT_SCSI_HOST));
7382496af39SMoore, Eric Dean  
7392496af39SMoore, Eric Dean  	if (!sh) {
7402496af39SMoore, Eric Dean  		printk(MYIOC_s_WARN_FMT
7412496af39SMoore, Eric Dean  			"Unable to register controller with SCSI subsystem\n",
7422496af39SMoore, Eric Dean  			ioc->name);
7437acec1e7SMoore, Eric Dean 		error = -1;
7447acec1e7SMoore, Eric Dean 		goto out_mptfc_probe;
7452496af39SMoore, Eric Dean          }
7462496af39SMoore, Eric Dean  
74705e8ec17SMichael Reed 	INIT_WORK(&ioc->fc_rescan_work, mptfc_rescan_devices,(void *)ioc);
74805e8ec17SMichael Reed 
7492496af39SMoore, Eric Dean  	spin_lock_irqsave(&ioc->FreeQlock, flags);
7502496af39SMoore, Eric Dean  
7512496af39SMoore, Eric Dean  	/* Attach the SCSI Host to the IOC structure
7522496af39SMoore, Eric Dean  	 */
7532496af39SMoore, Eric Dean  	ioc->sh = sh;
7542496af39SMoore, Eric Dean  
7552496af39SMoore, Eric Dean  	sh->io_port = 0;
7562496af39SMoore, Eric Dean  	sh->n_io_port = 0;
7572496af39SMoore, Eric Dean  	sh->irq = 0;
7582496af39SMoore, Eric Dean  
7592496af39SMoore, Eric Dean  	/* set 16 byte cdb's */
7602496af39SMoore, Eric Dean  	sh->max_cmd_len = 16;
7612496af39SMoore, Eric Dean  
7622496af39SMoore, Eric Dean  	sh->max_id = MPT_MAX_FC_DEVICES<256 ? MPT_MAX_FC_DEVICES : 255;
7632496af39SMoore, Eric Dean  
7642496af39SMoore, Eric Dean  	sh->max_lun = MPT_LAST_LUN + 1;
7652496af39SMoore, Eric Dean  	sh->max_channel = 0;
7662496af39SMoore, Eric Dean  	sh->this_id = ioc->pfacts[0].PortSCSIID;
7672496af39SMoore, Eric Dean  
7682496af39SMoore, Eric Dean  	/* Required entry.
7692496af39SMoore, Eric Dean  	 */
7702496af39SMoore, Eric Dean  	sh->unique_id = ioc->id;
7712496af39SMoore, Eric Dean  
7722496af39SMoore, Eric Dean  	/* Verify that we won't exceed the maximum
7732496af39SMoore, Eric Dean  	 * number of chain buffers
7742496af39SMoore, Eric Dean  	 * We can optimize:  ZZ = req_sz/sizeof(SGE)
7752496af39SMoore, Eric Dean  	 * For 32bit SGE's:
7762496af39SMoore, Eric Dean  	 *  numSGE = 1 + (ZZ-1)*(maxChain -1) + ZZ
7772496af39SMoore, Eric Dean  	 *               + (req_sz - 64)/sizeof(SGE)
7782496af39SMoore, Eric Dean  	 * A slightly different algorithm is required for
7792496af39SMoore, Eric Dean  	 * 64bit SGEs.
7802496af39SMoore, Eric Dean  	 */
7812496af39SMoore, Eric Dean  	scale = ioc->req_sz/(sizeof(dma_addr_t) + sizeof(u32));
7822496af39SMoore, Eric Dean  	if (sizeof(dma_addr_t) == sizeof(u64)) {
7832496af39SMoore, Eric Dean  		numSGE = (scale - 1) *
7842496af39SMoore, Eric Dean  		  (ioc->facts.MaxChainDepth-1) + scale +
7852496af39SMoore, Eric Dean  		  (ioc->req_sz - 60) / (sizeof(dma_addr_t) +
7862496af39SMoore, Eric Dean  		  sizeof(u32));
7872496af39SMoore, Eric Dean  	} else {
7882496af39SMoore, Eric Dean  		numSGE = 1 + (scale - 1) *
7892496af39SMoore, Eric Dean  		  (ioc->facts.MaxChainDepth-1) + scale +
7902496af39SMoore, Eric Dean  		  (ioc->req_sz - 64) / (sizeof(dma_addr_t) +
7912496af39SMoore, Eric Dean  		  sizeof(u32));
7922496af39SMoore, Eric Dean  	}
7932496af39SMoore, Eric Dean  
7942496af39SMoore, Eric Dean  	if (numSGE < sh->sg_tablesize) {
7952496af39SMoore, Eric Dean  		/* Reset this value */
7962496af39SMoore, Eric Dean  		dprintk((MYIOC_s_INFO_FMT
7972496af39SMoore, Eric Dean  		  "Resetting sg_tablesize to %d from %d\n",
7982496af39SMoore, Eric Dean  		  ioc->name, numSGE, sh->sg_tablesize));
7992496af39SMoore, Eric Dean  		sh->sg_tablesize = numSGE;
8002496af39SMoore, Eric Dean  	}
8012496af39SMoore, Eric Dean  
8022496af39SMoore, Eric Dean  	spin_unlock_irqrestore(&ioc->FreeQlock, flags);
8032496af39SMoore, Eric Dean  
8042496af39SMoore, Eric Dean  	hd = (MPT_SCSI_HOST *) sh->hostdata;
8052496af39SMoore, Eric Dean  	hd->ioc = ioc;
8062496af39SMoore, Eric Dean  
8072496af39SMoore, Eric Dean  	/* SCSI needs scsi_cmnd lookup table!
8082496af39SMoore, Eric Dean  	 * (with size equal to req_depth*PtrSz!)
8092496af39SMoore, Eric Dean  	 */
8101ca00bb7SChristoph Hellwig 	hd->ScsiLookup = kcalloc(ioc->req_depth, sizeof(void *), GFP_ATOMIC);
8111ca00bb7SChristoph Hellwig 	if (!hd->ScsiLookup) {
8122496af39SMoore, Eric Dean  		error = -ENOMEM;
8137acec1e7SMoore, Eric Dean 		goto out_mptfc_probe;
8142496af39SMoore, Eric Dean  	}
8152496af39SMoore, Eric Dean  
8161ca00bb7SChristoph Hellwig 	dprintk((MYIOC_s_INFO_FMT "ScsiLookup @ %p\n",
8171ca00bb7SChristoph Hellwig 		 ioc->name, hd->ScsiLookup));
8182496af39SMoore, Eric Dean  
8192496af39SMoore, Eric Dean  	/* Allocate memory for the device structures.
8202496af39SMoore, Eric Dean  	 * A non-Null pointer at an offset
8212496af39SMoore, Eric Dean  	 * indicates a device exists.
8222496af39SMoore, Eric Dean  	 * max_id = 1 + maximum id (hosts.h)
8232496af39SMoore, Eric Dean  	 */
8241ca00bb7SChristoph Hellwig 	hd->Targets = kcalloc(sh->max_id, sizeof(void *), GFP_ATOMIC);
8251ca00bb7SChristoph Hellwig 	if (!hd->Targets) {
8262496af39SMoore, Eric Dean  		error = -ENOMEM;
8277acec1e7SMoore, Eric Dean 		goto out_mptfc_probe;
8282496af39SMoore, Eric Dean  	}
8292496af39SMoore, Eric Dean  
8301ca00bb7SChristoph Hellwig 	dprintk((KERN_INFO "  vdev @ %p\n", hd->Targets));
8312496af39SMoore, Eric Dean  
8322496af39SMoore, Eric Dean  	/* Clear the TM flags
8332496af39SMoore, Eric Dean  	 */
8342496af39SMoore, Eric Dean  	hd->tmPending = 0;
8352496af39SMoore, Eric Dean  	hd->tmState = TM_STATE_NONE;
8362496af39SMoore, Eric Dean  	hd->resetPending = 0;
8372496af39SMoore, Eric Dean  	hd->abortSCpnt = NULL;
8382496af39SMoore, Eric Dean  
8392496af39SMoore, Eric Dean  	/* Clear the pointer used to store
8402496af39SMoore, Eric Dean  	 * single-threaded commands, i.e., those
8412496af39SMoore, Eric Dean  	 * issued during a bus scan, dv and
8422496af39SMoore, Eric Dean  	 * configuration pages.
8432496af39SMoore, Eric Dean  	 */
8442496af39SMoore, Eric Dean  	hd->cmdPtr = NULL;
8452496af39SMoore, Eric Dean  
8462496af39SMoore, Eric Dean  	/* Initialize this SCSI Hosts' timers
8472496af39SMoore, Eric Dean  	 * To use, set the timer expires field
8482496af39SMoore, Eric Dean  	 * and add_timer
8492496af39SMoore, Eric Dean  	 */
8502496af39SMoore, Eric Dean  	init_timer(&hd->timer);
8512496af39SMoore, Eric Dean  	hd->timer.data = (unsigned long) hd;
8522496af39SMoore, Eric Dean  	hd->timer.function = mptscsih_timer_expired;
8532496af39SMoore, Eric Dean  
8542496af39SMoore, Eric Dean  	hd->mpt_pq_filter = mpt_pq_filter;
8552496af39SMoore, Eric Dean  
8562496af39SMoore, Eric Dean  	ddvprintk((MYIOC_s_INFO_FMT
8572496af39SMoore, Eric Dean  		"mpt_pq_filter %x\n",
8582496af39SMoore, Eric Dean  		ioc->name,
8592496af39SMoore, Eric Dean  		mpt_pq_filter));
8602496af39SMoore, Eric Dean  
8612496af39SMoore, Eric Dean  	init_waitqueue_head(&hd->scandv_waitq);
8622496af39SMoore, Eric Dean  	hd->scandv_wait_done = 0;
8632496af39SMoore, Eric Dean  	hd->last_queue_full = 0;
8642496af39SMoore, Eric Dean  
86505e8ec17SMichael Reed 	sh->transportt = mptfc_transport_template;
8662496af39SMoore, Eric Dean  	error = scsi_add_host (sh, &ioc->pcidev->dev);
8672496af39SMoore, Eric Dean  	if(error) {
8682496af39SMoore, Eric Dean  		dprintk((KERN_ERR MYNAM
8692496af39SMoore, Eric Dean  		  "scsi_add_host failed\n"));
8707acec1e7SMoore, Eric Dean 		goto out_mptfc_probe;
8712496af39SMoore, Eric Dean  	}
8722496af39SMoore, Eric Dean  
87305e8ec17SMichael Reed 	for (ii=0; ii < ioc->facts.NumberOfPorts; ii++) {
87405e8ec17SMichael Reed 		mptfc_init_host_attr(ioc,ii);
87505e8ec17SMichael Reed 		mptfc_GetFcDevPage0(ioc,ii,mptfc_register_dev);
87605e8ec17SMichael Reed 	}
87705e8ec17SMichael Reed 
8782496af39SMoore, Eric Dean  	return 0;
8792496af39SMoore, Eric Dean  
8807acec1e7SMoore, Eric Dean out_mptfc_probe:
8812496af39SMoore, Eric Dean  
8822496af39SMoore, Eric Dean  	mptscsih_remove(pdev);
8832496af39SMoore, Eric Dean  	return error;
8842496af39SMoore, Eric Dean  }
8852496af39SMoore, Eric Dean  
8862496af39SMoore, Eric Dean  static struct pci_driver mptfc_driver = {
8872496af39SMoore, Eric Dean  	.name		= "mptfc",
8882496af39SMoore, Eric Dean  	.id_table	= mptfc_pci_table,
8892496af39SMoore, Eric Dean  	.probe		= mptfc_probe,
89005e8ec17SMichael Reed 	.remove		= __devexit_p(mptfc_remove),
8912496af39SMoore, Eric Dean  	.shutdown	= mptscsih_shutdown,
8922496af39SMoore, Eric Dean  #ifdef CONFIG_PM
8932496af39SMoore, Eric Dean  	.suspend	= mptscsih_suspend,
8942496af39SMoore, Eric Dean  	.resume		= mptscsih_resume,
8952496af39SMoore, Eric Dean  #endif
8962496af39SMoore, Eric Dean  };
8972496af39SMoore, Eric Dean  
8982496af39SMoore, Eric Dean  /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
8992496af39SMoore, Eric Dean  /**
9002496af39SMoore, Eric Dean   *	mptfc_init - Register MPT adapter(s) as SCSI host(s) with
9012496af39SMoore, Eric Dean   *	linux scsi mid-layer.
9022496af39SMoore, Eric Dean   *
9032496af39SMoore, Eric Dean   *	Returns 0 for success, non-zero for failure.
9042496af39SMoore, Eric Dean   */
9052496af39SMoore, Eric Dean  static int __init
9062496af39SMoore, Eric Dean  mptfc_init(void)
9072496af39SMoore, Eric Dean  {
90805e8ec17SMichael Reed 	int error;
9092496af39SMoore, Eric Dean  
9102496af39SMoore, Eric Dean  	show_mptmod_ver(my_NAME, my_VERSION);
9112496af39SMoore, Eric Dean  
91205e8ec17SMichael Reed 	/* sanity check module parameter */
91305e8ec17SMichael Reed 	if (mptfc_dev_loss_tmo == 0)
91405e8ec17SMichael Reed 		mptfc_dev_loss_tmo = MPTFC_DEV_LOSS_TMO;
91505e8ec17SMichael Reed 
91605e8ec17SMichael Reed 	mptfc_transport_template =
91705e8ec17SMichael Reed 		fc_attach_transport(&mptfc_transport_functions);
91805e8ec17SMichael Reed 
91905e8ec17SMichael Reed 	if (!mptfc_transport_template)
92005e8ec17SMichael Reed 		return -ENODEV;
92105e8ec17SMichael Reed 
9222496af39SMoore, Eric Dean  	mptfcDoneCtx = mpt_register(mptscsih_io_done, MPTFC_DRIVER);
9232496af39SMoore, Eric Dean  	mptfcTaskCtx = mpt_register(mptscsih_taskmgmt_complete, MPTFC_DRIVER);
9242496af39SMoore, Eric Dean  	mptfcInternalCtx = mpt_register(mptscsih_scandv_complete, MPTFC_DRIVER);
9252496af39SMoore, Eric Dean  
9262496af39SMoore, Eric Dean  	if (mpt_event_register(mptfcDoneCtx, mptscsih_event_process) == 0) {
9273a892befSMoore, Eric 		devtverboseprintk((KERN_INFO MYNAM
9282496af39SMoore, Eric Dean  		  ": Registered for IOC event notifications\n"));
9292496af39SMoore, Eric Dean  	}
9302496af39SMoore, Eric Dean  
9312496af39SMoore, Eric Dean  	if (mpt_reset_register(mptfcDoneCtx, mptscsih_ioc_reset) == 0) {
9322496af39SMoore, Eric Dean  		dprintk((KERN_INFO MYNAM
9332496af39SMoore, Eric Dean  		  ": Registered for IOC reset notifications\n"));
9342496af39SMoore, Eric Dean  	}
9352496af39SMoore, Eric Dean  
93605e8ec17SMichael Reed 	error = pci_register_driver(&mptfc_driver);
9373bc7bf1dSMichael Reed 	if (error)
93805e8ec17SMichael Reed 		fc_release_transport(mptfc_transport_template);
93905e8ec17SMichael Reed 
94005e8ec17SMichael Reed 	return error;
94105e8ec17SMichael Reed }
94205e8ec17SMichael Reed 
94305e8ec17SMichael Reed /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
94405e8ec17SMichael Reed /**
94505e8ec17SMichael Reed  *	mptfc_remove - Removed fc infrastructure for devices
94605e8ec17SMichael Reed  *	@pdev: Pointer to pci_dev structure
94705e8ec17SMichael Reed  *
94805e8ec17SMichael Reed  */
9493bc7bf1dSMichael Reed static void __devexit
9503bc7bf1dSMichael Reed mptfc_remove(struct pci_dev *pdev)
95105e8ec17SMichael Reed {
95205e8ec17SMichael Reed 	MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
95305e8ec17SMichael Reed 	struct mptfc_rport_info *p, *n;
95405e8ec17SMichael Reed 
95505e8ec17SMichael Reed 	fc_remove_host(ioc->sh);
95605e8ec17SMichael Reed 
95705e8ec17SMichael Reed 	list_for_each_entry_safe(p, n, &ioc->fc_rports, list) {
95805e8ec17SMichael Reed 		list_del(&p->list);
95905e8ec17SMichael Reed 		kfree(p);
96005e8ec17SMichael Reed 	}
96105e8ec17SMichael Reed 
96205e8ec17SMichael Reed 	mptscsih_remove(pdev);
9632496af39SMoore, Eric Dean  }
9642496af39SMoore, Eric Dean  
9652496af39SMoore, Eric Dean  /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
9662496af39SMoore, Eric Dean  /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
9672496af39SMoore, Eric Dean  /**
9682496af39SMoore, Eric Dean   *	mptfc_exit - Unregisters MPT adapter(s)
9692496af39SMoore, Eric Dean   *
9702496af39SMoore, Eric Dean   */
9712496af39SMoore, Eric Dean  static void __exit
9722496af39SMoore, Eric Dean  mptfc_exit(void)
9732496af39SMoore, Eric Dean  {
9742496af39SMoore, Eric Dean  	pci_unregister_driver(&mptfc_driver);
97505e8ec17SMichael Reed 	fc_release_transport(mptfc_transport_template);
9762496af39SMoore, Eric Dean  
9772496af39SMoore, Eric Dean  	mpt_reset_deregister(mptfcDoneCtx);
9782496af39SMoore, Eric Dean  	dprintk((KERN_INFO MYNAM
9792496af39SMoore, Eric Dean  	  ": Deregistered for IOC reset notifications\n"));
9802496af39SMoore, Eric Dean  
9812496af39SMoore, Eric Dean  	mpt_event_deregister(mptfcDoneCtx);
9822496af39SMoore, Eric Dean  	dprintk((KERN_INFO MYNAM
9832496af39SMoore, Eric Dean  	  ": Deregistered for IOC event notifications\n"));
9842496af39SMoore, Eric Dean  
9852496af39SMoore, Eric Dean  	mpt_deregister(mptfcInternalCtx);
9862496af39SMoore, Eric Dean  	mpt_deregister(mptfcTaskCtx);
9872496af39SMoore, Eric Dean  	mpt_deregister(mptfcDoneCtx);
9882496af39SMoore, Eric Dean  }
9892496af39SMoore, Eric Dean  
9902496af39SMoore, Eric Dean  module_init(mptfc_init);
9912496af39SMoore, Eric Dean  module_exit(mptfc_exit);
992