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 34505e8ec17SMichael Reed return 0; 34605e8ec17SMichael Reed } 34705e8ec17SMichael Reed 34805e8ec17SMichael Reed static void 34905e8ec17SMichael Reed mptfc_register_dev(MPT_ADAPTER *ioc, int channel, FCDevicePage0_t *pg0) 35005e8ec17SMichael Reed { 35105e8ec17SMichael Reed struct fc_rport_identifiers rport_ids; 35205e8ec17SMichael Reed struct fc_rport *rport; 35305e8ec17SMichael Reed struct mptfc_rport_info *ri; 3543bc7bf1dSMichael Reed int new_ri = 1; 35565207fedSMoore, Eric u64 pn, nn; 3563bc7bf1dSMichael Reed VirtTarget *vtarget; 3576dd727daSmdr@sgi.com u32 roles = FC_RPORT_ROLE_UNKNOWN; 35805e8ec17SMichael Reed 35905e8ec17SMichael Reed if (mptfc_generate_rport_ids(pg0, &rport_ids) < 0) 36005e8ec17SMichael Reed return; 36105e8ec17SMichael Reed 3626dd727daSmdr@sgi.com roles |= FC_RPORT_ROLE_FCP_TARGET; 3636dd727daSmdr@sgi.com if (pg0->Protocol & MPI_FC_DEVICE_PAGE0_PROT_FCP_INITIATOR) 3646dd727daSmdr@sgi.com roles |= FC_RPORT_ROLE_FCP_INITIATOR; 3656dd727daSmdr@sgi.com 36605e8ec17SMichael Reed /* scan list looking for a match */ 36705e8ec17SMichael Reed list_for_each_entry(ri, &ioc->fc_rports, list) { 3683bc7bf1dSMichael Reed pn = (u64)ri->pg0.WWPN.High << 32 | (u64)ri->pg0.WWPN.Low; 3693bc7bf1dSMichael Reed if (pn == rport_ids.port_name) { /* match */ 37005e8ec17SMichael Reed list_move_tail(&ri->list, &ioc->fc_rports); 3713bc7bf1dSMichael Reed new_ri = 0; 37205e8ec17SMichael Reed break; 37305e8ec17SMichael Reed } 37405e8ec17SMichael Reed } 3753bc7bf1dSMichael Reed if (new_ri) { /* allocate one */ 37605e8ec17SMichael Reed ri = kzalloc(sizeof(struct mptfc_rport_info), GFP_KERNEL); 37705e8ec17SMichael Reed if (!ri) 37805e8ec17SMichael Reed return; 37905e8ec17SMichael Reed list_add_tail(&ri->list, &ioc->fc_rports); 38005e8ec17SMichael Reed } 38105e8ec17SMichael Reed 38205e8ec17SMichael Reed ri->pg0 = *pg0; /* add/update pg0 data */ 38305e8ec17SMichael Reed ri->flags &= ~MPT_RPORT_INFO_FLAGS_MISSING; 38405e8ec17SMichael Reed 3853bc7bf1dSMichael Reed /* MPT_RPORT_INFO_FLAGS_REGISTERED - rport not previously deleted */ 38605e8ec17SMichael Reed if (!(ri->flags & MPT_RPORT_INFO_FLAGS_REGISTERED)) { 38705e8ec17SMichael Reed ri->flags |= MPT_RPORT_INFO_FLAGS_REGISTERED; 38805e8ec17SMichael Reed rport = fc_remote_port_add(ioc->sh, channel, &rport_ids); 38905e8ec17SMichael Reed if (rport) { 39005e8ec17SMichael Reed ri->rport = rport; 3913bc7bf1dSMichael Reed if (new_ri) /* may have been reset by user */ 39205e8ec17SMichael Reed rport->dev_loss_tmo = mptfc_dev_loss_tmo; 39305e8ec17SMichael Reed /* 39405e8ec17SMichael Reed * if already mapped, remap here. If not mapped, 3953bc7bf1dSMichael Reed * target_alloc will allocate vtarget and map, 3963bc7bf1dSMichael Reed * slave_alloc will fill in vdev from vtarget. 39705e8ec17SMichael Reed */ 3983bc7bf1dSMichael Reed if (ri->starget) { 3993bc7bf1dSMichael Reed vtarget = ri->starget->hostdata; 4003bc7bf1dSMichael Reed if (vtarget) { 4013bc7bf1dSMichael Reed vtarget->target_id = pg0->CurrentTargetID; 4023bc7bf1dSMichael Reed vtarget->bus_id = pg0->CurrentBus; 40305e8ec17SMichael Reed } 4043bc7bf1dSMichael Reed } 40565207fedSMoore, Eric *((struct mptfc_rport_info **)rport->dd_data) = ri; 4066dd727daSmdr@sgi.com /* scan will be scheduled once rport becomes a target */ 4076dd727daSmdr@sgi.com fc_remote_port_rolechg(rport,roles); 40865207fedSMoore, Eric 40965207fedSMoore, Eric pn = (u64)ri->pg0.WWPN.High << 32 | (u64)ri->pg0.WWPN.Low; 41065207fedSMoore, Eric nn = (u64)ri->pg0.WWNN.High << 32 | (u64)ri->pg0.WWNN.Low; 4113bc7bf1dSMichael Reed dfcprintk ((MYIOC_s_INFO_FMT 4123bc7bf1dSMichael Reed "mptfc_reg_dev.%d: %x, %llx / %llx, tid %d, " 41305e8ec17SMichael Reed "rport tid %d, tmo %d\n", 4143bc7bf1dSMichael Reed ioc->name, 415914c2d8eSMoore, Eric ioc->sh->host_no, 41605e8ec17SMichael Reed pg0->PortIdentifier, 41765207fedSMoore, Eric (unsigned long long)nn, 41865207fedSMoore, Eric (unsigned long long)pn, 41905e8ec17SMichael Reed pg0->CurrentTargetID, 42005e8ec17SMichael Reed ri->rport->scsi_target_id, 4213bc7bf1dSMichael Reed ri->rport->dev_loss_tmo)); 42205e8ec17SMichael Reed } else { 42305e8ec17SMichael Reed list_del(&ri->list); 42405e8ec17SMichael Reed kfree(ri); 42505e8ec17SMichael Reed ri = NULL; 42605e8ec17SMichael Reed } 42705e8ec17SMichael Reed } 42805e8ec17SMichael Reed } 42905e8ec17SMichael Reed 43005e8ec17SMichael Reed /* 4313bc7bf1dSMichael Reed * OS entry point to allow for host driver to free allocated memory 4323bc7bf1dSMichael Reed * Called if no device present or device being unloaded 4333bc7bf1dSMichael Reed */ 4343bc7bf1dSMichael Reed static void 4353bc7bf1dSMichael Reed mptfc_target_destroy(struct scsi_target *starget) 4363bc7bf1dSMichael Reed { 4373bc7bf1dSMichael Reed struct fc_rport *rport; 4383bc7bf1dSMichael Reed struct mptfc_rport_info *ri; 4393bc7bf1dSMichael Reed 4403bc7bf1dSMichael Reed rport = starget_to_rport(starget); 4413bc7bf1dSMichael Reed if (rport) { 4423bc7bf1dSMichael Reed ri = *((struct mptfc_rport_info **)rport->dd_data); 4433bc7bf1dSMichael Reed if (ri) /* better be! */ 4443bc7bf1dSMichael Reed ri->starget = NULL; 4453bc7bf1dSMichael Reed } 4463bc7bf1dSMichael Reed if (starget->hostdata) 4473bc7bf1dSMichael Reed kfree(starget->hostdata); 4483bc7bf1dSMichael Reed starget->hostdata = NULL; 4493bc7bf1dSMichael Reed } 4503bc7bf1dSMichael Reed 4513bc7bf1dSMichael Reed /* 4523bc7bf1dSMichael Reed * OS entry point to allow host driver to alloc memory 4533bc7bf1dSMichael Reed * for each scsi target. Called once per device the bus scan. 4543bc7bf1dSMichael Reed * Return non-zero if allocation fails. 4553bc7bf1dSMichael Reed */ 4563bc7bf1dSMichael Reed static int 4573bc7bf1dSMichael Reed mptfc_target_alloc(struct scsi_target *starget) 4583bc7bf1dSMichael Reed { 4593bc7bf1dSMichael Reed VirtTarget *vtarget; 4603bc7bf1dSMichael Reed struct fc_rport *rport; 4613bc7bf1dSMichael Reed struct mptfc_rport_info *ri; 4623bc7bf1dSMichael Reed int rc; 4633bc7bf1dSMichael Reed 4643bc7bf1dSMichael Reed vtarget = kzalloc(sizeof(VirtTarget), GFP_KERNEL); 4653bc7bf1dSMichael Reed if (!vtarget) 4663bc7bf1dSMichael Reed return -ENOMEM; 4673bc7bf1dSMichael Reed starget->hostdata = vtarget; 4683bc7bf1dSMichael Reed 4693bc7bf1dSMichael Reed rc = -ENODEV; 4703bc7bf1dSMichael Reed rport = starget_to_rport(starget); 4713bc7bf1dSMichael Reed if (rport) { 4723bc7bf1dSMichael Reed ri = *((struct mptfc_rport_info **)rport->dd_data); 4733bc7bf1dSMichael Reed if (ri) { /* better be! */ 4743bc7bf1dSMichael Reed vtarget->target_id = ri->pg0.CurrentTargetID; 4753bc7bf1dSMichael Reed vtarget->bus_id = ri->pg0.CurrentBus; 4763bc7bf1dSMichael Reed ri->starget = starget; 4773bc7bf1dSMichael Reed rc = 0; 4783bc7bf1dSMichael Reed } 4793bc7bf1dSMichael Reed } 4803bc7bf1dSMichael Reed if (rc != 0) { 4813bc7bf1dSMichael Reed kfree(vtarget); 4823bc7bf1dSMichael Reed starget->hostdata = NULL; 4833bc7bf1dSMichael Reed } 4843bc7bf1dSMichael Reed 4853bc7bf1dSMichael Reed return rc; 4863bc7bf1dSMichael Reed } 4873bc7bf1dSMichael Reed 4883bc7bf1dSMichael Reed /* 48905e8ec17SMichael Reed * OS entry point to allow host driver to alloc memory 49005e8ec17SMichael Reed * for each scsi device. Called once per device the bus scan. 49105e8ec17SMichael Reed * Return non-zero if allocation fails. 49205e8ec17SMichael Reed * Init memory once per LUN. 49305e8ec17SMichael Reed */ 49403fbcbcdSAdrian Bunk static int 49505e8ec17SMichael Reed mptfc_slave_alloc(struct scsi_device *sdev) 49605e8ec17SMichael Reed { 49705e8ec17SMichael Reed MPT_SCSI_HOST *hd; 49805e8ec17SMichael Reed VirtTarget *vtarget; 49905e8ec17SMichael Reed VirtDevice *vdev; 50005e8ec17SMichael Reed struct scsi_target *starget; 50105e8ec17SMichael Reed struct fc_rport *rport; 50205e8ec17SMichael Reed 50305e8ec17SMichael Reed 50465207fedSMoore, Eric starget = scsi_target(sdev); 50565207fedSMoore, Eric rport = starget_to_rport(starget); 50605e8ec17SMichael Reed 50705e8ec17SMichael Reed if (!rport || fc_remote_port_chkready(rport)) 50805e8ec17SMichael Reed return -ENXIO; 50905e8ec17SMichael Reed 51005e8ec17SMichael Reed hd = (MPT_SCSI_HOST *)sdev->host->hostdata; 51105e8ec17SMichael Reed 5123bc7bf1dSMichael Reed vdev = kzalloc(sizeof(VirtDevice), GFP_KERNEL); 51305e8ec17SMichael Reed if (!vdev) { 51405e8ec17SMichael Reed printk(MYIOC_s_ERR_FMT "slave_alloc kmalloc(%zd) FAILED!\n", 51505e8ec17SMichael Reed hd->ioc->name, sizeof(VirtDevice)); 51605e8ec17SMichael Reed return -ENOMEM; 51705e8ec17SMichael Reed } 51805e8ec17SMichael Reed 51905e8ec17SMichael Reed 52005e8ec17SMichael Reed sdev->hostdata = vdev; 52105e8ec17SMichael Reed vtarget = starget->hostdata; 5223bc7bf1dSMichael Reed 52305e8ec17SMichael Reed if (vtarget->num_luns == 0) { 5243bc7bf1dSMichael Reed vtarget->ioc_id = hd->ioc->id; 52505e8ec17SMichael Reed vtarget->tflags = MPT_TARGET_FLAGS_Q_YES | 52605e8ec17SMichael Reed MPT_TARGET_FLAGS_VALID_INQUIRY; 52705e8ec17SMichael Reed hd->Targets[sdev->id] = vtarget; 52805e8ec17SMichael Reed } 52905e8ec17SMichael Reed 53005e8ec17SMichael Reed vdev->vtarget = vtarget; 53105e8ec17SMichael Reed vdev->lun = sdev->lun; 53205e8ec17SMichael Reed 53305e8ec17SMichael Reed vtarget->num_luns++; 53405e8ec17SMichael Reed 53565207fedSMoore, Eric 536914c2d8eSMoore, Eric #ifdef DMPT_DEBUG_FC 537914c2d8eSMoore, Eric { 53865207fedSMoore, Eric u64 nn, pn; 539914c2d8eSMoore, Eric struct mptfc_rport_info *ri; 540914c2d8eSMoore, Eric ri = *((struct mptfc_rport_info **)rport->dd_data); 54165207fedSMoore, Eric pn = (u64)ri->pg0.WWPN.High << 32 | (u64)ri->pg0.WWPN.Low; 54265207fedSMoore, Eric nn = (u64)ri->pg0.WWNN.High << 32 | (u64)ri->pg0.WWNN.Low; 5433bc7bf1dSMichael Reed dfcprintk ((MYIOC_s_INFO_FMT 5443bc7bf1dSMichael Reed "mptfc_slv_alloc.%d: num_luns %d, sdev.id %d, " 54505e8ec17SMichael Reed "CurrentTargetID %d, %x %llx %llx\n", 546914c2d8eSMoore, Eric hd->ioc->name, 54705e8ec17SMichael Reed sdev->host->host_no, 54805e8ec17SMichael Reed vtarget->num_luns, 54905e8ec17SMichael Reed sdev->id, ri->pg0.CurrentTargetID, 55065207fedSMoore, Eric ri->pg0.PortIdentifier, 55165207fedSMoore, Eric (unsigned long long)pn, 55265207fedSMoore, Eric (unsigned long long)nn)); 553914c2d8eSMoore, Eric } 554914c2d8eSMoore, Eric #endif 55505e8ec17SMichael Reed 55605e8ec17SMichael Reed return 0; 55705e8ec17SMichael Reed } 55805e8ec17SMichael Reed 55905e8ec17SMichael Reed static int 56005e8ec17SMichael Reed mptfc_qcmd(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *)) 56105e8ec17SMichael Reed { 5623bc7bf1dSMichael Reed struct mptfc_rport_info *ri; 56305e8ec17SMichael Reed struct fc_rport *rport = starget_to_rport(scsi_target(SCpnt->device)); 56405e8ec17SMichael Reed int err; 56505e8ec17SMichael Reed 56605e8ec17SMichael Reed err = fc_remote_port_chkready(rport); 56705e8ec17SMichael Reed if (unlikely(err)) { 56805e8ec17SMichael Reed SCpnt->result = err; 56905e8ec17SMichael Reed done(SCpnt); 57005e8ec17SMichael Reed return 0; 57105e8ec17SMichael Reed } 5723bc7bf1dSMichael Reed 57365207fedSMoore, Eric /* dd_data is null until finished adding target */ 57465207fedSMoore, Eric ri = *((struct mptfc_rport_info **)rport->dd_data); 57565207fedSMoore, Eric if (unlikely(!ri)) { 57665207fedSMoore, Eric dfcprintk ((MYIOC_s_INFO_FMT 57765207fedSMoore, Eric "mptfc_qcmd.%d: %d:%d, dd_data is null.\n", 57865207fedSMoore, Eric ((MPT_SCSI_HOST *) SCpnt->device->host->hostdata)->ioc->name, 57965207fedSMoore, Eric ((MPT_SCSI_HOST *) SCpnt->device->host->hostdata)->ioc->sh->host_no, 58065207fedSMoore, Eric SCpnt->device->id,SCpnt->device->lun)); 58165207fedSMoore, Eric SCpnt->result = DID_IMM_RETRY << 16; 58265207fedSMoore, Eric done(SCpnt); 58365207fedSMoore, Eric return 0; 58465207fedSMoore, Eric } 58565207fedSMoore, Eric 58665207fedSMoore, Eric err = mptscsih_qcmd(SCpnt,done); 58765207fedSMoore, Eric #ifdef DMPT_DEBUG_FC 58865207fedSMoore, Eric if (unlikely(err)) { 58965207fedSMoore, Eric dfcprintk ((MYIOC_s_INFO_FMT 59065207fedSMoore, Eric "mptfc_qcmd.%d: %d:%d, mptscsih_qcmd returns non-zero.\n", 59165207fedSMoore, Eric ((MPT_SCSI_HOST *) SCpnt->device->host->hostdata)->ioc->name, 59265207fedSMoore, Eric ((MPT_SCSI_HOST *) SCpnt->device->host->hostdata)->ioc->sh->host_no, 59365207fedSMoore, Eric SCpnt->device->id,SCpnt->device->lun)); 59465207fedSMoore, Eric } 59565207fedSMoore, Eric #endif 59665207fedSMoore, Eric return err; 59705e8ec17SMichael Reed } 59805e8ec17SMichael Reed 599*80d3ac77SMichael Reed /* 600*80d3ac77SMichael Reed * mptfc_GetFcPortPage0 - Fetch FCPort config Page0. 601*80d3ac77SMichael Reed * @ioc: Pointer to MPT_ADAPTER structure 602*80d3ac77SMichael Reed * @portnum: IOC Port number 603*80d3ac77SMichael Reed * 604*80d3ac77SMichael Reed * Return: 0 for success 605*80d3ac77SMichael Reed * -ENOMEM if no memory available 606*80d3ac77SMichael Reed * -EPERM if not allowed due to ISR context 607*80d3ac77SMichael Reed * -EAGAIN if no msg frames currently available 608*80d3ac77SMichael Reed * -EFAULT for non-successful reply or no reply (timeout) 609*80d3ac77SMichael Reed * -EINVAL portnum arg out of range (hardwired to two elements) 610*80d3ac77SMichael Reed */ 611*80d3ac77SMichael Reed static int 612*80d3ac77SMichael Reed mptfc_GetFcPortPage0(MPT_ADAPTER *ioc, int portnum) 613*80d3ac77SMichael Reed { 614*80d3ac77SMichael Reed ConfigPageHeader_t hdr; 615*80d3ac77SMichael Reed CONFIGPARMS cfg; 616*80d3ac77SMichael Reed FCPortPage0_t *ppage0_alloc; 617*80d3ac77SMichael Reed FCPortPage0_t *pp0dest; 618*80d3ac77SMichael Reed dma_addr_t page0_dma; 619*80d3ac77SMichael Reed int data_sz; 620*80d3ac77SMichael Reed int copy_sz; 621*80d3ac77SMichael Reed int rc; 622*80d3ac77SMichael Reed int count = 400; 623*80d3ac77SMichael Reed 624*80d3ac77SMichael Reed if (portnum > 1) 625*80d3ac77SMichael Reed return -EINVAL; 626*80d3ac77SMichael Reed 627*80d3ac77SMichael Reed /* Get FCPort Page 0 header */ 628*80d3ac77SMichael Reed hdr.PageVersion = 0; 629*80d3ac77SMichael Reed hdr.PageLength = 0; 630*80d3ac77SMichael Reed hdr.PageNumber = 0; 631*80d3ac77SMichael Reed hdr.PageType = MPI_CONFIG_PAGETYPE_FC_PORT; 632*80d3ac77SMichael Reed cfg.cfghdr.hdr = &hdr; 633*80d3ac77SMichael Reed cfg.physAddr = -1; 634*80d3ac77SMichael Reed cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER; 635*80d3ac77SMichael Reed cfg.dir = 0; 636*80d3ac77SMichael Reed cfg.pageAddr = portnum; 637*80d3ac77SMichael Reed cfg.timeout = 0; 638*80d3ac77SMichael Reed 639*80d3ac77SMichael Reed if ((rc = mpt_config(ioc, &cfg)) != 0) 640*80d3ac77SMichael Reed return rc; 641*80d3ac77SMichael Reed 642*80d3ac77SMichael Reed if (hdr.PageLength == 0) 643*80d3ac77SMichael Reed return 0; 644*80d3ac77SMichael Reed 645*80d3ac77SMichael Reed data_sz = hdr.PageLength * 4; 646*80d3ac77SMichael Reed rc = -ENOMEM; 647*80d3ac77SMichael Reed ppage0_alloc = (FCPortPage0_t *) pci_alloc_consistent(ioc->pcidev, data_sz, &page0_dma); 648*80d3ac77SMichael Reed if (ppage0_alloc) { 649*80d3ac77SMichael Reed 650*80d3ac77SMichael Reed try_again: 651*80d3ac77SMichael Reed memset((u8 *)ppage0_alloc, 0, data_sz); 652*80d3ac77SMichael Reed cfg.physAddr = page0_dma; 653*80d3ac77SMichael Reed cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT; 654*80d3ac77SMichael Reed 655*80d3ac77SMichael Reed if ((rc = mpt_config(ioc, &cfg)) == 0) { 656*80d3ac77SMichael Reed /* save the data */ 657*80d3ac77SMichael Reed pp0dest = &ioc->fc_port_page0[portnum]; 658*80d3ac77SMichael Reed copy_sz = min_t(int, sizeof(FCPortPage0_t), data_sz); 659*80d3ac77SMichael Reed memcpy(pp0dest, ppage0_alloc, copy_sz); 660*80d3ac77SMichael Reed 661*80d3ac77SMichael Reed /* 662*80d3ac77SMichael Reed * Normalize endianness of structure data, 663*80d3ac77SMichael Reed * by byte-swapping all > 1 byte fields! 664*80d3ac77SMichael Reed */ 665*80d3ac77SMichael Reed pp0dest->Flags = le32_to_cpu(pp0dest->Flags); 666*80d3ac77SMichael Reed pp0dest->PortIdentifier = le32_to_cpu(pp0dest->PortIdentifier); 667*80d3ac77SMichael Reed pp0dest->WWNN.Low = le32_to_cpu(pp0dest->WWNN.Low); 668*80d3ac77SMichael Reed pp0dest->WWNN.High = le32_to_cpu(pp0dest->WWNN.High); 669*80d3ac77SMichael Reed pp0dest->WWPN.Low = le32_to_cpu(pp0dest->WWPN.Low); 670*80d3ac77SMichael Reed pp0dest->WWPN.High = le32_to_cpu(pp0dest->WWPN.High); 671*80d3ac77SMichael Reed pp0dest->SupportedServiceClass = le32_to_cpu(pp0dest->SupportedServiceClass); 672*80d3ac77SMichael Reed pp0dest->SupportedSpeeds = le32_to_cpu(pp0dest->SupportedSpeeds); 673*80d3ac77SMichael Reed pp0dest->CurrentSpeed = le32_to_cpu(pp0dest->CurrentSpeed); 674*80d3ac77SMichael Reed pp0dest->MaxFrameSize = le32_to_cpu(pp0dest->MaxFrameSize); 675*80d3ac77SMichael Reed pp0dest->FabricWWNN.Low = le32_to_cpu(pp0dest->FabricWWNN.Low); 676*80d3ac77SMichael Reed pp0dest->FabricWWNN.High = le32_to_cpu(pp0dest->FabricWWNN.High); 677*80d3ac77SMichael Reed pp0dest->FabricWWPN.Low = le32_to_cpu(pp0dest->FabricWWPN.Low); 678*80d3ac77SMichael Reed pp0dest->FabricWWPN.High = le32_to_cpu(pp0dest->FabricWWPN.High); 679*80d3ac77SMichael Reed pp0dest->DiscoveredPortsCount = le32_to_cpu(pp0dest->DiscoveredPortsCount); 680*80d3ac77SMichael Reed pp0dest->MaxInitiators = le32_to_cpu(pp0dest->MaxInitiators); 681*80d3ac77SMichael Reed 682*80d3ac77SMichael Reed /* 683*80d3ac77SMichael Reed * if still doing discovery, 684*80d3ac77SMichael Reed * hang loose a while until finished 685*80d3ac77SMichael Reed */ 686*80d3ac77SMichael Reed if (pp0dest->PortState == MPI_FCPORTPAGE0_PORTSTATE_UNKNOWN) { 687*80d3ac77SMichael Reed if (count-- > 0) { 688*80d3ac77SMichael Reed msleep_interruptible(100); 689*80d3ac77SMichael Reed goto try_again; 690*80d3ac77SMichael Reed } 691*80d3ac77SMichael Reed printk(MYIOC_s_INFO_FMT "Firmware discovery not" 692*80d3ac77SMichael Reed " complete.\n", 693*80d3ac77SMichael Reed ioc->name); 694*80d3ac77SMichael Reed } 695*80d3ac77SMichael Reed } 696*80d3ac77SMichael Reed 697*80d3ac77SMichael Reed pci_free_consistent(ioc->pcidev, data_sz, (u8 *) ppage0_alloc, page0_dma); 698*80d3ac77SMichael Reed } 699*80d3ac77SMichael Reed 700*80d3ac77SMichael Reed return rc; 701*80d3ac77SMichael Reed } 702*80d3ac77SMichael Reed 70305e8ec17SMichael Reed static void 70405e8ec17SMichael Reed mptfc_init_host_attr(MPT_ADAPTER *ioc,int portnum) 70505e8ec17SMichael Reed { 70605e8ec17SMichael Reed unsigned class = 0, cos = 0; 70705e8ec17SMichael Reed 70805e8ec17SMichael Reed /* don't know what to do as only one scsi (fc) host was allocated */ 70905e8ec17SMichael Reed if (portnum != 0) 71005e8ec17SMichael Reed return; 71105e8ec17SMichael Reed 71205e8ec17SMichael Reed class = ioc->fc_port_page0[portnum].SupportedServiceClass; 71305e8ec17SMichael Reed if (class & MPI_FCPORTPAGE0_SUPPORT_CLASS_1) 71405e8ec17SMichael Reed cos |= FC_COS_CLASS1; 71505e8ec17SMichael Reed if (class & MPI_FCPORTPAGE0_SUPPORT_CLASS_2) 71605e8ec17SMichael Reed cos |= FC_COS_CLASS2; 71705e8ec17SMichael Reed if (class & MPI_FCPORTPAGE0_SUPPORT_CLASS_3) 71805e8ec17SMichael Reed cos |= FC_COS_CLASS3; 71905e8ec17SMichael Reed 72005e8ec17SMichael Reed fc_host_node_name(ioc->sh) = 72105e8ec17SMichael Reed (u64)ioc->fc_port_page0[portnum].WWNN.High << 32 72205e8ec17SMichael Reed | (u64)ioc->fc_port_page0[portnum].WWNN.Low; 72305e8ec17SMichael Reed 72405e8ec17SMichael Reed fc_host_port_name(ioc->sh) = 72505e8ec17SMichael Reed (u64)ioc->fc_port_page0[portnum].WWPN.High << 32 72605e8ec17SMichael Reed | (u64)ioc->fc_port_page0[portnum].WWPN.Low; 72705e8ec17SMichael Reed 72805e8ec17SMichael Reed fc_host_port_id(ioc->sh) = ioc->fc_port_page0[portnum].PortIdentifier; 72905e8ec17SMichael Reed 73005e8ec17SMichael Reed fc_host_supported_classes(ioc->sh) = cos; 73105e8ec17SMichael Reed 73205e8ec17SMichael Reed fc_host_tgtid_bind_type(ioc->sh) = FC_TGTID_BIND_BY_WWPN; 73305e8ec17SMichael Reed } 73405e8ec17SMichael Reed 73505e8ec17SMichael Reed static void 73605e8ec17SMichael Reed mptfc_rescan_devices(void *arg) 73705e8ec17SMichael Reed { 73805e8ec17SMichael Reed MPT_ADAPTER *ioc = (MPT_ADAPTER *)arg; 73905e8ec17SMichael Reed int ii; 74005e8ec17SMichael Reed int work_to_do; 74165207fedSMoore, Eric u64 pn; 74205e8ec17SMichael Reed unsigned long flags; 74305e8ec17SMichael Reed struct mptfc_rport_info *ri; 74405e8ec17SMichael Reed 74505e8ec17SMichael Reed do { 74605e8ec17SMichael Reed /* start by tagging all ports as missing */ 74705e8ec17SMichael Reed list_for_each_entry(ri, &ioc->fc_rports, list) { 74805e8ec17SMichael Reed if (ri->flags & MPT_RPORT_INFO_FLAGS_REGISTERED) { 74905e8ec17SMichael Reed ri->flags |= MPT_RPORT_INFO_FLAGS_MISSING; 75005e8ec17SMichael Reed } 75105e8ec17SMichael Reed } 75205e8ec17SMichael Reed 75305e8ec17SMichael Reed /* 75405e8ec17SMichael Reed * now rescan devices known to adapter, 75505e8ec17SMichael Reed * will reregister existing rports 75605e8ec17SMichael Reed */ 75705e8ec17SMichael Reed for (ii=0; ii < ioc->facts.NumberOfPorts; ii++) { 758*80d3ac77SMichael Reed (void) mptfc_GetFcPortPage0(ioc, ii); 75905e8ec17SMichael Reed mptfc_init_host_attr(ioc,ii); /* refresh */ 76005e8ec17SMichael Reed mptfc_GetFcDevPage0(ioc,ii,mptfc_register_dev); 76105e8ec17SMichael Reed } 76205e8ec17SMichael Reed 76305e8ec17SMichael Reed /* delete devices still missing */ 76405e8ec17SMichael Reed list_for_each_entry(ri, &ioc->fc_rports, list) { 76505e8ec17SMichael Reed /* if newly missing, delete it */ 76665207fedSMoore, Eric if (ri->flags & MPT_RPORT_INFO_FLAGS_MISSING) { 76705e8ec17SMichael Reed 76805e8ec17SMichael Reed ri->flags &= ~(MPT_RPORT_INFO_FLAGS_REGISTERED| 76905e8ec17SMichael Reed MPT_RPORT_INFO_FLAGS_MISSING); 77065207fedSMoore, Eric fc_remote_port_delete(ri->rport); /* won't sleep */ 7713bc7bf1dSMichael Reed ri->rport = NULL; 77265207fedSMoore, Eric 77365207fedSMoore, Eric pn = (u64)ri->pg0.WWPN.High << 32 | 77465207fedSMoore, Eric (u64)ri->pg0.WWPN.Low; 7753bc7bf1dSMichael Reed dfcprintk ((MYIOC_s_INFO_FMT 7763bc7bf1dSMichael Reed "mptfc_rescan.%d: %llx deleted\n", 7773bc7bf1dSMichael Reed ioc->name, 7783bc7bf1dSMichael Reed ioc->sh->host_no, 77965207fedSMoore, Eric (unsigned long long)pn)); 78005e8ec17SMichael Reed } 78105e8ec17SMichael Reed } 78205e8ec17SMichael Reed 78305e8ec17SMichael Reed /* 78405e8ec17SMichael Reed * allow multiple passes as target state 78505e8ec17SMichael Reed * might have changed during scan 78605e8ec17SMichael Reed */ 78705e8ec17SMichael Reed spin_lock_irqsave(&ioc->fc_rescan_work_lock, flags); 78805e8ec17SMichael Reed if (ioc->fc_rescan_work_count > 2) /* only need one more */ 78905e8ec17SMichael Reed ioc->fc_rescan_work_count = 2; 79005e8ec17SMichael Reed work_to_do = --ioc->fc_rescan_work_count; 79105e8ec17SMichael Reed spin_unlock_irqrestore(&ioc->fc_rescan_work_lock, flags); 79205e8ec17SMichael Reed } while (work_to_do); 79305e8ec17SMichael Reed } 79405e8ec17SMichael Reed 7952496af39SMoore, Eric Dean static int 7962496af39SMoore, Eric Dean mptfc_probe(struct pci_dev *pdev, const struct pci_device_id *id) 7972496af39SMoore, Eric Dean { 7982496af39SMoore, Eric Dean struct Scsi_Host *sh; 7992496af39SMoore, Eric Dean MPT_SCSI_HOST *hd; 8002496af39SMoore, Eric Dean MPT_ADAPTER *ioc; 8012496af39SMoore, Eric Dean unsigned long flags; 8021ca00bb7SChristoph Hellwig int ii; 8032496af39SMoore, Eric Dean int numSGE = 0; 8042496af39SMoore, Eric Dean int scale; 8052496af39SMoore, Eric Dean int ioc_cap; 8062496af39SMoore, Eric Dean int error=0; 8072496af39SMoore, Eric Dean int r; 8082496af39SMoore, Eric Dean 8092496af39SMoore, Eric Dean if ((r = mpt_attach(pdev,id)) != 0) 8102496af39SMoore, Eric Dean return r; 8112496af39SMoore, Eric Dean 8122496af39SMoore, Eric Dean ioc = pci_get_drvdata(pdev); 813d335cc38SMoore, Eric Dean ioc->DoneCtx = mptfcDoneCtx; 814d335cc38SMoore, Eric Dean ioc->TaskCtx = mptfcTaskCtx; 815d335cc38SMoore, Eric Dean ioc->InternalCtx = mptfcInternalCtx; 8162496af39SMoore, Eric Dean 8172496af39SMoore, Eric Dean /* Added sanity check on readiness of the MPT adapter. 8182496af39SMoore, Eric Dean */ 8192496af39SMoore, Eric Dean if (ioc->last_state != MPI_IOC_STATE_OPERATIONAL) { 8202496af39SMoore, Eric Dean printk(MYIOC_s_WARN_FMT 8212496af39SMoore, Eric Dean "Skipping because it's not operational!\n", 8222496af39SMoore, Eric Dean ioc->name); 8237acec1e7SMoore, Eric Dean error = -ENODEV; 8247acec1e7SMoore, Eric Dean goto out_mptfc_probe; 8252496af39SMoore, Eric Dean } 8262496af39SMoore, Eric Dean 8272496af39SMoore, Eric Dean if (!ioc->active) { 8282496af39SMoore, Eric Dean printk(MYIOC_s_WARN_FMT "Skipping because it's disabled!\n", 8292496af39SMoore, Eric Dean ioc->name); 8307acec1e7SMoore, Eric Dean error = -ENODEV; 8317acec1e7SMoore, Eric Dean goto out_mptfc_probe; 8322496af39SMoore, Eric Dean } 8332496af39SMoore, Eric Dean 8342496af39SMoore, Eric Dean /* Sanity check - ensure at least 1 port is INITIATOR capable 8352496af39SMoore, Eric Dean */ 8362496af39SMoore, Eric Dean ioc_cap = 0; 8372496af39SMoore, Eric Dean for (ii=0; ii < ioc->facts.NumberOfPorts; ii++) { 8382496af39SMoore, Eric Dean if (ioc->pfacts[ii].ProtocolFlags & 8392496af39SMoore, Eric Dean MPI_PORTFACTS_PROTOCOL_INITIATOR) 8402496af39SMoore, Eric Dean ioc_cap ++; 8412496af39SMoore, Eric Dean } 8422496af39SMoore, Eric Dean 8432496af39SMoore, Eric Dean if (!ioc_cap) { 8442496af39SMoore, Eric Dean printk(MYIOC_s_WARN_FMT 8452496af39SMoore, Eric Dean "Skipping ioc=%p because SCSI Initiator mode is NOT enabled!\n", 8462496af39SMoore, Eric Dean ioc->name, ioc); 84705e8ec17SMichael Reed return -ENODEV; 8482496af39SMoore, Eric Dean } 8492496af39SMoore, Eric Dean 8502496af39SMoore, Eric Dean sh = scsi_host_alloc(&mptfc_driver_template, sizeof(MPT_SCSI_HOST)); 8512496af39SMoore, Eric Dean 8522496af39SMoore, Eric Dean if (!sh) { 8532496af39SMoore, Eric Dean printk(MYIOC_s_WARN_FMT 8542496af39SMoore, Eric Dean "Unable to register controller with SCSI subsystem\n", 8552496af39SMoore, Eric Dean ioc->name); 8567acec1e7SMoore, Eric Dean error = -1; 8577acec1e7SMoore, Eric Dean goto out_mptfc_probe; 8582496af39SMoore, Eric Dean } 8592496af39SMoore, Eric Dean 860*80d3ac77SMichael Reed spin_lock_init(&ioc->fc_rescan_work_lock); 86105e8ec17SMichael Reed INIT_WORK(&ioc->fc_rescan_work, mptfc_rescan_devices,(void *)ioc); 86205e8ec17SMichael Reed 8632496af39SMoore, Eric Dean spin_lock_irqsave(&ioc->FreeQlock, flags); 8642496af39SMoore, Eric Dean 8652496af39SMoore, Eric Dean /* Attach the SCSI Host to the IOC structure 8662496af39SMoore, Eric Dean */ 8672496af39SMoore, Eric Dean ioc->sh = sh; 8682496af39SMoore, Eric Dean 8692496af39SMoore, Eric Dean sh->io_port = 0; 8702496af39SMoore, Eric Dean sh->n_io_port = 0; 8712496af39SMoore, Eric Dean sh->irq = 0; 8722496af39SMoore, Eric Dean 8732496af39SMoore, Eric Dean /* set 16 byte cdb's */ 8742496af39SMoore, Eric Dean sh->max_cmd_len = 16; 8752496af39SMoore, Eric Dean 8762496af39SMoore, Eric Dean sh->max_id = MPT_MAX_FC_DEVICES<256 ? MPT_MAX_FC_DEVICES : 255; 8772496af39SMoore, Eric Dean 8782496af39SMoore, Eric Dean sh->max_lun = MPT_LAST_LUN + 1; 8792496af39SMoore, Eric Dean sh->max_channel = 0; 8802496af39SMoore, Eric Dean sh->this_id = ioc->pfacts[0].PortSCSIID; 8812496af39SMoore, Eric Dean 8822496af39SMoore, Eric Dean /* Required entry. 8832496af39SMoore, Eric Dean */ 8842496af39SMoore, Eric Dean sh->unique_id = ioc->id; 8852496af39SMoore, Eric Dean 8862496af39SMoore, Eric Dean /* Verify that we won't exceed the maximum 8872496af39SMoore, Eric Dean * number of chain buffers 8882496af39SMoore, Eric Dean * We can optimize: ZZ = req_sz/sizeof(SGE) 8892496af39SMoore, Eric Dean * For 32bit SGE's: 8902496af39SMoore, Eric Dean * numSGE = 1 + (ZZ-1)*(maxChain -1) + ZZ 8912496af39SMoore, Eric Dean * + (req_sz - 64)/sizeof(SGE) 8922496af39SMoore, Eric Dean * A slightly different algorithm is required for 8932496af39SMoore, Eric Dean * 64bit SGEs. 8942496af39SMoore, Eric Dean */ 8952496af39SMoore, Eric Dean scale = ioc->req_sz/(sizeof(dma_addr_t) + sizeof(u32)); 8962496af39SMoore, Eric Dean if (sizeof(dma_addr_t) == sizeof(u64)) { 8972496af39SMoore, Eric Dean numSGE = (scale - 1) * 8982496af39SMoore, Eric Dean (ioc->facts.MaxChainDepth-1) + scale + 8992496af39SMoore, Eric Dean (ioc->req_sz - 60) / (sizeof(dma_addr_t) + 9002496af39SMoore, Eric Dean sizeof(u32)); 9012496af39SMoore, Eric Dean } else { 9022496af39SMoore, Eric Dean numSGE = 1 + (scale - 1) * 9032496af39SMoore, Eric Dean (ioc->facts.MaxChainDepth-1) + scale + 9042496af39SMoore, Eric Dean (ioc->req_sz - 64) / (sizeof(dma_addr_t) + 9052496af39SMoore, Eric Dean sizeof(u32)); 9062496af39SMoore, Eric Dean } 9072496af39SMoore, Eric Dean 9082496af39SMoore, Eric Dean if (numSGE < sh->sg_tablesize) { 9092496af39SMoore, Eric Dean /* Reset this value */ 9102496af39SMoore, Eric Dean dprintk((MYIOC_s_INFO_FMT 9112496af39SMoore, Eric Dean "Resetting sg_tablesize to %d from %d\n", 9122496af39SMoore, Eric Dean ioc->name, numSGE, sh->sg_tablesize)); 9132496af39SMoore, Eric Dean sh->sg_tablesize = numSGE; 9142496af39SMoore, Eric Dean } 9152496af39SMoore, Eric Dean 9162496af39SMoore, Eric Dean spin_unlock_irqrestore(&ioc->FreeQlock, flags); 9172496af39SMoore, Eric Dean 9182496af39SMoore, Eric Dean hd = (MPT_SCSI_HOST *) sh->hostdata; 9192496af39SMoore, Eric Dean hd->ioc = ioc; 9202496af39SMoore, Eric Dean 9212496af39SMoore, Eric Dean /* SCSI needs scsi_cmnd lookup table! 9222496af39SMoore, Eric Dean * (with size equal to req_depth*PtrSz!) 9232496af39SMoore, Eric Dean */ 9241ca00bb7SChristoph Hellwig hd->ScsiLookup = kcalloc(ioc->req_depth, sizeof(void *), GFP_ATOMIC); 9251ca00bb7SChristoph Hellwig if (!hd->ScsiLookup) { 9262496af39SMoore, Eric Dean error = -ENOMEM; 9277acec1e7SMoore, Eric Dean goto out_mptfc_probe; 9282496af39SMoore, Eric Dean } 9292496af39SMoore, Eric Dean 9301ca00bb7SChristoph Hellwig dprintk((MYIOC_s_INFO_FMT "ScsiLookup @ %p\n", 9311ca00bb7SChristoph Hellwig ioc->name, hd->ScsiLookup)); 9322496af39SMoore, Eric Dean 9332496af39SMoore, Eric Dean /* Allocate memory for the device structures. 9342496af39SMoore, Eric Dean * A non-Null pointer at an offset 9352496af39SMoore, Eric Dean * indicates a device exists. 9362496af39SMoore, Eric Dean * max_id = 1 + maximum id (hosts.h) 9372496af39SMoore, Eric Dean */ 9381ca00bb7SChristoph Hellwig hd->Targets = kcalloc(sh->max_id, sizeof(void *), GFP_ATOMIC); 9391ca00bb7SChristoph Hellwig if (!hd->Targets) { 9402496af39SMoore, Eric Dean error = -ENOMEM; 9417acec1e7SMoore, Eric Dean goto out_mptfc_probe; 9422496af39SMoore, Eric Dean } 9432496af39SMoore, Eric Dean 9441ca00bb7SChristoph Hellwig dprintk((KERN_INFO " vdev @ %p\n", hd->Targets)); 9452496af39SMoore, Eric Dean 9462496af39SMoore, Eric Dean /* Clear the TM flags 9472496af39SMoore, Eric Dean */ 9482496af39SMoore, Eric Dean hd->tmPending = 0; 9492496af39SMoore, Eric Dean hd->tmState = TM_STATE_NONE; 9502496af39SMoore, Eric Dean hd->resetPending = 0; 9512496af39SMoore, Eric Dean hd->abortSCpnt = NULL; 9522496af39SMoore, Eric Dean 9532496af39SMoore, Eric Dean /* Clear the pointer used to store 9542496af39SMoore, Eric Dean * single-threaded commands, i.e., those 9552496af39SMoore, Eric Dean * issued during a bus scan, dv and 9562496af39SMoore, Eric Dean * configuration pages. 9572496af39SMoore, Eric Dean */ 9582496af39SMoore, Eric Dean hd->cmdPtr = NULL; 9592496af39SMoore, Eric Dean 9602496af39SMoore, Eric Dean /* Initialize this SCSI Hosts' timers 9612496af39SMoore, Eric Dean * To use, set the timer expires field 9622496af39SMoore, Eric Dean * and add_timer 9632496af39SMoore, Eric Dean */ 9642496af39SMoore, Eric Dean init_timer(&hd->timer); 9652496af39SMoore, Eric Dean hd->timer.data = (unsigned long) hd; 9662496af39SMoore, Eric Dean hd->timer.function = mptscsih_timer_expired; 9672496af39SMoore, Eric Dean 9682496af39SMoore, Eric Dean hd->mpt_pq_filter = mpt_pq_filter; 9692496af39SMoore, Eric Dean 9702496af39SMoore, Eric Dean ddvprintk((MYIOC_s_INFO_FMT 9712496af39SMoore, Eric Dean "mpt_pq_filter %x\n", 9722496af39SMoore, Eric Dean ioc->name, 9732496af39SMoore, Eric Dean mpt_pq_filter)); 9742496af39SMoore, Eric Dean 9752496af39SMoore, Eric Dean init_waitqueue_head(&hd->scandv_waitq); 9762496af39SMoore, Eric Dean hd->scandv_wait_done = 0; 9772496af39SMoore, Eric Dean hd->last_queue_full = 0; 9782496af39SMoore, Eric Dean 97905e8ec17SMichael Reed sh->transportt = mptfc_transport_template; 9802496af39SMoore, Eric Dean error = scsi_add_host (sh, &ioc->pcidev->dev); 9812496af39SMoore, Eric Dean if(error) { 9822496af39SMoore, Eric Dean dprintk((KERN_ERR MYNAM 9832496af39SMoore, Eric Dean "scsi_add_host failed\n")); 9847acec1e7SMoore, Eric Dean goto out_mptfc_probe; 9852496af39SMoore, Eric Dean } 9862496af39SMoore, Eric Dean 98765207fedSMoore, Eric /* initialize workqueue */ 98865207fedSMoore, Eric 98965207fedSMoore, Eric snprintf(ioc->fc_rescan_work_q_name, KOBJ_NAME_LEN, "mptfc_wq_%d", 99065207fedSMoore, Eric sh->host_no); 99165207fedSMoore, Eric ioc->fc_rescan_work_q = 99265207fedSMoore, Eric create_singlethread_workqueue(ioc->fc_rescan_work_q_name); 99365207fedSMoore, Eric if (!ioc->fc_rescan_work_q) 99465207fedSMoore, Eric goto out_mptfc_probe; 99565207fedSMoore, Eric 99665207fedSMoore, Eric /* 997*80d3ac77SMichael Reed * Pre-fetch FC port WWN and stuff... 998*80d3ac77SMichael Reed * (FCPortPage0_t stuff) 999*80d3ac77SMichael Reed */ 1000*80d3ac77SMichael Reed for (ii=0; ii < ioc->facts.NumberOfPorts; ii++) { 1001*80d3ac77SMichael Reed (void) mptfc_GetFcPortPage0(ioc, ii); 1002*80d3ac77SMichael Reed } 1003*80d3ac77SMichael Reed 1004*80d3ac77SMichael Reed /* 100565207fedSMoore, Eric * scan for rports - 100665207fedSMoore, Eric * by doing it via the workqueue, some locking is eliminated 100765207fedSMoore, Eric */ 100865207fedSMoore, Eric 100965207fedSMoore, Eric ioc->fc_rescan_work_count = 1; 101065207fedSMoore, Eric queue_work(ioc->fc_rescan_work_q, &ioc->fc_rescan_work); 101165207fedSMoore, Eric flush_workqueue(ioc->fc_rescan_work_q); 101205e8ec17SMichael Reed 10132496af39SMoore, Eric Dean return 0; 10142496af39SMoore, Eric Dean 10157acec1e7SMoore, Eric Dean out_mptfc_probe: 10162496af39SMoore, Eric Dean 10172496af39SMoore, Eric Dean mptscsih_remove(pdev); 10182496af39SMoore, Eric Dean return error; 10192496af39SMoore, Eric Dean } 10202496af39SMoore, Eric Dean 10212496af39SMoore, Eric Dean static struct pci_driver mptfc_driver = { 10222496af39SMoore, Eric Dean .name = "mptfc", 10232496af39SMoore, Eric Dean .id_table = mptfc_pci_table, 10242496af39SMoore, Eric Dean .probe = mptfc_probe, 102505e8ec17SMichael Reed .remove = __devexit_p(mptfc_remove), 10262496af39SMoore, Eric Dean .shutdown = mptscsih_shutdown, 10272496af39SMoore, Eric Dean #ifdef CONFIG_PM 10282496af39SMoore, Eric Dean .suspend = mptscsih_suspend, 10292496af39SMoore, Eric Dean .resume = mptscsih_resume, 10302496af39SMoore, Eric Dean #endif 10312496af39SMoore, Eric Dean }; 10322496af39SMoore, Eric Dean 1033*80d3ac77SMichael Reed static int 1034*80d3ac77SMichael Reed mptfc_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *pEvReply) 1035*80d3ac77SMichael Reed { 1036*80d3ac77SMichael Reed MPT_SCSI_HOST *hd; 1037*80d3ac77SMichael Reed u8 event = le32_to_cpu(pEvReply->Event) & 0xFF; 1038*80d3ac77SMichael Reed unsigned long flags; 1039*80d3ac77SMichael Reed int rc=1; 1040*80d3ac77SMichael Reed 1041*80d3ac77SMichael Reed devtverboseprintk((MYIOC_s_INFO_FMT "MPT event (=%02Xh) routed to SCSI host driver!\n", 1042*80d3ac77SMichael Reed ioc->name, event)); 1043*80d3ac77SMichael Reed 1044*80d3ac77SMichael Reed if (ioc->sh == NULL || 1045*80d3ac77SMichael Reed ((hd = (MPT_SCSI_HOST *)ioc->sh->hostdata) == NULL)) 1046*80d3ac77SMichael Reed return 1; 1047*80d3ac77SMichael Reed 1048*80d3ac77SMichael Reed switch (event) { 1049*80d3ac77SMichael Reed case MPI_EVENT_RESCAN: 1050*80d3ac77SMichael Reed spin_lock_irqsave(&ioc->fc_rescan_work_lock, flags); 1051*80d3ac77SMichael Reed if (ioc->fc_rescan_work_q) { 1052*80d3ac77SMichael Reed if (ioc->fc_rescan_work_count++ == 0) { 1053*80d3ac77SMichael Reed queue_work(ioc->fc_rescan_work_q, 1054*80d3ac77SMichael Reed &ioc->fc_rescan_work); 1055*80d3ac77SMichael Reed } 1056*80d3ac77SMichael Reed } 1057*80d3ac77SMichael Reed spin_unlock_irqrestore(&ioc->fc_rescan_work_lock, flags); 1058*80d3ac77SMichael Reed break; 1059*80d3ac77SMichael Reed default: 1060*80d3ac77SMichael Reed rc = mptscsih_event_process(ioc,pEvReply); 1061*80d3ac77SMichael Reed break; 1062*80d3ac77SMichael Reed } 1063*80d3ac77SMichael Reed return rc; 1064*80d3ac77SMichael Reed } 1065*80d3ac77SMichael Reed 1066*80d3ac77SMichael Reed static int 1067*80d3ac77SMichael Reed mptfc_ioc_reset(MPT_ADAPTER *ioc, int reset_phase) 1068*80d3ac77SMichael Reed { 1069*80d3ac77SMichael Reed int rc; 1070*80d3ac77SMichael Reed unsigned long flags; 1071*80d3ac77SMichael Reed 1072*80d3ac77SMichael Reed rc = mptscsih_ioc_reset(ioc,reset_phase); 1073*80d3ac77SMichael Reed if (rc == 0) 1074*80d3ac77SMichael Reed return rc; 1075*80d3ac77SMichael Reed 1076*80d3ac77SMichael Reed 1077*80d3ac77SMichael Reed dtmprintk((KERN_WARNING MYNAM 1078*80d3ac77SMichael Reed ": IOC %s_reset routed to FC host driver!\n", 1079*80d3ac77SMichael Reed reset_phase==MPT_IOC_SETUP_RESET ? "setup" : ( 1080*80d3ac77SMichael Reed reset_phase==MPT_IOC_PRE_RESET ? "pre" : "post"))); 1081*80d3ac77SMichael Reed 1082*80d3ac77SMichael Reed if (reset_phase == MPT_IOC_SETUP_RESET) { 1083*80d3ac77SMichael Reed } 1084*80d3ac77SMichael Reed 1085*80d3ac77SMichael Reed else if (reset_phase == MPT_IOC_PRE_RESET) { 1086*80d3ac77SMichael Reed } 1087*80d3ac77SMichael Reed 1088*80d3ac77SMichael Reed else { /* MPT_IOC_POST_RESET */ 1089*80d3ac77SMichael Reed spin_lock_irqsave(&ioc->fc_rescan_work_lock, flags); 1090*80d3ac77SMichael Reed if (ioc->fc_rescan_work_q) { 1091*80d3ac77SMichael Reed if (ioc->fc_rescan_work_count++ == 0) { 1092*80d3ac77SMichael Reed queue_work(ioc->fc_rescan_work_q, 1093*80d3ac77SMichael Reed &ioc->fc_rescan_work); 1094*80d3ac77SMichael Reed } 1095*80d3ac77SMichael Reed } 1096*80d3ac77SMichael Reed spin_unlock_irqrestore(&ioc->fc_rescan_work_lock, flags); 1097*80d3ac77SMichael Reed } 1098*80d3ac77SMichael Reed return 1; 1099*80d3ac77SMichael Reed } 1100*80d3ac77SMichael Reed 11012496af39SMoore, Eric Dean /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 11022496af39SMoore, Eric Dean /** 11032496af39SMoore, Eric Dean * mptfc_init - Register MPT adapter(s) as SCSI host(s) with 11042496af39SMoore, Eric Dean * linux scsi mid-layer. 11052496af39SMoore, Eric Dean * 11062496af39SMoore, Eric Dean * Returns 0 for success, non-zero for failure. 11072496af39SMoore, Eric Dean */ 11082496af39SMoore, Eric Dean static int __init 11092496af39SMoore, Eric Dean mptfc_init(void) 11102496af39SMoore, Eric Dean { 111105e8ec17SMichael Reed int error; 11122496af39SMoore, Eric Dean 11132496af39SMoore, Eric Dean show_mptmod_ver(my_NAME, my_VERSION); 11142496af39SMoore, Eric Dean 111505e8ec17SMichael Reed /* sanity check module parameter */ 111605e8ec17SMichael Reed if (mptfc_dev_loss_tmo == 0) 111705e8ec17SMichael Reed mptfc_dev_loss_tmo = MPTFC_DEV_LOSS_TMO; 111805e8ec17SMichael Reed 111905e8ec17SMichael Reed mptfc_transport_template = 112005e8ec17SMichael Reed fc_attach_transport(&mptfc_transport_functions); 112105e8ec17SMichael Reed 112205e8ec17SMichael Reed if (!mptfc_transport_template) 112305e8ec17SMichael Reed return -ENODEV; 112405e8ec17SMichael Reed 11252496af39SMoore, Eric Dean mptfcDoneCtx = mpt_register(mptscsih_io_done, MPTFC_DRIVER); 11262496af39SMoore, Eric Dean mptfcTaskCtx = mpt_register(mptscsih_taskmgmt_complete, MPTFC_DRIVER); 11272496af39SMoore, Eric Dean mptfcInternalCtx = mpt_register(mptscsih_scandv_complete, MPTFC_DRIVER); 11282496af39SMoore, Eric Dean 1129*80d3ac77SMichael Reed if (mpt_event_register(mptfcDoneCtx, mptfc_event_process) == 0) { 11303a892befSMoore, Eric devtverboseprintk((KERN_INFO MYNAM 11312496af39SMoore, Eric Dean ": Registered for IOC event notifications\n")); 11322496af39SMoore, Eric Dean } 11332496af39SMoore, Eric Dean 1134*80d3ac77SMichael Reed if (mpt_reset_register(mptfcDoneCtx, mptfc_ioc_reset) == 0) { 11352496af39SMoore, Eric Dean dprintk((KERN_INFO MYNAM 11362496af39SMoore, Eric Dean ": Registered for IOC reset notifications\n")); 11372496af39SMoore, Eric Dean } 11382496af39SMoore, Eric Dean 113905e8ec17SMichael Reed error = pci_register_driver(&mptfc_driver); 11403bc7bf1dSMichael Reed if (error) 114105e8ec17SMichael Reed fc_release_transport(mptfc_transport_template); 114205e8ec17SMichael Reed 114305e8ec17SMichael Reed return error; 114405e8ec17SMichael Reed } 114505e8ec17SMichael Reed 114605e8ec17SMichael Reed /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 114705e8ec17SMichael Reed /** 114805e8ec17SMichael Reed * mptfc_remove - Removed fc infrastructure for devices 114905e8ec17SMichael Reed * @pdev: Pointer to pci_dev structure 115005e8ec17SMichael Reed * 115105e8ec17SMichael Reed */ 11523bc7bf1dSMichael Reed static void __devexit 11533bc7bf1dSMichael Reed mptfc_remove(struct pci_dev *pdev) 115405e8ec17SMichael Reed { 115505e8ec17SMichael Reed MPT_ADAPTER *ioc = pci_get_drvdata(pdev); 115605e8ec17SMichael Reed struct mptfc_rport_info *p, *n; 115765207fedSMoore, Eric struct workqueue_struct *work_q; 115865207fedSMoore, Eric unsigned long flags; 115965207fedSMoore, Eric 116065207fedSMoore, Eric /* destroy workqueue */ 116165207fedSMoore, Eric if ((work_q=ioc->fc_rescan_work_q)) { 116265207fedSMoore, Eric spin_lock_irqsave(&ioc->fc_rescan_work_lock, flags); 116365207fedSMoore, Eric ioc->fc_rescan_work_q = NULL; 116465207fedSMoore, Eric spin_unlock_irqrestore(&ioc->fc_rescan_work_lock, flags); 116565207fedSMoore, Eric destroy_workqueue(work_q); 116665207fedSMoore, Eric } 116705e8ec17SMichael Reed 116805e8ec17SMichael Reed fc_remove_host(ioc->sh); 116905e8ec17SMichael Reed 117005e8ec17SMichael Reed list_for_each_entry_safe(p, n, &ioc->fc_rports, list) { 117105e8ec17SMichael Reed list_del(&p->list); 117205e8ec17SMichael Reed kfree(p); 117305e8ec17SMichael Reed } 117405e8ec17SMichael Reed 117505e8ec17SMichael Reed mptscsih_remove(pdev); 11762496af39SMoore, Eric Dean } 11772496af39SMoore, Eric Dean 11782496af39SMoore, Eric Dean /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 11792496af39SMoore, Eric Dean /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 11802496af39SMoore, Eric Dean /** 11812496af39SMoore, Eric Dean * mptfc_exit - Unregisters MPT adapter(s) 11822496af39SMoore, Eric Dean * 11832496af39SMoore, Eric Dean */ 11842496af39SMoore, Eric Dean static void __exit 11852496af39SMoore, Eric Dean mptfc_exit(void) 11862496af39SMoore, Eric Dean { 11872496af39SMoore, Eric Dean pci_unregister_driver(&mptfc_driver); 118805e8ec17SMichael Reed fc_release_transport(mptfc_transport_template); 11892496af39SMoore, Eric Dean 11902496af39SMoore, Eric Dean mpt_reset_deregister(mptfcDoneCtx); 11912496af39SMoore, Eric Dean dprintk((KERN_INFO MYNAM 11922496af39SMoore, Eric Dean ": Deregistered for IOC reset notifications\n")); 11932496af39SMoore, Eric Dean 11942496af39SMoore, Eric Dean mpt_event_deregister(mptfcDoneCtx); 11952496af39SMoore, Eric Dean dprintk((KERN_INFO MYNAM 11962496af39SMoore, Eric Dean ": Deregistered for IOC event notifications\n")); 11972496af39SMoore, Eric Dean 11982496af39SMoore, Eric Dean mpt_deregister(mptfcInternalCtx); 11992496af39SMoore, Eric Dean mpt_deregister(mptfcTaskCtx); 12002496af39SMoore, Eric Dean mpt_deregister(mptfcDoneCtx); 12012496af39SMoore, Eric Dean } 12022496af39SMoore, Eric Dean 12032496af39SMoore, Eric Dean module_init(mptfc_init); 12042496af39SMoore, Eric Dean module_exit(mptfc_exit); 1205