bfa_fcs_rport.c 78 KB

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