lpfc_init.c 73 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2008 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. struct lpfc_vport **vports;
  414. int i;
  415. /* Disable interrupts */
  416. writel(0, phba->HCregaddr);
  417. readl(phba->HCregaddr); /* flush */
  418. if (phba->pport->load_flag & FC_UNLOADING)
  419. lpfc_cleanup_discovery_resources(phba->pport);
  420. else {
  421. vports = lpfc_create_vport_work_array(phba);
  422. if (vports != NULL)
  423. for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++)
  424. lpfc_cleanup_discovery_resources(vports[i]);
  425. lpfc_destroy_vport_work_array(phba, vports);
  426. }
  427. return 0;
  428. }
  429. /************************************************************************/
  430. /* */
  431. /* lpfc_hba_down_post */
  432. /* This routine will do uninitialization after the HBA is reset */
  433. /* when bringing down the SLI Layer. */
  434. /* This routine returns 0 on success. Any other return value */
  435. /* indicates an error. */
  436. /* */
  437. /************************************************************************/
  438. int
  439. lpfc_hba_down_post(struct lpfc_hba *phba)
  440. {
  441. struct lpfc_sli *psli = &phba->sli;
  442. struct lpfc_sli_ring *pring;
  443. struct lpfc_dmabuf *mp, *next_mp;
  444. struct lpfc_iocbq *iocb;
  445. IOCB_t *cmd = NULL;
  446. LIST_HEAD(completions);
  447. int i;
  448. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
  449. lpfc_sli_hbqbuf_free_all(phba);
  450. else {
  451. /* Cleanup preposted buffers on the ELS ring */
  452. pring = &psli->ring[LPFC_ELS_RING];
  453. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  454. list_del(&mp->list);
  455. pring->postbufq_cnt--;
  456. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  457. kfree(mp);
  458. }
  459. }
  460. spin_lock_irq(&phba->hbalock);
  461. for (i = 0; i < psli->num_rings; i++) {
  462. pring = &psli->ring[i];
  463. /* At this point in time the HBA is either reset or DOA. Either
  464. * way, nothing should be on txcmplq as it will NEVER complete.
  465. */
  466. list_splice_init(&pring->txcmplq, &completions);
  467. pring->txcmplq_cnt = 0;
  468. spin_unlock_irq(&phba->hbalock);
  469. while (!list_empty(&completions)) {
  470. iocb = list_get_first(&completions, struct lpfc_iocbq,
  471. list);
  472. cmd = &iocb->iocb;
  473. list_del_init(&iocb->list);
  474. if (!iocb->iocb_cmpl)
  475. lpfc_sli_release_iocbq(phba, iocb);
  476. else {
  477. cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
  478. cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
  479. (iocb->iocb_cmpl) (phba, iocb, iocb);
  480. }
  481. }
  482. lpfc_sli_abort_iocb_ring(phba, pring);
  483. spin_lock_irq(&phba->hbalock);
  484. }
  485. spin_unlock_irq(&phba->hbalock);
  486. return 0;
  487. }
  488. /* HBA heart beat timeout handler */
  489. static void
  490. lpfc_hb_timeout(unsigned long ptr)
  491. {
  492. struct lpfc_hba *phba;
  493. unsigned long iflag;
  494. phba = (struct lpfc_hba *)ptr;
  495. spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
  496. if (!(phba->pport->work_port_events & WORKER_HB_TMO))
  497. phba->pport->work_port_events |= WORKER_HB_TMO;
  498. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
  499. spin_lock_irqsave(&phba->hbalock, iflag);
  500. if (phba->work_wait)
  501. wake_up(phba->work_wait);
  502. spin_unlock_irqrestore(&phba->hbalock, iflag);
  503. return;
  504. }
  505. static void
  506. lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
  507. {
  508. unsigned long drvr_flag;
  509. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  510. phba->hb_outstanding = 0;
  511. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  512. mempool_free(pmboxq, phba->mbox_mem_pool);
  513. if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) &&
  514. !(phba->link_state == LPFC_HBA_ERROR) &&
  515. !(phba->pport->load_flag & FC_UNLOADING))
  516. mod_timer(&phba->hb_tmofunc,
  517. jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  518. return;
  519. }
  520. void
  521. lpfc_hb_timeout_handler(struct lpfc_hba *phba)
  522. {
  523. LPFC_MBOXQ_t *pmboxq;
  524. struct lpfc_dmabuf *buf_ptr;
  525. int retval;
  526. struct lpfc_sli *psli = &phba->sli;
  527. LIST_HEAD(completions);
  528. if ((phba->link_state == LPFC_HBA_ERROR) ||
  529. (phba->pport->load_flag & FC_UNLOADING) ||
  530. (phba->pport->fc_flag & FC_OFFLINE_MODE))
  531. return;
  532. spin_lock_irq(&phba->pport->work_port_lock);
  533. /* If the timer is already canceled do nothing */
  534. if (!(phba->pport->work_port_events & WORKER_HB_TMO)) {
  535. spin_unlock_irq(&phba->pport->work_port_lock);
  536. return;
  537. }
  538. if (time_after(phba->last_completion_time + LPFC_HB_MBOX_INTERVAL * HZ,
  539. jiffies)) {
  540. spin_unlock_irq(&phba->pport->work_port_lock);
  541. if (!phba->hb_outstanding)
  542. mod_timer(&phba->hb_tmofunc,
  543. jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  544. else
  545. mod_timer(&phba->hb_tmofunc,
  546. jiffies + HZ * LPFC_HB_MBOX_TIMEOUT);
  547. return;
  548. }
  549. spin_unlock_irq(&phba->pport->work_port_lock);
  550. if (phba->elsbuf_cnt &&
  551. (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) {
  552. spin_lock_irq(&phba->hbalock);
  553. list_splice_init(&phba->elsbuf, &completions);
  554. phba->elsbuf_cnt = 0;
  555. phba->elsbuf_prev_cnt = 0;
  556. spin_unlock_irq(&phba->hbalock);
  557. while (!list_empty(&completions)) {
  558. list_remove_head(&completions, buf_ptr,
  559. struct lpfc_dmabuf, list);
  560. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  561. kfree(buf_ptr);
  562. }
  563. }
  564. phba->elsbuf_prev_cnt = phba->elsbuf_cnt;
  565. /* If there is no heart beat outstanding, issue a heartbeat command */
  566. if (phba->cfg_enable_hba_heartbeat) {
  567. if (!phba->hb_outstanding) {
  568. pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
  569. if (!pmboxq) {
  570. mod_timer(&phba->hb_tmofunc,
  571. jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  572. return;
  573. }
  574. lpfc_heart_beat(phba, pmboxq);
  575. pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl;
  576. pmboxq->vport = phba->pport;
  577. retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
  578. if (retval != MBX_BUSY && retval != MBX_SUCCESS) {
  579. mempool_free(pmboxq, phba->mbox_mem_pool);
  580. mod_timer(&phba->hb_tmofunc,
  581. jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  582. return;
  583. }
  584. mod_timer(&phba->hb_tmofunc,
  585. jiffies + HZ * LPFC_HB_MBOX_TIMEOUT);
  586. phba->hb_outstanding = 1;
  587. return;
  588. } else {
  589. /*
  590. * If heart beat timeout called with hb_outstanding set
  591. * we need to take the HBA offline.
  592. */
  593. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  594. "0459 Adapter heartbeat failure, "
  595. "taking this port offline.\n");
  596. spin_lock_irq(&phba->hbalock);
  597. psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
  598. spin_unlock_irq(&phba->hbalock);
  599. lpfc_offline_prep(phba);
  600. lpfc_offline(phba);
  601. lpfc_unblock_mgmt_io(phba);
  602. phba->link_state = LPFC_HBA_ERROR;
  603. lpfc_hba_down_post(phba);
  604. }
  605. }
  606. }
  607. static void
  608. lpfc_offline_eratt(struct lpfc_hba *phba)
  609. {
  610. struct lpfc_sli *psli = &phba->sli;
  611. spin_lock_irq(&phba->hbalock);
  612. psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
  613. spin_unlock_irq(&phba->hbalock);
  614. lpfc_offline_prep(phba);
  615. lpfc_offline(phba);
  616. lpfc_reset_barrier(phba);
  617. lpfc_sli_brdreset(phba);
  618. lpfc_hba_down_post(phba);
  619. lpfc_sli_brdready(phba, HS_MBRDY);
  620. lpfc_unblock_mgmt_io(phba);
  621. phba->link_state = LPFC_HBA_ERROR;
  622. return;
  623. }
  624. /************************************************************************/
  625. /* */
  626. /* lpfc_handle_eratt */
  627. /* This routine will handle processing a Host Attention */
  628. /* Error Status event. This will be initialized */
  629. /* as a SLI layer callback routine. */
  630. /* */
  631. /************************************************************************/
  632. void
  633. lpfc_handle_eratt(struct lpfc_hba *phba)
  634. {
  635. struct lpfc_vport *vport = phba->pport;
  636. struct lpfc_sli *psli = &phba->sli;
  637. struct lpfc_sli_ring *pring;
  638. uint32_t event_data;
  639. unsigned long temperature;
  640. struct temp_event temp_event_data;
  641. struct Scsi_Host *shost;
  642. /* If the pci channel is offline, ignore possible errors,
  643. * since we cannot communicate with the pci card anyway. */
  644. if (pci_channel_offline(phba->pcidev))
  645. return;
  646. /* If resets are disabled then leave the HBA alone and return */
  647. if (!phba->cfg_enable_hba_reset)
  648. return;
  649. if (phba->work_hs & HS_FFER6) {
  650. /* Re-establishing Link */
  651. lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
  652. "1301 Re-establishing Link "
  653. "Data: x%x x%x x%x\n",
  654. phba->work_hs,
  655. phba->work_status[0], phba->work_status[1]);
  656. spin_lock_irq(&phba->hbalock);
  657. psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
  658. spin_unlock_irq(&phba->hbalock);
  659. /*
  660. * Firmware stops when it triggled erratt with HS_FFER6.
  661. * That could cause the I/Os dropped by the firmware.
  662. * Error iocb (I/O) on txcmplq and let the SCSI layer
  663. * retry it after re-establishing link.
  664. */
  665. pring = &psli->ring[psli->fcp_ring];
  666. lpfc_sli_abort_iocb_ring(phba, pring);
  667. /*
  668. * There was a firmware error. Take the hba offline and then
  669. * attempt to restart it.
  670. */
  671. lpfc_offline_prep(phba);
  672. lpfc_offline(phba);
  673. lpfc_sli_brdrestart(phba);
  674. if (lpfc_online(phba) == 0) { /* Initialize the HBA */
  675. lpfc_unblock_mgmt_io(phba);
  676. return;
  677. }
  678. lpfc_unblock_mgmt_io(phba);
  679. } else if (phba->work_hs & HS_CRIT_TEMP) {
  680. temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET);
  681. temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
  682. temp_event_data.event_code = LPFC_CRIT_TEMP;
  683. temp_event_data.data = (uint32_t)temperature;
  684. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  685. "0459 Adapter maximum temperature exceeded "
  686. "(%ld), taking this port offline "
  687. "Data: x%x x%x x%x\n",
  688. temperature, phba->work_hs,
  689. phba->work_status[0], phba->work_status[1]);
  690. shost = lpfc_shost_from_vport(phba->pport);
  691. fc_host_post_vendor_event(shost, fc_get_event_number(),
  692. sizeof(temp_event_data),
  693. (char *) &temp_event_data,
  694. SCSI_NL_VID_TYPE_PCI
  695. | PCI_VENDOR_ID_EMULEX);
  696. spin_lock_irq(&phba->hbalock);
  697. phba->over_temp_state = HBA_OVER_TEMP;
  698. spin_unlock_irq(&phba->hbalock);
  699. lpfc_offline_eratt(phba);
  700. } else {
  701. /* The if clause above forces this code path when the status
  702. * failure is a value other than FFER6. Do not call the offline
  703. * twice. This is the adapter hardware error path.
  704. */
  705. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  706. "0457 Adapter Hardware Error "
  707. "Data: x%x x%x x%x\n",
  708. phba->work_hs,
  709. phba->work_status[0], phba->work_status[1]);
  710. event_data = FC_REG_DUMP_EVENT;
  711. shost = lpfc_shost_from_vport(vport);
  712. fc_host_post_vendor_event(shost, fc_get_event_number(),
  713. sizeof(event_data), (char *) &event_data,
  714. SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
  715. lpfc_offline_eratt(phba);
  716. }
  717. }
  718. /************************************************************************/
  719. /* */
  720. /* lpfc_handle_latt */
  721. /* This routine will handle processing a Host Attention */
  722. /* Link Status event. This will be initialized */
  723. /* as a SLI layer callback routine. */
  724. /* */
  725. /************************************************************************/
  726. void
  727. lpfc_handle_latt(struct lpfc_hba *phba)
  728. {
  729. struct lpfc_vport *vport = phba->pport;
  730. struct lpfc_sli *psli = &phba->sli;
  731. LPFC_MBOXQ_t *pmb;
  732. volatile uint32_t control;
  733. struct lpfc_dmabuf *mp;
  734. int rc = 0;
  735. pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  736. if (!pmb) {
  737. rc = 1;
  738. goto lpfc_handle_latt_err_exit;
  739. }
  740. mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  741. if (!mp) {
  742. rc = 2;
  743. goto lpfc_handle_latt_free_pmb;
  744. }
  745. mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
  746. if (!mp->virt) {
  747. rc = 3;
  748. goto lpfc_handle_latt_free_mp;
  749. }
  750. /* Cleanup any outstanding ELS commands */
  751. lpfc_els_flush_all_cmd(phba);
  752. psli->slistat.link_event++;
  753. lpfc_read_la(phba, pmb, mp);
  754. pmb->mbox_cmpl = lpfc_mbx_cmpl_read_la;
  755. pmb->vport = vport;
  756. rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT);
  757. if (rc == MBX_NOT_FINISHED) {
  758. rc = 4;
  759. goto lpfc_handle_latt_free_mbuf;
  760. }
  761. /* Clear Link Attention in HA REG */
  762. spin_lock_irq(&phba->hbalock);
  763. writel(HA_LATT, phba->HAregaddr);
  764. readl(phba->HAregaddr); /* flush */
  765. spin_unlock_irq(&phba->hbalock);
  766. return;
  767. lpfc_handle_latt_free_mbuf:
  768. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  769. lpfc_handle_latt_free_mp:
  770. kfree(mp);
  771. lpfc_handle_latt_free_pmb:
  772. mempool_free(pmb, phba->mbox_mem_pool);
  773. lpfc_handle_latt_err_exit:
  774. /* Enable Link attention interrupts */
  775. spin_lock_irq(&phba->hbalock);
  776. psli->sli_flag |= LPFC_PROCESS_LA;
  777. control = readl(phba->HCregaddr);
  778. control |= HC_LAINT_ENA;
  779. writel(control, phba->HCregaddr);
  780. readl(phba->HCregaddr); /* flush */
  781. /* Clear Link Attention in HA REG */
  782. writel(HA_LATT, phba->HAregaddr);
  783. readl(phba->HAregaddr); /* flush */
  784. spin_unlock_irq(&phba->hbalock);
  785. lpfc_linkdown(phba);
  786. phba->link_state = LPFC_HBA_ERROR;
  787. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  788. "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc);
  789. return;
  790. }
  791. /************************************************************************/
  792. /* */
  793. /* lpfc_parse_vpd */
  794. /* This routine will parse the VPD data */
  795. /* */
  796. /************************************************************************/
  797. static int
  798. lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len)
  799. {
  800. uint8_t lenlo, lenhi;
  801. int Length;
  802. int i, j;
  803. int finished = 0;
  804. int index = 0;
  805. if (!vpd)
  806. return 0;
  807. /* Vital Product */
  808. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  809. "0455 Vital Product Data: x%x x%x x%x x%x\n",
  810. (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
  811. (uint32_t) vpd[3]);
  812. while (!finished && (index < (len - 4))) {
  813. switch (vpd[index]) {
  814. case 0x82:
  815. case 0x91:
  816. index += 1;
  817. lenlo = vpd[index];
  818. index += 1;
  819. lenhi = vpd[index];
  820. index += 1;
  821. i = ((((unsigned short)lenhi) << 8) + lenlo);
  822. index += i;
  823. break;
  824. case 0x90:
  825. index += 1;
  826. lenlo = vpd[index];
  827. index += 1;
  828. lenhi = vpd[index];
  829. index += 1;
  830. Length = ((((unsigned short)lenhi) << 8) + lenlo);
  831. if (Length > len - index)
  832. Length = len - index;
  833. while (Length > 0) {
  834. /* Look for Serial Number */
  835. if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) {
  836. index += 2;
  837. i = vpd[index];
  838. index += 1;
  839. j = 0;
  840. Length -= (3+i);
  841. while(i--) {
  842. phba->SerialNumber[j++] = vpd[index++];
  843. if (j == 31)
  844. break;
  845. }
  846. phba->SerialNumber[j] = 0;
  847. continue;
  848. }
  849. else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) {
  850. phba->vpd_flag |= VPD_MODEL_DESC;
  851. index += 2;
  852. i = vpd[index];
  853. index += 1;
  854. j = 0;
  855. Length -= (3+i);
  856. while(i--) {
  857. phba->ModelDesc[j++] = vpd[index++];
  858. if (j == 255)
  859. break;
  860. }
  861. phba->ModelDesc[j] = 0;
  862. continue;
  863. }
  864. else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) {
  865. phba->vpd_flag |= VPD_MODEL_NAME;
  866. index += 2;
  867. i = vpd[index];
  868. index += 1;
  869. j = 0;
  870. Length -= (3+i);
  871. while(i--) {
  872. phba->ModelName[j++] = vpd[index++];
  873. if (j == 79)
  874. break;
  875. }
  876. phba->ModelName[j] = 0;
  877. continue;
  878. }
  879. else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) {
  880. phba->vpd_flag |= VPD_PROGRAM_TYPE;
  881. index += 2;
  882. i = vpd[index];
  883. index += 1;
  884. j = 0;
  885. Length -= (3+i);
  886. while(i--) {
  887. phba->ProgramType[j++] = vpd[index++];
  888. if (j == 255)
  889. break;
  890. }
  891. phba->ProgramType[j] = 0;
  892. continue;
  893. }
  894. else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) {
  895. phba->vpd_flag |= VPD_PORT;
  896. index += 2;
  897. i = vpd[index];
  898. index += 1;
  899. j = 0;
  900. Length -= (3+i);
  901. while(i--) {
  902. phba->Port[j++] = vpd[index++];
  903. if (j == 19)
  904. break;
  905. }
  906. phba->Port[j] = 0;
  907. continue;
  908. }
  909. else {
  910. index += 2;
  911. i = vpd[index];
  912. index += 1;
  913. index += i;
  914. Length -= (3 + i);
  915. }
  916. }
  917. finished = 0;
  918. break;
  919. case 0x78:
  920. finished = 1;
  921. break;
  922. default:
  923. index ++;
  924. break;
  925. }
  926. }
  927. return(1);
  928. }
  929. static void
  930. lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
  931. {
  932. lpfc_vpd_t *vp;
  933. uint16_t dev_id = phba->pcidev->device;
  934. int max_speed;
  935. struct {
  936. char * name;
  937. int max_speed;
  938. char * bus;
  939. } m = {"<Unknown>", 0, ""};
  940. if (mdp && mdp[0] != '\0'
  941. && descp && descp[0] != '\0')
  942. return;
  943. if (phba->lmt & LMT_10Gb)
  944. max_speed = 10;
  945. else if (phba->lmt & LMT_8Gb)
  946. max_speed = 8;
  947. else if (phba->lmt & LMT_4Gb)
  948. max_speed = 4;
  949. else if (phba->lmt & LMT_2Gb)
  950. max_speed = 2;
  951. else
  952. max_speed = 1;
  953. vp = &phba->vpd;
  954. switch (dev_id) {
  955. case PCI_DEVICE_ID_FIREFLY:
  956. m = (typeof(m)){"LP6000", max_speed, "PCI"};
  957. break;
  958. case PCI_DEVICE_ID_SUPERFLY:
  959. if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
  960. m = (typeof(m)){"LP7000", max_speed, "PCI"};
  961. else
  962. m = (typeof(m)){"LP7000E", max_speed, "PCI"};
  963. break;
  964. case PCI_DEVICE_ID_DRAGONFLY:
  965. m = (typeof(m)){"LP8000", max_speed, "PCI"};
  966. break;
  967. case PCI_DEVICE_ID_CENTAUR:
  968. if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
  969. m = (typeof(m)){"LP9002", max_speed, "PCI"};
  970. else
  971. m = (typeof(m)){"LP9000", max_speed, "PCI"};
  972. break;
  973. case PCI_DEVICE_ID_RFLY:
  974. m = (typeof(m)){"LP952", max_speed, "PCI"};
  975. break;
  976. case PCI_DEVICE_ID_PEGASUS:
  977. m = (typeof(m)){"LP9802", max_speed, "PCI-X"};
  978. break;
  979. case PCI_DEVICE_ID_THOR:
  980. m = (typeof(m)){"LP10000", max_speed, "PCI-X"};
  981. break;
  982. case PCI_DEVICE_ID_VIPER:
  983. m = (typeof(m)){"LPX1000", max_speed, "PCI-X"};
  984. break;
  985. case PCI_DEVICE_ID_PFLY:
  986. m = (typeof(m)){"LP982", max_speed, "PCI-X"};
  987. break;
  988. case PCI_DEVICE_ID_TFLY:
  989. m = (typeof(m)){"LP1050", max_speed, "PCI-X"};
  990. break;
  991. case PCI_DEVICE_ID_HELIOS:
  992. m = (typeof(m)){"LP11000", max_speed, "PCI-X2"};
  993. break;
  994. case PCI_DEVICE_ID_HELIOS_SCSP:
  995. m = (typeof(m)){"LP11000-SP", max_speed, "PCI-X2"};
  996. break;
  997. case PCI_DEVICE_ID_HELIOS_DCSP:
  998. m = (typeof(m)){"LP11002-SP", max_speed, "PCI-X2"};
  999. break;
  1000. case PCI_DEVICE_ID_NEPTUNE:
  1001. m = (typeof(m)){"LPe1000", max_speed, "PCIe"};
  1002. break;
  1003. case PCI_DEVICE_ID_NEPTUNE_SCSP:
  1004. m = (typeof(m)){"LPe1000-SP", max_speed, "PCIe"};
  1005. break;
  1006. case PCI_DEVICE_ID_NEPTUNE_DCSP:
  1007. m = (typeof(m)){"LPe1002-SP", max_speed, "PCIe"};
  1008. break;
  1009. case PCI_DEVICE_ID_BMID:
  1010. m = (typeof(m)){"LP1150", max_speed, "PCI-X2"};
  1011. break;
  1012. case PCI_DEVICE_ID_BSMB:
  1013. m = (typeof(m)){"LP111", max_speed, "PCI-X2"};
  1014. break;
  1015. case PCI_DEVICE_ID_ZEPHYR:
  1016. m = (typeof(m)){"LPe11000", max_speed, "PCIe"};
  1017. break;
  1018. case PCI_DEVICE_ID_ZEPHYR_SCSP:
  1019. m = (typeof(m)){"LPe11000", max_speed, "PCIe"};
  1020. break;
  1021. case PCI_DEVICE_ID_ZEPHYR_DCSP:
  1022. m = (typeof(m)){"LPe11002-SP", max_speed, "PCIe"};
  1023. break;
  1024. case PCI_DEVICE_ID_ZMID:
  1025. m = (typeof(m)){"LPe1150", max_speed, "PCIe"};
  1026. break;
  1027. case PCI_DEVICE_ID_ZSMB:
  1028. m = (typeof(m)){"LPe111", max_speed, "PCIe"};
  1029. break;
  1030. case PCI_DEVICE_ID_LP101:
  1031. m = (typeof(m)){"LP101", max_speed, "PCI-X"};
  1032. break;
  1033. case PCI_DEVICE_ID_LP10000S:
  1034. m = (typeof(m)){"LP10000-S", max_speed, "PCI"};
  1035. break;
  1036. case PCI_DEVICE_ID_LP11000S:
  1037. m = (typeof(m)){"LP11000-S", max_speed,
  1038. "PCI-X2"};
  1039. break;
  1040. case PCI_DEVICE_ID_LPE11000S:
  1041. m = (typeof(m)){"LPe11000-S", max_speed,
  1042. "PCIe"};
  1043. break;
  1044. case PCI_DEVICE_ID_SAT:
  1045. m = (typeof(m)){"LPe12000", max_speed, "PCIe"};
  1046. break;
  1047. case PCI_DEVICE_ID_SAT_MID:
  1048. m = (typeof(m)){"LPe1250", max_speed, "PCIe"};
  1049. break;
  1050. case PCI_DEVICE_ID_SAT_SMB:
  1051. m = (typeof(m)){"LPe121", max_speed, "PCIe"};
  1052. break;
  1053. case PCI_DEVICE_ID_SAT_DCSP:
  1054. m = (typeof(m)){"LPe12002-SP", max_speed, "PCIe"};
  1055. break;
  1056. case PCI_DEVICE_ID_SAT_SCSP:
  1057. m = (typeof(m)){"LPe12000-SP", max_speed, "PCIe"};
  1058. break;
  1059. case PCI_DEVICE_ID_SAT_S:
  1060. m = (typeof(m)){"LPe12000-S", max_speed, "PCIe"};
  1061. break;
  1062. default:
  1063. m = (typeof(m)){ NULL };
  1064. break;
  1065. }
  1066. if (mdp && mdp[0] == '\0')
  1067. snprintf(mdp, 79,"%s", m.name);
  1068. if (descp && descp[0] == '\0')
  1069. snprintf(descp, 255,
  1070. "Emulex %s %dGb %s Fibre Channel Adapter",
  1071. m.name, m.max_speed, m.bus);
  1072. }
  1073. /**************************************************/
  1074. /* lpfc_post_buffer */
  1075. /* */
  1076. /* This routine will post count buffers to the */
  1077. /* ring with the QUE_RING_BUF_CN command. This */
  1078. /* allows 3 buffers / command to be posted. */
  1079. /* Returns the number of buffers NOT posted. */
  1080. /**************************************************/
  1081. int
  1082. lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt,
  1083. int type)
  1084. {
  1085. IOCB_t *icmd;
  1086. struct lpfc_iocbq *iocb;
  1087. struct lpfc_dmabuf *mp1, *mp2;
  1088. cnt += pring->missbufcnt;
  1089. /* While there are buffers to post */
  1090. while (cnt > 0) {
  1091. /* Allocate buffer for command iocb */
  1092. iocb = lpfc_sli_get_iocbq(phba);
  1093. if (iocb == NULL) {
  1094. pring->missbufcnt = cnt;
  1095. return cnt;
  1096. }
  1097. icmd = &iocb->iocb;
  1098. /* 2 buffers can be posted per command */
  1099. /* Allocate buffer to post */
  1100. mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
  1101. if (mp1)
  1102. mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys);
  1103. if (!mp1 || !mp1->virt) {
  1104. kfree(mp1);
  1105. lpfc_sli_release_iocbq(phba, iocb);
  1106. pring->missbufcnt = cnt;
  1107. return cnt;
  1108. }
  1109. INIT_LIST_HEAD(&mp1->list);
  1110. /* Allocate buffer to post */
  1111. if (cnt > 1) {
  1112. mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
  1113. if (mp2)
  1114. mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
  1115. &mp2->phys);
  1116. if (!mp2 || !mp2->virt) {
  1117. kfree(mp2);
  1118. lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
  1119. kfree(mp1);
  1120. lpfc_sli_release_iocbq(phba, iocb);
  1121. pring->missbufcnt = cnt;
  1122. return cnt;
  1123. }
  1124. INIT_LIST_HEAD(&mp2->list);
  1125. } else {
  1126. mp2 = NULL;
  1127. }
  1128. icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
  1129. icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
  1130. icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
  1131. icmd->ulpBdeCount = 1;
  1132. cnt--;
  1133. if (mp2) {
  1134. icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
  1135. icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
  1136. icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
  1137. cnt--;
  1138. icmd->ulpBdeCount = 2;
  1139. }
  1140. icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
  1141. icmd->ulpLe = 1;
  1142. if (lpfc_sli_issue_iocb(phba, pring, iocb, 0) == IOCB_ERROR) {
  1143. lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
  1144. kfree(mp1);
  1145. cnt++;
  1146. if (mp2) {
  1147. lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
  1148. kfree(mp2);
  1149. cnt++;
  1150. }
  1151. lpfc_sli_release_iocbq(phba, iocb);
  1152. pring->missbufcnt = cnt;
  1153. return cnt;
  1154. }
  1155. lpfc_sli_ringpostbuf_put(phba, pring, mp1);
  1156. if (mp2)
  1157. lpfc_sli_ringpostbuf_put(phba, pring, mp2);
  1158. }
  1159. pring->missbufcnt = 0;
  1160. return 0;
  1161. }
  1162. /************************************************************************/
  1163. /* */
  1164. /* lpfc_post_rcv_buf */
  1165. /* This routine post initial rcv buffers to the configured rings */
  1166. /* */
  1167. /************************************************************************/
  1168. static int
  1169. lpfc_post_rcv_buf(struct lpfc_hba *phba)
  1170. {
  1171. struct lpfc_sli *psli = &phba->sli;
  1172. /* Ring 0, ELS / CT buffers */
  1173. lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0, 1);
  1174. /* Ring 2 - FCP no buffers needed */
  1175. return 0;
  1176. }
  1177. #define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
  1178. /************************************************************************/
  1179. /* */
  1180. /* lpfc_sha_init */
  1181. /* */
  1182. /************************************************************************/
  1183. static void
  1184. lpfc_sha_init(uint32_t * HashResultPointer)
  1185. {
  1186. HashResultPointer[0] = 0x67452301;
  1187. HashResultPointer[1] = 0xEFCDAB89;
  1188. HashResultPointer[2] = 0x98BADCFE;
  1189. HashResultPointer[3] = 0x10325476;
  1190. HashResultPointer[4] = 0xC3D2E1F0;
  1191. }
  1192. /************************************************************************/
  1193. /* */
  1194. /* lpfc_sha_iterate */
  1195. /* */
  1196. /************************************************************************/
  1197. static void
  1198. lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
  1199. {
  1200. int t;
  1201. uint32_t TEMP;
  1202. uint32_t A, B, C, D, E;
  1203. t = 16;
  1204. do {
  1205. HashWorkingPointer[t] =
  1206. S(1,
  1207. HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
  1208. 8] ^
  1209. HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
  1210. } while (++t <= 79);
  1211. t = 0;
  1212. A = HashResultPointer[0];
  1213. B = HashResultPointer[1];
  1214. C = HashResultPointer[2];
  1215. D = HashResultPointer[3];
  1216. E = HashResultPointer[4];
  1217. do {
  1218. if (t < 20) {
  1219. TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
  1220. } else if (t < 40) {
  1221. TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
  1222. } else if (t < 60) {
  1223. TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
  1224. } else {
  1225. TEMP = (B ^ C ^ D) + 0xCA62C1D6;
  1226. }
  1227. TEMP += S(5, A) + E + HashWorkingPointer[t];
  1228. E = D;
  1229. D = C;
  1230. C = S(30, B);
  1231. B = A;
  1232. A = TEMP;
  1233. } while (++t <= 79);
  1234. HashResultPointer[0] += A;
  1235. HashResultPointer[1] += B;
  1236. HashResultPointer[2] += C;
  1237. HashResultPointer[3] += D;
  1238. HashResultPointer[4] += E;
  1239. }
  1240. /************************************************************************/
  1241. /* */
  1242. /* lpfc_challenge_key */
  1243. /* */
  1244. /************************************************************************/
  1245. static void
  1246. lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
  1247. {
  1248. *HashWorking = (*RandomChallenge ^ *HashWorking);
  1249. }
  1250. /************************************************************************/
  1251. /* */
  1252. /* lpfc_hba_init */
  1253. /* */
  1254. /************************************************************************/
  1255. void
  1256. lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
  1257. {
  1258. int t;
  1259. uint32_t *HashWorking;
  1260. uint32_t *pwwnn = (uint32_t *) phba->wwnn;
  1261. HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL);
  1262. if (!HashWorking)
  1263. return;
  1264. HashWorking[0] = HashWorking[78] = *pwwnn++;
  1265. HashWorking[1] = HashWorking[79] = *pwwnn;
  1266. for (t = 0; t < 7; t++)
  1267. lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
  1268. lpfc_sha_init(hbainit);
  1269. lpfc_sha_iterate(hbainit, HashWorking);
  1270. kfree(HashWorking);
  1271. }
  1272. void
  1273. lpfc_cleanup(struct lpfc_vport *vport)
  1274. {
  1275. struct lpfc_hba *phba = vport->phba;
  1276. struct lpfc_nodelist *ndlp, *next_ndlp;
  1277. int i = 0;
  1278. if (phba->link_state > LPFC_LINK_DOWN)
  1279. lpfc_port_link_failure(vport);
  1280. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
  1281. if (!NLP_CHK_NODE_ACT(ndlp)) {
  1282. ndlp = lpfc_enable_node(vport, ndlp,
  1283. NLP_STE_UNUSED_NODE);
  1284. if (!ndlp)
  1285. continue;
  1286. spin_lock_irq(&phba->ndlp_lock);
  1287. NLP_SET_FREE_REQ(ndlp);
  1288. spin_unlock_irq(&phba->ndlp_lock);
  1289. /* Trigger the release of the ndlp memory */
  1290. lpfc_nlp_put(ndlp);
  1291. continue;
  1292. }
  1293. spin_lock_irq(&phba->ndlp_lock);
  1294. if (NLP_CHK_FREE_REQ(ndlp)) {
  1295. /* The ndlp should not be in memory free mode already */
  1296. spin_unlock_irq(&phba->ndlp_lock);
  1297. continue;
  1298. } else
  1299. /* Indicate request for freeing ndlp memory */
  1300. NLP_SET_FREE_REQ(ndlp);
  1301. spin_unlock_irq(&phba->ndlp_lock);
  1302. if (vport->port_type != LPFC_PHYSICAL_PORT &&
  1303. ndlp->nlp_DID == Fabric_DID) {
  1304. /* Just free up ndlp with Fabric_DID for vports */
  1305. lpfc_nlp_put(ndlp);
  1306. continue;
  1307. }
  1308. if (ndlp->nlp_type & NLP_FABRIC)
  1309. lpfc_disc_state_machine(vport, ndlp, NULL,
  1310. NLP_EVT_DEVICE_RECOVERY);
  1311. lpfc_disc_state_machine(vport, ndlp, NULL,
  1312. NLP_EVT_DEVICE_RM);
  1313. }
  1314. /* At this point, ALL ndlp's should be gone
  1315. * because of the previous NLP_EVT_DEVICE_RM.
  1316. * Lets wait for this to happen, if needed.
  1317. */
  1318. while (!list_empty(&vport->fc_nodes)) {
  1319. if (i++ > 3000) {
  1320. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  1321. "0233 Nodelist not empty\n");
  1322. list_for_each_entry_safe(ndlp, next_ndlp,
  1323. &vport->fc_nodes, nlp_listp) {
  1324. lpfc_printf_vlog(ndlp->vport, KERN_ERR,
  1325. LOG_NODE,
  1326. "0282: did:x%x ndlp:x%p "
  1327. "usgmap:x%x refcnt:%d\n",
  1328. ndlp->nlp_DID, (void *)ndlp,
  1329. ndlp->nlp_usg_map,
  1330. atomic_read(
  1331. &ndlp->kref.refcount));
  1332. }
  1333. break;
  1334. }
  1335. /* Wait for any activity on ndlps to settle */
  1336. msleep(10);
  1337. }
  1338. return;
  1339. }
  1340. void
  1341. lpfc_stop_vport_timers(struct lpfc_vport *vport)
  1342. {
  1343. del_timer_sync(&vport->els_tmofunc);
  1344. del_timer_sync(&vport->fc_fdmitmo);
  1345. lpfc_can_disctmo(vport);
  1346. return;
  1347. }
  1348. static void
  1349. lpfc_stop_phba_timers(struct lpfc_hba *phba)
  1350. {
  1351. del_timer_sync(&phba->fcp_poll_timer);
  1352. lpfc_stop_vport_timers(phba->pport);
  1353. del_timer_sync(&phba->sli.mbox_tmo);
  1354. del_timer_sync(&phba->fabric_block_timer);
  1355. phba->hb_outstanding = 0;
  1356. del_timer_sync(&phba->hb_tmofunc);
  1357. return;
  1358. }
  1359. static void
  1360. lpfc_block_mgmt_io(struct lpfc_hba * phba)
  1361. {
  1362. unsigned long iflag;
  1363. spin_lock_irqsave(&phba->hbalock, iflag);
  1364. phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO;
  1365. spin_unlock_irqrestore(&phba->hbalock, iflag);
  1366. }
  1367. int
  1368. lpfc_online(struct lpfc_hba *phba)
  1369. {
  1370. struct lpfc_vport *vport = phba->pport;
  1371. struct lpfc_vport **vports;
  1372. int i;
  1373. if (!phba)
  1374. return 0;
  1375. if (!(vport->fc_flag & FC_OFFLINE_MODE))
  1376. return 0;
  1377. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  1378. "0458 Bring Adapter online\n");
  1379. lpfc_block_mgmt_io(phba);
  1380. if (!lpfc_sli_queue_setup(phba)) {
  1381. lpfc_unblock_mgmt_io(phba);
  1382. return 1;
  1383. }
  1384. if (lpfc_sli_hba_setup(phba)) { /* Initialize the HBA */
  1385. lpfc_unblock_mgmt_io(phba);
  1386. return 1;
  1387. }
  1388. vports = lpfc_create_vport_work_array(phba);
  1389. if (vports != NULL)
  1390. for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
  1391. struct Scsi_Host *shost;
  1392. shost = lpfc_shost_from_vport(vports[i]);
  1393. spin_lock_irq(shost->host_lock);
  1394. vports[i]->fc_flag &= ~FC_OFFLINE_MODE;
  1395. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
  1396. vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  1397. spin_unlock_irq(shost->host_lock);
  1398. }
  1399. lpfc_destroy_vport_work_array(phba, vports);
  1400. lpfc_unblock_mgmt_io(phba);
  1401. return 0;
  1402. }
  1403. void
  1404. lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
  1405. {
  1406. unsigned long iflag;
  1407. spin_lock_irqsave(&phba->hbalock, iflag);
  1408. phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO;
  1409. spin_unlock_irqrestore(&phba->hbalock, iflag);
  1410. }
  1411. void
  1412. lpfc_offline_prep(struct lpfc_hba * phba)
  1413. {
  1414. struct lpfc_vport *vport = phba->pport;
  1415. struct lpfc_nodelist *ndlp, *next_ndlp;
  1416. struct lpfc_vport **vports;
  1417. int i;
  1418. if (vport->fc_flag & FC_OFFLINE_MODE)
  1419. return;
  1420. lpfc_block_mgmt_io(phba);
  1421. lpfc_linkdown(phba);
  1422. /* Issue an unreg_login to all nodes on all vports */
  1423. vports = lpfc_create_vport_work_array(phba);
  1424. if (vports != NULL) {
  1425. for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
  1426. struct Scsi_Host *shost;
  1427. if (vports[i]->load_flag & FC_UNLOADING)
  1428. continue;
  1429. shost = lpfc_shost_from_vport(vports[i]);
  1430. list_for_each_entry_safe(ndlp, next_ndlp,
  1431. &vports[i]->fc_nodes,
  1432. nlp_listp) {
  1433. if (!NLP_CHK_NODE_ACT(ndlp))
  1434. continue;
  1435. if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
  1436. continue;
  1437. if (ndlp->nlp_type & NLP_FABRIC) {
  1438. lpfc_disc_state_machine(vports[i], ndlp,
  1439. NULL, NLP_EVT_DEVICE_RECOVERY);
  1440. lpfc_disc_state_machine(vports[i], ndlp,
  1441. NULL, NLP_EVT_DEVICE_RM);
  1442. }
  1443. spin_lock_irq(shost->host_lock);
  1444. ndlp->nlp_flag &= ~NLP_NPR_ADISC;
  1445. spin_unlock_irq(shost->host_lock);
  1446. lpfc_unreg_rpi(vports[i], ndlp);
  1447. }
  1448. }
  1449. }
  1450. lpfc_destroy_vport_work_array(phba, vports);
  1451. lpfc_sli_flush_mbox_queue(phba);
  1452. }
  1453. void
  1454. lpfc_offline(struct lpfc_hba *phba)
  1455. {
  1456. struct Scsi_Host *shost;
  1457. struct lpfc_vport **vports;
  1458. int i;
  1459. if (phba->pport->fc_flag & FC_OFFLINE_MODE)
  1460. return;
  1461. /* stop all timers associated with this hba */
  1462. lpfc_stop_phba_timers(phba);
  1463. vports = lpfc_create_vport_work_array(phba);
  1464. if (vports != NULL)
  1465. for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++)
  1466. lpfc_stop_vport_timers(vports[i]);
  1467. lpfc_destroy_vport_work_array(phba, vports);
  1468. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  1469. "0460 Bring Adapter offline\n");
  1470. /* Bring down the SLI Layer and cleanup. The HBA is offline
  1471. now. */
  1472. lpfc_sli_hba_down(phba);
  1473. spin_lock_irq(&phba->hbalock);
  1474. phba->work_ha = 0;
  1475. spin_unlock_irq(&phba->hbalock);
  1476. vports = lpfc_create_vport_work_array(phba);
  1477. if (vports != NULL)
  1478. for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
  1479. shost = lpfc_shost_from_vport(vports[i]);
  1480. spin_lock_irq(shost->host_lock);
  1481. vports[i]->work_port_events = 0;
  1482. vports[i]->fc_flag |= FC_OFFLINE_MODE;
  1483. spin_unlock_irq(shost->host_lock);
  1484. }
  1485. lpfc_destroy_vport_work_array(phba, vports);
  1486. }
  1487. /******************************************************************************
  1488. * Function name: lpfc_scsi_free
  1489. *
  1490. * Description: Called from lpfc_pci_remove_one free internal driver resources
  1491. *
  1492. ******************************************************************************/
  1493. static int
  1494. lpfc_scsi_free(struct lpfc_hba *phba)
  1495. {
  1496. struct lpfc_scsi_buf *sb, *sb_next;
  1497. struct lpfc_iocbq *io, *io_next;
  1498. spin_lock_irq(&phba->hbalock);
  1499. /* Release all the lpfc_scsi_bufs maintained by this host. */
  1500. list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list, list) {
  1501. list_del(&sb->list);
  1502. pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data,
  1503. sb->dma_handle);
  1504. kfree(sb);
  1505. phba->total_scsi_bufs--;
  1506. }
  1507. /* Release all the lpfc_iocbq entries maintained by this host. */
  1508. list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) {
  1509. list_del(&io->list);
  1510. kfree(io);
  1511. phba->total_iocbq_bufs--;
  1512. }
  1513. spin_unlock_irq(&phba->hbalock);
  1514. return 0;
  1515. }
  1516. struct lpfc_vport *
  1517. lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
  1518. {
  1519. struct lpfc_vport *vport;
  1520. struct Scsi_Host *shost;
  1521. int error = 0;
  1522. if (dev != &phba->pcidev->dev)
  1523. shost = scsi_host_alloc(&lpfc_vport_template,
  1524. sizeof(struct lpfc_vport));
  1525. else
  1526. shost = scsi_host_alloc(&lpfc_template,
  1527. sizeof(struct lpfc_vport));
  1528. if (!shost)
  1529. goto out;
  1530. vport = (struct lpfc_vport *) shost->hostdata;
  1531. vport->phba = phba;
  1532. vport->load_flag |= FC_LOADING;
  1533. vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  1534. vport->fc_rscn_flush = 0;
  1535. lpfc_get_vport_cfgparam(vport);
  1536. shost->unique_id = instance;
  1537. shost->max_id = LPFC_MAX_TARGET;
  1538. shost->max_lun = vport->cfg_max_luns;
  1539. shost->this_id = -1;
  1540. shost->max_cmd_len = 16;
  1541. /*
  1542. * Set initial can_queue value since 0 is no longer supported and
  1543. * scsi_add_host will fail. This will be adjusted later based on the
  1544. * max xri value determined in hba setup.
  1545. */
  1546. shost->can_queue = phba->cfg_hba_queue_depth - 10;
  1547. if (dev != &phba->pcidev->dev) {
  1548. shost->transportt = lpfc_vport_transport_template;
  1549. vport->port_type = LPFC_NPIV_PORT;
  1550. } else {
  1551. shost->transportt = lpfc_transport_template;
  1552. vport->port_type = LPFC_PHYSICAL_PORT;
  1553. }
  1554. /* Initialize all internally managed lists. */
  1555. INIT_LIST_HEAD(&vport->fc_nodes);
  1556. spin_lock_init(&vport->work_port_lock);
  1557. init_timer(&vport->fc_disctmo);
  1558. vport->fc_disctmo.function = lpfc_disc_timeout;
  1559. vport->fc_disctmo.data = (unsigned long)vport;
  1560. init_timer(&vport->fc_fdmitmo);
  1561. vport->fc_fdmitmo.function = lpfc_fdmi_tmo;
  1562. vport->fc_fdmitmo.data = (unsigned long)vport;
  1563. init_timer(&vport->els_tmofunc);
  1564. vport->els_tmofunc.function = lpfc_els_timeout;
  1565. vport->els_tmofunc.data = (unsigned long)vport;
  1566. error = scsi_add_host(shost, dev);
  1567. if (error)
  1568. goto out_put_shost;
  1569. spin_lock_irq(&phba->hbalock);
  1570. list_add_tail(&vport->listentry, &phba->port_list);
  1571. spin_unlock_irq(&phba->hbalock);
  1572. return vport;
  1573. out_put_shost:
  1574. scsi_host_put(shost);
  1575. out:
  1576. return NULL;
  1577. }
  1578. void
  1579. destroy_port(struct lpfc_vport *vport)
  1580. {
  1581. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1582. struct lpfc_hba *phba = vport->phba;
  1583. kfree(vport->vname);
  1584. lpfc_debugfs_terminate(vport);
  1585. fc_remove_host(shost);
  1586. scsi_remove_host(shost);
  1587. spin_lock_irq(&phba->hbalock);
  1588. list_del_init(&vport->listentry);
  1589. spin_unlock_irq(&phba->hbalock);
  1590. lpfc_cleanup(vport);
  1591. return;
  1592. }
  1593. int
  1594. lpfc_get_instance(void)
  1595. {
  1596. int instance = 0;
  1597. /* Assign an unused number */
  1598. if (!idr_pre_get(&lpfc_hba_index, GFP_KERNEL))
  1599. return -1;
  1600. if (idr_get_new(&lpfc_hba_index, NULL, &instance))
  1601. return -1;
  1602. return instance;
  1603. }
  1604. /*
  1605. * Note: there is no scan_start function as adapter initialization
  1606. * will have asynchronously kicked off the link initialization.
  1607. */
  1608. int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
  1609. {
  1610. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1611. struct lpfc_hba *phba = vport->phba;
  1612. int stat = 0;
  1613. spin_lock_irq(shost->host_lock);
  1614. if (vport->load_flag & FC_UNLOADING) {
  1615. stat = 1;
  1616. goto finished;
  1617. }
  1618. if (time >= 30 * HZ) {
  1619. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  1620. "0461 Scanning longer than 30 "
  1621. "seconds. Continuing initialization\n");
  1622. stat = 1;
  1623. goto finished;
  1624. }
  1625. if (time >= 15 * HZ && phba->link_state <= LPFC_LINK_DOWN) {
  1626. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  1627. "0465 Link down longer than 15 "
  1628. "seconds. Continuing initialization\n");
  1629. stat = 1;
  1630. goto finished;
  1631. }
  1632. if (vport->port_state != LPFC_VPORT_READY)
  1633. goto finished;
  1634. if (vport->num_disc_nodes || vport->fc_prli_sent)
  1635. goto finished;
  1636. if (vport->fc_map_cnt == 0 && time < 2 * HZ)
  1637. goto finished;
  1638. if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
  1639. goto finished;
  1640. stat = 1;
  1641. finished:
  1642. spin_unlock_irq(shost->host_lock);
  1643. return stat;
  1644. }
  1645. void lpfc_host_attrib_init(struct Scsi_Host *shost)
  1646. {
  1647. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1648. struct lpfc_hba *phba = vport->phba;
  1649. /*
  1650. * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
  1651. */
  1652. fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
  1653. fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
  1654. fc_host_supported_classes(shost) = FC_COS_CLASS3;
  1655. memset(fc_host_supported_fc4s(shost), 0,
  1656. sizeof(fc_host_supported_fc4s(shost)));
  1657. fc_host_supported_fc4s(shost)[2] = 1;
  1658. fc_host_supported_fc4s(shost)[7] = 1;
  1659. lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
  1660. sizeof fc_host_symbolic_name(shost));
  1661. fc_host_supported_speeds(shost) = 0;
  1662. if (phba->lmt & LMT_10Gb)
  1663. fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
  1664. if (phba->lmt & LMT_8Gb)
  1665. fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT;
  1666. if (phba->lmt & LMT_4Gb)
  1667. fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
  1668. if (phba->lmt & LMT_2Gb)
  1669. fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
  1670. if (phba->lmt & LMT_1Gb)
  1671. fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
  1672. fc_host_maxframe_size(shost) =
  1673. (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
  1674. (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
  1675. /* This value is also unchanging */
  1676. memset(fc_host_active_fc4s(shost), 0,
  1677. sizeof(fc_host_active_fc4s(shost)));
  1678. fc_host_active_fc4s(shost)[2] = 1;
  1679. fc_host_active_fc4s(shost)[7] = 1;
  1680. fc_host_max_npiv_vports(shost) = phba->max_vpi;
  1681. spin_lock_irq(shost->host_lock);
  1682. vport->load_flag &= ~FC_LOADING;
  1683. spin_unlock_irq(shost->host_lock);
  1684. }
  1685. static int
  1686. lpfc_enable_msix(struct lpfc_hba *phba)
  1687. {
  1688. int error;
  1689. phba->msix_entries[0].entry = 0;
  1690. phba->msix_entries[0].vector = 0;
  1691. error = pci_enable_msix(phba->pcidev, phba->msix_entries,
  1692. ARRAY_SIZE(phba->msix_entries));
  1693. if (error) {
  1694. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  1695. "0420 Enable MSI-X failed (%d), continuing "
  1696. "with MSI\n", error);
  1697. pci_disable_msix(phba->pcidev);
  1698. return error;
  1699. }
  1700. error = request_irq(phba->msix_entries[0].vector, lpfc_intr_handler, 0,
  1701. LPFC_DRIVER_NAME, phba);
  1702. if (error) {
  1703. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1704. "0421 MSI-X request_irq failed (%d), "
  1705. "continuing with MSI\n", error);
  1706. pci_disable_msix(phba->pcidev);
  1707. }
  1708. return error;
  1709. }
  1710. static void
  1711. lpfc_disable_msix(struct lpfc_hba *phba)
  1712. {
  1713. free_irq(phba->msix_entries[0].vector, phba);
  1714. pci_disable_msix(phba->pcidev);
  1715. }
  1716. static int __devinit
  1717. lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
  1718. {
  1719. struct lpfc_vport *vport = NULL;
  1720. struct lpfc_hba *phba;
  1721. struct lpfc_sli *psli;
  1722. struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
  1723. struct Scsi_Host *shost = NULL;
  1724. void *ptr;
  1725. unsigned long bar0map_len, bar2map_len;
  1726. int error = -ENODEV, retval;
  1727. int i, hbq_count;
  1728. uint16_t iotag;
  1729. int bars = pci_select_bars(pdev, IORESOURCE_MEM);
  1730. if (pci_enable_device_mem(pdev))
  1731. goto out;
  1732. if (pci_request_selected_regions(pdev, bars, LPFC_DRIVER_NAME))
  1733. goto out_disable_device;
  1734. phba = kzalloc(sizeof (struct lpfc_hba), GFP_KERNEL);
  1735. if (!phba)
  1736. goto out_release_regions;
  1737. spin_lock_init(&phba->hbalock);
  1738. /* Initialize ndlp management spinlock */
  1739. spin_lock_init(&phba->ndlp_lock);
  1740. phba->pcidev = pdev;
  1741. /* Assign an unused board number */
  1742. if ((phba->brd_no = lpfc_get_instance()) < 0)
  1743. goto out_free_phba;
  1744. INIT_LIST_HEAD(&phba->port_list);
  1745. /*
  1746. * Get all the module params for configuring this host and then
  1747. * establish the host.
  1748. */
  1749. lpfc_get_cfgparam(phba);
  1750. phba->max_vpi = LPFC_MAX_VPI;
  1751. /* Initialize timers used by driver */
  1752. init_timer(&phba->hb_tmofunc);
  1753. phba->hb_tmofunc.function = lpfc_hb_timeout;
  1754. phba->hb_tmofunc.data = (unsigned long)phba;
  1755. psli = &phba->sli;
  1756. init_timer(&psli->mbox_tmo);
  1757. psli->mbox_tmo.function = lpfc_mbox_timeout;
  1758. psli->mbox_tmo.data = (unsigned long) phba;
  1759. init_timer(&phba->fcp_poll_timer);
  1760. phba->fcp_poll_timer.function = lpfc_poll_timeout;
  1761. phba->fcp_poll_timer.data = (unsigned long) phba;
  1762. init_timer(&phba->fabric_block_timer);
  1763. phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
  1764. phba->fabric_block_timer.data = (unsigned long) phba;
  1765. pci_set_master(pdev);
  1766. pci_try_set_mwi(pdev);
  1767. if (pci_set_dma_mask(phba->pcidev, DMA_64BIT_MASK) != 0)
  1768. if (pci_set_dma_mask(phba->pcidev, DMA_32BIT_MASK) != 0)
  1769. goto out_idr_remove;
  1770. /*
  1771. * Get the bus address of Bar0 and Bar2 and the number of bytes
  1772. * required by each mapping.
  1773. */
  1774. phba->pci_bar0_map = pci_resource_start(phba->pcidev, 0);
  1775. bar0map_len = pci_resource_len(phba->pcidev, 0);
  1776. phba->pci_bar2_map = pci_resource_start(phba->pcidev, 2);
  1777. bar2map_len = pci_resource_len(phba->pcidev, 2);
  1778. /* Map HBA SLIM to a kernel virtual address. */
  1779. phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
  1780. if (!phba->slim_memmap_p) {
  1781. error = -ENODEV;
  1782. dev_printk(KERN_ERR, &pdev->dev,
  1783. "ioremap failed for SLIM memory.\n");
  1784. goto out_idr_remove;
  1785. }
  1786. /* Map HBA Control Registers to a kernel virtual address. */
  1787. phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
  1788. if (!phba->ctrl_regs_memmap_p) {
  1789. error = -ENODEV;
  1790. dev_printk(KERN_ERR, &pdev->dev,
  1791. "ioremap failed for HBA control registers.\n");
  1792. goto out_iounmap_slim;
  1793. }
  1794. /* Allocate memory for SLI-2 structures */
  1795. phba->slim2p = dma_alloc_coherent(&phba->pcidev->dev, SLI2_SLIM_SIZE,
  1796. &phba->slim2p_mapping, GFP_KERNEL);
  1797. if (!phba->slim2p)
  1798. goto out_iounmap;
  1799. memset(phba->slim2p, 0, SLI2_SLIM_SIZE);
  1800. phba->hbqslimp.virt = dma_alloc_coherent(&phba->pcidev->dev,
  1801. lpfc_sli_hbq_size(),
  1802. &phba->hbqslimp.phys,
  1803. GFP_KERNEL);
  1804. if (!phba->hbqslimp.virt)
  1805. goto out_free_slim;
  1806. hbq_count = lpfc_sli_hbq_count();
  1807. ptr = phba->hbqslimp.virt;
  1808. for (i = 0; i < hbq_count; ++i) {
  1809. phba->hbqs[i].hbq_virt = ptr;
  1810. INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
  1811. ptr += (lpfc_hbq_defs[i]->entry_count *
  1812. sizeof(struct lpfc_hbq_entry));
  1813. }
  1814. phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc;
  1815. phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free;
  1816. memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size());
  1817. INIT_LIST_HEAD(&phba->hbqbuf_in_list);
  1818. /* Initialize the SLI Layer to run with lpfc HBAs. */
  1819. lpfc_sli_setup(phba);
  1820. lpfc_sli_queue_setup(phba);
  1821. retval = lpfc_mem_alloc(phba);
  1822. if (retval) {
  1823. error = retval;
  1824. goto out_free_hbqslimp;
  1825. }
  1826. /* Initialize and populate the iocb list per host. */
  1827. INIT_LIST_HEAD(&phba->lpfc_iocb_list);
  1828. for (i = 0; i < LPFC_IOCB_LIST_CNT; i++) {
  1829. iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
  1830. if (iocbq_entry == NULL) {
  1831. printk(KERN_ERR "%s: only allocated %d iocbs of "
  1832. "expected %d count. Unloading driver.\n",
  1833. __FUNCTION__, i, LPFC_IOCB_LIST_CNT);
  1834. error = -ENOMEM;
  1835. goto out_free_iocbq;
  1836. }
  1837. iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
  1838. if (iotag == 0) {
  1839. kfree (iocbq_entry);
  1840. printk(KERN_ERR "%s: failed to allocate IOTAG. "
  1841. "Unloading driver.\n",
  1842. __FUNCTION__);
  1843. error = -ENOMEM;
  1844. goto out_free_iocbq;
  1845. }
  1846. spin_lock_irq(&phba->hbalock);
  1847. list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
  1848. phba->total_iocbq_bufs++;
  1849. spin_unlock_irq(&phba->hbalock);
  1850. }
  1851. /* Initialize HBA structure */
  1852. phba->fc_edtov = FF_DEF_EDTOV;
  1853. phba->fc_ratov = FF_DEF_RATOV;
  1854. phba->fc_altov = FF_DEF_ALTOV;
  1855. phba->fc_arbtov = FF_DEF_ARBTOV;
  1856. INIT_LIST_HEAD(&phba->work_list);
  1857. phba->work_ha_mask = (HA_ERATT|HA_MBATT|HA_LATT);
  1858. phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
  1859. /* Startup the kernel thread for this host adapter. */
  1860. phba->worker_thread = kthread_run(lpfc_do_work, phba,
  1861. "lpfc_worker_%d", phba->brd_no);
  1862. if (IS_ERR(phba->worker_thread)) {
  1863. error = PTR_ERR(phba->worker_thread);
  1864. goto out_free_iocbq;
  1865. }
  1866. /* Initialize the list of scsi buffers used by driver for scsi IO. */
  1867. spin_lock_init(&phba->scsi_buf_list_lock);
  1868. INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list);
  1869. /* Initialize list of fabric iocbs */
  1870. INIT_LIST_HEAD(&phba->fabric_iocb_list);
  1871. /* Initialize list to save ELS buffers */
  1872. INIT_LIST_HEAD(&phba->elsbuf);
  1873. vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev);
  1874. if (!vport)
  1875. goto out_kthread_stop;
  1876. shost = lpfc_shost_from_vport(vport);
  1877. phba->pport = vport;
  1878. lpfc_debugfs_initialize(vport);
  1879. pci_set_drvdata(pdev, shost);
  1880. phba->intr_type = NONE;
  1881. if (phba->cfg_use_msi == 2) {
  1882. error = lpfc_enable_msix(phba);
  1883. if (!error)
  1884. phba->intr_type = MSIX;
  1885. }
  1886. /* Fallback to MSI if MSI-X initialization failed */
  1887. if (phba->cfg_use_msi >= 1 && phba->intr_type == NONE) {
  1888. retval = pci_enable_msi(phba->pcidev);
  1889. if (!retval)
  1890. phba->intr_type = MSI;
  1891. else
  1892. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  1893. "0452 Enable MSI failed, continuing "
  1894. "with IRQ\n");
  1895. }
  1896. /* MSI-X is the only case the doesn't need to call request_irq */
  1897. if (phba->intr_type != MSIX) {
  1898. retval = request_irq(phba->pcidev->irq, lpfc_intr_handler,
  1899. IRQF_SHARED, LPFC_DRIVER_NAME, phba);
  1900. if (retval) {
  1901. lpfc_printf_log(phba, KERN_ERR, LOG_INIT, "0451 Enable "
  1902. "interrupt handler failed\n");
  1903. error = retval;
  1904. goto out_disable_msi;
  1905. } else if (phba->intr_type != MSI)
  1906. phba->intr_type = INTx;
  1907. }
  1908. phba->MBslimaddr = phba->slim_memmap_p;
  1909. phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
  1910. phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
  1911. phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
  1912. phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
  1913. if (lpfc_alloc_sysfs_attr(vport)) {
  1914. error = -ENOMEM;
  1915. goto out_free_irq;
  1916. }
  1917. if (lpfc_sli_hba_setup(phba)) {
  1918. error = -ENODEV;
  1919. goto out_remove_device;
  1920. }
  1921. /*
  1922. * hba setup may have changed the hba_queue_depth so we need to adjust
  1923. * the value of can_queue.
  1924. */
  1925. shost->can_queue = phba->cfg_hba_queue_depth - 10;
  1926. lpfc_host_attrib_init(shost);
  1927. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  1928. spin_lock_irq(shost->host_lock);
  1929. lpfc_poll_start_timer(phba);
  1930. spin_unlock_irq(shost->host_lock);
  1931. }
  1932. scsi_scan_host(shost);
  1933. return 0;
  1934. out_remove_device:
  1935. lpfc_free_sysfs_attr(vport);
  1936. spin_lock_irq(shost->host_lock);
  1937. vport->load_flag |= FC_UNLOADING;
  1938. spin_unlock_irq(shost->host_lock);
  1939. out_free_irq:
  1940. lpfc_stop_phba_timers(phba);
  1941. phba->pport->work_port_events = 0;
  1942. if (phba->intr_type == MSIX)
  1943. lpfc_disable_msix(phba);
  1944. else
  1945. free_irq(phba->pcidev->irq, phba);
  1946. out_disable_msi:
  1947. if (phba->intr_type == MSI)
  1948. pci_disable_msi(phba->pcidev);
  1949. destroy_port(vport);
  1950. out_kthread_stop:
  1951. kthread_stop(phba->worker_thread);
  1952. out_free_iocbq:
  1953. list_for_each_entry_safe(iocbq_entry, iocbq_next,
  1954. &phba->lpfc_iocb_list, list) {
  1955. kfree(iocbq_entry);
  1956. phba->total_iocbq_bufs--;
  1957. }
  1958. lpfc_mem_free(phba);
  1959. out_free_hbqslimp:
  1960. dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), phba->hbqslimp.virt,
  1961. phba->hbqslimp.phys);
  1962. out_free_slim:
  1963. dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, phba->slim2p,
  1964. phba->slim2p_mapping);
  1965. out_iounmap:
  1966. iounmap(phba->ctrl_regs_memmap_p);
  1967. out_iounmap_slim:
  1968. iounmap(phba->slim_memmap_p);
  1969. out_idr_remove:
  1970. idr_remove(&lpfc_hba_index, phba->brd_no);
  1971. out_free_phba:
  1972. kfree(phba);
  1973. out_release_regions:
  1974. pci_release_selected_regions(pdev, bars);
  1975. out_disable_device:
  1976. pci_disable_device(pdev);
  1977. out:
  1978. pci_set_drvdata(pdev, NULL);
  1979. if (shost)
  1980. scsi_host_put(shost);
  1981. return error;
  1982. }
  1983. static void __devexit
  1984. lpfc_pci_remove_one(struct pci_dev *pdev)
  1985. {
  1986. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  1987. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1988. struct lpfc_hba *phba = vport->phba;
  1989. int bars = pci_select_bars(pdev, IORESOURCE_MEM);
  1990. spin_lock_irq(&phba->hbalock);
  1991. vport->load_flag |= FC_UNLOADING;
  1992. spin_unlock_irq(&phba->hbalock);
  1993. kfree(vport->vname);
  1994. lpfc_free_sysfs_attr(vport);
  1995. kthread_stop(phba->worker_thread);
  1996. fc_remove_host(shost);
  1997. scsi_remove_host(shost);
  1998. lpfc_cleanup(vport);
  1999. /*
  2000. * Bring down the SLI Layer. This step disable all interrupts,
  2001. * clears the rings, discards all mailbox commands, and resets
  2002. * the HBA.
  2003. */
  2004. lpfc_sli_hba_down(phba);
  2005. lpfc_sli_brdrestart(phba);
  2006. lpfc_stop_phba_timers(phba);
  2007. spin_lock_irq(&phba->hbalock);
  2008. list_del_init(&vport->listentry);
  2009. spin_unlock_irq(&phba->hbalock);
  2010. lpfc_debugfs_terminate(vport);
  2011. if (phba->intr_type == MSIX)
  2012. lpfc_disable_msix(phba);
  2013. else {
  2014. free_irq(phba->pcidev->irq, phba);
  2015. if (phba->intr_type == MSI)
  2016. pci_disable_msi(phba->pcidev);
  2017. }
  2018. pci_set_drvdata(pdev, NULL);
  2019. scsi_host_put(shost);
  2020. /*
  2021. * Call scsi_free before mem_free since scsi bufs are released to their
  2022. * corresponding pools here.
  2023. */
  2024. lpfc_scsi_free(phba);
  2025. lpfc_mem_free(phba);
  2026. dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), phba->hbqslimp.virt,
  2027. phba->hbqslimp.phys);
  2028. /* Free resources associated with SLI2 interface */
  2029. dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
  2030. phba->slim2p, phba->slim2p_mapping);
  2031. /* unmap adapter SLIM and Control Registers */
  2032. iounmap(phba->ctrl_regs_memmap_p);
  2033. iounmap(phba->slim_memmap_p);
  2034. idr_remove(&lpfc_hba_index, phba->brd_no);
  2035. kfree(phba);
  2036. pci_release_selected_regions(pdev, bars);
  2037. pci_disable_device(pdev);
  2038. }
  2039. /**
  2040. * lpfc_io_error_detected - called when PCI error is detected
  2041. * @pdev: Pointer to PCI device
  2042. * @state: The current pci conneection state
  2043. *
  2044. * This function is called after a PCI bus error affecting
  2045. * this device has been detected.
  2046. */
  2047. static pci_ers_result_t lpfc_io_error_detected(struct pci_dev *pdev,
  2048. pci_channel_state_t state)
  2049. {
  2050. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  2051. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  2052. struct lpfc_sli *psli = &phba->sli;
  2053. struct lpfc_sli_ring *pring;
  2054. if (state == pci_channel_io_perm_failure)
  2055. return PCI_ERS_RESULT_DISCONNECT;
  2056. pci_disable_device(pdev);
  2057. /*
  2058. * There may be I/Os dropped by the firmware.
  2059. * Error iocb (I/O) on txcmplq and let the SCSI layer
  2060. * retry it after re-establishing link.
  2061. */
  2062. pring = &psli->ring[psli->fcp_ring];
  2063. lpfc_sli_abort_iocb_ring(phba, pring);
  2064. if (phba->intr_type == MSIX)
  2065. lpfc_disable_msix(phba);
  2066. else {
  2067. free_irq(phba->pcidev->irq, phba);
  2068. if (phba->intr_type == MSI)
  2069. pci_disable_msi(phba->pcidev);
  2070. }
  2071. /* Request a slot reset. */
  2072. return PCI_ERS_RESULT_NEED_RESET;
  2073. }
  2074. /**
  2075. * lpfc_io_slot_reset - called after the pci bus has been reset.
  2076. * @pdev: Pointer to PCI device
  2077. *
  2078. * Restart the card from scratch, as if from a cold-boot.
  2079. */
  2080. static pci_ers_result_t lpfc_io_slot_reset(struct pci_dev *pdev)
  2081. {
  2082. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  2083. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  2084. struct lpfc_sli *psli = &phba->sli;
  2085. int error, retval;
  2086. dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
  2087. if (pci_enable_device_mem(pdev)) {
  2088. printk(KERN_ERR "lpfc: Cannot re-enable "
  2089. "PCI device after reset.\n");
  2090. return PCI_ERS_RESULT_DISCONNECT;
  2091. }
  2092. pci_set_master(pdev);
  2093. spin_lock_irq(&phba->hbalock);
  2094. psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
  2095. spin_unlock_irq(&phba->hbalock);
  2096. /* Enable configured interrupt method */
  2097. phba->intr_type = NONE;
  2098. if (phba->cfg_use_msi == 2) {
  2099. error = lpfc_enable_msix(phba);
  2100. if (!error)
  2101. phba->intr_type = MSIX;
  2102. }
  2103. /* Fallback to MSI if MSI-X initialization failed */
  2104. if (phba->cfg_use_msi >= 1 && phba->intr_type == NONE) {
  2105. retval = pci_enable_msi(phba->pcidev);
  2106. if (!retval)
  2107. phba->intr_type = MSI;
  2108. else
  2109. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  2110. "0470 Enable MSI failed, continuing "
  2111. "with IRQ\n");
  2112. }
  2113. /* MSI-X is the only case the doesn't need to call request_irq */
  2114. if (phba->intr_type != MSIX) {
  2115. retval = request_irq(phba->pcidev->irq, lpfc_intr_handler,
  2116. IRQF_SHARED, LPFC_DRIVER_NAME, phba);
  2117. if (retval) {
  2118. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2119. "0471 Enable interrupt handler "
  2120. "failed\n");
  2121. } else if (phba->intr_type != MSI)
  2122. phba->intr_type = INTx;
  2123. }
  2124. /* Take device offline; this will perform cleanup */
  2125. lpfc_offline(phba);
  2126. lpfc_sli_brdrestart(phba);
  2127. return PCI_ERS_RESULT_RECOVERED;
  2128. }
  2129. /**
  2130. * lpfc_io_resume - called when traffic can start flowing again.
  2131. * @pdev: Pointer to PCI device
  2132. *
  2133. * This callback is called when the error recovery driver tells us that
  2134. * its OK to resume normal operation.
  2135. */
  2136. static void lpfc_io_resume(struct pci_dev *pdev)
  2137. {
  2138. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  2139. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  2140. lpfc_online(phba);
  2141. }
  2142. static struct pci_device_id lpfc_id_table[] = {
  2143. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER,
  2144. PCI_ANY_ID, PCI_ANY_ID, },
  2145. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY,
  2146. PCI_ANY_ID, PCI_ANY_ID, },
  2147. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR,
  2148. PCI_ANY_ID, PCI_ANY_ID, },
  2149. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS,
  2150. PCI_ANY_ID, PCI_ANY_ID, },
  2151. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR,
  2152. PCI_ANY_ID, PCI_ANY_ID, },
  2153. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY,
  2154. PCI_ANY_ID, PCI_ANY_ID, },
  2155. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY,
  2156. PCI_ANY_ID, PCI_ANY_ID, },
  2157. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY,
  2158. PCI_ANY_ID, PCI_ANY_ID, },
  2159. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY,
  2160. PCI_ANY_ID, PCI_ANY_ID, },
  2161. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE,
  2162. PCI_ANY_ID, PCI_ANY_ID, },
  2163. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP,
  2164. PCI_ANY_ID, PCI_ANY_ID, },
  2165. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP,
  2166. PCI_ANY_ID, PCI_ANY_ID, },
  2167. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS,
  2168. PCI_ANY_ID, PCI_ANY_ID, },
  2169. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP,
  2170. PCI_ANY_ID, PCI_ANY_ID, },
  2171. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP,
  2172. PCI_ANY_ID, PCI_ANY_ID, },
  2173. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID,
  2174. PCI_ANY_ID, PCI_ANY_ID, },
  2175. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB,
  2176. PCI_ANY_ID, PCI_ANY_ID, },
  2177. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR,
  2178. PCI_ANY_ID, PCI_ANY_ID, },
  2179. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP,
  2180. PCI_ANY_ID, PCI_ANY_ID, },
  2181. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP,
  2182. PCI_ANY_ID, PCI_ANY_ID, },
  2183. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID,
  2184. PCI_ANY_ID, PCI_ANY_ID, },
  2185. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB,
  2186. PCI_ANY_ID, PCI_ANY_ID, },
  2187. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY,
  2188. PCI_ANY_ID, PCI_ANY_ID, },
  2189. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101,
  2190. PCI_ANY_ID, PCI_ANY_ID, },
  2191. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S,
  2192. PCI_ANY_ID, PCI_ANY_ID, },
  2193. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S,
  2194. PCI_ANY_ID, PCI_ANY_ID, },
  2195. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S,
  2196. PCI_ANY_ID, PCI_ANY_ID, },
  2197. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT,
  2198. PCI_ANY_ID, PCI_ANY_ID, },
  2199. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID,
  2200. PCI_ANY_ID, PCI_ANY_ID, },
  2201. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB,
  2202. PCI_ANY_ID, PCI_ANY_ID, },
  2203. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP,
  2204. PCI_ANY_ID, PCI_ANY_ID, },
  2205. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP,
  2206. PCI_ANY_ID, PCI_ANY_ID, },
  2207. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S,
  2208. PCI_ANY_ID, PCI_ANY_ID, },
  2209. { 0 }
  2210. };
  2211. MODULE_DEVICE_TABLE(pci, lpfc_id_table);
  2212. static struct pci_error_handlers lpfc_err_handler = {
  2213. .error_detected = lpfc_io_error_detected,
  2214. .slot_reset = lpfc_io_slot_reset,
  2215. .resume = lpfc_io_resume,
  2216. };
  2217. static struct pci_driver lpfc_driver = {
  2218. .name = LPFC_DRIVER_NAME,
  2219. .id_table = lpfc_id_table,
  2220. .probe = lpfc_pci_probe_one,
  2221. .remove = __devexit_p(lpfc_pci_remove_one),
  2222. .err_handler = &lpfc_err_handler,
  2223. };
  2224. static int __init
  2225. lpfc_init(void)
  2226. {
  2227. int error = 0;
  2228. printk(LPFC_MODULE_DESC "\n");
  2229. printk(LPFC_COPYRIGHT "\n");
  2230. if (lpfc_enable_npiv) {
  2231. lpfc_transport_functions.vport_create = lpfc_vport_create;
  2232. lpfc_transport_functions.vport_delete = lpfc_vport_delete;
  2233. }
  2234. lpfc_transport_template =
  2235. fc_attach_transport(&lpfc_transport_functions);
  2236. if (lpfc_transport_template == NULL)
  2237. return -ENOMEM;
  2238. if (lpfc_enable_npiv) {
  2239. lpfc_vport_transport_template =
  2240. fc_attach_transport(&lpfc_vport_transport_functions);
  2241. if (lpfc_vport_transport_template == NULL) {
  2242. fc_release_transport(lpfc_transport_template);
  2243. return -ENOMEM;
  2244. }
  2245. }
  2246. error = pci_register_driver(&lpfc_driver);
  2247. if (error) {
  2248. fc_release_transport(lpfc_transport_template);
  2249. fc_release_transport(lpfc_vport_transport_template);
  2250. }
  2251. return error;
  2252. }
  2253. static void __exit
  2254. lpfc_exit(void)
  2255. {
  2256. pci_unregister_driver(&lpfc_driver);
  2257. fc_release_transport(lpfc_transport_template);
  2258. if (lpfc_enable_npiv)
  2259. fc_release_transport(lpfc_vport_transport_template);
  2260. }
  2261. module_init(lpfc_init);
  2262. module_exit(lpfc_exit);
  2263. MODULE_LICENSE("GPL");
  2264. MODULE_DESCRIPTION(LPFC_MODULE_DESC);
  2265. MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com");
  2266. MODULE_VERSION("0:" LPFC_DRIVER_VERSION);