lpfc_init.c 90 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2008 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_nl.h"
  37. #include "lpfc_disc.h"
  38. #include "lpfc_scsi.h"
  39. #include "lpfc.h"
  40. #include "lpfc_logmsg.h"
  41. #include "lpfc_crtn.h"
  42. #include "lpfc_vport.h"
  43. #include "lpfc_version.h"
  44. static int lpfc_parse_vpd(struct lpfc_hba *, uint8_t *, int);
  45. static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *);
  46. static int lpfc_post_rcv_buf(struct lpfc_hba *);
  47. static struct scsi_transport_template *lpfc_transport_template = NULL;
  48. static struct scsi_transport_template *lpfc_vport_transport_template = NULL;
  49. static DEFINE_IDR(lpfc_hba_index);
  50. /**
  51. * lpfc_config_port_prep: Perform lpfc initialization prior to config port.
  52. * @phba: pointer to lpfc hba data structure.
  53. *
  54. * This routine will do LPFC initialization prior to issuing the CONFIG_PORT
  55. * mailbox command. It retrieves the revision information from the HBA and
  56. * collects the Vital Product Data (VPD) about the HBA for preparing the
  57. * configuration of the HBA.
  58. *
  59. * Return codes:
  60. * 0 - success.
  61. * -ERESTART - requests the SLI layer to reset the HBA and try again.
  62. * Any other value - indicates an error.
  63. **/
  64. int
  65. lpfc_config_port_prep(struct lpfc_hba *phba)
  66. {
  67. lpfc_vpd_t *vp = &phba->vpd;
  68. int i = 0, rc;
  69. LPFC_MBOXQ_t *pmb;
  70. MAILBOX_t *mb;
  71. char *lpfc_vpd_data = NULL;
  72. uint16_t offset = 0;
  73. static char licensed[56] =
  74. "key unlock for use with gnu public licensed code only\0";
  75. static int init_key = 1;
  76. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  77. if (!pmb) {
  78. phba->link_state = LPFC_HBA_ERROR;
  79. return -ENOMEM;
  80. }
  81. mb = &pmb->mb;
  82. phba->link_state = LPFC_INIT_MBX_CMDS;
  83. if (lpfc_is_LC_HBA(phba->pcidev->device)) {
  84. if (init_key) {
  85. uint32_t *ptext = (uint32_t *) licensed;
  86. for (i = 0; i < 56; i += sizeof (uint32_t), ptext++)
  87. *ptext = cpu_to_be32(*ptext);
  88. init_key = 0;
  89. }
  90. lpfc_read_nv(phba, pmb);
  91. memset((char*)mb->un.varRDnvp.rsvd3, 0,
  92. sizeof (mb->un.varRDnvp.rsvd3));
  93. memcpy((char*)mb->un.varRDnvp.rsvd3, licensed,
  94. sizeof (licensed));
  95. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  96. if (rc != MBX_SUCCESS) {
  97. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  98. "0324 Config Port initialization "
  99. "error, mbxCmd x%x READ_NVPARM, "
  100. "mbxStatus x%x\n",
  101. mb->mbxCommand, mb->mbxStatus);
  102. mempool_free(pmb, phba->mbox_mem_pool);
  103. return -ERESTART;
  104. }
  105. memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename,
  106. sizeof(phba->wwnn));
  107. memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname,
  108. sizeof(phba->wwpn));
  109. }
  110. phba->sli3_options = 0x0;
  111. /* Setup and issue mailbox READ REV command */
  112. lpfc_read_rev(phba, pmb);
  113. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  114. if (rc != MBX_SUCCESS) {
  115. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  116. "0439 Adapter failed to init, mbxCmd x%x "
  117. "READ_REV, mbxStatus x%x\n",
  118. mb->mbxCommand, mb->mbxStatus);
  119. mempool_free( pmb, phba->mbox_mem_pool);
  120. return -ERESTART;
  121. }
  122. /*
  123. * The value of rr must be 1 since the driver set the cv field to 1.
  124. * This setting requires the FW to set all revision fields.
  125. */
  126. if (mb->un.varRdRev.rr == 0) {
  127. vp->rev.rBit = 0;
  128. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  129. "0440 Adapter failed to init, READ_REV has "
  130. "missing revision information.\n");
  131. mempool_free(pmb, phba->mbox_mem_pool);
  132. return -ERESTART;
  133. }
  134. if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) {
  135. mempool_free(pmb, phba->mbox_mem_pool);
  136. return -EINVAL;
  137. }
  138. /* Save information as VPD data */
  139. vp->rev.rBit = 1;
  140. memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t));
  141. vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev;
  142. memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16);
  143. vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev;
  144. memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16);
  145. vp->rev.biuRev = mb->un.varRdRev.biuRev;
  146. vp->rev.smRev = mb->un.varRdRev.smRev;
  147. vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev;
  148. vp->rev.endecRev = mb->un.varRdRev.endecRev;
  149. vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh;
  150. vp->rev.fcphLow = mb->un.varRdRev.fcphLow;
  151. vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh;
  152. vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow;
  153. vp->rev.postKernRev = mb->un.varRdRev.postKernRev;
  154. vp->rev.opFwRev = mb->un.varRdRev.opFwRev;
  155. /* If the sli feature level is less then 9, we must
  156. * tear down all RPIs and VPIs on link down if NPIV
  157. * is enabled.
  158. */
  159. if (vp->rev.feaLevelHigh < 9)
  160. phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN;
  161. if (lpfc_is_LC_HBA(phba->pcidev->device))
  162. memcpy(phba->RandomData, (char *)&mb->un.varWords[24],
  163. sizeof (phba->RandomData));
  164. /* Get adapter VPD information */
  165. lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL);
  166. if (!lpfc_vpd_data)
  167. goto out_free_mbox;
  168. do {
  169. lpfc_dump_mem(phba, pmb, offset);
  170. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  171. if (rc != MBX_SUCCESS) {
  172. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  173. "0441 VPD not present on adapter, "
  174. "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
  175. mb->mbxCommand, mb->mbxStatus);
  176. mb->un.varDmp.word_cnt = 0;
  177. }
  178. if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset)
  179. mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset;
  180. lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
  181. lpfc_vpd_data + offset,
  182. mb->un.varDmp.word_cnt);
  183. offset += mb->un.varDmp.word_cnt;
  184. } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE);
  185. lpfc_parse_vpd(phba, lpfc_vpd_data, offset);
  186. kfree(lpfc_vpd_data);
  187. out_free_mbox:
  188. mempool_free(pmb, phba->mbox_mem_pool);
  189. return 0;
  190. }
  191. /**
  192. * lpfc_config_async_cmpl: Completion handler for config async event mbox cmd.
  193. * @phba: pointer to lpfc hba data structure.
  194. * @pmboxq: pointer to the driver internal queue element for mailbox command.
  195. *
  196. * This is the completion handler for driver's configuring asynchronous event
  197. * mailbox command to the device. If the mailbox command returns successfully,
  198. * it will set internal async event support flag to 1; otherwise, it will
  199. * set internal async event support flag to 0.
  200. **/
  201. static void
  202. lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
  203. {
  204. if (pmboxq->mb.mbxStatus == MBX_SUCCESS)
  205. phba->temp_sensor_support = 1;
  206. else
  207. phba->temp_sensor_support = 0;
  208. mempool_free(pmboxq, phba->mbox_mem_pool);
  209. return;
  210. }
  211. /**
  212. * lpfc_config_port_post: Perform lpfc initialization after config port.
  213. * @phba: pointer to lpfc hba data structure.
  214. *
  215. * This routine will do LPFC initialization after the CONFIG_PORT mailbox
  216. * command call. It performs all internal resource and state setups on the
  217. * port: post IOCB buffers, enable appropriate host interrupt attentions,
  218. * ELS ring timers, etc.
  219. *
  220. * Return codes
  221. * 0 - success.
  222. * Any other value - error.
  223. **/
  224. int
  225. lpfc_config_port_post(struct lpfc_hba *phba)
  226. {
  227. struct lpfc_vport *vport = phba->pport;
  228. LPFC_MBOXQ_t *pmb;
  229. MAILBOX_t *mb;
  230. struct lpfc_dmabuf *mp;
  231. struct lpfc_sli *psli = &phba->sli;
  232. uint32_t status, timeout;
  233. int i, j;
  234. int rc;
  235. spin_lock_irq(&phba->hbalock);
  236. /*
  237. * If the Config port completed correctly the HBA is not
  238. * over heated any more.
  239. */
  240. if (phba->over_temp_state == HBA_OVER_TEMP)
  241. phba->over_temp_state = HBA_NORMAL_TEMP;
  242. spin_unlock_irq(&phba->hbalock);
  243. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  244. if (!pmb) {
  245. phba->link_state = LPFC_HBA_ERROR;
  246. return -ENOMEM;
  247. }
  248. mb = &pmb->mb;
  249. /* Get login parameters for NID. */
  250. lpfc_read_sparam(phba, pmb, 0);
  251. pmb->vport = vport;
  252. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  253. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  254. "0448 Adapter failed init, mbxCmd x%x "
  255. "READ_SPARM mbxStatus x%x\n",
  256. mb->mbxCommand, mb->mbxStatus);
  257. phba->link_state = LPFC_HBA_ERROR;
  258. mp = (struct lpfc_dmabuf *) pmb->context1;
  259. mempool_free( pmb, phba->mbox_mem_pool);
  260. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  261. kfree(mp);
  262. return -EIO;
  263. }
  264. mp = (struct lpfc_dmabuf *) pmb->context1;
  265. memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm));
  266. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  267. kfree(mp);
  268. pmb->context1 = NULL;
  269. if (phba->cfg_soft_wwnn)
  270. u64_to_wwn(phba->cfg_soft_wwnn,
  271. vport->fc_sparam.nodeName.u.wwn);
  272. if (phba->cfg_soft_wwpn)
  273. u64_to_wwn(phba->cfg_soft_wwpn,
  274. vport->fc_sparam.portName.u.wwn);
  275. memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
  276. sizeof (struct lpfc_name));
  277. memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
  278. sizeof (struct lpfc_name));
  279. /* If no serial number in VPD data, use low 6 bytes of WWNN */
  280. /* This should be consolidated into parse_vpd ? - mr */
  281. if (phba->SerialNumber[0] == 0) {
  282. uint8_t *outptr;
  283. outptr = &vport->fc_nodename.u.s.IEEE[0];
  284. for (i = 0; i < 12; i++) {
  285. status = *outptr++;
  286. j = ((status & 0xf0) >> 4);
  287. if (j <= 9)
  288. phba->SerialNumber[i] =
  289. (char)((uint8_t) 0x30 + (uint8_t) j);
  290. else
  291. phba->SerialNumber[i] =
  292. (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
  293. i++;
  294. j = (status & 0xf);
  295. if (j <= 9)
  296. phba->SerialNumber[i] =
  297. (char)((uint8_t) 0x30 + (uint8_t) j);
  298. else
  299. phba->SerialNumber[i] =
  300. (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
  301. }
  302. }
  303. lpfc_read_config(phba, pmb);
  304. pmb->vport = vport;
  305. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  306. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  307. "0453 Adapter failed to init, mbxCmd x%x "
  308. "READ_CONFIG, mbxStatus x%x\n",
  309. mb->mbxCommand, mb->mbxStatus);
  310. phba->link_state = LPFC_HBA_ERROR;
  311. mempool_free( pmb, phba->mbox_mem_pool);
  312. return -EIO;
  313. }
  314. /* Reset the DFT_HBA_Q_DEPTH to the max xri */
  315. if (phba->cfg_hba_queue_depth > (mb->un.varRdConfig.max_xri+1))
  316. phba->cfg_hba_queue_depth =
  317. mb->un.varRdConfig.max_xri + 1;
  318. phba->lmt = mb->un.varRdConfig.lmt;
  319. /* Get the default values for Model Name and Description */
  320. lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
  321. if ((phba->cfg_link_speed > LINK_SPEED_10G)
  322. || ((phba->cfg_link_speed == LINK_SPEED_1G)
  323. && !(phba->lmt & LMT_1Gb))
  324. || ((phba->cfg_link_speed == LINK_SPEED_2G)
  325. && !(phba->lmt & LMT_2Gb))
  326. || ((phba->cfg_link_speed == LINK_SPEED_4G)
  327. && !(phba->lmt & LMT_4Gb))
  328. || ((phba->cfg_link_speed == LINK_SPEED_8G)
  329. && !(phba->lmt & LMT_8Gb))
  330. || ((phba->cfg_link_speed == LINK_SPEED_10G)
  331. && !(phba->lmt & LMT_10Gb))) {
  332. /* Reset link speed to auto */
  333. lpfc_printf_log(phba, KERN_WARNING, LOG_LINK_EVENT,
  334. "1302 Invalid speed for this board: "
  335. "Reset link speed to auto: x%x\n",
  336. phba->cfg_link_speed);
  337. phba->cfg_link_speed = LINK_SPEED_AUTO;
  338. }
  339. phba->link_state = LPFC_LINK_DOWN;
  340. /* Only process IOCBs on ELS ring till hba_state is READY */
  341. if (psli->ring[psli->extra_ring].cmdringaddr)
  342. psli->ring[psli->extra_ring].flag |= LPFC_STOP_IOCB_EVENT;
  343. if (psli->ring[psli->fcp_ring].cmdringaddr)
  344. psli->ring[psli->fcp_ring].flag |= LPFC_STOP_IOCB_EVENT;
  345. if (psli->ring[psli->next_ring].cmdringaddr)
  346. psli->ring[psli->next_ring].flag |= LPFC_STOP_IOCB_EVENT;
  347. /* Post receive buffers for desired rings */
  348. if (phba->sli_rev != 3)
  349. lpfc_post_rcv_buf(phba);
  350. /*
  351. * Configure HBA MSI-X attention conditions to messages if MSI-X mode
  352. */
  353. if (phba->intr_type == MSIX) {
  354. rc = lpfc_config_msi(phba, pmb);
  355. if (rc) {
  356. mempool_free(pmb, phba->mbox_mem_pool);
  357. return -EIO;
  358. }
  359. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  360. if (rc != MBX_SUCCESS) {
  361. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  362. "0352 Config MSI mailbox command "
  363. "failed, mbxCmd x%x, mbxStatus x%x\n",
  364. pmb->mb.mbxCommand, pmb->mb.mbxStatus);
  365. mempool_free(pmb, phba->mbox_mem_pool);
  366. return -EIO;
  367. }
  368. }
  369. /* Initialize ERATT handling flag */
  370. phba->hba_flag &= ~HBA_ERATT_HANDLED;
  371. /* Enable appropriate host interrupts */
  372. spin_lock_irq(&phba->hbalock);
  373. status = readl(phba->HCregaddr);
  374. status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA;
  375. if (psli->num_rings > 0)
  376. status |= HC_R0INT_ENA;
  377. if (psli->num_rings > 1)
  378. status |= HC_R1INT_ENA;
  379. if (psli->num_rings > 2)
  380. status |= HC_R2INT_ENA;
  381. if (psli->num_rings > 3)
  382. status |= HC_R3INT_ENA;
  383. if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) &&
  384. (phba->cfg_poll & DISABLE_FCP_RING_INT))
  385. status &= ~(HC_R0INT_ENA);
  386. writel(status, phba->HCregaddr);
  387. readl(phba->HCregaddr); /* flush */
  388. spin_unlock_irq(&phba->hbalock);
  389. /* Set up ring-0 (ELS) timer */
  390. timeout = phba->fc_ratov * 2;
  391. mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
  392. /* Set up heart beat (HB) timer */
  393. mod_timer(&phba->hb_tmofunc, jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  394. phba->hb_outstanding = 0;
  395. phba->last_completion_time = jiffies;
  396. /* Set up error attention (ERATT) polling timer */
  397. mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL);
  398. lpfc_init_link(phba, pmb, phba->cfg_topology, phba->cfg_link_speed);
  399. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  400. lpfc_set_loopback_flag(phba);
  401. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  402. if (rc != MBX_SUCCESS) {
  403. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  404. "0454 Adapter failed to init, mbxCmd x%x "
  405. "INIT_LINK, mbxStatus x%x\n",
  406. mb->mbxCommand, mb->mbxStatus);
  407. /* Clear all interrupt enable conditions */
  408. writel(0, phba->HCregaddr);
  409. readl(phba->HCregaddr); /* flush */
  410. /* Clear all pending interrupts */
  411. writel(0xffffffff, phba->HAregaddr);
  412. readl(phba->HAregaddr); /* flush */
  413. phba->link_state = LPFC_HBA_ERROR;
  414. if (rc != MBX_BUSY)
  415. mempool_free(pmb, phba->mbox_mem_pool);
  416. return -EIO;
  417. }
  418. /* MBOX buffer will be freed in mbox compl */
  419. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  420. lpfc_config_async(phba, pmb, LPFC_ELS_RING);
  421. pmb->mbox_cmpl = lpfc_config_async_cmpl;
  422. pmb->vport = phba->pport;
  423. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  424. if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
  425. lpfc_printf_log(phba,
  426. KERN_ERR,
  427. LOG_INIT,
  428. "0456 Adapter failed to issue "
  429. "ASYNCEVT_ENABLE mbox status x%x \n.",
  430. rc);
  431. mempool_free(pmb, phba->mbox_mem_pool);
  432. }
  433. return 0;
  434. }
  435. /**
  436. * lpfc_hba_down_prep: Perform lpfc uninitialization prior to HBA reset.
  437. * @phba: pointer to lpfc HBA data structure.
  438. *
  439. * This routine will do LPFC uninitialization before the HBA is reset when
  440. * bringing down the SLI Layer.
  441. *
  442. * Return codes
  443. * 0 - success.
  444. * Any other value - error.
  445. **/
  446. int
  447. lpfc_hba_down_prep(struct lpfc_hba *phba)
  448. {
  449. struct lpfc_vport **vports;
  450. int i;
  451. /* Disable interrupts */
  452. writel(0, phba->HCregaddr);
  453. readl(phba->HCregaddr); /* flush */
  454. if (phba->pport->load_flag & FC_UNLOADING)
  455. lpfc_cleanup_discovery_resources(phba->pport);
  456. else {
  457. vports = lpfc_create_vport_work_array(phba);
  458. if (vports != NULL)
  459. for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++)
  460. lpfc_cleanup_discovery_resources(vports[i]);
  461. lpfc_destroy_vport_work_array(phba, vports);
  462. }
  463. return 0;
  464. }
  465. /**
  466. * lpfc_hba_down_post: Perform lpfc uninitialization after HBA reset.
  467. * @phba: pointer to lpfc HBA data structure.
  468. *
  469. * This routine will do uninitialization after the HBA is reset when bring
  470. * down the SLI Layer.
  471. *
  472. * Return codes
  473. * 0 - sucess.
  474. * Any other value - error.
  475. **/
  476. int
  477. lpfc_hba_down_post(struct lpfc_hba *phba)
  478. {
  479. struct lpfc_sli *psli = &phba->sli;
  480. struct lpfc_sli_ring *pring;
  481. struct lpfc_dmabuf *mp, *next_mp;
  482. struct lpfc_iocbq *iocb;
  483. IOCB_t *cmd = NULL;
  484. LIST_HEAD(completions);
  485. int i;
  486. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
  487. lpfc_sli_hbqbuf_free_all(phba);
  488. else {
  489. /* Cleanup preposted buffers on the ELS ring */
  490. pring = &psli->ring[LPFC_ELS_RING];
  491. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  492. list_del(&mp->list);
  493. pring->postbufq_cnt--;
  494. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  495. kfree(mp);
  496. }
  497. }
  498. spin_lock_irq(&phba->hbalock);
  499. for (i = 0; i < psli->num_rings; i++) {
  500. pring = &psli->ring[i];
  501. /* At this point in time the HBA is either reset or DOA. Either
  502. * way, nothing should be on txcmplq as it will NEVER complete.
  503. */
  504. list_splice_init(&pring->txcmplq, &completions);
  505. pring->txcmplq_cnt = 0;
  506. spin_unlock_irq(&phba->hbalock);
  507. while (!list_empty(&completions)) {
  508. iocb = list_get_first(&completions, struct lpfc_iocbq,
  509. list);
  510. cmd = &iocb->iocb;
  511. list_del_init(&iocb->list);
  512. if (!iocb->iocb_cmpl)
  513. lpfc_sli_release_iocbq(phba, iocb);
  514. else {
  515. cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
  516. cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
  517. (iocb->iocb_cmpl) (phba, iocb, iocb);
  518. }
  519. }
  520. lpfc_sli_abort_iocb_ring(phba, pring);
  521. spin_lock_irq(&phba->hbalock);
  522. }
  523. spin_unlock_irq(&phba->hbalock);
  524. return 0;
  525. }
  526. /**
  527. * lpfc_hb_timeout: The HBA-timer timeout handler.
  528. * @ptr: unsigned long holds the pointer to lpfc hba data structure.
  529. *
  530. * This is the HBA-timer timeout handler registered to the lpfc driver. When
  531. * this timer fires, a HBA timeout event shall be posted to the lpfc driver
  532. * work-port-events bitmap and the worker thread is notified. This timeout
  533. * event will be used by the worker thread to invoke the actual timeout
  534. * handler routine, lpfc_hb_timeout_handler. Any periodical operations will
  535. * be performed in the timeout handler and the HBA timeout event bit shall
  536. * be cleared by the worker thread after it has taken the event bitmap out.
  537. **/
  538. static void
  539. lpfc_hb_timeout(unsigned long ptr)
  540. {
  541. struct lpfc_hba *phba;
  542. uint32_t tmo_posted;
  543. unsigned long iflag;
  544. phba = (struct lpfc_hba *)ptr;
  545. /* Check for heart beat timeout conditions */
  546. spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
  547. tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO;
  548. if (!tmo_posted)
  549. phba->pport->work_port_events |= WORKER_HB_TMO;
  550. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
  551. /* Tell the worker thread there is work to do */
  552. if (!tmo_posted)
  553. lpfc_worker_wake_up(phba);
  554. return;
  555. }
  556. /**
  557. * lpfc_hb_mbox_cmpl: The lpfc heart-beat mailbox command callback function.
  558. * @phba: pointer to lpfc hba data structure.
  559. * @pmboxq: pointer to the driver internal queue element for mailbox command.
  560. *
  561. * This is the callback function to the lpfc heart-beat mailbox command.
  562. * If configured, the lpfc driver issues the heart-beat mailbox command to
  563. * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the
  564. * heart-beat mailbox command is issued, the driver shall set up heart-beat
  565. * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks
  566. * heart-beat outstanding state. Once the mailbox command comes back and
  567. * no error conditions detected, the heart-beat mailbox command timer is
  568. * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding
  569. * state is cleared for the next heart-beat. If the timer expired with the
  570. * heart-beat outstanding state set, the driver will put the HBA offline.
  571. **/
  572. static void
  573. lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
  574. {
  575. unsigned long drvr_flag;
  576. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  577. phba->hb_outstanding = 0;
  578. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  579. /* Check and reset heart-beat timer is necessary */
  580. mempool_free(pmboxq, phba->mbox_mem_pool);
  581. if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) &&
  582. !(phba->link_state == LPFC_HBA_ERROR) &&
  583. !(phba->pport->load_flag & FC_UNLOADING))
  584. mod_timer(&phba->hb_tmofunc,
  585. jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  586. return;
  587. }
  588. /**
  589. * lpfc_hb_timeout_handler: The HBA-timer timeout handler.
  590. * @phba: pointer to lpfc hba data structure.
  591. *
  592. * This is the actual HBA-timer timeout handler to be invoked by the worker
  593. * thread whenever the HBA timer fired and HBA-timeout event posted. This
  594. * handler performs any periodic operations needed for the device. If such
  595. * periodic event has already been attended to either in the interrupt handler
  596. * or by processing slow-ring or fast-ring events within the HBA-timer
  597. * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets
  598. * the timer for the next timeout period. If lpfc heart-beat mailbox command
  599. * is configured and there is no heart-beat mailbox command outstanding, a
  600. * heart-beat mailbox is issued and timer set properly. Otherwise, if there
  601. * has been a heart-beat mailbox command outstanding, the HBA shall be put
  602. * to offline.
  603. **/
  604. void
  605. lpfc_hb_timeout_handler(struct lpfc_hba *phba)
  606. {
  607. LPFC_MBOXQ_t *pmboxq;
  608. struct lpfc_dmabuf *buf_ptr;
  609. int retval;
  610. struct lpfc_sli *psli = &phba->sli;
  611. LIST_HEAD(completions);
  612. if ((phba->link_state == LPFC_HBA_ERROR) ||
  613. (phba->pport->load_flag & FC_UNLOADING) ||
  614. (phba->pport->fc_flag & FC_OFFLINE_MODE))
  615. return;
  616. spin_lock_irq(&phba->pport->work_port_lock);
  617. /* If the timer is already canceled do nothing */
  618. if (!(phba->pport->work_port_events & WORKER_HB_TMO)) {
  619. spin_unlock_irq(&phba->pport->work_port_lock);
  620. return;
  621. }
  622. if (time_after(phba->last_completion_time + LPFC_HB_MBOX_INTERVAL * HZ,
  623. jiffies)) {
  624. spin_unlock_irq(&phba->pport->work_port_lock);
  625. if (!phba->hb_outstanding)
  626. mod_timer(&phba->hb_tmofunc,
  627. jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  628. else
  629. mod_timer(&phba->hb_tmofunc,
  630. jiffies + HZ * LPFC_HB_MBOX_TIMEOUT);
  631. return;
  632. }
  633. spin_unlock_irq(&phba->pport->work_port_lock);
  634. if (phba->elsbuf_cnt &&
  635. (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) {
  636. spin_lock_irq(&phba->hbalock);
  637. list_splice_init(&phba->elsbuf, &completions);
  638. phba->elsbuf_cnt = 0;
  639. phba->elsbuf_prev_cnt = 0;
  640. spin_unlock_irq(&phba->hbalock);
  641. while (!list_empty(&completions)) {
  642. list_remove_head(&completions, buf_ptr,
  643. struct lpfc_dmabuf, list);
  644. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  645. kfree(buf_ptr);
  646. }
  647. }
  648. phba->elsbuf_prev_cnt = phba->elsbuf_cnt;
  649. /* If there is no heart beat outstanding, issue a heartbeat command */
  650. if (phba->cfg_enable_hba_heartbeat) {
  651. if (!phba->hb_outstanding) {
  652. pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
  653. if (!pmboxq) {
  654. mod_timer(&phba->hb_tmofunc,
  655. jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  656. return;
  657. }
  658. lpfc_heart_beat(phba, pmboxq);
  659. pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl;
  660. pmboxq->vport = phba->pport;
  661. retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
  662. if (retval != MBX_BUSY && retval != MBX_SUCCESS) {
  663. mempool_free(pmboxq, phba->mbox_mem_pool);
  664. mod_timer(&phba->hb_tmofunc,
  665. jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  666. return;
  667. }
  668. mod_timer(&phba->hb_tmofunc,
  669. jiffies + HZ * LPFC_HB_MBOX_TIMEOUT);
  670. phba->hb_outstanding = 1;
  671. return;
  672. } else {
  673. /*
  674. * If heart beat timeout called with hb_outstanding set
  675. * we need to take the HBA offline.
  676. */
  677. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  678. "0459 Adapter heartbeat failure, "
  679. "taking this port offline.\n");
  680. spin_lock_irq(&phba->hbalock);
  681. psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
  682. spin_unlock_irq(&phba->hbalock);
  683. lpfc_offline_prep(phba);
  684. lpfc_offline(phba);
  685. lpfc_unblock_mgmt_io(phba);
  686. phba->link_state = LPFC_HBA_ERROR;
  687. lpfc_hba_down_post(phba);
  688. }
  689. }
  690. }
  691. /**
  692. * lpfc_offline_eratt: Bring lpfc offline on hardware error attention.
  693. * @phba: pointer to lpfc hba data structure.
  694. *
  695. * This routine is called to bring the HBA offline when HBA hardware error
  696. * other than Port Error 6 has been detected.
  697. **/
  698. static void
  699. lpfc_offline_eratt(struct lpfc_hba *phba)
  700. {
  701. struct lpfc_sli *psli = &phba->sli;
  702. spin_lock_irq(&phba->hbalock);
  703. psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
  704. spin_unlock_irq(&phba->hbalock);
  705. lpfc_offline_prep(phba);
  706. lpfc_offline(phba);
  707. lpfc_reset_barrier(phba);
  708. lpfc_sli_brdreset(phba);
  709. lpfc_hba_down_post(phba);
  710. lpfc_sli_brdready(phba, HS_MBRDY);
  711. lpfc_unblock_mgmt_io(phba);
  712. phba->link_state = LPFC_HBA_ERROR;
  713. return;
  714. }
  715. /**
  716. * lpfc_handle_eratt: The HBA hardware error handler.
  717. * @phba: pointer to lpfc hba data structure.
  718. *
  719. * This routine is invoked to handle the following HBA hardware error
  720. * conditions:
  721. * 1 - HBA error attention interrupt
  722. * 2 - DMA ring index out of range
  723. * 3 - Mailbox command came back as unknown
  724. **/
  725. void
  726. lpfc_handle_eratt(struct lpfc_hba *phba)
  727. {
  728. struct lpfc_vport *vport = phba->pport;
  729. struct lpfc_sli *psli = &phba->sli;
  730. struct lpfc_sli_ring *pring;
  731. uint32_t event_data;
  732. unsigned long temperature;
  733. struct temp_event temp_event_data;
  734. struct Scsi_Host *shost;
  735. struct lpfc_board_event_header board_event;
  736. /* If the pci channel is offline, ignore possible errors,
  737. * since we cannot communicate with the pci card anyway. */
  738. if (pci_channel_offline(phba->pcidev))
  739. return;
  740. /* If resets are disabled then leave the HBA alone and return */
  741. if (!phba->cfg_enable_hba_reset)
  742. return;
  743. /* Send an internal error event to mgmt application */
  744. board_event.event_type = FC_REG_BOARD_EVENT;
  745. board_event.subcategory = LPFC_EVENT_PORTINTERR;
  746. shost = lpfc_shost_from_vport(phba->pport);
  747. fc_host_post_vendor_event(shost, fc_get_event_number(),
  748. sizeof(board_event),
  749. (char *) &board_event,
  750. SCSI_NL_VID_TYPE_PCI
  751. | PCI_VENDOR_ID_EMULEX);
  752. if (phba->work_hs & HS_FFER6) {
  753. /* Re-establishing Link */
  754. lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
  755. "1301 Re-establishing Link "
  756. "Data: x%x x%x x%x\n",
  757. phba->work_hs,
  758. phba->work_status[0], phba->work_status[1]);
  759. spin_lock_irq(&phba->hbalock);
  760. psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
  761. spin_unlock_irq(&phba->hbalock);
  762. /*
  763. * Firmware stops when it triggled erratt with HS_FFER6.
  764. * That could cause the I/Os dropped by the firmware.
  765. * Error iocb (I/O) on txcmplq and let the SCSI layer
  766. * retry it after re-establishing link.
  767. */
  768. pring = &psli->ring[psli->fcp_ring];
  769. lpfc_sli_abort_iocb_ring(phba, pring);
  770. /*
  771. * There was a firmware error. Take the hba offline and then
  772. * attempt to restart it.
  773. */
  774. lpfc_offline_prep(phba);
  775. lpfc_offline(phba);
  776. lpfc_sli_brdrestart(phba);
  777. if (lpfc_online(phba) == 0) { /* Initialize the HBA */
  778. lpfc_unblock_mgmt_io(phba);
  779. return;
  780. }
  781. lpfc_unblock_mgmt_io(phba);
  782. } else if (phba->work_hs & HS_CRIT_TEMP) {
  783. temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET);
  784. temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
  785. temp_event_data.event_code = LPFC_CRIT_TEMP;
  786. temp_event_data.data = (uint32_t)temperature;
  787. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  788. "0406 Adapter maximum temperature exceeded "
  789. "(%ld), taking this port offline "
  790. "Data: x%x x%x x%x\n",
  791. temperature, phba->work_hs,
  792. phba->work_status[0], phba->work_status[1]);
  793. shost = lpfc_shost_from_vport(phba->pport);
  794. fc_host_post_vendor_event(shost, fc_get_event_number(),
  795. sizeof(temp_event_data),
  796. (char *) &temp_event_data,
  797. SCSI_NL_VID_TYPE_PCI
  798. | PCI_VENDOR_ID_EMULEX);
  799. spin_lock_irq(&phba->hbalock);
  800. phba->over_temp_state = HBA_OVER_TEMP;
  801. spin_unlock_irq(&phba->hbalock);
  802. lpfc_offline_eratt(phba);
  803. } else {
  804. /* The if clause above forces this code path when the status
  805. * failure is a value other than FFER6. Do not call the offline
  806. * twice. This is the adapter hardware error path.
  807. */
  808. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  809. "0457 Adapter Hardware Error "
  810. "Data: x%x x%x x%x\n",
  811. phba->work_hs,
  812. phba->work_status[0], phba->work_status[1]);
  813. event_data = FC_REG_DUMP_EVENT;
  814. shost = lpfc_shost_from_vport(vport);
  815. fc_host_post_vendor_event(shost, fc_get_event_number(),
  816. sizeof(event_data), (char *) &event_data,
  817. SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
  818. lpfc_offline_eratt(phba);
  819. }
  820. return;
  821. }
  822. /**
  823. * lpfc_handle_latt: The HBA link event handler.
  824. * @phba: pointer to lpfc hba data structure.
  825. *
  826. * This routine is invoked from the worker thread to handle a HBA host
  827. * attention link event.
  828. **/
  829. void
  830. lpfc_handle_latt(struct lpfc_hba *phba)
  831. {
  832. struct lpfc_vport *vport = phba->pport;
  833. struct lpfc_sli *psli = &phba->sli;
  834. LPFC_MBOXQ_t *pmb;
  835. volatile uint32_t control;
  836. struct lpfc_dmabuf *mp;
  837. int rc = 0;
  838. pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  839. if (!pmb) {
  840. rc = 1;
  841. goto lpfc_handle_latt_err_exit;
  842. }
  843. mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  844. if (!mp) {
  845. rc = 2;
  846. goto lpfc_handle_latt_free_pmb;
  847. }
  848. mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
  849. if (!mp->virt) {
  850. rc = 3;
  851. goto lpfc_handle_latt_free_mp;
  852. }
  853. /* Cleanup any outstanding ELS commands */
  854. lpfc_els_flush_all_cmd(phba);
  855. psli->slistat.link_event++;
  856. lpfc_read_la(phba, pmb, mp);
  857. pmb->mbox_cmpl = lpfc_mbx_cmpl_read_la;
  858. pmb->vport = vport;
  859. /* Block ELS IOCBs until we have processed this mbox command */
  860. phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
  861. rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT);
  862. if (rc == MBX_NOT_FINISHED) {
  863. rc = 4;
  864. goto lpfc_handle_latt_free_mbuf;
  865. }
  866. /* Clear Link Attention in HA REG */
  867. spin_lock_irq(&phba->hbalock);
  868. writel(HA_LATT, phba->HAregaddr);
  869. readl(phba->HAregaddr); /* flush */
  870. spin_unlock_irq(&phba->hbalock);
  871. return;
  872. lpfc_handle_latt_free_mbuf:
  873. phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
  874. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  875. lpfc_handle_latt_free_mp:
  876. kfree(mp);
  877. lpfc_handle_latt_free_pmb:
  878. mempool_free(pmb, phba->mbox_mem_pool);
  879. lpfc_handle_latt_err_exit:
  880. /* Enable Link attention interrupts */
  881. spin_lock_irq(&phba->hbalock);
  882. psli->sli_flag |= LPFC_PROCESS_LA;
  883. control = readl(phba->HCregaddr);
  884. control |= HC_LAINT_ENA;
  885. writel(control, phba->HCregaddr);
  886. readl(phba->HCregaddr); /* flush */
  887. /* Clear Link Attention in HA REG */
  888. writel(HA_LATT, phba->HAregaddr);
  889. readl(phba->HAregaddr); /* flush */
  890. spin_unlock_irq(&phba->hbalock);
  891. lpfc_linkdown(phba);
  892. phba->link_state = LPFC_HBA_ERROR;
  893. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  894. "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc);
  895. return;
  896. }
  897. /**
  898. * lpfc_parse_vpd: Parse VPD (Vital Product Data).
  899. * @phba: pointer to lpfc hba data structure.
  900. * @vpd: pointer to the vital product data.
  901. * @len: length of the vital product data in bytes.
  902. *
  903. * This routine parses the Vital Product Data (VPD). The VPD is treated as
  904. * an array of characters. In this routine, the ModelName, ProgramType, and
  905. * ModelDesc, etc. fields of the phba data structure will be populated.
  906. *
  907. * Return codes
  908. * 0 - pointer to the VPD passed in is NULL
  909. * 1 - success
  910. **/
  911. static int
  912. lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len)
  913. {
  914. uint8_t lenlo, lenhi;
  915. int Length;
  916. int i, j;
  917. int finished = 0;
  918. int index = 0;
  919. if (!vpd)
  920. return 0;
  921. /* Vital Product */
  922. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  923. "0455 Vital Product Data: x%x x%x x%x x%x\n",
  924. (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
  925. (uint32_t) vpd[3]);
  926. while (!finished && (index < (len - 4))) {
  927. switch (vpd[index]) {
  928. case 0x82:
  929. case 0x91:
  930. index += 1;
  931. lenlo = vpd[index];
  932. index += 1;
  933. lenhi = vpd[index];
  934. index += 1;
  935. i = ((((unsigned short)lenhi) << 8) + lenlo);
  936. index += i;
  937. break;
  938. case 0x90:
  939. index += 1;
  940. lenlo = vpd[index];
  941. index += 1;
  942. lenhi = vpd[index];
  943. index += 1;
  944. Length = ((((unsigned short)lenhi) << 8) + lenlo);
  945. if (Length > len - index)
  946. Length = len - index;
  947. while (Length > 0) {
  948. /* Look for Serial Number */
  949. if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) {
  950. index += 2;
  951. i = vpd[index];
  952. index += 1;
  953. j = 0;
  954. Length -= (3+i);
  955. while(i--) {
  956. phba->SerialNumber[j++] = vpd[index++];
  957. if (j == 31)
  958. break;
  959. }
  960. phba->SerialNumber[j] = 0;
  961. continue;
  962. }
  963. else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) {
  964. phba->vpd_flag |= VPD_MODEL_DESC;
  965. index += 2;
  966. i = vpd[index];
  967. index += 1;
  968. j = 0;
  969. Length -= (3+i);
  970. while(i--) {
  971. phba->ModelDesc[j++] = vpd[index++];
  972. if (j == 255)
  973. break;
  974. }
  975. phba->ModelDesc[j] = 0;
  976. continue;
  977. }
  978. else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) {
  979. phba->vpd_flag |= VPD_MODEL_NAME;
  980. index += 2;
  981. i = vpd[index];
  982. index += 1;
  983. j = 0;
  984. Length -= (3+i);
  985. while(i--) {
  986. phba->ModelName[j++] = vpd[index++];
  987. if (j == 79)
  988. break;
  989. }
  990. phba->ModelName[j] = 0;
  991. continue;
  992. }
  993. else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) {
  994. phba->vpd_flag |= VPD_PROGRAM_TYPE;
  995. index += 2;
  996. i = vpd[index];
  997. index += 1;
  998. j = 0;
  999. Length -= (3+i);
  1000. while(i--) {
  1001. phba->ProgramType[j++] = vpd[index++];
  1002. if (j == 255)
  1003. break;
  1004. }
  1005. phba->ProgramType[j] = 0;
  1006. continue;
  1007. }
  1008. else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) {
  1009. phba->vpd_flag |= VPD_PORT;
  1010. index += 2;
  1011. i = vpd[index];
  1012. index += 1;
  1013. j = 0;
  1014. Length -= (3+i);
  1015. while(i--) {
  1016. phba->Port[j++] = vpd[index++];
  1017. if (j == 19)
  1018. break;
  1019. }
  1020. phba->Port[j] = 0;
  1021. continue;
  1022. }
  1023. else {
  1024. index += 2;
  1025. i = vpd[index];
  1026. index += 1;
  1027. index += i;
  1028. Length -= (3 + i);
  1029. }
  1030. }
  1031. finished = 0;
  1032. break;
  1033. case 0x78:
  1034. finished = 1;
  1035. break;
  1036. default:
  1037. index ++;
  1038. break;
  1039. }
  1040. }
  1041. return(1);
  1042. }
  1043. /**
  1044. * lpfc_get_hba_model_desc: Retrieve HBA device model name and description.
  1045. * @phba: pointer to lpfc hba data structure.
  1046. * @mdp: pointer to the data structure to hold the derived model name.
  1047. * @descp: pointer to the data structure to hold the derived description.
  1048. *
  1049. * This routine retrieves HBA's description based on its registered PCI device
  1050. * ID. The @descp passed into this function points to an array of 256 chars. It
  1051. * shall be returned with the model name, maximum speed, and the host bus type.
  1052. * The @mdp passed into this function points to an array of 80 chars. When the
  1053. * function returns, the @mdp will be filled with the model name.
  1054. **/
  1055. static void
  1056. lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
  1057. {
  1058. lpfc_vpd_t *vp;
  1059. uint16_t dev_id = phba->pcidev->device;
  1060. int max_speed;
  1061. int GE = 0;
  1062. struct {
  1063. char * name;
  1064. int max_speed;
  1065. char * bus;
  1066. } m = {"<Unknown>", 0, ""};
  1067. if (mdp && mdp[0] != '\0'
  1068. && descp && descp[0] != '\0')
  1069. return;
  1070. if (phba->lmt & LMT_10Gb)
  1071. max_speed = 10;
  1072. else if (phba->lmt & LMT_8Gb)
  1073. max_speed = 8;
  1074. else if (phba->lmt & LMT_4Gb)
  1075. max_speed = 4;
  1076. else if (phba->lmt & LMT_2Gb)
  1077. max_speed = 2;
  1078. else
  1079. max_speed = 1;
  1080. vp = &phba->vpd;
  1081. switch (dev_id) {
  1082. case PCI_DEVICE_ID_FIREFLY:
  1083. m = (typeof(m)){"LP6000", max_speed, "PCI"};
  1084. break;
  1085. case PCI_DEVICE_ID_SUPERFLY:
  1086. if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
  1087. m = (typeof(m)){"LP7000", max_speed, "PCI"};
  1088. else
  1089. m = (typeof(m)){"LP7000E", max_speed, "PCI"};
  1090. break;
  1091. case PCI_DEVICE_ID_DRAGONFLY:
  1092. m = (typeof(m)){"LP8000", max_speed, "PCI"};
  1093. break;
  1094. case PCI_DEVICE_ID_CENTAUR:
  1095. if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
  1096. m = (typeof(m)){"LP9002", max_speed, "PCI"};
  1097. else
  1098. m = (typeof(m)){"LP9000", max_speed, "PCI"};
  1099. break;
  1100. case PCI_DEVICE_ID_RFLY:
  1101. m = (typeof(m)){"LP952", max_speed, "PCI"};
  1102. break;
  1103. case PCI_DEVICE_ID_PEGASUS:
  1104. m = (typeof(m)){"LP9802", max_speed, "PCI-X"};
  1105. break;
  1106. case PCI_DEVICE_ID_THOR:
  1107. m = (typeof(m)){"LP10000", max_speed, "PCI-X"};
  1108. break;
  1109. case PCI_DEVICE_ID_VIPER:
  1110. m = (typeof(m)){"LPX1000", max_speed, "PCI-X"};
  1111. break;
  1112. case PCI_DEVICE_ID_PFLY:
  1113. m = (typeof(m)){"LP982", max_speed, "PCI-X"};
  1114. break;
  1115. case PCI_DEVICE_ID_TFLY:
  1116. m = (typeof(m)){"LP1050", max_speed, "PCI-X"};
  1117. break;
  1118. case PCI_DEVICE_ID_HELIOS:
  1119. m = (typeof(m)){"LP11000", max_speed, "PCI-X2"};
  1120. break;
  1121. case PCI_DEVICE_ID_HELIOS_SCSP:
  1122. m = (typeof(m)){"LP11000-SP", max_speed, "PCI-X2"};
  1123. break;
  1124. case PCI_DEVICE_ID_HELIOS_DCSP:
  1125. m = (typeof(m)){"LP11002-SP", max_speed, "PCI-X2"};
  1126. break;
  1127. case PCI_DEVICE_ID_NEPTUNE:
  1128. m = (typeof(m)){"LPe1000", max_speed, "PCIe"};
  1129. break;
  1130. case PCI_DEVICE_ID_NEPTUNE_SCSP:
  1131. m = (typeof(m)){"LPe1000-SP", max_speed, "PCIe"};
  1132. break;
  1133. case PCI_DEVICE_ID_NEPTUNE_DCSP:
  1134. m = (typeof(m)){"LPe1002-SP", max_speed, "PCIe"};
  1135. break;
  1136. case PCI_DEVICE_ID_BMID:
  1137. m = (typeof(m)){"LP1150", max_speed, "PCI-X2"};
  1138. break;
  1139. case PCI_DEVICE_ID_BSMB:
  1140. m = (typeof(m)){"LP111", max_speed, "PCI-X2"};
  1141. break;
  1142. case PCI_DEVICE_ID_ZEPHYR:
  1143. m = (typeof(m)){"LPe11000", max_speed, "PCIe"};
  1144. break;
  1145. case PCI_DEVICE_ID_ZEPHYR_SCSP:
  1146. m = (typeof(m)){"LPe11000", max_speed, "PCIe"};
  1147. break;
  1148. case PCI_DEVICE_ID_ZEPHYR_DCSP:
  1149. m = (typeof(m)){"LPe11002-SP", max_speed, "PCIe"};
  1150. break;
  1151. case PCI_DEVICE_ID_ZMID:
  1152. m = (typeof(m)){"LPe1150", max_speed, "PCIe"};
  1153. break;
  1154. case PCI_DEVICE_ID_ZSMB:
  1155. m = (typeof(m)){"LPe111", max_speed, "PCIe"};
  1156. break;
  1157. case PCI_DEVICE_ID_LP101:
  1158. m = (typeof(m)){"LP101", max_speed, "PCI-X"};
  1159. break;
  1160. case PCI_DEVICE_ID_LP10000S:
  1161. m = (typeof(m)){"LP10000-S", max_speed, "PCI"};
  1162. break;
  1163. case PCI_DEVICE_ID_LP11000S:
  1164. m = (typeof(m)){"LP11000-S", max_speed,
  1165. "PCI-X2"};
  1166. break;
  1167. case PCI_DEVICE_ID_LPE11000S:
  1168. m = (typeof(m)){"LPe11000-S", max_speed,
  1169. "PCIe"};
  1170. break;
  1171. case PCI_DEVICE_ID_SAT:
  1172. m = (typeof(m)){"LPe12000", max_speed, "PCIe"};
  1173. break;
  1174. case PCI_DEVICE_ID_SAT_MID:
  1175. m = (typeof(m)){"LPe1250", max_speed, "PCIe"};
  1176. break;
  1177. case PCI_DEVICE_ID_SAT_SMB:
  1178. m = (typeof(m)){"LPe121", max_speed, "PCIe"};
  1179. break;
  1180. case PCI_DEVICE_ID_SAT_DCSP:
  1181. m = (typeof(m)){"LPe12002-SP", max_speed, "PCIe"};
  1182. break;
  1183. case PCI_DEVICE_ID_SAT_SCSP:
  1184. m = (typeof(m)){"LPe12000-SP", max_speed, "PCIe"};
  1185. break;
  1186. case PCI_DEVICE_ID_SAT_S:
  1187. m = (typeof(m)){"LPe12000-S", max_speed, "PCIe"};
  1188. break;
  1189. case PCI_DEVICE_ID_HORNET:
  1190. m = (typeof(m)){"LP21000", max_speed, "PCIe"};
  1191. GE = 1;
  1192. break;
  1193. case PCI_DEVICE_ID_PROTEUS_VF:
  1194. m = (typeof(m)) {"LPev12000", max_speed, "PCIe IOV"};
  1195. break;
  1196. case PCI_DEVICE_ID_PROTEUS_PF:
  1197. m = (typeof(m)) {"LPev12000", max_speed, "PCIe IOV"};
  1198. break;
  1199. case PCI_DEVICE_ID_PROTEUS_S:
  1200. m = (typeof(m)) {"LPemv12002-S", max_speed, "PCIe IOV"};
  1201. break;
  1202. default:
  1203. m = (typeof(m)){ NULL };
  1204. break;
  1205. }
  1206. if (mdp && mdp[0] == '\0')
  1207. snprintf(mdp, 79,"%s", m.name);
  1208. if (descp && descp[0] == '\0')
  1209. snprintf(descp, 255,
  1210. "Emulex %s %d%s %s %s",
  1211. m.name, m.max_speed,
  1212. (GE) ? "GE" : "Gb",
  1213. m.bus,
  1214. (GE) ? "FCoE Adapter" : "Fibre Channel Adapter");
  1215. }
  1216. /**
  1217. * lpfc_post_buffer: Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring.
  1218. * @phba: pointer to lpfc hba data structure.
  1219. * @pring: pointer to a IOCB ring.
  1220. * @cnt: the number of IOCBs to be posted to the IOCB ring.
  1221. *
  1222. * This routine posts a given number of IOCBs with the associated DMA buffer
  1223. * descriptors specified by the cnt argument to the given IOCB ring.
  1224. *
  1225. * Return codes
  1226. * The number of IOCBs NOT able to be posted to the IOCB ring.
  1227. **/
  1228. int
  1229. lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt)
  1230. {
  1231. IOCB_t *icmd;
  1232. struct lpfc_iocbq *iocb;
  1233. struct lpfc_dmabuf *mp1, *mp2;
  1234. cnt += pring->missbufcnt;
  1235. /* While there are buffers to post */
  1236. while (cnt > 0) {
  1237. /* Allocate buffer for command iocb */
  1238. iocb = lpfc_sli_get_iocbq(phba);
  1239. if (iocb == NULL) {
  1240. pring->missbufcnt = cnt;
  1241. return cnt;
  1242. }
  1243. icmd = &iocb->iocb;
  1244. /* 2 buffers can be posted per command */
  1245. /* Allocate buffer to post */
  1246. mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
  1247. if (mp1)
  1248. mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys);
  1249. if (!mp1 || !mp1->virt) {
  1250. kfree(mp1);
  1251. lpfc_sli_release_iocbq(phba, iocb);
  1252. pring->missbufcnt = cnt;
  1253. return cnt;
  1254. }
  1255. INIT_LIST_HEAD(&mp1->list);
  1256. /* Allocate buffer to post */
  1257. if (cnt > 1) {
  1258. mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
  1259. if (mp2)
  1260. mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
  1261. &mp2->phys);
  1262. if (!mp2 || !mp2->virt) {
  1263. kfree(mp2);
  1264. lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
  1265. kfree(mp1);
  1266. lpfc_sli_release_iocbq(phba, iocb);
  1267. pring->missbufcnt = cnt;
  1268. return cnt;
  1269. }
  1270. INIT_LIST_HEAD(&mp2->list);
  1271. } else {
  1272. mp2 = NULL;
  1273. }
  1274. icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
  1275. icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
  1276. icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
  1277. icmd->ulpBdeCount = 1;
  1278. cnt--;
  1279. if (mp2) {
  1280. icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
  1281. icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
  1282. icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
  1283. cnt--;
  1284. icmd->ulpBdeCount = 2;
  1285. }
  1286. icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
  1287. icmd->ulpLe = 1;
  1288. if (lpfc_sli_issue_iocb(phba, pring, iocb, 0) == IOCB_ERROR) {
  1289. lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
  1290. kfree(mp1);
  1291. cnt++;
  1292. if (mp2) {
  1293. lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
  1294. kfree(mp2);
  1295. cnt++;
  1296. }
  1297. lpfc_sli_release_iocbq(phba, iocb);
  1298. pring->missbufcnt = cnt;
  1299. return cnt;
  1300. }
  1301. lpfc_sli_ringpostbuf_put(phba, pring, mp1);
  1302. if (mp2)
  1303. lpfc_sli_ringpostbuf_put(phba, pring, mp2);
  1304. }
  1305. pring->missbufcnt = 0;
  1306. return 0;
  1307. }
  1308. /**
  1309. * lpfc_post_rcv_buf: Post the initial receive IOCB buffers to ELS ring.
  1310. * @phba: pointer to lpfc hba data structure.
  1311. *
  1312. * This routine posts initial receive IOCB buffers to the ELS ring. The
  1313. * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is
  1314. * set to 64 IOCBs.
  1315. *
  1316. * Return codes
  1317. * 0 - success (currently always success)
  1318. **/
  1319. static int
  1320. lpfc_post_rcv_buf(struct lpfc_hba *phba)
  1321. {
  1322. struct lpfc_sli *psli = &phba->sli;
  1323. /* Ring 0, ELS / CT buffers */
  1324. lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0);
  1325. /* Ring 2 - FCP no buffers needed */
  1326. return 0;
  1327. }
  1328. #define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
  1329. /**
  1330. * lpfc_sha_init: Set up initial array of hash table entries.
  1331. * @HashResultPointer: pointer to an array as hash table.
  1332. *
  1333. * This routine sets up the initial values to the array of hash table entries
  1334. * for the LC HBAs.
  1335. **/
  1336. static void
  1337. lpfc_sha_init(uint32_t * HashResultPointer)
  1338. {
  1339. HashResultPointer[0] = 0x67452301;
  1340. HashResultPointer[1] = 0xEFCDAB89;
  1341. HashResultPointer[2] = 0x98BADCFE;
  1342. HashResultPointer[3] = 0x10325476;
  1343. HashResultPointer[4] = 0xC3D2E1F0;
  1344. }
  1345. /**
  1346. * lpfc_sha_iterate: Iterate initial hash table with the working hash table.
  1347. * @HashResultPointer: pointer to an initial/result hash table.
  1348. * @HashWorkingPointer: pointer to an working hash table.
  1349. *
  1350. * This routine iterates an initial hash table pointed by @HashResultPointer
  1351. * with the values from the working hash table pointeed by @HashWorkingPointer.
  1352. * The results are putting back to the initial hash table, returned through
  1353. * the @HashResultPointer as the result hash table.
  1354. **/
  1355. static void
  1356. lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
  1357. {
  1358. int t;
  1359. uint32_t TEMP;
  1360. uint32_t A, B, C, D, E;
  1361. t = 16;
  1362. do {
  1363. HashWorkingPointer[t] =
  1364. S(1,
  1365. HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
  1366. 8] ^
  1367. HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
  1368. } while (++t <= 79);
  1369. t = 0;
  1370. A = HashResultPointer[0];
  1371. B = HashResultPointer[1];
  1372. C = HashResultPointer[2];
  1373. D = HashResultPointer[3];
  1374. E = HashResultPointer[4];
  1375. do {
  1376. if (t < 20) {
  1377. TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
  1378. } else if (t < 40) {
  1379. TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
  1380. } else if (t < 60) {
  1381. TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
  1382. } else {
  1383. TEMP = (B ^ C ^ D) + 0xCA62C1D6;
  1384. }
  1385. TEMP += S(5, A) + E + HashWorkingPointer[t];
  1386. E = D;
  1387. D = C;
  1388. C = S(30, B);
  1389. B = A;
  1390. A = TEMP;
  1391. } while (++t <= 79);
  1392. HashResultPointer[0] += A;
  1393. HashResultPointer[1] += B;
  1394. HashResultPointer[2] += C;
  1395. HashResultPointer[3] += D;
  1396. HashResultPointer[4] += E;
  1397. }
  1398. /**
  1399. * lpfc_challenge_key: Create challenge key based on WWPN of the HBA.
  1400. * @RandomChallenge: pointer to the entry of host challenge random number array.
  1401. * @HashWorking: pointer to the entry of the working hash array.
  1402. *
  1403. * This routine calculates the working hash array referred by @HashWorking
  1404. * from the challenge random numbers associated with the host, referred by
  1405. * @RandomChallenge. The result is put into the entry of the working hash
  1406. * array and returned by reference through @HashWorking.
  1407. **/
  1408. static void
  1409. lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
  1410. {
  1411. *HashWorking = (*RandomChallenge ^ *HashWorking);
  1412. }
  1413. /**
  1414. * lpfc_hba_init: Perform special handling for LC HBA initialization.
  1415. * @phba: pointer to lpfc hba data structure.
  1416. * @hbainit: pointer to an array of unsigned 32-bit integers.
  1417. *
  1418. * This routine performs the special handling for LC HBA initialization.
  1419. **/
  1420. void
  1421. lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
  1422. {
  1423. int t;
  1424. uint32_t *HashWorking;
  1425. uint32_t *pwwnn = (uint32_t *) phba->wwnn;
  1426. HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL);
  1427. if (!HashWorking)
  1428. return;
  1429. HashWorking[0] = HashWorking[78] = *pwwnn++;
  1430. HashWorking[1] = HashWorking[79] = *pwwnn;
  1431. for (t = 0; t < 7; t++)
  1432. lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
  1433. lpfc_sha_init(hbainit);
  1434. lpfc_sha_iterate(hbainit, HashWorking);
  1435. kfree(HashWorking);
  1436. }
  1437. /**
  1438. * lpfc_cleanup: Performs vport cleanups before deleting a vport.
  1439. * @vport: pointer to a virtual N_Port data structure.
  1440. *
  1441. * This routine performs the necessary cleanups before deleting the @vport.
  1442. * It invokes the discovery state machine to perform necessary state
  1443. * transitions and to release the ndlps associated with the @vport. Note,
  1444. * the physical port is treated as @vport 0.
  1445. **/
  1446. void
  1447. lpfc_cleanup(struct lpfc_vport *vport)
  1448. {
  1449. struct lpfc_hba *phba = vport->phba;
  1450. struct lpfc_nodelist *ndlp, *next_ndlp;
  1451. int i = 0;
  1452. if (phba->link_state > LPFC_LINK_DOWN)
  1453. lpfc_port_link_failure(vport);
  1454. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
  1455. if (!NLP_CHK_NODE_ACT(ndlp)) {
  1456. ndlp = lpfc_enable_node(vport, ndlp,
  1457. NLP_STE_UNUSED_NODE);
  1458. if (!ndlp)
  1459. continue;
  1460. spin_lock_irq(&phba->ndlp_lock);
  1461. NLP_SET_FREE_REQ(ndlp);
  1462. spin_unlock_irq(&phba->ndlp_lock);
  1463. /* Trigger the release of the ndlp memory */
  1464. lpfc_nlp_put(ndlp);
  1465. continue;
  1466. }
  1467. spin_lock_irq(&phba->ndlp_lock);
  1468. if (NLP_CHK_FREE_REQ(ndlp)) {
  1469. /* The ndlp should not be in memory free mode already */
  1470. spin_unlock_irq(&phba->ndlp_lock);
  1471. continue;
  1472. } else
  1473. /* Indicate request for freeing ndlp memory */
  1474. NLP_SET_FREE_REQ(ndlp);
  1475. spin_unlock_irq(&phba->ndlp_lock);
  1476. if (vport->port_type != LPFC_PHYSICAL_PORT &&
  1477. ndlp->nlp_DID == Fabric_DID) {
  1478. /* Just free up ndlp with Fabric_DID for vports */
  1479. lpfc_nlp_put(ndlp);
  1480. continue;
  1481. }
  1482. if (ndlp->nlp_type & NLP_FABRIC)
  1483. lpfc_disc_state_machine(vport, ndlp, NULL,
  1484. NLP_EVT_DEVICE_RECOVERY);
  1485. lpfc_disc_state_machine(vport, ndlp, NULL,
  1486. NLP_EVT_DEVICE_RM);
  1487. }
  1488. /* At this point, ALL ndlp's should be gone
  1489. * because of the previous NLP_EVT_DEVICE_RM.
  1490. * Lets wait for this to happen, if needed.
  1491. */
  1492. while (!list_empty(&vport->fc_nodes)) {
  1493. if (i++ > 3000) {
  1494. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  1495. "0233 Nodelist not empty\n");
  1496. list_for_each_entry_safe(ndlp, next_ndlp,
  1497. &vport->fc_nodes, nlp_listp) {
  1498. lpfc_printf_vlog(ndlp->vport, KERN_ERR,
  1499. LOG_NODE,
  1500. "0282 did:x%x ndlp:x%p "
  1501. "usgmap:x%x refcnt:%d\n",
  1502. ndlp->nlp_DID, (void *)ndlp,
  1503. ndlp->nlp_usg_map,
  1504. atomic_read(
  1505. &ndlp->kref.refcount));
  1506. }
  1507. break;
  1508. }
  1509. /* Wait for any activity on ndlps to settle */
  1510. msleep(10);
  1511. }
  1512. return;
  1513. }
  1514. /**
  1515. * lpfc_stop_vport_timers: Stop all the timers associated with a vport.
  1516. * @vport: pointer to a virtual N_Port data structure.
  1517. *
  1518. * This routine stops all the timers associated with a @vport. This function
  1519. * is invoked before disabling or deleting a @vport. Note that the physical
  1520. * port is treated as @vport 0.
  1521. **/
  1522. void
  1523. lpfc_stop_vport_timers(struct lpfc_vport *vport)
  1524. {
  1525. del_timer_sync(&vport->els_tmofunc);
  1526. del_timer_sync(&vport->fc_fdmitmo);
  1527. lpfc_can_disctmo(vport);
  1528. return;
  1529. }
  1530. /**
  1531. * lpfc_stop_phba_timers: Stop all the timers associated with an HBA.
  1532. * @phba: pointer to lpfc hba data structure.
  1533. *
  1534. * This routine stops all the timers associated with a HBA. This function is
  1535. * invoked before either putting a HBA offline or unloading the driver.
  1536. **/
  1537. static void
  1538. lpfc_stop_phba_timers(struct lpfc_hba *phba)
  1539. {
  1540. del_timer_sync(&phba->fcp_poll_timer);
  1541. lpfc_stop_vport_timers(phba->pport);
  1542. del_timer_sync(&phba->sli.mbox_tmo);
  1543. del_timer_sync(&phba->fabric_block_timer);
  1544. phba->hb_outstanding = 0;
  1545. del_timer_sync(&phba->hb_tmofunc);
  1546. del_timer_sync(&phba->eratt_poll);
  1547. return;
  1548. }
  1549. /**
  1550. * lpfc_block_mgmt_io: Mark a HBA's management interface as blocked.
  1551. * @phba: pointer to lpfc hba data structure.
  1552. *
  1553. * This routine marks a HBA's management interface as blocked. Once the HBA's
  1554. * management interface is marked as blocked, all the user space access to
  1555. * the HBA, whether they are from sysfs interface or libdfc interface will
  1556. * all be blocked. The HBA is set to block the management interface when the
  1557. * driver prepares the HBA interface for online or offline.
  1558. **/
  1559. static void
  1560. lpfc_block_mgmt_io(struct lpfc_hba * phba)
  1561. {
  1562. unsigned long iflag;
  1563. spin_lock_irqsave(&phba->hbalock, iflag);
  1564. phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO;
  1565. spin_unlock_irqrestore(&phba->hbalock, iflag);
  1566. }
  1567. /**
  1568. * lpfc_online: Initialize and bring a HBA online.
  1569. * @phba: pointer to lpfc hba data structure.
  1570. *
  1571. * This routine initializes the HBA and brings a HBA online. During this
  1572. * process, the management interface is blocked to prevent user space access
  1573. * to the HBA interfering with the driver initialization.
  1574. *
  1575. * Return codes
  1576. * 0 - successful
  1577. * 1 - failed
  1578. **/
  1579. int
  1580. lpfc_online(struct lpfc_hba *phba)
  1581. {
  1582. struct lpfc_vport *vport = phba->pport;
  1583. struct lpfc_vport **vports;
  1584. int i;
  1585. if (!phba)
  1586. return 0;
  1587. if (!(vport->fc_flag & FC_OFFLINE_MODE))
  1588. return 0;
  1589. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  1590. "0458 Bring Adapter online\n");
  1591. lpfc_block_mgmt_io(phba);
  1592. if (!lpfc_sli_queue_setup(phba)) {
  1593. lpfc_unblock_mgmt_io(phba);
  1594. return 1;
  1595. }
  1596. if (lpfc_sli_hba_setup(phba)) { /* Initialize the HBA */
  1597. lpfc_unblock_mgmt_io(phba);
  1598. return 1;
  1599. }
  1600. vports = lpfc_create_vport_work_array(phba);
  1601. if (vports != NULL)
  1602. for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
  1603. struct Scsi_Host *shost;
  1604. shost = lpfc_shost_from_vport(vports[i]);
  1605. spin_lock_irq(shost->host_lock);
  1606. vports[i]->fc_flag &= ~FC_OFFLINE_MODE;
  1607. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
  1608. vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  1609. spin_unlock_irq(shost->host_lock);
  1610. }
  1611. lpfc_destroy_vport_work_array(phba, vports);
  1612. lpfc_unblock_mgmt_io(phba);
  1613. return 0;
  1614. }
  1615. /**
  1616. * lpfc_unblock_mgmt_io: Mark a HBA's management interface to be not blocked.
  1617. * @phba: pointer to lpfc hba data structure.
  1618. *
  1619. * This routine marks a HBA's management interface as not blocked. Once the
  1620. * HBA's management interface is marked as not blocked, all the user space
  1621. * access to the HBA, whether they are from sysfs interface or libdfc
  1622. * interface will be allowed. The HBA is set to block the management interface
  1623. * when the driver prepares the HBA interface for online or offline and then
  1624. * set to unblock the management interface afterwards.
  1625. **/
  1626. void
  1627. lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
  1628. {
  1629. unsigned long iflag;
  1630. spin_lock_irqsave(&phba->hbalock, iflag);
  1631. phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO;
  1632. spin_unlock_irqrestore(&phba->hbalock, iflag);
  1633. }
  1634. /**
  1635. * lpfc_offline_prep: Prepare a HBA to be brought offline.
  1636. * @phba: pointer to lpfc hba data structure.
  1637. *
  1638. * This routine is invoked to prepare a HBA to be brought offline. It performs
  1639. * unregistration login to all the nodes on all vports and flushes the mailbox
  1640. * queue to make it ready to be brought offline.
  1641. **/
  1642. void
  1643. lpfc_offline_prep(struct lpfc_hba * phba)
  1644. {
  1645. struct lpfc_vport *vport = phba->pport;
  1646. struct lpfc_nodelist *ndlp, *next_ndlp;
  1647. struct lpfc_vport **vports;
  1648. int i;
  1649. if (vport->fc_flag & FC_OFFLINE_MODE)
  1650. return;
  1651. lpfc_block_mgmt_io(phba);
  1652. lpfc_linkdown(phba);
  1653. /* Issue an unreg_login to all nodes on all vports */
  1654. vports = lpfc_create_vport_work_array(phba);
  1655. if (vports != NULL) {
  1656. for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
  1657. struct Scsi_Host *shost;
  1658. if (vports[i]->load_flag & FC_UNLOADING)
  1659. continue;
  1660. shost = lpfc_shost_from_vport(vports[i]);
  1661. list_for_each_entry_safe(ndlp, next_ndlp,
  1662. &vports[i]->fc_nodes,
  1663. nlp_listp) {
  1664. if (!NLP_CHK_NODE_ACT(ndlp))
  1665. continue;
  1666. if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
  1667. continue;
  1668. if (ndlp->nlp_type & NLP_FABRIC) {
  1669. lpfc_disc_state_machine(vports[i], ndlp,
  1670. NULL, NLP_EVT_DEVICE_RECOVERY);
  1671. lpfc_disc_state_machine(vports[i], ndlp,
  1672. NULL, NLP_EVT_DEVICE_RM);
  1673. }
  1674. spin_lock_irq(shost->host_lock);
  1675. ndlp->nlp_flag &= ~NLP_NPR_ADISC;
  1676. spin_unlock_irq(shost->host_lock);
  1677. lpfc_unreg_rpi(vports[i], ndlp);
  1678. }
  1679. }
  1680. }
  1681. lpfc_destroy_vport_work_array(phba, vports);
  1682. lpfc_sli_flush_mbox_queue(phba);
  1683. }
  1684. /**
  1685. * lpfc_offline: Bring a HBA offline.
  1686. * @phba: pointer to lpfc hba data structure.
  1687. *
  1688. * This routine actually brings a HBA offline. It stops all the timers
  1689. * associated with the HBA, brings down the SLI layer, and eventually
  1690. * marks the HBA as in offline state for the upper layer protocol.
  1691. **/
  1692. void
  1693. lpfc_offline(struct lpfc_hba *phba)
  1694. {
  1695. struct Scsi_Host *shost;
  1696. struct lpfc_vport **vports;
  1697. int i;
  1698. if (phba->pport->fc_flag & FC_OFFLINE_MODE)
  1699. return;
  1700. /* stop all timers associated with this hba */
  1701. lpfc_stop_phba_timers(phba);
  1702. vports = lpfc_create_vport_work_array(phba);
  1703. if (vports != NULL)
  1704. for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++)
  1705. lpfc_stop_vport_timers(vports[i]);
  1706. lpfc_destroy_vport_work_array(phba, vports);
  1707. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  1708. "0460 Bring Adapter offline\n");
  1709. /* Bring down the SLI Layer and cleanup. The HBA is offline
  1710. now. */
  1711. lpfc_sli_hba_down(phba);
  1712. spin_lock_irq(&phba->hbalock);
  1713. phba->work_ha = 0;
  1714. spin_unlock_irq(&phba->hbalock);
  1715. vports = lpfc_create_vport_work_array(phba);
  1716. if (vports != NULL)
  1717. for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
  1718. shost = lpfc_shost_from_vport(vports[i]);
  1719. spin_lock_irq(shost->host_lock);
  1720. vports[i]->work_port_events = 0;
  1721. vports[i]->fc_flag |= FC_OFFLINE_MODE;
  1722. spin_unlock_irq(shost->host_lock);
  1723. }
  1724. lpfc_destroy_vport_work_array(phba, vports);
  1725. }
  1726. /**
  1727. * lpfc_scsi_free: Free all the SCSI buffers and IOCBs from driver lists.
  1728. * @phba: pointer to lpfc hba data structure.
  1729. *
  1730. * This routine is to free all the SCSI buffers and IOCBs from the driver
  1731. * list back to kernel. It is called from lpfc_pci_remove_one to free
  1732. * the internal resources before the device is removed from the system.
  1733. *
  1734. * Return codes
  1735. * 0 - successful (for now, it always returns 0)
  1736. **/
  1737. static int
  1738. lpfc_scsi_free(struct lpfc_hba *phba)
  1739. {
  1740. struct lpfc_scsi_buf *sb, *sb_next;
  1741. struct lpfc_iocbq *io, *io_next;
  1742. spin_lock_irq(&phba->hbalock);
  1743. /* Release all the lpfc_scsi_bufs maintained by this host. */
  1744. list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list, list) {
  1745. list_del(&sb->list);
  1746. pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data,
  1747. sb->dma_handle);
  1748. kfree(sb);
  1749. phba->total_scsi_bufs--;
  1750. }
  1751. /* Release all the lpfc_iocbq entries maintained by this host. */
  1752. list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) {
  1753. list_del(&io->list);
  1754. kfree(io);
  1755. phba->total_iocbq_bufs--;
  1756. }
  1757. spin_unlock_irq(&phba->hbalock);
  1758. return 0;
  1759. }
  1760. /**
  1761. * lpfc_create_port: Create an FC port.
  1762. * @phba: pointer to lpfc hba data structure.
  1763. * @instance: a unique integer ID to this FC port.
  1764. * @dev: pointer to the device data structure.
  1765. *
  1766. * This routine creates a FC port for the upper layer protocol. The FC port
  1767. * can be created on top of either a physical port or a virtual port provided
  1768. * by the HBA. This routine also allocates a SCSI host data structure (shost)
  1769. * and associates the FC port created before adding the shost into the SCSI
  1770. * layer.
  1771. *
  1772. * Return codes
  1773. * @vport - pointer to the virtual N_Port data structure.
  1774. * NULL - port create failed.
  1775. **/
  1776. struct lpfc_vport *
  1777. lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
  1778. {
  1779. struct lpfc_vport *vport;
  1780. struct Scsi_Host *shost;
  1781. int error = 0;
  1782. if (dev != &phba->pcidev->dev)
  1783. shost = scsi_host_alloc(&lpfc_vport_template,
  1784. sizeof(struct lpfc_vport));
  1785. else
  1786. shost = scsi_host_alloc(&lpfc_template,
  1787. sizeof(struct lpfc_vport));
  1788. if (!shost)
  1789. goto out;
  1790. vport = (struct lpfc_vport *) shost->hostdata;
  1791. vport->phba = phba;
  1792. vport->load_flag |= FC_LOADING;
  1793. vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  1794. vport->fc_rscn_flush = 0;
  1795. lpfc_get_vport_cfgparam(vport);
  1796. shost->unique_id = instance;
  1797. shost->max_id = LPFC_MAX_TARGET;
  1798. shost->max_lun = vport->cfg_max_luns;
  1799. shost->this_id = -1;
  1800. shost->max_cmd_len = 16;
  1801. /*
  1802. * Set initial can_queue value since 0 is no longer supported and
  1803. * scsi_add_host will fail. This will be adjusted later based on the
  1804. * max xri value determined in hba setup.
  1805. */
  1806. shost->can_queue = phba->cfg_hba_queue_depth - 10;
  1807. if (dev != &phba->pcidev->dev) {
  1808. shost->transportt = lpfc_vport_transport_template;
  1809. vport->port_type = LPFC_NPIV_PORT;
  1810. } else {
  1811. shost->transportt = lpfc_transport_template;
  1812. vport->port_type = LPFC_PHYSICAL_PORT;
  1813. }
  1814. /* Initialize all internally managed lists. */
  1815. INIT_LIST_HEAD(&vport->fc_nodes);
  1816. spin_lock_init(&vport->work_port_lock);
  1817. init_timer(&vport->fc_disctmo);
  1818. vport->fc_disctmo.function = lpfc_disc_timeout;
  1819. vport->fc_disctmo.data = (unsigned long)vport;
  1820. init_timer(&vport->fc_fdmitmo);
  1821. vport->fc_fdmitmo.function = lpfc_fdmi_tmo;
  1822. vport->fc_fdmitmo.data = (unsigned long)vport;
  1823. init_timer(&vport->els_tmofunc);
  1824. vport->els_tmofunc.function = lpfc_els_timeout;
  1825. vport->els_tmofunc.data = (unsigned long)vport;
  1826. error = scsi_add_host(shost, dev);
  1827. if (error)
  1828. goto out_put_shost;
  1829. spin_lock_irq(&phba->hbalock);
  1830. list_add_tail(&vport->listentry, &phba->port_list);
  1831. spin_unlock_irq(&phba->hbalock);
  1832. return vport;
  1833. out_put_shost:
  1834. scsi_host_put(shost);
  1835. out:
  1836. return NULL;
  1837. }
  1838. /**
  1839. * destroy_port: Destroy an FC port.
  1840. * @vport: pointer to an lpfc virtual N_Port data structure.
  1841. *
  1842. * This routine destroys a FC port from the upper layer protocol. All the
  1843. * resources associated with the port are released.
  1844. **/
  1845. void
  1846. destroy_port(struct lpfc_vport *vport)
  1847. {
  1848. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1849. struct lpfc_hba *phba = vport->phba;
  1850. kfree(vport->vname);
  1851. lpfc_debugfs_terminate(vport);
  1852. fc_remove_host(shost);
  1853. scsi_remove_host(shost);
  1854. spin_lock_irq(&phba->hbalock);
  1855. list_del_init(&vport->listentry);
  1856. spin_unlock_irq(&phba->hbalock);
  1857. lpfc_cleanup(vport);
  1858. return;
  1859. }
  1860. /**
  1861. * lpfc_get_instance: Get a unique integer ID.
  1862. *
  1863. * This routine allocates a unique integer ID from lpfc_hba_index pool. It
  1864. * uses the kernel idr facility to perform the task.
  1865. *
  1866. * Return codes:
  1867. * instance - a unique integer ID allocated as the new instance.
  1868. * -1 - lpfc get instance failed.
  1869. **/
  1870. int
  1871. lpfc_get_instance(void)
  1872. {
  1873. int instance = 0;
  1874. /* Assign an unused number */
  1875. if (!idr_pre_get(&lpfc_hba_index, GFP_KERNEL))
  1876. return -1;
  1877. if (idr_get_new(&lpfc_hba_index, NULL, &instance))
  1878. return -1;
  1879. return instance;
  1880. }
  1881. /**
  1882. * lpfc_scan_finished: method for SCSI layer to detect whether scan is done.
  1883. * @shost: pointer to SCSI host data structure.
  1884. * @time: elapsed time of the scan in jiffies.
  1885. *
  1886. * This routine is called by the SCSI layer with a SCSI host to determine
  1887. * whether the scan host is finished.
  1888. *
  1889. * Note: there is no scan_start function as adapter initialization will have
  1890. * asynchronously kicked off the link initialization.
  1891. *
  1892. * Return codes
  1893. * 0 - SCSI host scan is not over yet.
  1894. * 1 - SCSI host scan is over.
  1895. **/
  1896. int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
  1897. {
  1898. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1899. struct lpfc_hba *phba = vport->phba;
  1900. int stat = 0;
  1901. spin_lock_irq(shost->host_lock);
  1902. if (vport->load_flag & FC_UNLOADING) {
  1903. stat = 1;
  1904. goto finished;
  1905. }
  1906. if (time >= 30 * HZ) {
  1907. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  1908. "0461 Scanning longer than 30 "
  1909. "seconds. Continuing initialization\n");
  1910. stat = 1;
  1911. goto finished;
  1912. }
  1913. if (time >= 15 * HZ && phba->link_state <= LPFC_LINK_DOWN) {
  1914. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  1915. "0465 Link down longer than 15 "
  1916. "seconds. Continuing initialization\n");
  1917. stat = 1;
  1918. goto finished;
  1919. }
  1920. if (vport->port_state != LPFC_VPORT_READY)
  1921. goto finished;
  1922. if (vport->num_disc_nodes || vport->fc_prli_sent)
  1923. goto finished;
  1924. if (vport->fc_map_cnt == 0 && time < 2 * HZ)
  1925. goto finished;
  1926. if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
  1927. goto finished;
  1928. stat = 1;
  1929. finished:
  1930. spin_unlock_irq(shost->host_lock);
  1931. return stat;
  1932. }
  1933. /**
  1934. * lpfc_host_attrib_init: Initialize SCSI host attributes on a FC port.
  1935. * @shost: pointer to SCSI host data structure.
  1936. *
  1937. * This routine initializes a given SCSI host attributes on a FC port. The
  1938. * SCSI host can be either on top of a physical port or a virtual port.
  1939. **/
  1940. void lpfc_host_attrib_init(struct Scsi_Host *shost)
  1941. {
  1942. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1943. struct lpfc_hba *phba = vport->phba;
  1944. /*
  1945. * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
  1946. */
  1947. fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
  1948. fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
  1949. fc_host_supported_classes(shost) = FC_COS_CLASS3;
  1950. memset(fc_host_supported_fc4s(shost), 0,
  1951. sizeof(fc_host_supported_fc4s(shost)));
  1952. fc_host_supported_fc4s(shost)[2] = 1;
  1953. fc_host_supported_fc4s(shost)[7] = 1;
  1954. lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
  1955. sizeof fc_host_symbolic_name(shost));
  1956. fc_host_supported_speeds(shost) = 0;
  1957. if (phba->lmt & LMT_10Gb)
  1958. fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
  1959. if (phba->lmt & LMT_8Gb)
  1960. fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT;
  1961. if (phba->lmt & LMT_4Gb)
  1962. fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
  1963. if (phba->lmt & LMT_2Gb)
  1964. fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
  1965. if (phba->lmt & LMT_1Gb)
  1966. fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
  1967. fc_host_maxframe_size(shost) =
  1968. (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
  1969. (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
  1970. /* This value is also unchanging */
  1971. memset(fc_host_active_fc4s(shost), 0,
  1972. sizeof(fc_host_active_fc4s(shost)));
  1973. fc_host_active_fc4s(shost)[2] = 1;
  1974. fc_host_active_fc4s(shost)[7] = 1;
  1975. fc_host_max_npiv_vports(shost) = phba->max_vpi;
  1976. spin_lock_irq(shost->host_lock);
  1977. vport->load_flag &= ~FC_LOADING;
  1978. spin_unlock_irq(shost->host_lock);
  1979. }
  1980. /**
  1981. * lpfc_enable_msix: Enable MSI-X interrupt mode.
  1982. * @phba: pointer to lpfc hba data structure.
  1983. *
  1984. * This routine is invoked to enable the MSI-X interrupt vectors. The kernel
  1985. * function pci_enable_msix() is called to enable the MSI-X vectors. Note that
  1986. * pci_enable_msix(), once invoked, enables either all or nothing, depending
  1987. * on the current availability of PCI vector resources. The device driver is
  1988. * responsible for calling the individual request_irq() to register each MSI-X
  1989. * vector with a interrupt handler, which is done in this function. Note that
  1990. * later when device is unloading, the driver should always call free_irq()
  1991. * on all MSI-X vectors it has done request_irq() on before calling
  1992. * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device
  1993. * will be left with MSI-X enabled and leaks its vectors.
  1994. *
  1995. * Return codes
  1996. * 0 - sucessful
  1997. * other values - error
  1998. **/
  1999. static int
  2000. lpfc_enable_msix(struct lpfc_hba *phba)
  2001. {
  2002. int rc, i;
  2003. LPFC_MBOXQ_t *pmb;
  2004. /* Set up MSI-X multi-message vectors */
  2005. for (i = 0; i < LPFC_MSIX_VECTORS; i++)
  2006. phba->msix_entries[i].entry = i;
  2007. /* Configure MSI-X capability structure */
  2008. rc = pci_enable_msix(phba->pcidev, phba->msix_entries,
  2009. ARRAY_SIZE(phba->msix_entries));
  2010. if (rc) {
  2011. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  2012. "0420 Enable MSI-X failed (%d), continuing "
  2013. "with MSI\n", rc);
  2014. goto msi_fail_out;
  2015. } else
  2016. for (i = 0; i < LPFC_MSIX_VECTORS; i++)
  2017. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  2018. "0477 MSI-X entry[%d]: vector=x%x "
  2019. "message=%d\n", i,
  2020. phba->msix_entries[i].vector,
  2021. phba->msix_entries[i].entry);
  2022. /*
  2023. * Assign MSI-X vectors to interrupt handlers
  2024. */
  2025. /* vector-0 is associated to slow-path handler */
  2026. rc = request_irq(phba->msix_entries[0].vector, &lpfc_sp_intr_handler,
  2027. IRQF_SHARED, LPFC_SP_DRIVER_HANDLER_NAME, phba);
  2028. if (rc) {
  2029. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2030. "0421 MSI-X slow-path request_irq failed "
  2031. "(%d), continuing with MSI\n", rc);
  2032. goto msi_fail_out;
  2033. }
  2034. /* vector-1 is associated to fast-path handler */
  2035. rc = request_irq(phba->msix_entries[1].vector, &lpfc_fp_intr_handler,
  2036. IRQF_SHARED, LPFC_FP_DRIVER_HANDLER_NAME, phba);
  2037. if (rc) {
  2038. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2039. "0429 MSI-X fast-path request_irq failed "
  2040. "(%d), continuing with MSI\n", rc);
  2041. goto irq_fail_out;
  2042. }
  2043. /*
  2044. * Configure HBA MSI-X attention conditions to messages
  2045. */
  2046. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  2047. if (!pmb) {
  2048. rc = -ENOMEM;
  2049. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2050. "0474 Unable to allocate memory for issuing "
  2051. "MBOX_CONFIG_MSI command\n");
  2052. goto mem_fail_out;
  2053. }
  2054. rc = lpfc_config_msi(phba, pmb);
  2055. if (rc)
  2056. goto mbx_fail_out;
  2057. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  2058. if (rc != MBX_SUCCESS) {
  2059. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  2060. "0351 Config MSI mailbox command failed, "
  2061. "mbxCmd x%x, mbxStatus x%x\n",
  2062. pmb->mb.mbxCommand, pmb->mb.mbxStatus);
  2063. goto mbx_fail_out;
  2064. }
  2065. /* Free memory allocated for mailbox command */
  2066. mempool_free(pmb, phba->mbox_mem_pool);
  2067. return rc;
  2068. mbx_fail_out:
  2069. /* Free memory allocated for mailbox command */
  2070. mempool_free(pmb, phba->mbox_mem_pool);
  2071. mem_fail_out:
  2072. /* free the irq already requested */
  2073. free_irq(phba->msix_entries[1].vector, phba);
  2074. irq_fail_out:
  2075. /* free the irq already requested */
  2076. free_irq(phba->msix_entries[0].vector, phba);
  2077. msi_fail_out:
  2078. /* Unconfigure MSI-X capability structure */
  2079. pci_disable_msix(phba->pcidev);
  2080. return rc;
  2081. }
  2082. /**
  2083. * lpfc_disable_msix: Disable MSI-X interrupt mode.
  2084. * @phba: pointer to lpfc hba data structure.
  2085. *
  2086. * This routine is invoked to release the MSI-X vectors and then disable the
  2087. * MSI-X interrupt mode.
  2088. **/
  2089. static void
  2090. lpfc_disable_msix(struct lpfc_hba *phba)
  2091. {
  2092. int i;
  2093. /* Free up MSI-X multi-message vectors */
  2094. for (i = 0; i < LPFC_MSIX_VECTORS; i++)
  2095. free_irq(phba->msix_entries[i].vector, phba);
  2096. /* Disable MSI-X */
  2097. pci_disable_msix(phba->pcidev);
  2098. }
  2099. /**
  2100. * lpfc_pci_probe_one: lpfc PCI probe func to register device to PCI subsystem.
  2101. * @pdev: pointer to PCI device
  2102. * @pid: pointer to PCI device identifier
  2103. *
  2104. * This routine is to be registered to the kernel's PCI subsystem. When an
  2105. * Emulex HBA is presented in PCI bus, the kernel PCI subsystem looks at
  2106. * PCI device-specific information of the device and driver to see if the
  2107. * driver state that it can support this kind of device. If the match is
  2108. * successful, the driver core invokes this routine. If this routine
  2109. * determines it can claim the HBA, it does all the initialization that it
  2110. * needs to do to handle the HBA properly.
  2111. *
  2112. * Return code
  2113. * 0 - driver can claim the device
  2114. * negative value - driver can not claim the device
  2115. **/
  2116. static int __devinit
  2117. lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
  2118. {
  2119. struct lpfc_vport *vport = NULL;
  2120. struct lpfc_hba *phba;
  2121. struct lpfc_sli *psli;
  2122. struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
  2123. struct Scsi_Host *shost = NULL;
  2124. void *ptr;
  2125. unsigned long bar0map_len, bar2map_len;
  2126. int error = -ENODEV, retval;
  2127. int i, hbq_count;
  2128. uint16_t iotag;
  2129. int bars = pci_select_bars(pdev, IORESOURCE_MEM);
  2130. struct lpfc_adapter_event_header adapter_event;
  2131. if (pci_enable_device_mem(pdev))
  2132. goto out;
  2133. if (pci_request_selected_regions(pdev, bars, LPFC_DRIVER_NAME))
  2134. goto out_disable_device;
  2135. phba = kzalloc(sizeof (struct lpfc_hba), GFP_KERNEL);
  2136. if (!phba)
  2137. goto out_release_regions;
  2138. atomic_set(&phba->fast_event_count, 0);
  2139. spin_lock_init(&phba->hbalock);
  2140. /* Initialize ndlp management spinlock */
  2141. spin_lock_init(&phba->ndlp_lock);
  2142. phba->pcidev = pdev;
  2143. /* Assign an unused board number */
  2144. if ((phba->brd_no = lpfc_get_instance()) < 0)
  2145. goto out_free_phba;
  2146. INIT_LIST_HEAD(&phba->port_list);
  2147. init_waitqueue_head(&phba->wait_4_mlo_m_q);
  2148. /*
  2149. * Get all the module params for configuring this host and then
  2150. * establish the host.
  2151. */
  2152. lpfc_get_cfgparam(phba);
  2153. phba->max_vpi = LPFC_MAX_VPI;
  2154. /* Initialize timers used by driver */
  2155. init_timer(&phba->hb_tmofunc);
  2156. phba->hb_tmofunc.function = lpfc_hb_timeout;
  2157. phba->hb_tmofunc.data = (unsigned long)phba;
  2158. psli = &phba->sli;
  2159. init_timer(&psli->mbox_tmo);
  2160. psli->mbox_tmo.function = lpfc_mbox_timeout;
  2161. psli->mbox_tmo.data = (unsigned long) phba;
  2162. init_timer(&phba->fcp_poll_timer);
  2163. phba->fcp_poll_timer.function = lpfc_poll_timeout;
  2164. phba->fcp_poll_timer.data = (unsigned long) phba;
  2165. init_timer(&phba->fabric_block_timer);
  2166. phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
  2167. phba->fabric_block_timer.data = (unsigned long) phba;
  2168. init_timer(&phba->eratt_poll);
  2169. phba->eratt_poll.function = lpfc_poll_eratt;
  2170. phba->eratt_poll.data = (unsigned long) phba;
  2171. pci_set_master(pdev);
  2172. pci_try_set_mwi(pdev);
  2173. if (pci_set_dma_mask(phba->pcidev, DMA_64BIT_MASK) != 0)
  2174. if (pci_set_dma_mask(phba->pcidev, DMA_32BIT_MASK) != 0)
  2175. goto out_idr_remove;
  2176. /*
  2177. * Get the bus address of Bar0 and Bar2 and the number of bytes
  2178. * required by each mapping.
  2179. */
  2180. phba->pci_bar0_map = pci_resource_start(phba->pcidev, 0);
  2181. bar0map_len = pci_resource_len(phba->pcidev, 0);
  2182. phba->pci_bar2_map = pci_resource_start(phba->pcidev, 2);
  2183. bar2map_len = pci_resource_len(phba->pcidev, 2);
  2184. /* Map HBA SLIM to a kernel virtual address. */
  2185. phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
  2186. if (!phba->slim_memmap_p) {
  2187. error = -ENODEV;
  2188. dev_printk(KERN_ERR, &pdev->dev,
  2189. "ioremap failed for SLIM memory.\n");
  2190. goto out_idr_remove;
  2191. }
  2192. /* Map HBA Control Registers to a kernel virtual address. */
  2193. phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
  2194. if (!phba->ctrl_regs_memmap_p) {
  2195. error = -ENODEV;
  2196. dev_printk(KERN_ERR, &pdev->dev,
  2197. "ioremap failed for HBA control registers.\n");
  2198. goto out_iounmap_slim;
  2199. }
  2200. /* Allocate memory for SLI-2 structures */
  2201. phba->slim2p.virt = dma_alloc_coherent(&phba->pcidev->dev,
  2202. SLI2_SLIM_SIZE,
  2203. &phba->slim2p.phys,
  2204. GFP_KERNEL);
  2205. if (!phba->slim2p.virt)
  2206. goto out_iounmap;
  2207. memset(phba->slim2p.virt, 0, SLI2_SLIM_SIZE);
  2208. phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx);
  2209. phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb));
  2210. phba->IOCBs = (phba->slim2p.virt +
  2211. offsetof(struct lpfc_sli2_slim, IOCBs));
  2212. phba->hbqslimp.virt = dma_alloc_coherent(&phba->pcidev->dev,
  2213. lpfc_sli_hbq_size(),
  2214. &phba->hbqslimp.phys,
  2215. GFP_KERNEL);
  2216. if (!phba->hbqslimp.virt)
  2217. goto out_free_slim;
  2218. hbq_count = lpfc_sli_hbq_count();
  2219. ptr = phba->hbqslimp.virt;
  2220. for (i = 0; i < hbq_count; ++i) {
  2221. phba->hbqs[i].hbq_virt = ptr;
  2222. INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
  2223. ptr += (lpfc_hbq_defs[i]->entry_count *
  2224. sizeof(struct lpfc_hbq_entry));
  2225. }
  2226. phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc;
  2227. phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free;
  2228. memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size());
  2229. INIT_LIST_HEAD(&phba->hbqbuf_in_list);
  2230. /* Initialize the SLI Layer to run with lpfc HBAs. */
  2231. lpfc_sli_setup(phba);
  2232. lpfc_sli_queue_setup(phba);
  2233. retval = lpfc_mem_alloc(phba);
  2234. if (retval) {
  2235. error = retval;
  2236. goto out_free_hbqslimp;
  2237. }
  2238. /* Initialize and populate the iocb list per host. */
  2239. INIT_LIST_HEAD(&phba->lpfc_iocb_list);
  2240. for (i = 0; i < LPFC_IOCB_LIST_CNT; i++) {
  2241. iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
  2242. if (iocbq_entry == NULL) {
  2243. printk(KERN_ERR "%s: only allocated %d iocbs of "
  2244. "expected %d count. Unloading driver.\n",
  2245. __func__, i, LPFC_IOCB_LIST_CNT);
  2246. error = -ENOMEM;
  2247. goto out_free_iocbq;
  2248. }
  2249. iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
  2250. if (iotag == 0) {
  2251. kfree (iocbq_entry);
  2252. printk(KERN_ERR "%s: failed to allocate IOTAG. "
  2253. "Unloading driver.\n",
  2254. __func__);
  2255. error = -ENOMEM;
  2256. goto out_free_iocbq;
  2257. }
  2258. spin_lock_irq(&phba->hbalock);
  2259. list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
  2260. phba->total_iocbq_bufs++;
  2261. spin_unlock_irq(&phba->hbalock);
  2262. }
  2263. /* Initialize HBA structure */
  2264. phba->fc_edtov = FF_DEF_EDTOV;
  2265. phba->fc_ratov = FF_DEF_RATOV;
  2266. phba->fc_altov = FF_DEF_ALTOV;
  2267. phba->fc_arbtov = FF_DEF_ARBTOV;
  2268. INIT_LIST_HEAD(&phba->work_list);
  2269. phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT);
  2270. phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
  2271. /* Initialize the wait queue head for the kernel thread */
  2272. init_waitqueue_head(&phba->work_waitq);
  2273. /* Startup the kernel thread for this host adapter. */
  2274. phba->worker_thread = kthread_run(lpfc_do_work, phba,
  2275. "lpfc_worker_%d", phba->brd_no);
  2276. if (IS_ERR(phba->worker_thread)) {
  2277. error = PTR_ERR(phba->worker_thread);
  2278. goto out_free_iocbq;
  2279. }
  2280. /* Initialize the list of scsi buffers used by driver for scsi IO. */
  2281. spin_lock_init(&phba->scsi_buf_list_lock);
  2282. INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list);
  2283. /* Initialize list of fabric iocbs */
  2284. INIT_LIST_HEAD(&phba->fabric_iocb_list);
  2285. /* Initialize list to save ELS buffers */
  2286. INIT_LIST_HEAD(&phba->elsbuf);
  2287. vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev);
  2288. if (!vport)
  2289. goto out_kthread_stop;
  2290. shost = lpfc_shost_from_vport(vport);
  2291. phba->pport = vport;
  2292. lpfc_debugfs_initialize(vport);
  2293. pci_set_drvdata(pdev, shost);
  2294. phba->intr_type = NONE;
  2295. phba->MBslimaddr = phba->slim_memmap_p;
  2296. phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
  2297. phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
  2298. phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
  2299. phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
  2300. /* Configure and enable interrupt */
  2301. if (phba->cfg_use_msi == 2) {
  2302. /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */
  2303. error = lpfc_sli_config_port(phba, 3);
  2304. if (error)
  2305. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  2306. "0427 Firmware not capable of SLI 3 mode.\n");
  2307. else {
  2308. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  2309. "0426 Firmware capable of SLI 3 mode.\n");
  2310. /* Now, try to enable MSI-X interrupt mode */
  2311. error = lpfc_enable_msix(phba);
  2312. if (!error) {
  2313. phba->intr_type = MSIX;
  2314. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  2315. "0430 enable MSI-X mode.\n");
  2316. }
  2317. }
  2318. }
  2319. /* Fallback to MSI if MSI-X initialization failed */
  2320. if (phba->cfg_use_msi >= 1 && phba->intr_type == NONE) {
  2321. retval = pci_enable_msi(phba->pcidev);
  2322. if (!retval) {
  2323. phba->intr_type = MSI;
  2324. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  2325. "0473 enable MSI mode.\n");
  2326. } else
  2327. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  2328. "0452 enable IRQ mode.\n");
  2329. }
  2330. /* MSI-X is the only case the doesn't need to call request_irq */
  2331. if (phba->intr_type != MSIX) {
  2332. retval = request_irq(phba->pcidev->irq, lpfc_intr_handler,
  2333. IRQF_SHARED, LPFC_DRIVER_NAME, phba);
  2334. if (retval) {
  2335. lpfc_printf_log(phba, KERN_ERR, LOG_INIT, "0451 Enable "
  2336. "interrupt handler failed\n");
  2337. error = retval;
  2338. goto out_disable_msi;
  2339. } else if (phba->intr_type != MSI)
  2340. phba->intr_type = INTx;
  2341. }
  2342. if (lpfc_alloc_sysfs_attr(vport)) {
  2343. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2344. "1476 Failed to allocate sysfs attr\n");
  2345. error = -ENOMEM;
  2346. goto out_free_irq;
  2347. }
  2348. if (lpfc_sli_hba_setup(phba)) {
  2349. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2350. "1477 Failed to set up hba\n");
  2351. error = -ENODEV;
  2352. goto out_remove_device;
  2353. }
  2354. /*
  2355. * hba setup may have changed the hba_queue_depth so we need to adjust
  2356. * the value of can_queue.
  2357. */
  2358. shost->can_queue = phba->cfg_hba_queue_depth - 10;
  2359. lpfc_host_attrib_init(shost);
  2360. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  2361. spin_lock_irq(shost->host_lock);
  2362. lpfc_poll_start_timer(phba);
  2363. spin_unlock_irq(shost->host_lock);
  2364. }
  2365. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  2366. "0428 Perform SCSI scan\n");
  2367. /* Send board arrival event to upper layer */
  2368. adapter_event.event_type = FC_REG_ADAPTER_EVENT;
  2369. adapter_event.subcategory = LPFC_EVENT_ARRIVAL;
  2370. fc_host_post_vendor_event(shost, fc_get_event_number(),
  2371. sizeof(adapter_event),
  2372. (char *) &adapter_event,
  2373. SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
  2374. scsi_scan_host(shost);
  2375. return 0;
  2376. out_remove_device:
  2377. lpfc_free_sysfs_attr(vport);
  2378. spin_lock_irq(shost->host_lock);
  2379. vport->load_flag |= FC_UNLOADING;
  2380. spin_unlock_irq(shost->host_lock);
  2381. out_free_irq:
  2382. lpfc_stop_phba_timers(phba);
  2383. phba->pport->work_port_events = 0;
  2384. if (phba->intr_type == MSIX)
  2385. lpfc_disable_msix(phba);
  2386. else
  2387. free_irq(phba->pcidev->irq, phba);
  2388. out_disable_msi:
  2389. if (phba->intr_type == MSI)
  2390. pci_disable_msi(phba->pcidev);
  2391. destroy_port(vport);
  2392. out_kthread_stop:
  2393. kthread_stop(phba->worker_thread);
  2394. out_free_iocbq:
  2395. list_for_each_entry_safe(iocbq_entry, iocbq_next,
  2396. &phba->lpfc_iocb_list, list) {
  2397. kfree(iocbq_entry);
  2398. phba->total_iocbq_bufs--;
  2399. }
  2400. lpfc_mem_free(phba);
  2401. out_free_hbqslimp:
  2402. dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
  2403. phba->hbqslimp.virt, phba->hbqslimp.phys);
  2404. out_free_slim:
  2405. dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
  2406. phba->slim2p.virt, phba->slim2p.phys);
  2407. out_iounmap:
  2408. iounmap(phba->ctrl_regs_memmap_p);
  2409. out_iounmap_slim:
  2410. iounmap(phba->slim_memmap_p);
  2411. out_idr_remove:
  2412. idr_remove(&lpfc_hba_index, phba->brd_no);
  2413. out_free_phba:
  2414. kfree(phba);
  2415. out_release_regions:
  2416. pci_release_selected_regions(pdev, bars);
  2417. out_disable_device:
  2418. pci_disable_device(pdev);
  2419. out:
  2420. pci_set_drvdata(pdev, NULL);
  2421. if (shost)
  2422. scsi_host_put(shost);
  2423. return error;
  2424. }
  2425. /**
  2426. * lpfc_pci_remove_one: lpfc PCI func to unregister device from PCI subsystem.
  2427. * @pdev: pointer to PCI device
  2428. *
  2429. * This routine is to be registered to the kernel's PCI subsystem. When an
  2430. * Emulex HBA is removed from PCI bus. It perform all the necessary cleanup
  2431. * for the HBA device to be removed from the PCI subsystem properly.
  2432. **/
  2433. static void __devexit
  2434. lpfc_pci_remove_one(struct pci_dev *pdev)
  2435. {
  2436. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  2437. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  2438. struct lpfc_hba *phba = vport->phba;
  2439. int bars = pci_select_bars(pdev, IORESOURCE_MEM);
  2440. spin_lock_irq(&phba->hbalock);
  2441. vport->load_flag |= FC_UNLOADING;
  2442. spin_unlock_irq(&phba->hbalock);
  2443. kfree(vport->vname);
  2444. lpfc_free_sysfs_attr(vport);
  2445. kthread_stop(phba->worker_thread);
  2446. fc_remove_host(shost);
  2447. scsi_remove_host(shost);
  2448. lpfc_cleanup(vport);
  2449. /*
  2450. * Bring down the SLI Layer. This step disable all interrupts,
  2451. * clears the rings, discards all mailbox commands, and resets
  2452. * the HBA.
  2453. */
  2454. lpfc_sli_hba_down(phba);
  2455. lpfc_sli_brdrestart(phba);
  2456. lpfc_stop_phba_timers(phba);
  2457. spin_lock_irq(&phba->hbalock);
  2458. list_del_init(&vport->listentry);
  2459. spin_unlock_irq(&phba->hbalock);
  2460. lpfc_debugfs_terminate(vport);
  2461. if (phba->intr_type == MSIX)
  2462. lpfc_disable_msix(phba);
  2463. else {
  2464. free_irq(phba->pcidev->irq, phba);
  2465. if (phba->intr_type == MSI)
  2466. pci_disable_msi(phba->pcidev);
  2467. }
  2468. pci_set_drvdata(pdev, NULL);
  2469. scsi_host_put(shost);
  2470. /*
  2471. * Call scsi_free before mem_free since scsi bufs are released to their
  2472. * corresponding pools here.
  2473. */
  2474. lpfc_scsi_free(phba);
  2475. lpfc_mem_free(phba);
  2476. dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
  2477. phba->hbqslimp.virt, phba->hbqslimp.phys);
  2478. /* Free resources associated with SLI2 interface */
  2479. dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
  2480. phba->slim2p.virt, phba->slim2p.phys);
  2481. /* unmap adapter SLIM and Control Registers */
  2482. iounmap(phba->ctrl_regs_memmap_p);
  2483. iounmap(phba->slim_memmap_p);
  2484. idr_remove(&lpfc_hba_index, phba->brd_no);
  2485. kfree(phba);
  2486. pci_release_selected_regions(pdev, bars);
  2487. pci_disable_device(pdev);
  2488. }
  2489. /**
  2490. * lpfc_io_error_detected: Driver method for handling PCI I/O error detected.
  2491. * @pdev: pointer to PCI device.
  2492. * @state: the current PCI connection state.
  2493. *
  2494. * This routine is registered to the PCI subsystem for error handling. This
  2495. * function is called by the PCI subsystem after a PCI bus error affecting
  2496. * this device has been detected. When this function is invoked, it will
  2497. * need to stop all the I/Os and interrupt(s) to the device. Once that is
  2498. * done, it will return PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to
  2499. * perform proper recovery as desired.
  2500. *
  2501. * Return codes
  2502. * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
  2503. * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
  2504. **/
  2505. static pci_ers_result_t lpfc_io_error_detected(struct pci_dev *pdev,
  2506. pci_channel_state_t state)
  2507. {
  2508. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  2509. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  2510. struct lpfc_sli *psli = &phba->sli;
  2511. struct lpfc_sli_ring *pring;
  2512. if (state == pci_channel_io_perm_failure) {
  2513. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2514. "0472 PCI channel I/O permanent failure\n");
  2515. /* Block all SCSI devices' I/Os on the host */
  2516. lpfc_scsi_dev_block(phba);
  2517. /* Clean up all driver's outstanding SCSI I/Os */
  2518. lpfc_sli_flush_fcp_rings(phba);
  2519. return PCI_ERS_RESULT_DISCONNECT;
  2520. }
  2521. pci_disable_device(pdev);
  2522. /*
  2523. * There may be I/Os dropped by the firmware.
  2524. * Error iocb (I/O) on txcmplq and let the SCSI layer
  2525. * retry it after re-establishing link.
  2526. */
  2527. pring = &psli->ring[psli->fcp_ring];
  2528. lpfc_sli_abort_iocb_ring(phba, pring);
  2529. if (phba->intr_type == MSIX)
  2530. lpfc_disable_msix(phba);
  2531. else {
  2532. free_irq(phba->pcidev->irq, phba);
  2533. if (phba->intr_type == MSI)
  2534. pci_disable_msi(phba->pcidev);
  2535. }
  2536. /* Request a slot reset. */
  2537. return PCI_ERS_RESULT_NEED_RESET;
  2538. }
  2539. /**
  2540. * lpfc_io_slot_reset: Restart a PCI device from scratch.
  2541. * @pdev: pointer to PCI device.
  2542. *
  2543. * This routine is registered to the PCI subsystem for error handling. This is
  2544. * called after PCI bus has been reset to restart the PCI card from scratch,
  2545. * as if from a cold-boot. During the PCI subsystem error recovery, after the
  2546. * driver returns PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform
  2547. * proper error recovery and then call this routine before calling the .resume
  2548. * method to recover the device. This function will initialize the HBA device,
  2549. * enable the interrupt, but it will just put the HBA to offline state without
  2550. * passing any I/O traffic.
  2551. *
  2552. * Return codes
  2553. * PCI_ERS_RESULT_RECOVERED - the device has been recovered
  2554. * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
  2555. */
  2556. static pci_ers_result_t lpfc_io_slot_reset(struct pci_dev *pdev)
  2557. {
  2558. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  2559. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  2560. struct lpfc_sli *psli = &phba->sli;
  2561. int error, retval;
  2562. dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
  2563. if (pci_enable_device_mem(pdev)) {
  2564. printk(KERN_ERR "lpfc: Cannot re-enable "
  2565. "PCI device after reset.\n");
  2566. return PCI_ERS_RESULT_DISCONNECT;
  2567. }
  2568. pci_set_master(pdev);
  2569. spin_lock_irq(&phba->hbalock);
  2570. psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
  2571. spin_unlock_irq(&phba->hbalock);
  2572. /* Enable configured interrupt method */
  2573. phba->intr_type = NONE;
  2574. if (phba->cfg_use_msi == 2) {
  2575. /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */
  2576. error = lpfc_sli_config_port(phba, 3);
  2577. if (error)
  2578. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  2579. "0478 Firmware not capable of SLI 3 mode.\n");
  2580. else {
  2581. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  2582. "0479 Firmware capable of SLI 3 mode.\n");
  2583. /* Now, try to enable MSI-X interrupt mode */
  2584. error = lpfc_enable_msix(phba);
  2585. if (!error) {
  2586. phba->intr_type = MSIX;
  2587. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  2588. "0480 enable MSI-X mode.\n");
  2589. }
  2590. }
  2591. }
  2592. /* Fallback to MSI if MSI-X initialization failed */
  2593. if (phba->cfg_use_msi >= 1 && phba->intr_type == NONE) {
  2594. retval = pci_enable_msi(phba->pcidev);
  2595. if (!retval) {
  2596. phba->intr_type = MSI;
  2597. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  2598. "0481 enable MSI mode.\n");
  2599. } else
  2600. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  2601. "0470 enable IRQ mode.\n");
  2602. }
  2603. /* MSI-X is the only case the doesn't need to call request_irq */
  2604. if (phba->intr_type != MSIX) {
  2605. retval = request_irq(phba->pcidev->irq, lpfc_intr_handler,
  2606. IRQF_SHARED, LPFC_DRIVER_NAME, phba);
  2607. if (retval) {
  2608. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2609. "0471 Enable interrupt handler "
  2610. "failed\n");
  2611. } else if (phba->intr_type != MSI)
  2612. phba->intr_type = INTx;
  2613. }
  2614. /* Take device offline; this will perform cleanup */
  2615. lpfc_offline(phba);
  2616. lpfc_sli_brdrestart(phba);
  2617. return PCI_ERS_RESULT_RECOVERED;
  2618. }
  2619. /**
  2620. * lpfc_io_resume: Resume PCI I/O operation.
  2621. * @pdev: pointer to PCI device
  2622. *
  2623. * This routine is registered to the PCI subsystem for error handling. It is
  2624. * called when kernel error recovery tells the lpfc driver that it is ok to
  2625. * resume normal PCI operation after PCI bus error recovery. After this call,
  2626. * traffic can start to flow from this device again.
  2627. */
  2628. static void lpfc_io_resume(struct pci_dev *pdev)
  2629. {
  2630. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  2631. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  2632. lpfc_online(phba);
  2633. }
  2634. static struct pci_device_id lpfc_id_table[] = {
  2635. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER,
  2636. PCI_ANY_ID, PCI_ANY_ID, },
  2637. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY,
  2638. PCI_ANY_ID, PCI_ANY_ID, },
  2639. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR,
  2640. PCI_ANY_ID, PCI_ANY_ID, },
  2641. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS,
  2642. PCI_ANY_ID, PCI_ANY_ID, },
  2643. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR,
  2644. PCI_ANY_ID, PCI_ANY_ID, },
  2645. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY,
  2646. PCI_ANY_ID, PCI_ANY_ID, },
  2647. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY,
  2648. PCI_ANY_ID, PCI_ANY_ID, },
  2649. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY,
  2650. PCI_ANY_ID, PCI_ANY_ID, },
  2651. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY,
  2652. PCI_ANY_ID, PCI_ANY_ID, },
  2653. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE,
  2654. PCI_ANY_ID, PCI_ANY_ID, },
  2655. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP,
  2656. PCI_ANY_ID, PCI_ANY_ID, },
  2657. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP,
  2658. PCI_ANY_ID, PCI_ANY_ID, },
  2659. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS,
  2660. PCI_ANY_ID, PCI_ANY_ID, },
  2661. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP,
  2662. PCI_ANY_ID, PCI_ANY_ID, },
  2663. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP,
  2664. PCI_ANY_ID, PCI_ANY_ID, },
  2665. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID,
  2666. PCI_ANY_ID, PCI_ANY_ID, },
  2667. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB,
  2668. PCI_ANY_ID, PCI_ANY_ID, },
  2669. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR,
  2670. PCI_ANY_ID, PCI_ANY_ID, },
  2671. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HORNET,
  2672. PCI_ANY_ID, PCI_ANY_ID, },
  2673. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP,
  2674. PCI_ANY_ID, PCI_ANY_ID, },
  2675. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP,
  2676. PCI_ANY_ID, PCI_ANY_ID, },
  2677. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID,
  2678. PCI_ANY_ID, PCI_ANY_ID, },
  2679. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB,
  2680. PCI_ANY_ID, PCI_ANY_ID, },
  2681. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY,
  2682. PCI_ANY_ID, PCI_ANY_ID, },
  2683. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101,
  2684. PCI_ANY_ID, PCI_ANY_ID, },
  2685. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S,
  2686. PCI_ANY_ID, PCI_ANY_ID, },
  2687. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S,
  2688. PCI_ANY_ID, PCI_ANY_ID, },
  2689. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S,
  2690. PCI_ANY_ID, PCI_ANY_ID, },
  2691. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT,
  2692. PCI_ANY_ID, PCI_ANY_ID, },
  2693. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID,
  2694. PCI_ANY_ID, PCI_ANY_ID, },
  2695. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB,
  2696. PCI_ANY_ID, PCI_ANY_ID, },
  2697. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP,
  2698. PCI_ANY_ID, PCI_ANY_ID, },
  2699. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP,
  2700. PCI_ANY_ID, PCI_ANY_ID, },
  2701. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S,
  2702. PCI_ANY_ID, PCI_ANY_ID, },
  2703. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_VF,
  2704. PCI_ANY_ID, PCI_ANY_ID, },
  2705. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_PF,
  2706. PCI_ANY_ID, PCI_ANY_ID, },
  2707. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_S,
  2708. PCI_ANY_ID, PCI_ANY_ID, },
  2709. { 0 }
  2710. };
  2711. MODULE_DEVICE_TABLE(pci, lpfc_id_table);
  2712. static struct pci_error_handlers lpfc_err_handler = {
  2713. .error_detected = lpfc_io_error_detected,
  2714. .slot_reset = lpfc_io_slot_reset,
  2715. .resume = lpfc_io_resume,
  2716. };
  2717. static struct pci_driver lpfc_driver = {
  2718. .name = LPFC_DRIVER_NAME,
  2719. .id_table = lpfc_id_table,
  2720. .probe = lpfc_pci_probe_one,
  2721. .remove = __devexit_p(lpfc_pci_remove_one),
  2722. .err_handler = &lpfc_err_handler,
  2723. };
  2724. /**
  2725. * lpfc_init: lpfc module initialization routine.
  2726. *
  2727. * This routine is to be invoked when the lpfc module is loaded into the
  2728. * kernel. The special kernel macro module_init() is used to indicate the
  2729. * role of this routine to the kernel as lpfc module entry point.
  2730. *
  2731. * Return codes
  2732. * 0 - successful
  2733. * -ENOMEM - FC attach transport failed
  2734. * all others - failed
  2735. */
  2736. static int __init
  2737. lpfc_init(void)
  2738. {
  2739. int error = 0;
  2740. printk(LPFC_MODULE_DESC "\n");
  2741. printk(LPFC_COPYRIGHT "\n");
  2742. if (lpfc_enable_npiv) {
  2743. lpfc_transport_functions.vport_create = lpfc_vport_create;
  2744. lpfc_transport_functions.vport_delete = lpfc_vport_delete;
  2745. }
  2746. lpfc_transport_template =
  2747. fc_attach_transport(&lpfc_transport_functions);
  2748. if (lpfc_transport_template == NULL)
  2749. return -ENOMEM;
  2750. if (lpfc_enable_npiv) {
  2751. lpfc_vport_transport_template =
  2752. fc_attach_transport(&lpfc_vport_transport_functions);
  2753. if (lpfc_vport_transport_template == NULL) {
  2754. fc_release_transport(lpfc_transport_template);
  2755. return -ENOMEM;
  2756. }
  2757. }
  2758. error = pci_register_driver(&lpfc_driver);
  2759. if (error) {
  2760. fc_release_transport(lpfc_transport_template);
  2761. if (lpfc_enable_npiv)
  2762. fc_release_transport(lpfc_vport_transport_template);
  2763. }
  2764. return error;
  2765. }
  2766. /**
  2767. * lpfc_exit: lpfc module removal routine.
  2768. *
  2769. * This routine is invoked when the lpfc module is removed from the kernel.
  2770. * The special kernel macro module_exit() is used to indicate the role of
  2771. * this routine to the kernel as lpfc module exit point.
  2772. */
  2773. static void __exit
  2774. lpfc_exit(void)
  2775. {
  2776. pci_unregister_driver(&lpfc_driver);
  2777. fc_release_transport(lpfc_transport_template);
  2778. if (lpfc_enable_npiv)
  2779. fc_release_transport(lpfc_vport_transport_template);
  2780. }
  2781. module_init(lpfc_init);
  2782. module_exit(lpfc_exit);
  2783. MODULE_LICENSE("GPL");
  2784. MODULE_DESCRIPTION(LPFC_MODULE_DESC);
  2785. MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com");
  2786. MODULE_VERSION("0:" LPFC_DRIVER_VERSION);