bfa_fcs_rport.c 78 KB

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