lpfc_hbadisc.c 77 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2007 Emulex. All rights reserved. *
  5. * EMULEX and SLI are trademarks of Emulex. *
  6. * www.emulex.com *
  7. * Portions Copyright (C) 2004-2005 Christoph Hellwig *
  8. * *
  9. * This program is free software; you can redistribute it and/or *
  10. * modify it under the terms of version 2 of the GNU General *
  11. * Public License as published by the Free Software Foundation. *
  12. * This program is distributed in the hope that it will be useful. *
  13. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
  14. * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
  15. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
  16. * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
  17. * TO BE LEGALLY INVALID. See the GNU General Public License for *
  18. * more details, a copy of which can be found in the file COPYING *
  19. * included with this package. *
  20. *******************************************************************/
  21. #include <linux/blkdev.h>
  22. #include <linux/pci.h>
  23. #include <linux/kthread.h>
  24. #include <linux/interrupt.h>
  25. #include <scsi/scsi.h>
  26. #include <scsi/scsi_device.h>
  27. #include <scsi/scsi_host.h>
  28. #include <scsi/scsi_transport_fc.h>
  29. #include "lpfc_hw.h"
  30. #include "lpfc_disc.h"
  31. #include "lpfc_sli.h"
  32. #include "lpfc_scsi.h"
  33. #include "lpfc.h"
  34. #include "lpfc_logmsg.h"
  35. #include "lpfc_crtn.h"
  36. #include "lpfc_vport.h"
  37. #include "lpfc_debugfs.h"
  38. /* AlpaArray for assignment of scsid for scan-down and bind_method */
  39. static uint8_t lpfcAlpaArray[] = {
  40. 0xEF, 0xE8, 0xE4, 0xE2, 0xE1, 0xE0, 0xDC, 0xDA, 0xD9, 0xD6,
  41. 0xD5, 0xD4, 0xD3, 0xD2, 0xD1, 0xCE, 0xCD, 0xCC, 0xCB, 0xCA,
  42. 0xC9, 0xC7, 0xC6, 0xC5, 0xC3, 0xBC, 0xBA, 0xB9, 0xB6, 0xB5,
  43. 0xB4, 0xB3, 0xB2, 0xB1, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9,
  44. 0xA7, 0xA6, 0xA5, 0xA3, 0x9F, 0x9E, 0x9D, 0x9B, 0x98, 0x97,
  45. 0x90, 0x8F, 0x88, 0x84, 0x82, 0x81, 0x80, 0x7C, 0x7A, 0x79,
  46. 0x76, 0x75, 0x74, 0x73, 0x72, 0x71, 0x6E, 0x6D, 0x6C, 0x6B,
  47. 0x6A, 0x69, 0x67, 0x66, 0x65, 0x63, 0x5C, 0x5A, 0x59, 0x56,
  48. 0x55, 0x54, 0x53, 0x52, 0x51, 0x4E, 0x4D, 0x4C, 0x4B, 0x4A,
  49. 0x49, 0x47, 0x46, 0x45, 0x43, 0x3C, 0x3A, 0x39, 0x36, 0x35,
  50. 0x34, 0x33, 0x32, 0x31, 0x2E, 0x2D, 0x2C, 0x2B, 0x2A, 0x29,
  51. 0x27, 0x26, 0x25, 0x23, 0x1F, 0x1E, 0x1D, 0x1B, 0x18, 0x17,
  52. 0x10, 0x0F, 0x08, 0x04, 0x02, 0x01
  53. };
  54. static void lpfc_disc_timeout_handler(struct lpfc_vport *);
  55. void
  56. lpfc_terminate_rport_io(struct fc_rport *rport)
  57. {
  58. struct lpfc_rport_data *rdata;
  59. struct lpfc_nodelist * ndlp;
  60. struct lpfc_hba *phba;
  61. rdata = rport->dd_data;
  62. ndlp = rdata->pnode;
  63. if (!ndlp) {
  64. if (rport->roles & FC_RPORT_ROLE_FCP_TARGET)
  65. printk(KERN_ERR "Cannot find remote node"
  66. " to terminate I/O Data x%x\n",
  67. rport->port_id);
  68. return;
  69. }
  70. phba = ndlp->vport->phba;
  71. lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_RPORT,
  72. "rport terminate: sid:x%x did:x%x flg:x%x",
  73. ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag);
  74. if (ndlp->nlp_sid != NLP_NO_SID) {
  75. lpfc_sli_abort_iocb(phba, &phba->sli.ring[phba->sli.fcp_ring],
  76. ndlp->nlp_sid, 0, 0, LPFC_CTX_TGT);
  77. }
  78. return;
  79. }
  80. /*
  81. * This function will be called when dev_loss_tmo fire.
  82. */
  83. void
  84. lpfc_dev_loss_tmo_callbk(struct fc_rport *rport)
  85. {
  86. struct lpfc_rport_data *rdata;
  87. struct lpfc_nodelist * ndlp;
  88. struct lpfc_vport *vport;
  89. struct lpfc_hba *phba;
  90. struct completion devloss_compl;
  91. struct lpfc_work_evt *evtp;
  92. rdata = rport->dd_data;
  93. ndlp = rdata->pnode;
  94. if (!ndlp) {
  95. if (rport->scsi_target_id != -1) {
  96. printk(KERN_ERR "Cannot find remote node"
  97. " for rport in dev_loss_tmo_callbk x%x\n",
  98. rport->port_id);
  99. }
  100. return;
  101. }
  102. vport = ndlp->vport;
  103. phba = vport->phba;
  104. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
  105. "rport devlosscb: sid:x%x did:x%x flg:x%x",
  106. ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag);
  107. init_completion(&devloss_compl);
  108. evtp = &ndlp->dev_loss_evt;
  109. if (!list_empty(&evtp->evt_listp))
  110. return;
  111. spin_lock_irq(&phba->hbalock);
  112. evtp->evt_arg1 = ndlp;
  113. evtp->evt_arg2 = &devloss_compl;
  114. evtp->evt = LPFC_EVT_DEV_LOSS;
  115. list_add_tail(&evtp->evt_listp, &phba->work_list);
  116. if (phba->work_wait)
  117. wake_up(phba->work_wait);
  118. spin_unlock_irq(&phba->hbalock);
  119. wait_for_completion(&devloss_compl);
  120. return;
  121. }
  122. /*
  123. * This function is called from the worker thread when dev_loss_tmo
  124. * expire.
  125. */
  126. void
  127. lpfc_dev_loss_tmo_handler(struct lpfc_nodelist *ndlp)
  128. {
  129. struct lpfc_rport_data *rdata;
  130. struct fc_rport *rport;
  131. struct lpfc_vport *vport;
  132. struct lpfc_hba *phba;
  133. uint8_t *name;
  134. int warn_on = 0;
  135. rport = ndlp->rport;
  136. if (!rport)
  137. return;
  138. rdata = rport->dd_data;
  139. name = (uint8_t *) &ndlp->nlp_portname;
  140. vport = ndlp->vport;
  141. phba = vport->phba;
  142. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
  143. "rport devlosstmo:did:x%x type:x%x id:x%x",
  144. ndlp->nlp_DID, ndlp->nlp_type, rport->scsi_target_id);
  145. if (!(vport->load_flag & FC_UNLOADING) &&
  146. ndlp->nlp_state == NLP_STE_MAPPED_NODE)
  147. return;
  148. if (ndlp->nlp_type & NLP_FABRIC) {
  149. int put_node;
  150. int put_rport;
  151. /* We will clean up these Nodes in linkup */
  152. put_node = rdata->pnode != NULL;
  153. put_rport = ndlp->rport != NULL;
  154. rdata->pnode = NULL;
  155. ndlp->rport = NULL;
  156. if (put_node)
  157. lpfc_nlp_put(ndlp);
  158. if (put_rport)
  159. put_device(&rport->dev);
  160. return;
  161. }
  162. if (ndlp->nlp_sid != NLP_NO_SID) {
  163. warn_on = 1;
  164. /* flush the target */
  165. lpfc_sli_abort_iocb(phba, &phba->sli.ring[phba->sli.fcp_ring],
  166. ndlp->nlp_sid, 0, 0, LPFC_CTX_TGT);
  167. }
  168. if (vport->load_flag & FC_UNLOADING)
  169. warn_on = 0;
  170. if (warn_on) {
  171. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
  172. "%d (%d):0203 Devloss timeout on "
  173. "WWPN %x:%x:%x:%x:%x:%x:%x:%x "
  174. "NPort x%x Data: x%x x%x x%x\n",
  175. phba->brd_no, vport->vpi,
  176. *name, *(name+1), *(name+2), *(name+3),
  177. *(name+4), *(name+5), *(name+6), *(name+7),
  178. ndlp->nlp_DID, ndlp->nlp_flag,
  179. ndlp->nlp_state, ndlp->nlp_rpi);
  180. } else {
  181. lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
  182. "%d (%d):0204 Devloss timeout on "
  183. "WWPN %x:%x:%x:%x:%x:%x:%x:%x "
  184. "NPort x%x Data: x%x x%x x%x\n",
  185. phba->brd_no, vport->vpi,
  186. *name, *(name+1), *(name+2), *(name+3),
  187. *(name+4), *(name+5), *(name+6), *(name+7),
  188. ndlp->nlp_DID, ndlp->nlp_flag,
  189. ndlp->nlp_state, ndlp->nlp_rpi);
  190. }
  191. if (!(vport->load_flag & FC_UNLOADING) &&
  192. !(ndlp->nlp_flag & NLP_DELAY_TMO) &&
  193. !(ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
  194. (ndlp->nlp_state != NLP_STE_UNMAPPED_NODE))
  195. lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
  196. else {
  197. int put_node;
  198. int put_rport;
  199. put_node = rdata->pnode != NULL;
  200. put_rport = ndlp->rport != NULL;
  201. rdata->pnode = NULL;
  202. ndlp->rport = NULL;
  203. if (put_node)
  204. lpfc_nlp_put(ndlp);
  205. if (put_rport)
  206. put_device(&rport->dev);
  207. }
  208. }
  209. void
  210. lpfc_worker_wake_up(struct lpfc_hba *phba)
  211. {
  212. wake_up(phba->work_wait);
  213. return;
  214. }
  215. static void
  216. lpfc_work_list_done(struct lpfc_hba *phba)
  217. {
  218. struct lpfc_work_evt *evtp = NULL;
  219. struct lpfc_nodelist *ndlp;
  220. struct lpfc_vport *vport;
  221. int free_evt;
  222. spin_lock_irq(&phba->hbalock);
  223. while (!list_empty(&phba->work_list)) {
  224. list_remove_head((&phba->work_list), evtp, typeof(*evtp),
  225. evt_listp);
  226. spin_unlock_irq(&phba->hbalock);
  227. free_evt = 1;
  228. switch (evtp->evt) {
  229. case LPFC_EVT_DEV_LOSS_DELAY:
  230. free_evt = 0; /* evt is part of ndlp */
  231. ndlp = (struct lpfc_nodelist *) (evtp->evt_arg1);
  232. vport = ndlp->vport;
  233. if (!vport)
  234. break;
  235. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
  236. "rport devlossdly:did:x%x flg:x%x",
  237. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  238. if (!(vport->load_flag & FC_UNLOADING) &&
  239. !(ndlp->nlp_flag & NLP_DELAY_TMO) &&
  240. !(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
  241. lpfc_disc_state_machine(vport, ndlp, NULL,
  242. NLP_EVT_DEVICE_RM);
  243. }
  244. break;
  245. case LPFC_EVT_ELS_RETRY:
  246. ndlp = (struct lpfc_nodelist *) (evtp->evt_arg1);
  247. lpfc_els_retry_delay_handler(ndlp);
  248. free_evt = 0; /* evt is part of ndlp */
  249. break;
  250. case LPFC_EVT_DEV_LOSS:
  251. ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
  252. lpfc_nlp_get(ndlp);
  253. lpfc_dev_loss_tmo_handler(ndlp);
  254. free_evt = 0;
  255. complete((struct completion *)(evtp->evt_arg2));
  256. lpfc_nlp_put(ndlp);
  257. break;
  258. case LPFC_EVT_ONLINE:
  259. if (phba->link_state < LPFC_LINK_DOWN)
  260. *(int *) (evtp->evt_arg1) = lpfc_online(phba);
  261. else
  262. *(int *) (evtp->evt_arg1) = 0;
  263. complete((struct completion *)(evtp->evt_arg2));
  264. break;
  265. case LPFC_EVT_OFFLINE_PREP:
  266. if (phba->link_state >= LPFC_LINK_DOWN)
  267. lpfc_offline_prep(phba);
  268. *(int *)(evtp->evt_arg1) = 0;
  269. complete((struct completion *)(evtp->evt_arg2));
  270. break;
  271. case LPFC_EVT_OFFLINE:
  272. lpfc_offline(phba);
  273. lpfc_sli_brdrestart(phba);
  274. *(int *)(evtp->evt_arg1) =
  275. lpfc_sli_brdready(phba, HS_FFRDY | HS_MBRDY);
  276. lpfc_unblock_mgmt_io(phba);
  277. complete((struct completion *)(evtp->evt_arg2));
  278. break;
  279. case LPFC_EVT_WARM_START:
  280. lpfc_offline(phba);
  281. lpfc_reset_barrier(phba);
  282. lpfc_sli_brdreset(phba);
  283. lpfc_hba_down_post(phba);
  284. *(int *)(evtp->evt_arg1) =
  285. lpfc_sli_brdready(phba, HS_MBRDY);
  286. lpfc_unblock_mgmt_io(phba);
  287. complete((struct completion *)(evtp->evt_arg2));
  288. break;
  289. case LPFC_EVT_KILL:
  290. lpfc_offline(phba);
  291. *(int *)(evtp->evt_arg1)
  292. = (phba->pport->stopped)
  293. ? 0 : lpfc_sli_brdkill(phba);
  294. lpfc_unblock_mgmt_io(phba);
  295. complete((struct completion *)(evtp->evt_arg2));
  296. break;
  297. }
  298. if (free_evt)
  299. kfree(evtp);
  300. spin_lock_irq(&phba->hbalock);
  301. }
  302. spin_unlock_irq(&phba->hbalock);
  303. }
  304. void
  305. lpfc_work_done(struct lpfc_hba *phba)
  306. {
  307. struct lpfc_sli_ring *pring;
  308. uint32_t ha_copy, status, control, work_port_events;
  309. struct lpfc_vport *vport;
  310. spin_lock_irq(&phba->hbalock);
  311. ha_copy = phba->work_ha;
  312. phba->work_ha = 0;
  313. spin_unlock_irq(&phba->hbalock);
  314. if (ha_copy & HA_ERATT)
  315. lpfc_handle_eratt(phba);
  316. if (ha_copy & HA_MBATT)
  317. lpfc_sli_handle_mb_event(phba);
  318. if (ha_copy & HA_LATT)
  319. lpfc_handle_latt(phba);
  320. spin_lock_irq(&phba->hbalock);
  321. list_for_each_entry(vport, &phba->port_list, listentry) {
  322. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  323. if (!scsi_host_get(shost)) {
  324. continue;
  325. }
  326. spin_unlock_irq(&phba->hbalock);
  327. work_port_events = vport->work_port_events;
  328. if (work_port_events & WORKER_DISC_TMO)
  329. lpfc_disc_timeout_handler(vport);
  330. if (work_port_events & WORKER_ELS_TMO)
  331. lpfc_els_timeout_handler(vport);
  332. if (work_port_events & WORKER_HB_TMO)
  333. lpfc_hb_timeout_handler(phba);
  334. if (work_port_events & WORKER_MBOX_TMO)
  335. lpfc_mbox_timeout_handler(phba);
  336. if (work_port_events & WORKER_FABRIC_BLOCK_TMO)
  337. lpfc_unblock_fabric_iocbs(phba);
  338. if (work_port_events & WORKER_FDMI_TMO)
  339. lpfc_fdmi_timeout_handler(vport);
  340. if (work_port_events & WORKER_RAMP_DOWN_QUEUE)
  341. lpfc_ramp_down_queue_handler(phba);
  342. if (work_port_events & WORKER_RAMP_UP_QUEUE)
  343. lpfc_ramp_up_queue_handler(phba);
  344. spin_lock_irq(&vport->work_port_lock);
  345. vport->work_port_events &= ~work_port_events;
  346. spin_unlock_irq(&vport->work_port_lock);
  347. scsi_host_put(shost);
  348. spin_lock_irq(&phba->hbalock);
  349. }
  350. spin_unlock_irq(&phba->hbalock);
  351. pring = &phba->sli.ring[LPFC_ELS_RING];
  352. status = (ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
  353. status >>= (4*LPFC_ELS_RING);
  354. if ((status & HA_RXMASK)
  355. || (pring->flag & LPFC_DEFERRED_RING_EVENT)) {
  356. if (pring->flag & LPFC_STOP_IOCB_MASK) {
  357. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  358. } else {
  359. lpfc_sli_handle_slow_ring_event(phba, pring,
  360. (status &
  361. HA_RXMASK));
  362. pring->flag &= ~LPFC_DEFERRED_RING_EVENT;
  363. }
  364. /*
  365. * Turn on Ring interrupts
  366. */
  367. spin_lock_irq(&phba->hbalock);
  368. control = readl(phba->HCregaddr);
  369. if (!(control & (HC_R0INT_ENA << LPFC_ELS_RING))) {
  370. control |= (HC_R0INT_ENA << LPFC_ELS_RING);
  371. writel(control, phba->HCregaddr);
  372. readl(phba->HCregaddr); /* flush */
  373. }
  374. spin_unlock_irq(&phba->hbalock);
  375. }
  376. lpfc_work_list_done(phba);
  377. }
  378. static int
  379. check_work_wait_done(struct lpfc_hba *phba)
  380. {
  381. struct lpfc_vport *vport;
  382. struct lpfc_sli_ring *pring;
  383. int rc = 0;
  384. spin_lock_irq(&phba->hbalock);
  385. list_for_each_entry(vport, &phba->port_list, listentry) {
  386. if (vport->work_port_events) {
  387. rc = 1;
  388. goto exit;
  389. }
  390. }
  391. if (phba->work_ha || (!list_empty(&phba->work_list)) ||
  392. kthread_should_stop()) {
  393. rc = 1;
  394. goto exit;
  395. }
  396. pring = &phba->sli.ring[LPFC_ELS_RING];
  397. if (pring->flag & LPFC_DEFERRED_RING_EVENT)
  398. rc = 1;
  399. exit:
  400. if (rc)
  401. phba->work_found++;
  402. else
  403. phba->work_found = 0;
  404. spin_unlock_irq(&phba->hbalock);
  405. return rc;
  406. }
  407. int
  408. lpfc_do_work(void *p)
  409. {
  410. struct lpfc_hba *phba = p;
  411. int rc;
  412. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(work_waitq);
  413. set_user_nice(current, -20);
  414. phba->work_wait = &work_waitq;
  415. phba->work_found = 0;
  416. while (1) {
  417. rc = wait_event_interruptible(work_waitq,
  418. check_work_wait_done(phba));
  419. BUG_ON(rc);
  420. if (kthread_should_stop())
  421. break;
  422. lpfc_work_done(phba);
  423. /* If there is alot of slow ring work, like during link up
  424. * check_work_wait_done() may cause this thread to not give
  425. * up the CPU for very long periods of time. This may cause
  426. * soft lockups or other problems. To avoid these situations
  427. * give up the CPU here after LPFC_MAX_WORKER_ITERATION
  428. * consecutive iterations.
  429. */
  430. if (phba->work_found >= LPFC_MAX_WORKER_ITERATION) {
  431. phba->work_found = 0;
  432. schedule();
  433. }
  434. }
  435. phba->work_wait = NULL;
  436. return 0;
  437. }
  438. /*
  439. * This is only called to handle FC worker events. Since this a rare
  440. * occurance, we allocate a struct lpfc_work_evt structure here instead of
  441. * embedding it in the IOCB.
  442. */
  443. int
  444. lpfc_workq_post_event(struct lpfc_hba *phba, void *arg1, void *arg2,
  445. uint32_t evt)
  446. {
  447. struct lpfc_work_evt *evtp;
  448. unsigned long flags;
  449. /*
  450. * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will
  451. * be queued to worker thread for processing
  452. */
  453. evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_ATOMIC);
  454. if (!evtp)
  455. return 0;
  456. evtp->evt_arg1 = arg1;
  457. evtp->evt_arg2 = arg2;
  458. evtp->evt = evt;
  459. spin_lock_irqsave(&phba->hbalock, flags);
  460. list_add_tail(&evtp->evt_listp, &phba->work_list);
  461. if (phba->work_wait)
  462. lpfc_worker_wake_up(phba);
  463. spin_unlock_irqrestore(&phba->hbalock, flags);
  464. return 1;
  465. }
  466. void
  467. lpfc_cleanup_rpis(struct lpfc_vport *vport, int remove)
  468. {
  469. struct lpfc_hba *phba = vport->phba;
  470. struct lpfc_nodelist *ndlp, *next_ndlp;
  471. int rc;
  472. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
  473. if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
  474. continue;
  475. if (phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN)
  476. lpfc_unreg_rpi(vport, ndlp);
  477. /* Leave Fabric nodes alone on link down */
  478. if (!remove && ndlp->nlp_type & NLP_FABRIC)
  479. continue;
  480. rc = lpfc_disc_state_machine(vport, ndlp, NULL,
  481. remove
  482. ? NLP_EVT_DEVICE_RM
  483. : NLP_EVT_DEVICE_RECOVERY);
  484. }
  485. if (phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) {
  486. lpfc_mbx_unreg_vpi(vport);
  487. vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  488. }
  489. }
  490. static void
  491. lpfc_linkdown_port(struct lpfc_vport *vport)
  492. {
  493. struct lpfc_nodelist *ndlp, *next_ndlp;
  494. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  495. fc_host_post_event(shost, fc_get_event_number(), FCH_EVT_LINKDOWN, 0);
  496. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  497. "Link Down: state:x%x rtry:x%x flg:x%x",
  498. vport->port_state, vport->fc_ns_retry, vport->fc_flag);
  499. /* Cleanup any outstanding RSCN activity */
  500. lpfc_els_flush_rscn(vport);
  501. /* Cleanup any outstanding ELS commands */
  502. lpfc_els_flush_cmd(vport);
  503. lpfc_cleanup_rpis(vport, 0);
  504. /* free any ndlp's on unused list */
  505. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp)
  506. /* free any ndlp's in unused state */
  507. if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
  508. lpfc_drop_node(vport, ndlp);
  509. /* Turn off discovery timer if its running */
  510. lpfc_can_disctmo(vport);
  511. }
  512. int
  513. lpfc_linkdown(struct lpfc_hba *phba)
  514. {
  515. struct lpfc_vport *vport = phba->pport;
  516. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  517. struct lpfc_vport *port_iterator;
  518. LPFC_MBOXQ_t *mb;
  519. if (phba->link_state == LPFC_LINK_DOWN) {
  520. return 0;
  521. }
  522. spin_lock_irq(&phba->hbalock);
  523. if (phba->link_state > LPFC_LINK_DOWN) {
  524. phba->link_state = LPFC_LINK_DOWN;
  525. phba->pport->fc_flag &= ~FC_LBIT;
  526. }
  527. spin_unlock_irq(&phba->hbalock);
  528. list_for_each_entry(port_iterator, &phba->port_list, listentry) {
  529. /* Issue a LINK DOWN event to all nodes */
  530. lpfc_linkdown_port(port_iterator);
  531. }
  532. /* Clean up any firmware default rpi's */
  533. mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  534. if (mb) {
  535. lpfc_unreg_did(phba, 0xffff, 0xffffffff, mb);
  536. mb->vport = vport;
  537. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  538. if (lpfc_sli_issue_mbox(phba, mb, (MBX_NOWAIT | MBX_STOP_IOCB))
  539. == MBX_NOT_FINISHED) {
  540. mempool_free(mb, phba->mbox_mem_pool);
  541. }
  542. }
  543. /* Setup myDID for link up if we are in pt2pt mode */
  544. if (phba->pport->fc_flag & FC_PT2PT) {
  545. phba->pport->fc_myDID = 0;
  546. mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  547. if (mb) {
  548. lpfc_config_link(phba, mb);
  549. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  550. mb->vport = vport;
  551. if (lpfc_sli_issue_mbox(phba, mb,
  552. (MBX_NOWAIT | MBX_STOP_IOCB))
  553. == MBX_NOT_FINISHED) {
  554. mempool_free(mb, phba->mbox_mem_pool);
  555. }
  556. }
  557. spin_lock_irq(shost->host_lock);
  558. phba->pport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI);
  559. spin_unlock_irq(shost->host_lock);
  560. }
  561. return 0;
  562. }
  563. static void
  564. lpfc_linkup_cleanup_nodes(struct lpfc_vport *vport)
  565. {
  566. struct lpfc_nodelist *ndlp;
  567. list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
  568. if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
  569. continue;
  570. if (ndlp->nlp_type & NLP_FABRIC) {
  571. /* On Linkup its safe to clean up the ndlp
  572. * from Fabric connections.
  573. */
  574. if (ndlp->nlp_DID != Fabric_DID)
  575. lpfc_unreg_rpi(vport, ndlp);
  576. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  577. } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
  578. /* Fail outstanding IO now since device is
  579. * marked for PLOGI.
  580. */
  581. lpfc_unreg_rpi(vport, ndlp);
  582. }
  583. }
  584. }
  585. static void
  586. lpfc_linkup_port(struct lpfc_vport *vport)
  587. {
  588. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  589. struct lpfc_nodelist *ndlp, *next_ndlp;
  590. struct lpfc_hba *phba = vport->phba;
  591. if ((vport->load_flag & FC_UNLOADING) != 0)
  592. return;
  593. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  594. "Link Up: top:x%x speed:x%x flg:x%x",
  595. phba->fc_topology, phba->fc_linkspeed, phba->link_flag);
  596. /* If NPIV is not enabled, only bring the physical port up */
  597. if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  598. (vport != phba->pport))
  599. return;
  600. fc_host_post_event(shost, fc_get_event_number(), FCH_EVT_LINKUP, 0);
  601. spin_lock_irq(shost->host_lock);
  602. vport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI | FC_ABORT_DISCOVERY |
  603. FC_RSCN_MODE | FC_NLP_MORE | FC_RSCN_DISCOVERY);
  604. vport->fc_flag |= FC_NDISC_ACTIVE;
  605. vport->fc_ns_retry = 0;
  606. spin_unlock_irq(shost->host_lock);
  607. if (vport->fc_flag & FC_LBIT)
  608. lpfc_linkup_cleanup_nodes(vport);
  609. /* free any ndlp's in unused state */
  610. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
  611. nlp_listp)
  612. if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
  613. lpfc_drop_node(vport, ndlp);
  614. }
  615. static int
  616. lpfc_linkup(struct lpfc_hba *phba)
  617. {
  618. struct lpfc_vport *vport;
  619. phba->link_state = LPFC_LINK_UP;
  620. /* Unblock fabric iocbs if they are blocked */
  621. clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
  622. del_timer_sync(&phba->fabric_block_timer);
  623. list_for_each_entry(vport, &phba->port_list, listentry) {
  624. lpfc_linkup_port(vport);
  625. }
  626. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
  627. lpfc_issue_clear_la(phba, phba->pport);
  628. return 0;
  629. }
  630. /*
  631. * This routine handles processing a CLEAR_LA mailbox
  632. * command upon completion. It is setup in the LPFC_MBOXQ
  633. * as the completion routine when the command is
  634. * handed off to the SLI layer.
  635. */
  636. void
  637. lpfc_mbx_cmpl_clear_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  638. {
  639. struct lpfc_vport *vport = pmb->vport;
  640. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  641. struct lpfc_sli *psli = &phba->sli;
  642. MAILBOX_t *mb = &pmb->mb;
  643. uint32_t control;
  644. /* Since we don't do discovery right now, turn these off here */
  645. psli->ring[psli->extra_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
  646. psli->ring[psli->fcp_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
  647. psli->ring[psli->next_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
  648. /* Check for error */
  649. if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) {
  650. /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */
  651. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  652. "%d (%d):0320 CLEAR_LA mbxStatus error x%x hba "
  653. "state x%x\n",
  654. phba->brd_no, vport->vpi, mb->mbxStatus,
  655. vport->port_state);
  656. phba->link_state = LPFC_HBA_ERROR;
  657. goto out;
  658. }
  659. if (vport->port_type == LPFC_PHYSICAL_PORT)
  660. phba->link_state = LPFC_HBA_READY;
  661. spin_lock_irq(&phba->hbalock);
  662. psli->sli_flag |= LPFC_PROCESS_LA;
  663. control = readl(phba->HCregaddr);
  664. control |= HC_LAINT_ENA;
  665. writel(control, phba->HCregaddr);
  666. readl(phba->HCregaddr); /* flush */
  667. spin_unlock_irq(&phba->hbalock);
  668. return;
  669. vport->num_disc_nodes = 0;
  670. /* go thru NPR nodes and issue ELS PLOGIs */
  671. if (vport->fc_npr_cnt)
  672. lpfc_els_disc_plogi(vport);
  673. if (!vport->num_disc_nodes) {
  674. spin_lock_irq(shost->host_lock);
  675. vport->fc_flag &= ~FC_NDISC_ACTIVE;
  676. spin_unlock_irq(shost->host_lock);
  677. }
  678. vport->port_state = LPFC_VPORT_READY;
  679. out:
  680. /* Device Discovery completes */
  681. lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
  682. "%d (%d):0225 Device Discovery completes\n",
  683. phba->brd_no, vport->vpi);
  684. mempool_free(pmb, phba->mbox_mem_pool);
  685. spin_lock_irq(shost->host_lock);
  686. vport->fc_flag &= ~(FC_ABORT_DISCOVERY | FC_ESTABLISH_LINK);
  687. spin_unlock_irq(shost->host_lock);
  688. del_timer_sync(&phba->fc_estabtmo);
  689. lpfc_can_disctmo(vport);
  690. /* turn on Link Attention interrupts */
  691. spin_lock_irq(&phba->hbalock);
  692. psli->sli_flag |= LPFC_PROCESS_LA;
  693. control = readl(phba->HCregaddr);
  694. control |= HC_LAINT_ENA;
  695. writel(control, phba->HCregaddr);
  696. readl(phba->HCregaddr); /* flush */
  697. spin_unlock_irq(&phba->hbalock);
  698. return;
  699. }
  700. static void
  701. lpfc_mbx_cmpl_local_config_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  702. {
  703. struct lpfc_vport *vport = pmb->vport;
  704. if (pmb->mb.mbxStatus)
  705. goto out;
  706. mempool_free(pmb, phba->mbox_mem_pool);
  707. if (phba->fc_topology == TOPOLOGY_LOOP &&
  708. vport->fc_flag & FC_PUBLIC_LOOP &&
  709. !(vport->fc_flag & FC_LBIT)) {
  710. /* Need to wait for FAN - use discovery timer
  711. * for timeout. port_state is identically
  712. * LPFC_LOCAL_CFG_LINK while waiting for FAN
  713. */
  714. lpfc_set_disctmo(vport);
  715. return;
  716. }
  717. /* Start discovery by sending a FLOGI. port_state is identically
  718. * LPFC_FLOGI while waiting for FLOGI cmpl
  719. */
  720. if (vport->port_state != LPFC_FLOGI) {
  721. vport->port_state = LPFC_FLOGI;
  722. lpfc_set_disctmo(vport);
  723. lpfc_initial_flogi(vport);
  724. }
  725. return;
  726. out:
  727. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  728. "%d (%d):0306 CONFIG_LINK mbxStatus error x%x "
  729. "HBA state x%x\n",
  730. phba->brd_no, vport->vpi, pmb->mb.mbxStatus,
  731. vport->port_state);
  732. mempool_free(pmb, phba->mbox_mem_pool);
  733. lpfc_linkdown(phba);
  734. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
  735. "%d (%d):0200 CONFIG_LINK bad hba state x%x\n",
  736. phba->brd_no, vport->vpi, vport->port_state);
  737. lpfc_issue_clear_la(phba, vport);
  738. return;
  739. }
  740. static void
  741. lpfc_mbx_cmpl_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  742. {
  743. MAILBOX_t *mb = &pmb->mb;
  744. struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) pmb->context1;
  745. struct lpfc_vport *vport = pmb->vport;
  746. /* Check for error */
  747. if (mb->mbxStatus) {
  748. /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */
  749. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  750. "%d (%d):0319 READ_SPARAM mbxStatus error x%x "
  751. "hba state x%x>\n",
  752. phba->brd_no, vport->vpi, mb->mbxStatus,
  753. vport->port_state);
  754. lpfc_linkdown(phba);
  755. goto out;
  756. }
  757. memcpy((uint8_t *) &vport->fc_sparam, (uint8_t *) mp->virt,
  758. sizeof (struct serv_parm));
  759. if (phba->cfg_soft_wwnn)
  760. u64_to_wwn(phba->cfg_soft_wwnn,
  761. vport->fc_sparam.nodeName.u.wwn);
  762. if (phba->cfg_soft_wwpn)
  763. u64_to_wwn(phba->cfg_soft_wwpn,
  764. vport->fc_sparam.portName.u.wwn);
  765. memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
  766. sizeof(vport->fc_nodename));
  767. memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
  768. sizeof(vport->fc_portname));
  769. if (vport->port_type == LPFC_PHYSICAL_PORT) {
  770. memcpy(&phba->wwnn, &vport->fc_nodename, sizeof(phba->wwnn));
  771. memcpy(&phba->wwpn, &vport->fc_portname, sizeof(phba->wwnn));
  772. }
  773. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  774. kfree(mp);
  775. mempool_free(pmb, phba->mbox_mem_pool);
  776. return;
  777. out:
  778. pmb->context1 = NULL;
  779. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  780. kfree(mp);
  781. lpfc_issue_clear_la(phba, vport);
  782. mempool_free(pmb, phba->mbox_mem_pool);
  783. return;
  784. }
  785. static void
  786. lpfc_mbx_process_link_up(struct lpfc_hba *phba, READ_LA_VAR *la)
  787. {
  788. struct lpfc_vport *vport = phba->pport;
  789. LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox;
  790. int i;
  791. struct lpfc_dmabuf *mp;
  792. int rc;
  793. sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  794. cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  795. spin_lock_irq(&phba->hbalock);
  796. switch (la->UlnkSpeed) {
  797. case LA_1GHZ_LINK:
  798. phba->fc_linkspeed = LA_1GHZ_LINK;
  799. break;
  800. case LA_2GHZ_LINK:
  801. phba->fc_linkspeed = LA_2GHZ_LINK;
  802. break;
  803. case LA_4GHZ_LINK:
  804. phba->fc_linkspeed = LA_4GHZ_LINK;
  805. break;
  806. case LA_8GHZ_LINK:
  807. phba->fc_linkspeed = LA_8GHZ_LINK;
  808. break;
  809. default:
  810. phba->fc_linkspeed = LA_UNKNW_LINK;
  811. break;
  812. }
  813. phba->fc_topology = la->topology;
  814. phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
  815. if (phba->fc_topology == TOPOLOGY_LOOP) {
  816. phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
  817. /* Get Loop Map information */
  818. if (la->il)
  819. vport->fc_flag |= FC_LBIT;
  820. vport->fc_myDID = la->granted_AL_PA;
  821. i = la->un.lilpBde64.tus.f.bdeSize;
  822. if (i == 0) {
  823. phba->alpa_map[0] = 0;
  824. } else {
  825. if (phba->cfg_log_verbose & LOG_LINK_EVENT) {
  826. int numalpa, j, k;
  827. union {
  828. uint8_t pamap[16];
  829. struct {
  830. uint32_t wd1;
  831. uint32_t wd2;
  832. uint32_t wd3;
  833. uint32_t wd4;
  834. } pa;
  835. } un;
  836. numalpa = phba->alpa_map[0];
  837. j = 0;
  838. while (j < numalpa) {
  839. memset(un.pamap, 0, 16);
  840. for (k = 1; j < numalpa; k++) {
  841. un.pamap[k - 1] =
  842. phba->alpa_map[j + 1];
  843. j++;
  844. if (k == 16)
  845. break;
  846. }
  847. /* Link Up Event ALPA map */
  848. lpfc_printf_log(phba,
  849. KERN_WARNING,
  850. LOG_LINK_EVENT,
  851. "%d:1304 Link Up Event "
  852. "ALPA map Data: x%x "
  853. "x%x x%x x%x\n",
  854. phba->brd_no,
  855. un.pa.wd1, un.pa.wd2,
  856. un.pa.wd3, un.pa.wd4);
  857. }
  858. }
  859. }
  860. } else {
  861. if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) {
  862. if (phba->max_vpi && phba->cfg_npiv_enable &&
  863. (phba->sli_rev == 3))
  864. phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
  865. }
  866. vport->fc_myDID = phba->fc_pref_DID;
  867. vport->fc_flag |= FC_LBIT;
  868. }
  869. spin_unlock_irq(&phba->hbalock);
  870. lpfc_linkup(phba);
  871. if (sparam_mbox) {
  872. lpfc_read_sparam(phba, sparam_mbox, 0);
  873. sparam_mbox->vport = vport;
  874. sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
  875. rc = lpfc_sli_issue_mbox(phba, sparam_mbox,
  876. (MBX_NOWAIT | MBX_STOP_IOCB));
  877. if (rc == MBX_NOT_FINISHED) {
  878. mp = (struct lpfc_dmabuf *) sparam_mbox->context1;
  879. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  880. kfree(mp);
  881. mempool_free(sparam_mbox, phba->mbox_mem_pool);
  882. if (cfglink_mbox)
  883. mempool_free(cfglink_mbox, phba->mbox_mem_pool);
  884. goto out;
  885. }
  886. }
  887. if (cfglink_mbox) {
  888. vport->port_state = LPFC_LOCAL_CFG_LINK;
  889. lpfc_config_link(phba, cfglink_mbox);
  890. cfglink_mbox->vport = vport;
  891. cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
  892. rc = lpfc_sli_issue_mbox(phba, cfglink_mbox,
  893. (MBX_NOWAIT | MBX_STOP_IOCB));
  894. if (rc != MBX_NOT_FINISHED)
  895. return;
  896. mempool_free(cfglink_mbox, phba->mbox_mem_pool);
  897. }
  898. out:
  899. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  900. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  901. "%d (%d):0263 Discovery Mailbox error: state: 0x%x : %p %p\n",
  902. phba->brd_no, vport->vpi,
  903. vport->port_state, sparam_mbox, cfglink_mbox);
  904. lpfc_issue_clear_la(phba, vport);
  905. return;
  906. }
  907. static void
  908. lpfc_mbx_issue_link_down(struct lpfc_hba *phba)
  909. {
  910. uint32_t control;
  911. struct lpfc_sli *psli = &phba->sli;
  912. lpfc_linkdown(phba);
  913. /* turn on Link Attention interrupts - no CLEAR_LA needed */
  914. spin_lock_irq(&phba->hbalock);
  915. psli->sli_flag |= LPFC_PROCESS_LA;
  916. control = readl(phba->HCregaddr);
  917. control |= HC_LAINT_ENA;
  918. writel(control, phba->HCregaddr);
  919. readl(phba->HCregaddr); /* flush */
  920. spin_unlock_irq(&phba->hbalock);
  921. }
  922. /*
  923. * This routine handles processing a READ_LA mailbox
  924. * command upon completion. It is setup in the LPFC_MBOXQ
  925. * as the completion routine when the command is
  926. * handed off to the SLI layer.
  927. */
  928. void
  929. lpfc_mbx_cmpl_read_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  930. {
  931. struct lpfc_vport *vport = pmb->vport;
  932. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  933. READ_LA_VAR *la;
  934. MAILBOX_t *mb = &pmb->mb;
  935. struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
  936. /* Check for error */
  937. if (mb->mbxStatus) {
  938. lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
  939. "%d:1307 READ_LA mbox error x%x state x%x\n",
  940. phba->brd_no, mb->mbxStatus, vport->port_state);
  941. lpfc_mbx_issue_link_down(phba);
  942. phba->link_state = LPFC_HBA_ERROR;
  943. goto lpfc_mbx_cmpl_read_la_free_mbuf;
  944. }
  945. la = (READ_LA_VAR *) & pmb->mb.un.varReadLA;
  946. memcpy(&phba->alpa_map[0], mp->virt, 128);
  947. spin_lock_irq(shost->host_lock);
  948. if (la->pb)
  949. vport->fc_flag |= FC_BYPASSED_MODE;
  950. else
  951. vport->fc_flag &= ~FC_BYPASSED_MODE;
  952. spin_unlock_irq(shost->host_lock);
  953. if (((phba->fc_eventTag + 1) < la->eventTag) ||
  954. (phba->fc_eventTag == la->eventTag)) {
  955. phba->fc_stat.LinkMultiEvent++;
  956. if (la->attType == AT_LINK_UP)
  957. if (phba->fc_eventTag != 0)
  958. lpfc_linkdown(phba);
  959. }
  960. phba->fc_eventTag = la->eventTag;
  961. if (la->attType == AT_LINK_UP) {
  962. phba->fc_stat.LinkUp++;
  963. if (phba->link_flag & LS_LOOPBACK_MODE) {
  964. lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
  965. "%d:1306 Link Up Event in loop back mode "
  966. "x%x received Data: x%x x%x x%x x%x\n",
  967. phba->brd_no, la->eventTag, phba->fc_eventTag,
  968. la->granted_AL_PA, la->UlnkSpeed,
  969. phba->alpa_map[0]);
  970. } else {
  971. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  972. "%d:1303 Link Up Event x%x received "
  973. "Data: x%x x%x x%x x%x\n",
  974. phba->brd_no, la->eventTag, phba->fc_eventTag,
  975. la->granted_AL_PA, la->UlnkSpeed,
  976. phba->alpa_map[0]);
  977. }
  978. lpfc_mbx_process_link_up(phba, la);
  979. } else {
  980. phba->fc_stat.LinkDown++;
  981. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  982. "%d:1305 Link Down Event x%x received "
  983. "Data: x%x x%x x%x\n",
  984. phba->brd_no, la->eventTag, phba->fc_eventTag,
  985. phba->pport->port_state, vport->fc_flag);
  986. lpfc_mbx_issue_link_down(phba);
  987. }
  988. lpfc_mbx_cmpl_read_la_free_mbuf:
  989. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  990. kfree(mp);
  991. mempool_free(pmb, phba->mbox_mem_pool);
  992. return;
  993. }
  994. /*
  995. * This routine handles processing a REG_LOGIN mailbox
  996. * command upon completion. It is setup in the LPFC_MBOXQ
  997. * as the completion routine when the command is
  998. * handed off to the SLI layer.
  999. */
  1000. void
  1001. lpfc_mbx_cmpl_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  1002. {
  1003. struct lpfc_vport *vport = pmb->vport;
  1004. struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
  1005. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
  1006. pmb->context1 = NULL;
  1007. /* Good status, call state machine */
  1008. lpfc_disc_state_machine(vport, ndlp, pmb, NLP_EVT_CMPL_REG_LOGIN);
  1009. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1010. kfree(mp);
  1011. mempool_free(pmb, phba->mbox_mem_pool);
  1012. lpfc_nlp_put(ndlp);
  1013. return;
  1014. }
  1015. static void
  1016. lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  1017. {
  1018. MAILBOX_t *mb = &pmb->mb;
  1019. struct lpfc_vport *vport = pmb->vport;
  1020. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1021. switch (mb->mbxStatus) {
  1022. case 0x0011:
  1023. case 0x0020:
  1024. case 0x9700:
  1025. lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
  1026. "%d (%d):0911 cmpl_unreg_vpi, "
  1027. "mb status = 0x%x\n",
  1028. phba->brd_no, vport->vpi, mb->mbxStatus);
  1029. break;
  1030. }
  1031. vport->unreg_vpi_cmpl = VPORT_OK;
  1032. mempool_free(pmb, phba->mbox_mem_pool);
  1033. /*
  1034. * This shost reference might have been taken at the beginning of
  1035. * lpfc_vport_delete()
  1036. */
  1037. if (vport->load_flag & FC_UNLOADING)
  1038. scsi_host_put(shost);
  1039. }
  1040. void
  1041. lpfc_mbx_unreg_vpi(struct lpfc_vport *vport)
  1042. {
  1043. struct lpfc_hba *phba = vport->phba;
  1044. LPFC_MBOXQ_t *mbox;
  1045. int rc;
  1046. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1047. if (!mbox)
  1048. return;
  1049. lpfc_unreg_vpi(phba, vport->vpi, mbox);
  1050. mbox->vport = vport;
  1051. mbox->mbox_cmpl = lpfc_mbx_cmpl_unreg_vpi;
  1052. rc = lpfc_sli_issue_mbox(phba, mbox, (MBX_NOWAIT | MBX_STOP_IOCB));
  1053. if (rc == MBX_NOT_FINISHED) {
  1054. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_VPORT,
  1055. "%d (%d):1800 Could not issue unreg_vpi\n",
  1056. phba->brd_no, vport->vpi);
  1057. mempool_free(mbox, phba->mbox_mem_pool);
  1058. vport->unreg_vpi_cmpl = VPORT_ERROR;
  1059. }
  1060. }
  1061. static void
  1062. lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  1063. {
  1064. struct lpfc_vport *vport = pmb->vport;
  1065. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1066. MAILBOX_t *mb = &pmb->mb;
  1067. switch (mb->mbxStatus) {
  1068. case 0x0011:
  1069. case 0x9601:
  1070. case 0x9602:
  1071. lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
  1072. "%d (%d):0912 cmpl_reg_vpi, mb status = 0x%x\n",
  1073. phba->brd_no, vport->vpi, mb->mbxStatus);
  1074. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  1075. spin_lock_irq(shost->host_lock);
  1076. vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
  1077. spin_unlock_irq(shost->host_lock);
  1078. vport->fc_myDID = 0;
  1079. goto out;
  1080. }
  1081. vport->num_disc_nodes = 0;
  1082. /* go thru NPR list and issue ELS PLOGIs */
  1083. if (vport->fc_npr_cnt)
  1084. lpfc_els_disc_plogi(vport);
  1085. if (!vport->num_disc_nodes) {
  1086. spin_lock_irq(shost->host_lock);
  1087. vport->fc_flag &= ~FC_NDISC_ACTIVE;
  1088. spin_unlock_irq(shost->host_lock);
  1089. lpfc_can_disctmo(vport);
  1090. }
  1091. vport->port_state = LPFC_VPORT_READY;
  1092. out:
  1093. mempool_free(pmb, phba->mbox_mem_pool);
  1094. return;
  1095. }
  1096. /*
  1097. * This routine handles processing a Fabric REG_LOGIN mailbox
  1098. * command upon completion. It is setup in the LPFC_MBOXQ
  1099. * as the completion routine when the command is
  1100. * handed off to the SLI layer.
  1101. */
  1102. void
  1103. lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  1104. {
  1105. struct lpfc_vport *vport = pmb->vport;
  1106. struct lpfc_vport *next_vport;
  1107. MAILBOX_t *mb = &pmb->mb;
  1108. struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
  1109. struct lpfc_nodelist *ndlp;
  1110. ndlp = (struct lpfc_nodelist *) pmb->context2;
  1111. pmb->context1 = NULL;
  1112. pmb->context2 = NULL;
  1113. if (mb->mbxStatus) {
  1114. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1115. kfree(mp);
  1116. mempool_free(pmb, phba->mbox_mem_pool);
  1117. lpfc_nlp_put(ndlp);
  1118. if (phba->fc_topology == TOPOLOGY_LOOP) {
  1119. /* FLOGI failed, use loop map to make discovery list */
  1120. lpfc_disc_list_loopmap(vport);
  1121. /* Start discovery */
  1122. lpfc_disc_start(vport);
  1123. return;
  1124. }
  1125. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  1126. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  1127. "%d (%d):0258 Register Fabric login error: 0x%x\n",
  1128. phba->brd_no, vport->vpi, mb->mbxStatus);
  1129. return;
  1130. }
  1131. ndlp->nlp_rpi = mb->un.varWords[0];
  1132. ndlp->nlp_type |= NLP_FABRIC;
  1133. lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
  1134. lpfc_nlp_put(ndlp); /* Drop the reference from the mbox */
  1135. if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
  1136. list_for_each_entry(next_vport, &phba->port_list, listentry) {
  1137. if (next_vport->port_type == LPFC_PHYSICAL_PORT)
  1138. continue;
  1139. if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
  1140. lpfc_initial_fdisc(next_vport);
  1141. else if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
  1142. lpfc_vport_set_state(vport,
  1143. FC_VPORT_NO_FABRIC_SUPP);
  1144. lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
  1145. "%d (%d):0259 No NPIV Fabric "
  1146. "support\n",
  1147. phba->brd_no, vport->vpi);
  1148. }
  1149. }
  1150. lpfc_do_scr_ns_plogi(phba, vport);
  1151. }
  1152. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1153. kfree(mp);
  1154. mempool_free(pmb, phba->mbox_mem_pool);
  1155. return;
  1156. }
  1157. /*
  1158. * This routine handles processing a NameServer REG_LOGIN mailbox
  1159. * command upon completion. It is setup in the LPFC_MBOXQ
  1160. * as the completion routine when the command is
  1161. * handed off to the SLI layer.
  1162. */
  1163. void
  1164. lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  1165. {
  1166. MAILBOX_t *mb = &pmb->mb;
  1167. struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
  1168. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
  1169. struct lpfc_vport *vport = pmb->vport;
  1170. if (mb->mbxStatus) {
  1171. out:
  1172. lpfc_nlp_put(ndlp);
  1173. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1174. kfree(mp);
  1175. mempool_free(pmb, phba->mbox_mem_pool);
  1176. lpfc_drop_node(vport, ndlp);
  1177. if (phba->fc_topology == TOPOLOGY_LOOP) {
  1178. /*
  1179. * RegLogin failed, use loop map to make discovery
  1180. * list
  1181. */
  1182. lpfc_disc_list_loopmap(vport);
  1183. /* Start discovery */
  1184. lpfc_disc_start(vport);
  1185. return;
  1186. }
  1187. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  1188. lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
  1189. "%d (%d):0260 Register NameServer error: 0x%x\n",
  1190. phba->brd_no, vport->vpi, mb->mbxStatus);
  1191. return;
  1192. }
  1193. pmb->context1 = NULL;
  1194. ndlp->nlp_rpi = mb->un.varWords[0];
  1195. ndlp->nlp_type |= NLP_FABRIC;
  1196. lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
  1197. if (vport->port_state < LPFC_VPORT_READY) {
  1198. /* Link up discovery requires Fabric registration. */
  1199. lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0, 0); /* Do this first! */
  1200. lpfc_ns_cmd(vport, SLI_CTNS_RNN_ID, 0, 0);
  1201. lpfc_ns_cmd(vport, SLI_CTNS_RSNN_NN, 0, 0);
  1202. lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
  1203. lpfc_ns_cmd(vport, SLI_CTNS_RFT_ID, 0, 0);
  1204. /* Issue SCR just before NameServer GID_FT Query */
  1205. lpfc_issue_els_scr(vport, SCR_DID, 0);
  1206. }
  1207. vport->fc_ns_retry = 0;
  1208. /* Good status, issue CT Request to NameServer */
  1209. if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0)) {
  1210. /* Cannot issue NameServer Query, so finish up discovery */
  1211. goto out;
  1212. }
  1213. lpfc_nlp_put(ndlp);
  1214. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1215. kfree(mp);
  1216. mempool_free(pmb, phba->mbox_mem_pool);
  1217. return;
  1218. }
  1219. static void
  1220. lpfc_register_remote_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  1221. {
  1222. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1223. struct fc_rport *rport;
  1224. struct lpfc_rport_data *rdata;
  1225. struct fc_rport_identifiers rport_ids;
  1226. struct lpfc_hba *phba = vport->phba;
  1227. /* Remote port has reappeared. Re-register w/ FC transport */
  1228. rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
  1229. rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
  1230. rport_ids.port_id = ndlp->nlp_DID;
  1231. rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
  1232. /*
  1233. * We leave our node pointer in rport->dd_data when we unregister a
  1234. * FCP target port. But fc_remote_port_add zeros the space to which
  1235. * rport->dd_data points. So, if we're reusing a previously
  1236. * registered port, drop the reference that we took the last time we
  1237. * registered the port.
  1238. */
  1239. if (ndlp->rport && ndlp->rport->dd_data &&
  1240. ((struct lpfc_rport_data *) ndlp->rport->dd_data)->pnode == ndlp) {
  1241. lpfc_nlp_put(ndlp);
  1242. }
  1243. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
  1244. "rport add: did:x%x flg:x%x type x%x",
  1245. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
  1246. ndlp->rport = rport = fc_remote_port_add(shost, 0, &rport_ids);
  1247. if (!rport || !get_device(&rport->dev)) {
  1248. dev_printk(KERN_WARNING, &phba->pcidev->dev,
  1249. "Warning: fc_remote_port_add failed\n");
  1250. return;
  1251. }
  1252. /* initialize static port data */
  1253. rport->maxframe_size = ndlp->nlp_maxframe;
  1254. rport->supported_classes = ndlp->nlp_class_sup;
  1255. rdata = rport->dd_data;
  1256. rdata->pnode = lpfc_nlp_get(ndlp);
  1257. if (ndlp->nlp_type & NLP_FCP_TARGET)
  1258. rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
  1259. if (ndlp->nlp_type & NLP_FCP_INITIATOR)
  1260. rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
  1261. if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN)
  1262. fc_remote_port_rolechg(rport, rport_ids.roles);
  1263. if ((rport->scsi_target_id != -1) &&
  1264. (rport->scsi_target_id < LPFC_MAX_TARGET)) {
  1265. ndlp->nlp_sid = rport->scsi_target_id;
  1266. }
  1267. return;
  1268. }
  1269. static void
  1270. lpfc_unregister_remote_port(struct lpfc_nodelist *ndlp)
  1271. {
  1272. struct fc_rport *rport = ndlp->rport;
  1273. lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_RPORT,
  1274. "rport delete: did:x%x flg:x%x type x%x",
  1275. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
  1276. fc_remote_port_delete(rport);
  1277. return;
  1278. }
  1279. static void
  1280. lpfc_nlp_counters(struct lpfc_vport *vport, int state, int count)
  1281. {
  1282. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1283. spin_lock_irq(shost->host_lock);
  1284. switch (state) {
  1285. case NLP_STE_UNUSED_NODE:
  1286. vport->fc_unused_cnt += count;
  1287. break;
  1288. case NLP_STE_PLOGI_ISSUE:
  1289. vport->fc_plogi_cnt += count;
  1290. break;
  1291. case NLP_STE_ADISC_ISSUE:
  1292. vport->fc_adisc_cnt += count;
  1293. break;
  1294. case NLP_STE_REG_LOGIN_ISSUE:
  1295. vport->fc_reglogin_cnt += count;
  1296. break;
  1297. case NLP_STE_PRLI_ISSUE:
  1298. vport->fc_prli_cnt += count;
  1299. break;
  1300. case NLP_STE_UNMAPPED_NODE:
  1301. vport->fc_unmap_cnt += count;
  1302. break;
  1303. case NLP_STE_MAPPED_NODE:
  1304. vport->fc_map_cnt += count;
  1305. break;
  1306. case NLP_STE_NPR_NODE:
  1307. vport->fc_npr_cnt += count;
  1308. break;
  1309. }
  1310. spin_unlock_irq(shost->host_lock);
  1311. }
  1312. static void
  1313. lpfc_nlp_state_cleanup(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1314. int old_state, int new_state)
  1315. {
  1316. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1317. if (new_state == NLP_STE_UNMAPPED_NODE) {
  1318. ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
  1319. ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
  1320. ndlp->nlp_type |= NLP_FC_NODE;
  1321. }
  1322. if (new_state == NLP_STE_MAPPED_NODE)
  1323. ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
  1324. if (new_state == NLP_STE_NPR_NODE)
  1325. ndlp->nlp_flag &= ~NLP_RCV_PLOGI;
  1326. /* Transport interface */
  1327. if (ndlp->rport && (old_state == NLP_STE_MAPPED_NODE ||
  1328. old_state == NLP_STE_UNMAPPED_NODE)) {
  1329. vport->phba->nport_event_cnt++;
  1330. lpfc_unregister_remote_port(ndlp);
  1331. }
  1332. if (new_state == NLP_STE_MAPPED_NODE ||
  1333. new_state == NLP_STE_UNMAPPED_NODE) {
  1334. vport->phba->nport_event_cnt++;
  1335. /*
  1336. * Tell the fc transport about the port, if we haven't
  1337. * already. If we have, and it's a scsi entity, be
  1338. * sure to unblock any attached scsi devices
  1339. */
  1340. lpfc_register_remote_port(vport, ndlp);
  1341. }
  1342. /*
  1343. * if we added to Mapped list, but the remote port
  1344. * registration failed or assigned a target id outside
  1345. * our presentable range - move the node to the
  1346. * Unmapped List
  1347. */
  1348. if (new_state == NLP_STE_MAPPED_NODE &&
  1349. (!ndlp->rport ||
  1350. ndlp->rport->scsi_target_id == -1 ||
  1351. ndlp->rport->scsi_target_id >= LPFC_MAX_TARGET)) {
  1352. spin_lock_irq(shost->host_lock);
  1353. ndlp->nlp_flag |= NLP_TGT_NO_SCSIID;
  1354. spin_unlock_irq(shost->host_lock);
  1355. lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
  1356. }
  1357. }
  1358. static char *
  1359. lpfc_nlp_state_name(char *buffer, size_t size, int state)
  1360. {
  1361. static char *states[] = {
  1362. [NLP_STE_UNUSED_NODE] = "UNUSED",
  1363. [NLP_STE_PLOGI_ISSUE] = "PLOGI",
  1364. [NLP_STE_ADISC_ISSUE] = "ADISC",
  1365. [NLP_STE_REG_LOGIN_ISSUE] = "REGLOGIN",
  1366. [NLP_STE_PRLI_ISSUE] = "PRLI",
  1367. [NLP_STE_UNMAPPED_NODE] = "UNMAPPED",
  1368. [NLP_STE_MAPPED_NODE] = "MAPPED",
  1369. [NLP_STE_NPR_NODE] = "NPR",
  1370. };
  1371. if (state < ARRAY_SIZE(states) && states[state])
  1372. strlcpy(buffer, states[state], size);
  1373. else
  1374. snprintf(buffer, size, "unknown (%d)", state);
  1375. return buffer;
  1376. }
  1377. void
  1378. lpfc_nlp_set_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1379. int state)
  1380. {
  1381. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1382. int old_state = ndlp->nlp_state;
  1383. char name1[16], name2[16];
  1384. lpfc_printf_log(vport->phba, KERN_INFO, LOG_NODE,
  1385. "%d (%d):0904 NPort state transition x%06x, %s -> %s\n",
  1386. vport->phba->brd_no, vport->vpi,
  1387. ndlp->nlp_DID,
  1388. lpfc_nlp_state_name(name1, sizeof(name1), old_state),
  1389. lpfc_nlp_state_name(name2, sizeof(name2), state));
  1390. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
  1391. "node statechg did:x%x old:%d ste:%d",
  1392. ndlp->nlp_DID, old_state, state);
  1393. if (old_state == NLP_STE_NPR_NODE &&
  1394. (ndlp->nlp_flag & NLP_DELAY_TMO) != 0 &&
  1395. state != NLP_STE_NPR_NODE)
  1396. lpfc_cancel_retry_delay_tmo(vport, ndlp);
  1397. if (old_state == NLP_STE_UNMAPPED_NODE) {
  1398. ndlp->nlp_flag &= ~NLP_TGT_NO_SCSIID;
  1399. ndlp->nlp_type &= ~NLP_FC_NODE;
  1400. }
  1401. if (list_empty(&ndlp->nlp_listp)) {
  1402. spin_lock_irq(shost->host_lock);
  1403. list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
  1404. spin_unlock_irq(shost->host_lock);
  1405. } else if (old_state)
  1406. lpfc_nlp_counters(vport, old_state, -1);
  1407. ndlp->nlp_state = state;
  1408. lpfc_nlp_counters(vport, state, 1);
  1409. lpfc_nlp_state_cleanup(vport, ndlp, old_state, state);
  1410. }
  1411. void
  1412. lpfc_dequeue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  1413. {
  1414. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1415. if ((ndlp->nlp_flag & NLP_DELAY_TMO) != 0)
  1416. lpfc_cancel_retry_delay_tmo(vport, ndlp);
  1417. if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
  1418. lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
  1419. spin_lock_irq(shost->host_lock);
  1420. list_del_init(&ndlp->nlp_listp);
  1421. spin_unlock_irq(shost->host_lock);
  1422. lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state,
  1423. NLP_STE_UNUSED_NODE);
  1424. }
  1425. void
  1426. lpfc_drop_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  1427. {
  1428. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1429. if ((ndlp->nlp_flag & NLP_DELAY_TMO) != 0)
  1430. lpfc_cancel_retry_delay_tmo(vport, ndlp);
  1431. if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
  1432. lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
  1433. spin_lock_irq(shost->host_lock);
  1434. list_del_init(&ndlp->nlp_listp);
  1435. ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
  1436. spin_unlock_irq(shost->host_lock);
  1437. lpfc_nlp_put(ndlp);
  1438. }
  1439. /*
  1440. * Start / ReStart rescue timer for Discovery / RSCN handling
  1441. */
  1442. void
  1443. lpfc_set_disctmo(struct lpfc_vport *vport)
  1444. {
  1445. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1446. struct lpfc_hba *phba = vport->phba;
  1447. uint32_t tmo;
  1448. if (vport->port_state == LPFC_LOCAL_CFG_LINK) {
  1449. /* For FAN, timeout should be greater then edtov */
  1450. tmo = (((phba->fc_edtov + 999) / 1000) + 1);
  1451. } else {
  1452. /* Normal discovery timeout should be > then ELS/CT timeout
  1453. * FC spec states we need 3 * ratov for CT requests
  1454. */
  1455. tmo = ((phba->fc_ratov * 3) + 3);
  1456. }
  1457. if (!timer_pending(&vport->fc_disctmo)) {
  1458. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  1459. "set disc timer: tmo:x%x state:x%x flg:x%x",
  1460. tmo, vport->port_state, vport->fc_flag);
  1461. }
  1462. mod_timer(&vport->fc_disctmo, jiffies + HZ * tmo);
  1463. spin_lock_irq(shost->host_lock);
  1464. vport->fc_flag |= FC_DISC_TMO;
  1465. spin_unlock_irq(shost->host_lock);
  1466. /* Start Discovery Timer state <hba_state> */
  1467. lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
  1468. "%d (%d):0247 Start Discovery Timer state x%x "
  1469. "Data: x%x x%lx x%x x%x\n",
  1470. phba->brd_no, vport->vpi, vport->port_state, tmo,
  1471. (unsigned long)&vport->fc_disctmo, vport->fc_plogi_cnt,
  1472. vport->fc_adisc_cnt);
  1473. return;
  1474. }
  1475. /*
  1476. * Cancel rescue timer for Discovery / RSCN handling
  1477. */
  1478. int
  1479. lpfc_can_disctmo(struct lpfc_vport *vport)
  1480. {
  1481. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1482. struct lpfc_hba *phba = vport->phba;
  1483. unsigned long iflags;
  1484. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  1485. "can disc timer: state:x%x rtry:x%x flg:x%x",
  1486. vport->port_state, vport->fc_ns_retry, vport->fc_flag);
  1487. /* Turn off discovery timer if its running */
  1488. if (vport->fc_flag & FC_DISC_TMO) {
  1489. spin_lock_irqsave(shost->host_lock, iflags);
  1490. vport->fc_flag &= ~FC_DISC_TMO;
  1491. spin_unlock_irqrestore(shost->host_lock, iflags);
  1492. del_timer_sync(&vport->fc_disctmo);
  1493. spin_lock_irqsave(&vport->work_port_lock, iflags);
  1494. vport->work_port_events &= ~WORKER_DISC_TMO;
  1495. spin_unlock_irqrestore(&vport->work_port_lock, iflags);
  1496. }
  1497. /* Cancel Discovery Timer state <hba_state> */
  1498. lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
  1499. "%d (%d):0248 Cancel Discovery Timer state x%x "
  1500. "Data: x%x x%x x%x\n",
  1501. phba->brd_no, vport->vpi, vport->port_state,
  1502. vport->fc_flag, vport->fc_plogi_cnt,
  1503. vport->fc_adisc_cnt);
  1504. return 0;
  1505. }
  1506. /*
  1507. * Check specified ring for outstanding IOCB on the SLI queue
  1508. * Return true if iocb matches the specified nport
  1509. */
  1510. int
  1511. lpfc_check_sli_ndlp(struct lpfc_hba *phba,
  1512. struct lpfc_sli_ring *pring,
  1513. struct lpfc_iocbq *iocb,
  1514. struct lpfc_nodelist *ndlp)
  1515. {
  1516. struct lpfc_sli *psli = &phba->sli;
  1517. IOCB_t *icmd = &iocb->iocb;
  1518. struct lpfc_vport *vport = ndlp->vport;
  1519. if (iocb->vport != vport)
  1520. return 0;
  1521. if (pring->ringno == LPFC_ELS_RING) {
  1522. switch (icmd->ulpCommand) {
  1523. case CMD_GEN_REQUEST64_CR:
  1524. if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi)
  1525. return 1;
  1526. case CMD_ELS_REQUEST64_CR:
  1527. if (icmd->un.elsreq64.remoteID == ndlp->nlp_DID)
  1528. return 1;
  1529. case CMD_XMIT_ELS_RSP64_CX:
  1530. if (iocb->context1 == (uint8_t *) ndlp)
  1531. return 1;
  1532. }
  1533. } else if (pring->ringno == psli->extra_ring) {
  1534. } else if (pring->ringno == psli->fcp_ring) {
  1535. /* Skip match check if waiting to relogin to FCP target */
  1536. if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
  1537. (ndlp->nlp_flag & NLP_DELAY_TMO)) {
  1538. return 0;
  1539. }
  1540. if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) {
  1541. return 1;
  1542. }
  1543. } else if (pring->ringno == psli->next_ring) {
  1544. }
  1545. return 0;
  1546. }
  1547. /*
  1548. * Free resources / clean up outstanding I/Os
  1549. * associated with nlp_rpi in the LPFC_NODELIST entry.
  1550. */
  1551. static int
  1552. lpfc_no_rpi(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
  1553. {
  1554. LIST_HEAD(completions);
  1555. struct lpfc_sli *psli;
  1556. struct lpfc_sli_ring *pring;
  1557. struct lpfc_iocbq *iocb, *next_iocb;
  1558. IOCB_t *icmd;
  1559. uint32_t rpi, i;
  1560. lpfc_fabric_abort_nport(ndlp);
  1561. /*
  1562. * Everything that matches on txcmplq will be returned
  1563. * by firmware with a no rpi error.
  1564. */
  1565. psli = &phba->sli;
  1566. rpi = ndlp->nlp_rpi;
  1567. if (rpi) {
  1568. /* Now process each ring */
  1569. for (i = 0; i < psli->num_rings; i++) {
  1570. pring = &psli->ring[i];
  1571. spin_lock_irq(&phba->hbalock);
  1572. list_for_each_entry_safe(iocb, next_iocb, &pring->txq,
  1573. list) {
  1574. /*
  1575. * Check to see if iocb matches the nport we are
  1576. * looking for
  1577. */
  1578. if ((lpfc_check_sli_ndlp(phba, pring, iocb,
  1579. ndlp))) {
  1580. /* It matches, so deque and call compl
  1581. with an error */
  1582. list_move_tail(&iocb->list,
  1583. &completions);
  1584. pring->txq_cnt--;
  1585. }
  1586. }
  1587. spin_unlock_irq(&phba->hbalock);
  1588. }
  1589. }
  1590. while (!list_empty(&completions)) {
  1591. iocb = list_get_first(&completions, struct lpfc_iocbq, list);
  1592. list_del_init(&iocb->list);
  1593. if (!iocb->iocb_cmpl)
  1594. lpfc_sli_release_iocbq(phba, iocb);
  1595. else {
  1596. icmd = &iocb->iocb;
  1597. icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
  1598. icmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
  1599. (iocb->iocb_cmpl)(phba, iocb, iocb);
  1600. }
  1601. }
  1602. return 0;
  1603. }
  1604. /*
  1605. * Free rpi associated with LPFC_NODELIST entry.
  1606. * This routine is called from lpfc_freenode(), when we are removing
  1607. * a LPFC_NODELIST entry. It is also called if the driver initiates a
  1608. * LOGO that completes successfully, and we are waiting to PLOGI back
  1609. * to the remote NPort. In addition, it is called after we receive
  1610. * and unsolicated ELS cmd, send back a rsp, the rsp completes and
  1611. * we are waiting to PLOGI back to the remote NPort.
  1612. */
  1613. int
  1614. lpfc_unreg_rpi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  1615. {
  1616. struct lpfc_hba *phba = vport->phba;
  1617. LPFC_MBOXQ_t *mbox;
  1618. int rc;
  1619. if (ndlp->nlp_rpi) {
  1620. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1621. if (mbox) {
  1622. lpfc_unreg_login(phba, vport->vpi, ndlp->nlp_rpi, mbox);
  1623. mbox->vport = vport;
  1624. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  1625. rc = lpfc_sli_issue_mbox(phba, mbox,
  1626. (MBX_NOWAIT | MBX_STOP_IOCB));
  1627. if (rc == MBX_NOT_FINISHED)
  1628. mempool_free(mbox, phba->mbox_mem_pool);
  1629. }
  1630. lpfc_no_rpi(phba, ndlp);
  1631. ndlp->nlp_rpi = 0;
  1632. return 1;
  1633. }
  1634. return 0;
  1635. }
  1636. void
  1637. lpfc_unreg_all_rpis(struct lpfc_vport *vport)
  1638. {
  1639. struct lpfc_hba *phba = vport->phba;
  1640. LPFC_MBOXQ_t *mbox;
  1641. int rc;
  1642. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1643. if (mbox) {
  1644. lpfc_unreg_login(phba, vport->vpi, 0xffff, mbox);
  1645. mbox->vport = vport;
  1646. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  1647. rc = lpfc_sli_issue_mbox(phba, mbox,
  1648. (MBX_NOWAIT | MBX_STOP_IOCB));
  1649. if (rc == MBX_NOT_FINISHED) {
  1650. mempool_free(mbox, phba->mbox_mem_pool);
  1651. }
  1652. }
  1653. }
  1654. void
  1655. lpfc_unreg_default_rpis(struct lpfc_vport *vport)
  1656. {
  1657. struct lpfc_hba *phba = vport->phba;
  1658. LPFC_MBOXQ_t *mbox;
  1659. int rc;
  1660. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1661. if (mbox) {
  1662. lpfc_unreg_did(phba, vport->vpi, 0xffffffff, mbox);
  1663. mbox->vport = vport;
  1664. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  1665. rc = lpfc_sli_issue_mbox(phba, mbox,
  1666. (MBX_NOWAIT | MBX_STOP_IOCB));
  1667. if (rc == MBX_NOT_FINISHED) {
  1668. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_VPORT,
  1669. "%d (%d):1815 Could not issue "
  1670. "unreg_did (default rpis)\n",
  1671. phba->brd_no, vport->vpi);
  1672. mempool_free(mbox, phba->mbox_mem_pool);
  1673. }
  1674. }
  1675. }
  1676. /*
  1677. * Free resources associated with LPFC_NODELIST entry
  1678. * so it can be freed.
  1679. */
  1680. static int
  1681. lpfc_cleanup_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  1682. {
  1683. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1684. struct lpfc_hba *phba = vport->phba;
  1685. LPFC_MBOXQ_t *mb, *nextmb;
  1686. struct lpfc_dmabuf *mp;
  1687. /* Cleanup node for NPort <nlp_DID> */
  1688. lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
  1689. "%d (%d):0900 Cleanup node for NPort x%x "
  1690. "Data: x%x x%x x%x\n",
  1691. phba->brd_no, vport->vpi, ndlp->nlp_DID, ndlp->nlp_flag,
  1692. ndlp->nlp_state, ndlp->nlp_rpi);
  1693. lpfc_dequeue_node(vport, ndlp);
  1694. /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
  1695. if ((mb = phba->sli.mbox_active)) {
  1696. if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
  1697. (ndlp == (struct lpfc_nodelist *) mb->context2)) {
  1698. mb->context2 = NULL;
  1699. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  1700. }
  1701. }
  1702. spin_lock_irq(&phba->hbalock);
  1703. list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
  1704. if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
  1705. (ndlp == (struct lpfc_nodelist *) mb->context2)) {
  1706. mp = (struct lpfc_dmabuf *) (mb->context1);
  1707. if (mp) {
  1708. __lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1709. kfree(mp);
  1710. }
  1711. list_del(&mb->list);
  1712. mempool_free(mb, phba->mbox_mem_pool);
  1713. lpfc_nlp_put(ndlp);
  1714. }
  1715. }
  1716. spin_unlock_irq(&phba->hbalock);
  1717. lpfc_els_abort(phba,ndlp);
  1718. spin_lock_irq(shost->host_lock);
  1719. ndlp->nlp_flag &= ~NLP_DELAY_TMO;
  1720. spin_unlock_irq(shost->host_lock);
  1721. ndlp->nlp_last_elscmd = 0;
  1722. del_timer_sync(&ndlp->nlp_delayfunc);
  1723. if (!list_empty(&ndlp->els_retry_evt.evt_listp))
  1724. list_del_init(&ndlp->els_retry_evt.evt_listp);
  1725. if (!list_empty(&ndlp->dev_loss_evt.evt_listp))
  1726. list_del_init(&ndlp->dev_loss_evt.evt_listp);
  1727. if (!list_empty(&ndlp->dev_loss_evt.evt_listp)) {
  1728. list_del_init(&ndlp->dev_loss_evt.evt_listp);
  1729. complete((struct completion *)(ndlp->dev_loss_evt.evt_arg2));
  1730. }
  1731. lpfc_unreg_rpi(vport, ndlp);
  1732. return 0;
  1733. }
  1734. /*
  1735. * Check to see if we can free the nlp back to the freelist.
  1736. * If we are in the middle of using the nlp in the discovery state
  1737. * machine, defer the free till we reach the end of the state machine.
  1738. */
  1739. static void
  1740. lpfc_nlp_remove(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  1741. {
  1742. struct lpfc_rport_data *rdata;
  1743. if (ndlp->nlp_flag & NLP_DELAY_TMO) {
  1744. lpfc_cancel_retry_delay_tmo(vport, ndlp);
  1745. }
  1746. lpfc_cleanup_node(vport, ndlp);
  1747. /*
  1748. * We can get here with a non-NULL ndlp->rport because when we
  1749. * unregister a rport we don't break the rport/node linkage. So if we
  1750. * do, make sure we don't leaving any dangling pointers behind.
  1751. */
  1752. if (ndlp->rport) {
  1753. rdata = ndlp->rport->dd_data;
  1754. rdata->pnode = NULL;
  1755. ndlp->rport = NULL;
  1756. }
  1757. }
  1758. static int
  1759. lpfc_matchdid(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1760. uint32_t did)
  1761. {
  1762. D_ID mydid, ndlpdid, matchdid;
  1763. if (did == Bcast_DID)
  1764. return 0;
  1765. if (ndlp->nlp_DID == 0) {
  1766. return 0;
  1767. }
  1768. /* First check for Direct match */
  1769. if (ndlp->nlp_DID == did)
  1770. return 1;
  1771. /* Next check for area/domain identically equals 0 match */
  1772. mydid.un.word = vport->fc_myDID;
  1773. if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) {
  1774. return 0;
  1775. }
  1776. matchdid.un.word = did;
  1777. ndlpdid.un.word = ndlp->nlp_DID;
  1778. if (matchdid.un.b.id == ndlpdid.un.b.id) {
  1779. if ((mydid.un.b.domain == matchdid.un.b.domain) &&
  1780. (mydid.un.b.area == matchdid.un.b.area)) {
  1781. if ((ndlpdid.un.b.domain == 0) &&
  1782. (ndlpdid.un.b.area == 0)) {
  1783. if (ndlpdid.un.b.id)
  1784. return 1;
  1785. }
  1786. return 0;
  1787. }
  1788. matchdid.un.word = ndlp->nlp_DID;
  1789. if ((mydid.un.b.domain == ndlpdid.un.b.domain) &&
  1790. (mydid.un.b.area == ndlpdid.un.b.area)) {
  1791. if ((matchdid.un.b.domain == 0) &&
  1792. (matchdid.un.b.area == 0)) {
  1793. if (matchdid.un.b.id)
  1794. return 1;
  1795. }
  1796. }
  1797. }
  1798. return 0;
  1799. }
  1800. /* Search for a nodelist entry */
  1801. static struct lpfc_nodelist *
  1802. __lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
  1803. {
  1804. struct lpfc_hba *phba = vport->phba;
  1805. struct lpfc_nodelist *ndlp;
  1806. uint32_t data1;
  1807. list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
  1808. if (lpfc_matchdid(vport, ndlp, did)) {
  1809. data1 = (((uint32_t) ndlp->nlp_state << 24) |
  1810. ((uint32_t) ndlp->nlp_xri << 16) |
  1811. ((uint32_t) ndlp->nlp_type << 8) |
  1812. ((uint32_t) ndlp->nlp_rpi & 0xff));
  1813. lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
  1814. "%d (%d):0929 FIND node DID "
  1815. " Data: x%p x%x x%x x%x\n",
  1816. phba->brd_no, vport->vpi,
  1817. ndlp, ndlp->nlp_DID,
  1818. ndlp->nlp_flag, data1);
  1819. return ndlp;
  1820. }
  1821. }
  1822. /* FIND node did <did> NOT FOUND */
  1823. lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
  1824. "%d (%d):0932 FIND node did x%x NOT FOUND.\n",
  1825. phba->brd_no, vport->vpi, did);
  1826. return NULL;
  1827. }
  1828. struct lpfc_nodelist *
  1829. lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
  1830. {
  1831. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1832. struct lpfc_nodelist *ndlp;
  1833. spin_lock_irq(shost->host_lock);
  1834. ndlp = __lpfc_findnode_did(vport, did);
  1835. spin_unlock_irq(shost->host_lock);
  1836. return ndlp;
  1837. }
  1838. struct lpfc_nodelist *
  1839. lpfc_setup_disc_node(struct lpfc_vport *vport, uint32_t did)
  1840. {
  1841. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1842. struct lpfc_nodelist *ndlp;
  1843. ndlp = lpfc_findnode_did(vport, did);
  1844. if (!ndlp) {
  1845. if ((vport->fc_flag & FC_RSCN_MODE) != 0 &&
  1846. lpfc_rscn_payload_check(vport, did) == 0)
  1847. return NULL;
  1848. ndlp = (struct lpfc_nodelist *)
  1849. mempool_alloc(vport->phba->nlp_mem_pool, GFP_KERNEL);
  1850. if (!ndlp)
  1851. return NULL;
  1852. lpfc_nlp_init(vport, ndlp, did);
  1853. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  1854. spin_lock_irq(shost->host_lock);
  1855. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  1856. spin_unlock_irq(shost->host_lock);
  1857. return ndlp;
  1858. }
  1859. if (vport->fc_flag & FC_RSCN_MODE) {
  1860. if (lpfc_rscn_payload_check(vport, did)) {
  1861. spin_lock_irq(shost->host_lock);
  1862. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  1863. spin_unlock_irq(shost->host_lock);
  1864. /* Since this node is marked for discovery,
  1865. * delay timeout is not needed.
  1866. */
  1867. if (ndlp->nlp_flag & NLP_DELAY_TMO)
  1868. lpfc_cancel_retry_delay_tmo(vport, ndlp);
  1869. } else
  1870. ndlp = NULL;
  1871. } else {
  1872. if (ndlp->nlp_state == NLP_STE_ADISC_ISSUE ||
  1873. ndlp->nlp_state == NLP_STE_PLOGI_ISSUE)
  1874. return NULL;
  1875. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  1876. spin_lock_irq(shost->host_lock);
  1877. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  1878. spin_unlock_irq(shost->host_lock);
  1879. }
  1880. return ndlp;
  1881. }
  1882. /* Build a list of nodes to discover based on the loopmap */
  1883. void
  1884. lpfc_disc_list_loopmap(struct lpfc_vport *vport)
  1885. {
  1886. struct lpfc_hba *phba = vport->phba;
  1887. int j;
  1888. uint32_t alpa, index;
  1889. if (!lpfc_is_link_up(phba))
  1890. return;
  1891. if (phba->fc_topology != TOPOLOGY_LOOP)
  1892. return;
  1893. /* Check for loop map present or not */
  1894. if (phba->alpa_map[0]) {
  1895. for (j = 1; j <= phba->alpa_map[0]; j++) {
  1896. alpa = phba->alpa_map[j];
  1897. if (((vport->fc_myDID & 0xff) == alpa) || (alpa == 0))
  1898. continue;
  1899. lpfc_setup_disc_node(vport, alpa);
  1900. }
  1901. } else {
  1902. /* No alpamap, so try all alpa's */
  1903. for (j = 0; j < FC_MAXLOOP; j++) {
  1904. /* If cfg_scan_down is set, start from highest
  1905. * ALPA (0xef) to lowest (0x1).
  1906. */
  1907. if (phba->cfg_scan_down)
  1908. index = j;
  1909. else
  1910. index = FC_MAXLOOP - j - 1;
  1911. alpa = lpfcAlpaArray[index];
  1912. if ((vport->fc_myDID & 0xff) == alpa)
  1913. continue;
  1914. lpfc_setup_disc_node(vport, alpa);
  1915. }
  1916. }
  1917. return;
  1918. }
  1919. void
  1920. lpfc_issue_clear_la(struct lpfc_hba *phba, struct lpfc_vport *vport)
  1921. {
  1922. LPFC_MBOXQ_t *mbox;
  1923. struct lpfc_sli *psli = &phba->sli;
  1924. struct lpfc_sli_ring *extra_ring = &psli->ring[psli->extra_ring];
  1925. struct lpfc_sli_ring *fcp_ring = &psli->ring[psli->fcp_ring];
  1926. struct lpfc_sli_ring *next_ring = &psli->ring[psli->next_ring];
  1927. int rc;
  1928. /*
  1929. * if it's not a physical port or if we already send
  1930. * clear_la then don't send it.
  1931. */
  1932. if ((phba->link_state >= LPFC_CLEAR_LA) ||
  1933. (vport->port_type != LPFC_PHYSICAL_PORT))
  1934. return;
  1935. /* Link up discovery */
  1936. if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) != NULL) {
  1937. phba->link_state = LPFC_CLEAR_LA;
  1938. lpfc_clear_la(phba, mbox);
  1939. mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
  1940. mbox->vport = vport;
  1941. rc = lpfc_sli_issue_mbox(phba, mbox, (MBX_NOWAIT |
  1942. MBX_STOP_IOCB));
  1943. if (rc == MBX_NOT_FINISHED) {
  1944. mempool_free(mbox, phba->mbox_mem_pool);
  1945. lpfc_disc_flush_list(vport);
  1946. extra_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
  1947. fcp_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
  1948. next_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
  1949. phba->link_state = LPFC_HBA_ERROR;
  1950. }
  1951. }
  1952. }
  1953. /* Reg_vpi to tell firmware to resume normal operations */
  1954. void
  1955. lpfc_issue_reg_vpi(struct lpfc_hba *phba, struct lpfc_vport *vport)
  1956. {
  1957. LPFC_MBOXQ_t *regvpimbox;
  1958. regvpimbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1959. if (regvpimbox) {
  1960. lpfc_reg_vpi(phba, vport->vpi, vport->fc_myDID, regvpimbox);
  1961. regvpimbox->mbox_cmpl = lpfc_mbx_cmpl_reg_vpi;
  1962. regvpimbox->vport = vport;
  1963. if (lpfc_sli_issue_mbox(phba, regvpimbox,
  1964. (MBX_NOWAIT | MBX_STOP_IOCB))
  1965. == MBX_NOT_FINISHED) {
  1966. mempool_free(regvpimbox, phba->mbox_mem_pool);
  1967. }
  1968. }
  1969. }
  1970. /* Start Link up / RSCN discovery on NPR nodes */
  1971. void
  1972. lpfc_disc_start(struct lpfc_vport *vport)
  1973. {
  1974. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1975. struct lpfc_hba *phba = vport->phba;
  1976. uint32_t num_sent;
  1977. uint32_t clear_la_pending;
  1978. int did_changed;
  1979. if (!lpfc_is_link_up(phba))
  1980. return;
  1981. if (phba->link_state == LPFC_CLEAR_LA)
  1982. clear_la_pending = 1;
  1983. else
  1984. clear_la_pending = 0;
  1985. if (vport->port_state < LPFC_VPORT_READY)
  1986. vport->port_state = LPFC_DISC_AUTH;
  1987. lpfc_set_disctmo(vport);
  1988. if (vport->fc_prevDID == vport->fc_myDID)
  1989. did_changed = 0;
  1990. else
  1991. did_changed = 1;
  1992. vport->fc_prevDID = vport->fc_myDID;
  1993. vport->num_disc_nodes = 0;
  1994. /* Start Discovery state <hba_state> */
  1995. lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
  1996. "%d (%d):0202 Start Discovery hba state x%x "
  1997. "Data: x%x x%x x%x\n",
  1998. phba->brd_no, vport->vpi, vport->port_state,
  1999. vport->fc_flag, vport->fc_plogi_cnt,
  2000. vport->fc_adisc_cnt);
  2001. /* First do ADISCs - if any */
  2002. num_sent = lpfc_els_disc_adisc(vport);
  2003. if (num_sent)
  2004. return;
  2005. /*
  2006. * For SLI3, cmpl_reg_vpi will set port_state to READY, and
  2007. * continue discovery.
  2008. */
  2009. if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  2010. !(vport->fc_flag & FC_RSCN_MODE)) {
  2011. lpfc_issue_reg_vpi(phba, vport);
  2012. return;
  2013. }
  2014. /*
  2015. * For SLI2, we need to set port_state to READY and continue
  2016. * discovery.
  2017. */
  2018. if (vport->port_state < LPFC_VPORT_READY && !clear_la_pending) {
  2019. /* If we get here, there is nothing to ADISC */
  2020. if (vport->port_type == LPFC_PHYSICAL_PORT)
  2021. lpfc_issue_clear_la(phba, vport);
  2022. if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
  2023. vport->num_disc_nodes = 0;
  2024. /* go thru NPR nodes and issue ELS PLOGIs */
  2025. if (vport->fc_npr_cnt)
  2026. lpfc_els_disc_plogi(vport);
  2027. if (!vport->num_disc_nodes) {
  2028. spin_lock_irq(shost->host_lock);
  2029. vport->fc_flag &= ~FC_NDISC_ACTIVE;
  2030. spin_unlock_irq(shost->host_lock);
  2031. lpfc_can_disctmo(vport);
  2032. }
  2033. }
  2034. vport->port_state = LPFC_VPORT_READY;
  2035. } else {
  2036. /* Next do PLOGIs - if any */
  2037. num_sent = lpfc_els_disc_plogi(vport);
  2038. if (num_sent)
  2039. return;
  2040. if (vport->fc_flag & FC_RSCN_MODE) {
  2041. /* Check to see if more RSCNs came in while we
  2042. * were processing this one.
  2043. */
  2044. if ((vport->fc_rscn_id_cnt == 0) &&
  2045. (!(vport->fc_flag & FC_RSCN_DISCOVERY))) {
  2046. spin_lock_irq(shost->host_lock);
  2047. vport->fc_flag &= ~FC_RSCN_MODE;
  2048. spin_unlock_irq(shost->host_lock);
  2049. lpfc_can_disctmo(vport);
  2050. } else
  2051. lpfc_els_handle_rscn(vport);
  2052. }
  2053. }
  2054. return;
  2055. }
  2056. /*
  2057. * Ignore completion for all IOCBs on tx and txcmpl queue for ELS
  2058. * ring the match the sppecified nodelist.
  2059. */
  2060. static void
  2061. lpfc_free_tx(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
  2062. {
  2063. LIST_HEAD(completions);
  2064. struct lpfc_sli *psli;
  2065. IOCB_t *icmd;
  2066. struct lpfc_iocbq *iocb, *next_iocb;
  2067. struct lpfc_sli_ring *pring;
  2068. psli = &phba->sli;
  2069. pring = &psli->ring[LPFC_ELS_RING];
  2070. /* Error matching iocb on txq or txcmplq
  2071. * First check the txq.
  2072. */
  2073. spin_lock_irq(&phba->hbalock);
  2074. list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
  2075. if (iocb->context1 != ndlp) {
  2076. continue;
  2077. }
  2078. icmd = &iocb->iocb;
  2079. if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
  2080. (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
  2081. list_move_tail(&iocb->list, &completions);
  2082. pring->txq_cnt--;
  2083. }
  2084. }
  2085. /* Next check the txcmplq */
  2086. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
  2087. if (iocb->context1 != ndlp) {
  2088. continue;
  2089. }
  2090. icmd = &iocb->iocb;
  2091. if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR ||
  2092. icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX) {
  2093. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  2094. }
  2095. }
  2096. spin_unlock_irq(&phba->hbalock);
  2097. while (!list_empty(&completions)) {
  2098. iocb = list_get_first(&completions, struct lpfc_iocbq, list);
  2099. list_del_init(&iocb->list);
  2100. if (!iocb->iocb_cmpl)
  2101. lpfc_sli_release_iocbq(phba, iocb);
  2102. else {
  2103. icmd = &iocb->iocb;
  2104. icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
  2105. icmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
  2106. (iocb->iocb_cmpl) (phba, iocb, iocb);
  2107. }
  2108. }
  2109. }
  2110. void
  2111. lpfc_disc_flush_list(struct lpfc_vport *vport)
  2112. {
  2113. struct lpfc_nodelist *ndlp, *next_ndlp;
  2114. struct lpfc_hba *phba = vport->phba;
  2115. if (vport->fc_plogi_cnt || vport->fc_adisc_cnt) {
  2116. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
  2117. nlp_listp) {
  2118. if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
  2119. ndlp->nlp_state == NLP_STE_ADISC_ISSUE) {
  2120. lpfc_free_tx(phba, ndlp);
  2121. lpfc_nlp_put(ndlp);
  2122. }
  2123. }
  2124. }
  2125. }
  2126. void
  2127. lpfc_cleanup_discovery_resources(struct lpfc_vport *vport)
  2128. {
  2129. lpfc_els_flush_rscn(vport);
  2130. lpfc_els_flush_cmd(vport);
  2131. lpfc_disc_flush_list(vport);
  2132. }
  2133. /*****************************************************************************/
  2134. /*
  2135. * NAME: lpfc_disc_timeout
  2136. *
  2137. * FUNCTION: Fibre Channel driver discovery timeout routine.
  2138. *
  2139. * EXECUTION ENVIRONMENT: interrupt only
  2140. *
  2141. * CALLED FROM:
  2142. * Timer function
  2143. *
  2144. * RETURNS:
  2145. * none
  2146. */
  2147. /*****************************************************************************/
  2148. void
  2149. lpfc_disc_timeout(unsigned long ptr)
  2150. {
  2151. struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
  2152. struct lpfc_hba *phba = vport->phba;
  2153. unsigned long flags = 0;
  2154. if (unlikely(!phba))
  2155. return;
  2156. if ((vport->work_port_events & WORKER_DISC_TMO) == 0) {
  2157. spin_lock_irqsave(&vport->work_port_lock, flags);
  2158. vport->work_port_events |= WORKER_DISC_TMO;
  2159. spin_unlock_irqrestore(&vport->work_port_lock, flags);
  2160. spin_lock_irqsave(&phba->hbalock, flags);
  2161. if (phba->work_wait)
  2162. lpfc_worker_wake_up(phba);
  2163. spin_unlock_irqrestore(&phba->hbalock, flags);
  2164. }
  2165. return;
  2166. }
  2167. static void
  2168. lpfc_disc_timeout_handler(struct lpfc_vport *vport)
  2169. {
  2170. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2171. struct lpfc_hba *phba = vport->phba;
  2172. struct lpfc_sli *psli = &phba->sli;
  2173. struct lpfc_nodelist *ndlp, *next_ndlp;
  2174. LPFC_MBOXQ_t *initlinkmbox;
  2175. int rc, clrlaerr = 0;
  2176. if (!(vport->fc_flag & FC_DISC_TMO))
  2177. return;
  2178. spin_lock_irq(shost->host_lock);
  2179. vport->fc_flag &= ~FC_DISC_TMO;
  2180. spin_unlock_irq(shost->host_lock);
  2181. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  2182. "disc timeout: state:x%x rtry:x%x flg:x%x",
  2183. vport->port_state, vport->fc_ns_retry, vport->fc_flag);
  2184. switch (vport->port_state) {
  2185. case LPFC_LOCAL_CFG_LINK:
  2186. /* port_state is identically LPFC_LOCAL_CFG_LINK while waiting for
  2187. * FAN
  2188. */
  2189. /* FAN timeout */
  2190. lpfc_printf_log(phba, KERN_WARNING, LOG_DISCOVERY,
  2191. "%d (%d):0221 FAN timeout\n",
  2192. phba->brd_no, vport->vpi);
  2193. /* Start discovery by sending FLOGI, clean up old rpis */
  2194. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
  2195. nlp_listp) {
  2196. if (ndlp->nlp_state != NLP_STE_NPR_NODE)
  2197. continue;
  2198. if (ndlp->nlp_type & NLP_FABRIC) {
  2199. /* Clean up the ndlp on Fabric connections */
  2200. lpfc_drop_node(vport, ndlp);
  2201. } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
  2202. /* Fail outstanding IO now since device
  2203. * is marked for PLOGI.
  2204. */
  2205. lpfc_unreg_rpi(vport, ndlp);
  2206. }
  2207. }
  2208. if (vport->port_state != LPFC_FLOGI) {
  2209. vport->port_state = LPFC_FLOGI;
  2210. lpfc_set_disctmo(vport);
  2211. lpfc_initial_flogi(vport);
  2212. }
  2213. break;
  2214. case LPFC_FDISC:
  2215. case LPFC_FLOGI:
  2216. /* port_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
  2217. /* Initial FLOGI timeout */
  2218. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
  2219. "%d (%d):0222 Initial %s timeout\n",
  2220. phba->brd_no, vport->vpi,
  2221. vport->vpi ? "FLOGI" : "FDISC");
  2222. /* Assume no Fabric and go on with discovery.
  2223. * Check for outstanding ELS FLOGI to abort.
  2224. */
  2225. /* FLOGI failed, so just use loop map to make discovery list */
  2226. lpfc_disc_list_loopmap(vport);
  2227. /* Start discovery */
  2228. lpfc_disc_start(vport);
  2229. break;
  2230. case LPFC_FABRIC_CFG_LINK:
  2231. /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
  2232. NameServer login */
  2233. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
  2234. "%d (%d):0223 Timeout while waiting for "
  2235. "NameServer login\n",
  2236. phba->brd_no, vport->vpi);
  2237. /* Next look for NameServer ndlp */
  2238. ndlp = lpfc_findnode_did(vport, NameServer_DID);
  2239. if (ndlp)
  2240. lpfc_nlp_put(ndlp);
  2241. /* Start discovery */
  2242. lpfc_disc_start(vport);
  2243. break;
  2244. case LPFC_NS_QRY:
  2245. /* Check for wait for NameServer Rsp timeout */
  2246. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
  2247. "%d (%d):0224 NameServer Query timeout "
  2248. "Data: x%x x%x\n",
  2249. phba->brd_no, vport->vpi,
  2250. vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
  2251. if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
  2252. /* Try it one more time */
  2253. vport->fc_ns_retry++;
  2254. rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT,
  2255. vport->fc_ns_retry, 0);
  2256. if (rc == 0)
  2257. break;
  2258. }
  2259. vport->fc_ns_retry = 0;
  2260. /*
  2261. * Discovery is over.
  2262. * set port_state to PORT_READY if SLI2.
  2263. * cmpl_reg_vpi will set port_state to READY for SLI3.
  2264. */
  2265. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
  2266. lpfc_issue_reg_vpi(phba, vport);
  2267. else { /* NPIV Not enabled */
  2268. lpfc_issue_clear_la(phba, vport);
  2269. vport->port_state = LPFC_VPORT_READY;
  2270. }
  2271. /* Setup and issue mailbox INITIALIZE LINK command */
  2272. initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  2273. if (!initlinkmbox) {
  2274. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
  2275. "%d (%d):0206 Device Discovery "
  2276. "completion error\n",
  2277. phba->brd_no, vport->vpi);
  2278. phba->link_state = LPFC_HBA_ERROR;
  2279. break;
  2280. }
  2281. lpfc_linkdown(phba);
  2282. lpfc_init_link(phba, initlinkmbox, phba->cfg_topology,
  2283. phba->cfg_link_speed);
  2284. initlinkmbox->mb.un.varInitLnk.lipsr_AL_PA = 0;
  2285. initlinkmbox->vport = vport;
  2286. initlinkmbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  2287. rc = lpfc_sli_issue_mbox(phba, initlinkmbox,
  2288. (MBX_NOWAIT | MBX_STOP_IOCB));
  2289. lpfc_set_loopback_flag(phba);
  2290. if (rc == MBX_NOT_FINISHED)
  2291. mempool_free(initlinkmbox, phba->mbox_mem_pool);
  2292. break;
  2293. case LPFC_DISC_AUTH:
  2294. /* Node Authentication timeout */
  2295. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
  2296. "%d (%d):0227 Node Authentication timeout\n",
  2297. phba->brd_no, vport->vpi);
  2298. lpfc_disc_flush_list(vport);
  2299. /*
  2300. * set port_state to PORT_READY if SLI2.
  2301. * cmpl_reg_vpi will set port_state to READY for SLI3.
  2302. */
  2303. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
  2304. lpfc_issue_reg_vpi(phba, vport);
  2305. else { /* NPIV Not enabled */
  2306. lpfc_issue_clear_la(phba, vport);
  2307. vport->port_state = LPFC_VPORT_READY;
  2308. }
  2309. break;
  2310. case LPFC_VPORT_READY:
  2311. if (vport->fc_flag & FC_RSCN_MODE) {
  2312. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
  2313. "%d (%d):0231 RSCN timeout Data: x%x "
  2314. "x%x\n",
  2315. phba->brd_no, vport->vpi,
  2316. vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
  2317. /* Cleanup any outstanding ELS commands */
  2318. lpfc_els_flush_cmd(vport);
  2319. lpfc_els_flush_rscn(vport);
  2320. lpfc_disc_flush_list(vport);
  2321. }
  2322. break;
  2323. default:
  2324. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
  2325. "%d (%d):0229 Unexpected discovery timeout, "
  2326. "vport State x%x\n",
  2327. phba->brd_no, vport->vpi, vport->port_state);
  2328. break;
  2329. }
  2330. switch (phba->link_state) {
  2331. case LPFC_CLEAR_LA:
  2332. /* CLEAR LA timeout */
  2333. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
  2334. "%d (%d):0228 CLEAR LA timeout\n",
  2335. phba->brd_no, vport->vpi);
  2336. clrlaerr = 1;
  2337. break;
  2338. case LPFC_LINK_UNKNOWN:
  2339. case LPFC_WARM_START:
  2340. case LPFC_INIT_START:
  2341. case LPFC_INIT_MBX_CMDS:
  2342. case LPFC_LINK_DOWN:
  2343. case LPFC_LINK_UP:
  2344. case LPFC_HBA_ERROR:
  2345. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
  2346. "%d (%d):0230 Unexpected timeout, hba link "
  2347. "state x%x\n",
  2348. phba->brd_no, vport->vpi, phba->link_state);
  2349. clrlaerr = 1;
  2350. break;
  2351. case LPFC_HBA_READY:
  2352. break;
  2353. }
  2354. if (clrlaerr) {
  2355. lpfc_disc_flush_list(vport);
  2356. psli->ring[(psli->extra_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
  2357. psli->ring[(psli->fcp_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
  2358. psli->ring[(psli->next_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
  2359. vport->port_state = LPFC_VPORT_READY;
  2360. }
  2361. return;
  2362. }
  2363. /*
  2364. * This routine handles processing a NameServer REG_LOGIN mailbox
  2365. * command upon completion. It is setup in the LPFC_MBOXQ
  2366. * as the completion routine when the command is
  2367. * handed off to the SLI layer.
  2368. */
  2369. void
  2370. lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  2371. {
  2372. MAILBOX_t *mb = &pmb->mb;
  2373. struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
  2374. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
  2375. struct lpfc_vport *vport = pmb->vport;
  2376. pmb->context1 = NULL;
  2377. ndlp->nlp_rpi = mb->un.varWords[0];
  2378. ndlp->nlp_type |= NLP_FABRIC;
  2379. lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
  2380. /*
  2381. * Start issuing Fabric-Device Management Interface (FDMI) command to
  2382. * 0xfffffa (FDMI well known port) or Delay issuing FDMI command if
  2383. * fdmi-on=2 (supporting RPA/hostnmae)
  2384. */
  2385. if (phba->cfg_fdmi_on == 1)
  2386. lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA);
  2387. else
  2388. mod_timer(&vport->fc_fdmitmo, jiffies + HZ * 60);
  2389. /* Mailbox took a reference to the node */
  2390. lpfc_nlp_put(ndlp);
  2391. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2392. kfree(mp);
  2393. mempool_free(pmb, phba->mbox_mem_pool);
  2394. return;
  2395. }
  2396. static int
  2397. lpfc_filter_by_rpi(struct lpfc_nodelist *ndlp, void *param)
  2398. {
  2399. uint16_t *rpi = param;
  2400. return ndlp->nlp_rpi == *rpi;
  2401. }
  2402. static int
  2403. lpfc_filter_by_wwpn(struct lpfc_nodelist *ndlp, void *param)
  2404. {
  2405. return memcmp(&ndlp->nlp_portname, param,
  2406. sizeof(ndlp->nlp_portname)) == 0;
  2407. }
  2408. struct lpfc_nodelist *
  2409. __lpfc_find_node(struct lpfc_vport *vport, node_filter filter, void *param)
  2410. {
  2411. struct lpfc_nodelist *ndlp;
  2412. list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
  2413. if (ndlp->nlp_state != NLP_STE_UNUSED_NODE &&
  2414. filter(ndlp, param))
  2415. return ndlp;
  2416. }
  2417. return NULL;
  2418. }
  2419. /*
  2420. * Search node lists for a remote port matching filter criteria
  2421. * Caller needs to hold host_lock before calling this routine.
  2422. */
  2423. struct lpfc_nodelist *
  2424. lpfc_find_node(struct lpfc_vport *vport, node_filter filter, void *param)
  2425. {
  2426. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2427. struct lpfc_nodelist *ndlp;
  2428. spin_lock_irq(shost->host_lock);
  2429. ndlp = __lpfc_find_node(vport, filter, param);
  2430. spin_unlock_irq(shost->host_lock);
  2431. return ndlp;
  2432. }
  2433. /*
  2434. * This routine looks up the ndlp lists for the given RPI. If rpi found it
  2435. * returns the node list element pointer else return NULL.
  2436. */
  2437. struct lpfc_nodelist *
  2438. __lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
  2439. {
  2440. return __lpfc_find_node(vport, lpfc_filter_by_rpi, &rpi);
  2441. }
  2442. struct lpfc_nodelist *
  2443. lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
  2444. {
  2445. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2446. struct lpfc_nodelist *ndlp;
  2447. spin_lock_irq(shost->host_lock);
  2448. ndlp = __lpfc_findnode_rpi(vport, rpi);
  2449. spin_unlock_irq(shost->host_lock);
  2450. return ndlp;
  2451. }
  2452. /*
  2453. * This routine looks up the ndlp lists for the given WWPN. If WWPN found it
  2454. * returns the node element list pointer else return NULL.
  2455. */
  2456. struct lpfc_nodelist *
  2457. lpfc_findnode_wwpn(struct lpfc_vport *vport, struct lpfc_name *wwpn)
  2458. {
  2459. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2460. struct lpfc_nodelist *ndlp;
  2461. spin_lock_irq(shost->host_lock);
  2462. ndlp = __lpfc_find_node(vport, lpfc_filter_by_wwpn, wwpn);
  2463. spin_unlock_irq(shost->host_lock);
  2464. return ndlp;
  2465. }
  2466. void
  2467. lpfc_dev_loss_delay(unsigned long ptr)
  2468. {
  2469. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
  2470. struct lpfc_vport *vport = ndlp->vport;
  2471. struct lpfc_hba *phba = vport->phba;
  2472. struct lpfc_work_evt *evtp = &ndlp->dev_loss_evt;
  2473. unsigned long flags;
  2474. evtp = &ndlp->dev_loss_evt;
  2475. spin_lock_irqsave(&phba->hbalock, flags);
  2476. if (!list_empty(&evtp->evt_listp)) {
  2477. spin_unlock_irqrestore(&phba->hbalock, flags);
  2478. return;
  2479. }
  2480. evtp->evt_arg1 = ndlp;
  2481. evtp->evt = LPFC_EVT_DEV_LOSS_DELAY;
  2482. list_add_tail(&evtp->evt_listp, &phba->work_list);
  2483. if (phba->work_wait)
  2484. lpfc_worker_wake_up(phba);
  2485. spin_unlock_irqrestore(&phba->hbalock, flags);
  2486. return;
  2487. }
  2488. void
  2489. lpfc_nlp_init(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  2490. uint32_t did)
  2491. {
  2492. memset(ndlp, 0, sizeof (struct lpfc_nodelist));
  2493. INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp);
  2494. INIT_LIST_HEAD(&ndlp->dev_loss_evt.evt_listp);
  2495. init_timer(&ndlp->nlp_delayfunc);
  2496. ndlp->nlp_delayfunc.function = lpfc_els_retry_delay;
  2497. ndlp->nlp_delayfunc.data = (unsigned long)ndlp;
  2498. ndlp->nlp_DID = did;
  2499. ndlp->vport = vport;
  2500. ndlp->nlp_sid = NLP_NO_SID;
  2501. INIT_LIST_HEAD(&ndlp->nlp_listp);
  2502. kref_init(&ndlp->kref);
  2503. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
  2504. "node init: did:x%x",
  2505. ndlp->nlp_DID, 0, 0);
  2506. return;
  2507. }
  2508. void
  2509. lpfc_nlp_release(struct kref *kref)
  2510. {
  2511. struct lpfc_nodelist *ndlp = container_of(kref, struct lpfc_nodelist,
  2512. kref);
  2513. lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
  2514. "node release: did:x%x flg:x%x type:x%x",
  2515. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
  2516. lpfc_nlp_remove(ndlp->vport, ndlp);
  2517. mempool_free(ndlp, ndlp->vport->phba->nlp_mem_pool);
  2518. }
  2519. struct lpfc_nodelist *
  2520. lpfc_nlp_get(struct lpfc_nodelist *ndlp)
  2521. {
  2522. if (ndlp)
  2523. kref_get(&ndlp->kref);
  2524. return ndlp;
  2525. }
  2526. int
  2527. lpfc_nlp_put(struct lpfc_nodelist *ndlp)
  2528. {
  2529. return ndlp ? kref_put(&ndlp->kref, lpfc_nlp_release) : 0;
  2530. }