bnx2x_main.c 362 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417
  1. /* bnx2x_main.c: Broadcom Everest network driver.
  2. *
  3. * Copyright (c) 2007-2012 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. #define MAC_LEADING_ZERO_CNT (ALIGN(ETH_ALEN, sizeof(u32)) - ETH_ALEN)
  74. /* Time in jiffies before concluding the transmitter is hung */
  75. #define TX_TIMEOUT (5*HZ)
  76. static char version[] =
  77. "Broadcom NetXtreme II 5771x/578xx 10/20-Gigabit Ethernet Driver "
  78. DRV_MODULE_NAME " " DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
  79. MODULE_AUTHOR("Eliezer Tamir");
  80. MODULE_DESCRIPTION("Broadcom NetXtreme II "
  81. "BCM57710/57711/57711E/"
  82. "57712/57712_MF/57800/57800_MF/57810/57810_MF/"
  83. "57840/57840_MF Driver");
  84. MODULE_LICENSE("GPL");
  85. MODULE_VERSION(DRV_MODULE_VERSION);
  86. MODULE_FIRMWARE(FW_FILE_NAME_E1);
  87. MODULE_FIRMWARE(FW_FILE_NAME_E1H);
  88. MODULE_FIRMWARE(FW_FILE_NAME_E2);
  89. int num_queues;
  90. module_param(num_queues, int, 0);
  91. MODULE_PARM_DESC(num_queues,
  92. " Set number of queues (default is as a number of CPUs)");
  93. static int disable_tpa;
  94. module_param(disable_tpa, int, 0);
  95. MODULE_PARM_DESC(disable_tpa, " Disable the TPA (LRO) feature");
  96. #define INT_MODE_INTx 1
  97. #define INT_MODE_MSI 2
  98. int int_mode;
  99. module_param(int_mode, int, 0);
  100. MODULE_PARM_DESC(int_mode, " Force interrupt mode other than MSI-X "
  101. "(1 INT#x; 2 MSI)");
  102. static int dropless_fc;
  103. module_param(dropless_fc, int, 0);
  104. MODULE_PARM_DESC(dropless_fc, " Pause on exhausted host ring");
  105. static int mrrs = -1;
  106. module_param(mrrs, int, 0);
  107. MODULE_PARM_DESC(mrrs, " Force Max Read Req Size (0..3) (for debug)");
  108. static int debug;
  109. module_param(debug, int, 0);
  110. MODULE_PARM_DESC(debug, " Default debug msglevel");
  111. struct workqueue_struct *bnx2x_wq;
  112. struct bnx2x_mac_vals {
  113. u32 xmac_addr;
  114. u32 xmac_val;
  115. u32 emac_addr;
  116. u32 emac_val;
  117. u32 umac_addr;
  118. u32 umac_val;
  119. u32 bmac_addr;
  120. u32 bmac_val[2];
  121. };
  122. enum bnx2x_board_type {
  123. BCM57710 = 0,
  124. BCM57711,
  125. BCM57711E,
  126. BCM57712,
  127. BCM57712_MF,
  128. BCM57712_VF,
  129. BCM57800,
  130. BCM57800_MF,
  131. BCM57800_VF,
  132. BCM57810,
  133. BCM57810_MF,
  134. BCM57810_VF,
  135. BCM57840_4_10,
  136. BCM57840_2_20,
  137. BCM57840_MF,
  138. BCM57840_VF,
  139. BCM57811,
  140. BCM57811_MF,
  141. BCM57840_O,
  142. BCM57840_MFO,
  143. BCM57811_VF
  144. };
  145. /* indexed by board_type, above */
  146. static struct {
  147. char *name;
  148. } board_info[] = {
  149. [BCM57710] = { "Broadcom NetXtreme II BCM57710 10 Gigabit PCIe [Everest]" },
  150. [BCM57711] = { "Broadcom NetXtreme II BCM57711 10 Gigabit PCIe" },
  151. [BCM57711E] = { "Broadcom NetXtreme II BCM57711E 10 Gigabit PCIe" },
  152. [BCM57712] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet" },
  153. [BCM57712_MF] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Multi Function" },
  154. [BCM57712_VF] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Virtual Function" },
  155. [BCM57800] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet" },
  156. [BCM57800_MF] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Multi Function" },
  157. [BCM57800_VF] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Virtual Function" },
  158. [BCM57810] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet" },
  159. [BCM57810_MF] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Multi Function" },
  160. [BCM57810_VF] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Virtual Function" },
  161. [BCM57840_4_10] = { "Broadcom NetXtreme II BCM57840 10 Gigabit Ethernet" },
  162. [BCM57840_2_20] = { "Broadcom NetXtreme II BCM57840 20 Gigabit Ethernet" },
  163. [BCM57840_MF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function" },
  164. [BCM57840_VF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Virtual Function" },
  165. [BCM57811] = { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet" },
  166. [BCM57811_MF] = { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet Multi Function" },
  167. [BCM57840_O] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet" },
  168. [BCM57840_MFO] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function" },
  169. [BCM57811_VF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Virtual Function" }
  170. };
  171. #ifndef PCI_DEVICE_ID_NX2_57710
  172. #define PCI_DEVICE_ID_NX2_57710 CHIP_NUM_57710
  173. #endif
  174. #ifndef PCI_DEVICE_ID_NX2_57711
  175. #define PCI_DEVICE_ID_NX2_57711 CHIP_NUM_57711
  176. #endif
  177. #ifndef PCI_DEVICE_ID_NX2_57711E
  178. #define PCI_DEVICE_ID_NX2_57711E CHIP_NUM_57711E
  179. #endif
  180. #ifndef PCI_DEVICE_ID_NX2_57712
  181. #define PCI_DEVICE_ID_NX2_57712 CHIP_NUM_57712
  182. #endif
  183. #ifndef PCI_DEVICE_ID_NX2_57712_MF
  184. #define PCI_DEVICE_ID_NX2_57712_MF CHIP_NUM_57712_MF
  185. #endif
  186. #ifndef PCI_DEVICE_ID_NX2_57712_VF
  187. #define PCI_DEVICE_ID_NX2_57712_VF CHIP_NUM_57712_VF
  188. #endif
  189. #ifndef PCI_DEVICE_ID_NX2_57800
  190. #define PCI_DEVICE_ID_NX2_57800 CHIP_NUM_57800
  191. #endif
  192. #ifndef PCI_DEVICE_ID_NX2_57800_MF
  193. #define PCI_DEVICE_ID_NX2_57800_MF CHIP_NUM_57800_MF
  194. #endif
  195. #ifndef PCI_DEVICE_ID_NX2_57800_VF
  196. #define PCI_DEVICE_ID_NX2_57800_VF CHIP_NUM_57800_VF
  197. #endif
  198. #ifndef PCI_DEVICE_ID_NX2_57810
  199. #define PCI_DEVICE_ID_NX2_57810 CHIP_NUM_57810
  200. #endif
  201. #ifndef PCI_DEVICE_ID_NX2_57810_MF
  202. #define PCI_DEVICE_ID_NX2_57810_MF CHIP_NUM_57810_MF
  203. #endif
  204. #ifndef PCI_DEVICE_ID_NX2_57840_O
  205. #define PCI_DEVICE_ID_NX2_57840_O CHIP_NUM_57840_OBSOLETE
  206. #endif
  207. #ifndef PCI_DEVICE_ID_NX2_57810_VF
  208. #define PCI_DEVICE_ID_NX2_57810_VF CHIP_NUM_57810_VF
  209. #endif
  210. #ifndef PCI_DEVICE_ID_NX2_57840_4_10
  211. #define PCI_DEVICE_ID_NX2_57840_4_10 CHIP_NUM_57840_4_10
  212. #endif
  213. #ifndef PCI_DEVICE_ID_NX2_57840_2_20
  214. #define PCI_DEVICE_ID_NX2_57840_2_20 CHIP_NUM_57840_2_20
  215. #endif
  216. #ifndef PCI_DEVICE_ID_NX2_57840_MFO
  217. #define PCI_DEVICE_ID_NX2_57840_MFO CHIP_NUM_57840_MF_OBSOLETE
  218. #endif
  219. #ifndef PCI_DEVICE_ID_NX2_57840_MF
  220. #define PCI_DEVICE_ID_NX2_57840_MF CHIP_NUM_57840_MF
  221. #endif
  222. #ifndef PCI_DEVICE_ID_NX2_57840_VF
  223. #define PCI_DEVICE_ID_NX2_57840_VF CHIP_NUM_57840_VF
  224. #endif
  225. #ifndef PCI_DEVICE_ID_NX2_57811
  226. #define PCI_DEVICE_ID_NX2_57811 CHIP_NUM_57811
  227. #endif
  228. #ifndef PCI_DEVICE_ID_NX2_57811_MF
  229. #define PCI_DEVICE_ID_NX2_57811_MF CHIP_NUM_57811_MF
  230. #endif
  231. #ifndef PCI_DEVICE_ID_NX2_57811_VF
  232. #define PCI_DEVICE_ID_NX2_57811_VF CHIP_NUM_57811_VF
  233. #endif
  234. static DEFINE_PCI_DEVICE_TABLE(bnx2x_pci_tbl) = {
  235. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57710), BCM57710 },
  236. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711), BCM57711 },
  237. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711E), BCM57711E },
  238. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712), BCM57712 },
  239. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_MF), BCM57712_MF },
  240. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_VF), BCM57712_VF },
  241. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800), BCM57800 },
  242. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_MF), BCM57800_MF },
  243. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_VF), BCM57800_VF },
  244. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810), BCM57810 },
  245. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_MF), BCM57810_MF },
  246. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_O), BCM57840_O },
  247. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_4_10), BCM57840_4_10 },
  248. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_2_20), BCM57840_2_20 },
  249. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_VF), BCM57810_VF },
  250. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MFO), BCM57840_MFO },
  251. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MF), BCM57840_MF },
  252. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_VF), BCM57840_VF },
  253. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811), BCM57811 },
  254. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_MF), BCM57811_MF },
  255. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_VF), BCM57811_VF },
  256. { 0 }
  257. };
  258. MODULE_DEVICE_TABLE(pci, bnx2x_pci_tbl);
  259. /* Global resources for unloading a previously loaded device */
  260. #define BNX2X_PREV_WAIT_NEEDED 1
  261. static DEFINE_SEMAPHORE(bnx2x_prev_sem);
  262. static LIST_HEAD(bnx2x_prev_list);
  263. /****************************************************************************
  264. * General service functions
  265. ****************************************************************************/
  266. static void __storm_memset_dma_mapping(struct bnx2x *bp,
  267. u32 addr, dma_addr_t mapping)
  268. {
  269. REG_WR(bp, addr, U64_LO(mapping));
  270. REG_WR(bp, addr + 4, U64_HI(mapping));
  271. }
  272. static void storm_memset_spq_addr(struct bnx2x *bp,
  273. dma_addr_t mapping, u16 abs_fid)
  274. {
  275. u32 addr = XSEM_REG_FAST_MEMORY +
  276. XSTORM_SPQ_PAGE_BASE_OFFSET(abs_fid);
  277. __storm_memset_dma_mapping(bp, addr, mapping);
  278. }
  279. static void storm_memset_vf_to_pf(struct bnx2x *bp, u16 abs_fid,
  280. u16 pf_id)
  281. {
  282. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_VF_TO_PF_OFFSET(abs_fid),
  283. pf_id);
  284. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_VF_TO_PF_OFFSET(abs_fid),
  285. pf_id);
  286. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_VF_TO_PF_OFFSET(abs_fid),
  287. pf_id);
  288. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_VF_TO_PF_OFFSET(abs_fid),
  289. pf_id);
  290. }
  291. static void storm_memset_func_en(struct bnx2x *bp, u16 abs_fid,
  292. u8 enable)
  293. {
  294. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(abs_fid),
  295. enable);
  296. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(abs_fid),
  297. enable);
  298. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(abs_fid),
  299. enable);
  300. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(abs_fid),
  301. enable);
  302. }
  303. static void storm_memset_eq_data(struct bnx2x *bp,
  304. struct event_ring_data *eq_data,
  305. u16 pfid)
  306. {
  307. size_t size = sizeof(struct event_ring_data);
  308. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_DATA_OFFSET(pfid);
  309. __storm_memset_struct(bp, addr, size, (u32 *)eq_data);
  310. }
  311. static void storm_memset_eq_prod(struct bnx2x *bp, u16 eq_prod,
  312. u16 pfid)
  313. {
  314. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_PROD_OFFSET(pfid);
  315. REG_WR16(bp, addr, eq_prod);
  316. }
  317. /* used only at init
  318. * locking is done by mcp
  319. */
  320. static void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val)
  321. {
  322. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  323. pci_write_config_dword(bp->pdev, PCICFG_GRC_DATA, val);
  324. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  325. PCICFG_VENDOR_ID_OFFSET);
  326. }
  327. static u32 bnx2x_reg_rd_ind(struct bnx2x *bp, u32 addr)
  328. {
  329. u32 val;
  330. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  331. pci_read_config_dword(bp->pdev, PCICFG_GRC_DATA, &val);
  332. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  333. PCICFG_VENDOR_ID_OFFSET);
  334. return val;
  335. }
  336. #define DMAE_DP_SRC_GRC "grc src_addr [%08x]"
  337. #define DMAE_DP_SRC_PCI "pci src_addr [%x:%08x]"
  338. #define DMAE_DP_DST_GRC "grc dst_addr [%08x]"
  339. #define DMAE_DP_DST_PCI "pci dst_addr [%x:%08x]"
  340. #define DMAE_DP_DST_NONE "dst_addr [none]"
  341. void bnx2x_dp_dmae(struct bnx2x *bp, struct dmae_command *dmae, int msglvl)
  342. {
  343. u32 src_type = dmae->opcode & DMAE_COMMAND_SRC;
  344. switch (dmae->opcode & DMAE_COMMAND_DST) {
  345. case DMAE_CMD_DST_PCI:
  346. if (src_type == DMAE_CMD_SRC_PCI)
  347. DP(msglvl, "DMAE: opcode 0x%08x\n"
  348. "src [%x:%08x], len [%d*4], dst [%x:%08x]\n"
  349. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  350. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  351. dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
  352. dmae->comp_addr_hi, dmae->comp_addr_lo,
  353. dmae->comp_val);
  354. else
  355. DP(msglvl, "DMAE: opcode 0x%08x\n"
  356. "src [%08x], len [%d*4], dst [%x:%08x]\n"
  357. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  358. dmae->opcode, dmae->src_addr_lo >> 2,
  359. dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
  360. dmae->comp_addr_hi, dmae->comp_addr_lo,
  361. dmae->comp_val);
  362. break;
  363. case DMAE_CMD_DST_GRC:
  364. if (src_type == DMAE_CMD_SRC_PCI)
  365. DP(msglvl, "DMAE: opcode 0x%08x\n"
  366. "src [%x:%08x], len [%d*4], dst_addr [%08x]\n"
  367. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  368. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  369. dmae->len, dmae->dst_addr_lo >> 2,
  370. dmae->comp_addr_hi, dmae->comp_addr_lo,
  371. dmae->comp_val);
  372. else
  373. DP(msglvl, "DMAE: opcode 0x%08x\n"
  374. "src [%08x], len [%d*4], dst [%08x]\n"
  375. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  376. dmae->opcode, dmae->src_addr_lo >> 2,
  377. dmae->len, dmae->dst_addr_lo >> 2,
  378. dmae->comp_addr_hi, dmae->comp_addr_lo,
  379. dmae->comp_val);
  380. break;
  381. default:
  382. if (src_type == DMAE_CMD_SRC_PCI)
  383. DP(msglvl, "DMAE: opcode 0x%08x\n"
  384. "src_addr [%x:%08x] len [%d * 4] dst_addr [none]\n"
  385. "comp_addr [%x:%08x] comp_val 0x%08x\n",
  386. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  387. dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
  388. dmae->comp_val);
  389. else
  390. DP(msglvl, "DMAE: opcode 0x%08x\n"
  391. "src_addr [%08x] len [%d * 4] dst_addr [none]\n"
  392. "comp_addr [%x:%08x] comp_val 0x%08x\n",
  393. dmae->opcode, dmae->src_addr_lo >> 2,
  394. dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
  395. dmae->comp_val);
  396. break;
  397. }
  398. }
  399. /* copy command into DMAE command memory and set DMAE command go */
  400. void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae, int idx)
  401. {
  402. u32 cmd_offset;
  403. int i;
  404. cmd_offset = (DMAE_REG_CMD_MEM + sizeof(struct dmae_command) * idx);
  405. for (i = 0; i < (sizeof(struct dmae_command)/4); i++) {
  406. REG_WR(bp, cmd_offset + i*4, *(((u32 *)dmae) + i));
  407. }
  408. REG_WR(bp, dmae_reg_go_c[idx], 1);
  409. }
  410. u32 bnx2x_dmae_opcode_add_comp(u32 opcode, u8 comp_type)
  411. {
  412. return opcode | ((comp_type << DMAE_COMMAND_C_DST_SHIFT) |
  413. DMAE_CMD_C_ENABLE);
  414. }
  415. u32 bnx2x_dmae_opcode_clr_src_reset(u32 opcode)
  416. {
  417. return opcode & ~DMAE_CMD_SRC_RESET;
  418. }
  419. u32 bnx2x_dmae_opcode(struct bnx2x *bp, u8 src_type, u8 dst_type,
  420. bool with_comp, u8 comp_type)
  421. {
  422. u32 opcode = 0;
  423. opcode |= ((src_type << DMAE_COMMAND_SRC_SHIFT) |
  424. (dst_type << DMAE_COMMAND_DST_SHIFT));
  425. opcode |= (DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET);
  426. opcode |= (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0);
  427. opcode |= ((BP_VN(bp) << DMAE_CMD_E1HVN_SHIFT) |
  428. (BP_VN(bp) << DMAE_COMMAND_DST_VN_SHIFT));
  429. opcode |= (DMAE_COM_SET_ERR << DMAE_COMMAND_ERR_POLICY_SHIFT);
  430. #ifdef __BIG_ENDIAN
  431. opcode |= DMAE_CMD_ENDIANITY_B_DW_SWAP;
  432. #else
  433. opcode |= DMAE_CMD_ENDIANITY_DW_SWAP;
  434. #endif
  435. if (with_comp)
  436. opcode = bnx2x_dmae_opcode_add_comp(opcode, comp_type);
  437. return opcode;
  438. }
  439. void bnx2x_prep_dmae_with_comp(struct bnx2x *bp,
  440. struct dmae_command *dmae,
  441. u8 src_type, u8 dst_type)
  442. {
  443. memset(dmae, 0, sizeof(struct dmae_command));
  444. /* set the opcode */
  445. dmae->opcode = bnx2x_dmae_opcode(bp, src_type, dst_type,
  446. true, DMAE_COMP_PCI);
  447. /* fill in the completion parameters */
  448. dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp));
  449. dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp));
  450. dmae->comp_val = DMAE_COMP_VAL;
  451. }
  452. /* issue a dmae command over the init-channel and wait for completion */
  453. int bnx2x_issue_dmae_with_comp(struct bnx2x *bp, struct dmae_command *dmae)
  454. {
  455. u32 *wb_comp = bnx2x_sp(bp, wb_comp);
  456. int cnt = CHIP_REV_IS_SLOW(bp) ? (400000) : 4000;
  457. int rc = 0;
  458. /*
  459. * Lock the dmae channel. Disable BHs to prevent a dead-lock
  460. * as long as this code is called both from syscall context and
  461. * from ndo_set_rx_mode() flow that may be called from BH.
  462. */
  463. spin_lock_bh(&bp->dmae_lock);
  464. /* reset completion */
  465. *wb_comp = 0;
  466. /* post the command on the channel used for initializations */
  467. bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp));
  468. /* wait for completion */
  469. udelay(5);
  470. while ((*wb_comp & ~DMAE_PCI_ERR_FLAG) != DMAE_COMP_VAL) {
  471. if (!cnt ||
  472. (bp->recovery_state != BNX2X_RECOVERY_DONE &&
  473. bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  474. BNX2X_ERR("DMAE timeout!\n");
  475. rc = DMAE_TIMEOUT;
  476. goto unlock;
  477. }
  478. cnt--;
  479. udelay(50);
  480. }
  481. if (*wb_comp & DMAE_PCI_ERR_FLAG) {
  482. BNX2X_ERR("DMAE PCI error!\n");
  483. rc = DMAE_PCI_ERROR;
  484. }
  485. unlock:
  486. spin_unlock_bh(&bp->dmae_lock);
  487. return rc;
  488. }
  489. void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr,
  490. u32 len32)
  491. {
  492. struct dmae_command dmae;
  493. if (!bp->dmae_ready) {
  494. u32 *data = bnx2x_sp(bp, wb_data[0]);
  495. if (CHIP_IS_E1(bp))
  496. bnx2x_init_ind_wr(bp, dst_addr, data, len32);
  497. else
  498. bnx2x_init_str_wr(bp, dst_addr, data, len32);
  499. return;
  500. }
  501. /* set opcode and fixed command fields */
  502. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_GRC);
  503. /* fill in addresses and len */
  504. dmae.src_addr_lo = U64_LO(dma_addr);
  505. dmae.src_addr_hi = U64_HI(dma_addr);
  506. dmae.dst_addr_lo = dst_addr >> 2;
  507. dmae.dst_addr_hi = 0;
  508. dmae.len = len32;
  509. /* issue the command and wait for completion */
  510. bnx2x_issue_dmae_with_comp(bp, &dmae);
  511. }
  512. void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32)
  513. {
  514. struct dmae_command dmae;
  515. if (!bp->dmae_ready) {
  516. u32 *data = bnx2x_sp(bp, wb_data[0]);
  517. int i;
  518. if (CHIP_IS_E1(bp))
  519. for (i = 0; i < len32; i++)
  520. data[i] = bnx2x_reg_rd_ind(bp, src_addr + i*4);
  521. else
  522. for (i = 0; i < len32; i++)
  523. data[i] = REG_RD(bp, src_addr + i*4);
  524. return;
  525. }
  526. /* set opcode and fixed command fields */
  527. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_GRC, DMAE_DST_PCI);
  528. /* fill in addresses and len */
  529. dmae.src_addr_lo = src_addr >> 2;
  530. dmae.src_addr_hi = 0;
  531. dmae.dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_data));
  532. dmae.dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_data));
  533. dmae.len = len32;
  534. /* issue the command and wait for completion */
  535. bnx2x_issue_dmae_with_comp(bp, &dmae);
  536. }
  537. static void bnx2x_write_dmae_phys_len(struct bnx2x *bp, dma_addr_t phys_addr,
  538. u32 addr, u32 len)
  539. {
  540. int dmae_wr_max = DMAE_LEN32_WR_MAX(bp);
  541. int offset = 0;
  542. while (len > dmae_wr_max) {
  543. bnx2x_write_dmae(bp, phys_addr + offset,
  544. addr + offset, dmae_wr_max);
  545. offset += dmae_wr_max * 4;
  546. len -= dmae_wr_max;
  547. }
  548. bnx2x_write_dmae(bp, phys_addr + offset, addr + offset, len);
  549. }
  550. static int bnx2x_mc_assert(struct bnx2x *bp)
  551. {
  552. char last_idx;
  553. int i, rc = 0;
  554. u32 row0, row1, row2, row3;
  555. /* XSTORM */
  556. last_idx = REG_RD8(bp, BAR_XSTRORM_INTMEM +
  557. XSTORM_ASSERT_LIST_INDEX_OFFSET);
  558. if (last_idx)
  559. BNX2X_ERR("XSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  560. /* print the asserts */
  561. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  562. row0 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  563. XSTORM_ASSERT_LIST_OFFSET(i));
  564. row1 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  565. XSTORM_ASSERT_LIST_OFFSET(i) + 4);
  566. row2 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  567. XSTORM_ASSERT_LIST_OFFSET(i) + 8);
  568. row3 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  569. XSTORM_ASSERT_LIST_OFFSET(i) + 12);
  570. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  571. BNX2X_ERR("XSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  572. i, row3, row2, row1, row0);
  573. rc++;
  574. } else {
  575. break;
  576. }
  577. }
  578. /* TSTORM */
  579. last_idx = REG_RD8(bp, BAR_TSTRORM_INTMEM +
  580. TSTORM_ASSERT_LIST_INDEX_OFFSET);
  581. if (last_idx)
  582. BNX2X_ERR("TSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  583. /* print the asserts */
  584. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  585. row0 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  586. TSTORM_ASSERT_LIST_OFFSET(i));
  587. row1 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  588. TSTORM_ASSERT_LIST_OFFSET(i) + 4);
  589. row2 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  590. TSTORM_ASSERT_LIST_OFFSET(i) + 8);
  591. row3 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  592. TSTORM_ASSERT_LIST_OFFSET(i) + 12);
  593. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  594. BNX2X_ERR("TSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  595. i, row3, row2, row1, row0);
  596. rc++;
  597. } else {
  598. break;
  599. }
  600. }
  601. /* CSTORM */
  602. last_idx = REG_RD8(bp, BAR_CSTRORM_INTMEM +
  603. CSTORM_ASSERT_LIST_INDEX_OFFSET);
  604. if (last_idx)
  605. BNX2X_ERR("CSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  606. /* print the asserts */
  607. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  608. row0 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  609. CSTORM_ASSERT_LIST_OFFSET(i));
  610. row1 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  611. CSTORM_ASSERT_LIST_OFFSET(i) + 4);
  612. row2 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  613. CSTORM_ASSERT_LIST_OFFSET(i) + 8);
  614. row3 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  615. CSTORM_ASSERT_LIST_OFFSET(i) + 12);
  616. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  617. BNX2X_ERR("CSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  618. i, row3, row2, row1, row0);
  619. rc++;
  620. } else {
  621. break;
  622. }
  623. }
  624. /* USTORM */
  625. last_idx = REG_RD8(bp, BAR_USTRORM_INTMEM +
  626. USTORM_ASSERT_LIST_INDEX_OFFSET);
  627. if (last_idx)
  628. BNX2X_ERR("USTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  629. /* print the asserts */
  630. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  631. row0 = REG_RD(bp, BAR_USTRORM_INTMEM +
  632. USTORM_ASSERT_LIST_OFFSET(i));
  633. row1 = REG_RD(bp, BAR_USTRORM_INTMEM +
  634. USTORM_ASSERT_LIST_OFFSET(i) + 4);
  635. row2 = REG_RD(bp, BAR_USTRORM_INTMEM +
  636. USTORM_ASSERT_LIST_OFFSET(i) + 8);
  637. row3 = REG_RD(bp, BAR_USTRORM_INTMEM +
  638. USTORM_ASSERT_LIST_OFFSET(i) + 12);
  639. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  640. BNX2X_ERR("USTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  641. i, row3, row2, row1, row0);
  642. rc++;
  643. } else {
  644. break;
  645. }
  646. }
  647. return rc;
  648. }
  649. void bnx2x_fw_dump_lvl(struct bnx2x *bp, const char *lvl)
  650. {
  651. u32 addr, val;
  652. u32 mark, offset;
  653. __be32 data[9];
  654. int word;
  655. u32 trace_shmem_base;
  656. if (BP_NOMCP(bp)) {
  657. BNX2X_ERR("NO MCP - can not dump\n");
  658. return;
  659. }
  660. netdev_printk(lvl, bp->dev, "bc %d.%d.%d\n",
  661. (bp->common.bc_ver & 0xff0000) >> 16,
  662. (bp->common.bc_ver & 0xff00) >> 8,
  663. (bp->common.bc_ver & 0xff));
  664. val = REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER);
  665. if (val == REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER))
  666. BNX2X_ERR("%s" "MCP PC at 0x%x\n", lvl, val);
  667. if (BP_PATH(bp) == 0)
  668. trace_shmem_base = bp->common.shmem_base;
  669. else
  670. trace_shmem_base = SHMEM2_RD(bp, other_shmem_base_addr);
  671. addr = trace_shmem_base - 0x800;
  672. /* validate TRCB signature */
  673. mark = REG_RD(bp, addr);
  674. if (mark != MFW_TRACE_SIGNATURE) {
  675. BNX2X_ERR("Trace buffer signature is missing.");
  676. return ;
  677. }
  678. /* read cyclic buffer pointer */
  679. addr += 4;
  680. mark = REG_RD(bp, addr);
  681. mark = (CHIP_IS_E1x(bp) ? MCP_REG_MCPR_SCRATCH : MCP_A_REG_MCPR_SCRATCH)
  682. + ((mark + 0x3) & ~0x3) - 0x08000000;
  683. printk("%s" "begin fw dump (mark 0x%x)\n", lvl, mark);
  684. printk("%s", lvl);
  685. for (offset = mark; offset <= trace_shmem_base; offset += 0x8*4) {
  686. for (word = 0; word < 8; word++)
  687. data[word] = htonl(REG_RD(bp, offset + 4*word));
  688. data[8] = 0x0;
  689. pr_cont("%s", (char *)data);
  690. }
  691. for (offset = addr + 4; offset <= mark; offset += 0x8*4) {
  692. for (word = 0; word < 8; word++)
  693. data[word] = htonl(REG_RD(bp, offset + 4*word));
  694. data[8] = 0x0;
  695. pr_cont("%s", (char *)data);
  696. }
  697. printk("%s" "end of fw dump\n", lvl);
  698. }
  699. static void bnx2x_fw_dump(struct bnx2x *bp)
  700. {
  701. bnx2x_fw_dump_lvl(bp, KERN_ERR);
  702. }
  703. void bnx2x_panic_dump(struct bnx2x *bp)
  704. {
  705. int i;
  706. u16 j;
  707. struct hc_sp_status_block_data sp_sb_data;
  708. int func = BP_FUNC(bp);
  709. #ifdef BNX2X_STOP_ON_ERROR
  710. u16 start = 0, end = 0;
  711. u8 cos;
  712. #endif
  713. bp->stats_state = STATS_STATE_DISABLED;
  714. bp->eth_stats.unrecoverable_error++;
  715. DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n");
  716. BNX2X_ERR("begin crash dump -----------------\n");
  717. /* Indices */
  718. /* Common */
  719. 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",
  720. bp->def_idx, bp->def_att_idx, bp->attn_state,
  721. bp->spq_prod_idx, bp->stats_counter);
  722. BNX2X_ERR("DSB: attn bits(0x%x) ack(0x%x) id(0x%x) idx(0x%x)\n",
  723. bp->def_status_blk->atten_status_block.attn_bits,
  724. bp->def_status_blk->atten_status_block.attn_bits_ack,
  725. bp->def_status_blk->atten_status_block.status_block_id,
  726. bp->def_status_blk->atten_status_block.attn_bits_index);
  727. BNX2X_ERR(" def (");
  728. for (i = 0; i < HC_SP_SB_MAX_INDICES; i++)
  729. pr_cont("0x%x%s",
  730. bp->def_status_blk->sp_sb.index_values[i],
  731. (i == HC_SP_SB_MAX_INDICES - 1) ? ") " : " ");
  732. for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
  733. *((u32 *)&sp_sb_data + i) = REG_RD(bp, BAR_CSTRORM_INTMEM +
  734. CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
  735. i*sizeof(u32));
  736. 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",
  737. sp_sb_data.igu_sb_id,
  738. sp_sb_data.igu_seg_id,
  739. sp_sb_data.p_func.pf_id,
  740. sp_sb_data.p_func.vnic_id,
  741. sp_sb_data.p_func.vf_id,
  742. sp_sb_data.p_func.vf_valid,
  743. sp_sb_data.state);
  744. for_each_eth_queue(bp, i) {
  745. struct bnx2x_fastpath *fp = &bp->fp[i];
  746. int loop;
  747. struct hc_status_block_data_e2 sb_data_e2;
  748. struct hc_status_block_data_e1x sb_data_e1x;
  749. struct hc_status_block_sm *hc_sm_p =
  750. CHIP_IS_E1x(bp) ?
  751. sb_data_e1x.common.state_machine :
  752. sb_data_e2.common.state_machine;
  753. struct hc_index_data *hc_index_p =
  754. CHIP_IS_E1x(bp) ?
  755. sb_data_e1x.index_data :
  756. sb_data_e2.index_data;
  757. u8 data_size, cos;
  758. u32 *sb_data_p;
  759. struct bnx2x_fp_txdata txdata;
  760. /* Rx */
  761. 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",
  762. i, fp->rx_bd_prod, fp->rx_bd_cons,
  763. fp->rx_comp_prod,
  764. fp->rx_comp_cons, le16_to_cpu(*fp->rx_cons_sb));
  765. BNX2X_ERR(" rx_sge_prod(0x%x) last_max_sge(0x%x) fp_hc_idx(0x%x)\n",
  766. fp->rx_sge_prod, fp->last_max_sge,
  767. le16_to_cpu(fp->fp_hc_idx));
  768. /* Tx */
  769. for_each_cos_in_tx_queue(fp, cos)
  770. {
  771. txdata = *fp->txdata_ptr[cos];
  772. 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",
  773. i, txdata.tx_pkt_prod,
  774. txdata.tx_pkt_cons, txdata.tx_bd_prod,
  775. txdata.tx_bd_cons,
  776. le16_to_cpu(*txdata.tx_cons_sb));
  777. }
  778. loop = CHIP_IS_E1x(bp) ?
  779. HC_SB_MAX_INDICES_E1X : HC_SB_MAX_INDICES_E2;
  780. /* host sb data */
  781. if (IS_FCOE_FP(fp))
  782. continue;
  783. BNX2X_ERR(" run indexes (");
  784. for (j = 0; j < HC_SB_MAX_SM; j++)
  785. pr_cont("0x%x%s",
  786. fp->sb_running_index[j],
  787. (j == HC_SB_MAX_SM - 1) ? ")" : " ");
  788. BNX2X_ERR(" indexes (");
  789. for (j = 0; j < loop; j++)
  790. pr_cont("0x%x%s",
  791. fp->sb_index_values[j],
  792. (j == loop - 1) ? ")" : " ");
  793. /* fw sb data */
  794. data_size = CHIP_IS_E1x(bp) ?
  795. sizeof(struct hc_status_block_data_e1x) :
  796. sizeof(struct hc_status_block_data_e2);
  797. data_size /= sizeof(u32);
  798. sb_data_p = CHIP_IS_E1x(bp) ?
  799. (u32 *)&sb_data_e1x :
  800. (u32 *)&sb_data_e2;
  801. /* copy sb data in here */
  802. for (j = 0; j < data_size; j++)
  803. *(sb_data_p + j) = REG_RD(bp, BAR_CSTRORM_INTMEM +
  804. CSTORM_STATUS_BLOCK_DATA_OFFSET(fp->fw_sb_id) +
  805. j * sizeof(u32));
  806. if (!CHIP_IS_E1x(bp)) {
  807. 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",
  808. sb_data_e2.common.p_func.pf_id,
  809. sb_data_e2.common.p_func.vf_id,
  810. sb_data_e2.common.p_func.vf_valid,
  811. sb_data_e2.common.p_func.vnic_id,
  812. sb_data_e2.common.same_igu_sb_1b,
  813. sb_data_e2.common.state);
  814. } else {
  815. 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",
  816. sb_data_e1x.common.p_func.pf_id,
  817. sb_data_e1x.common.p_func.vf_id,
  818. sb_data_e1x.common.p_func.vf_valid,
  819. sb_data_e1x.common.p_func.vnic_id,
  820. sb_data_e1x.common.same_igu_sb_1b,
  821. sb_data_e1x.common.state);
  822. }
  823. /* SB_SMs data */
  824. for (j = 0; j < HC_SB_MAX_SM; j++) {
  825. 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",
  826. j, hc_sm_p[j].__flags,
  827. hc_sm_p[j].igu_sb_id,
  828. hc_sm_p[j].igu_seg_id,
  829. hc_sm_p[j].time_to_expire,
  830. hc_sm_p[j].timer_value);
  831. }
  832. /* Indecies data */
  833. for (j = 0; j < loop; j++) {
  834. pr_cont("INDEX[%d] flags (0x%x) timeout (0x%x)\n", j,
  835. hc_index_p[j].flags,
  836. hc_index_p[j].timeout);
  837. }
  838. }
  839. #ifdef BNX2X_STOP_ON_ERROR
  840. /* Rings */
  841. /* Rx */
  842. for_each_valid_rx_queue(bp, i) {
  843. struct bnx2x_fastpath *fp = &bp->fp[i];
  844. start = RX_BD(le16_to_cpu(*fp->rx_cons_sb) - 10);
  845. end = RX_BD(le16_to_cpu(*fp->rx_cons_sb) + 503);
  846. for (j = start; j != end; j = RX_BD(j + 1)) {
  847. u32 *rx_bd = (u32 *)&fp->rx_desc_ring[j];
  848. struct sw_rx_bd *sw_bd = &fp->rx_buf_ring[j];
  849. BNX2X_ERR("fp%d: rx_bd[%x]=[%x:%x] sw_bd=[%p]\n",
  850. i, j, rx_bd[1], rx_bd[0], sw_bd->data);
  851. }
  852. start = RX_SGE(fp->rx_sge_prod);
  853. end = RX_SGE(fp->last_max_sge);
  854. for (j = start; j != end; j = RX_SGE(j + 1)) {
  855. u32 *rx_sge = (u32 *)&fp->rx_sge_ring[j];
  856. struct sw_rx_page *sw_page = &fp->rx_page_ring[j];
  857. BNX2X_ERR("fp%d: rx_sge[%x]=[%x:%x] sw_page=[%p]\n",
  858. i, j, rx_sge[1], rx_sge[0], sw_page->page);
  859. }
  860. start = RCQ_BD(fp->rx_comp_cons - 10);
  861. end = RCQ_BD(fp->rx_comp_cons + 503);
  862. for (j = start; j != end; j = RCQ_BD(j + 1)) {
  863. u32 *cqe = (u32 *)&fp->rx_comp_ring[j];
  864. BNX2X_ERR("fp%d: cqe[%x]=[%x:%x:%x:%x]\n",
  865. i, j, cqe[0], cqe[1], cqe[2], cqe[3]);
  866. }
  867. }
  868. /* Tx */
  869. for_each_valid_tx_queue(bp, i) {
  870. struct bnx2x_fastpath *fp = &bp->fp[i];
  871. for_each_cos_in_tx_queue(fp, cos) {
  872. struct bnx2x_fp_txdata *txdata = fp->txdata_ptr[cos];
  873. start = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) - 10);
  874. end = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) + 245);
  875. for (j = start; j != end; j = TX_BD(j + 1)) {
  876. struct sw_tx_bd *sw_bd =
  877. &txdata->tx_buf_ring[j];
  878. BNX2X_ERR("fp%d: txdata %d, packet[%x]=[%p,%x]\n",
  879. i, cos, j, sw_bd->skb,
  880. sw_bd->first_bd);
  881. }
  882. start = TX_BD(txdata->tx_bd_cons - 10);
  883. end = TX_BD(txdata->tx_bd_cons + 254);
  884. for (j = start; j != end; j = TX_BD(j + 1)) {
  885. u32 *tx_bd = (u32 *)&txdata->tx_desc_ring[j];
  886. BNX2X_ERR("fp%d: txdata %d, tx_bd[%x]=[%x:%x:%x:%x]\n",
  887. i, cos, j, tx_bd[0], tx_bd[1],
  888. tx_bd[2], tx_bd[3]);
  889. }
  890. }
  891. }
  892. #endif
  893. bnx2x_fw_dump(bp);
  894. bnx2x_mc_assert(bp);
  895. BNX2X_ERR("end crash dump -----------------\n");
  896. }
  897. /*
  898. * FLR Support for E2
  899. *
  900. * bnx2x_pf_flr_clnup() is called during nic_load in the per function HW
  901. * initialization.
  902. */
  903. #define FLR_WAIT_USEC 10000 /* 10 miliseconds */
  904. #define FLR_WAIT_INTERVAL 50 /* usec */
  905. #define FLR_POLL_CNT (FLR_WAIT_USEC/FLR_WAIT_INTERVAL) /* 200 */
  906. struct pbf_pN_buf_regs {
  907. int pN;
  908. u32 init_crd;
  909. u32 crd;
  910. u32 crd_freed;
  911. };
  912. struct pbf_pN_cmd_regs {
  913. int pN;
  914. u32 lines_occup;
  915. u32 lines_freed;
  916. };
  917. static void bnx2x_pbf_pN_buf_flushed(struct bnx2x *bp,
  918. struct pbf_pN_buf_regs *regs,
  919. u32 poll_count)
  920. {
  921. u32 init_crd, crd, crd_start, crd_freed, crd_freed_start;
  922. u32 cur_cnt = poll_count;
  923. crd_freed = crd_freed_start = REG_RD(bp, regs->crd_freed);
  924. crd = crd_start = REG_RD(bp, regs->crd);
  925. init_crd = REG_RD(bp, regs->init_crd);
  926. DP(BNX2X_MSG_SP, "INIT CREDIT[%d] : %x\n", regs->pN, init_crd);
  927. DP(BNX2X_MSG_SP, "CREDIT[%d] : s:%x\n", regs->pN, crd);
  928. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: s:%x\n", regs->pN, crd_freed);
  929. while ((crd != init_crd) && ((u32)SUB_S32(crd_freed, crd_freed_start) <
  930. (init_crd - crd_start))) {
  931. if (cur_cnt--) {
  932. udelay(FLR_WAIT_INTERVAL);
  933. crd = REG_RD(bp, regs->crd);
  934. crd_freed = REG_RD(bp, regs->crd_freed);
  935. } else {
  936. DP(BNX2X_MSG_SP, "PBF tx buffer[%d] timed out\n",
  937. regs->pN);
  938. DP(BNX2X_MSG_SP, "CREDIT[%d] : c:%x\n",
  939. regs->pN, crd);
  940. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: c:%x\n",
  941. regs->pN, crd_freed);
  942. break;
  943. }
  944. }
  945. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF tx buffer[%d]\n",
  946. poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
  947. }
  948. static void bnx2x_pbf_pN_cmd_flushed(struct bnx2x *bp,
  949. struct pbf_pN_cmd_regs *regs,
  950. u32 poll_count)
  951. {
  952. u32 occup, to_free, freed, freed_start;
  953. u32 cur_cnt = poll_count;
  954. occup = to_free = REG_RD(bp, regs->lines_occup);
  955. freed = freed_start = REG_RD(bp, regs->lines_freed);
  956. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n", regs->pN, occup);
  957. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n", regs->pN, freed);
  958. while (occup && ((u32)SUB_S32(freed, freed_start) < to_free)) {
  959. if (cur_cnt--) {
  960. udelay(FLR_WAIT_INTERVAL);
  961. occup = REG_RD(bp, regs->lines_occup);
  962. freed = REG_RD(bp, regs->lines_freed);
  963. } else {
  964. DP(BNX2X_MSG_SP, "PBF cmd queue[%d] timed out\n",
  965. regs->pN);
  966. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n",
  967. regs->pN, occup);
  968. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n",
  969. regs->pN, freed);
  970. break;
  971. }
  972. }
  973. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF cmd queue[%d]\n",
  974. poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
  975. }
  976. static u32 bnx2x_flr_clnup_reg_poll(struct bnx2x *bp, u32 reg,
  977. u32 expected, u32 poll_count)
  978. {
  979. u32 cur_cnt = poll_count;
  980. u32 val;
  981. while ((val = REG_RD(bp, reg)) != expected && cur_cnt--)
  982. udelay(FLR_WAIT_INTERVAL);
  983. return val;
  984. }
  985. int bnx2x_flr_clnup_poll_hw_counter(struct bnx2x *bp, u32 reg,
  986. char *msg, u32 poll_cnt)
  987. {
  988. u32 val = bnx2x_flr_clnup_reg_poll(bp, reg, 0, poll_cnt);
  989. if (val != 0) {
  990. BNX2X_ERR("%s usage count=%d\n", msg, val);
  991. return 1;
  992. }
  993. return 0;
  994. }
  995. /* Common routines with VF FLR cleanup */
  996. u32 bnx2x_flr_clnup_poll_count(struct bnx2x *bp)
  997. {
  998. /* adjust polling timeout */
  999. if (CHIP_REV_IS_EMUL(bp))
  1000. return FLR_POLL_CNT * 2000;
  1001. if (CHIP_REV_IS_FPGA(bp))
  1002. return FLR_POLL_CNT * 120;
  1003. return FLR_POLL_CNT;
  1004. }
  1005. void bnx2x_tx_hw_flushed(struct bnx2x *bp, u32 poll_count)
  1006. {
  1007. struct pbf_pN_cmd_regs cmd_regs[] = {
  1008. {0, (CHIP_IS_E3B0(bp)) ?
  1009. PBF_REG_TQ_OCCUPANCY_Q0 :
  1010. PBF_REG_P0_TQ_OCCUPANCY,
  1011. (CHIP_IS_E3B0(bp)) ?
  1012. PBF_REG_TQ_LINES_FREED_CNT_Q0 :
  1013. PBF_REG_P0_TQ_LINES_FREED_CNT},
  1014. {1, (CHIP_IS_E3B0(bp)) ?
  1015. PBF_REG_TQ_OCCUPANCY_Q1 :
  1016. PBF_REG_P1_TQ_OCCUPANCY,
  1017. (CHIP_IS_E3B0(bp)) ?
  1018. PBF_REG_TQ_LINES_FREED_CNT_Q1 :
  1019. PBF_REG_P1_TQ_LINES_FREED_CNT},
  1020. {4, (CHIP_IS_E3B0(bp)) ?
  1021. PBF_REG_TQ_OCCUPANCY_LB_Q :
  1022. PBF_REG_P4_TQ_OCCUPANCY,
  1023. (CHIP_IS_E3B0(bp)) ?
  1024. PBF_REG_TQ_LINES_FREED_CNT_LB_Q :
  1025. PBF_REG_P4_TQ_LINES_FREED_CNT}
  1026. };
  1027. struct pbf_pN_buf_regs buf_regs[] = {
  1028. {0, (CHIP_IS_E3B0(bp)) ?
  1029. PBF_REG_INIT_CRD_Q0 :
  1030. PBF_REG_P0_INIT_CRD ,
  1031. (CHIP_IS_E3B0(bp)) ?
  1032. PBF_REG_CREDIT_Q0 :
  1033. PBF_REG_P0_CREDIT,
  1034. (CHIP_IS_E3B0(bp)) ?
  1035. PBF_REG_INTERNAL_CRD_FREED_CNT_Q0 :
  1036. PBF_REG_P0_INTERNAL_CRD_FREED_CNT},
  1037. {1, (CHIP_IS_E3B0(bp)) ?
  1038. PBF_REG_INIT_CRD_Q1 :
  1039. PBF_REG_P1_INIT_CRD,
  1040. (CHIP_IS_E3B0(bp)) ?
  1041. PBF_REG_CREDIT_Q1 :
  1042. PBF_REG_P1_CREDIT,
  1043. (CHIP_IS_E3B0(bp)) ?
  1044. PBF_REG_INTERNAL_CRD_FREED_CNT_Q1 :
  1045. PBF_REG_P1_INTERNAL_CRD_FREED_CNT},
  1046. {4, (CHIP_IS_E3B0(bp)) ?
  1047. PBF_REG_INIT_CRD_LB_Q :
  1048. PBF_REG_P4_INIT_CRD,
  1049. (CHIP_IS_E3B0(bp)) ?
  1050. PBF_REG_CREDIT_LB_Q :
  1051. PBF_REG_P4_CREDIT,
  1052. (CHIP_IS_E3B0(bp)) ?
  1053. PBF_REG_INTERNAL_CRD_FREED_CNT_LB_Q :
  1054. PBF_REG_P4_INTERNAL_CRD_FREED_CNT},
  1055. };
  1056. int i;
  1057. /* Verify the command queues are flushed P0, P1, P4 */
  1058. for (i = 0; i < ARRAY_SIZE(cmd_regs); i++)
  1059. bnx2x_pbf_pN_cmd_flushed(bp, &cmd_regs[i], poll_count);
  1060. /* Verify the transmission buffers are flushed P0, P1, P4 */
  1061. for (i = 0; i < ARRAY_SIZE(buf_regs); i++)
  1062. bnx2x_pbf_pN_buf_flushed(bp, &buf_regs[i], poll_count);
  1063. }
  1064. #define OP_GEN_PARAM(param) \
  1065. (((param) << SDM_OP_GEN_COMP_PARAM_SHIFT) & SDM_OP_GEN_COMP_PARAM)
  1066. #define OP_GEN_TYPE(type) \
  1067. (((type) << SDM_OP_GEN_COMP_TYPE_SHIFT) & SDM_OP_GEN_COMP_TYPE)
  1068. #define OP_GEN_AGG_VECT(index) \
  1069. (((index) << SDM_OP_GEN_AGG_VECT_IDX_SHIFT) & SDM_OP_GEN_AGG_VECT_IDX)
  1070. int bnx2x_send_final_clnup(struct bnx2x *bp, u8 clnup_func, u32 poll_cnt)
  1071. {
  1072. struct sdm_op_gen op_gen = {0};
  1073. u32 comp_addr = BAR_CSTRORM_INTMEM +
  1074. CSTORM_FINAL_CLEANUP_COMPLETE_OFFSET(clnup_func);
  1075. int ret = 0;
  1076. if (REG_RD(bp, comp_addr)) {
  1077. BNX2X_ERR("Cleanup complete was not 0 before sending\n");
  1078. return 1;
  1079. }
  1080. op_gen.command |= OP_GEN_PARAM(XSTORM_AGG_INT_FINAL_CLEANUP_INDEX);
  1081. op_gen.command |= OP_GEN_TYPE(XSTORM_AGG_INT_FINAL_CLEANUP_COMP_TYPE);
  1082. op_gen.command |= OP_GEN_AGG_VECT(clnup_func);
  1083. op_gen.command |= 1 << SDM_OP_GEN_AGG_VECT_IDX_VALID_SHIFT;
  1084. DP(BNX2X_MSG_SP, "sending FW Final cleanup\n");
  1085. REG_WR(bp, XSDM_REG_OPERATION_GEN, op_gen.command);
  1086. if (bnx2x_flr_clnup_reg_poll(bp, comp_addr, 1, poll_cnt) != 1) {
  1087. BNX2X_ERR("FW final cleanup did not succeed\n");
  1088. DP(BNX2X_MSG_SP, "At timeout completion address contained %x\n",
  1089. (REG_RD(bp, comp_addr)));
  1090. bnx2x_panic();
  1091. return 1;
  1092. }
  1093. /* Zero completion for nxt FLR */
  1094. REG_WR(bp, comp_addr, 0);
  1095. return ret;
  1096. }
  1097. u8 bnx2x_is_pcie_pending(struct pci_dev *dev)
  1098. {
  1099. u16 status;
  1100. pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status);
  1101. return status & PCI_EXP_DEVSTA_TRPND;
  1102. }
  1103. /* PF FLR specific routines
  1104. */
  1105. static int bnx2x_poll_hw_usage_counters(struct bnx2x *bp, u32 poll_cnt)
  1106. {
  1107. /* wait for CFC PF usage-counter to zero (includes all the VFs) */
  1108. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1109. CFC_REG_NUM_LCIDS_INSIDE_PF,
  1110. "CFC PF usage counter timed out",
  1111. poll_cnt))
  1112. return 1;
  1113. /* Wait for DQ PF usage-counter to zero (until DQ cleanup) */
  1114. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1115. DORQ_REG_PF_USAGE_CNT,
  1116. "DQ PF usage counter timed out",
  1117. poll_cnt))
  1118. return 1;
  1119. /* Wait for QM PF usage-counter to zero (until DQ cleanup) */
  1120. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1121. QM_REG_PF_USG_CNT_0 + 4*BP_FUNC(bp),
  1122. "QM PF usage counter timed out",
  1123. poll_cnt))
  1124. return 1;
  1125. /* Wait for Timer PF usage-counters to zero (until DQ cleanup) */
  1126. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1127. TM_REG_LIN0_VNIC_UC + 4*BP_PORT(bp),
  1128. "Timers VNIC usage counter timed out",
  1129. poll_cnt))
  1130. return 1;
  1131. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1132. TM_REG_LIN0_NUM_SCANS + 4*BP_PORT(bp),
  1133. "Timers NUM_SCANS usage counter timed out",
  1134. poll_cnt))
  1135. return 1;
  1136. /* Wait DMAE PF usage counter to zero */
  1137. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1138. dmae_reg_go_c[INIT_DMAE_C(bp)],
  1139. "DMAE dommand register timed out",
  1140. poll_cnt))
  1141. return 1;
  1142. return 0;
  1143. }
  1144. static void bnx2x_hw_enable_status(struct bnx2x *bp)
  1145. {
  1146. u32 val;
  1147. val = REG_RD(bp, CFC_REG_WEAK_ENABLE_PF);
  1148. DP(BNX2X_MSG_SP, "CFC_REG_WEAK_ENABLE_PF is 0x%x\n", val);
  1149. val = REG_RD(bp, PBF_REG_DISABLE_PF);
  1150. DP(BNX2X_MSG_SP, "PBF_REG_DISABLE_PF is 0x%x\n", val);
  1151. val = REG_RD(bp, IGU_REG_PCI_PF_MSI_EN);
  1152. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSI_EN is 0x%x\n", val);
  1153. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_EN);
  1154. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_EN is 0x%x\n", val);
  1155. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_FUNC_MASK);
  1156. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_FUNC_MASK is 0x%x\n", val);
  1157. val = REG_RD(bp, PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR);
  1158. DP(BNX2X_MSG_SP, "PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR is 0x%x\n", val);
  1159. val = REG_RD(bp, PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR);
  1160. DP(BNX2X_MSG_SP, "PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR is 0x%x\n", val);
  1161. val = REG_RD(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
  1162. DP(BNX2X_MSG_SP, "PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER is 0x%x\n",
  1163. val);
  1164. }
  1165. static int bnx2x_pf_flr_clnup(struct bnx2x *bp)
  1166. {
  1167. u32 poll_cnt = bnx2x_flr_clnup_poll_count(bp);
  1168. DP(BNX2X_MSG_SP, "Cleanup after FLR PF[%d]\n", BP_ABS_FUNC(bp));
  1169. /* Re-enable PF target read access */
  1170. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  1171. /* Poll HW usage counters */
  1172. DP(BNX2X_MSG_SP, "Polling usage counters\n");
  1173. if (bnx2x_poll_hw_usage_counters(bp, poll_cnt))
  1174. return -EBUSY;
  1175. /* Zero the igu 'trailing edge' and 'leading edge' */
  1176. /* Send the FW cleanup command */
  1177. if (bnx2x_send_final_clnup(bp, (u8)BP_FUNC(bp), poll_cnt))
  1178. return -EBUSY;
  1179. /* ATC cleanup */
  1180. /* Verify TX hw is flushed */
  1181. bnx2x_tx_hw_flushed(bp, poll_cnt);
  1182. /* Wait 100ms (not adjusted according to platform) */
  1183. msleep(100);
  1184. /* Verify no pending pci transactions */
  1185. if (bnx2x_is_pcie_pending(bp->pdev))
  1186. BNX2X_ERR("PCIE Transactions still pending\n");
  1187. /* Debug */
  1188. bnx2x_hw_enable_status(bp);
  1189. /*
  1190. * Master enable - Due to WB DMAE writes performed before this
  1191. * register is re-initialized as part of the regular function init
  1192. */
  1193. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  1194. return 0;
  1195. }
  1196. static void bnx2x_hc_int_enable(struct bnx2x *bp)
  1197. {
  1198. int port = BP_PORT(bp);
  1199. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  1200. u32 val = REG_RD(bp, addr);
  1201. bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
  1202. bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
  1203. bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
  1204. if (msix) {
  1205. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1206. HC_CONFIG_0_REG_INT_LINE_EN_0);
  1207. val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1208. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1209. if (single_msix)
  1210. val |= HC_CONFIG_0_REG_SINGLE_ISR_EN_0;
  1211. } else if (msi) {
  1212. val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0;
  1213. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1214. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1215. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1216. } else {
  1217. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1218. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1219. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  1220. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1221. if (!CHIP_IS_E1(bp)) {
  1222. DP(NETIF_MSG_IFUP,
  1223. "write %x to HC %d (addr 0x%x)\n", val, port, addr);
  1224. REG_WR(bp, addr, val);
  1225. val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0;
  1226. }
  1227. }
  1228. if (CHIP_IS_E1(bp))
  1229. REG_WR(bp, HC_REG_INT_MASK + port*4, 0x1FFFF);
  1230. DP(NETIF_MSG_IFUP,
  1231. "write %x to HC %d (addr 0x%x) mode %s\n", val, port, addr,
  1232. (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1233. REG_WR(bp, addr, val);
  1234. /*
  1235. * Ensure that HC_CONFIG is written before leading/trailing edge config
  1236. */
  1237. mmiowb();
  1238. barrier();
  1239. if (!CHIP_IS_E1(bp)) {
  1240. /* init leading/trailing edge */
  1241. if (IS_MF(bp)) {
  1242. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1243. if (bp->port.pmf)
  1244. /* enable nig and gpio3 attention */
  1245. val |= 0x1100;
  1246. } else
  1247. val = 0xffff;
  1248. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  1249. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  1250. }
  1251. /* Make sure that interrupts are indeed enabled from here on */
  1252. mmiowb();
  1253. }
  1254. static void bnx2x_igu_int_enable(struct bnx2x *bp)
  1255. {
  1256. u32 val;
  1257. bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
  1258. bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
  1259. bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
  1260. val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  1261. if (msix) {
  1262. val &= ~(IGU_PF_CONF_INT_LINE_EN |
  1263. IGU_PF_CONF_SINGLE_ISR_EN);
  1264. val |= (IGU_PF_CONF_FUNC_EN |
  1265. IGU_PF_CONF_MSI_MSIX_EN |
  1266. IGU_PF_CONF_ATTN_BIT_EN);
  1267. if (single_msix)
  1268. val |= IGU_PF_CONF_SINGLE_ISR_EN;
  1269. } else if (msi) {
  1270. val &= ~IGU_PF_CONF_INT_LINE_EN;
  1271. val |= (IGU_PF_CONF_FUNC_EN |
  1272. IGU_PF_CONF_MSI_MSIX_EN |
  1273. IGU_PF_CONF_ATTN_BIT_EN |
  1274. IGU_PF_CONF_SINGLE_ISR_EN);
  1275. } else {
  1276. val &= ~IGU_PF_CONF_MSI_MSIX_EN;
  1277. val |= (IGU_PF_CONF_FUNC_EN |
  1278. IGU_PF_CONF_INT_LINE_EN |
  1279. IGU_PF_CONF_ATTN_BIT_EN |
  1280. IGU_PF_CONF_SINGLE_ISR_EN);
  1281. }
  1282. DP(NETIF_MSG_IFUP, "write 0x%x to IGU mode %s\n",
  1283. val, (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1284. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1285. if (val & IGU_PF_CONF_INT_LINE_EN)
  1286. pci_intx(bp->pdev, true);
  1287. barrier();
  1288. /* init leading/trailing edge */
  1289. if (IS_MF(bp)) {
  1290. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1291. if (bp->port.pmf)
  1292. /* enable nig and gpio3 attention */
  1293. val |= 0x1100;
  1294. } else
  1295. val = 0xffff;
  1296. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  1297. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  1298. /* Make sure that interrupts are indeed enabled from here on */
  1299. mmiowb();
  1300. }
  1301. void bnx2x_int_enable(struct bnx2x *bp)
  1302. {
  1303. if (bp->common.int_block == INT_BLOCK_HC)
  1304. bnx2x_hc_int_enable(bp);
  1305. else
  1306. bnx2x_igu_int_enable(bp);
  1307. }
  1308. static void bnx2x_hc_int_disable(struct bnx2x *bp)
  1309. {
  1310. int port = BP_PORT(bp);
  1311. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  1312. u32 val = REG_RD(bp, addr);
  1313. /*
  1314. * in E1 we must use only PCI configuration space to disable
  1315. * MSI/MSIX capablility
  1316. * It's forbitten to disable IGU_PF_CONF_MSI_MSIX_EN in HC block
  1317. */
  1318. if (CHIP_IS_E1(bp)) {
  1319. /* Since IGU_PF_CONF_MSI_MSIX_EN still always on
  1320. * Use mask register to prevent from HC sending interrupts
  1321. * after we exit the function
  1322. */
  1323. REG_WR(bp, HC_REG_INT_MASK + port*4, 0);
  1324. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1325. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  1326. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1327. } else
  1328. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1329. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1330. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  1331. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1332. DP(NETIF_MSG_IFDOWN,
  1333. "write %x to HC %d (addr 0x%x)\n",
  1334. val, port, addr);
  1335. /* flush all outstanding writes */
  1336. mmiowb();
  1337. REG_WR(bp, addr, val);
  1338. if (REG_RD(bp, addr) != val)
  1339. BNX2X_ERR("BUG! proper val not read from IGU!\n");
  1340. }
  1341. static void bnx2x_igu_int_disable(struct bnx2x *bp)
  1342. {
  1343. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  1344. val &= ~(IGU_PF_CONF_MSI_MSIX_EN |
  1345. IGU_PF_CONF_INT_LINE_EN |
  1346. IGU_PF_CONF_ATTN_BIT_EN);
  1347. DP(NETIF_MSG_IFDOWN, "write %x to IGU\n", val);
  1348. /* flush all outstanding writes */
  1349. mmiowb();
  1350. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1351. if (REG_RD(bp, IGU_REG_PF_CONFIGURATION) != val)
  1352. BNX2X_ERR("BUG! proper val not read from IGU!\n");
  1353. }
  1354. static void bnx2x_int_disable(struct bnx2x *bp)
  1355. {
  1356. if (bp->common.int_block == INT_BLOCK_HC)
  1357. bnx2x_hc_int_disable(bp);
  1358. else
  1359. bnx2x_igu_int_disable(bp);
  1360. }
  1361. void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw)
  1362. {
  1363. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  1364. int i, offset;
  1365. if (disable_hw)
  1366. /* prevent the HW from sending interrupts */
  1367. bnx2x_int_disable(bp);
  1368. /* make sure all ISRs are done */
  1369. if (msix) {
  1370. synchronize_irq(bp->msix_table[0].vector);
  1371. offset = 1;
  1372. if (CNIC_SUPPORT(bp))
  1373. offset++;
  1374. for_each_eth_queue(bp, i)
  1375. synchronize_irq(bp->msix_table[offset++].vector);
  1376. } else
  1377. synchronize_irq(bp->pdev->irq);
  1378. /* make sure sp_task is not running */
  1379. cancel_delayed_work(&bp->sp_task);
  1380. cancel_delayed_work(&bp->period_task);
  1381. flush_workqueue(bnx2x_wq);
  1382. }
  1383. /* fast path */
  1384. /*
  1385. * General service functions
  1386. */
  1387. /* Return true if succeeded to acquire the lock */
  1388. static bool bnx2x_trylock_hw_lock(struct bnx2x *bp, u32 resource)
  1389. {
  1390. u32 lock_status;
  1391. u32 resource_bit = (1 << resource);
  1392. int func = BP_FUNC(bp);
  1393. u32 hw_lock_control_reg;
  1394. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1395. "Trying to take a lock on resource %d\n", resource);
  1396. /* Validating that the resource is within range */
  1397. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1398. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1399. "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1400. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1401. return false;
  1402. }
  1403. if (func <= 5)
  1404. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1405. else
  1406. hw_lock_control_reg =
  1407. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1408. /* Try to acquire the lock */
  1409. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1410. lock_status = REG_RD(bp, hw_lock_control_reg);
  1411. if (lock_status & resource_bit)
  1412. return true;
  1413. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1414. "Failed to get a lock on resource %d\n", resource);
  1415. return false;
  1416. }
  1417. /**
  1418. * bnx2x_get_leader_lock_resource - get the recovery leader resource id
  1419. *
  1420. * @bp: driver handle
  1421. *
  1422. * Returns the recovery leader resource id according to the engine this function
  1423. * belongs to. Currently only only 2 engines is supported.
  1424. */
  1425. static int bnx2x_get_leader_lock_resource(struct bnx2x *bp)
  1426. {
  1427. if (BP_PATH(bp))
  1428. return HW_LOCK_RESOURCE_RECOVERY_LEADER_1;
  1429. else
  1430. return HW_LOCK_RESOURCE_RECOVERY_LEADER_0;
  1431. }
  1432. /**
  1433. * bnx2x_trylock_leader_lock- try to aquire a leader lock.
  1434. *
  1435. * @bp: driver handle
  1436. *
  1437. * Tries to aquire a leader lock for current engine.
  1438. */
  1439. static bool bnx2x_trylock_leader_lock(struct bnx2x *bp)
  1440. {
  1441. return bnx2x_trylock_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1442. }
  1443. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err);
  1444. /* schedule the sp task and mark that interrupt occurred (runs from ISR) */
  1445. static int bnx2x_schedule_sp_task(struct bnx2x *bp)
  1446. {
  1447. /* Set the interrupt occurred bit for the sp-task to recognize it
  1448. * must ack the interrupt and transition according to the IGU
  1449. * state machine.
  1450. */
  1451. atomic_set(&bp->interrupt_occurred, 1);
  1452. /* The sp_task must execute only after this bit
  1453. * is set, otherwise we will get out of sync and miss all
  1454. * further interrupts. Hence, the barrier.
  1455. */
  1456. smp_wmb();
  1457. /* schedule sp_task to workqueue */
  1458. return queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
  1459. }
  1460. void bnx2x_sp_event(struct bnx2x_fastpath *fp, union eth_rx_cqe *rr_cqe)
  1461. {
  1462. struct bnx2x *bp = fp->bp;
  1463. int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1464. int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1465. enum bnx2x_queue_cmd drv_cmd = BNX2X_Q_CMD_MAX;
  1466. struct bnx2x_queue_sp_obj *q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  1467. DP(BNX2X_MSG_SP,
  1468. "fp %d cid %d got ramrod #%d state is %x type is %d\n",
  1469. fp->index, cid, command, bp->state,
  1470. rr_cqe->ramrod_cqe.ramrod_type);
  1471. /* If cid is within VF range, replace the slowpath object with the
  1472. * one corresponding to this VF
  1473. */
  1474. if (cid >= BNX2X_FIRST_VF_CID &&
  1475. cid < BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)
  1476. bnx2x_iov_set_queue_sp_obj(bp, cid, &q_obj);
  1477. switch (command) {
  1478. case (RAMROD_CMD_ID_ETH_CLIENT_UPDATE):
  1479. DP(BNX2X_MSG_SP, "got UPDATE ramrod. CID %d\n", cid);
  1480. drv_cmd = BNX2X_Q_CMD_UPDATE;
  1481. break;
  1482. case (RAMROD_CMD_ID_ETH_CLIENT_SETUP):
  1483. DP(BNX2X_MSG_SP, "got MULTI[%d] setup ramrod\n", cid);
  1484. drv_cmd = BNX2X_Q_CMD_SETUP;
  1485. break;
  1486. case (RAMROD_CMD_ID_ETH_TX_QUEUE_SETUP):
  1487. DP(BNX2X_MSG_SP, "got MULTI[%d] tx-only setup ramrod\n", cid);
  1488. drv_cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  1489. break;
  1490. case (RAMROD_CMD_ID_ETH_HALT):
  1491. DP(BNX2X_MSG_SP, "got MULTI[%d] halt ramrod\n", cid);
  1492. drv_cmd = BNX2X_Q_CMD_HALT;
  1493. break;
  1494. case (RAMROD_CMD_ID_ETH_TERMINATE):
  1495. DP(BNX2X_MSG_SP, "got MULTI[%d] teminate ramrod\n", cid);
  1496. drv_cmd = BNX2X_Q_CMD_TERMINATE;
  1497. break;
  1498. case (RAMROD_CMD_ID_ETH_EMPTY):
  1499. DP(BNX2X_MSG_SP, "got MULTI[%d] empty ramrod\n", cid);
  1500. drv_cmd = BNX2X_Q_CMD_EMPTY;
  1501. break;
  1502. default:
  1503. BNX2X_ERR("unexpected MC reply (%d) on fp[%d]\n",
  1504. command, fp->index);
  1505. return;
  1506. }
  1507. if ((drv_cmd != BNX2X_Q_CMD_MAX) &&
  1508. q_obj->complete_cmd(bp, q_obj, drv_cmd))
  1509. /* q_obj->complete_cmd() failure means that this was
  1510. * an unexpected completion.
  1511. *
  1512. * In this case we don't want to increase the bp->spq_left
  1513. * because apparently we haven't sent this command the first
  1514. * place.
  1515. */
  1516. #ifdef BNX2X_STOP_ON_ERROR
  1517. bnx2x_panic();
  1518. #else
  1519. return;
  1520. #endif
  1521. /* SRIOV: reschedule any 'in_progress' operations */
  1522. bnx2x_iov_sp_event(bp, cid, true);
  1523. smp_mb__before_atomic_inc();
  1524. atomic_inc(&bp->cq_spq_left);
  1525. /* push the change in bp->spq_left and towards the memory */
  1526. smp_mb__after_atomic_inc();
  1527. DP(BNX2X_MSG_SP, "bp->cq_spq_left %x\n", atomic_read(&bp->cq_spq_left));
  1528. if ((drv_cmd == BNX2X_Q_CMD_UPDATE) && (IS_FCOE_FP(fp)) &&
  1529. (!!test_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state))) {
  1530. /* if Q update ramrod is completed for last Q in AFEX vif set
  1531. * flow, then ACK MCP at the end
  1532. *
  1533. * mark pending ACK to MCP bit.
  1534. * prevent case that both bits are cleared.
  1535. * At the end of load/unload driver checks that
  1536. * sp_state is cleaerd, and this order prevents
  1537. * races
  1538. */
  1539. smp_mb__before_clear_bit();
  1540. set_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK, &bp->sp_state);
  1541. wmb();
  1542. clear_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
  1543. smp_mb__after_clear_bit();
  1544. /* schedule the sp task as mcp ack is required */
  1545. bnx2x_schedule_sp_task(bp);
  1546. }
  1547. return;
  1548. }
  1549. irqreturn_t bnx2x_interrupt(int irq, void *dev_instance)
  1550. {
  1551. struct bnx2x *bp = netdev_priv(dev_instance);
  1552. u16 status = bnx2x_ack_int(bp);
  1553. u16 mask;
  1554. int i;
  1555. u8 cos;
  1556. /* Return here if interrupt is shared and it's not for us */
  1557. if (unlikely(status == 0)) {
  1558. DP(NETIF_MSG_INTR, "not our interrupt!\n");
  1559. return IRQ_NONE;
  1560. }
  1561. DP(NETIF_MSG_INTR, "got an interrupt status 0x%x\n", status);
  1562. #ifdef BNX2X_STOP_ON_ERROR
  1563. if (unlikely(bp->panic))
  1564. return IRQ_HANDLED;
  1565. #endif
  1566. for_each_eth_queue(bp, i) {
  1567. struct bnx2x_fastpath *fp = &bp->fp[i];
  1568. mask = 0x2 << (fp->index + CNIC_SUPPORT(bp));
  1569. if (status & mask) {
  1570. /* Handle Rx or Tx according to SB id */
  1571. prefetch(fp->rx_cons_sb);
  1572. for_each_cos_in_tx_queue(fp, cos)
  1573. prefetch(fp->txdata_ptr[cos]->tx_cons_sb);
  1574. prefetch(&fp->sb_running_index[SM_RX_ID]);
  1575. napi_schedule(&bnx2x_fp(bp, fp->index, napi));
  1576. status &= ~mask;
  1577. }
  1578. }
  1579. if (CNIC_SUPPORT(bp)) {
  1580. mask = 0x2;
  1581. if (status & (mask | 0x1)) {
  1582. struct cnic_ops *c_ops = NULL;
  1583. if (likely(bp->state == BNX2X_STATE_OPEN)) {
  1584. rcu_read_lock();
  1585. c_ops = rcu_dereference(bp->cnic_ops);
  1586. if (c_ops)
  1587. c_ops->cnic_handler(bp->cnic_data,
  1588. NULL);
  1589. rcu_read_unlock();
  1590. }
  1591. status &= ~mask;
  1592. }
  1593. }
  1594. if (unlikely(status & 0x1)) {
  1595. /* schedule sp task to perform default status block work, ack
  1596. * attentions and enable interrupts.
  1597. */
  1598. bnx2x_schedule_sp_task(bp);
  1599. status &= ~0x1;
  1600. if (!status)
  1601. return IRQ_HANDLED;
  1602. }
  1603. if (unlikely(status))
  1604. DP(NETIF_MSG_INTR, "got an unknown interrupt! (status 0x%x)\n",
  1605. status);
  1606. return IRQ_HANDLED;
  1607. }
  1608. /* Link */
  1609. /*
  1610. * General service functions
  1611. */
  1612. int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource)
  1613. {
  1614. u32 lock_status;
  1615. u32 resource_bit = (1 << resource);
  1616. int func = BP_FUNC(bp);
  1617. u32 hw_lock_control_reg;
  1618. int cnt;
  1619. /* Validating that the resource is within range */
  1620. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1621. BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1622. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1623. return -EINVAL;
  1624. }
  1625. if (func <= 5) {
  1626. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1627. } else {
  1628. hw_lock_control_reg =
  1629. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1630. }
  1631. /* Validating that the resource is not already taken */
  1632. lock_status = REG_RD(bp, hw_lock_control_reg);
  1633. if (lock_status & resource_bit) {
  1634. BNX2X_ERR("lock_status 0x%x resource_bit 0x%x\n",
  1635. lock_status, resource_bit);
  1636. return -EEXIST;
  1637. }
  1638. /* Try for 5 second every 5ms */
  1639. for (cnt = 0; cnt < 1000; cnt++) {
  1640. /* Try to acquire the lock */
  1641. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1642. lock_status = REG_RD(bp, hw_lock_control_reg);
  1643. if (lock_status & resource_bit)
  1644. return 0;
  1645. msleep(5);
  1646. }
  1647. BNX2X_ERR("Timeout\n");
  1648. return -EAGAIN;
  1649. }
  1650. int bnx2x_release_leader_lock(struct bnx2x *bp)
  1651. {
  1652. return bnx2x_release_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1653. }
  1654. int bnx2x_release_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. /* Validating that the resource is within range */
  1661. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1662. BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1663. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1664. return -EINVAL;
  1665. }
  1666. if (func <= 5) {
  1667. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1668. } else {
  1669. hw_lock_control_reg =
  1670. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1671. }
  1672. /* Validating that the resource is currently taken */
  1673. lock_status = REG_RD(bp, hw_lock_control_reg);
  1674. if (!(lock_status & resource_bit)) {
  1675. BNX2X_ERR("lock_status 0x%x resource_bit 0x%x. unlock was called but lock wasn't taken!\n",
  1676. lock_status, resource_bit);
  1677. return -EFAULT;
  1678. }
  1679. REG_WR(bp, hw_lock_control_reg, resource_bit);
  1680. return 0;
  1681. }
  1682. int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port)
  1683. {
  1684. /* The GPIO should be swapped if swap register is set and active */
  1685. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1686. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1687. int gpio_shift = gpio_num +
  1688. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1689. u32 gpio_mask = (1 << gpio_shift);
  1690. u32 gpio_reg;
  1691. int value;
  1692. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1693. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1694. return -EINVAL;
  1695. }
  1696. /* read GPIO value */
  1697. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1698. /* get the requested pin value */
  1699. if ((gpio_reg & gpio_mask) == gpio_mask)
  1700. value = 1;
  1701. else
  1702. value = 0;
  1703. DP(NETIF_MSG_LINK, "pin %d value 0x%x\n", gpio_num, value);
  1704. return value;
  1705. }
  1706. int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1707. {
  1708. /* The GPIO should be swapped if swap register is set and active */
  1709. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1710. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1711. int gpio_shift = gpio_num +
  1712. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1713. u32 gpio_mask = (1 << gpio_shift);
  1714. u32 gpio_reg;
  1715. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1716. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1717. return -EINVAL;
  1718. }
  1719. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1720. /* read GPIO and mask except the float bits */
  1721. gpio_reg = (REG_RD(bp, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT);
  1722. switch (mode) {
  1723. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1724. DP(NETIF_MSG_LINK,
  1725. "Set GPIO %d (shift %d) -> output low\n",
  1726. gpio_num, gpio_shift);
  1727. /* clear FLOAT and set CLR */
  1728. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1729. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS);
  1730. break;
  1731. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1732. DP(NETIF_MSG_LINK,
  1733. "Set GPIO %d (shift %d) -> output high\n",
  1734. gpio_num, gpio_shift);
  1735. /* clear FLOAT and set SET */
  1736. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1737. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS);
  1738. break;
  1739. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1740. DP(NETIF_MSG_LINK,
  1741. "Set GPIO %d (shift %d) -> input\n",
  1742. gpio_num, gpio_shift);
  1743. /* set FLOAT */
  1744. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1745. break;
  1746. default:
  1747. break;
  1748. }
  1749. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1750. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1751. return 0;
  1752. }
  1753. int bnx2x_set_mult_gpio(struct bnx2x *bp, u8 pins, u32 mode)
  1754. {
  1755. u32 gpio_reg = 0;
  1756. int rc = 0;
  1757. /* Any port swapping should be handled by caller. */
  1758. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1759. /* read GPIO and mask except the float bits */
  1760. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1761. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1762. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_CLR_POS);
  1763. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_SET_POS);
  1764. switch (mode) {
  1765. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1766. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output low\n", pins);
  1767. /* set CLR */
  1768. gpio_reg |= (pins << MISC_REGISTERS_GPIO_CLR_POS);
  1769. break;
  1770. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1771. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output high\n", pins);
  1772. /* set SET */
  1773. gpio_reg |= (pins << MISC_REGISTERS_GPIO_SET_POS);
  1774. break;
  1775. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1776. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> input\n", pins);
  1777. /* set FLOAT */
  1778. gpio_reg |= (pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1779. break;
  1780. default:
  1781. BNX2X_ERR("Invalid GPIO mode assignment %d\n", mode);
  1782. rc = -EINVAL;
  1783. break;
  1784. }
  1785. if (rc == 0)
  1786. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1787. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1788. return rc;
  1789. }
  1790. int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1791. {
  1792. /* The GPIO should be swapped if swap register is set and active */
  1793. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1794. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1795. int gpio_shift = gpio_num +
  1796. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1797. u32 gpio_mask = (1 << gpio_shift);
  1798. u32 gpio_reg;
  1799. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1800. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1801. return -EINVAL;
  1802. }
  1803. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1804. /* read GPIO int */
  1805. gpio_reg = REG_RD(bp, MISC_REG_GPIO_INT);
  1806. switch (mode) {
  1807. case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR:
  1808. DP(NETIF_MSG_LINK,
  1809. "Clear GPIO INT %d (shift %d) -> output low\n",
  1810. gpio_num, gpio_shift);
  1811. /* clear SET and set CLR */
  1812. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1813. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1814. break;
  1815. case MISC_REGISTERS_GPIO_INT_OUTPUT_SET:
  1816. DP(NETIF_MSG_LINK,
  1817. "Set GPIO INT %d (shift %d) -> output high\n",
  1818. gpio_num, gpio_shift);
  1819. /* clear CLR and set SET */
  1820. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1821. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1822. break;
  1823. default:
  1824. break;
  1825. }
  1826. REG_WR(bp, MISC_REG_GPIO_INT, gpio_reg);
  1827. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1828. return 0;
  1829. }
  1830. static int bnx2x_set_spio(struct bnx2x *bp, int spio, u32 mode)
  1831. {
  1832. u32 spio_reg;
  1833. /* Only 2 SPIOs are configurable */
  1834. if ((spio != MISC_SPIO_SPIO4) && (spio != MISC_SPIO_SPIO5)) {
  1835. BNX2X_ERR("Invalid SPIO 0x%x\n", spio);
  1836. return -EINVAL;
  1837. }
  1838. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1839. /* read SPIO and mask except the float bits */
  1840. spio_reg = (REG_RD(bp, MISC_REG_SPIO) & MISC_SPIO_FLOAT);
  1841. switch (mode) {
  1842. case MISC_SPIO_OUTPUT_LOW:
  1843. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output low\n", spio);
  1844. /* clear FLOAT and set CLR */
  1845. spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
  1846. spio_reg |= (spio << MISC_SPIO_CLR_POS);
  1847. break;
  1848. case MISC_SPIO_OUTPUT_HIGH:
  1849. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output high\n", spio);
  1850. /* clear FLOAT and set SET */
  1851. spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
  1852. spio_reg |= (spio << MISC_SPIO_SET_POS);
  1853. break;
  1854. case MISC_SPIO_INPUT_HI_Z:
  1855. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> input\n", spio);
  1856. /* set FLOAT */
  1857. spio_reg |= (spio << MISC_SPIO_FLOAT_POS);
  1858. break;
  1859. default:
  1860. break;
  1861. }
  1862. REG_WR(bp, MISC_REG_SPIO, spio_reg);
  1863. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1864. return 0;
  1865. }
  1866. void bnx2x_calc_fc_adv(struct bnx2x *bp)
  1867. {
  1868. u8 cfg_idx = bnx2x_get_link_cfg_idx(bp);
  1869. switch (bp->link_vars.ieee_fc &
  1870. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) {
  1871. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE:
  1872. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1873. ADVERTISED_Pause);
  1874. break;
  1875. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH:
  1876. bp->port.advertising[cfg_idx] |= (ADVERTISED_Asym_Pause |
  1877. ADVERTISED_Pause);
  1878. break;
  1879. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC:
  1880. bp->port.advertising[cfg_idx] |= ADVERTISED_Asym_Pause;
  1881. break;
  1882. default:
  1883. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1884. ADVERTISED_Pause);
  1885. break;
  1886. }
  1887. }
  1888. static void bnx2x_set_requested_fc(struct bnx2x *bp)
  1889. {
  1890. /* Initialize link parameters structure variables
  1891. * It is recommended to turn off RX FC for jumbo frames
  1892. * for better performance
  1893. */
  1894. if (CHIP_IS_E1x(bp) && (bp->dev->mtu > 5000))
  1895. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_TX;
  1896. else
  1897. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH;
  1898. }
  1899. int bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode)
  1900. {
  1901. int rc, cfx_idx = bnx2x_get_link_cfg_idx(bp);
  1902. u16 req_line_speed = bp->link_params.req_line_speed[cfx_idx];
  1903. if (!BP_NOMCP(bp)) {
  1904. bnx2x_set_requested_fc(bp);
  1905. bnx2x_acquire_phy_lock(bp);
  1906. if (load_mode == LOAD_DIAG) {
  1907. struct link_params *lp = &bp->link_params;
  1908. lp->loopback_mode = LOOPBACK_XGXS;
  1909. /* do PHY loopback at 10G speed, if possible */
  1910. if (lp->req_line_speed[cfx_idx] < SPEED_10000) {
  1911. if (lp->speed_cap_mask[cfx_idx] &
  1912. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
  1913. lp->req_line_speed[cfx_idx] =
  1914. SPEED_10000;
  1915. else
  1916. lp->req_line_speed[cfx_idx] =
  1917. SPEED_1000;
  1918. }
  1919. }
  1920. if (load_mode == LOAD_LOOPBACK_EXT) {
  1921. struct link_params *lp = &bp->link_params;
  1922. lp->loopback_mode = LOOPBACK_EXT;
  1923. }
  1924. rc = bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  1925. bnx2x_release_phy_lock(bp);
  1926. bnx2x_calc_fc_adv(bp);
  1927. if (bp->link_vars.link_up) {
  1928. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  1929. bnx2x_link_report(bp);
  1930. }
  1931. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  1932. bp->link_params.req_line_speed[cfx_idx] = req_line_speed;
  1933. return rc;
  1934. }
  1935. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  1936. return -EINVAL;
  1937. }
  1938. void bnx2x_link_set(struct bnx2x *bp)
  1939. {
  1940. if (!BP_NOMCP(bp)) {
  1941. bnx2x_acquire_phy_lock(bp);
  1942. bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  1943. bnx2x_release_phy_lock(bp);
  1944. bnx2x_calc_fc_adv(bp);
  1945. } else
  1946. BNX2X_ERR("Bootcode is missing - can not set link\n");
  1947. }
  1948. static void bnx2x__link_reset(struct bnx2x *bp)
  1949. {
  1950. if (!BP_NOMCP(bp)) {
  1951. bnx2x_acquire_phy_lock(bp);
  1952. bnx2x_lfa_reset(&bp->link_params, &bp->link_vars);
  1953. bnx2x_release_phy_lock(bp);
  1954. } else
  1955. BNX2X_ERR("Bootcode is missing - can not reset link\n");
  1956. }
  1957. void bnx2x_force_link_reset(struct bnx2x *bp)
  1958. {
  1959. bnx2x_acquire_phy_lock(bp);
  1960. bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
  1961. bnx2x_release_phy_lock(bp);
  1962. }
  1963. u8 bnx2x_link_test(struct bnx2x *bp, u8 is_serdes)
  1964. {
  1965. u8 rc = 0;
  1966. if (!BP_NOMCP(bp)) {
  1967. bnx2x_acquire_phy_lock(bp);
  1968. rc = bnx2x_test_link(&bp->link_params, &bp->link_vars,
  1969. is_serdes);
  1970. bnx2x_release_phy_lock(bp);
  1971. } else
  1972. BNX2X_ERR("Bootcode is missing - can not test link\n");
  1973. return rc;
  1974. }
  1975. /* Calculates the sum of vn_min_rates.
  1976. It's needed for further normalizing of the min_rates.
  1977. Returns:
  1978. sum of vn_min_rates.
  1979. or
  1980. 0 - if all the min_rates are 0.
  1981. In the later case fainess algorithm should be deactivated.
  1982. If not all min_rates are zero then those that are zeroes will be set to 1.
  1983. */
  1984. static void bnx2x_calc_vn_min(struct bnx2x *bp,
  1985. struct cmng_init_input *input)
  1986. {
  1987. int all_zero = 1;
  1988. int vn;
  1989. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  1990. u32 vn_cfg = bp->mf_config[vn];
  1991. u32 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
  1992. FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
  1993. /* Skip hidden vns */
  1994. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  1995. vn_min_rate = 0;
  1996. /* If min rate is zero - set it to 1 */
  1997. else if (!vn_min_rate)
  1998. vn_min_rate = DEF_MIN_RATE;
  1999. else
  2000. all_zero = 0;
  2001. input->vnic_min_rate[vn] = vn_min_rate;
  2002. }
  2003. /* if ETS or all min rates are zeros - disable fairness */
  2004. if (BNX2X_IS_ETS_ENABLED(bp)) {
  2005. input->flags.cmng_enables &=
  2006. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2007. DP(NETIF_MSG_IFUP, "Fairness will be disabled due to ETS\n");
  2008. } else if (all_zero) {
  2009. input->flags.cmng_enables &=
  2010. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2011. DP(NETIF_MSG_IFUP,
  2012. "All MIN values are zeroes fairness will be disabled\n");
  2013. } else
  2014. input->flags.cmng_enables |=
  2015. CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2016. }
  2017. static void bnx2x_calc_vn_max(struct bnx2x *bp, int vn,
  2018. struct cmng_init_input *input)
  2019. {
  2020. u16 vn_max_rate;
  2021. u32 vn_cfg = bp->mf_config[vn];
  2022. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  2023. vn_max_rate = 0;
  2024. else {
  2025. u32 maxCfg = bnx2x_extract_max_cfg(bp, vn_cfg);
  2026. if (IS_MF_SI(bp)) {
  2027. /* maxCfg in percents of linkspeed */
  2028. vn_max_rate = (bp->link_vars.line_speed * maxCfg) / 100;
  2029. } else /* SD modes */
  2030. /* maxCfg is absolute in 100Mb units */
  2031. vn_max_rate = maxCfg * 100;
  2032. }
  2033. DP(NETIF_MSG_IFUP, "vn %d: vn_max_rate %d\n", vn, vn_max_rate);
  2034. input->vnic_max_rate[vn] = vn_max_rate;
  2035. }
  2036. static int bnx2x_get_cmng_fns_mode(struct bnx2x *bp)
  2037. {
  2038. if (CHIP_REV_IS_SLOW(bp))
  2039. return CMNG_FNS_NONE;
  2040. if (IS_MF(bp))
  2041. return CMNG_FNS_MINMAX;
  2042. return CMNG_FNS_NONE;
  2043. }
  2044. void bnx2x_read_mf_cfg(struct bnx2x *bp)
  2045. {
  2046. int vn, n = (CHIP_MODE_IS_4_PORT(bp) ? 2 : 1);
  2047. if (BP_NOMCP(bp))
  2048. return; /* what should be the default bvalue in this case */
  2049. /* For 2 port configuration the absolute function number formula
  2050. * is:
  2051. * abs_func = 2 * vn + BP_PORT + BP_PATH
  2052. *
  2053. * and there are 4 functions per port
  2054. *
  2055. * For 4 port configuration it is
  2056. * abs_func = 4 * vn + 2 * BP_PORT + BP_PATH
  2057. *
  2058. * and there are 2 functions per port
  2059. */
  2060. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2061. int /*abs*/func = n * (2 * vn + BP_PORT(bp)) + BP_PATH(bp);
  2062. if (func >= E1H_FUNC_MAX)
  2063. break;
  2064. bp->mf_config[vn] =
  2065. MF_CFG_RD(bp, func_mf_config[func].config);
  2066. }
  2067. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  2068. DP(NETIF_MSG_IFUP, "mf_cfg function disabled\n");
  2069. bp->flags |= MF_FUNC_DIS;
  2070. } else {
  2071. DP(NETIF_MSG_IFUP, "mf_cfg function enabled\n");
  2072. bp->flags &= ~MF_FUNC_DIS;
  2073. }
  2074. }
  2075. static void bnx2x_cmng_fns_init(struct bnx2x *bp, u8 read_cfg, u8 cmng_type)
  2076. {
  2077. struct cmng_init_input input;
  2078. memset(&input, 0, sizeof(struct cmng_init_input));
  2079. input.port_rate = bp->link_vars.line_speed;
  2080. if (cmng_type == CMNG_FNS_MINMAX) {
  2081. int vn;
  2082. /* read mf conf from shmem */
  2083. if (read_cfg)
  2084. bnx2x_read_mf_cfg(bp);
  2085. /* vn_weight_sum and enable fairness if not 0 */
  2086. bnx2x_calc_vn_min(bp, &input);
  2087. /* calculate and set min-max rate for each vn */
  2088. if (bp->port.pmf)
  2089. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++)
  2090. bnx2x_calc_vn_max(bp, vn, &input);
  2091. /* always enable rate shaping and fairness */
  2092. input.flags.cmng_enables |=
  2093. CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN;
  2094. bnx2x_init_cmng(&input, &bp->cmng);
  2095. return;
  2096. }
  2097. /* rate shaping and fairness are disabled */
  2098. DP(NETIF_MSG_IFUP,
  2099. "rate shaping and fairness are disabled\n");
  2100. }
  2101. static void storm_memset_cmng(struct bnx2x *bp,
  2102. struct cmng_init *cmng,
  2103. u8 port)
  2104. {
  2105. int vn;
  2106. size_t size = sizeof(struct cmng_struct_per_port);
  2107. u32 addr = BAR_XSTRORM_INTMEM +
  2108. XSTORM_CMNG_PER_PORT_VARS_OFFSET(port);
  2109. __storm_memset_struct(bp, addr, size, (u32 *)&cmng->port);
  2110. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2111. int func = func_by_vn(bp, vn);
  2112. addr = BAR_XSTRORM_INTMEM +
  2113. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func);
  2114. size = sizeof(struct rate_shaping_vars_per_vn);
  2115. __storm_memset_struct(bp, addr, size,
  2116. (u32 *)&cmng->vnic.vnic_max_rate[vn]);
  2117. addr = BAR_XSTRORM_INTMEM +
  2118. XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func);
  2119. size = sizeof(struct fairness_vars_per_vn);
  2120. __storm_memset_struct(bp, addr, size,
  2121. (u32 *)&cmng->vnic.vnic_min_rate[vn]);
  2122. }
  2123. }
  2124. /* This function is called upon link interrupt */
  2125. static void bnx2x_link_attn(struct bnx2x *bp)
  2126. {
  2127. /* Make sure that we are synced with the current statistics */
  2128. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2129. bnx2x_link_update(&bp->link_params, &bp->link_vars);
  2130. if (bp->link_vars.link_up) {
  2131. /* dropless flow control */
  2132. if (!CHIP_IS_E1(bp) && bp->dropless_fc) {
  2133. int port = BP_PORT(bp);
  2134. u32 pause_enabled = 0;
  2135. if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX)
  2136. pause_enabled = 1;
  2137. REG_WR(bp, BAR_USTRORM_INTMEM +
  2138. USTORM_ETH_PAUSE_ENABLED_OFFSET(port),
  2139. pause_enabled);
  2140. }
  2141. if (bp->link_vars.mac_type != MAC_TYPE_EMAC) {
  2142. struct host_port_stats *pstats;
  2143. pstats = bnx2x_sp(bp, port_stats);
  2144. /* reset old mac stats */
  2145. memset(&(pstats->mac_stx[0]), 0,
  2146. sizeof(struct mac_stx));
  2147. }
  2148. if (bp->state == BNX2X_STATE_OPEN)
  2149. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2150. }
  2151. if (bp->link_vars.link_up && bp->link_vars.line_speed) {
  2152. int cmng_fns = bnx2x_get_cmng_fns_mode(bp);
  2153. if (cmng_fns != CMNG_FNS_NONE) {
  2154. bnx2x_cmng_fns_init(bp, false, cmng_fns);
  2155. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2156. } else
  2157. /* rate shaping and fairness are disabled */
  2158. DP(NETIF_MSG_IFUP,
  2159. "single function mode without fairness\n");
  2160. }
  2161. __bnx2x_link_report(bp);
  2162. if (IS_MF(bp))
  2163. bnx2x_link_sync_notify(bp);
  2164. }
  2165. void bnx2x__link_status_update(struct bnx2x *bp)
  2166. {
  2167. if (bp->state != BNX2X_STATE_OPEN)
  2168. return;
  2169. /* read updated dcb configuration */
  2170. if (IS_PF(bp)) {
  2171. bnx2x_dcbx_pmf_update(bp);
  2172. bnx2x_link_status_update(&bp->link_params, &bp->link_vars);
  2173. if (bp->link_vars.link_up)
  2174. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2175. else
  2176. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2177. /* indicate link status */
  2178. bnx2x_link_report(bp);
  2179. } else { /* VF */
  2180. bp->port.supported[0] |= (SUPPORTED_10baseT_Half |
  2181. SUPPORTED_10baseT_Full |
  2182. SUPPORTED_100baseT_Half |
  2183. SUPPORTED_100baseT_Full |
  2184. SUPPORTED_1000baseT_Full |
  2185. SUPPORTED_2500baseX_Full |
  2186. SUPPORTED_10000baseT_Full |
  2187. SUPPORTED_TP |
  2188. SUPPORTED_FIBRE |
  2189. SUPPORTED_Autoneg |
  2190. SUPPORTED_Pause |
  2191. SUPPORTED_Asym_Pause);
  2192. bp->port.advertising[0] = bp->port.supported[0];
  2193. bp->link_params.bp = bp;
  2194. bp->link_params.port = BP_PORT(bp);
  2195. bp->link_params.req_duplex[0] = DUPLEX_FULL;
  2196. bp->link_params.req_flow_ctrl[0] = BNX2X_FLOW_CTRL_NONE;
  2197. bp->link_params.req_line_speed[0] = SPEED_10000;
  2198. bp->link_params.speed_cap_mask[0] = 0x7f0000;
  2199. bp->link_params.switch_cfg = SWITCH_CFG_10G;
  2200. bp->link_vars.mac_type = MAC_TYPE_BMAC;
  2201. bp->link_vars.line_speed = SPEED_10000;
  2202. bp->link_vars.link_status =
  2203. (LINK_STATUS_LINK_UP |
  2204. LINK_STATUS_SPEED_AND_DUPLEX_10GTFD);
  2205. bp->link_vars.link_up = 1;
  2206. bp->link_vars.duplex = DUPLEX_FULL;
  2207. bp->link_vars.flow_ctrl = BNX2X_FLOW_CTRL_NONE;
  2208. __bnx2x_link_report(bp);
  2209. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2210. }
  2211. }
  2212. static int bnx2x_afex_func_update(struct bnx2x *bp, u16 vifid,
  2213. u16 vlan_val, u8 allowed_prio)
  2214. {
  2215. struct bnx2x_func_state_params func_params = {0};
  2216. struct bnx2x_func_afex_update_params *f_update_params =
  2217. &func_params.params.afex_update;
  2218. func_params.f_obj = &bp->func_obj;
  2219. func_params.cmd = BNX2X_F_CMD_AFEX_UPDATE;
  2220. /* no need to wait for RAMROD completion, so don't
  2221. * set RAMROD_COMP_WAIT flag
  2222. */
  2223. f_update_params->vif_id = vifid;
  2224. f_update_params->afex_default_vlan = vlan_val;
  2225. f_update_params->allowed_priorities = allowed_prio;
  2226. /* if ramrod can not be sent, response to MCP immediately */
  2227. if (bnx2x_func_state_change(bp, &func_params) < 0)
  2228. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  2229. return 0;
  2230. }
  2231. static int bnx2x_afex_handle_vif_list_cmd(struct bnx2x *bp, u8 cmd_type,
  2232. u16 vif_index, u8 func_bit_map)
  2233. {
  2234. struct bnx2x_func_state_params func_params = {0};
  2235. struct bnx2x_func_afex_viflists_params *update_params =
  2236. &func_params.params.afex_viflists;
  2237. int rc;
  2238. u32 drv_msg_code;
  2239. /* validate only LIST_SET and LIST_GET are received from switch */
  2240. if ((cmd_type != VIF_LIST_RULE_GET) && (cmd_type != VIF_LIST_RULE_SET))
  2241. BNX2X_ERR("BUG! afex_handle_vif_list_cmd invalid type 0x%x\n",
  2242. cmd_type);
  2243. func_params.f_obj = &bp->func_obj;
  2244. func_params.cmd = BNX2X_F_CMD_AFEX_VIFLISTS;
  2245. /* set parameters according to cmd_type */
  2246. update_params->afex_vif_list_command = cmd_type;
  2247. update_params->vif_list_index = cpu_to_le16(vif_index);
  2248. update_params->func_bit_map =
  2249. (cmd_type == VIF_LIST_RULE_GET) ? 0 : func_bit_map;
  2250. update_params->func_to_clear = 0;
  2251. drv_msg_code =
  2252. (cmd_type == VIF_LIST_RULE_GET) ?
  2253. DRV_MSG_CODE_AFEX_LISTGET_ACK :
  2254. DRV_MSG_CODE_AFEX_LISTSET_ACK;
  2255. /* if ramrod can not be sent, respond to MCP immediately for
  2256. * SET and GET requests (other are not triggered from MCP)
  2257. */
  2258. rc = bnx2x_func_state_change(bp, &func_params);
  2259. if (rc < 0)
  2260. bnx2x_fw_command(bp, drv_msg_code, 0);
  2261. return 0;
  2262. }
  2263. static void bnx2x_handle_afex_cmd(struct bnx2x *bp, u32 cmd)
  2264. {
  2265. struct afex_stats afex_stats;
  2266. u32 func = BP_ABS_FUNC(bp);
  2267. u32 mf_config;
  2268. u16 vlan_val;
  2269. u32 vlan_prio;
  2270. u16 vif_id;
  2271. u8 allowed_prio;
  2272. u8 vlan_mode;
  2273. u32 addr_to_write, vifid, addrs, stats_type, i;
  2274. if (cmd & DRV_STATUS_AFEX_LISTGET_REQ) {
  2275. vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2276. DP(BNX2X_MSG_MCP,
  2277. "afex: got MCP req LISTGET_REQ for vifid 0x%x\n", vifid);
  2278. bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_GET, vifid, 0);
  2279. }
  2280. if (cmd & DRV_STATUS_AFEX_LISTSET_REQ) {
  2281. vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2282. addrs = SHMEM2_RD(bp, afex_param2_to_driver[BP_FW_MB_IDX(bp)]);
  2283. DP(BNX2X_MSG_MCP,
  2284. "afex: got MCP req LISTSET_REQ for vifid 0x%x addrs 0x%x\n",
  2285. vifid, addrs);
  2286. bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_SET, vifid,
  2287. addrs);
  2288. }
  2289. if (cmd & DRV_STATUS_AFEX_STATSGET_REQ) {
  2290. addr_to_write = SHMEM2_RD(bp,
  2291. afex_scratchpad_addr_to_write[BP_FW_MB_IDX(bp)]);
  2292. stats_type = SHMEM2_RD(bp,
  2293. afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2294. DP(BNX2X_MSG_MCP,
  2295. "afex: got MCP req STATSGET_REQ, write to addr 0x%x\n",
  2296. addr_to_write);
  2297. bnx2x_afex_collect_stats(bp, (void *)&afex_stats, stats_type);
  2298. /* write response to scratchpad, for MCP */
  2299. for (i = 0; i < (sizeof(struct afex_stats)/sizeof(u32)); i++)
  2300. REG_WR(bp, addr_to_write + i*sizeof(u32),
  2301. *(((u32 *)(&afex_stats))+i));
  2302. /* send ack message to MCP */
  2303. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_STATSGET_ACK, 0);
  2304. }
  2305. if (cmd & DRV_STATUS_AFEX_VIFSET_REQ) {
  2306. mf_config = MF_CFG_RD(bp, func_mf_config[func].config);
  2307. bp->mf_config[BP_VN(bp)] = mf_config;
  2308. DP(BNX2X_MSG_MCP,
  2309. "afex: got MCP req VIFSET_REQ, mf_config 0x%x\n",
  2310. mf_config);
  2311. /* if VIF_SET is "enabled" */
  2312. if (!(mf_config & FUNC_MF_CFG_FUNC_DISABLED)) {
  2313. /* set rate limit directly to internal RAM */
  2314. struct cmng_init_input cmng_input;
  2315. struct rate_shaping_vars_per_vn m_rs_vn;
  2316. size_t size = sizeof(struct rate_shaping_vars_per_vn);
  2317. u32 addr = BAR_XSTRORM_INTMEM +
  2318. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(BP_FUNC(bp));
  2319. bp->mf_config[BP_VN(bp)] = mf_config;
  2320. bnx2x_calc_vn_max(bp, BP_VN(bp), &cmng_input);
  2321. m_rs_vn.vn_counter.rate =
  2322. cmng_input.vnic_max_rate[BP_VN(bp)];
  2323. m_rs_vn.vn_counter.quota =
  2324. (m_rs_vn.vn_counter.rate *
  2325. RS_PERIODIC_TIMEOUT_USEC) / 8;
  2326. __storm_memset_struct(bp, addr, size, (u32 *)&m_rs_vn);
  2327. /* read relevant values from mf_cfg struct in shmem */
  2328. vif_id =
  2329. (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2330. FUNC_MF_CFG_E1HOV_TAG_MASK) >>
  2331. FUNC_MF_CFG_E1HOV_TAG_SHIFT;
  2332. vlan_val =
  2333. (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2334. FUNC_MF_CFG_AFEX_VLAN_MASK) >>
  2335. FUNC_MF_CFG_AFEX_VLAN_SHIFT;
  2336. vlan_prio = (mf_config &
  2337. FUNC_MF_CFG_TRANSMIT_PRIORITY_MASK) >>
  2338. FUNC_MF_CFG_TRANSMIT_PRIORITY_SHIFT;
  2339. vlan_val |= (vlan_prio << VLAN_PRIO_SHIFT);
  2340. vlan_mode =
  2341. (MF_CFG_RD(bp,
  2342. func_mf_config[func].afex_config) &
  2343. FUNC_MF_CFG_AFEX_VLAN_MODE_MASK) >>
  2344. FUNC_MF_CFG_AFEX_VLAN_MODE_SHIFT;
  2345. allowed_prio =
  2346. (MF_CFG_RD(bp,
  2347. func_mf_config[func].afex_config) &
  2348. FUNC_MF_CFG_AFEX_COS_FILTER_MASK) >>
  2349. FUNC_MF_CFG_AFEX_COS_FILTER_SHIFT;
  2350. /* send ramrod to FW, return in case of failure */
  2351. if (bnx2x_afex_func_update(bp, vif_id, vlan_val,
  2352. allowed_prio))
  2353. return;
  2354. bp->afex_def_vlan_tag = vlan_val;
  2355. bp->afex_vlan_mode = vlan_mode;
  2356. } else {
  2357. /* notify link down because BP->flags is disabled */
  2358. bnx2x_link_report(bp);
  2359. /* send INVALID VIF ramrod to FW */
  2360. bnx2x_afex_func_update(bp, 0xFFFF, 0, 0);
  2361. /* Reset the default afex VLAN */
  2362. bp->afex_def_vlan_tag = -1;
  2363. }
  2364. }
  2365. }
  2366. static void bnx2x_pmf_update(struct bnx2x *bp)
  2367. {
  2368. int port = BP_PORT(bp);
  2369. u32 val;
  2370. bp->port.pmf = 1;
  2371. DP(BNX2X_MSG_MCP, "pmf %d\n", bp->port.pmf);
  2372. /*
  2373. * We need the mb() to ensure the ordering between the writing to
  2374. * bp->port.pmf here and reading it from the bnx2x_periodic_task().
  2375. */
  2376. smp_mb();
  2377. /* queue a periodic task */
  2378. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  2379. bnx2x_dcbx_pmf_update(bp);
  2380. /* enable nig attention */
  2381. val = (0xff0f | (1 << (BP_VN(bp) + 4)));
  2382. if (bp->common.int_block == INT_BLOCK_HC) {
  2383. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  2384. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  2385. } else if (!CHIP_IS_E1x(bp)) {
  2386. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  2387. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  2388. }
  2389. bnx2x_stats_handle(bp, STATS_EVENT_PMF);
  2390. }
  2391. /* end of Link */
  2392. /* slow path */
  2393. /*
  2394. * General service functions
  2395. */
  2396. /* send the MCP a request, block until there is a reply */
  2397. u32 bnx2x_fw_command(struct bnx2x *bp, u32 command, u32 param)
  2398. {
  2399. int mb_idx = BP_FW_MB_IDX(bp);
  2400. u32 seq;
  2401. u32 rc = 0;
  2402. u32 cnt = 1;
  2403. u8 delay = CHIP_REV_IS_SLOW(bp) ? 100 : 10;
  2404. mutex_lock(&bp->fw_mb_mutex);
  2405. seq = ++bp->fw_seq;
  2406. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_param, param);
  2407. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_header, (command | seq));
  2408. DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB param 0x%08x\n",
  2409. (command | seq), param);
  2410. do {
  2411. /* let the FW do it's magic ... */
  2412. msleep(delay);
  2413. rc = SHMEM_RD(bp, func_mb[mb_idx].fw_mb_header);
  2414. /* Give the FW up to 5 second (500*10ms) */
  2415. } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500));
  2416. DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n",
  2417. cnt*delay, rc, seq);
  2418. /* is this a reply to our command? */
  2419. if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK))
  2420. rc &= FW_MSG_CODE_MASK;
  2421. else {
  2422. /* FW BUG! */
  2423. BNX2X_ERR("FW failed to respond!\n");
  2424. bnx2x_fw_dump(bp);
  2425. rc = 0;
  2426. }
  2427. mutex_unlock(&bp->fw_mb_mutex);
  2428. return rc;
  2429. }
  2430. static void storm_memset_func_cfg(struct bnx2x *bp,
  2431. struct tstorm_eth_function_common_config *tcfg,
  2432. u16 abs_fid)
  2433. {
  2434. size_t size = sizeof(struct tstorm_eth_function_common_config);
  2435. u32 addr = BAR_TSTRORM_INTMEM +
  2436. TSTORM_FUNCTION_COMMON_CONFIG_OFFSET(abs_fid);
  2437. __storm_memset_struct(bp, addr, size, (u32 *)tcfg);
  2438. }
  2439. void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p)
  2440. {
  2441. if (CHIP_IS_E1x(bp)) {
  2442. struct tstorm_eth_function_common_config tcfg = {0};
  2443. storm_memset_func_cfg(bp, &tcfg, p->func_id);
  2444. }
  2445. /* Enable the function in the FW */
  2446. storm_memset_vf_to_pf(bp, p->func_id, p->pf_id);
  2447. storm_memset_func_en(bp, p->func_id, 1);
  2448. /* spq */
  2449. if (p->func_flgs & FUNC_FLG_SPQ) {
  2450. storm_memset_spq_addr(bp, p->spq_map, p->func_id);
  2451. REG_WR(bp, XSEM_REG_FAST_MEMORY +
  2452. XSTORM_SPQ_PROD_OFFSET(p->func_id), p->spq_prod);
  2453. }
  2454. }
  2455. /**
  2456. * bnx2x_get_tx_only_flags - Return common flags
  2457. *
  2458. * @bp device handle
  2459. * @fp queue handle
  2460. * @zero_stats TRUE if statistics zeroing is needed
  2461. *
  2462. * Return the flags that are common for the Tx-only and not normal connections.
  2463. */
  2464. static unsigned long bnx2x_get_common_flags(struct bnx2x *bp,
  2465. struct bnx2x_fastpath *fp,
  2466. bool zero_stats)
  2467. {
  2468. unsigned long flags = 0;
  2469. /* PF driver will always initialize the Queue to an ACTIVE state */
  2470. __set_bit(BNX2X_Q_FLG_ACTIVE, &flags);
  2471. /* tx only connections collect statistics (on the same index as the
  2472. * parent connection). The statistics are zeroed when the parent
  2473. * connection is initialized.
  2474. */
  2475. __set_bit(BNX2X_Q_FLG_STATS, &flags);
  2476. if (zero_stats)
  2477. __set_bit(BNX2X_Q_FLG_ZERO_STATS, &flags);
  2478. return flags;
  2479. }
  2480. static unsigned long bnx2x_get_q_flags(struct bnx2x *bp,
  2481. struct bnx2x_fastpath *fp,
  2482. bool leading)
  2483. {
  2484. unsigned long flags = 0;
  2485. /* calculate other queue flags */
  2486. if (IS_MF_SD(bp))
  2487. __set_bit(BNX2X_Q_FLG_OV, &flags);
  2488. if (IS_FCOE_FP(fp)) {
  2489. __set_bit(BNX2X_Q_FLG_FCOE, &flags);
  2490. /* For FCoE - force usage of default priority (for afex) */
  2491. __set_bit(BNX2X_Q_FLG_FORCE_DEFAULT_PRI, &flags);
  2492. }
  2493. if (!fp->disable_tpa) {
  2494. __set_bit(BNX2X_Q_FLG_TPA, &flags);
  2495. __set_bit(BNX2X_Q_FLG_TPA_IPV6, &flags);
  2496. if (fp->mode == TPA_MODE_GRO)
  2497. __set_bit(BNX2X_Q_FLG_TPA_GRO, &flags);
  2498. }
  2499. if (leading) {
  2500. __set_bit(BNX2X_Q_FLG_LEADING_RSS, &flags);
  2501. __set_bit(BNX2X_Q_FLG_MCAST, &flags);
  2502. }
  2503. /* Always set HW VLAN stripping */
  2504. __set_bit(BNX2X_Q_FLG_VLAN, &flags);
  2505. /* configure silent vlan removal */
  2506. if (IS_MF_AFEX(bp))
  2507. __set_bit(BNX2X_Q_FLG_SILENT_VLAN_REM, &flags);
  2508. return flags | bnx2x_get_common_flags(bp, fp, true);
  2509. }
  2510. static void bnx2x_pf_q_prep_general(struct bnx2x *bp,
  2511. struct bnx2x_fastpath *fp, struct bnx2x_general_setup_params *gen_init,
  2512. u8 cos)
  2513. {
  2514. gen_init->stat_id = bnx2x_stats_id(fp);
  2515. gen_init->spcl_id = fp->cl_id;
  2516. /* Always use mini-jumbo MTU for FCoE L2 ring */
  2517. if (IS_FCOE_FP(fp))
  2518. gen_init->mtu = BNX2X_FCOE_MINI_JUMBO_MTU;
  2519. else
  2520. gen_init->mtu = bp->dev->mtu;
  2521. gen_init->cos = cos;
  2522. }
  2523. static void bnx2x_pf_rx_q_prep(struct bnx2x *bp,
  2524. struct bnx2x_fastpath *fp, struct rxq_pause_params *pause,
  2525. struct bnx2x_rxq_setup_params *rxq_init)
  2526. {
  2527. u8 max_sge = 0;
  2528. u16 sge_sz = 0;
  2529. u16 tpa_agg_size = 0;
  2530. if (!fp->disable_tpa) {
  2531. pause->sge_th_lo = SGE_TH_LO(bp);
  2532. pause->sge_th_hi = SGE_TH_HI(bp);
  2533. /* validate SGE ring has enough to cross high threshold */
  2534. WARN_ON(bp->dropless_fc &&
  2535. pause->sge_th_hi + FW_PREFETCH_CNT >
  2536. MAX_RX_SGE_CNT * NUM_RX_SGE_PAGES);
  2537. tpa_agg_size = min_t(u32,
  2538. (min_t(u32, 8, MAX_SKB_FRAGS) *
  2539. SGE_PAGE_SIZE * PAGES_PER_SGE), 0xffff);
  2540. max_sge = SGE_PAGE_ALIGN(bp->dev->mtu) >>
  2541. SGE_PAGE_SHIFT;
  2542. max_sge = ((max_sge + PAGES_PER_SGE - 1) &
  2543. (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
  2544. sge_sz = (u16)min_t(u32, SGE_PAGE_SIZE * PAGES_PER_SGE,
  2545. 0xffff);
  2546. }
  2547. /* pause - not for e1 */
  2548. if (!CHIP_IS_E1(bp)) {
  2549. pause->bd_th_lo = BD_TH_LO(bp);
  2550. pause->bd_th_hi = BD_TH_HI(bp);
  2551. pause->rcq_th_lo = RCQ_TH_LO(bp);
  2552. pause->rcq_th_hi = RCQ_TH_HI(bp);
  2553. /*
  2554. * validate that rings have enough entries to cross
  2555. * high thresholds
  2556. */
  2557. WARN_ON(bp->dropless_fc &&
  2558. pause->bd_th_hi + FW_PREFETCH_CNT >
  2559. bp->rx_ring_size);
  2560. WARN_ON(bp->dropless_fc &&
  2561. pause->rcq_th_hi + FW_PREFETCH_CNT >
  2562. NUM_RCQ_RINGS * MAX_RCQ_DESC_CNT);
  2563. pause->pri_map = 1;
  2564. }
  2565. /* rxq setup */
  2566. rxq_init->dscr_map = fp->rx_desc_mapping;
  2567. rxq_init->sge_map = fp->rx_sge_mapping;
  2568. rxq_init->rcq_map = fp->rx_comp_mapping;
  2569. rxq_init->rcq_np_map = fp->rx_comp_mapping + BCM_PAGE_SIZE;
  2570. /* This should be a maximum number of data bytes that may be
  2571. * placed on the BD (not including paddings).
  2572. */
  2573. rxq_init->buf_sz = fp->rx_buf_size - BNX2X_FW_RX_ALIGN_START -
  2574. BNX2X_FW_RX_ALIGN_END - IP_HEADER_ALIGNMENT_PADDING;
  2575. rxq_init->cl_qzone_id = fp->cl_qzone_id;
  2576. rxq_init->tpa_agg_sz = tpa_agg_size;
  2577. rxq_init->sge_buf_sz = sge_sz;
  2578. rxq_init->max_sges_pkt = max_sge;
  2579. rxq_init->rss_engine_id = BP_FUNC(bp);
  2580. rxq_init->mcast_engine_id = BP_FUNC(bp);
  2581. /* Maximum number or simultaneous TPA aggregation for this Queue.
  2582. *
  2583. * For PF Clients it should be the maximum avaliable number.
  2584. * VF driver(s) may want to define it to a smaller value.
  2585. */
  2586. rxq_init->max_tpa_queues = MAX_AGG_QS(bp);
  2587. rxq_init->cache_line_log = BNX2X_RX_ALIGN_SHIFT;
  2588. rxq_init->fw_sb_id = fp->fw_sb_id;
  2589. if (IS_FCOE_FP(fp))
  2590. rxq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS;
  2591. else
  2592. rxq_init->sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  2593. /* configure silent vlan removal
  2594. * if multi function mode is afex, then mask default vlan
  2595. */
  2596. if (IS_MF_AFEX(bp)) {
  2597. rxq_init->silent_removal_value = bp->afex_def_vlan_tag;
  2598. rxq_init->silent_removal_mask = VLAN_VID_MASK;
  2599. }
  2600. }
  2601. static void bnx2x_pf_tx_q_prep(struct bnx2x *bp,
  2602. struct bnx2x_fastpath *fp, struct bnx2x_txq_setup_params *txq_init,
  2603. u8 cos)
  2604. {
  2605. txq_init->dscr_map = fp->txdata_ptr[cos]->tx_desc_mapping;
  2606. txq_init->sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS + cos;
  2607. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_NW;
  2608. txq_init->fw_sb_id = fp->fw_sb_id;
  2609. /*
  2610. * set the tss leading client id for TX classfication ==
  2611. * leading RSS client id
  2612. */
  2613. txq_init->tss_leading_cl_id = bnx2x_fp(bp, 0, cl_id);
  2614. if (IS_FCOE_FP(fp)) {
  2615. txq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS;
  2616. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_FCOE;
  2617. }
  2618. }
  2619. static void bnx2x_pf_init(struct bnx2x *bp)
  2620. {
  2621. struct bnx2x_func_init_params func_init = {0};
  2622. struct event_ring_data eq_data = { {0} };
  2623. u16 flags;
  2624. if (!CHIP_IS_E1x(bp)) {
  2625. /* reset IGU PF statistics: MSIX + ATTN */
  2626. /* PF */
  2627. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2628. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2629. (CHIP_MODE_IS_4_PORT(bp) ?
  2630. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2631. /* ATTN */
  2632. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2633. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2634. BNX2X_IGU_STAS_MSG_PF_CNT*4 +
  2635. (CHIP_MODE_IS_4_PORT(bp) ?
  2636. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2637. }
  2638. /* function setup flags */
  2639. flags = (FUNC_FLG_STATS | FUNC_FLG_LEADING | FUNC_FLG_SPQ);
  2640. /* This flag is relevant for E1x only.
  2641. * E2 doesn't have a TPA configuration in a function level.
  2642. */
  2643. flags |= (bp->flags & TPA_ENABLE_FLAG) ? FUNC_FLG_TPA : 0;
  2644. func_init.func_flgs = flags;
  2645. func_init.pf_id = BP_FUNC(bp);
  2646. func_init.func_id = BP_FUNC(bp);
  2647. func_init.spq_map = bp->spq_mapping;
  2648. func_init.spq_prod = bp->spq_prod_idx;
  2649. bnx2x_func_init(bp, &func_init);
  2650. memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port));
  2651. /*
  2652. * Congestion management values depend on the link rate
  2653. * There is no active link so initial link rate is set to 10 Gbps.
  2654. * When the link comes up The congestion management values are
  2655. * re-calculated according to the actual link rate.
  2656. */
  2657. bp->link_vars.line_speed = SPEED_10000;
  2658. bnx2x_cmng_fns_init(bp, true, bnx2x_get_cmng_fns_mode(bp));
  2659. /* Only the PMF sets the HW */
  2660. if (bp->port.pmf)
  2661. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2662. /* init Event Queue */
  2663. eq_data.base_addr.hi = U64_HI(bp->eq_mapping);
  2664. eq_data.base_addr.lo = U64_LO(bp->eq_mapping);
  2665. eq_data.producer = bp->eq_prod;
  2666. eq_data.index_id = HC_SP_INDEX_EQ_CONS;
  2667. eq_data.sb_id = DEF_SB_ID;
  2668. storm_memset_eq_data(bp, &eq_data, BP_FUNC(bp));
  2669. }
  2670. static void bnx2x_e1h_disable(struct bnx2x *bp)
  2671. {
  2672. int port = BP_PORT(bp);
  2673. bnx2x_tx_disable(bp);
  2674. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  2675. }
  2676. static void bnx2x_e1h_enable(struct bnx2x *bp)
  2677. {
  2678. int port = BP_PORT(bp);
  2679. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
  2680. /* Tx queue should be only reenabled */
  2681. netif_tx_wake_all_queues(bp->dev);
  2682. /*
  2683. * Should not call netif_carrier_on since it will be called if the link
  2684. * is up when checking for link state
  2685. */
  2686. }
  2687. #define DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED 3
  2688. static void bnx2x_drv_info_ether_stat(struct bnx2x *bp)
  2689. {
  2690. struct eth_stats_info *ether_stat =
  2691. &bp->slowpath->drv_info_to_mcp.ether_stat;
  2692. strlcpy(ether_stat->version, DRV_MODULE_VERSION,
  2693. ETH_STAT_INFO_VERSION_LEN);
  2694. bp->sp_objs[0].mac_obj.get_n_elements(bp, &bp->sp_objs[0].mac_obj,
  2695. DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED,
  2696. ether_stat->mac_local);
  2697. ether_stat->mtu_size = bp->dev->mtu;
  2698. if (bp->dev->features & NETIF_F_RXCSUM)
  2699. ether_stat->feature_flags |= FEATURE_ETH_CHKSUM_OFFLOAD_MASK;
  2700. if (bp->dev->features & NETIF_F_TSO)
  2701. ether_stat->feature_flags |= FEATURE_ETH_LSO_MASK;
  2702. ether_stat->feature_flags |= bp->common.boot_mode;
  2703. ether_stat->promiscuous_mode = (bp->dev->flags & IFF_PROMISC) ? 1 : 0;
  2704. ether_stat->txq_size = bp->tx_ring_size;
  2705. ether_stat->rxq_size = bp->rx_ring_size;
  2706. }
  2707. static void bnx2x_drv_info_fcoe_stat(struct bnx2x *bp)
  2708. {
  2709. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2710. struct fcoe_stats_info *fcoe_stat =
  2711. &bp->slowpath->drv_info_to_mcp.fcoe_stat;
  2712. if (!CNIC_LOADED(bp))
  2713. return;
  2714. memcpy(fcoe_stat->mac_local + MAC_LEADING_ZERO_CNT,
  2715. bp->fip_mac, ETH_ALEN);
  2716. fcoe_stat->qos_priority =
  2717. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_FCOE];
  2718. /* insert FCoE stats from ramrod response */
  2719. if (!NO_FCOE(bp)) {
  2720. struct tstorm_per_queue_stats *fcoe_q_tstorm_stats =
  2721. &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
  2722. tstorm_queue_statistics;
  2723. struct xstorm_per_queue_stats *fcoe_q_xstorm_stats =
  2724. &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
  2725. xstorm_queue_statistics;
  2726. struct fcoe_statistics_params *fw_fcoe_stat =
  2727. &bp->fw_stats_data->fcoe;
  2728. ADD_64(fcoe_stat->rx_bytes_hi, 0, fcoe_stat->rx_bytes_lo,
  2729. fw_fcoe_stat->rx_stat0.fcoe_rx_byte_cnt);
  2730. ADD_64(fcoe_stat->rx_bytes_hi,
  2731. fcoe_q_tstorm_stats->rcv_ucast_bytes.hi,
  2732. fcoe_stat->rx_bytes_lo,
  2733. fcoe_q_tstorm_stats->rcv_ucast_bytes.lo);
  2734. ADD_64(fcoe_stat->rx_bytes_hi,
  2735. fcoe_q_tstorm_stats->rcv_bcast_bytes.hi,
  2736. fcoe_stat->rx_bytes_lo,
  2737. fcoe_q_tstorm_stats->rcv_bcast_bytes.lo);
  2738. ADD_64(fcoe_stat->rx_bytes_hi,
  2739. fcoe_q_tstorm_stats->rcv_mcast_bytes.hi,
  2740. fcoe_stat->rx_bytes_lo,
  2741. fcoe_q_tstorm_stats->rcv_mcast_bytes.lo);
  2742. ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
  2743. fw_fcoe_stat->rx_stat0.fcoe_rx_pkt_cnt);
  2744. ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
  2745. fcoe_q_tstorm_stats->rcv_ucast_pkts);
  2746. ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
  2747. fcoe_q_tstorm_stats->rcv_bcast_pkts);
  2748. ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
  2749. fcoe_q_tstorm_stats->rcv_mcast_pkts);
  2750. ADD_64(fcoe_stat->tx_bytes_hi, 0, fcoe_stat->tx_bytes_lo,
  2751. fw_fcoe_stat->tx_stat.fcoe_tx_byte_cnt);
  2752. ADD_64(fcoe_stat->tx_bytes_hi,
  2753. fcoe_q_xstorm_stats->ucast_bytes_sent.hi,
  2754. fcoe_stat->tx_bytes_lo,
  2755. fcoe_q_xstorm_stats->ucast_bytes_sent.lo);
  2756. ADD_64(fcoe_stat->tx_bytes_hi,
  2757. fcoe_q_xstorm_stats->bcast_bytes_sent.hi,
  2758. fcoe_stat->tx_bytes_lo,
  2759. fcoe_q_xstorm_stats->bcast_bytes_sent.lo);
  2760. ADD_64(fcoe_stat->tx_bytes_hi,
  2761. fcoe_q_xstorm_stats->mcast_bytes_sent.hi,
  2762. fcoe_stat->tx_bytes_lo,
  2763. fcoe_q_xstorm_stats->mcast_bytes_sent.lo);
  2764. ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
  2765. fw_fcoe_stat->tx_stat.fcoe_tx_pkt_cnt);
  2766. ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
  2767. fcoe_q_xstorm_stats->ucast_pkts_sent);
  2768. ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
  2769. fcoe_q_xstorm_stats->bcast_pkts_sent);
  2770. ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
  2771. fcoe_q_xstorm_stats->mcast_pkts_sent);
  2772. }
  2773. /* ask L5 driver to add data to the struct */
  2774. bnx2x_cnic_notify(bp, CNIC_CTL_FCOE_STATS_GET_CMD);
  2775. }
  2776. static void bnx2x_drv_info_iscsi_stat(struct bnx2x *bp)
  2777. {
  2778. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2779. struct iscsi_stats_info *iscsi_stat =
  2780. &bp->slowpath->drv_info_to_mcp.iscsi_stat;
  2781. if (!CNIC_LOADED(bp))
  2782. return;
  2783. memcpy(iscsi_stat->mac_local + MAC_LEADING_ZERO_CNT,
  2784. bp->cnic_eth_dev.iscsi_mac, ETH_ALEN);
  2785. iscsi_stat->qos_priority =
  2786. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_ISCSI];
  2787. /* ask L5 driver to add data to the struct */
  2788. bnx2x_cnic_notify(bp, CNIC_CTL_ISCSI_STATS_GET_CMD);
  2789. }
  2790. /* called due to MCP event (on pmf):
  2791. * reread new bandwidth configuration
  2792. * configure FW
  2793. * notify others function about the change
  2794. */
  2795. static void bnx2x_config_mf_bw(struct bnx2x *bp)
  2796. {
  2797. if (bp->link_vars.link_up) {
  2798. bnx2x_cmng_fns_init(bp, true, CMNG_FNS_MINMAX);
  2799. bnx2x_link_sync_notify(bp);
  2800. }
  2801. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2802. }
  2803. static void bnx2x_set_mf_bw(struct bnx2x *bp)
  2804. {
  2805. bnx2x_config_mf_bw(bp);
  2806. bnx2x_fw_command(bp, DRV_MSG_CODE_SET_MF_BW_ACK, 0);
  2807. }
  2808. static void bnx2x_handle_eee_event(struct bnx2x *bp)
  2809. {
  2810. DP(BNX2X_MSG_MCP, "EEE - LLDP event\n");
  2811. bnx2x_fw_command(bp, DRV_MSG_CODE_EEE_RESULTS_ACK, 0);
  2812. }
  2813. static void bnx2x_handle_drv_info_req(struct bnx2x *bp)
  2814. {
  2815. enum drv_info_opcode op_code;
  2816. u32 drv_info_ctl = SHMEM2_RD(bp, drv_info_control);
  2817. /* if drv_info version supported by MFW doesn't match - send NACK */
  2818. if ((drv_info_ctl & DRV_INFO_CONTROL_VER_MASK) != DRV_INFO_CUR_VER) {
  2819. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  2820. return;
  2821. }
  2822. op_code = (drv_info_ctl & DRV_INFO_CONTROL_OP_CODE_MASK) >>
  2823. DRV_INFO_CONTROL_OP_CODE_SHIFT;
  2824. memset(&bp->slowpath->drv_info_to_mcp, 0,
  2825. sizeof(union drv_info_to_mcp));
  2826. switch (op_code) {
  2827. case ETH_STATS_OPCODE:
  2828. bnx2x_drv_info_ether_stat(bp);
  2829. break;
  2830. case FCOE_STATS_OPCODE:
  2831. bnx2x_drv_info_fcoe_stat(bp);
  2832. break;
  2833. case ISCSI_STATS_OPCODE:
  2834. bnx2x_drv_info_iscsi_stat(bp);
  2835. break;
  2836. default:
  2837. /* if op code isn't supported - send NACK */
  2838. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  2839. return;
  2840. }
  2841. /* if we got drv_info attn from MFW then these fields are defined in
  2842. * shmem2 for sure
  2843. */
  2844. SHMEM2_WR(bp, drv_info_host_addr_lo,
  2845. U64_LO(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  2846. SHMEM2_WR(bp, drv_info_host_addr_hi,
  2847. U64_HI(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  2848. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_ACK, 0);
  2849. }
  2850. static void bnx2x_dcc_event(struct bnx2x *bp, u32 dcc_event)
  2851. {
  2852. DP(BNX2X_MSG_MCP, "dcc_event 0x%x\n", dcc_event);
  2853. if (dcc_event & DRV_STATUS_DCC_DISABLE_ENABLE_PF) {
  2854. /*
  2855. * This is the only place besides the function initialization
  2856. * where the bp->flags can change so it is done without any
  2857. * locks
  2858. */
  2859. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  2860. DP(BNX2X_MSG_MCP, "mf_cfg function disabled\n");
  2861. bp->flags |= MF_FUNC_DIS;
  2862. bnx2x_e1h_disable(bp);
  2863. } else {
  2864. DP(BNX2X_MSG_MCP, "mf_cfg function enabled\n");
  2865. bp->flags &= ~MF_FUNC_DIS;
  2866. bnx2x_e1h_enable(bp);
  2867. }
  2868. dcc_event &= ~DRV_STATUS_DCC_DISABLE_ENABLE_PF;
  2869. }
  2870. if (dcc_event & DRV_STATUS_DCC_BANDWIDTH_ALLOCATION) {
  2871. bnx2x_config_mf_bw(bp);
  2872. dcc_event &= ~DRV_STATUS_DCC_BANDWIDTH_ALLOCATION;
  2873. }
  2874. /* Report results to MCP */
  2875. if (dcc_event)
  2876. bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_FAILURE, 0);
  2877. else
  2878. bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_OK, 0);
  2879. }
  2880. /* must be called under the spq lock */
  2881. static struct eth_spe *bnx2x_sp_get_next(struct bnx2x *bp)
  2882. {
  2883. struct eth_spe *next_spe = bp->spq_prod_bd;
  2884. if (bp->spq_prod_bd == bp->spq_last_bd) {
  2885. bp->spq_prod_bd = bp->spq;
  2886. bp->spq_prod_idx = 0;
  2887. DP(BNX2X_MSG_SP, "end of spq\n");
  2888. } else {
  2889. bp->spq_prod_bd++;
  2890. bp->spq_prod_idx++;
  2891. }
  2892. return next_spe;
  2893. }
  2894. /* must be called under the spq lock */
  2895. static void bnx2x_sp_prod_update(struct bnx2x *bp)
  2896. {
  2897. int func = BP_FUNC(bp);
  2898. /*
  2899. * Make sure that BD data is updated before writing the producer:
  2900. * BD data is written to the memory, the producer is read from the
  2901. * memory, thus we need a full memory barrier to ensure the ordering.
  2902. */
  2903. mb();
  2904. REG_WR16(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func),
  2905. bp->spq_prod_idx);
  2906. mmiowb();
  2907. }
  2908. /**
  2909. * bnx2x_is_contextless_ramrod - check if the current command ends on EQ
  2910. *
  2911. * @cmd: command to check
  2912. * @cmd_type: command type
  2913. */
  2914. static bool bnx2x_is_contextless_ramrod(int cmd, int cmd_type)
  2915. {
  2916. if ((cmd_type == NONE_CONNECTION_TYPE) ||
  2917. (cmd == RAMROD_CMD_ID_ETH_FORWARD_SETUP) ||
  2918. (cmd == RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES) ||
  2919. (cmd == RAMROD_CMD_ID_ETH_FILTER_RULES) ||
  2920. (cmd == RAMROD_CMD_ID_ETH_MULTICAST_RULES) ||
  2921. (cmd == RAMROD_CMD_ID_ETH_SET_MAC) ||
  2922. (cmd == RAMROD_CMD_ID_ETH_RSS_UPDATE))
  2923. return true;
  2924. else
  2925. return false;
  2926. }
  2927. /**
  2928. * bnx2x_sp_post - place a single command on an SP ring
  2929. *
  2930. * @bp: driver handle
  2931. * @command: command to place (e.g. SETUP, FILTER_RULES, etc.)
  2932. * @cid: SW CID the command is related to
  2933. * @data_hi: command private data address (high 32 bits)
  2934. * @data_lo: command private data address (low 32 bits)
  2935. * @cmd_type: command type (e.g. NONE, ETH)
  2936. *
  2937. * SP data is handled as if it's always an address pair, thus data fields are
  2938. * not swapped to little endian in upper functions. Instead this function swaps
  2939. * data as if it's two u32 fields.
  2940. */
  2941. int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
  2942. u32 data_hi, u32 data_lo, int cmd_type)
  2943. {
  2944. struct eth_spe *spe;
  2945. u16 type;
  2946. bool common = bnx2x_is_contextless_ramrod(command, cmd_type);
  2947. #ifdef BNX2X_STOP_ON_ERROR
  2948. if (unlikely(bp->panic)) {
  2949. BNX2X_ERR("Can't post SP when there is panic\n");
  2950. return -EIO;
  2951. }
  2952. #endif
  2953. spin_lock_bh(&bp->spq_lock);
  2954. if (common) {
  2955. if (!atomic_read(&bp->eq_spq_left)) {
  2956. BNX2X_ERR("BUG! EQ ring full!\n");
  2957. spin_unlock_bh(&bp->spq_lock);
  2958. bnx2x_panic();
  2959. return -EBUSY;
  2960. }
  2961. } else if (!atomic_read(&bp->cq_spq_left)) {
  2962. BNX2X_ERR("BUG! SPQ ring full!\n");
  2963. spin_unlock_bh(&bp->spq_lock);
  2964. bnx2x_panic();
  2965. return -EBUSY;
  2966. }
  2967. spe = bnx2x_sp_get_next(bp);
  2968. /* CID needs port number to be encoded int it */
  2969. spe->hdr.conn_and_cmd_data =
  2970. cpu_to_le32((command << SPE_HDR_CMD_ID_SHIFT) |
  2971. HW_CID(bp, cid));
  2972. type = (cmd_type << SPE_HDR_CONN_TYPE_SHIFT) & SPE_HDR_CONN_TYPE;
  2973. type |= ((BP_FUNC(bp) << SPE_HDR_FUNCTION_ID_SHIFT) &
  2974. SPE_HDR_FUNCTION_ID);
  2975. spe->hdr.type = cpu_to_le16(type);
  2976. spe->data.update_data_addr.hi = cpu_to_le32(data_hi);
  2977. spe->data.update_data_addr.lo = cpu_to_le32(data_lo);
  2978. /*
  2979. * It's ok if the actual decrement is issued towards the memory
  2980. * somewhere between the spin_lock and spin_unlock. Thus no
  2981. * more explict memory barrier is needed.
  2982. */
  2983. if (common)
  2984. atomic_dec(&bp->eq_spq_left);
  2985. else
  2986. atomic_dec(&bp->cq_spq_left);
  2987. DP(BNX2X_MSG_SP,
  2988. "SPQE[%x] (%x:%x) (cmd, common?) (%d,%d) hw_cid %x data (%x:%x) type(0x%x) left (CQ, EQ) (%x,%x)\n",
  2989. bp->spq_prod_idx, (u32)U64_HI(bp->spq_mapping),
  2990. (u32)(U64_LO(bp->spq_mapping) +
  2991. (void *)bp->spq_prod_bd - (void *)bp->spq), command, common,
  2992. HW_CID(bp, cid), data_hi, data_lo, type,
  2993. atomic_read(&bp->cq_spq_left), atomic_read(&bp->eq_spq_left));
  2994. bnx2x_sp_prod_update(bp);
  2995. spin_unlock_bh(&bp->spq_lock);
  2996. return 0;
  2997. }
  2998. /* acquire split MCP access lock register */
  2999. static int bnx2x_acquire_alr(struct bnx2x *bp)
  3000. {
  3001. u32 j, val;
  3002. int rc = 0;
  3003. might_sleep();
  3004. for (j = 0; j < 1000; j++) {
  3005. val = (1UL << 31);
  3006. REG_WR(bp, GRCBASE_MCP + 0x9c, val);
  3007. val = REG_RD(bp, GRCBASE_MCP + 0x9c);
  3008. if (val & (1L << 31))
  3009. break;
  3010. msleep(5);
  3011. }
  3012. if (!(val & (1L << 31))) {
  3013. BNX2X_ERR("Cannot acquire MCP access lock register\n");
  3014. rc = -EBUSY;
  3015. }
  3016. return rc;
  3017. }
  3018. /* release split MCP access lock register */
  3019. static void bnx2x_release_alr(struct bnx2x *bp)
  3020. {
  3021. REG_WR(bp, GRCBASE_MCP + 0x9c, 0);
  3022. }
  3023. #define BNX2X_DEF_SB_ATT_IDX 0x0001
  3024. #define BNX2X_DEF_SB_IDX 0x0002
  3025. static u16 bnx2x_update_dsb_idx(struct bnx2x *bp)
  3026. {
  3027. struct host_sp_status_block *def_sb = bp->def_status_blk;
  3028. u16 rc = 0;
  3029. barrier(); /* status block is written to by the chip */
  3030. if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) {
  3031. bp->def_att_idx = def_sb->atten_status_block.attn_bits_index;
  3032. rc |= BNX2X_DEF_SB_ATT_IDX;
  3033. }
  3034. if (bp->def_idx != def_sb->sp_sb.running_index) {
  3035. bp->def_idx = def_sb->sp_sb.running_index;
  3036. rc |= BNX2X_DEF_SB_IDX;
  3037. }
  3038. /* Do not reorder: indecies reading should complete before handling */
  3039. barrier();
  3040. return rc;
  3041. }
  3042. /*
  3043. * slow path service functions
  3044. */
  3045. static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted)
  3046. {
  3047. int port = BP_PORT(bp);
  3048. u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  3049. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  3050. u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 :
  3051. NIG_REG_MASK_INTERRUPT_PORT0;
  3052. u32 aeu_mask;
  3053. u32 nig_mask = 0;
  3054. u32 reg_addr;
  3055. if (bp->attn_state & asserted)
  3056. BNX2X_ERR("IGU ERROR\n");
  3057. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3058. aeu_mask = REG_RD(bp, aeu_addr);
  3059. DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n",
  3060. aeu_mask, asserted);
  3061. aeu_mask &= ~(asserted & 0x3ff);
  3062. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  3063. REG_WR(bp, aeu_addr, aeu_mask);
  3064. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3065. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  3066. bp->attn_state |= asserted;
  3067. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  3068. if (asserted & ATTN_HARD_WIRED_MASK) {
  3069. if (asserted & ATTN_NIG_FOR_FUNC) {
  3070. bnx2x_acquire_phy_lock(bp);
  3071. /* save nig interrupt mask */
  3072. nig_mask = REG_RD(bp, nig_int_mask_addr);
  3073. /* If nig_mask is not set, no need to call the update
  3074. * function.
  3075. */
  3076. if (nig_mask) {
  3077. REG_WR(bp, nig_int_mask_addr, 0);
  3078. bnx2x_link_attn(bp);
  3079. }
  3080. /* handle unicore attn? */
  3081. }
  3082. if (asserted & ATTN_SW_TIMER_4_FUNC)
  3083. DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n");
  3084. if (asserted & GPIO_2_FUNC)
  3085. DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n");
  3086. if (asserted & GPIO_3_FUNC)
  3087. DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n");
  3088. if (asserted & GPIO_4_FUNC)
  3089. DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n");
  3090. if (port == 0) {
  3091. if (asserted & ATTN_GENERAL_ATTN_1) {
  3092. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n");
  3093. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0);
  3094. }
  3095. if (asserted & ATTN_GENERAL_ATTN_2) {
  3096. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n");
  3097. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0);
  3098. }
  3099. if (asserted & ATTN_GENERAL_ATTN_3) {
  3100. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n");
  3101. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0);
  3102. }
  3103. } else {
  3104. if (asserted & ATTN_GENERAL_ATTN_4) {
  3105. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n");
  3106. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0);
  3107. }
  3108. if (asserted & ATTN_GENERAL_ATTN_5) {
  3109. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n");
  3110. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0);
  3111. }
  3112. if (asserted & ATTN_GENERAL_ATTN_6) {
  3113. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n");
  3114. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0);
  3115. }
  3116. }
  3117. } /* if hardwired */
  3118. if (bp->common.int_block == INT_BLOCK_HC)
  3119. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  3120. COMMAND_REG_ATTN_BITS_SET);
  3121. else
  3122. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_SET_UPPER*8);
  3123. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", asserted,
  3124. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  3125. REG_WR(bp, reg_addr, asserted);
  3126. /* now set back the mask */
  3127. if (asserted & ATTN_NIG_FOR_FUNC) {
  3128. /* Verify that IGU ack through BAR was written before restoring
  3129. * NIG mask. This loop should exit after 2-3 iterations max.
  3130. */
  3131. if (bp->common.int_block != INT_BLOCK_HC) {
  3132. u32 cnt = 0, igu_acked;
  3133. do {
  3134. igu_acked = REG_RD(bp,
  3135. IGU_REG_ATTENTION_ACK_BITS);
  3136. } while (((igu_acked & ATTN_NIG_FOR_FUNC) == 0) &&
  3137. (++cnt < MAX_IGU_ATTN_ACK_TO));
  3138. if (!igu_acked)
  3139. DP(NETIF_MSG_HW,
  3140. "Failed to verify IGU ack on time\n");
  3141. barrier();
  3142. }
  3143. REG_WR(bp, nig_int_mask_addr, nig_mask);
  3144. bnx2x_release_phy_lock(bp);
  3145. }
  3146. }
  3147. static void bnx2x_fan_failure(struct bnx2x *bp)
  3148. {
  3149. int port = BP_PORT(bp);
  3150. u32 ext_phy_config;
  3151. /* mark the failure */
  3152. ext_phy_config =
  3153. SHMEM_RD(bp,
  3154. dev_info.port_hw_config[port].external_phy_config);
  3155. ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
  3156. ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE;
  3157. SHMEM_WR(bp, dev_info.port_hw_config[port].external_phy_config,
  3158. ext_phy_config);
  3159. /* log the failure */
  3160. netdev_err(bp->dev, "Fan Failure on Network Controller has caused the driver to shutdown the card to prevent permanent damage.\n"
  3161. "Please contact OEM Support for assistance\n");
  3162. /*
  3163. * Scheudle device reset (unload)
  3164. * This is due to some boards consuming sufficient power when driver is
  3165. * up to overheat if fan fails.
  3166. */
  3167. smp_mb__before_clear_bit();
  3168. set_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state);
  3169. smp_mb__after_clear_bit();
  3170. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  3171. }
  3172. static void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn)
  3173. {
  3174. int port = BP_PORT(bp);
  3175. int reg_offset;
  3176. u32 val;
  3177. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  3178. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  3179. if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) {
  3180. val = REG_RD(bp, reg_offset);
  3181. val &= ~AEU_INPUTS_ATTN_BITS_SPIO5;
  3182. REG_WR(bp, reg_offset, val);
  3183. BNX2X_ERR("SPIO5 hw attention\n");
  3184. /* Fan failure attention */
  3185. bnx2x_hw_reset_phy(&bp->link_params);
  3186. bnx2x_fan_failure(bp);
  3187. }
  3188. if ((attn & bp->link_vars.aeu_int_mask) && bp->port.pmf) {
  3189. bnx2x_acquire_phy_lock(bp);
  3190. bnx2x_handle_module_detect_int(&bp->link_params);
  3191. bnx2x_release_phy_lock(bp);
  3192. }
  3193. if (attn & HW_INTERRUT_ASSERT_SET_0) {
  3194. val = REG_RD(bp, reg_offset);
  3195. val &= ~(attn & HW_INTERRUT_ASSERT_SET_0);
  3196. REG_WR(bp, reg_offset, val);
  3197. BNX2X_ERR("FATAL HW block attention set0 0x%x\n",
  3198. (u32)(attn & HW_INTERRUT_ASSERT_SET_0));
  3199. bnx2x_panic();
  3200. }
  3201. }
  3202. static void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn)
  3203. {
  3204. u32 val;
  3205. if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) {
  3206. val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR);
  3207. BNX2X_ERR("DB hw attention 0x%x\n", val);
  3208. /* DORQ discard attention */
  3209. if (val & 0x2)
  3210. BNX2X_ERR("FATAL error from DORQ\n");
  3211. }
  3212. if (attn & HW_INTERRUT_ASSERT_SET_1) {
  3213. int port = BP_PORT(bp);
  3214. int reg_offset;
  3215. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 :
  3216. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1);
  3217. val = REG_RD(bp, reg_offset);
  3218. val &= ~(attn & HW_INTERRUT_ASSERT_SET_1);
  3219. REG_WR(bp, reg_offset, val);
  3220. BNX2X_ERR("FATAL HW block attention set1 0x%x\n",
  3221. (u32)(attn & HW_INTERRUT_ASSERT_SET_1));
  3222. bnx2x_panic();
  3223. }
  3224. }
  3225. static void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn)
  3226. {
  3227. u32 val;
  3228. if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) {
  3229. val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR);
  3230. BNX2X_ERR("CFC hw attention 0x%x\n", val);
  3231. /* CFC error attention */
  3232. if (val & 0x2)
  3233. BNX2X_ERR("FATAL error from CFC\n");
  3234. }
  3235. if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) {
  3236. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0);
  3237. BNX2X_ERR("PXP hw attention-0 0x%x\n", val);
  3238. /* RQ_USDMDP_FIFO_OVERFLOW */
  3239. if (val & 0x18000)
  3240. BNX2X_ERR("FATAL error from PXP\n");
  3241. if (!CHIP_IS_E1x(bp)) {
  3242. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_1);
  3243. BNX2X_ERR("PXP hw attention-1 0x%x\n", val);
  3244. }
  3245. }
  3246. if (attn & HW_INTERRUT_ASSERT_SET_2) {
  3247. int port = BP_PORT(bp);
  3248. int reg_offset;
  3249. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 :
  3250. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2);
  3251. val = REG_RD(bp, reg_offset);
  3252. val &= ~(attn & HW_INTERRUT_ASSERT_SET_2);
  3253. REG_WR(bp, reg_offset, val);
  3254. BNX2X_ERR("FATAL HW block attention set2 0x%x\n",
  3255. (u32)(attn & HW_INTERRUT_ASSERT_SET_2));
  3256. bnx2x_panic();
  3257. }
  3258. }
  3259. static void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn)
  3260. {
  3261. u32 val;
  3262. if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) {
  3263. if (attn & BNX2X_PMF_LINK_ASSERT) {
  3264. int func = BP_FUNC(bp);
  3265. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  3266. bnx2x_read_mf_cfg(bp);
  3267. bp->mf_config[BP_VN(bp)] = MF_CFG_RD(bp,
  3268. func_mf_config[BP_ABS_FUNC(bp)].config);
  3269. val = SHMEM_RD(bp,
  3270. func_mb[BP_FW_MB_IDX(bp)].drv_status);
  3271. if (val & DRV_STATUS_DCC_EVENT_MASK)
  3272. bnx2x_dcc_event(bp,
  3273. (val & DRV_STATUS_DCC_EVENT_MASK));
  3274. if (val & DRV_STATUS_SET_MF_BW)
  3275. bnx2x_set_mf_bw(bp);
  3276. if (val & DRV_STATUS_DRV_INFO_REQ)
  3277. bnx2x_handle_drv_info_req(bp);
  3278. if (val & DRV_STATUS_VF_DISABLED)
  3279. bnx2x_vf_handle_flr_event(bp);
  3280. if ((bp->port.pmf == 0) && (val & DRV_STATUS_PMF))
  3281. bnx2x_pmf_update(bp);
  3282. if (bp->port.pmf &&
  3283. (val & DRV_STATUS_DCBX_NEGOTIATION_RESULTS) &&
  3284. bp->dcbx_enabled > 0)
  3285. /* start dcbx state machine */
  3286. bnx2x_dcbx_set_params(bp,
  3287. BNX2X_DCBX_STATE_NEG_RECEIVED);
  3288. if (val & DRV_STATUS_AFEX_EVENT_MASK)
  3289. bnx2x_handle_afex_cmd(bp,
  3290. val & DRV_STATUS_AFEX_EVENT_MASK);
  3291. if (val & DRV_STATUS_EEE_NEGOTIATION_RESULTS)
  3292. bnx2x_handle_eee_event(bp);
  3293. if (bp->link_vars.periodic_flags &
  3294. PERIODIC_FLAGS_LINK_EVENT) {
  3295. /* sync with link */
  3296. bnx2x_acquire_phy_lock(bp);
  3297. bp->link_vars.periodic_flags &=
  3298. ~PERIODIC_FLAGS_LINK_EVENT;
  3299. bnx2x_release_phy_lock(bp);
  3300. if (IS_MF(bp))
  3301. bnx2x_link_sync_notify(bp);
  3302. bnx2x_link_report(bp);
  3303. }
  3304. /* Always call it here: bnx2x_link_report() will
  3305. * prevent the link indication duplication.
  3306. */
  3307. bnx2x__link_status_update(bp);
  3308. } else if (attn & BNX2X_MC_ASSERT_BITS) {
  3309. BNX2X_ERR("MC assert!\n");
  3310. bnx2x_mc_assert(bp);
  3311. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0);
  3312. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0);
  3313. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0);
  3314. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0);
  3315. bnx2x_panic();
  3316. } else if (attn & BNX2X_MCP_ASSERT) {
  3317. BNX2X_ERR("MCP assert!\n");
  3318. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0);
  3319. bnx2x_fw_dump(bp);
  3320. } else
  3321. BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn);
  3322. }
  3323. if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) {
  3324. BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn);
  3325. if (attn & BNX2X_GRC_TIMEOUT) {
  3326. val = CHIP_IS_E1(bp) ? 0 :
  3327. REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN);
  3328. BNX2X_ERR("GRC time-out 0x%08x\n", val);
  3329. }
  3330. if (attn & BNX2X_GRC_RSV) {
  3331. val = CHIP_IS_E1(bp) ? 0 :
  3332. REG_RD(bp, MISC_REG_GRC_RSV_ATTN);
  3333. BNX2X_ERR("GRC reserved 0x%08x\n", val);
  3334. }
  3335. REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff);
  3336. }
  3337. }
  3338. /*
  3339. * Bits map:
  3340. * 0-7 - Engine0 load counter.
  3341. * 8-15 - Engine1 load counter.
  3342. * 16 - Engine0 RESET_IN_PROGRESS bit.
  3343. * 17 - Engine1 RESET_IN_PROGRESS bit.
  3344. * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active function
  3345. * on the engine
  3346. * 19 - Engine1 ONE_IS_LOADED.
  3347. * 20 - Chip reset flow bit. When set none-leader must wait for both engines
  3348. * leader to complete (check for both RESET_IN_PROGRESS bits and not for
  3349. * just the one belonging to its engine).
  3350. *
  3351. */
  3352. #define BNX2X_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1
  3353. #define BNX2X_PATH0_LOAD_CNT_MASK 0x000000ff
  3354. #define BNX2X_PATH0_LOAD_CNT_SHIFT 0
  3355. #define BNX2X_PATH1_LOAD_CNT_MASK 0x0000ff00
  3356. #define BNX2X_PATH1_LOAD_CNT_SHIFT 8
  3357. #define BNX2X_PATH0_RST_IN_PROG_BIT 0x00010000
  3358. #define BNX2X_PATH1_RST_IN_PROG_BIT 0x00020000
  3359. #define BNX2X_GLOBAL_RESET_BIT 0x00040000
  3360. /*
  3361. * Set the GLOBAL_RESET bit.
  3362. *
  3363. * Should be run under rtnl lock
  3364. */
  3365. void bnx2x_set_reset_global(struct bnx2x *bp)
  3366. {
  3367. u32 val;
  3368. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3369. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3370. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val | BNX2X_GLOBAL_RESET_BIT);
  3371. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3372. }
  3373. /*
  3374. * Clear the GLOBAL_RESET bit.
  3375. *
  3376. * Should be run under rtnl lock
  3377. */
  3378. static void bnx2x_clear_reset_global(struct bnx2x *bp)
  3379. {
  3380. u32 val;
  3381. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3382. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3383. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~BNX2X_GLOBAL_RESET_BIT));
  3384. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3385. }
  3386. /*
  3387. * Checks the GLOBAL_RESET bit.
  3388. *
  3389. * should be run under rtnl lock
  3390. */
  3391. static bool bnx2x_reset_is_global(struct bnx2x *bp)
  3392. {
  3393. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3394. DP(NETIF_MSG_HW, "GEN_REG_VAL=0x%08x\n", val);
  3395. return (val & BNX2X_GLOBAL_RESET_BIT) ? true : false;
  3396. }
  3397. /*
  3398. * Clear RESET_IN_PROGRESS bit for the current engine.
  3399. *
  3400. * Should be run under rtnl lock
  3401. */
  3402. static void bnx2x_set_reset_done(struct bnx2x *bp)
  3403. {
  3404. u32 val;
  3405. u32 bit = BP_PATH(bp) ?
  3406. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3407. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3408. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3409. /* Clear the bit */
  3410. val &= ~bit;
  3411. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3412. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3413. }
  3414. /*
  3415. * Set RESET_IN_PROGRESS for the current engine.
  3416. *
  3417. * should be run under rtnl lock
  3418. */
  3419. void bnx2x_set_reset_in_progress(struct bnx2x *bp)
  3420. {
  3421. u32 val;
  3422. u32 bit = BP_PATH(bp) ?
  3423. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3424. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3425. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3426. /* Set the bit */
  3427. val |= bit;
  3428. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3429. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3430. }
  3431. /*
  3432. * Checks the RESET_IN_PROGRESS bit for the given engine.
  3433. * should be run under rtnl lock
  3434. */
  3435. bool bnx2x_reset_is_done(struct bnx2x *bp, int engine)
  3436. {
  3437. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3438. u32 bit = engine ?
  3439. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3440. /* return false if bit is set */
  3441. return (val & bit) ? false : true;
  3442. }
  3443. /*
  3444. * set pf load for the current pf.
  3445. *
  3446. * should be run under rtnl lock
  3447. */
  3448. void bnx2x_set_pf_load(struct bnx2x *bp)
  3449. {
  3450. u32 val1, val;
  3451. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3452. BNX2X_PATH0_LOAD_CNT_MASK;
  3453. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3454. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3455. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3456. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3457. DP(NETIF_MSG_IFUP, "Old GEN_REG_VAL=0x%08x\n", val);
  3458. /* get the current counter value */
  3459. val1 = (val & mask) >> shift;
  3460. /* set bit of that PF */
  3461. val1 |= (1 << bp->pf_num);
  3462. /* clear the old value */
  3463. val &= ~mask;
  3464. /* set the new one */
  3465. val |= ((val1 << shift) & mask);
  3466. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3467. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3468. }
  3469. /**
  3470. * bnx2x_clear_pf_load - clear pf load mark
  3471. *
  3472. * @bp: driver handle
  3473. *
  3474. * Should be run under rtnl lock.
  3475. * Decrements the load counter for the current engine. Returns
  3476. * whether other functions are still loaded
  3477. */
  3478. bool bnx2x_clear_pf_load(struct bnx2x *bp)
  3479. {
  3480. u32 val1, val;
  3481. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3482. BNX2X_PATH0_LOAD_CNT_MASK;
  3483. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3484. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3485. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3486. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3487. DP(NETIF_MSG_IFDOWN, "Old GEN_REG_VAL=0x%08x\n", val);
  3488. /* get the current counter value */
  3489. val1 = (val & mask) >> shift;
  3490. /* clear bit of that PF */
  3491. val1 &= ~(1 << bp->pf_num);
  3492. /* clear the old value */
  3493. val &= ~mask;
  3494. /* set the new one */
  3495. val |= ((val1 << shift) & mask);
  3496. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3497. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3498. return val1 != 0;
  3499. }
  3500. /*
  3501. * Read the load status for the current engine.
  3502. *
  3503. * should be run under rtnl lock
  3504. */
  3505. static bool bnx2x_get_load_status(struct bnx2x *bp, int engine)
  3506. {
  3507. u32 mask = (engine ? BNX2X_PATH1_LOAD_CNT_MASK :
  3508. BNX2X_PATH0_LOAD_CNT_MASK);
  3509. u32 shift = (engine ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3510. BNX2X_PATH0_LOAD_CNT_SHIFT);
  3511. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3512. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "GLOB_REG=0x%08x\n", val);
  3513. val = (val & mask) >> shift;
  3514. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "load mask for engine %d = 0x%x\n",
  3515. engine, val);
  3516. return val != 0;
  3517. }
  3518. static void _print_next_block(int idx, const char *blk)
  3519. {
  3520. pr_cont("%s%s", idx ? ", " : "", blk);
  3521. }
  3522. static int bnx2x_check_blocks_with_parity0(u32 sig, int par_num,
  3523. bool print)
  3524. {
  3525. int i = 0;
  3526. u32 cur_bit = 0;
  3527. for (i = 0; sig; i++) {
  3528. cur_bit = ((u32)0x1 << i);
  3529. if (sig & cur_bit) {
  3530. switch (cur_bit) {
  3531. case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR:
  3532. if (print)
  3533. _print_next_block(par_num++, "BRB");
  3534. break;
  3535. case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR:
  3536. if (print)
  3537. _print_next_block(par_num++, "PARSER");
  3538. break;
  3539. case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR:
  3540. if (print)
  3541. _print_next_block(par_num++, "TSDM");
  3542. break;
  3543. case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR:
  3544. if (print)
  3545. _print_next_block(par_num++,
  3546. "SEARCHER");
  3547. break;
  3548. case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR:
  3549. if (print)
  3550. _print_next_block(par_num++, "TCM");
  3551. break;
  3552. case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR:
  3553. if (print)
  3554. _print_next_block(par_num++, "TSEMI");
  3555. break;
  3556. case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR:
  3557. if (print)
  3558. _print_next_block(par_num++, "XPB");
  3559. break;
  3560. }
  3561. /* Clear the bit */
  3562. sig &= ~cur_bit;
  3563. }
  3564. }
  3565. return par_num;
  3566. }
  3567. static int bnx2x_check_blocks_with_parity1(u32 sig, int par_num,
  3568. bool *global, bool print)
  3569. {
  3570. int i = 0;
  3571. u32 cur_bit = 0;
  3572. for (i = 0; sig; i++) {
  3573. cur_bit = ((u32)0x1 << i);
  3574. if (sig & cur_bit) {
  3575. switch (cur_bit) {
  3576. case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR:
  3577. if (print)
  3578. _print_next_block(par_num++, "PBF");
  3579. break;
  3580. case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR:
  3581. if (print)
  3582. _print_next_block(par_num++, "QM");
  3583. break;
  3584. case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR:
  3585. if (print)
  3586. _print_next_block(par_num++, "TM");
  3587. break;
  3588. case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR:
  3589. if (print)
  3590. _print_next_block(par_num++, "XSDM");
  3591. break;
  3592. case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR:
  3593. if (print)
  3594. _print_next_block(par_num++, "XCM");
  3595. break;
  3596. case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR:
  3597. if (print)
  3598. _print_next_block(par_num++, "XSEMI");
  3599. break;
  3600. case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR:
  3601. if (print)
  3602. _print_next_block(par_num++,
  3603. "DOORBELLQ");
  3604. break;
  3605. case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR:
  3606. if (print)
  3607. _print_next_block(par_num++, "NIG");
  3608. break;
  3609. case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR:
  3610. if (print)
  3611. _print_next_block(par_num++,
  3612. "VAUX PCI CORE");
  3613. *global = true;
  3614. break;
  3615. case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR:
  3616. if (print)
  3617. _print_next_block(par_num++, "DEBUG");
  3618. break;
  3619. case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR:
  3620. if (print)
  3621. _print_next_block(par_num++, "USDM");
  3622. break;
  3623. case AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR:
  3624. if (print)
  3625. _print_next_block(par_num++, "UCM");
  3626. break;
  3627. case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR:
  3628. if (print)
  3629. _print_next_block(par_num++, "USEMI");
  3630. break;
  3631. case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR:
  3632. if (print)
  3633. _print_next_block(par_num++, "UPB");
  3634. break;
  3635. case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR:
  3636. if (print)
  3637. _print_next_block(par_num++, "CSDM");
  3638. break;
  3639. case AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR:
  3640. if (print)
  3641. _print_next_block(par_num++, "CCM");
  3642. break;
  3643. }
  3644. /* Clear the bit */
  3645. sig &= ~cur_bit;
  3646. }
  3647. }
  3648. return par_num;
  3649. }
  3650. static int bnx2x_check_blocks_with_parity2(u32 sig, int par_num,
  3651. bool print)
  3652. {
  3653. int i = 0;
  3654. u32 cur_bit = 0;
  3655. for (i = 0; sig; i++) {
  3656. cur_bit = ((u32)0x1 << i);
  3657. if (sig & cur_bit) {
  3658. switch (cur_bit) {
  3659. case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR:
  3660. if (print)
  3661. _print_next_block(par_num++, "CSEMI");
  3662. break;
  3663. case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR:
  3664. if (print)
  3665. _print_next_block(par_num++, "PXP");
  3666. break;
  3667. case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR:
  3668. if (print)
  3669. _print_next_block(par_num++,
  3670. "PXPPCICLOCKCLIENT");
  3671. break;
  3672. case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR:
  3673. if (print)
  3674. _print_next_block(par_num++, "CFC");
  3675. break;
  3676. case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR:
  3677. if (print)
  3678. _print_next_block(par_num++, "CDU");
  3679. break;
  3680. case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR:
  3681. if (print)
  3682. _print_next_block(par_num++, "DMAE");
  3683. break;
  3684. case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR:
  3685. if (print)
  3686. _print_next_block(par_num++, "IGU");
  3687. break;
  3688. case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR:
  3689. if (print)
  3690. _print_next_block(par_num++, "MISC");
  3691. break;
  3692. }
  3693. /* Clear the bit */
  3694. sig &= ~cur_bit;
  3695. }
  3696. }
  3697. return par_num;
  3698. }
  3699. static int bnx2x_check_blocks_with_parity3(u32 sig, int par_num,
  3700. bool *global, bool print)
  3701. {
  3702. int i = 0;
  3703. u32 cur_bit = 0;
  3704. for (i = 0; sig; i++) {
  3705. cur_bit = ((u32)0x1 << i);
  3706. if (sig & cur_bit) {
  3707. switch (cur_bit) {
  3708. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY:
  3709. if (print)
  3710. _print_next_block(par_num++, "MCP ROM");
  3711. *global = true;
  3712. break;
  3713. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY:
  3714. if (print)
  3715. _print_next_block(par_num++,
  3716. "MCP UMP RX");
  3717. *global = true;
  3718. break;
  3719. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY:
  3720. if (print)
  3721. _print_next_block(par_num++,
  3722. "MCP UMP TX");
  3723. *global = true;
  3724. break;
  3725. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY:
  3726. if (print)
  3727. _print_next_block(par_num++,
  3728. "MCP SCPAD");
  3729. *global = true;
  3730. break;
  3731. }
  3732. /* Clear the bit */
  3733. sig &= ~cur_bit;
  3734. }
  3735. }
  3736. return par_num;
  3737. }
  3738. static int bnx2x_check_blocks_with_parity4(u32 sig, int par_num,
  3739. bool print)
  3740. {
  3741. int i = 0;
  3742. u32 cur_bit = 0;
  3743. for (i = 0; sig; i++) {
  3744. cur_bit = ((u32)0x1 << i);
  3745. if (sig & cur_bit) {
  3746. switch (cur_bit) {
  3747. case AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR:
  3748. if (print)
  3749. _print_next_block(par_num++, "PGLUE_B");
  3750. break;
  3751. case AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR:
  3752. if (print)
  3753. _print_next_block(par_num++, "ATC");
  3754. break;
  3755. }
  3756. /* Clear the bit */
  3757. sig &= ~cur_bit;
  3758. }
  3759. }
  3760. return par_num;
  3761. }
  3762. static bool bnx2x_parity_attn(struct bnx2x *bp, bool *global, bool print,
  3763. u32 *sig)
  3764. {
  3765. if ((sig[0] & HW_PRTY_ASSERT_SET_0) ||
  3766. (sig[1] & HW_PRTY_ASSERT_SET_1) ||
  3767. (sig[2] & HW_PRTY_ASSERT_SET_2) ||
  3768. (sig[3] & HW_PRTY_ASSERT_SET_3) ||
  3769. (sig[4] & HW_PRTY_ASSERT_SET_4)) {
  3770. int par_num = 0;
  3771. DP(NETIF_MSG_HW, "Was parity error: HW block parity attention:\n"
  3772. "[0]:0x%08x [1]:0x%08x [2]:0x%08x [3]:0x%08x [4]:0x%08x\n",
  3773. sig[0] & HW_PRTY_ASSERT_SET_0,
  3774. sig[1] & HW_PRTY_ASSERT_SET_1,
  3775. sig[2] & HW_PRTY_ASSERT_SET_2,
  3776. sig[3] & HW_PRTY_ASSERT_SET_3,
  3777. sig[4] & HW_PRTY_ASSERT_SET_4);
  3778. if (print)
  3779. netdev_err(bp->dev,
  3780. "Parity errors detected in blocks: ");
  3781. par_num = bnx2x_check_blocks_with_parity0(
  3782. sig[0] & HW_PRTY_ASSERT_SET_0, par_num, print);
  3783. par_num = bnx2x_check_blocks_with_parity1(
  3784. sig[1] & HW_PRTY_ASSERT_SET_1, par_num, global, print);
  3785. par_num = bnx2x_check_blocks_with_parity2(
  3786. sig[2] & HW_PRTY_ASSERT_SET_2, par_num, print);
  3787. par_num = bnx2x_check_blocks_with_parity3(
  3788. sig[3] & HW_PRTY_ASSERT_SET_3, par_num, global, print);
  3789. par_num = bnx2x_check_blocks_with_parity4(
  3790. sig[4] & HW_PRTY_ASSERT_SET_4, par_num, print);
  3791. if (print)
  3792. pr_cont("\n");
  3793. return true;
  3794. } else
  3795. return false;
  3796. }
  3797. /**
  3798. * bnx2x_chk_parity_attn - checks for parity attentions.
  3799. *
  3800. * @bp: driver handle
  3801. * @global: true if there was a global attention
  3802. * @print: show parity attention in syslog
  3803. */
  3804. bool bnx2x_chk_parity_attn(struct bnx2x *bp, bool *global, bool print)
  3805. {
  3806. struct attn_route attn = { {0} };
  3807. int port = BP_PORT(bp);
  3808. attn.sig[0] = REG_RD(bp,
  3809. MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 +
  3810. port*4);
  3811. attn.sig[1] = REG_RD(bp,
  3812. MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 +
  3813. port*4);
  3814. attn.sig[2] = REG_RD(bp,
  3815. MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 +
  3816. port*4);
  3817. attn.sig[3] = REG_RD(bp,
  3818. MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 +
  3819. port*4);
  3820. if (!CHIP_IS_E1x(bp))
  3821. attn.sig[4] = REG_RD(bp,
  3822. MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 +
  3823. port*4);
  3824. return bnx2x_parity_attn(bp, global, print, attn.sig);
  3825. }
  3826. static void bnx2x_attn_int_deasserted4(struct bnx2x *bp, u32 attn)
  3827. {
  3828. u32 val;
  3829. if (attn & AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT) {
  3830. val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS_CLR);
  3831. BNX2X_ERR("PGLUE hw attention 0x%x\n", val);
  3832. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR)
  3833. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR\n");
  3834. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR)
  3835. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR\n");
  3836. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN)
  3837. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN\n");
  3838. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN)
  3839. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN\n");
  3840. if (val &
  3841. PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN)
  3842. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN\n");
  3843. if (val &
  3844. PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN)
  3845. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN\n");
  3846. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN)
  3847. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN\n");
  3848. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN)
  3849. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN\n");
  3850. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW)
  3851. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW\n");
  3852. }
  3853. if (attn & AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT) {
  3854. val = REG_RD(bp, ATC_REG_ATC_INT_STS_CLR);
  3855. BNX2X_ERR("ATC hw attention 0x%x\n", val);
  3856. if (val & ATC_ATC_INT_STS_REG_ADDRESS_ERROR)
  3857. BNX2X_ERR("ATC_ATC_INT_STS_REG_ADDRESS_ERROR\n");
  3858. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND)
  3859. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND\n");
  3860. if (val & ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS)
  3861. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS\n");
  3862. if (val & ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT)
  3863. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT\n");
  3864. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR)
  3865. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR\n");
  3866. if (val & ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU)
  3867. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU\n");
  3868. }
  3869. if (attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  3870. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)) {
  3871. BNX2X_ERR("FATAL parity attention set4 0x%x\n",
  3872. (u32)(attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  3873. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)));
  3874. }
  3875. }
  3876. static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted)
  3877. {
  3878. struct attn_route attn, *group_mask;
  3879. int port = BP_PORT(bp);
  3880. int index;
  3881. u32 reg_addr;
  3882. u32 val;
  3883. u32 aeu_mask;
  3884. bool global = false;
  3885. /* need to take HW lock because MCP or other port might also
  3886. try to handle this event */
  3887. bnx2x_acquire_alr(bp);
  3888. if (bnx2x_chk_parity_attn(bp, &global, true)) {
  3889. #ifndef BNX2X_STOP_ON_ERROR
  3890. bp->recovery_state = BNX2X_RECOVERY_INIT;
  3891. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  3892. /* Disable HW interrupts */
  3893. bnx2x_int_disable(bp);
  3894. /* In case of parity errors don't handle attentions so that
  3895. * other function would "see" parity errors.
  3896. */
  3897. #else
  3898. bnx2x_panic();
  3899. #endif
  3900. bnx2x_release_alr(bp);
  3901. return;
  3902. }
  3903. attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
  3904. attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
  3905. attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
  3906. attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
  3907. if (!CHIP_IS_E1x(bp))
  3908. attn.sig[4] =
  3909. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4);
  3910. else
  3911. attn.sig[4] = 0;
  3912. DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x %08x\n",
  3913. attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3], attn.sig[4]);
  3914. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  3915. if (deasserted & (1 << index)) {
  3916. group_mask = &bp->attn_group[index];
  3917. DP(NETIF_MSG_HW, "group[%d]: %08x %08x %08x %08x %08x\n",
  3918. index,
  3919. group_mask->sig[0], group_mask->sig[1],
  3920. group_mask->sig[2], group_mask->sig[3],
  3921. group_mask->sig[4]);
  3922. bnx2x_attn_int_deasserted4(bp,
  3923. attn.sig[4] & group_mask->sig[4]);
  3924. bnx2x_attn_int_deasserted3(bp,
  3925. attn.sig[3] & group_mask->sig[3]);
  3926. bnx2x_attn_int_deasserted1(bp,
  3927. attn.sig[1] & group_mask->sig[1]);
  3928. bnx2x_attn_int_deasserted2(bp,
  3929. attn.sig[2] & group_mask->sig[2]);
  3930. bnx2x_attn_int_deasserted0(bp,
  3931. attn.sig[0] & group_mask->sig[0]);
  3932. }
  3933. }
  3934. bnx2x_release_alr(bp);
  3935. if (bp->common.int_block == INT_BLOCK_HC)
  3936. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  3937. COMMAND_REG_ATTN_BITS_CLR);
  3938. else
  3939. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_CLR_UPPER*8);
  3940. val = ~deasserted;
  3941. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", val,
  3942. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  3943. REG_WR(bp, reg_addr, val);
  3944. if (~bp->attn_state & deasserted)
  3945. BNX2X_ERR("IGU ERROR\n");
  3946. reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  3947. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  3948. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3949. aeu_mask = REG_RD(bp, reg_addr);
  3950. DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n",
  3951. aeu_mask, deasserted);
  3952. aeu_mask |= (deasserted & 0x3ff);
  3953. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  3954. REG_WR(bp, reg_addr, aeu_mask);
  3955. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3956. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  3957. bp->attn_state &= ~deasserted;
  3958. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  3959. }
  3960. static void bnx2x_attn_int(struct bnx2x *bp)
  3961. {
  3962. /* read local copy of bits */
  3963. u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block.
  3964. attn_bits);
  3965. u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block.
  3966. attn_bits_ack);
  3967. u32 attn_state = bp->attn_state;
  3968. /* look for changed bits */
  3969. u32 asserted = attn_bits & ~attn_ack & ~attn_state;
  3970. u32 deasserted = ~attn_bits & attn_ack & attn_state;
  3971. DP(NETIF_MSG_HW,
  3972. "attn_bits %x attn_ack %x asserted %x deasserted %x\n",
  3973. attn_bits, attn_ack, asserted, deasserted);
  3974. if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state))
  3975. BNX2X_ERR("BAD attention state\n");
  3976. /* handle bits that were raised */
  3977. if (asserted)
  3978. bnx2x_attn_int_asserted(bp, asserted);
  3979. if (deasserted)
  3980. bnx2x_attn_int_deasserted(bp, deasserted);
  3981. }
  3982. void bnx2x_igu_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 segment,
  3983. u16 index, u8 op, u8 update)
  3984. {
  3985. u32 igu_addr = bp->igu_base_addr;
  3986. igu_addr += (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8;
  3987. bnx2x_igu_ack_sb_gen(bp, igu_sb_id, segment, index, op, update,
  3988. igu_addr);
  3989. }
  3990. static void bnx2x_update_eq_prod(struct bnx2x *bp, u16 prod)
  3991. {
  3992. /* No memory barriers */
  3993. storm_memset_eq_prod(bp, prod, BP_FUNC(bp));
  3994. mmiowb(); /* keep prod updates ordered */
  3995. }
  3996. static int bnx2x_cnic_handle_cfc_del(struct bnx2x *bp, u32 cid,
  3997. union event_ring_elem *elem)
  3998. {
  3999. u8 err = elem->message.error;
  4000. if (!bp->cnic_eth_dev.starting_cid ||
  4001. (cid < bp->cnic_eth_dev.starting_cid &&
  4002. cid != bp->cnic_eth_dev.iscsi_l2_cid))
  4003. return 1;
  4004. DP(BNX2X_MSG_SP, "got delete ramrod for CNIC CID %d\n", cid);
  4005. if (unlikely(err)) {
  4006. BNX2X_ERR("got delete ramrod for CNIC CID %d with error!\n",
  4007. cid);
  4008. bnx2x_panic_dump(bp);
  4009. }
  4010. bnx2x_cnic_cfc_comp(bp, cid, err);
  4011. return 0;
  4012. }
  4013. static void bnx2x_handle_mcast_eqe(struct bnx2x *bp)
  4014. {
  4015. struct bnx2x_mcast_ramrod_params rparam;
  4016. int rc;
  4017. memset(&rparam, 0, sizeof(rparam));
  4018. rparam.mcast_obj = &bp->mcast_obj;
  4019. netif_addr_lock_bh(bp->dev);
  4020. /* Clear pending state for the last command */
  4021. bp->mcast_obj.raw.clear_pending(&bp->mcast_obj.raw);
  4022. /* If there are pending mcast commands - send them */
  4023. if (bp->mcast_obj.check_pending(&bp->mcast_obj)) {
  4024. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT);
  4025. if (rc < 0)
  4026. BNX2X_ERR("Failed to send pending mcast commands: %d\n",
  4027. rc);
  4028. }
  4029. netif_addr_unlock_bh(bp->dev);
  4030. }
  4031. static void bnx2x_handle_classification_eqe(struct bnx2x *bp,
  4032. union event_ring_elem *elem)
  4033. {
  4034. unsigned long ramrod_flags = 0;
  4035. int rc = 0;
  4036. u32 cid = elem->message.data.eth_event.echo & BNX2X_SWCID_MASK;
  4037. struct bnx2x_vlan_mac_obj *vlan_mac_obj;
  4038. /* Always push next commands out, don't wait here */
  4039. __set_bit(RAMROD_CONT, &ramrod_flags);
  4040. switch (elem->message.data.eth_event.echo >> BNX2X_SWCID_SHIFT) {
  4041. case BNX2X_FILTER_MAC_PENDING:
  4042. DP(BNX2X_MSG_SP, "Got SETUP_MAC completions\n");
  4043. if (CNIC_LOADED(bp) && (cid == BNX2X_ISCSI_ETH_CID(bp)))
  4044. vlan_mac_obj = &bp->iscsi_l2_mac_obj;
  4045. else
  4046. vlan_mac_obj = &bp->sp_objs[cid].mac_obj;
  4047. break;
  4048. case BNX2X_FILTER_MCAST_PENDING:
  4049. DP(BNX2X_MSG_SP, "Got SETUP_MCAST completions\n");
  4050. /* This is only relevant for 57710 where multicast MACs are
  4051. * configured as unicast MACs using the same ramrod.
  4052. */
  4053. bnx2x_handle_mcast_eqe(bp);
  4054. return;
  4055. default:
  4056. BNX2X_ERR("Unsupported classification command: %d\n",
  4057. elem->message.data.eth_event.echo);
  4058. return;
  4059. }
  4060. rc = vlan_mac_obj->complete(bp, vlan_mac_obj, elem, &ramrod_flags);
  4061. if (rc < 0)
  4062. BNX2X_ERR("Failed to schedule new commands: %d\n", rc);
  4063. else if (rc > 0)
  4064. DP(BNX2X_MSG_SP, "Scheduled next pending commands...\n");
  4065. }
  4066. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start);
  4067. static void bnx2x_handle_rx_mode_eqe(struct bnx2x *bp)
  4068. {
  4069. netif_addr_lock_bh(bp->dev);
  4070. clear_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  4071. /* Send rx_mode command again if was requested */
  4072. if (test_and_clear_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state))
  4073. bnx2x_set_storm_rx_mode(bp);
  4074. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED,
  4075. &bp->sp_state))
  4076. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  4077. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED,
  4078. &bp->sp_state))
  4079. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  4080. netif_addr_unlock_bh(bp->dev);
  4081. }
  4082. static void bnx2x_after_afex_vif_lists(struct bnx2x *bp,
  4083. union event_ring_elem *elem)
  4084. {
  4085. if (elem->message.data.vif_list_event.echo == VIF_LIST_RULE_GET) {
  4086. DP(BNX2X_MSG_SP,
  4087. "afex: ramrod completed VIF LIST_GET, addrs 0x%x\n",
  4088. elem->message.data.vif_list_event.func_bit_map);
  4089. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTGET_ACK,
  4090. elem->message.data.vif_list_event.func_bit_map);
  4091. } else if (elem->message.data.vif_list_event.echo ==
  4092. VIF_LIST_RULE_SET) {
  4093. DP(BNX2X_MSG_SP, "afex: ramrod completed VIF LIST_SET\n");
  4094. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTSET_ACK, 0);
  4095. }
  4096. }
  4097. /* called with rtnl_lock */
  4098. static void bnx2x_after_function_update(struct bnx2x *bp)
  4099. {
  4100. int q, rc;
  4101. struct bnx2x_fastpath *fp;
  4102. struct bnx2x_queue_state_params queue_params = {NULL};
  4103. struct bnx2x_queue_update_params *q_update_params =
  4104. &queue_params.params.update;
  4105. /* Send Q update command with afex vlan removal values for all Qs */
  4106. queue_params.cmd = BNX2X_Q_CMD_UPDATE;
  4107. /* set silent vlan removal values according to vlan mode */
  4108. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM_CHNG,
  4109. &q_update_params->update_flags);
  4110. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM,
  4111. &q_update_params->update_flags);
  4112. __set_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
  4113. /* in access mode mark mask and value are 0 to strip all vlans */
  4114. if (bp->afex_vlan_mode == FUNC_MF_CFG_AFEX_VLAN_ACCESS_MODE) {
  4115. q_update_params->silent_removal_value = 0;
  4116. q_update_params->silent_removal_mask = 0;
  4117. } else {
  4118. q_update_params->silent_removal_value =
  4119. (bp->afex_def_vlan_tag & VLAN_VID_MASK);
  4120. q_update_params->silent_removal_mask = VLAN_VID_MASK;
  4121. }
  4122. for_each_eth_queue(bp, q) {
  4123. /* Set the appropriate Queue object */
  4124. fp = &bp->fp[q];
  4125. queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  4126. /* send the ramrod */
  4127. rc = bnx2x_queue_state_change(bp, &queue_params);
  4128. if (rc < 0)
  4129. BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
  4130. q);
  4131. }
  4132. if (!NO_FCOE(bp)) {
  4133. fp = &bp->fp[FCOE_IDX(bp)];
  4134. queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  4135. /* clear pending completion bit */
  4136. __clear_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
  4137. /* mark latest Q bit */
  4138. smp_mb__before_clear_bit();
  4139. set_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
  4140. smp_mb__after_clear_bit();
  4141. /* send Q update ramrod for FCoE Q */
  4142. rc = bnx2x_queue_state_change(bp, &queue_params);
  4143. if (rc < 0)
  4144. BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
  4145. q);
  4146. } else {
  4147. /* If no FCoE ring - ACK MCP now */
  4148. bnx2x_link_report(bp);
  4149. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  4150. }
  4151. }
  4152. static struct bnx2x_queue_sp_obj *bnx2x_cid_to_q_obj(
  4153. struct bnx2x *bp, u32 cid)
  4154. {
  4155. DP(BNX2X_MSG_SP, "retrieving fp from cid %d\n", cid);
  4156. if (CNIC_LOADED(bp) && (cid == BNX2X_FCOE_ETH_CID(bp)))
  4157. return &bnx2x_fcoe_sp_obj(bp, q_obj);
  4158. else
  4159. return &bp->sp_objs[CID_TO_FP(cid, bp)].q_obj;
  4160. }
  4161. static void bnx2x_eq_int(struct bnx2x *bp)
  4162. {
  4163. u16 hw_cons, sw_cons, sw_prod;
  4164. union event_ring_elem *elem;
  4165. u8 echo;
  4166. u32 cid;
  4167. u8 opcode;
  4168. int rc, spqe_cnt = 0;
  4169. struct bnx2x_queue_sp_obj *q_obj;
  4170. struct bnx2x_func_sp_obj *f_obj = &bp->func_obj;
  4171. struct bnx2x_raw_obj *rss_raw = &bp->rss_conf_obj.raw;
  4172. hw_cons = le16_to_cpu(*bp->eq_cons_sb);
  4173. /* The hw_cos range is 1-255, 257 - the sw_cons range is 0-254, 256.
  4174. * when we get the the next-page we nned to adjust so the loop
  4175. * condition below will be met. The next element is the size of a
  4176. * regular element and hence incrementing by 1
  4177. */
  4178. if ((hw_cons & EQ_DESC_MAX_PAGE) == EQ_DESC_MAX_PAGE)
  4179. hw_cons++;
  4180. /* This function may never run in parallel with itself for a
  4181. * specific bp, thus there is no need in "paired" read memory
  4182. * barrier here.
  4183. */
  4184. sw_cons = bp->eq_cons;
  4185. sw_prod = bp->eq_prod;
  4186. DP(BNX2X_MSG_SP, "EQ: hw_cons %u sw_cons %u bp->eq_spq_left %x\n",
  4187. hw_cons, sw_cons, atomic_read(&bp->eq_spq_left));
  4188. for (; sw_cons != hw_cons;
  4189. sw_prod = NEXT_EQ_IDX(sw_prod), sw_cons = NEXT_EQ_IDX(sw_cons)) {
  4190. elem = &bp->eq_ring[EQ_DESC(sw_cons)];
  4191. rc = bnx2x_iov_eq_sp_event(bp, elem);
  4192. if (!rc) {
  4193. DP(BNX2X_MSG_IOV, "bnx2x_iov_eq_sp_event returned %d\n",
  4194. rc);
  4195. goto next_spqe;
  4196. }
  4197. cid = SW_CID(elem->message.data.cfc_del_event.cid);
  4198. opcode = elem->message.opcode;
  4199. /* handle eq element */
  4200. switch (opcode) {
  4201. case EVENT_RING_OPCODE_VF_PF_CHANNEL:
  4202. DP(BNX2X_MSG_IOV, "vf pf channel element on eq\n");
  4203. bnx2x_vf_mbx(bp, &elem->message.data.vf_pf_event);
  4204. continue;
  4205. case EVENT_RING_OPCODE_STAT_QUERY:
  4206. DP(BNX2X_MSG_SP | BNX2X_MSG_STATS,
  4207. "got statistics comp event %d\n",
  4208. bp->stats_comp++);
  4209. /* nothing to do with stats comp */
  4210. goto next_spqe;
  4211. case EVENT_RING_OPCODE_CFC_DEL:
  4212. /* handle according to cid range */
  4213. /*
  4214. * we may want to verify here that the bp state is
  4215. * HALTING
  4216. */
  4217. DP(BNX2X_MSG_SP,
  4218. "got delete ramrod for MULTI[%d]\n", cid);
  4219. if (CNIC_LOADED(bp) &&
  4220. !bnx2x_cnic_handle_cfc_del(bp, cid, elem))
  4221. goto next_spqe;
  4222. q_obj = bnx2x_cid_to_q_obj(bp, cid);
  4223. if (q_obj->complete_cmd(bp, q_obj, BNX2X_Q_CMD_CFC_DEL))
  4224. break;
  4225. goto next_spqe;
  4226. case EVENT_RING_OPCODE_STOP_TRAFFIC:
  4227. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got STOP TRAFFIC\n");
  4228. if (f_obj->complete_cmd(bp, f_obj,
  4229. BNX2X_F_CMD_TX_STOP))
  4230. break;
  4231. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_PAUSED);
  4232. goto next_spqe;
  4233. case EVENT_RING_OPCODE_START_TRAFFIC:
  4234. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got START TRAFFIC\n");
  4235. if (f_obj->complete_cmd(bp, f_obj,
  4236. BNX2X_F_CMD_TX_START))
  4237. break;
  4238. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_RELEASED);
  4239. goto next_spqe;
  4240. case EVENT_RING_OPCODE_FUNCTION_UPDATE:
  4241. echo = elem->message.data.function_update_event.echo;
  4242. if (echo == SWITCH_UPDATE) {
  4243. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4244. "got FUNC_SWITCH_UPDATE ramrod\n");
  4245. if (f_obj->complete_cmd(
  4246. bp, f_obj, BNX2X_F_CMD_SWITCH_UPDATE))
  4247. break;
  4248. } else {
  4249. DP(BNX2X_MSG_SP | BNX2X_MSG_MCP,
  4250. "AFEX: ramrod completed FUNCTION_UPDATE\n");
  4251. f_obj->complete_cmd(bp, f_obj,
  4252. BNX2X_F_CMD_AFEX_UPDATE);
  4253. /* We will perform the Queues update from
  4254. * sp_rtnl task as all Queue SP operations
  4255. * should run under rtnl_lock.
  4256. */
  4257. smp_mb__before_clear_bit();
  4258. set_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE,
  4259. &bp->sp_rtnl_state);
  4260. smp_mb__after_clear_bit();
  4261. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  4262. }
  4263. goto next_spqe;
  4264. case EVENT_RING_OPCODE_AFEX_VIF_LISTS:
  4265. f_obj->complete_cmd(bp, f_obj,
  4266. BNX2X_F_CMD_AFEX_VIFLISTS);
  4267. bnx2x_after_afex_vif_lists(bp, elem);
  4268. goto next_spqe;
  4269. case EVENT_RING_OPCODE_FUNCTION_START:
  4270. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4271. "got FUNC_START ramrod\n");
  4272. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_START))
  4273. break;
  4274. goto next_spqe;
  4275. case EVENT_RING_OPCODE_FUNCTION_STOP:
  4276. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4277. "got FUNC_STOP ramrod\n");
  4278. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_STOP))
  4279. break;
  4280. goto next_spqe;
  4281. }
  4282. switch (opcode | bp->state) {
  4283. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4284. BNX2X_STATE_OPEN):
  4285. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4286. BNX2X_STATE_OPENING_WAIT4_PORT):
  4287. cid = elem->message.data.eth_event.echo &
  4288. BNX2X_SWCID_MASK;
  4289. DP(BNX2X_MSG_SP, "got RSS_UPDATE ramrod. CID %d\n",
  4290. cid);
  4291. rss_raw->clear_pending(rss_raw);
  4292. break;
  4293. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_OPEN):
  4294. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_DIAG):
  4295. case (EVENT_RING_OPCODE_SET_MAC |
  4296. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4297. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4298. BNX2X_STATE_OPEN):
  4299. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4300. BNX2X_STATE_DIAG):
  4301. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4302. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4303. DP(BNX2X_MSG_SP, "got (un)set mac ramrod\n");
  4304. bnx2x_handle_classification_eqe(bp, elem);
  4305. break;
  4306. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4307. BNX2X_STATE_OPEN):
  4308. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4309. BNX2X_STATE_DIAG):
  4310. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4311. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4312. DP(BNX2X_MSG_SP, "got mcast ramrod\n");
  4313. bnx2x_handle_mcast_eqe(bp);
  4314. break;
  4315. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4316. BNX2X_STATE_OPEN):
  4317. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4318. BNX2X_STATE_DIAG):
  4319. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4320. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4321. DP(BNX2X_MSG_SP, "got rx_mode ramrod\n");
  4322. bnx2x_handle_rx_mode_eqe(bp);
  4323. break;
  4324. default:
  4325. /* unknown event log error and continue */
  4326. BNX2X_ERR("Unknown EQ event %d, bp->state 0x%x\n",
  4327. elem->message.opcode, bp->state);
  4328. }
  4329. next_spqe:
  4330. spqe_cnt++;
  4331. } /* for */
  4332. smp_mb__before_atomic_inc();
  4333. atomic_add(spqe_cnt, &bp->eq_spq_left);
  4334. bp->eq_cons = sw_cons;
  4335. bp->eq_prod = sw_prod;
  4336. /* Make sure that above mem writes were issued towards the memory */
  4337. smp_wmb();
  4338. /* update producer */
  4339. bnx2x_update_eq_prod(bp, bp->eq_prod);
  4340. }
  4341. static void bnx2x_sp_task(struct work_struct *work)
  4342. {
  4343. struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work);
  4344. DP(BNX2X_MSG_SP, "sp task invoked\n");
  4345. /* make sure the atomic interupt_occurred has been written */
  4346. smp_rmb();
  4347. if (atomic_read(&bp->interrupt_occurred)) {
  4348. /* what work needs to be performed? */
  4349. u16 status = bnx2x_update_dsb_idx(bp);
  4350. DP(BNX2X_MSG_SP, "status %x\n", status);
  4351. DP(BNX2X_MSG_SP, "setting interrupt_occurred to 0\n");
  4352. atomic_set(&bp->interrupt_occurred, 0);
  4353. /* HW attentions */
  4354. if (status & BNX2X_DEF_SB_ATT_IDX) {
  4355. bnx2x_attn_int(bp);
  4356. status &= ~BNX2X_DEF_SB_ATT_IDX;
  4357. }
  4358. /* SP events: STAT_QUERY and others */
  4359. if (status & BNX2X_DEF_SB_IDX) {
  4360. struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
  4361. if (FCOE_INIT(bp) &&
  4362. (bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp))) {
  4363. /* Prevent local bottom-halves from running as
  4364. * we are going to change the local NAPI list.
  4365. */
  4366. local_bh_disable();
  4367. napi_schedule(&bnx2x_fcoe(bp, napi));
  4368. local_bh_enable();
  4369. }
  4370. /* Handle EQ completions */
  4371. bnx2x_eq_int(bp);
  4372. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID,
  4373. le16_to_cpu(bp->def_idx), IGU_INT_NOP, 1);
  4374. status &= ~BNX2X_DEF_SB_IDX;
  4375. }
  4376. /* if status is non zero then perhaps something went wrong */
  4377. if (unlikely(status))
  4378. DP(BNX2X_MSG_SP,
  4379. "got an unknown interrupt! (status 0x%x)\n", status);
  4380. /* ack status block only if something was actually handled */
  4381. bnx2x_ack_sb(bp, bp->igu_dsb_id, ATTENTION_ID,
  4382. le16_to_cpu(bp->def_att_idx), IGU_INT_ENABLE, 1);
  4383. }
  4384. /* must be called after the EQ processing (since eq leads to sriov
  4385. * ramrod completion flows).
  4386. * This flow may have been scheduled by the arrival of a ramrod
  4387. * completion, or by the sriov code rescheduling itself.
  4388. */
  4389. bnx2x_iov_sp_task(bp);
  4390. /* afex - poll to check if VIFSET_ACK should be sent to MFW */
  4391. if (test_and_clear_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK,
  4392. &bp->sp_state)) {
  4393. bnx2x_link_report(bp);
  4394. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  4395. }
  4396. }
  4397. irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance)
  4398. {
  4399. struct net_device *dev = dev_instance;
  4400. struct bnx2x *bp = netdev_priv(dev);
  4401. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0,
  4402. IGU_INT_DISABLE, 0);
  4403. #ifdef BNX2X_STOP_ON_ERROR
  4404. if (unlikely(bp->panic))
  4405. return IRQ_HANDLED;
  4406. #endif
  4407. if (CNIC_LOADED(bp)) {
  4408. struct cnic_ops *c_ops;
  4409. rcu_read_lock();
  4410. c_ops = rcu_dereference(bp->cnic_ops);
  4411. if (c_ops)
  4412. c_ops->cnic_handler(bp->cnic_data, NULL);
  4413. rcu_read_unlock();
  4414. }
  4415. /* schedule sp task to perform default status block work, ack
  4416. * attentions and enable interrupts.
  4417. */
  4418. bnx2x_schedule_sp_task(bp);
  4419. return IRQ_HANDLED;
  4420. }
  4421. /* end of slow path */
  4422. void bnx2x_drv_pulse(struct bnx2x *bp)
  4423. {
  4424. SHMEM_WR(bp, func_mb[BP_FW_MB_IDX(bp)].drv_pulse_mb,
  4425. bp->fw_drv_pulse_wr_seq);
  4426. }
  4427. static void bnx2x_timer(unsigned long data)
  4428. {
  4429. struct bnx2x *bp = (struct bnx2x *) data;
  4430. if (!netif_running(bp->dev))
  4431. return;
  4432. if (IS_PF(bp) &&
  4433. !BP_NOMCP(bp)) {
  4434. int mb_idx = BP_FW_MB_IDX(bp);
  4435. u32 drv_pulse;
  4436. u32 mcp_pulse;
  4437. ++bp->fw_drv_pulse_wr_seq;
  4438. bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK;
  4439. /* TBD - add SYSTEM_TIME */
  4440. drv_pulse = bp->fw_drv_pulse_wr_seq;
  4441. bnx2x_drv_pulse(bp);
  4442. mcp_pulse = (SHMEM_RD(bp, func_mb[mb_idx].mcp_pulse_mb) &
  4443. MCP_PULSE_SEQ_MASK);
  4444. /* The delta between driver pulse and mcp response
  4445. * should be 1 (before mcp response) or 0 (after mcp response)
  4446. */
  4447. if ((drv_pulse != mcp_pulse) &&
  4448. (drv_pulse != ((mcp_pulse + 1) & MCP_PULSE_SEQ_MASK))) {
  4449. /* someone lost a heartbeat... */
  4450. BNX2X_ERR("drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
  4451. drv_pulse, mcp_pulse);
  4452. }
  4453. }
  4454. if (bp->state == BNX2X_STATE_OPEN)
  4455. bnx2x_stats_handle(bp, STATS_EVENT_UPDATE);
  4456. /* sample pf vf bulletin board for new posts from pf */
  4457. if (IS_VF(bp))
  4458. bnx2x_sample_bulletin(bp);
  4459. mod_timer(&bp->timer, jiffies + bp->current_interval);
  4460. }
  4461. /* end of Statistics */
  4462. /* nic init */
  4463. /*
  4464. * nic init service functions
  4465. */
  4466. static void bnx2x_fill(struct bnx2x *bp, u32 addr, int fill, u32 len)
  4467. {
  4468. u32 i;
  4469. if (!(len%4) && !(addr%4))
  4470. for (i = 0; i < len; i += 4)
  4471. REG_WR(bp, addr + i, fill);
  4472. else
  4473. for (i = 0; i < len; i++)
  4474. REG_WR8(bp, addr + i, fill);
  4475. }
  4476. /* helper: writes FP SP data to FW - data_size in dwords */
  4477. static void bnx2x_wr_fp_sb_data(struct bnx2x *bp,
  4478. int fw_sb_id,
  4479. u32 *sb_data_p,
  4480. u32 data_size)
  4481. {
  4482. int index;
  4483. for (index = 0; index < data_size; index++)
  4484. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4485. CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id) +
  4486. sizeof(u32)*index,
  4487. *(sb_data_p + index));
  4488. }
  4489. static void bnx2x_zero_fp_sb(struct bnx2x *bp, int fw_sb_id)
  4490. {
  4491. u32 *sb_data_p;
  4492. u32 data_size = 0;
  4493. struct hc_status_block_data_e2 sb_data_e2;
  4494. struct hc_status_block_data_e1x sb_data_e1x;
  4495. /* disable the function first */
  4496. if (!CHIP_IS_E1x(bp)) {
  4497. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  4498. sb_data_e2.common.state = SB_DISABLED;
  4499. sb_data_e2.common.p_func.vf_valid = false;
  4500. sb_data_p = (u32 *)&sb_data_e2;
  4501. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  4502. } else {
  4503. memset(&sb_data_e1x, 0,
  4504. sizeof(struct hc_status_block_data_e1x));
  4505. sb_data_e1x.common.state = SB_DISABLED;
  4506. sb_data_e1x.common.p_func.vf_valid = false;
  4507. sb_data_p = (u32 *)&sb_data_e1x;
  4508. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  4509. }
  4510. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  4511. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4512. CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id), 0,
  4513. CSTORM_STATUS_BLOCK_SIZE);
  4514. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4515. CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id), 0,
  4516. CSTORM_SYNC_BLOCK_SIZE);
  4517. }
  4518. /* helper: writes SP SB data to FW */
  4519. static void bnx2x_wr_sp_sb_data(struct bnx2x *bp,
  4520. struct hc_sp_status_block_data *sp_sb_data)
  4521. {
  4522. int func = BP_FUNC(bp);
  4523. int i;
  4524. for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
  4525. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4526. CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
  4527. i*sizeof(u32),
  4528. *((u32 *)sp_sb_data + i));
  4529. }
  4530. static void bnx2x_zero_sp_sb(struct bnx2x *bp)
  4531. {
  4532. int func = BP_FUNC(bp);
  4533. struct hc_sp_status_block_data sp_sb_data;
  4534. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  4535. sp_sb_data.state = SB_DISABLED;
  4536. sp_sb_data.p_func.vf_valid = false;
  4537. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  4538. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4539. CSTORM_SP_STATUS_BLOCK_OFFSET(func), 0,
  4540. CSTORM_SP_STATUS_BLOCK_SIZE);
  4541. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4542. CSTORM_SP_SYNC_BLOCK_OFFSET(func), 0,
  4543. CSTORM_SP_SYNC_BLOCK_SIZE);
  4544. }
  4545. static void bnx2x_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm,
  4546. int igu_sb_id, int igu_seg_id)
  4547. {
  4548. hc_sm->igu_sb_id = igu_sb_id;
  4549. hc_sm->igu_seg_id = igu_seg_id;
  4550. hc_sm->timer_value = 0xFF;
  4551. hc_sm->time_to_expire = 0xFFFFFFFF;
  4552. }
  4553. /* allocates state machine ids. */
  4554. static void bnx2x_map_sb_state_machines(struct hc_index_data *index_data)
  4555. {
  4556. /* zero out state machine indices */
  4557. /* rx indices */
  4558. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4559. /* tx indices */
  4560. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4561. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags &= ~HC_INDEX_DATA_SM_ID;
  4562. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags &= ~HC_INDEX_DATA_SM_ID;
  4563. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags &= ~HC_INDEX_DATA_SM_ID;
  4564. /* map indices */
  4565. /* rx indices */
  4566. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags |=
  4567. SM_RX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4568. /* tx indices */
  4569. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags |=
  4570. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4571. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags |=
  4572. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4573. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags |=
  4574. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4575. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags |=
  4576. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4577. }
  4578. void bnx2x_init_sb(struct bnx2x *bp, dma_addr_t mapping, int vfid,
  4579. u8 vf_valid, int fw_sb_id, int igu_sb_id)
  4580. {
  4581. int igu_seg_id;
  4582. struct hc_status_block_data_e2 sb_data_e2;
  4583. struct hc_status_block_data_e1x sb_data_e1x;
  4584. struct hc_status_block_sm *hc_sm_p;
  4585. int data_size;
  4586. u32 *sb_data_p;
  4587. if (CHIP_INT_MODE_IS_BC(bp))
  4588. igu_seg_id = HC_SEG_ACCESS_NORM;
  4589. else
  4590. igu_seg_id = IGU_SEG_ACCESS_NORM;
  4591. bnx2x_zero_fp_sb(bp, fw_sb_id);
  4592. if (!CHIP_IS_E1x(bp)) {
  4593. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  4594. sb_data_e2.common.state = SB_ENABLED;
  4595. sb_data_e2.common.p_func.pf_id = BP_FUNC(bp);
  4596. sb_data_e2.common.p_func.vf_id = vfid;
  4597. sb_data_e2.common.p_func.vf_valid = vf_valid;
  4598. sb_data_e2.common.p_func.vnic_id = BP_VN(bp);
  4599. sb_data_e2.common.same_igu_sb_1b = true;
  4600. sb_data_e2.common.host_sb_addr.hi = U64_HI(mapping);
  4601. sb_data_e2.common.host_sb_addr.lo = U64_LO(mapping);
  4602. hc_sm_p = sb_data_e2.common.state_machine;
  4603. sb_data_p = (u32 *)&sb_data_e2;
  4604. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  4605. bnx2x_map_sb_state_machines(sb_data_e2.index_data);
  4606. } else {
  4607. memset(&sb_data_e1x, 0,
  4608. sizeof(struct hc_status_block_data_e1x));
  4609. sb_data_e1x.common.state = SB_ENABLED;
  4610. sb_data_e1x.common.p_func.pf_id = BP_FUNC(bp);
  4611. sb_data_e1x.common.p_func.vf_id = 0xff;
  4612. sb_data_e1x.common.p_func.vf_valid = false;
  4613. sb_data_e1x.common.p_func.vnic_id = BP_VN(bp);
  4614. sb_data_e1x.common.same_igu_sb_1b = true;
  4615. sb_data_e1x.common.host_sb_addr.hi = U64_HI(mapping);
  4616. sb_data_e1x.common.host_sb_addr.lo = U64_LO(mapping);
  4617. hc_sm_p = sb_data_e1x.common.state_machine;
  4618. sb_data_p = (u32 *)&sb_data_e1x;
  4619. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  4620. bnx2x_map_sb_state_machines(sb_data_e1x.index_data);
  4621. }
  4622. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_RX_ID],
  4623. igu_sb_id, igu_seg_id);
  4624. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_TX_ID],
  4625. igu_sb_id, igu_seg_id);
  4626. DP(NETIF_MSG_IFUP, "Init FW SB %d\n", fw_sb_id);
  4627. /* write indecies to HW */
  4628. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  4629. }
  4630. static void bnx2x_update_coalesce_sb(struct bnx2x *bp, u8 fw_sb_id,
  4631. u16 tx_usec, u16 rx_usec)
  4632. {
  4633. bnx2x_update_coalesce_sb_index(bp, fw_sb_id, HC_INDEX_ETH_RX_CQ_CONS,
  4634. false, rx_usec);
  4635. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4636. HC_INDEX_ETH_TX_CQ_CONS_COS0, false,
  4637. tx_usec);
  4638. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4639. HC_INDEX_ETH_TX_CQ_CONS_COS1, false,
  4640. tx_usec);
  4641. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4642. HC_INDEX_ETH_TX_CQ_CONS_COS2, false,
  4643. tx_usec);
  4644. }
  4645. static void bnx2x_init_def_sb(struct bnx2x *bp)
  4646. {
  4647. struct host_sp_status_block *def_sb = bp->def_status_blk;
  4648. dma_addr_t mapping = bp->def_status_blk_mapping;
  4649. int igu_sp_sb_index;
  4650. int igu_seg_id;
  4651. int port = BP_PORT(bp);
  4652. int func = BP_FUNC(bp);
  4653. int reg_offset, reg_offset_en5;
  4654. u64 section;
  4655. int index;
  4656. struct hc_sp_status_block_data sp_sb_data;
  4657. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  4658. if (CHIP_INT_MODE_IS_BC(bp)) {
  4659. igu_sp_sb_index = DEF_SB_IGU_ID;
  4660. igu_seg_id = HC_SEG_ACCESS_DEF;
  4661. } else {
  4662. igu_sp_sb_index = bp->igu_dsb_id;
  4663. igu_seg_id = IGU_SEG_ACCESS_DEF;
  4664. }
  4665. /* ATTN */
  4666. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  4667. atten_status_block);
  4668. def_sb->atten_status_block.status_block_id = igu_sp_sb_index;
  4669. bp->attn_state = 0;
  4670. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  4671. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  4672. reg_offset_en5 = (port ? MISC_REG_AEU_ENABLE5_FUNC_1_OUT_0 :
  4673. MISC_REG_AEU_ENABLE5_FUNC_0_OUT_0);
  4674. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  4675. int sindex;
  4676. /* take care of sig[0]..sig[4] */
  4677. for (sindex = 0; sindex < 4; sindex++)
  4678. bp->attn_group[index].sig[sindex] =
  4679. REG_RD(bp, reg_offset + sindex*0x4 + 0x10*index);
  4680. if (!CHIP_IS_E1x(bp))
  4681. /*
  4682. * enable5 is separate from the rest of the registers,
  4683. * and therefore the address skip is 4
  4684. * and not 16 between the different groups
  4685. */
  4686. bp->attn_group[index].sig[4] = REG_RD(bp,
  4687. reg_offset_en5 + 0x4*index);
  4688. else
  4689. bp->attn_group[index].sig[4] = 0;
  4690. }
  4691. if (bp->common.int_block == INT_BLOCK_HC) {
  4692. reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L :
  4693. HC_REG_ATTN_MSG0_ADDR_L);
  4694. REG_WR(bp, reg_offset, U64_LO(section));
  4695. REG_WR(bp, reg_offset + 4, U64_HI(section));
  4696. } else if (!CHIP_IS_E1x(bp)) {
  4697. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_L, U64_LO(section));
  4698. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_H, U64_HI(section));
  4699. }
  4700. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  4701. sp_sb);
  4702. bnx2x_zero_sp_sb(bp);
  4703. sp_sb_data.state = SB_ENABLED;
  4704. sp_sb_data.host_sb_addr.lo = U64_LO(section);
  4705. sp_sb_data.host_sb_addr.hi = U64_HI(section);
  4706. sp_sb_data.igu_sb_id = igu_sp_sb_index;
  4707. sp_sb_data.igu_seg_id = igu_seg_id;
  4708. sp_sb_data.p_func.pf_id = func;
  4709. sp_sb_data.p_func.vnic_id = BP_VN(bp);
  4710. sp_sb_data.p_func.vf_id = 0xff;
  4711. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  4712. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0);
  4713. }
  4714. void bnx2x_update_coalesce(struct bnx2x *bp)
  4715. {
  4716. int i;
  4717. for_each_eth_queue(bp, i)
  4718. bnx2x_update_coalesce_sb(bp, bp->fp[i].fw_sb_id,
  4719. bp->tx_ticks, bp->rx_ticks);
  4720. }
  4721. static void bnx2x_init_sp_ring(struct bnx2x *bp)
  4722. {
  4723. spin_lock_init(&bp->spq_lock);
  4724. atomic_set(&bp->cq_spq_left, MAX_SPQ_PENDING);
  4725. bp->spq_prod_idx = 0;
  4726. bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX;
  4727. bp->spq_prod_bd = bp->spq;
  4728. bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT;
  4729. }
  4730. static void bnx2x_init_eq_ring(struct bnx2x *bp)
  4731. {
  4732. int i;
  4733. for (i = 1; i <= NUM_EQ_PAGES; i++) {
  4734. union event_ring_elem *elem =
  4735. &bp->eq_ring[EQ_DESC_CNT_PAGE * i - 1];
  4736. elem->next_page.addr.hi =
  4737. cpu_to_le32(U64_HI(bp->eq_mapping +
  4738. BCM_PAGE_SIZE * (i % NUM_EQ_PAGES)));
  4739. elem->next_page.addr.lo =
  4740. cpu_to_le32(U64_LO(bp->eq_mapping +
  4741. BCM_PAGE_SIZE*(i % NUM_EQ_PAGES)));
  4742. }
  4743. bp->eq_cons = 0;
  4744. bp->eq_prod = NUM_EQ_DESC;
  4745. bp->eq_cons_sb = BNX2X_EQ_INDEX;
  4746. /* we want a warning message before it gets rought... */
  4747. atomic_set(&bp->eq_spq_left,
  4748. min_t(int, MAX_SP_DESC_CNT - MAX_SPQ_PENDING, NUM_EQ_DESC) - 1);
  4749. }
  4750. /* called with netif_addr_lock_bh() */
  4751. void bnx2x_set_q_rx_mode(struct bnx2x *bp, u8 cl_id,
  4752. unsigned long rx_mode_flags,
  4753. unsigned long rx_accept_flags,
  4754. unsigned long tx_accept_flags,
  4755. unsigned long ramrod_flags)
  4756. {
  4757. struct bnx2x_rx_mode_ramrod_params ramrod_param;
  4758. int rc;
  4759. memset(&ramrod_param, 0, sizeof(ramrod_param));
  4760. /* Prepare ramrod parameters */
  4761. ramrod_param.cid = 0;
  4762. ramrod_param.cl_id = cl_id;
  4763. ramrod_param.rx_mode_obj = &bp->rx_mode_obj;
  4764. ramrod_param.func_id = BP_FUNC(bp);
  4765. ramrod_param.pstate = &bp->sp_state;
  4766. ramrod_param.state = BNX2X_FILTER_RX_MODE_PENDING;
  4767. ramrod_param.rdata = bnx2x_sp(bp, rx_mode_rdata);
  4768. ramrod_param.rdata_mapping = bnx2x_sp_mapping(bp, rx_mode_rdata);
  4769. set_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  4770. ramrod_param.ramrod_flags = ramrod_flags;
  4771. ramrod_param.rx_mode_flags = rx_mode_flags;
  4772. ramrod_param.rx_accept_flags = rx_accept_flags;
  4773. ramrod_param.tx_accept_flags = tx_accept_flags;
  4774. rc = bnx2x_config_rx_mode(bp, &ramrod_param);
  4775. if (rc < 0) {
  4776. BNX2X_ERR("Set rx_mode %d failed\n", bp->rx_mode);
  4777. return;
  4778. }
  4779. }
  4780. /* called with netif_addr_lock_bh() */
  4781. void bnx2x_set_storm_rx_mode(struct bnx2x *bp)
  4782. {
  4783. unsigned long rx_mode_flags = 0, ramrod_flags = 0;
  4784. unsigned long rx_accept_flags = 0, tx_accept_flags = 0;
  4785. if (!NO_FCOE(bp))
  4786. /* Configure rx_mode of FCoE Queue */
  4787. __set_bit(BNX2X_RX_MODE_FCOE_ETH, &rx_mode_flags);
  4788. switch (bp->rx_mode) {
  4789. case BNX2X_RX_MODE_NONE:
  4790. /*
  4791. * 'drop all' supersedes any accept flags that may have been
  4792. * passed to the function.
  4793. */
  4794. break;
  4795. case BNX2X_RX_MODE_NORMAL:
  4796. __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
  4797. __set_bit(BNX2X_ACCEPT_MULTICAST, &rx_accept_flags);
  4798. __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
  4799. /* internal switching mode */
  4800. __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
  4801. __set_bit(BNX2X_ACCEPT_MULTICAST, &tx_accept_flags);
  4802. __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
  4803. break;
  4804. case BNX2X_RX_MODE_ALLMULTI:
  4805. __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
  4806. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &rx_accept_flags);
  4807. __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
  4808. /* internal switching mode */
  4809. __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
  4810. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &tx_accept_flags);
  4811. __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
  4812. break;
  4813. case BNX2X_RX_MODE_PROMISC:
  4814. /* According to deffinition of SI mode, iface in promisc mode
  4815. * should receive matched and unmatched (in resolution of port)
  4816. * unicast packets.
  4817. */
  4818. __set_bit(BNX2X_ACCEPT_UNMATCHED, &rx_accept_flags);
  4819. __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
  4820. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &rx_accept_flags);
  4821. __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
  4822. /* internal switching mode */
  4823. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &tx_accept_flags);
  4824. __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
  4825. if (IS_MF_SI(bp))
  4826. __set_bit(BNX2X_ACCEPT_ALL_UNICAST, &tx_accept_flags);
  4827. else
  4828. __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
  4829. break;
  4830. default:
  4831. BNX2X_ERR("Unknown rx_mode: %d\n", bp->rx_mode);
  4832. return;
  4833. }
  4834. if (bp->rx_mode != BNX2X_RX_MODE_NONE) {
  4835. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &rx_accept_flags);
  4836. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &tx_accept_flags);
  4837. }
  4838. __set_bit(RAMROD_RX, &ramrod_flags);
  4839. __set_bit(RAMROD_TX, &ramrod_flags);
  4840. bnx2x_set_q_rx_mode(bp, bp->fp->cl_id, rx_mode_flags, rx_accept_flags,
  4841. tx_accept_flags, ramrod_flags);
  4842. }
  4843. static void bnx2x_init_internal_common(struct bnx2x *bp)
  4844. {
  4845. int i;
  4846. if (IS_MF_SI(bp))
  4847. /*
  4848. * In switch independent mode, the TSTORM needs to accept
  4849. * packets that failed classification, since approximate match
  4850. * mac addresses aren't written to NIG LLH
  4851. */
  4852. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  4853. TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 2);
  4854. else if (!CHIP_IS_E1(bp)) /* 57710 doesn't support MF */
  4855. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  4856. TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 0);
  4857. /* Zero this manually as its initialization is
  4858. currently missing in the initTool */
  4859. for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++)
  4860. REG_WR(bp, BAR_USTRORM_INTMEM +
  4861. USTORM_AGG_DATA_OFFSET + i * 4, 0);
  4862. if (!CHIP_IS_E1x(bp)) {
  4863. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_IGU_MODE_OFFSET,
  4864. CHIP_INT_MODE_IS_BC(bp) ?
  4865. HC_IGU_BC_MODE : HC_IGU_NBC_MODE);
  4866. }
  4867. }
  4868. static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code)
  4869. {
  4870. switch (load_code) {
  4871. case FW_MSG_CODE_DRV_LOAD_COMMON:
  4872. case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
  4873. bnx2x_init_internal_common(bp);
  4874. /* no break */
  4875. case FW_MSG_CODE_DRV_LOAD_PORT:
  4876. /* nothing to do */
  4877. /* no break */
  4878. case FW_MSG_CODE_DRV_LOAD_FUNCTION:
  4879. /* internal memory per function is
  4880. initialized inside bnx2x_pf_init */
  4881. break;
  4882. default:
  4883. BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
  4884. break;
  4885. }
  4886. }
  4887. static inline u8 bnx2x_fp_igu_sb_id(struct bnx2x_fastpath *fp)
  4888. {
  4889. return fp->bp->igu_base_sb + fp->index + CNIC_SUPPORT(fp->bp);
  4890. }
  4891. static inline u8 bnx2x_fp_fw_sb_id(struct bnx2x_fastpath *fp)
  4892. {
  4893. return fp->bp->base_fw_ndsb + fp->index + CNIC_SUPPORT(fp->bp);
  4894. }
  4895. static u8 bnx2x_fp_cl_id(struct bnx2x_fastpath *fp)
  4896. {
  4897. if (CHIP_IS_E1x(fp->bp))
  4898. return BP_L_ID(fp->bp) + fp->index;
  4899. else /* We want Client ID to be the same as IGU SB ID for 57712 */
  4900. return bnx2x_fp_igu_sb_id(fp);
  4901. }
  4902. static void bnx2x_init_eth_fp(struct bnx2x *bp, int fp_idx)
  4903. {
  4904. struct bnx2x_fastpath *fp = &bp->fp[fp_idx];
  4905. u8 cos;
  4906. unsigned long q_type = 0;
  4907. u32 cids[BNX2X_MULTI_TX_COS] = { 0 };
  4908. fp->rx_queue = fp_idx;
  4909. fp->cid = fp_idx;
  4910. fp->cl_id = bnx2x_fp_cl_id(fp);
  4911. fp->fw_sb_id = bnx2x_fp_fw_sb_id(fp);
  4912. fp->igu_sb_id = bnx2x_fp_igu_sb_id(fp);
  4913. /* qZone id equals to FW (per path) client id */
  4914. fp->cl_qzone_id = bnx2x_fp_qzone_id(fp);
  4915. /* init shortcut */
  4916. fp->ustorm_rx_prods_offset = bnx2x_rx_ustorm_prods_offset(fp);
  4917. /* Setup SB indicies */
  4918. fp->rx_cons_sb = BNX2X_RX_SB_INDEX;
  4919. /* Configure Queue State object */
  4920. __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
  4921. __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
  4922. BUG_ON(fp->max_cos > BNX2X_MULTI_TX_COS);
  4923. /* init tx data */
  4924. for_each_cos_in_tx_queue(fp, cos) {
  4925. bnx2x_init_txdata(bp, fp->txdata_ptr[cos],
  4926. CID_COS_TO_TX_ONLY_CID(fp->cid, cos, bp),
  4927. FP_COS_TO_TXQ(fp, cos, bp),
  4928. BNX2X_TX_SB_INDEX_BASE + cos, fp);
  4929. cids[cos] = fp->txdata_ptr[cos]->cid;
  4930. }
  4931. /* nothing more for vf to do here */
  4932. if (IS_VF(bp))
  4933. return;
  4934. bnx2x_init_sb(bp, fp->status_blk_mapping, BNX2X_VF_ID_INVALID, false,
  4935. fp->fw_sb_id, fp->igu_sb_id);
  4936. bnx2x_update_fpsb_idx(fp);
  4937. bnx2x_init_queue_obj(bp, &bnx2x_sp_obj(bp, fp).q_obj, fp->cl_id, cids,
  4938. fp->max_cos, BP_FUNC(bp), bnx2x_sp(bp, q_rdata),
  4939. bnx2x_sp_mapping(bp, q_rdata), q_type);
  4940. /**
  4941. * Configure classification DBs: Always enable Tx switching
  4942. */
  4943. bnx2x_init_vlan_mac_fp_objs(fp, BNX2X_OBJ_TYPE_RX_TX);
  4944. DP(NETIF_MSG_IFUP,
  4945. "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d fw_sb %d igu_sb %d\n",
  4946. fp_idx, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
  4947. fp->igu_sb_id);
  4948. }
  4949. static void bnx2x_init_tx_ring_one(struct bnx2x_fp_txdata *txdata)
  4950. {
  4951. int i;
  4952. for (i = 1; i <= NUM_TX_RINGS; i++) {
  4953. struct eth_tx_next_bd *tx_next_bd =
  4954. &txdata->tx_desc_ring[TX_DESC_CNT * i - 1].next_bd;
  4955. tx_next_bd->addr_hi =
  4956. cpu_to_le32(U64_HI(txdata->tx_desc_mapping +
  4957. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  4958. tx_next_bd->addr_lo =
  4959. cpu_to_le32(U64_LO(txdata->tx_desc_mapping +
  4960. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  4961. }
  4962. SET_FLAG(txdata->tx_db.data.header.header, DOORBELL_HDR_DB_TYPE, 1);
  4963. txdata->tx_db.data.zero_fill1 = 0;
  4964. txdata->tx_db.data.prod = 0;
  4965. txdata->tx_pkt_prod = 0;
  4966. txdata->tx_pkt_cons = 0;
  4967. txdata->tx_bd_prod = 0;
  4968. txdata->tx_bd_cons = 0;
  4969. txdata->tx_pkt = 0;
  4970. }
  4971. static void bnx2x_init_tx_rings_cnic(struct bnx2x *bp)
  4972. {
  4973. int i;
  4974. for_each_tx_queue_cnic(bp, i)
  4975. bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[0]);
  4976. }
  4977. static void bnx2x_init_tx_rings(struct bnx2x *bp)
  4978. {
  4979. int i;
  4980. u8 cos;
  4981. for_each_eth_queue(bp, i)
  4982. for_each_cos_in_tx_queue(&bp->fp[i], cos)
  4983. bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[cos]);
  4984. }
  4985. void bnx2x_nic_init_cnic(struct bnx2x *bp)
  4986. {
  4987. if (!NO_FCOE(bp))
  4988. bnx2x_init_fcoe_fp(bp);
  4989. bnx2x_init_sb(bp, bp->cnic_sb_mapping,
  4990. BNX2X_VF_ID_INVALID, false,
  4991. bnx2x_cnic_fw_sb_id(bp), bnx2x_cnic_igu_sb_id(bp));
  4992. /* ensure status block indices were read */
  4993. rmb();
  4994. bnx2x_init_rx_rings_cnic(bp);
  4995. bnx2x_init_tx_rings_cnic(bp);
  4996. /* flush all */
  4997. mb();
  4998. mmiowb();
  4999. }
  5000. void bnx2x_nic_init(struct bnx2x *bp, u32 load_code)
  5001. {
  5002. int i;
  5003. for_each_eth_queue(bp, i)
  5004. bnx2x_init_eth_fp(bp, i);
  5005. /* ensure status block indices were read */
  5006. rmb();
  5007. bnx2x_init_rx_rings(bp);
  5008. bnx2x_init_tx_rings(bp);
  5009. if (IS_VF(bp))
  5010. return;
  5011. /* Initialize MOD_ABS interrupts */
  5012. bnx2x_init_mod_abs_int(bp, &bp->link_vars, bp->common.chip_id,
  5013. bp->common.shmem_base, bp->common.shmem2_base,
  5014. BP_PORT(bp));
  5015. bnx2x_init_def_sb(bp);
  5016. bnx2x_update_dsb_idx(bp);
  5017. bnx2x_init_sp_ring(bp);
  5018. bnx2x_init_eq_ring(bp);
  5019. bnx2x_init_internal(bp, load_code);
  5020. bnx2x_pf_init(bp);
  5021. bnx2x_stats_init(bp);
  5022. /* flush all before enabling interrupts */
  5023. mb();
  5024. mmiowb();
  5025. bnx2x_int_enable(bp);
  5026. /* Check for SPIO5 */
  5027. bnx2x_attn_int_deasserted0(bp,
  5028. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + BP_PORT(bp)*4) &
  5029. AEU_INPUTS_ATTN_BITS_SPIO5);
  5030. }
  5031. /* end of nic init */
  5032. /*
  5033. * gzip service functions
  5034. */
  5035. static int bnx2x_gunzip_init(struct bnx2x *bp)
  5036. {
  5037. bp->gunzip_buf = dma_alloc_coherent(&bp->pdev->dev, FW_BUF_SIZE,
  5038. &bp->gunzip_mapping, GFP_KERNEL);
  5039. if (bp->gunzip_buf == NULL)
  5040. goto gunzip_nomem1;
  5041. bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL);
  5042. if (bp->strm == NULL)
  5043. goto gunzip_nomem2;
  5044. bp->strm->workspace = vmalloc(zlib_inflate_workspacesize());
  5045. if (bp->strm->workspace == NULL)
  5046. goto gunzip_nomem3;
  5047. return 0;
  5048. gunzip_nomem3:
  5049. kfree(bp->strm);
  5050. bp->strm = NULL;
  5051. gunzip_nomem2:
  5052. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  5053. bp->gunzip_mapping);
  5054. bp->gunzip_buf = NULL;
  5055. gunzip_nomem1:
  5056. BNX2X_ERR("Cannot allocate firmware buffer for un-compression\n");
  5057. return -ENOMEM;
  5058. }
  5059. static void bnx2x_gunzip_end(struct bnx2x *bp)
  5060. {
  5061. if (bp->strm) {
  5062. vfree(bp->strm->workspace);
  5063. kfree(bp->strm);
  5064. bp->strm = NULL;
  5065. }
  5066. if (bp->gunzip_buf) {
  5067. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  5068. bp->gunzip_mapping);
  5069. bp->gunzip_buf = NULL;
  5070. }
  5071. }
  5072. static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len)
  5073. {
  5074. int n, rc;
  5075. /* check gzip header */
  5076. if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED)) {
  5077. BNX2X_ERR("Bad gzip header\n");
  5078. return -EINVAL;
  5079. }
  5080. n = 10;
  5081. #define FNAME 0x8
  5082. if (zbuf[3] & FNAME)
  5083. while ((zbuf[n++] != 0) && (n < len));
  5084. bp->strm->next_in = (typeof(bp->strm->next_in))zbuf + n;
  5085. bp->strm->avail_in = len - n;
  5086. bp->strm->next_out = bp->gunzip_buf;
  5087. bp->strm->avail_out = FW_BUF_SIZE;
  5088. rc = zlib_inflateInit2(bp->strm, -MAX_WBITS);
  5089. if (rc != Z_OK)
  5090. return rc;
  5091. rc = zlib_inflate(bp->strm, Z_FINISH);
  5092. if ((rc != Z_OK) && (rc != Z_STREAM_END))
  5093. netdev_err(bp->dev, "Firmware decompression error: %s\n",
  5094. bp->strm->msg);
  5095. bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out);
  5096. if (bp->gunzip_outlen & 0x3)
  5097. netdev_err(bp->dev,
  5098. "Firmware decompression error: gunzip_outlen (%d) not aligned\n",
  5099. bp->gunzip_outlen);
  5100. bp->gunzip_outlen >>= 2;
  5101. zlib_inflateEnd(bp->strm);
  5102. if (rc == Z_STREAM_END)
  5103. return 0;
  5104. return rc;
  5105. }
  5106. /* nic load/unload */
  5107. /*
  5108. * General service functions
  5109. */
  5110. /* send a NIG loopback debug packet */
  5111. static void bnx2x_lb_pckt(struct bnx2x *bp)
  5112. {
  5113. u32 wb_write[3];
  5114. /* Ethernet source and destination addresses */
  5115. wb_write[0] = 0x55555555;
  5116. wb_write[1] = 0x55555555;
  5117. wb_write[2] = 0x20; /* SOP */
  5118. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  5119. /* NON-IP protocol */
  5120. wb_write[0] = 0x09000000;
  5121. wb_write[1] = 0x55555555;
  5122. wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */
  5123. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  5124. }
  5125. /* some of the internal memories
  5126. * are not directly readable from the driver
  5127. * to test them we send debug packets
  5128. */
  5129. static int bnx2x_int_mem_test(struct bnx2x *bp)
  5130. {
  5131. int factor;
  5132. int count, i;
  5133. u32 val = 0;
  5134. if (CHIP_REV_IS_FPGA(bp))
  5135. factor = 120;
  5136. else if (CHIP_REV_IS_EMUL(bp))
  5137. factor = 200;
  5138. else
  5139. factor = 1;
  5140. /* Disable inputs of parser neighbor blocks */
  5141. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  5142. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  5143. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  5144. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  5145. /* Write 0 to parser credits for CFC search request */
  5146. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  5147. /* send Ethernet packet */
  5148. bnx2x_lb_pckt(bp);
  5149. /* TODO do i reset NIG statistic? */
  5150. /* Wait until NIG register shows 1 packet of size 0x10 */
  5151. count = 1000 * factor;
  5152. while (count) {
  5153. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5154. val = *bnx2x_sp(bp, wb_data[0]);
  5155. if (val == 0x10)
  5156. break;
  5157. msleep(10);
  5158. count--;
  5159. }
  5160. if (val != 0x10) {
  5161. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  5162. return -1;
  5163. }
  5164. /* Wait until PRS register shows 1 packet */
  5165. count = 1000 * factor;
  5166. while (count) {
  5167. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5168. if (val == 1)
  5169. break;
  5170. msleep(10);
  5171. count--;
  5172. }
  5173. if (val != 0x1) {
  5174. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5175. return -2;
  5176. }
  5177. /* Reset and init BRB, PRS */
  5178. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  5179. msleep(50);
  5180. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  5181. msleep(50);
  5182. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5183. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5184. DP(NETIF_MSG_HW, "part2\n");
  5185. /* Disable inputs of parser neighbor blocks */
  5186. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  5187. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  5188. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  5189. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  5190. /* Write 0 to parser credits for CFC search request */
  5191. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  5192. /* send 10 Ethernet packets */
  5193. for (i = 0; i < 10; i++)
  5194. bnx2x_lb_pckt(bp);
  5195. /* Wait until NIG register shows 10 + 1
  5196. packets of size 11*0x10 = 0xb0 */
  5197. count = 1000 * factor;
  5198. while (count) {
  5199. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5200. val = *bnx2x_sp(bp, wb_data[0]);
  5201. if (val == 0xb0)
  5202. break;
  5203. msleep(10);
  5204. count--;
  5205. }
  5206. if (val != 0xb0) {
  5207. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  5208. return -3;
  5209. }
  5210. /* Wait until PRS register shows 2 packets */
  5211. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5212. if (val != 2)
  5213. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5214. /* Write 1 to parser credits for CFC search request */
  5215. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1);
  5216. /* Wait until PRS register shows 3 packets */
  5217. msleep(10 * factor);
  5218. /* Wait until NIG register shows 1 packet of size 0x10 */
  5219. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5220. if (val != 3)
  5221. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5222. /* clear NIG EOP FIFO */
  5223. for (i = 0; i < 11; i++)
  5224. REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO);
  5225. val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY);
  5226. if (val != 1) {
  5227. BNX2X_ERR("clear of NIG failed\n");
  5228. return -4;
  5229. }
  5230. /* Reset and init BRB, PRS, NIG */
  5231. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  5232. msleep(50);
  5233. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  5234. msleep(50);
  5235. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5236. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5237. if (!CNIC_SUPPORT(bp))
  5238. /* set NIC mode */
  5239. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  5240. /* Enable inputs of parser neighbor blocks */
  5241. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff);
  5242. REG_WR(bp, TCM_REG_PRS_IFEN, 0x1);
  5243. REG_WR(bp, CFC_REG_DEBUG0, 0x0);
  5244. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1);
  5245. DP(NETIF_MSG_HW, "done\n");
  5246. return 0; /* OK */
  5247. }
  5248. static void bnx2x_enable_blocks_attention(struct bnx2x *bp)
  5249. {
  5250. u32 val;
  5251. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5252. if (!CHIP_IS_E1x(bp))
  5253. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0x40);
  5254. else
  5255. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0);
  5256. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  5257. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  5258. /*
  5259. * mask read length error interrupts in brb for parser
  5260. * (parsing unit and 'checksum and crc' unit)
  5261. * these errors are legal (PU reads fixed length and CAC can cause
  5262. * read length error on truncated packets)
  5263. */
  5264. REG_WR(bp, BRB1_REG_BRB1_INT_MASK, 0xFC00);
  5265. REG_WR(bp, QM_REG_QM_INT_MASK, 0);
  5266. REG_WR(bp, TM_REG_TM_INT_MASK, 0);
  5267. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0);
  5268. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0);
  5269. REG_WR(bp, XCM_REG_XCM_INT_MASK, 0);
  5270. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */
  5271. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */
  5272. REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0);
  5273. REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0);
  5274. REG_WR(bp, UCM_REG_UCM_INT_MASK, 0);
  5275. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */
  5276. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */
  5277. REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0);
  5278. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0);
  5279. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0);
  5280. REG_WR(bp, CCM_REG_CCM_INT_MASK, 0);
  5281. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */
  5282. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */
  5283. val = PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT |
  5284. PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF |
  5285. PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN;
  5286. if (!CHIP_IS_E1x(bp))
  5287. val |= PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED |
  5288. PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED;
  5289. REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, val);
  5290. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0);
  5291. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0);
  5292. REG_WR(bp, TCM_REG_TCM_INT_MASK, 0);
  5293. /* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */
  5294. if (!CHIP_IS_E1x(bp))
  5295. /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */
  5296. REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0x07ff);
  5297. REG_WR(bp, CDU_REG_CDU_INT_MASK, 0);
  5298. REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0);
  5299. /* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */
  5300. REG_WR(bp, PBF_REG_PBF_INT_MASK, 0x18); /* bit 3,4 masked */
  5301. }
  5302. static void bnx2x_reset_common(struct bnx2x *bp)
  5303. {
  5304. u32 val = 0x1400;
  5305. /* reset_common */
  5306. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  5307. 0xd3ffff7f);
  5308. if (CHIP_IS_E3(bp)) {
  5309. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  5310. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  5311. }
  5312. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, val);
  5313. }
  5314. static void bnx2x_setup_dmae(struct bnx2x *bp)
  5315. {
  5316. bp->dmae_ready = 0;
  5317. spin_lock_init(&bp->dmae_lock);
  5318. }
  5319. static void bnx2x_init_pxp(struct bnx2x *bp)
  5320. {
  5321. u16 devctl;
  5322. int r_order, w_order;
  5323. pcie_capability_read_word(bp->pdev, PCI_EXP_DEVCTL, &devctl);
  5324. DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl);
  5325. w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
  5326. if (bp->mrrs == -1)
  5327. r_order = ((devctl & PCI_EXP_DEVCTL_READRQ) >> 12);
  5328. else {
  5329. DP(NETIF_MSG_HW, "force read order to %d\n", bp->mrrs);
  5330. r_order = bp->mrrs;
  5331. }
  5332. bnx2x_init_pxp_arb(bp, r_order, w_order);
  5333. }
  5334. static void bnx2x_setup_fan_failure_detection(struct bnx2x *bp)
  5335. {
  5336. int is_required;
  5337. u32 val;
  5338. int port;
  5339. if (BP_NOMCP(bp))
  5340. return;
  5341. is_required = 0;
  5342. val = SHMEM_RD(bp, dev_info.shared_hw_config.config2) &
  5343. SHARED_HW_CFG_FAN_FAILURE_MASK;
  5344. if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED)
  5345. is_required = 1;
  5346. /*
  5347. * The fan failure mechanism is usually related to the PHY type since
  5348. * the power consumption of the board is affected by the PHY. Currently,
  5349. * fan is required for most designs with SFX7101, BCM8727 and BCM8481.
  5350. */
  5351. else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE)
  5352. for (port = PORT_0; port < PORT_MAX; port++) {
  5353. is_required |=
  5354. bnx2x_fan_failure_det_req(
  5355. bp,
  5356. bp->common.shmem_base,
  5357. bp->common.shmem2_base,
  5358. port);
  5359. }
  5360. DP(NETIF_MSG_HW, "fan detection setting: %d\n", is_required);
  5361. if (is_required == 0)
  5362. return;
  5363. /* Fan failure is indicated by SPIO 5 */
  5364. bnx2x_set_spio(bp, MISC_SPIO_SPIO5, MISC_SPIO_INPUT_HI_Z);
  5365. /* set to active low mode */
  5366. val = REG_RD(bp, MISC_REG_SPIO_INT);
  5367. val |= (MISC_SPIO_SPIO5 << MISC_SPIO_INT_OLD_SET_POS);
  5368. REG_WR(bp, MISC_REG_SPIO_INT, val);
  5369. /* enable interrupt to signal the IGU */
  5370. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  5371. val |= MISC_SPIO_SPIO5;
  5372. REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val);
  5373. }
  5374. void bnx2x_pf_disable(struct bnx2x *bp)
  5375. {
  5376. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  5377. val &= ~IGU_PF_CONF_FUNC_EN;
  5378. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  5379. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  5380. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 0);
  5381. }
  5382. static void bnx2x__common_init_phy(struct bnx2x *bp)
  5383. {
  5384. u32 shmem_base[2], shmem2_base[2];
  5385. /* Avoid common init in case MFW supports LFA */
  5386. if (SHMEM2_RD(bp, size) >
  5387. (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
  5388. return;
  5389. shmem_base[0] = bp->common.shmem_base;
  5390. shmem2_base[0] = bp->common.shmem2_base;
  5391. if (!CHIP_IS_E1x(bp)) {
  5392. shmem_base[1] =
  5393. SHMEM2_RD(bp, other_shmem_base_addr);
  5394. shmem2_base[1] =
  5395. SHMEM2_RD(bp, other_shmem2_base_addr);
  5396. }
  5397. bnx2x_acquire_phy_lock(bp);
  5398. bnx2x_common_init_phy(bp, shmem_base, shmem2_base,
  5399. bp->common.chip_id);
  5400. bnx2x_release_phy_lock(bp);
  5401. }
  5402. /**
  5403. * bnx2x_init_hw_common - initialize the HW at the COMMON phase.
  5404. *
  5405. * @bp: driver handle
  5406. */
  5407. static int bnx2x_init_hw_common(struct bnx2x *bp)
  5408. {
  5409. u32 val;
  5410. DP(NETIF_MSG_HW, "starting common init func %d\n", BP_ABS_FUNC(bp));
  5411. /*
  5412. * take the UNDI lock to protect undi_unload flow from accessing
  5413. * registers while we're resetting the chip
  5414. */
  5415. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5416. bnx2x_reset_common(bp);
  5417. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff);
  5418. val = 0xfffc;
  5419. if (CHIP_IS_E3(bp)) {
  5420. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  5421. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  5422. }
  5423. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, val);
  5424. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5425. bnx2x_init_block(bp, BLOCK_MISC, PHASE_COMMON);
  5426. if (!CHIP_IS_E1x(bp)) {
  5427. u8 abs_func_id;
  5428. /**
  5429. * 4-port mode or 2-port mode we need to turn of master-enable
  5430. * for everyone, after that, turn it back on for self.
  5431. * so, we disregard multi-function or not, and always disable
  5432. * for all functions on the given path, this means 0,2,4,6 for
  5433. * path 0 and 1,3,5,7 for path 1
  5434. */
  5435. for (abs_func_id = BP_PATH(bp);
  5436. abs_func_id < E2_FUNC_MAX*2; abs_func_id += 2) {
  5437. if (abs_func_id == BP_ABS_FUNC(bp)) {
  5438. REG_WR(bp,
  5439. PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER,
  5440. 1);
  5441. continue;
  5442. }
  5443. bnx2x_pretend_func(bp, abs_func_id);
  5444. /* clear pf enable */
  5445. bnx2x_pf_disable(bp);
  5446. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  5447. }
  5448. }
  5449. bnx2x_init_block(bp, BLOCK_PXP, PHASE_COMMON);
  5450. if (CHIP_IS_E1(bp)) {
  5451. /* enable HW interrupt from PXP on USDM overflow
  5452. bit 16 on INT_MASK_0 */
  5453. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5454. }
  5455. bnx2x_init_block(bp, BLOCK_PXP2, PHASE_COMMON);
  5456. bnx2x_init_pxp(bp);
  5457. #ifdef __BIG_ENDIAN
  5458. REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, 1);
  5459. REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, 1);
  5460. REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, 1);
  5461. REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, 1);
  5462. REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, 1);
  5463. /* make sure this value is 0 */
  5464. REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0);
  5465. /* REG_WR(bp, PXP2_REG_RD_PBF_SWAP_MODE, 1); */
  5466. REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, 1);
  5467. REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, 1);
  5468. REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, 1);
  5469. REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, 1);
  5470. #endif
  5471. bnx2x_ilt_init_page_size(bp, INITOP_SET);
  5472. if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp))
  5473. REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1);
  5474. /* let the HW do it's magic ... */
  5475. msleep(100);
  5476. /* finish PXP init */
  5477. val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE);
  5478. if (val != 1) {
  5479. BNX2X_ERR("PXP2 CFG failed\n");
  5480. return -EBUSY;
  5481. }
  5482. val = REG_RD(bp, PXP2_REG_RD_INIT_DONE);
  5483. if (val != 1) {
  5484. BNX2X_ERR("PXP2 RD_INIT failed\n");
  5485. return -EBUSY;
  5486. }
  5487. /* Timers bug workaround E2 only. We need to set the entire ILT to
  5488. * have entries with value "0" and valid bit on.
  5489. * This needs to be done by the first PF that is loaded in a path
  5490. * (i.e. common phase)
  5491. */
  5492. if (!CHIP_IS_E1x(bp)) {
  5493. /* In E2 there is a bug in the timers block that can cause function 6 / 7
  5494. * (i.e. vnic3) to start even if it is marked as "scan-off".
  5495. * This occurs when a different function (func2,3) is being marked
  5496. * as "scan-off". Real-life scenario for example: if a driver is being
  5497. * load-unloaded while func6,7 are down. This will cause the timer to access
  5498. * the ilt, translate to a logical address and send a request to read/write.
  5499. * Since the ilt for the function that is down is not valid, this will cause
  5500. * a translation error which is unrecoverable.
  5501. * The Workaround is intended to make sure that when this happens nothing fatal
  5502. * will occur. The workaround:
  5503. * 1. First PF driver which loads on a path will:
  5504. * a. After taking the chip out of reset, by using pretend,
  5505. * it will write "0" to the following registers of
  5506. * the other vnics.
  5507. * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  5508. * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0);
  5509. * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0);
  5510. * And for itself it will write '1' to
  5511. * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable
  5512. * dmae-operations (writing to pram for example.)
  5513. * note: can be done for only function 6,7 but cleaner this
  5514. * way.
  5515. * b. Write zero+valid to the entire ILT.
  5516. * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of
  5517. * VNIC3 (of that port). The range allocated will be the
  5518. * entire ILT. This is needed to prevent ILT range error.
  5519. * 2. Any PF driver load flow:
  5520. * a. ILT update with the physical addresses of the allocated
  5521. * logical pages.
  5522. * b. Wait 20msec. - note that this timeout is needed to make
  5523. * sure there are no requests in one of the PXP internal
  5524. * queues with "old" ILT addresses.
  5525. * c. PF enable in the PGLC.
  5526. * d. Clear the was_error of the PF in the PGLC. (could have
  5527. * occured while driver was down)
  5528. * e. PF enable in the CFC (WEAK + STRONG)
  5529. * f. Timers scan enable
  5530. * 3. PF driver unload flow:
  5531. * a. Clear the Timers scan_en.
  5532. * b. Polling for scan_on=0 for that PF.
  5533. * c. Clear the PF enable bit in the PXP.
  5534. * d. Clear the PF enable in the CFC (WEAK + STRONG)
  5535. * e. Write zero+valid to all ILT entries (The valid bit must
  5536. * stay set)
  5537. * f. If this is VNIC 3 of a port then also init
  5538. * first_timers_ilt_entry to zero and last_timers_ilt_entry
  5539. * to the last enrty in the ILT.
  5540. *
  5541. * Notes:
  5542. * Currently the PF error in the PGLC is non recoverable.
  5543. * In the future the there will be a recovery routine for this error.
  5544. * Currently attention is masked.
  5545. * Having an MCP lock on the load/unload process does not guarantee that
  5546. * there is no Timer disable during Func6/7 enable. This is because the
  5547. * Timers scan is currently being cleared by the MCP on FLR.
  5548. * Step 2.d can be done only for PF6/7 and the driver can also check if
  5549. * there is error before clearing it. But the flow above is simpler and
  5550. * more general.
  5551. * All ILT entries are written by zero+valid and not just PF6/7
  5552. * ILT entries since in the future the ILT entries allocation for
  5553. * PF-s might be dynamic.
  5554. */
  5555. struct ilt_client_info ilt_cli;
  5556. struct bnx2x_ilt ilt;
  5557. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  5558. memset(&ilt, 0, sizeof(struct bnx2x_ilt));
  5559. /* initialize dummy TM client */
  5560. ilt_cli.start = 0;
  5561. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  5562. ilt_cli.client_num = ILT_CLIENT_TM;
  5563. /* Step 1: set zeroes to all ilt page entries with valid bit on
  5564. * Step 2: set the timers first/last ilt entry to point
  5565. * to the entire range to prevent ILT range error for 3rd/4th
  5566. * vnic (this code assumes existance of the vnic)
  5567. *
  5568. * both steps performed by call to bnx2x_ilt_client_init_op()
  5569. * with dummy TM client
  5570. *
  5571. * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT
  5572. * and his brother are split registers
  5573. */
  5574. bnx2x_pretend_func(bp, (BP_PATH(bp) + 6));
  5575. bnx2x_ilt_client_init_op_ilt(bp, &ilt, &ilt_cli, INITOP_CLEAR);
  5576. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  5577. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN, BNX2X_PXP_DRAM_ALIGN);
  5578. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_RD, BNX2X_PXP_DRAM_ALIGN);
  5579. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_SEL, 1);
  5580. }
  5581. REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0);
  5582. REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0);
  5583. if (!CHIP_IS_E1x(bp)) {
  5584. int factor = CHIP_REV_IS_EMUL(bp) ? 1000 :
  5585. (CHIP_REV_IS_FPGA(bp) ? 400 : 0);
  5586. bnx2x_init_block(bp, BLOCK_PGLUE_B, PHASE_COMMON);
  5587. bnx2x_init_block(bp, BLOCK_ATC, PHASE_COMMON);
  5588. /* let the HW do it's magic ... */
  5589. do {
  5590. msleep(200);
  5591. val = REG_RD(bp, ATC_REG_ATC_INIT_DONE);
  5592. } while (factor-- && (val != 1));
  5593. if (val != 1) {
  5594. BNX2X_ERR("ATC_INIT failed\n");
  5595. return -EBUSY;
  5596. }
  5597. }
  5598. bnx2x_init_block(bp, BLOCK_DMAE, PHASE_COMMON);
  5599. bnx2x_iov_init_dmae(bp);
  5600. /* clean the DMAE memory */
  5601. bp->dmae_ready = 1;
  5602. bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8, 1);
  5603. bnx2x_init_block(bp, BLOCK_TCM, PHASE_COMMON);
  5604. bnx2x_init_block(bp, BLOCK_UCM, PHASE_COMMON);
  5605. bnx2x_init_block(bp, BLOCK_CCM, PHASE_COMMON);
  5606. bnx2x_init_block(bp, BLOCK_XCM, PHASE_COMMON);
  5607. bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3);
  5608. bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3);
  5609. bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3);
  5610. bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3);
  5611. bnx2x_init_block(bp, BLOCK_QM, PHASE_COMMON);
  5612. /* QM queues pointers table */
  5613. bnx2x_qm_init_ptr_table(bp, bp->qm_cid_count, INITOP_SET);
  5614. /* soft reset pulse */
  5615. REG_WR(bp, QM_REG_SOFT_RESET, 1);
  5616. REG_WR(bp, QM_REG_SOFT_RESET, 0);
  5617. if (CNIC_SUPPORT(bp))
  5618. bnx2x_init_block(bp, BLOCK_TM, PHASE_COMMON);
  5619. bnx2x_init_block(bp, BLOCK_DORQ, PHASE_COMMON);
  5620. REG_WR(bp, DORQ_REG_DPM_CID_OFST, BNX2X_DB_SHIFT);
  5621. if (!CHIP_REV_IS_SLOW(bp))
  5622. /* enable hw interrupt from doorbell Q */
  5623. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  5624. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5625. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5626. REG_WR(bp, PRS_REG_A_PRSU_20, 0xf);
  5627. if (!CHIP_IS_E1(bp))
  5628. REG_WR(bp, PRS_REG_E1HOV_MODE, bp->path_has_ovlan);
  5629. if (!CHIP_IS_E1x(bp) && !CHIP_IS_E3B0(bp)) {
  5630. if (IS_MF_AFEX(bp)) {
  5631. /* configure that VNTag and VLAN headers must be
  5632. * received in afex mode
  5633. */
  5634. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC, 0xE);
  5635. REG_WR(bp, PRS_REG_MUST_HAVE_HDRS, 0xA);
  5636. REG_WR(bp, PRS_REG_HDRS_AFTER_TAG_0, 0x6);
  5637. REG_WR(bp, PRS_REG_TAG_ETHERTYPE_0, 0x8926);
  5638. REG_WR(bp, PRS_REG_TAG_LEN_0, 0x4);
  5639. } else {
  5640. /* Bit-map indicating which L2 hdrs may appear
  5641. * after the basic Ethernet header
  5642. */
  5643. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC,
  5644. bp->path_has_ovlan ? 7 : 6);
  5645. }
  5646. }
  5647. bnx2x_init_block(bp, BLOCK_TSDM, PHASE_COMMON);
  5648. bnx2x_init_block(bp, BLOCK_CSDM, PHASE_COMMON);
  5649. bnx2x_init_block(bp, BLOCK_USDM, PHASE_COMMON);
  5650. bnx2x_init_block(bp, BLOCK_XSDM, PHASE_COMMON);
  5651. if (!CHIP_IS_E1x(bp)) {
  5652. /* reset VFC memories */
  5653. REG_WR(bp, TSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  5654. VFC_MEMORIES_RST_REG_CAM_RST |
  5655. VFC_MEMORIES_RST_REG_RAM_RST);
  5656. REG_WR(bp, XSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  5657. VFC_MEMORIES_RST_REG_CAM_RST |
  5658. VFC_MEMORIES_RST_REG_RAM_RST);
  5659. msleep(20);
  5660. }
  5661. bnx2x_init_block(bp, BLOCK_TSEM, PHASE_COMMON);
  5662. bnx2x_init_block(bp, BLOCK_USEM, PHASE_COMMON);
  5663. bnx2x_init_block(bp, BLOCK_CSEM, PHASE_COMMON);
  5664. bnx2x_init_block(bp, BLOCK_XSEM, PHASE_COMMON);
  5665. /* sync semi rtc */
  5666. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  5667. 0x80000000);
  5668. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
  5669. 0x80000000);
  5670. bnx2x_init_block(bp, BLOCK_UPB, PHASE_COMMON);
  5671. bnx2x_init_block(bp, BLOCK_XPB, PHASE_COMMON);
  5672. bnx2x_init_block(bp, BLOCK_PBF, PHASE_COMMON);
  5673. if (!CHIP_IS_E1x(bp)) {
  5674. if (IS_MF_AFEX(bp)) {
  5675. /* configure that VNTag and VLAN headers must be
  5676. * sent in afex mode
  5677. */
  5678. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC, 0xE);
  5679. REG_WR(bp, PBF_REG_MUST_HAVE_HDRS, 0xA);
  5680. REG_WR(bp, PBF_REG_HDRS_AFTER_TAG_0, 0x6);
  5681. REG_WR(bp, PBF_REG_TAG_ETHERTYPE_0, 0x8926);
  5682. REG_WR(bp, PBF_REG_TAG_LEN_0, 0x4);
  5683. } else {
  5684. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC,
  5685. bp->path_has_ovlan ? 7 : 6);
  5686. }
  5687. }
  5688. REG_WR(bp, SRC_REG_SOFT_RST, 1);
  5689. bnx2x_init_block(bp, BLOCK_SRC, PHASE_COMMON);
  5690. if (CNIC_SUPPORT(bp)) {
  5691. REG_WR(bp, SRC_REG_KEYSEARCH_0, 0x63285672);
  5692. REG_WR(bp, SRC_REG_KEYSEARCH_1, 0x24b8f2cc);
  5693. REG_WR(bp, SRC_REG_KEYSEARCH_2, 0x223aef9b);
  5694. REG_WR(bp, SRC_REG_KEYSEARCH_3, 0x26001e3a);
  5695. REG_WR(bp, SRC_REG_KEYSEARCH_4, 0x7ae91116);
  5696. REG_WR(bp, SRC_REG_KEYSEARCH_5, 0x5ce5230b);
  5697. REG_WR(bp, SRC_REG_KEYSEARCH_6, 0x298d8adf);
  5698. REG_WR(bp, SRC_REG_KEYSEARCH_7, 0x6eb0ff09);
  5699. REG_WR(bp, SRC_REG_KEYSEARCH_8, 0x1830f82f);
  5700. REG_WR(bp, SRC_REG_KEYSEARCH_9, 0x01e46be7);
  5701. }
  5702. REG_WR(bp, SRC_REG_SOFT_RST, 0);
  5703. if (sizeof(union cdu_context) != 1024)
  5704. /* we currently assume that a context is 1024 bytes */
  5705. dev_alert(&bp->pdev->dev,
  5706. "please adjust the size of cdu_context(%ld)\n",
  5707. (long)sizeof(union cdu_context));
  5708. bnx2x_init_block(bp, BLOCK_CDU, PHASE_COMMON);
  5709. val = (4 << 24) + (0 << 12) + 1024;
  5710. REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val);
  5711. bnx2x_init_block(bp, BLOCK_CFC, PHASE_COMMON);
  5712. REG_WR(bp, CFC_REG_INIT_REG, 0x7FF);
  5713. /* enable context validation interrupt from CFC */
  5714. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  5715. /* set the thresholds to prevent CFC/CDU race */
  5716. REG_WR(bp, CFC_REG_DEBUG0, 0x20020000);
  5717. bnx2x_init_block(bp, BLOCK_HC, PHASE_COMMON);
  5718. if (!CHIP_IS_E1x(bp) && BP_NOMCP(bp))
  5719. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x36);
  5720. bnx2x_init_block(bp, BLOCK_IGU, PHASE_COMMON);
  5721. bnx2x_init_block(bp, BLOCK_MISC_AEU, PHASE_COMMON);
  5722. /* Reset PCIE errors for debug */
  5723. REG_WR(bp, 0x2814, 0xffffffff);
  5724. REG_WR(bp, 0x3820, 0xffffffff);
  5725. if (!CHIP_IS_E1x(bp)) {
  5726. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_CONTROL_5,
  5727. (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1 |
  5728. PXPCS_TL_CONTROL_5_ERR_UNSPPORT));
  5729. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC345_STAT,
  5730. (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4 |
  5731. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3 |
  5732. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2));
  5733. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC678_STAT,
  5734. (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7 |
  5735. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6 |
  5736. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5));
  5737. }
  5738. bnx2x_init_block(bp, BLOCK_NIG, PHASE_COMMON);
  5739. if (!CHIP_IS_E1(bp)) {
  5740. /* in E3 this done in per-port section */
  5741. if (!CHIP_IS_E3(bp))
  5742. REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_MF(bp));
  5743. }
  5744. if (CHIP_IS_E1H(bp))
  5745. /* not applicable for E2 (and above ...) */
  5746. REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_MF_SD(bp));
  5747. if (CHIP_REV_IS_SLOW(bp))
  5748. msleep(200);
  5749. /* finish CFC init */
  5750. val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10);
  5751. if (val != 1) {
  5752. BNX2X_ERR("CFC LL_INIT failed\n");
  5753. return -EBUSY;
  5754. }
  5755. val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10);
  5756. if (val != 1) {
  5757. BNX2X_ERR("CFC AC_INIT failed\n");
  5758. return -EBUSY;
  5759. }
  5760. val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10);
  5761. if (val != 1) {
  5762. BNX2X_ERR("CFC CAM_INIT failed\n");
  5763. return -EBUSY;
  5764. }
  5765. REG_WR(bp, CFC_REG_DEBUG0, 0);
  5766. if (CHIP_IS_E1(bp)) {
  5767. /* read NIG statistic
  5768. to see if this is our first up since powerup */
  5769. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5770. val = *bnx2x_sp(bp, wb_data[0]);
  5771. /* do internal memory self test */
  5772. if ((val == 0) && bnx2x_int_mem_test(bp)) {
  5773. BNX2X_ERR("internal mem self test failed\n");
  5774. return -EBUSY;
  5775. }
  5776. }
  5777. bnx2x_setup_fan_failure_detection(bp);
  5778. /* clear PXP2 attentions */
  5779. REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0);
  5780. bnx2x_enable_blocks_attention(bp);
  5781. bnx2x_enable_blocks_parity(bp);
  5782. if (!BP_NOMCP(bp)) {
  5783. if (CHIP_IS_E1x(bp))
  5784. bnx2x__common_init_phy(bp);
  5785. } else
  5786. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  5787. return 0;
  5788. }
  5789. /**
  5790. * bnx2x_init_hw_common_chip - init HW at the COMMON_CHIP phase.
  5791. *
  5792. * @bp: driver handle
  5793. */
  5794. static int bnx2x_init_hw_common_chip(struct bnx2x *bp)
  5795. {
  5796. int rc = bnx2x_init_hw_common(bp);
  5797. if (rc)
  5798. return rc;
  5799. /* In E2 2-PORT mode, same ext phy is used for the two paths */
  5800. if (!BP_NOMCP(bp))
  5801. bnx2x__common_init_phy(bp);
  5802. return 0;
  5803. }
  5804. static int bnx2x_init_hw_port(struct bnx2x *bp)
  5805. {
  5806. int port = BP_PORT(bp);
  5807. int init_phase = port ? PHASE_PORT1 : PHASE_PORT0;
  5808. u32 low, high;
  5809. u32 val;
  5810. DP(NETIF_MSG_HW, "starting port init port %d\n", port);
  5811. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  5812. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  5813. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  5814. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  5815. /* Timers bug workaround: disables the pf_master bit in pglue at
  5816. * common phase, we need to enable it here before any dmae access are
  5817. * attempted. Therefore we manually added the enable-master to the
  5818. * port phase (it also happens in the function phase)
  5819. */
  5820. if (!CHIP_IS_E1x(bp))
  5821. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  5822. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  5823. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  5824. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  5825. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  5826. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  5827. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  5828. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  5829. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  5830. /* QM cid (connection) count */
  5831. bnx2x_qm_init_cid_count(bp, bp->qm_cid_count, INITOP_SET);
  5832. if (CNIC_SUPPORT(bp)) {
  5833. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  5834. REG_WR(bp, TM_REG_LIN0_SCAN_TIME + port*4, 20);
  5835. REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31);
  5836. }
  5837. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  5838. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  5839. if (CHIP_IS_E1(bp) || CHIP_IS_E1H(bp)) {
  5840. if (IS_MF(bp))
  5841. low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246);
  5842. else if (bp->dev->mtu > 4096) {
  5843. if (bp->flags & ONE_PORT_FLAG)
  5844. low = 160;
  5845. else {
  5846. val = bp->dev->mtu;
  5847. /* (24*1024 + val*4)/256 */
  5848. low = 96 + (val/64) +
  5849. ((val % 64) ? 1 : 0);
  5850. }
  5851. } else
  5852. low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160);
  5853. high = low + 56; /* 14*1024/256 */
  5854. REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low);
  5855. REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high);
  5856. }
  5857. if (CHIP_MODE_IS_4_PORT(bp))
  5858. REG_WR(bp, (BP_PORT(bp) ?
  5859. BRB1_REG_MAC_GUARANTIED_1 :
  5860. BRB1_REG_MAC_GUARANTIED_0), 40);
  5861. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  5862. if (CHIP_IS_E3B0(bp)) {
  5863. if (IS_MF_AFEX(bp)) {
  5864. /* configure headers for AFEX mode */
  5865. REG_WR(bp, BP_PORT(bp) ?
  5866. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  5867. PRS_REG_HDRS_AFTER_BASIC_PORT_0, 0xE);
  5868. REG_WR(bp, BP_PORT(bp) ?
  5869. PRS_REG_HDRS_AFTER_TAG_0_PORT_1 :
  5870. PRS_REG_HDRS_AFTER_TAG_0_PORT_0, 0x6);
  5871. REG_WR(bp, BP_PORT(bp) ?
  5872. PRS_REG_MUST_HAVE_HDRS_PORT_1 :
  5873. PRS_REG_MUST_HAVE_HDRS_PORT_0, 0xA);
  5874. } else {
  5875. /* Ovlan exists only if we are in multi-function +
  5876. * switch-dependent mode, in switch-independent there
  5877. * is no ovlan headers
  5878. */
  5879. REG_WR(bp, BP_PORT(bp) ?
  5880. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  5881. PRS_REG_HDRS_AFTER_BASIC_PORT_0,
  5882. (bp->path_has_ovlan ? 7 : 6));
  5883. }
  5884. }
  5885. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  5886. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  5887. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  5888. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  5889. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  5890. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  5891. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  5892. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  5893. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  5894. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  5895. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  5896. if (CHIP_IS_E1x(bp)) {
  5897. /* configure PBF to work without PAUSE mtu 9000 */
  5898. REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
  5899. /* update threshold */
  5900. REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16));
  5901. /* update init credit */
  5902. REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22);
  5903. /* probe changes */
  5904. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1);
  5905. udelay(50);
  5906. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0);
  5907. }
  5908. if (CNIC_SUPPORT(bp))
  5909. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  5910. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  5911. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  5912. if (CHIP_IS_E1(bp)) {
  5913. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  5914. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  5915. }
  5916. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  5917. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  5918. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  5919. /* init aeu_mask_attn_func_0/1:
  5920. * - SF mode: bits 3-7 are masked. only bits 0-2 are in use
  5921. * - MF mode: bit 3 is masked. bits 0-2 are in use as in SF
  5922. * bits 4-7 are used for "per vn group attention" */
  5923. val = IS_MF(bp) ? 0xF7 : 0x7;
  5924. /* Enable DCBX attention for all but E1 */
  5925. val |= CHIP_IS_E1(bp) ? 0 : 0x10;
  5926. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, val);
  5927. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  5928. if (!CHIP_IS_E1x(bp)) {
  5929. /* Bit-map indicating which L2 hdrs may appear after the
  5930. * basic Ethernet header
  5931. */
  5932. if (IS_MF_AFEX(bp))
  5933. REG_WR(bp, BP_PORT(bp) ?
  5934. NIG_REG_P1_HDRS_AFTER_BASIC :
  5935. NIG_REG_P0_HDRS_AFTER_BASIC, 0xE);
  5936. else
  5937. REG_WR(bp, BP_PORT(bp) ?
  5938. NIG_REG_P1_HDRS_AFTER_BASIC :
  5939. NIG_REG_P0_HDRS_AFTER_BASIC,
  5940. IS_MF_SD(bp) ? 7 : 6);
  5941. if (CHIP_IS_E3(bp))
  5942. REG_WR(bp, BP_PORT(bp) ?
  5943. NIG_REG_LLH1_MF_MODE :
  5944. NIG_REG_LLH_MF_MODE, IS_MF(bp));
  5945. }
  5946. if (!CHIP_IS_E3(bp))
  5947. REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
  5948. if (!CHIP_IS_E1(bp)) {
  5949. /* 0x2 disable mf_ov, 0x1 enable */
  5950. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4,
  5951. (IS_MF_SD(bp) ? 0x1 : 0x2));
  5952. if (!CHIP_IS_E1x(bp)) {
  5953. val = 0;
  5954. switch (bp->mf_mode) {
  5955. case MULTI_FUNCTION_SD:
  5956. val = 1;
  5957. break;
  5958. case MULTI_FUNCTION_SI:
  5959. case MULTI_FUNCTION_AFEX:
  5960. val = 2;
  5961. break;
  5962. }
  5963. REG_WR(bp, (BP_PORT(bp) ? NIG_REG_LLH1_CLS_TYPE :
  5964. NIG_REG_LLH0_CLS_TYPE), val);
  5965. }
  5966. {
  5967. REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0);
  5968. REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0);
  5969. REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1);
  5970. }
  5971. }
  5972. /* If SPIO5 is set to generate interrupts, enable it for this port */
  5973. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  5974. if (val & MISC_SPIO_SPIO5) {
  5975. u32 reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  5976. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  5977. val = REG_RD(bp, reg_addr);
  5978. val |= AEU_INPUTS_ATTN_BITS_SPIO5;
  5979. REG_WR(bp, reg_addr, val);
  5980. }
  5981. return 0;
  5982. }
  5983. static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr)
  5984. {
  5985. int reg;
  5986. u32 wb_write[2];
  5987. if (CHIP_IS_E1(bp))
  5988. reg = PXP2_REG_RQ_ONCHIP_AT + index*8;
  5989. else
  5990. reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8;
  5991. wb_write[0] = ONCHIP_ADDR1(addr);
  5992. wb_write[1] = ONCHIP_ADDR2(addr);
  5993. REG_WR_DMAE(bp, reg, wb_write, 2);
  5994. }
  5995. void bnx2x_igu_clear_sb_gen(struct bnx2x *bp, u8 func, u8 idu_sb_id, bool is_pf)
  5996. {
  5997. u32 data, ctl, cnt = 100;
  5998. u32 igu_addr_data = IGU_REG_COMMAND_REG_32LSB_DATA;
  5999. u32 igu_addr_ctl = IGU_REG_COMMAND_REG_CTRL;
  6000. u32 igu_addr_ack = IGU_REG_CSTORM_TYPE_0_SB_CLEANUP + (idu_sb_id/32)*4;
  6001. u32 sb_bit = 1 << (idu_sb_id%32);
  6002. u32 func_encode = func | (is_pf ? 1 : 0) << IGU_FID_ENCODE_IS_PF_SHIFT;
  6003. u32 addr_encode = IGU_CMD_E2_PROD_UPD_BASE + idu_sb_id;
  6004. /* Not supported in BC mode */
  6005. if (CHIP_INT_MODE_IS_BC(bp))
  6006. return;
  6007. data = (IGU_USE_REGISTER_cstorm_type_0_sb_cleanup
  6008. << IGU_REGULAR_CLEANUP_TYPE_SHIFT) |
  6009. IGU_REGULAR_CLEANUP_SET |
  6010. IGU_REGULAR_BCLEANUP;
  6011. ctl = addr_encode << IGU_CTRL_REG_ADDRESS_SHIFT |
  6012. func_encode << IGU_CTRL_REG_FID_SHIFT |
  6013. IGU_CTRL_CMD_TYPE_WR << IGU_CTRL_REG_TYPE_SHIFT;
  6014. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  6015. data, igu_addr_data);
  6016. REG_WR(bp, igu_addr_data, data);
  6017. mmiowb();
  6018. barrier();
  6019. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  6020. ctl, igu_addr_ctl);
  6021. REG_WR(bp, igu_addr_ctl, ctl);
  6022. mmiowb();
  6023. barrier();
  6024. /* wait for clean up to finish */
  6025. while (!(REG_RD(bp, igu_addr_ack) & sb_bit) && --cnt)
  6026. msleep(20);
  6027. if (!(REG_RD(bp, igu_addr_ack) & sb_bit)) {
  6028. DP(NETIF_MSG_HW,
  6029. "Unable to finish IGU cleanup: idu_sb_id %d offset %d bit %d (cnt %d)\n",
  6030. idu_sb_id, idu_sb_id/32, idu_sb_id%32, cnt);
  6031. }
  6032. }
  6033. static void bnx2x_igu_clear_sb(struct bnx2x *bp, u8 idu_sb_id)
  6034. {
  6035. bnx2x_igu_clear_sb_gen(bp, BP_FUNC(bp), idu_sb_id, true /*PF*/);
  6036. }
  6037. static void bnx2x_clear_func_ilt(struct bnx2x *bp, u32 func)
  6038. {
  6039. u32 i, base = FUNC_ILT_BASE(func);
  6040. for (i = base; i < base + ILT_PER_FUNC; i++)
  6041. bnx2x_ilt_wr(bp, i, 0);
  6042. }
  6043. static void bnx2x_init_searcher(struct bnx2x *bp)
  6044. {
  6045. int port = BP_PORT(bp);
  6046. bnx2x_src_init_t2(bp, bp->t2, bp->t2_mapping, SRC_CONN_NUM);
  6047. /* T1 hash bits value determines the T1 number of entries */
  6048. REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + port*4, SRC_HASH_BITS);
  6049. }
  6050. static inline int bnx2x_func_switch_update(struct bnx2x *bp, int suspend)
  6051. {
  6052. int rc;
  6053. struct bnx2x_func_state_params func_params = {NULL};
  6054. struct bnx2x_func_switch_update_params *switch_update_params =
  6055. &func_params.params.switch_update;
  6056. /* Prepare parameters for function state transitions */
  6057. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  6058. __set_bit(RAMROD_RETRY, &func_params.ramrod_flags);
  6059. func_params.f_obj = &bp->func_obj;
  6060. func_params.cmd = BNX2X_F_CMD_SWITCH_UPDATE;
  6061. /* Function parameters */
  6062. switch_update_params->suspend = suspend;
  6063. rc = bnx2x_func_state_change(bp, &func_params);
  6064. return rc;
  6065. }
  6066. static int bnx2x_reset_nic_mode(struct bnx2x *bp)
  6067. {
  6068. int rc, i, port = BP_PORT(bp);
  6069. int vlan_en = 0, mac_en[NUM_MACS];
  6070. /* Close input from network */
  6071. if (bp->mf_mode == SINGLE_FUNCTION) {
  6072. bnx2x_set_rx_filter(&bp->link_params, 0);
  6073. } else {
  6074. vlan_en = REG_RD(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6075. NIG_REG_LLH0_FUNC_EN);
  6076. REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6077. NIG_REG_LLH0_FUNC_EN, 0);
  6078. for (i = 0; i < NUM_MACS; i++) {
  6079. mac_en[i] = REG_RD(bp, port ?
  6080. (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6081. 4 * i) :
  6082. (NIG_REG_LLH0_FUNC_MEM_ENABLE +
  6083. 4 * i));
  6084. REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6085. 4 * i) :
  6086. (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i), 0);
  6087. }
  6088. }
  6089. /* Close BMC to host */
  6090. REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
  6091. NIG_REG_P1_TX_MNG_HOST_ENABLE, 0);
  6092. /* Suspend Tx switching to the PF. Completion of this ramrod
  6093. * further guarantees that all the packets of that PF / child
  6094. * VFs in BRB were processed by the Parser, so it is safe to
  6095. * change the NIC_MODE register.
  6096. */
  6097. rc = bnx2x_func_switch_update(bp, 1);
  6098. if (rc) {
  6099. BNX2X_ERR("Can't suspend tx-switching!\n");
  6100. return rc;
  6101. }
  6102. /* Change NIC_MODE register */
  6103. REG_WR(bp, PRS_REG_NIC_MODE, 0);
  6104. /* Open input from network */
  6105. if (bp->mf_mode == SINGLE_FUNCTION) {
  6106. bnx2x_set_rx_filter(&bp->link_params, 1);
  6107. } else {
  6108. REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6109. NIG_REG_LLH0_FUNC_EN, vlan_en);
  6110. for (i = 0; i < NUM_MACS; i++) {
  6111. REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6112. 4 * i) :
  6113. (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i),
  6114. mac_en[i]);
  6115. }
  6116. }
  6117. /* Enable BMC to host */
  6118. REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
  6119. NIG_REG_P1_TX_MNG_HOST_ENABLE, 1);
  6120. /* Resume Tx switching to the PF */
  6121. rc = bnx2x_func_switch_update(bp, 0);
  6122. if (rc) {
  6123. BNX2X_ERR("Can't resume tx-switching!\n");
  6124. return rc;
  6125. }
  6126. DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
  6127. return 0;
  6128. }
  6129. int bnx2x_init_hw_func_cnic(struct bnx2x *bp)
  6130. {
  6131. int rc;
  6132. bnx2x_ilt_init_op_cnic(bp, INITOP_SET);
  6133. if (CONFIGURE_NIC_MODE(bp)) {
  6134. /* Configrue searcher as part of function hw init */
  6135. bnx2x_init_searcher(bp);
  6136. /* Reset NIC mode */
  6137. rc = bnx2x_reset_nic_mode(bp);
  6138. if (rc)
  6139. BNX2X_ERR("Can't change NIC mode!\n");
  6140. return rc;
  6141. }
  6142. return 0;
  6143. }
  6144. static int bnx2x_init_hw_func(struct bnx2x *bp)
  6145. {
  6146. int port = BP_PORT(bp);
  6147. int func = BP_FUNC(bp);
  6148. int init_phase = PHASE_PF0 + func;
  6149. struct bnx2x_ilt *ilt = BP_ILT(bp);
  6150. u16 cdu_ilt_start;
  6151. u32 addr, val;
  6152. u32 main_mem_base, main_mem_size, main_mem_prty_clr;
  6153. int i, main_mem_width, rc;
  6154. DP(NETIF_MSG_HW, "starting func init func %d\n", func);
  6155. /* FLR cleanup - hmmm */
  6156. if (!CHIP_IS_E1x(bp)) {
  6157. rc = bnx2x_pf_flr_clnup(bp);
  6158. if (rc)
  6159. return rc;
  6160. }
  6161. /* set MSI reconfigure capability */
  6162. if (bp->common.int_block == INT_BLOCK_HC) {
  6163. addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0);
  6164. val = REG_RD(bp, addr);
  6165. val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0;
  6166. REG_WR(bp, addr, val);
  6167. }
  6168. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  6169. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  6170. ilt = BP_ILT(bp);
  6171. cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
  6172. if (IS_SRIOV(bp))
  6173. cdu_ilt_start += BNX2X_FIRST_VF_CID/ILT_PAGE_CIDS;
  6174. cdu_ilt_start = bnx2x_iov_init_ilt(bp, cdu_ilt_start);
  6175. /* since BNX2X_FIRST_VF_CID > 0 the PF L2 cids precedes
  6176. * those of the VFs, so start line should be reset
  6177. */
  6178. cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
  6179. for (i = 0; i < L2_ILT_LINES(bp); i++) {
  6180. ilt->lines[cdu_ilt_start + i].page = bp->context[i].vcxt;
  6181. ilt->lines[cdu_ilt_start + i].page_mapping =
  6182. bp->context[i].cxt_mapping;
  6183. ilt->lines[cdu_ilt_start + i].size = bp->context[i].size;
  6184. }
  6185. bnx2x_ilt_init_op(bp, INITOP_SET);
  6186. if (!CONFIGURE_NIC_MODE(bp)) {
  6187. bnx2x_init_searcher(bp);
  6188. REG_WR(bp, PRS_REG_NIC_MODE, 0);
  6189. DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
  6190. } else {
  6191. /* Set NIC mode */
  6192. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  6193. DP(NETIF_MSG_IFUP, "NIC MODE configrued\n");
  6194. }
  6195. if (!CHIP_IS_E1x(bp)) {
  6196. u32 pf_conf = IGU_PF_CONF_FUNC_EN;
  6197. /* Turn on a single ISR mode in IGU if driver is going to use
  6198. * INT#x or MSI
  6199. */
  6200. if (!(bp->flags & USING_MSIX_FLAG))
  6201. pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN;
  6202. /*
  6203. * Timers workaround bug: function init part.
  6204. * Need to wait 20msec after initializing ILT,
  6205. * needed to make sure there are no requests in
  6206. * one of the PXP internal queues with "old" ILT addresses
  6207. */
  6208. msleep(20);
  6209. /*
  6210. * Master enable - Due to WB DMAE writes performed before this
  6211. * register is re-initialized as part of the regular function
  6212. * init
  6213. */
  6214. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  6215. /* Enable the function in IGU */
  6216. REG_WR(bp, IGU_REG_PF_CONFIGURATION, pf_conf);
  6217. }
  6218. bp->dmae_ready = 1;
  6219. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  6220. if (!CHIP_IS_E1x(bp))
  6221. REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, func);
  6222. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  6223. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  6224. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  6225. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  6226. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  6227. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  6228. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  6229. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  6230. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  6231. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  6232. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  6233. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  6234. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  6235. if (!CHIP_IS_E1x(bp))
  6236. REG_WR(bp, QM_REG_PF_EN, 1);
  6237. if (!CHIP_IS_E1x(bp)) {
  6238. REG_WR(bp, TSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6239. REG_WR(bp, USEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6240. REG_WR(bp, CSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6241. REG_WR(bp, XSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6242. }
  6243. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  6244. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  6245. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  6246. bnx2x_iov_init_dq(bp);
  6247. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  6248. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  6249. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  6250. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  6251. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  6252. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  6253. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  6254. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  6255. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  6256. if (!CHIP_IS_E1x(bp))
  6257. REG_WR(bp, PBF_REG_DISABLE_PF, 0);
  6258. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  6259. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  6260. if (!CHIP_IS_E1x(bp))
  6261. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 1);
  6262. if (IS_MF(bp)) {
  6263. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
  6264. REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port*8, bp->mf_ov);
  6265. }
  6266. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  6267. /* HC init per function */
  6268. if (bp->common.int_block == INT_BLOCK_HC) {
  6269. if (CHIP_IS_E1H(bp)) {
  6270. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  6271. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  6272. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  6273. }
  6274. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  6275. } else {
  6276. int num_segs, sb_idx, prod_offset;
  6277. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  6278. if (!CHIP_IS_E1x(bp)) {
  6279. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  6280. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  6281. }
  6282. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  6283. if (!CHIP_IS_E1x(bp)) {
  6284. int dsb_idx = 0;
  6285. /**
  6286. * Producer memory:
  6287. * E2 mode: address 0-135 match to the mapping memory;
  6288. * 136 - PF0 default prod; 137 - PF1 default prod;
  6289. * 138 - PF2 default prod; 139 - PF3 default prod;
  6290. * 140 - PF0 attn prod; 141 - PF1 attn prod;
  6291. * 142 - PF2 attn prod; 143 - PF3 attn prod;
  6292. * 144-147 reserved.
  6293. *
  6294. * E1.5 mode - In backward compatible mode;
  6295. * for non default SB; each even line in the memory
  6296. * holds the U producer and each odd line hold
  6297. * the C producer. The first 128 producers are for
  6298. * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20
  6299. * producers are for the DSB for each PF.
  6300. * Each PF has five segments: (the order inside each
  6301. * segment is PF0; PF1; PF2; PF3) - 128-131 U prods;
  6302. * 132-135 C prods; 136-139 X prods; 140-143 T prods;
  6303. * 144-147 attn prods;
  6304. */
  6305. /* non-default-status-blocks */
  6306. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  6307. IGU_BC_NDSB_NUM_SEGS : IGU_NORM_NDSB_NUM_SEGS;
  6308. for (sb_idx = 0; sb_idx < bp->igu_sb_cnt; sb_idx++) {
  6309. prod_offset = (bp->igu_base_sb + sb_idx) *
  6310. num_segs;
  6311. for (i = 0; i < num_segs; i++) {
  6312. addr = IGU_REG_PROD_CONS_MEMORY +
  6313. (prod_offset + i) * 4;
  6314. REG_WR(bp, addr, 0);
  6315. }
  6316. /* send consumer update with value 0 */
  6317. bnx2x_ack_sb(bp, bp->igu_base_sb + sb_idx,
  6318. USTORM_ID, 0, IGU_INT_NOP, 1);
  6319. bnx2x_igu_clear_sb(bp,
  6320. bp->igu_base_sb + sb_idx);
  6321. }
  6322. /* default-status-blocks */
  6323. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  6324. IGU_BC_DSB_NUM_SEGS : IGU_NORM_DSB_NUM_SEGS;
  6325. if (CHIP_MODE_IS_4_PORT(bp))
  6326. dsb_idx = BP_FUNC(bp);
  6327. else
  6328. dsb_idx = BP_VN(bp);
  6329. prod_offset = (CHIP_INT_MODE_IS_BC(bp) ?
  6330. IGU_BC_BASE_DSB_PROD + dsb_idx :
  6331. IGU_NORM_BASE_DSB_PROD + dsb_idx);
  6332. /*
  6333. * igu prods come in chunks of E1HVN_MAX (4) -
  6334. * does not matters what is the current chip mode
  6335. */
  6336. for (i = 0; i < (num_segs * E1HVN_MAX);
  6337. i += E1HVN_MAX) {
  6338. addr = IGU_REG_PROD_CONS_MEMORY +
  6339. (prod_offset + i)*4;
  6340. REG_WR(bp, addr, 0);
  6341. }
  6342. /* send consumer update with 0 */
  6343. if (CHIP_INT_MODE_IS_BC(bp)) {
  6344. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6345. USTORM_ID, 0, IGU_INT_NOP, 1);
  6346. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6347. CSTORM_ID, 0, IGU_INT_NOP, 1);
  6348. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6349. XSTORM_ID, 0, IGU_INT_NOP, 1);
  6350. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6351. TSTORM_ID, 0, IGU_INT_NOP, 1);
  6352. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6353. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  6354. } else {
  6355. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6356. USTORM_ID, 0, IGU_INT_NOP, 1);
  6357. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6358. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  6359. }
  6360. bnx2x_igu_clear_sb(bp, bp->igu_dsb_id);
  6361. /* !!! these should become driver const once
  6362. rf-tool supports split-68 const */
  6363. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0);
  6364. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0);
  6365. REG_WR(bp, IGU_REG_SB_MASK_LSB, 0);
  6366. REG_WR(bp, IGU_REG_SB_MASK_MSB, 0);
  6367. REG_WR(bp, IGU_REG_PBA_STATUS_LSB, 0);
  6368. REG_WR(bp, IGU_REG_PBA_STATUS_MSB, 0);
  6369. }
  6370. }
  6371. /* Reset PCIE errors for debug */
  6372. REG_WR(bp, 0x2114, 0xffffffff);
  6373. REG_WR(bp, 0x2120, 0xffffffff);
  6374. if (CHIP_IS_E1x(bp)) {
  6375. main_mem_size = HC_REG_MAIN_MEMORY_SIZE / 2; /*dwords*/
  6376. main_mem_base = HC_REG_MAIN_MEMORY +
  6377. BP_PORT(bp) * (main_mem_size * 4);
  6378. main_mem_prty_clr = HC_REG_HC_PRTY_STS_CLR;
  6379. main_mem_width = 8;
  6380. val = REG_RD(bp, main_mem_prty_clr);
  6381. if (val)
  6382. DP(NETIF_MSG_HW,
  6383. "Hmmm... Parity errors in HC block during function init (0x%x)!\n",
  6384. val);
  6385. /* Clear "false" parity errors in MSI-X table */
  6386. for (i = main_mem_base;
  6387. i < main_mem_base + main_mem_size * 4;
  6388. i += main_mem_width) {
  6389. bnx2x_read_dmae(bp, i, main_mem_width / 4);
  6390. bnx2x_write_dmae(bp, bnx2x_sp_mapping(bp, wb_data),
  6391. i, main_mem_width / 4);
  6392. }
  6393. /* Clear HC parity attention */
  6394. REG_RD(bp, main_mem_prty_clr);
  6395. }
  6396. #ifdef BNX2X_STOP_ON_ERROR
  6397. /* Enable STORMs SP logging */
  6398. REG_WR8(bp, BAR_USTRORM_INTMEM +
  6399. USTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6400. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  6401. TSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6402. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6403. CSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6404. REG_WR8(bp, BAR_XSTRORM_INTMEM +
  6405. XSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6406. #endif
  6407. bnx2x_phy_probe(&bp->link_params);
  6408. return 0;
  6409. }
  6410. void bnx2x_free_mem_cnic(struct bnx2x *bp)
  6411. {
  6412. bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_FREE);
  6413. if (!CHIP_IS_E1x(bp))
  6414. BNX2X_PCI_FREE(bp->cnic_sb.e2_sb, bp->cnic_sb_mapping,
  6415. sizeof(struct host_hc_status_block_e2));
  6416. else
  6417. BNX2X_PCI_FREE(bp->cnic_sb.e1x_sb, bp->cnic_sb_mapping,
  6418. sizeof(struct host_hc_status_block_e1x));
  6419. BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
  6420. }
  6421. void bnx2x_free_mem(struct bnx2x *bp)
  6422. {
  6423. int i;
  6424. /* fastpath */
  6425. bnx2x_free_fp_mem(bp);
  6426. /* end of fastpath */
  6427. BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping,
  6428. sizeof(struct host_sp_status_block));
  6429. BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
  6430. bp->fw_stats_data_sz + bp->fw_stats_req_sz);
  6431. BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping,
  6432. sizeof(struct bnx2x_slowpath));
  6433. for (i = 0; i < L2_ILT_LINES(bp); i++)
  6434. BNX2X_PCI_FREE(bp->context[i].vcxt, bp->context[i].cxt_mapping,
  6435. bp->context[i].size);
  6436. bnx2x_ilt_mem_op(bp, ILT_MEMOP_FREE);
  6437. BNX2X_FREE(bp->ilt->lines);
  6438. BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE);
  6439. BNX2X_PCI_FREE(bp->eq_ring, bp->eq_mapping,
  6440. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  6441. }
  6442. int bnx2x_alloc_mem_cnic(struct bnx2x *bp)
  6443. {
  6444. if (!CHIP_IS_E1x(bp))
  6445. /* size = the status block + ramrod buffers */
  6446. BNX2X_PCI_ALLOC(bp->cnic_sb.e2_sb, &bp->cnic_sb_mapping,
  6447. sizeof(struct host_hc_status_block_e2));
  6448. else
  6449. BNX2X_PCI_ALLOC(bp->cnic_sb.e1x_sb,
  6450. &bp->cnic_sb_mapping,
  6451. sizeof(struct
  6452. host_hc_status_block_e1x));
  6453. if (CONFIGURE_NIC_MODE(bp))
  6454. /* allocate searcher T2 table, as it wan't allocated before */
  6455. BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
  6456. /* write address to which L5 should insert its values */
  6457. bp->cnic_eth_dev.addr_drv_info_to_mcp =
  6458. &bp->slowpath->drv_info_to_mcp;
  6459. if (bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_ALLOC))
  6460. goto alloc_mem_err;
  6461. return 0;
  6462. alloc_mem_err:
  6463. bnx2x_free_mem_cnic(bp);
  6464. BNX2X_ERR("Can't allocate memory\n");
  6465. return -ENOMEM;
  6466. }
  6467. int bnx2x_alloc_mem(struct bnx2x *bp)
  6468. {
  6469. int i, allocated, context_size;
  6470. if (!CONFIGURE_NIC_MODE(bp))
  6471. /* allocate searcher T2 table */
  6472. BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
  6473. BNX2X_PCI_ALLOC(bp->def_status_blk, &bp->def_status_blk_mapping,
  6474. sizeof(struct host_sp_status_block));
  6475. BNX2X_PCI_ALLOC(bp->slowpath, &bp->slowpath_mapping,
  6476. sizeof(struct bnx2x_slowpath));
  6477. /* Allocate memory for CDU context:
  6478. * This memory is allocated separately and not in the generic ILT
  6479. * functions because CDU differs in few aspects:
  6480. * 1. There are multiple entities allocating memory for context -
  6481. * 'regular' driver, CNIC and SRIOV driver. Each separately controls
  6482. * its own ILT lines.
  6483. * 2. Since CDU page-size is not a single 4KB page (which is the case
  6484. * for the other ILT clients), to be efficient we want to support
  6485. * allocation of sub-page-size in the last entry.
  6486. * 3. Context pointers are used by the driver to pass to FW / update
  6487. * the context (for the other ILT clients the pointers are used just to
  6488. * free the memory during unload).
  6489. */
  6490. context_size = sizeof(union cdu_context) * BNX2X_L2_CID_COUNT(bp);
  6491. for (i = 0, allocated = 0; allocated < context_size; i++) {
  6492. bp->context[i].size = min(CDU_ILT_PAGE_SZ,
  6493. (context_size - allocated));
  6494. BNX2X_PCI_ALLOC(bp->context[i].vcxt,
  6495. &bp->context[i].cxt_mapping,
  6496. bp->context[i].size);
  6497. allocated += bp->context[i].size;
  6498. }
  6499. BNX2X_ALLOC(bp->ilt->lines, sizeof(struct ilt_line) * ILT_MAX_LINES);
  6500. if (bnx2x_ilt_mem_op(bp, ILT_MEMOP_ALLOC))
  6501. goto alloc_mem_err;
  6502. if (bnx2x_iov_alloc_mem(bp))
  6503. goto alloc_mem_err;
  6504. /* Slow path ring */
  6505. BNX2X_PCI_ALLOC(bp->spq, &bp->spq_mapping, BCM_PAGE_SIZE);
  6506. /* EQ */
  6507. BNX2X_PCI_ALLOC(bp->eq_ring, &bp->eq_mapping,
  6508. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  6509. return 0;
  6510. alloc_mem_err:
  6511. bnx2x_free_mem(bp);
  6512. BNX2X_ERR("Can't allocate memory\n");
  6513. return -ENOMEM;
  6514. }
  6515. /*
  6516. * Init service functions
  6517. */
  6518. int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac,
  6519. struct bnx2x_vlan_mac_obj *obj, bool set,
  6520. int mac_type, unsigned long *ramrod_flags)
  6521. {
  6522. int rc;
  6523. struct bnx2x_vlan_mac_ramrod_params ramrod_param;
  6524. memset(&ramrod_param, 0, sizeof(ramrod_param));
  6525. /* Fill general parameters */
  6526. ramrod_param.vlan_mac_obj = obj;
  6527. ramrod_param.ramrod_flags = *ramrod_flags;
  6528. /* Fill a user request section if needed */
  6529. if (!test_bit(RAMROD_CONT, ramrod_flags)) {
  6530. memcpy(ramrod_param.user_req.u.mac.mac, mac, ETH_ALEN);
  6531. __set_bit(mac_type, &ramrod_param.user_req.vlan_mac_flags);
  6532. /* Set the command: ADD or DEL */
  6533. if (set)
  6534. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD;
  6535. else
  6536. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_DEL;
  6537. }
  6538. rc = bnx2x_config_vlan_mac(bp, &ramrod_param);
  6539. if (rc == -EEXIST) {
  6540. DP(BNX2X_MSG_SP, "Failed to schedule ADD operations: %d\n", rc);
  6541. /* do not treat adding same MAC as error */
  6542. rc = 0;
  6543. } else if (rc < 0)
  6544. BNX2X_ERR("%s MAC failed\n", (set ? "Set" : "Del"));
  6545. return rc;
  6546. }
  6547. int bnx2x_del_all_macs(struct bnx2x *bp,
  6548. struct bnx2x_vlan_mac_obj *mac_obj,
  6549. int mac_type, bool wait_for_comp)
  6550. {
  6551. int rc;
  6552. unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
  6553. /* Wait for completion of requested */
  6554. if (wait_for_comp)
  6555. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  6556. /* Set the mac type of addresses we want to clear */
  6557. __set_bit(mac_type, &vlan_mac_flags);
  6558. rc = mac_obj->delete_all(bp, mac_obj, &vlan_mac_flags, &ramrod_flags);
  6559. if (rc < 0)
  6560. BNX2X_ERR("Failed to delete MACs: %d\n", rc);
  6561. return rc;
  6562. }
  6563. int bnx2x_set_eth_mac(struct bnx2x *bp, bool set)
  6564. {
  6565. unsigned long ramrod_flags = 0;
  6566. if (is_zero_ether_addr(bp->dev->dev_addr) &&
  6567. (IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp))) {
  6568. DP(NETIF_MSG_IFUP | NETIF_MSG_IFDOWN,
  6569. "Ignoring Zero MAC for STORAGE SD mode\n");
  6570. return 0;
  6571. }
  6572. DP(NETIF_MSG_IFUP, "Adding Eth MAC\n");
  6573. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  6574. /* Eth MAC is set on RSS leading client (fp[0]) */
  6575. return bnx2x_set_mac_one(bp, bp->dev->dev_addr, &bp->sp_objs->mac_obj,
  6576. set, BNX2X_ETH_MAC, &ramrod_flags);
  6577. }
  6578. int bnx2x_setup_leading(struct bnx2x *bp)
  6579. {
  6580. return bnx2x_setup_queue(bp, &bp->fp[0], 1);
  6581. }
  6582. /**
  6583. * bnx2x_set_int_mode - configure interrupt mode
  6584. *
  6585. * @bp: driver handle
  6586. *
  6587. * In case of MSI-X it will also try to enable MSI-X.
  6588. */
  6589. int bnx2x_set_int_mode(struct bnx2x *bp)
  6590. {
  6591. int rc = 0;
  6592. if (IS_VF(bp) && int_mode != BNX2X_INT_MODE_MSIX)
  6593. return -EINVAL;
  6594. switch (int_mode) {
  6595. case BNX2X_INT_MODE_MSIX:
  6596. /* attempt to enable msix */
  6597. rc = bnx2x_enable_msix(bp);
  6598. /* msix attained */
  6599. if (!rc)
  6600. return 0;
  6601. /* vfs use only msix */
  6602. if (rc && IS_VF(bp))
  6603. return rc;
  6604. /* failed to enable multiple MSI-X */
  6605. BNX2X_DEV_INFO("Failed to enable multiple MSI-X (%d), set number of queues to %d\n",
  6606. bp->num_queues,
  6607. 1 + bp->num_cnic_queues);
  6608. /* falling through... */
  6609. case BNX2X_INT_MODE_MSI:
  6610. bnx2x_enable_msi(bp);
  6611. /* falling through... */
  6612. case BNX2X_INT_MODE_INTX:
  6613. bp->num_ethernet_queues = 1;
  6614. bp->num_queues = bp->num_ethernet_queues + bp->num_cnic_queues;
  6615. BNX2X_DEV_INFO("set number of queues to 1\n");
  6616. break;
  6617. default:
  6618. BNX2X_DEV_INFO("unknown value in int_mode module parameter\n");
  6619. return -EINVAL;
  6620. }
  6621. return 0;
  6622. }
  6623. /* must be called prior to any HW initializations */
  6624. static inline u16 bnx2x_cid_ilt_lines(struct bnx2x *bp)
  6625. {
  6626. if (IS_SRIOV(bp))
  6627. return (BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)/ILT_PAGE_CIDS;
  6628. return L2_ILT_LINES(bp);
  6629. }
  6630. void bnx2x_ilt_set_info(struct bnx2x *bp)
  6631. {
  6632. struct ilt_client_info *ilt_client;
  6633. struct bnx2x_ilt *ilt = BP_ILT(bp);
  6634. u16 line = 0;
  6635. ilt->start_line = FUNC_ILT_BASE(BP_FUNC(bp));
  6636. DP(BNX2X_MSG_SP, "ilt starts at line %d\n", ilt->start_line);
  6637. /* CDU */
  6638. ilt_client = &ilt->clients[ILT_CLIENT_CDU];
  6639. ilt_client->client_num = ILT_CLIENT_CDU;
  6640. ilt_client->page_size = CDU_ILT_PAGE_SZ;
  6641. ilt_client->flags = ILT_CLIENT_SKIP_MEM;
  6642. ilt_client->start = line;
  6643. line += bnx2x_cid_ilt_lines(bp);
  6644. if (CNIC_SUPPORT(bp))
  6645. line += CNIC_ILT_LINES;
  6646. ilt_client->end = line - 1;
  6647. DP(NETIF_MSG_IFUP, "ilt client[CDU]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6648. ilt_client->start,
  6649. ilt_client->end,
  6650. ilt_client->page_size,
  6651. ilt_client->flags,
  6652. ilog2(ilt_client->page_size >> 12));
  6653. /* QM */
  6654. if (QM_INIT(bp->qm_cid_count)) {
  6655. ilt_client = &ilt->clients[ILT_CLIENT_QM];
  6656. ilt_client->client_num = ILT_CLIENT_QM;
  6657. ilt_client->page_size = QM_ILT_PAGE_SZ;
  6658. ilt_client->flags = 0;
  6659. ilt_client->start = line;
  6660. /* 4 bytes for each cid */
  6661. line += DIV_ROUND_UP(bp->qm_cid_count * QM_QUEUES_PER_FUNC * 4,
  6662. QM_ILT_PAGE_SZ);
  6663. ilt_client->end = line - 1;
  6664. DP(NETIF_MSG_IFUP,
  6665. "ilt client[QM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6666. ilt_client->start,
  6667. ilt_client->end,
  6668. ilt_client->page_size,
  6669. ilt_client->flags,
  6670. ilog2(ilt_client->page_size >> 12));
  6671. }
  6672. if (CNIC_SUPPORT(bp)) {
  6673. /* SRC */
  6674. ilt_client = &ilt->clients[ILT_CLIENT_SRC];
  6675. ilt_client->client_num = ILT_CLIENT_SRC;
  6676. ilt_client->page_size = SRC_ILT_PAGE_SZ;
  6677. ilt_client->flags = 0;
  6678. ilt_client->start = line;
  6679. line += SRC_ILT_LINES;
  6680. ilt_client->end = line - 1;
  6681. DP(NETIF_MSG_IFUP,
  6682. "ilt client[SRC]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6683. ilt_client->start,
  6684. ilt_client->end,
  6685. ilt_client->page_size,
  6686. ilt_client->flags,
  6687. ilog2(ilt_client->page_size >> 12));
  6688. /* TM */
  6689. ilt_client = &ilt->clients[ILT_CLIENT_TM];
  6690. ilt_client->client_num = ILT_CLIENT_TM;
  6691. ilt_client->page_size = TM_ILT_PAGE_SZ;
  6692. ilt_client->flags = 0;
  6693. ilt_client->start = line;
  6694. line += TM_ILT_LINES;
  6695. ilt_client->end = line - 1;
  6696. DP(NETIF_MSG_IFUP,
  6697. "ilt client[TM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6698. ilt_client->start,
  6699. ilt_client->end,
  6700. ilt_client->page_size,
  6701. ilt_client->flags,
  6702. ilog2(ilt_client->page_size >> 12));
  6703. }
  6704. BUG_ON(line > ILT_MAX_LINES);
  6705. }
  6706. /**
  6707. * bnx2x_pf_q_prep_init - prepare INIT transition parameters
  6708. *
  6709. * @bp: driver handle
  6710. * @fp: pointer to fastpath
  6711. * @init_params: pointer to parameters structure
  6712. *
  6713. * parameters configured:
  6714. * - HC configuration
  6715. * - Queue's CDU context
  6716. */
  6717. static void bnx2x_pf_q_prep_init(struct bnx2x *bp,
  6718. struct bnx2x_fastpath *fp, struct bnx2x_queue_init_params *init_params)
  6719. {
  6720. u8 cos;
  6721. int cxt_index, cxt_offset;
  6722. /* FCoE Queue uses Default SB, thus has no HC capabilities */
  6723. if (!IS_FCOE_FP(fp)) {
  6724. __set_bit(BNX2X_Q_FLG_HC, &init_params->rx.flags);
  6725. __set_bit(BNX2X_Q_FLG_HC, &init_params->tx.flags);
  6726. /* If HC is supporterd, enable host coalescing in the transition
  6727. * to INIT state.
  6728. */
  6729. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->rx.flags);
  6730. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->tx.flags);
  6731. /* HC rate */
  6732. init_params->rx.hc_rate = bp->rx_ticks ?
  6733. (1000000 / bp->rx_ticks) : 0;
  6734. init_params->tx.hc_rate = bp->tx_ticks ?
  6735. (1000000 / bp->tx_ticks) : 0;
  6736. /* FW SB ID */
  6737. init_params->rx.fw_sb_id = init_params->tx.fw_sb_id =
  6738. fp->fw_sb_id;
  6739. /*
  6740. * CQ index among the SB indices: FCoE clients uses the default
  6741. * SB, therefore it's different.
  6742. */
  6743. init_params->rx.sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  6744. init_params->tx.sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS;
  6745. }
  6746. /* set maximum number of COSs supported by this queue */
  6747. init_params->max_cos = fp->max_cos;
  6748. DP(NETIF_MSG_IFUP, "fp: %d setting queue params max cos to: %d\n",
  6749. fp->index, init_params->max_cos);
  6750. /* set the context pointers queue object */
  6751. for (cos = FIRST_TX_COS_INDEX; cos < init_params->max_cos; cos++) {
  6752. cxt_index = fp->txdata_ptr[cos]->cid / ILT_PAGE_CIDS;
  6753. cxt_offset = fp->txdata_ptr[cos]->cid - (cxt_index *
  6754. ILT_PAGE_CIDS);
  6755. init_params->cxts[cos] =
  6756. &bp->context[cxt_index].vcxt[cxt_offset].eth;
  6757. }
  6758. }
  6759. static int bnx2x_setup_tx_only(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  6760. struct bnx2x_queue_state_params *q_params,
  6761. struct bnx2x_queue_setup_tx_only_params *tx_only_params,
  6762. int tx_index, bool leading)
  6763. {
  6764. memset(tx_only_params, 0, sizeof(*tx_only_params));
  6765. /* Set the command */
  6766. q_params->cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  6767. /* Set tx-only QUEUE flags: don't zero statistics */
  6768. tx_only_params->flags = bnx2x_get_common_flags(bp, fp, false);
  6769. /* choose the index of the cid to send the slow path on */
  6770. tx_only_params->cid_index = tx_index;
  6771. /* Set general TX_ONLY_SETUP parameters */
  6772. bnx2x_pf_q_prep_general(bp, fp, &tx_only_params->gen_params, tx_index);
  6773. /* Set Tx TX_ONLY_SETUP parameters */
  6774. bnx2x_pf_tx_q_prep(bp, fp, &tx_only_params->txq_params, tx_index);
  6775. DP(NETIF_MSG_IFUP,
  6776. "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",
  6777. tx_index, q_params->q_obj->cids[FIRST_TX_COS_INDEX],
  6778. q_params->q_obj->cids[tx_index], q_params->q_obj->cl_id,
  6779. tx_only_params->gen_params.spcl_id, tx_only_params->flags);
  6780. /* send the ramrod */
  6781. return bnx2x_queue_state_change(bp, q_params);
  6782. }
  6783. /**
  6784. * bnx2x_setup_queue - setup queue
  6785. *
  6786. * @bp: driver handle
  6787. * @fp: pointer to fastpath
  6788. * @leading: is leading
  6789. *
  6790. * This function performs 2 steps in a Queue state machine
  6791. * actually: 1) RESET->INIT 2) INIT->SETUP
  6792. */
  6793. int bnx2x_setup_queue(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  6794. bool leading)
  6795. {
  6796. struct bnx2x_queue_state_params q_params = {NULL};
  6797. struct bnx2x_queue_setup_params *setup_params =
  6798. &q_params.params.setup;
  6799. struct bnx2x_queue_setup_tx_only_params *tx_only_params =
  6800. &q_params.params.tx_only;
  6801. int rc;
  6802. u8 tx_index;
  6803. DP(NETIF_MSG_IFUP, "setting up queue %d\n", fp->index);
  6804. /* reset IGU state skip FCoE L2 queue */
  6805. if (!IS_FCOE_FP(fp))
  6806. bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID, 0,
  6807. IGU_INT_ENABLE, 0);
  6808. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  6809. /* We want to wait for completion in this context */
  6810. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  6811. /* Prepare the INIT parameters */
  6812. bnx2x_pf_q_prep_init(bp, fp, &q_params.params.init);
  6813. /* Set the command */
  6814. q_params.cmd = BNX2X_Q_CMD_INIT;
  6815. /* Change the state to INIT */
  6816. rc = bnx2x_queue_state_change(bp, &q_params);
  6817. if (rc) {
  6818. BNX2X_ERR("Queue(%d) INIT failed\n", fp->index);
  6819. return rc;
  6820. }
  6821. DP(NETIF_MSG_IFUP, "init complete\n");
  6822. /* Now move the Queue to the SETUP state... */
  6823. memset(setup_params, 0, sizeof(*setup_params));
  6824. /* Set QUEUE flags */
  6825. setup_params->flags = bnx2x_get_q_flags(bp, fp, leading);
  6826. /* Set general SETUP parameters */
  6827. bnx2x_pf_q_prep_general(bp, fp, &setup_params->gen_params,
  6828. FIRST_TX_COS_INDEX);
  6829. bnx2x_pf_rx_q_prep(bp, fp, &setup_params->pause_params,
  6830. &setup_params->rxq_params);
  6831. bnx2x_pf_tx_q_prep(bp, fp, &setup_params->txq_params,
  6832. FIRST_TX_COS_INDEX);
  6833. /* Set the command */
  6834. q_params.cmd = BNX2X_Q_CMD_SETUP;
  6835. if (IS_FCOE_FP(fp))
  6836. bp->fcoe_init = true;
  6837. /* Change the state to SETUP */
  6838. rc = bnx2x_queue_state_change(bp, &q_params);
  6839. if (rc) {
  6840. BNX2X_ERR("Queue(%d) SETUP failed\n", fp->index);
  6841. return rc;
  6842. }
  6843. /* loop through the relevant tx-only indices */
  6844. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  6845. tx_index < fp->max_cos;
  6846. tx_index++) {
  6847. /* prepare and send tx-only ramrod*/
  6848. rc = bnx2x_setup_tx_only(bp, fp, &q_params,
  6849. tx_only_params, tx_index, leading);
  6850. if (rc) {
  6851. BNX2X_ERR("Queue(%d.%d) TX_ONLY_SETUP failed\n",
  6852. fp->index, tx_index);
  6853. return rc;
  6854. }
  6855. }
  6856. return rc;
  6857. }
  6858. static int bnx2x_stop_queue(struct bnx2x *bp, int index)
  6859. {
  6860. struct bnx2x_fastpath *fp = &bp->fp[index];
  6861. struct bnx2x_fp_txdata *txdata;
  6862. struct bnx2x_queue_state_params q_params = {NULL};
  6863. int rc, tx_index;
  6864. DP(NETIF_MSG_IFDOWN, "stopping queue %d cid %d\n", index, fp->cid);
  6865. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  6866. /* We want to wait for completion in this context */
  6867. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  6868. /* close tx-only connections */
  6869. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  6870. tx_index < fp->max_cos;
  6871. tx_index++){
  6872. /* ascertain this is a normal queue*/
  6873. txdata = fp->txdata_ptr[tx_index];
  6874. DP(NETIF_MSG_IFDOWN, "stopping tx-only queue %d\n",
  6875. txdata->txq_index);
  6876. /* send halt terminate on tx-only connection */
  6877. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  6878. memset(&q_params.params.terminate, 0,
  6879. sizeof(q_params.params.terminate));
  6880. q_params.params.terminate.cid_index = tx_index;
  6881. rc = bnx2x_queue_state_change(bp, &q_params);
  6882. if (rc)
  6883. return rc;
  6884. /* send halt terminate on tx-only connection */
  6885. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  6886. memset(&q_params.params.cfc_del, 0,
  6887. sizeof(q_params.params.cfc_del));
  6888. q_params.params.cfc_del.cid_index = tx_index;
  6889. rc = bnx2x_queue_state_change(bp, &q_params);
  6890. if (rc)
  6891. return rc;
  6892. }
  6893. /* Stop the primary connection: */
  6894. /* ...halt the connection */
  6895. q_params.cmd = BNX2X_Q_CMD_HALT;
  6896. rc = bnx2x_queue_state_change(bp, &q_params);
  6897. if (rc)
  6898. return rc;
  6899. /* ...terminate the connection */
  6900. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  6901. memset(&q_params.params.terminate, 0,
  6902. sizeof(q_params.params.terminate));
  6903. q_params.params.terminate.cid_index = FIRST_TX_COS_INDEX;
  6904. rc = bnx2x_queue_state_change(bp, &q_params);
  6905. if (rc)
  6906. return rc;
  6907. /* ...delete cfc entry */
  6908. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  6909. memset(&q_params.params.cfc_del, 0,
  6910. sizeof(q_params.params.cfc_del));
  6911. q_params.params.cfc_del.cid_index = FIRST_TX_COS_INDEX;
  6912. return bnx2x_queue_state_change(bp, &q_params);
  6913. }
  6914. static void bnx2x_reset_func(struct bnx2x *bp)
  6915. {
  6916. int port = BP_PORT(bp);
  6917. int func = BP_FUNC(bp);
  6918. int i;
  6919. /* Disable the function in the FW */
  6920. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0);
  6921. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0);
  6922. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0);
  6923. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0);
  6924. /* FP SBs */
  6925. for_each_eth_queue(bp, i) {
  6926. struct bnx2x_fastpath *fp = &bp->fp[i];
  6927. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6928. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id),
  6929. SB_DISABLED);
  6930. }
  6931. if (CNIC_LOADED(bp))
  6932. /* CNIC SB */
  6933. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6934. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET
  6935. (bnx2x_cnic_fw_sb_id(bp)), SB_DISABLED);
  6936. /* SP SB */
  6937. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6938. CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func),
  6939. SB_DISABLED);
  6940. for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++)
  6941. REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func),
  6942. 0);
  6943. /* Configure IGU */
  6944. if (bp->common.int_block == INT_BLOCK_HC) {
  6945. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  6946. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  6947. } else {
  6948. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  6949. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  6950. }
  6951. if (CNIC_LOADED(bp)) {
  6952. /* Disable Timer scan */
  6953. REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 0);
  6954. /*
  6955. * Wait for at least 10ms and up to 2 second for the timers
  6956. * scan to complete
  6957. */
  6958. for (i = 0; i < 200; i++) {
  6959. msleep(10);
  6960. if (!REG_RD(bp, TM_REG_LIN0_SCAN_ON + port*4))
  6961. break;
  6962. }
  6963. }
  6964. /* Clear ILT */
  6965. bnx2x_clear_func_ilt(bp, func);
  6966. /* Timers workaround bug for E2: if this is vnic-3,
  6967. * we need to set the entire ilt range for this timers.
  6968. */
  6969. if (!CHIP_IS_E1x(bp) && BP_VN(bp) == 3) {
  6970. struct ilt_client_info ilt_cli;
  6971. /* use dummy TM client */
  6972. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  6973. ilt_cli.start = 0;
  6974. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  6975. ilt_cli.client_num = ILT_CLIENT_TM;
  6976. bnx2x_ilt_boundry_init_op(bp, &ilt_cli, 0, INITOP_CLEAR);
  6977. }
  6978. /* this assumes that reset_port() called before reset_func()*/
  6979. if (!CHIP_IS_E1x(bp))
  6980. bnx2x_pf_disable(bp);
  6981. bp->dmae_ready = 0;
  6982. }
  6983. static void bnx2x_reset_port(struct bnx2x *bp)
  6984. {
  6985. int port = BP_PORT(bp);
  6986. u32 val;
  6987. /* Reset physical Link */
  6988. bnx2x__link_reset(bp);
  6989. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  6990. /* Do not rcv packets to BRB */
  6991. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0);
  6992. /* Do not direct rcv packets that are not for MCP to the BRB */
  6993. REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
  6994. NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
  6995. /* Configure AEU */
  6996. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0);
  6997. msleep(100);
  6998. /* Check for BRB port occupancy */
  6999. val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4);
  7000. if (val)
  7001. DP(NETIF_MSG_IFDOWN,
  7002. "BRB1 is not empty %d blocks are occupied\n", val);
  7003. /* TODO: Close Doorbell port? */
  7004. }
  7005. static int bnx2x_reset_hw(struct bnx2x *bp, u32 load_code)
  7006. {
  7007. struct bnx2x_func_state_params func_params = {NULL};
  7008. /* Prepare parameters for function state transitions */
  7009. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  7010. func_params.f_obj = &bp->func_obj;
  7011. func_params.cmd = BNX2X_F_CMD_HW_RESET;
  7012. func_params.params.hw_init.load_phase = load_code;
  7013. return bnx2x_func_state_change(bp, &func_params);
  7014. }
  7015. static int bnx2x_func_stop(struct bnx2x *bp)
  7016. {
  7017. struct bnx2x_func_state_params func_params = {NULL};
  7018. int rc;
  7019. /* Prepare parameters for function state transitions */
  7020. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  7021. func_params.f_obj = &bp->func_obj;
  7022. func_params.cmd = BNX2X_F_CMD_STOP;
  7023. /*
  7024. * Try to stop the function the 'good way'. If fails (in case
  7025. * of a parity error during bnx2x_chip_cleanup()) and we are
  7026. * not in a debug mode, perform a state transaction in order to
  7027. * enable further HW_RESET transaction.
  7028. */
  7029. rc = bnx2x_func_state_change(bp, &func_params);
  7030. if (rc) {
  7031. #ifdef BNX2X_STOP_ON_ERROR
  7032. return rc;
  7033. #else
  7034. BNX2X_ERR("FUNC_STOP ramrod failed. Running a dry transaction\n");
  7035. __set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags);
  7036. return bnx2x_func_state_change(bp, &func_params);
  7037. #endif
  7038. }
  7039. return 0;
  7040. }
  7041. /**
  7042. * bnx2x_send_unload_req - request unload mode from the MCP.
  7043. *
  7044. * @bp: driver handle
  7045. * @unload_mode: requested function's unload mode
  7046. *
  7047. * Return unload mode returned by the MCP: COMMON, PORT or FUNC.
  7048. */
  7049. u32 bnx2x_send_unload_req(struct bnx2x *bp, int unload_mode)
  7050. {
  7051. u32 reset_code = 0;
  7052. int port = BP_PORT(bp);
  7053. /* Select the UNLOAD request mode */
  7054. if (unload_mode == UNLOAD_NORMAL)
  7055. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  7056. else if (bp->flags & NO_WOL_FLAG)
  7057. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP;
  7058. else if (bp->wol) {
  7059. u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
  7060. u8 *mac_addr = bp->dev->dev_addr;
  7061. u32 val;
  7062. u16 pmc;
  7063. /* The mac address is written to entries 1-4 to
  7064. * preserve entry 0 which is used by the PMF
  7065. */
  7066. u8 entry = (BP_VN(bp) + 1)*8;
  7067. val = (mac_addr[0] << 8) | mac_addr[1];
  7068. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val);
  7069. val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
  7070. (mac_addr[4] << 8) | mac_addr[5];
  7071. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val);
  7072. /* Enable the PME and clear the status */
  7073. pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, &pmc);
  7074. pmc |= PCI_PM_CTRL_PME_ENABLE | PCI_PM_CTRL_PME_STATUS;
  7075. pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, pmc);
  7076. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN;
  7077. } else
  7078. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  7079. /* Send the request to the MCP */
  7080. if (!BP_NOMCP(bp))
  7081. reset_code = bnx2x_fw_command(bp, reset_code, 0);
  7082. else {
  7083. int path = BP_PATH(bp);
  7084. DP(NETIF_MSG_IFDOWN, "NO MCP - load counts[%d] %d, %d, %d\n",
  7085. path, load_count[path][0], load_count[path][1],
  7086. load_count[path][2]);
  7087. load_count[path][0]--;
  7088. load_count[path][1 + port]--;
  7089. DP(NETIF_MSG_IFDOWN, "NO MCP - new load counts[%d] %d, %d, %d\n",
  7090. path, load_count[path][0], load_count[path][1],
  7091. load_count[path][2]);
  7092. if (load_count[path][0] == 0)
  7093. reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON;
  7094. else if (load_count[path][1 + port] == 0)
  7095. reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT;
  7096. else
  7097. reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION;
  7098. }
  7099. return reset_code;
  7100. }
  7101. /**
  7102. * bnx2x_send_unload_done - send UNLOAD_DONE command to the MCP.
  7103. *
  7104. * @bp: driver handle
  7105. * @keep_link: true iff link should be kept up
  7106. */
  7107. void bnx2x_send_unload_done(struct bnx2x *bp, bool keep_link)
  7108. {
  7109. u32 reset_param = keep_link ? DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET : 0;
  7110. /* Report UNLOAD_DONE to MCP */
  7111. if (!BP_NOMCP(bp))
  7112. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, reset_param);
  7113. }
  7114. static int bnx2x_func_wait_started(struct bnx2x *bp)
  7115. {
  7116. int tout = 50;
  7117. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  7118. if (!bp->port.pmf)
  7119. return 0;
  7120. /*
  7121. * (assumption: No Attention from MCP at this stage)
  7122. * PMF probably in the middle of TXdisable/enable transaction
  7123. * 1. Sync IRS for default SB
  7124. * 2. Sync SP queue - this guarantes us that attention handling started
  7125. * 3. Wait, that TXdisable/enable transaction completes
  7126. *
  7127. * 1+2 guranty that if DCBx attention was scheduled it already changed
  7128. * pending bit of transaction from STARTED-->TX_STOPPED, if we alredy
  7129. * received complettion for the transaction the state is TX_STOPPED.
  7130. * State will return to STARTED after completion of TX_STOPPED-->STARTED
  7131. * transaction.
  7132. */
  7133. /* make sure default SB ISR is done */
  7134. if (msix)
  7135. synchronize_irq(bp->msix_table[0].vector);
  7136. else
  7137. synchronize_irq(bp->pdev->irq);
  7138. flush_workqueue(bnx2x_wq);
  7139. while (bnx2x_func_get_state(bp, &bp->func_obj) !=
  7140. BNX2X_F_STATE_STARTED && tout--)
  7141. msleep(20);
  7142. if (bnx2x_func_get_state(bp, &bp->func_obj) !=
  7143. BNX2X_F_STATE_STARTED) {
  7144. #ifdef BNX2X_STOP_ON_ERROR
  7145. BNX2X_ERR("Wrong function state\n");
  7146. return -EBUSY;
  7147. #else
  7148. /*
  7149. * Failed to complete the transaction in a "good way"
  7150. * Force both transactions with CLR bit
  7151. */
  7152. struct bnx2x_func_state_params func_params = {NULL};
  7153. DP(NETIF_MSG_IFDOWN,
  7154. "Hmmm... unexpected function state! Forcing STARTED-->TX_ST0PPED-->STARTED\n");
  7155. func_params.f_obj = &bp->func_obj;
  7156. __set_bit(RAMROD_DRV_CLR_ONLY,
  7157. &func_params.ramrod_flags);
  7158. /* STARTED-->TX_ST0PPED */
  7159. func_params.cmd = BNX2X_F_CMD_TX_STOP;
  7160. bnx2x_func_state_change(bp, &func_params);
  7161. /* TX_ST0PPED-->STARTED */
  7162. func_params.cmd = BNX2X_F_CMD_TX_START;
  7163. return bnx2x_func_state_change(bp, &func_params);
  7164. #endif
  7165. }
  7166. return 0;
  7167. }
  7168. void bnx2x_chip_cleanup(struct bnx2x *bp, int unload_mode, bool keep_link)
  7169. {
  7170. int port = BP_PORT(bp);
  7171. int i, rc = 0;
  7172. u8 cos;
  7173. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  7174. u32 reset_code;
  7175. /* Wait until tx fastpath tasks complete */
  7176. for_each_tx_queue(bp, i) {
  7177. struct bnx2x_fastpath *fp = &bp->fp[i];
  7178. for_each_cos_in_tx_queue(fp, cos)
  7179. rc = bnx2x_clean_tx_queue(bp, fp->txdata_ptr[cos]);
  7180. #ifdef BNX2X_STOP_ON_ERROR
  7181. if (rc)
  7182. return;
  7183. #endif
  7184. }
  7185. /* Give HW time to discard old tx messages */
  7186. usleep_range(1000, 1000);
  7187. /* Clean all ETH MACs */
  7188. rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_ETH_MAC,
  7189. false);
  7190. if (rc < 0)
  7191. BNX2X_ERR("Failed to delete all ETH macs: %d\n", rc);
  7192. /* Clean up UC list */
  7193. rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_UC_LIST_MAC,
  7194. true);
  7195. if (rc < 0)
  7196. BNX2X_ERR("Failed to schedule DEL commands for UC MACs list: %d\n",
  7197. rc);
  7198. /* Disable LLH */
  7199. if (!CHIP_IS_E1(bp))
  7200. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  7201. /* Set "drop all" (stop Rx).
  7202. * We need to take a netif_addr_lock() here in order to prevent
  7203. * a race between the completion code and this code.
  7204. */
  7205. netif_addr_lock_bh(bp->dev);
  7206. /* Schedule the rx_mode command */
  7207. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  7208. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  7209. else
  7210. bnx2x_set_storm_rx_mode(bp);
  7211. /* Cleanup multicast configuration */
  7212. rparam.mcast_obj = &bp->mcast_obj;
  7213. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  7214. if (rc < 0)
  7215. BNX2X_ERR("Failed to send DEL multicast command: %d\n", rc);
  7216. netif_addr_unlock_bh(bp->dev);
  7217. bnx2x_iov_chip_cleanup(bp);
  7218. /*
  7219. * Send the UNLOAD_REQUEST to the MCP. This will return if
  7220. * this function should perform FUNC, PORT or COMMON HW
  7221. * reset.
  7222. */
  7223. reset_code = bnx2x_send_unload_req(bp, unload_mode);
  7224. /*
  7225. * (assumption: No Attention from MCP at this stage)
  7226. * PMF probably in the middle of TXdisable/enable transaction
  7227. */
  7228. rc = bnx2x_func_wait_started(bp);
  7229. if (rc) {
  7230. BNX2X_ERR("bnx2x_func_wait_started failed\n");
  7231. #ifdef BNX2X_STOP_ON_ERROR
  7232. return;
  7233. #endif
  7234. }
  7235. /* Close multi and leading connections
  7236. * Completions for ramrods are collected in a synchronous way
  7237. */
  7238. for_each_eth_queue(bp, i)
  7239. if (bnx2x_stop_queue(bp, i))
  7240. #ifdef BNX2X_STOP_ON_ERROR
  7241. return;
  7242. #else
  7243. goto unload_error;
  7244. #endif
  7245. if (CNIC_LOADED(bp)) {
  7246. for_each_cnic_queue(bp, i)
  7247. if (bnx2x_stop_queue(bp, i))
  7248. #ifdef BNX2X_STOP_ON_ERROR
  7249. return;
  7250. #else
  7251. goto unload_error;
  7252. #endif
  7253. }
  7254. /* If SP settings didn't get completed so far - something
  7255. * very wrong has happen.
  7256. */
  7257. if (!bnx2x_wait_sp_comp(bp, ~0x0UL))
  7258. BNX2X_ERR("Hmmm... Common slow path ramrods got stuck!\n");
  7259. #ifndef BNX2X_STOP_ON_ERROR
  7260. unload_error:
  7261. #endif
  7262. rc = bnx2x_func_stop(bp);
  7263. if (rc) {
  7264. BNX2X_ERR("Function stop failed!\n");
  7265. #ifdef BNX2X_STOP_ON_ERROR
  7266. return;
  7267. #endif
  7268. }
  7269. /* Disable HW interrupts, NAPI */
  7270. bnx2x_netif_stop(bp, 1);
  7271. /* Delete all NAPI objects */
  7272. bnx2x_del_all_napi(bp);
  7273. if (CNIC_LOADED(bp))
  7274. bnx2x_del_all_napi_cnic(bp);
  7275. /* Release IRQs */
  7276. bnx2x_free_irq(bp);
  7277. /* Reset the chip */
  7278. rc = bnx2x_reset_hw(bp, reset_code);
  7279. if (rc)
  7280. BNX2X_ERR("HW_RESET failed\n");
  7281. /* Report UNLOAD_DONE to MCP */
  7282. bnx2x_send_unload_done(bp, keep_link);
  7283. }
  7284. void bnx2x_disable_close_the_gate(struct bnx2x *bp)
  7285. {
  7286. u32 val;
  7287. DP(NETIF_MSG_IFDOWN, "Disabling \"close the gates\"\n");
  7288. if (CHIP_IS_E1(bp)) {
  7289. int port = BP_PORT(bp);
  7290. u32 addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  7291. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  7292. val = REG_RD(bp, addr);
  7293. val &= ~(0x300);
  7294. REG_WR(bp, addr, val);
  7295. } else {
  7296. val = REG_RD(bp, MISC_REG_AEU_GENERAL_MASK);
  7297. val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK |
  7298. MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK);
  7299. REG_WR(bp, MISC_REG_AEU_GENERAL_MASK, val);
  7300. }
  7301. }
  7302. /* Close gates #2, #3 and #4: */
  7303. static void bnx2x_set_234_gates(struct bnx2x *bp, bool close)
  7304. {
  7305. u32 val;
  7306. /* Gates #2 and #4a are closed/opened for "not E1" only */
  7307. if (!CHIP_IS_E1(bp)) {
  7308. /* #4 */
  7309. REG_WR(bp, PXP_REG_HST_DISCARD_DOORBELLS, !!close);
  7310. /* #2 */
  7311. REG_WR(bp, PXP_REG_HST_DISCARD_INTERNAL_WRITES, !!close);
  7312. }
  7313. /* #3 */
  7314. if (CHIP_IS_E1x(bp)) {
  7315. /* Prevent interrupts from HC on both ports */
  7316. val = REG_RD(bp, HC_REG_CONFIG_1);
  7317. REG_WR(bp, HC_REG_CONFIG_1,
  7318. (!close) ? (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1) :
  7319. (val & ~(u32)HC_CONFIG_1_REG_BLOCK_DISABLE_1));
  7320. val = REG_RD(bp, HC_REG_CONFIG_0);
  7321. REG_WR(bp, HC_REG_CONFIG_0,
  7322. (!close) ? (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0) :
  7323. (val & ~(u32)HC_CONFIG_0_REG_BLOCK_DISABLE_0));
  7324. } else {
  7325. /* Prevent incomming interrupts in IGU */
  7326. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  7327. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION,
  7328. (!close) ?
  7329. (val | IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE) :
  7330. (val & ~(u32)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE));
  7331. }
  7332. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "%s gates #2, #3 and #4\n",
  7333. close ? "closing" : "opening");
  7334. mmiowb();
  7335. }
  7336. #define SHARED_MF_CLP_MAGIC 0x80000000 /* `magic' bit */
  7337. static void bnx2x_clp_reset_prep(struct bnx2x *bp, u32 *magic_val)
  7338. {
  7339. /* Do some magic... */
  7340. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  7341. *magic_val = val & SHARED_MF_CLP_MAGIC;
  7342. MF_CFG_WR(bp, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC);
  7343. }
  7344. /**
  7345. * bnx2x_clp_reset_done - restore the value of the `magic' bit.
  7346. *
  7347. * @bp: driver handle
  7348. * @magic_val: old value of the `magic' bit.
  7349. */
  7350. static void bnx2x_clp_reset_done(struct bnx2x *bp, u32 magic_val)
  7351. {
  7352. /* Restore the `magic' bit value... */
  7353. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  7354. MF_CFG_WR(bp, shared_mf_config.clp_mb,
  7355. (val & (~SHARED_MF_CLP_MAGIC)) | magic_val);
  7356. }
  7357. /**
  7358. * bnx2x_reset_mcp_prep - prepare for MCP reset.
  7359. *
  7360. * @bp: driver handle
  7361. * @magic_val: old value of 'magic' bit.
  7362. *
  7363. * Takes care of CLP configurations.
  7364. */
  7365. static void bnx2x_reset_mcp_prep(struct bnx2x *bp, u32 *magic_val)
  7366. {
  7367. u32 shmem;
  7368. u32 validity_offset;
  7369. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "Starting\n");
  7370. /* Set `magic' bit in order to save MF config */
  7371. if (!CHIP_IS_E1(bp))
  7372. bnx2x_clp_reset_prep(bp, magic_val);
  7373. /* Get shmem offset */
  7374. shmem = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  7375. validity_offset =
  7376. offsetof(struct shmem_region, validity_map[BP_PORT(bp)]);
  7377. /* Clear validity map flags */
  7378. if (shmem > 0)
  7379. REG_WR(bp, shmem + validity_offset, 0);
  7380. }
  7381. #define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */
  7382. #define MCP_ONE_TIMEOUT 100 /* 100 ms */
  7383. /**
  7384. * bnx2x_mcp_wait_one - wait for MCP_ONE_TIMEOUT
  7385. *
  7386. * @bp: driver handle
  7387. */
  7388. static void bnx2x_mcp_wait_one(struct bnx2x *bp)
  7389. {
  7390. /* special handling for emulation and FPGA,
  7391. wait 10 times longer */
  7392. if (CHIP_REV_IS_SLOW(bp))
  7393. msleep(MCP_ONE_TIMEOUT*10);
  7394. else
  7395. msleep(MCP_ONE_TIMEOUT);
  7396. }
  7397. /*
  7398. * initializes bp->common.shmem_base and waits for validity signature to appear
  7399. */
  7400. static int bnx2x_init_shmem(struct bnx2x *bp)
  7401. {
  7402. int cnt = 0;
  7403. u32 val = 0;
  7404. do {
  7405. bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  7406. if (bp->common.shmem_base) {
  7407. val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
  7408. if (val & SHR_MEM_VALIDITY_MB)
  7409. return 0;
  7410. }
  7411. bnx2x_mcp_wait_one(bp);
  7412. } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT));
  7413. BNX2X_ERR("BAD MCP validity signature\n");
  7414. return -ENODEV;
  7415. }
  7416. static int bnx2x_reset_mcp_comp(struct bnx2x *bp, u32 magic_val)
  7417. {
  7418. int rc = bnx2x_init_shmem(bp);
  7419. /* Restore the `magic' bit value */
  7420. if (!CHIP_IS_E1(bp))
  7421. bnx2x_clp_reset_done(bp, magic_val);
  7422. return rc;
  7423. }
  7424. static void bnx2x_pxp_prep(struct bnx2x *bp)
  7425. {
  7426. if (!CHIP_IS_E1(bp)) {
  7427. REG_WR(bp, PXP2_REG_RD_START_INIT, 0);
  7428. REG_WR(bp, PXP2_REG_RQ_RBC_DONE, 0);
  7429. mmiowb();
  7430. }
  7431. }
  7432. /*
  7433. * Reset the whole chip except for:
  7434. * - PCIE core
  7435. * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by
  7436. * one reset bit)
  7437. * - IGU
  7438. * - MISC (including AEU)
  7439. * - GRC
  7440. * - RBCN, RBCP
  7441. */
  7442. static void bnx2x_process_kill_chip_reset(struct bnx2x *bp, bool global)
  7443. {
  7444. u32 not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2;
  7445. u32 global_bits2, stay_reset2;
  7446. /*
  7447. * Bits that have to be set in reset_mask2 if we want to reset 'global'
  7448. * (per chip) blocks.
  7449. */
  7450. global_bits2 =
  7451. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU |
  7452. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE;
  7453. /* Don't reset the following blocks.
  7454. * Important: per port blocks (such as EMAC, BMAC, UMAC) can't be
  7455. * reset, as in 4 port device they might still be owned
  7456. * by the MCP (there is only one leader per path).
  7457. */
  7458. not_reset_mask1 =
  7459. MISC_REGISTERS_RESET_REG_1_RST_HC |
  7460. MISC_REGISTERS_RESET_REG_1_RST_PXPV |
  7461. MISC_REGISTERS_RESET_REG_1_RST_PXP;
  7462. not_reset_mask2 =
  7463. MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO |
  7464. MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE |
  7465. MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE |
  7466. MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE |
  7467. MISC_REGISTERS_RESET_REG_2_RST_RBCN |
  7468. MISC_REGISTERS_RESET_REG_2_RST_GRC |
  7469. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE |
  7470. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B |
  7471. MISC_REGISTERS_RESET_REG_2_RST_ATC |
  7472. MISC_REGISTERS_RESET_REG_2_PGLC |
  7473. MISC_REGISTERS_RESET_REG_2_RST_BMAC0 |
  7474. MISC_REGISTERS_RESET_REG_2_RST_BMAC1 |
  7475. MISC_REGISTERS_RESET_REG_2_RST_EMAC0 |
  7476. MISC_REGISTERS_RESET_REG_2_RST_EMAC1 |
  7477. MISC_REGISTERS_RESET_REG_2_UMAC0 |
  7478. MISC_REGISTERS_RESET_REG_2_UMAC1;
  7479. /*
  7480. * Keep the following blocks in reset:
  7481. * - all xxMACs are handled by the bnx2x_link code.
  7482. */
  7483. stay_reset2 =
  7484. MISC_REGISTERS_RESET_REG_2_XMAC |
  7485. MISC_REGISTERS_RESET_REG_2_XMAC_SOFT;
  7486. /* Full reset masks according to the chip */
  7487. reset_mask1 = 0xffffffff;
  7488. if (CHIP_IS_E1(bp))
  7489. reset_mask2 = 0xffff;
  7490. else if (CHIP_IS_E1H(bp))
  7491. reset_mask2 = 0x1ffff;
  7492. else if (CHIP_IS_E2(bp))
  7493. reset_mask2 = 0xfffff;
  7494. else /* CHIP_IS_E3 */
  7495. reset_mask2 = 0x3ffffff;
  7496. /* Don't reset global blocks unless we need to */
  7497. if (!global)
  7498. reset_mask2 &= ~global_bits2;
  7499. /*
  7500. * In case of attention in the QM, we need to reset PXP
  7501. * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM
  7502. * because otherwise QM reset would release 'close the gates' shortly
  7503. * before resetting the PXP, then the PSWRQ would send a write
  7504. * request to PGLUE. Then when PXP is reset, PGLUE would try to
  7505. * read the payload data from PSWWR, but PSWWR would not
  7506. * respond. The write queue in PGLUE would stuck, dmae commands
  7507. * would not return. Therefore it's important to reset the second
  7508. * reset register (containing the
  7509. * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the
  7510. * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM
  7511. * bit).
  7512. */
  7513. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
  7514. reset_mask2 & (~not_reset_mask2));
  7515. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  7516. reset_mask1 & (~not_reset_mask1));
  7517. barrier();
  7518. mmiowb();
  7519. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
  7520. reset_mask2 & (~stay_reset2));
  7521. barrier();
  7522. mmiowb();
  7523. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1);
  7524. mmiowb();
  7525. }
  7526. /**
  7527. * bnx2x_er_poll_igu_vq - poll for pending writes bit.
  7528. * It should get cleared in no more than 1s.
  7529. *
  7530. * @bp: driver handle
  7531. *
  7532. * It should get cleared in no more than 1s. Returns 0 if
  7533. * pending writes bit gets cleared.
  7534. */
  7535. static int bnx2x_er_poll_igu_vq(struct bnx2x *bp)
  7536. {
  7537. u32 cnt = 1000;
  7538. u32 pend_bits = 0;
  7539. do {
  7540. pend_bits = REG_RD(bp, IGU_REG_PENDING_BITS_STATUS);
  7541. if (pend_bits == 0)
  7542. break;
  7543. usleep_range(1000, 1000);
  7544. } while (cnt-- > 0);
  7545. if (cnt <= 0) {
  7546. BNX2X_ERR("Still pending IGU requests pend_bits=%x!\n",
  7547. pend_bits);
  7548. return -EBUSY;
  7549. }
  7550. return 0;
  7551. }
  7552. static int bnx2x_process_kill(struct bnx2x *bp, bool global)
  7553. {
  7554. int cnt = 1000;
  7555. u32 val = 0;
  7556. u32 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2;
  7557. u32 tags_63_32 = 0;
  7558. /* Empty the Tetris buffer, wait for 1s */
  7559. do {
  7560. sr_cnt = REG_RD(bp, PXP2_REG_RD_SR_CNT);
  7561. blk_cnt = REG_RD(bp, PXP2_REG_RD_BLK_CNT);
  7562. port_is_idle_0 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_0);
  7563. port_is_idle_1 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_1);
  7564. pgl_exp_rom2 = REG_RD(bp, PXP2_REG_PGL_EXP_ROM2);
  7565. if (CHIP_IS_E3(bp))
  7566. tags_63_32 = REG_RD(bp, PGLUE_B_REG_TAGS_63_32);
  7567. if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) &&
  7568. ((port_is_idle_0 & 0x1) == 0x1) &&
  7569. ((port_is_idle_1 & 0x1) == 0x1) &&
  7570. (pgl_exp_rom2 == 0xffffffff) &&
  7571. (!CHIP_IS_E3(bp) || (tags_63_32 == 0xffffffff)))
  7572. break;
  7573. usleep_range(1000, 1000);
  7574. } while (cnt-- > 0);
  7575. if (cnt <= 0) {
  7576. BNX2X_ERR("Tetris buffer didn't get empty or there are still outstanding read requests after 1s!\n");
  7577. 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",
  7578. sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1,
  7579. pgl_exp_rom2);
  7580. return -EAGAIN;
  7581. }
  7582. barrier();
  7583. /* Close gates #2, #3 and #4 */
  7584. bnx2x_set_234_gates(bp, true);
  7585. /* Poll for IGU VQs for 57712 and newer chips */
  7586. if (!CHIP_IS_E1x(bp) && bnx2x_er_poll_igu_vq(bp))
  7587. return -EAGAIN;
  7588. /* TBD: Indicate that "process kill" is in progress to MCP */
  7589. /* Clear "unprepared" bit */
  7590. REG_WR(bp, MISC_REG_UNPREPARED, 0);
  7591. barrier();
  7592. /* Make sure all is written to the chip before the reset */
  7593. mmiowb();
  7594. /* Wait for 1ms to empty GLUE and PCI-E core queues,
  7595. * PSWHST, GRC and PSWRD Tetris buffer.
  7596. */
  7597. usleep_range(1000, 1000);
  7598. /* Prepare to chip reset: */
  7599. /* MCP */
  7600. if (global)
  7601. bnx2x_reset_mcp_prep(bp, &val);
  7602. /* PXP */
  7603. bnx2x_pxp_prep(bp);
  7604. barrier();
  7605. /* reset the chip */
  7606. bnx2x_process_kill_chip_reset(bp, global);
  7607. barrier();
  7608. /* Recover after reset: */
  7609. /* MCP */
  7610. if (global && bnx2x_reset_mcp_comp(bp, val))
  7611. return -EAGAIN;
  7612. /* TBD: Add resetting the NO_MCP mode DB here */
  7613. /* Open the gates #2, #3 and #4 */
  7614. bnx2x_set_234_gates(bp, false);
  7615. /* TBD: IGU/AEU preparation bring back the AEU/IGU to a
  7616. * reset state, re-enable attentions. */
  7617. return 0;
  7618. }
  7619. static int bnx2x_leader_reset(struct bnx2x *bp)
  7620. {
  7621. int rc = 0;
  7622. bool global = bnx2x_reset_is_global(bp);
  7623. u32 load_code;
  7624. /* if not going to reset MCP - load "fake" driver to reset HW while
  7625. * driver is owner of the HW
  7626. */
  7627. if (!global && !BP_NOMCP(bp)) {
  7628. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_REQ,
  7629. DRV_MSG_CODE_LOAD_REQ_WITH_LFA);
  7630. if (!load_code) {
  7631. BNX2X_ERR("MCP response failure, aborting\n");
  7632. rc = -EAGAIN;
  7633. goto exit_leader_reset;
  7634. }
  7635. if ((load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) &&
  7636. (load_code != FW_MSG_CODE_DRV_LOAD_COMMON)) {
  7637. BNX2X_ERR("MCP unexpected resp, aborting\n");
  7638. rc = -EAGAIN;
  7639. goto exit_leader_reset2;
  7640. }
  7641. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE, 0);
  7642. if (!load_code) {
  7643. BNX2X_ERR("MCP response failure, aborting\n");
  7644. rc = -EAGAIN;
  7645. goto exit_leader_reset2;
  7646. }
  7647. }
  7648. /* Try to recover after the failure */
  7649. if (bnx2x_process_kill(bp, global)) {
  7650. BNX2X_ERR("Something bad had happen on engine %d! Aii!\n",
  7651. BP_PATH(bp));
  7652. rc = -EAGAIN;
  7653. goto exit_leader_reset2;
  7654. }
  7655. /*
  7656. * Clear RESET_IN_PROGRES and RESET_GLOBAL bits and update the driver
  7657. * state.
  7658. */
  7659. bnx2x_set_reset_done(bp);
  7660. if (global)
  7661. bnx2x_clear_reset_global(bp);
  7662. exit_leader_reset2:
  7663. /* unload "fake driver" if it was loaded */
  7664. if (!global && !BP_NOMCP(bp)) {
  7665. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0);
  7666. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
  7667. }
  7668. exit_leader_reset:
  7669. bp->is_leader = 0;
  7670. bnx2x_release_leader_lock(bp);
  7671. smp_mb();
  7672. return rc;
  7673. }
  7674. static void bnx2x_recovery_failed(struct bnx2x *bp)
  7675. {
  7676. netdev_err(bp->dev, "Recovery has failed. Power cycle is needed.\n");
  7677. /* Disconnect this device */
  7678. netif_device_detach(bp->dev);
  7679. /*
  7680. * Block ifup for all function on this engine until "process kill"
  7681. * or power cycle.
  7682. */
  7683. bnx2x_set_reset_in_progress(bp);
  7684. /* Shut down the power */
  7685. bnx2x_set_power_state(bp, PCI_D3hot);
  7686. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  7687. smp_mb();
  7688. }
  7689. /*
  7690. * Assumption: runs under rtnl lock. This together with the fact
  7691. * that it's called only from bnx2x_sp_rtnl() ensure that it
  7692. * will never be called when netif_running(bp->dev) is false.
  7693. */
  7694. static void bnx2x_parity_recover(struct bnx2x *bp)
  7695. {
  7696. bool global = false;
  7697. u32 error_recovered, error_unrecovered;
  7698. bool is_parity;
  7699. DP(NETIF_MSG_HW, "Handling parity\n");
  7700. while (1) {
  7701. switch (bp->recovery_state) {
  7702. case BNX2X_RECOVERY_INIT:
  7703. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_INIT\n");
  7704. is_parity = bnx2x_chk_parity_attn(bp, &global, false);
  7705. WARN_ON(!is_parity);
  7706. /* Try to get a LEADER_LOCK HW lock */
  7707. if (bnx2x_trylock_leader_lock(bp)) {
  7708. bnx2x_set_reset_in_progress(bp);
  7709. /*
  7710. * Check if there is a global attention and if
  7711. * there was a global attention, set the global
  7712. * reset bit.
  7713. */
  7714. if (global)
  7715. bnx2x_set_reset_global(bp);
  7716. bp->is_leader = 1;
  7717. }
  7718. /* Stop the driver */
  7719. /* If interface has been removed - break */
  7720. if (bnx2x_nic_unload(bp, UNLOAD_RECOVERY, false))
  7721. return;
  7722. bp->recovery_state = BNX2X_RECOVERY_WAIT;
  7723. /* Ensure "is_leader", MCP command sequence and
  7724. * "recovery_state" update values are seen on other
  7725. * CPUs.
  7726. */
  7727. smp_mb();
  7728. break;
  7729. case BNX2X_RECOVERY_WAIT:
  7730. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_WAIT\n");
  7731. if (bp->is_leader) {
  7732. int other_engine = BP_PATH(bp) ? 0 : 1;
  7733. bool other_load_status =
  7734. bnx2x_get_load_status(bp, other_engine);
  7735. bool load_status =
  7736. bnx2x_get_load_status(bp, BP_PATH(bp));
  7737. global = bnx2x_reset_is_global(bp);
  7738. /*
  7739. * In case of a parity in a global block, let
  7740. * the first leader that performs a
  7741. * leader_reset() reset the global blocks in
  7742. * order to clear global attentions. Otherwise
  7743. * the the gates will remain closed for that
  7744. * engine.
  7745. */
  7746. if (load_status ||
  7747. (global && other_load_status)) {
  7748. /* Wait until all other functions get
  7749. * down.
  7750. */
  7751. schedule_delayed_work(&bp->sp_rtnl_task,
  7752. HZ/10);
  7753. return;
  7754. } else {
  7755. /* If all other functions got down -
  7756. * try to bring the chip back to
  7757. * normal. In any case it's an exit
  7758. * point for a leader.
  7759. */
  7760. if (bnx2x_leader_reset(bp)) {
  7761. bnx2x_recovery_failed(bp);
  7762. return;
  7763. }
  7764. /* If we are here, means that the
  7765. * leader has succeeded and doesn't
  7766. * want to be a leader any more. Try
  7767. * to continue as a none-leader.
  7768. */
  7769. break;
  7770. }
  7771. } else { /* non-leader */
  7772. if (!bnx2x_reset_is_done(bp, BP_PATH(bp))) {
  7773. /* Try to get a LEADER_LOCK HW lock as
  7774. * long as a former leader may have
  7775. * been unloaded by the user or
  7776. * released a leadership by another
  7777. * reason.
  7778. */
  7779. if (bnx2x_trylock_leader_lock(bp)) {
  7780. /* I'm a leader now! Restart a
  7781. * switch case.
  7782. */
  7783. bp->is_leader = 1;
  7784. break;
  7785. }
  7786. schedule_delayed_work(&bp->sp_rtnl_task,
  7787. HZ/10);
  7788. return;
  7789. } else {
  7790. /*
  7791. * If there was a global attention, wait
  7792. * for it to be cleared.
  7793. */
  7794. if (bnx2x_reset_is_global(bp)) {
  7795. schedule_delayed_work(
  7796. &bp->sp_rtnl_task,
  7797. HZ/10);
  7798. return;
  7799. }
  7800. error_recovered =
  7801. bp->eth_stats.recoverable_error;
  7802. error_unrecovered =
  7803. bp->eth_stats.unrecoverable_error;
  7804. bp->recovery_state =
  7805. BNX2X_RECOVERY_NIC_LOADING;
  7806. if (bnx2x_nic_load(bp, LOAD_NORMAL)) {
  7807. error_unrecovered++;
  7808. netdev_err(bp->dev,
  7809. "Recovery failed. Power cycle needed\n");
  7810. /* Disconnect this device */
  7811. netif_device_detach(bp->dev);
  7812. /* Shut down the power */
  7813. bnx2x_set_power_state(
  7814. bp, PCI_D3hot);
  7815. smp_mb();
  7816. } else {
  7817. bp->recovery_state =
  7818. BNX2X_RECOVERY_DONE;
  7819. error_recovered++;
  7820. smp_mb();
  7821. }
  7822. bp->eth_stats.recoverable_error =
  7823. error_recovered;
  7824. bp->eth_stats.unrecoverable_error =
  7825. error_unrecovered;
  7826. return;
  7827. }
  7828. }
  7829. default:
  7830. return;
  7831. }
  7832. }
  7833. }
  7834. static int bnx2x_close(struct net_device *dev);
  7835. /* bnx2x_nic_unload() flushes the bnx2x_wq, thus reset task is
  7836. * scheduled on a general queue in order to prevent a dead lock.
  7837. */
  7838. static void bnx2x_sp_rtnl_task(struct work_struct *work)
  7839. {
  7840. struct bnx2x *bp = container_of(work, struct bnx2x, sp_rtnl_task.work);
  7841. rtnl_lock();
  7842. if (!netif_running(bp->dev)) {
  7843. rtnl_unlock();
  7844. return;
  7845. }
  7846. /* if stop on error is defined no recovery flows should be executed */
  7847. #ifdef BNX2X_STOP_ON_ERROR
  7848. BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
  7849. "you will need to reboot when done\n");
  7850. goto sp_rtnl_not_reset;
  7851. #endif
  7852. if (unlikely(bp->recovery_state != BNX2X_RECOVERY_DONE)) {
  7853. /*
  7854. * Clear all pending SP commands as we are going to reset the
  7855. * function anyway.
  7856. */
  7857. bp->sp_rtnl_state = 0;
  7858. smp_mb();
  7859. bnx2x_parity_recover(bp);
  7860. rtnl_unlock();
  7861. return;
  7862. }
  7863. if (test_and_clear_bit(BNX2X_SP_RTNL_TX_TIMEOUT, &bp->sp_rtnl_state)) {
  7864. /*
  7865. * Clear all pending SP commands as we are going to reset the
  7866. * function anyway.
  7867. */
  7868. bp->sp_rtnl_state = 0;
  7869. smp_mb();
  7870. bnx2x_nic_unload(bp, UNLOAD_NORMAL, true);
  7871. bnx2x_nic_load(bp, LOAD_NORMAL);
  7872. rtnl_unlock();
  7873. return;
  7874. }
  7875. #ifdef BNX2X_STOP_ON_ERROR
  7876. sp_rtnl_not_reset:
  7877. #endif
  7878. if (test_and_clear_bit(BNX2X_SP_RTNL_SETUP_TC, &bp->sp_rtnl_state))
  7879. bnx2x_setup_tc(bp->dev, bp->dcbx_port_params.ets.num_of_cos);
  7880. if (test_and_clear_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE, &bp->sp_rtnl_state))
  7881. bnx2x_after_function_update(bp);
  7882. /*
  7883. * in case of fan failure we need to reset id if the "stop on error"
  7884. * debug flag is set, since we trying to prevent permanent overheating
  7885. * damage
  7886. */
  7887. if (test_and_clear_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state)) {
  7888. DP(NETIF_MSG_HW, "fan failure detected. Unloading driver\n");
  7889. netif_device_detach(bp->dev);
  7890. bnx2x_close(bp->dev);
  7891. rtnl_unlock();
  7892. return;
  7893. }
  7894. if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_MCAST, &bp->sp_rtnl_state)) {
  7895. DP(BNX2X_MSG_SP,
  7896. "sending set mcast vf pf channel message from rtnl sp-task\n");
  7897. bnx2x_vfpf_set_mcast(bp->dev);
  7898. }
  7899. if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_STORM_RX_MODE,
  7900. &bp->sp_rtnl_state)) {
  7901. DP(BNX2X_MSG_SP,
  7902. "sending set storm rx mode vf pf channel message from rtnl sp-task\n");
  7903. bnx2x_vfpf_storm_rx_mode(bp);
  7904. }
  7905. /* work which needs rtnl lock not-taken (as it takes the lock itself and
  7906. * can be called from other contexts as well)
  7907. */
  7908. rtnl_unlock();
  7909. /* enable SR-IOV if applicable */
  7910. if (IS_SRIOV(bp) && test_and_clear_bit(BNX2X_SP_RTNL_ENABLE_SRIOV,
  7911. &bp->sp_rtnl_state))
  7912. bnx2x_enable_sriov(bp);
  7913. }
  7914. static void bnx2x_period_task(struct work_struct *work)
  7915. {
  7916. struct bnx2x *bp = container_of(work, struct bnx2x, period_task.work);
  7917. if (!netif_running(bp->dev))
  7918. goto period_task_exit;
  7919. if (CHIP_REV_IS_SLOW(bp)) {
  7920. BNX2X_ERR("period task called on emulation, ignoring\n");
  7921. goto period_task_exit;
  7922. }
  7923. bnx2x_acquire_phy_lock(bp);
  7924. /*
  7925. * The barrier is needed to ensure the ordering between the writing to
  7926. * the bp->port.pmf in the bnx2x_nic_load() or bnx2x_pmf_update() and
  7927. * the reading here.
  7928. */
  7929. smp_mb();
  7930. if (bp->port.pmf) {
  7931. bnx2x_period_func(&bp->link_params, &bp->link_vars);
  7932. /* Re-queue task in 1 sec */
  7933. queue_delayed_work(bnx2x_wq, &bp->period_task, 1*HZ);
  7934. }
  7935. bnx2x_release_phy_lock(bp);
  7936. period_task_exit:
  7937. return;
  7938. }
  7939. /*
  7940. * Init service functions
  7941. */
  7942. u32 bnx2x_get_pretend_reg(struct bnx2x *bp)
  7943. {
  7944. u32 base = PXP2_REG_PGL_PRETEND_FUNC_F0;
  7945. u32 stride = PXP2_REG_PGL_PRETEND_FUNC_F1 - base;
  7946. return base + (BP_ABS_FUNC(bp)) * stride;
  7947. }
  7948. static void bnx2x_undi_int_disable_e1h(struct bnx2x *bp)
  7949. {
  7950. u32 reg = bnx2x_get_pretend_reg(bp);
  7951. /* Flush all outstanding writes */
  7952. mmiowb();
  7953. /* Pretend to be function 0 */
  7954. REG_WR(bp, reg, 0);
  7955. REG_RD(bp, reg); /* Flush the GRC transaction (in the chip) */
  7956. /* From now we are in the "like-E1" mode */
  7957. bnx2x_int_disable(bp);
  7958. /* Flush all outstanding writes */
  7959. mmiowb();
  7960. /* Restore the original function */
  7961. REG_WR(bp, reg, BP_ABS_FUNC(bp));
  7962. REG_RD(bp, reg);
  7963. }
  7964. static inline void bnx2x_undi_int_disable(struct bnx2x *bp)
  7965. {
  7966. if (CHIP_IS_E1(bp))
  7967. bnx2x_int_disable(bp);
  7968. else
  7969. bnx2x_undi_int_disable_e1h(bp);
  7970. }
  7971. static void bnx2x_prev_unload_close_mac(struct bnx2x *bp,
  7972. struct bnx2x_mac_vals *vals)
  7973. {
  7974. u32 val, base_addr, offset, mask, reset_reg;
  7975. bool mac_stopped = false;
  7976. u8 port = BP_PORT(bp);
  7977. /* reset addresses as they also mark which values were changed */
  7978. vals->bmac_addr = 0;
  7979. vals->umac_addr = 0;
  7980. vals->xmac_addr = 0;
  7981. vals->emac_addr = 0;
  7982. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_2);
  7983. if (!CHIP_IS_E3(bp)) {
  7984. val = REG_RD(bp, NIG_REG_BMAC0_REGS_OUT_EN + port * 4);
  7985. mask = MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port;
  7986. if ((mask & reset_reg) && val) {
  7987. u32 wb_data[2];
  7988. BNX2X_DEV_INFO("Disable bmac Rx\n");
  7989. base_addr = BP_PORT(bp) ? NIG_REG_INGRESS_BMAC1_MEM
  7990. : NIG_REG_INGRESS_BMAC0_MEM;
  7991. offset = CHIP_IS_E2(bp) ? BIGMAC2_REGISTER_BMAC_CONTROL
  7992. : BIGMAC_REGISTER_BMAC_CONTROL;
  7993. /*
  7994. * use rd/wr since we cannot use dmae. This is safe
  7995. * since MCP won't access the bus due to the request
  7996. * to unload, and no function on the path can be
  7997. * loaded at this time.
  7998. */
  7999. wb_data[0] = REG_RD(bp, base_addr + offset);
  8000. wb_data[1] = REG_RD(bp, base_addr + offset + 0x4);
  8001. vals->bmac_addr = base_addr + offset;
  8002. vals->bmac_val[0] = wb_data[0];
  8003. vals->bmac_val[1] = wb_data[1];
  8004. wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE;
  8005. REG_WR(bp, vals->bmac_addr, wb_data[0]);
  8006. REG_WR(bp, vals->bmac_addr + 0x4, wb_data[1]);
  8007. }
  8008. BNX2X_DEV_INFO("Disable emac Rx\n");
  8009. vals->emac_addr = NIG_REG_NIG_EMAC0_EN + BP_PORT(bp)*4;
  8010. vals->emac_val = REG_RD(bp, vals->emac_addr);
  8011. REG_WR(bp, vals->emac_addr, 0);
  8012. mac_stopped = true;
  8013. } else {
  8014. if (reset_reg & MISC_REGISTERS_RESET_REG_2_XMAC) {
  8015. BNX2X_DEV_INFO("Disable xmac Rx\n");
  8016. base_addr = BP_PORT(bp) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
  8017. val = REG_RD(bp, base_addr + XMAC_REG_PFC_CTRL_HI);
  8018. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  8019. val & ~(1 << 1));
  8020. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  8021. val | (1 << 1));
  8022. vals->xmac_addr = base_addr + XMAC_REG_CTRL;
  8023. vals->xmac_val = REG_RD(bp, vals->xmac_addr);
  8024. REG_WR(bp, vals->xmac_addr, 0);
  8025. mac_stopped = true;
  8026. }
  8027. mask = MISC_REGISTERS_RESET_REG_2_UMAC0 << port;
  8028. if (mask & reset_reg) {
  8029. BNX2X_DEV_INFO("Disable umac Rx\n");
  8030. base_addr = BP_PORT(bp) ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
  8031. vals->umac_addr = base_addr + UMAC_REG_COMMAND_CONFIG;
  8032. vals->umac_val = REG_RD(bp, vals->umac_addr);
  8033. REG_WR(bp, vals->umac_addr, 0);
  8034. mac_stopped = true;
  8035. }
  8036. }
  8037. if (mac_stopped)
  8038. msleep(20);
  8039. }
  8040. #define BNX2X_PREV_UNDI_PROD_ADDR(p) (BAR_TSTRORM_INTMEM + 0x1508 + ((p) << 4))
  8041. #define BNX2X_PREV_UNDI_RCQ(val) ((val) & 0xffff)
  8042. #define BNX2X_PREV_UNDI_BD(val) ((val) >> 16 & 0xffff)
  8043. #define BNX2X_PREV_UNDI_PROD(rcq, bd) ((bd) << 16 | (rcq))
  8044. static void bnx2x_prev_unload_undi_inc(struct bnx2x *bp, u8 port, u8 inc)
  8045. {
  8046. u16 rcq, bd;
  8047. u32 tmp_reg = REG_RD(bp, BNX2X_PREV_UNDI_PROD_ADDR(port));
  8048. rcq = BNX2X_PREV_UNDI_RCQ(tmp_reg) + inc;
  8049. bd = BNX2X_PREV_UNDI_BD(tmp_reg) + inc;
  8050. tmp_reg = BNX2X_PREV_UNDI_PROD(rcq, bd);
  8051. REG_WR(bp, BNX2X_PREV_UNDI_PROD_ADDR(port), tmp_reg);
  8052. BNX2X_DEV_INFO("UNDI producer [%d] rings bd -> 0x%04x, rcq -> 0x%04x\n",
  8053. port, bd, rcq);
  8054. }
  8055. static int bnx2x_prev_mcp_done(struct bnx2x *bp)
  8056. {
  8057. u32 rc = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE,
  8058. DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET);
  8059. if (!rc) {
  8060. BNX2X_ERR("MCP response failure, aborting\n");
  8061. return -EBUSY;
  8062. }
  8063. return 0;
  8064. }
  8065. static struct bnx2x_prev_path_list *
  8066. bnx2x_prev_path_get_entry(struct bnx2x *bp)
  8067. {
  8068. struct bnx2x_prev_path_list *tmp_list;
  8069. list_for_each_entry(tmp_list, &bnx2x_prev_list, list)
  8070. if (PCI_SLOT(bp->pdev->devfn) == tmp_list->slot &&
  8071. bp->pdev->bus->number == tmp_list->bus &&
  8072. BP_PATH(bp) == tmp_list->path)
  8073. return tmp_list;
  8074. return NULL;
  8075. }
  8076. static bool bnx2x_prev_is_path_marked(struct bnx2x *bp)
  8077. {
  8078. struct bnx2x_prev_path_list *tmp_list;
  8079. int rc = false;
  8080. if (down_trylock(&bnx2x_prev_sem))
  8081. return false;
  8082. list_for_each_entry(tmp_list, &bnx2x_prev_list, list) {
  8083. if (PCI_SLOT(bp->pdev->devfn) == tmp_list->slot &&
  8084. bp->pdev->bus->number == tmp_list->bus &&
  8085. BP_PATH(bp) == tmp_list->path) {
  8086. rc = true;
  8087. BNX2X_DEV_INFO("Path %d was already cleaned from previous drivers\n",
  8088. BP_PATH(bp));
  8089. break;
  8090. }
  8091. }
  8092. up(&bnx2x_prev_sem);
  8093. return rc;
  8094. }
  8095. static int bnx2x_prev_mark_path(struct bnx2x *bp, bool after_undi)
  8096. {
  8097. struct bnx2x_prev_path_list *tmp_list;
  8098. int rc;
  8099. tmp_list = kmalloc(sizeof(struct bnx2x_prev_path_list), GFP_KERNEL);
  8100. if (!tmp_list) {
  8101. BNX2X_ERR("Failed to allocate 'bnx2x_prev_path_list'\n");
  8102. return -ENOMEM;
  8103. }
  8104. tmp_list->bus = bp->pdev->bus->number;
  8105. tmp_list->slot = PCI_SLOT(bp->pdev->devfn);
  8106. tmp_list->path = BP_PATH(bp);
  8107. tmp_list->undi = after_undi ? (1 << BP_PORT(bp)) : 0;
  8108. rc = down_interruptible(&bnx2x_prev_sem);
  8109. if (rc) {
  8110. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  8111. kfree(tmp_list);
  8112. } else {
  8113. BNX2X_DEV_INFO("Marked path [%d] - finished previous unload\n",
  8114. BP_PATH(bp));
  8115. list_add(&tmp_list->list, &bnx2x_prev_list);
  8116. up(&bnx2x_prev_sem);
  8117. }
  8118. return rc;
  8119. }
  8120. static int bnx2x_do_flr(struct bnx2x *bp)
  8121. {
  8122. int i;
  8123. u16 status;
  8124. struct pci_dev *dev = bp->pdev;
  8125. if (CHIP_IS_E1x(bp)) {
  8126. BNX2X_DEV_INFO("FLR not supported in E1/E1H\n");
  8127. return -EINVAL;
  8128. }
  8129. /* only bootcode REQ_BC_VER_4_INITIATE_FLR and onwards support flr */
  8130. if (bp->common.bc_ver < REQ_BC_VER_4_INITIATE_FLR) {
  8131. BNX2X_ERR("FLR not supported by BC_VER: 0x%x\n",
  8132. bp->common.bc_ver);
  8133. return -EINVAL;
  8134. }
  8135. /* Wait for Transaction Pending bit clean */
  8136. for (i = 0; i < 4; i++) {
  8137. if (i)
  8138. msleep((1 << (i - 1)) * 100);
  8139. pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status);
  8140. if (!(status & PCI_EXP_DEVSTA_TRPND))
  8141. goto clear;
  8142. }
  8143. dev_err(&dev->dev,
  8144. "transaction is not cleared; proceeding with reset anyway\n");
  8145. clear:
  8146. BNX2X_DEV_INFO("Initiating FLR\n");
  8147. bnx2x_fw_command(bp, DRV_MSG_CODE_INITIATE_FLR, 0);
  8148. return 0;
  8149. }
  8150. static int bnx2x_prev_unload_uncommon(struct bnx2x *bp)
  8151. {
  8152. int rc;
  8153. BNX2X_DEV_INFO("Uncommon unload Flow\n");
  8154. /* Test if previous unload process was already finished for this path */
  8155. if (bnx2x_prev_is_path_marked(bp))
  8156. return bnx2x_prev_mcp_done(bp);
  8157. /* If function has FLR capabilities, and existing FW version matches
  8158. * the one required, then FLR will be sufficient to clean any residue
  8159. * left by previous driver
  8160. */
  8161. rc = bnx2x_nic_load_analyze_req(bp, FW_MSG_CODE_DRV_LOAD_FUNCTION);
  8162. if (!rc) {
  8163. /* fw version is good */
  8164. BNX2X_DEV_INFO("FW version matches our own. Attempting FLR\n");
  8165. rc = bnx2x_do_flr(bp);
  8166. }
  8167. if (!rc) {
  8168. /* FLR was performed */
  8169. BNX2X_DEV_INFO("FLR successful\n");
  8170. return 0;
  8171. }
  8172. BNX2X_DEV_INFO("Could not FLR\n");
  8173. /* Close the MCP request, return failure*/
  8174. rc = bnx2x_prev_mcp_done(bp);
  8175. if (!rc)
  8176. rc = BNX2X_PREV_WAIT_NEEDED;
  8177. return rc;
  8178. }
  8179. static int bnx2x_prev_unload_common(struct bnx2x *bp)
  8180. {
  8181. u32 reset_reg, tmp_reg = 0, rc;
  8182. bool prev_undi = false;
  8183. struct bnx2x_mac_vals mac_vals;
  8184. /* It is possible a previous function received 'common' answer,
  8185. * but hasn't loaded yet, therefore creating a scenario of
  8186. * multiple functions receiving 'common' on the same path.
  8187. */
  8188. BNX2X_DEV_INFO("Common unload Flow\n");
  8189. memset(&mac_vals, 0, sizeof(mac_vals));
  8190. if (bnx2x_prev_is_path_marked(bp))
  8191. return bnx2x_prev_mcp_done(bp);
  8192. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
  8193. /* Reset should be performed after BRB is emptied */
  8194. if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_BRB1) {
  8195. u32 timer_count = 1000;
  8196. /* Close the MAC Rx to prevent BRB from filling up */
  8197. bnx2x_prev_unload_close_mac(bp, &mac_vals);
  8198. /* close LLH filters towards the BRB */
  8199. bnx2x_set_rx_filter(&bp->link_params, 0);
  8200. /* Check if the UNDI driver was previously loaded
  8201. * UNDI driver initializes CID offset for normal bell to 0x7
  8202. */
  8203. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
  8204. if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_DORQ) {
  8205. tmp_reg = REG_RD(bp, DORQ_REG_NORM_CID_OFST);
  8206. if (tmp_reg == 0x7) {
  8207. BNX2X_DEV_INFO("UNDI previously loaded\n");
  8208. prev_undi = true;
  8209. /* clear the UNDI indication */
  8210. REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0);
  8211. /* clear possible idle check errors */
  8212. REG_RD(bp, NIG_REG_NIG_INT_STS_CLR_0);
  8213. }
  8214. }
  8215. /* wait until BRB is empty */
  8216. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  8217. while (timer_count) {
  8218. u32 prev_brb = tmp_reg;
  8219. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  8220. if (!tmp_reg)
  8221. break;
  8222. BNX2X_DEV_INFO("BRB still has 0x%08x\n", tmp_reg);
  8223. /* reset timer as long as BRB actually gets emptied */
  8224. if (prev_brb > tmp_reg)
  8225. timer_count = 1000;
  8226. else
  8227. timer_count--;
  8228. /* If UNDI resides in memory, manually increment it */
  8229. if (prev_undi)
  8230. bnx2x_prev_unload_undi_inc(bp, BP_PORT(bp), 1);
  8231. udelay(10);
  8232. }
  8233. if (!timer_count)
  8234. BNX2X_ERR("Failed to empty BRB, hope for the best\n");
  8235. }
  8236. /* No packets are in the pipeline, path is ready for reset */
  8237. bnx2x_reset_common(bp);
  8238. if (mac_vals.xmac_addr)
  8239. REG_WR(bp, mac_vals.xmac_addr, mac_vals.xmac_val);
  8240. if (mac_vals.umac_addr)
  8241. REG_WR(bp, mac_vals.umac_addr, mac_vals.umac_val);
  8242. if (mac_vals.emac_addr)
  8243. REG_WR(bp, mac_vals.emac_addr, mac_vals.emac_val);
  8244. if (mac_vals.bmac_addr) {
  8245. REG_WR(bp, mac_vals.bmac_addr, mac_vals.bmac_val[0]);
  8246. REG_WR(bp, mac_vals.bmac_addr + 4, mac_vals.bmac_val[1]);
  8247. }
  8248. rc = bnx2x_prev_mark_path(bp, prev_undi);
  8249. if (rc) {
  8250. bnx2x_prev_mcp_done(bp);
  8251. return rc;
  8252. }
  8253. return bnx2x_prev_mcp_done(bp);
  8254. }
  8255. /* previous driver DMAE transaction may have occurred when pre-boot stage ended
  8256. * and boot began, or when kdump kernel was loaded. Either case would invalidate
  8257. * the addresses of the transaction, resulting in was-error bit set in the pci
  8258. * causing all hw-to-host pcie transactions to timeout. If this happened we want
  8259. * to clear the interrupt which detected this from the pglueb and the was done
  8260. * bit
  8261. */
  8262. static void bnx2x_prev_interrupted_dmae(struct bnx2x *bp)
  8263. {
  8264. if (!CHIP_IS_E1x(bp)) {
  8265. u32 val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS);
  8266. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN) {
  8267. BNX2X_ERR("was error bit was found to be set in pglueb upon startup. Clearing");
  8268. REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR,
  8269. 1 << BP_FUNC(bp));
  8270. }
  8271. }
  8272. }
  8273. static int bnx2x_prev_unload(struct bnx2x *bp)
  8274. {
  8275. int time_counter = 10;
  8276. u32 rc, fw, hw_lock_reg, hw_lock_val;
  8277. struct bnx2x_prev_path_list *prev_list;
  8278. BNX2X_DEV_INFO("Entering Previous Unload Flow\n");
  8279. /* clear hw from errors which may have resulted from an interrupted
  8280. * dmae transaction.
  8281. */
  8282. bnx2x_prev_interrupted_dmae(bp);
  8283. /* Release previously held locks */
  8284. hw_lock_reg = (BP_FUNC(bp) <= 5) ?
  8285. (MISC_REG_DRIVER_CONTROL_1 + BP_FUNC(bp) * 8) :
  8286. (MISC_REG_DRIVER_CONTROL_7 + (BP_FUNC(bp) - 6) * 8);
  8287. hw_lock_val = (REG_RD(bp, hw_lock_reg));
  8288. if (hw_lock_val) {
  8289. if (hw_lock_val & HW_LOCK_RESOURCE_NVRAM) {
  8290. BNX2X_DEV_INFO("Release Previously held NVRAM lock\n");
  8291. REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
  8292. (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << BP_PORT(bp)));
  8293. }
  8294. BNX2X_DEV_INFO("Release Previously held hw lock\n");
  8295. REG_WR(bp, hw_lock_reg, 0xffffffff);
  8296. } else
  8297. BNX2X_DEV_INFO("No need to release hw/nvram locks\n");
  8298. if (MCPR_ACCESS_LOCK_LOCK & REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK)) {
  8299. BNX2X_DEV_INFO("Release previously held alr\n");
  8300. REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, 0);
  8301. }
  8302. do {
  8303. /* Lock MCP using an unload request */
  8304. fw = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS, 0);
  8305. if (!fw) {
  8306. BNX2X_ERR("MCP response failure, aborting\n");
  8307. rc = -EBUSY;
  8308. break;
  8309. }
  8310. if (fw == FW_MSG_CODE_DRV_UNLOAD_COMMON) {
  8311. rc = bnx2x_prev_unload_common(bp);
  8312. break;
  8313. }
  8314. /* non-common reply from MCP night require looping */
  8315. rc = bnx2x_prev_unload_uncommon(bp);
  8316. if (rc != BNX2X_PREV_WAIT_NEEDED)
  8317. break;
  8318. msleep(20);
  8319. } while (--time_counter);
  8320. if (!time_counter || rc) {
  8321. BNX2X_ERR("Failed unloading previous driver, aborting\n");
  8322. rc = -EBUSY;
  8323. }
  8324. /* Mark function if its port was used to boot from SAN */
  8325. prev_list = bnx2x_prev_path_get_entry(bp);
  8326. if (prev_list && (prev_list->undi & (1 << BP_PORT(bp))))
  8327. bp->link_params.feature_config_flags |=
  8328. FEATURE_CONFIG_BOOT_FROM_SAN;
  8329. BNX2X_DEV_INFO("Finished Previous Unload Flow [%d]\n", rc);
  8330. return rc;
  8331. }
  8332. static void bnx2x_get_common_hwinfo(struct bnx2x *bp)
  8333. {
  8334. u32 val, val2, val3, val4, id, boot_mode;
  8335. u16 pmc;
  8336. /* Get the chip revision id and number. */
  8337. /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
  8338. val = REG_RD(bp, MISC_REG_CHIP_NUM);
  8339. id = ((val & 0xffff) << 16);
  8340. val = REG_RD(bp, MISC_REG_CHIP_REV);
  8341. id |= ((val & 0xf) << 12);
  8342. val = REG_RD(bp, MISC_REG_CHIP_METAL);
  8343. id |= ((val & 0xff) << 4);
  8344. val = REG_RD(bp, MISC_REG_BOND_ID);
  8345. id |= (val & 0xf);
  8346. bp->common.chip_id = id;
  8347. /* force 57811 according to MISC register */
  8348. if (REG_RD(bp, MISC_REG_CHIP_TYPE) & MISC_REG_CHIP_TYPE_57811_MASK) {
  8349. if (CHIP_IS_57810(bp))
  8350. bp->common.chip_id = (CHIP_NUM_57811 << 16) |
  8351. (bp->common.chip_id & 0x0000FFFF);
  8352. else if (CHIP_IS_57810_MF(bp))
  8353. bp->common.chip_id = (CHIP_NUM_57811_MF << 16) |
  8354. (bp->common.chip_id & 0x0000FFFF);
  8355. bp->common.chip_id |= 0x1;
  8356. }
  8357. /* Set doorbell size */
  8358. bp->db_size = (1 << BNX2X_DB_SHIFT);
  8359. if (!CHIP_IS_E1x(bp)) {
  8360. val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR);
  8361. if ((val & 1) == 0)
  8362. val = REG_RD(bp, MISC_REG_PORT4MODE_EN);
  8363. else
  8364. val = (val >> 1) & 1;
  8365. BNX2X_DEV_INFO("chip is in %s\n", val ? "4_PORT_MODE" :
  8366. "2_PORT_MODE");
  8367. bp->common.chip_port_mode = val ? CHIP_4_PORT_MODE :
  8368. CHIP_2_PORT_MODE;
  8369. if (CHIP_MODE_IS_4_PORT(bp))
  8370. bp->pfid = (bp->pf_num >> 1); /* 0..3 */
  8371. else
  8372. bp->pfid = (bp->pf_num & 0x6); /* 0, 2, 4, 6 */
  8373. } else {
  8374. bp->common.chip_port_mode = CHIP_PORT_MODE_NONE; /* N/A */
  8375. bp->pfid = bp->pf_num; /* 0..7 */
  8376. }
  8377. BNX2X_DEV_INFO("pf_id: %x", bp->pfid);
  8378. bp->link_params.chip_id = bp->common.chip_id;
  8379. BNX2X_DEV_INFO("chip ID is 0x%x\n", id);
  8380. val = (REG_RD(bp, 0x2874) & 0x55);
  8381. if ((bp->common.chip_id & 0x1) ||
  8382. (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) {
  8383. bp->flags |= ONE_PORT_FLAG;
  8384. BNX2X_DEV_INFO("single port device\n");
  8385. }
  8386. val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4);
  8387. bp->common.flash_size = (BNX2X_NVRAM_1MB_SIZE <<
  8388. (val & MCPR_NVM_CFG4_FLASH_SIZE));
  8389. BNX2X_DEV_INFO("flash_size 0x%x (%d)\n",
  8390. bp->common.flash_size, bp->common.flash_size);
  8391. bnx2x_init_shmem(bp);
  8392. bp->common.shmem2_base = REG_RD(bp, (BP_PATH(bp) ?
  8393. MISC_REG_GENERIC_CR_1 :
  8394. MISC_REG_GENERIC_CR_0));
  8395. bp->link_params.shmem_base = bp->common.shmem_base;
  8396. bp->link_params.shmem2_base = bp->common.shmem2_base;
  8397. if (SHMEM2_RD(bp, size) >
  8398. (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
  8399. bp->link_params.lfa_base =
  8400. REG_RD(bp, bp->common.shmem2_base +
  8401. (u32)offsetof(struct shmem2_region,
  8402. lfa_host_addr[BP_PORT(bp)]));
  8403. else
  8404. bp->link_params.lfa_base = 0;
  8405. BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n",
  8406. bp->common.shmem_base, bp->common.shmem2_base);
  8407. if (!bp->common.shmem_base) {
  8408. BNX2X_DEV_INFO("MCP not active\n");
  8409. bp->flags |= NO_MCP_FLAG;
  8410. return;
  8411. }
  8412. bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config);
  8413. BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config);
  8414. bp->link_params.hw_led_mode = ((bp->common.hw_config &
  8415. SHARED_HW_CFG_LED_MODE_MASK) >>
  8416. SHARED_HW_CFG_LED_MODE_SHIFT);
  8417. bp->link_params.feature_config_flags = 0;
  8418. val = SHMEM_RD(bp, dev_info.shared_feature_config.config);
  8419. if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED)
  8420. bp->link_params.feature_config_flags |=
  8421. FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  8422. else
  8423. bp->link_params.feature_config_flags &=
  8424. ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  8425. val = SHMEM_RD(bp, dev_info.bc_rev) >> 8;
  8426. bp->common.bc_ver = val;
  8427. BNX2X_DEV_INFO("bc_ver %X\n", val);
  8428. if (val < BNX2X_BC_VER) {
  8429. /* for now only warn
  8430. * later we might need to enforce this */
  8431. BNX2X_ERR("This driver needs bc_ver %X but found %X, please upgrade BC\n",
  8432. BNX2X_BC_VER, val);
  8433. }
  8434. bp->link_params.feature_config_flags |=
  8435. (val >= REQ_BC_VER_4_VRFY_FIRST_PHY_OPT_MDL) ?
  8436. FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY : 0;
  8437. bp->link_params.feature_config_flags |=
  8438. (val >= REQ_BC_VER_4_VRFY_SPECIFIC_PHY_OPT_MDL) ?
  8439. FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY : 0;
  8440. bp->link_params.feature_config_flags |=
  8441. (val >= REQ_BC_VER_4_VRFY_AFEX_SUPPORTED) ?
  8442. FEATURE_CONFIG_BC_SUPPORTS_AFEX : 0;
  8443. bp->link_params.feature_config_flags |=
  8444. (val >= REQ_BC_VER_4_SFP_TX_DISABLE_SUPPORTED) ?
  8445. FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED : 0;
  8446. bp->link_params.feature_config_flags |=
  8447. (val >= REQ_BC_VER_4_MT_SUPPORTED) ?
  8448. FEATURE_CONFIG_MT_SUPPORT : 0;
  8449. bp->flags |= (val >= REQ_BC_VER_4_PFC_STATS_SUPPORTED) ?
  8450. BC_SUPPORTS_PFC_STATS : 0;
  8451. bp->flags |= (val >= REQ_BC_VER_4_FCOE_FEATURES) ?
  8452. BC_SUPPORTS_FCOE_FEATURES : 0;
  8453. bp->flags |= (val >= REQ_BC_VER_4_DCBX_ADMIN_MSG_NON_PMF) ?
  8454. BC_SUPPORTS_DCBX_MSG_NON_PMF : 0;
  8455. boot_mode = SHMEM_RD(bp,
  8456. dev_info.port_feature_config[BP_PORT(bp)].mba_config) &
  8457. PORT_FEATURE_MBA_BOOT_AGENT_TYPE_MASK;
  8458. switch (boot_mode) {
  8459. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_PXE:
  8460. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_PXE;
  8461. break;
  8462. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_ISCSIB:
  8463. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_ISCSI;
  8464. break;
  8465. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_FCOE_BOOT:
  8466. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_FCOE;
  8467. break;
  8468. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_NONE:
  8469. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_NONE;
  8470. break;
  8471. }
  8472. pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_PMC, &pmc);
  8473. bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG;
  8474. BNX2X_DEV_INFO("%sWoL capable\n",
  8475. (bp->flags & NO_WOL_FLAG) ? "not " : "");
  8476. val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num);
  8477. val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]);
  8478. val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]);
  8479. val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]);
  8480. dev_info(&bp->pdev->dev, "part number %X-%X-%X-%X\n",
  8481. val, val2, val3, val4);
  8482. }
  8483. #define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID)
  8484. #define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR)
  8485. static int bnx2x_get_igu_cam_info(struct bnx2x *bp)
  8486. {
  8487. int pfid = BP_FUNC(bp);
  8488. int igu_sb_id;
  8489. u32 val;
  8490. u8 fid, igu_sb_cnt = 0;
  8491. bp->igu_base_sb = 0xff;
  8492. if (CHIP_INT_MODE_IS_BC(bp)) {
  8493. int vn = BP_VN(bp);
  8494. igu_sb_cnt = bp->igu_sb_cnt;
  8495. bp->igu_base_sb = (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn) *
  8496. FP_SB_MAX_E1x;
  8497. bp->igu_dsb_id = E1HVN_MAX * FP_SB_MAX_E1x +
  8498. (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn);
  8499. return 0;
  8500. }
  8501. /* IGU in normal mode - read CAM */
  8502. for (igu_sb_id = 0; igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE;
  8503. igu_sb_id++) {
  8504. val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4);
  8505. if (!(val & IGU_REG_MAPPING_MEMORY_VALID))
  8506. continue;
  8507. fid = IGU_FID(val);
  8508. if ((fid & IGU_FID_ENCODE_IS_PF)) {
  8509. if ((fid & IGU_FID_PF_NUM_MASK) != pfid)
  8510. continue;
  8511. if (IGU_VEC(val) == 0)
  8512. /* default status block */
  8513. bp->igu_dsb_id = igu_sb_id;
  8514. else {
  8515. if (bp->igu_base_sb == 0xff)
  8516. bp->igu_base_sb = igu_sb_id;
  8517. igu_sb_cnt++;
  8518. }
  8519. }
  8520. }
  8521. #ifdef CONFIG_PCI_MSI
  8522. /* Due to new PF resource allocation by MFW T7.4 and above, it's
  8523. * optional that number of CAM entries will not be equal to the value
  8524. * advertised in PCI.
  8525. * Driver should use the minimal value of both as the actual status
  8526. * block count
  8527. */
  8528. bp->igu_sb_cnt = min_t(int, bp->igu_sb_cnt, igu_sb_cnt);
  8529. #endif
  8530. if (igu_sb_cnt == 0) {
  8531. BNX2X_ERR("CAM configuration error\n");
  8532. return -EINVAL;
  8533. }
  8534. return 0;
  8535. }
  8536. static void bnx2x_link_settings_supported(struct bnx2x *bp, u32 switch_cfg)
  8537. {
  8538. int cfg_size = 0, idx, port = BP_PORT(bp);
  8539. /* Aggregation of supported attributes of all external phys */
  8540. bp->port.supported[0] = 0;
  8541. bp->port.supported[1] = 0;
  8542. switch (bp->link_params.num_phys) {
  8543. case 1:
  8544. bp->port.supported[0] = bp->link_params.phy[INT_PHY].supported;
  8545. cfg_size = 1;
  8546. break;
  8547. case 2:
  8548. bp->port.supported[0] = bp->link_params.phy[EXT_PHY1].supported;
  8549. cfg_size = 1;
  8550. break;
  8551. case 3:
  8552. if (bp->link_params.multi_phy_config &
  8553. PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
  8554. bp->port.supported[1] =
  8555. bp->link_params.phy[EXT_PHY1].supported;
  8556. bp->port.supported[0] =
  8557. bp->link_params.phy[EXT_PHY2].supported;
  8558. } else {
  8559. bp->port.supported[0] =
  8560. bp->link_params.phy[EXT_PHY1].supported;
  8561. bp->port.supported[1] =
  8562. bp->link_params.phy[EXT_PHY2].supported;
  8563. }
  8564. cfg_size = 2;
  8565. break;
  8566. }
  8567. if (!(bp->port.supported[0] || bp->port.supported[1])) {
  8568. BNX2X_ERR("NVRAM config error. BAD phy config. PHY1 config 0x%x, PHY2 config 0x%x\n",
  8569. SHMEM_RD(bp,
  8570. dev_info.port_hw_config[port].external_phy_config),
  8571. SHMEM_RD(bp,
  8572. dev_info.port_hw_config[port].external_phy_config2));
  8573. return;
  8574. }
  8575. if (CHIP_IS_E3(bp))
  8576. bp->port.phy_addr = REG_RD(bp, MISC_REG_WC0_CTRL_PHY_ADDR);
  8577. else {
  8578. switch (switch_cfg) {
  8579. case SWITCH_CFG_1G:
  8580. bp->port.phy_addr = REG_RD(
  8581. bp, NIG_REG_SERDES0_CTRL_PHY_ADDR + port*0x10);
  8582. break;
  8583. case SWITCH_CFG_10G:
  8584. bp->port.phy_addr = REG_RD(
  8585. bp, NIG_REG_XGXS0_CTRL_PHY_ADDR + port*0x18);
  8586. break;
  8587. default:
  8588. BNX2X_ERR("BAD switch_cfg link_config 0x%x\n",
  8589. bp->port.link_config[0]);
  8590. return;
  8591. }
  8592. }
  8593. BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
  8594. /* mask what we support according to speed_cap_mask per configuration */
  8595. for (idx = 0; idx < cfg_size; idx++) {
  8596. if (!(bp->link_params.speed_cap_mask[idx] &
  8597. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF))
  8598. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Half;
  8599. if (!(bp->link_params.speed_cap_mask[idx] &
  8600. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL))
  8601. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Full;
  8602. if (!(bp->link_params.speed_cap_mask[idx] &
  8603. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF))
  8604. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Half;
  8605. if (!(bp->link_params.speed_cap_mask[idx] &
  8606. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL))
  8607. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Full;
  8608. if (!(bp->link_params.speed_cap_mask[idx] &
  8609. PORT_HW_CFG_SPEED_CAPABILITY_D0_1G))
  8610. bp->port.supported[idx] &= ~(SUPPORTED_1000baseT_Half |
  8611. SUPPORTED_1000baseT_Full);
  8612. if (!(bp->link_params.speed_cap_mask[idx] &
  8613. PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
  8614. bp->port.supported[idx] &= ~SUPPORTED_2500baseX_Full;
  8615. if (!(bp->link_params.speed_cap_mask[idx] &
  8616. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G))
  8617. bp->port.supported[idx] &= ~SUPPORTED_10000baseT_Full;
  8618. }
  8619. BNX2X_DEV_INFO("supported 0x%x 0x%x\n", bp->port.supported[0],
  8620. bp->port.supported[1]);
  8621. }
  8622. static void bnx2x_link_settings_requested(struct bnx2x *bp)
  8623. {
  8624. u32 link_config, idx, cfg_size = 0;
  8625. bp->port.advertising[0] = 0;
  8626. bp->port.advertising[1] = 0;
  8627. switch (bp->link_params.num_phys) {
  8628. case 1:
  8629. case 2:
  8630. cfg_size = 1;
  8631. break;
  8632. case 3:
  8633. cfg_size = 2;
  8634. break;
  8635. }
  8636. for (idx = 0; idx < cfg_size; idx++) {
  8637. bp->link_params.req_duplex[idx] = DUPLEX_FULL;
  8638. link_config = bp->port.link_config[idx];
  8639. switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
  8640. case PORT_FEATURE_LINK_SPEED_AUTO:
  8641. if (bp->port.supported[idx] & SUPPORTED_Autoneg) {
  8642. bp->link_params.req_line_speed[idx] =
  8643. SPEED_AUTO_NEG;
  8644. bp->port.advertising[idx] |=
  8645. bp->port.supported[idx];
  8646. if (bp->link_params.phy[EXT_PHY1].type ==
  8647. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
  8648. bp->port.advertising[idx] |=
  8649. (SUPPORTED_100baseT_Half |
  8650. SUPPORTED_100baseT_Full);
  8651. } else {
  8652. /* force 10G, no AN */
  8653. bp->link_params.req_line_speed[idx] =
  8654. SPEED_10000;
  8655. bp->port.advertising[idx] |=
  8656. (ADVERTISED_10000baseT_Full |
  8657. ADVERTISED_FIBRE);
  8658. continue;
  8659. }
  8660. break;
  8661. case PORT_FEATURE_LINK_SPEED_10M_FULL:
  8662. if (bp->port.supported[idx] & SUPPORTED_10baseT_Full) {
  8663. bp->link_params.req_line_speed[idx] =
  8664. SPEED_10;
  8665. bp->port.advertising[idx] |=
  8666. (ADVERTISED_10baseT_Full |
  8667. ADVERTISED_TP);
  8668. } else {
  8669. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8670. link_config,
  8671. bp->link_params.speed_cap_mask[idx]);
  8672. return;
  8673. }
  8674. break;
  8675. case PORT_FEATURE_LINK_SPEED_10M_HALF:
  8676. if (bp->port.supported[idx] & SUPPORTED_10baseT_Half) {
  8677. bp->link_params.req_line_speed[idx] =
  8678. SPEED_10;
  8679. bp->link_params.req_duplex[idx] =
  8680. DUPLEX_HALF;
  8681. bp->port.advertising[idx] |=
  8682. (ADVERTISED_10baseT_Half |
  8683. ADVERTISED_TP);
  8684. } else {
  8685. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8686. link_config,
  8687. bp->link_params.speed_cap_mask[idx]);
  8688. return;
  8689. }
  8690. break;
  8691. case PORT_FEATURE_LINK_SPEED_100M_FULL:
  8692. if (bp->port.supported[idx] &
  8693. SUPPORTED_100baseT_Full) {
  8694. bp->link_params.req_line_speed[idx] =
  8695. SPEED_100;
  8696. bp->port.advertising[idx] |=
  8697. (ADVERTISED_100baseT_Full |
  8698. ADVERTISED_TP);
  8699. } else {
  8700. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8701. link_config,
  8702. bp->link_params.speed_cap_mask[idx]);
  8703. return;
  8704. }
  8705. break;
  8706. case PORT_FEATURE_LINK_SPEED_100M_HALF:
  8707. if (bp->port.supported[idx] &
  8708. SUPPORTED_100baseT_Half) {
  8709. bp->link_params.req_line_speed[idx] =
  8710. SPEED_100;
  8711. bp->link_params.req_duplex[idx] =
  8712. DUPLEX_HALF;
  8713. bp->port.advertising[idx] |=
  8714. (ADVERTISED_100baseT_Half |
  8715. ADVERTISED_TP);
  8716. } else {
  8717. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8718. link_config,
  8719. bp->link_params.speed_cap_mask[idx]);
  8720. return;
  8721. }
  8722. break;
  8723. case PORT_FEATURE_LINK_SPEED_1G:
  8724. if (bp->port.supported[idx] &
  8725. SUPPORTED_1000baseT_Full) {
  8726. bp->link_params.req_line_speed[idx] =
  8727. SPEED_1000;
  8728. bp->port.advertising[idx] |=
  8729. (ADVERTISED_1000baseT_Full |
  8730. ADVERTISED_TP);
  8731. } else {
  8732. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8733. link_config,
  8734. bp->link_params.speed_cap_mask[idx]);
  8735. return;
  8736. }
  8737. break;
  8738. case PORT_FEATURE_LINK_SPEED_2_5G:
  8739. if (bp->port.supported[idx] &
  8740. SUPPORTED_2500baseX_Full) {
  8741. bp->link_params.req_line_speed[idx] =
  8742. SPEED_2500;
  8743. bp->port.advertising[idx] |=
  8744. (ADVERTISED_2500baseX_Full |
  8745. ADVERTISED_TP);
  8746. } else {
  8747. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8748. link_config,
  8749. bp->link_params.speed_cap_mask[idx]);
  8750. return;
  8751. }
  8752. break;
  8753. case PORT_FEATURE_LINK_SPEED_10G_CX4:
  8754. if (bp->port.supported[idx] &
  8755. SUPPORTED_10000baseT_Full) {
  8756. bp->link_params.req_line_speed[idx] =
  8757. SPEED_10000;
  8758. bp->port.advertising[idx] |=
  8759. (ADVERTISED_10000baseT_Full |
  8760. ADVERTISED_FIBRE);
  8761. } else {
  8762. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8763. link_config,
  8764. bp->link_params.speed_cap_mask[idx]);
  8765. return;
  8766. }
  8767. break;
  8768. case PORT_FEATURE_LINK_SPEED_20G:
  8769. bp->link_params.req_line_speed[idx] = SPEED_20000;
  8770. break;
  8771. default:
  8772. BNX2X_ERR("NVRAM config error. BAD link speed link_config 0x%x\n",
  8773. link_config);
  8774. bp->link_params.req_line_speed[idx] =
  8775. SPEED_AUTO_NEG;
  8776. bp->port.advertising[idx] =
  8777. bp->port.supported[idx];
  8778. break;
  8779. }
  8780. bp->link_params.req_flow_ctrl[idx] = (link_config &
  8781. PORT_FEATURE_FLOW_CONTROL_MASK);
  8782. if (bp->link_params.req_flow_ctrl[idx] ==
  8783. BNX2X_FLOW_CTRL_AUTO) {
  8784. if (!(bp->port.supported[idx] & SUPPORTED_Autoneg))
  8785. bp->link_params.req_flow_ctrl[idx] =
  8786. BNX2X_FLOW_CTRL_NONE;
  8787. else
  8788. bnx2x_set_requested_fc(bp);
  8789. }
  8790. BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl 0x%x advertising 0x%x\n",
  8791. bp->link_params.req_line_speed[idx],
  8792. bp->link_params.req_duplex[idx],
  8793. bp->link_params.req_flow_ctrl[idx],
  8794. bp->port.advertising[idx]);
  8795. }
  8796. }
  8797. static void bnx2x_set_mac_buf(u8 *mac_buf, u32 mac_lo, u16 mac_hi)
  8798. {
  8799. mac_hi = cpu_to_be16(mac_hi);
  8800. mac_lo = cpu_to_be32(mac_lo);
  8801. memcpy(mac_buf, &mac_hi, sizeof(mac_hi));
  8802. memcpy(mac_buf + sizeof(mac_hi), &mac_lo, sizeof(mac_lo));
  8803. }
  8804. static void bnx2x_get_port_hwinfo(struct bnx2x *bp)
  8805. {
  8806. int port = BP_PORT(bp);
  8807. u32 config;
  8808. u32 ext_phy_type, ext_phy_config, eee_mode;
  8809. bp->link_params.bp = bp;
  8810. bp->link_params.port = port;
  8811. bp->link_params.lane_config =
  8812. SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config);
  8813. bp->link_params.speed_cap_mask[0] =
  8814. SHMEM_RD(bp,
  8815. dev_info.port_hw_config[port].speed_capability_mask);
  8816. bp->link_params.speed_cap_mask[1] =
  8817. SHMEM_RD(bp,
  8818. dev_info.port_hw_config[port].speed_capability_mask2);
  8819. bp->port.link_config[0] =
  8820. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config);
  8821. bp->port.link_config[1] =
  8822. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config2);
  8823. bp->link_params.multi_phy_config =
  8824. SHMEM_RD(bp, dev_info.port_hw_config[port].multi_phy_config);
  8825. /* If the device is capable of WoL, set the default state according
  8826. * to the HW
  8827. */
  8828. config = SHMEM_RD(bp, dev_info.port_feature_config[port].config);
  8829. bp->wol = (!(bp->flags & NO_WOL_FLAG) &&
  8830. (config & PORT_FEATURE_WOL_ENABLED));
  8831. BNX2X_DEV_INFO("lane_config 0x%08x speed_cap_mask0 0x%08x link_config0 0x%08x\n",
  8832. bp->link_params.lane_config,
  8833. bp->link_params.speed_cap_mask[0],
  8834. bp->port.link_config[0]);
  8835. bp->link_params.switch_cfg = (bp->port.link_config[0] &
  8836. PORT_FEATURE_CONNECTED_SWITCH_MASK);
  8837. bnx2x_phy_probe(&bp->link_params);
  8838. bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg);
  8839. bnx2x_link_settings_requested(bp);
  8840. /*
  8841. * If connected directly, work with the internal PHY, otherwise, work
  8842. * with the external PHY
  8843. */
  8844. ext_phy_config =
  8845. SHMEM_RD(bp,
  8846. dev_info.port_hw_config[port].external_phy_config);
  8847. ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
  8848. if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
  8849. bp->mdio.prtad = bp->port.phy_addr;
  8850. else if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) &&
  8851. (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
  8852. bp->mdio.prtad =
  8853. XGXS_EXT_PHY_ADDR(ext_phy_config);
  8854. /* Configure link feature according to nvram value */
  8855. eee_mode = (((SHMEM_RD(bp, dev_info.
  8856. port_feature_config[port].eee_power_mode)) &
  8857. PORT_FEAT_CFG_EEE_POWER_MODE_MASK) >>
  8858. PORT_FEAT_CFG_EEE_POWER_MODE_SHIFT);
  8859. if (eee_mode != PORT_FEAT_CFG_EEE_POWER_MODE_DISABLED) {
  8860. bp->link_params.eee_mode = EEE_MODE_ADV_LPI |
  8861. EEE_MODE_ENABLE_LPI |
  8862. EEE_MODE_OUTPUT_TIME;
  8863. } else {
  8864. bp->link_params.eee_mode = 0;
  8865. }
  8866. }
  8867. void bnx2x_get_iscsi_info(struct bnx2x *bp)
  8868. {
  8869. u32 no_flags = NO_ISCSI_FLAG;
  8870. int port = BP_PORT(bp);
  8871. u32 max_iscsi_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  8872. drv_lic_key[port].max_iscsi_conn);
  8873. if (!CNIC_SUPPORT(bp)) {
  8874. bp->flags |= no_flags;
  8875. return;
  8876. }
  8877. /* Get the number of maximum allowed iSCSI connections */
  8878. bp->cnic_eth_dev.max_iscsi_conn =
  8879. (max_iscsi_conn & BNX2X_MAX_ISCSI_INIT_CONN_MASK) >>
  8880. BNX2X_MAX_ISCSI_INIT_CONN_SHIFT;
  8881. BNX2X_DEV_INFO("max_iscsi_conn 0x%x\n",
  8882. bp->cnic_eth_dev.max_iscsi_conn);
  8883. /*
  8884. * If maximum allowed number of connections is zero -
  8885. * disable the feature.
  8886. */
  8887. if (!bp->cnic_eth_dev.max_iscsi_conn)
  8888. bp->flags |= no_flags;
  8889. }
  8890. static void bnx2x_get_ext_wwn_info(struct bnx2x *bp, int func)
  8891. {
  8892. /* Port info */
  8893. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  8894. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_upper);
  8895. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  8896. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_lower);
  8897. /* Node info */
  8898. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  8899. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_upper);
  8900. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  8901. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_lower);
  8902. }
  8903. static void bnx2x_get_fcoe_info(struct bnx2x *bp)
  8904. {
  8905. int port = BP_PORT(bp);
  8906. int func = BP_ABS_FUNC(bp);
  8907. u32 max_fcoe_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  8908. drv_lic_key[port].max_fcoe_conn);
  8909. if (!CNIC_SUPPORT(bp)) {
  8910. bp->flags |= NO_FCOE_FLAG;
  8911. return;
  8912. }
  8913. /* Get the number of maximum allowed FCoE connections */
  8914. bp->cnic_eth_dev.max_fcoe_conn =
  8915. (max_fcoe_conn & BNX2X_MAX_FCOE_INIT_CONN_MASK) >>
  8916. BNX2X_MAX_FCOE_INIT_CONN_SHIFT;
  8917. /* Read the WWN: */
  8918. if (!IS_MF(bp)) {
  8919. /* Port info */
  8920. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  8921. SHMEM_RD(bp,
  8922. dev_info.port_hw_config[port].
  8923. fcoe_wwn_port_name_upper);
  8924. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  8925. SHMEM_RD(bp,
  8926. dev_info.port_hw_config[port].
  8927. fcoe_wwn_port_name_lower);
  8928. /* Node info */
  8929. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  8930. SHMEM_RD(bp,
  8931. dev_info.port_hw_config[port].
  8932. fcoe_wwn_node_name_upper);
  8933. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  8934. SHMEM_RD(bp,
  8935. dev_info.port_hw_config[port].
  8936. fcoe_wwn_node_name_lower);
  8937. } else if (!IS_MF_SD(bp)) {
  8938. /*
  8939. * Read the WWN info only if the FCoE feature is enabled for
  8940. * this function.
  8941. */
  8942. if (BNX2X_MF_EXT_PROTOCOL_FCOE(bp) && !CHIP_IS_E1x(bp))
  8943. bnx2x_get_ext_wwn_info(bp, func);
  8944. } else if (IS_MF_FCOE_SD(bp) && !CHIP_IS_E1x(bp)) {
  8945. bnx2x_get_ext_wwn_info(bp, func);
  8946. }
  8947. BNX2X_DEV_INFO("max_fcoe_conn 0x%x\n", bp->cnic_eth_dev.max_fcoe_conn);
  8948. /*
  8949. * If maximum allowed number of connections is zero -
  8950. * disable the feature.
  8951. */
  8952. if (!bp->cnic_eth_dev.max_fcoe_conn)
  8953. bp->flags |= NO_FCOE_FLAG;
  8954. }
  8955. static void bnx2x_get_cnic_info(struct bnx2x *bp)
  8956. {
  8957. /*
  8958. * iSCSI may be dynamically disabled but reading
  8959. * info here we will decrease memory usage by driver
  8960. * if the feature is disabled for good
  8961. */
  8962. bnx2x_get_iscsi_info(bp);
  8963. bnx2x_get_fcoe_info(bp);
  8964. }
  8965. static void bnx2x_get_cnic_mac_hwinfo(struct bnx2x *bp)
  8966. {
  8967. u32 val, val2;
  8968. int func = BP_ABS_FUNC(bp);
  8969. int port = BP_PORT(bp);
  8970. u8 *iscsi_mac = bp->cnic_eth_dev.iscsi_mac;
  8971. u8 *fip_mac = bp->fip_mac;
  8972. if (IS_MF(bp)) {
  8973. /* iSCSI and FCoE NPAR MACs: if there is no either iSCSI or
  8974. * FCoE MAC then the appropriate feature should be disabled.
  8975. * In non SD mode features configuration comes from struct
  8976. * func_ext_config.
  8977. */
  8978. if (!IS_MF_SD(bp) && !CHIP_IS_E1x(bp)) {
  8979. u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
  8980. if (cfg & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) {
  8981. val2 = MF_CFG_RD(bp, func_ext_config[func].
  8982. iscsi_mac_addr_upper);
  8983. val = MF_CFG_RD(bp, func_ext_config[func].
  8984. iscsi_mac_addr_lower);
  8985. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  8986. BNX2X_DEV_INFO
  8987. ("Read iSCSI MAC: %pM\n", iscsi_mac);
  8988. } else {
  8989. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  8990. }
  8991. if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) {
  8992. val2 = MF_CFG_RD(bp, func_ext_config[func].
  8993. fcoe_mac_addr_upper);
  8994. val = MF_CFG_RD(bp, func_ext_config[func].
  8995. fcoe_mac_addr_lower);
  8996. bnx2x_set_mac_buf(fip_mac, val, val2);
  8997. BNX2X_DEV_INFO
  8998. ("Read FCoE L2 MAC: %pM\n", fip_mac);
  8999. } else {
  9000. bp->flags |= NO_FCOE_FLAG;
  9001. }
  9002. bp->mf_ext_config = cfg;
  9003. } else { /* SD MODE */
  9004. if (BNX2X_IS_MF_SD_PROTOCOL_ISCSI(bp)) {
  9005. /* use primary mac as iscsi mac */
  9006. memcpy(iscsi_mac, bp->dev->dev_addr, ETH_ALEN);
  9007. BNX2X_DEV_INFO("SD ISCSI MODE\n");
  9008. BNX2X_DEV_INFO
  9009. ("Read iSCSI MAC: %pM\n", iscsi_mac);
  9010. } else if (BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp)) {
  9011. /* use primary mac as fip mac */
  9012. memcpy(fip_mac, bp->dev->dev_addr, ETH_ALEN);
  9013. BNX2X_DEV_INFO("SD FCoE MODE\n");
  9014. BNX2X_DEV_INFO
  9015. ("Read FIP MAC: %pM\n", fip_mac);
  9016. }
  9017. }
  9018. if (IS_MF_STORAGE_SD(bp))
  9019. /* Zero primary MAC configuration */
  9020. memset(bp->dev->dev_addr, 0, ETH_ALEN);
  9021. if (IS_MF_FCOE_AFEX(bp) || IS_MF_FCOE_SD(bp))
  9022. /* use FIP MAC as primary MAC */
  9023. memcpy(bp->dev->dev_addr, fip_mac, ETH_ALEN);
  9024. } else {
  9025. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9026. iscsi_mac_upper);
  9027. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9028. iscsi_mac_lower);
  9029. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  9030. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9031. fcoe_fip_mac_upper);
  9032. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9033. fcoe_fip_mac_lower);
  9034. bnx2x_set_mac_buf(fip_mac, val, val2);
  9035. }
  9036. /* Disable iSCSI OOO if MAC configuration is invalid. */
  9037. if (!is_valid_ether_addr(iscsi_mac)) {
  9038. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  9039. memset(iscsi_mac, 0, ETH_ALEN);
  9040. }
  9041. /* Disable FCoE if MAC configuration is invalid. */
  9042. if (!is_valid_ether_addr(fip_mac)) {
  9043. bp->flags |= NO_FCOE_FLAG;
  9044. memset(bp->fip_mac, 0, ETH_ALEN);
  9045. }
  9046. }
  9047. static void bnx2x_get_mac_hwinfo(struct bnx2x *bp)
  9048. {
  9049. u32 val, val2;
  9050. int func = BP_ABS_FUNC(bp);
  9051. int port = BP_PORT(bp);
  9052. /* Zero primary MAC configuration */
  9053. memset(bp->dev->dev_addr, 0, ETH_ALEN);
  9054. if (BP_NOMCP(bp)) {
  9055. BNX2X_ERROR("warning: random MAC workaround active\n");
  9056. eth_hw_addr_random(bp->dev);
  9057. } else if (IS_MF(bp)) {
  9058. val2 = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
  9059. val = MF_CFG_RD(bp, func_mf_config[func].mac_lower);
  9060. if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) &&
  9061. (val != FUNC_MF_CFG_LOWERMAC_DEFAULT))
  9062. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  9063. if (CNIC_SUPPORT(bp))
  9064. bnx2x_get_cnic_mac_hwinfo(bp);
  9065. } else {
  9066. /* in SF read MACs from port configuration */
  9067. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
  9068. val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
  9069. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  9070. if (CNIC_SUPPORT(bp))
  9071. bnx2x_get_cnic_mac_hwinfo(bp);
  9072. }
  9073. memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN);
  9074. if (!bnx2x_is_valid_ether_addr(bp, bp->dev->dev_addr))
  9075. dev_err(&bp->pdev->dev,
  9076. "bad Ethernet MAC address configuration: %pM\n"
  9077. "change it manually before bringing up the appropriate network interface\n",
  9078. bp->dev->dev_addr);
  9079. }
  9080. static bool bnx2x_get_dropless_info(struct bnx2x *bp)
  9081. {
  9082. int tmp;
  9083. u32 cfg;
  9084. if (IS_MF(bp) && !CHIP_IS_E1x(bp)) {
  9085. /* Take function: tmp = func */
  9086. tmp = BP_ABS_FUNC(bp);
  9087. cfg = MF_CFG_RD(bp, func_ext_config[tmp].func_cfg);
  9088. cfg = !!(cfg & MACP_FUNC_CFG_PAUSE_ON_HOST_RING);
  9089. } else {
  9090. /* Take port: tmp = port */
  9091. tmp = BP_PORT(bp);
  9092. cfg = SHMEM_RD(bp,
  9093. dev_info.port_hw_config[tmp].generic_features);
  9094. cfg = !!(cfg & PORT_HW_CFG_PAUSE_ON_HOST_RING_ENABLED);
  9095. }
  9096. return cfg;
  9097. }
  9098. static int bnx2x_get_hwinfo(struct bnx2x *bp)
  9099. {
  9100. int /*abs*/func = BP_ABS_FUNC(bp);
  9101. int vn;
  9102. u32 val = 0;
  9103. int rc = 0;
  9104. bnx2x_get_common_hwinfo(bp);
  9105. /*
  9106. * initialize IGU parameters
  9107. */
  9108. if (CHIP_IS_E1x(bp)) {
  9109. bp->common.int_block = INT_BLOCK_HC;
  9110. bp->igu_dsb_id = DEF_SB_IGU_ID;
  9111. bp->igu_base_sb = 0;
  9112. } else {
  9113. bp->common.int_block = INT_BLOCK_IGU;
  9114. /* do not allow device reset during IGU info preocessing */
  9115. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  9116. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  9117. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  9118. int tout = 5000;
  9119. BNX2X_DEV_INFO("FORCING Normal Mode\n");
  9120. val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN);
  9121. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION, val);
  9122. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x7f);
  9123. while (tout && REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  9124. tout--;
  9125. usleep_range(1000, 1000);
  9126. }
  9127. if (REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  9128. dev_err(&bp->pdev->dev,
  9129. "FORCING Normal Mode failed!!!\n");
  9130. bnx2x_release_hw_lock(bp,
  9131. HW_LOCK_RESOURCE_RESET);
  9132. return -EPERM;
  9133. }
  9134. }
  9135. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  9136. BNX2X_DEV_INFO("IGU Backward Compatible Mode\n");
  9137. bp->common.int_block |= INT_BLOCK_MODE_BW_COMP;
  9138. } else
  9139. BNX2X_DEV_INFO("IGU Normal Mode\n");
  9140. rc = bnx2x_get_igu_cam_info(bp);
  9141. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  9142. if (rc)
  9143. return rc;
  9144. }
  9145. /*
  9146. * set base FW non-default (fast path) status block id, this value is
  9147. * used to initialize the fw_sb_id saved on the fp/queue structure to
  9148. * determine the id used by the FW.
  9149. */
  9150. if (CHIP_IS_E1x(bp))
  9151. bp->base_fw_ndsb = BP_PORT(bp) * FP_SB_MAX_E1x + BP_L_ID(bp);
  9152. else /*
  9153. * 57712 - we currently use one FW SB per IGU SB (Rx and Tx of
  9154. * the same queue are indicated on the same IGU SB). So we prefer
  9155. * FW and IGU SBs to be the same value.
  9156. */
  9157. bp->base_fw_ndsb = bp->igu_base_sb;
  9158. BNX2X_DEV_INFO("igu_dsb_id %d igu_base_sb %d igu_sb_cnt %d\n"
  9159. "base_fw_ndsb %d\n", bp->igu_dsb_id, bp->igu_base_sb,
  9160. bp->igu_sb_cnt, bp->base_fw_ndsb);
  9161. /*
  9162. * Initialize MF configuration
  9163. */
  9164. bp->mf_ov = 0;
  9165. bp->mf_mode = 0;
  9166. vn = BP_VN(bp);
  9167. if (!CHIP_IS_E1(bp) && !BP_NOMCP(bp)) {
  9168. BNX2X_DEV_INFO("shmem2base 0x%x, size %d, mfcfg offset %d\n",
  9169. bp->common.shmem2_base, SHMEM2_RD(bp, size),
  9170. (u32)offsetof(struct shmem2_region, mf_cfg_addr));
  9171. if (SHMEM2_HAS(bp, mf_cfg_addr))
  9172. bp->common.mf_cfg_base = SHMEM2_RD(bp, mf_cfg_addr);
  9173. else
  9174. bp->common.mf_cfg_base = bp->common.shmem_base +
  9175. offsetof(struct shmem_region, func_mb) +
  9176. E1H_FUNC_MAX * sizeof(struct drv_func_mb);
  9177. /*
  9178. * get mf configuration:
  9179. * 1. existence of MF configuration
  9180. * 2. MAC address must be legal (check only upper bytes)
  9181. * for Switch-Independent mode;
  9182. * OVLAN must be legal for Switch-Dependent mode
  9183. * 3. SF_MODE configures specific MF mode
  9184. */
  9185. if (bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  9186. /* get mf configuration */
  9187. val = SHMEM_RD(bp,
  9188. dev_info.shared_feature_config.config);
  9189. val &= SHARED_FEAT_CFG_FORCE_SF_MODE_MASK;
  9190. switch (val) {
  9191. case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT:
  9192. val = MF_CFG_RD(bp, func_mf_config[func].
  9193. mac_upper);
  9194. /* check for legal mac (upper bytes)*/
  9195. if (val != 0xffff) {
  9196. bp->mf_mode = MULTI_FUNCTION_SI;
  9197. bp->mf_config[vn] = MF_CFG_RD(bp,
  9198. func_mf_config[func].config);
  9199. } else
  9200. BNX2X_DEV_INFO("illegal MAC address for SI\n");
  9201. break;
  9202. case SHARED_FEAT_CFG_FORCE_SF_MODE_AFEX_MODE:
  9203. if ((!CHIP_IS_E1x(bp)) &&
  9204. (MF_CFG_RD(bp, func_mf_config[func].
  9205. mac_upper) != 0xffff) &&
  9206. (SHMEM2_HAS(bp,
  9207. afex_driver_support))) {
  9208. bp->mf_mode = MULTI_FUNCTION_AFEX;
  9209. bp->mf_config[vn] = MF_CFG_RD(bp,
  9210. func_mf_config[func].config);
  9211. } else {
  9212. BNX2X_DEV_INFO("can not configure afex mode\n");
  9213. }
  9214. break;
  9215. case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED:
  9216. /* get OV configuration */
  9217. val = MF_CFG_RD(bp,
  9218. func_mf_config[FUNC_0].e1hov_tag);
  9219. val &= FUNC_MF_CFG_E1HOV_TAG_MASK;
  9220. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  9221. bp->mf_mode = MULTI_FUNCTION_SD;
  9222. bp->mf_config[vn] = MF_CFG_RD(bp,
  9223. func_mf_config[func].config);
  9224. } else
  9225. BNX2X_DEV_INFO("illegal OV for SD\n");
  9226. break;
  9227. default:
  9228. /* Unknown configuration: reset mf_config */
  9229. bp->mf_config[vn] = 0;
  9230. BNX2X_DEV_INFO("unknown MF mode 0x%x\n", val);
  9231. }
  9232. }
  9233. BNX2X_DEV_INFO("%s function mode\n",
  9234. IS_MF(bp) ? "multi" : "single");
  9235. switch (bp->mf_mode) {
  9236. case MULTI_FUNCTION_SD:
  9237. val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  9238. FUNC_MF_CFG_E1HOV_TAG_MASK;
  9239. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  9240. bp->mf_ov = val;
  9241. bp->path_has_ovlan = true;
  9242. BNX2X_DEV_INFO("MF OV for func %d is %d (0x%04x)\n",
  9243. func, bp->mf_ov, bp->mf_ov);
  9244. } else {
  9245. dev_err(&bp->pdev->dev,
  9246. "No valid MF OV for func %d, aborting\n",
  9247. func);
  9248. return -EPERM;
  9249. }
  9250. break;
  9251. case MULTI_FUNCTION_AFEX:
  9252. BNX2X_DEV_INFO("func %d is in MF afex mode\n", func);
  9253. break;
  9254. case MULTI_FUNCTION_SI:
  9255. BNX2X_DEV_INFO("func %d is in MF switch-independent mode\n",
  9256. func);
  9257. break;
  9258. default:
  9259. if (vn) {
  9260. dev_err(&bp->pdev->dev,
  9261. "VN %d is in a single function mode, aborting\n",
  9262. vn);
  9263. return -EPERM;
  9264. }
  9265. break;
  9266. }
  9267. /* check if other port on the path needs ovlan:
  9268. * Since MF configuration is shared between ports
  9269. * Possible mixed modes are only
  9270. * {SF, SI} {SF, SD} {SD, SF} {SI, SF}
  9271. */
  9272. if (CHIP_MODE_IS_4_PORT(bp) &&
  9273. !bp->path_has_ovlan &&
  9274. !IS_MF(bp) &&
  9275. bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  9276. u8 other_port = !BP_PORT(bp);
  9277. u8 other_func = BP_PATH(bp) + 2*other_port;
  9278. val = MF_CFG_RD(bp,
  9279. func_mf_config[other_func].e1hov_tag);
  9280. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT)
  9281. bp->path_has_ovlan = true;
  9282. }
  9283. }
  9284. /* adjust igu_sb_cnt to MF for E1x */
  9285. if (CHIP_IS_E1x(bp) && IS_MF(bp))
  9286. bp->igu_sb_cnt /= E1HVN_MAX;
  9287. /* port info */
  9288. bnx2x_get_port_hwinfo(bp);
  9289. /* Get MAC addresses */
  9290. bnx2x_get_mac_hwinfo(bp);
  9291. bnx2x_get_cnic_info(bp);
  9292. return rc;
  9293. }
  9294. static void bnx2x_read_fwinfo(struct bnx2x *bp)
  9295. {
  9296. int cnt, i, block_end, rodi;
  9297. char vpd_start[BNX2X_VPD_LEN+1];
  9298. char str_id_reg[VENDOR_ID_LEN+1];
  9299. char str_id_cap[VENDOR_ID_LEN+1];
  9300. char *vpd_data;
  9301. char *vpd_extended_data = NULL;
  9302. u8 len;
  9303. cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_start);
  9304. memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
  9305. if (cnt < BNX2X_VPD_LEN)
  9306. goto out_not_found;
  9307. /* VPD RO tag should be first tag after identifier string, hence
  9308. * we should be able to find it in first BNX2X_VPD_LEN chars
  9309. */
  9310. i = pci_vpd_find_tag(vpd_start, 0, BNX2X_VPD_LEN,
  9311. PCI_VPD_LRDT_RO_DATA);
  9312. if (i < 0)
  9313. goto out_not_found;
  9314. block_end = i + PCI_VPD_LRDT_TAG_SIZE +
  9315. pci_vpd_lrdt_size(&vpd_start[i]);
  9316. i += PCI_VPD_LRDT_TAG_SIZE;
  9317. if (block_end > BNX2X_VPD_LEN) {
  9318. vpd_extended_data = kmalloc(block_end, GFP_KERNEL);
  9319. if (vpd_extended_data == NULL)
  9320. goto out_not_found;
  9321. /* read rest of vpd image into vpd_extended_data */
  9322. memcpy(vpd_extended_data, vpd_start, BNX2X_VPD_LEN);
  9323. cnt = pci_read_vpd(bp->pdev, BNX2X_VPD_LEN,
  9324. block_end - BNX2X_VPD_LEN,
  9325. vpd_extended_data + BNX2X_VPD_LEN);
  9326. if (cnt < (block_end - BNX2X_VPD_LEN))
  9327. goto out_not_found;
  9328. vpd_data = vpd_extended_data;
  9329. } else
  9330. vpd_data = vpd_start;
  9331. /* now vpd_data holds full vpd content in both cases */
  9332. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  9333. PCI_VPD_RO_KEYWORD_MFR_ID);
  9334. if (rodi < 0)
  9335. goto out_not_found;
  9336. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  9337. if (len != VENDOR_ID_LEN)
  9338. goto out_not_found;
  9339. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  9340. /* vendor specific info */
  9341. snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL);
  9342. snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL);
  9343. if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) ||
  9344. !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) {
  9345. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  9346. PCI_VPD_RO_KEYWORD_VENDOR0);
  9347. if (rodi >= 0) {
  9348. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  9349. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  9350. if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) {
  9351. memcpy(bp->fw_ver, &vpd_data[rodi], len);
  9352. bp->fw_ver[len] = ' ';
  9353. }
  9354. }
  9355. kfree(vpd_extended_data);
  9356. return;
  9357. }
  9358. out_not_found:
  9359. kfree(vpd_extended_data);
  9360. return;
  9361. }
  9362. static void bnx2x_set_modes_bitmap(struct bnx2x *bp)
  9363. {
  9364. u32 flags = 0;
  9365. if (CHIP_REV_IS_FPGA(bp))
  9366. SET_FLAGS(flags, MODE_FPGA);
  9367. else if (CHIP_REV_IS_EMUL(bp))
  9368. SET_FLAGS(flags, MODE_EMUL);
  9369. else
  9370. SET_FLAGS(flags, MODE_ASIC);
  9371. if (CHIP_MODE_IS_4_PORT(bp))
  9372. SET_FLAGS(flags, MODE_PORT4);
  9373. else
  9374. SET_FLAGS(flags, MODE_PORT2);
  9375. if (CHIP_IS_E2(bp))
  9376. SET_FLAGS(flags, MODE_E2);
  9377. else if (CHIP_IS_E3(bp)) {
  9378. SET_FLAGS(flags, MODE_E3);
  9379. if (CHIP_REV(bp) == CHIP_REV_Ax)
  9380. SET_FLAGS(flags, MODE_E3_A0);
  9381. else /*if (CHIP_REV(bp) == CHIP_REV_Bx)*/
  9382. SET_FLAGS(flags, MODE_E3_B0 | MODE_COS3);
  9383. }
  9384. if (IS_MF(bp)) {
  9385. SET_FLAGS(flags, MODE_MF);
  9386. switch (bp->mf_mode) {
  9387. case MULTI_FUNCTION_SD:
  9388. SET_FLAGS(flags, MODE_MF_SD);
  9389. break;
  9390. case MULTI_FUNCTION_SI:
  9391. SET_FLAGS(flags, MODE_MF_SI);
  9392. break;
  9393. case MULTI_FUNCTION_AFEX:
  9394. SET_FLAGS(flags, MODE_MF_AFEX);
  9395. break;
  9396. }
  9397. } else
  9398. SET_FLAGS(flags, MODE_SF);
  9399. #if defined(__LITTLE_ENDIAN)
  9400. SET_FLAGS(flags, MODE_LITTLE_ENDIAN);
  9401. #else /*(__BIG_ENDIAN)*/
  9402. SET_FLAGS(flags, MODE_BIG_ENDIAN);
  9403. #endif
  9404. INIT_MODE_FLAGS(bp) = flags;
  9405. }
  9406. static int bnx2x_init_bp(struct bnx2x *bp)
  9407. {
  9408. int func;
  9409. int rc;
  9410. mutex_init(&bp->port.phy_mutex);
  9411. mutex_init(&bp->fw_mb_mutex);
  9412. spin_lock_init(&bp->stats_lock);
  9413. INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task);
  9414. INIT_DELAYED_WORK(&bp->sp_rtnl_task, bnx2x_sp_rtnl_task);
  9415. INIT_DELAYED_WORK(&bp->period_task, bnx2x_period_task);
  9416. if (IS_PF(bp)) {
  9417. rc = bnx2x_get_hwinfo(bp);
  9418. if (rc)
  9419. return rc;
  9420. } else {
  9421. random_ether_addr(bp->dev->dev_addr);
  9422. }
  9423. bnx2x_set_modes_bitmap(bp);
  9424. rc = bnx2x_alloc_mem_bp(bp);
  9425. if (rc)
  9426. return rc;
  9427. bnx2x_read_fwinfo(bp);
  9428. func = BP_FUNC(bp);
  9429. /* need to reset chip if undi was active */
  9430. if (IS_PF(bp) && !BP_NOMCP(bp)) {
  9431. /* init fw_seq */
  9432. bp->fw_seq =
  9433. SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
  9434. DRV_MSG_SEQ_NUMBER_MASK;
  9435. BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
  9436. bnx2x_prev_unload(bp);
  9437. }
  9438. if (CHIP_REV_IS_FPGA(bp))
  9439. dev_err(&bp->pdev->dev, "FPGA detected\n");
  9440. if (BP_NOMCP(bp) && (func == 0))
  9441. dev_err(&bp->pdev->dev, "MCP disabled, must load devices in order!\n");
  9442. bp->disable_tpa = disable_tpa;
  9443. bp->disable_tpa |= IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp);
  9444. /* Set TPA flags */
  9445. if (bp->disable_tpa) {
  9446. bp->flags &= ~(TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
  9447. bp->dev->features &= ~NETIF_F_LRO;
  9448. } else {
  9449. bp->flags |= (TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
  9450. bp->dev->features |= NETIF_F_LRO;
  9451. }
  9452. if (CHIP_IS_E1(bp))
  9453. bp->dropless_fc = 0;
  9454. else
  9455. bp->dropless_fc = dropless_fc | bnx2x_get_dropless_info(bp);
  9456. bp->mrrs = mrrs;
  9457. bp->tx_ring_size = IS_MF_FCOE_AFEX(bp) ? 0 : MAX_TX_AVAIL;
  9458. if (IS_VF(bp))
  9459. bp->rx_ring_size = MAX_RX_AVAIL;
  9460. /* make sure that the numbers are in the right granularity */
  9461. bp->tx_ticks = (50 / BNX2X_BTR) * BNX2X_BTR;
  9462. bp->rx_ticks = (25 / BNX2X_BTR) * BNX2X_BTR;
  9463. bp->current_interval = CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ;
  9464. init_timer(&bp->timer);
  9465. bp->timer.expires = jiffies + bp->current_interval;
  9466. bp->timer.data = (unsigned long) bp;
  9467. bp->timer.function = bnx2x_timer;
  9468. if (SHMEM2_HAS(bp, dcbx_lldp_params_offset) &&
  9469. SHMEM2_HAS(bp, dcbx_lldp_dcbx_stat_offset) &&
  9470. SHMEM2_RD(bp, dcbx_lldp_params_offset) &&
  9471. SHMEM2_RD(bp, dcbx_lldp_dcbx_stat_offset)) {
  9472. bnx2x_dcbx_set_state(bp, true, BNX2X_DCBX_ENABLED_ON_NEG_ON);
  9473. bnx2x_dcbx_init_params(bp);
  9474. } else {
  9475. bnx2x_dcbx_set_state(bp, false, BNX2X_DCBX_ENABLED_OFF);
  9476. }
  9477. if (CHIP_IS_E1x(bp))
  9478. bp->cnic_base_cl_id = FP_SB_MAX_E1x;
  9479. else
  9480. bp->cnic_base_cl_id = FP_SB_MAX_E2;
  9481. /* multiple tx priority */
  9482. if (IS_VF(bp))
  9483. bp->max_cos = 1;
  9484. else if (CHIP_IS_E1x(bp))
  9485. bp->max_cos = BNX2X_MULTI_TX_COS_E1X;
  9486. else if (CHIP_IS_E2(bp) || CHIP_IS_E3A0(bp))
  9487. bp->max_cos = BNX2X_MULTI_TX_COS_E2_E3A0;
  9488. else if (CHIP_IS_E3B0(bp))
  9489. bp->max_cos = BNX2X_MULTI_TX_COS_E3B0;
  9490. else
  9491. BNX2X_ERR("unknown chip %x revision %x\n",
  9492. CHIP_NUM(bp), CHIP_REV(bp));
  9493. BNX2X_DEV_INFO("set bp->max_cos to %d\n", bp->max_cos);
  9494. /* We need at least one default status block for slow-path events,
  9495. * second status block for the L2 queue, and a third status block for
  9496. * CNIC if supproted.
  9497. */
  9498. if (CNIC_SUPPORT(bp))
  9499. bp->min_msix_vec_cnt = 3;
  9500. else
  9501. bp->min_msix_vec_cnt = 2;
  9502. BNX2X_DEV_INFO("bp->min_msix_vec_cnt %d", bp->min_msix_vec_cnt);
  9503. return rc;
  9504. }
  9505. /****************************************************************************
  9506. * General service functions
  9507. ****************************************************************************/
  9508. /*
  9509. * net_device service functions
  9510. */
  9511. static int bnx2x_open_epilog(struct bnx2x *bp)
  9512. {
  9513. /* Enable sriov via delayed work. This must be done via delayed work
  9514. * because it causes the probe of the vf devices to be run, which invoke
  9515. * register_netdevice which must have rtnl lock taken. As we are holding
  9516. * the lock right now, that could only work if the probe would not take
  9517. * the lock. However, as the probe of the vf may be called from other
  9518. * contexts as well (such as passthrough to vm failes) it can't assume
  9519. * the lock is being held for it. Using delayed work here allows the
  9520. * probe code to simply take the lock (i.e. wait for it to be released
  9521. * if it is being held).
  9522. */
  9523. smp_mb__before_clear_bit();
  9524. set_bit(BNX2X_SP_RTNL_ENABLE_SRIOV, &bp->sp_rtnl_state);
  9525. smp_mb__after_clear_bit();
  9526. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  9527. return 0;
  9528. }
  9529. /* called with rtnl_lock */
  9530. static int bnx2x_open(struct net_device *dev)
  9531. {
  9532. struct bnx2x *bp = netdev_priv(dev);
  9533. bool global = false;
  9534. int other_engine = BP_PATH(bp) ? 0 : 1;
  9535. bool other_load_status, load_status;
  9536. int rc;
  9537. bp->stats_init = true;
  9538. netif_carrier_off(dev);
  9539. bnx2x_set_power_state(bp, PCI_D0);
  9540. /* If parity had happen during the unload, then attentions
  9541. * and/or RECOVERY_IN_PROGRES may still be set. In this case we
  9542. * want the first function loaded on the current engine to
  9543. * complete the recovery.
  9544. * Parity recovery is only relevant for PF driver.
  9545. */
  9546. if (IS_PF(bp)) {
  9547. other_load_status = bnx2x_get_load_status(bp, other_engine);
  9548. load_status = bnx2x_get_load_status(bp, BP_PATH(bp));
  9549. if (!bnx2x_reset_is_done(bp, BP_PATH(bp)) ||
  9550. bnx2x_chk_parity_attn(bp, &global, true)) {
  9551. do {
  9552. /* If there are attentions and they are in a
  9553. * global blocks, set the GLOBAL_RESET bit
  9554. * regardless whether it will be this function
  9555. * that will complete the recovery or not.
  9556. */
  9557. if (global)
  9558. bnx2x_set_reset_global(bp);
  9559. /* Only the first function on the current
  9560. * engine should try to recover in open. In case
  9561. * of attentions in global blocks only the first
  9562. * in the chip should try to recover.
  9563. */
  9564. if ((!load_status &&
  9565. (!global || !other_load_status)) &&
  9566. bnx2x_trylock_leader_lock(bp) &&
  9567. !bnx2x_leader_reset(bp)) {
  9568. netdev_info(bp->dev,
  9569. "Recovered in open\n");
  9570. break;
  9571. }
  9572. /* recovery has failed... */
  9573. bnx2x_set_power_state(bp, PCI_D3hot);
  9574. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  9575. BNX2X_ERR("Recovery flow hasn't been properly completed yet. Try again later.\n"
  9576. "If you still see this message after a few retries then power cycle is required.\n");
  9577. return -EAGAIN;
  9578. } while (0);
  9579. }
  9580. }
  9581. bp->recovery_state = BNX2X_RECOVERY_DONE;
  9582. rc = bnx2x_nic_load(bp, LOAD_OPEN);
  9583. if (rc)
  9584. return rc;
  9585. return bnx2x_open_epilog(bp);
  9586. }
  9587. /* called with rtnl_lock */
  9588. static int bnx2x_close(struct net_device *dev)
  9589. {
  9590. struct bnx2x *bp = netdev_priv(dev);
  9591. /* Unload the driver, release IRQs */
  9592. bnx2x_nic_unload(bp, UNLOAD_CLOSE, false);
  9593. /* Power off */
  9594. bnx2x_set_power_state(bp, PCI_D3hot);
  9595. return 0;
  9596. }
  9597. static int bnx2x_init_mcast_macs_list(struct bnx2x *bp,
  9598. struct bnx2x_mcast_ramrod_params *p)
  9599. {
  9600. int mc_count = netdev_mc_count(bp->dev);
  9601. struct bnx2x_mcast_list_elem *mc_mac =
  9602. kzalloc(sizeof(*mc_mac) * mc_count, GFP_ATOMIC);
  9603. struct netdev_hw_addr *ha;
  9604. if (!mc_mac)
  9605. return -ENOMEM;
  9606. INIT_LIST_HEAD(&p->mcast_list);
  9607. netdev_for_each_mc_addr(ha, bp->dev) {
  9608. mc_mac->mac = bnx2x_mc_addr(ha);
  9609. list_add_tail(&mc_mac->link, &p->mcast_list);
  9610. mc_mac++;
  9611. }
  9612. p->mcast_list_len = mc_count;
  9613. return 0;
  9614. }
  9615. static void bnx2x_free_mcast_macs_list(
  9616. struct bnx2x_mcast_ramrod_params *p)
  9617. {
  9618. struct bnx2x_mcast_list_elem *mc_mac =
  9619. list_first_entry(&p->mcast_list, struct bnx2x_mcast_list_elem,
  9620. link);
  9621. WARN_ON(!mc_mac);
  9622. kfree(mc_mac);
  9623. }
  9624. /**
  9625. * bnx2x_set_uc_list - configure a new unicast MACs list.
  9626. *
  9627. * @bp: driver handle
  9628. *
  9629. * We will use zero (0) as a MAC type for these MACs.
  9630. */
  9631. static int bnx2x_set_uc_list(struct bnx2x *bp)
  9632. {
  9633. int rc;
  9634. struct net_device *dev = bp->dev;
  9635. struct netdev_hw_addr *ha;
  9636. struct bnx2x_vlan_mac_obj *mac_obj = &bp->sp_objs->mac_obj;
  9637. unsigned long ramrod_flags = 0;
  9638. /* First schedule a cleanup up of old configuration */
  9639. rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, false);
  9640. if (rc < 0) {
  9641. BNX2X_ERR("Failed to schedule DELETE operations: %d\n", rc);
  9642. return rc;
  9643. }
  9644. netdev_for_each_uc_addr(ha, dev) {
  9645. rc = bnx2x_set_mac_one(bp, bnx2x_uc_addr(ha), mac_obj, true,
  9646. BNX2X_UC_LIST_MAC, &ramrod_flags);
  9647. if (rc == -EEXIST) {
  9648. DP(BNX2X_MSG_SP,
  9649. "Failed to schedule ADD operations: %d\n", rc);
  9650. /* do not treat adding same MAC as error */
  9651. rc = 0;
  9652. } else if (rc < 0) {
  9653. BNX2X_ERR("Failed to schedule ADD operations: %d\n",
  9654. rc);
  9655. return rc;
  9656. }
  9657. }
  9658. /* Execute the pending commands */
  9659. __set_bit(RAMROD_CONT, &ramrod_flags);
  9660. return bnx2x_set_mac_one(bp, NULL, mac_obj, false /* don't care */,
  9661. BNX2X_UC_LIST_MAC, &ramrod_flags);
  9662. }
  9663. static int bnx2x_set_mc_list(struct bnx2x *bp)
  9664. {
  9665. struct net_device *dev = bp->dev;
  9666. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  9667. int rc = 0;
  9668. rparam.mcast_obj = &bp->mcast_obj;
  9669. /* first, clear all configured multicast MACs */
  9670. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  9671. if (rc < 0) {
  9672. BNX2X_ERR("Failed to clear multicast configuration: %d\n", rc);
  9673. return rc;
  9674. }
  9675. /* then, configure a new MACs list */
  9676. if (netdev_mc_count(dev)) {
  9677. rc = bnx2x_init_mcast_macs_list(bp, &rparam);
  9678. if (rc) {
  9679. BNX2X_ERR("Failed to create multicast MACs list: %d\n",
  9680. rc);
  9681. return rc;
  9682. }
  9683. /* Now add the new MACs */
  9684. rc = bnx2x_config_mcast(bp, &rparam,
  9685. BNX2X_MCAST_CMD_ADD);
  9686. if (rc < 0)
  9687. BNX2X_ERR("Failed to set a new multicast configuration: %d\n",
  9688. rc);
  9689. bnx2x_free_mcast_macs_list(&rparam);
  9690. }
  9691. return rc;
  9692. }
  9693. /* If bp->state is OPEN, should be called with netif_addr_lock_bh() */
  9694. void bnx2x_set_rx_mode(struct net_device *dev)
  9695. {
  9696. struct bnx2x *bp = netdev_priv(dev);
  9697. u32 rx_mode = BNX2X_RX_MODE_NORMAL;
  9698. if (bp->state != BNX2X_STATE_OPEN) {
  9699. DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
  9700. return;
  9701. }
  9702. DP(NETIF_MSG_IFUP, "dev->flags = %x\n", bp->dev->flags);
  9703. if (dev->flags & IFF_PROMISC)
  9704. rx_mode = BNX2X_RX_MODE_PROMISC;
  9705. else if ((dev->flags & IFF_ALLMULTI) ||
  9706. ((netdev_mc_count(dev) > BNX2X_MAX_MULTICAST) &&
  9707. CHIP_IS_E1(bp)))
  9708. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  9709. else {
  9710. if (IS_PF(bp)) {
  9711. /* some multicasts */
  9712. if (bnx2x_set_mc_list(bp) < 0)
  9713. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  9714. if (bnx2x_set_uc_list(bp) < 0)
  9715. rx_mode = BNX2X_RX_MODE_PROMISC;
  9716. } else {
  9717. /* configuring mcast to a vf involves sleeping (when we
  9718. * wait for the pf's response). Since this function is
  9719. * called from non sleepable context we must schedule
  9720. * a work item for this purpose
  9721. */
  9722. smp_mb__before_clear_bit();
  9723. set_bit(BNX2X_SP_RTNL_VFPF_MCAST,
  9724. &bp->sp_rtnl_state);
  9725. smp_mb__after_clear_bit();
  9726. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  9727. }
  9728. }
  9729. bp->rx_mode = rx_mode;
  9730. /* handle ISCSI SD mode */
  9731. if (IS_MF_ISCSI_SD(bp))
  9732. bp->rx_mode = BNX2X_RX_MODE_NONE;
  9733. /* Schedule the rx_mode command */
  9734. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) {
  9735. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  9736. return;
  9737. }
  9738. if (IS_PF(bp)) {
  9739. bnx2x_set_storm_rx_mode(bp);
  9740. } else {
  9741. /* configuring rx mode to storms in a vf involves sleeping (when
  9742. * we wait for the pf's response). Since this function is
  9743. * called from non sleepable context we must schedule
  9744. * a work item for this purpose
  9745. */
  9746. smp_mb__before_clear_bit();
  9747. set_bit(BNX2X_SP_RTNL_VFPF_STORM_RX_MODE,
  9748. &bp->sp_rtnl_state);
  9749. smp_mb__after_clear_bit();
  9750. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  9751. }
  9752. }
  9753. /* called with rtnl_lock */
  9754. static int bnx2x_mdio_read(struct net_device *netdev, int prtad,
  9755. int devad, u16 addr)
  9756. {
  9757. struct bnx2x *bp = netdev_priv(netdev);
  9758. u16 value;
  9759. int rc;
  9760. DP(NETIF_MSG_LINK, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n",
  9761. prtad, devad, addr);
  9762. /* The HW expects different devad if CL22 is used */
  9763. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  9764. bnx2x_acquire_phy_lock(bp);
  9765. rc = bnx2x_phy_read(&bp->link_params, prtad, devad, addr, &value);
  9766. bnx2x_release_phy_lock(bp);
  9767. DP(NETIF_MSG_LINK, "mdio_read_val 0x%x rc = 0x%x\n", value, rc);
  9768. if (!rc)
  9769. rc = value;
  9770. return rc;
  9771. }
  9772. /* called with rtnl_lock */
  9773. static int bnx2x_mdio_write(struct net_device *netdev, int prtad, int devad,
  9774. u16 addr, u16 value)
  9775. {
  9776. struct bnx2x *bp = netdev_priv(netdev);
  9777. int rc;
  9778. DP(NETIF_MSG_LINK,
  9779. "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x, value 0x%x\n",
  9780. prtad, devad, addr, value);
  9781. /* The HW expects different devad if CL22 is used */
  9782. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  9783. bnx2x_acquire_phy_lock(bp);
  9784. rc = bnx2x_phy_write(&bp->link_params, prtad, devad, addr, value);
  9785. bnx2x_release_phy_lock(bp);
  9786. return rc;
  9787. }
  9788. /* called with rtnl_lock */
  9789. static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  9790. {
  9791. struct bnx2x *bp = netdev_priv(dev);
  9792. struct mii_ioctl_data *mdio = if_mii(ifr);
  9793. DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n",
  9794. mdio->phy_id, mdio->reg_num, mdio->val_in);
  9795. if (!netif_running(dev))
  9796. return -EAGAIN;
  9797. return mdio_mii_ioctl(&bp->mdio, mdio, cmd);
  9798. }
  9799. #ifdef CONFIG_NET_POLL_CONTROLLER
  9800. static void poll_bnx2x(struct net_device *dev)
  9801. {
  9802. struct bnx2x *bp = netdev_priv(dev);
  9803. int i;
  9804. for_each_eth_queue(bp, i) {
  9805. struct bnx2x_fastpath *fp = &bp->fp[i];
  9806. napi_schedule(&bnx2x_fp(bp, fp->index, napi));
  9807. }
  9808. }
  9809. #endif
  9810. static int bnx2x_validate_addr(struct net_device *dev)
  9811. {
  9812. struct bnx2x *bp = netdev_priv(dev);
  9813. if (!bnx2x_is_valid_ether_addr(bp, dev->dev_addr)) {
  9814. BNX2X_ERR("Non-valid Ethernet address\n");
  9815. return -EADDRNOTAVAIL;
  9816. }
  9817. return 0;
  9818. }
  9819. static const struct net_device_ops bnx2x_netdev_ops = {
  9820. .ndo_open = bnx2x_open,
  9821. .ndo_stop = bnx2x_close,
  9822. .ndo_start_xmit = bnx2x_start_xmit,
  9823. .ndo_select_queue = bnx2x_select_queue,
  9824. .ndo_set_rx_mode = bnx2x_set_rx_mode,
  9825. .ndo_set_mac_address = bnx2x_change_mac_addr,
  9826. .ndo_validate_addr = bnx2x_validate_addr,
  9827. .ndo_do_ioctl = bnx2x_ioctl,
  9828. .ndo_change_mtu = bnx2x_change_mtu,
  9829. .ndo_fix_features = bnx2x_fix_features,
  9830. .ndo_set_features = bnx2x_set_features,
  9831. .ndo_tx_timeout = bnx2x_tx_timeout,
  9832. #ifdef CONFIG_NET_POLL_CONTROLLER
  9833. .ndo_poll_controller = poll_bnx2x,
  9834. #endif
  9835. .ndo_setup_tc = bnx2x_setup_tc,
  9836. #ifdef CONFIG_BNX2X_SRIOV
  9837. .ndo_set_vf_mac = bnx2x_set_vf_mac,
  9838. #endif
  9839. #ifdef NETDEV_FCOE_WWNN
  9840. .ndo_fcoe_get_wwn = bnx2x_fcoe_get_wwn,
  9841. #endif
  9842. };
  9843. static int bnx2x_set_coherency_mask(struct bnx2x *bp)
  9844. {
  9845. struct device *dev = &bp->pdev->dev;
  9846. if (dma_set_mask(dev, DMA_BIT_MASK(64)) == 0) {
  9847. bp->flags |= USING_DAC_FLAG;
  9848. if (dma_set_coherent_mask(dev, DMA_BIT_MASK(64)) != 0) {
  9849. dev_err(dev, "dma_set_coherent_mask failed, aborting\n");
  9850. return -EIO;
  9851. }
  9852. } else if (dma_set_mask(dev, DMA_BIT_MASK(32)) != 0) {
  9853. dev_err(dev, "System does not support DMA, aborting\n");
  9854. return -EIO;
  9855. }
  9856. return 0;
  9857. }
  9858. static int bnx2x_init_dev(struct bnx2x *bp, struct pci_dev *pdev,
  9859. struct net_device *dev, unsigned long board_type)
  9860. {
  9861. int rc;
  9862. u32 pci_cfg_dword;
  9863. bool chip_is_e1x = (board_type == BCM57710 ||
  9864. board_type == BCM57711 ||
  9865. board_type == BCM57711E);
  9866. SET_NETDEV_DEV(dev, &pdev->dev);
  9867. bp->dev = dev;
  9868. bp->pdev = pdev;
  9869. rc = pci_enable_device(pdev);
  9870. if (rc) {
  9871. dev_err(&bp->pdev->dev,
  9872. "Cannot enable PCI device, aborting\n");
  9873. goto err_out;
  9874. }
  9875. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  9876. dev_err(&bp->pdev->dev,
  9877. "Cannot find PCI device base address, aborting\n");
  9878. rc = -ENODEV;
  9879. goto err_out_disable;
  9880. }
  9881. if (IS_PF(bp) && !(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
  9882. dev_err(&bp->pdev->dev, "Cannot find second PCI device base address, aborting\n");
  9883. rc = -ENODEV;
  9884. goto err_out_disable;
  9885. }
  9886. pci_read_config_dword(pdev, PCICFG_REVISION_ID_OFFSET, &pci_cfg_dword);
  9887. if ((pci_cfg_dword & PCICFG_REVESION_ID_MASK) ==
  9888. PCICFG_REVESION_ID_ERROR_VAL) {
  9889. pr_err("PCI device error, probably due to fan failure, aborting\n");
  9890. rc = -ENODEV;
  9891. goto err_out_disable;
  9892. }
  9893. if (atomic_read(&pdev->enable_cnt) == 1) {
  9894. rc = pci_request_regions(pdev, DRV_MODULE_NAME);
  9895. if (rc) {
  9896. dev_err(&bp->pdev->dev,
  9897. "Cannot obtain PCI resources, aborting\n");
  9898. goto err_out_disable;
  9899. }
  9900. pci_set_master(pdev);
  9901. pci_save_state(pdev);
  9902. }
  9903. if (IS_PF(bp)) {
  9904. bp->pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
  9905. if (bp->pm_cap == 0) {
  9906. dev_err(&bp->pdev->dev,
  9907. "Cannot find power management capability, aborting\n");
  9908. rc = -EIO;
  9909. goto err_out_release;
  9910. }
  9911. }
  9912. if (!pci_is_pcie(pdev)) {
  9913. dev_err(&bp->pdev->dev, "Not PCI Express, aborting\n");
  9914. rc = -EIO;
  9915. goto err_out_release;
  9916. }
  9917. rc = bnx2x_set_coherency_mask(bp);
  9918. if (rc)
  9919. goto err_out_release;
  9920. dev->mem_start = pci_resource_start(pdev, 0);
  9921. dev->base_addr = dev->mem_start;
  9922. dev->mem_end = pci_resource_end(pdev, 0);
  9923. dev->irq = pdev->irq;
  9924. bp->regview = pci_ioremap_bar(pdev, 0);
  9925. if (!bp->regview) {
  9926. dev_err(&bp->pdev->dev,
  9927. "Cannot map register space, aborting\n");
  9928. rc = -ENOMEM;
  9929. goto err_out_release;
  9930. }
  9931. /* In E1/E1H use pci device function given by kernel.
  9932. * In E2/E3 read physical function from ME register since these chips
  9933. * support Physical Device Assignment where kernel BDF maybe arbitrary
  9934. * (depending on hypervisor).
  9935. */
  9936. if (chip_is_e1x)
  9937. bp->pf_num = PCI_FUNC(pdev->devfn);
  9938. else {/* chip is E2/3*/
  9939. pci_read_config_dword(bp->pdev,
  9940. PCICFG_ME_REGISTER, &pci_cfg_dword);
  9941. bp->pf_num = (u8)((pci_cfg_dword & ME_REG_ABS_PF_NUM) >>
  9942. ME_REG_ABS_PF_NUM_SHIFT);
  9943. }
  9944. BNX2X_DEV_INFO("me reg PF num: %d\n", bp->pf_num);
  9945. bnx2x_set_power_state(bp, PCI_D0);
  9946. /* clean indirect addresses */
  9947. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  9948. PCICFG_VENDOR_ID_OFFSET);
  9949. /*
  9950. * Clean the following indirect addresses for all functions since it
  9951. * is not used by the driver.
  9952. */
  9953. if (IS_PF(bp)) {
  9954. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0, 0);
  9955. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0, 0);
  9956. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0, 0);
  9957. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0, 0);
  9958. if (chip_is_e1x) {
  9959. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F1, 0);
  9960. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F1, 0);
  9961. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F1, 0);
  9962. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F1, 0);
  9963. }
  9964. /* Enable internal target-read (in case we are probed after PF
  9965. * FLR). Must be done prior to any BAR read access. Only for
  9966. * 57712 and up
  9967. */
  9968. if (!chip_is_e1x)
  9969. REG_WR(bp,
  9970. PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  9971. }
  9972. dev->watchdog_timeo = TX_TIMEOUT;
  9973. dev->netdev_ops = &bnx2x_netdev_ops;
  9974. bnx2x_set_ethtool_ops(dev);
  9975. dev->priv_flags |= IFF_UNICAST_FLT;
  9976. dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  9977. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
  9978. NETIF_F_RXCSUM | NETIF_F_LRO | NETIF_F_GRO |
  9979. NETIF_F_RXHASH | NETIF_F_HW_VLAN_TX;
  9980. dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  9981. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_HIGHDMA;
  9982. dev->features |= dev->hw_features | NETIF_F_HW_VLAN_RX;
  9983. if (bp->flags & USING_DAC_FLAG)
  9984. dev->features |= NETIF_F_HIGHDMA;
  9985. /* Add Loopback capability to the device */
  9986. dev->hw_features |= NETIF_F_LOOPBACK;
  9987. #ifdef BCM_DCBNL
  9988. dev->dcbnl_ops = &bnx2x_dcbnl_ops;
  9989. #endif
  9990. /* get_port_hwinfo() will set prtad and mmds properly */
  9991. bp->mdio.prtad = MDIO_PRTAD_NONE;
  9992. bp->mdio.mmds = 0;
  9993. bp->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
  9994. bp->mdio.dev = dev;
  9995. bp->mdio.mdio_read = bnx2x_mdio_read;
  9996. bp->mdio.mdio_write = bnx2x_mdio_write;
  9997. return 0;
  9998. err_out_release:
  9999. if (atomic_read(&pdev->enable_cnt) == 1)
  10000. pci_release_regions(pdev);
  10001. err_out_disable:
  10002. pci_disable_device(pdev);
  10003. pci_set_drvdata(pdev, NULL);
  10004. err_out:
  10005. return rc;
  10006. }
  10007. static void bnx2x_get_pcie_width_speed(struct bnx2x *bp, int *width, int *speed)
  10008. {
  10009. u32 val = 0;
  10010. pci_read_config_dword(bp->pdev, PCICFG_LINK_CONTROL, &val);
  10011. *width = (val & PCICFG_LINK_WIDTH) >> PCICFG_LINK_WIDTH_SHIFT;
  10012. /* return value of 1=2.5GHz 2=5GHz */
  10013. *speed = (val & PCICFG_LINK_SPEED) >> PCICFG_LINK_SPEED_SHIFT;
  10014. }
  10015. static int bnx2x_check_firmware(struct bnx2x *bp)
  10016. {
  10017. const struct firmware *firmware = bp->firmware;
  10018. struct bnx2x_fw_file_hdr *fw_hdr;
  10019. struct bnx2x_fw_file_section *sections;
  10020. u32 offset, len, num_ops;
  10021. u16 *ops_offsets;
  10022. int i;
  10023. const u8 *fw_ver;
  10024. if (firmware->size < sizeof(struct bnx2x_fw_file_hdr)) {
  10025. BNX2X_ERR("Wrong FW size\n");
  10026. return -EINVAL;
  10027. }
  10028. fw_hdr = (struct bnx2x_fw_file_hdr *)firmware->data;
  10029. sections = (struct bnx2x_fw_file_section *)fw_hdr;
  10030. /* Make sure none of the offsets and sizes make us read beyond
  10031. * the end of the firmware data */
  10032. for (i = 0; i < sizeof(*fw_hdr) / sizeof(*sections); i++) {
  10033. offset = be32_to_cpu(sections[i].offset);
  10034. len = be32_to_cpu(sections[i].len);
  10035. if (offset + len > firmware->size) {
  10036. BNX2X_ERR("Section %d length is out of bounds\n", i);
  10037. return -EINVAL;
  10038. }
  10039. }
  10040. /* Likewise for the init_ops offsets */
  10041. offset = be32_to_cpu(fw_hdr->init_ops_offsets.offset);
  10042. ops_offsets = (u16 *)(firmware->data + offset);
  10043. num_ops = be32_to_cpu(fw_hdr->init_ops.len) / sizeof(struct raw_op);
  10044. for (i = 0; i < be32_to_cpu(fw_hdr->init_ops_offsets.len) / 2; i++) {
  10045. if (be16_to_cpu(ops_offsets[i]) > num_ops) {
  10046. BNX2X_ERR("Section offset %d is out of bounds\n", i);
  10047. return -EINVAL;
  10048. }
  10049. }
  10050. /* Check FW version */
  10051. offset = be32_to_cpu(fw_hdr->fw_version.offset);
  10052. fw_ver = firmware->data + offset;
  10053. if ((fw_ver[0] != BCM_5710_FW_MAJOR_VERSION) ||
  10054. (fw_ver[1] != BCM_5710_FW_MINOR_VERSION) ||
  10055. (fw_ver[2] != BCM_5710_FW_REVISION_VERSION) ||
  10056. (fw_ver[3] != BCM_5710_FW_ENGINEERING_VERSION)) {
  10057. BNX2X_ERR("Bad FW version:%d.%d.%d.%d. Should be %d.%d.%d.%d\n",
  10058. fw_ver[0], fw_ver[1], fw_ver[2], fw_ver[3],
  10059. BCM_5710_FW_MAJOR_VERSION,
  10060. BCM_5710_FW_MINOR_VERSION,
  10061. BCM_5710_FW_REVISION_VERSION,
  10062. BCM_5710_FW_ENGINEERING_VERSION);
  10063. return -EINVAL;
  10064. }
  10065. return 0;
  10066. }
  10067. static void be32_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  10068. {
  10069. const __be32 *source = (const __be32 *)_source;
  10070. u32 *target = (u32 *)_target;
  10071. u32 i;
  10072. for (i = 0; i < n/4; i++)
  10073. target[i] = be32_to_cpu(source[i]);
  10074. }
  10075. /*
  10076. Ops array is stored in the following format:
  10077. {op(8bit), offset(24bit, big endian), data(32bit, big endian)}
  10078. */
  10079. static void bnx2x_prep_ops(const u8 *_source, u8 *_target, u32 n)
  10080. {
  10081. const __be32 *source = (const __be32 *)_source;
  10082. struct raw_op *target = (struct raw_op *)_target;
  10083. u32 i, j, tmp;
  10084. for (i = 0, j = 0; i < n/8; i++, j += 2) {
  10085. tmp = be32_to_cpu(source[j]);
  10086. target[i].op = (tmp >> 24) & 0xff;
  10087. target[i].offset = tmp & 0xffffff;
  10088. target[i].raw_data = be32_to_cpu(source[j + 1]);
  10089. }
  10090. }
  10091. /* IRO array is stored in the following format:
  10092. * {base(24bit), m1(16bit), m2(16bit), m3(16bit), size(16bit) }
  10093. */
  10094. static void bnx2x_prep_iro(const u8 *_source, u8 *_target, u32 n)
  10095. {
  10096. const __be32 *source = (const __be32 *)_source;
  10097. struct iro *target = (struct iro *)_target;
  10098. u32 i, j, tmp;
  10099. for (i = 0, j = 0; i < n/sizeof(struct iro); i++) {
  10100. target[i].base = be32_to_cpu(source[j]);
  10101. j++;
  10102. tmp = be32_to_cpu(source[j]);
  10103. target[i].m1 = (tmp >> 16) & 0xffff;
  10104. target[i].m2 = tmp & 0xffff;
  10105. j++;
  10106. tmp = be32_to_cpu(source[j]);
  10107. target[i].m3 = (tmp >> 16) & 0xffff;
  10108. target[i].size = tmp & 0xffff;
  10109. j++;
  10110. }
  10111. }
  10112. static void be16_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  10113. {
  10114. const __be16 *source = (const __be16 *)_source;
  10115. u16 *target = (u16 *)_target;
  10116. u32 i;
  10117. for (i = 0; i < n/2; i++)
  10118. target[i] = be16_to_cpu(source[i]);
  10119. }
  10120. #define BNX2X_ALLOC_AND_SET(arr, lbl, func) \
  10121. do { \
  10122. u32 len = be32_to_cpu(fw_hdr->arr.len); \
  10123. bp->arr = kmalloc(len, GFP_KERNEL); \
  10124. if (!bp->arr) \
  10125. goto lbl; \
  10126. func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \
  10127. (u8 *)bp->arr, len); \
  10128. } while (0)
  10129. static int bnx2x_init_firmware(struct bnx2x *bp)
  10130. {
  10131. const char *fw_file_name;
  10132. struct bnx2x_fw_file_hdr *fw_hdr;
  10133. int rc;
  10134. if (bp->firmware)
  10135. return 0;
  10136. if (CHIP_IS_E1(bp))
  10137. fw_file_name = FW_FILE_NAME_E1;
  10138. else if (CHIP_IS_E1H(bp))
  10139. fw_file_name = FW_FILE_NAME_E1H;
  10140. else if (!CHIP_IS_E1x(bp))
  10141. fw_file_name = FW_FILE_NAME_E2;
  10142. else {
  10143. BNX2X_ERR("Unsupported chip revision\n");
  10144. return -EINVAL;
  10145. }
  10146. BNX2X_DEV_INFO("Loading %s\n", fw_file_name);
  10147. rc = request_firmware(&bp->firmware, fw_file_name, &bp->pdev->dev);
  10148. if (rc) {
  10149. BNX2X_ERR("Can't load firmware file %s\n",
  10150. fw_file_name);
  10151. goto request_firmware_exit;
  10152. }
  10153. rc = bnx2x_check_firmware(bp);
  10154. if (rc) {
  10155. BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name);
  10156. goto request_firmware_exit;
  10157. }
  10158. fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data;
  10159. /* Initialize the pointers to the init arrays */
  10160. /* Blob */
  10161. BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n);
  10162. /* Opcodes */
  10163. BNX2X_ALLOC_AND_SET(init_ops, init_ops_alloc_err, bnx2x_prep_ops);
  10164. /* Offsets */
  10165. BNX2X_ALLOC_AND_SET(init_ops_offsets, init_offsets_alloc_err,
  10166. be16_to_cpu_n);
  10167. /* STORMs firmware */
  10168. INIT_TSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10169. be32_to_cpu(fw_hdr->tsem_int_table_data.offset);
  10170. INIT_TSEM_PRAM_DATA(bp) = bp->firmware->data +
  10171. be32_to_cpu(fw_hdr->tsem_pram_data.offset);
  10172. INIT_USEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10173. be32_to_cpu(fw_hdr->usem_int_table_data.offset);
  10174. INIT_USEM_PRAM_DATA(bp) = bp->firmware->data +
  10175. be32_to_cpu(fw_hdr->usem_pram_data.offset);
  10176. INIT_XSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10177. be32_to_cpu(fw_hdr->xsem_int_table_data.offset);
  10178. INIT_XSEM_PRAM_DATA(bp) = bp->firmware->data +
  10179. be32_to_cpu(fw_hdr->xsem_pram_data.offset);
  10180. INIT_CSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10181. be32_to_cpu(fw_hdr->csem_int_table_data.offset);
  10182. INIT_CSEM_PRAM_DATA(bp) = bp->firmware->data +
  10183. be32_to_cpu(fw_hdr->csem_pram_data.offset);
  10184. /* IRO */
  10185. BNX2X_ALLOC_AND_SET(iro_arr, iro_alloc_err, bnx2x_prep_iro);
  10186. return 0;
  10187. iro_alloc_err:
  10188. kfree(bp->init_ops_offsets);
  10189. init_offsets_alloc_err:
  10190. kfree(bp->init_ops);
  10191. init_ops_alloc_err:
  10192. kfree(bp->init_data);
  10193. request_firmware_exit:
  10194. release_firmware(bp->firmware);
  10195. bp->firmware = NULL;
  10196. return rc;
  10197. }
  10198. static void bnx2x_release_firmware(struct bnx2x *bp)
  10199. {
  10200. kfree(bp->init_ops_offsets);
  10201. kfree(bp->init_ops);
  10202. kfree(bp->init_data);
  10203. release_firmware(bp->firmware);
  10204. bp->firmware = NULL;
  10205. }
  10206. static struct bnx2x_func_sp_drv_ops bnx2x_func_sp_drv = {
  10207. .init_hw_cmn_chip = bnx2x_init_hw_common_chip,
  10208. .init_hw_cmn = bnx2x_init_hw_common,
  10209. .init_hw_port = bnx2x_init_hw_port,
  10210. .init_hw_func = bnx2x_init_hw_func,
  10211. .reset_hw_cmn = bnx2x_reset_common,
  10212. .reset_hw_port = bnx2x_reset_port,
  10213. .reset_hw_func = bnx2x_reset_func,
  10214. .gunzip_init = bnx2x_gunzip_init,
  10215. .gunzip_end = bnx2x_gunzip_end,
  10216. .init_fw = bnx2x_init_firmware,
  10217. .release_fw = bnx2x_release_firmware,
  10218. };
  10219. void bnx2x__init_func_obj(struct bnx2x *bp)
  10220. {
  10221. /* Prepare DMAE related driver resources */
  10222. bnx2x_setup_dmae(bp);
  10223. bnx2x_init_func_obj(bp, &bp->func_obj,
  10224. bnx2x_sp(bp, func_rdata),
  10225. bnx2x_sp_mapping(bp, func_rdata),
  10226. bnx2x_sp(bp, func_afex_rdata),
  10227. bnx2x_sp_mapping(bp, func_afex_rdata),
  10228. &bnx2x_func_sp_drv);
  10229. }
  10230. /* must be called after sriov-enable */
  10231. static int bnx2x_set_qm_cid_count(struct bnx2x *bp)
  10232. {
  10233. int cid_count = BNX2X_L2_MAX_CID(bp);
  10234. if (IS_SRIOV(bp))
  10235. cid_count += BNX2X_VF_CIDS;
  10236. if (CNIC_SUPPORT(bp))
  10237. cid_count += CNIC_CID_MAX;
  10238. return roundup(cid_count, QM_CID_ROUND);
  10239. }
  10240. /**
  10241. * bnx2x_get_num_none_def_sbs - return the number of none default SBs
  10242. *
  10243. * @dev: pci device
  10244. *
  10245. */
  10246. static int bnx2x_get_num_non_def_sbs(struct pci_dev *pdev,
  10247. int cnic_cnt, bool is_vf)
  10248. {
  10249. int pos, index;
  10250. u16 control = 0;
  10251. pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
  10252. /*
  10253. * If MSI-X is not supported - return number of SBs needed to support
  10254. * one fast path queue: one FP queue + SB for CNIC
  10255. */
  10256. if (!pos) {
  10257. dev_info(&pdev->dev, "no msix capability found\n");
  10258. return 1 + cnic_cnt;
  10259. }
  10260. dev_info(&pdev->dev, "msix capability found\n");
  10261. /*
  10262. * The value in the PCI configuration space is the index of the last
  10263. * entry, namely one less than the actual size of the table, which is
  10264. * exactly what we want to return from this function: number of all SBs
  10265. * without the default SB.
  10266. * For VFs there is no default SB, then we return (index+1).
  10267. */
  10268. pci_read_config_word(pdev, pos + PCI_MSI_FLAGS, &control);
  10269. index = control & PCI_MSIX_FLAGS_QSIZE;
  10270. return is_vf ? index + 1 : index;
  10271. }
  10272. static int set_max_cos_est(int chip_id)
  10273. {
  10274. switch (chip_id) {
  10275. case BCM57710:
  10276. case BCM57711:
  10277. case BCM57711E:
  10278. return BNX2X_MULTI_TX_COS_E1X;
  10279. case BCM57712:
  10280. case BCM57712_MF:
  10281. case BCM57712_VF:
  10282. return BNX2X_MULTI_TX_COS_E2_E3A0;
  10283. case BCM57800:
  10284. case BCM57800_MF:
  10285. case BCM57800_VF:
  10286. case BCM57810:
  10287. case BCM57810_MF:
  10288. case BCM57840_4_10:
  10289. case BCM57840_2_20:
  10290. case BCM57840_O:
  10291. case BCM57840_MFO:
  10292. case BCM57810_VF:
  10293. case BCM57840_MF:
  10294. case BCM57840_VF:
  10295. case BCM57811:
  10296. case BCM57811_MF:
  10297. case BCM57811_VF:
  10298. return BNX2X_MULTI_TX_COS_E3B0;
  10299. return 1;
  10300. default:
  10301. pr_err("Unknown board_type (%d), aborting\n", chip_id);
  10302. return -ENODEV;
  10303. }
  10304. }
  10305. static int set_is_vf(int chip_id)
  10306. {
  10307. switch (chip_id) {
  10308. case BCM57712_VF:
  10309. case BCM57800_VF:
  10310. case BCM57810_VF:
  10311. case BCM57840_VF:
  10312. case BCM57811_VF:
  10313. return true;
  10314. default:
  10315. return false;
  10316. }
  10317. }
  10318. struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev);
  10319. static int bnx2x_init_one(struct pci_dev *pdev,
  10320. const struct pci_device_id *ent)
  10321. {
  10322. struct net_device *dev = NULL;
  10323. struct bnx2x *bp;
  10324. int pcie_width, pcie_speed;
  10325. int rc, max_non_def_sbs;
  10326. int rx_count, tx_count, rss_count, doorbell_size;
  10327. int max_cos_est;
  10328. bool is_vf;
  10329. int cnic_cnt;
  10330. /* An estimated maximum supported CoS number according to the chip
  10331. * version.
  10332. * We will try to roughly estimate the maximum number of CoSes this chip
  10333. * may support in order to minimize the memory allocated for Tx
  10334. * netdev_queue's. This number will be accurately calculated during the
  10335. * initialization of bp->max_cos based on the chip versions AND chip
  10336. * revision in the bnx2x_init_bp().
  10337. */
  10338. max_cos_est = set_max_cos_est(ent->driver_data);
  10339. if (max_cos_est < 0)
  10340. return max_cos_est;
  10341. is_vf = set_is_vf(ent->driver_data);
  10342. cnic_cnt = is_vf ? 0 : 1;
  10343. max_non_def_sbs = bnx2x_get_num_non_def_sbs(pdev, cnic_cnt, is_vf);
  10344. /* Maximum number of RSS queues: one IGU SB goes to CNIC */
  10345. rss_count = is_vf ? 1 : max_non_def_sbs - cnic_cnt;
  10346. if (rss_count < 1)
  10347. return -EINVAL;
  10348. /* Maximum number of netdev Rx queues: RSS + FCoE L2 */
  10349. rx_count = rss_count + cnic_cnt;
  10350. /* Maximum number of netdev Tx queues:
  10351. * Maximum TSS queues * Maximum supported number of CoS + FCoE L2
  10352. */
  10353. tx_count = rss_count * max_cos_est + cnic_cnt;
  10354. /* dev zeroed in init_etherdev */
  10355. dev = alloc_etherdev_mqs(sizeof(*bp), tx_count, rx_count);
  10356. if (!dev)
  10357. return -ENOMEM;
  10358. bp = netdev_priv(dev);
  10359. bp->flags = 0;
  10360. if (is_vf)
  10361. bp->flags |= IS_VF_FLAG;
  10362. bp->igu_sb_cnt = max_non_def_sbs;
  10363. bp->igu_base_addr = IS_VF(bp) ? PXP_VF_ADDR_IGU_START : BAR_IGU_INTMEM;
  10364. bp->msg_enable = debug;
  10365. bp->cnic_support = cnic_cnt;
  10366. bp->cnic_probe = bnx2x_cnic_probe;
  10367. pci_set_drvdata(pdev, dev);
  10368. rc = bnx2x_init_dev(bp, pdev, dev, ent->driver_data);
  10369. if (rc < 0) {
  10370. free_netdev(dev);
  10371. return rc;
  10372. }
  10373. BNX2X_DEV_INFO("This is a %s function\n",
  10374. IS_PF(bp) ? "physical" : "virtual");
  10375. BNX2X_DEV_INFO("Cnic support is %s\n", CNIC_SUPPORT(bp) ? "on" : "off");
  10376. BNX2X_DEV_INFO("Max num of status blocks %d\n", max_non_def_sbs);
  10377. BNX2X_DEV_INFO("Allocated netdev with %d tx and %d rx queues\n",
  10378. tx_count, rx_count);
  10379. rc = bnx2x_init_bp(bp);
  10380. if (rc)
  10381. goto init_one_exit;
  10382. /* Map doorbells here as we need the real value of bp->max_cos which
  10383. * is initialized in bnx2x_init_bp() to determine the number of
  10384. * l2 connections.
  10385. */
  10386. if (IS_VF(bp)) {
  10387. bnx2x_vf_map_doorbells(bp);
  10388. rc = bnx2x_vf_pci_alloc(bp);
  10389. if (rc)
  10390. goto init_one_exit;
  10391. } else {
  10392. doorbell_size = BNX2X_L2_MAX_CID(bp) * (1 << BNX2X_DB_SHIFT);
  10393. if (doorbell_size > pci_resource_len(pdev, 2)) {
  10394. dev_err(&bp->pdev->dev,
  10395. "Cannot map doorbells, bar size too small, aborting\n");
  10396. rc = -ENOMEM;
  10397. goto init_one_exit;
  10398. }
  10399. bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2),
  10400. doorbell_size);
  10401. }
  10402. if (!bp->doorbells) {
  10403. dev_err(&bp->pdev->dev,
  10404. "Cannot map doorbell space, aborting\n");
  10405. rc = -ENOMEM;
  10406. goto init_one_exit;
  10407. }
  10408. if (IS_VF(bp)) {
  10409. rc = bnx2x_vfpf_acquire(bp, tx_count, rx_count);
  10410. if (rc)
  10411. goto init_one_exit;
  10412. }
  10413. /* Enable SRIOV if capability found in configuration space.
  10414. * Once the generic SR-IOV framework makes it in from the
  10415. * pci tree this will be revised, to allow dynamic control
  10416. * over the number of VFs. Right now, change the num of vfs
  10417. * param below to enable SR-IOV.
  10418. */
  10419. rc = bnx2x_iov_init_one(bp, int_mode, 0/*num vfs*/);
  10420. if (rc)
  10421. goto init_one_exit;
  10422. /* calc qm_cid_count */
  10423. bp->qm_cid_count = bnx2x_set_qm_cid_count(bp);
  10424. BNX2X_DEV_INFO("qm_cid_count %d\n", bp->qm_cid_count);
  10425. /* disable FCOE L2 queue for E1x*/
  10426. if (CHIP_IS_E1x(bp))
  10427. bp->flags |= NO_FCOE_FLAG;
  10428. /* disable FCOE for 57840 device, until FW supports it */
  10429. switch (ent->driver_data) {
  10430. case BCM57840_O:
  10431. case BCM57840_4_10:
  10432. case BCM57840_2_20:
  10433. case BCM57840_MFO:
  10434. case BCM57840_MF:
  10435. bp->flags |= NO_FCOE_FLAG;
  10436. }
  10437. /* Set bp->num_queues for MSI-X mode*/
  10438. bnx2x_set_num_queues(bp);
  10439. /* Configure interrupt mode: try to enable MSI-X/MSI if
  10440. * needed.
  10441. */
  10442. rc = bnx2x_set_int_mode(bp);
  10443. if (rc) {
  10444. dev_err(&pdev->dev, "Cannot set interrupts\n");
  10445. goto init_one_exit;
  10446. }
  10447. /* register the net device */
  10448. rc = register_netdev(dev);
  10449. if (rc) {
  10450. dev_err(&pdev->dev, "Cannot register net device\n");
  10451. goto init_one_exit;
  10452. }
  10453. BNX2X_DEV_INFO("device name after netdev register %s\n", dev->name);
  10454. if (!NO_FCOE(bp)) {
  10455. /* Add storage MAC address */
  10456. rtnl_lock();
  10457. dev_addr_add(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  10458. rtnl_unlock();
  10459. }
  10460. bnx2x_get_pcie_width_speed(bp, &pcie_width, &pcie_speed);
  10461. BNX2X_DEV_INFO("got pcie width %d and speed %d\n",
  10462. pcie_width, pcie_speed);
  10463. BNX2X_DEV_INFO(
  10464. "%s (%c%d) PCI-E x%d %s found at mem %lx, IRQ %d, node addr %pM\n",
  10465. board_info[ent->driver_data].name,
  10466. (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4),
  10467. pcie_width,
  10468. ((!CHIP_IS_E2(bp) && pcie_speed == 2) ||
  10469. (CHIP_IS_E2(bp) && pcie_speed == 1)) ?
  10470. "5GHz (Gen2)" : "2.5GHz",
  10471. dev->base_addr, bp->pdev->irq, dev->dev_addr);
  10472. return 0;
  10473. init_one_exit:
  10474. if (bp->regview)
  10475. iounmap(bp->regview);
  10476. if (IS_PF(bp) && bp->doorbells)
  10477. iounmap(bp->doorbells);
  10478. free_netdev(dev);
  10479. if (atomic_read(&pdev->enable_cnt) == 1)
  10480. pci_release_regions(pdev);
  10481. pci_disable_device(pdev);
  10482. pci_set_drvdata(pdev, NULL);
  10483. return rc;
  10484. }
  10485. static void bnx2x_remove_one(struct pci_dev *pdev)
  10486. {
  10487. struct net_device *dev = pci_get_drvdata(pdev);
  10488. struct bnx2x *bp;
  10489. if (!dev) {
  10490. dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n");
  10491. return;
  10492. }
  10493. bp = netdev_priv(dev);
  10494. /* Delete storage MAC address */
  10495. if (!NO_FCOE(bp)) {
  10496. rtnl_lock();
  10497. dev_addr_del(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  10498. rtnl_unlock();
  10499. }
  10500. #ifdef BCM_DCBNL
  10501. /* Delete app tlvs from dcbnl */
  10502. bnx2x_dcbnl_update_applist(bp, true);
  10503. #endif
  10504. unregister_netdev(dev);
  10505. /* Power on: we can't let PCI layer write to us while we are in D3 */
  10506. if (IS_PF(bp))
  10507. bnx2x_set_power_state(bp, PCI_D0);
  10508. /* Disable MSI/MSI-X */
  10509. bnx2x_disable_msi(bp);
  10510. /* Power off */
  10511. if (IS_PF(bp))
  10512. bnx2x_set_power_state(bp, PCI_D3hot);
  10513. /* Make sure RESET task is not scheduled before continuing */
  10514. cancel_delayed_work_sync(&bp->sp_rtnl_task);
  10515. bnx2x_iov_remove_one(bp);
  10516. /* send message via vfpf channel to release the resources of this vf */
  10517. if (IS_VF(bp))
  10518. bnx2x_vfpf_release(bp);
  10519. if (bp->regview)
  10520. iounmap(bp->regview);
  10521. /* for vf doorbells are part of the regview and were unmapped along with
  10522. * it. FW is only loaded by PF.
  10523. */
  10524. if (IS_PF(bp)) {
  10525. if (bp->doorbells)
  10526. iounmap(bp->doorbells);
  10527. bnx2x_release_firmware(bp);
  10528. }
  10529. bnx2x_free_mem_bp(bp);
  10530. free_netdev(dev);
  10531. if (atomic_read(&pdev->enable_cnt) == 1)
  10532. pci_release_regions(pdev);
  10533. pci_disable_device(pdev);
  10534. pci_set_drvdata(pdev, NULL);
  10535. }
  10536. static int bnx2x_eeh_nic_unload(struct bnx2x *bp)
  10537. {
  10538. int i;
  10539. bp->state = BNX2X_STATE_ERROR;
  10540. bp->rx_mode = BNX2X_RX_MODE_NONE;
  10541. if (CNIC_LOADED(bp))
  10542. bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD);
  10543. /* Stop Tx */
  10544. bnx2x_tx_disable(bp);
  10545. bnx2x_netif_stop(bp, 0);
  10546. /* Delete all NAPI objects */
  10547. bnx2x_del_all_napi(bp);
  10548. if (CNIC_LOADED(bp))
  10549. bnx2x_del_all_napi_cnic(bp);
  10550. del_timer_sync(&bp->timer);
  10551. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  10552. /* Release IRQs */
  10553. bnx2x_free_irq(bp);
  10554. /* Free SKBs, SGEs, TPA pool and driver internals */
  10555. bnx2x_free_skbs(bp);
  10556. for_each_rx_queue(bp, i)
  10557. bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
  10558. bnx2x_free_mem(bp);
  10559. bp->state = BNX2X_STATE_CLOSED;
  10560. netif_carrier_off(bp->dev);
  10561. return 0;
  10562. }
  10563. static void bnx2x_eeh_recover(struct bnx2x *bp)
  10564. {
  10565. u32 val;
  10566. mutex_init(&bp->port.phy_mutex);
  10567. val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
  10568. if ((val & (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
  10569. != (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
  10570. BNX2X_ERR("BAD MCP validity signature\n");
  10571. }
  10572. /**
  10573. * bnx2x_io_error_detected - called when PCI error is detected
  10574. * @pdev: Pointer to PCI device
  10575. * @state: The current pci connection state
  10576. *
  10577. * This function is called after a PCI bus error affecting
  10578. * this device has been detected.
  10579. */
  10580. static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev,
  10581. pci_channel_state_t state)
  10582. {
  10583. struct net_device *dev = pci_get_drvdata(pdev);
  10584. struct bnx2x *bp = netdev_priv(dev);
  10585. rtnl_lock();
  10586. netif_device_detach(dev);
  10587. if (state == pci_channel_io_perm_failure) {
  10588. rtnl_unlock();
  10589. return PCI_ERS_RESULT_DISCONNECT;
  10590. }
  10591. if (netif_running(dev))
  10592. bnx2x_eeh_nic_unload(bp);
  10593. pci_disable_device(pdev);
  10594. rtnl_unlock();
  10595. /* Request a slot reset */
  10596. return PCI_ERS_RESULT_NEED_RESET;
  10597. }
  10598. /**
  10599. * bnx2x_io_slot_reset - called after the PCI bus has been reset
  10600. * @pdev: Pointer to PCI device
  10601. *
  10602. * Restart the card from scratch, as if from a cold-boot.
  10603. */
  10604. static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev)
  10605. {
  10606. struct net_device *dev = pci_get_drvdata(pdev);
  10607. struct bnx2x *bp = netdev_priv(dev);
  10608. rtnl_lock();
  10609. if (pci_enable_device(pdev)) {
  10610. dev_err(&pdev->dev,
  10611. "Cannot re-enable PCI device after reset\n");
  10612. rtnl_unlock();
  10613. return PCI_ERS_RESULT_DISCONNECT;
  10614. }
  10615. pci_set_master(pdev);
  10616. pci_restore_state(pdev);
  10617. if (netif_running(dev))
  10618. bnx2x_set_power_state(bp, PCI_D0);
  10619. rtnl_unlock();
  10620. return PCI_ERS_RESULT_RECOVERED;
  10621. }
  10622. /**
  10623. * bnx2x_io_resume - called when traffic can start flowing again
  10624. * @pdev: Pointer to PCI device
  10625. *
  10626. * This callback is called when the error recovery driver tells us that
  10627. * its OK to resume normal operation.
  10628. */
  10629. static void bnx2x_io_resume(struct pci_dev *pdev)
  10630. {
  10631. struct net_device *dev = pci_get_drvdata(pdev);
  10632. struct bnx2x *bp = netdev_priv(dev);
  10633. if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
  10634. netdev_err(bp->dev, "Handling parity error recovery. Try again later\n");
  10635. return;
  10636. }
  10637. rtnl_lock();
  10638. bnx2x_eeh_recover(bp);
  10639. if (netif_running(dev))
  10640. bnx2x_nic_load(bp, LOAD_NORMAL);
  10641. netif_device_attach(dev);
  10642. rtnl_unlock();
  10643. }
  10644. static const struct pci_error_handlers bnx2x_err_handler = {
  10645. .error_detected = bnx2x_io_error_detected,
  10646. .slot_reset = bnx2x_io_slot_reset,
  10647. .resume = bnx2x_io_resume,
  10648. };
  10649. static struct pci_driver bnx2x_pci_driver = {
  10650. .name = DRV_MODULE_NAME,
  10651. .id_table = bnx2x_pci_tbl,
  10652. .probe = bnx2x_init_one,
  10653. .remove = bnx2x_remove_one,
  10654. .suspend = bnx2x_suspend,
  10655. .resume = bnx2x_resume,
  10656. .err_handler = &bnx2x_err_handler,
  10657. };
  10658. static int __init bnx2x_init(void)
  10659. {
  10660. int ret;
  10661. pr_info("%s", version);
  10662. bnx2x_wq = create_singlethread_workqueue("bnx2x");
  10663. if (bnx2x_wq == NULL) {
  10664. pr_err("Cannot create workqueue\n");
  10665. return -ENOMEM;
  10666. }
  10667. ret = pci_register_driver(&bnx2x_pci_driver);
  10668. if (ret) {
  10669. pr_err("Cannot register driver\n");
  10670. destroy_workqueue(bnx2x_wq);
  10671. }
  10672. return ret;
  10673. }
  10674. static void __exit bnx2x_cleanup(void)
  10675. {
  10676. struct list_head *pos, *q;
  10677. pci_unregister_driver(&bnx2x_pci_driver);
  10678. destroy_workqueue(bnx2x_wq);
  10679. /* Free globablly allocated resources */
  10680. list_for_each_safe(pos, q, &bnx2x_prev_list) {
  10681. struct bnx2x_prev_path_list *tmp =
  10682. list_entry(pos, struct bnx2x_prev_path_list, list);
  10683. list_del(pos);
  10684. kfree(tmp);
  10685. }
  10686. }
  10687. void bnx2x_notify_link_changed(struct bnx2x *bp)
  10688. {
  10689. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + BP_FUNC(bp)*sizeof(u32), 1);
  10690. }
  10691. module_init(bnx2x_init);
  10692. module_exit(bnx2x_cleanup);
  10693. /**
  10694. * bnx2x_set_iscsi_eth_mac_addr - set iSCSI MAC(s).
  10695. *
  10696. * @bp: driver handle
  10697. * @set: set or clear the CAM entry
  10698. *
  10699. * This function will wait until the ramdord completion returns.
  10700. * Return 0 if success, -ENODEV if ramrod doesn't return.
  10701. */
  10702. static int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp)
  10703. {
  10704. unsigned long ramrod_flags = 0;
  10705. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  10706. return bnx2x_set_mac_one(bp, bp->cnic_eth_dev.iscsi_mac,
  10707. &bp->iscsi_l2_mac_obj, true,
  10708. BNX2X_ISCSI_ETH_MAC, &ramrod_flags);
  10709. }
  10710. /* count denotes the number of new completions we have seen */
  10711. static void bnx2x_cnic_sp_post(struct bnx2x *bp, int count)
  10712. {
  10713. struct eth_spe *spe;
  10714. int cxt_index, cxt_offset;
  10715. #ifdef BNX2X_STOP_ON_ERROR
  10716. if (unlikely(bp->panic))
  10717. return;
  10718. #endif
  10719. spin_lock_bh(&bp->spq_lock);
  10720. BUG_ON(bp->cnic_spq_pending < count);
  10721. bp->cnic_spq_pending -= count;
  10722. for (; bp->cnic_kwq_pending; bp->cnic_kwq_pending--) {
  10723. u16 type = (le16_to_cpu(bp->cnic_kwq_cons->hdr.type)
  10724. & SPE_HDR_CONN_TYPE) >>
  10725. SPE_HDR_CONN_TYPE_SHIFT;
  10726. u8 cmd = (le32_to_cpu(bp->cnic_kwq_cons->hdr.conn_and_cmd_data)
  10727. >> SPE_HDR_CMD_ID_SHIFT) & 0xff;
  10728. /* Set validation for iSCSI L2 client before sending SETUP
  10729. * ramrod
  10730. */
  10731. if (type == ETH_CONNECTION_TYPE) {
  10732. if (cmd == RAMROD_CMD_ID_ETH_CLIENT_SETUP) {
  10733. cxt_index = BNX2X_ISCSI_ETH_CID(bp) /
  10734. ILT_PAGE_CIDS;
  10735. cxt_offset = BNX2X_ISCSI_ETH_CID(bp) -
  10736. (cxt_index * ILT_PAGE_CIDS);
  10737. bnx2x_set_ctx_validation(bp,
  10738. &bp->context[cxt_index].
  10739. vcxt[cxt_offset].eth,
  10740. BNX2X_ISCSI_ETH_CID(bp));
  10741. }
  10742. }
  10743. /*
  10744. * There may be not more than 8 L2, not more than 8 L5 SPEs
  10745. * and in the air. We also check that number of outstanding
  10746. * COMMON ramrods is not more than the EQ and SPQ can
  10747. * accommodate.
  10748. */
  10749. if (type == ETH_CONNECTION_TYPE) {
  10750. if (!atomic_read(&bp->cq_spq_left))
  10751. break;
  10752. else
  10753. atomic_dec(&bp->cq_spq_left);
  10754. } else if (type == NONE_CONNECTION_TYPE) {
  10755. if (!atomic_read(&bp->eq_spq_left))
  10756. break;
  10757. else
  10758. atomic_dec(&bp->eq_spq_left);
  10759. } else if ((type == ISCSI_CONNECTION_TYPE) ||
  10760. (type == FCOE_CONNECTION_TYPE)) {
  10761. if (bp->cnic_spq_pending >=
  10762. bp->cnic_eth_dev.max_kwqe_pending)
  10763. break;
  10764. else
  10765. bp->cnic_spq_pending++;
  10766. } else {
  10767. BNX2X_ERR("Unknown SPE type: %d\n", type);
  10768. bnx2x_panic();
  10769. break;
  10770. }
  10771. spe = bnx2x_sp_get_next(bp);
  10772. *spe = *bp->cnic_kwq_cons;
  10773. DP(BNX2X_MSG_SP, "pending on SPQ %d, on KWQ %d count %d\n",
  10774. bp->cnic_spq_pending, bp->cnic_kwq_pending, count);
  10775. if (bp->cnic_kwq_cons == bp->cnic_kwq_last)
  10776. bp->cnic_kwq_cons = bp->cnic_kwq;
  10777. else
  10778. bp->cnic_kwq_cons++;
  10779. }
  10780. bnx2x_sp_prod_update(bp);
  10781. spin_unlock_bh(&bp->spq_lock);
  10782. }
  10783. static int bnx2x_cnic_sp_queue(struct net_device *dev,
  10784. struct kwqe_16 *kwqes[], u32 count)
  10785. {
  10786. struct bnx2x *bp = netdev_priv(dev);
  10787. int i;
  10788. #ifdef BNX2X_STOP_ON_ERROR
  10789. if (unlikely(bp->panic)) {
  10790. BNX2X_ERR("Can't post to SP queue while panic\n");
  10791. return -EIO;
  10792. }
  10793. #endif
  10794. if ((bp->recovery_state != BNX2X_RECOVERY_DONE) &&
  10795. (bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  10796. BNX2X_ERR("Handling parity error recovery. Try again later\n");
  10797. return -EAGAIN;
  10798. }
  10799. spin_lock_bh(&bp->spq_lock);
  10800. for (i = 0; i < count; i++) {
  10801. struct eth_spe *spe = (struct eth_spe *)kwqes[i];
  10802. if (bp->cnic_kwq_pending == MAX_SP_DESC_CNT)
  10803. break;
  10804. *bp->cnic_kwq_prod = *spe;
  10805. bp->cnic_kwq_pending++;
  10806. DP(BNX2X_MSG_SP, "L5 SPQE %x %x %x:%x pos %d\n",
  10807. spe->hdr.conn_and_cmd_data, spe->hdr.type,
  10808. spe->data.update_data_addr.hi,
  10809. spe->data.update_data_addr.lo,
  10810. bp->cnic_kwq_pending);
  10811. if (bp->cnic_kwq_prod == bp->cnic_kwq_last)
  10812. bp->cnic_kwq_prod = bp->cnic_kwq;
  10813. else
  10814. bp->cnic_kwq_prod++;
  10815. }
  10816. spin_unlock_bh(&bp->spq_lock);
  10817. if (bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending)
  10818. bnx2x_cnic_sp_post(bp, 0);
  10819. return i;
  10820. }
  10821. static int bnx2x_cnic_ctl_send(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  10822. {
  10823. struct cnic_ops *c_ops;
  10824. int rc = 0;
  10825. mutex_lock(&bp->cnic_mutex);
  10826. c_ops = rcu_dereference_protected(bp->cnic_ops,
  10827. lockdep_is_held(&bp->cnic_mutex));
  10828. if (c_ops)
  10829. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  10830. mutex_unlock(&bp->cnic_mutex);
  10831. return rc;
  10832. }
  10833. static int bnx2x_cnic_ctl_send_bh(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  10834. {
  10835. struct cnic_ops *c_ops;
  10836. int rc = 0;
  10837. rcu_read_lock();
  10838. c_ops = rcu_dereference(bp->cnic_ops);
  10839. if (c_ops)
  10840. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  10841. rcu_read_unlock();
  10842. return rc;
  10843. }
  10844. /*
  10845. * for commands that have no data
  10846. */
  10847. int bnx2x_cnic_notify(struct bnx2x *bp, int cmd)
  10848. {
  10849. struct cnic_ctl_info ctl = {0};
  10850. ctl.cmd = cmd;
  10851. return bnx2x_cnic_ctl_send(bp, &ctl);
  10852. }
  10853. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err)
  10854. {
  10855. struct cnic_ctl_info ctl = {0};
  10856. /* first we tell CNIC and only then we count this as a completion */
  10857. ctl.cmd = CNIC_CTL_COMPLETION_CMD;
  10858. ctl.data.comp.cid = cid;
  10859. ctl.data.comp.error = err;
  10860. bnx2x_cnic_ctl_send_bh(bp, &ctl);
  10861. bnx2x_cnic_sp_post(bp, 0);
  10862. }
  10863. /* Called with netif_addr_lock_bh() taken.
  10864. * Sets an rx_mode config for an iSCSI ETH client.
  10865. * Doesn't block.
  10866. * Completion should be checked outside.
  10867. */
  10868. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start)
  10869. {
  10870. unsigned long accept_flags = 0, ramrod_flags = 0;
  10871. u8 cl_id = bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  10872. int sched_state = BNX2X_FILTER_ISCSI_ETH_STOP_SCHED;
  10873. if (start) {
  10874. /* Start accepting on iSCSI L2 ring. Accept all multicasts
  10875. * because it's the only way for UIO Queue to accept
  10876. * multicasts (in non-promiscuous mode only one Queue per
  10877. * function will receive multicast packets (leading in our
  10878. * case).
  10879. */
  10880. __set_bit(BNX2X_ACCEPT_UNICAST, &accept_flags);
  10881. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept_flags);
  10882. __set_bit(BNX2X_ACCEPT_BROADCAST, &accept_flags);
  10883. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags);
  10884. /* Clear STOP_PENDING bit if START is requested */
  10885. clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &bp->sp_state);
  10886. sched_state = BNX2X_FILTER_ISCSI_ETH_START_SCHED;
  10887. } else
  10888. /* Clear START_PENDING bit if STOP is requested */
  10889. clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &bp->sp_state);
  10890. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  10891. set_bit(sched_state, &bp->sp_state);
  10892. else {
  10893. __set_bit(RAMROD_RX, &ramrod_flags);
  10894. bnx2x_set_q_rx_mode(bp, cl_id, 0, accept_flags, 0,
  10895. ramrod_flags);
  10896. }
  10897. }
  10898. static int bnx2x_drv_ctl(struct net_device *dev, struct drv_ctl_info *ctl)
  10899. {
  10900. struct bnx2x *bp = netdev_priv(dev);
  10901. int rc = 0;
  10902. switch (ctl->cmd) {
  10903. case DRV_CTL_CTXTBL_WR_CMD: {
  10904. u32 index = ctl->data.io.offset;
  10905. dma_addr_t addr = ctl->data.io.dma_addr;
  10906. bnx2x_ilt_wr(bp, index, addr);
  10907. break;
  10908. }
  10909. case DRV_CTL_RET_L5_SPQ_CREDIT_CMD: {
  10910. int count = ctl->data.credit.credit_count;
  10911. bnx2x_cnic_sp_post(bp, count);
  10912. break;
  10913. }
  10914. /* rtnl_lock is held. */
  10915. case DRV_CTL_START_L2_CMD: {
  10916. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  10917. unsigned long sp_bits = 0;
  10918. /* Configure the iSCSI classification object */
  10919. bnx2x_init_mac_obj(bp, &bp->iscsi_l2_mac_obj,
  10920. cp->iscsi_l2_client_id,
  10921. cp->iscsi_l2_cid, BP_FUNC(bp),
  10922. bnx2x_sp(bp, mac_rdata),
  10923. bnx2x_sp_mapping(bp, mac_rdata),
  10924. BNX2X_FILTER_MAC_PENDING,
  10925. &bp->sp_state, BNX2X_OBJ_TYPE_RX,
  10926. &bp->macs_pool);
  10927. /* Set iSCSI MAC address */
  10928. rc = bnx2x_set_iscsi_eth_mac_addr(bp);
  10929. if (rc)
  10930. break;
  10931. mmiowb();
  10932. barrier();
  10933. /* Start accepting on iSCSI L2 ring */
  10934. netif_addr_lock_bh(dev);
  10935. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  10936. netif_addr_unlock_bh(dev);
  10937. /* bits to wait on */
  10938. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  10939. __set_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &sp_bits);
  10940. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  10941. BNX2X_ERR("rx_mode completion timed out!\n");
  10942. break;
  10943. }
  10944. /* rtnl_lock is held. */
  10945. case DRV_CTL_STOP_L2_CMD: {
  10946. unsigned long sp_bits = 0;
  10947. /* Stop accepting on iSCSI L2 ring */
  10948. netif_addr_lock_bh(dev);
  10949. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  10950. netif_addr_unlock_bh(dev);
  10951. /* bits to wait on */
  10952. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  10953. __set_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &sp_bits);
  10954. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  10955. BNX2X_ERR("rx_mode completion timed out!\n");
  10956. mmiowb();
  10957. barrier();
  10958. /* Unset iSCSI L2 MAC */
  10959. rc = bnx2x_del_all_macs(bp, &bp->iscsi_l2_mac_obj,
  10960. BNX2X_ISCSI_ETH_MAC, true);
  10961. break;
  10962. }
  10963. case DRV_CTL_RET_L2_SPQ_CREDIT_CMD: {
  10964. int count = ctl->data.credit.credit_count;
  10965. smp_mb__before_atomic_inc();
  10966. atomic_add(count, &bp->cq_spq_left);
  10967. smp_mb__after_atomic_inc();
  10968. break;
  10969. }
  10970. case DRV_CTL_ULP_REGISTER_CMD: {
  10971. int ulp_type = ctl->data.register_data.ulp_type;
  10972. if (CHIP_IS_E3(bp)) {
  10973. int idx = BP_FW_MB_IDX(bp);
  10974. u32 cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  10975. int path = BP_PATH(bp);
  10976. int port = BP_PORT(bp);
  10977. int i;
  10978. u32 scratch_offset;
  10979. u32 *host_addr;
  10980. /* first write capability to shmem2 */
  10981. if (ulp_type == CNIC_ULP_ISCSI)
  10982. cap |= DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  10983. else if (ulp_type == CNIC_ULP_FCOE)
  10984. cap |= DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  10985. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  10986. if ((ulp_type != CNIC_ULP_FCOE) ||
  10987. (!SHMEM2_HAS(bp, ncsi_oem_data_addr)) ||
  10988. (!(bp->flags & BC_SUPPORTS_FCOE_FEATURES)))
  10989. break;
  10990. /* if reached here - should write fcoe capabilities */
  10991. scratch_offset = SHMEM2_RD(bp, ncsi_oem_data_addr);
  10992. if (!scratch_offset)
  10993. break;
  10994. scratch_offset += offsetof(struct glob_ncsi_oem_data,
  10995. fcoe_features[path][port]);
  10996. host_addr = (u32 *) &(ctl->data.register_data.
  10997. fcoe_features);
  10998. for (i = 0; i < sizeof(struct fcoe_capabilities);
  10999. i += 4)
  11000. REG_WR(bp, scratch_offset + i,
  11001. *(host_addr + i/4));
  11002. }
  11003. break;
  11004. }
  11005. case DRV_CTL_ULP_UNREGISTER_CMD: {
  11006. int ulp_type = ctl->data.ulp_type;
  11007. if (CHIP_IS_E3(bp)) {
  11008. int idx = BP_FW_MB_IDX(bp);
  11009. u32 cap;
  11010. cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  11011. if (ulp_type == CNIC_ULP_ISCSI)
  11012. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  11013. else if (ulp_type == CNIC_ULP_FCOE)
  11014. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  11015. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  11016. }
  11017. break;
  11018. }
  11019. default:
  11020. BNX2X_ERR("unknown command %x\n", ctl->cmd);
  11021. rc = -EINVAL;
  11022. }
  11023. return rc;
  11024. }
  11025. void bnx2x_setup_cnic_irq_info(struct bnx2x *bp)
  11026. {
  11027. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11028. if (bp->flags & USING_MSIX_FLAG) {
  11029. cp->drv_state |= CNIC_DRV_STATE_USING_MSIX;
  11030. cp->irq_arr[0].irq_flags |= CNIC_IRQ_FL_MSIX;
  11031. cp->irq_arr[0].vector = bp->msix_table[1].vector;
  11032. } else {
  11033. cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX;
  11034. cp->irq_arr[0].irq_flags &= ~CNIC_IRQ_FL_MSIX;
  11035. }
  11036. if (!CHIP_IS_E1x(bp))
  11037. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e2_sb;
  11038. else
  11039. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e1x_sb;
  11040. cp->irq_arr[0].status_blk_num = bnx2x_cnic_fw_sb_id(bp);
  11041. cp->irq_arr[0].status_blk_num2 = bnx2x_cnic_igu_sb_id(bp);
  11042. cp->irq_arr[1].status_blk = bp->def_status_blk;
  11043. cp->irq_arr[1].status_blk_num = DEF_SB_ID;
  11044. cp->irq_arr[1].status_blk_num2 = DEF_SB_IGU_ID;
  11045. cp->num_irq = 2;
  11046. }
  11047. void bnx2x_setup_cnic_info(struct bnx2x *bp)
  11048. {
  11049. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11050. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  11051. bnx2x_cid_ilt_lines(bp);
  11052. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  11053. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
  11054. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
  11055. if (NO_ISCSI_OOO(bp))
  11056. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  11057. }
  11058. static int bnx2x_register_cnic(struct net_device *dev, struct cnic_ops *ops,
  11059. void *data)
  11060. {
  11061. struct bnx2x *bp = netdev_priv(dev);
  11062. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11063. int rc;
  11064. DP(NETIF_MSG_IFUP, "Register_cnic called\n");
  11065. if (ops == NULL) {
  11066. BNX2X_ERR("NULL ops received\n");
  11067. return -EINVAL;
  11068. }
  11069. if (!CNIC_SUPPORT(bp)) {
  11070. BNX2X_ERR("Can't register CNIC when not supported\n");
  11071. return -EOPNOTSUPP;
  11072. }
  11073. if (!CNIC_LOADED(bp)) {
  11074. rc = bnx2x_load_cnic(bp);
  11075. if (rc) {
  11076. BNX2X_ERR("CNIC-related load failed\n");
  11077. return rc;
  11078. }
  11079. }
  11080. bp->cnic_enabled = true;
  11081. bp->cnic_kwq = kzalloc(PAGE_SIZE, GFP_KERNEL);
  11082. if (!bp->cnic_kwq)
  11083. return -ENOMEM;
  11084. bp->cnic_kwq_cons = bp->cnic_kwq;
  11085. bp->cnic_kwq_prod = bp->cnic_kwq;
  11086. bp->cnic_kwq_last = bp->cnic_kwq + MAX_SP_DESC_CNT;
  11087. bp->cnic_spq_pending = 0;
  11088. bp->cnic_kwq_pending = 0;
  11089. bp->cnic_data = data;
  11090. cp->num_irq = 0;
  11091. cp->drv_state |= CNIC_DRV_STATE_REGD;
  11092. cp->iro_arr = bp->iro_arr;
  11093. bnx2x_setup_cnic_irq_info(bp);
  11094. rcu_assign_pointer(bp->cnic_ops, ops);
  11095. return 0;
  11096. }
  11097. static int bnx2x_unregister_cnic(struct net_device *dev)
  11098. {
  11099. struct bnx2x *bp = netdev_priv(dev);
  11100. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11101. mutex_lock(&bp->cnic_mutex);
  11102. cp->drv_state = 0;
  11103. RCU_INIT_POINTER(bp->cnic_ops, NULL);
  11104. mutex_unlock(&bp->cnic_mutex);
  11105. synchronize_rcu();
  11106. kfree(bp->cnic_kwq);
  11107. bp->cnic_kwq = NULL;
  11108. return 0;
  11109. }
  11110. struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev)
  11111. {
  11112. struct bnx2x *bp = netdev_priv(dev);
  11113. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11114. /* If both iSCSI and FCoE are disabled - return NULL in
  11115. * order to indicate CNIC that it should not try to work
  11116. * with this device.
  11117. */
  11118. if (NO_ISCSI(bp) && NO_FCOE(bp))
  11119. return NULL;
  11120. cp->drv_owner = THIS_MODULE;
  11121. cp->chip_id = CHIP_ID(bp);
  11122. cp->pdev = bp->pdev;
  11123. cp->io_base = bp->regview;
  11124. cp->io_base2 = bp->doorbells;
  11125. cp->max_kwqe_pending = 8;
  11126. cp->ctx_blk_size = CDU_ILT_PAGE_SZ;
  11127. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  11128. bnx2x_cid_ilt_lines(bp);
  11129. cp->ctx_tbl_len = CNIC_ILT_LINES;
  11130. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  11131. cp->drv_submit_kwqes_16 = bnx2x_cnic_sp_queue;
  11132. cp->drv_ctl = bnx2x_drv_ctl;
  11133. cp->drv_register_cnic = bnx2x_register_cnic;
  11134. cp->drv_unregister_cnic = bnx2x_unregister_cnic;
  11135. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
  11136. cp->iscsi_l2_client_id =
  11137. bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  11138. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
  11139. if (NO_ISCSI_OOO(bp))
  11140. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  11141. if (NO_ISCSI(bp))
  11142. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI;
  11143. if (NO_FCOE(bp))
  11144. cp->drv_state |= CNIC_DRV_STATE_NO_FCOE;
  11145. BNX2X_DEV_INFO(
  11146. "page_size %d, tbl_offset %d, tbl_lines %d, starting cid %d\n",
  11147. cp->ctx_blk_size,
  11148. cp->ctx_tbl_offset,
  11149. cp->ctx_tbl_len,
  11150. cp->starting_cid);
  11151. return cp;
  11152. }
  11153. u32 bnx2x_rx_ustorm_prods_offset(struct bnx2x_fastpath *fp)
  11154. {
  11155. struct bnx2x *bp = fp->bp;
  11156. u32 offset = BAR_USTRORM_INTMEM;
  11157. if (IS_VF(bp))
  11158. return bnx2x_vf_ustorm_prods_offset(bp, fp);
  11159. else if (!CHIP_IS_E1x(bp))
  11160. offset += USTORM_RX_PRODS_E2_OFFSET(fp->cl_qzone_id);
  11161. else
  11162. offset += USTORM_RX_PRODS_E1X_OFFSET(BP_PORT(bp), fp->cl_id);
  11163. return offset;
  11164. }
  11165. /* called only on E1H or E2.
  11166. * When pretending to be PF, the pretend value is the function number 0...7
  11167. * When pretending to be VF, the pretend val is the PF-num:VF-valid:ABS-VFID
  11168. * combination
  11169. */
  11170. int bnx2x_pretend_func(struct bnx2x *bp, u16 pretend_func_val)
  11171. {
  11172. u32 pretend_reg;
  11173. if (CHIP_IS_E1H(bp) && pretend_func_val >= E1H_FUNC_MAX)
  11174. return -1;
  11175. /* get my own pretend register */
  11176. pretend_reg = bnx2x_get_pretend_reg(bp);
  11177. REG_WR(bp, pretend_reg, pretend_func_val);
  11178. REG_RD(bp, pretend_reg);
  11179. return 0;
  11180. }