bfa_svc.c 132 KB

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