lpfc_init.c 54 KB

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