bfa_fcs_rport.c 82 KB

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