lpfc_init.c 96 KB

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