bnx2x_main.c 402 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854
  1. /* bnx2x_main.c: Broadcom Everest network driver.
  2. *
  3. * Copyright (c) 2007-2013 Broadcom Corporation
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation.
  8. *
  9. * Maintained by: Ariel Elior <ariel.elior@qlogic.com>
  10. * Written by: Eliezer Tamir
  11. * Based on code from Michael Chan's bnx2 driver
  12. * UDP CSUM errata workaround by Arik Gendelman
  13. * Slowpath and fastpath rework by Vladislav Zolotarov
  14. * Statistics and Link management by Yitchak Gertner
  15. *
  16. */
  17. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  18. #include <linux/module.h>
  19. #include <linux/moduleparam.h>
  20. #include <linux/kernel.h>
  21. #include <linux/device.h> /* for dev_info() */
  22. #include <linux/timer.h>
  23. #include <linux/errno.h>
  24. #include <linux/ioport.h>
  25. #include <linux/slab.h>
  26. #include <linux/interrupt.h>
  27. #include <linux/pci.h>
  28. #include <linux/aer.h>
  29. #include <linux/init.h>
  30. #include <linux/netdevice.h>
  31. #include <linux/etherdevice.h>
  32. #include <linux/skbuff.h>
  33. #include <linux/dma-mapping.h>
  34. #include <linux/bitops.h>
  35. #include <linux/irq.h>
  36. #include <linux/delay.h>
  37. #include <asm/byteorder.h>
  38. #include <linux/time.h>
  39. #include <linux/ethtool.h>
  40. #include <linux/mii.h>
  41. #include <linux/if_vlan.h>
  42. #include <linux/crash_dump.h>
  43. #include <net/ip.h>
  44. #include <net/ipv6.h>
  45. #include <net/tcp.h>
  46. #include <net/checksum.h>
  47. #include <net/ip6_checksum.h>
  48. #include <linux/workqueue.h>
  49. #include <linux/crc32.h>
  50. #include <linux/crc32c.h>
  51. #include <linux/prefetch.h>
  52. #include <linux/zlib.h>
  53. #include <linux/io.h>
  54. #include <linux/semaphore.h>
  55. #include <linux/stringify.h>
  56. #include <linux/vmalloc.h>
  57. #include "bnx2x.h"
  58. #include "bnx2x_init.h"
  59. #include "bnx2x_init_ops.h"
  60. #include "bnx2x_cmn.h"
  61. #include "bnx2x_vfpf.h"
  62. #include "bnx2x_dcb.h"
  63. #include "bnx2x_sp.h"
  64. #include <linux/firmware.h>
  65. #include "bnx2x_fw_file_hdr.h"
  66. /* FW files */
  67. #define FW_FILE_VERSION \
  68. __stringify(BCM_5710_FW_MAJOR_VERSION) "." \
  69. __stringify(BCM_5710_FW_MINOR_VERSION) "." \
  70. __stringify(BCM_5710_FW_REVISION_VERSION) "." \
  71. __stringify(BCM_5710_FW_ENGINEERING_VERSION)
  72. #define FW_FILE_NAME_E1 "bnx2x/bnx2x-e1-" FW_FILE_VERSION ".fw"
  73. #define FW_FILE_NAME_E1H "bnx2x/bnx2x-e1h-" FW_FILE_VERSION ".fw"
  74. #define FW_FILE_NAME_E2 "bnx2x/bnx2x-e2-" FW_FILE_VERSION ".fw"
  75. /* Time in jiffies before concluding the transmitter is hung */
  76. #define TX_TIMEOUT (5*HZ)
  77. static char version[] =
  78. "Broadcom NetXtreme II 5771x/578xx 10/20-Gigabit Ethernet Driver "
  79. DRV_MODULE_NAME " " DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
  80. MODULE_AUTHOR("Eliezer Tamir");
  81. MODULE_DESCRIPTION("Broadcom NetXtreme II "
  82. "BCM57710/57711/57711E/"
  83. "57712/57712_MF/57800/57800_MF/57810/57810_MF/"
  84. "57840/57840_MF Driver");
  85. MODULE_LICENSE("GPL");
  86. MODULE_VERSION(DRV_MODULE_VERSION);
  87. MODULE_FIRMWARE(FW_FILE_NAME_E1);
  88. MODULE_FIRMWARE(FW_FILE_NAME_E1H);
  89. MODULE_FIRMWARE(FW_FILE_NAME_E2);
  90. int bnx2x_num_queues;
  91. module_param_named(num_queues, bnx2x_num_queues, int, S_IRUGO);
  92. MODULE_PARM_DESC(num_queues,
  93. " Set number of queues (default is as a number of CPUs)");
  94. static int disable_tpa;
  95. module_param(disable_tpa, int, S_IRUGO);
  96. MODULE_PARM_DESC(disable_tpa, " Disable the TPA (LRO) feature");
  97. static int int_mode;
  98. module_param(int_mode, int, S_IRUGO);
  99. MODULE_PARM_DESC(int_mode, " Force interrupt mode other than MSI-X "
  100. "(1 INT#x; 2 MSI)");
  101. static int dropless_fc;
  102. module_param(dropless_fc, int, S_IRUGO);
  103. MODULE_PARM_DESC(dropless_fc, " Pause on exhausted host ring");
  104. static int mrrs = -1;
  105. module_param(mrrs, int, S_IRUGO);
  106. MODULE_PARM_DESC(mrrs, " Force Max Read Req Size (0..3) (for debug)");
  107. static int debug;
  108. module_param(debug, int, S_IRUGO);
  109. MODULE_PARM_DESC(debug, " Default debug msglevel");
  110. static struct workqueue_struct *bnx2x_wq;
  111. struct workqueue_struct *bnx2x_iov_wq;
  112. struct bnx2x_mac_vals {
  113. u32 xmac_addr;
  114. u32 xmac_val;
  115. u32 emac_addr;
  116. u32 emac_val;
  117. u32 umac_addr;
  118. u32 umac_val;
  119. u32 bmac_addr;
  120. u32 bmac_val[2];
  121. };
  122. enum bnx2x_board_type {
  123. BCM57710 = 0,
  124. BCM57711,
  125. BCM57711E,
  126. BCM57712,
  127. BCM57712_MF,
  128. BCM57712_VF,
  129. BCM57800,
  130. BCM57800_MF,
  131. BCM57800_VF,
  132. BCM57810,
  133. BCM57810_MF,
  134. BCM57810_VF,
  135. BCM57840_4_10,
  136. BCM57840_2_20,
  137. BCM57840_MF,
  138. BCM57840_VF,
  139. BCM57811,
  140. BCM57811_MF,
  141. BCM57840_O,
  142. BCM57840_MFO,
  143. BCM57811_VF
  144. };
  145. /* indexed by board_type, above */
  146. static struct {
  147. char *name;
  148. } board_info[] = {
  149. [BCM57710] = { "Broadcom NetXtreme II BCM57710 10 Gigabit PCIe [Everest]" },
  150. [BCM57711] = { "Broadcom NetXtreme II BCM57711 10 Gigabit PCIe" },
  151. [BCM57711E] = { "Broadcom NetXtreme II BCM57711E 10 Gigabit PCIe" },
  152. [BCM57712] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet" },
  153. [BCM57712_MF] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Multi Function" },
  154. [BCM57712_VF] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Virtual Function" },
  155. [BCM57800] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet" },
  156. [BCM57800_MF] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Multi Function" },
  157. [BCM57800_VF] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Virtual Function" },
  158. [BCM57810] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet" },
  159. [BCM57810_MF] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Multi Function" },
  160. [BCM57810_VF] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Virtual Function" },
  161. [BCM57840_4_10] = { "Broadcom NetXtreme II BCM57840 10 Gigabit Ethernet" },
  162. [BCM57840_2_20] = { "Broadcom NetXtreme II BCM57840 20 Gigabit Ethernet" },
  163. [BCM57840_MF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function" },
  164. [BCM57840_VF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Virtual Function" },
  165. [BCM57811] = { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet" },
  166. [BCM57811_MF] = { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet Multi Function" },
  167. [BCM57840_O] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet" },
  168. [BCM57840_MFO] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function" },
  169. [BCM57811_VF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Virtual Function" }
  170. };
  171. #ifndef PCI_DEVICE_ID_NX2_57710
  172. #define PCI_DEVICE_ID_NX2_57710 CHIP_NUM_57710
  173. #endif
  174. #ifndef PCI_DEVICE_ID_NX2_57711
  175. #define PCI_DEVICE_ID_NX2_57711 CHIP_NUM_57711
  176. #endif
  177. #ifndef PCI_DEVICE_ID_NX2_57711E
  178. #define PCI_DEVICE_ID_NX2_57711E CHIP_NUM_57711E
  179. #endif
  180. #ifndef PCI_DEVICE_ID_NX2_57712
  181. #define PCI_DEVICE_ID_NX2_57712 CHIP_NUM_57712
  182. #endif
  183. #ifndef PCI_DEVICE_ID_NX2_57712_MF
  184. #define PCI_DEVICE_ID_NX2_57712_MF CHIP_NUM_57712_MF
  185. #endif
  186. #ifndef PCI_DEVICE_ID_NX2_57712_VF
  187. #define PCI_DEVICE_ID_NX2_57712_VF CHIP_NUM_57712_VF
  188. #endif
  189. #ifndef PCI_DEVICE_ID_NX2_57800
  190. #define PCI_DEVICE_ID_NX2_57800 CHIP_NUM_57800
  191. #endif
  192. #ifndef PCI_DEVICE_ID_NX2_57800_MF
  193. #define PCI_DEVICE_ID_NX2_57800_MF CHIP_NUM_57800_MF
  194. #endif
  195. #ifndef PCI_DEVICE_ID_NX2_57800_VF
  196. #define PCI_DEVICE_ID_NX2_57800_VF CHIP_NUM_57800_VF
  197. #endif
  198. #ifndef PCI_DEVICE_ID_NX2_57810
  199. #define PCI_DEVICE_ID_NX2_57810 CHIP_NUM_57810
  200. #endif
  201. #ifndef PCI_DEVICE_ID_NX2_57810_MF
  202. #define PCI_DEVICE_ID_NX2_57810_MF CHIP_NUM_57810_MF
  203. #endif
  204. #ifndef PCI_DEVICE_ID_NX2_57840_O
  205. #define PCI_DEVICE_ID_NX2_57840_O CHIP_NUM_57840_OBSOLETE
  206. #endif
  207. #ifndef PCI_DEVICE_ID_NX2_57810_VF
  208. #define PCI_DEVICE_ID_NX2_57810_VF CHIP_NUM_57810_VF
  209. #endif
  210. #ifndef PCI_DEVICE_ID_NX2_57840_4_10
  211. #define PCI_DEVICE_ID_NX2_57840_4_10 CHIP_NUM_57840_4_10
  212. #endif
  213. #ifndef PCI_DEVICE_ID_NX2_57840_2_20
  214. #define PCI_DEVICE_ID_NX2_57840_2_20 CHIP_NUM_57840_2_20
  215. #endif
  216. #ifndef PCI_DEVICE_ID_NX2_57840_MFO
  217. #define PCI_DEVICE_ID_NX2_57840_MFO CHIP_NUM_57840_MF_OBSOLETE
  218. #endif
  219. #ifndef PCI_DEVICE_ID_NX2_57840_MF
  220. #define PCI_DEVICE_ID_NX2_57840_MF CHIP_NUM_57840_MF
  221. #endif
  222. #ifndef PCI_DEVICE_ID_NX2_57840_VF
  223. #define PCI_DEVICE_ID_NX2_57840_VF CHIP_NUM_57840_VF
  224. #endif
  225. #ifndef PCI_DEVICE_ID_NX2_57811
  226. #define PCI_DEVICE_ID_NX2_57811 CHIP_NUM_57811
  227. #endif
  228. #ifndef PCI_DEVICE_ID_NX2_57811_MF
  229. #define PCI_DEVICE_ID_NX2_57811_MF CHIP_NUM_57811_MF
  230. #endif
  231. #ifndef PCI_DEVICE_ID_NX2_57811_VF
  232. #define PCI_DEVICE_ID_NX2_57811_VF CHIP_NUM_57811_VF
  233. #endif
  234. static const struct pci_device_id bnx2x_pci_tbl[] = {
  235. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57710), BCM57710 },
  236. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711), BCM57711 },
  237. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711E), BCM57711E },
  238. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712), BCM57712 },
  239. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_MF), BCM57712_MF },
  240. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_VF), BCM57712_VF },
  241. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800), BCM57800 },
  242. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_MF), BCM57800_MF },
  243. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_VF), BCM57800_VF },
  244. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810), BCM57810 },
  245. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_MF), BCM57810_MF },
  246. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_O), BCM57840_O },
  247. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_4_10), BCM57840_4_10 },
  248. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_2_20), BCM57840_2_20 },
  249. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_VF), BCM57810_VF },
  250. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MFO), BCM57840_MFO },
  251. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MF), BCM57840_MF },
  252. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_VF), BCM57840_VF },
  253. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811), BCM57811 },
  254. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_MF), BCM57811_MF },
  255. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_VF), BCM57811_VF },
  256. { 0 }
  257. };
  258. MODULE_DEVICE_TABLE(pci, bnx2x_pci_tbl);
  259. /* Global resources for unloading a previously loaded device */
  260. #define BNX2X_PREV_WAIT_NEEDED 1
  261. static DEFINE_SEMAPHORE(bnx2x_prev_sem);
  262. static LIST_HEAD(bnx2x_prev_list);
  263. /* Forward declaration */
  264. static struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev);
  265. static u32 bnx2x_rx_ustorm_prods_offset(struct bnx2x_fastpath *fp);
  266. static int bnx2x_set_storm_rx_mode(struct bnx2x *bp);
  267. /****************************************************************************
  268. * General service functions
  269. ****************************************************************************/
  270. static int bnx2x_hwtstamp_ioctl(struct bnx2x *bp, struct ifreq *ifr);
  271. static void __storm_memset_dma_mapping(struct bnx2x *bp,
  272. u32 addr, dma_addr_t mapping)
  273. {
  274. REG_WR(bp, addr, U64_LO(mapping));
  275. REG_WR(bp, addr + 4, U64_HI(mapping));
  276. }
  277. static void storm_memset_spq_addr(struct bnx2x *bp,
  278. dma_addr_t mapping, u16 abs_fid)
  279. {
  280. u32 addr = XSEM_REG_FAST_MEMORY +
  281. XSTORM_SPQ_PAGE_BASE_OFFSET(abs_fid);
  282. __storm_memset_dma_mapping(bp, addr, mapping);
  283. }
  284. static void storm_memset_vf_to_pf(struct bnx2x *bp, u16 abs_fid,
  285. u16 pf_id)
  286. {
  287. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_VF_TO_PF_OFFSET(abs_fid),
  288. pf_id);
  289. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_VF_TO_PF_OFFSET(abs_fid),
  290. pf_id);
  291. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_VF_TO_PF_OFFSET(abs_fid),
  292. pf_id);
  293. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_VF_TO_PF_OFFSET(abs_fid),
  294. pf_id);
  295. }
  296. static void storm_memset_func_en(struct bnx2x *bp, u16 abs_fid,
  297. u8 enable)
  298. {
  299. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(abs_fid),
  300. enable);
  301. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(abs_fid),
  302. enable);
  303. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(abs_fid),
  304. enable);
  305. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(abs_fid),
  306. enable);
  307. }
  308. static void storm_memset_eq_data(struct bnx2x *bp,
  309. struct event_ring_data *eq_data,
  310. u16 pfid)
  311. {
  312. size_t size = sizeof(struct event_ring_data);
  313. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_DATA_OFFSET(pfid);
  314. __storm_memset_struct(bp, addr, size, (u32 *)eq_data);
  315. }
  316. static void storm_memset_eq_prod(struct bnx2x *bp, u16 eq_prod,
  317. u16 pfid)
  318. {
  319. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_PROD_OFFSET(pfid);
  320. REG_WR16(bp, addr, eq_prod);
  321. }
  322. /* used only at init
  323. * locking is done by mcp
  324. */
  325. static void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val)
  326. {
  327. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  328. pci_write_config_dword(bp->pdev, PCICFG_GRC_DATA, val);
  329. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  330. PCICFG_VENDOR_ID_OFFSET);
  331. }
  332. static u32 bnx2x_reg_rd_ind(struct bnx2x *bp, u32 addr)
  333. {
  334. u32 val;
  335. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  336. pci_read_config_dword(bp->pdev, PCICFG_GRC_DATA, &val);
  337. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  338. PCICFG_VENDOR_ID_OFFSET);
  339. return val;
  340. }
  341. #define DMAE_DP_SRC_GRC "grc src_addr [%08x]"
  342. #define DMAE_DP_SRC_PCI "pci src_addr [%x:%08x]"
  343. #define DMAE_DP_DST_GRC "grc dst_addr [%08x]"
  344. #define DMAE_DP_DST_PCI "pci dst_addr [%x:%08x]"
  345. #define DMAE_DP_DST_NONE "dst_addr [none]"
  346. static void bnx2x_dp_dmae(struct bnx2x *bp,
  347. struct dmae_command *dmae, int msglvl)
  348. {
  349. u32 src_type = dmae->opcode & DMAE_COMMAND_SRC;
  350. int i;
  351. switch (dmae->opcode & DMAE_COMMAND_DST) {
  352. case DMAE_CMD_DST_PCI:
  353. if (src_type == DMAE_CMD_SRC_PCI)
  354. DP(msglvl, "DMAE: opcode 0x%08x\n"
  355. "src [%x:%08x], len [%d*4], dst [%x:%08x]\n"
  356. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  357. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  358. dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
  359. dmae->comp_addr_hi, dmae->comp_addr_lo,
  360. dmae->comp_val);
  361. else
  362. DP(msglvl, "DMAE: opcode 0x%08x\n"
  363. "src [%08x], len [%d*4], dst [%x:%08x]\n"
  364. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  365. dmae->opcode, dmae->src_addr_lo >> 2,
  366. dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
  367. dmae->comp_addr_hi, dmae->comp_addr_lo,
  368. dmae->comp_val);
  369. break;
  370. case DMAE_CMD_DST_GRC:
  371. if (src_type == DMAE_CMD_SRC_PCI)
  372. DP(msglvl, "DMAE: opcode 0x%08x\n"
  373. "src [%x:%08x], len [%d*4], dst_addr [%08x]\n"
  374. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  375. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  376. dmae->len, dmae->dst_addr_lo >> 2,
  377. dmae->comp_addr_hi, dmae->comp_addr_lo,
  378. dmae->comp_val);
  379. else
  380. DP(msglvl, "DMAE: opcode 0x%08x\n"
  381. "src [%08x], len [%d*4], dst [%08x]\n"
  382. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  383. dmae->opcode, dmae->src_addr_lo >> 2,
  384. dmae->len, dmae->dst_addr_lo >> 2,
  385. dmae->comp_addr_hi, dmae->comp_addr_lo,
  386. dmae->comp_val);
  387. break;
  388. default:
  389. if (src_type == DMAE_CMD_SRC_PCI)
  390. DP(msglvl, "DMAE: opcode 0x%08x\n"
  391. "src_addr [%x:%08x] len [%d * 4] dst_addr [none]\n"
  392. "comp_addr [%x:%08x] comp_val 0x%08x\n",
  393. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  394. dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
  395. dmae->comp_val);
  396. else
  397. DP(msglvl, "DMAE: opcode 0x%08x\n"
  398. "src_addr [%08x] len [%d * 4] dst_addr [none]\n"
  399. "comp_addr [%x:%08x] comp_val 0x%08x\n",
  400. dmae->opcode, dmae->src_addr_lo >> 2,
  401. dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
  402. dmae->comp_val);
  403. break;
  404. }
  405. for (i = 0; i < (sizeof(struct dmae_command)/4); i++)
  406. DP(msglvl, "DMAE RAW [%02d]: 0x%08x\n",
  407. i, *(((u32 *)dmae) + i));
  408. }
  409. /* copy command into DMAE command memory and set DMAE command go */
  410. void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae, int idx)
  411. {
  412. u32 cmd_offset;
  413. int i;
  414. cmd_offset = (DMAE_REG_CMD_MEM + sizeof(struct dmae_command) * idx);
  415. for (i = 0; i < (sizeof(struct dmae_command)/4); i++) {
  416. REG_WR(bp, cmd_offset + i*4, *(((u32 *)dmae) + i));
  417. }
  418. REG_WR(bp, dmae_reg_go_c[idx], 1);
  419. }
  420. u32 bnx2x_dmae_opcode_add_comp(u32 opcode, u8 comp_type)
  421. {
  422. return opcode | ((comp_type << DMAE_COMMAND_C_DST_SHIFT) |
  423. DMAE_CMD_C_ENABLE);
  424. }
  425. u32 bnx2x_dmae_opcode_clr_src_reset(u32 opcode)
  426. {
  427. return opcode & ~DMAE_CMD_SRC_RESET;
  428. }
  429. u32 bnx2x_dmae_opcode(struct bnx2x *bp, u8 src_type, u8 dst_type,
  430. bool with_comp, u8 comp_type)
  431. {
  432. u32 opcode = 0;
  433. opcode |= ((src_type << DMAE_COMMAND_SRC_SHIFT) |
  434. (dst_type << DMAE_COMMAND_DST_SHIFT));
  435. opcode |= (DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET);
  436. opcode |= (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0);
  437. opcode |= ((BP_VN(bp) << DMAE_CMD_E1HVN_SHIFT) |
  438. (BP_VN(bp) << DMAE_COMMAND_DST_VN_SHIFT));
  439. opcode |= (DMAE_COM_SET_ERR << DMAE_COMMAND_ERR_POLICY_SHIFT);
  440. #ifdef __BIG_ENDIAN
  441. opcode |= DMAE_CMD_ENDIANITY_B_DW_SWAP;
  442. #else
  443. opcode |= DMAE_CMD_ENDIANITY_DW_SWAP;
  444. #endif
  445. if (with_comp)
  446. opcode = bnx2x_dmae_opcode_add_comp(opcode, comp_type);
  447. return opcode;
  448. }
  449. void bnx2x_prep_dmae_with_comp(struct bnx2x *bp,
  450. struct dmae_command *dmae,
  451. u8 src_type, u8 dst_type)
  452. {
  453. memset(dmae, 0, sizeof(struct dmae_command));
  454. /* set the opcode */
  455. dmae->opcode = bnx2x_dmae_opcode(bp, src_type, dst_type,
  456. true, DMAE_COMP_PCI);
  457. /* fill in the completion parameters */
  458. dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp));
  459. dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp));
  460. dmae->comp_val = DMAE_COMP_VAL;
  461. }
  462. /* issue a dmae command over the init-channel and wait for completion */
  463. int bnx2x_issue_dmae_with_comp(struct bnx2x *bp, struct dmae_command *dmae,
  464. u32 *comp)
  465. {
  466. int cnt = CHIP_REV_IS_SLOW(bp) ? (400000) : 4000;
  467. int rc = 0;
  468. bnx2x_dp_dmae(bp, dmae, BNX2X_MSG_DMAE);
  469. /* Lock the dmae channel. Disable BHs to prevent a dead-lock
  470. * as long as this code is called both from syscall context and
  471. * from ndo_set_rx_mode() flow that may be called from BH.
  472. */
  473. spin_lock_bh(&bp->dmae_lock);
  474. /* reset completion */
  475. *comp = 0;
  476. /* post the command on the channel used for initializations */
  477. bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp));
  478. /* wait for completion */
  479. udelay(5);
  480. while ((*comp & ~DMAE_PCI_ERR_FLAG) != DMAE_COMP_VAL) {
  481. if (!cnt ||
  482. (bp->recovery_state != BNX2X_RECOVERY_DONE &&
  483. bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  484. BNX2X_ERR("DMAE timeout!\n");
  485. rc = DMAE_TIMEOUT;
  486. goto unlock;
  487. }
  488. cnt--;
  489. udelay(50);
  490. }
  491. if (*comp & DMAE_PCI_ERR_FLAG) {
  492. BNX2X_ERR("DMAE PCI error!\n");
  493. rc = DMAE_PCI_ERROR;
  494. }
  495. unlock:
  496. spin_unlock_bh(&bp->dmae_lock);
  497. return rc;
  498. }
  499. void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr,
  500. u32 len32)
  501. {
  502. int rc;
  503. struct dmae_command dmae;
  504. if (!bp->dmae_ready) {
  505. u32 *data = bnx2x_sp(bp, wb_data[0]);
  506. if (CHIP_IS_E1(bp))
  507. bnx2x_init_ind_wr(bp, dst_addr, data, len32);
  508. else
  509. bnx2x_init_str_wr(bp, dst_addr, data, len32);
  510. return;
  511. }
  512. /* set opcode and fixed command fields */
  513. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_GRC);
  514. /* fill in addresses and len */
  515. dmae.src_addr_lo = U64_LO(dma_addr);
  516. dmae.src_addr_hi = U64_HI(dma_addr);
  517. dmae.dst_addr_lo = dst_addr >> 2;
  518. dmae.dst_addr_hi = 0;
  519. dmae.len = len32;
  520. /* issue the command and wait for completion */
  521. rc = bnx2x_issue_dmae_with_comp(bp, &dmae, bnx2x_sp(bp, wb_comp));
  522. if (rc) {
  523. BNX2X_ERR("DMAE returned failure %d\n", rc);
  524. #ifdef BNX2X_STOP_ON_ERROR
  525. bnx2x_panic();
  526. #endif
  527. }
  528. }
  529. void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32)
  530. {
  531. int rc;
  532. struct dmae_command dmae;
  533. if (!bp->dmae_ready) {
  534. u32 *data = bnx2x_sp(bp, wb_data[0]);
  535. int i;
  536. if (CHIP_IS_E1(bp))
  537. for (i = 0; i < len32; i++)
  538. data[i] = bnx2x_reg_rd_ind(bp, src_addr + i*4);
  539. else
  540. for (i = 0; i < len32; i++)
  541. data[i] = REG_RD(bp, src_addr + i*4);
  542. return;
  543. }
  544. /* set opcode and fixed command fields */
  545. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_GRC, DMAE_DST_PCI);
  546. /* fill in addresses and len */
  547. dmae.src_addr_lo = src_addr >> 2;
  548. dmae.src_addr_hi = 0;
  549. dmae.dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_data));
  550. dmae.dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_data));
  551. dmae.len = len32;
  552. /* issue the command and wait for completion */
  553. rc = bnx2x_issue_dmae_with_comp(bp, &dmae, bnx2x_sp(bp, wb_comp));
  554. if (rc) {
  555. BNX2X_ERR("DMAE returned failure %d\n", rc);
  556. #ifdef BNX2X_STOP_ON_ERROR
  557. bnx2x_panic();
  558. #endif
  559. }
  560. }
  561. static void bnx2x_write_dmae_phys_len(struct bnx2x *bp, dma_addr_t phys_addr,
  562. u32 addr, u32 len)
  563. {
  564. int dmae_wr_max = DMAE_LEN32_WR_MAX(bp);
  565. int offset = 0;
  566. while (len > dmae_wr_max) {
  567. bnx2x_write_dmae(bp, phys_addr + offset,
  568. addr + offset, dmae_wr_max);
  569. offset += dmae_wr_max * 4;
  570. len -= dmae_wr_max;
  571. }
  572. bnx2x_write_dmae(bp, phys_addr + offset, addr + offset, len);
  573. }
  574. enum storms {
  575. XSTORM,
  576. TSTORM,
  577. CSTORM,
  578. USTORM,
  579. MAX_STORMS
  580. };
  581. #define STORMS_NUM 4
  582. #define REGS_IN_ENTRY 4
  583. static inline int bnx2x_get_assert_list_entry(struct bnx2x *bp,
  584. enum storms storm,
  585. int entry)
  586. {
  587. switch (storm) {
  588. case XSTORM:
  589. return XSTORM_ASSERT_LIST_OFFSET(entry);
  590. case TSTORM:
  591. return TSTORM_ASSERT_LIST_OFFSET(entry);
  592. case CSTORM:
  593. return CSTORM_ASSERT_LIST_OFFSET(entry);
  594. case USTORM:
  595. return USTORM_ASSERT_LIST_OFFSET(entry);
  596. case MAX_STORMS:
  597. default:
  598. BNX2X_ERR("unknown storm\n");
  599. }
  600. return -EINVAL;
  601. }
  602. static int bnx2x_mc_assert(struct bnx2x *bp)
  603. {
  604. char last_idx;
  605. int i, j, rc = 0;
  606. enum storms storm;
  607. u32 regs[REGS_IN_ENTRY];
  608. u32 bar_storm_intmem[STORMS_NUM] = {
  609. BAR_XSTRORM_INTMEM,
  610. BAR_TSTRORM_INTMEM,
  611. BAR_CSTRORM_INTMEM,
  612. BAR_USTRORM_INTMEM
  613. };
  614. u32 storm_assert_list_index[STORMS_NUM] = {
  615. XSTORM_ASSERT_LIST_INDEX_OFFSET,
  616. TSTORM_ASSERT_LIST_INDEX_OFFSET,
  617. CSTORM_ASSERT_LIST_INDEX_OFFSET,
  618. USTORM_ASSERT_LIST_INDEX_OFFSET
  619. };
  620. char *storms_string[STORMS_NUM] = {
  621. "XSTORM",
  622. "TSTORM",
  623. "CSTORM",
  624. "USTORM"
  625. };
  626. for (storm = XSTORM; storm < MAX_STORMS; storm++) {
  627. last_idx = REG_RD8(bp, bar_storm_intmem[storm] +
  628. storm_assert_list_index[storm]);
  629. if (last_idx)
  630. BNX2X_ERR("%s_ASSERT_LIST_INDEX 0x%x\n",
  631. storms_string[storm], last_idx);
  632. /* print the asserts */
  633. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  634. /* read a single assert entry */
  635. for (j = 0; j < REGS_IN_ENTRY; j++)
  636. regs[j] = REG_RD(bp, bar_storm_intmem[storm] +
  637. bnx2x_get_assert_list_entry(bp,
  638. storm,
  639. i) +
  640. sizeof(u32) * j);
  641. /* log entry if it contains a valid assert */
  642. if (regs[0] != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  643. BNX2X_ERR("%s_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  644. storms_string[storm], i, regs[3],
  645. regs[2], regs[1], regs[0]);
  646. rc++;
  647. } else {
  648. break;
  649. }
  650. }
  651. }
  652. BNX2X_ERR("Chip Revision: %s, FW Version: %d_%d_%d\n",
  653. CHIP_IS_E1(bp) ? "everest1" :
  654. CHIP_IS_E1H(bp) ? "everest1h" :
  655. CHIP_IS_E2(bp) ? "everest2" : "everest3",
  656. BCM_5710_FW_MAJOR_VERSION,
  657. BCM_5710_FW_MINOR_VERSION,
  658. BCM_5710_FW_REVISION_VERSION);
  659. return rc;
  660. }
  661. #define MCPR_TRACE_BUFFER_SIZE (0x800)
  662. #define SCRATCH_BUFFER_SIZE(bp) \
  663. (CHIP_IS_E1(bp) ? 0x10000 : (CHIP_IS_E1H(bp) ? 0x20000 : 0x28000))
  664. void bnx2x_fw_dump_lvl(struct bnx2x *bp, const char *lvl)
  665. {
  666. u32 addr, val;
  667. u32 mark, offset;
  668. __be32 data[9];
  669. int word;
  670. u32 trace_shmem_base;
  671. if (BP_NOMCP(bp)) {
  672. BNX2X_ERR("NO MCP - can not dump\n");
  673. return;
  674. }
  675. netdev_printk(lvl, bp->dev, "bc %d.%d.%d\n",
  676. (bp->common.bc_ver & 0xff0000) >> 16,
  677. (bp->common.bc_ver & 0xff00) >> 8,
  678. (bp->common.bc_ver & 0xff));
  679. val = REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER);
  680. if (val == REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER))
  681. BNX2X_ERR("%s" "MCP PC at 0x%x\n", lvl, val);
  682. if (BP_PATH(bp) == 0)
  683. trace_shmem_base = bp->common.shmem_base;
  684. else
  685. trace_shmem_base = SHMEM2_RD(bp, other_shmem_base_addr);
  686. /* sanity */
  687. if (trace_shmem_base < MCPR_SCRATCH_BASE(bp) + MCPR_TRACE_BUFFER_SIZE ||
  688. trace_shmem_base >= MCPR_SCRATCH_BASE(bp) +
  689. SCRATCH_BUFFER_SIZE(bp)) {
  690. BNX2X_ERR("Unable to dump trace buffer (mark %x)\n",
  691. trace_shmem_base);
  692. return;
  693. }
  694. addr = trace_shmem_base - MCPR_TRACE_BUFFER_SIZE;
  695. /* validate TRCB signature */
  696. mark = REG_RD(bp, addr);
  697. if (mark != MFW_TRACE_SIGNATURE) {
  698. BNX2X_ERR("Trace buffer signature is missing.");
  699. return ;
  700. }
  701. /* read cyclic buffer pointer */
  702. addr += 4;
  703. mark = REG_RD(bp, addr);
  704. mark = MCPR_SCRATCH_BASE(bp) + ((mark + 0x3) & ~0x3) - 0x08000000;
  705. if (mark >= trace_shmem_base || mark < addr + 4) {
  706. BNX2X_ERR("Mark doesn't fall inside Trace Buffer\n");
  707. return;
  708. }
  709. printk("%s" "begin fw dump (mark 0x%x)\n", lvl, mark);
  710. printk("%s", lvl);
  711. /* dump buffer after the mark */
  712. for (offset = mark; offset < trace_shmem_base; offset += 0x8*4) {
  713. for (word = 0; word < 8; word++)
  714. data[word] = htonl(REG_RD(bp, offset + 4*word));
  715. data[8] = 0x0;
  716. pr_cont("%s", (char *)data);
  717. }
  718. /* dump buffer before the mark */
  719. for (offset = addr + 4; offset <= mark; offset += 0x8*4) {
  720. for (word = 0; word < 8; word++)
  721. data[word] = htonl(REG_RD(bp, offset + 4*word));
  722. data[8] = 0x0;
  723. pr_cont("%s", (char *)data);
  724. }
  725. printk("%s" "end of fw dump\n", lvl);
  726. }
  727. static void bnx2x_fw_dump(struct bnx2x *bp)
  728. {
  729. bnx2x_fw_dump_lvl(bp, KERN_ERR);
  730. }
  731. static void bnx2x_hc_int_disable(struct bnx2x *bp)
  732. {
  733. int port = BP_PORT(bp);
  734. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  735. u32 val = REG_RD(bp, addr);
  736. /* in E1 we must use only PCI configuration space to disable
  737. * MSI/MSIX capability
  738. * It's forbidden to disable IGU_PF_CONF_MSI_MSIX_EN in HC block
  739. */
  740. if (CHIP_IS_E1(bp)) {
  741. /* Since IGU_PF_CONF_MSI_MSIX_EN still always on
  742. * Use mask register to prevent from HC sending interrupts
  743. * after we exit the function
  744. */
  745. REG_WR(bp, HC_REG_INT_MASK + port*4, 0);
  746. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  747. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  748. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  749. } else
  750. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  751. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  752. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  753. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  754. DP(NETIF_MSG_IFDOWN,
  755. "write %x to HC %d (addr 0x%x)\n",
  756. val, port, addr);
  757. /* flush all outstanding writes */
  758. mmiowb();
  759. REG_WR(bp, addr, val);
  760. if (REG_RD(bp, addr) != val)
  761. BNX2X_ERR("BUG! Proper val not read from IGU!\n");
  762. }
  763. static void bnx2x_igu_int_disable(struct bnx2x *bp)
  764. {
  765. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  766. val &= ~(IGU_PF_CONF_MSI_MSIX_EN |
  767. IGU_PF_CONF_INT_LINE_EN |
  768. IGU_PF_CONF_ATTN_BIT_EN);
  769. DP(NETIF_MSG_IFDOWN, "write %x to IGU\n", val);
  770. /* flush all outstanding writes */
  771. mmiowb();
  772. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  773. if (REG_RD(bp, IGU_REG_PF_CONFIGURATION) != val)
  774. BNX2X_ERR("BUG! Proper val not read from IGU!\n");
  775. }
  776. static void bnx2x_int_disable(struct bnx2x *bp)
  777. {
  778. if (bp->common.int_block == INT_BLOCK_HC)
  779. bnx2x_hc_int_disable(bp);
  780. else
  781. bnx2x_igu_int_disable(bp);
  782. }
  783. void bnx2x_panic_dump(struct bnx2x *bp, bool disable_int)
  784. {
  785. int i;
  786. u16 j;
  787. struct hc_sp_status_block_data sp_sb_data;
  788. int func = BP_FUNC(bp);
  789. #ifdef BNX2X_STOP_ON_ERROR
  790. u16 start = 0, end = 0;
  791. u8 cos;
  792. #endif
  793. if (IS_PF(bp) && disable_int)
  794. bnx2x_int_disable(bp);
  795. bp->stats_state = STATS_STATE_DISABLED;
  796. bp->eth_stats.unrecoverable_error++;
  797. DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n");
  798. BNX2X_ERR("begin crash dump -----------------\n");
  799. /* Indices */
  800. /* Common */
  801. if (IS_PF(bp)) {
  802. struct host_sp_status_block *def_sb = bp->def_status_blk;
  803. int data_size, cstorm_offset;
  804. BNX2X_ERR("def_idx(0x%x) def_att_idx(0x%x) attn_state(0x%x) spq_prod_idx(0x%x) next_stats_cnt(0x%x)\n",
  805. bp->def_idx, bp->def_att_idx, bp->attn_state,
  806. bp->spq_prod_idx, bp->stats_counter);
  807. BNX2X_ERR("DSB: attn bits(0x%x) ack(0x%x) id(0x%x) idx(0x%x)\n",
  808. def_sb->atten_status_block.attn_bits,
  809. def_sb->atten_status_block.attn_bits_ack,
  810. def_sb->atten_status_block.status_block_id,
  811. def_sb->atten_status_block.attn_bits_index);
  812. BNX2X_ERR(" def (");
  813. for (i = 0; i < HC_SP_SB_MAX_INDICES; i++)
  814. pr_cont("0x%x%s",
  815. def_sb->sp_sb.index_values[i],
  816. (i == HC_SP_SB_MAX_INDICES - 1) ? ") " : " ");
  817. data_size = sizeof(struct hc_sp_status_block_data) /
  818. sizeof(u32);
  819. cstorm_offset = CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func);
  820. for (i = 0; i < data_size; i++)
  821. *((u32 *)&sp_sb_data + i) =
  822. REG_RD(bp, BAR_CSTRORM_INTMEM + cstorm_offset +
  823. i * sizeof(u32));
  824. pr_cont("igu_sb_id(0x%x) igu_seg_id(0x%x) pf_id(0x%x) vnic_id(0x%x) vf_id(0x%x) vf_valid (0x%x) state(0x%x)\n",
  825. sp_sb_data.igu_sb_id,
  826. sp_sb_data.igu_seg_id,
  827. sp_sb_data.p_func.pf_id,
  828. sp_sb_data.p_func.vnic_id,
  829. sp_sb_data.p_func.vf_id,
  830. sp_sb_data.p_func.vf_valid,
  831. sp_sb_data.state);
  832. }
  833. for_each_eth_queue(bp, i) {
  834. struct bnx2x_fastpath *fp = &bp->fp[i];
  835. int loop;
  836. struct hc_status_block_data_e2 sb_data_e2;
  837. struct hc_status_block_data_e1x sb_data_e1x;
  838. struct hc_status_block_sm *hc_sm_p =
  839. CHIP_IS_E1x(bp) ?
  840. sb_data_e1x.common.state_machine :
  841. sb_data_e2.common.state_machine;
  842. struct hc_index_data *hc_index_p =
  843. CHIP_IS_E1x(bp) ?
  844. sb_data_e1x.index_data :
  845. sb_data_e2.index_data;
  846. u8 data_size, cos;
  847. u32 *sb_data_p;
  848. struct bnx2x_fp_txdata txdata;
  849. if (!bp->fp)
  850. break;
  851. if (!fp->rx_cons_sb)
  852. continue;
  853. /* Rx */
  854. BNX2X_ERR("fp%d: rx_bd_prod(0x%x) rx_bd_cons(0x%x) rx_comp_prod(0x%x) rx_comp_cons(0x%x) *rx_cons_sb(0x%x)\n",
  855. i, fp->rx_bd_prod, fp->rx_bd_cons,
  856. fp->rx_comp_prod,
  857. fp->rx_comp_cons, le16_to_cpu(*fp->rx_cons_sb));
  858. BNX2X_ERR(" rx_sge_prod(0x%x) last_max_sge(0x%x) fp_hc_idx(0x%x)\n",
  859. fp->rx_sge_prod, fp->last_max_sge,
  860. le16_to_cpu(fp->fp_hc_idx));
  861. /* Tx */
  862. for_each_cos_in_tx_queue(fp, cos)
  863. {
  864. if (!fp->txdata_ptr[cos])
  865. break;
  866. txdata = *fp->txdata_ptr[cos];
  867. if (!txdata.tx_cons_sb)
  868. continue;
  869. BNX2X_ERR("fp%d: tx_pkt_prod(0x%x) tx_pkt_cons(0x%x) tx_bd_prod(0x%x) tx_bd_cons(0x%x) *tx_cons_sb(0x%x)\n",
  870. i, txdata.tx_pkt_prod,
  871. txdata.tx_pkt_cons, txdata.tx_bd_prod,
  872. txdata.tx_bd_cons,
  873. le16_to_cpu(*txdata.tx_cons_sb));
  874. }
  875. loop = CHIP_IS_E1x(bp) ?
  876. HC_SB_MAX_INDICES_E1X : HC_SB_MAX_INDICES_E2;
  877. /* host sb data */
  878. if (IS_FCOE_FP(fp))
  879. continue;
  880. BNX2X_ERR(" run indexes (");
  881. for (j = 0; j < HC_SB_MAX_SM; j++)
  882. pr_cont("0x%x%s",
  883. fp->sb_running_index[j],
  884. (j == HC_SB_MAX_SM - 1) ? ")" : " ");
  885. BNX2X_ERR(" indexes (");
  886. for (j = 0; j < loop; j++)
  887. pr_cont("0x%x%s",
  888. fp->sb_index_values[j],
  889. (j == loop - 1) ? ")" : " ");
  890. /* VF cannot access FW refelection for status block */
  891. if (IS_VF(bp))
  892. continue;
  893. /* fw sb data */
  894. data_size = CHIP_IS_E1x(bp) ?
  895. sizeof(struct hc_status_block_data_e1x) :
  896. sizeof(struct hc_status_block_data_e2);
  897. data_size /= sizeof(u32);
  898. sb_data_p = CHIP_IS_E1x(bp) ?
  899. (u32 *)&sb_data_e1x :
  900. (u32 *)&sb_data_e2;
  901. /* copy sb data in here */
  902. for (j = 0; j < data_size; j++)
  903. *(sb_data_p + j) = REG_RD(bp, BAR_CSTRORM_INTMEM +
  904. CSTORM_STATUS_BLOCK_DATA_OFFSET(fp->fw_sb_id) +
  905. j * sizeof(u32));
  906. if (!CHIP_IS_E1x(bp)) {
  907. pr_cont("pf_id(0x%x) vf_id(0x%x) vf_valid(0x%x) vnic_id(0x%x) same_igu_sb_1b(0x%x) state(0x%x)\n",
  908. sb_data_e2.common.p_func.pf_id,
  909. sb_data_e2.common.p_func.vf_id,
  910. sb_data_e2.common.p_func.vf_valid,
  911. sb_data_e2.common.p_func.vnic_id,
  912. sb_data_e2.common.same_igu_sb_1b,
  913. sb_data_e2.common.state);
  914. } else {
  915. pr_cont("pf_id(0x%x) vf_id(0x%x) vf_valid(0x%x) vnic_id(0x%x) same_igu_sb_1b(0x%x) state(0x%x)\n",
  916. sb_data_e1x.common.p_func.pf_id,
  917. sb_data_e1x.common.p_func.vf_id,
  918. sb_data_e1x.common.p_func.vf_valid,
  919. sb_data_e1x.common.p_func.vnic_id,
  920. sb_data_e1x.common.same_igu_sb_1b,
  921. sb_data_e1x.common.state);
  922. }
  923. /* SB_SMs data */
  924. for (j = 0; j < HC_SB_MAX_SM; j++) {
  925. pr_cont("SM[%d] __flags (0x%x) igu_sb_id (0x%x) igu_seg_id(0x%x) time_to_expire (0x%x) timer_value(0x%x)\n",
  926. j, hc_sm_p[j].__flags,
  927. hc_sm_p[j].igu_sb_id,
  928. hc_sm_p[j].igu_seg_id,
  929. hc_sm_p[j].time_to_expire,
  930. hc_sm_p[j].timer_value);
  931. }
  932. /* Indices data */
  933. for (j = 0; j < loop; j++) {
  934. pr_cont("INDEX[%d] flags (0x%x) timeout (0x%x)\n", j,
  935. hc_index_p[j].flags,
  936. hc_index_p[j].timeout);
  937. }
  938. }
  939. #ifdef BNX2X_STOP_ON_ERROR
  940. if (IS_PF(bp)) {
  941. /* event queue */
  942. BNX2X_ERR("eq cons %x prod %x\n", bp->eq_cons, bp->eq_prod);
  943. for (i = 0; i < NUM_EQ_DESC; i++) {
  944. u32 *data = (u32 *)&bp->eq_ring[i].message.data;
  945. BNX2X_ERR("event queue [%d]: header: opcode %d, error %d\n",
  946. i, bp->eq_ring[i].message.opcode,
  947. bp->eq_ring[i].message.error);
  948. BNX2X_ERR("data: %x %x %x\n",
  949. data[0], data[1], data[2]);
  950. }
  951. }
  952. /* Rings */
  953. /* Rx */
  954. for_each_valid_rx_queue(bp, i) {
  955. struct bnx2x_fastpath *fp = &bp->fp[i];
  956. if (!bp->fp)
  957. break;
  958. if (!fp->rx_cons_sb)
  959. continue;
  960. start = RX_BD(le16_to_cpu(*fp->rx_cons_sb) - 10);
  961. end = RX_BD(le16_to_cpu(*fp->rx_cons_sb) + 503);
  962. for (j = start; j != end; j = RX_BD(j + 1)) {
  963. u32 *rx_bd = (u32 *)&fp->rx_desc_ring[j];
  964. struct sw_rx_bd *sw_bd = &fp->rx_buf_ring[j];
  965. BNX2X_ERR("fp%d: rx_bd[%x]=[%x:%x] sw_bd=[%p]\n",
  966. i, j, rx_bd[1], rx_bd[0], sw_bd->data);
  967. }
  968. start = RX_SGE(fp->rx_sge_prod);
  969. end = RX_SGE(fp->last_max_sge);
  970. for (j = start; j != end; j = RX_SGE(j + 1)) {
  971. u32 *rx_sge = (u32 *)&fp->rx_sge_ring[j];
  972. struct sw_rx_page *sw_page = &fp->rx_page_ring[j];
  973. BNX2X_ERR("fp%d: rx_sge[%x]=[%x:%x] sw_page=[%p]\n",
  974. i, j, rx_sge[1], rx_sge[0], sw_page->page);
  975. }
  976. start = RCQ_BD(fp->rx_comp_cons - 10);
  977. end = RCQ_BD(fp->rx_comp_cons + 503);
  978. for (j = start; j != end; j = RCQ_BD(j + 1)) {
  979. u32 *cqe = (u32 *)&fp->rx_comp_ring[j];
  980. BNX2X_ERR("fp%d: cqe[%x]=[%x:%x:%x:%x]\n",
  981. i, j, cqe[0], cqe[1], cqe[2], cqe[3]);
  982. }
  983. }
  984. /* Tx */
  985. for_each_valid_tx_queue(bp, i) {
  986. struct bnx2x_fastpath *fp = &bp->fp[i];
  987. if (!bp->fp)
  988. break;
  989. for_each_cos_in_tx_queue(fp, cos) {
  990. struct bnx2x_fp_txdata *txdata = fp->txdata_ptr[cos];
  991. if (!fp->txdata_ptr[cos])
  992. break;
  993. if (!txdata->tx_cons_sb)
  994. continue;
  995. start = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) - 10);
  996. end = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) + 245);
  997. for (j = start; j != end; j = TX_BD(j + 1)) {
  998. struct sw_tx_bd *sw_bd =
  999. &txdata->tx_buf_ring[j];
  1000. BNX2X_ERR("fp%d: txdata %d, packet[%x]=[%p,%x]\n",
  1001. i, cos, j, sw_bd->skb,
  1002. sw_bd->first_bd);
  1003. }
  1004. start = TX_BD(txdata->tx_bd_cons - 10);
  1005. end = TX_BD(txdata->tx_bd_cons + 254);
  1006. for (j = start; j != end; j = TX_BD(j + 1)) {
  1007. u32 *tx_bd = (u32 *)&txdata->tx_desc_ring[j];
  1008. BNX2X_ERR("fp%d: txdata %d, tx_bd[%x]=[%x:%x:%x:%x]\n",
  1009. i, cos, j, tx_bd[0], tx_bd[1],
  1010. tx_bd[2], tx_bd[3]);
  1011. }
  1012. }
  1013. }
  1014. #endif
  1015. if (IS_PF(bp)) {
  1016. bnx2x_fw_dump(bp);
  1017. bnx2x_mc_assert(bp);
  1018. }
  1019. BNX2X_ERR("end crash dump -----------------\n");
  1020. }
  1021. /*
  1022. * FLR Support for E2
  1023. *
  1024. * bnx2x_pf_flr_clnup() is called during nic_load in the per function HW
  1025. * initialization.
  1026. */
  1027. #define FLR_WAIT_USEC 10000 /* 10 milliseconds */
  1028. #define FLR_WAIT_INTERVAL 50 /* usec */
  1029. #define FLR_POLL_CNT (FLR_WAIT_USEC/FLR_WAIT_INTERVAL) /* 200 */
  1030. struct pbf_pN_buf_regs {
  1031. int pN;
  1032. u32 init_crd;
  1033. u32 crd;
  1034. u32 crd_freed;
  1035. };
  1036. struct pbf_pN_cmd_regs {
  1037. int pN;
  1038. u32 lines_occup;
  1039. u32 lines_freed;
  1040. };
  1041. static void bnx2x_pbf_pN_buf_flushed(struct bnx2x *bp,
  1042. struct pbf_pN_buf_regs *regs,
  1043. u32 poll_count)
  1044. {
  1045. u32 init_crd, crd, crd_start, crd_freed, crd_freed_start;
  1046. u32 cur_cnt = poll_count;
  1047. crd_freed = crd_freed_start = REG_RD(bp, regs->crd_freed);
  1048. crd = crd_start = REG_RD(bp, regs->crd);
  1049. init_crd = REG_RD(bp, regs->init_crd);
  1050. DP(BNX2X_MSG_SP, "INIT CREDIT[%d] : %x\n", regs->pN, init_crd);
  1051. DP(BNX2X_MSG_SP, "CREDIT[%d] : s:%x\n", regs->pN, crd);
  1052. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: s:%x\n", regs->pN, crd_freed);
  1053. while ((crd != init_crd) && ((u32)SUB_S32(crd_freed, crd_freed_start) <
  1054. (init_crd - crd_start))) {
  1055. if (cur_cnt--) {
  1056. udelay(FLR_WAIT_INTERVAL);
  1057. crd = REG_RD(bp, regs->crd);
  1058. crd_freed = REG_RD(bp, regs->crd_freed);
  1059. } else {
  1060. DP(BNX2X_MSG_SP, "PBF tx buffer[%d] timed out\n",
  1061. regs->pN);
  1062. DP(BNX2X_MSG_SP, "CREDIT[%d] : c:%x\n",
  1063. regs->pN, crd);
  1064. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: c:%x\n",
  1065. regs->pN, crd_freed);
  1066. break;
  1067. }
  1068. }
  1069. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF tx buffer[%d]\n",
  1070. poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
  1071. }
  1072. static void bnx2x_pbf_pN_cmd_flushed(struct bnx2x *bp,
  1073. struct pbf_pN_cmd_regs *regs,
  1074. u32 poll_count)
  1075. {
  1076. u32 occup, to_free, freed, freed_start;
  1077. u32 cur_cnt = poll_count;
  1078. occup = to_free = REG_RD(bp, regs->lines_occup);
  1079. freed = freed_start = REG_RD(bp, regs->lines_freed);
  1080. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n", regs->pN, occup);
  1081. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n", regs->pN, freed);
  1082. while (occup && ((u32)SUB_S32(freed, freed_start) < to_free)) {
  1083. if (cur_cnt--) {
  1084. udelay(FLR_WAIT_INTERVAL);
  1085. occup = REG_RD(bp, regs->lines_occup);
  1086. freed = REG_RD(bp, regs->lines_freed);
  1087. } else {
  1088. DP(BNX2X_MSG_SP, "PBF cmd queue[%d] timed out\n",
  1089. regs->pN);
  1090. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n",
  1091. regs->pN, occup);
  1092. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n",
  1093. regs->pN, freed);
  1094. break;
  1095. }
  1096. }
  1097. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF cmd queue[%d]\n",
  1098. poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
  1099. }
  1100. static u32 bnx2x_flr_clnup_reg_poll(struct bnx2x *bp, u32 reg,
  1101. u32 expected, u32 poll_count)
  1102. {
  1103. u32 cur_cnt = poll_count;
  1104. u32 val;
  1105. while ((val = REG_RD(bp, reg)) != expected && cur_cnt--)
  1106. udelay(FLR_WAIT_INTERVAL);
  1107. return val;
  1108. }
  1109. int bnx2x_flr_clnup_poll_hw_counter(struct bnx2x *bp, u32 reg,
  1110. char *msg, u32 poll_cnt)
  1111. {
  1112. u32 val = bnx2x_flr_clnup_reg_poll(bp, reg, 0, poll_cnt);
  1113. if (val != 0) {
  1114. BNX2X_ERR("%s usage count=%d\n", msg, val);
  1115. return 1;
  1116. }
  1117. return 0;
  1118. }
  1119. /* Common routines with VF FLR cleanup */
  1120. u32 bnx2x_flr_clnup_poll_count(struct bnx2x *bp)
  1121. {
  1122. /* adjust polling timeout */
  1123. if (CHIP_REV_IS_EMUL(bp))
  1124. return FLR_POLL_CNT * 2000;
  1125. if (CHIP_REV_IS_FPGA(bp))
  1126. return FLR_POLL_CNT * 120;
  1127. return FLR_POLL_CNT;
  1128. }
  1129. void bnx2x_tx_hw_flushed(struct bnx2x *bp, u32 poll_count)
  1130. {
  1131. struct pbf_pN_cmd_regs cmd_regs[] = {
  1132. {0, (CHIP_IS_E3B0(bp)) ?
  1133. PBF_REG_TQ_OCCUPANCY_Q0 :
  1134. PBF_REG_P0_TQ_OCCUPANCY,
  1135. (CHIP_IS_E3B0(bp)) ?
  1136. PBF_REG_TQ_LINES_FREED_CNT_Q0 :
  1137. PBF_REG_P0_TQ_LINES_FREED_CNT},
  1138. {1, (CHIP_IS_E3B0(bp)) ?
  1139. PBF_REG_TQ_OCCUPANCY_Q1 :
  1140. PBF_REG_P1_TQ_OCCUPANCY,
  1141. (CHIP_IS_E3B0(bp)) ?
  1142. PBF_REG_TQ_LINES_FREED_CNT_Q1 :
  1143. PBF_REG_P1_TQ_LINES_FREED_CNT},
  1144. {4, (CHIP_IS_E3B0(bp)) ?
  1145. PBF_REG_TQ_OCCUPANCY_LB_Q :
  1146. PBF_REG_P4_TQ_OCCUPANCY,
  1147. (CHIP_IS_E3B0(bp)) ?
  1148. PBF_REG_TQ_LINES_FREED_CNT_LB_Q :
  1149. PBF_REG_P4_TQ_LINES_FREED_CNT}
  1150. };
  1151. struct pbf_pN_buf_regs buf_regs[] = {
  1152. {0, (CHIP_IS_E3B0(bp)) ?
  1153. PBF_REG_INIT_CRD_Q0 :
  1154. PBF_REG_P0_INIT_CRD ,
  1155. (CHIP_IS_E3B0(bp)) ?
  1156. PBF_REG_CREDIT_Q0 :
  1157. PBF_REG_P0_CREDIT,
  1158. (CHIP_IS_E3B0(bp)) ?
  1159. PBF_REG_INTERNAL_CRD_FREED_CNT_Q0 :
  1160. PBF_REG_P0_INTERNAL_CRD_FREED_CNT},
  1161. {1, (CHIP_IS_E3B0(bp)) ?
  1162. PBF_REG_INIT_CRD_Q1 :
  1163. PBF_REG_P1_INIT_CRD,
  1164. (CHIP_IS_E3B0(bp)) ?
  1165. PBF_REG_CREDIT_Q1 :
  1166. PBF_REG_P1_CREDIT,
  1167. (CHIP_IS_E3B0(bp)) ?
  1168. PBF_REG_INTERNAL_CRD_FREED_CNT_Q1 :
  1169. PBF_REG_P1_INTERNAL_CRD_FREED_CNT},
  1170. {4, (CHIP_IS_E3B0(bp)) ?
  1171. PBF_REG_INIT_CRD_LB_Q :
  1172. PBF_REG_P4_INIT_CRD,
  1173. (CHIP_IS_E3B0(bp)) ?
  1174. PBF_REG_CREDIT_LB_Q :
  1175. PBF_REG_P4_CREDIT,
  1176. (CHIP_IS_E3B0(bp)) ?
  1177. PBF_REG_INTERNAL_CRD_FREED_CNT_LB_Q :
  1178. PBF_REG_P4_INTERNAL_CRD_FREED_CNT},
  1179. };
  1180. int i;
  1181. /* Verify the command queues are flushed P0, P1, P4 */
  1182. for (i = 0; i < ARRAY_SIZE(cmd_regs); i++)
  1183. bnx2x_pbf_pN_cmd_flushed(bp, &cmd_regs[i], poll_count);
  1184. /* Verify the transmission buffers are flushed P0, P1, P4 */
  1185. for (i = 0; i < ARRAY_SIZE(buf_regs); i++)
  1186. bnx2x_pbf_pN_buf_flushed(bp, &buf_regs[i], poll_count);
  1187. }
  1188. #define OP_GEN_PARAM(param) \
  1189. (((param) << SDM_OP_GEN_COMP_PARAM_SHIFT) & SDM_OP_GEN_COMP_PARAM)
  1190. #define OP_GEN_TYPE(type) \
  1191. (((type) << SDM_OP_GEN_COMP_TYPE_SHIFT) & SDM_OP_GEN_COMP_TYPE)
  1192. #define OP_GEN_AGG_VECT(index) \
  1193. (((index) << SDM_OP_GEN_AGG_VECT_IDX_SHIFT) & SDM_OP_GEN_AGG_VECT_IDX)
  1194. int bnx2x_send_final_clnup(struct bnx2x *bp, u8 clnup_func, u32 poll_cnt)
  1195. {
  1196. u32 op_gen_command = 0;
  1197. u32 comp_addr = BAR_CSTRORM_INTMEM +
  1198. CSTORM_FINAL_CLEANUP_COMPLETE_OFFSET(clnup_func);
  1199. int ret = 0;
  1200. if (REG_RD(bp, comp_addr)) {
  1201. BNX2X_ERR("Cleanup complete was not 0 before sending\n");
  1202. return 1;
  1203. }
  1204. op_gen_command |= OP_GEN_PARAM(XSTORM_AGG_INT_FINAL_CLEANUP_INDEX);
  1205. op_gen_command |= OP_GEN_TYPE(XSTORM_AGG_INT_FINAL_CLEANUP_COMP_TYPE);
  1206. op_gen_command |= OP_GEN_AGG_VECT(clnup_func);
  1207. op_gen_command |= 1 << SDM_OP_GEN_AGG_VECT_IDX_VALID_SHIFT;
  1208. DP(BNX2X_MSG_SP, "sending FW Final cleanup\n");
  1209. REG_WR(bp, XSDM_REG_OPERATION_GEN, op_gen_command);
  1210. if (bnx2x_flr_clnup_reg_poll(bp, comp_addr, 1, poll_cnt) != 1) {
  1211. BNX2X_ERR("FW final cleanup did not succeed\n");
  1212. DP(BNX2X_MSG_SP, "At timeout completion address contained %x\n",
  1213. (REG_RD(bp, comp_addr)));
  1214. bnx2x_panic();
  1215. return 1;
  1216. }
  1217. /* Zero completion for next FLR */
  1218. REG_WR(bp, comp_addr, 0);
  1219. return ret;
  1220. }
  1221. u8 bnx2x_is_pcie_pending(struct pci_dev *dev)
  1222. {
  1223. u16 status;
  1224. pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status);
  1225. return status & PCI_EXP_DEVSTA_TRPND;
  1226. }
  1227. /* PF FLR specific routines
  1228. */
  1229. static int bnx2x_poll_hw_usage_counters(struct bnx2x *bp, u32 poll_cnt)
  1230. {
  1231. /* wait for CFC PF usage-counter to zero (includes all the VFs) */
  1232. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1233. CFC_REG_NUM_LCIDS_INSIDE_PF,
  1234. "CFC PF usage counter timed out",
  1235. poll_cnt))
  1236. return 1;
  1237. /* Wait for DQ PF usage-counter to zero (until DQ cleanup) */
  1238. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1239. DORQ_REG_PF_USAGE_CNT,
  1240. "DQ PF usage counter timed out",
  1241. poll_cnt))
  1242. return 1;
  1243. /* Wait for QM PF usage-counter to zero (until DQ cleanup) */
  1244. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1245. QM_REG_PF_USG_CNT_0 + 4*BP_FUNC(bp),
  1246. "QM PF usage counter timed out",
  1247. poll_cnt))
  1248. return 1;
  1249. /* Wait for Timer PF usage-counters to zero (until DQ cleanup) */
  1250. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1251. TM_REG_LIN0_VNIC_UC + 4*BP_PORT(bp),
  1252. "Timers VNIC usage counter timed out",
  1253. poll_cnt))
  1254. return 1;
  1255. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1256. TM_REG_LIN0_NUM_SCANS + 4*BP_PORT(bp),
  1257. "Timers NUM_SCANS usage counter timed out",
  1258. poll_cnt))
  1259. return 1;
  1260. /* Wait DMAE PF usage counter to zero */
  1261. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1262. dmae_reg_go_c[INIT_DMAE_C(bp)],
  1263. "DMAE command register timed out",
  1264. poll_cnt))
  1265. return 1;
  1266. return 0;
  1267. }
  1268. static void bnx2x_hw_enable_status(struct bnx2x *bp)
  1269. {
  1270. u32 val;
  1271. val = REG_RD(bp, CFC_REG_WEAK_ENABLE_PF);
  1272. DP(BNX2X_MSG_SP, "CFC_REG_WEAK_ENABLE_PF is 0x%x\n", val);
  1273. val = REG_RD(bp, PBF_REG_DISABLE_PF);
  1274. DP(BNX2X_MSG_SP, "PBF_REG_DISABLE_PF is 0x%x\n", val);
  1275. val = REG_RD(bp, IGU_REG_PCI_PF_MSI_EN);
  1276. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSI_EN is 0x%x\n", val);
  1277. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_EN);
  1278. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_EN is 0x%x\n", val);
  1279. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_FUNC_MASK);
  1280. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_FUNC_MASK is 0x%x\n", val);
  1281. val = REG_RD(bp, PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR);
  1282. DP(BNX2X_MSG_SP, "PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR is 0x%x\n", val);
  1283. val = REG_RD(bp, PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR);
  1284. DP(BNX2X_MSG_SP, "PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR is 0x%x\n", val);
  1285. val = REG_RD(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
  1286. DP(BNX2X_MSG_SP, "PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER is 0x%x\n",
  1287. val);
  1288. }
  1289. static int bnx2x_pf_flr_clnup(struct bnx2x *bp)
  1290. {
  1291. u32 poll_cnt = bnx2x_flr_clnup_poll_count(bp);
  1292. DP(BNX2X_MSG_SP, "Cleanup after FLR PF[%d]\n", BP_ABS_FUNC(bp));
  1293. /* Re-enable PF target read access */
  1294. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  1295. /* Poll HW usage counters */
  1296. DP(BNX2X_MSG_SP, "Polling usage counters\n");
  1297. if (bnx2x_poll_hw_usage_counters(bp, poll_cnt))
  1298. return -EBUSY;
  1299. /* Zero the igu 'trailing edge' and 'leading edge' */
  1300. /* Send the FW cleanup command */
  1301. if (bnx2x_send_final_clnup(bp, (u8)BP_FUNC(bp), poll_cnt))
  1302. return -EBUSY;
  1303. /* ATC cleanup */
  1304. /* Verify TX hw is flushed */
  1305. bnx2x_tx_hw_flushed(bp, poll_cnt);
  1306. /* Wait 100ms (not adjusted according to platform) */
  1307. msleep(100);
  1308. /* Verify no pending pci transactions */
  1309. if (bnx2x_is_pcie_pending(bp->pdev))
  1310. BNX2X_ERR("PCIE Transactions still pending\n");
  1311. /* Debug */
  1312. bnx2x_hw_enable_status(bp);
  1313. /*
  1314. * Master enable - Due to WB DMAE writes performed before this
  1315. * register is re-initialized as part of the regular function init
  1316. */
  1317. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  1318. return 0;
  1319. }
  1320. static void bnx2x_hc_int_enable(struct bnx2x *bp)
  1321. {
  1322. int port = BP_PORT(bp);
  1323. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  1324. u32 val = REG_RD(bp, addr);
  1325. bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
  1326. bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
  1327. bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
  1328. if (msix) {
  1329. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1330. HC_CONFIG_0_REG_INT_LINE_EN_0);
  1331. val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1332. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1333. if (single_msix)
  1334. val |= HC_CONFIG_0_REG_SINGLE_ISR_EN_0;
  1335. } else if (msi) {
  1336. val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0;
  1337. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1338. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1339. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1340. } else {
  1341. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1342. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1343. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  1344. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1345. if (!CHIP_IS_E1(bp)) {
  1346. DP(NETIF_MSG_IFUP,
  1347. "write %x to HC %d (addr 0x%x)\n", val, port, addr);
  1348. REG_WR(bp, addr, val);
  1349. val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0;
  1350. }
  1351. }
  1352. if (CHIP_IS_E1(bp))
  1353. REG_WR(bp, HC_REG_INT_MASK + port*4, 0x1FFFF);
  1354. DP(NETIF_MSG_IFUP,
  1355. "write %x to HC %d (addr 0x%x) mode %s\n", val, port, addr,
  1356. (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1357. REG_WR(bp, addr, val);
  1358. /*
  1359. * Ensure that HC_CONFIG is written before leading/trailing edge config
  1360. */
  1361. mmiowb();
  1362. barrier();
  1363. if (!CHIP_IS_E1(bp)) {
  1364. /* init leading/trailing edge */
  1365. if (IS_MF(bp)) {
  1366. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1367. if (bp->port.pmf)
  1368. /* enable nig and gpio3 attention */
  1369. val |= 0x1100;
  1370. } else
  1371. val = 0xffff;
  1372. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  1373. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  1374. }
  1375. /* Make sure that interrupts are indeed enabled from here on */
  1376. mmiowb();
  1377. }
  1378. static void bnx2x_igu_int_enable(struct bnx2x *bp)
  1379. {
  1380. u32 val;
  1381. bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
  1382. bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
  1383. bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
  1384. val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  1385. if (msix) {
  1386. val &= ~(IGU_PF_CONF_INT_LINE_EN |
  1387. IGU_PF_CONF_SINGLE_ISR_EN);
  1388. val |= (IGU_PF_CONF_MSI_MSIX_EN |
  1389. IGU_PF_CONF_ATTN_BIT_EN);
  1390. if (single_msix)
  1391. val |= IGU_PF_CONF_SINGLE_ISR_EN;
  1392. } else if (msi) {
  1393. val &= ~IGU_PF_CONF_INT_LINE_EN;
  1394. val |= (IGU_PF_CONF_MSI_MSIX_EN |
  1395. IGU_PF_CONF_ATTN_BIT_EN |
  1396. IGU_PF_CONF_SINGLE_ISR_EN);
  1397. } else {
  1398. val &= ~IGU_PF_CONF_MSI_MSIX_EN;
  1399. val |= (IGU_PF_CONF_INT_LINE_EN |
  1400. IGU_PF_CONF_ATTN_BIT_EN |
  1401. IGU_PF_CONF_SINGLE_ISR_EN);
  1402. }
  1403. /* Clean previous status - need to configure igu prior to ack*/
  1404. if ((!msix) || single_msix) {
  1405. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1406. bnx2x_ack_int(bp);
  1407. }
  1408. val |= IGU_PF_CONF_FUNC_EN;
  1409. DP(NETIF_MSG_IFUP, "write 0x%x to IGU mode %s\n",
  1410. val, (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1411. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1412. if (val & IGU_PF_CONF_INT_LINE_EN)
  1413. pci_intx(bp->pdev, true);
  1414. barrier();
  1415. /* init leading/trailing edge */
  1416. if (IS_MF(bp)) {
  1417. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1418. if (bp->port.pmf)
  1419. /* enable nig and gpio3 attention */
  1420. val |= 0x1100;
  1421. } else
  1422. val = 0xffff;
  1423. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  1424. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  1425. /* Make sure that interrupts are indeed enabled from here on */
  1426. mmiowb();
  1427. }
  1428. void bnx2x_int_enable(struct bnx2x *bp)
  1429. {
  1430. if (bp->common.int_block == INT_BLOCK_HC)
  1431. bnx2x_hc_int_enable(bp);
  1432. else
  1433. bnx2x_igu_int_enable(bp);
  1434. }
  1435. void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw)
  1436. {
  1437. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  1438. int i, offset;
  1439. if (disable_hw)
  1440. /* prevent the HW from sending interrupts */
  1441. bnx2x_int_disable(bp);
  1442. /* make sure all ISRs are done */
  1443. if (msix) {
  1444. synchronize_irq(bp->msix_table[0].vector);
  1445. offset = 1;
  1446. if (CNIC_SUPPORT(bp))
  1447. offset++;
  1448. for_each_eth_queue(bp, i)
  1449. synchronize_irq(bp->msix_table[offset++].vector);
  1450. } else
  1451. synchronize_irq(bp->pdev->irq);
  1452. /* make sure sp_task is not running */
  1453. cancel_delayed_work(&bp->sp_task);
  1454. cancel_delayed_work(&bp->period_task);
  1455. flush_workqueue(bnx2x_wq);
  1456. }
  1457. /* fast path */
  1458. /*
  1459. * General service functions
  1460. */
  1461. /* Return true if succeeded to acquire the lock */
  1462. static bool bnx2x_trylock_hw_lock(struct bnx2x *bp, u32 resource)
  1463. {
  1464. u32 lock_status;
  1465. u32 resource_bit = (1 << resource);
  1466. int func = BP_FUNC(bp);
  1467. u32 hw_lock_control_reg;
  1468. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1469. "Trying to take a lock on resource %d\n", resource);
  1470. /* Validating that the resource is within range */
  1471. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1472. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1473. "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1474. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1475. return false;
  1476. }
  1477. if (func <= 5)
  1478. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1479. else
  1480. hw_lock_control_reg =
  1481. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1482. /* Try to acquire the lock */
  1483. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1484. lock_status = REG_RD(bp, hw_lock_control_reg);
  1485. if (lock_status & resource_bit)
  1486. return true;
  1487. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1488. "Failed to get a lock on resource %d\n", resource);
  1489. return false;
  1490. }
  1491. /**
  1492. * bnx2x_get_leader_lock_resource - get the recovery leader resource id
  1493. *
  1494. * @bp: driver handle
  1495. *
  1496. * Returns the recovery leader resource id according to the engine this function
  1497. * belongs to. Currently only only 2 engines is supported.
  1498. */
  1499. static int bnx2x_get_leader_lock_resource(struct bnx2x *bp)
  1500. {
  1501. if (BP_PATH(bp))
  1502. return HW_LOCK_RESOURCE_RECOVERY_LEADER_1;
  1503. else
  1504. return HW_LOCK_RESOURCE_RECOVERY_LEADER_0;
  1505. }
  1506. /**
  1507. * bnx2x_trylock_leader_lock- try to acquire a leader lock.
  1508. *
  1509. * @bp: driver handle
  1510. *
  1511. * Tries to acquire a leader lock for current engine.
  1512. */
  1513. static bool bnx2x_trylock_leader_lock(struct bnx2x *bp)
  1514. {
  1515. return bnx2x_trylock_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1516. }
  1517. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err);
  1518. /* schedule the sp task and mark that interrupt occurred (runs from ISR) */
  1519. static int bnx2x_schedule_sp_task(struct bnx2x *bp)
  1520. {
  1521. /* Set the interrupt occurred bit for the sp-task to recognize it
  1522. * must ack the interrupt and transition according to the IGU
  1523. * state machine.
  1524. */
  1525. atomic_set(&bp->interrupt_occurred, 1);
  1526. /* The sp_task must execute only after this bit
  1527. * is set, otherwise we will get out of sync and miss all
  1528. * further interrupts. Hence, the barrier.
  1529. */
  1530. smp_wmb();
  1531. /* schedule sp_task to workqueue */
  1532. return queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
  1533. }
  1534. void bnx2x_sp_event(struct bnx2x_fastpath *fp, union eth_rx_cqe *rr_cqe)
  1535. {
  1536. struct bnx2x *bp = fp->bp;
  1537. int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1538. int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1539. enum bnx2x_queue_cmd drv_cmd = BNX2X_Q_CMD_MAX;
  1540. struct bnx2x_queue_sp_obj *q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  1541. DP(BNX2X_MSG_SP,
  1542. "fp %d cid %d got ramrod #%d state is %x type is %d\n",
  1543. fp->index, cid, command, bp->state,
  1544. rr_cqe->ramrod_cqe.ramrod_type);
  1545. /* If cid is within VF range, replace the slowpath object with the
  1546. * one corresponding to this VF
  1547. */
  1548. if (cid >= BNX2X_FIRST_VF_CID &&
  1549. cid < BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)
  1550. bnx2x_iov_set_queue_sp_obj(bp, cid, &q_obj);
  1551. switch (command) {
  1552. case (RAMROD_CMD_ID_ETH_CLIENT_UPDATE):
  1553. DP(BNX2X_MSG_SP, "got UPDATE ramrod. CID %d\n", cid);
  1554. drv_cmd = BNX2X_Q_CMD_UPDATE;
  1555. break;
  1556. case (RAMROD_CMD_ID_ETH_CLIENT_SETUP):
  1557. DP(BNX2X_MSG_SP, "got MULTI[%d] setup ramrod\n", cid);
  1558. drv_cmd = BNX2X_Q_CMD_SETUP;
  1559. break;
  1560. case (RAMROD_CMD_ID_ETH_TX_QUEUE_SETUP):
  1561. DP(BNX2X_MSG_SP, "got MULTI[%d] tx-only setup ramrod\n", cid);
  1562. drv_cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  1563. break;
  1564. case (RAMROD_CMD_ID_ETH_HALT):
  1565. DP(BNX2X_MSG_SP, "got MULTI[%d] halt ramrod\n", cid);
  1566. drv_cmd = BNX2X_Q_CMD_HALT;
  1567. break;
  1568. case (RAMROD_CMD_ID_ETH_TERMINATE):
  1569. DP(BNX2X_MSG_SP, "got MULTI[%d] terminate ramrod\n", cid);
  1570. drv_cmd = BNX2X_Q_CMD_TERMINATE;
  1571. break;
  1572. case (RAMROD_CMD_ID_ETH_EMPTY):
  1573. DP(BNX2X_MSG_SP, "got MULTI[%d] empty ramrod\n", cid);
  1574. drv_cmd = BNX2X_Q_CMD_EMPTY;
  1575. break;
  1576. case (RAMROD_CMD_ID_ETH_TPA_UPDATE):
  1577. DP(BNX2X_MSG_SP, "got tpa update ramrod CID=%d\n", cid);
  1578. drv_cmd = BNX2X_Q_CMD_UPDATE_TPA;
  1579. break;
  1580. default:
  1581. BNX2X_ERR("unexpected MC reply (%d) on fp[%d]\n",
  1582. command, fp->index);
  1583. return;
  1584. }
  1585. if ((drv_cmd != BNX2X_Q_CMD_MAX) &&
  1586. q_obj->complete_cmd(bp, q_obj, drv_cmd))
  1587. /* q_obj->complete_cmd() failure means that this was
  1588. * an unexpected completion.
  1589. *
  1590. * In this case we don't want to increase the bp->spq_left
  1591. * because apparently we haven't sent this command the first
  1592. * place.
  1593. */
  1594. #ifdef BNX2X_STOP_ON_ERROR
  1595. bnx2x_panic();
  1596. #else
  1597. return;
  1598. #endif
  1599. smp_mb__before_atomic();
  1600. atomic_inc(&bp->cq_spq_left);
  1601. /* push the change in bp->spq_left and towards the memory */
  1602. smp_mb__after_atomic();
  1603. DP(BNX2X_MSG_SP, "bp->cq_spq_left %x\n", atomic_read(&bp->cq_spq_left));
  1604. if ((drv_cmd == BNX2X_Q_CMD_UPDATE) && (IS_FCOE_FP(fp)) &&
  1605. (!!test_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state))) {
  1606. /* if Q update ramrod is completed for last Q in AFEX vif set
  1607. * flow, then ACK MCP at the end
  1608. *
  1609. * mark pending ACK to MCP bit.
  1610. * prevent case that both bits are cleared.
  1611. * At the end of load/unload driver checks that
  1612. * sp_state is cleared, and this order prevents
  1613. * races
  1614. */
  1615. smp_mb__before_atomic();
  1616. set_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK, &bp->sp_state);
  1617. wmb();
  1618. clear_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
  1619. smp_mb__after_atomic();
  1620. /* schedule the sp task as mcp ack is required */
  1621. bnx2x_schedule_sp_task(bp);
  1622. }
  1623. return;
  1624. }
  1625. irqreturn_t bnx2x_interrupt(int irq, void *dev_instance)
  1626. {
  1627. struct bnx2x *bp = netdev_priv(dev_instance);
  1628. u16 status = bnx2x_ack_int(bp);
  1629. u16 mask;
  1630. int i;
  1631. u8 cos;
  1632. /* Return here if interrupt is shared and it's not for us */
  1633. if (unlikely(status == 0)) {
  1634. DP(NETIF_MSG_INTR, "not our interrupt!\n");
  1635. return IRQ_NONE;
  1636. }
  1637. DP(NETIF_MSG_INTR, "got an interrupt status 0x%x\n", status);
  1638. #ifdef BNX2X_STOP_ON_ERROR
  1639. if (unlikely(bp->panic))
  1640. return IRQ_HANDLED;
  1641. #endif
  1642. for_each_eth_queue(bp, i) {
  1643. struct bnx2x_fastpath *fp = &bp->fp[i];
  1644. mask = 0x2 << (fp->index + CNIC_SUPPORT(bp));
  1645. if (status & mask) {
  1646. /* Handle Rx or Tx according to SB id */
  1647. for_each_cos_in_tx_queue(fp, cos)
  1648. prefetch(fp->txdata_ptr[cos]->tx_cons_sb);
  1649. prefetch(&fp->sb_running_index[SM_RX_ID]);
  1650. napi_schedule(&bnx2x_fp(bp, fp->index, napi));
  1651. status &= ~mask;
  1652. }
  1653. }
  1654. if (CNIC_SUPPORT(bp)) {
  1655. mask = 0x2;
  1656. if (status & (mask | 0x1)) {
  1657. struct cnic_ops *c_ops = NULL;
  1658. rcu_read_lock();
  1659. c_ops = rcu_dereference(bp->cnic_ops);
  1660. if (c_ops && (bp->cnic_eth_dev.drv_state &
  1661. CNIC_DRV_STATE_HANDLES_IRQ))
  1662. c_ops->cnic_handler(bp->cnic_data, NULL);
  1663. rcu_read_unlock();
  1664. status &= ~mask;
  1665. }
  1666. }
  1667. if (unlikely(status & 0x1)) {
  1668. /* schedule sp task to perform default status block work, ack
  1669. * attentions and enable interrupts.
  1670. */
  1671. bnx2x_schedule_sp_task(bp);
  1672. status &= ~0x1;
  1673. if (!status)
  1674. return IRQ_HANDLED;
  1675. }
  1676. if (unlikely(status))
  1677. DP(NETIF_MSG_INTR, "got an unknown interrupt! (status 0x%x)\n",
  1678. status);
  1679. return IRQ_HANDLED;
  1680. }
  1681. /* Link */
  1682. /*
  1683. * General service functions
  1684. */
  1685. int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource)
  1686. {
  1687. u32 lock_status;
  1688. u32 resource_bit = (1 << resource);
  1689. int func = BP_FUNC(bp);
  1690. u32 hw_lock_control_reg;
  1691. int cnt;
  1692. /* Validating that the resource is within range */
  1693. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1694. BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1695. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1696. return -EINVAL;
  1697. }
  1698. if (func <= 5) {
  1699. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1700. } else {
  1701. hw_lock_control_reg =
  1702. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1703. }
  1704. /* Validating that the resource is not already taken */
  1705. lock_status = REG_RD(bp, hw_lock_control_reg);
  1706. if (lock_status & resource_bit) {
  1707. BNX2X_ERR("lock_status 0x%x resource_bit 0x%x\n",
  1708. lock_status, resource_bit);
  1709. return -EEXIST;
  1710. }
  1711. /* Try for 5 second every 5ms */
  1712. for (cnt = 0; cnt < 1000; cnt++) {
  1713. /* Try to acquire the lock */
  1714. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1715. lock_status = REG_RD(bp, hw_lock_control_reg);
  1716. if (lock_status & resource_bit)
  1717. return 0;
  1718. usleep_range(5000, 10000);
  1719. }
  1720. BNX2X_ERR("Timeout\n");
  1721. return -EAGAIN;
  1722. }
  1723. int bnx2x_release_leader_lock(struct bnx2x *bp)
  1724. {
  1725. return bnx2x_release_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1726. }
  1727. int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource)
  1728. {
  1729. u32 lock_status;
  1730. u32 resource_bit = (1 << resource);
  1731. int func = BP_FUNC(bp);
  1732. u32 hw_lock_control_reg;
  1733. /* Validating that the resource is within range */
  1734. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1735. BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1736. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1737. return -EINVAL;
  1738. }
  1739. if (func <= 5) {
  1740. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1741. } else {
  1742. hw_lock_control_reg =
  1743. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1744. }
  1745. /* Validating that the resource is currently taken */
  1746. lock_status = REG_RD(bp, hw_lock_control_reg);
  1747. if (!(lock_status & resource_bit)) {
  1748. BNX2X_ERR("lock_status 0x%x resource_bit 0x%x. Unlock was called but lock wasn't taken!\n",
  1749. lock_status, resource_bit);
  1750. return -EFAULT;
  1751. }
  1752. REG_WR(bp, hw_lock_control_reg, resource_bit);
  1753. return 0;
  1754. }
  1755. int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port)
  1756. {
  1757. /* The GPIO should be swapped if swap register is set and active */
  1758. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1759. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1760. int gpio_shift = gpio_num +
  1761. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1762. u32 gpio_mask = (1 << gpio_shift);
  1763. u32 gpio_reg;
  1764. int value;
  1765. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1766. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1767. return -EINVAL;
  1768. }
  1769. /* read GPIO value */
  1770. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1771. /* get the requested pin value */
  1772. if ((gpio_reg & gpio_mask) == gpio_mask)
  1773. value = 1;
  1774. else
  1775. value = 0;
  1776. return value;
  1777. }
  1778. int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1779. {
  1780. /* The GPIO should be swapped if swap register is set and active */
  1781. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1782. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1783. int gpio_shift = gpio_num +
  1784. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1785. u32 gpio_mask = (1 << gpio_shift);
  1786. u32 gpio_reg;
  1787. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1788. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1789. return -EINVAL;
  1790. }
  1791. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1792. /* read GPIO and mask except the float bits */
  1793. gpio_reg = (REG_RD(bp, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT);
  1794. switch (mode) {
  1795. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1796. DP(NETIF_MSG_LINK,
  1797. "Set GPIO %d (shift %d) -> output low\n",
  1798. gpio_num, gpio_shift);
  1799. /* clear FLOAT and set CLR */
  1800. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1801. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS);
  1802. break;
  1803. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1804. DP(NETIF_MSG_LINK,
  1805. "Set GPIO %d (shift %d) -> output high\n",
  1806. gpio_num, gpio_shift);
  1807. /* clear FLOAT and set SET */
  1808. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1809. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS);
  1810. break;
  1811. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1812. DP(NETIF_MSG_LINK,
  1813. "Set GPIO %d (shift %d) -> input\n",
  1814. gpio_num, gpio_shift);
  1815. /* set FLOAT */
  1816. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1817. break;
  1818. default:
  1819. break;
  1820. }
  1821. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1822. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1823. return 0;
  1824. }
  1825. int bnx2x_set_mult_gpio(struct bnx2x *bp, u8 pins, u32 mode)
  1826. {
  1827. u32 gpio_reg = 0;
  1828. int rc = 0;
  1829. /* Any port swapping should be handled by caller. */
  1830. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1831. /* read GPIO and mask except the float bits */
  1832. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1833. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1834. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_CLR_POS);
  1835. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_SET_POS);
  1836. switch (mode) {
  1837. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1838. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output low\n", pins);
  1839. /* set CLR */
  1840. gpio_reg |= (pins << MISC_REGISTERS_GPIO_CLR_POS);
  1841. break;
  1842. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1843. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output high\n", pins);
  1844. /* set SET */
  1845. gpio_reg |= (pins << MISC_REGISTERS_GPIO_SET_POS);
  1846. break;
  1847. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1848. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> input\n", pins);
  1849. /* set FLOAT */
  1850. gpio_reg |= (pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1851. break;
  1852. default:
  1853. BNX2X_ERR("Invalid GPIO mode assignment %d\n", mode);
  1854. rc = -EINVAL;
  1855. break;
  1856. }
  1857. if (rc == 0)
  1858. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1859. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1860. return rc;
  1861. }
  1862. int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1863. {
  1864. /* The GPIO should be swapped if swap register is set and active */
  1865. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1866. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1867. int gpio_shift = gpio_num +
  1868. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1869. u32 gpio_mask = (1 << gpio_shift);
  1870. u32 gpio_reg;
  1871. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1872. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1873. return -EINVAL;
  1874. }
  1875. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1876. /* read GPIO int */
  1877. gpio_reg = REG_RD(bp, MISC_REG_GPIO_INT);
  1878. switch (mode) {
  1879. case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR:
  1880. DP(NETIF_MSG_LINK,
  1881. "Clear GPIO INT %d (shift %d) -> output low\n",
  1882. gpio_num, gpio_shift);
  1883. /* clear SET and set CLR */
  1884. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1885. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1886. break;
  1887. case MISC_REGISTERS_GPIO_INT_OUTPUT_SET:
  1888. DP(NETIF_MSG_LINK,
  1889. "Set GPIO INT %d (shift %d) -> output high\n",
  1890. gpio_num, gpio_shift);
  1891. /* clear CLR and set SET */
  1892. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1893. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1894. break;
  1895. default:
  1896. break;
  1897. }
  1898. REG_WR(bp, MISC_REG_GPIO_INT, gpio_reg);
  1899. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1900. return 0;
  1901. }
  1902. static int bnx2x_set_spio(struct bnx2x *bp, int spio, u32 mode)
  1903. {
  1904. u32 spio_reg;
  1905. /* Only 2 SPIOs are configurable */
  1906. if ((spio != MISC_SPIO_SPIO4) && (spio != MISC_SPIO_SPIO5)) {
  1907. BNX2X_ERR("Invalid SPIO 0x%x\n", spio);
  1908. return -EINVAL;
  1909. }
  1910. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1911. /* read SPIO and mask except the float bits */
  1912. spio_reg = (REG_RD(bp, MISC_REG_SPIO) & MISC_SPIO_FLOAT);
  1913. switch (mode) {
  1914. case MISC_SPIO_OUTPUT_LOW:
  1915. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output low\n", spio);
  1916. /* clear FLOAT and set CLR */
  1917. spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
  1918. spio_reg |= (spio << MISC_SPIO_CLR_POS);
  1919. break;
  1920. case MISC_SPIO_OUTPUT_HIGH:
  1921. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output high\n", spio);
  1922. /* clear FLOAT and set SET */
  1923. spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
  1924. spio_reg |= (spio << MISC_SPIO_SET_POS);
  1925. break;
  1926. case MISC_SPIO_INPUT_HI_Z:
  1927. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> input\n", spio);
  1928. /* set FLOAT */
  1929. spio_reg |= (spio << MISC_SPIO_FLOAT_POS);
  1930. break;
  1931. default:
  1932. break;
  1933. }
  1934. REG_WR(bp, MISC_REG_SPIO, spio_reg);
  1935. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1936. return 0;
  1937. }
  1938. void bnx2x_calc_fc_adv(struct bnx2x *bp)
  1939. {
  1940. u8 cfg_idx = bnx2x_get_link_cfg_idx(bp);
  1941. switch (bp->link_vars.ieee_fc &
  1942. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) {
  1943. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE:
  1944. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1945. ADVERTISED_Pause);
  1946. break;
  1947. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH:
  1948. bp->port.advertising[cfg_idx] |= (ADVERTISED_Asym_Pause |
  1949. ADVERTISED_Pause);
  1950. break;
  1951. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC:
  1952. bp->port.advertising[cfg_idx] |= ADVERTISED_Asym_Pause;
  1953. break;
  1954. default:
  1955. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1956. ADVERTISED_Pause);
  1957. break;
  1958. }
  1959. }
  1960. static void bnx2x_set_requested_fc(struct bnx2x *bp)
  1961. {
  1962. /* Initialize link parameters structure variables
  1963. * It is recommended to turn off RX FC for jumbo frames
  1964. * for better performance
  1965. */
  1966. if (CHIP_IS_E1x(bp) && (bp->dev->mtu > 5000))
  1967. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_TX;
  1968. else
  1969. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH;
  1970. }
  1971. static void bnx2x_init_dropless_fc(struct bnx2x *bp)
  1972. {
  1973. u32 pause_enabled = 0;
  1974. if (!CHIP_IS_E1(bp) && bp->dropless_fc && bp->link_vars.link_up) {
  1975. if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX)
  1976. pause_enabled = 1;
  1977. REG_WR(bp, BAR_USTRORM_INTMEM +
  1978. USTORM_ETH_PAUSE_ENABLED_OFFSET(BP_PORT(bp)),
  1979. pause_enabled);
  1980. }
  1981. DP(NETIF_MSG_IFUP | NETIF_MSG_LINK, "dropless_fc is %s\n",
  1982. pause_enabled ? "enabled" : "disabled");
  1983. }
  1984. int bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode)
  1985. {
  1986. int rc, cfx_idx = bnx2x_get_link_cfg_idx(bp);
  1987. u16 req_line_speed = bp->link_params.req_line_speed[cfx_idx];
  1988. if (!BP_NOMCP(bp)) {
  1989. bnx2x_set_requested_fc(bp);
  1990. bnx2x_acquire_phy_lock(bp);
  1991. if (load_mode == LOAD_DIAG) {
  1992. struct link_params *lp = &bp->link_params;
  1993. lp->loopback_mode = LOOPBACK_XGXS;
  1994. /* do PHY loopback at 10G speed, if possible */
  1995. if (lp->req_line_speed[cfx_idx] < SPEED_10000) {
  1996. if (lp->speed_cap_mask[cfx_idx] &
  1997. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
  1998. lp->req_line_speed[cfx_idx] =
  1999. SPEED_10000;
  2000. else
  2001. lp->req_line_speed[cfx_idx] =
  2002. SPEED_1000;
  2003. }
  2004. }
  2005. if (load_mode == LOAD_LOOPBACK_EXT) {
  2006. struct link_params *lp = &bp->link_params;
  2007. lp->loopback_mode = LOOPBACK_EXT;
  2008. }
  2009. rc = bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  2010. bnx2x_release_phy_lock(bp);
  2011. bnx2x_init_dropless_fc(bp);
  2012. bnx2x_calc_fc_adv(bp);
  2013. if (bp->link_vars.link_up) {
  2014. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2015. bnx2x_link_report(bp);
  2016. }
  2017. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  2018. bp->link_params.req_line_speed[cfx_idx] = req_line_speed;
  2019. return rc;
  2020. }
  2021. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  2022. return -EINVAL;
  2023. }
  2024. void bnx2x_link_set(struct bnx2x *bp)
  2025. {
  2026. if (!BP_NOMCP(bp)) {
  2027. bnx2x_acquire_phy_lock(bp);
  2028. bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  2029. bnx2x_release_phy_lock(bp);
  2030. bnx2x_init_dropless_fc(bp);
  2031. bnx2x_calc_fc_adv(bp);
  2032. } else
  2033. BNX2X_ERR("Bootcode is missing - can not set link\n");
  2034. }
  2035. static void bnx2x__link_reset(struct bnx2x *bp)
  2036. {
  2037. if (!BP_NOMCP(bp)) {
  2038. bnx2x_acquire_phy_lock(bp);
  2039. bnx2x_lfa_reset(&bp->link_params, &bp->link_vars);
  2040. bnx2x_release_phy_lock(bp);
  2041. } else
  2042. BNX2X_ERR("Bootcode is missing - can not reset link\n");
  2043. }
  2044. void bnx2x_force_link_reset(struct bnx2x *bp)
  2045. {
  2046. bnx2x_acquire_phy_lock(bp);
  2047. bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
  2048. bnx2x_release_phy_lock(bp);
  2049. }
  2050. u8 bnx2x_link_test(struct bnx2x *bp, u8 is_serdes)
  2051. {
  2052. u8 rc = 0;
  2053. if (!BP_NOMCP(bp)) {
  2054. bnx2x_acquire_phy_lock(bp);
  2055. rc = bnx2x_test_link(&bp->link_params, &bp->link_vars,
  2056. is_serdes);
  2057. bnx2x_release_phy_lock(bp);
  2058. } else
  2059. BNX2X_ERR("Bootcode is missing - can not test link\n");
  2060. return rc;
  2061. }
  2062. /* Calculates the sum of vn_min_rates.
  2063. It's needed for further normalizing of the min_rates.
  2064. Returns:
  2065. sum of vn_min_rates.
  2066. or
  2067. 0 - if all the min_rates are 0.
  2068. In the later case fairness algorithm should be deactivated.
  2069. If not all min_rates are zero then those that are zeroes will be set to 1.
  2070. */
  2071. static void bnx2x_calc_vn_min(struct bnx2x *bp,
  2072. struct cmng_init_input *input)
  2073. {
  2074. int all_zero = 1;
  2075. int vn;
  2076. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2077. u32 vn_cfg = bp->mf_config[vn];
  2078. u32 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
  2079. FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
  2080. /* Skip hidden vns */
  2081. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  2082. vn_min_rate = 0;
  2083. /* If min rate is zero - set it to 1 */
  2084. else if (!vn_min_rate)
  2085. vn_min_rate = DEF_MIN_RATE;
  2086. else
  2087. all_zero = 0;
  2088. input->vnic_min_rate[vn] = vn_min_rate;
  2089. }
  2090. /* if ETS or all min rates are zeros - disable fairness */
  2091. if (BNX2X_IS_ETS_ENABLED(bp)) {
  2092. input->flags.cmng_enables &=
  2093. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2094. DP(NETIF_MSG_IFUP, "Fairness will be disabled due to ETS\n");
  2095. } else if (all_zero) {
  2096. input->flags.cmng_enables &=
  2097. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2098. DP(NETIF_MSG_IFUP,
  2099. "All MIN values are zeroes fairness will be disabled\n");
  2100. } else
  2101. input->flags.cmng_enables |=
  2102. CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2103. }
  2104. static void bnx2x_calc_vn_max(struct bnx2x *bp, int vn,
  2105. struct cmng_init_input *input)
  2106. {
  2107. u16 vn_max_rate;
  2108. u32 vn_cfg = bp->mf_config[vn];
  2109. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  2110. vn_max_rate = 0;
  2111. else {
  2112. u32 maxCfg = bnx2x_extract_max_cfg(bp, vn_cfg);
  2113. if (IS_MF_SI(bp)) {
  2114. /* maxCfg in percents of linkspeed */
  2115. vn_max_rate = (bp->link_vars.line_speed * maxCfg) / 100;
  2116. } else /* SD modes */
  2117. /* maxCfg is absolute in 100Mb units */
  2118. vn_max_rate = maxCfg * 100;
  2119. }
  2120. DP(NETIF_MSG_IFUP, "vn %d: vn_max_rate %d\n", vn, vn_max_rate);
  2121. input->vnic_max_rate[vn] = vn_max_rate;
  2122. }
  2123. static int bnx2x_get_cmng_fns_mode(struct bnx2x *bp)
  2124. {
  2125. if (CHIP_REV_IS_SLOW(bp))
  2126. return CMNG_FNS_NONE;
  2127. if (IS_MF(bp))
  2128. return CMNG_FNS_MINMAX;
  2129. return CMNG_FNS_NONE;
  2130. }
  2131. void bnx2x_read_mf_cfg(struct bnx2x *bp)
  2132. {
  2133. int vn, n = (CHIP_MODE_IS_4_PORT(bp) ? 2 : 1);
  2134. if (BP_NOMCP(bp))
  2135. return; /* what should be the default value in this case */
  2136. /* For 2 port configuration the absolute function number formula
  2137. * is:
  2138. * abs_func = 2 * vn + BP_PORT + BP_PATH
  2139. *
  2140. * and there are 4 functions per port
  2141. *
  2142. * For 4 port configuration it is
  2143. * abs_func = 4 * vn + 2 * BP_PORT + BP_PATH
  2144. *
  2145. * and there are 2 functions per port
  2146. */
  2147. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2148. int /*abs*/func = n * (2 * vn + BP_PORT(bp)) + BP_PATH(bp);
  2149. if (func >= E1H_FUNC_MAX)
  2150. break;
  2151. bp->mf_config[vn] =
  2152. MF_CFG_RD(bp, func_mf_config[func].config);
  2153. }
  2154. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  2155. DP(NETIF_MSG_IFUP, "mf_cfg function disabled\n");
  2156. bp->flags |= MF_FUNC_DIS;
  2157. } else {
  2158. DP(NETIF_MSG_IFUP, "mf_cfg function enabled\n");
  2159. bp->flags &= ~MF_FUNC_DIS;
  2160. }
  2161. }
  2162. static void bnx2x_cmng_fns_init(struct bnx2x *bp, u8 read_cfg, u8 cmng_type)
  2163. {
  2164. struct cmng_init_input input;
  2165. memset(&input, 0, sizeof(struct cmng_init_input));
  2166. input.port_rate = bp->link_vars.line_speed;
  2167. if (cmng_type == CMNG_FNS_MINMAX && input.port_rate) {
  2168. int vn;
  2169. /* read mf conf from shmem */
  2170. if (read_cfg)
  2171. bnx2x_read_mf_cfg(bp);
  2172. /* vn_weight_sum and enable fairness if not 0 */
  2173. bnx2x_calc_vn_min(bp, &input);
  2174. /* calculate and set min-max rate for each vn */
  2175. if (bp->port.pmf)
  2176. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++)
  2177. bnx2x_calc_vn_max(bp, vn, &input);
  2178. /* always enable rate shaping and fairness */
  2179. input.flags.cmng_enables |=
  2180. CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN;
  2181. bnx2x_init_cmng(&input, &bp->cmng);
  2182. return;
  2183. }
  2184. /* rate shaping and fairness are disabled */
  2185. DP(NETIF_MSG_IFUP,
  2186. "rate shaping and fairness are disabled\n");
  2187. }
  2188. static void storm_memset_cmng(struct bnx2x *bp,
  2189. struct cmng_init *cmng,
  2190. u8 port)
  2191. {
  2192. int vn;
  2193. size_t size = sizeof(struct cmng_struct_per_port);
  2194. u32 addr = BAR_XSTRORM_INTMEM +
  2195. XSTORM_CMNG_PER_PORT_VARS_OFFSET(port);
  2196. __storm_memset_struct(bp, addr, size, (u32 *)&cmng->port);
  2197. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2198. int func = func_by_vn(bp, vn);
  2199. addr = BAR_XSTRORM_INTMEM +
  2200. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func);
  2201. size = sizeof(struct rate_shaping_vars_per_vn);
  2202. __storm_memset_struct(bp, addr, size,
  2203. (u32 *)&cmng->vnic.vnic_max_rate[vn]);
  2204. addr = BAR_XSTRORM_INTMEM +
  2205. XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func);
  2206. size = sizeof(struct fairness_vars_per_vn);
  2207. __storm_memset_struct(bp, addr, size,
  2208. (u32 *)&cmng->vnic.vnic_min_rate[vn]);
  2209. }
  2210. }
  2211. /* init cmng mode in HW according to local configuration */
  2212. void bnx2x_set_local_cmng(struct bnx2x *bp)
  2213. {
  2214. int cmng_fns = bnx2x_get_cmng_fns_mode(bp);
  2215. if (cmng_fns != CMNG_FNS_NONE) {
  2216. bnx2x_cmng_fns_init(bp, false, cmng_fns);
  2217. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2218. } else {
  2219. /* rate shaping and fairness are disabled */
  2220. DP(NETIF_MSG_IFUP,
  2221. "single function mode without fairness\n");
  2222. }
  2223. }
  2224. /* This function is called upon link interrupt */
  2225. static void bnx2x_link_attn(struct bnx2x *bp)
  2226. {
  2227. /* Make sure that we are synced with the current statistics */
  2228. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2229. bnx2x_link_update(&bp->link_params, &bp->link_vars);
  2230. bnx2x_init_dropless_fc(bp);
  2231. if (bp->link_vars.link_up) {
  2232. if (bp->link_vars.mac_type != MAC_TYPE_EMAC) {
  2233. struct host_port_stats *pstats;
  2234. pstats = bnx2x_sp(bp, port_stats);
  2235. /* reset old mac stats */
  2236. memset(&(pstats->mac_stx[0]), 0,
  2237. sizeof(struct mac_stx));
  2238. }
  2239. if (bp->state == BNX2X_STATE_OPEN)
  2240. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2241. }
  2242. if (bp->link_vars.link_up && bp->link_vars.line_speed)
  2243. bnx2x_set_local_cmng(bp);
  2244. __bnx2x_link_report(bp);
  2245. if (IS_MF(bp))
  2246. bnx2x_link_sync_notify(bp);
  2247. }
  2248. void bnx2x__link_status_update(struct bnx2x *bp)
  2249. {
  2250. if (bp->state != BNX2X_STATE_OPEN)
  2251. return;
  2252. /* read updated dcb configuration */
  2253. if (IS_PF(bp)) {
  2254. bnx2x_dcbx_pmf_update(bp);
  2255. bnx2x_link_status_update(&bp->link_params, &bp->link_vars);
  2256. if (bp->link_vars.link_up)
  2257. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2258. else
  2259. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2260. /* indicate link status */
  2261. bnx2x_link_report(bp);
  2262. } else { /* VF */
  2263. bp->port.supported[0] |= (SUPPORTED_10baseT_Half |
  2264. SUPPORTED_10baseT_Full |
  2265. SUPPORTED_100baseT_Half |
  2266. SUPPORTED_100baseT_Full |
  2267. SUPPORTED_1000baseT_Full |
  2268. SUPPORTED_2500baseX_Full |
  2269. SUPPORTED_10000baseT_Full |
  2270. SUPPORTED_TP |
  2271. SUPPORTED_FIBRE |
  2272. SUPPORTED_Autoneg |
  2273. SUPPORTED_Pause |
  2274. SUPPORTED_Asym_Pause);
  2275. bp->port.advertising[0] = bp->port.supported[0];
  2276. bp->link_params.bp = bp;
  2277. bp->link_params.port = BP_PORT(bp);
  2278. bp->link_params.req_duplex[0] = DUPLEX_FULL;
  2279. bp->link_params.req_flow_ctrl[0] = BNX2X_FLOW_CTRL_NONE;
  2280. bp->link_params.req_line_speed[0] = SPEED_10000;
  2281. bp->link_params.speed_cap_mask[0] = 0x7f0000;
  2282. bp->link_params.switch_cfg = SWITCH_CFG_10G;
  2283. bp->link_vars.mac_type = MAC_TYPE_BMAC;
  2284. bp->link_vars.line_speed = SPEED_10000;
  2285. bp->link_vars.link_status =
  2286. (LINK_STATUS_LINK_UP |
  2287. LINK_STATUS_SPEED_AND_DUPLEX_10GTFD);
  2288. bp->link_vars.link_up = 1;
  2289. bp->link_vars.duplex = DUPLEX_FULL;
  2290. bp->link_vars.flow_ctrl = BNX2X_FLOW_CTRL_NONE;
  2291. __bnx2x_link_report(bp);
  2292. bnx2x_sample_bulletin(bp);
  2293. /* if bulletin board did not have an update for link status
  2294. * __bnx2x_link_report will report current status
  2295. * but it will NOT duplicate report in case of already reported
  2296. * during sampling bulletin board.
  2297. */
  2298. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2299. }
  2300. }
  2301. static int bnx2x_afex_func_update(struct bnx2x *bp, u16 vifid,
  2302. u16 vlan_val, u8 allowed_prio)
  2303. {
  2304. struct bnx2x_func_state_params func_params = {NULL};
  2305. struct bnx2x_func_afex_update_params *f_update_params =
  2306. &func_params.params.afex_update;
  2307. func_params.f_obj = &bp->func_obj;
  2308. func_params.cmd = BNX2X_F_CMD_AFEX_UPDATE;
  2309. /* no need to wait for RAMROD completion, so don't
  2310. * set RAMROD_COMP_WAIT flag
  2311. */
  2312. f_update_params->vif_id = vifid;
  2313. f_update_params->afex_default_vlan = vlan_val;
  2314. f_update_params->allowed_priorities = allowed_prio;
  2315. /* if ramrod can not be sent, response to MCP immediately */
  2316. if (bnx2x_func_state_change(bp, &func_params) < 0)
  2317. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  2318. return 0;
  2319. }
  2320. static int bnx2x_afex_handle_vif_list_cmd(struct bnx2x *bp, u8 cmd_type,
  2321. u16 vif_index, u8 func_bit_map)
  2322. {
  2323. struct bnx2x_func_state_params func_params = {NULL};
  2324. struct bnx2x_func_afex_viflists_params *update_params =
  2325. &func_params.params.afex_viflists;
  2326. int rc;
  2327. u32 drv_msg_code;
  2328. /* validate only LIST_SET and LIST_GET are received from switch */
  2329. if ((cmd_type != VIF_LIST_RULE_GET) && (cmd_type != VIF_LIST_RULE_SET))
  2330. BNX2X_ERR("BUG! afex_handle_vif_list_cmd invalid type 0x%x\n",
  2331. cmd_type);
  2332. func_params.f_obj = &bp->func_obj;
  2333. func_params.cmd = BNX2X_F_CMD_AFEX_VIFLISTS;
  2334. /* set parameters according to cmd_type */
  2335. update_params->afex_vif_list_command = cmd_type;
  2336. update_params->vif_list_index = vif_index;
  2337. update_params->func_bit_map =
  2338. (cmd_type == VIF_LIST_RULE_GET) ? 0 : func_bit_map;
  2339. update_params->func_to_clear = 0;
  2340. drv_msg_code =
  2341. (cmd_type == VIF_LIST_RULE_GET) ?
  2342. DRV_MSG_CODE_AFEX_LISTGET_ACK :
  2343. DRV_MSG_CODE_AFEX_LISTSET_ACK;
  2344. /* if ramrod can not be sent, respond to MCP immediately for
  2345. * SET and GET requests (other are not triggered from MCP)
  2346. */
  2347. rc = bnx2x_func_state_change(bp, &func_params);
  2348. if (rc < 0)
  2349. bnx2x_fw_command(bp, drv_msg_code, 0);
  2350. return 0;
  2351. }
  2352. static void bnx2x_handle_afex_cmd(struct bnx2x *bp, u32 cmd)
  2353. {
  2354. struct afex_stats afex_stats;
  2355. u32 func = BP_ABS_FUNC(bp);
  2356. u32 mf_config;
  2357. u16 vlan_val;
  2358. u32 vlan_prio;
  2359. u16 vif_id;
  2360. u8 allowed_prio;
  2361. u8 vlan_mode;
  2362. u32 addr_to_write, vifid, addrs, stats_type, i;
  2363. if (cmd & DRV_STATUS_AFEX_LISTGET_REQ) {
  2364. vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2365. DP(BNX2X_MSG_MCP,
  2366. "afex: got MCP req LISTGET_REQ for vifid 0x%x\n", vifid);
  2367. bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_GET, vifid, 0);
  2368. }
  2369. if (cmd & DRV_STATUS_AFEX_LISTSET_REQ) {
  2370. vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2371. addrs = SHMEM2_RD(bp, afex_param2_to_driver[BP_FW_MB_IDX(bp)]);
  2372. DP(BNX2X_MSG_MCP,
  2373. "afex: got MCP req LISTSET_REQ for vifid 0x%x addrs 0x%x\n",
  2374. vifid, addrs);
  2375. bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_SET, vifid,
  2376. addrs);
  2377. }
  2378. if (cmd & DRV_STATUS_AFEX_STATSGET_REQ) {
  2379. addr_to_write = SHMEM2_RD(bp,
  2380. afex_scratchpad_addr_to_write[BP_FW_MB_IDX(bp)]);
  2381. stats_type = SHMEM2_RD(bp,
  2382. afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2383. DP(BNX2X_MSG_MCP,
  2384. "afex: got MCP req STATSGET_REQ, write to addr 0x%x\n",
  2385. addr_to_write);
  2386. bnx2x_afex_collect_stats(bp, (void *)&afex_stats, stats_type);
  2387. /* write response to scratchpad, for MCP */
  2388. for (i = 0; i < (sizeof(struct afex_stats)/sizeof(u32)); i++)
  2389. REG_WR(bp, addr_to_write + i*sizeof(u32),
  2390. *(((u32 *)(&afex_stats))+i));
  2391. /* send ack message to MCP */
  2392. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_STATSGET_ACK, 0);
  2393. }
  2394. if (cmd & DRV_STATUS_AFEX_VIFSET_REQ) {
  2395. mf_config = MF_CFG_RD(bp, func_mf_config[func].config);
  2396. bp->mf_config[BP_VN(bp)] = mf_config;
  2397. DP(BNX2X_MSG_MCP,
  2398. "afex: got MCP req VIFSET_REQ, mf_config 0x%x\n",
  2399. mf_config);
  2400. /* if VIF_SET is "enabled" */
  2401. if (!(mf_config & FUNC_MF_CFG_FUNC_DISABLED)) {
  2402. /* set rate limit directly to internal RAM */
  2403. struct cmng_init_input cmng_input;
  2404. struct rate_shaping_vars_per_vn m_rs_vn;
  2405. size_t size = sizeof(struct rate_shaping_vars_per_vn);
  2406. u32 addr = BAR_XSTRORM_INTMEM +
  2407. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(BP_FUNC(bp));
  2408. bp->mf_config[BP_VN(bp)] = mf_config;
  2409. bnx2x_calc_vn_max(bp, BP_VN(bp), &cmng_input);
  2410. m_rs_vn.vn_counter.rate =
  2411. cmng_input.vnic_max_rate[BP_VN(bp)];
  2412. m_rs_vn.vn_counter.quota =
  2413. (m_rs_vn.vn_counter.rate *
  2414. RS_PERIODIC_TIMEOUT_USEC) / 8;
  2415. __storm_memset_struct(bp, addr, size, (u32 *)&m_rs_vn);
  2416. /* read relevant values from mf_cfg struct in shmem */
  2417. vif_id =
  2418. (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2419. FUNC_MF_CFG_E1HOV_TAG_MASK) >>
  2420. FUNC_MF_CFG_E1HOV_TAG_SHIFT;
  2421. vlan_val =
  2422. (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2423. FUNC_MF_CFG_AFEX_VLAN_MASK) >>
  2424. FUNC_MF_CFG_AFEX_VLAN_SHIFT;
  2425. vlan_prio = (mf_config &
  2426. FUNC_MF_CFG_TRANSMIT_PRIORITY_MASK) >>
  2427. FUNC_MF_CFG_TRANSMIT_PRIORITY_SHIFT;
  2428. vlan_val |= (vlan_prio << VLAN_PRIO_SHIFT);
  2429. vlan_mode =
  2430. (MF_CFG_RD(bp,
  2431. func_mf_config[func].afex_config) &
  2432. FUNC_MF_CFG_AFEX_VLAN_MODE_MASK) >>
  2433. FUNC_MF_CFG_AFEX_VLAN_MODE_SHIFT;
  2434. allowed_prio =
  2435. (MF_CFG_RD(bp,
  2436. func_mf_config[func].afex_config) &
  2437. FUNC_MF_CFG_AFEX_COS_FILTER_MASK) >>
  2438. FUNC_MF_CFG_AFEX_COS_FILTER_SHIFT;
  2439. /* send ramrod to FW, return in case of failure */
  2440. if (bnx2x_afex_func_update(bp, vif_id, vlan_val,
  2441. allowed_prio))
  2442. return;
  2443. bp->afex_def_vlan_tag = vlan_val;
  2444. bp->afex_vlan_mode = vlan_mode;
  2445. } else {
  2446. /* notify link down because BP->flags is disabled */
  2447. bnx2x_link_report(bp);
  2448. /* send INVALID VIF ramrod to FW */
  2449. bnx2x_afex_func_update(bp, 0xFFFF, 0, 0);
  2450. /* Reset the default afex VLAN */
  2451. bp->afex_def_vlan_tag = -1;
  2452. }
  2453. }
  2454. }
  2455. static void bnx2x_handle_update_svid_cmd(struct bnx2x *bp)
  2456. {
  2457. struct bnx2x_func_switch_update_params *switch_update_params;
  2458. struct bnx2x_func_state_params func_params;
  2459. memset(&func_params, 0, sizeof(struct bnx2x_func_state_params));
  2460. switch_update_params = &func_params.params.switch_update;
  2461. func_params.f_obj = &bp->func_obj;
  2462. func_params.cmd = BNX2X_F_CMD_SWITCH_UPDATE;
  2463. if (IS_MF_UFP(bp)) {
  2464. int func = BP_ABS_FUNC(bp);
  2465. u32 val;
  2466. /* Re-learn the S-tag from shmem */
  2467. val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2468. FUNC_MF_CFG_E1HOV_TAG_MASK;
  2469. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  2470. bp->mf_ov = val;
  2471. } else {
  2472. BNX2X_ERR("Got an SVID event, but no tag is configured in shmem\n");
  2473. goto fail;
  2474. }
  2475. /* Configure new S-tag in LLH */
  2476. REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + BP_PORT(bp) * 8,
  2477. bp->mf_ov);
  2478. /* Send Ramrod to update FW of change */
  2479. __set_bit(BNX2X_F_UPDATE_SD_VLAN_TAG_CHNG,
  2480. &switch_update_params->changes);
  2481. switch_update_params->vlan = bp->mf_ov;
  2482. if (bnx2x_func_state_change(bp, &func_params) < 0) {
  2483. BNX2X_ERR("Failed to configure FW of S-tag Change to %02x\n",
  2484. bp->mf_ov);
  2485. goto fail;
  2486. }
  2487. DP(BNX2X_MSG_MCP, "Configured S-tag %02x\n", bp->mf_ov);
  2488. bnx2x_fw_command(bp, DRV_MSG_CODE_OEM_UPDATE_SVID_OK, 0);
  2489. return;
  2490. }
  2491. /* not supported by SW yet */
  2492. fail:
  2493. bnx2x_fw_command(bp, DRV_MSG_CODE_OEM_UPDATE_SVID_FAILURE, 0);
  2494. }
  2495. static void bnx2x_pmf_update(struct bnx2x *bp)
  2496. {
  2497. int port = BP_PORT(bp);
  2498. u32 val;
  2499. bp->port.pmf = 1;
  2500. DP(BNX2X_MSG_MCP, "pmf %d\n", bp->port.pmf);
  2501. /*
  2502. * We need the mb() to ensure the ordering between the writing to
  2503. * bp->port.pmf here and reading it from the bnx2x_periodic_task().
  2504. */
  2505. smp_mb();
  2506. /* queue a periodic task */
  2507. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  2508. bnx2x_dcbx_pmf_update(bp);
  2509. /* enable nig attention */
  2510. val = (0xff0f | (1 << (BP_VN(bp) + 4)));
  2511. if (bp->common.int_block == INT_BLOCK_HC) {
  2512. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  2513. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  2514. } else if (!CHIP_IS_E1x(bp)) {
  2515. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  2516. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  2517. }
  2518. bnx2x_stats_handle(bp, STATS_EVENT_PMF);
  2519. }
  2520. /* end of Link */
  2521. /* slow path */
  2522. /*
  2523. * General service functions
  2524. */
  2525. /* send the MCP a request, block until there is a reply */
  2526. u32 bnx2x_fw_command(struct bnx2x *bp, u32 command, u32 param)
  2527. {
  2528. int mb_idx = BP_FW_MB_IDX(bp);
  2529. u32 seq;
  2530. u32 rc = 0;
  2531. u32 cnt = 1;
  2532. u8 delay = CHIP_REV_IS_SLOW(bp) ? 100 : 10;
  2533. mutex_lock(&bp->fw_mb_mutex);
  2534. seq = ++bp->fw_seq;
  2535. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_param, param);
  2536. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_header, (command | seq));
  2537. DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB param 0x%08x\n",
  2538. (command | seq), param);
  2539. do {
  2540. /* let the FW do it's magic ... */
  2541. msleep(delay);
  2542. rc = SHMEM_RD(bp, func_mb[mb_idx].fw_mb_header);
  2543. /* Give the FW up to 5 second (500*10ms) */
  2544. } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500));
  2545. DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n",
  2546. cnt*delay, rc, seq);
  2547. /* is this a reply to our command? */
  2548. if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK))
  2549. rc &= FW_MSG_CODE_MASK;
  2550. else {
  2551. /* FW BUG! */
  2552. BNX2X_ERR("FW failed to respond!\n");
  2553. bnx2x_fw_dump(bp);
  2554. rc = 0;
  2555. }
  2556. mutex_unlock(&bp->fw_mb_mutex);
  2557. return rc;
  2558. }
  2559. static void storm_memset_func_cfg(struct bnx2x *bp,
  2560. struct tstorm_eth_function_common_config *tcfg,
  2561. u16 abs_fid)
  2562. {
  2563. size_t size = sizeof(struct tstorm_eth_function_common_config);
  2564. u32 addr = BAR_TSTRORM_INTMEM +
  2565. TSTORM_FUNCTION_COMMON_CONFIG_OFFSET(abs_fid);
  2566. __storm_memset_struct(bp, addr, size, (u32 *)tcfg);
  2567. }
  2568. void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p)
  2569. {
  2570. if (CHIP_IS_E1x(bp)) {
  2571. struct tstorm_eth_function_common_config tcfg = {0};
  2572. storm_memset_func_cfg(bp, &tcfg, p->func_id);
  2573. }
  2574. /* Enable the function in the FW */
  2575. storm_memset_vf_to_pf(bp, p->func_id, p->pf_id);
  2576. storm_memset_func_en(bp, p->func_id, 1);
  2577. /* spq */
  2578. if (p->func_flgs & FUNC_FLG_SPQ) {
  2579. storm_memset_spq_addr(bp, p->spq_map, p->func_id);
  2580. REG_WR(bp, XSEM_REG_FAST_MEMORY +
  2581. XSTORM_SPQ_PROD_OFFSET(p->func_id), p->spq_prod);
  2582. }
  2583. }
  2584. /**
  2585. * bnx2x_get_common_flags - Return common flags
  2586. *
  2587. * @bp device handle
  2588. * @fp queue handle
  2589. * @zero_stats TRUE if statistics zeroing is needed
  2590. *
  2591. * Return the flags that are common for the Tx-only and not normal connections.
  2592. */
  2593. static unsigned long bnx2x_get_common_flags(struct bnx2x *bp,
  2594. struct bnx2x_fastpath *fp,
  2595. bool zero_stats)
  2596. {
  2597. unsigned long flags = 0;
  2598. /* PF driver will always initialize the Queue to an ACTIVE state */
  2599. __set_bit(BNX2X_Q_FLG_ACTIVE, &flags);
  2600. /* tx only connections collect statistics (on the same index as the
  2601. * parent connection). The statistics are zeroed when the parent
  2602. * connection is initialized.
  2603. */
  2604. __set_bit(BNX2X_Q_FLG_STATS, &flags);
  2605. if (zero_stats)
  2606. __set_bit(BNX2X_Q_FLG_ZERO_STATS, &flags);
  2607. if (bp->flags & TX_SWITCHING)
  2608. __set_bit(BNX2X_Q_FLG_TX_SWITCH, &flags);
  2609. __set_bit(BNX2X_Q_FLG_PCSUM_ON_PKT, &flags);
  2610. __set_bit(BNX2X_Q_FLG_TUN_INC_INNER_IP_ID, &flags);
  2611. #ifdef BNX2X_STOP_ON_ERROR
  2612. __set_bit(BNX2X_Q_FLG_TX_SEC, &flags);
  2613. #endif
  2614. return flags;
  2615. }
  2616. static unsigned long bnx2x_get_q_flags(struct bnx2x *bp,
  2617. struct bnx2x_fastpath *fp,
  2618. bool leading)
  2619. {
  2620. unsigned long flags = 0;
  2621. /* calculate other queue flags */
  2622. if (IS_MF_SD(bp))
  2623. __set_bit(BNX2X_Q_FLG_OV, &flags);
  2624. if (IS_FCOE_FP(fp)) {
  2625. __set_bit(BNX2X_Q_FLG_FCOE, &flags);
  2626. /* For FCoE - force usage of default priority (for afex) */
  2627. __set_bit(BNX2X_Q_FLG_FORCE_DEFAULT_PRI, &flags);
  2628. }
  2629. if (!fp->disable_tpa) {
  2630. __set_bit(BNX2X_Q_FLG_TPA, &flags);
  2631. __set_bit(BNX2X_Q_FLG_TPA_IPV6, &flags);
  2632. if (fp->mode == TPA_MODE_GRO)
  2633. __set_bit(BNX2X_Q_FLG_TPA_GRO, &flags);
  2634. }
  2635. if (leading) {
  2636. __set_bit(BNX2X_Q_FLG_LEADING_RSS, &flags);
  2637. __set_bit(BNX2X_Q_FLG_MCAST, &flags);
  2638. }
  2639. /* Always set HW VLAN stripping */
  2640. __set_bit(BNX2X_Q_FLG_VLAN, &flags);
  2641. /* configure silent vlan removal */
  2642. if (IS_MF_AFEX(bp))
  2643. __set_bit(BNX2X_Q_FLG_SILENT_VLAN_REM, &flags);
  2644. return flags | bnx2x_get_common_flags(bp, fp, true);
  2645. }
  2646. static void bnx2x_pf_q_prep_general(struct bnx2x *bp,
  2647. struct bnx2x_fastpath *fp, struct bnx2x_general_setup_params *gen_init,
  2648. u8 cos)
  2649. {
  2650. gen_init->stat_id = bnx2x_stats_id(fp);
  2651. gen_init->spcl_id = fp->cl_id;
  2652. /* Always use mini-jumbo MTU for FCoE L2 ring */
  2653. if (IS_FCOE_FP(fp))
  2654. gen_init->mtu = BNX2X_FCOE_MINI_JUMBO_MTU;
  2655. else
  2656. gen_init->mtu = bp->dev->mtu;
  2657. gen_init->cos = cos;
  2658. }
  2659. static void bnx2x_pf_rx_q_prep(struct bnx2x *bp,
  2660. struct bnx2x_fastpath *fp, struct rxq_pause_params *pause,
  2661. struct bnx2x_rxq_setup_params *rxq_init)
  2662. {
  2663. u8 max_sge = 0;
  2664. u16 sge_sz = 0;
  2665. u16 tpa_agg_size = 0;
  2666. if (!fp->disable_tpa) {
  2667. pause->sge_th_lo = SGE_TH_LO(bp);
  2668. pause->sge_th_hi = SGE_TH_HI(bp);
  2669. /* validate SGE ring has enough to cross high threshold */
  2670. WARN_ON(bp->dropless_fc &&
  2671. pause->sge_th_hi + FW_PREFETCH_CNT >
  2672. MAX_RX_SGE_CNT * NUM_RX_SGE_PAGES);
  2673. tpa_agg_size = TPA_AGG_SIZE;
  2674. max_sge = SGE_PAGE_ALIGN(bp->dev->mtu) >>
  2675. SGE_PAGE_SHIFT;
  2676. max_sge = ((max_sge + PAGES_PER_SGE - 1) &
  2677. (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
  2678. sge_sz = (u16)min_t(u32, SGE_PAGES, 0xffff);
  2679. }
  2680. /* pause - not for e1 */
  2681. if (!CHIP_IS_E1(bp)) {
  2682. pause->bd_th_lo = BD_TH_LO(bp);
  2683. pause->bd_th_hi = BD_TH_HI(bp);
  2684. pause->rcq_th_lo = RCQ_TH_LO(bp);
  2685. pause->rcq_th_hi = RCQ_TH_HI(bp);
  2686. /*
  2687. * validate that rings have enough entries to cross
  2688. * high thresholds
  2689. */
  2690. WARN_ON(bp->dropless_fc &&
  2691. pause->bd_th_hi + FW_PREFETCH_CNT >
  2692. bp->rx_ring_size);
  2693. WARN_ON(bp->dropless_fc &&
  2694. pause->rcq_th_hi + FW_PREFETCH_CNT >
  2695. NUM_RCQ_RINGS * MAX_RCQ_DESC_CNT);
  2696. pause->pri_map = 1;
  2697. }
  2698. /* rxq setup */
  2699. rxq_init->dscr_map = fp->rx_desc_mapping;
  2700. rxq_init->sge_map = fp->rx_sge_mapping;
  2701. rxq_init->rcq_map = fp->rx_comp_mapping;
  2702. rxq_init->rcq_np_map = fp->rx_comp_mapping + BCM_PAGE_SIZE;
  2703. /* This should be a maximum number of data bytes that may be
  2704. * placed on the BD (not including paddings).
  2705. */
  2706. rxq_init->buf_sz = fp->rx_buf_size - BNX2X_FW_RX_ALIGN_START -
  2707. BNX2X_FW_RX_ALIGN_END - IP_HEADER_ALIGNMENT_PADDING;
  2708. rxq_init->cl_qzone_id = fp->cl_qzone_id;
  2709. rxq_init->tpa_agg_sz = tpa_agg_size;
  2710. rxq_init->sge_buf_sz = sge_sz;
  2711. rxq_init->max_sges_pkt = max_sge;
  2712. rxq_init->rss_engine_id = BP_FUNC(bp);
  2713. rxq_init->mcast_engine_id = BP_FUNC(bp);
  2714. /* Maximum number or simultaneous TPA aggregation for this Queue.
  2715. *
  2716. * For PF Clients it should be the maximum available number.
  2717. * VF driver(s) may want to define it to a smaller value.
  2718. */
  2719. rxq_init->max_tpa_queues = MAX_AGG_QS(bp);
  2720. rxq_init->cache_line_log = BNX2X_RX_ALIGN_SHIFT;
  2721. rxq_init->fw_sb_id = fp->fw_sb_id;
  2722. if (IS_FCOE_FP(fp))
  2723. rxq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS;
  2724. else
  2725. rxq_init->sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  2726. /* configure silent vlan removal
  2727. * if multi function mode is afex, then mask default vlan
  2728. */
  2729. if (IS_MF_AFEX(bp)) {
  2730. rxq_init->silent_removal_value = bp->afex_def_vlan_tag;
  2731. rxq_init->silent_removal_mask = VLAN_VID_MASK;
  2732. }
  2733. }
  2734. static void bnx2x_pf_tx_q_prep(struct bnx2x *bp,
  2735. struct bnx2x_fastpath *fp, struct bnx2x_txq_setup_params *txq_init,
  2736. u8 cos)
  2737. {
  2738. txq_init->dscr_map = fp->txdata_ptr[cos]->tx_desc_mapping;
  2739. txq_init->sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS + cos;
  2740. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_NW;
  2741. txq_init->fw_sb_id = fp->fw_sb_id;
  2742. /*
  2743. * set the tss leading client id for TX classification ==
  2744. * leading RSS client id
  2745. */
  2746. txq_init->tss_leading_cl_id = bnx2x_fp(bp, 0, cl_id);
  2747. if (IS_FCOE_FP(fp)) {
  2748. txq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS;
  2749. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_FCOE;
  2750. }
  2751. }
  2752. static void bnx2x_pf_init(struct bnx2x *bp)
  2753. {
  2754. struct bnx2x_func_init_params func_init = {0};
  2755. struct event_ring_data eq_data = { {0} };
  2756. u16 flags;
  2757. if (!CHIP_IS_E1x(bp)) {
  2758. /* reset IGU PF statistics: MSIX + ATTN */
  2759. /* PF */
  2760. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2761. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2762. (CHIP_MODE_IS_4_PORT(bp) ?
  2763. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2764. /* ATTN */
  2765. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2766. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2767. BNX2X_IGU_STAS_MSG_PF_CNT*4 +
  2768. (CHIP_MODE_IS_4_PORT(bp) ?
  2769. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2770. }
  2771. /* function setup flags */
  2772. flags = (FUNC_FLG_STATS | FUNC_FLG_LEADING | FUNC_FLG_SPQ);
  2773. /* This flag is relevant for E1x only.
  2774. * E2 doesn't have a TPA configuration in a function level.
  2775. */
  2776. flags |= (bp->flags & TPA_ENABLE_FLAG) ? FUNC_FLG_TPA : 0;
  2777. func_init.func_flgs = flags;
  2778. func_init.pf_id = BP_FUNC(bp);
  2779. func_init.func_id = BP_FUNC(bp);
  2780. func_init.spq_map = bp->spq_mapping;
  2781. func_init.spq_prod = bp->spq_prod_idx;
  2782. bnx2x_func_init(bp, &func_init);
  2783. memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port));
  2784. /*
  2785. * Congestion management values depend on the link rate
  2786. * There is no active link so initial link rate is set to 10 Gbps.
  2787. * When the link comes up The congestion management values are
  2788. * re-calculated according to the actual link rate.
  2789. */
  2790. bp->link_vars.line_speed = SPEED_10000;
  2791. bnx2x_cmng_fns_init(bp, true, bnx2x_get_cmng_fns_mode(bp));
  2792. /* Only the PMF sets the HW */
  2793. if (bp->port.pmf)
  2794. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2795. /* init Event Queue - PCI bus guarantees correct endianity*/
  2796. eq_data.base_addr.hi = U64_HI(bp->eq_mapping);
  2797. eq_data.base_addr.lo = U64_LO(bp->eq_mapping);
  2798. eq_data.producer = bp->eq_prod;
  2799. eq_data.index_id = HC_SP_INDEX_EQ_CONS;
  2800. eq_data.sb_id = DEF_SB_ID;
  2801. storm_memset_eq_data(bp, &eq_data, BP_FUNC(bp));
  2802. }
  2803. static void bnx2x_e1h_disable(struct bnx2x *bp)
  2804. {
  2805. int port = BP_PORT(bp);
  2806. bnx2x_tx_disable(bp);
  2807. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  2808. }
  2809. static void bnx2x_e1h_enable(struct bnx2x *bp)
  2810. {
  2811. int port = BP_PORT(bp);
  2812. if (!(IS_MF_UFP(bp) && BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp)))
  2813. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port * 8, 1);
  2814. /* Tx queue should be only re-enabled */
  2815. netif_tx_wake_all_queues(bp->dev);
  2816. /*
  2817. * Should not call netif_carrier_on since it will be called if the link
  2818. * is up when checking for link state
  2819. */
  2820. }
  2821. #define DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED 3
  2822. static void bnx2x_drv_info_ether_stat(struct bnx2x *bp)
  2823. {
  2824. struct eth_stats_info *ether_stat =
  2825. &bp->slowpath->drv_info_to_mcp.ether_stat;
  2826. struct bnx2x_vlan_mac_obj *mac_obj =
  2827. &bp->sp_objs->mac_obj;
  2828. int i;
  2829. strlcpy(ether_stat->version, DRV_MODULE_VERSION,
  2830. ETH_STAT_INFO_VERSION_LEN);
  2831. /* get DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED macs, placing them in the
  2832. * mac_local field in ether_stat struct. The base address is offset by 2
  2833. * bytes to account for the field being 8 bytes but a mac address is
  2834. * only 6 bytes. Likewise, the stride for the get_n_elements function is
  2835. * 2 bytes to compensate from the 6 bytes of a mac to the 8 bytes
  2836. * allocated by the ether_stat struct, so the macs will land in their
  2837. * proper positions.
  2838. */
  2839. for (i = 0; i < DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED; i++)
  2840. memset(ether_stat->mac_local + i, 0,
  2841. sizeof(ether_stat->mac_local[0]));
  2842. mac_obj->get_n_elements(bp, &bp->sp_objs[0].mac_obj,
  2843. DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED,
  2844. ether_stat->mac_local + MAC_PAD, MAC_PAD,
  2845. ETH_ALEN);
  2846. ether_stat->mtu_size = bp->dev->mtu;
  2847. if (bp->dev->features & NETIF_F_RXCSUM)
  2848. ether_stat->feature_flags |= FEATURE_ETH_CHKSUM_OFFLOAD_MASK;
  2849. if (bp->dev->features & NETIF_F_TSO)
  2850. ether_stat->feature_flags |= FEATURE_ETH_LSO_MASK;
  2851. ether_stat->feature_flags |= bp->common.boot_mode;
  2852. ether_stat->promiscuous_mode = (bp->dev->flags & IFF_PROMISC) ? 1 : 0;
  2853. ether_stat->txq_size = bp->tx_ring_size;
  2854. ether_stat->rxq_size = bp->rx_ring_size;
  2855. #ifdef CONFIG_BNX2X_SRIOV
  2856. ether_stat->vf_cnt = IS_SRIOV(bp) ? bp->vfdb->sriov.nr_virtfn : 0;
  2857. #endif
  2858. }
  2859. static void bnx2x_drv_info_fcoe_stat(struct bnx2x *bp)
  2860. {
  2861. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2862. struct fcoe_stats_info *fcoe_stat =
  2863. &bp->slowpath->drv_info_to_mcp.fcoe_stat;
  2864. if (!CNIC_LOADED(bp))
  2865. return;
  2866. memcpy(fcoe_stat->mac_local + MAC_PAD, bp->fip_mac, ETH_ALEN);
  2867. fcoe_stat->qos_priority =
  2868. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_FCOE];
  2869. /* insert FCoE stats from ramrod response */
  2870. if (!NO_FCOE(bp)) {
  2871. struct tstorm_per_queue_stats *fcoe_q_tstorm_stats =
  2872. &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
  2873. tstorm_queue_statistics;
  2874. struct xstorm_per_queue_stats *fcoe_q_xstorm_stats =
  2875. &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
  2876. xstorm_queue_statistics;
  2877. struct fcoe_statistics_params *fw_fcoe_stat =
  2878. &bp->fw_stats_data->fcoe;
  2879. ADD_64_LE(fcoe_stat->rx_bytes_hi, LE32_0,
  2880. fcoe_stat->rx_bytes_lo,
  2881. fw_fcoe_stat->rx_stat0.fcoe_rx_byte_cnt);
  2882. ADD_64_LE(fcoe_stat->rx_bytes_hi,
  2883. fcoe_q_tstorm_stats->rcv_ucast_bytes.hi,
  2884. fcoe_stat->rx_bytes_lo,
  2885. fcoe_q_tstorm_stats->rcv_ucast_bytes.lo);
  2886. ADD_64_LE(fcoe_stat->rx_bytes_hi,
  2887. fcoe_q_tstorm_stats->rcv_bcast_bytes.hi,
  2888. fcoe_stat->rx_bytes_lo,
  2889. fcoe_q_tstorm_stats->rcv_bcast_bytes.lo);
  2890. ADD_64_LE(fcoe_stat->rx_bytes_hi,
  2891. fcoe_q_tstorm_stats->rcv_mcast_bytes.hi,
  2892. fcoe_stat->rx_bytes_lo,
  2893. fcoe_q_tstorm_stats->rcv_mcast_bytes.lo);
  2894. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2895. fcoe_stat->rx_frames_lo,
  2896. fw_fcoe_stat->rx_stat0.fcoe_rx_pkt_cnt);
  2897. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2898. fcoe_stat->rx_frames_lo,
  2899. fcoe_q_tstorm_stats->rcv_ucast_pkts);
  2900. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2901. fcoe_stat->rx_frames_lo,
  2902. fcoe_q_tstorm_stats->rcv_bcast_pkts);
  2903. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2904. fcoe_stat->rx_frames_lo,
  2905. fcoe_q_tstorm_stats->rcv_mcast_pkts);
  2906. ADD_64_LE(fcoe_stat->tx_bytes_hi, LE32_0,
  2907. fcoe_stat->tx_bytes_lo,
  2908. fw_fcoe_stat->tx_stat.fcoe_tx_byte_cnt);
  2909. ADD_64_LE(fcoe_stat->tx_bytes_hi,
  2910. fcoe_q_xstorm_stats->ucast_bytes_sent.hi,
  2911. fcoe_stat->tx_bytes_lo,
  2912. fcoe_q_xstorm_stats->ucast_bytes_sent.lo);
  2913. ADD_64_LE(fcoe_stat->tx_bytes_hi,
  2914. fcoe_q_xstorm_stats->bcast_bytes_sent.hi,
  2915. fcoe_stat->tx_bytes_lo,
  2916. fcoe_q_xstorm_stats->bcast_bytes_sent.lo);
  2917. ADD_64_LE(fcoe_stat->tx_bytes_hi,
  2918. fcoe_q_xstorm_stats->mcast_bytes_sent.hi,
  2919. fcoe_stat->tx_bytes_lo,
  2920. fcoe_q_xstorm_stats->mcast_bytes_sent.lo);
  2921. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2922. fcoe_stat->tx_frames_lo,
  2923. fw_fcoe_stat->tx_stat.fcoe_tx_pkt_cnt);
  2924. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2925. fcoe_stat->tx_frames_lo,
  2926. fcoe_q_xstorm_stats->ucast_pkts_sent);
  2927. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2928. fcoe_stat->tx_frames_lo,
  2929. fcoe_q_xstorm_stats->bcast_pkts_sent);
  2930. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2931. fcoe_stat->tx_frames_lo,
  2932. fcoe_q_xstorm_stats->mcast_pkts_sent);
  2933. }
  2934. /* ask L5 driver to add data to the struct */
  2935. bnx2x_cnic_notify(bp, CNIC_CTL_FCOE_STATS_GET_CMD);
  2936. }
  2937. static void bnx2x_drv_info_iscsi_stat(struct bnx2x *bp)
  2938. {
  2939. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2940. struct iscsi_stats_info *iscsi_stat =
  2941. &bp->slowpath->drv_info_to_mcp.iscsi_stat;
  2942. if (!CNIC_LOADED(bp))
  2943. return;
  2944. memcpy(iscsi_stat->mac_local + MAC_PAD, bp->cnic_eth_dev.iscsi_mac,
  2945. ETH_ALEN);
  2946. iscsi_stat->qos_priority =
  2947. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_ISCSI];
  2948. /* ask L5 driver to add data to the struct */
  2949. bnx2x_cnic_notify(bp, CNIC_CTL_ISCSI_STATS_GET_CMD);
  2950. }
  2951. /* called due to MCP event (on pmf):
  2952. * reread new bandwidth configuration
  2953. * configure FW
  2954. * notify others function about the change
  2955. */
  2956. static void bnx2x_config_mf_bw(struct bnx2x *bp)
  2957. {
  2958. if (bp->link_vars.link_up) {
  2959. bnx2x_cmng_fns_init(bp, true, CMNG_FNS_MINMAX);
  2960. bnx2x_link_sync_notify(bp);
  2961. }
  2962. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2963. }
  2964. static void bnx2x_set_mf_bw(struct bnx2x *bp)
  2965. {
  2966. bnx2x_config_mf_bw(bp);
  2967. bnx2x_fw_command(bp, DRV_MSG_CODE_SET_MF_BW_ACK, 0);
  2968. }
  2969. static void bnx2x_handle_eee_event(struct bnx2x *bp)
  2970. {
  2971. DP(BNX2X_MSG_MCP, "EEE - LLDP event\n");
  2972. bnx2x_fw_command(bp, DRV_MSG_CODE_EEE_RESULTS_ACK, 0);
  2973. }
  2974. #define BNX2X_UPDATE_DRV_INFO_IND_LENGTH (20)
  2975. #define BNX2X_UPDATE_DRV_INFO_IND_COUNT (25)
  2976. static void bnx2x_handle_drv_info_req(struct bnx2x *bp)
  2977. {
  2978. enum drv_info_opcode op_code;
  2979. u32 drv_info_ctl = SHMEM2_RD(bp, drv_info_control);
  2980. bool release = false;
  2981. int wait;
  2982. /* if drv_info version supported by MFW doesn't match - send NACK */
  2983. if ((drv_info_ctl & DRV_INFO_CONTROL_VER_MASK) != DRV_INFO_CUR_VER) {
  2984. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  2985. return;
  2986. }
  2987. op_code = (drv_info_ctl & DRV_INFO_CONTROL_OP_CODE_MASK) >>
  2988. DRV_INFO_CONTROL_OP_CODE_SHIFT;
  2989. /* Must prevent other flows from accessing drv_info_to_mcp */
  2990. mutex_lock(&bp->drv_info_mutex);
  2991. memset(&bp->slowpath->drv_info_to_mcp, 0,
  2992. sizeof(union drv_info_to_mcp));
  2993. switch (op_code) {
  2994. case ETH_STATS_OPCODE:
  2995. bnx2x_drv_info_ether_stat(bp);
  2996. break;
  2997. case FCOE_STATS_OPCODE:
  2998. bnx2x_drv_info_fcoe_stat(bp);
  2999. break;
  3000. case ISCSI_STATS_OPCODE:
  3001. bnx2x_drv_info_iscsi_stat(bp);
  3002. break;
  3003. default:
  3004. /* if op code isn't supported - send NACK */
  3005. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  3006. goto out;
  3007. }
  3008. /* if we got drv_info attn from MFW then these fields are defined in
  3009. * shmem2 for sure
  3010. */
  3011. SHMEM2_WR(bp, drv_info_host_addr_lo,
  3012. U64_LO(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  3013. SHMEM2_WR(bp, drv_info_host_addr_hi,
  3014. U64_HI(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  3015. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_ACK, 0);
  3016. /* Since possible management wants both this and get_driver_version
  3017. * need to wait until management notifies us it finished utilizing
  3018. * the buffer.
  3019. */
  3020. if (!SHMEM2_HAS(bp, mfw_drv_indication)) {
  3021. DP(BNX2X_MSG_MCP, "Management does not support indication\n");
  3022. } else if (!bp->drv_info_mng_owner) {
  3023. u32 bit = MFW_DRV_IND_READ_DONE_OFFSET((BP_ABS_FUNC(bp) >> 1));
  3024. for (wait = 0; wait < BNX2X_UPDATE_DRV_INFO_IND_COUNT; wait++) {
  3025. u32 indication = SHMEM2_RD(bp, mfw_drv_indication);
  3026. /* Management is done; need to clear indication */
  3027. if (indication & bit) {
  3028. SHMEM2_WR(bp, mfw_drv_indication,
  3029. indication & ~bit);
  3030. release = true;
  3031. break;
  3032. }
  3033. msleep(BNX2X_UPDATE_DRV_INFO_IND_LENGTH);
  3034. }
  3035. }
  3036. if (!release) {
  3037. DP(BNX2X_MSG_MCP, "Management did not release indication\n");
  3038. bp->drv_info_mng_owner = true;
  3039. }
  3040. out:
  3041. mutex_unlock(&bp->drv_info_mutex);
  3042. }
  3043. static u32 bnx2x_update_mng_version_utility(u8 *version, bool bnx2x_format)
  3044. {
  3045. u8 vals[4];
  3046. int i = 0;
  3047. if (bnx2x_format) {
  3048. i = sscanf(version, "1.%c%hhd.%hhd.%hhd",
  3049. &vals[0], &vals[1], &vals[2], &vals[3]);
  3050. if (i > 0)
  3051. vals[0] -= '0';
  3052. } else {
  3053. i = sscanf(version, "%hhd.%hhd.%hhd.%hhd",
  3054. &vals[0], &vals[1], &vals[2], &vals[3]);
  3055. }
  3056. while (i < 4)
  3057. vals[i++] = 0;
  3058. return (vals[0] << 24) | (vals[1] << 16) | (vals[2] << 8) | vals[3];
  3059. }
  3060. void bnx2x_update_mng_version(struct bnx2x *bp)
  3061. {
  3062. u32 iscsiver = DRV_VER_NOT_LOADED;
  3063. u32 fcoever = DRV_VER_NOT_LOADED;
  3064. u32 ethver = DRV_VER_NOT_LOADED;
  3065. int idx = BP_FW_MB_IDX(bp);
  3066. u8 *version;
  3067. if (!SHMEM2_HAS(bp, func_os_drv_ver))
  3068. return;
  3069. mutex_lock(&bp->drv_info_mutex);
  3070. /* Must not proceed when `bnx2x_handle_drv_info_req' is feasible */
  3071. if (bp->drv_info_mng_owner)
  3072. goto out;
  3073. if (bp->state != BNX2X_STATE_OPEN)
  3074. goto out;
  3075. /* Parse ethernet driver version */
  3076. ethver = bnx2x_update_mng_version_utility(DRV_MODULE_VERSION, true);
  3077. if (!CNIC_LOADED(bp))
  3078. goto out;
  3079. /* Try getting storage driver version via cnic */
  3080. memset(&bp->slowpath->drv_info_to_mcp, 0,
  3081. sizeof(union drv_info_to_mcp));
  3082. bnx2x_drv_info_iscsi_stat(bp);
  3083. version = bp->slowpath->drv_info_to_mcp.iscsi_stat.version;
  3084. iscsiver = bnx2x_update_mng_version_utility(version, false);
  3085. memset(&bp->slowpath->drv_info_to_mcp, 0,
  3086. sizeof(union drv_info_to_mcp));
  3087. bnx2x_drv_info_fcoe_stat(bp);
  3088. version = bp->slowpath->drv_info_to_mcp.fcoe_stat.version;
  3089. fcoever = bnx2x_update_mng_version_utility(version, false);
  3090. out:
  3091. SHMEM2_WR(bp, func_os_drv_ver[idx].versions[DRV_PERS_ETHERNET], ethver);
  3092. SHMEM2_WR(bp, func_os_drv_ver[idx].versions[DRV_PERS_ISCSI], iscsiver);
  3093. SHMEM2_WR(bp, func_os_drv_ver[idx].versions[DRV_PERS_FCOE], fcoever);
  3094. mutex_unlock(&bp->drv_info_mutex);
  3095. DP(BNX2X_MSG_MCP, "Setting driver version: ETH [%08x] iSCSI [%08x] FCoE [%08x]\n",
  3096. ethver, iscsiver, fcoever);
  3097. }
  3098. static void bnx2x_oem_event(struct bnx2x *bp, u32 event)
  3099. {
  3100. u32 cmd_ok, cmd_fail;
  3101. /* sanity */
  3102. if (event & DRV_STATUS_DCC_EVENT_MASK &&
  3103. event & DRV_STATUS_OEM_EVENT_MASK) {
  3104. BNX2X_ERR("Received simultaneous events %08x\n", event);
  3105. return;
  3106. }
  3107. if (event & DRV_STATUS_DCC_EVENT_MASK) {
  3108. cmd_fail = DRV_MSG_CODE_DCC_FAILURE;
  3109. cmd_ok = DRV_MSG_CODE_DCC_OK;
  3110. } else /* if (event & DRV_STATUS_OEM_EVENT_MASK) */ {
  3111. cmd_fail = DRV_MSG_CODE_OEM_FAILURE;
  3112. cmd_ok = DRV_MSG_CODE_OEM_OK;
  3113. }
  3114. DP(BNX2X_MSG_MCP, "oem_event 0x%x\n", event);
  3115. if (event & (DRV_STATUS_DCC_DISABLE_ENABLE_PF |
  3116. DRV_STATUS_OEM_DISABLE_ENABLE_PF)) {
  3117. /* This is the only place besides the function initialization
  3118. * where the bp->flags can change so it is done without any
  3119. * locks
  3120. */
  3121. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  3122. DP(BNX2X_MSG_MCP, "mf_cfg function disabled\n");
  3123. bp->flags |= MF_FUNC_DIS;
  3124. bnx2x_e1h_disable(bp);
  3125. } else {
  3126. DP(BNX2X_MSG_MCP, "mf_cfg function enabled\n");
  3127. bp->flags &= ~MF_FUNC_DIS;
  3128. bnx2x_e1h_enable(bp);
  3129. }
  3130. event &= ~(DRV_STATUS_DCC_DISABLE_ENABLE_PF |
  3131. DRV_STATUS_OEM_DISABLE_ENABLE_PF);
  3132. }
  3133. if (event & (DRV_STATUS_DCC_BANDWIDTH_ALLOCATION |
  3134. DRV_STATUS_OEM_BANDWIDTH_ALLOCATION)) {
  3135. bnx2x_config_mf_bw(bp);
  3136. event &= ~(DRV_STATUS_DCC_BANDWIDTH_ALLOCATION |
  3137. DRV_STATUS_OEM_BANDWIDTH_ALLOCATION);
  3138. }
  3139. /* Report results to MCP */
  3140. if (event)
  3141. bnx2x_fw_command(bp, cmd_fail, 0);
  3142. else
  3143. bnx2x_fw_command(bp, cmd_ok, 0);
  3144. }
  3145. /* must be called under the spq lock */
  3146. static struct eth_spe *bnx2x_sp_get_next(struct bnx2x *bp)
  3147. {
  3148. struct eth_spe *next_spe = bp->spq_prod_bd;
  3149. if (bp->spq_prod_bd == bp->spq_last_bd) {
  3150. bp->spq_prod_bd = bp->spq;
  3151. bp->spq_prod_idx = 0;
  3152. DP(BNX2X_MSG_SP, "end of spq\n");
  3153. } else {
  3154. bp->spq_prod_bd++;
  3155. bp->spq_prod_idx++;
  3156. }
  3157. return next_spe;
  3158. }
  3159. /* must be called under the spq lock */
  3160. static void bnx2x_sp_prod_update(struct bnx2x *bp)
  3161. {
  3162. int func = BP_FUNC(bp);
  3163. /*
  3164. * Make sure that BD data is updated before writing the producer:
  3165. * BD data is written to the memory, the producer is read from the
  3166. * memory, thus we need a full memory barrier to ensure the ordering.
  3167. */
  3168. mb();
  3169. REG_WR16(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func),
  3170. bp->spq_prod_idx);
  3171. mmiowb();
  3172. }
  3173. /**
  3174. * bnx2x_is_contextless_ramrod - check if the current command ends on EQ
  3175. *
  3176. * @cmd: command to check
  3177. * @cmd_type: command type
  3178. */
  3179. static bool bnx2x_is_contextless_ramrod(int cmd, int cmd_type)
  3180. {
  3181. if ((cmd_type == NONE_CONNECTION_TYPE) ||
  3182. (cmd == RAMROD_CMD_ID_ETH_FORWARD_SETUP) ||
  3183. (cmd == RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES) ||
  3184. (cmd == RAMROD_CMD_ID_ETH_FILTER_RULES) ||
  3185. (cmd == RAMROD_CMD_ID_ETH_MULTICAST_RULES) ||
  3186. (cmd == RAMROD_CMD_ID_ETH_SET_MAC) ||
  3187. (cmd == RAMROD_CMD_ID_ETH_RSS_UPDATE))
  3188. return true;
  3189. else
  3190. return false;
  3191. }
  3192. /**
  3193. * bnx2x_sp_post - place a single command on an SP ring
  3194. *
  3195. * @bp: driver handle
  3196. * @command: command to place (e.g. SETUP, FILTER_RULES, etc.)
  3197. * @cid: SW CID the command is related to
  3198. * @data_hi: command private data address (high 32 bits)
  3199. * @data_lo: command private data address (low 32 bits)
  3200. * @cmd_type: command type (e.g. NONE, ETH)
  3201. *
  3202. * SP data is handled as if it's always an address pair, thus data fields are
  3203. * not swapped to little endian in upper functions. Instead this function swaps
  3204. * data as if it's two u32 fields.
  3205. */
  3206. int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
  3207. u32 data_hi, u32 data_lo, int cmd_type)
  3208. {
  3209. struct eth_spe *spe;
  3210. u16 type;
  3211. bool common = bnx2x_is_contextless_ramrod(command, cmd_type);
  3212. #ifdef BNX2X_STOP_ON_ERROR
  3213. if (unlikely(bp->panic)) {
  3214. BNX2X_ERR("Can't post SP when there is panic\n");
  3215. return -EIO;
  3216. }
  3217. #endif
  3218. spin_lock_bh(&bp->spq_lock);
  3219. if (common) {
  3220. if (!atomic_read(&bp->eq_spq_left)) {
  3221. BNX2X_ERR("BUG! EQ ring full!\n");
  3222. spin_unlock_bh(&bp->spq_lock);
  3223. bnx2x_panic();
  3224. return -EBUSY;
  3225. }
  3226. } else if (!atomic_read(&bp->cq_spq_left)) {
  3227. BNX2X_ERR("BUG! SPQ ring full!\n");
  3228. spin_unlock_bh(&bp->spq_lock);
  3229. bnx2x_panic();
  3230. return -EBUSY;
  3231. }
  3232. spe = bnx2x_sp_get_next(bp);
  3233. /* CID needs port number to be encoded int it */
  3234. spe->hdr.conn_and_cmd_data =
  3235. cpu_to_le32((command << SPE_HDR_CMD_ID_SHIFT) |
  3236. HW_CID(bp, cid));
  3237. /* In some cases, type may already contain the func-id
  3238. * mainly in SRIOV related use cases, so we add it here only
  3239. * if it's not already set.
  3240. */
  3241. if (!(cmd_type & SPE_HDR_FUNCTION_ID)) {
  3242. type = (cmd_type << SPE_HDR_CONN_TYPE_SHIFT) &
  3243. SPE_HDR_CONN_TYPE;
  3244. type |= ((BP_FUNC(bp) << SPE_HDR_FUNCTION_ID_SHIFT) &
  3245. SPE_HDR_FUNCTION_ID);
  3246. } else {
  3247. type = cmd_type;
  3248. }
  3249. spe->hdr.type = cpu_to_le16(type);
  3250. spe->data.update_data_addr.hi = cpu_to_le32(data_hi);
  3251. spe->data.update_data_addr.lo = cpu_to_le32(data_lo);
  3252. /*
  3253. * It's ok if the actual decrement is issued towards the memory
  3254. * somewhere between the spin_lock and spin_unlock. Thus no
  3255. * more explicit memory barrier is needed.
  3256. */
  3257. if (common)
  3258. atomic_dec(&bp->eq_spq_left);
  3259. else
  3260. atomic_dec(&bp->cq_spq_left);
  3261. DP(BNX2X_MSG_SP,
  3262. "SPQE[%x] (%x:%x) (cmd, common?) (%d,%d) hw_cid %x data (%x:%x) type(0x%x) left (CQ, EQ) (%x,%x)\n",
  3263. bp->spq_prod_idx, (u32)U64_HI(bp->spq_mapping),
  3264. (u32)(U64_LO(bp->spq_mapping) +
  3265. (void *)bp->spq_prod_bd - (void *)bp->spq), command, common,
  3266. HW_CID(bp, cid), data_hi, data_lo, type,
  3267. atomic_read(&bp->cq_spq_left), atomic_read(&bp->eq_spq_left));
  3268. bnx2x_sp_prod_update(bp);
  3269. spin_unlock_bh(&bp->spq_lock);
  3270. return 0;
  3271. }
  3272. /* acquire split MCP access lock register */
  3273. static int bnx2x_acquire_alr(struct bnx2x *bp)
  3274. {
  3275. u32 j, val;
  3276. int rc = 0;
  3277. might_sleep();
  3278. for (j = 0; j < 1000; j++) {
  3279. REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, MCPR_ACCESS_LOCK_LOCK);
  3280. val = REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK);
  3281. if (val & MCPR_ACCESS_LOCK_LOCK)
  3282. break;
  3283. usleep_range(5000, 10000);
  3284. }
  3285. if (!(val & MCPR_ACCESS_LOCK_LOCK)) {
  3286. BNX2X_ERR("Cannot acquire MCP access lock register\n");
  3287. rc = -EBUSY;
  3288. }
  3289. return rc;
  3290. }
  3291. /* release split MCP access lock register */
  3292. static void bnx2x_release_alr(struct bnx2x *bp)
  3293. {
  3294. REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, 0);
  3295. }
  3296. #define BNX2X_DEF_SB_ATT_IDX 0x0001
  3297. #define BNX2X_DEF_SB_IDX 0x0002
  3298. static u16 bnx2x_update_dsb_idx(struct bnx2x *bp)
  3299. {
  3300. struct host_sp_status_block *def_sb = bp->def_status_blk;
  3301. u16 rc = 0;
  3302. barrier(); /* status block is written to by the chip */
  3303. if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) {
  3304. bp->def_att_idx = def_sb->atten_status_block.attn_bits_index;
  3305. rc |= BNX2X_DEF_SB_ATT_IDX;
  3306. }
  3307. if (bp->def_idx != def_sb->sp_sb.running_index) {
  3308. bp->def_idx = def_sb->sp_sb.running_index;
  3309. rc |= BNX2X_DEF_SB_IDX;
  3310. }
  3311. /* Do not reorder: indices reading should complete before handling */
  3312. barrier();
  3313. return rc;
  3314. }
  3315. /*
  3316. * slow path service functions
  3317. */
  3318. static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted)
  3319. {
  3320. int port = BP_PORT(bp);
  3321. u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  3322. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  3323. u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 :
  3324. NIG_REG_MASK_INTERRUPT_PORT0;
  3325. u32 aeu_mask;
  3326. u32 nig_mask = 0;
  3327. u32 reg_addr;
  3328. if (bp->attn_state & asserted)
  3329. BNX2X_ERR("IGU ERROR\n");
  3330. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3331. aeu_mask = REG_RD(bp, aeu_addr);
  3332. DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n",
  3333. aeu_mask, asserted);
  3334. aeu_mask &= ~(asserted & 0x3ff);
  3335. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  3336. REG_WR(bp, aeu_addr, aeu_mask);
  3337. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3338. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  3339. bp->attn_state |= asserted;
  3340. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  3341. if (asserted & ATTN_HARD_WIRED_MASK) {
  3342. if (asserted & ATTN_NIG_FOR_FUNC) {
  3343. bnx2x_acquire_phy_lock(bp);
  3344. /* save nig interrupt mask */
  3345. nig_mask = REG_RD(bp, nig_int_mask_addr);
  3346. /* If nig_mask is not set, no need to call the update
  3347. * function.
  3348. */
  3349. if (nig_mask) {
  3350. REG_WR(bp, nig_int_mask_addr, 0);
  3351. bnx2x_link_attn(bp);
  3352. }
  3353. /* handle unicore attn? */
  3354. }
  3355. if (asserted & ATTN_SW_TIMER_4_FUNC)
  3356. DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n");
  3357. if (asserted & GPIO_2_FUNC)
  3358. DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n");
  3359. if (asserted & GPIO_3_FUNC)
  3360. DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n");
  3361. if (asserted & GPIO_4_FUNC)
  3362. DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n");
  3363. if (port == 0) {
  3364. if (asserted & ATTN_GENERAL_ATTN_1) {
  3365. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n");
  3366. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0);
  3367. }
  3368. if (asserted & ATTN_GENERAL_ATTN_2) {
  3369. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n");
  3370. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0);
  3371. }
  3372. if (asserted & ATTN_GENERAL_ATTN_3) {
  3373. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n");
  3374. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0);
  3375. }
  3376. } else {
  3377. if (asserted & ATTN_GENERAL_ATTN_4) {
  3378. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n");
  3379. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0);
  3380. }
  3381. if (asserted & ATTN_GENERAL_ATTN_5) {
  3382. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n");
  3383. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0);
  3384. }
  3385. if (asserted & ATTN_GENERAL_ATTN_6) {
  3386. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n");
  3387. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0);
  3388. }
  3389. }
  3390. } /* if hardwired */
  3391. if (bp->common.int_block == INT_BLOCK_HC)
  3392. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  3393. COMMAND_REG_ATTN_BITS_SET);
  3394. else
  3395. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_SET_UPPER*8);
  3396. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", asserted,
  3397. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  3398. REG_WR(bp, reg_addr, asserted);
  3399. /* now set back the mask */
  3400. if (asserted & ATTN_NIG_FOR_FUNC) {
  3401. /* Verify that IGU ack through BAR was written before restoring
  3402. * NIG mask. This loop should exit after 2-3 iterations max.
  3403. */
  3404. if (bp->common.int_block != INT_BLOCK_HC) {
  3405. u32 cnt = 0, igu_acked;
  3406. do {
  3407. igu_acked = REG_RD(bp,
  3408. IGU_REG_ATTENTION_ACK_BITS);
  3409. } while (((igu_acked & ATTN_NIG_FOR_FUNC) == 0) &&
  3410. (++cnt < MAX_IGU_ATTN_ACK_TO));
  3411. if (!igu_acked)
  3412. DP(NETIF_MSG_HW,
  3413. "Failed to verify IGU ack on time\n");
  3414. barrier();
  3415. }
  3416. REG_WR(bp, nig_int_mask_addr, nig_mask);
  3417. bnx2x_release_phy_lock(bp);
  3418. }
  3419. }
  3420. static void bnx2x_fan_failure(struct bnx2x *bp)
  3421. {
  3422. int port = BP_PORT(bp);
  3423. u32 ext_phy_config;
  3424. /* mark the failure */
  3425. ext_phy_config =
  3426. SHMEM_RD(bp,
  3427. dev_info.port_hw_config[port].external_phy_config);
  3428. ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
  3429. ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE;
  3430. SHMEM_WR(bp, dev_info.port_hw_config[port].external_phy_config,
  3431. ext_phy_config);
  3432. /* log the failure */
  3433. netdev_err(bp->dev, "Fan Failure on Network Controller has caused the driver to shutdown the card to prevent permanent damage.\n"
  3434. "Please contact OEM Support for assistance\n");
  3435. /* Schedule device reset (unload)
  3436. * This is due to some boards consuming sufficient power when driver is
  3437. * up to overheat if fan fails.
  3438. */
  3439. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_FAN_FAILURE, 0);
  3440. }
  3441. static void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn)
  3442. {
  3443. int port = BP_PORT(bp);
  3444. int reg_offset;
  3445. u32 val;
  3446. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  3447. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  3448. if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) {
  3449. val = REG_RD(bp, reg_offset);
  3450. val &= ~AEU_INPUTS_ATTN_BITS_SPIO5;
  3451. REG_WR(bp, reg_offset, val);
  3452. BNX2X_ERR("SPIO5 hw attention\n");
  3453. /* Fan failure attention */
  3454. bnx2x_hw_reset_phy(&bp->link_params);
  3455. bnx2x_fan_failure(bp);
  3456. }
  3457. if ((attn & bp->link_vars.aeu_int_mask) && bp->port.pmf) {
  3458. bnx2x_acquire_phy_lock(bp);
  3459. bnx2x_handle_module_detect_int(&bp->link_params);
  3460. bnx2x_release_phy_lock(bp);
  3461. }
  3462. if (attn & HW_INTERRUT_ASSERT_SET_0) {
  3463. val = REG_RD(bp, reg_offset);
  3464. val &= ~(attn & HW_INTERRUT_ASSERT_SET_0);
  3465. REG_WR(bp, reg_offset, val);
  3466. BNX2X_ERR("FATAL HW block attention set0 0x%x\n",
  3467. (u32)(attn & HW_INTERRUT_ASSERT_SET_0));
  3468. bnx2x_panic();
  3469. }
  3470. }
  3471. static void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn)
  3472. {
  3473. u32 val;
  3474. if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) {
  3475. val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR);
  3476. BNX2X_ERR("DB hw attention 0x%x\n", val);
  3477. /* DORQ discard attention */
  3478. if (val & 0x2)
  3479. BNX2X_ERR("FATAL error from DORQ\n");
  3480. }
  3481. if (attn & HW_INTERRUT_ASSERT_SET_1) {
  3482. int port = BP_PORT(bp);
  3483. int reg_offset;
  3484. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 :
  3485. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1);
  3486. val = REG_RD(bp, reg_offset);
  3487. val &= ~(attn & HW_INTERRUT_ASSERT_SET_1);
  3488. REG_WR(bp, reg_offset, val);
  3489. BNX2X_ERR("FATAL HW block attention set1 0x%x\n",
  3490. (u32)(attn & HW_INTERRUT_ASSERT_SET_1));
  3491. bnx2x_panic();
  3492. }
  3493. }
  3494. static void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn)
  3495. {
  3496. u32 val;
  3497. if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) {
  3498. val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR);
  3499. BNX2X_ERR("CFC hw attention 0x%x\n", val);
  3500. /* CFC error attention */
  3501. if (val & 0x2)
  3502. BNX2X_ERR("FATAL error from CFC\n");
  3503. }
  3504. if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) {
  3505. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0);
  3506. BNX2X_ERR("PXP hw attention-0 0x%x\n", val);
  3507. /* RQ_USDMDP_FIFO_OVERFLOW */
  3508. if (val & 0x18000)
  3509. BNX2X_ERR("FATAL error from PXP\n");
  3510. if (!CHIP_IS_E1x(bp)) {
  3511. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_1);
  3512. BNX2X_ERR("PXP hw attention-1 0x%x\n", val);
  3513. }
  3514. }
  3515. if (attn & HW_INTERRUT_ASSERT_SET_2) {
  3516. int port = BP_PORT(bp);
  3517. int reg_offset;
  3518. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 :
  3519. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2);
  3520. val = REG_RD(bp, reg_offset);
  3521. val &= ~(attn & HW_INTERRUT_ASSERT_SET_2);
  3522. REG_WR(bp, reg_offset, val);
  3523. BNX2X_ERR("FATAL HW block attention set2 0x%x\n",
  3524. (u32)(attn & HW_INTERRUT_ASSERT_SET_2));
  3525. bnx2x_panic();
  3526. }
  3527. }
  3528. static void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn)
  3529. {
  3530. u32 val;
  3531. if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) {
  3532. if (attn & BNX2X_PMF_LINK_ASSERT) {
  3533. int func = BP_FUNC(bp);
  3534. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  3535. bnx2x_read_mf_cfg(bp);
  3536. bp->mf_config[BP_VN(bp)] = MF_CFG_RD(bp,
  3537. func_mf_config[BP_ABS_FUNC(bp)].config);
  3538. val = SHMEM_RD(bp,
  3539. func_mb[BP_FW_MB_IDX(bp)].drv_status);
  3540. if (val & (DRV_STATUS_DCC_EVENT_MASK |
  3541. DRV_STATUS_OEM_EVENT_MASK))
  3542. bnx2x_oem_event(bp,
  3543. (val & (DRV_STATUS_DCC_EVENT_MASK |
  3544. DRV_STATUS_OEM_EVENT_MASK)));
  3545. if (val & DRV_STATUS_SET_MF_BW)
  3546. bnx2x_set_mf_bw(bp);
  3547. if (val & DRV_STATUS_DRV_INFO_REQ)
  3548. bnx2x_handle_drv_info_req(bp);
  3549. if (val & DRV_STATUS_VF_DISABLED)
  3550. bnx2x_schedule_iov_task(bp,
  3551. BNX2X_IOV_HANDLE_FLR);
  3552. if ((bp->port.pmf == 0) && (val & DRV_STATUS_PMF))
  3553. bnx2x_pmf_update(bp);
  3554. if (bp->port.pmf &&
  3555. (val & DRV_STATUS_DCBX_NEGOTIATION_RESULTS) &&
  3556. bp->dcbx_enabled > 0)
  3557. /* start dcbx state machine */
  3558. bnx2x_dcbx_set_params(bp,
  3559. BNX2X_DCBX_STATE_NEG_RECEIVED);
  3560. if (val & DRV_STATUS_AFEX_EVENT_MASK)
  3561. bnx2x_handle_afex_cmd(bp,
  3562. val & DRV_STATUS_AFEX_EVENT_MASK);
  3563. if (val & DRV_STATUS_EEE_NEGOTIATION_RESULTS)
  3564. bnx2x_handle_eee_event(bp);
  3565. if (val & DRV_STATUS_OEM_UPDATE_SVID)
  3566. bnx2x_handle_update_svid_cmd(bp);
  3567. if (bp->link_vars.periodic_flags &
  3568. PERIODIC_FLAGS_LINK_EVENT) {
  3569. /* sync with link */
  3570. bnx2x_acquire_phy_lock(bp);
  3571. bp->link_vars.periodic_flags &=
  3572. ~PERIODIC_FLAGS_LINK_EVENT;
  3573. bnx2x_release_phy_lock(bp);
  3574. if (IS_MF(bp))
  3575. bnx2x_link_sync_notify(bp);
  3576. bnx2x_link_report(bp);
  3577. }
  3578. /* Always call it here: bnx2x_link_report() will
  3579. * prevent the link indication duplication.
  3580. */
  3581. bnx2x__link_status_update(bp);
  3582. } else if (attn & BNX2X_MC_ASSERT_BITS) {
  3583. BNX2X_ERR("MC assert!\n");
  3584. bnx2x_mc_assert(bp);
  3585. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0);
  3586. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0);
  3587. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0);
  3588. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0);
  3589. bnx2x_panic();
  3590. } else if (attn & BNX2X_MCP_ASSERT) {
  3591. BNX2X_ERR("MCP assert!\n");
  3592. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0);
  3593. bnx2x_fw_dump(bp);
  3594. } else
  3595. BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn);
  3596. }
  3597. if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) {
  3598. BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn);
  3599. if (attn & BNX2X_GRC_TIMEOUT) {
  3600. val = CHIP_IS_E1(bp) ? 0 :
  3601. REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN);
  3602. BNX2X_ERR("GRC time-out 0x%08x\n", val);
  3603. }
  3604. if (attn & BNX2X_GRC_RSV) {
  3605. val = CHIP_IS_E1(bp) ? 0 :
  3606. REG_RD(bp, MISC_REG_GRC_RSV_ATTN);
  3607. BNX2X_ERR("GRC reserved 0x%08x\n", val);
  3608. }
  3609. REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff);
  3610. }
  3611. }
  3612. /*
  3613. * Bits map:
  3614. * 0-7 - Engine0 load counter.
  3615. * 8-15 - Engine1 load counter.
  3616. * 16 - Engine0 RESET_IN_PROGRESS bit.
  3617. * 17 - Engine1 RESET_IN_PROGRESS bit.
  3618. * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active function
  3619. * on the engine
  3620. * 19 - Engine1 ONE_IS_LOADED.
  3621. * 20 - Chip reset flow bit. When set none-leader must wait for both engines
  3622. * leader to complete (check for both RESET_IN_PROGRESS bits and not for
  3623. * just the one belonging to its engine).
  3624. *
  3625. */
  3626. #define BNX2X_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1
  3627. #define BNX2X_PATH0_LOAD_CNT_MASK 0x000000ff
  3628. #define BNX2X_PATH0_LOAD_CNT_SHIFT 0
  3629. #define BNX2X_PATH1_LOAD_CNT_MASK 0x0000ff00
  3630. #define BNX2X_PATH1_LOAD_CNT_SHIFT 8
  3631. #define BNX2X_PATH0_RST_IN_PROG_BIT 0x00010000
  3632. #define BNX2X_PATH1_RST_IN_PROG_BIT 0x00020000
  3633. #define BNX2X_GLOBAL_RESET_BIT 0x00040000
  3634. /*
  3635. * Set the GLOBAL_RESET bit.
  3636. *
  3637. * Should be run under rtnl lock
  3638. */
  3639. void bnx2x_set_reset_global(struct bnx2x *bp)
  3640. {
  3641. u32 val;
  3642. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3643. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3644. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val | BNX2X_GLOBAL_RESET_BIT);
  3645. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3646. }
  3647. /*
  3648. * Clear the GLOBAL_RESET bit.
  3649. *
  3650. * Should be run under rtnl lock
  3651. */
  3652. static void bnx2x_clear_reset_global(struct bnx2x *bp)
  3653. {
  3654. u32 val;
  3655. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3656. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3657. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~BNX2X_GLOBAL_RESET_BIT));
  3658. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3659. }
  3660. /*
  3661. * Checks the GLOBAL_RESET bit.
  3662. *
  3663. * should be run under rtnl lock
  3664. */
  3665. static bool bnx2x_reset_is_global(struct bnx2x *bp)
  3666. {
  3667. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3668. DP(NETIF_MSG_HW, "GEN_REG_VAL=0x%08x\n", val);
  3669. return (val & BNX2X_GLOBAL_RESET_BIT) ? true : false;
  3670. }
  3671. /*
  3672. * Clear RESET_IN_PROGRESS bit for the current engine.
  3673. *
  3674. * Should be run under rtnl lock
  3675. */
  3676. static void bnx2x_set_reset_done(struct bnx2x *bp)
  3677. {
  3678. u32 val;
  3679. u32 bit = BP_PATH(bp) ?
  3680. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3681. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3682. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3683. /* Clear the bit */
  3684. val &= ~bit;
  3685. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3686. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3687. }
  3688. /*
  3689. * Set RESET_IN_PROGRESS for the current engine.
  3690. *
  3691. * should be run under rtnl lock
  3692. */
  3693. void bnx2x_set_reset_in_progress(struct bnx2x *bp)
  3694. {
  3695. u32 val;
  3696. u32 bit = BP_PATH(bp) ?
  3697. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3698. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3699. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3700. /* Set the bit */
  3701. val |= bit;
  3702. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3703. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3704. }
  3705. /*
  3706. * Checks the RESET_IN_PROGRESS bit for the given engine.
  3707. * should be run under rtnl lock
  3708. */
  3709. bool bnx2x_reset_is_done(struct bnx2x *bp, int engine)
  3710. {
  3711. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3712. u32 bit = engine ?
  3713. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3714. /* return false if bit is set */
  3715. return (val & bit) ? false : true;
  3716. }
  3717. /*
  3718. * set pf load for the current pf.
  3719. *
  3720. * should be run under rtnl lock
  3721. */
  3722. void bnx2x_set_pf_load(struct bnx2x *bp)
  3723. {
  3724. u32 val1, val;
  3725. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3726. BNX2X_PATH0_LOAD_CNT_MASK;
  3727. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3728. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3729. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3730. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3731. DP(NETIF_MSG_IFUP, "Old GEN_REG_VAL=0x%08x\n", val);
  3732. /* get the current counter value */
  3733. val1 = (val & mask) >> shift;
  3734. /* set bit of that PF */
  3735. val1 |= (1 << bp->pf_num);
  3736. /* clear the old value */
  3737. val &= ~mask;
  3738. /* set the new one */
  3739. val |= ((val1 << shift) & mask);
  3740. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3741. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3742. }
  3743. /**
  3744. * bnx2x_clear_pf_load - clear pf load mark
  3745. *
  3746. * @bp: driver handle
  3747. *
  3748. * Should be run under rtnl lock.
  3749. * Decrements the load counter for the current engine. Returns
  3750. * whether other functions are still loaded
  3751. */
  3752. bool bnx2x_clear_pf_load(struct bnx2x *bp)
  3753. {
  3754. u32 val1, val;
  3755. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3756. BNX2X_PATH0_LOAD_CNT_MASK;
  3757. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3758. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3759. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3760. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3761. DP(NETIF_MSG_IFDOWN, "Old GEN_REG_VAL=0x%08x\n", val);
  3762. /* get the current counter value */
  3763. val1 = (val & mask) >> shift;
  3764. /* clear bit of that PF */
  3765. val1 &= ~(1 << bp->pf_num);
  3766. /* clear the old value */
  3767. val &= ~mask;
  3768. /* set the new one */
  3769. val |= ((val1 << shift) & mask);
  3770. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3771. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3772. return val1 != 0;
  3773. }
  3774. /*
  3775. * Read the load status for the current engine.
  3776. *
  3777. * should be run under rtnl lock
  3778. */
  3779. static bool bnx2x_get_load_status(struct bnx2x *bp, int engine)
  3780. {
  3781. u32 mask = (engine ? BNX2X_PATH1_LOAD_CNT_MASK :
  3782. BNX2X_PATH0_LOAD_CNT_MASK);
  3783. u32 shift = (engine ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3784. BNX2X_PATH0_LOAD_CNT_SHIFT);
  3785. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3786. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "GLOB_REG=0x%08x\n", val);
  3787. val = (val & mask) >> shift;
  3788. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "load mask for engine %d = 0x%x\n",
  3789. engine, val);
  3790. return val != 0;
  3791. }
  3792. static void _print_parity(struct bnx2x *bp, u32 reg)
  3793. {
  3794. pr_cont(" [0x%08x] ", REG_RD(bp, reg));
  3795. }
  3796. static void _print_next_block(int idx, const char *blk)
  3797. {
  3798. pr_cont("%s%s", idx ? ", " : "", blk);
  3799. }
  3800. static bool bnx2x_check_blocks_with_parity0(struct bnx2x *bp, u32 sig,
  3801. int *par_num, bool print)
  3802. {
  3803. u32 cur_bit;
  3804. bool res;
  3805. int i;
  3806. res = false;
  3807. for (i = 0; sig; i++) {
  3808. cur_bit = (0x1UL << i);
  3809. if (sig & cur_bit) {
  3810. res |= true; /* Each bit is real error! */
  3811. if (print) {
  3812. switch (cur_bit) {
  3813. case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR:
  3814. _print_next_block((*par_num)++, "BRB");
  3815. _print_parity(bp,
  3816. BRB1_REG_BRB1_PRTY_STS);
  3817. break;
  3818. case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR:
  3819. _print_next_block((*par_num)++,
  3820. "PARSER");
  3821. _print_parity(bp, PRS_REG_PRS_PRTY_STS);
  3822. break;
  3823. case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR:
  3824. _print_next_block((*par_num)++, "TSDM");
  3825. _print_parity(bp,
  3826. TSDM_REG_TSDM_PRTY_STS);
  3827. break;
  3828. case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR:
  3829. _print_next_block((*par_num)++,
  3830. "SEARCHER");
  3831. _print_parity(bp, SRC_REG_SRC_PRTY_STS);
  3832. break;
  3833. case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR:
  3834. _print_next_block((*par_num)++, "TCM");
  3835. _print_parity(bp, TCM_REG_TCM_PRTY_STS);
  3836. break;
  3837. case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR:
  3838. _print_next_block((*par_num)++,
  3839. "TSEMI");
  3840. _print_parity(bp,
  3841. TSEM_REG_TSEM_PRTY_STS_0);
  3842. _print_parity(bp,
  3843. TSEM_REG_TSEM_PRTY_STS_1);
  3844. break;
  3845. case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR:
  3846. _print_next_block((*par_num)++, "XPB");
  3847. _print_parity(bp, GRCBASE_XPB +
  3848. PB_REG_PB_PRTY_STS);
  3849. break;
  3850. }
  3851. }
  3852. /* Clear the bit */
  3853. sig &= ~cur_bit;
  3854. }
  3855. }
  3856. return res;
  3857. }
  3858. static bool bnx2x_check_blocks_with_parity1(struct bnx2x *bp, u32 sig,
  3859. int *par_num, bool *global,
  3860. bool print)
  3861. {
  3862. u32 cur_bit;
  3863. bool res;
  3864. int i;
  3865. res = false;
  3866. for (i = 0; sig; i++) {
  3867. cur_bit = (0x1UL << i);
  3868. if (sig & cur_bit) {
  3869. res |= true; /* Each bit is real error! */
  3870. switch (cur_bit) {
  3871. case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR:
  3872. if (print) {
  3873. _print_next_block((*par_num)++, "PBF");
  3874. _print_parity(bp, PBF_REG_PBF_PRTY_STS);
  3875. }
  3876. break;
  3877. case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR:
  3878. if (print) {
  3879. _print_next_block((*par_num)++, "QM");
  3880. _print_parity(bp, QM_REG_QM_PRTY_STS);
  3881. }
  3882. break;
  3883. case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR:
  3884. if (print) {
  3885. _print_next_block((*par_num)++, "TM");
  3886. _print_parity(bp, TM_REG_TM_PRTY_STS);
  3887. }
  3888. break;
  3889. case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR:
  3890. if (print) {
  3891. _print_next_block((*par_num)++, "XSDM");
  3892. _print_parity(bp,
  3893. XSDM_REG_XSDM_PRTY_STS);
  3894. }
  3895. break;
  3896. case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR:
  3897. if (print) {
  3898. _print_next_block((*par_num)++, "XCM");
  3899. _print_parity(bp, XCM_REG_XCM_PRTY_STS);
  3900. }
  3901. break;
  3902. case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR:
  3903. if (print) {
  3904. _print_next_block((*par_num)++,
  3905. "XSEMI");
  3906. _print_parity(bp,
  3907. XSEM_REG_XSEM_PRTY_STS_0);
  3908. _print_parity(bp,
  3909. XSEM_REG_XSEM_PRTY_STS_1);
  3910. }
  3911. break;
  3912. case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR:
  3913. if (print) {
  3914. _print_next_block((*par_num)++,
  3915. "DOORBELLQ");
  3916. _print_parity(bp,
  3917. DORQ_REG_DORQ_PRTY_STS);
  3918. }
  3919. break;
  3920. case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR:
  3921. if (print) {
  3922. _print_next_block((*par_num)++, "NIG");
  3923. if (CHIP_IS_E1x(bp)) {
  3924. _print_parity(bp,
  3925. NIG_REG_NIG_PRTY_STS);
  3926. } else {
  3927. _print_parity(bp,
  3928. NIG_REG_NIG_PRTY_STS_0);
  3929. _print_parity(bp,
  3930. NIG_REG_NIG_PRTY_STS_1);
  3931. }
  3932. }
  3933. break;
  3934. case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR:
  3935. if (print)
  3936. _print_next_block((*par_num)++,
  3937. "VAUX PCI CORE");
  3938. *global = true;
  3939. break;
  3940. case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR:
  3941. if (print) {
  3942. _print_next_block((*par_num)++,
  3943. "DEBUG");
  3944. _print_parity(bp, DBG_REG_DBG_PRTY_STS);
  3945. }
  3946. break;
  3947. case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR:
  3948. if (print) {
  3949. _print_next_block((*par_num)++, "USDM");
  3950. _print_parity(bp,
  3951. USDM_REG_USDM_PRTY_STS);
  3952. }
  3953. break;
  3954. case AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR:
  3955. if (print) {
  3956. _print_next_block((*par_num)++, "UCM");
  3957. _print_parity(bp, UCM_REG_UCM_PRTY_STS);
  3958. }
  3959. break;
  3960. case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR:
  3961. if (print) {
  3962. _print_next_block((*par_num)++,
  3963. "USEMI");
  3964. _print_parity(bp,
  3965. USEM_REG_USEM_PRTY_STS_0);
  3966. _print_parity(bp,
  3967. USEM_REG_USEM_PRTY_STS_1);
  3968. }
  3969. break;
  3970. case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR:
  3971. if (print) {
  3972. _print_next_block((*par_num)++, "UPB");
  3973. _print_parity(bp, GRCBASE_UPB +
  3974. PB_REG_PB_PRTY_STS);
  3975. }
  3976. break;
  3977. case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR:
  3978. if (print) {
  3979. _print_next_block((*par_num)++, "CSDM");
  3980. _print_parity(bp,
  3981. CSDM_REG_CSDM_PRTY_STS);
  3982. }
  3983. break;
  3984. case AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR:
  3985. if (print) {
  3986. _print_next_block((*par_num)++, "CCM");
  3987. _print_parity(bp, CCM_REG_CCM_PRTY_STS);
  3988. }
  3989. break;
  3990. }
  3991. /* Clear the bit */
  3992. sig &= ~cur_bit;
  3993. }
  3994. }
  3995. return res;
  3996. }
  3997. static bool bnx2x_check_blocks_with_parity2(struct bnx2x *bp, u32 sig,
  3998. int *par_num, bool print)
  3999. {
  4000. u32 cur_bit;
  4001. bool res;
  4002. int i;
  4003. res = false;
  4004. for (i = 0; sig; i++) {
  4005. cur_bit = (0x1UL << i);
  4006. if (sig & cur_bit) {
  4007. res = true; /* Each bit is real error! */
  4008. if (print) {
  4009. switch (cur_bit) {
  4010. case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR:
  4011. _print_next_block((*par_num)++,
  4012. "CSEMI");
  4013. _print_parity(bp,
  4014. CSEM_REG_CSEM_PRTY_STS_0);
  4015. _print_parity(bp,
  4016. CSEM_REG_CSEM_PRTY_STS_1);
  4017. break;
  4018. case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR:
  4019. _print_next_block((*par_num)++, "PXP");
  4020. _print_parity(bp, PXP_REG_PXP_PRTY_STS);
  4021. _print_parity(bp,
  4022. PXP2_REG_PXP2_PRTY_STS_0);
  4023. _print_parity(bp,
  4024. PXP2_REG_PXP2_PRTY_STS_1);
  4025. break;
  4026. case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR:
  4027. _print_next_block((*par_num)++,
  4028. "PXPPCICLOCKCLIENT");
  4029. break;
  4030. case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR:
  4031. _print_next_block((*par_num)++, "CFC");
  4032. _print_parity(bp,
  4033. CFC_REG_CFC_PRTY_STS);
  4034. break;
  4035. case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR:
  4036. _print_next_block((*par_num)++, "CDU");
  4037. _print_parity(bp, CDU_REG_CDU_PRTY_STS);
  4038. break;
  4039. case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR:
  4040. _print_next_block((*par_num)++, "DMAE");
  4041. _print_parity(bp,
  4042. DMAE_REG_DMAE_PRTY_STS);
  4043. break;
  4044. case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR:
  4045. _print_next_block((*par_num)++, "IGU");
  4046. if (CHIP_IS_E1x(bp))
  4047. _print_parity(bp,
  4048. HC_REG_HC_PRTY_STS);
  4049. else
  4050. _print_parity(bp,
  4051. IGU_REG_IGU_PRTY_STS);
  4052. break;
  4053. case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR:
  4054. _print_next_block((*par_num)++, "MISC");
  4055. _print_parity(bp,
  4056. MISC_REG_MISC_PRTY_STS);
  4057. break;
  4058. }
  4059. }
  4060. /* Clear the bit */
  4061. sig &= ~cur_bit;
  4062. }
  4063. }
  4064. return res;
  4065. }
  4066. static bool bnx2x_check_blocks_with_parity3(struct bnx2x *bp, u32 sig,
  4067. int *par_num, bool *global,
  4068. bool print)
  4069. {
  4070. bool res = false;
  4071. u32 cur_bit;
  4072. int i;
  4073. for (i = 0; sig; i++) {
  4074. cur_bit = (0x1UL << i);
  4075. if (sig & cur_bit) {
  4076. switch (cur_bit) {
  4077. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY:
  4078. if (print)
  4079. _print_next_block((*par_num)++,
  4080. "MCP ROM");
  4081. *global = true;
  4082. res = true;
  4083. break;
  4084. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY:
  4085. if (print)
  4086. _print_next_block((*par_num)++,
  4087. "MCP UMP RX");
  4088. *global = true;
  4089. res = true;
  4090. break;
  4091. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY:
  4092. if (print)
  4093. _print_next_block((*par_num)++,
  4094. "MCP UMP TX");
  4095. *global = true;
  4096. res = true;
  4097. break;
  4098. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY:
  4099. if (print)
  4100. _print_next_block((*par_num)++,
  4101. "MCP SCPAD");
  4102. /* clear latched SCPAD PATIRY from MCP */
  4103. REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL,
  4104. 1UL << 10);
  4105. break;
  4106. }
  4107. /* Clear the bit */
  4108. sig &= ~cur_bit;
  4109. }
  4110. }
  4111. return res;
  4112. }
  4113. static bool bnx2x_check_blocks_with_parity4(struct bnx2x *bp, u32 sig,
  4114. int *par_num, bool print)
  4115. {
  4116. u32 cur_bit;
  4117. bool res;
  4118. int i;
  4119. res = false;
  4120. for (i = 0; sig; i++) {
  4121. cur_bit = (0x1UL << i);
  4122. if (sig & cur_bit) {
  4123. res = true; /* Each bit is real error! */
  4124. if (print) {
  4125. switch (cur_bit) {
  4126. case AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR:
  4127. _print_next_block((*par_num)++,
  4128. "PGLUE_B");
  4129. _print_parity(bp,
  4130. PGLUE_B_REG_PGLUE_B_PRTY_STS);
  4131. break;
  4132. case AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR:
  4133. _print_next_block((*par_num)++, "ATC");
  4134. _print_parity(bp,
  4135. ATC_REG_ATC_PRTY_STS);
  4136. break;
  4137. }
  4138. }
  4139. /* Clear the bit */
  4140. sig &= ~cur_bit;
  4141. }
  4142. }
  4143. return res;
  4144. }
  4145. static bool bnx2x_parity_attn(struct bnx2x *bp, bool *global, bool print,
  4146. u32 *sig)
  4147. {
  4148. bool res = false;
  4149. if ((sig[0] & HW_PRTY_ASSERT_SET_0) ||
  4150. (sig[1] & HW_PRTY_ASSERT_SET_1) ||
  4151. (sig[2] & HW_PRTY_ASSERT_SET_2) ||
  4152. (sig[3] & HW_PRTY_ASSERT_SET_3) ||
  4153. (sig[4] & HW_PRTY_ASSERT_SET_4)) {
  4154. int par_num = 0;
  4155. DP(NETIF_MSG_HW, "Was parity error: HW block parity attention:\n"
  4156. "[0]:0x%08x [1]:0x%08x [2]:0x%08x [3]:0x%08x [4]:0x%08x\n",
  4157. sig[0] & HW_PRTY_ASSERT_SET_0,
  4158. sig[1] & HW_PRTY_ASSERT_SET_1,
  4159. sig[2] & HW_PRTY_ASSERT_SET_2,
  4160. sig[3] & HW_PRTY_ASSERT_SET_3,
  4161. sig[4] & HW_PRTY_ASSERT_SET_4);
  4162. if (print)
  4163. netdev_err(bp->dev,
  4164. "Parity errors detected in blocks: ");
  4165. res |= bnx2x_check_blocks_with_parity0(bp,
  4166. sig[0] & HW_PRTY_ASSERT_SET_0, &par_num, print);
  4167. res |= bnx2x_check_blocks_with_parity1(bp,
  4168. sig[1] & HW_PRTY_ASSERT_SET_1, &par_num, global, print);
  4169. res |= bnx2x_check_blocks_with_parity2(bp,
  4170. sig[2] & HW_PRTY_ASSERT_SET_2, &par_num, print);
  4171. res |= bnx2x_check_blocks_with_parity3(bp,
  4172. sig[3] & HW_PRTY_ASSERT_SET_3, &par_num, global, print);
  4173. res |= bnx2x_check_blocks_with_parity4(bp,
  4174. sig[4] & HW_PRTY_ASSERT_SET_4, &par_num, print);
  4175. if (print)
  4176. pr_cont("\n");
  4177. }
  4178. return res;
  4179. }
  4180. /**
  4181. * bnx2x_chk_parity_attn - checks for parity attentions.
  4182. *
  4183. * @bp: driver handle
  4184. * @global: true if there was a global attention
  4185. * @print: show parity attention in syslog
  4186. */
  4187. bool bnx2x_chk_parity_attn(struct bnx2x *bp, bool *global, bool print)
  4188. {
  4189. struct attn_route attn = { {0} };
  4190. int port = BP_PORT(bp);
  4191. attn.sig[0] = REG_RD(bp,
  4192. MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 +
  4193. port*4);
  4194. attn.sig[1] = REG_RD(bp,
  4195. MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 +
  4196. port*4);
  4197. attn.sig[2] = REG_RD(bp,
  4198. MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 +
  4199. port*4);
  4200. attn.sig[3] = REG_RD(bp,
  4201. MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 +
  4202. port*4);
  4203. /* Since MCP attentions can't be disabled inside the block, we need to
  4204. * read AEU registers to see whether they're currently disabled
  4205. */
  4206. attn.sig[3] &= ((REG_RD(bp,
  4207. !port ? MISC_REG_AEU_ENABLE4_FUNC_0_OUT_0
  4208. : MISC_REG_AEU_ENABLE4_FUNC_1_OUT_0) &
  4209. MISC_AEU_ENABLE_MCP_PRTY_BITS) |
  4210. ~MISC_AEU_ENABLE_MCP_PRTY_BITS);
  4211. if (!CHIP_IS_E1x(bp))
  4212. attn.sig[4] = REG_RD(bp,
  4213. MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 +
  4214. port*4);
  4215. return bnx2x_parity_attn(bp, global, print, attn.sig);
  4216. }
  4217. static void bnx2x_attn_int_deasserted4(struct bnx2x *bp, u32 attn)
  4218. {
  4219. u32 val;
  4220. if (attn & AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT) {
  4221. val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS_CLR);
  4222. BNX2X_ERR("PGLUE hw attention 0x%x\n", val);
  4223. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR)
  4224. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR\n");
  4225. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR)
  4226. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR\n");
  4227. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN)
  4228. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN\n");
  4229. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN)
  4230. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN\n");
  4231. if (val &
  4232. PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN)
  4233. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN\n");
  4234. if (val &
  4235. PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN)
  4236. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN\n");
  4237. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN)
  4238. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN\n");
  4239. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN)
  4240. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN\n");
  4241. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW)
  4242. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW\n");
  4243. }
  4244. if (attn & AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT) {
  4245. val = REG_RD(bp, ATC_REG_ATC_INT_STS_CLR);
  4246. BNX2X_ERR("ATC hw attention 0x%x\n", val);
  4247. if (val & ATC_ATC_INT_STS_REG_ADDRESS_ERROR)
  4248. BNX2X_ERR("ATC_ATC_INT_STS_REG_ADDRESS_ERROR\n");
  4249. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND)
  4250. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND\n");
  4251. if (val & ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS)
  4252. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS\n");
  4253. if (val & ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT)
  4254. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT\n");
  4255. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR)
  4256. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR\n");
  4257. if (val & ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU)
  4258. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU\n");
  4259. }
  4260. if (attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  4261. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)) {
  4262. BNX2X_ERR("FATAL parity attention set4 0x%x\n",
  4263. (u32)(attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  4264. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)));
  4265. }
  4266. }
  4267. static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted)
  4268. {
  4269. struct attn_route attn, *group_mask;
  4270. int port = BP_PORT(bp);
  4271. int index;
  4272. u32 reg_addr;
  4273. u32 val;
  4274. u32 aeu_mask;
  4275. bool global = false;
  4276. /* need to take HW lock because MCP or other port might also
  4277. try to handle this event */
  4278. bnx2x_acquire_alr(bp);
  4279. if (bnx2x_chk_parity_attn(bp, &global, true)) {
  4280. #ifndef BNX2X_STOP_ON_ERROR
  4281. bp->recovery_state = BNX2X_RECOVERY_INIT;
  4282. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  4283. /* Disable HW interrupts */
  4284. bnx2x_int_disable(bp);
  4285. /* In case of parity errors don't handle attentions so that
  4286. * other function would "see" parity errors.
  4287. */
  4288. #else
  4289. bnx2x_panic();
  4290. #endif
  4291. bnx2x_release_alr(bp);
  4292. return;
  4293. }
  4294. attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
  4295. attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
  4296. attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
  4297. attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
  4298. if (!CHIP_IS_E1x(bp))
  4299. attn.sig[4] =
  4300. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4);
  4301. else
  4302. attn.sig[4] = 0;
  4303. DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x %08x\n",
  4304. attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3], attn.sig[4]);
  4305. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  4306. if (deasserted & (1 << index)) {
  4307. group_mask = &bp->attn_group[index];
  4308. DP(NETIF_MSG_HW, "group[%d]: %08x %08x %08x %08x %08x\n",
  4309. index,
  4310. group_mask->sig[0], group_mask->sig[1],
  4311. group_mask->sig[2], group_mask->sig[3],
  4312. group_mask->sig[4]);
  4313. bnx2x_attn_int_deasserted4(bp,
  4314. attn.sig[4] & group_mask->sig[4]);
  4315. bnx2x_attn_int_deasserted3(bp,
  4316. attn.sig[3] & group_mask->sig[3]);
  4317. bnx2x_attn_int_deasserted1(bp,
  4318. attn.sig[1] & group_mask->sig[1]);
  4319. bnx2x_attn_int_deasserted2(bp,
  4320. attn.sig[2] & group_mask->sig[2]);
  4321. bnx2x_attn_int_deasserted0(bp,
  4322. attn.sig[0] & group_mask->sig[0]);
  4323. }
  4324. }
  4325. bnx2x_release_alr(bp);
  4326. if (bp->common.int_block == INT_BLOCK_HC)
  4327. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  4328. COMMAND_REG_ATTN_BITS_CLR);
  4329. else
  4330. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_CLR_UPPER*8);
  4331. val = ~deasserted;
  4332. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", val,
  4333. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  4334. REG_WR(bp, reg_addr, val);
  4335. if (~bp->attn_state & deasserted)
  4336. BNX2X_ERR("IGU ERROR\n");
  4337. reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  4338. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  4339. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  4340. aeu_mask = REG_RD(bp, reg_addr);
  4341. DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n",
  4342. aeu_mask, deasserted);
  4343. aeu_mask |= (deasserted & 0x3ff);
  4344. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  4345. REG_WR(bp, reg_addr, aeu_mask);
  4346. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  4347. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  4348. bp->attn_state &= ~deasserted;
  4349. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  4350. }
  4351. static void bnx2x_attn_int(struct bnx2x *bp)
  4352. {
  4353. /* read local copy of bits */
  4354. u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block.
  4355. attn_bits);
  4356. u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block.
  4357. attn_bits_ack);
  4358. u32 attn_state = bp->attn_state;
  4359. /* look for changed bits */
  4360. u32 asserted = attn_bits & ~attn_ack & ~attn_state;
  4361. u32 deasserted = ~attn_bits & attn_ack & attn_state;
  4362. DP(NETIF_MSG_HW,
  4363. "attn_bits %x attn_ack %x asserted %x deasserted %x\n",
  4364. attn_bits, attn_ack, asserted, deasserted);
  4365. if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state))
  4366. BNX2X_ERR("BAD attention state\n");
  4367. /* handle bits that were raised */
  4368. if (asserted)
  4369. bnx2x_attn_int_asserted(bp, asserted);
  4370. if (deasserted)
  4371. bnx2x_attn_int_deasserted(bp, deasserted);
  4372. }
  4373. void bnx2x_igu_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 segment,
  4374. u16 index, u8 op, u8 update)
  4375. {
  4376. u32 igu_addr = bp->igu_base_addr;
  4377. igu_addr += (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8;
  4378. bnx2x_igu_ack_sb_gen(bp, igu_sb_id, segment, index, op, update,
  4379. igu_addr);
  4380. }
  4381. static void bnx2x_update_eq_prod(struct bnx2x *bp, u16 prod)
  4382. {
  4383. /* No memory barriers */
  4384. storm_memset_eq_prod(bp, prod, BP_FUNC(bp));
  4385. mmiowb(); /* keep prod updates ordered */
  4386. }
  4387. static int bnx2x_cnic_handle_cfc_del(struct bnx2x *bp, u32 cid,
  4388. union event_ring_elem *elem)
  4389. {
  4390. u8 err = elem->message.error;
  4391. if (!bp->cnic_eth_dev.starting_cid ||
  4392. (cid < bp->cnic_eth_dev.starting_cid &&
  4393. cid != bp->cnic_eth_dev.iscsi_l2_cid))
  4394. return 1;
  4395. DP(BNX2X_MSG_SP, "got delete ramrod for CNIC CID %d\n", cid);
  4396. if (unlikely(err)) {
  4397. BNX2X_ERR("got delete ramrod for CNIC CID %d with error!\n",
  4398. cid);
  4399. bnx2x_panic_dump(bp, false);
  4400. }
  4401. bnx2x_cnic_cfc_comp(bp, cid, err);
  4402. return 0;
  4403. }
  4404. static void bnx2x_handle_mcast_eqe(struct bnx2x *bp)
  4405. {
  4406. struct bnx2x_mcast_ramrod_params rparam;
  4407. int rc;
  4408. memset(&rparam, 0, sizeof(rparam));
  4409. rparam.mcast_obj = &bp->mcast_obj;
  4410. netif_addr_lock_bh(bp->dev);
  4411. /* Clear pending state for the last command */
  4412. bp->mcast_obj.raw.clear_pending(&bp->mcast_obj.raw);
  4413. /* If there are pending mcast commands - send them */
  4414. if (bp->mcast_obj.check_pending(&bp->mcast_obj)) {
  4415. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT);
  4416. if (rc < 0)
  4417. BNX2X_ERR("Failed to send pending mcast commands: %d\n",
  4418. rc);
  4419. }
  4420. netif_addr_unlock_bh(bp->dev);
  4421. }
  4422. static void bnx2x_handle_classification_eqe(struct bnx2x *bp,
  4423. union event_ring_elem *elem)
  4424. {
  4425. unsigned long ramrod_flags = 0;
  4426. int rc = 0;
  4427. u32 cid = elem->message.data.eth_event.echo & BNX2X_SWCID_MASK;
  4428. struct bnx2x_vlan_mac_obj *vlan_mac_obj;
  4429. /* Always push next commands out, don't wait here */
  4430. __set_bit(RAMROD_CONT, &ramrod_flags);
  4431. switch (le32_to_cpu((__force __le32)elem->message.data.eth_event.echo)
  4432. >> BNX2X_SWCID_SHIFT) {
  4433. case BNX2X_FILTER_MAC_PENDING:
  4434. DP(BNX2X_MSG_SP, "Got SETUP_MAC completions\n");
  4435. if (CNIC_LOADED(bp) && (cid == BNX2X_ISCSI_ETH_CID(bp)))
  4436. vlan_mac_obj = &bp->iscsi_l2_mac_obj;
  4437. else
  4438. vlan_mac_obj = &bp->sp_objs[cid].mac_obj;
  4439. break;
  4440. case BNX2X_FILTER_MCAST_PENDING:
  4441. DP(BNX2X_MSG_SP, "Got SETUP_MCAST completions\n");
  4442. /* This is only relevant for 57710 where multicast MACs are
  4443. * configured as unicast MACs using the same ramrod.
  4444. */
  4445. bnx2x_handle_mcast_eqe(bp);
  4446. return;
  4447. default:
  4448. BNX2X_ERR("Unsupported classification command: %d\n",
  4449. elem->message.data.eth_event.echo);
  4450. return;
  4451. }
  4452. rc = vlan_mac_obj->complete(bp, vlan_mac_obj, elem, &ramrod_flags);
  4453. if (rc < 0)
  4454. BNX2X_ERR("Failed to schedule new commands: %d\n", rc);
  4455. else if (rc > 0)
  4456. DP(BNX2X_MSG_SP, "Scheduled next pending commands...\n");
  4457. }
  4458. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start);
  4459. static void bnx2x_handle_rx_mode_eqe(struct bnx2x *bp)
  4460. {
  4461. netif_addr_lock_bh(bp->dev);
  4462. clear_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  4463. /* Send rx_mode command again if was requested */
  4464. if (test_and_clear_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state))
  4465. bnx2x_set_storm_rx_mode(bp);
  4466. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED,
  4467. &bp->sp_state))
  4468. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  4469. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED,
  4470. &bp->sp_state))
  4471. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  4472. netif_addr_unlock_bh(bp->dev);
  4473. }
  4474. static void bnx2x_after_afex_vif_lists(struct bnx2x *bp,
  4475. union event_ring_elem *elem)
  4476. {
  4477. if (elem->message.data.vif_list_event.echo == VIF_LIST_RULE_GET) {
  4478. DP(BNX2X_MSG_SP,
  4479. "afex: ramrod completed VIF LIST_GET, addrs 0x%x\n",
  4480. elem->message.data.vif_list_event.func_bit_map);
  4481. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTGET_ACK,
  4482. elem->message.data.vif_list_event.func_bit_map);
  4483. } else if (elem->message.data.vif_list_event.echo ==
  4484. VIF_LIST_RULE_SET) {
  4485. DP(BNX2X_MSG_SP, "afex: ramrod completed VIF LIST_SET\n");
  4486. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTSET_ACK, 0);
  4487. }
  4488. }
  4489. /* called with rtnl_lock */
  4490. static void bnx2x_after_function_update(struct bnx2x *bp)
  4491. {
  4492. int q, rc;
  4493. struct bnx2x_fastpath *fp;
  4494. struct bnx2x_queue_state_params queue_params = {NULL};
  4495. struct bnx2x_queue_update_params *q_update_params =
  4496. &queue_params.params.update;
  4497. /* Send Q update command with afex vlan removal values for all Qs */
  4498. queue_params.cmd = BNX2X_Q_CMD_UPDATE;
  4499. /* set silent vlan removal values according to vlan mode */
  4500. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM_CHNG,
  4501. &q_update_params->update_flags);
  4502. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM,
  4503. &q_update_params->update_flags);
  4504. __set_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
  4505. /* in access mode mark mask and value are 0 to strip all vlans */
  4506. if (bp->afex_vlan_mode == FUNC_MF_CFG_AFEX_VLAN_ACCESS_MODE) {
  4507. q_update_params->silent_removal_value = 0;
  4508. q_update_params->silent_removal_mask = 0;
  4509. } else {
  4510. q_update_params->silent_removal_value =
  4511. (bp->afex_def_vlan_tag & VLAN_VID_MASK);
  4512. q_update_params->silent_removal_mask = VLAN_VID_MASK;
  4513. }
  4514. for_each_eth_queue(bp, q) {
  4515. /* Set the appropriate Queue object */
  4516. fp = &bp->fp[q];
  4517. queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  4518. /* send the ramrod */
  4519. rc = bnx2x_queue_state_change(bp, &queue_params);
  4520. if (rc < 0)
  4521. BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
  4522. q);
  4523. }
  4524. if (!NO_FCOE(bp) && CNIC_ENABLED(bp)) {
  4525. fp = &bp->fp[FCOE_IDX(bp)];
  4526. queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  4527. /* clear pending completion bit */
  4528. __clear_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
  4529. /* mark latest Q bit */
  4530. smp_mb__before_atomic();
  4531. set_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
  4532. smp_mb__after_atomic();
  4533. /* send Q update ramrod for FCoE Q */
  4534. rc = bnx2x_queue_state_change(bp, &queue_params);
  4535. if (rc < 0)
  4536. BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
  4537. q);
  4538. } else {
  4539. /* If no FCoE ring - ACK MCP now */
  4540. bnx2x_link_report(bp);
  4541. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  4542. }
  4543. }
  4544. static struct bnx2x_queue_sp_obj *bnx2x_cid_to_q_obj(
  4545. struct bnx2x *bp, u32 cid)
  4546. {
  4547. DP(BNX2X_MSG_SP, "retrieving fp from cid %d\n", cid);
  4548. if (CNIC_LOADED(bp) && (cid == BNX2X_FCOE_ETH_CID(bp)))
  4549. return &bnx2x_fcoe_sp_obj(bp, q_obj);
  4550. else
  4551. return &bp->sp_objs[CID_TO_FP(cid, bp)].q_obj;
  4552. }
  4553. static void bnx2x_eq_int(struct bnx2x *bp)
  4554. {
  4555. u16 hw_cons, sw_cons, sw_prod;
  4556. union event_ring_elem *elem;
  4557. u8 echo;
  4558. u32 cid;
  4559. u8 opcode;
  4560. int rc, spqe_cnt = 0;
  4561. struct bnx2x_queue_sp_obj *q_obj;
  4562. struct bnx2x_func_sp_obj *f_obj = &bp->func_obj;
  4563. struct bnx2x_raw_obj *rss_raw = &bp->rss_conf_obj.raw;
  4564. hw_cons = le16_to_cpu(*bp->eq_cons_sb);
  4565. /* The hw_cos range is 1-255, 257 - the sw_cons range is 0-254, 256.
  4566. * when we get the next-page we need to adjust so the loop
  4567. * condition below will be met. The next element is the size of a
  4568. * regular element and hence incrementing by 1
  4569. */
  4570. if ((hw_cons & EQ_DESC_MAX_PAGE) == EQ_DESC_MAX_PAGE)
  4571. hw_cons++;
  4572. /* This function may never run in parallel with itself for a
  4573. * specific bp, thus there is no need in "paired" read memory
  4574. * barrier here.
  4575. */
  4576. sw_cons = bp->eq_cons;
  4577. sw_prod = bp->eq_prod;
  4578. DP(BNX2X_MSG_SP, "EQ: hw_cons %u sw_cons %u bp->eq_spq_left %x\n",
  4579. hw_cons, sw_cons, atomic_read(&bp->eq_spq_left));
  4580. for (; sw_cons != hw_cons;
  4581. sw_prod = NEXT_EQ_IDX(sw_prod), sw_cons = NEXT_EQ_IDX(sw_cons)) {
  4582. elem = &bp->eq_ring[EQ_DESC(sw_cons)];
  4583. rc = bnx2x_iov_eq_sp_event(bp, elem);
  4584. if (!rc) {
  4585. DP(BNX2X_MSG_IOV, "bnx2x_iov_eq_sp_event returned %d\n",
  4586. rc);
  4587. goto next_spqe;
  4588. }
  4589. /* elem CID originates from FW; actually LE */
  4590. cid = SW_CID((__force __le32)
  4591. elem->message.data.cfc_del_event.cid);
  4592. opcode = elem->message.opcode;
  4593. /* handle eq element */
  4594. switch (opcode) {
  4595. case EVENT_RING_OPCODE_VF_PF_CHANNEL:
  4596. bnx2x_vf_mbx_schedule(bp,
  4597. &elem->message.data.vf_pf_event);
  4598. continue;
  4599. case EVENT_RING_OPCODE_STAT_QUERY:
  4600. DP_AND((BNX2X_MSG_SP | BNX2X_MSG_STATS),
  4601. "got statistics comp event %d\n",
  4602. bp->stats_comp++);
  4603. /* nothing to do with stats comp */
  4604. goto next_spqe;
  4605. case EVENT_RING_OPCODE_CFC_DEL:
  4606. /* handle according to cid range */
  4607. /*
  4608. * we may want to verify here that the bp state is
  4609. * HALTING
  4610. */
  4611. DP(BNX2X_MSG_SP,
  4612. "got delete ramrod for MULTI[%d]\n", cid);
  4613. if (CNIC_LOADED(bp) &&
  4614. !bnx2x_cnic_handle_cfc_del(bp, cid, elem))
  4615. goto next_spqe;
  4616. q_obj = bnx2x_cid_to_q_obj(bp, cid);
  4617. if (q_obj->complete_cmd(bp, q_obj, BNX2X_Q_CMD_CFC_DEL))
  4618. break;
  4619. goto next_spqe;
  4620. case EVENT_RING_OPCODE_STOP_TRAFFIC:
  4621. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got STOP TRAFFIC\n");
  4622. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_PAUSED);
  4623. if (f_obj->complete_cmd(bp, f_obj,
  4624. BNX2X_F_CMD_TX_STOP))
  4625. break;
  4626. goto next_spqe;
  4627. case EVENT_RING_OPCODE_START_TRAFFIC:
  4628. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got START TRAFFIC\n");
  4629. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_RELEASED);
  4630. if (f_obj->complete_cmd(bp, f_obj,
  4631. BNX2X_F_CMD_TX_START))
  4632. break;
  4633. goto next_spqe;
  4634. case EVENT_RING_OPCODE_FUNCTION_UPDATE:
  4635. echo = elem->message.data.function_update_event.echo;
  4636. if (echo == SWITCH_UPDATE) {
  4637. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4638. "got FUNC_SWITCH_UPDATE ramrod\n");
  4639. if (f_obj->complete_cmd(
  4640. bp, f_obj, BNX2X_F_CMD_SWITCH_UPDATE))
  4641. break;
  4642. } else {
  4643. int cmd = BNX2X_SP_RTNL_AFEX_F_UPDATE;
  4644. DP(BNX2X_MSG_SP | BNX2X_MSG_MCP,
  4645. "AFEX: ramrod completed FUNCTION_UPDATE\n");
  4646. f_obj->complete_cmd(bp, f_obj,
  4647. BNX2X_F_CMD_AFEX_UPDATE);
  4648. /* We will perform the Queues update from
  4649. * sp_rtnl task as all Queue SP operations
  4650. * should run under rtnl_lock.
  4651. */
  4652. bnx2x_schedule_sp_rtnl(bp, cmd, 0);
  4653. }
  4654. goto next_spqe;
  4655. case EVENT_RING_OPCODE_AFEX_VIF_LISTS:
  4656. f_obj->complete_cmd(bp, f_obj,
  4657. BNX2X_F_CMD_AFEX_VIFLISTS);
  4658. bnx2x_after_afex_vif_lists(bp, elem);
  4659. goto next_spqe;
  4660. case EVENT_RING_OPCODE_FUNCTION_START:
  4661. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4662. "got FUNC_START ramrod\n");
  4663. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_START))
  4664. break;
  4665. goto next_spqe;
  4666. case EVENT_RING_OPCODE_FUNCTION_STOP:
  4667. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4668. "got FUNC_STOP ramrod\n");
  4669. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_STOP))
  4670. break;
  4671. goto next_spqe;
  4672. case EVENT_RING_OPCODE_SET_TIMESYNC:
  4673. DP(BNX2X_MSG_SP | BNX2X_MSG_PTP,
  4674. "got set_timesync ramrod completion\n");
  4675. if (f_obj->complete_cmd(bp, f_obj,
  4676. BNX2X_F_CMD_SET_TIMESYNC))
  4677. break;
  4678. goto next_spqe;
  4679. }
  4680. switch (opcode | bp->state) {
  4681. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4682. BNX2X_STATE_OPEN):
  4683. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4684. BNX2X_STATE_OPENING_WAIT4_PORT):
  4685. cid = elem->message.data.eth_event.echo &
  4686. BNX2X_SWCID_MASK;
  4687. DP(BNX2X_MSG_SP, "got RSS_UPDATE ramrod. CID %d\n",
  4688. cid);
  4689. rss_raw->clear_pending(rss_raw);
  4690. break;
  4691. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_OPEN):
  4692. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_DIAG):
  4693. case (EVENT_RING_OPCODE_SET_MAC |
  4694. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4695. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4696. BNX2X_STATE_OPEN):
  4697. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4698. BNX2X_STATE_DIAG):
  4699. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4700. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4701. DP(BNX2X_MSG_SP, "got (un)set mac ramrod\n");
  4702. bnx2x_handle_classification_eqe(bp, elem);
  4703. break;
  4704. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4705. BNX2X_STATE_OPEN):
  4706. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4707. BNX2X_STATE_DIAG):
  4708. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4709. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4710. DP(BNX2X_MSG_SP, "got mcast ramrod\n");
  4711. bnx2x_handle_mcast_eqe(bp);
  4712. break;
  4713. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4714. BNX2X_STATE_OPEN):
  4715. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4716. BNX2X_STATE_DIAG):
  4717. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4718. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4719. DP(BNX2X_MSG_SP, "got rx_mode ramrod\n");
  4720. bnx2x_handle_rx_mode_eqe(bp);
  4721. break;
  4722. default:
  4723. /* unknown event log error and continue */
  4724. BNX2X_ERR("Unknown EQ event %d, bp->state 0x%x\n",
  4725. elem->message.opcode, bp->state);
  4726. }
  4727. next_spqe:
  4728. spqe_cnt++;
  4729. } /* for */
  4730. smp_mb__before_atomic();
  4731. atomic_add(spqe_cnt, &bp->eq_spq_left);
  4732. bp->eq_cons = sw_cons;
  4733. bp->eq_prod = sw_prod;
  4734. /* Make sure that above mem writes were issued towards the memory */
  4735. smp_wmb();
  4736. /* update producer */
  4737. bnx2x_update_eq_prod(bp, bp->eq_prod);
  4738. }
  4739. static void bnx2x_sp_task(struct work_struct *work)
  4740. {
  4741. struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work);
  4742. DP(BNX2X_MSG_SP, "sp task invoked\n");
  4743. /* make sure the atomic interrupt_occurred has been written */
  4744. smp_rmb();
  4745. if (atomic_read(&bp->interrupt_occurred)) {
  4746. /* what work needs to be performed? */
  4747. u16 status = bnx2x_update_dsb_idx(bp);
  4748. DP(BNX2X_MSG_SP, "status %x\n", status);
  4749. DP(BNX2X_MSG_SP, "setting interrupt_occurred to 0\n");
  4750. atomic_set(&bp->interrupt_occurred, 0);
  4751. /* HW attentions */
  4752. if (status & BNX2X_DEF_SB_ATT_IDX) {
  4753. bnx2x_attn_int(bp);
  4754. status &= ~BNX2X_DEF_SB_ATT_IDX;
  4755. }
  4756. /* SP events: STAT_QUERY and others */
  4757. if (status & BNX2X_DEF_SB_IDX) {
  4758. struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
  4759. if (FCOE_INIT(bp) &&
  4760. (bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp))) {
  4761. /* Prevent local bottom-halves from running as
  4762. * we are going to change the local NAPI list.
  4763. */
  4764. local_bh_disable();
  4765. napi_schedule(&bnx2x_fcoe(bp, napi));
  4766. local_bh_enable();
  4767. }
  4768. /* Handle EQ completions */
  4769. bnx2x_eq_int(bp);
  4770. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID,
  4771. le16_to_cpu(bp->def_idx), IGU_INT_NOP, 1);
  4772. status &= ~BNX2X_DEF_SB_IDX;
  4773. }
  4774. /* if status is non zero then perhaps something went wrong */
  4775. if (unlikely(status))
  4776. DP(BNX2X_MSG_SP,
  4777. "got an unknown interrupt! (status 0x%x)\n", status);
  4778. /* ack status block only if something was actually handled */
  4779. bnx2x_ack_sb(bp, bp->igu_dsb_id, ATTENTION_ID,
  4780. le16_to_cpu(bp->def_att_idx), IGU_INT_ENABLE, 1);
  4781. }
  4782. /* afex - poll to check if VIFSET_ACK should be sent to MFW */
  4783. if (test_and_clear_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK,
  4784. &bp->sp_state)) {
  4785. bnx2x_link_report(bp);
  4786. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  4787. }
  4788. }
  4789. irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance)
  4790. {
  4791. struct net_device *dev = dev_instance;
  4792. struct bnx2x *bp = netdev_priv(dev);
  4793. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0,
  4794. IGU_INT_DISABLE, 0);
  4795. #ifdef BNX2X_STOP_ON_ERROR
  4796. if (unlikely(bp->panic))
  4797. return IRQ_HANDLED;
  4798. #endif
  4799. if (CNIC_LOADED(bp)) {
  4800. struct cnic_ops *c_ops;
  4801. rcu_read_lock();
  4802. c_ops = rcu_dereference(bp->cnic_ops);
  4803. if (c_ops)
  4804. c_ops->cnic_handler(bp->cnic_data, NULL);
  4805. rcu_read_unlock();
  4806. }
  4807. /* schedule sp task to perform default status block work, ack
  4808. * attentions and enable interrupts.
  4809. */
  4810. bnx2x_schedule_sp_task(bp);
  4811. return IRQ_HANDLED;
  4812. }
  4813. /* end of slow path */
  4814. void bnx2x_drv_pulse(struct bnx2x *bp)
  4815. {
  4816. SHMEM_WR(bp, func_mb[BP_FW_MB_IDX(bp)].drv_pulse_mb,
  4817. bp->fw_drv_pulse_wr_seq);
  4818. }
  4819. static void bnx2x_timer(unsigned long data)
  4820. {
  4821. struct bnx2x *bp = (struct bnx2x *) data;
  4822. if (!netif_running(bp->dev))
  4823. return;
  4824. if (IS_PF(bp) &&
  4825. !BP_NOMCP(bp)) {
  4826. int mb_idx = BP_FW_MB_IDX(bp);
  4827. u16 drv_pulse;
  4828. u16 mcp_pulse;
  4829. ++bp->fw_drv_pulse_wr_seq;
  4830. bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK;
  4831. drv_pulse = bp->fw_drv_pulse_wr_seq;
  4832. bnx2x_drv_pulse(bp);
  4833. mcp_pulse = (SHMEM_RD(bp, func_mb[mb_idx].mcp_pulse_mb) &
  4834. MCP_PULSE_SEQ_MASK);
  4835. /* The delta between driver pulse and mcp response
  4836. * should not get too big. If the MFW is more than 5 pulses
  4837. * behind, we should worry about it enough to generate an error
  4838. * log.
  4839. */
  4840. if (((drv_pulse - mcp_pulse) & MCP_PULSE_SEQ_MASK) > 5)
  4841. BNX2X_ERR("MFW seems hanged: drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
  4842. drv_pulse, mcp_pulse);
  4843. }
  4844. if (bp->state == BNX2X_STATE_OPEN)
  4845. bnx2x_stats_handle(bp, STATS_EVENT_UPDATE);
  4846. /* sample pf vf bulletin board for new posts from pf */
  4847. if (IS_VF(bp))
  4848. bnx2x_timer_sriov(bp);
  4849. mod_timer(&bp->timer, jiffies + bp->current_interval);
  4850. }
  4851. /* end of Statistics */
  4852. /* nic init */
  4853. /*
  4854. * nic init service functions
  4855. */
  4856. static void bnx2x_fill(struct bnx2x *bp, u32 addr, int fill, u32 len)
  4857. {
  4858. u32 i;
  4859. if (!(len%4) && !(addr%4))
  4860. for (i = 0; i < len; i += 4)
  4861. REG_WR(bp, addr + i, fill);
  4862. else
  4863. for (i = 0; i < len; i++)
  4864. REG_WR8(bp, addr + i, fill);
  4865. }
  4866. /* helper: writes FP SP data to FW - data_size in dwords */
  4867. static void bnx2x_wr_fp_sb_data(struct bnx2x *bp,
  4868. int fw_sb_id,
  4869. u32 *sb_data_p,
  4870. u32 data_size)
  4871. {
  4872. int index;
  4873. for (index = 0; index < data_size; index++)
  4874. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4875. CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id) +
  4876. sizeof(u32)*index,
  4877. *(sb_data_p + index));
  4878. }
  4879. static void bnx2x_zero_fp_sb(struct bnx2x *bp, int fw_sb_id)
  4880. {
  4881. u32 *sb_data_p;
  4882. u32 data_size = 0;
  4883. struct hc_status_block_data_e2 sb_data_e2;
  4884. struct hc_status_block_data_e1x sb_data_e1x;
  4885. /* disable the function first */
  4886. if (!CHIP_IS_E1x(bp)) {
  4887. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  4888. sb_data_e2.common.state = SB_DISABLED;
  4889. sb_data_e2.common.p_func.vf_valid = false;
  4890. sb_data_p = (u32 *)&sb_data_e2;
  4891. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  4892. } else {
  4893. memset(&sb_data_e1x, 0,
  4894. sizeof(struct hc_status_block_data_e1x));
  4895. sb_data_e1x.common.state = SB_DISABLED;
  4896. sb_data_e1x.common.p_func.vf_valid = false;
  4897. sb_data_p = (u32 *)&sb_data_e1x;
  4898. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  4899. }
  4900. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  4901. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4902. CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id), 0,
  4903. CSTORM_STATUS_BLOCK_SIZE);
  4904. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4905. CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id), 0,
  4906. CSTORM_SYNC_BLOCK_SIZE);
  4907. }
  4908. /* helper: writes SP SB data to FW */
  4909. static void bnx2x_wr_sp_sb_data(struct bnx2x *bp,
  4910. struct hc_sp_status_block_data *sp_sb_data)
  4911. {
  4912. int func = BP_FUNC(bp);
  4913. int i;
  4914. for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
  4915. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4916. CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
  4917. i*sizeof(u32),
  4918. *((u32 *)sp_sb_data + i));
  4919. }
  4920. static void bnx2x_zero_sp_sb(struct bnx2x *bp)
  4921. {
  4922. int func = BP_FUNC(bp);
  4923. struct hc_sp_status_block_data sp_sb_data;
  4924. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  4925. sp_sb_data.state = SB_DISABLED;
  4926. sp_sb_data.p_func.vf_valid = false;
  4927. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  4928. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4929. CSTORM_SP_STATUS_BLOCK_OFFSET(func), 0,
  4930. CSTORM_SP_STATUS_BLOCK_SIZE);
  4931. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4932. CSTORM_SP_SYNC_BLOCK_OFFSET(func), 0,
  4933. CSTORM_SP_SYNC_BLOCK_SIZE);
  4934. }
  4935. static void bnx2x_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm,
  4936. int igu_sb_id, int igu_seg_id)
  4937. {
  4938. hc_sm->igu_sb_id = igu_sb_id;
  4939. hc_sm->igu_seg_id = igu_seg_id;
  4940. hc_sm->timer_value = 0xFF;
  4941. hc_sm->time_to_expire = 0xFFFFFFFF;
  4942. }
  4943. /* allocates state machine ids. */
  4944. static void bnx2x_map_sb_state_machines(struct hc_index_data *index_data)
  4945. {
  4946. /* zero out state machine indices */
  4947. /* rx indices */
  4948. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4949. /* tx indices */
  4950. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4951. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags &= ~HC_INDEX_DATA_SM_ID;
  4952. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags &= ~HC_INDEX_DATA_SM_ID;
  4953. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags &= ~HC_INDEX_DATA_SM_ID;
  4954. /* map indices */
  4955. /* rx indices */
  4956. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags |=
  4957. SM_RX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4958. /* tx indices */
  4959. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags |=
  4960. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4961. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags |=
  4962. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4963. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags |=
  4964. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4965. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags |=
  4966. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4967. }
  4968. void bnx2x_init_sb(struct bnx2x *bp, dma_addr_t mapping, int vfid,
  4969. u8 vf_valid, int fw_sb_id, int igu_sb_id)
  4970. {
  4971. int igu_seg_id;
  4972. struct hc_status_block_data_e2 sb_data_e2;
  4973. struct hc_status_block_data_e1x sb_data_e1x;
  4974. struct hc_status_block_sm *hc_sm_p;
  4975. int data_size;
  4976. u32 *sb_data_p;
  4977. if (CHIP_INT_MODE_IS_BC(bp))
  4978. igu_seg_id = HC_SEG_ACCESS_NORM;
  4979. else
  4980. igu_seg_id = IGU_SEG_ACCESS_NORM;
  4981. bnx2x_zero_fp_sb(bp, fw_sb_id);
  4982. if (!CHIP_IS_E1x(bp)) {
  4983. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  4984. sb_data_e2.common.state = SB_ENABLED;
  4985. sb_data_e2.common.p_func.pf_id = BP_FUNC(bp);
  4986. sb_data_e2.common.p_func.vf_id = vfid;
  4987. sb_data_e2.common.p_func.vf_valid = vf_valid;
  4988. sb_data_e2.common.p_func.vnic_id = BP_VN(bp);
  4989. sb_data_e2.common.same_igu_sb_1b = true;
  4990. sb_data_e2.common.host_sb_addr.hi = U64_HI(mapping);
  4991. sb_data_e2.common.host_sb_addr.lo = U64_LO(mapping);
  4992. hc_sm_p = sb_data_e2.common.state_machine;
  4993. sb_data_p = (u32 *)&sb_data_e2;
  4994. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  4995. bnx2x_map_sb_state_machines(sb_data_e2.index_data);
  4996. } else {
  4997. memset(&sb_data_e1x, 0,
  4998. sizeof(struct hc_status_block_data_e1x));
  4999. sb_data_e1x.common.state = SB_ENABLED;
  5000. sb_data_e1x.common.p_func.pf_id = BP_FUNC(bp);
  5001. sb_data_e1x.common.p_func.vf_id = 0xff;
  5002. sb_data_e1x.common.p_func.vf_valid = false;
  5003. sb_data_e1x.common.p_func.vnic_id = BP_VN(bp);
  5004. sb_data_e1x.common.same_igu_sb_1b = true;
  5005. sb_data_e1x.common.host_sb_addr.hi = U64_HI(mapping);
  5006. sb_data_e1x.common.host_sb_addr.lo = U64_LO(mapping);
  5007. hc_sm_p = sb_data_e1x.common.state_machine;
  5008. sb_data_p = (u32 *)&sb_data_e1x;
  5009. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  5010. bnx2x_map_sb_state_machines(sb_data_e1x.index_data);
  5011. }
  5012. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_RX_ID],
  5013. igu_sb_id, igu_seg_id);
  5014. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_TX_ID],
  5015. igu_sb_id, igu_seg_id);
  5016. DP(NETIF_MSG_IFUP, "Init FW SB %d\n", fw_sb_id);
  5017. /* write indices to HW - PCI guarantees endianity of regpairs */
  5018. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  5019. }
  5020. static void bnx2x_update_coalesce_sb(struct bnx2x *bp, u8 fw_sb_id,
  5021. u16 tx_usec, u16 rx_usec)
  5022. {
  5023. bnx2x_update_coalesce_sb_index(bp, fw_sb_id, HC_INDEX_ETH_RX_CQ_CONS,
  5024. false, rx_usec);
  5025. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  5026. HC_INDEX_ETH_TX_CQ_CONS_COS0, false,
  5027. tx_usec);
  5028. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  5029. HC_INDEX_ETH_TX_CQ_CONS_COS1, false,
  5030. tx_usec);
  5031. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  5032. HC_INDEX_ETH_TX_CQ_CONS_COS2, false,
  5033. tx_usec);
  5034. }
  5035. static void bnx2x_init_def_sb(struct bnx2x *bp)
  5036. {
  5037. struct host_sp_status_block *def_sb = bp->def_status_blk;
  5038. dma_addr_t mapping = bp->def_status_blk_mapping;
  5039. int igu_sp_sb_index;
  5040. int igu_seg_id;
  5041. int port = BP_PORT(bp);
  5042. int func = BP_FUNC(bp);
  5043. int reg_offset, reg_offset_en5;
  5044. u64 section;
  5045. int index;
  5046. struct hc_sp_status_block_data sp_sb_data;
  5047. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  5048. if (CHIP_INT_MODE_IS_BC(bp)) {
  5049. igu_sp_sb_index = DEF_SB_IGU_ID;
  5050. igu_seg_id = HC_SEG_ACCESS_DEF;
  5051. } else {
  5052. igu_sp_sb_index = bp->igu_dsb_id;
  5053. igu_seg_id = IGU_SEG_ACCESS_DEF;
  5054. }
  5055. /* ATTN */
  5056. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  5057. atten_status_block);
  5058. def_sb->atten_status_block.status_block_id = igu_sp_sb_index;
  5059. bp->attn_state = 0;
  5060. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  5061. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  5062. reg_offset_en5 = (port ? MISC_REG_AEU_ENABLE5_FUNC_1_OUT_0 :
  5063. MISC_REG_AEU_ENABLE5_FUNC_0_OUT_0);
  5064. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  5065. int sindex;
  5066. /* take care of sig[0]..sig[4] */
  5067. for (sindex = 0; sindex < 4; sindex++)
  5068. bp->attn_group[index].sig[sindex] =
  5069. REG_RD(bp, reg_offset + sindex*0x4 + 0x10*index);
  5070. if (!CHIP_IS_E1x(bp))
  5071. /*
  5072. * enable5 is separate from the rest of the registers,
  5073. * and therefore the address skip is 4
  5074. * and not 16 between the different groups
  5075. */
  5076. bp->attn_group[index].sig[4] = REG_RD(bp,
  5077. reg_offset_en5 + 0x4*index);
  5078. else
  5079. bp->attn_group[index].sig[4] = 0;
  5080. }
  5081. if (bp->common.int_block == INT_BLOCK_HC) {
  5082. reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L :
  5083. HC_REG_ATTN_MSG0_ADDR_L);
  5084. REG_WR(bp, reg_offset, U64_LO(section));
  5085. REG_WR(bp, reg_offset + 4, U64_HI(section));
  5086. } else if (!CHIP_IS_E1x(bp)) {
  5087. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_L, U64_LO(section));
  5088. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_H, U64_HI(section));
  5089. }
  5090. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  5091. sp_sb);
  5092. bnx2x_zero_sp_sb(bp);
  5093. /* PCI guarantees endianity of regpairs */
  5094. sp_sb_data.state = SB_ENABLED;
  5095. sp_sb_data.host_sb_addr.lo = U64_LO(section);
  5096. sp_sb_data.host_sb_addr.hi = U64_HI(section);
  5097. sp_sb_data.igu_sb_id = igu_sp_sb_index;
  5098. sp_sb_data.igu_seg_id = igu_seg_id;
  5099. sp_sb_data.p_func.pf_id = func;
  5100. sp_sb_data.p_func.vnic_id = BP_VN(bp);
  5101. sp_sb_data.p_func.vf_id = 0xff;
  5102. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  5103. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0);
  5104. }
  5105. void bnx2x_update_coalesce(struct bnx2x *bp)
  5106. {
  5107. int i;
  5108. for_each_eth_queue(bp, i)
  5109. bnx2x_update_coalesce_sb(bp, bp->fp[i].fw_sb_id,
  5110. bp->tx_ticks, bp->rx_ticks);
  5111. }
  5112. static void bnx2x_init_sp_ring(struct bnx2x *bp)
  5113. {
  5114. spin_lock_init(&bp->spq_lock);
  5115. atomic_set(&bp->cq_spq_left, MAX_SPQ_PENDING);
  5116. bp->spq_prod_idx = 0;
  5117. bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX;
  5118. bp->spq_prod_bd = bp->spq;
  5119. bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT;
  5120. }
  5121. static void bnx2x_init_eq_ring(struct bnx2x *bp)
  5122. {
  5123. int i;
  5124. for (i = 1; i <= NUM_EQ_PAGES; i++) {
  5125. union event_ring_elem *elem =
  5126. &bp->eq_ring[EQ_DESC_CNT_PAGE * i - 1];
  5127. elem->next_page.addr.hi =
  5128. cpu_to_le32(U64_HI(bp->eq_mapping +
  5129. BCM_PAGE_SIZE * (i % NUM_EQ_PAGES)));
  5130. elem->next_page.addr.lo =
  5131. cpu_to_le32(U64_LO(bp->eq_mapping +
  5132. BCM_PAGE_SIZE*(i % NUM_EQ_PAGES)));
  5133. }
  5134. bp->eq_cons = 0;
  5135. bp->eq_prod = NUM_EQ_DESC;
  5136. bp->eq_cons_sb = BNX2X_EQ_INDEX;
  5137. /* we want a warning message before it gets wrought... */
  5138. atomic_set(&bp->eq_spq_left,
  5139. min_t(int, MAX_SP_DESC_CNT - MAX_SPQ_PENDING, NUM_EQ_DESC) - 1);
  5140. }
  5141. /* called with netif_addr_lock_bh() */
  5142. static int bnx2x_set_q_rx_mode(struct bnx2x *bp, u8 cl_id,
  5143. unsigned long rx_mode_flags,
  5144. unsigned long rx_accept_flags,
  5145. unsigned long tx_accept_flags,
  5146. unsigned long ramrod_flags)
  5147. {
  5148. struct bnx2x_rx_mode_ramrod_params ramrod_param;
  5149. int rc;
  5150. memset(&ramrod_param, 0, sizeof(ramrod_param));
  5151. /* Prepare ramrod parameters */
  5152. ramrod_param.cid = 0;
  5153. ramrod_param.cl_id = cl_id;
  5154. ramrod_param.rx_mode_obj = &bp->rx_mode_obj;
  5155. ramrod_param.func_id = BP_FUNC(bp);
  5156. ramrod_param.pstate = &bp->sp_state;
  5157. ramrod_param.state = BNX2X_FILTER_RX_MODE_PENDING;
  5158. ramrod_param.rdata = bnx2x_sp(bp, rx_mode_rdata);
  5159. ramrod_param.rdata_mapping = bnx2x_sp_mapping(bp, rx_mode_rdata);
  5160. set_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  5161. ramrod_param.ramrod_flags = ramrod_flags;
  5162. ramrod_param.rx_mode_flags = rx_mode_flags;
  5163. ramrod_param.rx_accept_flags = rx_accept_flags;
  5164. ramrod_param.tx_accept_flags = tx_accept_flags;
  5165. rc = bnx2x_config_rx_mode(bp, &ramrod_param);
  5166. if (rc < 0) {
  5167. BNX2X_ERR("Set rx_mode %d failed\n", bp->rx_mode);
  5168. return rc;
  5169. }
  5170. return 0;
  5171. }
  5172. static int bnx2x_fill_accept_flags(struct bnx2x *bp, u32 rx_mode,
  5173. unsigned long *rx_accept_flags,
  5174. unsigned long *tx_accept_flags)
  5175. {
  5176. /* Clear the flags first */
  5177. *rx_accept_flags = 0;
  5178. *tx_accept_flags = 0;
  5179. switch (rx_mode) {
  5180. case BNX2X_RX_MODE_NONE:
  5181. /*
  5182. * 'drop all' supersedes any accept flags that may have been
  5183. * passed to the function.
  5184. */
  5185. break;
  5186. case BNX2X_RX_MODE_NORMAL:
  5187. __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
  5188. __set_bit(BNX2X_ACCEPT_MULTICAST, rx_accept_flags);
  5189. __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
  5190. /* internal switching mode */
  5191. __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
  5192. __set_bit(BNX2X_ACCEPT_MULTICAST, tx_accept_flags);
  5193. __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
  5194. break;
  5195. case BNX2X_RX_MODE_ALLMULTI:
  5196. __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
  5197. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, rx_accept_flags);
  5198. __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
  5199. /* internal switching mode */
  5200. __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
  5201. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, tx_accept_flags);
  5202. __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
  5203. break;
  5204. case BNX2X_RX_MODE_PROMISC:
  5205. /* According to definition of SI mode, iface in promisc mode
  5206. * should receive matched and unmatched (in resolution of port)
  5207. * unicast packets.
  5208. */
  5209. __set_bit(BNX2X_ACCEPT_UNMATCHED, rx_accept_flags);
  5210. __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
  5211. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, rx_accept_flags);
  5212. __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
  5213. /* internal switching mode */
  5214. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, tx_accept_flags);
  5215. __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
  5216. if (IS_MF_SI(bp))
  5217. __set_bit(BNX2X_ACCEPT_ALL_UNICAST, tx_accept_flags);
  5218. else
  5219. __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
  5220. break;
  5221. default:
  5222. BNX2X_ERR("Unknown rx_mode: %d\n", rx_mode);
  5223. return -EINVAL;
  5224. }
  5225. /* Set ACCEPT_ANY_VLAN as we do not enable filtering by VLAN */
  5226. if (rx_mode != BNX2X_RX_MODE_NONE) {
  5227. __set_bit(BNX2X_ACCEPT_ANY_VLAN, rx_accept_flags);
  5228. __set_bit(BNX2X_ACCEPT_ANY_VLAN, tx_accept_flags);
  5229. }
  5230. return 0;
  5231. }
  5232. /* called with netif_addr_lock_bh() */
  5233. static int bnx2x_set_storm_rx_mode(struct bnx2x *bp)
  5234. {
  5235. unsigned long rx_mode_flags = 0, ramrod_flags = 0;
  5236. unsigned long rx_accept_flags = 0, tx_accept_flags = 0;
  5237. int rc;
  5238. if (!NO_FCOE(bp))
  5239. /* Configure rx_mode of FCoE Queue */
  5240. __set_bit(BNX2X_RX_MODE_FCOE_ETH, &rx_mode_flags);
  5241. rc = bnx2x_fill_accept_flags(bp, bp->rx_mode, &rx_accept_flags,
  5242. &tx_accept_flags);
  5243. if (rc)
  5244. return rc;
  5245. __set_bit(RAMROD_RX, &ramrod_flags);
  5246. __set_bit(RAMROD_TX, &ramrod_flags);
  5247. return bnx2x_set_q_rx_mode(bp, bp->fp->cl_id, rx_mode_flags,
  5248. rx_accept_flags, tx_accept_flags,
  5249. ramrod_flags);
  5250. }
  5251. static void bnx2x_init_internal_common(struct bnx2x *bp)
  5252. {
  5253. int i;
  5254. /* Zero this manually as its initialization is
  5255. currently missing in the initTool */
  5256. for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++)
  5257. REG_WR(bp, BAR_USTRORM_INTMEM +
  5258. USTORM_AGG_DATA_OFFSET + i * 4, 0);
  5259. if (!CHIP_IS_E1x(bp)) {
  5260. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_IGU_MODE_OFFSET,
  5261. CHIP_INT_MODE_IS_BC(bp) ?
  5262. HC_IGU_BC_MODE : HC_IGU_NBC_MODE);
  5263. }
  5264. }
  5265. static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code)
  5266. {
  5267. switch (load_code) {
  5268. case FW_MSG_CODE_DRV_LOAD_COMMON:
  5269. case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
  5270. bnx2x_init_internal_common(bp);
  5271. /* no break */
  5272. case FW_MSG_CODE_DRV_LOAD_PORT:
  5273. /* nothing to do */
  5274. /* no break */
  5275. case FW_MSG_CODE_DRV_LOAD_FUNCTION:
  5276. /* internal memory per function is
  5277. initialized inside bnx2x_pf_init */
  5278. break;
  5279. default:
  5280. BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
  5281. break;
  5282. }
  5283. }
  5284. static inline u8 bnx2x_fp_igu_sb_id(struct bnx2x_fastpath *fp)
  5285. {
  5286. return fp->bp->igu_base_sb + fp->index + CNIC_SUPPORT(fp->bp);
  5287. }
  5288. static inline u8 bnx2x_fp_fw_sb_id(struct bnx2x_fastpath *fp)
  5289. {
  5290. return fp->bp->base_fw_ndsb + fp->index + CNIC_SUPPORT(fp->bp);
  5291. }
  5292. static u8 bnx2x_fp_cl_id(struct bnx2x_fastpath *fp)
  5293. {
  5294. if (CHIP_IS_E1x(fp->bp))
  5295. return BP_L_ID(fp->bp) + fp->index;
  5296. else /* We want Client ID to be the same as IGU SB ID for 57712 */
  5297. return bnx2x_fp_igu_sb_id(fp);
  5298. }
  5299. static void bnx2x_init_eth_fp(struct bnx2x *bp, int fp_idx)
  5300. {
  5301. struct bnx2x_fastpath *fp = &bp->fp[fp_idx];
  5302. u8 cos;
  5303. unsigned long q_type = 0;
  5304. u32 cids[BNX2X_MULTI_TX_COS] = { 0 };
  5305. fp->rx_queue = fp_idx;
  5306. fp->cid = fp_idx;
  5307. fp->cl_id = bnx2x_fp_cl_id(fp);
  5308. fp->fw_sb_id = bnx2x_fp_fw_sb_id(fp);
  5309. fp->igu_sb_id = bnx2x_fp_igu_sb_id(fp);
  5310. /* qZone id equals to FW (per path) client id */
  5311. fp->cl_qzone_id = bnx2x_fp_qzone_id(fp);
  5312. /* init shortcut */
  5313. fp->ustorm_rx_prods_offset = bnx2x_rx_ustorm_prods_offset(fp);
  5314. /* Setup SB indices */
  5315. fp->rx_cons_sb = BNX2X_RX_SB_INDEX;
  5316. /* Configure Queue State object */
  5317. __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
  5318. __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
  5319. BUG_ON(fp->max_cos > BNX2X_MULTI_TX_COS);
  5320. /* init tx data */
  5321. for_each_cos_in_tx_queue(fp, cos) {
  5322. bnx2x_init_txdata(bp, fp->txdata_ptr[cos],
  5323. CID_COS_TO_TX_ONLY_CID(fp->cid, cos, bp),
  5324. FP_COS_TO_TXQ(fp, cos, bp),
  5325. BNX2X_TX_SB_INDEX_BASE + cos, fp);
  5326. cids[cos] = fp->txdata_ptr[cos]->cid;
  5327. }
  5328. /* nothing more for vf to do here */
  5329. if (IS_VF(bp))
  5330. return;
  5331. bnx2x_init_sb(bp, fp->status_blk_mapping, BNX2X_VF_ID_INVALID, false,
  5332. fp->fw_sb_id, fp->igu_sb_id);
  5333. bnx2x_update_fpsb_idx(fp);
  5334. bnx2x_init_queue_obj(bp, &bnx2x_sp_obj(bp, fp).q_obj, fp->cl_id, cids,
  5335. fp->max_cos, BP_FUNC(bp), bnx2x_sp(bp, q_rdata),
  5336. bnx2x_sp_mapping(bp, q_rdata), q_type);
  5337. /**
  5338. * Configure classification DBs: Always enable Tx switching
  5339. */
  5340. bnx2x_init_vlan_mac_fp_objs(fp, BNX2X_OBJ_TYPE_RX_TX);
  5341. DP(NETIF_MSG_IFUP,
  5342. "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d fw_sb %d igu_sb %d\n",
  5343. fp_idx, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
  5344. fp->igu_sb_id);
  5345. }
  5346. static void bnx2x_init_tx_ring_one(struct bnx2x_fp_txdata *txdata)
  5347. {
  5348. int i;
  5349. for (i = 1; i <= NUM_TX_RINGS; i++) {
  5350. struct eth_tx_next_bd *tx_next_bd =
  5351. &txdata->tx_desc_ring[TX_DESC_CNT * i - 1].next_bd;
  5352. tx_next_bd->addr_hi =
  5353. cpu_to_le32(U64_HI(txdata->tx_desc_mapping +
  5354. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  5355. tx_next_bd->addr_lo =
  5356. cpu_to_le32(U64_LO(txdata->tx_desc_mapping +
  5357. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  5358. }
  5359. *txdata->tx_cons_sb = cpu_to_le16(0);
  5360. SET_FLAG(txdata->tx_db.data.header.header, DOORBELL_HDR_DB_TYPE, 1);
  5361. txdata->tx_db.data.zero_fill1 = 0;
  5362. txdata->tx_db.data.prod = 0;
  5363. txdata->tx_pkt_prod = 0;
  5364. txdata->tx_pkt_cons = 0;
  5365. txdata->tx_bd_prod = 0;
  5366. txdata->tx_bd_cons = 0;
  5367. txdata->tx_pkt = 0;
  5368. }
  5369. static void bnx2x_init_tx_rings_cnic(struct bnx2x *bp)
  5370. {
  5371. int i;
  5372. for_each_tx_queue_cnic(bp, i)
  5373. bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[0]);
  5374. }
  5375. static void bnx2x_init_tx_rings(struct bnx2x *bp)
  5376. {
  5377. int i;
  5378. u8 cos;
  5379. for_each_eth_queue(bp, i)
  5380. for_each_cos_in_tx_queue(&bp->fp[i], cos)
  5381. bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[cos]);
  5382. }
  5383. static void bnx2x_init_fcoe_fp(struct bnx2x *bp)
  5384. {
  5385. struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
  5386. unsigned long q_type = 0;
  5387. bnx2x_fcoe(bp, rx_queue) = BNX2X_NUM_ETH_QUEUES(bp);
  5388. bnx2x_fcoe(bp, cl_id) = bnx2x_cnic_eth_cl_id(bp,
  5389. BNX2X_FCOE_ETH_CL_ID_IDX);
  5390. bnx2x_fcoe(bp, cid) = BNX2X_FCOE_ETH_CID(bp);
  5391. bnx2x_fcoe(bp, fw_sb_id) = DEF_SB_ID;
  5392. bnx2x_fcoe(bp, igu_sb_id) = bp->igu_dsb_id;
  5393. bnx2x_fcoe(bp, rx_cons_sb) = BNX2X_FCOE_L2_RX_INDEX;
  5394. bnx2x_init_txdata(bp, bnx2x_fcoe(bp, txdata_ptr[0]),
  5395. fp->cid, FCOE_TXQ_IDX(bp), BNX2X_FCOE_L2_TX_INDEX,
  5396. fp);
  5397. DP(NETIF_MSG_IFUP, "created fcoe tx data (fp index %d)\n", fp->index);
  5398. /* qZone id equals to FW (per path) client id */
  5399. bnx2x_fcoe(bp, cl_qzone_id) = bnx2x_fp_qzone_id(fp);
  5400. /* init shortcut */
  5401. bnx2x_fcoe(bp, ustorm_rx_prods_offset) =
  5402. bnx2x_rx_ustorm_prods_offset(fp);
  5403. /* Configure Queue State object */
  5404. __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
  5405. __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
  5406. /* No multi-CoS for FCoE L2 client */
  5407. BUG_ON(fp->max_cos != 1);
  5408. bnx2x_init_queue_obj(bp, &bnx2x_sp_obj(bp, fp).q_obj, fp->cl_id,
  5409. &fp->cid, 1, BP_FUNC(bp), bnx2x_sp(bp, q_rdata),
  5410. bnx2x_sp_mapping(bp, q_rdata), q_type);
  5411. DP(NETIF_MSG_IFUP,
  5412. "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d fw_sb %d igu_sb %d\n",
  5413. fp->index, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
  5414. fp->igu_sb_id);
  5415. }
  5416. void bnx2x_nic_init_cnic(struct bnx2x *bp)
  5417. {
  5418. if (!NO_FCOE(bp))
  5419. bnx2x_init_fcoe_fp(bp);
  5420. bnx2x_init_sb(bp, bp->cnic_sb_mapping,
  5421. BNX2X_VF_ID_INVALID, false,
  5422. bnx2x_cnic_fw_sb_id(bp), bnx2x_cnic_igu_sb_id(bp));
  5423. /* ensure status block indices were read */
  5424. rmb();
  5425. bnx2x_init_rx_rings_cnic(bp);
  5426. bnx2x_init_tx_rings_cnic(bp);
  5427. /* flush all */
  5428. mb();
  5429. mmiowb();
  5430. }
  5431. void bnx2x_pre_irq_nic_init(struct bnx2x *bp)
  5432. {
  5433. int i;
  5434. /* Setup NIC internals and enable interrupts */
  5435. for_each_eth_queue(bp, i)
  5436. bnx2x_init_eth_fp(bp, i);
  5437. /* ensure status block indices were read */
  5438. rmb();
  5439. bnx2x_init_rx_rings(bp);
  5440. bnx2x_init_tx_rings(bp);
  5441. if (IS_PF(bp)) {
  5442. /* Initialize MOD_ABS interrupts */
  5443. bnx2x_init_mod_abs_int(bp, &bp->link_vars, bp->common.chip_id,
  5444. bp->common.shmem_base,
  5445. bp->common.shmem2_base, BP_PORT(bp));
  5446. /* initialize the default status block and sp ring */
  5447. bnx2x_init_def_sb(bp);
  5448. bnx2x_update_dsb_idx(bp);
  5449. bnx2x_init_sp_ring(bp);
  5450. } else {
  5451. bnx2x_memset_stats(bp);
  5452. }
  5453. }
  5454. void bnx2x_post_irq_nic_init(struct bnx2x *bp, u32 load_code)
  5455. {
  5456. bnx2x_init_eq_ring(bp);
  5457. bnx2x_init_internal(bp, load_code);
  5458. bnx2x_pf_init(bp);
  5459. bnx2x_stats_init(bp);
  5460. /* flush all before enabling interrupts */
  5461. mb();
  5462. mmiowb();
  5463. bnx2x_int_enable(bp);
  5464. /* Check for SPIO5 */
  5465. bnx2x_attn_int_deasserted0(bp,
  5466. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + BP_PORT(bp)*4) &
  5467. AEU_INPUTS_ATTN_BITS_SPIO5);
  5468. }
  5469. /* gzip service functions */
  5470. static int bnx2x_gunzip_init(struct bnx2x *bp)
  5471. {
  5472. bp->gunzip_buf = dma_alloc_coherent(&bp->pdev->dev, FW_BUF_SIZE,
  5473. &bp->gunzip_mapping, GFP_KERNEL);
  5474. if (bp->gunzip_buf == NULL)
  5475. goto gunzip_nomem1;
  5476. bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL);
  5477. if (bp->strm == NULL)
  5478. goto gunzip_nomem2;
  5479. bp->strm->workspace = vmalloc(zlib_inflate_workspacesize());
  5480. if (bp->strm->workspace == NULL)
  5481. goto gunzip_nomem3;
  5482. return 0;
  5483. gunzip_nomem3:
  5484. kfree(bp->strm);
  5485. bp->strm = NULL;
  5486. gunzip_nomem2:
  5487. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  5488. bp->gunzip_mapping);
  5489. bp->gunzip_buf = NULL;
  5490. gunzip_nomem1:
  5491. BNX2X_ERR("Cannot allocate firmware buffer for un-compression\n");
  5492. return -ENOMEM;
  5493. }
  5494. static void bnx2x_gunzip_end(struct bnx2x *bp)
  5495. {
  5496. if (bp->strm) {
  5497. vfree(bp->strm->workspace);
  5498. kfree(bp->strm);
  5499. bp->strm = NULL;
  5500. }
  5501. if (bp->gunzip_buf) {
  5502. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  5503. bp->gunzip_mapping);
  5504. bp->gunzip_buf = NULL;
  5505. }
  5506. }
  5507. static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len)
  5508. {
  5509. int n, rc;
  5510. /* check gzip header */
  5511. if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED)) {
  5512. BNX2X_ERR("Bad gzip header\n");
  5513. return -EINVAL;
  5514. }
  5515. n = 10;
  5516. #define FNAME 0x8
  5517. if (zbuf[3] & FNAME)
  5518. while ((zbuf[n++] != 0) && (n < len));
  5519. bp->strm->next_in = (typeof(bp->strm->next_in))zbuf + n;
  5520. bp->strm->avail_in = len - n;
  5521. bp->strm->next_out = bp->gunzip_buf;
  5522. bp->strm->avail_out = FW_BUF_SIZE;
  5523. rc = zlib_inflateInit2(bp->strm, -MAX_WBITS);
  5524. if (rc != Z_OK)
  5525. return rc;
  5526. rc = zlib_inflate(bp->strm, Z_FINISH);
  5527. if ((rc != Z_OK) && (rc != Z_STREAM_END))
  5528. netdev_err(bp->dev, "Firmware decompression error: %s\n",
  5529. bp->strm->msg);
  5530. bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out);
  5531. if (bp->gunzip_outlen & 0x3)
  5532. netdev_err(bp->dev,
  5533. "Firmware decompression error: gunzip_outlen (%d) not aligned\n",
  5534. bp->gunzip_outlen);
  5535. bp->gunzip_outlen >>= 2;
  5536. zlib_inflateEnd(bp->strm);
  5537. if (rc == Z_STREAM_END)
  5538. return 0;
  5539. return rc;
  5540. }
  5541. /* nic load/unload */
  5542. /*
  5543. * General service functions
  5544. */
  5545. /* send a NIG loopback debug packet */
  5546. static void bnx2x_lb_pckt(struct bnx2x *bp)
  5547. {
  5548. u32 wb_write[3];
  5549. /* Ethernet source and destination addresses */
  5550. wb_write[0] = 0x55555555;
  5551. wb_write[1] = 0x55555555;
  5552. wb_write[2] = 0x20; /* SOP */
  5553. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  5554. /* NON-IP protocol */
  5555. wb_write[0] = 0x09000000;
  5556. wb_write[1] = 0x55555555;
  5557. wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */
  5558. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  5559. }
  5560. /* some of the internal memories
  5561. * are not directly readable from the driver
  5562. * to test them we send debug packets
  5563. */
  5564. static int bnx2x_int_mem_test(struct bnx2x *bp)
  5565. {
  5566. int factor;
  5567. int count, i;
  5568. u32 val = 0;
  5569. if (CHIP_REV_IS_FPGA(bp))
  5570. factor = 120;
  5571. else if (CHIP_REV_IS_EMUL(bp))
  5572. factor = 200;
  5573. else
  5574. factor = 1;
  5575. /* Disable inputs of parser neighbor blocks */
  5576. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  5577. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  5578. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  5579. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  5580. /* Write 0 to parser credits for CFC search request */
  5581. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  5582. /* send Ethernet packet */
  5583. bnx2x_lb_pckt(bp);
  5584. /* TODO do i reset NIG statistic? */
  5585. /* Wait until NIG register shows 1 packet of size 0x10 */
  5586. count = 1000 * factor;
  5587. while (count) {
  5588. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5589. val = *bnx2x_sp(bp, wb_data[0]);
  5590. if (val == 0x10)
  5591. break;
  5592. usleep_range(10000, 20000);
  5593. count--;
  5594. }
  5595. if (val != 0x10) {
  5596. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  5597. return -1;
  5598. }
  5599. /* Wait until PRS register shows 1 packet */
  5600. count = 1000 * factor;
  5601. while (count) {
  5602. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5603. if (val == 1)
  5604. break;
  5605. usleep_range(10000, 20000);
  5606. count--;
  5607. }
  5608. if (val != 0x1) {
  5609. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5610. return -2;
  5611. }
  5612. /* Reset and init BRB, PRS */
  5613. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  5614. msleep(50);
  5615. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  5616. msleep(50);
  5617. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5618. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5619. DP(NETIF_MSG_HW, "part2\n");
  5620. /* Disable inputs of parser neighbor blocks */
  5621. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  5622. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  5623. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  5624. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  5625. /* Write 0 to parser credits for CFC search request */
  5626. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  5627. /* send 10 Ethernet packets */
  5628. for (i = 0; i < 10; i++)
  5629. bnx2x_lb_pckt(bp);
  5630. /* Wait until NIG register shows 10 + 1
  5631. packets of size 11*0x10 = 0xb0 */
  5632. count = 1000 * factor;
  5633. while (count) {
  5634. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5635. val = *bnx2x_sp(bp, wb_data[0]);
  5636. if (val == 0xb0)
  5637. break;
  5638. usleep_range(10000, 20000);
  5639. count--;
  5640. }
  5641. if (val != 0xb0) {
  5642. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  5643. return -3;
  5644. }
  5645. /* Wait until PRS register shows 2 packets */
  5646. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5647. if (val != 2)
  5648. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5649. /* Write 1 to parser credits for CFC search request */
  5650. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1);
  5651. /* Wait until PRS register shows 3 packets */
  5652. msleep(10 * factor);
  5653. /* Wait until NIG register shows 1 packet of size 0x10 */
  5654. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5655. if (val != 3)
  5656. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5657. /* clear NIG EOP FIFO */
  5658. for (i = 0; i < 11; i++)
  5659. REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO);
  5660. val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY);
  5661. if (val != 1) {
  5662. BNX2X_ERR("clear of NIG failed\n");
  5663. return -4;
  5664. }
  5665. /* Reset and init BRB, PRS, NIG */
  5666. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  5667. msleep(50);
  5668. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  5669. msleep(50);
  5670. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5671. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5672. if (!CNIC_SUPPORT(bp))
  5673. /* set NIC mode */
  5674. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  5675. /* Enable inputs of parser neighbor blocks */
  5676. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff);
  5677. REG_WR(bp, TCM_REG_PRS_IFEN, 0x1);
  5678. REG_WR(bp, CFC_REG_DEBUG0, 0x0);
  5679. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1);
  5680. DP(NETIF_MSG_HW, "done\n");
  5681. return 0; /* OK */
  5682. }
  5683. static void bnx2x_enable_blocks_attention(struct bnx2x *bp)
  5684. {
  5685. u32 val;
  5686. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5687. if (!CHIP_IS_E1x(bp))
  5688. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0x40);
  5689. else
  5690. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0);
  5691. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  5692. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  5693. /*
  5694. * mask read length error interrupts in brb for parser
  5695. * (parsing unit and 'checksum and crc' unit)
  5696. * these errors are legal (PU reads fixed length and CAC can cause
  5697. * read length error on truncated packets)
  5698. */
  5699. REG_WR(bp, BRB1_REG_BRB1_INT_MASK, 0xFC00);
  5700. REG_WR(bp, QM_REG_QM_INT_MASK, 0);
  5701. REG_WR(bp, TM_REG_TM_INT_MASK, 0);
  5702. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0);
  5703. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0);
  5704. REG_WR(bp, XCM_REG_XCM_INT_MASK, 0);
  5705. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */
  5706. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */
  5707. REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0);
  5708. REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0);
  5709. REG_WR(bp, UCM_REG_UCM_INT_MASK, 0);
  5710. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */
  5711. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */
  5712. REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0);
  5713. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0);
  5714. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0);
  5715. REG_WR(bp, CCM_REG_CCM_INT_MASK, 0);
  5716. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */
  5717. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */
  5718. val = PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT |
  5719. PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF |
  5720. PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN;
  5721. if (!CHIP_IS_E1x(bp))
  5722. val |= PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED |
  5723. PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED;
  5724. REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, val);
  5725. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0);
  5726. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0);
  5727. REG_WR(bp, TCM_REG_TCM_INT_MASK, 0);
  5728. /* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */
  5729. if (!CHIP_IS_E1x(bp))
  5730. /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */
  5731. REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0x07ff);
  5732. REG_WR(bp, CDU_REG_CDU_INT_MASK, 0);
  5733. REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0);
  5734. /* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */
  5735. REG_WR(bp, PBF_REG_PBF_INT_MASK, 0x18); /* bit 3,4 masked */
  5736. }
  5737. static void bnx2x_reset_common(struct bnx2x *bp)
  5738. {
  5739. u32 val = 0x1400;
  5740. /* reset_common */
  5741. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  5742. 0xd3ffff7f);
  5743. if (CHIP_IS_E3(bp)) {
  5744. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  5745. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  5746. }
  5747. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, val);
  5748. }
  5749. static void bnx2x_setup_dmae(struct bnx2x *bp)
  5750. {
  5751. bp->dmae_ready = 0;
  5752. spin_lock_init(&bp->dmae_lock);
  5753. }
  5754. static void bnx2x_init_pxp(struct bnx2x *bp)
  5755. {
  5756. u16 devctl;
  5757. int r_order, w_order;
  5758. pcie_capability_read_word(bp->pdev, PCI_EXP_DEVCTL, &devctl);
  5759. DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl);
  5760. w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
  5761. if (bp->mrrs == -1)
  5762. r_order = ((devctl & PCI_EXP_DEVCTL_READRQ) >> 12);
  5763. else {
  5764. DP(NETIF_MSG_HW, "force read order to %d\n", bp->mrrs);
  5765. r_order = bp->mrrs;
  5766. }
  5767. bnx2x_init_pxp_arb(bp, r_order, w_order);
  5768. }
  5769. static void bnx2x_setup_fan_failure_detection(struct bnx2x *bp)
  5770. {
  5771. int is_required;
  5772. u32 val;
  5773. int port;
  5774. if (BP_NOMCP(bp))
  5775. return;
  5776. is_required = 0;
  5777. val = SHMEM_RD(bp, dev_info.shared_hw_config.config2) &
  5778. SHARED_HW_CFG_FAN_FAILURE_MASK;
  5779. if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED)
  5780. is_required = 1;
  5781. /*
  5782. * The fan failure mechanism is usually related to the PHY type since
  5783. * the power consumption of the board is affected by the PHY. Currently,
  5784. * fan is required for most designs with SFX7101, BCM8727 and BCM8481.
  5785. */
  5786. else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE)
  5787. for (port = PORT_0; port < PORT_MAX; port++) {
  5788. is_required |=
  5789. bnx2x_fan_failure_det_req(
  5790. bp,
  5791. bp->common.shmem_base,
  5792. bp->common.shmem2_base,
  5793. port);
  5794. }
  5795. DP(NETIF_MSG_HW, "fan detection setting: %d\n", is_required);
  5796. if (is_required == 0)
  5797. return;
  5798. /* Fan failure is indicated by SPIO 5 */
  5799. bnx2x_set_spio(bp, MISC_SPIO_SPIO5, MISC_SPIO_INPUT_HI_Z);
  5800. /* set to active low mode */
  5801. val = REG_RD(bp, MISC_REG_SPIO_INT);
  5802. val |= (MISC_SPIO_SPIO5 << MISC_SPIO_INT_OLD_SET_POS);
  5803. REG_WR(bp, MISC_REG_SPIO_INT, val);
  5804. /* enable interrupt to signal the IGU */
  5805. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  5806. val |= MISC_SPIO_SPIO5;
  5807. REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val);
  5808. }
  5809. void bnx2x_pf_disable(struct bnx2x *bp)
  5810. {
  5811. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  5812. val &= ~IGU_PF_CONF_FUNC_EN;
  5813. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  5814. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  5815. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 0);
  5816. }
  5817. static void bnx2x__common_init_phy(struct bnx2x *bp)
  5818. {
  5819. u32 shmem_base[2], shmem2_base[2];
  5820. /* Avoid common init in case MFW supports LFA */
  5821. if (SHMEM2_RD(bp, size) >
  5822. (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
  5823. return;
  5824. shmem_base[0] = bp->common.shmem_base;
  5825. shmem2_base[0] = bp->common.shmem2_base;
  5826. if (!CHIP_IS_E1x(bp)) {
  5827. shmem_base[1] =
  5828. SHMEM2_RD(bp, other_shmem_base_addr);
  5829. shmem2_base[1] =
  5830. SHMEM2_RD(bp, other_shmem2_base_addr);
  5831. }
  5832. bnx2x_acquire_phy_lock(bp);
  5833. bnx2x_common_init_phy(bp, shmem_base, shmem2_base,
  5834. bp->common.chip_id);
  5835. bnx2x_release_phy_lock(bp);
  5836. }
  5837. static void bnx2x_config_endianity(struct bnx2x *bp, u32 val)
  5838. {
  5839. REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, val);
  5840. REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, val);
  5841. REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, val);
  5842. REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, val);
  5843. REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, val);
  5844. /* make sure this value is 0 */
  5845. REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0);
  5846. REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, val);
  5847. REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, val);
  5848. REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, val);
  5849. REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, val);
  5850. }
  5851. static void bnx2x_set_endianity(struct bnx2x *bp)
  5852. {
  5853. #ifdef __BIG_ENDIAN
  5854. bnx2x_config_endianity(bp, 1);
  5855. #else
  5856. bnx2x_config_endianity(bp, 0);
  5857. #endif
  5858. }
  5859. static void bnx2x_reset_endianity(struct bnx2x *bp)
  5860. {
  5861. bnx2x_config_endianity(bp, 0);
  5862. }
  5863. /**
  5864. * bnx2x_init_hw_common - initialize the HW at the COMMON phase.
  5865. *
  5866. * @bp: driver handle
  5867. */
  5868. static int bnx2x_init_hw_common(struct bnx2x *bp)
  5869. {
  5870. u32 val;
  5871. DP(NETIF_MSG_HW, "starting common init func %d\n", BP_ABS_FUNC(bp));
  5872. /*
  5873. * take the RESET lock to protect undi_unload flow from accessing
  5874. * registers while we're resetting the chip
  5875. */
  5876. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5877. bnx2x_reset_common(bp);
  5878. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff);
  5879. val = 0xfffc;
  5880. if (CHIP_IS_E3(bp)) {
  5881. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  5882. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  5883. }
  5884. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, val);
  5885. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5886. bnx2x_init_block(bp, BLOCK_MISC, PHASE_COMMON);
  5887. if (!CHIP_IS_E1x(bp)) {
  5888. u8 abs_func_id;
  5889. /**
  5890. * 4-port mode or 2-port mode we need to turn of master-enable
  5891. * for everyone, after that, turn it back on for self.
  5892. * so, we disregard multi-function or not, and always disable
  5893. * for all functions on the given path, this means 0,2,4,6 for
  5894. * path 0 and 1,3,5,7 for path 1
  5895. */
  5896. for (abs_func_id = BP_PATH(bp);
  5897. abs_func_id < E2_FUNC_MAX*2; abs_func_id += 2) {
  5898. if (abs_func_id == BP_ABS_FUNC(bp)) {
  5899. REG_WR(bp,
  5900. PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER,
  5901. 1);
  5902. continue;
  5903. }
  5904. bnx2x_pretend_func(bp, abs_func_id);
  5905. /* clear pf enable */
  5906. bnx2x_pf_disable(bp);
  5907. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  5908. }
  5909. }
  5910. bnx2x_init_block(bp, BLOCK_PXP, PHASE_COMMON);
  5911. if (CHIP_IS_E1(bp)) {
  5912. /* enable HW interrupt from PXP on USDM overflow
  5913. bit 16 on INT_MASK_0 */
  5914. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5915. }
  5916. bnx2x_init_block(bp, BLOCK_PXP2, PHASE_COMMON);
  5917. bnx2x_init_pxp(bp);
  5918. bnx2x_set_endianity(bp);
  5919. bnx2x_ilt_init_page_size(bp, INITOP_SET);
  5920. if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp))
  5921. REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1);
  5922. /* let the HW do it's magic ... */
  5923. msleep(100);
  5924. /* finish PXP init */
  5925. val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE);
  5926. if (val != 1) {
  5927. BNX2X_ERR("PXP2 CFG failed\n");
  5928. return -EBUSY;
  5929. }
  5930. val = REG_RD(bp, PXP2_REG_RD_INIT_DONE);
  5931. if (val != 1) {
  5932. BNX2X_ERR("PXP2 RD_INIT failed\n");
  5933. return -EBUSY;
  5934. }
  5935. /* Timers bug workaround E2 only. We need to set the entire ILT to
  5936. * have entries with value "0" and valid bit on.
  5937. * This needs to be done by the first PF that is loaded in a path
  5938. * (i.e. common phase)
  5939. */
  5940. if (!CHIP_IS_E1x(bp)) {
  5941. /* In E2 there is a bug in the timers block that can cause function 6 / 7
  5942. * (i.e. vnic3) to start even if it is marked as "scan-off".
  5943. * This occurs when a different function (func2,3) is being marked
  5944. * as "scan-off". Real-life scenario for example: if a driver is being
  5945. * load-unloaded while func6,7 are down. This will cause the timer to access
  5946. * the ilt, translate to a logical address and send a request to read/write.
  5947. * Since the ilt for the function that is down is not valid, this will cause
  5948. * a translation error which is unrecoverable.
  5949. * The Workaround is intended to make sure that when this happens nothing fatal
  5950. * will occur. The workaround:
  5951. * 1. First PF driver which loads on a path will:
  5952. * a. After taking the chip out of reset, by using pretend,
  5953. * it will write "0" to the following registers of
  5954. * the other vnics.
  5955. * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  5956. * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0);
  5957. * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0);
  5958. * And for itself it will write '1' to
  5959. * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable
  5960. * dmae-operations (writing to pram for example.)
  5961. * note: can be done for only function 6,7 but cleaner this
  5962. * way.
  5963. * b. Write zero+valid to the entire ILT.
  5964. * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of
  5965. * VNIC3 (of that port). The range allocated will be the
  5966. * entire ILT. This is needed to prevent ILT range error.
  5967. * 2. Any PF driver load flow:
  5968. * a. ILT update with the physical addresses of the allocated
  5969. * logical pages.
  5970. * b. Wait 20msec. - note that this timeout is needed to make
  5971. * sure there are no requests in one of the PXP internal
  5972. * queues with "old" ILT addresses.
  5973. * c. PF enable in the PGLC.
  5974. * d. Clear the was_error of the PF in the PGLC. (could have
  5975. * occurred while driver was down)
  5976. * e. PF enable in the CFC (WEAK + STRONG)
  5977. * f. Timers scan enable
  5978. * 3. PF driver unload flow:
  5979. * a. Clear the Timers scan_en.
  5980. * b. Polling for scan_on=0 for that PF.
  5981. * c. Clear the PF enable bit in the PXP.
  5982. * d. Clear the PF enable in the CFC (WEAK + STRONG)
  5983. * e. Write zero+valid to all ILT entries (The valid bit must
  5984. * stay set)
  5985. * f. If this is VNIC 3 of a port then also init
  5986. * first_timers_ilt_entry to zero and last_timers_ilt_entry
  5987. * to the last entry in the ILT.
  5988. *
  5989. * Notes:
  5990. * Currently the PF error in the PGLC is non recoverable.
  5991. * In the future the there will be a recovery routine for this error.
  5992. * Currently attention is masked.
  5993. * Having an MCP lock on the load/unload process does not guarantee that
  5994. * there is no Timer disable during Func6/7 enable. This is because the
  5995. * Timers scan is currently being cleared by the MCP on FLR.
  5996. * Step 2.d can be done only for PF6/7 and the driver can also check if
  5997. * there is error before clearing it. But the flow above is simpler and
  5998. * more general.
  5999. * All ILT entries are written by zero+valid and not just PF6/7
  6000. * ILT entries since in the future the ILT entries allocation for
  6001. * PF-s might be dynamic.
  6002. */
  6003. struct ilt_client_info ilt_cli;
  6004. struct bnx2x_ilt ilt;
  6005. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  6006. memset(&ilt, 0, sizeof(struct bnx2x_ilt));
  6007. /* initialize dummy TM client */
  6008. ilt_cli.start = 0;
  6009. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  6010. ilt_cli.client_num = ILT_CLIENT_TM;
  6011. /* Step 1: set zeroes to all ilt page entries with valid bit on
  6012. * Step 2: set the timers first/last ilt entry to point
  6013. * to the entire range to prevent ILT range error for 3rd/4th
  6014. * vnic (this code assumes existence of the vnic)
  6015. *
  6016. * both steps performed by call to bnx2x_ilt_client_init_op()
  6017. * with dummy TM client
  6018. *
  6019. * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT
  6020. * and his brother are split registers
  6021. */
  6022. bnx2x_pretend_func(bp, (BP_PATH(bp) + 6));
  6023. bnx2x_ilt_client_init_op_ilt(bp, &ilt, &ilt_cli, INITOP_CLEAR);
  6024. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  6025. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN, BNX2X_PXP_DRAM_ALIGN);
  6026. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_RD, BNX2X_PXP_DRAM_ALIGN);
  6027. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_SEL, 1);
  6028. }
  6029. REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0);
  6030. REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0);
  6031. if (!CHIP_IS_E1x(bp)) {
  6032. int factor = CHIP_REV_IS_EMUL(bp) ? 1000 :
  6033. (CHIP_REV_IS_FPGA(bp) ? 400 : 0);
  6034. bnx2x_init_block(bp, BLOCK_PGLUE_B, PHASE_COMMON);
  6035. bnx2x_init_block(bp, BLOCK_ATC, PHASE_COMMON);
  6036. /* let the HW do it's magic ... */
  6037. do {
  6038. msleep(200);
  6039. val = REG_RD(bp, ATC_REG_ATC_INIT_DONE);
  6040. } while (factor-- && (val != 1));
  6041. if (val != 1) {
  6042. BNX2X_ERR("ATC_INIT failed\n");
  6043. return -EBUSY;
  6044. }
  6045. }
  6046. bnx2x_init_block(bp, BLOCK_DMAE, PHASE_COMMON);
  6047. bnx2x_iov_init_dmae(bp);
  6048. /* clean the DMAE memory */
  6049. bp->dmae_ready = 1;
  6050. bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8, 1);
  6051. bnx2x_init_block(bp, BLOCK_TCM, PHASE_COMMON);
  6052. bnx2x_init_block(bp, BLOCK_UCM, PHASE_COMMON);
  6053. bnx2x_init_block(bp, BLOCK_CCM, PHASE_COMMON);
  6054. bnx2x_init_block(bp, BLOCK_XCM, PHASE_COMMON);
  6055. bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3);
  6056. bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3);
  6057. bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3);
  6058. bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3);
  6059. bnx2x_init_block(bp, BLOCK_QM, PHASE_COMMON);
  6060. /* QM queues pointers table */
  6061. bnx2x_qm_init_ptr_table(bp, bp->qm_cid_count, INITOP_SET);
  6062. /* soft reset pulse */
  6063. REG_WR(bp, QM_REG_SOFT_RESET, 1);
  6064. REG_WR(bp, QM_REG_SOFT_RESET, 0);
  6065. if (CNIC_SUPPORT(bp))
  6066. bnx2x_init_block(bp, BLOCK_TM, PHASE_COMMON);
  6067. bnx2x_init_block(bp, BLOCK_DORQ, PHASE_COMMON);
  6068. if (!CHIP_REV_IS_SLOW(bp))
  6069. /* enable hw interrupt from doorbell Q */
  6070. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  6071. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  6072. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  6073. REG_WR(bp, PRS_REG_A_PRSU_20, 0xf);
  6074. if (!CHIP_IS_E1(bp))
  6075. REG_WR(bp, PRS_REG_E1HOV_MODE, bp->path_has_ovlan);
  6076. if (!CHIP_IS_E1x(bp) && !CHIP_IS_E3B0(bp)) {
  6077. if (IS_MF_AFEX(bp)) {
  6078. /* configure that VNTag and VLAN headers must be
  6079. * received in afex mode
  6080. */
  6081. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC, 0xE);
  6082. REG_WR(bp, PRS_REG_MUST_HAVE_HDRS, 0xA);
  6083. REG_WR(bp, PRS_REG_HDRS_AFTER_TAG_0, 0x6);
  6084. REG_WR(bp, PRS_REG_TAG_ETHERTYPE_0, 0x8926);
  6085. REG_WR(bp, PRS_REG_TAG_LEN_0, 0x4);
  6086. } else {
  6087. /* Bit-map indicating which L2 hdrs may appear
  6088. * after the basic Ethernet header
  6089. */
  6090. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC,
  6091. bp->path_has_ovlan ? 7 : 6);
  6092. }
  6093. }
  6094. bnx2x_init_block(bp, BLOCK_TSDM, PHASE_COMMON);
  6095. bnx2x_init_block(bp, BLOCK_CSDM, PHASE_COMMON);
  6096. bnx2x_init_block(bp, BLOCK_USDM, PHASE_COMMON);
  6097. bnx2x_init_block(bp, BLOCK_XSDM, PHASE_COMMON);
  6098. if (!CHIP_IS_E1x(bp)) {
  6099. /* reset VFC memories */
  6100. REG_WR(bp, TSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  6101. VFC_MEMORIES_RST_REG_CAM_RST |
  6102. VFC_MEMORIES_RST_REG_RAM_RST);
  6103. REG_WR(bp, XSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  6104. VFC_MEMORIES_RST_REG_CAM_RST |
  6105. VFC_MEMORIES_RST_REG_RAM_RST);
  6106. msleep(20);
  6107. }
  6108. bnx2x_init_block(bp, BLOCK_TSEM, PHASE_COMMON);
  6109. bnx2x_init_block(bp, BLOCK_USEM, PHASE_COMMON);
  6110. bnx2x_init_block(bp, BLOCK_CSEM, PHASE_COMMON);
  6111. bnx2x_init_block(bp, BLOCK_XSEM, PHASE_COMMON);
  6112. /* sync semi rtc */
  6113. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  6114. 0x80000000);
  6115. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
  6116. 0x80000000);
  6117. bnx2x_init_block(bp, BLOCK_UPB, PHASE_COMMON);
  6118. bnx2x_init_block(bp, BLOCK_XPB, PHASE_COMMON);
  6119. bnx2x_init_block(bp, BLOCK_PBF, PHASE_COMMON);
  6120. if (!CHIP_IS_E1x(bp)) {
  6121. if (IS_MF_AFEX(bp)) {
  6122. /* configure that VNTag and VLAN headers must be
  6123. * sent in afex mode
  6124. */
  6125. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC, 0xE);
  6126. REG_WR(bp, PBF_REG_MUST_HAVE_HDRS, 0xA);
  6127. REG_WR(bp, PBF_REG_HDRS_AFTER_TAG_0, 0x6);
  6128. REG_WR(bp, PBF_REG_TAG_ETHERTYPE_0, 0x8926);
  6129. REG_WR(bp, PBF_REG_TAG_LEN_0, 0x4);
  6130. } else {
  6131. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC,
  6132. bp->path_has_ovlan ? 7 : 6);
  6133. }
  6134. }
  6135. REG_WR(bp, SRC_REG_SOFT_RST, 1);
  6136. bnx2x_init_block(bp, BLOCK_SRC, PHASE_COMMON);
  6137. if (CNIC_SUPPORT(bp)) {
  6138. REG_WR(bp, SRC_REG_KEYSEARCH_0, 0x63285672);
  6139. REG_WR(bp, SRC_REG_KEYSEARCH_1, 0x24b8f2cc);
  6140. REG_WR(bp, SRC_REG_KEYSEARCH_2, 0x223aef9b);
  6141. REG_WR(bp, SRC_REG_KEYSEARCH_3, 0x26001e3a);
  6142. REG_WR(bp, SRC_REG_KEYSEARCH_4, 0x7ae91116);
  6143. REG_WR(bp, SRC_REG_KEYSEARCH_5, 0x5ce5230b);
  6144. REG_WR(bp, SRC_REG_KEYSEARCH_6, 0x298d8adf);
  6145. REG_WR(bp, SRC_REG_KEYSEARCH_7, 0x6eb0ff09);
  6146. REG_WR(bp, SRC_REG_KEYSEARCH_8, 0x1830f82f);
  6147. REG_WR(bp, SRC_REG_KEYSEARCH_9, 0x01e46be7);
  6148. }
  6149. REG_WR(bp, SRC_REG_SOFT_RST, 0);
  6150. if (sizeof(union cdu_context) != 1024)
  6151. /* we currently assume that a context is 1024 bytes */
  6152. dev_alert(&bp->pdev->dev,
  6153. "please adjust the size of cdu_context(%ld)\n",
  6154. (long)sizeof(union cdu_context));
  6155. bnx2x_init_block(bp, BLOCK_CDU, PHASE_COMMON);
  6156. val = (4 << 24) + (0 << 12) + 1024;
  6157. REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val);
  6158. bnx2x_init_block(bp, BLOCK_CFC, PHASE_COMMON);
  6159. REG_WR(bp, CFC_REG_INIT_REG, 0x7FF);
  6160. /* enable context validation interrupt from CFC */
  6161. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  6162. /* set the thresholds to prevent CFC/CDU race */
  6163. REG_WR(bp, CFC_REG_DEBUG0, 0x20020000);
  6164. bnx2x_init_block(bp, BLOCK_HC, PHASE_COMMON);
  6165. if (!CHIP_IS_E1x(bp) && BP_NOMCP(bp))
  6166. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x36);
  6167. bnx2x_init_block(bp, BLOCK_IGU, PHASE_COMMON);
  6168. bnx2x_init_block(bp, BLOCK_MISC_AEU, PHASE_COMMON);
  6169. /* Reset PCIE errors for debug */
  6170. REG_WR(bp, 0x2814, 0xffffffff);
  6171. REG_WR(bp, 0x3820, 0xffffffff);
  6172. if (!CHIP_IS_E1x(bp)) {
  6173. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_CONTROL_5,
  6174. (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1 |
  6175. PXPCS_TL_CONTROL_5_ERR_UNSPPORT));
  6176. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC345_STAT,
  6177. (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4 |
  6178. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3 |
  6179. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2));
  6180. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC678_STAT,
  6181. (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7 |
  6182. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6 |
  6183. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5));
  6184. }
  6185. bnx2x_init_block(bp, BLOCK_NIG, PHASE_COMMON);
  6186. if (!CHIP_IS_E1(bp)) {
  6187. /* in E3 this done in per-port section */
  6188. if (!CHIP_IS_E3(bp))
  6189. REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_MF(bp));
  6190. }
  6191. if (CHIP_IS_E1H(bp))
  6192. /* not applicable for E2 (and above ...) */
  6193. REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_MF_SD(bp));
  6194. if (CHIP_REV_IS_SLOW(bp))
  6195. msleep(200);
  6196. /* finish CFC init */
  6197. val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10);
  6198. if (val != 1) {
  6199. BNX2X_ERR("CFC LL_INIT failed\n");
  6200. return -EBUSY;
  6201. }
  6202. val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10);
  6203. if (val != 1) {
  6204. BNX2X_ERR("CFC AC_INIT failed\n");
  6205. return -EBUSY;
  6206. }
  6207. val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10);
  6208. if (val != 1) {
  6209. BNX2X_ERR("CFC CAM_INIT failed\n");
  6210. return -EBUSY;
  6211. }
  6212. REG_WR(bp, CFC_REG_DEBUG0, 0);
  6213. if (CHIP_IS_E1(bp)) {
  6214. /* read NIG statistic
  6215. to see if this is our first up since powerup */
  6216. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  6217. val = *bnx2x_sp(bp, wb_data[0]);
  6218. /* do internal memory self test */
  6219. if ((val == 0) && bnx2x_int_mem_test(bp)) {
  6220. BNX2X_ERR("internal mem self test failed\n");
  6221. return -EBUSY;
  6222. }
  6223. }
  6224. bnx2x_setup_fan_failure_detection(bp);
  6225. /* clear PXP2 attentions */
  6226. REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0);
  6227. bnx2x_enable_blocks_attention(bp);
  6228. bnx2x_enable_blocks_parity(bp);
  6229. if (!BP_NOMCP(bp)) {
  6230. if (CHIP_IS_E1x(bp))
  6231. bnx2x__common_init_phy(bp);
  6232. } else
  6233. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  6234. return 0;
  6235. }
  6236. /**
  6237. * bnx2x_init_hw_common_chip - init HW at the COMMON_CHIP phase.
  6238. *
  6239. * @bp: driver handle
  6240. */
  6241. static int bnx2x_init_hw_common_chip(struct bnx2x *bp)
  6242. {
  6243. int rc = bnx2x_init_hw_common(bp);
  6244. if (rc)
  6245. return rc;
  6246. /* In E2 2-PORT mode, same ext phy is used for the two paths */
  6247. if (!BP_NOMCP(bp))
  6248. bnx2x__common_init_phy(bp);
  6249. return 0;
  6250. }
  6251. static int bnx2x_init_hw_port(struct bnx2x *bp)
  6252. {
  6253. int port = BP_PORT(bp);
  6254. int init_phase = port ? PHASE_PORT1 : PHASE_PORT0;
  6255. u32 low, high;
  6256. u32 val, reg;
  6257. DP(NETIF_MSG_HW, "starting port init port %d\n", port);
  6258. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  6259. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  6260. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  6261. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  6262. /* Timers bug workaround: disables the pf_master bit in pglue at
  6263. * common phase, we need to enable it here before any dmae access are
  6264. * attempted. Therefore we manually added the enable-master to the
  6265. * port phase (it also happens in the function phase)
  6266. */
  6267. if (!CHIP_IS_E1x(bp))
  6268. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  6269. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  6270. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  6271. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  6272. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  6273. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  6274. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  6275. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  6276. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  6277. /* QM cid (connection) count */
  6278. bnx2x_qm_init_cid_count(bp, bp->qm_cid_count, INITOP_SET);
  6279. if (CNIC_SUPPORT(bp)) {
  6280. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  6281. REG_WR(bp, TM_REG_LIN0_SCAN_TIME + port*4, 20);
  6282. REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31);
  6283. }
  6284. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  6285. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  6286. if (CHIP_IS_E1(bp) || CHIP_IS_E1H(bp)) {
  6287. if (IS_MF(bp))
  6288. low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246);
  6289. else if (bp->dev->mtu > 4096) {
  6290. if (bp->flags & ONE_PORT_FLAG)
  6291. low = 160;
  6292. else {
  6293. val = bp->dev->mtu;
  6294. /* (24*1024 + val*4)/256 */
  6295. low = 96 + (val/64) +
  6296. ((val % 64) ? 1 : 0);
  6297. }
  6298. } else
  6299. low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160);
  6300. high = low + 56; /* 14*1024/256 */
  6301. REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low);
  6302. REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high);
  6303. }
  6304. if (CHIP_MODE_IS_4_PORT(bp))
  6305. REG_WR(bp, (BP_PORT(bp) ?
  6306. BRB1_REG_MAC_GUARANTIED_1 :
  6307. BRB1_REG_MAC_GUARANTIED_0), 40);
  6308. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  6309. if (CHIP_IS_E3B0(bp)) {
  6310. if (IS_MF_AFEX(bp)) {
  6311. /* configure headers for AFEX mode */
  6312. REG_WR(bp, BP_PORT(bp) ?
  6313. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  6314. PRS_REG_HDRS_AFTER_BASIC_PORT_0, 0xE);
  6315. REG_WR(bp, BP_PORT(bp) ?
  6316. PRS_REG_HDRS_AFTER_TAG_0_PORT_1 :
  6317. PRS_REG_HDRS_AFTER_TAG_0_PORT_0, 0x6);
  6318. REG_WR(bp, BP_PORT(bp) ?
  6319. PRS_REG_MUST_HAVE_HDRS_PORT_1 :
  6320. PRS_REG_MUST_HAVE_HDRS_PORT_0, 0xA);
  6321. } else {
  6322. /* Ovlan exists only if we are in multi-function +
  6323. * switch-dependent mode, in switch-independent there
  6324. * is no ovlan headers
  6325. */
  6326. REG_WR(bp, BP_PORT(bp) ?
  6327. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  6328. PRS_REG_HDRS_AFTER_BASIC_PORT_0,
  6329. (bp->path_has_ovlan ? 7 : 6));
  6330. }
  6331. }
  6332. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  6333. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  6334. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  6335. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  6336. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  6337. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  6338. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  6339. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  6340. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  6341. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  6342. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  6343. if (CHIP_IS_E1x(bp)) {
  6344. /* configure PBF to work without PAUSE mtu 9000 */
  6345. REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
  6346. /* update threshold */
  6347. REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16));
  6348. /* update init credit */
  6349. REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22);
  6350. /* probe changes */
  6351. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1);
  6352. udelay(50);
  6353. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0);
  6354. }
  6355. if (CNIC_SUPPORT(bp))
  6356. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  6357. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  6358. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  6359. if (CHIP_IS_E1(bp)) {
  6360. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  6361. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  6362. }
  6363. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  6364. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  6365. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  6366. /* init aeu_mask_attn_func_0/1:
  6367. * - SF mode: bits 3-7 are masked. Only bits 0-2 are in use
  6368. * - MF mode: bit 3 is masked. Bits 0-2 are in use as in SF
  6369. * bits 4-7 are used for "per vn group attention" */
  6370. val = IS_MF(bp) ? 0xF7 : 0x7;
  6371. /* Enable DCBX attention for all but E1 */
  6372. val |= CHIP_IS_E1(bp) ? 0 : 0x10;
  6373. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, val);
  6374. /* SCPAD_PARITY should NOT trigger close the gates */
  6375. reg = port ? MISC_REG_AEU_ENABLE4_NIG_1 : MISC_REG_AEU_ENABLE4_NIG_0;
  6376. REG_WR(bp, reg,
  6377. REG_RD(bp, reg) &
  6378. ~AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY);
  6379. reg = port ? MISC_REG_AEU_ENABLE4_PXP_1 : MISC_REG_AEU_ENABLE4_PXP_0;
  6380. REG_WR(bp, reg,
  6381. REG_RD(bp, reg) &
  6382. ~AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY);
  6383. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  6384. if (!CHIP_IS_E1x(bp)) {
  6385. /* Bit-map indicating which L2 hdrs may appear after the
  6386. * basic Ethernet header
  6387. */
  6388. if (IS_MF_AFEX(bp))
  6389. REG_WR(bp, BP_PORT(bp) ?
  6390. NIG_REG_P1_HDRS_AFTER_BASIC :
  6391. NIG_REG_P0_HDRS_AFTER_BASIC, 0xE);
  6392. else
  6393. REG_WR(bp, BP_PORT(bp) ?
  6394. NIG_REG_P1_HDRS_AFTER_BASIC :
  6395. NIG_REG_P0_HDRS_AFTER_BASIC,
  6396. IS_MF_SD(bp) ? 7 : 6);
  6397. if (CHIP_IS_E3(bp))
  6398. REG_WR(bp, BP_PORT(bp) ?
  6399. NIG_REG_LLH1_MF_MODE :
  6400. NIG_REG_LLH_MF_MODE, IS_MF(bp));
  6401. }
  6402. if (!CHIP_IS_E3(bp))
  6403. REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
  6404. if (!CHIP_IS_E1(bp)) {
  6405. /* 0x2 disable mf_ov, 0x1 enable */
  6406. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4,
  6407. (IS_MF_SD(bp) ? 0x1 : 0x2));
  6408. if (!CHIP_IS_E1x(bp)) {
  6409. val = 0;
  6410. switch (bp->mf_mode) {
  6411. case MULTI_FUNCTION_SD:
  6412. val = 1;
  6413. break;
  6414. case MULTI_FUNCTION_SI:
  6415. case MULTI_FUNCTION_AFEX:
  6416. val = 2;
  6417. break;
  6418. }
  6419. REG_WR(bp, (BP_PORT(bp) ? NIG_REG_LLH1_CLS_TYPE :
  6420. NIG_REG_LLH0_CLS_TYPE), val);
  6421. }
  6422. {
  6423. REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0);
  6424. REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0);
  6425. REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1);
  6426. }
  6427. }
  6428. /* If SPIO5 is set to generate interrupts, enable it for this port */
  6429. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  6430. if (val & MISC_SPIO_SPIO5) {
  6431. u32 reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  6432. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  6433. val = REG_RD(bp, reg_addr);
  6434. val |= AEU_INPUTS_ATTN_BITS_SPIO5;
  6435. REG_WR(bp, reg_addr, val);
  6436. }
  6437. return 0;
  6438. }
  6439. static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr)
  6440. {
  6441. int reg;
  6442. u32 wb_write[2];
  6443. if (CHIP_IS_E1(bp))
  6444. reg = PXP2_REG_RQ_ONCHIP_AT + index*8;
  6445. else
  6446. reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8;
  6447. wb_write[0] = ONCHIP_ADDR1(addr);
  6448. wb_write[1] = ONCHIP_ADDR2(addr);
  6449. REG_WR_DMAE(bp, reg, wb_write, 2);
  6450. }
  6451. void bnx2x_igu_clear_sb_gen(struct bnx2x *bp, u8 func, u8 idu_sb_id, bool is_pf)
  6452. {
  6453. u32 data, ctl, cnt = 100;
  6454. u32 igu_addr_data = IGU_REG_COMMAND_REG_32LSB_DATA;
  6455. u32 igu_addr_ctl = IGU_REG_COMMAND_REG_CTRL;
  6456. u32 igu_addr_ack = IGU_REG_CSTORM_TYPE_0_SB_CLEANUP + (idu_sb_id/32)*4;
  6457. u32 sb_bit = 1 << (idu_sb_id%32);
  6458. u32 func_encode = func | (is_pf ? 1 : 0) << IGU_FID_ENCODE_IS_PF_SHIFT;
  6459. u32 addr_encode = IGU_CMD_E2_PROD_UPD_BASE + idu_sb_id;
  6460. /* Not supported in BC mode */
  6461. if (CHIP_INT_MODE_IS_BC(bp))
  6462. return;
  6463. data = (IGU_USE_REGISTER_cstorm_type_0_sb_cleanup
  6464. << IGU_REGULAR_CLEANUP_TYPE_SHIFT) |
  6465. IGU_REGULAR_CLEANUP_SET |
  6466. IGU_REGULAR_BCLEANUP;
  6467. ctl = addr_encode << IGU_CTRL_REG_ADDRESS_SHIFT |
  6468. func_encode << IGU_CTRL_REG_FID_SHIFT |
  6469. IGU_CTRL_CMD_TYPE_WR << IGU_CTRL_REG_TYPE_SHIFT;
  6470. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  6471. data, igu_addr_data);
  6472. REG_WR(bp, igu_addr_data, data);
  6473. mmiowb();
  6474. barrier();
  6475. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  6476. ctl, igu_addr_ctl);
  6477. REG_WR(bp, igu_addr_ctl, ctl);
  6478. mmiowb();
  6479. barrier();
  6480. /* wait for clean up to finish */
  6481. while (!(REG_RD(bp, igu_addr_ack) & sb_bit) && --cnt)
  6482. msleep(20);
  6483. if (!(REG_RD(bp, igu_addr_ack) & sb_bit)) {
  6484. DP(NETIF_MSG_HW,
  6485. "Unable to finish IGU cleanup: idu_sb_id %d offset %d bit %d (cnt %d)\n",
  6486. idu_sb_id, idu_sb_id/32, idu_sb_id%32, cnt);
  6487. }
  6488. }
  6489. static void bnx2x_igu_clear_sb(struct bnx2x *bp, u8 idu_sb_id)
  6490. {
  6491. bnx2x_igu_clear_sb_gen(bp, BP_FUNC(bp), idu_sb_id, true /*PF*/);
  6492. }
  6493. static void bnx2x_clear_func_ilt(struct bnx2x *bp, u32 func)
  6494. {
  6495. u32 i, base = FUNC_ILT_BASE(func);
  6496. for (i = base; i < base + ILT_PER_FUNC; i++)
  6497. bnx2x_ilt_wr(bp, i, 0);
  6498. }
  6499. static void bnx2x_init_searcher(struct bnx2x *bp)
  6500. {
  6501. int port = BP_PORT(bp);
  6502. bnx2x_src_init_t2(bp, bp->t2, bp->t2_mapping, SRC_CONN_NUM);
  6503. /* T1 hash bits value determines the T1 number of entries */
  6504. REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + port*4, SRC_HASH_BITS);
  6505. }
  6506. static inline int bnx2x_func_switch_update(struct bnx2x *bp, int suspend)
  6507. {
  6508. int rc;
  6509. struct bnx2x_func_state_params func_params = {NULL};
  6510. struct bnx2x_func_switch_update_params *switch_update_params =
  6511. &func_params.params.switch_update;
  6512. /* Prepare parameters for function state transitions */
  6513. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  6514. __set_bit(RAMROD_RETRY, &func_params.ramrod_flags);
  6515. func_params.f_obj = &bp->func_obj;
  6516. func_params.cmd = BNX2X_F_CMD_SWITCH_UPDATE;
  6517. /* Function parameters */
  6518. __set_bit(BNX2X_F_UPDATE_TX_SWITCH_SUSPEND_CHNG,
  6519. &switch_update_params->changes);
  6520. if (suspend)
  6521. __set_bit(BNX2X_F_UPDATE_TX_SWITCH_SUSPEND,
  6522. &switch_update_params->changes);
  6523. rc = bnx2x_func_state_change(bp, &func_params);
  6524. return rc;
  6525. }
  6526. static int bnx2x_reset_nic_mode(struct bnx2x *bp)
  6527. {
  6528. int rc, i, port = BP_PORT(bp);
  6529. int vlan_en = 0, mac_en[NUM_MACS];
  6530. /* Close input from network */
  6531. if (bp->mf_mode == SINGLE_FUNCTION) {
  6532. bnx2x_set_rx_filter(&bp->link_params, 0);
  6533. } else {
  6534. vlan_en = REG_RD(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6535. NIG_REG_LLH0_FUNC_EN);
  6536. REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6537. NIG_REG_LLH0_FUNC_EN, 0);
  6538. for (i = 0; i < NUM_MACS; i++) {
  6539. mac_en[i] = REG_RD(bp, port ?
  6540. (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6541. 4 * i) :
  6542. (NIG_REG_LLH0_FUNC_MEM_ENABLE +
  6543. 4 * i));
  6544. REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6545. 4 * i) :
  6546. (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i), 0);
  6547. }
  6548. }
  6549. /* Close BMC to host */
  6550. REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
  6551. NIG_REG_P1_TX_MNG_HOST_ENABLE, 0);
  6552. /* Suspend Tx switching to the PF. Completion of this ramrod
  6553. * further guarantees that all the packets of that PF / child
  6554. * VFs in BRB were processed by the Parser, so it is safe to
  6555. * change the NIC_MODE register.
  6556. */
  6557. rc = bnx2x_func_switch_update(bp, 1);
  6558. if (rc) {
  6559. BNX2X_ERR("Can't suspend tx-switching!\n");
  6560. return rc;
  6561. }
  6562. /* Change NIC_MODE register */
  6563. REG_WR(bp, PRS_REG_NIC_MODE, 0);
  6564. /* Open input from network */
  6565. if (bp->mf_mode == SINGLE_FUNCTION) {
  6566. bnx2x_set_rx_filter(&bp->link_params, 1);
  6567. } else {
  6568. REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6569. NIG_REG_LLH0_FUNC_EN, vlan_en);
  6570. for (i = 0; i < NUM_MACS; i++) {
  6571. REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6572. 4 * i) :
  6573. (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i),
  6574. mac_en[i]);
  6575. }
  6576. }
  6577. /* Enable BMC to host */
  6578. REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
  6579. NIG_REG_P1_TX_MNG_HOST_ENABLE, 1);
  6580. /* Resume Tx switching to the PF */
  6581. rc = bnx2x_func_switch_update(bp, 0);
  6582. if (rc) {
  6583. BNX2X_ERR("Can't resume tx-switching!\n");
  6584. return rc;
  6585. }
  6586. DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
  6587. return 0;
  6588. }
  6589. int bnx2x_init_hw_func_cnic(struct bnx2x *bp)
  6590. {
  6591. int rc;
  6592. bnx2x_ilt_init_op_cnic(bp, INITOP_SET);
  6593. if (CONFIGURE_NIC_MODE(bp)) {
  6594. /* Configure searcher as part of function hw init */
  6595. bnx2x_init_searcher(bp);
  6596. /* Reset NIC mode */
  6597. rc = bnx2x_reset_nic_mode(bp);
  6598. if (rc)
  6599. BNX2X_ERR("Can't change NIC mode!\n");
  6600. return rc;
  6601. }
  6602. return 0;
  6603. }
  6604. static int bnx2x_init_hw_func(struct bnx2x *bp)
  6605. {
  6606. int port = BP_PORT(bp);
  6607. int func = BP_FUNC(bp);
  6608. int init_phase = PHASE_PF0 + func;
  6609. struct bnx2x_ilt *ilt = BP_ILT(bp);
  6610. u16 cdu_ilt_start;
  6611. u32 addr, val;
  6612. u32 main_mem_base, main_mem_size, main_mem_prty_clr;
  6613. int i, main_mem_width, rc;
  6614. DP(NETIF_MSG_HW, "starting func init func %d\n", func);
  6615. /* FLR cleanup - hmmm */
  6616. if (!CHIP_IS_E1x(bp)) {
  6617. rc = bnx2x_pf_flr_clnup(bp);
  6618. if (rc) {
  6619. bnx2x_fw_dump(bp);
  6620. return rc;
  6621. }
  6622. }
  6623. /* set MSI reconfigure capability */
  6624. if (bp->common.int_block == INT_BLOCK_HC) {
  6625. addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0);
  6626. val = REG_RD(bp, addr);
  6627. val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0;
  6628. REG_WR(bp, addr, val);
  6629. }
  6630. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  6631. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  6632. ilt = BP_ILT(bp);
  6633. cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
  6634. if (IS_SRIOV(bp))
  6635. cdu_ilt_start += BNX2X_FIRST_VF_CID/ILT_PAGE_CIDS;
  6636. cdu_ilt_start = bnx2x_iov_init_ilt(bp, cdu_ilt_start);
  6637. /* since BNX2X_FIRST_VF_CID > 0 the PF L2 cids precedes
  6638. * those of the VFs, so start line should be reset
  6639. */
  6640. cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
  6641. for (i = 0; i < L2_ILT_LINES(bp); i++) {
  6642. ilt->lines[cdu_ilt_start + i].page = bp->context[i].vcxt;
  6643. ilt->lines[cdu_ilt_start + i].page_mapping =
  6644. bp->context[i].cxt_mapping;
  6645. ilt->lines[cdu_ilt_start + i].size = bp->context[i].size;
  6646. }
  6647. bnx2x_ilt_init_op(bp, INITOP_SET);
  6648. if (!CONFIGURE_NIC_MODE(bp)) {
  6649. bnx2x_init_searcher(bp);
  6650. REG_WR(bp, PRS_REG_NIC_MODE, 0);
  6651. DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
  6652. } else {
  6653. /* Set NIC mode */
  6654. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  6655. DP(NETIF_MSG_IFUP, "NIC MODE configured\n");
  6656. }
  6657. if (!CHIP_IS_E1x(bp)) {
  6658. u32 pf_conf = IGU_PF_CONF_FUNC_EN;
  6659. /* Turn on a single ISR mode in IGU if driver is going to use
  6660. * INT#x or MSI
  6661. */
  6662. if (!(bp->flags & USING_MSIX_FLAG))
  6663. pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN;
  6664. /*
  6665. * Timers workaround bug: function init part.
  6666. * Need to wait 20msec after initializing ILT,
  6667. * needed to make sure there are no requests in
  6668. * one of the PXP internal queues with "old" ILT addresses
  6669. */
  6670. msleep(20);
  6671. /*
  6672. * Master enable - Due to WB DMAE writes performed before this
  6673. * register is re-initialized as part of the regular function
  6674. * init
  6675. */
  6676. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  6677. /* Enable the function in IGU */
  6678. REG_WR(bp, IGU_REG_PF_CONFIGURATION, pf_conf);
  6679. }
  6680. bp->dmae_ready = 1;
  6681. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  6682. if (!CHIP_IS_E1x(bp))
  6683. REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, func);
  6684. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  6685. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  6686. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  6687. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  6688. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  6689. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  6690. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  6691. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  6692. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  6693. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  6694. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  6695. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  6696. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  6697. if (!CHIP_IS_E1x(bp))
  6698. REG_WR(bp, QM_REG_PF_EN, 1);
  6699. if (!CHIP_IS_E1x(bp)) {
  6700. REG_WR(bp, TSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6701. REG_WR(bp, USEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6702. REG_WR(bp, CSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6703. REG_WR(bp, XSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6704. }
  6705. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  6706. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  6707. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  6708. REG_WR(bp, DORQ_REG_MODE_ACT, 1); /* no dpm */
  6709. bnx2x_iov_init_dq(bp);
  6710. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  6711. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  6712. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  6713. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  6714. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  6715. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  6716. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  6717. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  6718. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  6719. if (!CHIP_IS_E1x(bp))
  6720. REG_WR(bp, PBF_REG_DISABLE_PF, 0);
  6721. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  6722. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  6723. if (!CHIP_IS_E1x(bp))
  6724. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 1);
  6725. if (IS_MF(bp)) {
  6726. if (!(IS_MF_UFP(bp) && BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp))) {
  6727. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port * 8, 1);
  6728. REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port * 8,
  6729. bp->mf_ov);
  6730. }
  6731. }
  6732. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  6733. /* HC init per function */
  6734. if (bp->common.int_block == INT_BLOCK_HC) {
  6735. if (CHIP_IS_E1H(bp)) {
  6736. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  6737. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  6738. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  6739. }
  6740. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  6741. } else {
  6742. int num_segs, sb_idx, prod_offset;
  6743. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  6744. if (!CHIP_IS_E1x(bp)) {
  6745. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  6746. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  6747. }
  6748. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  6749. if (!CHIP_IS_E1x(bp)) {
  6750. int dsb_idx = 0;
  6751. /**
  6752. * Producer memory:
  6753. * E2 mode: address 0-135 match to the mapping memory;
  6754. * 136 - PF0 default prod; 137 - PF1 default prod;
  6755. * 138 - PF2 default prod; 139 - PF3 default prod;
  6756. * 140 - PF0 attn prod; 141 - PF1 attn prod;
  6757. * 142 - PF2 attn prod; 143 - PF3 attn prod;
  6758. * 144-147 reserved.
  6759. *
  6760. * E1.5 mode - In backward compatible mode;
  6761. * for non default SB; each even line in the memory
  6762. * holds the U producer and each odd line hold
  6763. * the C producer. The first 128 producers are for
  6764. * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20
  6765. * producers are for the DSB for each PF.
  6766. * Each PF has five segments: (the order inside each
  6767. * segment is PF0; PF1; PF2; PF3) - 128-131 U prods;
  6768. * 132-135 C prods; 136-139 X prods; 140-143 T prods;
  6769. * 144-147 attn prods;
  6770. */
  6771. /* non-default-status-blocks */
  6772. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  6773. IGU_BC_NDSB_NUM_SEGS : IGU_NORM_NDSB_NUM_SEGS;
  6774. for (sb_idx = 0; sb_idx < bp->igu_sb_cnt; sb_idx++) {
  6775. prod_offset = (bp->igu_base_sb + sb_idx) *
  6776. num_segs;
  6777. for (i = 0; i < num_segs; i++) {
  6778. addr = IGU_REG_PROD_CONS_MEMORY +
  6779. (prod_offset + i) * 4;
  6780. REG_WR(bp, addr, 0);
  6781. }
  6782. /* send consumer update with value 0 */
  6783. bnx2x_ack_sb(bp, bp->igu_base_sb + sb_idx,
  6784. USTORM_ID, 0, IGU_INT_NOP, 1);
  6785. bnx2x_igu_clear_sb(bp,
  6786. bp->igu_base_sb + sb_idx);
  6787. }
  6788. /* default-status-blocks */
  6789. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  6790. IGU_BC_DSB_NUM_SEGS : IGU_NORM_DSB_NUM_SEGS;
  6791. if (CHIP_MODE_IS_4_PORT(bp))
  6792. dsb_idx = BP_FUNC(bp);
  6793. else
  6794. dsb_idx = BP_VN(bp);
  6795. prod_offset = (CHIP_INT_MODE_IS_BC(bp) ?
  6796. IGU_BC_BASE_DSB_PROD + dsb_idx :
  6797. IGU_NORM_BASE_DSB_PROD + dsb_idx);
  6798. /*
  6799. * igu prods come in chunks of E1HVN_MAX (4) -
  6800. * does not matters what is the current chip mode
  6801. */
  6802. for (i = 0; i < (num_segs * E1HVN_MAX);
  6803. i += E1HVN_MAX) {
  6804. addr = IGU_REG_PROD_CONS_MEMORY +
  6805. (prod_offset + i)*4;
  6806. REG_WR(bp, addr, 0);
  6807. }
  6808. /* send consumer update with 0 */
  6809. if (CHIP_INT_MODE_IS_BC(bp)) {
  6810. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6811. USTORM_ID, 0, IGU_INT_NOP, 1);
  6812. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6813. CSTORM_ID, 0, IGU_INT_NOP, 1);
  6814. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6815. XSTORM_ID, 0, IGU_INT_NOP, 1);
  6816. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6817. TSTORM_ID, 0, IGU_INT_NOP, 1);
  6818. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6819. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  6820. } else {
  6821. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6822. USTORM_ID, 0, IGU_INT_NOP, 1);
  6823. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6824. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  6825. }
  6826. bnx2x_igu_clear_sb(bp, bp->igu_dsb_id);
  6827. /* !!! These should become driver const once
  6828. rf-tool supports split-68 const */
  6829. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0);
  6830. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0);
  6831. REG_WR(bp, IGU_REG_SB_MASK_LSB, 0);
  6832. REG_WR(bp, IGU_REG_SB_MASK_MSB, 0);
  6833. REG_WR(bp, IGU_REG_PBA_STATUS_LSB, 0);
  6834. REG_WR(bp, IGU_REG_PBA_STATUS_MSB, 0);
  6835. }
  6836. }
  6837. /* Reset PCIE errors for debug */
  6838. REG_WR(bp, 0x2114, 0xffffffff);
  6839. REG_WR(bp, 0x2120, 0xffffffff);
  6840. if (CHIP_IS_E1x(bp)) {
  6841. main_mem_size = HC_REG_MAIN_MEMORY_SIZE / 2; /*dwords*/
  6842. main_mem_base = HC_REG_MAIN_MEMORY +
  6843. BP_PORT(bp) * (main_mem_size * 4);
  6844. main_mem_prty_clr = HC_REG_HC_PRTY_STS_CLR;
  6845. main_mem_width = 8;
  6846. val = REG_RD(bp, main_mem_prty_clr);
  6847. if (val)
  6848. DP(NETIF_MSG_HW,
  6849. "Hmmm... Parity errors in HC block during function init (0x%x)!\n",
  6850. val);
  6851. /* Clear "false" parity errors in MSI-X table */
  6852. for (i = main_mem_base;
  6853. i < main_mem_base + main_mem_size * 4;
  6854. i += main_mem_width) {
  6855. bnx2x_read_dmae(bp, i, main_mem_width / 4);
  6856. bnx2x_write_dmae(bp, bnx2x_sp_mapping(bp, wb_data),
  6857. i, main_mem_width / 4);
  6858. }
  6859. /* Clear HC parity attention */
  6860. REG_RD(bp, main_mem_prty_clr);
  6861. }
  6862. #ifdef BNX2X_STOP_ON_ERROR
  6863. /* Enable STORMs SP logging */
  6864. REG_WR8(bp, BAR_USTRORM_INTMEM +
  6865. USTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6866. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  6867. TSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6868. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6869. CSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6870. REG_WR8(bp, BAR_XSTRORM_INTMEM +
  6871. XSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6872. #endif
  6873. bnx2x_phy_probe(&bp->link_params);
  6874. return 0;
  6875. }
  6876. void bnx2x_free_mem_cnic(struct bnx2x *bp)
  6877. {
  6878. bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_FREE);
  6879. if (!CHIP_IS_E1x(bp))
  6880. BNX2X_PCI_FREE(bp->cnic_sb.e2_sb, bp->cnic_sb_mapping,
  6881. sizeof(struct host_hc_status_block_e2));
  6882. else
  6883. BNX2X_PCI_FREE(bp->cnic_sb.e1x_sb, bp->cnic_sb_mapping,
  6884. sizeof(struct host_hc_status_block_e1x));
  6885. BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
  6886. }
  6887. void bnx2x_free_mem(struct bnx2x *bp)
  6888. {
  6889. int i;
  6890. BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
  6891. bp->fw_stats_data_sz + bp->fw_stats_req_sz);
  6892. if (IS_VF(bp))
  6893. return;
  6894. BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping,
  6895. sizeof(struct host_sp_status_block));
  6896. BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping,
  6897. sizeof(struct bnx2x_slowpath));
  6898. for (i = 0; i < L2_ILT_LINES(bp); i++)
  6899. BNX2X_PCI_FREE(bp->context[i].vcxt, bp->context[i].cxt_mapping,
  6900. bp->context[i].size);
  6901. bnx2x_ilt_mem_op(bp, ILT_MEMOP_FREE);
  6902. BNX2X_FREE(bp->ilt->lines);
  6903. BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE);
  6904. BNX2X_PCI_FREE(bp->eq_ring, bp->eq_mapping,
  6905. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  6906. BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
  6907. bnx2x_iov_free_mem(bp);
  6908. }
  6909. int bnx2x_alloc_mem_cnic(struct bnx2x *bp)
  6910. {
  6911. if (!CHIP_IS_E1x(bp)) {
  6912. /* size = the status block + ramrod buffers */
  6913. bp->cnic_sb.e2_sb = BNX2X_PCI_ALLOC(&bp->cnic_sb_mapping,
  6914. sizeof(struct host_hc_status_block_e2));
  6915. if (!bp->cnic_sb.e2_sb)
  6916. goto alloc_mem_err;
  6917. } else {
  6918. bp->cnic_sb.e1x_sb = BNX2X_PCI_ALLOC(&bp->cnic_sb_mapping,
  6919. sizeof(struct host_hc_status_block_e1x));
  6920. if (!bp->cnic_sb.e1x_sb)
  6921. goto alloc_mem_err;
  6922. }
  6923. if (CONFIGURE_NIC_MODE(bp) && !bp->t2) {
  6924. /* allocate searcher T2 table, as it wasn't allocated before */
  6925. bp->t2 = BNX2X_PCI_ALLOC(&bp->t2_mapping, SRC_T2_SZ);
  6926. if (!bp->t2)
  6927. goto alloc_mem_err;
  6928. }
  6929. /* write address to which L5 should insert its values */
  6930. bp->cnic_eth_dev.addr_drv_info_to_mcp =
  6931. &bp->slowpath->drv_info_to_mcp;
  6932. if (bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_ALLOC))
  6933. goto alloc_mem_err;
  6934. return 0;
  6935. alloc_mem_err:
  6936. bnx2x_free_mem_cnic(bp);
  6937. BNX2X_ERR("Can't allocate memory\n");
  6938. return -ENOMEM;
  6939. }
  6940. int bnx2x_alloc_mem(struct bnx2x *bp)
  6941. {
  6942. int i, allocated, context_size;
  6943. if (!CONFIGURE_NIC_MODE(bp) && !bp->t2) {
  6944. /* allocate searcher T2 table */
  6945. bp->t2 = BNX2X_PCI_ALLOC(&bp->t2_mapping, SRC_T2_SZ);
  6946. if (!bp->t2)
  6947. goto alloc_mem_err;
  6948. }
  6949. bp->def_status_blk = BNX2X_PCI_ALLOC(&bp->def_status_blk_mapping,
  6950. sizeof(struct host_sp_status_block));
  6951. if (!bp->def_status_blk)
  6952. goto alloc_mem_err;
  6953. bp->slowpath = BNX2X_PCI_ALLOC(&bp->slowpath_mapping,
  6954. sizeof(struct bnx2x_slowpath));
  6955. if (!bp->slowpath)
  6956. goto alloc_mem_err;
  6957. /* Allocate memory for CDU context:
  6958. * This memory is allocated separately and not in the generic ILT
  6959. * functions because CDU differs in few aspects:
  6960. * 1. There are multiple entities allocating memory for context -
  6961. * 'regular' driver, CNIC and SRIOV driver. Each separately controls
  6962. * its own ILT lines.
  6963. * 2. Since CDU page-size is not a single 4KB page (which is the case
  6964. * for the other ILT clients), to be efficient we want to support
  6965. * allocation of sub-page-size in the last entry.
  6966. * 3. Context pointers are used by the driver to pass to FW / update
  6967. * the context (for the other ILT clients the pointers are used just to
  6968. * free the memory during unload).
  6969. */
  6970. context_size = sizeof(union cdu_context) * BNX2X_L2_CID_COUNT(bp);
  6971. for (i = 0, allocated = 0; allocated < context_size; i++) {
  6972. bp->context[i].size = min(CDU_ILT_PAGE_SZ,
  6973. (context_size - allocated));
  6974. bp->context[i].vcxt = BNX2X_PCI_ALLOC(&bp->context[i].cxt_mapping,
  6975. bp->context[i].size);
  6976. if (!bp->context[i].vcxt)
  6977. goto alloc_mem_err;
  6978. allocated += bp->context[i].size;
  6979. }
  6980. bp->ilt->lines = kcalloc(ILT_MAX_LINES, sizeof(struct ilt_line),
  6981. GFP_KERNEL);
  6982. if (!bp->ilt->lines)
  6983. goto alloc_mem_err;
  6984. if (bnx2x_ilt_mem_op(bp, ILT_MEMOP_ALLOC))
  6985. goto alloc_mem_err;
  6986. if (bnx2x_iov_alloc_mem(bp))
  6987. goto alloc_mem_err;
  6988. /* Slow path ring */
  6989. bp->spq = BNX2X_PCI_ALLOC(&bp->spq_mapping, BCM_PAGE_SIZE);
  6990. if (!bp->spq)
  6991. goto alloc_mem_err;
  6992. /* EQ */
  6993. bp->eq_ring = BNX2X_PCI_ALLOC(&bp->eq_mapping,
  6994. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  6995. if (!bp->eq_ring)
  6996. goto alloc_mem_err;
  6997. return 0;
  6998. alloc_mem_err:
  6999. bnx2x_free_mem(bp);
  7000. BNX2X_ERR("Can't allocate memory\n");
  7001. return -ENOMEM;
  7002. }
  7003. /*
  7004. * Init service functions
  7005. */
  7006. int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac,
  7007. struct bnx2x_vlan_mac_obj *obj, bool set,
  7008. int mac_type, unsigned long *ramrod_flags)
  7009. {
  7010. int rc;
  7011. struct bnx2x_vlan_mac_ramrod_params ramrod_param;
  7012. memset(&ramrod_param, 0, sizeof(ramrod_param));
  7013. /* Fill general parameters */
  7014. ramrod_param.vlan_mac_obj = obj;
  7015. ramrod_param.ramrod_flags = *ramrod_flags;
  7016. /* Fill a user request section if needed */
  7017. if (!test_bit(RAMROD_CONT, ramrod_flags)) {
  7018. memcpy(ramrod_param.user_req.u.mac.mac, mac, ETH_ALEN);
  7019. __set_bit(mac_type, &ramrod_param.user_req.vlan_mac_flags);
  7020. /* Set the command: ADD or DEL */
  7021. if (set)
  7022. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD;
  7023. else
  7024. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_DEL;
  7025. }
  7026. rc = bnx2x_config_vlan_mac(bp, &ramrod_param);
  7027. if (rc == -EEXIST) {
  7028. DP(BNX2X_MSG_SP, "Failed to schedule ADD operations: %d\n", rc);
  7029. /* do not treat adding same MAC as error */
  7030. rc = 0;
  7031. } else if (rc < 0)
  7032. BNX2X_ERR("%s MAC failed\n", (set ? "Set" : "Del"));
  7033. return rc;
  7034. }
  7035. int bnx2x_del_all_macs(struct bnx2x *bp,
  7036. struct bnx2x_vlan_mac_obj *mac_obj,
  7037. int mac_type, bool wait_for_comp)
  7038. {
  7039. int rc;
  7040. unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
  7041. /* Wait for completion of requested */
  7042. if (wait_for_comp)
  7043. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  7044. /* Set the mac type of addresses we want to clear */
  7045. __set_bit(mac_type, &vlan_mac_flags);
  7046. rc = mac_obj->delete_all(bp, mac_obj, &vlan_mac_flags, &ramrod_flags);
  7047. if (rc < 0)
  7048. BNX2X_ERR("Failed to delete MACs: %d\n", rc);
  7049. return rc;
  7050. }
  7051. int bnx2x_set_eth_mac(struct bnx2x *bp, bool set)
  7052. {
  7053. if (IS_PF(bp)) {
  7054. unsigned long ramrod_flags = 0;
  7055. DP(NETIF_MSG_IFUP, "Adding Eth MAC\n");
  7056. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  7057. return bnx2x_set_mac_one(bp, bp->dev->dev_addr,
  7058. &bp->sp_objs->mac_obj, set,
  7059. BNX2X_ETH_MAC, &ramrod_flags);
  7060. } else { /* vf */
  7061. return bnx2x_vfpf_config_mac(bp, bp->dev->dev_addr,
  7062. bp->fp->index, true);
  7063. }
  7064. }
  7065. int bnx2x_setup_leading(struct bnx2x *bp)
  7066. {
  7067. if (IS_PF(bp))
  7068. return bnx2x_setup_queue(bp, &bp->fp[0], true);
  7069. else /* VF */
  7070. return bnx2x_vfpf_setup_q(bp, &bp->fp[0], true);
  7071. }
  7072. /**
  7073. * bnx2x_set_int_mode - configure interrupt mode
  7074. *
  7075. * @bp: driver handle
  7076. *
  7077. * In case of MSI-X it will also try to enable MSI-X.
  7078. */
  7079. int bnx2x_set_int_mode(struct bnx2x *bp)
  7080. {
  7081. int rc = 0;
  7082. if (IS_VF(bp) && int_mode != BNX2X_INT_MODE_MSIX) {
  7083. BNX2X_ERR("VF not loaded since interrupt mode not msix\n");
  7084. return -EINVAL;
  7085. }
  7086. switch (int_mode) {
  7087. case BNX2X_INT_MODE_MSIX:
  7088. /* attempt to enable msix */
  7089. rc = bnx2x_enable_msix(bp);
  7090. /* msix attained */
  7091. if (!rc)
  7092. return 0;
  7093. /* vfs use only msix */
  7094. if (rc && IS_VF(bp))
  7095. return rc;
  7096. /* failed to enable multiple MSI-X */
  7097. BNX2X_DEV_INFO("Failed to enable multiple MSI-X (%d), set number of queues to %d\n",
  7098. bp->num_queues,
  7099. 1 + bp->num_cnic_queues);
  7100. /* falling through... */
  7101. case BNX2X_INT_MODE_MSI:
  7102. bnx2x_enable_msi(bp);
  7103. /* falling through... */
  7104. case BNX2X_INT_MODE_INTX:
  7105. bp->num_ethernet_queues = 1;
  7106. bp->num_queues = bp->num_ethernet_queues + bp->num_cnic_queues;
  7107. BNX2X_DEV_INFO("set number of queues to 1\n");
  7108. break;
  7109. default:
  7110. BNX2X_DEV_INFO("unknown value in int_mode module parameter\n");
  7111. return -EINVAL;
  7112. }
  7113. return 0;
  7114. }
  7115. /* must be called prior to any HW initializations */
  7116. static inline u16 bnx2x_cid_ilt_lines(struct bnx2x *bp)
  7117. {
  7118. if (IS_SRIOV(bp))
  7119. return (BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)/ILT_PAGE_CIDS;
  7120. return L2_ILT_LINES(bp);
  7121. }
  7122. void bnx2x_ilt_set_info(struct bnx2x *bp)
  7123. {
  7124. struct ilt_client_info *ilt_client;
  7125. struct bnx2x_ilt *ilt = BP_ILT(bp);
  7126. u16 line = 0;
  7127. ilt->start_line = FUNC_ILT_BASE(BP_FUNC(bp));
  7128. DP(BNX2X_MSG_SP, "ilt starts at line %d\n", ilt->start_line);
  7129. /* CDU */
  7130. ilt_client = &ilt->clients[ILT_CLIENT_CDU];
  7131. ilt_client->client_num = ILT_CLIENT_CDU;
  7132. ilt_client->page_size = CDU_ILT_PAGE_SZ;
  7133. ilt_client->flags = ILT_CLIENT_SKIP_MEM;
  7134. ilt_client->start = line;
  7135. line += bnx2x_cid_ilt_lines(bp);
  7136. if (CNIC_SUPPORT(bp))
  7137. line += CNIC_ILT_LINES;
  7138. ilt_client->end = line - 1;
  7139. DP(NETIF_MSG_IFUP, "ilt client[CDU]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  7140. ilt_client->start,
  7141. ilt_client->end,
  7142. ilt_client->page_size,
  7143. ilt_client->flags,
  7144. ilog2(ilt_client->page_size >> 12));
  7145. /* QM */
  7146. if (QM_INIT(bp->qm_cid_count)) {
  7147. ilt_client = &ilt->clients[ILT_CLIENT_QM];
  7148. ilt_client->client_num = ILT_CLIENT_QM;
  7149. ilt_client->page_size = QM_ILT_PAGE_SZ;
  7150. ilt_client->flags = 0;
  7151. ilt_client->start = line;
  7152. /* 4 bytes for each cid */
  7153. line += DIV_ROUND_UP(bp->qm_cid_count * QM_QUEUES_PER_FUNC * 4,
  7154. QM_ILT_PAGE_SZ);
  7155. ilt_client->end = line - 1;
  7156. DP(NETIF_MSG_IFUP,
  7157. "ilt client[QM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  7158. ilt_client->start,
  7159. ilt_client->end,
  7160. ilt_client->page_size,
  7161. ilt_client->flags,
  7162. ilog2(ilt_client->page_size >> 12));
  7163. }
  7164. if (CNIC_SUPPORT(bp)) {
  7165. /* SRC */
  7166. ilt_client = &ilt->clients[ILT_CLIENT_SRC];
  7167. ilt_client->client_num = ILT_CLIENT_SRC;
  7168. ilt_client->page_size = SRC_ILT_PAGE_SZ;
  7169. ilt_client->flags = 0;
  7170. ilt_client->start = line;
  7171. line += SRC_ILT_LINES;
  7172. ilt_client->end = line - 1;
  7173. DP(NETIF_MSG_IFUP,
  7174. "ilt client[SRC]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  7175. ilt_client->start,
  7176. ilt_client->end,
  7177. ilt_client->page_size,
  7178. ilt_client->flags,
  7179. ilog2(ilt_client->page_size >> 12));
  7180. /* TM */
  7181. ilt_client = &ilt->clients[ILT_CLIENT_TM];
  7182. ilt_client->client_num = ILT_CLIENT_TM;
  7183. ilt_client->page_size = TM_ILT_PAGE_SZ;
  7184. ilt_client->flags = 0;
  7185. ilt_client->start = line;
  7186. line += TM_ILT_LINES;
  7187. ilt_client->end = line - 1;
  7188. DP(NETIF_MSG_IFUP,
  7189. "ilt client[TM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  7190. ilt_client->start,
  7191. ilt_client->end,
  7192. ilt_client->page_size,
  7193. ilt_client->flags,
  7194. ilog2(ilt_client->page_size >> 12));
  7195. }
  7196. BUG_ON(line > ILT_MAX_LINES);
  7197. }
  7198. /**
  7199. * bnx2x_pf_q_prep_init - prepare INIT transition parameters
  7200. *
  7201. * @bp: driver handle
  7202. * @fp: pointer to fastpath
  7203. * @init_params: pointer to parameters structure
  7204. *
  7205. * parameters configured:
  7206. * - HC configuration
  7207. * - Queue's CDU context
  7208. */
  7209. static void bnx2x_pf_q_prep_init(struct bnx2x *bp,
  7210. struct bnx2x_fastpath *fp, struct bnx2x_queue_init_params *init_params)
  7211. {
  7212. u8 cos;
  7213. int cxt_index, cxt_offset;
  7214. /* FCoE Queue uses Default SB, thus has no HC capabilities */
  7215. if (!IS_FCOE_FP(fp)) {
  7216. __set_bit(BNX2X_Q_FLG_HC, &init_params->rx.flags);
  7217. __set_bit(BNX2X_Q_FLG_HC, &init_params->tx.flags);
  7218. /* If HC is supported, enable host coalescing in the transition
  7219. * to INIT state.
  7220. */
  7221. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->rx.flags);
  7222. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->tx.flags);
  7223. /* HC rate */
  7224. init_params->rx.hc_rate = bp->rx_ticks ?
  7225. (1000000 / bp->rx_ticks) : 0;
  7226. init_params->tx.hc_rate = bp->tx_ticks ?
  7227. (1000000 / bp->tx_ticks) : 0;
  7228. /* FW SB ID */
  7229. init_params->rx.fw_sb_id = init_params->tx.fw_sb_id =
  7230. fp->fw_sb_id;
  7231. /*
  7232. * CQ index among the SB indices: FCoE clients uses the default
  7233. * SB, therefore it's different.
  7234. */
  7235. init_params->rx.sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  7236. init_params->tx.sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS;
  7237. }
  7238. /* set maximum number of COSs supported by this queue */
  7239. init_params->max_cos = fp->max_cos;
  7240. DP(NETIF_MSG_IFUP, "fp: %d setting queue params max cos to: %d\n",
  7241. fp->index, init_params->max_cos);
  7242. /* set the context pointers queue object */
  7243. for (cos = FIRST_TX_COS_INDEX; cos < init_params->max_cos; cos++) {
  7244. cxt_index = fp->txdata_ptr[cos]->cid / ILT_PAGE_CIDS;
  7245. cxt_offset = fp->txdata_ptr[cos]->cid - (cxt_index *
  7246. ILT_PAGE_CIDS);
  7247. init_params->cxts[cos] =
  7248. &bp->context[cxt_index].vcxt[cxt_offset].eth;
  7249. }
  7250. }
  7251. static int bnx2x_setup_tx_only(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  7252. struct bnx2x_queue_state_params *q_params,
  7253. struct bnx2x_queue_setup_tx_only_params *tx_only_params,
  7254. int tx_index, bool leading)
  7255. {
  7256. memset(tx_only_params, 0, sizeof(*tx_only_params));
  7257. /* Set the command */
  7258. q_params->cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  7259. /* Set tx-only QUEUE flags: don't zero statistics */
  7260. tx_only_params->flags = bnx2x_get_common_flags(bp, fp, false);
  7261. /* choose the index of the cid to send the slow path on */
  7262. tx_only_params->cid_index = tx_index;
  7263. /* Set general TX_ONLY_SETUP parameters */
  7264. bnx2x_pf_q_prep_general(bp, fp, &tx_only_params->gen_params, tx_index);
  7265. /* Set Tx TX_ONLY_SETUP parameters */
  7266. bnx2x_pf_tx_q_prep(bp, fp, &tx_only_params->txq_params, tx_index);
  7267. DP(NETIF_MSG_IFUP,
  7268. "preparing to send tx-only ramrod for connection: cos %d, primary cid %d, cid %d, client id %d, sp-client id %d, flags %lx\n",
  7269. tx_index, q_params->q_obj->cids[FIRST_TX_COS_INDEX],
  7270. q_params->q_obj->cids[tx_index], q_params->q_obj->cl_id,
  7271. tx_only_params->gen_params.spcl_id, tx_only_params->flags);
  7272. /* send the ramrod */
  7273. return bnx2x_queue_state_change(bp, q_params);
  7274. }
  7275. /**
  7276. * bnx2x_setup_queue - setup queue
  7277. *
  7278. * @bp: driver handle
  7279. * @fp: pointer to fastpath
  7280. * @leading: is leading
  7281. *
  7282. * This function performs 2 steps in a Queue state machine
  7283. * actually: 1) RESET->INIT 2) INIT->SETUP
  7284. */
  7285. int bnx2x_setup_queue(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  7286. bool leading)
  7287. {
  7288. struct bnx2x_queue_state_params q_params = {NULL};
  7289. struct bnx2x_queue_setup_params *setup_params =
  7290. &q_params.params.setup;
  7291. struct bnx2x_queue_setup_tx_only_params *tx_only_params =
  7292. &q_params.params.tx_only;
  7293. int rc;
  7294. u8 tx_index;
  7295. DP(NETIF_MSG_IFUP, "setting up queue %d\n", fp->index);
  7296. /* reset IGU state skip FCoE L2 queue */
  7297. if (!IS_FCOE_FP(fp))
  7298. bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID, 0,
  7299. IGU_INT_ENABLE, 0);
  7300. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  7301. /* We want to wait for completion in this context */
  7302. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  7303. /* Prepare the INIT parameters */
  7304. bnx2x_pf_q_prep_init(bp, fp, &q_params.params.init);
  7305. /* Set the command */
  7306. q_params.cmd = BNX2X_Q_CMD_INIT;
  7307. /* Change the state to INIT */
  7308. rc = bnx2x_queue_state_change(bp, &q_params);
  7309. if (rc) {
  7310. BNX2X_ERR("Queue(%d) INIT failed\n", fp->index);
  7311. return rc;
  7312. }
  7313. DP(NETIF_MSG_IFUP, "init complete\n");
  7314. /* Now move the Queue to the SETUP state... */
  7315. memset(setup_params, 0, sizeof(*setup_params));
  7316. /* Set QUEUE flags */
  7317. setup_params->flags = bnx2x_get_q_flags(bp, fp, leading);
  7318. /* Set general SETUP parameters */
  7319. bnx2x_pf_q_prep_general(bp, fp, &setup_params->gen_params,
  7320. FIRST_TX_COS_INDEX);
  7321. bnx2x_pf_rx_q_prep(bp, fp, &setup_params->pause_params,
  7322. &setup_params->rxq_params);
  7323. bnx2x_pf_tx_q_prep(bp, fp, &setup_params->txq_params,
  7324. FIRST_TX_COS_INDEX);
  7325. /* Set the command */
  7326. q_params.cmd = BNX2X_Q_CMD_SETUP;
  7327. if (IS_FCOE_FP(fp))
  7328. bp->fcoe_init = true;
  7329. /* Change the state to SETUP */
  7330. rc = bnx2x_queue_state_change(bp, &q_params);
  7331. if (rc) {
  7332. BNX2X_ERR("Queue(%d) SETUP failed\n", fp->index);
  7333. return rc;
  7334. }
  7335. /* loop through the relevant tx-only indices */
  7336. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  7337. tx_index < fp->max_cos;
  7338. tx_index++) {
  7339. /* prepare and send tx-only ramrod*/
  7340. rc = bnx2x_setup_tx_only(bp, fp, &q_params,
  7341. tx_only_params, tx_index, leading);
  7342. if (rc) {
  7343. BNX2X_ERR("Queue(%d.%d) TX_ONLY_SETUP failed\n",
  7344. fp->index, tx_index);
  7345. return rc;
  7346. }
  7347. }
  7348. return rc;
  7349. }
  7350. static int bnx2x_stop_queue(struct bnx2x *bp, int index)
  7351. {
  7352. struct bnx2x_fastpath *fp = &bp->fp[index];
  7353. struct bnx2x_fp_txdata *txdata;
  7354. struct bnx2x_queue_state_params q_params = {NULL};
  7355. int rc, tx_index;
  7356. DP(NETIF_MSG_IFDOWN, "stopping queue %d cid %d\n", index, fp->cid);
  7357. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  7358. /* We want to wait for completion in this context */
  7359. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  7360. /* close tx-only connections */
  7361. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  7362. tx_index < fp->max_cos;
  7363. tx_index++){
  7364. /* ascertain this is a normal queue*/
  7365. txdata = fp->txdata_ptr[tx_index];
  7366. DP(NETIF_MSG_IFDOWN, "stopping tx-only queue %d\n",
  7367. txdata->txq_index);
  7368. /* send halt terminate on tx-only connection */
  7369. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  7370. memset(&q_params.params.terminate, 0,
  7371. sizeof(q_params.params.terminate));
  7372. q_params.params.terminate.cid_index = tx_index;
  7373. rc = bnx2x_queue_state_change(bp, &q_params);
  7374. if (rc)
  7375. return rc;
  7376. /* send halt terminate on tx-only connection */
  7377. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  7378. memset(&q_params.params.cfc_del, 0,
  7379. sizeof(q_params.params.cfc_del));
  7380. q_params.params.cfc_del.cid_index = tx_index;
  7381. rc = bnx2x_queue_state_change(bp, &q_params);
  7382. if (rc)
  7383. return rc;
  7384. }
  7385. /* Stop the primary connection: */
  7386. /* ...halt the connection */
  7387. q_params.cmd = BNX2X_Q_CMD_HALT;
  7388. rc = bnx2x_queue_state_change(bp, &q_params);
  7389. if (rc)
  7390. return rc;
  7391. /* ...terminate the connection */
  7392. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  7393. memset(&q_params.params.terminate, 0,
  7394. sizeof(q_params.params.terminate));
  7395. q_params.params.terminate.cid_index = FIRST_TX_COS_INDEX;
  7396. rc = bnx2x_queue_state_change(bp, &q_params);
  7397. if (rc)
  7398. return rc;
  7399. /* ...delete cfc entry */
  7400. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  7401. memset(&q_params.params.cfc_del, 0,
  7402. sizeof(q_params.params.cfc_del));
  7403. q_params.params.cfc_del.cid_index = FIRST_TX_COS_INDEX;
  7404. return bnx2x_queue_state_change(bp, &q_params);
  7405. }
  7406. static void bnx2x_reset_func(struct bnx2x *bp)
  7407. {
  7408. int port = BP_PORT(bp);
  7409. int func = BP_FUNC(bp);
  7410. int i;
  7411. /* Disable the function in the FW */
  7412. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0);
  7413. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0);
  7414. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0);
  7415. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0);
  7416. /* FP SBs */
  7417. for_each_eth_queue(bp, i) {
  7418. struct bnx2x_fastpath *fp = &bp->fp[i];
  7419. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  7420. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id),
  7421. SB_DISABLED);
  7422. }
  7423. if (CNIC_LOADED(bp))
  7424. /* CNIC SB */
  7425. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  7426. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET
  7427. (bnx2x_cnic_fw_sb_id(bp)), SB_DISABLED);
  7428. /* SP SB */
  7429. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  7430. CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func),
  7431. SB_DISABLED);
  7432. for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++)
  7433. REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func),
  7434. 0);
  7435. /* Configure IGU */
  7436. if (bp->common.int_block == INT_BLOCK_HC) {
  7437. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  7438. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  7439. } else {
  7440. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  7441. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  7442. }
  7443. if (CNIC_LOADED(bp)) {
  7444. /* Disable Timer scan */
  7445. REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 0);
  7446. /*
  7447. * Wait for at least 10ms and up to 2 second for the timers
  7448. * scan to complete
  7449. */
  7450. for (i = 0; i < 200; i++) {
  7451. usleep_range(10000, 20000);
  7452. if (!REG_RD(bp, TM_REG_LIN0_SCAN_ON + port*4))
  7453. break;
  7454. }
  7455. }
  7456. /* Clear ILT */
  7457. bnx2x_clear_func_ilt(bp, func);
  7458. /* Timers workaround bug for E2: if this is vnic-3,
  7459. * we need to set the entire ilt range for this timers.
  7460. */
  7461. if (!CHIP_IS_E1x(bp) && BP_VN(bp) == 3) {
  7462. struct ilt_client_info ilt_cli;
  7463. /* use dummy TM client */
  7464. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  7465. ilt_cli.start = 0;
  7466. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  7467. ilt_cli.client_num = ILT_CLIENT_TM;
  7468. bnx2x_ilt_boundry_init_op(bp, &ilt_cli, 0, INITOP_CLEAR);
  7469. }
  7470. /* this assumes that reset_port() called before reset_func()*/
  7471. if (!CHIP_IS_E1x(bp))
  7472. bnx2x_pf_disable(bp);
  7473. bp->dmae_ready = 0;
  7474. }
  7475. static void bnx2x_reset_port(struct bnx2x *bp)
  7476. {
  7477. int port = BP_PORT(bp);
  7478. u32 val;
  7479. /* Reset physical Link */
  7480. bnx2x__link_reset(bp);
  7481. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  7482. /* Do not rcv packets to BRB */
  7483. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0);
  7484. /* Do not direct rcv packets that are not for MCP to the BRB */
  7485. REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
  7486. NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
  7487. /* Configure AEU */
  7488. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0);
  7489. msleep(100);
  7490. /* Check for BRB port occupancy */
  7491. val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4);
  7492. if (val)
  7493. DP(NETIF_MSG_IFDOWN,
  7494. "BRB1 is not empty %d blocks are occupied\n", val);
  7495. /* TODO: Close Doorbell port? */
  7496. }
  7497. static int bnx2x_reset_hw(struct bnx2x *bp, u32 load_code)
  7498. {
  7499. struct bnx2x_func_state_params func_params = {NULL};
  7500. /* Prepare parameters for function state transitions */
  7501. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  7502. func_params.f_obj = &bp->func_obj;
  7503. func_params.cmd = BNX2X_F_CMD_HW_RESET;
  7504. func_params.params.hw_init.load_phase = load_code;
  7505. return bnx2x_func_state_change(bp, &func_params);
  7506. }
  7507. static int bnx2x_func_stop(struct bnx2x *bp)
  7508. {
  7509. struct bnx2x_func_state_params func_params = {NULL};
  7510. int rc;
  7511. /* Prepare parameters for function state transitions */
  7512. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  7513. func_params.f_obj = &bp->func_obj;
  7514. func_params.cmd = BNX2X_F_CMD_STOP;
  7515. /*
  7516. * Try to stop the function the 'good way'. If fails (in case
  7517. * of a parity error during bnx2x_chip_cleanup()) and we are
  7518. * not in a debug mode, perform a state transaction in order to
  7519. * enable further HW_RESET transaction.
  7520. */
  7521. rc = bnx2x_func_state_change(bp, &func_params);
  7522. if (rc) {
  7523. #ifdef BNX2X_STOP_ON_ERROR
  7524. return rc;
  7525. #else
  7526. BNX2X_ERR("FUNC_STOP ramrod failed. Running a dry transaction\n");
  7527. __set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags);
  7528. return bnx2x_func_state_change(bp, &func_params);
  7529. #endif
  7530. }
  7531. return 0;
  7532. }
  7533. /**
  7534. * bnx2x_send_unload_req - request unload mode from the MCP.
  7535. *
  7536. * @bp: driver handle
  7537. * @unload_mode: requested function's unload mode
  7538. *
  7539. * Return unload mode returned by the MCP: COMMON, PORT or FUNC.
  7540. */
  7541. u32 bnx2x_send_unload_req(struct bnx2x *bp, int unload_mode)
  7542. {
  7543. u32 reset_code = 0;
  7544. int port = BP_PORT(bp);
  7545. /* Select the UNLOAD request mode */
  7546. if (unload_mode == UNLOAD_NORMAL)
  7547. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  7548. else if (bp->flags & NO_WOL_FLAG)
  7549. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP;
  7550. else if (bp->wol) {
  7551. u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
  7552. u8 *mac_addr = bp->dev->dev_addr;
  7553. struct pci_dev *pdev = bp->pdev;
  7554. u32 val;
  7555. u16 pmc;
  7556. /* The mac address is written to entries 1-4 to
  7557. * preserve entry 0 which is used by the PMF
  7558. */
  7559. u8 entry = (BP_VN(bp) + 1)*8;
  7560. val = (mac_addr[0] << 8) | mac_addr[1];
  7561. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val);
  7562. val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
  7563. (mac_addr[4] << 8) | mac_addr[5];
  7564. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val);
  7565. /* Enable the PME and clear the status */
  7566. pci_read_config_word(pdev, pdev->pm_cap + PCI_PM_CTRL, &pmc);
  7567. pmc |= PCI_PM_CTRL_PME_ENABLE | PCI_PM_CTRL_PME_STATUS;
  7568. pci_write_config_word(pdev, pdev->pm_cap + PCI_PM_CTRL, pmc);
  7569. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN;
  7570. } else
  7571. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  7572. /* Send the request to the MCP */
  7573. if (!BP_NOMCP(bp))
  7574. reset_code = bnx2x_fw_command(bp, reset_code, 0);
  7575. else {
  7576. int path = BP_PATH(bp);
  7577. DP(NETIF_MSG_IFDOWN, "NO MCP - load counts[%d] %d, %d, %d\n",
  7578. path, bnx2x_load_count[path][0], bnx2x_load_count[path][1],
  7579. bnx2x_load_count[path][2]);
  7580. bnx2x_load_count[path][0]--;
  7581. bnx2x_load_count[path][1 + port]--;
  7582. DP(NETIF_MSG_IFDOWN, "NO MCP - new load counts[%d] %d, %d, %d\n",
  7583. path, bnx2x_load_count[path][0], bnx2x_load_count[path][1],
  7584. bnx2x_load_count[path][2]);
  7585. if (bnx2x_load_count[path][0] == 0)
  7586. reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON;
  7587. else if (bnx2x_load_count[path][1 + port] == 0)
  7588. reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT;
  7589. else
  7590. reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION;
  7591. }
  7592. return reset_code;
  7593. }
  7594. /**
  7595. * bnx2x_send_unload_done - send UNLOAD_DONE command to the MCP.
  7596. *
  7597. * @bp: driver handle
  7598. * @keep_link: true iff link should be kept up
  7599. */
  7600. void bnx2x_send_unload_done(struct bnx2x *bp, bool keep_link)
  7601. {
  7602. u32 reset_param = keep_link ? DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET : 0;
  7603. /* Report UNLOAD_DONE to MCP */
  7604. if (!BP_NOMCP(bp))
  7605. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, reset_param);
  7606. }
  7607. static int bnx2x_func_wait_started(struct bnx2x *bp)
  7608. {
  7609. int tout = 50;
  7610. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  7611. if (!bp->port.pmf)
  7612. return 0;
  7613. /*
  7614. * (assumption: No Attention from MCP at this stage)
  7615. * PMF probably in the middle of TX disable/enable transaction
  7616. * 1. Sync IRS for default SB
  7617. * 2. Sync SP queue - this guarantees us that attention handling started
  7618. * 3. Wait, that TX disable/enable transaction completes
  7619. *
  7620. * 1+2 guarantee that if DCBx attention was scheduled it already changed
  7621. * pending bit of transaction from STARTED-->TX_STOPPED, if we already
  7622. * received completion for the transaction the state is TX_STOPPED.
  7623. * State will return to STARTED after completion of TX_STOPPED-->STARTED
  7624. * transaction.
  7625. */
  7626. /* make sure default SB ISR is done */
  7627. if (msix)
  7628. synchronize_irq(bp->msix_table[0].vector);
  7629. else
  7630. synchronize_irq(bp->pdev->irq);
  7631. flush_workqueue(bnx2x_wq);
  7632. flush_workqueue(bnx2x_iov_wq);
  7633. while (bnx2x_func_get_state(bp, &bp->func_obj) !=
  7634. BNX2X_F_STATE_STARTED && tout--)
  7635. msleep(20);
  7636. if (bnx2x_func_get_state(bp, &bp->func_obj) !=
  7637. BNX2X_F_STATE_STARTED) {
  7638. #ifdef BNX2X_STOP_ON_ERROR
  7639. BNX2X_ERR("Wrong function state\n");
  7640. return -EBUSY;
  7641. #else
  7642. /*
  7643. * Failed to complete the transaction in a "good way"
  7644. * Force both transactions with CLR bit
  7645. */
  7646. struct bnx2x_func_state_params func_params = {NULL};
  7647. DP(NETIF_MSG_IFDOWN,
  7648. "Hmmm... Unexpected function state! Forcing STARTED-->TX_STOPPED-->STARTED\n");
  7649. func_params.f_obj = &bp->func_obj;
  7650. __set_bit(RAMROD_DRV_CLR_ONLY,
  7651. &func_params.ramrod_flags);
  7652. /* STARTED-->TX_ST0PPED */
  7653. func_params.cmd = BNX2X_F_CMD_TX_STOP;
  7654. bnx2x_func_state_change(bp, &func_params);
  7655. /* TX_ST0PPED-->STARTED */
  7656. func_params.cmd = BNX2X_F_CMD_TX_START;
  7657. return bnx2x_func_state_change(bp, &func_params);
  7658. #endif
  7659. }
  7660. return 0;
  7661. }
  7662. static void bnx2x_disable_ptp(struct bnx2x *bp)
  7663. {
  7664. int port = BP_PORT(bp);
  7665. /* Disable sending PTP packets to host */
  7666. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_TO_HOST :
  7667. NIG_REG_P0_LLH_PTP_TO_HOST, 0x0);
  7668. /* Reset PTP event detection rules */
  7669. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_PARAM_MASK :
  7670. NIG_REG_P0_LLH_PTP_PARAM_MASK, 0x7FF);
  7671. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_RULE_MASK :
  7672. NIG_REG_P0_LLH_PTP_RULE_MASK, 0x3FFF);
  7673. REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_PARAM_MASK :
  7674. NIG_REG_P0_TLLH_PTP_PARAM_MASK, 0x7FF);
  7675. REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_RULE_MASK :
  7676. NIG_REG_P0_TLLH_PTP_RULE_MASK, 0x3FFF);
  7677. /* Disable the PTP feature */
  7678. REG_WR(bp, port ? NIG_REG_P1_PTP_EN :
  7679. NIG_REG_P0_PTP_EN, 0x0);
  7680. }
  7681. /* Called during unload, to stop PTP-related stuff */
  7682. void bnx2x_stop_ptp(struct bnx2x *bp)
  7683. {
  7684. /* Cancel PTP work queue. Should be done after the Tx queues are
  7685. * drained to prevent additional scheduling.
  7686. */
  7687. cancel_work_sync(&bp->ptp_task);
  7688. if (bp->ptp_tx_skb) {
  7689. dev_kfree_skb_any(bp->ptp_tx_skb);
  7690. bp->ptp_tx_skb = NULL;
  7691. }
  7692. /* Disable PTP in HW */
  7693. bnx2x_disable_ptp(bp);
  7694. DP(BNX2X_MSG_PTP, "PTP stop ended successfully\n");
  7695. }
  7696. void bnx2x_chip_cleanup(struct bnx2x *bp, int unload_mode, bool keep_link)
  7697. {
  7698. int port = BP_PORT(bp);
  7699. int i, rc = 0;
  7700. u8 cos;
  7701. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  7702. u32 reset_code;
  7703. /* Wait until tx fastpath tasks complete */
  7704. for_each_tx_queue(bp, i) {
  7705. struct bnx2x_fastpath *fp = &bp->fp[i];
  7706. for_each_cos_in_tx_queue(fp, cos)
  7707. rc = bnx2x_clean_tx_queue(bp, fp->txdata_ptr[cos]);
  7708. #ifdef BNX2X_STOP_ON_ERROR
  7709. if (rc)
  7710. return;
  7711. #endif
  7712. }
  7713. /* Give HW time to discard old tx messages */
  7714. usleep_range(1000, 2000);
  7715. /* Clean all ETH MACs */
  7716. rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_ETH_MAC,
  7717. false);
  7718. if (rc < 0)
  7719. BNX2X_ERR("Failed to delete all ETH macs: %d\n", rc);
  7720. /* Clean up UC list */
  7721. rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_UC_LIST_MAC,
  7722. true);
  7723. if (rc < 0)
  7724. BNX2X_ERR("Failed to schedule DEL commands for UC MACs list: %d\n",
  7725. rc);
  7726. /* Disable LLH */
  7727. if (!CHIP_IS_E1(bp))
  7728. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  7729. /* Set "drop all" (stop Rx).
  7730. * We need to take a netif_addr_lock() here in order to prevent
  7731. * a race between the completion code and this code.
  7732. */
  7733. netif_addr_lock_bh(bp->dev);
  7734. /* Schedule the rx_mode command */
  7735. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  7736. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  7737. else
  7738. bnx2x_set_storm_rx_mode(bp);
  7739. /* Cleanup multicast configuration */
  7740. rparam.mcast_obj = &bp->mcast_obj;
  7741. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  7742. if (rc < 0)
  7743. BNX2X_ERR("Failed to send DEL multicast command: %d\n", rc);
  7744. netif_addr_unlock_bh(bp->dev);
  7745. bnx2x_iov_chip_cleanup(bp);
  7746. /*
  7747. * Send the UNLOAD_REQUEST to the MCP. This will return if
  7748. * this function should perform FUNC, PORT or COMMON HW
  7749. * reset.
  7750. */
  7751. reset_code = bnx2x_send_unload_req(bp, unload_mode);
  7752. /*
  7753. * (assumption: No Attention from MCP at this stage)
  7754. * PMF probably in the middle of TX disable/enable transaction
  7755. */
  7756. rc = bnx2x_func_wait_started(bp);
  7757. if (rc) {
  7758. BNX2X_ERR("bnx2x_func_wait_started failed\n");
  7759. #ifdef BNX2X_STOP_ON_ERROR
  7760. return;
  7761. #endif
  7762. }
  7763. /* Close multi and leading connections
  7764. * Completions for ramrods are collected in a synchronous way
  7765. */
  7766. for_each_eth_queue(bp, i)
  7767. if (bnx2x_stop_queue(bp, i))
  7768. #ifdef BNX2X_STOP_ON_ERROR
  7769. return;
  7770. #else
  7771. goto unload_error;
  7772. #endif
  7773. if (CNIC_LOADED(bp)) {
  7774. for_each_cnic_queue(bp, i)
  7775. if (bnx2x_stop_queue(bp, i))
  7776. #ifdef BNX2X_STOP_ON_ERROR
  7777. return;
  7778. #else
  7779. goto unload_error;
  7780. #endif
  7781. }
  7782. /* If SP settings didn't get completed so far - something
  7783. * very wrong has happen.
  7784. */
  7785. if (!bnx2x_wait_sp_comp(bp, ~0x0UL))
  7786. BNX2X_ERR("Hmmm... Common slow path ramrods got stuck!\n");
  7787. #ifndef BNX2X_STOP_ON_ERROR
  7788. unload_error:
  7789. #endif
  7790. rc = bnx2x_func_stop(bp);
  7791. if (rc) {
  7792. BNX2X_ERR("Function stop failed!\n");
  7793. #ifdef BNX2X_STOP_ON_ERROR
  7794. return;
  7795. #endif
  7796. }
  7797. /* stop_ptp should be after the Tx queues are drained to prevent
  7798. * scheduling to the cancelled PTP work queue. It should also be after
  7799. * function stop ramrod is sent, since as part of this ramrod FW access
  7800. * PTP registers.
  7801. */
  7802. if (bp->flags & PTP_SUPPORTED)
  7803. bnx2x_stop_ptp(bp);
  7804. /* Disable HW interrupts, NAPI */
  7805. bnx2x_netif_stop(bp, 1);
  7806. /* Delete all NAPI objects */
  7807. bnx2x_del_all_napi(bp);
  7808. if (CNIC_LOADED(bp))
  7809. bnx2x_del_all_napi_cnic(bp);
  7810. /* Release IRQs */
  7811. bnx2x_free_irq(bp);
  7812. /* Reset the chip */
  7813. rc = bnx2x_reset_hw(bp, reset_code);
  7814. if (rc)
  7815. BNX2X_ERR("HW_RESET failed\n");
  7816. /* Report UNLOAD_DONE to MCP */
  7817. bnx2x_send_unload_done(bp, keep_link);
  7818. }
  7819. void bnx2x_disable_close_the_gate(struct bnx2x *bp)
  7820. {
  7821. u32 val;
  7822. DP(NETIF_MSG_IFDOWN, "Disabling \"close the gates\"\n");
  7823. if (CHIP_IS_E1(bp)) {
  7824. int port = BP_PORT(bp);
  7825. u32 addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  7826. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  7827. val = REG_RD(bp, addr);
  7828. val &= ~(0x300);
  7829. REG_WR(bp, addr, val);
  7830. } else {
  7831. val = REG_RD(bp, MISC_REG_AEU_GENERAL_MASK);
  7832. val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK |
  7833. MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK);
  7834. REG_WR(bp, MISC_REG_AEU_GENERAL_MASK, val);
  7835. }
  7836. }
  7837. /* Close gates #2, #3 and #4: */
  7838. static void bnx2x_set_234_gates(struct bnx2x *bp, bool close)
  7839. {
  7840. u32 val;
  7841. /* Gates #2 and #4a are closed/opened for "not E1" only */
  7842. if (!CHIP_IS_E1(bp)) {
  7843. /* #4 */
  7844. REG_WR(bp, PXP_REG_HST_DISCARD_DOORBELLS, !!close);
  7845. /* #2 */
  7846. REG_WR(bp, PXP_REG_HST_DISCARD_INTERNAL_WRITES, !!close);
  7847. }
  7848. /* #3 */
  7849. if (CHIP_IS_E1x(bp)) {
  7850. /* Prevent interrupts from HC on both ports */
  7851. val = REG_RD(bp, HC_REG_CONFIG_1);
  7852. REG_WR(bp, HC_REG_CONFIG_1,
  7853. (!close) ? (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1) :
  7854. (val & ~(u32)HC_CONFIG_1_REG_BLOCK_DISABLE_1));
  7855. val = REG_RD(bp, HC_REG_CONFIG_0);
  7856. REG_WR(bp, HC_REG_CONFIG_0,
  7857. (!close) ? (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0) :
  7858. (val & ~(u32)HC_CONFIG_0_REG_BLOCK_DISABLE_0));
  7859. } else {
  7860. /* Prevent incoming interrupts in IGU */
  7861. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  7862. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION,
  7863. (!close) ?
  7864. (val | IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE) :
  7865. (val & ~(u32)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE));
  7866. }
  7867. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "%s gates #2, #3 and #4\n",
  7868. close ? "closing" : "opening");
  7869. mmiowb();
  7870. }
  7871. #define SHARED_MF_CLP_MAGIC 0x80000000 /* `magic' bit */
  7872. static void bnx2x_clp_reset_prep(struct bnx2x *bp, u32 *magic_val)
  7873. {
  7874. /* Do some magic... */
  7875. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  7876. *magic_val = val & SHARED_MF_CLP_MAGIC;
  7877. MF_CFG_WR(bp, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC);
  7878. }
  7879. /**
  7880. * bnx2x_clp_reset_done - restore the value of the `magic' bit.
  7881. *
  7882. * @bp: driver handle
  7883. * @magic_val: old value of the `magic' bit.
  7884. */
  7885. static void bnx2x_clp_reset_done(struct bnx2x *bp, u32 magic_val)
  7886. {
  7887. /* Restore the `magic' bit value... */
  7888. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  7889. MF_CFG_WR(bp, shared_mf_config.clp_mb,
  7890. (val & (~SHARED_MF_CLP_MAGIC)) | magic_val);
  7891. }
  7892. /**
  7893. * bnx2x_reset_mcp_prep - prepare for MCP reset.
  7894. *
  7895. * @bp: driver handle
  7896. * @magic_val: old value of 'magic' bit.
  7897. *
  7898. * Takes care of CLP configurations.
  7899. */
  7900. static void bnx2x_reset_mcp_prep(struct bnx2x *bp, u32 *magic_val)
  7901. {
  7902. u32 shmem;
  7903. u32 validity_offset;
  7904. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "Starting\n");
  7905. /* Set `magic' bit in order to save MF config */
  7906. if (!CHIP_IS_E1(bp))
  7907. bnx2x_clp_reset_prep(bp, magic_val);
  7908. /* Get shmem offset */
  7909. shmem = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  7910. validity_offset =
  7911. offsetof(struct shmem_region, validity_map[BP_PORT(bp)]);
  7912. /* Clear validity map flags */
  7913. if (shmem > 0)
  7914. REG_WR(bp, shmem + validity_offset, 0);
  7915. }
  7916. #define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */
  7917. #define MCP_ONE_TIMEOUT 100 /* 100 ms */
  7918. /**
  7919. * bnx2x_mcp_wait_one - wait for MCP_ONE_TIMEOUT
  7920. *
  7921. * @bp: driver handle
  7922. */
  7923. static void bnx2x_mcp_wait_one(struct bnx2x *bp)
  7924. {
  7925. /* special handling for emulation and FPGA,
  7926. wait 10 times longer */
  7927. if (CHIP_REV_IS_SLOW(bp))
  7928. msleep(MCP_ONE_TIMEOUT*10);
  7929. else
  7930. msleep(MCP_ONE_TIMEOUT);
  7931. }
  7932. /*
  7933. * initializes bp->common.shmem_base and waits for validity signature to appear
  7934. */
  7935. static int bnx2x_init_shmem(struct bnx2x *bp)
  7936. {
  7937. int cnt = 0;
  7938. u32 val = 0;
  7939. do {
  7940. bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  7941. if (bp->common.shmem_base) {
  7942. val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
  7943. if (val & SHR_MEM_VALIDITY_MB)
  7944. return 0;
  7945. }
  7946. bnx2x_mcp_wait_one(bp);
  7947. } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT));
  7948. BNX2X_ERR("BAD MCP validity signature\n");
  7949. return -ENODEV;
  7950. }
  7951. static int bnx2x_reset_mcp_comp(struct bnx2x *bp, u32 magic_val)
  7952. {
  7953. int rc = bnx2x_init_shmem(bp);
  7954. /* Restore the `magic' bit value */
  7955. if (!CHIP_IS_E1(bp))
  7956. bnx2x_clp_reset_done(bp, magic_val);
  7957. return rc;
  7958. }
  7959. static void bnx2x_pxp_prep(struct bnx2x *bp)
  7960. {
  7961. if (!CHIP_IS_E1(bp)) {
  7962. REG_WR(bp, PXP2_REG_RD_START_INIT, 0);
  7963. REG_WR(bp, PXP2_REG_RQ_RBC_DONE, 0);
  7964. mmiowb();
  7965. }
  7966. }
  7967. /*
  7968. * Reset the whole chip except for:
  7969. * - PCIE core
  7970. * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by
  7971. * one reset bit)
  7972. * - IGU
  7973. * - MISC (including AEU)
  7974. * - GRC
  7975. * - RBCN, RBCP
  7976. */
  7977. static void bnx2x_process_kill_chip_reset(struct bnx2x *bp, bool global)
  7978. {
  7979. u32 not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2;
  7980. u32 global_bits2, stay_reset2;
  7981. /*
  7982. * Bits that have to be set in reset_mask2 if we want to reset 'global'
  7983. * (per chip) blocks.
  7984. */
  7985. global_bits2 =
  7986. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU |
  7987. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE;
  7988. /* Don't reset the following blocks.
  7989. * Important: per port blocks (such as EMAC, BMAC, UMAC) can't be
  7990. * reset, as in 4 port device they might still be owned
  7991. * by the MCP (there is only one leader per path).
  7992. */
  7993. not_reset_mask1 =
  7994. MISC_REGISTERS_RESET_REG_1_RST_HC |
  7995. MISC_REGISTERS_RESET_REG_1_RST_PXPV |
  7996. MISC_REGISTERS_RESET_REG_1_RST_PXP;
  7997. not_reset_mask2 =
  7998. MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO |
  7999. MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE |
  8000. MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE |
  8001. MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE |
  8002. MISC_REGISTERS_RESET_REG_2_RST_RBCN |
  8003. MISC_REGISTERS_RESET_REG_2_RST_GRC |
  8004. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE |
  8005. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B |
  8006. MISC_REGISTERS_RESET_REG_2_RST_ATC |
  8007. MISC_REGISTERS_RESET_REG_2_PGLC |
  8008. MISC_REGISTERS_RESET_REG_2_RST_BMAC0 |
  8009. MISC_REGISTERS_RESET_REG_2_RST_BMAC1 |
  8010. MISC_REGISTERS_RESET_REG_2_RST_EMAC0 |
  8011. MISC_REGISTERS_RESET_REG_2_RST_EMAC1 |
  8012. MISC_REGISTERS_RESET_REG_2_UMAC0 |
  8013. MISC_REGISTERS_RESET_REG_2_UMAC1;
  8014. /*
  8015. * Keep the following blocks in reset:
  8016. * - all xxMACs are handled by the bnx2x_link code.
  8017. */
  8018. stay_reset2 =
  8019. MISC_REGISTERS_RESET_REG_2_XMAC |
  8020. MISC_REGISTERS_RESET_REG_2_XMAC_SOFT;
  8021. /* Full reset masks according to the chip */
  8022. reset_mask1 = 0xffffffff;
  8023. if (CHIP_IS_E1(bp))
  8024. reset_mask2 = 0xffff;
  8025. else if (CHIP_IS_E1H(bp))
  8026. reset_mask2 = 0x1ffff;
  8027. else if (CHIP_IS_E2(bp))
  8028. reset_mask2 = 0xfffff;
  8029. else /* CHIP_IS_E3 */
  8030. reset_mask2 = 0x3ffffff;
  8031. /* Don't reset global blocks unless we need to */
  8032. if (!global)
  8033. reset_mask2 &= ~global_bits2;
  8034. /*
  8035. * In case of attention in the QM, we need to reset PXP
  8036. * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM
  8037. * because otherwise QM reset would release 'close the gates' shortly
  8038. * before resetting the PXP, then the PSWRQ would send a write
  8039. * request to PGLUE. Then when PXP is reset, PGLUE would try to
  8040. * read the payload data from PSWWR, but PSWWR would not
  8041. * respond. The write queue in PGLUE would stuck, dmae commands
  8042. * would not return. Therefore it's important to reset the second
  8043. * reset register (containing the
  8044. * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the
  8045. * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM
  8046. * bit).
  8047. */
  8048. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
  8049. reset_mask2 & (~not_reset_mask2));
  8050. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  8051. reset_mask1 & (~not_reset_mask1));
  8052. barrier();
  8053. mmiowb();
  8054. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
  8055. reset_mask2 & (~stay_reset2));
  8056. barrier();
  8057. mmiowb();
  8058. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1);
  8059. mmiowb();
  8060. }
  8061. /**
  8062. * bnx2x_er_poll_igu_vq - poll for pending writes bit.
  8063. * It should get cleared in no more than 1s.
  8064. *
  8065. * @bp: driver handle
  8066. *
  8067. * It should get cleared in no more than 1s. Returns 0 if
  8068. * pending writes bit gets cleared.
  8069. */
  8070. static int bnx2x_er_poll_igu_vq(struct bnx2x *bp)
  8071. {
  8072. u32 cnt = 1000;
  8073. u32 pend_bits = 0;
  8074. do {
  8075. pend_bits = REG_RD(bp, IGU_REG_PENDING_BITS_STATUS);
  8076. if (pend_bits == 0)
  8077. break;
  8078. usleep_range(1000, 2000);
  8079. } while (cnt-- > 0);
  8080. if (cnt <= 0) {
  8081. BNX2X_ERR("Still pending IGU requests pend_bits=%x!\n",
  8082. pend_bits);
  8083. return -EBUSY;
  8084. }
  8085. return 0;
  8086. }
  8087. static int bnx2x_process_kill(struct bnx2x *bp, bool global)
  8088. {
  8089. int cnt = 1000;
  8090. u32 val = 0;
  8091. u32 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2;
  8092. u32 tags_63_32 = 0;
  8093. /* Empty the Tetris buffer, wait for 1s */
  8094. do {
  8095. sr_cnt = REG_RD(bp, PXP2_REG_RD_SR_CNT);
  8096. blk_cnt = REG_RD(bp, PXP2_REG_RD_BLK_CNT);
  8097. port_is_idle_0 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_0);
  8098. port_is_idle_1 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_1);
  8099. pgl_exp_rom2 = REG_RD(bp, PXP2_REG_PGL_EXP_ROM2);
  8100. if (CHIP_IS_E3(bp))
  8101. tags_63_32 = REG_RD(bp, PGLUE_B_REG_TAGS_63_32);
  8102. if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) &&
  8103. ((port_is_idle_0 & 0x1) == 0x1) &&
  8104. ((port_is_idle_1 & 0x1) == 0x1) &&
  8105. (pgl_exp_rom2 == 0xffffffff) &&
  8106. (!CHIP_IS_E3(bp) || (tags_63_32 == 0xffffffff)))
  8107. break;
  8108. usleep_range(1000, 2000);
  8109. } while (cnt-- > 0);
  8110. if (cnt <= 0) {
  8111. BNX2X_ERR("Tetris buffer didn't get empty or there are still outstanding read requests after 1s!\n");
  8112. BNX2X_ERR("sr_cnt=0x%08x, blk_cnt=0x%08x, port_is_idle_0=0x%08x, port_is_idle_1=0x%08x, pgl_exp_rom2=0x%08x\n",
  8113. sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1,
  8114. pgl_exp_rom2);
  8115. return -EAGAIN;
  8116. }
  8117. barrier();
  8118. /* Close gates #2, #3 and #4 */
  8119. bnx2x_set_234_gates(bp, true);
  8120. /* Poll for IGU VQs for 57712 and newer chips */
  8121. if (!CHIP_IS_E1x(bp) && bnx2x_er_poll_igu_vq(bp))
  8122. return -EAGAIN;
  8123. /* TBD: Indicate that "process kill" is in progress to MCP */
  8124. /* Clear "unprepared" bit */
  8125. REG_WR(bp, MISC_REG_UNPREPARED, 0);
  8126. barrier();
  8127. /* Make sure all is written to the chip before the reset */
  8128. mmiowb();
  8129. /* Wait for 1ms to empty GLUE and PCI-E core queues,
  8130. * PSWHST, GRC and PSWRD Tetris buffer.
  8131. */
  8132. usleep_range(1000, 2000);
  8133. /* Prepare to chip reset: */
  8134. /* MCP */
  8135. if (global)
  8136. bnx2x_reset_mcp_prep(bp, &val);
  8137. /* PXP */
  8138. bnx2x_pxp_prep(bp);
  8139. barrier();
  8140. /* reset the chip */
  8141. bnx2x_process_kill_chip_reset(bp, global);
  8142. barrier();
  8143. /* clear errors in PGB */
  8144. if (!CHIP_IS_E1x(bp))
  8145. REG_WR(bp, PGLUE_B_REG_LATCHED_ERRORS_CLR, 0x7f);
  8146. /* Recover after reset: */
  8147. /* MCP */
  8148. if (global && bnx2x_reset_mcp_comp(bp, val))
  8149. return -EAGAIN;
  8150. /* TBD: Add resetting the NO_MCP mode DB here */
  8151. /* Open the gates #2, #3 and #4 */
  8152. bnx2x_set_234_gates(bp, false);
  8153. /* TBD: IGU/AEU preparation bring back the AEU/IGU to a
  8154. * reset state, re-enable attentions. */
  8155. return 0;
  8156. }
  8157. static int bnx2x_leader_reset(struct bnx2x *bp)
  8158. {
  8159. int rc = 0;
  8160. bool global = bnx2x_reset_is_global(bp);
  8161. u32 load_code;
  8162. /* if not going to reset MCP - load "fake" driver to reset HW while
  8163. * driver is owner of the HW
  8164. */
  8165. if (!global && !BP_NOMCP(bp)) {
  8166. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_REQ,
  8167. DRV_MSG_CODE_LOAD_REQ_WITH_LFA);
  8168. if (!load_code) {
  8169. BNX2X_ERR("MCP response failure, aborting\n");
  8170. rc = -EAGAIN;
  8171. goto exit_leader_reset;
  8172. }
  8173. if ((load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) &&
  8174. (load_code != FW_MSG_CODE_DRV_LOAD_COMMON)) {
  8175. BNX2X_ERR("MCP unexpected resp, aborting\n");
  8176. rc = -EAGAIN;
  8177. goto exit_leader_reset2;
  8178. }
  8179. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE, 0);
  8180. if (!load_code) {
  8181. BNX2X_ERR("MCP response failure, aborting\n");
  8182. rc = -EAGAIN;
  8183. goto exit_leader_reset2;
  8184. }
  8185. }
  8186. /* Try to recover after the failure */
  8187. if (bnx2x_process_kill(bp, global)) {
  8188. BNX2X_ERR("Something bad had happen on engine %d! Aii!\n",
  8189. BP_PATH(bp));
  8190. rc = -EAGAIN;
  8191. goto exit_leader_reset2;
  8192. }
  8193. /*
  8194. * Clear RESET_IN_PROGRES and RESET_GLOBAL bits and update the driver
  8195. * state.
  8196. */
  8197. bnx2x_set_reset_done(bp);
  8198. if (global)
  8199. bnx2x_clear_reset_global(bp);
  8200. exit_leader_reset2:
  8201. /* unload "fake driver" if it was loaded */
  8202. if (!global && !BP_NOMCP(bp)) {
  8203. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0);
  8204. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
  8205. }
  8206. exit_leader_reset:
  8207. bp->is_leader = 0;
  8208. bnx2x_release_leader_lock(bp);
  8209. smp_mb();
  8210. return rc;
  8211. }
  8212. static void bnx2x_recovery_failed(struct bnx2x *bp)
  8213. {
  8214. netdev_err(bp->dev, "Recovery has failed. Power cycle is needed.\n");
  8215. /* Disconnect this device */
  8216. netif_device_detach(bp->dev);
  8217. /*
  8218. * Block ifup for all function on this engine until "process kill"
  8219. * or power cycle.
  8220. */
  8221. bnx2x_set_reset_in_progress(bp);
  8222. /* Shut down the power */
  8223. bnx2x_set_power_state(bp, PCI_D3hot);
  8224. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  8225. smp_mb();
  8226. }
  8227. /*
  8228. * Assumption: runs under rtnl lock. This together with the fact
  8229. * that it's called only from bnx2x_sp_rtnl() ensure that it
  8230. * will never be called when netif_running(bp->dev) is false.
  8231. */
  8232. static void bnx2x_parity_recover(struct bnx2x *bp)
  8233. {
  8234. bool global = false;
  8235. u32 error_recovered, error_unrecovered;
  8236. bool is_parity;
  8237. DP(NETIF_MSG_HW, "Handling parity\n");
  8238. while (1) {
  8239. switch (bp->recovery_state) {
  8240. case BNX2X_RECOVERY_INIT:
  8241. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_INIT\n");
  8242. is_parity = bnx2x_chk_parity_attn(bp, &global, false);
  8243. WARN_ON(!is_parity);
  8244. /* Try to get a LEADER_LOCK HW lock */
  8245. if (bnx2x_trylock_leader_lock(bp)) {
  8246. bnx2x_set_reset_in_progress(bp);
  8247. /*
  8248. * Check if there is a global attention and if
  8249. * there was a global attention, set the global
  8250. * reset bit.
  8251. */
  8252. if (global)
  8253. bnx2x_set_reset_global(bp);
  8254. bp->is_leader = 1;
  8255. }
  8256. /* Stop the driver */
  8257. /* If interface has been removed - break */
  8258. if (bnx2x_nic_unload(bp, UNLOAD_RECOVERY, false))
  8259. return;
  8260. bp->recovery_state = BNX2X_RECOVERY_WAIT;
  8261. /* Ensure "is_leader", MCP command sequence and
  8262. * "recovery_state" update values are seen on other
  8263. * CPUs.
  8264. */
  8265. smp_mb();
  8266. break;
  8267. case BNX2X_RECOVERY_WAIT:
  8268. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_WAIT\n");
  8269. if (bp->is_leader) {
  8270. int other_engine = BP_PATH(bp) ? 0 : 1;
  8271. bool other_load_status =
  8272. bnx2x_get_load_status(bp, other_engine);
  8273. bool load_status =
  8274. bnx2x_get_load_status(bp, BP_PATH(bp));
  8275. global = bnx2x_reset_is_global(bp);
  8276. /*
  8277. * In case of a parity in a global block, let
  8278. * the first leader that performs a
  8279. * leader_reset() reset the global blocks in
  8280. * order to clear global attentions. Otherwise
  8281. * the gates will remain closed for that
  8282. * engine.
  8283. */
  8284. if (load_status ||
  8285. (global && other_load_status)) {
  8286. /* Wait until all other functions get
  8287. * down.
  8288. */
  8289. schedule_delayed_work(&bp->sp_rtnl_task,
  8290. HZ/10);
  8291. return;
  8292. } else {
  8293. /* If all other functions got down -
  8294. * try to bring the chip back to
  8295. * normal. In any case it's an exit
  8296. * point for a leader.
  8297. */
  8298. if (bnx2x_leader_reset(bp)) {
  8299. bnx2x_recovery_failed(bp);
  8300. return;
  8301. }
  8302. /* If we are here, means that the
  8303. * leader has succeeded and doesn't
  8304. * want to be a leader any more. Try
  8305. * to continue as a none-leader.
  8306. */
  8307. break;
  8308. }
  8309. } else { /* non-leader */
  8310. if (!bnx2x_reset_is_done(bp, BP_PATH(bp))) {
  8311. /* Try to get a LEADER_LOCK HW lock as
  8312. * long as a former leader may have
  8313. * been unloaded by the user or
  8314. * released a leadership by another
  8315. * reason.
  8316. */
  8317. if (bnx2x_trylock_leader_lock(bp)) {
  8318. /* I'm a leader now! Restart a
  8319. * switch case.
  8320. */
  8321. bp->is_leader = 1;
  8322. break;
  8323. }
  8324. schedule_delayed_work(&bp->sp_rtnl_task,
  8325. HZ/10);
  8326. return;
  8327. } else {
  8328. /*
  8329. * If there was a global attention, wait
  8330. * for it to be cleared.
  8331. */
  8332. if (bnx2x_reset_is_global(bp)) {
  8333. schedule_delayed_work(
  8334. &bp->sp_rtnl_task,
  8335. HZ/10);
  8336. return;
  8337. }
  8338. error_recovered =
  8339. bp->eth_stats.recoverable_error;
  8340. error_unrecovered =
  8341. bp->eth_stats.unrecoverable_error;
  8342. bp->recovery_state =
  8343. BNX2X_RECOVERY_NIC_LOADING;
  8344. if (bnx2x_nic_load(bp, LOAD_NORMAL)) {
  8345. error_unrecovered++;
  8346. netdev_err(bp->dev,
  8347. "Recovery failed. Power cycle needed\n");
  8348. /* Disconnect this device */
  8349. netif_device_detach(bp->dev);
  8350. /* Shut down the power */
  8351. bnx2x_set_power_state(
  8352. bp, PCI_D3hot);
  8353. smp_mb();
  8354. } else {
  8355. bp->recovery_state =
  8356. BNX2X_RECOVERY_DONE;
  8357. error_recovered++;
  8358. smp_mb();
  8359. }
  8360. bp->eth_stats.recoverable_error =
  8361. error_recovered;
  8362. bp->eth_stats.unrecoverable_error =
  8363. error_unrecovered;
  8364. return;
  8365. }
  8366. }
  8367. default:
  8368. return;
  8369. }
  8370. }
  8371. }
  8372. static int bnx2x_close(struct net_device *dev);
  8373. /* bnx2x_nic_unload() flushes the bnx2x_wq, thus reset task is
  8374. * scheduled on a general queue in order to prevent a dead lock.
  8375. */
  8376. static void bnx2x_sp_rtnl_task(struct work_struct *work)
  8377. {
  8378. struct bnx2x *bp = container_of(work, struct bnx2x, sp_rtnl_task.work);
  8379. rtnl_lock();
  8380. if (!netif_running(bp->dev)) {
  8381. rtnl_unlock();
  8382. return;
  8383. }
  8384. if (unlikely(bp->recovery_state != BNX2X_RECOVERY_DONE)) {
  8385. #ifdef BNX2X_STOP_ON_ERROR
  8386. BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
  8387. "you will need to reboot when done\n");
  8388. goto sp_rtnl_not_reset;
  8389. #endif
  8390. /*
  8391. * Clear all pending SP commands as we are going to reset the
  8392. * function anyway.
  8393. */
  8394. bp->sp_rtnl_state = 0;
  8395. smp_mb();
  8396. bnx2x_parity_recover(bp);
  8397. rtnl_unlock();
  8398. return;
  8399. }
  8400. if (test_and_clear_bit(BNX2X_SP_RTNL_TX_TIMEOUT, &bp->sp_rtnl_state)) {
  8401. #ifdef BNX2X_STOP_ON_ERROR
  8402. BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
  8403. "you will need to reboot when done\n");
  8404. goto sp_rtnl_not_reset;
  8405. #endif
  8406. /*
  8407. * Clear all pending SP commands as we are going to reset the
  8408. * function anyway.
  8409. */
  8410. bp->sp_rtnl_state = 0;
  8411. smp_mb();
  8412. bnx2x_nic_unload(bp, UNLOAD_NORMAL, true);
  8413. bnx2x_nic_load(bp, LOAD_NORMAL);
  8414. rtnl_unlock();
  8415. return;
  8416. }
  8417. #ifdef BNX2X_STOP_ON_ERROR
  8418. sp_rtnl_not_reset:
  8419. #endif
  8420. if (test_and_clear_bit(BNX2X_SP_RTNL_SETUP_TC, &bp->sp_rtnl_state))
  8421. bnx2x_setup_tc(bp->dev, bp->dcbx_port_params.ets.num_of_cos);
  8422. if (test_and_clear_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE, &bp->sp_rtnl_state))
  8423. bnx2x_after_function_update(bp);
  8424. /*
  8425. * in case of fan failure we need to reset id if the "stop on error"
  8426. * debug flag is set, since we trying to prevent permanent overheating
  8427. * damage
  8428. */
  8429. if (test_and_clear_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state)) {
  8430. DP(NETIF_MSG_HW, "fan failure detected. Unloading driver\n");
  8431. netif_device_detach(bp->dev);
  8432. bnx2x_close(bp->dev);
  8433. rtnl_unlock();
  8434. return;
  8435. }
  8436. if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_MCAST, &bp->sp_rtnl_state)) {
  8437. DP(BNX2X_MSG_SP,
  8438. "sending set mcast vf pf channel message from rtnl sp-task\n");
  8439. bnx2x_vfpf_set_mcast(bp->dev);
  8440. }
  8441. if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_CHANNEL_DOWN,
  8442. &bp->sp_rtnl_state)){
  8443. if (!test_bit(__LINK_STATE_NOCARRIER, &bp->dev->state)) {
  8444. bnx2x_tx_disable(bp);
  8445. BNX2X_ERR("PF indicated channel is not servicable anymore. This means this VF device is no longer operational\n");
  8446. }
  8447. }
  8448. if (test_and_clear_bit(BNX2X_SP_RTNL_RX_MODE, &bp->sp_rtnl_state)) {
  8449. DP(BNX2X_MSG_SP, "Handling Rx Mode setting\n");
  8450. bnx2x_set_rx_mode_inner(bp);
  8451. }
  8452. if (test_and_clear_bit(BNX2X_SP_RTNL_HYPERVISOR_VLAN,
  8453. &bp->sp_rtnl_state))
  8454. bnx2x_pf_set_vfs_vlan(bp);
  8455. if (test_and_clear_bit(BNX2X_SP_RTNL_TX_STOP, &bp->sp_rtnl_state)) {
  8456. bnx2x_dcbx_stop_hw_tx(bp);
  8457. bnx2x_dcbx_resume_hw_tx(bp);
  8458. }
  8459. if (test_and_clear_bit(BNX2X_SP_RTNL_GET_DRV_VERSION,
  8460. &bp->sp_rtnl_state))
  8461. bnx2x_update_mng_version(bp);
  8462. /* work which needs rtnl lock not-taken (as it takes the lock itself and
  8463. * can be called from other contexts as well)
  8464. */
  8465. rtnl_unlock();
  8466. /* enable SR-IOV if applicable */
  8467. if (IS_SRIOV(bp) && test_and_clear_bit(BNX2X_SP_RTNL_ENABLE_SRIOV,
  8468. &bp->sp_rtnl_state)) {
  8469. bnx2x_disable_sriov(bp);
  8470. bnx2x_enable_sriov(bp);
  8471. }
  8472. }
  8473. static void bnx2x_period_task(struct work_struct *work)
  8474. {
  8475. struct bnx2x *bp = container_of(work, struct bnx2x, period_task.work);
  8476. if (!netif_running(bp->dev))
  8477. goto period_task_exit;
  8478. if (CHIP_REV_IS_SLOW(bp)) {
  8479. BNX2X_ERR("period task called on emulation, ignoring\n");
  8480. goto period_task_exit;
  8481. }
  8482. bnx2x_acquire_phy_lock(bp);
  8483. /*
  8484. * The barrier is needed to ensure the ordering between the writing to
  8485. * the bp->port.pmf in the bnx2x_nic_load() or bnx2x_pmf_update() and
  8486. * the reading here.
  8487. */
  8488. smp_mb();
  8489. if (bp->port.pmf) {
  8490. bnx2x_period_func(&bp->link_params, &bp->link_vars);
  8491. /* Re-queue task in 1 sec */
  8492. queue_delayed_work(bnx2x_wq, &bp->period_task, 1*HZ);
  8493. }
  8494. bnx2x_release_phy_lock(bp);
  8495. period_task_exit:
  8496. return;
  8497. }
  8498. /*
  8499. * Init service functions
  8500. */
  8501. static u32 bnx2x_get_pretend_reg(struct bnx2x *bp)
  8502. {
  8503. u32 base = PXP2_REG_PGL_PRETEND_FUNC_F0;
  8504. u32 stride = PXP2_REG_PGL_PRETEND_FUNC_F1 - base;
  8505. return base + (BP_ABS_FUNC(bp)) * stride;
  8506. }
  8507. static void bnx2x_prev_unload_close_mac(struct bnx2x *bp,
  8508. struct bnx2x_mac_vals *vals)
  8509. {
  8510. u32 val, base_addr, offset, mask, reset_reg;
  8511. bool mac_stopped = false;
  8512. u8 port = BP_PORT(bp);
  8513. /* reset addresses as they also mark which values were changed */
  8514. vals->bmac_addr = 0;
  8515. vals->umac_addr = 0;
  8516. vals->xmac_addr = 0;
  8517. vals->emac_addr = 0;
  8518. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_2);
  8519. if (!CHIP_IS_E3(bp)) {
  8520. val = REG_RD(bp, NIG_REG_BMAC0_REGS_OUT_EN + port * 4);
  8521. mask = MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port;
  8522. if ((mask & reset_reg) && val) {
  8523. u32 wb_data[2];
  8524. BNX2X_DEV_INFO("Disable bmac Rx\n");
  8525. base_addr = BP_PORT(bp) ? NIG_REG_INGRESS_BMAC1_MEM
  8526. : NIG_REG_INGRESS_BMAC0_MEM;
  8527. offset = CHIP_IS_E2(bp) ? BIGMAC2_REGISTER_BMAC_CONTROL
  8528. : BIGMAC_REGISTER_BMAC_CONTROL;
  8529. /*
  8530. * use rd/wr since we cannot use dmae. This is safe
  8531. * since MCP won't access the bus due to the request
  8532. * to unload, and no function on the path can be
  8533. * loaded at this time.
  8534. */
  8535. wb_data[0] = REG_RD(bp, base_addr + offset);
  8536. wb_data[1] = REG_RD(bp, base_addr + offset + 0x4);
  8537. vals->bmac_addr = base_addr + offset;
  8538. vals->bmac_val[0] = wb_data[0];
  8539. vals->bmac_val[1] = wb_data[1];
  8540. wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE;
  8541. REG_WR(bp, vals->bmac_addr, wb_data[0]);
  8542. REG_WR(bp, vals->bmac_addr + 0x4, wb_data[1]);
  8543. }
  8544. BNX2X_DEV_INFO("Disable emac Rx\n");
  8545. vals->emac_addr = NIG_REG_NIG_EMAC0_EN + BP_PORT(bp)*4;
  8546. vals->emac_val = REG_RD(bp, vals->emac_addr);
  8547. REG_WR(bp, vals->emac_addr, 0);
  8548. mac_stopped = true;
  8549. } else {
  8550. if (reset_reg & MISC_REGISTERS_RESET_REG_2_XMAC) {
  8551. BNX2X_DEV_INFO("Disable xmac Rx\n");
  8552. base_addr = BP_PORT(bp) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
  8553. val = REG_RD(bp, base_addr + XMAC_REG_PFC_CTRL_HI);
  8554. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  8555. val & ~(1 << 1));
  8556. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  8557. val | (1 << 1));
  8558. vals->xmac_addr = base_addr + XMAC_REG_CTRL;
  8559. vals->xmac_val = REG_RD(bp, vals->xmac_addr);
  8560. REG_WR(bp, vals->xmac_addr, 0);
  8561. mac_stopped = true;
  8562. }
  8563. mask = MISC_REGISTERS_RESET_REG_2_UMAC0 << port;
  8564. if (mask & reset_reg) {
  8565. BNX2X_DEV_INFO("Disable umac Rx\n");
  8566. base_addr = BP_PORT(bp) ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
  8567. vals->umac_addr = base_addr + UMAC_REG_COMMAND_CONFIG;
  8568. vals->umac_val = REG_RD(bp, vals->umac_addr);
  8569. REG_WR(bp, vals->umac_addr, 0);
  8570. mac_stopped = true;
  8571. }
  8572. }
  8573. if (mac_stopped)
  8574. msleep(20);
  8575. }
  8576. #define BNX2X_PREV_UNDI_PROD_ADDR(p) (BAR_TSTRORM_INTMEM + 0x1508 + ((p) << 4))
  8577. #define BNX2X_PREV_UNDI_PROD_ADDR_H(f) (BAR_TSTRORM_INTMEM + \
  8578. 0x1848 + ((f) << 4))
  8579. #define BNX2X_PREV_UNDI_RCQ(val) ((val) & 0xffff)
  8580. #define BNX2X_PREV_UNDI_BD(val) ((val) >> 16 & 0xffff)
  8581. #define BNX2X_PREV_UNDI_PROD(rcq, bd) ((bd) << 16 | (rcq))
  8582. #define BCM_5710_UNDI_FW_MF_MAJOR (0x07)
  8583. #define BCM_5710_UNDI_FW_MF_MINOR (0x08)
  8584. #define BCM_5710_UNDI_FW_MF_VERS (0x05)
  8585. static bool bnx2x_prev_is_after_undi(struct bnx2x *bp)
  8586. {
  8587. /* UNDI marks its presence in DORQ -
  8588. * it initializes CID offset for normal bell to 0x7
  8589. */
  8590. if (!(REG_RD(bp, MISC_REG_RESET_REG_1) &
  8591. MISC_REGISTERS_RESET_REG_1_RST_DORQ))
  8592. return false;
  8593. if (REG_RD(bp, DORQ_REG_NORM_CID_OFST) == 0x7) {
  8594. BNX2X_DEV_INFO("UNDI previously loaded\n");
  8595. return true;
  8596. }
  8597. return false;
  8598. }
  8599. static void bnx2x_prev_unload_undi_inc(struct bnx2x *bp, u8 inc)
  8600. {
  8601. u16 rcq, bd;
  8602. u32 addr, tmp_reg;
  8603. if (BP_FUNC(bp) < 2)
  8604. addr = BNX2X_PREV_UNDI_PROD_ADDR(BP_PORT(bp));
  8605. else
  8606. addr = BNX2X_PREV_UNDI_PROD_ADDR_H(BP_FUNC(bp) - 2);
  8607. tmp_reg = REG_RD(bp, addr);
  8608. rcq = BNX2X_PREV_UNDI_RCQ(tmp_reg) + inc;
  8609. bd = BNX2X_PREV_UNDI_BD(tmp_reg) + inc;
  8610. tmp_reg = BNX2X_PREV_UNDI_PROD(rcq, bd);
  8611. REG_WR(bp, addr, tmp_reg);
  8612. BNX2X_DEV_INFO("UNDI producer [%d/%d][%08x] rings bd -> 0x%04x, rcq -> 0x%04x\n",
  8613. BP_PORT(bp), BP_FUNC(bp), addr, bd, rcq);
  8614. }
  8615. static int bnx2x_prev_mcp_done(struct bnx2x *bp)
  8616. {
  8617. u32 rc = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE,
  8618. DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET);
  8619. if (!rc) {
  8620. BNX2X_ERR("MCP response failure, aborting\n");
  8621. return -EBUSY;
  8622. }
  8623. return 0;
  8624. }
  8625. static struct bnx2x_prev_path_list *
  8626. bnx2x_prev_path_get_entry(struct bnx2x *bp)
  8627. {
  8628. struct bnx2x_prev_path_list *tmp_list;
  8629. list_for_each_entry(tmp_list, &bnx2x_prev_list, list)
  8630. if (PCI_SLOT(bp->pdev->devfn) == tmp_list->slot &&
  8631. bp->pdev->bus->number == tmp_list->bus &&
  8632. BP_PATH(bp) == tmp_list->path)
  8633. return tmp_list;
  8634. return NULL;
  8635. }
  8636. static int bnx2x_prev_path_mark_eeh(struct bnx2x *bp)
  8637. {
  8638. struct bnx2x_prev_path_list *tmp_list;
  8639. int rc;
  8640. rc = down_interruptible(&bnx2x_prev_sem);
  8641. if (rc) {
  8642. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  8643. return rc;
  8644. }
  8645. tmp_list = bnx2x_prev_path_get_entry(bp);
  8646. if (tmp_list) {
  8647. tmp_list->aer = 1;
  8648. rc = 0;
  8649. } else {
  8650. BNX2X_ERR("path %d: Entry does not exist for eeh; Flow occurs before initial insmod is over ?\n",
  8651. BP_PATH(bp));
  8652. }
  8653. up(&bnx2x_prev_sem);
  8654. return rc;
  8655. }
  8656. static bool bnx2x_prev_is_path_marked(struct bnx2x *bp)
  8657. {
  8658. struct bnx2x_prev_path_list *tmp_list;
  8659. bool rc = false;
  8660. if (down_trylock(&bnx2x_prev_sem))
  8661. return false;
  8662. tmp_list = bnx2x_prev_path_get_entry(bp);
  8663. if (tmp_list) {
  8664. if (tmp_list->aer) {
  8665. DP(NETIF_MSG_HW, "Path %d was marked by AER\n",
  8666. BP_PATH(bp));
  8667. } else {
  8668. rc = true;
  8669. BNX2X_DEV_INFO("Path %d was already cleaned from previous drivers\n",
  8670. BP_PATH(bp));
  8671. }
  8672. }
  8673. up(&bnx2x_prev_sem);
  8674. return rc;
  8675. }
  8676. bool bnx2x_port_after_undi(struct bnx2x *bp)
  8677. {
  8678. struct bnx2x_prev_path_list *entry;
  8679. bool val;
  8680. down(&bnx2x_prev_sem);
  8681. entry = bnx2x_prev_path_get_entry(bp);
  8682. val = !!(entry && (entry->undi & (1 << BP_PORT(bp))));
  8683. up(&bnx2x_prev_sem);
  8684. return val;
  8685. }
  8686. static int bnx2x_prev_mark_path(struct bnx2x *bp, bool after_undi)
  8687. {
  8688. struct bnx2x_prev_path_list *tmp_list;
  8689. int rc;
  8690. rc = down_interruptible(&bnx2x_prev_sem);
  8691. if (rc) {
  8692. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  8693. return rc;
  8694. }
  8695. /* Check whether the entry for this path already exists */
  8696. tmp_list = bnx2x_prev_path_get_entry(bp);
  8697. if (tmp_list) {
  8698. if (!tmp_list->aer) {
  8699. BNX2X_ERR("Re-Marking the path.\n");
  8700. } else {
  8701. DP(NETIF_MSG_HW, "Removing AER indication from path %d\n",
  8702. BP_PATH(bp));
  8703. tmp_list->aer = 0;
  8704. }
  8705. up(&bnx2x_prev_sem);
  8706. return 0;
  8707. }
  8708. up(&bnx2x_prev_sem);
  8709. /* Create an entry for this path and add it */
  8710. tmp_list = kmalloc(sizeof(struct bnx2x_prev_path_list), GFP_KERNEL);
  8711. if (!tmp_list) {
  8712. BNX2X_ERR("Failed to allocate 'bnx2x_prev_path_list'\n");
  8713. return -ENOMEM;
  8714. }
  8715. tmp_list->bus = bp->pdev->bus->number;
  8716. tmp_list->slot = PCI_SLOT(bp->pdev->devfn);
  8717. tmp_list->path = BP_PATH(bp);
  8718. tmp_list->aer = 0;
  8719. tmp_list->undi = after_undi ? (1 << BP_PORT(bp)) : 0;
  8720. rc = down_interruptible(&bnx2x_prev_sem);
  8721. if (rc) {
  8722. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  8723. kfree(tmp_list);
  8724. } else {
  8725. DP(NETIF_MSG_HW, "Marked path [%d] - finished previous unload\n",
  8726. BP_PATH(bp));
  8727. list_add(&tmp_list->list, &bnx2x_prev_list);
  8728. up(&bnx2x_prev_sem);
  8729. }
  8730. return rc;
  8731. }
  8732. static int bnx2x_do_flr(struct bnx2x *bp)
  8733. {
  8734. struct pci_dev *dev = bp->pdev;
  8735. if (CHIP_IS_E1x(bp)) {
  8736. BNX2X_DEV_INFO("FLR not supported in E1/E1H\n");
  8737. return -EINVAL;
  8738. }
  8739. /* only bootcode REQ_BC_VER_4_INITIATE_FLR and onwards support flr */
  8740. if (bp->common.bc_ver < REQ_BC_VER_4_INITIATE_FLR) {
  8741. BNX2X_ERR("FLR not supported by BC_VER: 0x%x\n",
  8742. bp->common.bc_ver);
  8743. return -EINVAL;
  8744. }
  8745. if (!pci_wait_for_pending_transaction(dev))
  8746. dev_err(&dev->dev, "transaction is not cleared; proceeding with reset anyway\n");
  8747. BNX2X_DEV_INFO("Initiating FLR\n");
  8748. bnx2x_fw_command(bp, DRV_MSG_CODE_INITIATE_FLR, 0);
  8749. return 0;
  8750. }
  8751. static int bnx2x_prev_unload_uncommon(struct bnx2x *bp)
  8752. {
  8753. int rc;
  8754. BNX2X_DEV_INFO("Uncommon unload Flow\n");
  8755. /* Test if previous unload process was already finished for this path */
  8756. if (bnx2x_prev_is_path_marked(bp))
  8757. return bnx2x_prev_mcp_done(bp);
  8758. BNX2X_DEV_INFO("Path is unmarked\n");
  8759. /* Cannot proceed with FLR if UNDI is loaded, since FW does not match */
  8760. if (bnx2x_prev_is_after_undi(bp))
  8761. goto out;
  8762. /* If function has FLR capabilities, and existing FW version matches
  8763. * the one required, then FLR will be sufficient to clean any residue
  8764. * left by previous driver
  8765. */
  8766. rc = bnx2x_compare_fw_ver(bp, FW_MSG_CODE_DRV_LOAD_FUNCTION, false);
  8767. if (!rc) {
  8768. /* fw version is good */
  8769. BNX2X_DEV_INFO("FW version matches our own. Attempting FLR\n");
  8770. rc = bnx2x_do_flr(bp);
  8771. }
  8772. if (!rc) {
  8773. /* FLR was performed */
  8774. BNX2X_DEV_INFO("FLR successful\n");
  8775. return 0;
  8776. }
  8777. BNX2X_DEV_INFO("Could not FLR\n");
  8778. out:
  8779. /* Close the MCP request, return failure*/
  8780. rc = bnx2x_prev_mcp_done(bp);
  8781. if (!rc)
  8782. rc = BNX2X_PREV_WAIT_NEEDED;
  8783. return rc;
  8784. }
  8785. static int bnx2x_prev_unload_common(struct bnx2x *bp)
  8786. {
  8787. u32 reset_reg, tmp_reg = 0, rc;
  8788. bool prev_undi = false;
  8789. struct bnx2x_mac_vals mac_vals;
  8790. /* It is possible a previous function received 'common' answer,
  8791. * but hasn't loaded yet, therefore creating a scenario of
  8792. * multiple functions receiving 'common' on the same path.
  8793. */
  8794. BNX2X_DEV_INFO("Common unload Flow\n");
  8795. memset(&mac_vals, 0, sizeof(mac_vals));
  8796. if (bnx2x_prev_is_path_marked(bp))
  8797. return bnx2x_prev_mcp_done(bp);
  8798. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
  8799. /* Reset should be performed after BRB is emptied */
  8800. if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_BRB1) {
  8801. u32 timer_count = 1000;
  8802. /* Close the MAC Rx to prevent BRB from filling up */
  8803. bnx2x_prev_unload_close_mac(bp, &mac_vals);
  8804. /* close LLH filters towards the BRB */
  8805. bnx2x_set_rx_filter(&bp->link_params, 0);
  8806. /* Check if the UNDI driver was previously loaded */
  8807. if (bnx2x_prev_is_after_undi(bp)) {
  8808. prev_undi = true;
  8809. /* clear the UNDI indication */
  8810. REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0);
  8811. /* clear possible idle check errors */
  8812. REG_RD(bp, NIG_REG_NIG_INT_STS_CLR_0);
  8813. }
  8814. if (!CHIP_IS_E1x(bp))
  8815. /* block FW from writing to host */
  8816. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  8817. /* wait until BRB is empty */
  8818. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  8819. while (timer_count) {
  8820. u32 prev_brb = tmp_reg;
  8821. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  8822. if (!tmp_reg)
  8823. break;
  8824. BNX2X_DEV_INFO("BRB still has 0x%08x\n", tmp_reg);
  8825. /* reset timer as long as BRB actually gets emptied */
  8826. if (prev_brb > tmp_reg)
  8827. timer_count = 1000;
  8828. else
  8829. timer_count--;
  8830. /* If UNDI resides in memory, manually increment it */
  8831. if (prev_undi)
  8832. bnx2x_prev_unload_undi_inc(bp, 1);
  8833. udelay(10);
  8834. }
  8835. if (!timer_count)
  8836. BNX2X_ERR("Failed to empty BRB, hope for the best\n");
  8837. }
  8838. /* No packets are in the pipeline, path is ready for reset */
  8839. bnx2x_reset_common(bp);
  8840. if (mac_vals.xmac_addr)
  8841. REG_WR(bp, mac_vals.xmac_addr, mac_vals.xmac_val);
  8842. if (mac_vals.umac_addr)
  8843. REG_WR(bp, mac_vals.umac_addr, mac_vals.umac_val);
  8844. if (mac_vals.emac_addr)
  8845. REG_WR(bp, mac_vals.emac_addr, mac_vals.emac_val);
  8846. if (mac_vals.bmac_addr) {
  8847. REG_WR(bp, mac_vals.bmac_addr, mac_vals.bmac_val[0]);
  8848. REG_WR(bp, mac_vals.bmac_addr + 4, mac_vals.bmac_val[1]);
  8849. }
  8850. rc = bnx2x_prev_mark_path(bp, prev_undi);
  8851. if (rc) {
  8852. bnx2x_prev_mcp_done(bp);
  8853. return rc;
  8854. }
  8855. return bnx2x_prev_mcp_done(bp);
  8856. }
  8857. /* previous driver DMAE transaction may have occurred when pre-boot stage ended
  8858. * and boot began, or when kdump kernel was loaded. Either case would invalidate
  8859. * the addresses of the transaction, resulting in was-error bit set in the pci
  8860. * causing all hw-to-host pcie transactions to timeout. If this happened we want
  8861. * to clear the interrupt which detected this from the pglueb and the was done
  8862. * bit
  8863. */
  8864. static void bnx2x_prev_interrupted_dmae(struct bnx2x *bp)
  8865. {
  8866. if (!CHIP_IS_E1x(bp)) {
  8867. u32 val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS);
  8868. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN) {
  8869. DP(BNX2X_MSG_SP,
  8870. "'was error' bit was found to be set in pglueb upon startup. Clearing\n");
  8871. REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR,
  8872. 1 << BP_FUNC(bp));
  8873. }
  8874. }
  8875. }
  8876. static int bnx2x_prev_unload(struct bnx2x *bp)
  8877. {
  8878. int time_counter = 10;
  8879. u32 rc, fw, hw_lock_reg, hw_lock_val;
  8880. BNX2X_DEV_INFO("Entering Previous Unload Flow\n");
  8881. /* clear hw from errors which may have resulted from an interrupted
  8882. * dmae transaction.
  8883. */
  8884. bnx2x_prev_interrupted_dmae(bp);
  8885. /* Release previously held locks */
  8886. hw_lock_reg = (BP_FUNC(bp) <= 5) ?
  8887. (MISC_REG_DRIVER_CONTROL_1 + BP_FUNC(bp) * 8) :
  8888. (MISC_REG_DRIVER_CONTROL_7 + (BP_FUNC(bp) - 6) * 8);
  8889. hw_lock_val = REG_RD(bp, hw_lock_reg);
  8890. if (hw_lock_val) {
  8891. if (hw_lock_val & HW_LOCK_RESOURCE_NVRAM) {
  8892. BNX2X_DEV_INFO("Release Previously held NVRAM lock\n");
  8893. REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
  8894. (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << BP_PORT(bp)));
  8895. }
  8896. BNX2X_DEV_INFO("Release Previously held hw lock\n");
  8897. REG_WR(bp, hw_lock_reg, 0xffffffff);
  8898. } else
  8899. BNX2X_DEV_INFO("No need to release hw/nvram locks\n");
  8900. if (MCPR_ACCESS_LOCK_LOCK & REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK)) {
  8901. BNX2X_DEV_INFO("Release previously held alr\n");
  8902. bnx2x_release_alr(bp);
  8903. }
  8904. do {
  8905. int aer = 0;
  8906. /* Lock MCP using an unload request */
  8907. fw = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS, 0);
  8908. if (!fw) {
  8909. BNX2X_ERR("MCP response failure, aborting\n");
  8910. rc = -EBUSY;
  8911. break;
  8912. }
  8913. rc = down_interruptible(&bnx2x_prev_sem);
  8914. if (rc) {
  8915. BNX2X_ERR("Cannot check for AER; Received %d when tried to take lock\n",
  8916. rc);
  8917. } else {
  8918. /* If Path is marked by EEH, ignore unload status */
  8919. aer = !!(bnx2x_prev_path_get_entry(bp) &&
  8920. bnx2x_prev_path_get_entry(bp)->aer);
  8921. up(&bnx2x_prev_sem);
  8922. }
  8923. if (fw == FW_MSG_CODE_DRV_UNLOAD_COMMON || aer) {
  8924. rc = bnx2x_prev_unload_common(bp);
  8925. break;
  8926. }
  8927. /* non-common reply from MCP might require looping */
  8928. rc = bnx2x_prev_unload_uncommon(bp);
  8929. if (rc != BNX2X_PREV_WAIT_NEEDED)
  8930. break;
  8931. msleep(20);
  8932. } while (--time_counter);
  8933. if (!time_counter || rc) {
  8934. BNX2X_DEV_INFO("Unloading previous driver did not occur, Possibly due to MF UNDI\n");
  8935. rc = -EPROBE_DEFER;
  8936. }
  8937. /* Mark function if its port was used to boot from SAN */
  8938. if (bnx2x_port_after_undi(bp))
  8939. bp->link_params.feature_config_flags |=
  8940. FEATURE_CONFIG_BOOT_FROM_SAN;
  8941. BNX2X_DEV_INFO("Finished Previous Unload Flow [%d]\n", rc);
  8942. return rc;
  8943. }
  8944. static void bnx2x_get_common_hwinfo(struct bnx2x *bp)
  8945. {
  8946. u32 val, val2, val3, val4, id, boot_mode;
  8947. u16 pmc;
  8948. /* Get the chip revision id and number. */
  8949. /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
  8950. val = REG_RD(bp, MISC_REG_CHIP_NUM);
  8951. id = ((val & 0xffff) << 16);
  8952. val = REG_RD(bp, MISC_REG_CHIP_REV);
  8953. id |= ((val & 0xf) << 12);
  8954. /* Metal is read from PCI regs, but we can't access >=0x400 from
  8955. * the configuration space (so we need to reg_rd)
  8956. */
  8957. val = REG_RD(bp, PCICFG_OFFSET + PCI_ID_VAL3);
  8958. id |= (((val >> 24) & 0xf) << 4);
  8959. val = REG_RD(bp, MISC_REG_BOND_ID);
  8960. id |= (val & 0xf);
  8961. bp->common.chip_id = id;
  8962. /* force 57811 according to MISC register */
  8963. if (REG_RD(bp, MISC_REG_CHIP_TYPE) & MISC_REG_CHIP_TYPE_57811_MASK) {
  8964. if (CHIP_IS_57810(bp))
  8965. bp->common.chip_id = (CHIP_NUM_57811 << 16) |
  8966. (bp->common.chip_id & 0x0000FFFF);
  8967. else if (CHIP_IS_57810_MF(bp))
  8968. bp->common.chip_id = (CHIP_NUM_57811_MF << 16) |
  8969. (bp->common.chip_id & 0x0000FFFF);
  8970. bp->common.chip_id |= 0x1;
  8971. }
  8972. /* Set doorbell size */
  8973. bp->db_size = (1 << BNX2X_DB_SHIFT);
  8974. if (!CHIP_IS_E1x(bp)) {
  8975. val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR);
  8976. if ((val & 1) == 0)
  8977. val = REG_RD(bp, MISC_REG_PORT4MODE_EN);
  8978. else
  8979. val = (val >> 1) & 1;
  8980. BNX2X_DEV_INFO("chip is in %s\n", val ? "4_PORT_MODE" :
  8981. "2_PORT_MODE");
  8982. bp->common.chip_port_mode = val ? CHIP_4_PORT_MODE :
  8983. CHIP_2_PORT_MODE;
  8984. if (CHIP_MODE_IS_4_PORT(bp))
  8985. bp->pfid = (bp->pf_num >> 1); /* 0..3 */
  8986. else
  8987. bp->pfid = (bp->pf_num & 0x6); /* 0, 2, 4, 6 */
  8988. } else {
  8989. bp->common.chip_port_mode = CHIP_PORT_MODE_NONE; /* N/A */
  8990. bp->pfid = bp->pf_num; /* 0..7 */
  8991. }
  8992. BNX2X_DEV_INFO("pf_id: %x", bp->pfid);
  8993. bp->link_params.chip_id = bp->common.chip_id;
  8994. BNX2X_DEV_INFO("chip ID is 0x%x\n", id);
  8995. val = (REG_RD(bp, 0x2874) & 0x55);
  8996. if ((bp->common.chip_id & 0x1) ||
  8997. (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) {
  8998. bp->flags |= ONE_PORT_FLAG;
  8999. BNX2X_DEV_INFO("single port device\n");
  9000. }
  9001. val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4);
  9002. bp->common.flash_size = (BNX2X_NVRAM_1MB_SIZE <<
  9003. (val & MCPR_NVM_CFG4_FLASH_SIZE));
  9004. BNX2X_DEV_INFO("flash_size 0x%x (%d)\n",
  9005. bp->common.flash_size, bp->common.flash_size);
  9006. bnx2x_init_shmem(bp);
  9007. bp->common.shmem2_base = REG_RD(bp, (BP_PATH(bp) ?
  9008. MISC_REG_GENERIC_CR_1 :
  9009. MISC_REG_GENERIC_CR_0));
  9010. bp->link_params.shmem_base = bp->common.shmem_base;
  9011. bp->link_params.shmem2_base = bp->common.shmem2_base;
  9012. if (SHMEM2_RD(bp, size) >
  9013. (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
  9014. bp->link_params.lfa_base =
  9015. REG_RD(bp, bp->common.shmem2_base +
  9016. (u32)offsetof(struct shmem2_region,
  9017. lfa_host_addr[BP_PORT(bp)]));
  9018. else
  9019. bp->link_params.lfa_base = 0;
  9020. BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n",
  9021. bp->common.shmem_base, bp->common.shmem2_base);
  9022. if (!bp->common.shmem_base) {
  9023. BNX2X_DEV_INFO("MCP not active\n");
  9024. bp->flags |= NO_MCP_FLAG;
  9025. return;
  9026. }
  9027. bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config);
  9028. BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config);
  9029. bp->link_params.hw_led_mode = ((bp->common.hw_config &
  9030. SHARED_HW_CFG_LED_MODE_MASK) >>
  9031. SHARED_HW_CFG_LED_MODE_SHIFT);
  9032. bp->link_params.feature_config_flags = 0;
  9033. val = SHMEM_RD(bp, dev_info.shared_feature_config.config);
  9034. if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED)
  9035. bp->link_params.feature_config_flags |=
  9036. FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  9037. else
  9038. bp->link_params.feature_config_flags &=
  9039. ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  9040. val = SHMEM_RD(bp, dev_info.bc_rev) >> 8;
  9041. bp->common.bc_ver = val;
  9042. BNX2X_DEV_INFO("bc_ver %X\n", val);
  9043. if (val < BNX2X_BC_VER) {
  9044. /* for now only warn
  9045. * later we might need to enforce this */
  9046. BNX2X_ERR("This driver needs bc_ver %X but found %X, please upgrade BC\n",
  9047. BNX2X_BC_VER, val);
  9048. }
  9049. bp->link_params.feature_config_flags |=
  9050. (val >= REQ_BC_VER_4_VRFY_FIRST_PHY_OPT_MDL) ?
  9051. FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY : 0;
  9052. bp->link_params.feature_config_flags |=
  9053. (val >= REQ_BC_VER_4_VRFY_SPECIFIC_PHY_OPT_MDL) ?
  9054. FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY : 0;
  9055. bp->link_params.feature_config_flags |=
  9056. (val >= REQ_BC_VER_4_VRFY_AFEX_SUPPORTED) ?
  9057. FEATURE_CONFIG_BC_SUPPORTS_AFEX : 0;
  9058. bp->link_params.feature_config_flags |=
  9059. (val >= REQ_BC_VER_4_SFP_TX_DISABLE_SUPPORTED) ?
  9060. FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED : 0;
  9061. bp->link_params.feature_config_flags |=
  9062. (val >= REQ_BC_VER_4_MT_SUPPORTED) ?
  9063. FEATURE_CONFIG_MT_SUPPORT : 0;
  9064. bp->flags |= (val >= REQ_BC_VER_4_PFC_STATS_SUPPORTED) ?
  9065. BC_SUPPORTS_PFC_STATS : 0;
  9066. bp->flags |= (val >= REQ_BC_VER_4_FCOE_FEATURES) ?
  9067. BC_SUPPORTS_FCOE_FEATURES : 0;
  9068. bp->flags |= (val >= REQ_BC_VER_4_DCBX_ADMIN_MSG_NON_PMF) ?
  9069. BC_SUPPORTS_DCBX_MSG_NON_PMF : 0;
  9070. bp->flags |= (val >= REQ_BC_VER_4_RMMOD_CMD) ?
  9071. BC_SUPPORTS_RMMOD_CMD : 0;
  9072. boot_mode = SHMEM_RD(bp,
  9073. dev_info.port_feature_config[BP_PORT(bp)].mba_config) &
  9074. PORT_FEATURE_MBA_BOOT_AGENT_TYPE_MASK;
  9075. switch (boot_mode) {
  9076. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_PXE:
  9077. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_PXE;
  9078. break;
  9079. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_ISCSIB:
  9080. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_ISCSI;
  9081. break;
  9082. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_FCOE_BOOT:
  9083. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_FCOE;
  9084. break;
  9085. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_NONE:
  9086. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_NONE;
  9087. break;
  9088. }
  9089. pci_read_config_word(bp->pdev, bp->pdev->pm_cap + PCI_PM_PMC, &pmc);
  9090. bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG;
  9091. BNX2X_DEV_INFO("%sWoL capable\n",
  9092. (bp->flags & NO_WOL_FLAG) ? "not " : "");
  9093. val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num);
  9094. val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]);
  9095. val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]);
  9096. val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]);
  9097. dev_info(&bp->pdev->dev, "part number %X-%X-%X-%X\n",
  9098. val, val2, val3, val4);
  9099. }
  9100. #define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID)
  9101. #define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR)
  9102. static int bnx2x_get_igu_cam_info(struct bnx2x *bp)
  9103. {
  9104. int pfid = BP_FUNC(bp);
  9105. int igu_sb_id;
  9106. u32 val;
  9107. u8 fid, igu_sb_cnt = 0;
  9108. bp->igu_base_sb = 0xff;
  9109. if (CHIP_INT_MODE_IS_BC(bp)) {
  9110. int vn = BP_VN(bp);
  9111. igu_sb_cnt = bp->igu_sb_cnt;
  9112. bp->igu_base_sb = (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn) *
  9113. FP_SB_MAX_E1x;
  9114. bp->igu_dsb_id = E1HVN_MAX * FP_SB_MAX_E1x +
  9115. (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn);
  9116. return 0;
  9117. }
  9118. /* IGU in normal mode - read CAM */
  9119. for (igu_sb_id = 0; igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE;
  9120. igu_sb_id++) {
  9121. val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4);
  9122. if (!(val & IGU_REG_MAPPING_MEMORY_VALID))
  9123. continue;
  9124. fid = IGU_FID(val);
  9125. if ((fid & IGU_FID_ENCODE_IS_PF)) {
  9126. if ((fid & IGU_FID_PF_NUM_MASK) != pfid)
  9127. continue;
  9128. if (IGU_VEC(val) == 0)
  9129. /* default status block */
  9130. bp->igu_dsb_id = igu_sb_id;
  9131. else {
  9132. if (bp->igu_base_sb == 0xff)
  9133. bp->igu_base_sb = igu_sb_id;
  9134. igu_sb_cnt++;
  9135. }
  9136. }
  9137. }
  9138. #ifdef CONFIG_PCI_MSI
  9139. /* Due to new PF resource allocation by MFW T7.4 and above, it's
  9140. * optional that number of CAM entries will not be equal to the value
  9141. * advertised in PCI.
  9142. * Driver should use the minimal value of both as the actual status
  9143. * block count
  9144. */
  9145. bp->igu_sb_cnt = min_t(int, bp->igu_sb_cnt, igu_sb_cnt);
  9146. #endif
  9147. if (igu_sb_cnt == 0) {
  9148. BNX2X_ERR("CAM configuration error\n");
  9149. return -EINVAL;
  9150. }
  9151. return 0;
  9152. }
  9153. static void bnx2x_link_settings_supported(struct bnx2x *bp, u32 switch_cfg)
  9154. {
  9155. int cfg_size = 0, idx, port = BP_PORT(bp);
  9156. /* Aggregation of supported attributes of all external phys */
  9157. bp->port.supported[0] = 0;
  9158. bp->port.supported[1] = 0;
  9159. switch (bp->link_params.num_phys) {
  9160. case 1:
  9161. bp->port.supported[0] = bp->link_params.phy[INT_PHY].supported;
  9162. cfg_size = 1;
  9163. break;
  9164. case 2:
  9165. bp->port.supported[0] = bp->link_params.phy[EXT_PHY1].supported;
  9166. cfg_size = 1;
  9167. break;
  9168. case 3:
  9169. if (bp->link_params.multi_phy_config &
  9170. PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
  9171. bp->port.supported[1] =
  9172. bp->link_params.phy[EXT_PHY1].supported;
  9173. bp->port.supported[0] =
  9174. bp->link_params.phy[EXT_PHY2].supported;
  9175. } else {
  9176. bp->port.supported[0] =
  9177. bp->link_params.phy[EXT_PHY1].supported;
  9178. bp->port.supported[1] =
  9179. bp->link_params.phy[EXT_PHY2].supported;
  9180. }
  9181. cfg_size = 2;
  9182. break;
  9183. }
  9184. if (!(bp->port.supported[0] || bp->port.supported[1])) {
  9185. BNX2X_ERR("NVRAM config error. BAD phy config. PHY1 config 0x%x, PHY2 config 0x%x\n",
  9186. SHMEM_RD(bp,
  9187. dev_info.port_hw_config[port].external_phy_config),
  9188. SHMEM_RD(bp,
  9189. dev_info.port_hw_config[port].external_phy_config2));
  9190. return;
  9191. }
  9192. if (CHIP_IS_E3(bp))
  9193. bp->port.phy_addr = REG_RD(bp, MISC_REG_WC0_CTRL_PHY_ADDR);
  9194. else {
  9195. switch (switch_cfg) {
  9196. case SWITCH_CFG_1G:
  9197. bp->port.phy_addr = REG_RD(
  9198. bp, NIG_REG_SERDES0_CTRL_PHY_ADDR + port*0x10);
  9199. break;
  9200. case SWITCH_CFG_10G:
  9201. bp->port.phy_addr = REG_RD(
  9202. bp, NIG_REG_XGXS0_CTRL_PHY_ADDR + port*0x18);
  9203. break;
  9204. default:
  9205. BNX2X_ERR("BAD switch_cfg link_config 0x%x\n",
  9206. bp->port.link_config[0]);
  9207. return;
  9208. }
  9209. }
  9210. BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
  9211. /* mask what we support according to speed_cap_mask per configuration */
  9212. for (idx = 0; idx < cfg_size; idx++) {
  9213. if (!(bp->link_params.speed_cap_mask[idx] &
  9214. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF))
  9215. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Half;
  9216. if (!(bp->link_params.speed_cap_mask[idx] &
  9217. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL))
  9218. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Full;
  9219. if (!(bp->link_params.speed_cap_mask[idx] &
  9220. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF))
  9221. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Half;
  9222. if (!(bp->link_params.speed_cap_mask[idx] &
  9223. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL))
  9224. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Full;
  9225. if (!(bp->link_params.speed_cap_mask[idx] &
  9226. PORT_HW_CFG_SPEED_CAPABILITY_D0_1G))
  9227. bp->port.supported[idx] &= ~(SUPPORTED_1000baseT_Half |
  9228. SUPPORTED_1000baseT_Full);
  9229. if (!(bp->link_params.speed_cap_mask[idx] &
  9230. PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
  9231. bp->port.supported[idx] &= ~SUPPORTED_2500baseX_Full;
  9232. if (!(bp->link_params.speed_cap_mask[idx] &
  9233. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G))
  9234. bp->port.supported[idx] &= ~SUPPORTED_10000baseT_Full;
  9235. if (!(bp->link_params.speed_cap_mask[idx] &
  9236. PORT_HW_CFG_SPEED_CAPABILITY_D0_20G))
  9237. bp->port.supported[idx] &= ~SUPPORTED_20000baseKR2_Full;
  9238. }
  9239. BNX2X_DEV_INFO("supported 0x%x 0x%x\n", bp->port.supported[0],
  9240. bp->port.supported[1]);
  9241. }
  9242. static void bnx2x_link_settings_requested(struct bnx2x *bp)
  9243. {
  9244. u32 link_config, idx, cfg_size = 0;
  9245. bp->port.advertising[0] = 0;
  9246. bp->port.advertising[1] = 0;
  9247. switch (bp->link_params.num_phys) {
  9248. case 1:
  9249. case 2:
  9250. cfg_size = 1;
  9251. break;
  9252. case 3:
  9253. cfg_size = 2;
  9254. break;
  9255. }
  9256. for (idx = 0; idx < cfg_size; idx++) {
  9257. bp->link_params.req_duplex[idx] = DUPLEX_FULL;
  9258. link_config = bp->port.link_config[idx];
  9259. switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
  9260. case PORT_FEATURE_LINK_SPEED_AUTO:
  9261. if (bp->port.supported[idx] & SUPPORTED_Autoneg) {
  9262. bp->link_params.req_line_speed[idx] =
  9263. SPEED_AUTO_NEG;
  9264. bp->port.advertising[idx] |=
  9265. bp->port.supported[idx];
  9266. if (bp->link_params.phy[EXT_PHY1].type ==
  9267. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
  9268. bp->port.advertising[idx] |=
  9269. (SUPPORTED_100baseT_Half |
  9270. SUPPORTED_100baseT_Full);
  9271. } else {
  9272. /* force 10G, no AN */
  9273. bp->link_params.req_line_speed[idx] =
  9274. SPEED_10000;
  9275. bp->port.advertising[idx] |=
  9276. (ADVERTISED_10000baseT_Full |
  9277. ADVERTISED_FIBRE);
  9278. continue;
  9279. }
  9280. break;
  9281. case PORT_FEATURE_LINK_SPEED_10M_FULL:
  9282. if (bp->port.supported[idx] & SUPPORTED_10baseT_Full) {
  9283. bp->link_params.req_line_speed[idx] =
  9284. SPEED_10;
  9285. bp->port.advertising[idx] |=
  9286. (ADVERTISED_10baseT_Full |
  9287. ADVERTISED_TP);
  9288. } else {
  9289. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9290. link_config,
  9291. bp->link_params.speed_cap_mask[idx]);
  9292. return;
  9293. }
  9294. break;
  9295. case PORT_FEATURE_LINK_SPEED_10M_HALF:
  9296. if (bp->port.supported[idx] & SUPPORTED_10baseT_Half) {
  9297. bp->link_params.req_line_speed[idx] =
  9298. SPEED_10;
  9299. bp->link_params.req_duplex[idx] =
  9300. DUPLEX_HALF;
  9301. bp->port.advertising[idx] |=
  9302. (ADVERTISED_10baseT_Half |
  9303. ADVERTISED_TP);
  9304. } else {
  9305. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9306. link_config,
  9307. bp->link_params.speed_cap_mask[idx]);
  9308. return;
  9309. }
  9310. break;
  9311. case PORT_FEATURE_LINK_SPEED_100M_FULL:
  9312. if (bp->port.supported[idx] &
  9313. SUPPORTED_100baseT_Full) {
  9314. bp->link_params.req_line_speed[idx] =
  9315. SPEED_100;
  9316. bp->port.advertising[idx] |=
  9317. (ADVERTISED_100baseT_Full |
  9318. ADVERTISED_TP);
  9319. } else {
  9320. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9321. link_config,
  9322. bp->link_params.speed_cap_mask[idx]);
  9323. return;
  9324. }
  9325. break;
  9326. case PORT_FEATURE_LINK_SPEED_100M_HALF:
  9327. if (bp->port.supported[idx] &
  9328. SUPPORTED_100baseT_Half) {
  9329. bp->link_params.req_line_speed[idx] =
  9330. SPEED_100;
  9331. bp->link_params.req_duplex[idx] =
  9332. DUPLEX_HALF;
  9333. bp->port.advertising[idx] |=
  9334. (ADVERTISED_100baseT_Half |
  9335. ADVERTISED_TP);
  9336. } else {
  9337. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9338. link_config,
  9339. bp->link_params.speed_cap_mask[idx]);
  9340. return;
  9341. }
  9342. break;
  9343. case PORT_FEATURE_LINK_SPEED_1G:
  9344. if (bp->port.supported[idx] &
  9345. SUPPORTED_1000baseT_Full) {
  9346. bp->link_params.req_line_speed[idx] =
  9347. SPEED_1000;
  9348. bp->port.advertising[idx] |=
  9349. (ADVERTISED_1000baseT_Full |
  9350. ADVERTISED_TP);
  9351. } else {
  9352. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9353. link_config,
  9354. bp->link_params.speed_cap_mask[idx]);
  9355. return;
  9356. }
  9357. break;
  9358. case PORT_FEATURE_LINK_SPEED_2_5G:
  9359. if (bp->port.supported[idx] &
  9360. SUPPORTED_2500baseX_Full) {
  9361. bp->link_params.req_line_speed[idx] =
  9362. SPEED_2500;
  9363. bp->port.advertising[idx] |=
  9364. (ADVERTISED_2500baseX_Full |
  9365. ADVERTISED_TP);
  9366. } else {
  9367. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9368. link_config,
  9369. bp->link_params.speed_cap_mask[idx]);
  9370. return;
  9371. }
  9372. break;
  9373. case PORT_FEATURE_LINK_SPEED_10G_CX4:
  9374. if (bp->port.supported[idx] &
  9375. SUPPORTED_10000baseT_Full) {
  9376. bp->link_params.req_line_speed[idx] =
  9377. SPEED_10000;
  9378. bp->port.advertising[idx] |=
  9379. (ADVERTISED_10000baseT_Full |
  9380. ADVERTISED_FIBRE);
  9381. } else {
  9382. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9383. link_config,
  9384. bp->link_params.speed_cap_mask[idx]);
  9385. return;
  9386. }
  9387. break;
  9388. case PORT_FEATURE_LINK_SPEED_20G:
  9389. bp->link_params.req_line_speed[idx] = SPEED_20000;
  9390. break;
  9391. default:
  9392. BNX2X_ERR("NVRAM config error. BAD link speed link_config 0x%x\n",
  9393. link_config);
  9394. bp->link_params.req_line_speed[idx] =
  9395. SPEED_AUTO_NEG;
  9396. bp->port.advertising[idx] =
  9397. bp->port.supported[idx];
  9398. break;
  9399. }
  9400. bp->link_params.req_flow_ctrl[idx] = (link_config &
  9401. PORT_FEATURE_FLOW_CONTROL_MASK);
  9402. if (bp->link_params.req_flow_ctrl[idx] ==
  9403. BNX2X_FLOW_CTRL_AUTO) {
  9404. if (!(bp->port.supported[idx] & SUPPORTED_Autoneg))
  9405. bp->link_params.req_flow_ctrl[idx] =
  9406. BNX2X_FLOW_CTRL_NONE;
  9407. else
  9408. bnx2x_set_requested_fc(bp);
  9409. }
  9410. BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl 0x%x advertising 0x%x\n",
  9411. bp->link_params.req_line_speed[idx],
  9412. bp->link_params.req_duplex[idx],
  9413. bp->link_params.req_flow_ctrl[idx],
  9414. bp->port.advertising[idx]);
  9415. }
  9416. }
  9417. static void bnx2x_set_mac_buf(u8 *mac_buf, u32 mac_lo, u16 mac_hi)
  9418. {
  9419. __be16 mac_hi_be = cpu_to_be16(mac_hi);
  9420. __be32 mac_lo_be = cpu_to_be32(mac_lo);
  9421. memcpy(mac_buf, &mac_hi_be, sizeof(mac_hi_be));
  9422. memcpy(mac_buf + sizeof(mac_hi_be), &mac_lo_be, sizeof(mac_lo_be));
  9423. }
  9424. static void bnx2x_get_port_hwinfo(struct bnx2x *bp)
  9425. {
  9426. int port = BP_PORT(bp);
  9427. u32 config;
  9428. u32 ext_phy_type, ext_phy_config, eee_mode;
  9429. bp->link_params.bp = bp;
  9430. bp->link_params.port = port;
  9431. bp->link_params.lane_config =
  9432. SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config);
  9433. bp->link_params.speed_cap_mask[0] =
  9434. SHMEM_RD(bp,
  9435. dev_info.port_hw_config[port].speed_capability_mask) &
  9436. PORT_HW_CFG_SPEED_CAPABILITY_D0_MASK;
  9437. bp->link_params.speed_cap_mask[1] =
  9438. SHMEM_RD(bp,
  9439. dev_info.port_hw_config[port].speed_capability_mask2) &
  9440. PORT_HW_CFG_SPEED_CAPABILITY_D0_MASK;
  9441. bp->port.link_config[0] =
  9442. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config);
  9443. bp->port.link_config[1] =
  9444. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config2);
  9445. bp->link_params.multi_phy_config =
  9446. SHMEM_RD(bp, dev_info.port_hw_config[port].multi_phy_config);
  9447. /* If the device is capable of WoL, set the default state according
  9448. * to the HW
  9449. */
  9450. config = SHMEM_RD(bp, dev_info.port_feature_config[port].config);
  9451. bp->wol = (!(bp->flags & NO_WOL_FLAG) &&
  9452. (config & PORT_FEATURE_WOL_ENABLED));
  9453. if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) ==
  9454. PORT_FEAT_CFG_STORAGE_PERSONALITY_FCOE && !IS_MF(bp))
  9455. bp->flags |= NO_ISCSI_FLAG;
  9456. if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) ==
  9457. PORT_FEAT_CFG_STORAGE_PERSONALITY_ISCSI && !(IS_MF(bp)))
  9458. bp->flags |= NO_FCOE_FLAG;
  9459. BNX2X_DEV_INFO("lane_config 0x%08x speed_cap_mask0 0x%08x link_config0 0x%08x\n",
  9460. bp->link_params.lane_config,
  9461. bp->link_params.speed_cap_mask[0],
  9462. bp->port.link_config[0]);
  9463. bp->link_params.switch_cfg = (bp->port.link_config[0] &
  9464. PORT_FEATURE_CONNECTED_SWITCH_MASK);
  9465. bnx2x_phy_probe(&bp->link_params);
  9466. bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg);
  9467. bnx2x_link_settings_requested(bp);
  9468. /*
  9469. * If connected directly, work with the internal PHY, otherwise, work
  9470. * with the external PHY
  9471. */
  9472. ext_phy_config =
  9473. SHMEM_RD(bp,
  9474. dev_info.port_hw_config[port].external_phy_config);
  9475. ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
  9476. if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
  9477. bp->mdio.prtad = bp->port.phy_addr;
  9478. else if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) &&
  9479. (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
  9480. bp->mdio.prtad =
  9481. XGXS_EXT_PHY_ADDR(ext_phy_config);
  9482. /* Configure link feature according to nvram value */
  9483. eee_mode = (((SHMEM_RD(bp, dev_info.
  9484. port_feature_config[port].eee_power_mode)) &
  9485. PORT_FEAT_CFG_EEE_POWER_MODE_MASK) >>
  9486. PORT_FEAT_CFG_EEE_POWER_MODE_SHIFT);
  9487. if (eee_mode != PORT_FEAT_CFG_EEE_POWER_MODE_DISABLED) {
  9488. bp->link_params.eee_mode = EEE_MODE_ADV_LPI |
  9489. EEE_MODE_ENABLE_LPI |
  9490. EEE_MODE_OUTPUT_TIME;
  9491. } else {
  9492. bp->link_params.eee_mode = 0;
  9493. }
  9494. }
  9495. void bnx2x_get_iscsi_info(struct bnx2x *bp)
  9496. {
  9497. u32 no_flags = NO_ISCSI_FLAG;
  9498. int port = BP_PORT(bp);
  9499. u32 max_iscsi_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  9500. drv_lic_key[port].max_iscsi_conn);
  9501. if (!CNIC_SUPPORT(bp)) {
  9502. bp->flags |= no_flags;
  9503. return;
  9504. }
  9505. /* Get the number of maximum allowed iSCSI connections */
  9506. bp->cnic_eth_dev.max_iscsi_conn =
  9507. (max_iscsi_conn & BNX2X_MAX_ISCSI_INIT_CONN_MASK) >>
  9508. BNX2X_MAX_ISCSI_INIT_CONN_SHIFT;
  9509. BNX2X_DEV_INFO("max_iscsi_conn 0x%x\n",
  9510. bp->cnic_eth_dev.max_iscsi_conn);
  9511. /*
  9512. * If maximum allowed number of connections is zero -
  9513. * disable the feature.
  9514. */
  9515. if (!bp->cnic_eth_dev.max_iscsi_conn)
  9516. bp->flags |= no_flags;
  9517. }
  9518. static void bnx2x_get_ext_wwn_info(struct bnx2x *bp, int func)
  9519. {
  9520. /* Port info */
  9521. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  9522. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_upper);
  9523. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  9524. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_lower);
  9525. /* Node info */
  9526. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  9527. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_upper);
  9528. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  9529. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_lower);
  9530. }
  9531. static int bnx2x_shared_fcoe_funcs(struct bnx2x *bp)
  9532. {
  9533. u8 count = 0;
  9534. if (IS_MF(bp)) {
  9535. u8 fid;
  9536. /* iterate over absolute function ids for this path: */
  9537. for (fid = BP_PATH(bp); fid < E2_FUNC_MAX * 2; fid += 2) {
  9538. if (IS_MF_SD(bp)) {
  9539. u32 cfg = MF_CFG_RD(bp,
  9540. func_mf_config[fid].config);
  9541. if (!(cfg & FUNC_MF_CFG_FUNC_HIDE) &&
  9542. ((cfg & FUNC_MF_CFG_PROTOCOL_MASK) ==
  9543. FUNC_MF_CFG_PROTOCOL_FCOE))
  9544. count++;
  9545. } else {
  9546. u32 cfg = MF_CFG_RD(bp,
  9547. func_ext_config[fid].
  9548. func_cfg);
  9549. if ((cfg & MACP_FUNC_CFG_FLAGS_ENABLED) &&
  9550. (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD))
  9551. count++;
  9552. }
  9553. }
  9554. } else { /* SF */
  9555. int port, port_cnt = CHIP_MODE_IS_4_PORT(bp) ? 2 : 1;
  9556. for (port = 0; port < port_cnt; port++) {
  9557. u32 lic = SHMEM_RD(bp,
  9558. drv_lic_key[port].max_fcoe_conn) ^
  9559. FW_ENCODE_32BIT_PATTERN;
  9560. if (lic)
  9561. count++;
  9562. }
  9563. }
  9564. return count;
  9565. }
  9566. static void bnx2x_get_fcoe_info(struct bnx2x *bp)
  9567. {
  9568. int port = BP_PORT(bp);
  9569. int func = BP_ABS_FUNC(bp);
  9570. u32 max_fcoe_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  9571. drv_lic_key[port].max_fcoe_conn);
  9572. u8 num_fcoe_func = bnx2x_shared_fcoe_funcs(bp);
  9573. if (!CNIC_SUPPORT(bp)) {
  9574. bp->flags |= NO_FCOE_FLAG;
  9575. return;
  9576. }
  9577. /* Get the number of maximum allowed FCoE connections */
  9578. bp->cnic_eth_dev.max_fcoe_conn =
  9579. (max_fcoe_conn & BNX2X_MAX_FCOE_INIT_CONN_MASK) >>
  9580. BNX2X_MAX_FCOE_INIT_CONN_SHIFT;
  9581. /* Calculate the number of maximum allowed FCoE tasks */
  9582. bp->cnic_eth_dev.max_fcoe_exchanges = MAX_NUM_FCOE_TASKS_PER_ENGINE;
  9583. /* check if FCoE resources must be shared between different functions */
  9584. if (num_fcoe_func)
  9585. bp->cnic_eth_dev.max_fcoe_exchanges /= num_fcoe_func;
  9586. /* Read the WWN: */
  9587. if (!IS_MF(bp)) {
  9588. /* Port info */
  9589. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  9590. SHMEM_RD(bp,
  9591. dev_info.port_hw_config[port].
  9592. fcoe_wwn_port_name_upper);
  9593. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  9594. SHMEM_RD(bp,
  9595. dev_info.port_hw_config[port].
  9596. fcoe_wwn_port_name_lower);
  9597. /* Node info */
  9598. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  9599. SHMEM_RD(bp,
  9600. dev_info.port_hw_config[port].
  9601. fcoe_wwn_node_name_upper);
  9602. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  9603. SHMEM_RD(bp,
  9604. dev_info.port_hw_config[port].
  9605. fcoe_wwn_node_name_lower);
  9606. } else if (!IS_MF_SD(bp)) {
  9607. /* Read the WWN info only if the FCoE feature is enabled for
  9608. * this function.
  9609. */
  9610. if (BNX2X_HAS_MF_EXT_PROTOCOL_FCOE(bp))
  9611. bnx2x_get_ext_wwn_info(bp, func);
  9612. } else {
  9613. if (BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp) && !CHIP_IS_E1x(bp))
  9614. bnx2x_get_ext_wwn_info(bp, func);
  9615. }
  9616. BNX2X_DEV_INFO("max_fcoe_conn 0x%x\n", bp->cnic_eth_dev.max_fcoe_conn);
  9617. /*
  9618. * If maximum allowed number of connections is zero -
  9619. * disable the feature.
  9620. */
  9621. if (!bp->cnic_eth_dev.max_fcoe_conn)
  9622. bp->flags |= NO_FCOE_FLAG;
  9623. }
  9624. static void bnx2x_get_cnic_info(struct bnx2x *bp)
  9625. {
  9626. /*
  9627. * iSCSI may be dynamically disabled but reading
  9628. * info here we will decrease memory usage by driver
  9629. * if the feature is disabled for good
  9630. */
  9631. bnx2x_get_iscsi_info(bp);
  9632. bnx2x_get_fcoe_info(bp);
  9633. }
  9634. static void bnx2x_get_cnic_mac_hwinfo(struct bnx2x *bp)
  9635. {
  9636. u32 val, val2;
  9637. int func = BP_ABS_FUNC(bp);
  9638. int port = BP_PORT(bp);
  9639. u8 *iscsi_mac = bp->cnic_eth_dev.iscsi_mac;
  9640. u8 *fip_mac = bp->fip_mac;
  9641. if (IS_MF(bp)) {
  9642. /* iSCSI and FCoE NPAR MACs: if there is no either iSCSI or
  9643. * FCoE MAC then the appropriate feature should be disabled.
  9644. * In non SD mode features configuration comes from struct
  9645. * func_ext_config.
  9646. */
  9647. if (!IS_MF_SD(bp)) {
  9648. u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
  9649. if (cfg & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) {
  9650. val2 = MF_CFG_RD(bp, func_ext_config[func].
  9651. iscsi_mac_addr_upper);
  9652. val = MF_CFG_RD(bp, func_ext_config[func].
  9653. iscsi_mac_addr_lower);
  9654. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  9655. BNX2X_DEV_INFO
  9656. ("Read iSCSI MAC: %pM\n", iscsi_mac);
  9657. } else {
  9658. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  9659. }
  9660. if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) {
  9661. val2 = MF_CFG_RD(bp, func_ext_config[func].
  9662. fcoe_mac_addr_upper);
  9663. val = MF_CFG_RD(bp, func_ext_config[func].
  9664. fcoe_mac_addr_lower);
  9665. bnx2x_set_mac_buf(fip_mac, val, val2);
  9666. BNX2X_DEV_INFO
  9667. ("Read FCoE L2 MAC: %pM\n", fip_mac);
  9668. } else {
  9669. bp->flags |= NO_FCOE_FLAG;
  9670. }
  9671. bp->mf_ext_config = cfg;
  9672. } else { /* SD MODE */
  9673. if (BNX2X_IS_MF_SD_PROTOCOL_ISCSI(bp)) {
  9674. /* use primary mac as iscsi mac */
  9675. memcpy(iscsi_mac, bp->dev->dev_addr, ETH_ALEN);
  9676. BNX2X_DEV_INFO("SD ISCSI MODE\n");
  9677. BNX2X_DEV_INFO
  9678. ("Read iSCSI MAC: %pM\n", iscsi_mac);
  9679. } else if (BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp)) {
  9680. /* use primary mac as fip mac */
  9681. memcpy(fip_mac, bp->dev->dev_addr, ETH_ALEN);
  9682. BNX2X_DEV_INFO("SD FCoE MODE\n");
  9683. BNX2X_DEV_INFO
  9684. ("Read FIP MAC: %pM\n", fip_mac);
  9685. }
  9686. }
  9687. /* If this is a storage-only interface, use SAN mac as
  9688. * primary MAC. Notice that for SD this is already the case,
  9689. * as the SAN mac was copied from the primary MAC.
  9690. */
  9691. if (IS_MF_FCOE_AFEX(bp))
  9692. memcpy(bp->dev->dev_addr, fip_mac, ETH_ALEN);
  9693. } else {
  9694. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9695. iscsi_mac_upper);
  9696. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9697. iscsi_mac_lower);
  9698. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  9699. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9700. fcoe_fip_mac_upper);
  9701. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9702. fcoe_fip_mac_lower);
  9703. bnx2x_set_mac_buf(fip_mac, val, val2);
  9704. }
  9705. /* Disable iSCSI OOO if MAC configuration is invalid. */
  9706. if (!is_valid_ether_addr(iscsi_mac)) {
  9707. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  9708. memset(iscsi_mac, 0, ETH_ALEN);
  9709. }
  9710. /* Disable FCoE if MAC configuration is invalid. */
  9711. if (!is_valid_ether_addr(fip_mac)) {
  9712. bp->flags |= NO_FCOE_FLAG;
  9713. memset(bp->fip_mac, 0, ETH_ALEN);
  9714. }
  9715. }
  9716. static void bnx2x_get_mac_hwinfo(struct bnx2x *bp)
  9717. {
  9718. u32 val, val2;
  9719. int func = BP_ABS_FUNC(bp);
  9720. int port = BP_PORT(bp);
  9721. /* Zero primary MAC configuration */
  9722. memset(bp->dev->dev_addr, 0, ETH_ALEN);
  9723. if (BP_NOMCP(bp)) {
  9724. BNX2X_ERROR("warning: random MAC workaround active\n");
  9725. eth_hw_addr_random(bp->dev);
  9726. } else if (IS_MF(bp)) {
  9727. val2 = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
  9728. val = MF_CFG_RD(bp, func_mf_config[func].mac_lower);
  9729. if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) &&
  9730. (val != FUNC_MF_CFG_LOWERMAC_DEFAULT))
  9731. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  9732. if (CNIC_SUPPORT(bp))
  9733. bnx2x_get_cnic_mac_hwinfo(bp);
  9734. } else {
  9735. /* in SF read MACs from port configuration */
  9736. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
  9737. val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
  9738. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  9739. if (CNIC_SUPPORT(bp))
  9740. bnx2x_get_cnic_mac_hwinfo(bp);
  9741. }
  9742. if (!BP_NOMCP(bp)) {
  9743. /* Read physical port identifier from shmem */
  9744. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
  9745. val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
  9746. bnx2x_set_mac_buf(bp->phys_port_id, val, val2);
  9747. bp->flags |= HAS_PHYS_PORT_ID;
  9748. }
  9749. memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN);
  9750. if (!is_valid_ether_addr(bp->dev->dev_addr))
  9751. dev_err(&bp->pdev->dev,
  9752. "bad Ethernet MAC address configuration: %pM\n"
  9753. "change it manually before bringing up the appropriate network interface\n",
  9754. bp->dev->dev_addr);
  9755. }
  9756. static bool bnx2x_get_dropless_info(struct bnx2x *bp)
  9757. {
  9758. int tmp;
  9759. u32 cfg;
  9760. if (IS_VF(bp))
  9761. return 0;
  9762. if (IS_MF(bp) && !CHIP_IS_E1x(bp)) {
  9763. /* Take function: tmp = func */
  9764. tmp = BP_ABS_FUNC(bp);
  9765. cfg = MF_CFG_RD(bp, func_ext_config[tmp].func_cfg);
  9766. cfg = !!(cfg & MACP_FUNC_CFG_PAUSE_ON_HOST_RING);
  9767. } else {
  9768. /* Take port: tmp = port */
  9769. tmp = BP_PORT(bp);
  9770. cfg = SHMEM_RD(bp,
  9771. dev_info.port_hw_config[tmp].generic_features);
  9772. cfg = !!(cfg & PORT_HW_CFG_PAUSE_ON_HOST_RING_ENABLED);
  9773. }
  9774. return cfg;
  9775. }
  9776. static void validate_set_si_mode(struct bnx2x *bp)
  9777. {
  9778. u8 func = BP_ABS_FUNC(bp);
  9779. u32 val;
  9780. val = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
  9781. /* check for legal mac (upper bytes) */
  9782. if (val != 0xffff) {
  9783. bp->mf_mode = MULTI_FUNCTION_SI;
  9784. bp->mf_config[BP_VN(bp)] =
  9785. MF_CFG_RD(bp, func_mf_config[func].config);
  9786. } else
  9787. BNX2X_DEV_INFO("illegal MAC address for SI\n");
  9788. }
  9789. static int bnx2x_get_hwinfo(struct bnx2x *bp)
  9790. {
  9791. int /*abs*/func = BP_ABS_FUNC(bp);
  9792. int vn;
  9793. u32 val = 0, val2 = 0;
  9794. int rc = 0;
  9795. bnx2x_get_common_hwinfo(bp);
  9796. /*
  9797. * initialize IGU parameters
  9798. */
  9799. if (CHIP_IS_E1x(bp)) {
  9800. bp->common.int_block = INT_BLOCK_HC;
  9801. bp->igu_dsb_id = DEF_SB_IGU_ID;
  9802. bp->igu_base_sb = 0;
  9803. } else {
  9804. bp->common.int_block = INT_BLOCK_IGU;
  9805. /* do not allow device reset during IGU info processing */
  9806. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  9807. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  9808. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  9809. int tout = 5000;
  9810. BNX2X_DEV_INFO("FORCING Normal Mode\n");
  9811. val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN);
  9812. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION, val);
  9813. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x7f);
  9814. while (tout && REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  9815. tout--;
  9816. usleep_range(1000, 2000);
  9817. }
  9818. if (REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  9819. dev_err(&bp->pdev->dev,
  9820. "FORCING Normal Mode failed!!!\n");
  9821. bnx2x_release_hw_lock(bp,
  9822. HW_LOCK_RESOURCE_RESET);
  9823. return -EPERM;
  9824. }
  9825. }
  9826. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  9827. BNX2X_DEV_INFO("IGU Backward Compatible Mode\n");
  9828. bp->common.int_block |= INT_BLOCK_MODE_BW_COMP;
  9829. } else
  9830. BNX2X_DEV_INFO("IGU Normal Mode\n");
  9831. rc = bnx2x_get_igu_cam_info(bp);
  9832. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  9833. if (rc)
  9834. return rc;
  9835. }
  9836. /*
  9837. * set base FW non-default (fast path) status block id, this value is
  9838. * used to initialize the fw_sb_id saved on the fp/queue structure to
  9839. * determine the id used by the FW.
  9840. */
  9841. if (CHIP_IS_E1x(bp))
  9842. bp->base_fw_ndsb = BP_PORT(bp) * FP_SB_MAX_E1x + BP_L_ID(bp);
  9843. else /*
  9844. * 57712 - we currently use one FW SB per IGU SB (Rx and Tx of
  9845. * the same queue are indicated on the same IGU SB). So we prefer
  9846. * FW and IGU SBs to be the same value.
  9847. */
  9848. bp->base_fw_ndsb = bp->igu_base_sb;
  9849. BNX2X_DEV_INFO("igu_dsb_id %d igu_base_sb %d igu_sb_cnt %d\n"
  9850. "base_fw_ndsb %d\n", bp->igu_dsb_id, bp->igu_base_sb,
  9851. bp->igu_sb_cnt, bp->base_fw_ndsb);
  9852. /*
  9853. * Initialize MF configuration
  9854. */
  9855. bp->mf_ov = 0;
  9856. bp->mf_mode = 0;
  9857. bp->mf_sub_mode = 0;
  9858. vn = BP_VN(bp);
  9859. if (!CHIP_IS_E1(bp) && !BP_NOMCP(bp)) {
  9860. BNX2X_DEV_INFO("shmem2base 0x%x, size %d, mfcfg offset %d\n",
  9861. bp->common.shmem2_base, SHMEM2_RD(bp, size),
  9862. (u32)offsetof(struct shmem2_region, mf_cfg_addr));
  9863. if (SHMEM2_HAS(bp, mf_cfg_addr))
  9864. bp->common.mf_cfg_base = SHMEM2_RD(bp, mf_cfg_addr);
  9865. else
  9866. bp->common.mf_cfg_base = bp->common.shmem_base +
  9867. offsetof(struct shmem_region, func_mb) +
  9868. E1H_FUNC_MAX * sizeof(struct drv_func_mb);
  9869. /*
  9870. * get mf configuration:
  9871. * 1. Existence of MF configuration
  9872. * 2. MAC address must be legal (check only upper bytes)
  9873. * for Switch-Independent mode;
  9874. * OVLAN must be legal for Switch-Dependent mode
  9875. * 3. SF_MODE configures specific MF mode
  9876. */
  9877. if (bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  9878. /* get mf configuration */
  9879. val = SHMEM_RD(bp,
  9880. dev_info.shared_feature_config.config);
  9881. val &= SHARED_FEAT_CFG_FORCE_SF_MODE_MASK;
  9882. switch (val) {
  9883. case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT:
  9884. validate_set_si_mode(bp);
  9885. break;
  9886. case SHARED_FEAT_CFG_FORCE_SF_MODE_AFEX_MODE:
  9887. if ((!CHIP_IS_E1x(bp)) &&
  9888. (MF_CFG_RD(bp, func_mf_config[func].
  9889. mac_upper) != 0xffff) &&
  9890. (SHMEM2_HAS(bp,
  9891. afex_driver_support))) {
  9892. bp->mf_mode = MULTI_FUNCTION_AFEX;
  9893. bp->mf_config[vn] = MF_CFG_RD(bp,
  9894. func_mf_config[func].config);
  9895. } else {
  9896. BNX2X_DEV_INFO("can not configure afex mode\n");
  9897. }
  9898. break;
  9899. case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED:
  9900. /* get OV configuration */
  9901. val = MF_CFG_RD(bp,
  9902. func_mf_config[FUNC_0].e1hov_tag);
  9903. val &= FUNC_MF_CFG_E1HOV_TAG_MASK;
  9904. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  9905. bp->mf_mode = MULTI_FUNCTION_SD;
  9906. bp->mf_config[vn] = MF_CFG_RD(bp,
  9907. func_mf_config[func].config);
  9908. } else
  9909. BNX2X_DEV_INFO("illegal OV for SD\n");
  9910. break;
  9911. case SHARED_FEAT_CFG_FORCE_SF_MODE_UFP_MODE:
  9912. bp->mf_mode = MULTI_FUNCTION_SD;
  9913. bp->mf_sub_mode = SUB_MF_MODE_UFP;
  9914. bp->mf_config[vn] =
  9915. MF_CFG_RD(bp,
  9916. func_mf_config[func].config);
  9917. break;
  9918. case SHARED_FEAT_CFG_FORCE_SF_MODE_FORCED_SF:
  9919. bp->mf_config[vn] = 0;
  9920. break;
  9921. case SHARED_FEAT_CFG_FORCE_SF_MODE_EXTENDED_MODE:
  9922. val2 = SHMEM_RD(bp,
  9923. dev_info.shared_hw_config.config_3);
  9924. val2 &= SHARED_HW_CFG_EXTENDED_MF_MODE_MASK;
  9925. switch (val2) {
  9926. case SHARED_HW_CFG_EXTENDED_MF_MODE_NPAR1_DOT_5:
  9927. validate_set_si_mode(bp);
  9928. bp->mf_sub_mode =
  9929. SUB_MF_MODE_NPAR1_DOT_5;
  9930. break;
  9931. default:
  9932. /* Unknown configuration */
  9933. bp->mf_config[vn] = 0;
  9934. BNX2X_DEV_INFO("unknown extended MF mode 0x%x\n",
  9935. val);
  9936. }
  9937. break;
  9938. default:
  9939. /* Unknown configuration: reset mf_config */
  9940. bp->mf_config[vn] = 0;
  9941. BNX2X_DEV_INFO("unknown MF mode 0x%x\n", val);
  9942. }
  9943. }
  9944. BNX2X_DEV_INFO("%s function mode\n",
  9945. IS_MF(bp) ? "multi" : "single");
  9946. switch (bp->mf_mode) {
  9947. case MULTI_FUNCTION_SD:
  9948. val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  9949. FUNC_MF_CFG_E1HOV_TAG_MASK;
  9950. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  9951. bp->mf_ov = val;
  9952. bp->path_has_ovlan = true;
  9953. BNX2X_DEV_INFO("MF OV for func %d is %d (0x%04x)\n",
  9954. func, bp->mf_ov, bp->mf_ov);
  9955. } else if (bp->mf_sub_mode == SUB_MF_MODE_UFP) {
  9956. dev_err(&bp->pdev->dev,
  9957. "Unexpected - no valid MF OV for func %d in UFP mode\n",
  9958. func);
  9959. bp->path_has_ovlan = true;
  9960. } else {
  9961. dev_err(&bp->pdev->dev,
  9962. "No valid MF OV for func %d, aborting\n",
  9963. func);
  9964. return -EPERM;
  9965. }
  9966. break;
  9967. case MULTI_FUNCTION_AFEX:
  9968. BNX2X_DEV_INFO("func %d is in MF afex mode\n", func);
  9969. break;
  9970. case MULTI_FUNCTION_SI:
  9971. BNX2X_DEV_INFO("func %d is in MF switch-independent mode\n",
  9972. func);
  9973. break;
  9974. default:
  9975. if (vn) {
  9976. dev_err(&bp->pdev->dev,
  9977. "VN %d is in a single function mode, aborting\n",
  9978. vn);
  9979. return -EPERM;
  9980. }
  9981. break;
  9982. }
  9983. /* check if other port on the path needs ovlan:
  9984. * Since MF configuration is shared between ports
  9985. * Possible mixed modes are only
  9986. * {SF, SI} {SF, SD} {SD, SF} {SI, SF}
  9987. */
  9988. if (CHIP_MODE_IS_4_PORT(bp) &&
  9989. !bp->path_has_ovlan &&
  9990. !IS_MF(bp) &&
  9991. bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  9992. u8 other_port = !BP_PORT(bp);
  9993. u8 other_func = BP_PATH(bp) + 2*other_port;
  9994. val = MF_CFG_RD(bp,
  9995. func_mf_config[other_func].e1hov_tag);
  9996. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT)
  9997. bp->path_has_ovlan = true;
  9998. }
  9999. }
  10000. /* adjust igu_sb_cnt to MF for E1H */
  10001. if (CHIP_IS_E1H(bp) && IS_MF(bp))
  10002. bp->igu_sb_cnt = min_t(u8, bp->igu_sb_cnt, E1H_MAX_MF_SB_COUNT);
  10003. /* port info */
  10004. bnx2x_get_port_hwinfo(bp);
  10005. /* Get MAC addresses */
  10006. bnx2x_get_mac_hwinfo(bp);
  10007. bnx2x_get_cnic_info(bp);
  10008. return rc;
  10009. }
  10010. static void bnx2x_read_fwinfo(struct bnx2x *bp)
  10011. {
  10012. int cnt, i, block_end, rodi;
  10013. char vpd_start[BNX2X_VPD_LEN+1];
  10014. char str_id_reg[VENDOR_ID_LEN+1];
  10015. char str_id_cap[VENDOR_ID_LEN+1];
  10016. char *vpd_data;
  10017. char *vpd_extended_data = NULL;
  10018. u8 len;
  10019. cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_start);
  10020. memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
  10021. if (cnt < BNX2X_VPD_LEN)
  10022. goto out_not_found;
  10023. /* VPD RO tag should be first tag after identifier string, hence
  10024. * we should be able to find it in first BNX2X_VPD_LEN chars
  10025. */
  10026. i = pci_vpd_find_tag(vpd_start, 0, BNX2X_VPD_LEN,
  10027. PCI_VPD_LRDT_RO_DATA);
  10028. if (i < 0)
  10029. goto out_not_found;
  10030. block_end = i + PCI_VPD_LRDT_TAG_SIZE +
  10031. pci_vpd_lrdt_size(&vpd_start[i]);
  10032. i += PCI_VPD_LRDT_TAG_SIZE;
  10033. if (block_end > BNX2X_VPD_LEN) {
  10034. vpd_extended_data = kmalloc(block_end, GFP_KERNEL);
  10035. if (vpd_extended_data == NULL)
  10036. goto out_not_found;
  10037. /* read rest of vpd image into vpd_extended_data */
  10038. memcpy(vpd_extended_data, vpd_start, BNX2X_VPD_LEN);
  10039. cnt = pci_read_vpd(bp->pdev, BNX2X_VPD_LEN,
  10040. block_end - BNX2X_VPD_LEN,
  10041. vpd_extended_data + BNX2X_VPD_LEN);
  10042. if (cnt < (block_end - BNX2X_VPD_LEN))
  10043. goto out_not_found;
  10044. vpd_data = vpd_extended_data;
  10045. } else
  10046. vpd_data = vpd_start;
  10047. /* now vpd_data holds full vpd content in both cases */
  10048. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  10049. PCI_VPD_RO_KEYWORD_MFR_ID);
  10050. if (rodi < 0)
  10051. goto out_not_found;
  10052. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  10053. if (len != VENDOR_ID_LEN)
  10054. goto out_not_found;
  10055. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  10056. /* vendor specific info */
  10057. snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL);
  10058. snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL);
  10059. if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) ||
  10060. !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) {
  10061. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  10062. PCI_VPD_RO_KEYWORD_VENDOR0);
  10063. if (rodi >= 0) {
  10064. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  10065. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  10066. if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) {
  10067. memcpy(bp->fw_ver, &vpd_data[rodi], len);
  10068. bp->fw_ver[len] = ' ';
  10069. }
  10070. }
  10071. kfree(vpd_extended_data);
  10072. return;
  10073. }
  10074. out_not_found:
  10075. kfree(vpd_extended_data);
  10076. return;
  10077. }
  10078. static void bnx2x_set_modes_bitmap(struct bnx2x *bp)
  10079. {
  10080. u32 flags = 0;
  10081. if (CHIP_REV_IS_FPGA(bp))
  10082. SET_FLAGS(flags, MODE_FPGA);
  10083. else if (CHIP_REV_IS_EMUL(bp))
  10084. SET_FLAGS(flags, MODE_EMUL);
  10085. else
  10086. SET_FLAGS(flags, MODE_ASIC);
  10087. if (CHIP_MODE_IS_4_PORT(bp))
  10088. SET_FLAGS(flags, MODE_PORT4);
  10089. else
  10090. SET_FLAGS(flags, MODE_PORT2);
  10091. if (CHIP_IS_E2(bp))
  10092. SET_FLAGS(flags, MODE_E2);
  10093. else if (CHIP_IS_E3(bp)) {
  10094. SET_FLAGS(flags, MODE_E3);
  10095. if (CHIP_REV(bp) == CHIP_REV_Ax)
  10096. SET_FLAGS(flags, MODE_E3_A0);
  10097. else /*if (CHIP_REV(bp) == CHIP_REV_Bx)*/
  10098. SET_FLAGS(flags, MODE_E3_B0 | MODE_COS3);
  10099. }
  10100. if (IS_MF(bp)) {
  10101. SET_FLAGS(flags, MODE_MF);
  10102. switch (bp->mf_mode) {
  10103. case MULTI_FUNCTION_SD:
  10104. SET_FLAGS(flags, MODE_MF_SD);
  10105. break;
  10106. case MULTI_FUNCTION_SI:
  10107. SET_FLAGS(flags, MODE_MF_SI);
  10108. break;
  10109. case MULTI_FUNCTION_AFEX:
  10110. SET_FLAGS(flags, MODE_MF_AFEX);
  10111. break;
  10112. }
  10113. } else
  10114. SET_FLAGS(flags, MODE_SF);
  10115. #if defined(__LITTLE_ENDIAN)
  10116. SET_FLAGS(flags, MODE_LITTLE_ENDIAN);
  10117. #else /*(__BIG_ENDIAN)*/
  10118. SET_FLAGS(flags, MODE_BIG_ENDIAN);
  10119. #endif
  10120. INIT_MODE_FLAGS(bp) = flags;
  10121. }
  10122. static int bnx2x_init_bp(struct bnx2x *bp)
  10123. {
  10124. int func;
  10125. int rc;
  10126. mutex_init(&bp->port.phy_mutex);
  10127. mutex_init(&bp->fw_mb_mutex);
  10128. mutex_init(&bp->drv_info_mutex);
  10129. bp->drv_info_mng_owner = false;
  10130. spin_lock_init(&bp->stats_lock);
  10131. sema_init(&bp->stats_sema, 1);
  10132. INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task);
  10133. INIT_DELAYED_WORK(&bp->sp_rtnl_task, bnx2x_sp_rtnl_task);
  10134. INIT_DELAYED_WORK(&bp->period_task, bnx2x_period_task);
  10135. INIT_DELAYED_WORK(&bp->iov_task, bnx2x_iov_task);
  10136. if (IS_PF(bp)) {
  10137. rc = bnx2x_get_hwinfo(bp);
  10138. if (rc)
  10139. return rc;
  10140. } else {
  10141. eth_zero_addr(bp->dev->dev_addr);
  10142. }
  10143. bnx2x_set_modes_bitmap(bp);
  10144. rc = bnx2x_alloc_mem_bp(bp);
  10145. if (rc)
  10146. return rc;
  10147. bnx2x_read_fwinfo(bp);
  10148. func = BP_FUNC(bp);
  10149. /* need to reset chip if undi was active */
  10150. if (IS_PF(bp) && !BP_NOMCP(bp)) {
  10151. /* init fw_seq */
  10152. bp->fw_seq =
  10153. SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
  10154. DRV_MSG_SEQ_NUMBER_MASK;
  10155. BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
  10156. rc = bnx2x_prev_unload(bp);
  10157. if (rc) {
  10158. bnx2x_free_mem_bp(bp);
  10159. return rc;
  10160. }
  10161. }
  10162. if (CHIP_REV_IS_FPGA(bp))
  10163. dev_err(&bp->pdev->dev, "FPGA detected\n");
  10164. if (BP_NOMCP(bp) && (func == 0))
  10165. dev_err(&bp->pdev->dev, "MCP disabled, must load devices in order!\n");
  10166. bp->disable_tpa = disable_tpa;
  10167. bp->disable_tpa |= !!IS_MF_STORAGE_ONLY(bp);
  10168. /* Reduce memory usage in kdump environment by disabling TPA */
  10169. bp->disable_tpa |= is_kdump_kernel();
  10170. /* Set TPA flags */
  10171. if (bp->disable_tpa) {
  10172. bp->flags &= ~(TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
  10173. bp->dev->features &= ~NETIF_F_LRO;
  10174. } else {
  10175. bp->flags |= (TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
  10176. bp->dev->features |= NETIF_F_LRO;
  10177. }
  10178. if (CHIP_IS_E1(bp))
  10179. bp->dropless_fc = 0;
  10180. else
  10181. bp->dropless_fc = dropless_fc | bnx2x_get_dropless_info(bp);
  10182. bp->mrrs = mrrs;
  10183. bp->tx_ring_size = IS_MF_STORAGE_ONLY(bp) ? 0 : MAX_TX_AVAIL;
  10184. if (IS_VF(bp))
  10185. bp->rx_ring_size = MAX_RX_AVAIL;
  10186. /* make sure that the numbers are in the right granularity */
  10187. bp->tx_ticks = (50 / BNX2X_BTR) * BNX2X_BTR;
  10188. bp->rx_ticks = (25 / BNX2X_BTR) * BNX2X_BTR;
  10189. bp->current_interval = CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ;
  10190. init_timer(&bp->timer);
  10191. bp->timer.expires = jiffies + bp->current_interval;
  10192. bp->timer.data = (unsigned long) bp;
  10193. bp->timer.function = bnx2x_timer;
  10194. if (SHMEM2_HAS(bp, dcbx_lldp_params_offset) &&
  10195. SHMEM2_HAS(bp, dcbx_lldp_dcbx_stat_offset) &&
  10196. SHMEM2_RD(bp, dcbx_lldp_params_offset) &&
  10197. SHMEM2_RD(bp, dcbx_lldp_dcbx_stat_offset)) {
  10198. bnx2x_dcbx_set_state(bp, true, BNX2X_DCBX_ENABLED_ON_NEG_ON);
  10199. bnx2x_dcbx_init_params(bp);
  10200. } else {
  10201. bnx2x_dcbx_set_state(bp, false, BNX2X_DCBX_ENABLED_OFF);
  10202. }
  10203. if (CHIP_IS_E1x(bp))
  10204. bp->cnic_base_cl_id = FP_SB_MAX_E1x;
  10205. else
  10206. bp->cnic_base_cl_id = FP_SB_MAX_E2;
  10207. /* multiple tx priority */
  10208. if (IS_VF(bp))
  10209. bp->max_cos = 1;
  10210. else if (CHIP_IS_E1x(bp))
  10211. bp->max_cos = BNX2X_MULTI_TX_COS_E1X;
  10212. else if (CHIP_IS_E2(bp) || CHIP_IS_E3A0(bp))
  10213. bp->max_cos = BNX2X_MULTI_TX_COS_E2_E3A0;
  10214. else if (CHIP_IS_E3B0(bp))
  10215. bp->max_cos = BNX2X_MULTI_TX_COS_E3B0;
  10216. else
  10217. BNX2X_ERR("unknown chip %x revision %x\n",
  10218. CHIP_NUM(bp), CHIP_REV(bp));
  10219. BNX2X_DEV_INFO("set bp->max_cos to %d\n", bp->max_cos);
  10220. /* We need at least one default status block for slow-path events,
  10221. * second status block for the L2 queue, and a third status block for
  10222. * CNIC if supported.
  10223. */
  10224. if (IS_VF(bp))
  10225. bp->min_msix_vec_cnt = 1;
  10226. else if (CNIC_SUPPORT(bp))
  10227. bp->min_msix_vec_cnt = 3;
  10228. else /* PF w/o cnic */
  10229. bp->min_msix_vec_cnt = 2;
  10230. BNX2X_DEV_INFO("bp->min_msix_vec_cnt %d", bp->min_msix_vec_cnt);
  10231. bp->dump_preset_idx = 1;
  10232. if (CHIP_IS_E3B0(bp))
  10233. bp->flags |= PTP_SUPPORTED;
  10234. return rc;
  10235. }
  10236. /****************************************************************************
  10237. * General service functions
  10238. ****************************************************************************/
  10239. /*
  10240. * net_device service functions
  10241. */
  10242. /* called with rtnl_lock */
  10243. static int bnx2x_open(struct net_device *dev)
  10244. {
  10245. struct bnx2x *bp = netdev_priv(dev);
  10246. int rc;
  10247. bp->stats_init = true;
  10248. netif_carrier_off(dev);
  10249. bnx2x_set_power_state(bp, PCI_D0);
  10250. /* If parity had happen during the unload, then attentions
  10251. * and/or RECOVERY_IN_PROGRES may still be set. In this case we
  10252. * want the first function loaded on the current engine to
  10253. * complete the recovery.
  10254. * Parity recovery is only relevant for PF driver.
  10255. */
  10256. if (IS_PF(bp)) {
  10257. int other_engine = BP_PATH(bp) ? 0 : 1;
  10258. bool other_load_status, load_status;
  10259. bool global = false;
  10260. other_load_status = bnx2x_get_load_status(bp, other_engine);
  10261. load_status = bnx2x_get_load_status(bp, BP_PATH(bp));
  10262. if (!bnx2x_reset_is_done(bp, BP_PATH(bp)) ||
  10263. bnx2x_chk_parity_attn(bp, &global, true)) {
  10264. do {
  10265. /* If there are attentions and they are in a
  10266. * global blocks, set the GLOBAL_RESET bit
  10267. * regardless whether it will be this function
  10268. * that will complete the recovery or not.
  10269. */
  10270. if (global)
  10271. bnx2x_set_reset_global(bp);
  10272. /* Only the first function on the current
  10273. * engine should try to recover in open. In case
  10274. * of attentions in global blocks only the first
  10275. * in the chip should try to recover.
  10276. */
  10277. if ((!load_status &&
  10278. (!global || !other_load_status)) &&
  10279. bnx2x_trylock_leader_lock(bp) &&
  10280. !bnx2x_leader_reset(bp)) {
  10281. netdev_info(bp->dev,
  10282. "Recovered in open\n");
  10283. break;
  10284. }
  10285. /* recovery has failed... */
  10286. bnx2x_set_power_state(bp, PCI_D3hot);
  10287. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  10288. BNX2X_ERR("Recovery flow hasn't been properly completed yet. Try again later.\n"
  10289. "If you still see this message after a few retries then power cycle is required.\n");
  10290. return -EAGAIN;
  10291. } while (0);
  10292. }
  10293. }
  10294. bp->recovery_state = BNX2X_RECOVERY_DONE;
  10295. rc = bnx2x_nic_load(bp, LOAD_OPEN);
  10296. if (rc)
  10297. return rc;
  10298. return 0;
  10299. }
  10300. /* called with rtnl_lock */
  10301. static int bnx2x_close(struct net_device *dev)
  10302. {
  10303. struct bnx2x *bp = netdev_priv(dev);
  10304. /* Unload the driver, release IRQs */
  10305. bnx2x_nic_unload(bp, UNLOAD_CLOSE, false);
  10306. return 0;
  10307. }
  10308. static int bnx2x_init_mcast_macs_list(struct bnx2x *bp,
  10309. struct bnx2x_mcast_ramrod_params *p)
  10310. {
  10311. int mc_count = netdev_mc_count(bp->dev);
  10312. struct bnx2x_mcast_list_elem *mc_mac =
  10313. kcalloc(mc_count, sizeof(*mc_mac), GFP_ATOMIC);
  10314. struct netdev_hw_addr *ha;
  10315. if (!mc_mac)
  10316. return -ENOMEM;
  10317. INIT_LIST_HEAD(&p->mcast_list);
  10318. netdev_for_each_mc_addr(ha, bp->dev) {
  10319. mc_mac->mac = bnx2x_mc_addr(ha);
  10320. list_add_tail(&mc_mac->link, &p->mcast_list);
  10321. mc_mac++;
  10322. }
  10323. p->mcast_list_len = mc_count;
  10324. return 0;
  10325. }
  10326. static void bnx2x_free_mcast_macs_list(
  10327. struct bnx2x_mcast_ramrod_params *p)
  10328. {
  10329. struct bnx2x_mcast_list_elem *mc_mac =
  10330. list_first_entry(&p->mcast_list, struct bnx2x_mcast_list_elem,
  10331. link);
  10332. WARN_ON(!mc_mac);
  10333. kfree(mc_mac);
  10334. }
  10335. /**
  10336. * bnx2x_set_uc_list - configure a new unicast MACs list.
  10337. *
  10338. * @bp: driver handle
  10339. *
  10340. * We will use zero (0) as a MAC type for these MACs.
  10341. */
  10342. static int bnx2x_set_uc_list(struct bnx2x *bp)
  10343. {
  10344. int rc;
  10345. struct net_device *dev = bp->dev;
  10346. struct netdev_hw_addr *ha;
  10347. struct bnx2x_vlan_mac_obj *mac_obj = &bp->sp_objs->mac_obj;
  10348. unsigned long ramrod_flags = 0;
  10349. /* First schedule a cleanup up of old configuration */
  10350. rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, false);
  10351. if (rc < 0) {
  10352. BNX2X_ERR("Failed to schedule DELETE operations: %d\n", rc);
  10353. return rc;
  10354. }
  10355. netdev_for_each_uc_addr(ha, dev) {
  10356. rc = bnx2x_set_mac_one(bp, bnx2x_uc_addr(ha), mac_obj, true,
  10357. BNX2X_UC_LIST_MAC, &ramrod_flags);
  10358. if (rc == -EEXIST) {
  10359. DP(BNX2X_MSG_SP,
  10360. "Failed to schedule ADD operations: %d\n", rc);
  10361. /* do not treat adding same MAC as error */
  10362. rc = 0;
  10363. } else if (rc < 0) {
  10364. BNX2X_ERR("Failed to schedule ADD operations: %d\n",
  10365. rc);
  10366. return rc;
  10367. }
  10368. }
  10369. /* Execute the pending commands */
  10370. __set_bit(RAMROD_CONT, &ramrod_flags);
  10371. return bnx2x_set_mac_one(bp, NULL, mac_obj, false /* don't care */,
  10372. BNX2X_UC_LIST_MAC, &ramrod_flags);
  10373. }
  10374. static int bnx2x_set_mc_list(struct bnx2x *bp)
  10375. {
  10376. struct net_device *dev = bp->dev;
  10377. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  10378. int rc = 0;
  10379. rparam.mcast_obj = &bp->mcast_obj;
  10380. /* first, clear all configured multicast MACs */
  10381. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  10382. if (rc < 0) {
  10383. BNX2X_ERR("Failed to clear multicast configuration: %d\n", rc);
  10384. return rc;
  10385. }
  10386. /* then, configure a new MACs list */
  10387. if (netdev_mc_count(dev)) {
  10388. rc = bnx2x_init_mcast_macs_list(bp, &rparam);
  10389. if (rc) {
  10390. BNX2X_ERR("Failed to create multicast MACs list: %d\n",
  10391. rc);
  10392. return rc;
  10393. }
  10394. /* Now add the new MACs */
  10395. rc = bnx2x_config_mcast(bp, &rparam,
  10396. BNX2X_MCAST_CMD_ADD);
  10397. if (rc < 0)
  10398. BNX2X_ERR("Failed to set a new multicast configuration: %d\n",
  10399. rc);
  10400. bnx2x_free_mcast_macs_list(&rparam);
  10401. }
  10402. return rc;
  10403. }
  10404. /* If bp->state is OPEN, should be called with netif_addr_lock_bh() */
  10405. static void bnx2x_set_rx_mode(struct net_device *dev)
  10406. {
  10407. struct bnx2x *bp = netdev_priv(dev);
  10408. if (bp->state != BNX2X_STATE_OPEN) {
  10409. DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
  10410. return;
  10411. } else {
  10412. /* Schedule an SP task to handle rest of change */
  10413. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_RX_MODE,
  10414. NETIF_MSG_IFUP);
  10415. }
  10416. }
  10417. void bnx2x_set_rx_mode_inner(struct bnx2x *bp)
  10418. {
  10419. u32 rx_mode = BNX2X_RX_MODE_NORMAL;
  10420. DP(NETIF_MSG_IFUP, "dev->flags = %x\n", bp->dev->flags);
  10421. netif_addr_lock_bh(bp->dev);
  10422. if (bp->dev->flags & IFF_PROMISC) {
  10423. rx_mode = BNX2X_RX_MODE_PROMISC;
  10424. } else if ((bp->dev->flags & IFF_ALLMULTI) ||
  10425. ((netdev_mc_count(bp->dev) > BNX2X_MAX_MULTICAST) &&
  10426. CHIP_IS_E1(bp))) {
  10427. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  10428. } else {
  10429. if (IS_PF(bp)) {
  10430. /* some multicasts */
  10431. if (bnx2x_set_mc_list(bp) < 0)
  10432. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  10433. /* release bh lock, as bnx2x_set_uc_list might sleep */
  10434. netif_addr_unlock_bh(bp->dev);
  10435. if (bnx2x_set_uc_list(bp) < 0)
  10436. rx_mode = BNX2X_RX_MODE_PROMISC;
  10437. netif_addr_lock_bh(bp->dev);
  10438. } else {
  10439. /* configuring mcast to a vf involves sleeping (when we
  10440. * wait for the pf's response).
  10441. */
  10442. bnx2x_schedule_sp_rtnl(bp,
  10443. BNX2X_SP_RTNL_VFPF_MCAST, 0);
  10444. }
  10445. }
  10446. bp->rx_mode = rx_mode;
  10447. /* handle ISCSI SD mode */
  10448. if (IS_MF_ISCSI_ONLY(bp))
  10449. bp->rx_mode = BNX2X_RX_MODE_NONE;
  10450. /* Schedule the rx_mode command */
  10451. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) {
  10452. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  10453. netif_addr_unlock_bh(bp->dev);
  10454. return;
  10455. }
  10456. if (IS_PF(bp)) {
  10457. bnx2x_set_storm_rx_mode(bp);
  10458. netif_addr_unlock_bh(bp->dev);
  10459. } else {
  10460. /* VF will need to request the PF to make this change, and so
  10461. * the VF needs to release the bottom-half lock prior to the
  10462. * request (as it will likely require sleep on the VF side)
  10463. */
  10464. netif_addr_unlock_bh(bp->dev);
  10465. bnx2x_vfpf_storm_rx_mode(bp);
  10466. }
  10467. }
  10468. /* called with rtnl_lock */
  10469. static int bnx2x_mdio_read(struct net_device *netdev, int prtad,
  10470. int devad, u16 addr)
  10471. {
  10472. struct bnx2x *bp = netdev_priv(netdev);
  10473. u16 value;
  10474. int rc;
  10475. DP(NETIF_MSG_LINK, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n",
  10476. prtad, devad, addr);
  10477. /* The HW expects different devad if CL22 is used */
  10478. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  10479. bnx2x_acquire_phy_lock(bp);
  10480. rc = bnx2x_phy_read(&bp->link_params, prtad, devad, addr, &value);
  10481. bnx2x_release_phy_lock(bp);
  10482. DP(NETIF_MSG_LINK, "mdio_read_val 0x%x rc = 0x%x\n", value, rc);
  10483. if (!rc)
  10484. rc = value;
  10485. return rc;
  10486. }
  10487. /* called with rtnl_lock */
  10488. static int bnx2x_mdio_write(struct net_device *netdev, int prtad, int devad,
  10489. u16 addr, u16 value)
  10490. {
  10491. struct bnx2x *bp = netdev_priv(netdev);
  10492. int rc;
  10493. DP(NETIF_MSG_LINK,
  10494. "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x, value 0x%x\n",
  10495. prtad, devad, addr, value);
  10496. /* The HW expects different devad if CL22 is used */
  10497. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  10498. bnx2x_acquire_phy_lock(bp);
  10499. rc = bnx2x_phy_write(&bp->link_params, prtad, devad, addr, value);
  10500. bnx2x_release_phy_lock(bp);
  10501. return rc;
  10502. }
  10503. /* called with rtnl_lock */
  10504. static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  10505. {
  10506. struct bnx2x *bp = netdev_priv(dev);
  10507. struct mii_ioctl_data *mdio = if_mii(ifr);
  10508. if (!netif_running(dev))
  10509. return -EAGAIN;
  10510. switch (cmd) {
  10511. case SIOCSHWTSTAMP:
  10512. return bnx2x_hwtstamp_ioctl(bp, ifr);
  10513. default:
  10514. DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n",
  10515. mdio->phy_id, mdio->reg_num, mdio->val_in);
  10516. return mdio_mii_ioctl(&bp->mdio, mdio, cmd);
  10517. }
  10518. }
  10519. #ifdef CONFIG_NET_POLL_CONTROLLER
  10520. static void poll_bnx2x(struct net_device *dev)
  10521. {
  10522. struct bnx2x *bp = netdev_priv(dev);
  10523. int i;
  10524. for_each_eth_queue(bp, i) {
  10525. struct bnx2x_fastpath *fp = &bp->fp[i];
  10526. napi_schedule(&bnx2x_fp(bp, fp->index, napi));
  10527. }
  10528. }
  10529. #endif
  10530. static int bnx2x_validate_addr(struct net_device *dev)
  10531. {
  10532. struct bnx2x *bp = netdev_priv(dev);
  10533. /* query the bulletin board for mac address configured by the PF */
  10534. if (IS_VF(bp))
  10535. bnx2x_sample_bulletin(bp);
  10536. if (!is_valid_ether_addr(dev->dev_addr)) {
  10537. BNX2X_ERR("Non-valid Ethernet address\n");
  10538. return -EADDRNOTAVAIL;
  10539. }
  10540. return 0;
  10541. }
  10542. static int bnx2x_get_phys_port_id(struct net_device *netdev,
  10543. struct netdev_phys_port_id *ppid)
  10544. {
  10545. struct bnx2x *bp = netdev_priv(netdev);
  10546. if (!(bp->flags & HAS_PHYS_PORT_ID))
  10547. return -EOPNOTSUPP;
  10548. ppid->id_len = sizeof(bp->phys_port_id);
  10549. memcpy(ppid->id, bp->phys_port_id, ppid->id_len);
  10550. return 0;
  10551. }
  10552. static const struct net_device_ops bnx2x_netdev_ops = {
  10553. .ndo_open = bnx2x_open,
  10554. .ndo_stop = bnx2x_close,
  10555. .ndo_start_xmit = bnx2x_start_xmit,
  10556. .ndo_select_queue = bnx2x_select_queue,
  10557. .ndo_set_rx_mode = bnx2x_set_rx_mode,
  10558. .ndo_set_mac_address = bnx2x_change_mac_addr,
  10559. .ndo_validate_addr = bnx2x_validate_addr,
  10560. .ndo_do_ioctl = bnx2x_ioctl,
  10561. .ndo_change_mtu = bnx2x_change_mtu,
  10562. .ndo_fix_features = bnx2x_fix_features,
  10563. .ndo_set_features = bnx2x_set_features,
  10564. .ndo_tx_timeout = bnx2x_tx_timeout,
  10565. #ifdef CONFIG_NET_POLL_CONTROLLER
  10566. .ndo_poll_controller = poll_bnx2x,
  10567. #endif
  10568. .ndo_setup_tc = bnx2x_setup_tc,
  10569. #ifdef CONFIG_BNX2X_SRIOV
  10570. .ndo_set_vf_mac = bnx2x_set_vf_mac,
  10571. .ndo_set_vf_vlan = bnx2x_set_vf_vlan,
  10572. .ndo_get_vf_config = bnx2x_get_vf_config,
  10573. #endif
  10574. #ifdef NETDEV_FCOE_WWNN
  10575. .ndo_fcoe_get_wwn = bnx2x_fcoe_get_wwn,
  10576. #endif
  10577. #ifdef CONFIG_NET_RX_BUSY_POLL
  10578. .ndo_busy_poll = bnx2x_low_latency_recv,
  10579. #endif
  10580. .ndo_get_phys_port_id = bnx2x_get_phys_port_id,
  10581. .ndo_set_vf_link_state = bnx2x_set_vf_link_state,
  10582. };
  10583. static int bnx2x_set_coherency_mask(struct bnx2x *bp)
  10584. {
  10585. struct device *dev = &bp->pdev->dev;
  10586. if (dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64)) != 0 &&
  10587. dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32)) != 0) {
  10588. dev_err(dev, "System does not support DMA, aborting\n");
  10589. return -EIO;
  10590. }
  10591. return 0;
  10592. }
  10593. static void bnx2x_disable_pcie_error_reporting(struct bnx2x *bp)
  10594. {
  10595. if (bp->flags & AER_ENABLED) {
  10596. pci_disable_pcie_error_reporting(bp->pdev);
  10597. bp->flags &= ~AER_ENABLED;
  10598. }
  10599. }
  10600. static int bnx2x_init_dev(struct bnx2x *bp, struct pci_dev *pdev,
  10601. struct net_device *dev, unsigned long board_type)
  10602. {
  10603. int rc;
  10604. u32 pci_cfg_dword;
  10605. bool chip_is_e1x = (board_type == BCM57710 ||
  10606. board_type == BCM57711 ||
  10607. board_type == BCM57711E);
  10608. SET_NETDEV_DEV(dev, &pdev->dev);
  10609. bp->dev = dev;
  10610. bp->pdev = pdev;
  10611. rc = pci_enable_device(pdev);
  10612. if (rc) {
  10613. dev_err(&bp->pdev->dev,
  10614. "Cannot enable PCI device, aborting\n");
  10615. goto err_out;
  10616. }
  10617. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  10618. dev_err(&bp->pdev->dev,
  10619. "Cannot find PCI device base address, aborting\n");
  10620. rc = -ENODEV;
  10621. goto err_out_disable;
  10622. }
  10623. if (IS_PF(bp) && !(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
  10624. dev_err(&bp->pdev->dev, "Cannot find second PCI device base address, aborting\n");
  10625. rc = -ENODEV;
  10626. goto err_out_disable;
  10627. }
  10628. pci_read_config_dword(pdev, PCICFG_REVISION_ID_OFFSET, &pci_cfg_dword);
  10629. if ((pci_cfg_dword & PCICFG_REVESION_ID_MASK) ==
  10630. PCICFG_REVESION_ID_ERROR_VAL) {
  10631. pr_err("PCI device error, probably due to fan failure, aborting\n");
  10632. rc = -ENODEV;
  10633. goto err_out_disable;
  10634. }
  10635. if (atomic_read(&pdev->enable_cnt) == 1) {
  10636. rc = pci_request_regions(pdev, DRV_MODULE_NAME);
  10637. if (rc) {
  10638. dev_err(&bp->pdev->dev,
  10639. "Cannot obtain PCI resources, aborting\n");
  10640. goto err_out_disable;
  10641. }
  10642. pci_set_master(pdev);
  10643. pci_save_state(pdev);
  10644. }
  10645. if (IS_PF(bp)) {
  10646. if (!pdev->pm_cap) {
  10647. dev_err(&bp->pdev->dev,
  10648. "Cannot find power management capability, aborting\n");
  10649. rc = -EIO;
  10650. goto err_out_release;
  10651. }
  10652. }
  10653. if (!pci_is_pcie(pdev)) {
  10654. dev_err(&bp->pdev->dev, "Not PCI Express, aborting\n");
  10655. rc = -EIO;
  10656. goto err_out_release;
  10657. }
  10658. rc = bnx2x_set_coherency_mask(bp);
  10659. if (rc)
  10660. goto err_out_release;
  10661. dev->mem_start = pci_resource_start(pdev, 0);
  10662. dev->base_addr = dev->mem_start;
  10663. dev->mem_end = pci_resource_end(pdev, 0);
  10664. dev->irq = pdev->irq;
  10665. bp->regview = pci_ioremap_bar(pdev, 0);
  10666. if (!bp->regview) {
  10667. dev_err(&bp->pdev->dev,
  10668. "Cannot map register space, aborting\n");
  10669. rc = -ENOMEM;
  10670. goto err_out_release;
  10671. }
  10672. /* In E1/E1H use pci device function given by kernel.
  10673. * In E2/E3 read physical function from ME register since these chips
  10674. * support Physical Device Assignment where kernel BDF maybe arbitrary
  10675. * (depending on hypervisor).
  10676. */
  10677. if (chip_is_e1x) {
  10678. bp->pf_num = PCI_FUNC(pdev->devfn);
  10679. } else {
  10680. /* chip is E2/3*/
  10681. pci_read_config_dword(bp->pdev,
  10682. PCICFG_ME_REGISTER, &pci_cfg_dword);
  10683. bp->pf_num = (u8)((pci_cfg_dword & ME_REG_ABS_PF_NUM) >>
  10684. ME_REG_ABS_PF_NUM_SHIFT);
  10685. }
  10686. BNX2X_DEV_INFO("me reg PF num: %d\n", bp->pf_num);
  10687. /* clean indirect addresses */
  10688. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  10689. PCICFG_VENDOR_ID_OFFSET);
  10690. /* Set PCIe reset type to fundamental for EEH recovery */
  10691. pdev->needs_freset = 1;
  10692. /* AER (Advanced Error reporting) configuration */
  10693. rc = pci_enable_pcie_error_reporting(pdev);
  10694. if (!rc)
  10695. bp->flags |= AER_ENABLED;
  10696. else
  10697. BNX2X_DEV_INFO("Failed To configure PCIe AER [%d]\n", rc);
  10698. /*
  10699. * Clean the following indirect addresses for all functions since it
  10700. * is not used by the driver.
  10701. */
  10702. if (IS_PF(bp)) {
  10703. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0, 0);
  10704. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0, 0);
  10705. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0, 0);
  10706. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0, 0);
  10707. if (chip_is_e1x) {
  10708. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F1, 0);
  10709. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F1, 0);
  10710. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F1, 0);
  10711. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F1, 0);
  10712. }
  10713. /* Enable internal target-read (in case we are probed after PF
  10714. * FLR). Must be done prior to any BAR read access. Only for
  10715. * 57712 and up
  10716. */
  10717. if (!chip_is_e1x)
  10718. REG_WR(bp,
  10719. PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  10720. }
  10721. dev->watchdog_timeo = TX_TIMEOUT;
  10722. dev->netdev_ops = &bnx2x_netdev_ops;
  10723. bnx2x_set_ethtool_ops(bp, dev);
  10724. dev->priv_flags |= IFF_UNICAST_FLT;
  10725. dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  10726. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
  10727. NETIF_F_RXCSUM | NETIF_F_LRO | NETIF_F_GRO |
  10728. NETIF_F_RXHASH | NETIF_F_HW_VLAN_CTAG_TX;
  10729. if (!CHIP_IS_E1x(bp)) {
  10730. dev->hw_features |= NETIF_F_GSO_GRE | NETIF_F_GSO_UDP_TUNNEL |
  10731. NETIF_F_GSO_IPIP | NETIF_F_GSO_SIT;
  10732. dev->hw_enc_features =
  10733. NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_SG |
  10734. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
  10735. NETIF_F_GSO_IPIP |
  10736. NETIF_F_GSO_SIT |
  10737. NETIF_F_GSO_GRE | NETIF_F_GSO_UDP_TUNNEL;
  10738. }
  10739. dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  10740. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_HIGHDMA;
  10741. dev->features |= dev->hw_features | NETIF_F_HW_VLAN_CTAG_RX;
  10742. dev->features |= NETIF_F_HIGHDMA;
  10743. /* Add Loopback capability to the device */
  10744. dev->hw_features |= NETIF_F_LOOPBACK;
  10745. #ifdef BCM_DCBNL
  10746. dev->dcbnl_ops = &bnx2x_dcbnl_ops;
  10747. #endif
  10748. /* get_port_hwinfo() will set prtad and mmds properly */
  10749. bp->mdio.prtad = MDIO_PRTAD_NONE;
  10750. bp->mdio.mmds = 0;
  10751. bp->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
  10752. bp->mdio.dev = dev;
  10753. bp->mdio.mdio_read = bnx2x_mdio_read;
  10754. bp->mdio.mdio_write = bnx2x_mdio_write;
  10755. return 0;
  10756. err_out_release:
  10757. if (atomic_read(&pdev->enable_cnt) == 1)
  10758. pci_release_regions(pdev);
  10759. err_out_disable:
  10760. pci_disable_device(pdev);
  10761. err_out:
  10762. return rc;
  10763. }
  10764. static int bnx2x_check_firmware(struct bnx2x *bp)
  10765. {
  10766. const struct firmware *firmware = bp->firmware;
  10767. struct bnx2x_fw_file_hdr *fw_hdr;
  10768. struct bnx2x_fw_file_section *sections;
  10769. u32 offset, len, num_ops;
  10770. __be16 *ops_offsets;
  10771. int i;
  10772. const u8 *fw_ver;
  10773. if (firmware->size < sizeof(struct bnx2x_fw_file_hdr)) {
  10774. BNX2X_ERR("Wrong FW size\n");
  10775. return -EINVAL;
  10776. }
  10777. fw_hdr = (struct bnx2x_fw_file_hdr *)firmware->data;
  10778. sections = (struct bnx2x_fw_file_section *)fw_hdr;
  10779. /* Make sure none of the offsets and sizes make us read beyond
  10780. * the end of the firmware data */
  10781. for (i = 0; i < sizeof(*fw_hdr) / sizeof(*sections); i++) {
  10782. offset = be32_to_cpu(sections[i].offset);
  10783. len = be32_to_cpu(sections[i].len);
  10784. if (offset + len > firmware->size) {
  10785. BNX2X_ERR("Section %d length is out of bounds\n", i);
  10786. return -EINVAL;
  10787. }
  10788. }
  10789. /* Likewise for the init_ops offsets */
  10790. offset = be32_to_cpu(fw_hdr->init_ops_offsets.offset);
  10791. ops_offsets = (__force __be16 *)(firmware->data + offset);
  10792. num_ops = be32_to_cpu(fw_hdr->init_ops.len) / sizeof(struct raw_op);
  10793. for (i = 0; i < be32_to_cpu(fw_hdr->init_ops_offsets.len) / 2; i++) {
  10794. if (be16_to_cpu(ops_offsets[i]) > num_ops) {
  10795. BNX2X_ERR("Section offset %d is out of bounds\n", i);
  10796. return -EINVAL;
  10797. }
  10798. }
  10799. /* Check FW version */
  10800. offset = be32_to_cpu(fw_hdr->fw_version.offset);
  10801. fw_ver = firmware->data + offset;
  10802. if ((fw_ver[0] != BCM_5710_FW_MAJOR_VERSION) ||
  10803. (fw_ver[1] != BCM_5710_FW_MINOR_VERSION) ||
  10804. (fw_ver[2] != BCM_5710_FW_REVISION_VERSION) ||
  10805. (fw_ver[3] != BCM_5710_FW_ENGINEERING_VERSION)) {
  10806. BNX2X_ERR("Bad FW version:%d.%d.%d.%d. Should be %d.%d.%d.%d\n",
  10807. fw_ver[0], fw_ver[1], fw_ver[2], fw_ver[3],
  10808. BCM_5710_FW_MAJOR_VERSION,
  10809. BCM_5710_FW_MINOR_VERSION,
  10810. BCM_5710_FW_REVISION_VERSION,
  10811. BCM_5710_FW_ENGINEERING_VERSION);
  10812. return -EINVAL;
  10813. }
  10814. return 0;
  10815. }
  10816. static void be32_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  10817. {
  10818. const __be32 *source = (const __be32 *)_source;
  10819. u32 *target = (u32 *)_target;
  10820. u32 i;
  10821. for (i = 0; i < n/4; i++)
  10822. target[i] = be32_to_cpu(source[i]);
  10823. }
  10824. /*
  10825. Ops array is stored in the following format:
  10826. {op(8bit), offset(24bit, big endian), data(32bit, big endian)}
  10827. */
  10828. static void bnx2x_prep_ops(const u8 *_source, u8 *_target, u32 n)
  10829. {
  10830. const __be32 *source = (const __be32 *)_source;
  10831. struct raw_op *target = (struct raw_op *)_target;
  10832. u32 i, j, tmp;
  10833. for (i = 0, j = 0; i < n/8; i++, j += 2) {
  10834. tmp = be32_to_cpu(source[j]);
  10835. target[i].op = (tmp >> 24) & 0xff;
  10836. target[i].offset = tmp & 0xffffff;
  10837. target[i].raw_data = be32_to_cpu(source[j + 1]);
  10838. }
  10839. }
  10840. /* IRO array is stored in the following format:
  10841. * {base(24bit), m1(16bit), m2(16bit), m3(16bit), size(16bit) }
  10842. */
  10843. static void bnx2x_prep_iro(const u8 *_source, u8 *_target, u32 n)
  10844. {
  10845. const __be32 *source = (const __be32 *)_source;
  10846. struct iro *target = (struct iro *)_target;
  10847. u32 i, j, tmp;
  10848. for (i = 0, j = 0; i < n/sizeof(struct iro); i++) {
  10849. target[i].base = be32_to_cpu(source[j]);
  10850. j++;
  10851. tmp = be32_to_cpu(source[j]);
  10852. target[i].m1 = (tmp >> 16) & 0xffff;
  10853. target[i].m2 = tmp & 0xffff;
  10854. j++;
  10855. tmp = be32_to_cpu(source[j]);
  10856. target[i].m3 = (tmp >> 16) & 0xffff;
  10857. target[i].size = tmp & 0xffff;
  10858. j++;
  10859. }
  10860. }
  10861. static void be16_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  10862. {
  10863. const __be16 *source = (const __be16 *)_source;
  10864. u16 *target = (u16 *)_target;
  10865. u32 i;
  10866. for (i = 0; i < n/2; i++)
  10867. target[i] = be16_to_cpu(source[i]);
  10868. }
  10869. #define BNX2X_ALLOC_AND_SET(arr, lbl, func) \
  10870. do { \
  10871. u32 len = be32_to_cpu(fw_hdr->arr.len); \
  10872. bp->arr = kmalloc(len, GFP_KERNEL); \
  10873. if (!bp->arr) \
  10874. goto lbl; \
  10875. func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \
  10876. (u8 *)bp->arr, len); \
  10877. } while (0)
  10878. static int bnx2x_init_firmware(struct bnx2x *bp)
  10879. {
  10880. const char *fw_file_name;
  10881. struct bnx2x_fw_file_hdr *fw_hdr;
  10882. int rc;
  10883. if (bp->firmware)
  10884. return 0;
  10885. if (CHIP_IS_E1(bp))
  10886. fw_file_name = FW_FILE_NAME_E1;
  10887. else if (CHIP_IS_E1H(bp))
  10888. fw_file_name = FW_FILE_NAME_E1H;
  10889. else if (!CHIP_IS_E1x(bp))
  10890. fw_file_name = FW_FILE_NAME_E2;
  10891. else {
  10892. BNX2X_ERR("Unsupported chip revision\n");
  10893. return -EINVAL;
  10894. }
  10895. BNX2X_DEV_INFO("Loading %s\n", fw_file_name);
  10896. rc = request_firmware(&bp->firmware, fw_file_name, &bp->pdev->dev);
  10897. if (rc) {
  10898. BNX2X_ERR("Can't load firmware file %s\n",
  10899. fw_file_name);
  10900. goto request_firmware_exit;
  10901. }
  10902. rc = bnx2x_check_firmware(bp);
  10903. if (rc) {
  10904. BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name);
  10905. goto request_firmware_exit;
  10906. }
  10907. fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data;
  10908. /* Initialize the pointers to the init arrays */
  10909. /* Blob */
  10910. BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n);
  10911. /* Opcodes */
  10912. BNX2X_ALLOC_AND_SET(init_ops, init_ops_alloc_err, bnx2x_prep_ops);
  10913. /* Offsets */
  10914. BNX2X_ALLOC_AND_SET(init_ops_offsets, init_offsets_alloc_err,
  10915. be16_to_cpu_n);
  10916. /* STORMs firmware */
  10917. INIT_TSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10918. be32_to_cpu(fw_hdr->tsem_int_table_data.offset);
  10919. INIT_TSEM_PRAM_DATA(bp) = bp->firmware->data +
  10920. be32_to_cpu(fw_hdr->tsem_pram_data.offset);
  10921. INIT_USEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10922. be32_to_cpu(fw_hdr->usem_int_table_data.offset);
  10923. INIT_USEM_PRAM_DATA(bp) = bp->firmware->data +
  10924. be32_to_cpu(fw_hdr->usem_pram_data.offset);
  10925. INIT_XSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10926. be32_to_cpu(fw_hdr->xsem_int_table_data.offset);
  10927. INIT_XSEM_PRAM_DATA(bp) = bp->firmware->data +
  10928. be32_to_cpu(fw_hdr->xsem_pram_data.offset);
  10929. INIT_CSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10930. be32_to_cpu(fw_hdr->csem_int_table_data.offset);
  10931. INIT_CSEM_PRAM_DATA(bp) = bp->firmware->data +
  10932. be32_to_cpu(fw_hdr->csem_pram_data.offset);
  10933. /* IRO */
  10934. BNX2X_ALLOC_AND_SET(iro_arr, iro_alloc_err, bnx2x_prep_iro);
  10935. return 0;
  10936. iro_alloc_err:
  10937. kfree(bp->init_ops_offsets);
  10938. init_offsets_alloc_err:
  10939. kfree(bp->init_ops);
  10940. init_ops_alloc_err:
  10941. kfree(bp->init_data);
  10942. request_firmware_exit:
  10943. release_firmware(bp->firmware);
  10944. bp->firmware = NULL;
  10945. return rc;
  10946. }
  10947. static void bnx2x_release_firmware(struct bnx2x *bp)
  10948. {
  10949. kfree(bp->init_ops_offsets);
  10950. kfree(bp->init_ops);
  10951. kfree(bp->init_data);
  10952. release_firmware(bp->firmware);
  10953. bp->firmware = NULL;
  10954. }
  10955. static struct bnx2x_func_sp_drv_ops bnx2x_func_sp_drv = {
  10956. .init_hw_cmn_chip = bnx2x_init_hw_common_chip,
  10957. .init_hw_cmn = bnx2x_init_hw_common,
  10958. .init_hw_port = bnx2x_init_hw_port,
  10959. .init_hw_func = bnx2x_init_hw_func,
  10960. .reset_hw_cmn = bnx2x_reset_common,
  10961. .reset_hw_port = bnx2x_reset_port,
  10962. .reset_hw_func = bnx2x_reset_func,
  10963. .gunzip_init = bnx2x_gunzip_init,
  10964. .gunzip_end = bnx2x_gunzip_end,
  10965. .init_fw = bnx2x_init_firmware,
  10966. .release_fw = bnx2x_release_firmware,
  10967. };
  10968. void bnx2x__init_func_obj(struct bnx2x *bp)
  10969. {
  10970. /* Prepare DMAE related driver resources */
  10971. bnx2x_setup_dmae(bp);
  10972. bnx2x_init_func_obj(bp, &bp->func_obj,
  10973. bnx2x_sp(bp, func_rdata),
  10974. bnx2x_sp_mapping(bp, func_rdata),
  10975. bnx2x_sp(bp, func_afex_rdata),
  10976. bnx2x_sp_mapping(bp, func_afex_rdata),
  10977. &bnx2x_func_sp_drv);
  10978. }
  10979. /* must be called after sriov-enable */
  10980. static int bnx2x_set_qm_cid_count(struct bnx2x *bp)
  10981. {
  10982. int cid_count = BNX2X_L2_MAX_CID(bp);
  10983. if (IS_SRIOV(bp))
  10984. cid_count += BNX2X_VF_CIDS;
  10985. if (CNIC_SUPPORT(bp))
  10986. cid_count += CNIC_CID_MAX;
  10987. return roundup(cid_count, QM_CID_ROUND);
  10988. }
  10989. /**
  10990. * bnx2x_get_num_none_def_sbs - return the number of none default SBs
  10991. *
  10992. * @dev: pci device
  10993. *
  10994. */
  10995. static int bnx2x_get_num_non_def_sbs(struct pci_dev *pdev, int cnic_cnt)
  10996. {
  10997. int index;
  10998. u16 control = 0;
  10999. /*
  11000. * If MSI-X is not supported - return number of SBs needed to support
  11001. * one fast path queue: one FP queue + SB for CNIC
  11002. */
  11003. if (!pdev->msix_cap) {
  11004. dev_info(&pdev->dev, "no msix capability found\n");
  11005. return 1 + cnic_cnt;
  11006. }
  11007. dev_info(&pdev->dev, "msix capability found\n");
  11008. /*
  11009. * The value in the PCI configuration space is the index of the last
  11010. * entry, namely one less than the actual size of the table, which is
  11011. * exactly what we want to return from this function: number of all SBs
  11012. * without the default SB.
  11013. * For VFs there is no default SB, then we return (index+1).
  11014. */
  11015. pci_read_config_word(pdev, pdev->msix_cap + PCI_MSIX_FLAGS, &control);
  11016. index = control & PCI_MSIX_FLAGS_QSIZE;
  11017. return index;
  11018. }
  11019. static int set_max_cos_est(int chip_id)
  11020. {
  11021. switch (chip_id) {
  11022. case BCM57710:
  11023. case BCM57711:
  11024. case BCM57711E:
  11025. return BNX2X_MULTI_TX_COS_E1X;
  11026. case BCM57712:
  11027. case BCM57712_MF:
  11028. return BNX2X_MULTI_TX_COS_E2_E3A0;
  11029. case BCM57800:
  11030. case BCM57800_MF:
  11031. case BCM57810:
  11032. case BCM57810_MF:
  11033. case BCM57840_4_10:
  11034. case BCM57840_2_20:
  11035. case BCM57840_O:
  11036. case BCM57840_MFO:
  11037. case BCM57840_MF:
  11038. case BCM57811:
  11039. case BCM57811_MF:
  11040. return BNX2X_MULTI_TX_COS_E3B0;
  11041. case BCM57712_VF:
  11042. case BCM57800_VF:
  11043. case BCM57810_VF:
  11044. case BCM57840_VF:
  11045. case BCM57811_VF:
  11046. return 1;
  11047. default:
  11048. pr_err("Unknown board_type (%d), aborting\n", chip_id);
  11049. return -ENODEV;
  11050. }
  11051. }
  11052. static int set_is_vf(int chip_id)
  11053. {
  11054. switch (chip_id) {
  11055. case BCM57712_VF:
  11056. case BCM57800_VF:
  11057. case BCM57810_VF:
  11058. case BCM57840_VF:
  11059. case BCM57811_VF:
  11060. return true;
  11061. default:
  11062. return false;
  11063. }
  11064. }
  11065. /* nig_tsgen registers relative address */
  11066. #define tsgen_ctrl 0x0
  11067. #define tsgen_freecount 0x10
  11068. #define tsgen_synctime_t0 0x20
  11069. #define tsgen_offset_t0 0x28
  11070. #define tsgen_drift_t0 0x30
  11071. #define tsgen_synctime_t1 0x58
  11072. #define tsgen_offset_t1 0x60
  11073. #define tsgen_drift_t1 0x68
  11074. /* FW workaround for setting drift */
  11075. static int bnx2x_send_update_drift_ramrod(struct bnx2x *bp, int drift_dir,
  11076. int best_val, int best_period)
  11077. {
  11078. struct bnx2x_func_state_params func_params = {NULL};
  11079. struct bnx2x_func_set_timesync_params *set_timesync_params =
  11080. &func_params.params.set_timesync;
  11081. /* Prepare parameters for function state transitions */
  11082. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  11083. __set_bit(RAMROD_RETRY, &func_params.ramrod_flags);
  11084. func_params.f_obj = &bp->func_obj;
  11085. func_params.cmd = BNX2X_F_CMD_SET_TIMESYNC;
  11086. /* Function parameters */
  11087. set_timesync_params->drift_adjust_cmd = TS_DRIFT_ADJUST_SET;
  11088. set_timesync_params->offset_cmd = TS_OFFSET_KEEP;
  11089. set_timesync_params->add_sub_drift_adjust_value =
  11090. drift_dir ? TS_ADD_VALUE : TS_SUB_VALUE;
  11091. set_timesync_params->drift_adjust_value = best_val;
  11092. set_timesync_params->drift_adjust_period = best_period;
  11093. return bnx2x_func_state_change(bp, &func_params);
  11094. }
  11095. static int bnx2x_ptp_adjfreq(struct ptp_clock_info *ptp, s32 ppb)
  11096. {
  11097. struct bnx2x *bp = container_of(ptp, struct bnx2x, ptp_clock_info);
  11098. int rc;
  11099. int drift_dir = 1;
  11100. int val, period, period1, period2, dif, dif1, dif2;
  11101. int best_dif = BNX2X_MAX_PHC_DRIFT, best_period = 0, best_val = 0;
  11102. DP(BNX2X_MSG_PTP, "PTP adjfreq called, ppb = %d\n", ppb);
  11103. if (!netif_running(bp->dev)) {
  11104. DP(BNX2X_MSG_PTP,
  11105. "PTP adjfreq called while the interface is down\n");
  11106. return -EFAULT;
  11107. }
  11108. if (ppb < 0) {
  11109. ppb = -ppb;
  11110. drift_dir = 0;
  11111. }
  11112. if (ppb == 0) {
  11113. best_val = 1;
  11114. best_period = 0x1FFFFFF;
  11115. } else if (ppb >= BNX2X_MAX_PHC_DRIFT) {
  11116. best_val = 31;
  11117. best_period = 1;
  11118. } else {
  11119. /* Changed not to allow val = 8, 16, 24 as these values
  11120. * are not supported in workaround.
  11121. */
  11122. for (val = 0; val <= 31; val++) {
  11123. if ((val & 0x7) == 0)
  11124. continue;
  11125. period1 = val * 1000000 / ppb;
  11126. period2 = period1 + 1;
  11127. if (period1 != 0)
  11128. dif1 = ppb - (val * 1000000 / period1);
  11129. else
  11130. dif1 = BNX2X_MAX_PHC_DRIFT;
  11131. if (dif1 < 0)
  11132. dif1 = -dif1;
  11133. dif2 = ppb - (val * 1000000 / period2);
  11134. if (dif2 < 0)
  11135. dif2 = -dif2;
  11136. dif = (dif1 < dif2) ? dif1 : dif2;
  11137. period = (dif1 < dif2) ? period1 : period2;
  11138. if (dif < best_dif) {
  11139. best_dif = dif;
  11140. best_val = val;
  11141. best_period = period;
  11142. }
  11143. }
  11144. }
  11145. rc = bnx2x_send_update_drift_ramrod(bp, drift_dir, best_val,
  11146. best_period);
  11147. if (rc) {
  11148. BNX2X_ERR("Failed to set drift\n");
  11149. return -EFAULT;
  11150. }
  11151. DP(BNX2X_MSG_PTP, "Configrued val = %d, period = %d\n", best_val,
  11152. best_period);
  11153. return 0;
  11154. }
  11155. static int bnx2x_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta)
  11156. {
  11157. struct bnx2x *bp = container_of(ptp, struct bnx2x, ptp_clock_info);
  11158. u64 now;
  11159. DP(BNX2X_MSG_PTP, "PTP adjtime called, delta = %llx\n", delta);
  11160. now = timecounter_read(&bp->timecounter);
  11161. now += delta;
  11162. /* Re-init the timecounter */
  11163. timecounter_init(&bp->timecounter, &bp->cyclecounter, now);
  11164. return 0;
  11165. }
  11166. static int bnx2x_ptp_gettime(struct ptp_clock_info *ptp, struct timespec *ts)
  11167. {
  11168. struct bnx2x *bp = container_of(ptp, struct bnx2x, ptp_clock_info);
  11169. u64 ns;
  11170. u32 remainder;
  11171. ns = timecounter_read(&bp->timecounter);
  11172. DP(BNX2X_MSG_PTP, "PTP gettime called, ns = %llu\n", ns);
  11173. ts->tv_sec = div_u64_rem(ns, 1000000000ULL, &remainder);
  11174. ts->tv_nsec = remainder;
  11175. return 0;
  11176. }
  11177. static int bnx2x_ptp_settime(struct ptp_clock_info *ptp,
  11178. const struct timespec *ts)
  11179. {
  11180. struct bnx2x *bp = container_of(ptp, struct bnx2x, ptp_clock_info);
  11181. u64 ns;
  11182. ns = ts->tv_sec * 1000000000ULL;
  11183. ns += ts->tv_nsec;
  11184. DP(BNX2X_MSG_PTP, "PTP settime called, ns = %llu\n", ns);
  11185. /* Re-init the timecounter */
  11186. timecounter_init(&bp->timecounter, &bp->cyclecounter, ns);
  11187. return 0;
  11188. }
  11189. /* Enable (or disable) ancillary features of the phc subsystem */
  11190. static int bnx2x_ptp_enable(struct ptp_clock_info *ptp,
  11191. struct ptp_clock_request *rq, int on)
  11192. {
  11193. struct bnx2x *bp = container_of(ptp, struct bnx2x, ptp_clock_info);
  11194. BNX2X_ERR("PHC ancillary features are not supported\n");
  11195. return -ENOTSUPP;
  11196. }
  11197. void bnx2x_register_phc(struct bnx2x *bp)
  11198. {
  11199. /* Fill the ptp_clock_info struct and register PTP clock*/
  11200. bp->ptp_clock_info.owner = THIS_MODULE;
  11201. snprintf(bp->ptp_clock_info.name, 16, "%s", bp->dev->name);
  11202. bp->ptp_clock_info.max_adj = BNX2X_MAX_PHC_DRIFT; /* In PPB */
  11203. bp->ptp_clock_info.n_alarm = 0;
  11204. bp->ptp_clock_info.n_ext_ts = 0;
  11205. bp->ptp_clock_info.n_per_out = 0;
  11206. bp->ptp_clock_info.pps = 0;
  11207. bp->ptp_clock_info.adjfreq = bnx2x_ptp_adjfreq;
  11208. bp->ptp_clock_info.adjtime = bnx2x_ptp_adjtime;
  11209. bp->ptp_clock_info.gettime = bnx2x_ptp_gettime;
  11210. bp->ptp_clock_info.settime = bnx2x_ptp_settime;
  11211. bp->ptp_clock_info.enable = bnx2x_ptp_enable;
  11212. bp->ptp_clock = ptp_clock_register(&bp->ptp_clock_info, &bp->pdev->dev);
  11213. if (IS_ERR(bp->ptp_clock)) {
  11214. bp->ptp_clock = NULL;
  11215. BNX2X_ERR("PTP clock registeration failed\n");
  11216. }
  11217. }
  11218. static int bnx2x_init_one(struct pci_dev *pdev,
  11219. const struct pci_device_id *ent)
  11220. {
  11221. struct net_device *dev = NULL;
  11222. struct bnx2x *bp;
  11223. enum pcie_link_width pcie_width;
  11224. enum pci_bus_speed pcie_speed;
  11225. int rc, max_non_def_sbs;
  11226. int rx_count, tx_count, rss_count, doorbell_size;
  11227. int max_cos_est;
  11228. bool is_vf;
  11229. int cnic_cnt;
  11230. /* An estimated maximum supported CoS number according to the chip
  11231. * version.
  11232. * We will try to roughly estimate the maximum number of CoSes this chip
  11233. * may support in order to minimize the memory allocated for Tx
  11234. * netdev_queue's. This number will be accurately calculated during the
  11235. * initialization of bp->max_cos based on the chip versions AND chip
  11236. * revision in the bnx2x_init_bp().
  11237. */
  11238. max_cos_est = set_max_cos_est(ent->driver_data);
  11239. if (max_cos_est < 0)
  11240. return max_cos_est;
  11241. is_vf = set_is_vf(ent->driver_data);
  11242. cnic_cnt = is_vf ? 0 : 1;
  11243. max_non_def_sbs = bnx2x_get_num_non_def_sbs(pdev, cnic_cnt);
  11244. /* add another SB for VF as it has no default SB */
  11245. max_non_def_sbs += is_vf ? 1 : 0;
  11246. /* Maximum number of RSS queues: one IGU SB goes to CNIC */
  11247. rss_count = max_non_def_sbs - cnic_cnt;
  11248. if (rss_count < 1)
  11249. return -EINVAL;
  11250. /* Maximum number of netdev Rx queues: RSS + FCoE L2 */
  11251. rx_count = rss_count + cnic_cnt;
  11252. /* Maximum number of netdev Tx queues:
  11253. * Maximum TSS queues * Maximum supported number of CoS + FCoE L2
  11254. */
  11255. tx_count = rss_count * max_cos_est + cnic_cnt;
  11256. /* dev zeroed in init_etherdev */
  11257. dev = alloc_etherdev_mqs(sizeof(*bp), tx_count, rx_count);
  11258. if (!dev)
  11259. return -ENOMEM;
  11260. bp = netdev_priv(dev);
  11261. bp->flags = 0;
  11262. if (is_vf)
  11263. bp->flags |= IS_VF_FLAG;
  11264. bp->igu_sb_cnt = max_non_def_sbs;
  11265. bp->igu_base_addr = IS_VF(bp) ? PXP_VF_ADDR_IGU_START : BAR_IGU_INTMEM;
  11266. bp->msg_enable = debug;
  11267. bp->cnic_support = cnic_cnt;
  11268. bp->cnic_probe = bnx2x_cnic_probe;
  11269. pci_set_drvdata(pdev, dev);
  11270. rc = bnx2x_init_dev(bp, pdev, dev, ent->driver_data);
  11271. if (rc < 0) {
  11272. free_netdev(dev);
  11273. return rc;
  11274. }
  11275. BNX2X_DEV_INFO("This is a %s function\n",
  11276. IS_PF(bp) ? "physical" : "virtual");
  11277. BNX2X_DEV_INFO("Cnic support is %s\n", CNIC_SUPPORT(bp) ? "on" : "off");
  11278. BNX2X_DEV_INFO("Max num of status blocks %d\n", max_non_def_sbs);
  11279. BNX2X_DEV_INFO("Allocated netdev with %d tx and %d rx queues\n",
  11280. tx_count, rx_count);
  11281. rc = bnx2x_init_bp(bp);
  11282. if (rc)
  11283. goto init_one_exit;
  11284. /* Map doorbells here as we need the real value of bp->max_cos which
  11285. * is initialized in bnx2x_init_bp() to determine the number of
  11286. * l2 connections.
  11287. */
  11288. if (IS_VF(bp)) {
  11289. bp->doorbells = bnx2x_vf_doorbells(bp);
  11290. rc = bnx2x_vf_pci_alloc(bp);
  11291. if (rc)
  11292. goto init_one_exit;
  11293. } else {
  11294. doorbell_size = BNX2X_L2_MAX_CID(bp) * (1 << BNX2X_DB_SHIFT);
  11295. if (doorbell_size > pci_resource_len(pdev, 2)) {
  11296. dev_err(&bp->pdev->dev,
  11297. "Cannot map doorbells, bar size too small, aborting\n");
  11298. rc = -ENOMEM;
  11299. goto init_one_exit;
  11300. }
  11301. bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2),
  11302. doorbell_size);
  11303. }
  11304. if (!bp->doorbells) {
  11305. dev_err(&bp->pdev->dev,
  11306. "Cannot map doorbell space, aborting\n");
  11307. rc = -ENOMEM;
  11308. goto init_one_exit;
  11309. }
  11310. if (IS_VF(bp)) {
  11311. rc = bnx2x_vfpf_acquire(bp, tx_count, rx_count);
  11312. if (rc)
  11313. goto init_one_exit;
  11314. }
  11315. /* Enable SRIOV if capability found in configuration space */
  11316. rc = bnx2x_iov_init_one(bp, int_mode, BNX2X_MAX_NUM_OF_VFS);
  11317. if (rc)
  11318. goto init_one_exit;
  11319. /* calc qm_cid_count */
  11320. bp->qm_cid_count = bnx2x_set_qm_cid_count(bp);
  11321. BNX2X_DEV_INFO("qm_cid_count %d\n", bp->qm_cid_count);
  11322. /* disable FCOE L2 queue for E1x*/
  11323. if (CHIP_IS_E1x(bp))
  11324. bp->flags |= NO_FCOE_FLAG;
  11325. /* Set bp->num_queues for MSI-X mode*/
  11326. bnx2x_set_num_queues(bp);
  11327. /* Configure interrupt mode: try to enable MSI-X/MSI if
  11328. * needed.
  11329. */
  11330. rc = bnx2x_set_int_mode(bp);
  11331. if (rc) {
  11332. dev_err(&pdev->dev, "Cannot set interrupts\n");
  11333. goto init_one_exit;
  11334. }
  11335. BNX2X_DEV_INFO("set interrupts successfully\n");
  11336. /* register the net device */
  11337. rc = register_netdev(dev);
  11338. if (rc) {
  11339. dev_err(&pdev->dev, "Cannot register net device\n");
  11340. goto init_one_exit;
  11341. }
  11342. BNX2X_DEV_INFO("device name after netdev register %s\n", dev->name);
  11343. if (!NO_FCOE(bp)) {
  11344. /* Add storage MAC address */
  11345. rtnl_lock();
  11346. dev_addr_add(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  11347. rtnl_unlock();
  11348. }
  11349. if (pcie_get_minimum_link(bp->pdev, &pcie_speed, &pcie_width) ||
  11350. pcie_speed == PCI_SPEED_UNKNOWN ||
  11351. pcie_width == PCIE_LNK_WIDTH_UNKNOWN)
  11352. BNX2X_DEV_INFO("Failed to determine PCI Express Bandwidth\n");
  11353. else
  11354. BNX2X_DEV_INFO(
  11355. "%s (%c%d) PCI-E x%d %s found at mem %lx, IRQ %d, node addr %pM\n",
  11356. board_info[ent->driver_data].name,
  11357. (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4),
  11358. pcie_width,
  11359. pcie_speed == PCIE_SPEED_2_5GT ? "2.5GHz" :
  11360. pcie_speed == PCIE_SPEED_5_0GT ? "5.0GHz" :
  11361. pcie_speed == PCIE_SPEED_8_0GT ? "8.0GHz" :
  11362. "Unknown",
  11363. dev->base_addr, bp->pdev->irq, dev->dev_addr);
  11364. bnx2x_register_phc(bp);
  11365. return 0;
  11366. init_one_exit:
  11367. bnx2x_disable_pcie_error_reporting(bp);
  11368. if (bp->regview)
  11369. iounmap(bp->regview);
  11370. if (IS_PF(bp) && bp->doorbells)
  11371. iounmap(bp->doorbells);
  11372. free_netdev(dev);
  11373. if (atomic_read(&pdev->enable_cnt) == 1)
  11374. pci_release_regions(pdev);
  11375. pci_disable_device(pdev);
  11376. return rc;
  11377. }
  11378. static void __bnx2x_remove(struct pci_dev *pdev,
  11379. struct net_device *dev,
  11380. struct bnx2x *bp,
  11381. bool remove_netdev)
  11382. {
  11383. if (bp->ptp_clock) {
  11384. ptp_clock_unregister(bp->ptp_clock);
  11385. bp->ptp_clock = NULL;
  11386. }
  11387. /* Delete storage MAC address */
  11388. if (!NO_FCOE(bp)) {
  11389. rtnl_lock();
  11390. dev_addr_del(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  11391. rtnl_unlock();
  11392. }
  11393. #ifdef BCM_DCBNL
  11394. /* Delete app tlvs from dcbnl */
  11395. bnx2x_dcbnl_update_applist(bp, true);
  11396. #endif
  11397. if (IS_PF(bp) &&
  11398. !BP_NOMCP(bp) &&
  11399. (bp->flags & BC_SUPPORTS_RMMOD_CMD))
  11400. bnx2x_fw_command(bp, DRV_MSG_CODE_RMMOD, 0);
  11401. /* Close the interface - either directly or implicitly */
  11402. if (remove_netdev) {
  11403. unregister_netdev(dev);
  11404. } else {
  11405. rtnl_lock();
  11406. dev_close(dev);
  11407. rtnl_unlock();
  11408. }
  11409. bnx2x_iov_remove_one(bp);
  11410. /* Power on: we can't let PCI layer write to us while we are in D3 */
  11411. if (IS_PF(bp)) {
  11412. bnx2x_set_power_state(bp, PCI_D0);
  11413. /* Set endianity registers to reset values in case next driver
  11414. * boots in different endianty environment.
  11415. */
  11416. bnx2x_reset_endianity(bp);
  11417. }
  11418. /* Disable MSI/MSI-X */
  11419. bnx2x_disable_msi(bp);
  11420. /* Power off */
  11421. if (IS_PF(bp))
  11422. bnx2x_set_power_state(bp, PCI_D3hot);
  11423. /* Make sure RESET task is not scheduled before continuing */
  11424. cancel_delayed_work_sync(&bp->sp_rtnl_task);
  11425. /* send message via vfpf channel to release the resources of this vf */
  11426. if (IS_VF(bp))
  11427. bnx2x_vfpf_release(bp);
  11428. /* Assumes no further PCIe PM changes will occur */
  11429. if (system_state == SYSTEM_POWER_OFF) {
  11430. pci_wake_from_d3(pdev, bp->wol);
  11431. pci_set_power_state(pdev, PCI_D3hot);
  11432. }
  11433. bnx2x_disable_pcie_error_reporting(bp);
  11434. if (remove_netdev) {
  11435. if (bp->regview)
  11436. iounmap(bp->regview);
  11437. /* For vfs, doorbells are part of the regview and were unmapped
  11438. * along with it. FW is only loaded by PF.
  11439. */
  11440. if (IS_PF(bp)) {
  11441. if (bp->doorbells)
  11442. iounmap(bp->doorbells);
  11443. bnx2x_release_firmware(bp);
  11444. } else {
  11445. bnx2x_vf_pci_dealloc(bp);
  11446. }
  11447. bnx2x_free_mem_bp(bp);
  11448. free_netdev(dev);
  11449. if (atomic_read(&pdev->enable_cnt) == 1)
  11450. pci_release_regions(pdev);
  11451. pci_disable_device(pdev);
  11452. }
  11453. }
  11454. static void bnx2x_remove_one(struct pci_dev *pdev)
  11455. {
  11456. struct net_device *dev = pci_get_drvdata(pdev);
  11457. struct bnx2x *bp;
  11458. if (!dev) {
  11459. dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n");
  11460. return;
  11461. }
  11462. bp = netdev_priv(dev);
  11463. __bnx2x_remove(pdev, dev, bp, true);
  11464. }
  11465. static int bnx2x_eeh_nic_unload(struct bnx2x *bp)
  11466. {
  11467. bp->state = BNX2X_STATE_CLOSING_WAIT4_HALT;
  11468. bp->rx_mode = BNX2X_RX_MODE_NONE;
  11469. if (CNIC_LOADED(bp))
  11470. bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD);
  11471. /* Stop Tx */
  11472. bnx2x_tx_disable(bp);
  11473. /* Delete all NAPI objects */
  11474. bnx2x_del_all_napi(bp);
  11475. if (CNIC_LOADED(bp))
  11476. bnx2x_del_all_napi_cnic(bp);
  11477. netdev_reset_tc(bp->dev);
  11478. del_timer_sync(&bp->timer);
  11479. cancel_delayed_work_sync(&bp->sp_task);
  11480. cancel_delayed_work_sync(&bp->period_task);
  11481. spin_lock_bh(&bp->stats_lock);
  11482. bp->stats_state = STATS_STATE_DISABLED;
  11483. spin_unlock_bh(&bp->stats_lock);
  11484. bnx2x_save_statistics(bp);
  11485. netif_carrier_off(bp->dev);
  11486. return 0;
  11487. }
  11488. /**
  11489. * bnx2x_io_error_detected - called when PCI error is detected
  11490. * @pdev: Pointer to PCI device
  11491. * @state: The current pci connection state
  11492. *
  11493. * This function is called after a PCI bus error affecting
  11494. * this device has been detected.
  11495. */
  11496. static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev,
  11497. pci_channel_state_t state)
  11498. {
  11499. struct net_device *dev = pci_get_drvdata(pdev);
  11500. struct bnx2x *bp = netdev_priv(dev);
  11501. rtnl_lock();
  11502. BNX2X_ERR("IO error detected\n");
  11503. netif_device_detach(dev);
  11504. if (state == pci_channel_io_perm_failure) {
  11505. rtnl_unlock();
  11506. return PCI_ERS_RESULT_DISCONNECT;
  11507. }
  11508. if (netif_running(dev))
  11509. bnx2x_eeh_nic_unload(bp);
  11510. bnx2x_prev_path_mark_eeh(bp);
  11511. pci_disable_device(pdev);
  11512. rtnl_unlock();
  11513. /* Request a slot reset */
  11514. return PCI_ERS_RESULT_NEED_RESET;
  11515. }
  11516. /**
  11517. * bnx2x_io_slot_reset - called after the PCI bus has been reset
  11518. * @pdev: Pointer to PCI device
  11519. *
  11520. * Restart the card from scratch, as if from a cold-boot.
  11521. */
  11522. static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev)
  11523. {
  11524. struct net_device *dev = pci_get_drvdata(pdev);
  11525. struct bnx2x *bp = netdev_priv(dev);
  11526. int i;
  11527. rtnl_lock();
  11528. BNX2X_ERR("IO slot reset initializing...\n");
  11529. if (pci_enable_device(pdev)) {
  11530. dev_err(&pdev->dev,
  11531. "Cannot re-enable PCI device after reset\n");
  11532. rtnl_unlock();
  11533. return PCI_ERS_RESULT_DISCONNECT;
  11534. }
  11535. pci_set_master(pdev);
  11536. pci_restore_state(pdev);
  11537. pci_save_state(pdev);
  11538. if (netif_running(dev))
  11539. bnx2x_set_power_state(bp, PCI_D0);
  11540. if (netif_running(dev)) {
  11541. BNX2X_ERR("IO slot reset --> driver unload\n");
  11542. /* MCP should have been reset; Need to wait for validity */
  11543. bnx2x_init_shmem(bp);
  11544. if (IS_PF(bp) && SHMEM2_HAS(bp, drv_capabilities_flag)) {
  11545. u32 v;
  11546. v = SHMEM2_RD(bp,
  11547. drv_capabilities_flag[BP_FW_MB_IDX(bp)]);
  11548. SHMEM2_WR(bp, drv_capabilities_flag[BP_FW_MB_IDX(bp)],
  11549. v & ~DRV_FLAGS_CAPABILITIES_LOADED_L2);
  11550. }
  11551. bnx2x_drain_tx_queues(bp);
  11552. bnx2x_send_unload_req(bp, UNLOAD_RECOVERY);
  11553. bnx2x_netif_stop(bp, 1);
  11554. bnx2x_free_irq(bp);
  11555. /* Report UNLOAD_DONE to MCP */
  11556. bnx2x_send_unload_done(bp, true);
  11557. bp->sp_state = 0;
  11558. bp->port.pmf = 0;
  11559. bnx2x_prev_unload(bp);
  11560. /* We should have reseted the engine, so It's fair to
  11561. * assume the FW will no longer write to the bnx2x driver.
  11562. */
  11563. bnx2x_squeeze_objects(bp);
  11564. bnx2x_free_skbs(bp);
  11565. for_each_rx_queue(bp, i)
  11566. bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
  11567. bnx2x_free_fp_mem(bp);
  11568. bnx2x_free_mem(bp);
  11569. bp->state = BNX2X_STATE_CLOSED;
  11570. }
  11571. rtnl_unlock();
  11572. /* If AER, perform cleanup of the PCIe registers */
  11573. if (bp->flags & AER_ENABLED) {
  11574. if (pci_cleanup_aer_uncorrect_error_status(pdev))
  11575. BNX2X_ERR("pci_cleanup_aer_uncorrect_error_status failed\n");
  11576. else
  11577. DP(NETIF_MSG_HW, "pci_cleanup_aer_uncorrect_error_status succeeded\n");
  11578. }
  11579. return PCI_ERS_RESULT_RECOVERED;
  11580. }
  11581. /**
  11582. * bnx2x_io_resume - called when traffic can start flowing again
  11583. * @pdev: Pointer to PCI device
  11584. *
  11585. * This callback is called when the error recovery driver tells us that
  11586. * its OK to resume normal operation.
  11587. */
  11588. static void bnx2x_io_resume(struct pci_dev *pdev)
  11589. {
  11590. struct net_device *dev = pci_get_drvdata(pdev);
  11591. struct bnx2x *bp = netdev_priv(dev);
  11592. if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
  11593. netdev_err(bp->dev, "Handling parity error recovery. Try again later\n");
  11594. return;
  11595. }
  11596. rtnl_lock();
  11597. bp->fw_seq = SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
  11598. DRV_MSG_SEQ_NUMBER_MASK;
  11599. if (netif_running(dev))
  11600. bnx2x_nic_load(bp, LOAD_NORMAL);
  11601. netif_device_attach(dev);
  11602. rtnl_unlock();
  11603. }
  11604. static const struct pci_error_handlers bnx2x_err_handler = {
  11605. .error_detected = bnx2x_io_error_detected,
  11606. .slot_reset = bnx2x_io_slot_reset,
  11607. .resume = bnx2x_io_resume,
  11608. };
  11609. static void bnx2x_shutdown(struct pci_dev *pdev)
  11610. {
  11611. struct net_device *dev = pci_get_drvdata(pdev);
  11612. struct bnx2x *bp;
  11613. if (!dev)
  11614. return;
  11615. bp = netdev_priv(dev);
  11616. if (!bp)
  11617. return;
  11618. rtnl_lock();
  11619. netif_device_detach(dev);
  11620. rtnl_unlock();
  11621. /* Don't remove the netdevice, as there are scenarios which will cause
  11622. * the kernel to hang, e.g., when trying to remove bnx2i while the
  11623. * rootfs is mounted from SAN.
  11624. */
  11625. __bnx2x_remove(pdev, dev, bp, false);
  11626. }
  11627. static struct pci_driver bnx2x_pci_driver = {
  11628. .name = DRV_MODULE_NAME,
  11629. .id_table = bnx2x_pci_tbl,
  11630. .probe = bnx2x_init_one,
  11631. .remove = bnx2x_remove_one,
  11632. .suspend = bnx2x_suspend,
  11633. .resume = bnx2x_resume,
  11634. .err_handler = &bnx2x_err_handler,
  11635. #ifdef CONFIG_BNX2X_SRIOV
  11636. .sriov_configure = bnx2x_sriov_configure,
  11637. #endif
  11638. .shutdown = bnx2x_shutdown,
  11639. };
  11640. static int __init bnx2x_init(void)
  11641. {
  11642. int ret;
  11643. pr_info("%s", version);
  11644. bnx2x_wq = create_singlethread_workqueue("bnx2x");
  11645. if (bnx2x_wq == NULL) {
  11646. pr_err("Cannot create workqueue\n");
  11647. return -ENOMEM;
  11648. }
  11649. bnx2x_iov_wq = create_singlethread_workqueue("bnx2x_iov");
  11650. if (!bnx2x_iov_wq) {
  11651. pr_err("Cannot create iov workqueue\n");
  11652. destroy_workqueue(bnx2x_wq);
  11653. return -ENOMEM;
  11654. }
  11655. ret = pci_register_driver(&bnx2x_pci_driver);
  11656. if (ret) {
  11657. pr_err("Cannot register driver\n");
  11658. destroy_workqueue(bnx2x_wq);
  11659. destroy_workqueue(bnx2x_iov_wq);
  11660. }
  11661. return ret;
  11662. }
  11663. static void __exit bnx2x_cleanup(void)
  11664. {
  11665. struct list_head *pos, *q;
  11666. pci_unregister_driver(&bnx2x_pci_driver);
  11667. destroy_workqueue(bnx2x_wq);
  11668. destroy_workqueue(bnx2x_iov_wq);
  11669. /* Free globally allocated resources */
  11670. list_for_each_safe(pos, q, &bnx2x_prev_list) {
  11671. struct bnx2x_prev_path_list *tmp =
  11672. list_entry(pos, struct bnx2x_prev_path_list, list);
  11673. list_del(pos);
  11674. kfree(tmp);
  11675. }
  11676. }
  11677. void bnx2x_notify_link_changed(struct bnx2x *bp)
  11678. {
  11679. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + BP_FUNC(bp)*sizeof(u32), 1);
  11680. }
  11681. module_init(bnx2x_init);
  11682. module_exit(bnx2x_cleanup);
  11683. /**
  11684. * bnx2x_set_iscsi_eth_mac_addr - set iSCSI MAC(s).
  11685. *
  11686. * @bp: driver handle
  11687. * @set: set or clear the CAM entry
  11688. *
  11689. * This function will wait until the ramrod completion returns.
  11690. * Return 0 if success, -ENODEV if ramrod doesn't return.
  11691. */
  11692. static int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp)
  11693. {
  11694. unsigned long ramrod_flags = 0;
  11695. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  11696. return bnx2x_set_mac_one(bp, bp->cnic_eth_dev.iscsi_mac,
  11697. &bp->iscsi_l2_mac_obj, true,
  11698. BNX2X_ISCSI_ETH_MAC, &ramrod_flags);
  11699. }
  11700. /* count denotes the number of new completions we have seen */
  11701. static void bnx2x_cnic_sp_post(struct bnx2x *bp, int count)
  11702. {
  11703. struct eth_spe *spe;
  11704. int cxt_index, cxt_offset;
  11705. #ifdef BNX2X_STOP_ON_ERROR
  11706. if (unlikely(bp->panic))
  11707. return;
  11708. #endif
  11709. spin_lock_bh(&bp->spq_lock);
  11710. BUG_ON(bp->cnic_spq_pending < count);
  11711. bp->cnic_spq_pending -= count;
  11712. for (; bp->cnic_kwq_pending; bp->cnic_kwq_pending--) {
  11713. u16 type = (le16_to_cpu(bp->cnic_kwq_cons->hdr.type)
  11714. & SPE_HDR_CONN_TYPE) >>
  11715. SPE_HDR_CONN_TYPE_SHIFT;
  11716. u8 cmd = (le32_to_cpu(bp->cnic_kwq_cons->hdr.conn_and_cmd_data)
  11717. >> SPE_HDR_CMD_ID_SHIFT) & 0xff;
  11718. /* Set validation for iSCSI L2 client before sending SETUP
  11719. * ramrod
  11720. */
  11721. if (type == ETH_CONNECTION_TYPE) {
  11722. if (cmd == RAMROD_CMD_ID_ETH_CLIENT_SETUP) {
  11723. cxt_index = BNX2X_ISCSI_ETH_CID(bp) /
  11724. ILT_PAGE_CIDS;
  11725. cxt_offset = BNX2X_ISCSI_ETH_CID(bp) -
  11726. (cxt_index * ILT_PAGE_CIDS);
  11727. bnx2x_set_ctx_validation(bp,
  11728. &bp->context[cxt_index].
  11729. vcxt[cxt_offset].eth,
  11730. BNX2X_ISCSI_ETH_CID(bp));
  11731. }
  11732. }
  11733. /*
  11734. * There may be not more than 8 L2, not more than 8 L5 SPEs
  11735. * and in the air. We also check that number of outstanding
  11736. * COMMON ramrods is not more than the EQ and SPQ can
  11737. * accommodate.
  11738. */
  11739. if (type == ETH_CONNECTION_TYPE) {
  11740. if (!atomic_read(&bp->cq_spq_left))
  11741. break;
  11742. else
  11743. atomic_dec(&bp->cq_spq_left);
  11744. } else if (type == NONE_CONNECTION_TYPE) {
  11745. if (!atomic_read(&bp->eq_spq_left))
  11746. break;
  11747. else
  11748. atomic_dec(&bp->eq_spq_left);
  11749. } else if ((type == ISCSI_CONNECTION_TYPE) ||
  11750. (type == FCOE_CONNECTION_TYPE)) {
  11751. if (bp->cnic_spq_pending >=
  11752. bp->cnic_eth_dev.max_kwqe_pending)
  11753. break;
  11754. else
  11755. bp->cnic_spq_pending++;
  11756. } else {
  11757. BNX2X_ERR("Unknown SPE type: %d\n", type);
  11758. bnx2x_panic();
  11759. break;
  11760. }
  11761. spe = bnx2x_sp_get_next(bp);
  11762. *spe = *bp->cnic_kwq_cons;
  11763. DP(BNX2X_MSG_SP, "pending on SPQ %d, on KWQ %d count %d\n",
  11764. bp->cnic_spq_pending, bp->cnic_kwq_pending, count);
  11765. if (bp->cnic_kwq_cons == bp->cnic_kwq_last)
  11766. bp->cnic_kwq_cons = bp->cnic_kwq;
  11767. else
  11768. bp->cnic_kwq_cons++;
  11769. }
  11770. bnx2x_sp_prod_update(bp);
  11771. spin_unlock_bh(&bp->spq_lock);
  11772. }
  11773. static int bnx2x_cnic_sp_queue(struct net_device *dev,
  11774. struct kwqe_16 *kwqes[], u32 count)
  11775. {
  11776. struct bnx2x *bp = netdev_priv(dev);
  11777. int i;
  11778. #ifdef BNX2X_STOP_ON_ERROR
  11779. if (unlikely(bp->panic)) {
  11780. BNX2X_ERR("Can't post to SP queue while panic\n");
  11781. return -EIO;
  11782. }
  11783. #endif
  11784. if ((bp->recovery_state != BNX2X_RECOVERY_DONE) &&
  11785. (bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  11786. BNX2X_ERR("Handling parity error recovery. Try again later\n");
  11787. return -EAGAIN;
  11788. }
  11789. spin_lock_bh(&bp->spq_lock);
  11790. for (i = 0; i < count; i++) {
  11791. struct eth_spe *spe = (struct eth_spe *)kwqes[i];
  11792. if (bp->cnic_kwq_pending == MAX_SP_DESC_CNT)
  11793. break;
  11794. *bp->cnic_kwq_prod = *spe;
  11795. bp->cnic_kwq_pending++;
  11796. DP(BNX2X_MSG_SP, "L5 SPQE %x %x %x:%x pos %d\n",
  11797. spe->hdr.conn_and_cmd_data, spe->hdr.type,
  11798. spe->data.update_data_addr.hi,
  11799. spe->data.update_data_addr.lo,
  11800. bp->cnic_kwq_pending);
  11801. if (bp->cnic_kwq_prod == bp->cnic_kwq_last)
  11802. bp->cnic_kwq_prod = bp->cnic_kwq;
  11803. else
  11804. bp->cnic_kwq_prod++;
  11805. }
  11806. spin_unlock_bh(&bp->spq_lock);
  11807. if (bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending)
  11808. bnx2x_cnic_sp_post(bp, 0);
  11809. return i;
  11810. }
  11811. static int bnx2x_cnic_ctl_send(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  11812. {
  11813. struct cnic_ops *c_ops;
  11814. int rc = 0;
  11815. mutex_lock(&bp->cnic_mutex);
  11816. c_ops = rcu_dereference_protected(bp->cnic_ops,
  11817. lockdep_is_held(&bp->cnic_mutex));
  11818. if (c_ops)
  11819. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  11820. mutex_unlock(&bp->cnic_mutex);
  11821. return rc;
  11822. }
  11823. static int bnx2x_cnic_ctl_send_bh(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  11824. {
  11825. struct cnic_ops *c_ops;
  11826. int rc = 0;
  11827. rcu_read_lock();
  11828. c_ops = rcu_dereference(bp->cnic_ops);
  11829. if (c_ops)
  11830. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  11831. rcu_read_unlock();
  11832. return rc;
  11833. }
  11834. /*
  11835. * for commands that have no data
  11836. */
  11837. int bnx2x_cnic_notify(struct bnx2x *bp, int cmd)
  11838. {
  11839. struct cnic_ctl_info ctl = {0};
  11840. ctl.cmd = cmd;
  11841. return bnx2x_cnic_ctl_send(bp, &ctl);
  11842. }
  11843. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err)
  11844. {
  11845. struct cnic_ctl_info ctl = {0};
  11846. /* first we tell CNIC and only then we count this as a completion */
  11847. ctl.cmd = CNIC_CTL_COMPLETION_CMD;
  11848. ctl.data.comp.cid = cid;
  11849. ctl.data.comp.error = err;
  11850. bnx2x_cnic_ctl_send_bh(bp, &ctl);
  11851. bnx2x_cnic_sp_post(bp, 0);
  11852. }
  11853. /* Called with netif_addr_lock_bh() taken.
  11854. * Sets an rx_mode config for an iSCSI ETH client.
  11855. * Doesn't block.
  11856. * Completion should be checked outside.
  11857. */
  11858. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start)
  11859. {
  11860. unsigned long accept_flags = 0, ramrod_flags = 0;
  11861. u8 cl_id = bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  11862. int sched_state = BNX2X_FILTER_ISCSI_ETH_STOP_SCHED;
  11863. if (start) {
  11864. /* Start accepting on iSCSI L2 ring. Accept all multicasts
  11865. * because it's the only way for UIO Queue to accept
  11866. * multicasts (in non-promiscuous mode only one Queue per
  11867. * function will receive multicast packets (leading in our
  11868. * case).
  11869. */
  11870. __set_bit(BNX2X_ACCEPT_UNICAST, &accept_flags);
  11871. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept_flags);
  11872. __set_bit(BNX2X_ACCEPT_BROADCAST, &accept_flags);
  11873. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags);
  11874. /* Clear STOP_PENDING bit if START is requested */
  11875. clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &bp->sp_state);
  11876. sched_state = BNX2X_FILTER_ISCSI_ETH_START_SCHED;
  11877. } else
  11878. /* Clear START_PENDING bit if STOP is requested */
  11879. clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &bp->sp_state);
  11880. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  11881. set_bit(sched_state, &bp->sp_state);
  11882. else {
  11883. __set_bit(RAMROD_RX, &ramrod_flags);
  11884. bnx2x_set_q_rx_mode(bp, cl_id, 0, accept_flags, 0,
  11885. ramrod_flags);
  11886. }
  11887. }
  11888. static int bnx2x_drv_ctl(struct net_device *dev, struct drv_ctl_info *ctl)
  11889. {
  11890. struct bnx2x *bp = netdev_priv(dev);
  11891. int rc = 0;
  11892. switch (ctl->cmd) {
  11893. case DRV_CTL_CTXTBL_WR_CMD: {
  11894. u32 index = ctl->data.io.offset;
  11895. dma_addr_t addr = ctl->data.io.dma_addr;
  11896. bnx2x_ilt_wr(bp, index, addr);
  11897. break;
  11898. }
  11899. case DRV_CTL_RET_L5_SPQ_CREDIT_CMD: {
  11900. int count = ctl->data.credit.credit_count;
  11901. bnx2x_cnic_sp_post(bp, count);
  11902. break;
  11903. }
  11904. /* rtnl_lock is held. */
  11905. case DRV_CTL_START_L2_CMD: {
  11906. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11907. unsigned long sp_bits = 0;
  11908. /* Configure the iSCSI classification object */
  11909. bnx2x_init_mac_obj(bp, &bp->iscsi_l2_mac_obj,
  11910. cp->iscsi_l2_client_id,
  11911. cp->iscsi_l2_cid, BP_FUNC(bp),
  11912. bnx2x_sp(bp, mac_rdata),
  11913. bnx2x_sp_mapping(bp, mac_rdata),
  11914. BNX2X_FILTER_MAC_PENDING,
  11915. &bp->sp_state, BNX2X_OBJ_TYPE_RX,
  11916. &bp->macs_pool);
  11917. /* Set iSCSI MAC address */
  11918. rc = bnx2x_set_iscsi_eth_mac_addr(bp);
  11919. if (rc)
  11920. break;
  11921. mmiowb();
  11922. barrier();
  11923. /* Start accepting on iSCSI L2 ring */
  11924. netif_addr_lock_bh(dev);
  11925. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  11926. netif_addr_unlock_bh(dev);
  11927. /* bits to wait on */
  11928. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  11929. __set_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &sp_bits);
  11930. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  11931. BNX2X_ERR("rx_mode completion timed out!\n");
  11932. break;
  11933. }
  11934. /* rtnl_lock is held. */
  11935. case DRV_CTL_STOP_L2_CMD: {
  11936. unsigned long sp_bits = 0;
  11937. /* Stop accepting on iSCSI L2 ring */
  11938. netif_addr_lock_bh(dev);
  11939. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  11940. netif_addr_unlock_bh(dev);
  11941. /* bits to wait on */
  11942. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  11943. __set_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &sp_bits);
  11944. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  11945. BNX2X_ERR("rx_mode completion timed out!\n");
  11946. mmiowb();
  11947. barrier();
  11948. /* Unset iSCSI L2 MAC */
  11949. rc = bnx2x_del_all_macs(bp, &bp->iscsi_l2_mac_obj,
  11950. BNX2X_ISCSI_ETH_MAC, true);
  11951. break;
  11952. }
  11953. case DRV_CTL_RET_L2_SPQ_CREDIT_CMD: {
  11954. int count = ctl->data.credit.credit_count;
  11955. smp_mb__before_atomic();
  11956. atomic_add(count, &bp->cq_spq_left);
  11957. smp_mb__after_atomic();
  11958. break;
  11959. }
  11960. case DRV_CTL_ULP_REGISTER_CMD: {
  11961. int ulp_type = ctl->data.register_data.ulp_type;
  11962. if (CHIP_IS_E3(bp)) {
  11963. int idx = BP_FW_MB_IDX(bp);
  11964. u32 cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  11965. int path = BP_PATH(bp);
  11966. int port = BP_PORT(bp);
  11967. int i;
  11968. u32 scratch_offset;
  11969. u32 *host_addr;
  11970. /* first write capability to shmem2 */
  11971. if (ulp_type == CNIC_ULP_ISCSI)
  11972. cap |= DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  11973. else if (ulp_type == CNIC_ULP_FCOE)
  11974. cap |= DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  11975. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  11976. if ((ulp_type != CNIC_ULP_FCOE) ||
  11977. (!SHMEM2_HAS(bp, ncsi_oem_data_addr)) ||
  11978. (!(bp->flags & BC_SUPPORTS_FCOE_FEATURES)))
  11979. break;
  11980. /* if reached here - should write fcoe capabilities */
  11981. scratch_offset = SHMEM2_RD(bp, ncsi_oem_data_addr);
  11982. if (!scratch_offset)
  11983. break;
  11984. scratch_offset += offsetof(struct glob_ncsi_oem_data,
  11985. fcoe_features[path][port]);
  11986. host_addr = (u32 *) &(ctl->data.register_data.
  11987. fcoe_features);
  11988. for (i = 0; i < sizeof(struct fcoe_capabilities);
  11989. i += 4)
  11990. REG_WR(bp, scratch_offset + i,
  11991. *(host_addr + i/4));
  11992. }
  11993. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_GET_DRV_VERSION, 0);
  11994. break;
  11995. }
  11996. case DRV_CTL_ULP_UNREGISTER_CMD: {
  11997. int ulp_type = ctl->data.ulp_type;
  11998. if (CHIP_IS_E3(bp)) {
  11999. int idx = BP_FW_MB_IDX(bp);
  12000. u32 cap;
  12001. cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  12002. if (ulp_type == CNIC_ULP_ISCSI)
  12003. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  12004. else if (ulp_type == CNIC_ULP_FCOE)
  12005. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  12006. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  12007. }
  12008. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_GET_DRV_VERSION, 0);
  12009. break;
  12010. }
  12011. default:
  12012. BNX2X_ERR("unknown command %x\n", ctl->cmd);
  12013. rc = -EINVAL;
  12014. }
  12015. return rc;
  12016. }
  12017. void bnx2x_setup_cnic_irq_info(struct bnx2x *bp)
  12018. {
  12019. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  12020. if (bp->flags & USING_MSIX_FLAG) {
  12021. cp->drv_state |= CNIC_DRV_STATE_USING_MSIX;
  12022. cp->irq_arr[0].irq_flags |= CNIC_IRQ_FL_MSIX;
  12023. cp->irq_arr[0].vector = bp->msix_table[1].vector;
  12024. } else {
  12025. cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX;
  12026. cp->irq_arr[0].irq_flags &= ~CNIC_IRQ_FL_MSIX;
  12027. }
  12028. if (!CHIP_IS_E1x(bp))
  12029. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e2_sb;
  12030. else
  12031. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e1x_sb;
  12032. cp->irq_arr[0].status_blk_num = bnx2x_cnic_fw_sb_id(bp);
  12033. cp->irq_arr[0].status_blk_num2 = bnx2x_cnic_igu_sb_id(bp);
  12034. cp->irq_arr[1].status_blk = bp->def_status_blk;
  12035. cp->irq_arr[1].status_blk_num = DEF_SB_ID;
  12036. cp->irq_arr[1].status_blk_num2 = DEF_SB_IGU_ID;
  12037. cp->num_irq = 2;
  12038. }
  12039. void bnx2x_setup_cnic_info(struct bnx2x *bp)
  12040. {
  12041. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  12042. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  12043. bnx2x_cid_ilt_lines(bp);
  12044. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  12045. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
  12046. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
  12047. DP(NETIF_MSG_IFUP, "BNX2X_1st_NON_L2_ETH_CID(bp) %x, cp->starting_cid %x, cp->fcoe_init_cid %x, cp->iscsi_l2_cid %x\n",
  12048. BNX2X_1st_NON_L2_ETH_CID(bp), cp->starting_cid, cp->fcoe_init_cid,
  12049. cp->iscsi_l2_cid);
  12050. if (NO_ISCSI_OOO(bp))
  12051. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  12052. }
  12053. static int bnx2x_register_cnic(struct net_device *dev, struct cnic_ops *ops,
  12054. void *data)
  12055. {
  12056. struct bnx2x *bp = netdev_priv(dev);
  12057. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  12058. int rc;
  12059. DP(NETIF_MSG_IFUP, "Register_cnic called\n");
  12060. if (ops == NULL) {
  12061. BNX2X_ERR("NULL ops received\n");
  12062. return -EINVAL;
  12063. }
  12064. if (!CNIC_SUPPORT(bp)) {
  12065. BNX2X_ERR("Can't register CNIC when not supported\n");
  12066. return -EOPNOTSUPP;
  12067. }
  12068. if (!CNIC_LOADED(bp)) {
  12069. rc = bnx2x_load_cnic(bp);
  12070. if (rc) {
  12071. BNX2X_ERR("CNIC-related load failed\n");
  12072. return rc;
  12073. }
  12074. }
  12075. bp->cnic_enabled = true;
  12076. bp->cnic_kwq = kzalloc(PAGE_SIZE, GFP_KERNEL);
  12077. if (!bp->cnic_kwq)
  12078. return -ENOMEM;
  12079. bp->cnic_kwq_cons = bp->cnic_kwq;
  12080. bp->cnic_kwq_prod = bp->cnic_kwq;
  12081. bp->cnic_kwq_last = bp->cnic_kwq + MAX_SP_DESC_CNT;
  12082. bp->cnic_spq_pending = 0;
  12083. bp->cnic_kwq_pending = 0;
  12084. bp->cnic_data = data;
  12085. cp->num_irq = 0;
  12086. cp->drv_state |= CNIC_DRV_STATE_REGD;
  12087. cp->iro_arr = bp->iro_arr;
  12088. bnx2x_setup_cnic_irq_info(bp);
  12089. rcu_assign_pointer(bp->cnic_ops, ops);
  12090. /* Schedule driver to read CNIC driver versions */
  12091. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_GET_DRV_VERSION, 0);
  12092. return 0;
  12093. }
  12094. static int bnx2x_unregister_cnic(struct net_device *dev)
  12095. {
  12096. struct bnx2x *bp = netdev_priv(dev);
  12097. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  12098. mutex_lock(&bp->cnic_mutex);
  12099. cp->drv_state = 0;
  12100. RCU_INIT_POINTER(bp->cnic_ops, NULL);
  12101. mutex_unlock(&bp->cnic_mutex);
  12102. synchronize_rcu();
  12103. bp->cnic_enabled = false;
  12104. kfree(bp->cnic_kwq);
  12105. bp->cnic_kwq = NULL;
  12106. return 0;
  12107. }
  12108. static struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev)
  12109. {
  12110. struct bnx2x *bp = netdev_priv(dev);
  12111. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  12112. /* If both iSCSI and FCoE are disabled - return NULL in
  12113. * order to indicate CNIC that it should not try to work
  12114. * with this device.
  12115. */
  12116. if (NO_ISCSI(bp) && NO_FCOE(bp))
  12117. return NULL;
  12118. cp->drv_owner = THIS_MODULE;
  12119. cp->chip_id = CHIP_ID(bp);
  12120. cp->pdev = bp->pdev;
  12121. cp->io_base = bp->regview;
  12122. cp->io_base2 = bp->doorbells;
  12123. cp->max_kwqe_pending = 8;
  12124. cp->ctx_blk_size = CDU_ILT_PAGE_SZ;
  12125. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  12126. bnx2x_cid_ilt_lines(bp);
  12127. cp->ctx_tbl_len = CNIC_ILT_LINES;
  12128. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  12129. cp->drv_submit_kwqes_16 = bnx2x_cnic_sp_queue;
  12130. cp->drv_ctl = bnx2x_drv_ctl;
  12131. cp->drv_register_cnic = bnx2x_register_cnic;
  12132. cp->drv_unregister_cnic = bnx2x_unregister_cnic;
  12133. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
  12134. cp->iscsi_l2_client_id =
  12135. bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  12136. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
  12137. if (NO_ISCSI_OOO(bp))
  12138. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  12139. if (NO_ISCSI(bp))
  12140. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI;
  12141. if (NO_FCOE(bp))
  12142. cp->drv_state |= CNIC_DRV_STATE_NO_FCOE;
  12143. BNX2X_DEV_INFO(
  12144. "page_size %d, tbl_offset %d, tbl_lines %d, starting cid %d\n",
  12145. cp->ctx_blk_size,
  12146. cp->ctx_tbl_offset,
  12147. cp->ctx_tbl_len,
  12148. cp->starting_cid);
  12149. return cp;
  12150. }
  12151. static u32 bnx2x_rx_ustorm_prods_offset(struct bnx2x_fastpath *fp)
  12152. {
  12153. struct bnx2x *bp = fp->bp;
  12154. u32 offset = BAR_USTRORM_INTMEM;
  12155. if (IS_VF(bp))
  12156. return bnx2x_vf_ustorm_prods_offset(bp, fp);
  12157. else if (!CHIP_IS_E1x(bp))
  12158. offset += USTORM_RX_PRODS_E2_OFFSET(fp->cl_qzone_id);
  12159. else
  12160. offset += USTORM_RX_PRODS_E1X_OFFSET(BP_PORT(bp), fp->cl_id);
  12161. return offset;
  12162. }
  12163. /* called only on E1H or E2.
  12164. * When pretending to be PF, the pretend value is the function number 0...7
  12165. * When pretending to be VF, the pretend val is the PF-num:VF-valid:ABS-VFID
  12166. * combination
  12167. */
  12168. int bnx2x_pretend_func(struct bnx2x *bp, u16 pretend_func_val)
  12169. {
  12170. u32 pretend_reg;
  12171. if (CHIP_IS_E1H(bp) && pretend_func_val >= E1H_FUNC_MAX)
  12172. return -1;
  12173. /* get my own pretend register */
  12174. pretend_reg = bnx2x_get_pretend_reg(bp);
  12175. REG_WR(bp, pretend_reg, pretend_func_val);
  12176. REG_RD(bp, pretend_reg);
  12177. return 0;
  12178. }
  12179. static void bnx2x_ptp_task(struct work_struct *work)
  12180. {
  12181. struct bnx2x *bp = container_of(work, struct bnx2x, ptp_task);
  12182. int port = BP_PORT(bp);
  12183. u32 val_seq;
  12184. u64 timestamp, ns;
  12185. struct skb_shared_hwtstamps shhwtstamps;
  12186. /* Read Tx timestamp registers */
  12187. val_seq = REG_RD(bp, port ? NIG_REG_P1_TLLH_PTP_BUF_SEQID :
  12188. NIG_REG_P0_TLLH_PTP_BUF_SEQID);
  12189. if (val_seq & 0x10000) {
  12190. /* There is a valid timestamp value */
  12191. timestamp = REG_RD(bp, port ? NIG_REG_P1_TLLH_PTP_BUF_TS_MSB :
  12192. NIG_REG_P0_TLLH_PTP_BUF_TS_MSB);
  12193. timestamp <<= 32;
  12194. timestamp |= REG_RD(bp, port ? NIG_REG_P1_TLLH_PTP_BUF_TS_LSB :
  12195. NIG_REG_P0_TLLH_PTP_BUF_TS_LSB);
  12196. /* Reset timestamp register to allow new timestamp */
  12197. REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_BUF_SEQID :
  12198. NIG_REG_P0_TLLH_PTP_BUF_SEQID, 0x10000);
  12199. ns = timecounter_cyc2time(&bp->timecounter, timestamp);
  12200. memset(&shhwtstamps, 0, sizeof(shhwtstamps));
  12201. shhwtstamps.hwtstamp = ns_to_ktime(ns);
  12202. skb_tstamp_tx(bp->ptp_tx_skb, &shhwtstamps);
  12203. dev_kfree_skb_any(bp->ptp_tx_skb);
  12204. bp->ptp_tx_skb = NULL;
  12205. DP(BNX2X_MSG_PTP, "Tx timestamp, timestamp cycles = %llu, ns = %llu\n",
  12206. timestamp, ns);
  12207. } else {
  12208. DP(BNX2X_MSG_PTP, "There is no valid Tx timestamp yet\n");
  12209. /* Reschedule to keep checking for a valid timestamp value */
  12210. schedule_work(&bp->ptp_task);
  12211. }
  12212. }
  12213. void bnx2x_set_rx_ts(struct bnx2x *bp, struct sk_buff *skb)
  12214. {
  12215. int port = BP_PORT(bp);
  12216. u64 timestamp, ns;
  12217. timestamp = REG_RD(bp, port ? NIG_REG_P1_LLH_PTP_HOST_BUF_TS_MSB :
  12218. NIG_REG_P0_LLH_PTP_HOST_BUF_TS_MSB);
  12219. timestamp <<= 32;
  12220. timestamp |= REG_RD(bp, port ? NIG_REG_P1_LLH_PTP_HOST_BUF_TS_LSB :
  12221. NIG_REG_P0_LLH_PTP_HOST_BUF_TS_LSB);
  12222. /* Reset timestamp register to allow new timestamp */
  12223. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_HOST_BUF_SEQID :
  12224. NIG_REG_P0_LLH_PTP_HOST_BUF_SEQID, 0x10000);
  12225. ns = timecounter_cyc2time(&bp->timecounter, timestamp);
  12226. skb_hwtstamps(skb)->hwtstamp = ns_to_ktime(ns);
  12227. DP(BNX2X_MSG_PTP, "Rx timestamp, timestamp cycles = %llu, ns = %llu\n",
  12228. timestamp, ns);
  12229. }
  12230. /* Read the PHC */
  12231. static cycle_t bnx2x_cyclecounter_read(const struct cyclecounter *cc)
  12232. {
  12233. struct bnx2x *bp = container_of(cc, struct bnx2x, cyclecounter);
  12234. int port = BP_PORT(bp);
  12235. u32 wb_data[2];
  12236. u64 phc_cycles;
  12237. REG_RD_DMAE(bp, port ? NIG_REG_TIMESYNC_GEN_REG + tsgen_synctime_t1 :
  12238. NIG_REG_TIMESYNC_GEN_REG + tsgen_synctime_t0, wb_data, 2);
  12239. phc_cycles = wb_data[1];
  12240. phc_cycles = (phc_cycles << 32) + wb_data[0];
  12241. DP(BNX2X_MSG_PTP, "PHC read cycles = %llu\n", phc_cycles);
  12242. return phc_cycles;
  12243. }
  12244. static void bnx2x_init_cyclecounter(struct bnx2x *bp)
  12245. {
  12246. memset(&bp->cyclecounter, 0, sizeof(bp->cyclecounter));
  12247. bp->cyclecounter.read = bnx2x_cyclecounter_read;
  12248. bp->cyclecounter.mask = CLOCKSOURCE_MASK(64);
  12249. bp->cyclecounter.shift = 1;
  12250. bp->cyclecounter.mult = 1;
  12251. }
  12252. static int bnx2x_send_reset_timesync_ramrod(struct bnx2x *bp)
  12253. {
  12254. struct bnx2x_func_state_params func_params = {NULL};
  12255. struct bnx2x_func_set_timesync_params *set_timesync_params =
  12256. &func_params.params.set_timesync;
  12257. /* Prepare parameters for function state transitions */
  12258. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  12259. __set_bit(RAMROD_RETRY, &func_params.ramrod_flags);
  12260. func_params.f_obj = &bp->func_obj;
  12261. func_params.cmd = BNX2X_F_CMD_SET_TIMESYNC;
  12262. /* Function parameters */
  12263. set_timesync_params->drift_adjust_cmd = TS_DRIFT_ADJUST_RESET;
  12264. set_timesync_params->offset_cmd = TS_OFFSET_KEEP;
  12265. return bnx2x_func_state_change(bp, &func_params);
  12266. }
  12267. int bnx2x_enable_ptp_packets(struct bnx2x *bp)
  12268. {
  12269. struct bnx2x_queue_state_params q_params;
  12270. int rc, i;
  12271. /* send queue update ramrod to enable PTP packets */
  12272. memset(&q_params, 0, sizeof(q_params));
  12273. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  12274. q_params.cmd = BNX2X_Q_CMD_UPDATE;
  12275. __set_bit(BNX2X_Q_UPDATE_PTP_PKTS_CHNG,
  12276. &q_params.params.update.update_flags);
  12277. __set_bit(BNX2X_Q_UPDATE_PTP_PKTS,
  12278. &q_params.params.update.update_flags);
  12279. /* send the ramrod on all the queues of the PF */
  12280. for_each_eth_queue(bp, i) {
  12281. struct bnx2x_fastpath *fp = &bp->fp[i];
  12282. /* Set the appropriate Queue object */
  12283. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  12284. /* Update the Queue state */
  12285. rc = bnx2x_queue_state_change(bp, &q_params);
  12286. if (rc) {
  12287. BNX2X_ERR("Failed to enable PTP packets\n");
  12288. return rc;
  12289. }
  12290. }
  12291. return 0;
  12292. }
  12293. int bnx2x_configure_ptp_filters(struct bnx2x *bp)
  12294. {
  12295. int port = BP_PORT(bp);
  12296. int rc;
  12297. if (!bp->hwtstamp_ioctl_called)
  12298. return 0;
  12299. switch (bp->tx_type) {
  12300. case HWTSTAMP_TX_ON:
  12301. bp->flags |= TX_TIMESTAMPING_EN;
  12302. REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_PARAM_MASK :
  12303. NIG_REG_P0_TLLH_PTP_PARAM_MASK, 0x6AA);
  12304. REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_RULE_MASK :
  12305. NIG_REG_P0_TLLH_PTP_RULE_MASK, 0x3EEE);
  12306. break;
  12307. case HWTSTAMP_TX_ONESTEP_SYNC:
  12308. BNX2X_ERR("One-step timestamping is not supported\n");
  12309. return -ERANGE;
  12310. }
  12311. switch (bp->rx_filter) {
  12312. case HWTSTAMP_FILTER_NONE:
  12313. break;
  12314. case HWTSTAMP_FILTER_ALL:
  12315. case HWTSTAMP_FILTER_SOME:
  12316. bp->rx_filter = HWTSTAMP_FILTER_NONE;
  12317. break;
  12318. case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
  12319. case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
  12320. case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
  12321. bp->rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_EVENT;
  12322. /* Initialize PTP detection for UDP/IPv4 events */
  12323. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_PARAM_MASK :
  12324. NIG_REG_P0_LLH_PTP_PARAM_MASK, 0x7EE);
  12325. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_RULE_MASK :
  12326. NIG_REG_P0_LLH_PTP_RULE_MASK, 0x3FFE);
  12327. break;
  12328. case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
  12329. case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
  12330. case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
  12331. bp->rx_filter = HWTSTAMP_FILTER_PTP_V2_L4_EVENT;
  12332. /* Initialize PTP detection for UDP/IPv4 or UDP/IPv6 events */
  12333. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_PARAM_MASK :
  12334. NIG_REG_P0_LLH_PTP_PARAM_MASK, 0x7EA);
  12335. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_RULE_MASK :
  12336. NIG_REG_P0_LLH_PTP_RULE_MASK, 0x3FEE);
  12337. break;
  12338. case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
  12339. case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
  12340. case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
  12341. bp->rx_filter = HWTSTAMP_FILTER_PTP_V2_L2_EVENT;
  12342. /* Initialize PTP detection L2 events */
  12343. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_PARAM_MASK :
  12344. NIG_REG_P0_LLH_PTP_PARAM_MASK, 0x6BF);
  12345. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_RULE_MASK :
  12346. NIG_REG_P0_LLH_PTP_RULE_MASK, 0x3EFF);
  12347. break;
  12348. case HWTSTAMP_FILTER_PTP_V2_EVENT:
  12349. case HWTSTAMP_FILTER_PTP_V2_SYNC:
  12350. case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
  12351. bp->rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
  12352. /* Initialize PTP detection L2, UDP/IPv4 or UDP/IPv6 events */
  12353. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_PARAM_MASK :
  12354. NIG_REG_P0_LLH_PTP_PARAM_MASK, 0x6AA);
  12355. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_RULE_MASK :
  12356. NIG_REG_P0_LLH_PTP_RULE_MASK, 0x3EEE);
  12357. break;
  12358. }
  12359. /* Indicate to FW that this PF expects recorded PTP packets */
  12360. rc = bnx2x_enable_ptp_packets(bp);
  12361. if (rc)
  12362. return rc;
  12363. /* Enable sending PTP packets to host */
  12364. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_TO_HOST :
  12365. NIG_REG_P0_LLH_PTP_TO_HOST, 0x1);
  12366. return 0;
  12367. }
  12368. static int bnx2x_hwtstamp_ioctl(struct bnx2x *bp, struct ifreq *ifr)
  12369. {
  12370. struct hwtstamp_config config;
  12371. int rc;
  12372. DP(BNX2X_MSG_PTP, "HWTSTAMP IOCTL called\n");
  12373. if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
  12374. return -EFAULT;
  12375. DP(BNX2X_MSG_PTP, "Requested tx_type: %d, requested rx_filters = %d\n",
  12376. config.tx_type, config.rx_filter);
  12377. if (config.flags) {
  12378. BNX2X_ERR("config.flags is reserved for future use\n");
  12379. return -EINVAL;
  12380. }
  12381. bp->hwtstamp_ioctl_called = 1;
  12382. bp->tx_type = config.tx_type;
  12383. bp->rx_filter = config.rx_filter;
  12384. rc = bnx2x_configure_ptp_filters(bp);
  12385. if (rc)
  12386. return rc;
  12387. config.rx_filter = bp->rx_filter;
  12388. return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ?
  12389. -EFAULT : 0;
  12390. }
  12391. /* Configrues HW for PTP */
  12392. static int bnx2x_configure_ptp(struct bnx2x *bp)
  12393. {
  12394. int rc, port = BP_PORT(bp);
  12395. u32 wb_data[2];
  12396. /* Reset PTP event detection rules - will be configured in the IOCTL */
  12397. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_PARAM_MASK :
  12398. NIG_REG_P0_LLH_PTP_PARAM_MASK, 0x7FF);
  12399. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_RULE_MASK :
  12400. NIG_REG_P0_LLH_PTP_RULE_MASK, 0x3FFF);
  12401. REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_PARAM_MASK :
  12402. NIG_REG_P0_TLLH_PTP_PARAM_MASK, 0x7FF);
  12403. REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_RULE_MASK :
  12404. NIG_REG_P0_TLLH_PTP_RULE_MASK, 0x3FFF);
  12405. /* Disable PTP packets to host - will be configured in the IOCTL*/
  12406. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_TO_HOST :
  12407. NIG_REG_P0_LLH_PTP_TO_HOST, 0x0);
  12408. /* Enable the PTP feature */
  12409. REG_WR(bp, port ? NIG_REG_P1_PTP_EN :
  12410. NIG_REG_P0_PTP_EN, 0x3F);
  12411. /* Enable the free-running counter */
  12412. wb_data[0] = 0;
  12413. wb_data[1] = 0;
  12414. REG_WR_DMAE(bp, NIG_REG_TIMESYNC_GEN_REG + tsgen_ctrl, wb_data, 2);
  12415. /* Reset drift register (offset register is not reset) */
  12416. rc = bnx2x_send_reset_timesync_ramrod(bp);
  12417. if (rc) {
  12418. BNX2X_ERR("Failed to reset PHC drift register\n");
  12419. return -EFAULT;
  12420. }
  12421. /* Reset possibly old timestamps */
  12422. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_HOST_BUF_SEQID :
  12423. NIG_REG_P0_LLH_PTP_HOST_BUF_SEQID, 0x10000);
  12424. REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_BUF_SEQID :
  12425. NIG_REG_P0_TLLH_PTP_BUF_SEQID, 0x10000);
  12426. return 0;
  12427. }
  12428. /* Called during load, to initialize PTP-related stuff */
  12429. void bnx2x_init_ptp(struct bnx2x *bp)
  12430. {
  12431. int rc;
  12432. /* Configure PTP in HW */
  12433. rc = bnx2x_configure_ptp(bp);
  12434. if (rc) {
  12435. BNX2X_ERR("Stopping PTP initialization\n");
  12436. return;
  12437. }
  12438. /* Init work queue for Tx timestamping */
  12439. INIT_WORK(&bp->ptp_task, bnx2x_ptp_task);
  12440. /* Init cyclecounter and timecounter. This is done only in the first
  12441. * load. If done in every load, PTP application will fail when doing
  12442. * unload / load (e.g. MTU change) while it is running.
  12443. */
  12444. if (!bp->timecounter_init_done) {
  12445. bnx2x_init_cyclecounter(bp);
  12446. timecounter_init(&bp->timecounter, &bp->cyclecounter,
  12447. ktime_to_ns(ktime_get_real()));
  12448. bp->timecounter_init_done = 1;
  12449. }
  12450. DP(BNX2X_MSG_PTP, "PTP initialization ended successfully\n");
  12451. }