| 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 | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4 | * Copyright (C) 2004-2008 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" |
| 46 | |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 47 | static int lpfc_parse_vpd(struct lpfc_hba *, uint8_t *, int); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 48 | static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *); |
| 49 | static int lpfc_post_rcv_buf(struct lpfc_hba *); |
| 50 | |
| 51 | static struct scsi_transport_template *lpfc_transport_template = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 52 | static struct scsi_transport_template *lpfc_vport_transport_template = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 53 | static DEFINE_IDR(lpfc_hba_index); |
| 54 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 55 | /** |
| 56 | * lpfc_config_port_prep: Perform lpfc initialization prior to config port. |
| 57 | * @phba: pointer to lpfc hba data structure. |
| 58 | * |
| 59 | * This routine will do LPFC initialization prior to issuing the CONFIG_PORT |
| 60 | * mailbox command. It retrieves the revision information from the HBA and |
| 61 | * collects the Vital Product Data (VPD) about the HBA for preparing the |
| 62 | * configuration of the HBA. |
| 63 | * |
| 64 | * Return codes: |
| 65 | * 0 - success. |
| 66 | * -ERESTART - requests the SLI layer to reset the HBA and try again. |
| 67 | * Any other value - indicates an error. |
| 68 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 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, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 110 | "0324 Config Port initialization " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 111 | "error, mbxCmd x%x READ_NVPARM, " |
| 112 | "mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 113 | mb->mbxCommand, mb->mbxStatus); |
| 114 | mempool_free(pmb, phba->mbox_mem_pool); |
| 115 | return -ERESTART; |
| 116 | } |
| 117 | memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 118 | sizeof(phba->wwnn)); |
| 119 | memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname, |
| 120 | sizeof(phba->wwpn)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 121 | } |
| 122 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 123 | phba->sli3_options = 0x0; |
| 124 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 125 | /* Setup and issue mailbox READ REV command */ |
| 126 | lpfc_read_rev(phba, pmb); |
| 127 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 128 | if (rc != MBX_SUCCESS) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 129 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 130 | "0439 Adapter failed to init, mbxCmd x%x " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 131 | "READ_REV, mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 132 | mb->mbxCommand, mb->mbxStatus); |
| 133 | mempool_free( pmb, phba->mbox_mem_pool); |
| 134 | return -ERESTART; |
| 135 | } |
| 136 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 137 | |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 138 | /* |
| 139 | * The value of rr must be 1 since the driver set the cv field to 1. |
| 140 | * This setting requires the FW to set all revision fields. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 141 | */ |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 142 | if (mb->un.varRdRev.rr == 0) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 143 | vp->rev.rBit = 0; |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 144 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 145 | "0440 Adapter failed to init, READ_REV has " |
| 146 | "missing revision information.\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 147 | mempool_free(pmb, phba->mbox_mem_pool); |
| 148 | return -ERESTART; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 149 | } |
| 150 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 151 | if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) { |
| 152 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 153 | return -EINVAL; |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 154 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 155 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 156 | /* Save information as VPD data */ |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 157 | vp->rev.rBit = 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 158 | memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t)); |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 159 | vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev; |
| 160 | memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16); |
| 161 | vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev; |
| 162 | memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 163 | vp->rev.biuRev = mb->un.varRdRev.biuRev; |
| 164 | vp->rev.smRev = mb->un.varRdRev.smRev; |
| 165 | vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev; |
| 166 | vp->rev.endecRev = mb->un.varRdRev.endecRev; |
| 167 | vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh; |
| 168 | vp->rev.fcphLow = mb->un.varRdRev.fcphLow; |
| 169 | vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh; |
| 170 | vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow; |
| 171 | vp->rev.postKernRev = mb->un.varRdRev.postKernRev; |
| 172 | vp->rev.opFwRev = mb->un.varRdRev.opFwRev; |
| 173 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 174 | /* If the sli feature level is less then 9, we must |
| 175 | * tear down all RPIs and VPIs on link down if NPIV |
| 176 | * is enabled. |
| 177 | */ |
| 178 | if (vp->rev.feaLevelHigh < 9) |
| 179 | phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN; |
| 180 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 181 | if (lpfc_is_LC_HBA(phba->pcidev->device)) |
| 182 | memcpy(phba->RandomData, (char *)&mb->un.varWords[24], |
| 183 | sizeof (phba->RandomData)); |
| 184 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 185 | /* Get adapter VPD information */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 186 | lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL); |
| 187 | if (!lpfc_vpd_data) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 188 | goto out_free_mbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 189 | |
| 190 | do { |
| 191 | lpfc_dump_mem(phba, pmb, offset); |
| 192 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 193 | |
| 194 | if (rc != MBX_SUCCESS) { |
| 195 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 196 | "0441 VPD not present on adapter, " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 197 | "mbxCmd x%x DUMP VPD, mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 198 | mb->mbxCommand, mb->mbxStatus); |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 199 | mb->un.varDmp.word_cnt = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 200 | } |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 201 | if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset) |
| 202 | mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 203 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, |
| 204 | lpfc_vpd_data + offset, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 205 | mb->un.varDmp.word_cnt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 206 | offset += mb->un.varDmp.word_cnt; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 207 | } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE); |
| 208 | lpfc_parse_vpd(phba, lpfc_vpd_data, offset); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 209 | |
| 210 | kfree(lpfc_vpd_data); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 211 | out_free_mbox: |
| 212 | mempool_free(pmb, phba->mbox_mem_pool); |
| 213 | return 0; |
| 214 | } |
| 215 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 216 | /** |
| 217 | * lpfc_config_async_cmpl: Completion handler for config async event mbox cmd. |
| 218 | * @phba: pointer to lpfc hba data structure. |
| 219 | * @pmboxq: pointer to the driver internal queue element for mailbox command. |
| 220 | * |
| 221 | * This is the completion handler for driver's configuring asynchronous event |
| 222 | * mailbox command to the device. If the mailbox command returns successfully, |
| 223 | * it will set internal async event support flag to 1; otherwise, it will |
| 224 | * set internal async event support flag to 0. |
| 225 | **/ |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 226 | static void |
| 227 | lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq) |
| 228 | { |
| 229 | if (pmboxq->mb.mbxStatus == MBX_SUCCESS) |
| 230 | phba->temp_sensor_support = 1; |
| 231 | else |
| 232 | phba->temp_sensor_support = 0; |
| 233 | mempool_free(pmboxq, phba->mbox_mem_pool); |
| 234 | return; |
| 235 | } |
| 236 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 237 | /** |
| 238 | * lpfc_config_port_post: Perform lpfc initialization after config port. |
| 239 | * @phba: pointer to lpfc hba data structure. |
| 240 | * |
| 241 | * This routine will do LPFC initialization after the CONFIG_PORT mailbox |
| 242 | * command call. It performs all internal resource and state setups on the |
| 243 | * port: post IOCB buffers, enable appropriate host interrupt attentions, |
| 244 | * ELS ring timers, etc. |
| 245 | * |
| 246 | * Return codes |
| 247 | * 0 - success. |
| 248 | * Any other value - error. |
| 249 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 250 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 251 | lpfc_config_port_post(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 252 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 253 | struct lpfc_vport *vport = phba->pport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 254 | LPFC_MBOXQ_t *pmb; |
| 255 | MAILBOX_t *mb; |
| 256 | struct lpfc_dmabuf *mp; |
| 257 | struct lpfc_sli *psli = &phba->sli; |
| 258 | uint32_t status, timeout; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 259 | int i, j; |
| 260 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 261 | |
James Smart | 7af6705 | 2007-10-27 13:38:11 -0400 | [diff] [blame] | 262 | spin_lock_irq(&phba->hbalock); |
| 263 | /* |
| 264 | * If the Config port completed correctly the HBA is not |
| 265 | * over heated any more. |
| 266 | */ |
| 267 | if (phba->over_temp_state == HBA_OVER_TEMP) |
| 268 | phba->over_temp_state = HBA_NORMAL_TEMP; |
| 269 | spin_unlock_irq(&phba->hbalock); |
| 270 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 271 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 272 | if (!pmb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 273 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 274 | return -ENOMEM; |
| 275 | } |
| 276 | mb = &pmb->mb; |
| 277 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 278 | /* Get login parameters for NID. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 279 | lpfc_read_sparam(phba, pmb, 0); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 280 | pmb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 281 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 282 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 283 | "0448 Adapter failed init, mbxCmd x%x " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 284 | "READ_SPARM mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 285 | mb->mbxCommand, mb->mbxStatus); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 286 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 287 | mp = (struct lpfc_dmabuf *) pmb->context1; |
| 288 | mempool_free( pmb, phba->mbox_mem_pool); |
| 289 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 290 | kfree(mp); |
| 291 | return -EIO; |
| 292 | } |
| 293 | |
| 294 | mp = (struct lpfc_dmabuf *) pmb->context1; |
| 295 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 296 | memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 297 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 298 | kfree(mp); |
| 299 | pmb->context1 = NULL; |
| 300 | |
James Smart | a12e07b | 2006-12-02 13:35:30 -0500 | [diff] [blame] | 301 | if (phba->cfg_soft_wwnn) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 302 | u64_to_wwn(phba->cfg_soft_wwnn, |
| 303 | vport->fc_sparam.nodeName.u.wwn); |
James Smart | c3f28af | 2006-08-18 17:47:18 -0400 | [diff] [blame] | 304 | if (phba->cfg_soft_wwpn) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 305 | u64_to_wwn(phba->cfg_soft_wwpn, |
| 306 | vport->fc_sparam.portName.u.wwn); |
| 307 | memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 308 | sizeof (struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 309 | memcpy(&vport->fc_portname, &vport->fc_sparam.portName, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 310 | sizeof (struct lpfc_name)); |
| 311 | /* If no serial number in VPD data, use low 6 bytes of WWNN */ |
| 312 | /* This should be consolidated into parse_vpd ? - mr */ |
| 313 | if (phba->SerialNumber[0] == 0) { |
| 314 | uint8_t *outptr; |
| 315 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 316 | outptr = &vport->fc_nodename.u.s.IEEE[0]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 317 | for (i = 0; i < 12; i++) { |
| 318 | status = *outptr++; |
| 319 | j = ((status & 0xf0) >> 4); |
| 320 | if (j <= 9) |
| 321 | phba->SerialNumber[i] = |
| 322 | (char)((uint8_t) 0x30 + (uint8_t) j); |
| 323 | else |
| 324 | phba->SerialNumber[i] = |
| 325 | (char)((uint8_t) 0x61 + (uint8_t) (j - 10)); |
| 326 | i++; |
| 327 | j = (status & 0xf); |
| 328 | if (j <= 9) |
| 329 | phba->SerialNumber[i] = |
| 330 | (char)((uint8_t) 0x30 + (uint8_t) j); |
| 331 | else |
| 332 | phba->SerialNumber[i] = |
| 333 | (char)((uint8_t) 0x61 + (uint8_t) (j - 10)); |
| 334 | } |
| 335 | } |
| 336 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 337 | lpfc_read_config(phba, pmb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 338 | pmb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 339 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 340 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 341 | "0453 Adapter failed to init, mbxCmd x%x " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 342 | "READ_CONFIG, mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 343 | mb->mbxCommand, mb->mbxStatus); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 344 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 345 | mempool_free( pmb, phba->mbox_mem_pool); |
| 346 | return -EIO; |
| 347 | } |
| 348 | |
| 349 | /* Reset the DFT_HBA_Q_DEPTH to the max xri */ |
| 350 | if (phba->cfg_hba_queue_depth > (mb->un.varRdConfig.max_xri+1)) |
| 351 | phba->cfg_hba_queue_depth = |
| 352 | mb->un.varRdConfig.max_xri + 1; |
| 353 | |
| 354 | phba->lmt = mb->un.varRdConfig.lmt; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 355 | |
| 356 | /* Get the default values for Model Name and Description */ |
| 357 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); |
| 358 | |
| 359 | if ((phba->cfg_link_speed > LINK_SPEED_10G) |
| 360 | || ((phba->cfg_link_speed == LINK_SPEED_1G) |
| 361 | && !(phba->lmt & LMT_1Gb)) |
| 362 | || ((phba->cfg_link_speed == LINK_SPEED_2G) |
| 363 | && !(phba->lmt & LMT_2Gb)) |
| 364 | || ((phba->cfg_link_speed == LINK_SPEED_4G) |
| 365 | && !(phba->lmt & LMT_4Gb)) |
| 366 | || ((phba->cfg_link_speed == LINK_SPEED_8G) |
| 367 | && !(phba->lmt & LMT_8Gb)) |
| 368 | || ((phba->cfg_link_speed == LINK_SPEED_10G) |
| 369 | && !(phba->lmt & LMT_10Gb))) { |
| 370 | /* Reset link speed to auto */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 371 | lpfc_printf_log(phba, KERN_WARNING, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 372 | "1302 Invalid speed for this board: " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 373 | "Reset link speed to auto: x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 374 | phba->cfg_link_speed); |
| 375 | phba->cfg_link_speed = LINK_SPEED_AUTO; |
| 376 | } |
| 377 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 378 | phba->link_state = LPFC_LINK_DOWN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 379 | |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 380 | /* Only process IOCBs on ELS ring till hba_state is READY */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 381 | if (psli->ring[psli->extra_ring].cmdringaddr) |
| 382 | psli->ring[psli->extra_ring].flag |= LPFC_STOP_IOCB_EVENT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 383 | if (psli->ring[psli->fcp_ring].cmdringaddr) |
| 384 | psli->ring[psli->fcp_ring].flag |= LPFC_STOP_IOCB_EVENT; |
| 385 | if (psli->ring[psli->next_ring].cmdringaddr) |
| 386 | psli->ring[psli->next_ring].flag |= LPFC_STOP_IOCB_EVENT; |
| 387 | |
| 388 | /* Post receive buffers for desired rings */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 389 | if (phba->sli_rev != 3) |
| 390 | lpfc_post_rcv_buf(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 391 | |
| 392 | /* Enable appropriate host interrupts */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 393 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 394 | status = readl(phba->HCregaddr); |
| 395 | status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA; |
| 396 | if (psli->num_rings > 0) |
| 397 | status |= HC_R0INT_ENA; |
| 398 | if (psli->num_rings > 1) |
| 399 | status |= HC_R1INT_ENA; |
| 400 | if (psli->num_rings > 2) |
| 401 | status |= HC_R2INT_ENA; |
| 402 | if (psli->num_rings > 3) |
| 403 | status |= HC_R3INT_ENA; |
| 404 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 405 | if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) && |
| 406 | (phba->cfg_poll & DISABLE_FCP_RING_INT)) |
| 407 | status &= ~(HC_R0INT_ENA << LPFC_FCP_RING); |
| 408 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 409 | writel(status, phba->HCregaddr); |
| 410 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 411 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 412 | |
| 413 | /* |
| 414 | * Setup the ring 0 (els) timeout handler |
| 415 | */ |
| 416 | timeout = phba->fc_ratov << 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 417 | mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 418 | mod_timer(&phba->hb_tmofunc, jiffies + HZ * LPFC_HB_MBOX_INTERVAL); |
| 419 | phba->hb_outstanding = 0; |
| 420 | phba->last_completion_time = jiffies; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 421 | |
| 422 | lpfc_init_link(phba, pmb, phba->cfg_topology, phba->cfg_link_speed); |
| 423 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 424 | lpfc_set_loopback_flag(phba); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 425 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
James Smart | 8aee918 | 2006-08-31 12:27:57 -0400 | [diff] [blame] | 426 | if (rc != MBX_SUCCESS) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 427 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 428 | "0454 Adapter failed to init, mbxCmd x%x " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 429 | "INIT_LINK, mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 430 | mb->mbxCommand, mb->mbxStatus); |
| 431 | |
| 432 | /* Clear all interrupt enable conditions */ |
| 433 | writel(0, phba->HCregaddr); |
| 434 | readl(phba->HCregaddr); /* flush */ |
| 435 | /* Clear all pending interrupts */ |
| 436 | writel(0xffffffff, phba->HAregaddr); |
| 437 | readl(phba->HAregaddr); /* flush */ |
| 438 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 439 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | 8aee918 | 2006-08-31 12:27:57 -0400 | [diff] [blame] | 440 | if (rc != MBX_BUSY) |
| 441 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 442 | return -EIO; |
| 443 | } |
| 444 | /* MBOX buffer will be freed in mbox compl */ |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 445 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 446 | lpfc_config_async(phba, pmb, LPFC_ELS_RING); |
| 447 | pmb->mbox_cmpl = lpfc_config_async_cmpl; |
| 448 | pmb->vport = phba->pport; |
| 449 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 450 | |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 451 | if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { |
| 452 | lpfc_printf_log(phba, |
| 453 | KERN_ERR, |
| 454 | LOG_INIT, |
| 455 | "0456 Adapter failed to issue " |
| 456 | "ASYNCEVT_ENABLE mbox status x%x \n.", |
| 457 | rc); |
| 458 | mempool_free(pmb, phba->mbox_mem_pool); |
| 459 | } |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 460 | return 0; |
James Smart | ce8b3ce | 2006-07-06 15:50:36 -0400 | [diff] [blame] | 461 | } |
| 462 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 463 | /** |
| 464 | * lpfc_hba_down_prep: Perform lpfc uninitialization prior to HBA reset. |
| 465 | * @phba: pointer to lpfc HBA data structure. |
| 466 | * |
| 467 | * This routine will do LPFC uninitialization before the HBA is reset when |
| 468 | * bringing down the SLI Layer. |
| 469 | * |
| 470 | * Return codes |
| 471 | * 0 - success. |
| 472 | * Any other value - error. |
| 473 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 474 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 475 | lpfc_hba_down_prep(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 476 | { |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 477 | struct lpfc_vport **vports; |
| 478 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 479 | /* Disable interrupts */ |
| 480 | writel(0, phba->HCregaddr); |
| 481 | readl(phba->HCregaddr); /* flush */ |
| 482 | |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 483 | if (phba->pport->load_flag & FC_UNLOADING) |
| 484 | lpfc_cleanup_discovery_resources(phba->pport); |
| 485 | else { |
| 486 | vports = lpfc_create_vport_work_array(phba); |
| 487 | if (vports != NULL) |
| 488 | for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) |
| 489 | lpfc_cleanup_discovery_resources(vports[i]); |
| 490 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 491 | } |
| 492 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 493 | } |
| 494 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 495 | /** |
| 496 | * lpfc_hba_down_post: Perform lpfc uninitialization after HBA reset. |
| 497 | * @phba: pointer to lpfc HBA data structure. |
| 498 | * |
| 499 | * This routine will do uninitialization after the HBA is reset when bring |
| 500 | * down the SLI Layer. |
| 501 | * |
| 502 | * Return codes |
| 503 | * 0 - sucess. |
| 504 | * Any other value - error. |
| 505 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 506 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 507 | lpfc_hba_down_post(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 508 | { |
| 509 | struct lpfc_sli *psli = &phba->sli; |
| 510 | struct lpfc_sli_ring *pring; |
| 511 | struct lpfc_dmabuf *mp, *next_mp; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 512 | struct lpfc_iocbq *iocb; |
| 513 | IOCB_t *cmd = NULL; |
| 514 | LIST_HEAD(completions); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 515 | int i; |
| 516 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 517 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) |
| 518 | lpfc_sli_hbqbuf_free_all(phba); |
| 519 | else { |
| 520 | /* Cleanup preposted buffers on the ELS ring */ |
| 521 | pring = &psli->ring[LPFC_ELS_RING]; |
| 522 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 523 | list_del(&mp->list); |
| 524 | pring->postbufq_cnt--; |
| 525 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 526 | kfree(mp); |
| 527 | } |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 528 | } |
| 529 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 530 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 531 | for (i = 0; i < psli->num_rings; i++) { |
| 532 | pring = &psli->ring[i]; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 533 | |
| 534 | /* At this point in time the HBA is either reset or DOA. Either |
| 535 | * way, nothing should be on txcmplq as it will NEVER complete. |
| 536 | */ |
| 537 | list_splice_init(&pring->txcmplq, &completions); |
| 538 | pring->txcmplq_cnt = 0; |
| 539 | spin_unlock_irq(&phba->hbalock); |
| 540 | |
| 541 | while (!list_empty(&completions)) { |
| 542 | iocb = list_get_first(&completions, struct lpfc_iocbq, |
| 543 | list); |
| 544 | cmd = &iocb->iocb; |
| 545 | list_del_init(&iocb->list); |
| 546 | |
| 547 | if (!iocb->iocb_cmpl) |
| 548 | lpfc_sli_release_iocbq(phba, iocb); |
| 549 | else { |
| 550 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 551 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 552 | (iocb->iocb_cmpl) (phba, iocb, iocb); |
| 553 | } |
| 554 | } |
| 555 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 556 | lpfc_sli_abort_iocb_ring(phba, pring); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 557 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 558 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 559 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 560 | |
| 561 | return 0; |
| 562 | } |
| 563 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 564 | /** |
| 565 | * lpfc_hb_timeout: The HBA-timer timeout handler. |
| 566 | * @ptr: unsigned long holds the pointer to lpfc hba data structure. |
| 567 | * |
| 568 | * This is the HBA-timer timeout handler registered to the lpfc driver. When |
| 569 | * this timer fires, a HBA timeout event shall be posted to the lpfc driver |
| 570 | * work-port-events bitmap and the worker thread is notified. This timeout |
| 571 | * event will be used by the worker thread to invoke the actual timeout |
| 572 | * handler routine, lpfc_hb_timeout_handler. Any periodical operations will |
| 573 | * be performed in the timeout handler and the HBA timeout event bit shall |
| 574 | * be cleared by the worker thread after it has taken the event bitmap out. |
| 575 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 576 | static void |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 577 | lpfc_hb_timeout(unsigned long ptr) |
| 578 | { |
| 579 | struct lpfc_hba *phba; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 580 | uint32_t tmo_posted; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 581 | unsigned long iflag; |
| 582 | |
| 583 | phba = (struct lpfc_hba *)ptr; |
| 584 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 585 | tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO; |
| 586 | if (!tmo_posted) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 587 | phba->pport->work_port_events |= WORKER_HB_TMO; |
| 588 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
| 589 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 590 | if (!tmo_posted) |
| 591 | lpfc_worker_wake_up(phba); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 592 | return; |
| 593 | } |
| 594 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 595 | /** |
| 596 | * lpfc_hb_mbox_cmpl: The lpfc heart-beat mailbox command callback function. |
| 597 | * @phba: pointer to lpfc hba data structure. |
| 598 | * @pmboxq: pointer to the driver internal queue element for mailbox command. |
| 599 | * |
| 600 | * This is the callback function to the lpfc heart-beat mailbox command. |
| 601 | * If configured, the lpfc driver issues the heart-beat mailbox command to |
| 602 | * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the |
| 603 | * heart-beat mailbox command is issued, the driver shall set up heart-beat |
| 604 | * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks |
| 605 | * heart-beat outstanding state. Once the mailbox command comes back and |
| 606 | * no error conditions detected, the heart-beat mailbox command timer is |
| 607 | * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding |
| 608 | * state is cleared for the next heart-beat. If the timer expired with the |
| 609 | * heart-beat outstanding state set, the driver will put the HBA offline. |
| 610 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 611 | static void |
| 612 | lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq) |
| 613 | { |
| 614 | unsigned long drvr_flag; |
| 615 | |
| 616 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 617 | phba->hb_outstanding = 0; |
| 618 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 619 | |
| 620 | mempool_free(pmboxq, phba->mbox_mem_pool); |
| 621 | if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) && |
| 622 | !(phba->link_state == LPFC_HBA_ERROR) && |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 623 | !(phba->pport->load_flag & FC_UNLOADING)) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 624 | mod_timer(&phba->hb_tmofunc, |
| 625 | jiffies + HZ * LPFC_HB_MBOX_INTERVAL); |
| 626 | return; |
| 627 | } |
| 628 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 629 | /** |
| 630 | * lpfc_hb_timeout_handler: The HBA-timer timeout handler. |
| 631 | * @phba: pointer to lpfc hba data structure. |
| 632 | * |
| 633 | * This is the actual HBA-timer timeout handler to be invoked by the worker |
| 634 | * thread whenever the HBA timer fired and HBA-timeout event posted. This |
| 635 | * handler performs any periodic operations needed for the device. If such |
| 636 | * periodic event has already been attended to either in the interrupt handler |
| 637 | * or by processing slow-ring or fast-ring events within the HBA-timer |
| 638 | * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets |
| 639 | * the timer for the next timeout period. If lpfc heart-beat mailbox command |
| 640 | * is configured and there is no heart-beat mailbox command outstanding, a |
| 641 | * heart-beat mailbox is issued and timer set properly. Otherwise, if there |
| 642 | * has been a heart-beat mailbox command outstanding, the HBA shall be put |
| 643 | * to offline. |
| 644 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 645 | void |
| 646 | lpfc_hb_timeout_handler(struct lpfc_hba *phba) |
| 647 | { |
| 648 | LPFC_MBOXQ_t *pmboxq; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 649 | struct lpfc_dmabuf *buf_ptr; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 650 | int retval; |
| 651 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 652 | LIST_HEAD(completions); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 653 | |
| 654 | if ((phba->link_state == LPFC_HBA_ERROR) || |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 655 | (phba->pport->load_flag & FC_UNLOADING) || |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 656 | (phba->pport->fc_flag & FC_OFFLINE_MODE)) |
| 657 | return; |
| 658 | |
| 659 | spin_lock_irq(&phba->pport->work_port_lock); |
| 660 | /* If the timer is already canceled do nothing */ |
| 661 | if (!(phba->pport->work_port_events & WORKER_HB_TMO)) { |
| 662 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 663 | return; |
| 664 | } |
| 665 | |
| 666 | if (time_after(phba->last_completion_time + LPFC_HB_MBOX_INTERVAL * HZ, |
| 667 | jiffies)) { |
| 668 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 669 | if (!phba->hb_outstanding) |
| 670 | mod_timer(&phba->hb_tmofunc, |
| 671 | jiffies + HZ * LPFC_HB_MBOX_INTERVAL); |
| 672 | else |
| 673 | mod_timer(&phba->hb_tmofunc, |
| 674 | jiffies + HZ * LPFC_HB_MBOX_TIMEOUT); |
| 675 | return; |
| 676 | } |
| 677 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 678 | |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 679 | if (phba->elsbuf_cnt && |
| 680 | (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) { |
| 681 | spin_lock_irq(&phba->hbalock); |
| 682 | list_splice_init(&phba->elsbuf, &completions); |
| 683 | phba->elsbuf_cnt = 0; |
| 684 | phba->elsbuf_prev_cnt = 0; |
| 685 | spin_unlock_irq(&phba->hbalock); |
| 686 | |
| 687 | while (!list_empty(&completions)) { |
| 688 | list_remove_head(&completions, buf_ptr, |
| 689 | struct lpfc_dmabuf, list); |
| 690 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 691 | kfree(buf_ptr); |
| 692 | } |
| 693 | } |
| 694 | phba->elsbuf_prev_cnt = phba->elsbuf_cnt; |
| 695 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 696 | /* If there is no heart beat outstanding, issue a heartbeat command */ |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 697 | if (phba->cfg_enable_hba_heartbeat) { |
| 698 | if (!phba->hb_outstanding) { |
| 699 | pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL); |
| 700 | if (!pmboxq) { |
| 701 | mod_timer(&phba->hb_tmofunc, |
| 702 | jiffies + HZ * LPFC_HB_MBOX_INTERVAL); |
| 703 | return; |
| 704 | } |
| 705 | |
| 706 | lpfc_heart_beat(phba, pmboxq); |
| 707 | pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl; |
| 708 | pmboxq->vport = phba->pport; |
| 709 | retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT); |
| 710 | |
| 711 | if (retval != MBX_BUSY && retval != MBX_SUCCESS) { |
| 712 | mempool_free(pmboxq, phba->mbox_mem_pool); |
| 713 | mod_timer(&phba->hb_tmofunc, |
| 714 | jiffies + HZ * LPFC_HB_MBOX_INTERVAL); |
| 715 | return; |
| 716 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 717 | mod_timer(&phba->hb_tmofunc, |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 718 | jiffies + HZ * LPFC_HB_MBOX_TIMEOUT); |
| 719 | phba->hb_outstanding = 1; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 720 | return; |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 721 | } else { |
| 722 | /* |
| 723 | * If heart beat timeout called with hb_outstanding set |
| 724 | * we need to take the HBA offline. |
| 725 | */ |
| 726 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 727 | "0459 Adapter heartbeat failure, " |
| 728 | "taking this port offline.\n"); |
| 729 | |
| 730 | spin_lock_irq(&phba->hbalock); |
| 731 | psli->sli_flag &= ~LPFC_SLI2_ACTIVE; |
| 732 | spin_unlock_irq(&phba->hbalock); |
| 733 | |
| 734 | lpfc_offline_prep(phba); |
| 735 | lpfc_offline(phba); |
| 736 | lpfc_unblock_mgmt_io(phba); |
| 737 | phba->link_state = LPFC_HBA_ERROR; |
| 738 | lpfc_hba_down_post(phba); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 739 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 740 | } |
| 741 | } |
| 742 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 743 | /** |
| 744 | * lpfc_offline_eratt: Bring lpfc offline on hardware error attention. |
| 745 | * @phba: pointer to lpfc hba data structure. |
| 746 | * |
| 747 | * This routine is called to bring the HBA offline when HBA hardware error |
| 748 | * other than Port Error 6 has been detected. |
| 749 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 750 | static void |
| 751 | lpfc_offline_eratt(struct lpfc_hba *phba) |
| 752 | { |
| 753 | struct lpfc_sli *psli = &phba->sli; |
| 754 | |
| 755 | spin_lock_irq(&phba->hbalock); |
| 756 | psli->sli_flag &= ~LPFC_SLI2_ACTIVE; |
| 757 | spin_unlock_irq(&phba->hbalock); |
| 758 | lpfc_offline_prep(phba); |
| 759 | |
| 760 | lpfc_offline(phba); |
| 761 | lpfc_reset_barrier(phba); |
| 762 | lpfc_sli_brdreset(phba); |
| 763 | lpfc_hba_down_post(phba); |
| 764 | lpfc_sli_brdready(phba, HS_MBRDY); |
| 765 | lpfc_unblock_mgmt_io(phba); |
| 766 | phba->link_state = LPFC_HBA_ERROR; |
| 767 | return; |
| 768 | } |
| 769 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 770 | /** |
| 771 | * lpfc_handle_eratt: The HBA hardware error handler. |
| 772 | * @phba: pointer to lpfc hba data structure. |
| 773 | * |
| 774 | * This routine is invoked to handle the following HBA hardware error |
| 775 | * conditions: |
| 776 | * 1 - HBA error attention interrupt |
| 777 | * 2 - DMA ring index out of range |
| 778 | * 3 - Mailbox command came back as unknown |
| 779 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 780 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 781 | lpfc_handle_eratt(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 782 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 783 | struct lpfc_vport *vport = phba->pport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 784 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 785 | struct lpfc_sli_ring *pring; |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 786 | uint32_t event_data; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 787 | unsigned long temperature; |
| 788 | struct temp_event temp_event_data; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 789 | struct Scsi_Host *shost; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 790 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 791 | /* If the pci channel is offline, ignore possible errors, |
| 792 | * since we cannot communicate with the pci card anyway. */ |
| 793 | if (pci_channel_offline(phba->pcidev)) |
| 794 | return; |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 795 | /* If resets are disabled then leave the HBA alone and return */ |
| 796 | if (!phba->cfg_enable_hba_reset) |
| 797 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 798 | |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 799 | if (phba->work_hs & HS_FFER6) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 800 | /* Re-establishing Link */ |
| 801 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 802 | "1301 Re-establishing Link " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 803 | "Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 804 | phba->work_hs, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 805 | phba->work_status[0], phba->work_status[1]); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 806 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 807 | spin_lock_irq(&phba->hbalock); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 808 | psli->sli_flag &= ~LPFC_SLI2_ACTIVE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 809 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 810 | |
| 811 | /* |
| 812 | * Firmware stops when it triggled erratt with HS_FFER6. |
| 813 | * That could cause the I/Os dropped by the firmware. |
| 814 | * Error iocb (I/O) on txcmplq and let the SCSI layer |
| 815 | * retry it after re-establishing link. |
| 816 | */ |
| 817 | pring = &psli->ring[psli->fcp_ring]; |
| 818 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 819 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 820 | /* |
| 821 | * There was a firmware error. Take the hba offline and then |
| 822 | * attempt to restart it. |
| 823 | */ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 824 | lpfc_offline_prep(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 825 | lpfc_offline(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 826 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 827 | if (lpfc_online(phba) == 0) { /* Initialize the HBA */ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 828 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 829 | return; |
| 830 | } |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 831 | lpfc_unblock_mgmt_io(phba); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 832 | } else if (phba->work_hs & HS_CRIT_TEMP) { |
| 833 | temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET); |
| 834 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 835 | temp_event_data.event_code = LPFC_CRIT_TEMP; |
| 836 | temp_event_data.data = (uint32_t)temperature; |
| 837 | |
| 838 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 839 | "0406 Adapter maximum temperature exceeded " |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 840 | "(%ld), taking this port offline " |
| 841 | "Data: x%x x%x x%x\n", |
| 842 | temperature, phba->work_hs, |
| 843 | phba->work_status[0], phba->work_status[1]); |
| 844 | |
| 845 | shost = lpfc_shost_from_vport(phba->pport); |
| 846 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 847 | sizeof(temp_event_data), |
| 848 | (char *) &temp_event_data, |
| 849 | SCSI_NL_VID_TYPE_PCI |
| 850 | | PCI_VENDOR_ID_EMULEX); |
| 851 | |
James Smart | 7af6705 | 2007-10-27 13:38:11 -0400 | [diff] [blame] | 852 | spin_lock_irq(&phba->hbalock); |
James Smart | 7af6705 | 2007-10-27 13:38:11 -0400 | [diff] [blame] | 853 | phba->over_temp_state = HBA_OVER_TEMP; |
| 854 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 855 | lpfc_offline_eratt(phba); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 856 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 857 | } else { |
| 858 | /* The if clause above forces this code path when the status |
| 859 | * failure is a value other than FFER6. Do not call the offline |
| 860 | * twice. This is the adapter hardware error path. |
| 861 | */ |
| 862 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 863 | "0457 Adapter Hardware Error " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 864 | "Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 865 | phba->work_hs, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 866 | phba->work_status[0], phba->work_status[1]); |
| 867 | |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 868 | event_data = FC_REG_DUMP_EVENT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 869 | shost = lpfc_shost_from_vport(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 870 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 871 | sizeof(event_data), (char *) &event_data, |
| 872 | SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX); |
| 873 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 874 | lpfc_offline_eratt(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 875 | } |
| 876 | } |
| 877 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 878 | /** |
| 879 | * lpfc_handle_latt: The HBA link event handler. |
| 880 | * @phba: pointer to lpfc hba data structure. |
| 881 | * |
| 882 | * This routine is invoked from the worker thread to handle a HBA host |
| 883 | * attention link event. |
| 884 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 885 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 886 | lpfc_handle_latt(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 887 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 888 | struct lpfc_vport *vport = phba->pport; |
| 889 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 890 | LPFC_MBOXQ_t *pmb; |
| 891 | volatile uint32_t control; |
| 892 | struct lpfc_dmabuf *mp; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 893 | int rc = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 894 | |
| 895 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 896 | if (!pmb) { |
| 897 | rc = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 898 | goto lpfc_handle_latt_err_exit; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 899 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 900 | |
| 901 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 902 | if (!mp) { |
| 903 | rc = 2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 904 | goto lpfc_handle_latt_free_pmb; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 905 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 906 | |
| 907 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 908 | if (!mp->virt) { |
| 909 | rc = 3; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 910 | goto lpfc_handle_latt_free_mp; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 911 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 912 | |
James.Smart@Emulex.Com | 6281bfe | 2005-11-28 11:41:33 -0500 | [diff] [blame] | 913 | /* Cleanup any outstanding ELS commands */ |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 914 | lpfc_els_flush_all_cmd(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 915 | |
| 916 | psli->slistat.link_event++; |
| 917 | lpfc_read_la(phba, pmb, mp); |
| 918 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_la; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 919 | pmb->vport = vport; |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 920 | /* Block ELS IOCBs until we have processed this mbox command */ |
| 921 | phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 922 | rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 923 | if (rc == MBX_NOT_FINISHED) { |
| 924 | rc = 4; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 925 | goto lpfc_handle_latt_free_mbuf; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 926 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 927 | |
| 928 | /* Clear Link Attention in HA REG */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 929 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 930 | writel(HA_LATT, phba->HAregaddr); |
| 931 | readl(phba->HAregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 932 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 933 | |
| 934 | return; |
| 935 | |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 936 | lpfc_handle_latt_free_mbuf: |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 937 | phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 938 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 939 | lpfc_handle_latt_free_mp: |
| 940 | kfree(mp); |
| 941 | lpfc_handle_latt_free_pmb: |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 942 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 943 | lpfc_handle_latt_err_exit: |
| 944 | /* Enable Link attention interrupts */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 945 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 946 | psli->sli_flag |= LPFC_PROCESS_LA; |
| 947 | control = readl(phba->HCregaddr); |
| 948 | control |= HC_LAINT_ENA; |
| 949 | writel(control, phba->HCregaddr); |
| 950 | readl(phba->HCregaddr); /* flush */ |
| 951 | |
| 952 | /* Clear Link Attention in HA REG */ |
| 953 | writel(HA_LATT, phba->HAregaddr); |
| 954 | readl(phba->HAregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 955 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 956 | lpfc_linkdown(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 957 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 958 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 959 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 960 | "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 961 | |
| 962 | return; |
| 963 | } |
| 964 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 965 | /** |
| 966 | * lpfc_parse_vpd: Parse VPD (Vital Product Data). |
| 967 | * @phba: pointer to lpfc hba data structure. |
| 968 | * @vpd: pointer to the vital product data. |
| 969 | * @len: length of the vital product data in bytes. |
| 970 | * |
| 971 | * This routine parses the Vital Product Data (VPD). The VPD is treated as |
| 972 | * an array of characters. In this routine, the ModelName, ProgramType, and |
| 973 | * ModelDesc, etc. fields of the phba data structure will be populated. |
| 974 | * |
| 975 | * Return codes |
| 976 | * 0 - pointer to the VPD passed in is NULL |
| 977 | * 1 - success |
| 978 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 979 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 980 | lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 981 | { |
| 982 | uint8_t lenlo, lenhi; |
Anton Blanchard | 07da60c | 2007-03-21 08:41:47 -0500 | [diff] [blame] | 983 | int Length; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 984 | int i, j; |
| 985 | int finished = 0; |
| 986 | int index = 0; |
| 987 | |
| 988 | if (!vpd) |
| 989 | return 0; |
| 990 | |
| 991 | /* Vital Product */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 992 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 993 | "0455 Vital Product Data: x%x x%x x%x x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 994 | (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2], |
| 995 | (uint32_t) vpd[3]); |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 996 | while (!finished && (index < (len - 4))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 997 | switch (vpd[index]) { |
| 998 | case 0x82: |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 999 | case 0x91: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1000 | index += 1; |
| 1001 | lenlo = vpd[index]; |
| 1002 | index += 1; |
| 1003 | lenhi = vpd[index]; |
| 1004 | index += 1; |
| 1005 | i = ((((unsigned short)lenhi) << 8) + lenlo); |
| 1006 | index += i; |
| 1007 | break; |
| 1008 | case 0x90: |
| 1009 | index += 1; |
| 1010 | lenlo = vpd[index]; |
| 1011 | index += 1; |
| 1012 | lenhi = vpd[index]; |
| 1013 | index += 1; |
| 1014 | Length = ((((unsigned short)lenhi) << 8) + lenlo); |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1015 | if (Length > len - index) |
| 1016 | Length = len - index; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1017 | while (Length > 0) { |
| 1018 | /* Look for Serial Number */ |
| 1019 | if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) { |
| 1020 | index += 2; |
| 1021 | i = vpd[index]; |
| 1022 | index += 1; |
| 1023 | j = 0; |
| 1024 | Length -= (3+i); |
| 1025 | while(i--) { |
| 1026 | phba->SerialNumber[j++] = vpd[index++]; |
| 1027 | if (j == 31) |
| 1028 | break; |
| 1029 | } |
| 1030 | phba->SerialNumber[j] = 0; |
| 1031 | continue; |
| 1032 | } |
| 1033 | else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) { |
| 1034 | phba->vpd_flag |= VPD_MODEL_DESC; |
| 1035 | index += 2; |
| 1036 | i = vpd[index]; |
| 1037 | index += 1; |
| 1038 | j = 0; |
| 1039 | Length -= (3+i); |
| 1040 | while(i--) { |
| 1041 | phba->ModelDesc[j++] = vpd[index++]; |
| 1042 | if (j == 255) |
| 1043 | break; |
| 1044 | } |
| 1045 | phba->ModelDesc[j] = 0; |
| 1046 | continue; |
| 1047 | } |
| 1048 | else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) { |
| 1049 | phba->vpd_flag |= VPD_MODEL_NAME; |
| 1050 | index += 2; |
| 1051 | i = vpd[index]; |
| 1052 | index += 1; |
| 1053 | j = 0; |
| 1054 | Length -= (3+i); |
| 1055 | while(i--) { |
| 1056 | phba->ModelName[j++] = vpd[index++]; |
| 1057 | if (j == 79) |
| 1058 | break; |
| 1059 | } |
| 1060 | phba->ModelName[j] = 0; |
| 1061 | continue; |
| 1062 | } |
| 1063 | else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) { |
| 1064 | phba->vpd_flag |= VPD_PROGRAM_TYPE; |
| 1065 | index += 2; |
| 1066 | i = vpd[index]; |
| 1067 | index += 1; |
| 1068 | j = 0; |
| 1069 | Length -= (3+i); |
| 1070 | while(i--) { |
| 1071 | phba->ProgramType[j++] = vpd[index++]; |
| 1072 | if (j == 255) |
| 1073 | break; |
| 1074 | } |
| 1075 | phba->ProgramType[j] = 0; |
| 1076 | continue; |
| 1077 | } |
| 1078 | else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) { |
| 1079 | phba->vpd_flag |= VPD_PORT; |
| 1080 | index += 2; |
| 1081 | i = vpd[index]; |
| 1082 | index += 1; |
| 1083 | j = 0; |
| 1084 | Length -= (3+i); |
| 1085 | while(i--) { |
| 1086 | phba->Port[j++] = vpd[index++]; |
| 1087 | if (j == 19) |
| 1088 | break; |
| 1089 | } |
| 1090 | phba->Port[j] = 0; |
| 1091 | continue; |
| 1092 | } |
| 1093 | else { |
| 1094 | index += 2; |
| 1095 | i = vpd[index]; |
| 1096 | index += 1; |
| 1097 | index += i; |
| 1098 | Length -= (3 + i); |
| 1099 | } |
| 1100 | } |
| 1101 | finished = 0; |
| 1102 | break; |
| 1103 | case 0x78: |
| 1104 | finished = 1; |
| 1105 | break; |
| 1106 | default: |
| 1107 | index ++; |
| 1108 | break; |
| 1109 | } |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1110 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1111 | |
| 1112 | return(1); |
| 1113 | } |
| 1114 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1115 | /** |
| 1116 | * lpfc_get_hba_model_desc: Retrieve HBA device model name and description. |
| 1117 | * @phba: pointer to lpfc hba data structure. |
| 1118 | * @mdp: pointer to the data structure to hold the derived model name. |
| 1119 | * @descp: pointer to the data structure to hold the derived description. |
| 1120 | * |
| 1121 | * This routine retrieves HBA's description based on its registered PCI device |
| 1122 | * ID. The @descp passed into this function points to an array of 256 chars. It |
| 1123 | * shall be returned with the model name, maximum speed, and the host bus type. |
| 1124 | * The @mdp passed into this function points to an array of 80 chars. When the |
| 1125 | * function returns, the @mdp will be filled with the model name. |
| 1126 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1127 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1128 | 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] | 1129 | { |
| 1130 | lpfc_vpd_t *vp; |
James.Smart@Emulex.Com | fefcb2b | 2005-11-28 15:08:56 -0500 | [diff] [blame] | 1131 | uint16_t dev_id = phba->pcidev->device; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1132 | int max_speed; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 1133 | int GE = 0; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1134 | struct { |
| 1135 | char * name; |
| 1136 | int max_speed; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1137 | char * bus; |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1138 | } m = {"<Unknown>", 0, ""}; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1139 | |
| 1140 | if (mdp && mdp[0] != '\0' |
| 1141 | && descp && descp[0] != '\0') |
| 1142 | return; |
| 1143 | |
| 1144 | if (phba->lmt & LMT_10Gb) |
| 1145 | max_speed = 10; |
| 1146 | else if (phba->lmt & LMT_8Gb) |
| 1147 | max_speed = 8; |
| 1148 | else if (phba->lmt & LMT_4Gb) |
| 1149 | max_speed = 4; |
| 1150 | else if (phba->lmt & LMT_2Gb) |
| 1151 | max_speed = 2; |
| 1152 | else |
| 1153 | max_speed = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1154 | |
| 1155 | vp = &phba->vpd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1156 | |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1157 | switch (dev_id) { |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 1158 | case PCI_DEVICE_ID_FIREFLY: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1159 | m = (typeof(m)){"LP6000", max_speed, "PCI"}; |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 1160 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1161 | case PCI_DEVICE_ID_SUPERFLY: |
| 1162 | if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3) |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1163 | m = (typeof(m)){"LP7000", max_speed, "PCI"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1164 | else |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1165 | m = (typeof(m)){"LP7000E", max_speed, "PCI"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1166 | break; |
| 1167 | case PCI_DEVICE_ID_DRAGONFLY: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1168 | m = (typeof(m)){"LP8000", max_speed, "PCI"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1169 | break; |
| 1170 | case PCI_DEVICE_ID_CENTAUR: |
| 1171 | if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID) |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1172 | m = (typeof(m)){"LP9002", max_speed, "PCI"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1173 | else |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1174 | m = (typeof(m)){"LP9000", max_speed, "PCI"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1175 | break; |
| 1176 | case PCI_DEVICE_ID_RFLY: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1177 | m = (typeof(m)){"LP952", max_speed, "PCI"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1178 | break; |
| 1179 | case PCI_DEVICE_ID_PEGASUS: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1180 | m = (typeof(m)){"LP9802", max_speed, "PCI-X"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1181 | break; |
| 1182 | case PCI_DEVICE_ID_THOR: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1183 | m = (typeof(m)){"LP10000", max_speed, "PCI-X"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1184 | break; |
| 1185 | case PCI_DEVICE_ID_VIPER: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1186 | m = (typeof(m)){"LPX1000", max_speed, "PCI-X"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1187 | break; |
| 1188 | case PCI_DEVICE_ID_PFLY: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1189 | m = (typeof(m)){"LP982", max_speed, "PCI-X"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1190 | break; |
| 1191 | case PCI_DEVICE_ID_TFLY: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1192 | m = (typeof(m)){"LP1050", max_speed, "PCI-X"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1193 | break; |
| 1194 | case PCI_DEVICE_ID_HELIOS: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1195 | m = (typeof(m)){"LP11000", max_speed, "PCI-X2"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1196 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1197 | case PCI_DEVICE_ID_HELIOS_SCSP: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1198 | m = (typeof(m)){"LP11000-SP", max_speed, "PCI-X2"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1199 | break; |
| 1200 | case PCI_DEVICE_ID_HELIOS_DCSP: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1201 | m = (typeof(m)){"LP11002-SP", max_speed, "PCI-X2"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1202 | break; |
| 1203 | case PCI_DEVICE_ID_NEPTUNE: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1204 | m = (typeof(m)){"LPe1000", max_speed, "PCIe"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1205 | break; |
| 1206 | case PCI_DEVICE_ID_NEPTUNE_SCSP: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1207 | m = (typeof(m)){"LPe1000-SP", max_speed, "PCIe"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1208 | break; |
| 1209 | case PCI_DEVICE_ID_NEPTUNE_DCSP: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1210 | m = (typeof(m)){"LPe1002-SP", max_speed, "PCIe"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1211 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1212 | case PCI_DEVICE_ID_BMID: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1213 | m = (typeof(m)){"LP1150", max_speed, "PCI-X2"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1214 | break; |
| 1215 | case PCI_DEVICE_ID_BSMB: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1216 | m = (typeof(m)){"LP111", max_speed, "PCI-X2"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1217 | break; |
| 1218 | case PCI_DEVICE_ID_ZEPHYR: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1219 | m = (typeof(m)){"LPe11000", max_speed, "PCIe"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1220 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1221 | case PCI_DEVICE_ID_ZEPHYR_SCSP: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1222 | m = (typeof(m)){"LPe11000", max_speed, "PCIe"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1223 | break; |
| 1224 | case PCI_DEVICE_ID_ZEPHYR_DCSP: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1225 | m = (typeof(m)){"LPe11002-SP", max_speed, "PCIe"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1226 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1227 | case PCI_DEVICE_ID_ZMID: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1228 | m = (typeof(m)){"LPe1150", max_speed, "PCIe"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1229 | break; |
| 1230 | case PCI_DEVICE_ID_ZSMB: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1231 | m = (typeof(m)){"LPe111", max_speed, "PCIe"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1232 | break; |
| 1233 | case PCI_DEVICE_ID_LP101: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1234 | m = (typeof(m)){"LP101", max_speed, "PCI-X"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1235 | break; |
| 1236 | case PCI_DEVICE_ID_LP10000S: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1237 | m = (typeof(m)){"LP10000-S", max_speed, "PCI"}; |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 1238 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1239 | case PCI_DEVICE_ID_LP11000S: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1240 | m = (typeof(m)){"LP11000-S", max_speed, |
| 1241 | "PCI-X2"}; |
| 1242 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1243 | case PCI_DEVICE_ID_LPE11000S: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1244 | m = (typeof(m)){"LPe11000-S", max_speed, |
| 1245 | "PCIe"}; |
James.Smart@Emulex.Com | 5cc36b3 | 2005-11-28 11:42:19 -0500 | [diff] [blame] | 1246 | break; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 1247 | case PCI_DEVICE_ID_SAT: |
| 1248 | m = (typeof(m)){"LPe12000", max_speed, "PCIe"}; |
| 1249 | break; |
| 1250 | case PCI_DEVICE_ID_SAT_MID: |
| 1251 | m = (typeof(m)){"LPe1250", max_speed, "PCIe"}; |
| 1252 | break; |
| 1253 | case PCI_DEVICE_ID_SAT_SMB: |
| 1254 | m = (typeof(m)){"LPe121", max_speed, "PCIe"}; |
| 1255 | break; |
| 1256 | case PCI_DEVICE_ID_SAT_DCSP: |
| 1257 | m = (typeof(m)){"LPe12002-SP", max_speed, "PCIe"}; |
| 1258 | break; |
| 1259 | case PCI_DEVICE_ID_SAT_SCSP: |
| 1260 | m = (typeof(m)){"LPe12000-SP", max_speed, "PCIe"}; |
| 1261 | break; |
| 1262 | case PCI_DEVICE_ID_SAT_S: |
| 1263 | m = (typeof(m)){"LPe12000-S", max_speed, "PCIe"}; |
| 1264 | break; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 1265 | case PCI_DEVICE_ID_HORNET: |
| 1266 | m = (typeof(m)){"LP21000", max_speed, "PCIe"}; |
| 1267 | GE = 1; |
| 1268 | break; |
| 1269 | case PCI_DEVICE_ID_PROTEUS_VF: |
| 1270 | m = (typeof(m)) {"LPev12000", max_speed, "PCIe IOV"}; |
| 1271 | break; |
| 1272 | case PCI_DEVICE_ID_PROTEUS_PF: |
| 1273 | m = (typeof(m)) {"LPev12000", max_speed, "PCIe IOV"}; |
| 1274 | break; |
| 1275 | case PCI_DEVICE_ID_PROTEUS_S: |
| 1276 | m = (typeof(m)) {"LPemv12002-S", max_speed, "PCIe IOV"}; |
| 1277 | break; |
James.Smart@Emulex.Com | 5cc36b3 | 2005-11-28 11:42:19 -0500 | [diff] [blame] | 1278 | default: |
Randy Dunlap | 041976f | 2006-06-25 01:58:51 -0700 | [diff] [blame] | 1279 | m = (typeof(m)){ NULL }; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1280 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1281 | } |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1282 | |
| 1283 | if (mdp && mdp[0] == '\0') |
| 1284 | snprintf(mdp, 79,"%s", m.name); |
| 1285 | if (descp && descp[0] == '\0') |
| 1286 | snprintf(descp, 255, |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 1287 | "Emulex %s %d%s %s %s", |
| 1288 | m.name, m.max_speed, |
| 1289 | (GE) ? "GE" : "Gb", |
| 1290 | m.bus, |
| 1291 | (GE) ? "FCoE Adapter" : "Fibre Channel Adapter"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1292 | } |
| 1293 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1294 | /** |
| 1295 | * lpfc_post_buffer: Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring. |
| 1296 | * @phba: pointer to lpfc hba data structure. |
| 1297 | * @pring: pointer to a IOCB ring. |
| 1298 | * @cnt: the number of IOCBs to be posted to the IOCB ring. |
| 1299 | * |
| 1300 | * This routine posts a given number of IOCBs with the associated DMA buffer |
| 1301 | * descriptors specified by the cnt argument to the given IOCB ring. |
| 1302 | * |
| 1303 | * Return codes |
| 1304 | * The number of IOCBs NOT able to be posted to the IOCB ring. |
| 1305 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1306 | int |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 1307 | lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1308 | { |
| 1309 | IOCB_t *icmd; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 1310 | struct lpfc_iocbq *iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1311 | struct lpfc_dmabuf *mp1, *mp2; |
| 1312 | |
| 1313 | cnt += pring->missbufcnt; |
| 1314 | |
| 1315 | /* While there are buffers to post */ |
| 1316 | while (cnt > 0) { |
| 1317 | /* Allocate buffer for command iocb */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 1318 | iocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1319 | if (iocb == NULL) { |
| 1320 | pring->missbufcnt = cnt; |
| 1321 | return cnt; |
| 1322 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1323 | icmd = &iocb->iocb; |
| 1324 | |
| 1325 | /* 2 buffers can be posted per command */ |
| 1326 | /* Allocate buffer to post */ |
| 1327 | mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); |
| 1328 | if (mp1) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1329 | mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys); |
| 1330 | if (!mp1 || !mp1->virt) { |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 1331 | kfree(mp1); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1332 | lpfc_sli_release_iocbq(phba, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1333 | pring->missbufcnt = cnt; |
| 1334 | return cnt; |
| 1335 | } |
| 1336 | |
| 1337 | INIT_LIST_HEAD(&mp1->list); |
| 1338 | /* Allocate buffer to post */ |
| 1339 | if (cnt > 1) { |
| 1340 | mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); |
| 1341 | if (mp2) |
| 1342 | mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI, |
| 1343 | &mp2->phys); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1344 | if (!mp2 || !mp2->virt) { |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 1345 | kfree(mp2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1346 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); |
| 1347 | kfree(mp1); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1348 | lpfc_sli_release_iocbq(phba, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1349 | pring->missbufcnt = cnt; |
| 1350 | return cnt; |
| 1351 | } |
| 1352 | |
| 1353 | INIT_LIST_HEAD(&mp2->list); |
| 1354 | } else { |
| 1355 | mp2 = NULL; |
| 1356 | } |
| 1357 | |
| 1358 | icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys); |
| 1359 | icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys); |
| 1360 | icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE; |
| 1361 | icmd->ulpBdeCount = 1; |
| 1362 | cnt--; |
| 1363 | if (mp2) { |
| 1364 | icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys); |
| 1365 | icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys); |
| 1366 | icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE; |
| 1367 | cnt--; |
| 1368 | icmd->ulpBdeCount = 2; |
| 1369 | } |
| 1370 | |
| 1371 | icmd->ulpCommand = CMD_QUE_RING_BUF64_CN; |
| 1372 | icmd->ulpLe = 1; |
| 1373 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1374 | if (lpfc_sli_issue_iocb(phba, pring, iocb, 0) == IOCB_ERROR) { |
| 1375 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); |
| 1376 | kfree(mp1); |
| 1377 | cnt++; |
| 1378 | if (mp2) { |
| 1379 | lpfc_mbuf_free(phba, mp2->virt, mp2->phys); |
| 1380 | kfree(mp2); |
| 1381 | cnt++; |
| 1382 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1383 | lpfc_sli_release_iocbq(phba, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1384 | pring->missbufcnt = cnt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1385 | return cnt; |
| 1386 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1387 | lpfc_sli_ringpostbuf_put(phba, pring, mp1); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1388 | if (mp2) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1389 | lpfc_sli_ringpostbuf_put(phba, pring, mp2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1390 | } |
| 1391 | pring->missbufcnt = 0; |
| 1392 | return 0; |
| 1393 | } |
| 1394 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1395 | /** |
| 1396 | * lpfc_post_rcv_buf: Post the initial receive IOCB buffers to ELS ring. |
| 1397 | * @phba: pointer to lpfc hba data structure. |
| 1398 | * |
| 1399 | * This routine posts initial receive IOCB buffers to the ELS ring. The |
| 1400 | * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is |
| 1401 | * set to 64 IOCBs. |
| 1402 | * |
| 1403 | * Return codes |
| 1404 | * 0 - success (currently always success) |
| 1405 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1406 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1407 | lpfc_post_rcv_buf(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1408 | { |
| 1409 | struct lpfc_sli *psli = &phba->sli; |
| 1410 | |
| 1411 | /* Ring 0, ELS / CT buffers */ |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 1412 | lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1413 | /* Ring 2 - FCP no buffers needed */ |
| 1414 | |
| 1415 | return 0; |
| 1416 | } |
| 1417 | |
| 1418 | #define S(N,V) (((V)<<(N))|((V)>>(32-(N)))) |
| 1419 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1420 | /** |
| 1421 | * lpfc_sha_init: Set up initial array of hash table entries. |
| 1422 | * @HashResultPointer: pointer to an array as hash table. |
| 1423 | * |
| 1424 | * This routine sets up the initial values to the array of hash table entries |
| 1425 | * for the LC HBAs. |
| 1426 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1427 | static void |
| 1428 | lpfc_sha_init(uint32_t * HashResultPointer) |
| 1429 | { |
| 1430 | HashResultPointer[0] = 0x67452301; |
| 1431 | HashResultPointer[1] = 0xEFCDAB89; |
| 1432 | HashResultPointer[2] = 0x98BADCFE; |
| 1433 | HashResultPointer[3] = 0x10325476; |
| 1434 | HashResultPointer[4] = 0xC3D2E1F0; |
| 1435 | } |
| 1436 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1437 | /** |
| 1438 | * lpfc_sha_iterate: Iterate initial hash table with the working hash table. |
| 1439 | * @HashResultPointer: pointer to an initial/result hash table. |
| 1440 | * @HashWorkingPointer: pointer to an working hash table. |
| 1441 | * |
| 1442 | * This routine iterates an initial hash table pointed by @HashResultPointer |
| 1443 | * with the values from the working hash table pointeed by @HashWorkingPointer. |
| 1444 | * The results are putting back to the initial hash table, returned through |
| 1445 | * the @HashResultPointer as the result hash table. |
| 1446 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1447 | static void |
| 1448 | lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer) |
| 1449 | { |
| 1450 | int t; |
| 1451 | uint32_t TEMP; |
| 1452 | uint32_t A, B, C, D, E; |
| 1453 | t = 16; |
| 1454 | do { |
| 1455 | HashWorkingPointer[t] = |
| 1456 | S(1, |
| 1457 | HashWorkingPointer[t - 3] ^ HashWorkingPointer[t - |
| 1458 | 8] ^ |
| 1459 | HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]); |
| 1460 | } while (++t <= 79); |
| 1461 | t = 0; |
| 1462 | A = HashResultPointer[0]; |
| 1463 | B = HashResultPointer[1]; |
| 1464 | C = HashResultPointer[2]; |
| 1465 | D = HashResultPointer[3]; |
| 1466 | E = HashResultPointer[4]; |
| 1467 | |
| 1468 | do { |
| 1469 | if (t < 20) { |
| 1470 | TEMP = ((B & C) | ((~B) & D)) + 0x5A827999; |
| 1471 | } else if (t < 40) { |
| 1472 | TEMP = (B ^ C ^ D) + 0x6ED9EBA1; |
| 1473 | } else if (t < 60) { |
| 1474 | TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC; |
| 1475 | } else { |
| 1476 | TEMP = (B ^ C ^ D) + 0xCA62C1D6; |
| 1477 | } |
| 1478 | TEMP += S(5, A) + E + HashWorkingPointer[t]; |
| 1479 | E = D; |
| 1480 | D = C; |
| 1481 | C = S(30, B); |
| 1482 | B = A; |
| 1483 | A = TEMP; |
| 1484 | } while (++t <= 79); |
| 1485 | |
| 1486 | HashResultPointer[0] += A; |
| 1487 | HashResultPointer[1] += B; |
| 1488 | HashResultPointer[2] += C; |
| 1489 | HashResultPointer[3] += D; |
| 1490 | HashResultPointer[4] += E; |
| 1491 | |
| 1492 | } |
| 1493 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1494 | /** |
| 1495 | * lpfc_challenge_key: Create challenge key based on WWPN of the HBA. |
| 1496 | * @RandomChallenge: pointer to the entry of host challenge random number array. |
| 1497 | * @HashWorking: pointer to the entry of the working hash array. |
| 1498 | * |
| 1499 | * This routine calculates the working hash array referred by @HashWorking |
| 1500 | * from the challenge random numbers associated with the host, referred by |
| 1501 | * @RandomChallenge. The result is put into the entry of the working hash |
| 1502 | * array and returned by reference through @HashWorking. |
| 1503 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1504 | static void |
| 1505 | lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking) |
| 1506 | { |
| 1507 | *HashWorking = (*RandomChallenge ^ *HashWorking); |
| 1508 | } |
| 1509 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1510 | /** |
| 1511 | * lpfc_hba_init: Perform special handling for LC HBA initialization. |
| 1512 | * @phba: pointer to lpfc hba data structure. |
| 1513 | * @hbainit: pointer to an array of unsigned 32-bit integers. |
| 1514 | * |
| 1515 | * This routine performs the special handling for LC HBA initialization. |
| 1516 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1517 | void |
| 1518 | lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit) |
| 1519 | { |
| 1520 | int t; |
| 1521 | uint32_t *HashWorking; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1522 | uint32_t *pwwnn = (uint32_t *) phba->wwnn; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1523 | |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 1524 | HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1525 | if (!HashWorking) |
| 1526 | return; |
| 1527 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1528 | HashWorking[0] = HashWorking[78] = *pwwnn++; |
| 1529 | HashWorking[1] = HashWorking[79] = *pwwnn; |
| 1530 | |
| 1531 | for (t = 0; t < 7; t++) |
| 1532 | lpfc_challenge_key(phba->RandomData + t, HashWorking + t); |
| 1533 | |
| 1534 | lpfc_sha_init(hbainit); |
| 1535 | lpfc_sha_iterate(hbainit, HashWorking); |
| 1536 | kfree(HashWorking); |
| 1537 | } |
| 1538 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1539 | /** |
| 1540 | * lpfc_cleanup: Performs vport cleanups before deleting a vport. |
| 1541 | * @vport: pointer to a virtual N_Port data structure. |
| 1542 | * |
| 1543 | * This routine performs the necessary cleanups before deleting the @vport. |
| 1544 | * It invokes the discovery state machine to perform necessary state |
| 1545 | * transitions and to release the ndlps associated with the @vport. Note, |
| 1546 | * the physical port is treated as @vport 0. |
| 1547 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1548 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1549 | lpfc_cleanup(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1550 | { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1551 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1552 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1553 | int i = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1554 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1555 | if (phba->link_state > LPFC_LINK_DOWN) |
| 1556 | lpfc_port_link_failure(vport); |
| 1557 | |
| 1558 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1559 | if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 1560 | ndlp = lpfc_enable_node(vport, ndlp, |
| 1561 | NLP_STE_UNUSED_NODE); |
| 1562 | if (!ndlp) |
| 1563 | continue; |
| 1564 | spin_lock_irq(&phba->ndlp_lock); |
| 1565 | NLP_SET_FREE_REQ(ndlp); |
| 1566 | spin_unlock_irq(&phba->ndlp_lock); |
| 1567 | /* Trigger the release of the ndlp memory */ |
| 1568 | lpfc_nlp_put(ndlp); |
| 1569 | continue; |
| 1570 | } |
| 1571 | spin_lock_irq(&phba->ndlp_lock); |
| 1572 | if (NLP_CHK_FREE_REQ(ndlp)) { |
| 1573 | /* The ndlp should not be in memory free mode already */ |
| 1574 | spin_unlock_irq(&phba->ndlp_lock); |
| 1575 | continue; |
| 1576 | } else |
| 1577 | /* Indicate request for freeing ndlp memory */ |
| 1578 | NLP_SET_FREE_REQ(ndlp); |
| 1579 | spin_unlock_irq(&phba->ndlp_lock); |
| 1580 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1581 | if (vport->port_type != LPFC_PHYSICAL_PORT && |
| 1582 | ndlp->nlp_DID == Fabric_DID) { |
| 1583 | /* Just free up ndlp with Fabric_DID for vports */ |
| 1584 | lpfc_nlp_put(ndlp); |
| 1585 | continue; |
| 1586 | } |
| 1587 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1588 | if (ndlp->nlp_type & NLP_FABRIC) |
| 1589 | lpfc_disc_state_machine(vport, ndlp, NULL, |
| 1590 | NLP_EVT_DEVICE_RECOVERY); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1591 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1592 | lpfc_disc_state_machine(vport, ndlp, NULL, |
| 1593 | NLP_EVT_DEVICE_RM); |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 1594 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1595 | } |
| 1596 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1597 | /* At this point, ALL ndlp's should be gone |
| 1598 | * because of the previous NLP_EVT_DEVICE_RM. |
| 1599 | * Lets wait for this to happen, if needed. |
| 1600 | */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1601 | while (!list_empty(&vport->fc_nodes)) { |
| 1602 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1603 | if (i++ > 3000) { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1604 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1605 | "0233 Nodelist not empty\n"); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1606 | list_for_each_entry_safe(ndlp, next_ndlp, |
| 1607 | &vport->fc_nodes, nlp_listp) { |
| 1608 | lpfc_printf_vlog(ndlp->vport, KERN_ERR, |
| 1609 | LOG_NODE, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1610 | "0282 did:x%x ndlp:x%p " |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1611 | "usgmap:x%x refcnt:%d\n", |
| 1612 | ndlp->nlp_DID, (void *)ndlp, |
| 1613 | ndlp->nlp_usg_map, |
| 1614 | atomic_read( |
| 1615 | &ndlp->kref.refcount)); |
| 1616 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1617 | break; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1618 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1619 | |
| 1620 | /* Wait for any activity on ndlps to settle */ |
| 1621 | msleep(10); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1622 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1623 | return; |
| 1624 | } |
| 1625 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1626 | /** |
| 1627 | * lpfc_stop_vport_timers: Stop all the timers associated with a vport. |
| 1628 | * @vport: pointer to a virtual N_Port data structure. |
| 1629 | * |
| 1630 | * This routine stops all the timers associated with a @vport. This function |
| 1631 | * is invoked before disabling or deleting a @vport. Note that the physical |
| 1632 | * port is treated as @vport 0. |
| 1633 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1634 | void |
| 1635 | lpfc_stop_vport_timers(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1636 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1637 | del_timer_sync(&vport->els_tmofunc); |
| 1638 | del_timer_sync(&vport->fc_fdmitmo); |
| 1639 | lpfc_can_disctmo(vport); |
| 1640 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1641 | } |
| 1642 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1643 | /** |
| 1644 | * lpfc_stop_phba_timers: Stop all the timers associated with an HBA. |
| 1645 | * @phba: pointer to lpfc hba data structure. |
| 1646 | * |
| 1647 | * This routine stops all the timers associated with a HBA. This function is |
| 1648 | * invoked before either putting a HBA offline or unloading the driver. |
| 1649 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1650 | static void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1651 | lpfc_stop_phba_timers(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1652 | { |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1653 | del_timer_sync(&phba->fcp_poll_timer); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1654 | lpfc_stop_vport_timers(phba->pport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1655 | del_timer_sync(&phba->sli.mbox_tmo); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1656 | del_timer_sync(&phba->fabric_block_timer); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1657 | phba->hb_outstanding = 0; |
| 1658 | del_timer_sync(&phba->hb_tmofunc); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1659 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1660 | } |
| 1661 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1662 | /** |
| 1663 | * lpfc_block_mgmt_io: Mark a HBA's management interface as blocked. |
| 1664 | * @phba: pointer to lpfc hba data structure. |
| 1665 | * |
| 1666 | * This routine marks a HBA's management interface as blocked. Once the HBA's |
| 1667 | * management interface is marked as blocked, all the user space access to |
| 1668 | * the HBA, whether they are from sysfs interface or libdfc interface will |
| 1669 | * all be blocked. The HBA is set to block the management interface when the |
| 1670 | * driver prepares the HBA interface for online or offline. |
| 1671 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1672 | static void |
| 1673 | lpfc_block_mgmt_io(struct lpfc_hba * phba) |
| 1674 | { |
| 1675 | unsigned long iflag; |
| 1676 | |
| 1677 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 1678 | phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO; |
| 1679 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 1680 | } |
| 1681 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1682 | /** |
| 1683 | * lpfc_online: Initialize and bring a HBA online. |
| 1684 | * @phba: pointer to lpfc hba data structure. |
| 1685 | * |
| 1686 | * This routine initializes the HBA and brings a HBA online. During this |
| 1687 | * process, the management interface is blocked to prevent user space access |
| 1688 | * to the HBA interfering with the driver initialization. |
| 1689 | * |
| 1690 | * Return codes |
| 1691 | * 0 - successful |
| 1692 | * 1 - failed |
| 1693 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1694 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1695 | lpfc_online(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1696 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1697 | struct lpfc_vport *vport = phba->pport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1698 | struct lpfc_vport **vports; |
| 1699 | int i; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1700 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1701 | if (!phba) |
| 1702 | return 0; |
| 1703 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1704 | if (!(vport->fc_flag & FC_OFFLINE_MODE)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1705 | return 0; |
| 1706 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1707 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1708 | "0458 Bring Adapter online\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1709 | |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1710 | lpfc_block_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1711 | |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1712 | if (!lpfc_sli_queue_setup(phba)) { |
| 1713 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1714 | return 1; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1715 | } |
| 1716 | |
| 1717 | if (lpfc_sli_hba_setup(phba)) { /* Initialize the HBA */ |
| 1718 | lpfc_unblock_mgmt_io(phba); |
| 1719 | return 1; |
| 1720 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1721 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1722 | vports = lpfc_create_vport_work_array(phba); |
| 1723 | if (vports != NULL) |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1724 | for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1725 | struct Scsi_Host *shost; |
| 1726 | shost = lpfc_shost_from_vport(vports[i]); |
| 1727 | spin_lock_irq(shost->host_lock); |
| 1728 | vports[i]->fc_flag &= ~FC_OFFLINE_MODE; |
| 1729 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) |
| 1730 | vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
| 1731 | spin_unlock_irq(shost->host_lock); |
| 1732 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1733 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1734 | |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1735 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1736 | return 0; |
| 1737 | } |
| 1738 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1739 | /** |
| 1740 | * lpfc_unblock_mgmt_io: Mark a HBA's management interface to be not blocked. |
| 1741 | * @phba: pointer to lpfc hba data structure. |
| 1742 | * |
| 1743 | * This routine marks a HBA's management interface as not blocked. Once the |
| 1744 | * HBA's management interface is marked as not blocked, all the user space |
| 1745 | * access to the HBA, whether they are from sysfs interface or libdfc |
| 1746 | * interface will be allowed. The HBA is set to block the management interface |
| 1747 | * when the driver prepares the HBA interface for online or offline and then |
| 1748 | * set to unblock the management interface afterwards. |
| 1749 | **/ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1750 | void |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1751 | lpfc_unblock_mgmt_io(struct lpfc_hba * phba) |
| 1752 | { |
| 1753 | unsigned long iflag; |
| 1754 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1755 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 1756 | phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO; |
| 1757 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1758 | } |
| 1759 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1760 | /** |
| 1761 | * lpfc_offline_prep: Prepare a HBA to be brought offline. |
| 1762 | * @phba: pointer to lpfc hba data structure. |
| 1763 | * |
| 1764 | * This routine is invoked to prepare a HBA to be brought offline. It performs |
| 1765 | * unregistration login to all the nodes on all vports and flushes the mailbox |
| 1766 | * queue to make it ready to be brought offline. |
| 1767 | **/ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1768 | void |
| 1769 | lpfc_offline_prep(struct lpfc_hba * phba) |
| 1770 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1771 | struct lpfc_vport *vport = phba->pport; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1772 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1773 | struct lpfc_vport **vports; |
| 1774 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1775 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1776 | if (vport->fc_flag & FC_OFFLINE_MODE) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1777 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1778 | |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1779 | lpfc_block_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1780 | |
| 1781 | lpfc_linkdown(phba); |
| 1782 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1783 | /* Issue an unreg_login to all nodes on all vports */ |
| 1784 | vports = lpfc_create_vport_work_array(phba); |
| 1785 | if (vports != NULL) { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1786 | for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1787 | struct Scsi_Host *shost; |
| 1788 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1789 | if (vports[i]->load_flag & FC_UNLOADING) |
| 1790 | continue; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1791 | shost = lpfc_shost_from_vport(vports[i]); |
| 1792 | list_for_each_entry_safe(ndlp, next_ndlp, |
| 1793 | &vports[i]->fc_nodes, |
| 1794 | nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1795 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 1796 | continue; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1797 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
| 1798 | continue; |
| 1799 | if (ndlp->nlp_type & NLP_FABRIC) { |
| 1800 | lpfc_disc_state_machine(vports[i], ndlp, |
| 1801 | NULL, NLP_EVT_DEVICE_RECOVERY); |
| 1802 | lpfc_disc_state_machine(vports[i], ndlp, |
| 1803 | NULL, NLP_EVT_DEVICE_RM); |
| 1804 | } |
| 1805 | spin_lock_irq(shost->host_lock); |
| 1806 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
| 1807 | spin_unlock_irq(shost->host_lock); |
| 1808 | lpfc_unreg_rpi(vports[i], ndlp); |
| 1809 | } |
| 1810 | } |
| 1811 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1812 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1813 | |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1814 | lpfc_sli_flush_mbox_queue(phba); |
| 1815 | } |
| 1816 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1817 | /** |
| 1818 | * lpfc_offline: Bring a HBA offline. |
| 1819 | * @phba: pointer to lpfc hba data structure. |
| 1820 | * |
| 1821 | * This routine actually brings a HBA offline. It stops all the timers |
| 1822 | * associated with the HBA, brings down the SLI layer, and eventually |
| 1823 | * marks the HBA as in offline state for the upper layer protocol. |
| 1824 | **/ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1825 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1826 | lpfc_offline(struct lpfc_hba *phba) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1827 | { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1828 | struct Scsi_Host *shost; |
| 1829 | struct lpfc_vport **vports; |
| 1830 | int i; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1831 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1832 | if (phba->pport->fc_flag & FC_OFFLINE_MODE) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1833 | return; |
James Smart | 688a886 | 2006-07-06 15:49:56 -0400 | [diff] [blame] | 1834 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1835 | /* stop all timers associated with this hba */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1836 | lpfc_stop_phba_timers(phba); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1837 | vports = lpfc_create_vport_work_array(phba); |
| 1838 | if (vports != NULL) |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1839 | for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1840 | lpfc_stop_vport_timers(vports[i]); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1841 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1842 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1843 | "0460 Bring Adapter offline\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1844 | /* Bring down the SLI Layer and cleanup. The HBA is offline |
| 1845 | now. */ |
| 1846 | lpfc_sli_hba_down(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1847 | spin_lock_irq(&phba->hbalock); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1848 | phba->work_ha = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1849 | spin_unlock_irq(&phba->hbalock); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1850 | vports = lpfc_create_vport_work_array(phba); |
| 1851 | if (vports != NULL) |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1852 | for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1853 | shost = lpfc_shost_from_vport(vports[i]); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1854 | spin_lock_irq(shost->host_lock); |
| 1855 | vports[i]->work_port_events = 0; |
| 1856 | vports[i]->fc_flag |= FC_OFFLINE_MODE; |
| 1857 | spin_unlock_irq(shost->host_lock); |
| 1858 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1859 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1860 | } |
| 1861 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1862 | /** |
| 1863 | * lpfc_scsi_free: Free all the SCSI buffers and IOCBs from driver lists. |
| 1864 | * @phba: pointer to lpfc hba data structure. |
| 1865 | * |
| 1866 | * This routine is to free all the SCSI buffers and IOCBs from the driver |
| 1867 | * list back to kernel. It is called from lpfc_pci_remove_one to free |
| 1868 | * the internal resources before the device is removed from the system. |
| 1869 | * |
| 1870 | * Return codes |
| 1871 | * 0 - successful (for now, it always returns 0) |
| 1872 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1873 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1874 | lpfc_scsi_free(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1875 | { |
| 1876 | struct lpfc_scsi_buf *sb, *sb_next; |
| 1877 | struct lpfc_iocbq *io, *io_next; |
| 1878 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1879 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1880 | /* Release all the lpfc_scsi_bufs maintained by this host. */ |
| 1881 | list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list, list) { |
| 1882 | list_del(&sb->list); |
| 1883 | pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1884 | sb->dma_handle); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1885 | kfree(sb); |
| 1886 | phba->total_scsi_bufs--; |
| 1887 | } |
| 1888 | |
| 1889 | /* Release all the lpfc_iocbq entries maintained by this host. */ |
| 1890 | list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) { |
| 1891 | list_del(&io->list); |
| 1892 | kfree(io); |
| 1893 | phba->total_iocbq_bufs--; |
| 1894 | } |
| 1895 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1896 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1897 | |
| 1898 | return 0; |
| 1899 | } |
| 1900 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1901 | /** |
| 1902 | * lpfc_create_port: Create an FC port. |
| 1903 | * @phba: pointer to lpfc hba data structure. |
| 1904 | * @instance: a unique integer ID to this FC port. |
| 1905 | * @dev: pointer to the device data structure. |
| 1906 | * |
| 1907 | * This routine creates a FC port for the upper layer protocol. The FC port |
| 1908 | * can be created on top of either a physical port or a virtual port provided |
| 1909 | * by the HBA. This routine also allocates a SCSI host data structure (shost) |
| 1910 | * and associates the FC port created before adding the shost into the SCSI |
| 1911 | * layer. |
| 1912 | * |
| 1913 | * Return codes |
| 1914 | * @vport - pointer to the virtual N_Port data structure. |
| 1915 | * NULL - port create failed. |
| 1916 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1917 | struct lpfc_vport * |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1918 | lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev) |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1919 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1920 | struct lpfc_vport *vport; |
| 1921 | struct Scsi_Host *shost; |
| 1922 | int error = 0; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1923 | |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1924 | if (dev != &phba->pcidev->dev) |
| 1925 | shost = scsi_host_alloc(&lpfc_vport_template, |
| 1926 | sizeof(struct lpfc_vport)); |
| 1927 | else |
| 1928 | shost = scsi_host_alloc(&lpfc_template, |
| 1929 | sizeof(struct lpfc_vport)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1930 | if (!shost) |
| 1931 | goto out; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1932 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1933 | vport = (struct lpfc_vport *) shost->hostdata; |
| 1934 | vport->phba = phba; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1935 | vport->load_flag |= FC_LOADING; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1936 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 1937 | vport->fc_rscn_flush = 0; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1938 | |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1939 | lpfc_get_vport_cfgparam(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1940 | shost->unique_id = instance; |
| 1941 | shost->max_id = LPFC_MAX_TARGET; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1942 | shost->max_lun = vport->cfg_max_luns; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1943 | shost->this_id = -1; |
| 1944 | shost->max_cmd_len = 16; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1945 | /* |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1946 | * Set initial can_queue value since 0 is no longer supported and |
| 1947 | * scsi_add_host will fail. This will be adjusted later based on the |
| 1948 | * max xri value determined in hba setup. |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1949 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1950 | shost->can_queue = phba->cfg_hba_queue_depth - 10; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1951 | if (dev != &phba->pcidev->dev) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1952 | shost->transportt = lpfc_vport_transport_template; |
| 1953 | vport->port_type = LPFC_NPIV_PORT; |
| 1954 | } else { |
| 1955 | shost->transportt = lpfc_transport_template; |
| 1956 | vport->port_type = LPFC_PHYSICAL_PORT; |
| 1957 | } |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1958 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1959 | /* Initialize all internally managed lists. */ |
| 1960 | INIT_LIST_HEAD(&vport->fc_nodes); |
| 1961 | spin_lock_init(&vport->work_port_lock); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1962 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1963 | init_timer(&vport->fc_disctmo); |
| 1964 | vport->fc_disctmo.function = lpfc_disc_timeout; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1965 | vport->fc_disctmo.data = (unsigned long)vport; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1966 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1967 | init_timer(&vport->fc_fdmitmo); |
| 1968 | vport->fc_fdmitmo.function = lpfc_fdmi_tmo; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1969 | vport->fc_fdmitmo.data = (unsigned long)vport; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1970 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1971 | init_timer(&vport->els_tmofunc); |
| 1972 | vport->els_tmofunc.function = lpfc_els_timeout; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1973 | vport->els_tmofunc.data = (unsigned long)vport; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1974 | |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1975 | error = scsi_add_host(shost, dev); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1976 | if (error) |
| 1977 | goto out_put_shost; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1978 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1979 | spin_lock_irq(&phba->hbalock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1980 | list_add_tail(&vport->listentry, &phba->port_list); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1981 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1982 | return vport; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1983 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1984 | out_put_shost: |
| 1985 | scsi_host_put(shost); |
| 1986 | out: |
| 1987 | return NULL; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1988 | } |
| 1989 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1990 | /** |
| 1991 | * destroy_port: Destroy an FC port. |
| 1992 | * @vport: pointer to an lpfc virtual N_Port data structure. |
| 1993 | * |
| 1994 | * This routine destroys a FC port from the upper layer protocol. All the |
| 1995 | * resources associated with the port are released. |
| 1996 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1997 | void |
| 1998 | destroy_port(struct lpfc_vport *vport) |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1999 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2000 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2001 | struct lpfc_hba *phba = vport->phba; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2002 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2003 | kfree(vport->vname); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2004 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2005 | lpfc_debugfs_terminate(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2006 | fc_remove_host(shost); |
| 2007 | scsi_remove_host(shost); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2008 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2009 | spin_lock_irq(&phba->hbalock); |
| 2010 | list_del_init(&vport->listentry); |
| 2011 | spin_unlock_irq(&phba->hbalock); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2012 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2013 | lpfc_cleanup(vport); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2014 | return; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2015 | } |
| 2016 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2017 | /** |
| 2018 | * lpfc_get_instance: Get a unique integer ID. |
| 2019 | * |
| 2020 | * This routine allocates a unique integer ID from lpfc_hba_index pool. It |
| 2021 | * uses the kernel idr facility to perform the task. |
| 2022 | * |
| 2023 | * Return codes: |
| 2024 | * instance - a unique integer ID allocated as the new instance. |
| 2025 | * -1 - lpfc get instance failed. |
| 2026 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2027 | int |
| 2028 | lpfc_get_instance(void) |
| 2029 | { |
| 2030 | int instance = 0; |
| 2031 | |
| 2032 | /* Assign an unused number */ |
| 2033 | if (!idr_pre_get(&lpfc_hba_index, GFP_KERNEL)) |
| 2034 | return -1; |
| 2035 | if (idr_get_new(&lpfc_hba_index, NULL, &instance)) |
| 2036 | return -1; |
| 2037 | return instance; |
| 2038 | } |
| 2039 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2040 | /** |
| 2041 | * lpfc_scan_finished: method for SCSI layer to detect whether scan is done. |
| 2042 | * @shost: pointer to SCSI host data structure. |
| 2043 | * @time: elapsed time of the scan in jiffies. |
| 2044 | * |
| 2045 | * This routine is called by the SCSI layer with a SCSI host to determine |
| 2046 | * whether the scan host is finished. |
| 2047 | * |
| 2048 | * Note: there is no scan_start function as adapter initialization will have |
| 2049 | * asynchronously kicked off the link initialization. |
| 2050 | * |
| 2051 | * Return codes |
| 2052 | * 0 - SCSI host scan is not over yet. |
| 2053 | * 1 - SCSI host scan is over. |
| 2054 | **/ |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2055 | int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time) |
| 2056 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2057 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 2058 | struct lpfc_hba *phba = vport->phba; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2059 | int stat = 0; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2060 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2061 | spin_lock_irq(shost->host_lock); |
| 2062 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2063 | if (vport->load_flag & FC_UNLOADING) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2064 | stat = 1; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2065 | goto finished; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2066 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2067 | if (time >= 30 * HZ) { |
| 2068 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2069 | "0461 Scanning longer than 30 " |
| 2070 | "seconds. Continuing initialization\n"); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2071 | stat = 1; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2072 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2073 | } |
| 2074 | if (time >= 15 * HZ && phba->link_state <= LPFC_LINK_DOWN) { |
| 2075 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2076 | "0465 Link down longer than 15 " |
| 2077 | "seconds. Continuing initialization\n"); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2078 | stat = 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2079 | goto finished; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2080 | } |
| 2081 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2082 | if (vport->port_state != LPFC_VPORT_READY) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2083 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2084 | if (vport->num_disc_nodes || vport->fc_prli_sent) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2085 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2086 | if (vport->fc_map_cnt == 0 && time < 2 * HZ) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2087 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2088 | if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2089 | goto finished; |
| 2090 | |
| 2091 | stat = 1; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2092 | |
| 2093 | finished: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2094 | spin_unlock_irq(shost->host_lock); |
| 2095 | return stat; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2096 | } |
| 2097 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2098 | /** |
| 2099 | * lpfc_host_attrib_init: Initialize SCSI host attributes on a FC port. |
| 2100 | * @shost: pointer to SCSI host data structure. |
| 2101 | * |
| 2102 | * This routine initializes a given SCSI host attributes on a FC port. The |
| 2103 | * SCSI host can be either on top of a physical port or a virtual port. |
| 2104 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2105 | void lpfc_host_attrib_init(struct Scsi_Host *shost) |
| 2106 | { |
| 2107 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 2108 | struct lpfc_hba *phba = vport->phba; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2109 | /* |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2110 | * Set fixed host attributes. Must done after lpfc_sli_hba_setup(). |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2111 | */ |
| 2112 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2113 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
| 2114 | 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] | 2115 | fc_host_supported_classes(shost) = FC_COS_CLASS3; |
| 2116 | |
| 2117 | memset(fc_host_supported_fc4s(shost), 0, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2118 | sizeof(fc_host_supported_fc4s(shost))); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2119 | fc_host_supported_fc4s(shost)[2] = 1; |
| 2120 | fc_host_supported_fc4s(shost)[7] = 1; |
| 2121 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2122 | lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost), |
| 2123 | sizeof fc_host_symbolic_name(shost)); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2124 | |
| 2125 | fc_host_supported_speeds(shost) = 0; |
| 2126 | if (phba->lmt & LMT_10Gb) |
| 2127 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2128 | if (phba->lmt & LMT_8Gb) |
| 2129 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2130 | if (phba->lmt & LMT_4Gb) |
| 2131 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT; |
| 2132 | if (phba->lmt & LMT_2Gb) |
| 2133 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT; |
| 2134 | if (phba->lmt & LMT_1Gb) |
| 2135 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT; |
| 2136 | |
| 2137 | fc_host_maxframe_size(shost) = |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2138 | (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) | |
| 2139 | (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2140 | |
| 2141 | /* This value is also unchanging */ |
| 2142 | memset(fc_host_active_fc4s(shost), 0, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2143 | sizeof(fc_host_active_fc4s(shost))); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2144 | fc_host_active_fc4s(shost)[2] = 1; |
| 2145 | fc_host_active_fc4s(shost)[7] = 1; |
| 2146 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2147 | fc_host_max_npiv_vports(shost) = phba->max_vpi; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2148 | spin_lock_irq(shost->host_lock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2149 | vport->load_flag &= ~FC_LOADING; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2150 | spin_unlock_irq(shost->host_lock); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2151 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2152 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2153 | /** |
| 2154 | * lpfc_enable_msix: Enable MSI-X interrupt mode. |
| 2155 | * @phba: pointer to lpfc hba data structure. |
| 2156 | * |
| 2157 | * This routine is invoked to enable the MSI-X interrupt vectors. The kernel |
| 2158 | * function pci_enable_msix() is called to enable the MSI-X vectors. Note that |
| 2159 | * pci_enable_msix(), once invoked, enables either all or nothing, depending |
| 2160 | * on the current availability of PCI vector resources. The device driver is |
| 2161 | * responsible for calling the individual request_irq() to register each MSI-X |
| 2162 | * vector with a interrupt handler, which is done in this function. Note that |
| 2163 | * later when device is unloading, the driver should always call free_irq() |
| 2164 | * on all MSI-X vectors it has done request_irq() on before calling |
| 2165 | * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device |
| 2166 | * will be left with MSI-X enabled and leaks its vectors. |
| 2167 | * |
| 2168 | * Return codes |
| 2169 | * 0 - sucessful |
| 2170 | * other values - error |
| 2171 | **/ |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 2172 | static int |
| 2173 | lpfc_enable_msix(struct lpfc_hba *phba) |
| 2174 | { |
| 2175 | int error; |
| 2176 | |
| 2177 | phba->msix_entries[0].entry = 0; |
| 2178 | phba->msix_entries[0].vector = 0; |
| 2179 | |
| 2180 | error = pci_enable_msix(phba->pcidev, phba->msix_entries, |
| 2181 | ARRAY_SIZE(phba->msix_entries)); |
| 2182 | if (error) { |
| 2183 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 2184 | "0420 Enable MSI-X failed (%d), continuing " |
| 2185 | "with MSI\n", error); |
| 2186 | pci_disable_msix(phba->pcidev); |
| 2187 | return error; |
| 2188 | } |
| 2189 | |
| 2190 | error = request_irq(phba->msix_entries[0].vector, lpfc_intr_handler, 0, |
| 2191 | LPFC_DRIVER_NAME, phba); |
| 2192 | if (error) { |
| 2193 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 2194 | "0421 MSI-X request_irq failed (%d), " |
| 2195 | "continuing with MSI\n", error); |
| 2196 | pci_disable_msix(phba->pcidev); |
| 2197 | } |
| 2198 | return error; |
| 2199 | } |
| 2200 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2201 | /** |
| 2202 | * lpfc_disable_msix: Disable MSI-X interrupt mode. |
| 2203 | * @phba: pointer to lpfc hba data structure. |
| 2204 | * |
| 2205 | * This routine is invoked to release the MSI-X vectors and then disable the |
| 2206 | * MSI-X interrupt mode. |
| 2207 | **/ |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 2208 | static void |
| 2209 | lpfc_disable_msix(struct lpfc_hba *phba) |
| 2210 | { |
| 2211 | free_irq(phba->msix_entries[0].vector, phba); |
| 2212 | pci_disable_msix(phba->pcidev); |
| 2213 | } |
| 2214 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2215 | /** |
| 2216 | * lpfc_pci_probe_one: lpfc PCI probe func to register device to PCI subsystem. |
| 2217 | * @pdev: pointer to PCI device |
| 2218 | * @pid: pointer to PCI device identifier |
| 2219 | * |
| 2220 | * This routine is to be registered to the kernel's PCI subsystem. When an |
| 2221 | * Emulex HBA is presented in PCI bus, the kernel PCI subsystem looks at |
| 2222 | * PCI device-specific information of the device and driver to see if the |
| 2223 | * driver state that it can support this kind of device. If the match is |
| 2224 | * successful, the driver core invokes this routine. If this routine |
| 2225 | * determines it can claim the HBA, it does all the initialization that it |
| 2226 | * needs to do to handle the HBA properly. |
| 2227 | * |
| 2228 | * Return code |
| 2229 | * 0 - driver can claim the device |
| 2230 | * negative value - driver can not claim the device |
| 2231 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2232 | static int __devinit |
| 2233 | lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid) |
| 2234 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2235 | struct lpfc_vport *vport = NULL; |
| 2236 | struct lpfc_hba *phba; |
| 2237 | struct lpfc_sli *psli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2238 | struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2239 | struct Scsi_Host *shost = NULL; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2240 | void *ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2241 | unsigned long bar0map_len, bar2map_len; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2242 | int error = -ENODEV, retval; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2243 | int i, hbq_count; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2244 | uint16_t iotag; |
Tomohiro Kusumi | 8a4df120 | 2008-01-11 01:53:00 -0500 | [diff] [blame] | 2245 | int bars = pci_select_bars(pdev, IORESOURCE_MEM); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2246 | |
Greg Kroah-Hartman | d5f78fb | 2008-02-02 12:13:22 +0100 | [diff] [blame] | 2247 | if (pci_enable_device_mem(pdev)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2248 | goto out; |
Tomohiro Kusumi | 8a4df120 | 2008-01-11 01:53:00 -0500 | [diff] [blame] | 2249 | if (pci_request_selected_regions(pdev, bars, LPFC_DRIVER_NAME)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2250 | goto out_disable_device; |
| 2251 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2252 | phba = kzalloc(sizeof (struct lpfc_hba), GFP_KERNEL); |
| 2253 | if (!phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2254 | goto out_release_regions; |
| 2255 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2256 | spin_lock_init(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2257 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2258 | /* Initialize ndlp management spinlock */ |
| 2259 | spin_lock_init(&phba->ndlp_lock); |
| 2260 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2261 | phba->pcidev = pdev; |
| 2262 | |
| 2263 | /* Assign an unused board number */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2264 | if ((phba->brd_no = lpfc_get_instance()) < 0) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2265 | goto out_free_phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2266 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2267 | INIT_LIST_HEAD(&phba->port_list); |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2268 | init_waitqueue_head(&phba->wait_4_mlo_m_q); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2269 | /* |
| 2270 | * Get all the module params for configuring this host and then |
| 2271 | * establish the host. |
| 2272 | */ |
| 2273 | lpfc_get_cfgparam(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2274 | phba->max_vpi = LPFC_MAX_VPI; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2275 | |
| 2276 | /* Initialize timers used by driver */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2277 | init_timer(&phba->hb_tmofunc); |
| 2278 | phba->hb_tmofunc.function = lpfc_hb_timeout; |
| 2279 | phba->hb_tmofunc.data = (unsigned long)phba; |
| 2280 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2281 | psli = &phba->sli; |
| 2282 | init_timer(&psli->mbox_tmo); |
| 2283 | psli->mbox_tmo.function = lpfc_mbox_timeout; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2284 | psli->mbox_tmo.data = (unsigned long) phba; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2285 | init_timer(&phba->fcp_poll_timer); |
| 2286 | phba->fcp_poll_timer.function = lpfc_poll_timeout; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2287 | phba->fcp_poll_timer.data = (unsigned long) phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2288 | init_timer(&phba->fabric_block_timer); |
| 2289 | phba->fabric_block_timer.function = lpfc_fabric_block_timeout; |
| 2290 | phba->fabric_block_timer.data = (unsigned long) phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2291 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2292 | pci_set_master(pdev); |
Randy Dunlap | 694625c | 2007-07-09 11:55:54 -0700 | [diff] [blame] | 2293 | pci_try_set_mwi(pdev); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2294 | |
| 2295 | if (pci_set_dma_mask(phba->pcidev, DMA_64BIT_MASK) != 0) |
| 2296 | if (pci_set_dma_mask(phba->pcidev, DMA_32BIT_MASK) != 0) |
| 2297 | goto out_idr_remove; |
| 2298 | |
| 2299 | /* |
| 2300 | * Get the bus address of Bar0 and Bar2 and the number of bytes |
| 2301 | * required by each mapping. |
| 2302 | */ |
| 2303 | phba->pci_bar0_map = pci_resource_start(phba->pcidev, 0); |
| 2304 | bar0map_len = pci_resource_len(phba->pcidev, 0); |
| 2305 | |
| 2306 | phba->pci_bar2_map = pci_resource_start(phba->pcidev, 2); |
| 2307 | bar2map_len = pci_resource_len(phba->pcidev, 2); |
| 2308 | |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 2309 | /* Map HBA SLIM to a kernel virtual address. */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2310 | phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len); |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 2311 | if (!phba->slim_memmap_p) { |
| 2312 | error = -ENODEV; |
| 2313 | dev_printk(KERN_ERR, &pdev->dev, |
| 2314 | "ioremap failed for SLIM memory.\n"); |
| 2315 | goto out_idr_remove; |
| 2316 | } |
| 2317 | |
| 2318 | /* Map HBA Control Registers to a kernel virtual address. */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2319 | phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len); |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 2320 | if (!phba->ctrl_regs_memmap_p) { |
| 2321 | error = -ENODEV; |
| 2322 | dev_printk(KERN_ERR, &pdev->dev, |
| 2323 | "ioremap failed for HBA control registers.\n"); |
| 2324 | goto out_iounmap_slim; |
| 2325 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2326 | |
| 2327 | /* Allocate memory for SLI-2 structures */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2328 | phba->slim2p.virt = dma_alloc_coherent(&phba->pcidev->dev, |
| 2329 | SLI2_SLIM_SIZE, |
| 2330 | &phba->slim2p.phys, |
| 2331 | GFP_KERNEL); |
| 2332 | if (!phba->slim2p.virt) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2333 | goto out_iounmap; |
| 2334 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2335 | memset(phba->slim2p.virt, 0, SLI2_SLIM_SIZE); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2336 | phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx); |
| 2337 | phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb)); |
| 2338 | phba->IOCBs = (phba->slim2p.virt + |
| 2339 | offsetof(struct lpfc_sli2_slim, IOCBs)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2340 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2341 | phba->hbqslimp.virt = dma_alloc_coherent(&phba->pcidev->dev, |
| 2342 | lpfc_sli_hbq_size(), |
| 2343 | &phba->hbqslimp.phys, |
| 2344 | GFP_KERNEL); |
| 2345 | if (!phba->hbqslimp.virt) |
| 2346 | goto out_free_slim; |
| 2347 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2348 | hbq_count = lpfc_sli_hbq_count(); |
| 2349 | ptr = phba->hbqslimp.virt; |
| 2350 | for (i = 0; i < hbq_count; ++i) { |
| 2351 | phba->hbqs[i].hbq_virt = ptr; |
| 2352 | INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list); |
| 2353 | ptr += (lpfc_hbq_defs[i]->entry_count * |
| 2354 | sizeof(struct lpfc_hbq_entry)); |
| 2355 | } |
| 2356 | phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc; |
| 2357 | phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free; |
| 2358 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2359 | memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size()); |
| 2360 | |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2361 | INIT_LIST_HEAD(&phba->hbqbuf_in_list); |
| 2362 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2363 | /* Initialize the SLI Layer to run with lpfc HBAs. */ |
| 2364 | lpfc_sli_setup(phba); |
| 2365 | lpfc_sli_queue_setup(phba); |
| 2366 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2367 | retval = lpfc_mem_alloc(phba); |
| 2368 | if (retval) { |
| 2369 | error = retval; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2370 | goto out_free_hbqslimp; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2371 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2372 | |
| 2373 | /* Initialize and populate the iocb list per host. */ |
| 2374 | INIT_LIST_HEAD(&phba->lpfc_iocb_list); |
| 2375 | for (i = 0; i < LPFC_IOCB_LIST_CNT; i++) { |
Yoann Padioleau | dd00cc4 | 2007-07-19 01:49:03 -0700 | [diff] [blame] | 2376 | iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2377 | if (iocbq_entry == NULL) { |
| 2378 | printk(KERN_ERR "%s: only allocated %d iocbs of " |
| 2379 | "expected %d count. Unloading driver.\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 2380 | __func__, i, LPFC_IOCB_LIST_CNT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2381 | error = -ENOMEM; |
| 2382 | goto out_free_iocbq; |
| 2383 | } |
| 2384 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2385 | iotag = lpfc_sli_next_iotag(phba, iocbq_entry); |
| 2386 | if (iotag == 0) { |
| 2387 | kfree (iocbq_entry); |
| 2388 | printk(KERN_ERR "%s: failed to allocate IOTAG. " |
| 2389 | "Unloading driver.\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 2390 | __func__); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2391 | error = -ENOMEM; |
| 2392 | goto out_free_iocbq; |
| 2393 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2394 | |
| 2395 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2396 | list_add(&iocbq_entry->list, &phba->lpfc_iocb_list); |
| 2397 | phba->total_iocbq_bufs++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2398 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2399 | } |
| 2400 | |
| 2401 | /* Initialize HBA structure */ |
| 2402 | phba->fc_edtov = FF_DEF_EDTOV; |
| 2403 | phba->fc_ratov = FF_DEF_RATOV; |
| 2404 | phba->fc_altov = FF_DEF_ALTOV; |
| 2405 | phba->fc_arbtov = FF_DEF_ARBTOV; |
| 2406 | |
| 2407 | INIT_LIST_HEAD(&phba->work_list); |
| 2408 | phba->work_ha_mask = (HA_ERATT|HA_MBATT|HA_LATT); |
| 2409 | phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4)); |
| 2410 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2411 | /* Initialize the wait queue head for the kernel thread */ |
| 2412 | init_waitqueue_head(&phba->work_waitq); |
| 2413 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2414 | /* Startup the kernel thread for this host adapter. */ |
| 2415 | phba->worker_thread = kthread_run(lpfc_do_work, phba, |
| 2416 | "lpfc_worker_%d", phba->brd_no); |
| 2417 | if (IS_ERR(phba->worker_thread)) { |
| 2418 | error = PTR_ERR(phba->worker_thread); |
| 2419 | goto out_free_iocbq; |
| 2420 | } |
| 2421 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2422 | /* 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] | 2423 | spin_lock_init(&phba->scsi_buf_list_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2424 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list); |
| 2425 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2426 | /* Initialize list of fabric iocbs */ |
| 2427 | INIT_LIST_HEAD(&phba->fabric_iocb_list); |
| 2428 | |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 2429 | /* Initialize list to save ELS buffers */ |
| 2430 | INIT_LIST_HEAD(&phba->elsbuf); |
| 2431 | |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 2432 | vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2433 | if (!vport) |
| 2434 | goto out_kthread_stop; |
| 2435 | |
| 2436 | shost = lpfc_shost_from_vport(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2437 | phba->pport = vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2438 | lpfc_debugfs_initialize(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2439 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2440 | pci_set_drvdata(pdev, shost); |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 2441 | phba->intr_type = NONE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2442 | |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 2443 | if (phba->cfg_use_msi == 2) { |
| 2444 | error = lpfc_enable_msix(phba); |
| 2445 | if (!error) |
| 2446 | phba->intr_type = MSIX; |
| 2447 | } |
| 2448 | |
| 2449 | /* Fallback to MSI if MSI-X initialization failed */ |
| 2450 | if (phba->cfg_use_msi >= 1 && phba->intr_type == NONE) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2451 | retval = pci_enable_msi(phba->pcidev); |
| 2452 | if (!retval) |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 2453 | phba->intr_type = MSI; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2454 | else |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2455 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 2456 | "0452 Enable MSI failed, continuing " |
| 2457 | "with IRQ\n"); |
James Smart | 4ff4324 | 2006-12-02 13:34:56 -0500 | [diff] [blame] | 2458 | } |
| 2459 | |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 2460 | /* MSI-X is the only case the doesn't need to call request_irq */ |
| 2461 | if (phba->intr_type != MSIX) { |
| 2462 | retval = request_irq(phba->pcidev->irq, lpfc_intr_handler, |
| 2463 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); |
| 2464 | if (retval) { |
| 2465 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, "0451 Enable " |
| 2466 | "interrupt handler failed\n"); |
| 2467 | error = retval; |
| 2468 | goto out_disable_msi; |
| 2469 | } else if (phba->intr_type != MSI) |
| 2470 | phba->intr_type = INTx; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2471 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2472 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2473 | phba->MBslimaddr = phba->slim_memmap_p; |
| 2474 | phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET; |
| 2475 | phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET; |
| 2476 | phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET; |
| 2477 | phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET; |
| 2478 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2479 | if (lpfc_alloc_sysfs_attr(vport)) { |
| 2480 | error = -ENOMEM; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2481 | goto out_free_irq; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2482 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2483 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2484 | if (lpfc_sli_hba_setup(phba)) { |
| 2485 | error = -ENODEV; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2486 | goto out_remove_device; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2487 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2488 | |
| 2489 | /* |
| 2490 | * hba setup may have changed the hba_queue_depth so we need to adjust |
| 2491 | * the value of can_queue. |
| 2492 | */ |
| 2493 | shost->can_queue = phba->cfg_hba_queue_depth - 10; |
| 2494 | |
| 2495 | lpfc_host_attrib_init(shost); |
| 2496 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2497 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
| 2498 | spin_lock_irq(shost->host_lock); |
| 2499 | lpfc_poll_start_timer(phba); |
| 2500 | spin_unlock_irq(shost->host_lock); |
| 2501 | } |
James Smart | 8f6d98d | 2006-08-01 07:34:00 -0400 | [diff] [blame] | 2502 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2503 | scsi_scan_host(shost); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2504 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2505 | return 0; |
| 2506 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2507 | out_remove_device: |
| 2508 | lpfc_free_sysfs_attr(vport); |
| 2509 | spin_lock_irq(shost->host_lock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2510 | vport->load_flag |= FC_UNLOADING; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2511 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2512 | out_free_irq: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2513 | lpfc_stop_phba_timers(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2514 | phba->pport->work_port_events = 0; |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 2515 | |
| 2516 | if (phba->intr_type == MSIX) |
| 2517 | lpfc_disable_msix(phba); |
| 2518 | else |
| 2519 | free_irq(phba->pcidev->irq, phba); |
| 2520 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2521 | out_disable_msi: |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 2522 | if (phba->intr_type == MSI) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2523 | pci_disable_msi(phba->pcidev); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2524 | destroy_port(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2525 | out_kthread_stop: |
| 2526 | kthread_stop(phba->worker_thread); |
| 2527 | out_free_iocbq: |
| 2528 | list_for_each_entry_safe(iocbq_entry, iocbq_next, |
| 2529 | &phba->lpfc_iocb_list, list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2530 | kfree(iocbq_entry); |
| 2531 | phba->total_iocbq_bufs--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2532 | } |
| 2533 | lpfc_mem_free(phba); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2534 | out_free_hbqslimp: |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2535 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), |
| 2536 | phba->hbqslimp.virt, phba->hbqslimp.phys); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2537 | out_free_slim: |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2538 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
| 2539 | phba->slim2p.virt, phba->slim2p.phys); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2540 | out_iounmap: |
| 2541 | iounmap(phba->ctrl_regs_memmap_p); |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 2542 | out_iounmap_slim: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2543 | iounmap(phba->slim_memmap_p); |
| 2544 | out_idr_remove: |
| 2545 | idr_remove(&lpfc_hba_index, phba->brd_no); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2546 | out_free_phba: |
| 2547 | kfree(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2548 | out_release_regions: |
Tomohiro Kusumi | 8a4df120 | 2008-01-11 01:53:00 -0500 | [diff] [blame] | 2549 | pci_release_selected_regions(pdev, bars); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2550 | out_disable_device: |
| 2551 | pci_disable_device(pdev); |
| 2552 | out: |
James Smart | defbcf1 | 2006-04-16 22:26:50 -0400 | [diff] [blame] | 2553 | pci_set_drvdata(pdev, NULL); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2554 | if (shost) |
| 2555 | scsi_host_put(shost); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2556 | return error; |
| 2557 | } |
| 2558 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2559 | /** |
| 2560 | * lpfc_pci_remove_one: lpfc PCI func to unregister device from PCI subsystem. |
| 2561 | * @pdev: pointer to PCI device |
| 2562 | * |
| 2563 | * This routine is to be registered to the kernel's PCI subsystem. When an |
| 2564 | * Emulex HBA is removed from PCI bus. It perform all the necessary cleanup |
| 2565 | * for the HBA device to be removed from the PCI subsystem properly. |
| 2566 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2567 | static void __devexit |
| 2568 | lpfc_pci_remove_one(struct pci_dev *pdev) |
| 2569 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2570 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 2571 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 2572 | struct lpfc_hba *phba = vport->phba; |
Tomohiro Kusumi | 8a4df120 | 2008-01-11 01:53:00 -0500 | [diff] [blame] | 2573 | int bars = pci_select_bars(pdev, IORESOURCE_MEM); |
| 2574 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2575 | spin_lock_irq(&phba->hbalock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2576 | vport->load_flag |= FC_UNLOADING; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2577 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2578 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2579 | kfree(vport->vname); |
| 2580 | lpfc_free_sysfs_attr(vport); |
| 2581 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2582 | kthread_stop(phba->worker_thread); |
| 2583 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2584 | fc_remove_host(shost); |
| 2585 | scsi_remove_host(shost); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2586 | lpfc_cleanup(vport); |
| 2587 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2588 | /* |
| 2589 | * Bring down the SLI Layer. This step disable all interrupts, |
| 2590 | * clears the rings, discards all mailbox commands, and resets |
| 2591 | * the HBA. |
| 2592 | */ |
| 2593 | lpfc_sli_hba_down(phba); |
| 2594 | lpfc_sli_brdrestart(phba); |
| 2595 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2596 | lpfc_stop_phba_timers(phba); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2597 | spin_lock_irq(&phba->hbalock); |
| 2598 | list_del_init(&vport->listentry); |
| 2599 | spin_unlock_irq(&phba->hbalock); |
| 2600 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2601 | lpfc_debugfs_terminate(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2602 | |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 2603 | if (phba->intr_type == MSIX) |
| 2604 | lpfc_disable_msix(phba); |
| 2605 | else { |
| 2606 | free_irq(phba->pcidev->irq, phba); |
| 2607 | if (phba->intr_type == MSI) |
| 2608 | pci_disable_msi(phba->pcidev); |
| 2609 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2610 | |
| 2611 | pci_set_drvdata(pdev, NULL); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2612 | scsi_host_put(shost); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2613 | |
| 2614 | /* |
| 2615 | * Call scsi_free before mem_free since scsi bufs are released to their |
| 2616 | * corresponding pools here. |
| 2617 | */ |
| 2618 | lpfc_scsi_free(phba); |
| 2619 | lpfc_mem_free(phba); |
| 2620 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2621 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), |
| 2622 | phba->hbqslimp.virt, phba->hbqslimp.phys); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2623 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2624 | /* Free resources associated with SLI2 interface */ |
| 2625 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2626 | phba->slim2p.virt, phba->slim2p.phys); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2627 | |
| 2628 | /* unmap adapter SLIM and Control Registers */ |
| 2629 | iounmap(phba->ctrl_regs_memmap_p); |
| 2630 | iounmap(phba->slim_memmap_p); |
| 2631 | |
| 2632 | idr_remove(&lpfc_hba_index, phba->brd_no); |
| 2633 | |
| 2634 | kfree(phba); |
| 2635 | |
Tomohiro Kusumi | 8a4df120 | 2008-01-11 01:53:00 -0500 | [diff] [blame] | 2636 | pci_release_selected_regions(pdev, bars); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2637 | pci_disable_device(pdev); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2638 | } |
| 2639 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 2640 | /** |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2641 | * lpfc_io_error_detected: Driver method for handling PCI I/O error detected. |
| 2642 | * @pdev: pointer to PCI device. |
| 2643 | * @state: the current PCI connection state. |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 2644 | * |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2645 | * This routine is registered to the PCI subsystem for error handling. This |
| 2646 | * function is called by the PCI subsystem after a PCI bus error affecting |
| 2647 | * this device has been detected. When this function is invoked, it will |
| 2648 | * need to stop all the I/Os and interrupt(s) to the device. Once that is |
| 2649 | * done, it will return PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to |
| 2650 | * perform proper recovery as desired. |
| 2651 | * |
| 2652 | * Return codes |
| 2653 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
| 2654 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 2655 | **/ |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 2656 | static pci_ers_result_t lpfc_io_error_detected(struct pci_dev *pdev, |
| 2657 | pci_channel_state_t state) |
| 2658 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2659 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 2660 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 2661 | struct lpfc_sli *psli = &phba->sli; |
| 2662 | struct lpfc_sli_ring *pring; |
| 2663 | |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 2664 | if (state == pci_channel_io_perm_failure) { |
| 2665 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 2666 | "0472 PCI channel I/O permanent failure\n"); |
| 2667 | /* Block all SCSI devices' I/Os on the host */ |
| 2668 | lpfc_scsi_dev_block(phba); |
| 2669 | /* Clean up all driver's outstanding SCSI I/Os */ |
| 2670 | lpfc_sli_flush_fcp_rings(phba); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 2671 | return PCI_ERS_RESULT_DISCONNECT; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 2672 | } |
Linas Vepstas | 5daa49e | 2007-03-08 16:19:11 -0600 | [diff] [blame] | 2673 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 2674 | pci_disable_device(pdev); |
| 2675 | /* |
| 2676 | * There may be I/Os dropped by the firmware. |
| 2677 | * Error iocb (I/O) on txcmplq and let the SCSI layer |
| 2678 | * retry it after re-establishing link. |
| 2679 | */ |
| 2680 | pring = &psli->ring[psli->fcp_ring]; |
| 2681 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 2682 | |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 2683 | if (phba->intr_type == MSIX) |
| 2684 | lpfc_disable_msix(phba); |
| 2685 | else { |
| 2686 | free_irq(phba->pcidev->irq, phba); |
| 2687 | if (phba->intr_type == MSI) |
| 2688 | pci_disable_msi(phba->pcidev); |
| 2689 | } |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2690 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 2691 | /* Request a slot reset. */ |
| 2692 | return PCI_ERS_RESULT_NEED_RESET; |
| 2693 | } |
| 2694 | |
| 2695 | /** |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2696 | * lpfc_io_slot_reset: Restart a PCI device from scratch. |
| 2697 | * @pdev: pointer to PCI device. |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 2698 | * |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2699 | * This routine is registered to the PCI subsystem for error handling. This is |
| 2700 | * called after PCI bus has been reset to restart the PCI card from scratch, |
| 2701 | * as if from a cold-boot. During the PCI subsystem error recovery, after the |
| 2702 | * driver returns PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform |
| 2703 | * proper error recovery and then call this routine before calling the .resume |
| 2704 | * method to recover the device. This function will initialize the HBA device, |
| 2705 | * enable the interrupt, but it will just put the HBA to offline state without |
| 2706 | * passing any I/O traffic. |
| 2707 | * |
| 2708 | * Return codes |
| 2709 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered |
| 2710 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 2711 | */ |
| 2712 | static pci_ers_result_t lpfc_io_slot_reset(struct pci_dev *pdev) |
| 2713 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2714 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 2715 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 2716 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 9b37960 | 2008-04-07 10:16:00 -0400 | [diff] [blame] | 2717 | int error, retval; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 2718 | |
| 2719 | dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n"); |
Benjamin Herrenschmidt | 0948391 | 2007-12-20 15:28:09 +1100 | [diff] [blame] | 2720 | if (pci_enable_device_mem(pdev)) { |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 2721 | printk(KERN_ERR "lpfc: Cannot re-enable " |
| 2722 | "PCI device after reset.\n"); |
| 2723 | return PCI_ERS_RESULT_DISCONNECT; |
| 2724 | } |
| 2725 | |
| 2726 | pci_set_master(pdev); |
| 2727 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2728 | spin_lock_irq(&phba->hbalock); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 2729 | psli->sli_flag &= ~LPFC_SLI2_ACTIVE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2730 | spin_unlock_irq(&phba->hbalock); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 2731 | |
James Smart | 9b37960 | 2008-04-07 10:16:00 -0400 | [diff] [blame] | 2732 | /* Enable configured interrupt method */ |
| 2733 | phba->intr_type = NONE; |
| 2734 | if (phba->cfg_use_msi == 2) { |
| 2735 | error = lpfc_enable_msix(phba); |
| 2736 | if (!error) |
| 2737 | phba->intr_type = MSIX; |
| 2738 | } |
| 2739 | |
| 2740 | /* Fallback to MSI if MSI-X initialization failed */ |
| 2741 | if (phba->cfg_use_msi >= 1 && phba->intr_type == NONE) { |
| 2742 | retval = pci_enable_msi(phba->pcidev); |
| 2743 | if (!retval) |
| 2744 | phba->intr_type = MSI; |
| 2745 | else |
| 2746 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 2747 | "0470 Enable MSI failed, continuing " |
| 2748 | "with IRQ\n"); |
| 2749 | } |
| 2750 | |
| 2751 | /* MSI-X is the only case the doesn't need to call request_irq */ |
| 2752 | if (phba->intr_type != MSIX) { |
| 2753 | retval = request_irq(phba->pcidev->irq, lpfc_intr_handler, |
| 2754 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); |
| 2755 | if (retval) { |
| 2756 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 2757 | "0471 Enable interrupt handler " |
| 2758 | "failed\n"); |
| 2759 | } else if (phba->intr_type != MSI) |
| 2760 | phba->intr_type = INTx; |
| 2761 | } |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 2762 | |
| 2763 | /* Take device offline; this will perform cleanup */ |
| 2764 | lpfc_offline(phba); |
| 2765 | lpfc_sli_brdrestart(phba); |
| 2766 | |
| 2767 | return PCI_ERS_RESULT_RECOVERED; |
| 2768 | } |
| 2769 | |
| 2770 | /** |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2771 | * lpfc_io_resume: Resume PCI I/O operation. |
| 2772 | * @pdev: pointer to PCI device |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 2773 | * |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2774 | * This routine is registered to the PCI subsystem for error handling. It is |
| 2775 | * called when kernel error recovery tells the lpfc driver that it is ok to |
| 2776 | * resume normal PCI operation after PCI bus error recovery. After this call, |
| 2777 | * traffic can start to flow from this device again. |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 2778 | */ |
| 2779 | static void lpfc_io_resume(struct pci_dev *pdev) |
| 2780 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2781 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 2782 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 2783 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2784 | lpfc_online(phba); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 2785 | } |
| 2786 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2787 | static struct pci_device_id lpfc_id_table[] = { |
| 2788 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER, |
| 2789 | PCI_ANY_ID, PCI_ANY_ID, }, |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 2790 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY, |
| 2791 | PCI_ANY_ID, PCI_ANY_ID, }, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2792 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR, |
| 2793 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 2794 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS, |
| 2795 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 2796 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR, |
| 2797 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 2798 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY, |
| 2799 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 2800 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY, |
| 2801 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 2802 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY, |
| 2803 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 2804 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY, |
| 2805 | PCI_ANY_ID, PCI_ANY_ID, }, |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2806 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE, |
| 2807 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 2808 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP, |
| 2809 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 2810 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP, |
| 2811 | PCI_ANY_ID, PCI_ANY_ID, }, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2812 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS, |
| 2813 | PCI_ANY_ID, PCI_ANY_ID, }, |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2814 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP, |
| 2815 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 2816 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP, |
| 2817 | PCI_ANY_ID, PCI_ANY_ID, }, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2818 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID, |
| 2819 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 2820 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB, |
| 2821 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 2822 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR, |
| 2823 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2824 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HORNET, |
| 2825 | PCI_ANY_ID, PCI_ANY_ID, }, |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2826 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP, |
| 2827 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 2828 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP, |
| 2829 | PCI_ANY_ID, PCI_ANY_ID, }, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2830 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID, |
| 2831 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 2832 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB, |
| 2833 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 2834 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY, |
| 2835 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 2836 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101, |
| 2837 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 2838 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S, |
| 2839 | PCI_ANY_ID, PCI_ANY_ID, }, |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2840 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S, |
| 2841 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 2842 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S, |
| 2843 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2844 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT, |
| 2845 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 2846 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID, |
| 2847 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 2848 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB, |
| 2849 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 2850 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP, |
| 2851 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 2852 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP, |
| 2853 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 2854 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S, |
| 2855 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2856 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_VF, |
| 2857 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 2858 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_PF, |
| 2859 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 2860 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_S, |
| 2861 | PCI_ANY_ID, PCI_ANY_ID, }, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2862 | { 0 } |
| 2863 | }; |
| 2864 | |
| 2865 | MODULE_DEVICE_TABLE(pci, lpfc_id_table); |
| 2866 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 2867 | static struct pci_error_handlers lpfc_err_handler = { |
| 2868 | .error_detected = lpfc_io_error_detected, |
| 2869 | .slot_reset = lpfc_io_slot_reset, |
| 2870 | .resume = lpfc_io_resume, |
| 2871 | }; |
| 2872 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2873 | static struct pci_driver lpfc_driver = { |
| 2874 | .name = LPFC_DRIVER_NAME, |
| 2875 | .id_table = lpfc_id_table, |
| 2876 | .probe = lpfc_pci_probe_one, |
| 2877 | .remove = __devexit_p(lpfc_pci_remove_one), |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2878 | .err_handler = &lpfc_err_handler, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2879 | }; |
| 2880 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2881 | /** |
| 2882 | * lpfc_init: lpfc module initialization routine. |
| 2883 | * |
| 2884 | * This routine is to be invoked when the lpfc module is loaded into the |
| 2885 | * kernel. The special kernel macro module_init() is used to indicate the |
| 2886 | * role of this routine to the kernel as lpfc module entry point. |
| 2887 | * |
| 2888 | * Return codes |
| 2889 | * 0 - successful |
| 2890 | * -ENOMEM - FC attach transport failed |
| 2891 | * all others - failed |
| 2892 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2893 | static int __init |
| 2894 | lpfc_init(void) |
| 2895 | { |
| 2896 | int error = 0; |
| 2897 | |
| 2898 | printk(LPFC_MODULE_DESC "\n"); |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 2899 | printk(LPFC_COPYRIGHT "\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2900 | |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 2901 | if (lpfc_enable_npiv) { |
| 2902 | lpfc_transport_functions.vport_create = lpfc_vport_create; |
| 2903 | lpfc_transport_functions.vport_delete = lpfc_vport_delete; |
| 2904 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2905 | lpfc_transport_template = |
| 2906 | fc_attach_transport(&lpfc_transport_functions); |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 2907 | if (lpfc_transport_template == NULL) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2908 | return -ENOMEM; |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 2909 | if (lpfc_enable_npiv) { |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 2910 | lpfc_vport_transport_template = |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2911 | fc_attach_transport(&lpfc_vport_transport_functions); |
| 2912 | if (lpfc_vport_transport_template == NULL) { |
| 2913 | fc_release_transport(lpfc_transport_template); |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 2914 | return -ENOMEM; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2915 | } |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 2916 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2917 | error = pci_register_driver(&lpfc_driver); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2918 | if (error) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2919 | fc_release_transport(lpfc_transport_template); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2920 | if (lpfc_enable_npiv) |
| 2921 | fc_release_transport(lpfc_vport_transport_template); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2922 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2923 | |
| 2924 | return error; |
| 2925 | } |
| 2926 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2927 | /** |
| 2928 | * lpfc_exit: lpfc module removal routine. |
| 2929 | * |
| 2930 | * This routine is invoked when the lpfc module is removed from the kernel. |
| 2931 | * The special kernel macro module_exit() is used to indicate the role of |
| 2932 | * this routine to the kernel as lpfc module exit point. |
| 2933 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2934 | static void __exit |
| 2935 | lpfc_exit(void) |
| 2936 | { |
| 2937 | pci_unregister_driver(&lpfc_driver); |
| 2938 | fc_release_transport(lpfc_transport_template); |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 2939 | if (lpfc_enable_npiv) |
| 2940 | fc_release_transport(lpfc_vport_transport_template); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2941 | } |
| 2942 | |
| 2943 | module_init(lpfc_init); |
| 2944 | module_exit(lpfc_exit); |
| 2945 | MODULE_LICENSE("GPL"); |
| 2946 | MODULE_DESCRIPTION(LPFC_MODULE_DESC); |
| 2947 | MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com"); |
| 2948 | MODULE_VERSION("0:" LPFC_DRIVER_VERSION); |