bfa_fcs_rport.c 75 KB

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