lpfc_init.c 64 KB

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