bfa_svc.c 116 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075
  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. #include "bfad_drv.h"
  18. #include "bfa_plog.h"
  19. #include "bfa_cs.h"
  20. #include "bfa_modules.h"
  21. BFA_TRC_FILE(HAL, FCXP);
  22. BFA_MODULE(fcxp);
  23. BFA_MODULE(sgpg);
  24. BFA_MODULE(lps);
  25. BFA_MODULE(fcport);
  26. BFA_MODULE(rport);
  27. BFA_MODULE(uf);
  28. /*
  29. * LPS related definitions
  30. */
  31. #define BFA_LPS_MIN_LPORTS (1)
  32. #define BFA_LPS_MAX_LPORTS (256)
  33. /*
  34. * Maximum Vports supported per physical port or vf.
  35. */
  36. #define BFA_LPS_MAX_VPORTS_SUPP_CB 255
  37. #define BFA_LPS_MAX_VPORTS_SUPP_CT 190
  38. /*
  39. * FC PORT related definitions
  40. */
  41. /*
  42. * The port is considered disabled if corresponding physical port or IOC are
  43. * disabled explicitly
  44. */
  45. #define BFA_PORT_IS_DISABLED(bfa) \
  46. ((bfa_fcport_is_disabled(bfa) == BFA_TRUE) || \
  47. (bfa_ioc_is_disabled(&bfa->ioc) == BFA_TRUE))
  48. /*
  49. * BFA port state machine events
  50. */
  51. enum bfa_fcport_sm_event {
  52. BFA_FCPORT_SM_START = 1, /* start port state machine */
  53. BFA_FCPORT_SM_STOP = 2, /* stop port state machine */
  54. BFA_FCPORT_SM_ENABLE = 3, /* enable port */
  55. BFA_FCPORT_SM_DISABLE = 4, /* disable port state machine */
  56. BFA_FCPORT_SM_FWRSP = 5, /* firmware enable/disable rsp */
  57. BFA_FCPORT_SM_LINKUP = 6, /* firmware linkup event */
  58. BFA_FCPORT_SM_LINKDOWN = 7, /* firmware linkup down */
  59. BFA_FCPORT_SM_QRESUME = 8, /* CQ space available */
  60. BFA_FCPORT_SM_HWFAIL = 9, /* IOC h/w failure */
  61. };
  62. /*
  63. * BFA port link notification state machine events
  64. */
  65. enum bfa_fcport_ln_sm_event {
  66. BFA_FCPORT_LN_SM_LINKUP = 1, /* linkup event */
  67. BFA_FCPORT_LN_SM_LINKDOWN = 2, /* linkdown event */
  68. BFA_FCPORT_LN_SM_NOTIFICATION = 3 /* done notification */
  69. };
  70. /*
  71. * RPORT related definitions
  72. */
  73. #define bfa_rport_offline_cb(__rp) do { \
  74. if ((__rp)->bfa->fcs) \
  75. bfa_cb_rport_offline((__rp)->rport_drv); \
  76. else { \
  77. bfa_cb_queue((__rp)->bfa, &(__rp)->hcb_qe, \
  78. __bfa_cb_rport_offline, (__rp)); \
  79. } \
  80. } while (0)
  81. #define bfa_rport_online_cb(__rp) do { \
  82. if ((__rp)->bfa->fcs) \
  83. bfa_cb_rport_online((__rp)->rport_drv); \
  84. else { \
  85. bfa_cb_queue((__rp)->bfa, &(__rp)->hcb_qe, \
  86. __bfa_cb_rport_online, (__rp)); \
  87. } \
  88. } while (0)
  89. /*
  90. * forward declarations FCXP related functions
  91. */
  92. static void __bfa_fcxp_send_cbfn(void *cbarg, bfa_boolean_t complete);
  93. static void hal_fcxp_rx_plog(struct bfa_s *bfa, struct bfa_fcxp_s *fcxp,
  94. struct bfi_fcxp_send_rsp_s *fcxp_rsp);
  95. static void hal_fcxp_tx_plog(struct bfa_s *bfa, u32 reqlen,
  96. struct bfa_fcxp_s *fcxp, struct fchs_s *fchs);
  97. static void bfa_fcxp_qresume(void *cbarg);
  98. static void bfa_fcxp_queue(struct bfa_fcxp_s *fcxp,
  99. struct bfi_fcxp_send_req_s *send_req);
  100. /*
  101. * forward declarations for LPS functions
  102. */
  103. static void bfa_lps_meminfo(struct bfa_iocfc_cfg_s *cfg, u32 *ndm_len,
  104. u32 *dm_len);
  105. static void bfa_lps_attach(struct bfa_s *bfa, void *bfad,
  106. struct bfa_iocfc_cfg_s *cfg,
  107. struct bfa_meminfo_s *meminfo,
  108. struct bfa_pcidev_s *pcidev);
  109. static void bfa_lps_detach(struct bfa_s *bfa);
  110. static void bfa_lps_start(struct bfa_s *bfa);
  111. static void bfa_lps_stop(struct bfa_s *bfa);
  112. static void bfa_lps_iocdisable(struct bfa_s *bfa);
  113. static void bfa_lps_login_rsp(struct bfa_s *bfa,
  114. struct bfi_lps_login_rsp_s *rsp);
  115. static void bfa_lps_logout_rsp(struct bfa_s *bfa,
  116. struct bfi_lps_logout_rsp_s *rsp);
  117. static void bfa_lps_reqq_resume(void *lps_arg);
  118. static void bfa_lps_free(struct bfa_lps_s *lps);
  119. static void bfa_lps_send_login(struct bfa_lps_s *lps);
  120. static void bfa_lps_send_logout(struct bfa_lps_s *lps);
  121. static void bfa_lps_send_set_n2n_pid(struct bfa_lps_s *lps);
  122. static void bfa_lps_login_comp(struct bfa_lps_s *lps);
  123. static void bfa_lps_logout_comp(struct bfa_lps_s *lps);
  124. static void bfa_lps_cvl_event(struct bfa_lps_s *lps);
  125. /*
  126. * forward declaration for LPS state machine
  127. */
  128. static void bfa_lps_sm_init(struct bfa_lps_s *lps, enum bfa_lps_event event);
  129. static void bfa_lps_sm_login(struct bfa_lps_s *lps, enum bfa_lps_event event);
  130. static void bfa_lps_sm_loginwait(struct bfa_lps_s *lps, enum bfa_lps_event
  131. event);
  132. static void bfa_lps_sm_online(struct bfa_lps_s *lps, enum bfa_lps_event event);
  133. static void bfa_lps_sm_online_n2n_pid_wait(struct bfa_lps_s *lps,
  134. enum bfa_lps_event event);
  135. static void bfa_lps_sm_logout(struct bfa_lps_s *lps, enum bfa_lps_event event);
  136. static void bfa_lps_sm_logowait(struct bfa_lps_s *lps, enum bfa_lps_event
  137. event);
  138. /*
  139. * forward declaration for FC Port functions
  140. */
  141. static bfa_boolean_t bfa_fcport_send_enable(struct bfa_fcport_s *fcport);
  142. static bfa_boolean_t bfa_fcport_send_disable(struct bfa_fcport_s *fcport);
  143. static void bfa_fcport_update_linkinfo(struct bfa_fcport_s *fcport);
  144. static void bfa_fcport_reset_linkinfo(struct bfa_fcport_s *fcport);
  145. static void bfa_fcport_set_wwns(struct bfa_fcport_s *fcport);
  146. static void __bfa_cb_fcport_event(void *cbarg, bfa_boolean_t complete);
  147. static void bfa_fcport_scn(struct bfa_fcport_s *fcport,
  148. enum bfa_port_linkstate event, bfa_boolean_t trunk);
  149. static void bfa_fcport_queue_cb(struct bfa_fcport_ln_s *ln,
  150. enum bfa_port_linkstate event);
  151. static void __bfa_cb_fcport_stats_clr(void *cbarg, bfa_boolean_t complete);
  152. static void bfa_fcport_stats_get_timeout(void *cbarg);
  153. static void bfa_fcport_stats_clr_timeout(void *cbarg);
  154. static void bfa_trunk_iocdisable(struct bfa_s *bfa);
  155. /*
  156. * forward declaration for FC PORT state machine
  157. */
  158. static void bfa_fcport_sm_uninit(struct bfa_fcport_s *fcport,
  159. enum bfa_fcport_sm_event event);
  160. static void bfa_fcport_sm_enabling_qwait(struct bfa_fcport_s *fcport,
  161. enum bfa_fcport_sm_event event);
  162. static void bfa_fcport_sm_enabling(struct bfa_fcport_s *fcport,
  163. enum bfa_fcport_sm_event event);
  164. static void bfa_fcport_sm_linkdown(struct bfa_fcport_s *fcport,
  165. enum bfa_fcport_sm_event event);
  166. static void bfa_fcport_sm_linkup(struct bfa_fcport_s *fcport,
  167. enum bfa_fcport_sm_event event);
  168. static void bfa_fcport_sm_disabling(struct bfa_fcport_s *fcport,
  169. enum bfa_fcport_sm_event event);
  170. static void bfa_fcport_sm_disabling_qwait(struct bfa_fcport_s *fcport,
  171. enum bfa_fcport_sm_event event);
  172. static void bfa_fcport_sm_toggling_qwait(struct bfa_fcport_s *fcport,
  173. enum bfa_fcport_sm_event event);
  174. static void bfa_fcport_sm_disabled(struct bfa_fcport_s *fcport,
  175. enum bfa_fcport_sm_event event);
  176. static void bfa_fcport_sm_stopped(struct bfa_fcport_s *fcport,
  177. enum bfa_fcport_sm_event event);
  178. static void bfa_fcport_sm_iocdown(struct bfa_fcport_s *fcport,
  179. enum bfa_fcport_sm_event event);
  180. static void bfa_fcport_sm_iocfail(struct bfa_fcport_s *fcport,
  181. enum bfa_fcport_sm_event event);
  182. static void bfa_fcport_ln_sm_dn(struct bfa_fcport_ln_s *ln,
  183. enum bfa_fcport_ln_sm_event event);
  184. static void bfa_fcport_ln_sm_dn_nf(struct bfa_fcport_ln_s *ln,
  185. enum bfa_fcport_ln_sm_event event);
  186. static void bfa_fcport_ln_sm_dn_up_nf(struct bfa_fcport_ln_s *ln,
  187. enum bfa_fcport_ln_sm_event event);
  188. static void bfa_fcport_ln_sm_up(struct bfa_fcport_ln_s *ln,
  189. enum bfa_fcport_ln_sm_event event);
  190. static void bfa_fcport_ln_sm_up_nf(struct bfa_fcport_ln_s *ln,
  191. enum bfa_fcport_ln_sm_event event);
  192. static void bfa_fcport_ln_sm_up_dn_nf(struct bfa_fcport_ln_s *ln,
  193. enum bfa_fcport_ln_sm_event event);
  194. static void bfa_fcport_ln_sm_up_dn_up_nf(struct bfa_fcport_ln_s *ln,
  195. enum bfa_fcport_ln_sm_event event);
  196. static struct bfa_sm_table_s hal_port_sm_table[] = {
  197. {BFA_SM(bfa_fcport_sm_uninit), BFA_PORT_ST_UNINIT},
  198. {BFA_SM(bfa_fcport_sm_enabling_qwait), BFA_PORT_ST_ENABLING_QWAIT},
  199. {BFA_SM(bfa_fcport_sm_enabling), BFA_PORT_ST_ENABLING},
  200. {BFA_SM(bfa_fcport_sm_linkdown), BFA_PORT_ST_LINKDOWN},
  201. {BFA_SM(bfa_fcport_sm_linkup), BFA_PORT_ST_LINKUP},
  202. {BFA_SM(bfa_fcport_sm_disabling_qwait), BFA_PORT_ST_DISABLING_QWAIT},
  203. {BFA_SM(bfa_fcport_sm_toggling_qwait), BFA_PORT_ST_TOGGLING_QWAIT},
  204. {BFA_SM(bfa_fcport_sm_disabling), BFA_PORT_ST_DISABLING},
  205. {BFA_SM(bfa_fcport_sm_disabled), BFA_PORT_ST_DISABLED},
  206. {BFA_SM(bfa_fcport_sm_stopped), BFA_PORT_ST_STOPPED},
  207. {BFA_SM(bfa_fcport_sm_iocdown), BFA_PORT_ST_IOCDOWN},
  208. {BFA_SM(bfa_fcport_sm_iocfail), BFA_PORT_ST_IOCDOWN},
  209. };
  210. /*
  211. * forward declaration for RPORT related functions
  212. */
  213. static struct bfa_rport_s *bfa_rport_alloc(struct bfa_rport_mod_s *rp_mod);
  214. static void bfa_rport_free(struct bfa_rport_s *rport);
  215. static bfa_boolean_t bfa_rport_send_fwcreate(struct bfa_rport_s *rp);
  216. static bfa_boolean_t bfa_rport_send_fwdelete(struct bfa_rport_s *rp);
  217. static bfa_boolean_t bfa_rport_send_fwspeed(struct bfa_rport_s *rp);
  218. static void __bfa_cb_rport_online(void *cbarg,
  219. bfa_boolean_t complete);
  220. static void __bfa_cb_rport_offline(void *cbarg,
  221. bfa_boolean_t complete);
  222. /*
  223. * forward declaration for RPORT state machine
  224. */
  225. static void bfa_rport_sm_uninit(struct bfa_rport_s *rp,
  226. enum bfa_rport_event event);
  227. static void bfa_rport_sm_created(struct bfa_rport_s *rp,
  228. enum bfa_rport_event event);
  229. static void bfa_rport_sm_fwcreate(struct bfa_rport_s *rp,
  230. enum bfa_rport_event event);
  231. static void bfa_rport_sm_online(struct bfa_rport_s *rp,
  232. enum bfa_rport_event event);
  233. static void bfa_rport_sm_fwdelete(struct bfa_rport_s *rp,
  234. enum bfa_rport_event event);
  235. static void bfa_rport_sm_offline(struct bfa_rport_s *rp,
  236. enum bfa_rport_event event);
  237. static void bfa_rport_sm_deleting(struct bfa_rport_s *rp,
  238. enum bfa_rport_event event);
  239. static void bfa_rport_sm_offline_pending(struct bfa_rport_s *rp,
  240. enum bfa_rport_event event);
  241. static void bfa_rport_sm_delete_pending(struct bfa_rport_s *rp,
  242. enum bfa_rport_event event);
  243. static void bfa_rport_sm_iocdisable(struct bfa_rport_s *rp,
  244. enum bfa_rport_event event);
  245. static void bfa_rport_sm_fwcreate_qfull(struct bfa_rport_s *rp,
  246. enum bfa_rport_event event);
  247. static void bfa_rport_sm_fwdelete_qfull(struct bfa_rport_s *rp,
  248. enum bfa_rport_event event);
  249. static void bfa_rport_sm_deleting_qfull(struct bfa_rport_s *rp,
  250. enum bfa_rport_event event);
  251. /*
  252. * PLOG related definitions
  253. */
  254. static int
  255. plkd_validate_logrec(struct bfa_plog_rec_s *pl_rec)
  256. {
  257. if ((pl_rec->log_type != BFA_PL_LOG_TYPE_INT) &&
  258. (pl_rec->log_type != BFA_PL_LOG_TYPE_STRING))
  259. return 1;
  260. if ((pl_rec->log_type != BFA_PL_LOG_TYPE_INT) &&
  261. (pl_rec->log_num_ints > BFA_PL_INT_LOG_SZ))
  262. return 1;
  263. return 0;
  264. }
  265. static u64
  266. bfa_get_log_time(void)
  267. {
  268. u64 system_time = 0;
  269. struct timeval tv;
  270. do_gettimeofday(&tv);
  271. /* We are interested in seconds only. */
  272. system_time = tv.tv_sec;
  273. return system_time;
  274. }
  275. static void
  276. bfa_plog_add(struct bfa_plog_s *plog, struct bfa_plog_rec_s *pl_rec)
  277. {
  278. u16 tail;
  279. struct bfa_plog_rec_s *pl_recp;
  280. if (plog->plog_enabled == 0)
  281. return;
  282. if (plkd_validate_logrec(pl_rec)) {
  283. WARN_ON(1);
  284. return;
  285. }
  286. tail = plog->tail;
  287. pl_recp = &(plog->plog_recs[tail]);
  288. memcpy(pl_recp, pl_rec, sizeof(struct bfa_plog_rec_s));
  289. pl_recp->tv = bfa_get_log_time();
  290. BFA_PL_LOG_REC_INCR(plog->tail);
  291. if (plog->head == plog->tail)
  292. BFA_PL_LOG_REC_INCR(plog->head);
  293. }
  294. void
  295. bfa_plog_init(struct bfa_plog_s *plog)
  296. {
  297. memset((char *)plog, 0, sizeof(struct bfa_plog_s));
  298. memcpy(plog->plog_sig, BFA_PL_SIG_STR, BFA_PL_SIG_LEN);
  299. plog->head = plog->tail = 0;
  300. plog->plog_enabled = 1;
  301. }
  302. void
  303. bfa_plog_str(struct bfa_plog_s *plog, enum bfa_plog_mid mid,
  304. enum bfa_plog_eid event,
  305. u16 misc, char *log_str)
  306. {
  307. struct bfa_plog_rec_s lp;
  308. if (plog->plog_enabled) {
  309. memset(&lp, 0, sizeof(struct bfa_plog_rec_s));
  310. lp.mid = mid;
  311. lp.eid = event;
  312. lp.log_type = BFA_PL_LOG_TYPE_STRING;
  313. lp.misc = misc;
  314. strncpy(lp.log_entry.string_log, log_str,
  315. BFA_PL_STRING_LOG_SZ - 1);
  316. lp.log_entry.string_log[BFA_PL_STRING_LOG_SZ - 1] = '\0';
  317. bfa_plog_add(plog, &lp);
  318. }
  319. }
  320. void
  321. bfa_plog_intarr(struct bfa_plog_s *plog, enum bfa_plog_mid mid,
  322. enum bfa_plog_eid event,
  323. u16 misc, u32 *intarr, u32 num_ints)
  324. {
  325. struct bfa_plog_rec_s lp;
  326. u32 i;
  327. if (num_ints > BFA_PL_INT_LOG_SZ)
  328. num_ints = BFA_PL_INT_LOG_SZ;
  329. if (plog->plog_enabled) {
  330. memset(&lp, 0, sizeof(struct bfa_plog_rec_s));
  331. lp.mid = mid;
  332. lp.eid = event;
  333. lp.log_type = BFA_PL_LOG_TYPE_INT;
  334. lp.misc = misc;
  335. for (i = 0; i < num_ints; i++)
  336. lp.log_entry.int_log[i] = intarr[i];
  337. lp.log_num_ints = (u8) num_ints;
  338. bfa_plog_add(plog, &lp);
  339. }
  340. }
  341. void
  342. bfa_plog_fchdr(struct bfa_plog_s *plog, enum bfa_plog_mid mid,
  343. enum bfa_plog_eid event,
  344. u16 misc, struct fchs_s *fchdr)
  345. {
  346. struct bfa_plog_rec_s lp;
  347. u32 *tmp_int = (u32 *) fchdr;
  348. u32 ints[BFA_PL_INT_LOG_SZ];
  349. if (plog->plog_enabled) {
  350. memset(&lp, 0, sizeof(struct bfa_plog_rec_s));
  351. ints[0] = tmp_int[0];
  352. ints[1] = tmp_int[1];
  353. ints[2] = tmp_int[4];
  354. bfa_plog_intarr(plog, mid, event, misc, ints, 3);
  355. }
  356. }
  357. void
  358. bfa_plog_fchdr_and_pl(struct bfa_plog_s *plog, enum bfa_plog_mid mid,
  359. enum bfa_plog_eid event, u16 misc, struct fchs_s *fchdr,
  360. u32 pld_w0)
  361. {
  362. struct bfa_plog_rec_s lp;
  363. u32 *tmp_int = (u32 *) fchdr;
  364. u32 ints[BFA_PL_INT_LOG_SZ];
  365. if (plog->plog_enabled) {
  366. memset(&lp, 0, sizeof(struct bfa_plog_rec_s));
  367. ints[0] = tmp_int[0];
  368. ints[1] = tmp_int[1];
  369. ints[2] = tmp_int[4];
  370. ints[3] = pld_w0;
  371. bfa_plog_intarr(plog, mid, event, misc, ints, 4);
  372. }
  373. }
  374. /*
  375. * fcxp_pvt BFA FCXP private functions
  376. */
  377. static void
  378. claim_fcxp_req_rsp_mem(struct bfa_fcxp_mod_s *mod, struct bfa_meminfo_s *mi)
  379. {
  380. u8 *dm_kva = NULL;
  381. u64 dm_pa;
  382. u32 buf_pool_sz;
  383. dm_kva = bfa_meminfo_dma_virt(mi);
  384. dm_pa = bfa_meminfo_dma_phys(mi);
  385. buf_pool_sz = mod->req_pld_sz * mod->num_fcxps;
  386. /*
  387. * Initialize the fcxp req payload list
  388. */
  389. mod->req_pld_list_kva = dm_kva;
  390. mod->req_pld_list_pa = dm_pa;
  391. dm_kva += buf_pool_sz;
  392. dm_pa += buf_pool_sz;
  393. memset(mod->req_pld_list_kva, 0, buf_pool_sz);
  394. /*
  395. * Initialize the fcxp rsp payload list
  396. */
  397. buf_pool_sz = mod->rsp_pld_sz * mod->num_fcxps;
  398. mod->rsp_pld_list_kva = dm_kva;
  399. mod->rsp_pld_list_pa = dm_pa;
  400. dm_kva += buf_pool_sz;
  401. dm_pa += buf_pool_sz;
  402. memset(mod->rsp_pld_list_kva, 0, buf_pool_sz);
  403. bfa_meminfo_dma_virt(mi) = dm_kva;
  404. bfa_meminfo_dma_phys(mi) = dm_pa;
  405. }
  406. static void
  407. claim_fcxps_mem(struct bfa_fcxp_mod_s *mod, struct bfa_meminfo_s *mi)
  408. {
  409. u16 i;
  410. struct bfa_fcxp_s *fcxp;
  411. fcxp = (struct bfa_fcxp_s *) bfa_meminfo_kva(mi);
  412. memset(fcxp, 0, sizeof(struct bfa_fcxp_s) * mod->num_fcxps);
  413. INIT_LIST_HEAD(&mod->fcxp_free_q);
  414. INIT_LIST_HEAD(&mod->fcxp_active_q);
  415. mod->fcxp_list = fcxp;
  416. for (i = 0; i < mod->num_fcxps; i++) {
  417. fcxp->fcxp_mod = mod;
  418. fcxp->fcxp_tag = i;
  419. list_add_tail(&fcxp->qe, &mod->fcxp_free_q);
  420. bfa_reqq_winit(&fcxp->reqq_wqe, bfa_fcxp_qresume, fcxp);
  421. fcxp->reqq_waiting = BFA_FALSE;
  422. fcxp = fcxp + 1;
  423. }
  424. bfa_meminfo_kva(mi) = (void *)fcxp;
  425. }
  426. static void
  427. bfa_fcxp_meminfo(struct bfa_iocfc_cfg_s *cfg, u32 *ndm_len,
  428. u32 *dm_len)
  429. {
  430. u16 num_fcxp_reqs = cfg->fwcfg.num_fcxp_reqs;
  431. if (num_fcxp_reqs == 0)
  432. return;
  433. /*
  434. * Account for req/rsp payload
  435. */
  436. *dm_len += BFA_FCXP_MAX_IBUF_SZ * num_fcxp_reqs;
  437. if (cfg->drvcfg.min_cfg)
  438. *dm_len += BFA_FCXP_MAX_IBUF_SZ * num_fcxp_reqs;
  439. else
  440. *dm_len += BFA_FCXP_MAX_LBUF_SZ * num_fcxp_reqs;
  441. /*
  442. * Account for fcxp structs
  443. */
  444. *ndm_len += sizeof(struct bfa_fcxp_s) * num_fcxp_reqs;
  445. }
  446. static void
  447. bfa_fcxp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
  448. struct bfa_meminfo_s *meminfo, struct bfa_pcidev_s *pcidev)
  449. {
  450. struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa);
  451. memset(mod, 0, sizeof(struct bfa_fcxp_mod_s));
  452. mod->bfa = bfa;
  453. mod->num_fcxps = cfg->fwcfg.num_fcxp_reqs;
  454. /*
  455. * Initialize FCXP request and response payload sizes.
  456. */
  457. mod->req_pld_sz = mod->rsp_pld_sz = BFA_FCXP_MAX_IBUF_SZ;
  458. if (!cfg->drvcfg.min_cfg)
  459. mod->rsp_pld_sz = BFA_FCXP_MAX_LBUF_SZ;
  460. INIT_LIST_HEAD(&mod->wait_q);
  461. claim_fcxp_req_rsp_mem(mod, meminfo);
  462. claim_fcxps_mem(mod, meminfo);
  463. }
  464. static void
  465. bfa_fcxp_detach(struct bfa_s *bfa)
  466. {
  467. }
  468. static void
  469. bfa_fcxp_start(struct bfa_s *bfa)
  470. {
  471. }
  472. static void
  473. bfa_fcxp_stop(struct bfa_s *bfa)
  474. {
  475. }
  476. static void
  477. bfa_fcxp_iocdisable(struct bfa_s *bfa)
  478. {
  479. struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa);
  480. struct bfa_fcxp_s *fcxp;
  481. struct list_head *qe, *qen;
  482. list_for_each_safe(qe, qen, &mod->fcxp_active_q) {
  483. fcxp = (struct bfa_fcxp_s *) qe;
  484. if (fcxp->caller == NULL) {
  485. fcxp->send_cbfn(fcxp->caller, fcxp, fcxp->send_cbarg,
  486. BFA_STATUS_IOC_FAILURE, 0, 0, NULL);
  487. bfa_fcxp_free(fcxp);
  488. } else {
  489. fcxp->rsp_status = BFA_STATUS_IOC_FAILURE;
  490. bfa_cb_queue(bfa, &fcxp->hcb_qe,
  491. __bfa_fcxp_send_cbfn, fcxp);
  492. }
  493. }
  494. }
  495. static struct bfa_fcxp_s *
  496. bfa_fcxp_get(struct bfa_fcxp_mod_s *fm)
  497. {
  498. struct bfa_fcxp_s *fcxp;
  499. bfa_q_deq(&fm->fcxp_free_q, &fcxp);
  500. if (fcxp)
  501. list_add_tail(&fcxp->qe, &fm->fcxp_active_q);
  502. return fcxp;
  503. }
  504. static void
  505. bfa_fcxp_init_reqrsp(struct bfa_fcxp_s *fcxp,
  506. struct bfa_s *bfa,
  507. u8 *use_ibuf,
  508. u32 *nr_sgles,
  509. bfa_fcxp_get_sgaddr_t *r_sga_cbfn,
  510. bfa_fcxp_get_sglen_t *r_sglen_cbfn,
  511. struct list_head *r_sgpg_q,
  512. int n_sgles,
  513. bfa_fcxp_get_sgaddr_t sga_cbfn,
  514. bfa_fcxp_get_sglen_t sglen_cbfn)
  515. {
  516. WARN_ON(bfa == NULL);
  517. bfa_trc(bfa, fcxp->fcxp_tag);
  518. if (n_sgles == 0) {
  519. *use_ibuf = 1;
  520. } else {
  521. WARN_ON(*sga_cbfn == NULL);
  522. WARN_ON(*sglen_cbfn == NULL);
  523. *use_ibuf = 0;
  524. *r_sga_cbfn = sga_cbfn;
  525. *r_sglen_cbfn = sglen_cbfn;
  526. *nr_sgles = n_sgles;
  527. /*
  528. * alloc required sgpgs
  529. */
  530. if (n_sgles > BFI_SGE_INLINE)
  531. WARN_ON(1);
  532. }
  533. }
  534. static void
  535. bfa_fcxp_init(struct bfa_fcxp_s *fcxp,
  536. void *caller, struct bfa_s *bfa, int nreq_sgles,
  537. int nrsp_sgles, bfa_fcxp_get_sgaddr_t req_sga_cbfn,
  538. bfa_fcxp_get_sglen_t req_sglen_cbfn,
  539. bfa_fcxp_get_sgaddr_t rsp_sga_cbfn,
  540. bfa_fcxp_get_sglen_t rsp_sglen_cbfn)
  541. {
  542. WARN_ON(bfa == NULL);
  543. bfa_trc(bfa, fcxp->fcxp_tag);
  544. fcxp->caller = caller;
  545. bfa_fcxp_init_reqrsp(fcxp, bfa,
  546. &fcxp->use_ireqbuf, &fcxp->nreq_sgles, &fcxp->req_sga_cbfn,
  547. &fcxp->req_sglen_cbfn, &fcxp->req_sgpg_q,
  548. nreq_sgles, req_sga_cbfn, req_sglen_cbfn);
  549. bfa_fcxp_init_reqrsp(fcxp, bfa,
  550. &fcxp->use_irspbuf, &fcxp->nrsp_sgles, &fcxp->rsp_sga_cbfn,
  551. &fcxp->rsp_sglen_cbfn, &fcxp->rsp_sgpg_q,
  552. nrsp_sgles, rsp_sga_cbfn, rsp_sglen_cbfn);
  553. }
  554. static void
  555. bfa_fcxp_put(struct bfa_fcxp_s *fcxp)
  556. {
  557. struct bfa_fcxp_mod_s *mod = fcxp->fcxp_mod;
  558. struct bfa_fcxp_wqe_s *wqe;
  559. bfa_q_deq(&mod->wait_q, &wqe);
  560. if (wqe) {
  561. bfa_trc(mod->bfa, fcxp->fcxp_tag);
  562. bfa_fcxp_init(fcxp, wqe->caller, wqe->bfa, wqe->nreq_sgles,
  563. wqe->nrsp_sgles, wqe->req_sga_cbfn,
  564. wqe->req_sglen_cbfn, wqe->rsp_sga_cbfn,
  565. wqe->rsp_sglen_cbfn);
  566. wqe->alloc_cbfn(wqe->alloc_cbarg, fcxp);
  567. return;
  568. }
  569. WARN_ON(!bfa_q_is_on_q(&mod->fcxp_active_q, fcxp));
  570. list_del(&fcxp->qe);
  571. list_add_tail(&fcxp->qe, &mod->fcxp_free_q);
  572. }
  573. static void
  574. bfa_fcxp_null_comp(void *bfad_fcxp, struct bfa_fcxp_s *fcxp, void *cbarg,
  575. bfa_status_t req_status, u32 rsp_len,
  576. u32 resid_len, struct fchs_s *rsp_fchs)
  577. {
  578. /* discarded fcxp completion */
  579. }
  580. static void
  581. __bfa_fcxp_send_cbfn(void *cbarg, bfa_boolean_t complete)
  582. {
  583. struct bfa_fcxp_s *fcxp = cbarg;
  584. if (complete) {
  585. fcxp->send_cbfn(fcxp->caller, fcxp, fcxp->send_cbarg,
  586. fcxp->rsp_status, fcxp->rsp_len,
  587. fcxp->residue_len, &fcxp->rsp_fchs);
  588. } else {
  589. bfa_fcxp_free(fcxp);
  590. }
  591. }
  592. static void
  593. hal_fcxp_send_comp(struct bfa_s *bfa, struct bfi_fcxp_send_rsp_s *fcxp_rsp)
  594. {
  595. struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa);
  596. struct bfa_fcxp_s *fcxp;
  597. u16 fcxp_tag = be16_to_cpu(fcxp_rsp->fcxp_tag);
  598. bfa_trc(bfa, fcxp_tag);
  599. fcxp_rsp->rsp_len = be32_to_cpu(fcxp_rsp->rsp_len);
  600. /*
  601. * @todo f/w should not set residue to non-0 when everything
  602. * is received.
  603. */
  604. if (fcxp_rsp->req_status == BFA_STATUS_OK)
  605. fcxp_rsp->residue_len = 0;
  606. else
  607. fcxp_rsp->residue_len = be32_to_cpu(fcxp_rsp->residue_len);
  608. fcxp = BFA_FCXP_FROM_TAG(mod, fcxp_tag);
  609. WARN_ON(fcxp->send_cbfn == NULL);
  610. hal_fcxp_rx_plog(mod->bfa, fcxp, fcxp_rsp);
  611. if (fcxp->send_cbfn != NULL) {
  612. bfa_trc(mod->bfa, (NULL == fcxp->caller));
  613. if (fcxp->caller == NULL) {
  614. fcxp->send_cbfn(fcxp->caller, fcxp, fcxp->send_cbarg,
  615. fcxp_rsp->req_status, fcxp_rsp->rsp_len,
  616. fcxp_rsp->residue_len, &fcxp_rsp->fchs);
  617. /*
  618. * fcxp automatically freed on return from the callback
  619. */
  620. bfa_fcxp_free(fcxp);
  621. } else {
  622. fcxp->rsp_status = fcxp_rsp->req_status;
  623. fcxp->rsp_len = fcxp_rsp->rsp_len;
  624. fcxp->residue_len = fcxp_rsp->residue_len;
  625. fcxp->rsp_fchs = fcxp_rsp->fchs;
  626. bfa_cb_queue(bfa, &fcxp->hcb_qe,
  627. __bfa_fcxp_send_cbfn, fcxp);
  628. }
  629. } else {
  630. bfa_trc(bfa, (NULL == fcxp->send_cbfn));
  631. }
  632. }
  633. static void
  634. hal_fcxp_set_local_sges(struct bfi_sge_s *sge, u32 reqlen, u64 req_pa)
  635. {
  636. union bfi_addr_u sga_zero = { {0} };
  637. sge->sg_len = reqlen;
  638. sge->flags = BFI_SGE_DATA_LAST;
  639. bfa_dma_addr_set(sge[0].sga, req_pa);
  640. bfa_sge_to_be(sge);
  641. sge++;
  642. sge->sga = sga_zero;
  643. sge->sg_len = reqlen;
  644. sge->flags = BFI_SGE_PGDLEN;
  645. bfa_sge_to_be(sge);
  646. }
  647. static void
  648. hal_fcxp_tx_plog(struct bfa_s *bfa, u32 reqlen, struct bfa_fcxp_s *fcxp,
  649. struct fchs_s *fchs)
  650. {
  651. /*
  652. * TODO: TX ox_id
  653. */
  654. if (reqlen > 0) {
  655. if (fcxp->use_ireqbuf) {
  656. u32 pld_w0 =
  657. *((u32 *) BFA_FCXP_REQ_PLD(fcxp));
  658. bfa_plog_fchdr_and_pl(bfa->plog, BFA_PL_MID_HAL_FCXP,
  659. BFA_PL_EID_TX,
  660. reqlen + sizeof(struct fchs_s), fchs,
  661. pld_w0);
  662. } else {
  663. bfa_plog_fchdr(bfa->plog, BFA_PL_MID_HAL_FCXP,
  664. BFA_PL_EID_TX,
  665. reqlen + sizeof(struct fchs_s),
  666. fchs);
  667. }
  668. } else {
  669. bfa_plog_fchdr(bfa->plog, BFA_PL_MID_HAL_FCXP, BFA_PL_EID_TX,
  670. reqlen + sizeof(struct fchs_s), fchs);
  671. }
  672. }
  673. static void
  674. hal_fcxp_rx_plog(struct bfa_s *bfa, struct bfa_fcxp_s *fcxp,
  675. struct bfi_fcxp_send_rsp_s *fcxp_rsp)
  676. {
  677. if (fcxp_rsp->rsp_len > 0) {
  678. if (fcxp->use_irspbuf) {
  679. u32 pld_w0 =
  680. *((u32 *) BFA_FCXP_RSP_PLD(fcxp));
  681. bfa_plog_fchdr_and_pl(bfa->plog, BFA_PL_MID_HAL_FCXP,
  682. BFA_PL_EID_RX,
  683. (u16) fcxp_rsp->rsp_len,
  684. &fcxp_rsp->fchs, pld_w0);
  685. } else {
  686. bfa_plog_fchdr(bfa->plog, BFA_PL_MID_HAL_FCXP,
  687. BFA_PL_EID_RX,
  688. (u16) fcxp_rsp->rsp_len,
  689. &fcxp_rsp->fchs);
  690. }
  691. } else {
  692. bfa_plog_fchdr(bfa->plog, BFA_PL_MID_HAL_FCXP, BFA_PL_EID_RX,
  693. (u16) fcxp_rsp->rsp_len, &fcxp_rsp->fchs);
  694. }
  695. }
  696. /*
  697. * Handler to resume sending fcxp when space in available in cpe queue.
  698. */
  699. static void
  700. bfa_fcxp_qresume(void *cbarg)
  701. {
  702. struct bfa_fcxp_s *fcxp = cbarg;
  703. struct bfa_s *bfa = fcxp->fcxp_mod->bfa;
  704. struct bfi_fcxp_send_req_s *send_req;
  705. fcxp->reqq_waiting = BFA_FALSE;
  706. send_req = bfa_reqq_next(bfa, BFA_REQQ_FCXP);
  707. bfa_fcxp_queue(fcxp, send_req);
  708. }
  709. /*
  710. * Queue fcxp send request to foimrware.
  711. */
  712. static void
  713. bfa_fcxp_queue(struct bfa_fcxp_s *fcxp, struct bfi_fcxp_send_req_s *send_req)
  714. {
  715. struct bfa_s *bfa = fcxp->fcxp_mod->bfa;
  716. struct bfa_fcxp_req_info_s *reqi = &fcxp->req_info;
  717. struct bfa_fcxp_rsp_info_s *rspi = &fcxp->rsp_info;
  718. struct bfa_rport_s *rport = reqi->bfa_rport;
  719. bfi_h2i_set(send_req->mh, BFI_MC_FCXP, BFI_FCXP_H2I_SEND_REQ,
  720. bfa_lpuid(bfa));
  721. send_req->fcxp_tag = cpu_to_be16(fcxp->fcxp_tag);
  722. if (rport) {
  723. send_req->rport_fw_hndl = rport->fw_handle;
  724. send_req->max_frmsz = cpu_to_be16(rport->rport_info.max_frmsz);
  725. if (send_req->max_frmsz == 0)
  726. send_req->max_frmsz = cpu_to_be16(FC_MAX_PDUSZ);
  727. } else {
  728. send_req->rport_fw_hndl = 0;
  729. send_req->max_frmsz = cpu_to_be16(FC_MAX_PDUSZ);
  730. }
  731. send_req->vf_id = cpu_to_be16(reqi->vf_id);
  732. send_req->lp_tag = reqi->lp_tag;
  733. send_req->class = reqi->class;
  734. send_req->rsp_timeout = rspi->rsp_timeout;
  735. send_req->cts = reqi->cts;
  736. send_req->fchs = reqi->fchs;
  737. send_req->req_len = cpu_to_be32(reqi->req_tot_len);
  738. send_req->rsp_maxlen = cpu_to_be32(rspi->rsp_maxlen);
  739. /*
  740. * setup req sgles
  741. */
  742. if (fcxp->use_ireqbuf == 1) {
  743. hal_fcxp_set_local_sges(send_req->req_sge, reqi->req_tot_len,
  744. BFA_FCXP_REQ_PLD_PA(fcxp));
  745. } else {
  746. if (fcxp->nreq_sgles > 0) {
  747. WARN_ON(fcxp->nreq_sgles != 1);
  748. hal_fcxp_set_local_sges(send_req->req_sge,
  749. reqi->req_tot_len,
  750. fcxp->req_sga_cbfn(fcxp->caller,
  751. 0));
  752. } else {
  753. WARN_ON(reqi->req_tot_len != 0);
  754. hal_fcxp_set_local_sges(send_req->rsp_sge, 0, 0);
  755. }
  756. }
  757. /*
  758. * setup rsp sgles
  759. */
  760. if (fcxp->use_irspbuf == 1) {
  761. WARN_ON(rspi->rsp_maxlen > BFA_FCXP_MAX_LBUF_SZ);
  762. hal_fcxp_set_local_sges(send_req->rsp_sge, rspi->rsp_maxlen,
  763. BFA_FCXP_RSP_PLD_PA(fcxp));
  764. } else {
  765. if (fcxp->nrsp_sgles > 0) {
  766. WARN_ON(fcxp->nrsp_sgles != 1);
  767. hal_fcxp_set_local_sges(send_req->rsp_sge,
  768. rspi->rsp_maxlen,
  769. fcxp->rsp_sga_cbfn(fcxp->caller,
  770. 0));
  771. } else {
  772. WARN_ON(rspi->rsp_maxlen != 0);
  773. hal_fcxp_set_local_sges(send_req->rsp_sge, 0, 0);
  774. }
  775. }
  776. hal_fcxp_tx_plog(bfa, reqi->req_tot_len, fcxp, &reqi->fchs);
  777. bfa_reqq_produce(bfa, BFA_REQQ_FCXP);
  778. bfa_trc(bfa, bfa_reqq_pi(bfa, BFA_REQQ_FCXP));
  779. bfa_trc(bfa, bfa_reqq_ci(bfa, BFA_REQQ_FCXP));
  780. }
  781. /*
  782. * Allocate an FCXP instance to send a response or to send a request
  783. * that has a response. Request/response buffers are allocated by caller.
  784. *
  785. * @param[in] bfa BFA bfa instance
  786. * @param[in] nreq_sgles Number of SG elements required for request
  787. * buffer. 0, if fcxp internal buffers are used.
  788. * Use bfa_fcxp_get_reqbuf() to get the
  789. * internal req buffer.
  790. * @param[in] req_sgles SG elements describing request buffer. Will be
  791. * copied in by BFA and hence can be freed on
  792. * return from this function.
  793. * @param[in] get_req_sga function ptr to be called to get a request SG
  794. * Address (given the sge index).
  795. * @param[in] get_req_sglen function ptr to be called to get a request SG
  796. * len (given the sge index).
  797. * @param[in] get_rsp_sga function ptr to be called to get a response SG
  798. * Address (given the sge index).
  799. * @param[in] get_rsp_sglen function ptr to be called to get a response SG
  800. * len (given the sge index).
  801. *
  802. * @return FCXP instance. NULL on failure.
  803. */
  804. struct bfa_fcxp_s *
  805. bfa_fcxp_alloc(void *caller, struct bfa_s *bfa, int nreq_sgles,
  806. int nrsp_sgles, bfa_fcxp_get_sgaddr_t req_sga_cbfn,
  807. bfa_fcxp_get_sglen_t req_sglen_cbfn,
  808. bfa_fcxp_get_sgaddr_t rsp_sga_cbfn,
  809. bfa_fcxp_get_sglen_t rsp_sglen_cbfn)
  810. {
  811. struct bfa_fcxp_s *fcxp = NULL;
  812. WARN_ON(bfa == NULL);
  813. fcxp = bfa_fcxp_get(BFA_FCXP_MOD(bfa));
  814. if (fcxp == NULL)
  815. return NULL;
  816. bfa_trc(bfa, fcxp->fcxp_tag);
  817. bfa_fcxp_init(fcxp, caller, bfa, nreq_sgles, nrsp_sgles, req_sga_cbfn,
  818. req_sglen_cbfn, rsp_sga_cbfn, rsp_sglen_cbfn);
  819. return fcxp;
  820. }
  821. /*
  822. * Get the internal request buffer pointer
  823. *
  824. * @param[in] fcxp BFA fcxp pointer
  825. *
  826. * @return pointer to the internal request buffer
  827. */
  828. void *
  829. bfa_fcxp_get_reqbuf(struct bfa_fcxp_s *fcxp)
  830. {
  831. struct bfa_fcxp_mod_s *mod = fcxp->fcxp_mod;
  832. void *reqbuf;
  833. WARN_ON(fcxp->use_ireqbuf != 1);
  834. reqbuf = ((u8 *)mod->req_pld_list_kva) +
  835. fcxp->fcxp_tag * mod->req_pld_sz;
  836. return reqbuf;
  837. }
  838. u32
  839. bfa_fcxp_get_reqbufsz(struct bfa_fcxp_s *fcxp)
  840. {
  841. struct bfa_fcxp_mod_s *mod = fcxp->fcxp_mod;
  842. return mod->req_pld_sz;
  843. }
  844. /*
  845. * Get the internal response buffer pointer
  846. *
  847. * @param[in] fcxp BFA fcxp pointer
  848. *
  849. * @return pointer to the internal request buffer
  850. */
  851. void *
  852. bfa_fcxp_get_rspbuf(struct bfa_fcxp_s *fcxp)
  853. {
  854. struct bfa_fcxp_mod_s *mod = fcxp->fcxp_mod;
  855. void *rspbuf;
  856. WARN_ON(fcxp->use_irspbuf != 1);
  857. rspbuf = ((u8 *)mod->rsp_pld_list_kva) +
  858. fcxp->fcxp_tag * mod->rsp_pld_sz;
  859. return rspbuf;
  860. }
  861. /*
  862. * Free the BFA FCXP
  863. *
  864. * @param[in] fcxp BFA fcxp pointer
  865. *
  866. * @return void
  867. */
  868. void
  869. bfa_fcxp_free(struct bfa_fcxp_s *fcxp)
  870. {
  871. struct bfa_fcxp_mod_s *mod = fcxp->fcxp_mod;
  872. WARN_ON(fcxp == NULL);
  873. bfa_trc(mod->bfa, fcxp->fcxp_tag);
  874. bfa_fcxp_put(fcxp);
  875. }
  876. /*
  877. * Send a FCXP request
  878. *
  879. * @param[in] fcxp BFA fcxp pointer
  880. * @param[in] rport BFA rport pointer. Could be left NULL for WKA rports
  881. * @param[in] vf_id virtual Fabric ID
  882. * @param[in] lp_tag lport tag
  883. * @param[in] cts use Continous sequence
  884. * @param[in] cos fc Class of Service
  885. * @param[in] reqlen request length, does not include FCHS length
  886. * @param[in] fchs fc Header Pointer. The header content will be copied
  887. * in by BFA.
  888. *
  889. * @param[in] cbfn call back function to be called on receiving
  890. * the response
  891. * @param[in] cbarg arg for cbfn
  892. * @param[in] rsp_timeout
  893. * response timeout
  894. *
  895. * @return bfa_status_t
  896. */
  897. void
  898. bfa_fcxp_send(struct bfa_fcxp_s *fcxp, struct bfa_rport_s *rport,
  899. u16 vf_id, u8 lp_tag, bfa_boolean_t cts, enum fc_cos cos,
  900. u32 reqlen, struct fchs_s *fchs, bfa_cb_fcxp_send_t cbfn,
  901. void *cbarg, u32 rsp_maxlen, u8 rsp_timeout)
  902. {
  903. struct bfa_s *bfa = fcxp->fcxp_mod->bfa;
  904. struct bfa_fcxp_req_info_s *reqi = &fcxp->req_info;
  905. struct bfa_fcxp_rsp_info_s *rspi = &fcxp->rsp_info;
  906. struct bfi_fcxp_send_req_s *send_req;
  907. bfa_trc(bfa, fcxp->fcxp_tag);
  908. /*
  909. * setup request/response info
  910. */
  911. reqi->bfa_rport = rport;
  912. reqi->vf_id = vf_id;
  913. reqi->lp_tag = lp_tag;
  914. reqi->class = cos;
  915. rspi->rsp_timeout = rsp_timeout;
  916. reqi->cts = cts;
  917. reqi->fchs = *fchs;
  918. reqi->req_tot_len = reqlen;
  919. rspi->rsp_maxlen = rsp_maxlen;
  920. fcxp->send_cbfn = cbfn ? cbfn : bfa_fcxp_null_comp;
  921. fcxp->send_cbarg = cbarg;
  922. /*
  923. * If no room in CPE queue, wait for space in request queue
  924. */
  925. send_req = bfa_reqq_next(bfa, BFA_REQQ_FCXP);
  926. if (!send_req) {
  927. bfa_trc(bfa, fcxp->fcxp_tag);
  928. fcxp->reqq_waiting = BFA_TRUE;
  929. bfa_reqq_wait(bfa, BFA_REQQ_FCXP, &fcxp->reqq_wqe);
  930. return;
  931. }
  932. bfa_fcxp_queue(fcxp, send_req);
  933. }
  934. /*
  935. * Abort a BFA FCXP
  936. *
  937. * @param[in] fcxp BFA fcxp pointer
  938. *
  939. * @return void
  940. */
  941. bfa_status_t
  942. bfa_fcxp_abort(struct bfa_fcxp_s *fcxp)
  943. {
  944. bfa_trc(fcxp->fcxp_mod->bfa, fcxp->fcxp_tag);
  945. WARN_ON(1);
  946. return BFA_STATUS_OK;
  947. }
  948. void
  949. bfa_fcxp_alloc_wait(struct bfa_s *bfa, struct bfa_fcxp_wqe_s *wqe,
  950. bfa_fcxp_alloc_cbfn_t alloc_cbfn, void *alloc_cbarg,
  951. void *caller, int nreq_sgles,
  952. int nrsp_sgles, bfa_fcxp_get_sgaddr_t req_sga_cbfn,
  953. bfa_fcxp_get_sglen_t req_sglen_cbfn,
  954. bfa_fcxp_get_sgaddr_t rsp_sga_cbfn,
  955. bfa_fcxp_get_sglen_t rsp_sglen_cbfn)
  956. {
  957. struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa);
  958. WARN_ON(!list_empty(&mod->fcxp_free_q));
  959. wqe->alloc_cbfn = alloc_cbfn;
  960. wqe->alloc_cbarg = alloc_cbarg;
  961. wqe->caller = caller;
  962. wqe->bfa = bfa;
  963. wqe->nreq_sgles = nreq_sgles;
  964. wqe->nrsp_sgles = nrsp_sgles;
  965. wqe->req_sga_cbfn = req_sga_cbfn;
  966. wqe->req_sglen_cbfn = req_sglen_cbfn;
  967. wqe->rsp_sga_cbfn = rsp_sga_cbfn;
  968. wqe->rsp_sglen_cbfn = rsp_sglen_cbfn;
  969. list_add_tail(&wqe->qe, &mod->wait_q);
  970. }
  971. void
  972. bfa_fcxp_walloc_cancel(struct bfa_s *bfa, struct bfa_fcxp_wqe_s *wqe)
  973. {
  974. struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa);
  975. WARN_ON(!bfa_q_is_on_q(&mod->wait_q, wqe));
  976. list_del(&wqe->qe);
  977. }
  978. void
  979. bfa_fcxp_discard(struct bfa_fcxp_s *fcxp)
  980. {
  981. /*
  982. * If waiting for room in request queue, cancel reqq wait
  983. * and free fcxp.
  984. */
  985. if (fcxp->reqq_waiting) {
  986. fcxp->reqq_waiting = BFA_FALSE;
  987. bfa_reqq_wcancel(&fcxp->reqq_wqe);
  988. bfa_fcxp_free(fcxp);
  989. return;
  990. }
  991. fcxp->send_cbfn = bfa_fcxp_null_comp;
  992. }
  993. void
  994. bfa_fcxp_isr(struct bfa_s *bfa, struct bfi_msg_s *msg)
  995. {
  996. switch (msg->mhdr.msg_id) {
  997. case BFI_FCXP_I2H_SEND_RSP:
  998. hal_fcxp_send_comp(bfa, (struct bfi_fcxp_send_rsp_s *) msg);
  999. break;
  1000. default:
  1001. bfa_trc(bfa, msg->mhdr.msg_id);
  1002. WARN_ON(1);
  1003. }
  1004. }
  1005. u32
  1006. bfa_fcxp_get_maxrsp(struct bfa_s *bfa)
  1007. {
  1008. struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa);
  1009. return mod->rsp_pld_sz;
  1010. }
  1011. /*
  1012. * BFA LPS state machine functions
  1013. */
  1014. /*
  1015. * Init state -- no login
  1016. */
  1017. static void
  1018. bfa_lps_sm_init(struct bfa_lps_s *lps, enum bfa_lps_event event)
  1019. {
  1020. bfa_trc(lps->bfa, lps->lp_tag);
  1021. bfa_trc(lps->bfa, event);
  1022. switch (event) {
  1023. case BFA_LPS_SM_LOGIN:
  1024. if (bfa_reqq_full(lps->bfa, lps->reqq)) {
  1025. bfa_sm_set_state(lps, bfa_lps_sm_loginwait);
  1026. bfa_reqq_wait(lps->bfa, lps->reqq, &lps->wqe);
  1027. } else {
  1028. bfa_sm_set_state(lps, bfa_lps_sm_login);
  1029. bfa_lps_send_login(lps);
  1030. }
  1031. if (lps->fdisc)
  1032. bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
  1033. BFA_PL_EID_LOGIN, 0, "FDISC Request");
  1034. else
  1035. bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
  1036. BFA_PL_EID_LOGIN, 0, "FLOGI Request");
  1037. break;
  1038. case BFA_LPS_SM_LOGOUT:
  1039. bfa_lps_logout_comp(lps);
  1040. break;
  1041. case BFA_LPS_SM_DELETE:
  1042. bfa_lps_free(lps);
  1043. break;
  1044. case BFA_LPS_SM_RX_CVL:
  1045. case BFA_LPS_SM_OFFLINE:
  1046. break;
  1047. case BFA_LPS_SM_FWRSP:
  1048. /*
  1049. * Could happen when fabric detects loopback and discards
  1050. * the lps request. Fw will eventually sent out the timeout
  1051. * Just ignore
  1052. */
  1053. break;
  1054. default:
  1055. bfa_sm_fault(lps->bfa, event);
  1056. }
  1057. }
  1058. /*
  1059. * login is in progress -- awaiting response from firmware
  1060. */
  1061. static void
  1062. bfa_lps_sm_login(struct bfa_lps_s *lps, enum bfa_lps_event event)
  1063. {
  1064. bfa_trc(lps->bfa, lps->lp_tag);
  1065. bfa_trc(lps->bfa, event);
  1066. switch (event) {
  1067. case BFA_LPS_SM_FWRSP:
  1068. if (lps->status == BFA_STATUS_OK) {
  1069. bfa_sm_set_state(lps, bfa_lps_sm_online);
  1070. if (lps->fdisc)
  1071. bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
  1072. BFA_PL_EID_LOGIN, 0, "FDISC Accept");
  1073. else
  1074. bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
  1075. BFA_PL_EID_LOGIN, 0, "FLOGI Accept");
  1076. /* If N2N, send the assigned PID to FW */
  1077. bfa_trc(lps->bfa, lps->fport);
  1078. bfa_trc(lps->bfa, lps->lp_pid);
  1079. if (!lps->fport && lps->lp_pid)
  1080. bfa_sm_send_event(lps, BFA_LPS_SM_SET_N2N_PID);
  1081. } else {
  1082. bfa_sm_set_state(lps, bfa_lps_sm_init);
  1083. if (lps->fdisc)
  1084. bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
  1085. BFA_PL_EID_LOGIN, 0,
  1086. "FDISC Fail (RJT or timeout)");
  1087. else
  1088. bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
  1089. BFA_PL_EID_LOGIN, 0,
  1090. "FLOGI Fail (RJT or timeout)");
  1091. }
  1092. bfa_lps_login_comp(lps);
  1093. break;
  1094. case BFA_LPS_SM_OFFLINE:
  1095. bfa_sm_set_state(lps, bfa_lps_sm_init);
  1096. break;
  1097. case BFA_LPS_SM_SET_N2N_PID:
  1098. bfa_trc(lps->bfa, lps->fport);
  1099. bfa_trc(lps->bfa, lps->lp_pid);
  1100. break;
  1101. default:
  1102. bfa_sm_fault(lps->bfa, event);
  1103. }
  1104. }
  1105. /*
  1106. * login pending - awaiting space in request queue
  1107. */
  1108. static void
  1109. bfa_lps_sm_loginwait(struct bfa_lps_s *lps, enum bfa_lps_event event)
  1110. {
  1111. bfa_trc(lps->bfa, lps->lp_tag);
  1112. bfa_trc(lps->bfa, event);
  1113. switch (event) {
  1114. case BFA_LPS_SM_RESUME:
  1115. bfa_sm_set_state(lps, bfa_lps_sm_login);
  1116. break;
  1117. case BFA_LPS_SM_OFFLINE:
  1118. bfa_sm_set_state(lps, bfa_lps_sm_init);
  1119. bfa_reqq_wcancel(&lps->wqe);
  1120. break;
  1121. case BFA_LPS_SM_RX_CVL:
  1122. /*
  1123. * Login was not even sent out; so when getting out
  1124. * of this state, it will appear like a login retry
  1125. * after Clear virtual link
  1126. */
  1127. break;
  1128. default:
  1129. bfa_sm_fault(lps->bfa, event);
  1130. }
  1131. }
  1132. /*
  1133. * login complete
  1134. */
  1135. static void
  1136. bfa_lps_sm_online(struct bfa_lps_s *lps, enum bfa_lps_event event)
  1137. {
  1138. bfa_trc(lps->bfa, lps->lp_tag);
  1139. bfa_trc(lps->bfa, event);
  1140. switch (event) {
  1141. case BFA_LPS_SM_LOGOUT:
  1142. if (bfa_reqq_full(lps->bfa, lps->reqq)) {
  1143. bfa_sm_set_state(lps, bfa_lps_sm_logowait);
  1144. bfa_reqq_wait(lps->bfa, lps->reqq, &lps->wqe);
  1145. } else {
  1146. bfa_sm_set_state(lps, bfa_lps_sm_logout);
  1147. bfa_lps_send_logout(lps);
  1148. }
  1149. bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
  1150. BFA_PL_EID_LOGO, 0, "Logout");
  1151. break;
  1152. case BFA_LPS_SM_RX_CVL:
  1153. bfa_sm_set_state(lps, bfa_lps_sm_init);
  1154. /* Let the vport module know about this event */
  1155. bfa_lps_cvl_event(lps);
  1156. bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
  1157. BFA_PL_EID_FIP_FCF_CVL, 0, "FCF Clear Virt. Link Rx");
  1158. break;
  1159. case BFA_LPS_SM_SET_N2N_PID:
  1160. if (bfa_reqq_full(lps->bfa, lps->reqq)) {
  1161. bfa_sm_set_state(lps, bfa_lps_sm_online_n2n_pid_wait);
  1162. bfa_reqq_wait(lps->bfa, lps->reqq, &lps->wqe);
  1163. } else
  1164. bfa_lps_send_set_n2n_pid(lps);
  1165. break;
  1166. case BFA_LPS_SM_OFFLINE:
  1167. case BFA_LPS_SM_DELETE:
  1168. bfa_sm_set_state(lps, bfa_lps_sm_init);
  1169. break;
  1170. default:
  1171. bfa_sm_fault(lps->bfa, event);
  1172. }
  1173. }
  1174. /*
  1175. * login complete
  1176. */
  1177. static void
  1178. bfa_lps_sm_online_n2n_pid_wait(struct bfa_lps_s *lps, enum bfa_lps_event event)
  1179. {
  1180. bfa_trc(lps->bfa, lps->lp_tag);
  1181. bfa_trc(lps->bfa, event);
  1182. switch (event) {
  1183. case BFA_LPS_SM_RESUME:
  1184. bfa_sm_set_state(lps, bfa_lps_sm_online);
  1185. bfa_lps_send_set_n2n_pid(lps);
  1186. break;
  1187. case BFA_LPS_SM_LOGOUT:
  1188. bfa_sm_set_state(lps, bfa_lps_sm_logowait);
  1189. bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
  1190. BFA_PL_EID_LOGO, 0, "Logout");
  1191. break;
  1192. case BFA_LPS_SM_RX_CVL:
  1193. bfa_sm_set_state(lps, bfa_lps_sm_init);
  1194. bfa_reqq_wcancel(&lps->wqe);
  1195. /* Let the vport module know about this event */
  1196. bfa_lps_cvl_event(lps);
  1197. bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
  1198. BFA_PL_EID_FIP_FCF_CVL, 0, "FCF Clear Virt. Link Rx");
  1199. break;
  1200. case BFA_LPS_SM_OFFLINE:
  1201. case BFA_LPS_SM_DELETE:
  1202. bfa_sm_set_state(lps, bfa_lps_sm_init);
  1203. bfa_reqq_wcancel(&lps->wqe);
  1204. break;
  1205. default:
  1206. bfa_sm_fault(lps->bfa, event);
  1207. }
  1208. }
  1209. /*
  1210. * logout in progress - awaiting firmware response
  1211. */
  1212. static void
  1213. bfa_lps_sm_logout(struct bfa_lps_s *lps, enum bfa_lps_event event)
  1214. {
  1215. bfa_trc(lps->bfa, lps->lp_tag);
  1216. bfa_trc(lps->bfa, event);
  1217. switch (event) {
  1218. case BFA_LPS_SM_FWRSP:
  1219. bfa_sm_set_state(lps, bfa_lps_sm_init);
  1220. bfa_lps_logout_comp(lps);
  1221. break;
  1222. case BFA_LPS_SM_OFFLINE:
  1223. bfa_sm_set_state(lps, bfa_lps_sm_init);
  1224. break;
  1225. default:
  1226. bfa_sm_fault(lps->bfa, event);
  1227. }
  1228. }
  1229. /*
  1230. * logout pending -- awaiting space in request queue
  1231. */
  1232. static void
  1233. bfa_lps_sm_logowait(struct bfa_lps_s *lps, enum bfa_lps_event event)
  1234. {
  1235. bfa_trc(lps->bfa, lps->lp_tag);
  1236. bfa_trc(lps->bfa, event);
  1237. switch (event) {
  1238. case BFA_LPS_SM_RESUME:
  1239. bfa_sm_set_state(lps, bfa_lps_sm_logout);
  1240. bfa_lps_send_logout(lps);
  1241. break;
  1242. case BFA_LPS_SM_OFFLINE:
  1243. bfa_sm_set_state(lps, bfa_lps_sm_init);
  1244. bfa_reqq_wcancel(&lps->wqe);
  1245. break;
  1246. default:
  1247. bfa_sm_fault(lps->bfa, event);
  1248. }
  1249. }
  1250. /*
  1251. * lps_pvt BFA LPS private functions
  1252. */
  1253. /*
  1254. * return memory requirement
  1255. */
  1256. static void
  1257. bfa_lps_meminfo(struct bfa_iocfc_cfg_s *cfg, u32 *ndm_len,
  1258. u32 *dm_len)
  1259. {
  1260. if (cfg->drvcfg.min_cfg)
  1261. *ndm_len += sizeof(struct bfa_lps_s) * BFA_LPS_MIN_LPORTS;
  1262. else
  1263. *ndm_len += sizeof(struct bfa_lps_s) * BFA_LPS_MAX_LPORTS;
  1264. }
  1265. /*
  1266. * bfa module attach at initialization time
  1267. */
  1268. static void
  1269. bfa_lps_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
  1270. struct bfa_meminfo_s *meminfo, struct bfa_pcidev_s *pcidev)
  1271. {
  1272. struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
  1273. struct bfa_lps_s *lps;
  1274. int i;
  1275. memset(mod, 0, sizeof(struct bfa_lps_mod_s));
  1276. mod->num_lps = BFA_LPS_MAX_LPORTS;
  1277. if (cfg->drvcfg.min_cfg)
  1278. mod->num_lps = BFA_LPS_MIN_LPORTS;
  1279. else
  1280. mod->num_lps = BFA_LPS_MAX_LPORTS;
  1281. mod->lps_arr = lps = (struct bfa_lps_s *) bfa_meminfo_kva(meminfo);
  1282. bfa_meminfo_kva(meminfo) += mod->num_lps * sizeof(struct bfa_lps_s);
  1283. INIT_LIST_HEAD(&mod->lps_free_q);
  1284. INIT_LIST_HEAD(&mod->lps_active_q);
  1285. for (i = 0; i < mod->num_lps; i++, lps++) {
  1286. lps->bfa = bfa;
  1287. lps->lp_tag = (u8) i;
  1288. lps->reqq = BFA_REQQ_LPS;
  1289. bfa_reqq_winit(&lps->wqe, bfa_lps_reqq_resume, lps);
  1290. list_add_tail(&lps->qe, &mod->lps_free_q);
  1291. }
  1292. }
  1293. static void
  1294. bfa_lps_detach(struct bfa_s *bfa)
  1295. {
  1296. }
  1297. static void
  1298. bfa_lps_start(struct bfa_s *bfa)
  1299. {
  1300. }
  1301. static void
  1302. bfa_lps_stop(struct bfa_s *bfa)
  1303. {
  1304. }
  1305. /*
  1306. * IOC in disabled state -- consider all lps offline
  1307. */
  1308. static void
  1309. bfa_lps_iocdisable(struct bfa_s *bfa)
  1310. {
  1311. struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
  1312. struct bfa_lps_s *lps;
  1313. struct list_head *qe, *qen;
  1314. list_for_each_safe(qe, qen, &mod->lps_active_q) {
  1315. lps = (struct bfa_lps_s *) qe;
  1316. bfa_sm_send_event(lps, BFA_LPS_SM_OFFLINE);
  1317. }
  1318. }
  1319. /*
  1320. * Firmware login response
  1321. */
  1322. static void
  1323. bfa_lps_login_rsp(struct bfa_s *bfa, struct bfi_lps_login_rsp_s *rsp)
  1324. {
  1325. struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
  1326. struct bfa_lps_s *lps;
  1327. WARN_ON(rsp->lp_tag >= mod->num_lps);
  1328. lps = BFA_LPS_FROM_TAG(mod, rsp->lp_tag);
  1329. lps->status = rsp->status;
  1330. switch (rsp->status) {
  1331. case BFA_STATUS_OK:
  1332. lps->fport = rsp->f_port;
  1333. if (lps->fport)
  1334. lps->lp_pid = rsp->lp_pid;
  1335. lps->npiv_en = rsp->npiv_en;
  1336. lps->pr_bbcred = be16_to_cpu(rsp->bb_credit);
  1337. lps->pr_pwwn = rsp->port_name;
  1338. lps->pr_nwwn = rsp->node_name;
  1339. lps->auth_req = rsp->auth_req;
  1340. lps->lp_mac = rsp->lp_mac;
  1341. lps->brcd_switch = rsp->brcd_switch;
  1342. lps->fcf_mac = rsp->fcf_mac;
  1343. break;
  1344. case BFA_STATUS_FABRIC_RJT:
  1345. lps->lsrjt_rsn = rsp->lsrjt_rsn;
  1346. lps->lsrjt_expl = rsp->lsrjt_expl;
  1347. break;
  1348. case BFA_STATUS_EPROTOCOL:
  1349. lps->ext_status = rsp->ext_status;
  1350. break;
  1351. default:
  1352. /* Nothing to do with other status */
  1353. break;
  1354. }
  1355. bfa_sm_send_event(lps, BFA_LPS_SM_FWRSP);
  1356. }
  1357. /*
  1358. * Firmware logout response
  1359. */
  1360. static void
  1361. bfa_lps_logout_rsp(struct bfa_s *bfa, struct bfi_lps_logout_rsp_s *rsp)
  1362. {
  1363. struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
  1364. struct bfa_lps_s *lps;
  1365. WARN_ON(rsp->lp_tag >= mod->num_lps);
  1366. lps = BFA_LPS_FROM_TAG(mod, rsp->lp_tag);
  1367. bfa_sm_send_event(lps, BFA_LPS_SM_FWRSP);
  1368. }
  1369. /*
  1370. * Firmware received a Clear virtual link request (for FCoE)
  1371. */
  1372. static void
  1373. bfa_lps_rx_cvl_event(struct bfa_s *bfa, struct bfi_lps_cvl_event_s *cvl)
  1374. {
  1375. struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
  1376. struct bfa_lps_s *lps;
  1377. lps = BFA_LPS_FROM_TAG(mod, cvl->lp_tag);
  1378. bfa_sm_send_event(lps, BFA_LPS_SM_RX_CVL);
  1379. }
  1380. /*
  1381. * Space is available in request queue, resume queueing request to firmware.
  1382. */
  1383. static void
  1384. bfa_lps_reqq_resume(void *lps_arg)
  1385. {
  1386. struct bfa_lps_s *lps = lps_arg;
  1387. bfa_sm_send_event(lps, BFA_LPS_SM_RESUME);
  1388. }
  1389. /*
  1390. * lps is freed -- triggered by vport delete
  1391. */
  1392. static void
  1393. bfa_lps_free(struct bfa_lps_s *lps)
  1394. {
  1395. struct bfa_lps_mod_s *mod = BFA_LPS_MOD(lps->bfa);
  1396. lps->lp_pid = 0;
  1397. list_del(&lps->qe);
  1398. list_add_tail(&lps->qe, &mod->lps_free_q);
  1399. }
  1400. /*
  1401. * send login request to firmware
  1402. */
  1403. static void
  1404. bfa_lps_send_login(struct bfa_lps_s *lps)
  1405. {
  1406. struct bfi_lps_login_req_s *m;
  1407. m = bfa_reqq_next(lps->bfa, lps->reqq);
  1408. WARN_ON(!m);
  1409. bfi_h2i_set(m->mh, BFI_MC_LPS, BFI_LPS_H2I_LOGIN_REQ,
  1410. bfa_lpuid(lps->bfa));
  1411. m->lp_tag = lps->lp_tag;
  1412. m->alpa = lps->alpa;
  1413. m->pdu_size = cpu_to_be16(lps->pdusz);
  1414. m->pwwn = lps->pwwn;
  1415. m->nwwn = lps->nwwn;
  1416. m->fdisc = lps->fdisc;
  1417. m->auth_en = lps->auth_en;
  1418. bfa_reqq_produce(lps->bfa, lps->reqq);
  1419. }
  1420. /*
  1421. * send logout request to firmware
  1422. */
  1423. static void
  1424. bfa_lps_send_logout(struct bfa_lps_s *lps)
  1425. {
  1426. struct bfi_lps_logout_req_s *m;
  1427. m = bfa_reqq_next(lps->bfa, lps->reqq);
  1428. WARN_ON(!m);
  1429. bfi_h2i_set(m->mh, BFI_MC_LPS, BFI_LPS_H2I_LOGOUT_REQ,
  1430. bfa_lpuid(lps->bfa));
  1431. m->lp_tag = lps->lp_tag;
  1432. m->port_name = lps->pwwn;
  1433. bfa_reqq_produce(lps->bfa, lps->reqq);
  1434. }
  1435. /*
  1436. * send n2n pid set request to firmware
  1437. */
  1438. static void
  1439. bfa_lps_send_set_n2n_pid(struct bfa_lps_s *lps)
  1440. {
  1441. struct bfi_lps_n2n_pid_req_s *m;
  1442. m = bfa_reqq_next(lps->bfa, lps->reqq);
  1443. WARN_ON(!m);
  1444. bfi_h2i_set(m->mh, BFI_MC_LPS, BFI_LPS_H2I_N2N_PID_REQ,
  1445. bfa_lpuid(lps->bfa));
  1446. m->lp_tag = lps->lp_tag;
  1447. m->lp_pid = lps->lp_pid;
  1448. bfa_reqq_produce(lps->bfa, lps->reqq);
  1449. }
  1450. /*
  1451. * Indirect login completion handler for non-fcs
  1452. */
  1453. static void
  1454. bfa_lps_login_comp_cb(void *arg, bfa_boolean_t complete)
  1455. {
  1456. struct bfa_lps_s *lps = arg;
  1457. if (!complete)
  1458. return;
  1459. if (lps->fdisc)
  1460. bfa_cb_lps_fdisc_comp(lps->bfa->bfad, lps->uarg, lps->status);
  1461. else
  1462. bfa_cb_lps_flogi_comp(lps->bfa->bfad, lps->uarg, lps->status);
  1463. }
  1464. /*
  1465. * Login completion handler -- direct call for fcs, queue for others
  1466. */
  1467. static void
  1468. bfa_lps_login_comp(struct bfa_lps_s *lps)
  1469. {
  1470. if (!lps->bfa->fcs) {
  1471. bfa_cb_queue(lps->bfa, &lps->hcb_qe, bfa_lps_login_comp_cb,
  1472. lps);
  1473. return;
  1474. }
  1475. if (lps->fdisc)
  1476. bfa_cb_lps_fdisc_comp(lps->bfa->bfad, lps->uarg, lps->status);
  1477. else
  1478. bfa_cb_lps_flogi_comp(lps->bfa->bfad, lps->uarg, lps->status);
  1479. }
  1480. /*
  1481. * Indirect logout completion handler for non-fcs
  1482. */
  1483. static void
  1484. bfa_lps_logout_comp_cb(void *arg, bfa_boolean_t complete)
  1485. {
  1486. struct bfa_lps_s *lps = arg;
  1487. if (!complete)
  1488. return;
  1489. if (lps->fdisc)
  1490. bfa_cb_lps_fdisclogo_comp(lps->bfa->bfad, lps->uarg);
  1491. }
  1492. /*
  1493. * Logout completion handler -- direct call for fcs, queue for others
  1494. */
  1495. static void
  1496. bfa_lps_logout_comp(struct bfa_lps_s *lps)
  1497. {
  1498. if (!lps->bfa->fcs) {
  1499. bfa_cb_queue(lps->bfa, &lps->hcb_qe, bfa_lps_logout_comp_cb,
  1500. lps);
  1501. return;
  1502. }
  1503. if (lps->fdisc)
  1504. bfa_cb_lps_fdisclogo_comp(lps->bfa->bfad, lps->uarg);
  1505. }
  1506. /*
  1507. * Clear virtual link completion handler for non-fcs
  1508. */
  1509. static void
  1510. bfa_lps_cvl_event_cb(void *arg, bfa_boolean_t complete)
  1511. {
  1512. struct bfa_lps_s *lps = arg;
  1513. if (!complete)
  1514. return;
  1515. /* Clear virtual link to base port will result in link down */
  1516. if (lps->fdisc)
  1517. bfa_cb_lps_cvl_event(lps->bfa->bfad, lps->uarg);
  1518. }
  1519. /*
  1520. * Received Clear virtual link event --direct call for fcs,
  1521. * queue for others
  1522. */
  1523. static void
  1524. bfa_lps_cvl_event(struct bfa_lps_s *lps)
  1525. {
  1526. if (!lps->bfa->fcs) {
  1527. bfa_cb_queue(lps->bfa, &lps->hcb_qe, bfa_lps_cvl_event_cb,
  1528. lps);
  1529. return;
  1530. }
  1531. /* Clear virtual link to base port will result in link down */
  1532. if (lps->fdisc)
  1533. bfa_cb_lps_cvl_event(lps->bfa->bfad, lps->uarg);
  1534. }
  1535. /*
  1536. * lps_public BFA LPS public functions
  1537. */
  1538. u32
  1539. bfa_lps_get_max_vport(struct bfa_s *bfa)
  1540. {
  1541. if (bfa_ioc_devid(&bfa->ioc) == BFA_PCI_DEVICE_ID_CT)
  1542. return BFA_LPS_MAX_VPORTS_SUPP_CT;
  1543. else
  1544. return BFA_LPS_MAX_VPORTS_SUPP_CB;
  1545. }
  1546. /*
  1547. * Allocate a lport srvice tag.
  1548. */
  1549. struct bfa_lps_s *
  1550. bfa_lps_alloc(struct bfa_s *bfa)
  1551. {
  1552. struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
  1553. struct bfa_lps_s *lps = NULL;
  1554. bfa_q_deq(&mod->lps_free_q, &lps);
  1555. if (lps == NULL)
  1556. return NULL;
  1557. list_add_tail(&lps->qe, &mod->lps_active_q);
  1558. bfa_sm_set_state(lps, bfa_lps_sm_init);
  1559. return lps;
  1560. }
  1561. /*
  1562. * Free lport service tag. This can be called anytime after an alloc.
  1563. * No need to wait for any pending login/logout completions.
  1564. */
  1565. void
  1566. bfa_lps_delete(struct bfa_lps_s *lps)
  1567. {
  1568. bfa_sm_send_event(lps, BFA_LPS_SM_DELETE);
  1569. }
  1570. /*
  1571. * Initiate a lport login.
  1572. */
  1573. void
  1574. bfa_lps_flogi(struct bfa_lps_s *lps, void *uarg, u8 alpa, u16 pdusz,
  1575. wwn_t pwwn, wwn_t nwwn, bfa_boolean_t auth_en)
  1576. {
  1577. lps->uarg = uarg;
  1578. lps->alpa = alpa;
  1579. lps->pdusz = pdusz;
  1580. lps->pwwn = pwwn;
  1581. lps->nwwn = nwwn;
  1582. lps->fdisc = BFA_FALSE;
  1583. lps->auth_en = auth_en;
  1584. bfa_sm_send_event(lps, BFA_LPS_SM_LOGIN);
  1585. }
  1586. /*
  1587. * Initiate a lport fdisc login.
  1588. */
  1589. void
  1590. bfa_lps_fdisc(struct bfa_lps_s *lps, void *uarg, u16 pdusz, wwn_t pwwn,
  1591. wwn_t nwwn)
  1592. {
  1593. lps->uarg = uarg;
  1594. lps->alpa = 0;
  1595. lps->pdusz = pdusz;
  1596. lps->pwwn = pwwn;
  1597. lps->nwwn = nwwn;
  1598. lps->fdisc = BFA_TRUE;
  1599. lps->auth_en = BFA_FALSE;
  1600. bfa_sm_send_event(lps, BFA_LPS_SM_LOGIN);
  1601. }
  1602. /*
  1603. * Initiate a lport FDSIC logout.
  1604. */
  1605. void
  1606. bfa_lps_fdisclogo(struct bfa_lps_s *lps)
  1607. {
  1608. bfa_sm_send_event(lps, BFA_LPS_SM_LOGOUT);
  1609. }
  1610. /*
  1611. * Return lport services tag given the pid
  1612. */
  1613. u8
  1614. bfa_lps_get_tag_from_pid(struct bfa_s *bfa, u32 pid)
  1615. {
  1616. struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
  1617. struct bfa_lps_s *lps;
  1618. int i;
  1619. for (i = 0, lps = mod->lps_arr; i < mod->num_lps; i++, lps++) {
  1620. if (lps->lp_pid == pid)
  1621. return lps->lp_tag;
  1622. }
  1623. /* Return base port tag anyway */
  1624. return 0;
  1625. }
  1626. /*
  1627. * return port id assigned to the base lport
  1628. */
  1629. u32
  1630. bfa_lps_get_base_pid(struct bfa_s *bfa)
  1631. {
  1632. struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
  1633. return BFA_LPS_FROM_TAG(mod, 0)->lp_pid;
  1634. }
  1635. /*
  1636. * Set PID in case of n2n (which is assigned during PLOGI)
  1637. */
  1638. void
  1639. bfa_lps_set_n2n_pid(struct bfa_lps_s *lps, uint32_t n2n_pid)
  1640. {
  1641. bfa_trc(lps->bfa, lps->lp_tag);
  1642. bfa_trc(lps->bfa, n2n_pid);
  1643. lps->lp_pid = n2n_pid;
  1644. bfa_sm_send_event(lps, BFA_LPS_SM_SET_N2N_PID);
  1645. }
  1646. /*
  1647. * LPS firmware message class handler.
  1648. */
  1649. void
  1650. bfa_lps_isr(struct bfa_s *bfa, struct bfi_msg_s *m)
  1651. {
  1652. union bfi_lps_i2h_msg_u msg;
  1653. bfa_trc(bfa, m->mhdr.msg_id);
  1654. msg.msg = m;
  1655. switch (m->mhdr.msg_id) {
  1656. case BFI_LPS_H2I_LOGIN_RSP:
  1657. bfa_lps_login_rsp(bfa, msg.login_rsp);
  1658. break;
  1659. case BFI_LPS_H2I_LOGOUT_RSP:
  1660. bfa_lps_logout_rsp(bfa, msg.logout_rsp);
  1661. break;
  1662. case BFI_LPS_H2I_CVL_EVENT:
  1663. bfa_lps_rx_cvl_event(bfa, msg.cvl_event);
  1664. break;
  1665. default:
  1666. bfa_trc(bfa, m->mhdr.msg_id);
  1667. WARN_ON(1);
  1668. }
  1669. }
  1670. /*
  1671. * FC PORT state machine functions
  1672. */
  1673. static void
  1674. bfa_fcport_sm_uninit(struct bfa_fcport_s *fcport,
  1675. enum bfa_fcport_sm_event event)
  1676. {
  1677. bfa_trc(fcport->bfa, event);
  1678. switch (event) {
  1679. case BFA_FCPORT_SM_START:
  1680. /*
  1681. * Start event after IOC is configured and BFA is started.
  1682. */
  1683. fcport->use_flash_cfg = BFA_TRUE;
  1684. if (bfa_fcport_send_enable(fcport)) {
  1685. bfa_trc(fcport->bfa, BFA_TRUE);
  1686. bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
  1687. } else {
  1688. bfa_trc(fcport->bfa, BFA_FALSE);
  1689. bfa_sm_set_state(fcport,
  1690. bfa_fcport_sm_enabling_qwait);
  1691. }
  1692. break;
  1693. case BFA_FCPORT_SM_ENABLE:
  1694. /*
  1695. * Port is persistently configured to be in enabled state. Do
  1696. * not change state. Port enabling is done when START event is
  1697. * received.
  1698. */
  1699. break;
  1700. case BFA_FCPORT_SM_DISABLE:
  1701. /*
  1702. * If a port is persistently configured to be disabled, the
  1703. * first event will a port disable request.
  1704. */
  1705. bfa_sm_set_state(fcport, bfa_fcport_sm_disabled);
  1706. break;
  1707. case BFA_FCPORT_SM_HWFAIL:
  1708. bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
  1709. break;
  1710. default:
  1711. bfa_sm_fault(fcport->bfa, event);
  1712. }
  1713. }
  1714. static void
  1715. bfa_fcport_sm_enabling_qwait(struct bfa_fcport_s *fcport,
  1716. enum bfa_fcport_sm_event event)
  1717. {
  1718. char pwwn_buf[BFA_STRING_32];
  1719. struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
  1720. bfa_trc(fcport->bfa, event);
  1721. switch (event) {
  1722. case BFA_FCPORT_SM_QRESUME:
  1723. bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
  1724. bfa_fcport_send_enable(fcport);
  1725. break;
  1726. case BFA_FCPORT_SM_STOP:
  1727. bfa_reqq_wcancel(&fcport->reqq_wait);
  1728. bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
  1729. break;
  1730. case BFA_FCPORT_SM_ENABLE:
  1731. /*
  1732. * Already enable is in progress.
  1733. */
  1734. break;
  1735. case BFA_FCPORT_SM_DISABLE:
  1736. /*
  1737. * Just send disable request to firmware when room becomes
  1738. * available in request queue.
  1739. */
  1740. bfa_sm_set_state(fcport, bfa_fcport_sm_disabled);
  1741. bfa_reqq_wcancel(&fcport->reqq_wait);
  1742. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  1743. BFA_PL_EID_PORT_DISABLE, 0, "Port Disable");
  1744. wwn2str(pwwn_buf, fcport->pwwn);
  1745. BFA_LOG(KERN_INFO, bfad, bfa_log_level,
  1746. "Base port disabled: WWN = %s\n", pwwn_buf);
  1747. break;
  1748. case BFA_FCPORT_SM_LINKUP:
  1749. case BFA_FCPORT_SM_LINKDOWN:
  1750. /*
  1751. * Possible to get link events when doing back-to-back
  1752. * enable/disables.
  1753. */
  1754. break;
  1755. case BFA_FCPORT_SM_HWFAIL:
  1756. bfa_reqq_wcancel(&fcport->reqq_wait);
  1757. bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
  1758. break;
  1759. default:
  1760. bfa_sm_fault(fcport->bfa, event);
  1761. }
  1762. }
  1763. static void
  1764. bfa_fcport_sm_enabling(struct bfa_fcport_s *fcport,
  1765. enum bfa_fcport_sm_event event)
  1766. {
  1767. char pwwn_buf[BFA_STRING_32];
  1768. struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
  1769. bfa_trc(fcport->bfa, event);
  1770. switch (event) {
  1771. case BFA_FCPORT_SM_FWRSP:
  1772. case BFA_FCPORT_SM_LINKDOWN:
  1773. bfa_sm_set_state(fcport, bfa_fcport_sm_linkdown);
  1774. break;
  1775. case BFA_FCPORT_SM_LINKUP:
  1776. bfa_fcport_update_linkinfo(fcport);
  1777. bfa_sm_set_state(fcport, bfa_fcport_sm_linkup);
  1778. WARN_ON(!fcport->event_cbfn);
  1779. bfa_fcport_scn(fcport, BFA_PORT_LINKUP, BFA_FALSE);
  1780. break;
  1781. case BFA_FCPORT_SM_ENABLE:
  1782. /*
  1783. * Already being enabled.
  1784. */
  1785. break;
  1786. case BFA_FCPORT_SM_DISABLE:
  1787. if (bfa_fcport_send_disable(fcport))
  1788. bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
  1789. else
  1790. bfa_sm_set_state(fcport,
  1791. bfa_fcport_sm_disabling_qwait);
  1792. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  1793. BFA_PL_EID_PORT_DISABLE, 0, "Port Disable");
  1794. wwn2str(pwwn_buf, fcport->pwwn);
  1795. BFA_LOG(KERN_INFO, bfad, bfa_log_level,
  1796. "Base port disabled: WWN = %s\n", pwwn_buf);
  1797. break;
  1798. case BFA_FCPORT_SM_STOP:
  1799. bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
  1800. break;
  1801. case BFA_FCPORT_SM_HWFAIL:
  1802. bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
  1803. break;
  1804. default:
  1805. bfa_sm_fault(fcport->bfa, event);
  1806. }
  1807. }
  1808. static void
  1809. bfa_fcport_sm_linkdown(struct bfa_fcport_s *fcport,
  1810. enum bfa_fcport_sm_event event)
  1811. {
  1812. struct bfi_fcport_event_s *pevent = fcport->event_arg.i2hmsg.event;
  1813. char pwwn_buf[BFA_STRING_32];
  1814. struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
  1815. bfa_trc(fcport->bfa, event);
  1816. switch (event) {
  1817. case BFA_FCPORT_SM_LINKUP:
  1818. bfa_fcport_update_linkinfo(fcport);
  1819. bfa_sm_set_state(fcport, bfa_fcport_sm_linkup);
  1820. WARN_ON(!fcport->event_cbfn);
  1821. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  1822. BFA_PL_EID_PORT_ST_CHANGE, 0, "Port Linkup");
  1823. if (!bfa_ioc_get_fcmode(&fcport->bfa->ioc)) {
  1824. bfa_trc(fcport->bfa,
  1825. pevent->link_state.vc_fcf.fcf.fipenabled);
  1826. bfa_trc(fcport->bfa,
  1827. pevent->link_state.vc_fcf.fcf.fipfailed);
  1828. if (pevent->link_state.vc_fcf.fcf.fipfailed)
  1829. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  1830. BFA_PL_EID_FIP_FCF_DISC, 0,
  1831. "FIP FCF Discovery Failed");
  1832. else
  1833. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  1834. BFA_PL_EID_FIP_FCF_DISC, 0,
  1835. "FIP FCF Discovered");
  1836. }
  1837. bfa_fcport_scn(fcport, BFA_PORT_LINKUP, BFA_FALSE);
  1838. wwn2str(pwwn_buf, fcport->pwwn);
  1839. BFA_LOG(KERN_INFO, bfad, bfa_log_level,
  1840. "Base port online: WWN = %s\n", pwwn_buf);
  1841. break;
  1842. case BFA_FCPORT_SM_LINKDOWN:
  1843. /*
  1844. * Possible to get link down event.
  1845. */
  1846. break;
  1847. case BFA_FCPORT_SM_ENABLE:
  1848. /*
  1849. * Already enabled.
  1850. */
  1851. break;
  1852. case BFA_FCPORT_SM_DISABLE:
  1853. if (bfa_fcport_send_disable(fcport))
  1854. bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
  1855. else
  1856. bfa_sm_set_state(fcport,
  1857. bfa_fcport_sm_disabling_qwait);
  1858. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  1859. BFA_PL_EID_PORT_DISABLE, 0, "Port Disable");
  1860. wwn2str(pwwn_buf, fcport->pwwn);
  1861. BFA_LOG(KERN_INFO, bfad, bfa_log_level,
  1862. "Base port disabled: WWN = %s\n", pwwn_buf);
  1863. break;
  1864. case BFA_FCPORT_SM_STOP:
  1865. bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
  1866. break;
  1867. case BFA_FCPORT_SM_HWFAIL:
  1868. bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
  1869. break;
  1870. default:
  1871. bfa_sm_fault(fcport->bfa, event);
  1872. }
  1873. }
  1874. static void
  1875. bfa_fcport_sm_linkup(struct bfa_fcport_s *fcport,
  1876. enum bfa_fcport_sm_event event)
  1877. {
  1878. char pwwn_buf[BFA_STRING_32];
  1879. struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
  1880. bfa_trc(fcport->bfa, event);
  1881. switch (event) {
  1882. case BFA_FCPORT_SM_ENABLE:
  1883. /*
  1884. * Already enabled.
  1885. */
  1886. break;
  1887. case BFA_FCPORT_SM_DISABLE:
  1888. if (bfa_fcport_send_disable(fcport))
  1889. bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
  1890. else
  1891. bfa_sm_set_state(fcport,
  1892. bfa_fcport_sm_disabling_qwait);
  1893. bfa_fcport_reset_linkinfo(fcport);
  1894. bfa_fcport_scn(fcport, BFA_PORT_LINKDOWN, BFA_FALSE);
  1895. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  1896. BFA_PL_EID_PORT_DISABLE, 0, "Port Disable");
  1897. wwn2str(pwwn_buf, fcport->pwwn);
  1898. BFA_LOG(KERN_INFO, bfad, bfa_log_level,
  1899. "Base port offline: WWN = %s\n", pwwn_buf);
  1900. BFA_LOG(KERN_INFO, bfad, bfa_log_level,
  1901. "Base port disabled: WWN = %s\n", pwwn_buf);
  1902. break;
  1903. case BFA_FCPORT_SM_LINKDOWN:
  1904. bfa_sm_set_state(fcport, bfa_fcport_sm_linkdown);
  1905. bfa_fcport_reset_linkinfo(fcport);
  1906. bfa_fcport_scn(fcport, BFA_PORT_LINKDOWN, BFA_FALSE);
  1907. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  1908. BFA_PL_EID_PORT_ST_CHANGE, 0, "Port Linkdown");
  1909. wwn2str(pwwn_buf, fcport->pwwn);
  1910. if (BFA_PORT_IS_DISABLED(fcport->bfa))
  1911. BFA_LOG(KERN_INFO, bfad, bfa_log_level,
  1912. "Base port offline: WWN = %s\n", pwwn_buf);
  1913. else
  1914. BFA_LOG(KERN_ERR, bfad, bfa_log_level,
  1915. "Base port (WWN = %s) "
  1916. "lost fabric connectivity\n", pwwn_buf);
  1917. break;
  1918. case BFA_FCPORT_SM_STOP:
  1919. bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
  1920. bfa_fcport_reset_linkinfo(fcport);
  1921. wwn2str(pwwn_buf, fcport->pwwn);
  1922. if (BFA_PORT_IS_DISABLED(fcport->bfa))
  1923. BFA_LOG(KERN_INFO, bfad, bfa_log_level,
  1924. "Base port offline: WWN = %s\n", pwwn_buf);
  1925. else
  1926. BFA_LOG(KERN_ERR, bfad, bfa_log_level,
  1927. "Base port (WWN = %s) "
  1928. "lost fabric connectivity\n", pwwn_buf);
  1929. break;
  1930. case BFA_FCPORT_SM_HWFAIL:
  1931. bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
  1932. bfa_fcport_reset_linkinfo(fcport);
  1933. bfa_fcport_scn(fcport, BFA_PORT_LINKDOWN, BFA_FALSE);
  1934. wwn2str(pwwn_buf, fcport->pwwn);
  1935. if (BFA_PORT_IS_DISABLED(fcport->bfa))
  1936. BFA_LOG(KERN_INFO, bfad, bfa_log_level,
  1937. "Base port offline: WWN = %s\n", pwwn_buf);
  1938. else
  1939. BFA_LOG(KERN_ERR, bfad, bfa_log_level,
  1940. "Base port (WWN = %s) "
  1941. "lost fabric connectivity\n", pwwn_buf);
  1942. break;
  1943. default:
  1944. bfa_sm_fault(fcport->bfa, event);
  1945. }
  1946. }
  1947. static void
  1948. bfa_fcport_sm_disabling_qwait(struct bfa_fcport_s *fcport,
  1949. enum bfa_fcport_sm_event event)
  1950. {
  1951. bfa_trc(fcport->bfa, event);
  1952. switch (event) {
  1953. case BFA_FCPORT_SM_QRESUME:
  1954. bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
  1955. bfa_fcport_send_disable(fcport);
  1956. break;
  1957. case BFA_FCPORT_SM_STOP:
  1958. bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
  1959. bfa_reqq_wcancel(&fcport->reqq_wait);
  1960. break;
  1961. case BFA_FCPORT_SM_ENABLE:
  1962. bfa_sm_set_state(fcport, bfa_fcport_sm_toggling_qwait);
  1963. break;
  1964. case BFA_FCPORT_SM_DISABLE:
  1965. /*
  1966. * Already being disabled.
  1967. */
  1968. break;
  1969. case BFA_FCPORT_SM_LINKUP:
  1970. case BFA_FCPORT_SM_LINKDOWN:
  1971. /*
  1972. * Possible to get link events when doing back-to-back
  1973. * enable/disables.
  1974. */
  1975. break;
  1976. case BFA_FCPORT_SM_HWFAIL:
  1977. bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail);
  1978. bfa_reqq_wcancel(&fcport->reqq_wait);
  1979. break;
  1980. default:
  1981. bfa_sm_fault(fcport->bfa, event);
  1982. }
  1983. }
  1984. static void
  1985. bfa_fcport_sm_toggling_qwait(struct bfa_fcport_s *fcport,
  1986. enum bfa_fcport_sm_event event)
  1987. {
  1988. bfa_trc(fcport->bfa, event);
  1989. switch (event) {
  1990. case BFA_FCPORT_SM_QRESUME:
  1991. bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
  1992. bfa_fcport_send_disable(fcport);
  1993. if (bfa_fcport_send_enable(fcport))
  1994. bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
  1995. else
  1996. bfa_sm_set_state(fcport,
  1997. bfa_fcport_sm_enabling_qwait);
  1998. break;
  1999. case BFA_FCPORT_SM_STOP:
  2000. bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
  2001. bfa_reqq_wcancel(&fcport->reqq_wait);
  2002. break;
  2003. case BFA_FCPORT_SM_ENABLE:
  2004. break;
  2005. case BFA_FCPORT_SM_DISABLE:
  2006. bfa_sm_set_state(fcport, bfa_fcport_sm_disabling_qwait);
  2007. break;
  2008. case BFA_FCPORT_SM_LINKUP:
  2009. case BFA_FCPORT_SM_LINKDOWN:
  2010. /*
  2011. * Possible to get link events when doing back-to-back
  2012. * enable/disables.
  2013. */
  2014. break;
  2015. case BFA_FCPORT_SM_HWFAIL:
  2016. bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail);
  2017. bfa_reqq_wcancel(&fcport->reqq_wait);
  2018. break;
  2019. default:
  2020. bfa_sm_fault(fcport->bfa, event);
  2021. }
  2022. }
  2023. static void
  2024. bfa_fcport_sm_disabling(struct bfa_fcport_s *fcport,
  2025. enum bfa_fcport_sm_event event)
  2026. {
  2027. char pwwn_buf[BFA_STRING_32];
  2028. struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
  2029. bfa_trc(fcport->bfa, event);
  2030. switch (event) {
  2031. case BFA_FCPORT_SM_FWRSP:
  2032. bfa_sm_set_state(fcport, bfa_fcport_sm_disabled);
  2033. break;
  2034. case BFA_FCPORT_SM_DISABLE:
  2035. /*
  2036. * Already being disabled.
  2037. */
  2038. break;
  2039. case BFA_FCPORT_SM_ENABLE:
  2040. if (bfa_fcport_send_enable(fcport))
  2041. bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
  2042. else
  2043. bfa_sm_set_state(fcport,
  2044. bfa_fcport_sm_enabling_qwait);
  2045. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  2046. BFA_PL_EID_PORT_ENABLE, 0, "Port Enable");
  2047. wwn2str(pwwn_buf, fcport->pwwn);
  2048. BFA_LOG(KERN_INFO, bfad, bfa_log_level,
  2049. "Base port enabled: WWN = %s\n", pwwn_buf);
  2050. break;
  2051. case BFA_FCPORT_SM_STOP:
  2052. bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
  2053. break;
  2054. case BFA_FCPORT_SM_LINKUP:
  2055. case BFA_FCPORT_SM_LINKDOWN:
  2056. /*
  2057. * Possible to get link events when doing back-to-back
  2058. * enable/disables.
  2059. */
  2060. break;
  2061. case BFA_FCPORT_SM_HWFAIL:
  2062. bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail);
  2063. break;
  2064. default:
  2065. bfa_sm_fault(fcport->bfa, event);
  2066. }
  2067. }
  2068. static void
  2069. bfa_fcport_sm_disabled(struct bfa_fcport_s *fcport,
  2070. enum bfa_fcport_sm_event event)
  2071. {
  2072. char pwwn_buf[BFA_STRING_32];
  2073. struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
  2074. bfa_trc(fcport->bfa, event);
  2075. switch (event) {
  2076. case BFA_FCPORT_SM_START:
  2077. /*
  2078. * Ignore start event for a port that is disabled.
  2079. */
  2080. break;
  2081. case BFA_FCPORT_SM_STOP:
  2082. bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
  2083. break;
  2084. case BFA_FCPORT_SM_ENABLE:
  2085. if (bfa_fcport_send_enable(fcport))
  2086. bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
  2087. else
  2088. bfa_sm_set_state(fcport,
  2089. bfa_fcport_sm_enabling_qwait);
  2090. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  2091. BFA_PL_EID_PORT_ENABLE, 0, "Port Enable");
  2092. wwn2str(pwwn_buf, fcport->pwwn);
  2093. BFA_LOG(KERN_INFO, bfad, bfa_log_level,
  2094. "Base port enabled: WWN = %s\n", pwwn_buf);
  2095. break;
  2096. case BFA_FCPORT_SM_DISABLE:
  2097. /*
  2098. * Already disabled.
  2099. */
  2100. break;
  2101. case BFA_FCPORT_SM_HWFAIL:
  2102. bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail);
  2103. break;
  2104. default:
  2105. bfa_sm_fault(fcport->bfa, event);
  2106. }
  2107. }
  2108. static void
  2109. bfa_fcport_sm_stopped(struct bfa_fcport_s *fcport,
  2110. enum bfa_fcport_sm_event event)
  2111. {
  2112. bfa_trc(fcport->bfa, event);
  2113. switch (event) {
  2114. case BFA_FCPORT_SM_START:
  2115. if (bfa_fcport_send_enable(fcport))
  2116. bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
  2117. else
  2118. bfa_sm_set_state(fcport,
  2119. bfa_fcport_sm_enabling_qwait);
  2120. break;
  2121. default:
  2122. /*
  2123. * Ignore all other events.
  2124. */
  2125. ;
  2126. }
  2127. }
  2128. /*
  2129. * Port is enabled. IOC is down/failed.
  2130. */
  2131. static void
  2132. bfa_fcport_sm_iocdown(struct bfa_fcport_s *fcport,
  2133. enum bfa_fcport_sm_event event)
  2134. {
  2135. bfa_trc(fcport->bfa, event);
  2136. switch (event) {
  2137. case BFA_FCPORT_SM_START:
  2138. if (bfa_fcport_send_enable(fcport))
  2139. bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
  2140. else
  2141. bfa_sm_set_state(fcport,
  2142. bfa_fcport_sm_enabling_qwait);
  2143. break;
  2144. default:
  2145. /*
  2146. * Ignore all events.
  2147. */
  2148. ;
  2149. }
  2150. }
  2151. /*
  2152. * Port is disabled. IOC is down/failed.
  2153. */
  2154. static void
  2155. bfa_fcport_sm_iocfail(struct bfa_fcport_s *fcport,
  2156. enum bfa_fcport_sm_event event)
  2157. {
  2158. bfa_trc(fcport->bfa, event);
  2159. switch (event) {
  2160. case BFA_FCPORT_SM_START:
  2161. bfa_sm_set_state(fcport, bfa_fcport_sm_disabled);
  2162. break;
  2163. case BFA_FCPORT_SM_ENABLE:
  2164. bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
  2165. break;
  2166. default:
  2167. /*
  2168. * Ignore all events.
  2169. */
  2170. ;
  2171. }
  2172. }
  2173. /*
  2174. * Link state is down
  2175. */
  2176. static void
  2177. bfa_fcport_ln_sm_dn(struct bfa_fcport_ln_s *ln,
  2178. enum bfa_fcport_ln_sm_event event)
  2179. {
  2180. bfa_trc(ln->fcport->bfa, event);
  2181. switch (event) {
  2182. case BFA_FCPORT_LN_SM_LINKUP:
  2183. bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_nf);
  2184. bfa_fcport_queue_cb(ln, BFA_PORT_LINKUP);
  2185. break;
  2186. default:
  2187. bfa_sm_fault(ln->fcport->bfa, event);
  2188. }
  2189. }
  2190. /*
  2191. * Link state is waiting for down notification
  2192. */
  2193. static void
  2194. bfa_fcport_ln_sm_dn_nf(struct bfa_fcport_ln_s *ln,
  2195. enum bfa_fcport_ln_sm_event event)
  2196. {
  2197. bfa_trc(ln->fcport->bfa, event);
  2198. switch (event) {
  2199. case BFA_FCPORT_LN_SM_LINKUP:
  2200. bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_up_nf);
  2201. break;
  2202. case BFA_FCPORT_LN_SM_NOTIFICATION:
  2203. bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn);
  2204. break;
  2205. default:
  2206. bfa_sm_fault(ln->fcport->bfa, event);
  2207. }
  2208. }
  2209. /*
  2210. * Link state is waiting for down notification and there is a pending up
  2211. */
  2212. static void
  2213. bfa_fcport_ln_sm_dn_up_nf(struct bfa_fcport_ln_s *ln,
  2214. enum bfa_fcport_ln_sm_event event)
  2215. {
  2216. bfa_trc(ln->fcport->bfa, event);
  2217. switch (event) {
  2218. case BFA_FCPORT_LN_SM_LINKDOWN:
  2219. bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_nf);
  2220. break;
  2221. case BFA_FCPORT_LN_SM_NOTIFICATION:
  2222. bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_nf);
  2223. bfa_fcport_queue_cb(ln, BFA_PORT_LINKUP);
  2224. break;
  2225. default:
  2226. bfa_sm_fault(ln->fcport->bfa, event);
  2227. }
  2228. }
  2229. /*
  2230. * Link state is up
  2231. */
  2232. static void
  2233. bfa_fcport_ln_sm_up(struct bfa_fcport_ln_s *ln,
  2234. enum bfa_fcport_ln_sm_event event)
  2235. {
  2236. bfa_trc(ln->fcport->bfa, event);
  2237. switch (event) {
  2238. case BFA_FCPORT_LN_SM_LINKDOWN:
  2239. bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_nf);
  2240. bfa_fcport_queue_cb(ln, BFA_PORT_LINKDOWN);
  2241. break;
  2242. default:
  2243. bfa_sm_fault(ln->fcport->bfa, event);
  2244. }
  2245. }
  2246. /*
  2247. * Link state is waiting for up notification
  2248. */
  2249. static void
  2250. bfa_fcport_ln_sm_up_nf(struct bfa_fcport_ln_s *ln,
  2251. enum bfa_fcport_ln_sm_event event)
  2252. {
  2253. bfa_trc(ln->fcport->bfa, event);
  2254. switch (event) {
  2255. case BFA_FCPORT_LN_SM_LINKDOWN:
  2256. bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_dn_nf);
  2257. break;
  2258. case BFA_FCPORT_LN_SM_NOTIFICATION:
  2259. bfa_sm_set_state(ln, bfa_fcport_ln_sm_up);
  2260. break;
  2261. default:
  2262. bfa_sm_fault(ln->fcport->bfa, event);
  2263. }
  2264. }
  2265. /*
  2266. * Link state is waiting for up notification and there is a pending down
  2267. */
  2268. static void
  2269. bfa_fcport_ln_sm_up_dn_nf(struct bfa_fcport_ln_s *ln,
  2270. enum bfa_fcport_ln_sm_event event)
  2271. {
  2272. bfa_trc(ln->fcport->bfa, event);
  2273. switch (event) {
  2274. case BFA_FCPORT_LN_SM_LINKUP:
  2275. bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_dn_up_nf);
  2276. break;
  2277. case BFA_FCPORT_LN_SM_NOTIFICATION:
  2278. bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_nf);
  2279. bfa_fcport_queue_cb(ln, BFA_PORT_LINKDOWN);
  2280. break;
  2281. default:
  2282. bfa_sm_fault(ln->fcport->bfa, event);
  2283. }
  2284. }
  2285. /*
  2286. * Link state is waiting for up notification and there are pending down and up
  2287. */
  2288. static void
  2289. bfa_fcport_ln_sm_up_dn_up_nf(struct bfa_fcport_ln_s *ln,
  2290. enum bfa_fcport_ln_sm_event event)
  2291. {
  2292. bfa_trc(ln->fcport->bfa, event);
  2293. switch (event) {
  2294. case BFA_FCPORT_LN_SM_LINKDOWN:
  2295. bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_dn_nf);
  2296. break;
  2297. case BFA_FCPORT_LN_SM_NOTIFICATION:
  2298. bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_up_nf);
  2299. bfa_fcport_queue_cb(ln, BFA_PORT_LINKDOWN);
  2300. break;
  2301. default:
  2302. bfa_sm_fault(ln->fcport->bfa, event);
  2303. }
  2304. }
  2305. static void
  2306. __bfa_cb_fcport_event(void *cbarg, bfa_boolean_t complete)
  2307. {
  2308. struct bfa_fcport_ln_s *ln = cbarg;
  2309. if (complete)
  2310. ln->fcport->event_cbfn(ln->fcport->event_cbarg, ln->ln_event);
  2311. else
  2312. bfa_sm_send_event(ln, BFA_FCPORT_LN_SM_NOTIFICATION);
  2313. }
  2314. /*
  2315. * Send SCN notification to upper layers.
  2316. * trunk - false if caller is fcport to ignore fcport event in trunked mode
  2317. */
  2318. static void
  2319. bfa_fcport_scn(struct bfa_fcport_s *fcport, enum bfa_port_linkstate event,
  2320. bfa_boolean_t trunk)
  2321. {
  2322. if (fcport->cfg.trunked && !trunk)
  2323. return;
  2324. switch (event) {
  2325. case BFA_PORT_LINKUP:
  2326. bfa_sm_send_event(&fcport->ln, BFA_FCPORT_LN_SM_LINKUP);
  2327. break;
  2328. case BFA_PORT_LINKDOWN:
  2329. bfa_sm_send_event(&fcport->ln, BFA_FCPORT_LN_SM_LINKDOWN);
  2330. break;
  2331. default:
  2332. WARN_ON(1);
  2333. }
  2334. }
  2335. static void
  2336. bfa_fcport_queue_cb(struct bfa_fcport_ln_s *ln, enum bfa_port_linkstate event)
  2337. {
  2338. struct bfa_fcport_s *fcport = ln->fcport;
  2339. if (fcport->bfa->fcs) {
  2340. fcport->event_cbfn(fcport->event_cbarg, event);
  2341. bfa_sm_send_event(ln, BFA_FCPORT_LN_SM_NOTIFICATION);
  2342. } else {
  2343. ln->ln_event = event;
  2344. bfa_cb_queue(fcport->bfa, &ln->ln_qe,
  2345. __bfa_cb_fcport_event, ln);
  2346. }
  2347. }
  2348. #define FCPORT_STATS_DMA_SZ (BFA_ROUNDUP(sizeof(union bfa_fcport_stats_u), \
  2349. BFA_CACHELINE_SZ))
  2350. static void
  2351. bfa_fcport_meminfo(struct bfa_iocfc_cfg_s *cfg, u32 *ndm_len,
  2352. u32 *dm_len)
  2353. {
  2354. *dm_len += FCPORT_STATS_DMA_SZ;
  2355. }
  2356. static void
  2357. bfa_fcport_qresume(void *cbarg)
  2358. {
  2359. struct bfa_fcport_s *fcport = cbarg;
  2360. bfa_sm_send_event(fcport, BFA_FCPORT_SM_QRESUME);
  2361. }
  2362. static void
  2363. bfa_fcport_mem_claim(struct bfa_fcport_s *fcport, struct bfa_meminfo_s *meminfo)
  2364. {
  2365. u8 *dm_kva;
  2366. u64 dm_pa;
  2367. dm_kva = bfa_meminfo_dma_virt(meminfo);
  2368. dm_pa = bfa_meminfo_dma_phys(meminfo);
  2369. fcport->stats_kva = dm_kva;
  2370. fcport->stats_pa = dm_pa;
  2371. fcport->stats = (union bfa_fcport_stats_u *) dm_kva;
  2372. dm_kva += FCPORT_STATS_DMA_SZ;
  2373. dm_pa += FCPORT_STATS_DMA_SZ;
  2374. bfa_meminfo_dma_virt(meminfo) = dm_kva;
  2375. bfa_meminfo_dma_phys(meminfo) = dm_pa;
  2376. }
  2377. /*
  2378. * Memory initialization.
  2379. */
  2380. static void
  2381. bfa_fcport_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
  2382. struct bfa_meminfo_s *meminfo, struct bfa_pcidev_s *pcidev)
  2383. {
  2384. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  2385. struct bfa_port_cfg_s *port_cfg = &fcport->cfg;
  2386. struct bfa_fcport_ln_s *ln = &fcport->ln;
  2387. struct timeval tv;
  2388. memset(fcport, 0, sizeof(struct bfa_fcport_s));
  2389. fcport->bfa = bfa;
  2390. ln->fcport = fcport;
  2391. bfa_fcport_mem_claim(fcport, meminfo);
  2392. bfa_sm_set_state(fcport, bfa_fcport_sm_uninit);
  2393. bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn);
  2394. /*
  2395. * initialize time stamp for stats reset
  2396. */
  2397. do_gettimeofday(&tv);
  2398. fcport->stats_reset_time = tv.tv_sec;
  2399. /*
  2400. * initialize and set default configuration
  2401. */
  2402. port_cfg->topology = BFA_PORT_TOPOLOGY_P2P;
  2403. port_cfg->speed = BFA_PORT_SPEED_AUTO;
  2404. port_cfg->trunked = BFA_FALSE;
  2405. port_cfg->maxfrsize = 0;
  2406. port_cfg->trl_def_speed = BFA_PORT_SPEED_1GBPS;
  2407. bfa_reqq_winit(&fcport->reqq_wait, bfa_fcport_qresume, fcport);
  2408. }
  2409. static void
  2410. bfa_fcport_detach(struct bfa_s *bfa)
  2411. {
  2412. }
  2413. /*
  2414. * Called when IOC is ready.
  2415. */
  2416. static void
  2417. bfa_fcport_start(struct bfa_s *bfa)
  2418. {
  2419. bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_START);
  2420. }
  2421. /*
  2422. * Called before IOC is stopped.
  2423. */
  2424. static void
  2425. bfa_fcport_stop(struct bfa_s *bfa)
  2426. {
  2427. bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_STOP);
  2428. bfa_trunk_iocdisable(bfa);
  2429. }
  2430. /*
  2431. * Called when IOC failure is detected.
  2432. */
  2433. static void
  2434. bfa_fcport_iocdisable(struct bfa_s *bfa)
  2435. {
  2436. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  2437. bfa_sm_send_event(fcport, BFA_FCPORT_SM_HWFAIL);
  2438. bfa_trunk_iocdisable(bfa);
  2439. }
  2440. static void
  2441. bfa_fcport_update_linkinfo(struct bfa_fcport_s *fcport)
  2442. {
  2443. struct bfi_fcport_event_s *pevent = fcport->event_arg.i2hmsg.event;
  2444. struct bfa_fcport_trunk_s *trunk = &fcport->trunk;
  2445. fcport->speed = pevent->link_state.speed;
  2446. fcport->topology = pevent->link_state.topology;
  2447. if (fcport->topology == BFA_PORT_TOPOLOGY_LOOP)
  2448. fcport->myalpa = 0;
  2449. /* QoS Details */
  2450. fcport->qos_attr = pevent->link_state.qos_attr;
  2451. fcport->qos_vc_attr = pevent->link_state.vc_fcf.qos_vc_attr;
  2452. /*
  2453. * update trunk state if applicable
  2454. */
  2455. if (!fcport->cfg.trunked)
  2456. trunk->attr.state = BFA_TRUNK_DISABLED;
  2457. /* update FCoE specific */
  2458. fcport->fcoe_vlan = be16_to_cpu(pevent->link_state.vc_fcf.fcf.vlan);
  2459. bfa_trc(fcport->bfa, fcport->speed);
  2460. bfa_trc(fcport->bfa, fcport->topology);
  2461. }
  2462. static void
  2463. bfa_fcport_reset_linkinfo(struct bfa_fcport_s *fcport)
  2464. {
  2465. fcport->speed = BFA_PORT_SPEED_UNKNOWN;
  2466. fcport->topology = BFA_PORT_TOPOLOGY_NONE;
  2467. }
  2468. /*
  2469. * Send port enable message to firmware.
  2470. */
  2471. static bfa_boolean_t
  2472. bfa_fcport_send_enable(struct bfa_fcport_s *fcport)
  2473. {
  2474. struct bfi_fcport_enable_req_s *m;
  2475. /*
  2476. * Increment message tag before queue check, so that responses to old
  2477. * requests are discarded.
  2478. */
  2479. fcport->msgtag++;
  2480. /*
  2481. * check for room in queue to send request now
  2482. */
  2483. m = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
  2484. if (!m) {
  2485. bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT,
  2486. &fcport->reqq_wait);
  2487. return BFA_FALSE;
  2488. }
  2489. bfi_h2i_set(m->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_ENABLE_REQ,
  2490. bfa_lpuid(fcport->bfa));
  2491. m->nwwn = fcport->nwwn;
  2492. m->pwwn = fcport->pwwn;
  2493. m->port_cfg = fcport->cfg;
  2494. m->msgtag = fcport->msgtag;
  2495. m->port_cfg.maxfrsize = cpu_to_be16(fcport->cfg.maxfrsize);
  2496. m->use_flash_cfg = fcport->use_flash_cfg;
  2497. bfa_dma_be_addr_set(m->stats_dma_addr, fcport->stats_pa);
  2498. bfa_trc(fcport->bfa, m->stats_dma_addr.a32.addr_lo);
  2499. bfa_trc(fcport->bfa, m->stats_dma_addr.a32.addr_hi);
  2500. /*
  2501. * queue I/O message to firmware
  2502. */
  2503. bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT);
  2504. return BFA_TRUE;
  2505. }
  2506. /*
  2507. * Send port disable message to firmware.
  2508. */
  2509. static bfa_boolean_t
  2510. bfa_fcport_send_disable(struct bfa_fcport_s *fcport)
  2511. {
  2512. struct bfi_fcport_req_s *m;
  2513. /*
  2514. * Increment message tag before queue check, so that responses to old
  2515. * requests are discarded.
  2516. */
  2517. fcport->msgtag++;
  2518. /*
  2519. * check for room in queue to send request now
  2520. */
  2521. m = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
  2522. if (!m) {
  2523. bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT,
  2524. &fcport->reqq_wait);
  2525. return BFA_FALSE;
  2526. }
  2527. bfi_h2i_set(m->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_DISABLE_REQ,
  2528. bfa_lpuid(fcport->bfa));
  2529. m->msgtag = fcport->msgtag;
  2530. /*
  2531. * queue I/O message to firmware
  2532. */
  2533. bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT);
  2534. return BFA_TRUE;
  2535. }
  2536. static void
  2537. bfa_fcport_set_wwns(struct bfa_fcport_s *fcport)
  2538. {
  2539. fcport->pwwn = fcport->bfa->ioc.attr->pwwn;
  2540. fcport->nwwn = fcport->bfa->ioc.attr->nwwn;
  2541. bfa_trc(fcport->bfa, fcport->pwwn);
  2542. bfa_trc(fcport->bfa, fcport->nwwn);
  2543. }
  2544. static void
  2545. bfa_fcport_send_txcredit(void *port_cbarg)
  2546. {
  2547. struct bfa_fcport_s *fcport = port_cbarg;
  2548. struct bfi_fcport_set_svc_params_req_s *m;
  2549. /*
  2550. * check for room in queue to send request now
  2551. */
  2552. m = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
  2553. if (!m) {
  2554. bfa_trc(fcport->bfa, fcport->cfg.tx_bbcredit);
  2555. return;
  2556. }
  2557. bfi_h2i_set(m->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_SET_SVC_PARAMS_REQ,
  2558. bfa_lpuid(fcport->bfa));
  2559. m->tx_bbcredit = cpu_to_be16((u16)fcport->cfg.tx_bbcredit);
  2560. /*
  2561. * queue I/O message to firmware
  2562. */
  2563. bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT);
  2564. }
  2565. static void
  2566. bfa_fcport_qos_stats_swap(struct bfa_qos_stats_s *d,
  2567. struct bfa_qos_stats_s *s)
  2568. {
  2569. u32 *dip = (u32 *) d;
  2570. __be32 *sip = (__be32 *) s;
  2571. int i;
  2572. /* Now swap the 32 bit fields */
  2573. for (i = 0; i < (sizeof(struct bfa_qos_stats_s)/sizeof(u32)); ++i)
  2574. dip[i] = be32_to_cpu(sip[i]);
  2575. }
  2576. static void
  2577. bfa_fcport_fcoe_stats_swap(struct bfa_fcoe_stats_s *d,
  2578. struct bfa_fcoe_stats_s *s)
  2579. {
  2580. u32 *dip = (u32 *) d;
  2581. __be32 *sip = (__be32 *) s;
  2582. int i;
  2583. for (i = 0; i < ((sizeof(struct bfa_fcoe_stats_s))/sizeof(u32));
  2584. i = i + 2) {
  2585. #ifdef __BIG_ENDIAN
  2586. dip[i] = be32_to_cpu(sip[i]);
  2587. dip[i + 1] = be32_to_cpu(sip[i + 1]);
  2588. #else
  2589. dip[i] = be32_to_cpu(sip[i + 1]);
  2590. dip[i + 1] = be32_to_cpu(sip[i]);
  2591. #endif
  2592. }
  2593. }
  2594. static void
  2595. __bfa_cb_fcport_stats_get(void *cbarg, bfa_boolean_t complete)
  2596. {
  2597. struct bfa_fcport_s *fcport = cbarg;
  2598. if (complete) {
  2599. if (fcport->stats_status == BFA_STATUS_OK) {
  2600. struct timeval tv;
  2601. /* Swap FC QoS or FCoE stats */
  2602. if (bfa_ioc_get_fcmode(&fcport->bfa->ioc)) {
  2603. bfa_fcport_qos_stats_swap(
  2604. &fcport->stats_ret->fcqos,
  2605. &fcport->stats->fcqos);
  2606. } else {
  2607. bfa_fcport_fcoe_stats_swap(
  2608. &fcport->stats_ret->fcoe,
  2609. &fcport->stats->fcoe);
  2610. do_gettimeofday(&tv);
  2611. fcport->stats_ret->fcoe.secs_reset =
  2612. tv.tv_sec - fcport->stats_reset_time;
  2613. }
  2614. }
  2615. fcport->stats_cbfn(fcport->stats_cbarg, fcport->stats_status);
  2616. } else {
  2617. fcport->stats_busy = BFA_FALSE;
  2618. fcport->stats_status = BFA_STATUS_OK;
  2619. }
  2620. }
  2621. static void
  2622. bfa_fcport_stats_get_timeout(void *cbarg)
  2623. {
  2624. struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
  2625. bfa_trc(fcport->bfa, fcport->stats_qfull);
  2626. if (fcport->stats_qfull) {
  2627. bfa_reqq_wcancel(&fcport->stats_reqq_wait);
  2628. fcport->stats_qfull = BFA_FALSE;
  2629. }
  2630. fcport->stats_status = BFA_STATUS_ETIMER;
  2631. bfa_cb_queue(fcport->bfa, &fcport->hcb_qe, __bfa_cb_fcport_stats_get,
  2632. fcport);
  2633. }
  2634. static void
  2635. bfa_fcport_send_stats_get(void *cbarg)
  2636. {
  2637. struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
  2638. struct bfi_fcport_req_s *msg;
  2639. msg = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
  2640. if (!msg) {
  2641. fcport->stats_qfull = BFA_TRUE;
  2642. bfa_reqq_winit(&fcport->stats_reqq_wait,
  2643. bfa_fcport_send_stats_get, fcport);
  2644. bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT,
  2645. &fcport->stats_reqq_wait);
  2646. return;
  2647. }
  2648. fcport->stats_qfull = BFA_FALSE;
  2649. memset(msg, 0, sizeof(struct bfi_fcport_req_s));
  2650. bfi_h2i_set(msg->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_STATS_GET_REQ,
  2651. bfa_lpuid(fcport->bfa));
  2652. bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT);
  2653. }
  2654. static void
  2655. __bfa_cb_fcport_stats_clr(void *cbarg, bfa_boolean_t complete)
  2656. {
  2657. struct bfa_fcport_s *fcport = cbarg;
  2658. if (complete) {
  2659. struct timeval tv;
  2660. /*
  2661. * re-initialize time stamp for stats reset
  2662. */
  2663. do_gettimeofday(&tv);
  2664. fcport->stats_reset_time = tv.tv_sec;
  2665. fcport->stats_cbfn(fcport->stats_cbarg, fcport->stats_status);
  2666. } else {
  2667. fcport->stats_busy = BFA_FALSE;
  2668. fcport->stats_status = BFA_STATUS_OK;
  2669. }
  2670. }
  2671. static void
  2672. bfa_fcport_stats_clr_timeout(void *cbarg)
  2673. {
  2674. struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
  2675. bfa_trc(fcport->bfa, fcport->stats_qfull);
  2676. if (fcport->stats_qfull) {
  2677. bfa_reqq_wcancel(&fcport->stats_reqq_wait);
  2678. fcport->stats_qfull = BFA_FALSE;
  2679. }
  2680. fcport->stats_status = BFA_STATUS_ETIMER;
  2681. bfa_cb_queue(fcport->bfa, &fcport->hcb_qe,
  2682. __bfa_cb_fcport_stats_clr, fcport);
  2683. }
  2684. static void
  2685. bfa_fcport_send_stats_clear(void *cbarg)
  2686. {
  2687. struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
  2688. struct bfi_fcport_req_s *msg;
  2689. msg = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
  2690. if (!msg) {
  2691. fcport->stats_qfull = BFA_TRUE;
  2692. bfa_reqq_winit(&fcport->stats_reqq_wait,
  2693. bfa_fcport_send_stats_clear, fcport);
  2694. bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT,
  2695. &fcport->stats_reqq_wait);
  2696. return;
  2697. }
  2698. fcport->stats_qfull = BFA_FALSE;
  2699. memset(msg, 0, sizeof(struct bfi_fcport_req_s));
  2700. bfi_h2i_set(msg->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_STATS_CLEAR_REQ,
  2701. bfa_lpuid(fcport->bfa));
  2702. bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT);
  2703. }
  2704. /*
  2705. * Handle trunk SCN event from firmware.
  2706. */
  2707. static void
  2708. bfa_trunk_scn(struct bfa_fcport_s *fcport, struct bfi_fcport_trunk_scn_s *scn)
  2709. {
  2710. struct bfa_fcport_trunk_s *trunk = &fcport->trunk;
  2711. struct bfi_fcport_trunk_link_s *tlink;
  2712. struct bfa_trunk_link_attr_s *lattr;
  2713. enum bfa_trunk_state state_prev;
  2714. int i;
  2715. int link_bm = 0;
  2716. bfa_trc(fcport->bfa, fcport->cfg.trunked);
  2717. WARN_ON(scn->trunk_state != BFA_TRUNK_ONLINE &&
  2718. scn->trunk_state != BFA_TRUNK_OFFLINE);
  2719. bfa_trc(fcport->bfa, trunk->attr.state);
  2720. bfa_trc(fcport->bfa, scn->trunk_state);
  2721. bfa_trc(fcport->bfa, scn->trunk_speed);
  2722. /*
  2723. * Save off new state for trunk attribute query
  2724. */
  2725. state_prev = trunk->attr.state;
  2726. if (fcport->cfg.trunked && (trunk->attr.state != BFA_TRUNK_DISABLED))
  2727. trunk->attr.state = scn->trunk_state;
  2728. trunk->attr.speed = scn->trunk_speed;
  2729. for (i = 0; i < BFA_TRUNK_MAX_PORTS; i++) {
  2730. lattr = &trunk->attr.link_attr[i];
  2731. tlink = &scn->tlink[i];
  2732. lattr->link_state = tlink->state;
  2733. lattr->trunk_wwn = tlink->trunk_wwn;
  2734. lattr->fctl = tlink->fctl;
  2735. lattr->speed = tlink->speed;
  2736. lattr->deskew = be32_to_cpu(tlink->deskew);
  2737. if (tlink->state == BFA_TRUNK_LINK_STATE_UP) {
  2738. fcport->speed = tlink->speed;
  2739. fcport->topology = BFA_PORT_TOPOLOGY_P2P;
  2740. link_bm |= 1 << i;
  2741. }
  2742. bfa_trc(fcport->bfa, lattr->link_state);
  2743. bfa_trc(fcport->bfa, lattr->trunk_wwn);
  2744. bfa_trc(fcport->bfa, lattr->fctl);
  2745. bfa_trc(fcport->bfa, lattr->speed);
  2746. bfa_trc(fcport->bfa, lattr->deskew);
  2747. }
  2748. switch (link_bm) {
  2749. case 3:
  2750. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  2751. BFA_PL_EID_TRUNK_SCN, 0, "Trunk up(0,1)");
  2752. break;
  2753. case 2:
  2754. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  2755. BFA_PL_EID_TRUNK_SCN, 0, "Trunk up(-,1)");
  2756. break;
  2757. case 1:
  2758. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  2759. BFA_PL_EID_TRUNK_SCN, 0, "Trunk up(0,-)");
  2760. break;
  2761. default:
  2762. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  2763. BFA_PL_EID_TRUNK_SCN, 0, "Trunk down");
  2764. }
  2765. /*
  2766. * Notify upper layers if trunk state changed.
  2767. */
  2768. if ((state_prev != trunk->attr.state) ||
  2769. (scn->trunk_state == BFA_TRUNK_OFFLINE)) {
  2770. bfa_fcport_scn(fcport, (scn->trunk_state == BFA_TRUNK_ONLINE) ?
  2771. BFA_PORT_LINKUP : BFA_PORT_LINKDOWN, BFA_TRUE);
  2772. }
  2773. }
  2774. static void
  2775. bfa_trunk_iocdisable(struct bfa_s *bfa)
  2776. {
  2777. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  2778. int i = 0;
  2779. /*
  2780. * In trunked mode, notify upper layers that link is down
  2781. */
  2782. if (fcport->cfg.trunked) {
  2783. if (fcport->trunk.attr.state == BFA_TRUNK_ONLINE)
  2784. bfa_fcport_scn(fcport, BFA_PORT_LINKDOWN, BFA_TRUE);
  2785. fcport->trunk.attr.state = BFA_TRUNK_OFFLINE;
  2786. fcport->trunk.attr.speed = BFA_PORT_SPEED_UNKNOWN;
  2787. for (i = 0; i < BFA_TRUNK_MAX_PORTS; i++) {
  2788. fcport->trunk.attr.link_attr[i].trunk_wwn = 0;
  2789. fcport->trunk.attr.link_attr[i].fctl =
  2790. BFA_TRUNK_LINK_FCTL_NORMAL;
  2791. fcport->trunk.attr.link_attr[i].link_state =
  2792. BFA_TRUNK_LINK_STATE_DN_LINKDN;
  2793. fcport->trunk.attr.link_attr[i].speed =
  2794. BFA_PORT_SPEED_UNKNOWN;
  2795. fcport->trunk.attr.link_attr[i].deskew = 0;
  2796. }
  2797. }
  2798. }
  2799. /*
  2800. * Called to initialize port attributes
  2801. */
  2802. void
  2803. bfa_fcport_init(struct bfa_s *bfa)
  2804. {
  2805. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  2806. /*
  2807. * Initialize port attributes from IOC hardware data.
  2808. */
  2809. bfa_fcport_set_wwns(fcport);
  2810. if (fcport->cfg.maxfrsize == 0)
  2811. fcport->cfg.maxfrsize = bfa_ioc_maxfrsize(&bfa->ioc);
  2812. fcport->cfg.rx_bbcredit = bfa_ioc_rx_bbcredit(&bfa->ioc);
  2813. fcport->speed_sup = bfa_ioc_speed_sup(&bfa->ioc);
  2814. WARN_ON(!fcport->cfg.maxfrsize);
  2815. WARN_ON(!fcport->cfg.rx_bbcredit);
  2816. WARN_ON(!fcport->speed_sup);
  2817. }
  2818. /*
  2819. * Firmware message handler.
  2820. */
  2821. void
  2822. bfa_fcport_isr(struct bfa_s *bfa, struct bfi_msg_s *msg)
  2823. {
  2824. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  2825. union bfi_fcport_i2h_msg_u i2hmsg;
  2826. i2hmsg.msg = msg;
  2827. fcport->event_arg.i2hmsg = i2hmsg;
  2828. bfa_trc(bfa, msg->mhdr.msg_id);
  2829. bfa_trc(bfa, bfa_sm_to_state(hal_port_sm_table, fcport->sm));
  2830. switch (msg->mhdr.msg_id) {
  2831. case BFI_FCPORT_I2H_ENABLE_RSP:
  2832. if (fcport->msgtag == i2hmsg.penable_rsp->msgtag) {
  2833. if (fcport->use_flash_cfg) {
  2834. fcport->cfg = i2hmsg.penable_rsp->port_cfg;
  2835. fcport->cfg.maxfrsize =
  2836. cpu_to_be16(fcport->cfg.maxfrsize);
  2837. fcport->cfg.path_tov =
  2838. cpu_to_be16(fcport->cfg.path_tov);
  2839. fcport->cfg.q_depth =
  2840. cpu_to_be16(fcport->cfg.q_depth);
  2841. if (fcport->cfg.trunked)
  2842. fcport->trunk.attr.state =
  2843. BFA_TRUNK_OFFLINE;
  2844. else
  2845. fcport->trunk.attr.state =
  2846. BFA_TRUNK_DISABLED;
  2847. fcport->use_flash_cfg = BFA_FALSE;
  2848. }
  2849. bfa_sm_send_event(fcport, BFA_FCPORT_SM_FWRSP);
  2850. }
  2851. break;
  2852. case BFI_FCPORT_I2H_DISABLE_RSP:
  2853. if (fcport->msgtag == i2hmsg.penable_rsp->msgtag)
  2854. bfa_sm_send_event(fcport, BFA_FCPORT_SM_FWRSP);
  2855. break;
  2856. case BFI_FCPORT_I2H_EVENT:
  2857. if (i2hmsg.event->link_state.linkstate == BFA_PORT_LINKUP)
  2858. bfa_sm_send_event(fcport, BFA_FCPORT_SM_LINKUP);
  2859. else
  2860. bfa_sm_send_event(fcport, BFA_FCPORT_SM_LINKDOWN);
  2861. break;
  2862. case BFI_FCPORT_I2H_TRUNK_SCN:
  2863. bfa_trunk_scn(fcport, i2hmsg.trunk_scn);
  2864. break;
  2865. case BFI_FCPORT_I2H_STATS_GET_RSP:
  2866. /*
  2867. * check for timer pop before processing the rsp
  2868. */
  2869. if (fcport->stats_busy == BFA_FALSE ||
  2870. fcport->stats_status == BFA_STATUS_ETIMER)
  2871. break;
  2872. bfa_timer_stop(&fcport->timer);
  2873. fcport->stats_status = i2hmsg.pstatsget_rsp->status;
  2874. bfa_cb_queue(fcport->bfa, &fcport->hcb_qe,
  2875. __bfa_cb_fcport_stats_get, fcport);
  2876. break;
  2877. case BFI_FCPORT_I2H_STATS_CLEAR_RSP:
  2878. /*
  2879. * check for timer pop before processing the rsp
  2880. */
  2881. if (fcport->stats_busy == BFA_FALSE ||
  2882. fcport->stats_status == BFA_STATUS_ETIMER)
  2883. break;
  2884. bfa_timer_stop(&fcport->timer);
  2885. fcport->stats_status = BFA_STATUS_OK;
  2886. bfa_cb_queue(fcport->bfa, &fcport->hcb_qe,
  2887. __bfa_cb_fcport_stats_clr, fcport);
  2888. break;
  2889. case BFI_FCPORT_I2H_ENABLE_AEN:
  2890. bfa_sm_send_event(fcport, BFA_FCPORT_SM_ENABLE);
  2891. break;
  2892. case BFI_FCPORT_I2H_DISABLE_AEN:
  2893. bfa_sm_send_event(fcport, BFA_FCPORT_SM_DISABLE);
  2894. break;
  2895. default:
  2896. WARN_ON(1);
  2897. break;
  2898. }
  2899. }
  2900. /*
  2901. * Registered callback for port events.
  2902. */
  2903. void
  2904. bfa_fcport_event_register(struct bfa_s *bfa,
  2905. void (*cbfn) (void *cbarg,
  2906. enum bfa_port_linkstate event),
  2907. void *cbarg)
  2908. {
  2909. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  2910. fcport->event_cbfn = cbfn;
  2911. fcport->event_cbarg = cbarg;
  2912. }
  2913. bfa_status_t
  2914. bfa_fcport_enable(struct bfa_s *bfa)
  2915. {
  2916. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  2917. if (bfa_ioc_is_disabled(&bfa->ioc))
  2918. return BFA_STATUS_IOC_DISABLED;
  2919. if (fcport->diag_busy)
  2920. return BFA_STATUS_DIAG_BUSY;
  2921. bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_ENABLE);
  2922. return BFA_STATUS_OK;
  2923. }
  2924. bfa_status_t
  2925. bfa_fcport_disable(struct bfa_s *bfa)
  2926. {
  2927. if (bfa_ioc_is_disabled(&bfa->ioc))
  2928. return BFA_STATUS_IOC_DISABLED;
  2929. bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_DISABLE);
  2930. return BFA_STATUS_OK;
  2931. }
  2932. /*
  2933. * Configure port speed.
  2934. */
  2935. bfa_status_t
  2936. bfa_fcport_cfg_speed(struct bfa_s *bfa, enum bfa_port_speed speed)
  2937. {
  2938. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  2939. bfa_trc(bfa, speed);
  2940. if (fcport->cfg.trunked == BFA_TRUE)
  2941. return BFA_STATUS_TRUNK_ENABLED;
  2942. if ((speed != BFA_PORT_SPEED_AUTO) && (speed > fcport->speed_sup)) {
  2943. bfa_trc(bfa, fcport->speed_sup);
  2944. return BFA_STATUS_UNSUPP_SPEED;
  2945. }
  2946. fcport->cfg.speed = speed;
  2947. return BFA_STATUS_OK;
  2948. }
  2949. /*
  2950. * Get current speed.
  2951. */
  2952. enum bfa_port_speed
  2953. bfa_fcport_get_speed(struct bfa_s *bfa)
  2954. {
  2955. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  2956. return fcport->speed;
  2957. }
  2958. /*
  2959. * Configure port topology.
  2960. */
  2961. bfa_status_t
  2962. bfa_fcport_cfg_topology(struct bfa_s *bfa, enum bfa_port_topology topology)
  2963. {
  2964. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  2965. bfa_trc(bfa, topology);
  2966. bfa_trc(bfa, fcport->cfg.topology);
  2967. switch (topology) {
  2968. case BFA_PORT_TOPOLOGY_P2P:
  2969. case BFA_PORT_TOPOLOGY_LOOP:
  2970. case BFA_PORT_TOPOLOGY_AUTO:
  2971. break;
  2972. default:
  2973. return BFA_STATUS_EINVAL;
  2974. }
  2975. fcport->cfg.topology = topology;
  2976. return BFA_STATUS_OK;
  2977. }
  2978. /*
  2979. * Get current topology.
  2980. */
  2981. enum bfa_port_topology
  2982. bfa_fcport_get_topology(struct bfa_s *bfa)
  2983. {
  2984. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  2985. return fcport->topology;
  2986. }
  2987. bfa_status_t
  2988. bfa_fcport_cfg_hardalpa(struct bfa_s *bfa, u8 alpa)
  2989. {
  2990. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  2991. bfa_trc(bfa, alpa);
  2992. bfa_trc(bfa, fcport->cfg.cfg_hardalpa);
  2993. bfa_trc(bfa, fcport->cfg.hardalpa);
  2994. fcport->cfg.cfg_hardalpa = BFA_TRUE;
  2995. fcport->cfg.hardalpa = alpa;
  2996. return BFA_STATUS_OK;
  2997. }
  2998. bfa_status_t
  2999. bfa_fcport_clr_hardalpa(struct bfa_s *bfa)
  3000. {
  3001. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3002. bfa_trc(bfa, fcport->cfg.cfg_hardalpa);
  3003. bfa_trc(bfa, fcport->cfg.hardalpa);
  3004. fcport->cfg.cfg_hardalpa = BFA_FALSE;
  3005. return BFA_STATUS_OK;
  3006. }
  3007. bfa_boolean_t
  3008. bfa_fcport_get_hardalpa(struct bfa_s *bfa, u8 *alpa)
  3009. {
  3010. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3011. *alpa = fcport->cfg.hardalpa;
  3012. return fcport->cfg.cfg_hardalpa;
  3013. }
  3014. u8
  3015. bfa_fcport_get_myalpa(struct bfa_s *bfa)
  3016. {
  3017. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3018. return fcport->myalpa;
  3019. }
  3020. bfa_status_t
  3021. bfa_fcport_cfg_maxfrsize(struct bfa_s *bfa, u16 maxfrsize)
  3022. {
  3023. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3024. bfa_trc(bfa, maxfrsize);
  3025. bfa_trc(bfa, fcport->cfg.maxfrsize);
  3026. /* with in range */
  3027. if ((maxfrsize > FC_MAX_PDUSZ) || (maxfrsize < FC_MIN_PDUSZ))
  3028. return BFA_STATUS_INVLD_DFSZ;
  3029. /* power of 2, if not the max frame size of 2112 */
  3030. if ((maxfrsize != FC_MAX_PDUSZ) && (maxfrsize & (maxfrsize - 1)))
  3031. return BFA_STATUS_INVLD_DFSZ;
  3032. fcport->cfg.maxfrsize = maxfrsize;
  3033. return BFA_STATUS_OK;
  3034. }
  3035. u16
  3036. bfa_fcport_get_maxfrsize(struct bfa_s *bfa)
  3037. {
  3038. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3039. return fcport->cfg.maxfrsize;
  3040. }
  3041. u8
  3042. bfa_fcport_get_rx_bbcredit(struct bfa_s *bfa)
  3043. {
  3044. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3045. return fcport->cfg.rx_bbcredit;
  3046. }
  3047. void
  3048. bfa_fcport_set_tx_bbcredit(struct bfa_s *bfa, u16 tx_bbcredit)
  3049. {
  3050. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3051. fcport->cfg.tx_bbcredit = (u8)tx_bbcredit;
  3052. bfa_fcport_send_txcredit(fcport);
  3053. }
  3054. /*
  3055. * Get port attributes.
  3056. */
  3057. wwn_t
  3058. bfa_fcport_get_wwn(struct bfa_s *bfa, bfa_boolean_t node)
  3059. {
  3060. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3061. if (node)
  3062. return fcport->nwwn;
  3063. else
  3064. return fcport->pwwn;
  3065. }
  3066. void
  3067. bfa_fcport_get_attr(struct bfa_s *bfa, struct bfa_port_attr_s *attr)
  3068. {
  3069. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3070. memset(attr, 0, sizeof(struct bfa_port_attr_s));
  3071. attr->nwwn = fcport->nwwn;
  3072. attr->pwwn = fcport->pwwn;
  3073. attr->factorypwwn = bfa->ioc.attr->mfg_pwwn;
  3074. attr->factorynwwn = bfa->ioc.attr->mfg_nwwn;
  3075. memcpy(&attr->pport_cfg, &fcport->cfg,
  3076. sizeof(struct bfa_port_cfg_s));
  3077. /* speed attributes */
  3078. attr->pport_cfg.speed = fcport->cfg.speed;
  3079. attr->speed_supported = fcport->speed_sup;
  3080. attr->speed = fcport->speed;
  3081. attr->cos_supported = FC_CLASS_3;
  3082. /* topology attributes */
  3083. attr->pport_cfg.topology = fcport->cfg.topology;
  3084. attr->topology = fcport->topology;
  3085. attr->pport_cfg.trunked = fcport->cfg.trunked;
  3086. /* beacon attributes */
  3087. attr->beacon = fcport->beacon;
  3088. attr->link_e2e_beacon = fcport->link_e2e_beacon;
  3089. attr->plog_enabled = (bfa_boolean_t)fcport->bfa->plog->plog_enabled;
  3090. attr->io_profile = bfa_fcpim_get_io_profile(fcport->bfa);
  3091. attr->pport_cfg.path_tov = bfa_fcpim_path_tov_get(bfa);
  3092. attr->pport_cfg.q_depth = bfa_fcpim_qdepth_get(bfa);
  3093. attr->port_state = bfa_sm_to_state(hal_port_sm_table, fcport->sm);
  3094. if (bfa_ioc_is_disabled(&fcport->bfa->ioc))
  3095. attr->port_state = BFA_PORT_ST_IOCDIS;
  3096. else if (bfa_ioc_fw_mismatch(&fcport->bfa->ioc))
  3097. attr->port_state = BFA_PORT_ST_FWMISMATCH;
  3098. /* FCoE vlan */
  3099. attr->fcoe_vlan = fcport->fcoe_vlan;
  3100. }
  3101. #define BFA_FCPORT_STATS_TOV 1000
  3102. /*
  3103. * Fetch port statistics (FCQoS or FCoE).
  3104. */
  3105. bfa_status_t
  3106. bfa_fcport_get_stats(struct bfa_s *bfa, union bfa_fcport_stats_u *stats,
  3107. bfa_cb_port_t cbfn, void *cbarg)
  3108. {
  3109. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3110. if (fcport->stats_busy) {
  3111. bfa_trc(bfa, fcport->stats_busy);
  3112. return BFA_STATUS_DEVBUSY;
  3113. }
  3114. fcport->stats_busy = BFA_TRUE;
  3115. fcport->stats_ret = stats;
  3116. fcport->stats_cbfn = cbfn;
  3117. fcport->stats_cbarg = cbarg;
  3118. bfa_fcport_send_stats_get(fcport);
  3119. bfa_timer_start(bfa, &fcport->timer, bfa_fcport_stats_get_timeout,
  3120. fcport, BFA_FCPORT_STATS_TOV);
  3121. return BFA_STATUS_OK;
  3122. }
  3123. /*
  3124. * Reset port statistics (FCQoS or FCoE).
  3125. */
  3126. bfa_status_t
  3127. bfa_fcport_clear_stats(struct bfa_s *bfa, bfa_cb_port_t cbfn, void *cbarg)
  3128. {
  3129. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3130. if (fcport->stats_busy) {
  3131. bfa_trc(bfa, fcport->stats_busy);
  3132. return BFA_STATUS_DEVBUSY;
  3133. }
  3134. fcport->stats_busy = BFA_TRUE;
  3135. fcport->stats_cbfn = cbfn;
  3136. fcport->stats_cbarg = cbarg;
  3137. bfa_fcport_send_stats_clear(fcport);
  3138. bfa_timer_start(bfa, &fcport->timer, bfa_fcport_stats_clr_timeout,
  3139. fcport, BFA_FCPORT_STATS_TOV);
  3140. return BFA_STATUS_OK;
  3141. }
  3142. /*
  3143. * Fetch port attributes.
  3144. */
  3145. bfa_boolean_t
  3146. bfa_fcport_is_disabled(struct bfa_s *bfa)
  3147. {
  3148. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3149. return bfa_sm_to_state(hal_port_sm_table, fcport->sm) ==
  3150. BFA_PORT_ST_DISABLED;
  3151. }
  3152. bfa_boolean_t
  3153. bfa_fcport_is_ratelim(struct bfa_s *bfa)
  3154. {
  3155. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3156. return fcport->cfg.ratelimit ? BFA_TRUE : BFA_FALSE;
  3157. }
  3158. /*
  3159. * Get default minimum ratelim speed
  3160. */
  3161. enum bfa_port_speed
  3162. bfa_fcport_get_ratelim_speed(struct bfa_s *bfa)
  3163. {
  3164. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3165. bfa_trc(bfa, fcport->cfg.trl_def_speed);
  3166. return fcport->cfg.trl_def_speed;
  3167. }
  3168. bfa_boolean_t
  3169. bfa_fcport_is_linkup(struct bfa_s *bfa)
  3170. {
  3171. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3172. return (!fcport->cfg.trunked &&
  3173. bfa_sm_cmp_state(fcport, bfa_fcport_sm_linkup)) ||
  3174. (fcport->cfg.trunked &&
  3175. fcport->trunk.attr.state == BFA_TRUNK_ONLINE);
  3176. }
  3177. bfa_boolean_t
  3178. bfa_fcport_is_qos_enabled(struct bfa_s *bfa)
  3179. {
  3180. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3181. return fcport->cfg.qos_enabled;
  3182. }
  3183. /*
  3184. * Rport State machine functions
  3185. */
  3186. /*
  3187. * Beginning state, only online event expected.
  3188. */
  3189. static void
  3190. bfa_rport_sm_uninit(struct bfa_rport_s *rp, enum bfa_rport_event event)
  3191. {
  3192. bfa_trc(rp->bfa, rp->rport_tag);
  3193. bfa_trc(rp->bfa, event);
  3194. switch (event) {
  3195. case BFA_RPORT_SM_CREATE:
  3196. bfa_stats(rp, sm_un_cr);
  3197. bfa_sm_set_state(rp, bfa_rport_sm_created);
  3198. break;
  3199. default:
  3200. bfa_stats(rp, sm_un_unexp);
  3201. bfa_sm_fault(rp->bfa, event);
  3202. }
  3203. }
  3204. static void
  3205. bfa_rport_sm_created(struct bfa_rport_s *rp, enum bfa_rport_event event)
  3206. {
  3207. bfa_trc(rp->bfa, rp->rport_tag);
  3208. bfa_trc(rp->bfa, event);
  3209. switch (event) {
  3210. case BFA_RPORT_SM_ONLINE:
  3211. bfa_stats(rp, sm_cr_on);
  3212. if (bfa_rport_send_fwcreate(rp))
  3213. bfa_sm_set_state(rp, bfa_rport_sm_fwcreate);
  3214. else
  3215. bfa_sm_set_state(rp, bfa_rport_sm_fwcreate_qfull);
  3216. break;
  3217. case BFA_RPORT_SM_DELETE:
  3218. bfa_stats(rp, sm_cr_del);
  3219. bfa_sm_set_state(rp, bfa_rport_sm_uninit);
  3220. bfa_rport_free(rp);
  3221. break;
  3222. case BFA_RPORT_SM_HWFAIL:
  3223. bfa_stats(rp, sm_cr_hwf);
  3224. bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
  3225. break;
  3226. default:
  3227. bfa_stats(rp, sm_cr_unexp);
  3228. bfa_sm_fault(rp->bfa, event);
  3229. }
  3230. }
  3231. /*
  3232. * Waiting for rport create response from firmware.
  3233. */
  3234. static void
  3235. bfa_rport_sm_fwcreate(struct bfa_rport_s *rp, enum bfa_rport_event event)
  3236. {
  3237. bfa_trc(rp->bfa, rp->rport_tag);
  3238. bfa_trc(rp->bfa, event);
  3239. switch (event) {
  3240. case BFA_RPORT_SM_FWRSP:
  3241. bfa_stats(rp, sm_fwc_rsp);
  3242. bfa_sm_set_state(rp, bfa_rport_sm_online);
  3243. bfa_rport_online_cb(rp);
  3244. break;
  3245. case BFA_RPORT_SM_DELETE:
  3246. bfa_stats(rp, sm_fwc_del);
  3247. bfa_sm_set_state(rp, bfa_rport_sm_delete_pending);
  3248. break;
  3249. case BFA_RPORT_SM_OFFLINE:
  3250. bfa_stats(rp, sm_fwc_off);
  3251. bfa_sm_set_state(rp, bfa_rport_sm_offline_pending);
  3252. break;
  3253. case BFA_RPORT_SM_HWFAIL:
  3254. bfa_stats(rp, sm_fwc_hwf);
  3255. bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
  3256. break;
  3257. default:
  3258. bfa_stats(rp, sm_fwc_unexp);
  3259. bfa_sm_fault(rp->bfa, event);
  3260. }
  3261. }
  3262. /*
  3263. * Request queue is full, awaiting queue resume to send create request.
  3264. */
  3265. static void
  3266. bfa_rport_sm_fwcreate_qfull(struct bfa_rport_s *rp, enum bfa_rport_event event)
  3267. {
  3268. bfa_trc(rp->bfa, rp->rport_tag);
  3269. bfa_trc(rp->bfa, event);
  3270. switch (event) {
  3271. case BFA_RPORT_SM_QRESUME:
  3272. bfa_sm_set_state(rp, bfa_rport_sm_fwcreate);
  3273. bfa_rport_send_fwcreate(rp);
  3274. break;
  3275. case BFA_RPORT_SM_DELETE:
  3276. bfa_stats(rp, sm_fwc_del);
  3277. bfa_sm_set_state(rp, bfa_rport_sm_uninit);
  3278. bfa_reqq_wcancel(&rp->reqq_wait);
  3279. bfa_rport_free(rp);
  3280. break;
  3281. case BFA_RPORT_SM_OFFLINE:
  3282. bfa_stats(rp, sm_fwc_off);
  3283. bfa_sm_set_state(rp, bfa_rport_sm_offline);
  3284. bfa_reqq_wcancel(&rp->reqq_wait);
  3285. bfa_rport_offline_cb(rp);
  3286. break;
  3287. case BFA_RPORT_SM_HWFAIL:
  3288. bfa_stats(rp, sm_fwc_hwf);
  3289. bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
  3290. bfa_reqq_wcancel(&rp->reqq_wait);
  3291. break;
  3292. default:
  3293. bfa_stats(rp, sm_fwc_unexp);
  3294. bfa_sm_fault(rp->bfa, event);
  3295. }
  3296. }
  3297. /*
  3298. * Online state - normal parking state.
  3299. */
  3300. static void
  3301. bfa_rport_sm_online(struct bfa_rport_s *rp, enum bfa_rport_event event)
  3302. {
  3303. struct bfi_rport_qos_scn_s *qos_scn;
  3304. bfa_trc(rp->bfa, rp->rport_tag);
  3305. bfa_trc(rp->bfa, event);
  3306. switch (event) {
  3307. case BFA_RPORT_SM_OFFLINE:
  3308. bfa_stats(rp, sm_on_off);
  3309. if (bfa_rport_send_fwdelete(rp))
  3310. bfa_sm_set_state(rp, bfa_rport_sm_fwdelete);
  3311. else
  3312. bfa_sm_set_state(rp, bfa_rport_sm_fwdelete_qfull);
  3313. break;
  3314. case BFA_RPORT_SM_DELETE:
  3315. bfa_stats(rp, sm_on_del);
  3316. if (bfa_rport_send_fwdelete(rp))
  3317. bfa_sm_set_state(rp, bfa_rport_sm_deleting);
  3318. else
  3319. bfa_sm_set_state(rp, bfa_rport_sm_deleting_qfull);
  3320. break;
  3321. case BFA_RPORT_SM_HWFAIL:
  3322. bfa_stats(rp, sm_on_hwf);
  3323. bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
  3324. break;
  3325. case BFA_RPORT_SM_SET_SPEED:
  3326. bfa_rport_send_fwspeed(rp);
  3327. break;
  3328. case BFA_RPORT_SM_QOS_SCN:
  3329. qos_scn = (struct bfi_rport_qos_scn_s *) rp->event_arg.fw_msg;
  3330. rp->qos_attr = qos_scn->new_qos_attr;
  3331. bfa_trc(rp->bfa, qos_scn->old_qos_attr.qos_flow_id);
  3332. bfa_trc(rp->bfa, qos_scn->new_qos_attr.qos_flow_id);
  3333. bfa_trc(rp->bfa, qos_scn->old_qos_attr.qos_priority);
  3334. bfa_trc(rp->bfa, qos_scn->new_qos_attr.qos_priority);
  3335. qos_scn->old_qos_attr.qos_flow_id =
  3336. be32_to_cpu(qos_scn->old_qos_attr.qos_flow_id);
  3337. qos_scn->new_qos_attr.qos_flow_id =
  3338. be32_to_cpu(qos_scn->new_qos_attr.qos_flow_id);
  3339. if (qos_scn->old_qos_attr.qos_flow_id !=
  3340. qos_scn->new_qos_attr.qos_flow_id)
  3341. bfa_cb_rport_qos_scn_flowid(rp->rport_drv,
  3342. qos_scn->old_qos_attr,
  3343. qos_scn->new_qos_attr);
  3344. if (qos_scn->old_qos_attr.qos_priority !=
  3345. qos_scn->new_qos_attr.qos_priority)
  3346. bfa_cb_rport_qos_scn_prio(rp->rport_drv,
  3347. qos_scn->old_qos_attr,
  3348. qos_scn->new_qos_attr);
  3349. break;
  3350. default:
  3351. bfa_stats(rp, sm_on_unexp);
  3352. bfa_sm_fault(rp->bfa, event);
  3353. }
  3354. }
  3355. /*
  3356. * Firmware rport is being deleted - awaiting f/w response.
  3357. */
  3358. static void
  3359. bfa_rport_sm_fwdelete(struct bfa_rport_s *rp, enum bfa_rport_event event)
  3360. {
  3361. bfa_trc(rp->bfa, rp->rport_tag);
  3362. bfa_trc(rp->bfa, event);
  3363. switch (event) {
  3364. case BFA_RPORT_SM_FWRSP:
  3365. bfa_stats(rp, sm_fwd_rsp);
  3366. bfa_sm_set_state(rp, bfa_rport_sm_offline);
  3367. bfa_rport_offline_cb(rp);
  3368. break;
  3369. case BFA_RPORT_SM_DELETE:
  3370. bfa_stats(rp, sm_fwd_del);
  3371. bfa_sm_set_state(rp, bfa_rport_sm_deleting);
  3372. break;
  3373. case BFA_RPORT_SM_HWFAIL:
  3374. bfa_stats(rp, sm_fwd_hwf);
  3375. bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
  3376. bfa_rport_offline_cb(rp);
  3377. break;
  3378. default:
  3379. bfa_stats(rp, sm_fwd_unexp);
  3380. bfa_sm_fault(rp->bfa, event);
  3381. }
  3382. }
  3383. static void
  3384. bfa_rport_sm_fwdelete_qfull(struct bfa_rport_s *rp, enum bfa_rport_event event)
  3385. {
  3386. bfa_trc(rp->bfa, rp->rport_tag);
  3387. bfa_trc(rp->bfa, event);
  3388. switch (event) {
  3389. case BFA_RPORT_SM_QRESUME:
  3390. bfa_sm_set_state(rp, bfa_rport_sm_fwdelete);
  3391. bfa_rport_send_fwdelete(rp);
  3392. break;
  3393. case BFA_RPORT_SM_DELETE:
  3394. bfa_stats(rp, sm_fwd_del);
  3395. bfa_sm_set_state(rp, bfa_rport_sm_deleting_qfull);
  3396. break;
  3397. case BFA_RPORT_SM_HWFAIL:
  3398. bfa_stats(rp, sm_fwd_hwf);
  3399. bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
  3400. bfa_reqq_wcancel(&rp->reqq_wait);
  3401. bfa_rport_offline_cb(rp);
  3402. break;
  3403. default:
  3404. bfa_stats(rp, sm_fwd_unexp);
  3405. bfa_sm_fault(rp->bfa, event);
  3406. }
  3407. }
  3408. /*
  3409. * Offline state.
  3410. */
  3411. static void
  3412. bfa_rport_sm_offline(struct bfa_rport_s *rp, enum bfa_rport_event event)
  3413. {
  3414. bfa_trc(rp->bfa, rp->rport_tag);
  3415. bfa_trc(rp->bfa, event);
  3416. switch (event) {
  3417. case BFA_RPORT_SM_DELETE:
  3418. bfa_stats(rp, sm_off_del);
  3419. bfa_sm_set_state(rp, bfa_rport_sm_uninit);
  3420. bfa_rport_free(rp);
  3421. break;
  3422. case BFA_RPORT_SM_ONLINE:
  3423. bfa_stats(rp, sm_off_on);
  3424. if (bfa_rport_send_fwcreate(rp))
  3425. bfa_sm_set_state(rp, bfa_rport_sm_fwcreate);
  3426. else
  3427. bfa_sm_set_state(rp, bfa_rport_sm_fwcreate_qfull);
  3428. break;
  3429. case BFA_RPORT_SM_HWFAIL:
  3430. bfa_stats(rp, sm_off_hwf);
  3431. bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
  3432. break;
  3433. default:
  3434. bfa_stats(rp, sm_off_unexp);
  3435. bfa_sm_fault(rp->bfa, event);
  3436. }
  3437. }
  3438. /*
  3439. * Rport is deleted, waiting for firmware response to delete.
  3440. */
  3441. static void
  3442. bfa_rport_sm_deleting(struct bfa_rport_s *rp, enum bfa_rport_event event)
  3443. {
  3444. bfa_trc(rp->bfa, rp->rport_tag);
  3445. bfa_trc(rp->bfa, event);
  3446. switch (event) {
  3447. case BFA_RPORT_SM_FWRSP:
  3448. bfa_stats(rp, sm_del_fwrsp);
  3449. bfa_sm_set_state(rp, bfa_rport_sm_uninit);
  3450. bfa_rport_free(rp);
  3451. break;
  3452. case BFA_RPORT_SM_HWFAIL:
  3453. bfa_stats(rp, sm_del_hwf);
  3454. bfa_sm_set_state(rp, bfa_rport_sm_uninit);
  3455. bfa_rport_free(rp);
  3456. break;
  3457. default:
  3458. bfa_sm_fault(rp->bfa, event);
  3459. }
  3460. }
  3461. static void
  3462. bfa_rport_sm_deleting_qfull(struct bfa_rport_s *rp, enum bfa_rport_event event)
  3463. {
  3464. bfa_trc(rp->bfa, rp->rport_tag);
  3465. bfa_trc(rp->bfa, event);
  3466. switch (event) {
  3467. case BFA_RPORT_SM_QRESUME:
  3468. bfa_stats(rp, sm_del_fwrsp);
  3469. bfa_sm_set_state(rp, bfa_rport_sm_deleting);
  3470. bfa_rport_send_fwdelete(rp);
  3471. break;
  3472. case BFA_RPORT_SM_HWFAIL:
  3473. bfa_stats(rp, sm_del_hwf);
  3474. bfa_sm_set_state(rp, bfa_rport_sm_uninit);
  3475. bfa_reqq_wcancel(&rp->reqq_wait);
  3476. bfa_rport_free(rp);
  3477. break;
  3478. default:
  3479. bfa_sm_fault(rp->bfa, event);
  3480. }
  3481. }
  3482. /*
  3483. * Waiting for rport create response from firmware. A delete is pending.
  3484. */
  3485. static void
  3486. bfa_rport_sm_delete_pending(struct bfa_rport_s *rp,
  3487. enum bfa_rport_event event)
  3488. {
  3489. bfa_trc(rp->bfa, rp->rport_tag);
  3490. bfa_trc(rp->bfa, event);
  3491. switch (event) {
  3492. case BFA_RPORT_SM_FWRSP:
  3493. bfa_stats(rp, sm_delp_fwrsp);
  3494. if (bfa_rport_send_fwdelete(rp))
  3495. bfa_sm_set_state(rp, bfa_rport_sm_deleting);
  3496. else
  3497. bfa_sm_set_state(rp, bfa_rport_sm_deleting_qfull);
  3498. break;
  3499. case BFA_RPORT_SM_HWFAIL:
  3500. bfa_stats(rp, sm_delp_hwf);
  3501. bfa_sm_set_state(rp, bfa_rport_sm_uninit);
  3502. bfa_rport_free(rp);
  3503. break;
  3504. default:
  3505. bfa_stats(rp, sm_delp_unexp);
  3506. bfa_sm_fault(rp->bfa, event);
  3507. }
  3508. }
  3509. /*
  3510. * Waiting for rport create response from firmware. Rport offline is pending.
  3511. */
  3512. static void
  3513. bfa_rport_sm_offline_pending(struct bfa_rport_s *rp,
  3514. enum bfa_rport_event event)
  3515. {
  3516. bfa_trc(rp->bfa, rp->rport_tag);
  3517. bfa_trc(rp->bfa, event);
  3518. switch (event) {
  3519. case BFA_RPORT_SM_FWRSP:
  3520. bfa_stats(rp, sm_offp_fwrsp);
  3521. if (bfa_rport_send_fwdelete(rp))
  3522. bfa_sm_set_state(rp, bfa_rport_sm_fwdelete);
  3523. else
  3524. bfa_sm_set_state(rp, bfa_rport_sm_fwdelete_qfull);
  3525. break;
  3526. case BFA_RPORT_SM_DELETE:
  3527. bfa_stats(rp, sm_offp_del);
  3528. bfa_sm_set_state(rp, bfa_rport_sm_delete_pending);
  3529. break;
  3530. case BFA_RPORT_SM_HWFAIL:
  3531. bfa_stats(rp, sm_offp_hwf);
  3532. bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
  3533. break;
  3534. default:
  3535. bfa_stats(rp, sm_offp_unexp);
  3536. bfa_sm_fault(rp->bfa, event);
  3537. }
  3538. }
  3539. /*
  3540. * IOC h/w failed.
  3541. */
  3542. static void
  3543. bfa_rport_sm_iocdisable(struct bfa_rport_s *rp, enum bfa_rport_event event)
  3544. {
  3545. bfa_trc(rp->bfa, rp->rport_tag);
  3546. bfa_trc(rp->bfa, event);
  3547. switch (event) {
  3548. case BFA_RPORT_SM_OFFLINE:
  3549. bfa_stats(rp, sm_iocd_off);
  3550. bfa_rport_offline_cb(rp);
  3551. break;
  3552. case BFA_RPORT_SM_DELETE:
  3553. bfa_stats(rp, sm_iocd_del);
  3554. bfa_sm_set_state(rp, bfa_rport_sm_uninit);
  3555. bfa_rport_free(rp);
  3556. break;
  3557. case BFA_RPORT_SM_ONLINE:
  3558. bfa_stats(rp, sm_iocd_on);
  3559. if (bfa_rport_send_fwcreate(rp))
  3560. bfa_sm_set_state(rp, bfa_rport_sm_fwcreate);
  3561. else
  3562. bfa_sm_set_state(rp, bfa_rport_sm_fwcreate_qfull);
  3563. break;
  3564. case BFA_RPORT_SM_HWFAIL:
  3565. break;
  3566. default:
  3567. bfa_stats(rp, sm_iocd_unexp);
  3568. bfa_sm_fault(rp->bfa, event);
  3569. }
  3570. }
  3571. /*
  3572. * bfa_rport_private BFA rport private functions
  3573. */
  3574. static void
  3575. __bfa_cb_rport_online(void *cbarg, bfa_boolean_t complete)
  3576. {
  3577. struct bfa_rport_s *rp = cbarg;
  3578. if (complete)
  3579. bfa_cb_rport_online(rp->rport_drv);
  3580. }
  3581. static void
  3582. __bfa_cb_rport_offline(void *cbarg, bfa_boolean_t complete)
  3583. {
  3584. struct bfa_rport_s *rp = cbarg;
  3585. if (complete)
  3586. bfa_cb_rport_offline(rp->rport_drv);
  3587. }
  3588. static void
  3589. bfa_rport_qresume(void *cbarg)
  3590. {
  3591. struct bfa_rport_s *rp = cbarg;
  3592. bfa_sm_send_event(rp, BFA_RPORT_SM_QRESUME);
  3593. }
  3594. static void
  3595. bfa_rport_meminfo(struct bfa_iocfc_cfg_s *cfg, u32 *km_len,
  3596. u32 *dm_len)
  3597. {
  3598. if (cfg->fwcfg.num_rports < BFA_RPORT_MIN)
  3599. cfg->fwcfg.num_rports = BFA_RPORT_MIN;
  3600. *km_len += cfg->fwcfg.num_rports * sizeof(struct bfa_rport_s);
  3601. }
  3602. static void
  3603. bfa_rport_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
  3604. struct bfa_meminfo_s *meminfo, struct bfa_pcidev_s *pcidev)
  3605. {
  3606. struct bfa_rport_mod_s *mod = BFA_RPORT_MOD(bfa);
  3607. struct bfa_rport_s *rp;
  3608. u16 i;
  3609. INIT_LIST_HEAD(&mod->rp_free_q);
  3610. INIT_LIST_HEAD(&mod->rp_active_q);
  3611. rp = (struct bfa_rport_s *) bfa_meminfo_kva(meminfo);
  3612. mod->rps_list = rp;
  3613. mod->num_rports = cfg->fwcfg.num_rports;
  3614. WARN_ON(!mod->num_rports ||
  3615. (mod->num_rports & (mod->num_rports - 1)));
  3616. for (i = 0; i < mod->num_rports; i++, rp++) {
  3617. memset(rp, 0, sizeof(struct bfa_rport_s));
  3618. rp->bfa = bfa;
  3619. rp->rport_tag = i;
  3620. bfa_sm_set_state(rp, bfa_rport_sm_uninit);
  3621. /*
  3622. * - is unused
  3623. */
  3624. if (i)
  3625. list_add_tail(&rp->qe, &mod->rp_free_q);
  3626. bfa_reqq_winit(&rp->reqq_wait, bfa_rport_qresume, rp);
  3627. }
  3628. /*
  3629. * consume memory
  3630. */
  3631. bfa_meminfo_kva(meminfo) = (u8 *) rp;
  3632. }
  3633. static void
  3634. bfa_rport_detach(struct bfa_s *bfa)
  3635. {
  3636. }
  3637. static void
  3638. bfa_rport_start(struct bfa_s *bfa)
  3639. {
  3640. }
  3641. static void
  3642. bfa_rport_stop(struct bfa_s *bfa)
  3643. {
  3644. }
  3645. static void
  3646. bfa_rport_iocdisable(struct bfa_s *bfa)
  3647. {
  3648. struct bfa_rport_mod_s *mod = BFA_RPORT_MOD(bfa);
  3649. struct bfa_rport_s *rport;
  3650. struct list_head *qe, *qen;
  3651. list_for_each_safe(qe, qen, &mod->rp_active_q) {
  3652. rport = (struct bfa_rport_s *) qe;
  3653. bfa_sm_send_event(rport, BFA_RPORT_SM_HWFAIL);
  3654. }
  3655. }
  3656. static struct bfa_rport_s *
  3657. bfa_rport_alloc(struct bfa_rport_mod_s *mod)
  3658. {
  3659. struct bfa_rport_s *rport;
  3660. bfa_q_deq(&mod->rp_free_q, &rport);
  3661. if (rport)
  3662. list_add_tail(&rport->qe, &mod->rp_active_q);
  3663. return rport;
  3664. }
  3665. static void
  3666. bfa_rport_free(struct bfa_rport_s *rport)
  3667. {
  3668. struct bfa_rport_mod_s *mod = BFA_RPORT_MOD(rport->bfa);
  3669. WARN_ON(!bfa_q_is_on_q(&mod->rp_active_q, rport));
  3670. list_del(&rport->qe);
  3671. list_add_tail(&rport->qe, &mod->rp_free_q);
  3672. }
  3673. static bfa_boolean_t
  3674. bfa_rport_send_fwcreate(struct bfa_rport_s *rp)
  3675. {
  3676. struct bfi_rport_create_req_s *m;
  3677. /*
  3678. * check for room in queue to send request now
  3679. */
  3680. m = bfa_reqq_next(rp->bfa, BFA_REQQ_RPORT);
  3681. if (!m) {
  3682. bfa_reqq_wait(rp->bfa, BFA_REQQ_RPORT, &rp->reqq_wait);
  3683. return BFA_FALSE;
  3684. }
  3685. bfi_h2i_set(m->mh, BFI_MC_RPORT, BFI_RPORT_H2I_CREATE_REQ,
  3686. bfa_lpuid(rp->bfa));
  3687. m->bfa_handle = rp->rport_tag;
  3688. m->max_frmsz = cpu_to_be16(rp->rport_info.max_frmsz);
  3689. m->pid = rp->rport_info.pid;
  3690. m->lp_tag = rp->rport_info.lp_tag;
  3691. m->local_pid = rp->rport_info.local_pid;
  3692. m->fc_class = rp->rport_info.fc_class;
  3693. m->vf_en = rp->rport_info.vf_en;
  3694. m->vf_id = rp->rport_info.vf_id;
  3695. m->cisc = rp->rport_info.cisc;
  3696. /*
  3697. * queue I/O message to firmware
  3698. */
  3699. bfa_reqq_produce(rp->bfa, BFA_REQQ_RPORT);
  3700. return BFA_TRUE;
  3701. }
  3702. static bfa_boolean_t
  3703. bfa_rport_send_fwdelete(struct bfa_rport_s *rp)
  3704. {
  3705. struct bfi_rport_delete_req_s *m;
  3706. /*
  3707. * check for room in queue to send request now
  3708. */
  3709. m = bfa_reqq_next(rp->bfa, BFA_REQQ_RPORT);
  3710. if (!m) {
  3711. bfa_reqq_wait(rp->bfa, BFA_REQQ_RPORT, &rp->reqq_wait);
  3712. return BFA_FALSE;
  3713. }
  3714. bfi_h2i_set(m->mh, BFI_MC_RPORT, BFI_RPORT_H2I_DELETE_REQ,
  3715. bfa_lpuid(rp->bfa));
  3716. m->fw_handle = rp->fw_handle;
  3717. /*
  3718. * queue I/O message to firmware
  3719. */
  3720. bfa_reqq_produce(rp->bfa, BFA_REQQ_RPORT);
  3721. return BFA_TRUE;
  3722. }
  3723. static bfa_boolean_t
  3724. bfa_rport_send_fwspeed(struct bfa_rport_s *rp)
  3725. {
  3726. struct bfa_rport_speed_req_s *m;
  3727. /*
  3728. * check for room in queue to send request now
  3729. */
  3730. m = bfa_reqq_next(rp->bfa, BFA_REQQ_RPORT);
  3731. if (!m) {
  3732. bfa_trc(rp->bfa, rp->rport_info.speed);
  3733. return BFA_FALSE;
  3734. }
  3735. bfi_h2i_set(m->mh, BFI_MC_RPORT, BFI_RPORT_H2I_SET_SPEED_REQ,
  3736. bfa_lpuid(rp->bfa));
  3737. m->fw_handle = rp->fw_handle;
  3738. m->speed = (u8)rp->rport_info.speed;
  3739. /*
  3740. * queue I/O message to firmware
  3741. */
  3742. bfa_reqq_produce(rp->bfa, BFA_REQQ_RPORT);
  3743. return BFA_TRUE;
  3744. }
  3745. /*
  3746. * bfa_rport_public
  3747. */
  3748. /*
  3749. * Rport interrupt processing.
  3750. */
  3751. void
  3752. bfa_rport_isr(struct bfa_s *bfa, struct bfi_msg_s *m)
  3753. {
  3754. union bfi_rport_i2h_msg_u msg;
  3755. struct bfa_rport_s *rp;
  3756. bfa_trc(bfa, m->mhdr.msg_id);
  3757. msg.msg = m;
  3758. switch (m->mhdr.msg_id) {
  3759. case BFI_RPORT_I2H_CREATE_RSP:
  3760. rp = BFA_RPORT_FROM_TAG(bfa, msg.create_rsp->bfa_handle);
  3761. rp->fw_handle = msg.create_rsp->fw_handle;
  3762. rp->qos_attr = msg.create_rsp->qos_attr;
  3763. WARN_ON(msg.create_rsp->status != BFA_STATUS_OK);
  3764. bfa_sm_send_event(rp, BFA_RPORT_SM_FWRSP);
  3765. break;
  3766. case BFI_RPORT_I2H_DELETE_RSP:
  3767. rp = BFA_RPORT_FROM_TAG(bfa, msg.delete_rsp->bfa_handle);
  3768. WARN_ON(msg.delete_rsp->status != BFA_STATUS_OK);
  3769. bfa_sm_send_event(rp, BFA_RPORT_SM_FWRSP);
  3770. break;
  3771. case BFI_RPORT_I2H_QOS_SCN:
  3772. rp = BFA_RPORT_FROM_TAG(bfa, msg.qos_scn_evt->bfa_handle);
  3773. rp->event_arg.fw_msg = msg.qos_scn_evt;
  3774. bfa_sm_send_event(rp, BFA_RPORT_SM_QOS_SCN);
  3775. break;
  3776. default:
  3777. bfa_trc(bfa, m->mhdr.msg_id);
  3778. WARN_ON(1);
  3779. }
  3780. }
  3781. /*
  3782. * bfa_rport_api
  3783. */
  3784. struct bfa_rport_s *
  3785. bfa_rport_create(struct bfa_s *bfa, void *rport_drv)
  3786. {
  3787. struct bfa_rport_s *rp;
  3788. rp = bfa_rport_alloc(BFA_RPORT_MOD(bfa));
  3789. if (rp == NULL)
  3790. return NULL;
  3791. rp->bfa = bfa;
  3792. rp->rport_drv = rport_drv;
  3793. memset(&rp->stats, 0, sizeof(rp->stats));
  3794. WARN_ON(!bfa_sm_cmp_state(rp, bfa_rport_sm_uninit));
  3795. bfa_sm_send_event(rp, BFA_RPORT_SM_CREATE);
  3796. return rp;
  3797. }
  3798. void
  3799. bfa_rport_online(struct bfa_rport_s *rport, struct bfa_rport_info_s *rport_info)
  3800. {
  3801. WARN_ON(rport_info->max_frmsz == 0);
  3802. /*
  3803. * Some JBODs are seen to be not setting PDU size correctly in PLOGI
  3804. * responses. Default to minimum size.
  3805. */
  3806. if (rport_info->max_frmsz == 0) {
  3807. bfa_trc(rport->bfa, rport->rport_tag);
  3808. rport_info->max_frmsz = FC_MIN_PDUSZ;
  3809. }
  3810. rport->rport_info = *rport_info;
  3811. bfa_sm_send_event(rport, BFA_RPORT_SM_ONLINE);
  3812. }
  3813. void
  3814. bfa_rport_speed(struct bfa_rport_s *rport, enum bfa_port_speed speed)
  3815. {
  3816. WARN_ON(speed == 0);
  3817. WARN_ON(speed == BFA_PORT_SPEED_AUTO);
  3818. rport->rport_info.speed = speed;
  3819. bfa_sm_send_event(rport, BFA_RPORT_SM_SET_SPEED);
  3820. }
  3821. /*
  3822. * SGPG related functions
  3823. */
  3824. /*
  3825. * Compute and return memory needed by FCP(im) module.
  3826. */
  3827. static void
  3828. bfa_sgpg_meminfo(struct bfa_iocfc_cfg_s *cfg, u32 *km_len,
  3829. u32 *dm_len)
  3830. {
  3831. if (cfg->drvcfg.num_sgpgs < BFA_SGPG_MIN)
  3832. cfg->drvcfg.num_sgpgs = BFA_SGPG_MIN;
  3833. *km_len += (cfg->drvcfg.num_sgpgs + 1) * sizeof(struct bfa_sgpg_s);
  3834. *dm_len += (cfg->drvcfg.num_sgpgs + 1) * sizeof(struct bfi_sgpg_s);
  3835. }
  3836. static void
  3837. bfa_sgpg_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
  3838. struct bfa_meminfo_s *minfo, struct bfa_pcidev_s *pcidev)
  3839. {
  3840. struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa);
  3841. int i;
  3842. struct bfa_sgpg_s *hsgpg;
  3843. struct bfi_sgpg_s *sgpg;
  3844. u64 align_len;
  3845. union {
  3846. u64 pa;
  3847. union bfi_addr_u addr;
  3848. } sgpg_pa, sgpg_pa_tmp;
  3849. INIT_LIST_HEAD(&mod->sgpg_q);
  3850. INIT_LIST_HEAD(&mod->sgpg_wait_q);
  3851. bfa_trc(bfa, cfg->drvcfg.num_sgpgs);
  3852. mod->num_sgpgs = cfg->drvcfg.num_sgpgs;
  3853. mod->sgpg_arr_pa = bfa_meminfo_dma_phys(minfo);
  3854. align_len = (BFA_SGPG_ROUNDUP(mod->sgpg_arr_pa) - mod->sgpg_arr_pa);
  3855. mod->sgpg_arr_pa += align_len;
  3856. mod->hsgpg_arr = (struct bfa_sgpg_s *) (bfa_meminfo_kva(minfo) +
  3857. align_len);
  3858. mod->sgpg_arr = (struct bfi_sgpg_s *) (bfa_meminfo_dma_virt(minfo) +
  3859. align_len);
  3860. hsgpg = mod->hsgpg_arr;
  3861. sgpg = mod->sgpg_arr;
  3862. sgpg_pa.pa = mod->sgpg_arr_pa;
  3863. mod->free_sgpgs = mod->num_sgpgs;
  3864. WARN_ON(sgpg_pa.pa & (sizeof(struct bfi_sgpg_s) - 1));
  3865. for (i = 0; i < mod->num_sgpgs; i++) {
  3866. memset(hsgpg, 0, sizeof(*hsgpg));
  3867. memset(sgpg, 0, sizeof(*sgpg));
  3868. hsgpg->sgpg = sgpg;
  3869. sgpg_pa_tmp.pa = bfa_sgaddr_le(sgpg_pa.pa);
  3870. hsgpg->sgpg_pa = sgpg_pa_tmp.addr;
  3871. list_add_tail(&hsgpg->qe, &mod->sgpg_q);
  3872. hsgpg++;
  3873. sgpg++;
  3874. sgpg_pa.pa += sizeof(struct bfi_sgpg_s);
  3875. }
  3876. bfa_meminfo_kva(minfo) = (u8 *) hsgpg;
  3877. bfa_meminfo_dma_virt(minfo) = (u8 *) sgpg;
  3878. bfa_meminfo_dma_phys(minfo) = sgpg_pa.pa;
  3879. }
  3880. static void
  3881. bfa_sgpg_detach(struct bfa_s *bfa)
  3882. {
  3883. }
  3884. static void
  3885. bfa_sgpg_start(struct bfa_s *bfa)
  3886. {
  3887. }
  3888. static void
  3889. bfa_sgpg_stop(struct bfa_s *bfa)
  3890. {
  3891. }
  3892. static void
  3893. bfa_sgpg_iocdisable(struct bfa_s *bfa)
  3894. {
  3895. }
  3896. bfa_status_t
  3897. bfa_sgpg_malloc(struct bfa_s *bfa, struct list_head *sgpg_q, int nsgpgs)
  3898. {
  3899. struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa);
  3900. struct bfa_sgpg_s *hsgpg;
  3901. int i;
  3902. if (mod->free_sgpgs < nsgpgs)
  3903. return BFA_STATUS_ENOMEM;
  3904. for (i = 0; i < nsgpgs; i++) {
  3905. bfa_q_deq(&mod->sgpg_q, &hsgpg);
  3906. WARN_ON(!hsgpg);
  3907. list_add_tail(&hsgpg->qe, sgpg_q);
  3908. }
  3909. mod->free_sgpgs -= nsgpgs;
  3910. return BFA_STATUS_OK;
  3911. }
  3912. void
  3913. bfa_sgpg_mfree(struct bfa_s *bfa, struct list_head *sgpg_q, int nsgpg)
  3914. {
  3915. struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa);
  3916. struct bfa_sgpg_wqe_s *wqe;
  3917. mod->free_sgpgs += nsgpg;
  3918. WARN_ON(mod->free_sgpgs > mod->num_sgpgs);
  3919. list_splice_tail_init(sgpg_q, &mod->sgpg_q);
  3920. if (list_empty(&mod->sgpg_wait_q))
  3921. return;
  3922. /*
  3923. * satisfy as many waiting requests as possible
  3924. */
  3925. do {
  3926. wqe = bfa_q_first(&mod->sgpg_wait_q);
  3927. if (mod->free_sgpgs < wqe->nsgpg)
  3928. nsgpg = mod->free_sgpgs;
  3929. else
  3930. nsgpg = wqe->nsgpg;
  3931. bfa_sgpg_malloc(bfa, &wqe->sgpg_q, nsgpg);
  3932. wqe->nsgpg -= nsgpg;
  3933. if (wqe->nsgpg == 0) {
  3934. list_del(&wqe->qe);
  3935. wqe->cbfn(wqe->cbarg);
  3936. }
  3937. } while (mod->free_sgpgs && !list_empty(&mod->sgpg_wait_q));
  3938. }
  3939. void
  3940. bfa_sgpg_wait(struct bfa_s *bfa, struct bfa_sgpg_wqe_s *wqe, int nsgpg)
  3941. {
  3942. struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa);
  3943. WARN_ON(nsgpg <= 0);
  3944. WARN_ON(nsgpg <= mod->free_sgpgs);
  3945. wqe->nsgpg_total = wqe->nsgpg = nsgpg;
  3946. /*
  3947. * allocate any left to this one first
  3948. */
  3949. if (mod->free_sgpgs) {
  3950. /*
  3951. * no one else is waiting for SGPG
  3952. */
  3953. WARN_ON(!list_empty(&mod->sgpg_wait_q));
  3954. list_splice_tail_init(&mod->sgpg_q, &wqe->sgpg_q);
  3955. wqe->nsgpg -= mod->free_sgpgs;
  3956. mod->free_sgpgs = 0;
  3957. }
  3958. list_add_tail(&wqe->qe, &mod->sgpg_wait_q);
  3959. }
  3960. void
  3961. bfa_sgpg_wcancel(struct bfa_s *bfa, struct bfa_sgpg_wqe_s *wqe)
  3962. {
  3963. struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa);
  3964. WARN_ON(!bfa_q_is_on_q(&mod->sgpg_wait_q, wqe));
  3965. list_del(&wqe->qe);
  3966. if (wqe->nsgpg_total != wqe->nsgpg)
  3967. bfa_sgpg_mfree(bfa, &wqe->sgpg_q,
  3968. wqe->nsgpg_total - wqe->nsgpg);
  3969. }
  3970. void
  3971. bfa_sgpg_winit(struct bfa_sgpg_wqe_s *wqe, void (*cbfn) (void *cbarg),
  3972. void *cbarg)
  3973. {
  3974. INIT_LIST_HEAD(&wqe->sgpg_q);
  3975. wqe->cbfn = cbfn;
  3976. wqe->cbarg = cbarg;
  3977. }
  3978. /*
  3979. * UF related functions
  3980. */
  3981. /*
  3982. *****************************************************************************
  3983. * Internal functions
  3984. *****************************************************************************
  3985. */
  3986. static void
  3987. __bfa_cb_uf_recv(void *cbarg, bfa_boolean_t complete)
  3988. {
  3989. struct bfa_uf_s *uf = cbarg;
  3990. struct bfa_uf_mod_s *ufm = BFA_UF_MOD(uf->bfa);
  3991. if (complete)
  3992. ufm->ufrecv(ufm->cbarg, uf);
  3993. }
  3994. static void
  3995. claim_uf_pbs(struct bfa_uf_mod_s *ufm, struct bfa_meminfo_s *mi)
  3996. {
  3997. u32 uf_pb_tot_sz;
  3998. ufm->uf_pbs_kva = (struct bfa_uf_buf_s *) bfa_meminfo_dma_virt(mi);
  3999. ufm->uf_pbs_pa = bfa_meminfo_dma_phys(mi);
  4000. uf_pb_tot_sz = BFA_ROUNDUP((sizeof(struct bfa_uf_buf_s) * ufm->num_ufs),
  4001. BFA_DMA_ALIGN_SZ);
  4002. bfa_meminfo_dma_virt(mi) += uf_pb_tot_sz;
  4003. bfa_meminfo_dma_phys(mi) += uf_pb_tot_sz;
  4004. memset((void *)ufm->uf_pbs_kva, 0, uf_pb_tot_sz);
  4005. }
  4006. static void
  4007. claim_uf_post_msgs(struct bfa_uf_mod_s *ufm, struct bfa_meminfo_s *mi)
  4008. {
  4009. struct bfi_uf_buf_post_s *uf_bp_msg;
  4010. struct bfi_sge_s *sge;
  4011. union bfi_addr_u sga_zero = { {0} };
  4012. u16 i;
  4013. u16 buf_len;
  4014. ufm->uf_buf_posts = (struct bfi_uf_buf_post_s *) bfa_meminfo_kva(mi);
  4015. uf_bp_msg = ufm->uf_buf_posts;
  4016. for (i = 0, uf_bp_msg = ufm->uf_buf_posts; i < ufm->num_ufs;
  4017. i++, uf_bp_msg++) {
  4018. memset(uf_bp_msg, 0, sizeof(struct bfi_uf_buf_post_s));
  4019. uf_bp_msg->buf_tag = i;
  4020. buf_len = sizeof(struct bfa_uf_buf_s);
  4021. uf_bp_msg->buf_len = cpu_to_be16(buf_len);
  4022. bfi_h2i_set(uf_bp_msg->mh, BFI_MC_UF, BFI_UF_H2I_BUF_POST,
  4023. bfa_lpuid(ufm->bfa));
  4024. sge = uf_bp_msg->sge;
  4025. sge[0].sg_len = buf_len;
  4026. sge[0].flags = BFI_SGE_DATA_LAST;
  4027. bfa_dma_addr_set(sge[0].sga, ufm_pbs_pa(ufm, i));
  4028. bfa_sge_to_be(sge);
  4029. sge[1].sg_len = buf_len;
  4030. sge[1].flags = BFI_SGE_PGDLEN;
  4031. sge[1].sga = sga_zero;
  4032. bfa_sge_to_be(&sge[1]);
  4033. }
  4034. /*
  4035. * advance pointer beyond consumed memory
  4036. */
  4037. bfa_meminfo_kva(mi) = (u8 *) uf_bp_msg;
  4038. }
  4039. static void
  4040. claim_ufs(struct bfa_uf_mod_s *ufm, struct bfa_meminfo_s *mi)
  4041. {
  4042. u16 i;
  4043. struct bfa_uf_s *uf;
  4044. /*
  4045. * Claim block of memory for UF list
  4046. */
  4047. ufm->uf_list = (struct bfa_uf_s *) bfa_meminfo_kva(mi);
  4048. /*
  4049. * Initialize UFs and queue it in UF free queue
  4050. */
  4051. for (i = 0, uf = ufm->uf_list; i < ufm->num_ufs; i++, uf++) {
  4052. memset(uf, 0, sizeof(struct bfa_uf_s));
  4053. uf->bfa = ufm->bfa;
  4054. uf->uf_tag = i;
  4055. uf->pb_len = sizeof(struct bfa_uf_buf_s);
  4056. uf->buf_kva = (void *)&ufm->uf_pbs_kva[i];
  4057. uf->buf_pa = ufm_pbs_pa(ufm, i);
  4058. list_add_tail(&uf->qe, &ufm->uf_free_q);
  4059. }
  4060. /*
  4061. * advance memory pointer
  4062. */
  4063. bfa_meminfo_kva(mi) = (u8 *) uf;
  4064. }
  4065. static void
  4066. uf_mem_claim(struct bfa_uf_mod_s *ufm, struct bfa_meminfo_s *mi)
  4067. {
  4068. claim_uf_pbs(ufm, mi);
  4069. claim_ufs(ufm, mi);
  4070. claim_uf_post_msgs(ufm, mi);
  4071. }
  4072. static void
  4073. bfa_uf_meminfo(struct bfa_iocfc_cfg_s *cfg, u32 *ndm_len, u32 *dm_len)
  4074. {
  4075. u32 num_ufs = cfg->fwcfg.num_uf_bufs;
  4076. /*
  4077. * dma-able memory for UF posted bufs
  4078. */
  4079. *dm_len += BFA_ROUNDUP((sizeof(struct bfa_uf_buf_s) * num_ufs),
  4080. BFA_DMA_ALIGN_SZ);
  4081. /*
  4082. * kernel Virtual memory for UFs and UF buf post msg copies
  4083. */
  4084. *ndm_len += sizeof(struct bfa_uf_s) * num_ufs;
  4085. *ndm_len += sizeof(struct bfi_uf_buf_post_s) * num_ufs;
  4086. }
  4087. static void
  4088. bfa_uf_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
  4089. struct bfa_meminfo_s *meminfo, struct bfa_pcidev_s *pcidev)
  4090. {
  4091. struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa);
  4092. memset(ufm, 0, sizeof(struct bfa_uf_mod_s));
  4093. ufm->bfa = bfa;
  4094. ufm->num_ufs = cfg->fwcfg.num_uf_bufs;
  4095. INIT_LIST_HEAD(&ufm->uf_free_q);
  4096. INIT_LIST_HEAD(&ufm->uf_posted_q);
  4097. uf_mem_claim(ufm, meminfo);
  4098. }
  4099. static void
  4100. bfa_uf_detach(struct bfa_s *bfa)
  4101. {
  4102. }
  4103. static struct bfa_uf_s *
  4104. bfa_uf_get(struct bfa_uf_mod_s *uf_mod)
  4105. {
  4106. struct bfa_uf_s *uf;
  4107. bfa_q_deq(&uf_mod->uf_free_q, &uf);
  4108. return uf;
  4109. }
  4110. static void
  4111. bfa_uf_put(struct bfa_uf_mod_s *uf_mod, struct bfa_uf_s *uf)
  4112. {
  4113. list_add_tail(&uf->qe, &uf_mod->uf_free_q);
  4114. }
  4115. static bfa_status_t
  4116. bfa_uf_post(struct bfa_uf_mod_s *ufm, struct bfa_uf_s *uf)
  4117. {
  4118. struct bfi_uf_buf_post_s *uf_post_msg;
  4119. uf_post_msg = bfa_reqq_next(ufm->bfa, BFA_REQQ_FCXP);
  4120. if (!uf_post_msg)
  4121. return BFA_STATUS_FAILED;
  4122. memcpy(uf_post_msg, &ufm->uf_buf_posts[uf->uf_tag],
  4123. sizeof(struct bfi_uf_buf_post_s));
  4124. bfa_reqq_produce(ufm->bfa, BFA_REQQ_FCXP);
  4125. bfa_trc(ufm->bfa, uf->uf_tag);
  4126. list_add_tail(&uf->qe, &ufm->uf_posted_q);
  4127. return BFA_STATUS_OK;
  4128. }
  4129. static void
  4130. bfa_uf_post_all(struct bfa_uf_mod_s *uf_mod)
  4131. {
  4132. struct bfa_uf_s *uf;
  4133. while ((uf = bfa_uf_get(uf_mod)) != NULL) {
  4134. if (bfa_uf_post(uf_mod, uf) != BFA_STATUS_OK)
  4135. break;
  4136. }
  4137. }
  4138. static void
  4139. uf_recv(struct bfa_s *bfa, struct bfi_uf_frm_rcvd_s *m)
  4140. {
  4141. struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa);
  4142. u16 uf_tag = m->buf_tag;
  4143. struct bfa_uf_buf_s *uf_buf = &ufm->uf_pbs_kva[uf_tag];
  4144. struct bfa_uf_s *uf = &ufm->uf_list[uf_tag];
  4145. u8 *buf = &uf_buf->d[0];
  4146. struct fchs_s *fchs;
  4147. m->frm_len = be16_to_cpu(m->frm_len);
  4148. m->xfr_len = be16_to_cpu(m->xfr_len);
  4149. fchs = (struct fchs_s *)uf_buf;
  4150. list_del(&uf->qe); /* dequeue from posted queue */
  4151. uf->data_ptr = buf;
  4152. uf->data_len = m->xfr_len;
  4153. WARN_ON(uf->data_len < sizeof(struct fchs_s));
  4154. if (uf->data_len == sizeof(struct fchs_s)) {
  4155. bfa_plog_fchdr(bfa->plog, BFA_PL_MID_HAL_UF, BFA_PL_EID_RX,
  4156. uf->data_len, (struct fchs_s *)buf);
  4157. } else {
  4158. u32 pld_w0 = *((u32 *) (buf + sizeof(struct fchs_s)));
  4159. bfa_plog_fchdr_and_pl(bfa->plog, BFA_PL_MID_HAL_UF,
  4160. BFA_PL_EID_RX, uf->data_len,
  4161. (struct fchs_s *)buf, pld_w0);
  4162. }
  4163. if (bfa->fcs)
  4164. __bfa_cb_uf_recv(uf, BFA_TRUE);
  4165. else
  4166. bfa_cb_queue(bfa, &uf->hcb_qe, __bfa_cb_uf_recv, uf);
  4167. }
  4168. static void
  4169. bfa_uf_stop(struct bfa_s *bfa)
  4170. {
  4171. }
  4172. static void
  4173. bfa_uf_iocdisable(struct bfa_s *bfa)
  4174. {
  4175. struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa);
  4176. struct bfa_uf_s *uf;
  4177. struct list_head *qe, *qen;
  4178. list_for_each_safe(qe, qen, &ufm->uf_posted_q) {
  4179. uf = (struct bfa_uf_s *) qe;
  4180. list_del(&uf->qe);
  4181. bfa_uf_put(ufm, uf);
  4182. }
  4183. }
  4184. static void
  4185. bfa_uf_start(struct bfa_s *bfa)
  4186. {
  4187. bfa_uf_post_all(BFA_UF_MOD(bfa));
  4188. }
  4189. /*
  4190. * Register handler for all unsolicted recieve frames.
  4191. *
  4192. * @param[in] bfa BFA instance
  4193. * @param[in] ufrecv receive handler function
  4194. * @param[in] cbarg receive handler arg
  4195. */
  4196. void
  4197. bfa_uf_recv_register(struct bfa_s *bfa, bfa_cb_uf_recv_t ufrecv, void *cbarg)
  4198. {
  4199. struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa);
  4200. ufm->ufrecv = ufrecv;
  4201. ufm->cbarg = cbarg;
  4202. }
  4203. /*
  4204. * Free an unsolicited frame back to BFA.
  4205. *
  4206. * @param[in] uf unsolicited frame to be freed
  4207. *
  4208. * @return None
  4209. */
  4210. void
  4211. bfa_uf_free(struct bfa_uf_s *uf)
  4212. {
  4213. bfa_uf_put(BFA_UF_MOD(uf->bfa), uf);
  4214. bfa_uf_post_all(BFA_UF_MOD(uf->bfa));
  4215. }
  4216. /*
  4217. * uf_pub BFA uf module public functions
  4218. */
  4219. void
  4220. bfa_uf_isr(struct bfa_s *bfa, struct bfi_msg_s *msg)
  4221. {
  4222. bfa_trc(bfa, msg->mhdr.msg_id);
  4223. switch (msg->mhdr.msg_id) {
  4224. case BFI_UF_I2H_FRM_RCVD:
  4225. uf_recv(bfa, (struct bfi_uf_frm_rcvd_s *) msg);
  4226. break;
  4227. default:
  4228. bfa_trc(bfa, msg->mhdr.msg_id);
  4229. WARN_ON(1);
  4230. }
  4231. }