lpfc_init.c 70 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2007 Emulex. All rights reserved. *
  5. * EMULEX and SLI are trademarks of Emulex. *
  6. * www.emulex.com *
  7. * Portions Copyright (C) 2004-2005 Christoph Hellwig *
  8. * *
  9. * This program is free software; you can redistribute it and/or *
  10. * modify it under the terms of version 2 of the GNU General *
  11. * Public License as published by the Free Software Foundation. *
  12. * This program is distributed in the hope that it will be useful. *
  13. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
  14. * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
  15. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
  16. * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
  17. * TO BE LEGALLY INVALID. See the GNU General Public License for *
  18. * more details, a copy of which can be found in the file COPYING *
  19. * included with this package. *
  20. *******************************************************************/
  21. #include <linux/blkdev.h>
  22. #include <linux/delay.h>
  23. #include <linux/dma-mapping.h>
  24. #include <linux/idr.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/kthread.h>
  27. #include <linux/pci.h>
  28. #include <linux/spinlock.h>
  29. #include <linux/ctype.h>
  30. #include <scsi/scsi.h>
  31. #include <scsi/scsi_device.h>
  32. #include <scsi/scsi_host.h>
  33. #include <scsi/scsi_transport_fc.h>
  34. #include "lpfc_hw.h"
  35. #include "lpfc_sli.h"
  36. #include "lpfc_disc.h"
  37. #include "lpfc_scsi.h"
  38. #include "lpfc.h"
  39. #include "lpfc_logmsg.h"
  40. #include "lpfc_crtn.h"
  41. #include "lpfc_vport.h"
  42. #include "lpfc_version.h"
  43. static int lpfc_parse_vpd(struct lpfc_hba *, uint8_t *, int);
  44. static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *);
  45. static int lpfc_post_rcv_buf(struct lpfc_hba *);
  46. static struct scsi_transport_template *lpfc_transport_template = NULL;
  47. static struct scsi_transport_template *lpfc_vport_transport_template = NULL;
  48. static DEFINE_IDR(lpfc_hba_index);
  49. /************************************************************************/
  50. /* */
  51. /* lpfc_config_port_prep */
  52. /* This routine will do LPFC initialization prior to the */
  53. /* CONFIG_PORT mailbox command. This will be initialized */
  54. /* as a SLI layer callback routine. */
  55. /* This routine returns 0 on success or -ERESTART if it wants */
  56. /* the SLI layer to reset the HBA and try again. Any */
  57. /* other return value indicates an error. */
  58. /* */
  59. /************************************************************************/
  60. int
  61. lpfc_config_port_prep(struct lpfc_hba *phba)
  62. {
  63. lpfc_vpd_t *vp = &phba->vpd;
  64. int i = 0, rc;
  65. LPFC_MBOXQ_t *pmb;
  66. MAILBOX_t *mb;
  67. char *lpfc_vpd_data = NULL;
  68. uint16_t offset = 0;
  69. static char licensed[56] =
  70. "key unlock for use with gnu public licensed code only\0";
  71. static int init_key = 1;
  72. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  73. if (!pmb) {
  74. phba->link_state = LPFC_HBA_ERROR;
  75. return -ENOMEM;
  76. }
  77. mb = &pmb->mb;
  78. phba->link_state = LPFC_INIT_MBX_CMDS;
  79. if (lpfc_is_LC_HBA(phba->pcidev->device)) {
  80. if (init_key) {
  81. uint32_t *ptext = (uint32_t *) licensed;
  82. for (i = 0; i < 56; i += sizeof (uint32_t), ptext++)
  83. *ptext = cpu_to_be32(*ptext);
  84. init_key = 0;
  85. }
  86. lpfc_read_nv(phba, pmb);
  87. memset((char*)mb->un.varRDnvp.rsvd3, 0,
  88. sizeof (mb->un.varRDnvp.rsvd3));
  89. memcpy((char*)mb->un.varRDnvp.rsvd3, licensed,
  90. sizeof (licensed));
  91. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  92. if (rc != MBX_SUCCESS) {
  93. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  94. "0324 Config Port initialization "
  95. "error, mbxCmd x%x READ_NVPARM, "
  96. "mbxStatus x%x\n",
  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(phba->wwnn));
  103. memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname,
  104. sizeof(phba->wwpn));
  105. }
  106. phba->sli3_options = 0x0;
  107. /* Setup and issue mailbox READ REV command */
  108. lpfc_read_rev(phba, pmb);
  109. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  110. if (rc != MBX_SUCCESS) {
  111. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  112. "0439 Adapter failed to init, mbxCmd x%x "
  113. "READ_REV, mbxStatus x%x\n",
  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. "0440 Adapter failed to init, READ_REV has "
  126. "missing revision information.\n");
  127. mempool_free(pmb, phba->mbox_mem_pool);
  128. return -ERESTART;
  129. }
  130. if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp)
  131. return -EINVAL;
  132. /* Save information as VPD data */
  133. vp->rev.rBit = 1;
  134. memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t));
  135. vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev;
  136. memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16);
  137. vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev;
  138. memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16);
  139. vp->rev.biuRev = mb->un.varRdRev.biuRev;
  140. vp->rev.smRev = mb->un.varRdRev.smRev;
  141. vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev;
  142. vp->rev.endecRev = mb->un.varRdRev.endecRev;
  143. vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh;
  144. vp->rev.fcphLow = mb->un.varRdRev.fcphLow;
  145. vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh;
  146. vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow;
  147. vp->rev.postKernRev = mb->un.varRdRev.postKernRev;
  148. vp->rev.opFwRev = mb->un.varRdRev.opFwRev;
  149. /* If the sli feature level is less then 9, we must
  150. * tear down all RPIs and VPIs on link down if NPIV
  151. * is enabled.
  152. */
  153. if (vp->rev.feaLevelHigh < 9)
  154. phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN;
  155. if (lpfc_is_LC_HBA(phba->pcidev->device))
  156. memcpy(phba->RandomData, (char *)&mb->un.varWords[24],
  157. sizeof (phba->RandomData));
  158. /* Get adapter VPD information */
  159. pmb->context2 = kmalloc(DMP_RSP_SIZE, GFP_KERNEL);
  160. if (!pmb->context2)
  161. goto out_free_mbox;
  162. lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL);
  163. if (!lpfc_vpd_data)
  164. goto out_free_context2;
  165. do {
  166. lpfc_dump_mem(phba, pmb, offset);
  167. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  168. if (rc != MBX_SUCCESS) {
  169. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  170. "0441 VPD not present on adapter, "
  171. "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
  172. mb->mbxCommand, mb->mbxStatus);
  173. mb->un.varDmp.word_cnt = 0;
  174. }
  175. if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset)
  176. mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset;
  177. lpfc_sli_pcimem_bcopy(pmb->context2, lpfc_vpd_data + offset,
  178. mb->un.varDmp.word_cnt);
  179. offset += mb->un.varDmp.word_cnt;
  180. } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE);
  181. lpfc_parse_vpd(phba, lpfc_vpd_data, offset);
  182. kfree(lpfc_vpd_data);
  183. out_free_context2:
  184. kfree(pmb->context2);
  185. out_free_mbox:
  186. mempool_free(pmb, phba->mbox_mem_pool);
  187. return 0;
  188. }
  189. /* Completion handler for config async event mailbox command. */
  190. static void
  191. lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
  192. {
  193. if (pmboxq->mb.mbxStatus == MBX_SUCCESS)
  194. phba->temp_sensor_support = 1;
  195. else
  196. phba->temp_sensor_support = 0;
  197. mempool_free(pmboxq, phba->mbox_mem_pool);
  198. return;
  199. }
  200. /************************************************************************/
  201. /* */
  202. /* lpfc_config_port_post */
  203. /* This routine will do LPFC initialization after the */
  204. /* CONFIG_PORT mailbox command. This will be initialized */
  205. /* as a SLI layer callback routine. */
  206. /* This routine returns 0 on success. Any other return value */
  207. /* indicates an error. */
  208. /* */
  209. /************************************************************************/
  210. int
  211. lpfc_config_port_post(struct lpfc_hba *phba)
  212. {
  213. struct lpfc_vport *vport = phba->pport;
  214. LPFC_MBOXQ_t *pmb;
  215. MAILBOX_t *mb;
  216. struct lpfc_dmabuf *mp;
  217. struct lpfc_sli *psli = &phba->sli;
  218. uint32_t status, timeout;
  219. int i, j;
  220. int rc;
  221. spin_lock_irq(&phba->hbalock);
  222. /*
  223. * If the Config port completed correctly the HBA is not
  224. * over heated any more.
  225. */
  226. if (phba->over_temp_state == HBA_OVER_TEMP)
  227. phba->over_temp_state = HBA_NORMAL_TEMP;
  228. spin_unlock_irq(&phba->hbalock);
  229. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  230. if (!pmb) {
  231. phba->link_state = LPFC_HBA_ERROR;
  232. return -ENOMEM;
  233. }
  234. mb = &pmb->mb;
  235. /* Get login parameters for NID. */
  236. lpfc_read_sparam(phba, pmb, 0);
  237. pmb->vport = vport;
  238. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  239. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  240. "0448 Adapter failed init, mbxCmd x%x "
  241. "READ_SPARM mbxStatus x%x\n",
  242. mb->mbxCommand, mb->mbxStatus);
  243. phba->link_state = LPFC_HBA_ERROR;
  244. mp = (struct lpfc_dmabuf *) pmb->context1;
  245. mempool_free( pmb, phba->mbox_mem_pool);
  246. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  247. kfree(mp);
  248. return -EIO;
  249. }
  250. mp = (struct lpfc_dmabuf *) pmb->context1;
  251. memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm));
  252. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  253. kfree(mp);
  254. pmb->context1 = NULL;
  255. if (phba->cfg_soft_wwnn)
  256. u64_to_wwn(phba->cfg_soft_wwnn,
  257. vport->fc_sparam.nodeName.u.wwn);
  258. if (phba->cfg_soft_wwpn)
  259. u64_to_wwn(phba->cfg_soft_wwpn,
  260. vport->fc_sparam.portName.u.wwn);
  261. memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
  262. sizeof (struct lpfc_name));
  263. memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
  264. sizeof (struct lpfc_name));
  265. /* If no serial number in VPD data, use low 6 bytes of WWNN */
  266. /* This should be consolidated into parse_vpd ? - mr */
  267. if (phba->SerialNumber[0] == 0) {
  268. uint8_t *outptr;
  269. outptr = &vport->fc_nodename.u.s.IEEE[0];
  270. for (i = 0; i < 12; i++) {
  271. status = *outptr++;
  272. j = ((status & 0xf0) >> 4);
  273. if (j <= 9)
  274. phba->SerialNumber[i] =
  275. (char)((uint8_t) 0x30 + (uint8_t) j);
  276. else
  277. phba->SerialNumber[i] =
  278. (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
  279. i++;
  280. j = (status & 0xf);
  281. if (j <= 9)
  282. phba->SerialNumber[i] =
  283. (char)((uint8_t) 0x30 + (uint8_t) j);
  284. else
  285. phba->SerialNumber[i] =
  286. (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
  287. }
  288. }
  289. lpfc_read_config(phba, pmb);
  290. pmb->vport = vport;
  291. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  292. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  293. "0453 Adapter failed to init, mbxCmd x%x "
  294. "READ_CONFIG, mbxStatus x%x\n",
  295. mb->mbxCommand, mb->mbxStatus);
  296. phba->link_state = LPFC_HBA_ERROR;
  297. mempool_free( pmb, phba->mbox_mem_pool);
  298. return -EIO;
  299. }
  300. /* Reset the DFT_HBA_Q_DEPTH to the max xri */
  301. if (phba->cfg_hba_queue_depth > (mb->un.varRdConfig.max_xri+1))
  302. phba->cfg_hba_queue_depth =
  303. mb->un.varRdConfig.max_xri + 1;
  304. phba->lmt = mb->un.varRdConfig.lmt;
  305. /* Get the default values for Model Name and Description */
  306. lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
  307. if ((phba->cfg_link_speed > LINK_SPEED_10G)
  308. || ((phba->cfg_link_speed == LINK_SPEED_1G)
  309. && !(phba->lmt & LMT_1Gb))
  310. || ((phba->cfg_link_speed == LINK_SPEED_2G)
  311. && !(phba->lmt & LMT_2Gb))
  312. || ((phba->cfg_link_speed == LINK_SPEED_4G)
  313. && !(phba->lmt & LMT_4Gb))
  314. || ((phba->cfg_link_speed == LINK_SPEED_8G)
  315. && !(phba->lmt & LMT_8Gb))
  316. || ((phba->cfg_link_speed == LINK_SPEED_10G)
  317. && !(phba->lmt & LMT_10Gb))) {
  318. /* Reset link speed to auto */
  319. lpfc_printf_log(phba, KERN_WARNING, LOG_LINK_EVENT,
  320. "1302 Invalid speed for this board: "
  321. "Reset link speed to auto: x%x\n",
  322. phba->cfg_link_speed);
  323. phba->cfg_link_speed = LINK_SPEED_AUTO;
  324. }
  325. phba->link_state = LPFC_LINK_DOWN;
  326. /* Only process IOCBs on ELS ring till hba_state is READY */
  327. if (psli->ring[psli->extra_ring].cmdringaddr)
  328. psli->ring[psli->extra_ring].flag |= LPFC_STOP_IOCB_EVENT;
  329. if (psli->ring[psli->fcp_ring].cmdringaddr)
  330. psli->ring[psli->fcp_ring].flag |= LPFC_STOP_IOCB_EVENT;
  331. if (psli->ring[psli->next_ring].cmdringaddr)
  332. psli->ring[psli->next_ring].flag |= LPFC_STOP_IOCB_EVENT;
  333. /* Post receive buffers for desired rings */
  334. if (phba->sli_rev != 3)
  335. lpfc_post_rcv_buf(phba);
  336. /* Enable appropriate host interrupts */
  337. spin_lock_irq(&phba->hbalock);
  338. status = readl(phba->HCregaddr);
  339. status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA;
  340. if (psli->num_rings > 0)
  341. status |= HC_R0INT_ENA;
  342. if (psli->num_rings > 1)
  343. status |= HC_R1INT_ENA;
  344. if (psli->num_rings > 2)
  345. status |= HC_R2INT_ENA;
  346. if (psli->num_rings > 3)
  347. status |= HC_R3INT_ENA;
  348. if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) &&
  349. (phba->cfg_poll & DISABLE_FCP_RING_INT))
  350. status &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
  351. writel(status, phba->HCregaddr);
  352. readl(phba->HCregaddr); /* flush */
  353. spin_unlock_irq(&phba->hbalock);
  354. /*
  355. * Setup the ring 0 (els) timeout handler
  356. */
  357. timeout = phba->fc_ratov << 1;
  358. mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
  359. mod_timer(&phba->hb_tmofunc, jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  360. phba->hb_outstanding = 0;
  361. phba->last_completion_time = jiffies;
  362. lpfc_init_link(phba, pmb, phba->cfg_topology, phba->cfg_link_speed);
  363. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  364. pmb->vport = vport;
  365. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  366. lpfc_set_loopback_flag(phba);
  367. if (rc != MBX_SUCCESS) {
  368. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  369. "0454 Adapter failed to init, mbxCmd x%x "
  370. "INIT_LINK, mbxStatus x%x\n",
  371. mb->mbxCommand, mb->mbxStatus);
  372. /* Clear all interrupt enable conditions */
  373. writel(0, phba->HCregaddr);
  374. readl(phba->HCregaddr); /* flush */
  375. /* Clear all pending interrupts */
  376. writel(0xffffffff, phba->HAregaddr);
  377. readl(phba->HAregaddr); /* flush */
  378. phba->link_state = LPFC_HBA_ERROR;
  379. if (rc != MBX_BUSY)
  380. mempool_free(pmb, phba->mbox_mem_pool);
  381. return -EIO;
  382. }
  383. /* MBOX buffer will be freed in mbox compl */
  384. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  385. lpfc_config_async(phba, pmb, LPFC_ELS_RING);
  386. pmb->mbox_cmpl = lpfc_config_async_cmpl;
  387. pmb->vport = phba->pport;
  388. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  389. if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
  390. lpfc_printf_log(phba,
  391. KERN_ERR,
  392. LOG_INIT,
  393. "0456 Adapter failed to issue "
  394. "ASYNCEVT_ENABLE mbox status x%x \n.",
  395. rc);
  396. mempool_free(pmb, phba->mbox_mem_pool);
  397. }
  398. return (0);
  399. }
  400. /************************************************************************/
  401. /* */
  402. /* lpfc_hba_down_prep */
  403. /* This routine will do LPFC uninitialization before the */
  404. /* HBA is reset when bringing down the SLI Layer. This will be */
  405. /* initialized as a SLI layer callback routine. */
  406. /* This routine returns 0 on success. Any other return value */
  407. /* indicates an error. */
  408. /* */
  409. /************************************************************************/
  410. int
  411. lpfc_hba_down_prep(struct lpfc_hba *phba)
  412. {
  413. /* Disable interrupts */
  414. writel(0, phba->HCregaddr);
  415. readl(phba->HCregaddr); /* flush */
  416. lpfc_cleanup_discovery_resources(phba->pport);
  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. struct lpfc_iocbq *iocb;
  435. IOCB_t *cmd = NULL;
  436. LIST_HEAD(completions);
  437. int i;
  438. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
  439. lpfc_sli_hbqbuf_free_all(phba);
  440. else {
  441. /* Cleanup preposted buffers on the ELS ring */
  442. pring = &psli->ring[LPFC_ELS_RING];
  443. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  444. list_del(&mp->list);
  445. pring->postbufq_cnt--;
  446. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  447. kfree(mp);
  448. }
  449. }
  450. spin_lock_irq(&phba->hbalock);
  451. for (i = 0; i < psli->num_rings; i++) {
  452. pring = &psli->ring[i];
  453. /* At this point in time the HBA is either reset or DOA. Either
  454. * way, nothing should be on txcmplq as it will NEVER complete.
  455. */
  456. list_splice_init(&pring->txcmplq, &completions);
  457. pring->txcmplq_cnt = 0;
  458. spin_unlock_irq(&phba->hbalock);
  459. while (!list_empty(&completions)) {
  460. iocb = list_get_first(&completions, struct lpfc_iocbq,
  461. list);
  462. cmd = &iocb->iocb;
  463. list_del_init(&iocb->list);
  464. if (!iocb->iocb_cmpl)
  465. lpfc_sli_release_iocbq(phba, iocb);
  466. else {
  467. cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
  468. cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
  469. (iocb->iocb_cmpl) (phba, iocb, iocb);
  470. }
  471. }
  472. lpfc_sli_abort_iocb_ring(phba, pring);
  473. spin_lock_irq(&phba->hbalock);
  474. }
  475. spin_unlock_irq(&phba->hbalock);
  476. return 0;
  477. }
  478. /* HBA heart beat timeout handler */
  479. static void
  480. lpfc_hb_timeout(unsigned long ptr)
  481. {
  482. struct lpfc_hba *phba;
  483. unsigned long iflag;
  484. phba = (struct lpfc_hba *)ptr;
  485. spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
  486. if (!(phba->pport->work_port_events & WORKER_HB_TMO))
  487. phba->pport->work_port_events |= WORKER_HB_TMO;
  488. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
  489. if (phba->work_wait)
  490. wake_up(phba->work_wait);
  491. return;
  492. }
  493. static void
  494. lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
  495. {
  496. unsigned long drvr_flag;
  497. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  498. phba->hb_outstanding = 0;
  499. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  500. mempool_free(pmboxq, phba->mbox_mem_pool);
  501. if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) &&
  502. !(phba->link_state == LPFC_HBA_ERROR) &&
  503. !(phba->pport->load_flag & FC_UNLOADING))
  504. mod_timer(&phba->hb_tmofunc,
  505. jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  506. return;
  507. }
  508. void
  509. lpfc_hb_timeout_handler(struct lpfc_hba *phba)
  510. {
  511. LPFC_MBOXQ_t *pmboxq;
  512. struct lpfc_dmabuf *buf_ptr;
  513. int retval;
  514. struct lpfc_sli *psli = &phba->sli;
  515. LIST_HEAD(completions);
  516. if ((phba->link_state == LPFC_HBA_ERROR) ||
  517. (phba->pport->load_flag & FC_UNLOADING) ||
  518. (phba->pport->fc_flag & FC_OFFLINE_MODE))
  519. return;
  520. spin_lock_irq(&phba->pport->work_port_lock);
  521. /* If the timer is already canceled do nothing */
  522. if (!(phba->pport->work_port_events & WORKER_HB_TMO)) {
  523. spin_unlock_irq(&phba->pport->work_port_lock);
  524. return;
  525. }
  526. if (time_after(phba->last_completion_time + LPFC_HB_MBOX_INTERVAL * HZ,
  527. jiffies)) {
  528. spin_unlock_irq(&phba->pport->work_port_lock);
  529. if (!phba->hb_outstanding)
  530. mod_timer(&phba->hb_tmofunc,
  531. jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  532. else
  533. mod_timer(&phba->hb_tmofunc,
  534. jiffies + HZ * LPFC_HB_MBOX_TIMEOUT);
  535. return;
  536. }
  537. spin_unlock_irq(&phba->pport->work_port_lock);
  538. if (phba->elsbuf_cnt &&
  539. (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) {
  540. spin_lock_irq(&phba->hbalock);
  541. list_splice_init(&phba->elsbuf, &completions);
  542. phba->elsbuf_cnt = 0;
  543. phba->elsbuf_prev_cnt = 0;
  544. spin_unlock_irq(&phba->hbalock);
  545. while (!list_empty(&completions)) {
  546. list_remove_head(&completions, buf_ptr,
  547. struct lpfc_dmabuf, list);
  548. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  549. kfree(buf_ptr);
  550. }
  551. }
  552. phba->elsbuf_prev_cnt = phba->elsbuf_cnt;
  553. /* If there is no heart beat outstanding, issue a heartbeat command */
  554. if (phba->cfg_enable_hba_heartbeat) {
  555. if (!phba->hb_outstanding) {
  556. pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
  557. if (!pmboxq) {
  558. mod_timer(&phba->hb_tmofunc,
  559. jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  560. return;
  561. }
  562. lpfc_heart_beat(phba, pmboxq);
  563. pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl;
  564. pmboxq->vport = phba->pport;
  565. retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
  566. if (retval != MBX_BUSY && retval != MBX_SUCCESS) {
  567. mempool_free(pmboxq, phba->mbox_mem_pool);
  568. mod_timer(&phba->hb_tmofunc,
  569. jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  570. return;
  571. }
  572. mod_timer(&phba->hb_tmofunc,
  573. jiffies + HZ * LPFC_HB_MBOX_TIMEOUT);
  574. phba->hb_outstanding = 1;
  575. return;
  576. } else {
  577. /*
  578. * If heart beat timeout called with hb_outstanding set
  579. * we need to take the HBA offline.
  580. */
  581. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  582. "0459 Adapter heartbeat failure, "
  583. "taking this port offline.\n");
  584. spin_lock_irq(&phba->hbalock);
  585. psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
  586. spin_unlock_irq(&phba->hbalock);
  587. lpfc_offline_prep(phba);
  588. lpfc_offline(phba);
  589. lpfc_unblock_mgmt_io(phba);
  590. phba->link_state = LPFC_HBA_ERROR;
  591. lpfc_hba_down_post(phba);
  592. }
  593. }
  594. }
  595. static void
  596. lpfc_offline_eratt(struct lpfc_hba *phba)
  597. {
  598. struct lpfc_sli *psli = &phba->sli;
  599. spin_lock_irq(&phba->hbalock);
  600. psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
  601. spin_unlock_irq(&phba->hbalock);
  602. lpfc_offline_prep(phba);
  603. lpfc_offline(phba);
  604. lpfc_reset_barrier(phba);
  605. lpfc_sli_brdreset(phba);
  606. lpfc_hba_down_post(phba);
  607. lpfc_sli_brdready(phba, HS_MBRDY);
  608. lpfc_unblock_mgmt_io(phba);
  609. phba->link_state = LPFC_HBA_ERROR;
  610. return;
  611. }
  612. /************************************************************************/
  613. /* */
  614. /* lpfc_handle_eratt */
  615. /* This routine will handle processing a Host Attention */
  616. /* Error Status event. This will be initialized */
  617. /* as a SLI layer callback routine. */
  618. /* */
  619. /************************************************************************/
  620. void
  621. lpfc_handle_eratt(struct lpfc_hba *phba)
  622. {
  623. struct lpfc_vport *vport = phba->pport;
  624. struct lpfc_sli *psli = &phba->sli;
  625. struct lpfc_sli_ring *pring;
  626. struct lpfc_vport **vports;
  627. uint32_t event_data;
  628. unsigned long temperature;
  629. struct temp_event temp_event_data;
  630. struct Scsi_Host *shost;
  631. int i;
  632. /* If the pci channel is offline, ignore possible errors,
  633. * since we cannot communicate with the pci card anyway. */
  634. if (pci_channel_offline(phba->pcidev))
  635. return;
  636. /* If resets are disabled then leave the HBA alone and return */
  637. if (!phba->cfg_enable_hba_reset)
  638. return;
  639. if (phba->work_hs & HS_FFER6 ||
  640. phba->work_hs & HS_FFER5) {
  641. /* Re-establishing Link */
  642. lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
  643. "1301 Re-establishing Link "
  644. "Data: x%x x%x x%x\n",
  645. phba->work_hs,
  646. phba->work_status[0], phba->work_status[1]);
  647. vports = lpfc_create_vport_work_array(phba);
  648. if (vports != NULL)
  649. for(i = 0;
  650. i <= phba->max_vpi && vports[i] != NULL;
  651. i++){
  652. shost = lpfc_shost_from_vport(vports[i]);
  653. spin_lock_irq(shost->host_lock);
  654. vports[i]->fc_flag |= FC_ESTABLISH_LINK;
  655. spin_unlock_irq(shost->host_lock);
  656. }
  657. lpfc_destroy_vport_work_array(phba, vports);
  658. spin_lock_irq(&phba->hbalock);
  659. psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
  660. spin_unlock_irq(&phba->hbalock);
  661. /*
  662. * Firmware stops when it triggled erratt with HS_FFER6.
  663. * That could cause the I/Os dropped by the firmware.
  664. * Error iocb (I/O) on txcmplq and let the SCSI layer
  665. * retry it after re-establishing link.
  666. */
  667. pring = &psli->ring[psli->fcp_ring];
  668. lpfc_sli_abort_iocb_ring(phba, pring);
  669. /*
  670. * There was a firmware error. Take the hba offline and then
  671. * attempt to restart it.
  672. */
  673. lpfc_offline_prep(phba);
  674. lpfc_offline(phba);
  675. lpfc_sli_brdrestart(phba);
  676. if (lpfc_online(phba) == 0) { /* Initialize the HBA */
  677. mod_timer(&phba->fc_estabtmo, jiffies + HZ * 60);
  678. lpfc_unblock_mgmt_io(phba);
  679. return;
  680. }
  681. lpfc_unblock_mgmt_io(phba);
  682. } else if (phba->work_hs & HS_CRIT_TEMP) {
  683. temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET);
  684. temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
  685. temp_event_data.event_code = LPFC_CRIT_TEMP;
  686. temp_event_data.data = (uint32_t)temperature;
  687. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  688. "0459 Adapter maximum temperature exceeded "
  689. "(%ld), taking this port offline "
  690. "Data: x%x x%x x%x\n",
  691. temperature, phba->work_hs,
  692. phba->work_status[0], phba->work_status[1]);
  693. shost = lpfc_shost_from_vport(phba->pport);
  694. fc_host_post_vendor_event(shost, fc_get_event_number(),
  695. sizeof(temp_event_data),
  696. (char *) &temp_event_data,
  697. SCSI_NL_VID_TYPE_PCI
  698. | PCI_VENDOR_ID_EMULEX);
  699. spin_lock_irq(&phba->hbalock);
  700. phba->over_temp_state = HBA_OVER_TEMP;
  701. spin_unlock_irq(&phba->hbalock);
  702. lpfc_offline_eratt(phba);
  703. } else {
  704. /* The if clause above forces this code path when the status
  705. * failure is a value other than FFER6. Do not call the offline
  706. * twice. This is the adapter hardware error path.
  707. */
  708. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  709. "0457 Adapter Hardware Error "
  710. "Data: x%x x%x x%x\n",
  711. phba->work_hs,
  712. phba->work_status[0], phba->work_status[1]);
  713. event_data = FC_REG_DUMP_EVENT;
  714. shost = lpfc_shost_from_vport(vport);
  715. fc_host_post_vendor_event(shost, fc_get_event_number(),
  716. sizeof(event_data), (char *) &event_data,
  717. SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
  718. lpfc_offline_eratt(phba);
  719. }
  720. }
  721. /************************************************************************/
  722. /* */
  723. /* lpfc_handle_latt */
  724. /* This routine will handle processing a Host Attention */
  725. /* Link Status event. This will be initialized */
  726. /* as a SLI layer callback routine. */
  727. /* */
  728. /************************************************************************/
  729. void
  730. lpfc_handle_latt(struct lpfc_hba *phba)
  731. {
  732. struct lpfc_vport *vport = phba->pport;
  733. struct lpfc_sli *psli = &phba->sli;
  734. LPFC_MBOXQ_t *pmb;
  735. volatile uint32_t control;
  736. struct lpfc_dmabuf *mp;
  737. int rc = 0;
  738. pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  739. if (!pmb) {
  740. rc = 1;
  741. goto lpfc_handle_latt_err_exit;
  742. }
  743. mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  744. if (!mp) {
  745. rc = 2;
  746. goto lpfc_handle_latt_free_pmb;
  747. }
  748. mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
  749. if (!mp->virt) {
  750. rc = 3;
  751. goto lpfc_handle_latt_free_mp;
  752. }
  753. /* Cleanup any outstanding ELS commands */
  754. lpfc_els_flush_all_cmd(phba);
  755. psli->slistat.link_event++;
  756. lpfc_read_la(phba, pmb, mp);
  757. pmb->mbox_cmpl = lpfc_mbx_cmpl_read_la;
  758. pmb->vport = vport;
  759. rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT);
  760. if (rc == MBX_NOT_FINISHED) {
  761. rc = 4;
  762. goto lpfc_handle_latt_free_mbuf;
  763. }
  764. /* Clear Link Attention in HA REG */
  765. spin_lock_irq(&phba->hbalock);
  766. writel(HA_LATT, phba->HAregaddr);
  767. readl(phba->HAregaddr); /* flush */
  768. spin_unlock_irq(&phba->hbalock);
  769. return;
  770. lpfc_handle_latt_free_mbuf:
  771. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  772. lpfc_handle_latt_free_mp:
  773. kfree(mp);
  774. lpfc_handle_latt_free_pmb:
  775. mempool_free(pmb, phba->mbox_mem_pool);
  776. lpfc_handle_latt_err_exit:
  777. /* Enable Link attention interrupts */
  778. spin_lock_irq(&phba->hbalock);
  779. psli->sli_flag |= LPFC_PROCESS_LA;
  780. control = readl(phba->HCregaddr);
  781. control |= HC_LAINT_ENA;
  782. writel(control, phba->HCregaddr);
  783. readl(phba->HCregaddr); /* flush */
  784. /* Clear Link Attention in HA REG */
  785. writel(HA_LATT, phba->HAregaddr);
  786. readl(phba->HAregaddr); /* flush */
  787. spin_unlock_irq(&phba->hbalock);
  788. lpfc_linkdown(phba);
  789. phba->link_state = LPFC_HBA_ERROR;
  790. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  791. "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc);
  792. return;
  793. }
  794. /************************************************************************/
  795. /* */
  796. /* lpfc_parse_vpd */
  797. /* This routine will parse the VPD data */
  798. /* */
  799. /************************************************************************/
  800. static int
  801. lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len)
  802. {
  803. uint8_t lenlo, lenhi;
  804. int Length;
  805. int i, j;
  806. int finished = 0;
  807. int index = 0;
  808. if (!vpd)
  809. return 0;
  810. /* Vital Product */
  811. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  812. "0455 Vital Product Data: x%x x%x x%x x%x\n",
  813. (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
  814. (uint32_t) vpd[3]);
  815. while (!finished && (index < (len - 4))) {
  816. switch (vpd[index]) {
  817. case 0x82:
  818. case 0x91:
  819. index += 1;
  820. lenlo = vpd[index];
  821. index += 1;
  822. lenhi = vpd[index];
  823. index += 1;
  824. i = ((((unsigned short)lenhi) << 8) + lenlo);
  825. index += i;
  826. break;
  827. case 0x90:
  828. index += 1;
  829. lenlo = vpd[index];
  830. index += 1;
  831. lenhi = vpd[index];
  832. index += 1;
  833. Length = ((((unsigned short)lenhi) << 8) + lenlo);
  834. if (Length > len - index)
  835. Length = len - index;
  836. while (Length > 0) {
  837. /* Look for Serial Number */
  838. if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) {
  839. index += 2;
  840. i = vpd[index];
  841. index += 1;
  842. j = 0;
  843. Length -= (3+i);
  844. while(i--) {
  845. phba->SerialNumber[j++] = vpd[index++];
  846. if (j == 31)
  847. break;
  848. }
  849. phba->SerialNumber[j] = 0;
  850. continue;
  851. }
  852. else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) {
  853. phba->vpd_flag |= VPD_MODEL_DESC;
  854. index += 2;
  855. i = vpd[index];
  856. index += 1;
  857. j = 0;
  858. Length -= (3+i);
  859. while(i--) {
  860. phba->ModelDesc[j++] = vpd[index++];
  861. if (j == 255)
  862. break;
  863. }
  864. phba->ModelDesc[j] = 0;
  865. continue;
  866. }
  867. else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) {
  868. phba->vpd_flag |= VPD_MODEL_NAME;
  869. index += 2;
  870. i = vpd[index];
  871. index += 1;
  872. j = 0;
  873. Length -= (3+i);
  874. while(i--) {
  875. phba->ModelName[j++] = vpd[index++];
  876. if (j == 79)
  877. break;
  878. }
  879. phba->ModelName[j] = 0;
  880. continue;
  881. }
  882. else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) {
  883. phba->vpd_flag |= VPD_PROGRAM_TYPE;
  884. index += 2;
  885. i = vpd[index];
  886. index += 1;
  887. j = 0;
  888. Length -= (3+i);
  889. while(i--) {
  890. phba->ProgramType[j++] = vpd[index++];
  891. if (j == 255)
  892. break;
  893. }
  894. phba->ProgramType[j] = 0;
  895. continue;
  896. }
  897. else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) {
  898. phba->vpd_flag |= VPD_PORT;
  899. index += 2;
  900. i = vpd[index];
  901. index += 1;
  902. j = 0;
  903. Length -= (3+i);
  904. while(i--) {
  905. phba->Port[j++] = vpd[index++];
  906. if (j == 19)
  907. break;
  908. }
  909. phba->Port[j] = 0;
  910. continue;
  911. }
  912. else {
  913. index += 2;
  914. i = vpd[index];
  915. index += 1;
  916. index += i;
  917. Length -= (3 + i);
  918. }
  919. }
  920. finished = 0;
  921. break;
  922. case 0x78:
  923. finished = 1;
  924. break;
  925. default:
  926. index ++;
  927. break;
  928. }
  929. }
  930. return(1);
  931. }
  932. static void
  933. lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
  934. {
  935. lpfc_vpd_t *vp;
  936. uint16_t dev_id = phba->pcidev->device;
  937. int max_speed;
  938. struct {
  939. char * name;
  940. int max_speed;
  941. char * bus;
  942. } m = {"<Unknown>", 0, ""};
  943. if (mdp && mdp[0] != '\0'
  944. && descp && descp[0] != '\0')
  945. return;
  946. if (phba->lmt & LMT_10Gb)
  947. max_speed = 10;
  948. else if (phba->lmt & LMT_8Gb)
  949. max_speed = 8;
  950. else if (phba->lmt & LMT_4Gb)
  951. max_speed = 4;
  952. else if (phba->lmt & LMT_2Gb)
  953. max_speed = 2;
  954. else
  955. max_speed = 1;
  956. vp = &phba->vpd;
  957. switch (dev_id) {
  958. case PCI_DEVICE_ID_FIREFLY:
  959. m = (typeof(m)){"LP6000", max_speed, "PCI"};
  960. break;
  961. case PCI_DEVICE_ID_SUPERFLY:
  962. if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
  963. m = (typeof(m)){"LP7000", max_speed, "PCI"};
  964. else
  965. m = (typeof(m)){"LP7000E", max_speed, "PCI"};
  966. break;
  967. case PCI_DEVICE_ID_DRAGONFLY:
  968. m = (typeof(m)){"LP8000", max_speed, "PCI"};
  969. break;
  970. case PCI_DEVICE_ID_CENTAUR:
  971. if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
  972. m = (typeof(m)){"LP9002", max_speed, "PCI"};
  973. else
  974. m = (typeof(m)){"LP9000", max_speed, "PCI"};
  975. break;
  976. case PCI_DEVICE_ID_RFLY:
  977. m = (typeof(m)){"LP952", max_speed, "PCI"};
  978. break;
  979. case PCI_DEVICE_ID_PEGASUS:
  980. m = (typeof(m)){"LP9802", max_speed, "PCI-X"};
  981. break;
  982. case PCI_DEVICE_ID_THOR:
  983. m = (typeof(m)){"LP10000", max_speed, "PCI-X"};
  984. break;
  985. case PCI_DEVICE_ID_VIPER:
  986. m = (typeof(m)){"LPX1000", max_speed, "PCI-X"};
  987. break;
  988. case PCI_DEVICE_ID_PFLY:
  989. m = (typeof(m)){"LP982", max_speed, "PCI-X"};
  990. break;
  991. case PCI_DEVICE_ID_TFLY:
  992. m = (typeof(m)){"LP1050", max_speed, "PCI-X"};
  993. break;
  994. case PCI_DEVICE_ID_HELIOS:
  995. m = (typeof(m)){"LP11000", max_speed, "PCI-X2"};
  996. break;
  997. case PCI_DEVICE_ID_HELIOS_SCSP:
  998. m = (typeof(m)){"LP11000-SP", max_speed, "PCI-X2"};
  999. break;
  1000. case PCI_DEVICE_ID_HELIOS_DCSP:
  1001. m = (typeof(m)){"LP11002-SP", max_speed, "PCI-X2"};
  1002. break;
  1003. case PCI_DEVICE_ID_NEPTUNE:
  1004. m = (typeof(m)){"LPe1000", max_speed, "PCIe"};
  1005. break;
  1006. case PCI_DEVICE_ID_NEPTUNE_SCSP:
  1007. m = (typeof(m)){"LPe1000-SP", max_speed, "PCIe"};
  1008. break;
  1009. case PCI_DEVICE_ID_NEPTUNE_DCSP:
  1010. m = (typeof(m)){"LPe1002-SP", max_speed, "PCIe"};
  1011. break;
  1012. case PCI_DEVICE_ID_BMID:
  1013. m = (typeof(m)){"LP1150", max_speed, "PCI-X2"};
  1014. break;
  1015. case PCI_DEVICE_ID_BSMB:
  1016. m = (typeof(m)){"LP111", max_speed, "PCI-X2"};
  1017. break;
  1018. case PCI_DEVICE_ID_ZEPHYR:
  1019. m = (typeof(m)){"LPe11000", max_speed, "PCIe"};
  1020. break;
  1021. case PCI_DEVICE_ID_ZEPHYR_SCSP:
  1022. m = (typeof(m)){"LPe11000", max_speed, "PCIe"};
  1023. break;
  1024. case PCI_DEVICE_ID_ZEPHYR_DCSP:
  1025. m = (typeof(m)){"LPe11002-SP", max_speed, "PCIe"};
  1026. break;
  1027. case PCI_DEVICE_ID_ZMID:
  1028. m = (typeof(m)){"LPe1150", max_speed, "PCIe"};
  1029. break;
  1030. case PCI_DEVICE_ID_ZSMB:
  1031. m = (typeof(m)){"LPe111", max_speed, "PCIe"};
  1032. break;
  1033. case PCI_DEVICE_ID_LP101:
  1034. m = (typeof(m)){"LP101", max_speed, "PCI-X"};
  1035. break;
  1036. case PCI_DEVICE_ID_LP10000S:
  1037. m = (typeof(m)){"LP10000-S", max_speed, "PCI"};
  1038. break;
  1039. case PCI_DEVICE_ID_LP11000S:
  1040. m = (typeof(m)){"LP11000-S", max_speed,
  1041. "PCI-X2"};
  1042. break;
  1043. case PCI_DEVICE_ID_LPE11000S:
  1044. m = (typeof(m)){"LPe11000-S", max_speed,
  1045. "PCIe"};
  1046. break;
  1047. case PCI_DEVICE_ID_SAT:
  1048. m = (typeof(m)){"LPe12000", max_speed, "PCIe"};
  1049. break;
  1050. case PCI_DEVICE_ID_SAT_MID:
  1051. m = (typeof(m)){"LPe1250", max_speed, "PCIe"};
  1052. break;
  1053. case PCI_DEVICE_ID_SAT_SMB:
  1054. m = (typeof(m)){"LPe121", max_speed, "PCIe"};
  1055. break;
  1056. case PCI_DEVICE_ID_SAT_DCSP:
  1057. m = (typeof(m)){"LPe12002-SP", max_speed, "PCIe"};
  1058. break;
  1059. case PCI_DEVICE_ID_SAT_SCSP:
  1060. m = (typeof(m)){"LPe12000-SP", max_speed, "PCIe"};
  1061. break;
  1062. case PCI_DEVICE_ID_SAT_S:
  1063. m = (typeof(m)){"LPe12000-S", max_speed, "PCIe"};
  1064. break;
  1065. default:
  1066. m = (typeof(m)){ NULL };
  1067. break;
  1068. }
  1069. if (mdp && mdp[0] == '\0')
  1070. snprintf(mdp, 79,"%s", m.name);
  1071. if (descp && descp[0] == '\0')
  1072. snprintf(descp, 255,
  1073. "Emulex %s %dGb %s Fibre Channel Adapter",
  1074. m.name, m.max_speed, m.bus);
  1075. }
  1076. /**************************************************/
  1077. /* lpfc_post_buffer */
  1078. /* */
  1079. /* This routine will post count buffers to the */
  1080. /* ring with the QUE_RING_BUF_CN command. This */
  1081. /* allows 3 buffers / command to be posted. */
  1082. /* Returns the number of buffers NOT posted. */
  1083. /**************************************************/
  1084. int
  1085. lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt,
  1086. int type)
  1087. {
  1088. IOCB_t *icmd;
  1089. struct lpfc_iocbq *iocb;
  1090. struct lpfc_dmabuf *mp1, *mp2;
  1091. cnt += pring->missbufcnt;
  1092. /* While there are buffers to post */
  1093. while (cnt > 0) {
  1094. /* Allocate buffer for command iocb */
  1095. iocb = lpfc_sli_get_iocbq(phba);
  1096. if (iocb == NULL) {
  1097. pring->missbufcnt = cnt;
  1098. return cnt;
  1099. }
  1100. icmd = &iocb->iocb;
  1101. /* 2 buffers can be posted per command */
  1102. /* Allocate buffer to post */
  1103. mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
  1104. if (mp1)
  1105. mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys);
  1106. if (!mp1 || !mp1->virt) {
  1107. kfree(mp1);
  1108. lpfc_sli_release_iocbq(phba, iocb);
  1109. pring->missbufcnt = cnt;
  1110. return cnt;
  1111. }
  1112. INIT_LIST_HEAD(&mp1->list);
  1113. /* Allocate buffer to post */
  1114. if (cnt > 1) {
  1115. mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
  1116. if (mp2)
  1117. mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
  1118. &mp2->phys);
  1119. if (!mp2 || !mp2->virt) {
  1120. kfree(mp2);
  1121. lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
  1122. kfree(mp1);
  1123. lpfc_sli_release_iocbq(phba, iocb);
  1124. pring->missbufcnt = cnt;
  1125. return cnt;
  1126. }
  1127. INIT_LIST_HEAD(&mp2->list);
  1128. } else {
  1129. mp2 = NULL;
  1130. }
  1131. icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
  1132. icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
  1133. icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
  1134. icmd->ulpBdeCount = 1;
  1135. cnt--;
  1136. if (mp2) {
  1137. icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
  1138. icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
  1139. icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
  1140. cnt--;
  1141. icmd->ulpBdeCount = 2;
  1142. }
  1143. icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
  1144. icmd->ulpLe = 1;
  1145. if (lpfc_sli_issue_iocb(phba, pring, iocb, 0) == IOCB_ERROR) {
  1146. lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
  1147. kfree(mp1);
  1148. cnt++;
  1149. if (mp2) {
  1150. lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
  1151. kfree(mp2);
  1152. cnt++;
  1153. }
  1154. lpfc_sli_release_iocbq(phba, iocb);
  1155. pring->missbufcnt = cnt;
  1156. return cnt;
  1157. }
  1158. lpfc_sli_ringpostbuf_put(phba, pring, mp1);
  1159. if (mp2)
  1160. lpfc_sli_ringpostbuf_put(phba, pring, mp2);
  1161. }
  1162. pring->missbufcnt = 0;
  1163. return 0;
  1164. }
  1165. /************************************************************************/
  1166. /* */
  1167. /* lpfc_post_rcv_buf */
  1168. /* This routine post initial rcv buffers to the configured rings */
  1169. /* */
  1170. /************************************************************************/
  1171. static int
  1172. lpfc_post_rcv_buf(struct lpfc_hba *phba)
  1173. {
  1174. struct lpfc_sli *psli = &phba->sli;
  1175. /* Ring 0, ELS / CT buffers */
  1176. lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0, 1);
  1177. /* Ring 2 - FCP no buffers needed */
  1178. return 0;
  1179. }
  1180. #define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
  1181. /************************************************************************/
  1182. /* */
  1183. /* lpfc_sha_init */
  1184. /* */
  1185. /************************************************************************/
  1186. static void
  1187. lpfc_sha_init(uint32_t * HashResultPointer)
  1188. {
  1189. HashResultPointer[0] = 0x67452301;
  1190. HashResultPointer[1] = 0xEFCDAB89;
  1191. HashResultPointer[2] = 0x98BADCFE;
  1192. HashResultPointer[3] = 0x10325476;
  1193. HashResultPointer[4] = 0xC3D2E1F0;
  1194. }
  1195. /************************************************************************/
  1196. /* */
  1197. /* lpfc_sha_iterate */
  1198. /* */
  1199. /************************************************************************/
  1200. static void
  1201. lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
  1202. {
  1203. int t;
  1204. uint32_t TEMP;
  1205. uint32_t A, B, C, D, E;
  1206. t = 16;
  1207. do {
  1208. HashWorkingPointer[t] =
  1209. S(1,
  1210. HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
  1211. 8] ^
  1212. HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
  1213. } while (++t <= 79);
  1214. t = 0;
  1215. A = HashResultPointer[0];
  1216. B = HashResultPointer[1];
  1217. C = HashResultPointer[2];
  1218. D = HashResultPointer[3];
  1219. E = HashResultPointer[4];
  1220. do {
  1221. if (t < 20) {
  1222. TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
  1223. } else if (t < 40) {
  1224. TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
  1225. } else if (t < 60) {
  1226. TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
  1227. } else {
  1228. TEMP = (B ^ C ^ D) + 0xCA62C1D6;
  1229. }
  1230. TEMP += S(5, A) + E + HashWorkingPointer[t];
  1231. E = D;
  1232. D = C;
  1233. C = S(30, B);
  1234. B = A;
  1235. A = TEMP;
  1236. } while (++t <= 79);
  1237. HashResultPointer[0] += A;
  1238. HashResultPointer[1] += B;
  1239. HashResultPointer[2] += C;
  1240. HashResultPointer[3] += D;
  1241. HashResultPointer[4] += E;
  1242. }
  1243. /************************************************************************/
  1244. /* */
  1245. /* lpfc_challenge_key */
  1246. /* */
  1247. /************************************************************************/
  1248. static void
  1249. lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
  1250. {
  1251. *HashWorking = (*RandomChallenge ^ *HashWorking);
  1252. }
  1253. /************************************************************************/
  1254. /* */
  1255. /* lpfc_hba_init */
  1256. /* */
  1257. /************************************************************************/
  1258. void
  1259. lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
  1260. {
  1261. int t;
  1262. uint32_t *HashWorking;
  1263. uint32_t *pwwnn = (uint32_t *) phba->wwnn;
  1264. HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL);
  1265. if (!HashWorking)
  1266. return;
  1267. HashWorking[0] = HashWorking[78] = *pwwnn++;
  1268. HashWorking[1] = HashWorking[79] = *pwwnn;
  1269. for (t = 0; t < 7; t++)
  1270. lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
  1271. lpfc_sha_init(hbainit);
  1272. lpfc_sha_iterate(hbainit, HashWorking);
  1273. kfree(HashWorking);
  1274. }
  1275. void
  1276. lpfc_cleanup(struct lpfc_vport *vport)
  1277. {
  1278. struct lpfc_hba *phba = vport->phba;
  1279. struct lpfc_nodelist *ndlp, *next_ndlp;
  1280. int i = 0;
  1281. if (phba->link_state > LPFC_LINK_DOWN)
  1282. lpfc_port_link_failure(vport);
  1283. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
  1284. if (ndlp->nlp_type & NLP_FABRIC)
  1285. lpfc_disc_state_machine(vport, ndlp, NULL,
  1286. NLP_EVT_DEVICE_RECOVERY);
  1287. lpfc_disc_state_machine(vport, ndlp, NULL,
  1288. NLP_EVT_DEVICE_RM);
  1289. }
  1290. /* At this point, ALL ndlp's should be gone
  1291. * because of the previous NLP_EVT_DEVICE_RM.
  1292. * Lets wait for this to happen, if needed.
  1293. */
  1294. while (!list_empty(&vport->fc_nodes)) {
  1295. if (i++ > 3000) {
  1296. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  1297. "0233 Nodelist not empty\n");
  1298. break;
  1299. }
  1300. /* Wait for any activity on ndlps to settle */
  1301. msleep(10);
  1302. }
  1303. return;
  1304. }
  1305. static void
  1306. lpfc_establish_link_tmo(unsigned long ptr)
  1307. {
  1308. struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
  1309. struct lpfc_vport **vports;
  1310. unsigned long iflag;
  1311. int i;
  1312. /* Re-establishing Link, timer expired */
  1313. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  1314. "1300 Re-establishing Link, timer expired "
  1315. "Data: x%x x%x\n",
  1316. phba->pport->fc_flag, phba->pport->port_state);
  1317. vports = lpfc_create_vport_work_array(phba);
  1318. if (vports != NULL)
  1319. for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
  1320. struct Scsi_Host *shost;
  1321. shost = lpfc_shost_from_vport(vports[i]);
  1322. spin_lock_irqsave(shost->host_lock, iflag);
  1323. vports[i]->fc_flag &= ~FC_ESTABLISH_LINK;
  1324. spin_unlock_irqrestore(shost->host_lock, iflag);
  1325. }
  1326. lpfc_destroy_vport_work_array(phba, vports);
  1327. }
  1328. void
  1329. lpfc_stop_vport_timers(struct lpfc_vport *vport)
  1330. {
  1331. del_timer_sync(&vport->els_tmofunc);
  1332. del_timer_sync(&vport->fc_fdmitmo);
  1333. lpfc_can_disctmo(vport);
  1334. return;
  1335. }
  1336. static void
  1337. lpfc_stop_phba_timers(struct lpfc_hba *phba)
  1338. {
  1339. del_timer_sync(&phba->fcp_poll_timer);
  1340. del_timer_sync(&phba->fc_estabtmo);
  1341. lpfc_stop_vport_timers(phba->pport);
  1342. del_timer_sync(&phba->sli.mbox_tmo);
  1343. del_timer_sync(&phba->fabric_block_timer);
  1344. phba->hb_outstanding = 0;
  1345. del_timer_sync(&phba->hb_tmofunc);
  1346. return;
  1347. }
  1348. static void
  1349. lpfc_block_mgmt_io(struct lpfc_hba * phba)
  1350. {
  1351. unsigned long iflag;
  1352. spin_lock_irqsave(&phba->hbalock, iflag);
  1353. phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO;
  1354. spin_unlock_irqrestore(&phba->hbalock, iflag);
  1355. }
  1356. int
  1357. lpfc_online(struct lpfc_hba *phba)
  1358. {
  1359. struct lpfc_vport *vport = phba->pport;
  1360. struct lpfc_vport **vports;
  1361. int i;
  1362. if (!phba)
  1363. return 0;
  1364. if (!(vport->fc_flag & FC_OFFLINE_MODE))
  1365. return 0;
  1366. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  1367. "0458 Bring Adapter online\n");
  1368. lpfc_block_mgmt_io(phba);
  1369. if (!lpfc_sli_queue_setup(phba)) {
  1370. lpfc_unblock_mgmt_io(phba);
  1371. return 1;
  1372. }
  1373. if (lpfc_sli_hba_setup(phba)) { /* Initialize the HBA */
  1374. lpfc_unblock_mgmt_io(phba);
  1375. return 1;
  1376. }
  1377. vports = lpfc_create_vport_work_array(phba);
  1378. if (vports != NULL)
  1379. for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
  1380. struct Scsi_Host *shost;
  1381. shost = lpfc_shost_from_vport(vports[i]);
  1382. spin_lock_irq(shost->host_lock);
  1383. vports[i]->fc_flag &= ~FC_OFFLINE_MODE;
  1384. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
  1385. vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  1386. spin_unlock_irq(shost->host_lock);
  1387. }
  1388. lpfc_destroy_vport_work_array(phba, vports);
  1389. lpfc_unblock_mgmt_io(phba);
  1390. return 0;
  1391. }
  1392. void
  1393. lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
  1394. {
  1395. unsigned long iflag;
  1396. spin_lock_irqsave(&phba->hbalock, iflag);
  1397. phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO;
  1398. spin_unlock_irqrestore(&phba->hbalock, iflag);
  1399. }
  1400. void
  1401. lpfc_offline_prep(struct lpfc_hba * phba)
  1402. {
  1403. struct lpfc_vport *vport = phba->pport;
  1404. struct lpfc_nodelist *ndlp, *next_ndlp;
  1405. struct lpfc_vport **vports;
  1406. int i;
  1407. if (vport->fc_flag & FC_OFFLINE_MODE)
  1408. return;
  1409. lpfc_block_mgmt_io(phba);
  1410. lpfc_linkdown(phba);
  1411. /* Issue an unreg_login to all nodes on all vports */
  1412. vports = lpfc_create_vport_work_array(phba);
  1413. if (vports != NULL) {
  1414. for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
  1415. struct Scsi_Host *shost;
  1416. if (vports[i]->load_flag & FC_UNLOADING)
  1417. continue;
  1418. shost = lpfc_shost_from_vport(vports[i]);
  1419. list_for_each_entry_safe(ndlp, next_ndlp,
  1420. &vports[i]->fc_nodes,
  1421. nlp_listp) {
  1422. if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
  1423. continue;
  1424. if (ndlp->nlp_type & NLP_FABRIC) {
  1425. lpfc_disc_state_machine(vports[i], ndlp,
  1426. NULL, NLP_EVT_DEVICE_RECOVERY);
  1427. lpfc_disc_state_machine(vports[i], ndlp,
  1428. NULL, NLP_EVT_DEVICE_RM);
  1429. }
  1430. spin_lock_irq(shost->host_lock);
  1431. ndlp->nlp_flag &= ~NLP_NPR_ADISC;
  1432. spin_unlock_irq(shost->host_lock);
  1433. lpfc_unreg_rpi(vports[i], ndlp);
  1434. }
  1435. }
  1436. }
  1437. lpfc_destroy_vport_work_array(phba, vports);
  1438. lpfc_sli_flush_mbox_queue(phba);
  1439. }
  1440. void
  1441. lpfc_offline(struct lpfc_hba *phba)
  1442. {
  1443. struct Scsi_Host *shost;
  1444. struct lpfc_vport **vports;
  1445. int i;
  1446. if (phba->pport->fc_flag & FC_OFFLINE_MODE)
  1447. return;
  1448. /* stop all timers associated with this hba */
  1449. lpfc_stop_phba_timers(phba);
  1450. vports = lpfc_create_vport_work_array(phba);
  1451. if (vports != NULL)
  1452. for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++)
  1453. lpfc_stop_vport_timers(vports[i]);
  1454. lpfc_destroy_vport_work_array(phba, vports);
  1455. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  1456. "0460 Bring Adapter offline\n");
  1457. /* Bring down the SLI Layer and cleanup. The HBA is offline
  1458. now. */
  1459. lpfc_sli_hba_down(phba);
  1460. spin_lock_irq(&phba->hbalock);
  1461. phba->work_ha = 0;
  1462. spin_unlock_irq(&phba->hbalock);
  1463. vports = lpfc_create_vport_work_array(phba);
  1464. if (vports != NULL)
  1465. for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
  1466. shost = lpfc_shost_from_vport(vports[i]);
  1467. spin_lock_irq(shost->host_lock);
  1468. vports[i]->work_port_events = 0;
  1469. vports[i]->fc_flag |= FC_OFFLINE_MODE;
  1470. spin_unlock_irq(shost->host_lock);
  1471. }
  1472. lpfc_destroy_vport_work_array(phba, vports);
  1473. }
  1474. /******************************************************************************
  1475. * Function name: lpfc_scsi_free
  1476. *
  1477. * Description: Called from lpfc_pci_remove_one free internal driver resources
  1478. *
  1479. ******************************************************************************/
  1480. static int
  1481. lpfc_scsi_free(struct lpfc_hba *phba)
  1482. {
  1483. struct lpfc_scsi_buf *sb, *sb_next;
  1484. struct lpfc_iocbq *io, *io_next;
  1485. spin_lock_irq(&phba->hbalock);
  1486. /* Release all the lpfc_scsi_bufs maintained by this host. */
  1487. list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list, list) {
  1488. list_del(&sb->list);
  1489. pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data,
  1490. sb->dma_handle);
  1491. kfree(sb);
  1492. phba->total_scsi_bufs--;
  1493. }
  1494. /* Release all the lpfc_iocbq entries maintained by this host. */
  1495. list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) {
  1496. list_del(&io->list);
  1497. kfree(io);
  1498. phba->total_iocbq_bufs--;
  1499. }
  1500. spin_unlock_irq(&phba->hbalock);
  1501. return 0;
  1502. }
  1503. struct lpfc_vport *
  1504. lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
  1505. {
  1506. struct lpfc_vport *vport;
  1507. struct Scsi_Host *shost;
  1508. int error = 0;
  1509. if (dev != &phba->pcidev->dev)
  1510. shost = scsi_host_alloc(&lpfc_vport_template,
  1511. sizeof(struct lpfc_vport));
  1512. else
  1513. shost = scsi_host_alloc(&lpfc_template,
  1514. sizeof(struct lpfc_vport));
  1515. if (!shost)
  1516. goto out;
  1517. vport = (struct lpfc_vport *) shost->hostdata;
  1518. vport->phba = phba;
  1519. vport->load_flag |= FC_LOADING;
  1520. vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  1521. lpfc_get_vport_cfgparam(vport);
  1522. shost->unique_id = instance;
  1523. shost->max_id = LPFC_MAX_TARGET;
  1524. shost->max_lun = vport->cfg_max_luns;
  1525. shost->this_id = -1;
  1526. shost->max_cmd_len = 16;
  1527. /*
  1528. * Set initial can_queue value since 0 is no longer supported and
  1529. * scsi_add_host will fail. This will be adjusted later based on the
  1530. * max xri value determined in hba setup.
  1531. */
  1532. shost->can_queue = phba->cfg_hba_queue_depth - 10;
  1533. if (dev != &phba->pcidev->dev) {
  1534. shost->transportt = lpfc_vport_transport_template;
  1535. vport->port_type = LPFC_NPIV_PORT;
  1536. } else {
  1537. shost->transportt = lpfc_transport_template;
  1538. vport->port_type = LPFC_PHYSICAL_PORT;
  1539. }
  1540. /* Initialize all internally managed lists. */
  1541. INIT_LIST_HEAD(&vport->fc_nodes);
  1542. spin_lock_init(&vport->work_port_lock);
  1543. init_timer(&vport->fc_disctmo);
  1544. vport->fc_disctmo.function = lpfc_disc_timeout;
  1545. vport->fc_disctmo.data = (unsigned long)vport;
  1546. init_timer(&vport->fc_fdmitmo);
  1547. vport->fc_fdmitmo.function = lpfc_fdmi_tmo;
  1548. vport->fc_fdmitmo.data = (unsigned long)vport;
  1549. init_timer(&vport->els_tmofunc);
  1550. vport->els_tmofunc.function = lpfc_els_timeout;
  1551. vport->els_tmofunc.data = (unsigned long)vport;
  1552. error = scsi_add_host(shost, dev);
  1553. if (error)
  1554. goto out_put_shost;
  1555. spin_lock_irq(&phba->hbalock);
  1556. list_add_tail(&vport->listentry, &phba->port_list);
  1557. spin_unlock_irq(&phba->hbalock);
  1558. return vport;
  1559. out_put_shost:
  1560. scsi_host_put(shost);
  1561. out:
  1562. return NULL;
  1563. }
  1564. void
  1565. destroy_port(struct lpfc_vport *vport)
  1566. {
  1567. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1568. struct lpfc_hba *phba = vport->phba;
  1569. kfree(vport->vname);
  1570. lpfc_debugfs_terminate(vport);
  1571. fc_remove_host(shost);
  1572. scsi_remove_host(shost);
  1573. spin_lock_irq(&phba->hbalock);
  1574. list_del_init(&vport->listentry);
  1575. spin_unlock_irq(&phba->hbalock);
  1576. lpfc_cleanup(vport);
  1577. return;
  1578. }
  1579. int
  1580. lpfc_get_instance(void)
  1581. {
  1582. int instance = 0;
  1583. /* Assign an unused number */
  1584. if (!idr_pre_get(&lpfc_hba_index, GFP_KERNEL))
  1585. return -1;
  1586. if (idr_get_new(&lpfc_hba_index, NULL, &instance))
  1587. return -1;
  1588. return instance;
  1589. }
  1590. /*
  1591. * Note: there is no scan_start function as adapter initialization
  1592. * will have asynchronously kicked off the link initialization.
  1593. */
  1594. int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
  1595. {
  1596. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1597. struct lpfc_hba *phba = vport->phba;
  1598. int stat = 0;
  1599. spin_lock_irq(shost->host_lock);
  1600. if (vport->load_flag & FC_UNLOADING) {
  1601. stat = 1;
  1602. goto finished;
  1603. }
  1604. if (time >= 30 * HZ) {
  1605. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  1606. "0461 Scanning longer than 30 "
  1607. "seconds. Continuing initialization\n");
  1608. stat = 1;
  1609. goto finished;
  1610. }
  1611. if (time >= 15 * HZ && phba->link_state <= LPFC_LINK_DOWN) {
  1612. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  1613. "0465 Link down longer than 15 "
  1614. "seconds. Continuing initialization\n");
  1615. stat = 1;
  1616. goto finished;
  1617. }
  1618. if (vport->port_state != LPFC_VPORT_READY)
  1619. goto finished;
  1620. if (vport->num_disc_nodes || vport->fc_prli_sent)
  1621. goto finished;
  1622. if (vport->fc_map_cnt == 0 && time < 2 * HZ)
  1623. goto finished;
  1624. if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
  1625. goto finished;
  1626. stat = 1;
  1627. finished:
  1628. spin_unlock_irq(shost->host_lock);
  1629. return stat;
  1630. }
  1631. void lpfc_host_attrib_init(struct Scsi_Host *shost)
  1632. {
  1633. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1634. struct lpfc_hba *phba = vport->phba;
  1635. /*
  1636. * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
  1637. */
  1638. fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
  1639. fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
  1640. fc_host_supported_classes(shost) = FC_COS_CLASS3;
  1641. memset(fc_host_supported_fc4s(shost), 0,
  1642. sizeof(fc_host_supported_fc4s(shost)));
  1643. fc_host_supported_fc4s(shost)[2] = 1;
  1644. fc_host_supported_fc4s(shost)[7] = 1;
  1645. lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
  1646. sizeof fc_host_symbolic_name(shost));
  1647. fc_host_supported_speeds(shost) = 0;
  1648. if (phba->lmt & LMT_10Gb)
  1649. fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
  1650. if (phba->lmt & LMT_8Gb)
  1651. fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT;
  1652. if (phba->lmt & LMT_4Gb)
  1653. fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
  1654. if (phba->lmt & LMT_2Gb)
  1655. fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
  1656. if (phba->lmt & LMT_1Gb)
  1657. fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
  1658. fc_host_maxframe_size(shost) =
  1659. (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
  1660. (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
  1661. /* This value is also unchanging */
  1662. memset(fc_host_active_fc4s(shost), 0,
  1663. sizeof(fc_host_active_fc4s(shost)));
  1664. fc_host_active_fc4s(shost)[2] = 1;
  1665. fc_host_active_fc4s(shost)[7] = 1;
  1666. fc_host_max_npiv_vports(shost) = phba->max_vpi;
  1667. spin_lock_irq(shost->host_lock);
  1668. vport->load_flag &= ~FC_LOADING;
  1669. spin_unlock_irq(shost->host_lock);
  1670. }
  1671. static int __devinit
  1672. lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
  1673. {
  1674. struct lpfc_vport *vport = NULL;
  1675. struct lpfc_hba *phba;
  1676. struct lpfc_sli *psli;
  1677. struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
  1678. struct Scsi_Host *shost = NULL;
  1679. void *ptr;
  1680. unsigned long bar0map_len, bar2map_len;
  1681. int error = -ENODEV, retval;
  1682. int i, hbq_count;
  1683. uint16_t iotag;
  1684. if (pci_enable_device(pdev))
  1685. goto out;
  1686. if (pci_request_regions(pdev, LPFC_DRIVER_NAME))
  1687. goto out_disable_device;
  1688. phba = kzalloc(sizeof (struct lpfc_hba), GFP_KERNEL);
  1689. if (!phba)
  1690. goto out_release_regions;
  1691. spin_lock_init(&phba->hbalock);
  1692. phba->pcidev = pdev;
  1693. /* Assign an unused board number */
  1694. if ((phba->brd_no = lpfc_get_instance()) < 0)
  1695. goto out_free_phba;
  1696. INIT_LIST_HEAD(&phba->port_list);
  1697. /*
  1698. * Get all the module params for configuring this host and then
  1699. * establish the host.
  1700. */
  1701. lpfc_get_cfgparam(phba);
  1702. phba->max_vpi = LPFC_MAX_VPI;
  1703. /* Initialize timers used by driver */
  1704. init_timer(&phba->fc_estabtmo);
  1705. phba->fc_estabtmo.function = lpfc_establish_link_tmo;
  1706. phba->fc_estabtmo.data = (unsigned long)phba;
  1707. init_timer(&phba->hb_tmofunc);
  1708. phba->hb_tmofunc.function = lpfc_hb_timeout;
  1709. phba->hb_tmofunc.data = (unsigned long)phba;
  1710. psli = &phba->sli;
  1711. init_timer(&psli->mbox_tmo);
  1712. psli->mbox_tmo.function = lpfc_mbox_timeout;
  1713. psli->mbox_tmo.data = (unsigned long) phba;
  1714. init_timer(&phba->fcp_poll_timer);
  1715. phba->fcp_poll_timer.function = lpfc_poll_timeout;
  1716. phba->fcp_poll_timer.data = (unsigned long) phba;
  1717. init_timer(&phba->fabric_block_timer);
  1718. phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
  1719. phba->fabric_block_timer.data = (unsigned long) phba;
  1720. pci_set_master(pdev);
  1721. pci_try_set_mwi(pdev);
  1722. if (pci_set_dma_mask(phba->pcidev, DMA_64BIT_MASK) != 0)
  1723. if (pci_set_dma_mask(phba->pcidev, DMA_32BIT_MASK) != 0)
  1724. goto out_idr_remove;
  1725. /*
  1726. * Get the bus address of Bar0 and Bar2 and the number of bytes
  1727. * required by each mapping.
  1728. */
  1729. phba->pci_bar0_map = pci_resource_start(phba->pcidev, 0);
  1730. bar0map_len = pci_resource_len(phba->pcidev, 0);
  1731. phba->pci_bar2_map = pci_resource_start(phba->pcidev, 2);
  1732. bar2map_len = pci_resource_len(phba->pcidev, 2);
  1733. /* Map HBA SLIM to a kernel virtual address. */
  1734. phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
  1735. if (!phba->slim_memmap_p) {
  1736. error = -ENODEV;
  1737. dev_printk(KERN_ERR, &pdev->dev,
  1738. "ioremap failed for SLIM memory.\n");
  1739. goto out_idr_remove;
  1740. }
  1741. /* Map HBA Control Registers to a kernel virtual address. */
  1742. phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
  1743. if (!phba->ctrl_regs_memmap_p) {
  1744. error = -ENODEV;
  1745. dev_printk(KERN_ERR, &pdev->dev,
  1746. "ioremap failed for HBA control registers.\n");
  1747. goto out_iounmap_slim;
  1748. }
  1749. /* Allocate memory for SLI-2 structures */
  1750. phba->slim2p = dma_alloc_coherent(&phba->pcidev->dev, SLI2_SLIM_SIZE,
  1751. &phba->slim2p_mapping, GFP_KERNEL);
  1752. if (!phba->slim2p)
  1753. goto out_iounmap;
  1754. memset(phba->slim2p, 0, SLI2_SLIM_SIZE);
  1755. phba->hbqslimp.virt = dma_alloc_coherent(&phba->pcidev->dev,
  1756. lpfc_sli_hbq_size(),
  1757. &phba->hbqslimp.phys,
  1758. GFP_KERNEL);
  1759. if (!phba->hbqslimp.virt)
  1760. goto out_free_slim;
  1761. hbq_count = lpfc_sli_hbq_count();
  1762. ptr = phba->hbqslimp.virt;
  1763. for (i = 0; i < hbq_count; ++i) {
  1764. phba->hbqs[i].hbq_virt = ptr;
  1765. INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
  1766. ptr += (lpfc_hbq_defs[i]->entry_count *
  1767. sizeof(struct lpfc_hbq_entry));
  1768. }
  1769. phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc;
  1770. phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free;
  1771. memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size());
  1772. /* Initialize the SLI Layer to run with lpfc HBAs. */
  1773. lpfc_sli_setup(phba);
  1774. lpfc_sli_queue_setup(phba);
  1775. retval = lpfc_mem_alloc(phba);
  1776. if (retval) {
  1777. error = retval;
  1778. goto out_free_hbqslimp;
  1779. }
  1780. /* Initialize and populate the iocb list per host. */
  1781. INIT_LIST_HEAD(&phba->lpfc_iocb_list);
  1782. for (i = 0; i < LPFC_IOCB_LIST_CNT; i++) {
  1783. iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
  1784. if (iocbq_entry == NULL) {
  1785. printk(KERN_ERR "%s: only allocated %d iocbs of "
  1786. "expected %d count. Unloading driver.\n",
  1787. __FUNCTION__, i, LPFC_IOCB_LIST_CNT);
  1788. error = -ENOMEM;
  1789. goto out_free_iocbq;
  1790. }
  1791. iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
  1792. if (iotag == 0) {
  1793. kfree (iocbq_entry);
  1794. printk(KERN_ERR "%s: failed to allocate IOTAG. "
  1795. "Unloading driver.\n",
  1796. __FUNCTION__);
  1797. error = -ENOMEM;
  1798. goto out_free_iocbq;
  1799. }
  1800. spin_lock_irq(&phba->hbalock);
  1801. list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
  1802. phba->total_iocbq_bufs++;
  1803. spin_unlock_irq(&phba->hbalock);
  1804. }
  1805. /* Initialize HBA structure */
  1806. phba->fc_edtov = FF_DEF_EDTOV;
  1807. phba->fc_ratov = FF_DEF_RATOV;
  1808. phba->fc_altov = FF_DEF_ALTOV;
  1809. phba->fc_arbtov = FF_DEF_ARBTOV;
  1810. INIT_LIST_HEAD(&phba->work_list);
  1811. phba->work_ha_mask = (HA_ERATT|HA_MBATT|HA_LATT);
  1812. phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
  1813. /* Startup the kernel thread for this host adapter. */
  1814. phba->worker_thread = kthread_run(lpfc_do_work, phba,
  1815. "lpfc_worker_%d", phba->brd_no);
  1816. if (IS_ERR(phba->worker_thread)) {
  1817. error = PTR_ERR(phba->worker_thread);
  1818. goto out_free_iocbq;
  1819. }
  1820. /* Initialize the list of scsi buffers used by driver for scsi IO. */
  1821. spin_lock_init(&phba->scsi_buf_list_lock);
  1822. INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list);
  1823. /* Initialize list of fabric iocbs */
  1824. INIT_LIST_HEAD(&phba->fabric_iocb_list);
  1825. /* Initialize list to save ELS buffers */
  1826. INIT_LIST_HEAD(&phba->elsbuf);
  1827. vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev);
  1828. if (!vport)
  1829. goto out_kthread_stop;
  1830. shost = lpfc_shost_from_vport(vport);
  1831. phba->pport = vport;
  1832. lpfc_debugfs_initialize(vport);
  1833. pci_set_drvdata(pdev, shost);
  1834. if (phba->cfg_use_msi) {
  1835. retval = pci_enable_msi(phba->pcidev);
  1836. if (!retval)
  1837. phba->using_msi = 1;
  1838. else
  1839. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  1840. "0452 Enable MSI failed, continuing "
  1841. "with IRQ\n");
  1842. }
  1843. retval = request_irq(phba->pcidev->irq, lpfc_intr_handler, IRQF_SHARED,
  1844. LPFC_DRIVER_NAME, phba);
  1845. if (retval) {
  1846. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1847. "0451 Enable interrupt handler failed\n");
  1848. error = retval;
  1849. goto out_disable_msi;
  1850. }
  1851. phba->MBslimaddr = phba->slim_memmap_p;
  1852. phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
  1853. phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
  1854. phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
  1855. phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
  1856. if (lpfc_alloc_sysfs_attr(vport)) {
  1857. error = -ENOMEM;
  1858. goto out_free_irq;
  1859. }
  1860. if (lpfc_sli_hba_setup(phba)) {
  1861. error = -ENODEV;
  1862. goto out_remove_device;
  1863. }
  1864. /*
  1865. * hba setup may have changed the hba_queue_depth so we need to adjust
  1866. * the value of can_queue.
  1867. */
  1868. shost->can_queue = phba->cfg_hba_queue_depth - 10;
  1869. lpfc_host_attrib_init(shost);
  1870. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  1871. spin_lock_irq(shost->host_lock);
  1872. lpfc_poll_start_timer(phba);
  1873. spin_unlock_irq(shost->host_lock);
  1874. }
  1875. scsi_scan_host(shost);
  1876. return 0;
  1877. out_remove_device:
  1878. lpfc_free_sysfs_attr(vport);
  1879. spin_lock_irq(shost->host_lock);
  1880. vport->load_flag |= FC_UNLOADING;
  1881. spin_unlock_irq(shost->host_lock);
  1882. out_free_irq:
  1883. lpfc_stop_phba_timers(phba);
  1884. phba->pport->work_port_events = 0;
  1885. free_irq(phba->pcidev->irq, phba);
  1886. out_disable_msi:
  1887. if (phba->using_msi)
  1888. pci_disable_msi(phba->pcidev);
  1889. destroy_port(vport);
  1890. out_kthread_stop:
  1891. kthread_stop(phba->worker_thread);
  1892. out_free_iocbq:
  1893. list_for_each_entry_safe(iocbq_entry, iocbq_next,
  1894. &phba->lpfc_iocb_list, list) {
  1895. kfree(iocbq_entry);
  1896. phba->total_iocbq_bufs--;
  1897. }
  1898. lpfc_mem_free(phba);
  1899. out_free_hbqslimp:
  1900. dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), phba->hbqslimp.virt,
  1901. phba->hbqslimp.phys);
  1902. out_free_slim:
  1903. dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, phba->slim2p,
  1904. phba->slim2p_mapping);
  1905. out_iounmap:
  1906. iounmap(phba->ctrl_regs_memmap_p);
  1907. out_iounmap_slim:
  1908. iounmap(phba->slim_memmap_p);
  1909. out_idr_remove:
  1910. idr_remove(&lpfc_hba_index, phba->brd_no);
  1911. out_free_phba:
  1912. kfree(phba);
  1913. out_release_regions:
  1914. pci_release_regions(pdev);
  1915. out_disable_device:
  1916. pci_disable_device(pdev);
  1917. out:
  1918. pci_set_drvdata(pdev, NULL);
  1919. if (shost)
  1920. scsi_host_put(shost);
  1921. return error;
  1922. }
  1923. static void __devexit
  1924. lpfc_pci_remove_one(struct pci_dev *pdev)
  1925. {
  1926. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  1927. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1928. struct lpfc_hba *phba = vport->phba;
  1929. spin_lock_irq(&phba->hbalock);
  1930. vport->load_flag |= FC_UNLOADING;
  1931. spin_unlock_irq(&phba->hbalock);
  1932. kfree(vport->vname);
  1933. lpfc_free_sysfs_attr(vport);
  1934. kthread_stop(phba->worker_thread);
  1935. fc_remove_host(shost);
  1936. scsi_remove_host(shost);
  1937. lpfc_cleanup(vport);
  1938. /*
  1939. * Bring down the SLI Layer. This step disable all interrupts,
  1940. * clears the rings, discards all mailbox commands, and resets
  1941. * the HBA.
  1942. */
  1943. lpfc_sli_hba_down(phba);
  1944. lpfc_sli_brdrestart(phba);
  1945. lpfc_stop_phba_timers(phba);
  1946. spin_lock_irq(&phba->hbalock);
  1947. list_del_init(&vport->listentry);
  1948. spin_unlock_irq(&phba->hbalock);
  1949. lpfc_debugfs_terminate(vport);
  1950. /* Release the irq reservation */
  1951. free_irq(phba->pcidev->irq, phba);
  1952. if (phba->using_msi)
  1953. pci_disable_msi(phba->pcidev);
  1954. pci_set_drvdata(pdev, NULL);
  1955. scsi_host_put(shost);
  1956. /*
  1957. * Call scsi_free before mem_free since scsi bufs are released to their
  1958. * corresponding pools here.
  1959. */
  1960. lpfc_scsi_free(phba);
  1961. lpfc_mem_free(phba);
  1962. dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), phba->hbqslimp.virt,
  1963. phba->hbqslimp.phys);
  1964. /* Free resources associated with SLI2 interface */
  1965. dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
  1966. phba->slim2p, phba->slim2p_mapping);
  1967. /* unmap adapter SLIM and Control Registers */
  1968. iounmap(phba->ctrl_regs_memmap_p);
  1969. iounmap(phba->slim_memmap_p);
  1970. idr_remove(&lpfc_hba_index, phba->brd_no);
  1971. kfree(phba);
  1972. pci_release_regions(pdev);
  1973. pci_disable_device(pdev);
  1974. }
  1975. /**
  1976. * lpfc_io_error_detected - called when PCI error is detected
  1977. * @pdev: Pointer to PCI device
  1978. * @state: The current pci conneection state
  1979. *
  1980. * This function is called after a PCI bus error affecting
  1981. * this device has been detected.
  1982. */
  1983. static pci_ers_result_t lpfc_io_error_detected(struct pci_dev *pdev,
  1984. pci_channel_state_t state)
  1985. {
  1986. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  1987. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  1988. struct lpfc_sli *psli = &phba->sli;
  1989. struct lpfc_sli_ring *pring;
  1990. if (state == pci_channel_io_perm_failure)
  1991. return PCI_ERS_RESULT_DISCONNECT;
  1992. pci_disable_device(pdev);
  1993. /*
  1994. * There may be I/Os dropped by the firmware.
  1995. * Error iocb (I/O) on txcmplq and let the SCSI layer
  1996. * retry it after re-establishing link.
  1997. */
  1998. pring = &psli->ring[psli->fcp_ring];
  1999. lpfc_sli_abort_iocb_ring(phba, pring);
  2000. /* Release the irq reservation */
  2001. free_irq(phba->pcidev->irq, phba);
  2002. if (phba->using_msi)
  2003. pci_disable_msi(phba->pcidev);
  2004. /* Request a slot reset. */
  2005. return PCI_ERS_RESULT_NEED_RESET;
  2006. }
  2007. /**
  2008. * lpfc_io_slot_reset - called after the pci bus has been reset.
  2009. * @pdev: Pointer to PCI device
  2010. *
  2011. * Restart the card from scratch, as if from a cold-boot.
  2012. */
  2013. static pci_ers_result_t lpfc_io_slot_reset(struct pci_dev *pdev)
  2014. {
  2015. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  2016. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  2017. struct lpfc_sli *psli = &phba->sli;
  2018. int bars = pci_select_bars(pdev, IORESOURCE_MEM);
  2019. dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
  2020. if (pci_enable_device_bars(pdev, bars)) {
  2021. printk(KERN_ERR "lpfc: Cannot re-enable "
  2022. "PCI device after reset.\n");
  2023. return PCI_ERS_RESULT_DISCONNECT;
  2024. }
  2025. pci_set_master(pdev);
  2026. /* Re-establishing Link */
  2027. spin_lock_irq(shost->host_lock);
  2028. phba->pport->fc_flag |= FC_ESTABLISH_LINK;
  2029. spin_unlock_irq(shost->host_lock);
  2030. spin_lock_irq(&phba->hbalock);
  2031. psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
  2032. spin_unlock_irq(&phba->hbalock);
  2033. /* Take device offline; this will perform cleanup */
  2034. lpfc_offline(phba);
  2035. lpfc_sli_brdrestart(phba);
  2036. return PCI_ERS_RESULT_RECOVERED;
  2037. }
  2038. /**
  2039. * lpfc_io_resume - called when traffic can start flowing again.
  2040. * @pdev: Pointer to PCI device
  2041. *
  2042. * This callback is called when the error recovery driver tells us that
  2043. * its OK to resume normal operation.
  2044. */
  2045. static void lpfc_io_resume(struct pci_dev *pdev)
  2046. {
  2047. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  2048. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  2049. if (lpfc_online(phba) == 0) {
  2050. mod_timer(&phba->fc_estabtmo, jiffies + HZ * 60);
  2051. }
  2052. }
  2053. static struct pci_device_id lpfc_id_table[] = {
  2054. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER,
  2055. PCI_ANY_ID, PCI_ANY_ID, },
  2056. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY,
  2057. PCI_ANY_ID, PCI_ANY_ID, },
  2058. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR,
  2059. PCI_ANY_ID, PCI_ANY_ID, },
  2060. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS,
  2061. PCI_ANY_ID, PCI_ANY_ID, },
  2062. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR,
  2063. PCI_ANY_ID, PCI_ANY_ID, },
  2064. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY,
  2065. PCI_ANY_ID, PCI_ANY_ID, },
  2066. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY,
  2067. PCI_ANY_ID, PCI_ANY_ID, },
  2068. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY,
  2069. PCI_ANY_ID, PCI_ANY_ID, },
  2070. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY,
  2071. PCI_ANY_ID, PCI_ANY_ID, },
  2072. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE,
  2073. PCI_ANY_ID, PCI_ANY_ID, },
  2074. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP,
  2075. PCI_ANY_ID, PCI_ANY_ID, },
  2076. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP,
  2077. PCI_ANY_ID, PCI_ANY_ID, },
  2078. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS,
  2079. PCI_ANY_ID, PCI_ANY_ID, },
  2080. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP,
  2081. PCI_ANY_ID, PCI_ANY_ID, },
  2082. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP,
  2083. PCI_ANY_ID, PCI_ANY_ID, },
  2084. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID,
  2085. PCI_ANY_ID, PCI_ANY_ID, },
  2086. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB,
  2087. PCI_ANY_ID, PCI_ANY_ID, },
  2088. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR,
  2089. PCI_ANY_ID, PCI_ANY_ID, },
  2090. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP,
  2091. PCI_ANY_ID, PCI_ANY_ID, },
  2092. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP,
  2093. PCI_ANY_ID, PCI_ANY_ID, },
  2094. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID,
  2095. PCI_ANY_ID, PCI_ANY_ID, },
  2096. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB,
  2097. PCI_ANY_ID, PCI_ANY_ID, },
  2098. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY,
  2099. PCI_ANY_ID, PCI_ANY_ID, },
  2100. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101,
  2101. PCI_ANY_ID, PCI_ANY_ID, },
  2102. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S,
  2103. PCI_ANY_ID, PCI_ANY_ID, },
  2104. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S,
  2105. PCI_ANY_ID, PCI_ANY_ID, },
  2106. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S,
  2107. PCI_ANY_ID, PCI_ANY_ID, },
  2108. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT,
  2109. PCI_ANY_ID, PCI_ANY_ID, },
  2110. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID,
  2111. PCI_ANY_ID, PCI_ANY_ID, },
  2112. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB,
  2113. PCI_ANY_ID, PCI_ANY_ID, },
  2114. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP,
  2115. PCI_ANY_ID, PCI_ANY_ID, },
  2116. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP,
  2117. PCI_ANY_ID, PCI_ANY_ID, },
  2118. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S,
  2119. PCI_ANY_ID, PCI_ANY_ID, },
  2120. { 0 }
  2121. };
  2122. MODULE_DEVICE_TABLE(pci, lpfc_id_table);
  2123. static struct pci_error_handlers lpfc_err_handler = {
  2124. .error_detected = lpfc_io_error_detected,
  2125. .slot_reset = lpfc_io_slot_reset,
  2126. .resume = lpfc_io_resume,
  2127. };
  2128. static struct pci_driver lpfc_driver = {
  2129. .name = LPFC_DRIVER_NAME,
  2130. .id_table = lpfc_id_table,
  2131. .probe = lpfc_pci_probe_one,
  2132. .remove = __devexit_p(lpfc_pci_remove_one),
  2133. .err_handler = &lpfc_err_handler,
  2134. };
  2135. static int __init
  2136. lpfc_init(void)
  2137. {
  2138. int error = 0;
  2139. printk(LPFC_MODULE_DESC "\n");
  2140. printk(LPFC_COPYRIGHT "\n");
  2141. if (lpfc_enable_npiv) {
  2142. lpfc_transport_functions.vport_create = lpfc_vport_create;
  2143. lpfc_transport_functions.vport_delete = lpfc_vport_delete;
  2144. }
  2145. lpfc_transport_template =
  2146. fc_attach_transport(&lpfc_transport_functions);
  2147. if (lpfc_transport_template == NULL)
  2148. return -ENOMEM;
  2149. if (lpfc_enable_npiv) {
  2150. lpfc_vport_transport_template =
  2151. fc_attach_transport(&lpfc_vport_transport_functions);
  2152. if (lpfc_vport_transport_template == NULL) {
  2153. fc_release_transport(lpfc_transport_template);
  2154. return -ENOMEM;
  2155. }
  2156. }
  2157. error = pci_register_driver(&lpfc_driver);
  2158. if (error) {
  2159. fc_release_transport(lpfc_transport_template);
  2160. fc_release_transport(lpfc_vport_transport_template);
  2161. }
  2162. return error;
  2163. }
  2164. static void __exit
  2165. lpfc_exit(void)
  2166. {
  2167. pci_unregister_driver(&lpfc_driver);
  2168. fc_release_transport(lpfc_transport_template);
  2169. if (lpfc_enable_npiv)
  2170. fc_release_transport(lpfc_vport_transport_template);
  2171. }
  2172. module_init(lpfc_init);
  2173. module_exit(lpfc_exit);
  2174. MODULE_LICENSE("GPL");
  2175. MODULE_DESCRIPTION(LPFC_MODULE_DESC);
  2176. MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com");
  2177. MODULE_VERSION("0:" LPFC_DRIVER_VERSION);