bfa_fcs_rport.c 88 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466
  1. /*
  2. * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
  3. * Copyright (c) 2014- QLogic Corporation.
  4. * All rights reserved
  5. * www.qlogic.com
  6. *
  7. * Linux driver for QLogic BR-series Fibre Channel Host Bus Adapter.
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License (GPL) Version 2 as
  11. * published by the Free Software Foundation
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. */
  18. /*
  19. * rport.c Remote port implementation.
  20. */
  21. #include "bfad_drv.h"
  22. #include "bfad_im.h"
  23. #include "bfa_fcs.h"
  24. #include "bfa_fcbuild.h"
  25. BFA_TRC_FILE(FCS, RPORT);
  26. static u32
  27. bfa_fcs_rport_del_timeout = BFA_FCS_RPORT_DEF_DEL_TIMEOUT * 1000;
  28. /* In millisecs */
  29. /*
  30. * bfa_fcs_rport_max_logins is max count of bfa_fcs_rports
  31. * whereas DEF_CFG_NUM_RPORTS is max count of bfa_rports
  32. */
  33. static u32 bfa_fcs_rport_max_logins = BFA_FCS_MAX_RPORT_LOGINS;
  34. /*
  35. * forward declarations
  36. */
  37. static struct bfa_fcs_rport_s *bfa_fcs_rport_alloc(
  38. struct bfa_fcs_lport_s *port, wwn_t pwwn, u32 rpid);
  39. static void bfa_fcs_rport_free(struct bfa_fcs_rport_s *rport);
  40. static void bfa_fcs_rport_hal_online(struct bfa_fcs_rport_s *rport);
  41. static void bfa_fcs_rport_fcs_online_action(struct bfa_fcs_rport_s *rport);
  42. static void bfa_fcs_rport_hal_online_action(struct bfa_fcs_rport_s *rport);
  43. static void bfa_fcs_rport_fcs_offline_action(struct bfa_fcs_rport_s *rport);
  44. static void bfa_fcs_rport_hal_offline_action(struct bfa_fcs_rport_s *rport);
  45. static void bfa_fcs_rport_update(struct bfa_fcs_rport_s *rport,
  46. struct fc_logi_s *plogi);
  47. static void bfa_fcs_rport_timeout(void *arg);
  48. static void bfa_fcs_rport_send_plogi(void *rport_cbarg,
  49. struct bfa_fcxp_s *fcxp_alloced);
  50. static void bfa_fcs_rport_send_plogiacc(void *rport_cbarg,
  51. struct bfa_fcxp_s *fcxp_alloced);
  52. static void bfa_fcs_rport_plogi_response(void *fcsarg,
  53. struct bfa_fcxp_s *fcxp, void *cbarg,
  54. bfa_status_t req_status, u32 rsp_len,
  55. u32 resid_len, struct fchs_s *rsp_fchs);
  56. static void bfa_fcs_rport_send_adisc(void *rport_cbarg,
  57. struct bfa_fcxp_s *fcxp_alloced);
  58. static void bfa_fcs_rport_adisc_response(void *fcsarg,
  59. struct bfa_fcxp_s *fcxp, void *cbarg,
  60. bfa_status_t req_status, u32 rsp_len,
  61. u32 resid_len, struct fchs_s *rsp_fchs);
  62. static void bfa_fcs_rport_send_nsdisc(void *rport_cbarg,
  63. struct bfa_fcxp_s *fcxp_alloced);
  64. static void bfa_fcs_rport_gidpn_response(void *fcsarg,
  65. struct bfa_fcxp_s *fcxp, void *cbarg,
  66. bfa_status_t req_status, u32 rsp_len,
  67. u32 resid_len, struct fchs_s *rsp_fchs);
  68. static void bfa_fcs_rport_gpnid_response(void *fcsarg,
  69. struct bfa_fcxp_s *fcxp, void *cbarg,
  70. bfa_status_t req_status, u32 rsp_len,
  71. u32 resid_len, struct fchs_s *rsp_fchs);
  72. static void bfa_fcs_rport_send_logo(void *rport_cbarg,
  73. struct bfa_fcxp_s *fcxp_alloced);
  74. static void bfa_fcs_rport_send_logo_acc(void *rport_cbarg);
  75. static void bfa_fcs_rport_process_prli(struct bfa_fcs_rport_s *rport,
  76. struct fchs_s *rx_fchs, u16 len);
  77. static void bfa_fcs_rport_send_ls_rjt(struct bfa_fcs_rport_s *rport,
  78. struct fchs_s *rx_fchs, u8 reason_code,
  79. u8 reason_code_expl);
  80. static void bfa_fcs_rport_process_adisc(struct bfa_fcs_rport_s *rport,
  81. struct fchs_s *rx_fchs, u16 len);
  82. static void bfa_fcs_rport_send_prlo_acc(struct bfa_fcs_rport_s *rport);
  83. static void bfa_fcs_rport_hal_offline(struct bfa_fcs_rport_s *rport);
  84. static void bfa_fcs_rport_sm_uninit(struct bfa_fcs_rport_s *rport,
  85. enum rport_event event);
  86. static void bfa_fcs_rport_sm_plogi_sending(struct bfa_fcs_rport_s *rport,
  87. enum rport_event event);
  88. static void bfa_fcs_rport_sm_plogiacc_sending(struct bfa_fcs_rport_s *rport,
  89. enum rport_event event);
  90. static void bfa_fcs_rport_sm_plogi_retry(struct bfa_fcs_rport_s *rport,
  91. enum rport_event event);
  92. static void bfa_fcs_rport_sm_plogi(struct bfa_fcs_rport_s *rport,
  93. enum rport_event event);
  94. static void bfa_fcs_rport_sm_fc4_fcs_online(struct bfa_fcs_rport_s *rport,
  95. enum rport_event event);
  96. static void bfa_fcs_rport_sm_hal_online(struct bfa_fcs_rport_s *rport,
  97. enum rport_event event);
  98. static void bfa_fcs_rport_sm_online(struct bfa_fcs_rport_s *rport,
  99. enum rport_event event);
  100. static void bfa_fcs_rport_sm_nsquery_sending(struct bfa_fcs_rport_s *rport,
  101. enum rport_event event);
  102. static void bfa_fcs_rport_sm_nsquery(struct bfa_fcs_rport_s *rport,
  103. enum rport_event event);
  104. static void bfa_fcs_rport_sm_adisc_online_sending(
  105. struct bfa_fcs_rport_s *rport, enum rport_event event);
  106. static void bfa_fcs_rport_sm_adisc_online(struct bfa_fcs_rport_s *rport,
  107. enum rport_event event);
  108. static void bfa_fcs_rport_sm_adisc_offline_sending(struct bfa_fcs_rport_s
  109. *rport, enum rport_event event);
  110. static void bfa_fcs_rport_sm_adisc_offline(struct bfa_fcs_rport_s *rport,
  111. enum rport_event event);
  112. static void bfa_fcs_rport_sm_fc4_logorcv(struct bfa_fcs_rport_s *rport,
  113. enum rport_event event);
  114. static void bfa_fcs_rport_sm_fc4_logosend(struct bfa_fcs_rport_s *rport,
  115. enum rport_event event);
  116. static void bfa_fcs_rport_sm_fc4_offline(struct bfa_fcs_rport_s *rport,
  117. enum rport_event event);
  118. static void bfa_fcs_rport_sm_hcb_offline(struct bfa_fcs_rport_s *rport,
  119. enum rport_event event);
  120. static void bfa_fcs_rport_sm_hcb_logorcv(struct bfa_fcs_rport_s *rport,
  121. enum rport_event event);
  122. static void bfa_fcs_rport_sm_hcb_logosend(struct bfa_fcs_rport_s *rport,
  123. enum rport_event event);
  124. static void bfa_fcs_rport_sm_logo_sending(struct bfa_fcs_rport_s *rport,
  125. enum rport_event event);
  126. static void bfa_fcs_rport_sm_offline(struct bfa_fcs_rport_s *rport,
  127. enum rport_event event);
  128. static void bfa_fcs_rport_sm_nsdisc_sending(struct bfa_fcs_rport_s *rport,
  129. enum rport_event event);
  130. static void bfa_fcs_rport_sm_nsdisc_retry(struct bfa_fcs_rport_s *rport,
  131. enum rport_event event);
  132. static void bfa_fcs_rport_sm_nsdisc_sent(struct bfa_fcs_rport_s *rport,
  133. enum rport_event event);
  134. static void bfa_fcs_rport_sm_nsdisc_sent(struct bfa_fcs_rport_s *rport,
  135. enum rport_event event);
  136. static void bfa_fcs_rport_sm_fc4_off_delete(struct bfa_fcs_rport_s *rport,
  137. enum rport_event event);
  138. static void bfa_fcs_rport_sm_delete_pending(struct bfa_fcs_rport_s *rport,
  139. enum rport_event event);
  140. static struct bfa_sm_table_s rport_sm_table[] = {
  141. {BFA_SM(bfa_fcs_rport_sm_uninit), BFA_RPORT_UNINIT},
  142. {BFA_SM(bfa_fcs_rport_sm_plogi_sending), BFA_RPORT_PLOGI},
  143. {BFA_SM(bfa_fcs_rport_sm_plogiacc_sending), BFA_RPORT_ONLINE},
  144. {BFA_SM(bfa_fcs_rport_sm_plogi_retry), BFA_RPORT_PLOGI_RETRY},
  145. {BFA_SM(bfa_fcs_rport_sm_plogi), BFA_RPORT_PLOGI},
  146. {BFA_SM(bfa_fcs_rport_sm_fc4_fcs_online), BFA_RPORT_ONLINE},
  147. {BFA_SM(bfa_fcs_rport_sm_hal_online), BFA_RPORT_ONLINE},
  148. {BFA_SM(bfa_fcs_rport_sm_online), BFA_RPORT_ONLINE},
  149. {BFA_SM(bfa_fcs_rport_sm_nsquery_sending), BFA_RPORT_NSQUERY},
  150. {BFA_SM(bfa_fcs_rport_sm_nsquery), BFA_RPORT_NSQUERY},
  151. {BFA_SM(bfa_fcs_rport_sm_adisc_online_sending), BFA_RPORT_ADISC},
  152. {BFA_SM(bfa_fcs_rport_sm_adisc_online), BFA_RPORT_ADISC},
  153. {BFA_SM(bfa_fcs_rport_sm_adisc_offline_sending), BFA_RPORT_ADISC},
  154. {BFA_SM(bfa_fcs_rport_sm_adisc_offline), BFA_RPORT_ADISC},
  155. {BFA_SM(bfa_fcs_rport_sm_fc4_logorcv), BFA_RPORT_LOGORCV},
  156. {BFA_SM(bfa_fcs_rport_sm_fc4_logosend), BFA_RPORT_LOGO},
  157. {BFA_SM(bfa_fcs_rport_sm_fc4_offline), BFA_RPORT_OFFLINE},
  158. {BFA_SM(bfa_fcs_rport_sm_hcb_offline), BFA_RPORT_OFFLINE},
  159. {BFA_SM(bfa_fcs_rport_sm_hcb_logorcv), BFA_RPORT_LOGORCV},
  160. {BFA_SM(bfa_fcs_rport_sm_hcb_logosend), BFA_RPORT_LOGO},
  161. {BFA_SM(bfa_fcs_rport_sm_logo_sending), BFA_RPORT_LOGO},
  162. {BFA_SM(bfa_fcs_rport_sm_offline), BFA_RPORT_OFFLINE},
  163. {BFA_SM(bfa_fcs_rport_sm_nsdisc_sending), BFA_RPORT_NSDISC},
  164. {BFA_SM(bfa_fcs_rport_sm_nsdisc_retry), BFA_RPORT_NSDISC},
  165. {BFA_SM(bfa_fcs_rport_sm_nsdisc_sent), BFA_RPORT_NSDISC},
  166. };
  167. /*
  168. * Beginning state.
  169. */
  170. static void
  171. bfa_fcs_rport_sm_uninit(struct bfa_fcs_rport_s *rport, enum rport_event event)
  172. {
  173. bfa_trc(rport->fcs, rport->pwwn);
  174. bfa_trc(rport->fcs, rport->pid);
  175. bfa_trc(rport->fcs, event);
  176. switch (event) {
  177. case RPSM_EVENT_PLOGI_SEND:
  178. bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogi_sending);
  179. rport->plogi_retries = 0;
  180. bfa_fcs_rport_send_plogi(rport, NULL);
  181. break;
  182. case RPSM_EVENT_PLOGI_RCVD:
  183. bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogiacc_sending);
  184. bfa_fcs_rport_send_plogiacc(rport, NULL);
  185. break;
  186. case RPSM_EVENT_PLOGI_COMP:
  187. bfa_sm_set_state(rport, bfa_fcs_rport_sm_hal_online);
  188. bfa_fcs_rport_hal_online(rport);
  189. break;
  190. case RPSM_EVENT_ADDRESS_CHANGE:
  191. case RPSM_EVENT_ADDRESS_DISC:
  192. bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sending);
  193. rport->ns_retries = 0;
  194. bfa_fcs_rport_send_nsdisc(rport, NULL);
  195. break;
  196. default:
  197. bfa_sm_fault(rport->fcs, event);
  198. }
  199. }
  200. /*
  201. * PLOGI is being sent.
  202. */
  203. static void
  204. bfa_fcs_rport_sm_plogi_sending(struct bfa_fcs_rport_s *rport,
  205. enum rport_event event)
  206. {
  207. bfa_trc(rport->fcs, rport->pwwn);
  208. bfa_trc(rport->fcs, rport->pid);
  209. bfa_trc(rport->fcs, event);
  210. switch (event) {
  211. case RPSM_EVENT_FCXP_SENT:
  212. bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogi);
  213. break;
  214. case RPSM_EVENT_DELETE:
  215. bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
  216. bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  217. bfa_fcs_rport_free(rport);
  218. break;
  219. case RPSM_EVENT_PLOGI_RCVD:
  220. bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogiacc_sending);
  221. bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  222. bfa_fcs_rport_send_plogiacc(rport, NULL);
  223. break;
  224. case RPSM_EVENT_SCN_OFFLINE:
  225. bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
  226. bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  227. bfa_timer_start(rport->fcs->bfa, &rport->timer,
  228. bfa_fcs_rport_timeout, rport,
  229. bfa_fcs_rport_del_timeout);
  230. break;
  231. case RPSM_EVENT_ADDRESS_CHANGE:
  232. case RPSM_EVENT_FAB_SCN:
  233. /* query the NS */
  234. bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  235. WARN_ON(!(bfa_fcport_get_topology(rport->port->fcs->bfa) !=
  236. BFA_PORT_TOPOLOGY_LOOP));
  237. bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sending);
  238. rport->ns_retries = 0;
  239. bfa_fcs_rport_send_nsdisc(rport, NULL);
  240. break;
  241. case RPSM_EVENT_LOGO_IMP:
  242. rport->pid = 0;
  243. bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
  244. bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  245. bfa_timer_start(rport->fcs->bfa, &rport->timer,
  246. bfa_fcs_rport_timeout, rport,
  247. bfa_fcs_rport_del_timeout);
  248. break;
  249. default:
  250. bfa_sm_fault(rport->fcs, event);
  251. }
  252. }
  253. /*
  254. * PLOGI is being sent.
  255. */
  256. static void
  257. bfa_fcs_rport_sm_plogiacc_sending(struct bfa_fcs_rport_s *rport,
  258. enum rport_event event)
  259. {
  260. bfa_trc(rport->fcs, rport->pwwn);
  261. bfa_trc(rport->fcs, rport->pid);
  262. bfa_trc(rport->fcs, event);
  263. switch (event) {
  264. case RPSM_EVENT_FCXP_SENT:
  265. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_fcs_online);
  266. bfa_fcs_rport_fcs_online_action(rport);
  267. break;
  268. case RPSM_EVENT_DELETE:
  269. bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
  270. bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  271. bfa_fcs_rport_free(rport);
  272. break;
  273. case RPSM_EVENT_PLOGI_RCVD:
  274. case RPSM_EVENT_PLOGI_COMP:
  275. case RPSM_EVENT_FAB_SCN:
  276. /*
  277. * Ignore, SCN is possibly online notification.
  278. */
  279. break;
  280. case RPSM_EVENT_SCN_OFFLINE:
  281. bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
  282. bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  283. bfa_timer_start(rport->fcs->bfa, &rport->timer,
  284. bfa_fcs_rport_timeout, rport,
  285. bfa_fcs_rport_del_timeout);
  286. break;
  287. case RPSM_EVENT_ADDRESS_CHANGE:
  288. bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  289. bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sending);
  290. rport->ns_retries = 0;
  291. bfa_fcs_rport_send_nsdisc(rport, NULL);
  292. break;
  293. case RPSM_EVENT_LOGO_IMP:
  294. rport->pid = 0;
  295. bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
  296. bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  297. bfa_timer_start(rport->fcs->bfa, &rport->timer,
  298. bfa_fcs_rport_timeout, rport,
  299. bfa_fcs_rport_del_timeout);
  300. break;
  301. case RPSM_EVENT_HCB_OFFLINE:
  302. /*
  303. * Ignore BFA callback, on a PLOGI receive we call bfa offline.
  304. */
  305. break;
  306. default:
  307. bfa_sm_fault(rport->fcs, event);
  308. }
  309. }
  310. /*
  311. * PLOGI is sent.
  312. */
  313. static void
  314. bfa_fcs_rport_sm_plogi_retry(struct bfa_fcs_rport_s *rport,
  315. enum rport_event event)
  316. {
  317. bfa_trc(rport->fcs, rport->pwwn);
  318. bfa_trc(rport->fcs, rport->pid);
  319. bfa_trc(rport->fcs, event);
  320. switch (event) {
  321. case RPSM_EVENT_TIMEOUT:
  322. bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogi_sending);
  323. bfa_fcs_rport_send_plogi(rport, NULL);
  324. break;
  325. case RPSM_EVENT_DELETE:
  326. bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
  327. bfa_timer_stop(&rport->timer);
  328. bfa_fcs_rport_free(rport);
  329. break;
  330. case RPSM_EVENT_PRLO_RCVD:
  331. case RPSM_EVENT_LOGO_RCVD:
  332. break;
  333. case RPSM_EVENT_PLOGI_RCVD:
  334. bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogiacc_sending);
  335. bfa_timer_stop(&rport->timer);
  336. bfa_fcs_rport_send_plogiacc(rport, NULL);
  337. break;
  338. case RPSM_EVENT_SCN_OFFLINE:
  339. bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
  340. bfa_timer_stop(&rport->timer);
  341. bfa_timer_start(rport->fcs->bfa, &rport->timer,
  342. bfa_fcs_rport_timeout, rport,
  343. bfa_fcs_rport_del_timeout);
  344. break;
  345. case RPSM_EVENT_ADDRESS_CHANGE:
  346. case RPSM_EVENT_FAB_SCN:
  347. bfa_timer_stop(&rport->timer);
  348. WARN_ON(!(bfa_fcport_get_topology(rport->port->fcs->bfa) !=
  349. BFA_PORT_TOPOLOGY_LOOP));
  350. bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sending);
  351. rport->ns_retries = 0;
  352. bfa_fcs_rport_send_nsdisc(rport, NULL);
  353. break;
  354. case RPSM_EVENT_LOGO_IMP:
  355. rport->pid = 0;
  356. bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
  357. bfa_timer_stop(&rport->timer);
  358. bfa_timer_start(rport->fcs->bfa, &rport->timer,
  359. bfa_fcs_rport_timeout, rport,
  360. bfa_fcs_rport_del_timeout);
  361. break;
  362. case RPSM_EVENT_PLOGI_COMP:
  363. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_fcs_online);
  364. bfa_timer_stop(&rport->timer);
  365. bfa_fcs_rport_fcs_online_action(rport);
  366. break;
  367. default:
  368. bfa_sm_fault(rport->fcs, event);
  369. }
  370. }
  371. /*
  372. * PLOGI is sent.
  373. */
  374. static void
  375. bfa_fcs_rport_sm_plogi(struct bfa_fcs_rport_s *rport, enum rport_event event)
  376. {
  377. bfa_trc(rport->fcs, rport->pwwn);
  378. bfa_trc(rport->fcs, rport->pid);
  379. bfa_trc(rport->fcs, event);
  380. switch (event) {
  381. case RPSM_EVENT_ACCEPTED:
  382. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_fcs_online);
  383. rport->plogi_retries = 0;
  384. bfa_fcs_rport_fcs_online_action(rport);
  385. break;
  386. case RPSM_EVENT_LOGO_RCVD:
  387. bfa_fcs_rport_send_logo_acc(rport);
  388. /*
  389. * !! fall through !!
  390. */
  391. case RPSM_EVENT_PRLO_RCVD:
  392. if (rport->prlo == BFA_TRUE)
  393. bfa_fcs_rport_send_prlo_acc(rport);
  394. bfa_fcxp_discard(rport->fcxp);
  395. /*
  396. * !! fall through !!
  397. */
  398. case RPSM_EVENT_FAILED:
  399. if (rport->plogi_retries < BFA_FCS_RPORT_MAX_RETRIES) {
  400. rport->plogi_retries++;
  401. bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogi_retry);
  402. bfa_timer_start(rport->fcs->bfa, &rport->timer,
  403. bfa_fcs_rport_timeout, rport,
  404. BFA_FCS_RETRY_TIMEOUT);
  405. } else {
  406. bfa_stats(rport->port, rport_del_max_plogi_retry);
  407. rport->old_pid = rport->pid;
  408. rport->pid = 0;
  409. bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
  410. bfa_timer_start(rport->fcs->bfa, &rport->timer,
  411. bfa_fcs_rport_timeout, rport,
  412. bfa_fcs_rport_del_timeout);
  413. }
  414. break;
  415. case RPSM_EVENT_SCN_ONLINE:
  416. break;
  417. case RPSM_EVENT_SCN_OFFLINE:
  418. bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
  419. bfa_fcxp_discard(rport->fcxp);
  420. bfa_timer_start(rport->fcs->bfa, &rport->timer,
  421. bfa_fcs_rport_timeout, rport,
  422. bfa_fcs_rport_del_timeout);
  423. break;
  424. case RPSM_EVENT_PLOGI_RETRY:
  425. rport->plogi_retries = 0;
  426. bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogi_retry);
  427. bfa_timer_start(rport->fcs->bfa, &rport->timer,
  428. bfa_fcs_rport_timeout, rport,
  429. (FC_RA_TOV * 1000));
  430. break;
  431. case RPSM_EVENT_LOGO_IMP:
  432. rport->pid = 0;
  433. bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
  434. bfa_fcxp_discard(rport->fcxp);
  435. bfa_timer_start(rport->fcs->bfa, &rport->timer,
  436. bfa_fcs_rport_timeout, rport,
  437. bfa_fcs_rport_del_timeout);
  438. break;
  439. case RPSM_EVENT_ADDRESS_CHANGE:
  440. case RPSM_EVENT_FAB_SCN:
  441. bfa_fcxp_discard(rport->fcxp);
  442. WARN_ON(!(bfa_fcport_get_topology(rport->port->fcs->bfa) !=
  443. BFA_PORT_TOPOLOGY_LOOP));
  444. bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sending);
  445. rport->ns_retries = 0;
  446. bfa_fcs_rport_send_nsdisc(rport, NULL);
  447. break;
  448. case RPSM_EVENT_PLOGI_RCVD:
  449. bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogiacc_sending);
  450. bfa_fcxp_discard(rport->fcxp);
  451. bfa_fcs_rport_send_plogiacc(rport, NULL);
  452. break;
  453. case RPSM_EVENT_DELETE:
  454. bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
  455. bfa_fcxp_discard(rport->fcxp);
  456. bfa_fcs_rport_free(rport);
  457. break;
  458. case RPSM_EVENT_PLOGI_COMP:
  459. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_fcs_online);
  460. bfa_fcxp_discard(rport->fcxp);
  461. bfa_fcs_rport_fcs_online_action(rport);
  462. break;
  463. default:
  464. bfa_sm_fault(rport->fcs, event);
  465. }
  466. }
  467. /*
  468. * PLOGI is done. Await bfa_fcs_itnim to ascertain the scsi function
  469. */
  470. static void
  471. bfa_fcs_rport_sm_fc4_fcs_online(struct bfa_fcs_rport_s *rport,
  472. enum rport_event event)
  473. {
  474. bfa_trc(rport->fcs, rport->pwwn);
  475. bfa_trc(rport->fcs, rport->pid);
  476. bfa_trc(rport->fcs, event);
  477. switch (event) {
  478. case RPSM_EVENT_FC4_FCS_ONLINE:
  479. if (rport->scsi_function == BFA_RPORT_INITIATOR) {
  480. if (!BFA_FCS_PID_IS_WKA(rport->pid))
  481. bfa_fcs_rpf_rport_online(rport);
  482. bfa_sm_set_state(rport, bfa_fcs_rport_sm_online);
  483. break;
  484. }
  485. if (!rport->bfa_rport)
  486. rport->bfa_rport =
  487. bfa_rport_create(rport->fcs->bfa, rport);
  488. if (rport->bfa_rport) {
  489. bfa_sm_set_state(rport, bfa_fcs_rport_sm_hal_online);
  490. bfa_fcs_rport_hal_online(rport);
  491. } else {
  492. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logosend);
  493. bfa_fcs_rport_fcs_offline_action(rport);
  494. }
  495. break;
  496. case RPSM_EVENT_PLOGI_RCVD:
  497. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
  498. rport->plogi_pending = BFA_TRUE;
  499. bfa_fcs_rport_fcs_offline_action(rport);
  500. break;
  501. case RPSM_EVENT_PLOGI_COMP:
  502. case RPSM_EVENT_LOGO_IMP:
  503. case RPSM_EVENT_ADDRESS_CHANGE:
  504. case RPSM_EVENT_FAB_SCN:
  505. case RPSM_EVENT_SCN_OFFLINE:
  506. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
  507. bfa_fcs_rport_fcs_offline_action(rport);
  508. break;
  509. case RPSM_EVENT_LOGO_RCVD:
  510. case RPSM_EVENT_PRLO_RCVD:
  511. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logorcv);
  512. bfa_fcs_rport_fcs_offline_action(rport);
  513. break;
  514. case RPSM_EVENT_DELETE:
  515. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logosend);
  516. bfa_fcs_rport_fcs_offline_action(rport);
  517. break;
  518. default:
  519. bfa_sm_fault(rport->fcs, event);
  520. break;
  521. }
  522. }
  523. /*
  524. * PLOGI is complete. Awaiting BFA rport online callback. FC-4s
  525. * are offline.
  526. */
  527. static void
  528. bfa_fcs_rport_sm_hal_online(struct bfa_fcs_rport_s *rport,
  529. enum rport_event event)
  530. {
  531. bfa_trc(rport->fcs, rport->pwwn);
  532. bfa_trc(rport->fcs, rport->pid);
  533. bfa_trc(rport->fcs, event);
  534. switch (event) {
  535. case RPSM_EVENT_HCB_ONLINE:
  536. bfa_sm_set_state(rport, bfa_fcs_rport_sm_online);
  537. bfa_fcs_rport_hal_online_action(rport);
  538. break;
  539. case RPSM_EVENT_PLOGI_COMP:
  540. break;
  541. case RPSM_EVENT_PRLO_RCVD:
  542. case RPSM_EVENT_LOGO_RCVD:
  543. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logorcv);
  544. bfa_fcs_rport_fcs_offline_action(rport);
  545. break;
  546. case RPSM_EVENT_FAB_SCN:
  547. case RPSM_EVENT_LOGO_IMP:
  548. case RPSM_EVENT_ADDRESS_CHANGE:
  549. case RPSM_EVENT_SCN_OFFLINE:
  550. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
  551. bfa_fcs_rport_fcs_offline_action(rport);
  552. break;
  553. case RPSM_EVENT_PLOGI_RCVD:
  554. rport->plogi_pending = BFA_TRUE;
  555. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
  556. bfa_fcs_rport_fcs_offline_action(rport);
  557. break;
  558. case RPSM_EVENT_DELETE:
  559. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logosend);
  560. bfa_fcs_rport_fcs_offline_action(rport);
  561. break;
  562. default:
  563. bfa_sm_fault(rport->fcs, event);
  564. }
  565. }
  566. /*
  567. * Rport is ONLINE. FC-4s active.
  568. */
  569. static void
  570. bfa_fcs_rport_sm_online(struct bfa_fcs_rport_s *rport, enum rport_event event)
  571. {
  572. bfa_trc(rport->fcs, rport->pwwn);
  573. bfa_trc(rport->fcs, rport->pid);
  574. bfa_trc(rport->fcs, event);
  575. switch (event) {
  576. case RPSM_EVENT_FAB_SCN:
  577. if (bfa_fcs_fabric_is_switched(rport->port->fabric)) {
  578. bfa_sm_set_state(rport,
  579. bfa_fcs_rport_sm_nsquery_sending);
  580. rport->ns_retries = 0;
  581. bfa_fcs_rport_send_nsdisc(rport, NULL);
  582. } else {
  583. bfa_sm_set_state(rport,
  584. bfa_fcs_rport_sm_adisc_online_sending);
  585. bfa_fcs_rport_send_adisc(rport, NULL);
  586. }
  587. break;
  588. case RPSM_EVENT_PLOGI_RCVD:
  589. case RPSM_EVENT_LOGO_IMP:
  590. case RPSM_EVENT_ADDRESS_CHANGE:
  591. case RPSM_EVENT_SCN_OFFLINE:
  592. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
  593. bfa_fcs_rport_hal_offline_action(rport);
  594. break;
  595. case RPSM_EVENT_DELETE:
  596. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logosend);
  597. bfa_fcs_rport_hal_offline_action(rport);
  598. break;
  599. case RPSM_EVENT_LOGO_RCVD:
  600. case RPSM_EVENT_PRLO_RCVD:
  601. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logorcv);
  602. bfa_fcs_rport_hal_offline_action(rport);
  603. break;
  604. case RPSM_EVENT_SCN_ONLINE:
  605. case RPSM_EVENT_PLOGI_COMP:
  606. break;
  607. default:
  608. bfa_sm_fault(rport->fcs, event);
  609. }
  610. }
  611. /*
  612. * An SCN event is received in ONLINE state. NS query is being sent
  613. * prior to ADISC authentication with rport. FC-4s are paused.
  614. */
  615. static void
  616. bfa_fcs_rport_sm_nsquery_sending(struct bfa_fcs_rport_s *rport,
  617. enum rport_event event)
  618. {
  619. bfa_trc(rport->fcs, rport->pwwn);
  620. bfa_trc(rport->fcs, rport->pid);
  621. bfa_trc(rport->fcs, event);
  622. switch (event) {
  623. case RPSM_EVENT_FCXP_SENT:
  624. bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsquery);
  625. break;
  626. case RPSM_EVENT_DELETE:
  627. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logosend);
  628. bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  629. bfa_fcs_rport_hal_offline_action(rport);
  630. break;
  631. case RPSM_EVENT_FAB_SCN:
  632. /*
  633. * ignore SCN, wait for response to query itself
  634. */
  635. break;
  636. case RPSM_EVENT_LOGO_RCVD:
  637. case RPSM_EVENT_PRLO_RCVD:
  638. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logorcv);
  639. bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  640. bfa_fcs_rport_hal_offline_action(rport);
  641. break;
  642. case RPSM_EVENT_LOGO_IMP:
  643. case RPSM_EVENT_PLOGI_RCVD:
  644. case RPSM_EVENT_ADDRESS_CHANGE:
  645. case RPSM_EVENT_PLOGI_COMP:
  646. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
  647. bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  648. bfa_fcs_rport_hal_offline_action(rport);
  649. break;
  650. default:
  651. bfa_sm_fault(rport->fcs, event);
  652. }
  653. }
  654. /*
  655. * An SCN event is received in ONLINE state. NS query is sent to rport.
  656. * FC-4s are paused.
  657. */
  658. static void
  659. bfa_fcs_rport_sm_nsquery(struct bfa_fcs_rport_s *rport, enum rport_event event)
  660. {
  661. bfa_trc(rport->fcs, rport->pwwn);
  662. bfa_trc(rport->fcs, rport->pid);
  663. bfa_trc(rport->fcs, event);
  664. switch (event) {
  665. case RPSM_EVENT_ACCEPTED:
  666. bfa_sm_set_state(rport, bfa_fcs_rport_sm_adisc_online_sending);
  667. bfa_fcs_rport_send_adisc(rport, NULL);
  668. break;
  669. case RPSM_EVENT_FAILED:
  670. rport->ns_retries++;
  671. if (rport->ns_retries < BFA_FCS_RPORT_MAX_RETRIES) {
  672. bfa_sm_set_state(rport,
  673. bfa_fcs_rport_sm_nsquery_sending);
  674. bfa_fcs_rport_send_nsdisc(rport, NULL);
  675. } else {
  676. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
  677. bfa_fcs_rport_hal_offline_action(rport);
  678. }
  679. break;
  680. case RPSM_EVENT_DELETE:
  681. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logosend);
  682. bfa_fcxp_discard(rport->fcxp);
  683. bfa_fcs_rport_hal_offline_action(rport);
  684. break;
  685. case RPSM_EVENT_FAB_SCN:
  686. break;
  687. case RPSM_EVENT_LOGO_RCVD:
  688. case RPSM_EVENT_PRLO_RCVD:
  689. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logorcv);
  690. bfa_fcxp_discard(rport->fcxp);
  691. bfa_fcs_rport_hal_offline_action(rport);
  692. break;
  693. case RPSM_EVENT_PLOGI_COMP:
  694. case RPSM_EVENT_ADDRESS_CHANGE:
  695. case RPSM_EVENT_PLOGI_RCVD:
  696. case RPSM_EVENT_LOGO_IMP:
  697. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
  698. bfa_fcxp_discard(rport->fcxp);
  699. bfa_fcs_rport_hal_offline_action(rport);
  700. break;
  701. default:
  702. bfa_sm_fault(rport->fcs, event);
  703. }
  704. }
  705. /*
  706. * An SCN event is received in ONLINE state. ADISC is being sent for
  707. * authenticating with rport. FC-4s are paused.
  708. */
  709. static void
  710. bfa_fcs_rport_sm_adisc_online_sending(struct bfa_fcs_rport_s *rport,
  711. enum rport_event event)
  712. {
  713. bfa_trc(rport->fcs, rport->pwwn);
  714. bfa_trc(rport->fcs, rport->pid);
  715. bfa_trc(rport->fcs, event);
  716. switch (event) {
  717. case RPSM_EVENT_FCXP_SENT:
  718. bfa_sm_set_state(rport, bfa_fcs_rport_sm_adisc_online);
  719. break;
  720. case RPSM_EVENT_DELETE:
  721. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logosend);
  722. bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  723. bfa_fcs_rport_hal_offline_action(rport);
  724. break;
  725. case RPSM_EVENT_LOGO_IMP:
  726. case RPSM_EVENT_ADDRESS_CHANGE:
  727. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
  728. bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  729. bfa_fcs_rport_hal_offline_action(rport);
  730. break;
  731. case RPSM_EVENT_LOGO_RCVD:
  732. case RPSM_EVENT_PRLO_RCVD:
  733. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logorcv);
  734. bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  735. bfa_fcs_rport_hal_offline_action(rport);
  736. break;
  737. case RPSM_EVENT_FAB_SCN:
  738. break;
  739. case RPSM_EVENT_PLOGI_RCVD:
  740. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
  741. bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  742. bfa_fcs_rport_hal_offline_action(rport);
  743. break;
  744. default:
  745. bfa_sm_fault(rport->fcs, event);
  746. }
  747. }
  748. /*
  749. * An SCN event is received in ONLINE state. ADISC is to rport.
  750. * FC-4s are paused.
  751. */
  752. static void
  753. bfa_fcs_rport_sm_adisc_online(struct bfa_fcs_rport_s *rport,
  754. enum rport_event event)
  755. {
  756. bfa_trc(rport->fcs, rport->pwwn);
  757. bfa_trc(rport->fcs, rport->pid);
  758. bfa_trc(rport->fcs, event);
  759. switch (event) {
  760. case RPSM_EVENT_ACCEPTED:
  761. bfa_sm_set_state(rport, bfa_fcs_rport_sm_online);
  762. break;
  763. case RPSM_EVENT_PLOGI_RCVD:
  764. /*
  765. * Too complex to cleanup FC-4 & rport and then acc to PLOGI.
  766. * At least go offline when a PLOGI is received.
  767. */
  768. bfa_fcxp_discard(rport->fcxp);
  769. /*
  770. * !!! fall through !!!
  771. */
  772. case RPSM_EVENT_FAILED:
  773. case RPSM_EVENT_ADDRESS_CHANGE:
  774. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
  775. bfa_fcs_rport_hal_offline_action(rport);
  776. break;
  777. case RPSM_EVENT_DELETE:
  778. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logosend);
  779. bfa_fcxp_discard(rport->fcxp);
  780. bfa_fcs_rport_hal_offline_action(rport);
  781. break;
  782. case RPSM_EVENT_FAB_SCN:
  783. /*
  784. * already processing RSCN
  785. */
  786. break;
  787. case RPSM_EVENT_LOGO_IMP:
  788. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
  789. bfa_fcxp_discard(rport->fcxp);
  790. bfa_fcs_rport_hal_offline_action(rport);
  791. break;
  792. case RPSM_EVENT_LOGO_RCVD:
  793. case RPSM_EVENT_PRLO_RCVD:
  794. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logorcv);
  795. bfa_fcxp_discard(rport->fcxp);
  796. bfa_fcs_rport_hal_offline_action(rport);
  797. break;
  798. default:
  799. bfa_sm_fault(rport->fcs, event);
  800. }
  801. }
  802. /*
  803. * ADISC is being sent for authenticating with rport
  804. * Already did offline actions.
  805. */
  806. static void
  807. bfa_fcs_rport_sm_adisc_offline_sending(struct bfa_fcs_rport_s *rport,
  808. enum rport_event event)
  809. {
  810. bfa_trc(rport->fcs, rport->pwwn);
  811. bfa_trc(rport->fcs, rport->pid);
  812. bfa_trc(rport->fcs, event);
  813. switch (event) {
  814. case RPSM_EVENT_FCXP_SENT:
  815. bfa_sm_set_state(rport, bfa_fcs_rport_sm_adisc_offline);
  816. break;
  817. case RPSM_EVENT_DELETE:
  818. case RPSM_EVENT_SCN_OFFLINE:
  819. case RPSM_EVENT_LOGO_IMP:
  820. case RPSM_EVENT_LOGO_RCVD:
  821. case RPSM_EVENT_PRLO_RCVD:
  822. bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
  823. bfa_fcxp_walloc_cancel(rport->fcs->bfa,
  824. &rport->fcxp_wqe);
  825. bfa_timer_start(rport->fcs->bfa, &rport->timer,
  826. bfa_fcs_rport_timeout, rport,
  827. bfa_fcs_rport_del_timeout);
  828. break;
  829. case RPSM_EVENT_PLOGI_RCVD:
  830. bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogiacc_sending);
  831. bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  832. bfa_fcs_rport_send_plogiacc(rport, NULL);
  833. break;
  834. default:
  835. bfa_sm_fault(rport->fcs, event);
  836. }
  837. }
  838. /*
  839. * ADISC to rport
  840. * Already did offline actions
  841. */
  842. static void
  843. bfa_fcs_rport_sm_adisc_offline(struct bfa_fcs_rport_s *rport,
  844. enum rport_event event)
  845. {
  846. bfa_trc(rport->fcs, rport->pwwn);
  847. bfa_trc(rport->fcs, rport->pid);
  848. bfa_trc(rport->fcs, event);
  849. switch (event) {
  850. case RPSM_EVENT_ACCEPTED:
  851. bfa_sm_set_state(rport, bfa_fcs_rport_sm_hal_online);
  852. bfa_fcs_rport_hal_online(rport);
  853. break;
  854. case RPSM_EVENT_PLOGI_RCVD:
  855. bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogiacc_sending);
  856. bfa_fcxp_discard(rport->fcxp);
  857. bfa_fcs_rport_send_plogiacc(rport, NULL);
  858. break;
  859. case RPSM_EVENT_FAILED:
  860. bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
  861. bfa_timer_start(rport->fcs->bfa, &rport->timer,
  862. bfa_fcs_rport_timeout, rport,
  863. bfa_fcs_rport_del_timeout);
  864. break;
  865. case RPSM_EVENT_DELETE:
  866. case RPSM_EVENT_SCN_OFFLINE:
  867. case RPSM_EVENT_LOGO_IMP:
  868. case RPSM_EVENT_LOGO_RCVD:
  869. case RPSM_EVENT_PRLO_RCVD:
  870. bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
  871. bfa_fcxp_discard(rport->fcxp);
  872. bfa_timer_start(rport->fcs->bfa, &rport->timer,
  873. bfa_fcs_rport_timeout, rport,
  874. bfa_fcs_rport_del_timeout);
  875. break;
  876. default:
  877. bfa_sm_fault(rport->fcs, event);
  878. }
  879. }
  880. /*
  881. * Rport has sent LOGO. Awaiting FC-4 offline completion callback.
  882. */
  883. static void
  884. bfa_fcs_rport_sm_fc4_logorcv(struct bfa_fcs_rport_s *rport,
  885. enum rport_event event)
  886. {
  887. bfa_trc(rport->fcs, rport->pwwn);
  888. bfa_trc(rport->fcs, rport->pid);
  889. bfa_trc(rport->fcs, event);
  890. switch (event) {
  891. case RPSM_EVENT_FC4_OFFLINE:
  892. bfa_sm_set_state(rport, bfa_fcs_rport_sm_hcb_logorcv);
  893. bfa_fcs_rport_hal_offline(rport);
  894. break;
  895. case RPSM_EVENT_DELETE:
  896. if (rport->pid && (rport->prlo == BFA_TRUE))
  897. bfa_fcs_rport_send_prlo_acc(rport);
  898. if (rport->pid && (rport->prlo == BFA_FALSE))
  899. bfa_fcs_rport_send_logo_acc(rport);
  900. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_off_delete);
  901. break;
  902. case RPSM_EVENT_SCN_ONLINE:
  903. case RPSM_EVENT_SCN_OFFLINE:
  904. case RPSM_EVENT_HCB_ONLINE:
  905. case RPSM_EVENT_LOGO_RCVD:
  906. case RPSM_EVENT_PRLO_RCVD:
  907. case RPSM_EVENT_ADDRESS_CHANGE:
  908. break;
  909. default:
  910. bfa_sm_fault(rport->fcs, event);
  911. }
  912. }
  913. /*
  914. * LOGO needs to be sent to rport. Awaiting FC-4 offline completion
  915. * callback.
  916. */
  917. static void
  918. bfa_fcs_rport_sm_fc4_logosend(struct bfa_fcs_rport_s *rport,
  919. enum rport_event event)
  920. {
  921. bfa_trc(rport->fcs, rport->pwwn);
  922. bfa_trc(rport->fcs, rport->pid);
  923. bfa_trc(rport->fcs, event);
  924. switch (event) {
  925. case RPSM_EVENT_FC4_OFFLINE:
  926. bfa_sm_set_state(rport, bfa_fcs_rport_sm_hcb_logosend);
  927. bfa_fcs_rport_hal_offline(rport);
  928. break;
  929. case RPSM_EVENT_LOGO_RCVD:
  930. bfa_fcs_rport_send_logo_acc(rport);
  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. /*
  1009. * !! fall through !!
  1010. */
  1011. case RPSM_EVENT_ADDRESS_CHANGE:
  1012. if (!bfa_fcs_lport_is_online(rport->port)) {
  1013. rport->pid = 0;
  1014. bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
  1015. bfa_timer_start(rport->fcs->bfa, &rport->timer,
  1016. bfa_fcs_rport_timeout, rport,
  1017. bfa_fcs_rport_del_timeout);
  1018. break;
  1019. }
  1020. if (bfa_fcs_fabric_is_switched(rport->port->fabric)) {
  1021. bfa_sm_set_state(rport,
  1022. bfa_fcs_rport_sm_nsdisc_sending);
  1023. rport->ns_retries = 0;
  1024. bfa_fcs_rport_send_nsdisc(rport, NULL);
  1025. } else if (bfa_fcport_get_topology(rport->port->fcs->bfa) ==
  1026. BFA_PORT_TOPOLOGY_LOOP) {
  1027. if (rport->scn_online) {
  1028. bfa_sm_set_state(rport,
  1029. bfa_fcs_rport_sm_adisc_offline_sending);
  1030. bfa_fcs_rport_send_adisc(rport, NULL);
  1031. } else {
  1032. bfa_sm_set_state(rport,
  1033. bfa_fcs_rport_sm_offline);
  1034. bfa_timer_start(rport->fcs->bfa, &rport->timer,
  1035. bfa_fcs_rport_timeout, rport,
  1036. bfa_fcs_rport_del_timeout);
  1037. }
  1038. } else {
  1039. bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogi_sending);
  1040. rport->plogi_retries = 0;
  1041. bfa_fcs_rport_send_plogi(rport, NULL);
  1042. }
  1043. break;
  1044. case RPSM_EVENT_DELETE:
  1045. bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
  1046. bfa_fcs_rport_free(rport);
  1047. break;
  1048. case RPSM_EVENT_SCN_ONLINE:
  1049. case RPSM_EVENT_SCN_OFFLINE:
  1050. case RPSM_EVENT_FAB_SCN:
  1051. case RPSM_EVENT_LOGO_RCVD:
  1052. case RPSM_EVENT_PRLO_RCVD:
  1053. case RPSM_EVENT_PLOGI_RCVD:
  1054. case RPSM_EVENT_LOGO_IMP:
  1055. /*
  1056. * Ignore, already offline.
  1057. */
  1058. break;
  1059. default:
  1060. bfa_sm_fault(rport->fcs, event);
  1061. }
  1062. }
  1063. /*
  1064. * Rport is offline. FC-4s are offline. Awaiting BFA rport offline
  1065. * callback to send LOGO accept.
  1066. */
  1067. static void
  1068. bfa_fcs_rport_sm_hcb_logorcv(struct bfa_fcs_rport_s *rport,
  1069. enum rport_event event)
  1070. {
  1071. bfa_trc(rport->fcs, rport->pwwn);
  1072. bfa_trc(rport->fcs, rport->pid);
  1073. bfa_trc(rport->fcs, event);
  1074. switch (event) {
  1075. case RPSM_EVENT_HCB_OFFLINE:
  1076. case RPSM_EVENT_ADDRESS_CHANGE:
  1077. if (rport->pid && (rport->prlo == BFA_TRUE))
  1078. bfa_fcs_rport_send_prlo_acc(rport);
  1079. if (rport->pid && (rport->prlo == BFA_FALSE))
  1080. bfa_fcs_rport_send_logo_acc(rport);
  1081. /*
  1082. * If the lport is online and if the rport is not a well
  1083. * known address port,
  1084. * we try to re-discover the r-port.
  1085. */
  1086. if (bfa_fcs_lport_is_online(rport->port) &&
  1087. (!BFA_FCS_PID_IS_WKA(rport->pid))) {
  1088. if (bfa_fcs_fabric_is_switched(rport->port->fabric)) {
  1089. bfa_sm_set_state(rport,
  1090. bfa_fcs_rport_sm_nsdisc_sending);
  1091. rport->ns_retries = 0;
  1092. bfa_fcs_rport_send_nsdisc(rport, NULL);
  1093. } else {
  1094. /* For N2N Direct Attach, try to re-login */
  1095. bfa_sm_set_state(rport,
  1096. bfa_fcs_rport_sm_plogi_sending);
  1097. rport->plogi_retries = 0;
  1098. bfa_fcs_rport_send_plogi(rport, NULL);
  1099. }
  1100. } else {
  1101. /*
  1102. * if it is not a well known address, reset the
  1103. * pid to 0.
  1104. */
  1105. if (!BFA_FCS_PID_IS_WKA(rport->pid))
  1106. rport->pid = 0;
  1107. bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
  1108. bfa_timer_start(rport->fcs->bfa, &rport->timer,
  1109. bfa_fcs_rport_timeout, rport,
  1110. bfa_fcs_rport_del_timeout);
  1111. }
  1112. break;
  1113. case RPSM_EVENT_DELETE:
  1114. bfa_sm_set_state(rport, bfa_fcs_rport_sm_delete_pending);
  1115. if (rport->pid && (rport->prlo == BFA_TRUE))
  1116. bfa_fcs_rport_send_prlo_acc(rport);
  1117. if (rport->pid && (rport->prlo == BFA_FALSE))
  1118. bfa_fcs_rport_send_logo_acc(rport);
  1119. break;
  1120. case RPSM_EVENT_LOGO_IMP:
  1121. bfa_sm_set_state(rport, bfa_fcs_rport_sm_hcb_offline);
  1122. break;
  1123. case RPSM_EVENT_SCN_ONLINE:
  1124. case RPSM_EVENT_SCN_OFFLINE:
  1125. case RPSM_EVENT_LOGO_RCVD:
  1126. case RPSM_EVENT_PRLO_RCVD:
  1127. /*
  1128. * Ignore - already processing a LOGO.
  1129. */
  1130. break;
  1131. default:
  1132. bfa_sm_fault(rport->fcs, event);
  1133. }
  1134. }
  1135. /*
  1136. * Rport is being deleted. FC-4s are offline.
  1137. * Awaiting BFA rport offline
  1138. * callback to send LOGO.
  1139. */
  1140. static void
  1141. bfa_fcs_rport_sm_hcb_logosend(struct bfa_fcs_rport_s *rport,
  1142. enum rport_event event)
  1143. {
  1144. bfa_trc(rport->fcs, rport->pwwn);
  1145. bfa_trc(rport->fcs, rport->pid);
  1146. bfa_trc(rport->fcs, event);
  1147. switch (event) {
  1148. case RPSM_EVENT_HCB_OFFLINE:
  1149. bfa_sm_set_state(rport, bfa_fcs_rport_sm_logo_sending);
  1150. bfa_fcs_rport_send_logo(rport, NULL);
  1151. break;
  1152. case RPSM_EVENT_LOGO_RCVD:
  1153. bfa_fcs_rport_send_logo_acc(rport);
  1154. case RPSM_EVENT_PRLO_RCVD:
  1155. if (rport->prlo == BFA_TRUE)
  1156. bfa_fcs_rport_send_prlo_acc(rport);
  1157. bfa_sm_set_state(rport, bfa_fcs_rport_sm_delete_pending);
  1158. break;
  1159. case RPSM_EVENT_SCN_ONLINE:
  1160. case RPSM_EVENT_SCN_OFFLINE:
  1161. case RPSM_EVENT_ADDRESS_CHANGE:
  1162. break;
  1163. default:
  1164. bfa_sm_fault(rport->fcs, event);
  1165. }
  1166. }
  1167. /*
  1168. * Rport is being deleted. FC-4s are offline. LOGO is being sent.
  1169. */
  1170. static void
  1171. bfa_fcs_rport_sm_logo_sending(struct bfa_fcs_rport_s *rport,
  1172. enum rport_event event)
  1173. {
  1174. bfa_trc(rport->fcs, rport->pwwn);
  1175. bfa_trc(rport->fcs, rport->pid);
  1176. bfa_trc(rport->fcs, event);
  1177. switch (event) {
  1178. case RPSM_EVENT_FCXP_SENT:
  1179. /* Once LOGO is sent, we donot wait for the response */
  1180. bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
  1181. bfa_fcs_rport_free(rport);
  1182. break;
  1183. case RPSM_EVENT_SCN_ONLINE:
  1184. case RPSM_EVENT_SCN_OFFLINE:
  1185. case RPSM_EVENT_FAB_SCN:
  1186. case RPSM_EVENT_ADDRESS_CHANGE:
  1187. break;
  1188. case RPSM_EVENT_LOGO_RCVD:
  1189. bfa_fcs_rport_send_logo_acc(rport);
  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. struct fc_adisc_s *adisc;
  1959. bfa_trc(port->fcs, rx_fchs->s_id);
  1960. bfa_trc(port->fcs, rx_fchs->d_id);
  1961. rport->stats.adisc_rcvd++;
  1962. adisc = (struct fc_adisc_s *) (rx_fchs + 1);
  1963. /*
  1964. * Accept if the itnim for this rport is online.
  1965. * Else reject the ADISC.
  1966. */
  1967. if (bfa_fcs_itnim_get_online_state(rport->itnim) == BFA_STATUS_OK) {
  1968. fcxp = bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
  1969. if (!fcxp)
  1970. return;
  1971. len = fc_adisc_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
  1972. rx_fchs->s_id, bfa_fcs_lport_get_fcid(port),
  1973. rx_fchs->ox_id, port->port_cfg.pwwn,
  1974. port->port_cfg.nwwn);
  1975. bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag,
  1976. BFA_FALSE, FC_CLASS_3, len, &fchs, NULL, NULL,
  1977. FC_MAX_PDUSZ, 0);
  1978. } else {
  1979. rport->stats.adisc_rejected++;
  1980. bfa_fcs_rport_send_ls_rjt(rport, rx_fchs,
  1981. FC_LS_RJT_RSN_UNABLE_TO_PERF_CMD,
  1982. FC_LS_RJT_EXP_LOGIN_REQUIRED);
  1983. }
  1984. }
  1985. static void
  1986. bfa_fcs_rport_hal_online(struct bfa_fcs_rport_s *rport)
  1987. {
  1988. struct bfa_fcs_lport_s *port = rport->port;
  1989. struct bfa_rport_info_s rport_info;
  1990. rport_info.pid = rport->pid;
  1991. rport_info.local_pid = port->pid;
  1992. rport_info.lp_tag = port->lp_tag;
  1993. rport_info.vf_id = port->fabric->vf_id;
  1994. rport_info.vf_en = port->fabric->is_vf;
  1995. rport_info.fc_class = rport->fc_cos;
  1996. rport_info.cisc = rport->cisc;
  1997. rport_info.max_frmsz = rport->maxfrsize;
  1998. bfa_rport_online(rport->bfa_rport, &rport_info);
  1999. }
  2000. static void
  2001. bfa_fcs_rport_hal_offline(struct bfa_fcs_rport_s *rport)
  2002. {
  2003. if (rport->bfa_rport)
  2004. bfa_sm_send_event(rport->bfa_rport, BFA_RPORT_SM_OFFLINE);
  2005. else
  2006. bfa_cb_rport_offline(rport);
  2007. }
  2008. static struct bfa_fcs_rport_s *
  2009. bfa_fcs_rport_alloc(struct bfa_fcs_lport_s *port, wwn_t pwwn, u32 rpid)
  2010. {
  2011. struct bfa_fcs_s *fcs = port->fcs;
  2012. struct bfa_fcs_rport_s *rport;
  2013. struct bfad_rport_s *rport_drv;
  2014. /*
  2015. * allocate rport
  2016. */
  2017. if (fcs->num_rport_logins >= bfa_fcs_rport_max_logins) {
  2018. bfa_trc(fcs, rpid);
  2019. return NULL;
  2020. }
  2021. if (bfa_fcb_rport_alloc(fcs->bfad, &rport, &rport_drv)
  2022. != BFA_STATUS_OK) {
  2023. bfa_trc(fcs, rpid);
  2024. return NULL;
  2025. }
  2026. /*
  2027. * Initialize r-port
  2028. */
  2029. rport->port = port;
  2030. rport->fcs = fcs;
  2031. rport->rp_drv = rport_drv;
  2032. rport->pid = rpid;
  2033. rport->pwwn = pwwn;
  2034. rport->old_pid = 0;
  2035. rport->bfa_rport = NULL;
  2036. /*
  2037. * allocate FC-4s
  2038. */
  2039. WARN_ON(!bfa_fcs_lport_is_initiator(port));
  2040. if (bfa_fcs_lport_is_initiator(port)) {
  2041. rport->itnim = bfa_fcs_itnim_create(rport);
  2042. if (!rport->itnim) {
  2043. bfa_trc(fcs, rpid);
  2044. kfree(rport_drv);
  2045. return NULL;
  2046. }
  2047. }
  2048. bfa_fcs_lport_add_rport(port, rport);
  2049. fcs->num_rport_logins++;
  2050. bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
  2051. /* Initialize the Rport Features(RPF) Sub Module */
  2052. if (!BFA_FCS_PID_IS_WKA(rport->pid))
  2053. bfa_fcs_rpf_init(rport);
  2054. return rport;
  2055. }
  2056. static void
  2057. bfa_fcs_rport_free(struct bfa_fcs_rport_s *rport)
  2058. {
  2059. struct bfa_fcs_lport_s *port = rport->port;
  2060. struct bfa_fcs_s *fcs = port->fcs;
  2061. /*
  2062. * - delete FC-4s
  2063. * - delete BFA rport
  2064. * - remove from queue of rports
  2065. */
  2066. rport->plogi_pending = BFA_FALSE;
  2067. if (bfa_fcs_lport_is_initiator(port)) {
  2068. bfa_fcs_itnim_delete(rport->itnim);
  2069. if (rport->pid != 0 && !BFA_FCS_PID_IS_WKA(rport->pid))
  2070. bfa_fcs_rpf_rport_offline(rport);
  2071. }
  2072. if (rport->bfa_rport) {
  2073. bfa_sm_send_event(rport->bfa_rport, BFA_RPORT_SM_DELETE);
  2074. rport->bfa_rport = NULL;
  2075. }
  2076. bfa_fcs_lport_del_rport(port, rport);
  2077. fcs->num_rport_logins--;
  2078. kfree(rport->rp_drv);
  2079. }
  2080. static void
  2081. bfa_fcs_rport_aen_post(struct bfa_fcs_rport_s *rport,
  2082. enum bfa_rport_aen_event event,
  2083. struct bfa_rport_aen_data_s *data)
  2084. {
  2085. struct bfa_fcs_lport_s *port = rport->port;
  2086. struct bfad_s *bfad = (struct bfad_s *)port->fcs->bfad;
  2087. struct bfa_aen_entry_s *aen_entry;
  2088. bfad_get_aen_entry(bfad, aen_entry);
  2089. if (!aen_entry)
  2090. return;
  2091. if (event == BFA_RPORT_AEN_QOS_PRIO)
  2092. aen_entry->aen_data.rport.priv.qos = data->priv.qos;
  2093. else if (event == BFA_RPORT_AEN_QOS_FLOWID)
  2094. aen_entry->aen_data.rport.priv.qos = data->priv.qos;
  2095. aen_entry->aen_data.rport.vf_id = rport->port->fabric->vf_id;
  2096. aen_entry->aen_data.rport.ppwwn = bfa_fcs_lport_get_pwwn(
  2097. bfa_fcs_get_base_port(rport->fcs));
  2098. aen_entry->aen_data.rport.lpwwn = bfa_fcs_lport_get_pwwn(rport->port);
  2099. aen_entry->aen_data.rport.rpwwn = rport->pwwn;
  2100. /* Send the AEN notification */
  2101. bfad_im_post_vendor_event(aen_entry, bfad, ++rport->fcs->fcs_aen_seq,
  2102. BFA_AEN_CAT_RPORT, event);
  2103. }
  2104. static void
  2105. bfa_fcs_rport_fcs_online_action(struct bfa_fcs_rport_s *rport)
  2106. {
  2107. if ((!rport->pid) || (!rport->pwwn)) {
  2108. bfa_trc(rport->fcs, rport->pid);
  2109. bfa_sm_fault(rport->fcs, rport->pid);
  2110. }
  2111. bfa_sm_send_event(rport->itnim, BFA_FCS_ITNIM_SM_FCS_ONLINE);
  2112. }
  2113. static void
  2114. bfa_fcs_rport_hal_online_action(struct bfa_fcs_rport_s *rport)
  2115. {
  2116. struct bfa_fcs_lport_s *port = rport->port;
  2117. struct bfad_s *bfad = (struct bfad_s *)port->fcs->bfad;
  2118. char lpwwn_buf[BFA_STRING_32];
  2119. char rpwwn_buf[BFA_STRING_32];
  2120. rport->stats.onlines++;
  2121. if ((!rport->pid) || (!rport->pwwn)) {
  2122. bfa_trc(rport->fcs, rport->pid);
  2123. bfa_sm_fault(rport->fcs, rport->pid);
  2124. }
  2125. if (bfa_fcs_lport_is_initiator(port)) {
  2126. bfa_fcs_itnim_brp_online(rport->itnim);
  2127. if (!BFA_FCS_PID_IS_WKA(rport->pid))
  2128. bfa_fcs_rpf_rport_online(rport);
  2129. };
  2130. wwn2str(lpwwn_buf, bfa_fcs_lport_get_pwwn(port));
  2131. wwn2str(rpwwn_buf, rport->pwwn);
  2132. if (!BFA_FCS_PID_IS_WKA(rport->pid)) {
  2133. BFA_LOG(KERN_INFO, bfad, bfa_log_level,
  2134. "Remote port (WWN = %s) online for logical port (WWN = %s)\n",
  2135. rpwwn_buf, lpwwn_buf);
  2136. bfa_fcs_rport_aen_post(rport, BFA_RPORT_AEN_ONLINE, NULL);
  2137. }
  2138. }
  2139. static void
  2140. bfa_fcs_rport_fcs_offline_action(struct bfa_fcs_rport_s *rport)
  2141. {
  2142. if (!BFA_FCS_PID_IS_WKA(rport->pid))
  2143. bfa_fcs_rpf_rport_offline(rport);
  2144. bfa_fcs_itnim_rport_offline(rport->itnim);
  2145. }
  2146. static void
  2147. bfa_fcs_rport_hal_offline_action(struct bfa_fcs_rport_s *rport)
  2148. {
  2149. struct bfa_fcs_lport_s *port = rport->port;
  2150. struct bfad_s *bfad = (struct bfad_s *)port->fcs->bfad;
  2151. char lpwwn_buf[BFA_STRING_32];
  2152. char rpwwn_buf[BFA_STRING_32];
  2153. if (!rport->bfa_rport) {
  2154. bfa_fcs_rport_fcs_offline_action(rport);
  2155. return;
  2156. }
  2157. rport->stats.offlines++;
  2158. wwn2str(lpwwn_buf, bfa_fcs_lport_get_pwwn(port));
  2159. wwn2str(rpwwn_buf, rport->pwwn);
  2160. if (!BFA_FCS_PID_IS_WKA(rport->pid)) {
  2161. if (bfa_fcs_lport_is_online(rport->port) == BFA_TRUE) {
  2162. BFA_LOG(KERN_ERR, bfad, bfa_log_level,
  2163. "Remote port (WWN = %s) connectivity lost for "
  2164. "logical port (WWN = %s)\n",
  2165. rpwwn_buf, lpwwn_buf);
  2166. bfa_fcs_rport_aen_post(rport,
  2167. BFA_RPORT_AEN_DISCONNECT, NULL);
  2168. } else {
  2169. BFA_LOG(KERN_INFO, bfad, bfa_log_level,
  2170. "Remote port (WWN = %s) offlined by "
  2171. "logical port (WWN = %s)\n",
  2172. rpwwn_buf, lpwwn_buf);
  2173. bfa_fcs_rport_aen_post(rport,
  2174. BFA_RPORT_AEN_OFFLINE, NULL);
  2175. }
  2176. }
  2177. if (bfa_fcs_lport_is_initiator(port)) {
  2178. bfa_fcs_itnim_rport_offline(rport->itnim);
  2179. if (!BFA_FCS_PID_IS_WKA(rport->pid))
  2180. bfa_fcs_rpf_rport_offline(rport);
  2181. }
  2182. }
  2183. /*
  2184. * Update rport parameters from PLOGI or PLOGI accept.
  2185. */
  2186. static void
  2187. bfa_fcs_rport_update(struct bfa_fcs_rport_s *rport, struct fc_logi_s *plogi)
  2188. {
  2189. bfa_fcs_lport_t *port = rport->port;
  2190. /*
  2191. * - port name
  2192. * - node name
  2193. */
  2194. rport->pwwn = plogi->port_name;
  2195. rport->nwwn = plogi->node_name;
  2196. /*
  2197. * - class of service
  2198. */
  2199. rport->fc_cos = 0;
  2200. if (plogi->class3.class_valid)
  2201. rport->fc_cos = FC_CLASS_3;
  2202. if (plogi->class2.class_valid)
  2203. rport->fc_cos |= FC_CLASS_2;
  2204. /*
  2205. * - CISC
  2206. * - MAX receive frame size
  2207. */
  2208. rport->cisc = plogi->csp.cisc;
  2209. if (be16_to_cpu(plogi->class3.rxsz) < be16_to_cpu(plogi->csp.rxsz))
  2210. rport->maxfrsize = be16_to_cpu(plogi->class3.rxsz);
  2211. else
  2212. rport->maxfrsize = be16_to_cpu(plogi->csp.rxsz);
  2213. bfa_trc(port->fcs, be16_to_cpu(plogi->csp.bbcred));
  2214. bfa_trc(port->fcs, port->fabric->bb_credit);
  2215. /*
  2216. * Direct Attach P2P mode :
  2217. * This is to handle a bug (233476) in IBM targets in Direct Attach
  2218. * Mode. Basically, in FLOGI Accept the target would have
  2219. * erroneously set the BB Credit to the value used in the FLOGI
  2220. * sent by the HBA. It uses the correct value (its own BB credit)
  2221. * in PLOGI.
  2222. */
  2223. if ((!bfa_fcs_fabric_is_switched(port->fabric)) &&
  2224. (be16_to_cpu(plogi->csp.bbcred) < port->fabric->bb_credit)) {
  2225. bfa_trc(port->fcs, be16_to_cpu(plogi->csp.bbcred));
  2226. bfa_trc(port->fcs, port->fabric->bb_credit);
  2227. port->fabric->bb_credit = be16_to_cpu(plogi->csp.bbcred);
  2228. bfa_fcport_set_tx_bbcredit(port->fcs->bfa,
  2229. port->fabric->bb_credit);
  2230. }
  2231. }
  2232. /*
  2233. * Called to handle LOGO received from an existing remote port.
  2234. */
  2235. static void
  2236. bfa_fcs_rport_process_logo(struct bfa_fcs_rport_s *rport, struct fchs_s *fchs)
  2237. {
  2238. rport->reply_oxid = fchs->ox_id;
  2239. bfa_trc(rport->fcs, rport->reply_oxid);
  2240. rport->prlo = BFA_FALSE;
  2241. rport->stats.logo_rcvd++;
  2242. bfa_sm_send_event(rport, RPSM_EVENT_LOGO_RCVD);
  2243. }
  2244. /*
  2245. * fcs_rport_public FCS rport public interfaces
  2246. */
  2247. /*
  2248. * Called by bport/vport to create a remote port instance for a discovered
  2249. * remote device.
  2250. *
  2251. * @param[in] port - base port or vport
  2252. * @param[in] rpid - remote port ID
  2253. *
  2254. * @return None
  2255. */
  2256. struct bfa_fcs_rport_s *
  2257. bfa_fcs_rport_create(struct bfa_fcs_lport_s *port, u32 rpid)
  2258. {
  2259. struct bfa_fcs_rport_s *rport;
  2260. bfa_trc(port->fcs, rpid);
  2261. rport = bfa_fcs_rport_alloc(port, WWN_NULL, rpid);
  2262. if (!rport)
  2263. return NULL;
  2264. bfa_sm_send_event(rport, RPSM_EVENT_PLOGI_SEND);
  2265. return rport;
  2266. }
  2267. /*
  2268. * Called to create a rport for which only the wwn is known.
  2269. *
  2270. * @param[in] port - base port
  2271. * @param[in] rpwwn - remote port wwn
  2272. *
  2273. * @return None
  2274. */
  2275. struct bfa_fcs_rport_s *
  2276. bfa_fcs_rport_create_by_wwn(struct bfa_fcs_lport_s *port, wwn_t rpwwn)
  2277. {
  2278. struct bfa_fcs_rport_s *rport;
  2279. bfa_trc(port->fcs, rpwwn);
  2280. rport = bfa_fcs_rport_alloc(port, rpwwn, 0);
  2281. if (!rport)
  2282. return NULL;
  2283. bfa_sm_send_event(rport, RPSM_EVENT_ADDRESS_DISC);
  2284. return rport;
  2285. }
  2286. /*
  2287. * Called by bport in private loop topology to indicate that a
  2288. * rport has been discovered and plogi has been completed.
  2289. *
  2290. * @param[in] port - base port or vport
  2291. * @param[in] rpid - remote port ID
  2292. */
  2293. void
  2294. bfa_fcs_rport_start(struct bfa_fcs_lport_s *port, struct fchs_s *fchs,
  2295. struct fc_logi_s *plogi)
  2296. {
  2297. struct bfa_fcs_rport_s *rport;
  2298. rport = bfa_fcs_rport_alloc(port, WWN_NULL, fchs->s_id);
  2299. if (!rport)
  2300. return;
  2301. bfa_fcs_rport_update(rport, plogi);
  2302. bfa_sm_send_event(rport, RPSM_EVENT_PLOGI_COMP);
  2303. }
  2304. /*
  2305. * Called by bport/vport to handle PLOGI received from a new remote port.
  2306. * If an existing rport does a plogi, it will be handled separately.
  2307. */
  2308. void
  2309. bfa_fcs_rport_plogi_create(struct bfa_fcs_lport_s *port, struct fchs_s *fchs,
  2310. struct fc_logi_s *plogi)
  2311. {
  2312. struct bfa_fcs_rport_s *rport;
  2313. rport = bfa_fcs_rport_alloc(port, plogi->port_name, fchs->s_id);
  2314. if (!rport)
  2315. return;
  2316. bfa_fcs_rport_update(rport, plogi);
  2317. rport->reply_oxid = fchs->ox_id;
  2318. bfa_trc(rport->fcs, rport->reply_oxid);
  2319. rport->stats.plogi_rcvd++;
  2320. bfa_sm_send_event(rport, RPSM_EVENT_PLOGI_RCVD);
  2321. }
  2322. /*
  2323. * Called by bport/vport to handle PLOGI received from an existing
  2324. * remote port.
  2325. */
  2326. void
  2327. bfa_fcs_rport_plogi(struct bfa_fcs_rport_s *rport, struct fchs_s *rx_fchs,
  2328. struct fc_logi_s *plogi)
  2329. {
  2330. /*
  2331. * @todo Handle P2P and initiator-initiator.
  2332. */
  2333. bfa_fcs_rport_update(rport, plogi);
  2334. rport->reply_oxid = rx_fchs->ox_id;
  2335. bfa_trc(rport->fcs, rport->reply_oxid);
  2336. rport->pid = rx_fchs->s_id;
  2337. bfa_trc(rport->fcs, rport->pid);
  2338. rport->stats.plogi_rcvd++;
  2339. bfa_sm_send_event(rport, RPSM_EVENT_PLOGI_RCVD);
  2340. }
  2341. /*
  2342. * Called by bport/vport to notify SCN for the remote port
  2343. */
  2344. void
  2345. bfa_fcs_rport_scn(struct bfa_fcs_rport_s *rport)
  2346. {
  2347. rport->stats.rscns++;
  2348. bfa_sm_send_event(rport, RPSM_EVENT_FAB_SCN);
  2349. }
  2350. /*
  2351. * brief
  2352. * This routine BFA callback for bfa_rport_online() call.
  2353. *
  2354. * param[in] cb_arg - rport struct.
  2355. *
  2356. * return
  2357. * void
  2358. *
  2359. * Special Considerations:
  2360. *
  2361. * note
  2362. */
  2363. void
  2364. bfa_cb_rport_online(void *cbarg)
  2365. {
  2366. struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *) cbarg;
  2367. bfa_trc(rport->fcs, rport->pwwn);
  2368. bfa_sm_send_event(rport, RPSM_EVENT_HCB_ONLINE);
  2369. }
  2370. /*
  2371. * brief
  2372. * This routine BFA callback for bfa_rport_offline() call.
  2373. *
  2374. * param[in] rport -
  2375. *
  2376. * return
  2377. * void
  2378. *
  2379. * Special Considerations:
  2380. *
  2381. * note
  2382. */
  2383. void
  2384. bfa_cb_rport_offline(void *cbarg)
  2385. {
  2386. struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *) cbarg;
  2387. bfa_trc(rport->fcs, rport->pwwn);
  2388. bfa_sm_send_event(rport, RPSM_EVENT_HCB_OFFLINE);
  2389. }
  2390. /*
  2391. * brief
  2392. * This routine is a static BFA callback when there is a QoS flow_id
  2393. * change notification
  2394. *
  2395. * param[in] rport -
  2396. *
  2397. * return
  2398. * void
  2399. *
  2400. * Special Considerations:
  2401. *
  2402. * note
  2403. */
  2404. void
  2405. bfa_cb_rport_qos_scn_flowid(void *cbarg,
  2406. struct bfa_rport_qos_attr_s old_qos_attr,
  2407. struct bfa_rport_qos_attr_s new_qos_attr)
  2408. {
  2409. struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *) cbarg;
  2410. struct bfa_rport_aen_data_s aen_data;
  2411. bfa_trc(rport->fcs, rport->pwwn);
  2412. aen_data.priv.qos = new_qos_attr;
  2413. bfa_fcs_rport_aen_post(rport, BFA_RPORT_AEN_QOS_FLOWID, &aen_data);
  2414. }
  2415. void
  2416. bfa_cb_rport_scn_online(struct bfa_s *bfa)
  2417. {
  2418. struct bfa_fcs_s *fcs = &((struct bfad_s *)bfa->bfad)->bfa_fcs;
  2419. struct bfa_fcs_lport_s *port = bfa_fcs_get_base_port(fcs);
  2420. struct bfa_fcs_rport_s *rp;
  2421. struct list_head *qe;
  2422. list_for_each(qe, &port->rport_q) {
  2423. rp = (struct bfa_fcs_rport_s *) qe;
  2424. bfa_sm_send_event(rp, RPSM_EVENT_SCN_ONLINE);
  2425. rp->scn_online = BFA_TRUE;
  2426. }
  2427. if (bfa_fcs_lport_is_online(port))
  2428. bfa_fcs_lport_lip_scn_online(port);
  2429. }
  2430. void
  2431. bfa_cb_rport_scn_no_dev(void *rport)
  2432. {
  2433. struct bfa_fcs_rport_s *rp = rport;
  2434. bfa_sm_send_event(rp, RPSM_EVENT_SCN_OFFLINE);
  2435. rp->scn_online = BFA_FALSE;
  2436. }
  2437. void
  2438. bfa_cb_rport_scn_offline(struct bfa_s *bfa)
  2439. {
  2440. struct bfa_fcs_s *fcs = &((struct bfad_s *)bfa->bfad)->bfa_fcs;
  2441. struct bfa_fcs_lport_s *port = bfa_fcs_get_base_port(fcs);
  2442. struct bfa_fcs_rport_s *rp;
  2443. struct list_head *qe;
  2444. list_for_each(qe, &port->rport_q) {
  2445. rp = (struct bfa_fcs_rport_s *) qe;
  2446. bfa_sm_send_event(rp, RPSM_EVENT_SCN_OFFLINE);
  2447. rp->scn_online = BFA_FALSE;
  2448. }
  2449. }
  2450. /*
  2451. * brief
  2452. * This routine is a static BFA callback when there is a QoS priority
  2453. * change notification
  2454. *
  2455. * param[in] rport -
  2456. *
  2457. * return
  2458. * void
  2459. *
  2460. * Special Considerations:
  2461. *
  2462. * note
  2463. */
  2464. void
  2465. bfa_cb_rport_qos_scn_prio(void *cbarg,
  2466. struct bfa_rport_qos_attr_s old_qos_attr,
  2467. struct bfa_rport_qos_attr_s new_qos_attr)
  2468. {
  2469. struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *) cbarg;
  2470. struct bfa_rport_aen_data_s aen_data;
  2471. bfa_trc(rport->fcs, rport->pwwn);
  2472. aen_data.priv.qos = new_qos_attr;
  2473. bfa_fcs_rport_aen_post(rport, BFA_RPORT_AEN_QOS_PRIO, &aen_data);
  2474. }
  2475. /*
  2476. * Called to process any unsolicted frames from this remote port
  2477. */
  2478. void
  2479. bfa_fcs_rport_uf_recv(struct bfa_fcs_rport_s *rport,
  2480. struct fchs_s *fchs, u16 len)
  2481. {
  2482. struct bfa_fcs_lport_s *port = rport->port;
  2483. struct fc_els_cmd_s *els_cmd;
  2484. bfa_trc(rport->fcs, fchs->s_id);
  2485. bfa_trc(rport->fcs, fchs->d_id);
  2486. bfa_trc(rport->fcs, fchs->type);
  2487. if (fchs->type != FC_TYPE_ELS)
  2488. return;
  2489. els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
  2490. bfa_trc(rport->fcs, els_cmd->els_code);
  2491. switch (els_cmd->els_code) {
  2492. case FC_ELS_LOGO:
  2493. bfa_stats(port, plogi_rcvd);
  2494. bfa_fcs_rport_process_logo(rport, fchs);
  2495. break;
  2496. case FC_ELS_ADISC:
  2497. bfa_stats(port, adisc_rcvd);
  2498. bfa_fcs_rport_process_adisc(rport, fchs, len);
  2499. break;
  2500. case FC_ELS_PRLO:
  2501. bfa_stats(port, prlo_rcvd);
  2502. if (bfa_fcs_lport_is_initiator(port))
  2503. bfa_fcs_fcpim_uf_recv(rport->itnim, fchs, len);
  2504. break;
  2505. case FC_ELS_PRLI:
  2506. bfa_stats(port, prli_rcvd);
  2507. bfa_fcs_rport_process_prli(rport, fchs, len);
  2508. break;
  2509. case FC_ELS_RPSC:
  2510. bfa_stats(port, rpsc_rcvd);
  2511. bfa_fcs_rport_process_rpsc(rport, fchs, len);
  2512. break;
  2513. default:
  2514. bfa_stats(port, un_handled_els_rcvd);
  2515. bfa_fcs_rport_send_ls_rjt(rport, fchs,
  2516. FC_LS_RJT_RSN_CMD_NOT_SUPP,
  2517. FC_LS_RJT_EXP_NO_ADDL_INFO);
  2518. break;
  2519. }
  2520. }
  2521. /* send best case acc to prlo */
  2522. static void
  2523. bfa_fcs_rport_send_prlo_acc(struct bfa_fcs_rport_s *rport)
  2524. {
  2525. struct bfa_fcs_lport_s *port = rport->port;
  2526. struct fchs_s fchs;
  2527. struct bfa_fcxp_s *fcxp;
  2528. int len;
  2529. bfa_trc(rport->fcs, rport->pid);
  2530. fcxp = bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
  2531. if (!fcxp)
  2532. return;
  2533. len = fc_prlo_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
  2534. rport->pid, bfa_fcs_lport_get_fcid(port),
  2535. rport->reply_oxid, 0);
  2536. bfa_fcxp_send(fcxp, rport->bfa_rport, port->fabric->vf_id,
  2537. port->lp_tag, BFA_FALSE, FC_CLASS_3, len, &fchs,
  2538. NULL, NULL, FC_MAX_PDUSZ, 0);
  2539. }
  2540. /*
  2541. * Send a LS reject
  2542. */
  2543. static void
  2544. bfa_fcs_rport_send_ls_rjt(struct bfa_fcs_rport_s *rport, struct fchs_s *rx_fchs,
  2545. u8 reason_code, u8 reason_code_expl)
  2546. {
  2547. struct bfa_fcs_lport_s *port = rport->port;
  2548. struct fchs_s fchs;
  2549. struct bfa_fcxp_s *fcxp;
  2550. int len;
  2551. bfa_trc(rport->fcs, rx_fchs->s_id);
  2552. fcxp = bfa_fcs_fcxp_alloc(rport->fcs, BFA_FALSE);
  2553. if (!fcxp)
  2554. return;
  2555. len = fc_ls_rjt_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
  2556. rx_fchs->s_id, bfa_fcs_lport_get_fcid(port),
  2557. rx_fchs->ox_id, reason_code, reason_code_expl);
  2558. bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag,
  2559. BFA_FALSE, FC_CLASS_3, len, &fchs, NULL, NULL,
  2560. FC_MAX_PDUSZ, 0);
  2561. }
  2562. /*
  2563. * Return state of rport.
  2564. */
  2565. int
  2566. bfa_fcs_rport_get_state(struct bfa_fcs_rport_s *rport)
  2567. {
  2568. return bfa_sm_to_state(rport_sm_table, rport->sm);
  2569. }
  2570. /*
  2571. * brief
  2572. * Called by the Driver to set rport delete/ageout timeout
  2573. *
  2574. * param[in] rport timeout value in seconds.
  2575. *
  2576. * return None
  2577. */
  2578. void
  2579. bfa_fcs_rport_set_del_timeout(u8 rport_tmo)
  2580. {
  2581. /* convert to Millisecs */
  2582. if (rport_tmo > 0)
  2583. bfa_fcs_rport_del_timeout = rport_tmo * 1000;
  2584. }
  2585. void
  2586. bfa_fcs_rport_prlo(struct bfa_fcs_rport_s *rport, __be16 ox_id)
  2587. {
  2588. bfa_trc(rport->fcs, rport->pid);
  2589. rport->prlo = BFA_TRUE;
  2590. rport->reply_oxid = ox_id;
  2591. bfa_sm_send_event(rport, RPSM_EVENT_PRLO_RCVD);
  2592. }
  2593. /*
  2594. * Called by BFAD to set the max limit on number of bfa_fcs_rport allocation
  2595. * which limits number of concurrent logins to remote ports
  2596. */
  2597. void
  2598. bfa_fcs_rport_set_max_logins(u32 max_logins)
  2599. {
  2600. if (max_logins > 0)
  2601. bfa_fcs_rport_max_logins = max_logins;
  2602. }
  2603. void
  2604. bfa_fcs_rport_get_attr(struct bfa_fcs_rport_s *rport,
  2605. struct bfa_rport_attr_s *rport_attr)
  2606. {
  2607. struct bfa_rport_qos_attr_s qos_attr;
  2608. struct bfa_fcs_lport_s *port = rport->port;
  2609. bfa_port_speed_t rport_speed = rport->rpf.rpsc_speed;
  2610. struct bfa_port_attr_s port_attr;
  2611. bfa_fcport_get_attr(rport->fcs->bfa, &port_attr);
  2612. memset(rport_attr, 0, sizeof(struct bfa_rport_attr_s));
  2613. memset(&qos_attr, 0, sizeof(struct bfa_rport_qos_attr_s));
  2614. rport_attr->pid = rport->pid;
  2615. rport_attr->pwwn = rport->pwwn;
  2616. rport_attr->nwwn = rport->nwwn;
  2617. rport_attr->cos_supported = rport->fc_cos;
  2618. rport_attr->df_sz = rport->maxfrsize;
  2619. rport_attr->state = bfa_fcs_rport_get_state(rport);
  2620. rport_attr->fc_cos = rport->fc_cos;
  2621. rport_attr->cisc = rport->cisc;
  2622. rport_attr->scsi_function = rport->scsi_function;
  2623. rport_attr->curr_speed = rport->rpf.rpsc_speed;
  2624. rport_attr->assigned_speed = rport->rpf.assigned_speed;
  2625. if (rport->bfa_rport) {
  2626. qos_attr.qos_priority = rport->bfa_rport->qos_attr.qos_priority;
  2627. qos_attr.qos_flow_id =
  2628. cpu_to_be32(rport->bfa_rport->qos_attr.qos_flow_id);
  2629. }
  2630. rport_attr->qos_attr = qos_attr;
  2631. rport_attr->trl_enforced = BFA_FALSE;
  2632. if (bfa_fcport_is_ratelim(port->fcs->bfa) &&
  2633. (rport->scsi_function == BFA_RPORT_TARGET)) {
  2634. if (rport_speed == BFA_PORT_SPEED_UNKNOWN)
  2635. rport_speed =
  2636. bfa_fcport_get_ratelim_speed(rport->fcs->bfa);
  2637. if ((bfa_fcs_lport_get_rport_max_speed(port) !=
  2638. BFA_PORT_SPEED_UNKNOWN) && (rport_speed < port_attr.speed))
  2639. rport_attr->trl_enforced = BFA_TRUE;
  2640. }
  2641. }
  2642. /*
  2643. * Remote port implementation.
  2644. */
  2645. /*
  2646. * fcs_rport_api FCS rport API.
  2647. */
  2648. struct bfa_fcs_rport_s *
  2649. bfa_fcs_rport_lookup(struct bfa_fcs_lport_s *port, wwn_t rpwwn)
  2650. {
  2651. struct bfa_fcs_rport_s *rport;
  2652. rport = bfa_fcs_lport_get_rport_by_pwwn(port, rpwwn);
  2653. if (rport == NULL) {
  2654. /*
  2655. * TBD Error handling
  2656. */
  2657. }
  2658. return rport;
  2659. }
  2660. struct bfa_fcs_rport_s *
  2661. bfa_fcs_rport_lookup_by_nwwn(struct bfa_fcs_lport_s *port, wwn_t rnwwn)
  2662. {
  2663. struct bfa_fcs_rport_s *rport;
  2664. rport = bfa_fcs_lport_get_rport_by_nwwn(port, rnwwn);
  2665. if (rport == NULL) {
  2666. /*
  2667. * TBD Error handling
  2668. */
  2669. }
  2670. return rport;
  2671. }
  2672. /*
  2673. * Remote port features (RPF) implementation.
  2674. */
  2675. #define BFA_FCS_RPF_RETRIES (3)
  2676. #define BFA_FCS_RPF_RETRY_TIMEOUT (1000) /* 1 sec (In millisecs) */
  2677. static void bfa_fcs_rpf_send_rpsc2(void *rport_cbarg,
  2678. struct bfa_fcxp_s *fcxp_alloced);
  2679. static void bfa_fcs_rpf_rpsc2_response(void *fcsarg,
  2680. struct bfa_fcxp_s *fcxp,
  2681. void *cbarg,
  2682. bfa_status_t req_status,
  2683. u32 rsp_len,
  2684. u32 resid_len,
  2685. struct fchs_s *rsp_fchs);
  2686. static void bfa_fcs_rpf_timeout(void *arg);
  2687. /*
  2688. * fcs_rport_ftrs_sm FCS rport state machine events
  2689. */
  2690. enum rpf_event {
  2691. RPFSM_EVENT_RPORT_OFFLINE = 1, /* Rport offline */
  2692. RPFSM_EVENT_RPORT_ONLINE = 2, /* Rport online */
  2693. RPFSM_EVENT_FCXP_SENT = 3, /* Frame from has been sent */
  2694. RPFSM_EVENT_TIMEOUT = 4, /* Rport SM timeout event */
  2695. RPFSM_EVENT_RPSC_COMP = 5,
  2696. RPFSM_EVENT_RPSC_FAIL = 6,
  2697. RPFSM_EVENT_RPSC_ERROR = 7,
  2698. };
  2699. static void bfa_fcs_rpf_sm_uninit(struct bfa_fcs_rpf_s *rpf,
  2700. enum rpf_event event);
  2701. static void bfa_fcs_rpf_sm_rpsc_sending(struct bfa_fcs_rpf_s *rpf,
  2702. enum rpf_event event);
  2703. static void bfa_fcs_rpf_sm_rpsc(struct bfa_fcs_rpf_s *rpf,
  2704. enum rpf_event event);
  2705. static void bfa_fcs_rpf_sm_rpsc_retry(struct bfa_fcs_rpf_s *rpf,
  2706. enum rpf_event event);
  2707. static void bfa_fcs_rpf_sm_offline(struct bfa_fcs_rpf_s *rpf,
  2708. enum rpf_event event);
  2709. static void bfa_fcs_rpf_sm_online(struct bfa_fcs_rpf_s *rpf,
  2710. enum rpf_event event);
  2711. static void
  2712. bfa_fcs_rpf_sm_uninit(struct bfa_fcs_rpf_s *rpf, enum rpf_event event)
  2713. {
  2714. struct bfa_fcs_rport_s *rport = rpf->rport;
  2715. struct bfa_fcs_fabric_s *fabric = &rport->fcs->fabric;
  2716. bfa_trc(rport->fcs, rport->pwwn);
  2717. bfa_trc(rport->fcs, rport->pid);
  2718. bfa_trc(rport->fcs, event);
  2719. switch (event) {
  2720. case RPFSM_EVENT_RPORT_ONLINE:
  2721. /* Send RPSC2 to a Brocade fabric only. */
  2722. if ((!BFA_FCS_PID_IS_WKA(rport->pid)) &&
  2723. ((rport->port->fabric->lps->brcd_switch) ||
  2724. (bfa_fcs_fabric_get_switch_oui(fabric) ==
  2725. BFA_FCS_BRCD_SWITCH_OUI))) {
  2726. bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_rpsc_sending);
  2727. rpf->rpsc_retries = 0;
  2728. bfa_fcs_rpf_send_rpsc2(rpf, NULL);
  2729. }
  2730. break;
  2731. case RPFSM_EVENT_RPORT_OFFLINE:
  2732. break;
  2733. default:
  2734. bfa_sm_fault(rport->fcs, event);
  2735. }
  2736. }
  2737. static void
  2738. bfa_fcs_rpf_sm_rpsc_sending(struct bfa_fcs_rpf_s *rpf, enum rpf_event event)
  2739. {
  2740. struct bfa_fcs_rport_s *rport = rpf->rport;
  2741. bfa_trc(rport->fcs, event);
  2742. switch (event) {
  2743. case RPFSM_EVENT_FCXP_SENT:
  2744. bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_rpsc);
  2745. break;
  2746. case RPFSM_EVENT_RPORT_OFFLINE:
  2747. bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_offline);
  2748. bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rpf->fcxp_wqe);
  2749. rpf->rpsc_retries = 0;
  2750. break;
  2751. default:
  2752. bfa_sm_fault(rport->fcs, event);
  2753. }
  2754. }
  2755. static void
  2756. bfa_fcs_rpf_sm_rpsc(struct bfa_fcs_rpf_s *rpf, enum rpf_event event)
  2757. {
  2758. struct bfa_fcs_rport_s *rport = rpf->rport;
  2759. bfa_trc(rport->fcs, rport->pid);
  2760. bfa_trc(rport->fcs, event);
  2761. switch (event) {
  2762. case RPFSM_EVENT_RPSC_COMP:
  2763. bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_online);
  2764. /* Update speed info in f/w via BFA */
  2765. if (rpf->rpsc_speed != BFA_PORT_SPEED_UNKNOWN)
  2766. bfa_rport_speed(rport->bfa_rport, rpf->rpsc_speed);
  2767. else if (rpf->assigned_speed != BFA_PORT_SPEED_UNKNOWN)
  2768. bfa_rport_speed(rport->bfa_rport, rpf->assigned_speed);
  2769. break;
  2770. case RPFSM_EVENT_RPSC_FAIL:
  2771. /* RPSC not supported by rport */
  2772. bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_online);
  2773. break;
  2774. case RPFSM_EVENT_RPSC_ERROR:
  2775. /* need to retry...delayed a bit. */
  2776. if (rpf->rpsc_retries++ < BFA_FCS_RPF_RETRIES) {
  2777. bfa_timer_start(rport->fcs->bfa, &rpf->timer,
  2778. bfa_fcs_rpf_timeout, rpf,
  2779. BFA_FCS_RPF_RETRY_TIMEOUT);
  2780. bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_rpsc_retry);
  2781. } else {
  2782. bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_online);
  2783. }
  2784. break;
  2785. case RPFSM_EVENT_RPORT_OFFLINE:
  2786. bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_offline);
  2787. bfa_fcxp_discard(rpf->fcxp);
  2788. rpf->rpsc_retries = 0;
  2789. break;
  2790. default:
  2791. bfa_sm_fault(rport->fcs, event);
  2792. }
  2793. }
  2794. static void
  2795. bfa_fcs_rpf_sm_rpsc_retry(struct bfa_fcs_rpf_s *rpf, enum rpf_event event)
  2796. {
  2797. struct bfa_fcs_rport_s *rport = rpf->rport;
  2798. bfa_trc(rport->fcs, rport->pid);
  2799. bfa_trc(rport->fcs, event);
  2800. switch (event) {
  2801. case RPFSM_EVENT_TIMEOUT:
  2802. /* re-send the RPSC */
  2803. bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_rpsc_sending);
  2804. bfa_fcs_rpf_send_rpsc2(rpf, NULL);
  2805. break;
  2806. case RPFSM_EVENT_RPORT_OFFLINE:
  2807. bfa_timer_stop(&rpf->timer);
  2808. bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_offline);
  2809. rpf->rpsc_retries = 0;
  2810. break;
  2811. default:
  2812. bfa_sm_fault(rport->fcs, event);
  2813. }
  2814. }
  2815. static void
  2816. bfa_fcs_rpf_sm_online(struct bfa_fcs_rpf_s *rpf, enum rpf_event event)
  2817. {
  2818. struct bfa_fcs_rport_s *rport = rpf->rport;
  2819. bfa_trc(rport->fcs, rport->pwwn);
  2820. bfa_trc(rport->fcs, rport->pid);
  2821. bfa_trc(rport->fcs, event);
  2822. switch (event) {
  2823. case RPFSM_EVENT_RPORT_OFFLINE:
  2824. bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_offline);
  2825. rpf->rpsc_retries = 0;
  2826. break;
  2827. default:
  2828. bfa_sm_fault(rport->fcs, event);
  2829. }
  2830. }
  2831. static void
  2832. bfa_fcs_rpf_sm_offline(struct bfa_fcs_rpf_s *rpf, enum rpf_event event)
  2833. {
  2834. struct bfa_fcs_rport_s *rport = rpf->rport;
  2835. bfa_trc(rport->fcs, rport->pwwn);
  2836. bfa_trc(rport->fcs, rport->pid);
  2837. bfa_trc(rport->fcs, event);
  2838. switch (event) {
  2839. case RPFSM_EVENT_RPORT_ONLINE:
  2840. bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_rpsc_sending);
  2841. bfa_fcs_rpf_send_rpsc2(rpf, NULL);
  2842. break;
  2843. case RPFSM_EVENT_RPORT_OFFLINE:
  2844. break;
  2845. default:
  2846. bfa_sm_fault(rport->fcs, event);
  2847. }
  2848. }
  2849. /*
  2850. * Called when Rport is created.
  2851. */
  2852. void
  2853. bfa_fcs_rpf_init(struct bfa_fcs_rport_s *rport)
  2854. {
  2855. struct bfa_fcs_rpf_s *rpf = &rport->rpf;
  2856. bfa_trc(rport->fcs, rport->pid);
  2857. rpf->rport = rport;
  2858. bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_uninit);
  2859. }
  2860. /*
  2861. * Called when Rport becomes online
  2862. */
  2863. void
  2864. bfa_fcs_rpf_rport_online(struct bfa_fcs_rport_s *rport)
  2865. {
  2866. bfa_trc(rport->fcs, rport->pid);
  2867. if (__fcs_min_cfg(rport->port->fcs))
  2868. return;
  2869. if (bfa_fcs_fabric_is_switched(rport->port->fabric))
  2870. bfa_sm_send_event(&rport->rpf, RPFSM_EVENT_RPORT_ONLINE);
  2871. }
  2872. /*
  2873. * Called when Rport becomes offline
  2874. */
  2875. void
  2876. bfa_fcs_rpf_rport_offline(struct bfa_fcs_rport_s *rport)
  2877. {
  2878. bfa_trc(rport->fcs, rport->pid);
  2879. if (__fcs_min_cfg(rport->port->fcs))
  2880. return;
  2881. rport->rpf.rpsc_speed = 0;
  2882. bfa_sm_send_event(&rport->rpf, RPFSM_EVENT_RPORT_OFFLINE);
  2883. }
  2884. static void
  2885. bfa_fcs_rpf_timeout(void *arg)
  2886. {
  2887. struct bfa_fcs_rpf_s *rpf = (struct bfa_fcs_rpf_s *) arg;
  2888. struct bfa_fcs_rport_s *rport = rpf->rport;
  2889. bfa_trc(rport->fcs, rport->pid);
  2890. bfa_sm_send_event(rpf, RPFSM_EVENT_TIMEOUT);
  2891. }
  2892. static void
  2893. bfa_fcs_rpf_send_rpsc2(void *rpf_cbarg, struct bfa_fcxp_s *fcxp_alloced)
  2894. {
  2895. struct bfa_fcs_rpf_s *rpf = (struct bfa_fcs_rpf_s *)rpf_cbarg;
  2896. struct bfa_fcs_rport_s *rport = rpf->rport;
  2897. struct bfa_fcs_lport_s *port = rport->port;
  2898. struct fchs_s fchs;
  2899. int len;
  2900. struct bfa_fcxp_s *fcxp;
  2901. bfa_trc(rport->fcs, rport->pwwn);
  2902. fcxp = fcxp_alloced ? fcxp_alloced :
  2903. bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
  2904. if (!fcxp) {
  2905. bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &rpf->fcxp_wqe,
  2906. bfa_fcs_rpf_send_rpsc2, rpf, BFA_TRUE);
  2907. return;
  2908. }
  2909. rpf->fcxp = fcxp;
  2910. len = fc_rpsc2_build(&fchs, bfa_fcxp_get_reqbuf(fcxp), rport->pid,
  2911. bfa_fcs_lport_get_fcid(port), &rport->pid, 1);
  2912. bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
  2913. FC_CLASS_3, len, &fchs, bfa_fcs_rpf_rpsc2_response,
  2914. rpf, FC_MAX_PDUSZ, FC_ELS_TOV);
  2915. rport->stats.rpsc_sent++;
  2916. bfa_sm_send_event(rpf, RPFSM_EVENT_FCXP_SENT);
  2917. }
  2918. static void
  2919. bfa_fcs_rpf_rpsc2_response(void *fcsarg, struct bfa_fcxp_s *fcxp, void *cbarg,
  2920. bfa_status_t req_status, u32 rsp_len,
  2921. u32 resid_len, struct fchs_s *rsp_fchs)
  2922. {
  2923. struct bfa_fcs_rpf_s *rpf = (struct bfa_fcs_rpf_s *) cbarg;
  2924. struct bfa_fcs_rport_s *rport = rpf->rport;
  2925. struct fc_ls_rjt_s *ls_rjt;
  2926. struct fc_rpsc2_acc_s *rpsc2_acc;
  2927. u16 num_ents;
  2928. bfa_trc(rport->fcs, req_status);
  2929. if (req_status != BFA_STATUS_OK) {
  2930. bfa_trc(rport->fcs, req_status);
  2931. if (req_status == BFA_STATUS_ETIMER)
  2932. rport->stats.rpsc_failed++;
  2933. bfa_sm_send_event(rpf, RPFSM_EVENT_RPSC_ERROR);
  2934. return;
  2935. }
  2936. rpsc2_acc = (struct fc_rpsc2_acc_s *) BFA_FCXP_RSP_PLD(fcxp);
  2937. if (rpsc2_acc->els_cmd == FC_ELS_ACC) {
  2938. rport->stats.rpsc_accs++;
  2939. num_ents = be16_to_cpu(rpsc2_acc->num_pids);
  2940. bfa_trc(rport->fcs, num_ents);
  2941. if (num_ents > 0) {
  2942. WARN_ON(be32_to_cpu(rpsc2_acc->port_info[0].pid) !=
  2943. bfa_ntoh3b(rport->pid));
  2944. bfa_trc(rport->fcs,
  2945. be32_to_cpu(rpsc2_acc->port_info[0].pid));
  2946. bfa_trc(rport->fcs,
  2947. be16_to_cpu(rpsc2_acc->port_info[0].speed));
  2948. bfa_trc(rport->fcs,
  2949. be16_to_cpu(rpsc2_acc->port_info[0].index));
  2950. bfa_trc(rport->fcs,
  2951. rpsc2_acc->port_info[0].type);
  2952. if (rpsc2_acc->port_info[0].speed == 0) {
  2953. bfa_sm_send_event(rpf, RPFSM_EVENT_RPSC_ERROR);
  2954. return;
  2955. }
  2956. rpf->rpsc_speed = fc_rpsc_operspeed_to_bfa_speed(
  2957. be16_to_cpu(rpsc2_acc->port_info[0].speed));
  2958. bfa_sm_send_event(rpf, RPFSM_EVENT_RPSC_COMP);
  2959. }
  2960. } else {
  2961. ls_rjt = (struct fc_ls_rjt_s *) BFA_FCXP_RSP_PLD(fcxp);
  2962. bfa_trc(rport->fcs, ls_rjt->reason_code);
  2963. bfa_trc(rport->fcs, ls_rjt->reason_code_expl);
  2964. rport->stats.rpsc_rejects++;
  2965. if (ls_rjt->reason_code == FC_LS_RJT_RSN_CMD_NOT_SUPP)
  2966. bfa_sm_send_event(rpf, RPFSM_EVENT_RPSC_FAIL);
  2967. else
  2968. bfa_sm_send_event(rpf, RPFSM_EVENT_RPSC_ERROR);
  2969. }
  2970. }