bfa_svc.c 135 KB

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