bfa_fcs_rport.c 88 KB

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