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