lpfc_init.c 54 KB

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