lpfc_init.c 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2005 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 <scsi/scsi.h>
  30. #include <scsi/scsi_device.h>
  31. #include <scsi/scsi_host.h>
  32. #include <scsi/scsi_transport_fc.h>
  33. #include "lpfc_hw.h"
  34. #include "lpfc_sli.h"
  35. #include "lpfc_disc.h"
  36. #include "lpfc_scsi.h"
  37. #include "lpfc.h"
  38. #include "lpfc_logmsg.h"
  39. #include "lpfc_crtn.h"
  40. #include "lpfc_version.h"
  41. static int lpfc_parse_vpd(struct lpfc_hba *, uint8_t *);
  42. static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *);
  43. static int lpfc_post_rcv_buf(struct lpfc_hba *);
  44. static struct scsi_transport_template *lpfc_transport_template = NULL;
  45. static DEFINE_IDR(lpfc_hba_index);
  46. /************************************************************************/
  47. /* */
  48. /* lpfc_config_port_prep */
  49. /* This routine will do LPFC initialization prior to the */
  50. /* CONFIG_PORT mailbox command. This will be initialized */
  51. /* as a SLI layer callback routine. */
  52. /* This routine returns 0 on success or -ERESTART if it wants */
  53. /* the SLI layer to reset the HBA and try again. Any */
  54. /* other return value indicates an error. */
  55. /* */
  56. /************************************************************************/
  57. int
  58. lpfc_config_port_prep(struct lpfc_hba * phba)
  59. {
  60. lpfc_vpd_t *vp = &phba->vpd;
  61. int i = 0, rc;
  62. LPFC_MBOXQ_t *pmb;
  63. MAILBOX_t *mb;
  64. char *lpfc_vpd_data = NULL;
  65. uint16_t offset = 0;
  66. static char licensed[56] =
  67. "key unlock for use with gnu public licensed code only\0";
  68. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  69. if (!pmb) {
  70. phba->hba_state = LPFC_HBA_ERROR;
  71. return -ENOMEM;
  72. }
  73. mb = &pmb->mb;
  74. phba->hba_state = LPFC_INIT_MBX_CMDS;
  75. if (lpfc_is_LC_HBA(phba->pcidev->device)) {
  76. uint32_t *ptext = (uint32_t *) licensed;
  77. for (i = 0; i < 56; i += sizeof (uint32_t), ptext++)
  78. *ptext = cpu_to_be32(*ptext);
  79. lpfc_read_nv(phba, pmb);
  80. memset((char*)mb->un.varRDnvp.rsvd3, 0,
  81. sizeof (mb->un.varRDnvp.rsvd3));
  82. memcpy((char*)mb->un.varRDnvp.rsvd3, licensed,
  83. sizeof (licensed));
  84. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  85. if (rc != MBX_SUCCESS) {
  86. lpfc_printf_log(phba,
  87. KERN_ERR,
  88. LOG_MBOX,
  89. "%d:0324 Config Port initialization "
  90. "error, mbxCmd x%x READ_NVPARM, "
  91. "mbxStatus x%x\n",
  92. phba->brd_no,
  93. mb->mbxCommand, mb->mbxStatus);
  94. mempool_free(pmb, phba->mbox_mem_pool);
  95. return -ERESTART;
  96. }
  97. memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename,
  98. sizeof (mb->un.varRDnvp.nodename));
  99. }
  100. /* Setup and issue mailbox READ REV command */
  101. lpfc_read_rev(phba, pmb);
  102. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  103. if (rc != MBX_SUCCESS) {
  104. lpfc_printf_log(phba,
  105. KERN_ERR,
  106. LOG_INIT,
  107. "%d:0439 Adapter failed to init, mbxCmd x%x "
  108. "READ_REV, mbxStatus x%x\n",
  109. phba->brd_no,
  110. mb->mbxCommand, mb->mbxStatus);
  111. mempool_free( pmb, phba->mbox_mem_pool);
  112. return -ERESTART;
  113. }
  114. /*
  115. * The value of rr must be 1 since the driver set the cv field to 1.
  116. * This setting requires the FW to set all revision fields.
  117. */
  118. if (mb->un.varRdRev.rr == 0) {
  119. vp->rev.rBit = 0;
  120. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  121. "%d:0440 Adapter failed to init, READ_REV has "
  122. "missing revision information.\n",
  123. phba->brd_no);
  124. mempool_free(pmb, phba->mbox_mem_pool);
  125. return -ERESTART;
  126. }
  127. /* Save information as VPD data */
  128. vp->rev.rBit = 1;
  129. vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev;
  130. memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16);
  131. vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev;
  132. memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16);
  133. vp->rev.biuRev = mb->un.varRdRev.biuRev;
  134. vp->rev.smRev = mb->un.varRdRev.smRev;
  135. vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev;
  136. vp->rev.endecRev = mb->un.varRdRev.endecRev;
  137. vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh;
  138. vp->rev.fcphLow = mb->un.varRdRev.fcphLow;
  139. vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh;
  140. vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow;
  141. vp->rev.postKernRev = mb->un.varRdRev.postKernRev;
  142. vp->rev.opFwRev = mb->un.varRdRev.opFwRev;
  143. if (lpfc_is_LC_HBA(phba->pcidev->device))
  144. memcpy(phba->RandomData, (char *)&mb->un.varWords[24],
  145. sizeof (phba->RandomData));
  146. /* Get the default values for Model Name and Description */
  147. lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
  148. /* Get adapter VPD information */
  149. pmb->context2 = kmalloc(DMP_RSP_SIZE, GFP_KERNEL);
  150. if (!pmb->context2)
  151. goto out_free_mbox;
  152. lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL);
  153. if (!lpfc_vpd_data)
  154. goto out_free_context2;
  155. do {
  156. lpfc_dump_mem(phba, pmb, offset);
  157. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  158. if (rc != MBX_SUCCESS) {
  159. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  160. "%d:0441 VPD not present on adapter, "
  161. "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
  162. phba->brd_no,
  163. mb->mbxCommand, mb->mbxStatus);
  164. kfree(lpfc_vpd_data);
  165. lpfc_vpd_data = NULL;
  166. break;
  167. }
  168. lpfc_sli_pcimem_bcopy(pmb->context2, lpfc_vpd_data + offset,
  169. mb->un.varDmp.word_cnt);
  170. offset += mb->un.varDmp.word_cnt;
  171. } while (mb->un.varDmp.word_cnt);
  172. lpfc_parse_vpd(phba, lpfc_vpd_data);
  173. kfree(lpfc_vpd_data);
  174. out_free_context2:
  175. kfree(pmb->context2);
  176. out_free_mbox:
  177. mempool_free(pmb, phba->mbox_mem_pool);
  178. return 0;
  179. }
  180. /************************************************************************/
  181. /* */
  182. /* lpfc_config_port_post */
  183. /* This routine will do LPFC initialization after the */
  184. /* CONFIG_PORT mailbox command. This will be initialized */
  185. /* as a SLI layer callback routine. */
  186. /* This routine returns 0 on success. Any other return value */
  187. /* indicates an error. */
  188. /* */
  189. /************************************************************************/
  190. int
  191. lpfc_config_port_post(struct lpfc_hba * phba)
  192. {
  193. LPFC_MBOXQ_t *pmb;
  194. MAILBOX_t *mb;
  195. struct lpfc_dmabuf *mp;
  196. struct lpfc_sli *psli = &phba->sli;
  197. uint32_t status, timeout;
  198. int i, j, rc;
  199. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  200. if (!pmb) {
  201. phba->hba_state = LPFC_HBA_ERROR;
  202. return -ENOMEM;
  203. }
  204. mb = &pmb->mb;
  205. lpfc_config_link(phba, pmb);
  206. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  207. if (rc != MBX_SUCCESS) {
  208. lpfc_printf_log(phba,
  209. KERN_ERR,
  210. LOG_INIT,
  211. "%d:0447 Adapter failed init, mbxCmd x%x "
  212. "CONFIG_LINK mbxStatus x%x\n",
  213. phba->brd_no,
  214. mb->mbxCommand, mb->mbxStatus);
  215. phba->hba_state = LPFC_HBA_ERROR;
  216. mempool_free( pmb, phba->mbox_mem_pool);
  217. return -EIO;
  218. }
  219. /* Get login parameters for NID. */
  220. lpfc_read_sparam(phba, pmb);
  221. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  222. lpfc_printf_log(phba,
  223. KERN_ERR,
  224. LOG_INIT,
  225. "%d:0448 Adapter failed init, mbxCmd x%x "
  226. "READ_SPARM mbxStatus x%x\n",
  227. phba->brd_no,
  228. mb->mbxCommand, mb->mbxStatus);
  229. phba->hba_state = LPFC_HBA_ERROR;
  230. mp = (struct lpfc_dmabuf *) pmb->context1;
  231. mempool_free( pmb, phba->mbox_mem_pool);
  232. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  233. kfree(mp);
  234. return -EIO;
  235. }
  236. mp = (struct lpfc_dmabuf *) pmb->context1;
  237. memcpy(&phba->fc_sparam, mp->virt, sizeof (struct serv_parm));
  238. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  239. kfree(mp);
  240. pmb->context1 = NULL;
  241. memcpy(&phba->fc_nodename, &phba->fc_sparam.nodeName,
  242. sizeof (struct lpfc_name));
  243. memcpy(&phba->fc_portname, &phba->fc_sparam.portName,
  244. sizeof (struct lpfc_name));
  245. /* If no serial number in VPD data, use low 6 bytes of WWNN */
  246. /* This should be consolidated into parse_vpd ? - mr */
  247. if (phba->SerialNumber[0] == 0) {
  248. uint8_t *outptr;
  249. outptr = &phba->fc_nodename.u.s.IEEE[0];
  250. for (i = 0; i < 12; i++) {
  251. status = *outptr++;
  252. j = ((status & 0xf0) >> 4);
  253. if (j <= 9)
  254. phba->SerialNumber[i] =
  255. (char)((uint8_t) 0x30 + (uint8_t) j);
  256. else
  257. phba->SerialNumber[i] =
  258. (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
  259. i++;
  260. j = (status & 0xf);
  261. if (j <= 9)
  262. phba->SerialNumber[i] =
  263. (char)((uint8_t) 0x30 + (uint8_t) j);
  264. else
  265. phba->SerialNumber[i] =
  266. (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
  267. }
  268. }
  269. /* This should turn on DELAYED ABTS for ELS timeouts */
  270. lpfc_set_slim(phba, pmb, 0x052198, 0x1);
  271. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  272. phba->hba_state = LPFC_HBA_ERROR;
  273. mempool_free( pmb, phba->mbox_mem_pool);
  274. return -EIO;
  275. }
  276. lpfc_read_config(phba, pmb);
  277. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  278. lpfc_printf_log(phba,
  279. KERN_ERR,
  280. LOG_INIT,
  281. "%d:0453 Adapter failed to init, mbxCmd x%x "
  282. "READ_CONFIG, mbxStatus x%x\n",
  283. phba->brd_no,
  284. mb->mbxCommand, mb->mbxStatus);
  285. phba->hba_state = LPFC_HBA_ERROR;
  286. mempool_free( pmb, phba->mbox_mem_pool);
  287. return -EIO;
  288. }
  289. /* Reset the DFT_HBA_Q_DEPTH to the max xri */
  290. if (phba->cfg_hba_queue_depth > (mb->un.varRdConfig.max_xri+1))
  291. phba->cfg_hba_queue_depth =
  292. mb->un.varRdConfig.max_xri + 1;
  293. phba->lmt = mb->un.varRdConfig.lmt;
  294. /* HBA is not 4GB capable, or HBA is not 2GB capable,
  295. don't let link speed ask for it */
  296. if ((((phba->lmt & LMT_4250_10bit) != LMT_4250_10bit) &&
  297. (phba->cfg_link_speed > LINK_SPEED_2G)) ||
  298. (((phba->lmt & LMT_2125_10bit) != LMT_2125_10bit) &&
  299. (phba->cfg_link_speed > LINK_SPEED_1G))) {
  300. /* Reset link speed to auto. 1G/2GB HBA cfg'd for 4G */
  301. lpfc_printf_log(phba,
  302. KERN_WARNING,
  303. LOG_LINK_EVENT,
  304. "%d:1302 Invalid speed for this board: "
  305. "Reset link speed to auto: x%x\n",
  306. phba->brd_no,
  307. phba->cfg_link_speed);
  308. phba->cfg_link_speed = LINK_SPEED_AUTO;
  309. }
  310. phba->hba_state = LPFC_LINK_DOWN;
  311. /* Only process IOCBs on ring 0 till hba_state is READY */
  312. if (psli->ring[psli->ip_ring].cmdringaddr)
  313. psli->ring[psli->ip_ring].flag |= LPFC_STOP_IOCB_EVENT;
  314. if (psli->ring[psli->fcp_ring].cmdringaddr)
  315. psli->ring[psli->fcp_ring].flag |= LPFC_STOP_IOCB_EVENT;
  316. if (psli->ring[psli->next_ring].cmdringaddr)
  317. psli->ring[psli->next_ring].flag |= LPFC_STOP_IOCB_EVENT;
  318. /* Post receive buffers for desired rings */
  319. lpfc_post_rcv_buf(phba);
  320. /* Enable appropriate host interrupts */
  321. spin_lock_irq(phba->host->host_lock);
  322. status = readl(phba->HCregaddr);
  323. status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA;
  324. if (psli->num_rings > 0)
  325. status |= HC_R0INT_ENA;
  326. if (psli->num_rings > 1)
  327. status |= HC_R1INT_ENA;
  328. if (psli->num_rings > 2)
  329. status |= HC_R2INT_ENA;
  330. if (psli->num_rings > 3)
  331. status |= HC_R3INT_ENA;
  332. if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) &&
  333. (phba->cfg_poll & DISABLE_FCP_RING_INT))
  334. status &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
  335. writel(status, phba->HCregaddr);
  336. readl(phba->HCregaddr); /* flush */
  337. spin_unlock_irq(phba->host->host_lock);
  338. /*
  339. * Setup the ring 0 (els) timeout handler
  340. */
  341. timeout = phba->fc_ratov << 1;
  342. phba->els_tmofunc.expires = jiffies + HZ * timeout;
  343. add_timer(&phba->els_tmofunc);
  344. lpfc_init_link(phba, pmb, phba->cfg_topology, phba->cfg_link_speed);
  345. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  346. if (lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT) != MBX_SUCCESS) {
  347. lpfc_printf_log(phba,
  348. KERN_ERR,
  349. LOG_INIT,
  350. "%d:0454 Adapter failed to init, mbxCmd x%x "
  351. "INIT_LINK, mbxStatus x%x\n",
  352. phba->brd_no,
  353. mb->mbxCommand, mb->mbxStatus);
  354. /* Clear all interrupt enable conditions */
  355. writel(0, phba->HCregaddr);
  356. readl(phba->HCregaddr); /* flush */
  357. /* Clear all pending interrupts */
  358. writel(0xffffffff, phba->HAregaddr);
  359. readl(phba->HAregaddr); /* flush */
  360. phba->hba_state = LPFC_HBA_ERROR;
  361. mempool_free(pmb, phba->mbox_mem_pool);
  362. return -EIO;
  363. }
  364. /* MBOX buffer will be freed in mbox compl */
  365. i = 0;
  366. while ((phba->hba_state != LPFC_HBA_READY) ||
  367. (phba->num_disc_nodes) || (phba->fc_prli_sent) ||
  368. ((phba->fc_map_cnt == 0) && (i<2)) ||
  369. (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE)) {
  370. /* Check every second for 30 retries. */
  371. i++;
  372. if (i > 30) {
  373. break;
  374. }
  375. if ((i >= 15) && (phba->hba_state <= LPFC_LINK_DOWN)) {
  376. /* The link is down. Set linkdown timeout */
  377. break;
  378. }
  379. /* Delay for 1 second to give discovery time to complete. */
  380. msleep(1000);
  381. }
  382. /* Since num_disc_nodes keys off of PLOGI, delay a bit to let
  383. * any potential PRLIs to flush thru the SLI sub-system.
  384. */
  385. msleep(50);
  386. return (0);
  387. }
  388. /************************************************************************/
  389. /* */
  390. /* lpfc_hba_down_prep */
  391. /* This routine will do LPFC uninitialization before the */
  392. /* HBA is reset when bringing down the SLI Layer. This will be */
  393. /* initialized as a SLI layer callback routine. */
  394. /* This routine returns 0 on success. Any other return value */
  395. /* indicates an error. */
  396. /* */
  397. /************************************************************************/
  398. int
  399. lpfc_hba_down_prep(struct lpfc_hba * phba)
  400. {
  401. /* Disable interrupts */
  402. writel(0, phba->HCregaddr);
  403. readl(phba->HCregaddr); /* flush */
  404. /* Cleanup potential discovery resources */
  405. lpfc_els_flush_rscn(phba);
  406. lpfc_els_flush_cmd(phba);
  407. lpfc_disc_flush_list(phba);
  408. return (0);
  409. }
  410. /************************************************************************/
  411. /* */
  412. /* lpfc_handle_eratt */
  413. /* This routine will handle processing a Host Attention */
  414. /* Error Status event. This will be initialized */
  415. /* as a SLI layer callback routine. */
  416. /* */
  417. /************************************************************************/
  418. void
  419. lpfc_handle_eratt(struct lpfc_hba * phba)
  420. {
  421. struct lpfc_sli *psli = &phba->sli;
  422. struct lpfc_sli_ring *pring;
  423. /*
  424. * If a reset is sent to the HBA restore PCI configuration registers.
  425. */
  426. if ( phba->hba_state == LPFC_INIT_START ) {
  427. mdelay(1);
  428. readl(phba->HCregaddr); /* flush */
  429. writel(0, phba->HCregaddr);
  430. readl(phba->HCregaddr); /* flush */
  431. /* Restore PCI cmd register */
  432. pci_write_config_word(phba->pcidev,
  433. PCI_COMMAND, phba->pci_cfg_value);
  434. }
  435. if (phba->work_hs & HS_FFER6) {
  436. /* Re-establishing Link */
  437. lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
  438. "%d:1301 Re-establishing Link "
  439. "Data: x%x x%x x%x\n",
  440. phba->brd_no, phba->work_hs,
  441. phba->work_status[0], phba->work_status[1]);
  442. spin_lock_irq(phba->host->host_lock);
  443. phba->fc_flag |= FC_ESTABLISH_LINK;
  444. spin_unlock_irq(phba->host->host_lock);
  445. /*
  446. * Firmware stops when it triggled erratt with HS_FFER6.
  447. * That could cause the I/Os dropped by the firmware.
  448. * Error iocb (I/O) on txcmplq and let the SCSI layer
  449. * retry it after re-establishing link.
  450. */
  451. pring = &psli->ring[psli->fcp_ring];
  452. lpfc_sli_abort_iocb_ring(phba, pring);
  453. /*
  454. * There was a firmware error. Take the hba offline and then
  455. * attempt to restart it.
  456. */
  457. lpfc_offline(phba);
  458. if (lpfc_online(phba) == 0) { /* Initialize the HBA */
  459. mod_timer(&phba->fc_estabtmo, jiffies + HZ * 60);
  460. return;
  461. }
  462. } else {
  463. /* The if clause above forces this code path when the status
  464. * failure is a value other than FFER6. Do not call the offline
  465. * twice. This is the adapter hardware error path.
  466. */
  467. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  468. "%d:0457 Adapter Hardware Error "
  469. "Data: x%x x%x x%x\n",
  470. phba->brd_no, phba->work_hs,
  471. phba->work_status[0], phba->work_status[1]);
  472. lpfc_offline(phba);
  473. }
  474. }
  475. /************************************************************************/
  476. /* */
  477. /* lpfc_handle_latt */
  478. /* This routine will handle processing a Host Attention */
  479. /* Link Status event. This will be initialized */
  480. /* as a SLI layer callback routine. */
  481. /* */
  482. /************************************************************************/
  483. void
  484. lpfc_handle_latt(struct lpfc_hba * phba)
  485. {
  486. struct lpfc_sli *psli = &phba->sli;
  487. LPFC_MBOXQ_t *pmb;
  488. volatile uint32_t control;
  489. struct lpfc_dmabuf *mp;
  490. int rc = -ENOMEM;
  491. pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  492. if (!pmb)
  493. goto lpfc_handle_latt_err_exit;
  494. mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  495. if (!mp)
  496. goto lpfc_handle_latt_free_pmb;
  497. mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
  498. if (!mp->virt)
  499. goto lpfc_handle_latt_free_mp;
  500. rc = -EIO;
  501. /* Cleanup any outstanding ELS commands */
  502. lpfc_els_flush_cmd(phba);
  503. psli->slistat.link_event++;
  504. lpfc_read_la(phba, pmb, mp);
  505. pmb->mbox_cmpl = lpfc_mbx_cmpl_read_la;
  506. rc = lpfc_sli_issue_mbox (phba, pmb, (MBX_NOWAIT | MBX_STOP_IOCB));
  507. if (rc == MBX_NOT_FINISHED)
  508. goto lpfc_handle_latt_free_mp;
  509. /* Clear Link Attention in HA REG */
  510. spin_lock_irq(phba->host->host_lock);
  511. writel(HA_LATT, phba->HAregaddr);
  512. readl(phba->HAregaddr); /* flush */
  513. spin_unlock_irq(phba->host->host_lock);
  514. return;
  515. lpfc_handle_latt_free_mp:
  516. kfree(mp);
  517. lpfc_handle_latt_free_pmb:
  518. kfree(pmb);
  519. lpfc_handle_latt_err_exit:
  520. /* Enable Link attention interrupts */
  521. spin_lock_irq(phba->host->host_lock);
  522. psli->sli_flag |= LPFC_PROCESS_LA;
  523. control = readl(phba->HCregaddr);
  524. control |= HC_LAINT_ENA;
  525. writel(control, phba->HCregaddr);
  526. readl(phba->HCregaddr); /* flush */
  527. /* Clear Link Attention in HA REG */
  528. writel(HA_LATT, phba->HAregaddr);
  529. readl(phba->HAregaddr); /* flush */
  530. spin_unlock_irq(phba->host->host_lock);
  531. lpfc_linkdown(phba);
  532. phba->hba_state = LPFC_HBA_ERROR;
  533. /* The other case is an error from issue_mbox */
  534. if (rc == -ENOMEM)
  535. lpfc_printf_log(phba,
  536. KERN_WARNING,
  537. LOG_MBOX,
  538. "%d:0300 READ_LA: no buffers\n",
  539. phba->brd_no);
  540. return;
  541. }
  542. /************************************************************************/
  543. /* */
  544. /* lpfc_parse_vpd */
  545. /* This routine will parse the VPD data */
  546. /* */
  547. /************************************************************************/
  548. static int
  549. lpfc_parse_vpd(struct lpfc_hba * phba, uint8_t * vpd)
  550. {
  551. uint8_t lenlo, lenhi;
  552. uint32_t Length;
  553. int i, j;
  554. int finished = 0;
  555. int index = 0;
  556. if (!vpd)
  557. return 0;
  558. /* Vital Product */
  559. lpfc_printf_log(phba,
  560. KERN_INFO,
  561. LOG_INIT,
  562. "%d:0455 Vital Product Data: x%x x%x x%x x%x\n",
  563. phba->brd_no,
  564. (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
  565. (uint32_t) vpd[3]);
  566. do {
  567. switch (vpd[index]) {
  568. case 0x82:
  569. index += 1;
  570. lenlo = vpd[index];
  571. index += 1;
  572. lenhi = vpd[index];
  573. index += 1;
  574. i = ((((unsigned short)lenhi) << 8) + lenlo);
  575. index += i;
  576. break;
  577. case 0x90:
  578. index += 1;
  579. lenlo = vpd[index];
  580. index += 1;
  581. lenhi = vpd[index];
  582. index += 1;
  583. Length = ((((unsigned short)lenhi) << 8) + lenlo);
  584. while (Length > 0) {
  585. /* Look for Serial Number */
  586. if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) {
  587. index += 2;
  588. i = vpd[index];
  589. index += 1;
  590. j = 0;
  591. Length -= (3+i);
  592. while(i--) {
  593. phba->SerialNumber[j++] = vpd[index++];
  594. if (j == 31)
  595. break;
  596. }
  597. phba->SerialNumber[j] = 0;
  598. continue;
  599. }
  600. else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) {
  601. phba->vpd_flag |= VPD_MODEL_DESC;
  602. index += 2;
  603. i = vpd[index];
  604. index += 1;
  605. j = 0;
  606. Length -= (3+i);
  607. while(i--) {
  608. phba->ModelDesc[j++] = vpd[index++];
  609. if (j == 255)
  610. break;
  611. }
  612. phba->ModelDesc[j] = 0;
  613. continue;
  614. }
  615. else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) {
  616. phba->vpd_flag |= VPD_MODEL_NAME;
  617. index += 2;
  618. i = vpd[index];
  619. index += 1;
  620. j = 0;
  621. Length -= (3+i);
  622. while(i--) {
  623. phba->ModelName[j++] = vpd[index++];
  624. if (j == 79)
  625. break;
  626. }
  627. phba->ModelName[j] = 0;
  628. continue;
  629. }
  630. else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) {
  631. phba->vpd_flag |= VPD_PROGRAM_TYPE;
  632. index += 2;
  633. i = vpd[index];
  634. index += 1;
  635. j = 0;
  636. Length -= (3+i);
  637. while(i--) {
  638. phba->ProgramType[j++] = vpd[index++];
  639. if (j == 255)
  640. break;
  641. }
  642. phba->ProgramType[j] = 0;
  643. continue;
  644. }
  645. else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) {
  646. phba->vpd_flag |= VPD_PORT;
  647. index += 2;
  648. i = vpd[index];
  649. index += 1;
  650. j = 0;
  651. Length -= (3+i);
  652. while(i--) {
  653. phba->Port[j++] = vpd[index++];
  654. if (j == 19)
  655. break;
  656. }
  657. phba->Port[j] = 0;
  658. continue;
  659. }
  660. else {
  661. index += 2;
  662. i = vpd[index];
  663. index += 1;
  664. index += i;
  665. Length -= (3 + i);
  666. }
  667. }
  668. finished = 0;
  669. break;
  670. case 0x78:
  671. finished = 1;
  672. break;
  673. default:
  674. index ++;
  675. break;
  676. }
  677. } while (!finished && (index < 108));
  678. return(1);
  679. }
  680. static void
  681. lpfc_get_hba_model_desc(struct lpfc_hba * phba, uint8_t * mdp, uint8_t * descp)
  682. {
  683. lpfc_vpd_t *vp;
  684. uint16_t dev_id = phba->pcidev->device;
  685. uint16_t dev_subid = phba->pcidev->subsystem_device;
  686. uint8_t hdrtype = phba->pcidev->hdr_type;
  687. char *model_str = "";
  688. vp = &phba->vpd;
  689. switch (dev_id) {
  690. case PCI_DEVICE_ID_FIREFLY:
  691. model_str = "LP6000 1Gb PCI";
  692. break;
  693. case PCI_DEVICE_ID_SUPERFLY:
  694. if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
  695. model_str = "LP7000 1Gb PCI";
  696. else
  697. model_str = "LP7000E 1Gb PCI";
  698. break;
  699. case PCI_DEVICE_ID_DRAGONFLY:
  700. model_str = "LP8000 1Gb PCI";
  701. break;
  702. case PCI_DEVICE_ID_CENTAUR:
  703. if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
  704. model_str = "LP9002 2Gb PCI";
  705. else
  706. model_str = "LP9000 1Gb PCI";
  707. break;
  708. case PCI_DEVICE_ID_RFLY:
  709. model_str = "LP952 2Gb PCI";
  710. break;
  711. case PCI_DEVICE_ID_PEGASUS:
  712. model_str = "LP9802 2Gb PCI-X";
  713. break;
  714. case PCI_DEVICE_ID_THOR:
  715. if (hdrtype == 0x80)
  716. model_str = "LP10000DC 2Gb 2-port PCI-X";
  717. else
  718. model_str = "LP10000 2Gb PCI-X";
  719. break;
  720. case PCI_DEVICE_ID_VIPER:
  721. model_str = "LPX1000 10Gb PCI-X";
  722. break;
  723. case PCI_DEVICE_ID_PFLY:
  724. model_str = "LP982 2Gb PCI-X";
  725. break;
  726. case PCI_DEVICE_ID_TFLY:
  727. if (hdrtype == 0x80)
  728. model_str = "LP1050DC 2Gb 2-port PCI-X";
  729. else
  730. model_str = "LP1050 2Gb PCI-X";
  731. break;
  732. case PCI_DEVICE_ID_HELIOS:
  733. if (hdrtype == 0x80)
  734. model_str = "LP11002 4Gb 2-port PCI-X2";
  735. else
  736. model_str = "LP11000 4Gb PCI-X2";
  737. break;
  738. case PCI_DEVICE_ID_HELIOS_SCSP:
  739. model_str = "LP11000-SP 4Gb PCI-X2";
  740. break;
  741. case PCI_DEVICE_ID_HELIOS_DCSP:
  742. model_str = "LP11002-SP 4Gb 2-port PCI-X2";
  743. break;
  744. case PCI_DEVICE_ID_NEPTUNE:
  745. if (hdrtype == 0x80)
  746. model_str = "LPe1002 4Gb 2-port";
  747. else
  748. model_str = "LPe1000 4Gb PCIe";
  749. break;
  750. case PCI_DEVICE_ID_NEPTUNE_SCSP:
  751. model_str = "LPe1000-SP 4Gb PCIe";
  752. break;
  753. case PCI_DEVICE_ID_NEPTUNE_DCSP:
  754. model_str = "LPe1002-SP 4Gb 2-port PCIe";
  755. break;
  756. case PCI_DEVICE_ID_BMID:
  757. model_str = "LP1150 4Gb PCI-X2";
  758. break;
  759. case PCI_DEVICE_ID_BSMB:
  760. model_str = "LP111 4Gb PCI-X2";
  761. break;
  762. case PCI_DEVICE_ID_ZEPHYR:
  763. if (hdrtype == 0x80)
  764. model_str = "LPe11002 4Gb 2-port PCIe";
  765. else
  766. model_str = "LPe11000 4Gb PCIe";
  767. break;
  768. case PCI_DEVICE_ID_ZEPHYR_SCSP:
  769. model_str = "LPe11000-SP 4Gb PCIe";
  770. break;
  771. case PCI_DEVICE_ID_ZEPHYR_DCSP:
  772. model_str = "LPe11002-SP 4Gb 2-port PCIe";
  773. break;
  774. case PCI_DEVICE_ID_ZMID:
  775. model_str = "LPe1150 4Gb PCIe";
  776. break;
  777. case PCI_DEVICE_ID_ZSMB:
  778. model_str = "LPe111 4Gb PCIe";
  779. break;
  780. case PCI_DEVICE_ID_LP101:
  781. model_str = "LP101 2Gb PCI-X";
  782. break;
  783. case PCI_DEVICE_ID_LP10000S:
  784. model_str = "LP10000-S 2Gb PCI";
  785. break;
  786. case PCI_DEVICE_ID_LP11000S:
  787. case PCI_DEVICE_ID_LPE11000S:
  788. switch (dev_subid) {
  789. case PCI_SUBSYSTEM_ID_LP11000S:
  790. model_str = "LP11002-S 4Gb PCI-X2";
  791. break;
  792. case PCI_SUBSYSTEM_ID_LP11002S:
  793. model_str = "LP11000-S 4Gb 2-port PCI-X2";
  794. break;
  795. case PCI_SUBSYSTEM_ID_LPE11000S:
  796. model_str = "LPe11002-S 4Gb PCIe";
  797. break;
  798. case PCI_SUBSYSTEM_ID_LPE11002S:
  799. model_str = "LPe11002-S 4Gb 2-port PCIe";
  800. break;
  801. case PCI_SUBSYSTEM_ID_LPE11010S:
  802. model_str = "LPe11010-S 4Gb 10-port PCIe";
  803. break;
  804. default:
  805. break;
  806. }
  807. break;
  808. default:
  809. break;
  810. }
  811. if (mdp)
  812. sscanf(model_str, "%s", mdp);
  813. if (descp)
  814. sprintf(descp, "Emulex %s Fibre Channel Adapter", model_str);
  815. }
  816. /**************************************************/
  817. /* lpfc_post_buffer */
  818. /* */
  819. /* This routine will post count buffers to the */
  820. /* ring with the QUE_RING_BUF_CN command. This */
  821. /* allows 3 buffers / command to be posted. */
  822. /* Returns the number of buffers NOT posted. */
  823. /**************************************************/
  824. int
  825. lpfc_post_buffer(struct lpfc_hba * phba, struct lpfc_sli_ring * pring, int cnt,
  826. int type)
  827. {
  828. IOCB_t *icmd;
  829. struct lpfc_iocbq *iocb;
  830. struct lpfc_dmabuf *mp1, *mp2;
  831. cnt += pring->missbufcnt;
  832. /* While there are buffers to post */
  833. while (cnt > 0) {
  834. /* Allocate buffer for command iocb */
  835. spin_lock_irq(phba->host->host_lock);
  836. iocb = lpfc_sli_get_iocbq(phba);
  837. spin_unlock_irq(phba->host->host_lock);
  838. if (iocb == NULL) {
  839. pring->missbufcnt = cnt;
  840. return cnt;
  841. }
  842. icmd = &iocb->iocb;
  843. /* 2 buffers can be posted per command */
  844. /* Allocate buffer to post */
  845. mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
  846. if (mp1)
  847. mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
  848. &mp1->phys);
  849. if (mp1 == 0 || mp1->virt == 0) {
  850. kfree(mp1);
  851. spin_lock_irq(phba->host->host_lock);
  852. lpfc_sli_release_iocbq(phba, iocb);
  853. spin_unlock_irq(phba->host->host_lock);
  854. pring->missbufcnt = cnt;
  855. return cnt;
  856. }
  857. INIT_LIST_HEAD(&mp1->list);
  858. /* Allocate buffer to post */
  859. if (cnt > 1) {
  860. mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
  861. if (mp2)
  862. mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
  863. &mp2->phys);
  864. if (mp2 == 0 || mp2->virt == 0) {
  865. kfree(mp2);
  866. lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
  867. kfree(mp1);
  868. spin_lock_irq(phba->host->host_lock);
  869. lpfc_sli_release_iocbq(phba, iocb);
  870. spin_unlock_irq(phba->host->host_lock);
  871. pring->missbufcnt = cnt;
  872. return cnt;
  873. }
  874. INIT_LIST_HEAD(&mp2->list);
  875. } else {
  876. mp2 = NULL;
  877. }
  878. icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
  879. icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
  880. icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
  881. icmd->ulpBdeCount = 1;
  882. cnt--;
  883. if (mp2) {
  884. icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
  885. icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
  886. icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
  887. cnt--;
  888. icmd->ulpBdeCount = 2;
  889. }
  890. icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
  891. icmd->ulpLe = 1;
  892. spin_lock_irq(phba->host->host_lock);
  893. if (lpfc_sli_issue_iocb(phba, pring, iocb, 0) == IOCB_ERROR) {
  894. lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
  895. kfree(mp1);
  896. cnt++;
  897. if (mp2) {
  898. lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
  899. kfree(mp2);
  900. cnt++;
  901. }
  902. lpfc_sli_release_iocbq(phba, iocb);
  903. pring->missbufcnt = cnt;
  904. spin_unlock_irq(phba->host->host_lock);
  905. return cnt;
  906. }
  907. spin_unlock_irq(phba->host->host_lock);
  908. lpfc_sli_ringpostbuf_put(phba, pring, mp1);
  909. if (mp2) {
  910. lpfc_sli_ringpostbuf_put(phba, pring, mp2);
  911. }
  912. }
  913. pring->missbufcnt = 0;
  914. return 0;
  915. }
  916. /************************************************************************/
  917. /* */
  918. /* lpfc_post_rcv_buf */
  919. /* This routine post initial rcv buffers to the configured rings */
  920. /* */
  921. /************************************************************************/
  922. static int
  923. lpfc_post_rcv_buf(struct lpfc_hba * phba)
  924. {
  925. struct lpfc_sli *psli = &phba->sli;
  926. /* Ring 0, ELS / CT buffers */
  927. lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0, 1);
  928. /* Ring 2 - FCP no buffers needed */
  929. return 0;
  930. }
  931. #define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
  932. /************************************************************************/
  933. /* */
  934. /* lpfc_sha_init */
  935. /* */
  936. /************************************************************************/
  937. static void
  938. lpfc_sha_init(uint32_t * HashResultPointer)
  939. {
  940. HashResultPointer[0] = 0x67452301;
  941. HashResultPointer[1] = 0xEFCDAB89;
  942. HashResultPointer[2] = 0x98BADCFE;
  943. HashResultPointer[3] = 0x10325476;
  944. HashResultPointer[4] = 0xC3D2E1F0;
  945. }
  946. /************************************************************************/
  947. /* */
  948. /* lpfc_sha_iterate */
  949. /* */
  950. /************************************************************************/
  951. static void
  952. lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
  953. {
  954. int t;
  955. uint32_t TEMP;
  956. uint32_t A, B, C, D, E;
  957. t = 16;
  958. do {
  959. HashWorkingPointer[t] =
  960. S(1,
  961. HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
  962. 8] ^
  963. HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
  964. } while (++t <= 79);
  965. t = 0;
  966. A = HashResultPointer[0];
  967. B = HashResultPointer[1];
  968. C = HashResultPointer[2];
  969. D = HashResultPointer[3];
  970. E = HashResultPointer[4];
  971. do {
  972. if (t < 20) {
  973. TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
  974. } else if (t < 40) {
  975. TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
  976. } else if (t < 60) {
  977. TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
  978. } else {
  979. TEMP = (B ^ C ^ D) + 0xCA62C1D6;
  980. }
  981. TEMP += S(5, A) + E + HashWorkingPointer[t];
  982. E = D;
  983. D = C;
  984. C = S(30, B);
  985. B = A;
  986. A = TEMP;
  987. } while (++t <= 79);
  988. HashResultPointer[0] += A;
  989. HashResultPointer[1] += B;
  990. HashResultPointer[2] += C;
  991. HashResultPointer[3] += D;
  992. HashResultPointer[4] += E;
  993. }
  994. /************************************************************************/
  995. /* */
  996. /* lpfc_challenge_key */
  997. /* */
  998. /************************************************************************/
  999. static void
  1000. lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
  1001. {
  1002. *HashWorking = (*RandomChallenge ^ *HashWorking);
  1003. }
  1004. /************************************************************************/
  1005. /* */
  1006. /* lpfc_hba_init */
  1007. /* */
  1008. /************************************************************************/
  1009. void
  1010. lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
  1011. {
  1012. int t;
  1013. uint32_t *HashWorking;
  1014. uint32_t *pwwnn = phba->wwnn;
  1015. HashWorking = kmalloc(80 * sizeof(uint32_t), GFP_KERNEL);
  1016. if (!HashWorking)
  1017. return;
  1018. memset(HashWorking, 0, (80 * sizeof(uint32_t)));
  1019. HashWorking[0] = HashWorking[78] = *pwwnn++;
  1020. HashWorking[1] = HashWorking[79] = *pwwnn;
  1021. for (t = 0; t < 7; t++)
  1022. lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
  1023. lpfc_sha_init(hbainit);
  1024. lpfc_sha_iterate(hbainit, HashWorking);
  1025. kfree(HashWorking);
  1026. }
  1027. static void
  1028. lpfc_cleanup(struct lpfc_hba * phba, uint32_t save_bind)
  1029. {
  1030. struct lpfc_nodelist *ndlp, *next_ndlp;
  1031. /* clean up phba - lpfc specific */
  1032. lpfc_can_disctmo(phba);
  1033. list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_nlpunmap_list,
  1034. nlp_listp) {
  1035. lpfc_nlp_remove(phba, ndlp);
  1036. }
  1037. list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_nlpmap_list,
  1038. nlp_listp) {
  1039. lpfc_nlp_remove(phba, ndlp);
  1040. }
  1041. list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_unused_list,
  1042. nlp_listp) {
  1043. lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
  1044. }
  1045. list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_plogi_list,
  1046. nlp_listp) {
  1047. lpfc_nlp_remove(phba, ndlp);
  1048. }
  1049. list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_adisc_list,
  1050. nlp_listp) {
  1051. lpfc_nlp_remove(phba, ndlp);
  1052. }
  1053. list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_reglogin_list,
  1054. nlp_listp) {
  1055. lpfc_nlp_remove(phba, ndlp);
  1056. }
  1057. list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_prli_list,
  1058. nlp_listp) {
  1059. lpfc_nlp_remove(phba, ndlp);
  1060. }
  1061. list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
  1062. nlp_listp) {
  1063. lpfc_nlp_remove(phba, ndlp);
  1064. }
  1065. INIT_LIST_HEAD(&phba->fc_nlpmap_list);
  1066. INIT_LIST_HEAD(&phba->fc_nlpunmap_list);
  1067. INIT_LIST_HEAD(&phba->fc_unused_list);
  1068. INIT_LIST_HEAD(&phba->fc_plogi_list);
  1069. INIT_LIST_HEAD(&phba->fc_adisc_list);
  1070. INIT_LIST_HEAD(&phba->fc_reglogin_list);
  1071. INIT_LIST_HEAD(&phba->fc_prli_list);
  1072. INIT_LIST_HEAD(&phba->fc_npr_list);
  1073. phba->fc_map_cnt = 0;
  1074. phba->fc_unmap_cnt = 0;
  1075. phba->fc_plogi_cnt = 0;
  1076. phba->fc_adisc_cnt = 0;
  1077. phba->fc_reglogin_cnt = 0;
  1078. phba->fc_prli_cnt = 0;
  1079. phba->fc_npr_cnt = 0;
  1080. phba->fc_unused_cnt= 0;
  1081. return;
  1082. }
  1083. static void
  1084. lpfc_establish_link_tmo(unsigned long ptr)
  1085. {
  1086. struct lpfc_hba *phba = (struct lpfc_hba *)ptr;
  1087. unsigned long iflag;
  1088. /* Re-establishing Link, timer expired */
  1089. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  1090. "%d:1300 Re-establishing Link, timer expired "
  1091. "Data: x%x x%x\n",
  1092. phba->brd_no, phba->fc_flag, phba->hba_state);
  1093. spin_lock_irqsave(phba->host->host_lock, iflag);
  1094. phba->fc_flag &= ~FC_ESTABLISH_LINK;
  1095. spin_unlock_irqrestore(phba->host->host_lock, iflag);
  1096. }
  1097. static int
  1098. lpfc_stop_timer(struct lpfc_hba * phba)
  1099. {
  1100. struct lpfc_sli *psli = &phba->sli;
  1101. /* Instead of a timer, this has been converted to a
  1102. * deferred procedding list.
  1103. */
  1104. while (!list_empty(&phba->freebufList)) {
  1105. struct lpfc_dmabuf *mp = NULL;
  1106. list_remove_head((&phba->freebufList), mp,
  1107. struct lpfc_dmabuf, list);
  1108. if (mp) {
  1109. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1110. kfree(mp);
  1111. }
  1112. }
  1113. del_timer_sync(&phba->fcp_poll_timer);
  1114. del_timer_sync(&phba->fc_estabtmo);
  1115. del_timer_sync(&phba->fc_disctmo);
  1116. del_timer_sync(&phba->fc_fdmitmo);
  1117. del_timer_sync(&phba->els_tmofunc);
  1118. psli = &phba->sli;
  1119. del_timer_sync(&psli->mbox_tmo);
  1120. return(1);
  1121. }
  1122. int
  1123. lpfc_online(struct lpfc_hba * phba)
  1124. {
  1125. if (!phba)
  1126. return 0;
  1127. if (!(phba->fc_flag & FC_OFFLINE_MODE))
  1128. return 0;
  1129. lpfc_printf_log(phba,
  1130. KERN_WARNING,
  1131. LOG_INIT,
  1132. "%d:0458 Bring Adapter online\n",
  1133. phba->brd_no);
  1134. if (!lpfc_sli_queue_setup(phba))
  1135. return 1;
  1136. if (lpfc_sli_hba_setup(phba)) /* Initialize the HBA */
  1137. return 1;
  1138. spin_lock_irq(phba->host->host_lock);
  1139. phba->fc_flag &= ~FC_OFFLINE_MODE;
  1140. spin_unlock_irq(phba->host->host_lock);
  1141. return 0;
  1142. }
  1143. int
  1144. lpfc_offline(struct lpfc_hba * phba)
  1145. {
  1146. struct lpfc_sli_ring *pring;
  1147. struct lpfc_sli *psli;
  1148. unsigned long iflag;
  1149. int i = 0;
  1150. if (!phba)
  1151. return 0;
  1152. if (phba->fc_flag & FC_OFFLINE_MODE)
  1153. return 0;
  1154. psli = &phba->sli;
  1155. pring = &psli->ring[psli->fcp_ring];
  1156. lpfc_linkdown(phba);
  1157. /* The linkdown event takes 30 seconds to timeout. */
  1158. while (pring->txcmplq_cnt) {
  1159. mdelay(10);
  1160. if (i++ > 3000)
  1161. break;
  1162. }
  1163. /* stop all timers associated with this hba */
  1164. lpfc_stop_timer(phba);
  1165. phba->work_hba_events = 0;
  1166. lpfc_printf_log(phba,
  1167. KERN_WARNING,
  1168. LOG_INIT,
  1169. "%d:0460 Bring Adapter offline\n",
  1170. phba->brd_no);
  1171. /* Bring down the SLI Layer and cleanup. The HBA is offline
  1172. now. */
  1173. lpfc_sli_hba_down(phba);
  1174. lpfc_cleanup(phba, 1);
  1175. spin_lock_irqsave(phba->host->host_lock, iflag);
  1176. phba->fc_flag |= FC_OFFLINE_MODE;
  1177. spin_unlock_irqrestore(phba->host->host_lock, iflag);
  1178. return 0;
  1179. }
  1180. /******************************************************************************
  1181. * Function name: lpfc_scsi_free
  1182. *
  1183. * Description: Called from lpfc_pci_remove_one free internal driver resources
  1184. *
  1185. ******************************************************************************/
  1186. static int
  1187. lpfc_scsi_free(struct lpfc_hba * phba)
  1188. {
  1189. struct lpfc_scsi_buf *sb, *sb_next;
  1190. struct lpfc_iocbq *io, *io_next;
  1191. spin_lock_irq(phba->host->host_lock);
  1192. /* Release all the lpfc_scsi_bufs maintained by this host. */
  1193. list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list, list) {
  1194. list_del(&sb->list);
  1195. pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data,
  1196. sb->dma_handle);
  1197. kfree(sb);
  1198. phba->total_scsi_bufs--;
  1199. }
  1200. /* Release all the lpfc_iocbq entries maintained by this host. */
  1201. list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) {
  1202. list_del(&io->list);
  1203. kfree(io);
  1204. phba->total_iocbq_bufs--;
  1205. }
  1206. spin_unlock_irq(phba->host->host_lock);
  1207. return 0;
  1208. }
  1209. static int __devinit
  1210. lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
  1211. {
  1212. struct Scsi_Host *host;
  1213. struct lpfc_hba *phba;
  1214. struct lpfc_sli *psli;
  1215. struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
  1216. unsigned long bar0map_len, bar2map_len;
  1217. int error = -ENODEV, retval;
  1218. int i;
  1219. uint16_t iotag;
  1220. if (pci_enable_device(pdev))
  1221. goto out;
  1222. if (pci_request_regions(pdev, LPFC_DRIVER_NAME))
  1223. goto out_disable_device;
  1224. host = scsi_host_alloc(&lpfc_template, sizeof (struct lpfc_hba));
  1225. if (!host)
  1226. goto out_release_regions;
  1227. phba = (struct lpfc_hba*)host->hostdata;
  1228. memset(phba, 0, sizeof (struct lpfc_hba));
  1229. phba->host = host;
  1230. phba->fc_flag |= FC_LOADING;
  1231. phba->pcidev = pdev;
  1232. /* Assign an unused board number */
  1233. if (!idr_pre_get(&lpfc_hba_index, GFP_KERNEL))
  1234. goto out_put_host;
  1235. error = idr_get_new(&lpfc_hba_index, NULL, &phba->brd_no);
  1236. if (error)
  1237. goto out_put_host;
  1238. host->unique_id = phba->brd_no;
  1239. init_MUTEX(&phba->hba_can_block);
  1240. INIT_LIST_HEAD(&phba->ctrspbuflist);
  1241. INIT_LIST_HEAD(&phba->rnidrspbuflist);
  1242. INIT_LIST_HEAD(&phba->freebufList);
  1243. /* Initialize timers used by driver */
  1244. init_timer(&phba->fc_estabtmo);
  1245. phba->fc_estabtmo.function = lpfc_establish_link_tmo;
  1246. phba->fc_estabtmo.data = (unsigned long)phba;
  1247. init_timer(&phba->fc_disctmo);
  1248. phba->fc_disctmo.function = lpfc_disc_timeout;
  1249. phba->fc_disctmo.data = (unsigned long)phba;
  1250. init_timer(&phba->fc_fdmitmo);
  1251. phba->fc_fdmitmo.function = lpfc_fdmi_tmo;
  1252. phba->fc_fdmitmo.data = (unsigned long)phba;
  1253. init_timer(&phba->els_tmofunc);
  1254. phba->els_tmofunc.function = lpfc_els_timeout;
  1255. phba->els_tmofunc.data = (unsigned long)phba;
  1256. psli = &phba->sli;
  1257. init_timer(&psli->mbox_tmo);
  1258. psli->mbox_tmo.function = lpfc_mbox_timeout;
  1259. psli->mbox_tmo.data = (unsigned long)phba;
  1260. init_timer(&phba->fcp_poll_timer);
  1261. phba->fcp_poll_timer.function = lpfc_poll_timeout;
  1262. phba->fcp_poll_timer.data = (unsigned long)phba;
  1263. /*
  1264. * Get all the module params for configuring this host and then
  1265. * establish the host parameters.
  1266. */
  1267. lpfc_get_cfgparam(phba);
  1268. host->max_id = LPFC_MAX_TARGET;
  1269. host->max_lun = phba->cfg_max_luns;
  1270. host->this_id = -1;
  1271. /* Initialize all internally managed lists. */
  1272. INIT_LIST_HEAD(&phba->fc_nlpmap_list);
  1273. INIT_LIST_HEAD(&phba->fc_nlpunmap_list);
  1274. INIT_LIST_HEAD(&phba->fc_unused_list);
  1275. INIT_LIST_HEAD(&phba->fc_plogi_list);
  1276. INIT_LIST_HEAD(&phba->fc_adisc_list);
  1277. INIT_LIST_HEAD(&phba->fc_reglogin_list);
  1278. INIT_LIST_HEAD(&phba->fc_prli_list);
  1279. INIT_LIST_HEAD(&phba->fc_npr_list);
  1280. pci_set_master(pdev);
  1281. retval = pci_set_mwi(pdev);
  1282. if (retval)
  1283. dev_printk(KERN_WARNING, &pdev->dev,
  1284. "Warning: pci_set_mwi returned %d\n", retval);
  1285. if (pci_set_dma_mask(phba->pcidev, DMA_64BIT_MASK) != 0)
  1286. if (pci_set_dma_mask(phba->pcidev, DMA_32BIT_MASK) != 0)
  1287. goto out_idr_remove;
  1288. /*
  1289. * Get the bus address of Bar0 and Bar2 and the number of bytes
  1290. * required by each mapping.
  1291. */
  1292. phba->pci_bar0_map = pci_resource_start(phba->pcidev, 0);
  1293. bar0map_len = pci_resource_len(phba->pcidev, 0);
  1294. phba->pci_bar2_map = pci_resource_start(phba->pcidev, 2);
  1295. bar2map_len = pci_resource_len(phba->pcidev, 2);
  1296. /* Map HBA SLIM and Control Registers to a kernel virtual address. */
  1297. phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
  1298. phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
  1299. /* Allocate memory for SLI-2 structures */
  1300. phba->slim2p = dma_alloc_coherent(&phba->pcidev->dev, SLI2_SLIM_SIZE,
  1301. &phba->slim2p_mapping, GFP_KERNEL);
  1302. if (!phba->slim2p)
  1303. goto out_iounmap;
  1304. memset(phba->slim2p, 0, SLI2_SLIM_SIZE);
  1305. /* Initialize the SLI Layer to run with lpfc HBAs. */
  1306. lpfc_sli_setup(phba);
  1307. lpfc_sli_queue_setup(phba);
  1308. error = lpfc_mem_alloc(phba);
  1309. if (error)
  1310. goto out_free_slim;
  1311. /* Initialize and populate the iocb list per host. */
  1312. INIT_LIST_HEAD(&phba->lpfc_iocb_list);
  1313. for (i = 0; i < LPFC_IOCB_LIST_CNT; i++) {
  1314. iocbq_entry = kmalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
  1315. if (iocbq_entry == NULL) {
  1316. printk(KERN_ERR "%s: only allocated %d iocbs of "
  1317. "expected %d count. Unloading driver.\n",
  1318. __FUNCTION__, i, LPFC_IOCB_LIST_CNT);
  1319. error = -ENOMEM;
  1320. goto out_free_iocbq;
  1321. }
  1322. memset(iocbq_entry, 0, sizeof(struct lpfc_iocbq));
  1323. iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
  1324. if (iotag == 0) {
  1325. kfree (iocbq_entry);
  1326. printk(KERN_ERR "%s: failed to allocate IOTAG. "
  1327. "Unloading driver.\n",
  1328. __FUNCTION__);
  1329. error = -ENOMEM;
  1330. goto out_free_iocbq;
  1331. }
  1332. spin_lock_irq(phba->host->host_lock);
  1333. list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
  1334. phba->total_iocbq_bufs++;
  1335. spin_unlock_irq(phba->host->host_lock);
  1336. }
  1337. /* Initialize HBA structure */
  1338. phba->fc_edtov = FF_DEF_EDTOV;
  1339. phba->fc_ratov = FF_DEF_RATOV;
  1340. phba->fc_altov = FF_DEF_ALTOV;
  1341. phba->fc_arbtov = FF_DEF_ARBTOV;
  1342. INIT_LIST_HEAD(&phba->work_list);
  1343. phba->work_ha_mask = (HA_ERATT|HA_MBATT|HA_LATT);
  1344. phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
  1345. /* Startup the kernel thread for this host adapter. */
  1346. phba->worker_thread = kthread_run(lpfc_do_work, phba,
  1347. "lpfc_worker_%d", phba->brd_no);
  1348. if (IS_ERR(phba->worker_thread)) {
  1349. error = PTR_ERR(phba->worker_thread);
  1350. goto out_free_iocbq;
  1351. }
  1352. /* We can rely on a queue depth attribute only after SLI HBA setup */
  1353. host->can_queue = phba->cfg_hba_queue_depth - 10;
  1354. /* Tell the midlayer we support 16 byte commands */
  1355. host->max_cmd_len = 16;
  1356. /* Initialize the list of scsi buffers used by driver for scsi IO. */
  1357. spin_lock_init(&phba->scsi_buf_list_lock);
  1358. INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list);
  1359. host->transportt = lpfc_transport_template;
  1360. host->hostdata[0] = (unsigned long)phba;
  1361. pci_set_drvdata(pdev, host);
  1362. error = scsi_add_host(host, &pdev->dev);
  1363. if (error)
  1364. goto out_kthread_stop;
  1365. error = lpfc_alloc_sysfs_attr(phba);
  1366. if (error)
  1367. goto out_kthread_stop;
  1368. error = request_irq(phba->pcidev->irq, lpfc_intr_handler, SA_SHIRQ,
  1369. LPFC_DRIVER_NAME, phba);
  1370. if (error) {
  1371. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1372. "%d:0451 Enable interrupt handler failed\n",
  1373. phba->brd_no);
  1374. goto out_free_sysfs_attr;
  1375. }
  1376. phba->MBslimaddr = phba->slim_memmap_p;
  1377. phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
  1378. phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
  1379. phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
  1380. phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
  1381. error = lpfc_sli_hba_setup(phba);
  1382. if (error)
  1383. goto out_free_irq;
  1384. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  1385. spin_lock_irq(phba->host->host_lock);
  1386. lpfc_poll_start_timer(phba);
  1387. spin_unlock_irq(phba->host->host_lock);
  1388. }
  1389. /*
  1390. * set fixed host attributes
  1391. * Must done after lpfc_sli_hba_setup()
  1392. */
  1393. fc_host_node_name(host) = wwn_to_u64(phba->fc_nodename.u.wwn);
  1394. fc_host_port_name(host) = wwn_to_u64(phba->fc_portname.u.wwn);
  1395. fc_host_supported_classes(host) = FC_COS_CLASS3;
  1396. memset(fc_host_supported_fc4s(host), 0,
  1397. sizeof(fc_host_supported_fc4s(host)));
  1398. fc_host_supported_fc4s(host)[2] = 1;
  1399. fc_host_supported_fc4s(host)[7] = 1;
  1400. lpfc_get_hba_sym_node_name(phba, fc_host_symbolic_name(host));
  1401. fc_host_supported_speeds(host) = 0;
  1402. switch (FC_JEDEC_ID(phba->vpd.rev.biuRev)) {
  1403. case VIPER_JEDEC_ID:
  1404. fc_host_supported_speeds(host) |= FC_PORTSPEED_10GBIT;
  1405. break;
  1406. case HELIOS_JEDEC_ID:
  1407. fc_host_supported_speeds(host) |= FC_PORTSPEED_4GBIT;
  1408. /* Fall through */
  1409. case CENTAUR_2G_JEDEC_ID:
  1410. case PEGASUS_JEDEC_ID:
  1411. case THOR_JEDEC_ID:
  1412. fc_host_supported_speeds(host) |= FC_PORTSPEED_2GBIT;
  1413. /* Fall through */
  1414. default:
  1415. fc_host_supported_speeds(host) = FC_PORTSPEED_1GBIT;
  1416. }
  1417. fc_host_maxframe_size(host) =
  1418. ((((uint32_t) phba->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
  1419. (uint32_t) phba->fc_sparam.cmn.bbRcvSizeLsb);
  1420. /* This value is also unchanging */
  1421. memset(fc_host_active_fc4s(host), 0,
  1422. sizeof(fc_host_active_fc4s(host)));
  1423. fc_host_active_fc4s(host)[2] = 1;
  1424. fc_host_active_fc4s(host)[7] = 1;
  1425. spin_lock_irq(phba->host->host_lock);
  1426. phba->fc_flag &= ~FC_LOADING;
  1427. spin_unlock_irq(phba->host->host_lock);
  1428. return 0;
  1429. out_free_irq:
  1430. lpfc_stop_timer(phba);
  1431. phba->work_hba_events = 0;
  1432. free_irq(phba->pcidev->irq, phba);
  1433. out_free_sysfs_attr:
  1434. lpfc_free_sysfs_attr(phba);
  1435. out_kthread_stop:
  1436. kthread_stop(phba->worker_thread);
  1437. out_free_iocbq:
  1438. list_for_each_entry_safe(iocbq_entry, iocbq_next,
  1439. &phba->lpfc_iocb_list, list) {
  1440. spin_lock_irq(phba->host->host_lock);
  1441. kfree(iocbq_entry);
  1442. phba->total_iocbq_bufs--;
  1443. spin_unlock_irq(phba->host->host_lock);
  1444. }
  1445. lpfc_mem_free(phba);
  1446. out_free_slim:
  1447. dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, phba->slim2p,
  1448. phba->slim2p_mapping);
  1449. out_iounmap:
  1450. iounmap(phba->ctrl_regs_memmap_p);
  1451. iounmap(phba->slim_memmap_p);
  1452. out_idr_remove:
  1453. idr_remove(&lpfc_hba_index, phba->brd_no);
  1454. out_put_host:
  1455. scsi_host_put(host);
  1456. out_release_regions:
  1457. pci_release_regions(pdev);
  1458. out_disable_device:
  1459. pci_disable_device(pdev);
  1460. out:
  1461. return error;
  1462. }
  1463. static void __devexit
  1464. lpfc_pci_remove_one(struct pci_dev *pdev)
  1465. {
  1466. struct Scsi_Host *host = pci_get_drvdata(pdev);
  1467. struct lpfc_hba *phba = (struct lpfc_hba *)host->hostdata[0];
  1468. unsigned long iflag;
  1469. lpfc_free_sysfs_attr(phba);
  1470. spin_lock_irqsave(phba->host->host_lock, iflag);
  1471. phba->fc_flag |= FC_UNLOADING;
  1472. spin_unlock_irqrestore(phba->host->host_lock, iflag);
  1473. fc_remove_host(phba->host);
  1474. scsi_remove_host(phba->host);
  1475. kthread_stop(phba->worker_thread);
  1476. /*
  1477. * Bring down the SLI Layer. This step disable all interrupts,
  1478. * clears the rings, discards all mailbox commands, and resets
  1479. * the HBA.
  1480. */
  1481. lpfc_sli_hba_down(phba);
  1482. /* Release the irq reservation */
  1483. free_irq(phba->pcidev->irq, phba);
  1484. lpfc_cleanup(phba, 0);
  1485. lpfc_stop_timer(phba);
  1486. phba->work_hba_events = 0;
  1487. /*
  1488. * Call scsi_free before mem_free since scsi bufs are released to their
  1489. * corresponding pools here.
  1490. */
  1491. lpfc_scsi_free(phba);
  1492. lpfc_mem_free(phba);
  1493. /* Free resources associated with SLI2 interface */
  1494. dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
  1495. phba->slim2p, phba->slim2p_mapping);
  1496. /* unmap adapter SLIM and Control Registers */
  1497. iounmap(phba->ctrl_regs_memmap_p);
  1498. iounmap(phba->slim_memmap_p);
  1499. pci_release_regions(phba->pcidev);
  1500. pci_disable_device(phba->pcidev);
  1501. idr_remove(&lpfc_hba_index, phba->brd_no);
  1502. scsi_host_put(phba->host);
  1503. pci_set_drvdata(pdev, NULL);
  1504. }
  1505. static struct pci_device_id lpfc_id_table[] = {
  1506. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER,
  1507. PCI_ANY_ID, PCI_ANY_ID, },
  1508. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY,
  1509. PCI_ANY_ID, PCI_ANY_ID, },
  1510. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR,
  1511. PCI_ANY_ID, PCI_ANY_ID, },
  1512. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS,
  1513. PCI_ANY_ID, PCI_ANY_ID, },
  1514. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR,
  1515. PCI_ANY_ID, PCI_ANY_ID, },
  1516. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY,
  1517. PCI_ANY_ID, PCI_ANY_ID, },
  1518. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY,
  1519. PCI_ANY_ID, PCI_ANY_ID, },
  1520. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY,
  1521. PCI_ANY_ID, PCI_ANY_ID, },
  1522. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY,
  1523. PCI_ANY_ID, PCI_ANY_ID, },
  1524. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE,
  1525. PCI_ANY_ID, PCI_ANY_ID, },
  1526. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP,
  1527. PCI_ANY_ID, PCI_ANY_ID, },
  1528. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP,
  1529. PCI_ANY_ID, PCI_ANY_ID, },
  1530. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS,
  1531. PCI_ANY_ID, PCI_ANY_ID, },
  1532. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP,
  1533. PCI_ANY_ID, PCI_ANY_ID, },
  1534. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP,
  1535. PCI_ANY_ID, PCI_ANY_ID, },
  1536. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID,
  1537. PCI_ANY_ID, PCI_ANY_ID, },
  1538. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB,
  1539. PCI_ANY_ID, PCI_ANY_ID, },
  1540. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR,
  1541. PCI_ANY_ID, PCI_ANY_ID, },
  1542. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP,
  1543. PCI_ANY_ID, PCI_ANY_ID, },
  1544. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP,
  1545. PCI_ANY_ID, PCI_ANY_ID, },
  1546. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID,
  1547. PCI_ANY_ID, PCI_ANY_ID, },
  1548. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB,
  1549. PCI_ANY_ID, PCI_ANY_ID, },
  1550. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY,
  1551. PCI_ANY_ID, PCI_ANY_ID, },
  1552. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101,
  1553. PCI_ANY_ID, PCI_ANY_ID, },
  1554. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S,
  1555. PCI_ANY_ID, PCI_ANY_ID, },
  1556. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S,
  1557. PCI_ANY_ID, PCI_ANY_ID, },
  1558. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S,
  1559. PCI_ANY_ID, PCI_ANY_ID, },
  1560. { 0 }
  1561. };
  1562. MODULE_DEVICE_TABLE(pci, lpfc_id_table);
  1563. static struct pci_driver lpfc_driver = {
  1564. .name = LPFC_DRIVER_NAME,
  1565. .id_table = lpfc_id_table,
  1566. .probe = lpfc_pci_probe_one,
  1567. .remove = __devexit_p(lpfc_pci_remove_one),
  1568. };
  1569. static int __init
  1570. lpfc_init(void)
  1571. {
  1572. int error = 0;
  1573. printk(LPFC_MODULE_DESC "\n");
  1574. printk(LPFC_COPYRIGHT "\n");
  1575. lpfc_transport_template =
  1576. fc_attach_transport(&lpfc_transport_functions);
  1577. if (!lpfc_transport_template)
  1578. return -ENOMEM;
  1579. error = pci_register_driver(&lpfc_driver);
  1580. if (error)
  1581. fc_release_transport(lpfc_transport_template);
  1582. return error;
  1583. }
  1584. static void __exit
  1585. lpfc_exit(void)
  1586. {
  1587. pci_unregister_driver(&lpfc_driver);
  1588. fc_release_transport(lpfc_transport_template);
  1589. }
  1590. module_init(lpfc_init);
  1591. module_exit(lpfc_exit);
  1592. MODULE_LICENSE("GPL");
  1593. MODULE_DESCRIPTION(LPFC_MODULE_DESC);
  1594. MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com");
  1595. MODULE_VERSION("0:" LPFC_DRIVER_VERSION);