xref: /openbmc/linux/drivers/message/fusion/mptfc.c (revision 3a892bef3f7e94c4d6c2c20b9a1b546f43679fd3)
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
3523bc7bf1dSMichael Reed mptfc_remap_sdev(struct scsi_device *sdev, void *arg)
3533bc7bf1dSMichael Reed {
3543bc7bf1dSMichael Reed 	VirtDevice		*vdev;
3553bc7bf1dSMichael Reed 	VirtTarget		*vtarget;
3563bc7bf1dSMichael Reed 	struct scsi_target	*starget;
3573bc7bf1dSMichael Reed 
3583bc7bf1dSMichael Reed 	starget = scsi_target(sdev);
3593bc7bf1dSMichael Reed 	if (starget->hostdata == arg) {
3603bc7bf1dSMichael Reed 		vtarget = arg;
3613bc7bf1dSMichael Reed 		vdev = sdev->hostdata;
3623bc7bf1dSMichael Reed 		if (vdev) {
3633bc7bf1dSMichael Reed 			vdev->bus_id = vtarget->bus_id;
3643bc7bf1dSMichael Reed 			vdev->target_id = vtarget->target_id;
3653bc7bf1dSMichael Reed 		}
3663bc7bf1dSMichael Reed 	}
3673bc7bf1dSMichael Reed }
3683bc7bf1dSMichael Reed 
3693bc7bf1dSMichael Reed static void
37005e8ec17SMichael Reed mptfc_register_dev(MPT_ADAPTER *ioc, int channel, FCDevicePage0_t *pg0)
37105e8ec17SMichael Reed {
37205e8ec17SMichael Reed 	struct fc_rport_identifiers rport_ids;
37305e8ec17SMichael Reed 	struct fc_rport		*rport;
37405e8ec17SMichael Reed 	struct mptfc_rport_info	*ri;
3753bc7bf1dSMichael Reed 	int			new_ri = 1;
3763bc7bf1dSMichael Reed 	u64			pn;
37705e8ec17SMichael Reed 	unsigned long		flags;
3783bc7bf1dSMichael Reed 	VirtTarget		*vtarget;
37905e8ec17SMichael Reed 
38005e8ec17SMichael Reed 	if (mptfc_generate_rport_ids(pg0, &rport_ids) < 0)
38105e8ec17SMichael Reed 		return;
38205e8ec17SMichael Reed 
38305e8ec17SMichael Reed 	/* scan list looking for a match */
38405e8ec17SMichael Reed 	spin_lock_irqsave(&ioc->fc_rport_lock, flags);
38505e8ec17SMichael Reed 	list_for_each_entry(ri, &ioc->fc_rports, list) {
3863bc7bf1dSMichael Reed 		pn = (u64)ri->pg0.WWPN.High << 32 | (u64)ri->pg0.WWPN.Low;
3873bc7bf1dSMichael Reed 		if (pn == rport_ids.port_name) {	/* match */
38805e8ec17SMichael Reed 			list_move_tail(&ri->list, &ioc->fc_rports);
3893bc7bf1dSMichael Reed 			new_ri = 0;
39005e8ec17SMichael Reed 			break;
39105e8ec17SMichael Reed 		}
39205e8ec17SMichael Reed 	}
3933bc7bf1dSMichael Reed 	if (new_ri) {	/* allocate one */
39405e8ec17SMichael Reed 		spin_unlock_irqrestore(&ioc->fc_rport_lock, flags);
39505e8ec17SMichael Reed 		ri = kzalloc(sizeof(struct mptfc_rport_info), GFP_KERNEL);
39605e8ec17SMichael Reed 		if (!ri)
39705e8ec17SMichael Reed 			return;
39805e8ec17SMichael Reed 		spin_lock_irqsave(&ioc->fc_rport_lock, flags);
39905e8ec17SMichael Reed 		list_add_tail(&ri->list, &ioc->fc_rports);
40005e8ec17SMichael Reed 	}
40105e8ec17SMichael Reed 
40205e8ec17SMichael Reed 	ri->pg0 = *pg0;	/* add/update pg0 data */
40305e8ec17SMichael Reed 	ri->flags &= ~MPT_RPORT_INFO_FLAGS_MISSING;
40405e8ec17SMichael Reed 
4053bc7bf1dSMichael Reed 	/* MPT_RPORT_INFO_FLAGS_REGISTERED - rport not previously deleted */
40605e8ec17SMichael Reed 	if (!(ri->flags & MPT_RPORT_INFO_FLAGS_REGISTERED)) {
40705e8ec17SMichael Reed 		ri->flags |= MPT_RPORT_INFO_FLAGS_REGISTERED;
40805e8ec17SMichael Reed 		spin_unlock_irqrestore(&ioc->fc_rport_lock, flags);
40905e8ec17SMichael Reed 		rport = fc_remote_port_add(ioc->sh, channel, &rport_ids);
41005e8ec17SMichael Reed 		spin_lock_irqsave(&ioc->fc_rport_lock, flags);
41105e8ec17SMichael Reed 		if (rport) {
41205e8ec17SMichael Reed 			ri->rport = rport;
4133bc7bf1dSMichael Reed 			if (new_ri) /* may have been reset by user */
41405e8ec17SMichael Reed 				rport->dev_loss_tmo = mptfc_dev_loss_tmo;
4153bc7bf1dSMichael Reed 			*((struct mptfc_rport_info **)rport->dd_data) = ri;
41605e8ec17SMichael Reed 			/*
41705e8ec17SMichael Reed 			 * if already mapped, remap here.  If not mapped,
4183bc7bf1dSMichael Reed 			 * target_alloc will allocate vtarget and map,
4193bc7bf1dSMichael Reed 			 * slave_alloc will fill in vdev from vtarget.
42005e8ec17SMichael Reed 			 */
4213bc7bf1dSMichael Reed 			if (ri->starget) {
4223bc7bf1dSMichael Reed 				vtarget = ri->starget->hostdata;
4233bc7bf1dSMichael Reed 				if (vtarget) {
4243bc7bf1dSMichael Reed 					vtarget->target_id = pg0->CurrentTargetID;
4253bc7bf1dSMichael Reed 					vtarget->bus_id = pg0->CurrentBus;
4263bc7bf1dSMichael Reed 					starget_for_each_device(ri->starget,
4273bc7bf1dSMichael Reed 						vtarget,mptfc_remap_sdev);
42805e8ec17SMichael Reed 				}
4293bc7bf1dSMichael Reed 				ri->remap_needed = 0;
4303bc7bf1dSMichael Reed 			}
4313bc7bf1dSMichael Reed 			dfcprintk ((MYIOC_s_INFO_FMT
4323bc7bf1dSMichael Reed 				"mptfc_reg_dev.%d: %x, %llx / %llx, tid %d, "
43305e8ec17SMichael Reed 				"rport tid %d, tmo %d\n",
4343bc7bf1dSMichael Reed 					ioc->name,
4353bc7bf1dSMichael Reed 					oc->sh->host_no,
43605e8ec17SMichael Reed 					pg0->PortIdentifier,
43705e8ec17SMichael Reed 					pg0->WWNN,
43805e8ec17SMichael Reed 					pg0->WWPN,
43905e8ec17SMichael Reed 					pg0->CurrentTargetID,
44005e8ec17SMichael Reed 					ri->rport->scsi_target_id,
4413bc7bf1dSMichael Reed 					ri->rport->dev_loss_tmo));
44205e8ec17SMichael Reed 		} else {
44305e8ec17SMichael Reed 			list_del(&ri->list);
44405e8ec17SMichael Reed 			kfree(ri);
44505e8ec17SMichael Reed 			ri = NULL;
44605e8ec17SMichael Reed 		}
44705e8ec17SMichael Reed 	}
44805e8ec17SMichael Reed 	spin_unlock_irqrestore(&ioc->fc_rport_lock,flags);
44905e8ec17SMichael Reed 
45005e8ec17SMichael Reed }
45105e8ec17SMichael Reed 
45205e8ec17SMichael Reed /*
4533bc7bf1dSMichael Reed  *	OS entry point to allow for host driver to free allocated memory
4543bc7bf1dSMichael Reed  *	Called if no device present or device being unloaded
4553bc7bf1dSMichael Reed  */
4563bc7bf1dSMichael Reed static void
4573bc7bf1dSMichael Reed mptfc_target_destroy(struct scsi_target *starget)
4583bc7bf1dSMichael Reed {
4593bc7bf1dSMichael Reed 	struct fc_rport		*rport;
4603bc7bf1dSMichael Reed 	struct mptfc_rport_info *ri;
4613bc7bf1dSMichael Reed 
4623bc7bf1dSMichael Reed 	rport = starget_to_rport(starget);
4633bc7bf1dSMichael Reed 	if (rport) {
4643bc7bf1dSMichael Reed 		ri = *((struct mptfc_rport_info **)rport->dd_data);
4653bc7bf1dSMichael Reed 		if (ri)	/* better be! */
4663bc7bf1dSMichael Reed 			ri->starget = NULL;
4673bc7bf1dSMichael Reed 	}
4683bc7bf1dSMichael Reed 	if (starget->hostdata)
4693bc7bf1dSMichael Reed 		kfree(starget->hostdata);
4703bc7bf1dSMichael Reed 	starget->hostdata = NULL;
4713bc7bf1dSMichael Reed }
4723bc7bf1dSMichael Reed 
4733bc7bf1dSMichael Reed /*
4743bc7bf1dSMichael Reed  *	OS entry point to allow host driver to alloc memory
4753bc7bf1dSMichael Reed  *	for each scsi target. Called once per device the bus scan.
4763bc7bf1dSMichael Reed  *	Return non-zero if allocation fails.
4773bc7bf1dSMichael Reed  */
4783bc7bf1dSMichael Reed static int
4793bc7bf1dSMichael Reed mptfc_target_alloc(struct scsi_target *starget)
4803bc7bf1dSMichael Reed {
4813bc7bf1dSMichael Reed 	VirtTarget		*vtarget;
4823bc7bf1dSMichael Reed 	struct fc_rport		*rport;
4833bc7bf1dSMichael Reed 	struct mptfc_rport_info *ri;
4843bc7bf1dSMichael Reed 	int			rc;
4853bc7bf1dSMichael Reed 
4863bc7bf1dSMichael Reed 	vtarget = kzalloc(sizeof(VirtTarget), GFP_KERNEL);
4873bc7bf1dSMichael Reed 	if (!vtarget)
4883bc7bf1dSMichael Reed 		return -ENOMEM;
4893bc7bf1dSMichael Reed 	starget->hostdata = vtarget;
4903bc7bf1dSMichael Reed 
4913bc7bf1dSMichael Reed 	rc = -ENODEV;
4923bc7bf1dSMichael Reed 	rport = starget_to_rport(starget);
4933bc7bf1dSMichael Reed 	if (rport) {
4943bc7bf1dSMichael Reed 		ri = *((struct mptfc_rport_info **)rport->dd_data);
4953bc7bf1dSMichael Reed 		if (ri) {	/* better be! */
4963bc7bf1dSMichael Reed 			vtarget->target_id = ri->pg0.CurrentTargetID;
4973bc7bf1dSMichael Reed 			vtarget->bus_id = ri->pg0.CurrentBus;
4983bc7bf1dSMichael Reed 			ri->starget = starget;
4993bc7bf1dSMichael Reed 			ri->remap_needed = 0;
5003bc7bf1dSMichael Reed 			rc = 0;
5013bc7bf1dSMichael Reed 		}
5023bc7bf1dSMichael Reed 	}
5033bc7bf1dSMichael Reed 	if (rc != 0) {
5043bc7bf1dSMichael Reed 		kfree(vtarget);
5053bc7bf1dSMichael Reed 		starget->hostdata = NULL;
5063bc7bf1dSMichael Reed 	}
5073bc7bf1dSMichael Reed 
5083bc7bf1dSMichael Reed 	return rc;
5093bc7bf1dSMichael Reed }
5103bc7bf1dSMichael Reed 
5113bc7bf1dSMichael Reed /*
51205e8ec17SMichael Reed  *	OS entry point to allow host driver to alloc memory
51305e8ec17SMichael Reed  *	for each scsi device. Called once per device the bus scan.
51405e8ec17SMichael Reed  *	Return non-zero if allocation fails.
51505e8ec17SMichael Reed  *	Init memory once per LUN.
51605e8ec17SMichael Reed  */
51703fbcbcdSAdrian Bunk static int
51805e8ec17SMichael Reed mptfc_slave_alloc(struct scsi_device *sdev)
51905e8ec17SMichael Reed {
52005e8ec17SMichael Reed 	MPT_SCSI_HOST		*hd;
52105e8ec17SMichael Reed 	VirtTarget		*vtarget;
52205e8ec17SMichael Reed 	VirtDevice		*vdev;
52305e8ec17SMichael Reed 	struct scsi_target	*starget;
52405e8ec17SMichael Reed 	struct fc_rport		*rport;
52505e8ec17SMichael Reed 	unsigned long		flags;
52605e8ec17SMichael Reed 
52705e8ec17SMichael Reed 
52805e8ec17SMichael Reed 	rport = starget_to_rport(scsi_target(sdev));
52905e8ec17SMichael Reed 
53005e8ec17SMichael Reed 	if (!rport || fc_remote_port_chkready(rport))
53105e8ec17SMichael Reed 		return -ENXIO;
53205e8ec17SMichael Reed 
53305e8ec17SMichael Reed 	hd = (MPT_SCSI_HOST *)sdev->host->hostdata;
53405e8ec17SMichael Reed 
5353bc7bf1dSMichael Reed 	vdev = kzalloc(sizeof(VirtDevice), GFP_KERNEL);
53605e8ec17SMichael Reed 	if (!vdev) {
53705e8ec17SMichael Reed 		printk(MYIOC_s_ERR_FMT "slave_alloc kmalloc(%zd) FAILED!\n",
53805e8ec17SMichael Reed 				hd->ioc->name, sizeof(VirtDevice));
53905e8ec17SMichael Reed 		return -ENOMEM;
54005e8ec17SMichael Reed 	}
54105e8ec17SMichael Reed 
54205e8ec17SMichael Reed 	spin_lock_irqsave(&hd->ioc->fc_rport_lock,flags);
54305e8ec17SMichael Reed 
54405e8ec17SMichael Reed 	sdev->hostdata = vdev;
54505e8ec17SMichael Reed 	starget = scsi_target(sdev);
54605e8ec17SMichael Reed 	vtarget = starget->hostdata;
5473bc7bf1dSMichael Reed 
54805e8ec17SMichael Reed 	if (vtarget->num_luns == 0) {
5493bc7bf1dSMichael Reed 		vtarget->ioc_id = hd->ioc->id;
55005e8ec17SMichael Reed 		vtarget->tflags = MPT_TARGET_FLAGS_Q_YES |
55105e8ec17SMichael Reed 		    		  MPT_TARGET_FLAGS_VALID_INQUIRY;
55205e8ec17SMichael Reed 		hd->Targets[sdev->id] = vtarget;
55305e8ec17SMichael Reed 	}
55405e8ec17SMichael Reed 
55505e8ec17SMichael Reed 	vdev->vtarget = vtarget;
55605e8ec17SMichael Reed 	vdev->ioc_id = hd->ioc->id;
55705e8ec17SMichael Reed 	vdev->lun = sdev->lun;
5583bc7bf1dSMichael Reed 	vdev->target_id = vtarget->target_id;
5593bc7bf1dSMichael Reed 	vdev->bus_id = vtarget->bus_id;
56005e8ec17SMichael Reed 
56105e8ec17SMichael Reed 	spin_unlock_irqrestore(&hd->ioc->fc_rport_lock,flags);
56205e8ec17SMichael Reed 
56305e8ec17SMichael Reed 	vtarget->num_luns++;
56405e8ec17SMichael Reed 
5653bc7bf1dSMichael Reed 	dfcprintk ((MYIOC_s_INFO_FMT
5663bc7bf1dSMichael Reed 		"mptfc_slv_alloc.%d: num_luns %d, sdev.id %d, "
56705e8ec17SMichael Reed 	        "CurrentTargetID %d, %x %llx %llx\n",
5683bc7bf1dSMichael Reed 		ioc->name,
56905e8ec17SMichael Reed 		sdev->host->host_no,
57005e8ec17SMichael Reed 		vtarget->num_luns,
57105e8ec17SMichael Reed 		sdev->id, ri->pg0.CurrentTargetID,
5723bc7bf1dSMichael Reed 		ri->pg0.PortIdentifier, ri->pg0.WWPN, ri->pg0.WWNN));
57305e8ec17SMichael Reed 
57405e8ec17SMichael Reed 	return 0;
57505e8ec17SMichael Reed }
57605e8ec17SMichael Reed 
57705e8ec17SMichael Reed static int
57805e8ec17SMichael Reed mptfc_qcmd(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *))
57905e8ec17SMichael Reed {
5803bc7bf1dSMichael Reed 	struct mptfc_rport_info	*ri;
58105e8ec17SMichael Reed 	struct fc_rport	*rport = starget_to_rport(scsi_target(SCpnt->device));
58205e8ec17SMichael Reed 	int		err;
58305e8ec17SMichael Reed 
58405e8ec17SMichael Reed 	err = fc_remote_port_chkready(rport);
58505e8ec17SMichael Reed 	if (unlikely(err)) {
58605e8ec17SMichael Reed 		SCpnt->result = err;
58705e8ec17SMichael Reed 		done(SCpnt);
58805e8ec17SMichael Reed 		return 0;
58905e8ec17SMichael Reed 	}
5903bc7bf1dSMichael Reed 	ri = *((struct mptfc_rport_info **)rport->dd_data);
5913bc7bf1dSMichael Reed 	if (unlikely(ri->remap_needed))
5923bc7bf1dSMichael Reed 		return SCSI_MLQUEUE_HOST_BUSY;
5933bc7bf1dSMichael Reed 
59405e8ec17SMichael Reed 	return mptscsih_qcmd(SCpnt,done);
59505e8ec17SMichael Reed }
59605e8ec17SMichael Reed 
59705e8ec17SMichael Reed static void
59805e8ec17SMichael Reed mptfc_init_host_attr(MPT_ADAPTER *ioc,int portnum)
59905e8ec17SMichael Reed {
60005e8ec17SMichael Reed 	unsigned class = 0, cos = 0;
60105e8ec17SMichael Reed 
60205e8ec17SMichael Reed 	/* don't know what to do as only one scsi (fc) host was allocated */
60305e8ec17SMichael Reed 	if (portnum != 0)
60405e8ec17SMichael Reed 		return;
60505e8ec17SMichael Reed 
60605e8ec17SMichael Reed 	class = ioc->fc_port_page0[portnum].SupportedServiceClass;
60705e8ec17SMichael Reed 	if (class & MPI_FCPORTPAGE0_SUPPORT_CLASS_1)
60805e8ec17SMichael Reed 		cos |= FC_COS_CLASS1;
60905e8ec17SMichael Reed 	if (class & MPI_FCPORTPAGE0_SUPPORT_CLASS_2)
61005e8ec17SMichael Reed 		cos |= FC_COS_CLASS2;
61105e8ec17SMichael Reed 	if (class & MPI_FCPORTPAGE0_SUPPORT_CLASS_3)
61205e8ec17SMichael Reed 		cos |= FC_COS_CLASS3;
61305e8ec17SMichael Reed 
61405e8ec17SMichael Reed 	fc_host_node_name(ioc->sh) =
61505e8ec17SMichael Reed 	    	(u64)ioc->fc_port_page0[portnum].WWNN.High << 32
61605e8ec17SMichael Reed 		    | (u64)ioc->fc_port_page0[portnum].WWNN.Low;
61705e8ec17SMichael Reed 
61805e8ec17SMichael Reed 	fc_host_port_name(ioc->sh) =
61905e8ec17SMichael Reed 	    	(u64)ioc->fc_port_page0[portnum].WWPN.High << 32
62005e8ec17SMichael Reed 		    | (u64)ioc->fc_port_page0[portnum].WWPN.Low;
62105e8ec17SMichael Reed 
62205e8ec17SMichael Reed 	fc_host_port_id(ioc->sh) = ioc->fc_port_page0[portnum].PortIdentifier;
62305e8ec17SMichael Reed 
62405e8ec17SMichael Reed 	fc_host_supported_classes(ioc->sh) = cos;
62505e8ec17SMichael Reed 
62605e8ec17SMichael Reed 	fc_host_tgtid_bind_type(ioc->sh) = FC_TGTID_BIND_BY_WWPN;
62705e8ec17SMichael Reed }
62805e8ec17SMichael Reed 
62905e8ec17SMichael Reed static void
63005e8ec17SMichael Reed mptfc_rescan_devices(void *arg)
63105e8ec17SMichael Reed {
63205e8ec17SMichael Reed 	MPT_ADAPTER		*ioc = (MPT_ADAPTER *)arg;
63305e8ec17SMichael Reed 	int			ii;
63405e8ec17SMichael Reed 	int			work_to_do;
63505e8ec17SMichael Reed 	unsigned long		flags;
63605e8ec17SMichael Reed 	struct mptfc_rport_info *ri;
63705e8ec17SMichael Reed 
63805e8ec17SMichael Reed 	do {
63905e8ec17SMichael Reed 		/* start by tagging all ports as missing */
64005e8ec17SMichael Reed 		spin_lock_irqsave(&ioc->fc_rport_lock,flags);
64105e8ec17SMichael Reed 		list_for_each_entry(ri, &ioc->fc_rports, list) {
64205e8ec17SMichael Reed 			if (ri->flags & MPT_RPORT_INFO_FLAGS_REGISTERED) {
64305e8ec17SMichael Reed 				ri->flags |= MPT_RPORT_INFO_FLAGS_MISSING;
64405e8ec17SMichael Reed 			}
64505e8ec17SMichael Reed 		}
64605e8ec17SMichael Reed 		spin_unlock_irqrestore(&ioc->fc_rport_lock,flags);
64705e8ec17SMichael Reed 
64805e8ec17SMichael Reed 		/*
64905e8ec17SMichael Reed 		 * now rescan devices known to adapter,
65005e8ec17SMichael Reed 		 * will reregister existing rports
65105e8ec17SMichael Reed 		 */
65205e8ec17SMichael Reed 		for (ii=0; ii < ioc->facts.NumberOfPorts; ii++) {
65305e8ec17SMichael Reed 			(void) mptbase_GetFcPortPage0(ioc, ii);
65405e8ec17SMichael Reed 			mptfc_init_host_attr(ioc,ii);	/* refresh */
65505e8ec17SMichael Reed 			mptfc_GetFcDevPage0(ioc,ii,mptfc_register_dev);
65605e8ec17SMichael Reed 		}
65705e8ec17SMichael Reed 
65805e8ec17SMichael Reed 		/* delete devices still missing */
65905e8ec17SMichael Reed 		spin_lock_irqsave(&ioc->fc_rport_lock, flags);
66005e8ec17SMichael Reed 		list_for_each_entry(ri, &ioc->fc_rports, list) {
66105e8ec17SMichael Reed 			/* if newly missing, delete it */
66205e8ec17SMichael Reed 			if ((ri->flags & (MPT_RPORT_INFO_FLAGS_REGISTERED |
66305e8ec17SMichael Reed 					  MPT_RPORT_INFO_FLAGS_MISSING))
66405e8ec17SMichael Reed 			  == (MPT_RPORT_INFO_FLAGS_REGISTERED |
66505e8ec17SMichael Reed 			      MPT_RPORT_INFO_FLAGS_MISSING)) {
66605e8ec17SMichael Reed 
66705e8ec17SMichael Reed 				ri->flags &= ~(MPT_RPORT_INFO_FLAGS_REGISTERED|
66805e8ec17SMichael Reed 					       MPT_RPORT_INFO_FLAGS_MISSING);
6693bc7bf1dSMichael Reed 				ri->remap_needed = 1;
67005e8ec17SMichael Reed 				fc_remote_port_delete(ri->rport);
67105e8ec17SMichael Reed 				/*
67205e8ec17SMichael Reed 				 * remote port not really deleted 'cause
67305e8ec17SMichael Reed 				 * binding is by WWPN and driver only
6743bc7bf1dSMichael Reed 				 * registers FCP_TARGETs but cannot trust
6753bc7bf1dSMichael Reed 				 * data structures.
67605e8ec17SMichael Reed 				 */
6773bc7bf1dSMichael Reed 				ri->rport = NULL;
6783bc7bf1dSMichael Reed 				dfcprintk ((MYIOC_s_INFO_FMT
6793bc7bf1dSMichael Reed 					"mptfc_rescan.%d: %llx deleted\n",
6803bc7bf1dSMichael Reed 					ioc->name,
6813bc7bf1dSMichael Reed 					ioc->sh->host_no,
6823bc7bf1dSMichael Reed 					ri->pg0.WWPN));
68305e8ec17SMichael Reed 			}
68405e8ec17SMichael Reed 		}
68505e8ec17SMichael Reed 		spin_unlock_irqrestore(&ioc->fc_rport_lock,flags);
68605e8ec17SMichael Reed 
68705e8ec17SMichael Reed 		/*
68805e8ec17SMichael Reed 		 * allow multiple passes as target state
68905e8ec17SMichael Reed 		 * might have changed during scan
69005e8ec17SMichael Reed 		 */
69105e8ec17SMichael Reed 		spin_lock_irqsave(&ioc->fc_rescan_work_lock, flags);
69205e8ec17SMichael Reed 		if (ioc->fc_rescan_work_count > 2) 	/* only need one more */
69305e8ec17SMichael Reed 			ioc->fc_rescan_work_count = 2;
69405e8ec17SMichael Reed 		work_to_do = --ioc->fc_rescan_work_count;
69505e8ec17SMichael Reed 		spin_unlock_irqrestore(&ioc->fc_rescan_work_lock, flags);
69605e8ec17SMichael Reed 	} while (work_to_do);
69705e8ec17SMichael Reed }
69805e8ec17SMichael Reed 
6992496af39SMoore, Eric Dean  static int
7002496af39SMoore, Eric Dean  mptfc_probe(struct pci_dev *pdev, const struct pci_device_id *id)
7012496af39SMoore, Eric Dean  {
7022496af39SMoore, Eric Dean  	struct Scsi_Host	*sh;
7032496af39SMoore, Eric Dean  	MPT_SCSI_HOST		*hd;
7042496af39SMoore, Eric Dean  	MPT_ADAPTER 		*ioc;
7052496af39SMoore, Eric Dean  	unsigned long		 flags;
7061ca00bb7SChristoph Hellwig 	int			 ii;
7072496af39SMoore, Eric Dean  	int			 numSGE = 0;
7082496af39SMoore, Eric Dean  	int			 scale;
7092496af39SMoore, Eric Dean  	int			 ioc_cap;
7102496af39SMoore, Eric Dean  	int			error=0;
7112496af39SMoore, Eric Dean  	int			r;
7122496af39SMoore, Eric Dean  
7132496af39SMoore, Eric Dean  	if ((r = mpt_attach(pdev,id)) != 0)
7142496af39SMoore, Eric Dean  		return r;
7152496af39SMoore, Eric Dean  
7162496af39SMoore, Eric Dean  	ioc = pci_get_drvdata(pdev);
717d335cc38SMoore, Eric Dean  	ioc->DoneCtx = mptfcDoneCtx;
718d335cc38SMoore, Eric Dean  	ioc->TaskCtx = mptfcTaskCtx;
719d335cc38SMoore, Eric Dean  	ioc->InternalCtx = mptfcInternalCtx;
7202496af39SMoore, Eric Dean  
7212496af39SMoore, Eric Dean  	/*  Added sanity check on readiness of the MPT adapter.
7222496af39SMoore, Eric Dean  	 */
7232496af39SMoore, Eric Dean  	if (ioc->last_state != MPI_IOC_STATE_OPERATIONAL) {
7242496af39SMoore, Eric Dean  		printk(MYIOC_s_WARN_FMT
7252496af39SMoore, Eric Dean  		  "Skipping because it's not operational!\n",
7262496af39SMoore, Eric Dean  		  ioc->name);
7277acec1e7SMoore, Eric Dean 		error = -ENODEV;
7287acec1e7SMoore, Eric Dean 		goto out_mptfc_probe;
7292496af39SMoore, Eric Dean  	}
7302496af39SMoore, Eric Dean  
7312496af39SMoore, Eric Dean  	if (!ioc->active) {
7322496af39SMoore, Eric Dean  		printk(MYIOC_s_WARN_FMT "Skipping because it's disabled!\n",
7332496af39SMoore, Eric Dean  		  ioc->name);
7347acec1e7SMoore, Eric Dean 		error = -ENODEV;
7357acec1e7SMoore, Eric Dean 		goto out_mptfc_probe;
7362496af39SMoore, Eric Dean  	}
7372496af39SMoore, Eric Dean  
7382496af39SMoore, Eric Dean  	/*  Sanity check - ensure at least 1 port is INITIATOR capable
7392496af39SMoore, Eric Dean  	 */
7402496af39SMoore, Eric Dean  	ioc_cap = 0;
7412496af39SMoore, Eric Dean  	for (ii=0; ii < ioc->facts.NumberOfPorts; ii++) {
7422496af39SMoore, Eric Dean  		if (ioc->pfacts[ii].ProtocolFlags &
7432496af39SMoore, Eric Dean  		    MPI_PORTFACTS_PROTOCOL_INITIATOR)
7442496af39SMoore, Eric Dean  			ioc_cap ++;
7452496af39SMoore, Eric Dean  	}
7462496af39SMoore, Eric Dean  
7472496af39SMoore, Eric Dean  	if (!ioc_cap) {
7482496af39SMoore, Eric Dean  		printk(MYIOC_s_WARN_FMT
7492496af39SMoore, Eric Dean  			"Skipping ioc=%p because SCSI Initiator mode is NOT enabled!\n",
7502496af39SMoore, Eric Dean  			ioc->name, ioc);
75105e8ec17SMichael Reed 		return -ENODEV;
7522496af39SMoore, Eric Dean  	}
7532496af39SMoore, Eric Dean  
7542496af39SMoore, Eric Dean  	sh = scsi_host_alloc(&mptfc_driver_template, sizeof(MPT_SCSI_HOST));
7552496af39SMoore, Eric Dean  
7562496af39SMoore, Eric Dean  	if (!sh) {
7572496af39SMoore, Eric Dean  		printk(MYIOC_s_WARN_FMT
7582496af39SMoore, Eric Dean  			"Unable to register controller with SCSI subsystem\n",
7592496af39SMoore, Eric Dean  			ioc->name);
7607acec1e7SMoore, Eric Dean 		error = -1;
7617acec1e7SMoore, Eric Dean 		goto out_mptfc_probe;
7622496af39SMoore, Eric Dean          }
7632496af39SMoore, Eric Dean  
76405e8ec17SMichael Reed 	INIT_WORK(&ioc->fc_rescan_work, mptfc_rescan_devices,(void *)ioc);
76505e8ec17SMichael Reed 
7662496af39SMoore, Eric Dean  	spin_lock_irqsave(&ioc->FreeQlock, flags);
7672496af39SMoore, Eric Dean  
7682496af39SMoore, Eric Dean  	/* Attach the SCSI Host to the IOC structure
7692496af39SMoore, Eric Dean  	 */
7702496af39SMoore, Eric Dean  	ioc->sh = sh;
7712496af39SMoore, Eric Dean  
7722496af39SMoore, Eric Dean  	sh->io_port = 0;
7732496af39SMoore, Eric Dean  	sh->n_io_port = 0;
7742496af39SMoore, Eric Dean  	sh->irq = 0;
7752496af39SMoore, Eric Dean  
7762496af39SMoore, Eric Dean  	/* set 16 byte cdb's */
7772496af39SMoore, Eric Dean  	sh->max_cmd_len = 16;
7782496af39SMoore, Eric Dean  
7792496af39SMoore, Eric Dean  	sh->max_id = MPT_MAX_FC_DEVICES<256 ? MPT_MAX_FC_DEVICES : 255;
7802496af39SMoore, Eric Dean  
7812496af39SMoore, Eric Dean  	sh->max_lun = MPT_LAST_LUN + 1;
7822496af39SMoore, Eric Dean  	sh->max_channel = 0;
7832496af39SMoore, Eric Dean  	sh->this_id = ioc->pfacts[0].PortSCSIID;
7842496af39SMoore, Eric Dean  
7852496af39SMoore, Eric Dean  	/* Required entry.
7862496af39SMoore, Eric Dean  	 */
7872496af39SMoore, Eric Dean  	sh->unique_id = ioc->id;
7882496af39SMoore, Eric Dean  
7892496af39SMoore, Eric Dean  	/* Verify that we won't exceed the maximum
7902496af39SMoore, Eric Dean  	 * number of chain buffers
7912496af39SMoore, Eric Dean  	 * We can optimize:  ZZ = req_sz/sizeof(SGE)
7922496af39SMoore, Eric Dean  	 * For 32bit SGE's:
7932496af39SMoore, Eric Dean  	 *  numSGE = 1 + (ZZ-1)*(maxChain -1) + ZZ
7942496af39SMoore, Eric Dean  	 *               + (req_sz - 64)/sizeof(SGE)
7952496af39SMoore, Eric Dean  	 * A slightly different algorithm is required for
7962496af39SMoore, Eric Dean  	 * 64bit SGEs.
7972496af39SMoore, Eric Dean  	 */
7982496af39SMoore, Eric Dean  	scale = ioc->req_sz/(sizeof(dma_addr_t) + sizeof(u32));
7992496af39SMoore, Eric Dean  	if (sizeof(dma_addr_t) == sizeof(u64)) {
8002496af39SMoore, Eric Dean  		numSGE = (scale - 1) *
8012496af39SMoore, Eric Dean  		  (ioc->facts.MaxChainDepth-1) + scale +
8022496af39SMoore, Eric Dean  		  (ioc->req_sz - 60) / (sizeof(dma_addr_t) +
8032496af39SMoore, Eric Dean  		  sizeof(u32));
8042496af39SMoore, Eric Dean  	} else {
8052496af39SMoore, Eric Dean  		numSGE = 1 + (scale - 1) *
8062496af39SMoore, Eric Dean  		  (ioc->facts.MaxChainDepth-1) + scale +
8072496af39SMoore, Eric Dean  		  (ioc->req_sz - 64) / (sizeof(dma_addr_t) +
8082496af39SMoore, Eric Dean  		  sizeof(u32));
8092496af39SMoore, Eric Dean  	}
8102496af39SMoore, Eric Dean  
8112496af39SMoore, Eric Dean  	if (numSGE < sh->sg_tablesize) {
8122496af39SMoore, Eric Dean  		/* Reset this value */
8132496af39SMoore, Eric Dean  		dprintk((MYIOC_s_INFO_FMT
8142496af39SMoore, Eric Dean  		  "Resetting sg_tablesize to %d from %d\n",
8152496af39SMoore, Eric Dean  		  ioc->name, numSGE, sh->sg_tablesize));
8162496af39SMoore, Eric Dean  		sh->sg_tablesize = numSGE;
8172496af39SMoore, Eric Dean  	}
8182496af39SMoore, Eric Dean  
8192496af39SMoore, Eric Dean  	spin_unlock_irqrestore(&ioc->FreeQlock, flags);
8202496af39SMoore, Eric Dean  
8212496af39SMoore, Eric Dean  	hd = (MPT_SCSI_HOST *) sh->hostdata;
8222496af39SMoore, Eric Dean  	hd->ioc = ioc;
8232496af39SMoore, Eric Dean  
8242496af39SMoore, Eric Dean  	/* SCSI needs scsi_cmnd lookup table!
8252496af39SMoore, Eric Dean  	 * (with size equal to req_depth*PtrSz!)
8262496af39SMoore, Eric Dean  	 */
8271ca00bb7SChristoph Hellwig 	hd->ScsiLookup = kcalloc(ioc->req_depth, sizeof(void *), GFP_ATOMIC);
8281ca00bb7SChristoph Hellwig 	if (!hd->ScsiLookup) {
8292496af39SMoore, Eric Dean  		error = -ENOMEM;
8307acec1e7SMoore, Eric Dean 		goto out_mptfc_probe;
8312496af39SMoore, Eric Dean  	}
8322496af39SMoore, Eric Dean  
8331ca00bb7SChristoph Hellwig 	dprintk((MYIOC_s_INFO_FMT "ScsiLookup @ %p\n",
8341ca00bb7SChristoph Hellwig 		 ioc->name, hd->ScsiLookup));
8352496af39SMoore, Eric Dean  
8362496af39SMoore, Eric Dean  	/* Allocate memory for the device structures.
8372496af39SMoore, Eric Dean  	 * A non-Null pointer at an offset
8382496af39SMoore, Eric Dean  	 * indicates a device exists.
8392496af39SMoore, Eric Dean  	 * max_id = 1 + maximum id (hosts.h)
8402496af39SMoore, Eric Dean  	 */
8411ca00bb7SChristoph Hellwig 	hd->Targets = kcalloc(sh->max_id, sizeof(void *), GFP_ATOMIC);
8421ca00bb7SChristoph Hellwig 	if (!hd->Targets) {
8432496af39SMoore, Eric Dean  		error = -ENOMEM;
8447acec1e7SMoore, Eric Dean 		goto out_mptfc_probe;
8452496af39SMoore, Eric Dean  	}
8462496af39SMoore, Eric Dean  
8471ca00bb7SChristoph Hellwig 	dprintk((KERN_INFO "  vdev @ %p\n", hd->Targets));
8482496af39SMoore, Eric Dean  
8492496af39SMoore, Eric Dean  	/* Clear the TM flags
8502496af39SMoore, Eric Dean  	 */
8512496af39SMoore, Eric Dean  	hd->tmPending = 0;
8522496af39SMoore, Eric Dean  	hd->tmState = TM_STATE_NONE;
8532496af39SMoore, Eric Dean  	hd->resetPending = 0;
8542496af39SMoore, Eric Dean  	hd->abortSCpnt = NULL;
8552496af39SMoore, Eric Dean  
8562496af39SMoore, Eric Dean  	/* Clear the pointer used to store
8572496af39SMoore, Eric Dean  	 * single-threaded commands, i.e., those
8582496af39SMoore, Eric Dean  	 * issued during a bus scan, dv and
8592496af39SMoore, Eric Dean  	 * configuration pages.
8602496af39SMoore, Eric Dean  	 */
8612496af39SMoore, Eric Dean  	hd->cmdPtr = NULL;
8622496af39SMoore, Eric Dean  
8632496af39SMoore, Eric Dean  	/* Initialize this SCSI Hosts' timers
8642496af39SMoore, Eric Dean  	 * To use, set the timer expires field
8652496af39SMoore, Eric Dean  	 * and add_timer
8662496af39SMoore, Eric Dean  	 */
8672496af39SMoore, Eric Dean  	init_timer(&hd->timer);
8682496af39SMoore, Eric Dean  	hd->timer.data = (unsigned long) hd;
8692496af39SMoore, Eric Dean  	hd->timer.function = mptscsih_timer_expired;
8702496af39SMoore, Eric Dean  
8712496af39SMoore, Eric Dean  	hd->mpt_pq_filter = mpt_pq_filter;
8722496af39SMoore, Eric Dean  
8732496af39SMoore, Eric Dean  	ddvprintk((MYIOC_s_INFO_FMT
8742496af39SMoore, Eric Dean  		"mpt_pq_filter %x\n",
8752496af39SMoore, Eric Dean  		ioc->name,
8762496af39SMoore, Eric Dean  		mpt_pq_filter));
8772496af39SMoore, Eric Dean  
8782496af39SMoore, Eric Dean  	init_waitqueue_head(&hd->scandv_waitq);
8792496af39SMoore, Eric Dean  	hd->scandv_wait_done = 0;
8802496af39SMoore, Eric Dean  	hd->last_queue_full = 0;
8812496af39SMoore, Eric Dean  
88205e8ec17SMichael Reed 	sh->transportt = mptfc_transport_template;
8832496af39SMoore, Eric Dean  	error = scsi_add_host (sh, &ioc->pcidev->dev);
8842496af39SMoore, Eric Dean  	if(error) {
8852496af39SMoore, Eric Dean  		dprintk((KERN_ERR MYNAM
8862496af39SMoore, Eric Dean  		  "scsi_add_host failed\n"));
8877acec1e7SMoore, Eric Dean 		goto out_mptfc_probe;
8882496af39SMoore, Eric Dean  	}
8892496af39SMoore, Eric Dean  
89005e8ec17SMichael Reed 	for (ii=0; ii < ioc->facts.NumberOfPorts; ii++) {
89105e8ec17SMichael Reed 		mptfc_init_host_attr(ioc,ii);
89205e8ec17SMichael Reed 		mptfc_GetFcDevPage0(ioc,ii,mptfc_register_dev);
89305e8ec17SMichael Reed 	}
89405e8ec17SMichael Reed 
8952496af39SMoore, Eric Dean  	return 0;
8962496af39SMoore, Eric Dean  
8977acec1e7SMoore, Eric Dean out_mptfc_probe:
8982496af39SMoore, Eric Dean  
8992496af39SMoore, Eric Dean  	mptscsih_remove(pdev);
9002496af39SMoore, Eric Dean  	return error;
9012496af39SMoore, Eric Dean  }
9022496af39SMoore, Eric Dean  
9032496af39SMoore, Eric Dean  static struct pci_driver mptfc_driver = {
9042496af39SMoore, Eric Dean  	.name		= "mptfc",
9052496af39SMoore, Eric Dean  	.id_table	= mptfc_pci_table,
9062496af39SMoore, Eric Dean  	.probe		= mptfc_probe,
90705e8ec17SMichael Reed 	.remove		= __devexit_p(mptfc_remove),
9082496af39SMoore, Eric Dean  	.shutdown	= mptscsih_shutdown,
9092496af39SMoore, Eric Dean  #ifdef CONFIG_PM
9102496af39SMoore, Eric Dean  	.suspend	= mptscsih_suspend,
9112496af39SMoore, Eric Dean  	.resume		= mptscsih_resume,
9122496af39SMoore, Eric Dean  #endif
9132496af39SMoore, Eric Dean  };
9142496af39SMoore, Eric Dean  
9152496af39SMoore, Eric Dean  /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
9162496af39SMoore, Eric Dean  /**
9172496af39SMoore, Eric Dean   *	mptfc_init - Register MPT adapter(s) as SCSI host(s) with
9182496af39SMoore, Eric Dean   *	linux scsi mid-layer.
9192496af39SMoore, Eric Dean   *
9202496af39SMoore, Eric Dean   *	Returns 0 for success, non-zero for failure.
9212496af39SMoore, Eric Dean   */
9222496af39SMoore, Eric Dean  static int __init
9232496af39SMoore, Eric Dean  mptfc_init(void)
9242496af39SMoore, Eric Dean  {
92505e8ec17SMichael Reed 	int error;
9262496af39SMoore, Eric Dean  
9272496af39SMoore, Eric Dean  	show_mptmod_ver(my_NAME, my_VERSION);
9282496af39SMoore, Eric Dean  
92905e8ec17SMichael Reed 	/* sanity check module parameter */
93005e8ec17SMichael Reed 	if (mptfc_dev_loss_tmo == 0)
93105e8ec17SMichael Reed 		mptfc_dev_loss_tmo = MPTFC_DEV_LOSS_TMO;
93205e8ec17SMichael Reed 
93305e8ec17SMichael Reed 	mptfc_transport_template =
93405e8ec17SMichael Reed 		fc_attach_transport(&mptfc_transport_functions);
93505e8ec17SMichael Reed 
93605e8ec17SMichael Reed 	if (!mptfc_transport_template)
93705e8ec17SMichael Reed 		return -ENODEV;
93805e8ec17SMichael Reed 
9392496af39SMoore, Eric Dean  	mptfcDoneCtx = mpt_register(mptscsih_io_done, MPTFC_DRIVER);
9402496af39SMoore, Eric Dean  	mptfcTaskCtx = mpt_register(mptscsih_taskmgmt_complete, MPTFC_DRIVER);
9412496af39SMoore, Eric Dean  	mptfcInternalCtx = mpt_register(mptscsih_scandv_complete, MPTFC_DRIVER);
9422496af39SMoore, Eric Dean  
9432496af39SMoore, Eric Dean  	if (mpt_event_register(mptfcDoneCtx, mptscsih_event_process) == 0) {
944*3a892befSMoore, Eric 		devtverboseprintk((KERN_INFO MYNAM
9452496af39SMoore, Eric Dean  		  ": Registered for IOC event notifications\n"));
9462496af39SMoore, Eric Dean  	}
9472496af39SMoore, Eric Dean  
9482496af39SMoore, Eric Dean  	if (mpt_reset_register(mptfcDoneCtx, mptscsih_ioc_reset) == 0) {
9492496af39SMoore, Eric Dean  		dprintk((KERN_INFO MYNAM
9502496af39SMoore, Eric Dean  		  ": Registered for IOC reset notifications\n"));
9512496af39SMoore, Eric Dean  	}
9522496af39SMoore, Eric Dean  
95305e8ec17SMichael Reed 	error = pci_register_driver(&mptfc_driver);
9543bc7bf1dSMichael Reed 	if (error)
95505e8ec17SMichael Reed 		fc_release_transport(mptfc_transport_template);
95605e8ec17SMichael Reed 
95705e8ec17SMichael Reed 	return error;
95805e8ec17SMichael Reed }
95905e8ec17SMichael Reed 
96005e8ec17SMichael Reed /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
96105e8ec17SMichael Reed /**
96205e8ec17SMichael Reed  *	mptfc_remove - Removed fc infrastructure for devices
96305e8ec17SMichael Reed  *	@pdev: Pointer to pci_dev structure
96405e8ec17SMichael Reed  *
96505e8ec17SMichael Reed  */
9663bc7bf1dSMichael Reed static void __devexit
9673bc7bf1dSMichael Reed mptfc_remove(struct pci_dev *pdev)
96805e8ec17SMichael Reed {
96905e8ec17SMichael Reed 	MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
97005e8ec17SMichael Reed 	struct mptfc_rport_info *p, *n;
97105e8ec17SMichael Reed 
97205e8ec17SMichael Reed 	fc_remove_host(ioc->sh);
97305e8ec17SMichael Reed 
97405e8ec17SMichael Reed 	list_for_each_entry_safe(p, n, &ioc->fc_rports, list) {
97505e8ec17SMichael Reed 		list_del(&p->list);
97605e8ec17SMichael Reed 		kfree(p);
97705e8ec17SMichael Reed 	}
97805e8ec17SMichael Reed 
97905e8ec17SMichael Reed 	mptscsih_remove(pdev);
9802496af39SMoore, Eric Dean  }
9812496af39SMoore, Eric Dean  
9822496af39SMoore, Eric Dean  /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
9832496af39SMoore, Eric Dean  /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
9842496af39SMoore, Eric Dean  /**
9852496af39SMoore, Eric Dean   *	mptfc_exit - Unregisters MPT adapter(s)
9862496af39SMoore, Eric Dean   *
9872496af39SMoore, Eric Dean   */
9882496af39SMoore, Eric Dean  static void __exit
9892496af39SMoore, Eric Dean  mptfc_exit(void)
9902496af39SMoore, Eric Dean  {
9912496af39SMoore, Eric Dean  	pci_unregister_driver(&mptfc_driver);
99205e8ec17SMichael Reed 	fc_release_transport(mptfc_transport_template);
9932496af39SMoore, Eric Dean  
9942496af39SMoore, Eric Dean  	mpt_reset_deregister(mptfcDoneCtx);
9952496af39SMoore, Eric Dean  	dprintk((KERN_INFO MYNAM
9962496af39SMoore, Eric Dean  	  ": Deregistered for IOC reset notifications\n"));
9972496af39SMoore, Eric Dean  
9982496af39SMoore, Eric Dean  	mpt_event_deregister(mptfcDoneCtx);
9992496af39SMoore, Eric Dean  	dprintk((KERN_INFO MYNAM
10002496af39SMoore, Eric Dean  	  ": Deregistered for IOC event notifications\n"));
10012496af39SMoore, Eric Dean  
10022496af39SMoore, Eric Dean  	mpt_deregister(mptfcInternalCtx);
10032496af39SMoore, Eric Dean  	mpt_deregister(mptfcTaskCtx);
10042496af39SMoore, Eric Dean  	mpt_deregister(mptfcDoneCtx);
10052496af39SMoore, Eric Dean  }
10062496af39SMoore, Eric Dean  
10072496af39SMoore, Eric Dean  module_init(mptfc_init);
10082496af39SMoore, Eric Dean  module_exit(mptfc_exit);
1009