lpfc_init.c 64 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264
  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 = kzalloc(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. iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
  1617. if (iotag == 0) {
  1618. kfree (iocbq_entry);
  1619. printk(KERN_ERR "%s: failed to allocate IOTAG. "
  1620. "Unloading driver.\n",
  1621. __FUNCTION__);
  1622. error = -ENOMEM;
  1623. goto out_free_iocbq;
  1624. }
  1625. spin_lock_irq(&phba->hbalock);
  1626. list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
  1627. phba->total_iocbq_bufs++;
  1628. spin_unlock_irq(&phba->hbalock);
  1629. }
  1630. /* Initialize HBA structure */
  1631. phba->fc_edtov = FF_DEF_EDTOV;
  1632. phba->fc_ratov = FF_DEF_RATOV;
  1633. phba->fc_altov = FF_DEF_ALTOV;
  1634. phba->fc_arbtov = FF_DEF_ARBTOV;
  1635. INIT_LIST_HEAD(&phba->work_list);
  1636. phba->work_ha_mask = (HA_ERATT|HA_MBATT|HA_LATT);
  1637. phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
  1638. /* Startup the kernel thread for this host adapter. */
  1639. phba->worker_thread = kthread_run(lpfc_do_work, phba,
  1640. "lpfc_worker_%d", phba->brd_no);
  1641. if (IS_ERR(phba->worker_thread)) {
  1642. error = PTR_ERR(phba->worker_thread);
  1643. goto out_free_iocbq;
  1644. }
  1645. /* Initialize the list of scsi buffers used by driver for scsi IO. */
  1646. spin_lock_init(&phba->scsi_buf_list_lock);
  1647. INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list);
  1648. /* Initialize list of fabric iocbs */
  1649. INIT_LIST_HEAD(&phba->fabric_iocb_list);
  1650. vport = lpfc_create_port(phba, phba->brd_no, NULL);
  1651. if (!vport)
  1652. goto out_kthread_stop;
  1653. shost = lpfc_shost_from_vport(vport);
  1654. phba->pport = vport;
  1655. lpfc_debugfs_initialize(vport);
  1656. pci_set_drvdata(pdev, shost);
  1657. if (phba->cfg_use_msi) {
  1658. error = pci_enable_msi(phba->pcidev);
  1659. if (error)
  1660. lpfc_printf_log(phba, KERN_INFO, LOG_INIT, "%d:0452 "
  1661. "Enable MSI failed, continuing with "
  1662. "IRQ\n", phba->brd_no);
  1663. }
  1664. error = request_irq(phba->pcidev->irq, lpfc_intr_handler, IRQF_SHARED,
  1665. LPFC_DRIVER_NAME, phba);
  1666. if (error) {
  1667. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1668. "%d:0451 Enable interrupt handler failed\n",
  1669. phba->brd_no);
  1670. goto out_disable_msi;
  1671. }
  1672. phba->MBslimaddr = phba->slim_memmap_p;
  1673. phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
  1674. phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
  1675. phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
  1676. phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
  1677. if (lpfc_alloc_sysfs_attr(vport))
  1678. goto out_free_irq;
  1679. if (lpfc_sli_hba_setup(phba))
  1680. goto out_remove_device;
  1681. /*
  1682. * hba setup may have changed the hba_queue_depth so we need to adjust
  1683. * the value of can_queue.
  1684. */
  1685. shost->can_queue = phba->cfg_hba_queue_depth - 10;
  1686. lpfc_host_attrib_init(shost);
  1687. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  1688. spin_lock_irq(shost->host_lock);
  1689. lpfc_poll_start_timer(phba);
  1690. spin_unlock_irq(shost->host_lock);
  1691. }
  1692. scsi_scan_host(shost);
  1693. return 0;
  1694. out_remove_device:
  1695. lpfc_free_sysfs_attr(vport);
  1696. spin_lock_irq(shost->host_lock);
  1697. vport->fc_flag |= FC_UNLOADING;
  1698. spin_unlock_irq(shost->host_lock);
  1699. out_free_irq:
  1700. lpfc_stop_phba_timers(phba);
  1701. phba->pport->work_port_events = 0;
  1702. free_irq(phba->pcidev->irq, phba);
  1703. out_disable_msi:
  1704. pci_disable_msi(phba->pcidev);
  1705. destroy_port(vport);
  1706. out_kthread_stop:
  1707. kthread_stop(phba->worker_thread);
  1708. out_free_iocbq:
  1709. list_for_each_entry_safe(iocbq_entry, iocbq_next,
  1710. &phba->lpfc_iocb_list, list) {
  1711. kfree(iocbq_entry);
  1712. phba->total_iocbq_bufs--;
  1713. }
  1714. lpfc_mem_free(phba);
  1715. out_free_hbqslimp:
  1716. dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), phba->hbqslimp.virt,
  1717. phba->hbqslimp.phys);
  1718. out_free_slim:
  1719. dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, phba->slim2p,
  1720. phba->slim2p_mapping);
  1721. out_iounmap:
  1722. iounmap(phba->ctrl_regs_memmap_p);
  1723. out_iounmap_slim:
  1724. iounmap(phba->slim_memmap_p);
  1725. out_idr_remove:
  1726. idr_remove(&lpfc_hba_index, phba->brd_no);
  1727. out_free_phba:
  1728. kfree(phba);
  1729. out_release_regions:
  1730. pci_release_regions(pdev);
  1731. out_disable_device:
  1732. pci_disable_device(pdev);
  1733. out:
  1734. pci_set_drvdata(pdev, NULL);
  1735. if (shost)
  1736. scsi_host_put(shost);
  1737. return error;
  1738. }
  1739. static void __devexit
  1740. lpfc_pci_remove_one(struct pci_dev *pdev)
  1741. {
  1742. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  1743. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1744. struct lpfc_hba *phba = vport->phba;
  1745. struct lpfc_vport *port_iterator;
  1746. list_for_each_entry(port_iterator, &phba->port_list, listentry)
  1747. port_iterator->load_flag |= FC_UNLOADING;
  1748. kfree(vport->vname);
  1749. lpfc_free_sysfs_attr(vport);
  1750. fc_remove_host(shost);
  1751. scsi_remove_host(shost);
  1752. /*
  1753. * Bring down the SLI Layer. This step disable all interrupts,
  1754. * clears the rings, discards all mailbox commands, and resets
  1755. * the HBA.
  1756. */
  1757. lpfc_sli_hba_down(phba);
  1758. lpfc_sli_brdrestart(phba);
  1759. lpfc_stop_phba_timers(phba);
  1760. spin_lock_irq(&phba->hbalock);
  1761. list_del_init(&vport->listentry);
  1762. spin_unlock_irq(&phba->hbalock);
  1763. lpfc_debugfs_terminate(vport);
  1764. lpfc_cleanup(vport);
  1765. kthread_stop(phba->worker_thread);
  1766. /* Release the irq reservation */
  1767. free_irq(phba->pcidev->irq, phba);
  1768. pci_disable_msi(phba->pcidev);
  1769. pci_set_drvdata(pdev, NULL);
  1770. scsi_host_put(shost);
  1771. /*
  1772. * Call scsi_free before mem_free since scsi bufs are released to their
  1773. * corresponding pools here.
  1774. */
  1775. lpfc_scsi_free(phba);
  1776. lpfc_mem_free(phba);
  1777. dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), phba->hbqslimp.virt,
  1778. phba->hbqslimp.phys);
  1779. /* Free resources associated with SLI2 interface */
  1780. dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
  1781. phba->slim2p, phba->slim2p_mapping);
  1782. /* unmap adapter SLIM and Control Registers */
  1783. iounmap(phba->ctrl_regs_memmap_p);
  1784. iounmap(phba->slim_memmap_p);
  1785. idr_remove(&lpfc_hba_index, phba->brd_no);
  1786. kfree(phba);
  1787. pci_release_regions(pdev);
  1788. pci_disable_device(pdev);
  1789. }
  1790. /**
  1791. * lpfc_io_error_detected - called when PCI error is detected
  1792. * @pdev: Pointer to PCI device
  1793. * @state: The current pci conneection state
  1794. *
  1795. * This function is called after a PCI bus error affecting
  1796. * this device has been detected.
  1797. */
  1798. static pci_ers_result_t lpfc_io_error_detected(struct pci_dev *pdev,
  1799. pci_channel_state_t state)
  1800. {
  1801. struct Scsi_Host *host = pci_get_drvdata(pdev);
  1802. struct lpfc_hba *phba = (struct lpfc_hba *)host->hostdata;
  1803. struct lpfc_sli *psli = &phba->sli;
  1804. struct lpfc_sli_ring *pring;
  1805. if (state == pci_channel_io_perm_failure)
  1806. return PCI_ERS_RESULT_DISCONNECT;
  1807. pci_disable_device(pdev);
  1808. /*
  1809. * There may be I/Os dropped by the firmware.
  1810. * Error iocb (I/O) on txcmplq and let the SCSI layer
  1811. * retry it after re-establishing link.
  1812. */
  1813. pring = &psli->ring[psli->fcp_ring];
  1814. lpfc_sli_abort_iocb_ring(phba, pring);
  1815. /* Request a slot reset. */
  1816. return PCI_ERS_RESULT_NEED_RESET;
  1817. }
  1818. /**
  1819. * lpfc_io_slot_reset - called after the pci bus has been reset.
  1820. * @pdev: Pointer to PCI device
  1821. *
  1822. * Restart the card from scratch, as if from a cold-boot.
  1823. */
  1824. static pci_ers_result_t lpfc_io_slot_reset(struct pci_dev *pdev)
  1825. {
  1826. struct Scsi_Host *host = pci_get_drvdata(pdev);
  1827. struct lpfc_hba *phba = (struct lpfc_hba *)host->hostdata;
  1828. struct lpfc_sli *psli = &phba->sli;
  1829. int bars = pci_select_bars(pdev, IORESOURCE_MEM);
  1830. dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
  1831. if (pci_enable_device_bars(pdev, bars)) {
  1832. printk(KERN_ERR "lpfc: Cannot re-enable "
  1833. "PCI device after reset.\n");
  1834. return PCI_ERS_RESULT_DISCONNECT;
  1835. }
  1836. pci_set_master(pdev);
  1837. /* Re-establishing Link */
  1838. spin_lock_irq(host->host_lock);
  1839. phba->pport->fc_flag |= FC_ESTABLISH_LINK;
  1840. spin_unlock_irq(host->host_lock);
  1841. spin_lock_irq(&phba->hbalock);
  1842. psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
  1843. spin_unlock_irq(&phba->hbalock);
  1844. /* Take device offline; this will perform cleanup */
  1845. lpfc_offline(phba);
  1846. lpfc_sli_brdrestart(phba);
  1847. return PCI_ERS_RESULT_RECOVERED;
  1848. }
  1849. /**
  1850. * lpfc_io_resume - called when traffic can start flowing again.
  1851. * @pdev: Pointer to PCI device
  1852. *
  1853. * This callback is called when the error recovery driver tells us that
  1854. * its OK to resume normal operation.
  1855. */
  1856. static void lpfc_io_resume(struct pci_dev *pdev)
  1857. {
  1858. struct Scsi_Host *host = pci_get_drvdata(pdev);
  1859. struct lpfc_hba *phba = (struct lpfc_hba *)host->hostdata;
  1860. if (lpfc_online(phba) == 0) {
  1861. mod_timer(&phba->fc_estabtmo, jiffies + HZ * 60);
  1862. }
  1863. }
  1864. static struct pci_device_id lpfc_id_table[] = {
  1865. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER,
  1866. PCI_ANY_ID, PCI_ANY_ID, },
  1867. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY,
  1868. PCI_ANY_ID, PCI_ANY_ID, },
  1869. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR,
  1870. PCI_ANY_ID, PCI_ANY_ID, },
  1871. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS,
  1872. PCI_ANY_ID, PCI_ANY_ID, },
  1873. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR,
  1874. PCI_ANY_ID, PCI_ANY_ID, },
  1875. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY,
  1876. PCI_ANY_ID, PCI_ANY_ID, },
  1877. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY,
  1878. PCI_ANY_ID, PCI_ANY_ID, },
  1879. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY,
  1880. PCI_ANY_ID, PCI_ANY_ID, },
  1881. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY,
  1882. PCI_ANY_ID, PCI_ANY_ID, },
  1883. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE,
  1884. PCI_ANY_ID, PCI_ANY_ID, },
  1885. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP,
  1886. PCI_ANY_ID, PCI_ANY_ID, },
  1887. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP,
  1888. PCI_ANY_ID, PCI_ANY_ID, },
  1889. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS,
  1890. PCI_ANY_ID, PCI_ANY_ID, },
  1891. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP,
  1892. PCI_ANY_ID, PCI_ANY_ID, },
  1893. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP,
  1894. PCI_ANY_ID, PCI_ANY_ID, },
  1895. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID,
  1896. PCI_ANY_ID, PCI_ANY_ID, },
  1897. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB,
  1898. PCI_ANY_ID, PCI_ANY_ID, },
  1899. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR,
  1900. PCI_ANY_ID, PCI_ANY_ID, },
  1901. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP,
  1902. PCI_ANY_ID, PCI_ANY_ID, },
  1903. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP,
  1904. PCI_ANY_ID, PCI_ANY_ID, },
  1905. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID,
  1906. PCI_ANY_ID, PCI_ANY_ID, },
  1907. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB,
  1908. PCI_ANY_ID, PCI_ANY_ID, },
  1909. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY,
  1910. PCI_ANY_ID, PCI_ANY_ID, },
  1911. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101,
  1912. PCI_ANY_ID, PCI_ANY_ID, },
  1913. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S,
  1914. PCI_ANY_ID, PCI_ANY_ID, },
  1915. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S,
  1916. PCI_ANY_ID, PCI_ANY_ID, },
  1917. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S,
  1918. PCI_ANY_ID, PCI_ANY_ID, },
  1919. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT,
  1920. PCI_ANY_ID, PCI_ANY_ID, },
  1921. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID,
  1922. PCI_ANY_ID, PCI_ANY_ID, },
  1923. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB,
  1924. PCI_ANY_ID, PCI_ANY_ID, },
  1925. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP,
  1926. PCI_ANY_ID, PCI_ANY_ID, },
  1927. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP,
  1928. PCI_ANY_ID, PCI_ANY_ID, },
  1929. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S,
  1930. PCI_ANY_ID, PCI_ANY_ID, },
  1931. { 0 }
  1932. };
  1933. MODULE_DEVICE_TABLE(pci, lpfc_id_table);
  1934. static struct pci_error_handlers lpfc_err_handler = {
  1935. .error_detected = lpfc_io_error_detected,
  1936. .slot_reset = lpfc_io_slot_reset,
  1937. .resume = lpfc_io_resume,
  1938. };
  1939. static struct pci_driver lpfc_driver = {
  1940. .name = LPFC_DRIVER_NAME,
  1941. .id_table = lpfc_id_table,
  1942. .probe = lpfc_pci_probe_one,
  1943. .remove = __devexit_p(lpfc_pci_remove_one),
  1944. .err_handler = &lpfc_err_handler,
  1945. };
  1946. static int __init
  1947. lpfc_init(void)
  1948. {
  1949. int error = 0;
  1950. printk(LPFC_MODULE_DESC "\n");
  1951. printk(LPFC_COPYRIGHT "\n");
  1952. lpfc_transport_template =
  1953. fc_attach_transport(&lpfc_transport_functions);
  1954. lpfc_vport_transport_template =
  1955. fc_attach_transport(&lpfc_vport_transport_functions);
  1956. if (!lpfc_transport_template || !lpfc_vport_transport_template)
  1957. return -ENOMEM;
  1958. error = pci_register_driver(&lpfc_driver);
  1959. if (error) {
  1960. fc_release_transport(lpfc_transport_template);
  1961. fc_release_transport(lpfc_vport_transport_template);
  1962. }
  1963. return error;
  1964. }
  1965. static void __exit
  1966. lpfc_exit(void)
  1967. {
  1968. pci_unregister_driver(&lpfc_driver);
  1969. fc_release_transport(lpfc_transport_template);
  1970. fc_release_transport(lpfc_vport_transport_template);
  1971. }
  1972. module_init(lpfc_init);
  1973. module_exit(lpfc_exit);
  1974. MODULE_LICENSE("GPL");
  1975. MODULE_DESCRIPTION(LPFC_MODULE_DESC);
  1976. MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com");
  1977. MODULE_VERSION("0:" LPFC_DRIVER_VERSION);