xref: /linux/drivers/message/fusion/mptfc.c (revision 3a39d672e7f48b8d6b91a09afa4b55352773b4b5)
12496af39SMoore, Eric Dean  /*
22496af39SMoore, Eric Dean   *  linux/drivers/message/fusion/mptfc.c
3f36789e2SPrakash, Sathya  *      For use with LSI PCI chip/adapter(s)
4f36789e2SPrakash, Sathya  *      running LSI Fusion MPT (Message Passing Technology) firmware.
52496af39SMoore, Eric Dean   *
6cddc0ab7SPrakash, Sathya  *  Copyright (c) 1999-2008 LSI Corporation
716d20101SEric Moore  *  (mailto:DL-MPTFusionLinux@lsi.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/module.h>
472496af39SMoore, Eric Dean  #include <linux/kernel.h>
482496af39SMoore, Eric Dean  #include <linux/init.h>
492496af39SMoore, Eric Dean  #include <linux/errno.h>
502496af39SMoore, Eric Dean  #include <linux/kdev_t.h>
512496af39SMoore, Eric Dean  #include <linux/blkdev.h>
522496af39SMoore, Eric Dean  #include <linux/delay.h>	/* for mdelay */
53b8a51443SThomas Gleixner #include <linux/interrupt.h>
542496af39SMoore, Eric Dean  #include <linux/reboot.h>	/* notifier code */
552496af39SMoore, Eric Dean  #include <linux/workqueue.h>
5605e8ec17SMichael Reed #include <linux/sort.h>
575a0e3ad6STejun Heo #include <linux/slab.h>
582496af39SMoore, Eric Dean  
592496af39SMoore, Eric Dean  #include <scsi/scsi.h>
602496af39SMoore, Eric Dean  #include <scsi/scsi_cmnd.h>
612496af39SMoore, Eric Dean  #include <scsi/scsi_device.h>
622496af39SMoore, Eric Dean  #include <scsi/scsi_host.h>
632496af39SMoore, Eric Dean  #include <scsi/scsi_tcq.h>
6405e8ec17SMichael Reed #include <scsi/scsi_transport_fc.h>
652496af39SMoore, Eric Dean  
662496af39SMoore, Eric Dean  #include "mptbase.h"
672496af39SMoore, Eric Dean  #include "mptscsih.h"
682496af39SMoore, Eric Dean  
692496af39SMoore, Eric Dean  /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
702496af39SMoore, Eric Dean  #define my_NAME		"Fusion MPT FC Host driver"
712496af39SMoore, Eric Dean  #define my_VERSION	MPT_LINUX_VERSION_COMMON
722496af39SMoore, Eric Dean  #define MYNAM		"mptfc"
732496af39SMoore, Eric Dean  
742496af39SMoore, Eric Dean  MODULE_AUTHOR(MODULEAUTHOR);
752496af39SMoore, Eric Dean  MODULE_DESCRIPTION(my_NAME);
762496af39SMoore, Eric Dean  MODULE_LICENSE("GPL");
779f4203b3SEric Moore MODULE_VERSION(my_VERSION);
782496af39SMoore, Eric Dean  
792496af39SMoore, Eric Dean  /* Command line args */
8005e8ec17SMichael Reed #define MPTFC_DEV_LOSS_TMO (60)
8105e8ec17SMichael Reed static int mptfc_dev_loss_tmo = MPTFC_DEV_LOSS_TMO;	/* reasonable default */
8205e8ec17SMichael Reed module_param(mptfc_dev_loss_tmo, int, 0);
8305e8ec17SMichael Reed MODULE_PARM_DESC(mptfc_dev_loss_tmo, " Initial time the driver programs the "
8405e8ec17SMichael Reed     				     " transport to wait for an rport to "
8505e8ec17SMichael Reed 				     " return following a device loss event."
8605e8ec17SMichael Reed 				     "  Default=60.");
8705e8ec17SMichael Reed 
88793955f5SEric Moore /* scsi-mid layer global parmeter is max_report_luns, which is 511 */
89793955f5SEric Moore #define MPTFC_MAX_LUN (16895)
90793955f5SEric Moore static int max_lun = MPTFC_MAX_LUN;
91793955f5SEric Moore module_param(max_lun, int, 0);
92793955f5SEric Moore MODULE_PARM_DESC(max_lun, " max lun, default=16895 ");
93793955f5SEric Moore 
94f606f571SPrakash, Sathya static u8	mptfcDoneCtx = MPT_MAX_PROTOCOL_DRIVERS;
95f606f571SPrakash, Sathya static u8	mptfcTaskCtx = MPT_MAX_PROTOCOL_DRIVERS;
96f606f571SPrakash, Sathya static u8	mptfcInternalCtx = MPT_MAX_PROTOCOL_DRIVERS;
972496af39SMoore, Eric Dean  
983bc7bf1dSMichael Reed static int mptfc_target_alloc(struct scsi_target *starget);
993bc7bf1dSMichael Reed static int mptfc_slave_alloc(struct scsi_device *sdev);
100f281233dSJeff Garzik static int mptfc_qcmd(struct Scsi_Host *shost, struct scsi_cmnd *SCpnt);
1013bc7bf1dSMichael Reed static void mptfc_target_destroy(struct scsi_target *starget);
10205e8ec17SMichael Reed static void mptfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout);
10347b1ea75SGreg Kroah-Hartman static void mptfc_remove(struct pci_dev *pdev);
10435508e46SMichael Reed static int mptfc_abort(struct scsi_cmnd *SCpnt);
10535508e46SMichael Reed static int mptfc_dev_reset(struct scsi_cmnd *SCpnt);
10635508e46SMichael Reed static int mptfc_bus_reset(struct scsi_cmnd *SCpnt);
10705e8ec17SMichael Reed 
10895a24cf1SBart Van Assche static const struct scsi_host_template mptfc_driver_template = {
109f78496daSMoore, Eric Dean 	.module				= THIS_MODULE,
1102496af39SMoore, Eric Dean  	.proc_name			= "mptfc",
111cac19703SAl Viro 	.show_info			= mptscsih_show_info,
1122496af39SMoore, Eric Dean  	.name				= "MPT FC Host",
1132496af39SMoore, Eric Dean  	.info				= mptscsih_info,
11405e8ec17SMichael Reed 	.queuecommand			= mptfc_qcmd,
1153bc7bf1dSMichael Reed 	.target_alloc			= mptfc_target_alloc,
11605e8ec17SMichael Reed 	.slave_alloc			= mptfc_slave_alloc,
1172496af39SMoore, Eric Dean  	.slave_configure		= mptscsih_slave_configure,
1183bc7bf1dSMichael Reed 	.target_destroy			= mptfc_target_destroy,
1192496af39SMoore, Eric Dean  	.slave_destroy			= mptscsih_slave_destroy,
1206e3815baSMoore, Eric Dean 	.change_queue_depth 		= mptscsih_change_queue_depth,
121b6a05c82SChristoph Hellwig 	.eh_timed_out			= fc_eh_timed_out,
12235508e46SMichael Reed 	.eh_abort_handler		= mptfc_abort,
12335508e46SMichael Reed 	.eh_device_reset_handler	= mptfc_dev_reset,
12435508e46SMichael Reed 	.eh_bus_reset_handler		= mptfc_bus_reset,
125fdad4aafSHannes Reinecke 	.eh_host_reset_handler		= mptscsih_host_reset,
1262496af39SMoore, Eric Dean  	.bios_param			= mptscsih_bios_param,
1272496af39SMoore, Eric Dean  	.can_queue			= MPT_FC_CAN_QUEUE,
1282496af39SMoore, Eric Dean  	.this_id			= -1,
1292496af39SMoore, Eric Dean  	.sg_tablesize			= MPT_SCSI_SG_DEPTH,
1302496af39SMoore, Eric Dean  	.max_sectors			= 8192,
1312496af39SMoore, Eric Dean  	.cmd_per_lun			= 7,
1325b7dfbefSChristoph Hellwig 	.dma_alignment			= 511,
1332899836fSBart Van Assche 	.shost_groups			= mptscsih_host_attr_groups,
1342496af39SMoore, Eric Dean  };
1352496af39SMoore, Eric Dean  
1362496af39SMoore, Eric Dean  /****************************************************************************
1372496af39SMoore, Eric Dean   * Supported hardware
1382496af39SMoore, Eric Dean   */
1392496af39SMoore, Eric Dean  
1402496af39SMoore, Eric Dean  static struct pci_device_id mptfc_pci_table[] = {
14187cf8986SEric Moore 	{ PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVICEID_FC909,
1422496af39SMoore, Eric Dean  		PCI_ANY_ID, PCI_ANY_ID },
14387cf8986SEric Moore 	{ PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVICEID_FC919,
1442496af39SMoore, Eric Dean  		PCI_ANY_ID, PCI_ANY_ID },
14587cf8986SEric Moore 	{ PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVICEID_FC929,
1462496af39SMoore, Eric Dean  		PCI_ANY_ID, PCI_ANY_ID },
14787cf8986SEric Moore 	{ PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVICEID_FC919X,
1482496af39SMoore, Eric Dean  		PCI_ANY_ID, PCI_ANY_ID },
14987cf8986SEric Moore 	{ PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVICEID_FC929X,
1502496af39SMoore, Eric Dean  		PCI_ANY_ID, PCI_ANY_ID },
15187cf8986SEric Moore 	{ PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVICEID_FC939X,
1523fadc59dSMoore, Eric Dean  		PCI_ANY_ID, PCI_ANY_ID },
15387cf8986SEric Moore 	{ PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVICEID_FC949X,
1543fadc59dSMoore, Eric Dean  		PCI_ANY_ID, PCI_ANY_ID },
15587cf8986SEric Moore 	{ PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVICEID_FC949E,
1566d5b0c31SMoore, Eric 		PCI_ANY_ID, PCI_ANY_ID },
157ef1d8df7SPrakash, Sathya 	{ PCI_VENDOR_ID_BROCADE, MPI_MANUFACTPAGE_DEVICEID_FC949E,
158ef1d8df7SPrakash, Sathya 		PCI_ANY_ID, PCI_ANY_ID },
1592496af39SMoore, Eric Dean  	{0}	/* Terminating entry */
1602496af39SMoore, Eric Dean  };
1612496af39SMoore, Eric Dean  MODULE_DEVICE_TABLE(pci, mptfc_pci_table);
1622496af39SMoore, Eric Dean  
16305e8ec17SMichael Reed static struct scsi_transport_template *mptfc_transport_template = NULL;
16405e8ec17SMichael Reed 
16503fbcbcdSAdrian Bunk static struct fc_function_template mptfc_transport_functions = {
16605e8ec17SMichael Reed 	.dd_fcrport_size = 8,
16705e8ec17SMichael Reed 	.show_host_node_name = 1,
16805e8ec17SMichael Reed 	.show_host_port_name = 1,
16905e8ec17SMichael Reed 	.show_host_supported_classes = 1,
17005e8ec17SMichael Reed 	.show_host_port_id = 1,
17105e8ec17SMichael Reed 	.show_rport_supported_classes = 1,
17205e8ec17SMichael Reed 	.show_starget_node_name = 1,
17305e8ec17SMichael Reed 	.show_starget_port_name = 1,
17405e8ec17SMichael Reed 	.show_starget_port_id = 1,
17505e8ec17SMichael Reed 	.set_rport_dev_loss_tmo = mptfc_set_rport_loss_tmo,
17605e8ec17SMichael Reed 	.show_rport_dev_loss_tmo = 1,
1775d947f2bSMichael Reed 	.show_host_supported_speeds = 1,
1785d947f2bSMichael Reed 	.show_host_maxframe_size = 1,
1795d947f2bSMichael Reed 	.show_host_speed = 1,
1805d947f2bSMichael Reed 	.show_host_fabric_name = 1,
1815d947f2bSMichael Reed 	.show_host_port_type = 1,
1825d947f2bSMichael Reed 	.show_host_port_state = 1,
1835d947f2bSMichael Reed 	.show_host_symbolic_name = 1,
18405e8ec17SMichael Reed };
18505e8ec17SMichael Reed 
18635508e46SMichael Reed static int
mptfc_block_error_handler(struct fc_rport * rport)187d9987d4bSHannes Reinecke mptfc_block_error_handler(struct fc_rport *rport)
18835508e46SMichael Reed {
189d6ecdd63SPrakash, Sathya 	MPT_SCSI_HOST		*hd;
190d9987d4bSHannes Reinecke 	struct Scsi_Host	*shost = rport_to_shost(rport);
19135508e46SMichael Reed 	unsigned long		flags;
19235508e46SMichael Reed 	int			ready;
193e80b002bSEric Moore 	MPT_ADAPTER		*ioc;
19403cb3829SMichael Reed 	int			loops = 40;	/* seconds */
19535508e46SMichael Reed 
196d9987d4bSHannes Reinecke 	hd = shost_priv(shost);
197e80b002bSEric Moore 	ioc = hd->ioc;
19835508e46SMichael Reed 	spin_lock_irqsave(shost->host_lock, flags);
19903cb3829SMichael Reed 	while ((ready = fc_remote_port_chkready(rport) >> 16) == DID_IMM_RETRY
20003cb3829SMichael Reed 	 || (loops > 0 && ioc->active == 0)) {
20135508e46SMichael Reed 		spin_unlock_irqrestore(shost->host_lock, flags);
202e80b002bSEric Moore 		dfcprintk (ioc, printk(MYIOC_s_DEBUG_FMT
203d9987d4bSHannes Reinecke 			"mptfc_block_error_handler.%d: %s, port status is "
204d9987d4bSHannes Reinecke 			"%x, active flag %d, deferring recovery.\n",
205e7eae9f6SEric Moore 			ioc->name, ioc->sh->host_no,
206d9987d4bSHannes Reinecke 			dev_name(&rport->dev), ready, ioc->active));
20735508e46SMichael Reed 		msleep(1000);
20835508e46SMichael Reed 		spin_lock_irqsave(shost->host_lock, flags);
20903cb3829SMichael Reed 		loops --;
21035508e46SMichael Reed 	}
21135508e46SMichael Reed 	spin_unlock_irqrestore(shost->host_lock, flags);
21235508e46SMichael Reed 
213d9987d4bSHannes Reinecke 	if (ready == DID_NO_CONNECT || ioc->active == 0) {
214e80b002bSEric Moore 		dfcprintk (ioc, printk(MYIOC_s_DEBUG_FMT
215d9987d4bSHannes Reinecke 			"mpt_block_error_handler.%d: %s, failing recovery, "
216d9987d4bSHannes Reinecke 			"port state %x, active %d.\n",
217e7eae9f6SEric Moore 			ioc->name, ioc->sh->host_no,
218d9987d4bSHannes Reinecke 			dev_name(&rport->dev), ready, ioc->active));
21935508e46SMichael Reed 		return FAILED;
22035508e46SMichael Reed 	}
221d9987d4bSHannes Reinecke 	return SUCCESS;
22235508e46SMichael Reed }
22335508e46SMichael Reed 
22435508e46SMichael Reed static int
mptfc_abort(struct scsi_cmnd * SCpnt)22535508e46SMichael Reed mptfc_abort(struct scsi_cmnd *SCpnt)
22635508e46SMichael Reed {
227d9987d4bSHannes Reinecke 	struct Scsi_Host *shost = SCpnt->device->host;
228d9987d4bSHannes Reinecke 	struct fc_rport *rport = starget_to_rport(scsi_target(SCpnt->device));
229d9987d4bSHannes Reinecke 	MPT_SCSI_HOST __maybe_unused *hd = shost_priv(shost);
230d9987d4bSHannes Reinecke 	int rtn;
231d9987d4bSHannes Reinecke 
232d9987d4bSHannes Reinecke 	rtn = mptfc_block_error_handler(rport);
233d9987d4bSHannes Reinecke 	if (rtn == SUCCESS) {
234d9987d4bSHannes Reinecke 		dfcprintk (hd->ioc, printk(MYIOC_s_DEBUG_FMT
235d9987d4bSHannes Reinecke 			"%s.%d: %d:%llu, executing recovery.\n", __func__,
236d9987d4bSHannes Reinecke 			hd->ioc->name, shost->host_no,
237d9987d4bSHannes Reinecke 			SCpnt->device->id, SCpnt->device->lun));
238d9987d4bSHannes Reinecke 		rtn = mptscsih_abort(SCpnt);
239d9987d4bSHannes Reinecke 	}
240d9987d4bSHannes Reinecke 	return rtn;
24135508e46SMichael Reed }
24235508e46SMichael Reed 
24335508e46SMichael Reed static int
mptfc_dev_reset(struct scsi_cmnd * SCpnt)24435508e46SMichael Reed mptfc_dev_reset(struct scsi_cmnd *SCpnt)
24535508e46SMichael Reed {
246d9987d4bSHannes Reinecke 	struct Scsi_Host *shost = SCpnt->device->host;
247d9987d4bSHannes Reinecke 	struct fc_rport *rport = starget_to_rport(scsi_target(SCpnt->device));
248d9987d4bSHannes Reinecke 	MPT_SCSI_HOST __maybe_unused *hd = shost_priv(shost);
249d9987d4bSHannes Reinecke 	int rtn;
250d9987d4bSHannes Reinecke 
251d9987d4bSHannes Reinecke 	rtn = mptfc_block_error_handler(rport);
252d9987d4bSHannes Reinecke 	if (rtn == SUCCESS) {
253d9987d4bSHannes Reinecke 		dfcprintk (hd->ioc, printk(MYIOC_s_DEBUG_FMT
254d9987d4bSHannes Reinecke 			"%s.%d: %d:%llu, executing recovery.\n", __func__,
255d9987d4bSHannes Reinecke 			hd->ioc->name, shost->host_no,
256d9987d4bSHannes Reinecke 			SCpnt->device->id, SCpnt->device->lun));
257d9987d4bSHannes Reinecke 		rtn = mptscsih_dev_reset(SCpnt);
258d9987d4bSHannes Reinecke 	}
259d9987d4bSHannes Reinecke 	return rtn;
26035508e46SMichael Reed }
26135508e46SMichael Reed 
26235508e46SMichael Reed static int
mptfc_bus_reset(struct scsi_cmnd * SCpnt)26335508e46SMichael Reed mptfc_bus_reset(struct scsi_cmnd *SCpnt)
26435508e46SMichael Reed {
265d9987d4bSHannes Reinecke 	struct Scsi_Host *shost = SCpnt->device->host;
266d9987d4bSHannes Reinecke 	MPT_SCSI_HOST __maybe_unused *hd = shost_priv(shost);
26717865dc2SHannes Reinecke 	int channel = SCpnt->device->channel;
26817865dc2SHannes Reinecke 	struct mptfc_rport_info *ri;
2694b1c0791SHannes Reinecke 	int rtn = FAILED;
270d9987d4bSHannes Reinecke 
27117865dc2SHannes Reinecke 	list_for_each_entry(ri, &hd->ioc->fc_rports, list) {
27217865dc2SHannes Reinecke 		if (ri->flags & MPT_RPORT_INFO_FLAGS_REGISTERED) {
27317865dc2SHannes Reinecke 			VirtTarget *vtarget = ri->starget->hostdata;
27417865dc2SHannes Reinecke 
27517865dc2SHannes Reinecke 			if (!vtarget || vtarget->channel != channel)
27617865dc2SHannes Reinecke 				continue;
27717865dc2SHannes Reinecke 			rtn = fc_block_rport(ri->rport);
27817865dc2SHannes Reinecke 			if (rtn != 0)
27917865dc2SHannes Reinecke 				break;
28017865dc2SHannes Reinecke 		}
28117865dc2SHannes Reinecke 	}
28217865dc2SHannes Reinecke 	if (rtn == 0) {
283d9987d4bSHannes Reinecke 		dfcprintk (hd->ioc, printk(MYIOC_s_DEBUG_FMT
284d9987d4bSHannes Reinecke 			"%s.%d: %d:%llu, executing recovery.\n", __func__,
285d9987d4bSHannes Reinecke 			hd->ioc->name, shost->host_no,
286d9987d4bSHannes Reinecke 			SCpnt->device->id, SCpnt->device->lun));
287d9987d4bSHannes Reinecke 		rtn = mptscsih_bus_reset(SCpnt);
288d9987d4bSHannes Reinecke 	}
289d9987d4bSHannes Reinecke 	return rtn;
29035508e46SMichael Reed }
29135508e46SMichael Reed 
29205e8ec17SMichael Reed static void
mptfc_set_rport_loss_tmo(struct fc_rport * rport,uint32_t timeout)29305e8ec17SMichael Reed mptfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
29405e8ec17SMichael Reed {
29505e8ec17SMichael Reed 	if (timeout > 0)
29605e8ec17SMichael Reed 		rport->dev_loss_tmo = timeout;
29705e8ec17SMichael Reed 	else
29805e8ec17SMichael Reed 		rport->dev_loss_tmo = mptfc_dev_loss_tmo;
29905e8ec17SMichael Reed }
30005e8ec17SMichael Reed 
30105e8ec17SMichael Reed static int
mptfc_FcDevPage0_cmp_func(const void * a,const void * b)30205e8ec17SMichael Reed mptfc_FcDevPage0_cmp_func(const void *a, const void *b)
30305e8ec17SMichael Reed {
30405e8ec17SMichael Reed 	FCDevicePage0_t **aa = (FCDevicePage0_t **)a;
30505e8ec17SMichael Reed 	FCDevicePage0_t **bb = (FCDevicePage0_t **)b;
30605e8ec17SMichael Reed 
30705e8ec17SMichael Reed 	if ((*aa)->CurrentBus == (*bb)->CurrentBus) {
30805e8ec17SMichael Reed 		if ((*aa)->CurrentTargetID == (*bb)->CurrentTargetID)
30905e8ec17SMichael Reed 			return 0;
31005e8ec17SMichael Reed 		if ((*aa)->CurrentTargetID < (*bb)->CurrentTargetID)
31105e8ec17SMichael Reed 			return -1;
31205e8ec17SMichael Reed 		return 1;
31305e8ec17SMichael Reed 	}
31405e8ec17SMichael Reed 	if ((*aa)->CurrentBus < (*bb)->CurrentBus)
31505e8ec17SMichael Reed 		return -1;
31605e8ec17SMichael Reed 	return 1;
31705e8ec17SMichael Reed }
31805e8ec17SMichael Reed 
31905e8ec17SMichael Reed static int
mptfc_GetFcDevPage0(MPT_ADAPTER * ioc,int ioc_port,void (* func)(MPT_ADAPTER * ioc,int channel,FCDevicePage0_t * arg))32005e8ec17SMichael Reed mptfc_GetFcDevPage0(MPT_ADAPTER *ioc, int ioc_port,
32105e8ec17SMichael Reed 	void(*func)(MPT_ADAPTER *ioc,int channel, FCDevicePage0_t *arg))
32205e8ec17SMichael Reed {
32305e8ec17SMichael Reed 	ConfigPageHeader_t	 hdr;
32405e8ec17SMichael Reed 	CONFIGPARMS		 cfg;
32505e8ec17SMichael Reed 	FCDevicePage0_t		*ppage0_alloc, *fc;
32605e8ec17SMichael Reed 	dma_addr_t		 page0_dma;
32705e8ec17SMichael Reed 	int			 data_sz;
32805e8ec17SMichael Reed 	int			 ii;
32905e8ec17SMichael Reed 
33005e8ec17SMichael Reed 	FCDevicePage0_t		*p0_array=NULL, *p_p0;
33105e8ec17SMichael Reed 	FCDevicePage0_t		**pp0_array=NULL, **p_pp0;
33205e8ec17SMichael Reed 
33305e8ec17SMichael Reed 	int			 rc = -ENOMEM;
33405e8ec17SMichael Reed 	U32			 port_id = 0xffffff;
33505e8ec17SMichael Reed 	int			 num_targ = 0;
33605e8ec17SMichael Reed 	int			 max_bus = ioc->facts.MaxBuses;
337793955f5SEric Moore 	int			 max_targ;
33805e8ec17SMichael Reed 
339793955f5SEric Moore 	max_targ = (ioc->facts.MaxDevices == 0) ? 256 : ioc->facts.MaxDevices;
34005e8ec17SMichael Reed 
34105e8ec17SMichael Reed 	data_sz = sizeof(FCDevicePage0_t) * max_bus * max_targ;
34205e8ec17SMichael Reed 	p_p0 = p0_array =  kzalloc(data_sz, GFP_KERNEL);
34305e8ec17SMichael Reed 	if (!p0_array)
34405e8ec17SMichael Reed 		goto out;
34505e8ec17SMichael Reed 
34605e8ec17SMichael Reed 	data_sz = sizeof(FCDevicePage0_t *) * max_bus * max_targ;
34705e8ec17SMichael Reed 	p_pp0 = pp0_array = kzalloc(data_sz, GFP_KERNEL);
34805e8ec17SMichael Reed 	if (!pp0_array)
34905e8ec17SMichael Reed 		goto out;
35005e8ec17SMichael Reed 
35105e8ec17SMichael Reed 	do {
35205e8ec17SMichael Reed 		/* Get FC Device Page 0 header */
35305e8ec17SMichael Reed 		hdr.PageVersion = 0;
35405e8ec17SMichael Reed 		hdr.PageLength = 0;
35505e8ec17SMichael Reed 		hdr.PageNumber = 0;
35605e8ec17SMichael Reed 		hdr.PageType = MPI_CONFIG_PAGETYPE_FC_DEVICE;
35705e8ec17SMichael Reed 		cfg.cfghdr.hdr = &hdr;
35805e8ec17SMichael Reed 		cfg.physAddr = -1;
35905e8ec17SMichael Reed 		cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
36005e8ec17SMichael Reed 		cfg.dir = 0;
36105e8ec17SMichael Reed 		cfg.pageAddr = port_id;
36205e8ec17SMichael Reed 		cfg.timeout = 0;
36305e8ec17SMichael Reed 
36405e8ec17SMichael Reed 		if ((rc = mpt_config(ioc, &cfg)) != 0)
36505e8ec17SMichael Reed 			break;
36605e8ec17SMichael Reed 
36705e8ec17SMichael Reed 		if (hdr.PageLength <= 0)
36805e8ec17SMichael Reed 			break;
36905e8ec17SMichael Reed 
37005e8ec17SMichael Reed 		data_sz = hdr.PageLength * 4;
3711897c5c7SChristophe JAILLET 		ppage0_alloc = dma_alloc_coherent(&ioc->pcidev->dev, data_sz,
3721897c5c7SChristophe JAILLET 						  &page0_dma, GFP_KERNEL);
37305e8ec17SMichael Reed 		rc = -ENOMEM;
37405e8ec17SMichael Reed 		if (!ppage0_alloc)
37505e8ec17SMichael Reed 			break;
37605e8ec17SMichael Reed 
37705e8ec17SMichael Reed 		cfg.physAddr = page0_dma;
37805e8ec17SMichael Reed 		cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
37905e8ec17SMichael Reed 
38005e8ec17SMichael Reed 		if ((rc = mpt_config(ioc, &cfg)) == 0) {
38105e8ec17SMichael Reed 			ppage0_alloc->PortIdentifier =
38205e8ec17SMichael Reed 				le32_to_cpu(ppage0_alloc->PortIdentifier);
38305e8ec17SMichael Reed 
38405e8ec17SMichael Reed 			ppage0_alloc->WWNN.Low =
38505e8ec17SMichael Reed 				le32_to_cpu(ppage0_alloc->WWNN.Low);
38605e8ec17SMichael Reed 
38705e8ec17SMichael Reed 			ppage0_alloc->WWNN.High =
38805e8ec17SMichael Reed 				le32_to_cpu(ppage0_alloc->WWNN.High);
38905e8ec17SMichael Reed 
39005e8ec17SMichael Reed 			ppage0_alloc->WWPN.Low =
39105e8ec17SMichael Reed 				le32_to_cpu(ppage0_alloc->WWPN.Low);
39205e8ec17SMichael Reed 
39305e8ec17SMichael Reed 			ppage0_alloc->WWPN.High =
39405e8ec17SMichael Reed 				le32_to_cpu(ppage0_alloc->WWPN.High);
39505e8ec17SMichael Reed 
39605e8ec17SMichael Reed 			ppage0_alloc->BBCredit =
39705e8ec17SMichael Reed 				le16_to_cpu(ppage0_alloc->BBCredit);
39805e8ec17SMichael Reed 
39905e8ec17SMichael Reed 			ppage0_alloc->MaxRxFrameSize =
40005e8ec17SMichael Reed 				le16_to_cpu(ppage0_alloc->MaxRxFrameSize);
40105e8ec17SMichael Reed 
40205e8ec17SMichael Reed 			port_id = ppage0_alloc->PortIdentifier;
40305e8ec17SMichael Reed 			num_targ++;
40405e8ec17SMichael Reed 			*p_p0 = *ppage0_alloc;	/* save data */
40505e8ec17SMichael Reed 			*p_pp0++ = p_p0++;	/* save addr */
40605e8ec17SMichael Reed 		}
4071897c5c7SChristophe JAILLET 		dma_free_coherent(&ioc->pcidev->dev, data_sz,
4081897c5c7SChristophe JAILLET 				  ppage0_alloc, page0_dma);
40905e8ec17SMichael Reed 		if (rc != 0)
41005e8ec17SMichael Reed 			break;
41105e8ec17SMichael Reed 
41205e8ec17SMichael Reed 	} while (port_id <= 0xff0000);
41305e8ec17SMichael Reed 
41405e8ec17SMichael Reed 	if (num_targ) {
41505e8ec17SMichael Reed 		/* sort array */
41605e8ec17SMichael Reed 		if (num_targ > 1)
41705e8ec17SMichael Reed 			sort (pp0_array, num_targ, sizeof(FCDevicePage0_t *),
41805e8ec17SMichael Reed 				mptfc_FcDevPage0_cmp_func, NULL);
41905e8ec17SMichael Reed 		/* call caller's func for each targ */
42005e8ec17SMichael Reed 		for (ii = 0; ii < num_targ;  ii++) {
42105e8ec17SMichael Reed 			fc = *(pp0_array+ii);
42205e8ec17SMichael Reed 			func(ioc, ioc_port, fc);
42305e8ec17SMichael Reed 		}
42405e8ec17SMichael Reed 	}
42505e8ec17SMichael Reed 
42605e8ec17SMichael Reed  out:
42705e8ec17SMichael Reed 	kfree(pp0_array);
42805e8ec17SMichael Reed 	kfree(p0_array);
42905e8ec17SMichael Reed 	return rc;
43005e8ec17SMichael Reed }
43105e8ec17SMichael Reed 
43205e8ec17SMichael Reed static int
mptfc_generate_rport_ids(FCDevicePage0_t * pg0,struct fc_rport_identifiers * rid)43305e8ec17SMichael Reed mptfc_generate_rport_ids(FCDevicePage0_t *pg0, struct fc_rport_identifiers *rid)
43405e8ec17SMichael Reed {
43505e8ec17SMichael Reed 	/* not currently usable */
43605e8ec17SMichael Reed 	if (pg0->Flags & (MPI_FC_DEVICE_PAGE0_FLAGS_PLOGI_INVALID |
43705e8ec17SMichael Reed 			  MPI_FC_DEVICE_PAGE0_FLAGS_PRLI_INVALID))
43805e8ec17SMichael Reed 		return -1;
43905e8ec17SMichael Reed 
44005e8ec17SMichael Reed 	if (!(pg0->Flags & MPI_FC_DEVICE_PAGE0_FLAGS_TARGETID_BUS_VALID))
44105e8ec17SMichael Reed 		return -1;
44205e8ec17SMichael Reed 
44305e8ec17SMichael Reed 	if (!(pg0->Protocol & MPI_FC_DEVICE_PAGE0_PROT_FCP_TARGET))
44405e8ec17SMichael Reed 		return -1;
44505e8ec17SMichael Reed 
44605e8ec17SMichael Reed 	/*
44705e8ec17SMichael Reed 	 * board data structure already normalized to platform endianness
44805e8ec17SMichael Reed 	 * shifted to avoid unaligned access on 64 bit architecture
44905e8ec17SMichael Reed 	 */
45005e8ec17SMichael Reed 	rid->node_name = ((u64)pg0->WWNN.High) << 32 | (u64)pg0->WWNN.Low;
45105e8ec17SMichael Reed 	rid->port_name = ((u64)pg0->WWPN.High) << 32 | (u64)pg0->WWPN.Low;
45205e8ec17SMichael Reed 	rid->port_id =   pg0->PortIdentifier;
45305e8ec17SMichael Reed 	rid->roles = FC_RPORT_ROLE_UNKNOWN;
45405e8ec17SMichael Reed 
45505e8ec17SMichael Reed 	return 0;
45605e8ec17SMichael Reed }
45705e8ec17SMichael Reed 
45805e8ec17SMichael Reed static void
mptfc_register_dev(MPT_ADAPTER * ioc,int channel,FCDevicePage0_t * pg0)45905e8ec17SMichael Reed mptfc_register_dev(MPT_ADAPTER *ioc, int channel, FCDevicePage0_t *pg0)
46005e8ec17SMichael Reed {
46105e8ec17SMichael Reed 	struct fc_rport_identifiers rport_ids;
46205e8ec17SMichael Reed 	struct fc_rport		*rport;
46305e8ec17SMichael Reed 	struct mptfc_rport_info	*ri;
4643bc7bf1dSMichael Reed 	int			new_ri = 1;
46565207fedSMoore, Eric 	u64			pn, nn;
4663bc7bf1dSMichael Reed 	VirtTarget		*vtarget;
4676dd727daSmdr@sgi.com 	u32			roles = FC_RPORT_ROLE_UNKNOWN;
46805e8ec17SMichael Reed 
46905e8ec17SMichael Reed 	if (mptfc_generate_rport_ids(pg0, &rport_ids) < 0)
47005e8ec17SMichael Reed 		return;
47105e8ec17SMichael Reed 
4726dd727daSmdr@sgi.com 	roles |= FC_RPORT_ROLE_FCP_TARGET;
4736dd727daSmdr@sgi.com 	if (pg0->Protocol & MPI_FC_DEVICE_PAGE0_PROT_FCP_INITIATOR)
4746dd727daSmdr@sgi.com 		roles |= FC_RPORT_ROLE_FCP_INITIATOR;
4756dd727daSmdr@sgi.com 
47605e8ec17SMichael Reed 	/* scan list looking for a match */
47705e8ec17SMichael Reed 	list_for_each_entry(ri, &ioc->fc_rports, list) {
4783bc7bf1dSMichael Reed 		pn = (u64)ri->pg0.WWPN.High << 32 | (u64)ri->pg0.WWPN.Low;
4793bc7bf1dSMichael Reed 		if (pn == rport_ids.port_name) {	/* match */
48005e8ec17SMichael Reed 			list_move_tail(&ri->list, &ioc->fc_rports);
4813bc7bf1dSMichael Reed 			new_ri = 0;
48205e8ec17SMichael Reed 			break;
48305e8ec17SMichael Reed 		}
48405e8ec17SMichael Reed 	}
4853bc7bf1dSMichael Reed 	if (new_ri) {	/* allocate one */
48605e8ec17SMichael Reed 		ri = kzalloc(sizeof(struct mptfc_rport_info), GFP_KERNEL);
48705e8ec17SMichael Reed 		if (!ri)
48805e8ec17SMichael Reed 			return;
48905e8ec17SMichael Reed 		list_add_tail(&ri->list, &ioc->fc_rports);
49005e8ec17SMichael Reed 	}
49105e8ec17SMichael Reed 
49205e8ec17SMichael Reed 	ri->pg0 = *pg0;	/* add/update pg0 data */
49305e8ec17SMichael Reed 	ri->flags &= ~MPT_RPORT_INFO_FLAGS_MISSING;
49405e8ec17SMichael Reed 
4953bc7bf1dSMichael Reed 	/* MPT_RPORT_INFO_FLAGS_REGISTERED - rport not previously deleted */
49605e8ec17SMichael Reed 	if (!(ri->flags & MPT_RPORT_INFO_FLAGS_REGISTERED)) {
49705e8ec17SMichael Reed 		ri->flags |= MPT_RPORT_INFO_FLAGS_REGISTERED;
49805e8ec17SMichael Reed 		rport = fc_remote_port_add(ioc->sh, channel, &rport_ids);
49905e8ec17SMichael Reed 		if (rport) {
50005e8ec17SMichael Reed 			ri->rport = rport;
5013bc7bf1dSMichael Reed 			if (new_ri) /* may have been reset by user */
50205e8ec17SMichael Reed 				rport->dev_loss_tmo = mptfc_dev_loss_tmo;
50305e8ec17SMichael Reed 			/*
50405e8ec17SMichael Reed 			 * if already mapped, remap here.  If not mapped,
5053bc7bf1dSMichael Reed 			 * target_alloc will allocate vtarget and map,
506a69de507SEric Moore 			 * slave_alloc will fill in vdevice from vtarget.
50705e8ec17SMichael Reed 			 */
5083bc7bf1dSMichael Reed 			if (ri->starget) {
5093bc7bf1dSMichael Reed 				vtarget = ri->starget->hostdata;
5103bc7bf1dSMichael Reed 				if (vtarget) {
511793955f5SEric Moore 					vtarget->id = pg0->CurrentTargetID;
512793955f5SEric Moore 					vtarget->channel = pg0->CurrentBus;
51308f5c5c2SKashyap, Desai 					vtarget->deleted = 0;
51405e8ec17SMichael Reed 				}
5153bc7bf1dSMichael Reed 			}
51665207fedSMoore, Eric 			*((struct mptfc_rport_info **)rport->dd_data) = ri;
5176dd727daSmdr@sgi.com 			/* scan will be scheduled once rport becomes a target */
5186dd727daSmdr@sgi.com 			fc_remote_port_rolechg(rport,roles);
51965207fedSMoore, Eric 
52065207fedSMoore, Eric 			pn = (u64)ri->pg0.WWPN.High << 32 | (u64)ri->pg0.WWPN.Low;
52165207fedSMoore, Eric 			nn = (u64)ri->pg0.WWNN.High << 32 | (u64)ri->pg0.WWNN.Low;
522d6ecdd63SPrakash, Sathya 			dfcprintk (ioc, printk(MYIOC_s_DEBUG_FMT
5233bc7bf1dSMichael Reed 				"mptfc_reg_dev.%d: %x, %llx / %llx, tid %d, "
52405e8ec17SMichael Reed 				"rport tid %d, tmo %d\n",
5253bc7bf1dSMichael Reed 					ioc->name,
526914c2d8eSMoore, Eric 					ioc->sh->host_no,
52705e8ec17SMichael Reed 					pg0->PortIdentifier,
52865207fedSMoore, Eric 					(unsigned long long)nn,
52965207fedSMoore, Eric 					(unsigned long long)pn,
53005e8ec17SMichael Reed 					pg0->CurrentTargetID,
53105e8ec17SMichael Reed 					ri->rport->scsi_target_id,
5323bc7bf1dSMichael Reed 					ri->rport->dev_loss_tmo));
53305e8ec17SMichael Reed 		} else {
53405e8ec17SMichael Reed 			list_del(&ri->list);
53505e8ec17SMichael Reed 			kfree(ri);
53605e8ec17SMichael Reed 			ri = NULL;
53705e8ec17SMichael Reed 		}
53805e8ec17SMichael Reed 	}
53905e8ec17SMichael Reed }
54005e8ec17SMichael Reed 
54105e8ec17SMichael Reed /*
5423bc7bf1dSMichael Reed  *	OS entry point to allow for host driver to free allocated memory
5433bc7bf1dSMichael Reed  *	Called if no device present or device being unloaded
5443bc7bf1dSMichael Reed  */
5453bc7bf1dSMichael Reed static void
mptfc_target_destroy(struct scsi_target * starget)5463bc7bf1dSMichael Reed mptfc_target_destroy(struct scsi_target *starget)
5473bc7bf1dSMichael Reed {
5483bc7bf1dSMichael Reed 	struct fc_rport		*rport;
5493bc7bf1dSMichael Reed 	struct mptfc_rport_info *ri;
5503bc7bf1dSMichael Reed 
5513bc7bf1dSMichael Reed 	rport = starget_to_rport(starget);
5523bc7bf1dSMichael Reed 	if (rport) {
5533bc7bf1dSMichael Reed 		ri = *((struct mptfc_rport_info **)rport->dd_data);
5543bc7bf1dSMichael Reed 		if (ri)	/* better be! */
5553bc7bf1dSMichael Reed 			ri->starget = NULL;
5563bc7bf1dSMichael Reed 	}
5573bc7bf1dSMichael Reed 	kfree(starget->hostdata);
5583bc7bf1dSMichael Reed 	starget->hostdata = NULL;
5593bc7bf1dSMichael Reed }
5603bc7bf1dSMichael Reed 
5613bc7bf1dSMichael Reed /*
5623bc7bf1dSMichael Reed  *	OS entry point to allow host driver to alloc memory
5633bc7bf1dSMichael Reed  *	for each scsi target. Called once per device the bus scan.
5643bc7bf1dSMichael Reed  *	Return non-zero if allocation fails.
5653bc7bf1dSMichael Reed  */
5663bc7bf1dSMichael Reed static int
mptfc_target_alloc(struct scsi_target * starget)5673bc7bf1dSMichael Reed mptfc_target_alloc(struct scsi_target *starget)
5683bc7bf1dSMichael Reed {
5693bc7bf1dSMichael Reed 	VirtTarget		*vtarget;
5703bc7bf1dSMichael Reed 	struct fc_rport		*rport;
5713bc7bf1dSMichael Reed 	struct mptfc_rport_info *ri;
5723bc7bf1dSMichael Reed 	int			rc;
5733bc7bf1dSMichael Reed 
5743bc7bf1dSMichael Reed 	vtarget = kzalloc(sizeof(VirtTarget), GFP_KERNEL);
5753bc7bf1dSMichael Reed 	if (!vtarget)
5763bc7bf1dSMichael Reed 		return -ENOMEM;
5773bc7bf1dSMichael Reed 	starget->hostdata = vtarget;
5783bc7bf1dSMichael Reed 
5793bc7bf1dSMichael Reed 	rc = -ENODEV;
5803bc7bf1dSMichael Reed 	rport = starget_to_rport(starget);
5813bc7bf1dSMichael Reed 	if (rport) {
5823bc7bf1dSMichael Reed 		ri = *((struct mptfc_rport_info **)rport->dd_data);
5833bc7bf1dSMichael Reed 		if (ri) {	/* better be! */
584793955f5SEric Moore 			vtarget->id = ri->pg0.CurrentTargetID;
585793955f5SEric Moore 			vtarget->channel = ri->pg0.CurrentBus;
5863bc7bf1dSMichael Reed 			ri->starget = starget;
5873bc7bf1dSMichael Reed 			rc = 0;
5883bc7bf1dSMichael Reed 		}
5893bc7bf1dSMichael Reed 	}
5903bc7bf1dSMichael Reed 	if (rc != 0) {
5913bc7bf1dSMichael Reed 		kfree(vtarget);
5923bc7bf1dSMichael Reed 		starget->hostdata = NULL;
5933bc7bf1dSMichael Reed 	}
5943bc7bf1dSMichael Reed 
5953bc7bf1dSMichael Reed 	return rc;
5963bc7bf1dSMichael Reed }
597d6ecdd63SPrakash, Sathya /*
598d6ecdd63SPrakash, Sathya  *	mptfc_dump_lun_info
599d6ecdd63SPrakash, Sathya  *	@ioc
600d6ecdd63SPrakash, Sathya  *	@rport
601d6ecdd63SPrakash, Sathya  *	@sdev
602d6ecdd63SPrakash, Sathya  *
603d6ecdd63SPrakash, Sathya  */
604d6ecdd63SPrakash, Sathya static void
mptfc_dump_lun_info(MPT_ADAPTER * ioc,struct fc_rport * rport,struct scsi_device * sdev,VirtTarget * vtarget)605d6ecdd63SPrakash, Sathya mptfc_dump_lun_info(MPT_ADAPTER *ioc, struct fc_rport *rport, struct scsi_device *sdev,
606d6ecdd63SPrakash, Sathya 		VirtTarget *vtarget)
607d6ecdd63SPrakash, Sathya {
608d6ecdd63SPrakash, Sathya 	u64 nn, pn;
609d6ecdd63SPrakash, Sathya 	struct mptfc_rport_info *ri;
610d6ecdd63SPrakash, Sathya 
611d6ecdd63SPrakash, Sathya 	ri = *((struct mptfc_rport_info **)rport->dd_data);
612d6ecdd63SPrakash, Sathya 	pn = (u64)ri->pg0.WWPN.High << 32 | (u64)ri->pg0.WWPN.Low;
613d6ecdd63SPrakash, Sathya 	nn = (u64)ri->pg0.WWNN.High << 32 | (u64)ri->pg0.WWNN.Low;
614d6ecdd63SPrakash, Sathya 	dfcprintk (ioc, printk(MYIOC_s_DEBUG_FMT
615d6ecdd63SPrakash, Sathya 		"mptfc_slv_alloc.%d: num_luns %d, sdev.id %d, "
616d6ecdd63SPrakash, Sathya 		"CurrentTargetID %d, %x %llx %llx\n",
617d6ecdd63SPrakash, Sathya 		ioc->name,
618d6ecdd63SPrakash, Sathya 		sdev->host->host_no,
619d6ecdd63SPrakash, Sathya 		vtarget->num_luns,
620d6ecdd63SPrakash, Sathya 		sdev->id, ri->pg0.CurrentTargetID,
621d6ecdd63SPrakash, Sathya 		ri->pg0.PortIdentifier,
622d6ecdd63SPrakash, Sathya 		(unsigned long long)pn,
623d6ecdd63SPrakash, Sathya 		(unsigned long long)nn));
624d6ecdd63SPrakash, Sathya }
625d6ecdd63SPrakash, Sathya 
6263bc7bf1dSMichael Reed 
6273bc7bf1dSMichael Reed /*
62805e8ec17SMichael Reed  *	OS entry point to allow host driver to alloc memory
62905e8ec17SMichael Reed  *	for each scsi device. Called once per device the bus scan.
63005e8ec17SMichael Reed  *	Return non-zero if allocation fails.
63105e8ec17SMichael Reed  *	Init memory once per LUN.
63205e8ec17SMichael Reed  */
63303fbcbcdSAdrian Bunk static int
mptfc_slave_alloc(struct scsi_device * sdev)63405e8ec17SMichael Reed mptfc_slave_alloc(struct scsi_device *sdev)
63505e8ec17SMichael Reed {
63605e8ec17SMichael Reed 	MPT_SCSI_HOST		*hd;
63705e8ec17SMichael Reed 	VirtTarget		*vtarget;
638a69de507SEric Moore 	VirtDevice		*vdevice;
63905e8ec17SMichael Reed 	struct scsi_target	*starget;
64005e8ec17SMichael Reed 	struct fc_rport		*rport;
641e80b002bSEric Moore 	MPT_ADAPTER 		*ioc;
64205e8ec17SMichael Reed 
64365207fedSMoore, Eric 	starget = scsi_target(sdev);
64465207fedSMoore, Eric 	rport = starget_to_rport(starget);
64505e8ec17SMichael Reed 
64605e8ec17SMichael Reed 	if (!rport || fc_remote_port_chkready(rport))
64705e8ec17SMichael Reed 		return -ENXIO;
64805e8ec17SMichael Reed 
649e7eae9f6SEric Moore 	hd = shost_priv(sdev->host);
650e80b002bSEric Moore 	ioc = hd->ioc;
65105e8ec17SMichael Reed 
652a69de507SEric Moore 	vdevice = kzalloc(sizeof(VirtDevice), GFP_KERNEL);
653a69de507SEric Moore 	if (!vdevice) {
65405e8ec17SMichael Reed 		printk(MYIOC_s_ERR_FMT "slave_alloc kmalloc(%zd) FAILED!\n",
655e80b002bSEric Moore 				ioc->name, sizeof(VirtDevice));
65605e8ec17SMichael Reed 		return -ENOMEM;
65705e8ec17SMichael Reed 	}
65805e8ec17SMichael Reed 
65905e8ec17SMichael Reed 
660a69de507SEric Moore 	sdev->hostdata = vdevice;
66105e8ec17SMichael Reed 	vtarget = starget->hostdata;
6623bc7bf1dSMichael Reed 
66305e8ec17SMichael Reed 	if (vtarget->num_luns == 0) {
664e80b002bSEric Moore 		vtarget->ioc_id = ioc->id;
665ba856d32SEric Moore 		vtarget->tflags = MPT_TARGET_FLAGS_Q_YES;
66605e8ec17SMichael Reed 	}
66705e8ec17SMichael Reed 
668a69de507SEric Moore 	vdevice->vtarget = vtarget;
669a69de507SEric Moore 	vdevice->lun = sdev->lun;
67005e8ec17SMichael Reed 
67105e8ec17SMichael Reed 	vtarget->num_luns++;
67205e8ec17SMichael Reed 
67365207fedSMoore, Eric 
674e80b002bSEric Moore 	mptfc_dump_lun_info(ioc, rport, sdev, vtarget);
67505e8ec17SMichael Reed 
67605e8ec17SMichael Reed 	return 0;
67705e8ec17SMichael Reed }
67805e8ec17SMichael Reed 
67905e8ec17SMichael Reed static int
mptfc_qcmd(struct Scsi_Host * shost,struct scsi_cmnd * SCpnt)680a48ac9e5SMatthew Wilcox mptfc_qcmd(struct Scsi_Host *shost, struct scsi_cmnd *SCpnt)
68105e8ec17SMichael Reed {
6823bc7bf1dSMichael Reed 	struct mptfc_rport_info	*ri;
68305e8ec17SMichael Reed 	struct fc_rport	*rport = starget_to_rport(scsi_target(SCpnt->device));
68405e8ec17SMichael Reed 	int		err;
685a69de507SEric Moore 	VirtDevice	*vdevice = SCpnt->device->hostdata;
68605e8ec17SMichael Reed 
687a69de507SEric Moore 	if (!vdevice || !vdevice->vtarget) {
688793955f5SEric Moore 		SCpnt->result = DID_NO_CONNECT << 16;
6891ae6d167SBart Van Assche 		scsi_done(SCpnt);
69005e8ec17SMichael Reed 		return 0;
69105e8ec17SMichael Reed 	}
6923bc7bf1dSMichael Reed 
693793955f5SEric Moore 	err = fc_remote_port_chkready(rport);
694793955f5SEric Moore 	if (unlikely(err)) {
695793955f5SEric Moore 		SCpnt->result = err;
6961ae6d167SBart Van Assche 		scsi_done(SCpnt);
69735508e46SMichael Reed 		return 0;
69835508e46SMichael Reed 	}
69935508e46SMichael Reed 
70065207fedSMoore, Eric 	/* dd_data is null until finished adding target */
70165207fedSMoore, Eric 	ri = *((struct mptfc_rport_info **)rport->dd_data);
70265207fedSMoore, Eric 	if (unlikely(!ri)) {
70365207fedSMoore, Eric 		SCpnt->result = DID_IMM_RETRY << 16;
7041ae6d167SBart Van Assche 		scsi_done(SCpnt);
70565207fedSMoore, Eric 		return 0;
70665207fedSMoore, Eric 	}
70765207fedSMoore, Eric 
708a48ac9e5SMatthew Wilcox 	return mptscsih_qcmd(SCpnt);
70905e8ec17SMichael Reed }
71005e8ec17SMichael Reed 
71180d3ac77SMichael Reed /*
712eb5329f4SPrakash, Sathya  *	mptfc_display_port_link_speed - displaying link speed
713eb5329f4SPrakash, Sathya  *	@ioc: Pointer to MPT_ADAPTER structure
714eb5329f4SPrakash, Sathya  *	@portnum: IOC Port number
715eb5329f4SPrakash, Sathya  *	@pp0dest: port page0 data payload
716eb5329f4SPrakash, Sathya  *
717eb5329f4SPrakash, Sathya  */
718eb5329f4SPrakash, Sathya static void
mptfc_display_port_link_speed(MPT_ADAPTER * ioc,int portnum,FCPortPage0_t * pp0dest)719eb5329f4SPrakash, Sathya mptfc_display_port_link_speed(MPT_ADAPTER *ioc, int portnum, FCPortPage0_t *pp0dest)
720eb5329f4SPrakash, Sathya {
721eb5329f4SPrakash, Sathya 	u8	old_speed, new_speed, state;
722eb5329f4SPrakash, Sathya 	char	*old, *new;
723eb5329f4SPrakash, Sathya 
724eb5329f4SPrakash, Sathya 	if (portnum >= 2)
725eb5329f4SPrakash, Sathya 		return;
726eb5329f4SPrakash, Sathya 
727eb5329f4SPrakash, Sathya 	old_speed = ioc->fc_link_speed[portnum];
728eb5329f4SPrakash, Sathya 	new_speed = pp0dest->CurrentSpeed;
729eb5329f4SPrakash, Sathya 	state = pp0dest->PortState;
730eb5329f4SPrakash, Sathya 
731eb5329f4SPrakash, Sathya 	if (state != MPI_FCPORTPAGE0_PORTSTATE_OFFLINE &&
732bcbba7bbSColin Ian King 	    new_speed != MPI_FCPORTPAGE0_CURRENT_SPEED_UNKNOWN) {
733eb5329f4SPrakash, Sathya 
734eb5329f4SPrakash, Sathya 		old = old_speed == MPI_FCPORTPAGE0_CURRENT_SPEED_1GBIT ? "1 Gbps" :
735eb5329f4SPrakash, Sathya 		       old_speed == MPI_FCPORTPAGE0_CURRENT_SPEED_2GBIT ? "2 Gbps" :
736eb5329f4SPrakash, Sathya 			old_speed == MPI_FCPORTPAGE0_CURRENT_SPEED_4GBIT ? "4 Gbps" :
737eb5329f4SPrakash, Sathya 			 "Unknown";
738eb5329f4SPrakash, Sathya 		new = new_speed == MPI_FCPORTPAGE0_CURRENT_SPEED_1GBIT ? "1 Gbps" :
739eb5329f4SPrakash, Sathya 		       new_speed == MPI_FCPORTPAGE0_CURRENT_SPEED_2GBIT ? "2 Gbps" :
740eb5329f4SPrakash, Sathya 			new_speed == MPI_FCPORTPAGE0_CURRENT_SPEED_4GBIT ? "4 Gbps" :
741eb5329f4SPrakash, Sathya 			 "Unknown";
742eb5329f4SPrakash, Sathya 		if (old_speed == 0)
743eb5329f4SPrakash, Sathya 			printk(MYIOC_s_NOTE_FMT
744eb5329f4SPrakash, Sathya 				"FC Link Established, Speed = %s\n",
745eb5329f4SPrakash, Sathya 				ioc->name, new);
746eb5329f4SPrakash, Sathya 		else if (old_speed != new_speed)
747eb5329f4SPrakash, Sathya 			printk(MYIOC_s_WARN_FMT
748eb5329f4SPrakash, Sathya 				"FC Link Speed Change, Old Speed = %s, New Speed = %s\n",
749eb5329f4SPrakash, Sathya 				ioc->name, old, new);
750eb5329f4SPrakash, Sathya 
751eb5329f4SPrakash, Sathya 		ioc->fc_link_speed[portnum] = new_speed;
752eb5329f4SPrakash, Sathya 	}
753eb5329f4SPrakash, Sathya }
754eb5329f4SPrakash, Sathya 
755eb5329f4SPrakash, Sathya /*
75680d3ac77SMichael Reed  *	mptfc_GetFcPortPage0 - Fetch FCPort config Page0.
75780d3ac77SMichael Reed  *	@ioc: Pointer to MPT_ADAPTER structure
75880d3ac77SMichael Reed  *	@portnum: IOC Port number
75980d3ac77SMichael Reed  *
76080d3ac77SMichael Reed  *	Return: 0 for success
76180d3ac77SMichael Reed  *	-ENOMEM if no memory available
76280d3ac77SMichael Reed  *		-EPERM if not allowed due to ISR context
76380d3ac77SMichael Reed  *		-EAGAIN if no msg frames currently available
76480d3ac77SMichael Reed  *		-EFAULT for non-successful reply or no reply (timeout)
76580d3ac77SMichael Reed  *		-EINVAL portnum arg out of range (hardwired to two elements)
76680d3ac77SMichael Reed  */
76780d3ac77SMichael Reed static int
mptfc_GetFcPortPage0(MPT_ADAPTER * ioc,int portnum)76880d3ac77SMichael Reed mptfc_GetFcPortPage0(MPT_ADAPTER *ioc, int portnum)
76980d3ac77SMichael Reed {
77080d3ac77SMichael Reed 	ConfigPageHeader_t	 hdr;
77180d3ac77SMichael Reed 	CONFIGPARMS		 cfg;
77280d3ac77SMichael Reed 	FCPortPage0_t		*ppage0_alloc;
77380d3ac77SMichael Reed 	FCPortPage0_t		*pp0dest;
77480d3ac77SMichael Reed 	dma_addr_t		 page0_dma;
77580d3ac77SMichael Reed 	int			 data_sz;
77680d3ac77SMichael Reed 	int			 copy_sz;
77780d3ac77SMichael Reed 	int			 rc;
77880d3ac77SMichael Reed 	int			 count = 400;
77980d3ac77SMichael Reed 
78080d3ac77SMichael Reed 	if (portnum > 1)
78180d3ac77SMichael Reed 		return -EINVAL;
78280d3ac77SMichael Reed 
78380d3ac77SMichael Reed 	/* Get FCPort Page 0 header */
78480d3ac77SMichael Reed 	hdr.PageVersion = 0;
78580d3ac77SMichael Reed 	hdr.PageLength = 0;
78680d3ac77SMichael Reed 	hdr.PageNumber = 0;
78780d3ac77SMichael Reed 	hdr.PageType = MPI_CONFIG_PAGETYPE_FC_PORT;
78880d3ac77SMichael Reed 	cfg.cfghdr.hdr = &hdr;
78980d3ac77SMichael Reed 	cfg.physAddr = -1;
79080d3ac77SMichael Reed 	cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
79180d3ac77SMichael Reed 	cfg.dir = 0;
79280d3ac77SMichael Reed 	cfg.pageAddr = portnum;
79380d3ac77SMichael Reed 	cfg.timeout = 0;
79480d3ac77SMichael Reed 
79580d3ac77SMichael Reed 	if ((rc = mpt_config(ioc, &cfg)) != 0)
79680d3ac77SMichael Reed 		return rc;
79780d3ac77SMichael Reed 
79880d3ac77SMichael Reed 	if (hdr.PageLength == 0)
79980d3ac77SMichael Reed 		return 0;
80080d3ac77SMichael Reed 
80180d3ac77SMichael Reed 	data_sz = hdr.PageLength * 4;
80280d3ac77SMichael Reed 	rc = -ENOMEM;
8031897c5c7SChristophe JAILLET 	ppage0_alloc = dma_alloc_coherent(&ioc->pcidev->dev, data_sz,
8041897c5c7SChristophe JAILLET 					  &page0_dma, GFP_KERNEL);
80580d3ac77SMichael Reed 	if (ppage0_alloc) {
80680d3ac77SMichael Reed 
80780d3ac77SMichael Reed  try_again:
80880d3ac77SMichael Reed 		memset((u8 *)ppage0_alloc, 0, data_sz);
80980d3ac77SMichael Reed 		cfg.physAddr = page0_dma;
81080d3ac77SMichael Reed 		cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
81180d3ac77SMichael Reed 
81280d3ac77SMichael Reed 		if ((rc = mpt_config(ioc, &cfg)) == 0) {
81380d3ac77SMichael Reed 			/* save the data */
81480d3ac77SMichael Reed 			pp0dest = &ioc->fc_port_page0[portnum];
81580d3ac77SMichael Reed 			copy_sz = min_t(int, sizeof(FCPortPage0_t), data_sz);
81680d3ac77SMichael Reed 			memcpy(pp0dest, ppage0_alloc, copy_sz);
81780d3ac77SMichael Reed 
81880d3ac77SMichael Reed 			/*
81980d3ac77SMichael Reed 			 *	Normalize endianness of structure data,
82080d3ac77SMichael Reed 			 *	by byte-swapping all > 1 byte fields!
82180d3ac77SMichael Reed 			 */
82280d3ac77SMichael Reed 			pp0dest->Flags = le32_to_cpu(pp0dest->Flags);
82380d3ac77SMichael Reed 			pp0dest->PortIdentifier = le32_to_cpu(pp0dest->PortIdentifier);
82480d3ac77SMichael Reed 			pp0dest->WWNN.Low = le32_to_cpu(pp0dest->WWNN.Low);
82580d3ac77SMichael Reed 			pp0dest->WWNN.High = le32_to_cpu(pp0dest->WWNN.High);
82680d3ac77SMichael Reed 			pp0dest->WWPN.Low = le32_to_cpu(pp0dest->WWPN.Low);
82780d3ac77SMichael Reed 			pp0dest->WWPN.High = le32_to_cpu(pp0dest->WWPN.High);
82880d3ac77SMichael Reed 			pp0dest->SupportedServiceClass = le32_to_cpu(pp0dest->SupportedServiceClass);
82980d3ac77SMichael Reed 			pp0dest->SupportedSpeeds = le32_to_cpu(pp0dest->SupportedSpeeds);
83080d3ac77SMichael Reed 			pp0dest->CurrentSpeed = le32_to_cpu(pp0dest->CurrentSpeed);
83180d3ac77SMichael Reed 			pp0dest->MaxFrameSize = le32_to_cpu(pp0dest->MaxFrameSize);
83280d3ac77SMichael Reed 			pp0dest->FabricWWNN.Low = le32_to_cpu(pp0dest->FabricWWNN.Low);
83380d3ac77SMichael Reed 			pp0dest->FabricWWNN.High = le32_to_cpu(pp0dest->FabricWWNN.High);
83480d3ac77SMichael Reed 			pp0dest->FabricWWPN.Low = le32_to_cpu(pp0dest->FabricWWPN.Low);
83580d3ac77SMichael Reed 			pp0dest->FabricWWPN.High = le32_to_cpu(pp0dest->FabricWWPN.High);
83680d3ac77SMichael Reed 			pp0dest->DiscoveredPortsCount = le32_to_cpu(pp0dest->DiscoveredPortsCount);
83780d3ac77SMichael Reed 			pp0dest->MaxInitiators = le32_to_cpu(pp0dest->MaxInitiators);
83880d3ac77SMichael Reed 
83980d3ac77SMichael Reed 			/*
84080d3ac77SMichael Reed 			 * if still doing discovery,
84180d3ac77SMichael Reed 			 * hang loose a while until finished
84280d3ac77SMichael Reed 			 */
84377d88ee2SMichael Reed 			if ((pp0dest->PortState == MPI_FCPORTPAGE0_PORTSTATE_UNKNOWN) ||
84477d88ee2SMichael Reed 			    (pp0dest->PortState == MPI_FCPORTPAGE0_PORTSTATE_ONLINE &&
84577d88ee2SMichael Reed 			     (pp0dest->Flags & MPI_FCPORTPAGE0_FLAGS_ATTACH_TYPE_MASK)
84677d88ee2SMichael Reed 			      == MPI_FCPORTPAGE0_FLAGS_ATTACH_NO_INIT)) {
84780d3ac77SMichael Reed 				if (count-- > 0) {
848d6be06c8SMichael Reed 					msleep(100);
84980d3ac77SMichael Reed 					goto try_again;
85080d3ac77SMichael Reed 				}
85180d3ac77SMichael Reed 				printk(MYIOC_s_INFO_FMT "Firmware discovery not"
85280d3ac77SMichael Reed 							" complete.\n",
85380d3ac77SMichael Reed 						ioc->name);
85480d3ac77SMichael Reed 			}
855eb5329f4SPrakash, Sathya 			mptfc_display_port_link_speed(ioc, portnum, pp0dest);
85680d3ac77SMichael Reed 		}
85780d3ac77SMichael Reed 
8581897c5c7SChristophe JAILLET 		dma_free_coherent(&ioc->pcidev->dev, data_sz, ppage0_alloc,
8591897c5c7SChristophe JAILLET 				  page0_dma);
86080d3ac77SMichael Reed 	}
86180d3ac77SMichael Reed 
86280d3ac77SMichael Reed 	return rc;
86380d3ac77SMichael Reed }
86480d3ac77SMichael Reed 
865ca2f938eSMichael Reed static int
mptfc_WriteFcPortPage1(MPT_ADAPTER * ioc,int portnum)866ca2f938eSMichael Reed mptfc_WriteFcPortPage1(MPT_ADAPTER *ioc, int portnum)
867ca2f938eSMichael Reed {
868ca2f938eSMichael Reed 	ConfigPageHeader_t	 hdr;
869ca2f938eSMichael Reed 	CONFIGPARMS		 cfg;
870ca2f938eSMichael Reed 	int			 rc;
871ca2f938eSMichael Reed 
872ca2f938eSMichael Reed 	if (portnum > 1)
873ca2f938eSMichael Reed 		return -EINVAL;
874ca2f938eSMichael Reed 
875ca2f938eSMichael Reed 	if (!(ioc->fc_data.fc_port_page1[portnum].data))
876ca2f938eSMichael Reed 		return -EINVAL;
877ca2f938eSMichael Reed 
878ca2f938eSMichael Reed 	/* get fcport page 1 header */
879ca2f938eSMichael Reed 	hdr.PageVersion = 0;
880ca2f938eSMichael Reed 	hdr.PageLength = 0;
881ca2f938eSMichael Reed 	hdr.PageNumber = 1;
882ca2f938eSMichael Reed 	hdr.PageType = MPI_CONFIG_PAGETYPE_FC_PORT;
883ca2f938eSMichael Reed 	cfg.cfghdr.hdr = &hdr;
884ca2f938eSMichael Reed 	cfg.physAddr = -1;
885ca2f938eSMichael Reed 	cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
886ca2f938eSMichael Reed 	cfg.dir = 0;
887ca2f938eSMichael Reed 	cfg.pageAddr = portnum;
888ca2f938eSMichael Reed 	cfg.timeout = 0;
889ca2f938eSMichael Reed 
890ca2f938eSMichael Reed 	if ((rc = mpt_config(ioc, &cfg)) != 0)
891ca2f938eSMichael Reed 		return rc;
892ca2f938eSMichael Reed 
893ca2f938eSMichael Reed 	if (hdr.PageLength == 0)
894ca2f938eSMichael Reed 		return -ENODEV;
895ca2f938eSMichael Reed 
896ca2f938eSMichael Reed 	if (hdr.PageLength*4 != ioc->fc_data.fc_port_page1[portnum].pg_sz)
897ca2f938eSMichael Reed 		return -EINVAL;
898ca2f938eSMichael Reed 
899ca2f938eSMichael Reed 	cfg.physAddr = ioc->fc_data.fc_port_page1[portnum].dma;
900ca2f938eSMichael Reed 	cfg.action = MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT;
901ca2f938eSMichael Reed 	cfg.dir = 1;
902ca2f938eSMichael Reed 
903ca2f938eSMichael Reed 	rc = mpt_config(ioc, &cfg);
904ca2f938eSMichael Reed 
905ca2f938eSMichael Reed 	return rc;
906ca2f938eSMichael Reed }
907ca2f938eSMichael Reed 
908ca2f938eSMichael Reed static int
mptfc_GetFcPortPage1(MPT_ADAPTER * ioc,int portnum)909ca2f938eSMichael Reed mptfc_GetFcPortPage1(MPT_ADAPTER *ioc, int portnum)
910ca2f938eSMichael Reed {
911ca2f938eSMichael Reed 	ConfigPageHeader_t	 hdr;
912ca2f938eSMichael Reed 	CONFIGPARMS		 cfg;
913ca2f938eSMichael Reed 	FCPortPage1_t		*page1_alloc;
914ca2f938eSMichael Reed 	dma_addr_t		 page1_dma;
915ca2f938eSMichael Reed 	int			 data_sz;
916ca2f938eSMichael Reed 	int			 rc;
917ca2f938eSMichael Reed 
918ca2f938eSMichael Reed 	if (portnum > 1)
919ca2f938eSMichael Reed 		return -EINVAL;
920ca2f938eSMichael Reed 
921ca2f938eSMichael Reed 	/* get fcport page 1 header */
922ca2f938eSMichael Reed 	hdr.PageVersion = 0;
923ca2f938eSMichael Reed 	hdr.PageLength = 0;
924ca2f938eSMichael Reed 	hdr.PageNumber = 1;
925ca2f938eSMichael Reed 	hdr.PageType = MPI_CONFIG_PAGETYPE_FC_PORT;
926ca2f938eSMichael Reed 	cfg.cfghdr.hdr = &hdr;
927ca2f938eSMichael Reed 	cfg.physAddr = -1;
928ca2f938eSMichael Reed 	cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
929ca2f938eSMichael Reed 	cfg.dir = 0;
930ca2f938eSMichael Reed 	cfg.pageAddr = portnum;
931ca2f938eSMichael Reed 	cfg.timeout = 0;
932ca2f938eSMichael Reed 
933ca2f938eSMichael Reed 	if ((rc = mpt_config(ioc, &cfg)) != 0)
934ca2f938eSMichael Reed 		return rc;
935ca2f938eSMichael Reed 
936ca2f938eSMichael Reed 	if (hdr.PageLength == 0)
937ca2f938eSMichael Reed 		return -ENODEV;
938ca2f938eSMichael Reed 
939ca2f938eSMichael Reed start_over:
940ca2f938eSMichael Reed 
941ca2f938eSMichael Reed 	if (ioc->fc_data.fc_port_page1[portnum].data == NULL) {
942ca2f938eSMichael Reed 		data_sz = hdr.PageLength * 4;
943ca2f938eSMichael Reed 		if (data_sz < sizeof(FCPortPage1_t))
944ca2f938eSMichael Reed 			data_sz = sizeof(FCPortPage1_t);
945ca2f938eSMichael Reed 
9461897c5c7SChristophe JAILLET 		page1_alloc = dma_alloc_coherent(&ioc->pcidev->dev, data_sz,
9471897c5c7SChristophe JAILLET 						 &page1_dma, GFP_KERNEL);
948ca2f938eSMichael Reed 		if (!page1_alloc)
949ca2f938eSMichael Reed 			return -ENOMEM;
950ca2f938eSMichael Reed 	}
951ca2f938eSMichael Reed 	else {
952ca2f938eSMichael Reed 		page1_alloc = ioc->fc_data.fc_port_page1[portnum].data;
953ca2f938eSMichael Reed 		page1_dma = ioc->fc_data.fc_port_page1[portnum].dma;
954ca2f938eSMichael Reed 		data_sz = ioc->fc_data.fc_port_page1[portnum].pg_sz;
955ca2f938eSMichael Reed 		if (hdr.PageLength * 4 > data_sz) {
956ca2f938eSMichael Reed 			ioc->fc_data.fc_port_page1[portnum].data = NULL;
9571897c5c7SChristophe JAILLET 			dma_free_coherent(&ioc->pcidev->dev, data_sz,
958ca2f938eSMichael Reed 					  page1_alloc, page1_dma);
959ca2f938eSMichael Reed 			goto start_over;
960ca2f938eSMichael Reed 		}
961ca2f938eSMichael Reed 	}
962ca2f938eSMichael Reed 
963ca2f938eSMichael Reed 	cfg.physAddr = page1_dma;
964ca2f938eSMichael Reed 	cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
965ca2f938eSMichael Reed 
966ca2f938eSMichael Reed 	if ((rc = mpt_config(ioc, &cfg)) == 0) {
967ca2f938eSMichael Reed 		ioc->fc_data.fc_port_page1[portnum].data = page1_alloc;
968ca2f938eSMichael Reed 		ioc->fc_data.fc_port_page1[portnum].pg_sz = data_sz;
969ca2f938eSMichael Reed 		ioc->fc_data.fc_port_page1[portnum].dma = page1_dma;
970ca2f938eSMichael Reed 	}
971ca2f938eSMichael Reed 	else {
972ca2f938eSMichael Reed 		ioc->fc_data.fc_port_page1[portnum].data = NULL;
9731897c5c7SChristophe JAILLET 		dma_free_coherent(&ioc->pcidev->dev, data_sz, page1_alloc,
9741897c5c7SChristophe JAILLET 				  page1_dma);
975ca2f938eSMichael Reed 	}
976ca2f938eSMichael Reed 
977ca2f938eSMichael Reed 	return rc;
978ca2f938eSMichael Reed }
979ca2f938eSMichael Reed 
980ca2f938eSMichael Reed static void
mptfc_SetFcPortPage1_defaults(MPT_ADAPTER * ioc)981ca2f938eSMichael Reed mptfc_SetFcPortPage1_defaults(MPT_ADAPTER *ioc)
982ca2f938eSMichael Reed {
983ca2f938eSMichael Reed 	int		ii;
984ca2f938eSMichael Reed 	FCPortPage1_t	*pp1;
985ca2f938eSMichael Reed 
986ca2f938eSMichael Reed 	#define MPTFC_FW_DEVICE_TIMEOUT	(1)
987ca2f938eSMichael Reed 	#define MPTFC_FW_IO_PEND_TIMEOUT (1)
988ca2f938eSMichael Reed 	#define ON_FLAGS  (MPI_FCPORTPAGE1_FLAGS_IMMEDIATE_ERROR_REPLY)
989ca2f938eSMichael Reed 	#define OFF_FLAGS (MPI_FCPORTPAGE1_FLAGS_VERBOSE_RESCAN_EVENTS)
990ca2f938eSMichael Reed 
991ca2f938eSMichael Reed 	for (ii=0; ii<ioc->facts.NumberOfPorts; ii++) {
992ca2f938eSMichael Reed 		if (mptfc_GetFcPortPage1(ioc, ii) != 0)
993ca2f938eSMichael Reed 			continue;
994ca2f938eSMichael Reed 		pp1 = ioc->fc_data.fc_port_page1[ii].data;
995ca2f938eSMichael Reed 		if ((pp1->InitiatorDeviceTimeout == MPTFC_FW_DEVICE_TIMEOUT)
996ca2f938eSMichael Reed 		 && (pp1->InitiatorIoPendTimeout == MPTFC_FW_IO_PEND_TIMEOUT)
997ca2f938eSMichael Reed 		 && ((pp1->Flags & ON_FLAGS) == ON_FLAGS)
998ca2f938eSMichael Reed 		 && ((pp1->Flags & OFF_FLAGS) == 0))
999ca2f938eSMichael Reed 			continue;
1000ca2f938eSMichael Reed 		pp1->InitiatorDeviceTimeout = MPTFC_FW_DEVICE_TIMEOUT;
1001ca2f938eSMichael Reed 		pp1->InitiatorIoPendTimeout = MPTFC_FW_IO_PEND_TIMEOUT;
1002ca2f938eSMichael Reed 		pp1->Flags &= ~OFF_FLAGS;
1003ca2f938eSMichael Reed 		pp1->Flags |= ON_FLAGS;
1004ca2f938eSMichael Reed 		mptfc_WriteFcPortPage1(ioc, ii);
1005ca2f938eSMichael Reed 	}
1006ca2f938eSMichael Reed }
1007ca2f938eSMichael Reed 
1008ca2f938eSMichael Reed 
100905e8ec17SMichael Reed static void
mptfc_init_host_attr(MPT_ADAPTER * ioc,int portnum)101005e8ec17SMichael Reed mptfc_init_host_attr(MPT_ADAPTER *ioc,int portnum)
101105e8ec17SMichael Reed {
10125d947f2bSMichael Reed 	unsigned	class = 0;
10135d947f2bSMichael Reed 	unsigned	cos = 0;
10145d947f2bSMichael Reed 	unsigned	speed;
10155d947f2bSMichael Reed 	unsigned	port_type;
10165d947f2bSMichael Reed 	unsigned	port_state;
10175d947f2bSMichael Reed 	FCPortPage0_t	*pp0;
10185d947f2bSMichael Reed 	struct Scsi_Host *sh;
10195d947f2bSMichael Reed 	char		*sn;
102005e8ec17SMichael Reed 
102105e8ec17SMichael Reed 	/* don't know what to do as only one scsi (fc) host was allocated */
102205e8ec17SMichael Reed 	if (portnum != 0)
102305e8ec17SMichael Reed 		return;
102405e8ec17SMichael Reed 
10255d947f2bSMichael Reed 	pp0 = &ioc->fc_port_page0[portnum];
10265d947f2bSMichael Reed 	sh = ioc->sh;
10275d947f2bSMichael Reed 
10285d947f2bSMichael Reed 	sn = fc_host_symbolic_name(sh);
10295d947f2bSMichael Reed 	snprintf(sn, FC_SYMBOLIC_NAME_SIZE, "%s %s%08xh",
10305d947f2bSMichael Reed 	    ioc->prod_name,
10315d947f2bSMichael Reed 	    MPT_FW_REV_MAGIC_ID_STRING,
10325d947f2bSMichael Reed 	    ioc->facts.FWVersion.Word);
10335d947f2bSMichael Reed 
10345d947f2bSMichael Reed 	fc_host_tgtid_bind_type(sh) = FC_TGTID_BIND_BY_WWPN;
10355d947f2bSMichael Reed 
10365d947f2bSMichael Reed 	fc_host_maxframe_size(sh) = pp0->MaxFrameSize;
10375d947f2bSMichael Reed 
10385d947f2bSMichael Reed 	fc_host_node_name(sh) =
10395d947f2bSMichael Reed 	    	(u64)pp0->WWNN.High << 32 | (u64)pp0->WWNN.Low;
10405d947f2bSMichael Reed 
10415d947f2bSMichael Reed 	fc_host_port_name(sh) =
10425d947f2bSMichael Reed 	    	(u64)pp0->WWPN.High << 32 | (u64)pp0->WWPN.Low;
10435d947f2bSMichael Reed 
10445d947f2bSMichael Reed 	fc_host_port_id(sh) = pp0->PortIdentifier;
10455d947f2bSMichael Reed 
10465d947f2bSMichael Reed 	class = pp0->SupportedServiceClass;
104705e8ec17SMichael Reed 	if (class & MPI_FCPORTPAGE0_SUPPORT_CLASS_1)
104805e8ec17SMichael Reed 		cos |= FC_COS_CLASS1;
104905e8ec17SMichael Reed 	if (class & MPI_FCPORTPAGE0_SUPPORT_CLASS_2)
105005e8ec17SMichael Reed 		cos |= FC_COS_CLASS2;
105105e8ec17SMichael Reed 	if (class & MPI_FCPORTPAGE0_SUPPORT_CLASS_3)
105205e8ec17SMichael Reed 		cos |= FC_COS_CLASS3;
10535d947f2bSMichael Reed 	fc_host_supported_classes(sh) = cos;
105405e8ec17SMichael Reed 
10555d947f2bSMichael Reed 	if (pp0->CurrentSpeed == MPI_FCPORTPAGE0_CURRENT_SPEED_1GBIT)
10565d947f2bSMichael Reed 		speed = FC_PORTSPEED_1GBIT;
10575d947f2bSMichael Reed 	else if (pp0->CurrentSpeed == MPI_FCPORTPAGE0_CURRENT_SPEED_2GBIT)
10585d947f2bSMichael Reed 		speed = FC_PORTSPEED_2GBIT;
10595d947f2bSMichael Reed 	else if (pp0->CurrentSpeed == MPI_FCPORTPAGE0_CURRENT_SPEED_4GBIT)
10605d947f2bSMichael Reed 		speed = FC_PORTSPEED_4GBIT;
10615d947f2bSMichael Reed 	else if (pp0->CurrentSpeed == MPI_FCPORTPAGE0_CURRENT_SPEED_10GBIT)
10625d947f2bSMichael Reed 		speed = FC_PORTSPEED_10GBIT;
10635d947f2bSMichael Reed 	else
10645d947f2bSMichael Reed 		speed = FC_PORTSPEED_UNKNOWN;
10655d947f2bSMichael Reed 	fc_host_speed(sh) = speed;
106605e8ec17SMichael Reed 
10675d947f2bSMichael Reed 	speed = 0;
10685d947f2bSMichael Reed 	if (pp0->SupportedSpeeds & MPI_FCPORTPAGE0_SUPPORT_1GBIT_SPEED)
10695d947f2bSMichael Reed 		speed |= FC_PORTSPEED_1GBIT;
10705d947f2bSMichael Reed 	if (pp0->SupportedSpeeds & MPI_FCPORTPAGE0_SUPPORT_2GBIT_SPEED)
10715d947f2bSMichael Reed 		speed |= FC_PORTSPEED_2GBIT;
10725d947f2bSMichael Reed 	if (pp0->SupportedSpeeds & MPI_FCPORTPAGE0_SUPPORT_4GBIT_SPEED)
10735d947f2bSMichael Reed 		speed |= FC_PORTSPEED_4GBIT;
10745d947f2bSMichael Reed 	if (pp0->SupportedSpeeds & MPI_FCPORTPAGE0_SUPPORT_10GBIT_SPEED)
10755d947f2bSMichael Reed 		speed |= FC_PORTSPEED_10GBIT;
10765d947f2bSMichael Reed 	fc_host_supported_speeds(sh) = speed;
107705e8ec17SMichael Reed 
10785d947f2bSMichael Reed 	port_state = FC_PORTSTATE_UNKNOWN;
10795d947f2bSMichael Reed 	if (pp0->PortState == MPI_FCPORTPAGE0_PORTSTATE_ONLINE)
10805d947f2bSMichael Reed 		port_state = FC_PORTSTATE_ONLINE;
10815d947f2bSMichael Reed 	else if (pp0->PortState == MPI_FCPORTPAGE0_PORTSTATE_OFFLINE)
10825d947f2bSMichael Reed 		port_state = FC_PORTSTATE_LINKDOWN;
10835d947f2bSMichael Reed 	fc_host_port_state(sh) = port_state;
108405e8ec17SMichael Reed 
10855d947f2bSMichael Reed 	port_type = FC_PORTTYPE_UNKNOWN;
10865d947f2bSMichael Reed 	if (pp0->Flags & MPI_FCPORTPAGE0_FLAGS_ATTACH_POINT_TO_POINT)
10875d947f2bSMichael Reed 		port_type = FC_PORTTYPE_PTP;
10885d947f2bSMichael Reed 	else if (pp0->Flags & MPI_FCPORTPAGE0_FLAGS_ATTACH_PRIVATE_LOOP)
10895d947f2bSMichael Reed 		port_type = FC_PORTTYPE_LPORT;
10905d947f2bSMichael Reed 	else if (pp0->Flags & MPI_FCPORTPAGE0_FLAGS_ATTACH_PUBLIC_LOOP)
10915d947f2bSMichael Reed 		port_type = FC_PORTTYPE_NLPORT;
10925d947f2bSMichael Reed 	else if (pp0->Flags & MPI_FCPORTPAGE0_FLAGS_ATTACH_FABRIC_DIRECT)
10935d947f2bSMichael Reed 		port_type = FC_PORTTYPE_NPORT;
10945d947f2bSMichael Reed 	fc_host_port_type(sh) = port_type;
109505e8ec17SMichael Reed 
10965d947f2bSMichael Reed 	fc_host_fabric_name(sh) =
10975d947f2bSMichael Reed 	    (pp0->Flags & MPI_FCPORTPAGE0_FLAGS_FABRIC_WWN_VALID) ?
10985d947f2bSMichael Reed 		(u64) pp0->FabricWWNN.High << 32 | (u64) pp0->FabricWWPN.Low :
10995d947f2bSMichael Reed 		(u64)pp0->WWNN.High << 32 | (u64)pp0->WWNN.Low;
11005d947f2bSMichael Reed 
110105e8ec17SMichael Reed }
110205e8ec17SMichael Reed 
110305e8ec17SMichael Reed static void
mptfc_link_status_change(struct work_struct * work)1104eb5329f4SPrakash, Sathya mptfc_link_status_change(struct work_struct *work)
1105eb5329f4SPrakash, Sathya {
1106eb5329f4SPrakash, Sathya 	MPT_ADAPTER             *ioc =
1107eb5329f4SPrakash, Sathya 		container_of(work, MPT_ADAPTER, fc_rescan_work);
1108eb5329f4SPrakash, Sathya 	int ii;
1109eb5329f4SPrakash, Sathya 
1110eb5329f4SPrakash, Sathya 	for (ii=0; ii < ioc->facts.NumberOfPorts; ii++)
1111eb5329f4SPrakash, Sathya 		(void) mptfc_GetFcPortPage0(ioc, ii);
1112eb5329f4SPrakash, Sathya 
1113eb5329f4SPrakash, Sathya }
1114eb5329f4SPrakash, Sathya 
1115eb5329f4SPrakash, Sathya static void
mptfc_setup_reset(struct work_struct * work)1116c4028958SDavid Howells mptfc_setup_reset(struct work_struct *work)
1117419835e2SMichael Reed {
1118c4028958SDavid Howells 	MPT_ADAPTER		*ioc =
1119c4028958SDavid Howells 		container_of(work, MPT_ADAPTER, fc_setup_reset_work);
1120419835e2SMichael Reed 	u64			pn;
1121419835e2SMichael Reed 	struct mptfc_rport_info *ri;
112208f5c5c2SKashyap, Desai 	struct scsi_target      *starget;
112308f5c5c2SKashyap, Desai 	VirtTarget              *vtarget;
1124419835e2SMichael Reed 
1125419835e2SMichael Reed 	/* reset about to happen, delete (block) all rports */
1126419835e2SMichael Reed 	list_for_each_entry(ri, &ioc->fc_rports, list) {
1127419835e2SMichael Reed 		if (ri->flags & MPT_RPORT_INFO_FLAGS_REGISTERED) {
1128419835e2SMichael Reed 			ri->flags &= ~MPT_RPORT_INFO_FLAGS_REGISTERED;
1129419835e2SMichael Reed 			fc_remote_port_delete(ri->rport);	/* won't sleep */
1130419835e2SMichael Reed 			ri->rport = NULL;
113108f5c5c2SKashyap, Desai 			starget = ri->starget;
113208f5c5c2SKashyap, Desai 			if (starget) {
113308f5c5c2SKashyap, Desai 				vtarget = starget->hostdata;
113408f5c5c2SKashyap, Desai 				if (vtarget)
113508f5c5c2SKashyap, Desai 					vtarget->deleted = 1;
113608f5c5c2SKashyap, Desai 			}
1137419835e2SMichael Reed 
1138419835e2SMichael Reed 			pn = (u64)ri->pg0.WWPN.High << 32 |
1139419835e2SMichael Reed 			     (u64)ri->pg0.WWPN.Low;
1140d6ecdd63SPrakash, Sathya 			dfcprintk (ioc, printk(MYIOC_s_DEBUG_FMT
1141419835e2SMichael Reed 				"mptfc_setup_reset.%d: %llx deleted\n",
1142419835e2SMichael Reed 				ioc->name,
1143419835e2SMichael Reed 				ioc->sh->host_no,
1144419835e2SMichael Reed 				(unsigned long long)pn));
1145419835e2SMichael Reed 		}
1146419835e2SMichael Reed 	}
1147419835e2SMichael Reed }
1148419835e2SMichael Reed 
1149419835e2SMichael Reed static void
mptfc_rescan_devices(struct work_struct * work)1150c4028958SDavid Howells mptfc_rescan_devices(struct work_struct *work)
115105e8ec17SMichael Reed {
1152c4028958SDavid Howells 	MPT_ADAPTER		*ioc =
1153c4028958SDavid Howells 		container_of(work, MPT_ADAPTER, fc_rescan_work);
115405e8ec17SMichael Reed 	int			ii;
115565207fedSMoore, Eric 	u64			pn;
115605e8ec17SMichael Reed 	struct mptfc_rport_info *ri;
115708f5c5c2SKashyap, Desai 	struct scsi_target      *starget;
115808f5c5c2SKashyap, Desai 	VirtTarget              *vtarget;
115905e8ec17SMichael Reed 
116005e8ec17SMichael Reed 	/* start by tagging all ports as missing */
116105e8ec17SMichael Reed 	list_for_each_entry(ri, &ioc->fc_rports, list) {
116205e8ec17SMichael Reed 		if (ri->flags & MPT_RPORT_INFO_FLAGS_REGISTERED) {
116305e8ec17SMichael Reed 			ri->flags |= MPT_RPORT_INFO_FLAGS_MISSING;
116405e8ec17SMichael Reed 		}
116505e8ec17SMichael Reed 	}
116605e8ec17SMichael Reed 
116705e8ec17SMichael Reed 	/*
116805e8ec17SMichael Reed 	 * now rescan devices known to adapter,
116905e8ec17SMichael Reed 	 * will reregister existing rports
117005e8ec17SMichael Reed 	 */
117105e8ec17SMichael Reed 	for (ii=0; ii < ioc->facts.NumberOfPorts; ii++) {
117280d3ac77SMichael Reed 		(void) mptfc_GetFcPortPage0(ioc, ii);
117305e8ec17SMichael Reed 		mptfc_init_host_attr(ioc, ii);	/* refresh */
117405e8ec17SMichael Reed 		mptfc_GetFcDevPage0(ioc, ii, mptfc_register_dev);
117505e8ec17SMichael Reed 	}
117605e8ec17SMichael Reed 
117705e8ec17SMichael Reed 	/* delete devices still missing */
117805e8ec17SMichael Reed 	list_for_each_entry(ri, &ioc->fc_rports, list) {
117905e8ec17SMichael Reed 		/* if newly missing, delete it */
118065207fedSMoore, Eric 		if (ri->flags & MPT_RPORT_INFO_FLAGS_MISSING) {
118105e8ec17SMichael Reed 
118205e8ec17SMichael Reed 			ri->flags &= ~(MPT_RPORT_INFO_FLAGS_REGISTERED|
118305e8ec17SMichael Reed 				       MPT_RPORT_INFO_FLAGS_MISSING);
118465207fedSMoore, Eric 			fc_remote_port_delete(ri->rport);	/* won't sleep */
11853bc7bf1dSMichael Reed 			ri->rport = NULL;
118608f5c5c2SKashyap, Desai 			starget = ri->starget;
118708f5c5c2SKashyap, Desai 			if (starget) {
118808f5c5c2SKashyap, Desai 				vtarget = starget->hostdata;
118908f5c5c2SKashyap, Desai 				if (vtarget)
119008f5c5c2SKashyap, Desai 					vtarget->deleted = 1;
119108f5c5c2SKashyap, Desai 			}
119265207fedSMoore, Eric 
119365207fedSMoore, Eric 			pn = (u64)ri->pg0.WWPN.High << 32 |
119465207fedSMoore, Eric 			     (u64)ri->pg0.WWPN.Low;
1195d6ecdd63SPrakash, Sathya 			dfcprintk (ioc, printk(MYIOC_s_DEBUG_FMT
11963bc7bf1dSMichael Reed 				"mptfc_rescan.%d: %llx deleted\n",
11973bc7bf1dSMichael Reed 				ioc->name,
11983bc7bf1dSMichael Reed 				ioc->sh->host_no,
119965207fedSMoore, Eric 				(unsigned long long)pn));
120005e8ec17SMichael Reed 		}
120105e8ec17SMichael Reed 	}
120205e8ec17SMichael Reed }
120305e8ec17SMichael Reed 
12042496af39SMoore, Eric Dean  static int
mptfc_probe(struct pci_dev * pdev,const struct pci_device_id * id)12052496af39SMoore, Eric Dean  mptfc_probe(struct pci_dev *pdev, const struct pci_device_id *id)
12062496af39SMoore, Eric Dean  {
12072496af39SMoore, Eric Dean  	struct Scsi_Host	*sh;
12082496af39SMoore, Eric Dean  	MPT_SCSI_HOST		*hd;
12092496af39SMoore, Eric Dean  	MPT_ADAPTER 		*ioc;
12102496af39SMoore, Eric Dean  	unsigned long		 flags;
12111ca00bb7SChristoph Hellwig 	int			 ii;
12122496af39SMoore, Eric Dean  	int			 numSGE = 0;
12132496af39SMoore, Eric Dean  	int			 scale;
12142496af39SMoore, Eric Dean  	int			 ioc_cap;
12152496af39SMoore, Eric Dean  	int			error=0;
12162496af39SMoore, Eric Dean  	int			r;
12172496af39SMoore, Eric Dean  
12182496af39SMoore, Eric Dean  	if ((r = mpt_attach(pdev,id)) != 0)
12192496af39SMoore, Eric Dean  		return r;
12202496af39SMoore, Eric Dean  
12212496af39SMoore, Eric Dean  	ioc = pci_get_drvdata(pdev);
1222d335cc38SMoore, Eric Dean  	ioc->DoneCtx = mptfcDoneCtx;
1223d335cc38SMoore, Eric Dean  	ioc->TaskCtx = mptfcTaskCtx;
1224d335cc38SMoore, Eric Dean  	ioc->InternalCtx = mptfcInternalCtx;
12252496af39SMoore, Eric Dean  
12262496af39SMoore, Eric Dean  	/*  Added sanity check on readiness of the MPT adapter.
12272496af39SMoore, Eric Dean  	 */
12282496af39SMoore, Eric Dean  	if (ioc->last_state != MPI_IOC_STATE_OPERATIONAL) {
12292496af39SMoore, Eric Dean  		printk(MYIOC_s_WARN_FMT
12302496af39SMoore, Eric Dean  		  "Skipping because it's not operational!\n",
12312496af39SMoore, Eric Dean  		  ioc->name);
12327acec1e7SMoore, Eric Dean 		error = -ENODEV;
12337acec1e7SMoore, Eric Dean 		goto out_mptfc_probe;
12342496af39SMoore, Eric Dean  	}
12352496af39SMoore, Eric Dean  
12362496af39SMoore, Eric Dean  	if (!ioc->active) {
12372496af39SMoore, Eric Dean  		printk(MYIOC_s_WARN_FMT "Skipping because it's disabled!\n",
12382496af39SMoore, Eric Dean  		  ioc->name);
12397acec1e7SMoore, Eric Dean 		error = -ENODEV;
12407acec1e7SMoore, Eric Dean 		goto out_mptfc_probe;
12412496af39SMoore, Eric Dean  	}
12422496af39SMoore, Eric Dean  
12432496af39SMoore, Eric Dean  	/*  Sanity check - ensure at least 1 port is INITIATOR capable
12442496af39SMoore, Eric Dean  	 */
12452496af39SMoore, Eric Dean  	ioc_cap = 0;
12462496af39SMoore, Eric Dean  	for (ii=0; ii < ioc->facts.NumberOfPorts; ii++) {
12472496af39SMoore, Eric Dean  		if (ioc->pfacts[ii].ProtocolFlags &
12482496af39SMoore, Eric Dean  		    MPI_PORTFACTS_PROTOCOL_INITIATOR)
12492496af39SMoore, Eric Dean  			ioc_cap ++;
12502496af39SMoore, Eric Dean  	}
12512496af39SMoore, Eric Dean  
12522496af39SMoore, Eric Dean  	if (!ioc_cap) {
12532496af39SMoore, Eric Dean  		printk(MYIOC_s_WARN_FMT
12542496af39SMoore, Eric Dean  			"Skipping ioc=%p because SCSI Initiator mode is NOT enabled!\n",
12552496af39SMoore, Eric Dean  			ioc->name, ioc);
1256793955f5SEric Moore 		return 0;
12572496af39SMoore, Eric Dean  	}
12582496af39SMoore, Eric Dean  
12592496af39SMoore, Eric Dean  	sh = scsi_host_alloc(&mptfc_driver_template, sizeof(MPT_SCSI_HOST));
12602496af39SMoore, Eric Dean  
12612496af39SMoore, Eric Dean  	if (!sh) {
12622496af39SMoore, Eric Dean  		printk(MYIOC_s_WARN_FMT
12632496af39SMoore, Eric Dean  			"Unable to register controller with SCSI subsystem\n",
12642496af39SMoore, Eric Dean  			ioc->name);
12657acec1e7SMoore, Eric Dean 		error = -1;
12667acec1e7SMoore, Eric Dean 		goto out_mptfc_probe;
12672496af39SMoore, Eric Dean          }
12682496af39SMoore, Eric Dean  
126980d3ac77SMichael Reed 	spin_lock_init(&ioc->fc_rescan_work_lock);
1270c4028958SDavid Howells 	INIT_WORK(&ioc->fc_rescan_work, mptfc_rescan_devices);
1271c4028958SDavid Howells 	INIT_WORK(&ioc->fc_setup_reset_work, mptfc_setup_reset);
1272eb5329f4SPrakash, Sathya 	INIT_WORK(&ioc->fc_lsc_work, mptfc_link_status_change);
127305e8ec17SMichael Reed 
12742496af39SMoore, Eric Dean  	spin_lock_irqsave(&ioc->FreeQlock, flags);
12752496af39SMoore, Eric Dean  
12762496af39SMoore, Eric Dean  	/* Attach the SCSI Host to the IOC structure
12772496af39SMoore, Eric Dean  	 */
12782496af39SMoore, Eric Dean  	ioc->sh = sh;
12792496af39SMoore, Eric Dean  
12802496af39SMoore, Eric Dean  	sh->io_port = 0;
12812496af39SMoore, Eric Dean  	sh->n_io_port = 0;
12822496af39SMoore, Eric Dean  	sh->irq = 0;
12832496af39SMoore, Eric Dean  
12842496af39SMoore, Eric Dean  	/* set 16 byte cdb's */
12852496af39SMoore, Eric Dean  	sh->max_cmd_len = 16;
12862496af39SMoore, Eric Dean  
1287793955f5SEric Moore 	sh->max_id = ioc->pfacts->MaxDevices;
1288793955f5SEric Moore 	sh->max_lun = max_lun;
12892496af39SMoore, Eric Dean  
12902496af39SMoore, Eric Dean  	/* Required entry.
12912496af39SMoore, Eric Dean  	 */
12922496af39SMoore, Eric Dean  	sh->unique_id = ioc->id;
12932496af39SMoore, Eric Dean  
12942496af39SMoore, Eric Dean  	/* Verify that we won't exceed the maximum
12952496af39SMoore, Eric Dean  	 * number of chain buffers
12962496af39SMoore, Eric Dean  	 * We can optimize:  ZZ = req_sz/sizeof(SGE)
12972496af39SMoore, Eric Dean  	 * For 32bit SGE's:
12982496af39SMoore, Eric Dean  	 *  numSGE = 1 + (ZZ-1)*(maxChain -1) + ZZ
12992496af39SMoore, Eric Dean  	 *               + (req_sz - 64)/sizeof(SGE)
13002496af39SMoore, Eric Dean  	 * A slightly different algorithm is required for
13012496af39SMoore, Eric Dean  	 * 64bit SGEs.
13022496af39SMoore, Eric Dean  	 */
130314d0f0b0SKashyap, Desai 	scale = ioc->req_sz/ioc->SGE_size;
130414d0f0b0SKashyap, Desai 	if (ioc->sg_addr_size == sizeof(u64)) {
13052496af39SMoore, Eric Dean  		numSGE = (scale - 1) *
13062496af39SMoore, Eric Dean  		  (ioc->facts.MaxChainDepth-1) + scale +
130714d0f0b0SKashyap, Desai 		  (ioc->req_sz - 60) / ioc->SGE_size;
13082496af39SMoore, Eric Dean  	} else {
13092496af39SMoore, Eric Dean  		numSGE = 1 + (scale - 1) *
13102496af39SMoore, Eric Dean  		  (ioc->facts.MaxChainDepth-1) + scale +
131114d0f0b0SKashyap, Desai 		  (ioc->req_sz - 64) / ioc->SGE_size;
13122496af39SMoore, Eric Dean  	}
13132496af39SMoore, Eric Dean  
13142496af39SMoore, Eric Dean  	if (numSGE < sh->sg_tablesize) {
13152496af39SMoore, Eric Dean  		/* Reset this value */
1316d6ecdd63SPrakash, Sathya 		dprintk(ioc, printk(MYIOC_s_DEBUG_FMT
13172496af39SMoore, Eric Dean  		  "Resetting sg_tablesize to %d from %d\n",
13182496af39SMoore, Eric Dean  		  ioc->name, numSGE, sh->sg_tablesize));
13192496af39SMoore, Eric Dean  		sh->sg_tablesize = numSGE;
13202496af39SMoore, Eric Dean  	}
13212496af39SMoore, Eric Dean  
13222496af39SMoore, Eric Dean  	spin_unlock_irqrestore(&ioc->FreeQlock, flags);
13232496af39SMoore, Eric Dean  
1324e7eae9f6SEric Moore 	hd = shost_priv(sh);
13252496af39SMoore, Eric Dean  	hd->ioc = ioc;
13262496af39SMoore, Eric Dean  
13272496af39SMoore, Eric Dean  	/* SCSI needs scsi_cmnd lookup table!
13282496af39SMoore, Eric Dean  	 * (with size equal to req_depth*PtrSz!)
13292496af39SMoore, Eric Dean  	 */
133050838500SJia-Ju Bai 	ioc->ScsiLookup = kcalloc(ioc->req_depth, sizeof(void *), GFP_KERNEL);
1331e8206381SEric Moore 	if (!ioc->ScsiLookup) {
13322496af39SMoore, Eric Dean  		error = -ENOMEM;
13337acec1e7SMoore, Eric Dean 		goto out_mptfc_probe;
13342496af39SMoore, Eric Dean  	}
1335e8206381SEric Moore 	spin_lock_init(&ioc->scsi_lookup_lock);
13362496af39SMoore, Eric Dean  
1337d6ecdd63SPrakash, Sathya 	dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "ScsiLookup @ %p\n",
1338e8206381SEric Moore 		 ioc->name, ioc->ScsiLookup));
13392496af39SMoore, Eric Dean  
13402496af39SMoore, Eric Dean  	hd->last_queue_full = 0;
13412496af39SMoore, Eric Dean  
134205e8ec17SMichael Reed 	sh->transportt = mptfc_transport_template;
13432496af39SMoore, Eric Dean  	error = scsi_add_host (sh, &ioc->pcidev->dev);
13442496af39SMoore, Eric Dean  	if(error) {
134529dd3609SEric Moore 		dprintk(ioc, printk(MYIOC_s_ERR_FMT
134629dd3609SEric Moore 		  "scsi_add_host failed\n", ioc->name));
13477acec1e7SMoore, Eric Dean 		goto out_mptfc_probe;
13482496af39SMoore, Eric Dean  	}
13492496af39SMoore, Eric Dean  
135065207fedSMoore, Eric 	/* initialize workqueue */
135165207fedSMoore, Eric 
1352*dec52397SBart Van Assche 	ioc->fc_rescan_work_q = alloc_ordered_workqueue(
1353*dec52397SBart Van Assche 		"mptfc_wq_%d", WQ_MEM_RECLAIM, sh->host_no);
1354c08b3f9aSWei Yongjun 	if (!ioc->fc_rescan_work_q) {
1355c08b3f9aSWei Yongjun 		error = -ENOMEM;
1356cfd2aff7SHannes Reinecke 		goto out_mptfc_host;
1357c08b3f9aSWei Yongjun 	}
135865207fedSMoore, Eric 
135965207fedSMoore, Eric 	/*
136080d3ac77SMichael Reed 	 *  Pre-fetch FC port WWN and stuff...
136180d3ac77SMichael Reed 	 *  (FCPortPage0_t stuff)
136280d3ac77SMichael Reed 	 */
136380d3ac77SMichael Reed 	for (ii=0; ii < ioc->facts.NumberOfPorts; ii++) {
136480d3ac77SMichael Reed 		(void) mptfc_GetFcPortPage0(ioc, ii);
136580d3ac77SMichael Reed 	}
1366ca2f938eSMichael Reed 	mptfc_SetFcPortPage1_defaults(ioc);
136780d3ac77SMichael Reed 
136880d3ac77SMichael Reed 	/*
136965207fedSMoore, Eric 	 * scan for rports -
137065207fedSMoore, Eric 	 *	by doing it via the workqueue, some locking is eliminated
137165207fedSMoore, Eric 	 */
137265207fedSMoore, Eric 
137365207fedSMoore, Eric 	queue_work(ioc->fc_rescan_work_q, &ioc->fc_rescan_work);
137465207fedSMoore, Eric 	flush_workqueue(ioc->fc_rescan_work_q);
137505e8ec17SMichael Reed 
13762496af39SMoore, Eric Dean  	return 0;
13772496af39SMoore, Eric Dean  
1378cfd2aff7SHannes Reinecke out_mptfc_host:
1379cfd2aff7SHannes Reinecke 	scsi_remove_host(sh);
1380cfd2aff7SHannes Reinecke 
13817acec1e7SMoore, Eric Dean out_mptfc_probe:
13822496af39SMoore, Eric Dean  
13832496af39SMoore, Eric Dean  	mptscsih_remove(pdev);
13842496af39SMoore, Eric Dean  	return error;
13852496af39SMoore, Eric Dean  }
13862496af39SMoore, Eric Dean  
13872496af39SMoore, Eric Dean  static struct pci_driver mptfc_driver = {
13882496af39SMoore, Eric Dean  	.name		= "mptfc",
13892496af39SMoore, Eric Dean  	.id_table	= mptfc_pci_table,
13902496af39SMoore, Eric Dean  	.probe		= mptfc_probe,
139147b1ea75SGreg Kroah-Hartman 	.remove		= mptfc_remove,
13922496af39SMoore, Eric Dean  	.shutdown	= mptscsih_shutdown,
13932496af39SMoore, Eric Dean  #ifdef CONFIG_PM
13942496af39SMoore, Eric Dean  	.suspend	= mptscsih_suspend,
13952496af39SMoore, Eric Dean  	.resume		= mptscsih_resume,
13962496af39SMoore, Eric Dean  #endif
13972496af39SMoore, Eric Dean  };
13982496af39SMoore, Eric Dean  
139980d3ac77SMichael Reed static int
mptfc_event_process(MPT_ADAPTER * ioc,EventNotificationReply_t * pEvReply)140080d3ac77SMichael Reed mptfc_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *pEvReply)
140180d3ac77SMichael Reed {
140280d3ac77SMichael Reed 	u8 event = le32_to_cpu(pEvReply->Event) & 0xFF;
140380d3ac77SMichael Reed 	unsigned long flags;
140480d3ac77SMichael Reed 	int rc=1;
140580d3ac77SMichael Reed 
1406ffb7fef3SKashyap, Desai 	if (ioc->bus_type != FC)
1407ffb7fef3SKashyap, Desai 		return 0;
1408ffb7fef3SKashyap, Desai 
1409d6ecdd63SPrakash, Sathya 	devtverboseprintk(ioc, printk(MYIOC_s_DEBUG_FMT "MPT event (=%02Xh) routed to SCSI host driver!\n",
141080d3ac77SMichael Reed 			ioc->name, event));
141180d3ac77SMichael Reed 
1412be7fc734SColin Ian King 	if (ioc->sh == NULL || shost_priv(ioc->sh) == NULL)
141380d3ac77SMichael Reed 		return 1;
141480d3ac77SMichael Reed 
141580d3ac77SMichael Reed 	switch (event) {
141680d3ac77SMichael Reed 	case MPI_EVENT_RESCAN:
141780d3ac77SMichael Reed 		spin_lock_irqsave(&ioc->fc_rescan_work_lock, flags);
141880d3ac77SMichael Reed 		if (ioc->fc_rescan_work_q) {
141980d3ac77SMichael Reed 			queue_work(ioc->fc_rescan_work_q,
142080d3ac77SMichael Reed 				   &ioc->fc_rescan_work);
142180d3ac77SMichael Reed 		}
142280d3ac77SMichael Reed 		spin_unlock_irqrestore(&ioc->fc_rescan_work_lock, flags);
142380d3ac77SMichael Reed 		break;
1424eb5329f4SPrakash, Sathya 	case MPI_EVENT_LINK_STATUS_CHANGE:
1425eb5329f4SPrakash, Sathya 		spin_lock_irqsave(&ioc->fc_rescan_work_lock, flags);
1426eb5329f4SPrakash, Sathya 		if (ioc->fc_rescan_work_q) {
1427eb5329f4SPrakash, Sathya 			queue_work(ioc->fc_rescan_work_q,
1428eb5329f4SPrakash, Sathya 				   &ioc->fc_lsc_work);
1429eb5329f4SPrakash, Sathya 		}
1430eb5329f4SPrakash, Sathya 		spin_unlock_irqrestore(&ioc->fc_rescan_work_lock, flags);
1431eb5329f4SPrakash, Sathya 		break;
143280d3ac77SMichael Reed 	default:
143380d3ac77SMichael Reed 		rc = mptscsih_event_process(ioc,pEvReply);
143480d3ac77SMichael Reed 		break;
143580d3ac77SMichael Reed 	}
143680d3ac77SMichael Reed 	return rc;
143780d3ac77SMichael Reed }
143880d3ac77SMichael Reed 
143980d3ac77SMichael Reed static int
mptfc_ioc_reset(MPT_ADAPTER * ioc,int reset_phase)144080d3ac77SMichael Reed mptfc_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
144180d3ac77SMichael Reed {
144280d3ac77SMichael Reed 	int		rc;
144380d3ac77SMichael Reed 	unsigned long	flags;
144480d3ac77SMichael Reed 
144580d3ac77SMichael Reed 	rc = mptscsih_ioc_reset(ioc,reset_phase);
1446ffb7fef3SKashyap, Desai 	if ((ioc->bus_type != FC) || (!rc))
144780d3ac77SMichael Reed 		return rc;
144880d3ac77SMichael Reed 
144980d3ac77SMichael Reed 
1450d6ecdd63SPrakash, Sathya 	dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
1451d6ecdd63SPrakash, Sathya 		": IOC %s_reset routed to FC host driver!\n",ioc->name,
145280d3ac77SMichael Reed 		reset_phase==MPT_IOC_SETUP_RESET ? "setup" : (
145380d3ac77SMichael Reed 		reset_phase==MPT_IOC_PRE_RESET ? "pre" : "post")));
145480d3ac77SMichael Reed 
145580d3ac77SMichael Reed 	if (reset_phase == MPT_IOC_SETUP_RESET) {
1456419835e2SMichael Reed 		spin_lock_irqsave(&ioc->fc_rescan_work_lock, flags);
1457419835e2SMichael Reed 		if (ioc->fc_rescan_work_q) {
1458419835e2SMichael Reed 			queue_work(ioc->fc_rescan_work_q,
1459419835e2SMichael Reed 				   &ioc->fc_setup_reset_work);
1460419835e2SMichael Reed 		}
1461419835e2SMichael Reed 		spin_unlock_irqrestore(&ioc->fc_rescan_work_lock, flags);
146280d3ac77SMichael Reed 	}
146380d3ac77SMichael Reed 
146480d3ac77SMichael Reed 	else if (reset_phase == MPT_IOC_PRE_RESET) {
146580d3ac77SMichael Reed 	}
146680d3ac77SMichael Reed 
146780d3ac77SMichael Reed 	else {	/* MPT_IOC_POST_RESET */
1468ca2f938eSMichael Reed 		mptfc_SetFcPortPage1_defaults(ioc);
146980d3ac77SMichael Reed 		spin_lock_irqsave(&ioc->fc_rescan_work_lock, flags);
147080d3ac77SMichael Reed 		if (ioc->fc_rescan_work_q) {
147180d3ac77SMichael Reed 			queue_work(ioc->fc_rescan_work_q,
147280d3ac77SMichael Reed 				   &ioc->fc_rescan_work);
147380d3ac77SMichael Reed 		}
147480d3ac77SMichael Reed 		spin_unlock_irqrestore(&ioc->fc_rescan_work_lock, flags);
147580d3ac77SMichael Reed 	}
147680d3ac77SMichael Reed 	return 1;
147780d3ac77SMichael Reed }
147880d3ac77SMichael Reed 
14792496af39SMoore, Eric Dean  /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
14802496af39SMoore, Eric Dean  /**
1481d9489fb6SRandy Dunlap  *	mptfc_init - Register MPT adapter(s) as SCSI host(s) with SCSI mid-layer.
14822496af39SMoore, Eric Dean   *
14832496af39SMoore, Eric Dean   *	Returns 0 for success, non-zero for failure.
14842496af39SMoore, Eric Dean   */
14852496af39SMoore, Eric Dean  static int __init
mptfc_init(void)14862496af39SMoore, Eric Dean  mptfc_init(void)
14872496af39SMoore, Eric Dean  {
148805e8ec17SMichael Reed 	int error;
14892496af39SMoore, Eric Dean  
14902496af39SMoore, Eric Dean  	show_mptmod_ver(my_NAME, my_VERSION);
14912496af39SMoore, Eric Dean  
1492ca2f938eSMichael Reed 	/* sanity check module parameters */
1493ca2f938eSMichael Reed 	if (mptfc_dev_loss_tmo <= 0)
149405e8ec17SMichael Reed 		mptfc_dev_loss_tmo = MPTFC_DEV_LOSS_TMO;
149505e8ec17SMichael Reed 
149605e8ec17SMichael Reed 	mptfc_transport_template =
149705e8ec17SMichael Reed 		fc_attach_transport(&mptfc_transport_functions);
149805e8ec17SMichael Reed 
149905e8ec17SMichael Reed 	if (!mptfc_transport_template)
150005e8ec17SMichael Reed 		return -ENODEV;
150105e8ec17SMichael Reed 
1502213aaca3SKashyap, Desai 	mptfcDoneCtx = mpt_register(mptscsih_io_done, MPTFC_DRIVER,
1503213aaca3SKashyap, Desai 	    "mptscsih_scandv_complete");
1504213aaca3SKashyap, Desai 	mptfcTaskCtx = mpt_register(mptscsih_taskmgmt_complete, MPTFC_DRIVER,
1505213aaca3SKashyap, Desai 	    "mptscsih_scandv_complete");
1506213aaca3SKashyap, Desai 	mptfcInternalCtx = mpt_register(mptscsih_scandv_complete, MPTFC_DRIVER,
1507213aaca3SKashyap, Desai 	    "mptscsih_scandv_complete");
15082496af39SMoore, Eric Dean  
1509d6ecdd63SPrakash, Sathya 	mpt_event_register(mptfcDoneCtx, mptfc_event_process);
1510d6ecdd63SPrakash, Sathya 	mpt_reset_register(mptfcDoneCtx, mptfc_ioc_reset);
15112496af39SMoore, Eric Dean  
151205e8ec17SMichael Reed 	error = pci_register_driver(&mptfc_driver);
15133bc7bf1dSMichael Reed 	if (error)
151405e8ec17SMichael Reed 		fc_release_transport(mptfc_transport_template);
151505e8ec17SMichael Reed 
151605e8ec17SMichael Reed 	return error;
151705e8ec17SMichael Reed }
151805e8ec17SMichael Reed 
151905e8ec17SMichael Reed /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
152005e8ec17SMichael Reed /**
1521d9489fb6SRandy Dunlap  *	mptfc_remove - Remove fc infrastructure for devices
152205e8ec17SMichael Reed  *	@pdev: Pointer to pci_dev structure
152305e8ec17SMichael Reed  *
152405e8ec17SMichael Reed  */
mptfc_remove(struct pci_dev * pdev)152547b1ea75SGreg Kroah-Hartman static void mptfc_remove(struct pci_dev *pdev)
152605e8ec17SMichael Reed {
152705e8ec17SMichael Reed 	MPT_ADAPTER		*ioc = pci_get_drvdata(pdev);
152805e8ec17SMichael Reed 	struct mptfc_rport_info	*p, *n;
152965207fedSMoore, Eric 	struct workqueue_struct *work_q;
153065207fedSMoore, Eric 	unsigned long		flags;
1531ca2f938eSMichael Reed 	int			ii;
153265207fedSMoore, Eric 
153365207fedSMoore, Eric 	/* destroy workqueue */
153465207fedSMoore, Eric 	if ((work_q=ioc->fc_rescan_work_q)) {
153565207fedSMoore, Eric 		spin_lock_irqsave(&ioc->fc_rescan_work_lock, flags);
153665207fedSMoore, Eric 		ioc->fc_rescan_work_q = NULL;
153765207fedSMoore, Eric 		spin_unlock_irqrestore(&ioc->fc_rescan_work_lock, flags);
153865207fedSMoore, Eric 		destroy_workqueue(work_q);
153965207fedSMoore, Eric 	}
154005e8ec17SMichael Reed 
154105e8ec17SMichael Reed 	fc_remove_host(ioc->sh);
154205e8ec17SMichael Reed 
154305e8ec17SMichael Reed 	list_for_each_entry_safe(p, n, &ioc->fc_rports, list) {
154405e8ec17SMichael Reed 		list_del(&p->list);
154505e8ec17SMichael Reed 		kfree(p);
154605e8ec17SMichael Reed 	}
154705e8ec17SMichael Reed 
1548ca2f938eSMichael Reed 	for (ii=0; ii<ioc->facts.NumberOfPorts; ii++) {
1549ca2f938eSMichael Reed 		if (ioc->fc_data.fc_port_page1[ii].data) {
15501897c5c7SChristophe JAILLET 			dma_free_coherent(&ioc->pcidev->dev,
1551ca2f938eSMichael Reed 					  ioc->fc_data.fc_port_page1[ii].pg_sz,
15521897c5c7SChristophe JAILLET 					  ioc->fc_data.fc_port_page1[ii].data,
1553ca2f938eSMichael Reed 					  ioc->fc_data.fc_port_page1[ii].dma);
1554ca2f938eSMichael Reed 			ioc->fc_data.fc_port_page1[ii].data = NULL;
1555ca2f938eSMichael Reed 		}
1556ca2f938eSMichael Reed 	}
1557ca2f938eSMichael Reed 
1558cfd2aff7SHannes Reinecke 	scsi_remove_host(ioc->sh);
1559cfd2aff7SHannes Reinecke 
156005e8ec17SMichael Reed 	mptscsih_remove(pdev);
15612496af39SMoore, Eric Dean  }
15622496af39SMoore, Eric Dean  
15632496af39SMoore, Eric Dean  /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
15642496af39SMoore, Eric Dean  /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
15652496af39SMoore, Eric Dean  /**
15662496af39SMoore, Eric Dean   *	mptfc_exit - Unregisters MPT adapter(s)
15672496af39SMoore, Eric Dean   *
15682496af39SMoore, Eric Dean   */
15692496af39SMoore, Eric Dean  static void __exit
mptfc_exit(void)15702496af39SMoore, Eric Dean  mptfc_exit(void)
15712496af39SMoore, Eric Dean  {
15722496af39SMoore, Eric Dean  	pci_unregister_driver(&mptfc_driver);
157305e8ec17SMichael Reed 	fc_release_transport(mptfc_transport_template);
15742496af39SMoore, Eric Dean  
15752496af39SMoore, Eric Dean  	mpt_reset_deregister(mptfcDoneCtx);
15762496af39SMoore, Eric Dean  	mpt_event_deregister(mptfcDoneCtx);
15772496af39SMoore, Eric Dean  
15782496af39SMoore, Eric Dean  	mpt_deregister(mptfcInternalCtx);
15792496af39SMoore, Eric Dean  	mpt_deregister(mptfcTaskCtx);
15802496af39SMoore, Eric Dean  	mpt_deregister(mptfcDoneCtx);
15812496af39SMoore, Eric Dean  }
15822496af39SMoore, Eric Dean  
15832496af39SMoore, Eric Dean  module_init(mptfc_init);
15842496af39SMoore, Eric Dean  module_exit(mptfc_exit);
1585