bnx2x_main.c 373 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780
  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: Eilon Greenstein <eilong@broadcom.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/init.h>
  29. #include <linux/netdevice.h>
  30. #include <linux/etherdevice.h>
  31. #include <linux/skbuff.h>
  32. #include <linux/dma-mapping.h>
  33. #include <linux/bitops.h>
  34. #include <linux/irq.h>
  35. #include <linux/delay.h>
  36. #include <asm/byteorder.h>
  37. #include <linux/time.h>
  38. #include <linux/ethtool.h>
  39. #include <linux/mii.h>
  40. #include <linux/if_vlan.h>
  41. #include <net/ip.h>
  42. #include <net/ipv6.h>
  43. #include <net/tcp.h>
  44. #include <net/checksum.h>
  45. #include <net/ip6_checksum.h>
  46. #include <linux/workqueue.h>
  47. #include <linux/crc32.h>
  48. #include <linux/crc32c.h>
  49. #include <linux/prefetch.h>
  50. #include <linux/zlib.h>
  51. #include <linux/io.h>
  52. #include <linux/semaphore.h>
  53. #include <linux/stringify.h>
  54. #include <linux/vmalloc.h>
  55. #include "bnx2x.h"
  56. #include "bnx2x_init.h"
  57. #include "bnx2x_init_ops.h"
  58. #include "bnx2x_cmn.h"
  59. #include "bnx2x_vfpf.h"
  60. #include "bnx2x_dcb.h"
  61. #include "bnx2x_sp.h"
  62. #include <linux/firmware.h>
  63. #include "bnx2x_fw_file_hdr.h"
  64. /* FW files */
  65. #define FW_FILE_VERSION \
  66. __stringify(BCM_5710_FW_MAJOR_VERSION) "." \
  67. __stringify(BCM_5710_FW_MINOR_VERSION) "." \
  68. __stringify(BCM_5710_FW_REVISION_VERSION) "." \
  69. __stringify(BCM_5710_FW_ENGINEERING_VERSION)
  70. #define FW_FILE_NAME_E1 "bnx2x/bnx2x-e1-" FW_FILE_VERSION ".fw"
  71. #define FW_FILE_NAME_E1H "bnx2x/bnx2x-e1h-" FW_FILE_VERSION ".fw"
  72. #define FW_FILE_NAME_E2 "bnx2x/bnx2x-e2-" FW_FILE_VERSION ".fw"
  73. /* Time in jiffies before concluding the transmitter is hung */
  74. #define TX_TIMEOUT (5*HZ)
  75. static char version[] =
  76. "Broadcom NetXtreme II 5771x/578xx 10/20-Gigabit Ethernet Driver "
  77. DRV_MODULE_NAME " " DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
  78. MODULE_AUTHOR("Eliezer Tamir");
  79. MODULE_DESCRIPTION("Broadcom NetXtreme II "
  80. "BCM57710/57711/57711E/"
  81. "57712/57712_MF/57800/57800_MF/57810/57810_MF/"
  82. "57840/57840_MF Driver");
  83. MODULE_LICENSE("GPL");
  84. MODULE_VERSION(DRV_MODULE_VERSION);
  85. MODULE_FIRMWARE(FW_FILE_NAME_E1);
  86. MODULE_FIRMWARE(FW_FILE_NAME_E1H);
  87. MODULE_FIRMWARE(FW_FILE_NAME_E2);
  88. int num_queues;
  89. module_param(num_queues, int, 0);
  90. MODULE_PARM_DESC(num_queues,
  91. " Set number of queues (default is as a number of CPUs)");
  92. static int disable_tpa;
  93. module_param(disable_tpa, int, 0);
  94. MODULE_PARM_DESC(disable_tpa, " Disable the TPA (LRO) feature");
  95. int int_mode;
  96. module_param(int_mode, int, 0);
  97. MODULE_PARM_DESC(int_mode, " Force interrupt mode other than MSI-X "
  98. "(1 INT#x; 2 MSI)");
  99. static int dropless_fc;
  100. module_param(dropless_fc, int, 0);
  101. MODULE_PARM_DESC(dropless_fc, " Pause on exhausted host ring");
  102. static int mrrs = -1;
  103. module_param(mrrs, int, 0);
  104. MODULE_PARM_DESC(mrrs, " Force Max Read Req Size (0..3) (for debug)");
  105. static int debug;
  106. module_param(debug, int, 0);
  107. MODULE_PARM_DESC(debug, " Default debug msglevel");
  108. struct workqueue_struct *bnx2x_wq;
  109. struct bnx2x_mac_vals {
  110. u32 xmac_addr;
  111. u32 xmac_val;
  112. u32 emac_addr;
  113. u32 emac_val;
  114. u32 umac_addr;
  115. u32 umac_val;
  116. u32 bmac_addr;
  117. u32 bmac_val[2];
  118. };
  119. enum bnx2x_board_type {
  120. BCM57710 = 0,
  121. BCM57711,
  122. BCM57711E,
  123. BCM57712,
  124. BCM57712_MF,
  125. BCM57712_VF,
  126. BCM57800,
  127. BCM57800_MF,
  128. BCM57800_VF,
  129. BCM57810,
  130. BCM57810_MF,
  131. BCM57810_VF,
  132. BCM57840_4_10,
  133. BCM57840_2_20,
  134. BCM57840_MF,
  135. BCM57840_VF,
  136. BCM57811,
  137. BCM57811_MF,
  138. BCM57840_O,
  139. BCM57840_MFO,
  140. BCM57811_VF
  141. };
  142. /* indexed by board_type, above */
  143. static struct {
  144. char *name;
  145. } board_info[] = {
  146. [BCM57710] = { "Broadcom NetXtreme II BCM57710 10 Gigabit PCIe [Everest]" },
  147. [BCM57711] = { "Broadcom NetXtreme II BCM57711 10 Gigabit PCIe" },
  148. [BCM57711E] = { "Broadcom NetXtreme II BCM57711E 10 Gigabit PCIe" },
  149. [BCM57712] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet" },
  150. [BCM57712_MF] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Multi Function" },
  151. [BCM57712_VF] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Virtual Function" },
  152. [BCM57800] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet" },
  153. [BCM57800_MF] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Multi Function" },
  154. [BCM57800_VF] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Virtual Function" },
  155. [BCM57810] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet" },
  156. [BCM57810_MF] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Multi Function" },
  157. [BCM57810_VF] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Virtual Function" },
  158. [BCM57840_4_10] = { "Broadcom NetXtreme II BCM57840 10 Gigabit Ethernet" },
  159. [BCM57840_2_20] = { "Broadcom NetXtreme II BCM57840 20 Gigabit Ethernet" },
  160. [BCM57840_MF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function" },
  161. [BCM57840_VF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Virtual Function" },
  162. [BCM57811] = { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet" },
  163. [BCM57811_MF] = { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet Multi Function" },
  164. [BCM57840_O] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet" },
  165. [BCM57840_MFO] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function" },
  166. [BCM57811_VF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Virtual Function" }
  167. };
  168. #ifndef PCI_DEVICE_ID_NX2_57710
  169. #define PCI_DEVICE_ID_NX2_57710 CHIP_NUM_57710
  170. #endif
  171. #ifndef PCI_DEVICE_ID_NX2_57711
  172. #define PCI_DEVICE_ID_NX2_57711 CHIP_NUM_57711
  173. #endif
  174. #ifndef PCI_DEVICE_ID_NX2_57711E
  175. #define PCI_DEVICE_ID_NX2_57711E CHIP_NUM_57711E
  176. #endif
  177. #ifndef PCI_DEVICE_ID_NX2_57712
  178. #define PCI_DEVICE_ID_NX2_57712 CHIP_NUM_57712
  179. #endif
  180. #ifndef PCI_DEVICE_ID_NX2_57712_MF
  181. #define PCI_DEVICE_ID_NX2_57712_MF CHIP_NUM_57712_MF
  182. #endif
  183. #ifndef PCI_DEVICE_ID_NX2_57712_VF
  184. #define PCI_DEVICE_ID_NX2_57712_VF CHIP_NUM_57712_VF
  185. #endif
  186. #ifndef PCI_DEVICE_ID_NX2_57800
  187. #define PCI_DEVICE_ID_NX2_57800 CHIP_NUM_57800
  188. #endif
  189. #ifndef PCI_DEVICE_ID_NX2_57800_MF
  190. #define PCI_DEVICE_ID_NX2_57800_MF CHIP_NUM_57800_MF
  191. #endif
  192. #ifndef PCI_DEVICE_ID_NX2_57800_VF
  193. #define PCI_DEVICE_ID_NX2_57800_VF CHIP_NUM_57800_VF
  194. #endif
  195. #ifndef PCI_DEVICE_ID_NX2_57810
  196. #define PCI_DEVICE_ID_NX2_57810 CHIP_NUM_57810
  197. #endif
  198. #ifndef PCI_DEVICE_ID_NX2_57810_MF
  199. #define PCI_DEVICE_ID_NX2_57810_MF CHIP_NUM_57810_MF
  200. #endif
  201. #ifndef PCI_DEVICE_ID_NX2_57840_O
  202. #define PCI_DEVICE_ID_NX2_57840_O CHIP_NUM_57840_OBSOLETE
  203. #endif
  204. #ifndef PCI_DEVICE_ID_NX2_57810_VF
  205. #define PCI_DEVICE_ID_NX2_57810_VF CHIP_NUM_57810_VF
  206. #endif
  207. #ifndef PCI_DEVICE_ID_NX2_57840_4_10
  208. #define PCI_DEVICE_ID_NX2_57840_4_10 CHIP_NUM_57840_4_10
  209. #endif
  210. #ifndef PCI_DEVICE_ID_NX2_57840_2_20
  211. #define PCI_DEVICE_ID_NX2_57840_2_20 CHIP_NUM_57840_2_20
  212. #endif
  213. #ifndef PCI_DEVICE_ID_NX2_57840_MFO
  214. #define PCI_DEVICE_ID_NX2_57840_MFO CHIP_NUM_57840_MF_OBSOLETE
  215. #endif
  216. #ifndef PCI_DEVICE_ID_NX2_57840_MF
  217. #define PCI_DEVICE_ID_NX2_57840_MF CHIP_NUM_57840_MF
  218. #endif
  219. #ifndef PCI_DEVICE_ID_NX2_57840_VF
  220. #define PCI_DEVICE_ID_NX2_57840_VF CHIP_NUM_57840_VF
  221. #endif
  222. #ifndef PCI_DEVICE_ID_NX2_57811
  223. #define PCI_DEVICE_ID_NX2_57811 CHIP_NUM_57811
  224. #endif
  225. #ifndef PCI_DEVICE_ID_NX2_57811_MF
  226. #define PCI_DEVICE_ID_NX2_57811_MF CHIP_NUM_57811_MF
  227. #endif
  228. #ifndef PCI_DEVICE_ID_NX2_57811_VF
  229. #define PCI_DEVICE_ID_NX2_57811_VF CHIP_NUM_57811_VF
  230. #endif
  231. static DEFINE_PCI_DEVICE_TABLE(bnx2x_pci_tbl) = {
  232. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57710), BCM57710 },
  233. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711), BCM57711 },
  234. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711E), BCM57711E },
  235. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712), BCM57712 },
  236. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_MF), BCM57712_MF },
  237. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_VF), BCM57712_VF },
  238. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800), BCM57800 },
  239. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_MF), BCM57800_MF },
  240. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_VF), BCM57800_VF },
  241. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810), BCM57810 },
  242. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_MF), BCM57810_MF },
  243. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_O), BCM57840_O },
  244. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_4_10), BCM57840_4_10 },
  245. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_2_20), BCM57840_2_20 },
  246. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_VF), BCM57810_VF },
  247. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MFO), BCM57840_MFO },
  248. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MF), BCM57840_MF },
  249. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_VF), BCM57840_VF },
  250. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811), BCM57811 },
  251. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_MF), BCM57811_MF },
  252. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_VF), BCM57811_VF },
  253. { 0 }
  254. };
  255. MODULE_DEVICE_TABLE(pci, bnx2x_pci_tbl);
  256. /* Global resources for unloading a previously loaded device */
  257. #define BNX2X_PREV_WAIT_NEEDED 1
  258. static DEFINE_SEMAPHORE(bnx2x_prev_sem);
  259. static LIST_HEAD(bnx2x_prev_list);
  260. /****************************************************************************
  261. * General service functions
  262. ****************************************************************************/
  263. static void __storm_memset_dma_mapping(struct bnx2x *bp,
  264. u32 addr, dma_addr_t mapping)
  265. {
  266. REG_WR(bp, addr, U64_LO(mapping));
  267. REG_WR(bp, addr + 4, U64_HI(mapping));
  268. }
  269. static void storm_memset_spq_addr(struct bnx2x *bp,
  270. dma_addr_t mapping, u16 abs_fid)
  271. {
  272. u32 addr = XSEM_REG_FAST_MEMORY +
  273. XSTORM_SPQ_PAGE_BASE_OFFSET(abs_fid);
  274. __storm_memset_dma_mapping(bp, addr, mapping);
  275. }
  276. static void storm_memset_vf_to_pf(struct bnx2x *bp, u16 abs_fid,
  277. u16 pf_id)
  278. {
  279. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_VF_TO_PF_OFFSET(abs_fid),
  280. pf_id);
  281. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_VF_TO_PF_OFFSET(abs_fid),
  282. pf_id);
  283. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_VF_TO_PF_OFFSET(abs_fid),
  284. pf_id);
  285. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_VF_TO_PF_OFFSET(abs_fid),
  286. pf_id);
  287. }
  288. static void storm_memset_func_en(struct bnx2x *bp, u16 abs_fid,
  289. u8 enable)
  290. {
  291. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(abs_fid),
  292. enable);
  293. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(abs_fid),
  294. enable);
  295. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(abs_fid),
  296. enable);
  297. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(abs_fid),
  298. enable);
  299. }
  300. static void storm_memset_eq_data(struct bnx2x *bp,
  301. struct event_ring_data *eq_data,
  302. u16 pfid)
  303. {
  304. size_t size = sizeof(struct event_ring_data);
  305. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_DATA_OFFSET(pfid);
  306. __storm_memset_struct(bp, addr, size, (u32 *)eq_data);
  307. }
  308. static void storm_memset_eq_prod(struct bnx2x *bp, u16 eq_prod,
  309. u16 pfid)
  310. {
  311. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_PROD_OFFSET(pfid);
  312. REG_WR16(bp, addr, eq_prod);
  313. }
  314. /* used only at init
  315. * locking is done by mcp
  316. */
  317. static void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val)
  318. {
  319. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  320. pci_write_config_dword(bp->pdev, PCICFG_GRC_DATA, val);
  321. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  322. PCICFG_VENDOR_ID_OFFSET);
  323. }
  324. static u32 bnx2x_reg_rd_ind(struct bnx2x *bp, u32 addr)
  325. {
  326. u32 val;
  327. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  328. pci_read_config_dword(bp->pdev, PCICFG_GRC_DATA, &val);
  329. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  330. PCICFG_VENDOR_ID_OFFSET);
  331. return val;
  332. }
  333. #define DMAE_DP_SRC_GRC "grc src_addr [%08x]"
  334. #define DMAE_DP_SRC_PCI "pci src_addr [%x:%08x]"
  335. #define DMAE_DP_DST_GRC "grc dst_addr [%08x]"
  336. #define DMAE_DP_DST_PCI "pci dst_addr [%x:%08x]"
  337. #define DMAE_DP_DST_NONE "dst_addr [none]"
  338. static void bnx2x_dp_dmae(struct bnx2x *bp,
  339. struct dmae_command *dmae, int msglvl)
  340. {
  341. u32 src_type = dmae->opcode & DMAE_COMMAND_SRC;
  342. int i;
  343. switch (dmae->opcode & DMAE_COMMAND_DST) {
  344. case DMAE_CMD_DST_PCI:
  345. if (src_type == DMAE_CMD_SRC_PCI)
  346. DP(msglvl, "DMAE: opcode 0x%08x\n"
  347. "src [%x:%08x], len [%d*4], dst [%x:%08x]\n"
  348. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  349. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  350. dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
  351. dmae->comp_addr_hi, dmae->comp_addr_lo,
  352. dmae->comp_val);
  353. else
  354. DP(msglvl, "DMAE: opcode 0x%08x\n"
  355. "src [%08x], len [%d*4], dst [%x:%08x]\n"
  356. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  357. dmae->opcode, dmae->src_addr_lo >> 2,
  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. break;
  362. case DMAE_CMD_DST_GRC:
  363. if (src_type == DMAE_CMD_SRC_PCI)
  364. DP(msglvl, "DMAE: opcode 0x%08x\n"
  365. "src [%x:%08x], len [%d*4], dst_addr [%08x]\n"
  366. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  367. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  368. dmae->len, dmae->dst_addr_lo >> 2,
  369. dmae->comp_addr_hi, dmae->comp_addr_lo,
  370. dmae->comp_val);
  371. else
  372. DP(msglvl, "DMAE: opcode 0x%08x\n"
  373. "src [%08x], len [%d*4], dst [%08x]\n"
  374. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  375. dmae->opcode, dmae->src_addr_lo >> 2,
  376. dmae->len, dmae->dst_addr_lo >> 2,
  377. dmae->comp_addr_hi, dmae->comp_addr_lo,
  378. dmae->comp_val);
  379. break;
  380. default:
  381. if (src_type == DMAE_CMD_SRC_PCI)
  382. DP(msglvl, "DMAE: opcode 0x%08x\n"
  383. "src_addr [%x:%08x] len [%d * 4] dst_addr [none]\n"
  384. "comp_addr [%x:%08x] comp_val 0x%08x\n",
  385. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  386. dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
  387. dmae->comp_val);
  388. else
  389. DP(msglvl, "DMAE: opcode 0x%08x\n"
  390. "src_addr [%08x] len [%d * 4] dst_addr [none]\n"
  391. "comp_addr [%x:%08x] comp_val 0x%08x\n",
  392. dmae->opcode, dmae->src_addr_lo >> 2,
  393. dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
  394. dmae->comp_val);
  395. break;
  396. }
  397. for (i = 0; i < (sizeof(struct dmae_command)/4); i++)
  398. DP(msglvl, "DMAE RAW [%02d]: 0x%08x\n",
  399. i, *(((u32 *)dmae) + i));
  400. }
  401. /* copy command into DMAE command memory and set DMAE command go */
  402. void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae, int idx)
  403. {
  404. u32 cmd_offset;
  405. int i;
  406. cmd_offset = (DMAE_REG_CMD_MEM + sizeof(struct dmae_command) * idx);
  407. for (i = 0; i < (sizeof(struct dmae_command)/4); i++) {
  408. REG_WR(bp, cmd_offset + i*4, *(((u32 *)dmae) + i));
  409. }
  410. REG_WR(bp, dmae_reg_go_c[idx], 1);
  411. }
  412. u32 bnx2x_dmae_opcode_add_comp(u32 opcode, u8 comp_type)
  413. {
  414. return opcode | ((comp_type << DMAE_COMMAND_C_DST_SHIFT) |
  415. DMAE_CMD_C_ENABLE);
  416. }
  417. u32 bnx2x_dmae_opcode_clr_src_reset(u32 opcode)
  418. {
  419. return opcode & ~DMAE_CMD_SRC_RESET;
  420. }
  421. u32 bnx2x_dmae_opcode(struct bnx2x *bp, u8 src_type, u8 dst_type,
  422. bool with_comp, u8 comp_type)
  423. {
  424. u32 opcode = 0;
  425. opcode |= ((src_type << DMAE_COMMAND_SRC_SHIFT) |
  426. (dst_type << DMAE_COMMAND_DST_SHIFT));
  427. opcode |= (DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET);
  428. opcode |= (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0);
  429. opcode |= ((BP_VN(bp) << DMAE_CMD_E1HVN_SHIFT) |
  430. (BP_VN(bp) << DMAE_COMMAND_DST_VN_SHIFT));
  431. opcode |= (DMAE_COM_SET_ERR << DMAE_COMMAND_ERR_POLICY_SHIFT);
  432. #ifdef __BIG_ENDIAN
  433. opcode |= DMAE_CMD_ENDIANITY_B_DW_SWAP;
  434. #else
  435. opcode |= DMAE_CMD_ENDIANITY_DW_SWAP;
  436. #endif
  437. if (with_comp)
  438. opcode = bnx2x_dmae_opcode_add_comp(opcode, comp_type);
  439. return opcode;
  440. }
  441. void bnx2x_prep_dmae_with_comp(struct bnx2x *bp,
  442. struct dmae_command *dmae,
  443. u8 src_type, u8 dst_type)
  444. {
  445. memset(dmae, 0, sizeof(struct dmae_command));
  446. /* set the opcode */
  447. dmae->opcode = bnx2x_dmae_opcode(bp, src_type, dst_type,
  448. true, DMAE_COMP_PCI);
  449. /* fill in the completion parameters */
  450. dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp));
  451. dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp));
  452. dmae->comp_val = DMAE_COMP_VAL;
  453. }
  454. /* issue a dmae command over the init-channel and wait for completion */
  455. int bnx2x_issue_dmae_with_comp(struct bnx2x *bp, struct dmae_command *dmae)
  456. {
  457. u32 *wb_comp = bnx2x_sp(bp, wb_comp);
  458. int cnt = CHIP_REV_IS_SLOW(bp) ? (400000) : 4000;
  459. int rc = 0;
  460. bnx2x_dp_dmae(bp, dmae, BNX2X_MSG_DMAE);
  461. /* Lock the dmae channel. Disable BHs to prevent a dead-lock
  462. * as long as this code is called both from syscall context and
  463. * from ndo_set_rx_mode() flow that may be called from BH.
  464. */
  465. spin_lock_bh(&bp->dmae_lock);
  466. /* reset completion */
  467. *wb_comp = 0;
  468. /* post the command on the channel used for initializations */
  469. bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp));
  470. /* wait for completion */
  471. udelay(5);
  472. while ((*wb_comp & ~DMAE_PCI_ERR_FLAG) != DMAE_COMP_VAL) {
  473. if (!cnt ||
  474. (bp->recovery_state != BNX2X_RECOVERY_DONE &&
  475. bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  476. BNX2X_ERR("DMAE timeout!\n");
  477. rc = DMAE_TIMEOUT;
  478. goto unlock;
  479. }
  480. cnt--;
  481. udelay(50);
  482. }
  483. if (*wb_comp & DMAE_PCI_ERR_FLAG) {
  484. BNX2X_ERR("DMAE PCI error!\n");
  485. rc = DMAE_PCI_ERROR;
  486. }
  487. unlock:
  488. spin_unlock_bh(&bp->dmae_lock);
  489. return rc;
  490. }
  491. void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr,
  492. u32 len32)
  493. {
  494. int rc;
  495. struct dmae_command dmae;
  496. if (!bp->dmae_ready) {
  497. u32 *data = bnx2x_sp(bp, wb_data[0]);
  498. if (CHIP_IS_E1(bp))
  499. bnx2x_init_ind_wr(bp, dst_addr, data, len32);
  500. else
  501. bnx2x_init_str_wr(bp, dst_addr, data, len32);
  502. return;
  503. }
  504. /* set opcode and fixed command fields */
  505. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_GRC);
  506. /* fill in addresses and len */
  507. dmae.src_addr_lo = U64_LO(dma_addr);
  508. dmae.src_addr_hi = U64_HI(dma_addr);
  509. dmae.dst_addr_lo = dst_addr >> 2;
  510. dmae.dst_addr_hi = 0;
  511. dmae.len = len32;
  512. /* issue the command and wait for completion */
  513. rc = bnx2x_issue_dmae_with_comp(bp, &dmae);
  514. if (rc) {
  515. BNX2X_ERR("DMAE returned failure %d\n", rc);
  516. bnx2x_panic();
  517. }
  518. }
  519. void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32)
  520. {
  521. int rc;
  522. struct dmae_command dmae;
  523. if (!bp->dmae_ready) {
  524. u32 *data = bnx2x_sp(bp, wb_data[0]);
  525. int i;
  526. if (CHIP_IS_E1(bp))
  527. for (i = 0; i < len32; i++)
  528. data[i] = bnx2x_reg_rd_ind(bp, src_addr + i*4);
  529. else
  530. for (i = 0; i < len32; i++)
  531. data[i] = REG_RD(bp, src_addr + i*4);
  532. return;
  533. }
  534. /* set opcode and fixed command fields */
  535. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_GRC, DMAE_DST_PCI);
  536. /* fill in addresses and len */
  537. dmae.src_addr_lo = src_addr >> 2;
  538. dmae.src_addr_hi = 0;
  539. dmae.dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_data));
  540. dmae.dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_data));
  541. dmae.len = len32;
  542. /* issue the command and wait for completion */
  543. rc = bnx2x_issue_dmae_with_comp(bp, &dmae);
  544. if (rc) {
  545. BNX2X_ERR("DMAE returned failure %d\n", rc);
  546. bnx2x_panic();
  547. }
  548. }
  549. static void bnx2x_write_dmae_phys_len(struct bnx2x *bp, dma_addr_t phys_addr,
  550. u32 addr, u32 len)
  551. {
  552. int dmae_wr_max = DMAE_LEN32_WR_MAX(bp);
  553. int offset = 0;
  554. while (len > dmae_wr_max) {
  555. bnx2x_write_dmae(bp, phys_addr + offset,
  556. addr + offset, dmae_wr_max);
  557. offset += dmae_wr_max * 4;
  558. len -= dmae_wr_max;
  559. }
  560. bnx2x_write_dmae(bp, phys_addr + offset, addr + offset, len);
  561. }
  562. static int bnx2x_mc_assert(struct bnx2x *bp)
  563. {
  564. char last_idx;
  565. int i, rc = 0;
  566. u32 row0, row1, row2, row3;
  567. /* XSTORM */
  568. last_idx = REG_RD8(bp, BAR_XSTRORM_INTMEM +
  569. XSTORM_ASSERT_LIST_INDEX_OFFSET);
  570. if (last_idx)
  571. BNX2X_ERR("XSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  572. /* print the asserts */
  573. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  574. row0 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  575. XSTORM_ASSERT_LIST_OFFSET(i));
  576. row1 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  577. XSTORM_ASSERT_LIST_OFFSET(i) + 4);
  578. row2 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  579. XSTORM_ASSERT_LIST_OFFSET(i) + 8);
  580. row3 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  581. XSTORM_ASSERT_LIST_OFFSET(i) + 12);
  582. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  583. BNX2X_ERR("XSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  584. i, row3, row2, row1, row0);
  585. rc++;
  586. } else {
  587. break;
  588. }
  589. }
  590. /* TSTORM */
  591. last_idx = REG_RD8(bp, BAR_TSTRORM_INTMEM +
  592. TSTORM_ASSERT_LIST_INDEX_OFFSET);
  593. if (last_idx)
  594. BNX2X_ERR("TSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  595. /* print the asserts */
  596. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  597. row0 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  598. TSTORM_ASSERT_LIST_OFFSET(i));
  599. row1 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  600. TSTORM_ASSERT_LIST_OFFSET(i) + 4);
  601. row2 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  602. TSTORM_ASSERT_LIST_OFFSET(i) + 8);
  603. row3 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  604. TSTORM_ASSERT_LIST_OFFSET(i) + 12);
  605. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  606. BNX2X_ERR("TSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  607. i, row3, row2, row1, row0);
  608. rc++;
  609. } else {
  610. break;
  611. }
  612. }
  613. /* CSTORM */
  614. last_idx = REG_RD8(bp, BAR_CSTRORM_INTMEM +
  615. CSTORM_ASSERT_LIST_INDEX_OFFSET);
  616. if (last_idx)
  617. BNX2X_ERR("CSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  618. /* print the asserts */
  619. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  620. row0 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  621. CSTORM_ASSERT_LIST_OFFSET(i));
  622. row1 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  623. CSTORM_ASSERT_LIST_OFFSET(i) + 4);
  624. row2 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  625. CSTORM_ASSERT_LIST_OFFSET(i) + 8);
  626. row3 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  627. CSTORM_ASSERT_LIST_OFFSET(i) + 12);
  628. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  629. BNX2X_ERR("CSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  630. i, row3, row2, row1, row0);
  631. rc++;
  632. } else {
  633. break;
  634. }
  635. }
  636. /* USTORM */
  637. last_idx = REG_RD8(bp, BAR_USTRORM_INTMEM +
  638. USTORM_ASSERT_LIST_INDEX_OFFSET);
  639. if (last_idx)
  640. BNX2X_ERR("USTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  641. /* print the asserts */
  642. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  643. row0 = REG_RD(bp, BAR_USTRORM_INTMEM +
  644. USTORM_ASSERT_LIST_OFFSET(i));
  645. row1 = REG_RD(bp, BAR_USTRORM_INTMEM +
  646. USTORM_ASSERT_LIST_OFFSET(i) + 4);
  647. row2 = REG_RD(bp, BAR_USTRORM_INTMEM +
  648. USTORM_ASSERT_LIST_OFFSET(i) + 8);
  649. row3 = REG_RD(bp, BAR_USTRORM_INTMEM +
  650. USTORM_ASSERT_LIST_OFFSET(i) + 12);
  651. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  652. BNX2X_ERR("USTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  653. i, row3, row2, row1, row0);
  654. rc++;
  655. } else {
  656. break;
  657. }
  658. }
  659. return rc;
  660. }
  661. void bnx2x_fw_dump_lvl(struct bnx2x *bp, const char *lvl)
  662. {
  663. u32 addr, val;
  664. u32 mark, offset;
  665. __be32 data[9];
  666. int word;
  667. u32 trace_shmem_base;
  668. if (BP_NOMCP(bp)) {
  669. BNX2X_ERR("NO MCP - can not dump\n");
  670. return;
  671. }
  672. netdev_printk(lvl, bp->dev, "bc %d.%d.%d\n",
  673. (bp->common.bc_ver & 0xff0000) >> 16,
  674. (bp->common.bc_ver & 0xff00) >> 8,
  675. (bp->common.bc_ver & 0xff));
  676. val = REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER);
  677. if (val == REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER))
  678. BNX2X_ERR("%s" "MCP PC at 0x%x\n", lvl, val);
  679. if (BP_PATH(bp) == 0)
  680. trace_shmem_base = bp->common.shmem_base;
  681. else
  682. trace_shmem_base = SHMEM2_RD(bp, other_shmem_base_addr);
  683. addr = trace_shmem_base - 0x800;
  684. /* validate TRCB signature */
  685. mark = REG_RD(bp, addr);
  686. if (mark != MFW_TRACE_SIGNATURE) {
  687. BNX2X_ERR("Trace buffer signature is missing.");
  688. return ;
  689. }
  690. /* read cyclic buffer pointer */
  691. addr += 4;
  692. mark = REG_RD(bp, addr);
  693. mark = (CHIP_IS_E1x(bp) ? MCP_REG_MCPR_SCRATCH : MCP_A_REG_MCPR_SCRATCH)
  694. + ((mark + 0x3) & ~0x3) - 0x08000000;
  695. printk("%s" "begin fw dump (mark 0x%x)\n", lvl, mark);
  696. printk("%s", lvl);
  697. /* dump buffer after the mark */
  698. for (offset = mark; offset <= trace_shmem_base; offset += 0x8*4) {
  699. for (word = 0; word < 8; word++)
  700. data[word] = htonl(REG_RD(bp, offset + 4*word));
  701. data[8] = 0x0;
  702. pr_cont("%s", (char *)data);
  703. }
  704. /* dump buffer before the mark */
  705. for (offset = addr + 4; offset <= mark; offset += 0x8*4) {
  706. for (word = 0; word < 8; word++)
  707. data[word] = htonl(REG_RD(bp, offset + 4*word));
  708. data[8] = 0x0;
  709. pr_cont("%s", (char *)data);
  710. }
  711. printk("%s" "end of fw dump\n", lvl);
  712. }
  713. static void bnx2x_fw_dump(struct bnx2x *bp)
  714. {
  715. bnx2x_fw_dump_lvl(bp, KERN_ERR);
  716. }
  717. static void bnx2x_hc_int_disable(struct bnx2x *bp)
  718. {
  719. int port = BP_PORT(bp);
  720. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  721. u32 val = REG_RD(bp, addr);
  722. /* in E1 we must use only PCI configuration space to disable
  723. * MSI/MSIX capability
  724. * It's forbidden to disable IGU_PF_CONF_MSI_MSIX_EN in HC block
  725. */
  726. if (CHIP_IS_E1(bp)) {
  727. /* Since IGU_PF_CONF_MSI_MSIX_EN still always on
  728. * Use mask register to prevent from HC sending interrupts
  729. * after we exit the function
  730. */
  731. REG_WR(bp, HC_REG_INT_MASK + port*4, 0);
  732. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  733. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  734. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  735. } else
  736. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  737. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  738. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  739. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  740. DP(NETIF_MSG_IFDOWN,
  741. "write %x to HC %d (addr 0x%x)\n",
  742. val, port, addr);
  743. /* flush all outstanding writes */
  744. mmiowb();
  745. REG_WR(bp, addr, val);
  746. if (REG_RD(bp, addr) != val)
  747. BNX2X_ERR("BUG! Proper val not read from IGU!\n");
  748. }
  749. static void bnx2x_igu_int_disable(struct bnx2x *bp)
  750. {
  751. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  752. val &= ~(IGU_PF_CONF_MSI_MSIX_EN |
  753. IGU_PF_CONF_INT_LINE_EN |
  754. IGU_PF_CONF_ATTN_BIT_EN);
  755. DP(NETIF_MSG_IFDOWN, "write %x to IGU\n", val);
  756. /* flush all outstanding writes */
  757. mmiowb();
  758. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  759. if (REG_RD(bp, IGU_REG_PF_CONFIGURATION) != val)
  760. BNX2X_ERR("BUG! Proper val not read from IGU!\n");
  761. }
  762. static void bnx2x_int_disable(struct bnx2x *bp)
  763. {
  764. if (bp->common.int_block == INT_BLOCK_HC)
  765. bnx2x_hc_int_disable(bp);
  766. else
  767. bnx2x_igu_int_disable(bp);
  768. }
  769. void bnx2x_panic_dump(struct bnx2x *bp, bool disable_int)
  770. {
  771. int i;
  772. u16 j;
  773. struct hc_sp_status_block_data sp_sb_data;
  774. int func = BP_FUNC(bp);
  775. #ifdef BNX2X_STOP_ON_ERROR
  776. u16 start = 0, end = 0;
  777. u8 cos;
  778. #endif
  779. if (disable_int)
  780. bnx2x_int_disable(bp);
  781. bp->stats_state = STATS_STATE_DISABLED;
  782. bp->eth_stats.unrecoverable_error++;
  783. DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n");
  784. BNX2X_ERR("begin crash dump -----------------\n");
  785. /* Indices */
  786. /* Common */
  787. 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",
  788. bp->def_idx, bp->def_att_idx, bp->attn_state,
  789. bp->spq_prod_idx, bp->stats_counter);
  790. BNX2X_ERR("DSB: attn bits(0x%x) ack(0x%x) id(0x%x) idx(0x%x)\n",
  791. bp->def_status_blk->atten_status_block.attn_bits,
  792. bp->def_status_blk->atten_status_block.attn_bits_ack,
  793. bp->def_status_blk->atten_status_block.status_block_id,
  794. bp->def_status_blk->atten_status_block.attn_bits_index);
  795. BNX2X_ERR(" def (");
  796. for (i = 0; i < HC_SP_SB_MAX_INDICES; i++)
  797. pr_cont("0x%x%s",
  798. bp->def_status_blk->sp_sb.index_values[i],
  799. (i == HC_SP_SB_MAX_INDICES - 1) ? ") " : " ");
  800. for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
  801. *((u32 *)&sp_sb_data + i) = REG_RD(bp, BAR_CSTRORM_INTMEM +
  802. CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
  803. i*sizeof(u32));
  804. 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",
  805. sp_sb_data.igu_sb_id,
  806. sp_sb_data.igu_seg_id,
  807. sp_sb_data.p_func.pf_id,
  808. sp_sb_data.p_func.vnic_id,
  809. sp_sb_data.p_func.vf_id,
  810. sp_sb_data.p_func.vf_valid,
  811. sp_sb_data.state);
  812. for_each_eth_queue(bp, i) {
  813. struct bnx2x_fastpath *fp = &bp->fp[i];
  814. int loop;
  815. struct hc_status_block_data_e2 sb_data_e2;
  816. struct hc_status_block_data_e1x sb_data_e1x;
  817. struct hc_status_block_sm *hc_sm_p =
  818. CHIP_IS_E1x(bp) ?
  819. sb_data_e1x.common.state_machine :
  820. sb_data_e2.common.state_machine;
  821. struct hc_index_data *hc_index_p =
  822. CHIP_IS_E1x(bp) ?
  823. sb_data_e1x.index_data :
  824. sb_data_e2.index_data;
  825. u8 data_size, cos;
  826. u32 *sb_data_p;
  827. struct bnx2x_fp_txdata txdata;
  828. /* Rx */
  829. 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",
  830. i, fp->rx_bd_prod, fp->rx_bd_cons,
  831. fp->rx_comp_prod,
  832. fp->rx_comp_cons, le16_to_cpu(*fp->rx_cons_sb));
  833. BNX2X_ERR(" rx_sge_prod(0x%x) last_max_sge(0x%x) fp_hc_idx(0x%x)\n",
  834. fp->rx_sge_prod, fp->last_max_sge,
  835. le16_to_cpu(fp->fp_hc_idx));
  836. /* Tx */
  837. for_each_cos_in_tx_queue(fp, cos)
  838. {
  839. txdata = *fp->txdata_ptr[cos];
  840. 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",
  841. i, txdata.tx_pkt_prod,
  842. txdata.tx_pkt_cons, txdata.tx_bd_prod,
  843. txdata.tx_bd_cons,
  844. le16_to_cpu(*txdata.tx_cons_sb));
  845. }
  846. loop = CHIP_IS_E1x(bp) ?
  847. HC_SB_MAX_INDICES_E1X : HC_SB_MAX_INDICES_E2;
  848. /* host sb data */
  849. if (IS_FCOE_FP(fp))
  850. continue;
  851. BNX2X_ERR(" run indexes (");
  852. for (j = 0; j < HC_SB_MAX_SM; j++)
  853. pr_cont("0x%x%s",
  854. fp->sb_running_index[j],
  855. (j == HC_SB_MAX_SM - 1) ? ")" : " ");
  856. BNX2X_ERR(" indexes (");
  857. for (j = 0; j < loop; j++)
  858. pr_cont("0x%x%s",
  859. fp->sb_index_values[j],
  860. (j == loop - 1) ? ")" : " ");
  861. /* fw sb data */
  862. data_size = CHIP_IS_E1x(bp) ?
  863. sizeof(struct hc_status_block_data_e1x) :
  864. sizeof(struct hc_status_block_data_e2);
  865. data_size /= sizeof(u32);
  866. sb_data_p = CHIP_IS_E1x(bp) ?
  867. (u32 *)&sb_data_e1x :
  868. (u32 *)&sb_data_e2;
  869. /* copy sb data in here */
  870. for (j = 0; j < data_size; j++)
  871. *(sb_data_p + j) = REG_RD(bp, BAR_CSTRORM_INTMEM +
  872. CSTORM_STATUS_BLOCK_DATA_OFFSET(fp->fw_sb_id) +
  873. j * sizeof(u32));
  874. if (!CHIP_IS_E1x(bp)) {
  875. 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",
  876. sb_data_e2.common.p_func.pf_id,
  877. sb_data_e2.common.p_func.vf_id,
  878. sb_data_e2.common.p_func.vf_valid,
  879. sb_data_e2.common.p_func.vnic_id,
  880. sb_data_e2.common.same_igu_sb_1b,
  881. sb_data_e2.common.state);
  882. } else {
  883. 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",
  884. sb_data_e1x.common.p_func.pf_id,
  885. sb_data_e1x.common.p_func.vf_id,
  886. sb_data_e1x.common.p_func.vf_valid,
  887. sb_data_e1x.common.p_func.vnic_id,
  888. sb_data_e1x.common.same_igu_sb_1b,
  889. sb_data_e1x.common.state);
  890. }
  891. /* SB_SMs data */
  892. for (j = 0; j < HC_SB_MAX_SM; j++) {
  893. 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",
  894. j, hc_sm_p[j].__flags,
  895. hc_sm_p[j].igu_sb_id,
  896. hc_sm_p[j].igu_seg_id,
  897. hc_sm_p[j].time_to_expire,
  898. hc_sm_p[j].timer_value);
  899. }
  900. /* Indices data */
  901. for (j = 0; j < loop; j++) {
  902. pr_cont("INDEX[%d] flags (0x%x) timeout (0x%x)\n", j,
  903. hc_index_p[j].flags,
  904. hc_index_p[j].timeout);
  905. }
  906. }
  907. #ifdef BNX2X_STOP_ON_ERROR
  908. /* event queue */
  909. BNX2X_ERR("eq cons %x prod %x\n", bp->eq_cons, bp->eq_prod);
  910. for (i = 0; i < NUM_EQ_DESC; i++) {
  911. u32 *data = (u32 *)&bp->eq_ring[i].message.data;
  912. BNX2X_ERR("event queue [%d]: header: opcode %d, error %d\n",
  913. i, bp->eq_ring[i].message.opcode,
  914. bp->eq_ring[i].message.error);
  915. BNX2X_ERR("data: %x %x %x\n", data[0], data[1], data[2]);
  916. }
  917. /* Rings */
  918. /* Rx */
  919. for_each_valid_rx_queue(bp, i) {
  920. struct bnx2x_fastpath *fp = &bp->fp[i];
  921. start = RX_BD(le16_to_cpu(*fp->rx_cons_sb) - 10);
  922. end = RX_BD(le16_to_cpu(*fp->rx_cons_sb) + 503);
  923. for (j = start; j != end; j = RX_BD(j + 1)) {
  924. u32 *rx_bd = (u32 *)&fp->rx_desc_ring[j];
  925. struct sw_rx_bd *sw_bd = &fp->rx_buf_ring[j];
  926. BNX2X_ERR("fp%d: rx_bd[%x]=[%x:%x] sw_bd=[%p]\n",
  927. i, j, rx_bd[1], rx_bd[0], sw_bd->data);
  928. }
  929. start = RX_SGE(fp->rx_sge_prod);
  930. end = RX_SGE(fp->last_max_sge);
  931. for (j = start; j != end; j = RX_SGE(j + 1)) {
  932. u32 *rx_sge = (u32 *)&fp->rx_sge_ring[j];
  933. struct sw_rx_page *sw_page = &fp->rx_page_ring[j];
  934. BNX2X_ERR("fp%d: rx_sge[%x]=[%x:%x] sw_page=[%p]\n",
  935. i, j, rx_sge[1], rx_sge[0], sw_page->page);
  936. }
  937. start = RCQ_BD(fp->rx_comp_cons - 10);
  938. end = RCQ_BD(fp->rx_comp_cons + 503);
  939. for (j = start; j != end; j = RCQ_BD(j + 1)) {
  940. u32 *cqe = (u32 *)&fp->rx_comp_ring[j];
  941. BNX2X_ERR("fp%d: cqe[%x]=[%x:%x:%x:%x]\n",
  942. i, j, cqe[0], cqe[1], cqe[2], cqe[3]);
  943. }
  944. }
  945. /* Tx */
  946. for_each_valid_tx_queue(bp, i) {
  947. struct bnx2x_fastpath *fp = &bp->fp[i];
  948. for_each_cos_in_tx_queue(fp, cos) {
  949. struct bnx2x_fp_txdata *txdata = fp->txdata_ptr[cos];
  950. start = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) - 10);
  951. end = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) + 245);
  952. for (j = start; j != end; j = TX_BD(j + 1)) {
  953. struct sw_tx_bd *sw_bd =
  954. &txdata->tx_buf_ring[j];
  955. BNX2X_ERR("fp%d: txdata %d, packet[%x]=[%p,%x]\n",
  956. i, cos, j, sw_bd->skb,
  957. sw_bd->first_bd);
  958. }
  959. start = TX_BD(txdata->tx_bd_cons - 10);
  960. end = TX_BD(txdata->tx_bd_cons + 254);
  961. for (j = start; j != end; j = TX_BD(j + 1)) {
  962. u32 *tx_bd = (u32 *)&txdata->tx_desc_ring[j];
  963. BNX2X_ERR("fp%d: txdata %d, tx_bd[%x]=[%x:%x:%x:%x]\n",
  964. i, cos, j, tx_bd[0], tx_bd[1],
  965. tx_bd[2], tx_bd[3]);
  966. }
  967. }
  968. }
  969. #endif
  970. bnx2x_fw_dump(bp);
  971. bnx2x_mc_assert(bp);
  972. BNX2X_ERR("end crash dump -----------------\n");
  973. }
  974. /*
  975. * FLR Support for E2
  976. *
  977. * bnx2x_pf_flr_clnup() is called during nic_load in the per function HW
  978. * initialization.
  979. */
  980. #define FLR_WAIT_USEC 10000 /* 10 milliseconds */
  981. #define FLR_WAIT_INTERVAL 50 /* usec */
  982. #define FLR_POLL_CNT (FLR_WAIT_USEC/FLR_WAIT_INTERVAL) /* 200 */
  983. struct pbf_pN_buf_regs {
  984. int pN;
  985. u32 init_crd;
  986. u32 crd;
  987. u32 crd_freed;
  988. };
  989. struct pbf_pN_cmd_regs {
  990. int pN;
  991. u32 lines_occup;
  992. u32 lines_freed;
  993. };
  994. static void bnx2x_pbf_pN_buf_flushed(struct bnx2x *bp,
  995. struct pbf_pN_buf_regs *regs,
  996. u32 poll_count)
  997. {
  998. u32 init_crd, crd, crd_start, crd_freed, crd_freed_start;
  999. u32 cur_cnt = poll_count;
  1000. crd_freed = crd_freed_start = REG_RD(bp, regs->crd_freed);
  1001. crd = crd_start = REG_RD(bp, regs->crd);
  1002. init_crd = REG_RD(bp, regs->init_crd);
  1003. DP(BNX2X_MSG_SP, "INIT CREDIT[%d] : %x\n", regs->pN, init_crd);
  1004. DP(BNX2X_MSG_SP, "CREDIT[%d] : s:%x\n", regs->pN, crd);
  1005. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: s:%x\n", regs->pN, crd_freed);
  1006. while ((crd != init_crd) && ((u32)SUB_S32(crd_freed, crd_freed_start) <
  1007. (init_crd - crd_start))) {
  1008. if (cur_cnt--) {
  1009. udelay(FLR_WAIT_INTERVAL);
  1010. crd = REG_RD(bp, regs->crd);
  1011. crd_freed = REG_RD(bp, regs->crd_freed);
  1012. } else {
  1013. DP(BNX2X_MSG_SP, "PBF tx buffer[%d] timed out\n",
  1014. regs->pN);
  1015. DP(BNX2X_MSG_SP, "CREDIT[%d] : c:%x\n",
  1016. regs->pN, crd);
  1017. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: c:%x\n",
  1018. regs->pN, crd_freed);
  1019. break;
  1020. }
  1021. }
  1022. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF tx buffer[%d]\n",
  1023. poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
  1024. }
  1025. static void bnx2x_pbf_pN_cmd_flushed(struct bnx2x *bp,
  1026. struct pbf_pN_cmd_regs *regs,
  1027. u32 poll_count)
  1028. {
  1029. u32 occup, to_free, freed, freed_start;
  1030. u32 cur_cnt = poll_count;
  1031. occup = to_free = REG_RD(bp, regs->lines_occup);
  1032. freed = freed_start = REG_RD(bp, regs->lines_freed);
  1033. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n", regs->pN, occup);
  1034. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n", regs->pN, freed);
  1035. while (occup && ((u32)SUB_S32(freed, freed_start) < to_free)) {
  1036. if (cur_cnt--) {
  1037. udelay(FLR_WAIT_INTERVAL);
  1038. occup = REG_RD(bp, regs->lines_occup);
  1039. freed = REG_RD(bp, regs->lines_freed);
  1040. } else {
  1041. DP(BNX2X_MSG_SP, "PBF cmd queue[%d] timed out\n",
  1042. regs->pN);
  1043. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n",
  1044. regs->pN, occup);
  1045. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n",
  1046. regs->pN, freed);
  1047. break;
  1048. }
  1049. }
  1050. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF cmd queue[%d]\n",
  1051. poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
  1052. }
  1053. static u32 bnx2x_flr_clnup_reg_poll(struct bnx2x *bp, u32 reg,
  1054. u32 expected, u32 poll_count)
  1055. {
  1056. u32 cur_cnt = poll_count;
  1057. u32 val;
  1058. while ((val = REG_RD(bp, reg)) != expected && cur_cnt--)
  1059. udelay(FLR_WAIT_INTERVAL);
  1060. return val;
  1061. }
  1062. int bnx2x_flr_clnup_poll_hw_counter(struct bnx2x *bp, u32 reg,
  1063. char *msg, u32 poll_cnt)
  1064. {
  1065. u32 val = bnx2x_flr_clnup_reg_poll(bp, reg, 0, poll_cnt);
  1066. if (val != 0) {
  1067. BNX2X_ERR("%s usage count=%d\n", msg, val);
  1068. return 1;
  1069. }
  1070. return 0;
  1071. }
  1072. /* Common routines with VF FLR cleanup */
  1073. u32 bnx2x_flr_clnup_poll_count(struct bnx2x *bp)
  1074. {
  1075. /* adjust polling timeout */
  1076. if (CHIP_REV_IS_EMUL(bp))
  1077. return FLR_POLL_CNT * 2000;
  1078. if (CHIP_REV_IS_FPGA(bp))
  1079. return FLR_POLL_CNT * 120;
  1080. return FLR_POLL_CNT;
  1081. }
  1082. void bnx2x_tx_hw_flushed(struct bnx2x *bp, u32 poll_count)
  1083. {
  1084. struct pbf_pN_cmd_regs cmd_regs[] = {
  1085. {0, (CHIP_IS_E3B0(bp)) ?
  1086. PBF_REG_TQ_OCCUPANCY_Q0 :
  1087. PBF_REG_P0_TQ_OCCUPANCY,
  1088. (CHIP_IS_E3B0(bp)) ?
  1089. PBF_REG_TQ_LINES_FREED_CNT_Q0 :
  1090. PBF_REG_P0_TQ_LINES_FREED_CNT},
  1091. {1, (CHIP_IS_E3B0(bp)) ?
  1092. PBF_REG_TQ_OCCUPANCY_Q1 :
  1093. PBF_REG_P1_TQ_OCCUPANCY,
  1094. (CHIP_IS_E3B0(bp)) ?
  1095. PBF_REG_TQ_LINES_FREED_CNT_Q1 :
  1096. PBF_REG_P1_TQ_LINES_FREED_CNT},
  1097. {4, (CHIP_IS_E3B0(bp)) ?
  1098. PBF_REG_TQ_OCCUPANCY_LB_Q :
  1099. PBF_REG_P4_TQ_OCCUPANCY,
  1100. (CHIP_IS_E3B0(bp)) ?
  1101. PBF_REG_TQ_LINES_FREED_CNT_LB_Q :
  1102. PBF_REG_P4_TQ_LINES_FREED_CNT}
  1103. };
  1104. struct pbf_pN_buf_regs buf_regs[] = {
  1105. {0, (CHIP_IS_E3B0(bp)) ?
  1106. PBF_REG_INIT_CRD_Q0 :
  1107. PBF_REG_P0_INIT_CRD ,
  1108. (CHIP_IS_E3B0(bp)) ?
  1109. PBF_REG_CREDIT_Q0 :
  1110. PBF_REG_P0_CREDIT,
  1111. (CHIP_IS_E3B0(bp)) ?
  1112. PBF_REG_INTERNAL_CRD_FREED_CNT_Q0 :
  1113. PBF_REG_P0_INTERNAL_CRD_FREED_CNT},
  1114. {1, (CHIP_IS_E3B0(bp)) ?
  1115. PBF_REG_INIT_CRD_Q1 :
  1116. PBF_REG_P1_INIT_CRD,
  1117. (CHIP_IS_E3B0(bp)) ?
  1118. PBF_REG_CREDIT_Q1 :
  1119. PBF_REG_P1_CREDIT,
  1120. (CHIP_IS_E3B0(bp)) ?
  1121. PBF_REG_INTERNAL_CRD_FREED_CNT_Q1 :
  1122. PBF_REG_P1_INTERNAL_CRD_FREED_CNT},
  1123. {4, (CHIP_IS_E3B0(bp)) ?
  1124. PBF_REG_INIT_CRD_LB_Q :
  1125. PBF_REG_P4_INIT_CRD,
  1126. (CHIP_IS_E3B0(bp)) ?
  1127. PBF_REG_CREDIT_LB_Q :
  1128. PBF_REG_P4_CREDIT,
  1129. (CHIP_IS_E3B0(bp)) ?
  1130. PBF_REG_INTERNAL_CRD_FREED_CNT_LB_Q :
  1131. PBF_REG_P4_INTERNAL_CRD_FREED_CNT},
  1132. };
  1133. int i;
  1134. /* Verify the command queues are flushed P0, P1, P4 */
  1135. for (i = 0; i < ARRAY_SIZE(cmd_regs); i++)
  1136. bnx2x_pbf_pN_cmd_flushed(bp, &cmd_regs[i], poll_count);
  1137. /* Verify the transmission buffers are flushed P0, P1, P4 */
  1138. for (i = 0; i < ARRAY_SIZE(buf_regs); i++)
  1139. bnx2x_pbf_pN_buf_flushed(bp, &buf_regs[i], poll_count);
  1140. }
  1141. #define OP_GEN_PARAM(param) \
  1142. (((param) << SDM_OP_GEN_COMP_PARAM_SHIFT) & SDM_OP_GEN_COMP_PARAM)
  1143. #define OP_GEN_TYPE(type) \
  1144. (((type) << SDM_OP_GEN_COMP_TYPE_SHIFT) & SDM_OP_GEN_COMP_TYPE)
  1145. #define OP_GEN_AGG_VECT(index) \
  1146. (((index) << SDM_OP_GEN_AGG_VECT_IDX_SHIFT) & SDM_OP_GEN_AGG_VECT_IDX)
  1147. int bnx2x_send_final_clnup(struct bnx2x *bp, u8 clnup_func, u32 poll_cnt)
  1148. {
  1149. u32 op_gen_command = 0;
  1150. u32 comp_addr = BAR_CSTRORM_INTMEM +
  1151. CSTORM_FINAL_CLEANUP_COMPLETE_OFFSET(clnup_func);
  1152. int ret = 0;
  1153. if (REG_RD(bp, comp_addr)) {
  1154. BNX2X_ERR("Cleanup complete was not 0 before sending\n");
  1155. return 1;
  1156. }
  1157. op_gen_command |= OP_GEN_PARAM(XSTORM_AGG_INT_FINAL_CLEANUP_INDEX);
  1158. op_gen_command |= OP_GEN_TYPE(XSTORM_AGG_INT_FINAL_CLEANUP_COMP_TYPE);
  1159. op_gen_command |= OP_GEN_AGG_VECT(clnup_func);
  1160. op_gen_command |= 1 << SDM_OP_GEN_AGG_VECT_IDX_VALID_SHIFT;
  1161. DP(BNX2X_MSG_SP, "sending FW Final cleanup\n");
  1162. REG_WR(bp, XSDM_REG_OPERATION_GEN, op_gen_command);
  1163. if (bnx2x_flr_clnup_reg_poll(bp, comp_addr, 1, poll_cnt) != 1) {
  1164. BNX2X_ERR("FW final cleanup did not succeed\n");
  1165. DP(BNX2X_MSG_SP, "At timeout completion address contained %x\n",
  1166. (REG_RD(bp, comp_addr)));
  1167. bnx2x_panic();
  1168. return 1;
  1169. }
  1170. /* Zero completion for next FLR */
  1171. REG_WR(bp, comp_addr, 0);
  1172. return ret;
  1173. }
  1174. u8 bnx2x_is_pcie_pending(struct pci_dev *dev)
  1175. {
  1176. u16 status;
  1177. pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status);
  1178. return status & PCI_EXP_DEVSTA_TRPND;
  1179. }
  1180. /* PF FLR specific routines
  1181. */
  1182. static int bnx2x_poll_hw_usage_counters(struct bnx2x *bp, u32 poll_cnt)
  1183. {
  1184. /* wait for CFC PF usage-counter to zero (includes all the VFs) */
  1185. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1186. CFC_REG_NUM_LCIDS_INSIDE_PF,
  1187. "CFC PF usage counter timed out",
  1188. poll_cnt))
  1189. return 1;
  1190. /* Wait for DQ PF usage-counter to zero (until DQ cleanup) */
  1191. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1192. DORQ_REG_PF_USAGE_CNT,
  1193. "DQ PF usage counter timed out",
  1194. poll_cnt))
  1195. return 1;
  1196. /* Wait for QM PF usage-counter to zero (until DQ cleanup) */
  1197. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1198. QM_REG_PF_USG_CNT_0 + 4*BP_FUNC(bp),
  1199. "QM PF usage counter timed out",
  1200. poll_cnt))
  1201. return 1;
  1202. /* Wait for Timer PF usage-counters to zero (until DQ cleanup) */
  1203. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1204. TM_REG_LIN0_VNIC_UC + 4*BP_PORT(bp),
  1205. "Timers VNIC usage counter timed out",
  1206. poll_cnt))
  1207. return 1;
  1208. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1209. TM_REG_LIN0_NUM_SCANS + 4*BP_PORT(bp),
  1210. "Timers NUM_SCANS usage counter timed out",
  1211. poll_cnt))
  1212. return 1;
  1213. /* Wait DMAE PF usage counter to zero */
  1214. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1215. dmae_reg_go_c[INIT_DMAE_C(bp)],
  1216. "DMAE command register timed out",
  1217. poll_cnt))
  1218. return 1;
  1219. return 0;
  1220. }
  1221. static void bnx2x_hw_enable_status(struct bnx2x *bp)
  1222. {
  1223. u32 val;
  1224. val = REG_RD(bp, CFC_REG_WEAK_ENABLE_PF);
  1225. DP(BNX2X_MSG_SP, "CFC_REG_WEAK_ENABLE_PF is 0x%x\n", val);
  1226. val = REG_RD(bp, PBF_REG_DISABLE_PF);
  1227. DP(BNX2X_MSG_SP, "PBF_REG_DISABLE_PF is 0x%x\n", val);
  1228. val = REG_RD(bp, IGU_REG_PCI_PF_MSI_EN);
  1229. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSI_EN is 0x%x\n", val);
  1230. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_EN);
  1231. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_EN is 0x%x\n", val);
  1232. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_FUNC_MASK);
  1233. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_FUNC_MASK is 0x%x\n", val);
  1234. val = REG_RD(bp, PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR);
  1235. DP(BNX2X_MSG_SP, "PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR is 0x%x\n", val);
  1236. val = REG_RD(bp, PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR);
  1237. DP(BNX2X_MSG_SP, "PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR is 0x%x\n", val);
  1238. val = REG_RD(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
  1239. DP(BNX2X_MSG_SP, "PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER is 0x%x\n",
  1240. val);
  1241. }
  1242. static int bnx2x_pf_flr_clnup(struct bnx2x *bp)
  1243. {
  1244. u32 poll_cnt = bnx2x_flr_clnup_poll_count(bp);
  1245. DP(BNX2X_MSG_SP, "Cleanup after FLR PF[%d]\n", BP_ABS_FUNC(bp));
  1246. /* Re-enable PF target read access */
  1247. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  1248. /* Poll HW usage counters */
  1249. DP(BNX2X_MSG_SP, "Polling usage counters\n");
  1250. if (bnx2x_poll_hw_usage_counters(bp, poll_cnt))
  1251. return -EBUSY;
  1252. /* Zero the igu 'trailing edge' and 'leading edge' */
  1253. /* Send the FW cleanup command */
  1254. if (bnx2x_send_final_clnup(bp, (u8)BP_FUNC(bp), poll_cnt))
  1255. return -EBUSY;
  1256. /* ATC cleanup */
  1257. /* Verify TX hw is flushed */
  1258. bnx2x_tx_hw_flushed(bp, poll_cnt);
  1259. /* Wait 100ms (not adjusted according to platform) */
  1260. msleep(100);
  1261. /* Verify no pending pci transactions */
  1262. if (bnx2x_is_pcie_pending(bp->pdev))
  1263. BNX2X_ERR("PCIE Transactions still pending\n");
  1264. /* Debug */
  1265. bnx2x_hw_enable_status(bp);
  1266. /*
  1267. * Master enable - Due to WB DMAE writes performed before this
  1268. * register is re-initialized as part of the regular function init
  1269. */
  1270. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  1271. return 0;
  1272. }
  1273. static void bnx2x_hc_int_enable(struct bnx2x *bp)
  1274. {
  1275. int port = BP_PORT(bp);
  1276. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  1277. u32 val = REG_RD(bp, addr);
  1278. bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
  1279. bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
  1280. bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
  1281. if (msix) {
  1282. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1283. HC_CONFIG_0_REG_INT_LINE_EN_0);
  1284. val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1285. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1286. if (single_msix)
  1287. val |= HC_CONFIG_0_REG_SINGLE_ISR_EN_0;
  1288. } else if (msi) {
  1289. val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0;
  1290. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1291. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1292. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1293. } else {
  1294. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1295. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1296. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  1297. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1298. if (!CHIP_IS_E1(bp)) {
  1299. DP(NETIF_MSG_IFUP,
  1300. "write %x to HC %d (addr 0x%x)\n", val, port, addr);
  1301. REG_WR(bp, addr, val);
  1302. val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0;
  1303. }
  1304. }
  1305. if (CHIP_IS_E1(bp))
  1306. REG_WR(bp, HC_REG_INT_MASK + port*4, 0x1FFFF);
  1307. DP(NETIF_MSG_IFUP,
  1308. "write %x to HC %d (addr 0x%x) mode %s\n", val, port, addr,
  1309. (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1310. REG_WR(bp, addr, val);
  1311. /*
  1312. * Ensure that HC_CONFIG is written before leading/trailing edge config
  1313. */
  1314. mmiowb();
  1315. barrier();
  1316. if (!CHIP_IS_E1(bp)) {
  1317. /* init leading/trailing edge */
  1318. if (IS_MF(bp)) {
  1319. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1320. if (bp->port.pmf)
  1321. /* enable nig and gpio3 attention */
  1322. val |= 0x1100;
  1323. } else
  1324. val = 0xffff;
  1325. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  1326. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  1327. }
  1328. /* Make sure that interrupts are indeed enabled from here on */
  1329. mmiowb();
  1330. }
  1331. static void bnx2x_igu_int_enable(struct bnx2x *bp)
  1332. {
  1333. u32 val;
  1334. bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
  1335. bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
  1336. bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
  1337. val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  1338. if (msix) {
  1339. val &= ~(IGU_PF_CONF_INT_LINE_EN |
  1340. IGU_PF_CONF_SINGLE_ISR_EN);
  1341. val |= (IGU_PF_CONF_MSI_MSIX_EN |
  1342. IGU_PF_CONF_ATTN_BIT_EN);
  1343. if (single_msix)
  1344. val |= IGU_PF_CONF_SINGLE_ISR_EN;
  1345. } else if (msi) {
  1346. val &= ~IGU_PF_CONF_INT_LINE_EN;
  1347. val |= (IGU_PF_CONF_MSI_MSIX_EN |
  1348. IGU_PF_CONF_ATTN_BIT_EN |
  1349. IGU_PF_CONF_SINGLE_ISR_EN);
  1350. } else {
  1351. val &= ~IGU_PF_CONF_MSI_MSIX_EN;
  1352. val |= (IGU_PF_CONF_INT_LINE_EN |
  1353. IGU_PF_CONF_ATTN_BIT_EN |
  1354. IGU_PF_CONF_SINGLE_ISR_EN);
  1355. }
  1356. /* Clean previous status - need to configure igu prior to ack*/
  1357. if ((!msix) || single_msix) {
  1358. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1359. bnx2x_ack_int(bp);
  1360. }
  1361. val |= IGU_PF_CONF_FUNC_EN;
  1362. DP(NETIF_MSG_IFUP, "write 0x%x to IGU mode %s\n",
  1363. val, (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1364. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1365. if (val & IGU_PF_CONF_INT_LINE_EN)
  1366. pci_intx(bp->pdev, true);
  1367. barrier();
  1368. /* init leading/trailing edge */
  1369. if (IS_MF(bp)) {
  1370. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1371. if (bp->port.pmf)
  1372. /* enable nig and gpio3 attention */
  1373. val |= 0x1100;
  1374. } else
  1375. val = 0xffff;
  1376. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  1377. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  1378. /* Make sure that interrupts are indeed enabled from here on */
  1379. mmiowb();
  1380. }
  1381. void bnx2x_int_enable(struct bnx2x *bp)
  1382. {
  1383. if (bp->common.int_block == INT_BLOCK_HC)
  1384. bnx2x_hc_int_enable(bp);
  1385. else
  1386. bnx2x_igu_int_enable(bp);
  1387. }
  1388. void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw)
  1389. {
  1390. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  1391. int i, offset;
  1392. if (disable_hw)
  1393. /* prevent the HW from sending interrupts */
  1394. bnx2x_int_disable(bp);
  1395. /* make sure all ISRs are done */
  1396. if (msix) {
  1397. synchronize_irq(bp->msix_table[0].vector);
  1398. offset = 1;
  1399. if (CNIC_SUPPORT(bp))
  1400. offset++;
  1401. for_each_eth_queue(bp, i)
  1402. synchronize_irq(bp->msix_table[offset++].vector);
  1403. } else
  1404. synchronize_irq(bp->pdev->irq);
  1405. /* make sure sp_task is not running */
  1406. cancel_delayed_work(&bp->sp_task);
  1407. cancel_delayed_work(&bp->period_task);
  1408. flush_workqueue(bnx2x_wq);
  1409. }
  1410. /* fast path */
  1411. /*
  1412. * General service functions
  1413. */
  1414. /* Return true if succeeded to acquire the lock */
  1415. static bool bnx2x_trylock_hw_lock(struct bnx2x *bp, u32 resource)
  1416. {
  1417. u32 lock_status;
  1418. u32 resource_bit = (1 << resource);
  1419. int func = BP_FUNC(bp);
  1420. u32 hw_lock_control_reg;
  1421. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1422. "Trying to take a lock on resource %d\n", resource);
  1423. /* Validating that the resource is within range */
  1424. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1425. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1426. "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1427. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1428. return false;
  1429. }
  1430. if (func <= 5)
  1431. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1432. else
  1433. hw_lock_control_reg =
  1434. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1435. /* Try to acquire the lock */
  1436. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1437. lock_status = REG_RD(bp, hw_lock_control_reg);
  1438. if (lock_status & resource_bit)
  1439. return true;
  1440. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1441. "Failed to get a lock on resource %d\n", resource);
  1442. return false;
  1443. }
  1444. /**
  1445. * bnx2x_get_leader_lock_resource - get the recovery leader resource id
  1446. *
  1447. * @bp: driver handle
  1448. *
  1449. * Returns the recovery leader resource id according to the engine this function
  1450. * belongs to. Currently only only 2 engines is supported.
  1451. */
  1452. static int bnx2x_get_leader_lock_resource(struct bnx2x *bp)
  1453. {
  1454. if (BP_PATH(bp))
  1455. return HW_LOCK_RESOURCE_RECOVERY_LEADER_1;
  1456. else
  1457. return HW_LOCK_RESOURCE_RECOVERY_LEADER_0;
  1458. }
  1459. /**
  1460. * bnx2x_trylock_leader_lock- try to acquire a leader lock.
  1461. *
  1462. * @bp: driver handle
  1463. *
  1464. * Tries to acquire a leader lock for current engine.
  1465. */
  1466. static bool bnx2x_trylock_leader_lock(struct bnx2x *bp)
  1467. {
  1468. return bnx2x_trylock_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1469. }
  1470. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err);
  1471. /* schedule the sp task and mark that interrupt occurred (runs from ISR) */
  1472. static int bnx2x_schedule_sp_task(struct bnx2x *bp)
  1473. {
  1474. /* Set the interrupt occurred bit for the sp-task to recognize it
  1475. * must ack the interrupt and transition according to the IGU
  1476. * state machine.
  1477. */
  1478. atomic_set(&bp->interrupt_occurred, 1);
  1479. /* The sp_task must execute only after this bit
  1480. * is set, otherwise we will get out of sync and miss all
  1481. * further interrupts. Hence, the barrier.
  1482. */
  1483. smp_wmb();
  1484. /* schedule sp_task to workqueue */
  1485. return queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
  1486. }
  1487. void bnx2x_sp_event(struct bnx2x_fastpath *fp, union eth_rx_cqe *rr_cqe)
  1488. {
  1489. struct bnx2x *bp = fp->bp;
  1490. int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1491. int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1492. enum bnx2x_queue_cmd drv_cmd = BNX2X_Q_CMD_MAX;
  1493. struct bnx2x_queue_sp_obj *q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  1494. DP(BNX2X_MSG_SP,
  1495. "fp %d cid %d got ramrod #%d state is %x type is %d\n",
  1496. fp->index, cid, command, bp->state,
  1497. rr_cqe->ramrod_cqe.ramrod_type);
  1498. /* If cid is within VF range, replace the slowpath object with the
  1499. * one corresponding to this VF
  1500. */
  1501. if (cid >= BNX2X_FIRST_VF_CID &&
  1502. cid < BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)
  1503. bnx2x_iov_set_queue_sp_obj(bp, cid, &q_obj);
  1504. switch (command) {
  1505. case (RAMROD_CMD_ID_ETH_CLIENT_UPDATE):
  1506. DP(BNX2X_MSG_SP, "got UPDATE ramrod. CID %d\n", cid);
  1507. drv_cmd = BNX2X_Q_CMD_UPDATE;
  1508. break;
  1509. case (RAMROD_CMD_ID_ETH_CLIENT_SETUP):
  1510. DP(BNX2X_MSG_SP, "got MULTI[%d] setup ramrod\n", cid);
  1511. drv_cmd = BNX2X_Q_CMD_SETUP;
  1512. break;
  1513. case (RAMROD_CMD_ID_ETH_TX_QUEUE_SETUP):
  1514. DP(BNX2X_MSG_SP, "got MULTI[%d] tx-only setup ramrod\n", cid);
  1515. drv_cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  1516. break;
  1517. case (RAMROD_CMD_ID_ETH_HALT):
  1518. DP(BNX2X_MSG_SP, "got MULTI[%d] halt ramrod\n", cid);
  1519. drv_cmd = BNX2X_Q_CMD_HALT;
  1520. break;
  1521. case (RAMROD_CMD_ID_ETH_TERMINATE):
  1522. DP(BNX2X_MSG_SP, "got MULTI[%d] terminate ramrod\n", cid);
  1523. drv_cmd = BNX2X_Q_CMD_TERMINATE;
  1524. break;
  1525. case (RAMROD_CMD_ID_ETH_EMPTY):
  1526. DP(BNX2X_MSG_SP, "got MULTI[%d] empty ramrod\n", cid);
  1527. drv_cmd = BNX2X_Q_CMD_EMPTY;
  1528. break;
  1529. default:
  1530. BNX2X_ERR("unexpected MC reply (%d) on fp[%d]\n",
  1531. command, fp->index);
  1532. return;
  1533. }
  1534. if ((drv_cmd != BNX2X_Q_CMD_MAX) &&
  1535. q_obj->complete_cmd(bp, q_obj, drv_cmd))
  1536. /* q_obj->complete_cmd() failure means that this was
  1537. * an unexpected completion.
  1538. *
  1539. * In this case we don't want to increase the bp->spq_left
  1540. * because apparently we haven't sent this command the first
  1541. * place.
  1542. */
  1543. #ifdef BNX2X_STOP_ON_ERROR
  1544. bnx2x_panic();
  1545. #else
  1546. return;
  1547. #endif
  1548. /* SRIOV: reschedule any 'in_progress' operations */
  1549. bnx2x_iov_sp_event(bp, cid, true);
  1550. smp_mb__before_atomic_inc();
  1551. atomic_inc(&bp->cq_spq_left);
  1552. /* push the change in bp->spq_left and towards the memory */
  1553. smp_mb__after_atomic_inc();
  1554. DP(BNX2X_MSG_SP, "bp->cq_spq_left %x\n", atomic_read(&bp->cq_spq_left));
  1555. if ((drv_cmd == BNX2X_Q_CMD_UPDATE) && (IS_FCOE_FP(fp)) &&
  1556. (!!test_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state))) {
  1557. /* if Q update ramrod is completed for last Q in AFEX vif set
  1558. * flow, then ACK MCP at the end
  1559. *
  1560. * mark pending ACK to MCP bit.
  1561. * prevent case that both bits are cleared.
  1562. * At the end of load/unload driver checks that
  1563. * sp_state is cleared, and this order prevents
  1564. * races
  1565. */
  1566. smp_mb__before_clear_bit();
  1567. set_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK, &bp->sp_state);
  1568. wmb();
  1569. clear_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
  1570. smp_mb__after_clear_bit();
  1571. /* schedule the sp task as mcp ack is required */
  1572. bnx2x_schedule_sp_task(bp);
  1573. }
  1574. return;
  1575. }
  1576. irqreturn_t bnx2x_interrupt(int irq, void *dev_instance)
  1577. {
  1578. struct bnx2x *bp = netdev_priv(dev_instance);
  1579. u16 status = bnx2x_ack_int(bp);
  1580. u16 mask;
  1581. int i;
  1582. u8 cos;
  1583. /* Return here if interrupt is shared and it's not for us */
  1584. if (unlikely(status == 0)) {
  1585. DP(NETIF_MSG_INTR, "not our interrupt!\n");
  1586. return IRQ_NONE;
  1587. }
  1588. DP(NETIF_MSG_INTR, "got an interrupt status 0x%x\n", status);
  1589. #ifdef BNX2X_STOP_ON_ERROR
  1590. if (unlikely(bp->panic))
  1591. return IRQ_HANDLED;
  1592. #endif
  1593. for_each_eth_queue(bp, i) {
  1594. struct bnx2x_fastpath *fp = &bp->fp[i];
  1595. mask = 0x2 << (fp->index + CNIC_SUPPORT(bp));
  1596. if (status & mask) {
  1597. /* Handle Rx or Tx according to SB id */
  1598. for_each_cos_in_tx_queue(fp, cos)
  1599. prefetch(fp->txdata_ptr[cos]->tx_cons_sb);
  1600. prefetch(&fp->sb_running_index[SM_RX_ID]);
  1601. napi_schedule(&bnx2x_fp(bp, fp->index, napi));
  1602. status &= ~mask;
  1603. }
  1604. }
  1605. if (CNIC_SUPPORT(bp)) {
  1606. mask = 0x2;
  1607. if (status & (mask | 0x1)) {
  1608. struct cnic_ops *c_ops = NULL;
  1609. rcu_read_lock();
  1610. c_ops = rcu_dereference(bp->cnic_ops);
  1611. if (c_ops && (bp->cnic_eth_dev.drv_state &
  1612. CNIC_DRV_STATE_HANDLES_IRQ))
  1613. c_ops->cnic_handler(bp->cnic_data, NULL);
  1614. rcu_read_unlock();
  1615. status &= ~mask;
  1616. }
  1617. }
  1618. if (unlikely(status & 0x1)) {
  1619. /* schedule sp task to perform default status block work, ack
  1620. * attentions and enable interrupts.
  1621. */
  1622. bnx2x_schedule_sp_task(bp);
  1623. status &= ~0x1;
  1624. if (!status)
  1625. return IRQ_HANDLED;
  1626. }
  1627. if (unlikely(status))
  1628. DP(NETIF_MSG_INTR, "got an unknown interrupt! (status 0x%x)\n",
  1629. status);
  1630. return IRQ_HANDLED;
  1631. }
  1632. /* Link */
  1633. /*
  1634. * General service functions
  1635. */
  1636. int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource)
  1637. {
  1638. u32 lock_status;
  1639. u32 resource_bit = (1 << resource);
  1640. int func = BP_FUNC(bp);
  1641. u32 hw_lock_control_reg;
  1642. int cnt;
  1643. /* Validating that the resource is within range */
  1644. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1645. BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1646. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1647. return -EINVAL;
  1648. }
  1649. if (func <= 5) {
  1650. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1651. } else {
  1652. hw_lock_control_reg =
  1653. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1654. }
  1655. /* Validating that the resource is not already taken */
  1656. lock_status = REG_RD(bp, hw_lock_control_reg);
  1657. if (lock_status & resource_bit) {
  1658. BNX2X_ERR("lock_status 0x%x resource_bit 0x%x\n",
  1659. lock_status, resource_bit);
  1660. return -EEXIST;
  1661. }
  1662. /* Try for 5 second every 5ms */
  1663. for (cnt = 0; cnt < 1000; cnt++) {
  1664. /* Try to acquire the lock */
  1665. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1666. lock_status = REG_RD(bp, hw_lock_control_reg);
  1667. if (lock_status & resource_bit)
  1668. return 0;
  1669. usleep_range(5000, 10000);
  1670. }
  1671. BNX2X_ERR("Timeout\n");
  1672. return -EAGAIN;
  1673. }
  1674. int bnx2x_release_leader_lock(struct bnx2x *bp)
  1675. {
  1676. return bnx2x_release_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1677. }
  1678. int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource)
  1679. {
  1680. u32 lock_status;
  1681. u32 resource_bit = (1 << resource);
  1682. int func = BP_FUNC(bp);
  1683. u32 hw_lock_control_reg;
  1684. /* Validating that the resource is within range */
  1685. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1686. BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1687. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1688. return -EINVAL;
  1689. }
  1690. if (func <= 5) {
  1691. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1692. } else {
  1693. hw_lock_control_reg =
  1694. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1695. }
  1696. /* Validating that the resource is currently taken */
  1697. lock_status = REG_RD(bp, hw_lock_control_reg);
  1698. if (!(lock_status & resource_bit)) {
  1699. BNX2X_ERR("lock_status 0x%x resource_bit 0x%x. Unlock was called but lock wasn't taken!\n",
  1700. lock_status, resource_bit);
  1701. return -EFAULT;
  1702. }
  1703. REG_WR(bp, hw_lock_control_reg, resource_bit);
  1704. return 0;
  1705. }
  1706. int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port)
  1707. {
  1708. /* The GPIO should be swapped if swap register is set and active */
  1709. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1710. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1711. int gpio_shift = gpio_num +
  1712. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1713. u32 gpio_mask = (1 << gpio_shift);
  1714. u32 gpio_reg;
  1715. int value;
  1716. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1717. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1718. return -EINVAL;
  1719. }
  1720. /* read GPIO value */
  1721. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1722. /* get the requested pin value */
  1723. if ((gpio_reg & gpio_mask) == gpio_mask)
  1724. value = 1;
  1725. else
  1726. value = 0;
  1727. DP(NETIF_MSG_LINK, "pin %d value 0x%x\n", gpio_num, value);
  1728. return value;
  1729. }
  1730. int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1731. {
  1732. /* The GPIO should be swapped if swap register is set and active */
  1733. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1734. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1735. int gpio_shift = gpio_num +
  1736. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1737. u32 gpio_mask = (1 << gpio_shift);
  1738. u32 gpio_reg;
  1739. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1740. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1741. return -EINVAL;
  1742. }
  1743. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1744. /* read GPIO and mask except the float bits */
  1745. gpio_reg = (REG_RD(bp, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT);
  1746. switch (mode) {
  1747. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1748. DP(NETIF_MSG_LINK,
  1749. "Set GPIO %d (shift %d) -> output low\n",
  1750. gpio_num, gpio_shift);
  1751. /* clear FLOAT and set CLR */
  1752. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1753. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS);
  1754. break;
  1755. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1756. DP(NETIF_MSG_LINK,
  1757. "Set GPIO %d (shift %d) -> output high\n",
  1758. gpio_num, gpio_shift);
  1759. /* clear FLOAT and set SET */
  1760. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1761. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS);
  1762. break;
  1763. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1764. DP(NETIF_MSG_LINK,
  1765. "Set GPIO %d (shift %d) -> input\n",
  1766. gpio_num, gpio_shift);
  1767. /* set FLOAT */
  1768. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1769. break;
  1770. default:
  1771. break;
  1772. }
  1773. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1774. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1775. return 0;
  1776. }
  1777. int bnx2x_set_mult_gpio(struct bnx2x *bp, u8 pins, u32 mode)
  1778. {
  1779. u32 gpio_reg = 0;
  1780. int rc = 0;
  1781. /* Any port swapping should be handled by caller. */
  1782. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1783. /* read GPIO and mask except the float bits */
  1784. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1785. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1786. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_CLR_POS);
  1787. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_SET_POS);
  1788. switch (mode) {
  1789. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1790. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output low\n", pins);
  1791. /* set CLR */
  1792. gpio_reg |= (pins << MISC_REGISTERS_GPIO_CLR_POS);
  1793. break;
  1794. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1795. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output high\n", pins);
  1796. /* set SET */
  1797. gpio_reg |= (pins << MISC_REGISTERS_GPIO_SET_POS);
  1798. break;
  1799. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1800. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> input\n", pins);
  1801. /* set FLOAT */
  1802. gpio_reg |= (pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1803. break;
  1804. default:
  1805. BNX2X_ERR("Invalid GPIO mode assignment %d\n", mode);
  1806. rc = -EINVAL;
  1807. break;
  1808. }
  1809. if (rc == 0)
  1810. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1811. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1812. return rc;
  1813. }
  1814. int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1815. {
  1816. /* The GPIO should be swapped if swap register is set and active */
  1817. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1818. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1819. int gpio_shift = gpio_num +
  1820. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1821. u32 gpio_mask = (1 << gpio_shift);
  1822. u32 gpio_reg;
  1823. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1824. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1825. return -EINVAL;
  1826. }
  1827. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1828. /* read GPIO int */
  1829. gpio_reg = REG_RD(bp, MISC_REG_GPIO_INT);
  1830. switch (mode) {
  1831. case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR:
  1832. DP(NETIF_MSG_LINK,
  1833. "Clear GPIO INT %d (shift %d) -> output low\n",
  1834. gpio_num, gpio_shift);
  1835. /* clear SET and set CLR */
  1836. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1837. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1838. break;
  1839. case MISC_REGISTERS_GPIO_INT_OUTPUT_SET:
  1840. DP(NETIF_MSG_LINK,
  1841. "Set GPIO INT %d (shift %d) -> output high\n",
  1842. gpio_num, gpio_shift);
  1843. /* clear CLR and set SET */
  1844. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1845. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1846. break;
  1847. default:
  1848. break;
  1849. }
  1850. REG_WR(bp, MISC_REG_GPIO_INT, gpio_reg);
  1851. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1852. return 0;
  1853. }
  1854. static int bnx2x_set_spio(struct bnx2x *bp, int spio, u32 mode)
  1855. {
  1856. u32 spio_reg;
  1857. /* Only 2 SPIOs are configurable */
  1858. if ((spio != MISC_SPIO_SPIO4) && (spio != MISC_SPIO_SPIO5)) {
  1859. BNX2X_ERR("Invalid SPIO 0x%x\n", spio);
  1860. return -EINVAL;
  1861. }
  1862. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1863. /* read SPIO and mask except the float bits */
  1864. spio_reg = (REG_RD(bp, MISC_REG_SPIO) & MISC_SPIO_FLOAT);
  1865. switch (mode) {
  1866. case MISC_SPIO_OUTPUT_LOW:
  1867. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output low\n", spio);
  1868. /* clear FLOAT and set CLR */
  1869. spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
  1870. spio_reg |= (spio << MISC_SPIO_CLR_POS);
  1871. break;
  1872. case MISC_SPIO_OUTPUT_HIGH:
  1873. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output high\n", spio);
  1874. /* clear FLOAT and set SET */
  1875. spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
  1876. spio_reg |= (spio << MISC_SPIO_SET_POS);
  1877. break;
  1878. case MISC_SPIO_INPUT_HI_Z:
  1879. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> input\n", spio);
  1880. /* set FLOAT */
  1881. spio_reg |= (spio << MISC_SPIO_FLOAT_POS);
  1882. break;
  1883. default:
  1884. break;
  1885. }
  1886. REG_WR(bp, MISC_REG_SPIO, spio_reg);
  1887. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1888. return 0;
  1889. }
  1890. void bnx2x_calc_fc_adv(struct bnx2x *bp)
  1891. {
  1892. u8 cfg_idx = bnx2x_get_link_cfg_idx(bp);
  1893. switch (bp->link_vars.ieee_fc &
  1894. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) {
  1895. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE:
  1896. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1897. ADVERTISED_Pause);
  1898. break;
  1899. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH:
  1900. bp->port.advertising[cfg_idx] |= (ADVERTISED_Asym_Pause |
  1901. ADVERTISED_Pause);
  1902. break;
  1903. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC:
  1904. bp->port.advertising[cfg_idx] |= ADVERTISED_Asym_Pause;
  1905. break;
  1906. default:
  1907. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1908. ADVERTISED_Pause);
  1909. break;
  1910. }
  1911. }
  1912. static void bnx2x_set_requested_fc(struct bnx2x *bp)
  1913. {
  1914. /* Initialize link parameters structure variables
  1915. * It is recommended to turn off RX FC for jumbo frames
  1916. * for better performance
  1917. */
  1918. if (CHIP_IS_E1x(bp) && (bp->dev->mtu > 5000))
  1919. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_TX;
  1920. else
  1921. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH;
  1922. }
  1923. static void bnx2x_init_dropless_fc(struct bnx2x *bp)
  1924. {
  1925. u32 pause_enabled = 0;
  1926. if (!CHIP_IS_E1(bp) && bp->dropless_fc && bp->link_vars.link_up) {
  1927. if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX)
  1928. pause_enabled = 1;
  1929. REG_WR(bp, BAR_USTRORM_INTMEM +
  1930. USTORM_ETH_PAUSE_ENABLED_OFFSET(BP_PORT(bp)),
  1931. pause_enabled);
  1932. }
  1933. DP(NETIF_MSG_IFUP | NETIF_MSG_LINK, "dropless_fc is %s\n",
  1934. pause_enabled ? "enabled" : "disabled");
  1935. }
  1936. int bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode)
  1937. {
  1938. int rc, cfx_idx = bnx2x_get_link_cfg_idx(bp);
  1939. u16 req_line_speed = bp->link_params.req_line_speed[cfx_idx];
  1940. if (!BP_NOMCP(bp)) {
  1941. bnx2x_set_requested_fc(bp);
  1942. bnx2x_acquire_phy_lock(bp);
  1943. if (load_mode == LOAD_DIAG) {
  1944. struct link_params *lp = &bp->link_params;
  1945. lp->loopback_mode = LOOPBACK_XGXS;
  1946. /* do PHY loopback at 10G speed, if possible */
  1947. if (lp->req_line_speed[cfx_idx] < SPEED_10000) {
  1948. if (lp->speed_cap_mask[cfx_idx] &
  1949. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
  1950. lp->req_line_speed[cfx_idx] =
  1951. SPEED_10000;
  1952. else
  1953. lp->req_line_speed[cfx_idx] =
  1954. SPEED_1000;
  1955. }
  1956. }
  1957. if (load_mode == LOAD_LOOPBACK_EXT) {
  1958. struct link_params *lp = &bp->link_params;
  1959. lp->loopback_mode = LOOPBACK_EXT;
  1960. }
  1961. rc = bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  1962. bnx2x_release_phy_lock(bp);
  1963. bnx2x_init_dropless_fc(bp);
  1964. bnx2x_calc_fc_adv(bp);
  1965. if (bp->link_vars.link_up) {
  1966. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  1967. bnx2x_link_report(bp);
  1968. }
  1969. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  1970. bp->link_params.req_line_speed[cfx_idx] = req_line_speed;
  1971. return rc;
  1972. }
  1973. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  1974. return -EINVAL;
  1975. }
  1976. void bnx2x_link_set(struct bnx2x *bp)
  1977. {
  1978. if (!BP_NOMCP(bp)) {
  1979. bnx2x_acquire_phy_lock(bp);
  1980. bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  1981. bnx2x_release_phy_lock(bp);
  1982. bnx2x_init_dropless_fc(bp);
  1983. bnx2x_calc_fc_adv(bp);
  1984. } else
  1985. BNX2X_ERR("Bootcode is missing - can not set link\n");
  1986. }
  1987. static void bnx2x__link_reset(struct bnx2x *bp)
  1988. {
  1989. if (!BP_NOMCP(bp)) {
  1990. bnx2x_acquire_phy_lock(bp);
  1991. bnx2x_lfa_reset(&bp->link_params, &bp->link_vars);
  1992. bnx2x_release_phy_lock(bp);
  1993. } else
  1994. BNX2X_ERR("Bootcode is missing - can not reset link\n");
  1995. }
  1996. void bnx2x_force_link_reset(struct bnx2x *bp)
  1997. {
  1998. bnx2x_acquire_phy_lock(bp);
  1999. bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
  2000. bnx2x_release_phy_lock(bp);
  2001. }
  2002. u8 bnx2x_link_test(struct bnx2x *bp, u8 is_serdes)
  2003. {
  2004. u8 rc = 0;
  2005. if (!BP_NOMCP(bp)) {
  2006. bnx2x_acquire_phy_lock(bp);
  2007. rc = bnx2x_test_link(&bp->link_params, &bp->link_vars,
  2008. is_serdes);
  2009. bnx2x_release_phy_lock(bp);
  2010. } else
  2011. BNX2X_ERR("Bootcode is missing - can not test link\n");
  2012. return rc;
  2013. }
  2014. /* Calculates the sum of vn_min_rates.
  2015. It's needed for further normalizing of the min_rates.
  2016. Returns:
  2017. sum of vn_min_rates.
  2018. or
  2019. 0 - if all the min_rates are 0.
  2020. In the later case fairness algorithm should be deactivated.
  2021. If not all min_rates are zero then those that are zeroes will be set to 1.
  2022. */
  2023. static void bnx2x_calc_vn_min(struct bnx2x *bp,
  2024. struct cmng_init_input *input)
  2025. {
  2026. int all_zero = 1;
  2027. int vn;
  2028. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2029. u32 vn_cfg = bp->mf_config[vn];
  2030. u32 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
  2031. FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
  2032. /* Skip hidden vns */
  2033. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  2034. vn_min_rate = 0;
  2035. /* If min rate is zero - set it to 1 */
  2036. else if (!vn_min_rate)
  2037. vn_min_rate = DEF_MIN_RATE;
  2038. else
  2039. all_zero = 0;
  2040. input->vnic_min_rate[vn] = vn_min_rate;
  2041. }
  2042. /* if ETS or all min rates are zeros - disable fairness */
  2043. if (BNX2X_IS_ETS_ENABLED(bp)) {
  2044. input->flags.cmng_enables &=
  2045. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2046. DP(NETIF_MSG_IFUP, "Fairness will be disabled due to ETS\n");
  2047. } else if (all_zero) {
  2048. input->flags.cmng_enables &=
  2049. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2050. DP(NETIF_MSG_IFUP,
  2051. "All MIN values are zeroes fairness will be disabled\n");
  2052. } else
  2053. input->flags.cmng_enables |=
  2054. CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2055. }
  2056. static void bnx2x_calc_vn_max(struct bnx2x *bp, int vn,
  2057. struct cmng_init_input *input)
  2058. {
  2059. u16 vn_max_rate;
  2060. u32 vn_cfg = bp->mf_config[vn];
  2061. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  2062. vn_max_rate = 0;
  2063. else {
  2064. u32 maxCfg = bnx2x_extract_max_cfg(bp, vn_cfg);
  2065. if (IS_MF_SI(bp)) {
  2066. /* maxCfg in percents of linkspeed */
  2067. vn_max_rate = (bp->link_vars.line_speed * maxCfg) / 100;
  2068. } else /* SD modes */
  2069. /* maxCfg is absolute in 100Mb units */
  2070. vn_max_rate = maxCfg * 100;
  2071. }
  2072. DP(NETIF_MSG_IFUP, "vn %d: vn_max_rate %d\n", vn, vn_max_rate);
  2073. input->vnic_max_rate[vn] = vn_max_rate;
  2074. }
  2075. static int bnx2x_get_cmng_fns_mode(struct bnx2x *bp)
  2076. {
  2077. if (CHIP_REV_IS_SLOW(bp))
  2078. return CMNG_FNS_NONE;
  2079. if (IS_MF(bp))
  2080. return CMNG_FNS_MINMAX;
  2081. return CMNG_FNS_NONE;
  2082. }
  2083. void bnx2x_read_mf_cfg(struct bnx2x *bp)
  2084. {
  2085. int vn, n = (CHIP_MODE_IS_4_PORT(bp) ? 2 : 1);
  2086. if (BP_NOMCP(bp))
  2087. return; /* what should be the default value in this case */
  2088. /* For 2 port configuration the absolute function number formula
  2089. * is:
  2090. * abs_func = 2 * vn + BP_PORT + BP_PATH
  2091. *
  2092. * and there are 4 functions per port
  2093. *
  2094. * For 4 port configuration it is
  2095. * abs_func = 4 * vn + 2 * BP_PORT + BP_PATH
  2096. *
  2097. * and there are 2 functions per port
  2098. */
  2099. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2100. int /*abs*/func = n * (2 * vn + BP_PORT(bp)) + BP_PATH(bp);
  2101. if (func >= E1H_FUNC_MAX)
  2102. break;
  2103. bp->mf_config[vn] =
  2104. MF_CFG_RD(bp, func_mf_config[func].config);
  2105. }
  2106. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  2107. DP(NETIF_MSG_IFUP, "mf_cfg function disabled\n");
  2108. bp->flags |= MF_FUNC_DIS;
  2109. } else {
  2110. DP(NETIF_MSG_IFUP, "mf_cfg function enabled\n");
  2111. bp->flags &= ~MF_FUNC_DIS;
  2112. }
  2113. }
  2114. static void bnx2x_cmng_fns_init(struct bnx2x *bp, u8 read_cfg, u8 cmng_type)
  2115. {
  2116. struct cmng_init_input input;
  2117. memset(&input, 0, sizeof(struct cmng_init_input));
  2118. input.port_rate = bp->link_vars.line_speed;
  2119. if (cmng_type == CMNG_FNS_MINMAX && input.port_rate) {
  2120. int vn;
  2121. /* read mf conf from shmem */
  2122. if (read_cfg)
  2123. bnx2x_read_mf_cfg(bp);
  2124. /* vn_weight_sum and enable fairness if not 0 */
  2125. bnx2x_calc_vn_min(bp, &input);
  2126. /* calculate and set min-max rate for each vn */
  2127. if (bp->port.pmf)
  2128. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++)
  2129. bnx2x_calc_vn_max(bp, vn, &input);
  2130. /* always enable rate shaping and fairness */
  2131. input.flags.cmng_enables |=
  2132. CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN;
  2133. bnx2x_init_cmng(&input, &bp->cmng);
  2134. return;
  2135. }
  2136. /* rate shaping and fairness are disabled */
  2137. DP(NETIF_MSG_IFUP,
  2138. "rate shaping and fairness are disabled\n");
  2139. }
  2140. static void storm_memset_cmng(struct bnx2x *bp,
  2141. struct cmng_init *cmng,
  2142. u8 port)
  2143. {
  2144. int vn;
  2145. size_t size = sizeof(struct cmng_struct_per_port);
  2146. u32 addr = BAR_XSTRORM_INTMEM +
  2147. XSTORM_CMNG_PER_PORT_VARS_OFFSET(port);
  2148. __storm_memset_struct(bp, addr, size, (u32 *)&cmng->port);
  2149. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2150. int func = func_by_vn(bp, vn);
  2151. addr = BAR_XSTRORM_INTMEM +
  2152. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func);
  2153. size = sizeof(struct rate_shaping_vars_per_vn);
  2154. __storm_memset_struct(bp, addr, size,
  2155. (u32 *)&cmng->vnic.vnic_max_rate[vn]);
  2156. addr = BAR_XSTRORM_INTMEM +
  2157. XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func);
  2158. size = sizeof(struct fairness_vars_per_vn);
  2159. __storm_memset_struct(bp, addr, size,
  2160. (u32 *)&cmng->vnic.vnic_min_rate[vn]);
  2161. }
  2162. }
  2163. /* init cmng mode in HW according to local configuration */
  2164. void bnx2x_set_local_cmng(struct bnx2x *bp)
  2165. {
  2166. int cmng_fns = bnx2x_get_cmng_fns_mode(bp);
  2167. if (cmng_fns != CMNG_FNS_NONE) {
  2168. bnx2x_cmng_fns_init(bp, false, cmng_fns);
  2169. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2170. } else {
  2171. /* rate shaping and fairness are disabled */
  2172. DP(NETIF_MSG_IFUP,
  2173. "single function mode without fairness\n");
  2174. }
  2175. }
  2176. /* This function is called upon link interrupt */
  2177. static void bnx2x_link_attn(struct bnx2x *bp)
  2178. {
  2179. /* Make sure that we are synced with the current statistics */
  2180. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2181. bnx2x_link_update(&bp->link_params, &bp->link_vars);
  2182. bnx2x_init_dropless_fc(bp);
  2183. if (bp->link_vars.link_up) {
  2184. if (bp->link_vars.mac_type != MAC_TYPE_EMAC) {
  2185. struct host_port_stats *pstats;
  2186. pstats = bnx2x_sp(bp, port_stats);
  2187. /* reset old mac stats */
  2188. memset(&(pstats->mac_stx[0]), 0,
  2189. sizeof(struct mac_stx));
  2190. }
  2191. if (bp->state == BNX2X_STATE_OPEN)
  2192. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2193. }
  2194. if (bp->link_vars.link_up && bp->link_vars.line_speed)
  2195. bnx2x_set_local_cmng(bp);
  2196. __bnx2x_link_report(bp);
  2197. if (IS_MF(bp))
  2198. bnx2x_link_sync_notify(bp);
  2199. }
  2200. void bnx2x__link_status_update(struct bnx2x *bp)
  2201. {
  2202. if (bp->state != BNX2X_STATE_OPEN)
  2203. return;
  2204. /* read updated dcb configuration */
  2205. if (IS_PF(bp)) {
  2206. bnx2x_dcbx_pmf_update(bp);
  2207. bnx2x_link_status_update(&bp->link_params, &bp->link_vars);
  2208. if (bp->link_vars.link_up)
  2209. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2210. else
  2211. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2212. /* indicate link status */
  2213. bnx2x_link_report(bp);
  2214. } else { /* VF */
  2215. bp->port.supported[0] |= (SUPPORTED_10baseT_Half |
  2216. SUPPORTED_10baseT_Full |
  2217. SUPPORTED_100baseT_Half |
  2218. SUPPORTED_100baseT_Full |
  2219. SUPPORTED_1000baseT_Full |
  2220. SUPPORTED_2500baseX_Full |
  2221. SUPPORTED_10000baseT_Full |
  2222. SUPPORTED_TP |
  2223. SUPPORTED_FIBRE |
  2224. SUPPORTED_Autoneg |
  2225. SUPPORTED_Pause |
  2226. SUPPORTED_Asym_Pause);
  2227. bp->port.advertising[0] = bp->port.supported[0];
  2228. bp->link_params.bp = bp;
  2229. bp->link_params.port = BP_PORT(bp);
  2230. bp->link_params.req_duplex[0] = DUPLEX_FULL;
  2231. bp->link_params.req_flow_ctrl[0] = BNX2X_FLOW_CTRL_NONE;
  2232. bp->link_params.req_line_speed[0] = SPEED_10000;
  2233. bp->link_params.speed_cap_mask[0] = 0x7f0000;
  2234. bp->link_params.switch_cfg = SWITCH_CFG_10G;
  2235. bp->link_vars.mac_type = MAC_TYPE_BMAC;
  2236. bp->link_vars.line_speed = SPEED_10000;
  2237. bp->link_vars.link_status =
  2238. (LINK_STATUS_LINK_UP |
  2239. LINK_STATUS_SPEED_AND_DUPLEX_10GTFD);
  2240. bp->link_vars.link_up = 1;
  2241. bp->link_vars.duplex = DUPLEX_FULL;
  2242. bp->link_vars.flow_ctrl = BNX2X_FLOW_CTRL_NONE;
  2243. __bnx2x_link_report(bp);
  2244. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2245. }
  2246. }
  2247. static int bnx2x_afex_func_update(struct bnx2x *bp, u16 vifid,
  2248. u16 vlan_val, u8 allowed_prio)
  2249. {
  2250. struct bnx2x_func_state_params func_params = {NULL};
  2251. struct bnx2x_func_afex_update_params *f_update_params =
  2252. &func_params.params.afex_update;
  2253. func_params.f_obj = &bp->func_obj;
  2254. func_params.cmd = BNX2X_F_CMD_AFEX_UPDATE;
  2255. /* no need to wait for RAMROD completion, so don't
  2256. * set RAMROD_COMP_WAIT flag
  2257. */
  2258. f_update_params->vif_id = vifid;
  2259. f_update_params->afex_default_vlan = vlan_val;
  2260. f_update_params->allowed_priorities = allowed_prio;
  2261. /* if ramrod can not be sent, response to MCP immediately */
  2262. if (bnx2x_func_state_change(bp, &func_params) < 0)
  2263. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  2264. return 0;
  2265. }
  2266. static int bnx2x_afex_handle_vif_list_cmd(struct bnx2x *bp, u8 cmd_type,
  2267. u16 vif_index, u8 func_bit_map)
  2268. {
  2269. struct bnx2x_func_state_params func_params = {NULL};
  2270. struct bnx2x_func_afex_viflists_params *update_params =
  2271. &func_params.params.afex_viflists;
  2272. int rc;
  2273. u32 drv_msg_code;
  2274. /* validate only LIST_SET and LIST_GET are received from switch */
  2275. if ((cmd_type != VIF_LIST_RULE_GET) && (cmd_type != VIF_LIST_RULE_SET))
  2276. BNX2X_ERR("BUG! afex_handle_vif_list_cmd invalid type 0x%x\n",
  2277. cmd_type);
  2278. func_params.f_obj = &bp->func_obj;
  2279. func_params.cmd = BNX2X_F_CMD_AFEX_VIFLISTS;
  2280. /* set parameters according to cmd_type */
  2281. update_params->afex_vif_list_command = cmd_type;
  2282. update_params->vif_list_index = vif_index;
  2283. update_params->func_bit_map =
  2284. (cmd_type == VIF_LIST_RULE_GET) ? 0 : func_bit_map;
  2285. update_params->func_to_clear = 0;
  2286. drv_msg_code =
  2287. (cmd_type == VIF_LIST_RULE_GET) ?
  2288. DRV_MSG_CODE_AFEX_LISTGET_ACK :
  2289. DRV_MSG_CODE_AFEX_LISTSET_ACK;
  2290. /* if ramrod can not be sent, respond to MCP immediately for
  2291. * SET and GET requests (other are not triggered from MCP)
  2292. */
  2293. rc = bnx2x_func_state_change(bp, &func_params);
  2294. if (rc < 0)
  2295. bnx2x_fw_command(bp, drv_msg_code, 0);
  2296. return 0;
  2297. }
  2298. static void bnx2x_handle_afex_cmd(struct bnx2x *bp, u32 cmd)
  2299. {
  2300. struct afex_stats afex_stats;
  2301. u32 func = BP_ABS_FUNC(bp);
  2302. u32 mf_config;
  2303. u16 vlan_val;
  2304. u32 vlan_prio;
  2305. u16 vif_id;
  2306. u8 allowed_prio;
  2307. u8 vlan_mode;
  2308. u32 addr_to_write, vifid, addrs, stats_type, i;
  2309. if (cmd & DRV_STATUS_AFEX_LISTGET_REQ) {
  2310. vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2311. DP(BNX2X_MSG_MCP,
  2312. "afex: got MCP req LISTGET_REQ for vifid 0x%x\n", vifid);
  2313. bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_GET, vifid, 0);
  2314. }
  2315. if (cmd & DRV_STATUS_AFEX_LISTSET_REQ) {
  2316. vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2317. addrs = SHMEM2_RD(bp, afex_param2_to_driver[BP_FW_MB_IDX(bp)]);
  2318. DP(BNX2X_MSG_MCP,
  2319. "afex: got MCP req LISTSET_REQ for vifid 0x%x addrs 0x%x\n",
  2320. vifid, addrs);
  2321. bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_SET, vifid,
  2322. addrs);
  2323. }
  2324. if (cmd & DRV_STATUS_AFEX_STATSGET_REQ) {
  2325. addr_to_write = SHMEM2_RD(bp,
  2326. afex_scratchpad_addr_to_write[BP_FW_MB_IDX(bp)]);
  2327. stats_type = SHMEM2_RD(bp,
  2328. afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2329. DP(BNX2X_MSG_MCP,
  2330. "afex: got MCP req STATSGET_REQ, write to addr 0x%x\n",
  2331. addr_to_write);
  2332. bnx2x_afex_collect_stats(bp, (void *)&afex_stats, stats_type);
  2333. /* write response to scratchpad, for MCP */
  2334. for (i = 0; i < (sizeof(struct afex_stats)/sizeof(u32)); i++)
  2335. REG_WR(bp, addr_to_write + i*sizeof(u32),
  2336. *(((u32 *)(&afex_stats))+i));
  2337. /* send ack message to MCP */
  2338. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_STATSGET_ACK, 0);
  2339. }
  2340. if (cmd & DRV_STATUS_AFEX_VIFSET_REQ) {
  2341. mf_config = MF_CFG_RD(bp, func_mf_config[func].config);
  2342. bp->mf_config[BP_VN(bp)] = mf_config;
  2343. DP(BNX2X_MSG_MCP,
  2344. "afex: got MCP req VIFSET_REQ, mf_config 0x%x\n",
  2345. mf_config);
  2346. /* if VIF_SET is "enabled" */
  2347. if (!(mf_config & FUNC_MF_CFG_FUNC_DISABLED)) {
  2348. /* set rate limit directly to internal RAM */
  2349. struct cmng_init_input cmng_input;
  2350. struct rate_shaping_vars_per_vn m_rs_vn;
  2351. size_t size = sizeof(struct rate_shaping_vars_per_vn);
  2352. u32 addr = BAR_XSTRORM_INTMEM +
  2353. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(BP_FUNC(bp));
  2354. bp->mf_config[BP_VN(bp)] = mf_config;
  2355. bnx2x_calc_vn_max(bp, BP_VN(bp), &cmng_input);
  2356. m_rs_vn.vn_counter.rate =
  2357. cmng_input.vnic_max_rate[BP_VN(bp)];
  2358. m_rs_vn.vn_counter.quota =
  2359. (m_rs_vn.vn_counter.rate *
  2360. RS_PERIODIC_TIMEOUT_USEC) / 8;
  2361. __storm_memset_struct(bp, addr, size, (u32 *)&m_rs_vn);
  2362. /* read relevant values from mf_cfg struct in shmem */
  2363. vif_id =
  2364. (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2365. FUNC_MF_CFG_E1HOV_TAG_MASK) >>
  2366. FUNC_MF_CFG_E1HOV_TAG_SHIFT;
  2367. vlan_val =
  2368. (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2369. FUNC_MF_CFG_AFEX_VLAN_MASK) >>
  2370. FUNC_MF_CFG_AFEX_VLAN_SHIFT;
  2371. vlan_prio = (mf_config &
  2372. FUNC_MF_CFG_TRANSMIT_PRIORITY_MASK) >>
  2373. FUNC_MF_CFG_TRANSMIT_PRIORITY_SHIFT;
  2374. vlan_val |= (vlan_prio << VLAN_PRIO_SHIFT);
  2375. vlan_mode =
  2376. (MF_CFG_RD(bp,
  2377. func_mf_config[func].afex_config) &
  2378. FUNC_MF_CFG_AFEX_VLAN_MODE_MASK) >>
  2379. FUNC_MF_CFG_AFEX_VLAN_MODE_SHIFT;
  2380. allowed_prio =
  2381. (MF_CFG_RD(bp,
  2382. func_mf_config[func].afex_config) &
  2383. FUNC_MF_CFG_AFEX_COS_FILTER_MASK) >>
  2384. FUNC_MF_CFG_AFEX_COS_FILTER_SHIFT;
  2385. /* send ramrod to FW, return in case of failure */
  2386. if (bnx2x_afex_func_update(bp, vif_id, vlan_val,
  2387. allowed_prio))
  2388. return;
  2389. bp->afex_def_vlan_tag = vlan_val;
  2390. bp->afex_vlan_mode = vlan_mode;
  2391. } else {
  2392. /* notify link down because BP->flags is disabled */
  2393. bnx2x_link_report(bp);
  2394. /* send INVALID VIF ramrod to FW */
  2395. bnx2x_afex_func_update(bp, 0xFFFF, 0, 0);
  2396. /* Reset the default afex VLAN */
  2397. bp->afex_def_vlan_tag = -1;
  2398. }
  2399. }
  2400. }
  2401. static void bnx2x_pmf_update(struct bnx2x *bp)
  2402. {
  2403. int port = BP_PORT(bp);
  2404. u32 val;
  2405. bp->port.pmf = 1;
  2406. DP(BNX2X_MSG_MCP, "pmf %d\n", bp->port.pmf);
  2407. /*
  2408. * We need the mb() to ensure the ordering between the writing to
  2409. * bp->port.pmf here and reading it from the bnx2x_periodic_task().
  2410. */
  2411. smp_mb();
  2412. /* queue a periodic task */
  2413. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  2414. bnx2x_dcbx_pmf_update(bp);
  2415. /* enable nig attention */
  2416. val = (0xff0f | (1 << (BP_VN(bp) + 4)));
  2417. if (bp->common.int_block == INT_BLOCK_HC) {
  2418. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  2419. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  2420. } else if (!CHIP_IS_E1x(bp)) {
  2421. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  2422. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  2423. }
  2424. bnx2x_stats_handle(bp, STATS_EVENT_PMF);
  2425. }
  2426. /* end of Link */
  2427. /* slow path */
  2428. /*
  2429. * General service functions
  2430. */
  2431. /* send the MCP a request, block until there is a reply */
  2432. u32 bnx2x_fw_command(struct bnx2x *bp, u32 command, u32 param)
  2433. {
  2434. int mb_idx = BP_FW_MB_IDX(bp);
  2435. u32 seq;
  2436. u32 rc = 0;
  2437. u32 cnt = 1;
  2438. u8 delay = CHIP_REV_IS_SLOW(bp) ? 100 : 10;
  2439. mutex_lock(&bp->fw_mb_mutex);
  2440. seq = ++bp->fw_seq;
  2441. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_param, param);
  2442. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_header, (command | seq));
  2443. DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB param 0x%08x\n",
  2444. (command | seq), param);
  2445. do {
  2446. /* let the FW do it's magic ... */
  2447. msleep(delay);
  2448. rc = SHMEM_RD(bp, func_mb[mb_idx].fw_mb_header);
  2449. /* Give the FW up to 5 second (500*10ms) */
  2450. } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500));
  2451. DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n",
  2452. cnt*delay, rc, seq);
  2453. /* is this a reply to our command? */
  2454. if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK))
  2455. rc &= FW_MSG_CODE_MASK;
  2456. else {
  2457. /* FW BUG! */
  2458. BNX2X_ERR("FW failed to respond!\n");
  2459. bnx2x_fw_dump(bp);
  2460. rc = 0;
  2461. }
  2462. mutex_unlock(&bp->fw_mb_mutex);
  2463. return rc;
  2464. }
  2465. static void storm_memset_func_cfg(struct bnx2x *bp,
  2466. struct tstorm_eth_function_common_config *tcfg,
  2467. u16 abs_fid)
  2468. {
  2469. size_t size = sizeof(struct tstorm_eth_function_common_config);
  2470. u32 addr = BAR_TSTRORM_INTMEM +
  2471. TSTORM_FUNCTION_COMMON_CONFIG_OFFSET(abs_fid);
  2472. __storm_memset_struct(bp, addr, size, (u32 *)tcfg);
  2473. }
  2474. void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p)
  2475. {
  2476. if (CHIP_IS_E1x(bp)) {
  2477. struct tstorm_eth_function_common_config tcfg = {0};
  2478. storm_memset_func_cfg(bp, &tcfg, p->func_id);
  2479. }
  2480. /* Enable the function in the FW */
  2481. storm_memset_vf_to_pf(bp, p->func_id, p->pf_id);
  2482. storm_memset_func_en(bp, p->func_id, 1);
  2483. /* spq */
  2484. if (p->func_flgs & FUNC_FLG_SPQ) {
  2485. storm_memset_spq_addr(bp, p->spq_map, p->func_id);
  2486. REG_WR(bp, XSEM_REG_FAST_MEMORY +
  2487. XSTORM_SPQ_PROD_OFFSET(p->func_id), p->spq_prod);
  2488. }
  2489. }
  2490. /**
  2491. * bnx2x_get_common_flags - Return common flags
  2492. *
  2493. * @bp device handle
  2494. * @fp queue handle
  2495. * @zero_stats TRUE if statistics zeroing is needed
  2496. *
  2497. * Return the flags that are common for the Tx-only and not normal connections.
  2498. */
  2499. static unsigned long bnx2x_get_common_flags(struct bnx2x *bp,
  2500. struct bnx2x_fastpath *fp,
  2501. bool zero_stats)
  2502. {
  2503. unsigned long flags = 0;
  2504. /* PF driver will always initialize the Queue to an ACTIVE state */
  2505. __set_bit(BNX2X_Q_FLG_ACTIVE, &flags);
  2506. /* tx only connections collect statistics (on the same index as the
  2507. * parent connection). The statistics are zeroed when the parent
  2508. * connection is initialized.
  2509. */
  2510. __set_bit(BNX2X_Q_FLG_STATS, &flags);
  2511. if (zero_stats)
  2512. __set_bit(BNX2X_Q_FLG_ZERO_STATS, &flags);
  2513. __set_bit(BNX2X_Q_FLG_PCSUM_ON_PKT, &flags);
  2514. __set_bit(BNX2X_Q_FLG_TUN_INC_INNER_IP_ID, &flags);
  2515. #ifdef BNX2X_STOP_ON_ERROR
  2516. __set_bit(BNX2X_Q_FLG_TX_SEC, &flags);
  2517. #endif
  2518. return flags;
  2519. }
  2520. static unsigned long bnx2x_get_q_flags(struct bnx2x *bp,
  2521. struct bnx2x_fastpath *fp,
  2522. bool leading)
  2523. {
  2524. unsigned long flags = 0;
  2525. /* calculate other queue flags */
  2526. if (IS_MF_SD(bp))
  2527. __set_bit(BNX2X_Q_FLG_OV, &flags);
  2528. if (IS_FCOE_FP(fp)) {
  2529. __set_bit(BNX2X_Q_FLG_FCOE, &flags);
  2530. /* For FCoE - force usage of default priority (for afex) */
  2531. __set_bit(BNX2X_Q_FLG_FORCE_DEFAULT_PRI, &flags);
  2532. }
  2533. if (!fp->disable_tpa) {
  2534. __set_bit(BNX2X_Q_FLG_TPA, &flags);
  2535. __set_bit(BNX2X_Q_FLG_TPA_IPV6, &flags);
  2536. if (fp->mode == TPA_MODE_GRO)
  2537. __set_bit(BNX2X_Q_FLG_TPA_GRO, &flags);
  2538. }
  2539. if (leading) {
  2540. __set_bit(BNX2X_Q_FLG_LEADING_RSS, &flags);
  2541. __set_bit(BNX2X_Q_FLG_MCAST, &flags);
  2542. }
  2543. /* Always set HW VLAN stripping */
  2544. __set_bit(BNX2X_Q_FLG_VLAN, &flags);
  2545. /* configure silent vlan removal */
  2546. if (IS_MF_AFEX(bp))
  2547. __set_bit(BNX2X_Q_FLG_SILENT_VLAN_REM, &flags);
  2548. return flags | bnx2x_get_common_flags(bp, fp, true);
  2549. }
  2550. static void bnx2x_pf_q_prep_general(struct bnx2x *bp,
  2551. struct bnx2x_fastpath *fp, struct bnx2x_general_setup_params *gen_init,
  2552. u8 cos)
  2553. {
  2554. gen_init->stat_id = bnx2x_stats_id(fp);
  2555. gen_init->spcl_id = fp->cl_id;
  2556. /* Always use mini-jumbo MTU for FCoE L2 ring */
  2557. if (IS_FCOE_FP(fp))
  2558. gen_init->mtu = BNX2X_FCOE_MINI_JUMBO_MTU;
  2559. else
  2560. gen_init->mtu = bp->dev->mtu;
  2561. gen_init->cos = cos;
  2562. }
  2563. static void bnx2x_pf_rx_q_prep(struct bnx2x *bp,
  2564. struct bnx2x_fastpath *fp, struct rxq_pause_params *pause,
  2565. struct bnx2x_rxq_setup_params *rxq_init)
  2566. {
  2567. u8 max_sge = 0;
  2568. u16 sge_sz = 0;
  2569. u16 tpa_agg_size = 0;
  2570. if (!fp->disable_tpa) {
  2571. pause->sge_th_lo = SGE_TH_LO(bp);
  2572. pause->sge_th_hi = SGE_TH_HI(bp);
  2573. /* validate SGE ring has enough to cross high threshold */
  2574. WARN_ON(bp->dropless_fc &&
  2575. pause->sge_th_hi + FW_PREFETCH_CNT >
  2576. MAX_RX_SGE_CNT * NUM_RX_SGE_PAGES);
  2577. tpa_agg_size = TPA_AGG_SIZE;
  2578. max_sge = SGE_PAGE_ALIGN(bp->dev->mtu) >>
  2579. SGE_PAGE_SHIFT;
  2580. max_sge = ((max_sge + PAGES_PER_SGE - 1) &
  2581. (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
  2582. sge_sz = (u16)min_t(u32, SGE_PAGES, 0xffff);
  2583. }
  2584. /* pause - not for e1 */
  2585. if (!CHIP_IS_E1(bp)) {
  2586. pause->bd_th_lo = BD_TH_LO(bp);
  2587. pause->bd_th_hi = BD_TH_HI(bp);
  2588. pause->rcq_th_lo = RCQ_TH_LO(bp);
  2589. pause->rcq_th_hi = RCQ_TH_HI(bp);
  2590. /*
  2591. * validate that rings have enough entries to cross
  2592. * high thresholds
  2593. */
  2594. WARN_ON(bp->dropless_fc &&
  2595. pause->bd_th_hi + FW_PREFETCH_CNT >
  2596. bp->rx_ring_size);
  2597. WARN_ON(bp->dropless_fc &&
  2598. pause->rcq_th_hi + FW_PREFETCH_CNT >
  2599. NUM_RCQ_RINGS * MAX_RCQ_DESC_CNT);
  2600. pause->pri_map = 1;
  2601. }
  2602. /* rxq setup */
  2603. rxq_init->dscr_map = fp->rx_desc_mapping;
  2604. rxq_init->sge_map = fp->rx_sge_mapping;
  2605. rxq_init->rcq_map = fp->rx_comp_mapping;
  2606. rxq_init->rcq_np_map = fp->rx_comp_mapping + BCM_PAGE_SIZE;
  2607. /* This should be a maximum number of data bytes that may be
  2608. * placed on the BD (not including paddings).
  2609. */
  2610. rxq_init->buf_sz = fp->rx_buf_size - BNX2X_FW_RX_ALIGN_START -
  2611. BNX2X_FW_RX_ALIGN_END - IP_HEADER_ALIGNMENT_PADDING;
  2612. rxq_init->cl_qzone_id = fp->cl_qzone_id;
  2613. rxq_init->tpa_agg_sz = tpa_agg_size;
  2614. rxq_init->sge_buf_sz = sge_sz;
  2615. rxq_init->max_sges_pkt = max_sge;
  2616. rxq_init->rss_engine_id = BP_FUNC(bp);
  2617. rxq_init->mcast_engine_id = BP_FUNC(bp);
  2618. /* Maximum number or simultaneous TPA aggregation for this Queue.
  2619. *
  2620. * For PF Clients it should be the maximum available number.
  2621. * VF driver(s) may want to define it to a smaller value.
  2622. */
  2623. rxq_init->max_tpa_queues = MAX_AGG_QS(bp);
  2624. rxq_init->cache_line_log = BNX2X_RX_ALIGN_SHIFT;
  2625. rxq_init->fw_sb_id = fp->fw_sb_id;
  2626. if (IS_FCOE_FP(fp))
  2627. rxq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS;
  2628. else
  2629. rxq_init->sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  2630. /* configure silent vlan removal
  2631. * if multi function mode is afex, then mask default vlan
  2632. */
  2633. if (IS_MF_AFEX(bp)) {
  2634. rxq_init->silent_removal_value = bp->afex_def_vlan_tag;
  2635. rxq_init->silent_removal_mask = VLAN_VID_MASK;
  2636. }
  2637. }
  2638. static void bnx2x_pf_tx_q_prep(struct bnx2x *bp,
  2639. struct bnx2x_fastpath *fp, struct bnx2x_txq_setup_params *txq_init,
  2640. u8 cos)
  2641. {
  2642. txq_init->dscr_map = fp->txdata_ptr[cos]->tx_desc_mapping;
  2643. txq_init->sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS + cos;
  2644. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_NW;
  2645. txq_init->fw_sb_id = fp->fw_sb_id;
  2646. /*
  2647. * set the tss leading client id for TX classification ==
  2648. * leading RSS client id
  2649. */
  2650. txq_init->tss_leading_cl_id = bnx2x_fp(bp, 0, cl_id);
  2651. if (IS_FCOE_FP(fp)) {
  2652. txq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS;
  2653. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_FCOE;
  2654. }
  2655. }
  2656. static void bnx2x_pf_init(struct bnx2x *bp)
  2657. {
  2658. struct bnx2x_func_init_params func_init = {0};
  2659. struct event_ring_data eq_data = { {0} };
  2660. u16 flags;
  2661. if (!CHIP_IS_E1x(bp)) {
  2662. /* reset IGU PF statistics: MSIX + ATTN */
  2663. /* PF */
  2664. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2665. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2666. (CHIP_MODE_IS_4_PORT(bp) ?
  2667. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2668. /* ATTN */
  2669. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2670. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2671. BNX2X_IGU_STAS_MSG_PF_CNT*4 +
  2672. (CHIP_MODE_IS_4_PORT(bp) ?
  2673. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2674. }
  2675. /* function setup flags */
  2676. flags = (FUNC_FLG_STATS | FUNC_FLG_LEADING | FUNC_FLG_SPQ);
  2677. /* This flag is relevant for E1x only.
  2678. * E2 doesn't have a TPA configuration in a function level.
  2679. */
  2680. flags |= (bp->flags & TPA_ENABLE_FLAG) ? FUNC_FLG_TPA : 0;
  2681. func_init.func_flgs = flags;
  2682. func_init.pf_id = BP_FUNC(bp);
  2683. func_init.func_id = BP_FUNC(bp);
  2684. func_init.spq_map = bp->spq_mapping;
  2685. func_init.spq_prod = bp->spq_prod_idx;
  2686. bnx2x_func_init(bp, &func_init);
  2687. memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port));
  2688. /*
  2689. * Congestion management values depend on the link rate
  2690. * There is no active link so initial link rate is set to 10 Gbps.
  2691. * When the link comes up The congestion management values are
  2692. * re-calculated according to the actual link rate.
  2693. */
  2694. bp->link_vars.line_speed = SPEED_10000;
  2695. bnx2x_cmng_fns_init(bp, true, bnx2x_get_cmng_fns_mode(bp));
  2696. /* Only the PMF sets the HW */
  2697. if (bp->port.pmf)
  2698. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2699. /* init Event Queue - PCI bus guarantees correct endianity*/
  2700. eq_data.base_addr.hi = U64_HI(bp->eq_mapping);
  2701. eq_data.base_addr.lo = U64_LO(bp->eq_mapping);
  2702. eq_data.producer = bp->eq_prod;
  2703. eq_data.index_id = HC_SP_INDEX_EQ_CONS;
  2704. eq_data.sb_id = DEF_SB_ID;
  2705. storm_memset_eq_data(bp, &eq_data, BP_FUNC(bp));
  2706. }
  2707. static void bnx2x_e1h_disable(struct bnx2x *bp)
  2708. {
  2709. int port = BP_PORT(bp);
  2710. bnx2x_tx_disable(bp);
  2711. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  2712. }
  2713. static void bnx2x_e1h_enable(struct bnx2x *bp)
  2714. {
  2715. int port = BP_PORT(bp);
  2716. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
  2717. /* Tx queue should be only re-enabled */
  2718. netif_tx_wake_all_queues(bp->dev);
  2719. /*
  2720. * Should not call netif_carrier_on since it will be called if the link
  2721. * is up when checking for link state
  2722. */
  2723. }
  2724. #define DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED 3
  2725. static void bnx2x_drv_info_ether_stat(struct bnx2x *bp)
  2726. {
  2727. struct eth_stats_info *ether_stat =
  2728. &bp->slowpath->drv_info_to_mcp.ether_stat;
  2729. struct bnx2x_vlan_mac_obj *mac_obj =
  2730. &bp->sp_objs->mac_obj;
  2731. int i;
  2732. strlcpy(ether_stat->version, DRV_MODULE_VERSION,
  2733. ETH_STAT_INFO_VERSION_LEN);
  2734. /* get DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED macs, placing them in the
  2735. * mac_local field in ether_stat struct. The base address is offset by 2
  2736. * bytes to account for the field being 8 bytes but a mac address is
  2737. * only 6 bytes. Likewise, the stride for the get_n_elements function is
  2738. * 2 bytes to compensate from the 6 bytes of a mac to the 8 bytes
  2739. * allocated by the ether_stat struct, so the macs will land in their
  2740. * proper positions.
  2741. */
  2742. for (i = 0; i < DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED; i++)
  2743. memset(ether_stat->mac_local + i, 0,
  2744. sizeof(ether_stat->mac_local[0]));
  2745. mac_obj->get_n_elements(bp, &bp->sp_objs[0].mac_obj,
  2746. DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED,
  2747. ether_stat->mac_local + MAC_PAD, MAC_PAD,
  2748. ETH_ALEN);
  2749. ether_stat->mtu_size = bp->dev->mtu;
  2750. if (bp->dev->features & NETIF_F_RXCSUM)
  2751. ether_stat->feature_flags |= FEATURE_ETH_CHKSUM_OFFLOAD_MASK;
  2752. if (bp->dev->features & NETIF_F_TSO)
  2753. ether_stat->feature_flags |= FEATURE_ETH_LSO_MASK;
  2754. ether_stat->feature_flags |= bp->common.boot_mode;
  2755. ether_stat->promiscuous_mode = (bp->dev->flags & IFF_PROMISC) ? 1 : 0;
  2756. ether_stat->txq_size = bp->tx_ring_size;
  2757. ether_stat->rxq_size = bp->rx_ring_size;
  2758. }
  2759. static void bnx2x_drv_info_fcoe_stat(struct bnx2x *bp)
  2760. {
  2761. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2762. struct fcoe_stats_info *fcoe_stat =
  2763. &bp->slowpath->drv_info_to_mcp.fcoe_stat;
  2764. if (!CNIC_LOADED(bp))
  2765. return;
  2766. memcpy(fcoe_stat->mac_local + MAC_PAD, bp->fip_mac, ETH_ALEN);
  2767. fcoe_stat->qos_priority =
  2768. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_FCOE];
  2769. /* insert FCoE stats from ramrod response */
  2770. if (!NO_FCOE(bp)) {
  2771. struct tstorm_per_queue_stats *fcoe_q_tstorm_stats =
  2772. &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
  2773. tstorm_queue_statistics;
  2774. struct xstorm_per_queue_stats *fcoe_q_xstorm_stats =
  2775. &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
  2776. xstorm_queue_statistics;
  2777. struct fcoe_statistics_params *fw_fcoe_stat =
  2778. &bp->fw_stats_data->fcoe;
  2779. ADD_64_LE(fcoe_stat->rx_bytes_hi, LE32_0,
  2780. fcoe_stat->rx_bytes_lo,
  2781. fw_fcoe_stat->rx_stat0.fcoe_rx_byte_cnt);
  2782. ADD_64_LE(fcoe_stat->rx_bytes_hi,
  2783. fcoe_q_tstorm_stats->rcv_ucast_bytes.hi,
  2784. fcoe_stat->rx_bytes_lo,
  2785. fcoe_q_tstorm_stats->rcv_ucast_bytes.lo);
  2786. ADD_64_LE(fcoe_stat->rx_bytes_hi,
  2787. fcoe_q_tstorm_stats->rcv_bcast_bytes.hi,
  2788. fcoe_stat->rx_bytes_lo,
  2789. fcoe_q_tstorm_stats->rcv_bcast_bytes.lo);
  2790. ADD_64_LE(fcoe_stat->rx_bytes_hi,
  2791. fcoe_q_tstorm_stats->rcv_mcast_bytes.hi,
  2792. fcoe_stat->rx_bytes_lo,
  2793. fcoe_q_tstorm_stats->rcv_mcast_bytes.lo);
  2794. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2795. fcoe_stat->rx_frames_lo,
  2796. fw_fcoe_stat->rx_stat0.fcoe_rx_pkt_cnt);
  2797. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2798. fcoe_stat->rx_frames_lo,
  2799. fcoe_q_tstorm_stats->rcv_ucast_pkts);
  2800. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2801. fcoe_stat->rx_frames_lo,
  2802. fcoe_q_tstorm_stats->rcv_bcast_pkts);
  2803. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2804. fcoe_stat->rx_frames_lo,
  2805. fcoe_q_tstorm_stats->rcv_mcast_pkts);
  2806. ADD_64_LE(fcoe_stat->tx_bytes_hi, LE32_0,
  2807. fcoe_stat->tx_bytes_lo,
  2808. fw_fcoe_stat->tx_stat.fcoe_tx_byte_cnt);
  2809. ADD_64_LE(fcoe_stat->tx_bytes_hi,
  2810. fcoe_q_xstorm_stats->ucast_bytes_sent.hi,
  2811. fcoe_stat->tx_bytes_lo,
  2812. fcoe_q_xstorm_stats->ucast_bytes_sent.lo);
  2813. ADD_64_LE(fcoe_stat->tx_bytes_hi,
  2814. fcoe_q_xstorm_stats->bcast_bytes_sent.hi,
  2815. fcoe_stat->tx_bytes_lo,
  2816. fcoe_q_xstorm_stats->bcast_bytes_sent.lo);
  2817. ADD_64_LE(fcoe_stat->tx_bytes_hi,
  2818. fcoe_q_xstorm_stats->mcast_bytes_sent.hi,
  2819. fcoe_stat->tx_bytes_lo,
  2820. fcoe_q_xstorm_stats->mcast_bytes_sent.lo);
  2821. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2822. fcoe_stat->tx_frames_lo,
  2823. fw_fcoe_stat->tx_stat.fcoe_tx_pkt_cnt);
  2824. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2825. fcoe_stat->tx_frames_lo,
  2826. fcoe_q_xstorm_stats->ucast_pkts_sent);
  2827. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2828. fcoe_stat->tx_frames_lo,
  2829. fcoe_q_xstorm_stats->bcast_pkts_sent);
  2830. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2831. fcoe_stat->tx_frames_lo,
  2832. fcoe_q_xstorm_stats->mcast_pkts_sent);
  2833. }
  2834. /* ask L5 driver to add data to the struct */
  2835. bnx2x_cnic_notify(bp, CNIC_CTL_FCOE_STATS_GET_CMD);
  2836. }
  2837. static void bnx2x_drv_info_iscsi_stat(struct bnx2x *bp)
  2838. {
  2839. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2840. struct iscsi_stats_info *iscsi_stat =
  2841. &bp->slowpath->drv_info_to_mcp.iscsi_stat;
  2842. if (!CNIC_LOADED(bp))
  2843. return;
  2844. memcpy(iscsi_stat->mac_local + MAC_PAD, bp->cnic_eth_dev.iscsi_mac,
  2845. ETH_ALEN);
  2846. iscsi_stat->qos_priority =
  2847. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_ISCSI];
  2848. /* ask L5 driver to add data to the struct */
  2849. bnx2x_cnic_notify(bp, CNIC_CTL_ISCSI_STATS_GET_CMD);
  2850. }
  2851. /* called due to MCP event (on pmf):
  2852. * reread new bandwidth configuration
  2853. * configure FW
  2854. * notify others function about the change
  2855. */
  2856. static void bnx2x_config_mf_bw(struct bnx2x *bp)
  2857. {
  2858. if (bp->link_vars.link_up) {
  2859. bnx2x_cmng_fns_init(bp, true, CMNG_FNS_MINMAX);
  2860. bnx2x_link_sync_notify(bp);
  2861. }
  2862. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2863. }
  2864. static void bnx2x_set_mf_bw(struct bnx2x *bp)
  2865. {
  2866. bnx2x_config_mf_bw(bp);
  2867. bnx2x_fw_command(bp, DRV_MSG_CODE_SET_MF_BW_ACK, 0);
  2868. }
  2869. static void bnx2x_handle_eee_event(struct bnx2x *bp)
  2870. {
  2871. DP(BNX2X_MSG_MCP, "EEE - LLDP event\n");
  2872. bnx2x_fw_command(bp, DRV_MSG_CODE_EEE_RESULTS_ACK, 0);
  2873. }
  2874. static void bnx2x_handle_drv_info_req(struct bnx2x *bp)
  2875. {
  2876. enum drv_info_opcode op_code;
  2877. u32 drv_info_ctl = SHMEM2_RD(bp, drv_info_control);
  2878. /* if drv_info version supported by MFW doesn't match - send NACK */
  2879. if ((drv_info_ctl & DRV_INFO_CONTROL_VER_MASK) != DRV_INFO_CUR_VER) {
  2880. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  2881. return;
  2882. }
  2883. op_code = (drv_info_ctl & DRV_INFO_CONTROL_OP_CODE_MASK) >>
  2884. DRV_INFO_CONTROL_OP_CODE_SHIFT;
  2885. memset(&bp->slowpath->drv_info_to_mcp, 0,
  2886. sizeof(union drv_info_to_mcp));
  2887. switch (op_code) {
  2888. case ETH_STATS_OPCODE:
  2889. bnx2x_drv_info_ether_stat(bp);
  2890. break;
  2891. case FCOE_STATS_OPCODE:
  2892. bnx2x_drv_info_fcoe_stat(bp);
  2893. break;
  2894. case ISCSI_STATS_OPCODE:
  2895. bnx2x_drv_info_iscsi_stat(bp);
  2896. break;
  2897. default:
  2898. /* if op code isn't supported - send NACK */
  2899. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  2900. return;
  2901. }
  2902. /* if we got drv_info attn from MFW then these fields are defined in
  2903. * shmem2 for sure
  2904. */
  2905. SHMEM2_WR(bp, drv_info_host_addr_lo,
  2906. U64_LO(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  2907. SHMEM2_WR(bp, drv_info_host_addr_hi,
  2908. U64_HI(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  2909. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_ACK, 0);
  2910. }
  2911. static void bnx2x_dcc_event(struct bnx2x *bp, u32 dcc_event)
  2912. {
  2913. DP(BNX2X_MSG_MCP, "dcc_event 0x%x\n", dcc_event);
  2914. if (dcc_event & DRV_STATUS_DCC_DISABLE_ENABLE_PF) {
  2915. /*
  2916. * This is the only place besides the function initialization
  2917. * where the bp->flags can change so it is done without any
  2918. * locks
  2919. */
  2920. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  2921. DP(BNX2X_MSG_MCP, "mf_cfg function disabled\n");
  2922. bp->flags |= MF_FUNC_DIS;
  2923. bnx2x_e1h_disable(bp);
  2924. } else {
  2925. DP(BNX2X_MSG_MCP, "mf_cfg function enabled\n");
  2926. bp->flags &= ~MF_FUNC_DIS;
  2927. bnx2x_e1h_enable(bp);
  2928. }
  2929. dcc_event &= ~DRV_STATUS_DCC_DISABLE_ENABLE_PF;
  2930. }
  2931. if (dcc_event & DRV_STATUS_DCC_BANDWIDTH_ALLOCATION) {
  2932. bnx2x_config_mf_bw(bp);
  2933. dcc_event &= ~DRV_STATUS_DCC_BANDWIDTH_ALLOCATION;
  2934. }
  2935. /* Report results to MCP */
  2936. if (dcc_event)
  2937. bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_FAILURE, 0);
  2938. else
  2939. bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_OK, 0);
  2940. }
  2941. /* must be called under the spq lock */
  2942. static struct eth_spe *bnx2x_sp_get_next(struct bnx2x *bp)
  2943. {
  2944. struct eth_spe *next_spe = bp->spq_prod_bd;
  2945. if (bp->spq_prod_bd == bp->spq_last_bd) {
  2946. bp->spq_prod_bd = bp->spq;
  2947. bp->spq_prod_idx = 0;
  2948. DP(BNX2X_MSG_SP, "end of spq\n");
  2949. } else {
  2950. bp->spq_prod_bd++;
  2951. bp->spq_prod_idx++;
  2952. }
  2953. return next_spe;
  2954. }
  2955. /* must be called under the spq lock */
  2956. static void bnx2x_sp_prod_update(struct bnx2x *bp)
  2957. {
  2958. int func = BP_FUNC(bp);
  2959. /*
  2960. * Make sure that BD data is updated before writing the producer:
  2961. * BD data is written to the memory, the producer is read from the
  2962. * memory, thus we need a full memory barrier to ensure the ordering.
  2963. */
  2964. mb();
  2965. REG_WR16(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func),
  2966. bp->spq_prod_idx);
  2967. mmiowb();
  2968. }
  2969. /**
  2970. * bnx2x_is_contextless_ramrod - check if the current command ends on EQ
  2971. *
  2972. * @cmd: command to check
  2973. * @cmd_type: command type
  2974. */
  2975. static bool bnx2x_is_contextless_ramrod(int cmd, int cmd_type)
  2976. {
  2977. if ((cmd_type == NONE_CONNECTION_TYPE) ||
  2978. (cmd == RAMROD_CMD_ID_ETH_FORWARD_SETUP) ||
  2979. (cmd == RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES) ||
  2980. (cmd == RAMROD_CMD_ID_ETH_FILTER_RULES) ||
  2981. (cmd == RAMROD_CMD_ID_ETH_MULTICAST_RULES) ||
  2982. (cmd == RAMROD_CMD_ID_ETH_SET_MAC) ||
  2983. (cmd == RAMROD_CMD_ID_ETH_RSS_UPDATE))
  2984. return true;
  2985. else
  2986. return false;
  2987. }
  2988. /**
  2989. * bnx2x_sp_post - place a single command on an SP ring
  2990. *
  2991. * @bp: driver handle
  2992. * @command: command to place (e.g. SETUP, FILTER_RULES, etc.)
  2993. * @cid: SW CID the command is related to
  2994. * @data_hi: command private data address (high 32 bits)
  2995. * @data_lo: command private data address (low 32 bits)
  2996. * @cmd_type: command type (e.g. NONE, ETH)
  2997. *
  2998. * SP data is handled as if it's always an address pair, thus data fields are
  2999. * not swapped to little endian in upper functions. Instead this function swaps
  3000. * data as if it's two u32 fields.
  3001. */
  3002. int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
  3003. u32 data_hi, u32 data_lo, int cmd_type)
  3004. {
  3005. struct eth_spe *spe;
  3006. u16 type;
  3007. bool common = bnx2x_is_contextless_ramrod(command, cmd_type);
  3008. #ifdef BNX2X_STOP_ON_ERROR
  3009. if (unlikely(bp->panic)) {
  3010. BNX2X_ERR("Can't post SP when there is panic\n");
  3011. return -EIO;
  3012. }
  3013. #endif
  3014. spin_lock_bh(&bp->spq_lock);
  3015. if (common) {
  3016. if (!atomic_read(&bp->eq_spq_left)) {
  3017. BNX2X_ERR("BUG! EQ ring full!\n");
  3018. spin_unlock_bh(&bp->spq_lock);
  3019. bnx2x_panic();
  3020. return -EBUSY;
  3021. }
  3022. } else if (!atomic_read(&bp->cq_spq_left)) {
  3023. BNX2X_ERR("BUG! SPQ ring full!\n");
  3024. spin_unlock_bh(&bp->spq_lock);
  3025. bnx2x_panic();
  3026. return -EBUSY;
  3027. }
  3028. spe = bnx2x_sp_get_next(bp);
  3029. /* CID needs port number to be encoded int it */
  3030. spe->hdr.conn_and_cmd_data =
  3031. cpu_to_le32((command << SPE_HDR_CMD_ID_SHIFT) |
  3032. HW_CID(bp, cid));
  3033. type = (cmd_type << SPE_HDR_CONN_TYPE_SHIFT) & SPE_HDR_CONN_TYPE;
  3034. type |= ((BP_FUNC(bp) << SPE_HDR_FUNCTION_ID_SHIFT) &
  3035. SPE_HDR_FUNCTION_ID);
  3036. spe->hdr.type = cpu_to_le16(type);
  3037. spe->data.update_data_addr.hi = cpu_to_le32(data_hi);
  3038. spe->data.update_data_addr.lo = cpu_to_le32(data_lo);
  3039. /*
  3040. * It's ok if the actual decrement is issued towards the memory
  3041. * somewhere between the spin_lock and spin_unlock. Thus no
  3042. * more explicit memory barrier is needed.
  3043. */
  3044. if (common)
  3045. atomic_dec(&bp->eq_spq_left);
  3046. else
  3047. atomic_dec(&bp->cq_spq_left);
  3048. DP(BNX2X_MSG_SP,
  3049. "SPQE[%x] (%x:%x) (cmd, common?) (%d,%d) hw_cid %x data (%x:%x) type(0x%x) left (CQ, EQ) (%x,%x)\n",
  3050. bp->spq_prod_idx, (u32)U64_HI(bp->spq_mapping),
  3051. (u32)(U64_LO(bp->spq_mapping) +
  3052. (void *)bp->spq_prod_bd - (void *)bp->spq), command, common,
  3053. HW_CID(bp, cid), data_hi, data_lo, type,
  3054. atomic_read(&bp->cq_spq_left), atomic_read(&bp->eq_spq_left));
  3055. bnx2x_sp_prod_update(bp);
  3056. spin_unlock_bh(&bp->spq_lock);
  3057. return 0;
  3058. }
  3059. /* acquire split MCP access lock register */
  3060. static int bnx2x_acquire_alr(struct bnx2x *bp)
  3061. {
  3062. u32 j, val;
  3063. int rc = 0;
  3064. might_sleep();
  3065. for (j = 0; j < 1000; j++) {
  3066. REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, MCPR_ACCESS_LOCK_LOCK);
  3067. val = REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK);
  3068. if (val & MCPR_ACCESS_LOCK_LOCK)
  3069. break;
  3070. usleep_range(5000, 10000);
  3071. }
  3072. if (!(val & MCPR_ACCESS_LOCK_LOCK)) {
  3073. BNX2X_ERR("Cannot acquire MCP access lock register\n");
  3074. rc = -EBUSY;
  3075. }
  3076. return rc;
  3077. }
  3078. /* release split MCP access lock register */
  3079. static void bnx2x_release_alr(struct bnx2x *bp)
  3080. {
  3081. REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, 0);
  3082. }
  3083. #define BNX2X_DEF_SB_ATT_IDX 0x0001
  3084. #define BNX2X_DEF_SB_IDX 0x0002
  3085. static u16 bnx2x_update_dsb_idx(struct bnx2x *bp)
  3086. {
  3087. struct host_sp_status_block *def_sb = bp->def_status_blk;
  3088. u16 rc = 0;
  3089. barrier(); /* status block is written to by the chip */
  3090. if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) {
  3091. bp->def_att_idx = def_sb->atten_status_block.attn_bits_index;
  3092. rc |= BNX2X_DEF_SB_ATT_IDX;
  3093. }
  3094. if (bp->def_idx != def_sb->sp_sb.running_index) {
  3095. bp->def_idx = def_sb->sp_sb.running_index;
  3096. rc |= BNX2X_DEF_SB_IDX;
  3097. }
  3098. /* Do not reorder: indices reading should complete before handling */
  3099. barrier();
  3100. return rc;
  3101. }
  3102. /*
  3103. * slow path service functions
  3104. */
  3105. static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted)
  3106. {
  3107. int port = BP_PORT(bp);
  3108. u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  3109. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  3110. u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 :
  3111. NIG_REG_MASK_INTERRUPT_PORT0;
  3112. u32 aeu_mask;
  3113. u32 nig_mask = 0;
  3114. u32 reg_addr;
  3115. if (bp->attn_state & asserted)
  3116. BNX2X_ERR("IGU ERROR\n");
  3117. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3118. aeu_mask = REG_RD(bp, aeu_addr);
  3119. DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n",
  3120. aeu_mask, asserted);
  3121. aeu_mask &= ~(asserted & 0x3ff);
  3122. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  3123. REG_WR(bp, aeu_addr, aeu_mask);
  3124. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3125. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  3126. bp->attn_state |= asserted;
  3127. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  3128. if (asserted & ATTN_HARD_WIRED_MASK) {
  3129. if (asserted & ATTN_NIG_FOR_FUNC) {
  3130. bnx2x_acquire_phy_lock(bp);
  3131. /* save nig interrupt mask */
  3132. nig_mask = REG_RD(bp, nig_int_mask_addr);
  3133. /* If nig_mask is not set, no need to call the update
  3134. * function.
  3135. */
  3136. if (nig_mask) {
  3137. REG_WR(bp, nig_int_mask_addr, 0);
  3138. bnx2x_link_attn(bp);
  3139. }
  3140. /* handle unicore attn? */
  3141. }
  3142. if (asserted & ATTN_SW_TIMER_4_FUNC)
  3143. DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n");
  3144. if (asserted & GPIO_2_FUNC)
  3145. DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n");
  3146. if (asserted & GPIO_3_FUNC)
  3147. DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n");
  3148. if (asserted & GPIO_4_FUNC)
  3149. DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n");
  3150. if (port == 0) {
  3151. if (asserted & ATTN_GENERAL_ATTN_1) {
  3152. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n");
  3153. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0);
  3154. }
  3155. if (asserted & ATTN_GENERAL_ATTN_2) {
  3156. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n");
  3157. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0);
  3158. }
  3159. if (asserted & ATTN_GENERAL_ATTN_3) {
  3160. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n");
  3161. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0);
  3162. }
  3163. } else {
  3164. if (asserted & ATTN_GENERAL_ATTN_4) {
  3165. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n");
  3166. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0);
  3167. }
  3168. if (asserted & ATTN_GENERAL_ATTN_5) {
  3169. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n");
  3170. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0);
  3171. }
  3172. if (asserted & ATTN_GENERAL_ATTN_6) {
  3173. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n");
  3174. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0);
  3175. }
  3176. }
  3177. } /* if hardwired */
  3178. if (bp->common.int_block == INT_BLOCK_HC)
  3179. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  3180. COMMAND_REG_ATTN_BITS_SET);
  3181. else
  3182. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_SET_UPPER*8);
  3183. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", asserted,
  3184. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  3185. REG_WR(bp, reg_addr, asserted);
  3186. /* now set back the mask */
  3187. if (asserted & ATTN_NIG_FOR_FUNC) {
  3188. /* Verify that IGU ack through BAR was written before restoring
  3189. * NIG mask. This loop should exit after 2-3 iterations max.
  3190. */
  3191. if (bp->common.int_block != INT_BLOCK_HC) {
  3192. u32 cnt = 0, igu_acked;
  3193. do {
  3194. igu_acked = REG_RD(bp,
  3195. IGU_REG_ATTENTION_ACK_BITS);
  3196. } while (((igu_acked & ATTN_NIG_FOR_FUNC) == 0) &&
  3197. (++cnt < MAX_IGU_ATTN_ACK_TO));
  3198. if (!igu_acked)
  3199. DP(NETIF_MSG_HW,
  3200. "Failed to verify IGU ack on time\n");
  3201. barrier();
  3202. }
  3203. REG_WR(bp, nig_int_mask_addr, nig_mask);
  3204. bnx2x_release_phy_lock(bp);
  3205. }
  3206. }
  3207. static void bnx2x_fan_failure(struct bnx2x *bp)
  3208. {
  3209. int port = BP_PORT(bp);
  3210. u32 ext_phy_config;
  3211. /* mark the failure */
  3212. ext_phy_config =
  3213. SHMEM_RD(bp,
  3214. dev_info.port_hw_config[port].external_phy_config);
  3215. ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
  3216. ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE;
  3217. SHMEM_WR(bp, dev_info.port_hw_config[port].external_phy_config,
  3218. ext_phy_config);
  3219. /* log the failure */
  3220. netdev_err(bp->dev, "Fan Failure on Network Controller has caused the driver to shutdown the card to prevent permanent damage.\n"
  3221. "Please contact OEM Support for assistance\n");
  3222. /* Schedule device reset (unload)
  3223. * This is due to some boards consuming sufficient power when driver is
  3224. * up to overheat if fan fails.
  3225. */
  3226. smp_mb__before_clear_bit();
  3227. set_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state);
  3228. smp_mb__after_clear_bit();
  3229. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  3230. }
  3231. static void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn)
  3232. {
  3233. int port = BP_PORT(bp);
  3234. int reg_offset;
  3235. u32 val;
  3236. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  3237. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  3238. if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) {
  3239. val = REG_RD(bp, reg_offset);
  3240. val &= ~AEU_INPUTS_ATTN_BITS_SPIO5;
  3241. REG_WR(bp, reg_offset, val);
  3242. BNX2X_ERR("SPIO5 hw attention\n");
  3243. /* Fan failure attention */
  3244. bnx2x_hw_reset_phy(&bp->link_params);
  3245. bnx2x_fan_failure(bp);
  3246. }
  3247. if ((attn & bp->link_vars.aeu_int_mask) && bp->port.pmf) {
  3248. bnx2x_acquire_phy_lock(bp);
  3249. bnx2x_handle_module_detect_int(&bp->link_params);
  3250. bnx2x_release_phy_lock(bp);
  3251. }
  3252. if (attn & HW_INTERRUT_ASSERT_SET_0) {
  3253. val = REG_RD(bp, reg_offset);
  3254. val &= ~(attn & HW_INTERRUT_ASSERT_SET_0);
  3255. REG_WR(bp, reg_offset, val);
  3256. BNX2X_ERR("FATAL HW block attention set0 0x%x\n",
  3257. (u32)(attn & HW_INTERRUT_ASSERT_SET_0));
  3258. bnx2x_panic();
  3259. }
  3260. }
  3261. static void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn)
  3262. {
  3263. u32 val;
  3264. if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) {
  3265. val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR);
  3266. BNX2X_ERR("DB hw attention 0x%x\n", val);
  3267. /* DORQ discard attention */
  3268. if (val & 0x2)
  3269. BNX2X_ERR("FATAL error from DORQ\n");
  3270. }
  3271. if (attn & HW_INTERRUT_ASSERT_SET_1) {
  3272. int port = BP_PORT(bp);
  3273. int reg_offset;
  3274. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 :
  3275. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1);
  3276. val = REG_RD(bp, reg_offset);
  3277. val &= ~(attn & HW_INTERRUT_ASSERT_SET_1);
  3278. REG_WR(bp, reg_offset, val);
  3279. BNX2X_ERR("FATAL HW block attention set1 0x%x\n",
  3280. (u32)(attn & HW_INTERRUT_ASSERT_SET_1));
  3281. bnx2x_panic();
  3282. }
  3283. }
  3284. static void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn)
  3285. {
  3286. u32 val;
  3287. if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) {
  3288. val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR);
  3289. BNX2X_ERR("CFC hw attention 0x%x\n", val);
  3290. /* CFC error attention */
  3291. if (val & 0x2)
  3292. BNX2X_ERR("FATAL error from CFC\n");
  3293. }
  3294. if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) {
  3295. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0);
  3296. BNX2X_ERR("PXP hw attention-0 0x%x\n", val);
  3297. /* RQ_USDMDP_FIFO_OVERFLOW */
  3298. if (val & 0x18000)
  3299. BNX2X_ERR("FATAL error from PXP\n");
  3300. if (!CHIP_IS_E1x(bp)) {
  3301. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_1);
  3302. BNX2X_ERR("PXP hw attention-1 0x%x\n", val);
  3303. }
  3304. }
  3305. if (attn & HW_INTERRUT_ASSERT_SET_2) {
  3306. int port = BP_PORT(bp);
  3307. int reg_offset;
  3308. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 :
  3309. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2);
  3310. val = REG_RD(bp, reg_offset);
  3311. val &= ~(attn & HW_INTERRUT_ASSERT_SET_2);
  3312. REG_WR(bp, reg_offset, val);
  3313. BNX2X_ERR("FATAL HW block attention set2 0x%x\n",
  3314. (u32)(attn & HW_INTERRUT_ASSERT_SET_2));
  3315. bnx2x_panic();
  3316. }
  3317. }
  3318. static void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn)
  3319. {
  3320. u32 val;
  3321. if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) {
  3322. if (attn & BNX2X_PMF_LINK_ASSERT) {
  3323. int func = BP_FUNC(bp);
  3324. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  3325. bnx2x_read_mf_cfg(bp);
  3326. bp->mf_config[BP_VN(bp)] = MF_CFG_RD(bp,
  3327. func_mf_config[BP_ABS_FUNC(bp)].config);
  3328. val = SHMEM_RD(bp,
  3329. func_mb[BP_FW_MB_IDX(bp)].drv_status);
  3330. if (val & DRV_STATUS_DCC_EVENT_MASK)
  3331. bnx2x_dcc_event(bp,
  3332. (val & DRV_STATUS_DCC_EVENT_MASK));
  3333. if (val & DRV_STATUS_SET_MF_BW)
  3334. bnx2x_set_mf_bw(bp);
  3335. if (val & DRV_STATUS_DRV_INFO_REQ)
  3336. bnx2x_handle_drv_info_req(bp);
  3337. if (val & DRV_STATUS_VF_DISABLED)
  3338. bnx2x_vf_handle_flr_event(bp);
  3339. if ((bp->port.pmf == 0) && (val & DRV_STATUS_PMF))
  3340. bnx2x_pmf_update(bp);
  3341. if (bp->port.pmf &&
  3342. (val & DRV_STATUS_DCBX_NEGOTIATION_RESULTS) &&
  3343. bp->dcbx_enabled > 0)
  3344. /* start dcbx state machine */
  3345. bnx2x_dcbx_set_params(bp,
  3346. BNX2X_DCBX_STATE_NEG_RECEIVED);
  3347. if (val & DRV_STATUS_AFEX_EVENT_MASK)
  3348. bnx2x_handle_afex_cmd(bp,
  3349. val & DRV_STATUS_AFEX_EVENT_MASK);
  3350. if (val & DRV_STATUS_EEE_NEGOTIATION_RESULTS)
  3351. bnx2x_handle_eee_event(bp);
  3352. if (bp->link_vars.periodic_flags &
  3353. PERIODIC_FLAGS_LINK_EVENT) {
  3354. /* sync with link */
  3355. bnx2x_acquire_phy_lock(bp);
  3356. bp->link_vars.periodic_flags &=
  3357. ~PERIODIC_FLAGS_LINK_EVENT;
  3358. bnx2x_release_phy_lock(bp);
  3359. if (IS_MF(bp))
  3360. bnx2x_link_sync_notify(bp);
  3361. bnx2x_link_report(bp);
  3362. }
  3363. /* Always call it here: bnx2x_link_report() will
  3364. * prevent the link indication duplication.
  3365. */
  3366. bnx2x__link_status_update(bp);
  3367. } else if (attn & BNX2X_MC_ASSERT_BITS) {
  3368. BNX2X_ERR("MC assert!\n");
  3369. bnx2x_mc_assert(bp);
  3370. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0);
  3371. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0);
  3372. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0);
  3373. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0);
  3374. bnx2x_panic();
  3375. } else if (attn & BNX2X_MCP_ASSERT) {
  3376. BNX2X_ERR("MCP assert!\n");
  3377. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0);
  3378. bnx2x_fw_dump(bp);
  3379. } else
  3380. BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn);
  3381. }
  3382. if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) {
  3383. BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn);
  3384. if (attn & BNX2X_GRC_TIMEOUT) {
  3385. val = CHIP_IS_E1(bp) ? 0 :
  3386. REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN);
  3387. BNX2X_ERR("GRC time-out 0x%08x\n", val);
  3388. }
  3389. if (attn & BNX2X_GRC_RSV) {
  3390. val = CHIP_IS_E1(bp) ? 0 :
  3391. REG_RD(bp, MISC_REG_GRC_RSV_ATTN);
  3392. BNX2X_ERR("GRC reserved 0x%08x\n", val);
  3393. }
  3394. REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff);
  3395. }
  3396. }
  3397. /*
  3398. * Bits map:
  3399. * 0-7 - Engine0 load counter.
  3400. * 8-15 - Engine1 load counter.
  3401. * 16 - Engine0 RESET_IN_PROGRESS bit.
  3402. * 17 - Engine1 RESET_IN_PROGRESS bit.
  3403. * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active function
  3404. * on the engine
  3405. * 19 - Engine1 ONE_IS_LOADED.
  3406. * 20 - Chip reset flow bit. When set none-leader must wait for both engines
  3407. * leader to complete (check for both RESET_IN_PROGRESS bits and not for
  3408. * just the one belonging to its engine).
  3409. *
  3410. */
  3411. #define BNX2X_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1
  3412. #define BNX2X_PATH0_LOAD_CNT_MASK 0x000000ff
  3413. #define BNX2X_PATH0_LOAD_CNT_SHIFT 0
  3414. #define BNX2X_PATH1_LOAD_CNT_MASK 0x0000ff00
  3415. #define BNX2X_PATH1_LOAD_CNT_SHIFT 8
  3416. #define BNX2X_PATH0_RST_IN_PROG_BIT 0x00010000
  3417. #define BNX2X_PATH1_RST_IN_PROG_BIT 0x00020000
  3418. #define BNX2X_GLOBAL_RESET_BIT 0x00040000
  3419. /*
  3420. * Set the GLOBAL_RESET bit.
  3421. *
  3422. * Should be run under rtnl lock
  3423. */
  3424. void bnx2x_set_reset_global(struct bnx2x *bp)
  3425. {
  3426. u32 val;
  3427. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3428. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3429. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val | BNX2X_GLOBAL_RESET_BIT);
  3430. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3431. }
  3432. /*
  3433. * Clear the GLOBAL_RESET bit.
  3434. *
  3435. * Should be run under rtnl lock
  3436. */
  3437. static void bnx2x_clear_reset_global(struct bnx2x *bp)
  3438. {
  3439. u32 val;
  3440. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3441. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3442. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~BNX2X_GLOBAL_RESET_BIT));
  3443. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3444. }
  3445. /*
  3446. * Checks the GLOBAL_RESET bit.
  3447. *
  3448. * should be run under rtnl lock
  3449. */
  3450. static bool bnx2x_reset_is_global(struct bnx2x *bp)
  3451. {
  3452. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3453. DP(NETIF_MSG_HW, "GEN_REG_VAL=0x%08x\n", val);
  3454. return (val & BNX2X_GLOBAL_RESET_BIT) ? true : false;
  3455. }
  3456. /*
  3457. * Clear RESET_IN_PROGRESS bit for the current engine.
  3458. *
  3459. * Should be run under rtnl lock
  3460. */
  3461. static void bnx2x_set_reset_done(struct bnx2x *bp)
  3462. {
  3463. u32 val;
  3464. u32 bit = BP_PATH(bp) ?
  3465. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3466. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3467. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3468. /* Clear the bit */
  3469. val &= ~bit;
  3470. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3471. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3472. }
  3473. /*
  3474. * Set RESET_IN_PROGRESS for the current engine.
  3475. *
  3476. * should be run under rtnl lock
  3477. */
  3478. void bnx2x_set_reset_in_progress(struct bnx2x *bp)
  3479. {
  3480. u32 val;
  3481. u32 bit = BP_PATH(bp) ?
  3482. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3483. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3484. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3485. /* Set the bit */
  3486. val |= bit;
  3487. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3488. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3489. }
  3490. /*
  3491. * Checks the RESET_IN_PROGRESS bit for the given engine.
  3492. * should be run under rtnl lock
  3493. */
  3494. bool bnx2x_reset_is_done(struct bnx2x *bp, int engine)
  3495. {
  3496. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3497. u32 bit = engine ?
  3498. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3499. /* return false if bit is set */
  3500. return (val & bit) ? false : true;
  3501. }
  3502. /*
  3503. * set pf load for the current pf.
  3504. *
  3505. * should be run under rtnl lock
  3506. */
  3507. void bnx2x_set_pf_load(struct bnx2x *bp)
  3508. {
  3509. u32 val1, val;
  3510. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3511. BNX2X_PATH0_LOAD_CNT_MASK;
  3512. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3513. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3514. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3515. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3516. DP(NETIF_MSG_IFUP, "Old GEN_REG_VAL=0x%08x\n", val);
  3517. /* get the current counter value */
  3518. val1 = (val & mask) >> shift;
  3519. /* set bit of that PF */
  3520. val1 |= (1 << bp->pf_num);
  3521. /* clear the old value */
  3522. val &= ~mask;
  3523. /* set the new one */
  3524. val |= ((val1 << shift) & mask);
  3525. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3526. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3527. }
  3528. /**
  3529. * bnx2x_clear_pf_load - clear pf load mark
  3530. *
  3531. * @bp: driver handle
  3532. *
  3533. * Should be run under rtnl lock.
  3534. * Decrements the load counter for the current engine. Returns
  3535. * whether other functions are still loaded
  3536. */
  3537. bool bnx2x_clear_pf_load(struct bnx2x *bp)
  3538. {
  3539. u32 val1, val;
  3540. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3541. BNX2X_PATH0_LOAD_CNT_MASK;
  3542. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3543. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3544. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3545. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3546. DP(NETIF_MSG_IFDOWN, "Old GEN_REG_VAL=0x%08x\n", val);
  3547. /* get the current counter value */
  3548. val1 = (val & mask) >> shift;
  3549. /* clear bit of that PF */
  3550. val1 &= ~(1 << bp->pf_num);
  3551. /* clear the old value */
  3552. val &= ~mask;
  3553. /* set the new one */
  3554. val |= ((val1 << shift) & mask);
  3555. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3556. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3557. return val1 != 0;
  3558. }
  3559. /*
  3560. * Read the load status for the current engine.
  3561. *
  3562. * should be run under rtnl lock
  3563. */
  3564. static bool bnx2x_get_load_status(struct bnx2x *bp, int engine)
  3565. {
  3566. u32 mask = (engine ? BNX2X_PATH1_LOAD_CNT_MASK :
  3567. BNX2X_PATH0_LOAD_CNT_MASK);
  3568. u32 shift = (engine ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3569. BNX2X_PATH0_LOAD_CNT_SHIFT);
  3570. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3571. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "GLOB_REG=0x%08x\n", val);
  3572. val = (val & mask) >> shift;
  3573. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "load mask for engine %d = 0x%x\n",
  3574. engine, val);
  3575. return val != 0;
  3576. }
  3577. static void _print_parity(struct bnx2x *bp, u32 reg)
  3578. {
  3579. pr_cont(" [0x%08x] ", REG_RD(bp, reg));
  3580. }
  3581. static void _print_next_block(int idx, const char *blk)
  3582. {
  3583. pr_cont("%s%s", idx ? ", " : "", blk);
  3584. }
  3585. static int bnx2x_check_blocks_with_parity0(struct bnx2x *bp, u32 sig,
  3586. int par_num, bool print)
  3587. {
  3588. int i = 0;
  3589. u32 cur_bit = 0;
  3590. for (i = 0; sig; i++) {
  3591. cur_bit = ((u32)0x1 << i);
  3592. if (sig & cur_bit) {
  3593. switch (cur_bit) {
  3594. case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR:
  3595. if (print) {
  3596. _print_next_block(par_num++, "BRB");
  3597. _print_parity(bp,
  3598. BRB1_REG_BRB1_PRTY_STS);
  3599. }
  3600. break;
  3601. case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR:
  3602. if (print) {
  3603. _print_next_block(par_num++, "PARSER");
  3604. _print_parity(bp, PRS_REG_PRS_PRTY_STS);
  3605. }
  3606. break;
  3607. case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR:
  3608. if (print) {
  3609. _print_next_block(par_num++, "TSDM");
  3610. _print_parity(bp,
  3611. TSDM_REG_TSDM_PRTY_STS);
  3612. }
  3613. break;
  3614. case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR:
  3615. if (print) {
  3616. _print_next_block(par_num++,
  3617. "SEARCHER");
  3618. _print_parity(bp, SRC_REG_SRC_PRTY_STS);
  3619. }
  3620. break;
  3621. case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR:
  3622. if (print) {
  3623. _print_next_block(par_num++, "TCM");
  3624. _print_parity(bp,
  3625. TCM_REG_TCM_PRTY_STS);
  3626. }
  3627. break;
  3628. case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR:
  3629. if (print) {
  3630. _print_next_block(par_num++, "TSEMI");
  3631. _print_parity(bp,
  3632. TSEM_REG_TSEM_PRTY_STS_0);
  3633. _print_parity(bp,
  3634. TSEM_REG_TSEM_PRTY_STS_1);
  3635. }
  3636. break;
  3637. case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR:
  3638. if (print) {
  3639. _print_next_block(par_num++, "XPB");
  3640. _print_parity(bp, GRCBASE_XPB +
  3641. PB_REG_PB_PRTY_STS);
  3642. }
  3643. break;
  3644. }
  3645. /* Clear the bit */
  3646. sig &= ~cur_bit;
  3647. }
  3648. }
  3649. return par_num;
  3650. }
  3651. static int bnx2x_check_blocks_with_parity1(struct bnx2x *bp, u32 sig,
  3652. int par_num, bool *global,
  3653. bool print)
  3654. {
  3655. int i = 0;
  3656. u32 cur_bit = 0;
  3657. for (i = 0; sig; i++) {
  3658. cur_bit = ((u32)0x1 << i);
  3659. if (sig & cur_bit) {
  3660. switch (cur_bit) {
  3661. case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR:
  3662. if (print) {
  3663. _print_next_block(par_num++, "PBF");
  3664. _print_parity(bp, PBF_REG_PBF_PRTY_STS);
  3665. }
  3666. break;
  3667. case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR:
  3668. if (print) {
  3669. _print_next_block(par_num++, "QM");
  3670. _print_parity(bp, QM_REG_QM_PRTY_STS);
  3671. }
  3672. break;
  3673. case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR:
  3674. if (print) {
  3675. _print_next_block(par_num++, "TM");
  3676. _print_parity(bp, TM_REG_TM_PRTY_STS);
  3677. }
  3678. break;
  3679. case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR:
  3680. if (print) {
  3681. _print_next_block(par_num++, "XSDM");
  3682. _print_parity(bp,
  3683. XSDM_REG_XSDM_PRTY_STS);
  3684. }
  3685. break;
  3686. case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR:
  3687. if (print) {
  3688. _print_next_block(par_num++, "XCM");
  3689. _print_parity(bp, XCM_REG_XCM_PRTY_STS);
  3690. }
  3691. break;
  3692. case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR:
  3693. if (print) {
  3694. _print_next_block(par_num++, "XSEMI");
  3695. _print_parity(bp,
  3696. XSEM_REG_XSEM_PRTY_STS_0);
  3697. _print_parity(bp,
  3698. XSEM_REG_XSEM_PRTY_STS_1);
  3699. }
  3700. break;
  3701. case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR:
  3702. if (print) {
  3703. _print_next_block(par_num++,
  3704. "DOORBELLQ");
  3705. _print_parity(bp,
  3706. DORQ_REG_DORQ_PRTY_STS);
  3707. }
  3708. break;
  3709. case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR:
  3710. if (print) {
  3711. _print_next_block(par_num++, "NIG");
  3712. if (CHIP_IS_E1x(bp)) {
  3713. _print_parity(bp,
  3714. NIG_REG_NIG_PRTY_STS);
  3715. } else {
  3716. _print_parity(bp,
  3717. NIG_REG_NIG_PRTY_STS_0);
  3718. _print_parity(bp,
  3719. NIG_REG_NIG_PRTY_STS_1);
  3720. }
  3721. }
  3722. break;
  3723. case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR:
  3724. if (print)
  3725. _print_next_block(par_num++,
  3726. "VAUX PCI CORE");
  3727. *global = true;
  3728. break;
  3729. case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR:
  3730. if (print) {
  3731. _print_next_block(par_num++, "DEBUG");
  3732. _print_parity(bp, DBG_REG_DBG_PRTY_STS);
  3733. }
  3734. break;
  3735. case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR:
  3736. if (print) {
  3737. _print_next_block(par_num++, "USDM");
  3738. _print_parity(bp,
  3739. USDM_REG_USDM_PRTY_STS);
  3740. }
  3741. break;
  3742. case AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR:
  3743. if (print) {
  3744. _print_next_block(par_num++, "UCM");
  3745. _print_parity(bp, UCM_REG_UCM_PRTY_STS);
  3746. }
  3747. break;
  3748. case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR:
  3749. if (print) {
  3750. _print_next_block(par_num++, "USEMI");
  3751. _print_parity(bp,
  3752. USEM_REG_USEM_PRTY_STS_0);
  3753. _print_parity(bp,
  3754. USEM_REG_USEM_PRTY_STS_1);
  3755. }
  3756. break;
  3757. case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR:
  3758. if (print) {
  3759. _print_next_block(par_num++, "UPB");
  3760. _print_parity(bp, GRCBASE_UPB +
  3761. PB_REG_PB_PRTY_STS);
  3762. }
  3763. break;
  3764. case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR:
  3765. if (print) {
  3766. _print_next_block(par_num++, "CSDM");
  3767. _print_parity(bp,
  3768. CSDM_REG_CSDM_PRTY_STS);
  3769. }
  3770. break;
  3771. case AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR:
  3772. if (print) {
  3773. _print_next_block(par_num++, "CCM");
  3774. _print_parity(bp, CCM_REG_CCM_PRTY_STS);
  3775. }
  3776. break;
  3777. }
  3778. /* Clear the bit */
  3779. sig &= ~cur_bit;
  3780. }
  3781. }
  3782. return par_num;
  3783. }
  3784. static int bnx2x_check_blocks_with_parity2(struct bnx2x *bp, u32 sig,
  3785. int par_num, bool print)
  3786. {
  3787. int i = 0;
  3788. u32 cur_bit = 0;
  3789. for (i = 0; sig; i++) {
  3790. cur_bit = ((u32)0x1 << i);
  3791. if (sig & cur_bit) {
  3792. switch (cur_bit) {
  3793. case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR:
  3794. if (print) {
  3795. _print_next_block(par_num++, "CSEMI");
  3796. _print_parity(bp,
  3797. CSEM_REG_CSEM_PRTY_STS_0);
  3798. _print_parity(bp,
  3799. CSEM_REG_CSEM_PRTY_STS_1);
  3800. }
  3801. break;
  3802. case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR:
  3803. if (print) {
  3804. _print_next_block(par_num++, "PXP");
  3805. _print_parity(bp, PXP_REG_PXP_PRTY_STS);
  3806. _print_parity(bp,
  3807. PXP2_REG_PXP2_PRTY_STS_0);
  3808. _print_parity(bp,
  3809. PXP2_REG_PXP2_PRTY_STS_1);
  3810. }
  3811. break;
  3812. case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR:
  3813. if (print)
  3814. _print_next_block(par_num++,
  3815. "PXPPCICLOCKCLIENT");
  3816. break;
  3817. case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR:
  3818. if (print) {
  3819. _print_next_block(par_num++, "CFC");
  3820. _print_parity(bp,
  3821. CFC_REG_CFC_PRTY_STS);
  3822. }
  3823. break;
  3824. case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR:
  3825. if (print) {
  3826. _print_next_block(par_num++, "CDU");
  3827. _print_parity(bp, CDU_REG_CDU_PRTY_STS);
  3828. }
  3829. break;
  3830. case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR:
  3831. if (print) {
  3832. _print_next_block(par_num++, "DMAE");
  3833. _print_parity(bp,
  3834. DMAE_REG_DMAE_PRTY_STS);
  3835. }
  3836. break;
  3837. case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR:
  3838. if (print) {
  3839. _print_next_block(par_num++, "IGU");
  3840. if (CHIP_IS_E1x(bp))
  3841. _print_parity(bp,
  3842. HC_REG_HC_PRTY_STS);
  3843. else
  3844. _print_parity(bp,
  3845. IGU_REG_IGU_PRTY_STS);
  3846. }
  3847. break;
  3848. case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR:
  3849. if (print) {
  3850. _print_next_block(par_num++, "MISC");
  3851. _print_parity(bp,
  3852. MISC_REG_MISC_PRTY_STS);
  3853. }
  3854. break;
  3855. }
  3856. /* Clear the bit */
  3857. sig &= ~cur_bit;
  3858. }
  3859. }
  3860. return par_num;
  3861. }
  3862. static int bnx2x_check_blocks_with_parity3(u32 sig, int par_num,
  3863. bool *global, bool print)
  3864. {
  3865. int i = 0;
  3866. u32 cur_bit = 0;
  3867. for (i = 0; sig; i++) {
  3868. cur_bit = ((u32)0x1 << i);
  3869. if (sig & cur_bit) {
  3870. switch (cur_bit) {
  3871. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY:
  3872. if (print)
  3873. _print_next_block(par_num++, "MCP ROM");
  3874. *global = true;
  3875. break;
  3876. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY:
  3877. if (print)
  3878. _print_next_block(par_num++,
  3879. "MCP UMP RX");
  3880. *global = true;
  3881. break;
  3882. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY:
  3883. if (print)
  3884. _print_next_block(par_num++,
  3885. "MCP UMP TX");
  3886. *global = true;
  3887. break;
  3888. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY:
  3889. if (print)
  3890. _print_next_block(par_num++,
  3891. "MCP SCPAD");
  3892. *global = true;
  3893. break;
  3894. }
  3895. /* Clear the bit */
  3896. sig &= ~cur_bit;
  3897. }
  3898. }
  3899. return par_num;
  3900. }
  3901. static int bnx2x_check_blocks_with_parity4(struct bnx2x *bp, u32 sig,
  3902. int par_num, bool print)
  3903. {
  3904. int i = 0;
  3905. u32 cur_bit = 0;
  3906. for (i = 0; sig; i++) {
  3907. cur_bit = ((u32)0x1 << i);
  3908. if (sig & cur_bit) {
  3909. switch (cur_bit) {
  3910. case AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR:
  3911. if (print) {
  3912. _print_next_block(par_num++, "PGLUE_B");
  3913. _print_parity(bp,
  3914. PGLUE_B_REG_PGLUE_B_PRTY_STS);
  3915. }
  3916. break;
  3917. case AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR:
  3918. if (print) {
  3919. _print_next_block(par_num++, "ATC");
  3920. _print_parity(bp,
  3921. ATC_REG_ATC_PRTY_STS);
  3922. }
  3923. break;
  3924. }
  3925. /* Clear the bit */
  3926. sig &= ~cur_bit;
  3927. }
  3928. }
  3929. return par_num;
  3930. }
  3931. static bool bnx2x_parity_attn(struct bnx2x *bp, bool *global, bool print,
  3932. u32 *sig)
  3933. {
  3934. if ((sig[0] & HW_PRTY_ASSERT_SET_0) ||
  3935. (sig[1] & HW_PRTY_ASSERT_SET_1) ||
  3936. (sig[2] & HW_PRTY_ASSERT_SET_2) ||
  3937. (sig[3] & HW_PRTY_ASSERT_SET_3) ||
  3938. (sig[4] & HW_PRTY_ASSERT_SET_4)) {
  3939. int par_num = 0;
  3940. DP(NETIF_MSG_HW, "Was parity error: HW block parity attention:\n"
  3941. "[0]:0x%08x [1]:0x%08x [2]:0x%08x [3]:0x%08x [4]:0x%08x\n",
  3942. sig[0] & HW_PRTY_ASSERT_SET_0,
  3943. sig[1] & HW_PRTY_ASSERT_SET_1,
  3944. sig[2] & HW_PRTY_ASSERT_SET_2,
  3945. sig[3] & HW_PRTY_ASSERT_SET_3,
  3946. sig[4] & HW_PRTY_ASSERT_SET_4);
  3947. if (print)
  3948. netdev_err(bp->dev,
  3949. "Parity errors detected in blocks: ");
  3950. par_num = bnx2x_check_blocks_with_parity0(bp,
  3951. sig[0] & HW_PRTY_ASSERT_SET_0, par_num, print);
  3952. par_num = bnx2x_check_blocks_with_parity1(bp,
  3953. sig[1] & HW_PRTY_ASSERT_SET_1, par_num, global, print);
  3954. par_num = bnx2x_check_blocks_with_parity2(bp,
  3955. sig[2] & HW_PRTY_ASSERT_SET_2, par_num, print);
  3956. par_num = bnx2x_check_blocks_with_parity3(
  3957. sig[3] & HW_PRTY_ASSERT_SET_3, par_num, global, print);
  3958. par_num = bnx2x_check_blocks_with_parity4(bp,
  3959. sig[4] & HW_PRTY_ASSERT_SET_4, par_num, print);
  3960. if (print)
  3961. pr_cont("\n");
  3962. return true;
  3963. } else
  3964. return false;
  3965. }
  3966. /**
  3967. * bnx2x_chk_parity_attn - checks for parity attentions.
  3968. *
  3969. * @bp: driver handle
  3970. * @global: true if there was a global attention
  3971. * @print: show parity attention in syslog
  3972. */
  3973. bool bnx2x_chk_parity_attn(struct bnx2x *bp, bool *global, bool print)
  3974. {
  3975. struct attn_route attn = { {0} };
  3976. int port = BP_PORT(bp);
  3977. attn.sig[0] = REG_RD(bp,
  3978. MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 +
  3979. port*4);
  3980. attn.sig[1] = REG_RD(bp,
  3981. MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 +
  3982. port*4);
  3983. attn.sig[2] = REG_RD(bp,
  3984. MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 +
  3985. port*4);
  3986. attn.sig[3] = REG_RD(bp,
  3987. MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 +
  3988. port*4);
  3989. /* Since MCP attentions can't be disabled inside the block, we need to
  3990. * read AEU registers to see whether they're currently disabled
  3991. */
  3992. attn.sig[3] &= ((REG_RD(bp,
  3993. !port ? MISC_REG_AEU_ENABLE4_FUNC_0_OUT_0
  3994. : MISC_REG_AEU_ENABLE4_FUNC_1_OUT_0) &
  3995. MISC_AEU_ENABLE_MCP_PRTY_BITS) |
  3996. ~MISC_AEU_ENABLE_MCP_PRTY_BITS);
  3997. if (!CHIP_IS_E1x(bp))
  3998. attn.sig[4] = REG_RD(bp,
  3999. MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 +
  4000. port*4);
  4001. return bnx2x_parity_attn(bp, global, print, attn.sig);
  4002. }
  4003. static void bnx2x_attn_int_deasserted4(struct bnx2x *bp, u32 attn)
  4004. {
  4005. u32 val;
  4006. if (attn & AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT) {
  4007. val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS_CLR);
  4008. BNX2X_ERR("PGLUE hw attention 0x%x\n", val);
  4009. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR)
  4010. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR\n");
  4011. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR)
  4012. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR\n");
  4013. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN)
  4014. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN\n");
  4015. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN)
  4016. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN\n");
  4017. if (val &
  4018. PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN)
  4019. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN\n");
  4020. if (val &
  4021. PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN)
  4022. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN\n");
  4023. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN)
  4024. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN\n");
  4025. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN)
  4026. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN\n");
  4027. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW)
  4028. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW\n");
  4029. }
  4030. if (attn & AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT) {
  4031. val = REG_RD(bp, ATC_REG_ATC_INT_STS_CLR);
  4032. BNX2X_ERR("ATC hw attention 0x%x\n", val);
  4033. if (val & ATC_ATC_INT_STS_REG_ADDRESS_ERROR)
  4034. BNX2X_ERR("ATC_ATC_INT_STS_REG_ADDRESS_ERROR\n");
  4035. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND)
  4036. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND\n");
  4037. if (val & ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS)
  4038. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS\n");
  4039. if (val & ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT)
  4040. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT\n");
  4041. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR)
  4042. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR\n");
  4043. if (val & ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU)
  4044. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU\n");
  4045. }
  4046. if (attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  4047. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)) {
  4048. BNX2X_ERR("FATAL parity attention set4 0x%x\n",
  4049. (u32)(attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  4050. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)));
  4051. }
  4052. }
  4053. static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted)
  4054. {
  4055. struct attn_route attn, *group_mask;
  4056. int port = BP_PORT(bp);
  4057. int index;
  4058. u32 reg_addr;
  4059. u32 val;
  4060. u32 aeu_mask;
  4061. bool global = false;
  4062. /* need to take HW lock because MCP or other port might also
  4063. try to handle this event */
  4064. bnx2x_acquire_alr(bp);
  4065. if (bnx2x_chk_parity_attn(bp, &global, true)) {
  4066. #ifndef BNX2X_STOP_ON_ERROR
  4067. bp->recovery_state = BNX2X_RECOVERY_INIT;
  4068. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  4069. /* Disable HW interrupts */
  4070. bnx2x_int_disable(bp);
  4071. /* In case of parity errors don't handle attentions so that
  4072. * other function would "see" parity errors.
  4073. */
  4074. #else
  4075. bnx2x_panic();
  4076. #endif
  4077. bnx2x_release_alr(bp);
  4078. return;
  4079. }
  4080. attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
  4081. attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
  4082. attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
  4083. attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
  4084. if (!CHIP_IS_E1x(bp))
  4085. attn.sig[4] =
  4086. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4);
  4087. else
  4088. attn.sig[4] = 0;
  4089. DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x %08x\n",
  4090. attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3], attn.sig[4]);
  4091. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  4092. if (deasserted & (1 << index)) {
  4093. group_mask = &bp->attn_group[index];
  4094. DP(NETIF_MSG_HW, "group[%d]: %08x %08x %08x %08x %08x\n",
  4095. index,
  4096. group_mask->sig[0], group_mask->sig[1],
  4097. group_mask->sig[2], group_mask->sig[3],
  4098. group_mask->sig[4]);
  4099. bnx2x_attn_int_deasserted4(bp,
  4100. attn.sig[4] & group_mask->sig[4]);
  4101. bnx2x_attn_int_deasserted3(bp,
  4102. attn.sig[3] & group_mask->sig[3]);
  4103. bnx2x_attn_int_deasserted1(bp,
  4104. attn.sig[1] & group_mask->sig[1]);
  4105. bnx2x_attn_int_deasserted2(bp,
  4106. attn.sig[2] & group_mask->sig[2]);
  4107. bnx2x_attn_int_deasserted0(bp,
  4108. attn.sig[0] & group_mask->sig[0]);
  4109. }
  4110. }
  4111. bnx2x_release_alr(bp);
  4112. if (bp->common.int_block == INT_BLOCK_HC)
  4113. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  4114. COMMAND_REG_ATTN_BITS_CLR);
  4115. else
  4116. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_CLR_UPPER*8);
  4117. val = ~deasserted;
  4118. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", val,
  4119. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  4120. REG_WR(bp, reg_addr, val);
  4121. if (~bp->attn_state & deasserted)
  4122. BNX2X_ERR("IGU ERROR\n");
  4123. reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  4124. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  4125. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  4126. aeu_mask = REG_RD(bp, reg_addr);
  4127. DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n",
  4128. aeu_mask, deasserted);
  4129. aeu_mask |= (deasserted & 0x3ff);
  4130. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  4131. REG_WR(bp, reg_addr, aeu_mask);
  4132. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  4133. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  4134. bp->attn_state &= ~deasserted;
  4135. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  4136. }
  4137. static void bnx2x_attn_int(struct bnx2x *bp)
  4138. {
  4139. /* read local copy of bits */
  4140. u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block.
  4141. attn_bits);
  4142. u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block.
  4143. attn_bits_ack);
  4144. u32 attn_state = bp->attn_state;
  4145. /* look for changed bits */
  4146. u32 asserted = attn_bits & ~attn_ack & ~attn_state;
  4147. u32 deasserted = ~attn_bits & attn_ack & attn_state;
  4148. DP(NETIF_MSG_HW,
  4149. "attn_bits %x attn_ack %x asserted %x deasserted %x\n",
  4150. attn_bits, attn_ack, asserted, deasserted);
  4151. if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state))
  4152. BNX2X_ERR("BAD attention state\n");
  4153. /* handle bits that were raised */
  4154. if (asserted)
  4155. bnx2x_attn_int_asserted(bp, asserted);
  4156. if (deasserted)
  4157. bnx2x_attn_int_deasserted(bp, deasserted);
  4158. }
  4159. void bnx2x_igu_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 segment,
  4160. u16 index, u8 op, u8 update)
  4161. {
  4162. u32 igu_addr = bp->igu_base_addr;
  4163. igu_addr += (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8;
  4164. bnx2x_igu_ack_sb_gen(bp, igu_sb_id, segment, index, op, update,
  4165. igu_addr);
  4166. }
  4167. static void bnx2x_update_eq_prod(struct bnx2x *bp, u16 prod)
  4168. {
  4169. /* No memory barriers */
  4170. storm_memset_eq_prod(bp, prod, BP_FUNC(bp));
  4171. mmiowb(); /* keep prod updates ordered */
  4172. }
  4173. static int bnx2x_cnic_handle_cfc_del(struct bnx2x *bp, u32 cid,
  4174. union event_ring_elem *elem)
  4175. {
  4176. u8 err = elem->message.error;
  4177. if (!bp->cnic_eth_dev.starting_cid ||
  4178. (cid < bp->cnic_eth_dev.starting_cid &&
  4179. cid != bp->cnic_eth_dev.iscsi_l2_cid))
  4180. return 1;
  4181. DP(BNX2X_MSG_SP, "got delete ramrod for CNIC CID %d\n", cid);
  4182. if (unlikely(err)) {
  4183. BNX2X_ERR("got delete ramrod for CNIC CID %d with error!\n",
  4184. cid);
  4185. bnx2x_panic_dump(bp, false);
  4186. }
  4187. bnx2x_cnic_cfc_comp(bp, cid, err);
  4188. return 0;
  4189. }
  4190. static void bnx2x_handle_mcast_eqe(struct bnx2x *bp)
  4191. {
  4192. struct bnx2x_mcast_ramrod_params rparam;
  4193. int rc;
  4194. memset(&rparam, 0, sizeof(rparam));
  4195. rparam.mcast_obj = &bp->mcast_obj;
  4196. netif_addr_lock_bh(bp->dev);
  4197. /* Clear pending state for the last command */
  4198. bp->mcast_obj.raw.clear_pending(&bp->mcast_obj.raw);
  4199. /* If there are pending mcast commands - send them */
  4200. if (bp->mcast_obj.check_pending(&bp->mcast_obj)) {
  4201. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT);
  4202. if (rc < 0)
  4203. BNX2X_ERR("Failed to send pending mcast commands: %d\n",
  4204. rc);
  4205. }
  4206. netif_addr_unlock_bh(bp->dev);
  4207. }
  4208. static void bnx2x_handle_classification_eqe(struct bnx2x *bp,
  4209. union event_ring_elem *elem)
  4210. {
  4211. unsigned long ramrod_flags = 0;
  4212. int rc = 0;
  4213. u32 cid = elem->message.data.eth_event.echo & BNX2X_SWCID_MASK;
  4214. struct bnx2x_vlan_mac_obj *vlan_mac_obj;
  4215. /* Always push next commands out, don't wait here */
  4216. __set_bit(RAMROD_CONT, &ramrod_flags);
  4217. switch (le32_to_cpu((__force __le32)elem->message.data.eth_event.echo)
  4218. >> BNX2X_SWCID_SHIFT) {
  4219. case BNX2X_FILTER_MAC_PENDING:
  4220. DP(BNX2X_MSG_SP, "Got SETUP_MAC completions\n");
  4221. if (CNIC_LOADED(bp) && (cid == BNX2X_ISCSI_ETH_CID(bp)))
  4222. vlan_mac_obj = &bp->iscsi_l2_mac_obj;
  4223. else
  4224. vlan_mac_obj = &bp->sp_objs[cid].mac_obj;
  4225. break;
  4226. case BNX2X_FILTER_MCAST_PENDING:
  4227. DP(BNX2X_MSG_SP, "Got SETUP_MCAST completions\n");
  4228. /* This is only relevant for 57710 where multicast MACs are
  4229. * configured as unicast MACs using the same ramrod.
  4230. */
  4231. bnx2x_handle_mcast_eqe(bp);
  4232. return;
  4233. default:
  4234. BNX2X_ERR("Unsupported classification command: %d\n",
  4235. elem->message.data.eth_event.echo);
  4236. return;
  4237. }
  4238. rc = vlan_mac_obj->complete(bp, vlan_mac_obj, elem, &ramrod_flags);
  4239. if (rc < 0)
  4240. BNX2X_ERR("Failed to schedule new commands: %d\n", rc);
  4241. else if (rc > 0)
  4242. DP(BNX2X_MSG_SP, "Scheduled next pending commands...\n");
  4243. }
  4244. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start);
  4245. static void bnx2x_handle_rx_mode_eqe(struct bnx2x *bp)
  4246. {
  4247. netif_addr_lock_bh(bp->dev);
  4248. clear_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  4249. /* Send rx_mode command again if was requested */
  4250. if (test_and_clear_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state))
  4251. bnx2x_set_storm_rx_mode(bp);
  4252. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED,
  4253. &bp->sp_state))
  4254. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  4255. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED,
  4256. &bp->sp_state))
  4257. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  4258. netif_addr_unlock_bh(bp->dev);
  4259. }
  4260. static void bnx2x_after_afex_vif_lists(struct bnx2x *bp,
  4261. union event_ring_elem *elem)
  4262. {
  4263. if (elem->message.data.vif_list_event.echo == VIF_LIST_RULE_GET) {
  4264. DP(BNX2X_MSG_SP,
  4265. "afex: ramrod completed VIF LIST_GET, addrs 0x%x\n",
  4266. elem->message.data.vif_list_event.func_bit_map);
  4267. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTGET_ACK,
  4268. elem->message.data.vif_list_event.func_bit_map);
  4269. } else if (elem->message.data.vif_list_event.echo ==
  4270. VIF_LIST_RULE_SET) {
  4271. DP(BNX2X_MSG_SP, "afex: ramrod completed VIF LIST_SET\n");
  4272. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTSET_ACK, 0);
  4273. }
  4274. }
  4275. /* called with rtnl_lock */
  4276. static void bnx2x_after_function_update(struct bnx2x *bp)
  4277. {
  4278. int q, rc;
  4279. struct bnx2x_fastpath *fp;
  4280. struct bnx2x_queue_state_params queue_params = {NULL};
  4281. struct bnx2x_queue_update_params *q_update_params =
  4282. &queue_params.params.update;
  4283. /* Send Q update command with afex vlan removal values for all Qs */
  4284. queue_params.cmd = BNX2X_Q_CMD_UPDATE;
  4285. /* set silent vlan removal values according to vlan mode */
  4286. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM_CHNG,
  4287. &q_update_params->update_flags);
  4288. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM,
  4289. &q_update_params->update_flags);
  4290. __set_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
  4291. /* in access mode mark mask and value are 0 to strip all vlans */
  4292. if (bp->afex_vlan_mode == FUNC_MF_CFG_AFEX_VLAN_ACCESS_MODE) {
  4293. q_update_params->silent_removal_value = 0;
  4294. q_update_params->silent_removal_mask = 0;
  4295. } else {
  4296. q_update_params->silent_removal_value =
  4297. (bp->afex_def_vlan_tag & VLAN_VID_MASK);
  4298. q_update_params->silent_removal_mask = VLAN_VID_MASK;
  4299. }
  4300. for_each_eth_queue(bp, q) {
  4301. /* Set the appropriate Queue object */
  4302. fp = &bp->fp[q];
  4303. queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  4304. /* send the ramrod */
  4305. rc = bnx2x_queue_state_change(bp, &queue_params);
  4306. if (rc < 0)
  4307. BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
  4308. q);
  4309. }
  4310. if (!NO_FCOE(bp) && CNIC_ENABLED(bp)) {
  4311. fp = &bp->fp[FCOE_IDX(bp)];
  4312. queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  4313. /* clear pending completion bit */
  4314. __clear_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
  4315. /* mark latest Q bit */
  4316. smp_mb__before_clear_bit();
  4317. set_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
  4318. smp_mb__after_clear_bit();
  4319. /* send Q update ramrod for FCoE Q */
  4320. rc = bnx2x_queue_state_change(bp, &queue_params);
  4321. if (rc < 0)
  4322. BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
  4323. q);
  4324. } else {
  4325. /* If no FCoE ring - ACK MCP now */
  4326. bnx2x_link_report(bp);
  4327. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  4328. }
  4329. }
  4330. static struct bnx2x_queue_sp_obj *bnx2x_cid_to_q_obj(
  4331. struct bnx2x *bp, u32 cid)
  4332. {
  4333. DP(BNX2X_MSG_SP, "retrieving fp from cid %d\n", cid);
  4334. if (CNIC_LOADED(bp) && (cid == BNX2X_FCOE_ETH_CID(bp)))
  4335. return &bnx2x_fcoe_sp_obj(bp, q_obj);
  4336. else
  4337. return &bp->sp_objs[CID_TO_FP(cid, bp)].q_obj;
  4338. }
  4339. static void bnx2x_eq_int(struct bnx2x *bp)
  4340. {
  4341. u16 hw_cons, sw_cons, sw_prod;
  4342. union event_ring_elem *elem;
  4343. u8 echo;
  4344. u32 cid;
  4345. u8 opcode;
  4346. int rc, spqe_cnt = 0;
  4347. struct bnx2x_queue_sp_obj *q_obj;
  4348. struct bnx2x_func_sp_obj *f_obj = &bp->func_obj;
  4349. struct bnx2x_raw_obj *rss_raw = &bp->rss_conf_obj.raw;
  4350. hw_cons = le16_to_cpu(*bp->eq_cons_sb);
  4351. /* The hw_cos range is 1-255, 257 - the sw_cons range is 0-254, 256.
  4352. * when we get the next-page we need to adjust so the loop
  4353. * condition below will be met. The next element is the size of a
  4354. * regular element and hence incrementing by 1
  4355. */
  4356. if ((hw_cons & EQ_DESC_MAX_PAGE) == EQ_DESC_MAX_PAGE)
  4357. hw_cons++;
  4358. /* This function may never run in parallel with itself for a
  4359. * specific bp, thus there is no need in "paired" read memory
  4360. * barrier here.
  4361. */
  4362. sw_cons = bp->eq_cons;
  4363. sw_prod = bp->eq_prod;
  4364. DP(BNX2X_MSG_SP, "EQ: hw_cons %u sw_cons %u bp->eq_spq_left %x\n",
  4365. hw_cons, sw_cons, atomic_read(&bp->eq_spq_left));
  4366. for (; sw_cons != hw_cons;
  4367. sw_prod = NEXT_EQ_IDX(sw_prod), sw_cons = NEXT_EQ_IDX(sw_cons)) {
  4368. elem = &bp->eq_ring[EQ_DESC(sw_cons)];
  4369. rc = bnx2x_iov_eq_sp_event(bp, elem);
  4370. if (!rc) {
  4371. DP(BNX2X_MSG_IOV, "bnx2x_iov_eq_sp_event returned %d\n",
  4372. rc);
  4373. goto next_spqe;
  4374. }
  4375. /* elem CID originates from FW; actually LE */
  4376. cid = SW_CID((__force __le32)
  4377. elem->message.data.cfc_del_event.cid);
  4378. opcode = elem->message.opcode;
  4379. /* handle eq element */
  4380. switch (opcode) {
  4381. case EVENT_RING_OPCODE_VF_PF_CHANNEL:
  4382. DP(BNX2X_MSG_IOV, "vf pf channel element on eq\n");
  4383. bnx2x_vf_mbx(bp, &elem->message.data.vf_pf_event);
  4384. continue;
  4385. case EVENT_RING_OPCODE_STAT_QUERY:
  4386. DP(BNX2X_MSG_SP | BNX2X_MSG_STATS,
  4387. "got statistics comp event %d\n",
  4388. bp->stats_comp++);
  4389. /* nothing to do with stats comp */
  4390. goto next_spqe;
  4391. case EVENT_RING_OPCODE_CFC_DEL:
  4392. /* handle according to cid range */
  4393. /*
  4394. * we may want to verify here that the bp state is
  4395. * HALTING
  4396. */
  4397. DP(BNX2X_MSG_SP,
  4398. "got delete ramrod for MULTI[%d]\n", cid);
  4399. if (CNIC_LOADED(bp) &&
  4400. !bnx2x_cnic_handle_cfc_del(bp, cid, elem))
  4401. goto next_spqe;
  4402. q_obj = bnx2x_cid_to_q_obj(bp, cid);
  4403. if (q_obj->complete_cmd(bp, q_obj, BNX2X_Q_CMD_CFC_DEL))
  4404. break;
  4405. goto next_spqe;
  4406. case EVENT_RING_OPCODE_STOP_TRAFFIC:
  4407. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got STOP TRAFFIC\n");
  4408. if (f_obj->complete_cmd(bp, f_obj,
  4409. BNX2X_F_CMD_TX_STOP))
  4410. break;
  4411. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_PAUSED);
  4412. goto next_spqe;
  4413. case EVENT_RING_OPCODE_START_TRAFFIC:
  4414. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got START TRAFFIC\n");
  4415. if (f_obj->complete_cmd(bp, f_obj,
  4416. BNX2X_F_CMD_TX_START))
  4417. break;
  4418. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_RELEASED);
  4419. goto next_spqe;
  4420. case EVENT_RING_OPCODE_FUNCTION_UPDATE:
  4421. echo = elem->message.data.function_update_event.echo;
  4422. if (echo == SWITCH_UPDATE) {
  4423. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4424. "got FUNC_SWITCH_UPDATE ramrod\n");
  4425. if (f_obj->complete_cmd(
  4426. bp, f_obj, BNX2X_F_CMD_SWITCH_UPDATE))
  4427. break;
  4428. } else {
  4429. DP(BNX2X_MSG_SP | BNX2X_MSG_MCP,
  4430. "AFEX: ramrod completed FUNCTION_UPDATE\n");
  4431. f_obj->complete_cmd(bp, f_obj,
  4432. BNX2X_F_CMD_AFEX_UPDATE);
  4433. /* We will perform the Queues update from
  4434. * sp_rtnl task as all Queue SP operations
  4435. * should run under rtnl_lock.
  4436. */
  4437. smp_mb__before_clear_bit();
  4438. set_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE,
  4439. &bp->sp_rtnl_state);
  4440. smp_mb__after_clear_bit();
  4441. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  4442. }
  4443. goto next_spqe;
  4444. case EVENT_RING_OPCODE_AFEX_VIF_LISTS:
  4445. f_obj->complete_cmd(bp, f_obj,
  4446. BNX2X_F_CMD_AFEX_VIFLISTS);
  4447. bnx2x_after_afex_vif_lists(bp, elem);
  4448. goto next_spqe;
  4449. case EVENT_RING_OPCODE_FUNCTION_START:
  4450. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4451. "got FUNC_START ramrod\n");
  4452. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_START))
  4453. break;
  4454. goto next_spqe;
  4455. case EVENT_RING_OPCODE_FUNCTION_STOP:
  4456. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4457. "got FUNC_STOP ramrod\n");
  4458. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_STOP))
  4459. break;
  4460. goto next_spqe;
  4461. }
  4462. switch (opcode | bp->state) {
  4463. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4464. BNX2X_STATE_OPEN):
  4465. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4466. BNX2X_STATE_OPENING_WAIT4_PORT):
  4467. cid = elem->message.data.eth_event.echo &
  4468. BNX2X_SWCID_MASK;
  4469. DP(BNX2X_MSG_SP, "got RSS_UPDATE ramrod. CID %d\n",
  4470. cid);
  4471. rss_raw->clear_pending(rss_raw);
  4472. break;
  4473. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_OPEN):
  4474. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_DIAG):
  4475. case (EVENT_RING_OPCODE_SET_MAC |
  4476. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4477. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4478. BNX2X_STATE_OPEN):
  4479. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4480. BNX2X_STATE_DIAG):
  4481. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4482. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4483. DP(BNX2X_MSG_SP, "got (un)set mac ramrod\n");
  4484. bnx2x_handle_classification_eqe(bp, elem);
  4485. break;
  4486. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4487. BNX2X_STATE_OPEN):
  4488. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4489. BNX2X_STATE_DIAG):
  4490. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4491. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4492. DP(BNX2X_MSG_SP, "got mcast ramrod\n");
  4493. bnx2x_handle_mcast_eqe(bp);
  4494. break;
  4495. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4496. BNX2X_STATE_OPEN):
  4497. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4498. BNX2X_STATE_DIAG):
  4499. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4500. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4501. DP(BNX2X_MSG_SP, "got rx_mode ramrod\n");
  4502. bnx2x_handle_rx_mode_eqe(bp);
  4503. break;
  4504. default:
  4505. /* unknown event log error and continue */
  4506. BNX2X_ERR("Unknown EQ event %d, bp->state 0x%x\n",
  4507. elem->message.opcode, bp->state);
  4508. }
  4509. next_spqe:
  4510. spqe_cnt++;
  4511. } /* for */
  4512. smp_mb__before_atomic_inc();
  4513. atomic_add(spqe_cnt, &bp->eq_spq_left);
  4514. bp->eq_cons = sw_cons;
  4515. bp->eq_prod = sw_prod;
  4516. /* Make sure that above mem writes were issued towards the memory */
  4517. smp_wmb();
  4518. /* update producer */
  4519. bnx2x_update_eq_prod(bp, bp->eq_prod);
  4520. }
  4521. static void bnx2x_sp_task(struct work_struct *work)
  4522. {
  4523. struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work);
  4524. DP(BNX2X_MSG_SP, "sp task invoked\n");
  4525. /* make sure the atomic interrupt_occurred has been written */
  4526. smp_rmb();
  4527. if (atomic_read(&bp->interrupt_occurred)) {
  4528. /* what work needs to be performed? */
  4529. u16 status = bnx2x_update_dsb_idx(bp);
  4530. DP(BNX2X_MSG_SP, "status %x\n", status);
  4531. DP(BNX2X_MSG_SP, "setting interrupt_occurred to 0\n");
  4532. atomic_set(&bp->interrupt_occurred, 0);
  4533. /* HW attentions */
  4534. if (status & BNX2X_DEF_SB_ATT_IDX) {
  4535. bnx2x_attn_int(bp);
  4536. status &= ~BNX2X_DEF_SB_ATT_IDX;
  4537. }
  4538. /* SP events: STAT_QUERY and others */
  4539. if (status & BNX2X_DEF_SB_IDX) {
  4540. struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
  4541. if (FCOE_INIT(bp) &&
  4542. (bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp))) {
  4543. /* Prevent local bottom-halves from running as
  4544. * we are going to change the local NAPI list.
  4545. */
  4546. local_bh_disable();
  4547. napi_schedule(&bnx2x_fcoe(bp, napi));
  4548. local_bh_enable();
  4549. }
  4550. /* Handle EQ completions */
  4551. bnx2x_eq_int(bp);
  4552. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID,
  4553. le16_to_cpu(bp->def_idx), IGU_INT_NOP, 1);
  4554. status &= ~BNX2X_DEF_SB_IDX;
  4555. }
  4556. /* if status is non zero then perhaps something went wrong */
  4557. if (unlikely(status))
  4558. DP(BNX2X_MSG_SP,
  4559. "got an unknown interrupt! (status 0x%x)\n", status);
  4560. /* ack status block only if something was actually handled */
  4561. bnx2x_ack_sb(bp, bp->igu_dsb_id, ATTENTION_ID,
  4562. le16_to_cpu(bp->def_att_idx), IGU_INT_ENABLE, 1);
  4563. }
  4564. /* must be called after the EQ processing (since eq leads to sriov
  4565. * ramrod completion flows).
  4566. * This flow may have been scheduled by the arrival of a ramrod
  4567. * completion, or by the sriov code rescheduling itself.
  4568. */
  4569. bnx2x_iov_sp_task(bp);
  4570. /* afex - poll to check if VIFSET_ACK should be sent to MFW */
  4571. if (test_and_clear_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK,
  4572. &bp->sp_state)) {
  4573. bnx2x_link_report(bp);
  4574. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  4575. }
  4576. }
  4577. irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance)
  4578. {
  4579. struct net_device *dev = dev_instance;
  4580. struct bnx2x *bp = netdev_priv(dev);
  4581. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0,
  4582. IGU_INT_DISABLE, 0);
  4583. #ifdef BNX2X_STOP_ON_ERROR
  4584. if (unlikely(bp->panic))
  4585. return IRQ_HANDLED;
  4586. #endif
  4587. if (CNIC_LOADED(bp)) {
  4588. struct cnic_ops *c_ops;
  4589. rcu_read_lock();
  4590. c_ops = rcu_dereference(bp->cnic_ops);
  4591. if (c_ops)
  4592. c_ops->cnic_handler(bp->cnic_data, NULL);
  4593. rcu_read_unlock();
  4594. }
  4595. /* schedule sp task to perform default status block work, ack
  4596. * attentions and enable interrupts.
  4597. */
  4598. bnx2x_schedule_sp_task(bp);
  4599. return IRQ_HANDLED;
  4600. }
  4601. /* end of slow path */
  4602. void bnx2x_drv_pulse(struct bnx2x *bp)
  4603. {
  4604. SHMEM_WR(bp, func_mb[BP_FW_MB_IDX(bp)].drv_pulse_mb,
  4605. bp->fw_drv_pulse_wr_seq);
  4606. }
  4607. static void bnx2x_timer(unsigned long data)
  4608. {
  4609. struct bnx2x *bp = (struct bnx2x *) data;
  4610. if (!netif_running(bp->dev))
  4611. return;
  4612. if (IS_PF(bp) &&
  4613. !BP_NOMCP(bp)) {
  4614. int mb_idx = BP_FW_MB_IDX(bp);
  4615. u16 drv_pulse;
  4616. u16 mcp_pulse;
  4617. ++bp->fw_drv_pulse_wr_seq;
  4618. bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK;
  4619. drv_pulse = bp->fw_drv_pulse_wr_seq;
  4620. bnx2x_drv_pulse(bp);
  4621. mcp_pulse = (SHMEM_RD(bp, func_mb[mb_idx].mcp_pulse_mb) &
  4622. MCP_PULSE_SEQ_MASK);
  4623. /* The delta between driver pulse and mcp response
  4624. * should not get too big. If the MFW is more than 5 pulses
  4625. * behind, we should worry about it enough to generate an error
  4626. * log.
  4627. */
  4628. if (((drv_pulse - mcp_pulse) & MCP_PULSE_SEQ_MASK) > 5)
  4629. BNX2X_ERR("MFW seems hanged: drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
  4630. drv_pulse, mcp_pulse);
  4631. }
  4632. if (bp->state == BNX2X_STATE_OPEN)
  4633. bnx2x_stats_handle(bp, STATS_EVENT_UPDATE);
  4634. /* sample pf vf bulletin board for new posts from pf */
  4635. if (IS_VF(bp))
  4636. bnx2x_timer_sriov(bp);
  4637. mod_timer(&bp->timer, jiffies + bp->current_interval);
  4638. }
  4639. /* end of Statistics */
  4640. /* nic init */
  4641. /*
  4642. * nic init service functions
  4643. */
  4644. static void bnx2x_fill(struct bnx2x *bp, u32 addr, int fill, u32 len)
  4645. {
  4646. u32 i;
  4647. if (!(len%4) && !(addr%4))
  4648. for (i = 0; i < len; i += 4)
  4649. REG_WR(bp, addr + i, fill);
  4650. else
  4651. for (i = 0; i < len; i++)
  4652. REG_WR8(bp, addr + i, fill);
  4653. }
  4654. /* helper: writes FP SP data to FW - data_size in dwords */
  4655. static void bnx2x_wr_fp_sb_data(struct bnx2x *bp,
  4656. int fw_sb_id,
  4657. u32 *sb_data_p,
  4658. u32 data_size)
  4659. {
  4660. int index;
  4661. for (index = 0; index < data_size; index++)
  4662. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4663. CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id) +
  4664. sizeof(u32)*index,
  4665. *(sb_data_p + index));
  4666. }
  4667. static void bnx2x_zero_fp_sb(struct bnx2x *bp, int fw_sb_id)
  4668. {
  4669. u32 *sb_data_p;
  4670. u32 data_size = 0;
  4671. struct hc_status_block_data_e2 sb_data_e2;
  4672. struct hc_status_block_data_e1x sb_data_e1x;
  4673. /* disable the function first */
  4674. if (!CHIP_IS_E1x(bp)) {
  4675. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  4676. sb_data_e2.common.state = SB_DISABLED;
  4677. sb_data_e2.common.p_func.vf_valid = false;
  4678. sb_data_p = (u32 *)&sb_data_e2;
  4679. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  4680. } else {
  4681. memset(&sb_data_e1x, 0,
  4682. sizeof(struct hc_status_block_data_e1x));
  4683. sb_data_e1x.common.state = SB_DISABLED;
  4684. sb_data_e1x.common.p_func.vf_valid = false;
  4685. sb_data_p = (u32 *)&sb_data_e1x;
  4686. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  4687. }
  4688. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  4689. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4690. CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id), 0,
  4691. CSTORM_STATUS_BLOCK_SIZE);
  4692. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4693. CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id), 0,
  4694. CSTORM_SYNC_BLOCK_SIZE);
  4695. }
  4696. /* helper: writes SP SB data to FW */
  4697. static void bnx2x_wr_sp_sb_data(struct bnx2x *bp,
  4698. struct hc_sp_status_block_data *sp_sb_data)
  4699. {
  4700. int func = BP_FUNC(bp);
  4701. int i;
  4702. for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
  4703. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4704. CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
  4705. i*sizeof(u32),
  4706. *((u32 *)sp_sb_data + i));
  4707. }
  4708. static void bnx2x_zero_sp_sb(struct bnx2x *bp)
  4709. {
  4710. int func = BP_FUNC(bp);
  4711. struct hc_sp_status_block_data sp_sb_data;
  4712. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  4713. sp_sb_data.state = SB_DISABLED;
  4714. sp_sb_data.p_func.vf_valid = false;
  4715. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  4716. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4717. CSTORM_SP_STATUS_BLOCK_OFFSET(func), 0,
  4718. CSTORM_SP_STATUS_BLOCK_SIZE);
  4719. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4720. CSTORM_SP_SYNC_BLOCK_OFFSET(func), 0,
  4721. CSTORM_SP_SYNC_BLOCK_SIZE);
  4722. }
  4723. static void bnx2x_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm,
  4724. int igu_sb_id, int igu_seg_id)
  4725. {
  4726. hc_sm->igu_sb_id = igu_sb_id;
  4727. hc_sm->igu_seg_id = igu_seg_id;
  4728. hc_sm->timer_value = 0xFF;
  4729. hc_sm->time_to_expire = 0xFFFFFFFF;
  4730. }
  4731. /* allocates state machine ids. */
  4732. static void bnx2x_map_sb_state_machines(struct hc_index_data *index_data)
  4733. {
  4734. /* zero out state machine indices */
  4735. /* rx indices */
  4736. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4737. /* tx indices */
  4738. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4739. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags &= ~HC_INDEX_DATA_SM_ID;
  4740. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags &= ~HC_INDEX_DATA_SM_ID;
  4741. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags &= ~HC_INDEX_DATA_SM_ID;
  4742. /* map indices */
  4743. /* rx indices */
  4744. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags |=
  4745. SM_RX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4746. /* tx indices */
  4747. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags |=
  4748. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4749. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags |=
  4750. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4751. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags |=
  4752. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4753. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags |=
  4754. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4755. }
  4756. void bnx2x_init_sb(struct bnx2x *bp, dma_addr_t mapping, int vfid,
  4757. u8 vf_valid, int fw_sb_id, int igu_sb_id)
  4758. {
  4759. int igu_seg_id;
  4760. struct hc_status_block_data_e2 sb_data_e2;
  4761. struct hc_status_block_data_e1x sb_data_e1x;
  4762. struct hc_status_block_sm *hc_sm_p;
  4763. int data_size;
  4764. u32 *sb_data_p;
  4765. if (CHIP_INT_MODE_IS_BC(bp))
  4766. igu_seg_id = HC_SEG_ACCESS_NORM;
  4767. else
  4768. igu_seg_id = IGU_SEG_ACCESS_NORM;
  4769. bnx2x_zero_fp_sb(bp, fw_sb_id);
  4770. if (!CHIP_IS_E1x(bp)) {
  4771. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  4772. sb_data_e2.common.state = SB_ENABLED;
  4773. sb_data_e2.common.p_func.pf_id = BP_FUNC(bp);
  4774. sb_data_e2.common.p_func.vf_id = vfid;
  4775. sb_data_e2.common.p_func.vf_valid = vf_valid;
  4776. sb_data_e2.common.p_func.vnic_id = BP_VN(bp);
  4777. sb_data_e2.common.same_igu_sb_1b = true;
  4778. sb_data_e2.common.host_sb_addr.hi = U64_HI(mapping);
  4779. sb_data_e2.common.host_sb_addr.lo = U64_LO(mapping);
  4780. hc_sm_p = sb_data_e2.common.state_machine;
  4781. sb_data_p = (u32 *)&sb_data_e2;
  4782. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  4783. bnx2x_map_sb_state_machines(sb_data_e2.index_data);
  4784. } else {
  4785. memset(&sb_data_e1x, 0,
  4786. sizeof(struct hc_status_block_data_e1x));
  4787. sb_data_e1x.common.state = SB_ENABLED;
  4788. sb_data_e1x.common.p_func.pf_id = BP_FUNC(bp);
  4789. sb_data_e1x.common.p_func.vf_id = 0xff;
  4790. sb_data_e1x.common.p_func.vf_valid = false;
  4791. sb_data_e1x.common.p_func.vnic_id = BP_VN(bp);
  4792. sb_data_e1x.common.same_igu_sb_1b = true;
  4793. sb_data_e1x.common.host_sb_addr.hi = U64_HI(mapping);
  4794. sb_data_e1x.common.host_sb_addr.lo = U64_LO(mapping);
  4795. hc_sm_p = sb_data_e1x.common.state_machine;
  4796. sb_data_p = (u32 *)&sb_data_e1x;
  4797. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  4798. bnx2x_map_sb_state_machines(sb_data_e1x.index_data);
  4799. }
  4800. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_RX_ID],
  4801. igu_sb_id, igu_seg_id);
  4802. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_TX_ID],
  4803. igu_sb_id, igu_seg_id);
  4804. DP(NETIF_MSG_IFUP, "Init FW SB %d\n", fw_sb_id);
  4805. /* write indices to HW - PCI guarantees endianity of regpairs */
  4806. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  4807. }
  4808. static void bnx2x_update_coalesce_sb(struct bnx2x *bp, u8 fw_sb_id,
  4809. u16 tx_usec, u16 rx_usec)
  4810. {
  4811. bnx2x_update_coalesce_sb_index(bp, fw_sb_id, HC_INDEX_ETH_RX_CQ_CONS,
  4812. false, rx_usec);
  4813. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4814. HC_INDEX_ETH_TX_CQ_CONS_COS0, false,
  4815. tx_usec);
  4816. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4817. HC_INDEX_ETH_TX_CQ_CONS_COS1, false,
  4818. tx_usec);
  4819. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4820. HC_INDEX_ETH_TX_CQ_CONS_COS2, false,
  4821. tx_usec);
  4822. }
  4823. static void bnx2x_init_def_sb(struct bnx2x *bp)
  4824. {
  4825. struct host_sp_status_block *def_sb = bp->def_status_blk;
  4826. dma_addr_t mapping = bp->def_status_blk_mapping;
  4827. int igu_sp_sb_index;
  4828. int igu_seg_id;
  4829. int port = BP_PORT(bp);
  4830. int func = BP_FUNC(bp);
  4831. int reg_offset, reg_offset_en5;
  4832. u64 section;
  4833. int index;
  4834. struct hc_sp_status_block_data sp_sb_data;
  4835. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  4836. if (CHIP_INT_MODE_IS_BC(bp)) {
  4837. igu_sp_sb_index = DEF_SB_IGU_ID;
  4838. igu_seg_id = HC_SEG_ACCESS_DEF;
  4839. } else {
  4840. igu_sp_sb_index = bp->igu_dsb_id;
  4841. igu_seg_id = IGU_SEG_ACCESS_DEF;
  4842. }
  4843. /* ATTN */
  4844. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  4845. atten_status_block);
  4846. def_sb->atten_status_block.status_block_id = igu_sp_sb_index;
  4847. bp->attn_state = 0;
  4848. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  4849. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  4850. reg_offset_en5 = (port ? MISC_REG_AEU_ENABLE5_FUNC_1_OUT_0 :
  4851. MISC_REG_AEU_ENABLE5_FUNC_0_OUT_0);
  4852. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  4853. int sindex;
  4854. /* take care of sig[0]..sig[4] */
  4855. for (sindex = 0; sindex < 4; sindex++)
  4856. bp->attn_group[index].sig[sindex] =
  4857. REG_RD(bp, reg_offset + sindex*0x4 + 0x10*index);
  4858. if (!CHIP_IS_E1x(bp))
  4859. /*
  4860. * enable5 is separate from the rest of the registers,
  4861. * and therefore the address skip is 4
  4862. * and not 16 between the different groups
  4863. */
  4864. bp->attn_group[index].sig[4] = REG_RD(bp,
  4865. reg_offset_en5 + 0x4*index);
  4866. else
  4867. bp->attn_group[index].sig[4] = 0;
  4868. }
  4869. if (bp->common.int_block == INT_BLOCK_HC) {
  4870. reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L :
  4871. HC_REG_ATTN_MSG0_ADDR_L);
  4872. REG_WR(bp, reg_offset, U64_LO(section));
  4873. REG_WR(bp, reg_offset + 4, U64_HI(section));
  4874. } else if (!CHIP_IS_E1x(bp)) {
  4875. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_L, U64_LO(section));
  4876. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_H, U64_HI(section));
  4877. }
  4878. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  4879. sp_sb);
  4880. bnx2x_zero_sp_sb(bp);
  4881. /* PCI guarantees endianity of regpairs */
  4882. sp_sb_data.state = SB_ENABLED;
  4883. sp_sb_data.host_sb_addr.lo = U64_LO(section);
  4884. sp_sb_data.host_sb_addr.hi = U64_HI(section);
  4885. sp_sb_data.igu_sb_id = igu_sp_sb_index;
  4886. sp_sb_data.igu_seg_id = igu_seg_id;
  4887. sp_sb_data.p_func.pf_id = func;
  4888. sp_sb_data.p_func.vnic_id = BP_VN(bp);
  4889. sp_sb_data.p_func.vf_id = 0xff;
  4890. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  4891. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0);
  4892. }
  4893. void bnx2x_update_coalesce(struct bnx2x *bp)
  4894. {
  4895. int i;
  4896. for_each_eth_queue(bp, i)
  4897. bnx2x_update_coalesce_sb(bp, bp->fp[i].fw_sb_id,
  4898. bp->tx_ticks, bp->rx_ticks);
  4899. }
  4900. static void bnx2x_init_sp_ring(struct bnx2x *bp)
  4901. {
  4902. spin_lock_init(&bp->spq_lock);
  4903. atomic_set(&bp->cq_spq_left, MAX_SPQ_PENDING);
  4904. bp->spq_prod_idx = 0;
  4905. bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX;
  4906. bp->spq_prod_bd = bp->spq;
  4907. bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT;
  4908. }
  4909. static void bnx2x_init_eq_ring(struct bnx2x *bp)
  4910. {
  4911. int i;
  4912. for (i = 1; i <= NUM_EQ_PAGES; i++) {
  4913. union event_ring_elem *elem =
  4914. &bp->eq_ring[EQ_DESC_CNT_PAGE * i - 1];
  4915. elem->next_page.addr.hi =
  4916. cpu_to_le32(U64_HI(bp->eq_mapping +
  4917. BCM_PAGE_SIZE * (i % NUM_EQ_PAGES)));
  4918. elem->next_page.addr.lo =
  4919. cpu_to_le32(U64_LO(bp->eq_mapping +
  4920. BCM_PAGE_SIZE*(i % NUM_EQ_PAGES)));
  4921. }
  4922. bp->eq_cons = 0;
  4923. bp->eq_prod = NUM_EQ_DESC;
  4924. bp->eq_cons_sb = BNX2X_EQ_INDEX;
  4925. /* we want a warning message before it gets wrought... */
  4926. atomic_set(&bp->eq_spq_left,
  4927. min_t(int, MAX_SP_DESC_CNT - MAX_SPQ_PENDING, NUM_EQ_DESC) - 1);
  4928. }
  4929. /* called with netif_addr_lock_bh() */
  4930. int bnx2x_set_q_rx_mode(struct bnx2x *bp, u8 cl_id,
  4931. unsigned long rx_mode_flags,
  4932. unsigned long rx_accept_flags,
  4933. unsigned long tx_accept_flags,
  4934. unsigned long ramrod_flags)
  4935. {
  4936. struct bnx2x_rx_mode_ramrod_params ramrod_param;
  4937. int rc;
  4938. memset(&ramrod_param, 0, sizeof(ramrod_param));
  4939. /* Prepare ramrod parameters */
  4940. ramrod_param.cid = 0;
  4941. ramrod_param.cl_id = cl_id;
  4942. ramrod_param.rx_mode_obj = &bp->rx_mode_obj;
  4943. ramrod_param.func_id = BP_FUNC(bp);
  4944. ramrod_param.pstate = &bp->sp_state;
  4945. ramrod_param.state = BNX2X_FILTER_RX_MODE_PENDING;
  4946. ramrod_param.rdata = bnx2x_sp(bp, rx_mode_rdata);
  4947. ramrod_param.rdata_mapping = bnx2x_sp_mapping(bp, rx_mode_rdata);
  4948. set_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  4949. ramrod_param.ramrod_flags = ramrod_flags;
  4950. ramrod_param.rx_mode_flags = rx_mode_flags;
  4951. ramrod_param.rx_accept_flags = rx_accept_flags;
  4952. ramrod_param.tx_accept_flags = tx_accept_flags;
  4953. rc = bnx2x_config_rx_mode(bp, &ramrod_param);
  4954. if (rc < 0) {
  4955. BNX2X_ERR("Set rx_mode %d failed\n", bp->rx_mode);
  4956. return rc;
  4957. }
  4958. return 0;
  4959. }
  4960. static int bnx2x_fill_accept_flags(struct bnx2x *bp, u32 rx_mode,
  4961. unsigned long *rx_accept_flags,
  4962. unsigned long *tx_accept_flags)
  4963. {
  4964. /* Clear the flags first */
  4965. *rx_accept_flags = 0;
  4966. *tx_accept_flags = 0;
  4967. switch (rx_mode) {
  4968. case BNX2X_RX_MODE_NONE:
  4969. /*
  4970. * 'drop all' supersedes any accept flags that may have been
  4971. * passed to the function.
  4972. */
  4973. break;
  4974. case BNX2X_RX_MODE_NORMAL:
  4975. __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
  4976. __set_bit(BNX2X_ACCEPT_MULTICAST, rx_accept_flags);
  4977. __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
  4978. /* internal switching mode */
  4979. __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
  4980. __set_bit(BNX2X_ACCEPT_MULTICAST, tx_accept_flags);
  4981. __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
  4982. break;
  4983. case BNX2X_RX_MODE_ALLMULTI:
  4984. __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
  4985. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, rx_accept_flags);
  4986. __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
  4987. /* internal switching mode */
  4988. __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
  4989. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, tx_accept_flags);
  4990. __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
  4991. break;
  4992. case BNX2X_RX_MODE_PROMISC:
  4993. /* According to definition of SI mode, iface in promisc mode
  4994. * should receive matched and unmatched (in resolution of port)
  4995. * unicast packets.
  4996. */
  4997. __set_bit(BNX2X_ACCEPT_UNMATCHED, rx_accept_flags);
  4998. __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
  4999. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, rx_accept_flags);
  5000. __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
  5001. /* internal switching mode */
  5002. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, tx_accept_flags);
  5003. __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
  5004. if (IS_MF_SI(bp))
  5005. __set_bit(BNX2X_ACCEPT_ALL_UNICAST, tx_accept_flags);
  5006. else
  5007. __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
  5008. break;
  5009. default:
  5010. BNX2X_ERR("Unknown rx_mode: %d\n", rx_mode);
  5011. return -EINVAL;
  5012. }
  5013. /* Set ACCEPT_ANY_VLAN as we do not enable filtering by VLAN */
  5014. if (bp->rx_mode != BNX2X_RX_MODE_NONE) {
  5015. __set_bit(BNX2X_ACCEPT_ANY_VLAN, rx_accept_flags);
  5016. __set_bit(BNX2X_ACCEPT_ANY_VLAN, tx_accept_flags);
  5017. }
  5018. return 0;
  5019. }
  5020. /* called with netif_addr_lock_bh() */
  5021. int bnx2x_set_storm_rx_mode(struct bnx2x *bp)
  5022. {
  5023. unsigned long rx_mode_flags = 0, ramrod_flags = 0;
  5024. unsigned long rx_accept_flags = 0, tx_accept_flags = 0;
  5025. int rc;
  5026. if (!NO_FCOE(bp))
  5027. /* Configure rx_mode of FCoE Queue */
  5028. __set_bit(BNX2X_RX_MODE_FCOE_ETH, &rx_mode_flags);
  5029. rc = bnx2x_fill_accept_flags(bp, bp->rx_mode, &rx_accept_flags,
  5030. &tx_accept_flags);
  5031. if (rc)
  5032. return rc;
  5033. __set_bit(RAMROD_RX, &ramrod_flags);
  5034. __set_bit(RAMROD_TX, &ramrod_flags);
  5035. return bnx2x_set_q_rx_mode(bp, bp->fp->cl_id, rx_mode_flags,
  5036. rx_accept_flags, tx_accept_flags,
  5037. ramrod_flags);
  5038. }
  5039. static void bnx2x_init_internal_common(struct bnx2x *bp)
  5040. {
  5041. int i;
  5042. if (IS_MF_SI(bp))
  5043. /*
  5044. * In switch independent mode, the TSTORM needs to accept
  5045. * packets that failed classification, since approximate match
  5046. * mac addresses aren't written to NIG LLH
  5047. */
  5048. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  5049. TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 2);
  5050. else if (!CHIP_IS_E1(bp)) /* 57710 doesn't support MF */
  5051. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  5052. TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 0);
  5053. /* Zero this manually as its initialization is
  5054. currently missing in the initTool */
  5055. for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++)
  5056. REG_WR(bp, BAR_USTRORM_INTMEM +
  5057. USTORM_AGG_DATA_OFFSET + i * 4, 0);
  5058. if (!CHIP_IS_E1x(bp)) {
  5059. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_IGU_MODE_OFFSET,
  5060. CHIP_INT_MODE_IS_BC(bp) ?
  5061. HC_IGU_BC_MODE : HC_IGU_NBC_MODE);
  5062. }
  5063. }
  5064. static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code)
  5065. {
  5066. switch (load_code) {
  5067. case FW_MSG_CODE_DRV_LOAD_COMMON:
  5068. case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
  5069. bnx2x_init_internal_common(bp);
  5070. /* no break */
  5071. case FW_MSG_CODE_DRV_LOAD_PORT:
  5072. /* nothing to do */
  5073. /* no break */
  5074. case FW_MSG_CODE_DRV_LOAD_FUNCTION:
  5075. /* internal memory per function is
  5076. initialized inside bnx2x_pf_init */
  5077. break;
  5078. default:
  5079. BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
  5080. break;
  5081. }
  5082. }
  5083. static inline u8 bnx2x_fp_igu_sb_id(struct bnx2x_fastpath *fp)
  5084. {
  5085. return fp->bp->igu_base_sb + fp->index + CNIC_SUPPORT(fp->bp);
  5086. }
  5087. static inline u8 bnx2x_fp_fw_sb_id(struct bnx2x_fastpath *fp)
  5088. {
  5089. return fp->bp->base_fw_ndsb + fp->index + CNIC_SUPPORT(fp->bp);
  5090. }
  5091. static u8 bnx2x_fp_cl_id(struct bnx2x_fastpath *fp)
  5092. {
  5093. if (CHIP_IS_E1x(fp->bp))
  5094. return BP_L_ID(fp->bp) + fp->index;
  5095. else /* We want Client ID to be the same as IGU SB ID for 57712 */
  5096. return bnx2x_fp_igu_sb_id(fp);
  5097. }
  5098. static void bnx2x_init_eth_fp(struct bnx2x *bp, int fp_idx)
  5099. {
  5100. struct bnx2x_fastpath *fp = &bp->fp[fp_idx];
  5101. u8 cos;
  5102. unsigned long q_type = 0;
  5103. u32 cids[BNX2X_MULTI_TX_COS] = { 0 };
  5104. fp->rx_queue = fp_idx;
  5105. fp->cid = fp_idx;
  5106. fp->cl_id = bnx2x_fp_cl_id(fp);
  5107. fp->fw_sb_id = bnx2x_fp_fw_sb_id(fp);
  5108. fp->igu_sb_id = bnx2x_fp_igu_sb_id(fp);
  5109. /* qZone id equals to FW (per path) client id */
  5110. fp->cl_qzone_id = bnx2x_fp_qzone_id(fp);
  5111. /* init shortcut */
  5112. fp->ustorm_rx_prods_offset = bnx2x_rx_ustorm_prods_offset(fp);
  5113. /* Setup SB indices */
  5114. fp->rx_cons_sb = BNX2X_RX_SB_INDEX;
  5115. /* Configure Queue State object */
  5116. __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
  5117. __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
  5118. BUG_ON(fp->max_cos > BNX2X_MULTI_TX_COS);
  5119. /* init tx data */
  5120. for_each_cos_in_tx_queue(fp, cos) {
  5121. bnx2x_init_txdata(bp, fp->txdata_ptr[cos],
  5122. CID_COS_TO_TX_ONLY_CID(fp->cid, cos, bp),
  5123. FP_COS_TO_TXQ(fp, cos, bp),
  5124. BNX2X_TX_SB_INDEX_BASE + cos, fp);
  5125. cids[cos] = fp->txdata_ptr[cos]->cid;
  5126. }
  5127. /* nothing more for vf to do here */
  5128. if (IS_VF(bp))
  5129. return;
  5130. bnx2x_init_sb(bp, fp->status_blk_mapping, BNX2X_VF_ID_INVALID, false,
  5131. fp->fw_sb_id, fp->igu_sb_id);
  5132. bnx2x_update_fpsb_idx(fp);
  5133. bnx2x_init_queue_obj(bp, &bnx2x_sp_obj(bp, fp).q_obj, fp->cl_id, cids,
  5134. fp->max_cos, BP_FUNC(bp), bnx2x_sp(bp, q_rdata),
  5135. bnx2x_sp_mapping(bp, q_rdata), q_type);
  5136. /**
  5137. * Configure classification DBs: Always enable Tx switching
  5138. */
  5139. bnx2x_init_vlan_mac_fp_objs(fp, BNX2X_OBJ_TYPE_RX_TX);
  5140. DP(NETIF_MSG_IFUP,
  5141. "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d fw_sb %d igu_sb %d\n",
  5142. fp_idx, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
  5143. fp->igu_sb_id);
  5144. }
  5145. static void bnx2x_init_tx_ring_one(struct bnx2x_fp_txdata *txdata)
  5146. {
  5147. int i;
  5148. for (i = 1; i <= NUM_TX_RINGS; i++) {
  5149. struct eth_tx_next_bd *tx_next_bd =
  5150. &txdata->tx_desc_ring[TX_DESC_CNT * i - 1].next_bd;
  5151. tx_next_bd->addr_hi =
  5152. cpu_to_le32(U64_HI(txdata->tx_desc_mapping +
  5153. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  5154. tx_next_bd->addr_lo =
  5155. cpu_to_le32(U64_LO(txdata->tx_desc_mapping +
  5156. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  5157. }
  5158. *txdata->tx_cons_sb = cpu_to_le16(0);
  5159. SET_FLAG(txdata->tx_db.data.header.header, DOORBELL_HDR_DB_TYPE, 1);
  5160. txdata->tx_db.data.zero_fill1 = 0;
  5161. txdata->tx_db.data.prod = 0;
  5162. txdata->tx_pkt_prod = 0;
  5163. txdata->tx_pkt_cons = 0;
  5164. txdata->tx_bd_prod = 0;
  5165. txdata->tx_bd_cons = 0;
  5166. txdata->tx_pkt = 0;
  5167. }
  5168. static void bnx2x_init_tx_rings_cnic(struct bnx2x *bp)
  5169. {
  5170. int i;
  5171. for_each_tx_queue_cnic(bp, i)
  5172. bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[0]);
  5173. }
  5174. static void bnx2x_init_tx_rings(struct bnx2x *bp)
  5175. {
  5176. int i;
  5177. u8 cos;
  5178. for_each_eth_queue(bp, i)
  5179. for_each_cos_in_tx_queue(&bp->fp[i], cos)
  5180. bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[cos]);
  5181. }
  5182. void bnx2x_nic_init_cnic(struct bnx2x *bp)
  5183. {
  5184. if (!NO_FCOE(bp))
  5185. bnx2x_init_fcoe_fp(bp);
  5186. bnx2x_init_sb(bp, bp->cnic_sb_mapping,
  5187. BNX2X_VF_ID_INVALID, false,
  5188. bnx2x_cnic_fw_sb_id(bp), bnx2x_cnic_igu_sb_id(bp));
  5189. /* ensure status block indices were read */
  5190. rmb();
  5191. bnx2x_init_rx_rings_cnic(bp);
  5192. bnx2x_init_tx_rings_cnic(bp);
  5193. /* flush all */
  5194. mb();
  5195. mmiowb();
  5196. }
  5197. void bnx2x_pre_irq_nic_init(struct bnx2x *bp)
  5198. {
  5199. int i;
  5200. /* Setup NIC internals and enable interrupts */
  5201. for_each_eth_queue(bp, i)
  5202. bnx2x_init_eth_fp(bp, i);
  5203. /* ensure status block indices were read */
  5204. rmb();
  5205. bnx2x_init_rx_rings(bp);
  5206. bnx2x_init_tx_rings(bp);
  5207. if (IS_PF(bp)) {
  5208. /* Initialize MOD_ABS interrupts */
  5209. bnx2x_init_mod_abs_int(bp, &bp->link_vars, bp->common.chip_id,
  5210. bp->common.shmem_base,
  5211. bp->common.shmem2_base, BP_PORT(bp));
  5212. /* initialize the default status block and sp ring */
  5213. bnx2x_init_def_sb(bp);
  5214. bnx2x_update_dsb_idx(bp);
  5215. bnx2x_init_sp_ring(bp);
  5216. } else {
  5217. bnx2x_memset_stats(bp);
  5218. }
  5219. }
  5220. void bnx2x_post_irq_nic_init(struct bnx2x *bp, u32 load_code)
  5221. {
  5222. bnx2x_init_eq_ring(bp);
  5223. bnx2x_init_internal(bp, load_code);
  5224. bnx2x_pf_init(bp);
  5225. bnx2x_stats_init(bp);
  5226. /* flush all before enabling interrupts */
  5227. mb();
  5228. mmiowb();
  5229. bnx2x_int_enable(bp);
  5230. /* Check for SPIO5 */
  5231. bnx2x_attn_int_deasserted0(bp,
  5232. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + BP_PORT(bp)*4) &
  5233. AEU_INPUTS_ATTN_BITS_SPIO5);
  5234. }
  5235. /* gzip service functions */
  5236. static int bnx2x_gunzip_init(struct bnx2x *bp)
  5237. {
  5238. bp->gunzip_buf = dma_alloc_coherent(&bp->pdev->dev, FW_BUF_SIZE,
  5239. &bp->gunzip_mapping, GFP_KERNEL);
  5240. if (bp->gunzip_buf == NULL)
  5241. goto gunzip_nomem1;
  5242. bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL);
  5243. if (bp->strm == NULL)
  5244. goto gunzip_nomem2;
  5245. bp->strm->workspace = vmalloc(zlib_inflate_workspacesize());
  5246. if (bp->strm->workspace == NULL)
  5247. goto gunzip_nomem3;
  5248. return 0;
  5249. gunzip_nomem3:
  5250. kfree(bp->strm);
  5251. bp->strm = NULL;
  5252. gunzip_nomem2:
  5253. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  5254. bp->gunzip_mapping);
  5255. bp->gunzip_buf = NULL;
  5256. gunzip_nomem1:
  5257. BNX2X_ERR("Cannot allocate firmware buffer for un-compression\n");
  5258. return -ENOMEM;
  5259. }
  5260. static void bnx2x_gunzip_end(struct bnx2x *bp)
  5261. {
  5262. if (bp->strm) {
  5263. vfree(bp->strm->workspace);
  5264. kfree(bp->strm);
  5265. bp->strm = NULL;
  5266. }
  5267. if (bp->gunzip_buf) {
  5268. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  5269. bp->gunzip_mapping);
  5270. bp->gunzip_buf = NULL;
  5271. }
  5272. }
  5273. static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len)
  5274. {
  5275. int n, rc;
  5276. /* check gzip header */
  5277. if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED)) {
  5278. BNX2X_ERR("Bad gzip header\n");
  5279. return -EINVAL;
  5280. }
  5281. n = 10;
  5282. #define FNAME 0x8
  5283. if (zbuf[3] & FNAME)
  5284. while ((zbuf[n++] != 0) && (n < len));
  5285. bp->strm->next_in = (typeof(bp->strm->next_in))zbuf + n;
  5286. bp->strm->avail_in = len - n;
  5287. bp->strm->next_out = bp->gunzip_buf;
  5288. bp->strm->avail_out = FW_BUF_SIZE;
  5289. rc = zlib_inflateInit2(bp->strm, -MAX_WBITS);
  5290. if (rc != Z_OK)
  5291. return rc;
  5292. rc = zlib_inflate(bp->strm, Z_FINISH);
  5293. if ((rc != Z_OK) && (rc != Z_STREAM_END))
  5294. netdev_err(bp->dev, "Firmware decompression error: %s\n",
  5295. bp->strm->msg);
  5296. bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out);
  5297. if (bp->gunzip_outlen & 0x3)
  5298. netdev_err(bp->dev,
  5299. "Firmware decompression error: gunzip_outlen (%d) not aligned\n",
  5300. bp->gunzip_outlen);
  5301. bp->gunzip_outlen >>= 2;
  5302. zlib_inflateEnd(bp->strm);
  5303. if (rc == Z_STREAM_END)
  5304. return 0;
  5305. return rc;
  5306. }
  5307. /* nic load/unload */
  5308. /*
  5309. * General service functions
  5310. */
  5311. /* send a NIG loopback debug packet */
  5312. static void bnx2x_lb_pckt(struct bnx2x *bp)
  5313. {
  5314. u32 wb_write[3];
  5315. /* Ethernet source and destination addresses */
  5316. wb_write[0] = 0x55555555;
  5317. wb_write[1] = 0x55555555;
  5318. wb_write[2] = 0x20; /* SOP */
  5319. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  5320. /* NON-IP protocol */
  5321. wb_write[0] = 0x09000000;
  5322. wb_write[1] = 0x55555555;
  5323. wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */
  5324. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  5325. }
  5326. /* some of the internal memories
  5327. * are not directly readable from the driver
  5328. * to test them we send debug packets
  5329. */
  5330. static int bnx2x_int_mem_test(struct bnx2x *bp)
  5331. {
  5332. int factor;
  5333. int count, i;
  5334. u32 val = 0;
  5335. if (CHIP_REV_IS_FPGA(bp))
  5336. factor = 120;
  5337. else if (CHIP_REV_IS_EMUL(bp))
  5338. factor = 200;
  5339. else
  5340. factor = 1;
  5341. /* Disable inputs of parser neighbor blocks */
  5342. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  5343. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  5344. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  5345. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  5346. /* Write 0 to parser credits for CFC search request */
  5347. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  5348. /* send Ethernet packet */
  5349. bnx2x_lb_pckt(bp);
  5350. /* TODO do i reset NIG statistic? */
  5351. /* Wait until NIG register shows 1 packet of size 0x10 */
  5352. count = 1000 * factor;
  5353. while (count) {
  5354. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5355. val = *bnx2x_sp(bp, wb_data[0]);
  5356. if (val == 0x10)
  5357. break;
  5358. usleep_range(10000, 20000);
  5359. count--;
  5360. }
  5361. if (val != 0x10) {
  5362. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  5363. return -1;
  5364. }
  5365. /* Wait until PRS register shows 1 packet */
  5366. count = 1000 * factor;
  5367. while (count) {
  5368. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5369. if (val == 1)
  5370. break;
  5371. usleep_range(10000, 20000);
  5372. count--;
  5373. }
  5374. if (val != 0x1) {
  5375. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5376. return -2;
  5377. }
  5378. /* Reset and init BRB, PRS */
  5379. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  5380. msleep(50);
  5381. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  5382. msleep(50);
  5383. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5384. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5385. DP(NETIF_MSG_HW, "part2\n");
  5386. /* Disable inputs of parser neighbor blocks */
  5387. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  5388. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  5389. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  5390. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  5391. /* Write 0 to parser credits for CFC search request */
  5392. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  5393. /* send 10 Ethernet packets */
  5394. for (i = 0; i < 10; i++)
  5395. bnx2x_lb_pckt(bp);
  5396. /* Wait until NIG register shows 10 + 1
  5397. packets of size 11*0x10 = 0xb0 */
  5398. count = 1000 * factor;
  5399. while (count) {
  5400. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5401. val = *bnx2x_sp(bp, wb_data[0]);
  5402. if (val == 0xb0)
  5403. break;
  5404. usleep_range(10000, 20000);
  5405. count--;
  5406. }
  5407. if (val != 0xb0) {
  5408. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  5409. return -3;
  5410. }
  5411. /* Wait until PRS register shows 2 packets */
  5412. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5413. if (val != 2)
  5414. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5415. /* Write 1 to parser credits for CFC search request */
  5416. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1);
  5417. /* Wait until PRS register shows 3 packets */
  5418. msleep(10 * factor);
  5419. /* Wait until NIG register shows 1 packet of size 0x10 */
  5420. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5421. if (val != 3)
  5422. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5423. /* clear NIG EOP FIFO */
  5424. for (i = 0; i < 11; i++)
  5425. REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO);
  5426. val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY);
  5427. if (val != 1) {
  5428. BNX2X_ERR("clear of NIG failed\n");
  5429. return -4;
  5430. }
  5431. /* Reset and init BRB, PRS, NIG */
  5432. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  5433. msleep(50);
  5434. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  5435. msleep(50);
  5436. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5437. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5438. if (!CNIC_SUPPORT(bp))
  5439. /* set NIC mode */
  5440. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  5441. /* Enable inputs of parser neighbor blocks */
  5442. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff);
  5443. REG_WR(bp, TCM_REG_PRS_IFEN, 0x1);
  5444. REG_WR(bp, CFC_REG_DEBUG0, 0x0);
  5445. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1);
  5446. DP(NETIF_MSG_HW, "done\n");
  5447. return 0; /* OK */
  5448. }
  5449. static void bnx2x_enable_blocks_attention(struct bnx2x *bp)
  5450. {
  5451. u32 val;
  5452. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5453. if (!CHIP_IS_E1x(bp))
  5454. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0x40);
  5455. else
  5456. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0);
  5457. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  5458. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  5459. /*
  5460. * mask read length error interrupts in brb for parser
  5461. * (parsing unit and 'checksum and crc' unit)
  5462. * these errors are legal (PU reads fixed length and CAC can cause
  5463. * read length error on truncated packets)
  5464. */
  5465. REG_WR(bp, BRB1_REG_BRB1_INT_MASK, 0xFC00);
  5466. REG_WR(bp, QM_REG_QM_INT_MASK, 0);
  5467. REG_WR(bp, TM_REG_TM_INT_MASK, 0);
  5468. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0);
  5469. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0);
  5470. REG_WR(bp, XCM_REG_XCM_INT_MASK, 0);
  5471. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */
  5472. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */
  5473. REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0);
  5474. REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0);
  5475. REG_WR(bp, UCM_REG_UCM_INT_MASK, 0);
  5476. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */
  5477. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */
  5478. REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0);
  5479. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0);
  5480. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0);
  5481. REG_WR(bp, CCM_REG_CCM_INT_MASK, 0);
  5482. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */
  5483. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */
  5484. val = PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT |
  5485. PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF |
  5486. PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN;
  5487. if (!CHIP_IS_E1x(bp))
  5488. val |= PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED |
  5489. PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED;
  5490. REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, val);
  5491. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0);
  5492. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0);
  5493. REG_WR(bp, TCM_REG_TCM_INT_MASK, 0);
  5494. /* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */
  5495. if (!CHIP_IS_E1x(bp))
  5496. /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */
  5497. REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0x07ff);
  5498. REG_WR(bp, CDU_REG_CDU_INT_MASK, 0);
  5499. REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0);
  5500. /* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */
  5501. REG_WR(bp, PBF_REG_PBF_INT_MASK, 0x18); /* bit 3,4 masked */
  5502. }
  5503. static void bnx2x_reset_common(struct bnx2x *bp)
  5504. {
  5505. u32 val = 0x1400;
  5506. /* reset_common */
  5507. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  5508. 0xd3ffff7f);
  5509. if (CHIP_IS_E3(bp)) {
  5510. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  5511. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  5512. }
  5513. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, val);
  5514. }
  5515. static void bnx2x_setup_dmae(struct bnx2x *bp)
  5516. {
  5517. bp->dmae_ready = 0;
  5518. spin_lock_init(&bp->dmae_lock);
  5519. }
  5520. static void bnx2x_init_pxp(struct bnx2x *bp)
  5521. {
  5522. u16 devctl;
  5523. int r_order, w_order;
  5524. pcie_capability_read_word(bp->pdev, PCI_EXP_DEVCTL, &devctl);
  5525. DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl);
  5526. w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
  5527. if (bp->mrrs == -1)
  5528. r_order = ((devctl & PCI_EXP_DEVCTL_READRQ) >> 12);
  5529. else {
  5530. DP(NETIF_MSG_HW, "force read order to %d\n", bp->mrrs);
  5531. r_order = bp->mrrs;
  5532. }
  5533. bnx2x_init_pxp_arb(bp, r_order, w_order);
  5534. }
  5535. static void bnx2x_setup_fan_failure_detection(struct bnx2x *bp)
  5536. {
  5537. int is_required;
  5538. u32 val;
  5539. int port;
  5540. if (BP_NOMCP(bp))
  5541. return;
  5542. is_required = 0;
  5543. val = SHMEM_RD(bp, dev_info.shared_hw_config.config2) &
  5544. SHARED_HW_CFG_FAN_FAILURE_MASK;
  5545. if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED)
  5546. is_required = 1;
  5547. /*
  5548. * The fan failure mechanism is usually related to the PHY type since
  5549. * the power consumption of the board is affected by the PHY. Currently,
  5550. * fan is required for most designs with SFX7101, BCM8727 and BCM8481.
  5551. */
  5552. else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE)
  5553. for (port = PORT_0; port < PORT_MAX; port++) {
  5554. is_required |=
  5555. bnx2x_fan_failure_det_req(
  5556. bp,
  5557. bp->common.shmem_base,
  5558. bp->common.shmem2_base,
  5559. port);
  5560. }
  5561. DP(NETIF_MSG_HW, "fan detection setting: %d\n", is_required);
  5562. if (is_required == 0)
  5563. return;
  5564. /* Fan failure is indicated by SPIO 5 */
  5565. bnx2x_set_spio(bp, MISC_SPIO_SPIO5, MISC_SPIO_INPUT_HI_Z);
  5566. /* set to active low mode */
  5567. val = REG_RD(bp, MISC_REG_SPIO_INT);
  5568. val |= (MISC_SPIO_SPIO5 << MISC_SPIO_INT_OLD_SET_POS);
  5569. REG_WR(bp, MISC_REG_SPIO_INT, val);
  5570. /* enable interrupt to signal the IGU */
  5571. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  5572. val |= MISC_SPIO_SPIO5;
  5573. REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val);
  5574. }
  5575. void bnx2x_pf_disable(struct bnx2x *bp)
  5576. {
  5577. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  5578. val &= ~IGU_PF_CONF_FUNC_EN;
  5579. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  5580. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  5581. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 0);
  5582. }
  5583. static void bnx2x__common_init_phy(struct bnx2x *bp)
  5584. {
  5585. u32 shmem_base[2], shmem2_base[2];
  5586. /* Avoid common init in case MFW supports LFA */
  5587. if (SHMEM2_RD(bp, size) >
  5588. (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
  5589. return;
  5590. shmem_base[0] = bp->common.shmem_base;
  5591. shmem2_base[0] = bp->common.shmem2_base;
  5592. if (!CHIP_IS_E1x(bp)) {
  5593. shmem_base[1] =
  5594. SHMEM2_RD(bp, other_shmem_base_addr);
  5595. shmem2_base[1] =
  5596. SHMEM2_RD(bp, other_shmem2_base_addr);
  5597. }
  5598. bnx2x_acquire_phy_lock(bp);
  5599. bnx2x_common_init_phy(bp, shmem_base, shmem2_base,
  5600. bp->common.chip_id);
  5601. bnx2x_release_phy_lock(bp);
  5602. }
  5603. /**
  5604. * bnx2x_init_hw_common - initialize the HW at the COMMON phase.
  5605. *
  5606. * @bp: driver handle
  5607. */
  5608. static int bnx2x_init_hw_common(struct bnx2x *bp)
  5609. {
  5610. u32 val;
  5611. DP(NETIF_MSG_HW, "starting common init func %d\n", BP_ABS_FUNC(bp));
  5612. /*
  5613. * take the RESET lock to protect undi_unload flow from accessing
  5614. * registers while we're resetting the chip
  5615. */
  5616. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5617. bnx2x_reset_common(bp);
  5618. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff);
  5619. val = 0xfffc;
  5620. if (CHIP_IS_E3(bp)) {
  5621. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  5622. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  5623. }
  5624. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, val);
  5625. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5626. bnx2x_init_block(bp, BLOCK_MISC, PHASE_COMMON);
  5627. if (!CHIP_IS_E1x(bp)) {
  5628. u8 abs_func_id;
  5629. /**
  5630. * 4-port mode or 2-port mode we need to turn of master-enable
  5631. * for everyone, after that, turn it back on for self.
  5632. * so, we disregard multi-function or not, and always disable
  5633. * for all functions on the given path, this means 0,2,4,6 for
  5634. * path 0 and 1,3,5,7 for path 1
  5635. */
  5636. for (abs_func_id = BP_PATH(bp);
  5637. abs_func_id < E2_FUNC_MAX*2; abs_func_id += 2) {
  5638. if (abs_func_id == BP_ABS_FUNC(bp)) {
  5639. REG_WR(bp,
  5640. PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER,
  5641. 1);
  5642. continue;
  5643. }
  5644. bnx2x_pretend_func(bp, abs_func_id);
  5645. /* clear pf enable */
  5646. bnx2x_pf_disable(bp);
  5647. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  5648. }
  5649. }
  5650. bnx2x_init_block(bp, BLOCK_PXP, PHASE_COMMON);
  5651. if (CHIP_IS_E1(bp)) {
  5652. /* enable HW interrupt from PXP on USDM overflow
  5653. bit 16 on INT_MASK_0 */
  5654. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5655. }
  5656. bnx2x_init_block(bp, BLOCK_PXP2, PHASE_COMMON);
  5657. bnx2x_init_pxp(bp);
  5658. #ifdef __BIG_ENDIAN
  5659. REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, 1);
  5660. REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, 1);
  5661. REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, 1);
  5662. REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, 1);
  5663. REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, 1);
  5664. /* make sure this value is 0 */
  5665. REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0);
  5666. /* REG_WR(bp, PXP2_REG_RD_PBF_SWAP_MODE, 1); */
  5667. REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, 1);
  5668. REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, 1);
  5669. REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, 1);
  5670. REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, 1);
  5671. #endif
  5672. bnx2x_ilt_init_page_size(bp, INITOP_SET);
  5673. if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp))
  5674. REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1);
  5675. /* let the HW do it's magic ... */
  5676. msleep(100);
  5677. /* finish PXP init */
  5678. val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE);
  5679. if (val != 1) {
  5680. BNX2X_ERR("PXP2 CFG failed\n");
  5681. return -EBUSY;
  5682. }
  5683. val = REG_RD(bp, PXP2_REG_RD_INIT_DONE);
  5684. if (val != 1) {
  5685. BNX2X_ERR("PXP2 RD_INIT failed\n");
  5686. return -EBUSY;
  5687. }
  5688. /* Timers bug workaround E2 only. We need to set the entire ILT to
  5689. * have entries with value "0" and valid bit on.
  5690. * This needs to be done by the first PF that is loaded in a path
  5691. * (i.e. common phase)
  5692. */
  5693. if (!CHIP_IS_E1x(bp)) {
  5694. /* In E2 there is a bug in the timers block that can cause function 6 / 7
  5695. * (i.e. vnic3) to start even if it is marked as "scan-off".
  5696. * This occurs when a different function (func2,3) is being marked
  5697. * as "scan-off". Real-life scenario for example: if a driver is being
  5698. * load-unloaded while func6,7 are down. This will cause the timer to access
  5699. * the ilt, translate to a logical address and send a request to read/write.
  5700. * Since the ilt for the function that is down is not valid, this will cause
  5701. * a translation error which is unrecoverable.
  5702. * The Workaround is intended to make sure that when this happens nothing fatal
  5703. * will occur. The workaround:
  5704. * 1. First PF driver which loads on a path will:
  5705. * a. After taking the chip out of reset, by using pretend,
  5706. * it will write "0" to the following registers of
  5707. * the other vnics.
  5708. * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  5709. * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0);
  5710. * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0);
  5711. * And for itself it will write '1' to
  5712. * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable
  5713. * dmae-operations (writing to pram for example.)
  5714. * note: can be done for only function 6,7 but cleaner this
  5715. * way.
  5716. * b. Write zero+valid to the entire ILT.
  5717. * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of
  5718. * VNIC3 (of that port). The range allocated will be the
  5719. * entire ILT. This is needed to prevent ILT range error.
  5720. * 2. Any PF driver load flow:
  5721. * a. ILT update with the physical addresses of the allocated
  5722. * logical pages.
  5723. * b. Wait 20msec. - note that this timeout is needed to make
  5724. * sure there are no requests in one of the PXP internal
  5725. * queues with "old" ILT addresses.
  5726. * c. PF enable in the PGLC.
  5727. * d. Clear the was_error of the PF in the PGLC. (could have
  5728. * occurred while driver was down)
  5729. * e. PF enable in the CFC (WEAK + STRONG)
  5730. * f. Timers scan enable
  5731. * 3. PF driver unload flow:
  5732. * a. Clear the Timers scan_en.
  5733. * b. Polling for scan_on=0 for that PF.
  5734. * c. Clear the PF enable bit in the PXP.
  5735. * d. Clear the PF enable in the CFC (WEAK + STRONG)
  5736. * e. Write zero+valid to all ILT entries (The valid bit must
  5737. * stay set)
  5738. * f. If this is VNIC 3 of a port then also init
  5739. * first_timers_ilt_entry to zero and last_timers_ilt_entry
  5740. * to the last entry in the ILT.
  5741. *
  5742. * Notes:
  5743. * Currently the PF error in the PGLC is non recoverable.
  5744. * In the future the there will be a recovery routine for this error.
  5745. * Currently attention is masked.
  5746. * Having an MCP lock on the load/unload process does not guarantee that
  5747. * there is no Timer disable during Func6/7 enable. This is because the
  5748. * Timers scan is currently being cleared by the MCP on FLR.
  5749. * Step 2.d can be done only for PF6/7 and the driver can also check if
  5750. * there is error before clearing it. But the flow above is simpler and
  5751. * more general.
  5752. * All ILT entries are written by zero+valid and not just PF6/7
  5753. * ILT entries since in the future the ILT entries allocation for
  5754. * PF-s might be dynamic.
  5755. */
  5756. struct ilt_client_info ilt_cli;
  5757. struct bnx2x_ilt ilt;
  5758. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  5759. memset(&ilt, 0, sizeof(struct bnx2x_ilt));
  5760. /* initialize dummy TM client */
  5761. ilt_cli.start = 0;
  5762. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  5763. ilt_cli.client_num = ILT_CLIENT_TM;
  5764. /* Step 1: set zeroes to all ilt page entries with valid bit on
  5765. * Step 2: set the timers first/last ilt entry to point
  5766. * to the entire range to prevent ILT range error for 3rd/4th
  5767. * vnic (this code assumes existence of the vnic)
  5768. *
  5769. * both steps performed by call to bnx2x_ilt_client_init_op()
  5770. * with dummy TM client
  5771. *
  5772. * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT
  5773. * and his brother are split registers
  5774. */
  5775. bnx2x_pretend_func(bp, (BP_PATH(bp) + 6));
  5776. bnx2x_ilt_client_init_op_ilt(bp, &ilt, &ilt_cli, INITOP_CLEAR);
  5777. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  5778. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN, BNX2X_PXP_DRAM_ALIGN);
  5779. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_RD, BNX2X_PXP_DRAM_ALIGN);
  5780. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_SEL, 1);
  5781. }
  5782. REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0);
  5783. REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0);
  5784. if (!CHIP_IS_E1x(bp)) {
  5785. int factor = CHIP_REV_IS_EMUL(bp) ? 1000 :
  5786. (CHIP_REV_IS_FPGA(bp) ? 400 : 0);
  5787. bnx2x_init_block(bp, BLOCK_PGLUE_B, PHASE_COMMON);
  5788. bnx2x_init_block(bp, BLOCK_ATC, PHASE_COMMON);
  5789. /* let the HW do it's magic ... */
  5790. do {
  5791. msleep(200);
  5792. val = REG_RD(bp, ATC_REG_ATC_INIT_DONE);
  5793. } while (factor-- && (val != 1));
  5794. if (val != 1) {
  5795. BNX2X_ERR("ATC_INIT failed\n");
  5796. return -EBUSY;
  5797. }
  5798. }
  5799. bnx2x_init_block(bp, BLOCK_DMAE, PHASE_COMMON);
  5800. bnx2x_iov_init_dmae(bp);
  5801. /* clean the DMAE memory */
  5802. bp->dmae_ready = 1;
  5803. bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8, 1);
  5804. bnx2x_init_block(bp, BLOCK_TCM, PHASE_COMMON);
  5805. bnx2x_init_block(bp, BLOCK_UCM, PHASE_COMMON);
  5806. bnx2x_init_block(bp, BLOCK_CCM, PHASE_COMMON);
  5807. bnx2x_init_block(bp, BLOCK_XCM, PHASE_COMMON);
  5808. bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3);
  5809. bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3);
  5810. bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3);
  5811. bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3);
  5812. bnx2x_init_block(bp, BLOCK_QM, PHASE_COMMON);
  5813. /* QM queues pointers table */
  5814. bnx2x_qm_init_ptr_table(bp, bp->qm_cid_count, INITOP_SET);
  5815. /* soft reset pulse */
  5816. REG_WR(bp, QM_REG_SOFT_RESET, 1);
  5817. REG_WR(bp, QM_REG_SOFT_RESET, 0);
  5818. if (CNIC_SUPPORT(bp))
  5819. bnx2x_init_block(bp, BLOCK_TM, PHASE_COMMON);
  5820. bnx2x_init_block(bp, BLOCK_DORQ, PHASE_COMMON);
  5821. if (!CHIP_REV_IS_SLOW(bp))
  5822. /* enable hw interrupt from doorbell Q */
  5823. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  5824. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5825. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5826. REG_WR(bp, PRS_REG_A_PRSU_20, 0xf);
  5827. if (!CHIP_IS_E1(bp))
  5828. REG_WR(bp, PRS_REG_E1HOV_MODE, bp->path_has_ovlan);
  5829. if (!CHIP_IS_E1x(bp) && !CHIP_IS_E3B0(bp)) {
  5830. if (IS_MF_AFEX(bp)) {
  5831. /* configure that VNTag and VLAN headers must be
  5832. * received in afex mode
  5833. */
  5834. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC, 0xE);
  5835. REG_WR(bp, PRS_REG_MUST_HAVE_HDRS, 0xA);
  5836. REG_WR(bp, PRS_REG_HDRS_AFTER_TAG_0, 0x6);
  5837. REG_WR(bp, PRS_REG_TAG_ETHERTYPE_0, 0x8926);
  5838. REG_WR(bp, PRS_REG_TAG_LEN_0, 0x4);
  5839. } else {
  5840. /* Bit-map indicating which L2 hdrs may appear
  5841. * after the basic Ethernet header
  5842. */
  5843. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC,
  5844. bp->path_has_ovlan ? 7 : 6);
  5845. }
  5846. }
  5847. bnx2x_init_block(bp, BLOCK_TSDM, PHASE_COMMON);
  5848. bnx2x_init_block(bp, BLOCK_CSDM, PHASE_COMMON);
  5849. bnx2x_init_block(bp, BLOCK_USDM, PHASE_COMMON);
  5850. bnx2x_init_block(bp, BLOCK_XSDM, PHASE_COMMON);
  5851. if (!CHIP_IS_E1x(bp)) {
  5852. /* reset VFC memories */
  5853. REG_WR(bp, TSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  5854. VFC_MEMORIES_RST_REG_CAM_RST |
  5855. VFC_MEMORIES_RST_REG_RAM_RST);
  5856. REG_WR(bp, XSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  5857. VFC_MEMORIES_RST_REG_CAM_RST |
  5858. VFC_MEMORIES_RST_REG_RAM_RST);
  5859. msleep(20);
  5860. }
  5861. bnx2x_init_block(bp, BLOCK_TSEM, PHASE_COMMON);
  5862. bnx2x_init_block(bp, BLOCK_USEM, PHASE_COMMON);
  5863. bnx2x_init_block(bp, BLOCK_CSEM, PHASE_COMMON);
  5864. bnx2x_init_block(bp, BLOCK_XSEM, PHASE_COMMON);
  5865. /* sync semi rtc */
  5866. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  5867. 0x80000000);
  5868. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
  5869. 0x80000000);
  5870. bnx2x_init_block(bp, BLOCK_UPB, PHASE_COMMON);
  5871. bnx2x_init_block(bp, BLOCK_XPB, PHASE_COMMON);
  5872. bnx2x_init_block(bp, BLOCK_PBF, PHASE_COMMON);
  5873. if (!CHIP_IS_E1x(bp)) {
  5874. if (IS_MF_AFEX(bp)) {
  5875. /* configure that VNTag and VLAN headers must be
  5876. * sent in afex mode
  5877. */
  5878. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC, 0xE);
  5879. REG_WR(bp, PBF_REG_MUST_HAVE_HDRS, 0xA);
  5880. REG_WR(bp, PBF_REG_HDRS_AFTER_TAG_0, 0x6);
  5881. REG_WR(bp, PBF_REG_TAG_ETHERTYPE_0, 0x8926);
  5882. REG_WR(bp, PBF_REG_TAG_LEN_0, 0x4);
  5883. } else {
  5884. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC,
  5885. bp->path_has_ovlan ? 7 : 6);
  5886. }
  5887. }
  5888. REG_WR(bp, SRC_REG_SOFT_RST, 1);
  5889. bnx2x_init_block(bp, BLOCK_SRC, PHASE_COMMON);
  5890. if (CNIC_SUPPORT(bp)) {
  5891. REG_WR(bp, SRC_REG_KEYSEARCH_0, 0x63285672);
  5892. REG_WR(bp, SRC_REG_KEYSEARCH_1, 0x24b8f2cc);
  5893. REG_WR(bp, SRC_REG_KEYSEARCH_2, 0x223aef9b);
  5894. REG_WR(bp, SRC_REG_KEYSEARCH_3, 0x26001e3a);
  5895. REG_WR(bp, SRC_REG_KEYSEARCH_4, 0x7ae91116);
  5896. REG_WR(bp, SRC_REG_KEYSEARCH_5, 0x5ce5230b);
  5897. REG_WR(bp, SRC_REG_KEYSEARCH_6, 0x298d8adf);
  5898. REG_WR(bp, SRC_REG_KEYSEARCH_7, 0x6eb0ff09);
  5899. REG_WR(bp, SRC_REG_KEYSEARCH_8, 0x1830f82f);
  5900. REG_WR(bp, SRC_REG_KEYSEARCH_9, 0x01e46be7);
  5901. }
  5902. REG_WR(bp, SRC_REG_SOFT_RST, 0);
  5903. if (sizeof(union cdu_context) != 1024)
  5904. /* we currently assume that a context is 1024 bytes */
  5905. dev_alert(&bp->pdev->dev,
  5906. "please adjust the size of cdu_context(%ld)\n",
  5907. (long)sizeof(union cdu_context));
  5908. bnx2x_init_block(bp, BLOCK_CDU, PHASE_COMMON);
  5909. val = (4 << 24) + (0 << 12) + 1024;
  5910. REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val);
  5911. bnx2x_init_block(bp, BLOCK_CFC, PHASE_COMMON);
  5912. REG_WR(bp, CFC_REG_INIT_REG, 0x7FF);
  5913. /* enable context validation interrupt from CFC */
  5914. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  5915. /* set the thresholds to prevent CFC/CDU race */
  5916. REG_WR(bp, CFC_REG_DEBUG0, 0x20020000);
  5917. bnx2x_init_block(bp, BLOCK_HC, PHASE_COMMON);
  5918. if (!CHIP_IS_E1x(bp) && BP_NOMCP(bp))
  5919. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x36);
  5920. bnx2x_init_block(bp, BLOCK_IGU, PHASE_COMMON);
  5921. bnx2x_init_block(bp, BLOCK_MISC_AEU, PHASE_COMMON);
  5922. /* Reset PCIE errors for debug */
  5923. REG_WR(bp, 0x2814, 0xffffffff);
  5924. REG_WR(bp, 0x3820, 0xffffffff);
  5925. if (!CHIP_IS_E1x(bp)) {
  5926. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_CONTROL_5,
  5927. (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1 |
  5928. PXPCS_TL_CONTROL_5_ERR_UNSPPORT));
  5929. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC345_STAT,
  5930. (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4 |
  5931. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3 |
  5932. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2));
  5933. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC678_STAT,
  5934. (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7 |
  5935. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6 |
  5936. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5));
  5937. }
  5938. bnx2x_init_block(bp, BLOCK_NIG, PHASE_COMMON);
  5939. if (!CHIP_IS_E1(bp)) {
  5940. /* in E3 this done in per-port section */
  5941. if (!CHIP_IS_E3(bp))
  5942. REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_MF(bp));
  5943. }
  5944. if (CHIP_IS_E1H(bp))
  5945. /* not applicable for E2 (and above ...) */
  5946. REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_MF_SD(bp));
  5947. if (CHIP_REV_IS_SLOW(bp))
  5948. msleep(200);
  5949. /* finish CFC init */
  5950. val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10);
  5951. if (val != 1) {
  5952. BNX2X_ERR("CFC LL_INIT failed\n");
  5953. return -EBUSY;
  5954. }
  5955. val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10);
  5956. if (val != 1) {
  5957. BNX2X_ERR("CFC AC_INIT failed\n");
  5958. return -EBUSY;
  5959. }
  5960. val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10);
  5961. if (val != 1) {
  5962. BNX2X_ERR("CFC CAM_INIT failed\n");
  5963. return -EBUSY;
  5964. }
  5965. REG_WR(bp, CFC_REG_DEBUG0, 0);
  5966. if (CHIP_IS_E1(bp)) {
  5967. /* read NIG statistic
  5968. to see if this is our first up since powerup */
  5969. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5970. val = *bnx2x_sp(bp, wb_data[0]);
  5971. /* do internal memory self test */
  5972. if ((val == 0) && bnx2x_int_mem_test(bp)) {
  5973. BNX2X_ERR("internal mem self test failed\n");
  5974. return -EBUSY;
  5975. }
  5976. }
  5977. bnx2x_setup_fan_failure_detection(bp);
  5978. /* clear PXP2 attentions */
  5979. REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0);
  5980. bnx2x_enable_blocks_attention(bp);
  5981. bnx2x_enable_blocks_parity(bp);
  5982. if (!BP_NOMCP(bp)) {
  5983. if (CHIP_IS_E1x(bp))
  5984. bnx2x__common_init_phy(bp);
  5985. } else
  5986. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  5987. return 0;
  5988. }
  5989. /**
  5990. * bnx2x_init_hw_common_chip - init HW at the COMMON_CHIP phase.
  5991. *
  5992. * @bp: driver handle
  5993. */
  5994. static int bnx2x_init_hw_common_chip(struct bnx2x *bp)
  5995. {
  5996. int rc = bnx2x_init_hw_common(bp);
  5997. if (rc)
  5998. return rc;
  5999. /* In E2 2-PORT mode, same ext phy is used for the two paths */
  6000. if (!BP_NOMCP(bp))
  6001. bnx2x__common_init_phy(bp);
  6002. return 0;
  6003. }
  6004. static int bnx2x_init_hw_port(struct bnx2x *bp)
  6005. {
  6006. int port = BP_PORT(bp);
  6007. int init_phase = port ? PHASE_PORT1 : PHASE_PORT0;
  6008. u32 low, high;
  6009. u32 val;
  6010. DP(NETIF_MSG_HW, "starting port init port %d\n", port);
  6011. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  6012. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  6013. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  6014. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  6015. /* Timers bug workaround: disables the pf_master bit in pglue at
  6016. * common phase, we need to enable it here before any dmae access are
  6017. * attempted. Therefore we manually added the enable-master to the
  6018. * port phase (it also happens in the function phase)
  6019. */
  6020. if (!CHIP_IS_E1x(bp))
  6021. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  6022. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  6023. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  6024. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  6025. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  6026. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  6027. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  6028. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  6029. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  6030. /* QM cid (connection) count */
  6031. bnx2x_qm_init_cid_count(bp, bp->qm_cid_count, INITOP_SET);
  6032. if (CNIC_SUPPORT(bp)) {
  6033. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  6034. REG_WR(bp, TM_REG_LIN0_SCAN_TIME + port*4, 20);
  6035. REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31);
  6036. }
  6037. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  6038. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  6039. if (CHIP_IS_E1(bp) || CHIP_IS_E1H(bp)) {
  6040. if (IS_MF(bp))
  6041. low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246);
  6042. else if (bp->dev->mtu > 4096) {
  6043. if (bp->flags & ONE_PORT_FLAG)
  6044. low = 160;
  6045. else {
  6046. val = bp->dev->mtu;
  6047. /* (24*1024 + val*4)/256 */
  6048. low = 96 + (val/64) +
  6049. ((val % 64) ? 1 : 0);
  6050. }
  6051. } else
  6052. low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160);
  6053. high = low + 56; /* 14*1024/256 */
  6054. REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low);
  6055. REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high);
  6056. }
  6057. if (CHIP_MODE_IS_4_PORT(bp))
  6058. REG_WR(bp, (BP_PORT(bp) ?
  6059. BRB1_REG_MAC_GUARANTIED_1 :
  6060. BRB1_REG_MAC_GUARANTIED_0), 40);
  6061. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  6062. if (CHIP_IS_E3B0(bp)) {
  6063. if (IS_MF_AFEX(bp)) {
  6064. /* configure headers for AFEX mode */
  6065. REG_WR(bp, BP_PORT(bp) ?
  6066. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  6067. PRS_REG_HDRS_AFTER_BASIC_PORT_0, 0xE);
  6068. REG_WR(bp, BP_PORT(bp) ?
  6069. PRS_REG_HDRS_AFTER_TAG_0_PORT_1 :
  6070. PRS_REG_HDRS_AFTER_TAG_0_PORT_0, 0x6);
  6071. REG_WR(bp, BP_PORT(bp) ?
  6072. PRS_REG_MUST_HAVE_HDRS_PORT_1 :
  6073. PRS_REG_MUST_HAVE_HDRS_PORT_0, 0xA);
  6074. } else {
  6075. /* Ovlan exists only if we are in multi-function +
  6076. * switch-dependent mode, in switch-independent there
  6077. * is no ovlan headers
  6078. */
  6079. REG_WR(bp, BP_PORT(bp) ?
  6080. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  6081. PRS_REG_HDRS_AFTER_BASIC_PORT_0,
  6082. (bp->path_has_ovlan ? 7 : 6));
  6083. }
  6084. }
  6085. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  6086. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  6087. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  6088. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  6089. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  6090. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  6091. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  6092. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  6093. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  6094. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  6095. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  6096. if (CHIP_IS_E1x(bp)) {
  6097. /* configure PBF to work without PAUSE mtu 9000 */
  6098. REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
  6099. /* update threshold */
  6100. REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16));
  6101. /* update init credit */
  6102. REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22);
  6103. /* probe changes */
  6104. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1);
  6105. udelay(50);
  6106. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0);
  6107. }
  6108. if (CNIC_SUPPORT(bp))
  6109. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  6110. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  6111. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  6112. if (CHIP_IS_E1(bp)) {
  6113. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  6114. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  6115. }
  6116. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  6117. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  6118. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  6119. /* init aeu_mask_attn_func_0/1:
  6120. * - SF mode: bits 3-7 are masked. Only bits 0-2 are in use
  6121. * - MF mode: bit 3 is masked. Bits 0-2 are in use as in SF
  6122. * bits 4-7 are used for "per vn group attention" */
  6123. val = IS_MF(bp) ? 0xF7 : 0x7;
  6124. /* Enable DCBX attention for all but E1 */
  6125. val |= CHIP_IS_E1(bp) ? 0 : 0x10;
  6126. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, val);
  6127. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  6128. if (!CHIP_IS_E1x(bp)) {
  6129. /* Bit-map indicating which L2 hdrs may appear after the
  6130. * basic Ethernet header
  6131. */
  6132. if (IS_MF_AFEX(bp))
  6133. REG_WR(bp, BP_PORT(bp) ?
  6134. NIG_REG_P1_HDRS_AFTER_BASIC :
  6135. NIG_REG_P0_HDRS_AFTER_BASIC, 0xE);
  6136. else
  6137. REG_WR(bp, BP_PORT(bp) ?
  6138. NIG_REG_P1_HDRS_AFTER_BASIC :
  6139. NIG_REG_P0_HDRS_AFTER_BASIC,
  6140. IS_MF_SD(bp) ? 7 : 6);
  6141. if (CHIP_IS_E3(bp))
  6142. REG_WR(bp, BP_PORT(bp) ?
  6143. NIG_REG_LLH1_MF_MODE :
  6144. NIG_REG_LLH_MF_MODE, IS_MF(bp));
  6145. }
  6146. if (!CHIP_IS_E3(bp))
  6147. REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
  6148. if (!CHIP_IS_E1(bp)) {
  6149. /* 0x2 disable mf_ov, 0x1 enable */
  6150. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4,
  6151. (IS_MF_SD(bp) ? 0x1 : 0x2));
  6152. if (!CHIP_IS_E1x(bp)) {
  6153. val = 0;
  6154. switch (bp->mf_mode) {
  6155. case MULTI_FUNCTION_SD:
  6156. val = 1;
  6157. break;
  6158. case MULTI_FUNCTION_SI:
  6159. case MULTI_FUNCTION_AFEX:
  6160. val = 2;
  6161. break;
  6162. }
  6163. REG_WR(bp, (BP_PORT(bp) ? NIG_REG_LLH1_CLS_TYPE :
  6164. NIG_REG_LLH0_CLS_TYPE), val);
  6165. }
  6166. {
  6167. REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0);
  6168. REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0);
  6169. REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1);
  6170. }
  6171. }
  6172. /* If SPIO5 is set to generate interrupts, enable it for this port */
  6173. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  6174. if (val & MISC_SPIO_SPIO5) {
  6175. u32 reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  6176. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  6177. val = REG_RD(bp, reg_addr);
  6178. val |= AEU_INPUTS_ATTN_BITS_SPIO5;
  6179. REG_WR(bp, reg_addr, val);
  6180. }
  6181. return 0;
  6182. }
  6183. static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr)
  6184. {
  6185. int reg;
  6186. u32 wb_write[2];
  6187. if (CHIP_IS_E1(bp))
  6188. reg = PXP2_REG_RQ_ONCHIP_AT + index*8;
  6189. else
  6190. reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8;
  6191. wb_write[0] = ONCHIP_ADDR1(addr);
  6192. wb_write[1] = ONCHIP_ADDR2(addr);
  6193. REG_WR_DMAE(bp, reg, wb_write, 2);
  6194. }
  6195. void bnx2x_igu_clear_sb_gen(struct bnx2x *bp, u8 func, u8 idu_sb_id, bool is_pf)
  6196. {
  6197. u32 data, ctl, cnt = 100;
  6198. u32 igu_addr_data = IGU_REG_COMMAND_REG_32LSB_DATA;
  6199. u32 igu_addr_ctl = IGU_REG_COMMAND_REG_CTRL;
  6200. u32 igu_addr_ack = IGU_REG_CSTORM_TYPE_0_SB_CLEANUP + (idu_sb_id/32)*4;
  6201. u32 sb_bit = 1 << (idu_sb_id%32);
  6202. u32 func_encode = func | (is_pf ? 1 : 0) << IGU_FID_ENCODE_IS_PF_SHIFT;
  6203. u32 addr_encode = IGU_CMD_E2_PROD_UPD_BASE + idu_sb_id;
  6204. /* Not supported in BC mode */
  6205. if (CHIP_INT_MODE_IS_BC(bp))
  6206. return;
  6207. data = (IGU_USE_REGISTER_cstorm_type_0_sb_cleanup
  6208. << IGU_REGULAR_CLEANUP_TYPE_SHIFT) |
  6209. IGU_REGULAR_CLEANUP_SET |
  6210. IGU_REGULAR_BCLEANUP;
  6211. ctl = addr_encode << IGU_CTRL_REG_ADDRESS_SHIFT |
  6212. func_encode << IGU_CTRL_REG_FID_SHIFT |
  6213. IGU_CTRL_CMD_TYPE_WR << IGU_CTRL_REG_TYPE_SHIFT;
  6214. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  6215. data, igu_addr_data);
  6216. REG_WR(bp, igu_addr_data, data);
  6217. mmiowb();
  6218. barrier();
  6219. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  6220. ctl, igu_addr_ctl);
  6221. REG_WR(bp, igu_addr_ctl, ctl);
  6222. mmiowb();
  6223. barrier();
  6224. /* wait for clean up to finish */
  6225. while (!(REG_RD(bp, igu_addr_ack) & sb_bit) && --cnt)
  6226. msleep(20);
  6227. if (!(REG_RD(bp, igu_addr_ack) & sb_bit)) {
  6228. DP(NETIF_MSG_HW,
  6229. "Unable to finish IGU cleanup: idu_sb_id %d offset %d bit %d (cnt %d)\n",
  6230. idu_sb_id, idu_sb_id/32, idu_sb_id%32, cnt);
  6231. }
  6232. }
  6233. static void bnx2x_igu_clear_sb(struct bnx2x *bp, u8 idu_sb_id)
  6234. {
  6235. bnx2x_igu_clear_sb_gen(bp, BP_FUNC(bp), idu_sb_id, true /*PF*/);
  6236. }
  6237. static void bnx2x_clear_func_ilt(struct bnx2x *bp, u32 func)
  6238. {
  6239. u32 i, base = FUNC_ILT_BASE(func);
  6240. for (i = base; i < base + ILT_PER_FUNC; i++)
  6241. bnx2x_ilt_wr(bp, i, 0);
  6242. }
  6243. static void bnx2x_init_searcher(struct bnx2x *bp)
  6244. {
  6245. int port = BP_PORT(bp);
  6246. bnx2x_src_init_t2(bp, bp->t2, bp->t2_mapping, SRC_CONN_NUM);
  6247. /* T1 hash bits value determines the T1 number of entries */
  6248. REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + port*4, SRC_HASH_BITS);
  6249. }
  6250. static inline int bnx2x_func_switch_update(struct bnx2x *bp, int suspend)
  6251. {
  6252. int rc;
  6253. struct bnx2x_func_state_params func_params = {NULL};
  6254. struct bnx2x_func_switch_update_params *switch_update_params =
  6255. &func_params.params.switch_update;
  6256. /* Prepare parameters for function state transitions */
  6257. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  6258. __set_bit(RAMROD_RETRY, &func_params.ramrod_flags);
  6259. func_params.f_obj = &bp->func_obj;
  6260. func_params.cmd = BNX2X_F_CMD_SWITCH_UPDATE;
  6261. /* Function parameters */
  6262. switch_update_params->suspend = suspend;
  6263. rc = bnx2x_func_state_change(bp, &func_params);
  6264. return rc;
  6265. }
  6266. static int bnx2x_reset_nic_mode(struct bnx2x *bp)
  6267. {
  6268. int rc, i, port = BP_PORT(bp);
  6269. int vlan_en = 0, mac_en[NUM_MACS];
  6270. /* Close input from network */
  6271. if (bp->mf_mode == SINGLE_FUNCTION) {
  6272. bnx2x_set_rx_filter(&bp->link_params, 0);
  6273. } else {
  6274. vlan_en = REG_RD(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6275. NIG_REG_LLH0_FUNC_EN);
  6276. REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6277. NIG_REG_LLH0_FUNC_EN, 0);
  6278. for (i = 0; i < NUM_MACS; i++) {
  6279. mac_en[i] = REG_RD(bp, port ?
  6280. (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6281. 4 * i) :
  6282. (NIG_REG_LLH0_FUNC_MEM_ENABLE +
  6283. 4 * i));
  6284. REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6285. 4 * i) :
  6286. (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i), 0);
  6287. }
  6288. }
  6289. /* Close BMC to host */
  6290. REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
  6291. NIG_REG_P1_TX_MNG_HOST_ENABLE, 0);
  6292. /* Suspend Tx switching to the PF. Completion of this ramrod
  6293. * further guarantees that all the packets of that PF / child
  6294. * VFs in BRB were processed by the Parser, so it is safe to
  6295. * change the NIC_MODE register.
  6296. */
  6297. rc = bnx2x_func_switch_update(bp, 1);
  6298. if (rc) {
  6299. BNX2X_ERR("Can't suspend tx-switching!\n");
  6300. return rc;
  6301. }
  6302. /* Change NIC_MODE register */
  6303. REG_WR(bp, PRS_REG_NIC_MODE, 0);
  6304. /* Open input from network */
  6305. if (bp->mf_mode == SINGLE_FUNCTION) {
  6306. bnx2x_set_rx_filter(&bp->link_params, 1);
  6307. } else {
  6308. REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6309. NIG_REG_LLH0_FUNC_EN, vlan_en);
  6310. for (i = 0; i < NUM_MACS; i++) {
  6311. REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6312. 4 * i) :
  6313. (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i),
  6314. mac_en[i]);
  6315. }
  6316. }
  6317. /* Enable BMC to host */
  6318. REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
  6319. NIG_REG_P1_TX_MNG_HOST_ENABLE, 1);
  6320. /* Resume Tx switching to the PF */
  6321. rc = bnx2x_func_switch_update(bp, 0);
  6322. if (rc) {
  6323. BNX2X_ERR("Can't resume tx-switching!\n");
  6324. return rc;
  6325. }
  6326. DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
  6327. return 0;
  6328. }
  6329. int bnx2x_init_hw_func_cnic(struct bnx2x *bp)
  6330. {
  6331. int rc;
  6332. bnx2x_ilt_init_op_cnic(bp, INITOP_SET);
  6333. if (CONFIGURE_NIC_MODE(bp)) {
  6334. /* Configure searcher as part of function hw init */
  6335. bnx2x_init_searcher(bp);
  6336. /* Reset NIC mode */
  6337. rc = bnx2x_reset_nic_mode(bp);
  6338. if (rc)
  6339. BNX2X_ERR("Can't change NIC mode!\n");
  6340. return rc;
  6341. }
  6342. return 0;
  6343. }
  6344. static int bnx2x_init_hw_func(struct bnx2x *bp)
  6345. {
  6346. int port = BP_PORT(bp);
  6347. int func = BP_FUNC(bp);
  6348. int init_phase = PHASE_PF0 + func;
  6349. struct bnx2x_ilt *ilt = BP_ILT(bp);
  6350. u16 cdu_ilt_start;
  6351. u32 addr, val;
  6352. u32 main_mem_base, main_mem_size, main_mem_prty_clr;
  6353. int i, main_mem_width, rc;
  6354. DP(NETIF_MSG_HW, "starting func init func %d\n", func);
  6355. /* FLR cleanup - hmmm */
  6356. if (!CHIP_IS_E1x(bp)) {
  6357. rc = bnx2x_pf_flr_clnup(bp);
  6358. if (rc) {
  6359. bnx2x_fw_dump(bp);
  6360. return rc;
  6361. }
  6362. }
  6363. /* set MSI reconfigure capability */
  6364. if (bp->common.int_block == INT_BLOCK_HC) {
  6365. addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0);
  6366. val = REG_RD(bp, addr);
  6367. val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0;
  6368. REG_WR(bp, addr, val);
  6369. }
  6370. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  6371. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  6372. ilt = BP_ILT(bp);
  6373. cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
  6374. if (IS_SRIOV(bp))
  6375. cdu_ilt_start += BNX2X_FIRST_VF_CID/ILT_PAGE_CIDS;
  6376. cdu_ilt_start = bnx2x_iov_init_ilt(bp, cdu_ilt_start);
  6377. /* since BNX2X_FIRST_VF_CID > 0 the PF L2 cids precedes
  6378. * those of the VFs, so start line should be reset
  6379. */
  6380. cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
  6381. for (i = 0; i < L2_ILT_LINES(bp); i++) {
  6382. ilt->lines[cdu_ilt_start + i].page = bp->context[i].vcxt;
  6383. ilt->lines[cdu_ilt_start + i].page_mapping =
  6384. bp->context[i].cxt_mapping;
  6385. ilt->lines[cdu_ilt_start + i].size = bp->context[i].size;
  6386. }
  6387. bnx2x_ilt_init_op(bp, INITOP_SET);
  6388. if (!CONFIGURE_NIC_MODE(bp)) {
  6389. bnx2x_init_searcher(bp);
  6390. REG_WR(bp, PRS_REG_NIC_MODE, 0);
  6391. DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
  6392. } else {
  6393. /* Set NIC mode */
  6394. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  6395. DP(NETIF_MSG_IFUP, "NIC MODE configured\n");
  6396. }
  6397. if (!CHIP_IS_E1x(bp)) {
  6398. u32 pf_conf = IGU_PF_CONF_FUNC_EN;
  6399. /* Turn on a single ISR mode in IGU if driver is going to use
  6400. * INT#x or MSI
  6401. */
  6402. if (!(bp->flags & USING_MSIX_FLAG))
  6403. pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN;
  6404. /*
  6405. * Timers workaround bug: function init part.
  6406. * Need to wait 20msec after initializing ILT,
  6407. * needed to make sure there are no requests in
  6408. * one of the PXP internal queues with "old" ILT addresses
  6409. */
  6410. msleep(20);
  6411. /*
  6412. * Master enable - Due to WB DMAE writes performed before this
  6413. * register is re-initialized as part of the regular function
  6414. * init
  6415. */
  6416. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  6417. /* Enable the function in IGU */
  6418. REG_WR(bp, IGU_REG_PF_CONFIGURATION, pf_conf);
  6419. }
  6420. bp->dmae_ready = 1;
  6421. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  6422. if (!CHIP_IS_E1x(bp))
  6423. REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, func);
  6424. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  6425. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  6426. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  6427. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  6428. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  6429. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  6430. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  6431. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  6432. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  6433. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  6434. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  6435. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  6436. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  6437. if (!CHIP_IS_E1x(bp))
  6438. REG_WR(bp, QM_REG_PF_EN, 1);
  6439. if (!CHIP_IS_E1x(bp)) {
  6440. REG_WR(bp, TSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6441. REG_WR(bp, USEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6442. REG_WR(bp, CSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6443. REG_WR(bp, XSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6444. }
  6445. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  6446. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  6447. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  6448. REG_WR(bp, DORQ_REG_MODE_ACT, 1); /* no dpm */
  6449. bnx2x_iov_init_dq(bp);
  6450. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  6451. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  6452. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  6453. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  6454. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  6455. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  6456. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  6457. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  6458. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  6459. if (!CHIP_IS_E1x(bp))
  6460. REG_WR(bp, PBF_REG_DISABLE_PF, 0);
  6461. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  6462. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  6463. if (!CHIP_IS_E1x(bp))
  6464. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 1);
  6465. if (IS_MF(bp)) {
  6466. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
  6467. REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port*8, bp->mf_ov);
  6468. }
  6469. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  6470. /* HC init per function */
  6471. if (bp->common.int_block == INT_BLOCK_HC) {
  6472. if (CHIP_IS_E1H(bp)) {
  6473. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  6474. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  6475. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  6476. }
  6477. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  6478. } else {
  6479. int num_segs, sb_idx, prod_offset;
  6480. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  6481. if (!CHIP_IS_E1x(bp)) {
  6482. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  6483. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  6484. }
  6485. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  6486. if (!CHIP_IS_E1x(bp)) {
  6487. int dsb_idx = 0;
  6488. /**
  6489. * Producer memory:
  6490. * E2 mode: address 0-135 match to the mapping memory;
  6491. * 136 - PF0 default prod; 137 - PF1 default prod;
  6492. * 138 - PF2 default prod; 139 - PF3 default prod;
  6493. * 140 - PF0 attn prod; 141 - PF1 attn prod;
  6494. * 142 - PF2 attn prod; 143 - PF3 attn prod;
  6495. * 144-147 reserved.
  6496. *
  6497. * E1.5 mode - In backward compatible mode;
  6498. * for non default SB; each even line in the memory
  6499. * holds the U producer and each odd line hold
  6500. * the C producer. The first 128 producers are for
  6501. * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20
  6502. * producers are for the DSB for each PF.
  6503. * Each PF has five segments: (the order inside each
  6504. * segment is PF0; PF1; PF2; PF3) - 128-131 U prods;
  6505. * 132-135 C prods; 136-139 X prods; 140-143 T prods;
  6506. * 144-147 attn prods;
  6507. */
  6508. /* non-default-status-blocks */
  6509. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  6510. IGU_BC_NDSB_NUM_SEGS : IGU_NORM_NDSB_NUM_SEGS;
  6511. for (sb_idx = 0; sb_idx < bp->igu_sb_cnt; sb_idx++) {
  6512. prod_offset = (bp->igu_base_sb + sb_idx) *
  6513. num_segs;
  6514. for (i = 0; i < num_segs; i++) {
  6515. addr = IGU_REG_PROD_CONS_MEMORY +
  6516. (prod_offset + i) * 4;
  6517. REG_WR(bp, addr, 0);
  6518. }
  6519. /* send consumer update with value 0 */
  6520. bnx2x_ack_sb(bp, bp->igu_base_sb + sb_idx,
  6521. USTORM_ID, 0, IGU_INT_NOP, 1);
  6522. bnx2x_igu_clear_sb(bp,
  6523. bp->igu_base_sb + sb_idx);
  6524. }
  6525. /* default-status-blocks */
  6526. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  6527. IGU_BC_DSB_NUM_SEGS : IGU_NORM_DSB_NUM_SEGS;
  6528. if (CHIP_MODE_IS_4_PORT(bp))
  6529. dsb_idx = BP_FUNC(bp);
  6530. else
  6531. dsb_idx = BP_VN(bp);
  6532. prod_offset = (CHIP_INT_MODE_IS_BC(bp) ?
  6533. IGU_BC_BASE_DSB_PROD + dsb_idx :
  6534. IGU_NORM_BASE_DSB_PROD + dsb_idx);
  6535. /*
  6536. * igu prods come in chunks of E1HVN_MAX (4) -
  6537. * does not matters what is the current chip mode
  6538. */
  6539. for (i = 0; i < (num_segs * E1HVN_MAX);
  6540. i += E1HVN_MAX) {
  6541. addr = IGU_REG_PROD_CONS_MEMORY +
  6542. (prod_offset + i)*4;
  6543. REG_WR(bp, addr, 0);
  6544. }
  6545. /* send consumer update with 0 */
  6546. if (CHIP_INT_MODE_IS_BC(bp)) {
  6547. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6548. USTORM_ID, 0, IGU_INT_NOP, 1);
  6549. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6550. CSTORM_ID, 0, IGU_INT_NOP, 1);
  6551. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6552. XSTORM_ID, 0, IGU_INT_NOP, 1);
  6553. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6554. TSTORM_ID, 0, IGU_INT_NOP, 1);
  6555. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6556. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  6557. } else {
  6558. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6559. USTORM_ID, 0, IGU_INT_NOP, 1);
  6560. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6561. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  6562. }
  6563. bnx2x_igu_clear_sb(bp, bp->igu_dsb_id);
  6564. /* !!! These should become driver const once
  6565. rf-tool supports split-68 const */
  6566. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0);
  6567. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0);
  6568. REG_WR(bp, IGU_REG_SB_MASK_LSB, 0);
  6569. REG_WR(bp, IGU_REG_SB_MASK_MSB, 0);
  6570. REG_WR(bp, IGU_REG_PBA_STATUS_LSB, 0);
  6571. REG_WR(bp, IGU_REG_PBA_STATUS_MSB, 0);
  6572. }
  6573. }
  6574. /* Reset PCIE errors for debug */
  6575. REG_WR(bp, 0x2114, 0xffffffff);
  6576. REG_WR(bp, 0x2120, 0xffffffff);
  6577. if (CHIP_IS_E1x(bp)) {
  6578. main_mem_size = HC_REG_MAIN_MEMORY_SIZE / 2; /*dwords*/
  6579. main_mem_base = HC_REG_MAIN_MEMORY +
  6580. BP_PORT(bp) * (main_mem_size * 4);
  6581. main_mem_prty_clr = HC_REG_HC_PRTY_STS_CLR;
  6582. main_mem_width = 8;
  6583. val = REG_RD(bp, main_mem_prty_clr);
  6584. if (val)
  6585. DP(NETIF_MSG_HW,
  6586. "Hmmm... Parity errors in HC block during function init (0x%x)!\n",
  6587. val);
  6588. /* Clear "false" parity errors in MSI-X table */
  6589. for (i = main_mem_base;
  6590. i < main_mem_base + main_mem_size * 4;
  6591. i += main_mem_width) {
  6592. bnx2x_read_dmae(bp, i, main_mem_width / 4);
  6593. bnx2x_write_dmae(bp, bnx2x_sp_mapping(bp, wb_data),
  6594. i, main_mem_width / 4);
  6595. }
  6596. /* Clear HC parity attention */
  6597. REG_RD(bp, main_mem_prty_clr);
  6598. }
  6599. #ifdef BNX2X_STOP_ON_ERROR
  6600. /* Enable STORMs SP logging */
  6601. REG_WR8(bp, BAR_USTRORM_INTMEM +
  6602. USTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6603. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  6604. TSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6605. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6606. CSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6607. REG_WR8(bp, BAR_XSTRORM_INTMEM +
  6608. XSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6609. #endif
  6610. bnx2x_phy_probe(&bp->link_params);
  6611. return 0;
  6612. }
  6613. void bnx2x_free_mem_cnic(struct bnx2x *bp)
  6614. {
  6615. bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_FREE);
  6616. if (!CHIP_IS_E1x(bp))
  6617. BNX2X_PCI_FREE(bp->cnic_sb.e2_sb, bp->cnic_sb_mapping,
  6618. sizeof(struct host_hc_status_block_e2));
  6619. else
  6620. BNX2X_PCI_FREE(bp->cnic_sb.e1x_sb, bp->cnic_sb_mapping,
  6621. sizeof(struct host_hc_status_block_e1x));
  6622. BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
  6623. }
  6624. void bnx2x_free_mem(struct bnx2x *bp)
  6625. {
  6626. int i;
  6627. BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
  6628. bp->fw_stats_data_sz + bp->fw_stats_req_sz);
  6629. if (IS_VF(bp))
  6630. return;
  6631. BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping,
  6632. sizeof(struct host_sp_status_block));
  6633. BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping,
  6634. sizeof(struct bnx2x_slowpath));
  6635. for (i = 0; i < L2_ILT_LINES(bp); i++)
  6636. BNX2X_PCI_FREE(bp->context[i].vcxt, bp->context[i].cxt_mapping,
  6637. bp->context[i].size);
  6638. bnx2x_ilt_mem_op(bp, ILT_MEMOP_FREE);
  6639. BNX2X_FREE(bp->ilt->lines);
  6640. BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE);
  6641. BNX2X_PCI_FREE(bp->eq_ring, bp->eq_mapping,
  6642. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  6643. BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
  6644. bnx2x_iov_free_mem(bp);
  6645. }
  6646. int bnx2x_alloc_mem_cnic(struct bnx2x *bp)
  6647. {
  6648. if (!CHIP_IS_E1x(bp))
  6649. /* size = the status block + ramrod buffers */
  6650. BNX2X_PCI_ALLOC(bp->cnic_sb.e2_sb, &bp->cnic_sb_mapping,
  6651. sizeof(struct host_hc_status_block_e2));
  6652. else
  6653. BNX2X_PCI_ALLOC(bp->cnic_sb.e1x_sb,
  6654. &bp->cnic_sb_mapping,
  6655. sizeof(struct
  6656. host_hc_status_block_e1x));
  6657. if (CONFIGURE_NIC_MODE(bp) && !bp->t2)
  6658. /* allocate searcher T2 table, as it wasn't allocated before */
  6659. BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
  6660. /* write address to which L5 should insert its values */
  6661. bp->cnic_eth_dev.addr_drv_info_to_mcp =
  6662. &bp->slowpath->drv_info_to_mcp;
  6663. if (bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_ALLOC))
  6664. goto alloc_mem_err;
  6665. return 0;
  6666. alloc_mem_err:
  6667. bnx2x_free_mem_cnic(bp);
  6668. BNX2X_ERR("Can't allocate memory\n");
  6669. return -ENOMEM;
  6670. }
  6671. int bnx2x_alloc_mem(struct bnx2x *bp)
  6672. {
  6673. int i, allocated, context_size;
  6674. if (!CONFIGURE_NIC_MODE(bp) && !bp->t2)
  6675. /* allocate searcher T2 table */
  6676. BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
  6677. BNX2X_PCI_ALLOC(bp->def_status_blk, &bp->def_status_blk_mapping,
  6678. sizeof(struct host_sp_status_block));
  6679. BNX2X_PCI_ALLOC(bp->slowpath, &bp->slowpath_mapping,
  6680. sizeof(struct bnx2x_slowpath));
  6681. /* Allocate memory for CDU context:
  6682. * This memory is allocated separately and not in the generic ILT
  6683. * functions because CDU differs in few aspects:
  6684. * 1. There are multiple entities allocating memory for context -
  6685. * 'regular' driver, CNIC and SRIOV driver. Each separately controls
  6686. * its own ILT lines.
  6687. * 2. Since CDU page-size is not a single 4KB page (which is the case
  6688. * for the other ILT clients), to be efficient we want to support
  6689. * allocation of sub-page-size in the last entry.
  6690. * 3. Context pointers are used by the driver to pass to FW / update
  6691. * the context (for the other ILT clients the pointers are used just to
  6692. * free the memory during unload).
  6693. */
  6694. context_size = sizeof(union cdu_context) * BNX2X_L2_CID_COUNT(bp);
  6695. for (i = 0, allocated = 0; allocated < context_size; i++) {
  6696. bp->context[i].size = min(CDU_ILT_PAGE_SZ,
  6697. (context_size - allocated));
  6698. BNX2X_PCI_ALLOC(bp->context[i].vcxt,
  6699. &bp->context[i].cxt_mapping,
  6700. bp->context[i].size);
  6701. allocated += bp->context[i].size;
  6702. }
  6703. BNX2X_ALLOC(bp->ilt->lines, sizeof(struct ilt_line) * ILT_MAX_LINES);
  6704. if (bnx2x_ilt_mem_op(bp, ILT_MEMOP_ALLOC))
  6705. goto alloc_mem_err;
  6706. if (bnx2x_iov_alloc_mem(bp))
  6707. goto alloc_mem_err;
  6708. /* Slow path ring */
  6709. BNX2X_PCI_ALLOC(bp->spq, &bp->spq_mapping, BCM_PAGE_SIZE);
  6710. /* EQ */
  6711. BNX2X_PCI_ALLOC(bp->eq_ring, &bp->eq_mapping,
  6712. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  6713. return 0;
  6714. alloc_mem_err:
  6715. bnx2x_free_mem(bp);
  6716. BNX2X_ERR("Can't allocate memory\n");
  6717. return -ENOMEM;
  6718. }
  6719. /*
  6720. * Init service functions
  6721. */
  6722. int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac,
  6723. struct bnx2x_vlan_mac_obj *obj, bool set,
  6724. int mac_type, unsigned long *ramrod_flags)
  6725. {
  6726. int rc;
  6727. struct bnx2x_vlan_mac_ramrod_params ramrod_param;
  6728. memset(&ramrod_param, 0, sizeof(ramrod_param));
  6729. /* Fill general parameters */
  6730. ramrod_param.vlan_mac_obj = obj;
  6731. ramrod_param.ramrod_flags = *ramrod_flags;
  6732. /* Fill a user request section if needed */
  6733. if (!test_bit(RAMROD_CONT, ramrod_flags)) {
  6734. memcpy(ramrod_param.user_req.u.mac.mac, mac, ETH_ALEN);
  6735. __set_bit(mac_type, &ramrod_param.user_req.vlan_mac_flags);
  6736. /* Set the command: ADD or DEL */
  6737. if (set)
  6738. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD;
  6739. else
  6740. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_DEL;
  6741. }
  6742. rc = bnx2x_config_vlan_mac(bp, &ramrod_param);
  6743. if (rc == -EEXIST) {
  6744. DP(BNX2X_MSG_SP, "Failed to schedule ADD operations: %d\n", rc);
  6745. /* do not treat adding same MAC as error */
  6746. rc = 0;
  6747. } else if (rc < 0)
  6748. BNX2X_ERR("%s MAC failed\n", (set ? "Set" : "Del"));
  6749. return rc;
  6750. }
  6751. int bnx2x_del_all_macs(struct bnx2x *bp,
  6752. struct bnx2x_vlan_mac_obj *mac_obj,
  6753. int mac_type, bool wait_for_comp)
  6754. {
  6755. int rc;
  6756. unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
  6757. /* Wait for completion of requested */
  6758. if (wait_for_comp)
  6759. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  6760. /* Set the mac type of addresses we want to clear */
  6761. __set_bit(mac_type, &vlan_mac_flags);
  6762. rc = mac_obj->delete_all(bp, mac_obj, &vlan_mac_flags, &ramrod_flags);
  6763. if (rc < 0)
  6764. BNX2X_ERR("Failed to delete MACs: %d\n", rc);
  6765. return rc;
  6766. }
  6767. int bnx2x_set_eth_mac(struct bnx2x *bp, bool set)
  6768. {
  6769. if (is_zero_ether_addr(bp->dev->dev_addr) &&
  6770. (IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp))) {
  6771. DP(NETIF_MSG_IFUP | NETIF_MSG_IFDOWN,
  6772. "Ignoring Zero MAC for STORAGE SD mode\n");
  6773. return 0;
  6774. }
  6775. if (IS_PF(bp)) {
  6776. unsigned long ramrod_flags = 0;
  6777. DP(NETIF_MSG_IFUP, "Adding Eth MAC\n");
  6778. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  6779. return bnx2x_set_mac_one(bp, bp->dev->dev_addr,
  6780. &bp->sp_objs->mac_obj, set,
  6781. BNX2X_ETH_MAC, &ramrod_flags);
  6782. } else { /* vf */
  6783. return bnx2x_vfpf_config_mac(bp, bp->dev->dev_addr,
  6784. bp->fp->index, true);
  6785. }
  6786. }
  6787. int bnx2x_setup_leading(struct bnx2x *bp)
  6788. {
  6789. if (IS_PF(bp))
  6790. return bnx2x_setup_queue(bp, &bp->fp[0], true);
  6791. else /* VF */
  6792. return bnx2x_vfpf_setup_q(bp, &bp->fp[0], true);
  6793. }
  6794. /**
  6795. * bnx2x_set_int_mode - configure interrupt mode
  6796. *
  6797. * @bp: driver handle
  6798. *
  6799. * In case of MSI-X it will also try to enable MSI-X.
  6800. */
  6801. int bnx2x_set_int_mode(struct bnx2x *bp)
  6802. {
  6803. int rc = 0;
  6804. if (IS_VF(bp) && int_mode != BNX2X_INT_MODE_MSIX) {
  6805. BNX2X_ERR("VF not loaded since interrupt mode not msix\n");
  6806. return -EINVAL;
  6807. }
  6808. switch (int_mode) {
  6809. case BNX2X_INT_MODE_MSIX:
  6810. /* attempt to enable msix */
  6811. rc = bnx2x_enable_msix(bp);
  6812. /* msix attained */
  6813. if (!rc)
  6814. return 0;
  6815. /* vfs use only msix */
  6816. if (rc && IS_VF(bp))
  6817. return rc;
  6818. /* failed to enable multiple MSI-X */
  6819. BNX2X_DEV_INFO("Failed to enable multiple MSI-X (%d), set number of queues to %d\n",
  6820. bp->num_queues,
  6821. 1 + bp->num_cnic_queues);
  6822. /* falling through... */
  6823. case BNX2X_INT_MODE_MSI:
  6824. bnx2x_enable_msi(bp);
  6825. /* falling through... */
  6826. case BNX2X_INT_MODE_INTX:
  6827. bp->num_ethernet_queues = 1;
  6828. bp->num_queues = bp->num_ethernet_queues + bp->num_cnic_queues;
  6829. BNX2X_DEV_INFO("set number of queues to 1\n");
  6830. break;
  6831. default:
  6832. BNX2X_DEV_INFO("unknown value in int_mode module parameter\n");
  6833. return -EINVAL;
  6834. }
  6835. return 0;
  6836. }
  6837. /* must be called prior to any HW initializations */
  6838. static inline u16 bnx2x_cid_ilt_lines(struct bnx2x *bp)
  6839. {
  6840. if (IS_SRIOV(bp))
  6841. return (BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)/ILT_PAGE_CIDS;
  6842. return L2_ILT_LINES(bp);
  6843. }
  6844. void bnx2x_ilt_set_info(struct bnx2x *bp)
  6845. {
  6846. struct ilt_client_info *ilt_client;
  6847. struct bnx2x_ilt *ilt = BP_ILT(bp);
  6848. u16 line = 0;
  6849. ilt->start_line = FUNC_ILT_BASE(BP_FUNC(bp));
  6850. DP(BNX2X_MSG_SP, "ilt starts at line %d\n", ilt->start_line);
  6851. /* CDU */
  6852. ilt_client = &ilt->clients[ILT_CLIENT_CDU];
  6853. ilt_client->client_num = ILT_CLIENT_CDU;
  6854. ilt_client->page_size = CDU_ILT_PAGE_SZ;
  6855. ilt_client->flags = ILT_CLIENT_SKIP_MEM;
  6856. ilt_client->start = line;
  6857. line += bnx2x_cid_ilt_lines(bp);
  6858. if (CNIC_SUPPORT(bp))
  6859. line += CNIC_ILT_LINES;
  6860. ilt_client->end = line - 1;
  6861. DP(NETIF_MSG_IFUP, "ilt client[CDU]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6862. ilt_client->start,
  6863. ilt_client->end,
  6864. ilt_client->page_size,
  6865. ilt_client->flags,
  6866. ilog2(ilt_client->page_size >> 12));
  6867. /* QM */
  6868. if (QM_INIT(bp->qm_cid_count)) {
  6869. ilt_client = &ilt->clients[ILT_CLIENT_QM];
  6870. ilt_client->client_num = ILT_CLIENT_QM;
  6871. ilt_client->page_size = QM_ILT_PAGE_SZ;
  6872. ilt_client->flags = 0;
  6873. ilt_client->start = line;
  6874. /* 4 bytes for each cid */
  6875. line += DIV_ROUND_UP(bp->qm_cid_count * QM_QUEUES_PER_FUNC * 4,
  6876. QM_ILT_PAGE_SZ);
  6877. ilt_client->end = line - 1;
  6878. DP(NETIF_MSG_IFUP,
  6879. "ilt client[QM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6880. ilt_client->start,
  6881. ilt_client->end,
  6882. ilt_client->page_size,
  6883. ilt_client->flags,
  6884. ilog2(ilt_client->page_size >> 12));
  6885. }
  6886. if (CNIC_SUPPORT(bp)) {
  6887. /* SRC */
  6888. ilt_client = &ilt->clients[ILT_CLIENT_SRC];
  6889. ilt_client->client_num = ILT_CLIENT_SRC;
  6890. ilt_client->page_size = SRC_ILT_PAGE_SZ;
  6891. ilt_client->flags = 0;
  6892. ilt_client->start = line;
  6893. line += SRC_ILT_LINES;
  6894. ilt_client->end = line - 1;
  6895. DP(NETIF_MSG_IFUP,
  6896. "ilt client[SRC]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6897. ilt_client->start,
  6898. ilt_client->end,
  6899. ilt_client->page_size,
  6900. ilt_client->flags,
  6901. ilog2(ilt_client->page_size >> 12));
  6902. /* TM */
  6903. ilt_client = &ilt->clients[ILT_CLIENT_TM];
  6904. ilt_client->client_num = ILT_CLIENT_TM;
  6905. ilt_client->page_size = TM_ILT_PAGE_SZ;
  6906. ilt_client->flags = 0;
  6907. ilt_client->start = line;
  6908. line += TM_ILT_LINES;
  6909. ilt_client->end = line - 1;
  6910. DP(NETIF_MSG_IFUP,
  6911. "ilt client[TM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6912. ilt_client->start,
  6913. ilt_client->end,
  6914. ilt_client->page_size,
  6915. ilt_client->flags,
  6916. ilog2(ilt_client->page_size >> 12));
  6917. }
  6918. BUG_ON(line > ILT_MAX_LINES);
  6919. }
  6920. /**
  6921. * bnx2x_pf_q_prep_init - prepare INIT transition parameters
  6922. *
  6923. * @bp: driver handle
  6924. * @fp: pointer to fastpath
  6925. * @init_params: pointer to parameters structure
  6926. *
  6927. * parameters configured:
  6928. * - HC configuration
  6929. * - Queue's CDU context
  6930. */
  6931. static void bnx2x_pf_q_prep_init(struct bnx2x *bp,
  6932. struct bnx2x_fastpath *fp, struct bnx2x_queue_init_params *init_params)
  6933. {
  6934. u8 cos;
  6935. int cxt_index, cxt_offset;
  6936. /* FCoE Queue uses Default SB, thus has no HC capabilities */
  6937. if (!IS_FCOE_FP(fp)) {
  6938. __set_bit(BNX2X_Q_FLG_HC, &init_params->rx.flags);
  6939. __set_bit(BNX2X_Q_FLG_HC, &init_params->tx.flags);
  6940. /* If HC is supported, enable host coalescing in the transition
  6941. * to INIT state.
  6942. */
  6943. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->rx.flags);
  6944. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->tx.flags);
  6945. /* HC rate */
  6946. init_params->rx.hc_rate = bp->rx_ticks ?
  6947. (1000000 / bp->rx_ticks) : 0;
  6948. init_params->tx.hc_rate = bp->tx_ticks ?
  6949. (1000000 / bp->tx_ticks) : 0;
  6950. /* FW SB ID */
  6951. init_params->rx.fw_sb_id = init_params->tx.fw_sb_id =
  6952. fp->fw_sb_id;
  6953. /*
  6954. * CQ index among the SB indices: FCoE clients uses the default
  6955. * SB, therefore it's different.
  6956. */
  6957. init_params->rx.sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  6958. init_params->tx.sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS;
  6959. }
  6960. /* set maximum number of COSs supported by this queue */
  6961. init_params->max_cos = fp->max_cos;
  6962. DP(NETIF_MSG_IFUP, "fp: %d setting queue params max cos to: %d\n",
  6963. fp->index, init_params->max_cos);
  6964. /* set the context pointers queue object */
  6965. for (cos = FIRST_TX_COS_INDEX; cos < init_params->max_cos; cos++) {
  6966. cxt_index = fp->txdata_ptr[cos]->cid / ILT_PAGE_CIDS;
  6967. cxt_offset = fp->txdata_ptr[cos]->cid - (cxt_index *
  6968. ILT_PAGE_CIDS);
  6969. init_params->cxts[cos] =
  6970. &bp->context[cxt_index].vcxt[cxt_offset].eth;
  6971. }
  6972. }
  6973. static int bnx2x_setup_tx_only(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  6974. struct bnx2x_queue_state_params *q_params,
  6975. struct bnx2x_queue_setup_tx_only_params *tx_only_params,
  6976. int tx_index, bool leading)
  6977. {
  6978. memset(tx_only_params, 0, sizeof(*tx_only_params));
  6979. /* Set the command */
  6980. q_params->cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  6981. /* Set tx-only QUEUE flags: don't zero statistics */
  6982. tx_only_params->flags = bnx2x_get_common_flags(bp, fp, false);
  6983. /* choose the index of the cid to send the slow path on */
  6984. tx_only_params->cid_index = tx_index;
  6985. /* Set general TX_ONLY_SETUP parameters */
  6986. bnx2x_pf_q_prep_general(bp, fp, &tx_only_params->gen_params, tx_index);
  6987. /* Set Tx TX_ONLY_SETUP parameters */
  6988. bnx2x_pf_tx_q_prep(bp, fp, &tx_only_params->txq_params, tx_index);
  6989. DP(NETIF_MSG_IFUP,
  6990. "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",
  6991. tx_index, q_params->q_obj->cids[FIRST_TX_COS_INDEX],
  6992. q_params->q_obj->cids[tx_index], q_params->q_obj->cl_id,
  6993. tx_only_params->gen_params.spcl_id, tx_only_params->flags);
  6994. /* send the ramrod */
  6995. return bnx2x_queue_state_change(bp, q_params);
  6996. }
  6997. /**
  6998. * bnx2x_setup_queue - setup queue
  6999. *
  7000. * @bp: driver handle
  7001. * @fp: pointer to fastpath
  7002. * @leading: is leading
  7003. *
  7004. * This function performs 2 steps in a Queue state machine
  7005. * actually: 1) RESET->INIT 2) INIT->SETUP
  7006. */
  7007. int bnx2x_setup_queue(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  7008. bool leading)
  7009. {
  7010. struct bnx2x_queue_state_params q_params = {NULL};
  7011. struct bnx2x_queue_setup_params *setup_params =
  7012. &q_params.params.setup;
  7013. struct bnx2x_queue_setup_tx_only_params *tx_only_params =
  7014. &q_params.params.tx_only;
  7015. int rc;
  7016. u8 tx_index;
  7017. DP(NETIF_MSG_IFUP, "setting up queue %d\n", fp->index);
  7018. /* reset IGU state skip FCoE L2 queue */
  7019. if (!IS_FCOE_FP(fp))
  7020. bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID, 0,
  7021. IGU_INT_ENABLE, 0);
  7022. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  7023. /* We want to wait for completion in this context */
  7024. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  7025. /* Prepare the INIT parameters */
  7026. bnx2x_pf_q_prep_init(bp, fp, &q_params.params.init);
  7027. /* Set the command */
  7028. q_params.cmd = BNX2X_Q_CMD_INIT;
  7029. /* Change the state to INIT */
  7030. rc = bnx2x_queue_state_change(bp, &q_params);
  7031. if (rc) {
  7032. BNX2X_ERR("Queue(%d) INIT failed\n", fp->index);
  7033. return rc;
  7034. }
  7035. DP(NETIF_MSG_IFUP, "init complete\n");
  7036. /* Now move the Queue to the SETUP state... */
  7037. memset(setup_params, 0, sizeof(*setup_params));
  7038. /* Set QUEUE flags */
  7039. setup_params->flags = bnx2x_get_q_flags(bp, fp, leading);
  7040. /* Set general SETUP parameters */
  7041. bnx2x_pf_q_prep_general(bp, fp, &setup_params->gen_params,
  7042. FIRST_TX_COS_INDEX);
  7043. bnx2x_pf_rx_q_prep(bp, fp, &setup_params->pause_params,
  7044. &setup_params->rxq_params);
  7045. bnx2x_pf_tx_q_prep(bp, fp, &setup_params->txq_params,
  7046. FIRST_TX_COS_INDEX);
  7047. /* Set the command */
  7048. q_params.cmd = BNX2X_Q_CMD_SETUP;
  7049. if (IS_FCOE_FP(fp))
  7050. bp->fcoe_init = true;
  7051. /* Change the state to SETUP */
  7052. rc = bnx2x_queue_state_change(bp, &q_params);
  7053. if (rc) {
  7054. BNX2X_ERR("Queue(%d) SETUP failed\n", fp->index);
  7055. return rc;
  7056. }
  7057. /* loop through the relevant tx-only indices */
  7058. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  7059. tx_index < fp->max_cos;
  7060. tx_index++) {
  7061. /* prepare and send tx-only ramrod*/
  7062. rc = bnx2x_setup_tx_only(bp, fp, &q_params,
  7063. tx_only_params, tx_index, leading);
  7064. if (rc) {
  7065. BNX2X_ERR("Queue(%d.%d) TX_ONLY_SETUP failed\n",
  7066. fp->index, tx_index);
  7067. return rc;
  7068. }
  7069. }
  7070. return rc;
  7071. }
  7072. static int bnx2x_stop_queue(struct bnx2x *bp, int index)
  7073. {
  7074. struct bnx2x_fastpath *fp = &bp->fp[index];
  7075. struct bnx2x_fp_txdata *txdata;
  7076. struct bnx2x_queue_state_params q_params = {NULL};
  7077. int rc, tx_index;
  7078. DP(NETIF_MSG_IFDOWN, "stopping queue %d cid %d\n", index, fp->cid);
  7079. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  7080. /* We want to wait for completion in this context */
  7081. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  7082. /* close tx-only connections */
  7083. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  7084. tx_index < fp->max_cos;
  7085. tx_index++){
  7086. /* ascertain this is a normal queue*/
  7087. txdata = fp->txdata_ptr[tx_index];
  7088. DP(NETIF_MSG_IFDOWN, "stopping tx-only queue %d\n",
  7089. txdata->txq_index);
  7090. /* send halt terminate on tx-only connection */
  7091. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  7092. memset(&q_params.params.terminate, 0,
  7093. sizeof(q_params.params.terminate));
  7094. q_params.params.terminate.cid_index = tx_index;
  7095. rc = bnx2x_queue_state_change(bp, &q_params);
  7096. if (rc)
  7097. return rc;
  7098. /* send halt terminate on tx-only connection */
  7099. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  7100. memset(&q_params.params.cfc_del, 0,
  7101. sizeof(q_params.params.cfc_del));
  7102. q_params.params.cfc_del.cid_index = tx_index;
  7103. rc = bnx2x_queue_state_change(bp, &q_params);
  7104. if (rc)
  7105. return rc;
  7106. }
  7107. /* Stop the primary connection: */
  7108. /* ...halt the connection */
  7109. q_params.cmd = BNX2X_Q_CMD_HALT;
  7110. rc = bnx2x_queue_state_change(bp, &q_params);
  7111. if (rc)
  7112. return rc;
  7113. /* ...terminate the connection */
  7114. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  7115. memset(&q_params.params.terminate, 0,
  7116. sizeof(q_params.params.terminate));
  7117. q_params.params.terminate.cid_index = FIRST_TX_COS_INDEX;
  7118. rc = bnx2x_queue_state_change(bp, &q_params);
  7119. if (rc)
  7120. return rc;
  7121. /* ...delete cfc entry */
  7122. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  7123. memset(&q_params.params.cfc_del, 0,
  7124. sizeof(q_params.params.cfc_del));
  7125. q_params.params.cfc_del.cid_index = FIRST_TX_COS_INDEX;
  7126. return bnx2x_queue_state_change(bp, &q_params);
  7127. }
  7128. static void bnx2x_reset_func(struct bnx2x *bp)
  7129. {
  7130. int port = BP_PORT(bp);
  7131. int func = BP_FUNC(bp);
  7132. int i;
  7133. /* Disable the function in the FW */
  7134. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0);
  7135. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0);
  7136. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0);
  7137. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0);
  7138. /* FP SBs */
  7139. for_each_eth_queue(bp, i) {
  7140. struct bnx2x_fastpath *fp = &bp->fp[i];
  7141. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  7142. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id),
  7143. SB_DISABLED);
  7144. }
  7145. if (CNIC_LOADED(bp))
  7146. /* CNIC SB */
  7147. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  7148. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET
  7149. (bnx2x_cnic_fw_sb_id(bp)), SB_DISABLED);
  7150. /* SP SB */
  7151. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  7152. CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func),
  7153. SB_DISABLED);
  7154. for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++)
  7155. REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func),
  7156. 0);
  7157. /* Configure IGU */
  7158. if (bp->common.int_block == INT_BLOCK_HC) {
  7159. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  7160. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  7161. } else {
  7162. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  7163. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  7164. }
  7165. if (CNIC_LOADED(bp)) {
  7166. /* Disable Timer scan */
  7167. REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 0);
  7168. /*
  7169. * Wait for at least 10ms and up to 2 second for the timers
  7170. * scan to complete
  7171. */
  7172. for (i = 0; i < 200; i++) {
  7173. usleep_range(10000, 20000);
  7174. if (!REG_RD(bp, TM_REG_LIN0_SCAN_ON + port*4))
  7175. break;
  7176. }
  7177. }
  7178. /* Clear ILT */
  7179. bnx2x_clear_func_ilt(bp, func);
  7180. /* Timers workaround bug for E2: if this is vnic-3,
  7181. * we need to set the entire ilt range for this timers.
  7182. */
  7183. if (!CHIP_IS_E1x(bp) && BP_VN(bp) == 3) {
  7184. struct ilt_client_info ilt_cli;
  7185. /* use dummy TM client */
  7186. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  7187. ilt_cli.start = 0;
  7188. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  7189. ilt_cli.client_num = ILT_CLIENT_TM;
  7190. bnx2x_ilt_boundry_init_op(bp, &ilt_cli, 0, INITOP_CLEAR);
  7191. }
  7192. /* this assumes that reset_port() called before reset_func()*/
  7193. if (!CHIP_IS_E1x(bp))
  7194. bnx2x_pf_disable(bp);
  7195. bp->dmae_ready = 0;
  7196. }
  7197. static void bnx2x_reset_port(struct bnx2x *bp)
  7198. {
  7199. int port = BP_PORT(bp);
  7200. u32 val;
  7201. /* Reset physical Link */
  7202. bnx2x__link_reset(bp);
  7203. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  7204. /* Do not rcv packets to BRB */
  7205. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0);
  7206. /* Do not direct rcv packets that are not for MCP to the BRB */
  7207. REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
  7208. NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
  7209. /* Configure AEU */
  7210. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0);
  7211. msleep(100);
  7212. /* Check for BRB port occupancy */
  7213. val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4);
  7214. if (val)
  7215. DP(NETIF_MSG_IFDOWN,
  7216. "BRB1 is not empty %d blocks are occupied\n", val);
  7217. /* TODO: Close Doorbell port? */
  7218. }
  7219. static int bnx2x_reset_hw(struct bnx2x *bp, u32 load_code)
  7220. {
  7221. struct bnx2x_func_state_params func_params = {NULL};
  7222. /* Prepare parameters for function state transitions */
  7223. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  7224. func_params.f_obj = &bp->func_obj;
  7225. func_params.cmd = BNX2X_F_CMD_HW_RESET;
  7226. func_params.params.hw_init.load_phase = load_code;
  7227. return bnx2x_func_state_change(bp, &func_params);
  7228. }
  7229. static int bnx2x_func_stop(struct bnx2x *bp)
  7230. {
  7231. struct bnx2x_func_state_params func_params = {NULL};
  7232. int rc;
  7233. /* Prepare parameters for function state transitions */
  7234. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  7235. func_params.f_obj = &bp->func_obj;
  7236. func_params.cmd = BNX2X_F_CMD_STOP;
  7237. /*
  7238. * Try to stop the function the 'good way'. If fails (in case
  7239. * of a parity error during bnx2x_chip_cleanup()) and we are
  7240. * not in a debug mode, perform a state transaction in order to
  7241. * enable further HW_RESET transaction.
  7242. */
  7243. rc = bnx2x_func_state_change(bp, &func_params);
  7244. if (rc) {
  7245. #ifdef BNX2X_STOP_ON_ERROR
  7246. return rc;
  7247. #else
  7248. BNX2X_ERR("FUNC_STOP ramrod failed. Running a dry transaction\n");
  7249. __set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags);
  7250. return bnx2x_func_state_change(bp, &func_params);
  7251. #endif
  7252. }
  7253. return 0;
  7254. }
  7255. /**
  7256. * bnx2x_send_unload_req - request unload mode from the MCP.
  7257. *
  7258. * @bp: driver handle
  7259. * @unload_mode: requested function's unload mode
  7260. *
  7261. * Return unload mode returned by the MCP: COMMON, PORT or FUNC.
  7262. */
  7263. u32 bnx2x_send_unload_req(struct bnx2x *bp, int unload_mode)
  7264. {
  7265. u32 reset_code = 0;
  7266. int port = BP_PORT(bp);
  7267. /* Select the UNLOAD request mode */
  7268. if (unload_mode == UNLOAD_NORMAL)
  7269. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  7270. else if (bp->flags & NO_WOL_FLAG)
  7271. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP;
  7272. else if (bp->wol) {
  7273. u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
  7274. u8 *mac_addr = bp->dev->dev_addr;
  7275. struct pci_dev *pdev = bp->pdev;
  7276. u32 val;
  7277. u16 pmc;
  7278. /* The mac address is written to entries 1-4 to
  7279. * preserve entry 0 which is used by the PMF
  7280. */
  7281. u8 entry = (BP_VN(bp) + 1)*8;
  7282. val = (mac_addr[0] << 8) | mac_addr[1];
  7283. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val);
  7284. val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
  7285. (mac_addr[4] << 8) | mac_addr[5];
  7286. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val);
  7287. /* Enable the PME and clear the status */
  7288. pci_read_config_word(pdev, pdev->pm_cap + PCI_PM_CTRL, &pmc);
  7289. pmc |= PCI_PM_CTRL_PME_ENABLE | PCI_PM_CTRL_PME_STATUS;
  7290. pci_write_config_word(pdev, pdev->pm_cap + PCI_PM_CTRL, pmc);
  7291. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN;
  7292. } else
  7293. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  7294. /* Send the request to the MCP */
  7295. if (!BP_NOMCP(bp))
  7296. reset_code = bnx2x_fw_command(bp, reset_code, 0);
  7297. else {
  7298. int path = BP_PATH(bp);
  7299. DP(NETIF_MSG_IFDOWN, "NO MCP - load counts[%d] %d, %d, %d\n",
  7300. path, load_count[path][0], load_count[path][1],
  7301. load_count[path][2]);
  7302. load_count[path][0]--;
  7303. load_count[path][1 + port]--;
  7304. DP(NETIF_MSG_IFDOWN, "NO MCP - new load counts[%d] %d, %d, %d\n",
  7305. path, load_count[path][0], load_count[path][1],
  7306. load_count[path][2]);
  7307. if (load_count[path][0] == 0)
  7308. reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON;
  7309. else if (load_count[path][1 + port] == 0)
  7310. reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT;
  7311. else
  7312. reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION;
  7313. }
  7314. return reset_code;
  7315. }
  7316. /**
  7317. * bnx2x_send_unload_done - send UNLOAD_DONE command to the MCP.
  7318. *
  7319. * @bp: driver handle
  7320. * @keep_link: true iff link should be kept up
  7321. */
  7322. void bnx2x_send_unload_done(struct bnx2x *bp, bool keep_link)
  7323. {
  7324. u32 reset_param = keep_link ? DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET : 0;
  7325. /* Report UNLOAD_DONE to MCP */
  7326. if (!BP_NOMCP(bp))
  7327. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, reset_param);
  7328. }
  7329. static int bnx2x_func_wait_started(struct bnx2x *bp)
  7330. {
  7331. int tout = 50;
  7332. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  7333. if (!bp->port.pmf)
  7334. return 0;
  7335. /*
  7336. * (assumption: No Attention from MCP at this stage)
  7337. * PMF probably in the middle of TX disable/enable transaction
  7338. * 1. Sync IRS for default SB
  7339. * 2. Sync SP queue - this guarantees us that attention handling started
  7340. * 3. Wait, that TX disable/enable transaction completes
  7341. *
  7342. * 1+2 guarantee that if DCBx attention was scheduled it already changed
  7343. * pending bit of transaction from STARTED-->TX_STOPPED, if we already
  7344. * received completion for the transaction the state is TX_STOPPED.
  7345. * State will return to STARTED after completion of TX_STOPPED-->STARTED
  7346. * transaction.
  7347. */
  7348. /* make sure default SB ISR is done */
  7349. if (msix)
  7350. synchronize_irq(bp->msix_table[0].vector);
  7351. else
  7352. synchronize_irq(bp->pdev->irq);
  7353. flush_workqueue(bnx2x_wq);
  7354. while (bnx2x_func_get_state(bp, &bp->func_obj) !=
  7355. BNX2X_F_STATE_STARTED && tout--)
  7356. msleep(20);
  7357. if (bnx2x_func_get_state(bp, &bp->func_obj) !=
  7358. BNX2X_F_STATE_STARTED) {
  7359. #ifdef BNX2X_STOP_ON_ERROR
  7360. BNX2X_ERR("Wrong function state\n");
  7361. return -EBUSY;
  7362. #else
  7363. /*
  7364. * Failed to complete the transaction in a "good way"
  7365. * Force both transactions with CLR bit
  7366. */
  7367. struct bnx2x_func_state_params func_params = {NULL};
  7368. DP(NETIF_MSG_IFDOWN,
  7369. "Hmmm... Unexpected function state! Forcing STARTED-->TX_ST0PPED-->STARTED\n");
  7370. func_params.f_obj = &bp->func_obj;
  7371. __set_bit(RAMROD_DRV_CLR_ONLY,
  7372. &func_params.ramrod_flags);
  7373. /* STARTED-->TX_ST0PPED */
  7374. func_params.cmd = BNX2X_F_CMD_TX_STOP;
  7375. bnx2x_func_state_change(bp, &func_params);
  7376. /* TX_ST0PPED-->STARTED */
  7377. func_params.cmd = BNX2X_F_CMD_TX_START;
  7378. return bnx2x_func_state_change(bp, &func_params);
  7379. #endif
  7380. }
  7381. return 0;
  7382. }
  7383. void bnx2x_chip_cleanup(struct bnx2x *bp, int unload_mode, bool keep_link)
  7384. {
  7385. int port = BP_PORT(bp);
  7386. int i, rc = 0;
  7387. u8 cos;
  7388. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  7389. u32 reset_code;
  7390. /* Wait until tx fastpath tasks complete */
  7391. for_each_tx_queue(bp, i) {
  7392. struct bnx2x_fastpath *fp = &bp->fp[i];
  7393. for_each_cos_in_tx_queue(fp, cos)
  7394. rc = bnx2x_clean_tx_queue(bp, fp->txdata_ptr[cos]);
  7395. #ifdef BNX2X_STOP_ON_ERROR
  7396. if (rc)
  7397. return;
  7398. #endif
  7399. }
  7400. /* Give HW time to discard old tx messages */
  7401. usleep_range(1000, 2000);
  7402. /* Clean all ETH MACs */
  7403. rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_ETH_MAC,
  7404. false);
  7405. if (rc < 0)
  7406. BNX2X_ERR("Failed to delete all ETH macs: %d\n", rc);
  7407. /* Clean up UC list */
  7408. rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_UC_LIST_MAC,
  7409. true);
  7410. if (rc < 0)
  7411. BNX2X_ERR("Failed to schedule DEL commands for UC MACs list: %d\n",
  7412. rc);
  7413. /* Disable LLH */
  7414. if (!CHIP_IS_E1(bp))
  7415. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  7416. /* Set "drop all" (stop Rx).
  7417. * We need to take a netif_addr_lock() here in order to prevent
  7418. * a race between the completion code and this code.
  7419. */
  7420. netif_addr_lock_bh(bp->dev);
  7421. /* Schedule the rx_mode command */
  7422. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  7423. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  7424. else
  7425. bnx2x_set_storm_rx_mode(bp);
  7426. /* Cleanup multicast configuration */
  7427. rparam.mcast_obj = &bp->mcast_obj;
  7428. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  7429. if (rc < 0)
  7430. BNX2X_ERR("Failed to send DEL multicast command: %d\n", rc);
  7431. netif_addr_unlock_bh(bp->dev);
  7432. bnx2x_iov_chip_cleanup(bp);
  7433. /*
  7434. * Send the UNLOAD_REQUEST to the MCP. This will return if
  7435. * this function should perform FUNC, PORT or COMMON HW
  7436. * reset.
  7437. */
  7438. reset_code = bnx2x_send_unload_req(bp, unload_mode);
  7439. /*
  7440. * (assumption: No Attention from MCP at this stage)
  7441. * PMF probably in the middle of TX disable/enable transaction
  7442. */
  7443. rc = bnx2x_func_wait_started(bp);
  7444. if (rc) {
  7445. BNX2X_ERR("bnx2x_func_wait_started failed\n");
  7446. #ifdef BNX2X_STOP_ON_ERROR
  7447. return;
  7448. #endif
  7449. }
  7450. /* Close multi and leading connections
  7451. * Completions for ramrods are collected in a synchronous way
  7452. */
  7453. for_each_eth_queue(bp, i)
  7454. if (bnx2x_stop_queue(bp, i))
  7455. #ifdef BNX2X_STOP_ON_ERROR
  7456. return;
  7457. #else
  7458. goto unload_error;
  7459. #endif
  7460. if (CNIC_LOADED(bp)) {
  7461. for_each_cnic_queue(bp, i)
  7462. if (bnx2x_stop_queue(bp, i))
  7463. #ifdef BNX2X_STOP_ON_ERROR
  7464. return;
  7465. #else
  7466. goto unload_error;
  7467. #endif
  7468. }
  7469. /* If SP settings didn't get completed so far - something
  7470. * very wrong has happen.
  7471. */
  7472. if (!bnx2x_wait_sp_comp(bp, ~0x0UL))
  7473. BNX2X_ERR("Hmmm... Common slow path ramrods got stuck!\n");
  7474. #ifndef BNX2X_STOP_ON_ERROR
  7475. unload_error:
  7476. #endif
  7477. rc = bnx2x_func_stop(bp);
  7478. if (rc) {
  7479. BNX2X_ERR("Function stop failed!\n");
  7480. #ifdef BNX2X_STOP_ON_ERROR
  7481. return;
  7482. #endif
  7483. }
  7484. /* Disable HW interrupts, NAPI */
  7485. bnx2x_netif_stop(bp, 1);
  7486. /* Delete all NAPI objects */
  7487. bnx2x_del_all_napi(bp);
  7488. if (CNIC_LOADED(bp))
  7489. bnx2x_del_all_napi_cnic(bp);
  7490. /* Release IRQs */
  7491. bnx2x_free_irq(bp);
  7492. /* Reset the chip */
  7493. rc = bnx2x_reset_hw(bp, reset_code);
  7494. if (rc)
  7495. BNX2X_ERR("HW_RESET failed\n");
  7496. /* Report UNLOAD_DONE to MCP */
  7497. bnx2x_send_unload_done(bp, keep_link);
  7498. }
  7499. void bnx2x_disable_close_the_gate(struct bnx2x *bp)
  7500. {
  7501. u32 val;
  7502. DP(NETIF_MSG_IFDOWN, "Disabling \"close the gates\"\n");
  7503. if (CHIP_IS_E1(bp)) {
  7504. int port = BP_PORT(bp);
  7505. u32 addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  7506. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  7507. val = REG_RD(bp, addr);
  7508. val &= ~(0x300);
  7509. REG_WR(bp, addr, val);
  7510. } else {
  7511. val = REG_RD(bp, MISC_REG_AEU_GENERAL_MASK);
  7512. val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK |
  7513. MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK);
  7514. REG_WR(bp, MISC_REG_AEU_GENERAL_MASK, val);
  7515. }
  7516. }
  7517. /* Close gates #2, #3 and #4: */
  7518. static void bnx2x_set_234_gates(struct bnx2x *bp, bool close)
  7519. {
  7520. u32 val;
  7521. /* Gates #2 and #4a are closed/opened for "not E1" only */
  7522. if (!CHIP_IS_E1(bp)) {
  7523. /* #4 */
  7524. REG_WR(bp, PXP_REG_HST_DISCARD_DOORBELLS, !!close);
  7525. /* #2 */
  7526. REG_WR(bp, PXP_REG_HST_DISCARD_INTERNAL_WRITES, !!close);
  7527. }
  7528. /* #3 */
  7529. if (CHIP_IS_E1x(bp)) {
  7530. /* Prevent interrupts from HC on both ports */
  7531. val = REG_RD(bp, HC_REG_CONFIG_1);
  7532. REG_WR(bp, HC_REG_CONFIG_1,
  7533. (!close) ? (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1) :
  7534. (val & ~(u32)HC_CONFIG_1_REG_BLOCK_DISABLE_1));
  7535. val = REG_RD(bp, HC_REG_CONFIG_0);
  7536. REG_WR(bp, HC_REG_CONFIG_0,
  7537. (!close) ? (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0) :
  7538. (val & ~(u32)HC_CONFIG_0_REG_BLOCK_DISABLE_0));
  7539. } else {
  7540. /* Prevent incoming interrupts in IGU */
  7541. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  7542. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION,
  7543. (!close) ?
  7544. (val | IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE) :
  7545. (val & ~(u32)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE));
  7546. }
  7547. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "%s gates #2, #3 and #4\n",
  7548. close ? "closing" : "opening");
  7549. mmiowb();
  7550. }
  7551. #define SHARED_MF_CLP_MAGIC 0x80000000 /* `magic' bit */
  7552. static void bnx2x_clp_reset_prep(struct bnx2x *bp, u32 *magic_val)
  7553. {
  7554. /* Do some magic... */
  7555. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  7556. *magic_val = val & SHARED_MF_CLP_MAGIC;
  7557. MF_CFG_WR(bp, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC);
  7558. }
  7559. /**
  7560. * bnx2x_clp_reset_done - restore the value of the `magic' bit.
  7561. *
  7562. * @bp: driver handle
  7563. * @magic_val: old value of the `magic' bit.
  7564. */
  7565. static void bnx2x_clp_reset_done(struct bnx2x *bp, u32 magic_val)
  7566. {
  7567. /* Restore the `magic' bit value... */
  7568. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  7569. MF_CFG_WR(bp, shared_mf_config.clp_mb,
  7570. (val & (~SHARED_MF_CLP_MAGIC)) | magic_val);
  7571. }
  7572. /**
  7573. * bnx2x_reset_mcp_prep - prepare for MCP reset.
  7574. *
  7575. * @bp: driver handle
  7576. * @magic_val: old value of 'magic' bit.
  7577. *
  7578. * Takes care of CLP configurations.
  7579. */
  7580. static void bnx2x_reset_mcp_prep(struct bnx2x *bp, u32 *magic_val)
  7581. {
  7582. u32 shmem;
  7583. u32 validity_offset;
  7584. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "Starting\n");
  7585. /* Set `magic' bit in order to save MF config */
  7586. if (!CHIP_IS_E1(bp))
  7587. bnx2x_clp_reset_prep(bp, magic_val);
  7588. /* Get shmem offset */
  7589. shmem = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  7590. validity_offset =
  7591. offsetof(struct shmem_region, validity_map[BP_PORT(bp)]);
  7592. /* Clear validity map flags */
  7593. if (shmem > 0)
  7594. REG_WR(bp, shmem + validity_offset, 0);
  7595. }
  7596. #define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */
  7597. #define MCP_ONE_TIMEOUT 100 /* 100 ms */
  7598. /**
  7599. * bnx2x_mcp_wait_one - wait for MCP_ONE_TIMEOUT
  7600. *
  7601. * @bp: driver handle
  7602. */
  7603. static void bnx2x_mcp_wait_one(struct bnx2x *bp)
  7604. {
  7605. /* special handling for emulation and FPGA,
  7606. wait 10 times longer */
  7607. if (CHIP_REV_IS_SLOW(bp))
  7608. msleep(MCP_ONE_TIMEOUT*10);
  7609. else
  7610. msleep(MCP_ONE_TIMEOUT);
  7611. }
  7612. /*
  7613. * initializes bp->common.shmem_base and waits for validity signature to appear
  7614. */
  7615. static int bnx2x_init_shmem(struct bnx2x *bp)
  7616. {
  7617. int cnt = 0;
  7618. u32 val = 0;
  7619. do {
  7620. bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  7621. if (bp->common.shmem_base) {
  7622. val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
  7623. if (val & SHR_MEM_VALIDITY_MB)
  7624. return 0;
  7625. }
  7626. bnx2x_mcp_wait_one(bp);
  7627. } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT));
  7628. BNX2X_ERR("BAD MCP validity signature\n");
  7629. return -ENODEV;
  7630. }
  7631. static int bnx2x_reset_mcp_comp(struct bnx2x *bp, u32 magic_val)
  7632. {
  7633. int rc = bnx2x_init_shmem(bp);
  7634. /* Restore the `magic' bit value */
  7635. if (!CHIP_IS_E1(bp))
  7636. bnx2x_clp_reset_done(bp, magic_val);
  7637. return rc;
  7638. }
  7639. static void bnx2x_pxp_prep(struct bnx2x *bp)
  7640. {
  7641. if (!CHIP_IS_E1(bp)) {
  7642. REG_WR(bp, PXP2_REG_RD_START_INIT, 0);
  7643. REG_WR(bp, PXP2_REG_RQ_RBC_DONE, 0);
  7644. mmiowb();
  7645. }
  7646. }
  7647. /*
  7648. * Reset the whole chip except for:
  7649. * - PCIE core
  7650. * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by
  7651. * one reset bit)
  7652. * - IGU
  7653. * - MISC (including AEU)
  7654. * - GRC
  7655. * - RBCN, RBCP
  7656. */
  7657. static void bnx2x_process_kill_chip_reset(struct bnx2x *bp, bool global)
  7658. {
  7659. u32 not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2;
  7660. u32 global_bits2, stay_reset2;
  7661. /*
  7662. * Bits that have to be set in reset_mask2 if we want to reset 'global'
  7663. * (per chip) blocks.
  7664. */
  7665. global_bits2 =
  7666. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU |
  7667. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE;
  7668. /* Don't reset the following blocks.
  7669. * Important: per port blocks (such as EMAC, BMAC, UMAC) can't be
  7670. * reset, as in 4 port device they might still be owned
  7671. * by the MCP (there is only one leader per path).
  7672. */
  7673. not_reset_mask1 =
  7674. MISC_REGISTERS_RESET_REG_1_RST_HC |
  7675. MISC_REGISTERS_RESET_REG_1_RST_PXPV |
  7676. MISC_REGISTERS_RESET_REG_1_RST_PXP;
  7677. not_reset_mask2 =
  7678. MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO |
  7679. MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE |
  7680. MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE |
  7681. MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE |
  7682. MISC_REGISTERS_RESET_REG_2_RST_RBCN |
  7683. MISC_REGISTERS_RESET_REG_2_RST_GRC |
  7684. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE |
  7685. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B |
  7686. MISC_REGISTERS_RESET_REG_2_RST_ATC |
  7687. MISC_REGISTERS_RESET_REG_2_PGLC |
  7688. MISC_REGISTERS_RESET_REG_2_RST_BMAC0 |
  7689. MISC_REGISTERS_RESET_REG_2_RST_BMAC1 |
  7690. MISC_REGISTERS_RESET_REG_2_RST_EMAC0 |
  7691. MISC_REGISTERS_RESET_REG_2_RST_EMAC1 |
  7692. MISC_REGISTERS_RESET_REG_2_UMAC0 |
  7693. MISC_REGISTERS_RESET_REG_2_UMAC1;
  7694. /*
  7695. * Keep the following blocks in reset:
  7696. * - all xxMACs are handled by the bnx2x_link code.
  7697. */
  7698. stay_reset2 =
  7699. MISC_REGISTERS_RESET_REG_2_XMAC |
  7700. MISC_REGISTERS_RESET_REG_2_XMAC_SOFT;
  7701. /* Full reset masks according to the chip */
  7702. reset_mask1 = 0xffffffff;
  7703. if (CHIP_IS_E1(bp))
  7704. reset_mask2 = 0xffff;
  7705. else if (CHIP_IS_E1H(bp))
  7706. reset_mask2 = 0x1ffff;
  7707. else if (CHIP_IS_E2(bp))
  7708. reset_mask2 = 0xfffff;
  7709. else /* CHIP_IS_E3 */
  7710. reset_mask2 = 0x3ffffff;
  7711. /* Don't reset global blocks unless we need to */
  7712. if (!global)
  7713. reset_mask2 &= ~global_bits2;
  7714. /*
  7715. * In case of attention in the QM, we need to reset PXP
  7716. * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM
  7717. * because otherwise QM reset would release 'close the gates' shortly
  7718. * before resetting the PXP, then the PSWRQ would send a write
  7719. * request to PGLUE. Then when PXP is reset, PGLUE would try to
  7720. * read the payload data from PSWWR, but PSWWR would not
  7721. * respond. The write queue in PGLUE would stuck, dmae commands
  7722. * would not return. Therefore it's important to reset the second
  7723. * reset register (containing the
  7724. * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the
  7725. * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM
  7726. * bit).
  7727. */
  7728. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
  7729. reset_mask2 & (~not_reset_mask2));
  7730. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  7731. reset_mask1 & (~not_reset_mask1));
  7732. barrier();
  7733. mmiowb();
  7734. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
  7735. reset_mask2 & (~stay_reset2));
  7736. barrier();
  7737. mmiowb();
  7738. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1);
  7739. mmiowb();
  7740. }
  7741. /**
  7742. * bnx2x_er_poll_igu_vq - poll for pending writes bit.
  7743. * It should get cleared in no more than 1s.
  7744. *
  7745. * @bp: driver handle
  7746. *
  7747. * It should get cleared in no more than 1s. Returns 0 if
  7748. * pending writes bit gets cleared.
  7749. */
  7750. static int bnx2x_er_poll_igu_vq(struct bnx2x *bp)
  7751. {
  7752. u32 cnt = 1000;
  7753. u32 pend_bits = 0;
  7754. do {
  7755. pend_bits = REG_RD(bp, IGU_REG_PENDING_BITS_STATUS);
  7756. if (pend_bits == 0)
  7757. break;
  7758. usleep_range(1000, 2000);
  7759. } while (cnt-- > 0);
  7760. if (cnt <= 0) {
  7761. BNX2X_ERR("Still pending IGU requests pend_bits=%x!\n",
  7762. pend_bits);
  7763. return -EBUSY;
  7764. }
  7765. return 0;
  7766. }
  7767. static int bnx2x_process_kill(struct bnx2x *bp, bool global)
  7768. {
  7769. int cnt = 1000;
  7770. u32 val = 0;
  7771. u32 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2;
  7772. u32 tags_63_32 = 0;
  7773. /* Empty the Tetris buffer, wait for 1s */
  7774. do {
  7775. sr_cnt = REG_RD(bp, PXP2_REG_RD_SR_CNT);
  7776. blk_cnt = REG_RD(bp, PXP2_REG_RD_BLK_CNT);
  7777. port_is_idle_0 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_0);
  7778. port_is_idle_1 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_1);
  7779. pgl_exp_rom2 = REG_RD(bp, PXP2_REG_PGL_EXP_ROM2);
  7780. if (CHIP_IS_E3(bp))
  7781. tags_63_32 = REG_RD(bp, PGLUE_B_REG_TAGS_63_32);
  7782. if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) &&
  7783. ((port_is_idle_0 & 0x1) == 0x1) &&
  7784. ((port_is_idle_1 & 0x1) == 0x1) &&
  7785. (pgl_exp_rom2 == 0xffffffff) &&
  7786. (!CHIP_IS_E3(bp) || (tags_63_32 == 0xffffffff)))
  7787. break;
  7788. usleep_range(1000, 2000);
  7789. } while (cnt-- > 0);
  7790. if (cnt <= 0) {
  7791. BNX2X_ERR("Tetris buffer didn't get empty or there are still outstanding read requests after 1s!\n");
  7792. 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",
  7793. sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1,
  7794. pgl_exp_rom2);
  7795. return -EAGAIN;
  7796. }
  7797. barrier();
  7798. /* Close gates #2, #3 and #4 */
  7799. bnx2x_set_234_gates(bp, true);
  7800. /* Poll for IGU VQs for 57712 and newer chips */
  7801. if (!CHIP_IS_E1x(bp) && bnx2x_er_poll_igu_vq(bp))
  7802. return -EAGAIN;
  7803. /* TBD: Indicate that "process kill" is in progress to MCP */
  7804. /* Clear "unprepared" bit */
  7805. REG_WR(bp, MISC_REG_UNPREPARED, 0);
  7806. barrier();
  7807. /* Make sure all is written to the chip before the reset */
  7808. mmiowb();
  7809. /* Wait for 1ms to empty GLUE and PCI-E core queues,
  7810. * PSWHST, GRC and PSWRD Tetris buffer.
  7811. */
  7812. usleep_range(1000, 2000);
  7813. /* Prepare to chip reset: */
  7814. /* MCP */
  7815. if (global)
  7816. bnx2x_reset_mcp_prep(bp, &val);
  7817. /* PXP */
  7818. bnx2x_pxp_prep(bp);
  7819. barrier();
  7820. /* reset the chip */
  7821. bnx2x_process_kill_chip_reset(bp, global);
  7822. barrier();
  7823. /* Recover after reset: */
  7824. /* MCP */
  7825. if (global && bnx2x_reset_mcp_comp(bp, val))
  7826. return -EAGAIN;
  7827. /* TBD: Add resetting the NO_MCP mode DB here */
  7828. /* Open the gates #2, #3 and #4 */
  7829. bnx2x_set_234_gates(bp, false);
  7830. /* TBD: IGU/AEU preparation bring back the AEU/IGU to a
  7831. * reset state, re-enable attentions. */
  7832. return 0;
  7833. }
  7834. static int bnx2x_leader_reset(struct bnx2x *bp)
  7835. {
  7836. int rc = 0;
  7837. bool global = bnx2x_reset_is_global(bp);
  7838. u32 load_code;
  7839. /* if not going to reset MCP - load "fake" driver to reset HW while
  7840. * driver is owner of the HW
  7841. */
  7842. if (!global && !BP_NOMCP(bp)) {
  7843. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_REQ,
  7844. DRV_MSG_CODE_LOAD_REQ_WITH_LFA);
  7845. if (!load_code) {
  7846. BNX2X_ERR("MCP response failure, aborting\n");
  7847. rc = -EAGAIN;
  7848. goto exit_leader_reset;
  7849. }
  7850. if ((load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) &&
  7851. (load_code != FW_MSG_CODE_DRV_LOAD_COMMON)) {
  7852. BNX2X_ERR("MCP unexpected resp, aborting\n");
  7853. rc = -EAGAIN;
  7854. goto exit_leader_reset2;
  7855. }
  7856. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE, 0);
  7857. if (!load_code) {
  7858. BNX2X_ERR("MCP response failure, aborting\n");
  7859. rc = -EAGAIN;
  7860. goto exit_leader_reset2;
  7861. }
  7862. }
  7863. /* Try to recover after the failure */
  7864. if (bnx2x_process_kill(bp, global)) {
  7865. BNX2X_ERR("Something bad had happen on engine %d! Aii!\n",
  7866. BP_PATH(bp));
  7867. rc = -EAGAIN;
  7868. goto exit_leader_reset2;
  7869. }
  7870. /*
  7871. * Clear RESET_IN_PROGRES and RESET_GLOBAL bits and update the driver
  7872. * state.
  7873. */
  7874. bnx2x_set_reset_done(bp);
  7875. if (global)
  7876. bnx2x_clear_reset_global(bp);
  7877. exit_leader_reset2:
  7878. /* unload "fake driver" if it was loaded */
  7879. if (!global && !BP_NOMCP(bp)) {
  7880. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0);
  7881. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
  7882. }
  7883. exit_leader_reset:
  7884. bp->is_leader = 0;
  7885. bnx2x_release_leader_lock(bp);
  7886. smp_mb();
  7887. return rc;
  7888. }
  7889. static void bnx2x_recovery_failed(struct bnx2x *bp)
  7890. {
  7891. netdev_err(bp->dev, "Recovery has failed. Power cycle is needed.\n");
  7892. /* Disconnect this device */
  7893. netif_device_detach(bp->dev);
  7894. /*
  7895. * Block ifup for all function on this engine until "process kill"
  7896. * or power cycle.
  7897. */
  7898. bnx2x_set_reset_in_progress(bp);
  7899. /* Shut down the power */
  7900. bnx2x_set_power_state(bp, PCI_D3hot);
  7901. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  7902. smp_mb();
  7903. }
  7904. /*
  7905. * Assumption: runs under rtnl lock. This together with the fact
  7906. * that it's called only from bnx2x_sp_rtnl() ensure that it
  7907. * will never be called when netif_running(bp->dev) is false.
  7908. */
  7909. static void bnx2x_parity_recover(struct bnx2x *bp)
  7910. {
  7911. bool global = false;
  7912. u32 error_recovered, error_unrecovered;
  7913. bool is_parity;
  7914. DP(NETIF_MSG_HW, "Handling parity\n");
  7915. while (1) {
  7916. switch (bp->recovery_state) {
  7917. case BNX2X_RECOVERY_INIT:
  7918. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_INIT\n");
  7919. is_parity = bnx2x_chk_parity_attn(bp, &global, false);
  7920. WARN_ON(!is_parity);
  7921. /* Try to get a LEADER_LOCK HW lock */
  7922. if (bnx2x_trylock_leader_lock(bp)) {
  7923. bnx2x_set_reset_in_progress(bp);
  7924. /*
  7925. * Check if there is a global attention and if
  7926. * there was a global attention, set the global
  7927. * reset bit.
  7928. */
  7929. if (global)
  7930. bnx2x_set_reset_global(bp);
  7931. bp->is_leader = 1;
  7932. }
  7933. /* Stop the driver */
  7934. /* If interface has been removed - break */
  7935. if (bnx2x_nic_unload(bp, UNLOAD_RECOVERY, false))
  7936. return;
  7937. bp->recovery_state = BNX2X_RECOVERY_WAIT;
  7938. /* Ensure "is_leader", MCP command sequence and
  7939. * "recovery_state" update values are seen on other
  7940. * CPUs.
  7941. */
  7942. smp_mb();
  7943. break;
  7944. case BNX2X_RECOVERY_WAIT:
  7945. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_WAIT\n");
  7946. if (bp->is_leader) {
  7947. int other_engine = BP_PATH(bp) ? 0 : 1;
  7948. bool other_load_status =
  7949. bnx2x_get_load_status(bp, other_engine);
  7950. bool load_status =
  7951. bnx2x_get_load_status(bp, BP_PATH(bp));
  7952. global = bnx2x_reset_is_global(bp);
  7953. /*
  7954. * In case of a parity in a global block, let
  7955. * the first leader that performs a
  7956. * leader_reset() reset the global blocks in
  7957. * order to clear global attentions. Otherwise
  7958. * the gates will remain closed for that
  7959. * engine.
  7960. */
  7961. if (load_status ||
  7962. (global && other_load_status)) {
  7963. /* Wait until all other functions get
  7964. * down.
  7965. */
  7966. schedule_delayed_work(&bp->sp_rtnl_task,
  7967. HZ/10);
  7968. return;
  7969. } else {
  7970. /* If all other functions got down -
  7971. * try to bring the chip back to
  7972. * normal. In any case it's an exit
  7973. * point for a leader.
  7974. */
  7975. if (bnx2x_leader_reset(bp)) {
  7976. bnx2x_recovery_failed(bp);
  7977. return;
  7978. }
  7979. /* If we are here, means that the
  7980. * leader has succeeded and doesn't
  7981. * want to be a leader any more. Try
  7982. * to continue as a none-leader.
  7983. */
  7984. break;
  7985. }
  7986. } else { /* non-leader */
  7987. if (!bnx2x_reset_is_done(bp, BP_PATH(bp))) {
  7988. /* Try to get a LEADER_LOCK HW lock as
  7989. * long as a former leader may have
  7990. * been unloaded by the user or
  7991. * released a leadership by another
  7992. * reason.
  7993. */
  7994. if (bnx2x_trylock_leader_lock(bp)) {
  7995. /* I'm a leader now! Restart a
  7996. * switch case.
  7997. */
  7998. bp->is_leader = 1;
  7999. break;
  8000. }
  8001. schedule_delayed_work(&bp->sp_rtnl_task,
  8002. HZ/10);
  8003. return;
  8004. } else {
  8005. /*
  8006. * If there was a global attention, wait
  8007. * for it to be cleared.
  8008. */
  8009. if (bnx2x_reset_is_global(bp)) {
  8010. schedule_delayed_work(
  8011. &bp->sp_rtnl_task,
  8012. HZ/10);
  8013. return;
  8014. }
  8015. error_recovered =
  8016. bp->eth_stats.recoverable_error;
  8017. error_unrecovered =
  8018. bp->eth_stats.unrecoverable_error;
  8019. bp->recovery_state =
  8020. BNX2X_RECOVERY_NIC_LOADING;
  8021. if (bnx2x_nic_load(bp, LOAD_NORMAL)) {
  8022. error_unrecovered++;
  8023. netdev_err(bp->dev,
  8024. "Recovery failed. Power cycle needed\n");
  8025. /* Disconnect this device */
  8026. netif_device_detach(bp->dev);
  8027. /* Shut down the power */
  8028. bnx2x_set_power_state(
  8029. bp, PCI_D3hot);
  8030. smp_mb();
  8031. } else {
  8032. bp->recovery_state =
  8033. BNX2X_RECOVERY_DONE;
  8034. error_recovered++;
  8035. smp_mb();
  8036. }
  8037. bp->eth_stats.recoverable_error =
  8038. error_recovered;
  8039. bp->eth_stats.unrecoverable_error =
  8040. error_unrecovered;
  8041. return;
  8042. }
  8043. }
  8044. default:
  8045. return;
  8046. }
  8047. }
  8048. }
  8049. static int bnx2x_close(struct net_device *dev);
  8050. /* bnx2x_nic_unload() flushes the bnx2x_wq, thus reset task is
  8051. * scheduled on a general queue in order to prevent a dead lock.
  8052. */
  8053. static void bnx2x_sp_rtnl_task(struct work_struct *work)
  8054. {
  8055. struct bnx2x *bp = container_of(work, struct bnx2x, sp_rtnl_task.work);
  8056. rtnl_lock();
  8057. if (!netif_running(bp->dev)) {
  8058. rtnl_unlock();
  8059. return;
  8060. }
  8061. if (unlikely(bp->recovery_state != BNX2X_RECOVERY_DONE)) {
  8062. #ifdef BNX2X_STOP_ON_ERROR
  8063. BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
  8064. "you will need to reboot when done\n");
  8065. goto sp_rtnl_not_reset;
  8066. #endif
  8067. /*
  8068. * Clear all pending SP commands as we are going to reset the
  8069. * function anyway.
  8070. */
  8071. bp->sp_rtnl_state = 0;
  8072. smp_mb();
  8073. bnx2x_parity_recover(bp);
  8074. rtnl_unlock();
  8075. return;
  8076. }
  8077. if (test_and_clear_bit(BNX2X_SP_RTNL_TX_TIMEOUT, &bp->sp_rtnl_state)) {
  8078. #ifdef BNX2X_STOP_ON_ERROR
  8079. BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
  8080. "you will need to reboot when done\n");
  8081. goto sp_rtnl_not_reset;
  8082. #endif
  8083. /*
  8084. * Clear all pending SP commands as we are going to reset the
  8085. * function anyway.
  8086. */
  8087. bp->sp_rtnl_state = 0;
  8088. smp_mb();
  8089. bnx2x_nic_unload(bp, UNLOAD_NORMAL, true);
  8090. bnx2x_nic_load(bp, LOAD_NORMAL);
  8091. rtnl_unlock();
  8092. return;
  8093. }
  8094. #ifdef BNX2X_STOP_ON_ERROR
  8095. sp_rtnl_not_reset:
  8096. #endif
  8097. if (test_and_clear_bit(BNX2X_SP_RTNL_SETUP_TC, &bp->sp_rtnl_state))
  8098. bnx2x_setup_tc(bp->dev, bp->dcbx_port_params.ets.num_of_cos);
  8099. if (test_and_clear_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE, &bp->sp_rtnl_state))
  8100. bnx2x_after_function_update(bp);
  8101. /*
  8102. * in case of fan failure we need to reset id if the "stop on error"
  8103. * debug flag is set, since we trying to prevent permanent overheating
  8104. * damage
  8105. */
  8106. if (test_and_clear_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state)) {
  8107. DP(NETIF_MSG_HW, "fan failure detected. Unloading driver\n");
  8108. netif_device_detach(bp->dev);
  8109. bnx2x_close(bp->dev);
  8110. rtnl_unlock();
  8111. return;
  8112. }
  8113. if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_MCAST, &bp->sp_rtnl_state)) {
  8114. DP(BNX2X_MSG_SP,
  8115. "sending set mcast vf pf channel message from rtnl sp-task\n");
  8116. bnx2x_vfpf_set_mcast(bp->dev);
  8117. }
  8118. if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_CHANNEL_DOWN,
  8119. &bp->sp_rtnl_state)){
  8120. if (!test_bit(__LINK_STATE_NOCARRIER, &bp->dev->state)) {
  8121. bnx2x_tx_disable(bp);
  8122. BNX2X_ERR("PF indicated channel is not servicable anymore. This means this VF device is no longer operational\n");
  8123. }
  8124. }
  8125. if (test_and_clear_bit(BNX2X_SP_RTNL_RX_MODE, &bp->sp_rtnl_state)) {
  8126. DP(BNX2X_MSG_SP, "Handling Rx Mode setting\n");
  8127. bnx2x_set_rx_mode_inner(bp);
  8128. }
  8129. if (test_and_clear_bit(BNX2X_SP_RTNL_HYPERVISOR_VLAN,
  8130. &bp->sp_rtnl_state))
  8131. bnx2x_pf_set_vfs_vlan(bp);
  8132. if (test_and_clear_bit(BNX2X_SP_RTNL_TX_STOP, &bp->sp_rtnl_state))
  8133. bnx2x_dcbx_stop_hw_tx(bp);
  8134. if (test_and_clear_bit(BNX2X_SP_RTNL_TX_RESUME, &bp->sp_rtnl_state))
  8135. bnx2x_dcbx_resume_hw_tx(bp);
  8136. /* work which needs rtnl lock not-taken (as it takes the lock itself and
  8137. * can be called from other contexts as well)
  8138. */
  8139. rtnl_unlock();
  8140. /* enable SR-IOV if applicable */
  8141. if (IS_SRIOV(bp) && test_and_clear_bit(BNX2X_SP_RTNL_ENABLE_SRIOV,
  8142. &bp->sp_rtnl_state)) {
  8143. bnx2x_disable_sriov(bp);
  8144. bnx2x_enable_sriov(bp);
  8145. }
  8146. }
  8147. static void bnx2x_period_task(struct work_struct *work)
  8148. {
  8149. struct bnx2x *bp = container_of(work, struct bnx2x, period_task.work);
  8150. if (!netif_running(bp->dev))
  8151. goto period_task_exit;
  8152. if (CHIP_REV_IS_SLOW(bp)) {
  8153. BNX2X_ERR("period task called on emulation, ignoring\n");
  8154. goto period_task_exit;
  8155. }
  8156. bnx2x_acquire_phy_lock(bp);
  8157. /*
  8158. * The barrier is needed to ensure the ordering between the writing to
  8159. * the bp->port.pmf in the bnx2x_nic_load() or bnx2x_pmf_update() and
  8160. * the reading here.
  8161. */
  8162. smp_mb();
  8163. if (bp->port.pmf) {
  8164. bnx2x_period_func(&bp->link_params, &bp->link_vars);
  8165. /* Re-queue task in 1 sec */
  8166. queue_delayed_work(bnx2x_wq, &bp->period_task, 1*HZ);
  8167. }
  8168. bnx2x_release_phy_lock(bp);
  8169. period_task_exit:
  8170. return;
  8171. }
  8172. /*
  8173. * Init service functions
  8174. */
  8175. u32 bnx2x_get_pretend_reg(struct bnx2x *bp)
  8176. {
  8177. u32 base = PXP2_REG_PGL_PRETEND_FUNC_F0;
  8178. u32 stride = PXP2_REG_PGL_PRETEND_FUNC_F1 - base;
  8179. return base + (BP_ABS_FUNC(bp)) * stride;
  8180. }
  8181. static void bnx2x_prev_unload_close_mac(struct bnx2x *bp,
  8182. struct bnx2x_mac_vals *vals)
  8183. {
  8184. u32 val, base_addr, offset, mask, reset_reg;
  8185. bool mac_stopped = false;
  8186. u8 port = BP_PORT(bp);
  8187. /* reset addresses as they also mark which values were changed */
  8188. vals->bmac_addr = 0;
  8189. vals->umac_addr = 0;
  8190. vals->xmac_addr = 0;
  8191. vals->emac_addr = 0;
  8192. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_2);
  8193. if (!CHIP_IS_E3(bp)) {
  8194. val = REG_RD(bp, NIG_REG_BMAC0_REGS_OUT_EN + port * 4);
  8195. mask = MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port;
  8196. if ((mask & reset_reg) && val) {
  8197. u32 wb_data[2];
  8198. BNX2X_DEV_INFO("Disable bmac Rx\n");
  8199. base_addr = BP_PORT(bp) ? NIG_REG_INGRESS_BMAC1_MEM
  8200. : NIG_REG_INGRESS_BMAC0_MEM;
  8201. offset = CHIP_IS_E2(bp) ? BIGMAC2_REGISTER_BMAC_CONTROL
  8202. : BIGMAC_REGISTER_BMAC_CONTROL;
  8203. /*
  8204. * use rd/wr since we cannot use dmae. This is safe
  8205. * since MCP won't access the bus due to the request
  8206. * to unload, and no function on the path can be
  8207. * loaded at this time.
  8208. */
  8209. wb_data[0] = REG_RD(bp, base_addr + offset);
  8210. wb_data[1] = REG_RD(bp, base_addr + offset + 0x4);
  8211. vals->bmac_addr = base_addr + offset;
  8212. vals->bmac_val[0] = wb_data[0];
  8213. vals->bmac_val[1] = wb_data[1];
  8214. wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE;
  8215. REG_WR(bp, vals->bmac_addr, wb_data[0]);
  8216. REG_WR(bp, vals->bmac_addr + 0x4, wb_data[1]);
  8217. }
  8218. BNX2X_DEV_INFO("Disable emac Rx\n");
  8219. vals->emac_addr = NIG_REG_NIG_EMAC0_EN + BP_PORT(bp)*4;
  8220. vals->emac_val = REG_RD(bp, vals->emac_addr);
  8221. REG_WR(bp, vals->emac_addr, 0);
  8222. mac_stopped = true;
  8223. } else {
  8224. if (reset_reg & MISC_REGISTERS_RESET_REG_2_XMAC) {
  8225. BNX2X_DEV_INFO("Disable xmac Rx\n");
  8226. base_addr = BP_PORT(bp) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
  8227. val = REG_RD(bp, base_addr + XMAC_REG_PFC_CTRL_HI);
  8228. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  8229. val & ~(1 << 1));
  8230. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  8231. val | (1 << 1));
  8232. vals->xmac_addr = base_addr + XMAC_REG_CTRL;
  8233. vals->xmac_val = REG_RD(bp, vals->xmac_addr);
  8234. REG_WR(bp, vals->xmac_addr, 0);
  8235. mac_stopped = true;
  8236. }
  8237. mask = MISC_REGISTERS_RESET_REG_2_UMAC0 << port;
  8238. if (mask & reset_reg) {
  8239. BNX2X_DEV_INFO("Disable umac Rx\n");
  8240. base_addr = BP_PORT(bp) ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
  8241. vals->umac_addr = base_addr + UMAC_REG_COMMAND_CONFIG;
  8242. vals->umac_val = REG_RD(bp, vals->umac_addr);
  8243. REG_WR(bp, vals->umac_addr, 0);
  8244. mac_stopped = true;
  8245. }
  8246. }
  8247. if (mac_stopped)
  8248. msleep(20);
  8249. }
  8250. #define BNX2X_PREV_UNDI_PROD_ADDR(p) (BAR_TSTRORM_INTMEM + 0x1508 + ((p) << 4))
  8251. #define BNX2X_PREV_UNDI_RCQ(val) ((val) & 0xffff)
  8252. #define BNX2X_PREV_UNDI_BD(val) ((val) >> 16 & 0xffff)
  8253. #define BNX2X_PREV_UNDI_PROD(rcq, bd) ((bd) << 16 | (rcq))
  8254. static void bnx2x_prev_unload_undi_inc(struct bnx2x *bp, u8 port, u8 inc)
  8255. {
  8256. u16 rcq, bd;
  8257. u32 tmp_reg = REG_RD(bp, BNX2X_PREV_UNDI_PROD_ADDR(port));
  8258. rcq = BNX2X_PREV_UNDI_RCQ(tmp_reg) + inc;
  8259. bd = BNX2X_PREV_UNDI_BD(tmp_reg) + inc;
  8260. tmp_reg = BNX2X_PREV_UNDI_PROD(rcq, bd);
  8261. REG_WR(bp, BNX2X_PREV_UNDI_PROD_ADDR(port), tmp_reg);
  8262. BNX2X_DEV_INFO("UNDI producer [%d] rings bd -> 0x%04x, rcq -> 0x%04x\n",
  8263. port, bd, rcq);
  8264. }
  8265. static int bnx2x_prev_mcp_done(struct bnx2x *bp)
  8266. {
  8267. u32 rc = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE,
  8268. DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET);
  8269. if (!rc) {
  8270. BNX2X_ERR("MCP response failure, aborting\n");
  8271. return -EBUSY;
  8272. }
  8273. return 0;
  8274. }
  8275. static struct bnx2x_prev_path_list *
  8276. bnx2x_prev_path_get_entry(struct bnx2x *bp)
  8277. {
  8278. struct bnx2x_prev_path_list *tmp_list;
  8279. list_for_each_entry(tmp_list, &bnx2x_prev_list, list)
  8280. if (PCI_SLOT(bp->pdev->devfn) == tmp_list->slot &&
  8281. bp->pdev->bus->number == tmp_list->bus &&
  8282. BP_PATH(bp) == tmp_list->path)
  8283. return tmp_list;
  8284. return NULL;
  8285. }
  8286. static int bnx2x_prev_path_mark_eeh(struct bnx2x *bp)
  8287. {
  8288. struct bnx2x_prev_path_list *tmp_list;
  8289. int rc;
  8290. rc = down_interruptible(&bnx2x_prev_sem);
  8291. if (rc) {
  8292. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  8293. return rc;
  8294. }
  8295. tmp_list = bnx2x_prev_path_get_entry(bp);
  8296. if (tmp_list) {
  8297. tmp_list->aer = 1;
  8298. rc = 0;
  8299. } else {
  8300. BNX2X_ERR("path %d: Entry does not exist for eeh; Flow occurs before initial insmod is over ?\n",
  8301. BP_PATH(bp));
  8302. }
  8303. up(&bnx2x_prev_sem);
  8304. return rc;
  8305. }
  8306. static bool bnx2x_prev_is_path_marked(struct bnx2x *bp)
  8307. {
  8308. struct bnx2x_prev_path_list *tmp_list;
  8309. bool rc = false;
  8310. if (down_trylock(&bnx2x_prev_sem))
  8311. return false;
  8312. tmp_list = bnx2x_prev_path_get_entry(bp);
  8313. if (tmp_list) {
  8314. if (tmp_list->aer) {
  8315. DP(NETIF_MSG_HW, "Path %d was marked by AER\n",
  8316. BP_PATH(bp));
  8317. } else {
  8318. rc = true;
  8319. BNX2X_DEV_INFO("Path %d was already cleaned from previous drivers\n",
  8320. BP_PATH(bp));
  8321. }
  8322. }
  8323. up(&bnx2x_prev_sem);
  8324. return rc;
  8325. }
  8326. bool bnx2x_port_after_undi(struct bnx2x *bp)
  8327. {
  8328. struct bnx2x_prev_path_list *entry;
  8329. bool val;
  8330. down(&bnx2x_prev_sem);
  8331. entry = bnx2x_prev_path_get_entry(bp);
  8332. val = !!(entry && (entry->undi & (1 << BP_PORT(bp))));
  8333. up(&bnx2x_prev_sem);
  8334. return val;
  8335. }
  8336. static int bnx2x_prev_mark_path(struct bnx2x *bp, bool after_undi)
  8337. {
  8338. struct bnx2x_prev_path_list *tmp_list;
  8339. int rc;
  8340. rc = down_interruptible(&bnx2x_prev_sem);
  8341. if (rc) {
  8342. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  8343. return rc;
  8344. }
  8345. /* Check whether the entry for this path already exists */
  8346. tmp_list = bnx2x_prev_path_get_entry(bp);
  8347. if (tmp_list) {
  8348. if (!tmp_list->aer) {
  8349. BNX2X_ERR("Re-Marking the path.\n");
  8350. } else {
  8351. DP(NETIF_MSG_HW, "Removing AER indication from path %d\n",
  8352. BP_PATH(bp));
  8353. tmp_list->aer = 0;
  8354. }
  8355. up(&bnx2x_prev_sem);
  8356. return 0;
  8357. }
  8358. up(&bnx2x_prev_sem);
  8359. /* Create an entry for this path and add it */
  8360. tmp_list = kmalloc(sizeof(struct bnx2x_prev_path_list), GFP_KERNEL);
  8361. if (!tmp_list) {
  8362. BNX2X_ERR("Failed to allocate 'bnx2x_prev_path_list'\n");
  8363. return -ENOMEM;
  8364. }
  8365. tmp_list->bus = bp->pdev->bus->number;
  8366. tmp_list->slot = PCI_SLOT(bp->pdev->devfn);
  8367. tmp_list->path = BP_PATH(bp);
  8368. tmp_list->aer = 0;
  8369. tmp_list->undi = after_undi ? (1 << BP_PORT(bp)) : 0;
  8370. rc = down_interruptible(&bnx2x_prev_sem);
  8371. if (rc) {
  8372. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  8373. kfree(tmp_list);
  8374. } else {
  8375. DP(NETIF_MSG_HW, "Marked path [%d] - finished previous unload\n",
  8376. BP_PATH(bp));
  8377. list_add(&tmp_list->list, &bnx2x_prev_list);
  8378. up(&bnx2x_prev_sem);
  8379. }
  8380. return rc;
  8381. }
  8382. static int bnx2x_do_flr(struct bnx2x *bp)
  8383. {
  8384. struct pci_dev *dev = bp->pdev;
  8385. if (CHIP_IS_E1x(bp)) {
  8386. BNX2X_DEV_INFO("FLR not supported in E1/E1H\n");
  8387. return -EINVAL;
  8388. }
  8389. /* only bootcode REQ_BC_VER_4_INITIATE_FLR and onwards support flr */
  8390. if (bp->common.bc_ver < REQ_BC_VER_4_INITIATE_FLR) {
  8391. BNX2X_ERR("FLR not supported by BC_VER: 0x%x\n",
  8392. bp->common.bc_ver);
  8393. return -EINVAL;
  8394. }
  8395. if (!pci_wait_for_pending_transaction(dev))
  8396. dev_err(&dev->dev, "transaction is not cleared; proceeding with reset anyway\n");
  8397. BNX2X_DEV_INFO("Initiating FLR\n");
  8398. bnx2x_fw_command(bp, DRV_MSG_CODE_INITIATE_FLR, 0);
  8399. return 0;
  8400. }
  8401. static int bnx2x_prev_unload_uncommon(struct bnx2x *bp)
  8402. {
  8403. int rc;
  8404. BNX2X_DEV_INFO("Uncommon unload Flow\n");
  8405. /* Test if previous unload process was already finished for this path */
  8406. if (bnx2x_prev_is_path_marked(bp))
  8407. return bnx2x_prev_mcp_done(bp);
  8408. BNX2X_DEV_INFO("Path is unmarked\n");
  8409. /* If function has FLR capabilities, and existing FW version matches
  8410. * the one required, then FLR will be sufficient to clean any residue
  8411. * left by previous driver
  8412. */
  8413. rc = bnx2x_nic_load_analyze_req(bp, FW_MSG_CODE_DRV_LOAD_FUNCTION);
  8414. if (!rc) {
  8415. /* fw version is good */
  8416. BNX2X_DEV_INFO("FW version matches our own. Attempting FLR\n");
  8417. rc = bnx2x_do_flr(bp);
  8418. }
  8419. if (!rc) {
  8420. /* FLR was performed */
  8421. BNX2X_DEV_INFO("FLR successful\n");
  8422. return 0;
  8423. }
  8424. BNX2X_DEV_INFO("Could not FLR\n");
  8425. /* Close the MCP request, return failure*/
  8426. rc = bnx2x_prev_mcp_done(bp);
  8427. if (!rc)
  8428. rc = BNX2X_PREV_WAIT_NEEDED;
  8429. return rc;
  8430. }
  8431. static int bnx2x_prev_unload_common(struct bnx2x *bp)
  8432. {
  8433. u32 reset_reg, tmp_reg = 0, rc;
  8434. bool prev_undi = false;
  8435. struct bnx2x_mac_vals mac_vals;
  8436. /* It is possible a previous function received 'common' answer,
  8437. * but hasn't loaded yet, therefore creating a scenario of
  8438. * multiple functions receiving 'common' on the same path.
  8439. */
  8440. BNX2X_DEV_INFO("Common unload Flow\n");
  8441. memset(&mac_vals, 0, sizeof(mac_vals));
  8442. if (bnx2x_prev_is_path_marked(bp))
  8443. return bnx2x_prev_mcp_done(bp);
  8444. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
  8445. /* Reset should be performed after BRB is emptied */
  8446. if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_BRB1) {
  8447. u32 timer_count = 1000;
  8448. /* Close the MAC Rx to prevent BRB from filling up */
  8449. bnx2x_prev_unload_close_mac(bp, &mac_vals);
  8450. /* close LLH filters towards the BRB */
  8451. bnx2x_set_rx_filter(&bp->link_params, 0);
  8452. /* Check if the UNDI driver was previously loaded
  8453. * UNDI driver initializes CID offset for normal bell to 0x7
  8454. */
  8455. if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_DORQ) {
  8456. tmp_reg = REG_RD(bp, DORQ_REG_NORM_CID_OFST);
  8457. if (tmp_reg == 0x7) {
  8458. BNX2X_DEV_INFO("UNDI previously loaded\n");
  8459. prev_undi = true;
  8460. /* clear the UNDI indication */
  8461. REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0);
  8462. /* clear possible idle check errors */
  8463. REG_RD(bp, NIG_REG_NIG_INT_STS_CLR_0);
  8464. }
  8465. }
  8466. if (!CHIP_IS_E1x(bp))
  8467. /* block FW from writing to host */
  8468. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  8469. /* wait until BRB is empty */
  8470. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  8471. while (timer_count) {
  8472. u32 prev_brb = tmp_reg;
  8473. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  8474. if (!tmp_reg)
  8475. break;
  8476. BNX2X_DEV_INFO("BRB still has 0x%08x\n", tmp_reg);
  8477. /* reset timer as long as BRB actually gets emptied */
  8478. if (prev_brb > tmp_reg)
  8479. timer_count = 1000;
  8480. else
  8481. timer_count--;
  8482. /* If UNDI resides in memory, manually increment it */
  8483. if (prev_undi)
  8484. bnx2x_prev_unload_undi_inc(bp, BP_PORT(bp), 1);
  8485. udelay(10);
  8486. }
  8487. if (!timer_count)
  8488. BNX2X_ERR("Failed to empty BRB, hope for the best\n");
  8489. }
  8490. /* No packets are in the pipeline, path is ready for reset */
  8491. bnx2x_reset_common(bp);
  8492. if (mac_vals.xmac_addr)
  8493. REG_WR(bp, mac_vals.xmac_addr, mac_vals.xmac_val);
  8494. if (mac_vals.umac_addr)
  8495. REG_WR(bp, mac_vals.umac_addr, mac_vals.umac_val);
  8496. if (mac_vals.emac_addr)
  8497. REG_WR(bp, mac_vals.emac_addr, mac_vals.emac_val);
  8498. if (mac_vals.bmac_addr) {
  8499. REG_WR(bp, mac_vals.bmac_addr, mac_vals.bmac_val[0]);
  8500. REG_WR(bp, mac_vals.bmac_addr + 4, mac_vals.bmac_val[1]);
  8501. }
  8502. rc = bnx2x_prev_mark_path(bp, prev_undi);
  8503. if (rc) {
  8504. bnx2x_prev_mcp_done(bp);
  8505. return rc;
  8506. }
  8507. return bnx2x_prev_mcp_done(bp);
  8508. }
  8509. /* previous driver DMAE transaction may have occurred when pre-boot stage ended
  8510. * and boot began, or when kdump kernel was loaded. Either case would invalidate
  8511. * the addresses of the transaction, resulting in was-error bit set in the pci
  8512. * causing all hw-to-host pcie transactions to timeout. If this happened we want
  8513. * to clear the interrupt which detected this from the pglueb and the was done
  8514. * bit
  8515. */
  8516. static void bnx2x_prev_interrupted_dmae(struct bnx2x *bp)
  8517. {
  8518. if (!CHIP_IS_E1x(bp)) {
  8519. u32 val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS);
  8520. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN) {
  8521. DP(BNX2X_MSG_SP,
  8522. "'was error' bit was found to be set in pglueb upon startup. Clearing\n");
  8523. REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR,
  8524. 1 << BP_FUNC(bp));
  8525. }
  8526. }
  8527. }
  8528. static int bnx2x_prev_unload(struct bnx2x *bp)
  8529. {
  8530. int time_counter = 10;
  8531. u32 rc, fw, hw_lock_reg, hw_lock_val;
  8532. BNX2X_DEV_INFO("Entering Previous Unload Flow\n");
  8533. /* clear hw from errors which may have resulted from an interrupted
  8534. * dmae transaction.
  8535. */
  8536. bnx2x_prev_interrupted_dmae(bp);
  8537. /* Release previously held locks */
  8538. hw_lock_reg = (BP_FUNC(bp) <= 5) ?
  8539. (MISC_REG_DRIVER_CONTROL_1 + BP_FUNC(bp) * 8) :
  8540. (MISC_REG_DRIVER_CONTROL_7 + (BP_FUNC(bp) - 6) * 8);
  8541. hw_lock_val = REG_RD(bp, hw_lock_reg);
  8542. if (hw_lock_val) {
  8543. if (hw_lock_val & HW_LOCK_RESOURCE_NVRAM) {
  8544. BNX2X_DEV_INFO("Release Previously held NVRAM lock\n");
  8545. REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
  8546. (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << BP_PORT(bp)));
  8547. }
  8548. BNX2X_DEV_INFO("Release Previously held hw lock\n");
  8549. REG_WR(bp, hw_lock_reg, 0xffffffff);
  8550. } else
  8551. BNX2X_DEV_INFO("No need to release hw/nvram locks\n");
  8552. if (MCPR_ACCESS_LOCK_LOCK & REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK)) {
  8553. BNX2X_DEV_INFO("Release previously held alr\n");
  8554. bnx2x_release_alr(bp);
  8555. }
  8556. do {
  8557. int aer = 0;
  8558. /* Lock MCP using an unload request */
  8559. fw = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS, 0);
  8560. if (!fw) {
  8561. BNX2X_ERR("MCP response failure, aborting\n");
  8562. rc = -EBUSY;
  8563. break;
  8564. }
  8565. rc = down_interruptible(&bnx2x_prev_sem);
  8566. if (rc) {
  8567. BNX2X_ERR("Cannot check for AER; Received %d when tried to take lock\n",
  8568. rc);
  8569. } else {
  8570. /* If Path is marked by EEH, ignore unload status */
  8571. aer = !!(bnx2x_prev_path_get_entry(bp) &&
  8572. bnx2x_prev_path_get_entry(bp)->aer);
  8573. up(&bnx2x_prev_sem);
  8574. }
  8575. if (fw == FW_MSG_CODE_DRV_UNLOAD_COMMON || aer) {
  8576. rc = bnx2x_prev_unload_common(bp);
  8577. break;
  8578. }
  8579. /* non-common reply from MCP might require looping */
  8580. rc = bnx2x_prev_unload_uncommon(bp);
  8581. if (rc != BNX2X_PREV_WAIT_NEEDED)
  8582. break;
  8583. msleep(20);
  8584. } while (--time_counter);
  8585. if (!time_counter || rc) {
  8586. BNX2X_ERR("Failed unloading previous driver, aborting\n");
  8587. rc = -EBUSY;
  8588. }
  8589. /* Mark function if its port was used to boot from SAN */
  8590. if (bnx2x_port_after_undi(bp))
  8591. bp->link_params.feature_config_flags |=
  8592. FEATURE_CONFIG_BOOT_FROM_SAN;
  8593. BNX2X_DEV_INFO("Finished Previous Unload Flow [%d]\n", rc);
  8594. return rc;
  8595. }
  8596. static void bnx2x_get_common_hwinfo(struct bnx2x *bp)
  8597. {
  8598. u32 val, val2, val3, val4, id, boot_mode;
  8599. u16 pmc;
  8600. /* Get the chip revision id and number. */
  8601. /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
  8602. val = REG_RD(bp, MISC_REG_CHIP_NUM);
  8603. id = ((val & 0xffff) << 16);
  8604. val = REG_RD(bp, MISC_REG_CHIP_REV);
  8605. id |= ((val & 0xf) << 12);
  8606. /* Metal is read from PCI regs, but we can't access >=0x400 from
  8607. * the configuration space (so we need to reg_rd)
  8608. */
  8609. val = REG_RD(bp, PCICFG_OFFSET + PCI_ID_VAL3);
  8610. id |= (((val >> 24) & 0xf) << 4);
  8611. val = REG_RD(bp, MISC_REG_BOND_ID);
  8612. id |= (val & 0xf);
  8613. bp->common.chip_id = id;
  8614. /* force 57811 according to MISC register */
  8615. if (REG_RD(bp, MISC_REG_CHIP_TYPE) & MISC_REG_CHIP_TYPE_57811_MASK) {
  8616. if (CHIP_IS_57810(bp))
  8617. bp->common.chip_id = (CHIP_NUM_57811 << 16) |
  8618. (bp->common.chip_id & 0x0000FFFF);
  8619. else if (CHIP_IS_57810_MF(bp))
  8620. bp->common.chip_id = (CHIP_NUM_57811_MF << 16) |
  8621. (bp->common.chip_id & 0x0000FFFF);
  8622. bp->common.chip_id |= 0x1;
  8623. }
  8624. /* Set doorbell size */
  8625. bp->db_size = (1 << BNX2X_DB_SHIFT);
  8626. if (!CHIP_IS_E1x(bp)) {
  8627. val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR);
  8628. if ((val & 1) == 0)
  8629. val = REG_RD(bp, MISC_REG_PORT4MODE_EN);
  8630. else
  8631. val = (val >> 1) & 1;
  8632. BNX2X_DEV_INFO("chip is in %s\n", val ? "4_PORT_MODE" :
  8633. "2_PORT_MODE");
  8634. bp->common.chip_port_mode = val ? CHIP_4_PORT_MODE :
  8635. CHIP_2_PORT_MODE;
  8636. if (CHIP_MODE_IS_4_PORT(bp))
  8637. bp->pfid = (bp->pf_num >> 1); /* 0..3 */
  8638. else
  8639. bp->pfid = (bp->pf_num & 0x6); /* 0, 2, 4, 6 */
  8640. } else {
  8641. bp->common.chip_port_mode = CHIP_PORT_MODE_NONE; /* N/A */
  8642. bp->pfid = bp->pf_num; /* 0..7 */
  8643. }
  8644. BNX2X_DEV_INFO("pf_id: %x", bp->pfid);
  8645. bp->link_params.chip_id = bp->common.chip_id;
  8646. BNX2X_DEV_INFO("chip ID is 0x%x\n", id);
  8647. val = (REG_RD(bp, 0x2874) & 0x55);
  8648. if ((bp->common.chip_id & 0x1) ||
  8649. (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) {
  8650. bp->flags |= ONE_PORT_FLAG;
  8651. BNX2X_DEV_INFO("single port device\n");
  8652. }
  8653. val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4);
  8654. bp->common.flash_size = (BNX2X_NVRAM_1MB_SIZE <<
  8655. (val & MCPR_NVM_CFG4_FLASH_SIZE));
  8656. BNX2X_DEV_INFO("flash_size 0x%x (%d)\n",
  8657. bp->common.flash_size, bp->common.flash_size);
  8658. bnx2x_init_shmem(bp);
  8659. bp->common.shmem2_base = REG_RD(bp, (BP_PATH(bp) ?
  8660. MISC_REG_GENERIC_CR_1 :
  8661. MISC_REG_GENERIC_CR_0));
  8662. bp->link_params.shmem_base = bp->common.shmem_base;
  8663. bp->link_params.shmem2_base = bp->common.shmem2_base;
  8664. if (SHMEM2_RD(bp, size) >
  8665. (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
  8666. bp->link_params.lfa_base =
  8667. REG_RD(bp, bp->common.shmem2_base +
  8668. (u32)offsetof(struct shmem2_region,
  8669. lfa_host_addr[BP_PORT(bp)]));
  8670. else
  8671. bp->link_params.lfa_base = 0;
  8672. BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n",
  8673. bp->common.shmem_base, bp->common.shmem2_base);
  8674. if (!bp->common.shmem_base) {
  8675. BNX2X_DEV_INFO("MCP not active\n");
  8676. bp->flags |= NO_MCP_FLAG;
  8677. return;
  8678. }
  8679. bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config);
  8680. BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config);
  8681. bp->link_params.hw_led_mode = ((bp->common.hw_config &
  8682. SHARED_HW_CFG_LED_MODE_MASK) >>
  8683. SHARED_HW_CFG_LED_MODE_SHIFT);
  8684. bp->link_params.feature_config_flags = 0;
  8685. val = SHMEM_RD(bp, dev_info.shared_feature_config.config);
  8686. if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED)
  8687. bp->link_params.feature_config_flags |=
  8688. FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  8689. else
  8690. bp->link_params.feature_config_flags &=
  8691. ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  8692. val = SHMEM_RD(bp, dev_info.bc_rev) >> 8;
  8693. bp->common.bc_ver = val;
  8694. BNX2X_DEV_INFO("bc_ver %X\n", val);
  8695. if (val < BNX2X_BC_VER) {
  8696. /* for now only warn
  8697. * later we might need to enforce this */
  8698. BNX2X_ERR("This driver needs bc_ver %X but found %X, please upgrade BC\n",
  8699. BNX2X_BC_VER, val);
  8700. }
  8701. bp->link_params.feature_config_flags |=
  8702. (val >= REQ_BC_VER_4_VRFY_FIRST_PHY_OPT_MDL) ?
  8703. FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY : 0;
  8704. bp->link_params.feature_config_flags |=
  8705. (val >= REQ_BC_VER_4_VRFY_SPECIFIC_PHY_OPT_MDL) ?
  8706. FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY : 0;
  8707. bp->link_params.feature_config_flags |=
  8708. (val >= REQ_BC_VER_4_VRFY_AFEX_SUPPORTED) ?
  8709. FEATURE_CONFIG_BC_SUPPORTS_AFEX : 0;
  8710. bp->link_params.feature_config_flags |=
  8711. (val >= REQ_BC_VER_4_SFP_TX_DISABLE_SUPPORTED) ?
  8712. FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED : 0;
  8713. bp->link_params.feature_config_flags |=
  8714. (val >= REQ_BC_VER_4_MT_SUPPORTED) ?
  8715. FEATURE_CONFIG_MT_SUPPORT : 0;
  8716. bp->flags |= (val >= REQ_BC_VER_4_PFC_STATS_SUPPORTED) ?
  8717. BC_SUPPORTS_PFC_STATS : 0;
  8718. bp->flags |= (val >= REQ_BC_VER_4_FCOE_FEATURES) ?
  8719. BC_SUPPORTS_FCOE_FEATURES : 0;
  8720. bp->flags |= (val >= REQ_BC_VER_4_DCBX_ADMIN_MSG_NON_PMF) ?
  8721. BC_SUPPORTS_DCBX_MSG_NON_PMF : 0;
  8722. bp->flags |= (val >= REQ_BC_VER_4_RMMOD_CMD) ?
  8723. BC_SUPPORTS_RMMOD_CMD : 0;
  8724. boot_mode = SHMEM_RD(bp,
  8725. dev_info.port_feature_config[BP_PORT(bp)].mba_config) &
  8726. PORT_FEATURE_MBA_BOOT_AGENT_TYPE_MASK;
  8727. switch (boot_mode) {
  8728. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_PXE:
  8729. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_PXE;
  8730. break;
  8731. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_ISCSIB:
  8732. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_ISCSI;
  8733. break;
  8734. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_FCOE_BOOT:
  8735. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_FCOE;
  8736. break;
  8737. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_NONE:
  8738. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_NONE;
  8739. break;
  8740. }
  8741. pci_read_config_word(bp->pdev, bp->pdev->pm_cap + PCI_PM_PMC, &pmc);
  8742. bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG;
  8743. BNX2X_DEV_INFO("%sWoL capable\n",
  8744. (bp->flags & NO_WOL_FLAG) ? "not " : "");
  8745. val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num);
  8746. val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]);
  8747. val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]);
  8748. val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]);
  8749. dev_info(&bp->pdev->dev, "part number %X-%X-%X-%X\n",
  8750. val, val2, val3, val4);
  8751. }
  8752. #define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID)
  8753. #define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR)
  8754. static int bnx2x_get_igu_cam_info(struct bnx2x *bp)
  8755. {
  8756. int pfid = BP_FUNC(bp);
  8757. int igu_sb_id;
  8758. u32 val;
  8759. u8 fid, igu_sb_cnt = 0;
  8760. bp->igu_base_sb = 0xff;
  8761. if (CHIP_INT_MODE_IS_BC(bp)) {
  8762. int vn = BP_VN(bp);
  8763. igu_sb_cnt = bp->igu_sb_cnt;
  8764. bp->igu_base_sb = (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn) *
  8765. FP_SB_MAX_E1x;
  8766. bp->igu_dsb_id = E1HVN_MAX * FP_SB_MAX_E1x +
  8767. (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn);
  8768. return 0;
  8769. }
  8770. /* IGU in normal mode - read CAM */
  8771. for (igu_sb_id = 0; igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE;
  8772. igu_sb_id++) {
  8773. val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4);
  8774. if (!(val & IGU_REG_MAPPING_MEMORY_VALID))
  8775. continue;
  8776. fid = IGU_FID(val);
  8777. if ((fid & IGU_FID_ENCODE_IS_PF)) {
  8778. if ((fid & IGU_FID_PF_NUM_MASK) != pfid)
  8779. continue;
  8780. if (IGU_VEC(val) == 0)
  8781. /* default status block */
  8782. bp->igu_dsb_id = igu_sb_id;
  8783. else {
  8784. if (bp->igu_base_sb == 0xff)
  8785. bp->igu_base_sb = igu_sb_id;
  8786. igu_sb_cnt++;
  8787. }
  8788. }
  8789. }
  8790. #ifdef CONFIG_PCI_MSI
  8791. /* Due to new PF resource allocation by MFW T7.4 and above, it's
  8792. * optional that number of CAM entries will not be equal to the value
  8793. * advertised in PCI.
  8794. * Driver should use the minimal value of both as the actual status
  8795. * block count
  8796. */
  8797. bp->igu_sb_cnt = min_t(int, bp->igu_sb_cnt, igu_sb_cnt);
  8798. #endif
  8799. if (igu_sb_cnt == 0) {
  8800. BNX2X_ERR("CAM configuration error\n");
  8801. return -EINVAL;
  8802. }
  8803. return 0;
  8804. }
  8805. static void bnx2x_link_settings_supported(struct bnx2x *bp, u32 switch_cfg)
  8806. {
  8807. int cfg_size = 0, idx, port = BP_PORT(bp);
  8808. /* Aggregation of supported attributes of all external phys */
  8809. bp->port.supported[0] = 0;
  8810. bp->port.supported[1] = 0;
  8811. switch (bp->link_params.num_phys) {
  8812. case 1:
  8813. bp->port.supported[0] = bp->link_params.phy[INT_PHY].supported;
  8814. cfg_size = 1;
  8815. break;
  8816. case 2:
  8817. bp->port.supported[0] = bp->link_params.phy[EXT_PHY1].supported;
  8818. cfg_size = 1;
  8819. break;
  8820. case 3:
  8821. if (bp->link_params.multi_phy_config &
  8822. PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
  8823. bp->port.supported[1] =
  8824. bp->link_params.phy[EXT_PHY1].supported;
  8825. bp->port.supported[0] =
  8826. bp->link_params.phy[EXT_PHY2].supported;
  8827. } else {
  8828. bp->port.supported[0] =
  8829. bp->link_params.phy[EXT_PHY1].supported;
  8830. bp->port.supported[1] =
  8831. bp->link_params.phy[EXT_PHY2].supported;
  8832. }
  8833. cfg_size = 2;
  8834. break;
  8835. }
  8836. if (!(bp->port.supported[0] || bp->port.supported[1])) {
  8837. BNX2X_ERR("NVRAM config error. BAD phy config. PHY1 config 0x%x, PHY2 config 0x%x\n",
  8838. SHMEM_RD(bp,
  8839. dev_info.port_hw_config[port].external_phy_config),
  8840. SHMEM_RD(bp,
  8841. dev_info.port_hw_config[port].external_phy_config2));
  8842. return;
  8843. }
  8844. if (CHIP_IS_E3(bp))
  8845. bp->port.phy_addr = REG_RD(bp, MISC_REG_WC0_CTRL_PHY_ADDR);
  8846. else {
  8847. switch (switch_cfg) {
  8848. case SWITCH_CFG_1G:
  8849. bp->port.phy_addr = REG_RD(
  8850. bp, NIG_REG_SERDES0_CTRL_PHY_ADDR + port*0x10);
  8851. break;
  8852. case SWITCH_CFG_10G:
  8853. bp->port.phy_addr = REG_RD(
  8854. bp, NIG_REG_XGXS0_CTRL_PHY_ADDR + port*0x18);
  8855. break;
  8856. default:
  8857. BNX2X_ERR("BAD switch_cfg link_config 0x%x\n",
  8858. bp->port.link_config[0]);
  8859. return;
  8860. }
  8861. }
  8862. BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
  8863. /* mask what we support according to speed_cap_mask per configuration */
  8864. for (idx = 0; idx < cfg_size; idx++) {
  8865. if (!(bp->link_params.speed_cap_mask[idx] &
  8866. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF))
  8867. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Half;
  8868. if (!(bp->link_params.speed_cap_mask[idx] &
  8869. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL))
  8870. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Full;
  8871. if (!(bp->link_params.speed_cap_mask[idx] &
  8872. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF))
  8873. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Half;
  8874. if (!(bp->link_params.speed_cap_mask[idx] &
  8875. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL))
  8876. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Full;
  8877. if (!(bp->link_params.speed_cap_mask[idx] &
  8878. PORT_HW_CFG_SPEED_CAPABILITY_D0_1G))
  8879. bp->port.supported[idx] &= ~(SUPPORTED_1000baseT_Half |
  8880. SUPPORTED_1000baseT_Full);
  8881. if (!(bp->link_params.speed_cap_mask[idx] &
  8882. PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
  8883. bp->port.supported[idx] &= ~SUPPORTED_2500baseX_Full;
  8884. if (!(bp->link_params.speed_cap_mask[idx] &
  8885. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G))
  8886. bp->port.supported[idx] &= ~SUPPORTED_10000baseT_Full;
  8887. if (!(bp->link_params.speed_cap_mask[idx] &
  8888. PORT_HW_CFG_SPEED_CAPABILITY_D0_20G))
  8889. bp->port.supported[idx] &= ~SUPPORTED_20000baseKR2_Full;
  8890. }
  8891. BNX2X_DEV_INFO("supported 0x%x 0x%x\n", bp->port.supported[0],
  8892. bp->port.supported[1]);
  8893. }
  8894. static void bnx2x_link_settings_requested(struct bnx2x *bp)
  8895. {
  8896. u32 link_config, idx, cfg_size = 0;
  8897. bp->port.advertising[0] = 0;
  8898. bp->port.advertising[1] = 0;
  8899. switch (bp->link_params.num_phys) {
  8900. case 1:
  8901. case 2:
  8902. cfg_size = 1;
  8903. break;
  8904. case 3:
  8905. cfg_size = 2;
  8906. break;
  8907. }
  8908. for (idx = 0; idx < cfg_size; idx++) {
  8909. bp->link_params.req_duplex[idx] = DUPLEX_FULL;
  8910. link_config = bp->port.link_config[idx];
  8911. switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
  8912. case PORT_FEATURE_LINK_SPEED_AUTO:
  8913. if (bp->port.supported[idx] & SUPPORTED_Autoneg) {
  8914. bp->link_params.req_line_speed[idx] =
  8915. SPEED_AUTO_NEG;
  8916. bp->port.advertising[idx] |=
  8917. bp->port.supported[idx];
  8918. if (bp->link_params.phy[EXT_PHY1].type ==
  8919. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
  8920. bp->port.advertising[idx] |=
  8921. (SUPPORTED_100baseT_Half |
  8922. SUPPORTED_100baseT_Full);
  8923. } else {
  8924. /* force 10G, no AN */
  8925. bp->link_params.req_line_speed[idx] =
  8926. SPEED_10000;
  8927. bp->port.advertising[idx] |=
  8928. (ADVERTISED_10000baseT_Full |
  8929. ADVERTISED_FIBRE);
  8930. continue;
  8931. }
  8932. break;
  8933. case PORT_FEATURE_LINK_SPEED_10M_FULL:
  8934. if (bp->port.supported[idx] & SUPPORTED_10baseT_Full) {
  8935. bp->link_params.req_line_speed[idx] =
  8936. SPEED_10;
  8937. bp->port.advertising[idx] |=
  8938. (ADVERTISED_10baseT_Full |
  8939. ADVERTISED_TP);
  8940. } else {
  8941. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8942. link_config,
  8943. bp->link_params.speed_cap_mask[idx]);
  8944. return;
  8945. }
  8946. break;
  8947. case PORT_FEATURE_LINK_SPEED_10M_HALF:
  8948. if (bp->port.supported[idx] & SUPPORTED_10baseT_Half) {
  8949. bp->link_params.req_line_speed[idx] =
  8950. SPEED_10;
  8951. bp->link_params.req_duplex[idx] =
  8952. DUPLEX_HALF;
  8953. bp->port.advertising[idx] |=
  8954. (ADVERTISED_10baseT_Half |
  8955. ADVERTISED_TP);
  8956. } else {
  8957. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8958. link_config,
  8959. bp->link_params.speed_cap_mask[idx]);
  8960. return;
  8961. }
  8962. break;
  8963. case PORT_FEATURE_LINK_SPEED_100M_FULL:
  8964. if (bp->port.supported[idx] &
  8965. SUPPORTED_100baseT_Full) {
  8966. bp->link_params.req_line_speed[idx] =
  8967. SPEED_100;
  8968. bp->port.advertising[idx] |=
  8969. (ADVERTISED_100baseT_Full |
  8970. ADVERTISED_TP);
  8971. } else {
  8972. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8973. link_config,
  8974. bp->link_params.speed_cap_mask[idx]);
  8975. return;
  8976. }
  8977. break;
  8978. case PORT_FEATURE_LINK_SPEED_100M_HALF:
  8979. if (bp->port.supported[idx] &
  8980. SUPPORTED_100baseT_Half) {
  8981. bp->link_params.req_line_speed[idx] =
  8982. SPEED_100;
  8983. bp->link_params.req_duplex[idx] =
  8984. DUPLEX_HALF;
  8985. bp->port.advertising[idx] |=
  8986. (ADVERTISED_100baseT_Half |
  8987. ADVERTISED_TP);
  8988. } else {
  8989. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8990. link_config,
  8991. bp->link_params.speed_cap_mask[idx]);
  8992. return;
  8993. }
  8994. break;
  8995. case PORT_FEATURE_LINK_SPEED_1G:
  8996. if (bp->port.supported[idx] &
  8997. SUPPORTED_1000baseT_Full) {
  8998. bp->link_params.req_line_speed[idx] =
  8999. SPEED_1000;
  9000. bp->port.advertising[idx] |=
  9001. (ADVERTISED_1000baseT_Full |
  9002. ADVERTISED_TP);
  9003. } else {
  9004. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9005. link_config,
  9006. bp->link_params.speed_cap_mask[idx]);
  9007. return;
  9008. }
  9009. break;
  9010. case PORT_FEATURE_LINK_SPEED_2_5G:
  9011. if (bp->port.supported[idx] &
  9012. SUPPORTED_2500baseX_Full) {
  9013. bp->link_params.req_line_speed[idx] =
  9014. SPEED_2500;
  9015. bp->port.advertising[idx] |=
  9016. (ADVERTISED_2500baseX_Full |
  9017. ADVERTISED_TP);
  9018. } else {
  9019. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9020. link_config,
  9021. bp->link_params.speed_cap_mask[idx]);
  9022. return;
  9023. }
  9024. break;
  9025. case PORT_FEATURE_LINK_SPEED_10G_CX4:
  9026. if (bp->port.supported[idx] &
  9027. SUPPORTED_10000baseT_Full) {
  9028. bp->link_params.req_line_speed[idx] =
  9029. SPEED_10000;
  9030. bp->port.advertising[idx] |=
  9031. (ADVERTISED_10000baseT_Full |
  9032. ADVERTISED_FIBRE);
  9033. } else {
  9034. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9035. link_config,
  9036. bp->link_params.speed_cap_mask[idx]);
  9037. return;
  9038. }
  9039. break;
  9040. case PORT_FEATURE_LINK_SPEED_20G:
  9041. bp->link_params.req_line_speed[idx] = SPEED_20000;
  9042. break;
  9043. default:
  9044. BNX2X_ERR("NVRAM config error. BAD link speed link_config 0x%x\n",
  9045. link_config);
  9046. bp->link_params.req_line_speed[idx] =
  9047. SPEED_AUTO_NEG;
  9048. bp->port.advertising[idx] =
  9049. bp->port.supported[idx];
  9050. break;
  9051. }
  9052. bp->link_params.req_flow_ctrl[idx] = (link_config &
  9053. PORT_FEATURE_FLOW_CONTROL_MASK);
  9054. if (bp->link_params.req_flow_ctrl[idx] ==
  9055. BNX2X_FLOW_CTRL_AUTO) {
  9056. if (!(bp->port.supported[idx] & SUPPORTED_Autoneg))
  9057. bp->link_params.req_flow_ctrl[idx] =
  9058. BNX2X_FLOW_CTRL_NONE;
  9059. else
  9060. bnx2x_set_requested_fc(bp);
  9061. }
  9062. BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl 0x%x advertising 0x%x\n",
  9063. bp->link_params.req_line_speed[idx],
  9064. bp->link_params.req_duplex[idx],
  9065. bp->link_params.req_flow_ctrl[idx],
  9066. bp->port.advertising[idx]);
  9067. }
  9068. }
  9069. static void bnx2x_set_mac_buf(u8 *mac_buf, u32 mac_lo, u16 mac_hi)
  9070. {
  9071. __be16 mac_hi_be = cpu_to_be16(mac_hi);
  9072. __be32 mac_lo_be = cpu_to_be32(mac_lo);
  9073. memcpy(mac_buf, &mac_hi_be, sizeof(mac_hi_be));
  9074. memcpy(mac_buf + sizeof(mac_hi_be), &mac_lo_be, sizeof(mac_lo_be));
  9075. }
  9076. static void bnx2x_get_port_hwinfo(struct bnx2x *bp)
  9077. {
  9078. int port = BP_PORT(bp);
  9079. u32 config;
  9080. u32 ext_phy_type, ext_phy_config, eee_mode;
  9081. bp->link_params.bp = bp;
  9082. bp->link_params.port = port;
  9083. bp->link_params.lane_config =
  9084. SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config);
  9085. bp->link_params.speed_cap_mask[0] =
  9086. SHMEM_RD(bp,
  9087. dev_info.port_hw_config[port].speed_capability_mask) &
  9088. PORT_HW_CFG_SPEED_CAPABILITY_D0_MASK;
  9089. bp->link_params.speed_cap_mask[1] =
  9090. SHMEM_RD(bp,
  9091. dev_info.port_hw_config[port].speed_capability_mask2) &
  9092. PORT_HW_CFG_SPEED_CAPABILITY_D0_MASK;
  9093. bp->port.link_config[0] =
  9094. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config);
  9095. bp->port.link_config[1] =
  9096. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config2);
  9097. bp->link_params.multi_phy_config =
  9098. SHMEM_RD(bp, dev_info.port_hw_config[port].multi_phy_config);
  9099. /* If the device is capable of WoL, set the default state according
  9100. * to the HW
  9101. */
  9102. config = SHMEM_RD(bp, dev_info.port_feature_config[port].config);
  9103. bp->wol = (!(bp->flags & NO_WOL_FLAG) &&
  9104. (config & PORT_FEATURE_WOL_ENABLED));
  9105. if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) ==
  9106. PORT_FEAT_CFG_STORAGE_PERSONALITY_FCOE && !IS_MF(bp))
  9107. bp->flags |= NO_ISCSI_FLAG;
  9108. if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) ==
  9109. PORT_FEAT_CFG_STORAGE_PERSONALITY_ISCSI && !(IS_MF(bp)))
  9110. bp->flags |= NO_FCOE_FLAG;
  9111. BNX2X_DEV_INFO("lane_config 0x%08x speed_cap_mask0 0x%08x link_config0 0x%08x\n",
  9112. bp->link_params.lane_config,
  9113. bp->link_params.speed_cap_mask[0],
  9114. bp->port.link_config[0]);
  9115. bp->link_params.switch_cfg = (bp->port.link_config[0] &
  9116. PORT_FEATURE_CONNECTED_SWITCH_MASK);
  9117. bnx2x_phy_probe(&bp->link_params);
  9118. bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg);
  9119. bnx2x_link_settings_requested(bp);
  9120. /*
  9121. * If connected directly, work with the internal PHY, otherwise, work
  9122. * with the external PHY
  9123. */
  9124. ext_phy_config =
  9125. SHMEM_RD(bp,
  9126. dev_info.port_hw_config[port].external_phy_config);
  9127. ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
  9128. if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
  9129. bp->mdio.prtad = bp->port.phy_addr;
  9130. else if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) &&
  9131. (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
  9132. bp->mdio.prtad =
  9133. XGXS_EXT_PHY_ADDR(ext_phy_config);
  9134. /* Configure link feature according to nvram value */
  9135. eee_mode = (((SHMEM_RD(bp, dev_info.
  9136. port_feature_config[port].eee_power_mode)) &
  9137. PORT_FEAT_CFG_EEE_POWER_MODE_MASK) >>
  9138. PORT_FEAT_CFG_EEE_POWER_MODE_SHIFT);
  9139. if (eee_mode != PORT_FEAT_CFG_EEE_POWER_MODE_DISABLED) {
  9140. bp->link_params.eee_mode = EEE_MODE_ADV_LPI |
  9141. EEE_MODE_ENABLE_LPI |
  9142. EEE_MODE_OUTPUT_TIME;
  9143. } else {
  9144. bp->link_params.eee_mode = 0;
  9145. }
  9146. }
  9147. void bnx2x_get_iscsi_info(struct bnx2x *bp)
  9148. {
  9149. u32 no_flags = NO_ISCSI_FLAG;
  9150. int port = BP_PORT(bp);
  9151. u32 max_iscsi_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  9152. drv_lic_key[port].max_iscsi_conn);
  9153. if (!CNIC_SUPPORT(bp)) {
  9154. bp->flags |= no_flags;
  9155. return;
  9156. }
  9157. /* Get the number of maximum allowed iSCSI connections */
  9158. bp->cnic_eth_dev.max_iscsi_conn =
  9159. (max_iscsi_conn & BNX2X_MAX_ISCSI_INIT_CONN_MASK) >>
  9160. BNX2X_MAX_ISCSI_INIT_CONN_SHIFT;
  9161. BNX2X_DEV_INFO("max_iscsi_conn 0x%x\n",
  9162. bp->cnic_eth_dev.max_iscsi_conn);
  9163. /*
  9164. * If maximum allowed number of connections is zero -
  9165. * disable the feature.
  9166. */
  9167. if (!bp->cnic_eth_dev.max_iscsi_conn)
  9168. bp->flags |= no_flags;
  9169. }
  9170. static void bnx2x_get_ext_wwn_info(struct bnx2x *bp, int func)
  9171. {
  9172. /* Port info */
  9173. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  9174. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_upper);
  9175. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  9176. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_lower);
  9177. /* Node info */
  9178. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  9179. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_upper);
  9180. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  9181. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_lower);
  9182. }
  9183. static int bnx2x_shared_fcoe_funcs(struct bnx2x *bp)
  9184. {
  9185. u8 count = 0;
  9186. if (IS_MF(bp)) {
  9187. u8 fid;
  9188. /* iterate over absolute function ids for this path: */
  9189. for (fid = BP_PATH(bp); fid < E2_FUNC_MAX * 2; fid += 2) {
  9190. if (IS_MF_SD(bp)) {
  9191. u32 cfg = MF_CFG_RD(bp,
  9192. func_mf_config[fid].config);
  9193. if (!(cfg & FUNC_MF_CFG_FUNC_HIDE) &&
  9194. ((cfg & FUNC_MF_CFG_PROTOCOL_MASK) ==
  9195. FUNC_MF_CFG_PROTOCOL_FCOE))
  9196. count++;
  9197. } else {
  9198. u32 cfg = MF_CFG_RD(bp,
  9199. func_ext_config[fid].
  9200. func_cfg);
  9201. if ((cfg & MACP_FUNC_CFG_FLAGS_ENABLED) &&
  9202. (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD))
  9203. count++;
  9204. }
  9205. }
  9206. } else { /* SF */
  9207. int port, port_cnt = CHIP_MODE_IS_4_PORT(bp) ? 2 : 1;
  9208. for (port = 0; port < port_cnt; port++) {
  9209. u32 lic = SHMEM_RD(bp,
  9210. drv_lic_key[port].max_fcoe_conn) ^
  9211. FW_ENCODE_32BIT_PATTERN;
  9212. if (lic)
  9213. count++;
  9214. }
  9215. }
  9216. return count;
  9217. }
  9218. static void bnx2x_get_fcoe_info(struct bnx2x *bp)
  9219. {
  9220. int port = BP_PORT(bp);
  9221. int func = BP_ABS_FUNC(bp);
  9222. u32 max_fcoe_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  9223. drv_lic_key[port].max_fcoe_conn);
  9224. u8 num_fcoe_func = bnx2x_shared_fcoe_funcs(bp);
  9225. if (!CNIC_SUPPORT(bp)) {
  9226. bp->flags |= NO_FCOE_FLAG;
  9227. return;
  9228. }
  9229. /* Get the number of maximum allowed FCoE connections */
  9230. bp->cnic_eth_dev.max_fcoe_conn =
  9231. (max_fcoe_conn & BNX2X_MAX_FCOE_INIT_CONN_MASK) >>
  9232. BNX2X_MAX_FCOE_INIT_CONN_SHIFT;
  9233. /* Calculate the number of maximum allowed FCoE tasks */
  9234. bp->cnic_eth_dev.max_fcoe_exchanges = MAX_NUM_FCOE_TASKS_PER_ENGINE;
  9235. /* check if FCoE resources must be shared between different functions */
  9236. if (num_fcoe_func)
  9237. bp->cnic_eth_dev.max_fcoe_exchanges /= num_fcoe_func;
  9238. /* Read the WWN: */
  9239. if (!IS_MF(bp)) {
  9240. /* Port info */
  9241. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  9242. SHMEM_RD(bp,
  9243. dev_info.port_hw_config[port].
  9244. fcoe_wwn_port_name_upper);
  9245. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  9246. SHMEM_RD(bp,
  9247. dev_info.port_hw_config[port].
  9248. fcoe_wwn_port_name_lower);
  9249. /* Node info */
  9250. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  9251. SHMEM_RD(bp,
  9252. dev_info.port_hw_config[port].
  9253. fcoe_wwn_node_name_upper);
  9254. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  9255. SHMEM_RD(bp,
  9256. dev_info.port_hw_config[port].
  9257. fcoe_wwn_node_name_lower);
  9258. } else if (!IS_MF_SD(bp)) {
  9259. /*
  9260. * Read the WWN info only if the FCoE feature is enabled for
  9261. * this function.
  9262. */
  9263. if (BNX2X_MF_EXT_PROTOCOL_FCOE(bp) && !CHIP_IS_E1x(bp))
  9264. bnx2x_get_ext_wwn_info(bp, func);
  9265. } else if (IS_MF_FCOE_SD(bp) && !CHIP_IS_E1x(bp)) {
  9266. bnx2x_get_ext_wwn_info(bp, func);
  9267. }
  9268. BNX2X_DEV_INFO("max_fcoe_conn 0x%x\n", bp->cnic_eth_dev.max_fcoe_conn);
  9269. /*
  9270. * If maximum allowed number of connections is zero -
  9271. * disable the feature.
  9272. */
  9273. if (!bp->cnic_eth_dev.max_fcoe_conn)
  9274. bp->flags |= NO_FCOE_FLAG;
  9275. }
  9276. static void bnx2x_get_cnic_info(struct bnx2x *bp)
  9277. {
  9278. /*
  9279. * iSCSI may be dynamically disabled but reading
  9280. * info here we will decrease memory usage by driver
  9281. * if the feature is disabled for good
  9282. */
  9283. bnx2x_get_iscsi_info(bp);
  9284. bnx2x_get_fcoe_info(bp);
  9285. }
  9286. static void bnx2x_get_cnic_mac_hwinfo(struct bnx2x *bp)
  9287. {
  9288. u32 val, val2;
  9289. int func = BP_ABS_FUNC(bp);
  9290. int port = BP_PORT(bp);
  9291. u8 *iscsi_mac = bp->cnic_eth_dev.iscsi_mac;
  9292. u8 *fip_mac = bp->fip_mac;
  9293. if (IS_MF(bp)) {
  9294. /* iSCSI and FCoE NPAR MACs: if there is no either iSCSI or
  9295. * FCoE MAC then the appropriate feature should be disabled.
  9296. * In non SD mode features configuration comes from struct
  9297. * func_ext_config.
  9298. */
  9299. if (!IS_MF_SD(bp) && !CHIP_IS_E1x(bp)) {
  9300. u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
  9301. if (cfg & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) {
  9302. val2 = MF_CFG_RD(bp, func_ext_config[func].
  9303. iscsi_mac_addr_upper);
  9304. val = MF_CFG_RD(bp, func_ext_config[func].
  9305. iscsi_mac_addr_lower);
  9306. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  9307. BNX2X_DEV_INFO
  9308. ("Read iSCSI MAC: %pM\n", iscsi_mac);
  9309. } else {
  9310. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  9311. }
  9312. if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) {
  9313. val2 = MF_CFG_RD(bp, func_ext_config[func].
  9314. fcoe_mac_addr_upper);
  9315. val = MF_CFG_RD(bp, func_ext_config[func].
  9316. fcoe_mac_addr_lower);
  9317. bnx2x_set_mac_buf(fip_mac, val, val2);
  9318. BNX2X_DEV_INFO
  9319. ("Read FCoE L2 MAC: %pM\n", fip_mac);
  9320. } else {
  9321. bp->flags |= NO_FCOE_FLAG;
  9322. }
  9323. bp->mf_ext_config = cfg;
  9324. } else { /* SD MODE */
  9325. if (BNX2X_IS_MF_SD_PROTOCOL_ISCSI(bp)) {
  9326. /* use primary mac as iscsi mac */
  9327. memcpy(iscsi_mac, bp->dev->dev_addr, ETH_ALEN);
  9328. BNX2X_DEV_INFO("SD ISCSI MODE\n");
  9329. BNX2X_DEV_INFO
  9330. ("Read iSCSI MAC: %pM\n", iscsi_mac);
  9331. } else if (BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp)) {
  9332. /* use primary mac as fip mac */
  9333. memcpy(fip_mac, bp->dev->dev_addr, ETH_ALEN);
  9334. BNX2X_DEV_INFO("SD FCoE MODE\n");
  9335. BNX2X_DEV_INFO
  9336. ("Read FIP MAC: %pM\n", fip_mac);
  9337. }
  9338. }
  9339. /* If this is a storage-only interface, use SAN mac as
  9340. * primary MAC. Notice that for SD this is already the case,
  9341. * as the SAN mac was copied from the primary MAC.
  9342. */
  9343. if (IS_MF_FCOE_AFEX(bp))
  9344. memcpy(bp->dev->dev_addr, fip_mac, ETH_ALEN);
  9345. } else {
  9346. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9347. iscsi_mac_upper);
  9348. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9349. iscsi_mac_lower);
  9350. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  9351. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9352. fcoe_fip_mac_upper);
  9353. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9354. fcoe_fip_mac_lower);
  9355. bnx2x_set_mac_buf(fip_mac, val, val2);
  9356. }
  9357. /* Disable iSCSI OOO if MAC configuration is invalid. */
  9358. if (!is_valid_ether_addr(iscsi_mac)) {
  9359. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  9360. memset(iscsi_mac, 0, ETH_ALEN);
  9361. }
  9362. /* Disable FCoE if MAC configuration is invalid. */
  9363. if (!is_valid_ether_addr(fip_mac)) {
  9364. bp->flags |= NO_FCOE_FLAG;
  9365. memset(bp->fip_mac, 0, ETH_ALEN);
  9366. }
  9367. }
  9368. static void bnx2x_get_mac_hwinfo(struct bnx2x *bp)
  9369. {
  9370. u32 val, val2;
  9371. int func = BP_ABS_FUNC(bp);
  9372. int port = BP_PORT(bp);
  9373. /* Zero primary MAC configuration */
  9374. memset(bp->dev->dev_addr, 0, ETH_ALEN);
  9375. if (BP_NOMCP(bp)) {
  9376. BNX2X_ERROR("warning: random MAC workaround active\n");
  9377. eth_hw_addr_random(bp->dev);
  9378. } else if (IS_MF(bp)) {
  9379. val2 = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
  9380. val = MF_CFG_RD(bp, func_mf_config[func].mac_lower);
  9381. if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) &&
  9382. (val != FUNC_MF_CFG_LOWERMAC_DEFAULT))
  9383. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  9384. if (CNIC_SUPPORT(bp))
  9385. bnx2x_get_cnic_mac_hwinfo(bp);
  9386. } else {
  9387. /* in SF read MACs from port configuration */
  9388. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
  9389. val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
  9390. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  9391. if (CNIC_SUPPORT(bp))
  9392. bnx2x_get_cnic_mac_hwinfo(bp);
  9393. }
  9394. memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN);
  9395. if (!bnx2x_is_valid_ether_addr(bp, bp->dev->dev_addr))
  9396. dev_err(&bp->pdev->dev,
  9397. "bad Ethernet MAC address configuration: %pM\n"
  9398. "change it manually before bringing up the appropriate network interface\n",
  9399. bp->dev->dev_addr);
  9400. }
  9401. static bool bnx2x_get_dropless_info(struct bnx2x *bp)
  9402. {
  9403. int tmp;
  9404. u32 cfg;
  9405. if (IS_VF(bp))
  9406. return 0;
  9407. if (IS_MF(bp) && !CHIP_IS_E1x(bp)) {
  9408. /* Take function: tmp = func */
  9409. tmp = BP_ABS_FUNC(bp);
  9410. cfg = MF_CFG_RD(bp, func_ext_config[tmp].func_cfg);
  9411. cfg = !!(cfg & MACP_FUNC_CFG_PAUSE_ON_HOST_RING);
  9412. } else {
  9413. /* Take port: tmp = port */
  9414. tmp = BP_PORT(bp);
  9415. cfg = SHMEM_RD(bp,
  9416. dev_info.port_hw_config[tmp].generic_features);
  9417. cfg = !!(cfg & PORT_HW_CFG_PAUSE_ON_HOST_RING_ENABLED);
  9418. }
  9419. return cfg;
  9420. }
  9421. static int bnx2x_get_hwinfo(struct bnx2x *bp)
  9422. {
  9423. int /*abs*/func = BP_ABS_FUNC(bp);
  9424. int vn;
  9425. u32 val = 0;
  9426. int rc = 0;
  9427. bnx2x_get_common_hwinfo(bp);
  9428. /*
  9429. * initialize IGU parameters
  9430. */
  9431. if (CHIP_IS_E1x(bp)) {
  9432. bp->common.int_block = INT_BLOCK_HC;
  9433. bp->igu_dsb_id = DEF_SB_IGU_ID;
  9434. bp->igu_base_sb = 0;
  9435. } else {
  9436. bp->common.int_block = INT_BLOCK_IGU;
  9437. /* do not allow device reset during IGU info processing */
  9438. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  9439. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  9440. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  9441. int tout = 5000;
  9442. BNX2X_DEV_INFO("FORCING Normal Mode\n");
  9443. val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN);
  9444. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION, val);
  9445. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x7f);
  9446. while (tout && REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  9447. tout--;
  9448. usleep_range(1000, 2000);
  9449. }
  9450. if (REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  9451. dev_err(&bp->pdev->dev,
  9452. "FORCING Normal Mode failed!!!\n");
  9453. bnx2x_release_hw_lock(bp,
  9454. HW_LOCK_RESOURCE_RESET);
  9455. return -EPERM;
  9456. }
  9457. }
  9458. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  9459. BNX2X_DEV_INFO("IGU Backward Compatible Mode\n");
  9460. bp->common.int_block |= INT_BLOCK_MODE_BW_COMP;
  9461. } else
  9462. BNX2X_DEV_INFO("IGU Normal Mode\n");
  9463. rc = bnx2x_get_igu_cam_info(bp);
  9464. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  9465. if (rc)
  9466. return rc;
  9467. }
  9468. /*
  9469. * set base FW non-default (fast path) status block id, this value is
  9470. * used to initialize the fw_sb_id saved on the fp/queue structure to
  9471. * determine the id used by the FW.
  9472. */
  9473. if (CHIP_IS_E1x(bp))
  9474. bp->base_fw_ndsb = BP_PORT(bp) * FP_SB_MAX_E1x + BP_L_ID(bp);
  9475. else /*
  9476. * 57712 - we currently use one FW SB per IGU SB (Rx and Tx of
  9477. * the same queue are indicated on the same IGU SB). So we prefer
  9478. * FW and IGU SBs to be the same value.
  9479. */
  9480. bp->base_fw_ndsb = bp->igu_base_sb;
  9481. BNX2X_DEV_INFO("igu_dsb_id %d igu_base_sb %d igu_sb_cnt %d\n"
  9482. "base_fw_ndsb %d\n", bp->igu_dsb_id, bp->igu_base_sb,
  9483. bp->igu_sb_cnt, bp->base_fw_ndsb);
  9484. /*
  9485. * Initialize MF configuration
  9486. */
  9487. bp->mf_ov = 0;
  9488. bp->mf_mode = 0;
  9489. vn = BP_VN(bp);
  9490. if (!CHIP_IS_E1(bp) && !BP_NOMCP(bp)) {
  9491. BNX2X_DEV_INFO("shmem2base 0x%x, size %d, mfcfg offset %d\n",
  9492. bp->common.shmem2_base, SHMEM2_RD(bp, size),
  9493. (u32)offsetof(struct shmem2_region, mf_cfg_addr));
  9494. if (SHMEM2_HAS(bp, mf_cfg_addr))
  9495. bp->common.mf_cfg_base = SHMEM2_RD(bp, mf_cfg_addr);
  9496. else
  9497. bp->common.mf_cfg_base = bp->common.shmem_base +
  9498. offsetof(struct shmem_region, func_mb) +
  9499. E1H_FUNC_MAX * sizeof(struct drv_func_mb);
  9500. /*
  9501. * get mf configuration:
  9502. * 1. Existence of MF configuration
  9503. * 2. MAC address must be legal (check only upper bytes)
  9504. * for Switch-Independent mode;
  9505. * OVLAN must be legal for Switch-Dependent mode
  9506. * 3. SF_MODE configures specific MF mode
  9507. */
  9508. if (bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  9509. /* get mf configuration */
  9510. val = SHMEM_RD(bp,
  9511. dev_info.shared_feature_config.config);
  9512. val &= SHARED_FEAT_CFG_FORCE_SF_MODE_MASK;
  9513. switch (val) {
  9514. case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT:
  9515. val = MF_CFG_RD(bp, func_mf_config[func].
  9516. mac_upper);
  9517. /* check for legal mac (upper bytes)*/
  9518. if (val != 0xffff) {
  9519. bp->mf_mode = MULTI_FUNCTION_SI;
  9520. bp->mf_config[vn] = MF_CFG_RD(bp,
  9521. func_mf_config[func].config);
  9522. } else
  9523. BNX2X_DEV_INFO("illegal MAC address for SI\n");
  9524. break;
  9525. case SHARED_FEAT_CFG_FORCE_SF_MODE_AFEX_MODE:
  9526. if ((!CHIP_IS_E1x(bp)) &&
  9527. (MF_CFG_RD(bp, func_mf_config[func].
  9528. mac_upper) != 0xffff) &&
  9529. (SHMEM2_HAS(bp,
  9530. afex_driver_support))) {
  9531. bp->mf_mode = MULTI_FUNCTION_AFEX;
  9532. bp->mf_config[vn] = MF_CFG_RD(bp,
  9533. func_mf_config[func].config);
  9534. } else {
  9535. BNX2X_DEV_INFO("can not configure afex mode\n");
  9536. }
  9537. break;
  9538. case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED:
  9539. /* get OV configuration */
  9540. val = MF_CFG_RD(bp,
  9541. func_mf_config[FUNC_0].e1hov_tag);
  9542. val &= FUNC_MF_CFG_E1HOV_TAG_MASK;
  9543. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  9544. bp->mf_mode = MULTI_FUNCTION_SD;
  9545. bp->mf_config[vn] = MF_CFG_RD(bp,
  9546. func_mf_config[func].config);
  9547. } else
  9548. BNX2X_DEV_INFO("illegal OV for SD\n");
  9549. break;
  9550. case SHARED_FEAT_CFG_FORCE_SF_MODE_FORCED_SF:
  9551. bp->mf_config[vn] = 0;
  9552. break;
  9553. default:
  9554. /* Unknown configuration: reset mf_config */
  9555. bp->mf_config[vn] = 0;
  9556. BNX2X_DEV_INFO("unknown MF mode 0x%x\n", val);
  9557. }
  9558. }
  9559. BNX2X_DEV_INFO("%s function mode\n",
  9560. IS_MF(bp) ? "multi" : "single");
  9561. switch (bp->mf_mode) {
  9562. case MULTI_FUNCTION_SD:
  9563. val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  9564. FUNC_MF_CFG_E1HOV_TAG_MASK;
  9565. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  9566. bp->mf_ov = val;
  9567. bp->path_has_ovlan = true;
  9568. BNX2X_DEV_INFO("MF OV for func %d is %d (0x%04x)\n",
  9569. func, bp->mf_ov, bp->mf_ov);
  9570. } else {
  9571. dev_err(&bp->pdev->dev,
  9572. "No valid MF OV for func %d, aborting\n",
  9573. func);
  9574. return -EPERM;
  9575. }
  9576. break;
  9577. case MULTI_FUNCTION_AFEX:
  9578. BNX2X_DEV_INFO("func %d is in MF afex mode\n", func);
  9579. break;
  9580. case MULTI_FUNCTION_SI:
  9581. BNX2X_DEV_INFO("func %d is in MF switch-independent mode\n",
  9582. func);
  9583. break;
  9584. default:
  9585. if (vn) {
  9586. dev_err(&bp->pdev->dev,
  9587. "VN %d is in a single function mode, aborting\n",
  9588. vn);
  9589. return -EPERM;
  9590. }
  9591. break;
  9592. }
  9593. /* check if other port on the path needs ovlan:
  9594. * Since MF configuration is shared between ports
  9595. * Possible mixed modes are only
  9596. * {SF, SI} {SF, SD} {SD, SF} {SI, SF}
  9597. */
  9598. if (CHIP_MODE_IS_4_PORT(bp) &&
  9599. !bp->path_has_ovlan &&
  9600. !IS_MF(bp) &&
  9601. bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  9602. u8 other_port = !BP_PORT(bp);
  9603. u8 other_func = BP_PATH(bp) + 2*other_port;
  9604. val = MF_CFG_RD(bp,
  9605. func_mf_config[other_func].e1hov_tag);
  9606. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT)
  9607. bp->path_has_ovlan = true;
  9608. }
  9609. }
  9610. /* adjust igu_sb_cnt to MF for E1x */
  9611. if (CHIP_IS_E1x(bp) && IS_MF(bp))
  9612. bp->igu_sb_cnt /= E1HVN_MAX;
  9613. /* port info */
  9614. bnx2x_get_port_hwinfo(bp);
  9615. /* Get MAC addresses */
  9616. bnx2x_get_mac_hwinfo(bp);
  9617. bnx2x_get_cnic_info(bp);
  9618. return rc;
  9619. }
  9620. static void bnx2x_read_fwinfo(struct bnx2x *bp)
  9621. {
  9622. int cnt, i, block_end, rodi;
  9623. char vpd_start[BNX2X_VPD_LEN+1];
  9624. char str_id_reg[VENDOR_ID_LEN+1];
  9625. char str_id_cap[VENDOR_ID_LEN+1];
  9626. char *vpd_data;
  9627. char *vpd_extended_data = NULL;
  9628. u8 len;
  9629. cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_start);
  9630. memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
  9631. if (cnt < BNX2X_VPD_LEN)
  9632. goto out_not_found;
  9633. /* VPD RO tag should be first tag after identifier string, hence
  9634. * we should be able to find it in first BNX2X_VPD_LEN chars
  9635. */
  9636. i = pci_vpd_find_tag(vpd_start, 0, BNX2X_VPD_LEN,
  9637. PCI_VPD_LRDT_RO_DATA);
  9638. if (i < 0)
  9639. goto out_not_found;
  9640. block_end = i + PCI_VPD_LRDT_TAG_SIZE +
  9641. pci_vpd_lrdt_size(&vpd_start[i]);
  9642. i += PCI_VPD_LRDT_TAG_SIZE;
  9643. if (block_end > BNX2X_VPD_LEN) {
  9644. vpd_extended_data = kmalloc(block_end, GFP_KERNEL);
  9645. if (vpd_extended_data == NULL)
  9646. goto out_not_found;
  9647. /* read rest of vpd image into vpd_extended_data */
  9648. memcpy(vpd_extended_data, vpd_start, BNX2X_VPD_LEN);
  9649. cnt = pci_read_vpd(bp->pdev, BNX2X_VPD_LEN,
  9650. block_end - BNX2X_VPD_LEN,
  9651. vpd_extended_data + BNX2X_VPD_LEN);
  9652. if (cnt < (block_end - BNX2X_VPD_LEN))
  9653. goto out_not_found;
  9654. vpd_data = vpd_extended_data;
  9655. } else
  9656. vpd_data = vpd_start;
  9657. /* now vpd_data holds full vpd content in both cases */
  9658. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  9659. PCI_VPD_RO_KEYWORD_MFR_ID);
  9660. if (rodi < 0)
  9661. goto out_not_found;
  9662. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  9663. if (len != VENDOR_ID_LEN)
  9664. goto out_not_found;
  9665. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  9666. /* vendor specific info */
  9667. snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL);
  9668. snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL);
  9669. if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) ||
  9670. !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) {
  9671. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  9672. PCI_VPD_RO_KEYWORD_VENDOR0);
  9673. if (rodi >= 0) {
  9674. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  9675. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  9676. if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) {
  9677. memcpy(bp->fw_ver, &vpd_data[rodi], len);
  9678. bp->fw_ver[len] = ' ';
  9679. }
  9680. }
  9681. kfree(vpd_extended_data);
  9682. return;
  9683. }
  9684. out_not_found:
  9685. kfree(vpd_extended_data);
  9686. return;
  9687. }
  9688. static void bnx2x_set_modes_bitmap(struct bnx2x *bp)
  9689. {
  9690. u32 flags = 0;
  9691. if (CHIP_REV_IS_FPGA(bp))
  9692. SET_FLAGS(flags, MODE_FPGA);
  9693. else if (CHIP_REV_IS_EMUL(bp))
  9694. SET_FLAGS(flags, MODE_EMUL);
  9695. else
  9696. SET_FLAGS(flags, MODE_ASIC);
  9697. if (CHIP_MODE_IS_4_PORT(bp))
  9698. SET_FLAGS(flags, MODE_PORT4);
  9699. else
  9700. SET_FLAGS(flags, MODE_PORT2);
  9701. if (CHIP_IS_E2(bp))
  9702. SET_FLAGS(flags, MODE_E2);
  9703. else if (CHIP_IS_E3(bp)) {
  9704. SET_FLAGS(flags, MODE_E3);
  9705. if (CHIP_REV(bp) == CHIP_REV_Ax)
  9706. SET_FLAGS(flags, MODE_E3_A0);
  9707. else /*if (CHIP_REV(bp) == CHIP_REV_Bx)*/
  9708. SET_FLAGS(flags, MODE_E3_B0 | MODE_COS3);
  9709. }
  9710. if (IS_MF(bp)) {
  9711. SET_FLAGS(flags, MODE_MF);
  9712. switch (bp->mf_mode) {
  9713. case MULTI_FUNCTION_SD:
  9714. SET_FLAGS(flags, MODE_MF_SD);
  9715. break;
  9716. case MULTI_FUNCTION_SI:
  9717. SET_FLAGS(flags, MODE_MF_SI);
  9718. break;
  9719. case MULTI_FUNCTION_AFEX:
  9720. SET_FLAGS(flags, MODE_MF_AFEX);
  9721. break;
  9722. }
  9723. } else
  9724. SET_FLAGS(flags, MODE_SF);
  9725. #if defined(__LITTLE_ENDIAN)
  9726. SET_FLAGS(flags, MODE_LITTLE_ENDIAN);
  9727. #else /*(__BIG_ENDIAN)*/
  9728. SET_FLAGS(flags, MODE_BIG_ENDIAN);
  9729. #endif
  9730. INIT_MODE_FLAGS(bp) = flags;
  9731. }
  9732. static int bnx2x_init_bp(struct bnx2x *bp)
  9733. {
  9734. int func;
  9735. int rc;
  9736. mutex_init(&bp->port.phy_mutex);
  9737. mutex_init(&bp->fw_mb_mutex);
  9738. spin_lock_init(&bp->stats_lock);
  9739. sema_init(&bp->stats_sema, 1);
  9740. INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task);
  9741. INIT_DELAYED_WORK(&bp->sp_rtnl_task, bnx2x_sp_rtnl_task);
  9742. INIT_DELAYED_WORK(&bp->period_task, bnx2x_period_task);
  9743. if (IS_PF(bp)) {
  9744. rc = bnx2x_get_hwinfo(bp);
  9745. if (rc)
  9746. return rc;
  9747. } else {
  9748. eth_zero_addr(bp->dev->dev_addr);
  9749. }
  9750. bnx2x_set_modes_bitmap(bp);
  9751. rc = bnx2x_alloc_mem_bp(bp);
  9752. if (rc)
  9753. return rc;
  9754. bnx2x_read_fwinfo(bp);
  9755. func = BP_FUNC(bp);
  9756. /* need to reset chip if undi was active */
  9757. if (IS_PF(bp) && !BP_NOMCP(bp)) {
  9758. /* init fw_seq */
  9759. bp->fw_seq =
  9760. SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
  9761. DRV_MSG_SEQ_NUMBER_MASK;
  9762. BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
  9763. bnx2x_prev_unload(bp);
  9764. }
  9765. if (CHIP_REV_IS_FPGA(bp))
  9766. dev_err(&bp->pdev->dev, "FPGA detected\n");
  9767. if (BP_NOMCP(bp) && (func == 0))
  9768. dev_err(&bp->pdev->dev, "MCP disabled, must load devices in order!\n");
  9769. bp->disable_tpa = disable_tpa;
  9770. bp->disable_tpa |= IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp);
  9771. /* Set TPA flags */
  9772. if (bp->disable_tpa) {
  9773. bp->flags &= ~(TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
  9774. bp->dev->features &= ~NETIF_F_LRO;
  9775. } else {
  9776. bp->flags |= (TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
  9777. bp->dev->features |= NETIF_F_LRO;
  9778. }
  9779. if (CHIP_IS_E1(bp))
  9780. bp->dropless_fc = 0;
  9781. else
  9782. bp->dropless_fc = dropless_fc | bnx2x_get_dropless_info(bp);
  9783. bp->mrrs = mrrs;
  9784. bp->tx_ring_size = IS_MF_FCOE_AFEX(bp) ? 0 : MAX_TX_AVAIL;
  9785. if (IS_VF(bp))
  9786. bp->rx_ring_size = MAX_RX_AVAIL;
  9787. /* make sure that the numbers are in the right granularity */
  9788. bp->tx_ticks = (50 / BNX2X_BTR) * BNX2X_BTR;
  9789. bp->rx_ticks = (25 / BNX2X_BTR) * BNX2X_BTR;
  9790. bp->current_interval = CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ;
  9791. init_timer(&bp->timer);
  9792. bp->timer.expires = jiffies + bp->current_interval;
  9793. bp->timer.data = (unsigned long) bp;
  9794. bp->timer.function = bnx2x_timer;
  9795. if (SHMEM2_HAS(bp, dcbx_lldp_params_offset) &&
  9796. SHMEM2_HAS(bp, dcbx_lldp_dcbx_stat_offset) &&
  9797. SHMEM2_RD(bp, dcbx_lldp_params_offset) &&
  9798. SHMEM2_RD(bp, dcbx_lldp_dcbx_stat_offset)) {
  9799. bnx2x_dcbx_set_state(bp, true, BNX2X_DCBX_ENABLED_ON_NEG_ON);
  9800. bnx2x_dcbx_init_params(bp);
  9801. } else {
  9802. bnx2x_dcbx_set_state(bp, false, BNX2X_DCBX_ENABLED_OFF);
  9803. }
  9804. if (CHIP_IS_E1x(bp))
  9805. bp->cnic_base_cl_id = FP_SB_MAX_E1x;
  9806. else
  9807. bp->cnic_base_cl_id = FP_SB_MAX_E2;
  9808. /* multiple tx priority */
  9809. if (IS_VF(bp))
  9810. bp->max_cos = 1;
  9811. else if (CHIP_IS_E1x(bp))
  9812. bp->max_cos = BNX2X_MULTI_TX_COS_E1X;
  9813. else if (CHIP_IS_E2(bp) || CHIP_IS_E3A0(bp))
  9814. bp->max_cos = BNX2X_MULTI_TX_COS_E2_E3A0;
  9815. else if (CHIP_IS_E3B0(bp))
  9816. bp->max_cos = BNX2X_MULTI_TX_COS_E3B0;
  9817. else
  9818. BNX2X_ERR("unknown chip %x revision %x\n",
  9819. CHIP_NUM(bp), CHIP_REV(bp));
  9820. BNX2X_DEV_INFO("set bp->max_cos to %d\n", bp->max_cos);
  9821. /* We need at least one default status block for slow-path events,
  9822. * second status block for the L2 queue, and a third status block for
  9823. * CNIC if supported.
  9824. */
  9825. if (IS_VF(bp))
  9826. bp->min_msix_vec_cnt = 1;
  9827. else if (CNIC_SUPPORT(bp))
  9828. bp->min_msix_vec_cnt = 3;
  9829. else /* PF w/o cnic */
  9830. bp->min_msix_vec_cnt = 2;
  9831. BNX2X_DEV_INFO("bp->min_msix_vec_cnt %d", bp->min_msix_vec_cnt);
  9832. bp->dump_preset_idx = 1;
  9833. return rc;
  9834. }
  9835. /****************************************************************************
  9836. * General service functions
  9837. ****************************************************************************/
  9838. /*
  9839. * net_device service functions
  9840. */
  9841. /* called with rtnl_lock */
  9842. static int bnx2x_open(struct net_device *dev)
  9843. {
  9844. struct bnx2x *bp = netdev_priv(dev);
  9845. bool global = false;
  9846. int other_engine = BP_PATH(bp) ? 0 : 1;
  9847. bool other_load_status, load_status;
  9848. int rc;
  9849. bp->stats_init = true;
  9850. netif_carrier_off(dev);
  9851. bnx2x_set_power_state(bp, PCI_D0);
  9852. /* If parity had happen during the unload, then attentions
  9853. * and/or RECOVERY_IN_PROGRES may still be set. In this case we
  9854. * want the first function loaded on the current engine to
  9855. * complete the recovery.
  9856. * Parity recovery is only relevant for PF driver.
  9857. */
  9858. if (IS_PF(bp)) {
  9859. other_load_status = bnx2x_get_load_status(bp, other_engine);
  9860. load_status = bnx2x_get_load_status(bp, BP_PATH(bp));
  9861. if (!bnx2x_reset_is_done(bp, BP_PATH(bp)) ||
  9862. bnx2x_chk_parity_attn(bp, &global, true)) {
  9863. do {
  9864. /* If there are attentions and they are in a
  9865. * global blocks, set the GLOBAL_RESET bit
  9866. * regardless whether it will be this function
  9867. * that will complete the recovery or not.
  9868. */
  9869. if (global)
  9870. bnx2x_set_reset_global(bp);
  9871. /* Only the first function on the current
  9872. * engine should try to recover in open. In case
  9873. * of attentions in global blocks only the first
  9874. * in the chip should try to recover.
  9875. */
  9876. if ((!load_status &&
  9877. (!global || !other_load_status)) &&
  9878. bnx2x_trylock_leader_lock(bp) &&
  9879. !bnx2x_leader_reset(bp)) {
  9880. netdev_info(bp->dev,
  9881. "Recovered in open\n");
  9882. break;
  9883. }
  9884. /* recovery has failed... */
  9885. bnx2x_set_power_state(bp, PCI_D3hot);
  9886. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  9887. BNX2X_ERR("Recovery flow hasn't been properly completed yet. Try again later.\n"
  9888. "If you still see this message after a few retries then power cycle is required.\n");
  9889. return -EAGAIN;
  9890. } while (0);
  9891. }
  9892. }
  9893. bp->recovery_state = BNX2X_RECOVERY_DONE;
  9894. rc = bnx2x_nic_load(bp, LOAD_OPEN);
  9895. if (rc)
  9896. return rc;
  9897. return 0;
  9898. }
  9899. /* called with rtnl_lock */
  9900. static int bnx2x_close(struct net_device *dev)
  9901. {
  9902. struct bnx2x *bp = netdev_priv(dev);
  9903. /* Unload the driver, release IRQs */
  9904. bnx2x_nic_unload(bp, UNLOAD_CLOSE, false);
  9905. return 0;
  9906. }
  9907. static int bnx2x_init_mcast_macs_list(struct bnx2x *bp,
  9908. struct bnx2x_mcast_ramrod_params *p)
  9909. {
  9910. int mc_count = netdev_mc_count(bp->dev);
  9911. struct bnx2x_mcast_list_elem *mc_mac =
  9912. kzalloc(sizeof(*mc_mac) * mc_count, GFP_ATOMIC);
  9913. struct netdev_hw_addr *ha;
  9914. if (!mc_mac)
  9915. return -ENOMEM;
  9916. INIT_LIST_HEAD(&p->mcast_list);
  9917. netdev_for_each_mc_addr(ha, bp->dev) {
  9918. mc_mac->mac = bnx2x_mc_addr(ha);
  9919. list_add_tail(&mc_mac->link, &p->mcast_list);
  9920. mc_mac++;
  9921. }
  9922. p->mcast_list_len = mc_count;
  9923. return 0;
  9924. }
  9925. static void bnx2x_free_mcast_macs_list(
  9926. struct bnx2x_mcast_ramrod_params *p)
  9927. {
  9928. struct bnx2x_mcast_list_elem *mc_mac =
  9929. list_first_entry(&p->mcast_list, struct bnx2x_mcast_list_elem,
  9930. link);
  9931. WARN_ON(!mc_mac);
  9932. kfree(mc_mac);
  9933. }
  9934. /**
  9935. * bnx2x_set_uc_list - configure a new unicast MACs list.
  9936. *
  9937. * @bp: driver handle
  9938. *
  9939. * We will use zero (0) as a MAC type for these MACs.
  9940. */
  9941. static int bnx2x_set_uc_list(struct bnx2x *bp)
  9942. {
  9943. int rc;
  9944. struct net_device *dev = bp->dev;
  9945. struct netdev_hw_addr *ha;
  9946. struct bnx2x_vlan_mac_obj *mac_obj = &bp->sp_objs->mac_obj;
  9947. unsigned long ramrod_flags = 0;
  9948. /* First schedule a cleanup up of old configuration */
  9949. rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, false);
  9950. if (rc < 0) {
  9951. BNX2X_ERR("Failed to schedule DELETE operations: %d\n", rc);
  9952. return rc;
  9953. }
  9954. netdev_for_each_uc_addr(ha, dev) {
  9955. rc = bnx2x_set_mac_one(bp, bnx2x_uc_addr(ha), mac_obj, true,
  9956. BNX2X_UC_LIST_MAC, &ramrod_flags);
  9957. if (rc == -EEXIST) {
  9958. DP(BNX2X_MSG_SP,
  9959. "Failed to schedule ADD operations: %d\n", rc);
  9960. /* do not treat adding same MAC as error */
  9961. rc = 0;
  9962. } else if (rc < 0) {
  9963. BNX2X_ERR("Failed to schedule ADD operations: %d\n",
  9964. rc);
  9965. return rc;
  9966. }
  9967. }
  9968. /* Execute the pending commands */
  9969. __set_bit(RAMROD_CONT, &ramrod_flags);
  9970. return bnx2x_set_mac_one(bp, NULL, mac_obj, false /* don't care */,
  9971. BNX2X_UC_LIST_MAC, &ramrod_flags);
  9972. }
  9973. static int bnx2x_set_mc_list(struct bnx2x *bp)
  9974. {
  9975. struct net_device *dev = bp->dev;
  9976. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  9977. int rc = 0;
  9978. rparam.mcast_obj = &bp->mcast_obj;
  9979. /* first, clear all configured multicast MACs */
  9980. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  9981. if (rc < 0) {
  9982. BNX2X_ERR("Failed to clear multicast configuration: %d\n", rc);
  9983. return rc;
  9984. }
  9985. /* then, configure a new MACs list */
  9986. if (netdev_mc_count(dev)) {
  9987. rc = bnx2x_init_mcast_macs_list(bp, &rparam);
  9988. if (rc) {
  9989. BNX2X_ERR("Failed to create multicast MACs list: %d\n",
  9990. rc);
  9991. return rc;
  9992. }
  9993. /* Now add the new MACs */
  9994. rc = bnx2x_config_mcast(bp, &rparam,
  9995. BNX2X_MCAST_CMD_ADD);
  9996. if (rc < 0)
  9997. BNX2X_ERR("Failed to set a new multicast configuration: %d\n",
  9998. rc);
  9999. bnx2x_free_mcast_macs_list(&rparam);
  10000. }
  10001. return rc;
  10002. }
  10003. /* If bp->state is OPEN, should be called with netif_addr_lock_bh() */
  10004. void bnx2x_set_rx_mode(struct net_device *dev)
  10005. {
  10006. struct bnx2x *bp = netdev_priv(dev);
  10007. if (bp->state != BNX2X_STATE_OPEN) {
  10008. DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
  10009. return;
  10010. } else {
  10011. /* Schedule an SP task to handle rest of change */
  10012. DP(NETIF_MSG_IFUP, "Scheduling an Rx mode change\n");
  10013. smp_mb__before_clear_bit();
  10014. set_bit(BNX2X_SP_RTNL_RX_MODE, &bp->sp_rtnl_state);
  10015. smp_mb__after_clear_bit();
  10016. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  10017. }
  10018. }
  10019. void bnx2x_set_rx_mode_inner(struct bnx2x *bp)
  10020. {
  10021. u32 rx_mode = BNX2X_RX_MODE_NORMAL;
  10022. DP(NETIF_MSG_IFUP, "dev->flags = %x\n", bp->dev->flags);
  10023. netif_addr_lock_bh(bp->dev);
  10024. if (bp->dev->flags & IFF_PROMISC) {
  10025. rx_mode = BNX2X_RX_MODE_PROMISC;
  10026. } else if ((bp->dev->flags & IFF_ALLMULTI) ||
  10027. ((netdev_mc_count(bp->dev) > BNX2X_MAX_MULTICAST) &&
  10028. CHIP_IS_E1(bp))) {
  10029. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  10030. } else {
  10031. if (IS_PF(bp)) {
  10032. /* some multicasts */
  10033. if (bnx2x_set_mc_list(bp) < 0)
  10034. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  10035. /* release bh lock, as bnx2x_set_uc_list might sleep */
  10036. netif_addr_unlock_bh(bp->dev);
  10037. if (bnx2x_set_uc_list(bp) < 0)
  10038. rx_mode = BNX2X_RX_MODE_PROMISC;
  10039. netif_addr_lock_bh(bp->dev);
  10040. } else {
  10041. /* configuring mcast to a vf involves sleeping (when we
  10042. * wait for the pf's response).
  10043. */
  10044. smp_mb__before_clear_bit();
  10045. set_bit(BNX2X_SP_RTNL_VFPF_MCAST,
  10046. &bp->sp_rtnl_state);
  10047. smp_mb__after_clear_bit();
  10048. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  10049. }
  10050. }
  10051. bp->rx_mode = rx_mode;
  10052. /* handle ISCSI SD mode */
  10053. if (IS_MF_ISCSI_SD(bp))
  10054. bp->rx_mode = BNX2X_RX_MODE_NONE;
  10055. /* Schedule the rx_mode command */
  10056. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) {
  10057. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  10058. netif_addr_unlock_bh(bp->dev);
  10059. return;
  10060. }
  10061. if (IS_PF(bp)) {
  10062. bnx2x_set_storm_rx_mode(bp);
  10063. netif_addr_unlock_bh(bp->dev);
  10064. } else {
  10065. /* VF will need to request the PF to make this change, and so
  10066. * the VF needs to release the bottom-half lock prior to the
  10067. * request (as it will likely require sleep on the VF side)
  10068. */
  10069. netif_addr_unlock_bh(bp->dev);
  10070. bnx2x_vfpf_storm_rx_mode(bp);
  10071. }
  10072. }
  10073. /* called with rtnl_lock */
  10074. static int bnx2x_mdio_read(struct net_device *netdev, int prtad,
  10075. int devad, u16 addr)
  10076. {
  10077. struct bnx2x *bp = netdev_priv(netdev);
  10078. u16 value;
  10079. int rc;
  10080. DP(NETIF_MSG_LINK, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n",
  10081. prtad, devad, addr);
  10082. /* The HW expects different devad if CL22 is used */
  10083. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  10084. bnx2x_acquire_phy_lock(bp);
  10085. rc = bnx2x_phy_read(&bp->link_params, prtad, devad, addr, &value);
  10086. bnx2x_release_phy_lock(bp);
  10087. DP(NETIF_MSG_LINK, "mdio_read_val 0x%x rc = 0x%x\n", value, rc);
  10088. if (!rc)
  10089. rc = value;
  10090. return rc;
  10091. }
  10092. /* called with rtnl_lock */
  10093. static int bnx2x_mdio_write(struct net_device *netdev, int prtad, int devad,
  10094. u16 addr, u16 value)
  10095. {
  10096. struct bnx2x *bp = netdev_priv(netdev);
  10097. int rc;
  10098. DP(NETIF_MSG_LINK,
  10099. "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x, value 0x%x\n",
  10100. prtad, devad, addr, value);
  10101. /* The HW expects different devad if CL22 is used */
  10102. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  10103. bnx2x_acquire_phy_lock(bp);
  10104. rc = bnx2x_phy_write(&bp->link_params, prtad, devad, addr, value);
  10105. bnx2x_release_phy_lock(bp);
  10106. return rc;
  10107. }
  10108. /* called with rtnl_lock */
  10109. static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  10110. {
  10111. struct bnx2x *bp = netdev_priv(dev);
  10112. struct mii_ioctl_data *mdio = if_mii(ifr);
  10113. DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n",
  10114. mdio->phy_id, mdio->reg_num, mdio->val_in);
  10115. if (!netif_running(dev))
  10116. return -EAGAIN;
  10117. return mdio_mii_ioctl(&bp->mdio, mdio, cmd);
  10118. }
  10119. #ifdef CONFIG_NET_POLL_CONTROLLER
  10120. static void poll_bnx2x(struct net_device *dev)
  10121. {
  10122. struct bnx2x *bp = netdev_priv(dev);
  10123. int i;
  10124. for_each_eth_queue(bp, i) {
  10125. struct bnx2x_fastpath *fp = &bp->fp[i];
  10126. napi_schedule(&bnx2x_fp(bp, fp->index, napi));
  10127. }
  10128. }
  10129. #endif
  10130. static int bnx2x_validate_addr(struct net_device *dev)
  10131. {
  10132. struct bnx2x *bp = netdev_priv(dev);
  10133. /* query the bulletin board for mac address configured by the PF */
  10134. if (IS_VF(bp))
  10135. bnx2x_sample_bulletin(bp);
  10136. if (!bnx2x_is_valid_ether_addr(bp, dev->dev_addr)) {
  10137. BNX2X_ERR("Non-valid Ethernet address\n");
  10138. return -EADDRNOTAVAIL;
  10139. }
  10140. return 0;
  10141. }
  10142. static const struct net_device_ops bnx2x_netdev_ops = {
  10143. .ndo_open = bnx2x_open,
  10144. .ndo_stop = bnx2x_close,
  10145. .ndo_start_xmit = bnx2x_start_xmit,
  10146. .ndo_select_queue = bnx2x_select_queue,
  10147. .ndo_set_rx_mode = bnx2x_set_rx_mode,
  10148. .ndo_set_mac_address = bnx2x_change_mac_addr,
  10149. .ndo_validate_addr = bnx2x_validate_addr,
  10150. .ndo_do_ioctl = bnx2x_ioctl,
  10151. .ndo_change_mtu = bnx2x_change_mtu,
  10152. .ndo_fix_features = bnx2x_fix_features,
  10153. .ndo_set_features = bnx2x_set_features,
  10154. .ndo_tx_timeout = bnx2x_tx_timeout,
  10155. #ifdef CONFIG_NET_POLL_CONTROLLER
  10156. .ndo_poll_controller = poll_bnx2x,
  10157. #endif
  10158. .ndo_setup_tc = bnx2x_setup_tc,
  10159. #ifdef CONFIG_BNX2X_SRIOV
  10160. .ndo_set_vf_mac = bnx2x_set_vf_mac,
  10161. .ndo_set_vf_vlan = bnx2x_set_vf_vlan,
  10162. .ndo_get_vf_config = bnx2x_get_vf_config,
  10163. #endif
  10164. #ifdef NETDEV_FCOE_WWNN
  10165. .ndo_fcoe_get_wwn = bnx2x_fcoe_get_wwn,
  10166. #endif
  10167. #ifdef CONFIG_NET_RX_BUSY_POLL
  10168. .ndo_busy_poll = bnx2x_low_latency_recv,
  10169. #endif
  10170. };
  10171. static int bnx2x_set_coherency_mask(struct bnx2x *bp)
  10172. {
  10173. struct device *dev = &bp->pdev->dev;
  10174. if (dma_set_mask(dev, DMA_BIT_MASK(64)) == 0) {
  10175. bp->flags |= USING_DAC_FLAG;
  10176. if (dma_set_coherent_mask(dev, DMA_BIT_MASK(64)) != 0) {
  10177. dev_err(dev, "dma_set_coherent_mask failed, aborting\n");
  10178. return -EIO;
  10179. }
  10180. } else if (dma_set_mask(dev, DMA_BIT_MASK(32)) != 0) {
  10181. dev_err(dev, "System does not support DMA, aborting\n");
  10182. return -EIO;
  10183. }
  10184. return 0;
  10185. }
  10186. static int bnx2x_init_dev(struct bnx2x *bp, struct pci_dev *pdev,
  10187. struct net_device *dev, unsigned long board_type)
  10188. {
  10189. int rc;
  10190. u32 pci_cfg_dword;
  10191. bool chip_is_e1x = (board_type == BCM57710 ||
  10192. board_type == BCM57711 ||
  10193. board_type == BCM57711E);
  10194. SET_NETDEV_DEV(dev, &pdev->dev);
  10195. bp->dev = dev;
  10196. bp->pdev = pdev;
  10197. rc = pci_enable_device(pdev);
  10198. if (rc) {
  10199. dev_err(&bp->pdev->dev,
  10200. "Cannot enable PCI device, aborting\n");
  10201. goto err_out;
  10202. }
  10203. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  10204. dev_err(&bp->pdev->dev,
  10205. "Cannot find PCI device base address, aborting\n");
  10206. rc = -ENODEV;
  10207. goto err_out_disable;
  10208. }
  10209. if (IS_PF(bp) && !(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
  10210. dev_err(&bp->pdev->dev, "Cannot find second PCI device base address, aborting\n");
  10211. rc = -ENODEV;
  10212. goto err_out_disable;
  10213. }
  10214. pci_read_config_dword(pdev, PCICFG_REVISION_ID_OFFSET, &pci_cfg_dword);
  10215. if ((pci_cfg_dword & PCICFG_REVESION_ID_MASK) ==
  10216. PCICFG_REVESION_ID_ERROR_VAL) {
  10217. pr_err("PCI device error, probably due to fan failure, aborting\n");
  10218. rc = -ENODEV;
  10219. goto err_out_disable;
  10220. }
  10221. if (atomic_read(&pdev->enable_cnt) == 1) {
  10222. rc = pci_request_regions(pdev, DRV_MODULE_NAME);
  10223. if (rc) {
  10224. dev_err(&bp->pdev->dev,
  10225. "Cannot obtain PCI resources, aborting\n");
  10226. goto err_out_disable;
  10227. }
  10228. pci_set_master(pdev);
  10229. pci_save_state(pdev);
  10230. }
  10231. if (IS_PF(bp)) {
  10232. if (!pdev->pm_cap) {
  10233. dev_err(&bp->pdev->dev,
  10234. "Cannot find power management capability, aborting\n");
  10235. rc = -EIO;
  10236. goto err_out_release;
  10237. }
  10238. }
  10239. if (!pci_is_pcie(pdev)) {
  10240. dev_err(&bp->pdev->dev, "Not PCI Express, aborting\n");
  10241. rc = -EIO;
  10242. goto err_out_release;
  10243. }
  10244. rc = bnx2x_set_coherency_mask(bp);
  10245. if (rc)
  10246. goto err_out_release;
  10247. dev->mem_start = pci_resource_start(pdev, 0);
  10248. dev->base_addr = dev->mem_start;
  10249. dev->mem_end = pci_resource_end(pdev, 0);
  10250. dev->irq = pdev->irq;
  10251. bp->regview = pci_ioremap_bar(pdev, 0);
  10252. if (!bp->regview) {
  10253. dev_err(&bp->pdev->dev,
  10254. "Cannot map register space, aborting\n");
  10255. rc = -ENOMEM;
  10256. goto err_out_release;
  10257. }
  10258. /* In E1/E1H use pci device function given by kernel.
  10259. * In E2/E3 read physical function from ME register since these chips
  10260. * support Physical Device Assignment where kernel BDF maybe arbitrary
  10261. * (depending on hypervisor).
  10262. */
  10263. if (chip_is_e1x) {
  10264. bp->pf_num = PCI_FUNC(pdev->devfn);
  10265. } else {
  10266. /* chip is E2/3*/
  10267. pci_read_config_dword(bp->pdev,
  10268. PCICFG_ME_REGISTER, &pci_cfg_dword);
  10269. bp->pf_num = (u8)((pci_cfg_dword & ME_REG_ABS_PF_NUM) >>
  10270. ME_REG_ABS_PF_NUM_SHIFT);
  10271. }
  10272. BNX2X_DEV_INFO("me reg PF num: %d\n", bp->pf_num);
  10273. /* clean indirect addresses */
  10274. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  10275. PCICFG_VENDOR_ID_OFFSET);
  10276. /*
  10277. * Clean the following indirect addresses for all functions since it
  10278. * is not used by the driver.
  10279. */
  10280. if (IS_PF(bp)) {
  10281. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0, 0);
  10282. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0, 0);
  10283. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0, 0);
  10284. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0, 0);
  10285. if (chip_is_e1x) {
  10286. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F1, 0);
  10287. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F1, 0);
  10288. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F1, 0);
  10289. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F1, 0);
  10290. }
  10291. /* Enable internal target-read (in case we are probed after PF
  10292. * FLR). Must be done prior to any BAR read access. Only for
  10293. * 57712 and up
  10294. */
  10295. if (!chip_is_e1x)
  10296. REG_WR(bp,
  10297. PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  10298. }
  10299. dev->watchdog_timeo = TX_TIMEOUT;
  10300. dev->netdev_ops = &bnx2x_netdev_ops;
  10301. bnx2x_set_ethtool_ops(bp, dev);
  10302. dev->priv_flags |= IFF_UNICAST_FLT;
  10303. dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  10304. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
  10305. NETIF_F_RXCSUM | NETIF_F_LRO | NETIF_F_GRO |
  10306. NETIF_F_RXHASH | NETIF_F_HW_VLAN_CTAG_TX;
  10307. if (!CHIP_IS_E1x(bp)) {
  10308. dev->hw_features |= NETIF_F_GSO_GRE | NETIF_F_GSO_UDP_TUNNEL;
  10309. dev->hw_enc_features =
  10310. NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_SG |
  10311. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
  10312. NETIF_F_GSO_GRE | NETIF_F_GSO_UDP_TUNNEL;
  10313. }
  10314. dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  10315. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_HIGHDMA;
  10316. dev->features |= dev->hw_features | NETIF_F_HW_VLAN_CTAG_RX;
  10317. if (bp->flags & USING_DAC_FLAG)
  10318. dev->features |= NETIF_F_HIGHDMA;
  10319. /* Add Loopback capability to the device */
  10320. dev->hw_features |= NETIF_F_LOOPBACK;
  10321. #ifdef BCM_DCBNL
  10322. dev->dcbnl_ops = &bnx2x_dcbnl_ops;
  10323. #endif
  10324. /* get_port_hwinfo() will set prtad and mmds properly */
  10325. bp->mdio.prtad = MDIO_PRTAD_NONE;
  10326. bp->mdio.mmds = 0;
  10327. bp->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
  10328. bp->mdio.dev = dev;
  10329. bp->mdio.mdio_read = bnx2x_mdio_read;
  10330. bp->mdio.mdio_write = bnx2x_mdio_write;
  10331. return 0;
  10332. err_out_release:
  10333. if (atomic_read(&pdev->enable_cnt) == 1)
  10334. pci_release_regions(pdev);
  10335. err_out_disable:
  10336. pci_disable_device(pdev);
  10337. pci_set_drvdata(pdev, NULL);
  10338. err_out:
  10339. return rc;
  10340. }
  10341. static int bnx2x_check_firmware(struct bnx2x *bp)
  10342. {
  10343. const struct firmware *firmware = bp->firmware;
  10344. struct bnx2x_fw_file_hdr *fw_hdr;
  10345. struct bnx2x_fw_file_section *sections;
  10346. u32 offset, len, num_ops;
  10347. __be16 *ops_offsets;
  10348. int i;
  10349. const u8 *fw_ver;
  10350. if (firmware->size < sizeof(struct bnx2x_fw_file_hdr)) {
  10351. BNX2X_ERR("Wrong FW size\n");
  10352. return -EINVAL;
  10353. }
  10354. fw_hdr = (struct bnx2x_fw_file_hdr *)firmware->data;
  10355. sections = (struct bnx2x_fw_file_section *)fw_hdr;
  10356. /* Make sure none of the offsets and sizes make us read beyond
  10357. * the end of the firmware data */
  10358. for (i = 0; i < sizeof(*fw_hdr) / sizeof(*sections); i++) {
  10359. offset = be32_to_cpu(sections[i].offset);
  10360. len = be32_to_cpu(sections[i].len);
  10361. if (offset + len > firmware->size) {
  10362. BNX2X_ERR("Section %d length is out of bounds\n", i);
  10363. return -EINVAL;
  10364. }
  10365. }
  10366. /* Likewise for the init_ops offsets */
  10367. offset = be32_to_cpu(fw_hdr->init_ops_offsets.offset);
  10368. ops_offsets = (__force __be16 *)(firmware->data + offset);
  10369. num_ops = be32_to_cpu(fw_hdr->init_ops.len) / sizeof(struct raw_op);
  10370. for (i = 0; i < be32_to_cpu(fw_hdr->init_ops_offsets.len) / 2; i++) {
  10371. if (be16_to_cpu(ops_offsets[i]) > num_ops) {
  10372. BNX2X_ERR("Section offset %d is out of bounds\n", i);
  10373. return -EINVAL;
  10374. }
  10375. }
  10376. /* Check FW version */
  10377. offset = be32_to_cpu(fw_hdr->fw_version.offset);
  10378. fw_ver = firmware->data + offset;
  10379. if ((fw_ver[0] != BCM_5710_FW_MAJOR_VERSION) ||
  10380. (fw_ver[1] != BCM_5710_FW_MINOR_VERSION) ||
  10381. (fw_ver[2] != BCM_5710_FW_REVISION_VERSION) ||
  10382. (fw_ver[3] != BCM_5710_FW_ENGINEERING_VERSION)) {
  10383. BNX2X_ERR("Bad FW version:%d.%d.%d.%d. Should be %d.%d.%d.%d\n",
  10384. fw_ver[0], fw_ver[1], fw_ver[2], fw_ver[3],
  10385. BCM_5710_FW_MAJOR_VERSION,
  10386. BCM_5710_FW_MINOR_VERSION,
  10387. BCM_5710_FW_REVISION_VERSION,
  10388. BCM_5710_FW_ENGINEERING_VERSION);
  10389. return -EINVAL;
  10390. }
  10391. return 0;
  10392. }
  10393. static void be32_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  10394. {
  10395. const __be32 *source = (const __be32 *)_source;
  10396. u32 *target = (u32 *)_target;
  10397. u32 i;
  10398. for (i = 0; i < n/4; i++)
  10399. target[i] = be32_to_cpu(source[i]);
  10400. }
  10401. /*
  10402. Ops array is stored in the following format:
  10403. {op(8bit), offset(24bit, big endian), data(32bit, big endian)}
  10404. */
  10405. static void bnx2x_prep_ops(const u8 *_source, u8 *_target, u32 n)
  10406. {
  10407. const __be32 *source = (const __be32 *)_source;
  10408. struct raw_op *target = (struct raw_op *)_target;
  10409. u32 i, j, tmp;
  10410. for (i = 0, j = 0; i < n/8; i++, j += 2) {
  10411. tmp = be32_to_cpu(source[j]);
  10412. target[i].op = (tmp >> 24) & 0xff;
  10413. target[i].offset = tmp & 0xffffff;
  10414. target[i].raw_data = be32_to_cpu(source[j + 1]);
  10415. }
  10416. }
  10417. /* IRO array is stored in the following format:
  10418. * {base(24bit), m1(16bit), m2(16bit), m3(16bit), size(16bit) }
  10419. */
  10420. static void bnx2x_prep_iro(const u8 *_source, u8 *_target, u32 n)
  10421. {
  10422. const __be32 *source = (const __be32 *)_source;
  10423. struct iro *target = (struct iro *)_target;
  10424. u32 i, j, tmp;
  10425. for (i = 0, j = 0; i < n/sizeof(struct iro); i++) {
  10426. target[i].base = be32_to_cpu(source[j]);
  10427. j++;
  10428. tmp = be32_to_cpu(source[j]);
  10429. target[i].m1 = (tmp >> 16) & 0xffff;
  10430. target[i].m2 = tmp & 0xffff;
  10431. j++;
  10432. tmp = be32_to_cpu(source[j]);
  10433. target[i].m3 = (tmp >> 16) & 0xffff;
  10434. target[i].size = tmp & 0xffff;
  10435. j++;
  10436. }
  10437. }
  10438. static void be16_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  10439. {
  10440. const __be16 *source = (const __be16 *)_source;
  10441. u16 *target = (u16 *)_target;
  10442. u32 i;
  10443. for (i = 0; i < n/2; i++)
  10444. target[i] = be16_to_cpu(source[i]);
  10445. }
  10446. #define BNX2X_ALLOC_AND_SET(arr, lbl, func) \
  10447. do { \
  10448. u32 len = be32_to_cpu(fw_hdr->arr.len); \
  10449. bp->arr = kmalloc(len, GFP_KERNEL); \
  10450. if (!bp->arr) \
  10451. goto lbl; \
  10452. func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \
  10453. (u8 *)bp->arr, len); \
  10454. } while (0)
  10455. static int bnx2x_init_firmware(struct bnx2x *bp)
  10456. {
  10457. const char *fw_file_name;
  10458. struct bnx2x_fw_file_hdr *fw_hdr;
  10459. int rc;
  10460. if (bp->firmware)
  10461. return 0;
  10462. if (CHIP_IS_E1(bp))
  10463. fw_file_name = FW_FILE_NAME_E1;
  10464. else if (CHIP_IS_E1H(bp))
  10465. fw_file_name = FW_FILE_NAME_E1H;
  10466. else if (!CHIP_IS_E1x(bp))
  10467. fw_file_name = FW_FILE_NAME_E2;
  10468. else {
  10469. BNX2X_ERR("Unsupported chip revision\n");
  10470. return -EINVAL;
  10471. }
  10472. BNX2X_DEV_INFO("Loading %s\n", fw_file_name);
  10473. rc = request_firmware(&bp->firmware, fw_file_name, &bp->pdev->dev);
  10474. if (rc) {
  10475. BNX2X_ERR("Can't load firmware file %s\n",
  10476. fw_file_name);
  10477. goto request_firmware_exit;
  10478. }
  10479. rc = bnx2x_check_firmware(bp);
  10480. if (rc) {
  10481. BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name);
  10482. goto request_firmware_exit;
  10483. }
  10484. fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data;
  10485. /* Initialize the pointers to the init arrays */
  10486. /* Blob */
  10487. BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n);
  10488. /* Opcodes */
  10489. BNX2X_ALLOC_AND_SET(init_ops, init_ops_alloc_err, bnx2x_prep_ops);
  10490. /* Offsets */
  10491. BNX2X_ALLOC_AND_SET(init_ops_offsets, init_offsets_alloc_err,
  10492. be16_to_cpu_n);
  10493. /* STORMs firmware */
  10494. INIT_TSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10495. be32_to_cpu(fw_hdr->tsem_int_table_data.offset);
  10496. INIT_TSEM_PRAM_DATA(bp) = bp->firmware->data +
  10497. be32_to_cpu(fw_hdr->tsem_pram_data.offset);
  10498. INIT_USEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10499. be32_to_cpu(fw_hdr->usem_int_table_data.offset);
  10500. INIT_USEM_PRAM_DATA(bp) = bp->firmware->data +
  10501. be32_to_cpu(fw_hdr->usem_pram_data.offset);
  10502. INIT_XSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10503. be32_to_cpu(fw_hdr->xsem_int_table_data.offset);
  10504. INIT_XSEM_PRAM_DATA(bp) = bp->firmware->data +
  10505. be32_to_cpu(fw_hdr->xsem_pram_data.offset);
  10506. INIT_CSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10507. be32_to_cpu(fw_hdr->csem_int_table_data.offset);
  10508. INIT_CSEM_PRAM_DATA(bp) = bp->firmware->data +
  10509. be32_to_cpu(fw_hdr->csem_pram_data.offset);
  10510. /* IRO */
  10511. BNX2X_ALLOC_AND_SET(iro_arr, iro_alloc_err, bnx2x_prep_iro);
  10512. return 0;
  10513. iro_alloc_err:
  10514. kfree(bp->init_ops_offsets);
  10515. init_offsets_alloc_err:
  10516. kfree(bp->init_ops);
  10517. init_ops_alloc_err:
  10518. kfree(bp->init_data);
  10519. request_firmware_exit:
  10520. release_firmware(bp->firmware);
  10521. bp->firmware = NULL;
  10522. return rc;
  10523. }
  10524. static void bnx2x_release_firmware(struct bnx2x *bp)
  10525. {
  10526. kfree(bp->init_ops_offsets);
  10527. kfree(bp->init_ops);
  10528. kfree(bp->init_data);
  10529. release_firmware(bp->firmware);
  10530. bp->firmware = NULL;
  10531. }
  10532. static struct bnx2x_func_sp_drv_ops bnx2x_func_sp_drv = {
  10533. .init_hw_cmn_chip = bnx2x_init_hw_common_chip,
  10534. .init_hw_cmn = bnx2x_init_hw_common,
  10535. .init_hw_port = bnx2x_init_hw_port,
  10536. .init_hw_func = bnx2x_init_hw_func,
  10537. .reset_hw_cmn = bnx2x_reset_common,
  10538. .reset_hw_port = bnx2x_reset_port,
  10539. .reset_hw_func = bnx2x_reset_func,
  10540. .gunzip_init = bnx2x_gunzip_init,
  10541. .gunzip_end = bnx2x_gunzip_end,
  10542. .init_fw = bnx2x_init_firmware,
  10543. .release_fw = bnx2x_release_firmware,
  10544. };
  10545. void bnx2x__init_func_obj(struct bnx2x *bp)
  10546. {
  10547. /* Prepare DMAE related driver resources */
  10548. bnx2x_setup_dmae(bp);
  10549. bnx2x_init_func_obj(bp, &bp->func_obj,
  10550. bnx2x_sp(bp, func_rdata),
  10551. bnx2x_sp_mapping(bp, func_rdata),
  10552. bnx2x_sp(bp, func_afex_rdata),
  10553. bnx2x_sp_mapping(bp, func_afex_rdata),
  10554. &bnx2x_func_sp_drv);
  10555. }
  10556. /* must be called after sriov-enable */
  10557. static int bnx2x_set_qm_cid_count(struct bnx2x *bp)
  10558. {
  10559. int cid_count = BNX2X_L2_MAX_CID(bp);
  10560. if (IS_SRIOV(bp))
  10561. cid_count += BNX2X_VF_CIDS;
  10562. if (CNIC_SUPPORT(bp))
  10563. cid_count += CNIC_CID_MAX;
  10564. return roundup(cid_count, QM_CID_ROUND);
  10565. }
  10566. /**
  10567. * bnx2x_get_num_none_def_sbs - return the number of none default SBs
  10568. *
  10569. * @dev: pci device
  10570. *
  10571. */
  10572. static int bnx2x_get_num_non_def_sbs(struct pci_dev *pdev, int cnic_cnt)
  10573. {
  10574. int index;
  10575. u16 control = 0;
  10576. /*
  10577. * If MSI-X is not supported - return number of SBs needed to support
  10578. * one fast path queue: one FP queue + SB for CNIC
  10579. */
  10580. if (!pdev->msix_cap) {
  10581. dev_info(&pdev->dev, "no msix capability found\n");
  10582. return 1 + cnic_cnt;
  10583. }
  10584. dev_info(&pdev->dev, "msix capability found\n");
  10585. /*
  10586. * The value in the PCI configuration space is the index of the last
  10587. * entry, namely one less than the actual size of the table, which is
  10588. * exactly what we want to return from this function: number of all SBs
  10589. * without the default SB.
  10590. * For VFs there is no default SB, then we return (index+1).
  10591. */
  10592. pci_read_config_word(pdev, pdev->msix_cap + PCI_MSI_FLAGS, &control);
  10593. index = control & PCI_MSIX_FLAGS_QSIZE;
  10594. return index;
  10595. }
  10596. static int set_max_cos_est(int chip_id)
  10597. {
  10598. switch (chip_id) {
  10599. case BCM57710:
  10600. case BCM57711:
  10601. case BCM57711E:
  10602. return BNX2X_MULTI_TX_COS_E1X;
  10603. case BCM57712:
  10604. case BCM57712_MF:
  10605. case BCM57712_VF:
  10606. return BNX2X_MULTI_TX_COS_E2_E3A0;
  10607. case BCM57800:
  10608. case BCM57800_MF:
  10609. case BCM57800_VF:
  10610. case BCM57810:
  10611. case BCM57810_MF:
  10612. case BCM57840_4_10:
  10613. case BCM57840_2_20:
  10614. case BCM57840_O:
  10615. case BCM57840_MFO:
  10616. case BCM57810_VF:
  10617. case BCM57840_MF:
  10618. case BCM57840_VF:
  10619. case BCM57811:
  10620. case BCM57811_MF:
  10621. case BCM57811_VF:
  10622. return BNX2X_MULTI_TX_COS_E3B0;
  10623. return 1;
  10624. default:
  10625. pr_err("Unknown board_type (%d), aborting\n", chip_id);
  10626. return -ENODEV;
  10627. }
  10628. }
  10629. static int set_is_vf(int chip_id)
  10630. {
  10631. switch (chip_id) {
  10632. case BCM57712_VF:
  10633. case BCM57800_VF:
  10634. case BCM57810_VF:
  10635. case BCM57840_VF:
  10636. case BCM57811_VF:
  10637. return true;
  10638. default:
  10639. return false;
  10640. }
  10641. }
  10642. struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev);
  10643. static int bnx2x_init_one(struct pci_dev *pdev,
  10644. const struct pci_device_id *ent)
  10645. {
  10646. struct net_device *dev = NULL;
  10647. struct bnx2x *bp;
  10648. enum pcie_link_width pcie_width;
  10649. enum pci_bus_speed pcie_speed;
  10650. int rc, max_non_def_sbs;
  10651. int rx_count, tx_count, rss_count, doorbell_size;
  10652. int max_cos_est;
  10653. bool is_vf;
  10654. int cnic_cnt;
  10655. /* An estimated maximum supported CoS number according to the chip
  10656. * version.
  10657. * We will try to roughly estimate the maximum number of CoSes this chip
  10658. * may support in order to minimize the memory allocated for Tx
  10659. * netdev_queue's. This number will be accurately calculated during the
  10660. * initialization of bp->max_cos based on the chip versions AND chip
  10661. * revision in the bnx2x_init_bp().
  10662. */
  10663. max_cos_est = set_max_cos_est(ent->driver_data);
  10664. if (max_cos_est < 0)
  10665. return max_cos_est;
  10666. is_vf = set_is_vf(ent->driver_data);
  10667. cnic_cnt = is_vf ? 0 : 1;
  10668. max_non_def_sbs = bnx2x_get_num_non_def_sbs(pdev, cnic_cnt);
  10669. /* add another SB for VF as it has no default SB */
  10670. max_non_def_sbs += is_vf ? 1 : 0;
  10671. /* Maximum number of RSS queues: one IGU SB goes to CNIC */
  10672. rss_count = max_non_def_sbs - cnic_cnt;
  10673. if (rss_count < 1)
  10674. return -EINVAL;
  10675. /* Maximum number of netdev Rx queues: RSS + FCoE L2 */
  10676. rx_count = rss_count + cnic_cnt;
  10677. /* Maximum number of netdev Tx queues:
  10678. * Maximum TSS queues * Maximum supported number of CoS + FCoE L2
  10679. */
  10680. tx_count = rss_count * max_cos_est + cnic_cnt;
  10681. /* dev zeroed in init_etherdev */
  10682. dev = alloc_etherdev_mqs(sizeof(*bp), tx_count, rx_count);
  10683. if (!dev)
  10684. return -ENOMEM;
  10685. bp = netdev_priv(dev);
  10686. bp->flags = 0;
  10687. if (is_vf)
  10688. bp->flags |= IS_VF_FLAG;
  10689. bp->igu_sb_cnt = max_non_def_sbs;
  10690. bp->igu_base_addr = IS_VF(bp) ? PXP_VF_ADDR_IGU_START : BAR_IGU_INTMEM;
  10691. bp->msg_enable = debug;
  10692. bp->cnic_support = cnic_cnt;
  10693. bp->cnic_probe = bnx2x_cnic_probe;
  10694. pci_set_drvdata(pdev, dev);
  10695. rc = bnx2x_init_dev(bp, pdev, dev, ent->driver_data);
  10696. if (rc < 0) {
  10697. free_netdev(dev);
  10698. return rc;
  10699. }
  10700. BNX2X_DEV_INFO("This is a %s function\n",
  10701. IS_PF(bp) ? "physical" : "virtual");
  10702. BNX2X_DEV_INFO("Cnic support is %s\n", CNIC_SUPPORT(bp) ? "on" : "off");
  10703. BNX2X_DEV_INFO("Max num of status blocks %d\n", max_non_def_sbs);
  10704. BNX2X_DEV_INFO("Allocated netdev with %d tx and %d rx queues\n",
  10705. tx_count, rx_count);
  10706. rc = bnx2x_init_bp(bp);
  10707. if (rc)
  10708. goto init_one_exit;
  10709. /* Map doorbells here as we need the real value of bp->max_cos which
  10710. * is initialized in bnx2x_init_bp() to determine the number of
  10711. * l2 connections.
  10712. */
  10713. if (IS_VF(bp)) {
  10714. bp->doorbells = bnx2x_vf_doorbells(bp);
  10715. rc = bnx2x_vf_pci_alloc(bp);
  10716. if (rc)
  10717. goto init_one_exit;
  10718. } else {
  10719. doorbell_size = BNX2X_L2_MAX_CID(bp) * (1 << BNX2X_DB_SHIFT);
  10720. if (doorbell_size > pci_resource_len(pdev, 2)) {
  10721. dev_err(&bp->pdev->dev,
  10722. "Cannot map doorbells, bar size too small, aborting\n");
  10723. rc = -ENOMEM;
  10724. goto init_one_exit;
  10725. }
  10726. bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2),
  10727. doorbell_size);
  10728. }
  10729. if (!bp->doorbells) {
  10730. dev_err(&bp->pdev->dev,
  10731. "Cannot map doorbell space, aborting\n");
  10732. rc = -ENOMEM;
  10733. goto init_one_exit;
  10734. }
  10735. if (IS_VF(bp)) {
  10736. rc = bnx2x_vfpf_acquire(bp, tx_count, rx_count);
  10737. if (rc)
  10738. goto init_one_exit;
  10739. }
  10740. /* Enable SRIOV if capability found in configuration space */
  10741. rc = bnx2x_iov_init_one(bp, int_mode, BNX2X_MAX_NUM_OF_VFS);
  10742. if (rc)
  10743. goto init_one_exit;
  10744. /* calc qm_cid_count */
  10745. bp->qm_cid_count = bnx2x_set_qm_cid_count(bp);
  10746. BNX2X_DEV_INFO("qm_cid_count %d\n", bp->qm_cid_count);
  10747. /* disable FCOE L2 queue for E1x*/
  10748. if (CHIP_IS_E1x(bp))
  10749. bp->flags |= NO_FCOE_FLAG;
  10750. /* Set bp->num_queues for MSI-X mode*/
  10751. bnx2x_set_num_queues(bp);
  10752. /* Configure interrupt mode: try to enable MSI-X/MSI if
  10753. * needed.
  10754. */
  10755. rc = bnx2x_set_int_mode(bp);
  10756. if (rc) {
  10757. dev_err(&pdev->dev, "Cannot set interrupts\n");
  10758. goto init_one_exit;
  10759. }
  10760. BNX2X_DEV_INFO("set interrupts successfully\n");
  10761. /* register the net device */
  10762. rc = register_netdev(dev);
  10763. if (rc) {
  10764. dev_err(&pdev->dev, "Cannot register net device\n");
  10765. goto init_one_exit;
  10766. }
  10767. BNX2X_DEV_INFO("device name after netdev register %s\n", dev->name);
  10768. if (!NO_FCOE(bp)) {
  10769. /* Add storage MAC address */
  10770. rtnl_lock();
  10771. dev_addr_add(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  10772. rtnl_unlock();
  10773. }
  10774. if (pcie_get_minimum_link(bp->pdev, &pcie_speed, &pcie_width) ||
  10775. pcie_speed == PCI_SPEED_UNKNOWN ||
  10776. pcie_width == PCIE_LNK_WIDTH_UNKNOWN)
  10777. BNX2X_DEV_INFO("Failed to determine PCI Express Bandwidth\n");
  10778. else
  10779. BNX2X_DEV_INFO(
  10780. "%s (%c%d) PCI-E x%d %s found at mem %lx, IRQ %d, node addr %pM\n",
  10781. board_info[ent->driver_data].name,
  10782. (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4),
  10783. pcie_width,
  10784. pcie_speed == PCIE_SPEED_2_5GT ? "2.5GHz" :
  10785. pcie_speed == PCIE_SPEED_5_0GT ? "5.0GHz" :
  10786. pcie_speed == PCIE_SPEED_8_0GT ? "8.0GHz" :
  10787. "Unknown",
  10788. dev->base_addr, bp->pdev->irq, dev->dev_addr);
  10789. return 0;
  10790. init_one_exit:
  10791. if (bp->regview)
  10792. iounmap(bp->regview);
  10793. if (IS_PF(bp) && bp->doorbells)
  10794. iounmap(bp->doorbells);
  10795. free_netdev(dev);
  10796. if (atomic_read(&pdev->enable_cnt) == 1)
  10797. pci_release_regions(pdev);
  10798. pci_disable_device(pdev);
  10799. pci_set_drvdata(pdev, NULL);
  10800. return rc;
  10801. }
  10802. static void __bnx2x_remove(struct pci_dev *pdev,
  10803. struct net_device *dev,
  10804. struct bnx2x *bp,
  10805. bool remove_netdev)
  10806. {
  10807. /* Delete storage MAC address */
  10808. if (!NO_FCOE(bp)) {
  10809. rtnl_lock();
  10810. dev_addr_del(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  10811. rtnl_unlock();
  10812. }
  10813. #ifdef BCM_DCBNL
  10814. /* Delete app tlvs from dcbnl */
  10815. bnx2x_dcbnl_update_applist(bp, true);
  10816. #endif
  10817. if (IS_PF(bp) &&
  10818. !BP_NOMCP(bp) &&
  10819. (bp->flags & BC_SUPPORTS_RMMOD_CMD))
  10820. bnx2x_fw_command(bp, DRV_MSG_CODE_RMMOD, 0);
  10821. /* Close the interface - either directly or implicitly */
  10822. if (remove_netdev) {
  10823. unregister_netdev(dev);
  10824. } else {
  10825. rtnl_lock();
  10826. dev_close(dev);
  10827. rtnl_unlock();
  10828. }
  10829. bnx2x_iov_remove_one(bp);
  10830. /* Power on: we can't let PCI layer write to us while we are in D3 */
  10831. if (IS_PF(bp))
  10832. bnx2x_set_power_state(bp, PCI_D0);
  10833. /* Disable MSI/MSI-X */
  10834. bnx2x_disable_msi(bp);
  10835. /* Power off */
  10836. if (IS_PF(bp))
  10837. bnx2x_set_power_state(bp, PCI_D3hot);
  10838. /* Make sure RESET task is not scheduled before continuing */
  10839. cancel_delayed_work_sync(&bp->sp_rtnl_task);
  10840. /* send message via vfpf channel to release the resources of this vf */
  10841. if (IS_VF(bp))
  10842. bnx2x_vfpf_release(bp);
  10843. /* Assumes no further PCIe PM changes will occur */
  10844. if (system_state == SYSTEM_POWER_OFF) {
  10845. pci_wake_from_d3(pdev, bp->wol);
  10846. pci_set_power_state(pdev, PCI_D3hot);
  10847. }
  10848. if (bp->regview)
  10849. iounmap(bp->regview);
  10850. /* for vf doorbells are part of the regview and were unmapped along with
  10851. * it. FW is only loaded by PF.
  10852. */
  10853. if (IS_PF(bp)) {
  10854. if (bp->doorbells)
  10855. iounmap(bp->doorbells);
  10856. bnx2x_release_firmware(bp);
  10857. }
  10858. bnx2x_free_mem_bp(bp);
  10859. if (remove_netdev)
  10860. free_netdev(dev);
  10861. if (atomic_read(&pdev->enable_cnt) == 1)
  10862. pci_release_regions(pdev);
  10863. pci_disable_device(pdev);
  10864. pci_set_drvdata(pdev, NULL);
  10865. }
  10866. static void bnx2x_remove_one(struct pci_dev *pdev)
  10867. {
  10868. struct net_device *dev = pci_get_drvdata(pdev);
  10869. struct bnx2x *bp;
  10870. if (!dev) {
  10871. dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n");
  10872. return;
  10873. }
  10874. bp = netdev_priv(dev);
  10875. __bnx2x_remove(pdev, dev, bp, true);
  10876. }
  10877. static int bnx2x_eeh_nic_unload(struct bnx2x *bp)
  10878. {
  10879. bp->state = BNX2X_STATE_CLOSING_WAIT4_HALT;
  10880. bp->rx_mode = BNX2X_RX_MODE_NONE;
  10881. if (CNIC_LOADED(bp))
  10882. bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD);
  10883. /* Stop Tx */
  10884. bnx2x_tx_disable(bp);
  10885. /* Delete all NAPI objects */
  10886. bnx2x_del_all_napi(bp);
  10887. if (CNIC_LOADED(bp))
  10888. bnx2x_del_all_napi_cnic(bp);
  10889. netdev_reset_tc(bp->dev);
  10890. del_timer_sync(&bp->timer);
  10891. cancel_delayed_work(&bp->sp_task);
  10892. cancel_delayed_work(&bp->period_task);
  10893. spin_lock_bh(&bp->stats_lock);
  10894. bp->stats_state = STATS_STATE_DISABLED;
  10895. spin_unlock_bh(&bp->stats_lock);
  10896. bnx2x_save_statistics(bp);
  10897. netif_carrier_off(bp->dev);
  10898. return 0;
  10899. }
  10900. /**
  10901. * bnx2x_io_error_detected - called when PCI error is detected
  10902. * @pdev: Pointer to PCI device
  10903. * @state: The current pci connection state
  10904. *
  10905. * This function is called after a PCI bus error affecting
  10906. * this device has been detected.
  10907. */
  10908. static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev,
  10909. pci_channel_state_t state)
  10910. {
  10911. struct net_device *dev = pci_get_drvdata(pdev);
  10912. struct bnx2x *bp = netdev_priv(dev);
  10913. rtnl_lock();
  10914. BNX2X_ERR("IO error detected\n");
  10915. netif_device_detach(dev);
  10916. if (state == pci_channel_io_perm_failure) {
  10917. rtnl_unlock();
  10918. return PCI_ERS_RESULT_DISCONNECT;
  10919. }
  10920. if (netif_running(dev))
  10921. bnx2x_eeh_nic_unload(bp);
  10922. bnx2x_prev_path_mark_eeh(bp);
  10923. pci_disable_device(pdev);
  10924. rtnl_unlock();
  10925. /* Request a slot reset */
  10926. return PCI_ERS_RESULT_NEED_RESET;
  10927. }
  10928. /**
  10929. * bnx2x_io_slot_reset - called after the PCI bus has been reset
  10930. * @pdev: Pointer to PCI device
  10931. *
  10932. * Restart the card from scratch, as if from a cold-boot.
  10933. */
  10934. static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev)
  10935. {
  10936. struct net_device *dev = pci_get_drvdata(pdev);
  10937. struct bnx2x *bp = netdev_priv(dev);
  10938. int i;
  10939. rtnl_lock();
  10940. BNX2X_ERR("IO slot reset initializing...\n");
  10941. if (pci_enable_device(pdev)) {
  10942. dev_err(&pdev->dev,
  10943. "Cannot re-enable PCI device after reset\n");
  10944. rtnl_unlock();
  10945. return PCI_ERS_RESULT_DISCONNECT;
  10946. }
  10947. pci_set_master(pdev);
  10948. pci_restore_state(pdev);
  10949. pci_save_state(pdev);
  10950. if (netif_running(dev))
  10951. bnx2x_set_power_state(bp, PCI_D0);
  10952. if (netif_running(dev)) {
  10953. BNX2X_ERR("IO slot reset --> driver unload\n");
  10954. /* MCP should have been reset; Need to wait for validity */
  10955. bnx2x_init_shmem(bp);
  10956. if (IS_PF(bp) && SHMEM2_HAS(bp, drv_capabilities_flag)) {
  10957. u32 v;
  10958. v = SHMEM2_RD(bp,
  10959. drv_capabilities_flag[BP_FW_MB_IDX(bp)]);
  10960. SHMEM2_WR(bp, drv_capabilities_flag[BP_FW_MB_IDX(bp)],
  10961. v & ~DRV_FLAGS_CAPABILITIES_LOADED_L2);
  10962. }
  10963. bnx2x_drain_tx_queues(bp);
  10964. bnx2x_send_unload_req(bp, UNLOAD_RECOVERY);
  10965. bnx2x_netif_stop(bp, 1);
  10966. bnx2x_free_irq(bp);
  10967. /* Report UNLOAD_DONE to MCP */
  10968. bnx2x_send_unload_done(bp, true);
  10969. bp->sp_state = 0;
  10970. bp->port.pmf = 0;
  10971. bnx2x_prev_unload(bp);
  10972. /* We should have reseted the engine, so It's fair to
  10973. * assume the FW will no longer write to the bnx2x driver.
  10974. */
  10975. bnx2x_squeeze_objects(bp);
  10976. bnx2x_free_skbs(bp);
  10977. for_each_rx_queue(bp, i)
  10978. bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
  10979. bnx2x_free_fp_mem(bp);
  10980. bnx2x_free_mem(bp);
  10981. bp->state = BNX2X_STATE_CLOSED;
  10982. }
  10983. rtnl_unlock();
  10984. return PCI_ERS_RESULT_RECOVERED;
  10985. }
  10986. /**
  10987. * bnx2x_io_resume - called when traffic can start flowing again
  10988. * @pdev: Pointer to PCI device
  10989. *
  10990. * This callback is called when the error recovery driver tells us that
  10991. * its OK to resume normal operation.
  10992. */
  10993. static void bnx2x_io_resume(struct pci_dev *pdev)
  10994. {
  10995. struct net_device *dev = pci_get_drvdata(pdev);
  10996. struct bnx2x *bp = netdev_priv(dev);
  10997. if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
  10998. netdev_err(bp->dev, "Handling parity error recovery. Try again later\n");
  10999. return;
  11000. }
  11001. rtnl_lock();
  11002. bp->fw_seq = SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
  11003. DRV_MSG_SEQ_NUMBER_MASK;
  11004. if (netif_running(dev))
  11005. bnx2x_nic_load(bp, LOAD_NORMAL);
  11006. netif_device_attach(dev);
  11007. rtnl_unlock();
  11008. }
  11009. static const struct pci_error_handlers bnx2x_err_handler = {
  11010. .error_detected = bnx2x_io_error_detected,
  11011. .slot_reset = bnx2x_io_slot_reset,
  11012. .resume = bnx2x_io_resume,
  11013. };
  11014. static void bnx2x_shutdown(struct pci_dev *pdev)
  11015. {
  11016. struct net_device *dev = pci_get_drvdata(pdev);
  11017. struct bnx2x *bp;
  11018. if (!dev)
  11019. return;
  11020. bp = netdev_priv(dev);
  11021. if (!bp)
  11022. return;
  11023. rtnl_lock();
  11024. netif_device_detach(dev);
  11025. rtnl_unlock();
  11026. /* Don't remove the netdevice, as there are scenarios which will cause
  11027. * the kernel to hang, e.g., when trying to remove bnx2i while the
  11028. * rootfs is mounted from SAN.
  11029. */
  11030. __bnx2x_remove(pdev, dev, bp, false);
  11031. }
  11032. static struct pci_driver bnx2x_pci_driver = {
  11033. .name = DRV_MODULE_NAME,
  11034. .id_table = bnx2x_pci_tbl,
  11035. .probe = bnx2x_init_one,
  11036. .remove = bnx2x_remove_one,
  11037. .suspend = bnx2x_suspend,
  11038. .resume = bnx2x_resume,
  11039. .err_handler = &bnx2x_err_handler,
  11040. #ifdef CONFIG_BNX2X_SRIOV
  11041. .sriov_configure = bnx2x_sriov_configure,
  11042. #endif
  11043. .shutdown = bnx2x_shutdown,
  11044. };
  11045. static int __init bnx2x_init(void)
  11046. {
  11047. int ret;
  11048. pr_info("%s", version);
  11049. bnx2x_wq = create_singlethread_workqueue("bnx2x");
  11050. if (bnx2x_wq == NULL) {
  11051. pr_err("Cannot create workqueue\n");
  11052. return -ENOMEM;
  11053. }
  11054. ret = pci_register_driver(&bnx2x_pci_driver);
  11055. if (ret) {
  11056. pr_err("Cannot register driver\n");
  11057. destroy_workqueue(bnx2x_wq);
  11058. }
  11059. return ret;
  11060. }
  11061. static void __exit bnx2x_cleanup(void)
  11062. {
  11063. struct list_head *pos, *q;
  11064. pci_unregister_driver(&bnx2x_pci_driver);
  11065. destroy_workqueue(bnx2x_wq);
  11066. /* Free globally allocated resources */
  11067. list_for_each_safe(pos, q, &bnx2x_prev_list) {
  11068. struct bnx2x_prev_path_list *tmp =
  11069. list_entry(pos, struct bnx2x_prev_path_list, list);
  11070. list_del(pos);
  11071. kfree(tmp);
  11072. }
  11073. }
  11074. void bnx2x_notify_link_changed(struct bnx2x *bp)
  11075. {
  11076. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + BP_FUNC(bp)*sizeof(u32), 1);
  11077. }
  11078. module_init(bnx2x_init);
  11079. module_exit(bnx2x_cleanup);
  11080. /**
  11081. * bnx2x_set_iscsi_eth_mac_addr - set iSCSI MAC(s).
  11082. *
  11083. * @bp: driver handle
  11084. * @set: set or clear the CAM entry
  11085. *
  11086. * This function will wait until the ramrod completion returns.
  11087. * Return 0 if success, -ENODEV if ramrod doesn't return.
  11088. */
  11089. static int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp)
  11090. {
  11091. unsigned long ramrod_flags = 0;
  11092. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  11093. return bnx2x_set_mac_one(bp, bp->cnic_eth_dev.iscsi_mac,
  11094. &bp->iscsi_l2_mac_obj, true,
  11095. BNX2X_ISCSI_ETH_MAC, &ramrod_flags);
  11096. }
  11097. /* count denotes the number of new completions we have seen */
  11098. static void bnx2x_cnic_sp_post(struct bnx2x *bp, int count)
  11099. {
  11100. struct eth_spe *spe;
  11101. int cxt_index, cxt_offset;
  11102. #ifdef BNX2X_STOP_ON_ERROR
  11103. if (unlikely(bp->panic))
  11104. return;
  11105. #endif
  11106. spin_lock_bh(&bp->spq_lock);
  11107. BUG_ON(bp->cnic_spq_pending < count);
  11108. bp->cnic_spq_pending -= count;
  11109. for (; bp->cnic_kwq_pending; bp->cnic_kwq_pending--) {
  11110. u16 type = (le16_to_cpu(bp->cnic_kwq_cons->hdr.type)
  11111. & SPE_HDR_CONN_TYPE) >>
  11112. SPE_HDR_CONN_TYPE_SHIFT;
  11113. u8 cmd = (le32_to_cpu(bp->cnic_kwq_cons->hdr.conn_and_cmd_data)
  11114. >> SPE_HDR_CMD_ID_SHIFT) & 0xff;
  11115. /* Set validation for iSCSI L2 client before sending SETUP
  11116. * ramrod
  11117. */
  11118. if (type == ETH_CONNECTION_TYPE) {
  11119. if (cmd == RAMROD_CMD_ID_ETH_CLIENT_SETUP) {
  11120. cxt_index = BNX2X_ISCSI_ETH_CID(bp) /
  11121. ILT_PAGE_CIDS;
  11122. cxt_offset = BNX2X_ISCSI_ETH_CID(bp) -
  11123. (cxt_index * ILT_PAGE_CIDS);
  11124. bnx2x_set_ctx_validation(bp,
  11125. &bp->context[cxt_index].
  11126. vcxt[cxt_offset].eth,
  11127. BNX2X_ISCSI_ETH_CID(bp));
  11128. }
  11129. }
  11130. /*
  11131. * There may be not more than 8 L2, not more than 8 L5 SPEs
  11132. * and in the air. We also check that number of outstanding
  11133. * COMMON ramrods is not more than the EQ and SPQ can
  11134. * accommodate.
  11135. */
  11136. if (type == ETH_CONNECTION_TYPE) {
  11137. if (!atomic_read(&bp->cq_spq_left))
  11138. break;
  11139. else
  11140. atomic_dec(&bp->cq_spq_left);
  11141. } else if (type == NONE_CONNECTION_TYPE) {
  11142. if (!atomic_read(&bp->eq_spq_left))
  11143. break;
  11144. else
  11145. atomic_dec(&bp->eq_spq_left);
  11146. } else if ((type == ISCSI_CONNECTION_TYPE) ||
  11147. (type == FCOE_CONNECTION_TYPE)) {
  11148. if (bp->cnic_spq_pending >=
  11149. bp->cnic_eth_dev.max_kwqe_pending)
  11150. break;
  11151. else
  11152. bp->cnic_spq_pending++;
  11153. } else {
  11154. BNX2X_ERR("Unknown SPE type: %d\n", type);
  11155. bnx2x_panic();
  11156. break;
  11157. }
  11158. spe = bnx2x_sp_get_next(bp);
  11159. *spe = *bp->cnic_kwq_cons;
  11160. DP(BNX2X_MSG_SP, "pending on SPQ %d, on KWQ %d count %d\n",
  11161. bp->cnic_spq_pending, bp->cnic_kwq_pending, count);
  11162. if (bp->cnic_kwq_cons == bp->cnic_kwq_last)
  11163. bp->cnic_kwq_cons = bp->cnic_kwq;
  11164. else
  11165. bp->cnic_kwq_cons++;
  11166. }
  11167. bnx2x_sp_prod_update(bp);
  11168. spin_unlock_bh(&bp->spq_lock);
  11169. }
  11170. static int bnx2x_cnic_sp_queue(struct net_device *dev,
  11171. struct kwqe_16 *kwqes[], u32 count)
  11172. {
  11173. struct bnx2x *bp = netdev_priv(dev);
  11174. int i;
  11175. #ifdef BNX2X_STOP_ON_ERROR
  11176. if (unlikely(bp->panic)) {
  11177. BNX2X_ERR("Can't post to SP queue while panic\n");
  11178. return -EIO;
  11179. }
  11180. #endif
  11181. if ((bp->recovery_state != BNX2X_RECOVERY_DONE) &&
  11182. (bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  11183. BNX2X_ERR("Handling parity error recovery. Try again later\n");
  11184. return -EAGAIN;
  11185. }
  11186. spin_lock_bh(&bp->spq_lock);
  11187. for (i = 0; i < count; i++) {
  11188. struct eth_spe *spe = (struct eth_spe *)kwqes[i];
  11189. if (bp->cnic_kwq_pending == MAX_SP_DESC_CNT)
  11190. break;
  11191. *bp->cnic_kwq_prod = *spe;
  11192. bp->cnic_kwq_pending++;
  11193. DP(BNX2X_MSG_SP, "L5 SPQE %x %x %x:%x pos %d\n",
  11194. spe->hdr.conn_and_cmd_data, spe->hdr.type,
  11195. spe->data.update_data_addr.hi,
  11196. spe->data.update_data_addr.lo,
  11197. bp->cnic_kwq_pending);
  11198. if (bp->cnic_kwq_prod == bp->cnic_kwq_last)
  11199. bp->cnic_kwq_prod = bp->cnic_kwq;
  11200. else
  11201. bp->cnic_kwq_prod++;
  11202. }
  11203. spin_unlock_bh(&bp->spq_lock);
  11204. if (bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending)
  11205. bnx2x_cnic_sp_post(bp, 0);
  11206. return i;
  11207. }
  11208. static int bnx2x_cnic_ctl_send(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  11209. {
  11210. struct cnic_ops *c_ops;
  11211. int rc = 0;
  11212. mutex_lock(&bp->cnic_mutex);
  11213. c_ops = rcu_dereference_protected(bp->cnic_ops,
  11214. lockdep_is_held(&bp->cnic_mutex));
  11215. if (c_ops)
  11216. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  11217. mutex_unlock(&bp->cnic_mutex);
  11218. return rc;
  11219. }
  11220. static int bnx2x_cnic_ctl_send_bh(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  11221. {
  11222. struct cnic_ops *c_ops;
  11223. int rc = 0;
  11224. rcu_read_lock();
  11225. c_ops = rcu_dereference(bp->cnic_ops);
  11226. if (c_ops)
  11227. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  11228. rcu_read_unlock();
  11229. return rc;
  11230. }
  11231. /*
  11232. * for commands that have no data
  11233. */
  11234. int bnx2x_cnic_notify(struct bnx2x *bp, int cmd)
  11235. {
  11236. struct cnic_ctl_info ctl = {0};
  11237. ctl.cmd = cmd;
  11238. return bnx2x_cnic_ctl_send(bp, &ctl);
  11239. }
  11240. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err)
  11241. {
  11242. struct cnic_ctl_info ctl = {0};
  11243. /* first we tell CNIC and only then we count this as a completion */
  11244. ctl.cmd = CNIC_CTL_COMPLETION_CMD;
  11245. ctl.data.comp.cid = cid;
  11246. ctl.data.comp.error = err;
  11247. bnx2x_cnic_ctl_send_bh(bp, &ctl);
  11248. bnx2x_cnic_sp_post(bp, 0);
  11249. }
  11250. /* Called with netif_addr_lock_bh() taken.
  11251. * Sets an rx_mode config for an iSCSI ETH client.
  11252. * Doesn't block.
  11253. * Completion should be checked outside.
  11254. */
  11255. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start)
  11256. {
  11257. unsigned long accept_flags = 0, ramrod_flags = 0;
  11258. u8 cl_id = bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  11259. int sched_state = BNX2X_FILTER_ISCSI_ETH_STOP_SCHED;
  11260. if (start) {
  11261. /* Start accepting on iSCSI L2 ring. Accept all multicasts
  11262. * because it's the only way for UIO Queue to accept
  11263. * multicasts (in non-promiscuous mode only one Queue per
  11264. * function will receive multicast packets (leading in our
  11265. * case).
  11266. */
  11267. __set_bit(BNX2X_ACCEPT_UNICAST, &accept_flags);
  11268. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept_flags);
  11269. __set_bit(BNX2X_ACCEPT_BROADCAST, &accept_flags);
  11270. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags);
  11271. /* Clear STOP_PENDING bit if START is requested */
  11272. clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &bp->sp_state);
  11273. sched_state = BNX2X_FILTER_ISCSI_ETH_START_SCHED;
  11274. } else
  11275. /* Clear START_PENDING bit if STOP is requested */
  11276. clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &bp->sp_state);
  11277. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  11278. set_bit(sched_state, &bp->sp_state);
  11279. else {
  11280. __set_bit(RAMROD_RX, &ramrod_flags);
  11281. bnx2x_set_q_rx_mode(bp, cl_id, 0, accept_flags, 0,
  11282. ramrod_flags);
  11283. }
  11284. }
  11285. static int bnx2x_drv_ctl(struct net_device *dev, struct drv_ctl_info *ctl)
  11286. {
  11287. struct bnx2x *bp = netdev_priv(dev);
  11288. int rc = 0;
  11289. switch (ctl->cmd) {
  11290. case DRV_CTL_CTXTBL_WR_CMD: {
  11291. u32 index = ctl->data.io.offset;
  11292. dma_addr_t addr = ctl->data.io.dma_addr;
  11293. bnx2x_ilt_wr(bp, index, addr);
  11294. break;
  11295. }
  11296. case DRV_CTL_RET_L5_SPQ_CREDIT_CMD: {
  11297. int count = ctl->data.credit.credit_count;
  11298. bnx2x_cnic_sp_post(bp, count);
  11299. break;
  11300. }
  11301. /* rtnl_lock is held. */
  11302. case DRV_CTL_START_L2_CMD: {
  11303. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11304. unsigned long sp_bits = 0;
  11305. /* Configure the iSCSI classification object */
  11306. bnx2x_init_mac_obj(bp, &bp->iscsi_l2_mac_obj,
  11307. cp->iscsi_l2_client_id,
  11308. cp->iscsi_l2_cid, BP_FUNC(bp),
  11309. bnx2x_sp(bp, mac_rdata),
  11310. bnx2x_sp_mapping(bp, mac_rdata),
  11311. BNX2X_FILTER_MAC_PENDING,
  11312. &bp->sp_state, BNX2X_OBJ_TYPE_RX,
  11313. &bp->macs_pool);
  11314. /* Set iSCSI MAC address */
  11315. rc = bnx2x_set_iscsi_eth_mac_addr(bp);
  11316. if (rc)
  11317. break;
  11318. mmiowb();
  11319. barrier();
  11320. /* Start accepting on iSCSI L2 ring */
  11321. netif_addr_lock_bh(dev);
  11322. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  11323. netif_addr_unlock_bh(dev);
  11324. /* bits to wait on */
  11325. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  11326. __set_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &sp_bits);
  11327. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  11328. BNX2X_ERR("rx_mode completion timed out!\n");
  11329. break;
  11330. }
  11331. /* rtnl_lock is held. */
  11332. case DRV_CTL_STOP_L2_CMD: {
  11333. unsigned long sp_bits = 0;
  11334. /* Stop accepting on iSCSI L2 ring */
  11335. netif_addr_lock_bh(dev);
  11336. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  11337. netif_addr_unlock_bh(dev);
  11338. /* bits to wait on */
  11339. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  11340. __set_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &sp_bits);
  11341. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  11342. BNX2X_ERR("rx_mode completion timed out!\n");
  11343. mmiowb();
  11344. barrier();
  11345. /* Unset iSCSI L2 MAC */
  11346. rc = bnx2x_del_all_macs(bp, &bp->iscsi_l2_mac_obj,
  11347. BNX2X_ISCSI_ETH_MAC, true);
  11348. break;
  11349. }
  11350. case DRV_CTL_RET_L2_SPQ_CREDIT_CMD: {
  11351. int count = ctl->data.credit.credit_count;
  11352. smp_mb__before_atomic_inc();
  11353. atomic_add(count, &bp->cq_spq_left);
  11354. smp_mb__after_atomic_inc();
  11355. break;
  11356. }
  11357. case DRV_CTL_ULP_REGISTER_CMD: {
  11358. int ulp_type = ctl->data.register_data.ulp_type;
  11359. if (CHIP_IS_E3(bp)) {
  11360. int idx = BP_FW_MB_IDX(bp);
  11361. u32 cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  11362. int path = BP_PATH(bp);
  11363. int port = BP_PORT(bp);
  11364. int i;
  11365. u32 scratch_offset;
  11366. u32 *host_addr;
  11367. /* first write capability to shmem2 */
  11368. if (ulp_type == CNIC_ULP_ISCSI)
  11369. cap |= DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  11370. else if (ulp_type == CNIC_ULP_FCOE)
  11371. cap |= DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  11372. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  11373. if ((ulp_type != CNIC_ULP_FCOE) ||
  11374. (!SHMEM2_HAS(bp, ncsi_oem_data_addr)) ||
  11375. (!(bp->flags & BC_SUPPORTS_FCOE_FEATURES)))
  11376. break;
  11377. /* if reached here - should write fcoe capabilities */
  11378. scratch_offset = SHMEM2_RD(bp, ncsi_oem_data_addr);
  11379. if (!scratch_offset)
  11380. break;
  11381. scratch_offset += offsetof(struct glob_ncsi_oem_data,
  11382. fcoe_features[path][port]);
  11383. host_addr = (u32 *) &(ctl->data.register_data.
  11384. fcoe_features);
  11385. for (i = 0; i < sizeof(struct fcoe_capabilities);
  11386. i += 4)
  11387. REG_WR(bp, scratch_offset + i,
  11388. *(host_addr + i/4));
  11389. }
  11390. break;
  11391. }
  11392. case DRV_CTL_ULP_UNREGISTER_CMD: {
  11393. int ulp_type = ctl->data.ulp_type;
  11394. if (CHIP_IS_E3(bp)) {
  11395. int idx = BP_FW_MB_IDX(bp);
  11396. u32 cap;
  11397. cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  11398. if (ulp_type == CNIC_ULP_ISCSI)
  11399. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  11400. else if (ulp_type == CNIC_ULP_FCOE)
  11401. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  11402. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  11403. }
  11404. break;
  11405. }
  11406. default:
  11407. BNX2X_ERR("unknown command %x\n", ctl->cmd);
  11408. rc = -EINVAL;
  11409. }
  11410. return rc;
  11411. }
  11412. void bnx2x_setup_cnic_irq_info(struct bnx2x *bp)
  11413. {
  11414. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11415. if (bp->flags & USING_MSIX_FLAG) {
  11416. cp->drv_state |= CNIC_DRV_STATE_USING_MSIX;
  11417. cp->irq_arr[0].irq_flags |= CNIC_IRQ_FL_MSIX;
  11418. cp->irq_arr[0].vector = bp->msix_table[1].vector;
  11419. } else {
  11420. cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX;
  11421. cp->irq_arr[0].irq_flags &= ~CNIC_IRQ_FL_MSIX;
  11422. }
  11423. if (!CHIP_IS_E1x(bp))
  11424. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e2_sb;
  11425. else
  11426. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e1x_sb;
  11427. cp->irq_arr[0].status_blk_num = bnx2x_cnic_fw_sb_id(bp);
  11428. cp->irq_arr[0].status_blk_num2 = bnx2x_cnic_igu_sb_id(bp);
  11429. cp->irq_arr[1].status_blk = bp->def_status_blk;
  11430. cp->irq_arr[1].status_blk_num = DEF_SB_ID;
  11431. cp->irq_arr[1].status_blk_num2 = DEF_SB_IGU_ID;
  11432. cp->num_irq = 2;
  11433. }
  11434. void bnx2x_setup_cnic_info(struct bnx2x *bp)
  11435. {
  11436. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11437. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  11438. bnx2x_cid_ilt_lines(bp);
  11439. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  11440. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
  11441. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
  11442. 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",
  11443. BNX2X_1st_NON_L2_ETH_CID(bp), cp->starting_cid, cp->fcoe_init_cid,
  11444. cp->iscsi_l2_cid);
  11445. if (NO_ISCSI_OOO(bp))
  11446. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  11447. }
  11448. static int bnx2x_register_cnic(struct net_device *dev, struct cnic_ops *ops,
  11449. void *data)
  11450. {
  11451. struct bnx2x *bp = netdev_priv(dev);
  11452. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11453. int rc;
  11454. DP(NETIF_MSG_IFUP, "Register_cnic called\n");
  11455. if (ops == NULL) {
  11456. BNX2X_ERR("NULL ops received\n");
  11457. return -EINVAL;
  11458. }
  11459. if (!CNIC_SUPPORT(bp)) {
  11460. BNX2X_ERR("Can't register CNIC when not supported\n");
  11461. return -EOPNOTSUPP;
  11462. }
  11463. if (!CNIC_LOADED(bp)) {
  11464. rc = bnx2x_load_cnic(bp);
  11465. if (rc) {
  11466. BNX2X_ERR("CNIC-related load failed\n");
  11467. return rc;
  11468. }
  11469. }
  11470. bp->cnic_enabled = true;
  11471. bp->cnic_kwq = kzalloc(PAGE_SIZE, GFP_KERNEL);
  11472. if (!bp->cnic_kwq)
  11473. return -ENOMEM;
  11474. bp->cnic_kwq_cons = bp->cnic_kwq;
  11475. bp->cnic_kwq_prod = bp->cnic_kwq;
  11476. bp->cnic_kwq_last = bp->cnic_kwq + MAX_SP_DESC_CNT;
  11477. bp->cnic_spq_pending = 0;
  11478. bp->cnic_kwq_pending = 0;
  11479. bp->cnic_data = data;
  11480. cp->num_irq = 0;
  11481. cp->drv_state |= CNIC_DRV_STATE_REGD;
  11482. cp->iro_arr = bp->iro_arr;
  11483. bnx2x_setup_cnic_irq_info(bp);
  11484. rcu_assign_pointer(bp->cnic_ops, ops);
  11485. return 0;
  11486. }
  11487. static int bnx2x_unregister_cnic(struct net_device *dev)
  11488. {
  11489. struct bnx2x *bp = netdev_priv(dev);
  11490. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11491. mutex_lock(&bp->cnic_mutex);
  11492. cp->drv_state = 0;
  11493. RCU_INIT_POINTER(bp->cnic_ops, NULL);
  11494. mutex_unlock(&bp->cnic_mutex);
  11495. synchronize_rcu();
  11496. bp->cnic_enabled = false;
  11497. kfree(bp->cnic_kwq);
  11498. bp->cnic_kwq = NULL;
  11499. return 0;
  11500. }
  11501. struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev)
  11502. {
  11503. struct bnx2x *bp = netdev_priv(dev);
  11504. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11505. /* If both iSCSI and FCoE are disabled - return NULL in
  11506. * order to indicate CNIC that it should not try to work
  11507. * with this device.
  11508. */
  11509. if (NO_ISCSI(bp) && NO_FCOE(bp))
  11510. return NULL;
  11511. cp->drv_owner = THIS_MODULE;
  11512. cp->chip_id = CHIP_ID(bp);
  11513. cp->pdev = bp->pdev;
  11514. cp->io_base = bp->regview;
  11515. cp->io_base2 = bp->doorbells;
  11516. cp->max_kwqe_pending = 8;
  11517. cp->ctx_blk_size = CDU_ILT_PAGE_SZ;
  11518. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  11519. bnx2x_cid_ilt_lines(bp);
  11520. cp->ctx_tbl_len = CNIC_ILT_LINES;
  11521. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  11522. cp->drv_submit_kwqes_16 = bnx2x_cnic_sp_queue;
  11523. cp->drv_ctl = bnx2x_drv_ctl;
  11524. cp->drv_register_cnic = bnx2x_register_cnic;
  11525. cp->drv_unregister_cnic = bnx2x_unregister_cnic;
  11526. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
  11527. cp->iscsi_l2_client_id =
  11528. bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  11529. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
  11530. if (NO_ISCSI_OOO(bp))
  11531. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  11532. if (NO_ISCSI(bp))
  11533. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI;
  11534. if (NO_FCOE(bp))
  11535. cp->drv_state |= CNIC_DRV_STATE_NO_FCOE;
  11536. BNX2X_DEV_INFO(
  11537. "page_size %d, tbl_offset %d, tbl_lines %d, starting cid %d\n",
  11538. cp->ctx_blk_size,
  11539. cp->ctx_tbl_offset,
  11540. cp->ctx_tbl_len,
  11541. cp->starting_cid);
  11542. return cp;
  11543. }
  11544. u32 bnx2x_rx_ustorm_prods_offset(struct bnx2x_fastpath *fp)
  11545. {
  11546. struct bnx2x *bp = fp->bp;
  11547. u32 offset = BAR_USTRORM_INTMEM;
  11548. if (IS_VF(bp))
  11549. return bnx2x_vf_ustorm_prods_offset(bp, fp);
  11550. else if (!CHIP_IS_E1x(bp))
  11551. offset += USTORM_RX_PRODS_E2_OFFSET(fp->cl_qzone_id);
  11552. else
  11553. offset += USTORM_RX_PRODS_E1X_OFFSET(BP_PORT(bp), fp->cl_id);
  11554. return offset;
  11555. }
  11556. /* called only on E1H or E2.
  11557. * When pretending to be PF, the pretend value is the function number 0...7
  11558. * When pretending to be VF, the pretend val is the PF-num:VF-valid:ABS-VFID
  11559. * combination
  11560. */
  11561. int bnx2x_pretend_func(struct bnx2x *bp, u16 pretend_func_val)
  11562. {
  11563. u32 pretend_reg;
  11564. if (CHIP_IS_E1H(bp) && pretend_func_val >= E1H_FUNC_MAX)
  11565. return -1;
  11566. /* get my own pretend register */
  11567. pretend_reg = bnx2x_get_pretend_reg(bp);
  11568. REG_WR(bp, pretend_reg, pretend_func_val);
  11569. REG_RD(bp, pretend_reg);
  11570. return 0;
  11571. }