lpfc_init.c 73 KB

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