bfa_fcs_rport.c 76 KB

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