lpfc_init.c 55 KB

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