| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1 | /******************************************************************* |
| 2 | * This file is part of the Emulex Linux Device Driver for * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 3 | * Fibre Channel Host Bus Adapters. * |
James Smart | 9413aff | 2007-04-25 09:53:35 -0400 | [diff] [blame] | 4 | * Copyright (C) 2004-2007 Emulex. All rights reserved. * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 5 | * EMULEX and SLI are trademarks of Emulex. * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6 | * www.emulex.com * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 7 | * Portions Copyright (C) 2004-2005 Christoph Hellwig * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8 | * * |
| 9 | * This program is free software; you can redistribute it and/or * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 10 | * modify it under the terms of version 2 of the GNU General * |
| 11 | * Public License as published by the Free Software Foundation. * |
| 12 | * This program is distributed in the hope that it will be useful. * |
| 13 | * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * |
| 14 | * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * |
| 15 | * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE * |
| 16 | * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD * |
| 17 | * TO BE LEGALLY INVALID. See the GNU General Public License for * |
| 18 | * more details, a copy of which can be found in the file COPYING * |
| 19 | * included with this package. * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 20 | *******************************************************************/ |
| 21 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 22 | #include <linux/blkdev.h> |
| 23 | #include <linux/delay.h> |
| 24 | #include <linux/dma-mapping.h> |
| 25 | #include <linux/idr.h> |
| 26 | #include <linux/interrupt.h> |
| 27 | #include <linux/kthread.h> |
| 28 | #include <linux/pci.h> |
| 29 | #include <linux/spinlock.h> |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 30 | #include <linux/ctype.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 31 | |
James.Smart@Emulex.Com | 9188652 | 2005-08-10 15:03:09 -0400 | [diff] [blame] | 32 | #include <scsi/scsi.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 33 | #include <scsi/scsi_device.h> |
| 34 | #include <scsi/scsi_host.h> |
| 35 | #include <scsi/scsi_transport_fc.h> |
| 36 | |
| 37 | #include "lpfc_hw.h" |
| 38 | #include "lpfc_sli.h" |
| 39 | #include "lpfc_disc.h" |
| 40 | #include "lpfc_scsi.h" |
| 41 | #include "lpfc.h" |
| 42 | #include "lpfc_logmsg.h" |
| 43 | #include "lpfc_crtn.h" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 44 | #include "lpfc_vport.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 45 | #include "lpfc_version.h" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 46 | #include "lpfc_vport.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 47 | |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 48 | static int lpfc_parse_vpd(struct lpfc_hba *, uint8_t *, int); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 49 | static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *); |
| 50 | static int lpfc_post_rcv_buf(struct lpfc_hba *); |
| 51 | |
| 52 | static struct scsi_transport_template *lpfc_transport_template = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 53 | static struct scsi_transport_template *lpfc_vport_transport_template = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 54 | static DEFINE_IDR(lpfc_hba_index); |
| 55 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 56 | |
| 57 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 58 | /************************************************************************/ |
| 59 | /* */ |
| 60 | /* lpfc_config_port_prep */ |
| 61 | /* This routine will do LPFC initialization prior to the */ |
| 62 | /* CONFIG_PORT mailbox command. This will be initialized */ |
| 63 | /* as a SLI layer callback routine. */ |
| 64 | /* This routine returns 0 on success or -ERESTART if it wants */ |
| 65 | /* the SLI layer to reset the HBA and try again. Any */ |
| 66 | /* other return value indicates an error. */ |
| 67 | /* */ |
| 68 | /************************************************************************/ |
| 69 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 70 | lpfc_config_port_prep(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 71 | { |
| 72 | lpfc_vpd_t *vp = &phba->vpd; |
| 73 | int i = 0, rc; |
| 74 | LPFC_MBOXQ_t *pmb; |
| 75 | MAILBOX_t *mb; |
| 76 | char *lpfc_vpd_data = NULL; |
| 77 | uint16_t offset = 0; |
| 78 | static char licensed[56] = |
| 79 | "key unlock for use with gnu public licensed code only\0"; |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 80 | static int init_key = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 81 | |
| 82 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 83 | if (!pmb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 84 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 85 | return -ENOMEM; |
| 86 | } |
| 87 | |
| 88 | mb = &pmb->mb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 89 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 90 | |
| 91 | if (lpfc_is_LC_HBA(phba->pcidev->device)) { |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 92 | if (init_key) { |
| 93 | uint32_t *ptext = (uint32_t *) licensed; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 94 | |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 95 | for (i = 0; i < 56; i += sizeof (uint32_t), ptext++) |
| 96 | *ptext = cpu_to_be32(*ptext); |
| 97 | init_key = 0; |
| 98 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 99 | |
| 100 | lpfc_read_nv(phba, pmb); |
| 101 | memset((char*)mb->un.varRDnvp.rsvd3, 0, |
| 102 | sizeof (mb->un.varRDnvp.rsvd3)); |
| 103 | memcpy((char*)mb->un.varRDnvp.rsvd3, licensed, |
| 104 | sizeof (licensed)); |
| 105 | |
| 106 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 107 | |
| 108 | if (rc != MBX_SUCCESS) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 109 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 110 | "%d:0324 Config Port initialization " |
| 111 | "error, mbxCmd x%x READ_NVPARM, " |
| 112 | "mbxStatus x%x\n", |
| 113 | phba->brd_no, |
| 114 | mb->mbxCommand, mb->mbxStatus); |
| 115 | mempool_free(pmb, phba->mbox_mem_pool); |
| 116 | return -ERESTART; |
| 117 | } |
| 118 | memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 119 | sizeof(phba->wwnn)); |
| 120 | memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname, |
| 121 | sizeof(phba->wwpn)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 122 | } |
| 123 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 124 | phba->sli3_options = 0x0; |
| 125 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 126 | /* Setup and issue mailbox READ REV command */ |
| 127 | lpfc_read_rev(phba, pmb); |
| 128 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 129 | if (rc != MBX_SUCCESS) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 130 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 131 | "%d:0439 Adapter failed to init, mbxCmd x%x " |
| 132 | "READ_REV, mbxStatus x%x\n", |
| 133 | phba->brd_no, |
| 134 | mb->mbxCommand, mb->mbxStatus); |
| 135 | mempool_free( pmb, phba->mbox_mem_pool); |
| 136 | return -ERESTART; |
| 137 | } |
| 138 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 139 | |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 140 | /* |
| 141 | * The value of rr must be 1 since the driver set the cv field to 1. |
| 142 | * This setting requires the FW to set all revision fields. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 143 | */ |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 144 | if (mb->un.varRdRev.rr == 0) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 145 | vp->rev.rBit = 0; |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 146 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 147 | "%d:0440 Adapter failed to init, READ_REV has " |
| 148 | "missing revision information.\n", |
| 149 | phba->brd_no); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 150 | mempool_free(pmb, phba->mbox_mem_pool); |
| 151 | return -ERESTART; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 152 | } |
| 153 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 154 | if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) |
| 155 | return -EINVAL; |
| 156 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 157 | /* Save information as VPD data */ |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 158 | vp->rev.rBit = 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 159 | memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t)); |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 160 | vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev; |
| 161 | memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16); |
| 162 | vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev; |
| 163 | memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 164 | vp->rev.biuRev = mb->un.varRdRev.biuRev; |
| 165 | vp->rev.smRev = mb->un.varRdRev.smRev; |
| 166 | vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev; |
| 167 | vp->rev.endecRev = mb->un.varRdRev.endecRev; |
| 168 | vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh; |
| 169 | vp->rev.fcphLow = mb->un.varRdRev.fcphLow; |
| 170 | vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh; |
| 171 | vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow; |
| 172 | vp->rev.postKernRev = mb->un.varRdRev.postKernRev; |
| 173 | vp->rev.opFwRev = mb->un.varRdRev.opFwRev; |
| 174 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 175 | /* If the sli feature level is less then 9, we must |
| 176 | * tear down all RPIs and VPIs on link down if NPIV |
| 177 | * is enabled. |
| 178 | */ |
| 179 | if (vp->rev.feaLevelHigh < 9) |
| 180 | phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN; |
| 181 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 182 | if (lpfc_is_LC_HBA(phba->pcidev->device)) |
| 183 | memcpy(phba->RandomData, (char *)&mb->un.varWords[24], |
| 184 | sizeof (phba->RandomData)); |
| 185 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 186 | /* Get adapter VPD information */ |
| 187 | pmb->context2 = kmalloc(DMP_RSP_SIZE, GFP_KERNEL); |
| 188 | if (!pmb->context2) |
| 189 | goto out_free_mbox; |
| 190 | lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL); |
| 191 | if (!lpfc_vpd_data) |
| 192 | goto out_free_context2; |
| 193 | |
| 194 | do { |
| 195 | lpfc_dump_mem(phba, pmb, offset); |
| 196 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 197 | |
| 198 | if (rc != MBX_SUCCESS) { |
| 199 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 200 | "%d:0441 VPD not present on adapter, " |
| 201 | "mbxCmd x%x DUMP VPD, mbxStatus x%x\n", |
| 202 | phba->brd_no, |
| 203 | mb->mbxCommand, mb->mbxStatus); |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 204 | mb->un.varDmp.word_cnt = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 205 | } |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 206 | if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset) |
| 207 | mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 208 | lpfc_sli_pcimem_bcopy(pmb->context2, lpfc_vpd_data + offset, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 209 | mb->un.varDmp.word_cnt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 210 | offset += mb->un.varDmp.word_cnt; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 211 | } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE); |
| 212 | lpfc_parse_vpd(phba, lpfc_vpd_data, offset); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 213 | |
| 214 | kfree(lpfc_vpd_data); |
| 215 | out_free_context2: |
| 216 | kfree(pmb->context2); |
| 217 | out_free_mbox: |
| 218 | mempool_free(pmb, phba->mbox_mem_pool); |
| 219 | return 0; |
| 220 | } |
| 221 | |
| 222 | /************************************************************************/ |
| 223 | /* */ |
| 224 | /* lpfc_config_port_post */ |
| 225 | /* This routine will do LPFC initialization after the */ |
| 226 | /* CONFIG_PORT mailbox command. This will be initialized */ |
| 227 | /* as a SLI layer callback routine. */ |
| 228 | /* This routine returns 0 on success. Any other return value */ |
| 229 | /* indicates an error. */ |
| 230 | /* */ |
| 231 | /************************************************************************/ |
| 232 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 233 | lpfc_config_port_post(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 234 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 235 | struct lpfc_vport *vport = phba->pport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 236 | LPFC_MBOXQ_t *pmb; |
| 237 | MAILBOX_t *mb; |
| 238 | struct lpfc_dmabuf *mp; |
| 239 | struct lpfc_sli *psli = &phba->sli; |
| 240 | uint32_t status, timeout; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 241 | int i, j; |
| 242 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 243 | |
| 244 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 245 | if (!pmb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 246 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 247 | return -ENOMEM; |
| 248 | } |
| 249 | mb = &pmb->mb; |
| 250 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 251 | /* Get login parameters for NID. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 252 | lpfc_read_sparam(phba, pmb, 0); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 253 | pmb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 254 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 255 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 256 | "%d:0448 Adapter failed init, mbxCmd x%x " |
| 257 | "READ_SPARM mbxStatus x%x\n", |
| 258 | phba->brd_no, |
| 259 | mb->mbxCommand, mb->mbxStatus); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 260 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 261 | mp = (struct lpfc_dmabuf *) pmb->context1; |
| 262 | mempool_free( pmb, phba->mbox_mem_pool); |
| 263 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 264 | kfree(mp); |
| 265 | return -EIO; |
| 266 | } |
| 267 | |
| 268 | mp = (struct lpfc_dmabuf *) pmb->context1; |
| 269 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 270 | memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 271 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 272 | kfree(mp); |
| 273 | pmb->context1 = NULL; |
| 274 | |
James Smart | a12e07b | 2006-12-02 13:35:30 -0500 | [diff] [blame] | 275 | if (phba->cfg_soft_wwnn) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 276 | u64_to_wwn(phba->cfg_soft_wwnn, |
| 277 | vport->fc_sparam.nodeName.u.wwn); |
James Smart | c3f28af | 2006-08-18 17:47:18 -0400 | [diff] [blame] | 278 | if (phba->cfg_soft_wwpn) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 279 | u64_to_wwn(phba->cfg_soft_wwpn, |
| 280 | vport->fc_sparam.portName.u.wwn); |
| 281 | memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 282 | sizeof (struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 283 | memcpy(&vport->fc_portname, &vport->fc_sparam.portName, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 284 | sizeof (struct lpfc_name)); |
| 285 | /* If no serial number in VPD data, use low 6 bytes of WWNN */ |
| 286 | /* This should be consolidated into parse_vpd ? - mr */ |
| 287 | if (phba->SerialNumber[0] == 0) { |
| 288 | uint8_t *outptr; |
| 289 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 290 | outptr = &vport->fc_nodename.u.s.IEEE[0]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 291 | for (i = 0; i < 12; i++) { |
| 292 | status = *outptr++; |
| 293 | j = ((status & 0xf0) >> 4); |
| 294 | if (j <= 9) |
| 295 | phba->SerialNumber[i] = |
| 296 | (char)((uint8_t) 0x30 + (uint8_t) j); |
| 297 | else |
| 298 | phba->SerialNumber[i] = |
| 299 | (char)((uint8_t) 0x61 + (uint8_t) (j - 10)); |
| 300 | i++; |
| 301 | j = (status & 0xf); |
| 302 | if (j <= 9) |
| 303 | phba->SerialNumber[i] = |
| 304 | (char)((uint8_t) 0x30 + (uint8_t) j); |
| 305 | else |
| 306 | phba->SerialNumber[i] = |
| 307 | (char)((uint8_t) 0x61 + (uint8_t) (j - 10)); |
| 308 | } |
| 309 | } |
| 310 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 311 | lpfc_read_config(phba, pmb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 312 | pmb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 313 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 314 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 315 | "%d:0453 Adapter failed to init, mbxCmd x%x " |
| 316 | "READ_CONFIG, mbxStatus x%x\n", |
| 317 | phba->brd_no, |
| 318 | mb->mbxCommand, mb->mbxStatus); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 319 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 320 | mempool_free( pmb, phba->mbox_mem_pool); |
| 321 | return -EIO; |
| 322 | } |
| 323 | |
| 324 | /* Reset the DFT_HBA_Q_DEPTH to the max xri */ |
| 325 | if (phba->cfg_hba_queue_depth > (mb->un.varRdConfig.max_xri+1)) |
| 326 | phba->cfg_hba_queue_depth = |
| 327 | mb->un.varRdConfig.max_xri + 1; |
| 328 | |
| 329 | phba->lmt = mb->un.varRdConfig.lmt; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 330 | |
| 331 | /* Get the default values for Model Name and Description */ |
| 332 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); |
| 333 | |
| 334 | if ((phba->cfg_link_speed > LINK_SPEED_10G) |
| 335 | || ((phba->cfg_link_speed == LINK_SPEED_1G) |
| 336 | && !(phba->lmt & LMT_1Gb)) |
| 337 | || ((phba->cfg_link_speed == LINK_SPEED_2G) |
| 338 | && !(phba->lmt & LMT_2Gb)) |
| 339 | || ((phba->cfg_link_speed == LINK_SPEED_4G) |
| 340 | && !(phba->lmt & LMT_4Gb)) |
| 341 | || ((phba->cfg_link_speed == LINK_SPEED_8G) |
| 342 | && !(phba->lmt & LMT_8Gb)) |
| 343 | || ((phba->cfg_link_speed == LINK_SPEED_10G) |
| 344 | && !(phba->lmt & LMT_10Gb))) { |
| 345 | /* Reset link speed to auto */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 346 | lpfc_printf_log(phba, KERN_WARNING, LOG_LINK_EVENT, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 347 | "%d:1302 Invalid speed for this board: " |
| 348 | "Reset link speed to auto: x%x\n", |
| 349 | phba->brd_no, |
| 350 | phba->cfg_link_speed); |
| 351 | phba->cfg_link_speed = LINK_SPEED_AUTO; |
| 352 | } |
| 353 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 354 | phba->link_state = LPFC_LINK_DOWN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 355 | |
| 356 | /* Only process IOCBs on ring 0 till hba_state is READY */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 357 | if (psli->ring[psli->extra_ring].cmdringaddr) |
| 358 | psli->ring[psli->extra_ring].flag |= LPFC_STOP_IOCB_EVENT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 359 | if (psli->ring[psli->fcp_ring].cmdringaddr) |
| 360 | psli->ring[psli->fcp_ring].flag |= LPFC_STOP_IOCB_EVENT; |
| 361 | if (psli->ring[psli->next_ring].cmdringaddr) |
| 362 | psli->ring[psli->next_ring].flag |= LPFC_STOP_IOCB_EVENT; |
| 363 | |
| 364 | /* Post receive buffers for desired rings */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 365 | if (phba->sli_rev != 3) |
| 366 | lpfc_post_rcv_buf(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 367 | |
| 368 | /* Enable appropriate host interrupts */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 369 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 370 | status = readl(phba->HCregaddr); |
| 371 | status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA; |
| 372 | if (psli->num_rings > 0) |
| 373 | status |= HC_R0INT_ENA; |
| 374 | if (psli->num_rings > 1) |
| 375 | status |= HC_R1INT_ENA; |
| 376 | if (psli->num_rings > 2) |
| 377 | status |= HC_R2INT_ENA; |
| 378 | if (psli->num_rings > 3) |
| 379 | status |= HC_R3INT_ENA; |
| 380 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 381 | if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) && |
| 382 | (phba->cfg_poll & DISABLE_FCP_RING_INT)) |
| 383 | status &= ~(HC_R0INT_ENA << LPFC_FCP_RING); |
| 384 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 385 | writel(status, phba->HCregaddr); |
| 386 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 387 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 388 | |
| 389 | /* |
| 390 | * Setup the ring 0 (els) timeout handler |
| 391 | */ |
| 392 | timeout = phba->fc_ratov << 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 393 | mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame^] | 394 | mod_timer(&phba->hb_tmofunc, jiffies + HZ * LPFC_HB_MBOX_INTERVAL); |
| 395 | phba->hb_outstanding = 0; |
| 396 | phba->last_completion_time = jiffies; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 397 | |
| 398 | lpfc_init_link(phba, pmb, phba->cfg_topology, phba->cfg_link_speed); |
| 399 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 400 | pmb->vport = vport; |
James Smart | 8aee918 | 2006-08-31 12:27:57 -0400 | [diff] [blame] | 401 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 402 | lpfc_set_loopback_flag(phba); |
James Smart | 8aee918 | 2006-08-31 12:27:57 -0400 | [diff] [blame] | 403 | if (rc != MBX_SUCCESS) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 404 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 405 | "%d:0454 Adapter failed to init, mbxCmd x%x " |
| 406 | "INIT_LINK, mbxStatus x%x\n", |
| 407 | phba->brd_no, |
| 408 | mb->mbxCommand, mb->mbxStatus); |
| 409 | |
| 410 | /* Clear all interrupt enable conditions */ |
| 411 | writel(0, phba->HCregaddr); |
| 412 | readl(phba->HCregaddr); /* flush */ |
| 413 | /* Clear all pending interrupts */ |
| 414 | writel(0xffffffff, phba->HAregaddr); |
| 415 | readl(phba->HAregaddr); /* flush */ |
| 416 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 417 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | 8aee918 | 2006-08-31 12:27:57 -0400 | [diff] [blame] | 418 | if (rc != MBX_BUSY) |
| 419 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 420 | return -EIO; |
| 421 | } |
| 422 | /* MBOX buffer will be freed in mbox compl */ |
| 423 | |
James Smart | ce8b3ce | 2006-07-06 15:50:36 -0400 | [diff] [blame] | 424 | return (0); |
| 425 | } |
| 426 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 427 | /************************************************************************/ |
| 428 | /* */ |
| 429 | /* lpfc_hba_down_prep */ |
| 430 | /* This routine will do LPFC uninitialization before the */ |
| 431 | /* HBA is reset when bringing down the SLI Layer. This will be */ |
| 432 | /* initialized as a SLI layer callback routine. */ |
| 433 | /* This routine returns 0 on success. Any other return value */ |
| 434 | /* indicates an error. */ |
| 435 | /* */ |
| 436 | /************************************************************************/ |
| 437 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 438 | lpfc_hba_down_prep(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 439 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 440 | struct lpfc_vport *vport = phba->pport; |
| 441 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 442 | /* Disable interrupts */ |
| 443 | writel(0, phba->HCregaddr); |
| 444 | readl(phba->HCregaddr); /* flush */ |
| 445 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 446 | list_for_each_entry(vport, &phba->port_list, listentry) { |
| 447 | lpfc_cleanup_discovery_resources(vport); |
| 448 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 449 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 450 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | /************************************************************************/ |
| 454 | /* */ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 455 | /* lpfc_hba_down_post */ |
| 456 | /* This routine will do uninitialization after the HBA is reset */ |
| 457 | /* when bringing down the SLI Layer. */ |
| 458 | /* This routine returns 0 on success. Any other return value */ |
| 459 | /* indicates an error. */ |
| 460 | /* */ |
| 461 | /************************************************************************/ |
| 462 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 463 | lpfc_hba_down_post(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 464 | { |
| 465 | struct lpfc_sli *psli = &phba->sli; |
| 466 | struct lpfc_sli_ring *pring; |
| 467 | struct lpfc_dmabuf *mp, *next_mp; |
| 468 | int i; |
| 469 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 470 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) |
| 471 | lpfc_sli_hbqbuf_free_all(phba); |
| 472 | else { |
| 473 | /* Cleanup preposted buffers on the ELS ring */ |
| 474 | pring = &psli->ring[LPFC_ELS_RING]; |
| 475 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 476 | list_del(&mp->list); |
| 477 | pring->postbufq_cnt--; |
| 478 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 479 | kfree(mp); |
| 480 | } |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 481 | } |
| 482 | |
| 483 | for (i = 0; i < psli->num_rings; i++) { |
| 484 | pring = &psli->ring[i]; |
| 485 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 486 | } |
| 487 | |
| 488 | return 0; |
| 489 | } |
| 490 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame^] | 491 | /* HBA heart beat timeout handler */ |
| 492 | void |
| 493 | lpfc_hb_timeout(unsigned long ptr) |
| 494 | { |
| 495 | struct lpfc_hba *phba; |
| 496 | unsigned long iflag; |
| 497 | |
| 498 | phba = (struct lpfc_hba *)ptr; |
| 499 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
| 500 | if (!(phba->pport->work_port_events & WORKER_HB_TMO)) |
| 501 | phba->pport->work_port_events |= WORKER_HB_TMO; |
| 502 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
| 503 | |
| 504 | if (phba->work_wait) |
| 505 | wake_up(phba->work_wait); |
| 506 | return; |
| 507 | } |
| 508 | |
| 509 | static void |
| 510 | lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq) |
| 511 | { |
| 512 | unsigned long drvr_flag; |
| 513 | |
| 514 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 515 | phba->hb_outstanding = 0; |
| 516 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 517 | |
| 518 | mempool_free(pmboxq, phba->mbox_mem_pool); |
| 519 | if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) && |
| 520 | !(phba->link_state == LPFC_HBA_ERROR) && |
| 521 | !(phba->pport->fc_flag & FC_UNLOADING)) |
| 522 | mod_timer(&phba->hb_tmofunc, |
| 523 | jiffies + HZ * LPFC_HB_MBOX_INTERVAL); |
| 524 | return; |
| 525 | } |
| 526 | |
| 527 | void |
| 528 | lpfc_hb_timeout_handler(struct lpfc_hba *phba) |
| 529 | { |
| 530 | LPFC_MBOXQ_t *pmboxq; |
| 531 | int retval; |
| 532 | struct lpfc_sli *psli = &phba->sli; |
| 533 | |
| 534 | if ((phba->link_state == LPFC_HBA_ERROR) || |
| 535 | (phba->pport->fc_flag & FC_UNLOADING) || |
| 536 | (phba->pport->fc_flag & FC_OFFLINE_MODE)) |
| 537 | return; |
| 538 | |
| 539 | spin_lock_irq(&phba->pport->work_port_lock); |
| 540 | /* If the timer is already canceled do nothing */ |
| 541 | if (!(phba->pport->work_port_events & WORKER_HB_TMO)) { |
| 542 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 543 | return; |
| 544 | } |
| 545 | |
| 546 | if (time_after(phba->last_completion_time + LPFC_HB_MBOX_INTERVAL * HZ, |
| 547 | jiffies)) { |
| 548 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 549 | if (!phba->hb_outstanding) |
| 550 | mod_timer(&phba->hb_tmofunc, |
| 551 | jiffies + HZ * LPFC_HB_MBOX_INTERVAL); |
| 552 | else |
| 553 | mod_timer(&phba->hb_tmofunc, |
| 554 | jiffies + HZ * LPFC_HB_MBOX_TIMEOUT); |
| 555 | return; |
| 556 | } |
| 557 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 558 | |
| 559 | /* If there is no heart beat outstanding, issue a heartbeat command */ |
| 560 | if (!phba->hb_outstanding) { |
| 561 | pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL); |
| 562 | if (!pmboxq) { |
| 563 | mod_timer(&phba->hb_tmofunc, |
| 564 | jiffies + HZ * LPFC_HB_MBOX_INTERVAL); |
| 565 | return; |
| 566 | } |
| 567 | |
| 568 | lpfc_heart_beat(phba, pmboxq); |
| 569 | pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl; |
| 570 | pmboxq->vport = phba->pport; |
| 571 | retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT); |
| 572 | |
| 573 | if (retval != MBX_BUSY && retval != MBX_SUCCESS) { |
| 574 | mempool_free(pmboxq, phba->mbox_mem_pool); |
| 575 | mod_timer(&phba->hb_tmofunc, |
| 576 | jiffies + HZ * LPFC_HB_MBOX_INTERVAL); |
| 577 | return; |
| 578 | } |
| 579 | mod_timer(&phba->hb_tmofunc, |
| 580 | jiffies + HZ * LPFC_HB_MBOX_TIMEOUT); |
| 581 | phba->hb_outstanding = 1; |
| 582 | return; |
| 583 | } else { |
| 584 | /* |
| 585 | * If heart beat timeout called with hb_outstanding set we |
| 586 | * need to take the HBA offline. |
| 587 | */ |
| 588 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 589 | "%d:0459 Adapter heartbeat failure, taking " |
| 590 | "this port offline.\n", phba->brd_no); |
| 591 | |
| 592 | spin_lock_irq(&phba->hbalock); |
| 593 | psli->sli_flag &= ~LPFC_SLI2_ACTIVE; |
| 594 | spin_unlock_irq(&phba->hbalock); |
| 595 | |
| 596 | lpfc_offline_prep(phba); |
| 597 | lpfc_offline(phba); |
| 598 | lpfc_unblock_mgmt_io(phba); |
| 599 | phba->link_state = LPFC_HBA_ERROR; |
| 600 | lpfc_hba_down_post(phba); |
| 601 | } |
| 602 | } |
| 603 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 604 | /************************************************************************/ |
| 605 | /* */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 606 | /* lpfc_handle_eratt */ |
| 607 | /* This routine will handle processing a Host Attention */ |
| 608 | /* Error Status event. This will be initialized */ |
| 609 | /* as a SLI layer callback routine. */ |
| 610 | /* */ |
| 611 | /************************************************************************/ |
| 612 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 613 | lpfc_handle_eratt(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 614 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 615 | struct lpfc_vport *vport = phba->pport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 616 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 617 | struct lpfc_sli_ring *pring; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 618 | struct lpfc_vport *port_iterator; |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 619 | uint32_t event_data; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 620 | struct Scsi_Host *shost; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 621 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 622 | /* If the pci channel is offline, ignore possible errors, |
| 623 | * since we cannot communicate with the pci card anyway. */ |
| 624 | if (pci_channel_offline(phba->pcidev)) |
| 625 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 626 | |
James Smart | f560351 | 2006-12-02 13:35:43 -0500 | [diff] [blame] | 627 | if (phba->work_hs & HS_FFER6 || |
| 628 | phba->work_hs & HS_FFER5) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 629 | /* Re-establishing Link */ |
| 630 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
| 631 | "%d:1301 Re-establishing Link " |
| 632 | "Data: x%x x%x x%x\n", |
| 633 | phba->brd_no, phba->work_hs, |
| 634 | phba->work_status[0], phba->work_status[1]); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 635 | list_for_each_entry(port_iterator, &phba->port_list, |
| 636 | listentry) { |
| 637 | shost = lpfc_shost_from_vport(port_iterator); |
| 638 | |
| 639 | spin_lock_irq(shost->host_lock); |
| 640 | port_iterator->fc_flag |= FC_ESTABLISH_LINK; |
| 641 | spin_unlock_irq(shost->host_lock); |
| 642 | } |
| 643 | spin_lock_irq(&phba->hbalock); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 644 | psli->sli_flag &= ~LPFC_SLI2_ACTIVE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 645 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 646 | |
| 647 | /* |
| 648 | * Firmware stops when it triggled erratt with HS_FFER6. |
| 649 | * That could cause the I/Os dropped by the firmware. |
| 650 | * Error iocb (I/O) on txcmplq and let the SCSI layer |
| 651 | * retry it after re-establishing link. |
| 652 | */ |
| 653 | pring = &psli->ring[psli->fcp_ring]; |
| 654 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 655 | |
| 656 | |
| 657 | /* |
| 658 | * There was a firmware error. Take the hba offline and then |
| 659 | * attempt to restart it. |
| 660 | */ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 661 | lpfc_offline_prep(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 662 | lpfc_offline(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 663 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 664 | if (lpfc_online(phba) == 0) { /* Initialize the HBA */ |
| 665 | mod_timer(&phba->fc_estabtmo, jiffies + HZ * 60); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 666 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 667 | return; |
| 668 | } |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 669 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 670 | } else { |
| 671 | /* The if clause above forces this code path when the status |
| 672 | * failure is a value other than FFER6. Do not call the offline |
| 673 | * twice. This is the adapter hardware error path. |
| 674 | */ |
| 675 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 676 | "%d:0457 Adapter Hardware Error " |
| 677 | "Data: x%x x%x x%x\n", |
| 678 | phba->brd_no, phba->work_hs, |
| 679 | phba->work_status[0], phba->work_status[1]); |
| 680 | |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 681 | event_data = FC_REG_DUMP_EVENT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 682 | shost = lpfc_shost_from_vport(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 683 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 684 | sizeof(event_data), (char *) &event_data, |
| 685 | SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX); |
| 686 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 687 | spin_lock_irq(&phba->hbalock); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 688 | psli->sli_flag &= ~LPFC_SLI2_ACTIVE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 689 | spin_unlock_irq(&phba->hbalock); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 690 | lpfc_offline_prep(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 691 | lpfc_offline(phba); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 692 | lpfc_unblock_mgmt_io(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 693 | phba->link_state = LPFC_HBA_ERROR; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 694 | lpfc_hba_down_post(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 695 | } |
| 696 | } |
| 697 | |
| 698 | /************************************************************************/ |
| 699 | /* */ |
| 700 | /* lpfc_handle_latt */ |
| 701 | /* This routine will handle processing a Host Attention */ |
| 702 | /* Link Status event. This will be initialized */ |
| 703 | /* as a SLI layer callback routine. */ |
| 704 | /* */ |
| 705 | /************************************************************************/ |
| 706 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 707 | lpfc_handle_latt(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 708 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 709 | struct lpfc_vport *vport = phba->pport; |
| 710 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 711 | struct lpfc_vport *port_iterator; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 712 | LPFC_MBOXQ_t *pmb; |
| 713 | volatile uint32_t control; |
| 714 | struct lpfc_dmabuf *mp; |
| 715 | int rc = -ENOMEM; |
| 716 | |
| 717 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 718 | if (!pmb) |
| 719 | goto lpfc_handle_latt_err_exit; |
| 720 | |
| 721 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 722 | if (!mp) |
| 723 | goto lpfc_handle_latt_free_pmb; |
| 724 | |
| 725 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
| 726 | if (!mp->virt) |
| 727 | goto lpfc_handle_latt_free_mp; |
| 728 | |
| 729 | rc = -EIO; |
| 730 | |
James.Smart@Emulex.Com | 6281bfe | 2005-11-28 11:41:33 -0500 | [diff] [blame] | 731 | /* Cleanup any outstanding ELS commands */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 732 | list_for_each_entry(port_iterator, &phba->port_list, listentry) |
| 733 | lpfc_els_flush_cmd(port_iterator); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 734 | |
| 735 | psli->slistat.link_event++; |
| 736 | lpfc_read_la(phba, pmb, mp); |
| 737 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_la; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 738 | pmb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 739 | rc = lpfc_sli_issue_mbox (phba, pmb, (MBX_NOWAIT | MBX_STOP_IOCB)); |
| 740 | if (rc == MBX_NOT_FINISHED) |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 741 | goto lpfc_handle_latt_free_mbuf; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 742 | |
| 743 | /* Clear Link Attention in HA REG */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 744 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 745 | writel(HA_LATT, phba->HAregaddr); |
| 746 | readl(phba->HAregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 747 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 748 | |
| 749 | return; |
| 750 | |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 751 | lpfc_handle_latt_free_mbuf: |
| 752 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 753 | lpfc_handle_latt_free_mp: |
| 754 | kfree(mp); |
| 755 | lpfc_handle_latt_free_pmb: |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 756 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 757 | lpfc_handle_latt_err_exit: |
| 758 | /* Enable Link attention interrupts */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 759 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 760 | psli->sli_flag |= LPFC_PROCESS_LA; |
| 761 | control = readl(phba->HCregaddr); |
| 762 | control |= HC_LAINT_ENA; |
| 763 | writel(control, phba->HCregaddr); |
| 764 | readl(phba->HCregaddr); /* flush */ |
| 765 | |
| 766 | /* Clear Link Attention in HA REG */ |
| 767 | writel(HA_LATT, phba->HAregaddr); |
| 768 | readl(phba->HAregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 769 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 770 | lpfc_linkdown(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 771 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 772 | |
| 773 | /* The other case is an error from issue_mbox */ |
| 774 | if (rc == -ENOMEM) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 775 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 776 | "%d:0300 READ_LA: no buffers\n", |
| 777 | phba->brd_no); |
| 778 | |
| 779 | return; |
| 780 | } |
| 781 | |
| 782 | /************************************************************************/ |
| 783 | /* */ |
| 784 | /* lpfc_parse_vpd */ |
| 785 | /* This routine will parse the VPD data */ |
| 786 | /* */ |
| 787 | /************************************************************************/ |
| 788 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 789 | lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 790 | { |
| 791 | uint8_t lenlo, lenhi; |
Anton Blanchard | 07da60c | 2007-03-21 08:41:47 -0500 | [diff] [blame] | 792 | int Length; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 793 | int i, j; |
| 794 | int finished = 0; |
| 795 | int index = 0; |
| 796 | |
| 797 | if (!vpd) |
| 798 | return 0; |
| 799 | |
| 800 | /* Vital Product */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 801 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 802 | "%d:0455 Vital Product Data: x%x x%x x%x x%x\n", |
| 803 | phba->brd_no, |
| 804 | (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2], |
| 805 | (uint32_t) vpd[3]); |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 806 | while (!finished && (index < (len - 4))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 807 | switch (vpd[index]) { |
| 808 | case 0x82: |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 809 | case 0x91: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 810 | index += 1; |
| 811 | lenlo = vpd[index]; |
| 812 | index += 1; |
| 813 | lenhi = vpd[index]; |
| 814 | index += 1; |
| 815 | i = ((((unsigned short)lenhi) << 8) + lenlo); |
| 816 | index += i; |
| 817 | break; |
| 818 | case 0x90: |
| 819 | index += 1; |
| 820 | lenlo = vpd[index]; |
| 821 | index += 1; |
| 822 | lenhi = vpd[index]; |
| 823 | index += 1; |
| 824 | Length = ((((unsigned short)lenhi) << 8) + lenlo); |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 825 | if (Length > len - index) |
| 826 | Length = len - index; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 827 | while (Length > 0) { |
| 828 | /* Look for Serial Number */ |
| 829 | if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) { |
| 830 | index += 2; |
| 831 | i = vpd[index]; |
| 832 | index += 1; |
| 833 | j = 0; |
| 834 | Length -= (3+i); |
| 835 | while(i--) { |
| 836 | phba->SerialNumber[j++] = vpd[index++]; |
| 837 | if (j == 31) |
| 838 | break; |
| 839 | } |
| 840 | phba->SerialNumber[j] = 0; |
| 841 | continue; |
| 842 | } |
| 843 | else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) { |
| 844 | phba->vpd_flag |= VPD_MODEL_DESC; |
| 845 | index += 2; |
| 846 | i = vpd[index]; |
| 847 | index += 1; |
| 848 | j = 0; |
| 849 | Length -= (3+i); |
| 850 | while(i--) { |
| 851 | phba->ModelDesc[j++] = vpd[index++]; |
| 852 | if (j == 255) |
| 853 | break; |
| 854 | } |
| 855 | phba->ModelDesc[j] = 0; |
| 856 | continue; |
| 857 | } |
| 858 | else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) { |
| 859 | phba->vpd_flag |= VPD_MODEL_NAME; |
| 860 | index += 2; |
| 861 | i = vpd[index]; |
| 862 | index += 1; |
| 863 | j = 0; |
| 864 | Length -= (3+i); |
| 865 | while(i--) { |
| 866 | phba->ModelName[j++] = vpd[index++]; |
| 867 | if (j == 79) |
| 868 | break; |
| 869 | } |
| 870 | phba->ModelName[j] = 0; |
| 871 | continue; |
| 872 | } |
| 873 | else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) { |
| 874 | phba->vpd_flag |= VPD_PROGRAM_TYPE; |
| 875 | index += 2; |
| 876 | i = vpd[index]; |
| 877 | index += 1; |
| 878 | j = 0; |
| 879 | Length -= (3+i); |
| 880 | while(i--) { |
| 881 | phba->ProgramType[j++] = vpd[index++]; |
| 882 | if (j == 255) |
| 883 | break; |
| 884 | } |
| 885 | phba->ProgramType[j] = 0; |
| 886 | continue; |
| 887 | } |
| 888 | else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) { |
| 889 | phba->vpd_flag |= VPD_PORT; |
| 890 | index += 2; |
| 891 | i = vpd[index]; |
| 892 | index += 1; |
| 893 | j = 0; |
| 894 | Length -= (3+i); |
| 895 | while(i--) { |
| 896 | phba->Port[j++] = vpd[index++]; |
| 897 | if (j == 19) |
| 898 | break; |
| 899 | } |
| 900 | phba->Port[j] = 0; |
| 901 | continue; |
| 902 | } |
| 903 | else { |
| 904 | index += 2; |
| 905 | i = vpd[index]; |
| 906 | index += 1; |
| 907 | index += i; |
| 908 | Length -= (3 + i); |
| 909 | } |
| 910 | } |
| 911 | finished = 0; |
| 912 | break; |
| 913 | case 0x78: |
| 914 | finished = 1; |
| 915 | break; |
| 916 | default: |
| 917 | index ++; |
| 918 | break; |
| 919 | } |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 920 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 921 | |
| 922 | return(1); |
| 923 | } |
| 924 | |
| 925 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 926 | lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 927 | { |
| 928 | lpfc_vpd_t *vp; |
James.Smart@Emulex.Com | fefcb2b | 2005-11-28 15:08:56 -0500 | [diff] [blame] | 929 | uint16_t dev_id = phba->pcidev->device; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 930 | int max_speed; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 931 | struct { |
| 932 | char * name; |
| 933 | int max_speed; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 934 | char * bus; |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 935 | } m = {"<Unknown>", 0, ""}; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 936 | |
| 937 | if (mdp && mdp[0] != '\0' |
| 938 | && descp && descp[0] != '\0') |
| 939 | return; |
| 940 | |
| 941 | if (phba->lmt & LMT_10Gb) |
| 942 | max_speed = 10; |
| 943 | else if (phba->lmt & LMT_8Gb) |
| 944 | max_speed = 8; |
| 945 | else if (phba->lmt & LMT_4Gb) |
| 946 | max_speed = 4; |
| 947 | else if (phba->lmt & LMT_2Gb) |
| 948 | max_speed = 2; |
| 949 | else |
| 950 | max_speed = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 951 | |
| 952 | vp = &phba->vpd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 953 | |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 954 | switch (dev_id) { |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 955 | case PCI_DEVICE_ID_FIREFLY: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 956 | m = (typeof(m)){"LP6000", max_speed, "PCI"}; |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 957 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 958 | case PCI_DEVICE_ID_SUPERFLY: |
| 959 | if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3) |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 960 | m = (typeof(m)){"LP7000", max_speed, "PCI"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 961 | else |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 962 | m = (typeof(m)){"LP7000E", max_speed, "PCI"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 963 | break; |
| 964 | case PCI_DEVICE_ID_DRAGONFLY: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 965 | m = (typeof(m)){"LP8000", max_speed, "PCI"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 966 | break; |
| 967 | case PCI_DEVICE_ID_CENTAUR: |
| 968 | if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID) |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 969 | m = (typeof(m)){"LP9002", max_speed, "PCI"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 970 | else |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 971 | m = (typeof(m)){"LP9000", max_speed, "PCI"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 972 | break; |
| 973 | case PCI_DEVICE_ID_RFLY: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 974 | m = (typeof(m)){"LP952", max_speed, "PCI"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 975 | break; |
| 976 | case PCI_DEVICE_ID_PEGASUS: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 977 | m = (typeof(m)){"LP9802", max_speed, "PCI-X"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 978 | break; |
| 979 | case PCI_DEVICE_ID_THOR: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 980 | m = (typeof(m)){"LP10000", max_speed, "PCI-X"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 981 | break; |
| 982 | case PCI_DEVICE_ID_VIPER: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 983 | m = (typeof(m)){"LPX1000", max_speed, "PCI-X"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 984 | break; |
| 985 | case PCI_DEVICE_ID_PFLY: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 986 | m = (typeof(m)){"LP982", max_speed, "PCI-X"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 987 | break; |
| 988 | case PCI_DEVICE_ID_TFLY: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 989 | m = (typeof(m)){"LP1050", max_speed, "PCI-X"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 990 | break; |
| 991 | case PCI_DEVICE_ID_HELIOS: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 992 | m = (typeof(m)){"LP11000", max_speed, "PCI-X2"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 993 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 994 | case PCI_DEVICE_ID_HELIOS_SCSP: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 995 | m = (typeof(m)){"LP11000-SP", max_speed, "PCI-X2"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 996 | break; |
| 997 | case PCI_DEVICE_ID_HELIOS_DCSP: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 998 | m = (typeof(m)){"LP11002-SP", max_speed, "PCI-X2"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 999 | break; |
| 1000 | case PCI_DEVICE_ID_NEPTUNE: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1001 | m = (typeof(m)){"LPe1000", max_speed, "PCIe"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1002 | break; |
| 1003 | case PCI_DEVICE_ID_NEPTUNE_SCSP: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1004 | m = (typeof(m)){"LPe1000-SP", max_speed, "PCIe"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1005 | break; |
| 1006 | case PCI_DEVICE_ID_NEPTUNE_DCSP: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1007 | m = (typeof(m)){"LPe1002-SP", max_speed, "PCIe"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1008 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1009 | case PCI_DEVICE_ID_BMID: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1010 | m = (typeof(m)){"LP1150", max_speed, "PCI-X2"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1011 | break; |
| 1012 | case PCI_DEVICE_ID_BSMB: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1013 | m = (typeof(m)){"LP111", max_speed, "PCI-X2"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1014 | break; |
| 1015 | case PCI_DEVICE_ID_ZEPHYR: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1016 | m = (typeof(m)){"LPe11000", max_speed, "PCIe"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1017 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1018 | case PCI_DEVICE_ID_ZEPHYR_SCSP: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1019 | m = (typeof(m)){"LPe11000", max_speed, "PCIe"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1020 | break; |
| 1021 | case PCI_DEVICE_ID_ZEPHYR_DCSP: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1022 | m = (typeof(m)){"LPe11002-SP", max_speed, "PCIe"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1023 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1024 | case PCI_DEVICE_ID_ZMID: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1025 | m = (typeof(m)){"LPe1150", max_speed, "PCIe"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1026 | break; |
| 1027 | case PCI_DEVICE_ID_ZSMB: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1028 | m = (typeof(m)){"LPe111", max_speed, "PCIe"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1029 | break; |
| 1030 | case PCI_DEVICE_ID_LP101: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1031 | m = (typeof(m)){"LP101", max_speed, "PCI-X"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1032 | break; |
| 1033 | case PCI_DEVICE_ID_LP10000S: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1034 | m = (typeof(m)){"LP10000-S", max_speed, "PCI"}; |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 1035 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1036 | case PCI_DEVICE_ID_LP11000S: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1037 | m = (typeof(m)){"LP11000-S", max_speed, |
| 1038 | "PCI-X2"}; |
| 1039 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1040 | case PCI_DEVICE_ID_LPE11000S: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1041 | m = (typeof(m)){"LPe11000-S", max_speed, |
| 1042 | "PCIe"}; |
James.Smart@Emulex.Com | 5cc36b3 | 2005-11-28 11:42:19 -0500 | [diff] [blame] | 1043 | break; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 1044 | case PCI_DEVICE_ID_SAT: |
| 1045 | m = (typeof(m)){"LPe12000", max_speed, "PCIe"}; |
| 1046 | break; |
| 1047 | case PCI_DEVICE_ID_SAT_MID: |
| 1048 | m = (typeof(m)){"LPe1250", max_speed, "PCIe"}; |
| 1049 | break; |
| 1050 | case PCI_DEVICE_ID_SAT_SMB: |
| 1051 | m = (typeof(m)){"LPe121", max_speed, "PCIe"}; |
| 1052 | break; |
| 1053 | case PCI_DEVICE_ID_SAT_DCSP: |
| 1054 | m = (typeof(m)){"LPe12002-SP", max_speed, "PCIe"}; |
| 1055 | break; |
| 1056 | case PCI_DEVICE_ID_SAT_SCSP: |
| 1057 | m = (typeof(m)){"LPe12000-SP", max_speed, "PCIe"}; |
| 1058 | break; |
| 1059 | case PCI_DEVICE_ID_SAT_S: |
| 1060 | m = (typeof(m)){"LPe12000-S", max_speed, "PCIe"}; |
| 1061 | break; |
James.Smart@Emulex.Com | 5cc36b3 | 2005-11-28 11:42:19 -0500 | [diff] [blame] | 1062 | default: |
Randy Dunlap | 041976f | 2006-06-25 01:58:51 -0700 | [diff] [blame] | 1063 | m = (typeof(m)){ NULL }; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1064 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1065 | } |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1066 | |
| 1067 | if (mdp && mdp[0] == '\0') |
| 1068 | snprintf(mdp, 79,"%s", m.name); |
| 1069 | if (descp && descp[0] == '\0') |
| 1070 | snprintf(descp, 255, |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1071 | "Emulex %s %dGb %s Fibre Channel Adapter", |
| 1072 | m.name, m.max_speed, m.bus); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1073 | } |
| 1074 | |
| 1075 | /**************************************************/ |
| 1076 | /* lpfc_post_buffer */ |
| 1077 | /* */ |
| 1078 | /* This routine will post count buffers to the */ |
| 1079 | /* ring with the QUE_RING_BUF_CN command. This */ |
| 1080 | /* allows 3 buffers / command to be posted. */ |
| 1081 | /* Returns the number of buffers NOT posted. */ |
| 1082 | /**************************************************/ |
| 1083 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1084 | lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1085 | int type) |
| 1086 | { |
| 1087 | IOCB_t *icmd; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 1088 | struct lpfc_iocbq *iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1089 | struct lpfc_dmabuf *mp1, *mp2; |
| 1090 | |
| 1091 | cnt += pring->missbufcnt; |
| 1092 | |
| 1093 | /* While there are buffers to post */ |
| 1094 | while (cnt > 0) { |
| 1095 | /* Allocate buffer for command iocb */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 1096 | iocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1097 | if (iocb == NULL) { |
| 1098 | pring->missbufcnt = cnt; |
| 1099 | return cnt; |
| 1100 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1101 | icmd = &iocb->iocb; |
| 1102 | |
| 1103 | /* 2 buffers can be posted per command */ |
| 1104 | /* Allocate buffer to post */ |
| 1105 | mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); |
| 1106 | if (mp1) |
| 1107 | mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, |
| 1108 | &mp1->phys); |
| 1109 | if (mp1 == 0 || mp1->virt == 0) { |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 1110 | kfree(mp1); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1111 | lpfc_sli_release_iocbq(phba, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1112 | pring->missbufcnt = cnt; |
| 1113 | return cnt; |
| 1114 | } |
| 1115 | |
| 1116 | INIT_LIST_HEAD(&mp1->list); |
| 1117 | /* Allocate buffer to post */ |
| 1118 | if (cnt > 1) { |
| 1119 | mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); |
| 1120 | if (mp2) |
| 1121 | mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI, |
| 1122 | &mp2->phys); |
| 1123 | if (mp2 == 0 || mp2->virt == 0) { |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 1124 | kfree(mp2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1125 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); |
| 1126 | kfree(mp1); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1127 | lpfc_sli_release_iocbq(phba, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1128 | pring->missbufcnt = cnt; |
| 1129 | return cnt; |
| 1130 | } |
| 1131 | |
| 1132 | INIT_LIST_HEAD(&mp2->list); |
| 1133 | } else { |
| 1134 | mp2 = NULL; |
| 1135 | } |
| 1136 | |
| 1137 | icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys); |
| 1138 | icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys); |
| 1139 | icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE; |
| 1140 | icmd->ulpBdeCount = 1; |
| 1141 | cnt--; |
| 1142 | if (mp2) { |
| 1143 | icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys); |
| 1144 | icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys); |
| 1145 | icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE; |
| 1146 | cnt--; |
| 1147 | icmd->ulpBdeCount = 2; |
| 1148 | } |
| 1149 | |
| 1150 | icmd->ulpCommand = CMD_QUE_RING_BUF64_CN; |
| 1151 | icmd->ulpLe = 1; |
| 1152 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1153 | if (lpfc_sli_issue_iocb(phba, pring, iocb, 0) == IOCB_ERROR) { |
| 1154 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); |
| 1155 | kfree(mp1); |
| 1156 | cnt++; |
| 1157 | if (mp2) { |
| 1158 | lpfc_mbuf_free(phba, mp2->virt, mp2->phys); |
| 1159 | kfree(mp2); |
| 1160 | cnt++; |
| 1161 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1162 | lpfc_sli_release_iocbq(phba, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1163 | pring->missbufcnt = cnt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1164 | return cnt; |
| 1165 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1166 | lpfc_sli_ringpostbuf_put(phba, pring, mp1); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1167 | if (mp2) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1168 | lpfc_sli_ringpostbuf_put(phba, pring, mp2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1169 | } |
| 1170 | pring->missbufcnt = 0; |
| 1171 | return 0; |
| 1172 | } |
| 1173 | |
| 1174 | /************************************************************************/ |
| 1175 | /* */ |
| 1176 | /* lpfc_post_rcv_buf */ |
| 1177 | /* This routine post initial rcv buffers to the configured rings */ |
| 1178 | /* */ |
| 1179 | /************************************************************************/ |
| 1180 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1181 | lpfc_post_rcv_buf(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1182 | { |
| 1183 | struct lpfc_sli *psli = &phba->sli; |
| 1184 | |
| 1185 | /* Ring 0, ELS / CT buffers */ |
| 1186 | lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0, 1); |
| 1187 | /* Ring 2 - FCP no buffers needed */ |
| 1188 | |
| 1189 | return 0; |
| 1190 | } |
| 1191 | |
| 1192 | #define S(N,V) (((V)<<(N))|((V)>>(32-(N)))) |
| 1193 | |
| 1194 | /************************************************************************/ |
| 1195 | /* */ |
| 1196 | /* lpfc_sha_init */ |
| 1197 | /* */ |
| 1198 | /************************************************************************/ |
| 1199 | static void |
| 1200 | lpfc_sha_init(uint32_t * HashResultPointer) |
| 1201 | { |
| 1202 | HashResultPointer[0] = 0x67452301; |
| 1203 | HashResultPointer[1] = 0xEFCDAB89; |
| 1204 | HashResultPointer[2] = 0x98BADCFE; |
| 1205 | HashResultPointer[3] = 0x10325476; |
| 1206 | HashResultPointer[4] = 0xC3D2E1F0; |
| 1207 | } |
| 1208 | |
| 1209 | /************************************************************************/ |
| 1210 | /* */ |
| 1211 | /* lpfc_sha_iterate */ |
| 1212 | /* */ |
| 1213 | /************************************************************************/ |
| 1214 | static void |
| 1215 | lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer) |
| 1216 | { |
| 1217 | int t; |
| 1218 | uint32_t TEMP; |
| 1219 | uint32_t A, B, C, D, E; |
| 1220 | t = 16; |
| 1221 | do { |
| 1222 | HashWorkingPointer[t] = |
| 1223 | S(1, |
| 1224 | HashWorkingPointer[t - 3] ^ HashWorkingPointer[t - |
| 1225 | 8] ^ |
| 1226 | HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]); |
| 1227 | } while (++t <= 79); |
| 1228 | t = 0; |
| 1229 | A = HashResultPointer[0]; |
| 1230 | B = HashResultPointer[1]; |
| 1231 | C = HashResultPointer[2]; |
| 1232 | D = HashResultPointer[3]; |
| 1233 | E = HashResultPointer[4]; |
| 1234 | |
| 1235 | do { |
| 1236 | if (t < 20) { |
| 1237 | TEMP = ((B & C) | ((~B) & D)) + 0x5A827999; |
| 1238 | } else if (t < 40) { |
| 1239 | TEMP = (B ^ C ^ D) + 0x6ED9EBA1; |
| 1240 | } else if (t < 60) { |
| 1241 | TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC; |
| 1242 | } else { |
| 1243 | TEMP = (B ^ C ^ D) + 0xCA62C1D6; |
| 1244 | } |
| 1245 | TEMP += S(5, A) + E + HashWorkingPointer[t]; |
| 1246 | E = D; |
| 1247 | D = C; |
| 1248 | C = S(30, B); |
| 1249 | B = A; |
| 1250 | A = TEMP; |
| 1251 | } while (++t <= 79); |
| 1252 | |
| 1253 | HashResultPointer[0] += A; |
| 1254 | HashResultPointer[1] += B; |
| 1255 | HashResultPointer[2] += C; |
| 1256 | HashResultPointer[3] += D; |
| 1257 | HashResultPointer[4] += E; |
| 1258 | |
| 1259 | } |
| 1260 | |
| 1261 | /************************************************************************/ |
| 1262 | /* */ |
| 1263 | /* lpfc_challenge_key */ |
| 1264 | /* */ |
| 1265 | /************************************************************************/ |
| 1266 | static void |
| 1267 | lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking) |
| 1268 | { |
| 1269 | *HashWorking = (*RandomChallenge ^ *HashWorking); |
| 1270 | } |
| 1271 | |
| 1272 | /************************************************************************/ |
| 1273 | /* */ |
| 1274 | /* lpfc_hba_init */ |
| 1275 | /* */ |
| 1276 | /************************************************************************/ |
| 1277 | void |
| 1278 | lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit) |
| 1279 | { |
| 1280 | int t; |
| 1281 | uint32_t *HashWorking; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1282 | uint32_t *pwwnn = (uint32_t *) phba->wwnn; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1283 | |
| 1284 | HashWorking = kmalloc(80 * sizeof(uint32_t), GFP_KERNEL); |
| 1285 | if (!HashWorking) |
| 1286 | return; |
| 1287 | |
| 1288 | memset(HashWorking, 0, (80 * sizeof(uint32_t))); |
| 1289 | HashWorking[0] = HashWorking[78] = *pwwnn++; |
| 1290 | HashWorking[1] = HashWorking[79] = *pwwnn; |
| 1291 | |
| 1292 | for (t = 0; t < 7; t++) |
| 1293 | lpfc_challenge_key(phba->RandomData + t, HashWorking + t); |
| 1294 | |
| 1295 | lpfc_sha_init(hbainit); |
| 1296 | lpfc_sha_iterate(hbainit, HashWorking); |
| 1297 | kfree(HashWorking); |
| 1298 | } |
| 1299 | |
| 1300 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1301 | lpfc_cleanup(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1302 | { |
| 1303 | struct lpfc_nodelist *ndlp, *next_ndlp; |
| 1304 | |
| 1305 | /* clean up phba - lpfc specific */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1306 | lpfc_can_disctmo(vport); |
| 1307 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1308 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1309 | return; |
| 1310 | } |
| 1311 | |
| 1312 | static void |
| 1313 | lpfc_establish_link_tmo(unsigned long ptr) |
| 1314 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1315 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1316 | struct lpfc_vport *vport = phba->pport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1317 | unsigned long iflag; |
| 1318 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1319 | /* Re-establishing Link, timer expired */ |
| 1320 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 1321 | "%d:1300 Re-establishing Link, timer expired " |
| 1322 | "Data: x%x x%x\n", |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1323 | phba->brd_no, vport->fc_flag, |
| 1324 | vport->port_state); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1325 | list_for_each_entry(vport, &phba->port_list, listentry) { |
| 1326 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1327 | |
| 1328 | spin_lock_irqsave(shost->host_lock, iflag); |
| 1329 | vport->fc_flag &= ~FC_ESTABLISH_LINK; |
| 1330 | spin_unlock_irqrestore(shost->host_lock, iflag); |
| 1331 | } |
| 1332 | } |
| 1333 | |
| 1334 | void |
| 1335 | lpfc_stop_vport_timers(struct lpfc_vport *vport) |
| 1336 | { |
| 1337 | del_timer_sync(&vport->els_tmofunc); |
| 1338 | del_timer_sync(&vport->fc_fdmitmo); |
| 1339 | lpfc_can_disctmo(vport); |
| 1340 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1341 | } |
| 1342 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1343 | static void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1344 | lpfc_stop_phba_timers(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1345 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1346 | struct lpfc_vport *vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1347 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1348 | del_timer_sync(&phba->fcp_poll_timer); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1349 | del_timer_sync(&phba->fc_estabtmo); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1350 | list_for_each_entry(vport, &phba->port_list, listentry) |
| 1351 | lpfc_stop_vport_timers(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1352 | del_timer_sync(&phba->sli.mbox_tmo); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1353 | del_timer_sync(&phba->fabric_block_timer); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame^] | 1354 | phba->hb_outstanding = 0; |
| 1355 | del_timer_sync(&phba->hb_tmofunc); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1356 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1357 | } |
| 1358 | |
| 1359 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1360 | lpfc_online(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1361 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1362 | struct lpfc_vport *vport = phba->pport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1363 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1364 | if (!phba) |
| 1365 | return 0; |
| 1366 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1367 | if (!(vport->fc_flag & FC_OFFLINE_MODE)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1368 | return 0; |
| 1369 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1370 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1371 | "%d:0458 Bring Adapter online\n", |
| 1372 | phba->brd_no); |
| 1373 | |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1374 | lpfc_block_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1375 | |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1376 | if (!lpfc_sli_queue_setup(phba)) { |
| 1377 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1378 | return 1; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1379 | } |
| 1380 | |
| 1381 | if (lpfc_sli_hba_setup(phba)) { /* Initialize the HBA */ |
| 1382 | lpfc_unblock_mgmt_io(phba); |
| 1383 | return 1; |
| 1384 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1385 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1386 | list_for_each_entry(vport, &phba->port_list, listentry) { |
| 1387 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1388 | spin_lock_irq(shost->host_lock); |
| 1389 | vport->fc_flag &= ~FC_OFFLINE_MODE; |
| 1390 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) |
| 1391 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
| 1392 | spin_unlock_irq(shost->host_lock); |
| 1393 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1394 | |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1395 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1396 | return 0; |
| 1397 | } |
| 1398 | |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1399 | void |
| 1400 | lpfc_block_mgmt_io(struct lpfc_hba * phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1401 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1402 | unsigned long iflag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1403 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1404 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 1405 | phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO; |
| 1406 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1407 | } |
| 1408 | |
| 1409 | void |
| 1410 | lpfc_unblock_mgmt_io(struct lpfc_hba * phba) |
| 1411 | { |
| 1412 | unsigned long iflag; |
| 1413 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1414 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 1415 | phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO; |
| 1416 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1417 | } |
| 1418 | |
| 1419 | void |
| 1420 | lpfc_offline_prep(struct lpfc_hba * phba) |
| 1421 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1422 | struct lpfc_vport *vport = phba->pport; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1423 | struct lpfc_nodelist *ndlp, *next_ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1424 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1425 | if (vport->fc_flag & FC_OFFLINE_MODE) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1426 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1427 | |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1428 | lpfc_block_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1429 | |
| 1430 | lpfc_linkdown(phba); |
| 1431 | |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1432 | /* Issue an unreg_login to all nodes */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1433 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1434 | if (ndlp->nlp_state != NLP_STE_UNUSED_NODE) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1435 | lpfc_unreg_rpi(vport, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1436 | |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1437 | lpfc_sli_flush_mbox_queue(phba); |
| 1438 | } |
| 1439 | |
| 1440 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1441 | lpfc_offline(struct lpfc_hba *phba) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1442 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1443 | struct lpfc_vport *vport = phba->pport; |
| 1444 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1445 | struct lpfc_vport *port_iterator; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1446 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1447 | if (vport->fc_flag & FC_OFFLINE_MODE) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1448 | return; |
James Smart | 688a886 | 2006-07-06 15:49:56 -0400 | [diff] [blame] | 1449 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1450 | /* stop all timers associated with this hba */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1451 | lpfc_stop_phba_timers(phba); |
| 1452 | list_for_each_entry(port_iterator, &phba->port_list, listentry) { |
| 1453 | port_iterator->work_port_events = 0; |
| 1454 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1455 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1456 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1457 | "%d:0460 Bring Adapter offline\n", |
| 1458 | phba->brd_no); |
| 1459 | |
| 1460 | /* Bring down the SLI Layer and cleanup. The HBA is offline |
| 1461 | now. */ |
| 1462 | lpfc_sli_hba_down(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1463 | spin_lock_irq(&phba->hbalock); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1464 | phba->work_ha = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1465 | vport->fc_flag |= FC_OFFLINE_MODE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1466 | spin_unlock_irq(&phba->hbalock); |
| 1467 | list_for_each_entry(port_iterator, &phba->port_list, listentry) { |
| 1468 | shost = lpfc_shost_from_vport(port_iterator); |
| 1469 | |
| 1470 | lpfc_cleanup(port_iterator); |
| 1471 | spin_lock_irq(shost->host_lock); |
| 1472 | vport->work_port_events = 0; |
| 1473 | vport->fc_flag |= FC_OFFLINE_MODE; |
| 1474 | spin_unlock_irq(shost->host_lock); |
| 1475 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1476 | } |
| 1477 | |
| 1478 | /****************************************************************************** |
| 1479 | * Function name: lpfc_scsi_free |
| 1480 | * |
| 1481 | * Description: Called from lpfc_pci_remove_one free internal driver resources |
| 1482 | * |
| 1483 | ******************************************************************************/ |
| 1484 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1485 | lpfc_scsi_free(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1486 | { |
| 1487 | struct lpfc_scsi_buf *sb, *sb_next; |
| 1488 | struct lpfc_iocbq *io, *io_next; |
| 1489 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1490 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1491 | /* Release all the lpfc_scsi_bufs maintained by this host. */ |
| 1492 | list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list, list) { |
| 1493 | list_del(&sb->list); |
| 1494 | pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1495 | sb->dma_handle); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1496 | kfree(sb); |
| 1497 | phba->total_scsi_bufs--; |
| 1498 | } |
| 1499 | |
| 1500 | /* Release all the lpfc_iocbq entries maintained by this host. */ |
| 1501 | list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) { |
| 1502 | list_del(&io->list); |
| 1503 | kfree(io); |
| 1504 | phba->total_iocbq_bufs--; |
| 1505 | } |
| 1506 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1507 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1508 | |
| 1509 | return 0; |
| 1510 | } |
| 1511 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1512 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1513 | struct lpfc_vport * |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1514 | lpfc_create_port(struct lpfc_hba *phba, int instance, struct fc_vport *fc_vport) |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1515 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1516 | struct lpfc_vport *vport; |
| 1517 | struct Scsi_Host *shost; |
| 1518 | int error = 0; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1519 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1520 | shost = scsi_host_alloc(&lpfc_template, sizeof(struct lpfc_vport)); |
| 1521 | if (!shost) |
| 1522 | goto out; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1523 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1524 | vport = (struct lpfc_vport *) shost->hostdata; |
| 1525 | vport->phba = phba; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1526 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1527 | vport->load_flag |= FC_LOADING; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1528 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1529 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1530 | shost->unique_id = instance; |
| 1531 | shost->max_id = LPFC_MAX_TARGET; |
| 1532 | shost->max_lun = phba->cfg_max_luns; |
| 1533 | shost->this_id = -1; |
| 1534 | shost->max_cmd_len = 16; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1535 | /* |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1536 | * Set initial can_queue value since 0 is no longer supported and |
| 1537 | * scsi_add_host will fail. This will be adjusted later based on the |
| 1538 | * max xri value determined in hba setup. |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1539 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1540 | shost->can_queue = phba->cfg_hba_queue_depth - 10; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1541 | if (fc_vport != NULL) { |
| 1542 | shost->transportt = lpfc_vport_transport_template; |
| 1543 | vport->port_type = LPFC_NPIV_PORT; |
| 1544 | } else { |
| 1545 | shost->transportt = lpfc_transport_template; |
| 1546 | vport->port_type = LPFC_PHYSICAL_PORT; |
| 1547 | } |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1548 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1549 | /* Initialize all internally managed lists. */ |
| 1550 | INIT_LIST_HEAD(&vport->fc_nodes); |
| 1551 | spin_lock_init(&vport->work_port_lock); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1552 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1553 | init_timer(&vport->fc_disctmo); |
| 1554 | vport->fc_disctmo.function = lpfc_disc_timeout; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1555 | vport->fc_disctmo.data = (unsigned long)vport; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1556 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1557 | init_timer(&vport->fc_fdmitmo); |
| 1558 | vport->fc_fdmitmo.function = lpfc_fdmi_tmo; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1559 | vport->fc_fdmitmo.data = (unsigned long)vport; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1560 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1561 | init_timer(&vport->els_tmofunc); |
| 1562 | vport->els_tmofunc.function = lpfc_els_timeout; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1563 | vport->els_tmofunc.data = (unsigned long)vport; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1564 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1565 | if (fc_vport != NULL) { |
| 1566 | error = scsi_add_host(shost, &fc_vport->dev); |
| 1567 | } else { |
| 1568 | error = scsi_add_host(shost, &phba->pcidev->dev); |
| 1569 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1570 | if (error) |
| 1571 | goto out_put_shost; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1572 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1573 | if (!shost->shost_classdev.kobj.dentry) |
| 1574 | goto out_put_shost; |
| 1575 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1576 | list_add_tail(&vport->listentry, &phba->port_list); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1577 | return vport; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1578 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1579 | out_put_shost: |
| 1580 | scsi_host_put(shost); |
| 1581 | out: |
| 1582 | return NULL; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1583 | } |
| 1584 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1585 | void |
| 1586 | destroy_port(struct lpfc_vport *vport) |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1587 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1588 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1589 | struct lpfc_hba *phba = vport->phba; |
| 1590 | |
| 1591 | kfree(vport->vname); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1592 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame^] | 1593 | lpfc_debugfs_terminate(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1594 | fc_remove_host(shost); |
| 1595 | scsi_remove_host(shost); |
| 1596 | |
| 1597 | spin_lock_irq(&phba->hbalock); |
| 1598 | list_del_init(&vport->listentry); |
| 1599 | spin_unlock_irq(&phba->hbalock); |
| 1600 | |
| 1601 | lpfc_cleanup(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1602 | return; |
| 1603 | } |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1604 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1605 | int |
| 1606 | lpfc_get_instance(void) |
| 1607 | { |
| 1608 | int instance = 0; |
| 1609 | |
| 1610 | /* Assign an unused number */ |
| 1611 | if (!idr_pre_get(&lpfc_hba_index, GFP_KERNEL)) |
| 1612 | return -1; |
| 1613 | if (idr_get_new(&lpfc_hba_index, NULL, &instance)) |
| 1614 | return -1; |
| 1615 | return instance; |
| 1616 | } |
| 1617 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame^] | 1618 | /* |
| 1619 | * Note: there is no scan_start function as adapter initialization |
| 1620 | * will have asynchronously kicked off the link initialization. |
| 1621 | */ |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1622 | |
| 1623 | int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time) |
| 1624 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1625 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 1626 | struct lpfc_hba *phba = vport->phba; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame^] | 1627 | int stat = 0; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1628 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame^] | 1629 | spin_lock_irq(shost->host_lock); |
| 1630 | |
| 1631 | if (vport->fc_flag & FC_UNLOADING) { |
| 1632 | stat = 1; |
| 1633 | goto finished; |
| 1634 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1635 | if (time >= 30 * HZ) { |
| 1636 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 1637 | "%d:0461 Scanning longer than 30 " |
| 1638 | "seconds. Continuing initialization\n", |
| 1639 | phba->brd_no); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame^] | 1640 | stat = 1; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1641 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1642 | } |
| 1643 | if (time >= 15 * HZ && phba->link_state <= LPFC_LINK_DOWN) { |
| 1644 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 1645 | "%d:0465 Link down longer than 15 " |
| 1646 | "seconds. Continuing initialization\n", |
| 1647 | phba->brd_no); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame^] | 1648 | stat = 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1649 | goto finished; |
| 1650 | } |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1651 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1652 | if (vport->port_state != LPFC_VPORT_READY) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame^] | 1653 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1654 | if (vport->num_disc_nodes || vport->fc_prli_sent) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame^] | 1655 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1656 | if (vport->fc_map_cnt == 0 && time < 2 * HZ) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame^] | 1657 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1658 | if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame^] | 1659 | goto finished; |
| 1660 | |
| 1661 | stat = 1; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1662 | |
| 1663 | finished: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame^] | 1664 | spin_unlock_irq(shost->host_lock); |
| 1665 | return stat; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1666 | } |
| 1667 | |
| 1668 | void lpfc_host_attrib_init(struct Scsi_Host *shost) |
| 1669 | { |
| 1670 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 1671 | struct lpfc_hba *phba = vport->phba; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1672 | /* |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1673 | * Set fixed host attributes. Must done after lpfc_sli_hba_setup(). |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1674 | */ |
| 1675 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1676 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
| 1677 | fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1678 | fc_host_supported_classes(shost) = FC_COS_CLASS3; |
| 1679 | |
| 1680 | memset(fc_host_supported_fc4s(shost), 0, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1681 | sizeof(fc_host_supported_fc4s(shost))); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1682 | fc_host_supported_fc4s(shost)[2] = 1; |
| 1683 | fc_host_supported_fc4s(shost)[7] = 1; |
| 1684 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1685 | lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost), |
| 1686 | sizeof fc_host_symbolic_name(shost)); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1687 | |
| 1688 | fc_host_supported_speeds(shost) = 0; |
| 1689 | if (phba->lmt & LMT_10Gb) |
| 1690 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT; |
| 1691 | if (phba->lmt & LMT_4Gb) |
| 1692 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT; |
| 1693 | if (phba->lmt & LMT_2Gb) |
| 1694 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT; |
| 1695 | if (phba->lmt & LMT_1Gb) |
| 1696 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT; |
| 1697 | |
| 1698 | fc_host_maxframe_size(shost) = |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1699 | (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) | |
| 1700 | (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1701 | |
| 1702 | /* This value is also unchanging */ |
| 1703 | memset(fc_host_active_fc4s(shost), 0, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1704 | sizeof(fc_host_active_fc4s(shost))); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1705 | fc_host_active_fc4s(shost)[2] = 1; |
| 1706 | fc_host_active_fc4s(shost)[7] = 1; |
| 1707 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1708 | fc_host_max_npiv_vports(shost) = phba->max_vpi; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1709 | spin_lock_irq(shost->host_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1710 | vport->fc_flag &= ~FC_LOADING; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1711 | spin_unlock_irq(shost->host_lock); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1712 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1713 | |
| 1714 | static int __devinit |
| 1715 | lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid) |
| 1716 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1717 | struct lpfc_vport *vport = NULL; |
| 1718 | struct lpfc_hba *phba; |
| 1719 | struct lpfc_sli *psli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1720 | struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1721 | struct Scsi_Host *shost = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1722 | unsigned long bar0map_len, bar2map_len; |
| 1723 | int error = -ENODEV, retval; |
| 1724 | int i; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1725 | uint16_t iotag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1726 | |
| 1727 | if (pci_enable_device(pdev)) |
| 1728 | goto out; |
| 1729 | if (pci_request_regions(pdev, LPFC_DRIVER_NAME)) |
| 1730 | goto out_disable_device; |
| 1731 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1732 | phba = kzalloc(sizeof (struct lpfc_hba), GFP_KERNEL); |
| 1733 | if (!phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1734 | goto out_release_regions; |
| 1735 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1736 | spin_lock_init(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1737 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1738 | phba->pcidev = pdev; |
| 1739 | |
| 1740 | /* Assign an unused board number */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1741 | if ((phba->brd_no = lpfc_get_instance()) < 0) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1742 | goto out_free_phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1743 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1744 | INIT_LIST_HEAD(&phba->port_list); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1745 | INIT_LIST_HEAD(&phba->hbq_buffer_list); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1746 | /* |
| 1747 | * Get all the module params for configuring this host and then |
| 1748 | * establish the host. |
| 1749 | */ |
| 1750 | lpfc_get_cfgparam(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1751 | phba->max_vpi = LPFC_MAX_VPI; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1752 | |
| 1753 | /* Initialize timers used by driver */ |
| 1754 | init_timer(&phba->fc_estabtmo); |
| 1755 | phba->fc_estabtmo.function = lpfc_establish_link_tmo; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame^] | 1756 | phba->fc_estabtmo.data = (unsigned long)phba; |
| 1757 | |
| 1758 | init_timer(&phba->hb_tmofunc); |
| 1759 | phba->hb_tmofunc.function = lpfc_hb_timeout; |
| 1760 | phba->hb_tmofunc.data = (unsigned long)phba; |
| 1761 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1762 | psli = &phba->sli; |
| 1763 | init_timer(&psli->mbox_tmo); |
| 1764 | psli->mbox_tmo.function = lpfc_mbox_timeout; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1765 | psli->mbox_tmo.data = (unsigned long) phba; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1766 | init_timer(&phba->fcp_poll_timer); |
| 1767 | phba->fcp_poll_timer.function = lpfc_poll_timeout; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1768 | phba->fcp_poll_timer.data = (unsigned long) phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1769 | init_timer(&phba->fabric_block_timer); |
| 1770 | phba->fabric_block_timer.function = lpfc_fabric_block_timeout; |
| 1771 | phba->fabric_block_timer.data = (unsigned long) phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1772 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1773 | pci_set_master(pdev); |
| 1774 | retval = pci_set_mwi(pdev); |
| 1775 | if (retval) |
| 1776 | dev_printk(KERN_WARNING, &pdev->dev, |
| 1777 | "Warning: pci_set_mwi returned %d\n", retval); |
| 1778 | |
| 1779 | if (pci_set_dma_mask(phba->pcidev, DMA_64BIT_MASK) != 0) |
| 1780 | if (pci_set_dma_mask(phba->pcidev, DMA_32BIT_MASK) != 0) |
| 1781 | goto out_idr_remove; |
| 1782 | |
| 1783 | /* |
| 1784 | * Get the bus address of Bar0 and Bar2 and the number of bytes |
| 1785 | * required by each mapping. |
| 1786 | */ |
| 1787 | phba->pci_bar0_map = pci_resource_start(phba->pcidev, 0); |
| 1788 | bar0map_len = pci_resource_len(phba->pcidev, 0); |
| 1789 | |
| 1790 | phba->pci_bar2_map = pci_resource_start(phba->pcidev, 2); |
| 1791 | bar2map_len = pci_resource_len(phba->pcidev, 2); |
| 1792 | |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 1793 | /* Map HBA SLIM to a kernel virtual address. */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1794 | phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len); |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 1795 | if (!phba->slim_memmap_p) { |
| 1796 | error = -ENODEV; |
| 1797 | dev_printk(KERN_ERR, &pdev->dev, |
| 1798 | "ioremap failed for SLIM memory.\n"); |
| 1799 | goto out_idr_remove; |
| 1800 | } |
| 1801 | |
| 1802 | /* Map HBA Control Registers to a kernel virtual address. */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1803 | phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len); |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 1804 | if (!phba->ctrl_regs_memmap_p) { |
| 1805 | error = -ENODEV; |
| 1806 | dev_printk(KERN_ERR, &pdev->dev, |
| 1807 | "ioremap failed for HBA control registers.\n"); |
| 1808 | goto out_iounmap_slim; |
| 1809 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1810 | |
| 1811 | /* Allocate memory for SLI-2 structures */ |
| 1812 | phba->slim2p = dma_alloc_coherent(&phba->pcidev->dev, SLI2_SLIM_SIZE, |
| 1813 | &phba->slim2p_mapping, GFP_KERNEL); |
| 1814 | if (!phba->slim2p) |
| 1815 | goto out_iounmap; |
| 1816 | |
James.Smart@Emulex.Com | f91b392 | 2005-10-28 20:29:28 -0400 | [diff] [blame] | 1817 | memset(phba->slim2p, 0, SLI2_SLIM_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1818 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1819 | phba->hbqslimp.virt = dma_alloc_coherent(&phba->pcidev->dev, |
| 1820 | lpfc_sli_hbq_size(), |
| 1821 | &phba->hbqslimp.phys, |
| 1822 | GFP_KERNEL); |
| 1823 | if (!phba->hbqslimp.virt) |
| 1824 | goto out_free_slim; |
| 1825 | |
| 1826 | memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size()); |
| 1827 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1828 | /* Initialize the SLI Layer to run with lpfc HBAs. */ |
| 1829 | lpfc_sli_setup(phba); |
| 1830 | lpfc_sli_queue_setup(phba); |
| 1831 | |
| 1832 | error = lpfc_mem_alloc(phba); |
| 1833 | if (error) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1834 | goto out_free_hbqslimp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1835 | |
| 1836 | /* Initialize and populate the iocb list per host. */ |
| 1837 | INIT_LIST_HEAD(&phba->lpfc_iocb_list); |
| 1838 | for (i = 0; i < LPFC_IOCB_LIST_CNT; i++) { |
| 1839 | iocbq_entry = kmalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL); |
| 1840 | if (iocbq_entry == NULL) { |
| 1841 | printk(KERN_ERR "%s: only allocated %d iocbs of " |
| 1842 | "expected %d count. Unloading driver.\n", |
| 1843 | __FUNCTION__, i, LPFC_IOCB_LIST_CNT); |
| 1844 | error = -ENOMEM; |
| 1845 | goto out_free_iocbq; |
| 1846 | } |
| 1847 | |
| 1848 | memset(iocbq_entry, 0, sizeof(struct lpfc_iocbq)); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1849 | iotag = lpfc_sli_next_iotag(phba, iocbq_entry); |
| 1850 | if (iotag == 0) { |
| 1851 | kfree (iocbq_entry); |
| 1852 | printk(KERN_ERR "%s: failed to allocate IOTAG. " |
| 1853 | "Unloading driver.\n", |
| 1854 | __FUNCTION__); |
| 1855 | error = -ENOMEM; |
| 1856 | goto out_free_iocbq; |
| 1857 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1858 | |
| 1859 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1860 | list_add(&iocbq_entry->list, &phba->lpfc_iocb_list); |
| 1861 | phba->total_iocbq_bufs++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1862 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1863 | } |
| 1864 | |
| 1865 | /* Initialize HBA structure */ |
| 1866 | phba->fc_edtov = FF_DEF_EDTOV; |
| 1867 | phba->fc_ratov = FF_DEF_RATOV; |
| 1868 | phba->fc_altov = FF_DEF_ALTOV; |
| 1869 | phba->fc_arbtov = FF_DEF_ARBTOV; |
| 1870 | |
| 1871 | INIT_LIST_HEAD(&phba->work_list); |
| 1872 | phba->work_ha_mask = (HA_ERATT|HA_MBATT|HA_LATT); |
| 1873 | phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4)); |
| 1874 | |
| 1875 | /* Startup the kernel thread for this host adapter. */ |
| 1876 | phba->worker_thread = kthread_run(lpfc_do_work, phba, |
| 1877 | "lpfc_worker_%d", phba->brd_no); |
| 1878 | if (IS_ERR(phba->worker_thread)) { |
| 1879 | error = PTR_ERR(phba->worker_thread); |
| 1880 | goto out_free_iocbq; |
| 1881 | } |
| 1882 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1883 | /* Initialize the list of scsi buffers used by driver for scsi IO. */ |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1884 | spin_lock_init(&phba->scsi_buf_list_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1885 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list); |
| 1886 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1887 | /* Initialize list of fabric iocbs */ |
| 1888 | INIT_LIST_HEAD(&phba->fabric_iocb_list); |
| 1889 | |
| 1890 | vport = lpfc_create_port(phba, phba->brd_no, NULL); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1891 | if (!vport) |
| 1892 | goto out_kthread_stop; |
| 1893 | |
| 1894 | shost = lpfc_shost_from_vport(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1895 | phba->pport = vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame^] | 1896 | lpfc_debugfs_initialize(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1897 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1898 | pci_set_drvdata(pdev, shost); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1899 | |
James Smart | 4ff4324 | 2006-12-02 13:34:56 -0500 | [diff] [blame] | 1900 | if (phba->cfg_use_msi) { |
| 1901 | error = pci_enable_msi(phba->pcidev); |
| 1902 | if (error) |
| 1903 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, "%d:0452 " |
| 1904 | "Enable MSI failed, continuing with " |
| 1905 | "IRQ\n", phba->brd_no); |
| 1906 | } |
| 1907 | |
Thomas Gleixner | 1d6f359 | 2006-07-01 19:29:42 -0700 | [diff] [blame] | 1908 | error = request_irq(phba->pcidev->irq, lpfc_intr_handler, IRQF_SHARED, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1909 | LPFC_DRIVER_NAME, phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1910 | if (error) { |
| 1911 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1912 | "%d:0451 Enable interrupt handler failed\n", |
| 1913 | phba->brd_no); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1914 | goto out_disable_msi; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1915 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1916 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1917 | phba->MBslimaddr = phba->slim_memmap_p; |
| 1918 | phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET; |
| 1919 | phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET; |
| 1920 | phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET; |
| 1921 | phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET; |
| 1922 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1923 | if (lpfc_alloc_sysfs_attr(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1924 | goto out_free_irq; |
| 1925 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame^] | 1926 | if (lpfc_sli_hba_setup(phba)) |
| 1927 | goto out_remove_device; |
| 1928 | |
| 1929 | /* |
| 1930 | * hba setup may have changed the hba_queue_depth so we need to adjust |
| 1931 | * the value of can_queue. |
| 1932 | */ |
| 1933 | shost->can_queue = phba->cfg_hba_queue_depth - 10; |
| 1934 | |
| 1935 | lpfc_host_attrib_init(shost); |
| 1936 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1937 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
| 1938 | spin_lock_irq(shost->host_lock); |
| 1939 | lpfc_poll_start_timer(phba); |
| 1940 | spin_unlock_irq(shost->host_lock); |
| 1941 | } |
James Smart | 8f6d98d | 2006-08-01 07:34:00 -0400 | [diff] [blame] | 1942 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame^] | 1943 | scsi_scan_host(shost); |
| 1944 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1945 | return 0; |
| 1946 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame^] | 1947 | out_remove_device: |
| 1948 | lpfc_free_sysfs_attr(vport); |
| 1949 | spin_lock_irq(shost->host_lock); |
| 1950 | vport->fc_flag |= FC_UNLOADING; |
| 1951 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1952 | out_free_irq: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1953 | lpfc_stop_phba_timers(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1954 | phba->pport->work_port_events = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1955 | free_irq(phba->pcidev->irq, phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1956 | out_disable_msi: |
James Smart | 4ff4324 | 2006-12-02 13:34:56 -0500 | [diff] [blame] | 1957 | pci_disable_msi(phba->pcidev); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1958 | destroy_port(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1959 | out_kthread_stop: |
| 1960 | kthread_stop(phba->worker_thread); |
| 1961 | out_free_iocbq: |
| 1962 | list_for_each_entry_safe(iocbq_entry, iocbq_next, |
| 1963 | &phba->lpfc_iocb_list, list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1964 | kfree(iocbq_entry); |
| 1965 | phba->total_iocbq_bufs--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1966 | } |
| 1967 | lpfc_mem_free(phba); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1968 | out_free_hbqslimp: |
| 1969 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), phba->hbqslimp.virt, |
| 1970 | phba->hbqslimp.phys); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1971 | out_free_slim: |
| 1972 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, phba->slim2p, |
| 1973 | phba->slim2p_mapping); |
| 1974 | out_iounmap: |
| 1975 | iounmap(phba->ctrl_regs_memmap_p); |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 1976 | out_iounmap_slim: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1977 | iounmap(phba->slim_memmap_p); |
| 1978 | out_idr_remove: |
| 1979 | idr_remove(&lpfc_hba_index, phba->brd_no); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1980 | out_free_phba: |
| 1981 | kfree(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1982 | out_release_regions: |
| 1983 | pci_release_regions(pdev); |
| 1984 | out_disable_device: |
| 1985 | pci_disable_device(pdev); |
| 1986 | out: |
James Smart | defbcf1 | 2006-04-16 22:26:50 -0400 | [diff] [blame] | 1987 | pci_set_drvdata(pdev, NULL); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame^] | 1988 | if (shost) |
| 1989 | scsi_host_put(shost); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1990 | return error; |
| 1991 | } |
| 1992 | |
| 1993 | static void __devexit |
| 1994 | lpfc_pci_remove_one(struct pci_dev *pdev) |
| 1995 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1996 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 1997 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 1998 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1999 | struct lpfc_vport *port_iterator; |
| 2000 | list_for_each_entry(port_iterator, &phba->port_list, listentry) |
| 2001 | port_iterator->load_flag |= FC_UNLOADING; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2002 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame^] | 2003 | kfree(vport->vname); |
| 2004 | lpfc_free_sysfs_attr(vport); |
| 2005 | |
| 2006 | fc_remove_host(shost); |
| 2007 | scsi_remove_host(shost); |
| 2008 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2009 | /* |
| 2010 | * Bring down the SLI Layer. This step disable all interrupts, |
| 2011 | * clears the rings, discards all mailbox commands, and resets |
| 2012 | * the HBA. |
| 2013 | */ |
| 2014 | lpfc_sli_hba_down(phba); |
| 2015 | lpfc_sli_brdrestart(phba); |
| 2016 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2017 | lpfc_stop_phba_timers(phba); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame^] | 2018 | spin_lock_irq(&phba->hbalock); |
| 2019 | list_del_init(&vport->listentry); |
| 2020 | spin_unlock_irq(&phba->hbalock); |
| 2021 | |
| 2022 | |
| 2023 | lpfc_debugfs_terminate(vport); |
| 2024 | lpfc_cleanup(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2025 | |
| 2026 | kthread_stop(phba->worker_thread); |
| 2027 | |
| 2028 | /* Release the irq reservation */ |
| 2029 | free_irq(phba->pcidev->irq, phba); |
| 2030 | pci_disable_msi(phba->pcidev); |
| 2031 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2032 | pci_set_drvdata(pdev, NULL); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame^] | 2033 | scsi_host_put(shost); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2034 | |
| 2035 | /* |
| 2036 | * Call scsi_free before mem_free since scsi bufs are released to their |
| 2037 | * corresponding pools here. |
| 2038 | */ |
| 2039 | lpfc_scsi_free(phba); |
| 2040 | lpfc_mem_free(phba); |
| 2041 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2042 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), phba->hbqslimp.virt, |
| 2043 | phba->hbqslimp.phys); |
| 2044 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2045 | /* Free resources associated with SLI2 interface */ |
| 2046 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
| 2047 | phba->slim2p, phba->slim2p_mapping); |
| 2048 | |
| 2049 | /* unmap adapter SLIM and Control Registers */ |
| 2050 | iounmap(phba->ctrl_regs_memmap_p); |
| 2051 | iounmap(phba->slim_memmap_p); |
| 2052 | |
| 2053 | idr_remove(&lpfc_hba_index, phba->brd_no); |
| 2054 | |
| 2055 | kfree(phba); |
| 2056 | |
| 2057 | pci_release_regions(pdev); |
| 2058 | pci_disable_device(pdev); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2059 | } |
| 2060 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 2061 | /** |
| 2062 | * lpfc_io_error_detected - called when PCI error is detected |
| 2063 | * @pdev: Pointer to PCI device |
| 2064 | * @state: The current pci conneection state |
| 2065 | * |
| 2066 | * This function is called after a PCI bus error affecting |
| 2067 | * this device has been detected. |
| 2068 | */ |
| 2069 | static pci_ers_result_t lpfc_io_error_detected(struct pci_dev *pdev, |
| 2070 | pci_channel_state_t state) |
| 2071 | { |
| 2072 | struct Scsi_Host *host = pci_get_drvdata(pdev); |
| 2073 | struct lpfc_hba *phba = (struct lpfc_hba *)host->hostdata; |
| 2074 | struct lpfc_sli *psli = &phba->sli; |
| 2075 | struct lpfc_sli_ring *pring; |
| 2076 | |
Linas Vepstas | 5daa49e | 2007-03-08 16:19:11 -0600 | [diff] [blame] | 2077 | if (state == pci_channel_io_perm_failure) |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 2078 | return PCI_ERS_RESULT_DISCONNECT; |
Linas Vepstas | 5daa49e | 2007-03-08 16:19:11 -0600 | [diff] [blame] | 2079 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 2080 | pci_disable_device(pdev); |
| 2081 | /* |
| 2082 | * There may be I/Os dropped by the firmware. |
| 2083 | * Error iocb (I/O) on txcmplq and let the SCSI layer |
| 2084 | * retry it after re-establishing link. |
| 2085 | */ |
| 2086 | pring = &psli->ring[psli->fcp_ring]; |
| 2087 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 2088 | |
| 2089 | /* Request a slot reset. */ |
| 2090 | return PCI_ERS_RESULT_NEED_RESET; |
| 2091 | } |
| 2092 | |
| 2093 | /** |
| 2094 | * lpfc_io_slot_reset - called after the pci bus has been reset. |
| 2095 | * @pdev: Pointer to PCI device |
| 2096 | * |
| 2097 | * Restart the card from scratch, as if from a cold-boot. |
| 2098 | */ |
| 2099 | static pci_ers_result_t lpfc_io_slot_reset(struct pci_dev *pdev) |
| 2100 | { |
| 2101 | struct Scsi_Host *host = pci_get_drvdata(pdev); |
| 2102 | struct lpfc_hba *phba = (struct lpfc_hba *)host->hostdata; |
| 2103 | struct lpfc_sli *psli = &phba->sli; |
| 2104 | int bars = pci_select_bars(pdev, IORESOURCE_MEM); |
| 2105 | |
| 2106 | dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n"); |
| 2107 | if (pci_enable_device_bars(pdev, bars)) { |
| 2108 | printk(KERN_ERR "lpfc: Cannot re-enable " |
| 2109 | "PCI device after reset.\n"); |
| 2110 | return PCI_ERS_RESULT_DISCONNECT; |
| 2111 | } |
| 2112 | |
| 2113 | pci_set_master(pdev); |
| 2114 | |
| 2115 | /* Re-establishing Link */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2116 | spin_lock_irq(host->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2117 | phba->pport->fc_flag |= FC_ESTABLISH_LINK; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2118 | spin_unlock_irq(host->host_lock); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 2119 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2120 | spin_lock_irq(&phba->hbalock); |
| 2121 | psli->sli_flag &= ~LPFC_SLI2_ACTIVE; |
| 2122 | spin_unlock_irq(&phba->hbalock); |
| 2123 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 2124 | |
| 2125 | /* Take device offline; this will perform cleanup */ |
| 2126 | lpfc_offline(phba); |
| 2127 | lpfc_sli_brdrestart(phba); |
| 2128 | |
| 2129 | return PCI_ERS_RESULT_RECOVERED; |
| 2130 | } |
| 2131 | |
| 2132 | /** |
| 2133 | * lpfc_io_resume - called when traffic can start flowing again. |
| 2134 | * @pdev: Pointer to PCI device |
| 2135 | * |
| 2136 | * This callback is called when the error recovery driver tells us that |
| 2137 | * its OK to resume normal operation. |
| 2138 | */ |
| 2139 | static void lpfc_io_resume(struct pci_dev *pdev) |
| 2140 | { |
| 2141 | struct Scsi_Host *host = pci_get_drvdata(pdev); |
| 2142 | struct lpfc_hba *phba = (struct lpfc_hba *)host->hostdata; |
| 2143 | |
| 2144 | if (lpfc_online(phba) == 0) { |
| 2145 | mod_timer(&phba->fc_estabtmo, jiffies + HZ * 60); |
| 2146 | } |
| 2147 | } |
| 2148 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2149 | static struct pci_device_id lpfc_id_table[] = { |
| 2150 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER, |
| 2151 | PCI_ANY_ID, PCI_ANY_ID, }, |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 2152 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY, |
| 2153 | PCI_ANY_ID, PCI_ANY_ID, }, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2154 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR, |
| 2155 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 2156 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS, |
| 2157 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 2158 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR, |
| 2159 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 2160 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY, |
| 2161 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 2162 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY, |
| 2163 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 2164 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY, |
| 2165 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 2166 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY, |
| 2167 | PCI_ANY_ID, PCI_ANY_ID, }, |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2168 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE, |
| 2169 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 2170 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP, |
| 2171 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 2172 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP, |
| 2173 | PCI_ANY_ID, PCI_ANY_ID, }, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2174 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS, |
| 2175 | PCI_ANY_ID, PCI_ANY_ID, }, |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2176 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP, |
| 2177 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 2178 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP, |
| 2179 | PCI_ANY_ID, PCI_ANY_ID, }, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2180 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID, |
| 2181 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 2182 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB, |
| 2183 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 2184 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR, |
| 2185 | PCI_ANY_ID, PCI_ANY_ID, }, |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2186 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP, |
| 2187 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 2188 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP, |
| 2189 | PCI_ANY_ID, PCI_ANY_ID, }, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2190 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID, |
| 2191 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 2192 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB, |
| 2193 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 2194 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY, |
| 2195 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 2196 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101, |
| 2197 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 2198 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S, |
| 2199 | PCI_ANY_ID, PCI_ANY_ID, }, |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2200 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S, |
| 2201 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 2202 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S, |
| 2203 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2204 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT, |
| 2205 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 2206 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID, |
| 2207 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 2208 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB, |
| 2209 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 2210 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP, |
| 2211 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 2212 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP, |
| 2213 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 2214 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S, |
| 2215 | PCI_ANY_ID, PCI_ANY_ID, }, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2216 | { 0 } |
| 2217 | }; |
| 2218 | |
| 2219 | MODULE_DEVICE_TABLE(pci, lpfc_id_table); |
| 2220 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 2221 | static struct pci_error_handlers lpfc_err_handler = { |
| 2222 | .error_detected = lpfc_io_error_detected, |
| 2223 | .slot_reset = lpfc_io_slot_reset, |
| 2224 | .resume = lpfc_io_resume, |
| 2225 | }; |
| 2226 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2227 | static struct pci_driver lpfc_driver = { |
| 2228 | .name = LPFC_DRIVER_NAME, |
| 2229 | .id_table = lpfc_id_table, |
| 2230 | .probe = lpfc_pci_probe_one, |
| 2231 | .remove = __devexit_p(lpfc_pci_remove_one), |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2232 | .err_handler = &lpfc_err_handler, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2233 | }; |
| 2234 | |
| 2235 | static int __init |
| 2236 | lpfc_init(void) |
| 2237 | { |
| 2238 | int error = 0; |
| 2239 | |
| 2240 | printk(LPFC_MODULE_DESC "\n"); |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 2241 | printk(LPFC_COPYRIGHT "\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2242 | |
| 2243 | lpfc_transport_template = |
| 2244 | fc_attach_transport(&lpfc_transport_functions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2245 | lpfc_vport_transport_template = |
| 2246 | fc_attach_transport(&lpfc_vport_transport_functions); |
| 2247 | if (!lpfc_transport_template || !lpfc_vport_transport_template) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2248 | return -ENOMEM; |
| 2249 | error = pci_register_driver(&lpfc_driver); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2250 | if (error) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2251 | fc_release_transport(lpfc_transport_template); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2252 | fc_release_transport(lpfc_vport_transport_template); |
| 2253 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2254 | |
| 2255 | return error; |
| 2256 | } |
| 2257 | |
| 2258 | static void __exit |
| 2259 | lpfc_exit(void) |
| 2260 | { |
| 2261 | pci_unregister_driver(&lpfc_driver); |
| 2262 | fc_release_transport(lpfc_transport_template); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2263 | fc_release_transport(lpfc_vport_transport_template); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2264 | } |
| 2265 | |
| 2266 | module_init(lpfc_init); |
| 2267 | module_exit(lpfc_exit); |
| 2268 | MODULE_LICENSE("GPL"); |
| 2269 | MODULE_DESCRIPTION(LPFC_MODULE_DESC); |
| 2270 | MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com"); |
| 2271 | MODULE_VERSION("0:" LPFC_DRIVER_VERSION); |