bfa_fcs_rport.c 73 KB

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