lpfc_init.c 54 KB

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