bfa_fcs_rport.c 88 KB

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