bfa_fcs_rport.c 73 KB

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