lpfc_init.c 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802
  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. writel(status, phba->HCregaddr);
  333. readl(phba->HCregaddr); /* flush */
  334. spin_unlock_irq(phba->host->host_lock);
  335. /*
  336. * Setup the ring 0 (els) timeout handler
  337. */
  338. timeout = phba->fc_ratov << 1;
  339. phba->els_tmofunc.expires = jiffies + HZ * timeout;
  340. add_timer(&phba->els_tmofunc);
  341. lpfc_init_link(phba, pmb, phba->cfg_topology, phba->cfg_link_speed);
  342. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  343. if (lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT) != MBX_SUCCESS) {
  344. lpfc_printf_log(phba,
  345. KERN_ERR,
  346. LOG_INIT,
  347. "%d:0454 Adapter failed to init, mbxCmd x%x "
  348. "INIT_LINK, mbxStatus x%x\n",
  349. phba->brd_no,
  350. mb->mbxCommand, mb->mbxStatus);
  351. /* Clear all interrupt enable conditions */
  352. writel(0, phba->HCregaddr);
  353. readl(phba->HCregaddr); /* flush */
  354. /* Clear all pending interrupts */
  355. writel(0xffffffff, phba->HAregaddr);
  356. readl(phba->HAregaddr); /* flush */
  357. phba->hba_state = LPFC_HBA_ERROR;
  358. mempool_free(pmb, phba->mbox_mem_pool);
  359. return -EIO;
  360. }
  361. /* MBOX buffer will be freed in mbox compl */
  362. i = 0;
  363. while ((phba->hba_state != LPFC_HBA_READY) ||
  364. (phba->num_disc_nodes) || (phba->fc_prli_sent) ||
  365. ((phba->fc_map_cnt == 0) && (i<2)) ||
  366. (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE)) {
  367. /* Check every second for 30 retries. */
  368. i++;
  369. if (i > 30) {
  370. break;
  371. }
  372. if ((i >= 15) && (phba->hba_state <= LPFC_LINK_DOWN)) {
  373. /* The link is down. Set linkdown timeout */
  374. break;
  375. }
  376. /* Delay for 1 second to give discovery time to complete. */
  377. msleep(1000);
  378. }
  379. /* Since num_disc_nodes keys off of PLOGI, delay a bit to let
  380. * any potential PRLIs to flush thru the SLI sub-system.
  381. */
  382. msleep(50);
  383. return (0);
  384. }
  385. /************************************************************************/
  386. /* */
  387. /* lpfc_hba_down_prep */
  388. /* This routine will do LPFC uninitialization before the */
  389. /* HBA is reset when bringing down the SLI Layer. This will be */
  390. /* initialized as a SLI layer callback routine. */
  391. /* This routine returns 0 on success. Any other return value */
  392. /* indicates an error. */
  393. /* */
  394. /************************************************************************/
  395. int
  396. lpfc_hba_down_prep(struct lpfc_hba * phba)
  397. {
  398. /* Disable interrupts */
  399. writel(0, phba->HCregaddr);
  400. readl(phba->HCregaddr); /* flush */
  401. /* Cleanup potential discovery resources */
  402. lpfc_els_flush_rscn(phba);
  403. lpfc_els_flush_cmd(phba);
  404. lpfc_disc_flush_list(phba);
  405. return (0);
  406. }
  407. /************************************************************************/
  408. /* */
  409. /* lpfc_handle_eratt */
  410. /* This routine will handle processing a Host Attention */
  411. /* Error Status event. This will be initialized */
  412. /* as a SLI layer callback routine. */
  413. /* */
  414. /************************************************************************/
  415. void
  416. lpfc_handle_eratt(struct lpfc_hba * phba)
  417. {
  418. struct lpfc_sli *psli = &phba->sli;
  419. struct lpfc_sli_ring *pring;
  420. /*
  421. * If a reset is sent to the HBA restore PCI configuration registers.
  422. */
  423. if ( phba->hba_state == LPFC_INIT_START ) {
  424. mdelay(1);
  425. readl(phba->HCregaddr); /* flush */
  426. writel(0, phba->HCregaddr);
  427. readl(phba->HCregaddr); /* flush */
  428. /* Restore PCI cmd register */
  429. pci_write_config_word(phba->pcidev,
  430. PCI_COMMAND, phba->pci_cfg_value);
  431. }
  432. if (phba->work_hs & HS_FFER6) {
  433. /* Re-establishing Link */
  434. lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
  435. "%d:1301 Re-establishing Link "
  436. "Data: x%x x%x x%x\n",
  437. phba->brd_no, phba->work_hs,
  438. phba->work_status[0], phba->work_status[1]);
  439. spin_lock_irq(phba->host->host_lock);
  440. phba->fc_flag |= FC_ESTABLISH_LINK;
  441. spin_unlock_irq(phba->host->host_lock);
  442. /*
  443. * Firmware stops when it triggled erratt with HS_FFER6.
  444. * That could cause the I/Os dropped by the firmware.
  445. * Error iocb (I/O) on txcmplq and let the SCSI layer
  446. * retry it after re-establishing link.
  447. */
  448. pring = &psli->ring[psli->fcp_ring];
  449. lpfc_sli_abort_iocb_ring(phba, pring);
  450. /*
  451. * There was a firmware error. Take the hba offline and then
  452. * attempt to restart it.
  453. */
  454. lpfc_offline(phba);
  455. if (lpfc_online(phba) == 0) { /* Initialize the HBA */
  456. mod_timer(&phba->fc_estabtmo, jiffies + HZ * 60);
  457. return;
  458. }
  459. } else {
  460. /* The if clause above forces this code path when the status
  461. * failure is a value other than FFER6. Do not call the offline
  462. * twice. This is the adapter hardware error path.
  463. */
  464. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  465. "%d:0457 Adapter Hardware Error "
  466. "Data: x%x x%x x%x\n",
  467. phba->brd_no, phba->work_hs,
  468. phba->work_status[0], phba->work_status[1]);
  469. lpfc_offline(phba);
  470. }
  471. }
  472. /************************************************************************/
  473. /* */
  474. /* lpfc_handle_latt */
  475. /* This routine will handle processing a Host Attention */
  476. /* Link Status event. This will be initialized */
  477. /* as a SLI layer callback routine. */
  478. /* */
  479. /************************************************************************/
  480. void
  481. lpfc_handle_latt(struct lpfc_hba * phba)
  482. {
  483. struct lpfc_sli *psli = &phba->sli;
  484. LPFC_MBOXQ_t *pmb;
  485. volatile uint32_t control;
  486. struct lpfc_dmabuf *mp;
  487. int rc = -ENOMEM;
  488. pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  489. if (!pmb)
  490. goto lpfc_handle_latt_err_exit;
  491. mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  492. if (!mp)
  493. goto lpfc_handle_latt_free_pmb;
  494. mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
  495. if (!mp->virt)
  496. goto lpfc_handle_latt_free_mp;
  497. rc = -EIO;
  498. /* Cleanup any outstanding ELS commands */
  499. lpfc_els_flush_cmd(phba);
  500. psli->slistat.link_event++;
  501. lpfc_read_la(phba, pmb, mp);
  502. pmb->mbox_cmpl = lpfc_mbx_cmpl_read_la;
  503. rc = lpfc_sli_issue_mbox (phba, pmb, (MBX_NOWAIT | MBX_STOP_IOCB));
  504. if (rc == MBX_NOT_FINISHED)
  505. goto lpfc_handle_latt_free_mp;
  506. /* Clear Link Attention in HA REG */
  507. spin_lock_irq(phba->host->host_lock);
  508. writel(HA_LATT, phba->HAregaddr);
  509. readl(phba->HAregaddr); /* flush */
  510. spin_unlock_irq(phba->host->host_lock);
  511. return;
  512. lpfc_handle_latt_free_mp:
  513. kfree(mp);
  514. lpfc_handle_latt_free_pmb:
  515. kfree(pmb);
  516. lpfc_handle_latt_err_exit:
  517. /* Enable Link attention interrupts */
  518. spin_lock_irq(phba->host->host_lock);
  519. psli->sli_flag |= LPFC_PROCESS_LA;
  520. control = readl(phba->HCregaddr);
  521. control |= HC_LAINT_ENA;
  522. writel(control, phba->HCregaddr);
  523. readl(phba->HCregaddr); /* flush */
  524. /* Clear Link Attention in HA REG */
  525. writel(HA_LATT, phba->HAregaddr);
  526. readl(phba->HAregaddr); /* flush */
  527. spin_unlock_irq(phba->host->host_lock);
  528. lpfc_linkdown(phba);
  529. phba->hba_state = LPFC_HBA_ERROR;
  530. /* The other case is an error from issue_mbox */
  531. if (rc == -ENOMEM)
  532. lpfc_printf_log(phba,
  533. KERN_WARNING,
  534. LOG_MBOX,
  535. "%d:0300 READ_LA: no buffers\n",
  536. phba->brd_no);
  537. return;
  538. }
  539. /************************************************************************/
  540. /* */
  541. /* lpfc_parse_vpd */
  542. /* This routine will parse the VPD data */
  543. /* */
  544. /************************************************************************/
  545. static int
  546. lpfc_parse_vpd(struct lpfc_hba * phba, uint8_t * vpd)
  547. {
  548. uint8_t lenlo, lenhi;
  549. uint32_t Length;
  550. int i, j;
  551. int finished = 0;
  552. int index = 0;
  553. if (!vpd)
  554. return 0;
  555. /* Vital Product */
  556. lpfc_printf_log(phba,
  557. KERN_INFO,
  558. LOG_INIT,
  559. "%d:0455 Vital Product Data: x%x x%x x%x x%x\n",
  560. phba->brd_no,
  561. (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
  562. (uint32_t) vpd[3]);
  563. do {
  564. switch (vpd[index]) {
  565. case 0x82:
  566. index += 1;
  567. lenlo = vpd[index];
  568. index += 1;
  569. lenhi = vpd[index];
  570. index += 1;
  571. i = ((((unsigned short)lenhi) << 8) + lenlo);
  572. index += i;
  573. break;
  574. case 0x90:
  575. index += 1;
  576. lenlo = vpd[index];
  577. index += 1;
  578. lenhi = vpd[index];
  579. index += 1;
  580. Length = ((((unsigned short)lenhi) << 8) + lenlo);
  581. while (Length > 0) {
  582. /* Look for Serial Number */
  583. if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) {
  584. index += 2;
  585. i = vpd[index];
  586. index += 1;
  587. j = 0;
  588. Length -= (3+i);
  589. while(i--) {
  590. phba->SerialNumber[j++] = vpd[index++];
  591. if (j == 31)
  592. break;
  593. }
  594. phba->SerialNumber[j] = 0;
  595. continue;
  596. }
  597. else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) {
  598. phba->vpd_flag |= VPD_MODEL_DESC;
  599. index += 2;
  600. i = vpd[index];
  601. index += 1;
  602. j = 0;
  603. Length -= (3+i);
  604. while(i--) {
  605. phba->ModelDesc[j++] = vpd[index++];
  606. if (j == 255)
  607. break;
  608. }
  609. phba->ModelDesc[j] = 0;
  610. continue;
  611. }
  612. else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) {
  613. phba->vpd_flag |= VPD_MODEL_NAME;
  614. index += 2;
  615. i = vpd[index];
  616. index += 1;
  617. j = 0;
  618. Length -= (3+i);
  619. while(i--) {
  620. phba->ModelName[j++] = vpd[index++];
  621. if (j == 79)
  622. break;
  623. }
  624. phba->ModelName[j] = 0;
  625. continue;
  626. }
  627. else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) {
  628. phba->vpd_flag |= VPD_PROGRAM_TYPE;
  629. index += 2;
  630. i = vpd[index];
  631. index += 1;
  632. j = 0;
  633. Length -= (3+i);
  634. while(i--) {
  635. phba->ProgramType[j++] = vpd[index++];
  636. if (j == 255)
  637. break;
  638. }
  639. phba->ProgramType[j] = 0;
  640. continue;
  641. }
  642. else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) {
  643. phba->vpd_flag |= VPD_PORT;
  644. index += 2;
  645. i = vpd[index];
  646. index += 1;
  647. j = 0;
  648. Length -= (3+i);
  649. while(i--) {
  650. phba->Port[j++] = vpd[index++];
  651. if (j == 19)
  652. break;
  653. }
  654. phba->Port[j] = 0;
  655. continue;
  656. }
  657. else {
  658. index += 2;
  659. i = vpd[index];
  660. index += 1;
  661. index += i;
  662. Length -= (3 + i);
  663. }
  664. }
  665. finished = 0;
  666. break;
  667. case 0x78:
  668. finished = 1;
  669. break;
  670. default:
  671. index ++;
  672. break;
  673. }
  674. } while (!finished && (index < 108));
  675. return(1);
  676. }
  677. static void
  678. lpfc_get_hba_model_desc(struct lpfc_hba * phba, uint8_t * mdp, uint8_t * descp)
  679. {
  680. lpfc_vpd_t *vp;
  681. uint16_t dev_id;
  682. uint16_t dev_subid;
  683. uint8_t hdrtype;
  684. char *model_str = "";
  685. vp = &phba->vpd;
  686. pci_read_config_word(phba->pcidev, PCI_DEVICE_ID, &dev_id);
  687. pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
  688. switch (dev_id) {
  689. case PCI_DEVICE_ID_FIREFLY:
  690. model_str = "LP6000 1Gb PCI";
  691. break;
  692. case PCI_DEVICE_ID_SUPERFLY:
  693. if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
  694. model_str = "LP7000 1Gb PCI";
  695. else
  696. model_str = "LP7000E 1Gb PCI";
  697. break;
  698. case PCI_DEVICE_ID_DRAGONFLY:
  699. model_str = "LP8000 1Gb PCI";
  700. break;
  701. case PCI_DEVICE_ID_CENTAUR:
  702. if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
  703. model_str = "LP9002 2Gb PCI";
  704. else
  705. model_str = "LP9000 1Gb PCI";
  706. break;
  707. case PCI_DEVICE_ID_RFLY:
  708. model_str = "LP952 2Gb PCI";
  709. break;
  710. case PCI_DEVICE_ID_PEGASUS:
  711. model_str = "LP9802 2Gb PCI-X";
  712. break;
  713. case PCI_DEVICE_ID_THOR:
  714. if (hdrtype == 0x80)
  715. model_str = "LP10000DC 2Gb 2-port PCI-X";
  716. else
  717. model_str = "LP10000 2Gb PCI-X";
  718. break;
  719. case PCI_DEVICE_ID_VIPER:
  720. model_str = "LPX1000 10Gb PCI-X";
  721. break;
  722. case PCI_DEVICE_ID_PFLY:
  723. model_str = "LP982 2Gb PCI-X";
  724. break;
  725. case PCI_DEVICE_ID_TFLY:
  726. if (hdrtype == 0x80)
  727. model_str = "LP1050DC 2Gb 2-port PCI-X";
  728. else
  729. model_str = "LP1050 2Gb PCI-X";
  730. break;
  731. case PCI_DEVICE_ID_HELIOS:
  732. if (hdrtype == 0x80)
  733. model_str = "LP11002 4Gb 2-port PCI-X2";
  734. else
  735. model_str = "LP11000 4Gb PCI-X2";
  736. break;
  737. case PCI_DEVICE_ID_HELIOS_SCSP:
  738. model_str = "LP11000-SP 4Gb PCI-X2";
  739. break;
  740. case PCI_DEVICE_ID_HELIOS_DCSP:
  741. model_str = "LP11002-SP 4Gb 2-port PCI-X2";
  742. break;
  743. case PCI_DEVICE_ID_NEPTUNE:
  744. if (hdrtype == 0x80)
  745. model_str = "LPe1002 4Gb 2-port";
  746. else
  747. model_str = "LPe1000 4Gb PCIe";
  748. break;
  749. case PCI_DEVICE_ID_NEPTUNE_SCSP:
  750. model_str = "LPe1000-SP 4Gb PCIe";
  751. break;
  752. case PCI_DEVICE_ID_NEPTUNE_DCSP:
  753. model_str = "LPe1002-SP 4Gb 2-port PCIe";
  754. break;
  755. case PCI_DEVICE_ID_BMID:
  756. model_str = "LP1150 4Gb PCI-X2";
  757. break;
  758. case PCI_DEVICE_ID_BSMB:
  759. model_str = "LP111 4Gb PCI-X2";
  760. break;
  761. case PCI_DEVICE_ID_ZEPHYR:
  762. if (hdrtype == 0x80)
  763. model_str = "LPe11002 4Gb 2-port PCIe";
  764. else
  765. model_str = "LPe11000 4Gb PCIe";
  766. break;
  767. case PCI_DEVICE_ID_ZEPHYR_SCSP:
  768. model_str = "LPe11000-SP 4Gb PCIe";
  769. break;
  770. case PCI_DEVICE_ID_ZEPHYR_DCSP:
  771. model_str = "LPe11002-SP 4Gb 2-port PCIe";
  772. break;
  773. case PCI_DEVICE_ID_ZMID:
  774. model_str = "LPe1150 4Gb PCIe";
  775. break;
  776. case PCI_DEVICE_ID_ZSMB:
  777. model_str = "LPe111 4Gb PCIe";
  778. break;
  779. case PCI_DEVICE_ID_LP101:
  780. model_str = "LP101 2Gb PCI-X";
  781. break;
  782. case PCI_DEVICE_ID_LP10000S:
  783. model_str = "LP10000-S 2Gb PCI";
  784. break;
  785. case PCI_DEVICE_ID_LP11000S:
  786. case PCI_DEVICE_ID_LPE11000S:
  787. pci_read_config_word(phba->pcidev, PCI_SUBSYSTEM_ID,
  788. &dev_subid);
  789. switch (dev_subid) {
  790. case PCI_SUBSYSTEM_ID_LP11000S:
  791. model_str = "LP11002-S 4Gb PCI-X2";
  792. break;
  793. case PCI_SUBSYSTEM_ID_LP11002S:
  794. model_str = "LP11000-S 4Gb 2-port PCI-X2";
  795. break;
  796. case PCI_SUBSYSTEM_ID_LPE11000S:
  797. model_str = "LPe11002-S 4Gb PCIe";
  798. break;
  799. case PCI_SUBSYSTEM_ID_LPE11002S:
  800. model_str = "LPe11002-S 4Gb 2-port PCIe";
  801. break;
  802. case PCI_SUBSYSTEM_ID_LPE11010S:
  803. model_str = "LPe11010-S 4Gb 10-port PCIe";
  804. break;
  805. default:
  806. break;
  807. }
  808. break;
  809. default:
  810. break;
  811. }
  812. if (mdp)
  813. sscanf(model_str, "%s", mdp);
  814. if (descp)
  815. sprintf(descp, "Emulex %s Fibre Channel Adapter", model_str);
  816. }
  817. /**************************************************/
  818. /* lpfc_post_buffer */
  819. /* */
  820. /* This routine will post count buffers to the */
  821. /* ring with the QUE_RING_BUF_CN command. This */
  822. /* allows 3 buffers / command to be posted. */
  823. /* Returns the number of buffers NOT posted. */
  824. /**************************************************/
  825. int
  826. lpfc_post_buffer(struct lpfc_hba * phba, struct lpfc_sli_ring * pring, int cnt,
  827. int type)
  828. {
  829. IOCB_t *icmd;
  830. struct lpfc_iocbq *iocb;
  831. struct lpfc_dmabuf *mp1, *mp2;
  832. cnt += pring->missbufcnt;
  833. /* While there are buffers to post */
  834. while (cnt > 0) {
  835. /* Allocate buffer for command iocb */
  836. spin_lock_irq(phba->host->host_lock);
  837. iocb = lpfc_sli_get_iocbq(phba);
  838. spin_unlock_irq(phba->host->host_lock);
  839. if (iocb == NULL) {
  840. pring->missbufcnt = cnt;
  841. return cnt;
  842. }
  843. icmd = &iocb->iocb;
  844. /* 2 buffers can be posted per command */
  845. /* Allocate buffer to post */
  846. mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
  847. if (mp1)
  848. mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
  849. &mp1->phys);
  850. if (mp1 == 0 || mp1->virt == 0) {
  851. kfree(mp1);
  852. spin_lock_irq(phba->host->host_lock);
  853. lpfc_sli_release_iocbq(phba, iocb);
  854. spin_unlock_irq(phba->host->host_lock);
  855. pring->missbufcnt = cnt;
  856. return cnt;
  857. }
  858. INIT_LIST_HEAD(&mp1->list);
  859. /* Allocate buffer to post */
  860. if (cnt > 1) {
  861. mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
  862. if (mp2)
  863. mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
  864. &mp2->phys);
  865. if (mp2 == 0 || mp2->virt == 0) {
  866. kfree(mp2);
  867. lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
  868. kfree(mp1);
  869. spin_lock_irq(phba->host->host_lock);
  870. lpfc_sli_release_iocbq(phba, iocb);
  871. spin_unlock_irq(phba->host->host_lock);
  872. pring->missbufcnt = cnt;
  873. return cnt;
  874. }
  875. INIT_LIST_HEAD(&mp2->list);
  876. } else {
  877. mp2 = NULL;
  878. }
  879. icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
  880. icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
  881. icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
  882. icmd->ulpBdeCount = 1;
  883. cnt--;
  884. if (mp2) {
  885. icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
  886. icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
  887. icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
  888. cnt--;
  889. icmd->ulpBdeCount = 2;
  890. }
  891. icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
  892. icmd->ulpLe = 1;
  893. spin_lock_irq(phba->host->host_lock);
  894. if (lpfc_sli_issue_iocb(phba, pring, iocb, 0) == IOCB_ERROR) {
  895. lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
  896. kfree(mp1);
  897. cnt++;
  898. if (mp2) {
  899. lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
  900. kfree(mp2);
  901. cnt++;
  902. }
  903. lpfc_sli_release_iocbq(phba, iocb);
  904. pring->missbufcnt = cnt;
  905. spin_unlock_irq(phba->host->host_lock);
  906. return cnt;
  907. }
  908. spin_unlock_irq(phba->host->host_lock);
  909. lpfc_sli_ringpostbuf_put(phba, pring, mp1);
  910. if (mp2) {
  911. lpfc_sli_ringpostbuf_put(phba, pring, mp2);
  912. }
  913. }
  914. pring->missbufcnt = 0;
  915. return 0;
  916. }
  917. /************************************************************************/
  918. /* */
  919. /* lpfc_post_rcv_buf */
  920. /* This routine post initial rcv buffers to the configured rings */
  921. /* */
  922. /************************************************************************/
  923. static int
  924. lpfc_post_rcv_buf(struct lpfc_hba * phba)
  925. {
  926. struct lpfc_sli *psli = &phba->sli;
  927. /* Ring 0, ELS / CT buffers */
  928. lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0, 1);
  929. /* Ring 2 - FCP no buffers needed */
  930. return 0;
  931. }
  932. #define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
  933. /************************************************************************/
  934. /* */
  935. /* lpfc_sha_init */
  936. /* */
  937. /************************************************************************/
  938. static void
  939. lpfc_sha_init(uint32_t * HashResultPointer)
  940. {
  941. HashResultPointer[0] = 0x67452301;
  942. HashResultPointer[1] = 0xEFCDAB89;
  943. HashResultPointer[2] = 0x98BADCFE;
  944. HashResultPointer[3] = 0x10325476;
  945. HashResultPointer[4] = 0xC3D2E1F0;
  946. }
  947. /************************************************************************/
  948. /* */
  949. /* lpfc_sha_iterate */
  950. /* */
  951. /************************************************************************/
  952. static void
  953. lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
  954. {
  955. int t;
  956. uint32_t TEMP;
  957. uint32_t A, B, C, D, E;
  958. t = 16;
  959. do {
  960. HashWorkingPointer[t] =
  961. S(1,
  962. HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
  963. 8] ^
  964. HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
  965. } while (++t <= 79);
  966. t = 0;
  967. A = HashResultPointer[0];
  968. B = HashResultPointer[1];
  969. C = HashResultPointer[2];
  970. D = HashResultPointer[3];
  971. E = HashResultPointer[4];
  972. do {
  973. if (t < 20) {
  974. TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
  975. } else if (t < 40) {
  976. TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
  977. } else if (t < 60) {
  978. TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
  979. } else {
  980. TEMP = (B ^ C ^ D) + 0xCA62C1D6;
  981. }
  982. TEMP += S(5, A) + E + HashWorkingPointer[t];
  983. E = D;
  984. D = C;
  985. C = S(30, B);
  986. B = A;
  987. A = TEMP;
  988. } while (++t <= 79);
  989. HashResultPointer[0] += A;
  990. HashResultPointer[1] += B;
  991. HashResultPointer[2] += C;
  992. HashResultPointer[3] += D;
  993. HashResultPointer[4] += E;
  994. }
  995. /************************************************************************/
  996. /* */
  997. /* lpfc_challenge_key */
  998. /* */
  999. /************************************************************************/
  1000. static void
  1001. lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
  1002. {
  1003. *HashWorking = (*RandomChallenge ^ *HashWorking);
  1004. }
  1005. /************************************************************************/
  1006. /* */
  1007. /* lpfc_hba_init */
  1008. /* */
  1009. /************************************************************************/
  1010. void
  1011. lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
  1012. {
  1013. int t;
  1014. uint32_t *HashWorking;
  1015. uint32_t *pwwnn = phba->wwnn;
  1016. HashWorking = kmalloc(80 * sizeof(uint32_t), GFP_KERNEL);
  1017. if (!HashWorking)
  1018. return;
  1019. memset(HashWorking, 0, (80 * sizeof(uint32_t)));
  1020. HashWorking[0] = HashWorking[78] = *pwwnn++;
  1021. HashWorking[1] = HashWorking[79] = *pwwnn;
  1022. for (t = 0; t < 7; t++)
  1023. lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
  1024. lpfc_sha_init(hbainit);
  1025. lpfc_sha_iterate(hbainit, HashWorking);
  1026. kfree(HashWorking);
  1027. }
  1028. static void
  1029. lpfc_cleanup(struct lpfc_hba * phba, uint32_t save_bind)
  1030. {
  1031. struct lpfc_nodelist *ndlp, *next_ndlp;
  1032. /* clean up phba - lpfc specific */
  1033. lpfc_can_disctmo(phba);
  1034. list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_nlpunmap_list,
  1035. nlp_listp) {
  1036. lpfc_nlp_remove(phba, ndlp);
  1037. }
  1038. list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_nlpmap_list,
  1039. nlp_listp) {
  1040. lpfc_nlp_remove(phba, ndlp);
  1041. }
  1042. list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_unused_list,
  1043. nlp_listp) {
  1044. lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
  1045. }
  1046. list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_plogi_list,
  1047. nlp_listp) {
  1048. lpfc_nlp_remove(phba, ndlp);
  1049. }
  1050. list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_adisc_list,
  1051. nlp_listp) {
  1052. lpfc_nlp_remove(phba, ndlp);
  1053. }
  1054. list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_reglogin_list,
  1055. nlp_listp) {
  1056. lpfc_nlp_remove(phba, ndlp);
  1057. }
  1058. list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_prli_list,
  1059. nlp_listp) {
  1060. lpfc_nlp_remove(phba, ndlp);
  1061. }
  1062. list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
  1063. nlp_listp) {
  1064. lpfc_nlp_remove(phba, ndlp);
  1065. }
  1066. INIT_LIST_HEAD(&phba->fc_nlpmap_list);
  1067. INIT_LIST_HEAD(&phba->fc_nlpunmap_list);
  1068. INIT_LIST_HEAD(&phba->fc_unused_list);
  1069. INIT_LIST_HEAD(&phba->fc_plogi_list);
  1070. INIT_LIST_HEAD(&phba->fc_adisc_list);
  1071. INIT_LIST_HEAD(&phba->fc_reglogin_list);
  1072. INIT_LIST_HEAD(&phba->fc_prli_list);
  1073. INIT_LIST_HEAD(&phba->fc_npr_list);
  1074. phba->fc_map_cnt = 0;
  1075. phba->fc_unmap_cnt = 0;
  1076. phba->fc_plogi_cnt = 0;
  1077. phba->fc_adisc_cnt = 0;
  1078. phba->fc_reglogin_cnt = 0;
  1079. phba->fc_prli_cnt = 0;
  1080. phba->fc_npr_cnt = 0;
  1081. phba->fc_unused_cnt= 0;
  1082. return;
  1083. }
  1084. static void
  1085. lpfc_establish_link_tmo(unsigned long ptr)
  1086. {
  1087. struct lpfc_hba *phba = (struct lpfc_hba *)ptr;
  1088. unsigned long iflag;
  1089. /* Re-establishing Link, timer expired */
  1090. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  1091. "%d:1300 Re-establishing Link, timer expired "
  1092. "Data: x%x x%x\n",
  1093. phba->brd_no, phba->fc_flag, phba->hba_state);
  1094. spin_lock_irqsave(phba->host->host_lock, iflag);
  1095. phba->fc_flag &= ~FC_ESTABLISH_LINK;
  1096. spin_unlock_irqrestore(phba->host->host_lock, iflag);
  1097. }
  1098. static int
  1099. lpfc_stop_timer(struct lpfc_hba * phba)
  1100. {
  1101. struct lpfc_sli *psli = &phba->sli;
  1102. /* Instead of a timer, this has been converted to a
  1103. * deferred procedding list.
  1104. */
  1105. while (!list_empty(&phba->freebufList)) {
  1106. struct lpfc_dmabuf *mp = NULL;
  1107. list_remove_head((&phba->freebufList), mp,
  1108. struct lpfc_dmabuf, list);
  1109. if (mp) {
  1110. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1111. kfree(mp);
  1112. }
  1113. }
  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. /*
  1261. * Get all the module params for configuring this host and then
  1262. * establish the host parameters.
  1263. */
  1264. lpfc_get_cfgparam(phba);
  1265. host->max_id = LPFC_MAX_TARGET;
  1266. host->max_lun = phba->cfg_max_luns;
  1267. host->this_id = -1;
  1268. /* Initialize all internally managed lists. */
  1269. INIT_LIST_HEAD(&phba->fc_nlpmap_list);
  1270. INIT_LIST_HEAD(&phba->fc_nlpunmap_list);
  1271. INIT_LIST_HEAD(&phba->fc_unused_list);
  1272. INIT_LIST_HEAD(&phba->fc_plogi_list);
  1273. INIT_LIST_HEAD(&phba->fc_adisc_list);
  1274. INIT_LIST_HEAD(&phba->fc_reglogin_list);
  1275. INIT_LIST_HEAD(&phba->fc_prli_list);
  1276. INIT_LIST_HEAD(&phba->fc_npr_list);
  1277. pci_set_master(pdev);
  1278. retval = pci_set_mwi(pdev);
  1279. if (retval)
  1280. dev_printk(KERN_WARNING, &pdev->dev,
  1281. "Warning: pci_set_mwi returned %d\n", retval);
  1282. if (pci_set_dma_mask(phba->pcidev, DMA_64BIT_MASK) != 0)
  1283. if (pci_set_dma_mask(phba->pcidev, DMA_32BIT_MASK) != 0)
  1284. goto out_idr_remove;
  1285. /*
  1286. * Get the bus address of Bar0 and Bar2 and the number of bytes
  1287. * required by each mapping.
  1288. */
  1289. phba->pci_bar0_map = pci_resource_start(phba->pcidev, 0);
  1290. bar0map_len = pci_resource_len(phba->pcidev, 0);
  1291. phba->pci_bar2_map = pci_resource_start(phba->pcidev, 2);
  1292. bar2map_len = pci_resource_len(phba->pcidev, 2);
  1293. /* Map HBA SLIM and Control Registers to a kernel virtual address. */
  1294. phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
  1295. phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
  1296. /* Allocate memory for SLI-2 structures */
  1297. phba->slim2p = dma_alloc_coherent(&phba->pcidev->dev, SLI2_SLIM_SIZE,
  1298. &phba->slim2p_mapping, GFP_KERNEL);
  1299. if (!phba->slim2p)
  1300. goto out_iounmap;
  1301. memset(phba->slim2p, 0, SLI2_SLIM_SIZE);
  1302. /* Initialize the SLI Layer to run with lpfc HBAs. */
  1303. lpfc_sli_setup(phba);
  1304. lpfc_sli_queue_setup(phba);
  1305. error = lpfc_mem_alloc(phba);
  1306. if (error)
  1307. goto out_free_slim;
  1308. /* Initialize and populate the iocb list per host. */
  1309. INIT_LIST_HEAD(&phba->lpfc_iocb_list);
  1310. for (i = 0; i < LPFC_IOCB_LIST_CNT; i++) {
  1311. iocbq_entry = kmalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
  1312. if (iocbq_entry == NULL) {
  1313. printk(KERN_ERR "%s: only allocated %d iocbs of "
  1314. "expected %d count. Unloading driver.\n",
  1315. __FUNCTION__, i, LPFC_IOCB_LIST_CNT);
  1316. error = -ENOMEM;
  1317. goto out_free_iocbq;
  1318. }
  1319. memset(iocbq_entry, 0, sizeof(struct lpfc_iocbq));
  1320. iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
  1321. if (iotag == 0) {
  1322. kfree (iocbq_entry);
  1323. printk(KERN_ERR "%s: failed to allocate IOTAG. "
  1324. "Unloading driver.\n",
  1325. __FUNCTION__);
  1326. error = -ENOMEM;
  1327. goto out_free_iocbq;
  1328. }
  1329. spin_lock_irq(phba->host->host_lock);
  1330. list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
  1331. phba->total_iocbq_bufs++;
  1332. spin_unlock_irq(phba->host->host_lock);
  1333. }
  1334. /* Initialize HBA structure */
  1335. phba->fc_edtov = FF_DEF_EDTOV;
  1336. phba->fc_ratov = FF_DEF_RATOV;
  1337. phba->fc_altov = FF_DEF_ALTOV;
  1338. phba->fc_arbtov = FF_DEF_ARBTOV;
  1339. INIT_LIST_HEAD(&phba->work_list);
  1340. phba->work_ha_mask = (HA_ERATT|HA_MBATT|HA_LATT);
  1341. phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
  1342. /* Startup the kernel thread for this host adapter. */
  1343. phba->worker_thread = kthread_run(lpfc_do_work, phba,
  1344. "lpfc_worker_%d", phba->brd_no);
  1345. if (IS_ERR(phba->worker_thread)) {
  1346. error = PTR_ERR(phba->worker_thread);
  1347. goto out_free_iocbq;
  1348. }
  1349. /* We can rely on a queue depth attribute only after SLI HBA setup */
  1350. host->can_queue = phba->cfg_hba_queue_depth - 10;
  1351. /* Tell the midlayer we support 16 byte commands */
  1352. host->max_cmd_len = 16;
  1353. /* Initialize the list of scsi buffers used by driver for scsi IO. */
  1354. INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list);
  1355. host->transportt = lpfc_transport_template;
  1356. host->hostdata[0] = (unsigned long)phba;
  1357. pci_set_drvdata(pdev, host);
  1358. error = scsi_add_host(host, &pdev->dev);
  1359. if (error)
  1360. goto out_kthread_stop;
  1361. error = lpfc_alloc_sysfs_attr(phba);
  1362. if (error)
  1363. goto out_kthread_stop;
  1364. error = request_irq(phba->pcidev->irq, lpfc_intr_handler, SA_SHIRQ,
  1365. LPFC_DRIVER_NAME, phba);
  1366. if (error) {
  1367. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1368. "%d:0451 Enable interrupt handler failed\n",
  1369. phba->brd_no);
  1370. goto out_free_sysfs_attr;
  1371. }
  1372. phba->MBslimaddr = phba->slim_memmap_p;
  1373. phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
  1374. phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
  1375. phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
  1376. phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
  1377. error = lpfc_sli_hba_setup(phba);
  1378. if (error)
  1379. goto out_free_irq;
  1380. /*
  1381. * set fixed host attributes
  1382. * Must done after lpfc_sli_hba_setup()
  1383. */
  1384. fc_host_node_name(host) = wwn_to_u64(phba->fc_nodename.u.wwn);
  1385. fc_host_port_name(host) = wwn_to_u64(phba->fc_portname.u.wwn);
  1386. fc_host_supported_classes(host) = FC_COS_CLASS3;
  1387. memset(fc_host_supported_fc4s(host), 0,
  1388. sizeof(fc_host_supported_fc4s(host)));
  1389. fc_host_supported_fc4s(host)[2] = 1;
  1390. fc_host_supported_fc4s(host)[7] = 1;
  1391. lpfc_get_hba_sym_node_name(phba, fc_host_symbolic_name(host));
  1392. fc_host_supported_speeds(host) = 0;
  1393. switch (FC_JEDEC_ID(phba->vpd.rev.biuRev)) {
  1394. case VIPER_JEDEC_ID:
  1395. fc_host_supported_speeds(host) |= FC_PORTSPEED_10GBIT;
  1396. break;
  1397. case HELIOS_JEDEC_ID:
  1398. fc_host_supported_speeds(host) |= FC_PORTSPEED_4GBIT;
  1399. /* Fall through */
  1400. case CENTAUR_2G_JEDEC_ID:
  1401. case PEGASUS_JEDEC_ID:
  1402. case THOR_JEDEC_ID:
  1403. fc_host_supported_speeds(host) |= FC_PORTSPEED_2GBIT;
  1404. /* Fall through */
  1405. default:
  1406. fc_host_supported_speeds(host) = FC_PORTSPEED_1GBIT;
  1407. }
  1408. fc_host_maxframe_size(host) =
  1409. ((((uint32_t) phba->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
  1410. (uint32_t) phba->fc_sparam.cmn.bbRcvSizeLsb);
  1411. /* This value is also unchanging */
  1412. memset(fc_host_active_fc4s(host), 0,
  1413. sizeof(fc_host_active_fc4s(host)));
  1414. fc_host_active_fc4s(host)[2] = 1;
  1415. fc_host_active_fc4s(host)[7] = 1;
  1416. spin_lock_irq(phba->host->host_lock);
  1417. phba->fc_flag &= ~FC_LOADING;
  1418. spin_unlock_irq(phba->host->host_lock);
  1419. return 0;
  1420. out_free_irq:
  1421. lpfc_stop_timer(phba);
  1422. phba->work_hba_events = 0;
  1423. free_irq(phba->pcidev->irq, phba);
  1424. out_free_sysfs_attr:
  1425. lpfc_free_sysfs_attr(phba);
  1426. out_kthread_stop:
  1427. kthread_stop(phba->worker_thread);
  1428. out_free_iocbq:
  1429. list_for_each_entry_safe(iocbq_entry, iocbq_next,
  1430. &phba->lpfc_iocb_list, list) {
  1431. spin_lock_irq(phba->host->host_lock);
  1432. kfree(iocbq_entry);
  1433. phba->total_iocbq_bufs--;
  1434. spin_unlock_irq(phba->host->host_lock);
  1435. }
  1436. lpfc_mem_free(phba);
  1437. out_free_slim:
  1438. dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, phba->slim2p,
  1439. phba->slim2p_mapping);
  1440. out_iounmap:
  1441. iounmap(phba->ctrl_regs_memmap_p);
  1442. iounmap(phba->slim_memmap_p);
  1443. out_idr_remove:
  1444. idr_remove(&lpfc_hba_index, phba->brd_no);
  1445. out_put_host:
  1446. scsi_host_put(host);
  1447. out_release_regions:
  1448. pci_release_regions(pdev);
  1449. out_disable_device:
  1450. pci_disable_device(pdev);
  1451. out:
  1452. return error;
  1453. }
  1454. static void __devexit
  1455. lpfc_pci_remove_one(struct pci_dev *pdev)
  1456. {
  1457. struct Scsi_Host *host = pci_get_drvdata(pdev);
  1458. struct lpfc_hba *phba = (struct lpfc_hba *)host->hostdata[0];
  1459. unsigned long iflag;
  1460. lpfc_free_sysfs_attr(phba);
  1461. spin_lock_irqsave(phba->host->host_lock, iflag);
  1462. phba->fc_flag |= FC_UNLOADING;
  1463. spin_unlock_irqrestore(phba->host->host_lock, iflag);
  1464. fc_remove_host(phba->host);
  1465. scsi_remove_host(phba->host);
  1466. kthread_stop(phba->worker_thread);
  1467. /*
  1468. * Bring down the SLI Layer. This step disable all interrupts,
  1469. * clears the rings, discards all mailbox commands, and resets
  1470. * the HBA.
  1471. */
  1472. lpfc_sli_hba_down(phba);
  1473. /* Release the irq reservation */
  1474. free_irq(phba->pcidev->irq, phba);
  1475. lpfc_cleanup(phba, 0);
  1476. lpfc_stop_timer(phba);
  1477. phba->work_hba_events = 0;
  1478. /*
  1479. * Call scsi_free before mem_free since scsi bufs are released to their
  1480. * corresponding pools here.
  1481. */
  1482. lpfc_scsi_free(phba);
  1483. lpfc_mem_free(phba);
  1484. /* Free resources associated with SLI2 interface */
  1485. dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
  1486. phba->slim2p, phba->slim2p_mapping);
  1487. /* unmap adapter SLIM and Control Registers */
  1488. iounmap(phba->ctrl_regs_memmap_p);
  1489. iounmap(phba->slim_memmap_p);
  1490. pci_release_regions(phba->pcidev);
  1491. pci_disable_device(phba->pcidev);
  1492. idr_remove(&lpfc_hba_index, phba->brd_no);
  1493. scsi_host_put(phba->host);
  1494. pci_set_drvdata(pdev, NULL);
  1495. }
  1496. static struct pci_device_id lpfc_id_table[] = {
  1497. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER,
  1498. PCI_ANY_ID, PCI_ANY_ID, },
  1499. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY,
  1500. PCI_ANY_ID, PCI_ANY_ID, },
  1501. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR,
  1502. PCI_ANY_ID, PCI_ANY_ID, },
  1503. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS,
  1504. PCI_ANY_ID, PCI_ANY_ID, },
  1505. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR,
  1506. PCI_ANY_ID, PCI_ANY_ID, },
  1507. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY,
  1508. PCI_ANY_ID, PCI_ANY_ID, },
  1509. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY,
  1510. PCI_ANY_ID, PCI_ANY_ID, },
  1511. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY,
  1512. PCI_ANY_ID, PCI_ANY_ID, },
  1513. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY,
  1514. PCI_ANY_ID, PCI_ANY_ID, },
  1515. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE,
  1516. PCI_ANY_ID, PCI_ANY_ID, },
  1517. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP,
  1518. PCI_ANY_ID, PCI_ANY_ID, },
  1519. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP,
  1520. PCI_ANY_ID, PCI_ANY_ID, },
  1521. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS,
  1522. PCI_ANY_ID, PCI_ANY_ID, },
  1523. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP,
  1524. PCI_ANY_ID, PCI_ANY_ID, },
  1525. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP,
  1526. PCI_ANY_ID, PCI_ANY_ID, },
  1527. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID,
  1528. PCI_ANY_ID, PCI_ANY_ID, },
  1529. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB,
  1530. PCI_ANY_ID, PCI_ANY_ID, },
  1531. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR,
  1532. PCI_ANY_ID, PCI_ANY_ID, },
  1533. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP,
  1534. PCI_ANY_ID, PCI_ANY_ID, },
  1535. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP,
  1536. PCI_ANY_ID, PCI_ANY_ID, },
  1537. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID,
  1538. PCI_ANY_ID, PCI_ANY_ID, },
  1539. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB,
  1540. PCI_ANY_ID, PCI_ANY_ID, },
  1541. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY,
  1542. PCI_ANY_ID, PCI_ANY_ID, },
  1543. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101,
  1544. PCI_ANY_ID, PCI_ANY_ID, },
  1545. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S,
  1546. PCI_ANY_ID, PCI_ANY_ID, },
  1547. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S,
  1548. PCI_ANY_ID, PCI_ANY_ID, },
  1549. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S,
  1550. PCI_ANY_ID, PCI_ANY_ID, },
  1551. { 0 }
  1552. };
  1553. MODULE_DEVICE_TABLE(pci, lpfc_id_table);
  1554. static struct pci_driver lpfc_driver = {
  1555. .name = LPFC_DRIVER_NAME,
  1556. .id_table = lpfc_id_table,
  1557. .probe = lpfc_pci_probe_one,
  1558. .remove = __devexit_p(lpfc_pci_remove_one),
  1559. };
  1560. static int __init
  1561. lpfc_init(void)
  1562. {
  1563. int error = 0;
  1564. printk(LPFC_MODULE_DESC "\n");
  1565. printk(LPFC_COPYRIGHT "\n");
  1566. lpfc_transport_template =
  1567. fc_attach_transport(&lpfc_transport_functions);
  1568. if (!lpfc_transport_template)
  1569. return -ENOMEM;
  1570. error = pci_register_driver(&lpfc_driver);
  1571. if (error)
  1572. fc_release_transport(lpfc_transport_template);
  1573. return error;
  1574. }
  1575. static void __exit
  1576. lpfc_exit(void)
  1577. {
  1578. pci_unregister_driver(&lpfc_driver);
  1579. fc_release_transport(lpfc_transport_template);
  1580. }
  1581. module_init(lpfc_init);
  1582. module_exit(lpfc_exit);
  1583. MODULE_LICENSE("GPL");
  1584. MODULE_DESCRIPTION(LPFC_MODULE_DESC);
  1585. MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com");
  1586. MODULE_VERSION("0:" LPFC_DRIVER_VERSION);