bfa_fcs_rport.c 75 KB

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