lpfc_init.c 65 KB

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