bnx2x_main.c 375 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846
  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. u32 *comp)
  457. {
  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. *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 ((*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 (*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, bnx2x_sp(bp, wb_comp));
  514. if (rc) {
  515. BNX2X_ERR("DMAE returned failure %d\n", rc);
  516. #ifdef BNX2X_STOP_ON_ERROR
  517. bnx2x_panic();
  518. #endif
  519. }
  520. }
  521. void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32)
  522. {
  523. int rc;
  524. struct dmae_command dmae;
  525. if (!bp->dmae_ready) {
  526. u32 *data = bnx2x_sp(bp, wb_data[0]);
  527. int i;
  528. if (CHIP_IS_E1(bp))
  529. for (i = 0; i < len32; i++)
  530. data[i] = bnx2x_reg_rd_ind(bp, src_addr + i*4);
  531. else
  532. for (i = 0; i < len32; i++)
  533. data[i] = REG_RD(bp, src_addr + i*4);
  534. return;
  535. }
  536. /* set opcode and fixed command fields */
  537. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_GRC, DMAE_DST_PCI);
  538. /* fill in addresses and len */
  539. dmae.src_addr_lo = src_addr >> 2;
  540. dmae.src_addr_hi = 0;
  541. dmae.dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_data));
  542. dmae.dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_data));
  543. dmae.len = len32;
  544. /* issue the command and wait for completion */
  545. rc = bnx2x_issue_dmae_with_comp(bp, &dmae, bnx2x_sp(bp, wb_comp));
  546. if (rc) {
  547. BNX2X_ERR("DMAE returned failure %d\n", rc);
  548. #ifdef BNX2X_STOP_ON_ERROR
  549. bnx2x_panic();
  550. #endif
  551. }
  552. }
  553. static void bnx2x_write_dmae_phys_len(struct bnx2x *bp, dma_addr_t phys_addr,
  554. u32 addr, u32 len)
  555. {
  556. int dmae_wr_max = DMAE_LEN32_WR_MAX(bp);
  557. int offset = 0;
  558. while (len > dmae_wr_max) {
  559. bnx2x_write_dmae(bp, phys_addr + offset,
  560. addr + offset, dmae_wr_max);
  561. offset += dmae_wr_max * 4;
  562. len -= dmae_wr_max;
  563. }
  564. bnx2x_write_dmae(bp, phys_addr + offset, addr + offset, len);
  565. }
  566. static int bnx2x_mc_assert(struct bnx2x *bp)
  567. {
  568. char last_idx;
  569. int i, rc = 0;
  570. u32 row0, row1, row2, row3;
  571. /* XSTORM */
  572. last_idx = REG_RD8(bp, BAR_XSTRORM_INTMEM +
  573. XSTORM_ASSERT_LIST_INDEX_OFFSET);
  574. if (last_idx)
  575. BNX2X_ERR("XSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  576. /* print the asserts */
  577. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  578. row0 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  579. XSTORM_ASSERT_LIST_OFFSET(i));
  580. row1 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  581. XSTORM_ASSERT_LIST_OFFSET(i) + 4);
  582. row2 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  583. XSTORM_ASSERT_LIST_OFFSET(i) + 8);
  584. row3 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  585. XSTORM_ASSERT_LIST_OFFSET(i) + 12);
  586. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  587. BNX2X_ERR("XSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  588. i, row3, row2, row1, row0);
  589. rc++;
  590. } else {
  591. break;
  592. }
  593. }
  594. /* TSTORM */
  595. last_idx = REG_RD8(bp, BAR_TSTRORM_INTMEM +
  596. TSTORM_ASSERT_LIST_INDEX_OFFSET);
  597. if (last_idx)
  598. BNX2X_ERR("TSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  599. /* print the asserts */
  600. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  601. row0 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  602. TSTORM_ASSERT_LIST_OFFSET(i));
  603. row1 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  604. TSTORM_ASSERT_LIST_OFFSET(i) + 4);
  605. row2 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  606. TSTORM_ASSERT_LIST_OFFSET(i) + 8);
  607. row3 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  608. TSTORM_ASSERT_LIST_OFFSET(i) + 12);
  609. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  610. BNX2X_ERR("TSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  611. i, row3, row2, row1, row0);
  612. rc++;
  613. } else {
  614. break;
  615. }
  616. }
  617. /* CSTORM */
  618. last_idx = REG_RD8(bp, BAR_CSTRORM_INTMEM +
  619. CSTORM_ASSERT_LIST_INDEX_OFFSET);
  620. if (last_idx)
  621. BNX2X_ERR("CSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  622. /* print the asserts */
  623. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  624. row0 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  625. CSTORM_ASSERT_LIST_OFFSET(i));
  626. row1 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  627. CSTORM_ASSERT_LIST_OFFSET(i) + 4);
  628. row2 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  629. CSTORM_ASSERT_LIST_OFFSET(i) + 8);
  630. row3 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  631. CSTORM_ASSERT_LIST_OFFSET(i) + 12);
  632. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  633. BNX2X_ERR("CSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  634. i, row3, row2, row1, row0);
  635. rc++;
  636. } else {
  637. break;
  638. }
  639. }
  640. /* USTORM */
  641. last_idx = REG_RD8(bp, BAR_USTRORM_INTMEM +
  642. USTORM_ASSERT_LIST_INDEX_OFFSET);
  643. if (last_idx)
  644. BNX2X_ERR("USTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  645. /* print the asserts */
  646. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  647. row0 = REG_RD(bp, BAR_USTRORM_INTMEM +
  648. USTORM_ASSERT_LIST_OFFSET(i));
  649. row1 = REG_RD(bp, BAR_USTRORM_INTMEM +
  650. USTORM_ASSERT_LIST_OFFSET(i) + 4);
  651. row2 = REG_RD(bp, BAR_USTRORM_INTMEM +
  652. USTORM_ASSERT_LIST_OFFSET(i) + 8);
  653. row3 = REG_RD(bp, BAR_USTRORM_INTMEM +
  654. USTORM_ASSERT_LIST_OFFSET(i) + 12);
  655. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  656. BNX2X_ERR("USTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  657. i, row3, row2, row1, row0);
  658. rc++;
  659. } else {
  660. break;
  661. }
  662. }
  663. return rc;
  664. }
  665. #define MCPR_TRACE_BUFFER_SIZE (0x800)
  666. #define SCRATCH_BUFFER_SIZE(bp) \
  667. (CHIP_IS_E1(bp) ? 0x10000 : (CHIP_IS_E1H(bp) ? 0x20000 : 0x28000))
  668. void bnx2x_fw_dump_lvl(struct bnx2x *bp, const char *lvl)
  669. {
  670. u32 addr, val;
  671. u32 mark, offset;
  672. __be32 data[9];
  673. int word;
  674. u32 trace_shmem_base;
  675. if (BP_NOMCP(bp)) {
  676. BNX2X_ERR("NO MCP - can not dump\n");
  677. return;
  678. }
  679. netdev_printk(lvl, bp->dev, "bc %d.%d.%d\n",
  680. (bp->common.bc_ver & 0xff0000) >> 16,
  681. (bp->common.bc_ver & 0xff00) >> 8,
  682. (bp->common.bc_ver & 0xff));
  683. val = REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER);
  684. if (val == REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER))
  685. BNX2X_ERR("%s" "MCP PC at 0x%x\n", lvl, val);
  686. if (BP_PATH(bp) == 0)
  687. trace_shmem_base = bp->common.shmem_base;
  688. else
  689. trace_shmem_base = SHMEM2_RD(bp, other_shmem_base_addr);
  690. /* sanity */
  691. if (trace_shmem_base < MCPR_SCRATCH_BASE(bp) + MCPR_TRACE_BUFFER_SIZE ||
  692. trace_shmem_base >= MCPR_SCRATCH_BASE(bp) +
  693. SCRATCH_BUFFER_SIZE(bp)) {
  694. BNX2X_ERR("Unable to dump trace buffer (mark %x)\n",
  695. trace_shmem_base);
  696. return;
  697. }
  698. addr = trace_shmem_base - MCPR_TRACE_BUFFER_SIZE;
  699. /* validate TRCB signature */
  700. mark = REG_RD(bp, addr);
  701. if (mark != MFW_TRACE_SIGNATURE) {
  702. BNX2X_ERR("Trace buffer signature is missing.");
  703. return ;
  704. }
  705. /* read cyclic buffer pointer */
  706. addr += 4;
  707. mark = REG_RD(bp, addr);
  708. mark = MCPR_SCRATCH_BASE(bp) + ((mark + 0x3) & ~0x3) - 0x08000000;
  709. if (mark >= trace_shmem_base || mark < addr + 4) {
  710. BNX2X_ERR("Mark doesn't fall inside Trace Buffer\n");
  711. return;
  712. }
  713. printk("%s" "begin fw dump (mark 0x%x)\n", lvl, mark);
  714. printk("%s", lvl);
  715. /* dump buffer after the mark */
  716. for (offset = mark; offset < trace_shmem_base; offset += 0x8*4) {
  717. for (word = 0; word < 8; word++)
  718. data[word] = htonl(REG_RD(bp, offset + 4*word));
  719. data[8] = 0x0;
  720. pr_cont("%s", (char *)data);
  721. }
  722. /* dump buffer before the mark */
  723. for (offset = addr + 4; offset <= mark; offset += 0x8*4) {
  724. for (word = 0; word < 8; word++)
  725. data[word] = htonl(REG_RD(bp, offset + 4*word));
  726. data[8] = 0x0;
  727. pr_cont("%s", (char *)data);
  728. }
  729. printk("%s" "end of fw dump\n", lvl);
  730. }
  731. static void bnx2x_fw_dump(struct bnx2x *bp)
  732. {
  733. bnx2x_fw_dump_lvl(bp, KERN_ERR);
  734. }
  735. static void bnx2x_hc_int_disable(struct bnx2x *bp)
  736. {
  737. int port = BP_PORT(bp);
  738. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  739. u32 val = REG_RD(bp, addr);
  740. /* in E1 we must use only PCI configuration space to disable
  741. * MSI/MSIX capability
  742. * It's forbidden to disable IGU_PF_CONF_MSI_MSIX_EN in HC block
  743. */
  744. if (CHIP_IS_E1(bp)) {
  745. /* Since IGU_PF_CONF_MSI_MSIX_EN still always on
  746. * Use mask register to prevent from HC sending interrupts
  747. * after we exit the function
  748. */
  749. REG_WR(bp, HC_REG_INT_MASK + port*4, 0);
  750. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  751. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  752. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  753. } else
  754. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  755. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  756. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  757. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  758. DP(NETIF_MSG_IFDOWN,
  759. "write %x to HC %d (addr 0x%x)\n",
  760. val, port, addr);
  761. /* flush all outstanding writes */
  762. mmiowb();
  763. REG_WR(bp, addr, val);
  764. if (REG_RD(bp, addr) != val)
  765. BNX2X_ERR("BUG! Proper val not read from IGU!\n");
  766. }
  767. static void bnx2x_igu_int_disable(struct bnx2x *bp)
  768. {
  769. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  770. val &= ~(IGU_PF_CONF_MSI_MSIX_EN |
  771. IGU_PF_CONF_INT_LINE_EN |
  772. IGU_PF_CONF_ATTN_BIT_EN);
  773. DP(NETIF_MSG_IFDOWN, "write %x to IGU\n", val);
  774. /* flush all outstanding writes */
  775. mmiowb();
  776. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  777. if (REG_RD(bp, IGU_REG_PF_CONFIGURATION) != val)
  778. BNX2X_ERR("BUG! Proper val not read from IGU!\n");
  779. }
  780. static void bnx2x_int_disable(struct bnx2x *bp)
  781. {
  782. if (bp->common.int_block == INT_BLOCK_HC)
  783. bnx2x_hc_int_disable(bp);
  784. else
  785. bnx2x_igu_int_disable(bp);
  786. }
  787. void bnx2x_panic_dump(struct bnx2x *bp, bool disable_int)
  788. {
  789. int i;
  790. u16 j;
  791. struct hc_sp_status_block_data sp_sb_data;
  792. int func = BP_FUNC(bp);
  793. #ifdef BNX2X_STOP_ON_ERROR
  794. u16 start = 0, end = 0;
  795. u8 cos;
  796. #endif
  797. if (disable_int)
  798. bnx2x_int_disable(bp);
  799. bp->stats_state = STATS_STATE_DISABLED;
  800. bp->eth_stats.unrecoverable_error++;
  801. DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n");
  802. BNX2X_ERR("begin crash dump -----------------\n");
  803. /* Indices */
  804. /* Common */
  805. 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",
  806. bp->def_idx, bp->def_att_idx, bp->attn_state,
  807. bp->spq_prod_idx, bp->stats_counter);
  808. BNX2X_ERR("DSB: attn bits(0x%x) ack(0x%x) id(0x%x) idx(0x%x)\n",
  809. bp->def_status_blk->atten_status_block.attn_bits,
  810. bp->def_status_blk->atten_status_block.attn_bits_ack,
  811. bp->def_status_blk->atten_status_block.status_block_id,
  812. bp->def_status_blk->atten_status_block.attn_bits_index);
  813. BNX2X_ERR(" def (");
  814. for (i = 0; i < HC_SP_SB_MAX_INDICES; i++)
  815. pr_cont("0x%x%s",
  816. bp->def_status_blk->sp_sb.index_values[i],
  817. (i == HC_SP_SB_MAX_INDICES - 1) ? ") " : " ");
  818. for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
  819. *((u32 *)&sp_sb_data + i) = REG_RD(bp, BAR_CSTRORM_INTMEM +
  820. CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
  821. i*sizeof(u32));
  822. 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",
  823. sp_sb_data.igu_sb_id,
  824. sp_sb_data.igu_seg_id,
  825. sp_sb_data.p_func.pf_id,
  826. sp_sb_data.p_func.vnic_id,
  827. sp_sb_data.p_func.vf_id,
  828. sp_sb_data.p_func.vf_valid,
  829. sp_sb_data.state);
  830. for_each_eth_queue(bp, i) {
  831. struct bnx2x_fastpath *fp = &bp->fp[i];
  832. int loop;
  833. struct hc_status_block_data_e2 sb_data_e2;
  834. struct hc_status_block_data_e1x sb_data_e1x;
  835. struct hc_status_block_sm *hc_sm_p =
  836. CHIP_IS_E1x(bp) ?
  837. sb_data_e1x.common.state_machine :
  838. sb_data_e2.common.state_machine;
  839. struct hc_index_data *hc_index_p =
  840. CHIP_IS_E1x(bp) ?
  841. sb_data_e1x.index_data :
  842. sb_data_e2.index_data;
  843. u8 data_size, cos;
  844. u32 *sb_data_p;
  845. struct bnx2x_fp_txdata txdata;
  846. /* Rx */
  847. 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",
  848. i, fp->rx_bd_prod, fp->rx_bd_cons,
  849. fp->rx_comp_prod,
  850. fp->rx_comp_cons, le16_to_cpu(*fp->rx_cons_sb));
  851. BNX2X_ERR(" rx_sge_prod(0x%x) last_max_sge(0x%x) fp_hc_idx(0x%x)\n",
  852. fp->rx_sge_prod, fp->last_max_sge,
  853. le16_to_cpu(fp->fp_hc_idx));
  854. /* Tx */
  855. for_each_cos_in_tx_queue(fp, cos)
  856. {
  857. txdata = *fp->txdata_ptr[cos];
  858. 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",
  859. i, txdata.tx_pkt_prod,
  860. txdata.tx_pkt_cons, txdata.tx_bd_prod,
  861. txdata.tx_bd_cons,
  862. le16_to_cpu(*txdata.tx_cons_sb));
  863. }
  864. loop = CHIP_IS_E1x(bp) ?
  865. HC_SB_MAX_INDICES_E1X : HC_SB_MAX_INDICES_E2;
  866. /* host sb data */
  867. if (IS_FCOE_FP(fp))
  868. continue;
  869. BNX2X_ERR(" run indexes (");
  870. for (j = 0; j < HC_SB_MAX_SM; j++)
  871. pr_cont("0x%x%s",
  872. fp->sb_running_index[j],
  873. (j == HC_SB_MAX_SM - 1) ? ")" : " ");
  874. BNX2X_ERR(" indexes (");
  875. for (j = 0; j < loop; j++)
  876. pr_cont("0x%x%s",
  877. fp->sb_index_values[j],
  878. (j == loop - 1) ? ")" : " ");
  879. /* fw sb data */
  880. data_size = CHIP_IS_E1x(bp) ?
  881. sizeof(struct hc_status_block_data_e1x) :
  882. sizeof(struct hc_status_block_data_e2);
  883. data_size /= sizeof(u32);
  884. sb_data_p = CHIP_IS_E1x(bp) ?
  885. (u32 *)&sb_data_e1x :
  886. (u32 *)&sb_data_e2;
  887. /* copy sb data in here */
  888. for (j = 0; j < data_size; j++)
  889. *(sb_data_p + j) = REG_RD(bp, BAR_CSTRORM_INTMEM +
  890. CSTORM_STATUS_BLOCK_DATA_OFFSET(fp->fw_sb_id) +
  891. j * sizeof(u32));
  892. if (!CHIP_IS_E1x(bp)) {
  893. 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",
  894. sb_data_e2.common.p_func.pf_id,
  895. sb_data_e2.common.p_func.vf_id,
  896. sb_data_e2.common.p_func.vf_valid,
  897. sb_data_e2.common.p_func.vnic_id,
  898. sb_data_e2.common.same_igu_sb_1b,
  899. sb_data_e2.common.state);
  900. } else {
  901. 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",
  902. sb_data_e1x.common.p_func.pf_id,
  903. sb_data_e1x.common.p_func.vf_id,
  904. sb_data_e1x.common.p_func.vf_valid,
  905. sb_data_e1x.common.p_func.vnic_id,
  906. sb_data_e1x.common.same_igu_sb_1b,
  907. sb_data_e1x.common.state);
  908. }
  909. /* SB_SMs data */
  910. for (j = 0; j < HC_SB_MAX_SM; j++) {
  911. 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",
  912. j, hc_sm_p[j].__flags,
  913. hc_sm_p[j].igu_sb_id,
  914. hc_sm_p[j].igu_seg_id,
  915. hc_sm_p[j].time_to_expire,
  916. hc_sm_p[j].timer_value);
  917. }
  918. /* Indices data */
  919. for (j = 0; j < loop; j++) {
  920. pr_cont("INDEX[%d] flags (0x%x) timeout (0x%x)\n", j,
  921. hc_index_p[j].flags,
  922. hc_index_p[j].timeout);
  923. }
  924. }
  925. #ifdef BNX2X_STOP_ON_ERROR
  926. /* event queue */
  927. BNX2X_ERR("eq cons %x prod %x\n", bp->eq_cons, bp->eq_prod);
  928. for (i = 0; i < NUM_EQ_DESC; i++) {
  929. u32 *data = (u32 *)&bp->eq_ring[i].message.data;
  930. BNX2X_ERR("event queue [%d]: header: opcode %d, error %d\n",
  931. i, bp->eq_ring[i].message.opcode,
  932. bp->eq_ring[i].message.error);
  933. BNX2X_ERR("data: %x %x %x\n", data[0], data[1], data[2]);
  934. }
  935. /* Rings */
  936. /* Rx */
  937. for_each_valid_rx_queue(bp, i) {
  938. struct bnx2x_fastpath *fp = &bp->fp[i];
  939. start = RX_BD(le16_to_cpu(*fp->rx_cons_sb) - 10);
  940. end = RX_BD(le16_to_cpu(*fp->rx_cons_sb) + 503);
  941. for (j = start; j != end; j = RX_BD(j + 1)) {
  942. u32 *rx_bd = (u32 *)&fp->rx_desc_ring[j];
  943. struct sw_rx_bd *sw_bd = &fp->rx_buf_ring[j];
  944. BNX2X_ERR("fp%d: rx_bd[%x]=[%x:%x] sw_bd=[%p]\n",
  945. i, j, rx_bd[1], rx_bd[0], sw_bd->data);
  946. }
  947. start = RX_SGE(fp->rx_sge_prod);
  948. end = RX_SGE(fp->last_max_sge);
  949. for (j = start; j != end; j = RX_SGE(j + 1)) {
  950. u32 *rx_sge = (u32 *)&fp->rx_sge_ring[j];
  951. struct sw_rx_page *sw_page = &fp->rx_page_ring[j];
  952. BNX2X_ERR("fp%d: rx_sge[%x]=[%x:%x] sw_page=[%p]\n",
  953. i, j, rx_sge[1], rx_sge[0], sw_page->page);
  954. }
  955. start = RCQ_BD(fp->rx_comp_cons - 10);
  956. end = RCQ_BD(fp->rx_comp_cons + 503);
  957. for (j = start; j != end; j = RCQ_BD(j + 1)) {
  958. u32 *cqe = (u32 *)&fp->rx_comp_ring[j];
  959. BNX2X_ERR("fp%d: cqe[%x]=[%x:%x:%x:%x]\n",
  960. i, j, cqe[0], cqe[1], cqe[2], cqe[3]);
  961. }
  962. }
  963. /* Tx */
  964. for_each_valid_tx_queue(bp, i) {
  965. struct bnx2x_fastpath *fp = &bp->fp[i];
  966. for_each_cos_in_tx_queue(fp, cos) {
  967. struct bnx2x_fp_txdata *txdata = fp->txdata_ptr[cos];
  968. start = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) - 10);
  969. end = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) + 245);
  970. for (j = start; j != end; j = TX_BD(j + 1)) {
  971. struct sw_tx_bd *sw_bd =
  972. &txdata->tx_buf_ring[j];
  973. BNX2X_ERR("fp%d: txdata %d, packet[%x]=[%p,%x]\n",
  974. i, cos, j, sw_bd->skb,
  975. sw_bd->first_bd);
  976. }
  977. start = TX_BD(txdata->tx_bd_cons - 10);
  978. end = TX_BD(txdata->tx_bd_cons + 254);
  979. for (j = start; j != end; j = TX_BD(j + 1)) {
  980. u32 *tx_bd = (u32 *)&txdata->tx_desc_ring[j];
  981. BNX2X_ERR("fp%d: txdata %d, tx_bd[%x]=[%x:%x:%x:%x]\n",
  982. i, cos, j, tx_bd[0], tx_bd[1],
  983. tx_bd[2], tx_bd[3]);
  984. }
  985. }
  986. }
  987. #endif
  988. bnx2x_fw_dump(bp);
  989. bnx2x_mc_assert(bp);
  990. BNX2X_ERR("end crash dump -----------------\n");
  991. }
  992. /*
  993. * FLR Support for E2
  994. *
  995. * bnx2x_pf_flr_clnup() is called during nic_load in the per function HW
  996. * initialization.
  997. */
  998. #define FLR_WAIT_USEC 10000 /* 10 milliseconds */
  999. #define FLR_WAIT_INTERVAL 50 /* usec */
  1000. #define FLR_POLL_CNT (FLR_WAIT_USEC/FLR_WAIT_INTERVAL) /* 200 */
  1001. struct pbf_pN_buf_regs {
  1002. int pN;
  1003. u32 init_crd;
  1004. u32 crd;
  1005. u32 crd_freed;
  1006. };
  1007. struct pbf_pN_cmd_regs {
  1008. int pN;
  1009. u32 lines_occup;
  1010. u32 lines_freed;
  1011. };
  1012. static void bnx2x_pbf_pN_buf_flushed(struct bnx2x *bp,
  1013. struct pbf_pN_buf_regs *regs,
  1014. u32 poll_count)
  1015. {
  1016. u32 init_crd, crd, crd_start, crd_freed, crd_freed_start;
  1017. u32 cur_cnt = poll_count;
  1018. crd_freed = crd_freed_start = REG_RD(bp, regs->crd_freed);
  1019. crd = crd_start = REG_RD(bp, regs->crd);
  1020. init_crd = REG_RD(bp, regs->init_crd);
  1021. DP(BNX2X_MSG_SP, "INIT CREDIT[%d] : %x\n", regs->pN, init_crd);
  1022. DP(BNX2X_MSG_SP, "CREDIT[%d] : s:%x\n", regs->pN, crd);
  1023. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: s:%x\n", regs->pN, crd_freed);
  1024. while ((crd != init_crd) && ((u32)SUB_S32(crd_freed, crd_freed_start) <
  1025. (init_crd - crd_start))) {
  1026. if (cur_cnt--) {
  1027. udelay(FLR_WAIT_INTERVAL);
  1028. crd = REG_RD(bp, regs->crd);
  1029. crd_freed = REG_RD(bp, regs->crd_freed);
  1030. } else {
  1031. DP(BNX2X_MSG_SP, "PBF tx buffer[%d] timed out\n",
  1032. regs->pN);
  1033. DP(BNX2X_MSG_SP, "CREDIT[%d] : c:%x\n",
  1034. regs->pN, crd);
  1035. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: c:%x\n",
  1036. regs->pN, crd_freed);
  1037. break;
  1038. }
  1039. }
  1040. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF tx buffer[%d]\n",
  1041. poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
  1042. }
  1043. static void bnx2x_pbf_pN_cmd_flushed(struct bnx2x *bp,
  1044. struct pbf_pN_cmd_regs *regs,
  1045. u32 poll_count)
  1046. {
  1047. u32 occup, to_free, freed, freed_start;
  1048. u32 cur_cnt = poll_count;
  1049. occup = to_free = REG_RD(bp, regs->lines_occup);
  1050. freed = freed_start = REG_RD(bp, regs->lines_freed);
  1051. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n", regs->pN, occup);
  1052. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n", regs->pN, freed);
  1053. while (occup && ((u32)SUB_S32(freed, freed_start) < to_free)) {
  1054. if (cur_cnt--) {
  1055. udelay(FLR_WAIT_INTERVAL);
  1056. occup = REG_RD(bp, regs->lines_occup);
  1057. freed = REG_RD(bp, regs->lines_freed);
  1058. } else {
  1059. DP(BNX2X_MSG_SP, "PBF cmd queue[%d] timed out\n",
  1060. regs->pN);
  1061. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n",
  1062. regs->pN, occup);
  1063. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n",
  1064. regs->pN, freed);
  1065. break;
  1066. }
  1067. }
  1068. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF cmd queue[%d]\n",
  1069. poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
  1070. }
  1071. static u32 bnx2x_flr_clnup_reg_poll(struct bnx2x *bp, u32 reg,
  1072. u32 expected, u32 poll_count)
  1073. {
  1074. u32 cur_cnt = poll_count;
  1075. u32 val;
  1076. while ((val = REG_RD(bp, reg)) != expected && cur_cnt--)
  1077. udelay(FLR_WAIT_INTERVAL);
  1078. return val;
  1079. }
  1080. int bnx2x_flr_clnup_poll_hw_counter(struct bnx2x *bp, u32 reg,
  1081. char *msg, u32 poll_cnt)
  1082. {
  1083. u32 val = bnx2x_flr_clnup_reg_poll(bp, reg, 0, poll_cnt);
  1084. if (val != 0) {
  1085. BNX2X_ERR("%s usage count=%d\n", msg, val);
  1086. return 1;
  1087. }
  1088. return 0;
  1089. }
  1090. /* Common routines with VF FLR cleanup */
  1091. u32 bnx2x_flr_clnup_poll_count(struct bnx2x *bp)
  1092. {
  1093. /* adjust polling timeout */
  1094. if (CHIP_REV_IS_EMUL(bp))
  1095. return FLR_POLL_CNT * 2000;
  1096. if (CHIP_REV_IS_FPGA(bp))
  1097. return FLR_POLL_CNT * 120;
  1098. return FLR_POLL_CNT;
  1099. }
  1100. void bnx2x_tx_hw_flushed(struct bnx2x *bp, u32 poll_count)
  1101. {
  1102. struct pbf_pN_cmd_regs cmd_regs[] = {
  1103. {0, (CHIP_IS_E3B0(bp)) ?
  1104. PBF_REG_TQ_OCCUPANCY_Q0 :
  1105. PBF_REG_P0_TQ_OCCUPANCY,
  1106. (CHIP_IS_E3B0(bp)) ?
  1107. PBF_REG_TQ_LINES_FREED_CNT_Q0 :
  1108. PBF_REG_P0_TQ_LINES_FREED_CNT},
  1109. {1, (CHIP_IS_E3B0(bp)) ?
  1110. PBF_REG_TQ_OCCUPANCY_Q1 :
  1111. PBF_REG_P1_TQ_OCCUPANCY,
  1112. (CHIP_IS_E3B0(bp)) ?
  1113. PBF_REG_TQ_LINES_FREED_CNT_Q1 :
  1114. PBF_REG_P1_TQ_LINES_FREED_CNT},
  1115. {4, (CHIP_IS_E3B0(bp)) ?
  1116. PBF_REG_TQ_OCCUPANCY_LB_Q :
  1117. PBF_REG_P4_TQ_OCCUPANCY,
  1118. (CHIP_IS_E3B0(bp)) ?
  1119. PBF_REG_TQ_LINES_FREED_CNT_LB_Q :
  1120. PBF_REG_P4_TQ_LINES_FREED_CNT}
  1121. };
  1122. struct pbf_pN_buf_regs buf_regs[] = {
  1123. {0, (CHIP_IS_E3B0(bp)) ?
  1124. PBF_REG_INIT_CRD_Q0 :
  1125. PBF_REG_P0_INIT_CRD ,
  1126. (CHIP_IS_E3B0(bp)) ?
  1127. PBF_REG_CREDIT_Q0 :
  1128. PBF_REG_P0_CREDIT,
  1129. (CHIP_IS_E3B0(bp)) ?
  1130. PBF_REG_INTERNAL_CRD_FREED_CNT_Q0 :
  1131. PBF_REG_P0_INTERNAL_CRD_FREED_CNT},
  1132. {1, (CHIP_IS_E3B0(bp)) ?
  1133. PBF_REG_INIT_CRD_Q1 :
  1134. PBF_REG_P1_INIT_CRD,
  1135. (CHIP_IS_E3B0(bp)) ?
  1136. PBF_REG_CREDIT_Q1 :
  1137. PBF_REG_P1_CREDIT,
  1138. (CHIP_IS_E3B0(bp)) ?
  1139. PBF_REG_INTERNAL_CRD_FREED_CNT_Q1 :
  1140. PBF_REG_P1_INTERNAL_CRD_FREED_CNT},
  1141. {4, (CHIP_IS_E3B0(bp)) ?
  1142. PBF_REG_INIT_CRD_LB_Q :
  1143. PBF_REG_P4_INIT_CRD,
  1144. (CHIP_IS_E3B0(bp)) ?
  1145. PBF_REG_CREDIT_LB_Q :
  1146. PBF_REG_P4_CREDIT,
  1147. (CHIP_IS_E3B0(bp)) ?
  1148. PBF_REG_INTERNAL_CRD_FREED_CNT_LB_Q :
  1149. PBF_REG_P4_INTERNAL_CRD_FREED_CNT},
  1150. };
  1151. int i;
  1152. /* Verify the command queues are flushed P0, P1, P4 */
  1153. for (i = 0; i < ARRAY_SIZE(cmd_regs); i++)
  1154. bnx2x_pbf_pN_cmd_flushed(bp, &cmd_regs[i], poll_count);
  1155. /* Verify the transmission buffers are flushed P0, P1, P4 */
  1156. for (i = 0; i < ARRAY_SIZE(buf_regs); i++)
  1157. bnx2x_pbf_pN_buf_flushed(bp, &buf_regs[i], poll_count);
  1158. }
  1159. #define OP_GEN_PARAM(param) \
  1160. (((param) << SDM_OP_GEN_COMP_PARAM_SHIFT) & SDM_OP_GEN_COMP_PARAM)
  1161. #define OP_GEN_TYPE(type) \
  1162. (((type) << SDM_OP_GEN_COMP_TYPE_SHIFT) & SDM_OP_GEN_COMP_TYPE)
  1163. #define OP_GEN_AGG_VECT(index) \
  1164. (((index) << SDM_OP_GEN_AGG_VECT_IDX_SHIFT) & SDM_OP_GEN_AGG_VECT_IDX)
  1165. int bnx2x_send_final_clnup(struct bnx2x *bp, u8 clnup_func, u32 poll_cnt)
  1166. {
  1167. u32 op_gen_command = 0;
  1168. u32 comp_addr = BAR_CSTRORM_INTMEM +
  1169. CSTORM_FINAL_CLEANUP_COMPLETE_OFFSET(clnup_func);
  1170. int ret = 0;
  1171. if (REG_RD(bp, comp_addr)) {
  1172. BNX2X_ERR("Cleanup complete was not 0 before sending\n");
  1173. return 1;
  1174. }
  1175. op_gen_command |= OP_GEN_PARAM(XSTORM_AGG_INT_FINAL_CLEANUP_INDEX);
  1176. op_gen_command |= OP_GEN_TYPE(XSTORM_AGG_INT_FINAL_CLEANUP_COMP_TYPE);
  1177. op_gen_command |= OP_GEN_AGG_VECT(clnup_func);
  1178. op_gen_command |= 1 << SDM_OP_GEN_AGG_VECT_IDX_VALID_SHIFT;
  1179. DP(BNX2X_MSG_SP, "sending FW Final cleanup\n");
  1180. REG_WR(bp, XSDM_REG_OPERATION_GEN, op_gen_command);
  1181. if (bnx2x_flr_clnup_reg_poll(bp, comp_addr, 1, poll_cnt) != 1) {
  1182. BNX2X_ERR("FW final cleanup did not succeed\n");
  1183. DP(BNX2X_MSG_SP, "At timeout completion address contained %x\n",
  1184. (REG_RD(bp, comp_addr)));
  1185. bnx2x_panic();
  1186. return 1;
  1187. }
  1188. /* Zero completion for next FLR */
  1189. REG_WR(bp, comp_addr, 0);
  1190. return ret;
  1191. }
  1192. u8 bnx2x_is_pcie_pending(struct pci_dev *dev)
  1193. {
  1194. u16 status;
  1195. pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status);
  1196. return status & PCI_EXP_DEVSTA_TRPND;
  1197. }
  1198. /* PF FLR specific routines
  1199. */
  1200. static int bnx2x_poll_hw_usage_counters(struct bnx2x *bp, u32 poll_cnt)
  1201. {
  1202. /* wait for CFC PF usage-counter to zero (includes all the VFs) */
  1203. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1204. CFC_REG_NUM_LCIDS_INSIDE_PF,
  1205. "CFC PF usage counter timed out",
  1206. poll_cnt))
  1207. return 1;
  1208. /* Wait for DQ PF usage-counter to zero (until DQ cleanup) */
  1209. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1210. DORQ_REG_PF_USAGE_CNT,
  1211. "DQ PF usage counter timed out",
  1212. poll_cnt))
  1213. return 1;
  1214. /* Wait for QM PF usage-counter to zero (until DQ cleanup) */
  1215. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1216. QM_REG_PF_USG_CNT_0 + 4*BP_FUNC(bp),
  1217. "QM PF usage counter timed out",
  1218. poll_cnt))
  1219. return 1;
  1220. /* Wait for Timer PF usage-counters to zero (until DQ cleanup) */
  1221. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1222. TM_REG_LIN0_VNIC_UC + 4*BP_PORT(bp),
  1223. "Timers VNIC usage counter timed out",
  1224. poll_cnt))
  1225. return 1;
  1226. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1227. TM_REG_LIN0_NUM_SCANS + 4*BP_PORT(bp),
  1228. "Timers NUM_SCANS usage counter timed out",
  1229. poll_cnt))
  1230. return 1;
  1231. /* Wait DMAE PF usage counter to zero */
  1232. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1233. dmae_reg_go_c[INIT_DMAE_C(bp)],
  1234. "DMAE command register timed out",
  1235. poll_cnt))
  1236. return 1;
  1237. return 0;
  1238. }
  1239. static void bnx2x_hw_enable_status(struct bnx2x *bp)
  1240. {
  1241. u32 val;
  1242. val = REG_RD(bp, CFC_REG_WEAK_ENABLE_PF);
  1243. DP(BNX2X_MSG_SP, "CFC_REG_WEAK_ENABLE_PF is 0x%x\n", val);
  1244. val = REG_RD(bp, PBF_REG_DISABLE_PF);
  1245. DP(BNX2X_MSG_SP, "PBF_REG_DISABLE_PF is 0x%x\n", val);
  1246. val = REG_RD(bp, IGU_REG_PCI_PF_MSI_EN);
  1247. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSI_EN is 0x%x\n", val);
  1248. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_EN);
  1249. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_EN is 0x%x\n", val);
  1250. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_FUNC_MASK);
  1251. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_FUNC_MASK is 0x%x\n", val);
  1252. val = REG_RD(bp, PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR);
  1253. DP(BNX2X_MSG_SP, "PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR is 0x%x\n", val);
  1254. val = REG_RD(bp, PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR);
  1255. DP(BNX2X_MSG_SP, "PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR is 0x%x\n", val);
  1256. val = REG_RD(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
  1257. DP(BNX2X_MSG_SP, "PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER is 0x%x\n",
  1258. val);
  1259. }
  1260. static int bnx2x_pf_flr_clnup(struct bnx2x *bp)
  1261. {
  1262. u32 poll_cnt = bnx2x_flr_clnup_poll_count(bp);
  1263. DP(BNX2X_MSG_SP, "Cleanup after FLR PF[%d]\n", BP_ABS_FUNC(bp));
  1264. /* Re-enable PF target read access */
  1265. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  1266. /* Poll HW usage counters */
  1267. DP(BNX2X_MSG_SP, "Polling usage counters\n");
  1268. if (bnx2x_poll_hw_usage_counters(bp, poll_cnt))
  1269. return -EBUSY;
  1270. /* Zero the igu 'trailing edge' and 'leading edge' */
  1271. /* Send the FW cleanup command */
  1272. if (bnx2x_send_final_clnup(bp, (u8)BP_FUNC(bp), poll_cnt))
  1273. return -EBUSY;
  1274. /* ATC cleanup */
  1275. /* Verify TX hw is flushed */
  1276. bnx2x_tx_hw_flushed(bp, poll_cnt);
  1277. /* Wait 100ms (not adjusted according to platform) */
  1278. msleep(100);
  1279. /* Verify no pending pci transactions */
  1280. if (bnx2x_is_pcie_pending(bp->pdev))
  1281. BNX2X_ERR("PCIE Transactions still pending\n");
  1282. /* Debug */
  1283. bnx2x_hw_enable_status(bp);
  1284. /*
  1285. * Master enable - Due to WB DMAE writes performed before this
  1286. * register is re-initialized as part of the regular function init
  1287. */
  1288. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  1289. return 0;
  1290. }
  1291. static void bnx2x_hc_int_enable(struct bnx2x *bp)
  1292. {
  1293. int port = BP_PORT(bp);
  1294. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  1295. u32 val = REG_RD(bp, addr);
  1296. bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
  1297. bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
  1298. bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
  1299. if (msix) {
  1300. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1301. HC_CONFIG_0_REG_INT_LINE_EN_0);
  1302. val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1303. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1304. if (single_msix)
  1305. val |= HC_CONFIG_0_REG_SINGLE_ISR_EN_0;
  1306. } else if (msi) {
  1307. val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0;
  1308. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1309. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1310. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1311. } else {
  1312. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1313. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1314. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  1315. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1316. if (!CHIP_IS_E1(bp)) {
  1317. DP(NETIF_MSG_IFUP,
  1318. "write %x to HC %d (addr 0x%x)\n", val, port, addr);
  1319. REG_WR(bp, addr, val);
  1320. val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0;
  1321. }
  1322. }
  1323. if (CHIP_IS_E1(bp))
  1324. REG_WR(bp, HC_REG_INT_MASK + port*4, 0x1FFFF);
  1325. DP(NETIF_MSG_IFUP,
  1326. "write %x to HC %d (addr 0x%x) mode %s\n", val, port, addr,
  1327. (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1328. REG_WR(bp, addr, val);
  1329. /*
  1330. * Ensure that HC_CONFIG is written before leading/trailing edge config
  1331. */
  1332. mmiowb();
  1333. barrier();
  1334. if (!CHIP_IS_E1(bp)) {
  1335. /* init leading/trailing edge */
  1336. if (IS_MF(bp)) {
  1337. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1338. if (bp->port.pmf)
  1339. /* enable nig and gpio3 attention */
  1340. val |= 0x1100;
  1341. } else
  1342. val = 0xffff;
  1343. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  1344. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  1345. }
  1346. /* Make sure that interrupts are indeed enabled from here on */
  1347. mmiowb();
  1348. }
  1349. static void bnx2x_igu_int_enable(struct bnx2x *bp)
  1350. {
  1351. u32 val;
  1352. bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
  1353. bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
  1354. bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
  1355. val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  1356. if (msix) {
  1357. val &= ~(IGU_PF_CONF_INT_LINE_EN |
  1358. IGU_PF_CONF_SINGLE_ISR_EN);
  1359. val |= (IGU_PF_CONF_MSI_MSIX_EN |
  1360. IGU_PF_CONF_ATTN_BIT_EN);
  1361. if (single_msix)
  1362. val |= IGU_PF_CONF_SINGLE_ISR_EN;
  1363. } else if (msi) {
  1364. val &= ~IGU_PF_CONF_INT_LINE_EN;
  1365. val |= (IGU_PF_CONF_MSI_MSIX_EN |
  1366. IGU_PF_CONF_ATTN_BIT_EN |
  1367. IGU_PF_CONF_SINGLE_ISR_EN);
  1368. } else {
  1369. val &= ~IGU_PF_CONF_MSI_MSIX_EN;
  1370. val |= (IGU_PF_CONF_INT_LINE_EN |
  1371. IGU_PF_CONF_ATTN_BIT_EN |
  1372. IGU_PF_CONF_SINGLE_ISR_EN);
  1373. }
  1374. /* Clean previous status - need to configure igu prior to ack*/
  1375. if ((!msix) || single_msix) {
  1376. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1377. bnx2x_ack_int(bp);
  1378. }
  1379. val |= IGU_PF_CONF_FUNC_EN;
  1380. DP(NETIF_MSG_IFUP, "write 0x%x to IGU mode %s\n",
  1381. val, (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1382. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1383. if (val & IGU_PF_CONF_INT_LINE_EN)
  1384. pci_intx(bp->pdev, true);
  1385. barrier();
  1386. /* init leading/trailing edge */
  1387. if (IS_MF(bp)) {
  1388. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1389. if (bp->port.pmf)
  1390. /* enable nig and gpio3 attention */
  1391. val |= 0x1100;
  1392. } else
  1393. val = 0xffff;
  1394. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  1395. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  1396. /* Make sure that interrupts are indeed enabled from here on */
  1397. mmiowb();
  1398. }
  1399. void bnx2x_int_enable(struct bnx2x *bp)
  1400. {
  1401. if (bp->common.int_block == INT_BLOCK_HC)
  1402. bnx2x_hc_int_enable(bp);
  1403. else
  1404. bnx2x_igu_int_enable(bp);
  1405. }
  1406. void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw)
  1407. {
  1408. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  1409. int i, offset;
  1410. if (disable_hw)
  1411. /* prevent the HW from sending interrupts */
  1412. bnx2x_int_disable(bp);
  1413. /* make sure all ISRs are done */
  1414. if (msix) {
  1415. synchronize_irq(bp->msix_table[0].vector);
  1416. offset = 1;
  1417. if (CNIC_SUPPORT(bp))
  1418. offset++;
  1419. for_each_eth_queue(bp, i)
  1420. synchronize_irq(bp->msix_table[offset++].vector);
  1421. } else
  1422. synchronize_irq(bp->pdev->irq);
  1423. /* make sure sp_task is not running */
  1424. cancel_delayed_work(&bp->sp_task);
  1425. cancel_delayed_work(&bp->period_task);
  1426. flush_workqueue(bnx2x_wq);
  1427. }
  1428. /* fast path */
  1429. /*
  1430. * General service functions
  1431. */
  1432. /* Return true if succeeded to acquire the lock */
  1433. static bool bnx2x_trylock_hw_lock(struct bnx2x *bp, u32 resource)
  1434. {
  1435. u32 lock_status;
  1436. u32 resource_bit = (1 << resource);
  1437. int func = BP_FUNC(bp);
  1438. u32 hw_lock_control_reg;
  1439. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1440. "Trying to take a lock on resource %d\n", resource);
  1441. /* Validating that the resource is within range */
  1442. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1443. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1444. "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1445. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1446. return false;
  1447. }
  1448. if (func <= 5)
  1449. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1450. else
  1451. hw_lock_control_reg =
  1452. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1453. /* Try to acquire the lock */
  1454. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1455. lock_status = REG_RD(bp, hw_lock_control_reg);
  1456. if (lock_status & resource_bit)
  1457. return true;
  1458. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1459. "Failed to get a lock on resource %d\n", resource);
  1460. return false;
  1461. }
  1462. /**
  1463. * bnx2x_get_leader_lock_resource - get the recovery leader resource id
  1464. *
  1465. * @bp: driver handle
  1466. *
  1467. * Returns the recovery leader resource id according to the engine this function
  1468. * belongs to. Currently only only 2 engines is supported.
  1469. */
  1470. static int bnx2x_get_leader_lock_resource(struct bnx2x *bp)
  1471. {
  1472. if (BP_PATH(bp))
  1473. return HW_LOCK_RESOURCE_RECOVERY_LEADER_1;
  1474. else
  1475. return HW_LOCK_RESOURCE_RECOVERY_LEADER_0;
  1476. }
  1477. /**
  1478. * bnx2x_trylock_leader_lock- try to acquire a leader lock.
  1479. *
  1480. * @bp: driver handle
  1481. *
  1482. * Tries to acquire a leader lock for current engine.
  1483. */
  1484. static bool bnx2x_trylock_leader_lock(struct bnx2x *bp)
  1485. {
  1486. return bnx2x_trylock_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1487. }
  1488. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err);
  1489. /* schedule the sp task and mark that interrupt occurred (runs from ISR) */
  1490. static int bnx2x_schedule_sp_task(struct bnx2x *bp)
  1491. {
  1492. /* Set the interrupt occurred bit for the sp-task to recognize it
  1493. * must ack the interrupt and transition according to the IGU
  1494. * state machine.
  1495. */
  1496. atomic_set(&bp->interrupt_occurred, 1);
  1497. /* The sp_task must execute only after this bit
  1498. * is set, otherwise we will get out of sync and miss all
  1499. * further interrupts. Hence, the barrier.
  1500. */
  1501. smp_wmb();
  1502. /* schedule sp_task to workqueue */
  1503. return queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
  1504. }
  1505. void bnx2x_sp_event(struct bnx2x_fastpath *fp, union eth_rx_cqe *rr_cqe)
  1506. {
  1507. struct bnx2x *bp = fp->bp;
  1508. int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1509. int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1510. enum bnx2x_queue_cmd drv_cmd = BNX2X_Q_CMD_MAX;
  1511. struct bnx2x_queue_sp_obj *q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  1512. DP(BNX2X_MSG_SP,
  1513. "fp %d cid %d got ramrod #%d state is %x type is %d\n",
  1514. fp->index, cid, command, bp->state,
  1515. rr_cqe->ramrod_cqe.ramrod_type);
  1516. /* If cid is within VF range, replace the slowpath object with the
  1517. * one corresponding to this VF
  1518. */
  1519. if (cid >= BNX2X_FIRST_VF_CID &&
  1520. cid < BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)
  1521. bnx2x_iov_set_queue_sp_obj(bp, cid, &q_obj);
  1522. switch (command) {
  1523. case (RAMROD_CMD_ID_ETH_CLIENT_UPDATE):
  1524. DP(BNX2X_MSG_SP, "got UPDATE ramrod. CID %d\n", cid);
  1525. drv_cmd = BNX2X_Q_CMD_UPDATE;
  1526. break;
  1527. case (RAMROD_CMD_ID_ETH_CLIENT_SETUP):
  1528. DP(BNX2X_MSG_SP, "got MULTI[%d] setup ramrod\n", cid);
  1529. drv_cmd = BNX2X_Q_CMD_SETUP;
  1530. break;
  1531. case (RAMROD_CMD_ID_ETH_TX_QUEUE_SETUP):
  1532. DP(BNX2X_MSG_SP, "got MULTI[%d] tx-only setup ramrod\n", cid);
  1533. drv_cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  1534. break;
  1535. case (RAMROD_CMD_ID_ETH_HALT):
  1536. DP(BNX2X_MSG_SP, "got MULTI[%d] halt ramrod\n", cid);
  1537. drv_cmd = BNX2X_Q_CMD_HALT;
  1538. break;
  1539. case (RAMROD_CMD_ID_ETH_TERMINATE):
  1540. DP(BNX2X_MSG_SP, "got MULTI[%d] terminate ramrod\n", cid);
  1541. drv_cmd = BNX2X_Q_CMD_TERMINATE;
  1542. break;
  1543. case (RAMROD_CMD_ID_ETH_EMPTY):
  1544. DP(BNX2X_MSG_SP, "got MULTI[%d] empty ramrod\n", cid);
  1545. drv_cmd = BNX2X_Q_CMD_EMPTY;
  1546. break;
  1547. default:
  1548. BNX2X_ERR("unexpected MC reply (%d) on fp[%d]\n",
  1549. command, fp->index);
  1550. return;
  1551. }
  1552. if ((drv_cmd != BNX2X_Q_CMD_MAX) &&
  1553. q_obj->complete_cmd(bp, q_obj, drv_cmd))
  1554. /* q_obj->complete_cmd() failure means that this was
  1555. * an unexpected completion.
  1556. *
  1557. * In this case we don't want to increase the bp->spq_left
  1558. * because apparently we haven't sent this command the first
  1559. * place.
  1560. */
  1561. #ifdef BNX2X_STOP_ON_ERROR
  1562. bnx2x_panic();
  1563. #else
  1564. return;
  1565. #endif
  1566. /* SRIOV: reschedule any 'in_progress' operations */
  1567. bnx2x_iov_sp_event(bp, cid, true);
  1568. smp_mb__before_atomic_inc();
  1569. atomic_inc(&bp->cq_spq_left);
  1570. /* push the change in bp->spq_left and towards the memory */
  1571. smp_mb__after_atomic_inc();
  1572. DP(BNX2X_MSG_SP, "bp->cq_spq_left %x\n", atomic_read(&bp->cq_spq_left));
  1573. if ((drv_cmd == BNX2X_Q_CMD_UPDATE) && (IS_FCOE_FP(fp)) &&
  1574. (!!test_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state))) {
  1575. /* if Q update ramrod is completed for last Q in AFEX vif set
  1576. * flow, then ACK MCP at the end
  1577. *
  1578. * mark pending ACK to MCP bit.
  1579. * prevent case that both bits are cleared.
  1580. * At the end of load/unload driver checks that
  1581. * sp_state is cleared, and this order prevents
  1582. * races
  1583. */
  1584. smp_mb__before_clear_bit();
  1585. set_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK, &bp->sp_state);
  1586. wmb();
  1587. clear_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
  1588. smp_mb__after_clear_bit();
  1589. /* schedule the sp task as mcp ack is required */
  1590. bnx2x_schedule_sp_task(bp);
  1591. }
  1592. return;
  1593. }
  1594. irqreturn_t bnx2x_interrupt(int irq, void *dev_instance)
  1595. {
  1596. struct bnx2x *bp = netdev_priv(dev_instance);
  1597. u16 status = bnx2x_ack_int(bp);
  1598. u16 mask;
  1599. int i;
  1600. u8 cos;
  1601. /* Return here if interrupt is shared and it's not for us */
  1602. if (unlikely(status == 0)) {
  1603. DP(NETIF_MSG_INTR, "not our interrupt!\n");
  1604. return IRQ_NONE;
  1605. }
  1606. DP(NETIF_MSG_INTR, "got an interrupt status 0x%x\n", status);
  1607. #ifdef BNX2X_STOP_ON_ERROR
  1608. if (unlikely(bp->panic))
  1609. return IRQ_HANDLED;
  1610. #endif
  1611. for_each_eth_queue(bp, i) {
  1612. struct bnx2x_fastpath *fp = &bp->fp[i];
  1613. mask = 0x2 << (fp->index + CNIC_SUPPORT(bp));
  1614. if (status & mask) {
  1615. /* Handle Rx or Tx according to SB id */
  1616. for_each_cos_in_tx_queue(fp, cos)
  1617. prefetch(fp->txdata_ptr[cos]->tx_cons_sb);
  1618. prefetch(&fp->sb_running_index[SM_RX_ID]);
  1619. napi_schedule(&bnx2x_fp(bp, fp->index, napi));
  1620. status &= ~mask;
  1621. }
  1622. }
  1623. if (CNIC_SUPPORT(bp)) {
  1624. mask = 0x2;
  1625. if (status & (mask | 0x1)) {
  1626. struct cnic_ops *c_ops = NULL;
  1627. rcu_read_lock();
  1628. c_ops = rcu_dereference(bp->cnic_ops);
  1629. if (c_ops && (bp->cnic_eth_dev.drv_state &
  1630. CNIC_DRV_STATE_HANDLES_IRQ))
  1631. c_ops->cnic_handler(bp->cnic_data, NULL);
  1632. rcu_read_unlock();
  1633. status &= ~mask;
  1634. }
  1635. }
  1636. if (unlikely(status & 0x1)) {
  1637. /* schedule sp task to perform default status block work, ack
  1638. * attentions and enable interrupts.
  1639. */
  1640. bnx2x_schedule_sp_task(bp);
  1641. status &= ~0x1;
  1642. if (!status)
  1643. return IRQ_HANDLED;
  1644. }
  1645. if (unlikely(status))
  1646. DP(NETIF_MSG_INTR, "got an unknown interrupt! (status 0x%x)\n",
  1647. status);
  1648. return IRQ_HANDLED;
  1649. }
  1650. /* Link */
  1651. /*
  1652. * General service functions
  1653. */
  1654. int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource)
  1655. {
  1656. u32 lock_status;
  1657. u32 resource_bit = (1 << resource);
  1658. int func = BP_FUNC(bp);
  1659. u32 hw_lock_control_reg;
  1660. int cnt;
  1661. /* Validating that the resource is within range */
  1662. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1663. BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1664. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1665. return -EINVAL;
  1666. }
  1667. if (func <= 5) {
  1668. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1669. } else {
  1670. hw_lock_control_reg =
  1671. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1672. }
  1673. /* Validating that the resource is not already taken */
  1674. lock_status = REG_RD(bp, hw_lock_control_reg);
  1675. if (lock_status & resource_bit) {
  1676. BNX2X_ERR("lock_status 0x%x resource_bit 0x%x\n",
  1677. lock_status, resource_bit);
  1678. return -EEXIST;
  1679. }
  1680. /* Try for 5 second every 5ms */
  1681. for (cnt = 0; cnt < 1000; cnt++) {
  1682. /* Try to acquire the lock */
  1683. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1684. lock_status = REG_RD(bp, hw_lock_control_reg);
  1685. if (lock_status & resource_bit)
  1686. return 0;
  1687. usleep_range(5000, 10000);
  1688. }
  1689. BNX2X_ERR("Timeout\n");
  1690. return -EAGAIN;
  1691. }
  1692. int bnx2x_release_leader_lock(struct bnx2x *bp)
  1693. {
  1694. return bnx2x_release_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1695. }
  1696. int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource)
  1697. {
  1698. u32 lock_status;
  1699. u32 resource_bit = (1 << resource);
  1700. int func = BP_FUNC(bp);
  1701. u32 hw_lock_control_reg;
  1702. /* Validating that the resource is within range */
  1703. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1704. BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1705. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1706. return -EINVAL;
  1707. }
  1708. if (func <= 5) {
  1709. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1710. } else {
  1711. hw_lock_control_reg =
  1712. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1713. }
  1714. /* Validating that the resource is currently taken */
  1715. lock_status = REG_RD(bp, hw_lock_control_reg);
  1716. if (!(lock_status & resource_bit)) {
  1717. BNX2X_ERR("lock_status 0x%x resource_bit 0x%x. Unlock was called but lock wasn't taken!\n",
  1718. lock_status, resource_bit);
  1719. return -EFAULT;
  1720. }
  1721. REG_WR(bp, hw_lock_control_reg, resource_bit);
  1722. return 0;
  1723. }
  1724. int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port)
  1725. {
  1726. /* The GPIO should be swapped if swap register is set and active */
  1727. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1728. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1729. int gpio_shift = gpio_num +
  1730. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1731. u32 gpio_mask = (1 << gpio_shift);
  1732. u32 gpio_reg;
  1733. int value;
  1734. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1735. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1736. return -EINVAL;
  1737. }
  1738. /* read GPIO value */
  1739. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1740. /* get the requested pin value */
  1741. if ((gpio_reg & gpio_mask) == gpio_mask)
  1742. value = 1;
  1743. else
  1744. value = 0;
  1745. DP(NETIF_MSG_LINK, "pin %d value 0x%x\n", gpio_num, value);
  1746. return value;
  1747. }
  1748. int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1749. {
  1750. /* The GPIO should be swapped if swap register is set and active */
  1751. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1752. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1753. int gpio_shift = gpio_num +
  1754. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1755. u32 gpio_mask = (1 << gpio_shift);
  1756. u32 gpio_reg;
  1757. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1758. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1759. return -EINVAL;
  1760. }
  1761. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1762. /* read GPIO and mask except the float bits */
  1763. gpio_reg = (REG_RD(bp, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT);
  1764. switch (mode) {
  1765. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1766. DP(NETIF_MSG_LINK,
  1767. "Set GPIO %d (shift %d) -> output low\n",
  1768. gpio_num, gpio_shift);
  1769. /* clear FLOAT and set CLR */
  1770. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1771. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS);
  1772. break;
  1773. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1774. DP(NETIF_MSG_LINK,
  1775. "Set GPIO %d (shift %d) -> output high\n",
  1776. gpio_num, gpio_shift);
  1777. /* clear FLOAT and set SET */
  1778. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1779. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS);
  1780. break;
  1781. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1782. DP(NETIF_MSG_LINK,
  1783. "Set GPIO %d (shift %d) -> input\n",
  1784. gpio_num, gpio_shift);
  1785. /* set FLOAT */
  1786. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1787. break;
  1788. default:
  1789. break;
  1790. }
  1791. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1792. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1793. return 0;
  1794. }
  1795. int bnx2x_set_mult_gpio(struct bnx2x *bp, u8 pins, u32 mode)
  1796. {
  1797. u32 gpio_reg = 0;
  1798. int rc = 0;
  1799. /* Any port swapping should be handled by caller. */
  1800. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1801. /* read GPIO and mask except the float bits */
  1802. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1803. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1804. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_CLR_POS);
  1805. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_SET_POS);
  1806. switch (mode) {
  1807. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1808. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output low\n", pins);
  1809. /* set CLR */
  1810. gpio_reg |= (pins << MISC_REGISTERS_GPIO_CLR_POS);
  1811. break;
  1812. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1813. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output high\n", pins);
  1814. /* set SET */
  1815. gpio_reg |= (pins << MISC_REGISTERS_GPIO_SET_POS);
  1816. break;
  1817. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1818. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> input\n", pins);
  1819. /* set FLOAT */
  1820. gpio_reg |= (pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1821. break;
  1822. default:
  1823. BNX2X_ERR("Invalid GPIO mode assignment %d\n", mode);
  1824. rc = -EINVAL;
  1825. break;
  1826. }
  1827. if (rc == 0)
  1828. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1829. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1830. return rc;
  1831. }
  1832. int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1833. {
  1834. /* The GPIO should be swapped if swap register is set and active */
  1835. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1836. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1837. int gpio_shift = gpio_num +
  1838. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1839. u32 gpio_mask = (1 << gpio_shift);
  1840. u32 gpio_reg;
  1841. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1842. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1843. return -EINVAL;
  1844. }
  1845. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1846. /* read GPIO int */
  1847. gpio_reg = REG_RD(bp, MISC_REG_GPIO_INT);
  1848. switch (mode) {
  1849. case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR:
  1850. DP(NETIF_MSG_LINK,
  1851. "Clear GPIO INT %d (shift %d) -> output low\n",
  1852. gpio_num, gpio_shift);
  1853. /* clear SET and set CLR */
  1854. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1855. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1856. break;
  1857. case MISC_REGISTERS_GPIO_INT_OUTPUT_SET:
  1858. DP(NETIF_MSG_LINK,
  1859. "Set GPIO INT %d (shift %d) -> output high\n",
  1860. gpio_num, gpio_shift);
  1861. /* clear CLR and set SET */
  1862. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1863. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1864. break;
  1865. default:
  1866. break;
  1867. }
  1868. REG_WR(bp, MISC_REG_GPIO_INT, gpio_reg);
  1869. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1870. return 0;
  1871. }
  1872. static int bnx2x_set_spio(struct bnx2x *bp, int spio, u32 mode)
  1873. {
  1874. u32 spio_reg;
  1875. /* Only 2 SPIOs are configurable */
  1876. if ((spio != MISC_SPIO_SPIO4) && (spio != MISC_SPIO_SPIO5)) {
  1877. BNX2X_ERR("Invalid SPIO 0x%x\n", spio);
  1878. return -EINVAL;
  1879. }
  1880. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1881. /* read SPIO and mask except the float bits */
  1882. spio_reg = (REG_RD(bp, MISC_REG_SPIO) & MISC_SPIO_FLOAT);
  1883. switch (mode) {
  1884. case MISC_SPIO_OUTPUT_LOW:
  1885. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output low\n", spio);
  1886. /* clear FLOAT and set CLR */
  1887. spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
  1888. spio_reg |= (spio << MISC_SPIO_CLR_POS);
  1889. break;
  1890. case MISC_SPIO_OUTPUT_HIGH:
  1891. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output high\n", spio);
  1892. /* clear FLOAT and set SET */
  1893. spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
  1894. spio_reg |= (spio << MISC_SPIO_SET_POS);
  1895. break;
  1896. case MISC_SPIO_INPUT_HI_Z:
  1897. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> input\n", spio);
  1898. /* set FLOAT */
  1899. spio_reg |= (spio << MISC_SPIO_FLOAT_POS);
  1900. break;
  1901. default:
  1902. break;
  1903. }
  1904. REG_WR(bp, MISC_REG_SPIO, spio_reg);
  1905. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1906. return 0;
  1907. }
  1908. void bnx2x_calc_fc_adv(struct bnx2x *bp)
  1909. {
  1910. u8 cfg_idx = bnx2x_get_link_cfg_idx(bp);
  1911. switch (bp->link_vars.ieee_fc &
  1912. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) {
  1913. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE:
  1914. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1915. ADVERTISED_Pause);
  1916. break;
  1917. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH:
  1918. bp->port.advertising[cfg_idx] |= (ADVERTISED_Asym_Pause |
  1919. ADVERTISED_Pause);
  1920. break;
  1921. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC:
  1922. bp->port.advertising[cfg_idx] |= ADVERTISED_Asym_Pause;
  1923. break;
  1924. default:
  1925. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1926. ADVERTISED_Pause);
  1927. break;
  1928. }
  1929. }
  1930. static void bnx2x_set_requested_fc(struct bnx2x *bp)
  1931. {
  1932. /* Initialize link parameters structure variables
  1933. * It is recommended to turn off RX FC for jumbo frames
  1934. * for better performance
  1935. */
  1936. if (CHIP_IS_E1x(bp) && (bp->dev->mtu > 5000))
  1937. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_TX;
  1938. else
  1939. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH;
  1940. }
  1941. static void bnx2x_init_dropless_fc(struct bnx2x *bp)
  1942. {
  1943. u32 pause_enabled = 0;
  1944. if (!CHIP_IS_E1(bp) && bp->dropless_fc && bp->link_vars.link_up) {
  1945. if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX)
  1946. pause_enabled = 1;
  1947. REG_WR(bp, BAR_USTRORM_INTMEM +
  1948. USTORM_ETH_PAUSE_ENABLED_OFFSET(BP_PORT(bp)),
  1949. pause_enabled);
  1950. }
  1951. DP(NETIF_MSG_IFUP | NETIF_MSG_LINK, "dropless_fc is %s\n",
  1952. pause_enabled ? "enabled" : "disabled");
  1953. }
  1954. int bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode)
  1955. {
  1956. int rc, cfx_idx = bnx2x_get_link_cfg_idx(bp);
  1957. u16 req_line_speed = bp->link_params.req_line_speed[cfx_idx];
  1958. if (!BP_NOMCP(bp)) {
  1959. bnx2x_set_requested_fc(bp);
  1960. bnx2x_acquire_phy_lock(bp);
  1961. if (load_mode == LOAD_DIAG) {
  1962. struct link_params *lp = &bp->link_params;
  1963. lp->loopback_mode = LOOPBACK_XGXS;
  1964. /* do PHY loopback at 10G speed, if possible */
  1965. if (lp->req_line_speed[cfx_idx] < SPEED_10000) {
  1966. if (lp->speed_cap_mask[cfx_idx] &
  1967. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
  1968. lp->req_line_speed[cfx_idx] =
  1969. SPEED_10000;
  1970. else
  1971. lp->req_line_speed[cfx_idx] =
  1972. SPEED_1000;
  1973. }
  1974. }
  1975. if (load_mode == LOAD_LOOPBACK_EXT) {
  1976. struct link_params *lp = &bp->link_params;
  1977. lp->loopback_mode = LOOPBACK_EXT;
  1978. }
  1979. rc = bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  1980. bnx2x_release_phy_lock(bp);
  1981. bnx2x_init_dropless_fc(bp);
  1982. bnx2x_calc_fc_adv(bp);
  1983. if (bp->link_vars.link_up) {
  1984. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  1985. bnx2x_link_report(bp);
  1986. }
  1987. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  1988. bp->link_params.req_line_speed[cfx_idx] = req_line_speed;
  1989. return rc;
  1990. }
  1991. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  1992. return -EINVAL;
  1993. }
  1994. void bnx2x_link_set(struct bnx2x *bp)
  1995. {
  1996. if (!BP_NOMCP(bp)) {
  1997. bnx2x_acquire_phy_lock(bp);
  1998. bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  1999. bnx2x_release_phy_lock(bp);
  2000. bnx2x_init_dropless_fc(bp);
  2001. bnx2x_calc_fc_adv(bp);
  2002. } else
  2003. BNX2X_ERR("Bootcode is missing - can not set link\n");
  2004. }
  2005. static void bnx2x__link_reset(struct bnx2x *bp)
  2006. {
  2007. if (!BP_NOMCP(bp)) {
  2008. bnx2x_acquire_phy_lock(bp);
  2009. bnx2x_lfa_reset(&bp->link_params, &bp->link_vars);
  2010. bnx2x_release_phy_lock(bp);
  2011. } else
  2012. BNX2X_ERR("Bootcode is missing - can not reset link\n");
  2013. }
  2014. void bnx2x_force_link_reset(struct bnx2x *bp)
  2015. {
  2016. bnx2x_acquire_phy_lock(bp);
  2017. bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
  2018. bnx2x_release_phy_lock(bp);
  2019. }
  2020. u8 bnx2x_link_test(struct bnx2x *bp, u8 is_serdes)
  2021. {
  2022. u8 rc = 0;
  2023. if (!BP_NOMCP(bp)) {
  2024. bnx2x_acquire_phy_lock(bp);
  2025. rc = bnx2x_test_link(&bp->link_params, &bp->link_vars,
  2026. is_serdes);
  2027. bnx2x_release_phy_lock(bp);
  2028. } else
  2029. BNX2X_ERR("Bootcode is missing - can not test link\n");
  2030. return rc;
  2031. }
  2032. /* Calculates the sum of vn_min_rates.
  2033. It's needed for further normalizing of the min_rates.
  2034. Returns:
  2035. sum of vn_min_rates.
  2036. or
  2037. 0 - if all the min_rates are 0.
  2038. In the later case fairness algorithm should be deactivated.
  2039. If not all min_rates are zero then those that are zeroes will be set to 1.
  2040. */
  2041. static void bnx2x_calc_vn_min(struct bnx2x *bp,
  2042. struct cmng_init_input *input)
  2043. {
  2044. int all_zero = 1;
  2045. int vn;
  2046. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2047. u32 vn_cfg = bp->mf_config[vn];
  2048. u32 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
  2049. FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
  2050. /* Skip hidden vns */
  2051. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  2052. vn_min_rate = 0;
  2053. /* If min rate is zero - set it to 1 */
  2054. else if (!vn_min_rate)
  2055. vn_min_rate = DEF_MIN_RATE;
  2056. else
  2057. all_zero = 0;
  2058. input->vnic_min_rate[vn] = vn_min_rate;
  2059. }
  2060. /* if ETS or all min rates are zeros - disable fairness */
  2061. if (BNX2X_IS_ETS_ENABLED(bp)) {
  2062. input->flags.cmng_enables &=
  2063. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2064. DP(NETIF_MSG_IFUP, "Fairness will be disabled due to ETS\n");
  2065. } else if (all_zero) {
  2066. input->flags.cmng_enables &=
  2067. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2068. DP(NETIF_MSG_IFUP,
  2069. "All MIN values are zeroes fairness will be disabled\n");
  2070. } else
  2071. input->flags.cmng_enables |=
  2072. CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2073. }
  2074. static void bnx2x_calc_vn_max(struct bnx2x *bp, int vn,
  2075. struct cmng_init_input *input)
  2076. {
  2077. u16 vn_max_rate;
  2078. u32 vn_cfg = bp->mf_config[vn];
  2079. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  2080. vn_max_rate = 0;
  2081. else {
  2082. u32 maxCfg = bnx2x_extract_max_cfg(bp, vn_cfg);
  2083. if (IS_MF_SI(bp)) {
  2084. /* maxCfg in percents of linkspeed */
  2085. vn_max_rate = (bp->link_vars.line_speed * maxCfg) / 100;
  2086. } else /* SD modes */
  2087. /* maxCfg is absolute in 100Mb units */
  2088. vn_max_rate = maxCfg * 100;
  2089. }
  2090. DP(NETIF_MSG_IFUP, "vn %d: vn_max_rate %d\n", vn, vn_max_rate);
  2091. input->vnic_max_rate[vn] = vn_max_rate;
  2092. }
  2093. static int bnx2x_get_cmng_fns_mode(struct bnx2x *bp)
  2094. {
  2095. if (CHIP_REV_IS_SLOW(bp))
  2096. return CMNG_FNS_NONE;
  2097. if (IS_MF(bp))
  2098. return CMNG_FNS_MINMAX;
  2099. return CMNG_FNS_NONE;
  2100. }
  2101. void bnx2x_read_mf_cfg(struct bnx2x *bp)
  2102. {
  2103. int vn, n = (CHIP_MODE_IS_4_PORT(bp) ? 2 : 1);
  2104. if (BP_NOMCP(bp))
  2105. return; /* what should be the default value in this case */
  2106. /* For 2 port configuration the absolute function number formula
  2107. * is:
  2108. * abs_func = 2 * vn + BP_PORT + BP_PATH
  2109. *
  2110. * and there are 4 functions per port
  2111. *
  2112. * For 4 port configuration it is
  2113. * abs_func = 4 * vn + 2 * BP_PORT + BP_PATH
  2114. *
  2115. * and there are 2 functions per port
  2116. */
  2117. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2118. int /*abs*/func = n * (2 * vn + BP_PORT(bp)) + BP_PATH(bp);
  2119. if (func >= E1H_FUNC_MAX)
  2120. break;
  2121. bp->mf_config[vn] =
  2122. MF_CFG_RD(bp, func_mf_config[func].config);
  2123. }
  2124. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  2125. DP(NETIF_MSG_IFUP, "mf_cfg function disabled\n");
  2126. bp->flags |= MF_FUNC_DIS;
  2127. } else {
  2128. DP(NETIF_MSG_IFUP, "mf_cfg function enabled\n");
  2129. bp->flags &= ~MF_FUNC_DIS;
  2130. }
  2131. }
  2132. static void bnx2x_cmng_fns_init(struct bnx2x *bp, u8 read_cfg, u8 cmng_type)
  2133. {
  2134. struct cmng_init_input input;
  2135. memset(&input, 0, sizeof(struct cmng_init_input));
  2136. input.port_rate = bp->link_vars.line_speed;
  2137. if (cmng_type == CMNG_FNS_MINMAX && input.port_rate) {
  2138. int vn;
  2139. /* read mf conf from shmem */
  2140. if (read_cfg)
  2141. bnx2x_read_mf_cfg(bp);
  2142. /* vn_weight_sum and enable fairness if not 0 */
  2143. bnx2x_calc_vn_min(bp, &input);
  2144. /* calculate and set min-max rate for each vn */
  2145. if (bp->port.pmf)
  2146. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++)
  2147. bnx2x_calc_vn_max(bp, vn, &input);
  2148. /* always enable rate shaping and fairness */
  2149. input.flags.cmng_enables |=
  2150. CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN;
  2151. bnx2x_init_cmng(&input, &bp->cmng);
  2152. return;
  2153. }
  2154. /* rate shaping and fairness are disabled */
  2155. DP(NETIF_MSG_IFUP,
  2156. "rate shaping and fairness are disabled\n");
  2157. }
  2158. static void storm_memset_cmng(struct bnx2x *bp,
  2159. struct cmng_init *cmng,
  2160. u8 port)
  2161. {
  2162. int vn;
  2163. size_t size = sizeof(struct cmng_struct_per_port);
  2164. u32 addr = BAR_XSTRORM_INTMEM +
  2165. XSTORM_CMNG_PER_PORT_VARS_OFFSET(port);
  2166. __storm_memset_struct(bp, addr, size, (u32 *)&cmng->port);
  2167. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2168. int func = func_by_vn(bp, vn);
  2169. addr = BAR_XSTRORM_INTMEM +
  2170. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func);
  2171. size = sizeof(struct rate_shaping_vars_per_vn);
  2172. __storm_memset_struct(bp, addr, size,
  2173. (u32 *)&cmng->vnic.vnic_max_rate[vn]);
  2174. addr = BAR_XSTRORM_INTMEM +
  2175. XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func);
  2176. size = sizeof(struct fairness_vars_per_vn);
  2177. __storm_memset_struct(bp, addr, size,
  2178. (u32 *)&cmng->vnic.vnic_min_rate[vn]);
  2179. }
  2180. }
  2181. /* init cmng mode in HW according to local configuration */
  2182. void bnx2x_set_local_cmng(struct bnx2x *bp)
  2183. {
  2184. int cmng_fns = bnx2x_get_cmng_fns_mode(bp);
  2185. if (cmng_fns != CMNG_FNS_NONE) {
  2186. bnx2x_cmng_fns_init(bp, false, cmng_fns);
  2187. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2188. } else {
  2189. /* rate shaping and fairness are disabled */
  2190. DP(NETIF_MSG_IFUP,
  2191. "single function mode without fairness\n");
  2192. }
  2193. }
  2194. /* This function is called upon link interrupt */
  2195. static void bnx2x_link_attn(struct bnx2x *bp)
  2196. {
  2197. /* Make sure that we are synced with the current statistics */
  2198. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2199. bnx2x_link_update(&bp->link_params, &bp->link_vars);
  2200. bnx2x_init_dropless_fc(bp);
  2201. if (bp->link_vars.link_up) {
  2202. if (bp->link_vars.mac_type != MAC_TYPE_EMAC) {
  2203. struct host_port_stats *pstats;
  2204. pstats = bnx2x_sp(bp, port_stats);
  2205. /* reset old mac stats */
  2206. memset(&(pstats->mac_stx[0]), 0,
  2207. sizeof(struct mac_stx));
  2208. }
  2209. if (bp->state == BNX2X_STATE_OPEN)
  2210. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2211. }
  2212. if (bp->link_vars.link_up && bp->link_vars.line_speed)
  2213. bnx2x_set_local_cmng(bp);
  2214. __bnx2x_link_report(bp);
  2215. if (IS_MF(bp))
  2216. bnx2x_link_sync_notify(bp);
  2217. }
  2218. void bnx2x__link_status_update(struct bnx2x *bp)
  2219. {
  2220. if (bp->state != BNX2X_STATE_OPEN)
  2221. return;
  2222. /* read updated dcb configuration */
  2223. if (IS_PF(bp)) {
  2224. bnx2x_dcbx_pmf_update(bp);
  2225. bnx2x_link_status_update(&bp->link_params, &bp->link_vars);
  2226. if (bp->link_vars.link_up)
  2227. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2228. else
  2229. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2230. /* indicate link status */
  2231. bnx2x_link_report(bp);
  2232. } else { /* VF */
  2233. bp->port.supported[0] |= (SUPPORTED_10baseT_Half |
  2234. SUPPORTED_10baseT_Full |
  2235. SUPPORTED_100baseT_Half |
  2236. SUPPORTED_100baseT_Full |
  2237. SUPPORTED_1000baseT_Full |
  2238. SUPPORTED_2500baseX_Full |
  2239. SUPPORTED_10000baseT_Full |
  2240. SUPPORTED_TP |
  2241. SUPPORTED_FIBRE |
  2242. SUPPORTED_Autoneg |
  2243. SUPPORTED_Pause |
  2244. SUPPORTED_Asym_Pause);
  2245. bp->port.advertising[0] = bp->port.supported[0];
  2246. bp->link_params.bp = bp;
  2247. bp->link_params.port = BP_PORT(bp);
  2248. bp->link_params.req_duplex[0] = DUPLEX_FULL;
  2249. bp->link_params.req_flow_ctrl[0] = BNX2X_FLOW_CTRL_NONE;
  2250. bp->link_params.req_line_speed[0] = SPEED_10000;
  2251. bp->link_params.speed_cap_mask[0] = 0x7f0000;
  2252. bp->link_params.switch_cfg = SWITCH_CFG_10G;
  2253. bp->link_vars.mac_type = MAC_TYPE_BMAC;
  2254. bp->link_vars.line_speed = SPEED_10000;
  2255. bp->link_vars.link_status =
  2256. (LINK_STATUS_LINK_UP |
  2257. LINK_STATUS_SPEED_AND_DUPLEX_10GTFD);
  2258. bp->link_vars.link_up = 1;
  2259. bp->link_vars.duplex = DUPLEX_FULL;
  2260. bp->link_vars.flow_ctrl = BNX2X_FLOW_CTRL_NONE;
  2261. __bnx2x_link_report(bp);
  2262. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2263. }
  2264. }
  2265. static int bnx2x_afex_func_update(struct bnx2x *bp, u16 vifid,
  2266. u16 vlan_val, u8 allowed_prio)
  2267. {
  2268. struct bnx2x_func_state_params func_params = {NULL};
  2269. struct bnx2x_func_afex_update_params *f_update_params =
  2270. &func_params.params.afex_update;
  2271. func_params.f_obj = &bp->func_obj;
  2272. func_params.cmd = BNX2X_F_CMD_AFEX_UPDATE;
  2273. /* no need to wait for RAMROD completion, so don't
  2274. * set RAMROD_COMP_WAIT flag
  2275. */
  2276. f_update_params->vif_id = vifid;
  2277. f_update_params->afex_default_vlan = vlan_val;
  2278. f_update_params->allowed_priorities = allowed_prio;
  2279. /* if ramrod can not be sent, response to MCP immediately */
  2280. if (bnx2x_func_state_change(bp, &func_params) < 0)
  2281. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  2282. return 0;
  2283. }
  2284. static int bnx2x_afex_handle_vif_list_cmd(struct bnx2x *bp, u8 cmd_type,
  2285. u16 vif_index, u8 func_bit_map)
  2286. {
  2287. struct bnx2x_func_state_params func_params = {NULL};
  2288. struct bnx2x_func_afex_viflists_params *update_params =
  2289. &func_params.params.afex_viflists;
  2290. int rc;
  2291. u32 drv_msg_code;
  2292. /* validate only LIST_SET and LIST_GET are received from switch */
  2293. if ((cmd_type != VIF_LIST_RULE_GET) && (cmd_type != VIF_LIST_RULE_SET))
  2294. BNX2X_ERR("BUG! afex_handle_vif_list_cmd invalid type 0x%x\n",
  2295. cmd_type);
  2296. func_params.f_obj = &bp->func_obj;
  2297. func_params.cmd = BNX2X_F_CMD_AFEX_VIFLISTS;
  2298. /* set parameters according to cmd_type */
  2299. update_params->afex_vif_list_command = cmd_type;
  2300. update_params->vif_list_index = vif_index;
  2301. update_params->func_bit_map =
  2302. (cmd_type == VIF_LIST_RULE_GET) ? 0 : func_bit_map;
  2303. update_params->func_to_clear = 0;
  2304. drv_msg_code =
  2305. (cmd_type == VIF_LIST_RULE_GET) ?
  2306. DRV_MSG_CODE_AFEX_LISTGET_ACK :
  2307. DRV_MSG_CODE_AFEX_LISTSET_ACK;
  2308. /* if ramrod can not be sent, respond to MCP immediately for
  2309. * SET and GET requests (other are not triggered from MCP)
  2310. */
  2311. rc = bnx2x_func_state_change(bp, &func_params);
  2312. if (rc < 0)
  2313. bnx2x_fw_command(bp, drv_msg_code, 0);
  2314. return 0;
  2315. }
  2316. static void bnx2x_handle_afex_cmd(struct bnx2x *bp, u32 cmd)
  2317. {
  2318. struct afex_stats afex_stats;
  2319. u32 func = BP_ABS_FUNC(bp);
  2320. u32 mf_config;
  2321. u16 vlan_val;
  2322. u32 vlan_prio;
  2323. u16 vif_id;
  2324. u8 allowed_prio;
  2325. u8 vlan_mode;
  2326. u32 addr_to_write, vifid, addrs, stats_type, i;
  2327. if (cmd & DRV_STATUS_AFEX_LISTGET_REQ) {
  2328. vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2329. DP(BNX2X_MSG_MCP,
  2330. "afex: got MCP req LISTGET_REQ for vifid 0x%x\n", vifid);
  2331. bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_GET, vifid, 0);
  2332. }
  2333. if (cmd & DRV_STATUS_AFEX_LISTSET_REQ) {
  2334. vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2335. addrs = SHMEM2_RD(bp, afex_param2_to_driver[BP_FW_MB_IDX(bp)]);
  2336. DP(BNX2X_MSG_MCP,
  2337. "afex: got MCP req LISTSET_REQ for vifid 0x%x addrs 0x%x\n",
  2338. vifid, addrs);
  2339. bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_SET, vifid,
  2340. addrs);
  2341. }
  2342. if (cmd & DRV_STATUS_AFEX_STATSGET_REQ) {
  2343. addr_to_write = SHMEM2_RD(bp,
  2344. afex_scratchpad_addr_to_write[BP_FW_MB_IDX(bp)]);
  2345. stats_type = SHMEM2_RD(bp,
  2346. afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2347. DP(BNX2X_MSG_MCP,
  2348. "afex: got MCP req STATSGET_REQ, write to addr 0x%x\n",
  2349. addr_to_write);
  2350. bnx2x_afex_collect_stats(bp, (void *)&afex_stats, stats_type);
  2351. /* write response to scratchpad, for MCP */
  2352. for (i = 0; i < (sizeof(struct afex_stats)/sizeof(u32)); i++)
  2353. REG_WR(bp, addr_to_write + i*sizeof(u32),
  2354. *(((u32 *)(&afex_stats))+i));
  2355. /* send ack message to MCP */
  2356. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_STATSGET_ACK, 0);
  2357. }
  2358. if (cmd & DRV_STATUS_AFEX_VIFSET_REQ) {
  2359. mf_config = MF_CFG_RD(bp, func_mf_config[func].config);
  2360. bp->mf_config[BP_VN(bp)] = mf_config;
  2361. DP(BNX2X_MSG_MCP,
  2362. "afex: got MCP req VIFSET_REQ, mf_config 0x%x\n",
  2363. mf_config);
  2364. /* if VIF_SET is "enabled" */
  2365. if (!(mf_config & FUNC_MF_CFG_FUNC_DISABLED)) {
  2366. /* set rate limit directly to internal RAM */
  2367. struct cmng_init_input cmng_input;
  2368. struct rate_shaping_vars_per_vn m_rs_vn;
  2369. size_t size = sizeof(struct rate_shaping_vars_per_vn);
  2370. u32 addr = BAR_XSTRORM_INTMEM +
  2371. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(BP_FUNC(bp));
  2372. bp->mf_config[BP_VN(bp)] = mf_config;
  2373. bnx2x_calc_vn_max(bp, BP_VN(bp), &cmng_input);
  2374. m_rs_vn.vn_counter.rate =
  2375. cmng_input.vnic_max_rate[BP_VN(bp)];
  2376. m_rs_vn.vn_counter.quota =
  2377. (m_rs_vn.vn_counter.rate *
  2378. RS_PERIODIC_TIMEOUT_USEC) / 8;
  2379. __storm_memset_struct(bp, addr, size, (u32 *)&m_rs_vn);
  2380. /* read relevant values from mf_cfg struct in shmem */
  2381. vif_id =
  2382. (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2383. FUNC_MF_CFG_E1HOV_TAG_MASK) >>
  2384. FUNC_MF_CFG_E1HOV_TAG_SHIFT;
  2385. vlan_val =
  2386. (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2387. FUNC_MF_CFG_AFEX_VLAN_MASK) >>
  2388. FUNC_MF_CFG_AFEX_VLAN_SHIFT;
  2389. vlan_prio = (mf_config &
  2390. FUNC_MF_CFG_TRANSMIT_PRIORITY_MASK) >>
  2391. FUNC_MF_CFG_TRANSMIT_PRIORITY_SHIFT;
  2392. vlan_val |= (vlan_prio << VLAN_PRIO_SHIFT);
  2393. vlan_mode =
  2394. (MF_CFG_RD(bp,
  2395. func_mf_config[func].afex_config) &
  2396. FUNC_MF_CFG_AFEX_VLAN_MODE_MASK) >>
  2397. FUNC_MF_CFG_AFEX_VLAN_MODE_SHIFT;
  2398. allowed_prio =
  2399. (MF_CFG_RD(bp,
  2400. func_mf_config[func].afex_config) &
  2401. FUNC_MF_CFG_AFEX_COS_FILTER_MASK) >>
  2402. FUNC_MF_CFG_AFEX_COS_FILTER_SHIFT;
  2403. /* send ramrod to FW, return in case of failure */
  2404. if (bnx2x_afex_func_update(bp, vif_id, vlan_val,
  2405. allowed_prio))
  2406. return;
  2407. bp->afex_def_vlan_tag = vlan_val;
  2408. bp->afex_vlan_mode = vlan_mode;
  2409. } else {
  2410. /* notify link down because BP->flags is disabled */
  2411. bnx2x_link_report(bp);
  2412. /* send INVALID VIF ramrod to FW */
  2413. bnx2x_afex_func_update(bp, 0xFFFF, 0, 0);
  2414. /* Reset the default afex VLAN */
  2415. bp->afex_def_vlan_tag = -1;
  2416. }
  2417. }
  2418. }
  2419. static void bnx2x_pmf_update(struct bnx2x *bp)
  2420. {
  2421. int port = BP_PORT(bp);
  2422. u32 val;
  2423. bp->port.pmf = 1;
  2424. DP(BNX2X_MSG_MCP, "pmf %d\n", bp->port.pmf);
  2425. /*
  2426. * We need the mb() to ensure the ordering between the writing to
  2427. * bp->port.pmf here and reading it from the bnx2x_periodic_task().
  2428. */
  2429. smp_mb();
  2430. /* queue a periodic task */
  2431. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  2432. bnx2x_dcbx_pmf_update(bp);
  2433. /* enable nig attention */
  2434. val = (0xff0f | (1 << (BP_VN(bp) + 4)));
  2435. if (bp->common.int_block == INT_BLOCK_HC) {
  2436. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  2437. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  2438. } else if (!CHIP_IS_E1x(bp)) {
  2439. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  2440. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  2441. }
  2442. bnx2x_stats_handle(bp, STATS_EVENT_PMF);
  2443. }
  2444. /* end of Link */
  2445. /* slow path */
  2446. /*
  2447. * General service functions
  2448. */
  2449. /* send the MCP a request, block until there is a reply */
  2450. u32 bnx2x_fw_command(struct bnx2x *bp, u32 command, u32 param)
  2451. {
  2452. int mb_idx = BP_FW_MB_IDX(bp);
  2453. u32 seq;
  2454. u32 rc = 0;
  2455. u32 cnt = 1;
  2456. u8 delay = CHIP_REV_IS_SLOW(bp) ? 100 : 10;
  2457. mutex_lock(&bp->fw_mb_mutex);
  2458. seq = ++bp->fw_seq;
  2459. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_param, param);
  2460. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_header, (command | seq));
  2461. DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB param 0x%08x\n",
  2462. (command | seq), param);
  2463. do {
  2464. /* let the FW do it's magic ... */
  2465. msleep(delay);
  2466. rc = SHMEM_RD(bp, func_mb[mb_idx].fw_mb_header);
  2467. /* Give the FW up to 5 second (500*10ms) */
  2468. } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500));
  2469. DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n",
  2470. cnt*delay, rc, seq);
  2471. /* is this a reply to our command? */
  2472. if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK))
  2473. rc &= FW_MSG_CODE_MASK;
  2474. else {
  2475. /* FW BUG! */
  2476. BNX2X_ERR("FW failed to respond!\n");
  2477. bnx2x_fw_dump(bp);
  2478. rc = 0;
  2479. }
  2480. mutex_unlock(&bp->fw_mb_mutex);
  2481. return rc;
  2482. }
  2483. static void storm_memset_func_cfg(struct bnx2x *bp,
  2484. struct tstorm_eth_function_common_config *tcfg,
  2485. u16 abs_fid)
  2486. {
  2487. size_t size = sizeof(struct tstorm_eth_function_common_config);
  2488. u32 addr = BAR_TSTRORM_INTMEM +
  2489. TSTORM_FUNCTION_COMMON_CONFIG_OFFSET(abs_fid);
  2490. __storm_memset_struct(bp, addr, size, (u32 *)tcfg);
  2491. }
  2492. void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p)
  2493. {
  2494. if (CHIP_IS_E1x(bp)) {
  2495. struct tstorm_eth_function_common_config tcfg = {0};
  2496. storm_memset_func_cfg(bp, &tcfg, p->func_id);
  2497. }
  2498. /* Enable the function in the FW */
  2499. storm_memset_vf_to_pf(bp, p->func_id, p->pf_id);
  2500. storm_memset_func_en(bp, p->func_id, 1);
  2501. /* spq */
  2502. if (p->func_flgs & FUNC_FLG_SPQ) {
  2503. storm_memset_spq_addr(bp, p->spq_map, p->func_id);
  2504. REG_WR(bp, XSEM_REG_FAST_MEMORY +
  2505. XSTORM_SPQ_PROD_OFFSET(p->func_id), p->spq_prod);
  2506. }
  2507. }
  2508. /**
  2509. * bnx2x_get_common_flags - Return common flags
  2510. *
  2511. * @bp device handle
  2512. * @fp queue handle
  2513. * @zero_stats TRUE if statistics zeroing is needed
  2514. *
  2515. * Return the flags that are common for the Tx-only and not normal connections.
  2516. */
  2517. static unsigned long bnx2x_get_common_flags(struct bnx2x *bp,
  2518. struct bnx2x_fastpath *fp,
  2519. bool zero_stats)
  2520. {
  2521. unsigned long flags = 0;
  2522. /* PF driver will always initialize the Queue to an ACTIVE state */
  2523. __set_bit(BNX2X_Q_FLG_ACTIVE, &flags);
  2524. /* tx only connections collect statistics (on the same index as the
  2525. * parent connection). The statistics are zeroed when the parent
  2526. * connection is initialized.
  2527. */
  2528. __set_bit(BNX2X_Q_FLG_STATS, &flags);
  2529. if (zero_stats)
  2530. __set_bit(BNX2X_Q_FLG_ZERO_STATS, &flags);
  2531. __set_bit(BNX2X_Q_FLG_PCSUM_ON_PKT, &flags);
  2532. __set_bit(BNX2X_Q_FLG_TUN_INC_INNER_IP_ID, &flags);
  2533. #ifdef BNX2X_STOP_ON_ERROR
  2534. __set_bit(BNX2X_Q_FLG_TX_SEC, &flags);
  2535. #endif
  2536. return flags;
  2537. }
  2538. static unsigned long bnx2x_get_q_flags(struct bnx2x *bp,
  2539. struct bnx2x_fastpath *fp,
  2540. bool leading)
  2541. {
  2542. unsigned long flags = 0;
  2543. /* calculate other queue flags */
  2544. if (IS_MF_SD(bp))
  2545. __set_bit(BNX2X_Q_FLG_OV, &flags);
  2546. if (IS_FCOE_FP(fp)) {
  2547. __set_bit(BNX2X_Q_FLG_FCOE, &flags);
  2548. /* For FCoE - force usage of default priority (for afex) */
  2549. __set_bit(BNX2X_Q_FLG_FORCE_DEFAULT_PRI, &flags);
  2550. }
  2551. if (!fp->disable_tpa) {
  2552. __set_bit(BNX2X_Q_FLG_TPA, &flags);
  2553. __set_bit(BNX2X_Q_FLG_TPA_IPV6, &flags);
  2554. if (fp->mode == TPA_MODE_GRO)
  2555. __set_bit(BNX2X_Q_FLG_TPA_GRO, &flags);
  2556. }
  2557. if (leading) {
  2558. __set_bit(BNX2X_Q_FLG_LEADING_RSS, &flags);
  2559. __set_bit(BNX2X_Q_FLG_MCAST, &flags);
  2560. }
  2561. /* Always set HW VLAN stripping */
  2562. __set_bit(BNX2X_Q_FLG_VLAN, &flags);
  2563. /* configure silent vlan removal */
  2564. if (IS_MF_AFEX(bp))
  2565. __set_bit(BNX2X_Q_FLG_SILENT_VLAN_REM, &flags);
  2566. return flags | bnx2x_get_common_flags(bp, fp, true);
  2567. }
  2568. static void bnx2x_pf_q_prep_general(struct bnx2x *bp,
  2569. struct bnx2x_fastpath *fp, struct bnx2x_general_setup_params *gen_init,
  2570. u8 cos)
  2571. {
  2572. gen_init->stat_id = bnx2x_stats_id(fp);
  2573. gen_init->spcl_id = fp->cl_id;
  2574. /* Always use mini-jumbo MTU for FCoE L2 ring */
  2575. if (IS_FCOE_FP(fp))
  2576. gen_init->mtu = BNX2X_FCOE_MINI_JUMBO_MTU;
  2577. else
  2578. gen_init->mtu = bp->dev->mtu;
  2579. gen_init->cos = cos;
  2580. }
  2581. static void bnx2x_pf_rx_q_prep(struct bnx2x *bp,
  2582. struct bnx2x_fastpath *fp, struct rxq_pause_params *pause,
  2583. struct bnx2x_rxq_setup_params *rxq_init)
  2584. {
  2585. u8 max_sge = 0;
  2586. u16 sge_sz = 0;
  2587. u16 tpa_agg_size = 0;
  2588. if (!fp->disable_tpa) {
  2589. pause->sge_th_lo = SGE_TH_LO(bp);
  2590. pause->sge_th_hi = SGE_TH_HI(bp);
  2591. /* validate SGE ring has enough to cross high threshold */
  2592. WARN_ON(bp->dropless_fc &&
  2593. pause->sge_th_hi + FW_PREFETCH_CNT >
  2594. MAX_RX_SGE_CNT * NUM_RX_SGE_PAGES);
  2595. tpa_agg_size = TPA_AGG_SIZE;
  2596. max_sge = SGE_PAGE_ALIGN(bp->dev->mtu) >>
  2597. SGE_PAGE_SHIFT;
  2598. max_sge = ((max_sge + PAGES_PER_SGE - 1) &
  2599. (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
  2600. sge_sz = (u16)min_t(u32, SGE_PAGES, 0xffff);
  2601. }
  2602. /* pause - not for e1 */
  2603. if (!CHIP_IS_E1(bp)) {
  2604. pause->bd_th_lo = BD_TH_LO(bp);
  2605. pause->bd_th_hi = BD_TH_HI(bp);
  2606. pause->rcq_th_lo = RCQ_TH_LO(bp);
  2607. pause->rcq_th_hi = RCQ_TH_HI(bp);
  2608. /*
  2609. * validate that rings have enough entries to cross
  2610. * high thresholds
  2611. */
  2612. WARN_ON(bp->dropless_fc &&
  2613. pause->bd_th_hi + FW_PREFETCH_CNT >
  2614. bp->rx_ring_size);
  2615. WARN_ON(bp->dropless_fc &&
  2616. pause->rcq_th_hi + FW_PREFETCH_CNT >
  2617. NUM_RCQ_RINGS * MAX_RCQ_DESC_CNT);
  2618. pause->pri_map = 1;
  2619. }
  2620. /* rxq setup */
  2621. rxq_init->dscr_map = fp->rx_desc_mapping;
  2622. rxq_init->sge_map = fp->rx_sge_mapping;
  2623. rxq_init->rcq_map = fp->rx_comp_mapping;
  2624. rxq_init->rcq_np_map = fp->rx_comp_mapping + BCM_PAGE_SIZE;
  2625. /* This should be a maximum number of data bytes that may be
  2626. * placed on the BD (not including paddings).
  2627. */
  2628. rxq_init->buf_sz = fp->rx_buf_size - BNX2X_FW_RX_ALIGN_START -
  2629. BNX2X_FW_RX_ALIGN_END - IP_HEADER_ALIGNMENT_PADDING;
  2630. rxq_init->cl_qzone_id = fp->cl_qzone_id;
  2631. rxq_init->tpa_agg_sz = tpa_agg_size;
  2632. rxq_init->sge_buf_sz = sge_sz;
  2633. rxq_init->max_sges_pkt = max_sge;
  2634. rxq_init->rss_engine_id = BP_FUNC(bp);
  2635. rxq_init->mcast_engine_id = BP_FUNC(bp);
  2636. /* Maximum number or simultaneous TPA aggregation for this Queue.
  2637. *
  2638. * For PF Clients it should be the maximum available number.
  2639. * VF driver(s) may want to define it to a smaller value.
  2640. */
  2641. rxq_init->max_tpa_queues = MAX_AGG_QS(bp);
  2642. rxq_init->cache_line_log = BNX2X_RX_ALIGN_SHIFT;
  2643. rxq_init->fw_sb_id = fp->fw_sb_id;
  2644. if (IS_FCOE_FP(fp))
  2645. rxq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS;
  2646. else
  2647. rxq_init->sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  2648. /* configure silent vlan removal
  2649. * if multi function mode is afex, then mask default vlan
  2650. */
  2651. if (IS_MF_AFEX(bp)) {
  2652. rxq_init->silent_removal_value = bp->afex_def_vlan_tag;
  2653. rxq_init->silent_removal_mask = VLAN_VID_MASK;
  2654. }
  2655. }
  2656. static void bnx2x_pf_tx_q_prep(struct bnx2x *bp,
  2657. struct bnx2x_fastpath *fp, struct bnx2x_txq_setup_params *txq_init,
  2658. u8 cos)
  2659. {
  2660. txq_init->dscr_map = fp->txdata_ptr[cos]->tx_desc_mapping;
  2661. txq_init->sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS + cos;
  2662. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_NW;
  2663. txq_init->fw_sb_id = fp->fw_sb_id;
  2664. /*
  2665. * set the tss leading client id for TX classification ==
  2666. * leading RSS client id
  2667. */
  2668. txq_init->tss_leading_cl_id = bnx2x_fp(bp, 0, cl_id);
  2669. if (IS_FCOE_FP(fp)) {
  2670. txq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS;
  2671. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_FCOE;
  2672. }
  2673. }
  2674. static void bnx2x_pf_init(struct bnx2x *bp)
  2675. {
  2676. struct bnx2x_func_init_params func_init = {0};
  2677. struct event_ring_data eq_data = { {0} };
  2678. u16 flags;
  2679. if (!CHIP_IS_E1x(bp)) {
  2680. /* reset IGU PF statistics: MSIX + ATTN */
  2681. /* PF */
  2682. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2683. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2684. (CHIP_MODE_IS_4_PORT(bp) ?
  2685. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2686. /* ATTN */
  2687. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2688. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2689. BNX2X_IGU_STAS_MSG_PF_CNT*4 +
  2690. (CHIP_MODE_IS_4_PORT(bp) ?
  2691. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2692. }
  2693. /* function setup flags */
  2694. flags = (FUNC_FLG_STATS | FUNC_FLG_LEADING | FUNC_FLG_SPQ);
  2695. /* This flag is relevant for E1x only.
  2696. * E2 doesn't have a TPA configuration in a function level.
  2697. */
  2698. flags |= (bp->flags & TPA_ENABLE_FLAG) ? FUNC_FLG_TPA : 0;
  2699. func_init.func_flgs = flags;
  2700. func_init.pf_id = BP_FUNC(bp);
  2701. func_init.func_id = BP_FUNC(bp);
  2702. func_init.spq_map = bp->spq_mapping;
  2703. func_init.spq_prod = bp->spq_prod_idx;
  2704. bnx2x_func_init(bp, &func_init);
  2705. memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port));
  2706. /*
  2707. * Congestion management values depend on the link rate
  2708. * There is no active link so initial link rate is set to 10 Gbps.
  2709. * When the link comes up The congestion management values are
  2710. * re-calculated according to the actual link rate.
  2711. */
  2712. bp->link_vars.line_speed = SPEED_10000;
  2713. bnx2x_cmng_fns_init(bp, true, bnx2x_get_cmng_fns_mode(bp));
  2714. /* Only the PMF sets the HW */
  2715. if (bp->port.pmf)
  2716. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2717. /* init Event Queue - PCI bus guarantees correct endianity*/
  2718. eq_data.base_addr.hi = U64_HI(bp->eq_mapping);
  2719. eq_data.base_addr.lo = U64_LO(bp->eq_mapping);
  2720. eq_data.producer = bp->eq_prod;
  2721. eq_data.index_id = HC_SP_INDEX_EQ_CONS;
  2722. eq_data.sb_id = DEF_SB_ID;
  2723. storm_memset_eq_data(bp, &eq_data, BP_FUNC(bp));
  2724. }
  2725. static void bnx2x_e1h_disable(struct bnx2x *bp)
  2726. {
  2727. int port = BP_PORT(bp);
  2728. bnx2x_tx_disable(bp);
  2729. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  2730. }
  2731. static void bnx2x_e1h_enable(struct bnx2x *bp)
  2732. {
  2733. int port = BP_PORT(bp);
  2734. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
  2735. /* Tx queue should be only re-enabled */
  2736. netif_tx_wake_all_queues(bp->dev);
  2737. /*
  2738. * Should not call netif_carrier_on since it will be called if the link
  2739. * is up when checking for link state
  2740. */
  2741. }
  2742. #define DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED 3
  2743. static void bnx2x_drv_info_ether_stat(struct bnx2x *bp)
  2744. {
  2745. struct eth_stats_info *ether_stat =
  2746. &bp->slowpath->drv_info_to_mcp.ether_stat;
  2747. struct bnx2x_vlan_mac_obj *mac_obj =
  2748. &bp->sp_objs->mac_obj;
  2749. int i;
  2750. strlcpy(ether_stat->version, DRV_MODULE_VERSION,
  2751. ETH_STAT_INFO_VERSION_LEN);
  2752. /* get DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED macs, placing them in the
  2753. * mac_local field in ether_stat struct. The base address is offset by 2
  2754. * bytes to account for the field being 8 bytes but a mac address is
  2755. * only 6 bytes. Likewise, the stride for the get_n_elements function is
  2756. * 2 bytes to compensate from the 6 bytes of a mac to the 8 bytes
  2757. * allocated by the ether_stat struct, so the macs will land in their
  2758. * proper positions.
  2759. */
  2760. for (i = 0; i < DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED; i++)
  2761. memset(ether_stat->mac_local + i, 0,
  2762. sizeof(ether_stat->mac_local[0]));
  2763. mac_obj->get_n_elements(bp, &bp->sp_objs[0].mac_obj,
  2764. DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED,
  2765. ether_stat->mac_local + MAC_PAD, MAC_PAD,
  2766. ETH_ALEN);
  2767. ether_stat->mtu_size = bp->dev->mtu;
  2768. if (bp->dev->features & NETIF_F_RXCSUM)
  2769. ether_stat->feature_flags |= FEATURE_ETH_CHKSUM_OFFLOAD_MASK;
  2770. if (bp->dev->features & NETIF_F_TSO)
  2771. ether_stat->feature_flags |= FEATURE_ETH_LSO_MASK;
  2772. ether_stat->feature_flags |= bp->common.boot_mode;
  2773. ether_stat->promiscuous_mode = (bp->dev->flags & IFF_PROMISC) ? 1 : 0;
  2774. ether_stat->txq_size = bp->tx_ring_size;
  2775. ether_stat->rxq_size = bp->rx_ring_size;
  2776. }
  2777. static void bnx2x_drv_info_fcoe_stat(struct bnx2x *bp)
  2778. {
  2779. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2780. struct fcoe_stats_info *fcoe_stat =
  2781. &bp->slowpath->drv_info_to_mcp.fcoe_stat;
  2782. if (!CNIC_LOADED(bp))
  2783. return;
  2784. memcpy(fcoe_stat->mac_local + MAC_PAD, bp->fip_mac, ETH_ALEN);
  2785. fcoe_stat->qos_priority =
  2786. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_FCOE];
  2787. /* insert FCoE stats from ramrod response */
  2788. if (!NO_FCOE(bp)) {
  2789. struct tstorm_per_queue_stats *fcoe_q_tstorm_stats =
  2790. &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
  2791. tstorm_queue_statistics;
  2792. struct xstorm_per_queue_stats *fcoe_q_xstorm_stats =
  2793. &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
  2794. xstorm_queue_statistics;
  2795. struct fcoe_statistics_params *fw_fcoe_stat =
  2796. &bp->fw_stats_data->fcoe;
  2797. ADD_64_LE(fcoe_stat->rx_bytes_hi, LE32_0,
  2798. fcoe_stat->rx_bytes_lo,
  2799. fw_fcoe_stat->rx_stat0.fcoe_rx_byte_cnt);
  2800. ADD_64_LE(fcoe_stat->rx_bytes_hi,
  2801. fcoe_q_tstorm_stats->rcv_ucast_bytes.hi,
  2802. fcoe_stat->rx_bytes_lo,
  2803. fcoe_q_tstorm_stats->rcv_ucast_bytes.lo);
  2804. ADD_64_LE(fcoe_stat->rx_bytes_hi,
  2805. fcoe_q_tstorm_stats->rcv_bcast_bytes.hi,
  2806. fcoe_stat->rx_bytes_lo,
  2807. fcoe_q_tstorm_stats->rcv_bcast_bytes.lo);
  2808. ADD_64_LE(fcoe_stat->rx_bytes_hi,
  2809. fcoe_q_tstorm_stats->rcv_mcast_bytes.hi,
  2810. fcoe_stat->rx_bytes_lo,
  2811. fcoe_q_tstorm_stats->rcv_mcast_bytes.lo);
  2812. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2813. fcoe_stat->rx_frames_lo,
  2814. fw_fcoe_stat->rx_stat0.fcoe_rx_pkt_cnt);
  2815. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2816. fcoe_stat->rx_frames_lo,
  2817. fcoe_q_tstorm_stats->rcv_ucast_pkts);
  2818. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2819. fcoe_stat->rx_frames_lo,
  2820. fcoe_q_tstorm_stats->rcv_bcast_pkts);
  2821. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2822. fcoe_stat->rx_frames_lo,
  2823. fcoe_q_tstorm_stats->rcv_mcast_pkts);
  2824. ADD_64_LE(fcoe_stat->tx_bytes_hi, LE32_0,
  2825. fcoe_stat->tx_bytes_lo,
  2826. fw_fcoe_stat->tx_stat.fcoe_tx_byte_cnt);
  2827. ADD_64_LE(fcoe_stat->tx_bytes_hi,
  2828. fcoe_q_xstorm_stats->ucast_bytes_sent.hi,
  2829. fcoe_stat->tx_bytes_lo,
  2830. fcoe_q_xstorm_stats->ucast_bytes_sent.lo);
  2831. ADD_64_LE(fcoe_stat->tx_bytes_hi,
  2832. fcoe_q_xstorm_stats->bcast_bytes_sent.hi,
  2833. fcoe_stat->tx_bytes_lo,
  2834. fcoe_q_xstorm_stats->bcast_bytes_sent.lo);
  2835. ADD_64_LE(fcoe_stat->tx_bytes_hi,
  2836. fcoe_q_xstorm_stats->mcast_bytes_sent.hi,
  2837. fcoe_stat->tx_bytes_lo,
  2838. fcoe_q_xstorm_stats->mcast_bytes_sent.lo);
  2839. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2840. fcoe_stat->tx_frames_lo,
  2841. fw_fcoe_stat->tx_stat.fcoe_tx_pkt_cnt);
  2842. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2843. fcoe_stat->tx_frames_lo,
  2844. fcoe_q_xstorm_stats->ucast_pkts_sent);
  2845. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2846. fcoe_stat->tx_frames_lo,
  2847. fcoe_q_xstorm_stats->bcast_pkts_sent);
  2848. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2849. fcoe_stat->tx_frames_lo,
  2850. fcoe_q_xstorm_stats->mcast_pkts_sent);
  2851. }
  2852. /* ask L5 driver to add data to the struct */
  2853. bnx2x_cnic_notify(bp, CNIC_CTL_FCOE_STATS_GET_CMD);
  2854. }
  2855. static void bnx2x_drv_info_iscsi_stat(struct bnx2x *bp)
  2856. {
  2857. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2858. struct iscsi_stats_info *iscsi_stat =
  2859. &bp->slowpath->drv_info_to_mcp.iscsi_stat;
  2860. if (!CNIC_LOADED(bp))
  2861. return;
  2862. memcpy(iscsi_stat->mac_local + MAC_PAD, bp->cnic_eth_dev.iscsi_mac,
  2863. ETH_ALEN);
  2864. iscsi_stat->qos_priority =
  2865. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_ISCSI];
  2866. /* ask L5 driver to add data to the struct */
  2867. bnx2x_cnic_notify(bp, CNIC_CTL_ISCSI_STATS_GET_CMD);
  2868. }
  2869. /* called due to MCP event (on pmf):
  2870. * reread new bandwidth configuration
  2871. * configure FW
  2872. * notify others function about the change
  2873. */
  2874. static void bnx2x_config_mf_bw(struct bnx2x *bp)
  2875. {
  2876. if (bp->link_vars.link_up) {
  2877. bnx2x_cmng_fns_init(bp, true, CMNG_FNS_MINMAX);
  2878. bnx2x_link_sync_notify(bp);
  2879. }
  2880. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2881. }
  2882. static void bnx2x_set_mf_bw(struct bnx2x *bp)
  2883. {
  2884. bnx2x_config_mf_bw(bp);
  2885. bnx2x_fw_command(bp, DRV_MSG_CODE_SET_MF_BW_ACK, 0);
  2886. }
  2887. static void bnx2x_handle_eee_event(struct bnx2x *bp)
  2888. {
  2889. DP(BNX2X_MSG_MCP, "EEE - LLDP event\n");
  2890. bnx2x_fw_command(bp, DRV_MSG_CODE_EEE_RESULTS_ACK, 0);
  2891. }
  2892. static void bnx2x_handle_drv_info_req(struct bnx2x *bp)
  2893. {
  2894. enum drv_info_opcode op_code;
  2895. u32 drv_info_ctl = SHMEM2_RD(bp, drv_info_control);
  2896. /* if drv_info version supported by MFW doesn't match - send NACK */
  2897. if ((drv_info_ctl & DRV_INFO_CONTROL_VER_MASK) != DRV_INFO_CUR_VER) {
  2898. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  2899. return;
  2900. }
  2901. op_code = (drv_info_ctl & DRV_INFO_CONTROL_OP_CODE_MASK) >>
  2902. DRV_INFO_CONTROL_OP_CODE_SHIFT;
  2903. memset(&bp->slowpath->drv_info_to_mcp, 0,
  2904. sizeof(union drv_info_to_mcp));
  2905. switch (op_code) {
  2906. case ETH_STATS_OPCODE:
  2907. bnx2x_drv_info_ether_stat(bp);
  2908. break;
  2909. case FCOE_STATS_OPCODE:
  2910. bnx2x_drv_info_fcoe_stat(bp);
  2911. break;
  2912. case ISCSI_STATS_OPCODE:
  2913. bnx2x_drv_info_iscsi_stat(bp);
  2914. break;
  2915. default:
  2916. /* if op code isn't supported - send NACK */
  2917. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  2918. return;
  2919. }
  2920. /* if we got drv_info attn from MFW then these fields are defined in
  2921. * shmem2 for sure
  2922. */
  2923. SHMEM2_WR(bp, drv_info_host_addr_lo,
  2924. U64_LO(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  2925. SHMEM2_WR(bp, drv_info_host_addr_hi,
  2926. U64_HI(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  2927. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_ACK, 0);
  2928. }
  2929. static void bnx2x_dcc_event(struct bnx2x *bp, u32 dcc_event)
  2930. {
  2931. DP(BNX2X_MSG_MCP, "dcc_event 0x%x\n", dcc_event);
  2932. if (dcc_event & DRV_STATUS_DCC_DISABLE_ENABLE_PF) {
  2933. /*
  2934. * This is the only place besides the function initialization
  2935. * where the bp->flags can change so it is done without any
  2936. * locks
  2937. */
  2938. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  2939. DP(BNX2X_MSG_MCP, "mf_cfg function disabled\n");
  2940. bp->flags |= MF_FUNC_DIS;
  2941. bnx2x_e1h_disable(bp);
  2942. } else {
  2943. DP(BNX2X_MSG_MCP, "mf_cfg function enabled\n");
  2944. bp->flags &= ~MF_FUNC_DIS;
  2945. bnx2x_e1h_enable(bp);
  2946. }
  2947. dcc_event &= ~DRV_STATUS_DCC_DISABLE_ENABLE_PF;
  2948. }
  2949. if (dcc_event & DRV_STATUS_DCC_BANDWIDTH_ALLOCATION) {
  2950. bnx2x_config_mf_bw(bp);
  2951. dcc_event &= ~DRV_STATUS_DCC_BANDWIDTH_ALLOCATION;
  2952. }
  2953. /* Report results to MCP */
  2954. if (dcc_event)
  2955. bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_FAILURE, 0);
  2956. else
  2957. bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_OK, 0);
  2958. }
  2959. /* must be called under the spq lock */
  2960. static struct eth_spe *bnx2x_sp_get_next(struct bnx2x *bp)
  2961. {
  2962. struct eth_spe *next_spe = bp->spq_prod_bd;
  2963. if (bp->spq_prod_bd == bp->spq_last_bd) {
  2964. bp->spq_prod_bd = bp->spq;
  2965. bp->spq_prod_idx = 0;
  2966. DP(BNX2X_MSG_SP, "end of spq\n");
  2967. } else {
  2968. bp->spq_prod_bd++;
  2969. bp->spq_prod_idx++;
  2970. }
  2971. return next_spe;
  2972. }
  2973. /* must be called under the spq lock */
  2974. static void bnx2x_sp_prod_update(struct bnx2x *bp)
  2975. {
  2976. int func = BP_FUNC(bp);
  2977. /*
  2978. * Make sure that BD data is updated before writing the producer:
  2979. * BD data is written to the memory, the producer is read from the
  2980. * memory, thus we need a full memory barrier to ensure the ordering.
  2981. */
  2982. mb();
  2983. REG_WR16(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func),
  2984. bp->spq_prod_idx);
  2985. mmiowb();
  2986. }
  2987. /**
  2988. * bnx2x_is_contextless_ramrod - check if the current command ends on EQ
  2989. *
  2990. * @cmd: command to check
  2991. * @cmd_type: command type
  2992. */
  2993. static bool bnx2x_is_contextless_ramrod(int cmd, int cmd_type)
  2994. {
  2995. if ((cmd_type == NONE_CONNECTION_TYPE) ||
  2996. (cmd == RAMROD_CMD_ID_ETH_FORWARD_SETUP) ||
  2997. (cmd == RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES) ||
  2998. (cmd == RAMROD_CMD_ID_ETH_FILTER_RULES) ||
  2999. (cmd == RAMROD_CMD_ID_ETH_MULTICAST_RULES) ||
  3000. (cmd == RAMROD_CMD_ID_ETH_SET_MAC) ||
  3001. (cmd == RAMROD_CMD_ID_ETH_RSS_UPDATE))
  3002. return true;
  3003. else
  3004. return false;
  3005. }
  3006. /**
  3007. * bnx2x_sp_post - place a single command on an SP ring
  3008. *
  3009. * @bp: driver handle
  3010. * @command: command to place (e.g. SETUP, FILTER_RULES, etc.)
  3011. * @cid: SW CID the command is related to
  3012. * @data_hi: command private data address (high 32 bits)
  3013. * @data_lo: command private data address (low 32 bits)
  3014. * @cmd_type: command type (e.g. NONE, ETH)
  3015. *
  3016. * SP data is handled as if it's always an address pair, thus data fields are
  3017. * not swapped to little endian in upper functions. Instead this function swaps
  3018. * data as if it's two u32 fields.
  3019. */
  3020. int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
  3021. u32 data_hi, u32 data_lo, int cmd_type)
  3022. {
  3023. struct eth_spe *spe;
  3024. u16 type;
  3025. bool common = bnx2x_is_contextless_ramrod(command, cmd_type);
  3026. #ifdef BNX2X_STOP_ON_ERROR
  3027. if (unlikely(bp->panic)) {
  3028. BNX2X_ERR("Can't post SP when there is panic\n");
  3029. return -EIO;
  3030. }
  3031. #endif
  3032. spin_lock_bh(&bp->spq_lock);
  3033. if (common) {
  3034. if (!atomic_read(&bp->eq_spq_left)) {
  3035. BNX2X_ERR("BUG! EQ ring full!\n");
  3036. spin_unlock_bh(&bp->spq_lock);
  3037. bnx2x_panic();
  3038. return -EBUSY;
  3039. }
  3040. } else if (!atomic_read(&bp->cq_spq_left)) {
  3041. BNX2X_ERR("BUG! SPQ ring full!\n");
  3042. spin_unlock_bh(&bp->spq_lock);
  3043. bnx2x_panic();
  3044. return -EBUSY;
  3045. }
  3046. spe = bnx2x_sp_get_next(bp);
  3047. /* CID needs port number to be encoded int it */
  3048. spe->hdr.conn_and_cmd_data =
  3049. cpu_to_le32((command << SPE_HDR_CMD_ID_SHIFT) |
  3050. HW_CID(bp, cid));
  3051. type = (cmd_type << SPE_HDR_CONN_TYPE_SHIFT) & SPE_HDR_CONN_TYPE;
  3052. type |= ((BP_FUNC(bp) << SPE_HDR_FUNCTION_ID_SHIFT) &
  3053. SPE_HDR_FUNCTION_ID);
  3054. spe->hdr.type = cpu_to_le16(type);
  3055. spe->data.update_data_addr.hi = cpu_to_le32(data_hi);
  3056. spe->data.update_data_addr.lo = cpu_to_le32(data_lo);
  3057. /*
  3058. * It's ok if the actual decrement is issued towards the memory
  3059. * somewhere between the spin_lock and spin_unlock. Thus no
  3060. * more explicit memory barrier is needed.
  3061. */
  3062. if (common)
  3063. atomic_dec(&bp->eq_spq_left);
  3064. else
  3065. atomic_dec(&bp->cq_spq_left);
  3066. DP(BNX2X_MSG_SP,
  3067. "SPQE[%x] (%x:%x) (cmd, common?) (%d,%d) hw_cid %x data (%x:%x) type(0x%x) left (CQ, EQ) (%x,%x)\n",
  3068. bp->spq_prod_idx, (u32)U64_HI(bp->spq_mapping),
  3069. (u32)(U64_LO(bp->spq_mapping) +
  3070. (void *)bp->spq_prod_bd - (void *)bp->spq), command, common,
  3071. HW_CID(bp, cid), data_hi, data_lo, type,
  3072. atomic_read(&bp->cq_spq_left), atomic_read(&bp->eq_spq_left));
  3073. bnx2x_sp_prod_update(bp);
  3074. spin_unlock_bh(&bp->spq_lock);
  3075. return 0;
  3076. }
  3077. /* acquire split MCP access lock register */
  3078. static int bnx2x_acquire_alr(struct bnx2x *bp)
  3079. {
  3080. u32 j, val;
  3081. int rc = 0;
  3082. might_sleep();
  3083. for (j = 0; j < 1000; j++) {
  3084. REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, MCPR_ACCESS_LOCK_LOCK);
  3085. val = REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK);
  3086. if (val & MCPR_ACCESS_LOCK_LOCK)
  3087. break;
  3088. usleep_range(5000, 10000);
  3089. }
  3090. if (!(val & MCPR_ACCESS_LOCK_LOCK)) {
  3091. BNX2X_ERR("Cannot acquire MCP access lock register\n");
  3092. rc = -EBUSY;
  3093. }
  3094. return rc;
  3095. }
  3096. /* release split MCP access lock register */
  3097. static void bnx2x_release_alr(struct bnx2x *bp)
  3098. {
  3099. REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, 0);
  3100. }
  3101. #define BNX2X_DEF_SB_ATT_IDX 0x0001
  3102. #define BNX2X_DEF_SB_IDX 0x0002
  3103. static u16 bnx2x_update_dsb_idx(struct bnx2x *bp)
  3104. {
  3105. struct host_sp_status_block *def_sb = bp->def_status_blk;
  3106. u16 rc = 0;
  3107. barrier(); /* status block is written to by the chip */
  3108. if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) {
  3109. bp->def_att_idx = def_sb->atten_status_block.attn_bits_index;
  3110. rc |= BNX2X_DEF_SB_ATT_IDX;
  3111. }
  3112. if (bp->def_idx != def_sb->sp_sb.running_index) {
  3113. bp->def_idx = def_sb->sp_sb.running_index;
  3114. rc |= BNX2X_DEF_SB_IDX;
  3115. }
  3116. /* Do not reorder: indices reading should complete before handling */
  3117. barrier();
  3118. return rc;
  3119. }
  3120. /*
  3121. * slow path service functions
  3122. */
  3123. static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted)
  3124. {
  3125. int port = BP_PORT(bp);
  3126. u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  3127. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  3128. u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 :
  3129. NIG_REG_MASK_INTERRUPT_PORT0;
  3130. u32 aeu_mask;
  3131. u32 nig_mask = 0;
  3132. u32 reg_addr;
  3133. if (bp->attn_state & asserted)
  3134. BNX2X_ERR("IGU ERROR\n");
  3135. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3136. aeu_mask = REG_RD(bp, aeu_addr);
  3137. DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n",
  3138. aeu_mask, asserted);
  3139. aeu_mask &= ~(asserted & 0x3ff);
  3140. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  3141. REG_WR(bp, aeu_addr, aeu_mask);
  3142. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3143. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  3144. bp->attn_state |= asserted;
  3145. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  3146. if (asserted & ATTN_HARD_WIRED_MASK) {
  3147. if (asserted & ATTN_NIG_FOR_FUNC) {
  3148. bnx2x_acquire_phy_lock(bp);
  3149. /* save nig interrupt mask */
  3150. nig_mask = REG_RD(bp, nig_int_mask_addr);
  3151. /* If nig_mask is not set, no need to call the update
  3152. * function.
  3153. */
  3154. if (nig_mask) {
  3155. REG_WR(bp, nig_int_mask_addr, 0);
  3156. bnx2x_link_attn(bp);
  3157. }
  3158. /* handle unicore attn? */
  3159. }
  3160. if (asserted & ATTN_SW_TIMER_4_FUNC)
  3161. DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n");
  3162. if (asserted & GPIO_2_FUNC)
  3163. DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n");
  3164. if (asserted & GPIO_3_FUNC)
  3165. DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n");
  3166. if (asserted & GPIO_4_FUNC)
  3167. DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n");
  3168. if (port == 0) {
  3169. if (asserted & ATTN_GENERAL_ATTN_1) {
  3170. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n");
  3171. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0);
  3172. }
  3173. if (asserted & ATTN_GENERAL_ATTN_2) {
  3174. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n");
  3175. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0);
  3176. }
  3177. if (asserted & ATTN_GENERAL_ATTN_3) {
  3178. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n");
  3179. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0);
  3180. }
  3181. } else {
  3182. if (asserted & ATTN_GENERAL_ATTN_4) {
  3183. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n");
  3184. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0);
  3185. }
  3186. if (asserted & ATTN_GENERAL_ATTN_5) {
  3187. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n");
  3188. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0);
  3189. }
  3190. if (asserted & ATTN_GENERAL_ATTN_6) {
  3191. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n");
  3192. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0);
  3193. }
  3194. }
  3195. } /* if hardwired */
  3196. if (bp->common.int_block == INT_BLOCK_HC)
  3197. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  3198. COMMAND_REG_ATTN_BITS_SET);
  3199. else
  3200. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_SET_UPPER*8);
  3201. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", asserted,
  3202. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  3203. REG_WR(bp, reg_addr, asserted);
  3204. /* now set back the mask */
  3205. if (asserted & ATTN_NIG_FOR_FUNC) {
  3206. /* Verify that IGU ack through BAR was written before restoring
  3207. * NIG mask. This loop should exit after 2-3 iterations max.
  3208. */
  3209. if (bp->common.int_block != INT_BLOCK_HC) {
  3210. u32 cnt = 0, igu_acked;
  3211. do {
  3212. igu_acked = REG_RD(bp,
  3213. IGU_REG_ATTENTION_ACK_BITS);
  3214. } while (((igu_acked & ATTN_NIG_FOR_FUNC) == 0) &&
  3215. (++cnt < MAX_IGU_ATTN_ACK_TO));
  3216. if (!igu_acked)
  3217. DP(NETIF_MSG_HW,
  3218. "Failed to verify IGU ack on time\n");
  3219. barrier();
  3220. }
  3221. REG_WR(bp, nig_int_mask_addr, nig_mask);
  3222. bnx2x_release_phy_lock(bp);
  3223. }
  3224. }
  3225. static void bnx2x_fan_failure(struct bnx2x *bp)
  3226. {
  3227. int port = BP_PORT(bp);
  3228. u32 ext_phy_config;
  3229. /* mark the failure */
  3230. ext_phy_config =
  3231. SHMEM_RD(bp,
  3232. dev_info.port_hw_config[port].external_phy_config);
  3233. ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
  3234. ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE;
  3235. SHMEM_WR(bp, dev_info.port_hw_config[port].external_phy_config,
  3236. ext_phy_config);
  3237. /* log the failure */
  3238. netdev_err(bp->dev, "Fan Failure on Network Controller has caused the driver to shutdown the card to prevent permanent damage.\n"
  3239. "Please contact OEM Support for assistance\n");
  3240. /* Schedule device reset (unload)
  3241. * This is due to some boards consuming sufficient power when driver is
  3242. * up to overheat if fan fails.
  3243. */
  3244. smp_mb__before_clear_bit();
  3245. set_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state);
  3246. smp_mb__after_clear_bit();
  3247. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  3248. }
  3249. static void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn)
  3250. {
  3251. int port = BP_PORT(bp);
  3252. int reg_offset;
  3253. u32 val;
  3254. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  3255. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  3256. if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) {
  3257. val = REG_RD(bp, reg_offset);
  3258. val &= ~AEU_INPUTS_ATTN_BITS_SPIO5;
  3259. REG_WR(bp, reg_offset, val);
  3260. BNX2X_ERR("SPIO5 hw attention\n");
  3261. /* Fan failure attention */
  3262. bnx2x_hw_reset_phy(&bp->link_params);
  3263. bnx2x_fan_failure(bp);
  3264. }
  3265. if ((attn & bp->link_vars.aeu_int_mask) && bp->port.pmf) {
  3266. bnx2x_acquire_phy_lock(bp);
  3267. bnx2x_handle_module_detect_int(&bp->link_params);
  3268. bnx2x_release_phy_lock(bp);
  3269. }
  3270. if (attn & HW_INTERRUT_ASSERT_SET_0) {
  3271. val = REG_RD(bp, reg_offset);
  3272. val &= ~(attn & HW_INTERRUT_ASSERT_SET_0);
  3273. REG_WR(bp, reg_offset, val);
  3274. BNX2X_ERR("FATAL HW block attention set0 0x%x\n",
  3275. (u32)(attn & HW_INTERRUT_ASSERT_SET_0));
  3276. bnx2x_panic();
  3277. }
  3278. }
  3279. static void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn)
  3280. {
  3281. u32 val;
  3282. if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) {
  3283. val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR);
  3284. BNX2X_ERR("DB hw attention 0x%x\n", val);
  3285. /* DORQ discard attention */
  3286. if (val & 0x2)
  3287. BNX2X_ERR("FATAL error from DORQ\n");
  3288. }
  3289. if (attn & HW_INTERRUT_ASSERT_SET_1) {
  3290. int port = BP_PORT(bp);
  3291. int reg_offset;
  3292. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 :
  3293. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1);
  3294. val = REG_RD(bp, reg_offset);
  3295. val &= ~(attn & HW_INTERRUT_ASSERT_SET_1);
  3296. REG_WR(bp, reg_offset, val);
  3297. BNX2X_ERR("FATAL HW block attention set1 0x%x\n",
  3298. (u32)(attn & HW_INTERRUT_ASSERT_SET_1));
  3299. bnx2x_panic();
  3300. }
  3301. }
  3302. static void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn)
  3303. {
  3304. u32 val;
  3305. if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) {
  3306. val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR);
  3307. BNX2X_ERR("CFC hw attention 0x%x\n", val);
  3308. /* CFC error attention */
  3309. if (val & 0x2)
  3310. BNX2X_ERR("FATAL error from CFC\n");
  3311. }
  3312. if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) {
  3313. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0);
  3314. BNX2X_ERR("PXP hw attention-0 0x%x\n", val);
  3315. /* RQ_USDMDP_FIFO_OVERFLOW */
  3316. if (val & 0x18000)
  3317. BNX2X_ERR("FATAL error from PXP\n");
  3318. if (!CHIP_IS_E1x(bp)) {
  3319. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_1);
  3320. BNX2X_ERR("PXP hw attention-1 0x%x\n", val);
  3321. }
  3322. }
  3323. if (attn & HW_INTERRUT_ASSERT_SET_2) {
  3324. int port = BP_PORT(bp);
  3325. int reg_offset;
  3326. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 :
  3327. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2);
  3328. val = REG_RD(bp, reg_offset);
  3329. val &= ~(attn & HW_INTERRUT_ASSERT_SET_2);
  3330. REG_WR(bp, reg_offset, val);
  3331. BNX2X_ERR("FATAL HW block attention set2 0x%x\n",
  3332. (u32)(attn & HW_INTERRUT_ASSERT_SET_2));
  3333. bnx2x_panic();
  3334. }
  3335. }
  3336. static void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn)
  3337. {
  3338. u32 val;
  3339. if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) {
  3340. if (attn & BNX2X_PMF_LINK_ASSERT) {
  3341. int func = BP_FUNC(bp);
  3342. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  3343. bnx2x_read_mf_cfg(bp);
  3344. bp->mf_config[BP_VN(bp)] = MF_CFG_RD(bp,
  3345. func_mf_config[BP_ABS_FUNC(bp)].config);
  3346. val = SHMEM_RD(bp,
  3347. func_mb[BP_FW_MB_IDX(bp)].drv_status);
  3348. if (val & DRV_STATUS_DCC_EVENT_MASK)
  3349. bnx2x_dcc_event(bp,
  3350. (val & DRV_STATUS_DCC_EVENT_MASK));
  3351. if (val & DRV_STATUS_SET_MF_BW)
  3352. bnx2x_set_mf_bw(bp);
  3353. if (val & DRV_STATUS_DRV_INFO_REQ)
  3354. bnx2x_handle_drv_info_req(bp);
  3355. if (val & DRV_STATUS_VF_DISABLED)
  3356. bnx2x_vf_handle_flr_event(bp);
  3357. if ((bp->port.pmf == 0) && (val & DRV_STATUS_PMF))
  3358. bnx2x_pmf_update(bp);
  3359. if (bp->port.pmf &&
  3360. (val & DRV_STATUS_DCBX_NEGOTIATION_RESULTS) &&
  3361. bp->dcbx_enabled > 0)
  3362. /* start dcbx state machine */
  3363. bnx2x_dcbx_set_params(bp,
  3364. BNX2X_DCBX_STATE_NEG_RECEIVED);
  3365. if (val & DRV_STATUS_AFEX_EVENT_MASK)
  3366. bnx2x_handle_afex_cmd(bp,
  3367. val & DRV_STATUS_AFEX_EVENT_MASK);
  3368. if (val & DRV_STATUS_EEE_NEGOTIATION_RESULTS)
  3369. bnx2x_handle_eee_event(bp);
  3370. if (bp->link_vars.periodic_flags &
  3371. PERIODIC_FLAGS_LINK_EVENT) {
  3372. /* sync with link */
  3373. bnx2x_acquire_phy_lock(bp);
  3374. bp->link_vars.periodic_flags &=
  3375. ~PERIODIC_FLAGS_LINK_EVENT;
  3376. bnx2x_release_phy_lock(bp);
  3377. if (IS_MF(bp))
  3378. bnx2x_link_sync_notify(bp);
  3379. bnx2x_link_report(bp);
  3380. }
  3381. /* Always call it here: bnx2x_link_report() will
  3382. * prevent the link indication duplication.
  3383. */
  3384. bnx2x__link_status_update(bp);
  3385. } else if (attn & BNX2X_MC_ASSERT_BITS) {
  3386. BNX2X_ERR("MC assert!\n");
  3387. bnx2x_mc_assert(bp);
  3388. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0);
  3389. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0);
  3390. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0);
  3391. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0);
  3392. bnx2x_panic();
  3393. } else if (attn & BNX2X_MCP_ASSERT) {
  3394. BNX2X_ERR("MCP assert!\n");
  3395. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0);
  3396. bnx2x_fw_dump(bp);
  3397. } else
  3398. BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn);
  3399. }
  3400. if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) {
  3401. BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn);
  3402. if (attn & BNX2X_GRC_TIMEOUT) {
  3403. val = CHIP_IS_E1(bp) ? 0 :
  3404. REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN);
  3405. BNX2X_ERR("GRC time-out 0x%08x\n", val);
  3406. }
  3407. if (attn & BNX2X_GRC_RSV) {
  3408. val = CHIP_IS_E1(bp) ? 0 :
  3409. REG_RD(bp, MISC_REG_GRC_RSV_ATTN);
  3410. BNX2X_ERR("GRC reserved 0x%08x\n", val);
  3411. }
  3412. REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff);
  3413. }
  3414. }
  3415. /*
  3416. * Bits map:
  3417. * 0-7 - Engine0 load counter.
  3418. * 8-15 - Engine1 load counter.
  3419. * 16 - Engine0 RESET_IN_PROGRESS bit.
  3420. * 17 - Engine1 RESET_IN_PROGRESS bit.
  3421. * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active function
  3422. * on the engine
  3423. * 19 - Engine1 ONE_IS_LOADED.
  3424. * 20 - Chip reset flow bit. When set none-leader must wait for both engines
  3425. * leader to complete (check for both RESET_IN_PROGRESS bits and not for
  3426. * just the one belonging to its engine).
  3427. *
  3428. */
  3429. #define BNX2X_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1
  3430. #define BNX2X_PATH0_LOAD_CNT_MASK 0x000000ff
  3431. #define BNX2X_PATH0_LOAD_CNT_SHIFT 0
  3432. #define BNX2X_PATH1_LOAD_CNT_MASK 0x0000ff00
  3433. #define BNX2X_PATH1_LOAD_CNT_SHIFT 8
  3434. #define BNX2X_PATH0_RST_IN_PROG_BIT 0x00010000
  3435. #define BNX2X_PATH1_RST_IN_PROG_BIT 0x00020000
  3436. #define BNX2X_GLOBAL_RESET_BIT 0x00040000
  3437. /*
  3438. * Set the GLOBAL_RESET bit.
  3439. *
  3440. * Should be run under rtnl lock
  3441. */
  3442. void bnx2x_set_reset_global(struct bnx2x *bp)
  3443. {
  3444. u32 val;
  3445. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3446. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3447. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val | BNX2X_GLOBAL_RESET_BIT);
  3448. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3449. }
  3450. /*
  3451. * Clear the GLOBAL_RESET bit.
  3452. *
  3453. * Should be run under rtnl lock
  3454. */
  3455. static void bnx2x_clear_reset_global(struct bnx2x *bp)
  3456. {
  3457. u32 val;
  3458. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3459. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3460. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~BNX2X_GLOBAL_RESET_BIT));
  3461. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3462. }
  3463. /*
  3464. * Checks the GLOBAL_RESET bit.
  3465. *
  3466. * should be run under rtnl lock
  3467. */
  3468. static bool bnx2x_reset_is_global(struct bnx2x *bp)
  3469. {
  3470. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3471. DP(NETIF_MSG_HW, "GEN_REG_VAL=0x%08x\n", val);
  3472. return (val & BNX2X_GLOBAL_RESET_BIT) ? true : false;
  3473. }
  3474. /*
  3475. * Clear RESET_IN_PROGRESS bit for the current engine.
  3476. *
  3477. * Should be run under rtnl lock
  3478. */
  3479. static void bnx2x_set_reset_done(struct bnx2x *bp)
  3480. {
  3481. u32 val;
  3482. u32 bit = BP_PATH(bp) ?
  3483. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3484. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3485. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3486. /* Clear the bit */
  3487. val &= ~bit;
  3488. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3489. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3490. }
  3491. /*
  3492. * Set RESET_IN_PROGRESS for the current engine.
  3493. *
  3494. * should be run under rtnl lock
  3495. */
  3496. void bnx2x_set_reset_in_progress(struct bnx2x *bp)
  3497. {
  3498. u32 val;
  3499. u32 bit = BP_PATH(bp) ?
  3500. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3501. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3502. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3503. /* Set the bit */
  3504. val |= bit;
  3505. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3506. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3507. }
  3508. /*
  3509. * Checks the RESET_IN_PROGRESS bit for the given engine.
  3510. * should be run under rtnl lock
  3511. */
  3512. bool bnx2x_reset_is_done(struct bnx2x *bp, int engine)
  3513. {
  3514. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3515. u32 bit = engine ?
  3516. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3517. /* return false if bit is set */
  3518. return (val & bit) ? false : true;
  3519. }
  3520. /*
  3521. * set pf load for the current pf.
  3522. *
  3523. * should be run under rtnl lock
  3524. */
  3525. void bnx2x_set_pf_load(struct bnx2x *bp)
  3526. {
  3527. u32 val1, val;
  3528. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3529. BNX2X_PATH0_LOAD_CNT_MASK;
  3530. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3531. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3532. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3533. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3534. DP(NETIF_MSG_IFUP, "Old GEN_REG_VAL=0x%08x\n", val);
  3535. /* get the current counter value */
  3536. val1 = (val & mask) >> shift;
  3537. /* set bit of that PF */
  3538. val1 |= (1 << bp->pf_num);
  3539. /* clear the old value */
  3540. val &= ~mask;
  3541. /* set the new one */
  3542. val |= ((val1 << shift) & mask);
  3543. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3544. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3545. }
  3546. /**
  3547. * bnx2x_clear_pf_load - clear pf load mark
  3548. *
  3549. * @bp: driver handle
  3550. *
  3551. * Should be run under rtnl lock.
  3552. * Decrements the load counter for the current engine. Returns
  3553. * whether other functions are still loaded
  3554. */
  3555. bool bnx2x_clear_pf_load(struct bnx2x *bp)
  3556. {
  3557. u32 val1, val;
  3558. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3559. BNX2X_PATH0_LOAD_CNT_MASK;
  3560. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3561. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3562. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3563. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3564. DP(NETIF_MSG_IFDOWN, "Old GEN_REG_VAL=0x%08x\n", val);
  3565. /* get the current counter value */
  3566. val1 = (val & mask) >> shift;
  3567. /* clear bit of that PF */
  3568. val1 &= ~(1 << bp->pf_num);
  3569. /* clear the old value */
  3570. val &= ~mask;
  3571. /* set the new one */
  3572. val |= ((val1 << shift) & mask);
  3573. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3574. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3575. return val1 != 0;
  3576. }
  3577. /*
  3578. * Read the load status for the current engine.
  3579. *
  3580. * should be run under rtnl lock
  3581. */
  3582. static bool bnx2x_get_load_status(struct bnx2x *bp, int engine)
  3583. {
  3584. u32 mask = (engine ? BNX2X_PATH1_LOAD_CNT_MASK :
  3585. BNX2X_PATH0_LOAD_CNT_MASK);
  3586. u32 shift = (engine ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3587. BNX2X_PATH0_LOAD_CNT_SHIFT);
  3588. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3589. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "GLOB_REG=0x%08x\n", val);
  3590. val = (val & mask) >> shift;
  3591. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "load mask for engine %d = 0x%x\n",
  3592. engine, val);
  3593. return val != 0;
  3594. }
  3595. static void _print_parity(struct bnx2x *bp, u32 reg)
  3596. {
  3597. pr_cont(" [0x%08x] ", REG_RD(bp, reg));
  3598. }
  3599. static void _print_next_block(int idx, const char *blk)
  3600. {
  3601. pr_cont("%s%s", idx ? ", " : "", blk);
  3602. }
  3603. static bool bnx2x_check_blocks_with_parity0(struct bnx2x *bp, u32 sig,
  3604. int *par_num, bool print)
  3605. {
  3606. u32 cur_bit;
  3607. bool res;
  3608. int i;
  3609. res = false;
  3610. for (i = 0; sig; i++) {
  3611. cur_bit = (0x1UL << i);
  3612. if (sig & cur_bit) {
  3613. res |= true; /* Each bit is real error! */
  3614. if (print) {
  3615. switch (cur_bit) {
  3616. case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR:
  3617. _print_next_block((*par_num)++, "BRB");
  3618. _print_parity(bp,
  3619. BRB1_REG_BRB1_PRTY_STS);
  3620. break;
  3621. case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR:
  3622. _print_next_block((*par_num)++,
  3623. "PARSER");
  3624. _print_parity(bp, PRS_REG_PRS_PRTY_STS);
  3625. break;
  3626. case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR:
  3627. _print_next_block((*par_num)++, "TSDM");
  3628. _print_parity(bp,
  3629. TSDM_REG_TSDM_PRTY_STS);
  3630. break;
  3631. case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR:
  3632. _print_next_block((*par_num)++,
  3633. "SEARCHER");
  3634. _print_parity(bp, SRC_REG_SRC_PRTY_STS);
  3635. break;
  3636. case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR:
  3637. _print_next_block((*par_num)++, "TCM");
  3638. _print_parity(bp, TCM_REG_TCM_PRTY_STS);
  3639. break;
  3640. case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR:
  3641. _print_next_block((*par_num)++,
  3642. "TSEMI");
  3643. _print_parity(bp,
  3644. TSEM_REG_TSEM_PRTY_STS_0);
  3645. _print_parity(bp,
  3646. TSEM_REG_TSEM_PRTY_STS_1);
  3647. break;
  3648. case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR:
  3649. _print_next_block((*par_num)++, "XPB");
  3650. _print_parity(bp, GRCBASE_XPB +
  3651. PB_REG_PB_PRTY_STS);
  3652. break;
  3653. }
  3654. }
  3655. /* Clear the bit */
  3656. sig &= ~cur_bit;
  3657. }
  3658. }
  3659. return res;
  3660. }
  3661. static bool bnx2x_check_blocks_with_parity1(struct bnx2x *bp, u32 sig,
  3662. int *par_num, bool *global,
  3663. bool print)
  3664. {
  3665. u32 cur_bit;
  3666. bool res;
  3667. int i;
  3668. res = false;
  3669. for (i = 0; sig; i++) {
  3670. cur_bit = (0x1UL << i);
  3671. if (sig & cur_bit) {
  3672. res |= true; /* Each bit is real error! */
  3673. switch (cur_bit) {
  3674. case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR:
  3675. if (print) {
  3676. _print_next_block((*par_num)++, "PBF");
  3677. _print_parity(bp, PBF_REG_PBF_PRTY_STS);
  3678. }
  3679. break;
  3680. case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR:
  3681. if (print) {
  3682. _print_next_block((*par_num)++, "QM");
  3683. _print_parity(bp, QM_REG_QM_PRTY_STS);
  3684. }
  3685. break;
  3686. case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR:
  3687. if (print) {
  3688. _print_next_block((*par_num)++, "TM");
  3689. _print_parity(bp, TM_REG_TM_PRTY_STS);
  3690. }
  3691. break;
  3692. case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR:
  3693. if (print) {
  3694. _print_next_block((*par_num)++, "XSDM");
  3695. _print_parity(bp,
  3696. XSDM_REG_XSDM_PRTY_STS);
  3697. }
  3698. break;
  3699. case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR:
  3700. if (print) {
  3701. _print_next_block((*par_num)++, "XCM");
  3702. _print_parity(bp, XCM_REG_XCM_PRTY_STS);
  3703. }
  3704. break;
  3705. case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR:
  3706. if (print) {
  3707. _print_next_block((*par_num)++,
  3708. "XSEMI");
  3709. _print_parity(bp,
  3710. XSEM_REG_XSEM_PRTY_STS_0);
  3711. _print_parity(bp,
  3712. XSEM_REG_XSEM_PRTY_STS_1);
  3713. }
  3714. break;
  3715. case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR:
  3716. if (print) {
  3717. _print_next_block((*par_num)++,
  3718. "DOORBELLQ");
  3719. _print_parity(bp,
  3720. DORQ_REG_DORQ_PRTY_STS);
  3721. }
  3722. break;
  3723. case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR:
  3724. if (print) {
  3725. _print_next_block((*par_num)++, "NIG");
  3726. if (CHIP_IS_E1x(bp)) {
  3727. _print_parity(bp,
  3728. NIG_REG_NIG_PRTY_STS);
  3729. } else {
  3730. _print_parity(bp,
  3731. NIG_REG_NIG_PRTY_STS_0);
  3732. _print_parity(bp,
  3733. NIG_REG_NIG_PRTY_STS_1);
  3734. }
  3735. }
  3736. break;
  3737. case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR:
  3738. if (print)
  3739. _print_next_block((*par_num)++,
  3740. "VAUX PCI CORE");
  3741. *global = true;
  3742. break;
  3743. case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR:
  3744. if (print) {
  3745. _print_next_block((*par_num)++,
  3746. "DEBUG");
  3747. _print_parity(bp, DBG_REG_DBG_PRTY_STS);
  3748. }
  3749. break;
  3750. case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR:
  3751. if (print) {
  3752. _print_next_block((*par_num)++, "USDM");
  3753. _print_parity(bp,
  3754. USDM_REG_USDM_PRTY_STS);
  3755. }
  3756. break;
  3757. case AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR:
  3758. if (print) {
  3759. _print_next_block((*par_num)++, "UCM");
  3760. _print_parity(bp, UCM_REG_UCM_PRTY_STS);
  3761. }
  3762. break;
  3763. case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR:
  3764. if (print) {
  3765. _print_next_block((*par_num)++,
  3766. "USEMI");
  3767. _print_parity(bp,
  3768. USEM_REG_USEM_PRTY_STS_0);
  3769. _print_parity(bp,
  3770. USEM_REG_USEM_PRTY_STS_1);
  3771. }
  3772. break;
  3773. case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR:
  3774. if (print) {
  3775. _print_next_block((*par_num)++, "UPB");
  3776. _print_parity(bp, GRCBASE_UPB +
  3777. PB_REG_PB_PRTY_STS);
  3778. }
  3779. break;
  3780. case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR:
  3781. if (print) {
  3782. _print_next_block((*par_num)++, "CSDM");
  3783. _print_parity(bp,
  3784. CSDM_REG_CSDM_PRTY_STS);
  3785. }
  3786. break;
  3787. case AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR:
  3788. if (print) {
  3789. _print_next_block((*par_num)++, "CCM");
  3790. _print_parity(bp, CCM_REG_CCM_PRTY_STS);
  3791. }
  3792. break;
  3793. }
  3794. /* Clear the bit */
  3795. sig &= ~cur_bit;
  3796. }
  3797. }
  3798. return res;
  3799. }
  3800. static bool bnx2x_check_blocks_with_parity2(struct bnx2x *bp, u32 sig,
  3801. int *par_num, bool print)
  3802. {
  3803. u32 cur_bit;
  3804. bool res;
  3805. int i;
  3806. res = false;
  3807. for (i = 0; sig; i++) {
  3808. cur_bit = (0x1UL << i);
  3809. if (sig & cur_bit) {
  3810. res |= true; /* Each bit is real error! */
  3811. if (print) {
  3812. switch (cur_bit) {
  3813. case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR:
  3814. _print_next_block((*par_num)++,
  3815. "CSEMI");
  3816. _print_parity(bp,
  3817. CSEM_REG_CSEM_PRTY_STS_0);
  3818. _print_parity(bp,
  3819. CSEM_REG_CSEM_PRTY_STS_1);
  3820. break;
  3821. case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR:
  3822. _print_next_block((*par_num)++, "PXP");
  3823. _print_parity(bp, PXP_REG_PXP_PRTY_STS);
  3824. _print_parity(bp,
  3825. PXP2_REG_PXP2_PRTY_STS_0);
  3826. _print_parity(bp,
  3827. PXP2_REG_PXP2_PRTY_STS_1);
  3828. break;
  3829. case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR:
  3830. _print_next_block((*par_num)++,
  3831. "PXPPCICLOCKCLIENT");
  3832. break;
  3833. case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR:
  3834. _print_next_block((*par_num)++, "CFC");
  3835. _print_parity(bp,
  3836. CFC_REG_CFC_PRTY_STS);
  3837. break;
  3838. case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR:
  3839. _print_next_block((*par_num)++, "CDU");
  3840. _print_parity(bp, CDU_REG_CDU_PRTY_STS);
  3841. break;
  3842. case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR:
  3843. _print_next_block((*par_num)++, "DMAE");
  3844. _print_parity(bp,
  3845. DMAE_REG_DMAE_PRTY_STS);
  3846. break;
  3847. case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR:
  3848. _print_next_block((*par_num)++, "IGU");
  3849. if (CHIP_IS_E1x(bp))
  3850. _print_parity(bp,
  3851. HC_REG_HC_PRTY_STS);
  3852. else
  3853. _print_parity(bp,
  3854. IGU_REG_IGU_PRTY_STS);
  3855. break;
  3856. case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR:
  3857. _print_next_block((*par_num)++, "MISC");
  3858. _print_parity(bp,
  3859. MISC_REG_MISC_PRTY_STS);
  3860. break;
  3861. }
  3862. }
  3863. /* Clear the bit */
  3864. sig &= ~cur_bit;
  3865. }
  3866. }
  3867. return res;
  3868. }
  3869. static bool bnx2x_check_blocks_with_parity3(struct bnx2x *bp, u32 sig,
  3870. int *par_num, bool *global,
  3871. bool print)
  3872. {
  3873. bool res = false;
  3874. u32 cur_bit;
  3875. int i;
  3876. for (i = 0; sig; i++) {
  3877. cur_bit = (0x1UL << i);
  3878. if (sig & cur_bit) {
  3879. switch (cur_bit) {
  3880. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY:
  3881. if (print)
  3882. _print_next_block((*par_num)++,
  3883. "MCP ROM");
  3884. *global = true;
  3885. res |= true;
  3886. break;
  3887. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY:
  3888. if (print)
  3889. _print_next_block((*par_num)++,
  3890. "MCP UMP RX");
  3891. *global = true;
  3892. res |= true;
  3893. break;
  3894. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY:
  3895. if (print)
  3896. _print_next_block((*par_num)++,
  3897. "MCP UMP TX");
  3898. *global = true;
  3899. res |= true;
  3900. break;
  3901. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY:
  3902. if (print)
  3903. _print_next_block((*par_num)++,
  3904. "MCP SCPAD");
  3905. /* clear latched SCPAD PATIRY from MCP */
  3906. REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL,
  3907. 1UL << 10);
  3908. break;
  3909. }
  3910. /* Clear the bit */
  3911. sig &= ~cur_bit;
  3912. }
  3913. }
  3914. return res;
  3915. }
  3916. static bool bnx2x_check_blocks_with_parity4(struct bnx2x *bp, u32 sig,
  3917. int *par_num, bool print)
  3918. {
  3919. u32 cur_bit;
  3920. bool res;
  3921. int i;
  3922. res = false;
  3923. for (i = 0; sig; i++) {
  3924. cur_bit = (0x1UL << i);
  3925. if (sig & cur_bit) {
  3926. res |= true; /* Each bit is real error! */
  3927. if (print) {
  3928. switch (cur_bit) {
  3929. case AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR:
  3930. _print_next_block((*par_num)++,
  3931. "PGLUE_B");
  3932. _print_parity(bp,
  3933. PGLUE_B_REG_PGLUE_B_PRTY_STS);
  3934. break;
  3935. case AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR:
  3936. _print_next_block((*par_num)++, "ATC");
  3937. _print_parity(bp,
  3938. ATC_REG_ATC_PRTY_STS);
  3939. break;
  3940. }
  3941. }
  3942. /* Clear the bit */
  3943. sig &= ~cur_bit;
  3944. }
  3945. }
  3946. return res;
  3947. }
  3948. static bool bnx2x_parity_attn(struct bnx2x *bp, bool *global, bool print,
  3949. u32 *sig)
  3950. {
  3951. bool res = false;
  3952. if ((sig[0] & HW_PRTY_ASSERT_SET_0) ||
  3953. (sig[1] & HW_PRTY_ASSERT_SET_1) ||
  3954. (sig[2] & HW_PRTY_ASSERT_SET_2) ||
  3955. (sig[3] & HW_PRTY_ASSERT_SET_3) ||
  3956. (sig[4] & HW_PRTY_ASSERT_SET_4)) {
  3957. int par_num = 0;
  3958. DP(NETIF_MSG_HW, "Was parity error: HW block parity attention:\n"
  3959. "[0]:0x%08x [1]:0x%08x [2]:0x%08x [3]:0x%08x [4]:0x%08x\n",
  3960. sig[0] & HW_PRTY_ASSERT_SET_0,
  3961. sig[1] & HW_PRTY_ASSERT_SET_1,
  3962. sig[2] & HW_PRTY_ASSERT_SET_2,
  3963. sig[3] & HW_PRTY_ASSERT_SET_3,
  3964. sig[4] & HW_PRTY_ASSERT_SET_4);
  3965. if (print)
  3966. netdev_err(bp->dev,
  3967. "Parity errors detected in blocks: ");
  3968. res |= bnx2x_check_blocks_with_parity0(bp,
  3969. sig[0] & HW_PRTY_ASSERT_SET_0, &par_num, print);
  3970. res |= bnx2x_check_blocks_with_parity1(bp,
  3971. sig[1] & HW_PRTY_ASSERT_SET_1, &par_num, global, print);
  3972. res |= bnx2x_check_blocks_with_parity2(bp,
  3973. sig[2] & HW_PRTY_ASSERT_SET_2, &par_num, print);
  3974. res |= bnx2x_check_blocks_with_parity3(bp,
  3975. sig[3] & HW_PRTY_ASSERT_SET_3, &par_num, global, print);
  3976. res |= bnx2x_check_blocks_with_parity4(bp,
  3977. sig[4] & HW_PRTY_ASSERT_SET_4, &par_num, print);
  3978. if (print)
  3979. pr_cont("\n");
  3980. }
  3981. return res;
  3982. }
  3983. /**
  3984. * bnx2x_chk_parity_attn - checks for parity attentions.
  3985. *
  3986. * @bp: driver handle
  3987. * @global: true if there was a global attention
  3988. * @print: show parity attention in syslog
  3989. */
  3990. bool bnx2x_chk_parity_attn(struct bnx2x *bp, bool *global, bool print)
  3991. {
  3992. struct attn_route attn = { {0} };
  3993. int port = BP_PORT(bp);
  3994. attn.sig[0] = REG_RD(bp,
  3995. MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 +
  3996. port*4);
  3997. attn.sig[1] = REG_RD(bp,
  3998. MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 +
  3999. port*4);
  4000. attn.sig[2] = REG_RD(bp,
  4001. MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 +
  4002. port*4);
  4003. attn.sig[3] = REG_RD(bp,
  4004. MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 +
  4005. port*4);
  4006. /* Since MCP attentions can't be disabled inside the block, we need to
  4007. * read AEU registers to see whether they're currently disabled
  4008. */
  4009. attn.sig[3] &= ((REG_RD(bp,
  4010. !port ? MISC_REG_AEU_ENABLE4_FUNC_0_OUT_0
  4011. : MISC_REG_AEU_ENABLE4_FUNC_1_OUT_0) &
  4012. MISC_AEU_ENABLE_MCP_PRTY_BITS) |
  4013. ~MISC_AEU_ENABLE_MCP_PRTY_BITS);
  4014. if (!CHIP_IS_E1x(bp))
  4015. attn.sig[4] = REG_RD(bp,
  4016. MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 +
  4017. port*4);
  4018. return bnx2x_parity_attn(bp, global, print, attn.sig);
  4019. }
  4020. static void bnx2x_attn_int_deasserted4(struct bnx2x *bp, u32 attn)
  4021. {
  4022. u32 val;
  4023. if (attn & AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT) {
  4024. val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS_CLR);
  4025. BNX2X_ERR("PGLUE hw attention 0x%x\n", val);
  4026. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR)
  4027. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR\n");
  4028. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR)
  4029. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR\n");
  4030. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN)
  4031. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN\n");
  4032. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN)
  4033. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN\n");
  4034. if (val &
  4035. PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN)
  4036. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN\n");
  4037. if (val &
  4038. PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN)
  4039. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN\n");
  4040. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN)
  4041. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN\n");
  4042. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN)
  4043. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN\n");
  4044. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW)
  4045. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW\n");
  4046. }
  4047. if (attn & AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT) {
  4048. val = REG_RD(bp, ATC_REG_ATC_INT_STS_CLR);
  4049. BNX2X_ERR("ATC hw attention 0x%x\n", val);
  4050. if (val & ATC_ATC_INT_STS_REG_ADDRESS_ERROR)
  4051. BNX2X_ERR("ATC_ATC_INT_STS_REG_ADDRESS_ERROR\n");
  4052. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND)
  4053. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND\n");
  4054. if (val & ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS)
  4055. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS\n");
  4056. if (val & ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT)
  4057. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT\n");
  4058. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR)
  4059. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR\n");
  4060. if (val & ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU)
  4061. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU\n");
  4062. }
  4063. if (attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  4064. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)) {
  4065. BNX2X_ERR("FATAL parity attention set4 0x%x\n",
  4066. (u32)(attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  4067. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)));
  4068. }
  4069. }
  4070. static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted)
  4071. {
  4072. struct attn_route attn, *group_mask;
  4073. int port = BP_PORT(bp);
  4074. int index;
  4075. u32 reg_addr;
  4076. u32 val;
  4077. u32 aeu_mask;
  4078. bool global = false;
  4079. /* need to take HW lock because MCP or other port might also
  4080. try to handle this event */
  4081. bnx2x_acquire_alr(bp);
  4082. if (bnx2x_chk_parity_attn(bp, &global, true)) {
  4083. #ifndef BNX2X_STOP_ON_ERROR
  4084. bp->recovery_state = BNX2X_RECOVERY_INIT;
  4085. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  4086. /* Disable HW interrupts */
  4087. bnx2x_int_disable(bp);
  4088. /* In case of parity errors don't handle attentions so that
  4089. * other function would "see" parity errors.
  4090. */
  4091. #else
  4092. bnx2x_panic();
  4093. #endif
  4094. bnx2x_release_alr(bp);
  4095. return;
  4096. }
  4097. attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
  4098. attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
  4099. attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
  4100. attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
  4101. if (!CHIP_IS_E1x(bp))
  4102. attn.sig[4] =
  4103. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4);
  4104. else
  4105. attn.sig[4] = 0;
  4106. DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x %08x\n",
  4107. attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3], attn.sig[4]);
  4108. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  4109. if (deasserted & (1 << index)) {
  4110. group_mask = &bp->attn_group[index];
  4111. DP(NETIF_MSG_HW, "group[%d]: %08x %08x %08x %08x %08x\n",
  4112. index,
  4113. group_mask->sig[0], group_mask->sig[1],
  4114. group_mask->sig[2], group_mask->sig[3],
  4115. group_mask->sig[4]);
  4116. bnx2x_attn_int_deasserted4(bp,
  4117. attn.sig[4] & group_mask->sig[4]);
  4118. bnx2x_attn_int_deasserted3(bp,
  4119. attn.sig[3] & group_mask->sig[3]);
  4120. bnx2x_attn_int_deasserted1(bp,
  4121. attn.sig[1] & group_mask->sig[1]);
  4122. bnx2x_attn_int_deasserted2(bp,
  4123. attn.sig[2] & group_mask->sig[2]);
  4124. bnx2x_attn_int_deasserted0(bp,
  4125. attn.sig[0] & group_mask->sig[0]);
  4126. }
  4127. }
  4128. bnx2x_release_alr(bp);
  4129. if (bp->common.int_block == INT_BLOCK_HC)
  4130. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  4131. COMMAND_REG_ATTN_BITS_CLR);
  4132. else
  4133. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_CLR_UPPER*8);
  4134. val = ~deasserted;
  4135. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", val,
  4136. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  4137. REG_WR(bp, reg_addr, val);
  4138. if (~bp->attn_state & deasserted)
  4139. BNX2X_ERR("IGU ERROR\n");
  4140. reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  4141. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  4142. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  4143. aeu_mask = REG_RD(bp, reg_addr);
  4144. DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n",
  4145. aeu_mask, deasserted);
  4146. aeu_mask |= (deasserted & 0x3ff);
  4147. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  4148. REG_WR(bp, reg_addr, aeu_mask);
  4149. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  4150. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  4151. bp->attn_state &= ~deasserted;
  4152. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  4153. }
  4154. static void bnx2x_attn_int(struct bnx2x *bp)
  4155. {
  4156. /* read local copy of bits */
  4157. u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block.
  4158. attn_bits);
  4159. u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block.
  4160. attn_bits_ack);
  4161. u32 attn_state = bp->attn_state;
  4162. /* look for changed bits */
  4163. u32 asserted = attn_bits & ~attn_ack & ~attn_state;
  4164. u32 deasserted = ~attn_bits & attn_ack & attn_state;
  4165. DP(NETIF_MSG_HW,
  4166. "attn_bits %x attn_ack %x asserted %x deasserted %x\n",
  4167. attn_bits, attn_ack, asserted, deasserted);
  4168. if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state))
  4169. BNX2X_ERR("BAD attention state\n");
  4170. /* handle bits that were raised */
  4171. if (asserted)
  4172. bnx2x_attn_int_asserted(bp, asserted);
  4173. if (deasserted)
  4174. bnx2x_attn_int_deasserted(bp, deasserted);
  4175. }
  4176. void bnx2x_igu_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 segment,
  4177. u16 index, u8 op, u8 update)
  4178. {
  4179. u32 igu_addr = bp->igu_base_addr;
  4180. igu_addr += (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8;
  4181. bnx2x_igu_ack_sb_gen(bp, igu_sb_id, segment, index, op, update,
  4182. igu_addr);
  4183. }
  4184. static void bnx2x_update_eq_prod(struct bnx2x *bp, u16 prod)
  4185. {
  4186. /* No memory barriers */
  4187. storm_memset_eq_prod(bp, prod, BP_FUNC(bp));
  4188. mmiowb(); /* keep prod updates ordered */
  4189. }
  4190. static int bnx2x_cnic_handle_cfc_del(struct bnx2x *bp, u32 cid,
  4191. union event_ring_elem *elem)
  4192. {
  4193. u8 err = elem->message.error;
  4194. if (!bp->cnic_eth_dev.starting_cid ||
  4195. (cid < bp->cnic_eth_dev.starting_cid &&
  4196. cid != bp->cnic_eth_dev.iscsi_l2_cid))
  4197. return 1;
  4198. DP(BNX2X_MSG_SP, "got delete ramrod for CNIC CID %d\n", cid);
  4199. if (unlikely(err)) {
  4200. BNX2X_ERR("got delete ramrod for CNIC CID %d with error!\n",
  4201. cid);
  4202. bnx2x_panic_dump(bp, false);
  4203. }
  4204. bnx2x_cnic_cfc_comp(bp, cid, err);
  4205. return 0;
  4206. }
  4207. static void bnx2x_handle_mcast_eqe(struct bnx2x *bp)
  4208. {
  4209. struct bnx2x_mcast_ramrod_params rparam;
  4210. int rc;
  4211. memset(&rparam, 0, sizeof(rparam));
  4212. rparam.mcast_obj = &bp->mcast_obj;
  4213. netif_addr_lock_bh(bp->dev);
  4214. /* Clear pending state for the last command */
  4215. bp->mcast_obj.raw.clear_pending(&bp->mcast_obj.raw);
  4216. /* If there are pending mcast commands - send them */
  4217. if (bp->mcast_obj.check_pending(&bp->mcast_obj)) {
  4218. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT);
  4219. if (rc < 0)
  4220. BNX2X_ERR("Failed to send pending mcast commands: %d\n",
  4221. rc);
  4222. }
  4223. netif_addr_unlock_bh(bp->dev);
  4224. }
  4225. static void bnx2x_handle_classification_eqe(struct bnx2x *bp,
  4226. union event_ring_elem *elem)
  4227. {
  4228. unsigned long ramrod_flags = 0;
  4229. int rc = 0;
  4230. u32 cid = elem->message.data.eth_event.echo & BNX2X_SWCID_MASK;
  4231. struct bnx2x_vlan_mac_obj *vlan_mac_obj;
  4232. /* Always push next commands out, don't wait here */
  4233. __set_bit(RAMROD_CONT, &ramrod_flags);
  4234. switch (le32_to_cpu((__force __le32)elem->message.data.eth_event.echo)
  4235. >> BNX2X_SWCID_SHIFT) {
  4236. case BNX2X_FILTER_MAC_PENDING:
  4237. DP(BNX2X_MSG_SP, "Got SETUP_MAC completions\n");
  4238. if (CNIC_LOADED(bp) && (cid == BNX2X_ISCSI_ETH_CID(bp)))
  4239. vlan_mac_obj = &bp->iscsi_l2_mac_obj;
  4240. else
  4241. vlan_mac_obj = &bp->sp_objs[cid].mac_obj;
  4242. break;
  4243. case BNX2X_FILTER_MCAST_PENDING:
  4244. DP(BNX2X_MSG_SP, "Got SETUP_MCAST completions\n");
  4245. /* This is only relevant for 57710 where multicast MACs are
  4246. * configured as unicast MACs using the same ramrod.
  4247. */
  4248. bnx2x_handle_mcast_eqe(bp);
  4249. return;
  4250. default:
  4251. BNX2X_ERR("Unsupported classification command: %d\n",
  4252. elem->message.data.eth_event.echo);
  4253. return;
  4254. }
  4255. rc = vlan_mac_obj->complete(bp, vlan_mac_obj, elem, &ramrod_flags);
  4256. if (rc < 0)
  4257. BNX2X_ERR("Failed to schedule new commands: %d\n", rc);
  4258. else if (rc > 0)
  4259. DP(BNX2X_MSG_SP, "Scheduled next pending commands...\n");
  4260. }
  4261. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start);
  4262. static void bnx2x_handle_rx_mode_eqe(struct bnx2x *bp)
  4263. {
  4264. netif_addr_lock_bh(bp->dev);
  4265. clear_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  4266. /* Send rx_mode command again if was requested */
  4267. if (test_and_clear_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state))
  4268. bnx2x_set_storm_rx_mode(bp);
  4269. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED,
  4270. &bp->sp_state))
  4271. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  4272. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED,
  4273. &bp->sp_state))
  4274. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  4275. netif_addr_unlock_bh(bp->dev);
  4276. }
  4277. static void bnx2x_after_afex_vif_lists(struct bnx2x *bp,
  4278. union event_ring_elem *elem)
  4279. {
  4280. if (elem->message.data.vif_list_event.echo == VIF_LIST_RULE_GET) {
  4281. DP(BNX2X_MSG_SP,
  4282. "afex: ramrod completed VIF LIST_GET, addrs 0x%x\n",
  4283. elem->message.data.vif_list_event.func_bit_map);
  4284. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTGET_ACK,
  4285. elem->message.data.vif_list_event.func_bit_map);
  4286. } else if (elem->message.data.vif_list_event.echo ==
  4287. VIF_LIST_RULE_SET) {
  4288. DP(BNX2X_MSG_SP, "afex: ramrod completed VIF LIST_SET\n");
  4289. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTSET_ACK, 0);
  4290. }
  4291. }
  4292. /* called with rtnl_lock */
  4293. static void bnx2x_after_function_update(struct bnx2x *bp)
  4294. {
  4295. int q, rc;
  4296. struct bnx2x_fastpath *fp;
  4297. struct bnx2x_queue_state_params queue_params = {NULL};
  4298. struct bnx2x_queue_update_params *q_update_params =
  4299. &queue_params.params.update;
  4300. /* Send Q update command with afex vlan removal values for all Qs */
  4301. queue_params.cmd = BNX2X_Q_CMD_UPDATE;
  4302. /* set silent vlan removal values according to vlan mode */
  4303. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM_CHNG,
  4304. &q_update_params->update_flags);
  4305. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM,
  4306. &q_update_params->update_flags);
  4307. __set_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
  4308. /* in access mode mark mask and value are 0 to strip all vlans */
  4309. if (bp->afex_vlan_mode == FUNC_MF_CFG_AFEX_VLAN_ACCESS_MODE) {
  4310. q_update_params->silent_removal_value = 0;
  4311. q_update_params->silent_removal_mask = 0;
  4312. } else {
  4313. q_update_params->silent_removal_value =
  4314. (bp->afex_def_vlan_tag & VLAN_VID_MASK);
  4315. q_update_params->silent_removal_mask = VLAN_VID_MASK;
  4316. }
  4317. for_each_eth_queue(bp, q) {
  4318. /* Set the appropriate Queue object */
  4319. fp = &bp->fp[q];
  4320. queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  4321. /* send the ramrod */
  4322. rc = bnx2x_queue_state_change(bp, &queue_params);
  4323. if (rc < 0)
  4324. BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
  4325. q);
  4326. }
  4327. if (!NO_FCOE(bp) && CNIC_ENABLED(bp)) {
  4328. fp = &bp->fp[FCOE_IDX(bp)];
  4329. queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  4330. /* clear pending completion bit */
  4331. __clear_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
  4332. /* mark latest Q bit */
  4333. smp_mb__before_clear_bit();
  4334. set_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
  4335. smp_mb__after_clear_bit();
  4336. /* send Q update ramrod for FCoE Q */
  4337. rc = bnx2x_queue_state_change(bp, &queue_params);
  4338. if (rc < 0)
  4339. BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
  4340. q);
  4341. } else {
  4342. /* If no FCoE ring - ACK MCP now */
  4343. bnx2x_link_report(bp);
  4344. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  4345. }
  4346. }
  4347. static struct bnx2x_queue_sp_obj *bnx2x_cid_to_q_obj(
  4348. struct bnx2x *bp, u32 cid)
  4349. {
  4350. DP(BNX2X_MSG_SP, "retrieving fp from cid %d\n", cid);
  4351. if (CNIC_LOADED(bp) && (cid == BNX2X_FCOE_ETH_CID(bp)))
  4352. return &bnx2x_fcoe_sp_obj(bp, q_obj);
  4353. else
  4354. return &bp->sp_objs[CID_TO_FP(cid, bp)].q_obj;
  4355. }
  4356. static void bnx2x_eq_int(struct bnx2x *bp)
  4357. {
  4358. u16 hw_cons, sw_cons, sw_prod;
  4359. union event_ring_elem *elem;
  4360. u8 echo;
  4361. u32 cid;
  4362. u8 opcode;
  4363. int rc, spqe_cnt = 0;
  4364. struct bnx2x_queue_sp_obj *q_obj;
  4365. struct bnx2x_func_sp_obj *f_obj = &bp->func_obj;
  4366. struct bnx2x_raw_obj *rss_raw = &bp->rss_conf_obj.raw;
  4367. hw_cons = le16_to_cpu(*bp->eq_cons_sb);
  4368. /* The hw_cos range is 1-255, 257 - the sw_cons range is 0-254, 256.
  4369. * when we get the next-page we need to adjust so the loop
  4370. * condition below will be met. The next element is the size of a
  4371. * regular element and hence incrementing by 1
  4372. */
  4373. if ((hw_cons & EQ_DESC_MAX_PAGE) == EQ_DESC_MAX_PAGE)
  4374. hw_cons++;
  4375. /* This function may never run in parallel with itself for a
  4376. * specific bp, thus there is no need in "paired" read memory
  4377. * barrier here.
  4378. */
  4379. sw_cons = bp->eq_cons;
  4380. sw_prod = bp->eq_prod;
  4381. DP(BNX2X_MSG_SP, "EQ: hw_cons %u sw_cons %u bp->eq_spq_left %x\n",
  4382. hw_cons, sw_cons, atomic_read(&bp->eq_spq_left));
  4383. for (; sw_cons != hw_cons;
  4384. sw_prod = NEXT_EQ_IDX(sw_prod), sw_cons = NEXT_EQ_IDX(sw_cons)) {
  4385. elem = &bp->eq_ring[EQ_DESC(sw_cons)];
  4386. rc = bnx2x_iov_eq_sp_event(bp, elem);
  4387. if (!rc) {
  4388. DP(BNX2X_MSG_IOV, "bnx2x_iov_eq_sp_event returned %d\n",
  4389. rc);
  4390. goto next_spqe;
  4391. }
  4392. /* elem CID originates from FW; actually LE */
  4393. cid = SW_CID((__force __le32)
  4394. elem->message.data.cfc_del_event.cid);
  4395. opcode = elem->message.opcode;
  4396. /* handle eq element */
  4397. switch (opcode) {
  4398. case EVENT_RING_OPCODE_VF_PF_CHANNEL:
  4399. DP(BNX2X_MSG_IOV, "vf pf channel element on eq\n");
  4400. bnx2x_vf_mbx(bp, &elem->message.data.vf_pf_event);
  4401. continue;
  4402. case EVENT_RING_OPCODE_STAT_QUERY:
  4403. DP(BNX2X_MSG_SP | BNX2X_MSG_STATS,
  4404. "got statistics comp event %d\n",
  4405. bp->stats_comp++);
  4406. /* nothing to do with stats comp */
  4407. goto next_spqe;
  4408. case EVENT_RING_OPCODE_CFC_DEL:
  4409. /* handle according to cid range */
  4410. /*
  4411. * we may want to verify here that the bp state is
  4412. * HALTING
  4413. */
  4414. DP(BNX2X_MSG_SP,
  4415. "got delete ramrod for MULTI[%d]\n", cid);
  4416. if (CNIC_LOADED(bp) &&
  4417. !bnx2x_cnic_handle_cfc_del(bp, cid, elem))
  4418. goto next_spqe;
  4419. q_obj = bnx2x_cid_to_q_obj(bp, cid);
  4420. if (q_obj->complete_cmd(bp, q_obj, BNX2X_Q_CMD_CFC_DEL))
  4421. break;
  4422. goto next_spqe;
  4423. case EVENT_RING_OPCODE_STOP_TRAFFIC:
  4424. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got STOP TRAFFIC\n");
  4425. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_PAUSED);
  4426. if (f_obj->complete_cmd(bp, f_obj,
  4427. BNX2X_F_CMD_TX_STOP))
  4428. break;
  4429. goto next_spqe;
  4430. case EVENT_RING_OPCODE_START_TRAFFIC:
  4431. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got START TRAFFIC\n");
  4432. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_RELEASED);
  4433. if (f_obj->complete_cmd(bp, f_obj,
  4434. BNX2X_F_CMD_TX_START))
  4435. break;
  4436. goto next_spqe;
  4437. case EVENT_RING_OPCODE_FUNCTION_UPDATE:
  4438. echo = elem->message.data.function_update_event.echo;
  4439. if (echo == SWITCH_UPDATE) {
  4440. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4441. "got FUNC_SWITCH_UPDATE ramrod\n");
  4442. if (f_obj->complete_cmd(
  4443. bp, f_obj, BNX2X_F_CMD_SWITCH_UPDATE))
  4444. break;
  4445. } else {
  4446. DP(BNX2X_MSG_SP | BNX2X_MSG_MCP,
  4447. "AFEX: ramrod completed FUNCTION_UPDATE\n");
  4448. f_obj->complete_cmd(bp, f_obj,
  4449. BNX2X_F_CMD_AFEX_UPDATE);
  4450. /* We will perform the Queues update from
  4451. * sp_rtnl task as all Queue SP operations
  4452. * should run under rtnl_lock.
  4453. */
  4454. smp_mb__before_clear_bit();
  4455. set_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE,
  4456. &bp->sp_rtnl_state);
  4457. smp_mb__after_clear_bit();
  4458. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  4459. }
  4460. goto next_spqe;
  4461. case EVENT_RING_OPCODE_AFEX_VIF_LISTS:
  4462. f_obj->complete_cmd(bp, f_obj,
  4463. BNX2X_F_CMD_AFEX_VIFLISTS);
  4464. bnx2x_after_afex_vif_lists(bp, elem);
  4465. goto next_spqe;
  4466. case EVENT_RING_OPCODE_FUNCTION_START:
  4467. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4468. "got FUNC_START ramrod\n");
  4469. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_START))
  4470. break;
  4471. goto next_spqe;
  4472. case EVENT_RING_OPCODE_FUNCTION_STOP:
  4473. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4474. "got FUNC_STOP ramrod\n");
  4475. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_STOP))
  4476. break;
  4477. goto next_spqe;
  4478. }
  4479. switch (opcode | bp->state) {
  4480. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4481. BNX2X_STATE_OPEN):
  4482. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4483. BNX2X_STATE_OPENING_WAIT4_PORT):
  4484. cid = elem->message.data.eth_event.echo &
  4485. BNX2X_SWCID_MASK;
  4486. DP(BNX2X_MSG_SP, "got RSS_UPDATE ramrod. CID %d\n",
  4487. cid);
  4488. rss_raw->clear_pending(rss_raw);
  4489. break;
  4490. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_OPEN):
  4491. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_DIAG):
  4492. case (EVENT_RING_OPCODE_SET_MAC |
  4493. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4494. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4495. BNX2X_STATE_OPEN):
  4496. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4497. BNX2X_STATE_DIAG):
  4498. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4499. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4500. DP(BNX2X_MSG_SP, "got (un)set mac ramrod\n");
  4501. bnx2x_handle_classification_eqe(bp, elem);
  4502. break;
  4503. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4504. BNX2X_STATE_OPEN):
  4505. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4506. BNX2X_STATE_DIAG):
  4507. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4508. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4509. DP(BNX2X_MSG_SP, "got mcast ramrod\n");
  4510. bnx2x_handle_mcast_eqe(bp);
  4511. break;
  4512. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4513. BNX2X_STATE_OPEN):
  4514. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4515. BNX2X_STATE_DIAG):
  4516. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4517. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4518. DP(BNX2X_MSG_SP, "got rx_mode ramrod\n");
  4519. bnx2x_handle_rx_mode_eqe(bp);
  4520. break;
  4521. default:
  4522. /* unknown event log error and continue */
  4523. BNX2X_ERR("Unknown EQ event %d, bp->state 0x%x\n",
  4524. elem->message.opcode, bp->state);
  4525. }
  4526. next_spqe:
  4527. spqe_cnt++;
  4528. } /* for */
  4529. smp_mb__before_atomic_inc();
  4530. atomic_add(spqe_cnt, &bp->eq_spq_left);
  4531. bp->eq_cons = sw_cons;
  4532. bp->eq_prod = sw_prod;
  4533. /* Make sure that above mem writes were issued towards the memory */
  4534. smp_wmb();
  4535. /* update producer */
  4536. bnx2x_update_eq_prod(bp, bp->eq_prod);
  4537. }
  4538. static void bnx2x_sp_task(struct work_struct *work)
  4539. {
  4540. struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work);
  4541. DP(BNX2X_MSG_SP, "sp task invoked\n");
  4542. /* make sure the atomic interrupt_occurred has been written */
  4543. smp_rmb();
  4544. if (atomic_read(&bp->interrupt_occurred)) {
  4545. /* what work needs to be performed? */
  4546. u16 status = bnx2x_update_dsb_idx(bp);
  4547. DP(BNX2X_MSG_SP, "status %x\n", status);
  4548. DP(BNX2X_MSG_SP, "setting interrupt_occurred to 0\n");
  4549. atomic_set(&bp->interrupt_occurred, 0);
  4550. /* HW attentions */
  4551. if (status & BNX2X_DEF_SB_ATT_IDX) {
  4552. bnx2x_attn_int(bp);
  4553. status &= ~BNX2X_DEF_SB_ATT_IDX;
  4554. }
  4555. /* SP events: STAT_QUERY and others */
  4556. if (status & BNX2X_DEF_SB_IDX) {
  4557. struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
  4558. if (FCOE_INIT(bp) &&
  4559. (bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp))) {
  4560. /* Prevent local bottom-halves from running as
  4561. * we are going to change the local NAPI list.
  4562. */
  4563. local_bh_disable();
  4564. napi_schedule(&bnx2x_fcoe(bp, napi));
  4565. local_bh_enable();
  4566. }
  4567. /* Handle EQ completions */
  4568. bnx2x_eq_int(bp);
  4569. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID,
  4570. le16_to_cpu(bp->def_idx), IGU_INT_NOP, 1);
  4571. status &= ~BNX2X_DEF_SB_IDX;
  4572. }
  4573. /* if status is non zero then perhaps something went wrong */
  4574. if (unlikely(status))
  4575. DP(BNX2X_MSG_SP,
  4576. "got an unknown interrupt! (status 0x%x)\n", status);
  4577. /* ack status block only if something was actually handled */
  4578. bnx2x_ack_sb(bp, bp->igu_dsb_id, ATTENTION_ID,
  4579. le16_to_cpu(bp->def_att_idx), IGU_INT_ENABLE, 1);
  4580. }
  4581. /* must be called after the EQ processing (since eq leads to sriov
  4582. * ramrod completion flows).
  4583. * This flow may have been scheduled by the arrival of a ramrod
  4584. * completion, or by the sriov code rescheduling itself.
  4585. */
  4586. bnx2x_iov_sp_task(bp);
  4587. /* afex - poll to check if VIFSET_ACK should be sent to MFW */
  4588. if (test_and_clear_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK,
  4589. &bp->sp_state)) {
  4590. bnx2x_link_report(bp);
  4591. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  4592. }
  4593. }
  4594. irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance)
  4595. {
  4596. struct net_device *dev = dev_instance;
  4597. struct bnx2x *bp = netdev_priv(dev);
  4598. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0,
  4599. IGU_INT_DISABLE, 0);
  4600. #ifdef BNX2X_STOP_ON_ERROR
  4601. if (unlikely(bp->panic))
  4602. return IRQ_HANDLED;
  4603. #endif
  4604. if (CNIC_LOADED(bp)) {
  4605. struct cnic_ops *c_ops;
  4606. rcu_read_lock();
  4607. c_ops = rcu_dereference(bp->cnic_ops);
  4608. if (c_ops)
  4609. c_ops->cnic_handler(bp->cnic_data, NULL);
  4610. rcu_read_unlock();
  4611. }
  4612. /* schedule sp task to perform default status block work, ack
  4613. * attentions and enable interrupts.
  4614. */
  4615. bnx2x_schedule_sp_task(bp);
  4616. return IRQ_HANDLED;
  4617. }
  4618. /* end of slow path */
  4619. void bnx2x_drv_pulse(struct bnx2x *bp)
  4620. {
  4621. SHMEM_WR(bp, func_mb[BP_FW_MB_IDX(bp)].drv_pulse_mb,
  4622. bp->fw_drv_pulse_wr_seq);
  4623. }
  4624. static void bnx2x_timer(unsigned long data)
  4625. {
  4626. struct bnx2x *bp = (struct bnx2x *) data;
  4627. if (!netif_running(bp->dev))
  4628. return;
  4629. if (IS_PF(bp) &&
  4630. !BP_NOMCP(bp)) {
  4631. int mb_idx = BP_FW_MB_IDX(bp);
  4632. u16 drv_pulse;
  4633. u16 mcp_pulse;
  4634. ++bp->fw_drv_pulse_wr_seq;
  4635. bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK;
  4636. drv_pulse = bp->fw_drv_pulse_wr_seq;
  4637. bnx2x_drv_pulse(bp);
  4638. mcp_pulse = (SHMEM_RD(bp, func_mb[mb_idx].mcp_pulse_mb) &
  4639. MCP_PULSE_SEQ_MASK);
  4640. /* The delta between driver pulse and mcp response
  4641. * should not get too big. If the MFW is more than 5 pulses
  4642. * behind, we should worry about it enough to generate an error
  4643. * log.
  4644. */
  4645. if (((drv_pulse - mcp_pulse) & MCP_PULSE_SEQ_MASK) > 5)
  4646. BNX2X_ERR("MFW seems hanged: drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
  4647. drv_pulse, mcp_pulse);
  4648. }
  4649. if (bp->state == BNX2X_STATE_OPEN)
  4650. bnx2x_stats_handle(bp, STATS_EVENT_UPDATE);
  4651. /* sample pf vf bulletin board for new posts from pf */
  4652. if (IS_VF(bp))
  4653. bnx2x_timer_sriov(bp);
  4654. mod_timer(&bp->timer, jiffies + bp->current_interval);
  4655. }
  4656. /* end of Statistics */
  4657. /* nic init */
  4658. /*
  4659. * nic init service functions
  4660. */
  4661. static void bnx2x_fill(struct bnx2x *bp, u32 addr, int fill, u32 len)
  4662. {
  4663. u32 i;
  4664. if (!(len%4) && !(addr%4))
  4665. for (i = 0; i < len; i += 4)
  4666. REG_WR(bp, addr + i, fill);
  4667. else
  4668. for (i = 0; i < len; i++)
  4669. REG_WR8(bp, addr + i, fill);
  4670. }
  4671. /* helper: writes FP SP data to FW - data_size in dwords */
  4672. static void bnx2x_wr_fp_sb_data(struct bnx2x *bp,
  4673. int fw_sb_id,
  4674. u32 *sb_data_p,
  4675. u32 data_size)
  4676. {
  4677. int index;
  4678. for (index = 0; index < data_size; index++)
  4679. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4680. CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id) +
  4681. sizeof(u32)*index,
  4682. *(sb_data_p + index));
  4683. }
  4684. static void bnx2x_zero_fp_sb(struct bnx2x *bp, int fw_sb_id)
  4685. {
  4686. u32 *sb_data_p;
  4687. u32 data_size = 0;
  4688. struct hc_status_block_data_e2 sb_data_e2;
  4689. struct hc_status_block_data_e1x sb_data_e1x;
  4690. /* disable the function first */
  4691. if (!CHIP_IS_E1x(bp)) {
  4692. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  4693. sb_data_e2.common.state = SB_DISABLED;
  4694. sb_data_e2.common.p_func.vf_valid = false;
  4695. sb_data_p = (u32 *)&sb_data_e2;
  4696. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  4697. } else {
  4698. memset(&sb_data_e1x, 0,
  4699. sizeof(struct hc_status_block_data_e1x));
  4700. sb_data_e1x.common.state = SB_DISABLED;
  4701. sb_data_e1x.common.p_func.vf_valid = false;
  4702. sb_data_p = (u32 *)&sb_data_e1x;
  4703. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  4704. }
  4705. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  4706. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4707. CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id), 0,
  4708. CSTORM_STATUS_BLOCK_SIZE);
  4709. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4710. CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id), 0,
  4711. CSTORM_SYNC_BLOCK_SIZE);
  4712. }
  4713. /* helper: writes SP SB data to FW */
  4714. static void bnx2x_wr_sp_sb_data(struct bnx2x *bp,
  4715. struct hc_sp_status_block_data *sp_sb_data)
  4716. {
  4717. int func = BP_FUNC(bp);
  4718. int i;
  4719. for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
  4720. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4721. CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
  4722. i*sizeof(u32),
  4723. *((u32 *)sp_sb_data + i));
  4724. }
  4725. static void bnx2x_zero_sp_sb(struct bnx2x *bp)
  4726. {
  4727. int func = BP_FUNC(bp);
  4728. struct hc_sp_status_block_data sp_sb_data;
  4729. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  4730. sp_sb_data.state = SB_DISABLED;
  4731. sp_sb_data.p_func.vf_valid = false;
  4732. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  4733. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4734. CSTORM_SP_STATUS_BLOCK_OFFSET(func), 0,
  4735. CSTORM_SP_STATUS_BLOCK_SIZE);
  4736. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4737. CSTORM_SP_SYNC_BLOCK_OFFSET(func), 0,
  4738. CSTORM_SP_SYNC_BLOCK_SIZE);
  4739. }
  4740. static void bnx2x_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm,
  4741. int igu_sb_id, int igu_seg_id)
  4742. {
  4743. hc_sm->igu_sb_id = igu_sb_id;
  4744. hc_sm->igu_seg_id = igu_seg_id;
  4745. hc_sm->timer_value = 0xFF;
  4746. hc_sm->time_to_expire = 0xFFFFFFFF;
  4747. }
  4748. /* allocates state machine ids. */
  4749. static void bnx2x_map_sb_state_machines(struct hc_index_data *index_data)
  4750. {
  4751. /* zero out state machine indices */
  4752. /* rx indices */
  4753. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4754. /* tx indices */
  4755. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4756. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags &= ~HC_INDEX_DATA_SM_ID;
  4757. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags &= ~HC_INDEX_DATA_SM_ID;
  4758. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags &= ~HC_INDEX_DATA_SM_ID;
  4759. /* map indices */
  4760. /* rx indices */
  4761. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags |=
  4762. SM_RX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4763. /* tx indices */
  4764. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags |=
  4765. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4766. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags |=
  4767. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4768. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags |=
  4769. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4770. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags |=
  4771. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4772. }
  4773. void bnx2x_init_sb(struct bnx2x *bp, dma_addr_t mapping, int vfid,
  4774. u8 vf_valid, int fw_sb_id, int igu_sb_id)
  4775. {
  4776. int igu_seg_id;
  4777. struct hc_status_block_data_e2 sb_data_e2;
  4778. struct hc_status_block_data_e1x sb_data_e1x;
  4779. struct hc_status_block_sm *hc_sm_p;
  4780. int data_size;
  4781. u32 *sb_data_p;
  4782. if (CHIP_INT_MODE_IS_BC(bp))
  4783. igu_seg_id = HC_SEG_ACCESS_NORM;
  4784. else
  4785. igu_seg_id = IGU_SEG_ACCESS_NORM;
  4786. bnx2x_zero_fp_sb(bp, fw_sb_id);
  4787. if (!CHIP_IS_E1x(bp)) {
  4788. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  4789. sb_data_e2.common.state = SB_ENABLED;
  4790. sb_data_e2.common.p_func.pf_id = BP_FUNC(bp);
  4791. sb_data_e2.common.p_func.vf_id = vfid;
  4792. sb_data_e2.common.p_func.vf_valid = vf_valid;
  4793. sb_data_e2.common.p_func.vnic_id = BP_VN(bp);
  4794. sb_data_e2.common.same_igu_sb_1b = true;
  4795. sb_data_e2.common.host_sb_addr.hi = U64_HI(mapping);
  4796. sb_data_e2.common.host_sb_addr.lo = U64_LO(mapping);
  4797. hc_sm_p = sb_data_e2.common.state_machine;
  4798. sb_data_p = (u32 *)&sb_data_e2;
  4799. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  4800. bnx2x_map_sb_state_machines(sb_data_e2.index_data);
  4801. } else {
  4802. memset(&sb_data_e1x, 0,
  4803. sizeof(struct hc_status_block_data_e1x));
  4804. sb_data_e1x.common.state = SB_ENABLED;
  4805. sb_data_e1x.common.p_func.pf_id = BP_FUNC(bp);
  4806. sb_data_e1x.common.p_func.vf_id = 0xff;
  4807. sb_data_e1x.common.p_func.vf_valid = false;
  4808. sb_data_e1x.common.p_func.vnic_id = BP_VN(bp);
  4809. sb_data_e1x.common.same_igu_sb_1b = true;
  4810. sb_data_e1x.common.host_sb_addr.hi = U64_HI(mapping);
  4811. sb_data_e1x.common.host_sb_addr.lo = U64_LO(mapping);
  4812. hc_sm_p = sb_data_e1x.common.state_machine;
  4813. sb_data_p = (u32 *)&sb_data_e1x;
  4814. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  4815. bnx2x_map_sb_state_machines(sb_data_e1x.index_data);
  4816. }
  4817. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_RX_ID],
  4818. igu_sb_id, igu_seg_id);
  4819. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_TX_ID],
  4820. igu_sb_id, igu_seg_id);
  4821. DP(NETIF_MSG_IFUP, "Init FW SB %d\n", fw_sb_id);
  4822. /* write indices to HW - PCI guarantees endianity of regpairs */
  4823. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  4824. }
  4825. static void bnx2x_update_coalesce_sb(struct bnx2x *bp, u8 fw_sb_id,
  4826. u16 tx_usec, u16 rx_usec)
  4827. {
  4828. bnx2x_update_coalesce_sb_index(bp, fw_sb_id, HC_INDEX_ETH_RX_CQ_CONS,
  4829. false, rx_usec);
  4830. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4831. HC_INDEX_ETH_TX_CQ_CONS_COS0, false,
  4832. tx_usec);
  4833. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4834. HC_INDEX_ETH_TX_CQ_CONS_COS1, false,
  4835. tx_usec);
  4836. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4837. HC_INDEX_ETH_TX_CQ_CONS_COS2, false,
  4838. tx_usec);
  4839. }
  4840. static void bnx2x_init_def_sb(struct bnx2x *bp)
  4841. {
  4842. struct host_sp_status_block *def_sb = bp->def_status_blk;
  4843. dma_addr_t mapping = bp->def_status_blk_mapping;
  4844. int igu_sp_sb_index;
  4845. int igu_seg_id;
  4846. int port = BP_PORT(bp);
  4847. int func = BP_FUNC(bp);
  4848. int reg_offset, reg_offset_en5;
  4849. u64 section;
  4850. int index;
  4851. struct hc_sp_status_block_data sp_sb_data;
  4852. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  4853. if (CHIP_INT_MODE_IS_BC(bp)) {
  4854. igu_sp_sb_index = DEF_SB_IGU_ID;
  4855. igu_seg_id = HC_SEG_ACCESS_DEF;
  4856. } else {
  4857. igu_sp_sb_index = bp->igu_dsb_id;
  4858. igu_seg_id = IGU_SEG_ACCESS_DEF;
  4859. }
  4860. /* ATTN */
  4861. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  4862. atten_status_block);
  4863. def_sb->atten_status_block.status_block_id = igu_sp_sb_index;
  4864. bp->attn_state = 0;
  4865. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  4866. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  4867. reg_offset_en5 = (port ? MISC_REG_AEU_ENABLE5_FUNC_1_OUT_0 :
  4868. MISC_REG_AEU_ENABLE5_FUNC_0_OUT_0);
  4869. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  4870. int sindex;
  4871. /* take care of sig[0]..sig[4] */
  4872. for (sindex = 0; sindex < 4; sindex++)
  4873. bp->attn_group[index].sig[sindex] =
  4874. REG_RD(bp, reg_offset + sindex*0x4 + 0x10*index);
  4875. if (!CHIP_IS_E1x(bp))
  4876. /*
  4877. * enable5 is separate from the rest of the registers,
  4878. * and therefore the address skip is 4
  4879. * and not 16 between the different groups
  4880. */
  4881. bp->attn_group[index].sig[4] = REG_RD(bp,
  4882. reg_offset_en5 + 0x4*index);
  4883. else
  4884. bp->attn_group[index].sig[4] = 0;
  4885. }
  4886. if (bp->common.int_block == INT_BLOCK_HC) {
  4887. reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L :
  4888. HC_REG_ATTN_MSG0_ADDR_L);
  4889. REG_WR(bp, reg_offset, U64_LO(section));
  4890. REG_WR(bp, reg_offset + 4, U64_HI(section));
  4891. } else if (!CHIP_IS_E1x(bp)) {
  4892. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_L, U64_LO(section));
  4893. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_H, U64_HI(section));
  4894. }
  4895. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  4896. sp_sb);
  4897. bnx2x_zero_sp_sb(bp);
  4898. /* PCI guarantees endianity of regpairs */
  4899. sp_sb_data.state = SB_ENABLED;
  4900. sp_sb_data.host_sb_addr.lo = U64_LO(section);
  4901. sp_sb_data.host_sb_addr.hi = U64_HI(section);
  4902. sp_sb_data.igu_sb_id = igu_sp_sb_index;
  4903. sp_sb_data.igu_seg_id = igu_seg_id;
  4904. sp_sb_data.p_func.pf_id = func;
  4905. sp_sb_data.p_func.vnic_id = BP_VN(bp);
  4906. sp_sb_data.p_func.vf_id = 0xff;
  4907. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  4908. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0);
  4909. }
  4910. void bnx2x_update_coalesce(struct bnx2x *bp)
  4911. {
  4912. int i;
  4913. for_each_eth_queue(bp, i)
  4914. bnx2x_update_coalesce_sb(bp, bp->fp[i].fw_sb_id,
  4915. bp->tx_ticks, bp->rx_ticks);
  4916. }
  4917. static void bnx2x_init_sp_ring(struct bnx2x *bp)
  4918. {
  4919. spin_lock_init(&bp->spq_lock);
  4920. atomic_set(&bp->cq_spq_left, MAX_SPQ_PENDING);
  4921. bp->spq_prod_idx = 0;
  4922. bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX;
  4923. bp->spq_prod_bd = bp->spq;
  4924. bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT;
  4925. }
  4926. static void bnx2x_init_eq_ring(struct bnx2x *bp)
  4927. {
  4928. int i;
  4929. for (i = 1; i <= NUM_EQ_PAGES; i++) {
  4930. union event_ring_elem *elem =
  4931. &bp->eq_ring[EQ_DESC_CNT_PAGE * i - 1];
  4932. elem->next_page.addr.hi =
  4933. cpu_to_le32(U64_HI(bp->eq_mapping +
  4934. BCM_PAGE_SIZE * (i % NUM_EQ_PAGES)));
  4935. elem->next_page.addr.lo =
  4936. cpu_to_le32(U64_LO(bp->eq_mapping +
  4937. BCM_PAGE_SIZE*(i % NUM_EQ_PAGES)));
  4938. }
  4939. bp->eq_cons = 0;
  4940. bp->eq_prod = NUM_EQ_DESC;
  4941. bp->eq_cons_sb = BNX2X_EQ_INDEX;
  4942. /* we want a warning message before it gets wrought... */
  4943. atomic_set(&bp->eq_spq_left,
  4944. min_t(int, MAX_SP_DESC_CNT - MAX_SPQ_PENDING, NUM_EQ_DESC) - 1);
  4945. }
  4946. /* called with netif_addr_lock_bh() */
  4947. int bnx2x_set_q_rx_mode(struct bnx2x *bp, u8 cl_id,
  4948. unsigned long rx_mode_flags,
  4949. unsigned long rx_accept_flags,
  4950. unsigned long tx_accept_flags,
  4951. unsigned long ramrod_flags)
  4952. {
  4953. struct bnx2x_rx_mode_ramrod_params ramrod_param;
  4954. int rc;
  4955. memset(&ramrod_param, 0, sizeof(ramrod_param));
  4956. /* Prepare ramrod parameters */
  4957. ramrod_param.cid = 0;
  4958. ramrod_param.cl_id = cl_id;
  4959. ramrod_param.rx_mode_obj = &bp->rx_mode_obj;
  4960. ramrod_param.func_id = BP_FUNC(bp);
  4961. ramrod_param.pstate = &bp->sp_state;
  4962. ramrod_param.state = BNX2X_FILTER_RX_MODE_PENDING;
  4963. ramrod_param.rdata = bnx2x_sp(bp, rx_mode_rdata);
  4964. ramrod_param.rdata_mapping = bnx2x_sp_mapping(bp, rx_mode_rdata);
  4965. set_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  4966. ramrod_param.ramrod_flags = ramrod_flags;
  4967. ramrod_param.rx_mode_flags = rx_mode_flags;
  4968. ramrod_param.rx_accept_flags = rx_accept_flags;
  4969. ramrod_param.tx_accept_flags = tx_accept_flags;
  4970. rc = bnx2x_config_rx_mode(bp, &ramrod_param);
  4971. if (rc < 0) {
  4972. BNX2X_ERR("Set rx_mode %d failed\n", bp->rx_mode);
  4973. return rc;
  4974. }
  4975. return 0;
  4976. }
  4977. static int bnx2x_fill_accept_flags(struct bnx2x *bp, u32 rx_mode,
  4978. unsigned long *rx_accept_flags,
  4979. unsigned long *tx_accept_flags)
  4980. {
  4981. /* Clear the flags first */
  4982. *rx_accept_flags = 0;
  4983. *tx_accept_flags = 0;
  4984. switch (rx_mode) {
  4985. case BNX2X_RX_MODE_NONE:
  4986. /*
  4987. * 'drop all' supersedes any accept flags that may have been
  4988. * passed to the function.
  4989. */
  4990. break;
  4991. case BNX2X_RX_MODE_NORMAL:
  4992. __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
  4993. __set_bit(BNX2X_ACCEPT_MULTICAST, rx_accept_flags);
  4994. __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
  4995. /* internal switching mode */
  4996. __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
  4997. __set_bit(BNX2X_ACCEPT_MULTICAST, tx_accept_flags);
  4998. __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
  4999. break;
  5000. case BNX2X_RX_MODE_ALLMULTI:
  5001. __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
  5002. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, rx_accept_flags);
  5003. __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
  5004. /* internal switching mode */
  5005. __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
  5006. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, tx_accept_flags);
  5007. __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
  5008. break;
  5009. case BNX2X_RX_MODE_PROMISC:
  5010. /* According to definition of SI mode, iface in promisc mode
  5011. * should receive matched and unmatched (in resolution of port)
  5012. * unicast packets.
  5013. */
  5014. __set_bit(BNX2X_ACCEPT_UNMATCHED, rx_accept_flags);
  5015. __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
  5016. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, rx_accept_flags);
  5017. __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
  5018. /* internal switching mode */
  5019. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, tx_accept_flags);
  5020. __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
  5021. if (IS_MF_SI(bp))
  5022. __set_bit(BNX2X_ACCEPT_ALL_UNICAST, tx_accept_flags);
  5023. else
  5024. __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
  5025. break;
  5026. default:
  5027. BNX2X_ERR("Unknown rx_mode: %d\n", rx_mode);
  5028. return -EINVAL;
  5029. }
  5030. /* Set ACCEPT_ANY_VLAN as we do not enable filtering by VLAN */
  5031. if (bp->rx_mode != BNX2X_RX_MODE_NONE) {
  5032. __set_bit(BNX2X_ACCEPT_ANY_VLAN, rx_accept_flags);
  5033. __set_bit(BNX2X_ACCEPT_ANY_VLAN, tx_accept_flags);
  5034. }
  5035. return 0;
  5036. }
  5037. /* called with netif_addr_lock_bh() */
  5038. int bnx2x_set_storm_rx_mode(struct bnx2x *bp)
  5039. {
  5040. unsigned long rx_mode_flags = 0, ramrod_flags = 0;
  5041. unsigned long rx_accept_flags = 0, tx_accept_flags = 0;
  5042. int rc;
  5043. if (!NO_FCOE(bp))
  5044. /* Configure rx_mode of FCoE Queue */
  5045. __set_bit(BNX2X_RX_MODE_FCOE_ETH, &rx_mode_flags);
  5046. rc = bnx2x_fill_accept_flags(bp, bp->rx_mode, &rx_accept_flags,
  5047. &tx_accept_flags);
  5048. if (rc)
  5049. return rc;
  5050. __set_bit(RAMROD_RX, &ramrod_flags);
  5051. __set_bit(RAMROD_TX, &ramrod_flags);
  5052. return bnx2x_set_q_rx_mode(bp, bp->fp->cl_id, rx_mode_flags,
  5053. rx_accept_flags, tx_accept_flags,
  5054. ramrod_flags);
  5055. }
  5056. static void bnx2x_init_internal_common(struct bnx2x *bp)
  5057. {
  5058. int i;
  5059. if (IS_MF_SI(bp))
  5060. /*
  5061. * In switch independent mode, the TSTORM needs to accept
  5062. * packets that failed classification, since approximate match
  5063. * mac addresses aren't written to NIG LLH
  5064. */
  5065. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  5066. TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 2);
  5067. else if (!CHIP_IS_E1(bp)) /* 57710 doesn't support MF */
  5068. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  5069. TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 0);
  5070. /* Zero this manually as its initialization is
  5071. currently missing in the initTool */
  5072. for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++)
  5073. REG_WR(bp, BAR_USTRORM_INTMEM +
  5074. USTORM_AGG_DATA_OFFSET + i * 4, 0);
  5075. if (!CHIP_IS_E1x(bp)) {
  5076. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_IGU_MODE_OFFSET,
  5077. CHIP_INT_MODE_IS_BC(bp) ?
  5078. HC_IGU_BC_MODE : HC_IGU_NBC_MODE);
  5079. }
  5080. }
  5081. static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code)
  5082. {
  5083. switch (load_code) {
  5084. case FW_MSG_CODE_DRV_LOAD_COMMON:
  5085. case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
  5086. bnx2x_init_internal_common(bp);
  5087. /* no break */
  5088. case FW_MSG_CODE_DRV_LOAD_PORT:
  5089. /* nothing to do */
  5090. /* no break */
  5091. case FW_MSG_CODE_DRV_LOAD_FUNCTION:
  5092. /* internal memory per function is
  5093. initialized inside bnx2x_pf_init */
  5094. break;
  5095. default:
  5096. BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
  5097. break;
  5098. }
  5099. }
  5100. static inline u8 bnx2x_fp_igu_sb_id(struct bnx2x_fastpath *fp)
  5101. {
  5102. return fp->bp->igu_base_sb + fp->index + CNIC_SUPPORT(fp->bp);
  5103. }
  5104. static inline u8 bnx2x_fp_fw_sb_id(struct bnx2x_fastpath *fp)
  5105. {
  5106. return fp->bp->base_fw_ndsb + fp->index + CNIC_SUPPORT(fp->bp);
  5107. }
  5108. static u8 bnx2x_fp_cl_id(struct bnx2x_fastpath *fp)
  5109. {
  5110. if (CHIP_IS_E1x(fp->bp))
  5111. return BP_L_ID(fp->bp) + fp->index;
  5112. else /* We want Client ID to be the same as IGU SB ID for 57712 */
  5113. return bnx2x_fp_igu_sb_id(fp);
  5114. }
  5115. static void bnx2x_init_eth_fp(struct bnx2x *bp, int fp_idx)
  5116. {
  5117. struct bnx2x_fastpath *fp = &bp->fp[fp_idx];
  5118. u8 cos;
  5119. unsigned long q_type = 0;
  5120. u32 cids[BNX2X_MULTI_TX_COS] = { 0 };
  5121. fp->rx_queue = fp_idx;
  5122. fp->cid = fp_idx;
  5123. fp->cl_id = bnx2x_fp_cl_id(fp);
  5124. fp->fw_sb_id = bnx2x_fp_fw_sb_id(fp);
  5125. fp->igu_sb_id = bnx2x_fp_igu_sb_id(fp);
  5126. /* qZone id equals to FW (per path) client id */
  5127. fp->cl_qzone_id = bnx2x_fp_qzone_id(fp);
  5128. /* init shortcut */
  5129. fp->ustorm_rx_prods_offset = bnx2x_rx_ustorm_prods_offset(fp);
  5130. /* Setup SB indices */
  5131. fp->rx_cons_sb = BNX2X_RX_SB_INDEX;
  5132. /* Configure Queue State object */
  5133. __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
  5134. __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
  5135. BUG_ON(fp->max_cos > BNX2X_MULTI_TX_COS);
  5136. /* init tx data */
  5137. for_each_cos_in_tx_queue(fp, cos) {
  5138. bnx2x_init_txdata(bp, fp->txdata_ptr[cos],
  5139. CID_COS_TO_TX_ONLY_CID(fp->cid, cos, bp),
  5140. FP_COS_TO_TXQ(fp, cos, bp),
  5141. BNX2X_TX_SB_INDEX_BASE + cos, fp);
  5142. cids[cos] = fp->txdata_ptr[cos]->cid;
  5143. }
  5144. /* nothing more for vf to do here */
  5145. if (IS_VF(bp))
  5146. return;
  5147. bnx2x_init_sb(bp, fp->status_blk_mapping, BNX2X_VF_ID_INVALID, false,
  5148. fp->fw_sb_id, fp->igu_sb_id);
  5149. bnx2x_update_fpsb_idx(fp);
  5150. bnx2x_init_queue_obj(bp, &bnx2x_sp_obj(bp, fp).q_obj, fp->cl_id, cids,
  5151. fp->max_cos, BP_FUNC(bp), bnx2x_sp(bp, q_rdata),
  5152. bnx2x_sp_mapping(bp, q_rdata), q_type);
  5153. /**
  5154. * Configure classification DBs: Always enable Tx switching
  5155. */
  5156. bnx2x_init_vlan_mac_fp_objs(fp, BNX2X_OBJ_TYPE_RX_TX);
  5157. DP(NETIF_MSG_IFUP,
  5158. "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d fw_sb %d igu_sb %d\n",
  5159. fp_idx, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
  5160. fp->igu_sb_id);
  5161. }
  5162. static void bnx2x_init_tx_ring_one(struct bnx2x_fp_txdata *txdata)
  5163. {
  5164. int i;
  5165. for (i = 1; i <= NUM_TX_RINGS; i++) {
  5166. struct eth_tx_next_bd *tx_next_bd =
  5167. &txdata->tx_desc_ring[TX_DESC_CNT * i - 1].next_bd;
  5168. tx_next_bd->addr_hi =
  5169. cpu_to_le32(U64_HI(txdata->tx_desc_mapping +
  5170. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  5171. tx_next_bd->addr_lo =
  5172. cpu_to_le32(U64_LO(txdata->tx_desc_mapping +
  5173. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  5174. }
  5175. *txdata->tx_cons_sb = cpu_to_le16(0);
  5176. SET_FLAG(txdata->tx_db.data.header.header, DOORBELL_HDR_DB_TYPE, 1);
  5177. txdata->tx_db.data.zero_fill1 = 0;
  5178. txdata->tx_db.data.prod = 0;
  5179. txdata->tx_pkt_prod = 0;
  5180. txdata->tx_pkt_cons = 0;
  5181. txdata->tx_bd_prod = 0;
  5182. txdata->tx_bd_cons = 0;
  5183. txdata->tx_pkt = 0;
  5184. }
  5185. static void bnx2x_init_tx_rings_cnic(struct bnx2x *bp)
  5186. {
  5187. int i;
  5188. for_each_tx_queue_cnic(bp, i)
  5189. bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[0]);
  5190. }
  5191. static void bnx2x_init_tx_rings(struct bnx2x *bp)
  5192. {
  5193. int i;
  5194. u8 cos;
  5195. for_each_eth_queue(bp, i)
  5196. for_each_cos_in_tx_queue(&bp->fp[i], cos)
  5197. bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[cos]);
  5198. }
  5199. void bnx2x_nic_init_cnic(struct bnx2x *bp)
  5200. {
  5201. if (!NO_FCOE(bp))
  5202. bnx2x_init_fcoe_fp(bp);
  5203. bnx2x_init_sb(bp, bp->cnic_sb_mapping,
  5204. BNX2X_VF_ID_INVALID, false,
  5205. bnx2x_cnic_fw_sb_id(bp), bnx2x_cnic_igu_sb_id(bp));
  5206. /* ensure status block indices were read */
  5207. rmb();
  5208. bnx2x_init_rx_rings_cnic(bp);
  5209. bnx2x_init_tx_rings_cnic(bp);
  5210. /* flush all */
  5211. mb();
  5212. mmiowb();
  5213. }
  5214. void bnx2x_pre_irq_nic_init(struct bnx2x *bp)
  5215. {
  5216. int i;
  5217. /* Setup NIC internals and enable interrupts */
  5218. for_each_eth_queue(bp, i)
  5219. bnx2x_init_eth_fp(bp, i);
  5220. /* ensure status block indices were read */
  5221. rmb();
  5222. bnx2x_init_rx_rings(bp);
  5223. bnx2x_init_tx_rings(bp);
  5224. if (IS_PF(bp)) {
  5225. /* Initialize MOD_ABS interrupts */
  5226. bnx2x_init_mod_abs_int(bp, &bp->link_vars, bp->common.chip_id,
  5227. bp->common.shmem_base,
  5228. bp->common.shmem2_base, BP_PORT(bp));
  5229. /* initialize the default status block and sp ring */
  5230. bnx2x_init_def_sb(bp);
  5231. bnx2x_update_dsb_idx(bp);
  5232. bnx2x_init_sp_ring(bp);
  5233. } else {
  5234. bnx2x_memset_stats(bp);
  5235. }
  5236. }
  5237. void bnx2x_post_irq_nic_init(struct bnx2x *bp, u32 load_code)
  5238. {
  5239. bnx2x_init_eq_ring(bp);
  5240. bnx2x_init_internal(bp, load_code);
  5241. bnx2x_pf_init(bp);
  5242. bnx2x_stats_init(bp);
  5243. /* flush all before enabling interrupts */
  5244. mb();
  5245. mmiowb();
  5246. bnx2x_int_enable(bp);
  5247. /* Check for SPIO5 */
  5248. bnx2x_attn_int_deasserted0(bp,
  5249. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + BP_PORT(bp)*4) &
  5250. AEU_INPUTS_ATTN_BITS_SPIO5);
  5251. }
  5252. /* gzip service functions */
  5253. static int bnx2x_gunzip_init(struct bnx2x *bp)
  5254. {
  5255. bp->gunzip_buf = dma_alloc_coherent(&bp->pdev->dev, FW_BUF_SIZE,
  5256. &bp->gunzip_mapping, GFP_KERNEL);
  5257. if (bp->gunzip_buf == NULL)
  5258. goto gunzip_nomem1;
  5259. bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL);
  5260. if (bp->strm == NULL)
  5261. goto gunzip_nomem2;
  5262. bp->strm->workspace = vmalloc(zlib_inflate_workspacesize());
  5263. if (bp->strm->workspace == NULL)
  5264. goto gunzip_nomem3;
  5265. return 0;
  5266. gunzip_nomem3:
  5267. kfree(bp->strm);
  5268. bp->strm = NULL;
  5269. gunzip_nomem2:
  5270. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  5271. bp->gunzip_mapping);
  5272. bp->gunzip_buf = NULL;
  5273. gunzip_nomem1:
  5274. BNX2X_ERR("Cannot allocate firmware buffer for un-compression\n");
  5275. return -ENOMEM;
  5276. }
  5277. static void bnx2x_gunzip_end(struct bnx2x *bp)
  5278. {
  5279. if (bp->strm) {
  5280. vfree(bp->strm->workspace);
  5281. kfree(bp->strm);
  5282. bp->strm = NULL;
  5283. }
  5284. if (bp->gunzip_buf) {
  5285. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  5286. bp->gunzip_mapping);
  5287. bp->gunzip_buf = NULL;
  5288. }
  5289. }
  5290. static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len)
  5291. {
  5292. int n, rc;
  5293. /* check gzip header */
  5294. if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED)) {
  5295. BNX2X_ERR("Bad gzip header\n");
  5296. return -EINVAL;
  5297. }
  5298. n = 10;
  5299. #define FNAME 0x8
  5300. if (zbuf[3] & FNAME)
  5301. while ((zbuf[n++] != 0) && (n < len));
  5302. bp->strm->next_in = (typeof(bp->strm->next_in))zbuf + n;
  5303. bp->strm->avail_in = len - n;
  5304. bp->strm->next_out = bp->gunzip_buf;
  5305. bp->strm->avail_out = FW_BUF_SIZE;
  5306. rc = zlib_inflateInit2(bp->strm, -MAX_WBITS);
  5307. if (rc != Z_OK)
  5308. return rc;
  5309. rc = zlib_inflate(bp->strm, Z_FINISH);
  5310. if ((rc != Z_OK) && (rc != Z_STREAM_END))
  5311. netdev_err(bp->dev, "Firmware decompression error: %s\n",
  5312. bp->strm->msg);
  5313. bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out);
  5314. if (bp->gunzip_outlen & 0x3)
  5315. netdev_err(bp->dev,
  5316. "Firmware decompression error: gunzip_outlen (%d) not aligned\n",
  5317. bp->gunzip_outlen);
  5318. bp->gunzip_outlen >>= 2;
  5319. zlib_inflateEnd(bp->strm);
  5320. if (rc == Z_STREAM_END)
  5321. return 0;
  5322. return rc;
  5323. }
  5324. /* nic load/unload */
  5325. /*
  5326. * General service functions
  5327. */
  5328. /* send a NIG loopback debug packet */
  5329. static void bnx2x_lb_pckt(struct bnx2x *bp)
  5330. {
  5331. u32 wb_write[3];
  5332. /* Ethernet source and destination addresses */
  5333. wb_write[0] = 0x55555555;
  5334. wb_write[1] = 0x55555555;
  5335. wb_write[2] = 0x20; /* SOP */
  5336. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  5337. /* NON-IP protocol */
  5338. wb_write[0] = 0x09000000;
  5339. wb_write[1] = 0x55555555;
  5340. wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */
  5341. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  5342. }
  5343. /* some of the internal memories
  5344. * are not directly readable from the driver
  5345. * to test them we send debug packets
  5346. */
  5347. static int bnx2x_int_mem_test(struct bnx2x *bp)
  5348. {
  5349. int factor;
  5350. int count, i;
  5351. u32 val = 0;
  5352. if (CHIP_REV_IS_FPGA(bp))
  5353. factor = 120;
  5354. else if (CHIP_REV_IS_EMUL(bp))
  5355. factor = 200;
  5356. else
  5357. factor = 1;
  5358. /* Disable inputs of parser neighbor blocks */
  5359. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  5360. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  5361. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  5362. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  5363. /* Write 0 to parser credits for CFC search request */
  5364. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  5365. /* send Ethernet packet */
  5366. bnx2x_lb_pckt(bp);
  5367. /* TODO do i reset NIG statistic? */
  5368. /* Wait until NIG register shows 1 packet of size 0x10 */
  5369. count = 1000 * factor;
  5370. while (count) {
  5371. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5372. val = *bnx2x_sp(bp, wb_data[0]);
  5373. if (val == 0x10)
  5374. break;
  5375. usleep_range(10000, 20000);
  5376. count--;
  5377. }
  5378. if (val != 0x10) {
  5379. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  5380. return -1;
  5381. }
  5382. /* Wait until PRS register shows 1 packet */
  5383. count = 1000 * factor;
  5384. while (count) {
  5385. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5386. if (val == 1)
  5387. break;
  5388. usleep_range(10000, 20000);
  5389. count--;
  5390. }
  5391. if (val != 0x1) {
  5392. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5393. return -2;
  5394. }
  5395. /* Reset and init BRB, PRS */
  5396. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  5397. msleep(50);
  5398. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  5399. msleep(50);
  5400. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5401. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5402. DP(NETIF_MSG_HW, "part2\n");
  5403. /* Disable inputs of parser neighbor blocks */
  5404. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  5405. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  5406. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  5407. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  5408. /* Write 0 to parser credits for CFC search request */
  5409. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  5410. /* send 10 Ethernet packets */
  5411. for (i = 0; i < 10; i++)
  5412. bnx2x_lb_pckt(bp);
  5413. /* Wait until NIG register shows 10 + 1
  5414. packets of size 11*0x10 = 0xb0 */
  5415. count = 1000 * factor;
  5416. while (count) {
  5417. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5418. val = *bnx2x_sp(bp, wb_data[0]);
  5419. if (val == 0xb0)
  5420. break;
  5421. usleep_range(10000, 20000);
  5422. count--;
  5423. }
  5424. if (val != 0xb0) {
  5425. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  5426. return -3;
  5427. }
  5428. /* Wait until PRS register shows 2 packets */
  5429. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5430. if (val != 2)
  5431. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5432. /* Write 1 to parser credits for CFC search request */
  5433. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1);
  5434. /* Wait until PRS register shows 3 packets */
  5435. msleep(10 * factor);
  5436. /* Wait until NIG register shows 1 packet of size 0x10 */
  5437. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5438. if (val != 3)
  5439. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5440. /* clear NIG EOP FIFO */
  5441. for (i = 0; i < 11; i++)
  5442. REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO);
  5443. val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY);
  5444. if (val != 1) {
  5445. BNX2X_ERR("clear of NIG failed\n");
  5446. return -4;
  5447. }
  5448. /* Reset and init BRB, PRS, NIG */
  5449. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  5450. msleep(50);
  5451. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  5452. msleep(50);
  5453. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5454. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5455. if (!CNIC_SUPPORT(bp))
  5456. /* set NIC mode */
  5457. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  5458. /* Enable inputs of parser neighbor blocks */
  5459. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff);
  5460. REG_WR(bp, TCM_REG_PRS_IFEN, 0x1);
  5461. REG_WR(bp, CFC_REG_DEBUG0, 0x0);
  5462. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1);
  5463. DP(NETIF_MSG_HW, "done\n");
  5464. return 0; /* OK */
  5465. }
  5466. static void bnx2x_enable_blocks_attention(struct bnx2x *bp)
  5467. {
  5468. u32 val;
  5469. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5470. if (!CHIP_IS_E1x(bp))
  5471. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0x40);
  5472. else
  5473. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0);
  5474. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  5475. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  5476. /*
  5477. * mask read length error interrupts in brb for parser
  5478. * (parsing unit and 'checksum and crc' unit)
  5479. * these errors are legal (PU reads fixed length and CAC can cause
  5480. * read length error on truncated packets)
  5481. */
  5482. REG_WR(bp, BRB1_REG_BRB1_INT_MASK, 0xFC00);
  5483. REG_WR(bp, QM_REG_QM_INT_MASK, 0);
  5484. REG_WR(bp, TM_REG_TM_INT_MASK, 0);
  5485. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0);
  5486. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0);
  5487. REG_WR(bp, XCM_REG_XCM_INT_MASK, 0);
  5488. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */
  5489. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */
  5490. REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0);
  5491. REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0);
  5492. REG_WR(bp, UCM_REG_UCM_INT_MASK, 0);
  5493. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */
  5494. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */
  5495. REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0);
  5496. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0);
  5497. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0);
  5498. REG_WR(bp, CCM_REG_CCM_INT_MASK, 0);
  5499. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */
  5500. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */
  5501. val = PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT |
  5502. PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF |
  5503. PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN;
  5504. if (!CHIP_IS_E1x(bp))
  5505. val |= PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED |
  5506. PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED;
  5507. REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, val);
  5508. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0);
  5509. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0);
  5510. REG_WR(bp, TCM_REG_TCM_INT_MASK, 0);
  5511. /* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */
  5512. if (!CHIP_IS_E1x(bp))
  5513. /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */
  5514. REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0x07ff);
  5515. REG_WR(bp, CDU_REG_CDU_INT_MASK, 0);
  5516. REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0);
  5517. /* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */
  5518. REG_WR(bp, PBF_REG_PBF_INT_MASK, 0x18); /* bit 3,4 masked */
  5519. }
  5520. static void bnx2x_reset_common(struct bnx2x *bp)
  5521. {
  5522. u32 val = 0x1400;
  5523. /* reset_common */
  5524. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  5525. 0xd3ffff7f);
  5526. if (CHIP_IS_E3(bp)) {
  5527. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  5528. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  5529. }
  5530. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, val);
  5531. }
  5532. static void bnx2x_setup_dmae(struct bnx2x *bp)
  5533. {
  5534. bp->dmae_ready = 0;
  5535. spin_lock_init(&bp->dmae_lock);
  5536. }
  5537. static void bnx2x_init_pxp(struct bnx2x *bp)
  5538. {
  5539. u16 devctl;
  5540. int r_order, w_order;
  5541. pcie_capability_read_word(bp->pdev, PCI_EXP_DEVCTL, &devctl);
  5542. DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl);
  5543. w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
  5544. if (bp->mrrs == -1)
  5545. r_order = ((devctl & PCI_EXP_DEVCTL_READRQ) >> 12);
  5546. else {
  5547. DP(NETIF_MSG_HW, "force read order to %d\n", bp->mrrs);
  5548. r_order = bp->mrrs;
  5549. }
  5550. bnx2x_init_pxp_arb(bp, r_order, w_order);
  5551. }
  5552. static void bnx2x_setup_fan_failure_detection(struct bnx2x *bp)
  5553. {
  5554. int is_required;
  5555. u32 val;
  5556. int port;
  5557. if (BP_NOMCP(bp))
  5558. return;
  5559. is_required = 0;
  5560. val = SHMEM_RD(bp, dev_info.shared_hw_config.config2) &
  5561. SHARED_HW_CFG_FAN_FAILURE_MASK;
  5562. if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED)
  5563. is_required = 1;
  5564. /*
  5565. * The fan failure mechanism is usually related to the PHY type since
  5566. * the power consumption of the board is affected by the PHY. Currently,
  5567. * fan is required for most designs with SFX7101, BCM8727 and BCM8481.
  5568. */
  5569. else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE)
  5570. for (port = PORT_0; port < PORT_MAX; port++) {
  5571. is_required |=
  5572. bnx2x_fan_failure_det_req(
  5573. bp,
  5574. bp->common.shmem_base,
  5575. bp->common.shmem2_base,
  5576. port);
  5577. }
  5578. DP(NETIF_MSG_HW, "fan detection setting: %d\n", is_required);
  5579. if (is_required == 0)
  5580. return;
  5581. /* Fan failure is indicated by SPIO 5 */
  5582. bnx2x_set_spio(bp, MISC_SPIO_SPIO5, MISC_SPIO_INPUT_HI_Z);
  5583. /* set to active low mode */
  5584. val = REG_RD(bp, MISC_REG_SPIO_INT);
  5585. val |= (MISC_SPIO_SPIO5 << MISC_SPIO_INT_OLD_SET_POS);
  5586. REG_WR(bp, MISC_REG_SPIO_INT, val);
  5587. /* enable interrupt to signal the IGU */
  5588. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  5589. val |= MISC_SPIO_SPIO5;
  5590. REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val);
  5591. }
  5592. void bnx2x_pf_disable(struct bnx2x *bp)
  5593. {
  5594. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  5595. val &= ~IGU_PF_CONF_FUNC_EN;
  5596. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  5597. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  5598. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 0);
  5599. }
  5600. static void bnx2x__common_init_phy(struct bnx2x *bp)
  5601. {
  5602. u32 shmem_base[2], shmem2_base[2];
  5603. /* Avoid common init in case MFW supports LFA */
  5604. if (SHMEM2_RD(bp, size) >
  5605. (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
  5606. return;
  5607. shmem_base[0] = bp->common.shmem_base;
  5608. shmem2_base[0] = bp->common.shmem2_base;
  5609. if (!CHIP_IS_E1x(bp)) {
  5610. shmem_base[1] =
  5611. SHMEM2_RD(bp, other_shmem_base_addr);
  5612. shmem2_base[1] =
  5613. SHMEM2_RD(bp, other_shmem2_base_addr);
  5614. }
  5615. bnx2x_acquire_phy_lock(bp);
  5616. bnx2x_common_init_phy(bp, shmem_base, shmem2_base,
  5617. bp->common.chip_id);
  5618. bnx2x_release_phy_lock(bp);
  5619. }
  5620. /**
  5621. * bnx2x_init_hw_common - initialize the HW at the COMMON phase.
  5622. *
  5623. * @bp: driver handle
  5624. */
  5625. static int bnx2x_init_hw_common(struct bnx2x *bp)
  5626. {
  5627. u32 val;
  5628. DP(NETIF_MSG_HW, "starting common init func %d\n", BP_ABS_FUNC(bp));
  5629. /*
  5630. * take the RESET lock to protect undi_unload flow from accessing
  5631. * registers while we're resetting the chip
  5632. */
  5633. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5634. bnx2x_reset_common(bp);
  5635. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff);
  5636. val = 0xfffc;
  5637. if (CHIP_IS_E3(bp)) {
  5638. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  5639. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  5640. }
  5641. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, val);
  5642. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5643. bnx2x_init_block(bp, BLOCK_MISC, PHASE_COMMON);
  5644. if (!CHIP_IS_E1x(bp)) {
  5645. u8 abs_func_id;
  5646. /**
  5647. * 4-port mode or 2-port mode we need to turn of master-enable
  5648. * for everyone, after that, turn it back on for self.
  5649. * so, we disregard multi-function or not, and always disable
  5650. * for all functions on the given path, this means 0,2,4,6 for
  5651. * path 0 and 1,3,5,7 for path 1
  5652. */
  5653. for (abs_func_id = BP_PATH(bp);
  5654. abs_func_id < E2_FUNC_MAX*2; abs_func_id += 2) {
  5655. if (abs_func_id == BP_ABS_FUNC(bp)) {
  5656. REG_WR(bp,
  5657. PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER,
  5658. 1);
  5659. continue;
  5660. }
  5661. bnx2x_pretend_func(bp, abs_func_id);
  5662. /* clear pf enable */
  5663. bnx2x_pf_disable(bp);
  5664. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  5665. }
  5666. }
  5667. bnx2x_init_block(bp, BLOCK_PXP, PHASE_COMMON);
  5668. if (CHIP_IS_E1(bp)) {
  5669. /* enable HW interrupt from PXP on USDM overflow
  5670. bit 16 on INT_MASK_0 */
  5671. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5672. }
  5673. bnx2x_init_block(bp, BLOCK_PXP2, PHASE_COMMON);
  5674. bnx2x_init_pxp(bp);
  5675. #ifdef __BIG_ENDIAN
  5676. REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, 1);
  5677. REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, 1);
  5678. REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, 1);
  5679. REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, 1);
  5680. REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, 1);
  5681. /* make sure this value is 0 */
  5682. REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0);
  5683. /* REG_WR(bp, PXP2_REG_RD_PBF_SWAP_MODE, 1); */
  5684. REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, 1);
  5685. REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, 1);
  5686. REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, 1);
  5687. REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, 1);
  5688. #endif
  5689. bnx2x_ilt_init_page_size(bp, INITOP_SET);
  5690. if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp))
  5691. REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1);
  5692. /* let the HW do it's magic ... */
  5693. msleep(100);
  5694. /* finish PXP init */
  5695. val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE);
  5696. if (val != 1) {
  5697. BNX2X_ERR("PXP2 CFG failed\n");
  5698. return -EBUSY;
  5699. }
  5700. val = REG_RD(bp, PXP2_REG_RD_INIT_DONE);
  5701. if (val != 1) {
  5702. BNX2X_ERR("PXP2 RD_INIT failed\n");
  5703. return -EBUSY;
  5704. }
  5705. /* Timers bug workaround E2 only. We need to set the entire ILT to
  5706. * have entries with value "0" and valid bit on.
  5707. * This needs to be done by the first PF that is loaded in a path
  5708. * (i.e. common phase)
  5709. */
  5710. if (!CHIP_IS_E1x(bp)) {
  5711. /* In E2 there is a bug in the timers block that can cause function 6 / 7
  5712. * (i.e. vnic3) to start even if it is marked as "scan-off".
  5713. * This occurs when a different function (func2,3) is being marked
  5714. * as "scan-off". Real-life scenario for example: if a driver is being
  5715. * load-unloaded while func6,7 are down. This will cause the timer to access
  5716. * the ilt, translate to a logical address and send a request to read/write.
  5717. * Since the ilt for the function that is down is not valid, this will cause
  5718. * a translation error which is unrecoverable.
  5719. * The Workaround is intended to make sure that when this happens nothing fatal
  5720. * will occur. The workaround:
  5721. * 1. First PF driver which loads on a path will:
  5722. * a. After taking the chip out of reset, by using pretend,
  5723. * it will write "0" to the following registers of
  5724. * the other vnics.
  5725. * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  5726. * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0);
  5727. * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0);
  5728. * And for itself it will write '1' to
  5729. * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable
  5730. * dmae-operations (writing to pram for example.)
  5731. * note: can be done for only function 6,7 but cleaner this
  5732. * way.
  5733. * b. Write zero+valid to the entire ILT.
  5734. * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of
  5735. * VNIC3 (of that port). The range allocated will be the
  5736. * entire ILT. This is needed to prevent ILT range error.
  5737. * 2. Any PF driver load flow:
  5738. * a. ILT update with the physical addresses of the allocated
  5739. * logical pages.
  5740. * b. Wait 20msec. - note that this timeout is needed to make
  5741. * sure there are no requests in one of the PXP internal
  5742. * queues with "old" ILT addresses.
  5743. * c. PF enable in the PGLC.
  5744. * d. Clear the was_error of the PF in the PGLC. (could have
  5745. * occurred while driver was down)
  5746. * e. PF enable in the CFC (WEAK + STRONG)
  5747. * f. Timers scan enable
  5748. * 3. PF driver unload flow:
  5749. * a. Clear the Timers scan_en.
  5750. * b. Polling for scan_on=0 for that PF.
  5751. * c. Clear the PF enable bit in the PXP.
  5752. * d. Clear the PF enable in the CFC (WEAK + STRONG)
  5753. * e. Write zero+valid to all ILT entries (The valid bit must
  5754. * stay set)
  5755. * f. If this is VNIC 3 of a port then also init
  5756. * first_timers_ilt_entry to zero and last_timers_ilt_entry
  5757. * to the last entry in the ILT.
  5758. *
  5759. * Notes:
  5760. * Currently the PF error in the PGLC is non recoverable.
  5761. * In the future the there will be a recovery routine for this error.
  5762. * Currently attention is masked.
  5763. * Having an MCP lock on the load/unload process does not guarantee that
  5764. * there is no Timer disable during Func6/7 enable. This is because the
  5765. * Timers scan is currently being cleared by the MCP on FLR.
  5766. * Step 2.d can be done only for PF6/7 and the driver can also check if
  5767. * there is error before clearing it. But the flow above is simpler and
  5768. * more general.
  5769. * All ILT entries are written by zero+valid and not just PF6/7
  5770. * ILT entries since in the future the ILT entries allocation for
  5771. * PF-s might be dynamic.
  5772. */
  5773. struct ilt_client_info ilt_cli;
  5774. struct bnx2x_ilt ilt;
  5775. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  5776. memset(&ilt, 0, sizeof(struct bnx2x_ilt));
  5777. /* initialize dummy TM client */
  5778. ilt_cli.start = 0;
  5779. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  5780. ilt_cli.client_num = ILT_CLIENT_TM;
  5781. /* Step 1: set zeroes to all ilt page entries with valid bit on
  5782. * Step 2: set the timers first/last ilt entry to point
  5783. * to the entire range to prevent ILT range error for 3rd/4th
  5784. * vnic (this code assumes existence of the vnic)
  5785. *
  5786. * both steps performed by call to bnx2x_ilt_client_init_op()
  5787. * with dummy TM client
  5788. *
  5789. * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT
  5790. * and his brother are split registers
  5791. */
  5792. bnx2x_pretend_func(bp, (BP_PATH(bp) + 6));
  5793. bnx2x_ilt_client_init_op_ilt(bp, &ilt, &ilt_cli, INITOP_CLEAR);
  5794. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  5795. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN, BNX2X_PXP_DRAM_ALIGN);
  5796. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_RD, BNX2X_PXP_DRAM_ALIGN);
  5797. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_SEL, 1);
  5798. }
  5799. REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0);
  5800. REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0);
  5801. if (!CHIP_IS_E1x(bp)) {
  5802. int factor = CHIP_REV_IS_EMUL(bp) ? 1000 :
  5803. (CHIP_REV_IS_FPGA(bp) ? 400 : 0);
  5804. bnx2x_init_block(bp, BLOCK_PGLUE_B, PHASE_COMMON);
  5805. bnx2x_init_block(bp, BLOCK_ATC, PHASE_COMMON);
  5806. /* let the HW do it's magic ... */
  5807. do {
  5808. msleep(200);
  5809. val = REG_RD(bp, ATC_REG_ATC_INIT_DONE);
  5810. } while (factor-- && (val != 1));
  5811. if (val != 1) {
  5812. BNX2X_ERR("ATC_INIT failed\n");
  5813. return -EBUSY;
  5814. }
  5815. }
  5816. bnx2x_init_block(bp, BLOCK_DMAE, PHASE_COMMON);
  5817. bnx2x_iov_init_dmae(bp);
  5818. /* clean the DMAE memory */
  5819. bp->dmae_ready = 1;
  5820. bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8, 1);
  5821. bnx2x_init_block(bp, BLOCK_TCM, PHASE_COMMON);
  5822. bnx2x_init_block(bp, BLOCK_UCM, PHASE_COMMON);
  5823. bnx2x_init_block(bp, BLOCK_CCM, PHASE_COMMON);
  5824. bnx2x_init_block(bp, BLOCK_XCM, PHASE_COMMON);
  5825. bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3);
  5826. bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3);
  5827. bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3);
  5828. bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3);
  5829. bnx2x_init_block(bp, BLOCK_QM, PHASE_COMMON);
  5830. /* QM queues pointers table */
  5831. bnx2x_qm_init_ptr_table(bp, bp->qm_cid_count, INITOP_SET);
  5832. /* soft reset pulse */
  5833. REG_WR(bp, QM_REG_SOFT_RESET, 1);
  5834. REG_WR(bp, QM_REG_SOFT_RESET, 0);
  5835. if (CNIC_SUPPORT(bp))
  5836. bnx2x_init_block(bp, BLOCK_TM, PHASE_COMMON);
  5837. bnx2x_init_block(bp, BLOCK_DORQ, PHASE_COMMON);
  5838. if (!CHIP_REV_IS_SLOW(bp))
  5839. /* enable hw interrupt from doorbell Q */
  5840. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  5841. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5842. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5843. REG_WR(bp, PRS_REG_A_PRSU_20, 0xf);
  5844. if (!CHIP_IS_E1(bp))
  5845. REG_WR(bp, PRS_REG_E1HOV_MODE, bp->path_has_ovlan);
  5846. if (!CHIP_IS_E1x(bp) && !CHIP_IS_E3B0(bp)) {
  5847. if (IS_MF_AFEX(bp)) {
  5848. /* configure that VNTag and VLAN headers must be
  5849. * received in afex mode
  5850. */
  5851. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC, 0xE);
  5852. REG_WR(bp, PRS_REG_MUST_HAVE_HDRS, 0xA);
  5853. REG_WR(bp, PRS_REG_HDRS_AFTER_TAG_0, 0x6);
  5854. REG_WR(bp, PRS_REG_TAG_ETHERTYPE_0, 0x8926);
  5855. REG_WR(bp, PRS_REG_TAG_LEN_0, 0x4);
  5856. } else {
  5857. /* Bit-map indicating which L2 hdrs may appear
  5858. * after the basic Ethernet header
  5859. */
  5860. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC,
  5861. bp->path_has_ovlan ? 7 : 6);
  5862. }
  5863. }
  5864. bnx2x_init_block(bp, BLOCK_TSDM, PHASE_COMMON);
  5865. bnx2x_init_block(bp, BLOCK_CSDM, PHASE_COMMON);
  5866. bnx2x_init_block(bp, BLOCK_USDM, PHASE_COMMON);
  5867. bnx2x_init_block(bp, BLOCK_XSDM, PHASE_COMMON);
  5868. if (!CHIP_IS_E1x(bp)) {
  5869. /* reset VFC memories */
  5870. REG_WR(bp, TSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  5871. VFC_MEMORIES_RST_REG_CAM_RST |
  5872. VFC_MEMORIES_RST_REG_RAM_RST);
  5873. REG_WR(bp, XSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  5874. VFC_MEMORIES_RST_REG_CAM_RST |
  5875. VFC_MEMORIES_RST_REG_RAM_RST);
  5876. msleep(20);
  5877. }
  5878. bnx2x_init_block(bp, BLOCK_TSEM, PHASE_COMMON);
  5879. bnx2x_init_block(bp, BLOCK_USEM, PHASE_COMMON);
  5880. bnx2x_init_block(bp, BLOCK_CSEM, PHASE_COMMON);
  5881. bnx2x_init_block(bp, BLOCK_XSEM, PHASE_COMMON);
  5882. /* sync semi rtc */
  5883. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  5884. 0x80000000);
  5885. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
  5886. 0x80000000);
  5887. bnx2x_init_block(bp, BLOCK_UPB, PHASE_COMMON);
  5888. bnx2x_init_block(bp, BLOCK_XPB, PHASE_COMMON);
  5889. bnx2x_init_block(bp, BLOCK_PBF, PHASE_COMMON);
  5890. if (!CHIP_IS_E1x(bp)) {
  5891. if (IS_MF_AFEX(bp)) {
  5892. /* configure that VNTag and VLAN headers must be
  5893. * sent in afex mode
  5894. */
  5895. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC, 0xE);
  5896. REG_WR(bp, PBF_REG_MUST_HAVE_HDRS, 0xA);
  5897. REG_WR(bp, PBF_REG_HDRS_AFTER_TAG_0, 0x6);
  5898. REG_WR(bp, PBF_REG_TAG_ETHERTYPE_0, 0x8926);
  5899. REG_WR(bp, PBF_REG_TAG_LEN_0, 0x4);
  5900. } else {
  5901. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC,
  5902. bp->path_has_ovlan ? 7 : 6);
  5903. }
  5904. }
  5905. REG_WR(bp, SRC_REG_SOFT_RST, 1);
  5906. bnx2x_init_block(bp, BLOCK_SRC, PHASE_COMMON);
  5907. if (CNIC_SUPPORT(bp)) {
  5908. REG_WR(bp, SRC_REG_KEYSEARCH_0, 0x63285672);
  5909. REG_WR(bp, SRC_REG_KEYSEARCH_1, 0x24b8f2cc);
  5910. REG_WR(bp, SRC_REG_KEYSEARCH_2, 0x223aef9b);
  5911. REG_WR(bp, SRC_REG_KEYSEARCH_3, 0x26001e3a);
  5912. REG_WR(bp, SRC_REG_KEYSEARCH_4, 0x7ae91116);
  5913. REG_WR(bp, SRC_REG_KEYSEARCH_5, 0x5ce5230b);
  5914. REG_WR(bp, SRC_REG_KEYSEARCH_6, 0x298d8adf);
  5915. REG_WR(bp, SRC_REG_KEYSEARCH_7, 0x6eb0ff09);
  5916. REG_WR(bp, SRC_REG_KEYSEARCH_8, 0x1830f82f);
  5917. REG_WR(bp, SRC_REG_KEYSEARCH_9, 0x01e46be7);
  5918. }
  5919. REG_WR(bp, SRC_REG_SOFT_RST, 0);
  5920. if (sizeof(union cdu_context) != 1024)
  5921. /* we currently assume that a context is 1024 bytes */
  5922. dev_alert(&bp->pdev->dev,
  5923. "please adjust the size of cdu_context(%ld)\n",
  5924. (long)sizeof(union cdu_context));
  5925. bnx2x_init_block(bp, BLOCK_CDU, PHASE_COMMON);
  5926. val = (4 << 24) + (0 << 12) + 1024;
  5927. REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val);
  5928. bnx2x_init_block(bp, BLOCK_CFC, PHASE_COMMON);
  5929. REG_WR(bp, CFC_REG_INIT_REG, 0x7FF);
  5930. /* enable context validation interrupt from CFC */
  5931. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  5932. /* set the thresholds to prevent CFC/CDU race */
  5933. REG_WR(bp, CFC_REG_DEBUG0, 0x20020000);
  5934. bnx2x_init_block(bp, BLOCK_HC, PHASE_COMMON);
  5935. if (!CHIP_IS_E1x(bp) && BP_NOMCP(bp))
  5936. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x36);
  5937. bnx2x_init_block(bp, BLOCK_IGU, PHASE_COMMON);
  5938. bnx2x_init_block(bp, BLOCK_MISC_AEU, PHASE_COMMON);
  5939. /* Reset PCIE errors for debug */
  5940. REG_WR(bp, 0x2814, 0xffffffff);
  5941. REG_WR(bp, 0x3820, 0xffffffff);
  5942. if (!CHIP_IS_E1x(bp)) {
  5943. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_CONTROL_5,
  5944. (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1 |
  5945. PXPCS_TL_CONTROL_5_ERR_UNSPPORT));
  5946. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC345_STAT,
  5947. (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4 |
  5948. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3 |
  5949. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2));
  5950. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC678_STAT,
  5951. (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7 |
  5952. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6 |
  5953. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5));
  5954. }
  5955. bnx2x_init_block(bp, BLOCK_NIG, PHASE_COMMON);
  5956. if (!CHIP_IS_E1(bp)) {
  5957. /* in E3 this done in per-port section */
  5958. if (!CHIP_IS_E3(bp))
  5959. REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_MF(bp));
  5960. }
  5961. if (CHIP_IS_E1H(bp))
  5962. /* not applicable for E2 (and above ...) */
  5963. REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_MF_SD(bp));
  5964. if (CHIP_REV_IS_SLOW(bp))
  5965. msleep(200);
  5966. /* finish CFC init */
  5967. val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10);
  5968. if (val != 1) {
  5969. BNX2X_ERR("CFC LL_INIT failed\n");
  5970. return -EBUSY;
  5971. }
  5972. val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10);
  5973. if (val != 1) {
  5974. BNX2X_ERR("CFC AC_INIT failed\n");
  5975. return -EBUSY;
  5976. }
  5977. val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10);
  5978. if (val != 1) {
  5979. BNX2X_ERR("CFC CAM_INIT failed\n");
  5980. return -EBUSY;
  5981. }
  5982. REG_WR(bp, CFC_REG_DEBUG0, 0);
  5983. if (CHIP_IS_E1(bp)) {
  5984. /* read NIG statistic
  5985. to see if this is our first up since powerup */
  5986. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5987. val = *bnx2x_sp(bp, wb_data[0]);
  5988. /* do internal memory self test */
  5989. if ((val == 0) && bnx2x_int_mem_test(bp)) {
  5990. BNX2X_ERR("internal mem self test failed\n");
  5991. return -EBUSY;
  5992. }
  5993. }
  5994. bnx2x_setup_fan_failure_detection(bp);
  5995. /* clear PXP2 attentions */
  5996. REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0);
  5997. bnx2x_enable_blocks_attention(bp);
  5998. bnx2x_enable_blocks_parity(bp);
  5999. if (!BP_NOMCP(bp)) {
  6000. if (CHIP_IS_E1x(bp))
  6001. bnx2x__common_init_phy(bp);
  6002. } else
  6003. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  6004. return 0;
  6005. }
  6006. /**
  6007. * bnx2x_init_hw_common_chip - init HW at the COMMON_CHIP phase.
  6008. *
  6009. * @bp: driver handle
  6010. */
  6011. static int bnx2x_init_hw_common_chip(struct bnx2x *bp)
  6012. {
  6013. int rc = bnx2x_init_hw_common(bp);
  6014. if (rc)
  6015. return rc;
  6016. /* In E2 2-PORT mode, same ext phy is used for the two paths */
  6017. if (!BP_NOMCP(bp))
  6018. bnx2x__common_init_phy(bp);
  6019. return 0;
  6020. }
  6021. static int bnx2x_init_hw_port(struct bnx2x *bp)
  6022. {
  6023. int port = BP_PORT(bp);
  6024. int init_phase = port ? PHASE_PORT1 : PHASE_PORT0;
  6025. u32 low, high;
  6026. u32 val, reg;
  6027. DP(NETIF_MSG_HW, "starting port init port %d\n", port);
  6028. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  6029. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  6030. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  6031. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  6032. /* Timers bug workaround: disables the pf_master bit in pglue at
  6033. * common phase, we need to enable it here before any dmae access are
  6034. * attempted. Therefore we manually added the enable-master to the
  6035. * port phase (it also happens in the function phase)
  6036. */
  6037. if (!CHIP_IS_E1x(bp))
  6038. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  6039. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  6040. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  6041. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  6042. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  6043. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  6044. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  6045. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  6046. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  6047. /* QM cid (connection) count */
  6048. bnx2x_qm_init_cid_count(bp, bp->qm_cid_count, INITOP_SET);
  6049. if (CNIC_SUPPORT(bp)) {
  6050. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  6051. REG_WR(bp, TM_REG_LIN0_SCAN_TIME + port*4, 20);
  6052. REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31);
  6053. }
  6054. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  6055. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  6056. if (CHIP_IS_E1(bp) || CHIP_IS_E1H(bp)) {
  6057. if (IS_MF(bp))
  6058. low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246);
  6059. else if (bp->dev->mtu > 4096) {
  6060. if (bp->flags & ONE_PORT_FLAG)
  6061. low = 160;
  6062. else {
  6063. val = bp->dev->mtu;
  6064. /* (24*1024 + val*4)/256 */
  6065. low = 96 + (val/64) +
  6066. ((val % 64) ? 1 : 0);
  6067. }
  6068. } else
  6069. low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160);
  6070. high = low + 56; /* 14*1024/256 */
  6071. REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low);
  6072. REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high);
  6073. }
  6074. if (CHIP_MODE_IS_4_PORT(bp))
  6075. REG_WR(bp, (BP_PORT(bp) ?
  6076. BRB1_REG_MAC_GUARANTIED_1 :
  6077. BRB1_REG_MAC_GUARANTIED_0), 40);
  6078. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  6079. if (CHIP_IS_E3B0(bp)) {
  6080. if (IS_MF_AFEX(bp)) {
  6081. /* configure headers for AFEX mode */
  6082. REG_WR(bp, BP_PORT(bp) ?
  6083. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  6084. PRS_REG_HDRS_AFTER_BASIC_PORT_0, 0xE);
  6085. REG_WR(bp, BP_PORT(bp) ?
  6086. PRS_REG_HDRS_AFTER_TAG_0_PORT_1 :
  6087. PRS_REG_HDRS_AFTER_TAG_0_PORT_0, 0x6);
  6088. REG_WR(bp, BP_PORT(bp) ?
  6089. PRS_REG_MUST_HAVE_HDRS_PORT_1 :
  6090. PRS_REG_MUST_HAVE_HDRS_PORT_0, 0xA);
  6091. } else {
  6092. /* Ovlan exists only if we are in multi-function +
  6093. * switch-dependent mode, in switch-independent there
  6094. * is no ovlan headers
  6095. */
  6096. REG_WR(bp, BP_PORT(bp) ?
  6097. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  6098. PRS_REG_HDRS_AFTER_BASIC_PORT_0,
  6099. (bp->path_has_ovlan ? 7 : 6));
  6100. }
  6101. }
  6102. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  6103. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  6104. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  6105. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  6106. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  6107. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  6108. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  6109. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  6110. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  6111. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  6112. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  6113. if (CHIP_IS_E1x(bp)) {
  6114. /* configure PBF to work without PAUSE mtu 9000 */
  6115. REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
  6116. /* update threshold */
  6117. REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16));
  6118. /* update init credit */
  6119. REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22);
  6120. /* probe changes */
  6121. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1);
  6122. udelay(50);
  6123. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0);
  6124. }
  6125. if (CNIC_SUPPORT(bp))
  6126. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  6127. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  6128. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  6129. if (CHIP_IS_E1(bp)) {
  6130. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  6131. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  6132. }
  6133. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  6134. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  6135. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  6136. /* init aeu_mask_attn_func_0/1:
  6137. * - SF mode: bits 3-7 are masked. Only bits 0-2 are in use
  6138. * - MF mode: bit 3 is masked. Bits 0-2 are in use as in SF
  6139. * bits 4-7 are used for "per vn group attention" */
  6140. val = IS_MF(bp) ? 0xF7 : 0x7;
  6141. /* Enable DCBX attention for all but E1 */
  6142. val |= CHIP_IS_E1(bp) ? 0 : 0x10;
  6143. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, val);
  6144. /* SCPAD_PARITY should NOT trigger close the gates */
  6145. reg = port ? MISC_REG_AEU_ENABLE4_NIG_1 : MISC_REG_AEU_ENABLE4_NIG_0;
  6146. REG_WR(bp, reg,
  6147. REG_RD(bp, reg) &
  6148. ~AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY);
  6149. reg = port ? MISC_REG_AEU_ENABLE4_PXP_1 : MISC_REG_AEU_ENABLE4_PXP_0;
  6150. REG_WR(bp, reg,
  6151. REG_RD(bp, reg) &
  6152. ~AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY);
  6153. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  6154. if (!CHIP_IS_E1x(bp)) {
  6155. /* Bit-map indicating which L2 hdrs may appear after the
  6156. * basic Ethernet header
  6157. */
  6158. if (IS_MF_AFEX(bp))
  6159. REG_WR(bp, BP_PORT(bp) ?
  6160. NIG_REG_P1_HDRS_AFTER_BASIC :
  6161. NIG_REG_P0_HDRS_AFTER_BASIC, 0xE);
  6162. else
  6163. REG_WR(bp, BP_PORT(bp) ?
  6164. NIG_REG_P1_HDRS_AFTER_BASIC :
  6165. NIG_REG_P0_HDRS_AFTER_BASIC,
  6166. IS_MF_SD(bp) ? 7 : 6);
  6167. if (CHIP_IS_E3(bp))
  6168. REG_WR(bp, BP_PORT(bp) ?
  6169. NIG_REG_LLH1_MF_MODE :
  6170. NIG_REG_LLH_MF_MODE, IS_MF(bp));
  6171. }
  6172. if (!CHIP_IS_E3(bp))
  6173. REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
  6174. if (!CHIP_IS_E1(bp)) {
  6175. /* 0x2 disable mf_ov, 0x1 enable */
  6176. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4,
  6177. (IS_MF_SD(bp) ? 0x1 : 0x2));
  6178. if (!CHIP_IS_E1x(bp)) {
  6179. val = 0;
  6180. switch (bp->mf_mode) {
  6181. case MULTI_FUNCTION_SD:
  6182. val = 1;
  6183. break;
  6184. case MULTI_FUNCTION_SI:
  6185. case MULTI_FUNCTION_AFEX:
  6186. val = 2;
  6187. break;
  6188. }
  6189. REG_WR(bp, (BP_PORT(bp) ? NIG_REG_LLH1_CLS_TYPE :
  6190. NIG_REG_LLH0_CLS_TYPE), val);
  6191. }
  6192. {
  6193. REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0);
  6194. REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0);
  6195. REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1);
  6196. }
  6197. }
  6198. /* If SPIO5 is set to generate interrupts, enable it for this port */
  6199. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  6200. if (val & MISC_SPIO_SPIO5) {
  6201. u32 reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  6202. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  6203. val = REG_RD(bp, reg_addr);
  6204. val |= AEU_INPUTS_ATTN_BITS_SPIO5;
  6205. REG_WR(bp, reg_addr, val);
  6206. }
  6207. return 0;
  6208. }
  6209. static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr)
  6210. {
  6211. int reg;
  6212. u32 wb_write[2];
  6213. if (CHIP_IS_E1(bp))
  6214. reg = PXP2_REG_RQ_ONCHIP_AT + index*8;
  6215. else
  6216. reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8;
  6217. wb_write[0] = ONCHIP_ADDR1(addr);
  6218. wb_write[1] = ONCHIP_ADDR2(addr);
  6219. REG_WR_DMAE(bp, reg, wb_write, 2);
  6220. }
  6221. void bnx2x_igu_clear_sb_gen(struct bnx2x *bp, u8 func, u8 idu_sb_id, bool is_pf)
  6222. {
  6223. u32 data, ctl, cnt = 100;
  6224. u32 igu_addr_data = IGU_REG_COMMAND_REG_32LSB_DATA;
  6225. u32 igu_addr_ctl = IGU_REG_COMMAND_REG_CTRL;
  6226. u32 igu_addr_ack = IGU_REG_CSTORM_TYPE_0_SB_CLEANUP + (idu_sb_id/32)*4;
  6227. u32 sb_bit = 1 << (idu_sb_id%32);
  6228. u32 func_encode = func | (is_pf ? 1 : 0) << IGU_FID_ENCODE_IS_PF_SHIFT;
  6229. u32 addr_encode = IGU_CMD_E2_PROD_UPD_BASE + idu_sb_id;
  6230. /* Not supported in BC mode */
  6231. if (CHIP_INT_MODE_IS_BC(bp))
  6232. return;
  6233. data = (IGU_USE_REGISTER_cstorm_type_0_sb_cleanup
  6234. << IGU_REGULAR_CLEANUP_TYPE_SHIFT) |
  6235. IGU_REGULAR_CLEANUP_SET |
  6236. IGU_REGULAR_BCLEANUP;
  6237. ctl = addr_encode << IGU_CTRL_REG_ADDRESS_SHIFT |
  6238. func_encode << IGU_CTRL_REG_FID_SHIFT |
  6239. IGU_CTRL_CMD_TYPE_WR << IGU_CTRL_REG_TYPE_SHIFT;
  6240. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  6241. data, igu_addr_data);
  6242. REG_WR(bp, igu_addr_data, data);
  6243. mmiowb();
  6244. barrier();
  6245. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  6246. ctl, igu_addr_ctl);
  6247. REG_WR(bp, igu_addr_ctl, ctl);
  6248. mmiowb();
  6249. barrier();
  6250. /* wait for clean up to finish */
  6251. while (!(REG_RD(bp, igu_addr_ack) & sb_bit) && --cnt)
  6252. msleep(20);
  6253. if (!(REG_RD(bp, igu_addr_ack) & sb_bit)) {
  6254. DP(NETIF_MSG_HW,
  6255. "Unable to finish IGU cleanup: idu_sb_id %d offset %d bit %d (cnt %d)\n",
  6256. idu_sb_id, idu_sb_id/32, idu_sb_id%32, cnt);
  6257. }
  6258. }
  6259. static void bnx2x_igu_clear_sb(struct bnx2x *bp, u8 idu_sb_id)
  6260. {
  6261. bnx2x_igu_clear_sb_gen(bp, BP_FUNC(bp), idu_sb_id, true /*PF*/);
  6262. }
  6263. static void bnx2x_clear_func_ilt(struct bnx2x *bp, u32 func)
  6264. {
  6265. u32 i, base = FUNC_ILT_BASE(func);
  6266. for (i = base; i < base + ILT_PER_FUNC; i++)
  6267. bnx2x_ilt_wr(bp, i, 0);
  6268. }
  6269. static void bnx2x_init_searcher(struct bnx2x *bp)
  6270. {
  6271. int port = BP_PORT(bp);
  6272. bnx2x_src_init_t2(bp, bp->t2, bp->t2_mapping, SRC_CONN_NUM);
  6273. /* T1 hash bits value determines the T1 number of entries */
  6274. REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + port*4, SRC_HASH_BITS);
  6275. }
  6276. static inline int bnx2x_func_switch_update(struct bnx2x *bp, int suspend)
  6277. {
  6278. int rc;
  6279. struct bnx2x_func_state_params func_params = {NULL};
  6280. struct bnx2x_func_switch_update_params *switch_update_params =
  6281. &func_params.params.switch_update;
  6282. /* Prepare parameters for function state transitions */
  6283. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  6284. __set_bit(RAMROD_RETRY, &func_params.ramrod_flags);
  6285. func_params.f_obj = &bp->func_obj;
  6286. func_params.cmd = BNX2X_F_CMD_SWITCH_UPDATE;
  6287. /* Function parameters */
  6288. switch_update_params->suspend = suspend;
  6289. rc = bnx2x_func_state_change(bp, &func_params);
  6290. return rc;
  6291. }
  6292. static int bnx2x_reset_nic_mode(struct bnx2x *bp)
  6293. {
  6294. int rc, i, port = BP_PORT(bp);
  6295. int vlan_en = 0, mac_en[NUM_MACS];
  6296. /* Close input from network */
  6297. if (bp->mf_mode == SINGLE_FUNCTION) {
  6298. bnx2x_set_rx_filter(&bp->link_params, 0);
  6299. } else {
  6300. vlan_en = REG_RD(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6301. NIG_REG_LLH0_FUNC_EN);
  6302. REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6303. NIG_REG_LLH0_FUNC_EN, 0);
  6304. for (i = 0; i < NUM_MACS; i++) {
  6305. mac_en[i] = REG_RD(bp, port ?
  6306. (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6307. 4 * i) :
  6308. (NIG_REG_LLH0_FUNC_MEM_ENABLE +
  6309. 4 * i));
  6310. REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6311. 4 * i) :
  6312. (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i), 0);
  6313. }
  6314. }
  6315. /* Close BMC to host */
  6316. REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
  6317. NIG_REG_P1_TX_MNG_HOST_ENABLE, 0);
  6318. /* Suspend Tx switching to the PF. Completion of this ramrod
  6319. * further guarantees that all the packets of that PF / child
  6320. * VFs in BRB were processed by the Parser, so it is safe to
  6321. * change the NIC_MODE register.
  6322. */
  6323. rc = bnx2x_func_switch_update(bp, 1);
  6324. if (rc) {
  6325. BNX2X_ERR("Can't suspend tx-switching!\n");
  6326. return rc;
  6327. }
  6328. /* Change NIC_MODE register */
  6329. REG_WR(bp, PRS_REG_NIC_MODE, 0);
  6330. /* Open input from network */
  6331. if (bp->mf_mode == SINGLE_FUNCTION) {
  6332. bnx2x_set_rx_filter(&bp->link_params, 1);
  6333. } else {
  6334. REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6335. NIG_REG_LLH0_FUNC_EN, vlan_en);
  6336. for (i = 0; i < NUM_MACS; i++) {
  6337. REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6338. 4 * i) :
  6339. (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i),
  6340. mac_en[i]);
  6341. }
  6342. }
  6343. /* Enable BMC to host */
  6344. REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
  6345. NIG_REG_P1_TX_MNG_HOST_ENABLE, 1);
  6346. /* Resume Tx switching to the PF */
  6347. rc = bnx2x_func_switch_update(bp, 0);
  6348. if (rc) {
  6349. BNX2X_ERR("Can't resume tx-switching!\n");
  6350. return rc;
  6351. }
  6352. DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
  6353. return 0;
  6354. }
  6355. int bnx2x_init_hw_func_cnic(struct bnx2x *bp)
  6356. {
  6357. int rc;
  6358. bnx2x_ilt_init_op_cnic(bp, INITOP_SET);
  6359. if (CONFIGURE_NIC_MODE(bp)) {
  6360. /* Configure searcher as part of function hw init */
  6361. bnx2x_init_searcher(bp);
  6362. /* Reset NIC mode */
  6363. rc = bnx2x_reset_nic_mode(bp);
  6364. if (rc)
  6365. BNX2X_ERR("Can't change NIC mode!\n");
  6366. return rc;
  6367. }
  6368. return 0;
  6369. }
  6370. static int bnx2x_init_hw_func(struct bnx2x *bp)
  6371. {
  6372. int port = BP_PORT(bp);
  6373. int func = BP_FUNC(bp);
  6374. int init_phase = PHASE_PF0 + func;
  6375. struct bnx2x_ilt *ilt = BP_ILT(bp);
  6376. u16 cdu_ilt_start;
  6377. u32 addr, val;
  6378. u32 main_mem_base, main_mem_size, main_mem_prty_clr;
  6379. int i, main_mem_width, rc;
  6380. DP(NETIF_MSG_HW, "starting func init func %d\n", func);
  6381. /* FLR cleanup - hmmm */
  6382. if (!CHIP_IS_E1x(bp)) {
  6383. rc = bnx2x_pf_flr_clnup(bp);
  6384. if (rc) {
  6385. bnx2x_fw_dump(bp);
  6386. return rc;
  6387. }
  6388. }
  6389. /* set MSI reconfigure capability */
  6390. if (bp->common.int_block == INT_BLOCK_HC) {
  6391. addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0);
  6392. val = REG_RD(bp, addr);
  6393. val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0;
  6394. REG_WR(bp, addr, val);
  6395. }
  6396. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  6397. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  6398. ilt = BP_ILT(bp);
  6399. cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
  6400. if (IS_SRIOV(bp))
  6401. cdu_ilt_start += BNX2X_FIRST_VF_CID/ILT_PAGE_CIDS;
  6402. cdu_ilt_start = bnx2x_iov_init_ilt(bp, cdu_ilt_start);
  6403. /* since BNX2X_FIRST_VF_CID > 0 the PF L2 cids precedes
  6404. * those of the VFs, so start line should be reset
  6405. */
  6406. cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
  6407. for (i = 0; i < L2_ILT_LINES(bp); i++) {
  6408. ilt->lines[cdu_ilt_start + i].page = bp->context[i].vcxt;
  6409. ilt->lines[cdu_ilt_start + i].page_mapping =
  6410. bp->context[i].cxt_mapping;
  6411. ilt->lines[cdu_ilt_start + i].size = bp->context[i].size;
  6412. }
  6413. bnx2x_ilt_init_op(bp, INITOP_SET);
  6414. if (!CONFIGURE_NIC_MODE(bp)) {
  6415. bnx2x_init_searcher(bp);
  6416. REG_WR(bp, PRS_REG_NIC_MODE, 0);
  6417. DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
  6418. } else {
  6419. /* Set NIC mode */
  6420. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  6421. DP(NETIF_MSG_IFUP, "NIC MODE configured\n");
  6422. }
  6423. if (!CHIP_IS_E1x(bp)) {
  6424. u32 pf_conf = IGU_PF_CONF_FUNC_EN;
  6425. /* Turn on a single ISR mode in IGU if driver is going to use
  6426. * INT#x or MSI
  6427. */
  6428. if (!(bp->flags & USING_MSIX_FLAG))
  6429. pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN;
  6430. /*
  6431. * Timers workaround bug: function init part.
  6432. * Need to wait 20msec after initializing ILT,
  6433. * needed to make sure there are no requests in
  6434. * one of the PXP internal queues with "old" ILT addresses
  6435. */
  6436. msleep(20);
  6437. /*
  6438. * Master enable - Due to WB DMAE writes performed before this
  6439. * register is re-initialized as part of the regular function
  6440. * init
  6441. */
  6442. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  6443. /* Enable the function in IGU */
  6444. REG_WR(bp, IGU_REG_PF_CONFIGURATION, pf_conf);
  6445. }
  6446. bp->dmae_ready = 1;
  6447. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  6448. if (!CHIP_IS_E1x(bp))
  6449. REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, func);
  6450. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  6451. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  6452. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  6453. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  6454. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  6455. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  6456. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  6457. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  6458. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  6459. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  6460. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  6461. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  6462. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  6463. if (!CHIP_IS_E1x(bp))
  6464. REG_WR(bp, QM_REG_PF_EN, 1);
  6465. if (!CHIP_IS_E1x(bp)) {
  6466. REG_WR(bp, TSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6467. REG_WR(bp, USEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6468. REG_WR(bp, CSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6469. REG_WR(bp, XSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6470. }
  6471. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  6472. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  6473. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  6474. REG_WR(bp, DORQ_REG_MODE_ACT, 1); /* no dpm */
  6475. bnx2x_iov_init_dq(bp);
  6476. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  6477. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  6478. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  6479. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  6480. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  6481. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  6482. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  6483. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  6484. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  6485. if (!CHIP_IS_E1x(bp))
  6486. REG_WR(bp, PBF_REG_DISABLE_PF, 0);
  6487. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  6488. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  6489. if (!CHIP_IS_E1x(bp))
  6490. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 1);
  6491. if (IS_MF(bp)) {
  6492. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
  6493. REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port*8, bp->mf_ov);
  6494. }
  6495. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  6496. /* HC init per function */
  6497. if (bp->common.int_block == INT_BLOCK_HC) {
  6498. if (CHIP_IS_E1H(bp)) {
  6499. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  6500. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  6501. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  6502. }
  6503. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  6504. } else {
  6505. int num_segs, sb_idx, prod_offset;
  6506. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  6507. if (!CHIP_IS_E1x(bp)) {
  6508. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  6509. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  6510. }
  6511. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  6512. if (!CHIP_IS_E1x(bp)) {
  6513. int dsb_idx = 0;
  6514. /**
  6515. * Producer memory:
  6516. * E2 mode: address 0-135 match to the mapping memory;
  6517. * 136 - PF0 default prod; 137 - PF1 default prod;
  6518. * 138 - PF2 default prod; 139 - PF3 default prod;
  6519. * 140 - PF0 attn prod; 141 - PF1 attn prod;
  6520. * 142 - PF2 attn prod; 143 - PF3 attn prod;
  6521. * 144-147 reserved.
  6522. *
  6523. * E1.5 mode - In backward compatible mode;
  6524. * for non default SB; each even line in the memory
  6525. * holds the U producer and each odd line hold
  6526. * the C producer. The first 128 producers are for
  6527. * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20
  6528. * producers are for the DSB for each PF.
  6529. * Each PF has five segments: (the order inside each
  6530. * segment is PF0; PF1; PF2; PF3) - 128-131 U prods;
  6531. * 132-135 C prods; 136-139 X prods; 140-143 T prods;
  6532. * 144-147 attn prods;
  6533. */
  6534. /* non-default-status-blocks */
  6535. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  6536. IGU_BC_NDSB_NUM_SEGS : IGU_NORM_NDSB_NUM_SEGS;
  6537. for (sb_idx = 0; sb_idx < bp->igu_sb_cnt; sb_idx++) {
  6538. prod_offset = (bp->igu_base_sb + sb_idx) *
  6539. num_segs;
  6540. for (i = 0; i < num_segs; i++) {
  6541. addr = IGU_REG_PROD_CONS_MEMORY +
  6542. (prod_offset + i) * 4;
  6543. REG_WR(bp, addr, 0);
  6544. }
  6545. /* send consumer update with value 0 */
  6546. bnx2x_ack_sb(bp, bp->igu_base_sb + sb_idx,
  6547. USTORM_ID, 0, IGU_INT_NOP, 1);
  6548. bnx2x_igu_clear_sb(bp,
  6549. bp->igu_base_sb + sb_idx);
  6550. }
  6551. /* default-status-blocks */
  6552. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  6553. IGU_BC_DSB_NUM_SEGS : IGU_NORM_DSB_NUM_SEGS;
  6554. if (CHIP_MODE_IS_4_PORT(bp))
  6555. dsb_idx = BP_FUNC(bp);
  6556. else
  6557. dsb_idx = BP_VN(bp);
  6558. prod_offset = (CHIP_INT_MODE_IS_BC(bp) ?
  6559. IGU_BC_BASE_DSB_PROD + dsb_idx :
  6560. IGU_NORM_BASE_DSB_PROD + dsb_idx);
  6561. /*
  6562. * igu prods come in chunks of E1HVN_MAX (4) -
  6563. * does not matters what is the current chip mode
  6564. */
  6565. for (i = 0; i < (num_segs * E1HVN_MAX);
  6566. i += E1HVN_MAX) {
  6567. addr = IGU_REG_PROD_CONS_MEMORY +
  6568. (prod_offset + i)*4;
  6569. REG_WR(bp, addr, 0);
  6570. }
  6571. /* send consumer update with 0 */
  6572. if (CHIP_INT_MODE_IS_BC(bp)) {
  6573. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6574. USTORM_ID, 0, IGU_INT_NOP, 1);
  6575. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6576. CSTORM_ID, 0, IGU_INT_NOP, 1);
  6577. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6578. XSTORM_ID, 0, IGU_INT_NOP, 1);
  6579. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6580. TSTORM_ID, 0, IGU_INT_NOP, 1);
  6581. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6582. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  6583. } else {
  6584. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6585. USTORM_ID, 0, IGU_INT_NOP, 1);
  6586. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6587. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  6588. }
  6589. bnx2x_igu_clear_sb(bp, bp->igu_dsb_id);
  6590. /* !!! These should become driver const once
  6591. rf-tool supports split-68 const */
  6592. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0);
  6593. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0);
  6594. REG_WR(bp, IGU_REG_SB_MASK_LSB, 0);
  6595. REG_WR(bp, IGU_REG_SB_MASK_MSB, 0);
  6596. REG_WR(bp, IGU_REG_PBA_STATUS_LSB, 0);
  6597. REG_WR(bp, IGU_REG_PBA_STATUS_MSB, 0);
  6598. }
  6599. }
  6600. /* Reset PCIE errors for debug */
  6601. REG_WR(bp, 0x2114, 0xffffffff);
  6602. REG_WR(bp, 0x2120, 0xffffffff);
  6603. if (CHIP_IS_E1x(bp)) {
  6604. main_mem_size = HC_REG_MAIN_MEMORY_SIZE / 2; /*dwords*/
  6605. main_mem_base = HC_REG_MAIN_MEMORY +
  6606. BP_PORT(bp) * (main_mem_size * 4);
  6607. main_mem_prty_clr = HC_REG_HC_PRTY_STS_CLR;
  6608. main_mem_width = 8;
  6609. val = REG_RD(bp, main_mem_prty_clr);
  6610. if (val)
  6611. DP(NETIF_MSG_HW,
  6612. "Hmmm... Parity errors in HC block during function init (0x%x)!\n",
  6613. val);
  6614. /* Clear "false" parity errors in MSI-X table */
  6615. for (i = main_mem_base;
  6616. i < main_mem_base + main_mem_size * 4;
  6617. i += main_mem_width) {
  6618. bnx2x_read_dmae(bp, i, main_mem_width / 4);
  6619. bnx2x_write_dmae(bp, bnx2x_sp_mapping(bp, wb_data),
  6620. i, main_mem_width / 4);
  6621. }
  6622. /* Clear HC parity attention */
  6623. REG_RD(bp, main_mem_prty_clr);
  6624. }
  6625. #ifdef BNX2X_STOP_ON_ERROR
  6626. /* Enable STORMs SP logging */
  6627. REG_WR8(bp, BAR_USTRORM_INTMEM +
  6628. USTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6629. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  6630. TSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6631. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6632. CSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6633. REG_WR8(bp, BAR_XSTRORM_INTMEM +
  6634. XSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6635. #endif
  6636. bnx2x_phy_probe(&bp->link_params);
  6637. return 0;
  6638. }
  6639. void bnx2x_free_mem_cnic(struct bnx2x *bp)
  6640. {
  6641. bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_FREE);
  6642. if (!CHIP_IS_E1x(bp))
  6643. BNX2X_PCI_FREE(bp->cnic_sb.e2_sb, bp->cnic_sb_mapping,
  6644. sizeof(struct host_hc_status_block_e2));
  6645. else
  6646. BNX2X_PCI_FREE(bp->cnic_sb.e1x_sb, bp->cnic_sb_mapping,
  6647. sizeof(struct host_hc_status_block_e1x));
  6648. BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
  6649. }
  6650. void bnx2x_free_mem(struct bnx2x *bp)
  6651. {
  6652. int i;
  6653. BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
  6654. bp->fw_stats_data_sz + bp->fw_stats_req_sz);
  6655. if (IS_VF(bp))
  6656. return;
  6657. BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping,
  6658. sizeof(struct host_sp_status_block));
  6659. BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping,
  6660. sizeof(struct bnx2x_slowpath));
  6661. for (i = 0; i < L2_ILT_LINES(bp); i++)
  6662. BNX2X_PCI_FREE(bp->context[i].vcxt, bp->context[i].cxt_mapping,
  6663. bp->context[i].size);
  6664. bnx2x_ilt_mem_op(bp, ILT_MEMOP_FREE);
  6665. BNX2X_FREE(bp->ilt->lines);
  6666. BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE);
  6667. BNX2X_PCI_FREE(bp->eq_ring, bp->eq_mapping,
  6668. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  6669. BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
  6670. bnx2x_iov_free_mem(bp);
  6671. }
  6672. int bnx2x_alloc_mem_cnic(struct bnx2x *bp)
  6673. {
  6674. if (!CHIP_IS_E1x(bp))
  6675. /* size = the status block + ramrod buffers */
  6676. BNX2X_PCI_ALLOC(bp->cnic_sb.e2_sb, &bp->cnic_sb_mapping,
  6677. sizeof(struct host_hc_status_block_e2));
  6678. else
  6679. BNX2X_PCI_ALLOC(bp->cnic_sb.e1x_sb,
  6680. &bp->cnic_sb_mapping,
  6681. sizeof(struct
  6682. host_hc_status_block_e1x));
  6683. if (CONFIGURE_NIC_MODE(bp) && !bp->t2)
  6684. /* allocate searcher T2 table, as it wasn't allocated before */
  6685. BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
  6686. /* write address to which L5 should insert its values */
  6687. bp->cnic_eth_dev.addr_drv_info_to_mcp =
  6688. &bp->slowpath->drv_info_to_mcp;
  6689. if (bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_ALLOC))
  6690. goto alloc_mem_err;
  6691. return 0;
  6692. alloc_mem_err:
  6693. bnx2x_free_mem_cnic(bp);
  6694. BNX2X_ERR("Can't allocate memory\n");
  6695. return -ENOMEM;
  6696. }
  6697. int bnx2x_alloc_mem(struct bnx2x *bp)
  6698. {
  6699. int i, allocated, context_size;
  6700. if (!CONFIGURE_NIC_MODE(bp) && !bp->t2)
  6701. /* allocate searcher T2 table */
  6702. BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
  6703. BNX2X_PCI_ALLOC(bp->def_status_blk, &bp->def_status_blk_mapping,
  6704. sizeof(struct host_sp_status_block));
  6705. BNX2X_PCI_ALLOC(bp->slowpath, &bp->slowpath_mapping,
  6706. sizeof(struct bnx2x_slowpath));
  6707. /* Allocate memory for CDU context:
  6708. * This memory is allocated separately and not in the generic ILT
  6709. * functions because CDU differs in few aspects:
  6710. * 1. There are multiple entities allocating memory for context -
  6711. * 'regular' driver, CNIC and SRIOV driver. Each separately controls
  6712. * its own ILT lines.
  6713. * 2. Since CDU page-size is not a single 4KB page (which is the case
  6714. * for the other ILT clients), to be efficient we want to support
  6715. * allocation of sub-page-size in the last entry.
  6716. * 3. Context pointers are used by the driver to pass to FW / update
  6717. * the context (for the other ILT clients the pointers are used just to
  6718. * free the memory during unload).
  6719. */
  6720. context_size = sizeof(union cdu_context) * BNX2X_L2_CID_COUNT(bp);
  6721. for (i = 0, allocated = 0; allocated < context_size; i++) {
  6722. bp->context[i].size = min(CDU_ILT_PAGE_SZ,
  6723. (context_size - allocated));
  6724. BNX2X_PCI_ALLOC(bp->context[i].vcxt,
  6725. &bp->context[i].cxt_mapping,
  6726. bp->context[i].size);
  6727. allocated += bp->context[i].size;
  6728. }
  6729. BNX2X_ALLOC(bp->ilt->lines, sizeof(struct ilt_line) * ILT_MAX_LINES);
  6730. if (bnx2x_ilt_mem_op(bp, ILT_MEMOP_ALLOC))
  6731. goto alloc_mem_err;
  6732. if (bnx2x_iov_alloc_mem(bp))
  6733. goto alloc_mem_err;
  6734. /* Slow path ring */
  6735. BNX2X_PCI_ALLOC(bp->spq, &bp->spq_mapping, BCM_PAGE_SIZE);
  6736. /* EQ */
  6737. BNX2X_PCI_ALLOC(bp->eq_ring, &bp->eq_mapping,
  6738. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  6739. return 0;
  6740. alloc_mem_err:
  6741. bnx2x_free_mem(bp);
  6742. BNX2X_ERR("Can't allocate memory\n");
  6743. return -ENOMEM;
  6744. }
  6745. /*
  6746. * Init service functions
  6747. */
  6748. int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac,
  6749. struct bnx2x_vlan_mac_obj *obj, bool set,
  6750. int mac_type, unsigned long *ramrod_flags)
  6751. {
  6752. int rc;
  6753. struct bnx2x_vlan_mac_ramrod_params ramrod_param;
  6754. memset(&ramrod_param, 0, sizeof(ramrod_param));
  6755. /* Fill general parameters */
  6756. ramrod_param.vlan_mac_obj = obj;
  6757. ramrod_param.ramrod_flags = *ramrod_flags;
  6758. /* Fill a user request section if needed */
  6759. if (!test_bit(RAMROD_CONT, ramrod_flags)) {
  6760. memcpy(ramrod_param.user_req.u.mac.mac, mac, ETH_ALEN);
  6761. __set_bit(mac_type, &ramrod_param.user_req.vlan_mac_flags);
  6762. /* Set the command: ADD or DEL */
  6763. if (set)
  6764. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD;
  6765. else
  6766. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_DEL;
  6767. }
  6768. rc = bnx2x_config_vlan_mac(bp, &ramrod_param);
  6769. if (rc == -EEXIST) {
  6770. DP(BNX2X_MSG_SP, "Failed to schedule ADD operations: %d\n", rc);
  6771. /* do not treat adding same MAC as error */
  6772. rc = 0;
  6773. } else if (rc < 0)
  6774. BNX2X_ERR("%s MAC failed\n", (set ? "Set" : "Del"));
  6775. return rc;
  6776. }
  6777. int bnx2x_del_all_macs(struct bnx2x *bp,
  6778. struct bnx2x_vlan_mac_obj *mac_obj,
  6779. int mac_type, bool wait_for_comp)
  6780. {
  6781. int rc;
  6782. unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
  6783. /* Wait for completion of requested */
  6784. if (wait_for_comp)
  6785. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  6786. /* Set the mac type of addresses we want to clear */
  6787. __set_bit(mac_type, &vlan_mac_flags);
  6788. rc = mac_obj->delete_all(bp, mac_obj, &vlan_mac_flags, &ramrod_flags);
  6789. if (rc < 0)
  6790. BNX2X_ERR("Failed to delete MACs: %d\n", rc);
  6791. return rc;
  6792. }
  6793. int bnx2x_set_eth_mac(struct bnx2x *bp, bool set)
  6794. {
  6795. if (is_zero_ether_addr(bp->dev->dev_addr) &&
  6796. (IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp))) {
  6797. DP(NETIF_MSG_IFUP | NETIF_MSG_IFDOWN,
  6798. "Ignoring Zero MAC for STORAGE SD mode\n");
  6799. return 0;
  6800. }
  6801. if (IS_PF(bp)) {
  6802. unsigned long ramrod_flags = 0;
  6803. DP(NETIF_MSG_IFUP, "Adding Eth MAC\n");
  6804. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  6805. return bnx2x_set_mac_one(bp, bp->dev->dev_addr,
  6806. &bp->sp_objs->mac_obj, set,
  6807. BNX2X_ETH_MAC, &ramrod_flags);
  6808. } else { /* vf */
  6809. return bnx2x_vfpf_config_mac(bp, bp->dev->dev_addr,
  6810. bp->fp->index, true);
  6811. }
  6812. }
  6813. int bnx2x_setup_leading(struct bnx2x *bp)
  6814. {
  6815. if (IS_PF(bp))
  6816. return bnx2x_setup_queue(bp, &bp->fp[0], true);
  6817. else /* VF */
  6818. return bnx2x_vfpf_setup_q(bp, &bp->fp[0], true);
  6819. }
  6820. /**
  6821. * bnx2x_set_int_mode - configure interrupt mode
  6822. *
  6823. * @bp: driver handle
  6824. *
  6825. * In case of MSI-X it will also try to enable MSI-X.
  6826. */
  6827. int bnx2x_set_int_mode(struct bnx2x *bp)
  6828. {
  6829. int rc = 0;
  6830. if (IS_VF(bp) && int_mode != BNX2X_INT_MODE_MSIX) {
  6831. BNX2X_ERR("VF not loaded since interrupt mode not msix\n");
  6832. return -EINVAL;
  6833. }
  6834. switch (int_mode) {
  6835. case BNX2X_INT_MODE_MSIX:
  6836. /* attempt to enable msix */
  6837. rc = bnx2x_enable_msix(bp);
  6838. /* msix attained */
  6839. if (!rc)
  6840. return 0;
  6841. /* vfs use only msix */
  6842. if (rc && IS_VF(bp))
  6843. return rc;
  6844. /* failed to enable multiple MSI-X */
  6845. BNX2X_DEV_INFO("Failed to enable multiple MSI-X (%d), set number of queues to %d\n",
  6846. bp->num_queues,
  6847. 1 + bp->num_cnic_queues);
  6848. /* falling through... */
  6849. case BNX2X_INT_MODE_MSI:
  6850. bnx2x_enable_msi(bp);
  6851. /* falling through... */
  6852. case BNX2X_INT_MODE_INTX:
  6853. bp->num_ethernet_queues = 1;
  6854. bp->num_queues = bp->num_ethernet_queues + bp->num_cnic_queues;
  6855. BNX2X_DEV_INFO("set number of queues to 1\n");
  6856. break;
  6857. default:
  6858. BNX2X_DEV_INFO("unknown value in int_mode module parameter\n");
  6859. return -EINVAL;
  6860. }
  6861. return 0;
  6862. }
  6863. /* must be called prior to any HW initializations */
  6864. static inline u16 bnx2x_cid_ilt_lines(struct bnx2x *bp)
  6865. {
  6866. if (IS_SRIOV(bp))
  6867. return (BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)/ILT_PAGE_CIDS;
  6868. return L2_ILT_LINES(bp);
  6869. }
  6870. void bnx2x_ilt_set_info(struct bnx2x *bp)
  6871. {
  6872. struct ilt_client_info *ilt_client;
  6873. struct bnx2x_ilt *ilt = BP_ILT(bp);
  6874. u16 line = 0;
  6875. ilt->start_line = FUNC_ILT_BASE(BP_FUNC(bp));
  6876. DP(BNX2X_MSG_SP, "ilt starts at line %d\n", ilt->start_line);
  6877. /* CDU */
  6878. ilt_client = &ilt->clients[ILT_CLIENT_CDU];
  6879. ilt_client->client_num = ILT_CLIENT_CDU;
  6880. ilt_client->page_size = CDU_ILT_PAGE_SZ;
  6881. ilt_client->flags = ILT_CLIENT_SKIP_MEM;
  6882. ilt_client->start = line;
  6883. line += bnx2x_cid_ilt_lines(bp);
  6884. if (CNIC_SUPPORT(bp))
  6885. line += CNIC_ILT_LINES;
  6886. ilt_client->end = line - 1;
  6887. DP(NETIF_MSG_IFUP, "ilt client[CDU]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6888. ilt_client->start,
  6889. ilt_client->end,
  6890. ilt_client->page_size,
  6891. ilt_client->flags,
  6892. ilog2(ilt_client->page_size >> 12));
  6893. /* QM */
  6894. if (QM_INIT(bp->qm_cid_count)) {
  6895. ilt_client = &ilt->clients[ILT_CLIENT_QM];
  6896. ilt_client->client_num = ILT_CLIENT_QM;
  6897. ilt_client->page_size = QM_ILT_PAGE_SZ;
  6898. ilt_client->flags = 0;
  6899. ilt_client->start = line;
  6900. /* 4 bytes for each cid */
  6901. line += DIV_ROUND_UP(bp->qm_cid_count * QM_QUEUES_PER_FUNC * 4,
  6902. QM_ILT_PAGE_SZ);
  6903. ilt_client->end = line - 1;
  6904. DP(NETIF_MSG_IFUP,
  6905. "ilt client[QM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6906. ilt_client->start,
  6907. ilt_client->end,
  6908. ilt_client->page_size,
  6909. ilt_client->flags,
  6910. ilog2(ilt_client->page_size >> 12));
  6911. }
  6912. if (CNIC_SUPPORT(bp)) {
  6913. /* SRC */
  6914. ilt_client = &ilt->clients[ILT_CLIENT_SRC];
  6915. ilt_client->client_num = ILT_CLIENT_SRC;
  6916. ilt_client->page_size = SRC_ILT_PAGE_SZ;
  6917. ilt_client->flags = 0;
  6918. ilt_client->start = line;
  6919. line += SRC_ILT_LINES;
  6920. ilt_client->end = line - 1;
  6921. DP(NETIF_MSG_IFUP,
  6922. "ilt client[SRC]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6923. ilt_client->start,
  6924. ilt_client->end,
  6925. ilt_client->page_size,
  6926. ilt_client->flags,
  6927. ilog2(ilt_client->page_size >> 12));
  6928. /* TM */
  6929. ilt_client = &ilt->clients[ILT_CLIENT_TM];
  6930. ilt_client->client_num = ILT_CLIENT_TM;
  6931. ilt_client->page_size = TM_ILT_PAGE_SZ;
  6932. ilt_client->flags = 0;
  6933. ilt_client->start = line;
  6934. line += TM_ILT_LINES;
  6935. ilt_client->end = line - 1;
  6936. DP(NETIF_MSG_IFUP,
  6937. "ilt client[TM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6938. ilt_client->start,
  6939. ilt_client->end,
  6940. ilt_client->page_size,
  6941. ilt_client->flags,
  6942. ilog2(ilt_client->page_size >> 12));
  6943. }
  6944. BUG_ON(line > ILT_MAX_LINES);
  6945. }
  6946. /**
  6947. * bnx2x_pf_q_prep_init - prepare INIT transition parameters
  6948. *
  6949. * @bp: driver handle
  6950. * @fp: pointer to fastpath
  6951. * @init_params: pointer to parameters structure
  6952. *
  6953. * parameters configured:
  6954. * - HC configuration
  6955. * - Queue's CDU context
  6956. */
  6957. static void bnx2x_pf_q_prep_init(struct bnx2x *bp,
  6958. struct bnx2x_fastpath *fp, struct bnx2x_queue_init_params *init_params)
  6959. {
  6960. u8 cos;
  6961. int cxt_index, cxt_offset;
  6962. /* FCoE Queue uses Default SB, thus has no HC capabilities */
  6963. if (!IS_FCOE_FP(fp)) {
  6964. __set_bit(BNX2X_Q_FLG_HC, &init_params->rx.flags);
  6965. __set_bit(BNX2X_Q_FLG_HC, &init_params->tx.flags);
  6966. /* If HC is supported, enable host coalescing in the transition
  6967. * to INIT state.
  6968. */
  6969. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->rx.flags);
  6970. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->tx.flags);
  6971. /* HC rate */
  6972. init_params->rx.hc_rate = bp->rx_ticks ?
  6973. (1000000 / bp->rx_ticks) : 0;
  6974. init_params->tx.hc_rate = bp->tx_ticks ?
  6975. (1000000 / bp->tx_ticks) : 0;
  6976. /* FW SB ID */
  6977. init_params->rx.fw_sb_id = init_params->tx.fw_sb_id =
  6978. fp->fw_sb_id;
  6979. /*
  6980. * CQ index among the SB indices: FCoE clients uses the default
  6981. * SB, therefore it's different.
  6982. */
  6983. init_params->rx.sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  6984. init_params->tx.sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS;
  6985. }
  6986. /* set maximum number of COSs supported by this queue */
  6987. init_params->max_cos = fp->max_cos;
  6988. DP(NETIF_MSG_IFUP, "fp: %d setting queue params max cos to: %d\n",
  6989. fp->index, init_params->max_cos);
  6990. /* set the context pointers queue object */
  6991. for (cos = FIRST_TX_COS_INDEX; cos < init_params->max_cos; cos++) {
  6992. cxt_index = fp->txdata_ptr[cos]->cid / ILT_PAGE_CIDS;
  6993. cxt_offset = fp->txdata_ptr[cos]->cid - (cxt_index *
  6994. ILT_PAGE_CIDS);
  6995. init_params->cxts[cos] =
  6996. &bp->context[cxt_index].vcxt[cxt_offset].eth;
  6997. }
  6998. }
  6999. static int bnx2x_setup_tx_only(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  7000. struct bnx2x_queue_state_params *q_params,
  7001. struct bnx2x_queue_setup_tx_only_params *tx_only_params,
  7002. int tx_index, bool leading)
  7003. {
  7004. memset(tx_only_params, 0, sizeof(*tx_only_params));
  7005. /* Set the command */
  7006. q_params->cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  7007. /* Set tx-only QUEUE flags: don't zero statistics */
  7008. tx_only_params->flags = bnx2x_get_common_flags(bp, fp, false);
  7009. /* choose the index of the cid to send the slow path on */
  7010. tx_only_params->cid_index = tx_index;
  7011. /* Set general TX_ONLY_SETUP parameters */
  7012. bnx2x_pf_q_prep_general(bp, fp, &tx_only_params->gen_params, tx_index);
  7013. /* Set Tx TX_ONLY_SETUP parameters */
  7014. bnx2x_pf_tx_q_prep(bp, fp, &tx_only_params->txq_params, tx_index);
  7015. DP(NETIF_MSG_IFUP,
  7016. "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",
  7017. tx_index, q_params->q_obj->cids[FIRST_TX_COS_INDEX],
  7018. q_params->q_obj->cids[tx_index], q_params->q_obj->cl_id,
  7019. tx_only_params->gen_params.spcl_id, tx_only_params->flags);
  7020. /* send the ramrod */
  7021. return bnx2x_queue_state_change(bp, q_params);
  7022. }
  7023. /**
  7024. * bnx2x_setup_queue - setup queue
  7025. *
  7026. * @bp: driver handle
  7027. * @fp: pointer to fastpath
  7028. * @leading: is leading
  7029. *
  7030. * This function performs 2 steps in a Queue state machine
  7031. * actually: 1) RESET->INIT 2) INIT->SETUP
  7032. */
  7033. int bnx2x_setup_queue(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  7034. bool leading)
  7035. {
  7036. struct bnx2x_queue_state_params q_params = {NULL};
  7037. struct bnx2x_queue_setup_params *setup_params =
  7038. &q_params.params.setup;
  7039. struct bnx2x_queue_setup_tx_only_params *tx_only_params =
  7040. &q_params.params.tx_only;
  7041. int rc;
  7042. u8 tx_index;
  7043. DP(NETIF_MSG_IFUP, "setting up queue %d\n", fp->index);
  7044. /* reset IGU state skip FCoE L2 queue */
  7045. if (!IS_FCOE_FP(fp))
  7046. bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID, 0,
  7047. IGU_INT_ENABLE, 0);
  7048. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  7049. /* We want to wait for completion in this context */
  7050. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  7051. /* Prepare the INIT parameters */
  7052. bnx2x_pf_q_prep_init(bp, fp, &q_params.params.init);
  7053. /* Set the command */
  7054. q_params.cmd = BNX2X_Q_CMD_INIT;
  7055. /* Change the state to INIT */
  7056. rc = bnx2x_queue_state_change(bp, &q_params);
  7057. if (rc) {
  7058. BNX2X_ERR("Queue(%d) INIT failed\n", fp->index);
  7059. return rc;
  7060. }
  7061. DP(NETIF_MSG_IFUP, "init complete\n");
  7062. /* Now move the Queue to the SETUP state... */
  7063. memset(setup_params, 0, sizeof(*setup_params));
  7064. /* Set QUEUE flags */
  7065. setup_params->flags = bnx2x_get_q_flags(bp, fp, leading);
  7066. /* Set general SETUP parameters */
  7067. bnx2x_pf_q_prep_general(bp, fp, &setup_params->gen_params,
  7068. FIRST_TX_COS_INDEX);
  7069. bnx2x_pf_rx_q_prep(bp, fp, &setup_params->pause_params,
  7070. &setup_params->rxq_params);
  7071. bnx2x_pf_tx_q_prep(bp, fp, &setup_params->txq_params,
  7072. FIRST_TX_COS_INDEX);
  7073. /* Set the command */
  7074. q_params.cmd = BNX2X_Q_CMD_SETUP;
  7075. if (IS_FCOE_FP(fp))
  7076. bp->fcoe_init = true;
  7077. /* Change the state to SETUP */
  7078. rc = bnx2x_queue_state_change(bp, &q_params);
  7079. if (rc) {
  7080. BNX2X_ERR("Queue(%d) SETUP failed\n", fp->index);
  7081. return rc;
  7082. }
  7083. /* loop through the relevant tx-only indices */
  7084. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  7085. tx_index < fp->max_cos;
  7086. tx_index++) {
  7087. /* prepare and send tx-only ramrod*/
  7088. rc = bnx2x_setup_tx_only(bp, fp, &q_params,
  7089. tx_only_params, tx_index, leading);
  7090. if (rc) {
  7091. BNX2X_ERR("Queue(%d.%d) TX_ONLY_SETUP failed\n",
  7092. fp->index, tx_index);
  7093. return rc;
  7094. }
  7095. }
  7096. return rc;
  7097. }
  7098. static int bnx2x_stop_queue(struct bnx2x *bp, int index)
  7099. {
  7100. struct bnx2x_fastpath *fp = &bp->fp[index];
  7101. struct bnx2x_fp_txdata *txdata;
  7102. struct bnx2x_queue_state_params q_params = {NULL};
  7103. int rc, tx_index;
  7104. DP(NETIF_MSG_IFDOWN, "stopping queue %d cid %d\n", index, fp->cid);
  7105. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  7106. /* We want to wait for completion in this context */
  7107. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  7108. /* close tx-only connections */
  7109. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  7110. tx_index < fp->max_cos;
  7111. tx_index++){
  7112. /* ascertain this is a normal queue*/
  7113. txdata = fp->txdata_ptr[tx_index];
  7114. DP(NETIF_MSG_IFDOWN, "stopping tx-only queue %d\n",
  7115. txdata->txq_index);
  7116. /* send halt terminate on tx-only connection */
  7117. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  7118. memset(&q_params.params.terminate, 0,
  7119. sizeof(q_params.params.terminate));
  7120. q_params.params.terminate.cid_index = tx_index;
  7121. rc = bnx2x_queue_state_change(bp, &q_params);
  7122. if (rc)
  7123. return rc;
  7124. /* send halt terminate on tx-only connection */
  7125. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  7126. memset(&q_params.params.cfc_del, 0,
  7127. sizeof(q_params.params.cfc_del));
  7128. q_params.params.cfc_del.cid_index = tx_index;
  7129. rc = bnx2x_queue_state_change(bp, &q_params);
  7130. if (rc)
  7131. return rc;
  7132. }
  7133. /* Stop the primary connection: */
  7134. /* ...halt the connection */
  7135. q_params.cmd = BNX2X_Q_CMD_HALT;
  7136. rc = bnx2x_queue_state_change(bp, &q_params);
  7137. if (rc)
  7138. return rc;
  7139. /* ...terminate the connection */
  7140. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  7141. memset(&q_params.params.terminate, 0,
  7142. sizeof(q_params.params.terminate));
  7143. q_params.params.terminate.cid_index = FIRST_TX_COS_INDEX;
  7144. rc = bnx2x_queue_state_change(bp, &q_params);
  7145. if (rc)
  7146. return rc;
  7147. /* ...delete cfc entry */
  7148. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  7149. memset(&q_params.params.cfc_del, 0,
  7150. sizeof(q_params.params.cfc_del));
  7151. q_params.params.cfc_del.cid_index = FIRST_TX_COS_INDEX;
  7152. return bnx2x_queue_state_change(bp, &q_params);
  7153. }
  7154. static void bnx2x_reset_func(struct bnx2x *bp)
  7155. {
  7156. int port = BP_PORT(bp);
  7157. int func = BP_FUNC(bp);
  7158. int i;
  7159. /* Disable the function in the FW */
  7160. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0);
  7161. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0);
  7162. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0);
  7163. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0);
  7164. /* FP SBs */
  7165. for_each_eth_queue(bp, i) {
  7166. struct bnx2x_fastpath *fp = &bp->fp[i];
  7167. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  7168. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id),
  7169. SB_DISABLED);
  7170. }
  7171. if (CNIC_LOADED(bp))
  7172. /* CNIC SB */
  7173. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  7174. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET
  7175. (bnx2x_cnic_fw_sb_id(bp)), SB_DISABLED);
  7176. /* SP SB */
  7177. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  7178. CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func),
  7179. SB_DISABLED);
  7180. for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++)
  7181. REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func),
  7182. 0);
  7183. /* Configure IGU */
  7184. if (bp->common.int_block == INT_BLOCK_HC) {
  7185. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  7186. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  7187. } else {
  7188. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  7189. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  7190. }
  7191. if (CNIC_LOADED(bp)) {
  7192. /* Disable Timer scan */
  7193. REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 0);
  7194. /*
  7195. * Wait for at least 10ms and up to 2 second for the timers
  7196. * scan to complete
  7197. */
  7198. for (i = 0; i < 200; i++) {
  7199. usleep_range(10000, 20000);
  7200. if (!REG_RD(bp, TM_REG_LIN0_SCAN_ON + port*4))
  7201. break;
  7202. }
  7203. }
  7204. /* Clear ILT */
  7205. bnx2x_clear_func_ilt(bp, func);
  7206. /* Timers workaround bug for E2: if this is vnic-3,
  7207. * we need to set the entire ilt range for this timers.
  7208. */
  7209. if (!CHIP_IS_E1x(bp) && BP_VN(bp) == 3) {
  7210. struct ilt_client_info ilt_cli;
  7211. /* use dummy TM client */
  7212. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  7213. ilt_cli.start = 0;
  7214. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  7215. ilt_cli.client_num = ILT_CLIENT_TM;
  7216. bnx2x_ilt_boundry_init_op(bp, &ilt_cli, 0, INITOP_CLEAR);
  7217. }
  7218. /* this assumes that reset_port() called before reset_func()*/
  7219. if (!CHIP_IS_E1x(bp))
  7220. bnx2x_pf_disable(bp);
  7221. bp->dmae_ready = 0;
  7222. }
  7223. static void bnx2x_reset_port(struct bnx2x *bp)
  7224. {
  7225. int port = BP_PORT(bp);
  7226. u32 val;
  7227. /* Reset physical Link */
  7228. bnx2x__link_reset(bp);
  7229. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  7230. /* Do not rcv packets to BRB */
  7231. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0);
  7232. /* Do not direct rcv packets that are not for MCP to the BRB */
  7233. REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
  7234. NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
  7235. /* Configure AEU */
  7236. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0);
  7237. msleep(100);
  7238. /* Check for BRB port occupancy */
  7239. val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4);
  7240. if (val)
  7241. DP(NETIF_MSG_IFDOWN,
  7242. "BRB1 is not empty %d blocks are occupied\n", val);
  7243. /* TODO: Close Doorbell port? */
  7244. }
  7245. static int bnx2x_reset_hw(struct bnx2x *bp, u32 load_code)
  7246. {
  7247. struct bnx2x_func_state_params func_params = {NULL};
  7248. /* Prepare parameters for function state transitions */
  7249. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  7250. func_params.f_obj = &bp->func_obj;
  7251. func_params.cmd = BNX2X_F_CMD_HW_RESET;
  7252. func_params.params.hw_init.load_phase = load_code;
  7253. return bnx2x_func_state_change(bp, &func_params);
  7254. }
  7255. static int bnx2x_func_stop(struct bnx2x *bp)
  7256. {
  7257. struct bnx2x_func_state_params func_params = {NULL};
  7258. int rc;
  7259. /* Prepare parameters for function state transitions */
  7260. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  7261. func_params.f_obj = &bp->func_obj;
  7262. func_params.cmd = BNX2X_F_CMD_STOP;
  7263. /*
  7264. * Try to stop the function the 'good way'. If fails (in case
  7265. * of a parity error during bnx2x_chip_cleanup()) and we are
  7266. * not in a debug mode, perform a state transaction in order to
  7267. * enable further HW_RESET transaction.
  7268. */
  7269. rc = bnx2x_func_state_change(bp, &func_params);
  7270. if (rc) {
  7271. #ifdef BNX2X_STOP_ON_ERROR
  7272. return rc;
  7273. #else
  7274. BNX2X_ERR("FUNC_STOP ramrod failed. Running a dry transaction\n");
  7275. __set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags);
  7276. return bnx2x_func_state_change(bp, &func_params);
  7277. #endif
  7278. }
  7279. return 0;
  7280. }
  7281. /**
  7282. * bnx2x_send_unload_req - request unload mode from the MCP.
  7283. *
  7284. * @bp: driver handle
  7285. * @unload_mode: requested function's unload mode
  7286. *
  7287. * Return unload mode returned by the MCP: COMMON, PORT or FUNC.
  7288. */
  7289. u32 bnx2x_send_unload_req(struct bnx2x *bp, int unload_mode)
  7290. {
  7291. u32 reset_code = 0;
  7292. int port = BP_PORT(bp);
  7293. /* Select the UNLOAD request mode */
  7294. if (unload_mode == UNLOAD_NORMAL)
  7295. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  7296. else if (bp->flags & NO_WOL_FLAG)
  7297. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP;
  7298. else if (bp->wol) {
  7299. u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
  7300. u8 *mac_addr = bp->dev->dev_addr;
  7301. struct pci_dev *pdev = bp->pdev;
  7302. u32 val;
  7303. u16 pmc;
  7304. /* The mac address is written to entries 1-4 to
  7305. * preserve entry 0 which is used by the PMF
  7306. */
  7307. u8 entry = (BP_VN(bp) + 1)*8;
  7308. val = (mac_addr[0] << 8) | mac_addr[1];
  7309. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val);
  7310. val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
  7311. (mac_addr[4] << 8) | mac_addr[5];
  7312. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val);
  7313. /* Enable the PME and clear the status */
  7314. pci_read_config_word(pdev, pdev->pm_cap + PCI_PM_CTRL, &pmc);
  7315. pmc |= PCI_PM_CTRL_PME_ENABLE | PCI_PM_CTRL_PME_STATUS;
  7316. pci_write_config_word(pdev, pdev->pm_cap + PCI_PM_CTRL, pmc);
  7317. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN;
  7318. } else
  7319. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  7320. /* Send the request to the MCP */
  7321. if (!BP_NOMCP(bp))
  7322. reset_code = bnx2x_fw_command(bp, reset_code, 0);
  7323. else {
  7324. int path = BP_PATH(bp);
  7325. DP(NETIF_MSG_IFDOWN, "NO MCP - load counts[%d] %d, %d, %d\n",
  7326. path, load_count[path][0], load_count[path][1],
  7327. load_count[path][2]);
  7328. load_count[path][0]--;
  7329. load_count[path][1 + port]--;
  7330. DP(NETIF_MSG_IFDOWN, "NO MCP - new load counts[%d] %d, %d, %d\n",
  7331. path, load_count[path][0], load_count[path][1],
  7332. load_count[path][2]);
  7333. if (load_count[path][0] == 0)
  7334. reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON;
  7335. else if (load_count[path][1 + port] == 0)
  7336. reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT;
  7337. else
  7338. reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION;
  7339. }
  7340. return reset_code;
  7341. }
  7342. /**
  7343. * bnx2x_send_unload_done - send UNLOAD_DONE command to the MCP.
  7344. *
  7345. * @bp: driver handle
  7346. * @keep_link: true iff link should be kept up
  7347. */
  7348. void bnx2x_send_unload_done(struct bnx2x *bp, bool keep_link)
  7349. {
  7350. u32 reset_param = keep_link ? DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET : 0;
  7351. /* Report UNLOAD_DONE to MCP */
  7352. if (!BP_NOMCP(bp))
  7353. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, reset_param);
  7354. }
  7355. static int bnx2x_func_wait_started(struct bnx2x *bp)
  7356. {
  7357. int tout = 50;
  7358. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  7359. if (!bp->port.pmf)
  7360. return 0;
  7361. /*
  7362. * (assumption: No Attention from MCP at this stage)
  7363. * PMF probably in the middle of TX disable/enable transaction
  7364. * 1. Sync IRS for default SB
  7365. * 2. Sync SP queue - this guarantees us that attention handling started
  7366. * 3. Wait, that TX disable/enable transaction completes
  7367. *
  7368. * 1+2 guarantee that if DCBx attention was scheduled it already changed
  7369. * pending bit of transaction from STARTED-->TX_STOPPED, if we already
  7370. * received completion for the transaction the state is TX_STOPPED.
  7371. * State will return to STARTED after completion of TX_STOPPED-->STARTED
  7372. * transaction.
  7373. */
  7374. /* make sure default SB ISR is done */
  7375. if (msix)
  7376. synchronize_irq(bp->msix_table[0].vector);
  7377. else
  7378. synchronize_irq(bp->pdev->irq);
  7379. flush_workqueue(bnx2x_wq);
  7380. while (bnx2x_func_get_state(bp, &bp->func_obj) !=
  7381. BNX2X_F_STATE_STARTED && tout--)
  7382. msleep(20);
  7383. if (bnx2x_func_get_state(bp, &bp->func_obj) !=
  7384. BNX2X_F_STATE_STARTED) {
  7385. #ifdef BNX2X_STOP_ON_ERROR
  7386. BNX2X_ERR("Wrong function state\n");
  7387. return -EBUSY;
  7388. #else
  7389. /*
  7390. * Failed to complete the transaction in a "good way"
  7391. * Force both transactions with CLR bit
  7392. */
  7393. struct bnx2x_func_state_params func_params = {NULL};
  7394. DP(NETIF_MSG_IFDOWN,
  7395. "Hmmm... Unexpected function state! Forcing STARTED-->TX_ST0PPED-->STARTED\n");
  7396. func_params.f_obj = &bp->func_obj;
  7397. __set_bit(RAMROD_DRV_CLR_ONLY,
  7398. &func_params.ramrod_flags);
  7399. /* STARTED-->TX_ST0PPED */
  7400. func_params.cmd = BNX2X_F_CMD_TX_STOP;
  7401. bnx2x_func_state_change(bp, &func_params);
  7402. /* TX_ST0PPED-->STARTED */
  7403. func_params.cmd = BNX2X_F_CMD_TX_START;
  7404. return bnx2x_func_state_change(bp, &func_params);
  7405. #endif
  7406. }
  7407. return 0;
  7408. }
  7409. void bnx2x_chip_cleanup(struct bnx2x *bp, int unload_mode, bool keep_link)
  7410. {
  7411. int port = BP_PORT(bp);
  7412. int i, rc = 0;
  7413. u8 cos;
  7414. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  7415. u32 reset_code;
  7416. /* Wait until tx fastpath tasks complete */
  7417. for_each_tx_queue(bp, i) {
  7418. struct bnx2x_fastpath *fp = &bp->fp[i];
  7419. for_each_cos_in_tx_queue(fp, cos)
  7420. rc = bnx2x_clean_tx_queue(bp, fp->txdata_ptr[cos]);
  7421. #ifdef BNX2X_STOP_ON_ERROR
  7422. if (rc)
  7423. return;
  7424. #endif
  7425. }
  7426. /* Give HW time to discard old tx messages */
  7427. usleep_range(1000, 2000);
  7428. /* Clean all ETH MACs */
  7429. rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_ETH_MAC,
  7430. false);
  7431. if (rc < 0)
  7432. BNX2X_ERR("Failed to delete all ETH macs: %d\n", rc);
  7433. /* Clean up UC list */
  7434. rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_UC_LIST_MAC,
  7435. true);
  7436. if (rc < 0)
  7437. BNX2X_ERR("Failed to schedule DEL commands for UC MACs list: %d\n",
  7438. rc);
  7439. /* Disable LLH */
  7440. if (!CHIP_IS_E1(bp))
  7441. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  7442. /* Set "drop all" (stop Rx).
  7443. * We need to take a netif_addr_lock() here in order to prevent
  7444. * a race between the completion code and this code.
  7445. */
  7446. netif_addr_lock_bh(bp->dev);
  7447. /* Schedule the rx_mode command */
  7448. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  7449. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  7450. else
  7451. bnx2x_set_storm_rx_mode(bp);
  7452. /* Cleanup multicast configuration */
  7453. rparam.mcast_obj = &bp->mcast_obj;
  7454. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  7455. if (rc < 0)
  7456. BNX2X_ERR("Failed to send DEL multicast command: %d\n", rc);
  7457. netif_addr_unlock_bh(bp->dev);
  7458. bnx2x_iov_chip_cleanup(bp);
  7459. /*
  7460. * Send the UNLOAD_REQUEST to the MCP. This will return if
  7461. * this function should perform FUNC, PORT or COMMON HW
  7462. * reset.
  7463. */
  7464. reset_code = bnx2x_send_unload_req(bp, unload_mode);
  7465. /*
  7466. * (assumption: No Attention from MCP at this stage)
  7467. * PMF probably in the middle of TX disable/enable transaction
  7468. */
  7469. rc = bnx2x_func_wait_started(bp);
  7470. if (rc) {
  7471. BNX2X_ERR("bnx2x_func_wait_started failed\n");
  7472. #ifdef BNX2X_STOP_ON_ERROR
  7473. return;
  7474. #endif
  7475. }
  7476. /* Close multi and leading connections
  7477. * Completions for ramrods are collected in a synchronous way
  7478. */
  7479. for_each_eth_queue(bp, i)
  7480. if (bnx2x_stop_queue(bp, i))
  7481. #ifdef BNX2X_STOP_ON_ERROR
  7482. return;
  7483. #else
  7484. goto unload_error;
  7485. #endif
  7486. if (CNIC_LOADED(bp)) {
  7487. for_each_cnic_queue(bp, i)
  7488. if (bnx2x_stop_queue(bp, i))
  7489. #ifdef BNX2X_STOP_ON_ERROR
  7490. return;
  7491. #else
  7492. goto unload_error;
  7493. #endif
  7494. }
  7495. /* If SP settings didn't get completed so far - something
  7496. * very wrong has happen.
  7497. */
  7498. if (!bnx2x_wait_sp_comp(bp, ~0x0UL))
  7499. BNX2X_ERR("Hmmm... Common slow path ramrods got stuck!\n");
  7500. #ifndef BNX2X_STOP_ON_ERROR
  7501. unload_error:
  7502. #endif
  7503. rc = bnx2x_func_stop(bp);
  7504. if (rc) {
  7505. BNX2X_ERR("Function stop failed!\n");
  7506. #ifdef BNX2X_STOP_ON_ERROR
  7507. return;
  7508. #endif
  7509. }
  7510. /* Disable HW interrupts, NAPI */
  7511. bnx2x_netif_stop(bp, 1);
  7512. /* Delete all NAPI objects */
  7513. bnx2x_del_all_napi(bp);
  7514. if (CNIC_LOADED(bp))
  7515. bnx2x_del_all_napi_cnic(bp);
  7516. /* Release IRQs */
  7517. bnx2x_free_irq(bp);
  7518. /* Reset the chip */
  7519. rc = bnx2x_reset_hw(bp, reset_code);
  7520. if (rc)
  7521. BNX2X_ERR("HW_RESET failed\n");
  7522. /* Report UNLOAD_DONE to MCP */
  7523. bnx2x_send_unload_done(bp, keep_link);
  7524. }
  7525. void bnx2x_disable_close_the_gate(struct bnx2x *bp)
  7526. {
  7527. u32 val;
  7528. DP(NETIF_MSG_IFDOWN, "Disabling \"close the gates\"\n");
  7529. if (CHIP_IS_E1(bp)) {
  7530. int port = BP_PORT(bp);
  7531. u32 addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  7532. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  7533. val = REG_RD(bp, addr);
  7534. val &= ~(0x300);
  7535. REG_WR(bp, addr, val);
  7536. } else {
  7537. val = REG_RD(bp, MISC_REG_AEU_GENERAL_MASK);
  7538. val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK |
  7539. MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK);
  7540. REG_WR(bp, MISC_REG_AEU_GENERAL_MASK, val);
  7541. }
  7542. }
  7543. /* Close gates #2, #3 and #4: */
  7544. static void bnx2x_set_234_gates(struct bnx2x *bp, bool close)
  7545. {
  7546. u32 val;
  7547. /* Gates #2 and #4a are closed/opened for "not E1" only */
  7548. if (!CHIP_IS_E1(bp)) {
  7549. /* #4 */
  7550. REG_WR(bp, PXP_REG_HST_DISCARD_DOORBELLS, !!close);
  7551. /* #2 */
  7552. REG_WR(bp, PXP_REG_HST_DISCARD_INTERNAL_WRITES, !!close);
  7553. }
  7554. /* #3 */
  7555. if (CHIP_IS_E1x(bp)) {
  7556. /* Prevent interrupts from HC on both ports */
  7557. val = REG_RD(bp, HC_REG_CONFIG_1);
  7558. REG_WR(bp, HC_REG_CONFIG_1,
  7559. (!close) ? (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1) :
  7560. (val & ~(u32)HC_CONFIG_1_REG_BLOCK_DISABLE_1));
  7561. val = REG_RD(bp, HC_REG_CONFIG_0);
  7562. REG_WR(bp, HC_REG_CONFIG_0,
  7563. (!close) ? (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0) :
  7564. (val & ~(u32)HC_CONFIG_0_REG_BLOCK_DISABLE_0));
  7565. } else {
  7566. /* Prevent incoming interrupts in IGU */
  7567. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  7568. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION,
  7569. (!close) ?
  7570. (val | IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE) :
  7571. (val & ~(u32)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE));
  7572. }
  7573. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "%s gates #2, #3 and #4\n",
  7574. close ? "closing" : "opening");
  7575. mmiowb();
  7576. }
  7577. #define SHARED_MF_CLP_MAGIC 0x80000000 /* `magic' bit */
  7578. static void bnx2x_clp_reset_prep(struct bnx2x *bp, u32 *magic_val)
  7579. {
  7580. /* Do some magic... */
  7581. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  7582. *magic_val = val & SHARED_MF_CLP_MAGIC;
  7583. MF_CFG_WR(bp, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC);
  7584. }
  7585. /**
  7586. * bnx2x_clp_reset_done - restore the value of the `magic' bit.
  7587. *
  7588. * @bp: driver handle
  7589. * @magic_val: old value of the `magic' bit.
  7590. */
  7591. static void bnx2x_clp_reset_done(struct bnx2x *bp, u32 magic_val)
  7592. {
  7593. /* Restore the `magic' bit value... */
  7594. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  7595. MF_CFG_WR(bp, shared_mf_config.clp_mb,
  7596. (val & (~SHARED_MF_CLP_MAGIC)) | magic_val);
  7597. }
  7598. /**
  7599. * bnx2x_reset_mcp_prep - prepare for MCP reset.
  7600. *
  7601. * @bp: driver handle
  7602. * @magic_val: old value of 'magic' bit.
  7603. *
  7604. * Takes care of CLP configurations.
  7605. */
  7606. static void bnx2x_reset_mcp_prep(struct bnx2x *bp, u32 *magic_val)
  7607. {
  7608. u32 shmem;
  7609. u32 validity_offset;
  7610. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "Starting\n");
  7611. /* Set `magic' bit in order to save MF config */
  7612. if (!CHIP_IS_E1(bp))
  7613. bnx2x_clp_reset_prep(bp, magic_val);
  7614. /* Get shmem offset */
  7615. shmem = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  7616. validity_offset =
  7617. offsetof(struct shmem_region, validity_map[BP_PORT(bp)]);
  7618. /* Clear validity map flags */
  7619. if (shmem > 0)
  7620. REG_WR(bp, shmem + validity_offset, 0);
  7621. }
  7622. #define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */
  7623. #define MCP_ONE_TIMEOUT 100 /* 100 ms */
  7624. /**
  7625. * bnx2x_mcp_wait_one - wait for MCP_ONE_TIMEOUT
  7626. *
  7627. * @bp: driver handle
  7628. */
  7629. static void bnx2x_mcp_wait_one(struct bnx2x *bp)
  7630. {
  7631. /* special handling for emulation and FPGA,
  7632. wait 10 times longer */
  7633. if (CHIP_REV_IS_SLOW(bp))
  7634. msleep(MCP_ONE_TIMEOUT*10);
  7635. else
  7636. msleep(MCP_ONE_TIMEOUT);
  7637. }
  7638. /*
  7639. * initializes bp->common.shmem_base and waits for validity signature to appear
  7640. */
  7641. static int bnx2x_init_shmem(struct bnx2x *bp)
  7642. {
  7643. int cnt = 0;
  7644. u32 val = 0;
  7645. do {
  7646. bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  7647. if (bp->common.shmem_base) {
  7648. val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
  7649. if (val & SHR_MEM_VALIDITY_MB)
  7650. return 0;
  7651. }
  7652. bnx2x_mcp_wait_one(bp);
  7653. } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT));
  7654. BNX2X_ERR("BAD MCP validity signature\n");
  7655. return -ENODEV;
  7656. }
  7657. static int bnx2x_reset_mcp_comp(struct bnx2x *bp, u32 magic_val)
  7658. {
  7659. int rc = bnx2x_init_shmem(bp);
  7660. /* Restore the `magic' bit value */
  7661. if (!CHIP_IS_E1(bp))
  7662. bnx2x_clp_reset_done(bp, magic_val);
  7663. return rc;
  7664. }
  7665. static void bnx2x_pxp_prep(struct bnx2x *bp)
  7666. {
  7667. if (!CHIP_IS_E1(bp)) {
  7668. REG_WR(bp, PXP2_REG_RD_START_INIT, 0);
  7669. REG_WR(bp, PXP2_REG_RQ_RBC_DONE, 0);
  7670. mmiowb();
  7671. }
  7672. }
  7673. /*
  7674. * Reset the whole chip except for:
  7675. * - PCIE core
  7676. * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by
  7677. * one reset bit)
  7678. * - IGU
  7679. * - MISC (including AEU)
  7680. * - GRC
  7681. * - RBCN, RBCP
  7682. */
  7683. static void bnx2x_process_kill_chip_reset(struct bnx2x *bp, bool global)
  7684. {
  7685. u32 not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2;
  7686. u32 global_bits2, stay_reset2;
  7687. /*
  7688. * Bits that have to be set in reset_mask2 if we want to reset 'global'
  7689. * (per chip) blocks.
  7690. */
  7691. global_bits2 =
  7692. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU |
  7693. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE;
  7694. /* Don't reset the following blocks.
  7695. * Important: per port blocks (such as EMAC, BMAC, UMAC) can't be
  7696. * reset, as in 4 port device they might still be owned
  7697. * by the MCP (there is only one leader per path).
  7698. */
  7699. not_reset_mask1 =
  7700. MISC_REGISTERS_RESET_REG_1_RST_HC |
  7701. MISC_REGISTERS_RESET_REG_1_RST_PXPV |
  7702. MISC_REGISTERS_RESET_REG_1_RST_PXP;
  7703. not_reset_mask2 =
  7704. MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO |
  7705. MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE |
  7706. MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE |
  7707. MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE |
  7708. MISC_REGISTERS_RESET_REG_2_RST_RBCN |
  7709. MISC_REGISTERS_RESET_REG_2_RST_GRC |
  7710. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE |
  7711. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B |
  7712. MISC_REGISTERS_RESET_REG_2_RST_ATC |
  7713. MISC_REGISTERS_RESET_REG_2_PGLC |
  7714. MISC_REGISTERS_RESET_REG_2_RST_BMAC0 |
  7715. MISC_REGISTERS_RESET_REG_2_RST_BMAC1 |
  7716. MISC_REGISTERS_RESET_REG_2_RST_EMAC0 |
  7717. MISC_REGISTERS_RESET_REG_2_RST_EMAC1 |
  7718. MISC_REGISTERS_RESET_REG_2_UMAC0 |
  7719. MISC_REGISTERS_RESET_REG_2_UMAC1;
  7720. /*
  7721. * Keep the following blocks in reset:
  7722. * - all xxMACs are handled by the bnx2x_link code.
  7723. */
  7724. stay_reset2 =
  7725. MISC_REGISTERS_RESET_REG_2_XMAC |
  7726. MISC_REGISTERS_RESET_REG_2_XMAC_SOFT;
  7727. /* Full reset masks according to the chip */
  7728. reset_mask1 = 0xffffffff;
  7729. if (CHIP_IS_E1(bp))
  7730. reset_mask2 = 0xffff;
  7731. else if (CHIP_IS_E1H(bp))
  7732. reset_mask2 = 0x1ffff;
  7733. else if (CHIP_IS_E2(bp))
  7734. reset_mask2 = 0xfffff;
  7735. else /* CHIP_IS_E3 */
  7736. reset_mask2 = 0x3ffffff;
  7737. /* Don't reset global blocks unless we need to */
  7738. if (!global)
  7739. reset_mask2 &= ~global_bits2;
  7740. /*
  7741. * In case of attention in the QM, we need to reset PXP
  7742. * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM
  7743. * because otherwise QM reset would release 'close the gates' shortly
  7744. * before resetting the PXP, then the PSWRQ would send a write
  7745. * request to PGLUE. Then when PXP is reset, PGLUE would try to
  7746. * read the payload data from PSWWR, but PSWWR would not
  7747. * respond. The write queue in PGLUE would stuck, dmae commands
  7748. * would not return. Therefore it's important to reset the second
  7749. * reset register (containing the
  7750. * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the
  7751. * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM
  7752. * bit).
  7753. */
  7754. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
  7755. reset_mask2 & (~not_reset_mask2));
  7756. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  7757. reset_mask1 & (~not_reset_mask1));
  7758. barrier();
  7759. mmiowb();
  7760. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
  7761. reset_mask2 & (~stay_reset2));
  7762. barrier();
  7763. mmiowb();
  7764. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1);
  7765. mmiowb();
  7766. }
  7767. /**
  7768. * bnx2x_er_poll_igu_vq - poll for pending writes bit.
  7769. * It should get cleared in no more than 1s.
  7770. *
  7771. * @bp: driver handle
  7772. *
  7773. * It should get cleared in no more than 1s. Returns 0 if
  7774. * pending writes bit gets cleared.
  7775. */
  7776. static int bnx2x_er_poll_igu_vq(struct bnx2x *bp)
  7777. {
  7778. u32 cnt = 1000;
  7779. u32 pend_bits = 0;
  7780. do {
  7781. pend_bits = REG_RD(bp, IGU_REG_PENDING_BITS_STATUS);
  7782. if (pend_bits == 0)
  7783. break;
  7784. usleep_range(1000, 2000);
  7785. } while (cnt-- > 0);
  7786. if (cnt <= 0) {
  7787. BNX2X_ERR("Still pending IGU requests pend_bits=%x!\n",
  7788. pend_bits);
  7789. return -EBUSY;
  7790. }
  7791. return 0;
  7792. }
  7793. static int bnx2x_process_kill(struct bnx2x *bp, bool global)
  7794. {
  7795. int cnt = 1000;
  7796. u32 val = 0;
  7797. u32 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2;
  7798. u32 tags_63_32 = 0;
  7799. /* Empty the Tetris buffer, wait for 1s */
  7800. do {
  7801. sr_cnt = REG_RD(bp, PXP2_REG_RD_SR_CNT);
  7802. blk_cnt = REG_RD(bp, PXP2_REG_RD_BLK_CNT);
  7803. port_is_idle_0 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_0);
  7804. port_is_idle_1 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_1);
  7805. pgl_exp_rom2 = REG_RD(bp, PXP2_REG_PGL_EXP_ROM2);
  7806. if (CHIP_IS_E3(bp))
  7807. tags_63_32 = REG_RD(bp, PGLUE_B_REG_TAGS_63_32);
  7808. if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) &&
  7809. ((port_is_idle_0 & 0x1) == 0x1) &&
  7810. ((port_is_idle_1 & 0x1) == 0x1) &&
  7811. (pgl_exp_rom2 == 0xffffffff) &&
  7812. (!CHIP_IS_E3(bp) || (tags_63_32 == 0xffffffff)))
  7813. break;
  7814. usleep_range(1000, 2000);
  7815. } while (cnt-- > 0);
  7816. if (cnt <= 0) {
  7817. BNX2X_ERR("Tetris buffer didn't get empty or there are still outstanding read requests after 1s!\n");
  7818. 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",
  7819. sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1,
  7820. pgl_exp_rom2);
  7821. return -EAGAIN;
  7822. }
  7823. barrier();
  7824. /* Close gates #2, #3 and #4 */
  7825. bnx2x_set_234_gates(bp, true);
  7826. /* Poll for IGU VQs for 57712 and newer chips */
  7827. if (!CHIP_IS_E1x(bp) && bnx2x_er_poll_igu_vq(bp))
  7828. return -EAGAIN;
  7829. /* TBD: Indicate that "process kill" is in progress to MCP */
  7830. /* Clear "unprepared" bit */
  7831. REG_WR(bp, MISC_REG_UNPREPARED, 0);
  7832. barrier();
  7833. /* Make sure all is written to the chip before the reset */
  7834. mmiowb();
  7835. /* Wait for 1ms to empty GLUE and PCI-E core queues,
  7836. * PSWHST, GRC and PSWRD Tetris buffer.
  7837. */
  7838. usleep_range(1000, 2000);
  7839. /* Prepare to chip reset: */
  7840. /* MCP */
  7841. if (global)
  7842. bnx2x_reset_mcp_prep(bp, &val);
  7843. /* PXP */
  7844. bnx2x_pxp_prep(bp);
  7845. barrier();
  7846. /* reset the chip */
  7847. bnx2x_process_kill_chip_reset(bp, global);
  7848. barrier();
  7849. /* clear errors in PGB */
  7850. if (!CHIP_IS_E1x(bp))
  7851. REG_WR(bp, PGLUE_B_REG_LATCHED_ERRORS_CLR, 0x7f);
  7852. /* Recover after reset: */
  7853. /* MCP */
  7854. if (global && bnx2x_reset_mcp_comp(bp, val))
  7855. return -EAGAIN;
  7856. /* TBD: Add resetting the NO_MCP mode DB here */
  7857. /* Open the gates #2, #3 and #4 */
  7858. bnx2x_set_234_gates(bp, false);
  7859. /* TBD: IGU/AEU preparation bring back the AEU/IGU to a
  7860. * reset state, re-enable attentions. */
  7861. return 0;
  7862. }
  7863. static int bnx2x_leader_reset(struct bnx2x *bp)
  7864. {
  7865. int rc = 0;
  7866. bool global = bnx2x_reset_is_global(bp);
  7867. u32 load_code;
  7868. /* if not going to reset MCP - load "fake" driver to reset HW while
  7869. * driver is owner of the HW
  7870. */
  7871. if (!global && !BP_NOMCP(bp)) {
  7872. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_REQ,
  7873. DRV_MSG_CODE_LOAD_REQ_WITH_LFA);
  7874. if (!load_code) {
  7875. BNX2X_ERR("MCP response failure, aborting\n");
  7876. rc = -EAGAIN;
  7877. goto exit_leader_reset;
  7878. }
  7879. if ((load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) &&
  7880. (load_code != FW_MSG_CODE_DRV_LOAD_COMMON)) {
  7881. BNX2X_ERR("MCP unexpected resp, aborting\n");
  7882. rc = -EAGAIN;
  7883. goto exit_leader_reset2;
  7884. }
  7885. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE, 0);
  7886. if (!load_code) {
  7887. BNX2X_ERR("MCP response failure, aborting\n");
  7888. rc = -EAGAIN;
  7889. goto exit_leader_reset2;
  7890. }
  7891. }
  7892. /* Try to recover after the failure */
  7893. if (bnx2x_process_kill(bp, global)) {
  7894. BNX2X_ERR("Something bad had happen on engine %d! Aii!\n",
  7895. BP_PATH(bp));
  7896. rc = -EAGAIN;
  7897. goto exit_leader_reset2;
  7898. }
  7899. /*
  7900. * Clear RESET_IN_PROGRES and RESET_GLOBAL bits and update the driver
  7901. * state.
  7902. */
  7903. bnx2x_set_reset_done(bp);
  7904. if (global)
  7905. bnx2x_clear_reset_global(bp);
  7906. exit_leader_reset2:
  7907. /* unload "fake driver" if it was loaded */
  7908. if (!global && !BP_NOMCP(bp)) {
  7909. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0);
  7910. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
  7911. }
  7912. exit_leader_reset:
  7913. bp->is_leader = 0;
  7914. bnx2x_release_leader_lock(bp);
  7915. smp_mb();
  7916. return rc;
  7917. }
  7918. static void bnx2x_recovery_failed(struct bnx2x *bp)
  7919. {
  7920. netdev_err(bp->dev, "Recovery has failed. Power cycle is needed.\n");
  7921. /* Disconnect this device */
  7922. netif_device_detach(bp->dev);
  7923. /*
  7924. * Block ifup for all function on this engine until "process kill"
  7925. * or power cycle.
  7926. */
  7927. bnx2x_set_reset_in_progress(bp);
  7928. /* Shut down the power */
  7929. bnx2x_set_power_state(bp, PCI_D3hot);
  7930. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  7931. smp_mb();
  7932. }
  7933. /*
  7934. * Assumption: runs under rtnl lock. This together with the fact
  7935. * that it's called only from bnx2x_sp_rtnl() ensure that it
  7936. * will never be called when netif_running(bp->dev) is false.
  7937. */
  7938. static void bnx2x_parity_recover(struct bnx2x *bp)
  7939. {
  7940. bool global = false;
  7941. u32 error_recovered, error_unrecovered;
  7942. bool is_parity;
  7943. DP(NETIF_MSG_HW, "Handling parity\n");
  7944. while (1) {
  7945. switch (bp->recovery_state) {
  7946. case BNX2X_RECOVERY_INIT:
  7947. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_INIT\n");
  7948. is_parity = bnx2x_chk_parity_attn(bp, &global, false);
  7949. WARN_ON(!is_parity);
  7950. /* Try to get a LEADER_LOCK HW lock */
  7951. if (bnx2x_trylock_leader_lock(bp)) {
  7952. bnx2x_set_reset_in_progress(bp);
  7953. /*
  7954. * Check if there is a global attention and if
  7955. * there was a global attention, set the global
  7956. * reset bit.
  7957. */
  7958. if (global)
  7959. bnx2x_set_reset_global(bp);
  7960. bp->is_leader = 1;
  7961. }
  7962. /* Stop the driver */
  7963. /* If interface has been removed - break */
  7964. if (bnx2x_nic_unload(bp, UNLOAD_RECOVERY, false))
  7965. return;
  7966. bp->recovery_state = BNX2X_RECOVERY_WAIT;
  7967. /* Ensure "is_leader", MCP command sequence and
  7968. * "recovery_state" update values are seen on other
  7969. * CPUs.
  7970. */
  7971. smp_mb();
  7972. break;
  7973. case BNX2X_RECOVERY_WAIT:
  7974. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_WAIT\n");
  7975. if (bp->is_leader) {
  7976. int other_engine = BP_PATH(bp) ? 0 : 1;
  7977. bool other_load_status =
  7978. bnx2x_get_load_status(bp, other_engine);
  7979. bool load_status =
  7980. bnx2x_get_load_status(bp, BP_PATH(bp));
  7981. global = bnx2x_reset_is_global(bp);
  7982. /*
  7983. * In case of a parity in a global block, let
  7984. * the first leader that performs a
  7985. * leader_reset() reset the global blocks in
  7986. * order to clear global attentions. Otherwise
  7987. * the gates will remain closed for that
  7988. * engine.
  7989. */
  7990. if (load_status ||
  7991. (global && other_load_status)) {
  7992. /* Wait until all other functions get
  7993. * down.
  7994. */
  7995. schedule_delayed_work(&bp->sp_rtnl_task,
  7996. HZ/10);
  7997. return;
  7998. } else {
  7999. /* If all other functions got down -
  8000. * try to bring the chip back to
  8001. * normal. In any case it's an exit
  8002. * point for a leader.
  8003. */
  8004. if (bnx2x_leader_reset(bp)) {
  8005. bnx2x_recovery_failed(bp);
  8006. return;
  8007. }
  8008. /* If we are here, means that the
  8009. * leader has succeeded and doesn't
  8010. * want to be a leader any more. Try
  8011. * to continue as a none-leader.
  8012. */
  8013. break;
  8014. }
  8015. } else { /* non-leader */
  8016. if (!bnx2x_reset_is_done(bp, BP_PATH(bp))) {
  8017. /* Try to get a LEADER_LOCK HW lock as
  8018. * long as a former leader may have
  8019. * been unloaded by the user or
  8020. * released a leadership by another
  8021. * reason.
  8022. */
  8023. if (bnx2x_trylock_leader_lock(bp)) {
  8024. /* I'm a leader now! Restart a
  8025. * switch case.
  8026. */
  8027. bp->is_leader = 1;
  8028. break;
  8029. }
  8030. schedule_delayed_work(&bp->sp_rtnl_task,
  8031. HZ/10);
  8032. return;
  8033. } else {
  8034. /*
  8035. * If there was a global attention, wait
  8036. * for it to be cleared.
  8037. */
  8038. if (bnx2x_reset_is_global(bp)) {
  8039. schedule_delayed_work(
  8040. &bp->sp_rtnl_task,
  8041. HZ/10);
  8042. return;
  8043. }
  8044. error_recovered =
  8045. bp->eth_stats.recoverable_error;
  8046. error_unrecovered =
  8047. bp->eth_stats.unrecoverable_error;
  8048. bp->recovery_state =
  8049. BNX2X_RECOVERY_NIC_LOADING;
  8050. if (bnx2x_nic_load(bp, LOAD_NORMAL)) {
  8051. error_unrecovered++;
  8052. netdev_err(bp->dev,
  8053. "Recovery failed. Power cycle needed\n");
  8054. /* Disconnect this device */
  8055. netif_device_detach(bp->dev);
  8056. /* Shut down the power */
  8057. bnx2x_set_power_state(
  8058. bp, PCI_D3hot);
  8059. smp_mb();
  8060. } else {
  8061. bp->recovery_state =
  8062. BNX2X_RECOVERY_DONE;
  8063. error_recovered++;
  8064. smp_mb();
  8065. }
  8066. bp->eth_stats.recoverable_error =
  8067. error_recovered;
  8068. bp->eth_stats.unrecoverable_error =
  8069. error_unrecovered;
  8070. return;
  8071. }
  8072. }
  8073. default:
  8074. return;
  8075. }
  8076. }
  8077. }
  8078. static int bnx2x_close(struct net_device *dev);
  8079. /* bnx2x_nic_unload() flushes the bnx2x_wq, thus reset task is
  8080. * scheduled on a general queue in order to prevent a dead lock.
  8081. */
  8082. static void bnx2x_sp_rtnl_task(struct work_struct *work)
  8083. {
  8084. struct bnx2x *bp = container_of(work, struct bnx2x, sp_rtnl_task.work);
  8085. rtnl_lock();
  8086. if (!netif_running(bp->dev)) {
  8087. rtnl_unlock();
  8088. return;
  8089. }
  8090. if (unlikely(bp->recovery_state != BNX2X_RECOVERY_DONE)) {
  8091. #ifdef BNX2X_STOP_ON_ERROR
  8092. BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
  8093. "you will need to reboot when done\n");
  8094. goto sp_rtnl_not_reset;
  8095. #endif
  8096. /*
  8097. * Clear all pending SP commands as we are going to reset the
  8098. * function anyway.
  8099. */
  8100. bp->sp_rtnl_state = 0;
  8101. smp_mb();
  8102. bnx2x_parity_recover(bp);
  8103. rtnl_unlock();
  8104. return;
  8105. }
  8106. if (test_and_clear_bit(BNX2X_SP_RTNL_TX_TIMEOUT, &bp->sp_rtnl_state)) {
  8107. #ifdef BNX2X_STOP_ON_ERROR
  8108. BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
  8109. "you will need to reboot when done\n");
  8110. goto sp_rtnl_not_reset;
  8111. #endif
  8112. /*
  8113. * Clear all pending SP commands as we are going to reset the
  8114. * function anyway.
  8115. */
  8116. bp->sp_rtnl_state = 0;
  8117. smp_mb();
  8118. bnx2x_nic_unload(bp, UNLOAD_NORMAL, true);
  8119. bnx2x_nic_load(bp, LOAD_NORMAL);
  8120. rtnl_unlock();
  8121. return;
  8122. }
  8123. #ifdef BNX2X_STOP_ON_ERROR
  8124. sp_rtnl_not_reset:
  8125. #endif
  8126. if (test_and_clear_bit(BNX2X_SP_RTNL_SETUP_TC, &bp->sp_rtnl_state))
  8127. bnx2x_setup_tc(bp->dev, bp->dcbx_port_params.ets.num_of_cos);
  8128. if (test_and_clear_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE, &bp->sp_rtnl_state))
  8129. bnx2x_after_function_update(bp);
  8130. /*
  8131. * in case of fan failure we need to reset id if the "stop on error"
  8132. * debug flag is set, since we trying to prevent permanent overheating
  8133. * damage
  8134. */
  8135. if (test_and_clear_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state)) {
  8136. DP(NETIF_MSG_HW, "fan failure detected. Unloading driver\n");
  8137. netif_device_detach(bp->dev);
  8138. bnx2x_close(bp->dev);
  8139. rtnl_unlock();
  8140. return;
  8141. }
  8142. if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_MCAST, &bp->sp_rtnl_state)) {
  8143. DP(BNX2X_MSG_SP,
  8144. "sending set mcast vf pf channel message from rtnl sp-task\n");
  8145. bnx2x_vfpf_set_mcast(bp->dev);
  8146. }
  8147. if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_CHANNEL_DOWN,
  8148. &bp->sp_rtnl_state)){
  8149. if (!test_bit(__LINK_STATE_NOCARRIER, &bp->dev->state)) {
  8150. bnx2x_tx_disable(bp);
  8151. BNX2X_ERR("PF indicated channel is not servicable anymore. This means this VF device is no longer operational\n");
  8152. }
  8153. }
  8154. if (test_and_clear_bit(BNX2X_SP_RTNL_RX_MODE, &bp->sp_rtnl_state)) {
  8155. DP(BNX2X_MSG_SP, "Handling Rx Mode setting\n");
  8156. bnx2x_set_rx_mode_inner(bp);
  8157. }
  8158. if (test_and_clear_bit(BNX2X_SP_RTNL_HYPERVISOR_VLAN,
  8159. &bp->sp_rtnl_state))
  8160. bnx2x_pf_set_vfs_vlan(bp);
  8161. if (test_and_clear_bit(BNX2X_SP_RTNL_TX_STOP, &bp->sp_rtnl_state)) {
  8162. bnx2x_dcbx_stop_hw_tx(bp);
  8163. bnx2x_dcbx_resume_hw_tx(bp);
  8164. }
  8165. /* work which needs rtnl lock not-taken (as it takes the lock itself and
  8166. * can be called from other contexts as well)
  8167. */
  8168. rtnl_unlock();
  8169. /* enable SR-IOV if applicable */
  8170. if (IS_SRIOV(bp) && test_and_clear_bit(BNX2X_SP_RTNL_ENABLE_SRIOV,
  8171. &bp->sp_rtnl_state)) {
  8172. bnx2x_disable_sriov(bp);
  8173. bnx2x_enable_sriov(bp);
  8174. }
  8175. }
  8176. static void bnx2x_period_task(struct work_struct *work)
  8177. {
  8178. struct bnx2x *bp = container_of(work, struct bnx2x, period_task.work);
  8179. if (!netif_running(bp->dev))
  8180. goto period_task_exit;
  8181. if (CHIP_REV_IS_SLOW(bp)) {
  8182. BNX2X_ERR("period task called on emulation, ignoring\n");
  8183. goto period_task_exit;
  8184. }
  8185. bnx2x_acquire_phy_lock(bp);
  8186. /*
  8187. * The barrier is needed to ensure the ordering between the writing to
  8188. * the bp->port.pmf in the bnx2x_nic_load() or bnx2x_pmf_update() and
  8189. * the reading here.
  8190. */
  8191. smp_mb();
  8192. if (bp->port.pmf) {
  8193. bnx2x_period_func(&bp->link_params, &bp->link_vars);
  8194. /* Re-queue task in 1 sec */
  8195. queue_delayed_work(bnx2x_wq, &bp->period_task, 1*HZ);
  8196. }
  8197. bnx2x_release_phy_lock(bp);
  8198. period_task_exit:
  8199. return;
  8200. }
  8201. /*
  8202. * Init service functions
  8203. */
  8204. u32 bnx2x_get_pretend_reg(struct bnx2x *bp)
  8205. {
  8206. u32 base = PXP2_REG_PGL_PRETEND_FUNC_F0;
  8207. u32 stride = PXP2_REG_PGL_PRETEND_FUNC_F1 - base;
  8208. return base + (BP_ABS_FUNC(bp)) * stride;
  8209. }
  8210. static void bnx2x_prev_unload_close_mac(struct bnx2x *bp,
  8211. struct bnx2x_mac_vals *vals)
  8212. {
  8213. u32 val, base_addr, offset, mask, reset_reg;
  8214. bool mac_stopped = false;
  8215. u8 port = BP_PORT(bp);
  8216. /* reset addresses as they also mark which values were changed */
  8217. vals->bmac_addr = 0;
  8218. vals->umac_addr = 0;
  8219. vals->xmac_addr = 0;
  8220. vals->emac_addr = 0;
  8221. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_2);
  8222. if (!CHIP_IS_E3(bp)) {
  8223. val = REG_RD(bp, NIG_REG_BMAC0_REGS_OUT_EN + port * 4);
  8224. mask = MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port;
  8225. if ((mask & reset_reg) && val) {
  8226. u32 wb_data[2];
  8227. BNX2X_DEV_INFO("Disable bmac Rx\n");
  8228. base_addr = BP_PORT(bp) ? NIG_REG_INGRESS_BMAC1_MEM
  8229. : NIG_REG_INGRESS_BMAC0_MEM;
  8230. offset = CHIP_IS_E2(bp) ? BIGMAC2_REGISTER_BMAC_CONTROL
  8231. : BIGMAC_REGISTER_BMAC_CONTROL;
  8232. /*
  8233. * use rd/wr since we cannot use dmae. This is safe
  8234. * since MCP won't access the bus due to the request
  8235. * to unload, and no function on the path can be
  8236. * loaded at this time.
  8237. */
  8238. wb_data[0] = REG_RD(bp, base_addr + offset);
  8239. wb_data[1] = REG_RD(bp, base_addr + offset + 0x4);
  8240. vals->bmac_addr = base_addr + offset;
  8241. vals->bmac_val[0] = wb_data[0];
  8242. vals->bmac_val[1] = wb_data[1];
  8243. wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE;
  8244. REG_WR(bp, vals->bmac_addr, wb_data[0]);
  8245. REG_WR(bp, vals->bmac_addr + 0x4, wb_data[1]);
  8246. }
  8247. BNX2X_DEV_INFO("Disable emac Rx\n");
  8248. vals->emac_addr = NIG_REG_NIG_EMAC0_EN + BP_PORT(bp)*4;
  8249. vals->emac_val = REG_RD(bp, vals->emac_addr);
  8250. REG_WR(bp, vals->emac_addr, 0);
  8251. mac_stopped = true;
  8252. } else {
  8253. if (reset_reg & MISC_REGISTERS_RESET_REG_2_XMAC) {
  8254. BNX2X_DEV_INFO("Disable xmac Rx\n");
  8255. base_addr = BP_PORT(bp) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
  8256. val = REG_RD(bp, base_addr + XMAC_REG_PFC_CTRL_HI);
  8257. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  8258. val & ~(1 << 1));
  8259. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  8260. val | (1 << 1));
  8261. vals->xmac_addr = base_addr + XMAC_REG_CTRL;
  8262. vals->xmac_val = REG_RD(bp, vals->xmac_addr);
  8263. REG_WR(bp, vals->xmac_addr, 0);
  8264. mac_stopped = true;
  8265. }
  8266. mask = MISC_REGISTERS_RESET_REG_2_UMAC0 << port;
  8267. if (mask & reset_reg) {
  8268. BNX2X_DEV_INFO("Disable umac Rx\n");
  8269. base_addr = BP_PORT(bp) ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
  8270. vals->umac_addr = base_addr + UMAC_REG_COMMAND_CONFIG;
  8271. vals->umac_val = REG_RD(bp, vals->umac_addr);
  8272. REG_WR(bp, vals->umac_addr, 0);
  8273. mac_stopped = true;
  8274. }
  8275. }
  8276. if (mac_stopped)
  8277. msleep(20);
  8278. }
  8279. #define BNX2X_PREV_UNDI_PROD_ADDR(p) (BAR_TSTRORM_INTMEM + 0x1508 + ((p) << 4))
  8280. #define BNX2X_PREV_UNDI_RCQ(val) ((val) & 0xffff)
  8281. #define BNX2X_PREV_UNDI_BD(val) ((val) >> 16 & 0xffff)
  8282. #define BNX2X_PREV_UNDI_PROD(rcq, bd) ((bd) << 16 | (rcq))
  8283. static void bnx2x_prev_unload_undi_inc(struct bnx2x *bp, u8 port, u8 inc)
  8284. {
  8285. u16 rcq, bd;
  8286. u32 tmp_reg = REG_RD(bp, BNX2X_PREV_UNDI_PROD_ADDR(port));
  8287. rcq = BNX2X_PREV_UNDI_RCQ(tmp_reg) + inc;
  8288. bd = BNX2X_PREV_UNDI_BD(tmp_reg) + inc;
  8289. tmp_reg = BNX2X_PREV_UNDI_PROD(rcq, bd);
  8290. REG_WR(bp, BNX2X_PREV_UNDI_PROD_ADDR(port), tmp_reg);
  8291. BNX2X_DEV_INFO("UNDI producer [%d] rings bd -> 0x%04x, rcq -> 0x%04x\n",
  8292. port, bd, rcq);
  8293. }
  8294. static int bnx2x_prev_mcp_done(struct bnx2x *bp)
  8295. {
  8296. u32 rc = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE,
  8297. DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET);
  8298. if (!rc) {
  8299. BNX2X_ERR("MCP response failure, aborting\n");
  8300. return -EBUSY;
  8301. }
  8302. return 0;
  8303. }
  8304. static struct bnx2x_prev_path_list *
  8305. bnx2x_prev_path_get_entry(struct bnx2x *bp)
  8306. {
  8307. struct bnx2x_prev_path_list *tmp_list;
  8308. list_for_each_entry(tmp_list, &bnx2x_prev_list, list)
  8309. if (PCI_SLOT(bp->pdev->devfn) == tmp_list->slot &&
  8310. bp->pdev->bus->number == tmp_list->bus &&
  8311. BP_PATH(bp) == tmp_list->path)
  8312. return tmp_list;
  8313. return NULL;
  8314. }
  8315. static int bnx2x_prev_path_mark_eeh(struct bnx2x *bp)
  8316. {
  8317. struct bnx2x_prev_path_list *tmp_list;
  8318. int rc;
  8319. rc = down_interruptible(&bnx2x_prev_sem);
  8320. if (rc) {
  8321. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  8322. return rc;
  8323. }
  8324. tmp_list = bnx2x_prev_path_get_entry(bp);
  8325. if (tmp_list) {
  8326. tmp_list->aer = 1;
  8327. rc = 0;
  8328. } else {
  8329. BNX2X_ERR("path %d: Entry does not exist for eeh; Flow occurs before initial insmod is over ?\n",
  8330. BP_PATH(bp));
  8331. }
  8332. up(&bnx2x_prev_sem);
  8333. return rc;
  8334. }
  8335. static bool bnx2x_prev_is_path_marked(struct bnx2x *bp)
  8336. {
  8337. struct bnx2x_prev_path_list *tmp_list;
  8338. bool rc = false;
  8339. if (down_trylock(&bnx2x_prev_sem))
  8340. return false;
  8341. tmp_list = bnx2x_prev_path_get_entry(bp);
  8342. if (tmp_list) {
  8343. if (tmp_list->aer) {
  8344. DP(NETIF_MSG_HW, "Path %d was marked by AER\n",
  8345. BP_PATH(bp));
  8346. } else {
  8347. rc = true;
  8348. BNX2X_DEV_INFO("Path %d was already cleaned from previous drivers\n",
  8349. BP_PATH(bp));
  8350. }
  8351. }
  8352. up(&bnx2x_prev_sem);
  8353. return rc;
  8354. }
  8355. bool bnx2x_port_after_undi(struct bnx2x *bp)
  8356. {
  8357. struct bnx2x_prev_path_list *entry;
  8358. bool val;
  8359. down(&bnx2x_prev_sem);
  8360. entry = bnx2x_prev_path_get_entry(bp);
  8361. val = !!(entry && (entry->undi & (1 << BP_PORT(bp))));
  8362. up(&bnx2x_prev_sem);
  8363. return val;
  8364. }
  8365. static int bnx2x_prev_mark_path(struct bnx2x *bp, bool after_undi)
  8366. {
  8367. struct bnx2x_prev_path_list *tmp_list;
  8368. int rc;
  8369. rc = down_interruptible(&bnx2x_prev_sem);
  8370. if (rc) {
  8371. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  8372. return rc;
  8373. }
  8374. /* Check whether the entry for this path already exists */
  8375. tmp_list = bnx2x_prev_path_get_entry(bp);
  8376. if (tmp_list) {
  8377. if (!tmp_list->aer) {
  8378. BNX2X_ERR("Re-Marking the path.\n");
  8379. } else {
  8380. DP(NETIF_MSG_HW, "Removing AER indication from path %d\n",
  8381. BP_PATH(bp));
  8382. tmp_list->aer = 0;
  8383. }
  8384. up(&bnx2x_prev_sem);
  8385. return 0;
  8386. }
  8387. up(&bnx2x_prev_sem);
  8388. /* Create an entry for this path and add it */
  8389. tmp_list = kmalloc(sizeof(struct bnx2x_prev_path_list), GFP_KERNEL);
  8390. if (!tmp_list) {
  8391. BNX2X_ERR("Failed to allocate 'bnx2x_prev_path_list'\n");
  8392. return -ENOMEM;
  8393. }
  8394. tmp_list->bus = bp->pdev->bus->number;
  8395. tmp_list->slot = PCI_SLOT(bp->pdev->devfn);
  8396. tmp_list->path = BP_PATH(bp);
  8397. tmp_list->aer = 0;
  8398. tmp_list->undi = after_undi ? (1 << BP_PORT(bp)) : 0;
  8399. rc = down_interruptible(&bnx2x_prev_sem);
  8400. if (rc) {
  8401. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  8402. kfree(tmp_list);
  8403. } else {
  8404. DP(NETIF_MSG_HW, "Marked path [%d] - finished previous unload\n",
  8405. BP_PATH(bp));
  8406. list_add(&tmp_list->list, &bnx2x_prev_list);
  8407. up(&bnx2x_prev_sem);
  8408. }
  8409. return rc;
  8410. }
  8411. static int bnx2x_do_flr(struct bnx2x *bp)
  8412. {
  8413. struct pci_dev *dev = bp->pdev;
  8414. if (CHIP_IS_E1x(bp)) {
  8415. BNX2X_DEV_INFO("FLR not supported in E1/E1H\n");
  8416. return -EINVAL;
  8417. }
  8418. /* only bootcode REQ_BC_VER_4_INITIATE_FLR and onwards support flr */
  8419. if (bp->common.bc_ver < REQ_BC_VER_4_INITIATE_FLR) {
  8420. BNX2X_ERR("FLR not supported by BC_VER: 0x%x\n",
  8421. bp->common.bc_ver);
  8422. return -EINVAL;
  8423. }
  8424. if (!pci_wait_for_pending_transaction(dev))
  8425. dev_err(&dev->dev, "transaction is not cleared; proceeding with reset anyway\n");
  8426. BNX2X_DEV_INFO("Initiating FLR\n");
  8427. bnx2x_fw_command(bp, DRV_MSG_CODE_INITIATE_FLR, 0);
  8428. return 0;
  8429. }
  8430. static int bnx2x_prev_unload_uncommon(struct bnx2x *bp)
  8431. {
  8432. int rc;
  8433. BNX2X_DEV_INFO("Uncommon unload Flow\n");
  8434. /* Test if previous unload process was already finished for this path */
  8435. if (bnx2x_prev_is_path_marked(bp))
  8436. return bnx2x_prev_mcp_done(bp);
  8437. BNX2X_DEV_INFO("Path is unmarked\n");
  8438. /* If function has FLR capabilities, and existing FW version matches
  8439. * the one required, then FLR will be sufficient to clean any residue
  8440. * left by previous driver
  8441. */
  8442. rc = bnx2x_nic_load_analyze_req(bp, FW_MSG_CODE_DRV_LOAD_FUNCTION);
  8443. if (!rc) {
  8444. /* fw version is good */
  8445. BNX2X_DEV_INFO("FW version matches our own. Attempting FLR\n");
  8446. rc = bnx2x_do_flr(bp);
  8447. }
  8448. if (!rc) {
  8449. /* FLR was performed */
  8450. BNX2X_DEV_INFO("FLR successful\n");
  8451. return 0;
  8452. }
  8453. BNX2X_DEV_INFO("Could not FLR\n");
  8454. /* Close the MCP request, return failure*/
  8455. rc = bnx2x_prev_mcp_done(bp);
  8456. if (!rc)
  8457. rc = BNX2X_PREV_WAIT_NEEDED;
  8458. return rc;
  8459. }
  8460. static int bnx2x_prev_unload_common(struct bnx2x *bp)
  8461. {
  8462. u32 reset_reg, tmp_reg = 0, rc;
  8463. bool prev_undi = false;
  8464. struct bnx2x_mac_vals mac_vals;
  8465. /* It is possible a previous function received 'common' answer,
  8466. * but hasn't loaded yet, therefore creating a scenario of
  8467. * multiple functions receiving 'common' on the same path.
  8468. */
  8469. BNX2X_DEV_INFO("Common unload Flow\n");
  8470. memset(&mac_vals, 0, sizeof(mac_vals));
  8471. if (bnx2x_prev_is_path_marked(bp))
  8472. return bnx2x_prev_mcp_done(bp);
  8473. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
  8474. /* Reset should be performed after BRB is emptied */
  8475. if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_BRB1) {
  8476. u32 timer_count = 1000;
  8477. /* Close the MAC Rx to prevent BRB from filling up */
  8478. bnx2x_prev_unload_close_mac(bp, &mac_vals);
  8479. /* close LLH filters towards the BRB */
  8480. bnx2x_set_rx_filter(&bp->link_params, 0);
  8481. /* Check if the UNDI driver was previously loaded
  8482. * UNDI driver initializes CID offset for normal bell to 0x7
  8483. */
  8484. if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_DORQ) {
  8485. tmp_reg = REG_RD(bp, DORQ_REG_NORM_CID_OFST);
  8486. if (tmp_reg == 0x7) {
  8487. BNX2X_DEV_INFO("UNDI previously loaded\n");
  8488. prev_undi = true;
  8489. /* clear the UNDI indication */
  8490. REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0);
  8491. /* clear possible idle check errors */
  8492. REG_RD(bp, NIG_REG_NIG_INT_STS_CLR_0);
  8493. }
  8494. }
  8495. if (!CHIP_IS_E1x(bp))
  8496. /* block FW from writing to host */
  8497. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  8498. /* wait until BRB is empty */
  8499. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  8500. while (timer_count) {
  8501. u32 prev_brb = tmp_reg;
  8502. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  8503. if (!tmp_reg)
  8504. break;
  8505. BNX2X_DEV_INFO("BRB still has 0x%08x\n", tmp_reg);
  8506. /* reset timer as long as BRB actually gets emptied */
  8507. if (prev_brb > tmp_reg)
  8508. timer_count = 1000;
  8509. else
  8510. timer_count--;
  8511. /* If UNDI resides in memory, manually increment it */
  8512. if (prev_undi)
  8513. bnx2x_prev_unload_undi_inc(bp, BP_PORT(bp), 1);
  8514. udelay(10);
  8515. }
  8516. if (!timer_count)
  8517. BNX2X_ERR("Failed to empty BRB, hope for the best\n");
  8518. }
  8519. /* No packets are in the pipeline, path is ready for reset */
  8520. bnx2x_reset_common(bp);
  8521. if (mac_vals.xmac_addr)
  8522. REG_WR(bp, mac_vals.xmac_addr, mac_vals.xmac_val);
  8523. if (mac_vals.umac_addr)
  8524. REG_WR(bp, mac_vals.umac_addr, mac_vals.umac_val);
  8525. if (mac_vals.emac_addr)
  8526. REG_WR(bp, mac_vals.emac_addr, mac_vals.emac_val);
  8527. if (mac_vals.bmac_addr) {
  8528. REG_WR(bp, mac_vals.bmac_addr, mac_vals.bmac_val[0]);
  8529. REG_WR(bp, mac_vals.bmac_addr + 4, mac_vals.bmac_val[1]);
  8530. }
  8531. rc = bnx2x_prev_mark_path(bp, prev_undi);
  8532. if (rc) {
  8533. bnx2x_prev_mcp_done(bp);
  8534. return rc;
  8535. }
  8536. return bnx2x_prev_mcp_done(bp);
  8537. }
  8538. /* previous driver DMAE transaction may have occurred when pre-boot stage ended
  8539. * and boot began, or when kdump kernel was loaded. Either case would invalidate
  8540. * the addresses of the transaction, resulting in was-error bit set in the pci
  8541. * causing all hw-to-host pcie transactions to timeout. If this happened we want
  8542. * to clear the interrupt which detected this from the pglueb and the was done
  8543. * bit
  8544. */
  8545. static void bnx2x_prev_interrupted_dmae(struct bnx2x *bp)
  8546. {
  8547. if (!CHIP_IS_E1x(bp)) {
  8548. u32 val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS);
  8549. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN) {
  8550. DP(BNX2X_MSG_SP,
  8551. "'was error' bit was found to be set in pglueb upon startup. Clearing\n");
  8552. REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR,
  8553. 1 << BP_FUNC(bp));
  8554. }
  8555. }
  8556. }
  8557. static int bnx2x_prev_unload(struct bnx2x *bp)
  8558. {
  8559. int time_counter = 10;
  8560. u32 rc, fw, hw_lock_reg, hw_lock_val;
  8561. BNX2X_DEV_INFO("Entering Previous Unload Flow\n");
  8562. /* clear hw from errors which may have resulted from an interrupted
  8563. * dmae transaction.
  8564. */
  8565. bnx2x_prev_interrupted_dmae(bp);
  8566. /* Release previously held locks */
  8567. hw_lock_reg = (BP_FUNC(bp) <= 5) ?
  8568. (MISC_REG_DRIVER_CONTROL_1 + BP_FUNC(bp) * 8) :
  8569. (MISC_REG_DRIVER_CONTROL_7 + (BP_FUNC(bp) - 6) * 8);
  8570. hw_lock_val = REG_RD(bp, hw_lock_reg);
  8571. if (hw_lock_val) {
  8572. if (hw_lock_val & HW_LOCK_RESOURCE_NVRAM) {
  8573. BNX2X_DEV_INFO("Release Previously held NVRAM lock\n");
  8574. REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
  8575. (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << BP_PORT(bp)));
  8576. }
  8577. BNX2X_DEV_INFO("Release Previously held hw lock\n");
  8578. REG_WR(bp, hw_lock_reg, 0xffffffff);
  8579. } else
  8580. BNX2X_DEV_INFO("No need to release hw/nvram locks\n");
  8581. if (MCPR_ACCESS_LOCK_LOCK & REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK)) {
  8582. BNX2X_DEV_INFO("Release previously held alr\n");
  8583. bnx2x_release_alr(bp);
  8584. }
  8585. do {
  8586. int aer = 0;
  8587. /* Lock MCP using an unload request */
  8588. fw = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS, 0);
  8589. if (!fw) {
  8590. BNX2X_ERR("MCP response failure, aborting\n");
  8591. rc = -EBUSY;
  8592. break;
  8593. }
  8594. rc = down_interruptible(&bnx2x_prev_sem);
  8595. if (rc) {
  8596. BNX2X_ERR("Cannot check for AER; Received %d when tried to take lock\n",
  8597. rc);
  8598. } else {
  8599. /* If Path is marked by EEH, ignore unload status */
  8600. aer = !!(bnx2x_prev_path_get_entry(bp) &&
  8601. bnx2x_prev_path_get_entry(bp)->aer);
  8602. up(&bnx2x_prev_sem);
  8603. }
  8604. if (fw == FW_MSG_CODE_DRV_UNLOAD_COMMON || aer) {
  8605. rc = bnx2x_prev_unload_common(bp);
  8606. break;
  8607. }
  8608. /* non-common reply from MCP might require looping */
  8609. rc = bnx2x_prev_unload_uncommon(bp);
  8610. if (rc != BNX2X_PREV_WAIT_NEEDED)
  8611. break;
  8612. msleep(20);
  8613. } while (--time_counter);
  8614. if (!time_counter || rc) {
  8615. BNX2X_ERR("Failed unloading previous driver, aborting\n");
  8616. rc = -EBUSY;
  8617. }
  8618. /* Mark function if its port was used to boot from SAN */
  8619. if (bnx2x_port_after_undi(bp))
  8620. bp->link_params.feature_config_flags |=
  8621. FEATURE_CONFIG_BOOT_FROM_SAN;
  8622. BNX2X_DEV_INFO("Finished Previous Unload Flow [%d]\n", rc);
  8623. return rc;
  8624. }
  8625. static void bnx2x_get_common_hwinfo(struct bnx2x *bp)
  8626. {
  8627. u32 val, val2, val3, val4, id, boot_mode;
  8628. u16 pmc;
  8629. /* Get the chip revision id and number. */
  8630. /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
  8631. val = REG_RD(bp, MISC_REG_CHIP_NUM);
  8632. id = ((val & 0xffff) << 16);
  8633. val = REG_RD(bp, MISC_REG_CHIP_REV);
  8634. id |= ((val & 0xf) << 12);
  8635. /* Metal is read from PCI regs, but we can't access >=0x400 from
  8636. * the configuration space (so we need to reg_rd)
  8637. */
  8638. val = REG_RD(bp, PCICFG_OFFSET + PCI_ID_VAL3);
  8639. id |= (((val >> 24) & 0xf) << 4);
  8640. val = REG_RD(bp, MISC_REG_BOND_ID);
  8641. id |= (val & 0xf);
  8642. bp->common.chip_id = id;
  8643. /* force 57811 according to MISC register */
  8644. if (REG_RD(bp, MISC_REG_CHIP_TYPE) & MISC_REG_CHIP_TYPE_57811_MASK) {
  8645. if (CHIP_IS_57810(bp))
  8646. bp->common.chip_id = (CHIP_NUM_57811 << 16) |
  8647. (bp->common.chip_id & 0x0000FFFF);
  8648. else if (CHIP_IS_57810_MF(bp))
  8649. bp->common.chip_id = (CHIP_NUM_57811_MF << 16) |
  8650. (bp->common.chip_id & 0x0000FFFF);
  8651. bp->common.chip_id |= 0x1;
  8652. }
  8653. /* Set doorbell size */
  8654. bp->db_size = (1 << BNX2X_DB_SHIFT);
  8655. if (!CHIP_IS_E1x(bp)) {
  8656. val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR);
  8657. if ((val & 1) == 0)
  8658. val = REG_RD(bp, MISC_REG_PORT4MODE_EN);
  8659. else
  8660. val = (val >> 1) & 1;
  8661. BNX2X_DEV_INFO("chip is in %s\n", val ? "4_PORT_MODE" :
  8662. "2_PORT_MODE");
  8663. bp->common.chip_port_mode = val ? CHIP_4_PORT_MODE :
  8664. CHIP_2_PORT_MODE;
  8665. if (CHIP_MODE_IS_4_PORT(bp))
  8666. bp->pfid = (bp->pf_num >> 1); /* 0..3 */
  8667. else
  8668. bp->pfid = (bp->pf_num & 0x6); /* 0, 2, 4, 6 */
  8669. } else {
  8670. bp->common.chip_port_mode = CHIP_PORT_MODE_NONE; /* N/A */
  8671. bp->pfid = bp->pf_num; /* 0..7 */
  8672. }
  8673. BNX2X_DEV_INFO("pf_id: %x", bp->pfid);
  8674. bp->link_params.chip_id = bp->common.chip_id;
  8675. BNX2X_DEV_INFO("chip ID is 0x%x\n", id);
  8676. val = (REG_RD(bp, 0x2874) & 0x55);
  8677. if ((bp->common.chip_id & 0x1) ||
  8678. (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) {
  8679. bp->flags |= ONE_PORT_FLAG;
  8680. BNX2X_DEV_INFO("single port device\n");
  8681. }
  8682. val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4);
  8683. bp->common.flash_size = (BNX2X_NVRAM_1MB_SIZE <<
  8684. (val & MCPR_NVM_CFG4_FLASH_SIZE));
  8685. BNX2X_DEV_INFO("flash_size 0x%x (%d)\n",
  8686. bp->common.flash_size, bp->common.flash_size);
  8687. bnx2x_init_shmem(bp);
  8688. bp->common.shmem2_base = REG_RD(bp, (BP_PATH(bp) ?
  8689. MISC_REG_GENERIC_CR_1 :
  8690. MISC_REG_GENERIC_CR_0));
  8691. bp->link_params.shmem_base = bp->common.shmem_base;
  8692. bp->link_params.shmem2_base = bp->common.shmem2_base;
  8693. if (SHMEM2_RD(bp, size) >
  8694. (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
  8695. bp->link_params.lfa_base =
  8696. REG_RD(bp, bp->common.shmem2_base +
  8697. (u32)offsetof(struct shmem2_region,
  8698. lfa_host_addr[BP_PORT(bp)]));
  8699. else
  8700. bp->link_params.lfa_base = 0;
  8701. BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n",
  8702. bp->common.shmem_base, bp->common.shmem2_base);
  8703. if (!bp->common.shmem_base) {
  8704. BNX2X_DEV_INFO("MCP not active\n");
  8705. bp->flags |= NO_MCP_FLAG;
  8706. return;
  8707. }
  8708. bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config);
  8709. BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config);
  8710. bp->link_params.hw_led_mode = ((bp->common.hw_config &
  8711. SHARED_HW_CFG_LED_MODE_MASK) >>
  8712. SHARED_HW_CFG_LED_MODE_SHIFT);
  8713. bp->link_params.feature_config_flags = 0;
  8714. val = SHMEM_RD(bp, dev_info.shared_feature_config.config);
  8715. if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED)
  8716. bp->link_params.feature_config_flags |=
  8717. FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  8718. else
  8719. bp->link_params.feature_config_flags &=
  8720. ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  8721. val = SHMEM_RD(bp, dev_info.bc_rev) >> 8;
  8722. bp->common.bc_ver = val;
  8723. BNX2X_DEV_INFO("bc_ver %X\n", val);
  8724. if (val < BNX2X_BC_VER) {
  8725. /* for now only warn
  8726. * later we might need to enforce this */
  8727. BNX2X_ERR("This driver needs bc_ver %X but found %X, please upgrade BC\n",
  8728. BNX2X_BC_VER, val);
  8729. }
  8730. bp->link_params.feature_config_flags |=
  8731. (val >= REQ_BC_VER_4_VRFY_FIRST_PHY_OPT_MDL) ?
  8732. FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY : 0;
  8733. bp->link_params.feature_config_flags |=
  8734. (val >= REQ_BC_VER_4_VRFY_SPECIFIC_PHY_OPT_MDL) ?
  8735. FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY : 0;
  8736. bp->link_params.feature_config_flags |=
  8737. (val >= REQ_BC_VER_4_VRFY_AFEX_SUPPORTED) ?
  8738. FEATURE_CONFIG_BC_SUPPORTS_AFEX : 0;
  8739. bp->link_params.feature_config_flags |=
  8740. (val >= REQ_BC_VER_4_SFP_TX_DISABLE_SUPPORTED) ?
  8741. FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED : 0;
  8742. bp->link_params.feature_config_flags |=
  8743. (val >= REQ_BC_VER_4_MT_SUPPORTED) ?
  8744. FEATURE_CONFIG_MT_SUPPORT : 0;
  8745. bp->flags |= (val >= REQ_BC_VER_4_PFC_STATS_SUPPORTED) ?
  8746. BC_SUPPORTS_PFC_STATS : 0;
  8747. bp->flags |= (val >= REQ_BC_VER_4_FCOE_FEATURES) ?
  8748. BC_SUPPORTS_FCOE_FEATURES : 0;
  8749. bp->flags |= (val >= REQ_BC_VER_4_DCBX_ADMIN_MSG_NON_PMF) ?
  8750. BC_SUPPORTS_DCBX_MSG_NON_PMF : 0;
  8751. bp->flags |= (val >= REQ_BC_VER_4_RMMOD_CMD) ?
  8752. BC_SUPPORTS_RMMOD_CMD : 0;
  8753. boot_mode = SHMEM_RD(bp,
  8754. dev_info.port_feature_config[BP_PORT(bp)].mba_config) &
  8755. PORT_FEATURE_MBA_BOOT_AGENT_TYPE_MASK;
  8756. switch (boot_mode) {
  8757. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_PXE:
  8758. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_PXE;
  8759. break;
  8760. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_ISCSIB:
  8761. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_ISCSI;
  8762. break;
  8763. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_FCOE_BOOT:
  8764. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_FCOE;
  8765. break;
  8766. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_NONE:
  8767. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_NONE;
  8768. break;
  8769. }
  8770. pci_read_config_word(bp->pdev, bp->pdev->pm_cap + PCI_PM_PMC, &pmc);
  8771. bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG;
  8772. BNX2X_DEV_INFO("%sWoL capable\n",
  8773. (bp->flags & NO_WOL_FLAG) ? "not " : "");
  8774. val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num);
  8775. val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]);
  8776. val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]);
  8777. val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]);
  8778. dev_info(&bp->pdev->dev, "part number %X-%X-%X-%X\n",
  8779. val, val2, val3, val4);
  8780. }
  8781. #define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID)
  8782. #define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR)
  8783. static int bnx2x_get_igu_cam_info(struct bnx2x *bp)
  8784. {
  8785. int pfid = BP_FUNC(bp);
  8786. int igu_sb_id;
  8787. u32 val;
  8788. u8 fid, igu_sb_cnt = 0;
  8789. bp->igu_base_sb = 0xff;
  8790. if (CHIP_INT_MODE_IS_BC(bp)) {
  8791. int vn = BP_VN(bp);
  8792. igu_sb_cnt = bp->igu_sb_cnt;
  8793. bp->igu_base_sb = (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn) *
  8794. FP_SB_MAX_E1x;
  8795. bp->igu_dsb_id = E1HVN_MAX * FP_SB_MAX_E1x +
  8796. (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn);
  8797. return 0;
  8798. }
  8799. /* IGU in normal mode - read CAM */
  8800. for (igu_sb_id = 0; igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE;
  8801. igu_sb_id++) {
  8802. val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4);
  8803. if (!(val & IGU_REG_MAPPING_MEMORY_VALID))
  8804. continue;
  8805. fid = IGU_FID(val);
  8806. if ((fid & IGU_FID_ENCODE_IS_PF)) {
  8807. if ((fid & IGU_FID_PF_NUM_MASK) != pfid)
  8808. continue;
  8809. if (IGU_VEC(val) == 0)
  8810. /* default status block */
  8811. bp->igu_dsb_id = igu_sb_id;
  8812. else {
  8813. if (bp->igu_base_sb == 0xff)
  8814. bp->igu_base_sb = igu_sb_id;
  8815. igu_sb_cnt++;
  8816. }
  8817. }
  8818. }
  8819. #ifdef CONFIG_PCI_MSI
  8820. /* Due to new PF resource allocation by MFW T7.4 and above, it's
  8821. * optional that number of CAM entries will not be equal to the value
  8822. * advertised in PCI.
  8823. * Driver should use the minimal value of both as the actual status
  8824. * block count
  8825. */
  8826. bp->igu_sb_cnt = min_t(int, bp->igu_sb_cnt, igu_sb_cnt);
  8827. #endif
  8828. if (igu_sb_cnt == 0) {
  8829. BNX2X_ERR("CAM configuration error\n");
  8830. return -EINVAL;
  8831. }
  8832. return 0;
  8833. }
  8834. static void bnx2x_link_settings_supported(struct bnx2x *bp, u32 switch_cfg)
  8835. {
  8836. int cfg_size = 0, idx, port = BP_PORT(bp);
  8837. /* Aggregation of supported attributes of all external phys */
  8838. bp->port.supported[0] = 0;
  8839. bp->port.supported[1] = 0;
  8840. switch (bp->link_params.num_phys) {
  8841. case 1:
  8842. bp->port.supported[0] = bp->link_params.phy[INT_PHY].supported;
  8843. cfg_size = 1;
  8844. break;
  8845. case 2:
  8846. bp->port.supported[0] = bp->link_params.phy[EXT_PHY1].supported;
  8847. cfg_size = 1;
  8848. break;
  8849. case 3:
  8850. if (bp->link_params.multi_phy_config &
  8851. PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
  8852. bp->port.supported[1] =
  8853. bp->link_params.phy[EXT_PHY1].supported;
  8854. bp->port.supported[0] =
  8855. bp->link_params.phy[EXT_PHY2].supported;
  8856. } else {
  8857. bp->port.supported[0] =
  8858. bp->link_params.phy[EXT_PHY1].supported;
  8859. bp->port.supported[1] =
  8860. bp->link_params.phy[EXT_PHY2].supported;
  8861. }
  8862. cfg_size = 2;
  8863. break;
  8864. }
  8865. if (!(bp->port.supported[0] || bp->port.supported[1])) {
  8866. BNX2X_ERR("NVRAM config error. BAD phy config. PHY1 config 0x%x, PHY2 config 0x%x\n",
  8867. SHMEM_RD(bp,
  8868. dev_info.port_hw_config[port].external_phy_config),
  8869. SHMEM_RD(bp,
  8870. dev_info.port_hw_config[port].external_phy_config2));
  8871. return;
  8872. }
  8873. if (CHIP_IS_E3(bp))
  8874. bp->port.phy_addr = REG_RD(bp, MISC_REG_WC0_CTRL_PHY_ADDR);
  8875. else {
  8876. switch (switch_cfg) {
  8877. case SWITCH_CFG_1G:
  8878. bp->port.phy_addr = REG_RD(
  8879. bp, NIG_REG_SERDES0_CTRL_PHY_ADDR + port*0x10);
  8880. break;
  8881. case SWITCH_CFG_10G:
  8882. bp->port.phy_addr = REG_RD(
  8883. bp, NIG_REG_XGXS0_CTRL_PHY_ADDR + port*0x18);
  8884. break;
  8885. default:
  8886. BNX2X_ERR("BAD switch_cfg link_config 0x%x\n",
  8887. bp->port.link_config[0]);
  8888. return;
  8889. }
  8890. }
  8891. BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
  8892. /* mask what we support according to speed_cap_mask per configuration */
  8893. for (idx = 0; idx < cfg_size; idx++) {
  8894. if (!(bp->link_params.speed_cap_mask[idx] &
  8895. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF))
  8896. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Half;
  8897. if (!(bp->link_params.speed_cap_mask[idx] &
  8898. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL))
  8899. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Full;
  8900. if (!(bp->link_params.speed_cap_mask[idx] &
  8901. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF))
  8902. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Half;
  8903. if (!(bp->link_params.speed_cap_mask[idx] &
  8904. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL))
  8905. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Full;
  8906. if (!(bp->link_params.speed_cap_mask[idx] &
  8907. PORT_HW_CFG_SPEED_CAPABILITY_D0_1G))
  8908. bp->port.supported[idx] &= ~(SUPPORTED_1000baseT_Half |
  8909. SUPPORTED_1000baseT_Full);
  8910. if (!(bp->link_params.speed_cap_mask[idx] &
  8911. PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
  8912. bp->port.supported[idx] &= ~SUPPORTED_2500baseX_Full;
  8913. if (!(bp->link_params.speed_cap_mask[idx] &
  8914. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G))
  8915. bp->port.supported[idx] &= ~SUPPORTED_10000baseT_Full;
  8916. if (!(bp->link_params.speed_cap_mask[idx] &
  8917. PORT_HW_CFG_SPEED_CAPABILITY_D0_20G))
  8918. bp->port.supported[idx] &= ~SUPPORTED_20000baseKR2_Full;
  8919. }
  8920. BNX2X_DEV_INFO("supported 0x%x 0x%x\n", bp->port.supported[0],
  8921. bp->port.supported[1]);
  8922. }
  8923. static void bnx2x_link_settings_requested(struct bnx2x *bp)
  8924. {
  8925. u32 link_config, idx, cfg_size = 0;
  8926. bp->port.advertising[0] = 0;
  8927. bp->port.advertising[1] = 0;
  8928. switch (bp->link_params.num_phys) {
  8929. case 1:
  8930. case 2:
  8931. cfg_size = 1;
  8932. break;
  8933. case 3:
  8934. cfg_size = 2;
  8935. break;
  8936. }
  8937. for (idx = 0; idx < cfg_size; idx++) {
  8938. bp->link_params.req_duplex[idx] = DUPLEX_FULL;
  8939. link_config = bp->port.link_config[idx];
  8940. switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
  8941. case PORT_FEATURE_LINK_SPEED_AUTO:
  8942. if (bp->port.supported[idx] & SUPPORTED_Autoneg) {
  8943. bp->link_params.req_line_speed[idx] =
  8944. SPEED_AUTO_NEG;
  8945. bp->port.advertising[idx] |=
  8946. bp->port.supported[idx];
  8947. if (bp->link_params.phy[EXT_PHY1].type ==
  8948. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
  8949. bp->port.advertising[idx] |=
  8950. (SUPPORTED_100baseT_Half |
  8951. SUPPORTED_100baseT_Full);
  8952. } else {
  8953. /* force 10G, no AN */
  8954. bp->link_params.req_line_speed[idx] =
  8955. SPEED_10000;
  8956. bp->port.advertising[idx] |=
  8957. (ADVERTISED_10000baseT_Full |
  8958. ADVERTISED_FIBRE);
  8959. continue;
  8960. }
  8961. break;
  8962. case PORT_FEATURE_LINK_SPEED_10M_FULL:
  8963. if (bp->port.supported[idx] & SUPPORTED_10baseT_Full) {
  8964. bp->link_params.req_line_speed[idx] =
  8965. SPEED_10;
  8966. bp->port.advertising[idx] |=
  8967. (ADVERTISED_10baseT_Full |
  8968. ADVERTISED_TP);
  8969. } else {
  8970. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8971. link_config,
  8972. bp->link_params.speed_cap_mask[idx]);
  8973. return;
  8974. }
  8975. break;
  8976. case PORT_FEATURE_LINK_SPEED_10M_HALF:
  8977. if (bp->port.supported[idx] & SUPPORTED_10baseT_Half) {
  8978. bp->link_params.req_line_speed[idx] =
  8979. SPEED_10;
  8980. bp->link_params.req_duplex[idx] =
  8981. DUPLEX_HALF;
  8982. bp->port.advertising[idx] |=
  8983. (ADVERTISED_10baseT_Half |
  8984. ADVERTISED_TP);
  8985. } else {
  8986. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8987. link_config,
  8988. bp->link_params.speed_cap_mask[idx]);
  8989. return;
  8990. }
  8991. break;
  8992. case PORT_FEATURE_LINK_SPEED_100M_FULL:
  8993. if (bp->port.supported[idx] &
  8994. SUPPORTED_100baseT_Full) {
  8995. bp->link_params.req_line_speed[idx] =
  8996. SPEED_100;
  8997. bp->port.advertising[idx] |=
  8998. (ADVERTISED_100baseT_Full |
  8999. ADVERTISED_TP);
  9000. } else {
  9001. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9002. link_config,
  9003. bp->link_params.speed_cap_mask[idx]);
  9004. return;
  9005. }
  9006. break;
  9007. case PORT_FEATURE_LINK_SPEED_100M_HALF:
  9008. if (bp->port.supported[idx] &
  9009. SUPPORTED_100baseT_Half) {
  9010. bp->link_params.req_line_speed[idx] =
  9011. SPEED_100;
  9012. bp->link_params.req_duplex[idx] =
  9013. DUPLEX_HALF;
  9014. bp->port.advertising[idx] |=
  9015. (ADVERTISED_100baseT_Half |
  9016. ADVERTISED_TP);
  9017. } else {
  9018. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9019. link_config,
  9020. bp->link_params.speed_cap_mask[idx]);
  9021. return;
  9022. }
  9023. break;
  9024. case PORT_FEATURE_LINK_SPEED_1G:
  9025. if (bp->port.supported[idx] &
  9026. SUPPORTED_1000baseT_Full) {
  9027. bp->link_params.req_line_speed[idx] =
  9028. SPEED_1000;
  9029. bp->port.advertising[idx] |=
  9030. (ADVERTISED_1000baseT_Full |
  9031. ADVERTISED_TP);
  9032. } else {
  9033. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9034. link_config,
  9035. bp->link_params.speed_cap_mask[idx]);
  9036. return;
  9037. }
  9038. break;
  9039. case PORT_FEATURE_LINK_SPEED_2_5G:
  9040. if (bp->port.supported[idx] &
  9041. SUPPORTED_2500baseX_Full) {
  9042. bp->link_params.req_line_speed[idx] =
  9043. SPEED_2500;
  9044. bp->port.advertising[idx] |=
  9045. (ADVERTISED_2500baseX_Full |
  9046. ADVERTISED_TP);
  9047. } else {
  9048. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9049. link_config,
  9050. bp->link_params.speed_cap_mask[idx]);
  9051. return;
  9052. }
  9053. break;
  9054. case PORT_FEATURE_LINK_SPEED_10G_CX4:
  9055. if (bp->port.supported[idx] &
  9056. SUPPORTED_10000baseT_Full) {
  9057. bp->link_params.req_line_speed[idx] =
  9058. SPEED_10000;
  9059. bp->port.advertising[idx] |=
  9060. (ADVERTISED_10000baseT_Full |
  9061. ADVERTISED_FIBRE);
  9062. } else {
  9063. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9064. link_config,
  9065. bp->link_params.speed_cap_mask[idx]);
  9066. return;
  9067. }
  9068. break;
  9069. case PORT_FEATURE_LINK_SPEED_20G:
  9070. bp->link_params.req_line_speed[idx] = SPEED_20000;
  9071. break;
  9072. default:
  9073. BNX2X_ERR("NVRAM config error. BAD link speed link_config 0x%x\n",
  9074. link_config);
  9075. bp->link_params.req_line_speed[idx] =
  9076. SPEED_AUTO_NEG;
  9077. bp->port.advertising[idx] =
  9078. bp->port.supported[idx];
  9079. break;
  9080. }
  9081. bp->link_params.req_flow_ctrl[idx] = (link_config &
  9082. PORT_FEATURE_FLOW_CONTROL_MASK);
  9083. if (bp->link_params.req_flow_ctrl[idx] ==
  9084. BNX2X_FLOW_CTRL_AUTO) {
  9085. if (!(bp->port.supported[idx] & SUPPORTED_Autoneg))
  9086. bp->link_params.req_flow_ctrl[idx] =
  9087. BNX2X_FLOW_CTRL_NONE;
  9088. else
  9089. bnx2x_set_requested_fc(bp);
  9090. }
  9091. BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl 0x%x advertising 0x%x\n",
  9092. bp->link_params.req_line_speed[idx],
  9093. bp->link_params.req_duplex[idx],
  9094. bp->link_params.req_flow_ctrl[idx],
  9095. bp->port.advertising[idx]);
  9096. }
  9097. }
  9098. static void bnx2x_set_mac_buf(u8 *mac_buf, u32 mac_lo, u16 mac_hi)
  9099. {
  9100. __be16 mac_hi_be = cpu_to_be16(mac_hi);
  9101. __be32 mac_lo_be = cpu_to_be32(mac_lo);
  9102. memcpy(mac_buf, &mac_hi_be, sizeof(mac_hi_be));
  9103. memcpy(mac_buf + sizeof(mac_hi_be), &mac_lo_be, sizeof(mac_lo_be));
  9104. }
  9105. static void bnx2x_get_port_hwinfo(struct bnx2x *bp)
  9106. {
  9107. int port = BP_PORT(bp);
  9108. u32 config;
  9109. u32 ext_phy_type, ext_phy_config, eee_mode;
  9110. bp->link_params.bp = bp;
  9111. bp->link_params.port = port;
  9112. bp->link_params.lane_config =
  9113. SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config);
  9114. bp->link_params.speed_cap_mask[0] =
  9115. SHMEM_RD(bp,
  9116. dev_info.port_hw_config[port].speed_capability_mask) &
  9117. PORT_HW_CFG_SPEED_CAPABILITY_D0_MASK;
  9118. bp->link_params.speed_cap_mask[1] =
  9119. SHMEM_RD(bp,
  9120. dev_info.port_hw_config[port].speed_capability_mask2) &
  9121. PORT_HW_CFG_SPEED_CAPABILITY_D0_MASK;
  9122. bp->port.link_config[0] =
  9123. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config);
  9124. bp->port.link_config[1] =
  9125. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config2);
  9126. bp->link_params.multi_phy_config =
  9127. SHMEM_RD(bp, dev_info.port_hw_config[port].multi_phy_config);
  9128. /* If the device is capable of WoL, set the default state according
  9129. * to the HW
  9130. */
  9131. config = SHMEM_RD(bp, dev_info.port_feature_config[port].config);
  9132. bp->wol = (!(bp->flags & NO_WOL_FLAG) &&
  9133. (config & PORT_FEATURE_WOL_ENABLED));
  9134. if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) ==
  9135. PORT_FEAT_CFG_STORAGE_PERSONALITY_FCOE && !IS_MF(bp))
  9136. bp->flags |= NO_ISCSI_FLAG;
  9137. if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) ==
  9138. PORT_FEAT_CFG_STORAGE_PERSONALITY_ISCSI && !(IS_MF(bp)))
  9139. bp->flags |= NO_FCOE_FLAG;
  9140. BNX2X_DEV_INFO("lane_config 0x%08x speed_cap_mask0 0x%08x link_config0 0x%08x\n",
  9141. bp->link_params.lane_config,
  9142. bp->link_params.speed_cap_mask[0],
  9143. bp->port.link_config[0]);
  9144. bp->link_params.switch_cfg = (bp->port.link_config[0] &
  9145. PORT_FEATURE_CONNECTED_SWITCH_MASK);
  9146. bnx2x_phy_probe(&bp->link_params);
  9147. bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg);
  9148. bnx2x_link_settings_requested(bp);
  9149. /*
  9150. * If connected directly, work with the internal PHY, otherwise, work
  9151. * with the external PHY
  9152. */
  9153. ext_phy_config =
  9154. SHMEM_RD(bp,
  9155. dev_info.port_hw_config[port].external_phy_config);
  9156. ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
  9157. if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
  9158. bp->mdio.prtad = bp->port.phy_addr;
  9159. else if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) &&
  9160. (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
  9161. bp->mdio.prtad =
  9162. XGXS_EXT_PHY_ADDR(ext_phy_config);
  9163. /* Configure link feature according to nvram value */
  9164. eee_mode = (((SHMEM_RD(bp, dev_info.
  9165. port_feature_config[port].eee_power_mode)) &
  9166. PORT_FEAT_CFG_EEE_POWER_MODE_MASK) >>
  9167. PORT_FEAT_CFG_EEE_POWER_MODE_SHIFT);
  9168. if (eee_mode != PORT_FEAT_CFG_EEE_POWER_MODE_DISABLED) {
  9169. bp->link_params.eee_mode = EEE_MODE_ADV_LPI |
  9170. EEE_MODE_ENABLE_LPI |
  9171. EEE_MODE_OUTPUT_TIME;
  9172. } else {
  9173. bp->link_params.eee_mode = 0;
  9174. }
  9175. }
  9176. void bnx2x_get_iscsi_info(struct bnx2x *bp)
  9177. {
  9178. u32 no_flags = NO_ISCSI_FLAG;
  9179. int port = BP_PORT(bp);
  9180. u32 max_iscsi_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  9181. drv_lic_key[port].max_iscsi_conn);
  9182. if (!CNIC_SUPPORT(bp)) {
  9183. bp->flags |= no_flags;
  9184. return;
  9185. }
  9186. /* Get the number of maximum allowed iSCSI connections */
  9187. bp->cnic_eth_dev.max_iscsi_conn =
  9188. (max_iscsi_conn & BNX2X_MAX_ISCSI_INIT_CONN_MASK) >>
  9189. BNX2X_MAX_ISCSI_INIT_CONN_SHIFT;
  9190. BNX2X_DEV_INFO("max_iscsi_conn 0x%x\n",
  9191. bp->cnic_eth_dev.max_iscsi_conn);
  9192. /*
  9193. * If maximum allowed number of connections is zero -
  9194. * disable the feature.
  9195. */
  9196. if (!bp->cnic_eth_dev.max_iscsi_conn)
  9197. bp->flags |= no_flags;
  9198. }
  9199. static void bnx2x_get_ext_wwn_info(struct bnx2x *bp, int func)
  9200. {
  9201. /* Port info */
  9202. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  9203. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_upper);
  9204. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  9205. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_lower);
  9206. /* Node info */
  9207. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  9208. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_upper);
  9209. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  9210. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_lower);
  9211. }
  9212. static int bnx2x_shared_fcoe_funcs(struct bnx2x *bp)
  9213. {
  9214. u8 count = 0;
  9215. if (IS_MF(bp)) {
  9216. u8 fid;
  9217. /* iterate over absolute function ids for this path: */
  9218. for (fid = BP_PATH(bp); fid < E2_FUNC_MAX * 2; fid += 2) {
  9219. if (IS_MF_SD(bp)) {
  9220. u32 cfg = MF_CFG_RD(bp,
  9221. func_mf_config[fid].config);
  9222. if (!(cfg & FUNC_MF_CFG_FUNC_HIDE) &&
  9223. ((cfg & FUNC_MF_CFG_PROTOCOL_MASK) ==
  9224. FUNC_MF_CFG_PROTOCOL_FCOE))
  9225. count++;
  9226. } else {
  9227. u32 cfg = MF_CFG_RD(bp,
  9228. func_ext_config[fid].
  9229. func_cfg);
  9230. if ((cfg & MACP_FUNC_CFG_FLAGS_ENABLED) &&
  9231. (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD))
  9232. count++;
  9233. }
  9234. }
  9235. } else { /* SF */
  9236. int port, port_cnt = CHIP_MODE_IS_4_PORT(bp) ? 2 : 1;
  9237. for (port = 0; port < port_cnt; port++) {
  9238. u32 lic = SHMEM_RD(bp,
  9239. drv_lic_key[port].max_fcoe_conn) ^
  9240. FW_ENCODE_32BIT_PATTERN;
  9241. if (lic)
  9242. count++;
  9243. }
  9244. }
  9245. return count;
  9246. }
  9247. static void bnx2x_get_fcoe_info(struct bnx2x *bp)
  9248. {
  9249. int port = BP_PORT(bp);
  9250. int func = BP_ABS_FUNC(bp);
  9251. u32 max_fcoe_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  9252. drv_lic_key[port].max_fcoe_conn);
  9253. u8 num_fcoe_func = bnx2x_shared_fcoe_funcs(bp);
  9254. if (!CNIC_SUPPORT(bp)) {
  9255. bp->flags |= NO_FCOE_FLAG;
  9256. return;
  9257. }
  9258. /* Get the number of maximum allowed FCoE connections */
  9259. bp->cnic_eth_dev.max_fcoe_conn =
  9260. (max_fcoe_conn & BNX2X_MAX_FCOE_INIT_CONN_MASK) >>
  9261. BNX2X_MAX_FCOE_INIT_CONN_SHIFT;
  9262. /* Calculate the number of maximum allowed FCoE tasks */
  9263. bp->cnic_eth_dev.max_fcoe_exchanges = MAX_NUM_FCOE_TASKS_PER_ENGINE;
  9264. /* check if FCoE resources must be shared between different functions */
  9265. if (num_fcoe_func)
  9266. bp->cnic_eth_dev.max_fcoe_exchanges /= num_fcoe_func;
  9267. /* Read the WWN: */
  9268. if (!IS_MF(bp)) {
  9269. /* Port info */
  9270. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  9271. SHMEM_RD(bp,
  9272. dev_info.port_hw_config[port].
  9273. fcoe_wwn_port_name_upper);
  9274. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  9275. SHMEM_RD(bp,
  9276. dev_info.port_hw_config[port].
  9277. fcoe_wwn_port_name_lower);
  9278. /* Node info */
  9279. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  9280. SHMEM_RD(bp,
  9281. dev_info.port_hw_config[port].
  9282. fcoe_wwn_node_name_upper);
  9283. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  9284. SHMEM_RD(bp,
  9285. dev_info.port_hw_config[port].
  9286. fcoe_wwn_node_name_lower);
  9287. } else if (!IS_MF_SD(bp)) {
  9288. /*
  9289. * Read the WWN info only if the FCoE feature is enabled for
  9290. * this function.
  9291. */
  9292. if (BNX2X_MF_EXT_PROTOCOL_FCOE(bp) && !CHIP_IS_E1x(bp))
  9293. bnx2x_get_ext_wwn_info(bp, func);
  9294. } else if (IS_MF_FCOE_SD(bp) && !CHIP_IS_E1x(bp)) {
  9295. bnx2x_get_ext_wwn_info(bp, func);
  9296. }
  9297. BNX2X_DEV_INFO("max_fcoe_conn 0x%x\n", bp->cnic_eth_dev.max_fcoe_conn);
  9298. /*
  9299. * If maximum allowed number of connections is zero -
  9300. * disable the feature.
  9301. */
  9302. if (!bp->cnic_eth_dev.max_fcoe_conn)
  9303. bp->flags |= NO_FCOE_FLAG;
  9304. }
  9305. static void bnx2x_get_cnic_info(struct bnx2x *bp)
  9306. {
  9307. /*
  9308. * iSCSI may be dynamically disabled but reading
  9309. * info here we will decrease memory usage by driver
  9310. * if the feature is disabled for good
  9311. */
  9312. bnx2x_get_iscsi_info(bp);
  9313. bnx2x_get_fcoe_info(bp);
  9314. }
  9315. static void bnx2x_get_cnic_mac_hwinfo(struct bnx2x *bp)
  9316. {
  9317. u32 val, val2;
  9318. int func = BP_ABS_FUNC(bp);
  9319. int port = BP_PORT(bp);
  9320. u8 *iscsi_mac = bp->cnic_eth_dev.iscsi_mac;
  9321. u8 *fip_mac = bp->fip_mac;
  9322. if (IS_MF(bp)) {
  9323. /* iSCSI and FCoE NPAR MACs: if there is no either iSCSI or
  9324. * FCoE MAC then the appropriate feature should be disabled.
  9325. * In non SD mode features configuration comes from struct
  9326. * func_ext_config.
  9327. */
  9328. if (!IS_MF_SD(bp) && !CHIP_IS_E1x(bp)) {
  9329. u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
  9330. if (cfg & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) {
  9331. val2 = MF_CFG_RD(bp, func_ext_config[func].
  9332. iscsi_mac_addr_upper);
  9333. val = MF_CFG_RD(bp, func_ext_config[func].
  9334. iscsi_mac_addr_lower);
  9335. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  9336. BNX2X_DEV_INFO
  9337. ("Read iSCSI MAC: %pM\n", iscsi_mac);
  9338. } else {
  9339. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  9340. }
  9341. if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) {
  9342. val2 = MF_CFG_RD(bp, func_ext_config[func].
  9343. fcoe_mac_addr_upper);
  9344. val = MF_CFG_RD(bp, func_ext_config[func].
  9345. fcoe_mac_addr_lower);
  9346. bnx2x_set_mac_buf(fip_mac, val, val2);
  9347. BNX2X_DEV_INFO
  9348. ("Read FCoE L2 MAC: %pM\n", fip_mac);
  9349. } else {
  9350. bp->flags |= NO_FCOE_FLAG;
  9351. }
  9352. bp->mf_ext_config = cfg;
  9353. } else { /* SD MODE */
  9354. if (BNX2X_IS_MF_SD_PROTOCOL_ISCSI(bp)) {
  9355. /* use primary mac as iscsi mac */
  9356. memcpy(iscsi_mac, bp->dev->dev_addr, ETH_ALEN);
  9357. BNX2X_DEV_INFO("SD ISCSI MODE\n");
  9358. BNX2X_DEV_INFO
  9359. ("Read iSCSI MAC: %pM\n", iscsi_mac);
  9360. } else if (BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp)) {
  9361. /* use primary mac as fip mac */
  9362. memcpy(fip_mac, bp->dev->dev_addr, ETH_ALEN);
  9363. BNX2X_DEV_INFO("SD FCoE MODE\n");
  9364. BNX2X_DEV_INFO
  9365. ("Read FIP MAC: %pM\n", fip_mac);
  9366. }
  9367. }
  9368. /* If this is a storage-only interface, use SAN mac as
  9369. * primary MAC. Notice that for SD this is already the case,
  9370. * as the SAN mac was copied from the primary MAC.
  9371. */
  9372. if (IS_MF_FCOE_AFEX(bp))
  9373. memcpy(bp->dev->dev_addr, fip_mac, ETH_ALEN);
  9374. } else {
  9375. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9376. iscsi_mac_upper);
  9377. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9378. iscsi_mac_lower);
  9379. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  9380. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9381. fcoe_fip_mac_upper);
  9382. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9383. fcoe_fip_mac_lower);
  9384. bnx2x_set_mac_buf(fip_mac, val, val2);
  9385. }
  9386. /* Disable iSCSI OOO if MAC configuration is invalid. */
  9387. if (!is_valid_ether_addr(iscsi_mac)) {
  9388. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  9389. memset(iscsi_mac, 0, ETH_ALEN);
  9390. }
  9391. /* Disable FCoE if MAC configuration is invalid. */
  9392. if (!is_valid_ether_addr(fip_mac)) {
  9393. bp->flags |= NO_FCOE_FLAG;
  9394. memset(bp->fip_mac, 0, ETH_ALEN);
  9395. }
  9396. }
  9397. static void bnx2x_get_mac_hwinfo(struct bnx2x *bp)
  9398. {
  9399. u32 val, val2;
  9400. int func = BP_ABS_FUNC(bp);
  9401. int port = BP_PORT(bp);
  9402. /* Zero primary MAC configuration */
  9403. memset(bp->dev->dev_addr, 0, ETH_ALEN);
  9404. if (BP_NOMCP(bp)) {
  9405. BNX2X_ERROR("warning: random MAC workaround active\n");
  9406. eth_hw_addr_random(bp->dev);
  9407. } else if (IS_MF(bp)) {
  9408. val2 = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
  9409. val = MF_CFG_RD(bp, func_mf_config[func].mac_lower);
  9410. if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) &&
  9411. (val != FUNC_MF_CFG_LOWERMAC_DEFAULT))
  9412. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  9413. if (CNIC_SUPPORT(bp))
  9414. bnx2x_get_cnic_mac_hwinfo(bp);
  9415. } else {
  9416. /* in SF read MACs from port configuration */
  9417. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
  9418. val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
  9419. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  9420. if (CNIC_SUPPORT(bp))
  9421. bnx2x_get_cnic_mac_hwinfo(bp);
  9422. }
  9423. if (!BP_NOMCP(bp)) {
  9424. /* Read physical port identifier from shmem */
  9425. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
  9426. val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
  9427. bnx2x_set_mac_buf(bp->phys_port_id, val, val2);
  9428. bp->flags |= HAS_PHYS_PORT_ID;
  9429. }
  9430. memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN);
  9431. if (!bnx2x_is_valid_ether_addr(bp, bp->dev->dev_addr))
  9432. dev_err(&bp->pdev->dev,
  9433. "bad Ethernet MAC address configuration: %pM\n"
  9434. "change it manually before bringing up the appropriate network interface\n",
  9435. bp->dev->dev_addr);
  9436. }
  9437. static bool bnx2x_get_dropless_info(struct bnx2x *bp)
  9438. {
  9439. int tmp;
  9440. u32 cfg;
  9441. if (IS_VF(bp))
  9442. return 0;
  9443. if (IS_MF(bp) && !CHIP_IS_E1x(bp)) {
  9444. /* Take function: tmp = func */
  9445. tmp = BP_ABS_FUNC(bp);
  9446. cfg = MF_CFG_RD(bp, func_ext_config[tmp].func_cfg);
  9447. cfg = !!(cfg & MACP_FUNC_CFG_PAUSE_ON_HOST_RING);
  9448. } else {
  9449. /* Take port: tmp = port */
  9450. tmp = BP_PORT(bp);
  9451. cfg = SHMEM_RD(bp,
  9452. dev_info.port_hw_config[tmp].generic_features);
  9453. cfg = !!(cfg & PORT_HW_CFG_PAUSE_ON_HOST_RING_ENABLED);
  9454. }
  9455. return cfg;
  9456. }
  9457. static int bnx2x_get_hwinfo(struct bnx2x *bp)
  9458. {
  9459. int /*abs*/func = BP_ABS_FUNC(bp);
  9460. int vn;
  9461. u32 val = 0;
  9462. int rc = 0;
  9463. bnx2x_get_common_hwinfo(bp);
  9464. /*
  9465. * initialize IGU parameters
  9466. */
  9467. if (CHIP_IS_E1x(bp)) {
  9468. bp->common.int_block = INT_BLOCK_HC;
  9469. bp->igu_dsb_id = DEF_SB_IGU_ID;
  9470. bp->igu_base_sb = 0;
  9471. } else {
  9472. bp->common.int_block = INT_BLOCK_IGU;
  9473. /* do not allow device reset during IGU info processing */
  9474. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  9475. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  9476. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  9477. int tout = 5000;
  9478. BNX2X_DEV_INFO("FORCING Normal Mode\n");
  9479. val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN);
  9480. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION, val);
  9481. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x7f);
  9482. while (tout && REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  9483. tout--;
  9484. usleep_range(1000, 2000);
  9485. }
  9486. if (REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  9487. dev_err(&bp->pdev->dev,
  9488. "FORCING Normal Mode failed!!!\n");
  9489. bnx2x_release_hw_lock(bp,
  9490. HW_LOCK_RESOURCE_RESET);
  9491. return -EPERM;
  9492. }
  9493. }
  9494. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  9495. BNX2X_DEV_INFO("IGU Backward Compatible Mode\n");
  9496. bp->common.int_block |= INT_BLOCK_MODE_BW_COMP;
  9497. } else
  9498. BNX2X_DEV_INFO("IGU Normal Mode\n");
  9499. rc = bnx2x_get_igu_cam_info(bp);
  9500. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  9501. if (rc)
  9502. return rc;
  9503. }
  9504. /*
  9505. * set base FW non-default (fast path) status block id, this value is
  9506. * used to initialize the fw_sb_id saved on the fp/queue structure to
  9507. * determine the id used by the FW.
  9508. */
  9509. if (CHIP_IS_E1x(bp))
  9510. bp->base_fw_ndsb = BP_PORT(bp) * FP_SB_MAX_E1x + BP_L_ID(bp);
  9511. else /*
  9512. * 57712 - we currently use one FW SB per IGU SB (Rx and Tx of
  9513. * the same queue are indicated on the same IGU SB). So we prefer
  9514. * FW and IGU SBs to be the same value.
  9515. */
  9516. bp->base_fw_ndsb = bp->igu_base_sb;
  9517. BNX2X_DEV_INFO("igu_dsb_id %d igu_base_sb %d igu_sb_cnt %d\n"
  9518. "base_fw_ndsb %d\n", bp->igu_dsb_id, bp->igu_base_sb,
  9519. bp->igu_sb_cnt, bp->base_fw_ndsb);
  9520. /*
  9521. * Initialize MF configuration
  9522. */
  9523. bp->mf_ov = 0;
  9524. bp->mf_mode = 0;
  9525. vn = BP_VN(bp);
  9526. if (!CHIP_IS_E1(bp) && !BP_NOMCP(bp)) {
  9527. BNX2X_DEV_INFO("shmem2base 0x%x, size %d, mfcfg offset %d\n",
  9528. bp->common.shmem2_base, SHMEM2_RD(bp, size),
  9529. (u32)offsetof(struct shmem2_region, mf_cfg_addr));
  9530. if (SHMEM2_HAS(bp, mf_cfg_addr))
  9531. bp->common.mf_cfg_base = SHMEM2_RD(bp, mf_cfg_addr);
  9532. else
  9533. bp->common.mf_cfg_base = bp->common.shmem_base +
  9534. offsetof(struct shmem_region, func_mb) +
  9535. E1H_FUNC_MAX * sizeof(struct drv_func_mb);
  9536. /*
  9537. * get mf configuration:
  9538. * 1. Existence of MF configuration
  9539. * 2. MAC address must be legal (check only upper bytes)
  9540. * for Switch-Independent mode;
  9541. * OVLAN must be legal for Switch-Dependent mode
  9542. * 3. SF_MODE configures specific MF mode
  9543. */
  9544. if (bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  9545. /* get mf configuration */
  9546. val = SHMEM_RD(bp,
  9547. dev_info.shared_feature_config.config);
  9548. val &= SHARED_FEAT_CFG_FORCE_SF_MODE_MASK;
  9549. switch (val) {
  9550. case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT:
  9551. val = MF_CFG_RD(bp, func_mf_config[func].
  9552. mac_upper);
  9553. /* check for legal mac (upper bytes)*/
  9554. if (val != 0xffff) {
  9555. bp->mf_mode = MULTI_FUNCTION_SI;
  9556. bp->mf_config[vn] = MF_CFG_RD(bp,
  9557. func_mf_config[func].config);
  9558. } else
  9559. BNX2X_DEV_INFO("illegal MAC address for SI\n");
  9560. break;
  9561. case SHARED_FEAT_CFG_FORCE_SF_MODE_AFEX_MODE:
  9562. if ((!CHIP_IS_E1x(bp)) &&
  9563. (MF_CFG_RD(bp, func_mf_config[func].
  9564. mac_upper) != 0xffff) &&
  9565. (SHMEM2_HAS(bp,
  9566. afex_driver_support))) {
  9567. bp->mf_mode = MULTI_FUNCTION_AFEX;
  9568. bp->mf_config[vn] = MF_CFG_RD(bp,
  9569. func_mf_config[func].config);
  9570. } else {
  9571. BNX2X_DEV_INFO("can not configure afex mode\n");
  9572. }
  9573. break;
  9574. case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED:
  9575. /* get OV configuration */
  9576. val = MF_CFG_RD(bp,
  9577. func_mf_config[FUNC_0].e1hov_tag);
  9578. val &= FUNC_MF_CFG_E1HOV_TAG_MASK;
  9579. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  9580. bp->mf_mode = MULTI_FUNCTION_SD;
  9581. bp->mf_config[vn] = MF_CFG_RD(bp,
  9582. func_mf_config[func].config);
  9583. } else
  9584. BNX2X_DEV_INFO("illegal OV for SD\n");
  9585. break;
  9586. case SHARED_FEAT_CFG_FORCE_SF_MODE_FORCED_SF:
  9587. bp->mf_config[vn] = 0;
  9588. break;
  9589. default:
  9590. /* Unknown configuration: reset mf_config */
  9591. bp->mf_config[vn] = 0;
  9592. BNX2X_DEV_INFO("unknown MF mode 0x%x\n", val);
  9593. }
  9594. }
  9595. BNX2X_DEV_INFO("%s function mode\n",
  9596. IS_MF(bp) ? "multi" : "single");
  9597. switch (bp->mf_mode) {
  9598. case MULTI_FUNCTION_SD:
  9599. val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  9600. FUNC_MF_CFG_E1HOV_TAG_MASK;
  9601. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  9602. bp->mf_ov = val;
  9603. bp->path_has_ovlan = true;
  9604. BNX2X_DEV_INFO("MF OV for func %d is %d (0x%04x)\n",
  9605. func, bp->mf_ov, bp->mf_ov);
  9606. } else {
  9607. dev_err(&bp->pdev->dev,
  9608. "No valid MF OV for func %d, aborting\n",
  9609. func);
  9610. return -EPERM;
  9611. }
  9612. break;
  9613. case MULTI_FUNCTION_AFEX:
  9614. BNX2X_DEV_INFO("func %d is in MF afex mode\n", func);
  9615. break;
  9616. case MULTI_FUNCTION_SI:
  9617. BNX2X_DEV_INFO("func %d is in MF switch-independent mode\n",
  9618. func);
  9619. break;
  9620. default:
  9621. if (vn) {
  9622. dev_err(&bp->pdev->dev,
  9623. "VN %d is in a single function mode, aborting\n",
  9624. vn);
  9625. return -EPERM;
  9626. }
  9627. break;
  9628. }
  9629. /* check if other port on the path needs ovlan:
  9630. * Since MF configuration is shared between ports
  9631. * Possible mixed modes are only
  9632. * {SF, SI} {SF, SD} {SD, SF} {SI, SF}
  9633. */
  9634. if (CHIP_MODE_IS_4_PORT(bp) &&
  9635. !bp->path_has_ovlan &&
  9636. !IS_MF(bp) &&
  9637. bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  9638. u8 other_port = !BP_PORT(bp);
  9639. u8 other_func = BP_PATH(bp) + 2*other_port;
  9640. val = MF_CFG_RD(bp,
  9641. func_mf_config[other_func].e1hov_tag);
  9642. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT)
  9643. bp->path_has_ovlan = true;
  9644. }
  9645. }
  9646. /* adjust igu_sb_cnt to MF for E1x */
  9647. if (CHIP_IS_E1x(bp) && IS_MF(bp))
  9648. bp->igu_sb_cnt /= E1HVN_MAX;
  9649. /* port info */
  9650. bnx2x_get_port_hwinfo(bp);
  9651. /* Get MAC addresses */
  9652. bnx2x_get_mac_hwinfo(bp);
  9653. bnx2x_get_cnic_info(bp);
  9654. return rc;
  9655. }
  9656. static void bnx2x_read_fwinfo(struct bnx2x *bp)
  9657. {
  9658. int cnt, i, block_end, rodi;
  9659. char vpd_start[BNX2X_VPD_LEN+1];
  9660. char str_id_reg[VENDOR_ID_LEN+1];
  9661. char str_id_cap[VENDOR_ID_LEN+1];
  9662. char *vpd_data;
  9663. char *vpd_extended_data = NULL;
  9664. u8 len;
  9665. cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_start);
  9666. memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
  9667. if (cnt < BNX2X_VPD_LEN)
  9668. goto out_not_found;
  9669. /* VPD RO tag should be first tag after identifier string, hence
  9670. * we should be able to find it in first BNX2X_VPD_LEN chars
  9671. */
  9672. i = pci_vpd_find_tag(vpd_start, 0, BNX2X_VPD_LEN,
  9673. PCI_VPD_LRDT_RO_DATA);
  9674. if (i < 0)
  9675. goto out_not_found;
  9676. block_end = i + PCI_VPD_LRDT_TAG_SIZE +
  9677. pci_vpd_lrdt_size(&vpd_start[i]);
  9678. i += PCI_VPD_LRDT_TAG_SIZE;
  9679. if (block_end > BNX2X_VPD_LEN) {
  9680. vpd_extended_data = kmalloc(block_end, GFP_KERNEL);
  9681. if (vpd_extended_data == NULL)
  9682. goto out_not_found;
  9683. /* read rest of vpd image into vpd_extended_data */
  9684. memcpy(vpd_extended_data, vpd_start, BNX2X_VPD_LEN);
  9685. cnt = pci_read_vpd(bp->pdev, BNX2X_VPD_LEN,
  9686. block_end - BNX2X_VPD_LEN,
  9687. vpd_extended_data + BNX2X_VPD_LEN);
  9688. if (cnt < (block_end - BNX2X_VPD_LEN))
  9689. goto out_not_found;
  9690. vpd_data = vpd_extended_data;
  9691. } else
  9692. vpd_data = vpd_start;
  9693. /* now vpd_data holds full vpd content in both cases */
  9694. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  9695. PCI_VPD_RO_KEYWORD_MFR_ID);
  9696. if (rodi < 0)
  9697. goto out_not_found;
  9698. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  9699. if (len != VENDOR_ID_LEN)
  9700. goto out_not_found;
  9701. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  9702. /* vendor specific info */
  9703. snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL);
  9704. snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL);
  9705. if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) ||
  9706. !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) {
  9707. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  9708. PCI_VPD_RO_KEYWORD_VENDOR0);
  9709. if (rodi >= 0) {
  9710. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  9711. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  9712. if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) {
  9713. memcpy(bp->fw_ver, &vpd_data[rodi], len);
  9714. bp->fw_ver[len] = ' ';
  9715. }
  9716. }
  9717. kfree(vpd_extended_data);
  9718. return;
  9719. }
  9720. out_not_found:
  9721. kfree(vpd_extended_data);
  9722. return;
  9723. }
  9724. static void bnx2x_set_modes_bitmap(struct bnx2x *bp)
  9725. {
  9726. u32 flags = 0;
  9727. if (CHIP_REV_IS_FPGA(bp))
  9728. SET_FLAGS(flags, MODE_FPGA);
  9729. else if (CHIP_REV_IS_EMUL(bp))
  9730. SET_FLAGS(flags, MODE_EMUL);
  9731. else
  9732. SET_FLAGS(flags, MODE_ASIC);
  9733. if (CHIP_MODE_IS_4_PORT(bp))
  9734. SET_FLAGS(flags, MODE_PORT4);
  9735. else
  9736. SET_FLAGS(flags, MODE_PORT2);
  9737. if (CHIP_IS_E2(bp))
  9738. SET_FLAGS(flags, MODE_E2);
  9739. else if (CHIP_IS_E3(bp)) {
  9740. SET_FLAGS(flags, MODE_E3);
  9741. if (CHIP_REV(bp) == CHIP_REV_Ax)
  9742. SET_FLAGS(flags, MODE_E3_A0);
  9743. else /*if (CHIP_REV(bp) == CHIP_REV_Bx)*/
  9744. SET_FLAGS(flags, MODE_E3_B0 | MODE_COS3);
  9745. }
  9746. if (IS_MF(bp)) {
  9747. SET_FLAGS(flags, MODE_MF);
  9748. switch (bp->mf_mode) {
  9749. case MULTI_FUNCTION_SD:
  9750. SET_FLAGS(flags, MODE_MF_SD);
  9751. break;
  9752. case MULTI_FUNCTION_SI:
  9753. SET_FLAGS(flags, MODE_MF_SI);
  9754. break;
  9755. case MULTI_FUNCTION_AFEX:
  9756. SET_FLAGS(flags, MODE_MF_AFEX);
  9757. break;
  9758. }
  9759. } else
  9760. SET_FLAGS(flags, MODE_SF);
  9761. #if defined(__LITTLE_ENDIAN)
  9762. SET_FLAGS(flags, MODE_LITTLE_ENDIAN);
  9763. #else /*(__BIG_ENDIAN)*/
  9764. SET_FLAGS(flags, MODE_BIG_ENDIAN);
  9765. #endif
  9766. INIT_MODE_FLAGS(bp) = flags;
  9767. }
  9768. static int bnx2x_init_bp(struct bnx2x *bp)
  9769. {
  9770. int func;
  9771. int rc;
  9772. mutex_init(&bp->port.phy_mutex);
  9773. mutex_init(&bp->fw_mb_mutex);
  9774. spin_lock_init(&bp->stats_lock);
  9775. sema_init(&bp->stats_sema, 1);
  9776. INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task);
  9777. INIT_DELAYED_WORK(&bp->sp_rtnl_task, bnx2x_sp_rtnl_task);
  9778. INIT_DELAYED_WORK(&bp->period_task, bnx2x_period_task);
  9779. if (IS_PF(bp)) {
  9780. rc = bnx2x_get_hwinfo(bp);
  9781. if (rc)
  9782. return rc;
  9783. } else {
  9784. eth_zero_addr(bp->dev->dev_addr);
  9785. }
  9786. bnx2x_set_modes_bitmap(bp);
  9787. rc = bnx2x_alloc_mem_bp(bp);
  9788. if (rc)
  9789. return rc;
  9790. bnx2x_read_fwinfo(bp);
  9791. func = BP_FUNC(bp);
  9792. /* need to reset chip if undi was active */
  9793. if (IS_PF(bp) && !BP_NOMCP(bp)) {
  9794. /* init fw_seq */
  9795. bp->fw_seq =
  9796. SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
  9797. DRV_MSG_SEQ_NUMBER_MASK;
  9798. BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
  9799. bnx2x_prev_unload(bp);
  9800. }
  9801. if (CHIP_REV_IS_FPGA(bp))
  9802. dev_err(&bp->pdev->dev, "FPGA detected\n");
  9803. if (BP_NOMCP(bp) && (func == 0))
  9804. dev_err(&bp->pdev->dev, "MCP disabled, must load devices in order!\n");
  9805. bp->disable_tpa = disable_tpa;
  9806. bp->disable_tpa |= IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp);
  9807. /* Set TPA flags */
  9808. if (bp->disable_tpa) {
  9809. bp->flags &= ~(TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
  9810. bp->dev->features &= ~NETIF_F_LRO;
  9811. } else {
  9812. bp->flags |= (TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
  9813. bp->dev->features |= NETIF_F_LRO;
  9814. }
  9815. if (CHIP_IS_E1(bp))
  9816. bp->dropless_fc = 0;
  9817. else
  9818. bp->dropless_fc = dropless_fc | bnx2x_get_dropless_info(bp);
  9819. bp->mrrs = mrrs;
  9820. bp->tx_ring_size = IS_MF_FCOE_AFEX(bp) ? 0 : MAX_TX_AVAIL;
  9821. if (IS_VF(bp))
  9822. bp->rx_ring_size = MAX_RX_AVAIL;
  9823. /* make sure that the numbers are in the right granularity */
  9824. bp->tx_ticks = (50 / BNX2X_BTR) * BNX2X_BTR;
  9825. bp->rx_ticks = (25 / BNX2X_BTR) * BNX2X_BTR;
  9826. bp->current_interval = CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ;
  9827. init_timer(&bp->timer);
  9828. bp->timer.expires = jiffies + bp->current_interval;
  9829. bp->timer.data = (unsigned long) bp;
  9830. bp->timer.function = bnx2x_timer;
  9831. if (SHMEM2_HAS(bp, dcbx_lldp_params_offset) &&
  9832. SHMEM2_HAS(bp, dcbx_lldp_dcbx_stat_offset) &&
  9833. SHMEM2_RD(bp, dcbx_lldp_params_offset) &&
  9834. SHMEM2_RD(bp, dcbx_lldp_dcbx_stat_offset)) {
  9835. bnx2x_dcbx_set_state(bp, true, BNX2X_DCBX_ENABLED_ON_NEG_ON);
  9836. bnx2x_dcbx_init_params(bp);
  9837. } else {
  9838. bnx2x_dcbx_set_state(bp, false, BNX2X_DCBX_ENABLED_OFF);
  9839. }
  9840. if (CHIP_IS_E1x(bp))
  9841. bp->cnic_base_cl_id = FP_SB_MAX_E1x;
  9842. else
  9843. bp->cnic_base_cl_id = FP_SB_MAX_E2;
  9844. /* multiple tx priority */
  9845. if (IS_VF(bp))
  9846. bp->max_cos = 1;
  9847. else if (CHIP_IS_E1x(bp))
  9848. bp->max_cos = BNX2X_MULTI_TX_COS_E1X;
  9849. else if (CHIP_IS_E2(bp) || CHIP_IS_E3A0(bp))
  9850. bp->max_cos = BNX2X_MULTI_TX_COS_E2_E3A0;
  9851. else if (CHIP_IS_E3B0(bp))
  9852. bp->max_cos = BNX2X_MULTI_TX_COS_E3B0;
  9853. else
  9854. BNX2X_ERR("unknown chip %x revision %x\n",
  9855. CHIP_NUM(bp), CHIP_REV(bp));
  9856. BNX2X_DEV_INFO("set bp->max_cos to %d\n", bp->max_cos);
  9857. /* We need at least one default status block for slow-path events,
  9858. * second status block for the L2 queue, and a third status block for
  9859. * CNIC if supported.
  9860. */
  9861. if (IS_VF(bp))
  9862. bp->min_msix_vec_cnt = 1;
  9863. else if (CNIC_SUPPORT(bp))
  9864. bp->min_msix_vec_cnt = 3;
  9865. else /* PF w/o cnic */
  9866. bp->min_msix_vec_cnt = 2;
  9867. BNX2X_DEV_INFO("bp->min_msix_vec_cnt %d", bp->min_msix_vec_cnt);
  9868. bp->dump_preset_idx = 1;
  9869. return rc;
  9870. }
  9871. /****************************************************************************
  9872. * General service functions
  9873. ****************************************************************************/
  9874. /*
  9875. * net_device service functions
  9876. */
  9877. /* called with rtnl_lock */
  9878. static int bnx2x_open(struct net_device *dev)
  9879. {
  9880. struct bnx2x *bp = netdev_priv(dev);
  9881. int rc;
  9882. bp->stats_init = true;
  9883. netif_carrier_off(dev);
  9884. bnx2x_set_power_state(bp, PCI_D0);
  9885. /* If parity had happen during the unload, then attentions
  9886. * and/or RECOVERY_IN_PROGRES may still be set. In this case we
  9887. * want the first function loaded on the current engine to
  9888. * complete the recovery.
  9889. * Parity recovery is only relevant for PF driver.
  9890. */
  9891. if (IS_PF(bp)) {
  9892. int other_engine = BP_PATH(bp) ? 0 : 1;
  9893. bool other_load_status, load_status;
  9894. bool global = false;
  9895. other_load_status = bnx2x_get_load_status(bp, other_engine);
  9896. load_status = bnx2x_get_load_status(bp, BP_PATH(bp));
  9897. if (!bnx2x_reset_is_done(bp, BP_PATH(bp)) ||
  9898. bnx2x_chk_parity_attn(bp, &global, true)) {
  9899. do {
  9900. /* If there are attentions and they are in a
  9901. * global blocks, set the GLOBAL_RESET bit
  9902. * regardless whether it will be this function
  9903. * that will complete the recovery or not.
  9904. */
  9905. if (global)
  9906. bnx2x_set_reset_global(bp);
  9907. /* Only the first function on the current
  9908. * engine should try to recover in open. In case
  9909. * of attentions in global blocks only the first
  9910. * in the chip should try to recover.
  9911. */
  9912. if ((!load_status &&
  9913. (!global || !other_load_status)) &&
  9914. bnx2x_trylock_leader_lock(bp) &&
  9915. !bnx2x_leader_reset(bp)) {
  9916. netdev_info(bp->dev,
  9917. "Recovered in open\n");
  9918. break;
  9919. }
  9920. /* recovery has failed... */
  9921. bnx2x_set_power_state(bp, PCI_D3hot);
  9922. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  9923. BNX2X_ERR("Recovery flow hasn't been properly completed yet. Try again later.\n"
  9924. "If you still see this message after a few retries then power cycle is required.\n");
  9925. return -EAGAIN;
  9926. } while (0);
  9927. }
  9928. }
  9929. bp->recovery_state = BNX2X_RECOVERY_DONE;
  9930. rc = bnx2x_nic_load(bp, LOAD_OPEN);
  9931. if (rc)
  9932. return rc;
  9933. return 0;
  9934. }
  9935. /* called with rtnl_lock */
  9936. static int bnx2x_close(struct net_device *dev)
  9937. {
  9938. struct bnx2x *bp = netdev_priv(dev);
  9939. /* Unload the driver, release IRQs */
  9940. bnx2x_nic_unload(bp, UNLOAD_CLOSE, false);
  9941. return 0;
  9942. }
  9943. static int bnx2x_init_mcast_macs_list(struct bnx2x *bp,
  9944. struct bnx2x_mcast_ramrod_params *p)
  9945. {
  9946. int mc_count = netdev_mc_count(bp->dev);
  9947. struct bnx2x_mcast_list_elem *mc_mac =
  9948. kzalloc(sizeof(*mc_mac) * mc_count, GFP_ATOMIC);
  9949. struct netdev_hw_addr *ha;
  9950. if (!mc_mac)
  9951. return -ENOMEM;
  9952. INIT_LIST_HEAD(&p->mcast_list);
  9953. netdev_for_each_mc_addr(ha, bp->dev) {
  9954. mc_mac->mac = bnx2x_mc_addr(ha);
  9955. list_add_tail(&mc_mac->link, &p->mcast_list);
  9956. mc_mac++;
  9957. }
  9958. p->mcast_list_len = mc_count;
  9959. return 0;
  9960. }
  9961. static void bnx2x_free_mcast_macs_list(
  9962. struct bnx2x_mcast_ramrod_params *p)
  9963. {
  9964. struct bnx2x_mcast_list_elem *mc_mac =
  9965. list_first_entry(&p->mcast_list, struct bnx2x_mcast_list_elem,
  9966. link);
  9967. WARN_ON(!mc_mac);
  9968. kfree(mc_mac);
  9969. }
  9970. /**
  9971. * bnx2x_set_uc_list - configure a new unicast MACs list.
  9972. *
  9973. * @bp: driver handle
  9974. *
  9975. * We will use zero (0) as a MAC type for these MACs.
  9976. */
  9977. static int bnx2x_set_uc_list(struct bnx2x *bp)
  9978. {
  9979. int rc;
  9980. struct net_device *dev = bp->dev;
  9981. struct netdev_hw_addr *ha;
  9982. struct bnx2x_vlan_mac_obj *mac_obj = &bp->sp_objs->mac_obj;
  9983. unsigned long ramrod_flags = 0;
  9984. /* First schedule a cleanup up of old configuration */
  9985. rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, false);
  9986. if (rc < 0) {
  9987. BNX2X_ERR("Failed to schedule DELETE operations: %d\n", rc);
  9988. return rc;
  9989. }
  9990. netdev_for_each_uc_addr(ha, dev) {
  9991. rc = bnx2x_set_mac_one(bp, bnx2x_uc_addr(ha), mac_obj, true,
  9992. BNX2X_UC_LIST_MAC, &ramrod_flags);
  9993. if (rc == -EEXIST) {
  9994. DP(BNX2X_MSG_SP,
  9995. "Failed to schedule ADD operations: %d\n", rc);
  9996. /* do not treat adding same MAC as error */
  9997. rc = 0;
  9998. } else if (rc < 0) {
  9999. BNX2X_ERR("Failed to schedule ADD operations: %d\n",
  10000. rc);
  10001. return rc;
  10002. }
  10003. }
  10004. /* Execute the pending commands */
  10005. __set_bit(RAMROD_CONT, &ramrod_flags);
  10006. return bnx2x_set_mac_one(bp, NULL, mac_obj, false /* don't care */,
  10007. BNX2X_UC_LIST_MAC, &ramrod_flags);
  10008. }
  10009. static int bnx2x_set_mc_list(struct bnx2x *bp)
  10010. {
  10011. struct net_device *dev = bp->dev;
  10012. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  10013. int rc = 0;
  10014. rparam.mcast_obj = &bp->mcast_obj;
  10015. /* first, clear all configured multicast MACs */
  10016. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  10017. if (rc < 0) {
  10018. BNX2X_ERR("Failed to clear multicast configuration: %d\n", rc);
  10019. return rc;
  10020. }
  10021. /* then, configure a new MACs list */
  10022. if (netdev_mc_count(dev)) {
  10023. rc = bnx2x_init_mcast_macs_list(bp, &rparam);
  10024. if (rc) {
  10025. BNX2X_ERR("Failed to create multicast MACs list: %d\n",
  10026. rc);
  10027. return rc;
  10028. }
  10029. /* Now add the new MACs */
  10030. rc = bnx2x_config_mcast(bp, &rparam,
  10031. BNX2X_MCAST_CMD_ADD);
  10032. if (rc < 0)
  10033. BNX2X_ERR("Failed to set a new multicast configuration: %d\n",
  10034. rc);
  10035. bnx2x_free_mcast_macs_list(&rparam);
  10036. }
  10037. return rc;
  10038. }
  10039. /* If bp->state is OPEN, should be called with netif_addr_lock_bh() */
  10040. void bnx2x_set_rx_mode(struct net_device *dev)
  10041. {
  10042. struct bnx2x *bp = netdev_priv(dev);
  10043. if (bp->state != BNX2X_STATE_OPEN) {
  10044. DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
  10045. return;
  10046. } else {
  10047. /* Schedule an SP task to handle rest of change */
  10048. DP(NETIF_MSG_IFUP, "Scheduling an Rx mode change\n");
  10049. smp_mb__before_clear_bit();
  10050. set_bit(BNX2X_SP_RTNL_RX_MODE, &bp->sp_rtnl_state);
  10051. smp_mb__after_clear_bit();
  10052. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  10053. }
  10054. }
  10055. void bnx2x_set_rx_mode_inner(struct bnx2x *bp)
  10056. {
  10057. u32 rx_mode = BNX2X_RX_MODE_NORMAL;
  10058. DP(NETIF_MSG_IFUP, "dev->flags = %x\n", bp->dev->flags);
  10059. netif_addr_lock_bh(bp->dev);
  10060. if (bp->dev->flags & IFF_PROMISC) {
  10061. rx_mode = BNX2X_RX_MODE_PROMISC;
  10062. } else if ((bp->dev->flags & IFF_ALLMULTI) ||
  10063. ((netdev_mc_count(bp->dev) > BNX2X_MAX_MULTICAST) &&
  10064. CHIP_IS_E1(bp))) {
  10065. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  10066. } else {
  10067. if (IS_PF(bp)) {
  10068. /* some multicasts */
  10069. if (bnx2x_set_mc_list(bp) < 0)
  10070. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  10071. /* release bh lock, as bnx2x_set_uc_list might sleep */
  10072. netif_addr_unlock_bh(bp->dev);
  10073. if (bnx2x_set_uc_list(bp) < 0)
  10074. rx_mode = BNX2X_RX_MODE_PROMISC;
  10075. netif_addr_lock_bh(bp->dev);
  10076. } else {
  10077. /* configuring mcast to a vf involves sleeping (when we
  10078. * wait for the pf's response).
  10079. */
  10080. smp_mb__before_clear_bit();
  10081. set_bit(BNX2X_SP_RTNL_VFPF_MCAST,
  10082. &bp->sp_rtnl_state);
  10083. smp_mb__after_clear_bit();
  10084. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  10085. }
  10086. }
  10087. bp->rx_mode = rx_mode;
  10088. /* handle ISCSI SD mode */
  10089. if (IS_MF_ISCSI_SD(bp))
  10090. bp->rx_mode = BNX2X_RX_MODE_NONE;
  10091. /* Schedule the rx_mode command */
  10092. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) {
  10093. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  10094. netif_addr_unlock_bh(bp->dev);
  10095. return;
  10096. }
  10097. if (IS_PF(bp)) {
  10098. bnx2x_set_storm_rx_mode(bp);
  10099. netif_addr_unlock_bh(bp->dev);
  10100. } else {
  10101. /* VF will need to request the PF to make this change, and so
  10102. * the VF needs to release the bottom-half lock prior to the
  10103. * request (as it will likely require sleep on the VF side)
  10104. */
  10105. netif_addr_unlock_bh(bp->dev);
  10106. bnx2x_vfpf_storm_rx_mode(bp);
  10107. }
  10108. }
  10109. /* called with rtnl_lock */
  10110. static int bnx2x_mdio_read(struct net_device *netdev, int prtad,
  10111. int devad, u16 addr)
  10112. {
  10113. struct bnx2x *bp = netdev_priv(netdev);
  10114. u16 value;
  10115. int rc;
  10116. DP(NETIF_MSG_LINK, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n",
  10117. prtad, devad, addr);
  10118. /* The HW expects different devad if CL22 is used */
  10119. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  10120. bnx2x_acquire_phy_lock(bp);
  10121. rc = bnx2x_phy_read(&bp->link_params, prtad, devad, addr, &value);
  10122. bnx2x_release_phy_lock(bp);
  10123. DP(NETIF_MSG_LINK, "mdio_read_val 0x%x rc = 0x%x\n", value, rc);
  10124. if (!rc)
  10125. rc = value;
  10126. return rc;
  10127. }
  10128. /* called with rtnl_lock */
  10129. static int bnx2x_mdio_write(struct net_device *netdev, int prtad, int devad,
  10130. u16 addr, u16 value)
  10131. {
  10132. struct bnx2x *bp = netdev_priv(netdev);
  10133. int rc;
  10134. DP(NETIF_MSG_LINK,
  10135. "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x, value 0x%x\n",
  10136. prtad, devad, addr, value);
  10137. /* The HW expects different devad if CL22 is used */
  10138. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  10139. bnx2x_acquire_phy_lock(bp);
  10140. rc = bnx2x_phy_write(&bp->link_params, prtad, devad, addr, value);
  10141. bnx2x_release_phy_lock(bp);
  10142. return rc;
  10143. }
  10144. /* called with rtnl_lock */
  10145. static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  10146. {
  10147. struct bnx2x *bp = netdev_priv(dev);
  10148. struct mii_ioctl_data *mdio = if_mii(ifr);
  10149. DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n",
  10150. mdio->phy_id, mdio->reg_num, mdio->val_in);
  10151. if (!netif_running(dev))
  10152. return -EAGAIN;
  10153. return mdio_mii_ioctl(&bp->mdio, mdio, cmd);
  10154. }
  10155. #ifdef CONFIG_NET_POLL_CONTROLLER
  10156. static void poll_bnx2x(struct net_device *dev)
  10157. {
  10158. struct bnx2x *bp = netdev_priv(dev);
  10159. int i;
  10160. for_each_eth_queue(bp, i) {
  10161. struct bnx2x_fastpath *fp = &bp->fp[i];
  10162. napi_schedule(&bnx2x_fp(bp, fp->index, napi));
  10163. }
  10164. }
  10165. #endif
  10166. static int bnx2x_validate_addr(struct net_device *dev)
  10167. {
  10168. struct bnx2x *bp = netdev_priv(dev);
  10169. /* query the bulletin board for mac address configured by the PF */
  10170. if (IS_VF(bp))
  10171. bnx2x_sample_bulletin(bp);
  10172. if (!bnx2x_is_valid_ether_addr(bp, dev->dev_addr)) {
  10173. BNX2X_ERR("Non-valid Ethernet address\n");
  10174. return -EADDRNOTAVAIL;
  10175. }
  10176. return 0;
  10177. }
  10178. static int bnx2x_get_phys_port_id(struct net_device *netdev,
  10179. struct netdev_phys_port_id *ppid)
  10180. {
  10181. struct bnx2x *bp = netdev_priv(netdev);
  10182. if (!(bp->flags & HAS_PHYS_PORT_ID))
  10183. return -EOPNOTSUPP;
  10184. ppid->id_len = sizeof(bp->phys_port_id);
  10185. memcpy(ppid->id, bp->phys_port_id, ppid->id_len);
  10186. return 0;
  10187. }
  10188. static const struct net_device_ops bnx2x_netdev_ops = {
  10189. .ndo_open = bnx2x_open,
  10190. .ndo_stop = bnx2x_close,
  10191. .ndo_start_xmit = bnx2x_start_xmit,
  10192. .ndo_select_queue = bnx2x_select_queue,
  10193. .ndo_set_rx_mode = bnx2x_set_rx_mode,
  10194. .ndo_set_mac_address = bnx2x_change_mac_addr,
  10195. .ndo_validate_addr = bnx2x_validate_addr,
  10196. .ndo_do_ioctl = bnx2x_ioctl,
  10197. .ndo_change_mtu = bnx2x_change_mtu,
  10198. .ndo_fix_features = bnx2x_fix_features,
  10199. .ndo_set_features = bnx2x_set_features,
  10200. .ndo_tx_timeout = bnx2x_tx_timeout,
  10201. #ifdef CONFIG_NET_POLL_CONTROLLER
  10202. .ndo_poll_controller = poll_bnx2x,
  10203. #endif
  10204. .ndo_setup_tc = bnx2x_setup_tc,
  10205. #ifdef CONFIG_BNX2X_SRIOV
  10206. .ndo_set_vf_mac = bnx2x_set_vf_mac,
  10207. .ndo_set_vf_vlan = bnx2x_set_vf_vlan,
  10208. .ndo_get_vf_config = bnx2x_get_vf_config,
  10209. #endif
  10210. #ifdef NETDEV_FCOE_WWNN
  10211. .ndo_fcoe_get_wwn = bnx2x_fcoe_get_wwn,
  10212. #endif
  10213. #ifdef CONFIG_NET_RX_BUSY_POLL
  10214. .ndo_busy_poll = bnx2x_low_latency_recv,
  10215. #endif
  10216. .ndo_get_phys_port_id = bnx2x_get_phys_port_id,
  10217. };
  10218. static int bnx2x_set_coherency_mask(struct bnx2x *bp)
  10219. {
  10220. struct device *dev = &bp->pdev->dev;
  10221. if (dma_set_mask(dev, DMA_BIT_MASK(64)) == 0) {
  10222. if (dma_set_coherent_mask(dev, DMA_BIT_MASK(64)) != 0) {
  10223. dev_err(dev, "dma_set_coherent_mask failed, aborting\n");
  10224. return -EIO;
  10225. }
  10226. } else if (dma_set_mask(dev, DMA_BIT_MASK(32)) != 0) {
  10227. dev_err(dev, "System does not support DMA, aborting\n");
  10228. return -EIO;
  10229. }
  10230. return 0;
  10231. }
  10232. static int bnx2x_init_dev(struct bnx2x *bp, struct pci_dev *pdev,
  10233. struct net_device *dev, unsigned long board_type)
  10234. {
  10235. int rc;
  10236. u32 pci_cfg_dword;
  10237. bool chip_is_e1x = (board_type == BCM57710 ||
  10238. board_type == BCM57711 ||
  10239. board_type == BCM57711E);
  10240. SET_NETDEV_DEV(dev, &pdev->dev);
  10241. bp->dev = dev;
  10242. bp->pdev = pdev;
  10243. rc = pci_enable_device(pdev);
  10244. if (rc) {
  10245. dev_err(&bp->pdev->dev,
  10246. "Cannot enable PCI device, aborting\n");
  10247. goto err_out;
  10248. }
  10249. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  10250. dev_err(&bp->pdev->dev,
  10251. "Cannot find PCI device base address, aborting\n");
  10252. rc = -ENODEV;
  10253. goto err_out_disable;
  10254. }
  10255. if (IS_PF(bp) && !(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
  10256. dev_err(&bp->pdev->dev, "Cannot find second PCI device base address, aborting\n");
  10257. rc = -ENODEV;
  10258. goto err_out_disable;
  10259. }
  10260. pci_read_config_dword(pdev, PCICFG_REVISION_ID_OFFSET, &pci_cfg_dword);
  10261. if ((pci_cfg_dword & PCICFG_REVESION_ID_MASK) ==
  10262. PCICFG_REVESION_ID_ERROR_VAL) {
  10263. pr_err("PCI device error, probably due to fan failure, aborting\n");
  10264. rc = -ENODEV;
  10265. goto err_out_disable;
  10266. }
  10267. if (atomic_read(&pdev->enable_cnt) == 1) {
  10268. rc = pci_request_regions(pdev, DRV_MODULE_NAME);
  10269. if (rc) {
  10270. dev_err(&bp->pdev->dev,
  10271. "Cannot obtain PCI resources, aborting\n");
  10272. goto err_out_disable;
  10273. }
  10274. pci_set_master(pdev);
  10275. pci_save_state(pdev);
  10276. }
  10277. if (IS_PF(bp)) {
  10278. if (!pdev->pm_cap) {
  10279. dev_err(&bp->pdev->dev,
  10280. "Cannot find power management capability, aborting\n");
  10281. rc = -EIO;
  10282. goto err_out_release;
  10283. }
  10284. }
  10285. if (!pci_is_pcie(pdev)) {
  10286. dev_err(&bp->pdev->dev, "Not PCI Express, aborting\n");
  10287. rc = -EIO;
  10288. goto err_out_release;
  10289. }
  10290. rc = bnx2x_set_coherency_mask(bp);
  10291. if (rc)
  10292. goto err_out_release;
  10293. dev->mem_start = pci_resource_start(pdev, 0);
  10294. dev->base_addr = dev->mem_start;
  10295. dev->mem_end = pci_resource_end(pdev, 0);
  10296. dev->irq = pdev->irq;
  10297. bp->regview = pci_ioremap_bar(pdev, 0);
  10298. if (!bp->regview) {
  10299. dev_err(&bp->pdev->dev,
  10300. "Cannot map register space, aborting\n");
  10301. rc = -ENOMEM;
  10302. goto err_out_release;
  10303. }
  10304. /* In E1/E1H use pci device function given by kernel.
  10305. * In E2/E3 read physical function from ME register since these chips
  10306. * support Physical Device Assignment where kernel BDF maybe arbitrary
  10307. * (depending on hypervisor).
  10308. */
  10309. if (chip_is_e1x) {
  10310. bp->pf_num = PCI_FUNC(pdev->devfn);
  10311. } else {
  10312. /* chip is E2/3*/
  10313. pci_read_config_dword(bp->pdev,
  10314. PCICFG_ME_REGISTER, &pci_cfg_dword);
  10315. bp->pf_num = (u8)((pci_cfg_dword & ME_REG_ABS_PF_NUM) >>
  10316. ME_REG_ABS_PF_NUM_SHIFT);
  10317. }
  10318. BNX2X_DEV_INFO("me reg PF num: %d\n", bp->pf_num);
  10319. /* clean indirect addresses */
  10320. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  10321. PCICFG_VENDOR_ID_OFFSET);
  10322. /*
  10323. * Clean the following indirect addresses for all functions since it
  10324. * is not used by the driver.
  10325. */
  10326. if (IS_PF(bp)) {
  10327. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0, 0);
  10328. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0, 0);
  10329. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0, 0);
  10330. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0, 0);
  10331. if (chip_is_e1x) {
  10332. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F1, 0);
  10333. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F1, 0);
  10334. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F1, 0);
  10335. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F1, 0);
  10336. }
  10337. /* Enable internal target-read (in case we are probed after PF
  10338. * FLR). Must be done prior to any BAR read access. Only for
  10339. * 57712 and up
  10340. */
  10341. if (!chip_is_e1x)
  10342. REG_WR(bp,
  10343. PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  10344. }
  10345. dev->watchdog_timeo = TX_TIMEOUT;
  10346. dev->netdev_ops = &bnx2x_netdev_ops;
  10347. bnx2x_set_ethtool_ops(bp, dev);
  10348. dev->priv_flags |= IFF_UNICAST_FLT;
  10349. dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  10350. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
  10351. NETIF_F_RXCSUM | NETIF_F_LRO | NETIF_F_GRO |
  10352. NETIF_F_RXHASH | NETIF_F_HW_VLAN_CTAG_TX;
  10353. if (!CHIP_IS_E1x(bp)) {
  10354. dev->hw_features |= NETIF_F_GSO_GRE | NETIF_F_GSO_UDP_TUNNEL |
  10355. NETIF_F_GSO_IPIP | NETIF_F_GSO_SIT;
  10356. dev->hw_enc_features =
  10357. NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_SG |
  10358. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
  10359. NETIF_F_GSO_IPIP |
  10360. NETIF_F_GSO_SIT |
  10361. NETIF_F_GSO_GRE | NETIF_F_GSO_UDP_TUNNEL;
  10362. }
  10363. dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  10364. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_HIGHDMA;
  10365. dev->features |= dev->hw_features | NETIF_F_HW_VLAN_CTAG_RX;
  10366. dev->features |= NETIF_F_HIGHDMA;
  10367. /* Add Loopback capability to the device */
  10368. dev->hw_features |= NETIF_F_LOOPBACK;
  10369. #ifdef BCM_DCBNL
  10370. dev->dcbnl_ops = &bnx2x_dcbnl_ops;
  10371. #endif
  10372. /* get_port_hwinfo() will set prtad and mmds properly */
  10373. bp->mdio.prtad = MDIO_PRTAD_NONE;
  10374. bp->mdio.mmds = 0;
  10375. bp->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
  10376. bp->mdio.dev = dev;
  10377. bp->mdio.mdio_read = bnx2x_mdio_read;
  10378. bp->mdio.mdio_write = bnx2x_mdio_write;
  10379. return 0;
  10380. err_out_release:
  10381. if (atomic_read(&pdev->enable_cnt) == 1)
  10382. pci_release_regions(pdev);
  10383. err_out_disable:
  10384. pci_disable_device(pdev);
  10385. err_out:
  10386. return rc;
  10387. }
  10388. static int bnx2x_check_firmware(struct bnx2x *bp)
  10389. {
  10390. const struct firmware *firmware = bp->firmware;
  10391. struct bnx2x_fw_file_hdr *fw_hdr;
  10392. struct bnx2x_fw_file_section *sections;
  10393. u32 offset, len, num_ops;
  10394. __be16 *ops_offsets;
  10395. int i;
  10396. const u8 *fw_ver;
  10397. if (firmware->size < sizeof(struct bnx2x_fw_file_hdr)) {
  10398. BNX2X_ERR("Wrong FW size\n");
  10399. return -EINVAL;
  10400. }
  10401. fw_hdr = (struct bnx2x_fw_file_hdr *)firmware->data;
  10402. sections = (struct bnx2x_fw_file_section *)fw_hdr;
  10403. /* Make sure none of the offsets and sizes make us read beyond
  10404. * the end of the firmware data */
  10405. for (i = 0; i < sizeof(*fw_hdr) / sizeof(*sections); i++) {
  10406. offset = be32_to_cpu(sections[i].offset);
  10407. len = be32_to_cpu(sections[i].len);
  10408. if (offset + len > firmware->size) {
  10409. BNX2X_ERR("Section %d length is out of bounds\n", i);
  10410. return -EINVAL;
  10411. }
  10412. }
  10413. /* Likewise for the init_ops offsets */
  10414. offset = be32_to_cpu(fw_hdr->init_ops_offsets.offset);
  10415. ops_offsets = (__force __be16 *)(firmware->data + offset);
  10416. num_ops = be32_to_cpu(fw_hdr->init_ops.len) / sizeof(struct raw_op);
  10417. for (i = 0; i < be32_to_cpu(fw_hdr->init_ops_offsets.len) / 2; i++) {
  10418. if (be16_to_cpu(ops_offsets[i]) > num_ops) {
  10419. BNX2X_ERR("Section offset %d is out of bounds\n", i);
  10420. return -EINVAL;
  10421. }
  10422. }
  10423. /* Check FW version */
  10424. offset = be32_to_cpu(fw_hdr->fw_version.offset);
  10425. fw_ver = firmware->data + offset;
  10426. if ((fw_ver[0] != BCM_5710_FW_MAJOR_VERSION) ||
  10427. (fw_ver[1] != BCM_5710_FW_MINOR_VERSION) ||
  10428. (fw_ver[2] != BCM_5710_FW_REVISION_VERSION) ||
  10429. (fw_ver[3] != BCM_5710_FW_ENGINEERING_VERSION)) {
  10430. BNX2X_ERR("Bad FW version:%d.%d.%d.%d. Should be %d.%d.%d.%d\n",
  10431. fw_ver[0], fw_ver[1], fw_ver[2], fw_ver[3],
  10432. BCM_5710_FW_MAJOR_VERSION,
  10433. BCM_5710_FW_MINOR_VERSION,
  10434. BCM_5710_FW_REVISION_VERSION,
  10435. BCM_5710_FW_ENGINEERING_VERSION);
  10436. return -EINVAL;
  10437. }
  10438. return 0;
  10439. }
  10440. static void be32_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  10441. {
  10442. const __be32 *source = (const __be32 *)_source;
  10443. u32 *target = (u32 *)_target;
  10444. u32 i;
  10445. for (i = 0; i < n/4; i++)
  10446. target[i] = be32_to_cpu(source[i]);
  10447. }
  10448. /*
  10449. Ops array is stored in the following format:
  10450. {op(8bit), offset(24bit, big endian), data(32bit, big endian)}
  10451. */
  10452. static void bnx2x_prep_ops(const u8 *_source, u8 *_target, u32 n)
  10453. {
  10454. const __be32 *source = (const __be32 *)_source;
  10455. struct raw_op *target = (struct raw_op *)_target;
  10456. u32 i, j, tmp;
  10457. for (i = 0, j = 0; i < n/8; i++, j += 2) {
  10458. tmp = be32_to_cpu(source[j]);
  10459. target[i].op = (tmp >> 24) & 0xff;
  10460. target[i].offset = tmp & 0xffffff;
  10461. target[i].raw_data = be32_to_cpu(source[j + 1]);
  10462. }
  10463. }
  10464. /* IRO array is stored in the following format:
  10465. * {base(24bit), m1(16bit), m2(16bit), m3(16bit), size(16bit) }
  10466. */
  10467. static void bnx2x_prep_iro(const u8 *_source, u8 *_target, u32 n)
  10468. {
  10469. const __be32 *source = (const __be32 *)_source;
  10470. struct iro *target = (struct iro *)_target;
  10471. u32 i, j, tmp;
  10472. for (i = 0, j = 0; i < n/sizeof(struct iro); i++) {
  10473. target[i].base = be32_to_cpu(source[j]);
  10474. j++;
  10475. tmp = be32_to_cpu(source[j]);
  10476. target[i].m1 = (tmp >> 16) & 0xffff;
  10477. target[i].m2 = tmp & 0xffff;
  10478. j++;
  10479. tmp = be32_to_cpu(source[j]);
  10480. target[i].m3 = (tmp >> 16) & 0xffff;
  10481. target[i].size = tmp & 0xffff;
  10482. j++;
  10483. }
  10484. }
  10485. static void be16_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  10486. {
  10487. const __be16 *source = (const __be16 *)_source;
  10488. u16 *target = (u16 *)_target;
  10489. u32 i;
  10490. for (i = 0; i < n/2; i++)
  10491. target[i] = be16_to_cpu(source[i]);
  10492. }
  10493. #define BNX2X_ALLOC_AND_SET(arr, lbl, func) \
  10494. do { \
  10495. u32 len = be32_to_cpu(fw_hdr->arr.len); \
  10496. bp->arr = kmalloc(len, GFP_KERNEL); \
  10497. if (!bp->arr) \
  10498. goto lbl; \
  10499. func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \
  10500. (u8 *)bp->arr, len); \
  10501. } while (0)
  10502. static int bnx2x_init_firmware(struct bnx2x *bp)
  10503. {
  10504. const char *fw_file_name;
  10505. struct bnx2x_fw_file_hdr *fw_hdr;
  10506. int rc;
  10507. if (bp->firmware)
  10508. return 0;
  10509. if (CHIP_IS_E1(bp))
  10510. fw_file_name = FW_FILE_NAME_E1;
  10511. else if (CHIP_IS_E1H(bp))
  10512. fw_file_name = FW_FILE_NAME_E1H;
  10513. else if (!CHIP_IS_E1x(bp))
  10514. fw_file_name = FW_FILE_NAME_E2;
  10515. else {
  10516. BNX2X_ERR("Unsupported chip revision\n");
  10517. return -EINVAL;
  10518. }
  10519. BNX2X_DEV_INFO("Loading %s\n", fw_file_name);
  10520. rc = request_firmware(&bp->firmware, fw_file_name, &bp->pdev->dev);
  10521. if (rc) {
  10522. BNX2X_ERR("Can't load firmware file %s\n",
  10523. fw_file_name);
  10524. goto request_firmware_exit;
  10525. }
  10526. rc = bnx2x_check_firmware(bp);
  10527. if (rc) {
  10528. BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name);
  10529. goto request_firmware_exit;
  10530. }
  10531. fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data;
  10532. /* Initialize the pointers to the init arrays */
  10533. /* Blob */
  10534. BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n);
  10535. /* Opcodes */
  10536. BNX2X_ALLOC_AND_SET(init_ops, init_ops_alloc_err, bnx2x_prep_ops);
  10537. /* Offsets */
  10538. BNX2X_ALLOC_AND_SET(init_ops_offsets, init_offsets_alloc_err,
  10539. be16_to_cpu_n);
  10540. /* STORMs firmware */
  10541. INIT_TSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10542. be32_to_cpu(fw_hdr->tsem_int_table_data.offset);
  10543. INIT_TSEM_PRAM_DATA(bp) = bp->firmware->data +
  10544. be32_to_cpu(fw_hdr->tsem_pram_data.offset);
  10545. INIT_USEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10546. be32_to_cpu(fw_hdr->usem_int_table_data.offset);
  10547. INIT_USEM_PRAM_DATA(bp) = bp->firmware->data +
  10548. be32_to_cpu(fw_hdr->usem_pram_data.offset);
  10549. INIT_XSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10550. be32_to_cpu(fw_hdr->xsem_int_table_data.offset);
  10551. INIT_XSEM_PRAM_DATA(bp) = bp->firmware->data +
  10552. be32_to_cpu(fw_hdr->xsem_pram_data.offset);
  10553. INIT_CSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10554. be32_to_cpu(fw_hdr->csem_int_table_data.offset);
  10555. INIT_CSEM_PRAM_DATA(bp) = bp->firmware->data +
  10556. be32_to_cpu(fw_hdr->csem_pram_data.offset);
  10557. /* IRO */
  10558. BNX2X_ALLOC_AND_SET(iro_arr, iro_alloc_err, bnx2x_prep_iro);
  10559. return 0;
  10560. iro_alloc_err:
  10561. kfree(bp->init_ops_offsets);
  10562. init_offsets_alloc_err:
  10563. kfree(bp->init_ops);
  10564. init_ops_alloc_err:
  10565. kfree(bp->init_data);
  10566. request_firmware_exit:
  10567. release_firmware(bp->firmware);
  10568. bp->firmware = NULL;
  10569. return rc;
  10570. }
  10571. static void bnx2x_release_firmware(struct bnx2x *bp)
  10572. {
  10573. kfree(bp->init_ops_offsets);
  10574. kfree(bp->init_ops);
  10575. kfree(bp->init_data);
  10576. release_firmware(bp->firmware);
  10577. bp->firmware = NULL;
  10578. }
  10579. static struct bnx2x_func_sp_drv_ops bnx2x_func_sp_drv = {
  10580. .init_hw_cmn_chip = bnx2x_init_hw_common_chip,
  10581. .init_hw_cmn = bnx2x_init_hw_common,
  10582. .init_hw_port = bnx2x_init_hw_port,
  10583. .init_hw_func = bnx2x_init_hw_func,
  10584. .reset_hw_cmn = bnx2x_reset_common,
  10585. .reset_hw_port = bnx2x_reset_port,
  10586. .reset_hw_func = bnx2x_reset_func,
  10587. .gunzip_init = bnx2x_gunzip_init,
  10588. .gunzip_end = bnx2x_gunzip_end,
  10589. .init_fw = bnx2x_init_firmware,
  10590. .release_fw = bnx2x_release_firmware,
  10591. };
  10592. void bnx2x__init_func_obj(struct bnx2x *bp)
  10593. {
  10594. /* Prepare DMAE related driver resources */
  10595. bnx2x_setup_dmae(bp);
  10596. bnx2x_init_func_obj(bp, &bp->func_obj,
  10597. bnx2x_sp(bp, func_rdata),
  10598. bnx2x_sp_mapping(bp, func_rdata),
  10599. bnx2x_sp(bp, func_afex_rdata),
  10600. bnx2x_sp_mapping(bp, func_afex_rdata),
  10601. &bnx2x_func_sp_drv);
  10602. }
  10603. /* must be called after sriov-enable */
  10604. static int bnx2x_set_qm_cid_count(struct bnx2x *bp)
  10605. {
  10606. int cid_count = BNX2X_L2_MAX_CID(bp);
  10607. if (IS_SRIOV(bp))
  10608. cid_count += BNX2X_VF_CIDS;
  10609. if (CNIC_SUPPORT(bp))
  10610. cid_count += CNIC_CID_MAX;
  10611. return roundup(cid_count, QM_CID_ROUND);
  10612. }
  10613. /**
  10614. * bnx2x_get_num_none_def_sbs - return the number of none default SBs
  10615. *
  10616. * @dev: pci device
  10617. *
  10618. */
  10619. static int bnx2x_get_num_non_def_sbs(struct pci_dev *pdev, int cnic_cnt)
  10620. {
  10621. int index;
  10622. u16 control = 0;
  10623. /*
  10624. * If MSI-X is not supported - return number of SBs needed to support
  10625. * one fast path queue: one FP queue + SB for CNIC
  10626. */
  10627. if (!pdev->msix_cap) {
  10628. dev_info(&pdev->dev, "no msix capability found\n");
  10629. return 1 + cnic_cnt;
  10630. }
  10631. dev_info(&pdev->dev, "msix capability found\n");
  10632. /*
  10633. * The value in the PCI configuration space is the index of the last
  10634. * entry, namely one less than the actual size of the table, which is
  10635. * exactly what we want to return from this function: number of all SBs
  10636. * without the default SB.
  10637. * For VFs there is no default SB, then we return (index+1).
  10638. */
  10639. pci_read_config_word(pdev, pdev->msix_cap + PCI_MSI_FLAGS, &control);
  10640. index = control & PCI_MSIX_FLAGS_QSIZE;
  10641. return index;
  10642. }
  10643. static int set_max_cos_est(int chip_id)
  10644. {
  10645. switch (chip_id) {
  10646. case BCM57710:
  10647. case BCM57711:
  10648. case BCM57711E:
  10649. return BNX2X_MULTI_TX_COS_E1X;
  10650. case BCM57712:
  10651. case BCM57712_MF:
  10652. return BNX2X_MULTI_TX_COS_E2_E3A0;
  10653. case BCM57800:
  10654. case BCM57800_MF:
  10655. case BCM57810:
  10656. case BCM57810_MF:
  10657. case BCM57840_4_10:
  10658. case BCM57840_2_20:
  10659. case BCM57840_O:
  10660. case BCM57840_MFO:
  10661. case BCM57840_MF:
  10662. case BCM57811:
  10663. case BCM57811_MF:
  10664. return BNX2X_MULTI_TX_COS_E3B0;
  10665. case BCM57712_VF:
  10666. case BCM57800_VF:
  10667. case BCM57810_VF:
  10668. case BCM57840_VF:
  10669. case BCM57811_VF:
  10670. return 1;
  10671. default:
  10672. pr_err("Unknown board_type (%d), aborting\n", chip_id);
  10673. return -ENODEV;
  10674. }
  10675. }
  10676. static int set_is_vf(int chip_id)
  10677. {
  10678. switch (chip_id) {
  10679. case BCM57712_VF:
  10680. case BCM57800_VF:
  10681. case BCM57810_VF:
  10682. case BCM57840_VF:
  10683. case BCM57811_VF:
  10684. return true;
  10685. default:
  10686. return false;
  10687. }
  10688. }
  10689. struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev);
  10690. static int bnx2x_init_one(struct pci_dev *pdev,
  10691. const struct pci_device_id *ent)
  10692. {
  10693. struct net_device *dev = NULL;
  10694. struct bnx2x *bp;
  10695. enum pcie_link_width pcie_width;
  10696. enum pci_bus_speed pcie_speed;
  10697. int rc, max_non_def_sbs;
  10698. int rx_count, tx_count, rss_count, doorbell_size;
  10699. int max_cos_est;
  10700. bool is_vf;
  10701. int cnic_cnt;
  10702. /* An estimated maximum supported CoS number according to the chip
  10703. * version.
  10704. * We will try to roughly estimate the maximum number of CoSes this chip
  10705. * may support in order to minimize the memory allocated for Tx
  10706. * netdev_queue's. This number will be accurately calculated during the
  10707. * initialization of bp->max_cos based on the chip versions AND chip
  10708. * revision in the bnx2x_init_bp().
  10709. */
  10710. max_cos_est = set_max_cos_est(ent->driver_data);
  10711. if (max_cos_est < 0)
  10712. return max_cos_est;
  10713. is_vf = set_is_vf(ent->driver_data);
  10714. cnic_cnt = is_vf ? 0 : 1;
  10715. max_non_def_sbs = bnx2x_get_num_non_def_sbs(pdev, cnic_cnt);
  10716. /* add another SB for VF as it has no default SB */
  10717. max_non_def_sbs += is_vf ? 1 : 0;
  10718. /* Maximum number of RSS queues: one IGU SB goes to CNIC */
  10719. rss_count = max_non_def_sbs - cnic_cnt;
  10720. if (rss_count < 1)
  10721. return -EINVAL;
  10722. /* Maximum number of netdev Rx queues: RSS + FCoE L2 */
  10723. rx_count = rss_count + cnic_cnt;
  10724. /* Maximum number of netdev Tx queues:
  10725. * Maximum TSS queues * Maximum supported number of CoS + FCoE L2
  10726. */
  10727. tx_count = rss_count * max_cos_est + cnic_cnt;
  10728. /* dev zeroed in init_etherdev */
  10729. dev = alloc_etherdev_mqs(sizeof(*bp), tx_count, rx_count);
  10730. if (!dev)
  10731. return -ENOMEM;
  10732. bp = netdev_priv(dev);
  10733. bp->flags = 0;
  10734. if (is_vf)
  10735. bp->flags |= IS_VF_FLAG;
  10736. bp->igu_sb_cnt = max_non_def_sbs;
  10737. bp->igu_base_addr = IS_VF(bp) ? PXP_VF_ADDR_IGU_START : BAR_IGU_INTMEM;
  10738. bp->msg_enable = debug;
  10739. bp->cnic_support = cnic_cnt;
  10740. bp->cnic_probe = bnx2x_cnic_probe;
  10741. pci_set_drvdata(pdev, dev);
  10742. rc = bnx2x_init_dev(bp, pdev, dev, ent->driver_data);
  10743. if (rc < 0) {
  10744. free_netdev(dev);
  10745. return rc;
  10746. }
  10747. BNX2X_DEV_INFO("This is a %s function\n",
  10748. IS_PF(bp) ? "physical" : "virtual");
  10749. BNX2X_DEV_INFO("Cnic support is %s\n", CNIC_SUPPORT(bp) ? "on" : "off");
  10750. BNX2X_DEV_INFO("Max num of status blocks %d\n", max_non_def_sbs);
  10751. BNX2X_DEV_INFO("Allocated netdev with %d tx and %d rx queues\n",
  10752. tx_count, rx_count);
  10753. rc = bnx2x_init_bp(bp);
  10754. if (rc)
  10755. goto init_one_exit;
  10756. /* Map doorbells here as we need the real value of bp->max_cos which
  10757. * is initialized in bnx2x_init_bp() to determine the number of
  10758. * l2 connections.
  10759. */
  10760. if (IS_VF(bp)) {
  10761. bp->doorbells = bnx2x_vf_doorbells(bp);
  10762. rc = bnx2x_vf_pci_alloc(bp);
  10763. if (rc)
  10764. goto init_one_exit;
  10765. } else {
  10766. doorbell_size = BNX2X_L2_MAX_CID(bp) * (1 << BNX2X_DB_SHIFT);
  10767. if (doorbell_size > pci_resource_len(pdev, 2)) {
  10768. dev_err(&bp->pdev->dev,
  10769. "Cannot map doorbells, bar size too small, aborting\n");
  10770. rc = -ENOMEM;
  10771. goto init_one_exit;
  10772. }
  10773. bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2),
  10774. doorbell_size);
  10775. }
  10776. if (!bp->doorbells) {
  10777. dev_err(&bp->pdev->dev,
  10778. "Cannot map doorbell space, aborting\n");
  10779. rc = -ENOMEM;
  10780. goto init_one_exit;
  10781. }
  10782. if (IS_VF(bp)) {
  10783. rc = bnx2x_vfpf_acquire(bp, tx_count, rx_count);
  10784. if (rc)
  10785. goto init_one_exit;
  10786. }
  10787. /* Enable SRIOV if capability found in configuration space */
  10788. rc = bnx2x_iov_init_one(bp, int_mode, BNX2X_MAX_NUM_OF_VFS);
  10789. if (rc)
  10790. goto init_one_exit;
  10791. /* calc qm_cid_count */
  10792. bp->qm_cid_count = bnx2x_set_qm_cid_count(bp);
  10793. BNX2X_DEV_INFO("qm_cid_count %d\n", bp->qm_cid_count);
  10794. /* disable FCOE L2 queue for E1x*/
  10795. if (CHIP_IS_E1x(bp))
  10796. bp->flags |= NO_FCOE_FLAG;
  10797. /* Set bp->num_queues for MSI-X mode*/
  10798. bnx2x_set_num_queues(bp);
  10799. /* Configure interrupt mode: try to enable MSI-X/MSI if
  10800. * needed.
  10801. */
  10802. rc = bnx2x_set_int_mode(bp);
  10803. if (rc) {
  10804. dev_err(&pdev->dev, "Cannot set interrupts\n");
  10805. goto init_one_exit;
  10806. }
  10807. BNX2X_DEV_INFO("set interrupts successfully\n");
  10808. /* register the net device */
  10809. rc = register_netdev(dev);
  10810. if (rc) {
  10811. dev_err(&pdev->dev, "Cannot register net device\n");
  10812. goto init_one_exit;
  10813. }
  10814. BNX2X_DEV_INFO("device name after netdev register %s\n", dev->name);
  10815. if (!NO_FCOE(bp)) {
  10816. /* Add storage MAC address */
  10817. rtnl_lock();
  10818. dev_addr_add(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  10819. rtnl_unlock();
  10820. }
  10821. if (pcie_get_minimum_link(bp->pdev, &pcie_speed, &pcie_width) ||
  10822. pcie_speed == PCI_SPEED_UNKNOWN ||
  10823. pcie_width == PCIE_LNK_WIDTH_UNKNOWN)
  10824. BNX2X_DEV_INFO("Failed to determine PCI Express Bandwidth\n");
  10825. else
  10826. BNX2X_DEV_INFO(
  10827. "%s (%c%d) PCI-E x%d %s found at mem %lx, IRQ %d, node addr %pM\n",
  10828. board_info[ent->driver_data].name,
  10829. (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4),
  10830. pcie_width,
  10831. pcie_speed == PCIE_SPEED_2_5GT ? "2.5GHz" :
  10832. pcie_speed == PCIE_SPEED_5_0GT ? "5.0GHz" :
  10833. pcie_speed == PCIE_SPEED_8_0GT ? "8.0GHz" :
  10834. "Unknown",
  10835. dev->base_addr, bp->pdev->irq, dev->dev_addr);
  10836. return 0;
  10837. init_one_exit:
  10838. if (bp->regview)
  10839. iounmap(bp->regview);
  10840. if (IS_PF(bp) && bp->doorbells)
  10841. iounmap(bp->doorbells);
  10842. free_netdev(dev);
  10843. if (atomic_read(&pdev->enable_cnt) == 1)
  10844. pci_release_regions(pdev);
  10845. pci_disable_device(pdev);
  10846. return rc;
  10847. }
  10848. static void __bnx2x_remove(struct pci_dev *pdev,
  10849. struct net_device *dev,
  10850. struct bnx2x *bp,
  10851. bool remove_netdev)
  10852. {
  10853. /* Delete storage MAC address */
  10854. if (!NO_FCOE(bp)) {
  10855. rtnl_lock();
  10856. dev_addr_del(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  10857. rtnl_unlock();
  10858. }
  10859. #ifdef BCM_DCBNL
  10860. /* Delete app tlvs from dcbnl */
  10861. bnx2x_dcbnl_update_applist(bp, true);
  10862. #endif
  10863. if (IS_PF(bp) &&
  10864. !BP_NOMCP(bp) &&
  10865. (bp->flags & BC_SUPPORTS_RMMOD_CMD))
  10866. bnx2x_fw_command(bp, DRV_MSG_CODE_RMMOD, 0);
  10867. /* Close the interface - either directly or implicitly */
  10868. if (remove_netdev) {
  10869. unregister_netdev(dev);
  10870. } else {
  10871. rtnl_lock();
  10872. dev_close(dev);
  10873. rtnl_unlock();
  10874. }
  10875. bnx2x_iov_remove_one(bp);
  10876. /* Power on: we can't let PCI layer write to us while we are in D3 */
  10877. if (IS_PF(bp))
  10878. bnx2x_set_power_state(bp, PCI_D0);
  10879. /* Disable MSI/MSI-X */
  10880. bnx2x_disable_msi(bp);
  10881. /* Power off */
  10882. if (IS_PF(bp))
  10883. bnx2x_set_power_state(bp, PCI_D3hot);
  10884. /* Make sure RESET task is not scheduled before continuing */
  10885. cancel_delayed_work_sync(&bp->sp_rtnl_task);
  10886. /* send message via vfpf channel to release the resources of this vf */
  10887. if (IS_VF(bp))
  10888. bnx2x_vfpf_release(bp);
  10889. /* Assumes no further PCIe PM changes will occur */
  10890. if (system_state == SYSTEM_POWER_OFF) {
  10891. pci_wake_from_d3(pdev, bp->wol);
  10892. pci_set_power_state(pdev, PCI_D3hot);
  10893. }
  10894. if (bp->regview)
  10895. iounmap(bp->regview);
  10896. /* for vf doorbells are part of the regview and were unmapped along with
  10897. * it. FW is only loaded by PF.
  10898. */
  10899. if (IS_PF(bp)) {
  10900. if (bp->doorbells)
  10901. iounmap(bp->doorbells);
  10902. bnx2x_release_firmware(bp);
  10903. }
  10904. bnx2x_free_mem_bp(bp);
  10905. if (remove_netdev)
  10906. free_netdev(dev);
  10907. if (atomic_read(&pdev->enable_cnt) == 1)
  10908. pci_release_regions(pdev);
  10909. pci_disable_device(pdev);
  10910. }
  10911. static void bnx2x_remove_one(struct pci_dev *pdev)
  10912. {
  10913. struct net_device *dev = pci_get_drvdata(pdev);
  10914. struct bnx2x *bp;
  10915. if (!dev) {
  10916. dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n");
  10917. return;
  10918. }
  10919. bp = netdev_priv(dev);
  10920. __bnx2x_remove(pdev, dev, bp, true);
  10921. }
  10922. static int bnx2x_eeh_nic_unload(struct bnx2x *bp)
  10923. {
  10924. bp->state = BNX2X_STATE_CLOSING_WAIT4_HALT;
  10925. bp->rx_mode = BNX2X_RX_MODE_NONE;
  10926. if (CNIC_LOADED(bp))
  10927. bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD);
  10928. /* Stop Tx */
  10929. bnx2x_tx_disable(bp);
  10930. /* Delete all NAPI objects */
  10931. bnx2x_del_all_napi(bp);
  10932. if (CNIC_LOADED(bp))
  10933. bnx2x_del_all_napi_cnic(bp);
  10934. netdev_reset_tc(bp->dev);
  10935. del_timer_sync(&bp->timer);
  10936. cancel_delayed_work(&bp->sp_task);
  10937. cancel_delayed_work(&bp->period_task);
  10938. spin_lock_bh(&bp->stats_lock);
  10939. bp->stats_state = STATS_STATE_DISABLED;
  10940. spin_unlock_bh(&bp->stats_lock);
  10941. bnx2x_save_statistics(bp);
  10942. netif_carrier_off(bp->dev);
  10943. return 0;
  10944. }
  10945. /**
  10946. * bnx2x_io_error_detected - called when PCI error is detected
  10947. * @pdev: Pointer to PCI device
  10948. * @state: The current pci connection state
  10949. *
  10950. * This function is called after a PCI bus error affecting
  10951. * this device has been detected.
  10952. */
  10953. static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev,
  10954. pci_channel_state_t state)
  10955. {
  10956. struct net_device *dev = pci_get_drvdata(pdev);
  10957. struct bnx2x *bp = netdev_priv(dev);
  10958. rtnl_lock();
  10959. BNX2X_ERR("IO error detected\n");
  10960. netif_device_detach(dev);
  10961. if (state == pci_channel_io_perm_failure) {
  10962. rtnl_unlock();
  10963. return PCI_ERS_RESULT_DISCONNECT;
  10964. }
  10965. if (netif_running(dev))
  10966. bnx2x_eeh_nic_unload(bp);
  10967. bnx2x_prev_path_mark_eeh(bp);
  10968. pci_disable_device(pdev);
  10969. rtnl_unlock();
  10970. /* Request a slot reset */
  10971. return PCI_ERS_RESULT_NEED_RESET;
  10972. }
  10973. /**
  10974. * bnx2x_io_slot_reset - called after the PCI bus has been reset
  10975. * @pdev: Pointer to PCI device
  10976. *
  10977. * Restart the card from scratch, as if from a cold-boot.
  10978. */
  10979. static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev)
  10980. {
  10981. struct net_device *dev = pci_get_drvdata(pdev);
  10982. struct bnx2x *bp = netdev_priv(dev);
  10983. int i;
  10984. rtnl_lock();
  10985. BNX2X_ERR("IO slot reset initializing...\n");
  10986. if (pci_enable_device(pdev)) {
  10987. dev_err(&pdev->dev,
  10988. "Cannot re-enable PCI device after reset\n");
  10989. rtnl_unlock();
  10990. return PCI_ERS_RESULT_DISCONNECT;
  10991. }
  10992. pci_set_master(pdev);
  10993. pci_restore_state(pdev);
  10994. pci_save_state(pdev);
  10995. if (netif_running(dev))
  10996. bnx2x_set_power_state(bp, PCI_D0);
  10997. if (netif_running(dev)) {
  10998. BNX2X_ERR("IO slot reset --> driver unload\n");
  10999. /* MCP should have been reset; Need to wait for validity */
  11000. bnx2x_init_shmem(bp);
  11001. if (IS_PF(bp) && SHMEM2_HAS(bp, drv_capabilities_flag)) {
  11002. u32 v;
  11003. v = SHMEM2_RD(bp,
  11004. drv_capabilities_flag[BP_FW_MB_IDX(bp)]);
  11005. SHMEM2_WR(bp, drv_capabilities_flag[BP_FW_MB_IDX(bp)],
  11006. v & ~DRV_FLAGS_CAPABILITIES_LOADED_L2);
  11007. }
  11008. bnx2x_drain_tx_queues(bp);
  11009. bnx2x_send_unload_req(bp, UNLOAD_RECOVERY);
  11010. bnx2x_netif_stop(bp, 1);
  11011. bnx2x_free_irq(bp);
  11012. /* Report UNLOAD_DONE to MCP */
  11013. bnx2x_send_unload_done(bp, true);
  11014. bp->sp_state = 0;
  11015. bp->port.pmf = 0;
  11016. bnx2x_prev_unload(bp);
  11017. /* We should have reseted the engine, so It's fair to
  11018. * assume the FW will no longer write to the bnx2x driver.
  11019. */
  11020. bnx2x_squeeze_objects(bp);
  11021. bnx2x_free_skbs(bp);
  11022. for_each_rx_queue(bp, i)
  11023. bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
  11024. bnx2x_free_fp_mem(bp);
  11025. bnx2x_free_mem(bp);
  11026. bp->state = BNX2X_STATE_CLOSED;
  11027. }
  11028. rtnl_unlock();
  11029. return PCI_ERS_RESULT_RECOVERED;
  11030. }
  11031. /**
  11032. * bnx2x_io_resume - called when traffic can start flowing again
  11033. * @pdev: Pointer to PCI device
  11034. *
  11035. * This callback is called when the error recovery driver tells us that
  11036. * its OK to resume normal operation.
  11037. */
  11038. static void bnx2x_io_resume(struct pci_dev *pdev)
  11039. {
  11040. struct net_device *dev = pci_get_drvdata(pdev);
  11041. struct bnx2x *bp = netdev_priv(dev);
  11042. if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
  11043. netdev_err(bp->dev, "Handling parity error recovery. Try again later\n");
  11044. return;
  11045. }
  11046. rtnl_lock();
  11047. bp->fw_seq = SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
  11048. DRV_MSG_SEQ_NUMBER_MASK;
  11049. if (netif_running(dev))
  11050. bnx2x_nic_load(bp, LOAD_NORMAL);
  11051. netif_device_attach(dev);
  11052. rtnl_unlock();
  11053. }
  11054. static const struct pci_error_handlers bnx2x_err_handler = {
  11055. .error_detected = bnx2x_io_error_detected,
  11056. .slot_reset = bnx2x_io_slot_reset,
  11057. .resume = bnx2x_io_resume,
  11058. };
  11059. static void bnx2x_shutdown(struct pci_dev *pdev)
  11060. {
  11061. struct net_device *dev = pci_get_drvdata(pdev);
  11062. struct bnx2x *bp;
  11063. if (!dev)
  11064. return;
  11065. bp = netdev_priv(dev);
  11066. if (!bp)
  11067. return;
  11068. rtnl_lock();
  11069. netif_device_detach(dev);
  11070. rtnl_unlock();
  11071. /* Don't remove the netdevice, as there are scenarios which will cause
  11072. * the kernel to hang, e.g., when trying to remove bnx2i while the
  11073. * rootfs is mounted from SAN.
  11074. */
  11075. __bnx2x_remove(pdev, dev, bp, false);
  11076. }
  11077. static struct pci_driver bnx2x_pci_driver = {
  11078. .name = DRV_MODULE_NAME,
  11079. .id_table = bnx2x_pci_tbl,
  11080. .probe = bnx2x_init_one,
  11081. .remove = bnx2x_remove_one,
  11082. .suspend = bnx2x_suspend,
  11083. .resume = bnx2x_resume,
  11084. .err_handler = &bnx2x_err_handler,
  11085. #ifdef CONFIG_BNX2X_SRIOV
  11086. .sriov_configure = bnx2x_sriov_configure,
  11087. #endif
  11088. .shutdown = bnx2x_shutdown,
  11089. };
  11090. static int __init bnx2x_init(void)
  11091. {
  11092. int ret;
  11093. pr_info("%s", version);
  11094. bnx2x_wq = create_singlethread_workqueue("bnx2x");
  11095. if (bnx2x_wq == NULL) {
  11096. pr_err("Cannot create workqueue\n");
  11097. return -ENOMEM;
  11098. }
  11099. ret = pci_register_driver(&bnx2x_pci_driver);
  11100. if (ret) {
  11101. pr_err("Cannot register driver\n");
  11102. destroy_workqueue(bnx2x_wq);
  11103. }
  11104. return ret;
  11105. }
  11106. static void __exit bnx2x_cleanup(void)
  11107. {
  11108. struct list_head *pos, *q;
  11109. pci_unregister_driver(&bnx2x_pci_driver);
  11110. destroy_workqueue(bnx2x_wq);
  11111. /* Free globally allocated resources */
  11112. list_for_each_safe(pos, q, &bnx2x_prev_list) {
  11113. struct bnx2x_prev_path_list *tmp =
  11114. list_entry(pos, struct bnx2x_prev_path_list, list);
  11115. list_del(pos);
  11116. kfree(tmp);
  11117. }
  11118. }
  11119. void bnx2x_notify_link_changed(struct bnx2x *bp)
  11120. {
  11121. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + BP_FUNC(bp)*sizeof(u32), 1);
  11122. }
  11123. module_init(bnx2x_init);
  11124. module_exit(bnx2x_cleanup);
  11125. /**
  11126. * bnx2x_set_iscsi_eth_mac_addr - set iSCSI MAC(s).
  11127. *
  11128. * @bp: driver handle
  11129. * @set: set or clear the CAM entry
  11130. *
  11131. * This function will wait until the ramrod completion returns.
  11132. * Return 0 if success, -ENODEV if ramrod doesn't return.
  11133. */
  11134. static int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp)
  11135. {
  11136. unsigned long ramrod_flags = 0;
  11137. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  11138. return bnx2x_set_mac_one(bp, bp->cnic_eth_dev.iscsi_mac,
  11139. &bp->iscsi_l2_mac_obj, true,
  11140. BNX2X_ISCSI_ETH_MAC, &ramrod_flags);
  11141. }
  11142. /* count denotes the number of new completions we have seen */
  11143. static void bnx2x_cnic_sp_post(struct bnx2x *bp, int count)
  11144. {
  11145. struct eth_spe *spe;
  11146. int cxt_index, cxt_offset;
  11147. #ifdef BNX2X_STOP_ON_ERROR
  11148. if (unlikely(bp->panic))
  11149. return;
  11150. #endif
  11151. spin_lock_bh(&bp->spq_lock);
  11152. BUG_ON(bp->cnic_spq_pending < count);
  11153. bp->cnic_spq_pending -= count;
  11154. for (; bp->cnic_kwq_pending; bp->cnic_kwq_pending--) {
  11155. u16 type = (le16_to_cpu(bp->cnic_kwq_cons->hdr.type)
  11156. & SPE_HDR_CONN_TYPE) >>
  11157. SPE_HDR_CONN_TYPE_SHIFT;
  11158. u8 cmd = (le32_to_cpu(bp->cnic_kwq_cons->hdr.conn_and_cmd_data)
  11159. >> SPE_HDR_CMD_ID_SHIFT) & 0xff;
  11160. /* Set validation for iSCSI L2 client before sending SETUP
  11161. * ramrod
  11162. */
  11163. if (type == ETH_CONNECTION_TYPE) {
  11164. if (cmd == RAMROD_CMD_ID_ETH_CLIENT_SETUP) {
  11165. cxt_index = BNX2X_ISCSI_ETH_CID(bp) /
  11166. ILT_PAGE_CIDS;
  11167. cxt_offset = BNX2X_ISCSI_ETH_CID(bp) -
  11168. (cxt_index * ILT_PAGE_CIDS);
  11169. bnx2x_set_ctx_validation(bp,
  11170. &bp->context[cxt_index].
  11171. vcxt[cxt_offset].eth,
  11172. BNX2X_ISCSI_ETH_CID(bp));
  11173. }
  11174. }
  11175. /*
  11176. * There may be not more than 8 L2, not more than 8 L5 SPEs
  11177. * and in the air. We also check that number of outstanding
  11178. * COMMON ramrods is not more than the EQ and SPQ can
  11179. * accommodate.
  11180. */
  11181. if (type == ETH_CONNECTION_TYPE) {
  11182. if (!atomic_read(&bp->cq_spq_left))
  11183. break;
  11184. else
  11185. atomic_dec(&bp->cq_spq_left);
  11186. } else if (type == NONE_CONNECTION_TYPE) {
  11187. if (!atomic_read(&bp->eq_spq_left))
  11188. break;
  11189. else
  11190. atomic_dec(&bp->eq_spq_left);
  11191. } else if ((type == ISCSI_CONNECTION_TYPE) ||
  11192. (type == FCOE_CONNECTION_TYPE)) {
  11193. if (bp->cnic_spq_pending >=
  11194. bp->cnic_eth_dev.max_kwqe_pending)
  11195. break;
  11196. else
  11197. bp->cnic_spq_pending++;
  11198. } else {
  11199. BNX2X_ERR("Unknown SPE type: %d\n", type);
  11200. bnx2x_panic();
  11201. break;
  11202. }
  11203. spe = bnx2x_sp_get_next(bp);
  11204. *spe = *bp->cnic_kwq_cons;
  11205. DP(BNX2X_MSG_SP, "pending on SPQ %d, on KWQ %d count %d\n",
  11206. bp->cnic_spq_pending, bp->cnic_kwq_pending, count);
  11207. if (bp->cnic_kwq_cons == bp->cnic_kwq_last)
  11208. bp->cnic_kwq_cons = bp->cnic_kwq;
  11209. else
  11210. bp->cnic_kwq_cons++;
  11211. }
  11212. bnx2x_sp_prod_update(bp);
  11213. spin_unlock_bh(&bp->spq_lock);
  11214. }
  11215. static int bnx2x_cnic_sp_queue(struct net_device *dev,
  11216. struct kwqe_16 *kwqes[], u32 count)
  11217. {
  11218. struct bnx2x *bp = netdev_priv(dev);
  11219. int i;
  11220. #ifdef BNX2X_STOP_ON_ERROR
  11221. if (unlikely(bp->panic)) {
  11222. BNX2X_ERR("Can't post to SP queue while panic\n");
  11223. return -EIO;
  11224. }
  11225. #endif
  11226. if ((bp->recovery_state != BNX2X_RECOVERY_DONE) &&
  11227. (bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  11228. BNX2X_ERR("Handling parity error recovery. Try again later\n");
  11229. return -EAGAIN;
  11230. }
  11231. spin_lock_bh(&bp->spq_lock);
  11232. for (i = 0; i < count; i++) {
  11233. struct eth_spe *spe = (struct eth_spe *)kwqes[i];
  11234. if (bp->cnic_kwq_pending == MAX_SP_DESC_CNT)
  11235. break;
  11236. *bp->cnic_kwq_prod = *spe;
  11237. bp->cnic_kwq_pending++;
  11238. DP(BNX2X_MSG_SP, "L5 SPQE %x %x %x:%x pos %d\n",
  11239. spe->hdr.conn_and_cmd_data, spe->hdr.type,
  11240. spe->data.update_data_addr.hi,
  11241. spe->data.update_data_addr.lo,
  11242. bp->cnic_kwq_pending);
  11243. if (bp->cnic_kwq_prod == bp->cnic_kwq_last)
  11244. bp->cnic_kwq_prod = bp->cnic_kwq;
  11245. else
  11246. bp->cnic_kwq_prod++;
  11247. }
  11248. spin_unlock_bh(&bp->spq_lock);
  11249. if (bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending)
  11250. bnx2x_cnic_sp_post(bp, 0);
  11251. return i;
  11252. }
  11253. static int bnx2x_cnic_ctl_send(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  11254. {
  11255. struct cnic_ops *c_ops;
  11256. int rc = 0;
  11257. mutex_lock(&bp->cnic_mutex);
  11258. c_ops = rcu_dereference_protected(bp->cnic_ops,
  11259. lockdep_is_held(&bp->cnic_mutex));
  11260. if (c_ops)
  11261. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  11262. mutex_unlock(&bp->cnic_mutex);
  11263. return rc;
  11264. }
  11265. static int bnx2x_cnic_ctl_send_bh(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  11266. {
  11267. struct cnic_ops *c_ops;
  11268. int rc = 0;
  11269. rcu_read_lock();
  11270. c_ops = rcu_dereference(bp->cnic_ops);
  11271. if (c_ops)
  11272. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  11273. rcu_read_unlock();
  11274. return rc;
  11275. }
  11276. /*
  11277. * for commands that have no data
  11278. */
  11279. int bnx2x_cnic_notify(struct bnx2x *bp, int cmd)
  11280. {
  11281. struct cnic_ctl_info ctl = {0};
  11282. ctl.cmd = cmd;
  11283. return bnx2x_cnic_ctl_send(bp, &ctl);
  11284. }
  11285. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err)
  11286. {
  11287. struct cnic_ctl_info ctl = {0};
  11288. /* first we tell CNIC and only then we count this as a completion */
  11289. ctl.cmd = CNIC_CTL_COMPLETION_CMD;
  11290. ctl.data.comp.cid = cid;
  11291. ctl.data.comp.error = err;
  11292. bnx2x_cnic_ctl_send_bh(bp, &ctl);
  11293. bnx2x_cnic_sp_post(bp, 0);
  11294. }
  11295. /* Called with netif_addr_lock_bh() taken.
  11296. * Sets an rx_mode config for an iSCSI ETH client.
  11297. * Doesn't block.
  11298. * Completion should be checked outside.
  11299. */
  11300. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start)
  11301. {
  11302. unsigned long accept_flags = 0, ramrod_flags = 0;
  11303. u8 cl_id = bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  11304. int sched_state = BNX2X_FILTER_ISCSI_ETH_STOP_SCHED;
  11305. if (start) {
  11306. /* Start accepting on iSCSI L2 ring. Accept all multicasts
  11307. * because it's the only way for UIO Queue to accept
  11308. * multicasts (in non-promiscuous mode only one Queue per
  11309. * function will receive multicast packets (leading in our
  11310. * case).
  11311. */
  11312. __set_bit(BNX2X_ACCEPT_UNICAST, &accept_flags);
  11313. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept_flags);
  11314. __set_bit(BNX2X_ACCEPT_BROADCAST, &accept_flags);
  11315. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags);
  11316. /* Clear STOP_PENDING bit if START is requested */
  11317. clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &bp->sp_state);
  11318. sched_state = BNX2X_FILTER_ISCSI_ETH_START_SCHED;
  11319. } else
  11320. /* Clear START_PENDING bit if STOP is requested */
  11321. clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &bp->sp_state);
  11322. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  11323. set_bit(sched_state, &bp->sp_state);
  11324. else {
  11325. __set_bit(RAMROD_RX, &ramrod_flags);
  11326. bnx2x_set_q_rx_mode(bp, cl_id, 0, accept_flags, 0,
  11327. ramrod_flags);
  11328. }
  11329. }
  11330. static int bnx2x_drv_ctl(struct net_device *dev, struct drv_ctl_info *ctl)
  11331. {
  11332. struct bnx2x *bp = netdev_priv(dev);
  11333. int rc = 0;
  11334. switch (ctl->cmd) {
  11335. case DRV_CTL_CTXTBL_WR_CMD: {
  11336. u32 index = ctl->data.io.offset;
  11337. dma_addr_t addr = ctl->data.io.dma_addr;
  11338. bnx2x_ilt_wr(bp, index, addr);
  11339. break;
  11340. }
  11341. case DRV_CTL_RET_L5_SPQ_CREDIT_CMD: {
  11342. int count = ctl->data.credit.credit_count;
  11343. bnx2x_cnic_sp_post(bp, count);
  11344. break;
  11345. }
  11346. /* rtnl_lock is held. */
  11347. case DRV_CTL_START_L2_CMD: {
  11348. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11349. unsigned long sp_bits = 0;
  11350. /* Configure the iSCSI classification object */
  11351. bnx2x_init_mac_obj(bp, &bp->iscsi_l2_mac_obj,
  11352. cp->iscsi_l2_client_id,
  11353. cp->iscsi_l2_cid, BP_FUNC(bp),
  11354. bnx2x_sp(bp, mac_rdata),
  11355. bnx2x_sp_mapping(bp, mac_rdata),
  11356. BNX2X_FILTER_MAC_PENDING,
  11357. &bp->sp_state, BNX2X_OBJ_TYPE_RX,
  11358. &bp->macs_pool);
  11359. /* Set iSCSI MAC address */
  11360. rc = bnx2x_set_iscsi_eth_mac_addr(bp);
  11361. if (rc)
  11362. break;
  11363. mmiowb();
  11364. barrier();
  11365. /* Start accepting on iSCSI L2 ring */
  11366. netif_addr_lock_bh(dev);
  11367. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  11368. netif_addr_unlock_bh(dev);
  11369. /* bits to wait on */
  11370. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  11371. __set_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &sp_bits);
  11372. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  11373. BNX2X_ERR("rx_mode completion timed out!\n");
  11374. break;
  11375. }
  11376. /* rtnl_lock is held. */
  11377. case DRV_CTL_STOP_L2_CMD: {
  11378. unsigned long sp_bits = 0;
  11379. /* Stop accepting on iSCSI L2 ring */
  11380. netif_addr_lock_bh(dev);
  11381. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  11382. netif_addr_unlock_bh(dev);
  11383. /* bits to wait on */
  11384. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  11385. __set_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &sp_bits);
  11386. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  11387. BNX2X_ERR("rx_mode completion timed out!\n");
  11388. mmiowb();
  11389. barrier();
  11390. /* Unset iSCSI L2 MAC */
  11391. rc = bnx2x_del_all_macs(bp, &bp->iscsi_l2_mac_obj,
  11392. BNX2X_ISCSI_ETH_MAC, true);
  11393. break;
  11394. }
  11395. case DRV_CTL_RET_L2_SPQ_CREDIT_CMD: {
  11396. int count = ctl->data.credit.credit_count;
  11397. smp_mb__before_atomic_inc();
  11398. atomic_add(count, &bp->cq_spq_left);
  11399. smp_mb__after_atomic_inc();
  11400. break;
  11401. }
  11402. case DRV_CTL_ULP_REGISTER_CMD: {
  11403. int ulp_type = ctl->data.register_data.ulp_type;
  11404. if (CHIP_IS_E3(bp)) {
  11405. int idx = BP_FW_MB_IDX(bp);
  11406. u32 cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  11407. int path = BP_PATH(bp);
  11408. int port = BP_PORT(bp);
  11409. int i;
  11410. u32 scratch_offset;
  11411. u32 *host_addr;
  11412. /* first write capability to shmem2 */
  11413. if (ulp_type == CNIC_ULP_ISCSI)
  11414. cap |= DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  11415. else if (ulp_type == CNIC_ULP_FCOE)
  11416. cap |= DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  11417. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  11418. if ((ulp_type != CNIC_ULP_FCOE) ||
  11419. (!SHMEM2_HAS(bp, ncsi_oem_data_addr)) ||
  11420. (!(bp->flags & BC_SUPPORTS_FCOE_FEATURES)))
  11421. break;
  11422. /* if reached here - should write fcoe capabilities */
  11423. scratch_offset = SHMEM2_RD(bp, ncsi_oem_data_addr);
  11424. if (!scratch_offset)
  11425. break;
  11426. scratch_offset += offsetof(struct glob_ncsi_oem_data,
  11427. fcoe_features[path][port]);
  11428. host_addr = (u32 *) &(ctl->data.register_data.
  11429. fcoe_features);
  11430. for (i = 0; i < sizeof(struct fcoe_capabilities);
  11431. i += 4)
  11432. REG_WR(bp, scratch_offset + i,
  11433. *(host_addr + i/4));
  11434. }
  11435. break;
  11436. }
  11437. case DRV_CTL_ULP_UNREGISTER_CMD: {
  11438. int ulp_type = ctl->data.ulp_type;
  11439. if (CHIP_IS_E3(bp)) {
  11440. int idx = BP_FW_MB_IDX(bp);
  11441. u32 cap;
  11442. cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  11443. if (ulp_type == CNIC_ULP_ISCSI)
  11444. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  11445. else if (ulp_type == CNIC_ULP_FCOE)
  11446. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  11447. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  11448. }
  11449. break;
  11450. }
  11451. default:
  11452. BNX2X_ERR("unknown command %x\n", ctl->cmd);
  11453. rc = -EINVAL;
  11454. }
  11455. return rc;
  11456. }
  11457. void bnx2x_setup_cnic_irq_info(struct bnx2x *bp)
  11458. {
  11459. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11460. if (bp->flags & USING_MSIX_FLAG) {
  11461. cp->drv_state |= CNIC_DRV_STATE_USING_MSIX;
  11462. cp->irq_arr[0].irq_flags |= CNIC_IRQ_FL_MSIX;
  11463. cp->irq_arr[0].vector = bp->msix_table[1].vector;
  11464. } else {
  11465. cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX;
  11466. cp->irq_arr[0].irq_flags &= ~CNIC_IRQ_FL_MSIX;
  11467. }
  11468. if (!CHIP_IS_E1x(bp))
  11469. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e2_sb;
  11470. else
  11471. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e1x_sb;
  11472. cp->irq_arr[0].status_blk_num = bnx2x_cnic_fw_sb_id(bp);
  11473. cp->irq_arr[0].status_blk_num2 = bnx2x_cnic_igu_sb_id(bp);
  11474. cp->irq_arr[1].status_blk = bp->def_status_blk;
  11475. cp->irq_arr[1].status_blk_num = DEF_SB_ID;
  11476. cp->irq_arr[1].status_blk_num2 = DEF_SB_IGU_ID;
  11477. cp->num_irq = 2;
  11478. }
  11479. void bnx2x_setup_cnic_info(struct bnx2x *bp)
  11480. {
  11481. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11482. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  11483. bnx2x_cid_ilt_lines(bp);
  11484. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  11485. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
  11486. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
  11487. 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",
  11488. BNX2X_1st_NON_L2_ETH_CID(bp), cp->starting_cid, cp->fcoe_init_cid,
  11489. cp->iscsi_l2_cid);
  11490. if (NO_ISCSI_OOO(bp))
  11491. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  11492. }
  11493. static int bnx2x_register_cnic(struct net_device *dev, struct cnic_ops *ops,
  11494. void *data)
  11495. {
  11496. struct bnx2x *bp = netdev_priv(dev);
  11497. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11498. int rc;
  11499. DP(NETIF_MSG_IFUP, "Register_cnic called\n");
  11500. if (ops == NULL) {
  11501. BNX2X_ERR("NULL ops received\n");
  11502. return -EINVAL;
  11503. }
  11504. if (!CNIC_SUPPORT(bp)) {
  11505. BNX2X_ERR("Can't register CNIC when not supported\n");
  11506. return -EOPNOTSUPP;
  11507. }
  11508. if (!CNIC_LOADED(bp)) {
  11509. rc = bnx2x_load_cnic(bp);
  11510. if (rc) {
  11511. BNX2X_ERR("CNIC-related load failed\n");
  11512. return rc;
  11513. }
  11514. }
  11515. bp->cnic_enabled = true;
  11516. bp->cnic_kwq = kzalloc(PAGE_SIZE, GFP_KERNEL);
  11517. if (!bp->cnic_kwq)
  11518. return -ENOMEM;
  11519. bp->cnic_kwq_cons = bp->cnic_kwq;
  11520. bp->cnic_kwq_prod = bp->cnic_kwq;
  11521. bp->cnic_kwq_last = bp->cnic_kwq + MAX_SP_DESC_CNT;
  11522. bp->cnic_spq_pending = 0;
  11523. bp->cnic_kwq_pending = 0;
  11524. bp->cnic_data = data;
  11525. cp->num_irq = 0;
  11526. cp->drv_state |= CNIC_DRV_STATE_REGD;
  11527. cp->iro_arr = bp->iro_arr;
  11528. bnx2x_setup_cnic_irq_info(bp);
  11529. rcu_assign_pointer(bp->cnic_ops, ops);
  11530. return 0;
  11531. }
  11532. static int bnx2x_unregister_cnic(struct net_device *dev)
  11533. {
  11534. struct bnx2x *bp = netdev_priv(dev);
  11535. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11536. mutex_lock(&bp->cnic_mutex);
  11537. cp->drv_state = 0;
  11538. RCU_INIT_POINTER(bp->cnic_ops, NULL);
  11539. mutex_unlock(&bp->cnic_mutex);
  11540. synchronize_rcu();
  11541. bp->cnic_enabled = false;
  11542. kfree(bp->cnic_kwq);
  11543. bp->cnic_kwq = NULL;
  11544. return 0;
  11545. }
  11546. struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev)
  11547. {
  11548. struct bnx2x *bp = netdev_priv(dev);
  11549. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11550. /* If both iSCSI and FCoE are disabled - return NULL in
  11551. * order to indicate CNIC that it should not try to work
  11552. * with this device.
  11553. */
  11554. if (NO_ISCSI(bp) && NO_FCOE(bp))
  11555. return NULL;
  11556. cp->drv_owner = THIS_MODULE;
  11557. cp->chip_id = CHIP_ID(bp);
  11558. cp->pdev = bp->pdev;
  11559. cp->io_base = bp->regview;
  11560. cp->io_base2 = bp->doorbells;
  11561. cp->max_kwqe_pending = 8;
  11562. cp->ctx_blk_size = CDU_ILT_PAGE_SZ;
  11563. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  11564. bnx2x_cid_ilt_lines(bp);
  11565. cp->ctx_tbl_len = CNIC_ILT_LINES;
  11566. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  11567. cp->drv_submit_kwqes_16 = bnx2x_cnic_sp_queue;
  11568. cp->drv_ctl = bnx2x_drv_ctl;
  11569. cp->drv_register_cnic = bnx2x_register_cnic;
  11570. cp->drv_unregister_cnic = bnx2x_unregister_cnic;
  11571. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
  11572. cp->iscsi_l2_client_id =
  11573. bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  11574. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
  11575. if (NO_ISCSI_OOO(bp))
  11576. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  11577. if (NO_ISCSI(bp))
  11578. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI;
  11579. if (NO_FCOE(bp))
  11580. cp->drv_state |= CNIC_DRV_STATE_NO_FCOE;
  11581. BNX2X_DEV_INFO(
  11582. "page_size %d, tbl_offset %d, tbl_lines %d, starting cid %d\n",
  11583. cp->ctx_blk_size,
  11584. cp->ctx_tbl_offset,
  11585. cp->ctx_tbl_len,
  11586. cp->starting_cid);
  11587. return cp;
  11588. }
  11589. u32 bnx2x_rx_ustorm_prods_offset(struct bnx2x_fastpath *fp)
  11590. {
  11591. struct bnx2x *bp = fp->bp;
  11592. u32 offset = BAR_USTRORM_INTMEM;
  11593. if (IS_VF(bp))
  11594. return bnx2x_vf_ustorm_prods_offset(bp, fp);
  11595. else if (!CHIP_IS_E1x(bp))
  11596. offset += USTORM_RX_PRODS_E2_OFFSET(fp->cl_qzone_id);
  11597. else
  11598. offset += USTORM_RX_PRODS_E1X_OFFSET(BP_PORT(bp), fp->cl_id);
  11599. return offset;
  11600. }
  11601. /* called only on E1H or E2.
  11602. * When pretending to be PF, the pretend value is the function number 0...7
  11603. * When pretending to be VF, the pretend val is the PF-num:VF-valid:ABS-VFID
  11604. * combination
  11605. */
  11606. int bnx2x_pretend_func(struct bnx2x *bp, u16 pretend_func_val)
  11607. {
  11608. u32 pretend_reg;
  11609. if (CHIP_IS_E1H(bp) && pretend_func_val >= E1H_FUNC_MAX)
  11610. return -1;
  11611. /* get my own pretend register */
  11612. pretend_reg = bnx2x_get_pretend_reg(bp);
  11613. REG_WR(bp, pretend_reg, pretend_func_val);
  11614. REG_RD(bp, pretend_reg);
  11615. return 0;
  11616. }