bfa_svc.c 135 KB

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