lpfc_init.c 69 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2007 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 <linux/ctype.h>
  30. #include <scsi/scsi.h>
  31. #include <scsi/scsi_device.h>
  32. #include <scsi/scsi_host.h>
  33. #include <scsi/scsi_transport_fc.h>
  34. #include "lpfc_hw.h"
  35. #include "lpfc_sli.h"
  36. #include "lpfc_disc.h"
  37. #include "lpfc_scsi.h"
  38. #include "lpfc.h"
  39. #include "lpfc_logmsg.h"
  40. #include "lpfc_crtn.h"
  41. #include "lpfc_vport.h"
  42. #include "lpfc_version.h"
  43. static int lpfc_parse_vpd(struct lpfc_hba *, uint8_t *, int);
  44. static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *);
  45. static int lpfc_post_rcv_buf(struct lpfc_hba *);
  46. static struct scsi_transport_template *lpfc_transport_template = NULL;
  47. static struct scsi_transport_template *lpfc_vport_transport_template = NULL;
  48. static DEFINE_IDR(lpfc_hba_index);
  49. /************************************************************************/
  50. /* */
  51. /* lpfc_config_port_prep */
  52. /* This routine will do LPFC initialization prior to the */
  53. /* CONFIG_PORT mailbox command. This will be initialized */
  54. /* as a SLI layer callback routine. */
  55. /* This routine returns 0 on success or -ERESTART if it wants */
  56. /* the SLI layer to reset the HBA and try again. Any */
  57. /* other return value indicates an error. */
  58. /* */
  59. /************************************************************************/
  60. int
  61. lpfc_config_port_prep(struct lpfc_hba *phba)
  62. {
  63. lpfc_vpd_t *vp = &phba->vpd;
  64. int i = 0, rc;
  65. LPFC_MBOXQ_t *pmb;
  66. MAILBOX_t *mb;
  67. char *lpfc_vpd_data = NULL;
  68. uint16_t offset = 0;
  69. static char licensed[56] =
  70. "key unlock for use with gnu public licensed code only\0";
  71. static int init_key = 1;
  72. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  73. if (!pmb) {
  74. phba->link_state = LPFC_HBA_ERROR;
  75. return -ENOMEM;
  76. }
  77. mb = &pmb->mb;
  78. phba->link_state = LPFC_INIT_MBX_CMDS;
  79. if (lpfc_is_LC_HBA(phba->pcidev->device)) {
  80. if (init_key) {
  81. uint32_t *ptext = (uint32_t *) licensed;
  82. for (i = 0; i < 56; i += sizeof (uint32_t), ptext++)
  83. *ptext = cpu_to_be32(*ptext);
  84. init_key = 0;
  85. }
  86. lpfc_read_nv(phba, pmb);
  87. memset((char*)mb->un.varRDnvp.rsvd3, 0,
  88. sizeof (mb->un.varRDnvp.rsvd3));
  89. memcpy((char*)mb->un.varRDnvp.rsvd3, licensed,
  90. sizeof (licensed));
  91. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  92. if (rc != MBX_SUCCESS) {
  93. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  94. "0324 Config Port initialization "
  95. "error, mbxCmd x%x READ_NVPARM, "
  96. "mbxStatus x%x\n",
  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(phba->wwnn));
  103. memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname,
  104. sizeof(phba->wwpn));
  105. }
  106. phba->sli3_options = 0x0;
  107. /* Setup and issue mailbox READ REV command */
  108. lpfc_read_rev(phba, pmb);
  109. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  110. if (rc != MBX_SUCCESS) {
  111. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  112. "0439 Adapter failed to init, mbxCmd x%x "
  113. "READ_REV, mbxStatus x%x\n",
  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. "0440 Adapter failed to init, READ_REV has "
  126. "missing revision information.\n");
  127. mempool_free(pmb, phba->mbox_mem_pool);
  128. return -ERESTART;
  129. }
  130. if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp)
  131. return -EINVAL;
  132. /* Save information as VPD data */
  133. vp->rev.rBit = 1;
  134. memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t));
  135. vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev;
  136. memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16);
  137. vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev;
  138. memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16);
  139. vp->rev.biuRev = mb->un.varRdRev.biuRev;
  140. vp->rev.smRev = mb->un.varRdRev.smRev;
  141. vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev;
  142. vp->rev.endecRev = mb->un.varRdRev.endecRev;
  143. vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh;
  144. vp->rev.fcphLow = mb->un.varRdRev.fcphLow;
  145. vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh;
  146. vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow;
  147. vp->rev.postKernRev = mb->un.varRdRev.postKernRev;
  148. vp->rev.opFwRev = mb->un.varRdRev.opFwRev;
  149. /* If the sli feature level is less then 9, we must
  150. * tear down all RPIs and VPIs on link down if NPIV
  151. * is enabled.
  152. */
  153. if (vp->rev.feaLevelHigh < 9)
  154. phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN;
  155. if (lpfc_is_LC_HBA(phba->pcidev->device))
  156. memcpy(phba->RandomData, (char *)&mb->un.varWords[24],
  157. sizeof (phba->RandomData));
  158. /* Get adapter VPD information */
  159. pmb->context2 = kmalloc(DMP_RSP_SIZE, GFP_KERNEL);
  160. if (!pmb->context2)
  161. goto out_free_mbox;
  162. lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL);
  163. if (!lpfc_vpd_data)
  164. goto out_free_context2;
  165. do {
  166. lpfc_dump_mem(phba, pmb, offset);
  167. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  168. if (rc != MBX_SUCCESS) {
  169. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  170. "0441 VPD not present on adapter, "
  171. "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
  172. mb->mbxCommand, mb->mbxStatus);
  173. mb->un.varDmp.word_cnt = 0;
  174. }
  175. if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset)
  176. mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset;
  177. lpfc_sli_pcimem_bcopy(pmb->context2, lpfc_vpd_data + offset,
  178. mb->un.varDmp.word_cnt);
  179. offset += mb->un.varDmp.word_cnt;
  180. } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE);
  181. lpfc_parse_vpd(phba, lpfc_vpd_data, offset);
  182. kfree(lpfc_vpd_data);
  183. out_free_context2:
  184. kfree(pmb->context2);
  185. out_free_mbox:
  186. mempool_free(pmb, phba->mbox_mem_pool);
  187. return 0;
  188. }
  189. /* Completion handler for config async event mailbox command. */
  190. static void
  191. lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
  192. {
  193. if (pmboxq->mb.mbxStatus == MBX_SUCCESS)
  194. phba->temp_sensor_support = 1;
  195. else
  196. phba->temp_sensor_support = 0;
  197. mempool_free(pmboxq, phba->mbox_mem_pool);
  198. return;
  199. }
  200. /************************************************************************/
  201. /* */
  202. /* lpfc_config_port_post */
  203. /* This routine will do LPFC initialization after the */
  204. /* CONFIG_PORT mailbox command. This will be initialized */
  205. /* as a SLI layer callback routine. */
  206. /* This routine returns 0 on success. Any other return value */
  207. /* indicates an error. */
  208. /* */
  209. /************************************************************************/
  210. int
  211. lpfc_config_port_post(struct lpfc_hba *phba)
  212. {
  213. struct lpfc_vport *vport = phba->pport;
  214. LPFC_MBOXQ_t *pmb;
  215. MAILBOX_t *mb;
  216. struct lpfc_dmabuf *mp;
  217. struct lpfc_sli *psli = &phba->sli;
  218. uint32_t status, timeout;
  219. int i, j;
  220. int rc;
  221. spin_lock_irq(&phba->hbalock);
  222. /*
  223. * If the Config port completed correctly the HBA is not
  224. * over heated any more.
  225. */
  226. if (phba->over_temp_state == HBA_OVER_TEMP)
  227. phba->over_temp_state = HBA_NORMAL_TEMP;
  228. spin_unlock_irq(&phba->hbalock);
  229. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  230. if (!pmb) {
  231. phba->link_state = LPFC_HBA_ERROR;
  232. return -ENOMEM;
  233. }
  234. mb = &pmb->mb;
  235. /* Get login parameters for NID. */
  236. lpfc_read_sparam(phba, pmb, 0);
  237. pmb->vport = vport;
  238. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  239. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  240. "0448 Adapter failed init, mbxCmd x%x "
  241. "READ_SPARM mbxStatus x%x\n",
  242. mb->mbxCommand, mb->mbxStatus);
  243. phba->link_state = LPFC_HBA_ERROR;
  244. mp = (struct lpfc_dmabuf *) pmb->context1;
  245. mempool_free( pmb, phba->mbox_mem_pool);
  246. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  247. kfree(mp);
  248. return -EIO;
  249. }
  250. mp = (struct lpfc_dmabuf *) pmb->context1;
  251. memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm));
  252. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  253. kfree(mp);
  254. pmb->context1 = NULL;
  255. if (phba->cfg_soft_wwnn)
  256. u64_to_wwn(phba->cfg_soft_wwnn,
  257. vport->fc_sparam.nodeName.u.wwn);
  258. if (phba->cfg_soft_wwpn)
  259. u64_to_wwn(phba->cfg_soft_wwpn,
  260. vport->fc_sparam.portName.u.wwn);
  261. memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
  262. sizeof (struct lpfc_name));
  263. memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
  264. sizeof (struct lpfc_name));
  265. /* If no serial number in VPD data, use low 6 bytes of WWNN */
  266. /* This should be consolidated into parse_vpd ? - mr */
  267. if (phba->SerialNumber[0] == 0) {
  268. uint8_t *outptr;
  269. outptr = &vport->fc_nodename.u.s.IEEE[0];
  270. for (i = 0; i < 12; i++) {
  271. status = *outptr++;
  272. j = ((status & 0xf0) >> 4);
  273. if (j <= 9)
  274. phba->SerialNumber[i] =
  275. (char)((uint8_t) 0x30 + (uint8_t) j);
  276. else
  277. phba->SerialNumber[i] =
  278. (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
  279. i++;
  280. j = (status & 0xf);
  281. if (j <= 9)
  282. phba->SerialNumber[i] =
  283. (char)((uint8_t) 0x30 + (uint8_t) j);
  284. else
  285. phba->SerialNumber[i] =
  286. (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
  287. }
  288. }
  289. lpfc_read_config(phba, pmb);
  290. pmb->vport = vport;
  291. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  292. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  293. "0453 Adapter failed to init, mbxCmd x%x "
  294. "READ_CONFIG, mbxStatus x%x\n",
  295. mb->mbxCommand, mb->mbxStatus);
  296. phba->link_state = LPFC_HBA_ERROR;
  297. mempool_free( pmb, phba->mbox_mem_pool);
  298. return -EIO;
  299. }
  300. /* Reset the DFT_HBA_Q_DEPTH to the max xri */
  301. if (phba->cfg_hba_queue_depth > (mb->un.varRdConfig.max_xri+1))
  302. phba->cfg_hba_queue_depth =
  303. mb->un.varRdConfig.max_xri + 1;
  304. phba->lmt = mb->un.varRdConfig.lmt;
  305. /* Get the default values for Model Name and Description */
  306. lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
  307. if ((phba->cfg_link_speed > LINK_SPEED_10G)
  308. || ((phba->cfg_link_speed == LINK_SPEED_1G)
  309. && !(phba->lmt & LMT_1Gb))
  310. || ((phba->cfg_link_speed == LINK_SPEED_2G)
  311. && !(phba->lmt & LMT_2Gb))
  312. || ((phba->cfg_link_speed == LINK_SPEED_4G)
  313. && !(phba->lmt & LMT_4Gb))
  314. || ((phba->cfg_link_speed == LINK_SPEED_8G)
  315. && !(phba->lmt & LMT_8Gb))
  316. || ((phba->cfg_link_speed == LINK_SPEED_10G)
  317. && !(phba->lmt & LMT_10Gb))) {
  318. /* Reset link speed to auto */
  319. lpfc_printf_log(phba, KERN_WARNING, LOG_LINK_EVENT,
  320. "1302 Invalid speed for this board: "
  321. "Reset link speed to auto: x%x\n",
  322. phba->cfg_link_speed);
  323. phba->cfg_link_speed = LINK_SPEED_AUTO;
  324. }
  325. phba->link_state = LPFC_LINK_DOWN;
  326. /* Only process IOCBs on ELS ring till hba_state is READY */
  327. if (psli->ring[psli->extra_ring].cmdringaddr)
  328. psli->ring[psli->extra_ring].flag |= LPFC_STOP_IOCB_EVENT;
  329. if (psli->ring[psli->fcp_ring].cmdringaddr)
  330. psli->ring[psli->fcp_ring].flag |= LPFC_STOP_IOCB_EVENT;
  331. if (psli->ring[psli->next_ring].cmdringaddr)
  332. psli->ring[psli->next_ring].flag |= LPFC_STOP_IOCB_EVENT;
  333. /* Post receive buffers for desired rings */
  334. if (phba->sli_rev != 3)
  335. lpfc_post_rcv_buf(phba);
  336. /* Enable appropriate host interrupts */
  337. spin_lock_irq(&phba->hbalock);
  338. status = readl(phba->HCregaddr);
  339. status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA;
  340. if (psli->num_rings > 0)
  341. status |= HC_R0INT_ENA;
  342. if (psli->num_rings > 1)
  343. status |= HC_R1INT_ENA;
  344. if (psli->num_rings > 2)
  345. status |= HC_R2INT_ENA;
  346. if (psli->num_rings > 3)
  347. status |= HC_R3INT_ENA;
  348. if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) &&
  349. (phba->cfg_poll & DISABLE_FCP_RING_INT))
  350. status &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
  351. writel(status, phba->HCregaddr);
  352. readl(phba->HCregaddr); /* flush */
  353. spin_unlock_irq(&phba->hbalock);
  354. /*
  355. * Setup the ring 0 (els) timeout handler
  356. */
  357. timeout = phba->fc_ratov << 1;
  358. mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
  359. mod_timer(&phba->hb_tmofunc, jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  360. phba->hb_outstanding = 0;
  361. phba->last_completion_time = jiffies;
  362. lpfc_init_link(phba, pmb, phba->cfg_topology, phba->cfg_link_speed);
  363. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  364. pmb->vport = vport;
  365. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  366. lpfc_set_loopback_flag(phba);
  367. if (rc != MBX_SUCCESS) {
  368. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  369. "0454 Adapter failed to init, mbxCmd x%x "
  370. "INIT_LINK, mbxStatus x%x\n",
  371. mb->mbxCommand, mb->mbxStatus);
  372. /* Clear all interrupt enable conditions */
  373. writel(0, phba->HCregaddr);
  374. readl(phba->HCregaddr); /* flush */
  375. /* Clear all pending interrupts */
  376. writel(0xffffffff, phba->HAregaddr);
  377. readl(phba->HAregaddr); /* flush */
  378. phba->link_state = LPFC_HBA_ERROR;
  379. if (rc != MBX_BUSY)
  380. mempool_free(pmb, phba->mbox_mem_pool);
  381. return -EIO;
  382. }
  383. /* MBOX buffer will be freed in mbox compl */
  384. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  385. lpfc_config_async(phba, pmb, LPFC_ELS_RING);
  386. pmb->mbox_cmpl = lpfc_config_async_cmpl;
  387. pmb->vport = phba->pport;
  388. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  389. if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
  390. lpfc_printf_log(phba,
  391. KERN_ERR,
  392. LOG_INIT,
  393. "0456 Adapter failed to issue "
  394. "ASYNCEVT_ENABLE mbox status x%x \n.",
  395. rc);
  396. mempool_free(pmb, phba->mbox_mem_pool);
  397. }
  398. return (0);
  399. }
  400. /************************************************************************/
  401. /* */
  402. /* lpfc_hba_down_prep */
  403. /* This routine will do LPFC uninitialization before the */
  404. /* HBA is reset when bringing down the SLI Layer. This will be */
  405. /* initialized as a SLI layer callback routine. */
  406. /* This routine returns 0 on success. Any other return value */
  407. /* indicates an error. */
  408. /* */
  409. /************************************************************************/
  410. int
  411. lpfc_hba_down_prep(struct lpfc_hba *phba)
  412. {
  413. /* Disable interrupts */
  414. writel(0, phba->HCregaddr);
  415. readl(phba->HCregaddr); /* flush */
  416. lpfc_cleanup_discovery_resources(phba->pport);
  417. return 0;
  418. }
  419. /************************************************************************/
  420. /* */
  421. /* lpfc_hba_down_post */
  422. /* This routine will do uninitialization after the HBA is reset */
  423. /* when bringing down the SLI Layer. */
  424. /* This routine returns 0 on success. Any other return value */
  425. /* indicates an error. */
  426. /* */
  427. /************************************************************************/
  428. int
  429. lpfc_hba_down_post(struct lpfc_hba *phba)
  430. {
  431. struct lpfc_sli *psli = &phba->sli;
  432. struct lpfc_sli_ring *pring;
  433. struct lpfc_dmabuf *mp, *next_mp;
  434. int i;
  435. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
  436. lpfc_sli_hbqbuf_free_all(phba);
  437. else {
  438. /* Cleanup preposted buffers on the ELS ring */
  439. pring = &psli->ring[LPFC_ELS_RING];
  440. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  441. list_del(&mp->list);
  442. pring->postbufq_cnt--;
  443. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  444. kfree(mp);
  445. }
  446. }
  447. for (i = 0; i < psli->num_rings; i++) {
  448. pring = &psli->ring[i];
  449. lpfc_sli_abort_iocb_ring(phba, pring);
  450. }
  451. return 0;
  452. }
  453. /* HBA heart beat timeout handler */
  454. static void
  455. lpfc_hb_timeout(unsigned long ptr)
  456. {
  457. struct lpfc_hba *phba;
  458. unsigned long iflag;
  459. phba = (struct lpfc_hba *)ptr;
  460. spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
  461. if (!(phba->pport->work_port_events & WORKER_HB_TMO))
  462. phba->pport->work_port_events |= WORKER_HB_TMO;
  463. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
  464. if (phba->work_wait)
  465. wake_up(phba->work_wait);
  466. return;
  467. }
  468. static void
  469. lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
  470. {
  471. unsigned long drvr_flag;
  472. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  473. phba->hb_outstanding = 0;
  474. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  475. mempool_free(pmboxq, phba->mbox_mem_pool);
  476. if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) &&
  477. !(phba->link_state == LPFC_HBA_ERROR) &&
  478. !(phba->pport->load_flag & FC_UNLOADING))
  479. mod_timer(&phba->hb_tmofunc,
  480. jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  481. return;
  482. }
  483. void
  484. lpfc_hb_timeout_handler(struct lpfc_hba *phba)
  485. {
  486. LPFC_MBOXQ_t *pmboxq;
  487. int retval;
  488. struct lpfc_sli *psli = &phba->sli;
  489. if ((phba->link_state == LPFC_HBA_ERROR) ||
  490. (phba->pport->load_flag & FC_UNLOADING) ||
  491. (phba->pport->fc_flag & FC_OFFLINE_MODE))
  492. return;
  493. spin_lock_irq(&phba->pport->work_port_lock);
  494. /* If the timer is already canceled do nothing */
  495. if (!(phba->pport->work_port_events & WORKER_HB_TMO)) {
  496. spin_unlock_irq(&phba->pport->work_port_lock);
  497. return;
  498. }
  499. if (time_after(phba->last_completion_time + LPFC_HB_MBOX_INTERVAL * HZ,
  500. jiffies)) {
  501. spin_unlock_irq(&phba->pport->work_port_lock);
  502. if (!phba->hb_outstanding)
  503. mod_timer(&phba->hb_tmofunc,
  504. jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  505. else
  506. mod_timer(&phba->hb_tmofunc,
  507. jiffies + HZ * LPFC_HB_MBOX_TIMEOUT);
  508. return;
  509. }
  510. spin_unlock_irq(&phba->pport->work_port_lock);
  511. /* If there is no heart beat outstanding, issue a heartbeat command */
  512. if (!phba->hb_outstanding) {
  513. pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
  514. if (!pmboxq) {
  515. mod_timer(&phba->hb_tmofunc,
  516. jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  517. return;
  518. }
  519. lpfc_heart_beat(phba, pmboxq);
  520. pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl;
  521. pmboxq->vport = phba->pport;
  522. retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
  523. if (retval != MBX_BUSY && retval != MBX_SUCCESS) {
  524. mempool_free(pmboxq, phba->mbox_mem_pool);
  525. mod_timer(&phba->hb_tmofunc,
  526. jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  527. return;
  528. }
  529. mod_timer(&phba->hb_tmofunc,
  530. jiffies + HZ * LPFC_HB_MBOX_TIMEOUT);
  531. phba->hb_outstanding = 1;
  532. return;
  533. } else {
  534. /*
  535. * If heart beat timeout called with hb_outstanding set we
  536. * need to take the HBA offline.
  537. */
  538. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  539. "0459 Adapter heartbeat failure, taking "
  540. "this port offline.\n");
  541. spin_lock_irq(&phba->hbalock);
  542. psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
  543. spin_unlock_irq(&phba->hbalock);
  544. lpfc_offline_prep(phba);
  545. lpfc_offline(phba);
  546. lpfc_unblock_mgmt_io(phba);
  547. phba->link_state = LPFC_HBA_ERROR;
  548. lpfc_hba_down_post(phba);
  549. }
  550. }
  551. /************************************************************************/
  552. /* */
  553. /* lpfc_handle_eratt */
  554. /* This routine will handle processing a Host Attention */
  555. /* Error Status event. This will be initialized */
  556. /* as a SLI layer callback routine. */
  557. /* */
  558. /************************************************************************/
  559. void
  560. lpfc_handle_eratt(struct lpfc_hba *phba)
  561. {
  562. struct lpfc_vport *vport = phba->pport;
  563. struct lpfc_sli *psli = &phba->sli;
  564. struct lpfc_sli_ring *pring;
  565. struct lpfc_vport **vports;
  566. uint32_t event_data;
  567. unsigned long temperature;
  568. struct temp_event temp_event_data;
  569. struct Scsi_Host *shost;
  570. int i;
  571. /* If the pci channel is offline, ignore possible errors,
  572. * since we cannot communicate with the pci card anyway. */
  573. if (pci_channel_offline(phba->pcidev))
  574. return;
  575. if (phba->work_hs & HS_FFER6 ||
  576. phba->work_hs & HS_FFER5) {
  577. /* Re-establishing Link */
  578. lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
  579. "1301 Re-establishing Link "
  580. "Data: x%x x%x x%x\n",
  581. phba->work_hs,
  582. phba->work_status[0], phba->work_status[1]);
  583. vports = lpfc_create_vport_work_array(phba);
  584. if (vports != NULL)
  585. for(i = 0;
  586. i < LPFC_MAX_VPORTS && vports[i] != NULL;
  587. i++){
  588. shost = lpfc_shost_from_vport(vports[i]);
  589. spin_lock_irq(shost->host_lock);
  590. vports[i]->fc_flag |= FC_ESTABLISH_LINK;
  591. spin_unlock_irq(shost->host_lock);
  592. }
  593. lpfc_destroy_vport_work_array(vports);
  594. spin_lock_irq(&phba->hbalock);
  595. psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
  596. spin_unlock_irq(&phba->hbalock);
  597. /*
  598. * Firmware stops when it triggled erratt with HS_FFER6.
  599. * That could cause the I/Os dropped by the firmware.
  600. * Error iocb (I/O) on txcmplq and let the SCSI layer
  601. * retry it after re-establishing link.
  602. */
  603. pring = &psli->ring[psli->fcp_ring];
  604. lpfc_sli_abort_iocb_ring(phba, pring);
  605. /*
  606. * There was a firmware error. Take the hba offline and then
  607. * attempt to restart it.
  608. */
  609. lpfc_offline_prep(phba);
  610. lpfc_offline(phba);
  611. lpfc_sli_brdrestart(phba);
  612. if (lpfc_online(phba) == 0) { /* Initialize the HBA */
  613. mod_timer(&phba->fc_estabtmo, jiffies + HZ * 60);
  614. lpfc_unblock_mgmt_io(phba);
  615. return;
  616. }
  617. lpfc_unblock_mgmt_io(phba);
  618. } else if (phba->work_hs & HS_CRIT_TEMP) {
  619. temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET);
  620. temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
  621. temp_event_data.event_code = LPFC_CRIT_TEMP;
  622. temp_event_data.data = (uint32_t)temperature;
  623. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  624. "0459 Adapter maximum temperature exceeded "
  625. "(%ld), taking this port offline "
  626. "Data: x%x x%x x%x\n",
  627. temperature, phba->work_hs,
  628. phba->work_status[0], phba->work_status[1]);
  629. shost = lpfc_shost_from_vport(phba->pport);
  630. fc_host_post_vendor_event(shost, fc_get_event_number(),
  631. sizeof(temp_event_data),
  632. (char *) &temp_event_data,
  633. SCSI_NL_VID_TYPE_PCI
  634. | PCI_VENDOR_ID_EMULEX);
  635. spin_lock_irq(&phba->hbalock);
  636. psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
  637. phba->over_temp_state = HBA_OVER_TEMP;
  638. spin_unlock_irq(&phba->hbalock);
  639. lpfc_offline_prep(phba);
  640. lpfc_offline(phba);
  641. lpfc_unblock_mgmt_io(phba);
  642. phba->link_state = LPFC_HBA_ERROR;
  643. lpfc_hba_down_post(phba);
  644. } else {
  645. /* The if clause above forces this code path when the status
  646. * failure is a value other than FFER6. Do not call the offline
  647. * twice. This is the adapter hardware error path.
  648. */
  649. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  650. "0457 Adapter Hardware Error "
  651. "Data: x%x x%x x%x\n",
  652. phba->work_hs,
  653. phba->work_status[0], phba->work_status[1]);
  654. event_data = FC_REG_DUMP_EVENT;
  655. shost = lpfc_shost_from_vport(vport);
  656. fc_host_post_vendor_event(shost, fc_get_event_number(),
  657. sizeof(event_data), (char *) &event_data,
  658. SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
  659. spin_lock_irq(&phba->hbalock);
  660. psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
  661. spin_unlock_irq(&phba->hbalock);
  662. lpfc_offline_prep(phba);
  663. lpfc_offline(phba);
  664. lpfc_unblock_mgmt_io(phba);
  665. phba->link_state = LPFC_HBA_ERROR;
  666. lpfc_hba_down_post(phba);
  667. }
  668. }
  669. /************************************************************************/
  670. /* */
  671. /* lpfc_handle_latt */
  672. /* This routine will handle processing a Host Attention */
  673. /* Link Status event. This will be initialized */
  674. /* as a SLI layer callback routine. */
  675. /* */
  676. /************************************************************************/
  677. void
  678. lpfc_handle_latt(struct lpfc_hba *phba)
  679. {
  680. struct lpfc_vport *vport = phba->pport;
  681. struct lpfc_sli *psli = &phba->sli;
  682. LPFC_MBOXQ_t *pmb;
  683. volatile uint32_t control;
  684. struct lpfc_dmabuf *mp;
  685. int rc = -ENOMEM;
  686. pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  687. if (!pmb)
  688. goto lpfc_handle_latt_err_exit;
  689. mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  690. if (!mp)
  691. goto lpfc_handle_latt_free_pmb;
  692. mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
  693. if (!mp->virt)
  694. goto lpfc_handle_latt_free_mp;
  695. rc = -EIO;
  696. /* Cleanup any outstanding ELS commands */
  697. lpfc_els_flush_all_cmd(phba);
  698. psli->slistat.link_event++;
  699. lpfc_read_la(phba, pmb, mp);
  700. pmb->mbox_cmpl = lpfc_mbx_cmpl_read_la;
  701. pmb->vport = vport;
  702. rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT);
  703. if (rc == MBX_NOT_FINISHED)
  704. goto lpfc_handle_latt_free_mbuf;
  705. /* Clear Link Attention in HA REG */
  706. spin_lock_irq(&phba->hbalock);
  707. writel(HA_LATT, phba->HAregaddr);
  708. readl(phba->HAregaddr); /* flush */
  709. spin_unlock_irq(&phba->hbalock);
  710. return;
  711. lpfc_handle_latt_free_mbuf:
  712. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  713. lpfc_handle_latt_free_mp:
  714. kfree(mp);
  715. lpfc_handle_latt_free_pmb:
  716. mempool_free(pmb, phba->mbox_mem_pool);
  717. lpfc_handle_latt_err_exit:
  718. /* Enable Link attention interrupts */
  719. spin_lock_irq(&phba->hbalock);
  720. psli->sli_flag |= LPFC_PROCESS_LA;
  721. control = readl(phba->HCregaddr);
  722. control |= HC_LAINT_ENA;
  723. writel(control, phba->HCregaddr);
  724. readl(phba->HCregaddr); /* flush */
  725. /* Clear Link Attention in HA REG */
  726. writel(HA_LATT, phba->HAregaddr);
  727. readl(phba->HAregaddr); /* flush */
  728. spin_unlock_irq(&phba->hbalock);
  729. lpfc_linkdown(phba);
  730. phba->link_state = LPFC_HBA_ERROR;
  731. /* The other case is an error from issue_mbox */
  732. if (rc == -ENOMEM)
  733. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
  734. "0300 READ_LA: no buffers\n");
  735. return;
  736. }
  737. /************************************************************************/
  738. /* */
  739. /* lpfc_parse_vpd */
  740. /* This routine will parse the VPD data */
  741. /* */
  742. /************************************************************************/
  743. static int
  744. lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len)
  745. {
  746. uint8_t lenlo, lenhi;
  747. int Length;
  748. int i, j;
  749. int finished = 0;
  750. int index = 0;
  751. if (!vpd)
  752. return 0;
  753. /* Vital Product */
  754. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  755. "0455 Vital Product Data: x%x x%x x%x x%x\n",
  756. (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
  757. (uint32_t) vpd[3]);
  758. while (!finished && (index < (len - 4))) {
  759. switch (vpd[index]) {
  760. case 0x82:
  761. case 0x91:
  762. index += 1;
  763. lenlo = vpd[index];
  764. index += 1;
  765. lenhi = vpd[index];
  766. index += 1;
  767. i = ((((unsigned short)lenhi) << 8) + lenlo);
  768. index += i;
  769. break;
  770. case 0x90:
  771. index += 1;
  772. lenlo = vpd[index];
  773. index += 1;
  774. lenhi = vpd[index];
  775. index += 1;
  776. Length = ((((unsigned short)lenhi) << 8) + lenlo);
  777. if (Length > len - index)
  778. Length = len - index;
  779. while (Length > 0) {
  780. /* Look for Serial Number */
  781. if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) {
  782. index += 2;
  783. i = vpd[index];
  784. index += 1;
  785. j = 0;
  786. Length -= (3+i);
  787. while(i--) {
  788. phba->SerialNumber[j++] = vpd[index++];
  789. if (j == 31)
  790. break;
  791. }
  792. phba->SerialNumber[j] = 0;
  793. continue;
  794. }
  795. else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) {
  796. phba->vpd_flag |= VPD_MODEL_DESC;
  797. index += 2;
  798. i = vpd[index];
  799. index += 1;
  800. j = 0;
  801. Length -= (3+i);
  802. while(i--) {
  803. phba->ModelDesc[j++] = vpd[index++];
  804. if (j == 255)
  805. break;
  806. }
  807. phba->ModelDesc[j] = 0;
  808. continue;
  809. }
  810. else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) {
  811. phba->vpd_flag |= VPD_MODEL_NAME;
  812. index += 2;
  813. i = vpd[index];
  814. index += 1;
  815. j = 0;
  816. Length -= (3+i);
  817. while(i--) {
  818. phba->ModelName[j++] = vpd[index++];
  819. if (j == 79)
  820. break;
  821. }
  822. phba->ModelName[j] = 0;
  823. continue;
  824. }
  825. else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) {
  826. phba->vpd_flag |= VPD_PROGRAM_TYPE;
  827. index += 2;
  828. i = vpd[index];
  829. index += 1;
  830. j = 0;
  831. Length -= (3+i);
  832. while(i--) {
  833. phba->ProgramType[j++] = vpd[index++];
  834. if (j == 255)
  835. break;
  836. }
  837. phba->ProgramType[j] = 0;
  838. continue;
  839. }
  840. else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) {
  841. phba->vpd_flag |= VPD_PORT;
  842. index += 2;
  843. i = vpd[index];
  844. index += 1;
  845. j = 0;
  846. Length -= (3+i);
  847. while(i--) {
  848. phba->Port[j++] = vpd[index++];
  849. if (j == 19)
  850. break;
  851. }
  852. phba->Port[j] = 0;
  853. continue;
  854. }
  855. else {
  856. index += 2;
  857. i = vpd[index];
  858. index += 1;
  859. index += i;
  860. Length -= (3 + i);
  861. }
  862. }
  863. finished = 0;
  864. break;
  865. case 0x78:
  866. finished = 1;
  867. break;
  868. default:
  869. index ++;
  870. break;
  871. }
  872. }
  873. return(1);
  874. }
  875. static void
  876. lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
  877. {
  878. lpfc_vpd_t *vp;
  879. uint16_t dev_id = phba->pcidev->device;
  880. int max_speed;
  881. struct {
  882. char * name;
  883. int max_speed;
  884. char * bus;
  885. } m = {"<Unknown>", 0, ""};
  886. if (mdp && mdp[0] != '\0'
  887. && descp && descp[0] != '\0')
  888. return;
  889. if (phba->lmt & LMT_10Gb)
  890. max_speed = 10;
  891. else if (phba->lmt & LMT_8Gb)
  892. max_speed = 8;
  893. else if (phba->lmt & LMT_4Gb)
  894. max_speed = 4;
  895. else if (phba->lmt & LMT_2Gb)
  896. max_speed = 2;
  897. else
  898. max_speed = 1;
  899. vp = &phba->vpd;
  900. switch (dev_id) {
  901. case PCI_DEVICE_ID_FIREFLY:
  902. m = (typeof(m)){"LP6000", max_speed, "PCI"};
  903. break;
  904. case PCI_DEVICE_ID_SUPERFLY:
  905. if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
  906. m = (typeof(m)){"LP7000", max_speed, "PCI"};
  907. else
  908. m = (typeof(m)){"LP7000E", max_speed, "PCI"};
  909. break;
  910. case PCI_DEVICE_ID_DRAGONFLY:
  911. m = (typeof(m)){"LP8000", max_speed, "PCI"};
  912. break;
  913. case PCI_DEVICE_ID_CENTAUR:
  914. if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
  915. m = (typeof(m)){"LP9002", max_speed, "PCI"};
  916. else
  917. m = (typeof(m)){"LP9000", max_speed, "PCI"};
  918. break;
  919. case PCI_DEVICE_ID_RFLY:
  920. m = (typeof(m)){"LP952", max_speed, "PCI"};
  921. break;
  922. case PCI_DEVICE_ID_PEGASUS:
  923. m = (typeof(m)){"LP9802", max_speed, "PCI-X"};
  924. break;
  925. case PCI_DEVICE_ID_THOR:
  926. m = (typeof(m)){"LP10000", max_speed, "PCI-X"};
  927. break;
  928. case PCI_DEVICE_ID_VIPER:
  929. m = (typeof(m)){"LPX1000", max_speed, "PCI-X"};
  930. break;
  931. case PCI_DEVICE_ID_PFLY:
  932. m = (typeof(m)){"LP982", max_speed, "PCI-X"};
  933. break;
  934. case PCI_DEVICE_ID_TFLY:
  935. m = (typeof(m)){"LP1050", max_speed, "PCI-X"};
  936. break;
  937. case PCI_DEVICE_ID_HELIOS:
  938. m = (typeof(m)){"LP11000", max_speed, "PCI-X2"};
  939. break;
  940. case PCI_DEVICE_ID_HELIOS_SCSP:
  941. m = (typeof(m)){"LP11000-SP", max_speed, "PCI-X2"};
  942. break;
  943. case PCI_DEVICE_ID_HELIOS_DCSP:
  944. m = (typeof(m)){"LP11002-SP", max_speed, "PCI-X2"};
  945. break;
  946. case PCI_DEVICE_ID_NEPTUNE:
  947. m = (typeof(m)){"LPe1000", max_speed, "PCIe"};
  948. break;
  949. case PCI_DEVICE_ID_NEPTUNE_SCSP:
  950. m = (typeof(m)){"LPe1000-SP", max_speed, "PCIe"};
  951. break;
  952. case PCI_DEVICE_ID_NEPTUNE_DCSP:
  953. m = (typeof(m)){"LPe1002-SP", max_speed, "PCIe"};
  954. break;
  955. case PCI_DEVICE_ID_BMID:
  956. m = (typeof(m)){"LP1150", max_speed, "PCI-X2"};
  957. break;
  958. case PCI_DEVICE_ID_BSMB:
  959. m = (typeof(m)){"LP111", max_speed, "PCI-X2"};
  960. break;
  961. case PCI_DEVICE_ID_ZEPHYR:
  962. m = (typeof(m)){"LPe11000", max_speed, "PCIe"};
  963. break;
  964. case PCI_DEVICE_ID_ZEPHYR_SCSP:
  965. m = (typeof(m)){"LPe11000", max_speed, "PCIe"};
  966. break;
  967. case PCI_DEVICE_ID_ZEPHYR_DCSP:
  968. m = (typeof(m)){"LPe11002-SP", max_speed, "PCIe"};
  969. break;
  970. case PCI_DEVICE_ID_ZMID:
  971. m = (typeof(m)){"LPe1150", max_speed, "PCIe"};
  972. break;
  973. case PCI_DEVICE_ID_ZSMB:
  974. m = (typeof(m)){"LPe111", max_speed, "PCIe"};
  975. break;
  976. case PCI_DEVICE_ID_LP101:
  977. m = (typeof(m)){"LP101", max_speed, "PCI-X"};
  978. break;
  979. case PCI_DEVICE_ID_LP10000S:
  980. m = (typeof(m)){"LP10000-S", max_speed, "PCI"};
  981. break;
  982. case PCI_DEVICE_ID_LP11000S:
  983. m = (typeof(m)){"LP11000-S", max_speed,
  984. "PCI-X2"};
  985. break;
  986. case PCI_DEVICE_ID_LPE11000S:
  987. m = (typeof(m)){"LPe11000-S", max_speed,
  988. "PCIe"};
  989. break;
  990. case PCI_DEVICE_ID_SAT:
  991. m = (typeof(m)){"LPe12000", max_speed, "PCIe"};
  992. break;
  993. case PCI_DEVICE_ID_SAT_MID:
  994. m = (typeof(m)){"LPe1250", max_speed, "PCIe"};
  995. break;
  996. case PCI_DEVICE_ID_SAT_SMB:
  997. m = (typeof(m)){"LPe121", max_speed, "PCIe"};
  998. break;
  999. case PCI_DEVICE_ID_SAT_DCSP:
  1000. m = (typeof(m)){"LPe12002-SP", max_speed, "PCIe"};
  1001. break;
  1002. case PCI_DEVICE_ID_SAT_SCSP:
  1003. m = (typeof(m)){"LPe12000-SP", max_speed, "PCIe"};
  1004. break;
  1005. case PCI_DEVICE_ID_SAT_S:
  1006. m = (typeof(m)){"LPe12000-S", max_speed, "PCIe"};
  1007. break;
  1008. default:
  1009. m = (typeof(m)){ NULL };
  1010. break;
  1011. }
  1012. if (mdp && mdp[0] == '\0')
  1013. snprintf(mdp, 79,"%s", m.name);
  1014. if (descp && descp[0] == '\0')
  1015. snprintf(descp, 255,
  1016. "Emulex %s %dGb %s Fibre Channel Adapter",
  1017. m.name, m.max_speed, m.bus);
  1018. }
  1019. /**************************************************/
  1020. /* lpfc_post_buffer */
  1021. /* */
  1022. /* This routine will post count buffers to the */
  1023. /* ring with the QUE_RING_BUF_CN command. This */
  1024. /* allows 3 buffers / command to be posted. */
  1025. /* Returns the number of buffers NOT posted. */
  1026. /**************************************************/
  1027. int
  1028. lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt,
  1029. int type)
  1030. {
  1031. IOCB_t *icmd;
  1032. struct lpfc_iocbq *iocb;
  1033. struct lpfc_dmabuf *mp1, *mp2;
  1034. cnt += pring->missbufcnt;
  1035. /* While there are buffers to post */
  1036. while (cnt > 0) {
  1037. /* Allocate buffer for command iocb */
  1038. iocb = lpfc_sli_get_iocbq(phba);
  1039. if (iocb == NULL) {
  1040. pring->missbufcnt = cnt;
  1041. return cnt;
  1042. }
  1043. icmd = &iocb->iocb;
  1044. /* 2 buffers can be posted per command */
  1045. /* Allocate buffer to post */
  1046. mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
  1047. if (mp1)
  1048. mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys);
  1049. if (!mp1 || !mp1->virt) {
  1050. kfree(mp1);
  1051. lpfc_sli_release_iocbq(phba, iocb);
  1052. pring->missbufcnt = cnt;
  1053. return cnt;
  1054. }
  1055. INIT_LIST_HEAD(&mp1->list);
  1056. /* Allocate buffer to post */
  1057. if (cnt > 1) {
  1058. mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
  1059. if (mp2)
  1060. mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
  1061. &mp2->phys);
  1062. if (!mp2 || !mp2->virt) {
  1063. kfree(mp2);
  1064. lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
  1065. kfree(mp1);
  1066. lpfc_sli_release_iocbq(phba, iocb);
  1067. pring->missbufcnt = cnt;
  1068. return cnt;
  1069. }
  1070. INIT_LIST_HEAD(&mp2->list);
  1071. } else {
  1072. mp2 = NULL;
  1073. }
  1074. icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
  1075. icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
  1076. icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
  1077. icmd->ulpBdeCount = 1;
  1078. cnt--;
  1079. if (mp2) {
  1080. icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
  1081. icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
  1082. icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
  1083. cnt--;
  1084. icmd->ulpBdeCount = 2;
  1085. }
  1086. icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
  1087. icmd->ulpLe = 1;
  1088. if (lpfc_sli_issue_iocb(phba, pring, iocb, 0) == IOCB_ERROR) {
  1089. lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
  1090. kfree(mp1);
  1091. cnt++;
  1092. if (mp2) {
  1093. lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
  1094. kfree(mp2);
  1095. cnt++;
  1096. }
  1097. lpfc_sli_release_iocbq(phba, iocb);
  1098. pring->missbufcnt = cnt;
  1099. return cnt;
  1100. }
  1101. lpfc_sli_ringpostbuf_put(phba, pring, mp1);
  1102. if (mp2)
  1103. lpfc_sli_ringpostbuf_put(phba, pring, mp2);
  1104. }
  1105. pring->missbufcnt = 0;
  1106. return 0;
  1107. }
  1108. /************************************************************************/
  1109. /* */
  1110. /* lpfc_post_rcv_buf */
  1111. /* This routine post initial rcv buffers to the configured rings */
  1112. /* */
  1113. /************************************************************************/
  1114. static int
  1115. lpfc_post_rcv_buf(struct lpfc_hba *phba)
  1116. {
  1117. struct lpfc_sli *psli = &phba->sli;
  1118. /* Ring 0, ELS / CT buffers */
  1119. lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0, 1);
  1120. /* Ring 2 - FCP no buffers needed */
  1121. return 0;
  1122. }
  1123. #define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
  1124. /************************************************************************/
  1125. /* */
  1126. /* lpfc_sha_init */
  1127. /* */
  1128. /************************************************************************/
  1129. static void
  1130. lpfc_sha_init(uint32_t * HashResultPointer)
  1131. {
  1132. HashResultPointer[0] = 0x67452301;
  1133. HashResultPointer[1] = 0xEFCDAB89;
  1134. HashResultPointer[2] = 0x98BADCFE;
  1135. HashResultPointer[3] = 0x10325476;
  1136. HashResultPointer[4] = 0xC3D2E1F0;
  1137. }
  1138. /************************************************************************/
  1139. /* */
  1140. /* lpfc_sha_iterate */
  1141. /* */
  1142. /************************************************************************/
  1143. static void
  1144. lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
  1145. {
  1146. int t;
  1147. uint32_t TEMP;
  1148. uint32_t A, B, C, D, E;
  1149. t = 16;
  1150. do {
  1151. HashWorkingPointer[t] =
  1152. S(1,
  1153. HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
  1154. 8] ^
  1155. HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
  1156. } while (++t <= 79);
  1157. t = 0;
  1158. A = HashResultPointer[0];
  1159. B = HashResultPointer[1];
  1160. C = HashResultPointer[2];
  1161. D = HashResultPointer[3];
  1162. E = HashResultPointer[4];
  1163. do {
  1164. if (t < 20) {
  1165. TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
  1166. } else if (t < 40) {
  1167. TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
  1168. } else if (t < 60) {
  1169. TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
  1170. } else {
  1171. TEMP = (B ^ C ^ D) + 0xCA62C1D6;
  1172. }
  1173. TEMP += S(5, A) + E + HashWorkingPointer[t];
  1174. E = D;
  1175. D = C;
  1176. C = S(30, B);
  1177. B = A;
  1178. A = TEMP;
  1179. } while (++t <= 79);
  1180. HashResultPointer[0] += A;
  1181. HashResultPointer[1] += B;
  1182. HashResultPointer[2] += C;
  1183. HashResultPointer[3] += D;
  1184. HashResultPointer[4] += E;
  1185. }
  1186. /************************************************************************/
  1187. /* */
  1188. /* lpfc_challenge_key */
  1189. /* */
  1190. /************************************************************************/
  1191. static void
  1192. lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
  1193. {
  1194. *HashWorking = (*RandomChallenge ^ *HashWorking);
  1195. }
  1196. /************************************************************************/
  1197. /* */
  1198. /* lpfc_hba_init */
  1199. /* */
  1200. /************************************************************************/
  1201. void
  1202. lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
  1203. {
  1204. int t;
  1205. uint32_t *HashWorking;
  1206. uint32_t *pwwnn = (uint32_t *) phba->wwnn;
  1207. HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL);
  1208. if (!HashWorking)
  1209. return;
  1210. HashWorking[0] = HashWorking[78] = *pwwnn++;
  1211. HashWorking[1] = HashWorking[79] = *pwwnn;
  1212. for (t = 0; t < 7; t++)
  1213. lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
  1214. lpfc_sha_init(hbainit);
  1215. lpfc_sha_iterate(hbainit, HashWorking);
  1216. kfree(HashWorking);
  1217. }
  1218. void
  1219. lpfc_cleanup(struct lpfc_vport *vport)
  1220. {
  1221. struct lpfc_hba *phba = vport->phba;
  1222. struct lpfc_nodelist *ndlp, *next_ndlp;
  1223. int i = 0;
  1224. if (phba->link_state > LPFC_LINK_DOWN)
  1225. lpfc_port_link_failure(vport);
  1226. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
  1227. if (ndlp->nlp_type & NLP_FABRIC)
  1228. lpfc_disc_state_machine(vport, ndlp, NULL,
  1229. NLP_EVT_DEVICE_RECOVERY);
  1230. lpfc_disc_state_machine(vport, ndlp, NULL,
  1231. NLP_EVT_DEVICE_RM);
  1232. }
  1233. /* At this point, ALL ndlp's should be gone
  1234. * because of the previous NLP_EVT_DEVICE_RM.
  1235. * Lets wait for this to happen, if needed.
  1236. */
  1237. while (!list_empty(&vport->fc_nodes)) {
  1238. if (i++ > 3000) {
  1239. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  1240. "0233 Nodelist not empty\n");
  1241. break;
  1242. }
  1243. /* Wait for any activity on ndlps to settle */
  1244. msleep(10);
  1245. }
  1246. return;
  1247. }
  1248. static void
  1249. lpfc_establish_link_tmo(unsigned long ptr)
  1250. {
  1251. struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
  1252. struct lpfc_vport **vports;
  1253. unsigned long iflag;
  1254. int i;
  1255. /* Re-establishing Link, timer expired */
  1256. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  1257. "1300 Re-establishing Link, timer expired "
  1258. "Data: x%x x%x\n",
  1259. phba->pport->fc_flag, phba->pport->port_state);
  1260. vports = lpfc_create_vport_work_array(phba);
  1261. if (vports != NULL)
  1262. for(i = 0; i < LPFC_MAX_VPORTS && vports[i] != NULL; i++) {
  1263. struct Scsi_Host *shost;
  1264. shost = lpfc_shost_from_vport(vports[i]);
  1265. spin_lock_irqsave(shost->host_lock, iflag);
  1266. vports[i]->fc_flag &= ~FC_ESTABLISH_LINK;
  1267. spin_unlock_irqrestore(shost->host_lock, iflag);
  1268. }
  1269. lpfc_destroy_vport_work_array(vports);
  1270. }
  1271. void
  1272. lpfc_stop_vport_timers(struct lpfc_vport *vport)
  1273. {
  1274. del_timer_sync(&vport->els_tmofunc);
  1275. del_timer_sync(&vport->fc_fdmitmo);
  1276. lpfc_can_disctmo(vport);
  1277. return;
  1278. }
  1279. static void
  1280. lpfc_stop_phba_timers(struct lpfc_hba *phba)
  1281. {
  1282. del_timer_sync(&phba->fcp_poll_timer);
  1283. del_timer_sync(&phba->fc_estabtmo);
  1284. lpfc_stop_vport_timers(phba->pport);
  1285. del_timer_sync(&phba->sli.mbox_tmo);
  1286. del_timer_sync(&phba->fabric_block_timer);
  1287. phba->hb_outstanding = 0;
  1288. del_timer_sync(&phba->hb_tmofunc);
  1289. return;
  1290. }
  1291. static void
  1292. lpfc_block_mgmt_io(struct lpfc_hba * phba)
  1293. {
  1294. unsigned long iflag;
  1295. spin_lock_irqsave(&phba->hbalock, iflag);
  1296. phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO;
  1297. spin_unlock_irqrestore(&phba->hbalock, iflag);
  1298. }
  1299. int
  1300. lpfc_online(struct lpfc_hba *phba)
  1301. {
  1302. struct lpfc_vport *vport = phba->pport;
  1303. struct lpfc_vport **vports;
  1304. int i;
  1305. if (!phba)
  1306. return 0;
  1307. if (!(vport->fc_flag & FC_OFFLINE_MODE))
  1308. return 0;
  1309. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  1310. "0458 Bring Adapter online\n");
  1311. lpfc_block_mgmt_io(phba);
  1312. if (!lpfc_sli_queue_setup(phba)) {
  1313. lpfc_unblock_mgmt_io(phba);
  1314. return 1;
  1315. }
  1316. if (lpfc_sli_hba_setup(phba)) { /* Initialize the HBA */
  1317. lpfc_unblock_mgmt_io(phba);
  1318. return 1;
  1319. }
  1320. vports = lpfc_create_vport_work_array(phba);
  1321. if (vports != NULL)
  1322. for(i = 0; i < LPFC_MAX_VPORTS && vports[i] != NULL; i++) {
  1323. struct Scsi_Host *shost;
  1324. shost = lpfc_shost_from_vport(vports[i]);
  1325. spin_lock_irq(shost->host_lock);
  1326. vports[i]->fc_flag &= ~FC_OFFLINE_MODE;
  1327. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
  1328. vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  1329. spin_unlock_irq(shost->host_lock);
  1330. }
  1331. lpfc_destroy_vport_work_array(vports);
  1332. lpfc_unblock_mgmt_io(phba);
  1333. return 0;
  1334. }
  1335. void
  1336. lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
  1337. {
  1338. unsigned long iflag;
  1339. spin_lock_irqsave(&phba->hbalock, iflag);
  1340. phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO;
  1341. spin_unlock_irqrestore(&phba->hbalock, iflag);
  1342. }
  1343. void
  1344. lpfc_offline_prep(struct lpfc_hba * phba)
  1345. {
  1346. struct lpfc_vport *vport = phba->pport;
  1347. struct lpfc_nodelist *ndlp, *next_ndlp;
  1348. struct lpfc_vport **vports;
  1349. int i;
  1350. if (vport->fc_flag & FC_OFFLINE_MODE)
  1351. return;
  1352. lpfc_block_mgmt_io(phba);
  1353. lpfc_linkdown(phba);
  1354. /* Issue an unreg_login to all nodes on all vports */
  1355. vports = lpfc_create_vport_work_array(phba);
  1356. if (vports != NULL) {
  1357. for(i = 0; i < LPFC_MAX_VPORTS && vports[i] != NULL; i++) {
  1358. struct Scsi_Host *shost;
  1359. if (vports[i]->load_flag & FC_UNLOADING)
  1360. continue;
  1361. shost = lpfc_shost_from_vport(vports[i]);
  1362. list_for_each_entry_safe(ndlp, next_ndlp,
  1363. &vports[i]->fc_nodes,
  1364. nlp_listp) {
  1365. if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
  1366. continue;
  1367. if (ndlp->nlp_type & NLP_FABRIC) {
  1368. lpfc_disc_state_machine(vports[i], ndlp,
  1369. NULL, NLP_EVT_DEVICE_RECOVERY);
  1370. lpfc_disc_state_machine(vports[i], ndlp,
  1371. NULL, NLP_EVT_DEVICE_RM);
  1372. }
  1373. spin_lock_irq(shost->host_lock);
  1374. ndlp->nlp_flag &= ~NLP_NPR_ADISC;
  1375. spin_unlock_irq(shost->host_lock);
  1376. lpfc_unreg_rpi(vports[i], ndlp);
  1377. }
  1378. }
  1379. }
  1380. lpfc_destroy_vport_work_array(vports);
  1381. lpfc_sli_flush_mbox_queue(phba);
  1382. }
  1383. void
  1384. lpfc_offline(struct lpfc_hba *phba)
  1385. {
  1386. struct Scsi_Host *shost;
  1387. struct lpfc_vport **vports;
  1388. int i;
  1389. if (phba->pport->fc_flag & FC_OFFLINE_MODE)
  1390. return;
  1391. /* stop all timers associated with this hba */
  1392. lpfc_stop_phba_timers(phba);
  1393. vports = lpfc_create_vport_work_array(phba);
  1394. if (vports != NULL)
  1395. for(i = 0; i < LPFC_MAX_VPORTS && vports[i] != NULL; i++)
  1396. lpfc_stop_vport_timers(vports[i]);
  1397. lpfc_destroy_vport_work_array(vports);
  1398. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  1399. "0460 Bring Adapter offline\n");
  1400. /* Bring down the SLI Layer and cleanup. The HBA is offline
  1401. now. */
  1402. lpfc_sli_hba_down(phba);
  1403. spin_lock_irq(&phba->hbalock);
  1404. phba->work_ha = 0;
  1405. spin_unlock_irq(&phba->hbalock);
  1406. vports = lpfc_create_vport_work_array(phba);
  1407. if (vports != NULL)
  1408. for(i = 0; i < LPFC_MAX_VPORTS && vports[i] != NULL; i++) {
  1409. shost = lpfc_shost_from_vport(vports[i]);
  1410. spin_lock_irq(shost->host_lock);
  1411. vports[i]->work_port_events = 0;
  1412. vports[i]->fc_flag |= FC_OFFLINE_MODE;
  1413. spin_unlock_irq(shost->host_lock);
  1414. }
  1415. lpfc_destroy_vport_work_array(vports);
  1416. }
  1417. /******************************************************************************
  1418. * Function name: lpfc_scsi_free
  1419. *
  1420. * Description: Called from lpfc_pci_remove_one free internal driver resources
  1421. *
  1422. ******************************************************************************/
  1423. static int
  1424. lpfc_scsi_free(struct lpfc_hba *phba)
  1425. {
  1426. struct lpfc_scsi_buf *sb, *sb_next;
  1427. struct lpfc_iocbq *io, *io_next;
  1428. spin_lock_irq(&phba->hbalock);
  1429. /* Release all the lpfc_scsi_bufs maintained by this host. */
  1430. list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list, list) {
  1431. list_del(&sb->list);
  1432. pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data,
  1433. sb->dma_handle);
  1434. kfree(sb);
  1435. phba->total_scsi_bufs--;
  1436. }
  1437. /* Release all the lpfc_iocbq entries maintained by this host. */
  1438. list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) {
  1439. list_del(&io->list);
  1440. kfree(io);
  1441. phba->total_iocbq_bufs--;
  1442. }
  1443. spin_unlock_irq(&phba->hbalock);
  1444. return 0;
  1445. }
  1446. struct lpfc_vport *
  1447. lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
  1448. {
  1449. struct lpfc_vport *vport;
  1450. struct Scsi_Host *shost;
  1451. int error = 0;
  1452. if (dev != &phba->pcidev->dev)
  1453. shost = scsi_host_alloc(&lpfc_vport_template,
  1454. sizeof(struct lpfc_vport));
  1455. else
  1456. shost = scsi_host_alloc(&lpfc_template,
  1457. sizeof(struct lpfc_vport));
  1458. if (!shost)
  1459. goto out;
  1460. vport = (struct lpfc_vport *) shost->hostdata;
  1461. vport->phba = phba;
  1462. vport->load_flag |= FC_LOADING;
  1463. vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  1464. lpfc_get_vport_cfgparam(vport);
  1465. shost->unique_id = instance;
  1466. shost->max_id = LPFC_MAX_TARGET;
  1467. shost->max_lun = vport->cfg_max_luns;
  1468. shost->this_id = -1;
  1469. shost->max_cmd_len = 16;
  1470. /*
  1471. * Set initial can_queue value since 0 is no longer supported and
  1472. * scsi_add_host will fail. This will be adjusted later based on the
  1473. * max xri value determined in hba setup.
  1474. */
  1475. shost->can_queue = phba->cfg_hba_queue_depth - 10;
  1476. if (dev != &phba->pcidev->dev) {
  1477. shost->transportt = lpfc_vport_transport_template;
  1478. vport->port_type = LPFC_NPIV_PORT;
  1479. } else {
  1480. shost->transportt = lpfc_transport_template;
  1481. vport->port_type = LPFC_PHYSICAL_PORT;
  1482. }
  1483. /* Initialize all internally managed lists. */
  1484. INIT_LIST_HEAD(&vport->fc_nodes);
  1485. spin_lock_init(&vport->work_port_lock);
  1486. init_timer(&vport->fc_disctmo);
  1487. vport->fc_disctmo.function = lpfc_disc_timeout;
  1488. vport->fc_disctmo.data = (unsigned long)vport;
  1489. init_timer(&vport->fc_fdmitmo);
  1490. vport->fc_fdmitmo.function = lpfc_fdmi_tmo;
  1491. vport->fc_fdmitmo.data = (unsigned long)vport;
  1492. init_timer(&vport->els_tmofunc);
  1493. vport->els_tmofunc.function = lpfc_els_timeout;
  1494. vport->els_tmofunc.data = (unsigned long)vport;
  1495. error = scsi_add_host(shost, dev);
  1496. if (error)
  1497. goto out_put_shost;
  1498. spin_lock_irq(&phba->hbalock);
  1499. list_add_tail(&vport->listentry, &phba->port_list);
  1500. spin_unlock_irq(&phba->hbalock);
  1501. return vport;
  1502. out_put_shost:
  1503. scsi_host_put(shost);
  1504. out:
  1505. return NULL;
  1506. }
  1507. void
  1508. destroy_port(struct lpfc_vport *vport)
  1509. {
  1510. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1511. struct lpfc_hba *phba = vport->phba;
  1512. kfree(vport->vname);
  1513. lpfc_debugfs_terminate(vport);
  1514. fc_remove_host(shost);
  1515. scsi_remove_host(shost);
  1516. spin_lock_irq(&phba->hbalock);
  1517. list_del_init(&vport->listentry);
  1518. spin_unlock_irq(&phba->hbalock);
  1519. lpfc_cleanup(vport);
  1520. return;
  1521. }
  1522. int
  1523. lpfc_get_instance(void)
  1524. {
  1525. int instance = 0;
  1526. /* Assign an unused number */
  1527. if (!idr_pre_get(&lpfc_hba_index, GFP_KERNEL))
  1528. return -1;
  1529. if (idr_get_new(&lpfc_hba_index, NULL, &instance))
  1530. return -1;
  1531. return instance;
  1532. }
  1533. /*
  1534. * Note: there is no scan_start function as adapter initialization
  1535. * will have asynchronously kicked off the link initialization.
  1536. */
  1537. int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
  1538. {
  1539. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1540. struct lpfc_hba *phba = vport->phba;
  1541. int stat = 0;
  1542. spin_lock_irq(shost->host_lock);
  1543. if (vport->load_flag & FC_UNLOADING) {
  1544. stat = 1;
  1545. goto finished;
  1546. }
  1547. if (time >= 30 * HZ) {
  1548. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  1549. "0461 Scanning longer than 30 "
  1550. "seconds. Continuing initialization\n");
  1551. stat = 1;
  1552. goto finished;
  1553. }
  1554. if (time >= 15 * HZ && phba->link_state <= LPFC_LINK_DOWN) {
  1555. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  1556. "0465 Link down longer than 15 "
  1557. "seconds. Continuing initialization\n");
  1558. stat = 1;
  1559. goto finished;
  1560. }
  1561. if (vport->port_state != LPFC_VPORT_READY)
  1562. goto finished;
  1563. if (vport->num_disc_nodes || vport->fc_prli_sent)
  1564. goto finished;
  1565. if (vport->fc_map_cnt == 0 && time < 2 * HZ)
  1566. goto finished;
  1567. if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
  1568. goto finished;
  1569. stat = 1;
  1570. finished:
  1571. spin_unlock_irq(shost->host_lock);
  1572. return stat;
  1573. }
  1574. void lpfc_host_attrib_init(struct Scsi_Host *shost)
  1575. {
  1576. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1577. struct lpfc_hba *phba = vport->phba;
  1578. /*
  1579. * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
  1580. */
  1581. fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
  1582. fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
  1583. fc_host_supported_classes(shost) = FC_COS_CLASS3;
  1584. memset(fc_host_supported_fc4s(shost), 0,
  1585. sizeof(fc_host_supported_fc4s(shost)));
  1586. fc_host_supported_fc4s(shost)[2] = 1;
  1587. fc_host_supported_fc4s(shost)[7] = 1;
  1588. lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
  1589. sizeof fc_host_symbolic_name(shost));
  1590. fc_host_supported_speeds(shost) = 0;
  1591. if (phba->lmt & LMT_10Gb)
  1592. fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
  1593. if (phba->lmt & LMT_8Gb)
  1594. fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT;
  1595. if (phba->lmt & LMT_4Gb)
  1596. fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
  1597. if (phba->lmt & LMT_2Gb)
  1598. fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
  1599. if (phba->lmt & LMT_1Gb)
  1600. fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
  1601. fc_host_maxframe_size(shost) =
  1602. (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
  1603. (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
  1604. /* This value is also unchanging */
  1605. memset(fc_host_active_fc4s(shost), 0,
  1606. sizeof(fc_host_active_fc4s(shost)));
  1607. fc_host_active_fc4s(shost)[2] = 1;
  1608. fc_host_active_fc4s(shost)[7] = 1;
  1609. fc_host_max_npiv_vports(shost) = phba->max_vpi;
  1610. spin_lock_irq(shost->host_lock);
  1611. vport->load_flag &= ~FC_LOADING;
  1612. spin_unlock_irq(shost->host_lock);
  1613. }
  1614. static int __devinit
  1615. lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
  1616. {
  1617. struct lpfc_vport *vport = NULL;
  1618. struct lpfc_hba *phba;
  1619. struct lpfc_sli *psli;
  1620. struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
  1621. struct Scsi_Host *shost = NULL;
  1622. void *ptr;
  1623. unsigned long bar0map_len, bar2map_len;
  1624. int error = -ENODEV, retval;
  1625. int i, hbq_count;
  1626. uint16_t iotag;
  1627. if (pci_enable_device(pdev))
  1628. goto out;
  1629. if (pci_request_regions(pdev, LPFC_DRIVER_NAME))
  1630. goto out_disable_device;
  1631. phba = kzalloc(sizeof (struct lpfc_hba), GFP_KERNEL);
  1632. if (!phba)
  1633. goto out_release_regions;
  1634. spin_lock_init(&phba->hbalock);
  1635. phba->pcidev = pdev;
  1636. /* Assign an unused board number */
  1637. if ((phba->brd_no = lpfc_get_instance()) < 0)
  1638. goto out_free_phba;
  1639. INIT_LIST_HEAD(&phba->port_list);
  1640. /*
  1641. * Get all the module params for configuring this host and then
  1642. * establish the host.
  1643. */
  1644. lpfc_get_cfgparam(phba);
  1645. phba->max_vpi = LPFC_MAX_VPI;
  1646. /* Initialize timers used by driver */
  1647. init_timer(&phba->fc_estabtmo);
  1648. phba->fc_estabtmo.function = lpfc_establish_link_tmo;
  1649. phba->fc_estabtmo.data = (unsigned long)phba;
  1650. init_timer(&phba->hb_tmofunc);
  1651. phba->hb_tmofunc.function = lpfc_hb_timeout;
  1652. phba->hb_tmofunc.data = (unsigned long)phba;
  1653. psli = &phba->sli;
  1654. init_timer(&psli->mbox_tmo);
  1655. psli->mbox_tmo.function = lpfc_mbox_timeout;
  1656. psli->mbox_tmo.data = (unsigned long) phba;
  1657. init_timer(&phba->fcp_poll_timer);
  1658. phba->fcp_poll_timer.function = lpfc_poll_timeout;
  1659. phba->fcp_poll_timer.data = (unsigned long) phba;
  1660. init_timer(&phba->fabric_block_timer);
  1661. phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
  1662. phba->fabric_block_timer.data = (unsigned long) phba;
  1663. pci_set_master(pdev);
  1664. pci_try_set_mwi(pdev);
  1665. if (pci_set_dma_mask(phba->pcidev, DMA_64BIT_MASK) != 0)
  1666. if (pci_set_dma_mask(phba->pcidev, DMA_32BIT_MASK) != 0)
  1667. goto out_idr_remove;
  1668. /*
  1669. * Get the bus address of Bar0 and Bar2 and the number of bytes
  1670. * required by each mapping.
  1671. */
  1672. phba->pci_bar0_map = pci_resource_start(phba->pcidev, 0);
  1673. bar0map_len = pci_resource_len(phba->pcidev, 0);
  1674. phba->pci_bar2_map = pci_resource_start(phba->pcidev, 2);
  1675. bar2map_len = pci_resource_len(phba->pcidev, 2);
  1676. /* Map HBA SLIM to a kernel virtual address. */
  1677. phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
  1678. if (!phba->slim_memmap_p) {
  1679. error = -ENODEV;
  1680. dev_printk(KERN_ERR, &pdev->dev,
  1681. "ioremap failed for SLIM memory.\n");
  1682. goto out_idr_remove;
  1683. }
  1684. /* Map HBA Control Registers to a kernel virtual address. */
  1685. phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
  1686. if (!phba->ctrl_regs_memmap_p) {
  1687. error = -ENODEV;
  1688. dev_printk(KERN_ERR, &pdev->dev,
  1689. "ioremap failed for HBA control registers.\n");
  1690. goto out_iounmap_slim;
  1691. }
  1692. /* Allocate memory for SLI-2 structures */
  1693. phba->slim2p = dma_alloc_coherent(&phba->pcidev->dev, SLI2_SLIM_SIZE,
  1694. &phba->slim2p_mapping, GFP_KERNEL);
  1695. if (!phba->slim2p)
  1696. goto out_iounmap;
  1697. memset(phba->slim2p, 0, SLI2_SLIM_SIZE);
  1698. phba->hbqslimp.virt = dma_alloc_coherent(&phba->pcidev->dev,
  1699. lpfc_sli_hbq_size(),
  1700. &phba->hbqslimp.phys,
  1701. GFP_KERNEL);
  1702. if (!phba->hbqslimp.virt)
  1703. goto out_free_slim;
  1704. hbq_count = lpfc_sli_hbq_count();
  1705. ptr = phba->hbqslimp.virt;
  1706. for (i = 0; i < hbq_count; ++i) {
  1707. phba->hbqs[i].hbq_virt = ptr;
  1708. INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
  1709. ptr += (lpfc_hbq_defs[i]->entry_count *
  1710. sizeof(struct lpfc_hbq_entry));
  1711. }
  1712. phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc;
  1713. phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free;
  1714. memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size());
  1715. /* Initialize the SLI Layer to run with lpfc HBAs. */
  1716. lpfc_sli_setup(phba);
  1717. lpfc_sli_queue_setup(phba);
  1718. retval = lpfc_mem_alloc(phba);
  1719. if (retval) {
  1720. error = retval;
  1721. goto out_free_hbqslimp;
  1722. }
  1723. /* Initialize and populate the iocb list per host. */
  1724. INIT_LIST_HEAD(&phba->lpfc_iocb_list);
  1725. for (i = 0; i < LPFC_IOCB_LIST_CNT; i++) {
  1726. iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
  1727. if (iocbq_entry == NULL) {
  1728. printk(KERN_ERR "%s: only allocated %d iocbs of "
  1729. "expected %d count. Unloading driver.\n",
  1730. __FUNCTION__, i, LPFC_IOCB_LIST_CNT);
  1731. error = -ENOMEM;
  1732. goto out_free_iocbq;
  1733. }
  1734. iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
  1735. if (iotag == 0) {
  1736. kfree (iocbq_entry);
  1737. printk(KERN_ERR "%s: failed to allocate IOTAG. "
  1738. "Unloading driver.\n",
  1739. __FUNCTION__);
  1740. error = -ENOMEM;
  1741. goto out_free_iocbq;
  1742. }
  1743. spin_lock_irq(&phba->hbalock);
  1744. list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
  1745. phba->total_iocbq_bufs++;
  1746. spin_unlock_irq(&phba->hbalock);
  1747. }
  1748. /* Initialize HBA structure */
  1749. phba->fc_edtov = FF_DEF_EDTOV;
  1750. phba->fc_ratov = FF_DEF_RATOV;
  1751. phba->fc_altov = FF_DEF_ALTOV;
  1752. phba->fc_arbtov = FF_DEF_ARBTOV;
  1753. INIT_LIST_HEAD(&phba->work_list);
  1754. phba->work_ha_mask = (HA_ERATT|HA_MBATT|HA_LATT);
  1755. phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
  1756. /* Startup the kernel thread for this host adapter. */
  1757. phba->worker_thread = kthread_run(lpfc_do_work, phba,
  1758. "lpfc_worker_%d", phba->brd_no);
  1759. if (IS_ERR(phba->worker_thread)) {
  1760. error = PTR_ERR(phba->worker_thread);
  1761. goto out_free_iocbq;
  1762. }
  1763. /* Initialize the list of scsi buffers used by driver for scsi IO. */
  1764. spin_lock_init(&phba->scsi_buf_list_lock);
  1765. INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list);
  1766. /* Initialize list of fabric iocbs */
  1767. INIT_LIST_HEAD(&phba->fabric_iocb_list);
  1768. vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev);
  1769. if (!vport)
  1770. goto out_kthread_stop;
  1771. shost = lpfc_shost_from_vport(vport);
  1772. phba->pport = vport;
  1773. lpfc_debugfs_initialize(vport);
  1774. pci_set_drvdata(pdev, shost);
  1775. if (phba->cfg_use_msi) {
  1776. retval = pci_enable_msi(phba->pcidev);
  1777. if (!retval)
  1778. phba->using_msi = 1;
  1779. else
  1780. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  1781. "0452 Enable MSI failed, continuing "
  1782. "with IRQ\n");
  1783. }
  1784. retval = request_irq(phba->pcidev->irq, lpfc_intr_handler, IRQF_SHARED,
  1785. LPFC_DRIVER_NAME, phba);
  1786. if (retval) {
  1787. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1788. "0451 Enable interrupt handler failed\n");
  1789. error = retval;
  1790. goto out_disable_msi;
  1791. }
  1792. phba->MBslimaddr = phba->slim_memmap_p;
  1793. phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
  1794. phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
  1795. phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
  1796. phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
  1797. if (lpfc_alloc_sysfs_attr(vport)) {
  1798. error = -ENOMEM;
  1799. goto out_free_irq;
  1800. }
  1801. if (lpfc_sli_hba_setup(phba)) {
  1802. error = -ENODEV;
  1803. goto out_remove_device;
  1804. }
  1805. /*
  1806. * hba setup may have changed the hba_queue_depth so we need to adjust
  1807. * the value of can_queue.
  1808. */
  1809. shost->can_queue = phba->cfg_hba_queue_depth - 10;
  1810. lpfc_host_attrib_init(shost);
  1811. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  1812. spin_lock_irq(shost->host_lock);
  1813. lpfc_poll_start_timer(phba);
  1814. spin_unlock_irq(shost->host_lock);
  1815. }
  1816. scsi_scan_host(shost);
  1817. return 0;
  1818. out_remove_device:
  1819. lpfc_free_sysfs_attr(vport);
  1820. spin_lock_irq(shost->host_lock);
  1821. vport->load_flag |= FC_UNLOADING;
  1822. spin_unlock_irq(shost->host_lock);
  1823. out_free_irq:
  1824. lpfc_stop_phba_timers(phba);
  1825. phba->pport->work_port_events = 0;
  1826. free_irq(phba->pcidev->irq, phba);
  1827. out_disable_msi:
  1828. if (phba->using_msi)
  1829. pci_disable_msi(phba->pcidev);
  1830. destroy_port(vport);
  1831. out_kthread_stop:
  1832. kthread_stop(phba->worker_thread);
  1833. out_free_iocbq:
  1834. list_for_each_entry_safe(iocbq_entry, iocbq_next,
  1835. &phba->lpfc_iocb_list, list) {
  1836. kfree(iocbq_entry);
  1837. phba->total_iocbq_bufs--;
  1838. }
  1839. lpfc_mem_free(phba);
  1840. out_free_hbqslimp:
  1841. dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), phba->hbqslimp.virt,
  1842. phba->hbqslimp.phys);
  1843. out_free_slim:
  1844. dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, phba->slim2p,
  1845. phba->slim2p_mapping);
  1846. out_iounmap:
  1847. iounmap(phba->ctrl_regs_memmap_p);
  1848. out_iounmap_slim:
  1849. iounmap(phba->slim_memmap_p);
  1850. out_idr_remove:
  1851. idr_remove(&lpfc_hba_index, phba->brd_no);
  1852. out_free_phba:
  1853. kfree(phba);
  1854. out_release_regions:
  1855. pci_release_regions(pdev);
  1856. out_disable_device:
  1857. pci_disable_device(pdev);
  1858. out:
  1859. pci_set_drvdata(pdev, NULL);
  1860. if (shost)
  1861. scsi_host_put(shost);
  1862. return error;
  1863. }
  1864. static void __devexit
  1865. lpfc_pci_remove_one(struct pci_dev *pdev)
  1866. {
  1867. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  1868. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1869. struct lpfc_hba *phba = vport->phba;
  1870. spin_lock_irq(&phba->hbalock);
  1871. vport->load_flag |= FC_UNLOADING;
  1872. spin_unlock_irq(&phba->hbalock);
  1873. kfree(vport->vname);
  1874. lpfc_free_sysfs_attr(vport);
  1875. fc_remove_host(shost);
  1876. scsi_remove_host(shost);
  1877. lpfc_cleanup(vport);
  1878. /*
  1879. * Bring down the SLI Layer. This step disable all interrupts,
  1880. * clears the rings, discards all mailbox commands, and resets
  1881. * the HBA.
  1882. */
  1883. lpfc_sli_hba_down(phba);
  1884. lpfc_sli_brdrestart(phba);
  1885. lpfc_stop_phba_timers(phba);
  1886. spin_lock_irq(&phba->hbalock);
  1887. list_del_init(&vport->listentry);
  1888. spin_unlock_irq(&phba->hbalock);
  1889. lpfc_debugfs_terminate(vport);
  1890. kthread_stop(phba->worker_thread);
  1891. /* Release the irq reservation */
  1892. free_irq(phba->pcidev->irq, phba);
  1893. if (phba->using_msi)
  1894. pci_disable_msi(phba->pcidev);
  1895. pci_set_drvdata(pdev, NULL);
  1896. scsi_host_put(shost);
  1897. /*
  1898. * Call scsi_free before mem_free since scsi bufs are released to their
  1899. * corresponding pools here.
  1900. */
  1901. lpfc_scsi_free(phba);
  1902. lpfc_mem_free(phba);
  1903. dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), phba->hbqslimp.virt,
  1904. phba->hbqslimp.phys);
  1905. /* Free resources associated with SLI2 interface */
  1906. dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
  1907. phba->slim2p, phba->slim2p_mapping);
  1908. /* unmap adapter SLIM and Control Registers */
  1909. iounmap(phba->ctrl_regs_memmap_p);
  1910. iounmap(phba->slim_memmap_p);
  1911. idr_remove(&lpfc_hba_index, phba->brd_no);
  1912. kfree(phba);
  1913. pci_release_regions(pdev);
  1914. pci_disable_device(pdev);
  1915. }
  1916. /**
  1917. * lpfc_io_error_detected - called when PCI error is detected
  1918. * @pdev: Pointer to PCI device
  1919. * @state: The current pci conneection state
  1920. *
  1921. * This function is called after a PCI bus error affecting
  1922. * this device has been detected.
  1923. */
  1924. static pci_ers_result_t lpfc_io_error_detected(struct pci_dev *pdev,
  1925. pci_channel_state_t state)
  1926. {
  1927. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  1928. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  1929. struct lpfc_sli *psli = &phba->sli;
  1930. struct lpfc_sli_ring *pring;
  1931. if (state == pci_channel_io_perm_failure)
  1932. return PCI_ERS_RESULT_DISCONNECT;
  1933. pci_disable_device(pdev);
  1934. /*
  1935. * There may be I/Os dropped by the firmware.
  1936. * Error iocb (I/O) on txcmplq and let the SCSI layer
  1937. * retry it after re-establishing link.
  1938. */
  1939. pring = &psli->ring[psli->fcp_ring];
  1940. lpfc_sli_abort_iocb_ring(phba, pring);
  1941. /* Release the irq reservation */
  1942. free_irq(phba->pcidev->irq, phba);
  1943. if (phba->using_msi)
  1944. pci_disable_msi(phba->pcidev);
  1945. /* Request a slot reset. */
  1946. return PCI_ERS_RESULT_NEED_RESET;
  1947. }
  1948. /**
  1949. * lpfc_io_slot_reset - called after the pci bus has been reset.
  1950. * @pdev: Pointer to PCI device
  1951. *
  1952. * Restart the card from scratch, as if from a cold-boot.
  1953. */
  1954. static pci_ers_result_t lpfc_io_slot_reset(struct pci_dev *pdev)
  1955. {
  1956. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  1957. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  1958. struct lpfc_sli *psli = &phba->sli;
  1959. int bars = pci_select_bars(pdev, IORESOURCE_MEM);
  1960. dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
  1961. if (pci_enable_device_bars(pdev, bars)) {
  1962. printk(KERN_ERR "lpfc: Cannot re-enable "
  1963. "PCI device after reset.\n");
  1964. return PCI_ERS_RESULT_DISCONNECT;
  1965. }
  1966. pci_set_master(pdev);
  1967. /* Re-establishing Link */
  1968. spin_lock_irq(shost->host_lock);
  1969. phba->pport->fc_flag |= FC_ESTABLISH_LINK;
  1970. spin_unlock_irq(shost->host_lock);
  1971. spin_lock_irq(&phba->hbalock);
  1972. psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
  1973. spin_unlock_irq(&phba->hbalock);
  1974. /* Take device offline; this will perform cleanup */
  1975. lpfc_offline(phba);
  1976. lpfc_sli_brdrestart(phba);
  1977. return PCI_ERS_RESULT_RECOVERED;
  1978. }
  1979. /**
  1980. * lpfc_io_resume - called when traffic can start flowing again.
  1981. * @pdev: Pointer to PCI device
  1982. *
  1983. * This callback is called when the error recovery driver tells us that
  1984. * its OK to resume normal operation.
  1985. */
  1986. static void lpfc_io_resume(struct pci_dev *pdev)
  1987. {
  1988. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  1989. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  1990. if (lpfc_online(phba) == 0) {
  1991. mod_timer(&phba->fc_estabtmo, jiffies + HZ * 60);
  1992. }
  1993. }
  1994. static struct pci_device_id lpfc_id_table[] = {
  1995. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER,
  1996. PCI_ANY_ID, PCI_ANY_ID, },
  1997. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY,
  1998. PCI_ANY_ID, PCI_ANY_ID, },
  1999. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR,
  2000. PCI_ANY_ID, PCI_ANY_ID, },
  2001. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS,
  2002. PCI_ANY_ID, PCI_ANY_ID, },
  2003. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR,
  2004. PCI_ANY_ID, PCI_ANY_ID, },
  2005. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY,
  2006. PCI_ANY_ID, PCI_ANY_ID, },
  2007. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY,
  2008. PCI_ANY_ID, PCI_ANY_ID, },
  2009. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY,
  2010. PCI_ANY_ID, PCI_ANY_ID, },
  2011. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY,
  2012. PCI_ANY_ID, PCI_ANY_ID, },
  2013. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE,
  2014. PCI_ANY_ID, PCI_ANY_ID, },
  2015. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP,
  2016. PCI_ANY_ID, PCI_ANY_ID, },
  2017. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP,
  2018. PCI_ANY_ID, PCI_ANY_ID, },
  2019. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS,
  2020. PCI_ANY_ID, PCI_ANY_ID, },
  2021. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP,
  2022. PCI_ANY_ID, PCI_ANY_ID, },
  2023. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP,
  2024. PCI_ANY_ID, PCI_ANY_ID, },
  2025. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID,
  2026. PCI_ANY_ID, PCI_ANY_ID, },
  2027. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB,
  2028. PCI_ANY_ID, PCI_ANY_ID, },
  2029. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR,
  2030. PCI_ANY_ID, PCI_ANY_ID, },
  2031. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP,
  2032. PCI_ANY_ID, PCI_ANY_ID, },
  2033. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP,
  2034. PCI_ANY_ID, PCI_ANY_ID, },
  2035. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID,
  2036. PCI_ANY_ID, PCI_ANY_ID, },
  2037. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB,
  2038. PCI_ANY_ID, PCI_ANY_ID, },
  2039. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY,
  2040. PCI_ANY_ID, PCI_ANY_ID, },
  2041. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101,
  2042. PCI_ANY_ID, PCI_ANY_ID, },
  2043. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S,
  2044. PCI_ANY_ID, PCI_ANY_ID, },
  2045. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S,
  2046. PCI_ANY_ID, PCI_ANY_ID, },
  2047. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S,
  2048. PCI_ANY_ID, PCI_ANY_ID, },
  2049. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT,
  2050. PCI_ANY_ID, PCI_ANY_ID, },
  2051. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID,
  2052. PCI_ANY_ID, PCI_ANY_ID, },
  2053. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB,
  2054. PCI_ANY_ID, PCI_ANY_ID, },
  2055. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP,
  2056. PCI_ANY_ID, PCI_ANY_ID, },
  2057. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP,
  2058. PCI_ANY_ID, PCI_ANY_ID, },
  2059. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S,
  2060. PCI_ANY_ID, PCI_ANY_ID, },
  2061. { 0 }
  2062. };
  2063. MODULE_DEVICE_TABLE(pci, lpfc_id_table);
  2064. static struct pci_error_handlers lpfc_err_handler = {
  2065. .error_detected = lpfc_io_error_detected,
  2066. .slot_reset = lpfc_io_slot_reset,
  2067. .resume = lpfc_io_resume,
  2068. };
  2069. static struct pci_driver lpfc_driver = {
  2070. .name = LPFC_DRIVER_NAME,
  2071. .id_table = lpfc_id_table,
  2072. .probe = lpfc_pci_probe_one,
  2073. .remove = __devexit_p(lpfc_pci_remove_one),
  2074. .err_handler = &lpfc_err_handler,
  2075. };
  2076. static int __init
  2077. lpfc_init(void)
  2078. {
  2079. int error = 0;
  2080. printk(LPFC_MODULE_DESC "\n");
  2081. printk(LPFC_COPYRIGHT "\n");
  2082. if (lpfc_enable_npiv) {
  2083. lpfc_transport_functions.vport_create = lpfc_vport_create;
  2084. lpfc_transport_functions.vport_delete = lpfc_vport_delete;
  2085. }
  2086. lpfc_transport_template =
  2087. fc_attach_transport(&lpfc_transport_functions);
  2088. if (lpfc_transport_template == NULL)
  2089. return -ENOMEM;
  2090. if (lpfc_enable_npiv) {
  2091. lpfc_vport_transport_template =
  2092. fc_attach_transport(&lpfc_vport_transport_functions);
  2093. if (lpfc_vport_transport_template == NULL) {
  2094. fc_release_transport(lpfc_transport_template);
  2095. return -ENOMEM;
  2096. }
  2097. }
  2098. error = pci_register_driver(&lpfc_driver);
  2099. if (error) {
  2100. fc_release_transport(lpfc_transport_template);
  2101. fc_release_transport(lpfc_vport_transport_template);
  2102. }
  2103. return error;
  2104. }
  2105. static void __exit
  2106. lpfc_exit(void)
  2107. {
  2108. pci_unregister_driver(&lpfc_driver);
  2109. fc_release_transport(lpfc_transport_template);
  2110. if (lpfc_enable_npiv)
  2111. fc_release_transport(lpfc_vport_transport_template);
  2112. }
  2113. module_init(lpfc_init);
  2114. module_exit(lpfc_exit);
  2115. MODULE_LICENSE("GPL");
  2116. MODULE_DESCRIPTION(LPFC_MODULE_DESC);
  2117. MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com");
  2118. MODULE_VERSION("0:" LPFC_DRIVER_VERSION);