bfa_fcs_rport.c 73 KB

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