lpfc_init.c 54 KB

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