lpfc_init.c 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2006 Emulex. All rights reserved. *
  5. * EMULEX and SLI are trademarks of Emulex. *
  6. * www.emulex.com *
  7. * Portions Copyright (C) 2004-2005 Christoph Hellwig *
  8. * *
  9. * This program is free software; you can redistribute it and/or *
  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. *
  20. *******************************************************************/
  21. #include <linux/blkdev.h>
  22. #include <linux/delay.h>
  23. #include <linux/dma-mapping.h>
  24. #include <linux/idr.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/kthread.h>
  27. #include <linux/pci.h>
  28. #include <linux/spinlock.h>
  29. #include <scsi/scsi.h>
  30. #include <scsi/scsi_device.h>
  31. #include <scsi/scsi_host.h>
  32. #include <scsi/scsi_transport_fc.h>
  33. #include "lpfc_hw.h"
  34. #include "lpfc_sli.h"
  35. #include "lpfc_disc.h"
  36. #include "lpfc_scsi.h"
  37. #include "lpfc.h"
  38. #include "lpfc_logmsg.h"
  39. #include "lpfc_crtn.h"
  40. #include "lpfc_version.h"
  41. static int lpfc_parse_vpd(struct lpfc_hba *, uint8_t *, int);
  42. static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *);
  43. static int lpfc_post_rcv_buf(struct lpfc_hba *);
  44. static struct scsi_transport_template *lpfc_transport_template = NULL;
  45. static DEFINE_IDR(lpfc_hba_index);
  46. /************************************************************************/
  47. /* */
  48. /* lpfc_config_port_prep */
  49. /* This routine will do LPFC initialization prior to the */
  50. /* CONFIG_PORT mailbox command. This will be initialized */
  51. /* as a SLI layer callback routine. */
  52. /* This routine returns 0 on success or -ERESTART if it wants */
  53. /* the SLI layer to reset the HBA and try again. Any */
  54. /* other return value indicates an error. */
  55. /* */
  56. /************************************************************************/
  57. int
  58. lpfc_config_port_prep(struct lpfc_hba * phba)
  59. {
  60. lpfc_vpd_t *vp = &phba->vpd;
  61. int i = 0, rc;
  62. LPFC_MBOXQ_t *pmb;
  63. MAILBOX_t *mb;
  64. char *lpfc_vpd_data = NULL;
  65. uint16_t offset = 0;
  66. static char licensed[56] =
  67. "key unlock for use with gnu public licensed code only\0";
  68. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  69. if (!pmb) {
  70. phba->hba_state = LPFC_HBA_ERROR;
  71. return -ENOMEM;
  72. }
  73. mb = &pmb->mb;
  74. phba->hba_state = LPFC_INIT_MBX_CMDS;
  75. if (lpfc_is_LC_HBA(phba->pcidev->device)) {
  76. uint32_t *ptext = (uint32_t *) licensed;
  77. for (i = 0; i < 56; i += sizeof (uint32_t), ptext++)
  78. *ptext = cpu_to_be32(*ptext);
  79. lpfc_read_nv(phba, pmb);
  80. memset((char*)mb->un.varRDnvp.rsvd3, 0,
  81. sizeof (mb->un.varRDnvp.rsvd3));
  82. memcpy((char*)mb->un.varRDnvp.rsvd3, licensed,
  83. sizeof (licensed));
  84. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  85. if (rc != MBX_SUCCESS) {
  86. lpfc_printf_log(phba,
  87. KERN_ERR,
  88. LOG_MBOX,
  89. "%d:0324 Config Port initialization "
  90. "error, mbxCmd x%x READ_NVPARM, "
  91. "mbxStatus x%x\n",
  92. phba->brd_no,
  93. mb->mbxCommand, mb->mbxStatus);
  94. mempool_free(pmb, phba->mbox_mem_pool);
  95. return -ERESTART;
  96. }
  97. memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename,
  98. sizeof (mb->un.varRDnvp.nodename));
  99. }
  100. /* Setup and issue mailbox READ REV command */
  101. lpfc_read_rev(phba, pmb);
  102. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  103. if (rc != MBX_SUCCESS) {
  104. lpfc_printf_log(phba,
  105. KERN_ERR,
  106. LOG_INIT,
  107. "%d:0439 Adapter failed to init, mbxCmd x%x "
  108. "READ_REV, mbxStatus x%x\n",
  109. phba->brd_no,
  110. mb->mbxCommand, mb->mbxStatus);
  111. mempool_free( pmb, phba->mbox_mem_pool);
  112. return -ERESTART;
  113. }
  114. /*
  115. * The value of rr must be 1 since the driver set the cv field to 1.
  116. * This setting requires the FW to set all revision fields.
  117. */
  118. if (mb->un.varRdRev.rr == 0) {
  119. vp->rev.rBit = 0;
  120. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  121. "%d:0440 Adapter failed to init, READ_REV has "
  122. "missing revision information.\n",
  123. phba->brd_no);
  124. mempool_free(pmb, phba->mbox_mem_pool);
  125. return -ERESTART;
  126. }
  127. /* Save information as VPD data */
  128. vp->rev.rBit = 1;
  129. vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev;
  130. memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16);
  131. vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev;
  132. memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16);
  133. vp->rev.biuRev = mb->un.varRdRev.biuRev;
  134. vp->rev.smRev = mb->un.varRdRev.smRev;
  135. vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev;
  136. vp->rev.endecRev = mb->un.varRdRev.endecRev;
  137. vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh;
  138. vp->rev.fcphLow = mb->un.varRdRev.fcphLow;
  139. vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh;
  140. vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow;
  141. vp->rev.postKernRev = mb->un.varRdRev.postKernRev;
  142. vp->rev.opFwRev = mb->un.varRdRev.opFwRev;
  143. if (lpfc_is_LC_HBA(phba->pcidev->device))
  144. memcpy(phba->RandomData, (char *)&mb->un.varWords[24],
  145. sizeof (phba->RandomData));
  146. /* Get adapter VPD information */
  147. pmb->context2 = kmalloc(DMP_RSP_SIZE, GFP_KERNEL);
  148. if (!pmb->context2)
  149. goto out_free_mbox;
  150. lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL);
  151. if (!lpfc_vpd_data)
  152. goto out_free_context2;
  153. do {
  154. lpfc_dump_mem(phba, pmb, offset);
  155. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  156. if (rc != MBX_SUCCESS) {
  157. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  158. "%d:0441 VPD not present on adapter, "
  159. "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
  160. phba->brd_no,
  161. mb->mbxCommand, mb->mbxStatus);
  162. mb->un.varDmp.word_cnt = 0;
  163. }
  164. if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset)
  165. mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset;
  166. lpfc_sli_pcimem_bcopy(pmb->context2, lpfc_vpd_data + offset,
  167. mb->un.varDmp.word_cnt);
  168. offset += mb->un.varDmp.word_cnt;
  169. } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE);
  170. lpfc_parse_vpd(phba, lpfc_vpd_data, offset);
  171. kfree(lpfc_vpd_data);
  172. out_free_context2:
  173. kfree(pmb->context2);
  174. out_free_mbox:
  175. mempool_free(pmb, phba->mbox_mem_pool);
  176. return 0;
  177. }
  178. /************************************************************************/
  179. /* */
  180. /* lpfc_config_port_post */
  181. /* This routine will do LPFC initialization after the */
  182. /* CONFIG_PORT mailbox command. This will be initialized */
  183. /* as a SLI layer callback routine. */
  184. /* This routine returns 0 on success. Any other return value */
  185. /* indicates an error. */
  186. /* */
  187. /************************************************************************/
  188. int
  189. lpfc_config_port_post(struct lpfc_hba * phba)
  190. {
  191. LPFC_MBOXQ_t *pmb;
  192. MAILBOX_t *mb;
  193. struct lpfc_dmabuf *mp;
  194. struct lpfc_sli *psli = &phba->sli;
  195. uint32_t status, timeout;
  196. int i, j, rc;
  197. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  198. if (!pmb) {
  199. phba->hba_state = LPFC_HBA_ERROR;
  200. return -ENOMEM;
  201. }
  202. mb = &pmb->mb;
  203. lpfc_config_link(phba, pmb);
  204. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  205. if (rc != MBX_SUCCESS) {
  206. lpfc_printf_log(phba,
  207. KERN_ERR,
  208. LOG_INIT,
  209. "%d:0447 Adapter failed init, mbxCmd x%x "
  210. "CONFIG_LINK mbxStatus x%x\n",
  211. phba->brd_no,
  212. mb->mbxCommand, mb->mbxStatus);
  213. phba->hba_state = LPFC_HBA_ERROR;
  214. mempool_free( pmb, phba->mbox_mem_pool);
  215. return -EIO;
  216. }
  217. /* Get login parameters for NID. */
  218. lpfc_read_sparam(phba, pmb);
  219. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  220. lpfc_printf_log(phba,
  221. KERN_ERR,
  222. LOG_INIT,
  223. "%d:0448 Adapter failed init, mbxCmd x%x "
  224. "READ_SPARM mbxStatus x%x\n",
  225. phba->brd_no,
  226. mb->mbxCommand, mb->mbxStatus);
  227. phba->hba_state = LPFC_HBA_ERROR;
  228. mp = (struct lpfc_dmabuf *) pmb->context1;
  229. mempool_free( pmb, phba->mbox_mem_pool);
  230. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  231. kfree(mp);
  232. return -EIO;
  233. }
  234. mp = (struct lpfc_dmabuf *) pmb->context1;
  235. memcpy(&phba->fc_sparam, mp->virt, sizeof (struct serv_parm));
  236. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  237. kfree(mp);
  238. pmb->context1 = NULL;
  239. memcpy(&phba->fc_nodename, &phba->fc_sparam.nodeName,
  240. sizeof (struct lpfc_name));
  241. memcpy(&phba->fc_portname, &phba->fc_sparam.portName,
  242. sizeof (struct lpfc_name));
  243. /* If no serial number in VPD data, use low 6 bytes of WWNN */
  244. /* This should be consolidated into parse_vpd ? - mr */
  245. if (phba->SerialNumber[0] == 0) {
  246. uint8_t *outptr;
  247. outptr = &phba->fc_nodename.u.s.IEEE[0];
  248. for (i = 0; i < 12; i++) {
  249. status = *outptr++;
  250. j = ((status & 0xf0) >> 4);
  251. if (j <= 9)
  252. phba->SerialNumber[i] =
  253. (char)((uint8_t) 0x30 + (uint8_t) j);
  254. else
  255. phba->SerialNumber[i] =
  256. (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
  257. i++;
  258. j = (status & 0xf);
  259. if (j <= 9)
  260. phba->SerialNumber[i] =
  261. (char)((uint8_t) 0x30 + (uint8_t) j);
  262. else
  263. phba->SerialNumber[i] =
  264. (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
  265. }
  266. }
  267. lpfc_read_config(phba, pmb);
  268. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  269. lpfc_printf_log(phba,
  270. KERN_ERR,
  271. LOG_INIT,
  272. "%d:0453 Adapter failed to init, mbxCmd x%x "
  273. "READ_CONFIG, mbxStatus x%x\n",
  274. phba->brd_no,
  275. mb->mbxCommand, mb->mbxStatus);
  276. phba->hba_state = LPFC_HBA_ERROR;
  277. mempool_free( pmb, phba->mbox_mem_pool);
  278. return -EIO;
  279. }
  280. /* Reset the DFT_HBA_Q_DEPTH to the max xri */
  281. if (phba->cfg_hba_queue_depth > (mb->un.varRdConfig.max_xri+1))
  282. phba->cfg_hba_queue_depth =
  283. mb->un.varRdConfig.max_xri + 1;
  284. phba->lmt = mb->un.varRdConfig.lmt;
  285. /* Get the default values for Model Name and Description */
  286. lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
  287. if ((phba->cfg_link_speed > LINK_SPEED_10G)
  288. || ((phba->cfg_link_speed == LINK_SPEED_1G)
  289. && !(phba->lmt & LMT_1Gb))
  290. || ((phba->cfg_link_speed == LINK_SPEED_2G)
  291. && !(phba->lmt & LMT_2Gb))
  292. || ((phba->cfg_link_speed == LINK_SPEED_4G)
  293. && !(phba->lmt & LMT_4Gb))
  294. || ((phba->cfg_link_speed == LINK_SPEED_8G)
  295. && !(phba->lmt & LMT_8Gb))
  296. || ((phba->cfg_link_speed == LINK_SPEED_10G)
  297. && !(phba->lmt & LMT_10Gb))) {
  298. /* Reset link speed to auto */
  299. lpfc_printf_log(phba,
  300. KERN_WARNING,
  301. LOG_LINK_EVENT,
  302. "%d:1302 Invalid speed for this board: "
  303. "Reset link speed to auto: x%x\n",
  304. phba->brd_no,
  305. phba->cfg_link_speed);
  306. phba->cfg_link_speed = LINK_SPEED_AUTO;
  307. }
  308. phba->hba_state = LPFC_LINK_DOWN;
  309. /* Only process IOCBs on ring 0 till hba_state is READY */
  310. if (psli->ring[psli->ip_ring].cmdringaddr)
  311. psli->ring[psli->ip_ring].flag |= LPFC_STOP_IOCB_EVENT;
  312. if (psli->ring[psli->fcp_ring].cmdringaddr)
  313. psli->ring[psli->fcp_ring].flag |= LPFC_STOP_IOCB_EVENT;
  314. if (psli->ring[psli->next_ring].cmdringaddr)
  315. psli->ring[psli->next_ring].flag |= LPFC_STOP_IOCB_EVENT;
  316. /* Post receive buffers for desired rings */
  317. lpfc_post_rcv_buf(phba);
  318. /* Enable appropriate host interrupts */
  319. spin_lock_irq(phba->host->host_lock);
  320. status = readl(phba->HCregaddr);
  321. status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA;
  322. if (psli->num_rings > 0)
  323. status |= HC_R0INT_ENA;
  324. if (psli->num_rings > 1)
  325. status |= HC_R1INT_ENA;
  326. if (psli->num_rings > 2)
  327. status |= HC_R2INT_ENA;
  328. if (psli->num_rings > 3)
  329. status |= HC_R3INT_ENA;
  330. if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) &&
  331. (phba->cfg_poll & DISABLE_FCP_RING_INT))
  332. status &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
  333. writel(status, phba->HCregaddr);
  334. readl(phba->HCregaddr); /* flush */
  335. spin_unlock_irq(phba->host->host_lock);
  336. /*
  337. * Setup the ring 0 (els) timeout handler
  338. */
  339. timeout = phba->fc_ratov << 1;
  340. phba->els_tmofunc.expires = jiffies + HZ * timeout;
  341. add_timer(&phba->els_tmofunc);
  342. lpfc_init_link(phba, pmb, phba->cfg_topology, phba->cfg_link_speed);
  343. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  344. if (lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT) != MBX_SUCCESS) {
  345. lpfc_printf_log(phba,
  346. KERN_ERR,
  347. LOG_INIT,
  348. "%d:0454 Adapter failed to init, mbxCmd x%x "
  349. "INIT_LINK, mbxStatus x%x\n",
  350. phba->brd_no,
  351. mb->mbxCommand, mb->mbxStatus);
  352. /* Clear all interrupt enable conditions */
  353. writel(0, phba->HCregaddr);
  354. readl(phba->HCregaddr); /* flush */
  355. /* Clear all pending interrupts */
  356. writel(0xffffffff, phba->HAregaddr);
  357. readl(phba->HAregaddr); /* flush */
  358. phba->hba_state = LPFC_HBA_ERROR;
  359. mempool_free(pmb, phba->mbox_mem_pool);
  360. return -EIO;
  361. }
  362. /* MBOX buffer will be freed in mbox compl */
  363. return (0);
  364. }
  365. static int
  366. lpfc_discovery_wait(struct lpfc_hba *phba)
  367. {
  368. int i = 0;
  369. while ((phba->hba_state != LPFC_HBA_READY) ||
  370. (phba->num_disc_nodes) || (phba->fc_prli_sent) ||
  371. ((phba->fc_map_cnt == 0) && (i<2)) ||
  372. (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE)) {
  373. /* Check every second for 30 retries. */
  374. i++;
  375. if (i > 30) {
  376. return -ETIMEDOUT;
  377. }
  378. if ((i >= 15) && (phba->hba_state <= LPFC_LINK_DOWN)) {
  379. /* The link is down. Set linkdown timeout */
  380. return -ETIMEDOUT;
  381. }
  382. /* Delay for 1 second to give discovery time to complete. */
  383. msleep(1000);
  384. }
  385. return 0;
  386. }
  387. /************************************************************************/
  388. /* */
  389. /* lpfc_hba_down_prep */
  390. /* This routine will do LPFC uninitialization before the */
  391. /* HBA is reset when bringing down the SLI Layer. This will be */
  392. /* initialized as a SLI layer callback routine. */
  393. /* This routine returns 0 on success. Any other return value */
  394. /* indicates an error. */
  395. /* */
  396. /************************************************************************/
  397. int
  398. lpfc_hba_down_prep(struct lpfc_hba * phba)
  399. {
  400. /* Disable interrupts */
  401. writel(0, phba->HCregaddr);
  402. readl(phba->HCregaddr); /* flush */
  403. /* Cleanup potential discovery resources */
  404. lpfc_els_flush_rscn(phba);
  405. lpfc_els_flush_cmd(phba);
  406. lpfc_disc_flush_list(phba);
  407. return (0);
  408. }
  409. /************************************************************************/
  410. /* */
  411. /* lpfc_hba_down_post */
  412. /* This routine will do uninitialization after the HBA is reset */
  413. /* when bringing down the SLI Layer. */
  414. /* This routine returns 0 on success. Any other return value */
  415. /* indicates an error. */
  416. /* */
  417. /************************************************************************/
  418. int
  419. lpfc_hba_down_post(struct lpfc_hba * phba)
  420. {
  421. struct lpfc_sli *psli = &phba->sli;
  422. struct lpfc_sli_ring *pring;
  423. struct lpfc_dmabuf *mp, *next_mp;
  424. int i;
  425. /* Cleanup preposted buffers on the ELS ring */
  426. pring = &psli->ring[LPFC_ELS_RING];
  427. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  428. list_del(&mp->list);
  429. pring->postbufq_cnt--;
  430. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  431. kfree(mp);
  432. }
  433. for (i = 0; i < psli->num_rings; i++) {
  434. pring = &psli->ring[i];
  435. lpfc_sli_abort_iocb_ring(phba, pring);
  436. }
  437. return 0;
  438. }
  439. /************************************************************************/
  440. /* */
  441. /* lpfc_handle_eratt */
  442. /* This routine will handle processing a Host Attention */
  443. /* Error Status event. This will be initialized */
  444. /* as a SLI layer callback routine. */
  445. /* */
  446. /************************************************************************/
  447. void
  448. lpfc_handle_eratt(struct lpfc_hba * phba)
  449. {
  450. struct lpfc_sli *psli = &phba->sli;
  451. struct lpfc_sli_ring *pring;
  452. if (phba->work_hs & HS_FFER6) {
  453. /* Re-establishing Link */
  454. lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
  455. "%d:1301 Re-establishing Link "
  456. "Data: x%x x%x x%x\n",
  457. phba->brd_no, phba->work_hs,
  458. phba->work_status[0], phba->work_status[1]);
  459. spin_lock_irq(phba->host->host_lock);
  460. phba->fc_flag |= FC_ESTABLISH_LINK;
  461. psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
  462. spin_unlock_irq(phba->host->host_lock);
  463. /*
  464. * Firmware stops when it triggled erratt with HS_FFER6.
  465. * That could cause the I/Os dropped by the firmware.
  466. * Error iocb (I/O) on txcmplq and let the SCSI layer
  467. * retry it after re-establishing link.
  468. */
  469. pring = &psli->ring[psli->fcp_ring];
  470. lpfc_sli_abort_iocb_ring(phba, pring);
  471. /*
  472. * There was a firmware error. Take the hba offline and then
  473. * attempt to restart it.
  474. */
  475. lpfc_offline(phba);
  476. lpfc_sli_brdrestart(phba);
  477. if (lpfc_online(phba) == 0) { /* Initialize the HBA */
  478. mod_timer(&phba->fc_estabtmo, jiffies + HZ * 60);
  479. return;
  480. }
  481. } else {
  482. /* The if clause above forces this code path when the status
  483. * failure is a value other than FFER6. Do not call the offline
  484. * twice. This is the adapter hardware error path.
  485. */
  486. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  487. "%d:0457 Adapter Hardware Error "
  488. "Data: x%x x%x x%x\n",
  489. phba->brd_no, phba->work_hs,
  490. phba->work_status[0], phba->work_status[1]);
  491. psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
  492. lpfc_offline(phba);
  493. phba->hba_state = LPFC_HBA_ERROR;
  494. lpfc_hba_down_post(phba);
  495. }
  496. }
  497. /************************************************************************/
  498. /* */
  499. /* lpfc_handle_latt */
  500. /* This routine will handle processing a Host Attention */
  501. /* Link Status event. This will be initialized */
  502. /* as a SLI layer callback routine. */
  503. /* */
  504. /************************************************************************/
  505. void
  506. lpfc_handle_latt(struct lpfc_hba * phba)
  507. {
  508. struct lpfc_sli *psli = &phba->sli;
  509. LPFC_MBOXQ_t *pmb;
  510. volatile uint32_t control;
  511. struct lpfc_dmabuf *mp;
  512. int rc = -ENOMEM;
  513. pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  514. if (!pmb)
  515. goto lpfc_handle_latt_err_exit;
  516. mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  517. if (!mp)
  518. goto lpfc_handle_latt_free_pmb;
  519. mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
  520. if (!mp->virt)
  521. goto lpfc_handle_latt_free_mp;
  522. rc = -EIO;
  523. /* Cleanup any outstanding ELS commands */
  524. lpfc_els_flush_cmd(phba);
  525. psli->slistat.link_event++;
  526. lpfc_read_la(phba, pmb, mp);
  527. pmb->mbox_cmpl = lpfc_mbx_cmpl_read_la;
  528. rc = lpfc_sli_issue_mbox (phba, pmb, (MBX_NOWAIT | MBX_STOP_IOCB));
  529. if (rc == MBX_NOT_FINISHED)
  530. goto lpfc_handle_latt_free_mp;
  531. /* Clear Link Attention in HA REG */
  532. spin_lock_irq(phba->host->host_lock);
  533. writel(HA_LATT, phba->HAregaddr);
  534. readl(phba->HAregaddr); /* flush */
  535. spin_unlock_irq(phba->host->host_lock);
  536. return;
  537. lpfc_handle_latt_free_mp:
  538. kfree(mp);
  539. lpfc_handle_latt_free_pmb:
  540. kfree(pmb);
  541. lpfc_handle_latt_err_exit:
  542. /* Enable Link attention interrupts */
  543. spin_lock_irq(phba->host->host_lock);
  544. psli->sli_flag |= LPFC_PROCESS_LA;
  545. control = readl(phba->HCregaddr);
  546. control |= HC_LAINT_ENA;
  547. writel(control, phba->HCregaddr);
  548. readl(phba->HCregaddr); /* flush */
  549. /* Clear Link Attention in HA REG */
  550. writel(HA_LATT, phba->HAregaddr);
  551. readl(phba->HAregaddr); /* flush */
  552. spin_unlock_irq(phba->host->host_lock);
  553. lpfc_linkdown(phba);
  554. phba->hba_state = LPFC_HBA_ERROR;
  555. /* The other case is an error from issue_mbox */
  556. if (rc == -ENOMEM)
  557. lpfc_printf_log(phba,
  558. KERN_WARNING,
  559. LOG_MBOX,
  560. "%d:0300 READ_LA: no buffers\n",
  561. phba->brd_no);
  562. return;
  563. }
  564. /************************************************************************/
  565. /* */
  566. /* lpfc_parse_vpd */
  567. /* This routine will parse the VPD data */
  568. /* */
  569. /************************************************************************/
  570. static int
  571. lpfc_parse_vpd(struct lpfc_hba * phba, uint8_t * vpd, int len)
  572. {
  573. uint8_t lenlo, lenhi;
  574. uint32_t Length;
  575. int i, j;
  576. int finished = 0;
  577. int index = 0;
  578. if (!vpd)
  579. return 0;
  580. /* Vital Product */
  581. lpfc_printf_log(phba,
  582. KERN_INFO,
  583. LOG_INIT,
  584. "%d:0455 Vital Product Data: x%x x%x x%x x%x\n",
  585. phba->brd_no,
  586. (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
  587. (uint32_t) vpd[3]);
  588. while (!finished && (index < (len - 4))) {
  589. switch (vpd[index]) {
  590. case 0x82:
  591. case 0x91:
  592. index += 1;
  593. lenlo = vpd[index];
  594. index += 1;
  595. lenhi = vpd[index];
  596. index += 1;
  597. i = ((((unsigned short)lenhi) << 8) + lenlo);
  598. index += i;
  599. break;
  600. case 0x90:
  601. index += 1;
  602. lenlo = vpd[index];
  603. index += 1;
  604. lenhi = vpd[index];
  605. index += 1;
  606. Length = ((((unsigned short)lenhi) << 8) + lenlo);
  607. if (Length > len - index)
  608. Length = len - index;
  609. while (Length > 0) {
  610. /* Look for Serial Number */
  611. if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) {
  612. index += 2;
  613. i = vpd[index];
  614. index += 1;
  615. j = 0;
  616. Length -= (3+i);
  617. while(i--) {
  618. phba->SerialNumber[j++] = vpd[index++];
  619. if (j == 31)
  620. break;
  621. }
  622. phba->SerialNumber[j] = 0;
  623. continue;
  624. }
  625. else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) {
  626. phba->vpd_flag |= VPD_MODEL_DESC;
  627. index += 2;
  628. i = vpd[index];
  629. index += 1;
  630. j = 0;
  631. Length -= (3+i);
  632. while(i--) {
  633. phba->ModelDesc[j++] = vpd[index++];
  634. if (j == 255)
  635. break;
  636. }
  637. phba->ModelDesc[j] = 0;
  638. continue;
  639. }
  640. else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) {
  641. phba->vpd_flag |= VPD_MODEL_NAME;
  642. index += 2;
  643. i = vpd[index];
  644. index += 1;
  645. j = 0;
  646. Length -= (3+i);
  647. while(i--) {
  648. phba->ModelName[j++] = vpd[index++];
  649. if (j == 79)
  650. break;
  651. }
  652. phba->ModelName[j] = 0;
  653. continue;
  654. }
  655. else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) {
  656. phba->vpd_flag |= VPD_PROGRAM_TYPE;
  657. index += 2;
  658. i = vpd[index];
  659. index += 1;
  660. j = 0;
  661. Length -= (3+i);
  662. while(i--) {
  663. phba->ProgramType[j++] = vpd[index++];
  664. if (j == 255)
  665. break;
  666. }
  667. phba->ProgramType[j] = 0;
  668. continue;
  669. }
  670. else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) {
  671. phba->vpd_flag |= VPD_PORT;
  672. index += 2;
  673. i = vpd[index];
  674. index += 1;
  675. j = 0;
  676. Length -= (3+i);
  677. while(i--) {
  678. phba->Port[j++] = vpd[index++];
  679. if (j == 19)
  680. break;
  681. }
  682. phba->Port[j] = 0;
  683. continue;
  684. }
  685. else {
  686. index += 2;
  687. i = vpd[index];
  688. index += 1;
  689. index += i;
  690. Length -= (3 + i);
  691. }
  692. }
  693. finished = 0;
  694. break;
  695. case 0x78:
  696. finished = 1;
  697. break;
  698. default:
  699. index ++;
  700. break;
  701. }
  702. }
  703. return(1);
  704. }
  705. static void
  706. lpfc_get_hba_model_desc(struct lpfc_hba * phba, uint8_t * mdp, uint8_t * descp)
  707. {
  708. lpfc_vpd_t *vp;
  709. uint16_t dev_id = phba->pcidev->device;
  710. uint16_t dev_subid = phba->pcidev->subsystem_device;
  711. uint8_t hdrtype;
  712. int max_speed;
  713. char * ports;
  714. struct {
  715. char * name;
  716. int max_speed;
  717. char * ports;
  718. char * bus;
  719. } m = {"<Unknown>", 0, "", ""};
  720. pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
  721. ports = (hdrtype == 0x80) ? "2-port " : "";
  722. if (mdp && mdp[0] != '\0'
  723. && descp && descp[0] != '\0')
  724. return;
  725. if (phba->lmt & LMT_10Gb)
  726. max_speed = 10;
  727. else if (phba->lmt & LMT_8Gb)
  728. max_speed = 8;
  729. else if (phba->lmt & LMT_4Gb)
  730. max_speed = 4;
  731. else if (phba->lmt & LMT_2Gb)
  732. max_speed = 2;
  733. else
  734. max_speed = 1;
  735. vp = &phba->vpd;
  736. switch (dev_id) {
  737. case PCI_DEVICE_ID_FIREFLY:
  738. m = (typeof(m)){"LP6000", max_speed, "", "PCI"};
  739. break;
  740. case PCI_DEVICE_ID_SUPERFLY:
  741. if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
  742. m = (typeof(m)){"LP7000", max_speed, "", "PCI"};
  743. else
  744. m = (typeof(m)){"LP7000E", max_speed, "", "PCI"};
  745. break;
  746. case PCI_DEVICE_ID_DRAGONFLY:
  747. m = (typeof(m)){"LP8000", max_speed, "", "PCI"};
  748. break;
  749. case PCI_DEVICE_ID_CENTAUR:
  750. if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
  751. m = (typeof(m)){"LP9002", max_speed, "", "PCI"};
  752. else
  753. m = (typeof(m)){"LP9000", max_speed, "", "PCI"};
  754. break;
  755. case PCI_DEVICE_ID_RFLY:
  756. m = (typeof(m)){"LP952", max_speed, "", "PCI"};
  757. break;
  758. case PCI_DEVICE_ID_PEGASUS:
  759. m = (typeof(m)){"LP9802", max_speed, "", "PCI-X"};
  760. break;
  761. case PCI_DEVICE_ID_THOR:
  762. if (hdrtype == 0x80)
  763. m = (typeof(m)){"LP10000DC",
  764. max_speed, ports, "PCI-X"};
  765. else
  766. m = (typeof(m)){"LP10000",
  767. max_speed, ports, "PCI-X"};
  768. break;
  769. case PCI_DEVICE_ID_VIPER:
  770. m = (typeof(m)){"LPX1000", max_speed, "", "PCI-X"};
  771. break;
  772. case PCI_DEVICE_ID_PFLY:
  773. m = (typeof(m)){"LP982", max_speed, "", "PCI-X"};
  774. break;
  775. case PCI_DEVICE_ID_TFLY:
  776. if (hdrtype == 0x80)
  777. m = (typeof(m)){"LP1050DC", max_speed, ports, "PCI-X"};
  778. else
  779. m = (typeof(m)){"LP1050", max_speed, ports, "PCI-X"};
  780. break;
  781. case PCI_DEVICE_ID_HELIOS:
  782. if (hdrtype == 0x80)
  783. m = (typeof(m)){"LP11002", max_speed, ports, "PCI-X2"};
  784. else
  785. m = (typeof(m)){"LP11000", max_speed, ports, "PCI-X2"};
  786. break;
  787. case PCI_DEVICE_ID_HELIOS_SCSP:
  788. m = (typeof(m)){"LP11000-SP", max_speed, ports, "PCI-X2"};
  789. break;
  790. case PCI_DEVICE_ID_HELIOS_DCSP:
  791. m = (typeof(m)){"LP11002-SP", max_speed, ports, "PCI-X2"};
  792. break;
  793. case PCI_DEVICE_ID_NEPTUNE:
  794. if (hdrtype == 0x80)
  795. m = (typeof(m)){"LPe1002", max_speed, ports, "PCIe"};
  796. else
  797. m = (typeof(m)){"LPe1000", max_speed, ports, "PCIe"};
  798. break;
  799. case PCI_DEVICE_ID_NEPTUNE_SCSP:
  800. m = (typeof(m)){"LPe1000-SP", max_speed, ports, "PCIe"};
  801. break;
  802. case PCI_DEVICE_ID_NEPTUNE_DCSP:
  803. m = (typeof(m)){"LPe1002-SP", max_speed, ports, "PCIe"};
  804. break;
  805. case PCI_DEVICE_ID_BMID:
  806. m = (typeof(m)){"LP1150", max_speed, ports, "PCI-X2"};
  807. break;
  808. case PCI_DEVICE_ID_BSMB:
  809. m = (typeof(m)){"LP111", max_speed, ports, "PCI-X2"};
  810. break;
  811. case PCI_DEVICE_ID_ZEPHYR:
  812. if (hdrtype == 0x80)
  813. m = (typeof(m)){"LPe11002", max_speed, ports, "PCIe"};
  814. else
  815. m = (typeof(m)){"LPe11000", max_speed, ports, "PCIe"};
  816. break;
  817. case PCI_DEVICE_ID_ZEPHYR_SCSP:
  818. m = (typeof(m)){"LPe11000", max_speed, ports, "PCIe"};
  819. break;
  820. case PCI_DEVICE_ID_ZEPHYR_DCSP:
  821. m = (typeof(m)){"LPe11002-SP", max_speed, ports, "PCIe"};
  822. break;
  823. case PCI_DEVICE_ID_ZMID:
  824. m = (typeof(m)){"LPe1150", max_speed, ports, "PCIe"};
  825. break;
  826. case PCI_DEVICE_ID_ZSMB:
  827. m = (typeof(m)){"LPe111", max_speed, ports, "PCIe"};
  828. break;
  829. case PCI_DEVICE_ID_LP101:
  830. m = (typeof(m)){"LP101", max_speed, ports, "PCI-X"};
  831. break;
  832. case PCI_DEVICE_ID_LP10000S:
  833. m = (typeof(m)){"LP10000-S", max_speed, ports, "PCI"};
  834. break;
  835. case PCI_DEVICE_ID_LP11000S:
  836. case PCI_DEVICE_ID_LPE11000S:
  837. switch (dev_subid) {
  838. case PCI_SUBSYSTEM_ID_LP11000S:
  839. m = (typeof(m)){"LP11000-S", max_speed,
  840. ports, "PCI-X2"};
  841. break;
  842. case PCI_SUBSYSTEM_ID_LP11002S:
  843. m = (typeof(m)){"LP11002-S", max_speed,
  844. ports, "PCI-X2"};
  845. break;
  846. case PCI_SUBSYSTEM_ID_LPE11000S:
  847. m = (typeof(m)){"LPe11000-S", max_speed,
  848. ports, "PCIe"};
  849. break;
  850. case PCI_SUBSYSTEM_ID_LPE11002S:
  851. m = (typeof(m)){"LPe11002-S", max_speed,
  852. ports, "PCIe"};
  853. break;
  854. case PCI_SUBSYSTEM_ID_LPE11010S:
  855. m = (typeof(m)){"LPe11010-S", max_speed,
  856. "10-port ", "PCIe"};
  857. break;
  858. default:
  859. m = (typeof(m)){ NULL };
  860. break;
  861. }
  862. break;
  863. default:
  864. m = (typeof(m)){ NULL };
  865. break;
  866. }
  867. if (mdp && mdp[0] == '\0')
  868. snprintf(mdp, 79,"%s", m.name);
  869. if (descp && descp[0] == '\0')
  870. snprintf(descp, 255,
  871. "Emulex %s %dGb %s%s Fibre Channel Adapter",
  872. m.name, m.max_speed, m.ports, m.bus);
  873. }
  874. /**************************************************/
  875. /* lpfc_post_buffer */
  876. /* */
  877. /* This routine will post count buffers to the */
  878. /* ring with the QUE_RING_BUF_CN command. This */
  879. /* allows 3 buffers / command to be posted. */
  880. /* Returns the number of buffers NOT posted. */
  881. /**************************************************/
  882. int
  883. lpfc_post_buffer(struct lpfc_hba * phba, struct lpfc_sli_ring * pring, int cnt,
  884. int type)
  885. {
  886. IOCB_t *icmd;
  887. struct lpfc_iocbq *iocb;
  888. struct lpfc_dmabuf *mp1, *mp2;
  889. cnt += pring->missbufcnt;
  890. /* While there are buffers to post */
  891. while (cnt > 0) {
  892. /* Allocate buffer for command iocb */
  893. spin_lock_irq(phba->host->host_lock);
  894. iocb = lpfc_sli_get_iocbq(phba);
  895. spin_unlock_irq(phba->host->host_lock);
  896. if (iocb == NULL) {
  897. pring->missbufcnt = cnt;
  898. return cnt;
  899. }
  900. icmd = &iocb->iocb;
  901. /* 2 buffers can be posted per command */
  902. /* Allocate buffer to post */
  903. mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
  904. if (mp1)
  905. mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
  906. &mp1->phys);
  907. if (mp1 == 0 || mp1->virt == 0) {
  908. kfree(mp1);
  909. spin_lock_irq(phba->host->host_lock);
  910. lpfc_sli_release_iocbq(phba, iocb);
  911. spin_unlock_irq(phba->host->host_lock);
  912. pring->missbufcnt = cnt;
  913. return cnt;
  914. }
  915. INIT_LIST_HEAD(&mp1->list);
  916. /* Allocate buffer to post */
  917. if (cnt > 1) {
  918. mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
  919. if (mp2)
  920. mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
  921. &mp2->phys);
  922. if (mp2 == 0 || mp2->virt == 0) {
  923. kfree(mp2);
  924. lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
  925. kfree(mp1);
  926. spin_lock_irq(phba->host->host_lock);
  927. lpfc_sli_release_iocbq(phba, iocb);
  928. spin_unlock_irq(phba->host->host_lock);
  929. pring->missbufcnt = cnt;
  930. return cnt;
  931. }
  932. INIT_LIST_HEAD(&mp2->list);
  933. } else {
  934. mp2 = NULL;
  935. }
  936. icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
  937. icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
  938. icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
  939. icmd->ulpBdeCount = 1;
  940. cnt--;
  941. if (mp2) {
  942. icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
  943. icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
  944. icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
  945. cnt--;
  946. icmd->ulpBdeCount = 2;
  947. }
  948. icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
  949. icmd->ulpLe = 1;
  950. spin_lock_irq(phba->host->host_lock);
  951. if (lpfc_sli_issue_iocb(phba, pring, iocb, 0) == IOCB_ERROR) {
  952. lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
  953. kfree(mp1);
  954. cnt++;
  955. if (mp2) {
  956. lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
  957. kfree(mp2);
  958. cnt++;
  959. }
  960. lpfc_sli_release_iocbq(phba, iocb);
  961. pring->missbufcnt = cnt;
  962. spin_unlock_irq(phba->host->host_lock);
  963. return cnt;
  964. }
  965. spin_unlock_irq(phba->host->host_lock);
  966. lpfc_sli_ringpostbuf_put(phba, pring, mp1);
  967. if (mp2) {
  968. lpfc_sli_ringpostbuf_put(phba, pring, mp2);
  969. }
  970. }
  971. pring->missbufcnt = 0;
  972. return 0;
  973. }
  974. /************************************************************************/
  975. /* */
  976. /* lpfc_post_rcv_buf */
  977. /* This routine post initial rcv buffers to the configured rings */
  978. /* */
  979. /************************************************************************/
  980. static int
  981. lpfc_post_rcv_buf(struct lpfc_hba * phba)
  982. {
  983. struct lpfc_sli *psli = &phba->sli;
  984. /* Ring 0, ELS / CT buffers */
  985. lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0, 1);
  986. /* Ring 2 - FCP no buffers needed */
  987. return 0;
  988. }
  989. #define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
  990. /************************************************************************/
  991. /* */
  992. /* lpfc_sha_init */
  993. /* */
  994. /************************************************************************/
  995. static void
  996. lpfc_sha_init(uint32_t * HashResultPointer)
  997. {
  998. HashResultPointer[0] = 0x67452301;
  999. HashResultPointer[1] = 0xEFCDAB89;
  1000. HashResultPointer[2] = 0x98BADCFE;
  1001. HashResultPointer[3] = 0x10325476;
  1002. HashResultPointer[4] = 0xC3D2E1F0;
  1003. }
  1004. /************************************************************************/
  1005. /* */
  1006. /* lpfc_sha_iterate */
  1007. /* */
  1008. /************************************************************************/
  1009. static void
  1010. lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
  1011. {
  1012. int t;
  1013. uint32_t TEMP;
  1014. uint32_t A, B, C, D, E;
  1015. t = 16;
  1016. do {
  1017. HashWorkingPointer[t] =
  1018. S(1,
  1019. HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
  1020. 8] ^
  1021. HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
  1022. } while (++t <= 79);
  1023. t = 0;
  1024. A = HashResultPointer[0];
  1025. B = HashResultPointer[1];
  1026. C = HashResultPointer[2];
  1027. D = HashResultPointer[3];
  1028. E = HashResultPointer[4];
  1029. do {
  1030. if (t < 20) {
  1031. TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
  1032. } else if (t < 40) {
  1033. TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
  1034. } else if (t < 60) {
  1035. TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
  1036. } else {
  1037. TEMP = (B ^ C ^ D) + 0xCA62C1D6;
  1038. }
  1039. TEMP += S(5, A) + E + HashWorkingPointer[t];
  1040. E = D;
  1041. D = C;
  1042. C = S(30, B);
  1043. B = A;
  1044. A = TEMP;
  1045. } while (++t <= 79);
  1046. HashResultPointer[0] += A;
  1047. HashResultPointer[1] += B;
  1048. HashResultPointer[2] += C;
  1049. HashResultPointer[3] += D;
  1050. HashResultPointer[4] += E;
  1051. }
  1052. /************************************************************************/
  1053. /* */
  1054. /* lpfc_challenge_key */
  1055. /* */
  1056. /************************************************************************/
  1057. static void
  1058. lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
  1059. {
  1060. *HashWorking = (*RandomChallenge ^ *HashWorking);
  1061. }
  1062. /************************************************************************/
  1063. /* */
  1064. /* lpfc_hba_init */
  1065. /* */
  1066. /************************************************************************/
  1067. void
  1068. lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
  1069. {
  1070. int t;
  1071. uint32_t *HashWorking;
  1072. uint32_t *pwwnn = phba->wwnn;
  1073. HashWorking = kmalloc(80 * sizeof(uint32_t), GFP_KERNEL);
  1074. if (!HashWorking)
  1075. return;
  1076. memset(HashWorking, 0, (80 * sizeof(uint32_t)));
  1077. HashWorking[0] = HashWorking[78] = *pwwnn++;
  1078. HashWorking[1] = HashWorking[79] = *pwwnn;
  1079. for (t = 0; t < 7; t++)
  1080. lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
  1081. lpfc_sha_init(hbainit);
  1082. lpfc_sha_iterate(hbainit, HashWorking);
  1083. kfree(HashWorking);
  1084. }
  1085. static void
  1086. lpfc_cleanup(struct lpfc_hba * phba, uint32_t save_bind)
  1087. {
  1088. struct lpfc_nodelist *ndlp, *next_ndlp;
  1089. /* clean up phba - lpfc specific */
  1090. lpfc_can_disctmo(phba);
  1091. list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_nlpunmap_list,
  1092. nlp_listp) {
  1093. lpfc_nlp_remove(phba, ndlp);
  1094. }
  1095. list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_nlpmap_list,
  1096. nlp_listp) {
  1097. lpfc_nlp_remove(phba, ndlp);
  1098. }
  1099. list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_unused_list,
  1100. nlp_listp) {
  1101. lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
  1102. }
  1103. list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_plogi_list,
  1104. nlp_listp) {
  1105. lpfc_nlp_remove(phba, ndlp);
  1106. }
  1107. list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_adisc_list,
  1108. nlp_listp) {
  1109. lpfc_nlp_remove(phba, ndlp);
  1110. }
  1111. list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_reglogin_list,
  1112. nlp_listp) {
  1113. lpfc_nlp_remove(phba, ndlp);
  1114. }
  1115. list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_prli_list,
  1116. nlp_listp) {
  1117. lpfc_nlp_remove(phba, ndlp);
  1118. }
  1119. list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
  1120. nlp_listp) {
  1121. lpfc_nlp_remove(phba, ndlp);
  1122. }
  1123. INIT_LIST_HEAD(&phba->fc_nlpmap_list);
  1124. INIT_LIST_HEAD(&phba->fc_nlpunmap_list);
  1125. INIT_LIST_HEAD(&phba->fc_unused_list);
  1126. INIT_LIST_HEAD(&phba->fc_plogi_list);
  1127. INIT_LIST_HEAD(&phba->fc_adisc_list);
  1128. INIT_LIST_HEAD(&phba->fc_reglogin_list);
  1129. INIT_LIST_HEAD(&phba->fc_prli_list);
  1130. INIT_LIST_HEAD(&phba->fc_npr_list);
  1131. phba->fc_map_cnt = 0;
  1132. phba->fc_unmap_cnt = 0;
  1133. phba->fc_plogi_cnt = 0;
  1134. phba->fc_adisc_cnt = 0;
  1135. phba->fc_reglogin_cnt = 0;
  1136. phba->fc_prli_cnt = 0;
  1137. phba->fc_npr_cnt = 0;
  1138. phba->fc_unused_cnt= 0;
  1139. return;
  1140. }
  1141. static void
  1142. lpfc_establish_link_tmo(unsigned long ptr)
  1143. {
  1144. struct lpfc_hba *phba = (struct lpfc_hba *)ptr;
  1145. unsigned long iflag;
  1146. /* Re-establishing Link, timer expired */
  1147. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  1148. "%d:1300 Re-establishing Link, timer expired "
  1149. "Data: x%x x%x\n",
  1150. phba->brd_no, phba->fc_flag, phba->hba_state);
  1151. spin_lock_irqsave(phba->host->host_lock, iflag);
  1152. phba->fc_flag &= ~FC_ESTABLISH_LINK;
  1153. spin_unlock_irqrestore(phba->host->host_lock, iflag);
  1154. }
  1155. static int
  1156. lpfc_stop_timer(struct lpfc_hba * phba)
  1157. {
  1158. struct lpfc_sli *psli = &phba->sli;
  1159. /* Instead of a timer, this has been converted to a
  1160. * deferred procedding list.
  1161. */
  1162. while (!list_empty(&phba->freebufList)) {
  1163. struct lpfc_dmabuf *mp = NULL;
  1164. list_remove_head((&phba->freebufList), mp,
  1165. struct lpfc_dmabuf, list);
  1166. if (mp) {
  1167. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1168. kfree(mp);
  1169. }
  1170. }
  1171. del_timer_sync(&phba->fcp_poll_timer);
  1172. del_timer_sync(&phba->fc_estabtmo);
  1173. del_timer_sync(&phba->fc_disctmo);
  1174. del_timer_sync(&phba->fc_fdmitmo);
  1175. del_timer_sync(&phba->els_tmofunc);
  1176. psli = &phba->sli;
  1177. del_timer_sync(&psli->mbox_tmo);
  1178. return(1);
  1179. }
  1180. int
  1181. lpfc_online(struct lpfc_hba * phba)
  1182. {
  1183. if (!phba)
  1184. return 0;
  1185. if (!(phba->fc_flag & FC_OFFLINE_MODE))
  1186. return 0;
  1187. lpfc_printf_log(phba,
  1188. KERN_WARNING,
  1189. LOG_INIT,
  1190. "%d:0458 Bring Adapter online\n",
  1191. phba->brd_no);
  1192. if (!lpfc_sli_queue_setup(phba))
  1193. return 1;
  1194. if (lpfc_sli_hba_setup(phba)) /* Initialize the HBA */
  1195. return 1;
  1196. spin_lock_irq(phba->host->host_lock);
  1197. phba->fc_flag &= ~FC_OFFLINE_MODE;
  1198. spin_unlock_irq(phba->host->host_lock);
  1199. return 0;
  1200. }
  1201. int
  1202. lpfc_offline(struct lpfc_hba * phba)
  1203. {
  1204. struct lpfc_sli_ring *pring;
  1205. struct lpfc_sli *psli;
  1206. unsigned long iflag;
  1207. int i;
  1208. int cnt = 0;
  1209. if (!phba)
  1210. return 0;
  1211. if (phba->fc_flag & FC_OFFLINE_MODE)
  1212. return 0;
  1213. psli = &phba->sli;
  1214. lpfc_linkdown(phba);
  1215. for (i = 0; i < psli->num_rings; i++) {
  1216. pring = &psli->ring[i];
  1217. /* The linkdown event takes 30 seconds to timeout. */
  1218. while (pring->txcmplq_cnt) {
  1219. mdelay(10);
  1220. if (cnt++ > 3000) {
  1221. lpfc_printf_log(phba,
  1222. KERN_WARNING, LOG_INIT,
  1223. "%d:0466 Outstanding IO when "
  1224. "bringing Adapter offline\n",
  1225. phba->brd_no);
  1226. break;
  1227. }
  1228. }
  1229. }
  1230. /* stop all timers associated with this hba */
  1231. lpfc_stop_timer(phba);
  1232. phba->work_hba_events = 0;
  1233. lpfc_printf_log(phba,
  1234. KERN_WARNING,
  1235. LOG_INIT,
  1236. "%d:0460 Bring Adapter offline\n",
  1237. phba->brd_no);
  1238. /* Bring down the SLI Layer and cleanup. The HBA is offline
  1239. now. */
  1240. lpfc_sli_hba_down(phba);
  1241. lpfc_cleanup(phba, 1);
  1242. spin_lock_irqsave(phba->host->host_lock, iflag);
  1243. phba->fc_flag |= FC_OFFLINE_MODE;
  1244. spin_unlock_irqrestore(phba->host->host_lock, iflag);
  1245. return 0;
  1246. }
  1247. /******************************************************************************
  1248. * Function name: lpfc_scsi_free
  1249. *
  1250. * Description: Called from lpfc_pci_remove_one free internal driver resources
  1251. *
  1252. ******************************************************************************/
  1253. static int
  1254. lpfc_scsi_free(struct lpfc_hba * phba)
  1255. {
  1256. struct lpfc_scsi_buf *sb, *sb_next;
  1257. struct lpfc_iocbq *io, *io_next;
  1258. spin_lock_irq(phba->host->host_lock);
  1259. /* Release all the lpfc_scsi_bufs maintained by this host. */
  1260. list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list, list) {
  1261. list_del(&sb->list);
  1262. pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data,
  1263. sb->dma_handle);
  1264. kfree(sb);
  1265. phba->total_scsi_bufs--;
  1266. }
  1267. /* Release all the lpfc_iocbq entries maintained by this host. */
  1268. list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) {
  1269. list_del(&io->list);
  1270. kfree(io);
  1271. phba->total_iocbq_bufs--;
  1272. }
  1273. spin_unlock_irq(phba->host->host_lock);
  1274. return 0;
  1275. }
  1276. static int __devinit
  1277. lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
  1278. {
  1279. struct Scsi_Host *host;
  1280. struct lpfc_hba *phba;
  1281. struct lpfc_sli *psli;
  1282. struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
  1283. unsigned long bar0map_len, bar2map_len;
  1284. int error = -ENODEV, retval;
  1285. int i;
  1286. uint16_t iotag;
  1287. if (pci_enable_device(pdev))
  1288. goto out;
  1289. if (pci_request_regions(pdev, LPFC_DRIVER_NAME))
  1290. goto out_disable_device;
  1291. host = scsi_host_alloc(&lpfc_template, sizeof (struct lpfc_hba));
  1292. if (!host)
  1293. goto out_release_regions;
  1294. phba = (struct lpfc_hba*)host->hostdata;
  1295. memset(phba, 0, sizeof (struct lpfc_hba));
  1296. phba->host = host;
  1297. phba->fc_flag |= FC_LOADING;
  1298. phba->pcidev = pdev;
  1299. /* Assign an unused board number */
  1300. if (!idr_pre_get(&lpfc_hba_index, GFP_KERNEL))
  1301. goto out_put_host;
  1302. error = idr_get_new(&lpfc_hba_index, NULL, &phba->brd_no);
  1303. if (error)
  1304. goto out_put_host;
  1305. host->unique_id = phba->brd_no;
  1306. INIT_LIST_HEAD(&phba->ctrspbuflist);
  1307. INIT_LIST_HEAD(&phba->rnidrspbuflist);
  1308. INIT_LIST_HEAD(&phba->freebufList);
  1309. /* Initialize timers used by driver */
  1310. init_timer(&phba->fc_estabtmo);
  1311. phba->fc_estabtmo.function = lpfc_establish_link_tmo;
  1312. phba->fc_estabtmo.data = (unsigned long)phba;
  1313. init_timer(&phba->fc_disctmo);
  1314. phba->fc_disctmo.function = lpfc_disc_timeout;
  1315. phba->fc_disctmo.data = (unsigned long)phba;
  1316. init_timer(&phba->fc_fdmitmo);
  1317. phba->fc_fdmitmo.function = lpfc_fdmi_tmo;
  1318. phba->fc_fdmitmo.data = (unsigned long)phba;
  1319. init_timer(&phba->els_tmofunc);
  1320. phba->els_tmofunc.function = lpfc_els_timeout;
  1321. phba->els_tmofunc.data = (unsigned long)phba;
  1322. psli = &phba->sli;
  1323. init_timer(&psli->mbox_tmo);
  1324. psli->mbox_tmo.function = lpfc_mbox_timeout;
  1325. psli->mbox_tmo.data = (unsigned long)phba;
  1326. init_timer(&phba->fcp_poll_timer);
  1327. phba->fcp_poll_timer.function = lpfc_poll_timeout;
  1328. phba->fcp_poll_timer.data = (unsigned long)phba;
  1329. /*
  1330. * Get all the module params for configuring this host and then
  1331. * establish the host parameters.
  1332. */
  1333. lpfc_get_cfgparam(phba);
  1334. host->max_id = LPFC_MAX_TARGET;
  1335. host->max_lun = phba->cfg_max_luns;
  1336. host->this_id = -1;
  1337. /* Initialize all internally managed lists. */
  1338. INIT_LIST_HEAD(&phba->fc_nlpmap_list);
  1339. INIT_LIST_HEAD(&phba->fc_nlpunmap_list);
  1340. INIT_LIST_HEAD(&phba->fc_unused_list);
  1341. INIT_LIST_HEAD(&phba->fc_plogi_list);
  1342. INIT_LIST_HEAD(&phba->fc_adisc_list);
  1343. INIT_LIST_HEAD(&phba->fc_reglogin_list);
  1344. INIT_LIST_HEAD(&phba->fc_prli_list);
  1345. INIT_LIST_HEAD(&phba->fc_npr_list);
  1346. pci_set_master(pdev);
  1347. retval = pci_set_mwi(pdev);
  1348. if (retval)
  1349. dev_printk(KERN_WARNING, &pdev->dev,
  1350. "Warning: pci_set_mwi returned %d\n", retval);
  1351. if (pci_set_dma_mask(phba->pcidev, DMA_64BIT_MASK) != 0)
  1352. if (pci_set_dma_mask(phba->pcidev, DMA_32BIT_MASK) != 0)
  1353. goto out_idr_remove;
  1354. /*
  1355. * Get the bus address of Bar0 and Bar2 and the number of bytes
  1356. * required by each mapping.
  1357. */
  1358. phba->pci_bar0_map = pci_resource_start(phba->pcidev, 0);
  1359. bar0map_len = pci_resource_len(phba->pcidev, 0);
  1360. phba->pci_bar2_map = pci_resource_start(phba->pcidev, 2);
  1361. bar2map_len = pci_resource_len(phba->pcidev, 2);
  1362. /* Map HBA SLIM to a kernel virtual address. */
  1363. phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
  1364. if (!phba->slim_memmap_p) {
  1365. error = -ENODEV;
  1366. dev_printk(KERN_ERR, &pdev->dev,
  1367. "ioremap failed for SLIM memory.\n");
  1368. goto out_idr_remove;
  1369. }
  1370. /* Map HBA Control Registers to a kernel virtual address. */
  1371. phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
  1372. if (!phba->ctrl_regs_memmap_p) {
  1373. error = -ENODEV;
  1374. dev_printk(KERN_ERR, &pdev->dev,
  1375. "ioremap failed for HBA control registers.\n");
  1376. goto out_iounmap_slim;
  1377. }
  1378. /* Allocate memory for SLI-2 structures */
  1379. phba->slim2p = dma_alloc_coherent(&phba->pcidev->dev, SLI2_SLIM_SIZE,
  1380. &phba->slim2p_mapping, GFP_KERNEL);
  1381. if (!phba->slim2p)
  1382. goto out_iounmap;
  1383. memset(phba->slim2p, 0, SLI2_SLIM_SIZE);
  1384. /* Initialize the SLI Layer to run with lpfc HBAs. */
  1385. lpfc_sli_setup(phba);
  1386. lpfc_sli_queue_setup(phba);
  1387. error = lpfc_mem_alloc(phba);
  1388. if (error)
  1389. goto out_free_slim;
  1390. /* Initialize and populate the iocb list per host. */
  1391. INIT_LIST_HEAD(&phba->lpfc_iocb_list);
  1392. for (i = 0; i < LPFC_IOCB_LIST_CNT; i++) {
  1393. iocbq_entry = kmalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
  1394. if (iocbq_entry == NULL) {
  1395. printk(KERN_ERR "%s: only allocated %d iocbs of "
  1396. "expected %d count. Unloading driver.\n",
  1397. __FUNCTION__, i, LPFC_IOCB_LIST_CNT);
  1398. error = -ENOMEM;
  1399. goto out_free_iocbq;
  1400. }
  1401. memset(iocbq_entry, 0, sizeof(struct lpfc_iocbq));
  1402. iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
  1403. if (iotag == 0) {
  1404. kfree (iocbq_entry);
  1405. printk(KERN_ERR "%s: failed to allocate IOTAG. "
  1406. "Unloading driver.\n",
  1407. __FUNCTION__);
  1408. error = -ENOMEM;
  1409. goto out_free_iocbq;
  1410. }
  1411. spin_lock_irq(phba->host->host_lock);
  1412. list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
  1413. phba->total_iocbq_bufs++;
  1414. spin_unlock_irq(phba->host->host_lock);
  1415. }
  1416. /* Initialize HBA structure */
  1417. phba->fc_edtov = FF_DEF_EDTOV;
  1418. phba->fc_ratov = FF_DEF_RATOV;
  1419. phba->fc_altov = FF_DEF_ALTOV;
  1420. phba->fc_arbtov = FF_DEF_ARBTOV;
  1421. INIT_LIST_HEAD(&phba->work_list);
  1422. phba->work_ha_mask = (HA_ERATT|HA_MBATT|HA_LATT);
  1423. phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
  1424. /* Startup the kernel thread for this host adapter. */
  1425. phba->worker_thread = kthread_run(lpfc_do_work, phba,
  1426. "lpfc_worker_%d", phba->brd_no);
  1427. if (IS_ERR(phba->worker_thread)) {
  1428. error = PTR_ERR(phba->worker_thread);
  1429. goto out_free_iocbq;
  1430. }
  1431. /* We can rely on a queue depth attribute only after SLI HBA setup */
  1432. host->can_queue = phba->cfg_hba_queue_depth - 10;
  1433. /* Tell the midlayer we support 16 byte commands */
  1434. host->max_cmd_len = 16;
  1435. /* Initialize the list of scsi buffers used by driver for scsi IO. */
  1436. spin_lock_init(&phba->scsi_buf_list_lock);
  1437. INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list);
  1438. host->transportt = lpfc_transport_template;
  1439. pci_set_drvdata(pdev, host);
  1440. error = scsi_add_host(host, &pdev->dev);
  1441. if (error)
  1442. goto out_kthread_stop;
  1443. error = lpfc_alloc_sysfs_attr(phba);
  1444. if (error)
  1445. goto out_remove_host;
  1446. error = request_irq(phba->pcidev->irq, lpfc_intr_handler, IRQF_SHARED,
  1447. LPFC_DRIVER_NAME, phba);
  1448. if (error) {
  1449. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1450. "%d:0451 Enable interrupt handler failed\n",
  1451. phba->brd_no);
  1452. goto out_free_sysfs_attr;
  1453. }
  1454. phba->MBslimaddr = phba->slim_memmap_p;
  1455. phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
  1456. phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
  1457. phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
  1458. phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
  1459. error = lpfc_sli_hba_setup(phba);
  1460. if (error) {
  1461. error = -ENODEV;
  1462. goto out_free_irq;
  1463. }
  1464. lpfc_discovery_wait(phba);
  1465. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  1466. spin_lock_irq(phba->host->host_lock);
  1467. lpfc_poll_start_timer(phba);
  1468. spin_unlock_irq(phba->host->host_lock);
  1469. }
  1470. /*
  1471. * set fixed host attributes
  1472. * Must done after lpfc_sli_hba_setup()
  1473. */
  1474. fc_host_node_name(host) = wwn_to_u64(phba->fc_nodename.u.wwn);
  1475. fc_host_port_name(host) = wwn_to_u64(phba->fc_portname.u.wwn);
  1476. fc_host_supported_classes(host) = FC_COS_CLASS3;
  1477. memset(fc_host_supported_fc4s(host), 0,
  1478. sizeof(fc_host_supported_fc4s(host)));
  1479. fc_host_supported_fc4s(host)[2] = 1;
  1480. fc_host_supported_fc4s(host)[7] = 1;
  1481. lpfc_get_hba_sym_node_name(phba, fc_host_symbolic_name(host));
  1482. fc_host_supported_speeds(host) = 0;
  1483. if (phba->lmt & LMT_10Gb)
  1484. fc_host_supported_speeds(host) |= FC_PORTSPEED_10GBIT;
  1485. if (phba->lmt & LMT_4Gb)
  1486. fc_host_supported_speeds(host) |= FC_PORTSPEED_4GBIT;
  1487. if (phba->lmt & LMT_2Gb)
  1488. fc_host_supported_speeds(host) |= FC_PORTSPEED_2GBIT;
  1489. if (phba->lmt & LMT_1Gb)
  1490. fc_host_supported_speeds(host) |= FC_PORTSPEED_1GBIT;
  1491. fc_host_maxframe_size(host) =
  1492. ((((uint32_t) phba->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
  1493. (uint32_t) phba->fc_sparam.cmn.bbRcvSizeLsb);
  1494. /* This value is also unchanging */
  1495. memset(fc_host_active_fc4s(host), 0,
  1496. sizeof(fc_host_active_fc4s(host)));
  1497. fc_host_active_fc4s(host)[2] = 1;
  1498. fc_host_active_fc4s(host)[7] = 1;
  1499. spin_lock_irq(phba->host->host_lock);
  1500. phba->fc_flag &= ~FC_LOADING;
  1501. spin_unlock_irq(phba->host->host_lock);
  1502. return 0;
  1503. out_free_irq:
  1504. lpfc_stop_timer(phba);
  1505. phba->work_hba_events = 0;
  1506. free_irq(phba->pcidev->irq, phba);
  1507. out_free_sysfs_attr:
  1508. lpfc_free_sysfs_attr(phba);
  1509. out_remove_host:
  1510. fc_remove_host(phba->host);
  1511. scsi_remove_host(phba->host);
  1512. out_kthread_stop:
  1513. kthread_stop(phba->worker_thread);
  1514. out_free_iocbq:
  1515. list_for_each_entry_safe(iocbq_entry, iocbq_next,
  1516. &phba->lpfc_iocb_list, list) {
  1517. spin_lock_irq(phba->host->host_lock);
  1518. kfree(iocbq_entry);
  1519. phba->total_iocbq_bufs--;
  1520. spin_unlock_irq(phba->host->host_lock);
  1521. }
  1522. lpfc_mem_free(phba);
  1523. out_free_slim:
  1524. dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, phba->slim2p,
  1525. phba->slim2p_mapping);
  1526. out_iounmap:
  1527. iounmap(phba->ctrl_regs_memmap_p);
  1528. out_iounmap_slim:
  1529. iounmap(phba->slim_memmap_p);
  1530. out_idr_remove:
  1531. idr_remove(&lpfc_hba_index, phba->brd_no);
  1532. out_put_host:
  1533. phba->host = NULL;
  1534. scsi_host_put(host);
  1535. out_release_regions:
  1536. pci_release_regions(pdev);
  1537. out_disable_device:
  1538. pci_disable_device(pdev);
  1539. out:
  1540. pci_set_drvdata(pdev, NULL);
  1541. return error;
  1542. }
  1543. static void __devexit
  1544. lpfc_pci_remove_one(struct pci_dev *pdev)
  1545. {
  1546. struct Scsi_Host *host = pci_get_drvdata(pdev);
  1547. struct lpfc_hba *phba = (struct lpfc_hba *)host->hostdata;
  1548. unsigned long iflag;
  1549. lpfc_free_sysfs_attr(phba);
  1550. spin_lock_irqsave(phba->host->host_lock, iflag);
  1551. phba->fc_flag |= FC_UNLOADING;
  1552. spin_unlock_irqrestore(phba->host->host_lock, iflag);
  1553. fc_remove_host(phba->host);
  1554. scsi_remove_host(phba->host);
  1555. kthread_stop(phba->worker_thread);
  1556. /*
  1557. * Bring down the SLI Layer. This step disable all interrupts,
  1558. * clears the rings, discards all mailbox commands, and resets
  1559. * the HBA.
  1560. */
  1561. lpfc_sli_hba_down(phba);
  1562. lpfc_sli_brdrestart(phba);
  1563. /* Release the irq reservation */
  1564. free_irq(phba->pcidev->irq, phba);
  1565. lpfc_cleanup(phba, 0);
  1566. lpfc_stop_timer(phba);
  1567. phba->work_hba_events = 0;
  1568. /*
  1569. * Call scsi_free before mem_free since scsi bufs are released to their
  1570. * corresponding pools here.
  1571. */
  1572. lpfc_scsi_free(phba);
  1573. lpfc_mem_free(phba);
  1574. /* Free resources associated with SLI2 interface */
  1575. dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
  1576. phba->slim2p, phba->slim2p_mapping);
  1577. /* unmap adapter SLIM and Control Registers */
  1578. iounmap(phba->ctrl_regs_memmap_p);
  1579. iounmap(phba->slim_memmap_p);
  1580. pci_release_regions(phba->pcidev);
  1581. pci_disable_device(phba->pcidev);
  1582. idr_remove(&lpfc_hba_index, phba->brd_no);
  1583. scsi_host_put(phba->host);
  1584. pci_set_drvdata(pdev, NULL);
  1585. }
  1586. static struct pci_device_id lpfc_id_table[] = {
  1587. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER,
  1588. PCI_ANY_ID, PCI_ANY_ID, },
  1589. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY,
  1590. PCI_ANY_ID, PCI_ANY_ID, },
  1591. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR,
  1592. PCI_ANY_ID, PCI_ANY_ID, },
  1593. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS,
  1594. PCI_ANY_ID, PCI_ANY_ID, },
  1595. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR,
  1596. PCI_ANY_ID, PCI_ANY_ID, },
  1597. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY,
  1598. PCI_ANY_ID, PCI_ANY_ID, },
  1599. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY,
  1600. PCI_ANY_ID, PCI_ANY_ID, },
  1601. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY,
  1602. PCI_ANY_ID, PCI_ANY_ID, },
  1603. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY,
  1604. PCI_ANY_ID, PCI_ANY_ID, },
  1605. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE,
  1606. PCI_ANY_ID, PCI_ANY_ID, },
  1607. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP,
  1608. PCI_ANY_ID, PCI_ANY_ID, },
  1609. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP,
  1610. PCI_ANY_ID, PCI_ANY_ID, },
  1611. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS,
  1612. PCI_ANY_ID, PCI_ANY_ID, },
  1613. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP,
  1614. PCI_ANY_ID, PCI_ANY_ID, },
  1615. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP,
  1616. PCI_ANY_ID, PCI_ANY_ID, },
  1617. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID,
  1618. PCI_ANY_ID, PCI_ANY_ID, },
  1619. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB,
  1620. PCI_ANY_ID, PCI_ANY_ID, },
  1621. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR,
  1622. PCI_ANY_ID, PCI_ANY_ID, },
  1623. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP,
  1624. PCI_ANY_ID, PCI_ANY_ID, },
  1625. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP,
  1626. PCI_ANY_ID, PCI_ANY_ID, },
  1627. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID,
  1628. PCI_ANY_ID, PCI_ANY_ID, },
  1629. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB,
  1630. PCI_ANY_ID, PCI_ANY_ID, },
  1631. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY,
  1632. PCI_ANY_ID, PCI_ANY_ID, },
  1633. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101,
  1634. PCI_ANY_ID, PCI_ANY_ID, },
  1635. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S,
  1636. PCI_ANY_ID, PCI_ANY_ID, },
  1637. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S,
  1638. PCI_ANY_ID, PCI_ANY_ID, },
  1639. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S,
  1640. PCI_ANY_ID, PCI_ANY_ID, },
  1641. { 0 }
  1642. };
  1643. MODULE_DEVICE_TABLE(pci, lpfc_id_table);
  1644. static struct pci_driver lpfc_driver = {
  1645. .name = LPFC_DRIVER_NAME,
  1646. .id_table = lpfc_id_table,
  1647. .probe = lpfc_pci_probe_one,
  1648. .remove = __devexit_p(lpfc_pci_remove_one),
  1649. };
  1650. static int __init
  1651. lpfc_init(void)
  1652. {
  1653. int error = 0;
  1654. printk(LPFC_MODULE_DESC "\n");
  1655. printk(LPFC_COPYRIGHT "\n");
  1656. lpfc_transport_template =
  1657. fc_attach_transport(&lpfc_transport_functions);
  1658. if (!lpfc_transport_template)
  1659. return -ENOMEM;
  1660. error = pci_register_driver(&lpfc_driver);
  1661. if (error)
  1662. fc_release_transport(lpfc_transport_template);
  1663. return error;
  1664. }
  1665. static void __exit
  1666. lpfc_exit(void)
  1667. {
  1668. pci_unregister_driver(&lpfc_driver);
  1669. fc_release_transport(lpfc_transport_template);
  1670. }
  1671. module_init(lpfc_init);
  1672. module_exit(lpfc_exit);
  1673. MODULE_LICENSE("GPL");
  1674. MODULE_DESCRIPTION(LPFC_MODULE_DESC);
  1675. MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com");
  1676. MODULE_VERSION("0:" LPFC_DRIVER_VERSION);