lpfc_init.c 55 KB

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