bfa_fcs_rport.c 88 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465
  1. /*
  2. * Copyright (c) 2005-2010 Brocade Communications Systems, Inc.
  3. * All rights reserved
  4. * www.brocade.com
  5. *
  6. * Linux driver for Brocade Fibre Channel Host Bus Adapter.
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License (GPL) Version 2 as
  10. * published by the Free Software Foundation
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. */
  17. /*
  18. * rport.c Remote port implementation.
  19. */
  20. #include "bfad_drv.h"
  21. #include "bfad_im.h"
  22. #include "bfa_fcs.h"
  23. #include "bfa_fcbuild.h"
  24. BFA_TRC_FILE(FCS, RPORT);
  25. static u32
  26. bfa_fcs_rport_del_timeout = BFA_FCS_RPORT_DEF_DEL_TIMEOUT * 1000;
  27. /* In millisecs */
  28. /*
  29. * bfa_fcs_rport_max_logins is max count of bfa_fcs_rports
  30. * whereas DEF_CFG_NUM_RPORTS is max count of bfa_rports
  31. */
  32. static u32 bfa_fcs_rport_max_logins = BFA_FCS_MAX_RPORT_LOGINS;
  33. /*
  34. * forward declarations
  35. */
  36. static struct bfa_fcs_rport_s *bfa_fcs_rport_alloc(
  37. struct bfa_fcs_lport_s *port, wwn_t pwwn, u32 rpid);
  38. static void bfa_fcs_rport_free(struct bfa_fcs_rport_s *rport);
  39. static void bfa_fcs_rport_hal_online(struct bfa_fcs_rport_s *rport);
  40. static void bfa_fcs_rport_fcs_online_action(struct bfa_fcs_rport_s *rport);
  41. static void bfa_fcs_rport_hal_online_action(struct bfa_fcs_rport_s *rport);
  42. static void bfa_fcs_rport_fcs_offline_action(struct bfa_fcs_rport_s *rport);
  43. static void bfa_fcs_rport_hal_offline_action(struct bfa_fcs_rport_s *rport);
  44. static void bfa_fcs_rport_update(struct bfa_fcs_rport_s *rport,
  45. struct fc_logi_s *plogi);
  46. static void bfa_fcs_rport_timeout(void *arg);
  47. static void bfa_fcs_rport_send_plogi(void *rport_cbarg,
  48. struct bfa_fcxp_s *fcxp_alloced);
  49. static void bfa_fcs_rport_send_plogiacc(void *rport_cbarg,
  50. struct bfa_fcxp_s *fcxp_alloced);
  51. static void bfa_fcs_rport_plogi_response(void *fcsarg,
  52. struct bfa_fcxp_s *fcxp, void *cbarg,
  53. bfa_status_t req_status, u32 rsp_len,
  54. u32 resid_len, struct fchs_s *rsp_fchs);
  55. static void bfa_fcs_rport_send_adisc(void *rport_cbarg,
  56. struct bfa_fcxp_s *fcxp_alloced);
  57. static void bfa_fcs_rport_adisc_response(void *fcsarg,
  58. struct bfa_fcxp_s *fcxp, void *cbarg,
  59. bfa_status_t req_status, u32 rsp_len,
  60. u32 resid_len, struct fchs_s *rsp_fchs);
  61. static void bfa_fcs_rport_send_nsdisc(void *rport_cbarg,
  62. struct bfa_fcxp_s *fcxp_alloced);
  63. static void bfa_fcs_rport_gidpn_response(void *fcsarg,
  64. struct bfa_fcxp_s *fcxp, void *cbarg,
  65. bfa_status_t req_status, u32 rsp_len,
  66. u32 resid_len, struct fchs_s *rsp_fchs);
  67. static void bfa_fcs_rport_gpnid_response(void *fcsarg,
  68. struct bfa_fcxp_s *fcxp, void *cbarg,
  69. bfa_status_t req_status, u32 rsp_len,
  70. u32 resid_len, struct fchs_s *rsp_fchs);
  71. static void bfa_fcs_rport_send_logo(void *rport_cbarg,
  72. struct bfa_fcxp_s *fcxp_alloced);
  73. static void bfa_fcs_rport_send_logo_acc(void *rport_cbarg);
  74. static void bfa_fcs_rport_process_prli(struct bfa_fcs_rport_s *rport,
  75. struct fchs_s *rx_fchs, u16 len);
  76. static void bfa_fcs_rport_send_ls_rjt(struct bfa_fcs_rport_s *rport,
  77. struct fchs_s *rx_fchs, u8 reason_code,
  78. u8 reason_code_expl);
  79. static void bfa_fcs_rport_process_adisc(struct bfa_fcs_rport_s *rport,
  80. struct fchs_s *rx_fchs, u16 len);
  81. static void bfa_fcs_rport_send_prlo_acc(struct bfa_fcs_rport_s *rport);
  82. static void bfa_fcs_rport_hal_offline(struct bfa_fcs_rport_s *rport);
  83. static void bfa_fcs_rport_sm_uninit(struct bfa_fcs_rport_s *rport,
  84. enum rport_event event);
  85. static void bfa_fcs_rport_sm_plogi_sending(struct bfa_fcs_rport_s *rport,
  86. enum rport_event event);
  87. static void bfa_fcs_rport_sm_plogiacc_sending(struct bfa_fcs_rport_s *rport,
  88. enum rport_event event);
  89. static void bfa_fcs_rport_sm_plogi_retry(struct bfa_fcs_rport_s *rport,
  90. enum rport_event event);
  91. static void bfa_fcs_rport_sm_plogi(struct bfa_fcs_rport_s *rport,
  92. enum rport_event event);
  93. static void bfa_fcs_rport_sm_fc4_fcs_online(struct bfa_fcs_rport_s *rport,
  94. enum rport_event event);
  95. static void bfa_fcs_rport_sm_hal_online(struct bfa_fcs_rport_s *rport,
  96. enum rport_event event);
  97. static void bfa_fcs_rport_sm_online(struct bfa_fcs_rport_s *rport,
  98. enum rport_event event);
  99. static void bfa_fcs_rport_sm_nsquery_sending(struct bfa_fcs_rport_s *rport,
  100. enum rport_event event);
  101. static void bfa_fcs_rport_sm_nsquery(struct bfa_fcs_rport_s *rport,
  102. enum rport_event event);
  103. static void bfa_fcs_rport_sm_adisc_online_sending(
  104. struct bfa_fcs_rport_s *rport, enum rport_event event);
  105. static void bfa_fcs_rport_sm_adisc_online(struct bfa_fcs_rport_s *rport,
  106. enum rport_event event);
  107. static void bfa_fcs_rport_sm_adisc_offline_sending(struct bfa_fcs_rport_s
  108. *rport, enum rport_event event);
  109. static void bfa_fcs_rport_sm_adisc_offline(struct bfa_fcs_rport_s *rport,
  110. enum rport_event event);
  111. static void bfa_fcs_rport_sm_fc4_logorcv(struct bfa_fcs_rport_s *rport,
  112. enum rport_event event);
  113. static void bfa_fcs_rport_sm_fc4_logosend(struct bfa_fcs_rport_s *rport,
  114. enum rport_event event);
  115. static void bfa_fcs_rport_sm_fc4_offline(struct bfa_fcs_rport_s *rport,
  116. enum rport_event event);
  117. static void bfa_fcs_rport_sm_hcb_offline(struct bfa_fcs_rport_s *rport,
  118. enum rport_event event);
  119. static void bfa_fcs_rport_sm_hcb_logorcv(struct bfa_fcs_rport_s *rport,
  120. enum rport_event event);
  121. static void bfa_fcs_rport_sm_hcb_logosend(struct bfa_fcs_rport_s *rport,
  122. enum rport_event event);
  123. static void bfa_fcs_rport_sm_logo_sending(struct bfa_fcs_rport_s *rport,
  124. enum rport_event event);
  125. static void bfa_fcs_rport_sm_offline(struct bfa_fcs_rport_s *rport,
  126. enum rport_event event);
  127. static void bfa_fcs_rport_sm_nsdisc_sending(struct bfa_fcs_rport_s *rport,
  128. enum rport_event event);
  129. static void bfa_fcs_rport_sm_nsdisc_retry(struct bfa_fcs_rport_s *rport,
  130. enum rport_event event);
  131. static void bfa_fcs_rport_sm_nsdisc_sent(struct bfa_fcs_rport_s *rport,
  132. enum rport_event event);
  133. static void bfa_fcs_rport_sm_nsdisc_sent(struct bfa_fcs_rport_s *rport,
  134. enum rport_event event);
  135. static void bfa_fcs_rport_sm_fc4_off_delete(struct bfa_fcs_rport_s *rport,
  136. enum rport_event event);
  137. static void bfa_fcs_rport_sm_delete_pending(struct bfa_fcs_rport_s *rport,
  138. enum rport_event event);
  139. static struct bfa_sm_table_s rport_sm_table[] = {
  140. {BFA_SM(bfa_fcs_rport_sm_uninit), BFA_RPORT_UNINIT},
  141. {BFA_SM(bfa_fcs_rport_sm_plogi_sending), BFA_RPORT_PLOGI},
  142. {BFA_SM(bfa_fcs_rport_sm_plogiacc_sending), BFA_RPORT_ONLINE},
  143. {BFA_SM(bfa_fcs_rport_sm_plogi_retry), BFA_RPORT_PLOGI_RETRY},
  144. {BFA_SM(bfa_fcs_rport_sm_plogi), BFA_RPORT_PLOGI},
  145. {BFA_SM(bfa_fcs_rport_sm_fc4_fcs_online), BFA_RPORT_ONLINE},
  146. {BFA_SM(bfa_fcs_rport_sm_hal_online), BFA_RPORT_ONLINE},
  147. {BFA_SM(bfa_fcs_rport_sm_online), BFA_RPORT_ONLINE},
  148. {BFA_SM(bfa_fcs_rport_sm_nsquery_sending), BFA_RPORT_NSQUERY},
  149. {BFA_SM(bfa_fcs_rport_sm_nsquery), BFA_RPORT_NSQUERY},
  150. {BFA_SM(bfa_fcs_rport_sm_adisc_online_sending), BFA_RPORT_ADISC},
  151. {BFA_SM(bfa_fcs_rport_sm_adisc_online), BFA_RPORT_ADISC},
  152. {BFA_SM(bfa_fcs_rport_sm_adisc_offline_sending), BFA_RPORT_ADISC},
  153. {BFA_SM(bfa_fcs_rport_sm_adisc_offline), BFA_RPORT_ADISC},
  154. {BFA_SM(bfa_fcs_rport_sm_fc4_logorcv), BFA_RPORT_LOGORCV},
  155. {BFA_SM(bfa_fcs_rport_sm_fc4_logosend), BFA_RPORT_LOGO},
  156. {BFA_SM(bfa_fcs_rport_sm_fc4_offline), BFA_RPORT_OFFLINE},
  157. {BFA_SM(bfa_fcs_rport_sm_hcb_offline), BFA_RPORT_OFFLINE},
  158. {BFA_SM(bfa_fcs_rport_sm_hcb_logorcv), BFA_RPORT_LOGORCV},
  159. {BFA_SM(bfa_fcs_rport_sm_hcb_logosend), BFA_RPORT_LOGO},
  160. {BFA_SM(bfa_fcs_rport_sm_logo_sending), BFA_RPORT_LOGO},
  161. {BFA_SM(bfa_fcs_rport_sm_offline), BFA_RPORT_OFFLINE},
  162. {BFA_SM(bfa_fcs_rport_sm_nsdisc_sending), BFA_RPORT_NSDISC},
  163. {BFA_SM(bfa_fcs_rport_sm_nsdisc_retry), BFA_RPORT_NSDISC},
  164. {BFA_SM(bfa_fcs_rport_sm_nsdisc_sent), BFA_RPORT_NSDISC},
  165. };
  166. /*
  167. * Beginning state.
  168. */
  169. static void
  170. bfa_fcs_rport_sm_uninit(struct bfa_fcs_rport_s *rport, enum rport_event event)
  171. {
  172. bfa_trc(rport->fcs, rport->pwwn);
  173. bfa_trc(rport->fcs, rport->pid);
  174. bfa_trc(rport->fcs, event);
  175. switch (event) {
  176. case RPSM_EVENT_PLOGI_SEND:
  177. bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogi_sending);
  178. rport->plogi_retries = 0;
  179. bfa_fcs_rport_send_plogi(rport, NULL);
  180. break;
  181. case RPSM_EVENT_PLOGI_RCVD:
  182. bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogiacc_sending);
  183. bfa_fcs_rport_send_plogiacc(rport, NULL);
  184. break;
  185. case RPSM_EVENT_PLOGI_COMP:
  186. bfa_sm_set_state(rport, bfa_fcs_rport_sm_hal_online);
  187. bfa_fcs_rport_hal_online(rport);
  188. break;
  189. case RPSM_EVENT_ADDRESS_CHANGE:
  190. case RPSM_EVENT_ADDRESS_DISC:
  191. bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sending);
  192. rport->ns_retries = 0;
  193. bfa_fcs_rport_send_nsdisc(rport, NULL);
  194. break;
  195. default:
  196. bfa_sm_fault(rport->fcs, event);
  197. }
  198. }
  199. /*
  200. * PLOGI is being sent.
  201. */
  202. static void
  203. bfa_fcs_rport_sm_plogi_sending(struct bfa_fcs_rport_s *rport,
  204. enum rport_event event)
  205. {
  206. bfa_trc(rport->fcs, rport->pwwn);
  207. bfa_trc(rport->fcs, rport->pid);
  208. bfa_trc(rport->fcs, event);
  209. switch (event) {
  210. case RPSM_EVENT_FCXP_SENT:
  211. bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogi);
  212. break;
  213. case RPSM_EVENT_DELETE:
  214. bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
  215. bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  216. bfa_fcs_rport_free(rport);
  217. break;
  218. case RPSM_EVENT_PLOGI_RCVD:
  219. bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogiacc_sending);
  220. bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  221. bfa_fcs_rport_send_plogiacc(rport, NULL);
  222. break;
  223. case RPSM_EVENT_SCN_OFFLINE:
  224. bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
  225. bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  226. bfa_timer_start(rport->fcs->bfa, &rport->timer,
  227. bfa_fcs_rport_timeout, rport,
  228. bfa_fcs_rport_del_timeout);
  229. break;
  230. case RPSM_EVENT_ADDRESS_CHANGE:
  231. case RPSM_EVENT_FAB_SCN:
  232. /* query the NS */
  233. bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  234. WARN_ON(!(bfa_fcport_get_topology(rport->port->fcs->bfa) !=
  235. BFA_PORT_TOPOLOGY_LOOP));
  236. bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sending);
  237. rport->ns_retries = 0;
  238. bfa_fcs_rport_send_nsdisc(rport, NULL);
  239. break;
  240. case RPSM_EVENT_LOGO_IMP:
  241. rport->pid = 0;
  242. bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
  243. bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  244. bfa_timer_start(rport->fcs->bfa, &rport->timer,
  245. bfa_fcs_rport_timeout, rport,
  246. bfa_fcs_rport_del_timeout);
  247. break;
  248. default:
  249. bfa_sm_fault(rport->fcs, event);
  250. }
  251. }
  252. /*
  253. * PLOGI is being sent.
  254. */
  255. static void
  256. bfa_fcs_rport_sm_plogiacc_sending(struct bfa_fcs_rport_s *rport,
  257. enum rport_event event)
  258. {
  259. bfa_trc(rport->fcs, rport->pwwn);
  260. bfa_trc(rport->fcs, rport->pid);
  261. bfa_trc(rport->fcs, event);
  262. switch (event) {
  263. case RPSM_EVENT_FCXP_SENT:
  264. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_fcs_online);
  265. bfa_fcs_rport_fcs_online_action(rport);
  266. break;
  267. case RPSM_EVENT_DELETE:
  268. bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
  269. bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  270. bfa_fcs_rport_free(rport);
  271. break;
  272. case RPSM_EVENT_PLOGI_RCVD:
  273. case RPSM_EVENT_PLOGI_COMP:
  274. case RPSM_EVENT_FAB_SCN:
  275. /*
  276. * Ignore, SCN is possibly online notification.
  277. */
  278. break;
  279. case RPSM_EVENT_SCN_OFFLINE:
  280. bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
  281. bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  282. bfa_timer_start(rport->fcs->bfa, &rport->timer,
  283. bfa_fcs_rport_timeout, rport,
  284. bfa_fcs_rport_del_timeout);
  285. break;
  286. case RPSM_EVENT_ADDRESS_CHANGE:
  287. bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  288. bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sending);
  289. rport->ns_retries = 0;
  290. bfa_fcs_rport_send_nsdisc(rport, NULL);
  291. break;
  292. case RPSM_EVENT_LOGO_IMP:
  293. rport->pid = 0;
  294. bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
  295. bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  296. bfa_timer_start(rport->fcs->bfa, &rport->timer,
  297. bfa_fcs_rport_timeout, rport,
  298. bfa_fcs_rport_del_timeout);
  299. break;
  300. case RPSM_EVENT_HCB_OFFLINE:
  301. /*
  302. * Ignore BFA callback, on a PLOGI receive we call bfa offline.
  303. */
  304. break;
  305. default:
  306. bfa_sm_fault(rport->fcs, event);
  307. }
  308. }
  309. /*
  310. * PLOGI is sent.
  311. */
  312. static void
  313. bfa_fcs_rport_sm_plogi_retry(struct bfa_fcs_rport_s *rport,
  314. enum rport_event event)
  315. {
  316. bfa_trc(rport->fcs, rport->pwwn);
  317. bfa_trc(rport->fcs, rport->pid);
  318. bfa_trc(rport->fcs, event);
  319. switch (event) {
  320. case RPSM_EVENT_TIMEOUT:
  321. bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogi_sending);
  322. bfa_fcs_rport_send_plogi(rport, NULL);
  323. break;
  324. case RPSM_EVENT_DELETE:
  325. bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
  326. bfa_timer_stop(&rport->timer);
  327. bfa_fcs_rport_free(rport);
  328. break;
  329. case RPSM_EVENT_PRLO_RCVD:
  330. case RPSM_EVENT_LOGO_RCVD:
  331. break;
  332. case RPSM_EVENT_PLOGI_RCVD:
  333. bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogiacc_sending);
  334. bfa_timer_stop(&rport->timer);
  335. bfa_fcs_rport_send_plogiacc(rport, NULL);
  336. break;
  337. case RPSM_EVENT_SCN_OFFLINE:
  338. bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
  339. bfa_timer_stop(&rport->timer);
  340. bfa_timer_start(rport->fcs->bfa, &rport->timer,
  341. bfa_fcs_rport_timeout, rport,
  342. bfa_fcs_rport_del_timeout);
  343. break;
  344. case RPSM_EVENT_ADDRESS_CHANGE:
  345. case RPSM_EVENT_FAB_SCN:
  346. bfa_timer_stop(&rport->timer);
  347. WARN_ON(!(bfa_fcport_get_topology(rport->port->fcs->bfa) !=
  348. BFA_PORT_TOPOLOGY_LOOP));
  349. bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sending);
  350. rport->ns_retries = 0;
  351. bfa_fcs_rport_send_nsdisc(rport, NULL);
  352. break;
  353. case RPSM_EVENT_LOGO_IMP:
  354. rport->pid = 0;
  355. bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
  356. bfa_timer_stop(&rport->timer);
  357. bfa_timer_start(rport->fcs->bfa, &rport->timer,
  358. bfa_fcs_rport_timeout, rport,
  359. bfa_fcs_rport_del_timeout);
  360. break;
  361. case RPSM_EVENT_PLOGI_COMP:
  362. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_fcs_online);
  363. bfa_timer_stop(&rport->timer);
  364. bfa_fcs_rport_fcs_online_action(rport);
  365. break;
  366. default:
  367. bfa_sm_fault(rport->fcs, event);
  368. }
  369. }
  370. /*
  371. * PLOGI is sent.
  372. */
  373. static void
  374. bfa_fcs_rport_sm_plogi(struct bfa_fcs_rport_s *rport, enum rport_event event)
  375. {
  376. bfa_trc(rport->fcs, rport->pwwn);
  377. bfa_trc(rport->fcs, rport->pid);
  378. bfa_trc(rport->fcs, event);
  379. switch (event) {
  380. case RPSM_EVENT_ACCEPTED:
  381. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_fcs_online);
  382. rport->plogi_retries = 0;
  383. bfa_fcs_rport_fcs_online_action(rport);
  384. break;
  385. case RPSM_EVENT_LOGO_RCVD:
  386. bfa_fcs_rport_send_logo_acc(rport);
  387. /*
  388. * !! fall through !!
  389. */
  390. case RPSM_EVENT_PRLO_RCVD:
  391. if (rport->prlo == BFA_TRUE)
  392. bfa_fcs_rport_send_prlo_acc(rport);
  393. bfa_fcxp_discard(rport->fcxp);
  394. /*
  395. * !! fall through !!
  396. */
  397. case RPSM_EVENT_FAILED:
  398. if (rport->plogi_retries < BFA_FCS_RPORT_MAX_RETRIES) {
  399. rport->plogi_retries++;
  400. bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogi_retry);
  401. bfa_timer_start(rport->fcs->bfa, &rport->timer,
  402. bfa_fcs_rport_timeout, rport,
  403. BFA_FCS_RETRY_TIMEOUT);
  404. } else {
  405. bfa_stats(rport->port, rport_del_max_plogi_retry);
  406. rport->old_pid = rport->pid;
  407. rport->pid = 0;
  408. bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
  409. bfa_timer_start(rport->fcs->bfa, &rport->timer,
  410. bfa_fcs_rport_timeout, rport,
  411. bfa_fcs_rport_del_timeout);
  412. }
  413. break;
  414. case RPSM_EVENT_SCN_ONLINE:
  415. break;
  416. case RPSM_EVENT_SCN_OFFLINE:
  417. bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
  418. bfa_fcxp_discard(rport->fcxp);
  419. bfa_timer_start(rport->fcs->bfa, &rport->timer,
  420. bfa_fcs_rport_timeout, rport,
  421. bfa_fcs_rport_del_timeout);
  422. break;
  423. case RPSM_EVENT_PLOGI_RETRY:
  424. rport->plogi_retries = 0;
  425. bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogi_retry);
  426. bfa_timer_start(rport->fcs->bfa, &rport->timer,
  427. bfa_fcs_rport_timeout, rport,
  428. (FC_RA_TOV * 1000));
  429. break;
  430. case RPSM_EVENT_LOGO_IMP:
  431. rport->pid = 0;
  432. bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
  433. bfa_fcxp_discard(rport->fcxp);
  434. bfa_timer_start(rport->fcs->bfa, &rport->timer,
  435. bfa_fcs_rport_timeout, rport,
  436. bfa_fcs_rport_del_timeout);
  437. break;
  438. case RPSM_EVENT_ADDRESS_CHANGE:
  439. case RPSM_EVENT_FAB_SCN:
  440. bfa_fcxp_discard(rport->fcxp);
  441. WARN_ON(!(bfa_fcport_get_topology(rport->port->fcs->bfa) !=
  442. BFA_PORT_TOPOLOGY_LOOP));
  443. bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sending);
  444. rport->ns_retries = 0;
  445. bfa_fcs_rport_send_nsdisc(rport, NULL);
  446. break;
  447. case RPSM_EVENT_PLOGI_RCVD:
  448. bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogiacc_sending);
  449. bfa_fcxp_discard(rport->fcxp);
  450. bfa_fcs_rport_send_plogiacc(rport, NULL);
  451. break;
  452. case RPSM_EVENT_DELETE:
  453. bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
  454. bfa_fcxp_discard(rport->fcxp);
  455. bfa_fcs_rport_free(rport);
  456. break;
  457. case RPSM_EVENT_PLOGI_COMP:
  458. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_fcs_online);
  459. bfa_fcxp_discard(rport->fcxp);
  460. bfa_fcs_rport_fcs_online_action(rport);
  461. break;
  462. default:
  463. bfa_sm_fault(rport->fcs, event);
  464. }
  465. }
  466. /*
  467. * PLOGI is done. Await bfa_fcs_itnim to ascertain the scsi function
  468. */
  469. static void
  470. bfa_fcs_rport_sm_fc4_fcs_online(struct bfa_fcs_rport_s *rport,
  471. enum rport_event event)
  472. {
  473. bfa_trc(rport->fcs, rport->pwwn);
  474. bfa_trc(rport->fcs, rport->pid);
  475. bfa_trc(rport->fcs, event);
  476. switch (event) {
  477. case RPSM_EVENT_FC4_FCS_ONLINE:
  478. if (rport->scsi_function == BFA_RPORT_INITIATOR) {
  479. if (!BFA_FCS_PID_IS_WKA(rport->pid))
  480. bfa_fcs_rpf_rport_online(rport);
  481. bfa_sm_set_state(rport, bfa_fcs_rport_sm_online);
  482. break;
  483. }
  484. if (!rport->bfa_rport)
  485. rport->bfa_rport =
  486. bfa_rport_create(rport->fcs->bfa, rport);
  487. if (rport->bfa_rport) {
  488. bfa_sm_set_state(rport, bfa_fcs_rport_sm_hal_online);
  489. bfa_fcs_rport_hal_online(rport);
  490. } else {
  491. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logosend);
  492. bfa_fcs_rport_fcs_offline_action(rport);
  493. }
  494. break;
  495. case RPSM_EVENT_PLOGI_RCVD:
  496. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
  497. rport->plogi_pending = BFA_TRUE;
  498. bfa_fcs_rport_fcs_offline_action(rport);
  499. break;
  500. case RPSM_EVENT_PLOGI_COMP:
  501. case RPSM_EVENT_LOGO_IMP:
  502. case RPSM_EVENT_ADDRESS_CHANGE:
  503. case RPSM_EVENT_FAB_SCN:
  504. case RPSM_EVENT_SCN_OFFLINE:
  505. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
  506. bfa_fcs_rport_fcs_offline_action(rport);
  507. break;
  508. case RPSM_EVENT_LOGO_RCVD:
  509. case RPSM_EVENT_PRLO_RCVD:
  510. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logorcv);
  511. bfa_fcs_rport_fcs_offline_action(rport);
  512. break;
  513. case RPSM_EVENT_DELETE:
  514. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logosend);
  515. bfa_fcs_rport_fcs_offline_action(rport);
  516. break;
  517. default:
  518. bfa_sm_fault(rport->fcs, event);
  519. break;
  520. }
  521. }
  522. /*
  523. * PLOGI is complete. Awaiting BFA rport online callback. FC-4s
  524. * are offline.
  525. */
  526. static void
  527. bfa_fcs_rport_sm_hal_online(struct bfa_fcs_rport_s *rport,
  528. enum rport_event event)
  529. {
  530. bfa_trc(rport->fcs, rport->pwwn);
  531. bfa_trc(rport->fcs, rport->pid);
  532. bfa_trc(rport->fcs, event);
  533. switch (event) {
  534. case RPSM_EVENT_HCB_ONLINE:
  535. bfa_sm_set_state(rport, bfa_fcs_rport_sm_online);
  536. bfa_fcs_rport_hal_online_action(rport);
  537. break;
  538. case RPSM_EVENT_PLOGI_COMP:
  539. break;
  540. case RPSM_EVENT_PRLO_RCVD:
  541. case RPSM_EVENT_LOGO_RCVD:
  542. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logorcv);
  543. bfa_fcs_rport_fcs_offline_action(rport);
  544. break;
  545. case RPSM_EVENT_FAB_SCN:
  546. case RPSM_EVENT_LOGO_IMP:
  547. case RPSM_EVENT_ADDRESS_CHANGE:
  548. case RPSM_EVENT_SCN_OFFLINE:
  549. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
  550. bfa_fcs_rport_fcs_offline_action(rport);
  551. break;
  552. case RPSM_EVENT_PLOGI_RCVD:
  553. rport->plogi_pending = BFA_TRUE;
  554. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
  555. bfa_fcs_rport_fcs_offline_action(rport);
  556. break;
  557. case RPSM_EVENT_DELETE:
  558. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logosend);
  559. bfa_fcs_rport_fcs_offline_action(rport);
  560. break;
  561. default:
  562. bfa_sm_fault(rport->fcs, event);
  563. }
  564. }
  565. /*
  566. * Rport is ONLINE. FC-4s active.
  567. */
  568. static void
  569. bfa_fcs_rport_sm_online(struct bfa_fcs_rport_s *rport, enum rport_event event)
  570. {
  571. bfa_trc(rport->fcs, rport->pwwn);
  572. bfa_trc(rport->fcs, rport->pid);
  573. bfa_trc(rport->fcs, event);
  574. switch (event) {
  575. case RPSM_EVENT_FAB_SCN:
  576. if (bfa_fcs_fabric_is_switched(rport->port->fabric)) {
  577. bfa_sm_set_state(rport,
  578. bfa_fcs_rport_sm_nsquery_sending);
  579. rport->ns_retries = 0;
  580. bfa_fcs_rport_send_nsdisc(rport, NULL);
  581. } else {
  582. bfa_sm_set_state(rport,
  583. bfa_fcs_rport_sm_adisc_online_sending);
  584. bfa_fcs_rport_send_adisc(rport, NULL);
  585. }
  586. break;
  587. case RPSM_EVENT_PLOGI_RCVD:
  588. case RPSM_EVENT_LOGO_IMP:
  589. case RPSM_EVENT_ADDRESS_CHANGE:
  590. case RPSM_EVENT_SCN_OFFLINE:
  591. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
  592. bfa_fcs_rport_hal_offline_action(rport);
  593. break;
  594. case RPSM_EVENT_DELETE:
  595. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logosend);
  596. bfa_fcs_rport_hal_offline_action(rport);
  597. break;
  598. case RPSM_EVENT_LOGO_RCVD:
  599. case RPSM_EVENT_PRLO_RCVD:
  600. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logorcv);
  601. bfa_fcs_rport_hal_offline_action(rport);
  602. break;
  603. case RPSM_EVENT_SCN_ONLINE:
  604. case RPSM_EVENT_PLOGI_COMP:
  605. break;
  606. default:
  607. bfa_sm_fault(rport->fcs, event);
  608. }
  609. }
  610. /*
  611. * An SCN event is received in ONLINE state. NS query is being sent
  612. * prior to ADISC authentication with rport. FC-4s are paused.
  613. */
  614. static void
  615. bfa_fcs_rport_sm_nsquery_sending(struct bfa_fcs_rport_s *rport,
  616. enum rport_event event)
  617. {
  618. bfa_trc(rport->fcs, rport->pwwn);
  619. bfa_trc(rport->fcs, rport->pid);
  620. bfa_trc(rport->fcs, event);
  621. switch (event) {
  622. case RPSM_EVENT_FCXP_SENT:
  623. bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsquery);
  624. break;
  625. case RPSM_EVENT_DELETE:
  626. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logosend);
  627. bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  628. bfa_fcs_rport_hal_offline_action(rport);
  629. break;
  630. case RPSM_EVENT_FAB_SCN:
  631. /*
  632. * ignore SCN, wait for response to query itself
  633. */
  634. break;
  635. case RPSM_EVENT_LOGO_RCVD:
  636. case RPSM_EVENT_PRLO_RCVD:
  637. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logorcv);
  638. bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  639. bfa_fcs_rport_hal_offline_action(rport);
  640. break;
  641. case RPSM_EVENT_LOGO_IMP:
  642. case RPSM_EVENT_PLOGI_RCVD:
  643. case RPSM_EVENT_ADDRESS_CHANGE:
  644. case RPSM_EVENT_PLOGI_COMP:
  645. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
  646. bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  647. bfa_fcs_rport_hal_offline_action(rport);
  648. break;
  649. default:
  650. bfa_sm_fault(rport->fcs, event);
  651. }
  652. }
  653. /*
  654. * An SCN event is received in ONLINE state. NS query is sent to rport.
  655. * FC-4s are paused.
  656. */
  657. static void
  658. bfa_fcs_rport_sm_nsquery(struct bfa_fcs_rport_s *rport, enum rport_event event)
  659. {
  660. bfa_trc(rport->fcs, rport->pwwn);
  661. bfa_trc(rport->fcs, rport->pid);
  662. bfa_trc(rport->fcs, event);
  663. switch (event) {
  664. case RPSM_EVENT_ACCEPTED:
  665. bfa_sm_set_state(rport, bfa_fcs_rport_sm_adisc_online_sending);
  666. bfa_fcs_rport_send_adisc(rport, NULL);
  667. break;
  668. case RPSM_EVENT_FAILED:
  669. rport->ns_retries++;
  670. if (rport->ns_retries < BFA_FCS_RPORT_MAX_RETRIES) {
  671. bfa_sm_set_state(rport,
  672. bfa_fcs_rport_sm_nsquery_sending);
  673. bfa_fcs_rport_send_nsdisc(rport, NULL);
  674. } else {
  675. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
  676. bfa_fcs_rport_hal_offline_action(rport);
  677. }
  678. break;
  679. case RPSM_EVENT_DELETE:
  680. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logosend);
  681. bfa_fcxp_discard(rport->fcxp);
  682. bfa_fcs_rport_hal_offline_action(rport);
  683. break;
  684. case RPSM_EVENT_FAB_SCN:
  685. break;
  686. case RPSM_EVENT_LOGO_RCVD:
  687. case RPSM_EVENT_PRLO_RCVD:
  688. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logorcv);
  689. bfa_fcxp_discard(rport->fcxp);
  690. bfa_fcs_rport_hal_offline_action(rport);
  691. break;
  692. case RPSM_EVENT_PLOGI_COMP:
  693. case RPSM_EVENT_ADDRESS_CHANGE:
  694. case RPSM_EVENT_PLOGI_RCVD:
  695. case RPSM_EVENT_LOGO_IMP:
  696. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
  697. bfa_fcxp_discard(rport->fcxp);
  698. bfa_fcs_rport_hal_offline_action(rport);
  699. break;
  700. default:
  701. bfa_sm_fault(rport->fcs, event);
  702. }
  703. }
  704. /*
  705. * An SCN event is received in ONLINE state. ADISC is being sent for
  706. * authenticating with rport. FC-4s are paused.
  707. */
  708. static void
  709. bfa_fcs_rport_sm_adisc_online_sending(struct bfa_fcs_rport_s *rport,
  710. enum rport_event event)
  711. {
  712. bfa_trc(rport->fcs, rport->pwwn);
  713. bfa_trc(rport->fcs, rport->pid);
  714. bfa_trc(rport->fcs, event);
  715. switch (event) {
  716. case RPSM_EVENT_FCXP_SENT:
  717. bfa_sm_set_state(rport, bfa_fcs_rport_sm_adisc_online);
  718. break;
  719. case RPSM_EVENT_DELETE:
  720. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logosend);
  721. bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  722. bfa_fcs_rport_hal_offline_action(rport);
  723. break;
  724. case RPSM_EVENT_LOGO_IMP:
  725. case RPSM_EVENT_ADDRESS_CHANGE:
  726. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
  727. bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  728. bfa_fcs_rport_hal_offline_action(rport);
  729. break;
  730. case RPSM_EVENT_LOGO_RCVD:
  731. case RPSM_EVENT_PRLO_RCVD:
  732. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logorcv);
  733. bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  734. bfa_fcs_rport_hal_offline_action(rport);
  735. break;
  736. case RPSM_EVENT_FAB_SCN:
  737. break;
  738. case RPSM_EVENT_PLOGI_RCVD:
  739. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
  740. bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  741. bfa_fcs_rport_hal_offline_action(rport);
  742. break;
  743. default:
  744. bfa_sm_fault(rport->fcs, event);
  745. }
  746. }
  747. /*
  748. * An SCN event is received in ONLINE state. ADISC is to rport.
  749. * FC-4s are paused.
  750. */
  751. static void
  752. bfa_fcs_rport_sm_adisc_online(struct bfa_fcs_rport_s *rport,
  753. enum rport_event event)
  754. {
  755. bfa_trc(rport->fcs, rport->pwwn);
  756. bfa_trc(rport->fcs, rport->pid);
  757. bfa_trc(rport->fcs, event);
  758. switch (event) {
  759. case RPSM_EVENT_ACCEPTED:
  760. bfa_sm_set_state(rport, bfa_fcs_rport_sm_online);
  761. break;
  762. case RPSM_EVENT_PLOGI_RCVD:
  763. /*
  764. * Too complex to cleanup FC-4 & rport and then acc to PLOGI.
  765. * At least go offline when a PLOGI is received.
  766. */
  767. bfa_fcxp_discard(rport->fcxp);
  768. /*
  769. * !!! fall through !!!
  770. */
  771. case RPSM_EVENT_FAILED:
  772. case RPSM_EVENT_ADDRESS_CHANGE:
  773. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
  774. bfa_fcs_rport_hal_offline_action(rport);
  775. break;
  776. case RPSM_EVENT_DELETE:
  777. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logosend);
  778. bfa_fcxp_discard(rport->fcxp);
  779. bfa_fcs_rport_hal_offline_action(rport);
  780. break;
  781. case RPSM_EVENT_FAB_SCN:
  782. /*
  783. * already processing RSCN
  784. */
  785. break;
  786. case RPSM_EVENT_LOGO_IMP:
  787. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
  788. bfa_fcxp_discard(rport->fcxp);
  789. bfa_fcs_rport_hal_offline_action(rport);
  790. break;
  791. case RPSM_EVENT_LOGO_RCVD:
  792. case RPSM_EVENT_PRLO_RCVD:
  793. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logorcv);
  794. bfa_fcxp_discard(rport->fcxp);
  795. bfa_fcs_rport_hal_offline_action(rport);
  796. break;
  797. default:
  798. bfa_sm_fault(rport->fcs, event);
  799. }
  800. }
  801. /*
  802. * ADISC is being sent for authenticating with rport
  803. * Already did offline actions.
  804. */
  805. static void
  806. bfa_fcs_rport_sm_adisc_offline_sending(struct bfa_fcs_rport_s *rport,
  807. enum rport_event event)
  808. {
  809. bfa_trc(rport->fcs, rport->pwwn);
  810. bfa_trc(rport->fcs, rport->pid);
  811. bfa_trc(rport->fcs, event);
  812. switch (event) {
  813. case RPSM_EVENT_FCXP_SENT:
  814. bfa_sm_set_state(rport, bfa_fcs_rport_sm_adisc_offline);
  815. break;
  816. case RPSM_EVENT_DELETE:
  817. case RPSM_EVENT_SCN_OFFLINE:
  818. case RPSM_EVENT_LOGO_IMP:
  819. case RPSM_EVENT_LOGO_RCVD:
  820. case RPSM_EVENT_PRLO_RCVD:
  821. bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
  822. bfa_fcxp_walloc_cancel(rport->fcs->bfa,
  823. &rport->fcxp_wqe);
  824. bfa_timer_start(rport->fcs->bfa, &rport->timer,
  825. bfa_fcs_rport_timeout, rport,
  826. bfa_fcs_rport_del_timeout);
  827. break;
  828. case RPSM_EVENT_PLOGI_RCVD:
  829. bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogiacc_sending);
  830. bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  831. bfa_fcs_rport_send_plogiacc(rport, NULL);
  832. break;
  833. default:
  834. bfa_sm_fault(rport->fcs, event);
  835. }
  836. }
  837. /*
  838. * ADISC to rport
  839. * Already did offline actions
  840. */
  841. static void
  842. bfa_fcs_rport_sm_adisc_offline(struct bfa_fcs_rport_s *rport,
  843. enum rport_event event)
  844. {
  845. bfa_trc(rport->fcs, rport->pwwn);
  846. bfa_trc(rport->fcs, rport->pid);
  847. bfa_trc(rport->fcs, event);
  848. switch (event) {
  849. case RPSM_EVENT_ACCEPTED:
  850. bfa_sm_set_state(rport, bfa_fcs_rport_sm_hal_online);
  851. bfa_fcs_rport_hal_online(rport);
  852. break;
  853. case RPSM_EVENT_PLOGI_RCVD:
  854. bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogiacc_sending);
  855. bfa_fcxp_discard(rport->fcxp);
  856. bfa_fcs_rport_send_plogiacc(rport, NULL);
  857. break;
  858. case RPSM_EVENT_FAILED:
  859. bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
  860. bfa_timer_start(rport->fcs->bfa, &rport->timer,
  861. bfa_fcs_rport_timeout, rport,
  862. bfa_fcs_rport_del_timeout);
  863. break;
  864. case RPSM_EVENT_DELETE:
  865. case RPSM_EVENT_SCN_OFFLINE:
  866. case RPSM_EVENT_LOGO_IMP:
  867. case RPSM_EVENT_LOGO_RCVD:
  868. case RPSM_EVENT_PRLO_RCVD:
  869. bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
  870. bfa_fcxp_discard(rport->fcxp);
  871. bfa_timer_start(rport->fcs->bfa, &rport->timer,
  872. bfa_fcs_rport_timeout, rport,
  873. bfa_fcs_rport_del_timeout);
  874. break;
  875. default:
  876. bfa_sm_fault(rport->fcs, event);
  877. }
  878. }
  879. /*
  880. * Rport has sent LOGO. Awaiting FC-4 offline completion callback.
  881. */
  882. static void
  883. bfa_fcs_rport_sm_fc4_logorcv(struct bfa_fcs_rport_s *rport,
  884. enum rport_event event)
  885. {
  886. bfa_trc(rport->fcs, rport->pwwn);
  887. bfa_trc(rport->fcs, rport->pid);
  888. bfa_trc(rport->fcs, event);
  889. switch (event) {
  890. case RPSM_EVENT_FC4_OFFLINE:
  891. bfa_sm_set_state(rport, bfa_fcs_rport_sm_hcb_logorcv);
  892. bfa_fcs_rport_hal_offline(rport);
  893. break;
  894. case RPSM_EVENT_DELETE:
  895. if (rport->pid && (rport->prlo == BFA_TRUE))
  896. bfa_fcs_rport_send_prlo_acc(rport);
  897. if (rport->pid && (rport->prlo == BFA_FALSE))
  898. bfa_fcs_rport_send_logo_acc(rport);
  899. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_off_delete);
  900. break;
  901. case RPSM_EVENT_SCN_ONLINE:
  902. case RPSM_EVENT_SCN_OFFLINE:
  903. case RPSM_EVENT_HCB_ONLINE:
  904. case RPSM_EVENT_LOGO_RCVD:
  905. case RPSM_EVENT_PRLO_RCVD:
  906. case RPSM_EVENT_ADDRESS_CHANGE:
  907. break;
  908. default:
  909. bfa_sm_fault(rport->fcs, event);
  910. }
  911. }
  912. /*
  913. * LOGO needs to be sent to rport. Awaiting FC-4 offline completion
  914. * callback.
  915. */
  916. static void
  917. bfa_fcs_rport_sm_fc4_logosend(struct bfa_fcs_rport_s *rport,
  918. enum rport_event event)
  919. {
  920. bfa_trc(rport->fcs, rport->pwwn);
  921. bfa_trc(rport->fcs, rport->pid);
  922. bfa_trc(rport->fcs, event);
  923. switch (event) {
  924. case RPSM_EVENT_FC4_OFFLINE:
  925. bfa_sm_set_state(rport, bfa_fcs_rport_sm_hcb_logosend);
  926. bfa_fcs_rport_hal_offline(rport);
  927. break;
  928. case RPSM_EVENT_LOGO_RCVD:
  929. bfa_fcs_rport_send_logo_acc(rport);
  930. case RPSM_EVENT_PRLO_RCVD:
  931. if (rport->prlo == BFA_TRUE)
  932. bfa_fcs_rport_send_prlo_acc(rport);
  933. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_off_delete);
  934. break;
  935. case RPSM_EVENT_HCB_ONLINE:
  936. case RPSM_EVENT_DELETE:
  937. /* Rport is being deleted */
  938. break;
  939. default:
  940. bfa_sm_fault(rport->fcs, event);
  941. }
  942. }
  943. /*
  944. * Rport is going offline. Awaiting FC-4 offline completion callback.
  945. */
  946. static void
  947. bfa_fcs_rport_sm_fc4_offline(struct bfa_fcs_rport_s *rport,
  948. enum rport_event event)
  949. {
  950. bfa_trc(rport->fcs, rport->pwwn);
  951. bfa_trc(rport->fcs, rport->pid);
  952. bfa_trc(rport->fcs, event);
  953. switch (event) {
  954. case RPSM_EVENT_FC4_OFFLINE:
  955. bfa_sm_set_state(rport, bfa_fcs_rport_sm_hcb_offline);
  956. bfa_fcs_rport_hal_offline(rport);
  957. break;
  958. case RPSM_EVENT_SCN_ONLINE:
  959. break;
  960. case RPSM_EVENT_LOGO_RCVD:
  961. /*
  962. * Rport is going offline. Just ack the logo
  963. */
  964. bfa_fcs_rport_send_logo_acc(rport);
  965. break;
  966. case RPSM_EVENT_PRLO_RCVD:
  967. bfa_fcs_rport_send_prlo_acc(rport);
  968. break;
  969. case RPSM_EVENT_SCN_OFFLINE:
  970. case RPSM_EVENT_HCB_ONLINE:
  971. case RPSM_EVENT_FAB_SCN:
  972. case RPSM_EVENT_LOGO_IMP:
  973. case RPSM_EVENT_ADDRESS_CHANGE:
  974. /*
  975. * rport is already going offline.
  976. * SCN - ignore and wait till transitioning to offline state
  977. */
  978. break;
  979. case RPSM_EVENT_DELETE:
  980. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logosend);
  981. break;
  982. default:
  983. bfa_sm_fault(rport->fcs, event);
  984. }
  985. }
  986. /*
  987. * Rport is offline. FC-4s are offline. Awaiting BFA rport offline
  988. * callback.
  989. */
  990. static void
  991. bfa_fcs_rport_sm_hcb_offline(struct bfa_fcs_rport_s *rport,
  992. enum rport_event event)
  993. {
  994. bfa_trc(rport->fcs, rport->pwwn);
  995. bfa_trc(rport->fcs, rport->pid);
  996. bfa_trc(rport->fcs, event);
  997. switch (event) {
  998. case RPSM_EVENT_HCB_OFFLINE:
  999. if (bfa_fcs_lport_is_online(rport->port) &&
  1000. (rport->plogi_pending)) {
  1001. rport->plogi_pending = BFA_FALSE;
  1002. bfa_sm_set_state(rport,
  1003. bfa_fcs_rport_sm_plogiacc_sending);
  1004. bfa_fcs_rport_send_plogiacc(rport, NULL);
  1005. break;
  1006. }
  1007. /*
  1008. * !! fall through !!
  1009. */
  1010. case RPSM_EVENT_ADDRESS_CHANGE:
  1011. if (!bfa_fcs_lport_is_online(rport->port)) {
  1012. rport->pid = 0;
  1013. bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
  1014. bfa_timer_start(rport->fcs->bfa, &rport->timer,
  1015. bfa_fcs_rport_timeout, rport,
  1016. bfa_fcs_rport_del_timeout);
  1017. break;
  1018. }
  1019. if (bfa_fcs_fabric_is_switched(rport->port->fabric)) {
  1020. bfa_sm_set_state(rport,
  1021. bfa_fcs_rport_sm_nsdisc_sending);
  1022. rport->ns_retries = 0;
  1023. bfa_fcs_rport_send_nsdisc(rport, NULL);
  1024. } else if (bfa_fcport_get_topology(rport->port->fcs->bfa) ==
  1025. BFA_PORT_TOPOLOGY_LOOP) {
  1026. if (rport->scn_online) {
  1027. bfa_sm_set_state(rport,
  1028. bfa_fcs_rport_sm_adisc_offline_sending);
  1029. bfa_fcs_rport_send_adisc(rport, NULL);
  1030. } else {
  1031. bfa_sm_set_state(rport,
  1032. bfa_fcs_rport_sm_offline);
  1033. bfa_timer_start(rport->fcs->bfa, &rport->timer,
  1034. bfa_fcs_rport_timeout, rport,
  1035. bfa_fcs_rport_del_timeout);
  1036. }
  1037. } else {
  1038. bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogi_sending);
  1039. rport->plogi_retries = 0;
  1040. bfa_fcs_rport_send_plogi(rport, NULL);
  1041. }
  1042. break;
  1043. case RPSM_EVENT_DELETE:
  1044. bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
  1045. bfa_fcs_rport_free(rport);
  1046. break;
  1047. case RPSM_EVENT_SCN_ONLINE:
  1048. case RPSM_EVENT_SCN_OFFLINE:
  1049. case RPSM_EVENT_FAB_SCN:
  1050. case RPSM_EVENT_LOGO_RCVD:
  1051. case RPSM_EVENT_PRLO_RCVD:
  1052. case RPSM_EVENT_PLOGI_RCVD:
  1053. case RPSM_EVENT_LOGO_IMP:
  1054. /*
  1055. * Ignore, already offline.
  1056. */
  1057. break;
  1058. default:
  1059. bfa_sm_fault(rport->fcs, event);
  1060. }
  1061. }
  1062. /*
  1063. * Rport is offline. FC-4s are offline. Awaiting BFA rport offline
  1064. * callback to send LOGO accept.
  1065. */
  1066. static void
  1067. bfa_fcs_rport_sm_hcb_logorcv(struct bfa_fcs_rport_s *rport,
  1068. enum rport_event event)
  1069. {
  1070. bfa_trc(rport->fcs, rport->pwwn);
  1071. bfa_trc(rport->fcs, rport->pid);
  1072. bfa_trc(rport->fcs, event);
  1073. switch (event) {
  1074. case RPSM_EVENT_HCB_OFFLINE:
  1075. case RPSM_EVENT_ADDRESS_CHANGE:
  1076. if (rport->pid && (rport->prlo == BFA_TRUE))
  1077. bfa_fcs_rport_send_prlo_acc(rport);
  1078. if (rport->pid && (rport->prlo == BFA_FALSE))
  1079. bfa_fcs_rport_send_logo_acc(rport);
  1080. /*
  1081. * If the lport is online and if the rport is not a well
  1082. * known address port,
  1083. * we try to re-discover the r-port.
  1084. */
  1085. if (bfa_fcs_lport_is_online(rport->port) &&
  1086. (!BFA_FCS_PID_IS_WKA(rport->pid))) {
  1087. if (bfa_fcs_fabric_is_switched(rport->port->fabric)) {
  1088. bfa_sm_set_state(rport,
  1089. bfa_fcs_rport_sm_nsdisc_sending);
  1090. rport->ns_retries = 0;
  1091. bfa_fcs_rport_send_nsdisc(rport, NULL);
  1092. } else {
  1093. /* For N2N Direct Attach, try to re-login */
  1094. bfa_sm_set_state(rport,
  1095. bfa_fcs_rport_sm_plogi_sending);
  1096. rport->plogi_retries = 0;
  1097. bfa_fcs_rport_send_plogi(rport, NULL);
  1098. }
  1099. } else {
  1100. /*
  1101. * if it is not a well known address, reset the
  1102. * pid to 0.
  1103. */
  1104. if (!BFA_FCS_PID_IS_WKA(rport->pid))
  1105. rport->pid = 0;
  1106. bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
  1107. bfa_timer_start(rport->fcs->bfa, &rport->timer,
  1108. bfa_fcs_rport_timeout, rport,
  1109. bfa_fcs_rport_del_timeout);
  1110. }
  1111. break;
  1112. case RPSM_EVENT_DELETE:
  1113. bfa_sm_set_state(rport, bfa_fcs_rport_sm_delete_pending);
  1114. if (rport->pid && (rport->prlo == BFA_TRUE))
  1115. bfa_fcs_rport_send_prlo_acc(rport);
  1116. if (rport->pid && (rport->prlo == BFA_FALSE))
  1117. bfa_fcs_rport_send_logo_acc(rport);
  1118. break;
  1119. case RPSM_EVENT_LOGO_IMP:
  1120. bfa_sm_set_state(rport, bfa_fcs_rport_sm_hcb_offline);
  1121. break;
  1122. case RPSM_EVENT_SCN_ONLINE:
  1123. case RPSM_EVENT_SCN_OFFLINE:
  1124. case RPSM_EVENT_LOGO_RCVD:
  1125. case RPSM_EVENT_PRLO_RCVD:
  1126. /*
  1127. * Ignore - already processing a LOGO.
  1128. */
  1129. break;
  1130. default:
  1131. bfa_sm_fault(rport->fcs, event);
  1132. }
  1133. }
  1134. /*
  1135. * Rport is being deleted. FC-4s are offline.
  1136. * Awaiting BFA rport offline
  1137. * callback to send LOGO.
  1138. */
  1139. static void
  1140. bfa_fcs_rport_sm_hcb_logosend(struct bfa_fcs_rport_s *rport,
  1141. enum rport_event event)
  1142. {
  1143. bfa_trc(rport->fcs, rport->pwwn);
  1144. bfa_trc(rport->fcs, rport->pid);
  1145. bfa_trc(rport->fcs, event);
  1146. switch (event) {
  1147. case RPSM_EVENT_HCB_OFFLINE:
  1148. bfa_sm_set_state(rport, bfa_fcs_rport_sm_logo_sending);
  1149. bfa_fcs_rport_send_logo(rport, NULL);
  1150. break;
  1151. case RPSM_EVENT_LOGO_RCVD:
  1152. bfa_fcs_rport_send_logo_acc(rport);
  1153. case RPSM_EVENT_PRLO_RCVD:
  1154. if (rport->prlo == BFA_TRUE)
  1155. bfa_fcs_rport_send_prlo_acc(rport);
  1156. bfa_sm_set_state(rport, bfa_fcs_rport_sm_delete_pending);
  1157. break;
  1158. case RPSM_EVENT_SCN_ONLINE:
  1159. case RPSM_EVENT_SCN_OFFLINE:
  1160. case RPSM_EVENT_ADDRESS_CHANGE:
  1161. break;
  1162. default:
  1163. bfa_sm_fault(rport->fcs, event);
  1164. }
  1165. }
  1166. /*
  1167. * Rport is being deleted. FC-4s are offline. LOGO is being sent.
  1168. */
  1169. static void
  1170. bfa_fcs_rport_sm_logo_sending(struct bfa_fcs_rport_s *rport,
  1171. enum rport_event event)
  1172. {
  1173. bfa_trc(rport->fcs, rport->pwwn);
  1174. bfa_trc(rport->fcs, rport->pid);
  1175. bfa_trc(rport->fcs, event);
  1176. switch (event) {
  1177. case RPSM_EVENT_FCXP_SENT:
  1178. /* Once LOGO is sent, we donot wait for the response */
  1179. bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
  1180. bfa_fcs_rport_free(rport);
  1181. break;
  1182. case RPSM_EVENT_SCN_ONLINE:
  1183. case RPSM_EVENT_SCN_OFFLINE:
  1184. case RPSM_EVENT_FAB_SCN:
  1185. case RPSM_EVENT_ADDRESS_CHANGE:
  1186. break;
  1187. case RPSM_EVENT_LOGO_RCVD:
  1188. bfa_fcs_rport_send_logo_acc(rport);
  1189. case RPSM_EVENT_PRLO_RCVD:
  1190. if (rport->prlo == BFA_TRUE)
  1191. bfa_fcs_rport_send_prlo_acc(rport);
  1192. bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
  1193. bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  1194. bfa_fcs_rport_free(rport);
  1195. break;
  1196. default:
  1197. bfa_sm_fault(rport->fcs, event);
  1198. }
  1199. }
  1200. /*
  1201. * Rport is offline. FC-4s are offline. BFA rport is offline.
  1202. * Timer active to delete stale rport.
  1203. */
  1204. static void
  1205. bfa_fcs_rport_sm_offline(struct bfa_fcs_rport_s *rport, enum rport_event event)
  1206. {
  1207. bfa_trc(rport->fcs, rport->pwwn);
  1208. bfa_trc(rport->fcs, rport->pid);
  1209. bfa_trc(rport->fcs, event);
  1210. switch (event) {
  1211. case RPSM_EVENT_TIMEOUT:
  1212. bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
  1213. bfa_fcs_rport_free(rport);
  1214. break;
  1215. case RPSM_EVENT_FAB_SCN:
  1216. case RPSM_EVENT_ADDRESS_CHANGE:
  1217. bfa_timer_stop(&rport->timer);
  1218. WARN_ON(!(bfa_fcport_get_topology(rport->port->fcs->bfa) !=
  1219. BFA_PORT_TOPOLOGY_LOOP));
  1220. bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sending);
  1221. rport->ns_retries = 0;
  1222. bfa_fcs_rport_send_nsdisc(rport, NULL);
  1223. break;
  1224. case RPSM_EVENT_DELETE:
  1225. bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
  1226. bfa_timer_stop(&rport->timer);
  1227. bfa_fcs_rport_free(rport);
  1228. break;
  1229. case RPSM_EVENT_PLOGI_RCVD:
  1230. bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogiacc_sending);
  1231. bfa_timer_stop(&rport->timer);
  1232. bfa_fcs_rport_send_plogiacc(rport, NULL);
  1233. break;
  1234. case RPSM_EVENT_LOGO_RCVD:
  1235. case RPSM_EVENT_PRLO_RCVD:
  1236. case RPSM_EVENT_LOGO_IMP:
  1237. case RPSM_EVENT_SCN_OFFLINE:
  1238. break;
  1239. case RPSM_EVENT_PLOGI_COMP:
  1240. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_fcs_online);
  1241. bfa_timer_stop(&rport->timer);
  1242. bfa_fcs_rport_fcs_online_action(rport);
  1243. break;
  1244. case RPSM_EVENT_SCN_ONLINE:
  1245. bfa_timer_stop(&rport->timer);
  1246. bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogi_sending);
  1247. bfa_fcs_rport_send_plogi(rport, NULL);
  1248. break;
  1249. case RPSM_EVENT_PLOGI_SEND:
  1250. bfa_timer_stop(&rport->timer);
  1251. bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogi_sending);
  1252. rport->plogi_retries = 0;
  1253. bfa_fcs_rport_send_plogi(rport, NULL);
  1254. break;
  1255. default:
  1256. bfa_sm_fault(rport->fcs, event);
  1257. }
  1258. }
  1259. /*
  1260. * Rport address has changed. Nameserver discovery request is being sent.
  1261. */
  1262. static void
  1263. bfa_fcs_rport_sm_nsdisc_sending(struct bfa_fcs_rport_s *rport,
  1264. enum rport_event event)
  1265. {
  1266. bfa_trc(rport->fcs, rport->pwwn);
  1267. bfa_trc(rport->fcs, rport->pid);
  1268. bfa_trc(rport->fcs, event);
  1269. switch (event) {
  1270. case RPSM_EVENT_FCXP_SENT:
  1271. bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sent);
  1272. break;
  1273. case RPSM_EVENT_DELETE:
  1274. bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
  1275. bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  1276. bfa_fcs_rport_free(rport);
  1277. break;
  1278. case RPSM_EVENT_PLOGI_RCVD:
  1279. bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogiacc_sending);
  1280. bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  1281. bfa_fcs_rport_send_plogiacc(rport, NULL);
  1282. break;
  1283. case RPSM_EVENT_FAB_SCN:
  1284. case RPSM_EVENT_LOGO_RCVD:
  1285. case RPSM_EVENT_PRLO_RCVD:
  1286. case RPSM_EVENT_PLOGI_SEND:
  1287. break;
  1288. case RPSM_EVENT_ADDRESS_CHANGE:
  1289. rport->ns_retries = 0; /* reset the retry count */
  1290. break;
  1291. case RPSM_EVENT_LOGO_IMP:
  1292. bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
  1293. bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  1294. bfa_timer_start(rport->fcs->bfa, &rport->timer,
  1295. bfa_fcs_rport_timeout, rport,
  1296. bfa_fcs_rport_del_timeout);
  1297. break;
  1298. case RPSM_EVENT_PLOGI_COMP:
  1299. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_fcs_online);
  1300. bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  1301. bfa_fcs_rport_fcs_online_action(rport);
  1302. break;
  1303. default:
  1304. bfa_sm_fault(rport->fcs, event);
  1305. }
  1306. }
  1307. /*
  1308. * Nameserver discovery failed. Waiting for timeout to retry.
  1309. */
  1310. static void
  1311. bfa_fcs_rport_sm_nsdisc_retry(struct bfa_fcs_rport_s *rport,
  1312. enum rport_event event)
  1313. {
  1314. bfa_trc(rport->fcs, rport->pwwn);
  1315. bfa_trc(rport->fcs, rport->pid);
  1316. bfa_trc(rport->fcs, event);
  1317. switch (event) {
  1318. case RPSM_EVENT_TIMEOUT:
  1319. bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sending);
  1320. bfa_fcs_rport_send_nsdisc(rport, NULL);
  1321. break;
  1322. case RPSM_EVENT_FAB_SCN:
  1323. case RPSM_EVENT_ADDRESS_CHANGE:
  1324. bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sending);
  1325. bfa_timer_stop(&rport->timer);
  1326. rport->ns_retries = 0;
  1327. bfa_fcs_rport_send_nsdisc(rport, NULL);
  1328. break;
  1329. case RPSM_EVENT_DELETE:
  1330. bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
  1331. bfa_timer_stop(&rport->timer);
  1332. bfa_fcs_rport_free(rport);
  1333. break;
  1334. case RPSM_EVENT_PLOGI_RCVD:
  1335. bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogiacc_sending);
  1336. bfa_timer_stop(&rport->timer);
  1337. bfa_fcs_rport_send_plogiacc(rport, NULL);
  1338. break;
  1339. case RPSM_EVENT_LOGO_IMP:
  1340. rport->pid = 0;
  1341. bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
  1342. bfa_timer_stop(&rport->timer);
  1343. bfa_timer_start(rport->fcs->bfa, &rport->timer,
  1344. bfa_fcs_rport_timeout, rport,
  1345. bfa_fcs_rport_del_timeout);
  1346. break;
  1347. case RPSM_EVENT_LOGO_RCVD:
  1348. bfa_fcs_rport_send_logo_acc(rport);
  1349. break;
  1350. case RPSM_EVENT_PRLO_RCVD:
  1351. bfa_fcs_rport_send_prlo_acc(rport);
  1352. break;
  1353. case RPSM_EVENT_PLOGI_COMP:
  1354. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_fcs_online);
  1355. bfa_timer_stop(&rport->timer);
  1356. bfa_fcs_rport_fcs_online_action(rport);
  1357. break;
  1358. default:
  1359. bfa_sm_fault(rport->fcs, event);
  1360. }
  1361. }
  1362. /*
  1363. * Rport address has changed. Nameserver discovery request is sent.
  1364. */
  1365. static void
  1366. bfa_fcs_rport_sm_nsdisc_sent(struct bfa_fcs_rport_s *rport,
  1367. enum rport_event event)
  1368. {
  1369. bfa_trc(rport->fcs, rport->pwwn);
  1370. bfa_trc(rport->fcs, rport->pid);
  1371. bfa_trc(rport->fcs, event);
  1372. switch (event) {
  1373. case RPSM_EVENT_ACCEPTED:
  1374. case RPSM_EVENT_ADDRESS_CHANGE:
  1375. if (rport->pid) {
  1376. bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogi_sending);
  1377. bfa_fcs_rport_send_plogi(rport, NULL);
  1378. } else {
  1379. bfa_sm_set_state(rport,
  1380. bfa_fcs_rport_sm_nsdisc_sending);
  1381. rport->ns_retries = 0;
  1382. bfa_fcs_rport_send_nsdisc(rport, NULL);
  1383. }
  1384. break;
  1385. case RPSM_EVENT_FAILED:
  1386. rport->ns_retries++;
  1387. if (rport->ns_retries < BFA_FCS_RPORT_MAX_RETRIES) {
  1388. bfa_sm_set_state(rport,
  1389. bfa_fcs_rport_sm_nsdisc_sending);
  1390. bfa_fcs_rport_send_nsdisc(rport, NULL);
  1391. } else {
  1392. rport->old_pid = rport->pid;
  1393. rport->pid = 0;
  1394. bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
  1395. bfa_timer_start(rport->fcs->bfa, &rport->timer,
  1396. bfa_fcs_rport_timeout, rport,
  1397. bfa_fcs_rport_del_timeout);
  1398. };
  1399. break;
  1400. case RPSM_EVENT_DELETE:
  1401. bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
  1402. bfa_fcxp_discard(rport->fcxp);
  1403. bfa_fcs_rport_free(rport);
  1404. break;
  1405. case RPSM_EVENT_PLOGI_RCVD:
  1406. bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogiacc_sending);
  1407. bfa_fcxp_discard(rport->fcxp);
  1408. bfa_fcs_rport_send_plogiacc(rport, NULL);
  1409. break;
  1410. case RPSM_EVENT_LOGO_IMP:
  1411. rport->pid = 0;
  1412. bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
  1413. bfa_fcxp_discard(rport->fcxp);
  1414. bfa_timer_start(rport->fcs->bfa, &rport->timer,
  1415. bfa_fcs_rport_timeout, rport,
  1416. bfa_fcs_rport_del_timeout);
  1417. break;
  1418. case RPSM_EVENT_PRLO_RCVD:
  1419. bfa_fcs_rport_send_prlo_acc(rport);
  1420. break;
  1421. case RPSM_EVENT_FAB_SCN:
  1422. /*
  1423. * ignore, wait for NS query response
  1424. */
  1425. break;
  1426. case RPSM_EVENT_LOGO_RCVD:
  1427. /*
  1428. * Not logged-in yet. Accept LOGO.
  1429. */
  1430. bfa_fcs_rport_send_logo_acc(rport);
  1431. break;
  1432. case RPSM_EVENT_PLOGI_COMP:
  1433. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_fcs_online);
  1434. bfa_fcxp_discard(rport->fcxp);
  1435. bfa_fcs_rport_fcs_online_action(rport);
  1436. break;
  1437. default:
  1438. bfa_sm_fault(rport->fcs, event);
  1439. }
  1440. }
  1441. /*
  1442. * Rport needs to be deleted
  1443. * waiting for ITNIM clean up to finish
  1444. */
  1445. static void
  1446. bfa_fcs_rport_sm_fc4_off_delete(struct bfa_fcs_rport_s *rport,
  1447. enum rport_event event)
  1448. {
  1449. bfa_trc(rport->fcs, rport->pwwn);
  1450. bfa_trc(rport->fcs, rport->pid);
  1451. bfa_trc(rport->fcs, event);
  1452. switch (event) {
  1453. case RPSM_EVENT_FC4_OFFLINE:
  1454. bfa_sm_set_state(rport, bfa_fcs_rport_sm_delete_pending);
  1455. bfa_fcs_rport_hal_offline(rport);
  1456. break;
  1457. case RPSM_EVENT_DELETE:
  1458. case RPSM_EVENT_PLOGI_RCVD:
  1459. /* Ignore these events */
  1460. break;
  1461. default:
  1462. bfa_sm_fault(rport->fcs, event);
  1463. break;
  1464. }
  1465. }
  1466. /*
  1467. * RPort needs to be deleted
  1468. * waiting for BFA/FW to finish current processing
  1469. */
  1470. static void
  1471. bfa_fcs_rport_sm_delete_pending(struct bfa_fcs_rport_s *rport,
  1472. enum rport_event event)
  1473. {
  1474. bfa_trc(rport->fcs, rport->pwwn);
  1475. bfa_trc(rport->fcs, rport->pid);
  1476. bfa_trc(rport->fcs, event);
  1477. switch (event) {
  1478. case RPSM_EVENT_HCB_OFFLINE:
  1479. bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
  1480. bfa_fcs_rport_free(rport);
  1481. break;
  1482. case RPSM_EVENT_DELETE:
  1483. case RPSM_EVENT_LOGO_IMP:
  1484. case RPSM_EVENT_PLOGI_RCVD:
  1485. /* Ignore these events */
  1486. break;
  1487. default:
  1488. bfa_sm_fault(rport->fcs, event);
  1489. }
  1490. }
  1491. /*
  1492. * fcs_rport_private FCS RPORT provate functions
  1493. */
  1494. static void
  1495. bfa_fcs_rport_send_plogi(void *rport_cbarg, struct bfa_fcxp_s *fcxp_alloced)
  1496. {
  1497. struct bfa_fcs_rport_s *rport = rport_cbarg;
  1498. struct bfa_fcs_lport_s *port = rport->port;
  1499. struct fchs_s fchs;
  1500. int len;
  1501. struct bfa_fcxp_s *fcxp;
  1502. bfa_trc(rport->fcs, rport->pwwn);
  1503. fcxp = fcxp_alloced ? fcxp_alloced :
  1504. bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
  1505. if (!fcxp) {
  1506. bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &rport->fcxp_wqe,
  1507. bfa_fcs_rport_send_plogi, rport, BFA_TRUE);
  1508. return;
  1509. }
  1510. rport->fcxp = fcxp;
  1511. len = fc_plogi_build(&fchs, bfa_fcxp_get_reqbuf(fcxp), rport->pid,
  1512. bfa_fcs_lport_get_fcid(port), 0,
  1513. port->port_cfg.pwwn, port->port_cfg.nwwn,
  1514. bfa_fcport_get_maxfrsize(port->fcs->bfa),
  1515. bfa_fcport_get_rx_bbcredit(port->fcs->bfa));
  1516. bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
  1517. FC_CLASS_3, len, &fchs, bfa_fcs_rport_plogi_response,
  1518. (void *)rport, FC_MAX_PDUSZ, FC_ELS_TOV);
  1519. rport->stats.plogis++;
  1520. bfa_sm_send_event(rport, RPSM_EVENT_FCXP_SENT);
  1521. }
  1522. static void
  1523. bfa_fcs_rport_plogi_response(void *fcsarg, struct bfa_fcxp_s *fcxp, void *cbarg,
  1524. bfa_status_t req_status, u32 rsp_len,
  1525. u32 resid_len, struct fchs_s *rsp_fchs)
  1526. {
  1527. struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *) cbarg;
  1528. struct fc_logi_s *plogi_rsp;
  1529. struct fc_ls_rjt_s *ls_rjt;
  1530. struct bfa_fcs_rport_s *twin;
  1531. struct list_head *qe;
  1532. bfa_trc(rport->fcs, rport->pwwn);
  1533. /*
  1534. * Sanity Checks
  1535. */
  1536. if (req_status != BFA_STATUS_OK) {
  1537. bfa_trc(rport->fcs, req_status);
  1538. rport->stats.plogi_failed++;
  1539. bfa_sm_send_event(rport, RPSM_EVENT_FAILED);
  1540. return;
  1541. }
  1542. plogi_rsp = (struct fc_logi_s *) BFA_FCXP_RSP_PLD(fcxp);
  1543. /*
  1544. * Check for failure first.
  1545. */
  1546. if (plogi_rsp->els_cmd.els_code != FC_ELS_ACC) {
  1547. ls_rjt = (struct fc_ls_rjt_s *) BFA_FCXP_RSP_PLD(fcxp);
  1548. bfa_trc(rport->fcs, ls_rjt->reason_code);
  1549. bfa_trc(rport->fcs, ls_rjt->reason_code_expl);
  1550. if ((ls_rjt->reason_code == FC_LS_RJT_RSN_UNABLE_TO_PERF_CMD) &&
  1551. (ls_rjt->reason_code_expl == FC_LS_RJT_EXP_INSUFF_RES)) {
  1552. rport->stats.rjt_insuff_res++;
  1553. bfa_sm_send_event(rport, RPSM_EVENT_PLOGI_RETRY);
  1554. return;
  1555. }
  1556. rport->stats.plogi_rejects++;
  1557. bfa_sm_send_event(rport, RPSM_EVENT_FAILED);
  1558. return;
  1559. }
  1560. /*
  1561. * PLOGI is complete. Make sure this device is not one of the known
  1562. * device with a new FC port address.
  1563. */
  1564. list_for_each(qe, &rport->port->rport_q) {
  1565. twin = (struct bfa_fcs_rport_s *) qe;
  1566. if (twin == rport)
  1567. continue;
  1568. if (!rport->pwwn && (plogi_rsp->port_name == twin->pwwn)) {
  1569. bfa_trc(rport->fcs, twin->pid);
  1570. bfa_trc(rport->fcs, rport->pid);
  1571. /* Update plogi stats in twin */
  1572. twin->stats.plogis += rport->stats.plogis;
  1573. twin->stats.plogi_rejects +=
  1574. rport->stats.plogi_rejects;
  1575. twin->stats.plogi_timeouts +=
  1576. rport->stats.plogi_timeouts;
  1577. twin->stats.plogi_failed +=
  1578. rport->stats.plogi_failed;
  1579. twin->stats.plogi_rcvd += rport->stats.plogi_rcvd;
  1580. twin->stats.plogi_accs++;
  1581. bfa_sm_send_event(rport, RPSM_EVENT_DELETE);
  1582. bfa_fcs_rport_update(twin, plogi_rsp);
  1583. twin->pid = rsp_fchs->s_id;
  1584. bfa_sm_send_event(twin, RPSM_EVENT_PLOGI_COMP);
  1585. return;
  1586. }
  1587. }
  1588. /*
  1589. * Normal login path -- no evil twins.
  1590. */
  1591. rport->stats.plogi_accs++;
  1592. bfa_fcs_rport_update(rport, plogi_rsp);
  1593. bfa_sm_send_event(rport, RPSM_EVENT_ACCEPTED);
  1594. }
  1595. static void
  1596. bfa_fcs_rport_send_plogiacc(void *rport_cbarg, struct bfa_fcxp_s *fcxp_alloced)
  1597. {
  1598. struct bfa_fcs_rport_s *rport = rport_cbarg;
  1599. struct bfa_fcs_lport_s *port = rport->port;
  1600. struct fchs_s fchs;
  1601. int len;
  1602. struct bfa_fcxp_s *fcxp;
  1603. bfa_trc(rport->fcs, rport->pwwn);
  1604. bfa_trc(rport->fcs, rport->reply_oxid);
  1605. fcxp = fcxp_alloced ? fcxp_alloced :
  1606. bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
  1607. if (!fcxp) {
  1608. bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &rport->fcxp_wqe,
  1609. bfa_fcs_rport_send_plogiacc, rport, BFA_FALSE);
  1610. return;
  1611. }
  1612. rport->fcxp = fcxp;
  1613. len = fc_plogi_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
  1614. rport->pid, bfa_fcs_lport_get_fcid(port),
  1615. rport->reply_oxid, port->port_cfg.pwwn,
  1616. port->port_cfg.nwwn,
  1617. bfa_fcport_get_maxfrsize(port->fcs->bfa),
  1618. bfa_fcport_get_rx_bbcredit(port->fcs->bfa));
  1619. bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
  1620. FC_CLASS_3, len, &fchs, NULL, NULL, FC_MAX_PDUSZ, 0);
  1621. bfa_sm_send_event(rport, RPSM_EVENT_FCXP_SENT);
  1622. }
  1623. static void
  1624. bfa_fcs_rport_send_adisc(void *rport_cbarg, struct bfa_fcxp_s *fcxp_alloced)
  1625. {
  1626. struct bfa_fcs_rport_s *rport = rport_cbarg;
  1627. struct bfa_fcs_lport_s *port = rport->port;
  1628. struct fchs_s fchs;
  1629. int len;
  1630. struct bfa_fcxp_s *fcxp;
  1631. bfa_trc(rport->fcs, rport->pwwn);
  1632. fcxp = fcxp_alloced ? fcxp_alloced :
  1633. bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
  1634. if (!fcxp) {
  1635. bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &rport->fcxp_wqe,
  1636. bfa_fcs_rport_send_adisc, rport, BFA_TRUE);
  1637. return;
  1638. }
  1639. rport->fcxp = fcxp;
  1640. len = fc_adisc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp), rport->pid,
  1641. bfa_fcs_lport_get_fcid(port), 0,
  1642. port->port_cfg.pwwn, port->port_cfg.nwwn);
  1643. bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
  1644. FC_CLASS_3, len, &fchs, bfa_fcs_rport_adisc_response,
  1645. rport, FC_MAX_PDUSZ, FC_ELS_TOV);
  1646. rport->stats.adisc_sent++;
  1647. bfa_sm_send_event(rport, RPSM_EVENT_FCXP_SENT);
  1648. }
  1649. static void
  1650. bfa_fcs_rport_adisc_response(void *fcsarg, struct bfa_fcxp_s *fcxp, void *cbarg,
  1651. bfa_status_t req_status, u32 rsp_len,
  1652. u32 resid_len, struct fchs_s *rsp_fchs)
  1653. {
  1654. struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *) cbarg;
  1655. void *pld = bfa_fcxp_get_rspbuf(fcxp);
  1656. struct fc_ls_rjt_s *ls_rjt;
  1657. if (req_status != BFA_STATUS_OK) {
  1658. bfa_trc(rport->fcs, req_status);
  1659. rport->stats.adisc_failed++;
  1660. bfa_sm_send_event(rport, RPSM_EVENT_FAILED);
  1661. return;
  1662. }
  1663. if (fc_adisc_rsp_parse((struct fc_adisc_s *)pld, rsp_len, rport->pwwn,
  1664. rport->nwwn) == FC_PARSE_OK) {
  1665. rport->stats.adisc_accs++;
  1666. bfa_sm_send_event(rport, RPSM_EVENT_ACCEPTED);
  1667. return;
  1668. }
  1669. rport->stats.adisc_rejects++;
  1670. ls_rjt = pld;
  1671. bfa_trc(rport->fcs, ls_rjt->els_cmd.els_code);
  1672. bfa_trc(rport->fcs, ls_rjt->reason_code);
  1673. bfa_trc(rport->fcs, ls_rjt->reason_code_expl);
  1674. bfa_sm_send_event(rport, RPSM_EVENT_FAILED);
  1675. }
  1676. static void
  1677. bfa_fcs_rport_send_nsdisc(void *rport_cbarg, struct bfa_fcxp_s *fcxp_alloced)
  1678. {
  1679. struct bfa_fcs_rport_s *rport = rport_cbarg;
  1680. struct bfa_fcs_lport_s *port = rport->port;
  1681. struct fchs_s fchs;
  1682. struct bfa_fcxp_s *fcxp;
  1683. int len;
  1684. bfa_cb_fcxp_send_t cbfn;
  1685. bfa_trc(rport->fcs, rport->pid);
  1686. fcxp = fcxp_alloced ? fcxp_alloced :
  1687. bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
  1688. if (!fcxp) {
  1689. bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &rport->fcxp_wqe,
  1690. bfa_fcs_rport_send_nsdisc, rport, BFA_TRUE);
  1691. return;
  1692. }
  1693. rport->fcxp = fcxp;
  1694. if (rport->pwwn) {
  1695. len = fc_gidpn_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
  1696. bfa_fcs_lport_get_fcid(port), 0, rport->pwwn);
  1697. cbfn = bfa_fcs_rport_gidpn_response;
  1698. } else {
  1699. len = fc_gpnid_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
  1700. bfa_fcs_lport_get_fcid(port), 0, rport->pid);
  1701. cbfn = bfa_fcs_rport_gpnid_response;
  1702. }
  1703. bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
  1704. FC_CLASS_3, len, &fchs, cbfn,
  1705. (void *)rport, FC_MAX_PDUSZ, FC_FCCT_TOV);
  1706. bfa_sm_send_event(rport, RPSM_EVENT_FCXP_SENT);
  1707. }
  1708. static void
  1709. bfa_fcs_rport_gidpn_response(void *fcsarg, struct bfa_fcxp_s *fcxp, void *cbarg,
  1710. bfa_status_t req_status, u32 rsp_len,
  1711. u32 resid_len, struct fchs_s *rsp_fchs)
  1712. {
  1713. struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *) cbarg;
  1714. struct ct_hdr_s *cthdr;
  1715. struct fcgs_gidpn_resp_s *gidpn_rsp;
  1716. struct bfa_fcs_rport_s *twin;
  1717. struct list_head *qe;
  1718. bfa_trc(rport->fcs, rport->pwwn);
  1719. cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
  1720. cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
  1721. if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
  1722. /* Check if the pid is the same as before. */
  1723. gidpn_rsp = (struct fcgs_gidpn_resp_s *) (cthdr + 1);
  1724. if (gidpn_rsp->dap == rport->pid) {
  1725. /* Device is online */
  1726. bfa_sm_send_event(rport, RPSM_EVENT_ACCEPTED);
  1727. } else {
  1728. /*
  1729. * Device's PID has changed. We need to cleanup
  1730. * and re-login. If there is another device with
  1731. * the the newly discovered pid, send an scn notice
  1732. * so that its new pid can be discovered.
  1733. */
  1734. list_for_each(qe, &rport->port->rport_q) {
  1735. twin = (struct bfa_fcs_rport_s *) qe;
  1736. if (twin == rport)
  1737. continue;
  1738. if (gidpn_rsp->dap == twin->pid) {
  1739. bfa_trc(rport->fcs, twin->pid);
  1740. bfa_trc(rport->fcs, rport->pid);
  1741. twin->pid = 0;
  1742. bfa_sm_send_event(twin,
  1743. RPSM_EVENT_ADDRESS_CHANGE);
  1744. }
  1745. }
  1746. rport->pid = gidpn_rsp->dap;
  1747. bfa_sm_send_event(rport, RPSM_EVENT_ADDRESS_CHANGE);
  1748. }
  1749. return;
  1750. }
  1751. /*
  1752. * Reject Response
  1753. */
  1754. switch (cthdr->reason_code) {
  1755. case CT_RSN_LOGICAL_BUSY:
  1756. /*
  1757. * Need to retry
  1758. */
  1759. bfa_sm_send_event(rport, RPSM_EVENT_TIMEOUT);
  1760. break;
  1761. case CT_RSN_UNABLE_TO_PERF:
  1762. /*
  1763. * device doesn't exist : Start timer to cleanup this later.
  1764. */
  1765. bfa_sm_send_event(rport, RPSM_EVENT_FAILED);
  1766. break;
  1767. default:
  1768. bfa_sm_send_event(rport, RPSM_EVENT_FAILED);
  1769. break;
  1770. }
  1771. }
  1772. static void
  1773. bfa_fcs_rport_gpnid_response(void *fcsarg, struct bfa_fcxp_s *fcxp, void *cbarg,
  1774. bfa_status_t req_status, u32 rsp_len,
  1775. u32 resid_len, struct fchs_s *rsp_fchs)
  1776. {
  1777. struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *) cbarg;
  1778. struct ct_hdr_s *cthdr;
  1779. bfa_trc(rport->fcs, rport->pwwn);
  1780. cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
  1781. cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
  1782. if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
  1783. bfa_sm_send_event(rport, RPSM_EVENT_ACCEPTED);
  1784. return;
  1785. }
  1786. /*
  1787. * Reject Response
  1788. */
  1789. switch (cthdr->reason_code) {
  1790. case CT_RSN_LOGICAL_BUSY:
  1791. /*
  1792. * Need to retry
  1793. */
  1794. bfa_sm_send_event(rport, RPSM_EVENT_TIMEOUT);
  1795. break;
  1796. case CT_RSN_UNABLE_TO_PERF:
  1797. /*
  1798. * device doesn't exist : Start timer to cleanup this later.
  1799. */
  1800. bfa_sm_send_event(rport, RPSM_EVENT_FAILED);
  1801. break;
  1802. default:
  1803. bfa_sm_send_event(rport, RPSM_EVENT_FAILED);
  1804. break;
  1805. }
  1806. }
  1807. /*
  1808. * Called to send a logout to the rport.
  1809. */
  1810. static void
  1811. bfa_fcs_rport_send_logo(void *rport_cbarg, struct bfa_fcxp_s *fcxp_alloced)
  1812. {
  1813. struct bfa_fcs_rport_s *rport = rport_cbarg;
  1814. struct bfa_fcs_lport_s *port;
  1815. struct fchs_s fchs;
  1816. struct bfa_fcxp_s *fcxp;
  1817. u16 len;
  1818. bfa_trc(rport->fcs, rport->pid);
  1819. port = rport->port;
  1820. fcxp = fcxp_alloced ? fcxp_alloced :
  1821. bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
  1822. if (!fcxp) {
  1823. bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &rport->fcxp_wqe,
  1824. bfa_fcs_rport_send_logo, rport, BFA_FALSE);
  1825. return;
  1826. }
  1827. rport->fcxp = fcxp;
  1828. len = fc_logo_build(&fchs, bfa_fcxp_get_reqbuf(fcxp), rport->pid,
  1829. bfa_fcs_lport_get_fcid(port), 0,
  1830. bfa_fcs_lport_get_pwwn(port));
  1831. bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
  1832. FC_CLASS_3, len, &fchs, NULL,
  1833. rport, FC_MAX_PDUSZ, FC_ELS_TOV);
  1834. rport->stats.logos++;
  1835. bfa_fcxp_discard(rport->fcxp);
  1836. bfa_sm_send_event(rport, RPSM_EVENT_FCXP_SENT);
  1837. }
  1838. /*
  1839. * Send ACC for a LOGO received.
  1840. */
  1841. static void
  1842. bfa_fcs_rport_send_logo_acc(void *rport_cbarg)
  1843. {
  1844. struct bfa_fcs_rport_s *rport = rport_cbarg;
  1845. struct bfa_fcs_lport_s *port;
  1846. struct fchs_s fchs;
  1847. struct bfa_fcxp_s *fcxp;
  1848. u16 len;
  1849. bfa_trc(rport->fcs, rport->pid);
  1850. port = rport->port;
  1851. fcxp = bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
  1852. if (!fcxp)
  1853. return;
  1854. rport->stats.logo_rcvd++;
  1855. len = fc_logo_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
  1856. rport->pid, bfa_fcs_lport_get_fcid(port),
  1857. rport->reply_oxid);
  1858. bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
  1859. FC_CLASS_3, len, &fchs, NULL, NULL, FC_MAX_PDUSZ, 0);
  1860. }
  1861. /*
  1862. * brief
  1863. * This routine will be called by bfa_timer on timer timeouts.
  1864. *
  1865. * param[in] rport - pointer to bfa_fcs_lport_ns_t.
  1866. * param[out] rport_status - pointer to return vport status in
  1867. *
  1868. * return
  1869. * void
  1870. *
  1871. * Special Considerations:
  1872. *
  1873. * note
  1874. */
  1875. static void
  1876. bfa_fcs_rport_timeout(void *arg)
  1877. {
  1878. struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *) arg;
  1879. rport->stats.plogi_timeouts++;
  1880. bfa_stats(rport->port, rport_plogi_timeouts);
  1881. bfa_sm_send_event(rport, RPSM_EVENT_TIMEOUT);
  1882. }
  1883. static void
  1884. bfa_fcs_rport_process_prli(struct bfa_fcs_rport_s *rport,
  1885. struct fchs_s *rx_fchs, u16 len)
  1886. {
  1887. struct bfa_fcxp_s *fcxp;
  1888. struct fchs_s fchs;
  1889. struct bfa_fcs_lport_s *port = rport->port;
  1890. struct fc_prli_s *prli;
  1891. bfa_trc(port->fcs, rx_fchs->s_id);
  1892. bfa_trc(port->fcs, rx_fchs->d_id);
  1893. rport->stats.prli_rcvd++;
  1894. /*
  1895. * We are in Initiator Mode
  1896. */
  1897. prli = (struct fc_prli_s *) (rx_fchs + 1);
  1898. if (prli->parampage.servparams.target) {
  1899. /*
  1900. * PRLI from a target ?
  1901. * Send the Acc.
  1902. * PRLI sent by us will be used to transition the IT nexus,
  1903. * once the response is received from the target.
  1904. */
  1905. bfa_trc(port->fcs, rx_fchs->s_id);
  1906. rport->scsi_function = BFA_RPORT_TARGET;
  1907. } else {
  1908. bfa_trc(rport->fcs, prli->parampage.type);
  1909. rport->scsi_function = BFA_RPORT_INITIATOR;
  1910. bfa_fcs_itnim_is_initiator(rport->itnim);
  1911. }
  1912. fcxp = bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
  1913. if (!fcxp)
  1914. return;
  1915. len = fc_prli_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
  1916. rx_fchs->s_id, bfa_fcs_lport_get_fcid(port),
  1917. rx_fchs->ox_id, port->port_cfg.roles);
  1918. bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
  1919. FC_CLASS_3, len, &fchs, NULL, NULL, FC_MAX_PDUSZ, 0);
  1920. }
  1921. static void
  1922. bfa_fcs_rport_process_rpsc(struct bfa_fcs_rport_s *rport,
  1923. struct fchs_s *rx_fchs, u16 len)
  1924. {
  1925. struct bfa_fcxp_s *fcxp;
  1926. struct fchs_s fchs;
  1927. struct bfa_fcs_lport_s *port = rport->port;
  1928. struct fc_rpsc_speed_info_s speeds;
  1929. struct bfa_port_attr_s pport_attr;
  1930. bfa_trc(port->fcs, rx_fchs->s_id);
  1931. bfa_trc(port->fcs, rx_fchs->d_id);
  1932. rport->stats.rpsc_rcvd++;
  1933. speeds.port_speed_cap =
  1934. RPSC_SPEED_CAP_1G | RPSC_SPEED_CAP_2G | RPSC_SPEED_CAP_4G |
  1935. RPSC_SPEED_CAP_8G;
  1936. /*
  1937. * get curent speed from pport attributes from BFA
  1938. */
  1939. bfa_fcport_get_attr(port->fcs->bfa, &pport_attr);
  1940. speeds.port_op_speed = fc_bfa_speed_to_rpsc_operspeed(pport_attr.speed);
  1941. fcxp = bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
  1942. if (!fcxp)
  1943. return;
  1944. len = fc_rpsc_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
  1945. rx_fchs->s_id, bfa_fcs_lport_get_fcid(port),
  1946. rx_fchs->ox_id, &speeds);
  1947. bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
  1948. FC_CLASS_3, len, &fchs, NULL, NULL, FC_MAX_PDUSZ, 0);
  1949. }
  1950. static void
  1951. bfa_fcs_rport_process_adisc(struct bfa_fcs_rport_s *rport,
  1952. struct fchs_s *rx_fchs, u16 len)
  1953. {
  1954. struct bfa_fcxp_s *fcxp;
  1955. struct fchs_s fchs;
  1956. struct bfa_fcs_lport_s *port = rport->port;
  1957. struct fc_adisc_s *adisc;
  1958. bfa_trc(port->fcs, rx_fchs->s_id);
  1959. bfa_trc(port->fcs, rx_fchs->d_id);
  1960. rport->stats.adisc_rcvd++;
  1961. adisc = (struct fc_adisc_s *) (rx_fchs + 1);
  1962. /*
  1963. * Accept if the itnim for this rport is online.
  1964. * Else reject the ADISC.
  1965. */
  1966. if (bfa_fcs_itnim_get_online_state(rport->itnim) == BFA_STATUS_OK) {
  1967. fcxp = bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
  1968. if (!fcxp)
  1969. return;
  1970. len = fc_adisc_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
  1971. rx_fchs->s_id, bfa_fcs_lport_get_fcid(port),
  1972. rx_fchs->ox_id, port->port_cfg.pwwn,
  1973. port->port_cfg.nwwn);
  1974. bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag,
  1975. BFA_FALSE, FC_CLASS_3, len, &fchs, NULL, NULL,
  1976. FC_MAX_PDUSZ, 0);
  1977. } else {
  1978. rport->stats.adisc_rejected++;
  1979. bfa_fcs_rport_send_ls_rjt(rport, rx_fchs,
  1980. FC_LS_RJT_RSN_UNABLE_TO_PERF_CMD,
  1981. FC_LS_RJT_EXP_LOGIN_REQUIRED);
  1982. }
  1983. }
  1984. static void
  1985. bfa_fcs_rport_hal_online(struct bfa_fcs_rport_s *rport)
  1986. {
  1987. struct bfa_fcs_lport_s *port = rport->port;
  1988. struct bfa_rport_info_s rport_info;
  1989. rport_info.pid = rport->pid;
  1990. rport_info.local_pid = port->pid;
  1991. rport_info.lp_tag = port->lp_tag;
  1992. rport_info.vf_id = port->fabric->vf_id;
  1993. rport_info.vf_en = port->fabric->is_vf;
  1994. rport_info.fc_class = rport->fc_cos;
  1995. rport_info.cisc = rport->cisc;
  1996. rport_info.max_frmsz = rport->maxfrsize;
  1997. bfa_rport_online(rport->bfa_rport, &rport_info);
  1998. }
  1999. static void
  2000. bfa_fcs_rport_hal_offline(struct bfa_fcs_rport_s *rport)
  2001. {
  2002. if (rport->bfa_rport)
  2003. bfa_sm_send_event(rport->bfa_rport, BFA_RPORT_SM_OFFLINE);
  2004. else
  2005. bfa_cb_rport_offline(rport);
  2006. }
  2007. static struct bfa_fcs_rport_s *
  2008. bfa_fcs_rport_alloc(struct bfa_fcs_lport_s *port, wwn_t pwwn, u32 rpid)
  2009. {
  2010. struct bfa_fcs_s *fcs = port->fcs;
  2011. struct bfa_fcs_rport_s *rport;
  2012. struct bfad_rport_s *rport_drv;
  2013. /*
  2014. * allocate rport
  2015. */
  2016. if (fcs->num_rport_logins >= bfa_fcs_rport_max_logins) {
  2017. bfa_trc(fcs, rpid);
  2018. return NULL;
  2019. }
  2020. if (bfa_fcb_rport_alloc(fcs->bfad, &rport, &rport_drv)
  2021. != BFA_STATUS_OK) {
  2022. bfa_trc(fcs, rpid);
  2023. return NULL;
  2024. }
  2025. /*
  2026. * Initialize r-port
  2027. */
  2028. rport->port = port;
  2029. rport->fcs = fcs;
  2030. rport->rp_drv = rport_drv;
  2031. rport->pid = rpid;
  2032. rport->pwwn = pwwn;
  2033. rport->old_pid = 0;
  2034. rport->bfa_rport = NULL;
  2035. /*
  2036. * allocate FC-4s
  2037. */
  2038. WARN_ON(!bfa_fcs_lport_is_initiator(port));
  2039. if (bfa_fcs_lport_is_initiator(port)) {
  2040. rport->itnim = bfa_fcs_itnim_create(rport);
  2041. if (!rport->itnim) {
  2042. bfa_trc(fcs, rpid);
  2043. kfree(rport_drv);
  2044. return NULL;
  2045. }
  2046. }
  2047. bfa_fcs_lport_add_rport(port, rport);
  2048. fcs->num_rport_logins++;
  2049. bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
  2050. /* Initialize the Rport Features(RPF) Sub Module */
  2051. if (!BFA_FCS_PID_IS_WKA(rport->pid))
  2052. bfa_fcs_rpf_init(rport);
  2053. return rport;
  2054. }
  2055. static void
  2056. bfa_fcs_rport_free(struct bfa_fcs_rport_s *rport)
  2057. {
  2058. struct bfa_fcs_lport_s *port = rport->port;
  2059. struct bfa_fcs_s *fcs = port->fcs;
  2060. /*
  2061. * - delete FC-4s
  2062. * - delete BFA rport
  2063. * - remove from queue of rports
  2064. */
  2065. rport->plogi_pending = BFA_FALSE;
  2066. if (bfa_fcs_lport_is_initiator(port)) {
  2067. bfa_fcs_itnim_delete(rport->itnim);
  2068. if (rport->pid != 0 && !BFA_FCS_PID_IS_WKA(rport->pid))
  2069. bfa_fcs_rpf_rport_offline(rport);
  2070. }
  2071. if (rport->bfa_rport) {
  2072. bfa_sm_send_event(rport->bfa_rport, BFA_RPORT_SM_DELETE);
  2073. rport->bfa_rport = NULL;
  2074. }
  2075. bfa_fcs_lport_del_rport(port, rport);
  2076. fcs->num_rport_logins--;
  2077. kfree(rport->rp_drv);
  2078. }
  2079. static void
  2080. bfa_fcs_rport_aen_post(struct bfa_fcs_rport_s *rport,
  2081. enum bfa_rport_aen_event event,
  2082. struct bfa_rport_aen_data_s *data)
  2083. {
  2084. struct bfa_fcs_lport_s *port = rport->port;
  2085. struct bfad_s *bfad = (struct bfad_s *)port->fcs->bfad;
  2086. struct bfa_aen_entry_s *aen_entry;
  2087. bfad_get_aen_entry(bfad, aen_entry);
  2088. if (!aen_entry)
  2089. return;
  2090. if (event == BFA_RPORT_AEN_QOS_PRIO)
  2091. aen_entry->aen_data.rport.priv.qos = data->priv.qos;
  2092. else if (event == BFA_RPORT_AEN_QOS_FLOWID)
  2093. aen_entry->aen_data.rport.priv.qos = data->priv.qos;
  2094. aen_entry->aen_data.rport.vf_id = rport->port->fabric->vf_id;
  2095. aen_entry->aen_data.rport.ppwwn = bfa_fcs_lport_get_pwwn(
  2096. bfa_fcs_get_base_port(rport->fcs));
  2097. aen_entry->aen_data.rport.lpwwn = bfa_fcs_lport_get_pwwn(rport->port);
  2098. aen_entry->aen_data.rport.rpwwn = rport->pwwn;
  2099. /* Send the AEN notification */
  2100. bfad_im_post_vendor_event(aen_entry, bfad, ++rport->fcs->fcs_aen_seq,
  2101. BFA_AEN_CAT_RPORT, event);
  2102. }
  2103. static void
  2104. bfa_fcs_rport_fcs_online_action(struct bfa_fcs_rport_s *rport)
  2105. {
  2106. if ((!rport->pid) || (!rport->pwwn)) {
  2107. bfa_trc(rport->fcs, rport->pid);
  2108. bfa_sm_fault(rport->fcs, rport->pid);
  2109. }
  2110. bfa_sm_send_event(rport->itnim, BFA_FCS_ITNIM_SM_FCS_ONLINE);
  2111. }
  2112. static void
  2113. bfa_fcs_rport_hal_online_action(struct bfa_fcs_rport_s *rport)
  2114. {
  2115. struct bfa_fcs_lport_s *port = rport->port;
  2116. struct bfad_s *bfad = (struct bfad_s *)port->fcs->bfad;
  2117. char lpwwn_buf[BFA_STRING_32];
  2118. char rpwwn_buf[BFA_STRING_32];
  2119. rport->stats.onlines++;
  2120. if ((!rport->pid) || (!rport->pwwn)) {
  2121. bfa_trc(rport->fcs, rport->pid);
  2122. bfa_sm_fault(rport->fcs, rport->pid);
  2123. }
  2124. if (bfa_fcs_lport_is_initiator(port)) {
  2125. bfa_fcs_itnim_brp_online(rport->itnim);
  2126. if (!BFA_FCS_PID_IS_WKA(rport->pid))
  2127. bfa_fcs_rpf_rport_online(rport);
  2128. };
  2129. wwn2str(lpwwn_buf, bfa_fcs_lport_get_pwwn(port));
  2130. wwn2str(rpwwn_buf, rport->pwwn);
  2131. if (!BFA_FCS_PID_IS_WKA(rport->pid)) {
  2132. BFA_LOG(KERN_INFO, bfad, bfa_log_level,
  2133. "Remote port (WWN = %s) online for logical port (WWN = %s)\n",
  2134. rpwwn_buf, lpwwn_buf);
  2135. bfa_fcs_rport_aen_post(rport, BFA_RPORT_AEN_ONLINE, NULL);
  2136. }
  2137. }
  2138. static void
  2139. bfa_fcs_rport_fcs_offline_action(struct bfa_fcs_rport_s *rport)
  2140. {
  2141. if (!BFA_FCS_PID_IS_WKA(rport->pid))
  2142. bfa_fcs_rpf_rport_offline(rport);
  2143. bfa_fcs_itnim_rport_offline(rport->itnim);
  2144. }
  2145. static void
  2146. bfa_fcs_rport_hal_offline_action(struct bfa_fcs_rport_s *rport)
  2147. {
  2148. struct bfa_fcs_lport_s *port = rport->port;
  2149. struct bfad_s *bfad = (struct bfad_s *)port->fcs->bfad;
  2150. char lpwwn_buf[BFA_STRING_32];
  2151. char rpwwn_buf[BFA_STRING_32];
  2152. if (!rport->bfa_rport) {
  2153. bfa_fcs_rport_fcs_offline_action(rport);
  2154. return;
  2155. }
  2156. rport->stats.offlines++;
  2157. wwn2str(lpwwn_buf, bfa_fcs_lport_get_pwwn(port));
  2158. wwn2str(rpwwn_buf, rport->pwwn);
  2159. if (!BFA_FCS_PID_IS_WKA(rport->pid)) {
  2160. if (bfa_fcs_lport_is_online(rport->port) == BFA_TRUE) {
  2161. BFA_LOG(KERN_ERR, bfad, bfa_log_level,
  2162. "Remote port (WWN = %s) connectivity lost for "
  2163. "logical port (WWN = %s)\n",
  2164. rpwwn_buf, lpwwn_buf);
  2165. bfa_fcs_rport_aen_post(rport,
  2166. BFA_RPORT_AEN_DISCONNECT, NULL);
  2167. } else {
  2168. BFA_LOG(KERN_INFO, bfad, bfa_log_level,
  2169. "Remote port (WWN = %s) offlined by "
  2170. "logical port (WWN = %s)\n",
  2171. rpwwn_buf, lpwwn_buf);
  2172. bfa_fcs_rport_aen_post(rport,
  2173. BFA_RPORT_AEN_OFFLINE, NULL);
  2174. }
  2175. }
  2176. if (bfa_fcs_lport_is_initiator(port)) {
  2177. bfa_fcs_itnim_rport_offline(rport->itnim);
  2178. if (!BFA_FCS_PID_IS_WKA(rport->pid))
  2179. bfa_fcs_rpf_rport_offline(rport);
  2180. }
  2181. }
  2182. /*
  2183. * Update rport parameters from PLOGI or PLOGI accept.
  2184. */
  2185. static void
  2186. bfa_fcs_rport_update(struct bfa_fcs_rport_s *rport, struct fc_logi_s *plogi)
  2187. {
  2188. bfa_fcs_lport_t *port = rport->port;
  2189. /*
  2190. * - port name
  2191. * - node name
  2192. */
  2193. rport->pwwn = plogi->port_name;
  2194. rport->nwwn = plogi->node_name;
  2195. /*
  2196. * - class of service
  2197. */
  2198. rport->fc_cos = 0;
  2199. if (plogi->class3.class_valid)
  2200. rport->fc_cos = FC_CLASS_3;
  2201. if (plogi->class2.class_valid)
  2202. rport->fc_cos |= FC_CLASS_2;
  2203. /*
  2204. * - CISC
  2205. * - MAX receive frame size
  2206. */
  2207. rport->cisc = plogi->csp.cisc;
  2208. if (be16_to_cpu(plogi->class3.rxsz) < be16_to_cpu(plogi->csp.rxsz))
  2209. rport->maxfrsize = be16_to_cpu(plogi->class3.rxsz);
  2210. else
  2211. rport->maxfrsize = be16_to_cpu(plogi->csp.rxsz);
  2212. bfa_trc(port->fcs, be16_to_cpu(plogi->csp.bbcred));
  2213. bfa_trc(port->fcs, port->fabric->bb_credit);
  2214. /*
  2215. * Direct Attach P2P mode :
  2216. * This is to handle a bug (233476) in IBM targets in Direct Attach
  2217. * Mode. Basically, in FLOGI Accept the target would have
  2218. * erroneously set the BB Credit to the value used in the FLOGI
  2219. * sent by the HBA. It uses the correct value (its own BB credit)
  2220. * in PLOGI.
  2221. */
  2222. if ((!bfa_fcs_fabric_is_switched(port->fabric)) &&
  2223. (be16_to_cpu(plogi->csp.bbcred) < port->fabric->bb_credit)) {
  2224. bfa_trc(port->fcs, be16_to_cpu(plogi->csp.bbcred));
  2225. bfa_trc(port->fcs, port->fabric->bb_credit);
  2226. port->fabric->bb_credit = be16_to_cpu(plogi->csp.bbcred);
  2227. bfa_fcport_set_tx_bbcredit(port->fcs->bfa,
  2228. port->fabric->bb_credit);
  2229. }
  2230. }
  2231. /*
  2232. * Called to handle LOGO received from an existing remote port.
  2233. */
  2234. static void
  2235. bfa_fcs_rport_process_logo(struct bfa_fcs_rport_s *rport, struct fchs_s *fchs)
  2236. {
  2237. rport->reply_oxid = fchs->ox_id;
  2238. bfa_trc(rport->fcs, rport->reply_oxid);
  2239. rport->prlo = BFA_FALSE;
  2240. rport->stats.logo_rcvd++;
  2241. bfa_sm_send_event(rport, RPSM_EVENT_LOGO_RCVD);
  2242. }
  2243. /*
  2244. * fcs_rport_public FCS rport public interfaces
  2245. */
  2246. /*
  2247. * Called by bport/vport to create a remote port instance for a discovered
  2248. * remote device.
  2249. *
  2250. * @param[in] port - base port or vport
  2251. * @param[in] rpid - remote port ID
  2252. *
  2253. * @return None
  2254. */
  2255. struct bfa_fcs_rport_s *
  2256. bfa_fcs_rport_create(struct bfa_fcs_lport_s *port, u32 rpid)
  2257. {
  2258. struct bfa_fcs_rport_s *rport;
  2259. bfa_trc(port->fcs, rpid);
  2260. rport = bfa_fcs_rport_alloc(port, WWN_NULL, rpid);
  2261. if (!rport)
  2262. return NULL;
  2263. bfa_sm_send_event(rport, RPSM_EVENT_PLOGI_SEND);
  2264. return rport;
  2265. }
  2266. /*
  2267. * Called to create a rport for which only the wwn is known.
  2268. *
  2269. * @param[in] port - base port
  2270. * @param[in] rpwwn - remote port wwn
  2271. *
  2272. * @return None
  2273. */
  2274. struct bfa_fcs_rport_s *
  2275. bfa_fcs_rport_create_by_wwn(struct bfa_fcs_lport_s *port, wwn_t rpwwn)
  2276. {
  2277. struct bfa_fcs_rport_s *rport;
  2278. bfa_trc(port->fcs, rpwwn);
  2279. rport = bfa_fcs_rport_alloc(port, rpwwn, 0);
  2280. if (!rport)
  2281. return NULL;
  2282. bfa_sm_send_event(rport, RPSM_EVENT_ADDRESS_DISC);
  2283. return rport;
  2284. }
  2285. /*
  2286. * Called by bport in private loop topology to indicate that a
  2287. * rport has been discovered and plogi has been completed.
  2288. *
  2289. * @param[in] port - base port or vport
  2290. * @param[in] rpid - remote port ID
  2291. */
  2292. void
  2293. bfa_fcs_rport_start(struct bfa_fcs_lport_s *port, struct fchs_s *fchs,
  2294. struct fc_logi_s *plogi)
  2295. {
  2296. struct bfa_fcs_rport_s *rport;
  2297. rport = bfa_fcs_rport_alloc(port, WWN_NULL, fchs->s_id);
  2298. if (!rport)
  2299. return;
  2300. bfa_fcs_rport_update(rport, plogi);
  2301. bfa_sm_send_event(rport, RPSM_EVENT_PLOGI_COMP);
  2302. }
  2303. /*
  2304. * Called by bport/vport to handle PLOGI received from a new remote port.
  2305. * If an existing rport does a plogi, it will be handled separately.
  2306. */
  2307. void
  2308. bfa_fcs_rport_plogi_create(struct bfa_fcs_lport_s *port, struct fchs_s *fchs,
  2309. struct fc_logi_s *plogi)
  2310. {
  2311. struct bfa_fcs_rport_s *rport;
  2312. rport = bfa_fcs_rport_alloc(port, plogi->port_name, fchs->s_id);
  2313. if (!rport)
  2314. return;
  2315. bfa_fcs_rport_update(rport, plogi);
  2316. rport->reply_oxid = fchs->ox_id;
  2317. bfa_trc(rport->fcs, rport->reply_oxid);
  2318. rport->stats.plogi_rcvd++;
  2319. bfa_sm_send_event(rport, RPSM_EVENT_PLOGI_RCVD);
  2320. }
  2321. /*
  2322. * Called by bport/vport to handle PLOGI received from an existing
  2323. * remote port.
  2324. */
  2325. void
  2326. bfa_fcs_rport_plogi(struct bfa_fcs_rport_s *rport, struct fchs_s *rx_fchs,
  2327. struct fc_logi_s *plogi)
  2328. {
  2329. /*
  2330. * @todo Handle P2P and initiator-initiator.
  2331. */
  2332. bfa_fcs_rport_update(rport, plogi);
  2333. rport->reply_oxid = rx_fchs->ox_id;
  2334. bfa_trc(rport->fcs, rport->reply_oxid);
  2335. rport->pid = rx_fchs->s_id;
  2336. bfa_trc(rport->fcs, rport->pid);
  2337. rport->stats.plogi_rcvd++;
  2338. bfa_sm_send_event(rport, RPSM_EVENT_PLOGI_RCVD);
  2339. }
  2340. /*
  2341. * Called by bport/vport to notify SCN for the remote port
  2342. */
  2343. void
  2344. bfa_fcs_rport_scn(struct bfa_fcs_rport_s *rport)
  2345. {
  2346. rport->stats.rscns++;
  2347. bfa_sm_send_event(rport, RPSM_EVENT_FAB_SCN);
  2348. }
  2349. /*
  2350. * brief
  2351. * This routine BFA callback for bfa_rport_online() call.
  2352. *
  2353. * param[in] cb_arg - rport struct.
  2354. *
  2355. * return
  2356. * void
  2357. *
  2358. * Special Considerations:
  2359. *
  2360. * note
  2361. */
  2362. void
  2363. bfa_cb_rport_online(void *cbarg)
  2364. {
  2365. struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *) cbarg;
  2366. bfa_trc(rport->fcs, rport->pwwn);
  2367. bfa_sm_send_event(rport, RPSM_EVENT_HCB_ONLINE);
  2368. }
  2369. /*
  2370. * brief
  2371. * This routine BFA callback for bfa_rport_offline() call.
  2372. *
  2373. * param[in] rport -
  2374. *
  2375. * return
  2376. * void
  2377. *
  2378. * Special Considerations:
  2379. *
  2380. * note
  2381. */
  2382. void
  2383. bfa_cb_rport_offline(void *cbarg)
  2384. {
  2385. struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *) cbarg;
  2386. bfa_trc(rport->fcs, rport->pwwn);
  2387. bfa_sm_send_event(rport, RPSM_EVENT_HCB_OFFLINE);
  2388. }
  2389. /*
  2390. * brief
  2391. * This routine is a static BFA callback when there is a QoS flow_id
  2392. * change notification
  2393. *
  2394. * param[in] rport -
  2395. *
  2396. * return
  2397. * void
  2398. *
  2399. * Special Considerations:
  2400. *
  2401. * note
  2402. */
  2403. void
  2404. bfa_cb_rport_qos_scn_flowid(void *cbarg,
  2405. struct bfa_rport_qos_attr_s old_qos_attr,
  2406. struct bfa_rport_qos_attr_s new_qos_attr)
  2407. {
  2408. struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *) cbarg;
  2409. struct bfa_rport_aen_data_s aen_data;
  2410. bfa_trc(rport->fcs, rport->pwwn);
  2411. aen_data.priv.qos = new_qos_attr;
  2412. bfa_fcs_rport_aen_post(rport, BFA_RPORT_AEN_QOS_FLOWID, &aen_data);
  2413. }
  2414. void
  2415. bfa_cb_rport_scn_online(struct bfa_s *bfa)
  2416. {
  2417. struct bfa_fcs_s *fcs = &((struct bfad_s *)bfa->bfad)->bfa_fcs;
  2418. struct bfa_fcs_lport_s *port = bfa_fcs_get_base_port(fcs);
  2419. struct bfa_fcs_rport_s *rp;
  2420. struct list_head *qe;
  2421. list_for_each(qe, &port->rport_q) {
  2422. rp = (struct bfa_fcs_rport_s *) qe;
  2423. bfa_sm_send_event(rp, RPSM_EVENT_SCN_ONLINE);
  2424. rp->scn_online = BFA_TRUE;
  2425. }
  2426. if (bfa_fcs_lport_is_online(port))
  2427. bfa_fcs_lport_lip_scn_online(port);
  2428. }
  2429. void
  2430. bfa_cb_rport_scn_no_dev(void *rport)
  2431. {
  2432. struct bfa_fcs_rport_s *rp = rport;
  2433. bfa_sm_send_event(rp, RPSM_EVENT_SCN_OFFLINE);
  2434. rp->scn_online = BFA_FALSE;
  2435. }
  2436. void
  2437. bfa_cb_rport_scn_offline(struct bfa_s *bfa)
  2438. {
  2439. struct bfa_fcs_s *fcs = &((struct bfad_s *)bfa->bfad)->bfa_fcs;
  2440. struct bfa_fcs_lport_s *port = bfa_fcs_get_base_port(fcs);
  2441. struct bfa_fcs_rport_s *rp;
  2442. struct list_head *qe;
  2443. list_for_each(qe, &port->rport_q) {
  2444. rp = (struct bfa_fcs_rport_s *) qe;
  2445. bfa_sm_send_event(rp, RPSM_EVENT_SCN_OFFLINE);
  2446. rp->scn_online = BFA_FALSE;
  2447. }
  2448. }
  2449. /*
  2450. * brief
  2451. * This routine is a static BFA callback when there is a QoS priority
  2452. * change notification
  2453. *
  2454. * param[in] rport -
  2455. *
  2456. * return
  2457. * void
  2458. *
  2459. * Special Considerations:
  2460. *
  2461. * note
  2462. */
  2463. void
  2464. bfa_cb_rport_qos_scn_prio(void *cbarg,
  2465. struct bfa_rport_qos_attr_s old_qos_attr,
  2466. struct bfa_rport_qos_attr_s new_qos_attr)
  2467. {
  2468. struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *) cbarg;
  2469. struct bfa_rport_aen_data_s aen_data;
  2470. bfa_trc(rport->fcs, rport->pwwn);
  2471. aen_data.priv.qos = new_qos_attr;
  2472. bfa_fcs_rport_aen_post(rport, BFA_RPORT_AEN_QOS_PRIO, &aen_data);
  2473. }
  2474. /*
  2475. * Called to process any unsolicted frames from this remote port
  2476. */
  2477. void
  2478. bfa_fcs_rport_uf_recv(struct bfa_fcs_rport_s *rport,
  2479. struct fchs_s *fchs, u16 len)
  2480. {
  2481. struct bfa_fcs_lport_s *port = rport->port;
  2482. struct fc_els_cmd_s *els_cmd;
  2483. bfa_trc(rport->fcs, fchs->s_id);
  2484. bfa_trc(rport->fcs, fchs->d_id);
  2485. bfa_trc(rport->fcs, fchs->type);
  2486. if (fchs->type != FC_TYPE_ELS)
  2487. return;
  2488. els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
  2489. bfa_trc(rport->fcs, els_cmd->els_code);
  2490. switch (els_cmd->els_code) {
  2491. case FC_ELS_LOGO:
  2492. bfa_stats(port, plogi_rcvd);
  2493. bfa_fcs_rport_process_logo(rport, fchs);
  2494. break;
  2495. case FC_ELS_ADISC:
  2496. bfa_stats(port, adisc_rcvd);
  2497. bfa_fcs_rport_process_adisc(rport, fchs, len);
  2498. break;
  2499. case FC_ELS_PRLO:
  2500. bfa_stats(port, prlo_rcvd);
  2501. if (bfa_fcs_lport_is_initiator(port))
  2502. bfa_fcs_fcpim_uf_recv(rport->itnim, fchs, len);
  2503. break;
  2504. case FC_ELS_PRLI:
  2505. bfa_stats(port, prli_rcvd);
  2506. bfa_fcs_rport_process_prli(rport, fchs, len);
  2507. break;
  2508. case FC_ELS_RPSC:
  2509. bfa_stats(port, rpsc_rcvd);
  2510. bfa_fcs_rport_process_rpsc(rport, fchs, len);
  2511. break;
  2512. default:
  2513. bfa_stats(port, un_handled_els_rcvd);
  2514. bfa_fcs_rport_send_ls_rjt(rport, fchs,
  2515. FC_LS_RJT_RSN_CMD_NOT_SUPP,
  2516. FC_LS_RJT_EXP_NO_ADDL_INFO);
  2517. break;
  2518. }
  2519. }
  2520. /* send best case acc to prlo */
  2521. static void
  2522. bfa_fcs_rport_send_prlo_acc(struct bfa_fcs_rport_s *rport)
  2523. {
  2524. struct bfa_fcs_lport_s *port = rport->port;
  2525. struct fchs_s fchs;
  2526. struct bfa_fcxp_s *fcxp;
  2527. int len;
  2528. bfa_trc(rport->fcs, rport->pid);
  2529. fcxp = bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
  2530. if (!fcxp)
  2531. return;
  2532. len = fc_prlo_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
  2533. rport->pid, bfa_fcs_lport_get_fcid(port),
  2534. rport->reply_oxid, 0);
  2535. bfa_fcxp_send(fcxp, rport->bfa_rport, port->fabric->vf_id,
  2536. port->lp_tag, BFA_FALSE, FC_CLASS_3, len, &fchs,
  2537. NULL, NULL, FC_MAX_PDUSZ, 0);
  2538. }
  2539. /*
  2540. * Send a LS reject
  2541. */
  2542. static void
  2543. bfa_fcs_rport_send_ls_rjt(struct bfa_fcs_rport_s *rport, struct fchs_s *rx_fchs,
  2544. u8 reason_code, u8 reason_code_expl)
  2545. {
  2546. struct bfa_fcs_lport_s *port = rport->port;
  2547. struct fchs_s fchs;
  2548. struct bfa_fcxp_s *fcxp;
  2549. int len;
  2550. bfa_trc(rport->fcs, rx_fchs->s_id);
  2551. fcxp = bfa_fcs_fcxp_alloc(rport->fcs, BFA_FALSE);
  2552. if (!fcxp)
  2553. return;
  2554. len = fc_ls_rjt_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
  2555. rx_fchs->s_id, bfa_fcs_lport_get_fcid(port),
  2556. rx_fchs->ox_id, reason_code, reason_code_expl);
  2557. bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag,
  2558. BFA_FALSE, FC_CLASS_3, len, &fchs, NULL, NULL,
  2559. FC_MAX_PDUSZ, 0);
  2560. }
  2561. /*
  2562. * Return state of rport.
  2563. */
  2564. int
  2565. bfa_fcs_rport_get_state(struct bfa_fcs_rport_s *rport)
  2566. {
  2567. return bfa_sm_to_state(rport_sm_table, rport->sm);
  2568. }
  2569. /*
  2570. * brief
  2571. * Called by the Driver to set rport delete/ageout timeout
  2572. *
  2573. * param[in] rport timeout value in seconds.
  2574. *
  2575. * return None
  2576. */
  2577. void
  2578. bfa_fcs_rport_set_del_timeout(u8 rport_tmo)
  2579. {
  2580. /* convert to Millisecs */
  2581. if (rport_tmo > 0)
  2582. bfa_fcs_rport_del_timeout = rport_tmo * 1000;
  2583. }
  2584. void
  2585. bfa_fcs_rport_prlo(struct bfa_fcs_rport_s *rport, __be16 ox_id)
  2586. {
  2587. bfa_trc(rport->fcs, rport->pid);
  2588. rport->prlo = BFA_TRUE;
  2589. rport->reply_oxid = ox_id;
  2590. bfa_sm_send_event(rport, RPSM_EVENT_PRLO_RCVD);
  2591. }
  2592. /*
  2593. * Called by BFAD to set the max limit on number of bfa_fcs_rport allocation
  2594. * which limits number of concurrent logins to remote ports
  2595. */
  2596. void
  2597. bfa_fcs_rport_set_max_logins(u32 max_logins)
  2598. {
  2599. if (max_logins > 0)
  2600. bfa_fcs_rport_max_logins = max_logins;
  2601. }
  2602. void
  2603. bfa_fcs_rport_get_attr(struct bfa_fcs_rport_s *rport,
  2604. struct bfa_rport_attr_s *rport_attr)
  2605. {
  2606. struct bfa_rport_qos_attr_s qos_attr;
  2607. struct bfa_fcs_lport_s *port = rport->port;
  2608. bfa_port_speed_t rport_speed = rport->rpf.rpsc_speed;
  2609. struct bfa_port_attr_s port_attr;
  2610. bfa_fcport_get_attr(rport->fcs->bfa, &port_attr);
  2611. memset(rport_attr, 0, sizeof(struct bfa_rport_attr_s));
  2612. memset(&qos_attr, 0, sizeof(struct bfa_rport_qos_attr_s));
  2613. rport_attr->pid = rport->pid;
  2614. rport_attr->pwwn = rport->pwwn;
  2615. rport_attr->nwwn = rport->nwwn;
  2616. rport_attr->cos_supported = rport->fc_cos;
  2617. rport_attr->df_sz = rport->maxfrsize;
  2618. rport_attr->state = bfa_fcs_rport_get_state(rport);
  2619. rport_attr->fc_cos = rport->fc_cos;
  2620. rport_attr->cisc = rport->cisc;
  2621. rport_attr->scsi_function = rport->scsi_function;
  2622. rport_attr->curr_speed = rport->rpf.rpsc_speed;
  2623. rport_attr->assigned_speed = rport->rpf.assigned_speed;
  2624. if (rport->bfa_rport) {
  2625. qos_attr.qos_priority = rport->bfa_rport->qos_attr.qos_priority;
  2626. qos_attr.qos_flow_id =
  2627. cpu_to_be32(rport->bfa_rport->qos_attr.qos_flow_id);
  2628. }
  2629. rport_attr->qos_attr = qos_attr;
  2630. rport_attr->trl_enforced = BFA_FALSE;
  2631. if (bfa_fcport_is_ratelim(port->fcs->bfa) &&
  2632. (rport->scsi_function == BFA_RPORT_TARGET)) {
  2633. if (rport_speed == BFA_PORT_SPEED_UNKNOWN)
  2634. rport_speed =
  2635. bfa_fcport_get_ratelim_speed(rport->fcs->bfa);
  2636. if ((bfa_fcs_lport_get_rport_max_speed(port) !=
  2637. BFA_PORT_SPEED_UNKNOWN) && (rport_speed < port_attr.speed))
  2638. rport_attr->trl_enforced = BFA_TRUE;
  2639. }
  2640. }
  2641. /*
  2642. * Remote port implementation.
  2643. */
  2644. /*
  2645. * fcs_rport_api FCS rport API.
  2646. */
  2647. struct bfa_fcs_rport_s *
  2648. bfa_fcs_rport_lookup(struct bfa_fcs_lport_s *port, wwn_t rpwwn)
  2649. {
  2650. struct bfa_fcs_rport_s *rport;
  2651. rport = bfa_fcs_lport_get_rport_by_pwwn(port, rpwwn);
  2652. if (rport == NULL) {
  2653. /*
  2654. * TBD Error handling
  2655. */
  2656. }
  2657. return rport;
  2658. }
  2659. struct bfa_fcs_rport_s *
  2660. bfa_fcs_rport_lookup_by_nwwn(struct bfa_fcs_lport_s *port, wwn_t rnwwn)
  2661. {
  2662. struct bfa_fcs_rport_s *rport;
  2663. rport = bfa_fcs_lport_get_rport_by_nwwn(port, rnwwn);
  2664. if (rport == NULL) {
  2665. /*
  2666. * TBD Error handling
  2667. */
  2668. }
  2669. return rport;
  2670. }
  2671. /*
  2672. * Remote port features (RPF) implementation.
  2673. */
  2674. #define BFA_FCS_RPF_RETRIES (3)
  2675. #define BFA_FCS_RPF_RETRY_TIMEOUT (1000) /* 1 sec (In millisecs) */
  2676. static void bfa_fcs_rpf_send_rpsc2(void *rport_cbarg,
  2677. struct bfa_fcxp_s *fcxp_alloced);
  2678. static void bfa_fcs_rpf_rpsc2_response(void *fcsarg,
  2679. struct bfa_fcxp_s *fcxp,
  2680. void *cbarg,
  2681. bfa_status_t req_status,
  2682. u32 rsp_len,
  2683. u32 resid_len,
  2684. struct fchs_s *rsp_fchs);
  2685. static void bfa_fcs_rpf_timeout(void *arg);
  2686. /*
  2687. * fcs_rport_ftrs_sm FCS rport state machine events
  2688. */
  2689. enum rpf_event {
  2690. RPFSM_EVENT_RPORT_OFFLINE = 1, /* Rport offline */
  2691. RPFSM_EVENT_RPORT_ONLINE = 2, /* Rport online */
  2692. RPFSM_EVENT_FCXP_SENT = 3, /* Frame from has been sent */
  2693. RPFSM_EVENT_TIMEOUT = 4, /* Rport SM timeout event */
  2694. RPFSM_EVENT_RPSC_COMP = 5,
  2695. RPFSM_EVENT_RPSC_FAIL = 6,
  2696. RPFSM_EVENT_RPSC_ERROR = 7,
  2697. };
  2698. static void bfa_fcs_rpf_sm_uninit(struct bfa_fcs_rpf_s *rpf,
  2699. enum rpf_event event);
  2700. static void bfa_fcs_rpf_sm_rpsc_sending(struct bfa_fcs_rpf_s *rpf,
  2701. enum rpf_event event);
  2702. static void bfa_fcs_rpf_sm_rpsc(struct bfa_fcs_rpf_s *rpf,
  2703. enum rpf_event event);
  2704. static void bfa_fcs_rpf_sm_rpsc_retry(struct bfa_fcs_rpf_s *rpf,
  2705. enum rpf_event event);
  2706. static void bfa_fcs_rpf_sm_offline(struct bfa_fcs_rpf_s *rpf,
  2707. enum rpf_event event);
  2708. static void bfa_fcs_rpf_sm_online(struct bfa_fcs_rpf_s *rpf,
  2709. enum rpf_event event);
  2710. static void
  2711. bfa_fcs_rpf_sm_uninit(struct bfa_fcs_rpf_s *rpf, enum rpf_event event)
  2712. {
  2713. struct bfa_fcs_rport_s *rport = rpf->rport;
  2714. struct bfa_fcs_fabric_s *fabric = &rport->fcs->fabric;
  2715. bfa_trc(rport->fcs, rport->pwwn);
  2716. bfa_trc(rport->fcs, rport->pid);
  2717. bfa_trc(rport->fcs, event);
  2718. switch (event) {
  2719. case RPFSM_EVENT_RPORT_ONLINE:
  2720. /* Send RPSC2 to a Brocade fabric only. */
  2721. if ((!BFA_FCS_PID_IS_WKA(rport->pid)) &&
  2722. ((rport->port->fabric->lps->brcd_switch) ||
  2723. (bfa_fcs_fabric_get_switch_oui(fabric) ==
  2724. BFA_FCS_BRCD_SWITCH_OUI))) {
  2725. bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_rpsc_sending);
  2726. rpf->rpsc_retries = 0;
  2727. bfa_fcs_rpf_send_rpsc2(rpf, NULL);
  2728. }
  2729. break;
  2730. case RPFSM_EVENT_RPORT_OFFLINE:
  2731. break;
  2732. default:
  2733. bfa_sm_fault(rport->fcs, event);
  2734. }
  2735. }
  2736. static void
  2737. bfa_fcs_rpf_sm_rpsc_sending(struct bfa_fcs_rpf_s *rpf, enum rpf_event event)
  2738. {
  2739. struct bfa_fcs_rport_s *rport = rpf->rport;
  2740. bfa_trc(rport->fcs, event);
  2741. switch (event) {
  2742. case RPFSM_EVENT_FCXP_SENT:
  2743. bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_rpsc);
  2744. break;
  2745. case RPFSM_EVENT_RPORT_OFFLINE:
  2746. bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_offline);
  2747. bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rpf->fcxp_wqe);
  2748. rpf->rpsc_retries = 0;
  2749. break;
  2750. default:
  2751. bfa_sm_fault(rport->fcs, event);
  2752. }
  2753. }
  2754. static void
  2755. bfa_fcs_rpf_sm_rpsc(struct bfa_fcs_rpf_s *rpf, enum rpf_event event)
  2756. {
  2757. struct bfa_fcs_rport_s *rport = rpf->rport;
  2758. bfa_trc(rport->fcs, rport->pid);
  2759. bfa_trc(rport->fcs, event);
  2760. switch (event) {
  2761. case RPFSM_EVENT_RPSC_COMP:
  2762. bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_online);
  2763. /* Update speed info in f/w via BFA */
  2764. if (rpf->rpsc_speed != BFA_PORT_SPEED_UNKNOWN)
  2765. bfa_rport_speed(rport->bfa_rport, rpf->rpsc_speed);
  2766. else if (rpf->assigned_speed != BFA_PORT_SPEED_UNKNOWN)
  2767. bfa_rport_speed(rport->bfa_rport, rpf->assigned_speed);
  2768. break;
  2769. case RPFSM_EVENT_RPSC_FAIL:
  2770. /* RPSC not supported by rport */
  2771. bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_online);
  2772. break;
  2773. case RPFSM_EVENT_RPSC_ERROR:
  2774. /* need to retry...delayed a bit. */
  2775. if (rpf->rpsc_retries++ < BFA_FCS_RPF_RETRIES) {
  2776. bfa_timer_start(rport->fcs->bfa, &rpf->timer,
  2777. bfa_fcs_rpf_timeout, rpf,
  2778. BFA_FCS_RPF_RETRY_TIMEOUT);
  2779. bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_rpsc_retry);
  2780. } else {
  2781. bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_online);
  2782. }
  2783. break;
  2784. case RPFSM_EVENT_RPORT_OFFLINE:
  2785. bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_offline);
  2786. bfa_fcxp_discard(rpf->fcxp);
  2787. rpf->rpsc_retries = 0;
  2788. break;
  2789. default:
  2790. bfa_sm_fault(rport->fcs, event);
  2791. }
  2792. }
  2793. static void
  2794. bfa_fcs_rpf_sm_rpsc_retry(struct bfa_fcs_rpf_s *rpf, enum rpf_event event)
  2795. {
  2796. struct bfa_fcs_rport_s *rport = rpf->rport;
  2797. bfa_trc(rport->fcs, rport->pid);
  2798. bfa_trc(rport->fcs, event);
  2799. switch (event) {
  2800. case RPFSM_EVENT_TIMEOUT:
  2801. /* re-send the RPSC */
  2802. bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_rpsc_sending);
  2803. bfa_fcs_rpf_send_rpsc2(rpf, NULL);
  2804. break;
  2805. case RPFSM_EVENT_RPORT_OFFLINE:
  2806. bfa_timer_stop(&rpf->timer);
  2807. bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_offline);
  2808. rpf->rpsc_retries = 0;
  2809. break;
  2810. default:
  2811. bfa_sm_fault(rport->fcs, event);
  2812. }
  2813. }
  2814. static void
  2815. bfa_fcs_rpf_sm_online(struct bfa_fcs_rpf_s *rpf, enum rpf_event event)
  2816. {
  2817. struct bfa_fcs_rport_s *rport = rpf->rport;
  2818. bfa_trc(rport->fcs, rport->pwwn);
  2819. bfa_trc(rport->fcs, rport->pid);
  2820. bfa_trc(rport->fcs, event);
  2821. switch (event) {
  2822. case RPFSM_EVENT_RPORT_OFFLINE:
  2823. bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_offline);
  2824. rpf->rpsc_retries = 0;
  2825. break;
  2826. default:
  2827. bfa_sm_fault(rport->fcs, event);
  2828. }
  2829. }
  2830. static void
  2831. bfa_fcs_rpf_sm_offline(struct bfa_fcs_rpf_s *rpf, enum rpf_event event)
  2832. {
  2833. struct bfa_fcs_rport_s *rport = rpf->rport;
  2834. bfa_trc(rport->fcs, rport->pwwn);
  2835. bfa_trc(rport->fcs, rport->pid);
  2836. bfa_trc(rport->fcs, event);
  2837. switch (event) {
  2838. case RPFSM_EVENT_RPORT_ONLINE:
  2839. bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_rpsc_sending);
  2840. bfa_fcs_rpf_send_rpsc2(rpf, NULL);
  2841. break;
  2842. case RPFSM_EVENT_RPORT_OFFLINE:
  2843. break;
  2844. default:
  2845. bfa_sm_fault(rport->fcs, event);
  2846. }
  2847. }
  2848. /*
  2849. * Called when Rport is created.
  2850. */
  2851. void
  2852. bfa_fcs_rpf_init(struct bfa_fcs_rport_s *rport)
  2853. {
  2854. struct bfa_fcs_rpf_s *rpf = &rport->rpf;
  2855. bfa_trc(rport->fcs, rport->pid);
  2856. rpf->rport = rport;
  2857. bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_uninit);
  2858. }
  2859. /*
  2860. * Called when Rport becomes online
  2861. */
  2862. void
  2863. bfa_fcs_rpf_rport_online(struct bfa_fcs_rport_s *rport)
  2864. {
  2865. bfa_trc(rport->fcs, rport->pid);
  2866. if (__fcs_min_cfg(rport->port->fcs))
  2867. return;
  2868. if (bfa_fcs_fabric_is_switched(rport->port->fabric))
  2869. bfa_sm_send_event(&rport->rpf, RPFSM_EVENT_RPORT_ONLINE);
  2870. }
  2871. /*
  2872. * Called when Rport becomes offline
  2873. */
  2874. void
  2875. bfa_fcs_rpf_rport_offline(struct bfa_fcs_rport_s *rport)
  2876. {
  2877. bfa_trc(rport->fcs, rport->pid);
  2878. if (__fcs_min_cfg(rport->port->fcs))
  2879. return;
  2880. rport->rpf.rpsc_speed = 0;
  2881. bfa_sm_send_event(&rport->rpf, RPFSM_EVENT_RPORT_OFFLINE);
  2882. }
  2883. static void
  2884. bfa_fcs_rpf_timeout(void *arg)
  2885. {
  2886. struct bfa_fcs_rpf_s *rpf = (struct bfa_fcs_rpf_s *) arg;
  2887. struct bfa_fcs_rport_s *rport = rpf->rport;
  2888. bfa_trc(rport->fcs, rport->pid);
  2889. bfa_sm_send_event(rpf, RPFSM_EVENT_TIMEOUT);
  2890. }
  2891. static void
  2892. bfa_fcs_rpf_send_rpsc2(void *rpf_cbarg, struct bfa_fcxp_s *fcxp_alloced)
  2893. {
  2894. struct bfa_fcs_rpf_s *rpf = (struct bfa_fcs_rpf_s *)rpf_cbarg;
  2895. struct bfa_fcs_rport_s *rport = rpf->rport;
  2896. struct bfa_fcs_lport_s *port = rport->port;
  2897. struct fchs_s fchs;
  2898. int len;
  2899. struct bfa_fcxp_s *fcxp;
  2900. bfa_trc(rport->fcs, rport->pwwn);
  2901. fcxp = fcxp_alloced ? fcxp_alloced :
  2902. bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
  2903. if (!fcxp) {
  2904. bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &rpf->fcxp_wqe,
  2905. bfa_fcs_rpf_send_rpsc2, rpf, BFA_TRUE);
  2906. return;
  2907. }
  2908. rpf->fcxp = fcxp;
  2909. len = fc_rpsc2_build(&fchs, bfa_fcxp_get_reqbuf(fcxp), rport->pid,
  2910. bfa_fcs_lport_get_fcid(port), &rport->pid, 1);
  2911. bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
  2912. FC_CLASS_3, len, &fchs, bfa_fcs_rpf_rpsc2_response,
  2913. rpf, FC_MAX_PDUSZ, FC_ELS_TOV);
  2914. rport->stats.rpsc_sent++;
  2915. bfa_sm_send_event(rpf, RPFSM_EVENT_FCXP_SENT);
  2916. }
  2917. static void
  2918. bfa_fcs_rpf_rpsc2_response(void *fcsarg, struct bfa_fcxp_s *fcxp, void *cbarg,
  2919. bfa_status_t req_status, u32 rsp_len,
  2920. u32 resid_len, struct fchs_s *rsp_fchs)
  2921. {
  2922. struct bfa_fcs_rpf_s *rpf = (struct bfa_fcs_rpf_s *) cbarg;
  2923. struct bfa_fcs_rport_s *rport = rpf->rport;
  2924. struct fc_ls_rjt_s *ls_rjt;
  2925. struct fc_rpsc2_acc_s *rpsc2_acc;
  2926. u16 num_ents;
  2927. bfa_trc(rport->fcs, req_status);
  2928. if (req_status != BFA_STATUS_OK) {
  2929. bfa_trc(rport->fcs, req_status);
  2930. if (req_status == BFA_STATUS_ETIMER)
  2931. rport->stats.rpsc_failed++;
  2932. bfa_sm_send_event(rpf, RPFSM_EVENT_RPSC_ERROR);
  2933. return;
  2934. }
  2935. rpsc2_acc = (struct fc_rpsc2_acc_s *) BFA_FCXP_RSP_PLD(fcxp);
  2936. if (rpsc2_acc->els_cmd == FC_ELS_ACC) {
  2937. rport->stats.rpsc_accs++;
  2938. num_ents = be16_to_cpu(rpsc2_acc->num_pids);
  2939. bfa_trc(rport->fcs, num_ents);
  2940. if (num_ents > 0) {
  2941. WARN_ON(be32_to_cpu(rpsc2_acc->port_info[0].pid) !=
  2942. bfa_ntoh3b(rport->pid));
  2943. bfa_trc(rport->fcs,
  2944. be32_to_cpu(rpsc2_acc->port_info[0].pid));
  2945. bfa_trc(rport->fcs,
  2946. be16_to_cpu(rpsc2_acc->port_info[0].speed));
  2947. bfa_trc(rport->fcs,
  2948. be16_to_cpu(rpsc2_acc->port_info[0].index));
  2949. bfa_trc(rport->fcs,
  2950. rpsc2_acc->port_info[0].type);
  2951. if (rpsc2_acc->port_info[0].speed == 0) {
  2952. bfa_sm_send_event(rpf, RPFSM_EVENT_RPSC_ERROR);
  2953. return;
  2954. }
  2955. rpf->rpsc_speed = fc_rpsc_operspeed_to_bfa_speed(
  2956. be16_to_cpu(rpsc2_acc->port_info[0].speed));
  2957. bfa_sm_send_event(rpf, RPFSM_EVENT_RPSC_COMP);
  2958. }
  2959. } else {
  2960. ls_rjt = (struct fc_ls_rjt_s *) BFA_FCXP_RSP_PLD(fcxp);
  2961. bfa_trc(rport->fcs, ls_rjt->reason_code);
  2962. bfa_trc(rport->fcs, ls_rjt->reason_code_expl);
  2963. rport->stats.rpsc_rejects++;
  2964. if (ls_rjt->reason_code == FC_LS_RJT_RSN_CMD_NOT_SUPP)
  2965. bfa_sm_send_event(rpf, RPFSM_EVENT_RPSC_FAIL);
  2966. else
  2967. bfa_sm_send_event(rpf, RPFSM_EVENT_RPSC_ERROR);
  2968. }
  2969. }