bnx2x_main.c 369 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672
  1. /* bnx2x_main.c: Broadcom Everest network driver.
  2. *
  3. * Copyright (c) 2007-2013 Broadcom Corporation
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation.
  8. *
  9. * Maintained by: Eilon Greenstein <eilong@broadcom.com>
  10. * Written by: Eliezer Tamir
  11. * Based on code from Michael Chan's bnx2 driver
  12. * UDP CSUM errata workaround by Arik Gendelman
  13. * Slowpath and fastpath rework by Vladislav Zolotarov
  14. * Statistics and Link management by Yitchak Gertner
  15. *
  16. */
  17. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  18. #include <linux/module.h>
  19. #include <linux/moduleparam.h>
  20. #include <linux/kernel.h>
  21. #include <linux/device.h> /* for dev_info() */
  22. #include <linux/timer.h>
  23. #include <linux/errno.h>
  24. #include <linux/ioport.h>
  25. #include <linux/slab.h>
  26. #include <linux/interrupt.h>
  27. #include <linux/pci.h>
  28. #include <linux/init.h>
  29. #include <linux/netdevice.h>
  30. #include <linux/etherdevice.h>
  31. #include <linux/skbuff.h>
  32. #include <linux/dma-mapping.h>
  33. #include <linux/bitops.h>
  34. #include <linux/irq.h>
  35. #include <linux/delay.h>
  36. #include <asm/byteorder.h>
  37. #include <linux/time.h>
  38. #include <linux/ethtool.h>
  39. #include <linux/mii.h>
  40. #include <linux/if_vlan.h>
  41. #include <net/ip.h>
  42. #include <net/ipv6.h>
  43. #include <net/tcp.h>
  44. #include <net/checksum.h>
  45. #include <net/ip6_checksum.h>
  46. #include <linux/workqueue.h>
  47. #include <linux/crc32.h>
  48. #include <linux/crc32c.h>
  49. #include <linux/prefetch.h>
  50. #include <linux/zlib.h>
  51. #include <linux/io.h>
  52. #include <linux/semaphore.h>
  53. #include <linux/stringify.h>
  54. #include <linux/vmalloc.h>
  55. #include "bnx2x.h"
  56. #include "bnx2x_init.h"
  57. #include "bnx2x_init_ops.h"
  58. #include "bnx2x_cmn.h"
  59. #include "bnx2x_vfpf.h"
  60. #include "bnx2x_dcb.h"
  61. #include "bnx2x_sp.h"
  62. #include <linux/firmware.h>
  63. #include "bnx2x_fw_file_hdr.h"
  64. /* FW files */
  65. #define FW_FILE_VERSION \
  66. __stringify(BCM_5710_FW_MAJOR_VERSION) "." \
  67. __stringify(BCM_5710_FW_MINOR_VERSION) "." \
  68. __stringify(BCM_5710_FW_REVISION_VERSION) "." \
  69. __stringify(BCM_5710_FW_ENGINEERING_VERSION)
  70. #define FW_FILE_NAME_E1 "bnx2x/bnx2x-e1-" FW_FILE_VERSION ".fw"
  71. #define FW_FILE_NAME_E1H "bnx2x/bnx2x-e1h-" FW_FILE_VERSION ".fw"
  72. #define FW_FILE_NAME_E2 "bnx2x/bnx2x-e2-" FW_FILE_VERSION ".fw"
  73. /* Time in jiffies before concluding the transmitter is hung */
  74. #define TX_TIMEOUT (5*HZ)
  75. static char version[] =
  76. "Broadcom NetXtreme II 5771x/578xx 10/20-Gigabit Ethernet Driver "
  77. DRV_MODULE_NAME " " DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
  78. MODULE_AUTHOR("Eliezer Tamir");
  79. MODULE_DESCRIPTION("Broadcom NetXtreme II "
  80. "BCM57710/57711/57711E/"
  81. "57712/57712_MF/57800/57800_MF/57810/57810_MF/"
  82. "57840/57840_MF Driver");
  83. MODULE_LICENSE("GPL");
  84. MODULE_VERSION(DRV_MODULE_VERSION);
  85. MODULE_FIRMWARE(FW_FILE_NAME_E1);
  86. MODULE_FIRMWARE(FW_FILE_NAME_E1H);
  87. MODULE_FIRMWARE(FW_FILE_NAME_E2);
  88. int num_queues;
  89. module_param(num_queues, int, 0);
  90. MODULE_PARM_DESC(num_queues,
  91. " Set number of queues (default is as a number of CPUs)");
  92. static int disable_tpa;
  93. module_param(disable_tpa, int, 0);
  94. MODULE_PARM_DESC(disable_tpa, " Disable the TPA (LRO) feature");
  95. #define INT_MODE_INTx 1
  96. #define INT_MODE_MSI 2
  97. int int_mode;
  98. module_param(int_mode, int, 0);
  99. MODULE_PARM_DESC(int_mode, " Force interrupt mode other than MSI-X "
  100. "(1 INT#x; 2 MSI)");
  101. static int dropless_fc;
  102. module_param(dropless_fc, int, 0);
  103. MODULE_PARM_DESC(dropless_fc, " Pause on exhausted host ring");
  104. static int mrrs = -1;
  105. module_param(mrrs, int, 0);
  106. MODULE_PARM_DESC(mrrs, " Force Max Read Req Size (0..3) (for debug)");
  107. static int debug;
  108. module_param(debug, int, 0);
  109. MODULE_PARM_DESC(debug, " Default debug msglevel");
  110. struct workqueue_struct *bnx2x_wq;
  111. struct bnx2x_mac_vals {
  112. u32 xmac_addr;
  113. u32 xmac_val;
  114. u32 emac_addr;
  115. u32 emac_val;
  116. u32 umac_addr;
  117. u32 umac_val;
  118. u32 bmac_addr;
  119. u32 bmac_val[2];
  120. };
  121. enum bnx2x_board_type {
  122. BCM57710 = 0,
  123. BCM57711,
  124. BCM57711E,
  125. BCM57712,
  126. BCM57712_MF,
  127. BCM57712_VF,
  128. BCM57800,
  129. BCM57800_MF,
  130. BCM57800_VF,
  131. BCM57810,
  132. BCM57810_MF,
  133. BCM57810_VF,
  134. BCM57840_4_10,
  135. BCM57840_2_20,
  136. BCM57840_MF,
  137. BCM57840_VF,
  138. BCM57811,
  139. BCM57811_MF,
  140. BCM57840_O,
  141. BCM57840_MFO,
  142. BCM57811_VF
  143. };
  144. /* indexed by board_type, above */
  145. static struct {
  146. char *name;
  147. } board_info[] = {
  148. [BCM57710] = { "Broadcom NetXtreme II BCM57710 10 Gigabit PCIe [Everest]" },
  149. [BCM57711] = { "Broadcom NetXtreme II BCM57711 10 Gigabit PCIe" },
  150. [BCM57711E] = { "Broadcom NetXtreme II BCM57711E 10 Gigabit PCIe" },
  151. [BCM57712] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet" },
  152. [BCM57712_MF] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Multi Function" },
  153. [BCM57712_VF] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Virtual Function" },
  154. [BCM57800] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet" },
  155. [BCM57800_MF] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Multi Function" },
  156. [BCM57800_VF] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Virtual Function" },
  157. [BCM57810] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet" },
  158. [BCM57810_MF] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Multi Function" },
  159. [BCM57810_VF] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Virtual Function" },
  160. [BCM57840_4_10] = { "Broadcom NetXtreme II BCM57840 10 Gigabit Ethernet" },
  161. [BCM57840_2_20] = { "Broadcom NetXtreme II BCM57840 20 Gigabit Ethernet" },
  162. [BCM57840_MF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function" },
  163. [BCM57840_VF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Virtual Function" },
  164. [BCM57811] = { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet" },
  165. [BCM57811_MF] = { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet Multi Function" },
  166. [BCM57840_O] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet" },
  167. [BCM57840_MFO] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function" },
  168. [BCM57811_VF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Virtual Function" }
  169. };
  170. #ifndef PCI_DEVICE_ID_NX2_57710
  171. #define PCI_DEVICE_ID_NX2_57710 CHIP_NUM_57710
  172. #endif
  173. #ifndef PCI_DEVICE_ID_NX2_57711
  174. #define PCI_DEVICE_ID_NX2_57711 CHIP_NUM_57711
  175. #endif
  176. #ifndef PCI_DEVICE_ID_NX2_57711E
  177. #define PCI_DEVICE_ID_NX2_57711E CHIP_NUM_57711E
  178. #endif
  179. #ifndef PCI_DEVICE_ID_NX2_57712
  180. #define PCI_DEVICE_ID_NX2_57712 CHIP_NUM_57712
  181. #endif
  182. #ifndef PCI_DEVICE_ID_NX2_57712_MF
  183. #define PCI_DEVICE_ID_NX2_57712_MF CHIP_NUM_57712_MF
  184. #endif
  185. #ifndef PCI_DEVICE_ID_NX2_57712_VF
  186. #define PCI_DEVICE_ID_NX2_57712_VF CHIP_NUM_57712_VF
  187. #endif
  188. #ifndef PCI_DEVICE_ID_NX2_57800
  189. #define PCI_DEVICE_ID_NX2_57800 CHIP_NUM_57800
  190. #endif
  191. #ifndef PCI_DEVICE_ID_NX2_57800_MF
  192. #define PCI_DEVICE_ID_NX2_57800_MF CHIP_NUM_57800_MF
  193. #endif
  194. #ifndef PCI_DEVICE_ID_NX2_57800_VF
  195. #define PCI_DEVICE_ID_NX2_57800_VF CHIP_NUM_57800_VF
  196. #endif
  197. #ifndef PCI_DEVICE_ID_NX2_57810
  198. #define PCI_DEVICE_ID_NX2_57810 CHIP_NUM_57810
  199. #endif
  200. #ifndef PCI_DEVICE_ID_NX2_57810_MF
  201. #define PCI_DEVICE_ID_NX2_57810_MF CHIP_NUM_57810_MF
  202. #endif
  203. #ifndef PCI_DEVICE_ID_NX2_57840_O
  204. #define PCI_DEVICE_ID_NX2_57840_O CHIP_NUM_57840_OBSOLETE
  205. #endif
  206. #ifndef PCI_DEVICE_ID_NX2_57810_VF
  207. #define PCI_DEVICE_ID_NX2_57810_VF CHIP_NUM_57810_VF
  208. #endif
  209. #ifndef PCI_DEVICE_ID_NX2_57840_4_10
  210. #define PCI_DEVICE_ID_NX2_57840_4_10 CHIP_NUM_57840_4_10
  211. #endif
  212. #ifndef PCI_DEVICE_ID_NX2_57840_2_20
  213. #define PCI_DEVICE_ID_NX2_57840_2_20 CHIP_NUM_57840_2_20
  214. #endif
  215. #ifndef PCI_DEVICE_ID_NX2_57840_MFO
  216. #define PCI_DEVICE_ID_NX2_57840_MFO CHIP_NUM_57840_MF_OBSOLETE
  217. #endif
  218. #ifndef PCI_DEVICE_ID_NX2_57840_MF
  219. #define PCI_DEVICE_ID_NX2_57840_MF CHIP_NUM_57840_MF
  220. #endif
  221. #ifndef PCI_DEVICE_ID_NX2_57840_VF
  222. #define PCI_DEVICE_ID_NX2_57840_VF CHIP_NUM_57840_VF
  223. #endif
  224. #ifndef PCI_DEVICE_ID_NX2_57811
  225. #define PCI_DEVICE_ID_NX2_57811 CHIP_NUM_57811
  226. #endif
  227. #ifndef PCI_DEVICE_ID_NX2_57811_MF
  228. #define PCI_DEVICE_ID_NX2_57811_MF CHIP_NUM_57811_MF
  229. #endif
  230. #ifndef PCI_DEVICE_ID_NX2_57811_VF
  231. #define PCI_DEVICE_ID_NX2_57811_VF CHIP_NUM_57811_VF
  232. #endif
  233. static DEFINE_PCI_DEVICE_TABLE(bnx2x_pci_tbl) = {
  234. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57710), BCM57710 },
  235. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711), BCM57711 },
  236. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711E), BCM57711E },
  237. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712), BCM57712 },
  238. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_MF), BCM57712_MF },
  239. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_VF), BCM57712_VF },
  240. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800), BCM57800 },
  241. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_MF), BCM57800_MF },
  242. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_VF), BCM57800_VF },
  243. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810), BCM57810 },
  244. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_MF), BCM57810_MF },
  245. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_O), BCM57840_O },
  246. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_4_10), BCM57840_4_10 },
  247. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_2_20), BCM57840_2_20 },
  248. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_VF), BCM57810_VF },
  249. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MFO), BCM57840_MFO },
  250. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MF), BCM57840_MF },
  251. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_VF), BCM57840_VF },
  252. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811), BCM57811 },
  253. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_MF), BCM57811_MF },
  254. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_VF), BCM57811_VF },
  255. { 0 }
  256. };
  257. MODULE_DEVICE_TABLE(pci, bnx2x_pci_tbl);
  258. /* Global resources for unloading a previously loaded device */
  259. #define BNX2X_PREV_WAIT_NEEDED 1
  260. static DEFINE_SEMAPHORE(bnx2x_prev_sem);
  261. static LIST_HEAD(bnx2x_prev_list);
  262. /****************************************************************************
  263. * General service functions
  264. ****************************************************************************/
  265. static void __storm_memset_dma_mapping(struct bnx2x *bp,
  266. u32 addr, dma_addr_t mapping)
  267. {
  268. REG_WR(bp, addr, U64_LO(mapping));
  269. REG_WR(bp, addr + 4, U64_HI(mapping));
  270. }
  271. static void storm_memset_spq_addr(struct bnx2x *bp,
  272. dma_addr_t mapping, u16 abs_fid)
  273. {
  274. u32 addr = XSEM_REG_FAST_MEMORY +
  275. XSTORM_SPQ_PAGE_BASE_OFFSET(abs_fid);
  276. __storm_memset_dma_mapping(bp, addr, mapping);
  277. }
  278. static void storm_memset_vf_to_pf(struct bnx2x *bp, u16 abs_fid,
  279. u16 pf_id)
  280. {
  281. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_VF_TO_PF_OFFSET(abs_fid),
  282. pf_id);
  283. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_VF_TO_PF_OFFSET(abs_fid),
  284. pf_id);
  285. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_VF_TO_PF_OFFSET(abs_fid),
  286. pf_id);
  287. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_VF_TO_PF_OFFSET(abs_fid),
  288. pf_id);
  289. }
  290. static void storm_memset_func_en(struct bnx2x *bp, u16 abs_fid,
  291. u8 enable)
  292. {
  293. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(abs_fid),
  294. enable);
  295. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(abs_fid),
  296. enable);
  297. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(abs_fid),
  298. enable);
  299. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(abs_fid),
  300. enable);
  301. }
  302. static void storm_memset_eq_data(struct bnx2x *bp,
  303. struct event_ring_data *eq_data,
  304. u16 pfid)
  305. {
  306. size_t size = sizeof(struct event_ring_data);
  307. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_DATA_OFFSET(pfid);
  308. __storm_memset_struct(bp, addr, size, (u32 *)eq_data);
  309. }
  310. static void storm_memset_eq_prod(struct bnx2x *bp, u16 eq_prod,
  311. u16 pfid)
  312. {
  313. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_PROD_OFFSET(pfid);
  314. REG_WR16(bp, addr, eq_prod);
  315. }
  316. /* used only at init
  317. * locking is done by mcp
  318. */
  319. static void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val)
  320. {
  321. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  322. pci_write_config_dword(bp->pdev, PCICFG_GRC_DATA, val);
  323. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  324. PCICFG_VENDOR_ID_OFFSET);
  325. }
  326. static u32 bnx2x_reg_rd_ind(struct bnx2x *bp, u32 addr)
  327. {
  328. u32 val;
  329. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  330. pci_read_config_dword(bp->pdev, PCICFG_GRC_DATA, &val);
  331. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  332. PCICFG_VENDOR_ID_OFFSET);
  333. return val;
  334. }
  335. #define DMAE_DP_SRC_GRC "grc src_addr [%08x]"
  336. #define DMAE_DP_SRC_PCI "pci src_addr [%x:%08x]"
  337. #define DMAE_DP_DST_GRC "grc dst_addr [%08x]"
  338. #define DMAE_DP_DST_PCI "pci dst_addr [%x:%08x]"
  339. #define DMAE_DP_DST_NONE "dst_addr [none]"
  340. void bnx2x_dp_dmae(struct bnx2x *bp, struct dmae_command *dmae, int msglvl)
  341. {
  342. u32 src_type = dmae->opcode & DMAE_COMMAND_SRC;
  343. switch (dmae->opcode & DMAE_COMMAND_DST) {
  344. case DMAE_CMD_DST_PCI:
  345. if (src_type == DMAE_CMD_SRC_PCI)
  346. DP(msglvl, "DMAE: opcode 0x%08x\n"
  347. "src [%x:%08x], len [%d*4], dst [%x:%08x]\n"
  348. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  349. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  350. dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
  351. dmae->comp_addr_hi, dmae->comp_addr_lo,
  352. dmae->comp_val);
  353. else
  354. DP(msglvl, "DMAE: opcode 0x%08x\n"
  355. "src [%08x], len [%d*4], dst [%x:%08x]\n"
  356. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  357. dmae->opcode, dmae->src_addr_lo >> 2,
  358. dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
  359. dmae->comp_addr_hi, dmae->comp_addr_lo,
  360. dmae->comp_val);
  361. break;
  362. case DMAE_CMD_DST_GRC:
  363. if (src_type == DMAE_CMD_SRC_PCI)
  364. DP(msglvl, "DMAE: opcode 0x%08x\n"
  365. "src [%x:%08x], len [%d*4], dst_addr [%08x]\n"
  366. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  367. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  368. dmae->len, dmae->dst_addr_lo >> 2,
  369. dmae->comp_addr_hi, dmae->comp_addr_lo,
  370. dmae->comp_val);
  371. else
  372. DP(msglvl, "DMAE: opcode 0x%08x\n"
  373. "src [%08x], len [%d*4], dst [%08x]\n"
  374. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  375. dmae->opcode, dmae->src_addr_lo >> 2,
  376. dmae->len, dmae->dst_addr_lo >> 2,
  377. dmae->comp_addr_hi, dmae->comp_addr_lo,
  378. dmae->comp_val);
  379. break;
  380. default:
  381. if (src_type == DMAE_CMD_SRC_PCI)
  382. DP(msglvl, "DMAE: opcode 0x%08x\n"
  383. "src_addr [%x:%08x] len [%d * 4] dst_addr [none]\n"
  384. "comp_addr [%x:%08x] comp_val 0x%08x\n",
  385. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  386. dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
  387. dmae->comp_val);
  388. else
  389. DP(msglvl, "DMAE: opcode 0x%08x\n"
  390. "src_addr [%08x] len [%d * 4] dst_addr [none]\n"
  391. "comp_addr [%x:%08x] comp_val 0x%08x\n",
  392. dmae->opcode, dmae->src_addr_lo >> 2,
  393. dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
  394. dmae->comp_val);
  395. break;
  396. }
  397. }
  398. /* copy command into DMAE command memory and set DMAE command go */
  399. void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae, int idx)
  400. {
  401. u32 cmd_offset;
  402. int i;
  403. cmd_offset = (DMAE_REG_CMD_MEM + sizeof(struct dmae_command) * idx);
  404. for (i = 0; i < (sizeof(struct dmae_command)/4); i++) {
  405. REG_WR(bp, cmd_offset + i*4, *(((u32 *)dmae) + i));
  406. }
  407. REG_WR(bp, dmae_reg_go_c[idx], 1);
  408. }
  409. u32 bnx2x_dmae_opcode_add_comp(u32 opcode, u8 comp_type)
  410. {
  411. return opcode | ((comp_type << DMAE_COMMAND_C_DST_SHIFT) |
  412. DMAE_CMD_C_ENABLE);
  413. }
  414. u32 bnx2x_dmae_opcode_clr_src_reset(u32 opcode)
  415. {
  416. return opcode & ~DMAE_CMD_SRC_RESET;
  417. }
  418. u32 bnx2x_dmae_opcode(struct bnx2x *bp, u8 src_type, u8 dst_type,
  419. bool with_comp, u8 comp_type)
  420. {
  421. u32 opcode = 0;
  422. opcode |= ((src_type << DMAE_COMMAND_SRC_SHIFT) |
  423. (dst_type << DMAE_COMMAND_DST_SHIFT));
  424. opcode |= (DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET);
  425. opcode |= (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0);
  426. opcode |= ((BP_VN(bp) << DMAE_CMD_E1HVN_SHIFT) |
  427. (BP_VN(bp) << DMAE_COMMAND_DST_VN_SHIFT));
  428. opcode |= (DMAE_COM_SET_ERR << DMAE_COMMAND_ERR_POLICY_SHIFT);
  429. #ifdef __BIG_ENDIAN
  430. opcode |= DMAE_CMD_ENDIANITY_B_DW_SWAP;
  431. #else
  432. opcode |= DMAE_CMD_ENDIANITY_DW_SWAP;
  433. #endif
  434. if (with_comp)
  435. opcode = bnx2x_dmae_opcode_add_comp(opcode, comp_type);
  436. return opcode;
  437. }
  438. void bnx2x_prep_dmae_with_comp(struct bnx2x *bp,
  439. struct dmae_command *dmae,
  440. u8 src_type, u8 dst_type)
  441. {
  442. memset(dmae, 0, sizeof(struct dmae_command));
  443. /* set the opcode */
  444. dmae->opcode = bnx2x_dmae_opcode(bp, src_type, dst_type,
  445. true, DMAE_COMP_PCI);
  446. /* fill in the completion parameters */
  447. dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp));
  448. dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp));
  449. dmae->comp_val = DMAE_COMP_VAL;
  450. }
  451. /* issue a dmae command over the init-channel and wait for completion */
  452. int bnx2x_issue_dmae_with_comp(struct bnx2x *bp, struct dmae_command *dmae)
  453. {
  454. u32 *wb_comp = bnx2x_sp(bp, wb_comp);
  455. int cnt = CHIP_REV_IS_SLOW(bp) ? (400000) : 4000;
  456. int rc = 0;
  457. /*
  458. * Lock the dmae channel. Disable BHs to prevent a dead-lock
  459. * as long as this code is called both from syscall context and
  460. * from ndo_set_rx_mode() flow that may be called from BH.
  461. */
  462. spin_lock_bh(&bp->dmae_lock);
  463. /* reset completion */
  464. *wb_comp = 0;
  465. /* post the command on the channel used for initializations */
  466. bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp));
  467. /* wait for completion */
  468. udelay(5);
  469. while ((*wb_comp & ~DMAE_PCI_ERR_FLAG) != DMAE_COMP_VAL) {
  470. if (!cnt ||
  471. (bp->recovery_state != BNX2X_RECOVERY_DONE &&
  472. bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  473. BNX2X_ERR("DMAE timeout!\n");
  474. rc = DMAE_TIMEOUT;
  475. goto unlock;
  476. }
  477. cnt--;
  478. udelay(50);
  479. }
  480. if (*wb_comp & DMAE_PCI_ERR_FLAG) {
  481. BNX2X_ERR("DMAE PCI error!\n");
  482. rc = DMAE_PCI_ERROR;
  483. }
  484. unlock:
  485. spin_unlock_bh(&bp->dmae_lock);
  486. return rc;
  487. }
  488. void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr,
  489. u32 len32)
  490. {
  491. struct dmae_command dmae;
  492. if (!bp->dmae_ready) {
  493. u32 *data = bnx2x_sp(bp, wb_data[0]);
  494. if (CHIP_IS_E1(bp))
  495. bnx2x_init_ind_wr(bp, dst_addr, data, len32);
  496. else
  497. bnx2x_init_str_wr(bp, dst_addr, data, len32);
  498. return;
  499. }
  500. /* set opcode and fixed command fields */
  501. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_GRC);
  502. /* fill in addresses and len */
  503. dmae.src_addr_lo = U64_LO(dma_addr);
  504. dmae.src_addr_hi = U64_HI(dma_addr);
  505. dmae.dst_addr_lo = dst_addr >> 2;
  506. dmae.dst_addr_hi = 0;
  507. dmae.len = len32;
  508. /* issue the command and wait for completion */
  509. bnx2x_issue_dmae_with_comp(bp, &dmae);
  510. }
  511. void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32)
  512. {
  513. struct dmae_command dmae;
  514. if (!bp->dmae_ready) {
  515. u32 *data = bnx2x_sp(bp, wb_data[0]);
  516. int i;
  517. if (CHIP_IS_E1(bp))
  518. for (i = 0; i < len32; i++)
  519. data[i] = bnx2x_reg_rd_ind(bp, src_addr + i*4);
  520. else
  521. for (i = 0; i < len32; i++)
  522. data[i] = REG_RD(bp, src_addr + i*4);
  523. return;
  524. }
  525. /* set opcode and fixed command fields */
  526. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_GRC, DMAE_DST_PCI);
  527. /* fill in addresses and len */
  528. dmae.src_addr_lo = src_addr >> 2;
  529. dmae.src_addr_hi = 0;
  530. dmae.dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_data));
  531. dmae.dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_data));
  532. dmae.len = len32;
  533. /* issue the command and wait for completion */
  534. bnx2x_issue_dmae_with_comp(bp, &dmae);
  535. }
  536. static void bnx2x_write_dmae_phys_len(struct bnx2x *bp, dma_addr_t phys_addr,
  537. u32 addr, u32 len)
  538. {
  539. int dmae_wr_max = DMAE_LEN32_WR_MAX(bp);
  540. int offset = 0;
  541. while (len > dmae_wr_max) {
  542. bnx2x_write_dmae(bp, phys_addr + offset,
  543. addr + offset, dmae_wr_max);
  544. offset += dmae_wr_max * 4;
  545. len -= dmae_wr_max;
  546. }
  547. bnx2x_write_dmae(bp, phys_addr + offset, addr + offset, len);
  548. }
  549. static int bnx2x_mc_assert(struct bnx2x *bp)
  550. {
  551. char last_idx;
  552. int i, rc = 0;
  553. u32 row0, row1, row2, row3;
  554. /* XSTORM */
  555. last_idx = REG_RD8(bp, BAR_XSTRORM_INTMEM +
  556. XSTORM_ASSERT_LIST_INDEX_OFFSET);
  557. if (last_idx)
  558. BNX2X_ERR("XSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  559. /* print the asserts */
  560. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  561. row0 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  562. XSTORM_ASSERT_LIST_OFFSET(i));
  563. row1 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  564. XSTORM_ASSERT_LIST_OFFSET(i) + 4);
  565. row2 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  566. XSTORM_ASSERT_LIST_OFFSET(i) + 8);
  567. row3 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  568. XSTORM_ASSERT_LIST_OFFSET(i) + 12);
  569. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  570. BNX2X_ERR("XSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  571. i, row3, row2, row1, row0);
  572. rc++;
  573. } else {
  574. break;
  575. }
  576. }
  577. /* TSTORM */
  578. last_idx = REG_RD8(bp, BAR_TSTRORM_INTMEM +
  579. TSTORM_ASSERT_LIST_INDEX_OFFSET);
  580. if (last_idx)
  581. BNX2X_ERR("TSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  582. /* print the asserts */
  583. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  584. row0 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  585. TSTORM_ASSERT_LIST_OFFSET(i));
  586. row1 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  587. TSTORM_ASSERT_LIST_OFFSET(i) + 4);
  588. row2 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  589. TSTORM_ASSERT_LIST_OFFSET(i) + 8);
  590. row3 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  591. TSTORM_ASSERT_LIST_OFFSET(i) + 12);
  592. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  593. BNX2X_ERR("TSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  594. i, row3, row2, row1, row0);
  595. rc++;
  596. } else {
  597. break;
  598. }
  599. }
  600. /* CSTORM */
  601. last_idx = REG_RD8(bp, BAR_CSTRORM_INTMEM +
  602. CSTORM_ASSERT_LIST_INDEX_OFFSET);
  603. if (last_idx)
  604. BNX2X_ERR("CSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  605. /* print the asserts */
  606. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  607. row0 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  608. CSTORM_ASSERT_LIST_OFFSET(i));
  609. row1 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  610. CSTORM_ASSERT_LIST_OFFSET(i) + 4);
  611. row2 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  612. CSTORM_ASSERT_LIST_OFFSET(i) + 8);
  613. row3 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  614. CSTORM_ASSERT_LIST_OFFSET(i) + 12);
  615. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  616. BNX2X_ERR("CSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  617. i, row3, row2, row1, row0);
  618. rc++;
  619. } else {
  620. break;
  621. }
  622. }
  623. /* USTORM */
  624. last_idx = REG_RD8(bp, BAR_USTRORM_INTMEM +
  625. USTORM_ASSERT_LIST_INDEX_OFFSET);
  626. if (last_idx)
  627. BNX2X_ERR("USTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  628. /* print the asserts */
  629. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  630. row0 = REG_RD(bp, BAR_USTRORM_INTMEM +
  631. USTORM_ASSERT_LIST_OFFSET(i));
  632. row1 = REG_RD(bp, BAR_USTRORM_INTMEM +
  633. USTORM_ASSERT_LIST_OFFSET(i) + 4);
  634. row2 = REG_RD(bp, BAR_USTRORM_INTMEM +
  635. USTORM_ASSERT_LIST_OFFSET(i) + 8);
  636. row3 = REG_RD(bp, BAR_USTRORM_INTMEM +
  637. USTORM_ASSERT_LIST_OFFSET(i) + 12);
  638. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  639. BNX2X_ERR("USTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  640. i, row3, row2, row1, row0);
  641. rc++;
  642. } else {
  643. break;
  644. }
  645. }
  646. return rc;
  647. }
  648. void bnx2x_fw_dump_lvl(struct bnx2x *bp, const char *lvl)
  649. {
  650. u32 addr, val;
  651. u32 mark, offset;
  652. __be32 data[9];
  653. int word;
  654. u32 trace_shmem_base;
  655. if (BP_NOMCP(bp)) {
  656. BNX2X_ERR("NO MCP - can not dump\n");
  657. return;
  658. }
  659. netdev_printk(lvl, bp->dev, "bc %d.%d.%d\n",
  660. (bp->common.bc_ver & 0xff0000) >> 16,
  661. (bp->common.bc_ver & 0xff00) >> 8,
  662. (bp->common.bc_ver & 0xff));
  663. val = REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER);
  664. if (val == REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER))
  665. BNX2X_ERR("%s" "MCP PC at 0x%x\n", lvl, val);
  666. if (BP_PATH(bp) == 0)
  667. trace_shmem_base = bp->common.shmem_base;
  668. else
  669. trace_shmem_base = SHMEM2_RD(bp, other_shmem_base_addr);
  670. addr = trace_shmem_base - 0x800;
  671. /* validate TRCB signature */
  672. mark = REG_RD(bp, addr);
  673. if (mark != MFW_TRACE_SIGNATURE) {
  674. BNX2X_ERR("Trace buffer signature is missing.");
  675. return ;
  676. }
  677. /* read cyclic buffer pointer */
  678. addr += 4;
  679. mark = REG_RD(bp, addr);
  680. mark = (CHIP_IS_E1x(bp) ? MCP_REG_MCPR_SCRATCH : MCP_A_REG_MCPR_SCRATCH)
  681. + ((mark + 0x3) & ~0x3) - 0x08000000;
  682. printk("%s" "begin fw dump (mark 0x%x)\n", lvl, mark);
  683. printk("%s", lvl);
  684. /* dump buffer after the mark */
  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. /* dump buffer before the mark */
  692. for (offset = addr + 4; offset <= mark; offset += 0x8*4) {
  693. for (word = 0; word < 8; word++)
  694. data[word] = htonl(REG_RD(bp, offset + 4*word));
  695. data[8] = 0x0;
  696. pr_cont("%s", (char *)data);
  697. }
  698. printk("%s" "end of fw dump\n", lvl);
  699. }
  700. static void bnx2x_fw_dump(struct bnx2x *bp)
  701. {
  702. bnx2x_fw_dump_lvl(bp, KERN_ERR);
  703. }
  704. static void bnx2x_hc_int_disable(struct bnx2x *bp)
  705. {
  706. int port = BP_PORT(bp);
  707. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  708. u32 val = REG_RD(bp, addr);
  709. /* in E1 we must use only PCI configuration space to disable
  710. * MSI/MSIX capablility
  711. * It's forbitten to disable IGU_PF_CONF_MSI_MSIX_EN in HC block
  712. */
  713. if (CHIP_IS_E1(bp)) {
  714. /* Since IGU_PF_CONF_MSI_MSIX_EN still always on
  715. * Use mask register to prevent from HC sending interrupts
  716. * after we exit the function
  717. */
  718. REG_WR(bp, HC_REG_INT_MASK + port*4, 0);
  719. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  720. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  721. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  722. } else
  723. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  724. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  725. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  726. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  727. DP(NETIF_MSG_IFDOWN,
  728. "write %x to HC %d (addr 0x%x)\n",
  729. val, port, addr);
  730. /* flush all outstanding writes */
  731. mmiowb();
  732. REG_WR(bp, addr, val);
  733. if (REG_RD(bp, addr) != val)
  734. BNX2X_ERR("BUG! proper val not read from IGU!\n");
  735. }
  736. static void bnx2x_igu_int_disable(struct bnx2x *bp)
  737. {
  738. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  739. val &= ~(IGU_PF_CONF_MSI_MSIX_EN |
  740. IGU_PF_CONF_INT_LINE_EN |
  741. IGU_PF_CONF_ATTN_BIT_EN);
  742. DP(NETIF_MSG_IFDOWN, "write %x to IGU\n", val);
  743. /* flush all outstanding writes */
  744. mmiowb();
  745. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  746. if (REG_RD(bp, IGU_REG_PF_CONFIGURATION) != val)
  747. BNX2X_ERR("BUG! proper val not read from IGU!\n");
  748. }
  749. static void bnx2x_int_disable(struct bnx2x *bp)
  750. {
  751. if (bp->common.int_block == INT_BLOCK_HC)
  752. bnx2x_hc_int_disable(bp);
  753. else
  754. bnx2x_igu_int_disable(bp);
  755. }
  756. void bnx2x_panic_dump(struct bnx2x *bp, bool disable_int)
  757. {
  758. int i;
  759. u16 j;
  760. struct hc_sp_status_block_data sp_sb_data;
  761. int func = BP_FUNC(bp);
  762. #ifdef BNX2X_STOP_ON_ERROR
  763. u16 start = 0, end = 0;
  764. u8 cos;
  765. #endif
  766. if (disable_int)
  767. bnx2x_int_disable(bp);
  768. bp->stats_state = STATS_STATE_DISABLED;
  769. bp->eth_stats.unrecoverable_error++;
  770. DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n");
  771. BNX2X_ERR("begin crash dump -----------------\n");
  772. /* Indices */
  773. /* Common */
  774. 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",
  775. bp->def_idx, bp->def_att_idx, bp->attn_state,
  776. bp->spq_prod_idx, bp->stats_counter);
  777. BNX2X_ERR("DSB: attn bits(0x%x) ack(0x%x) id(0x%x) idx(0x%x)\n",
  778. bp->def_status_blk->atten_status_block.attn_bits,
  779. bp->def_status_blk->atten_status_block.attn_bits_ack,
  780. bp->def_status_blk->atten_status_block.status_block_id,
  781. bp->def_status_blk->atten_status_block.attn_bits_index);
  782. BNX2X_ERR(" def (");
  783. for (i = 0; i < HC_SP_SB_MAX_INDICES; i++)
  784. pr_cont("0x%x%s",
  785. bp->def_status_blk->sp_sb.index_values[i],
  786. (i == HC_SP_SB_MAX_INDICES - 1) ? ") " : " ");
  787. for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
  788. *((u32 *)&sp_sb_data + i) = REG_RD(bp, BAR_CSTRORM_INTMEM +
  789. CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
  790. i*sizeof(u32));
  791. 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",
  792. sp_sb_data.igu_sb_id,
  793. sp_sb_data.igu_seg_id,
  794. sp_sb_data.p_func.pf_id,
  795. sp_sb_data.p_func.vnic_id,
  796. sp_sb_data.p_func.vf_id,
  797. sp_sb_data.p_func.vf_valid,
  798. sp_sb_data.state);
  799. for_each_eth_queue(bp, i) {
  800. struct bnx2x_fastpath *fp = &bp->fp[i];
  801. int loop;
  802. struct hc_status_block_data_e2 sb_data_e2;
  803. struct hc_status_block_data_e1x sb_data_e1x;
  804. struct hc_status_block_sm *hc_sm_p =
  805. CHIP_IS_E1x(bp) ?
  806. sb_data_e1x.common.state_machine :
  807. sb_data_e2.common.state_machine;
  808. struct hc_index_data *hc_index_p =
  809. CHIP_IS_E1x(bp) ?
  810. sb_data_e1x.index_data :
  811. sb_data_e2.index_data;
  812. u8 data_size, cos;
  813. u32 *sb_data_p;
  814. struct bnx2x_fp_txdata txdata;
  815. /* Rx */
  816. 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",
  817. i, fp->rx_bd_prod, fp->rx_bd_cons,
  818. fp->rx_comp_prod,
  819. fp->rx_comp_cons, le16_to_cpu(*fp->rx_cons_sb));
  820. BNX2X_ERR(" rx_sge_prod(0x%x) last_max_sge(0x%x) fp_hc_idx(0x%x)\n",
  821. fp->rx_sge_prod, fp->last_max_sge,
  822. le16_to_cpu(fp->fp_hc_idx));
  823. /* Tx */
  824. for_each_cos_in_tx_queue(fp, cos)
  825. {
  826. txdata = *fp->txdata_ptr[cos];
  827. 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",
  828. i, txdata.tx_pkt_prod,
  829. txdata.tx_pkt_cons, txdata.tx_bd_prod,
  830. txdata.tx_bd_cons,
  831. le16_to_cpu(*txdata.tx_cons_sb));
  832. }
  833. loop = CHIP_IS_E1x(bp) ?
  834. HC_SB_MAX_INDICES_E1X : HC_SB_MAX_INDICES_E2;
  835. /* host sb data */
  836. if (IS_FCOE_FP(fp))
  837. continue;
  838. BNX2X_ERR(" run indexes (");
  839. for (j = 0; j < HC_SB_MAX_SM; j++)
  840. pr_cont("0x%x%s",
  841. fp->sb_running_index[j],
  842. (j == HC_SB_MAX_SM - 1) ? ")" : " ");
  843. BNX2X_ERR(" indexes (");
  844. for (j = 0; j < loop; j++)
  845. pr_cont("0x%x%s",
  846. fp->sb_index_values[j],
  847. (j == loop - 1) ? ")" : " ");
  848. /* fw sb data */
  849. data_size = CHIP_IS_E1x(bp) ?
  850. sizeof(struct hc_status_block_data_e1x) :
  851. sizeof(struct hc_status_block_data_e2);
  852. data_size /= sizeof(u32);
  853. sb_data_p = CHIP_IS_E1x(bp) ?
  854. (u32 *)&sb_data_e1x :
  855. (u32 *)&sb_data_e2;
  856. /* copy sb data in here */
  857. for (j = 0; j < data_size; j++)
  858. *(sb_data_p + j) = REG_RD(bp, BAR_CSTRORM_INTMEM +
  859. CSTORM_STATUS_BLOCK_DATA_OFFSET(fp->fw_sb_id) +
  860. j * sizeof(u32));
  861. if (!CHIP_IS_E1x(bp)) {
  862. 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",
  863. sb_data_e2.common.p_func.pf_id,
  864. sb_data_e2.common.p_func.vf_id,
  865. sb_data_e2.common.p_func.vf_valid,
  866. sb_data_e2.common.p_func.vnic_id,
  867. sb_data_e2.common.same_igu_sb_1b,
  868. sb_data_e2.common.state);
  869. } else {
  870. 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",
  871. sb_data_e1x.common.p_func.pf_id,
  872. sb_data_e1x.common.p_func.vf_id,
  873. sb_data_e1x.common.p_func.vf_valid,
  874. sb_data_e1x.common.p_func.vnic_id,
  875. sb_data_e1x.common.same_igu_sb_1b,
  876. sb_data_e1x.common.state);
  877. }
  878. /* SB_SMs data */
  879. for (j = 0; j < HC_SB_MAX_SM; j++) {
  880. 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",
  881. j, hc_sm_p[j].__flags,
  882. hc_sm_p[j].igu_sb_id,
  883. hc_sm_p[j].igu_seg_id,
  884. hc_sm_p[j].time_to_expire,
  885. hc_sm_p[j].timer_value);
  886. }
  887. /* Indecies data */
  888. for (j = 0; j < loop; j++) {
  889. pr_cont("INDEX[%d] flags (0x%x) timeout (0x%x)\n", j,
  890. hc_index_p[j].flags,
  891. hc_index_p[j].timeout);
  892. }
  893. }
  894. #ifdef BNX2X_STOP_ON_ERROR
  895. /* event queue */
  896. for (i = 0; i < NUM_EQ_DESC; i++) {
  897. u32 *data = (u32 *)&bp->eq_ring[i].message.data;
  898. BNX2X_ERR("event queue [%d]: header: opcode %d, error %d\n",
  899. i, bp->eq_ring[i].message.opcode,
  900. bp->eq_ring[i].message.error);
  901. BNX2X_ERR("data: %x %x %x\n", data[0], data[1], data[2]);
  902. }
  903. /* Rings */
  904. /* Rx */
  905. for_each_valid_rx_queue(bp, i) {
  906. struct bnx2x_fastpath *fp = &bp->fp[i];
  907. start = RX_BD(le16_to_cpu(*fp->rx_cons_sb) - 10);
  908. end = RX_BD(le16_to_cpu(*fp->rx_cons_sb) + 503);
  909. for (j = start; j != end; j = RX_BD(j + 1)) {
  910. u32 *rx_bd = (u32 *)&fp->rx_desc_ring[j];
  911. struct sw_rx_bd *sw_bd = &fp->rx_buf_ring[j];
  912. BNX2X_ERR("fp%d: rx_bd[%x]=[%x:%x] sw_bd=[%p]\n",
  913. i, j, rx_bd[1], rx_bd[0], sw_bd->data);
  914. }
  915. start = RX_SGE(fp->rx_sge_prod);
  916. end = RX_SGE(fp->last_max_sge);
  917. for (j = start; j != end; j = RX_SGE(j + 1)) {
  918. u32 *rx_sge = (u32 *)&fp->rx_sge_ring[j];
  919. struct sw_rx_page *sw_page = &fp->rx_page_ring[j];
  920. BNX2X_ERR("fp%d: rx_sge[%x]=[%x:%x] sw_page=[%p]\n",
  921. i, j, rx_sge[1], rx_sge[0], sw_page->page);
  922. }
  923. start = RCQ_BD(fp->rx_comp_cons - 10);
  924. end = RCQ_BD(fp->rx_comp_cons + 503);
  925. for (j = start; j != end; j = RCQ_BD(j + 1)) {
  926. u32 *cqe = (u32 *)&fp->rx_comp_ring[j];
  927. BNX2X_ERR("fp%d: cqe[%x]=[%x:%x:%x:%x]\n",
  928. i, j, cqe[0], cqe[1], cqe[2], cqe[3]);
  929. }
  930. }
  931. /* Tx */
  932. for_each_valid_tx_queue(bp, i) {
  933. struct bnx2x_fastpath *fp = &bp->fp[i];
  934. for_each_cos_in_tx_queue(fp, cos) {
  935. struct bnx2x_fp_txdata *txdata = fp->txdata_ptr[cos];
  936. start = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) - 10);
  937. end = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) + 245);
  938. for (j = start; j != end; j = TX_BD(j + 1)) {
  939. struct sw_tx_bd *sw_bd =
  940. &txdata->tx_buf_ring[j];
  941. BNX2X_ERR("fp%d: txdata %d, packet[%x]=[%p,%x]\n",
  942. i, cos, j, sw_bd->skb,
  943. sw_bd->first_bd);
  944. }
  945. start = TX_BD(txdata->tx_bd_cons - 10);
  946. end = TX_BD(txdata->tx_bd_cons + 254);
  947. for (j = start; j != end; j = TX_BD(j + 1)) {
  948. u32 *tx_bd = (u32 *)&txdata->tx_desc_ring[j];
  949. BNX2X_ERR("fp%d: txdata %d, tx_bd[%x]=[%x:%x:%x:%x]\n",
  950. i, cos, j, tx_bd[0], tx_bd[1],
  951. tx_bd[2], tx_bd[3]);
  952. }
  953. }
  954. }
  955. #endif
  956. bnx2x_fw_dump(bp);
  957. bnx2x_mc_assert(bp);
  958. BNX2X_ERR("end crash dump -----------------\n");
  959. }
  960. /*
  961. * FLR Support for E2
  962. *
  963. * bnx2x_pf_flr_clnup() is called during nic_load in the per function HW
  964. * initialization.
  965. */
  966. #define FLR_WAIT_USEC 10000 /* 10 miliseconds */
  967. #define FLR_WAIT_INTERVAL 50 /* usec */
  968. #define FLR_POLL_CNT (FLR_WAIT_USEC/FLR_WAIT_INTERVAL) /* 200 */
  969. struct pbf_pN_buf_regs {
  970. int pN;
  971. u32 init_crd;
  972. u32 crd;
  973. u32 crd_freed;
  974. };
  975. struct pbf_pN_cmd_regs {
  976. int pN;
  977. u32 lines_occup;
  978. u32 lines_freed;
  979. };
  980. static void bnx2x_pbf_pN_buf_flushed(struct bnx2x *bp,
  981. struct pbf_pN_buf_regs *regs,
  982. u32 poll_count)
  983. {
  984. u32 init_crd, crd, crd_start, crd_freed, crd_freed_start;
  985. u32 cur_cnt = poll_count;
  986. crd_freed = crd_freed_start = REG_RD(bp, regs->crd_freed);
  987. crd = crd_start = REG_RD(bp, regs->crd);
  988. init_crd = REG_RD(bp, regs->init_crd);
  989. DP(BNX2X_MSG_SP, "INIT CREDIT[%d] : %x\n", regs->pN, init_crd);
  990. DP(BNX2X_MSG_SP, "CREDIT[%d] : s:%x\n", regs->pN, crd);
  991. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: s:%x\n", regs->pN, crd_freed);
  992. while ((crd != init_crd) && ((u32)SUB_S32(crd_freed, crd_freed_start) <
  993. (init_crd - crd_start))) {
  994. if (cur_cnt--) {
  995. udelay(FLR_WAIT_INTERVAL);
  996. crd = REG_RD(bp, regs->crd);
  997. crd_freed = REG_RD(bp, regs->crd_freed);
  998. } else {
  999. DP(BNX2X_MSG_SP, "PBF tx buffer[%d] timed out\n",
  1000. regs->pN);
  1001. DP(BNX2X_MSG_SP, "CREDIT[%d] : c:%x\n",
  1002. regs->pN, crd);
  1003. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: c:%x\n",
  1004. regs->pN, crd_freed);
  1005. break;
  1006. }
  1007. }
  1008. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF tx buffer[%d]\n",
  1009. poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
  1010. }
  1011. static void bnx2x_pbf_pN_cmd_flushed(struct bnx2x *bp,
  1012. struct pbf_pN_cmd_regs *regs,
  1013. u32 poll_count)
  1014. {
  1015. u32 occup, to_free, freed, freed_start;
  1016. u32 cur_cnt = poll_count;
  1017. occup = to_free = REG_RD(bp, regs->lines_occup);
  1018. freed = freed_start = REG_RD(bp, regs->lines_freed);
  1019. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n", regs->pN, occup);
  1020. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n", regs->pN, freed);
  1021. while (occup && ((u32)SUB_S32(freed, freed_start) < to_free)) {
  1022. if (cur_cnt--) {
  1023. udelay(FLR_WAIT_INTERVAL);
  1024. occup = REG_RD(bp, regs->lines_occup);
  1025. freed = REG_RD(bp, regs->lines_freed);
  1026. } else {
  1027. DP(BNX2X_MSG_SP, "PBF cmd queue[%d] timed out\n",
  1028. regs->pN);
  1029. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n",
  1030. regs->pN, occup);
  1031. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n",
  1032. regs->pN, freed);
  1033. break;
  1034. }
  1035. }
  1036. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF cmd queue[%d]\n",
  1037. poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
  1038. }
  1039. static u32 bnx2x_flr_clnup_reg_poll(struct bnx2x *bp, u32 reg,
  1040. u32 expected, u32 poll_count)
  1041. {
  1042. u32 cur_cnt = poll_count;
  1043. u32 val;
  1044. while ((val = REG_RD(bp, reg)) != expected && cur_cnt--)
  1045. udelay(FLR_WAIT_INTERVAL);
  1046. return val;
  1047. }
  1048. int bnx2x_flr_clnup_poll_hw_counter(struct bnx2x *bp, u32 reg,
  1049. char *msg, u32 poll_cnt)
  1050. {
  1051. u32 val = bnx2x_flr_clnup_reg_poll(bp, reg, 0, poll_cnt);
  1052. if (val != 0) {
  1053. BNX2X_ERR("%s usage count=%d\n", msg, val);
  1054. return 1;
  1055. }
  1056. return 0;
  1057. }
  1058. /* Common routines with VF FLR cleanup */
  1059. u32 bnx2x_flr_clnup_poll_count(struct bnx2x *bp)
  1060. {
  1061. /* adjust polling timeout */
  1062. if (CHIP_REV_IS_EMUL(bp))
  1063. return FLR_POLL_CNT * 2000;
  1064. if (CHIP_REV_IS_FPGA(bp))
  1065. return FLR_POLL_CNT * 120;
  1066. return FLR_POLL_CNT;
  1067. }
  1068. void bnx2x_tx_hw_flushed(struct bnx2x *bp, u32 poll_count)
  1069. {
  1070. struct pbf_pN_cmd_regs cmd_regs[] = {
  1071. {0, (CHIP_IS_E3B0(bp)) ?
  1072. PBF_REG_TQ_OCCUPANCY_Q0 :
  1073. PBF_REG_P0_TQ_OCCUPANCY,
  1074. (CHIP_IS_E3B0(bp)) ?
  1075. PBF_REG_TQ_LINES_FREED_CNT_Q0 :
  1076. PBF_REG_P0_TQ_LINES_FREED_CNT},
  1077. {1, (CHIP_IS_E3B0(bp)) ?
  1078. PBF_REG_TQ_OCCUPANCY_Q1 :
  1079. PBF_REG_P1_TQ_OCCUPANCY,
  1080. (CHIP_IS_E3B0(bp)) ?
  1081. PBF_REG_TQ_LINES_FREED_CNT_Q1 :
  1082. PBF_REG_P1_TQ_LINES_FREED_CNT},
  1083. {4, (CHIP_IS_E3B0(bp)) ?
  1084. PBF_REG_TQ_OCCUPANCY_LB_Q :
  1085. PBF_REG_P4_TQ_OCCUPANCY,
  1086. (CHIP_IS_E3B0(bp)) ?
  1087. PBF_REG_TQ_LINES_FREED_CNT_LB_Q :
  1088. PBF_REG_P4_TQ_LINES_FREED_CNT}
  1089. };
  1090. struct pbf_pN_buf_regs buf_regs[] = {
  1091. {0, (CHIP_IS_E3B0(bp)) ?
  1092. PBF_REG_INIT_CRD_Q0 :
  1093. PBF_REG_P0_INIT_CRD ,
  1094. (CHIP_IS_E3B0(bp)) ?
  1095. PBF_REG_CREDIT_Q0 :
  1096. PBF_REG_P0_CREDIT,
  1097. (CHIP_IS_E3B0(bp)) ?
  1098. PBF_REG_INTERNAL_CRD_FREED_CNT_Q0 :
  1099. PBF_REG_P0_INTERNAL_CRD_FREED_CNT},
  1100. {1, (CHIP_IS_E3B0(bp)) ?
  1101. PBF_REG_INIT_CRD_Q1 :
  1102. PBF_REG_P1_INIT_CRD,
  1103. (CHIP_IS_E3B0(bp)) ?
  1104. PBF_REG_CREDIT_Q1 :
  1105. PBF_REG_P1_CREDIT,
  1106. (CHIP_IS_E3B0(bp)) ?
  1107. PBF_REG_INTERNAL_CRD_FREED_CNT_Q1 :
  1108. PBF_REG_P1_INTERNAL_CRD_FREED_CNT},
  1109. {4, (CHIP_IS_E3B0(bp)) ?
  1110. PBF_REG_INIT_CRD_LB_Q :
  1111. PBF_REG_P4_INIT_CRD,
  1112. (CHIP_IS_E3B0(bp)) ?
  1113. PBF_REG_CREDIT_LB_Q :
  1114. PBF_REG_P4_CREDIT,
  1115. (CHIP_IS_E3B0(bp)) ?
  1116. PBF_REG_INTERNAL_CRD_FREED_CNT_LB_Q :
  1117. PBF_REG_P4_INTERNAL_CRD_FREED_CNT},
  1118. };
  1119. int i;
  1120. /* Verify the command queues are flushed P0, P1, P4 */
  1121. for (i = 0; i < ARRAY_SIZE(cmd_regs); i++)
  1122. bnx2x_pbf_pN_cmd_flushed(bp, &cmd_regs[i], poll_count);
  1123. /* Verify the transmission buffers are flushed P0, P1, P4 */
  1124. for (i = 0; i < ARRAY_SIZE(buf_regs); i++)
  1125. bnx2x_pbf_pN_buf_flushed(bp, &buf_regs[i], poll_count);
  1126. }
  1127. #define OP_GEN_PARAM(param) \
  1128. (((param) << SDM_OP_GEN_COMP_PARAM_SHIFT) & SDM_OP_GEN_COMP_PARAM)
  1129. #define OP_GEN_TYPE(type) \
  1130. (((type) << SDM_OP_GEN_COMP_TYPE_SHIFT) & SDM_OP_GEN_COMP_TYPE)
  1131. #define OP_GEN_AGG_VECT(index) \
  1132. (((index) << SDM_OP_GEN_AGG_VECT_IDX_SHIFT) & SDM_OP_GEN_AGG_VECT_IDX)
  1133. int bnx2x_send_final_clnup(struct bnx2x *bp, u8 clnup_func, u32 poll_cnt)
  1134. {
  1135. u32 op_gen_command = 0;
  1136. u32 comp_addr = BAR_CSTRORM_INTMEM +
  1137. CSTORM_FINAL_CLEANUP_COMPLETE_OFFSET(clnup_func);
  1138. int ret = 0;
  1139. if (REG_RD(bp, comp_addr)) {
  1140. BNX2X_ERR("Cleanup complete was not 0 before sending\n");
  1141. return 1;
  1142. }
  1143. op_gen_command |= OP_GEN_PARAM(XSTORM_AGG_INT_FINAL_CLEANUP_INDEX);
  1144. op_gen_command |= OP_GEN_TYPE(XSTORM_AGG_INT_FINAL_CLEANUP_COMP_TYPE);
  1145. op_gen_command |= OP_GEN_AGG_VECT(clnup_func);
  1146. op_gen_command |= 1 << SDM_OP_GEN_AGG_VECT_IDX_VALID_SHIFT;
  1147. DP(BNX2X_MSG_SP, "sending FW Final cleanup\n");
  1148. REG_WR(bp, XSDM_REG_OPERATION_GEN, op_gen_command);
  1149. if (bnx2x_flr_clnup_reg_poll(bp, comp_addr, 1, poll_cnt) != 1) {
  1150. BNX2X_ERR("FW final cleanup did not succeed\n");
  1151. DP(BNX2X_MSG_SP, "At timeout completion address contained %x\n",
  1152. (REG_RD(bp, comp_addr)));
  1153. bnx2x_panic();
  1154. return 1;
  1155. }
  1156. /* Zero completion for nxt FLR */
  1157. REG_WR(bp, comp_addr, 0);
  1158. return ret;
  1159. }
  1160. u8 bnx2x_is_pcie_pending(struct pci_dev *dev)
  1161. {
  1162. u16 status;
  1163. pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status);
  1164. return status & PCI_EXP_DEVSTA_TRPND;
  1165. }
  1166. /* PF FLR specific routines
  1167. */
  1168. static int bnx2x_poll_hw_usage_counters(struct bnx2x *bp, u32 poll_cnt)
  1169. {
  1170. /* wait for CFC PF usage-counter to zero (includes all the VFs) */
  1171. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1172. CFC_REG_NUM_LCIDS_INSIDE_PF,
  1173. "CFC PF usage counter timed out",
  1174. poll_cnt))
  1175. return 1;
  1176. /* Wait for DQ PF usage-counter to zero (until DQ cleanup) */
  1177. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1178. DORQ_REG_PF_USAGE_CNT,
  1179. "DQ PF usage counter timed out",
  1180. poll_cnt))
  1181. return 1;
  1182. /* Wait for QM PF usage-counter to zero (until DQ cleanup) */
  1183. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1184. QM_REG_PF_USG_CNT_0 + 4*BP_FUNC(bp),
  1185. "QM PF usage counter timed out",
  1186. poll_cnt))
  1187. return 1;
  1188. /* Wait for Timer PF usage-counters to zero (until DQ cleanup) */
  1189. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1190. TM_REG_LIN0_VNIC_UC + 4*BP_PORT(bp),
  1191. "Timers VNIC usage counter timed out",
  1192. poll_cnt))
  1193. return 1;
  1194. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1195. TM_REG_LIN0_NUM_SCANS + 4*BP_PORT(bp),
  1196. "Timers NUM_SCANS usage counter timed out",
  1197. poll_cnt))
  1198. return 1;
  1199. /* Wait DMAE PF usage counter to zero */
  1200. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1201. dmae_reg_go_c[INIT_DMAE_C(bp)],
  1202. "DMAE dommand register timed out",
  1203. poll_cnt))
  1204. return 1;
  1205. return 0;
  1206. }
  1207. static void bnx2x_hw_enable_status(struct bnx2x *bp)
  1208. {
  1209. u32 val;
  1210. val = REG_RD(bp, CFC_REG_WEAK_ENABLE_PF);
  1211. DP(BNX2X_MSG_SP, "CFC_REG_WEAK_ENABLE_PF is 0x%x\n", val);
  1212. val = REG_RD(bp, PBF_REG_DISABLE_PF);
  1213. DP(BNX2X_MSG_SP, "PBF_REG_DISABLE_PF is 0x%x\n", val);
  1214. val = REG_RD(bp, IGU_REG_PCI_PF_MSI_EN);
  1215. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSI_EN is 0x%x\n", val);
  1216. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_EN);
  1217. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_EN is 0x%x\n", val);
  1218. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_FUNC_MASK);
  1219. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_FUNC_MASK is 0x%x\n", val);
  1220. val = REG_RD(bp, PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR);
  1221. DP(BNX2X_MSG_SP, "PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR is 0x%x\n", val);
  1222. val = REG_RD(bp, PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR);
  1223. DP(BNX2X_MSG_SP, "PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR is 0x%x\n", val);
  1224. val = REG_RD(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
  1225. DP(BNX2X_MSG_SP, "PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER is 0x%x\n",
  1226. val);
  1227. }
  1228. static int bnx2x_pf_flr_clnup(struct bnx2x *bp)
  1229. {
  1230. u32 poll_cnt = bnx2x_flr_clnup_poll_count(bp);
  1231. DP(BNX2X_MSG_SP, "Cleanup after FLR PF[%d]\n", BP_ABS_FUNC(bp));
  1232. /* Re-enable PF target read access */
  1233. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  1234. /* Poll HW usage counters */
  1235. DP(BNX2X_MSG_SP, "Polling usage counters\n");
  1236. if (bnx2x_poll_hw_usage_counters(bp, poll_cnt))
  1237. return -EBUSY;
  1238. /* Zero the igu 'trailing edge' and 'leading edge' */
  1239. /* Send the FW cleanup command */
  1240. if (bnx2x_send_final_clnup(bp, (u8)BP_FUNC(bp), poll_cnt))
  1241. return -EBUSY;
  1242. /* ATC cleanup */
  1243. /* Verify TX hw is flushed */
  1244. bnx2x_tx_hw_flushed(bp, poll_cnt);
  1245. /* Wait 100ms (not adjusted according to platform) */
  1246. msleep(100);
  1247. /* Verify no pending pci transactions */
  1248. if (bnx2x_is_pcie_pending(bp->pdev))
  1249. BNX2X_ERR("PCIE Transactions still pending\n");
  1250. /* Debug */
  1251. bnx2x_hw_enable_status(bp);
  1252. /*
  1253. * Master enable - Due to WB DMAE writes performed before this
  1254. * register is re-initialized as part of the regular function init
  1255. */
  1256. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  1257. return 0;
  1258. }
  1259. static void bnx2x_hc_int_enable(struct bnx2x *bp)
  1260. {
  1261. int port = BP_PORT(bp);
  1262. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  1263. u32 val = REG_RD(bp, addr);
  1264. bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
  1265. bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
  1266. bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
  1267. if (msix) {
  1268. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1269. HC_CONFIG_0_REG_INT_LINE_EN_0);
  1270. val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1271. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1272. if (single_msix)
  1273. val |= HC_CONFIG_0_REG_SINGLE_ISR_EN_0;
  1274. } else if (msi) {
  1275. val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0;
  1276. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1277. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1278. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1279. } else {
  1280. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1281. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1282. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  1283. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1284. if (!CHIP_IS_E1(bp)) {
  1285. DP(NETIF_MSG_IFUP,
  1286. "write %x to HC %d (addr 0x%x)\n", val, port, addr);
  1287. REG_WR(bp, addr, val);
  1288. val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0;
  1289. }
  1290. }
  1291. if (CHIP_IS_E1(bp))
  1292. REG_WR(bp, HC_REG_INT_MASK + port*4, 0x1FFFF);
  1293. DP(NETIF_MSG_IFUP,
  1294. "write %x to HC %d (addr 0x%x) mode %s\n", val, port, addr,
  1295. (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1296. REG_WR(bp, addr, val);
  1297. /*
  1298. * Ensure that HC_CONFIG is written before leading/trailing edge config
  1299. */
  1300. mmiowb();
  1301. barrier();
  1302. if (!CHIP_IS_E1(bp)) {
  1303. /* init leading/trailing edge */
  1304. if (IS_MF(bp)) {
  1305. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1306. if (bp->port.pmf)
  1307. /* enable nig and gpio3 attention */
  1308. val |= 0x1100;
  1309. } else
  1310. val = 0xffff;
  1311. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  1312. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  1313. }
  1314. /* Make sure that interrupts are indeed enabled from here on */
  1315. mmiowb();
  1316. }
  1317. static void bnx2x_igu_int_enable(struct bnx2x *bp)
  1318. {
  1319. u32 val;
  1320. bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
  1321. bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
  1322. bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
  1323. val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  1324. if (msix) {
  1325. val &= ~(IGU_PF_CONF_INT_LINE_EN |
  1326. IGU_PF_CONF_SINGLE_ISR_EN);
  1327. val |= (IGU_PF_CONF_MSI_MSIX_EN |
  1328. IGU_PF_CONF_ATTN_BIT_EN);
  1329. if (single_msix)
  1330. val |= IGU_PF_CONF_SINGLE_ISR_EN;
  1331. } else if (msi) {
  1332. val &= ~IGU_PF_CONF_INT_LINE_EN;
  1333. val |= (IGU_PF_CONF_MSI_MSIX_EN |
  1334. IGU_PF_CONF_ATTN_BIT_EN |
  1335. IGU_PF_CONF_SINGLE_ISR_EN);
  1336. } else {
  1337. val &= ~IGU_PF_CONF_MSI_MSIX_EN;
  1338. val |= (IGU_PF_CONF_INT_LINE_EN |
  1339. IGU_PF_CONF_ATTN_BIT_EN |
  1340. IGU_PF_CONF_SINGLE_ISR_EN);
  1341. }
  1342. /* Clean previous status - need to configure igu prior to ack*/
  1343. if ((!msix) || single_msix) {
  1344. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1345. bnx2x_ack_int(bp);
  1346. }
  1347. val |= IGU_PF_CONF_FUNC_EN;
  1348. DP(NETIF_MSG_IFUP, "write 0x%x to IGU mode %s\n",
  1349. val, (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1350. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1351. if (val & IGU_PF_CONF_INT_LINE_EN)
  1352. pci_intx(bp->pdev, true);
  1353. barrier();
  1354. /* init leading/trailing edge */
  1355. if (IS_MF(bp)) {
  1356. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1357. if (bp->port.pmf)
  1358. /* enable nig and gpio3 attention */
  1359. val |= 0x1100;
  1360. } else
  1361. val = 0xffff;
  1362. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  1363. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  1364. /* Make sure that interrupts are indeed enabled from here on */
  1365. mmiowb();
  1366. }
  1367. void bnx2x_int_enable(struct bnx2x *bp)
  1368. {
  1369. if (bp->common.int_block == INT_BLOCK_HC)
  1370. bnx2x_hc_int_enable(bp);
  1371. else
  1372. bnx2x_igu_int_enable(bp);
  1373. }
  1374. void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw)
  1375. {
  1376. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  1377. int i, offset;
  1378. if (disable_hw)
  1379. /* prevent the HW from sending interrupts */
  1380. bnx2x_int_disable(bp);
  1381. /* make sure all ISRs are done */
  1382. if (msix) {
  1383. synchronize_irq(bp->msix_table[0].vector);
  1384. offset = 1;
  1385. if (CNIC_SUPPORT(bp))
  1386. offset++;
  1387. for_each_eth_queue(bp, i)
  1388. synchronize_irq(bp->msix_table[offset++].vector);
  1389. } else
  1390. synchronize_irq(bp->pdev->irq);
  1391. /* make sure sp_task is not running */
  1392. cancel_delayed_work(&bp->sp_task);
  1393. cancel_delayed_work(&bp->period_task);
  1394. flush_workqueue(bnx2x_wq);
  1395. }
  1396. /* fast path */
  1397. /*
  1398. * General service functions
  1399. */
  1400. /* Return true if succeeded to acquire the lock */
  1401. static bool bnx2x_trylock_hw_lock(struct bnx2x *bp, u32 resource)
  1402. {
  1403. u32 lock_status;
  1404. u32 resource_bit = (1 << resource);
  1405. int func = BP_FUNC(bp);
  1406. u32 hw_lock_control_reg;
  1407. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1408. "Trying to take a lock on resource %d\n", resource);
  1409. /* Validating that the resource is within range */
  1410. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1411. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1412. "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1413. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1414. return false;
  1415. }
  1416. if (func <= 5)
  1417. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1418. else
  1419. hw_lock_control_reg =
  1420. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1421. /* Try to acquire the lock */
  1422. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1423. lock_status = REG_RD(bp, hw_lock_control_reg);
  1424. if (lock_status & resource_bit)
  1425. return true;
  1426. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1427. "Failed to get a lock on resource %d\n", resource);
  1428. return false;
  1429. }
  1430. /**
  1431. * bnx2x_get_leader_lock_resource - get the recovery leader resource id
  1432. *
  1433. * @bp: driver handle
  1434. *
  1435. * Returns the recovery leader resource id according to the engine this function
  1436. * belongs to. Currently only only 2 engines is supported.
  1437. */
  1438. static int bnx2x_get_leader_lock_resource(struct bnx2x *bp)
  1439. {
  1440. if (BP_PATH(bp))
  1441. return HW_LOCK_RESOURCE_RECOVERY_LEADER_1;
  1442. else
  1443. return HW_LOCK_RESOURCE_RECOVERY_LEADER_0;
  1444. }
  1445. /**
  1446. * bnx2x_trylock_leader_lock- try to acquire a leader lock.
  1447. *
  1448. * @bp: driver handle
  1449. *
  1450. * Tries to acquire a leader lock for current engine.
  1451. */
  1452. static bool bnx2x_trylock_leader_lock(struct bnx2x *bp)
  1453. {
  1454. return bnx2x_trylock_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1455. }
  1456. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err);
  1457. /* schedule the sp task and mark that interrupt occurred (runs from ISR) */
  1458. static int bnx2x_schedule_sp_task(struct bnx2x *bp)
  1459. {
  1460. /* Set the interrupt occurred bit for the sp-task to recognize it
  1461. * must ack the interrupt and transition according to the IGU
  1462. * state machine.
  1463. */
  1464. atomic_set(&bp->interrupt_occurred, 1);
  1465. /* The sp_task must execute only after this bit
  1466. * is set, otherwise we will get out of sync and miss all
  1467. * further interrupts. Hence, the barrier.
  1468. */
  1469. smp_wmb();
  1470. /* schedule sp_task to workqueue */
  1471. return queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
  1472. }
  1473. void bnx2x_sp_event(struct bnx2x_fastpath *fp, union eth_rx_cqe *rr_cqe)
  1474. {
  1475. struct bnx2x *bp = fp->bp;
  1476. int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1477. int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1478. enum bnx2x_queue_cmd drv_cmd = BNX2X_Q_CMD_MAX;
  1479. struct bnx2x_queue_sp_obj *q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  1480. DP(BNX2X_MSG_SP,
  1481. "fp %d cid %d got ramrod #%d state is %x type is %d\n",
  1482. fp->index, cid, command, bp->state,
  1483. rr_cqe->ramrod_cqe.ramrod_type);
  1484. /* If cid is within VF range, replace the slowpath object with the
  1485. * one corresponding to this VF
  1486. */
  1487. if (cid >= BNX2X_FIRST_VF_CID &&
  1488. cid < BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)
  1489. bnx2x_iov_set_queue_sp_obj(bp, cid, &q_obj);
  1490. switch (command) {
  1491. case (RAMROD_CMD_ID_ETH_CLIENT_UPDATE):
  1492. DP(BNX2X_MSG_SP, "got UPDATE ramrod. CID %d\n", cid);
  1493. drv_cmd = BNX2X_Q_CMD_UPDATE;
  1494. break;
  1495. case (RAMROD_CMD_ID_ETH_CLIENT_SETUP):
  1496. DP(BNX2X_MSG_SP, "got MULTI[%d] setup ramrod\n", cid);
  1497. drv_cmd = BNX2X_Q_CMD_SETUP;
  1498. break;
  1499. case (RAMROD_CMD_ID_ETH_TX_QUEUE_SETUP):
  1500. DP(BNX2X_MSG_SP, "got MULTI[%d] tx-only setup ramrod\n", cid);
  1501. drv_cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  1502. break;
  1503. case (RAMROD_CMD_ID_ETH_HALT):
  1504. DP(BNX2X_MSG_SP, "got MULTI[%d] halt ramrod\n", cid);
  1505. drv_cmd = BNX2X_Q_CMD_HALT;
  1506. break;
  1507. case (RAMROD_CMD_ID_ETH_TERMINATE):
  1508. DP(BNX2X_MSG_SP, "got MULTI[%d] teminate ramrod\n", cid);
  1509. drv_cmd = BNX2X_Q_CMD_TERMINATE;
  1510. break;
  1511. case (RAMROD_CMD_ID_ETH_EMPTY):
  1512. DP(BNX2X_MSG_SP, "got MULTI[%d] empty ramrod\n", cid);
  1513. drv_cmd = BNX2X_Q_CMD_EMPTY;
  1514. break;
  1515. default:
  1516. BNX2X_ERR("unexpected MC reply (%d) on fp[%d]\n",
  1517. command, fp->index);
  1518. return;
  1519. }
  1520. if ((drv_cmd != BNX2X_Q_CMD_MAX) &&
  1521. q_obj->complete_cmd(bp, q_obj, drv_cmd))
  1522. /* q_obj->complete_cmd() failure means that this was
  1523. * an unexpected completion.
  1524. *
  1525. * In this case we don't want to increase the bp->spq_left
  1526. * because apparently we haven't sent this command the first
  1527. * place.
  1528. */
  1529. #ifdef BNX2X_STOP_ON_ERROR
  1530. bnx2x_panic();
  1531. #else
  1532. return;
  1533. #endif
  1534. /* SRIOV: reschedule any 'in_progress' operations */
  1535. bnx2x_iov_sp_event(bp, cid, true);
  1536. smp_mb__before_atomic_inc();
  1537. atomic_inc(&bp->cq_spq_left);
  1538. /* push the change in bp->spq_left and towards the memory */
  1539. smp_mb__after_atomic_inc();
  1540. DP(BNX2X_MSG_SP, "bp->cq_spq_left %x\n", atomic_read(&bp->cq_spq_left));
  1541. if ((drv_cmd == BNX2X_Q_CMD_UPDATE) && (IS_FCOE_FP(fp)) &&
  1542. (!!test_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state))) {
  1543. /* if Q update ramrod is completed for last Q in AFEX vif set
  1544. * flow, then ACK MCP at the end
  1545. *
  1546. * mark pending ACK to MCP bit.
  1547. * prevent case that both bits are cleared.
  1548. * At the end of load/unload driver checks that
  1549. * sp_state is cleared, and this order prevents
  1550. * races
  1551. */
  1552. smp_mb__before_clear_bit();
  1553. set_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK, &bp->sp_state);
  1554. wmb();
  1555. clear_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
  1556. smp_mb__after_clear_bit();
  1557. /* schedule the sp task as mcp ack is required */
  1558. bnx2x_schedule_sp_task(bp);
  1559. }
  1560. return;
  1561. }
  1562. irqreturn_t bnx2x_interrupt(int irq, void *dev_instance)
  1563. {
  1564. struct bnx2x *bp = netdev_priv(dev_instance);
  1565. u16 status = bnx2x_ack_int(bp);
  1566. u16 mask;
  1567. int i;
  1568. u8 cos;
  1569. /* Return here if interrupt is shared and it's not for us */
  1570. if (unlikely(status == 0)) {
  1571. DP(NETIF_MSG_INTR, "not our interrupt!\n");
  1572. return IRQ_NONE;
  1573. }
  1574. DP(NETIF_MSG_INTR, "got an interrupt status 0x%x\n", status);
  1575. #ifdef BNX2X_STOP_ON_ERROR
  1576. if (unlikely(bp->panic))
  1577. return IRQ_HANDLED;
  1578. #endif
  1579. for_each_eth_queue(bp, i) {
  1580. struct bnx2x_fastpath *fp = &bp->fp[i];
  1581. mask = 0x2 << (fp->index + CNIC_SUPPORT(bp));
  1582. if (status & mask) {
  1583. /* Handle Rx or Tx according to SB id */
  1584. prefetch(fp->rx_cons_sb);
  1585. for_each_cos_in_tx_queue(fp, cos)
  1586. prefetch(fp->txdata_ptr[cos]->tx_cons_sb);
  1587. prefetch(&fp->sb_running_index[SM_RX_ID]);
  1588. napi_schedule(&bnx2x_fp(bp, fp->index, napi));
  1589. status &= ~mask;
  1590. }
  1591. }
  1592. if (CNIC_SUPPORT(bp)) {
  1593. mask = 0x2;
  1594. if (status & (mask | 0x1)) {
  1595. struct cnic_ops *c_ops = NULL;
  1596. rcu_read_lock();
  1597. c_ops = rcu_dereference(bp->cnic_ops);
  1598. if (c_ops && (bp->cnic_eth_dev.drv_state &
  1599. CNIC_DRV_STATE_HANDLES_IRQ))
  1600. c_ops->cnic_handler(bp->cnic_data, NULL);
  1601. rcu_read_unlock();
  1602. status &= ~mask;
  1603. }
  1604. }
  1605. if (unlikely(status & 0x1)) {
  1606. /* schedule sp task to perform default status block work, ack
  1607. * attentions and enable interrupts.
  1608. */
  1609. bnx2x_schedule_sp_task(bp);
  1610. status &= ~0x1;
  1611. if (!status)
  1612. return IRQ_HANDLED;
  1613. }
  1614. if (unlikely(status))
  1615. DP(NETIF_MSG_INTR, "got an unknown interrupt! (status 0x%x)\n",
  1616. status);
  1617. return IRQ_HANDLED;
  1618. }
  1619. /* Link */
  1620. /*
  1621. * General service functions
  1622. */
  1623. int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource)
  1624. {
  1625. u32 lock_status;
  1626. u32 resource_bit = (1 << resource);
  1627. int func = BP_FUNC(bp);
  1628. u32 hw_lock_control_reg;
  1629. int cnt;
  1630. /* Validating that the resource is within range */
  1631. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1632. BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1633. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1634. return -EINVAL;
  1635. }
  1636. if (func <= 5) {
  1637. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1638. } else {
  1639. hw_lock_control_reg =
  1640. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1641. }
  1642. /* Validating that the resource is not already taken */
  1643. lock_status = REG_RD(bp, hw_lock_control_reg);
  1644. if (lock_status & resource_bit) {
  1645. BNX2X_ERR("lock_status 0x%x resource_bit 0x%x\n",
  1646. lock_status, resource_bit);
  1647. return -EEXIST;
  1648. }
  1649. /* Try for 5 second every 5ms */
  1650. for (cnt = 0; cnt < 1000; cnt++) {
  1651. /* Try to acquire the lock */
  1652. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1653. lock_status = REG_RD(bp, hw_lock_control_reg);
  1654. if (lock_status & resource_bit)
  1655. return 0;
  1656. msleep(5);
  1657. }
  1658. BNX2X_ERR("Timeout\n");
  1659. return -EAGAIN;
  1660. }
  1661. int bnx2x_release_leader_lock(struct bnx2x *bp)
  1662. {
  1663. return bnx2x_release_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1664. }
  1665. int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource)
  1666. {
  1667. u32 lock_status;
  1668. u32 resource_bit = (1 << resource);
  1669. int func = BP_FUNC(bp);
  1670. u32 hw_lock_control_reg;
  1671. /* Validating that the resource is within range */
  1672. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1673. BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1674. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1675. return -EINVAL;
  1676. }
  1677. if (func <= 5) {
  1678. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1679. } else {
  1680. hw_lock_control_reg =
  1681. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1682. }
  1683. /* Validating that the resource is currently taken */
  1684. lock_status = REG_RD(bp, hw_lock_control_reg);
  1685. if (!(lock_status & resource_bit)) {
  1686. BNX2X_ERR("lock_status 0x%x resource_bit 0x%x. unlock was called but lock wasn't taken!\n",
  1687. lock_status, resource_bit);
  1688. return -EFAULT;
  1689. }
  1690. REG_WR(bp, hw_lock_control_reg, resource_bit);
  1691. return 0;
  1692. }
  1693. int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port)
  1694. {
  1695. /* The GPIO should be swapped if swap register is set and active */
  1696. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1697. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1698. int gpio_shift = gpio_num +
  1699. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1700. u32 gpio_mask = (1 << gpio_shift);
  1701. u32 gpio_reg;
  1702. int value;
  1703. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1704. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1705. return -EINVAL;
  1706. }
  1707. /* read GPIO value */
  1708. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1709. /* get the requested pin value */
  1710. if ((gpio_reg & gpio_mask) == gpio_mask)
  1711. value = 1;
  1712. else
  1713. value = 0;
  1714. DP(NETIF_MSG_LINK, "pin %d value 0x%x\n", gpio_num, value);
  1715. return value;
  1716. }
  1717. int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1718. {
  1719. /* The GPIO should be swapped if swap register is set and active */
  1720. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1721. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1722. int gpio_shift = gpio_num +
  1723. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1724. u32 gpio_mask = (1 << gpio_shift);
  1725. u32 gpio_reg;
  1726. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1727. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1728. return -EINVAL;
  1729. }
  1730. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1731. /* read GPIO and mask except the float bits */
  1732. gpio_reg = (REG_RD(bp, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT);
  1733. switch (mode) {
  1734. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1735. DP(NETIF_MSG_LINK,
  1736. "Set GPIO %d (shift %d) -> output low\n",
  1737. gpio_num, gpio_shift);
  1738. /* clear FLOAT and set CLR */
  1739. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1740. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS);
  1741. break;
  1742. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1743. DP(NETIF_MSG_LINK,
  1744. "Set GPIO %d (shift %d) -> output high\n",
  1745. gpio_num, gpio_shift);
  1746. /* clear FLOAT and set SET */
  1747. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1748. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS);
  1749. break;
  1750. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1751. DP(NETIF_MSG_LINK,
  1752. "Set GPIO %d (shift %d) -> input\n",
  1753. gpio_num, gpio_shift);
  1754. /* set FLOAT */
  1755. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1756. break;
  1757. default:
  1758. break;
  1759. }
  1760. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1761. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1762. return 0;
  1763. }
  1764. int bnx2x_set_mult_gpio(struct bnx2x *bp, u8 pins, u32 mode)
  1765. {
  1766. u32 gpio_reg = 0;
  1767. int rc = 0;
  1768. /* Any port swapping should be handled by caller. */
  1769. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1770. /* read GPIO and mask except the float bits */
  1771. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1772. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1773. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_CLR_POS);
  1774. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_SET_POS);
  1775. switch (mode) {
  1776. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1777. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output low\n", pins);
  1778. /* set CLR */
  1779. gpio_reg |= (pins << MISC_REGISTERS_GPIO_CLR_POS);
  1780. break;
  1781. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1782. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output high\n", pins);
  1783. /* set SET */
  1784. gpio_reg |= (pins << MISC_REGISTERS_GPIO_SET_POS);
  1785. break;
  1786. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1787. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> input\n", pins);
  1788. /* set FLOAT */
  1789. gpio_reg |= (pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1790. break;
  1791. default:
  1792. BNX2X_ERR("Invalid GPIO mode assignment %d\n", mode);
  1793. rc = -EINVAL;
  1794. break;
  1795. }
  1796. if (rc == 0)
  1797. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1798. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1799. return rc;
  1800. }
  1801. int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1802. {
  1803. /* The GPIO should be swapped if swap register is set and active */
  1804. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1805. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1806. int gpio_shift = gpio_num +
  1807. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1808. u32 gpio_mask = (1 << gpio_shift);
  1809. u32 gpio_reg;
  1810. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1811. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1812. return -EINVAL;
  1813. }
  1814. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1815. /* read GPIO int */
  1816. gpio_reg = REG_RD(bp, MISC_REG_GPIO_INT);
  1817. switch (mode) {
  1818. case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR:
  1819. DP(NETIF_MSG_LINK,
  1820. "Clear GPIO INT %d (shift %d) -> output low\n",
  1821. gpio_num, gpio_shift);
  1822. /* clear SET and set CLR */
  1823. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1824. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1825. break;
  1826. case MISC_REGISTERS_GPIO_INT_OUTPUT_SET:
  1827. DP(NETIF_MSG_LINK,
  1828. "Set GPIO INT %d (shift %d) -> output high\n",
  1829. gpio_num, gpio_shift);
  1830. /* clear CLR and set SET */
  1831. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1832. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1833. break;
  1834. default:
  1835. break;
  1836. }
  1837. REG_WR(bp, MISC_REG_GPIO_INT, gpio_reg);
  1838. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1839. return 0;
  1840. }
  1841. static int bnx2x_set_spio(struct bnx2x *bp, int spio, u32 mode)
  1842. {
  1843. u32 spio_reg;
  1844. /* Only 2 SPIOs are configurable */
  1845. if ((spio != MISC_SPIO_SPIO4) && (spio != MISC_SPIO_SPIO5)) {
  1846. BNX2X_ERR("Invalid SPIO 0x%x\n", spio);
  1847. return -EINVAL;
  1848. }
  1849. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1850. /* read SPIO and mask except the float bits */
  1851. spio_reg = (REG_RD(bp, MISC_REG_SPIO) & MISC_SPIO_FLOAT);
  1852. switch (mode) {
  1853. case MISC_SPIO_OUTPUT_LOW:
  1854. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output low\n", spio);
  1855. /* clear FLOAT and set CLR */
  1856. spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
  1857. spio_reg |= (spio << MISC_SPIO_CLR_POS);
  1858. break;
  1859. case MISC_SPIO_OUTPUT_HIGH:
  1860. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output high\n", spio);
  1861. /* clear FLOAT and set SET */
  1862. spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
  1863. spio_reg |= (spio << MISC_SPIO_SET_POS);
  1864. break;
  1865. case MISC_SPIO_INPUT_HI_Z:
  1866. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> input\n", spio);
  1867. /* set FLOAT */
  1868. spio_reg |= (spio << MISC_SPIO_FLOAT_POS);
  1869. break;
  1870. default:
  1871. break;
  1872. }
  1873. REG_WR(bp, MISC_REG_SPIO, spio_reg);
  1874. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1875. return 0;
  1876. }
  1877. void bnx2x_calc_fc_adv(struct bnx2x *bp)
  1878. {
  1879. u8 cfg_idx = bnx2x_get_link_cfg_idx(bp);
  1880. switch (bp->link_vars.ieee_fc &
  1881. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) {
  1882. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE:
  1883. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1884. ADVERTISED_Pause);
  1885. break;
  1886. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH:
  1887. bp->port.advertising[cfg_idx] |= (ADVERTISED_Asym_Pause |
  1888. ADVERTISED_Pause);
  1889. break;
  1890. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC:
  1891. bp->port.advertising[cfg_idx] |= ADVERTISED_Asym_Pause;
  1892. break;
  1893. default:
  1894. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1895. ADVERTISED_Pause);
  1896. break;
  1897. }
  1898. }
  1899. static void bnx2x_set_requested_fc(struct bnx2x *bp)
  1900. {
  1901. /* Initialize link parameters structure variables
  1902. * It is recommended to turn off RX FC for jumbo frames
  1903. * for better performance
  1904. */
  1905. if (CHIP_IS_E1x(bp) && (bp->dev->mtu > 5000))
  1906. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_TX;
  1907. else
  1908. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH;
  1909. }
  1910. int bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode)
  1911. {
  1912. int rc, cfx_idx = bnx2x_get_link_cfg_idx(bp);
  1913. u16 req_line_speed = bp->link_params.req_line_speed[cfx_idx];
  1914. if (!BP_NOMCP(bp)) {
  1915. bnx2x_set_requested_fc(bp);
  1916. bnx2x_acquire_phy_lock(bp);
  1917. if (load_mode == LOAD_DIAG) {
  1918. struct link_params *lp = &bp->link_params;
  1919. lp->loopback_mode = LOOPBACK_XGXS;
  1920. /* do PHY loopback at 10G speed, if possible */
  1921. if (lp->req_line_speed[cfx_idx] < SPEED_10000) {
  1922. if (lp->speed_cap_mask[cfx_idx] &
  1923. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
  1924. lp->req_line_speed[cfx_idx] =
  1925. SPEED_10000;
  1926. else
  1927. lp->req_line_speed[cfx_idx] =
  1928. SPEED_1000;
  1929. }
  1930. }
  1931. if (load_mode == LOAD_LOOPBACK_EXT) {
  1932. struct link_params *lp = &bp->link_params;
  1933. lp->loopback_mode = LOOPBACK_EXT;
  1934. }
  1935. rc = bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  1936. bnx2x_release_phy_lock(bp);
  1937. bnx2x_calc_fc_adv(bp);
  1938. if (bp->link_vars.link_up) {
  1939. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  1940. bnx2x_link_report(bp);
  1941. }
  1942. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  1943. bp->link_params.req_line_speed[cfx_idx] = req_line_speed;
  1944. return rc;
  1945. }
  1946. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  1947. return -EINVAL;
  1948. }
  1949. void bnx2x_link_set(struct bnx2x *bp)
  1950. {
  1951. if (!BP_NOMCP(bp)) {
  1952. bnx2x_acquire_phy_lock(bp);
  1953. bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  1954. bnx2x_release_phy_lock(bp);
  1955. bnx2x_calc_fc_adv(bp);
  1956. } else
  1957. BNX2X_ERR("Bootcode is missing - can not set link\n");
  1958. }
  1959. static void bnx2x__link_reset(struct bnx2x *bp)
  1960. {
  1961. if (!BP_NOMCP(bp)) {
  1962. bnx2x_acquire_phy_lock(bp);
  1963. bnx2x_lfa_reset(&bp->link_params, &bp->link_vars);
  1964. bnx2x_release_phy_lock(bp);
  1965. } else
  1966. BNX2X_ERR("Bootcode is missing - can not reset link\n");
  1967. }
  1968. void bnx2x_force_link_reset(struct bnx2x *bp)
  1969. {
  1970. bnx2x_acquire_phy_lock(bp);
  1971. bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
  1972. bnx2x_release_phy_lock(bp);
  1973. }
  1974. u8 bnx2x_link_test(struct bnx2x *bp, u8 is_serdes)
  1975. {
  1976. u8 rc = 0;
  1977. if (!BP_NOMCP(bp)) {
  1978. bnx2x_acquire_phy_lock(bp);
  1979. rc = bnx2x_test_link(&bp->link_params, &bp->link_vars,
  1980. is_serdes);
  1981. bnx2x_release_phy_lock(bp);
  1982. } else
  1983. BNX2X_ERR("Bootcode is missing - can not test link\n");
  1984. return rc;
  1985. }
  1986. /* Calculates the sum of vn_min_rates.
  1987. It's needed for further normalizing of the min_rates.
  1988. Returns:
  1989. sum of vn_min_rates.
  1990. or
  1991. 0 - if all the min_rates are 0.
  1992. In the later case fainess algorithm should be deactivated.
  1993. If not all min_rates are zero then those that are zeroes will be set to 1.
  1994. */
  1995. static void bnx2x_calc_vn_min(struct bnx2x *bp,
  1996. struct cmng_init_input *input)
  1997. {
  1998. int all_zero = 1;
  1999. int vn;
  2000. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2001. u32 vn_cfg = bp->mf_config[vn];
  2002. u32 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
  2003. FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
  2004. /* Skip hidden vns */
  2005. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  2006. vn_min_rate = 0;
  2007. /* If min rate is zero - set it to 1 */
  2008. else if (!vn_min_rate)
  2009. vn_min_rate = DEF_MIN_RATE;
  2010. else
  2011. all_zero = 0;
  2012. input->vnic_min_rate[vn] = vn_min_rate;
  2013. }
  2014. /* if ETS or all min rates are zeros - disable fairness */
  2015. if (BNX2X_IS_ETS_ENABLED(bp)) {
  2016. input->flags.cmng_enables &=
  2017. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2018. DP(NETIF_MSG_IFUP, "Fairness will be disabled due to ETS\n");
  2019. } else if (all_zero) {
  2020. input->flags.cmng_enables &=
  2021. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2022. DP(NETIF_MSG_IFUP,
  2023. "All MIN values are zeroes fairness will be disabled\n");
  2024. } else
  2025. input->flags.cmng_enables |=
  2026. CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2027. }
  2028. static void bnx2x_calc_vn_max(struct bnx2x *bp, int vn,
  2029. struct cmng_init_input *input)
  2030. {
  2031. u16 vn_max_rate;
  2032. u32 vn_cfg = bp->mf_config[vn];
  2033. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  2034. vn_max_rate = 0;
  2035. else {
  2036. u32 maxCfg = bnx2x_extract_max_cfg(bp, vn_cfg);
  2037. if (IS_MF_SI(bp)) {
  2038. /* maxCfg in percents of linkspeed */
  2039. vn_max_rate = (bp->link_vars.line_speed * maxCfg) / 100;
  2040. } else /* SD modes */
  2041. /* maxCfg is absolute in 100Mb units */
  2042. vn_max_rate = maxCfg * 100;
  2043. }
  2044. DP(NETIF_MSG_IFUP, "vn %d: vn_max_rate %d\n", vn, vn_max_rate);
  2045. input->vnic_max_rate[vn] = vn_max_rate;
  2046. }
  2047. static int bnx2x_get_cmng_fns_mode(struct bnx2x *bp)
  2048. {
  2049. if (CHIP_REV_IS_SLOW(bp))
  2050. return CMNG_FNS_NONE;
  2051. if (IS_MF(bp))
  2052. return CMNG_FNS_MINMAX;
  2053. return CMNG_FNS_NONE;
  2054. }
  2055. void bnx2x_read_mf_cfg(struct bnx2x *bp)
  2056. {
  2057. int vn, n = (CHIP_MODE_IS_4_PORT(bp) ? 2 : 1);
  2058. if (BP_NOMCP(bp))
  2059. return; /* what should be the default bvalue in this case */
  2060. /* For 2 port configuration the absolute function number formula
  2061. * is:
  2062. * abs_func = 2 * vn + BP_PORT + BP_PATH
  2063. *
  2064. * and there are 4 functions per port
  2065. *
  2066. * For 4 port configuration it is
  2067. * abs_func = 4 * vn + 2 * BP_PORT + BP_PATH
  2068. *
  2069. * and there are 2 functions per port
  2070. */
  2071. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2072. int /*abs*/func = n * (2 * vn + BP_PORT(bp)) + BP_PATH(bp);
  2073. if (func >= E1H_FUNC_MAX)
  2074. break;
  2075. bp->mf_config[vn] =
  2076. MF_CFG_RD(bp, func_mf_config[func].config);
  2077. }
  2078. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  2079. DP(NETIF_MSG_IFUP, "mf_cfg function disabled\n");
  2080. bp->flags |= MF_FUNC_DIS;
  2081. } else {
  2082. DP(NETIF_MSG_IFUP, "mf_cfg function enabled\n");
  2083. bp->flags &= ~MF_FUNC_DIS;
  2084. }
  2085. }
  2086. static void bnx2x_cmng_fns_init(struct bnx2x *bp, u8 read_cfg, u8 cmng_type)
  2087. {
  2088. struct cmng_init_input input;
  2089. memset(&input, 0, sizeof(struct cmng_init_input));
  2090. input.port_rate = bp->link_vars.line_speed;
  2091. if (cmng_type == CMNG_FNS_MINMAX) {
  2092. int vn;
  2093. /* read mf conf from shmem */
  2094. if (read_cfg)
  2095. bnx2x_read_mf_cfg(bp);
  2096. /* vn_weight_sum and enable fairness if not 0 */
  2097. bnx2x_calc_vn_min(bp, &input);
  2098. /* calculate and set min-max rate for each vn */
  2099. if (bp->port.pmf)
  2100. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++)
  2101. bnx2x_calc_vn_max(bp, vn, &input);
  2102. /* always enable rate shaping and fairness */
  2103. input.flags.cmng_enables |=
  2104. CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN;
  2105. bnx2x_init_cmng(&input, &bp->cmng);
  2106. return;
  2107. }
  2108. /* rate shaping and fairness are disabled */
  2109. DP(NETIF_MSG_IFUP,
  2110. "rate shaping and fairness are disabled\n");
  2111. }
  2112. static void storm_memset_cmng(struct bnx2x *bp,
  2113. struct cmng_init *cmng,
  2114. u8 port)
  2115. {
  2116. int vn;
  2117. size_t size = sizeof(struct cmng_struct_per_port);
  2118. u32 addr = BAR_XSTRORM_INTMEM +
  2119. XSTORM_CMNG_PER_PORT_VARS_OFFSET(port);
  2120. __storm_memset_struct(bp, addr, size, (u32 *)&cmng->port);
  2121. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2122. int func = func_by_vn(bp, vn);
  2123. addr = BAR_XSTRORM_INTMEM +
  2124. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func);
  2125. size = sizeof(struct rate_shaping_vars_per_vn);
  2126. __storm_memset_struct(bp, addr, size,
  2127. (u32 *)&cmng->vnic.vnic_max_rate[vn]);
  2128. addr = BAR_XSTRORM_INTMEM +
  2129. XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func);
  2130. size = sizeof(struct fairness_vars_per_vn);
  2131. __storm_memset_struct(bp, addr, size,
  2132. (u32 *)&cmng->vnic.vnic_min_rate[vn]);
  2133. }
  2134. }
  2135. /* This function is called upon link interrupt */
  2136. static void bnx2x_link_attn(struct bnx2x *bp)
  2137. {
  2138. /* Make sure that we are synced with the current statistics */
  2139. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2140. bnx2x_link_update(&bp->link_params, &bp->link_vars);
  2141. if (bp->link_vars.link_up) {
  2142. /* dropless flow control */
  2143. if (!CHIP_IS_E1(bp) && bp->dropless_fc) {
  2144. int port = BP_PORT(bp);
  2145. u32 pause_enabled = 0;
  2146. if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX)
  2147. pause_enabled = 1;
  2148. REG_WR(bp, BAR_USTRORM_INTMEM +
  2149. USTORM_ETH_PAUSE_ENABLED_OFFSET(port),
  2150. pause_enabled);
  2151. }
  2152. if (bp->link_vars.mac_type != MAC_TYPE_EMAC) {
  2153. struct host_port_stats *pstats;
  2154. pstats = bnx2x_sp(bp, port_stats);
  2155. /* reset old mac stats */
  2156. memset(&(pstats->mac_stx[0]), 0,
  2157. sizeof(struct mac_stx));
  2158. }
  2159. if (bp->state == BNX2X_STATE_OPEN)
  2160. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2161. }
  2162. if (bp->link_vars.link_up && bp->link_vars.line_speed) {
  2163. int cmng_fns = bnx2x_get_cmng_fns_mode(bp);
  2164. if (cmng_fns != CMNG_FNS_NONE) {
  2165. bnx2x_cmng_fns_init(bp, false, cmng_fns);
  2166. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2167. } else
  2168. /* rate shaping and fairness are disabled */
  2169. DP(NETIF_MSG_IFUP,
  2170. "single function mode without fairness\n");
  2171. }
  2172. __bnx2x_link_report(bp);
  2173. if (IS_MF(bp))
  2174. bnx2x_link_sync_notify(bp);
  2175. }
  2176. void bnx2x__link_status_update(struct bnx2x *bp)
  2177. {
  2178. if (bp->state != BNX2X_STATE_OPEN)
  2179. return;
  2180. /* read updated dcb configuration */
  2181. if (IS_PF(bp)) {
  2182. bnx2x_dcbx_pmf_update(bp);
  2183. bnx2x_link_status_update(&bp->link_params, &bp->link_vars);
  2184. if (bp->link_vars.link_up)
  2185. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2186. else
  2187. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2188. /* indicate link status */
  2189. bnx2x_link_report(bp);
  2190. } else { /* VF */
  2191. bp->port.supported[0] |= (SUPPORTED_10baseT_Half |
  2192. SUPPORTED_10baseT_Full |
  2193. SUPPORTED_100baseT_Half |
  2194. SUPPORTED_100baseT_Full |
  2195. SUPPORTED_1000baseT_Full |
  2196. SUPPORTED_2500baseX_Full |
  2197. SUPPORTED_10000baseT_Full |
  2198. SUPPORTED_TP |
  2199. SUPPORTED_FIBRE |
  2200. SUPPORTED_Autoneg |
  2201. SUPPORTED_Pause |
  2202. SUPPORTED_Asym_Pause);
  2203. bp->port.advertising[0] = bp->port.supported[0];
  2204. bp->link_params.bp = bp;
  2205. bp->link_params.port = BP_PORT(bp);
  2206. bp->link_params.req_duplex[0] = DUPLEX_FULL;
  2207. bp->link_params.req_flow_ctrl[0] = BNX2X_FLOW_CTRL_NONE;
  2208. bp->link_params.req_line_speed[0] = SPEED_10000;
  2209. bp->link_params.speed_cap_mask[0] = 0x7f0000;
  2210. bp->link_params.switch_cfg = SWITCH_CFG_10G;
  2211. bp->link_vars.mac_type = MAC_TYPE_BMAC;
  2212. bp->link_vars.line_speed = SPEED_10000;
  2213. bp->link_vars.link_status =
  2214. (LINK_STATUS_LINK_UP |
  2215. LINK_STATUS_SPEED_AND_DUPLEX_10GTFD);
  2216. bp->link_vars.link_up = 1;
  2217. bp->link_vars.duplex = DUPLEX_FULL;
  2218. bp->link_vars.flow_ctrl = BNX2X_FLOW_CTRL_NONE;
  2219. __bnx2x_link_report(bp);
  2220. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2221. }
  2222. }
  2223. static int bnx2x_afex_func_update(struct bnx2x *bp, u16 vifid,
  2224. u16 vlan_val, u8 allowed_prio)
  2225. {
  2226. struct bnx2x_func_state_params func_params = {NULL};
  2227. struct bnx2x_func_afex_update_params *f_update_params =
  2228. &func_params.params.afex_update;
  2229. func_params.f_obj = &bp->func_obj;
  2230. func_params.cmd = BNX2X_F_CMD_AFEX_UPDATE;
  2231. /* no need to wait for RAMROD completion, so don't
  2232. * set RAMROD_COMP_WAIT flag
  2233. */
  2234. f_update_params->vif_id = vifid;
  2235. f_update_params->afex_default_vlan = vlan_val;
  2236. f_update_params->allowed_priorities = allowed_prio;
  2237. /* if ramrod can not be sent, response to MCP immediately */
  2238. if (bnx2x_func_state_change(bp, &func_params) < 0)
  2239. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  2240. return 0;
  2241. }
  2242. static int bnx2x_afex_handle_vif_list_cmd(struct bnx2x *bp, u8 cmd_type,
  2243. u16 vif_index, u8 func_bit_map)
  2244. {
  2245. struct bnx2x_func_state_params func_params = {NULL};
  2246. struct bnx2x_func_afex_viflists_params *update_params =
  2247. &func_params.params.afex_viflists;
  2248. int rc;
  2249. u32 drv_msg_code;
  2250. /* validate only LIST_SET and LIST_GET are received from switch */
  2251. if ((cmd_type != VIF_LIST_RULE_GET) && (cmd_type != VIF_LIST_RULE_SET))
  2252. BNX2X_ERR("BUG! afex_handle_vif_list_cmd invalid type 0x%x\n",
  2253. cmd_type);
  2254. func_params.f_obj = &bp->func_obj;
  2255. func_params.cmd = BNX2X_F_CMD_AFEX_VIFLISTS;
  2256. /* set parameters according to cmd_type */
  2257. update_params->afex_vif_list_command = cmd_type;
  2258. update_params->vif_list_index = vif_index;
  2259. update_params->func_bit_map =
  2260. (cmd_type == VIF_LIST_RULE_GET) ? 0 : func_bit_map;
  2261. update_params->func_to_clear = 0;
  2262. drv_msg_code =
  2263. (cmd_type == VIF_LIST_RULE_GET) ?
  2264. DRV_MSG_CODE_AFEX_LISTGET_ACK :
  2265. DRV_MSG_CODE_AFEX_LISTSET_ACK;
  2266. /* if ramrod can not be sent, respond to MCP immediately for
  2267. * SET and GET requests (other are not triggered from MCP)
  2268. */
  2269. rc = bnx2x_func_state_change(bp, &func_params);
  2270. if (rc < 0)
  2271. bnx2x_fw_command(bp, drv_msg_code, 0);
  2272. return 0;
  2273. }
  2274. static void bnx2x_handle_afex_cmd(struct bnx2x *bp, u32 cmd)
  2275. {
  2276. struct afex_stats afex_stats;
  2277. u32 func = BP_ABS_FUNC(bp);
  2278. u32 mf_config;
  2279. u16 vlan_val;
  2280. u32 vlan_prio;
  2281. u16 vif_id;
  2282. u8 allowed_prio;
  2283. u8 vlan_mode;
  2284. u32 addr_to_write, vifid, addrs, stats_type, i;
  2285. if (cmd & DRV_STATUS_AFEX_LISTGET_REQ) {
  2286. vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2287. DP(BNX2X_MSG_MCP,
  2288. "afex: got MCP req LISTGET_REQ for vifid 0x%x\n", vifid);
  2289. bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_GET, vifid, 0);
  2290. }
  2291. if (cmd & DRV_STATUS_AFEX_LISTSET_REQ) {
  2292. vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2293. addrs = SHMEM2_RD(bp, afex_param2_to_driver[BP_FW_MB_IDX(bp)]);
  2294. DP(BNX2X_MSG_MCP,
  2295. "afex: got MCP req LISTSET_REQ for vifid 0x%x addrs 0x%x\n",
  2296. vifid, addrs);
  2297. bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_SET, vifid,
  2298. addrs);
  2299. }
  2300. if (cmd & DRV_STATUS_AFEX_STATSGET_REQ) {
  2301. addr_to_write = SHMEM2_RD(bp,
  2302. afex_scratchpad_addr_to_write[BP_FW_MB_IDX(bp)]);
  2303. stats_type = SHMEM2_RD(bp,
  2304. afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2305. DP(BNX2X_MSG_MCP,
  2306. "afex: got MCP req STATSGET_REQ, write to addr 0x%x\n",
  2307. addr_to_write);
  2308. bnx2x_afex_collect_stats(bp, (void *)&afex_stats, stats_type);
  2309. /* write response to scratchpad, for MCP */
  2310. for (i = 0; i < (sizeof(struct afex_stats)/sizeof(u32)); i++)
  2311. REG_WR(bp, addr_to_write + i*sizeof(u32),
  2312. *(((u32 *)(&afex_stats))+i));
  2313. /* send ack message to MCP */
  2314. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_STATSGET_ACK, 0);
  2315. }
  2316. if (cmd & DRV_STATUS_AFEX_VIFSET_REQ) {
  2317. mf_config = MF_CFG_RD(bp, func_mf_config[func].config);
  2318. bp->mf_config[BP_VN(bp)] = mf_config;
  2319. DP(BNX2X_MSG_MCP,
  2320. "afex: got MCP req VIFSET_REQ, mf_config 0x%x\n",
  2321. mf_config);
  2322. /* if VIF_SET is "enabled" */
  2323. if (!(mf_config & FUNC_MF_CFG_FUNC_DISABLED)) {
  2324. /* set rate limit directly to internal RAM */
  2325. struct cmng_init_input cmng_input;
  2326. struct rate_shaping_vars_per_vn m_rs_vn;
  2327. size_t size = sizeof(struct rate_shaping_vars_per_vn);
  2328. u32 addr = BAR_XSTRORM_INTMEM +
  2329. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(BP_FUNC(bp));
  2330. bp->mf_config[BP_VN(bp)] = mf_config;
  2331. bnx2x_calc_vn_max(bp, BP_VN(bp), &cmng_input);
  2332. m_rs_vn.vn_counter.rate =
  2333. cmng_input.vnic_max_rate[BP_VN(bp)];
  2334. m_rs_vn.vn_counter.quota =
  2335. (m_rs_vn.vn_counter.rate *
  2336. RS_PERIODIC_TIMEOUT_USEC) / 8;
  2337. __storm_memset_struct(bp, addr, size, (u32 *)&m_rs_vn);
  2338. /* read relevant values from mf_cfg struct in shmem */
  2339. vif_id =
  2340. (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2341. FUNC_MF_CFG_E1HOV_TAG_MASK) >>
  2342. FUNC_MF_CFG_E1HOV_TAG_SHIFT;
  2343. vlan_val =
  2344. (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2345. FUNC_MF_CFG_AFEX_VLAN_MASK) >>
  2346. FUNC_MF_CFG_AFEX_VLAN_SHIFT;
  2347. vlan_prio = (mf_config &
  2348. FUNC_MF_CFG_TRANSMIT_PRIORITY_MASK) >>
  2349. FUNC_MF_CFG_TRANSMIT_PRIORITY_SHIFT;
  2350. vlan_val |= (vlan_prio << VLAN_PRIO_SHIFT);
  2351. vlan_mode =
  2352. (MF_CFG_RD(bp,
  2353. func_mf_config[func].afex_config) &
  2354. FUNC_MF_CFG_AFEX_VLAN_MODE_MASK) >>
  2355. FUNC_MF_CFG_AFEX_VLAN_MODE_SHIFT;
  2356. allowed_prio =
  2357. (MF_CFG_RD(bp,
  2358. func_mf_config[func].afex_config) &
  2359. FUNC_MF_CFG_AFEX_COS_FILTER_MASK) >>
  2360. FUNC_MF_CFG_AFEX_COS_FILTER_SHIFT;
  2361. /* send ramrod to FW, return in case of failure */
  2362. if (bnx2x_afex_func_update(bp, vif_id, vlan_val,
  2363. allowed_prio))
  2364. return;
  2365. bp->afex_def_vlan_tag = vlan_val;
  2366. bp->afex_vlan_mode = vlan_mode;
  2367. } else {
  2368. /* notify link down because BP->flags is disabled */
  2369. bnx2x_link_report(bp);
  2370. /* send INVALID VIF ramrod to FW */
  2371. bnx2x_afex_func_update(bp, 0xFFFF, 0, 0);
  2372. /* Reset the default afex VLAN */
  2373. bp->afex_def_vlan_tag = -1;
  2374. }
  2375. }
  2376. }
  2377. static void bnx2x_pmf_update(struct bnx2x *bp)
  2378. {
  2379. int port = BP_PORT(bp);
  2380. u32 val;
  2381. bp->port.pmf = 1;
  2382. DP(BNX2X_MSG_MCP, "pmf %d\n", bp->port.pmf);
  2383. /*
  2384. * We need the mb() to ensure the ordering between the writing to
  2385. * bp->port.pmf here and reading it from the bnx2x_periodic_task().
  2386. */
  2387. smp_mb();
  2388. /* queue a periodic task */
  2389. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  2390. bnx2x_dcbx_pmf_update(bp);
  2391. /* enable nig attention */
  2392. val = (0xff0f | (1 << (BP_VN(bp) + 4)));
  2393. if (bp->common.int_block == INT_BLOCK_HC) {
  2394. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  2395. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  2396. } else if (!CHIP_IS_E1x(bp)) {
  2397. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  2398. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  2399. }
  2400. bnx2x_stats_handle(bp, STATS_EVENT_PMF);
  2401. }
  2402. /* end of Link */
  2403. /* slow path */
  2404. /*
  2405. * General service functions
  2406. */
  2407. /* send the MCP a request, block until there is a reply */
  2408. u32 bnx2x_fw_command(struct bnx2x *bp, u32 command, u32 param)
  2409. {
  2410. int mb_idx = BP_FW_MB_IDX(bp);
  2411. u32 seq;
  2412. u32 rc = 0;
  2413. u32 cnt = 1;
  2414. u8 delay = CHIP_REV_IS_SLOW(bp) ? 100 : 10;
  2415. mutex_lock(&bp->fw_mb_mutex);
  2416. seq = ++bp->fw_seq;
  2417. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_param, param);
  2418. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_header, (command | seq));
  2419. DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB param 0x%08x\n",
  2420. (command | seq), param);
  2421. do {
  2422. /* let the FW do it's magic ... */
  2423. msleep(delay);
  2424. rc = SHMEM_RD(bp, func_mb[mb_idx].fw_mb_header);
  2425. /* Give the FW up to 5 second (500*10ms) */
  2426. } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500));
  2427. DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n",
  2428. cnt*delay, rc, seq);
  2429. /* is this a reply to our command? */
  2430. if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK))
  2431. rc &= FW_MSG_CODE_MASK;
  2432. else {
  2433. /* FW BUG! */
  2434. BNX2X_ERR("FW failed to respond!\n");
  2435. bnx2x_fw_dump(bp);
  2436. rc = 0;
  2437. }
  2438. mutex_unlock(&bp->fw_mb_mutex);
  2439. return rc;
  2440. }
  2441. static void storm_memset_func_cfg(struct bnx2x *bp,
  2442. struct tstorm_eth_function_common_config *tcfg,
  2443. u16 abs_fid)
  2444. {
  2445. size_t size = sizeof(struct tstorm_eth_function_common_config);
  2446. u32 addr = BAR_TSTRORM_INTMEM +
  2447. TSTORM_FUNCTION_COMMON_CONFIG_OFFSET(abs_fid);
  2448. __storm_memset_struct(bp, addr, size, (u32 *)tcfg);
  2449. }
  2450. void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p)
  2451. {
  2452. if (CHIP_IS_E1x(bp)) {
  2453. struct tstorm_eth_function_common_config tcfg = {0};
  2454. storm_memset_func_cfg(bp, &tcfg, p->func_id);
  2455. }
  2456. /* Enable the function in the FW */
  2457. storm_memset_vf_to_pf(bp, p->func_id, p->pf_id);
  2458. storm_memset_func_en(bp, p->func_id, 1);
  2459. /* spq */
  2460. if (p->func_flgs & FUNC_FLG_SPQ) {
  2461. storm_memset_spq_addr(bp, p->spq_map, p->func_id);
  2462. REG_WR(bp, XSEM_REG_FAST_MEMORY +
  2463. XSTORM_SPQ_PROD_OFFSET(p->func_id), p->spq_prod);
  2464. }
  2465. }
  2466. /**
  2467. * bnx2x_get_tx_only_flags - Return common flags
  2468. *
  2469. * @bp device handle
  2470. * @fp queue handle
  2471. * @zero_stats TRUE if statistics zeroing is needed
  2472. *
  2473. * Return the flags that are common for the Tx-only and not normal connections.
  2474. */
  2475. static unsigned long bnx2x_get_common_flags(struct bnx2x *bp,
  2476. struct bnx2x_fastpath *fp,
  2477. bool zero_stats)
  2478. {
  2479. unsigned long flags = 0;
  2480. /* PF driver will always initialize the Queue to an ACTIVE state */
  2481. __set_bit(BNX2X_Q_FLG_ACTIVE, &flags);
  2482. /* tx only connections collect statistics (on the same index as the
  2483. * parent connection). The statistics are zeroed when the parent
  2484. * connection is initialized.
  2485. */
  2486. __set_bit(BNX2X_Q_FLG_STATS, &flags);
  2487. if (zero_stats)
  2488. __set_bit(BNX2X_Q_FLG_ZERO_STATS, &flags);
  2489. __set_bit(BNX2X_Q_FLG_PCSUM_ON_PKT, &flags);
  2490. __set_bit(BNX2X_Q_FLG_TUN_INC_INNER_IP_ID, &flags);
  2491. #ifdef BNX2X_STOP_ON_ERROR
  2492. __set_bit(BNX2X_Q_FLG_TX_SEC, &flags);
  2493. #endif
  2494. return flags;
  2495. }
  2496. static unsigned long bnx2x_get_q_flags(struct bnx2x *bp,
  2497. struct bnx2x_fastpath *fp,
  2498. bool leading)
  2499. {
  2500. unsigned long flags = 0;
  2501. /* calculate other queue flags */
  2502. if (IS_MF_SD(bp))
  2503. __set_bit(BNX2X_Q_FLG_OV, &flags);
  2504. if (IS_FCOE_FP(fp)) {
  2505. __set_bit(BNX2X_Q_FLG_FCOE, &flags);
  2506. /* For FCoE - force usage of default priority (for afex) */
  2507. __set_bit(BNX2X_Q_FLG_FORCE_DEFAULT_PRI, &flags);
  2508. }
  2509. if (!fp->disable_tpa) {
  2510. __set_bit(BNX2X_Q_FLG_TPA, &flags);
  2511. __set_bit(BNX2X_Q_FLG_TPA_IPV6, &flags);
  2512. if (fp->mode == TPA_MODE_GRO)
  2513. __set_bit(BNX2X_Q_FLG_TPA_GRO, &flags);
  2514. }
  2515. if (leading) {
  2516. __set_bit(BNX2X_Q_FLG_LEADING_RSS, &flags);
  2517. __set_bit(BNX2X_Q_FLG_MCAST, &flags);
  2518. }
  2519. /* Always set HW VLAN stripping */
  2520. __set_bit(BNX2X_Q_FLG_VLAN, &flags);
  2521. /* configure silent vlan removal */
  2522. if (IS_MF_AFEX(bp))
  2523. __set_bit(BNX2X_Q_FLG_SILENT_VLAN_REM, &flags);
  2524. return flags | bnx2x_get_common_flags(bp, fp, true);
  2525. }
  2526. static void bnx2x_pf_q_prep_general(struct bnx2x *bp,
  2527. struct bnx2x_fastpath *fp, struct bnx2x_general_setup_params *gen_init,
  2528. u8 cos)
  2529. {
  2530. gen_init->stat_id = bnx2x_stats_id(fp);
  2531. gen_init->spcl_id = fp->cl_id;
  2532. /* Always use mini-jumbo MTU for FCoE L2 ring */
  2533. if (IS_FCOE_FP(fp))
  2534. gen_init->mtu = BNX2X_FCOE_MINI_JUMBO_MTU;
  2535. else
  2536. gen_init->mtu = bp->dev->mtu;
  2537. gen_init->cos = cos;
  2538. }
  2539. static void bnx2x_pf_rx_q_prep(struct bnx2x *bp,
  2540. struct bnx2x_fastpath *fp, struct rxq_pause_params *pause,
  2541. struct bnx2x_rxq_setup_params *rxq_init)
  2542. {
  2543. u8 max_sge = 0;
  2544. u16 sge_sz = 0;
  2545. u16 tpa_agg_size = 0;
  2546. if (!fp->disable_tpa) {
  2547. pause->sge_th_lo = SGE_TH_LO(bp);
  2548. pause->sge_th_hi = SGE_TH_HI(bp);
  2549. /* validate SGE ring has enough to cross high threshold */
  2550. WARN_ON(bp->dropless_fc &&
  2551. pause->sge_th_hi + FW_PREFETCH_CNT >
  2552. MAX_RX_SGE_CNT * NUM_RX_SGE_PAGES);
  2553. tpa_agg_size = TPA_AGG_SIZE;
  2554. max_sge = SGE_PAGE_ALIGN(bp->dev->mtu) >>
  2555. SGE_PAGE_SHIFT;
  2556. max_sge = ((max_sge + PAGES_PER_SGE - 1) &
  2557. (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
  2558. sge_sz = (u16)min_t(u32, SGE_PAGES, 0xffff);
  2559. }
  2560. /* pause - not for e1 */
  2561. if (!CHIP_IS_E1(bp)) {
  2562. pause->bd_th_lo = BD_TH_LO(bp);
  2563. pause->bd_th_hi = BD_TH_HI(bp);
  2564. pause->rcq_th_lo = RCQ_TH_LO(bp);
  2565. pause->rcq_th_hi = RCQ_TH_HI(bp);
  2566. /*
  2567. * validate that rings have enough entries to cross
  2568. * high thresholds
  2569. */
  2570. WARN_ON(bp->dropless_fc &&
  2571. pause->bd_th_hi + FW_PREFETCH_CNT >
  2572. bp->rx_ring_size);
  2573. WARN_ON(bp->dropless_fc &&
  2574. pause->rcq_th_hi + FW_PREFETCH_CNT >
  2575. NUM_RCQ_RINGS * MAX_RCQ_DESC_CNT);
  2576. pause->pri_map = 1;
  2577. }
  2578. /* rxq setup */
  2579. rxq_init->dscr_map = fp->rx_desc_mapping;
  2580. rxq_init->sge_map = fp->rx_sge_mapping;
  2581. rxq_init->rcq_map = fp->rx_comp_mapping;
  2582. rxq_init->rcq_np_map = fp->rx_comp_mapping + BCM_PAGE_SIZE;
  2583. /* This should be a maximum number of data bytes that may be
  2584. * placed on the BD (not including paddings).
  2585. */
  2586. rxq_init->buf_sz = fp->rx_buf_size - BNX2X_FW_RX_ALIGN_START -
  2587. BNX2X_FW_RX_ALIGN_END - IP_HEADER_ALIGNMENT_PADDING;
  2588. rxq_init->cl_qzone_id = fp->cl_qzone_id;
  2589. rxq_init->tpa_agg_sz = tpa_agg_size;
  2590. rxq_init->sge_buf_sz = sge_sz;
  2591. rxq_init->max_sges_pkt = max_sge;
  2592. rxq_init->rss_engine_id = BP_FUNC(bp);
  2593. rxq_init->mcast_engine_id = BP_FUNC(bp);
  2594. /* Maximum number or simultaneous TPA aggregation for this Queue.
  2595. *
  2596. * For PF Clients it should be the maximum available number.
  2597. * VF driver(s) may want to define it to a smaller value.
  2598. */
  2599. rxq_init->max_tpa_queues = MAX_AGG_QS(bp);
  2600. rxq_init->cache_line_log = BNX2X_RX_ALIGN_SHIFT;
  2601. rxq_init->fw_sb_id = fp->fw_sb_id;
  2602. if (IS_FCOE_FP(fp))
  2603. rxq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS;
  2604. else
  2605. rxq_init->sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  2606. /* configure silent vlan removal
  2607. * if multi function mode is afex, then mask default vlan
  2608. */
  2609. if (IS_MF_AFEX(bp)) {
  2610. rxq_init->silent_removal_value = bp->afex_def_vlan_tag;
  2611. rxq_init->silent_removal_mask = VLAN_VID_MASK;
  2612. }
  2613. }
  2614. static void bnx2x_pf_tx_q_prep(struct bnx2x *bp,
  2615. struct bnx2x_fastpath *fp, struct bnx2x_txq_setup_params *txq_init,
  2616. u8 cos)
  2617. {
  2618. txq_init->dscr_map = fp->txdata_ptr[cos]->tx_desc_mapping;
  2619. txq_init->sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS + cos;
  2620. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_NW;
  2621. txq_init->fw_sb_id = fp->fw_sb_id;
  2622. /*
  2623. * set the tss leading client id for TX classfication ==
  2624. * leading RSS client id
  2625. */
  2626. txq_init->tss_leading_cl_id = bnx2x_fp(bp, 0, cl_id);
  2627. if (IS_FCOE_FP(fp)) {
  2628. txq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS;
  2629. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_FCOE;
  2630. }
  2631. }
  2632. static void bnx2x_pf_init(struct bnx2x *bp)
  2633. {
  2634. struct bnx2x_func_init_params func_init = {0};
  2635. struct event_ring_data eq_data = { {0} };
  2636. u16 flags;
  2637. if (!CHIP_IS_E1x(bp)) {
  2638. /* reset IGU PF statistics: MSIX + ATTN */
  2639. /* PF */
  2640. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2641. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2642. (CHIP_MODE_IS_4_PORT(bp) ?
  2643. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2644. /* ATTN */
  2645. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2646. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2647. BNX2X_IGU_STAS_MSG_PF_CNT*4 +
  2648. (CHIP_MODE_IS_4_PORT(bp) ?
  2649. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2650. }
  2651. /* function setup flags */
  2652. flags = (FUNC_FLG_STATS | FUNC_FLG_LEADING | FUNC_FLG_SPQ);
  2653. /* This flag is relevant for E1x only.
  2654. * E2 doesn't have a TPA configuration in a function level.
  2655. */
  2656. flags |= (bp->flags & TPA_ENABLE_FLAG) ? FUNC_FLG_TPA : 0;
  2657. func_init.func_flgs = flags;
  2658. func_init.pf_id = BP_FUNC(bp);
  2659. func_init.func_id = BP_FUNC(bp);
  2660. func_init.spq_map = bp->spq_mapping;
  2661. func_init.spq_prod = bp->spq_prod_idx;
  2662. bnx2x_func_init(bp, &func_init);
  2663. memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port));
  2664. /*
  2665. * Congestion management values depend on the link rate
  2666. * There is no active link so initial link rate is set to 10 Gbps.
  2667. * When the link comes up The congestion management values are
  2668. * re-calculated according to the actual link rate.
  2669. */
  2670. bp->link_vars.line_speed = SPEED_10000;
  2671. bnx2x_cmng_fns_init(bp, true, bnx2x_get_cmng_fns_mode(bp));
  2672. /* Only the PMF sets the HW */
  2673. if (bp->port.pmf)
  2674. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2675. /* init Event Queue - PCI bus guarantees correct endianity*/
  2676. eq_data.base_addr.hi = U64_HI(bp->eq_mapping);
  2677. eq_data.base_addr.lo = U64_LO(bp->eq_mapping);
  2678. eq_data.producer = bp->eq_prod;
  2679. eq_data.index_id = HC_SP_INDEX_EQ_CONS;
  2680. eq_data.sb_id = DEF_SB_ID;
  2681. storm_memset_eq_data(bp, &eq_data, BP_FUNC(bp));
  2682. }
  2683. static void bnx2x_e1h_disable(struct bnx2x *bp)
  2684. {
  2685. int port = BP_PORT(bp);
  2686. bnx2x_tx_disable(bp);
  2687. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  2688. }
  2689. static void bnx2x_e1h_enable(struct bnx2x *bp)
  2690. {
  2691. int port = BP_PORT(bp);
  2692. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
  2693. /* Tx queue should be only reenabled */
  2694. netif_tx_wake_all_queues(bp->dev);
  2695. /*
  2696. * Should not call netif_carrier_on since it will be called if the link
  2697. * is up when checking for link state
  2698. */
  2699. }
  2700. #define DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED 3
  2701. static void bnx2x_drv_info_ether_stat(struct bnx2x *bp)
  2702. {
  2703. struct eth_stats_info *ether_stat =
  2704. &bp->slowpath->drv_info_to_mcp.ether_stat;
  2705. struct bnx2x_vlan_mac_obj *mac_obj =
  2706. &bp->sp_objs->mac_obj;
  2707. int i;
  2708. strlcpy(ether_stat->version, DRV_MODULE_VERSION,
  2709. ETH_STAT_INFO_VERSION_LEN);
  2710. /* get DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED macs, placing them in the
  2711. * mac_local field in ether_stat struct. The base address is offset by 2
  2712. * bytes to account for the field being 8 bytes but a mac address is
  2713. * only 6 bytes. Likewise, the stride for the get_n_elements function is
  2714. * 2 bytes to compensate from the 6 bytes of a mac to the 8 bytes
  2715. * allocated by the ether_stat struct, so the macs will land in their
  2716. * proper positions.
  2717. */
  2718. for (i = 0; i < DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED; i++)
  2719. memset(ether_stat->mac_local + i, 0,
  2720. sizeof(ether_stat->mac_local[0]));
  2721. mac_obj->get_n_elements(bp, &bp->sp_objs[0].mac_obj,
  2722. DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED,
  2723. ether_stat->mac_local + MAC_PAD, MAC_PAD,
  2724. ETH_ALEN);
  2725. ether_stat->mtu_size = bp->dev->mtu;
  2726. if (bp->dev->features & NETIF_F_RXCSUM)
  2727. ether_stat->feature_flags |= FEATURE_ETH_CHKSUM_OFFLOAD_MASK;
  2728. if (bp->dev->features & NETIF_F_TSO)
  2729. ether_stat->feature_flags |= FEATURE_ETH_LSO_MASK;
  2730. ether_stat->feature_flags |= bp->common.boot_mode;
  2731. ether_stat->promiscuous_mode = (bp->dev->flags & IFF_PROMISC) ? 1 : 0;
  2732. ether_stat->txq_size = bp->tx_ring_size;
  2733. ether_stat->rxq_size = bp->rx_ring_size;
  2734. }
  2735. static void bnx2x_drv_info_fcoe_stat(struct bnx2x *bp)
  2736. {
  2737. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2738. struct fcoe_stats_info *fcoe_stat =
  2739. &bp->slowpath->drv_info_to_mcp.fcoe_stat;
  2740. if (!CNIC_LOADED(bp))
  2741. return;
  2742. memcpy(fcoe_stat->mac_local + MAC_PAD, bp->fip_mac, ETH_ALEN);
  2743. fcoe_stat->qos_priority =
  2744. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_FCOE];
  2745. /* insert FCoE stats from ramrod response */
  2746. if (!NO_FCOE(bp)) {
  2747. struct tstorm_per_queue_stats *fcoe_q_tstorm_stats =
  2748. &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
  2749. tstorm_queue_statistics;
  2750. struct xstorm_per_queue_stats *fcoe_q_xstorm_stats =
  2751. &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
  2752. xstorm_queue_statistics;
  2753. struct fcoe_statistics_params *fw_fcoe_stat =
  2754. &bp->fw_stats_data->fcoe;
  2755. ADD_64_LE(fcoe_stat->rx_bytes_hi, LE32_0,
  2756. fcoe_stat->rx_bytes_lo,
  2757. fw_fcoe_stat->rx_stat0.fcoe_rx_byte_cnt);
  2758. ADD_64_LE(fcoe_stat->rx_bytes_hi,
  2759. fcoe_q_tstorm_stats->rcv_ucast_bytes.hi,
  2760. fcoe_stat->rx_bytes_lo,
  2761. fcoe_q_tstorm_stats->rcv_ucast_bytes.lo);
  2762. ADD_64_LE(fcoe_stat->rx_bytes_hi,
  2763. fcoe_q_tstorm_stats->rcv_bcast_bytes.hi,
  2764. fcoe_stat->rx_bytes_lo,
  2765. fcoe_q_tstorm_stats->rcv_bcast_bytes.lo);
  2766. ADD_64_LE(fcoe_stat->rx_bytes_hi,
  2767. fcoe_q_tstorm_stats->rcv_mcast_bytes.hi,
  2768. fcoe_stat->rx_bytes_lo,
  2769. fcoe_q_tstorm_stats->rcv_mcast_bytes.lo);
  2770. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2771. fcoe_stat->rx_frames_lo,
  2772. fw_fcoe_stat->rx_stat0.fcoe_rx_pkt_cnt);
  2773. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2774. fcoe_stat->rx_frames_lo,
  2775. fcoe_q_tstorm_stats->rcv_ucast_pkts);
  2776. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2777. fcoe_stat->rx_frames_lo,
  2778. fcoe_q_tstorm_stats->rcv_bcast_pkts);
  2779. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2780. fcoe_stat->rx_frames_lo,
  2781. fcoe_q_tstorm_stats->rcv_mcast_pkts);
  2782. ADD_64_LE(fcoe_stat->tx_bytes_hi, LE32_0,
  2783. fcoe_stat->tx_bytes_lo,
  2784. fw_fcoe_stat->tx_stat.fcoe_tx_byte_cnt);
  2785. ADD_64_LE(fcoe_stat->tx_bytes_hi,
  2786. fcoe_q_xstorm_stats->ucast_bytes_sent.hi,
  2787. fcoe_stat->tx_bytes_lo,
  2788. fcoe_q_xstorm_stats->ucast_bytes_sent.lo);
  2789. ADD_64_LE(fcoe_stat->tx_bytes_hi,
  2790. fcoe_q_xstorm_stats->bcast_bytes_sent.hi,
  2791. fcoe_stat->tx_bytes_lo,
  2792. fcoe_q_xstorm_stats->bcast_bytes_sent.lo);
  2793. ADD_64_LE(fcoe_stat->tx_bytes_hi,
  2794. fcoe_q_xstorm_stats->mcast_bytes_sent.hi,
  2795. fcoe_stat->tx_bytes_lo,
  2796. fcoe_q_xstorm_stats->mcast_bytes_sent.lo);
  2797. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2798. fcoe_stat->tx_frames_lo,
  2799. fw_fcoe_stat->tx_stat.fcoe_tx_pkt_cnt);
  2800. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2801. fcoe_stat->tx_frames_lo,
  2802. fcoe_q_xstorm_stats->ucast_pkts_sent);
  2803. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2804. fcoe_stat->tx_frames_lo,
  2805. fcoe_q_xstorm_stats->bcast_pkts_sent);
  2806. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2807. fcoe_stat->tx_frames_lo,
  2808. fcoe_q_xstorm_stats->mcast_pkts_sent);
  2809. }
  2810. /* ask L5 driver to add data to the struct */
  2811. bnx2x_cnic_notify(bp, CNIC_CTL_FCOE_STATS_GET_CMD);
  2812. }
  2813. static void bnx2x_drv_info_iscsi_stat(struct bnx2x *bp)
  2814. {
  2815. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2816. struct iscsi_stats_info *iscsi_stat =
  2817. &bp->slowpath->drv_info_to_mcp.iscsi_stat;
  2818. if (!CNIC_LOADED(bp))
  2819. return;
  2820. memcpy(iscsi_stat->mac_local + MAC_PAD, bp->cnic_eth_dev.iscsi_mac,
  2821. ETH_ALEN);
  2822. iscsi_stat->qos_priority =
  2823. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_ISCSI];
  2824. /* ask L5 driver to add data to the struct */
  2825. bnx2x_cnic_notify(bp, CNIC_CTL_ISCSI_STATS_GET_CMD);
  2826. }
  2827. /* called due to MCP event (on pmf):
  2828. * reread new bandwidth configuration
  2829. * configure FW
  2830. * notify others function about the change
  2831. */
  2832. static void bnx2x_config_mf_bw(struct bnx2x *bp)
  2833. {
  2834. if (bp->link_vars.link_up) {
  2835. bnx2x_cmng_fns_init(bp, true, CMNG_FNS_MINMAX);
  2836. bnx2x_link_sync_notify(bp);
  2837. }
  2838. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2839. }
  2840. static void bnx2x_set_mf_bw(struct bnx2x *bp)
  2841. {
  2842. bnx2x_config_mf_bw(bp);
  2843. bnx2x_fw_command(bp, DRV_MSG_CODE_SET_MF_BW_ACK, 0);
  2844. }
  2845. static void bnx2x_handle_eee_event(struct bnx2x *bp)
  2846. {
  2847. DP(BNX2X_MSG_MCP, "EEE - LLDP event\n");
  2848. bnx2x_fw_command(bp, DRV_MSG_CODE_EEE_RESULTS_ACK, 0);
  2849. }
  2850. static void bnx2x_handle_drv_info_req(struct bnx2x *bp)
  2851. {
  2852. enum drv_info_opcode op_code;
  2853. u32 drv_info_ctl = SHMEM2_RD(bp, drv_info_control);
  2854. /* if drv_info version supported by MFW doesn't match - send NACK */
  2855. if ((drv_info_ctl & DRV_INFO_CONTROL_VER_MASK) != DRV_INFO_CUR_VER) {
  2856. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  2857. return;
  2858. }
  2859. op_code = (drv_info_ctl & DRV_INFO_CONTROL_OP_CODE_MASK) >>
  2860. DRV_INFO_CONTROL_OP_CODE_SHIFT;
  2861. memset(&bp->slowpath->drv_info_to_mcp, 0,
  2862. sizeof(union drv_info_to_mcp));
  2863. switch (op_code) {
  2864. case ETH_STATS_OPCODE:
  2865. bnx2x_drv_info_ether_stat(bp);
  2866. break;
  2867. case FCOE_STATS_OPCODE:
  2868. bnx2x_drv_info_fcoe_stat(bp);
  2869. break;
  2870. case ISCSI_STATS_OPCODE:
  2871. bnx2x_drv_info_iscsi_stat(bp);
  2872. break;
  2873. default:
  2874. /* if op code isn't supported - send NACK */
  2875. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  2876. return;
  2877. }
  2878. /* if we got drv_info attn from MFW then these fields are defined in
  2879. * shmem2 for sure
  2880. */
  2881. SHMEM2_WR(bp, drv_info_host_addr_lo,
  2882. U64_LO(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  2883. SHMEM2_WR(bp, drv_info_host_addr_hi,
  2884. U64_HI(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  2885. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_ACK, 0);
  2886. }
  2887. static void bnx2x_dcc_event(struct bnx2x *bp, u32 dcc_event)
  2888. {
  2889. DP(BNX2X_MSG_MCP, "dcc_event 0x%x\n", dcc_event);
  2890. if (dcc_event & DRV_STATUS_DCC_DISABLE_ENABLE_PF) {
  2891. /*
  2892. * This is the only place besides the function initialization
  2893. * where the bp->flags can change so it is done without any
  2894. * locks
  2895. */
  2896. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  2897. DP(BNX2X_MSG_MCP, "mf_cfg function disabled\n");
  2898. bp->flags |= MF_FUNC_DIS;
  2899. bnx2x_e1h_disable(bp);
  2900. } else {
  2901. DP(BNX2X_MSG_MCP, "mf_cfg function enabled\n");
  2902. bp->flags &= ~MF_FUNC_DIS;
  2903. bnx2x_e1h_enable(bp);
  2904. }
  2905. dcc_event &= ~DRV_STATUS_DCC_DISABLE_ENABLE_PF;
  2906. }
  2907. if (dcc_event & DRV_STATUS_DCC_BANDWIDTH_ALLOCATION) {
  2908. bnx2x_config_mf_bw(bp);
  2909. dcc_event &= ~DRV_STATUS_DCC_BANDWIDTH_ALLOCATION;
  2910. }
  2911. /* Report results to MCP */
  2912. if (dcc_event)
  2913. bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_FAILURE, 0);
  2914. else
  2915. bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_OK, 0);
  2916. }
  2917. /* must be called under the spq lock */
  2918. static struct eth_spe *bnx2x_sp_get_next(struct bnx2x *bp)
  2919. {
  2920. struct eth_spe *next_spe = bp->spq_prod_bd;
  2921. if (bp->spq_prod_bd == bp->spq_last_bd) {
  2922. bp->spq_prod_bd = bp->spq;
  2923. bp->spq_prod_idx = 0;
  2924. DP(BNX2X_MSG_SP, "end of spq\n");
  2925. } else {
  2926. bp->spq_prod_bd++;
  2927. bp->spq_prod_idx++;
  2928. }
  2929. return next_spe;
  2930. }
  2931. /* must be called under the spq lock */
  2932. static void bnx2x_sp_prod_update(struct bnx2x *bp)
  2933. {
  2934. int func = BP_FUNC(bp);
  2935. /*
  2936. * Make sure that BD data is updated before writing the producer:
  2937. * BD data is written to the memory, the producer is read from the
  2938. * memory, thus we need a full memory barrier to ensure the ordering.
  2939. */
  2940. mb();
  2941. REG_WR16(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func),
  2942. bp->spq_prod_idx);
  2943. mmiowb();
  2944. }
  2945. /**
  2946. * bnx2x_is_contextless_ramrod - check if the current command ends on EQ
  2947. *
  2948. * @cmd: command to check
  2949. * @cmd_type: command type
  2950. */
  2951. static bool bnx2x_is_contextless_ramrod(int cmd, int cmd_type)
  2952. {
  2953. if ((cmd_type == NONE_CONNECTION_TYPE) ||
  2954. (cmd == RAMROD_CMD_ID_ETH_FORWARD_SETUP) ||
  2955. (cmd == RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES) ||
  2956. (cmd == RAMROD_CMD_ID_ETH_FILTER_RULES) ||
  2957. (cmd == RAMROD_CMD_ID_ETH_MULTICAST_RULES) ||
  2958. (cmd == RAMROD_CMD_ID_ETH_SET_MAC) ||
  2959. (cmd == RAMROD_CMD_ID_ETH_RSS_UPDATE))
  2960. return true;
  2961. else
  2962. return false;
  2963. }
  2964. /**
  2965. * bnx2x_sp_post - place a single command on an SP ring
  2966. *
  2967. * @bp: driver handle
  2968. * @command: command to place (e.g. SETUP, FILTER_RULES, etc.)
  2969. * @cid: SW CID the command is related to
  2970. * @data_hi: command private data address (high 32 bits)
  2971. * @data_lo: command private data address (low 32 bits)
  2972. * @cmd_type: command type (e.g. NONE, ETH)
  2973. *
  2974. * SP data is handled as if it's always an address pair, thus data fields are
  2975. * not swapped to little endian in upper functions. Instead this function swaps
  2976. * data as if it's two u32 fields.
  2977. */
  2978. int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
  2979. u32 data_hi, u32 data_lo, int cmd_type)
  2980. {
  2981. struct eth_spe *spe;
  2982. u16 type;
  2983. bool common = bnx2x_is_contextless_ramrod(command, cmd_type);
  2984. #ifdef BNX2X_STOP_ON_ERROR
  2985. if (unlikely(bp->panic)) {
  2986. BNX2X_ERR("Can't post SP when there is panic\n");
  2987. return -EIO;
  2988. }
  2989. #endif
  2990. spin_lock_bh(&bp->spq_lock);
  2991. if (common) {
  2992. if (!atomic_read(&bp->eq_spq_left)) {
  2993. BNX2X_ERR("BUG! EQ ring full!\n");
  2994. spin_unlock_bh(&bp->spq_lock);
  2995. bnx2x_panic();
  2996. return -EBUSY;
  2997. }
  2998. } else if (!atomic_read(&bp->cq_spq_left)) {
  2999. BNX2X_ERR("BUG! SPQ ring full!\n");
  3000. spin_unlock_bh(&bp->spq_lock);
  3001. bnx2x_panic();
  3002. return -EBUSY;
  3003. }
  3004. spe = bnx2x_sp_get_next(bp);
  3005. /* CID needs port number to be encoded int it */
  3006. spe->hdr.conn_and_cmd_data =
  3007. cpu_to_le32((command << SPE_HDR_CMD_ID_SHIFT) |
  3008. HW_CID(bp, cid));
  3009. type = (cmd_type << SPE_HDR_CONN_TYPE_SHIFT) & SPE_HDR_CONN_TYPE;
  3010. type |= ((BP_FUNC(bp) << SPE_HDR_FUNCTION_ID_SHIFT) &
  3011. SPE_HDR_FUNCTION_ID);
  3012. spe->hdr.type = cpu_to_le16(type);
  3013. spe->data.update_data_addr.hi = cpu_to_le32(data_hi);
  3014. spe->data.update_data_addr.lo = cpu_to_le32(data_lo);
  3015. /*
  3016. * It's ok if the actual decrement is issued towards the memory
  3017. * somewhere between the spin_lock and spin_unlock. Thus no
  3018. * more explict memory barrier is needed.
  3019. */
  3020. if (common)
  3021. atomic_dec(&bp->eq_spq_left);
  3022. else
  3023. atomic_dec(&bp->cq_spq_left);
  3024. DP(BNX2X_MSG_SP,
  3025. "SPQE[%x] (%x:%x) (cmd, common?) (%d,%d) hw_cid %x data (%x:%x) type(0x%x) left (CQ, EQ) (%x,%x)\n",
  3026. bp->spq_prod_idx, (u32)U64_HI(bp->spq_mapping),
  3027. (u32)(U64_LO(bp->spq_mapping) +
  3028. (void *)bp->spq_prod_bd - (void *)bp->spq), command, common,
  3029. HW_CID(bp, cid), data_hi, data_lo, type,
  3030. atomic_read(&bp->cq_spq_left), atomic_read(&bp->eq_spq_left));
  3031. bnx2x_sp_prod_update(bp);
  3032. spin_unlock_bh(&bp->spq_lock);
  3033. return 0;
  3034. }
  3035. /* acquire split MCP access lock register */
  3036. static int bnx2x_acquire_alr(struct bnx2x *bp)
  3037. {
  3038. u32 j, val;
  3039. int rc = 0;
  3040. might_sleep();
  3041. for (j = 0; j < 1000; j++) {
  3042. val = (1UL << 31);
  3043. REG_WR(bp, GRCBASE_MCP + 0x9c, val);
  3044. val = REG_RD(bp, GRCBASE_MCP + 0x9c);
  3045. if (val & (1L << 31))
  3046. break;
  3047. msleep(5);
  3048. }
  3049. if (!(val & (1L << 31))) {
  3050. BNX2X_ERR("Cannot acquire MCP access lock register\n");
  3051. rc = -EBUSY;
  3052. }
  3053. return rc;
  3054. }
  3055. /* release split MCP access lock register */
  3056. static void bnx2x_release_alr(struct bnx2x *bp)
  3057. {
  3058. REG_WR(bp, GRCBASE_MCP + 0x9c, 0);
  3059. }
  3060. #define BNX2X_DEF_SB_ATT_IDX 0x0001
  3061. #define BNX2X_DEF_SB_IDX 0x0002
  3062. static u16 bnx2x_update_dsb_idx(struct bnx2x *bp)
  3063. {
  3064. struct host_sp_status_block *def_sb = bp->def_status_blk;
  3065. u16 rc = 0;
  3066. barrier(); /* status block is written to by the chip */
  3067. if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) {
  3068. bp->def_att_idx = def_sb->atten_status_block.attn_bits_index;
  3069. rc |= BNX2X_DEF_SB_ATT_IDX;
  3070. }
  3071. if (bp->def_idx != def_sb->sp_sb.running_index) {
  3072. bp->def_idx = def_sb->sp_sb.running_index;
  3073. rc |= BNX2X_DEF_SB_IDX;
  3074. }
  3075. /* Do not reorder: indecies reading should complete before handling */
  3076. barrier();
  3077. return rc;
  3078. }
  3079. /*
  3080. * slow path service functions
  3081. */
  3082. static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted)
  3083. {
  3084. int port = BP_PORT(bp);
  3085. u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  3086. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  3087. u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 :
  3088. NIG_REG_MASK_INTERRUPT_PORT0;
  3089. u32 aeu_mask;
  3090. u32 nig_mask = 0;
  3091. u32 reg_addr;
  3092. if (bp->attn_state & asserted)
  3093. BNX2X_ERR("IGU ERROR\n");
  3094. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3095. aeu_mask = REG_RD(bp, aeu_addr);
  3096. DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n",
  3097. aeu_mask, asserted);
  3098. aeu_mask &= ~(asserted & 0x3ff);
  3099. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  3100. REG_WR(bp, aeu_addr, aeu_mask);
  3101. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3102. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  3103. bp->attn_state |= asserted;
  3104. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  3105. if (asserted & ATTN_HARD_WIRED_MASK) {
  3106. if (asserted & ATTN_NIG_FOR_FUNC) {
  3107. bnx2x_acquire_phy_lock(bp);
  3108. /* save nig interrupt mask */
  3109. nig_mask = REG_RD(bp, nig_int_mask_addr);
  3110. /* If nig_mask is not set, no need to call the update
  3111. * function.
  3112. */
  3113. if (nig_mask) {
  3114. REG_WR(bp, nig_int_mask_addr, 0);
  3115. bnx2x_link_attn(bp);
  3116. }
  3117. /* handle unicore attn? */
  3118. }
  3119. if (asserted & ATTN_SW_TIMER_4_FUNC)
  3120. DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n");
  3121. if (asserted & GPIO_2_FUNC)
  3122. DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n");
  3123. if (asserted & GPIO_3_FUNC)
  3124. DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n");
  3125. if (asserted & GPIO_4_FUNC)
  3126. DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n");
  3127. if (port == 0) {
  3128. if (asserted & ATTN_GENERAL_ATTN_1) {
  3129. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n");
  3130. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0);
  3131. }
  3132. if (asserted & ATTN_GENERAL_ATTN_2) {
  3133. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n");
  3134. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0);
  3135. }
  3136. if (asserted & ATTN_GENERAL_ATTN_3) {
  3137. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n");
  3138. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0);
  3139. }
  3140. } else {
  3141. if (asserted & ATTN_GENERAL_ATTN_4) {
  3142. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n");
  3143. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0);
  3144. }
  3145. if (asserted & ATTN_GENERAL_ATTN_5) {
  3146. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n");
  3147. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0);
  3148. }
  3149. if (asserted & ATTN_GENERAL_ATTN_6) {
  3150. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n");
  3151. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0);
  3152. }
  3153. }
  3154. } /* if hardwired */
  3155. if (bp->common.int_block == INT_BLOCK_HC)
  3156. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  3157. COMMAND_REG_ATTN_BITS_SET);
  3158. else
  3159. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_SET_UPPER*8);
  3160. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", asserted,
  3161. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  3162. REG_WR(bp, reg_addr, asserted);
  3163. /* now set back the mask */
  3164. if (asserted & ATTN_NIG_FOR_FUNC) {
  3165. /* Verify that IGU ack through BAR was written before restoring
  3166. * NIG mask. This loop should exit after 2-3 iterations max.
  3167. */
  3168. if (bp->common.int_block != INT_BLOCK_HC) {
  3169. u32 cnt = 0, igu_acked;
  3170. do {
  3171. igu_acked = REG_RD(bp,
  3172. IGU_REG_ATTENTION_ACK_BITS);
  3173. } while (((igu_acked & ATTN_NIG_FOR_FUNC) == 0) &&
  3174. (++cnt < MAX_IGU_ATTN_ACK_TO));
  3175. if (!igu_acked)
  3176. DP(NETIF_MSG_HW,
  3177. "Failed to verify IGU ack on time\n");
  3178. barrier();
  3179. }
  3180. REG_WR(bp, nig_int_mask_addr, nig_mask);
  3181. bnx2x_release_phy_lock(bp);
  3182. }
  3183. }
  3184. static void bnx2x_fan_failure(struct bnx2x *bp)
  3185. {
  3186. int port = BP_PORT(bp);
  3187. u32 ext_phy_config;
  3188. /* mark the failure */
  3189. ext_phy_config =
  3190. SHMEM_RD(bp,
  3191. dev_info.port_hw_config[port].external_phy_config);
  3192. ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
  3193. ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE;
  3194. SHMEM_WR(bp, dev_info.port_hw_config[port].external_phy_config,
  3195. ext_phy_config);
  3196. /* log the failure */
  3197. netdev_err(bp->dev, "Fan Failure on Network Controller has caused the driver to shutdown the card to prevent permanent damage.\n"
  3198. "Please contact OEM Support for assistance\n");
  3199. /*
  3200. * Schedule device reset (unload)
  3201. * This is due to some boards consuming sufficient power when driver is
  3202. * up to overheat if fan fails.
  3203. */
  3204. smp_mb__before_clear_bit();
  3205. set_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state);
  3206. smp_mb__after_clear_bit();
  3207. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  3208. }
  3209. static void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn)
  3210. {
  3211. int port = BP_PORT(bp);
  3212. int reg_offset;
  3213. u32 val;
  3214. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  3215. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  3216. if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) {
  3217. val = REG_RD(bp, reg_offset);
  3218. val &= ~AEU_INPUTS_ATTN_BITS_SPIO5;
  3219. REG_WR(bp, reg_offset, val);
  3220. BNX2X_ERR("SPIO5 hw attention\n");
  3221. /* Fan failure attention */
  3222. bnx2x_hw_reset_phy(&bp->link_params);
  3223. bnx2x_fan_failure(bp);
  3224. }
  3225. if ((attn & bp->link_vars.aeu_int_mask) && bp->port.pmf) {
  3226. bnx2x_acquire_phy_lock(bp);
  3227. bnx2x_handle_module_detect_int(&bp->link_params);
  3228. bnx2x_release_phy_lock(bp);
  3229. }
  3230. if (attn & HW_INTERRUT_ASSERT_SET_0) {
  3231. val = REG_RD(bp, reg_offset);
  3232. val &= ~(attn & HW_INTERRUT_ASSERT_SET_0);
  3233. REG_WR(bp, reg_offset, val);
  3234. BNX2X_ERR("FATAL HW block attention set0 0x%x\n",
  3235. (u32)(attn & HW_INTERRUT_ASSERT_SET_0));
  3236. bnx2x_panic();
  3237. }
  3238. }
  3239. static void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn)
  3240. {
  3241. u32 val;
  3242. if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) {
  3243. val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR);
  3244. BNX2X_ERR("DB hw attention 0x%x\n", val);
  3245. /* DORQ discard attention */
  3246. if (val & 0x2)
  3247. BNX2X_ERR("FATAL error from DORQ\n");
  3248. }
  3249. if (attn & HW_INTERRUT_ASSERT_SET_1) {
  3250. int port = BP_PORT(bp);
  3251. int reg_offset;
  3252. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 :
  3253. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1);
  3254. val = REG_RD(bp, reg_offset);
  3255. val &= ~(attn & HW_INTERRUT_ASSERT_SET_1);
  3256. REG_WR(bp, reg_offset, val);
  3257. BNX2X_ERR("FATAL HW block attention set1 0x%x\n",
  3258. (u32)(attn & HW_INTERRUT_ASSERT_SET_1));
  3259. bnx2x_panic();
  3260. }
  3261. }
  3262. static void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn)
  3263. {
  3264. u32 val;
  3265. if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) {
  3266. val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR);
  3267. BNX2X_ERR("CFC hw attention 0x%x\n", val);
  3268. /* CFC error attention */
  3269. if (val & 0x2)
  3270. BNX2X_ERR("FATAL error from CFC\n");
  3271. }
  3272. if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) {
  3273. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0);
  3274. BNX2X_ERR("PXP hw attention-0 0x%x\n", val);
  3275. /* RQ_USDMDP_FIFO_OVERFLOW */
  3276. if (val & 0x18000)
  3277. BNX2X_ERR("FATAL error from PXP\n");
  3278. if (!CHIP_IS_E1x(bp)) {
  3279. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_1);
  3280. BNX2X_ERR("PXP hw attention-1 0x%x\n", val);
  3281. }
  3282. }
  3283. if (attn & HW_INTERRUT_ASSERT_SET_2) {
  3284. int port = BP_PORT(bp);
  3285. int reg_offset;
  3286. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 :
  3287. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2);
  3288. val = REG_RD(bp, reg_offset);
  3289. val &= ~(attn & HW_INTERRUT_ASSERT_SET_2);
  3290. REG_WR(bp, reg_offset, val);
  3291. BNX2X_ERR("FATAL HW block attention set2 0x%x\n",
  3292. (u32)(attn & HW_INTERRUT_ASSERT_SET_2));
  3293. bnx2x_panic();
  3294. }
  3295. }
  3296. static void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn)
  3297. {
  3298. u32 val;
  3299. if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) {
  3300. if (attn & BNX2X_PMF_LINK_ASSERT) {
  3301. int func = BP_FUNC(bp);
  3302. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  3303. bnx2x_read_mf_cfg(bp);
  3304. bp->mf_config[BP_VN(bp)] = MF_CFG_RD(bp,
  3305. func_mf_config[BP_ABS_FUNC(bp)].config);
  3306. val = SHMEM_RD(bp,
  3307. func_mb[BP_FW_MB_IDX(bp)].drv_status);
  3308. if (val & DRV_STATUS_DCC_EVENT_MASK)
  3309. bnx2x_dcc_event(bp,
  3310. (val & DRV_STATUS_DCC_EVENT_MASK));
  3311. if (val & DRV_STATUS_SET_MF_BW)
  3312. bnx2x_set_mf_bw(bp);
  3313. if (val & DRV_STATUS_DRV_INFO_REQ)
  3314. bnx2x_handle_drv_info_req(bp);
  3315. if (val & DRV_STATUS_VF_DISABLED)
  3316. bnx2x_vf_handle_flr_event(bp);
  3317. if ((bp->port.pmf == 0) && (val & DRV_STATUS_PMF))
  3318. bnx2x_pmf_update(bp);
  3319. if (bp->port.pmf &&
  3320. (val & DRV_STATUS_DCBX_NEGOTIATION_RESULTS) &&
  3321. bp->dcbx_enabled > 0)
  3322. /* start dcbx state machine */
  3323. bnx2x_dcbx_set_params(bp,
  3324. BNX2X_DCBX_STATE_NEG_RECEIVED);
  3325. if (val & DRV_STATUS_AFEX_EVENT_MASK)
  3326. bnx2x_handle_afex_cmd(bp,
  3327. val & DRV_STATUS_AFEX_EVENT_MASK);
  3328. if (val & DRV_STATUS_EEE_NEGOTIATION_RESULTS)
  3329. bnx2x_handle_eee_event(bp);
  3330. if (bp->link_vars.periodic_flags &
  3331. PERIODIC_FLAGS_LINK_EVENT) {
  3332. /* sync with link */
  3333. bnx2x_acquire_phy_lock(bp);
  3334. bp->link_vars.periodic_flags &=
  3335. ~PERIODIC_FLAGS_LINK_EVENT;
  3336. bnx2x_release_phy_lock(bp);
  3337. if (IS_MF(bp))
  3338. bnx2x_link_sync_notify(bp);
  3339. bnx2x_link_report(bp);
  3340. }
  3341. /* Always call it here: bnx2x_link_report() will
  3342. * prevent the link indication duplication.
  3343. */
  3344. bnx2x__link_status_update(bp);
  3345. } else if (attn & BNX2X_MC_ASSERT_BITS) {
  3346. BNX2X_ERR("MC assert!\n");
  3347. bnx2x_mc_assert(bp);
  3348. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0);
  3349. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0);
  3350. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0);
  3351. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0);
  3352. bnx2x_panic();
  3353. } else if (attn & BNX2X_MCP_ASSERT) {
  3354. BNX2X_ERR("MCP assert!\n");
  3355. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0);
  3356. bnx2x_fw_dump(bp);
  3357. } else
  3358. BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn);
  3359. }
  3360. if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) {
  3361. BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn);
  3362. if (attn & BNX2X_GRC_TIMEOUT) {
  3363. val = CHIP_IS_E1(bp) ? 0 :
  3364. REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN);
  3365. BNX2X_ERR("GRC time-out 0x%08x\n", val);
  3366. }
  3367. if (attn & BNX2X_GRC_RSV) {
  3368. val = CHIP_IS_E1(bp) ? 0 :
  3369. REG_RD(bp, MISC_REG_GRC_RSV_ATTN);
  3370. BNX2X_ERR("GRC reserved 0x%08x\n", val);
  3371. }
  3372. REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff);
  3373. }
  3374. }
  3375. /*
  3376. * Bits map:
  3377. * 0-7 - Engine0 load counter.
  3378. * 8-15 - Engine1 load counter.
  3379. * 16 - Engine0 RESET_IN_PROGRESS bit.
  3380. * 17 - Engine1 RESET_IN_PROGRESS bit.
  3381. * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active function
  3382. * on the engine
  3383. * 19 - Engine1 ONE_IS_LOADED.
  3384. * 20 - Chip reset flow bit. When set none-leader must wait for both engines
  3385. * leader to complete (check for both RESET_IN_PROGRESS bits and not for
  3386. * just the one belonging to its engine).
  3387. *
  3388. */
  3389. #define BNX2X_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1
  3390. #define BNX2X_PATH0_LOAD_CNT_MASK 0x000000ff
  3391. #define BNX2X_PATH0_LOAD_CNT_SHIFT 0
  3392. #define BNX2X_PATH1_LOAD_CNT_MASK 0x0000ff00
  3393. #define BNX2X_PATH1_LOAD_CNT_SHIFT 8
  3394. #define BNX2X_PATH0_RST_IN_PROG_BIT 0x00010000
  3395. #define BNX2X_PATH1_RST_IN_PROG_BIT 0x00020000
  3396. #define BNX2X_GLOBAL_RESET_BIT 0x00040000
  3397. /*
  3398. * Set the GLOBAL_RESET bit.
  3399. *
  3400. * Should be run under rtnl lock
  3401. */
  3402. void bnx2x_set_reset_global(struct bnx2x *bp)
  3403. {
  3404. u32 val;
  3405. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3406. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3407. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val | BNX2X_GLOBAL_RESET_BIT);
  3408. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3409. }
  3410. /*
  3411. * Clear the GLOBAL_RESET bit.
  3412. *
  3413. * Should be run under rtnl lock
  3414. */
  3415. static void bnx2x_clear_reset_global(struct bnx2x *bp)
  3416. {
  3417. u32 val;
  3418. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3419. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3420. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~BNX2X_GLOBAL_RESET_BIT));
  3421. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3422. }
  3423. /*
  3424. * Checks the GLOBAL_RESET bit.
  3425. *
  3426. * should be run under rtnl lock
  3427. */
  3428. static bool bnx2x_reset_is_global(struct bnx2x *bp)
  3429. {
  3430. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3431. DP(NETIF_MSG_HW, "GEN_REG_VAL=0x%08x\n", val);
  3432. return (val & BNX2X_GLOBAL_RESET_BIT) ? true : false;
  3433. }
  3434. /*
  3435. * Clear RESET_IN_PROGRESS bit for the current engine.
  3436. *
  3437. * Should be run under rtnl lock
  3438. */
  3439. static void bnx2x_set_reset_done(struct bnx2x *bp)
  3440. {
  3441. u32 val;
  3442. u32 bit = BP_PATH(bp) ?
  3443. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3444. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3445. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3446. /* Clear the bit */
  3447. val &= ~bit;
  3448. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3449. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3450. }
  3451. /*
  3452. * Set RESET_IN_PROGRESS for the current engine.
  3453. *
  3454. * should be run under rtnl lock
  3455. */
  3456. void bnx2x_set_reset_in_progress(struct bnx2x *bp)
  3457. {
  3458. u32 val;
  3459. u32 bit = BP_PATH(bp) ?
  3460. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3461. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3462. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3463. /* Set the bit */
  3464. val |= bit;
  3465. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3466. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3467. }
  3468. /*
  3469. * Checks the RESET_IN_PROGRESS bit for the given engine.
  3470. * should be run under rtnl lock
  3471. */
  3472. bool bnx2x_reset_is_done(struct bnx2x *bp, int engine)
  3473. {
  3474. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3475. u32 bit = engine ?
  3476. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3477. /* return false if bit is set */
  3478. return (val & bit) ? false : true;
  3479. }
  3480. /*
  3481. * set pf load for the current pf.
  3482. *
  3483. * should be run under rtnl lock
  3484. */
  3485. void bnx2x_set_pf_load(struct bnx2x *bp)
  3486. {
  3487. u32 val1, val;
  3488. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3489. BNX2X_PATH0_LOAD_CNT_MASK;
  3490. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3491. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3492. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3493. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3494. DP(NETIF_MSG_IFUP, "Old GEN_REG_VAL=0x%08x\n", val);
  3495. /* get the current counter value */
  3496. val1 = (val & mask) >> shift;
  3497. /* set bit of that PF */
  3498. val1 |= (1 << bp->pf_num);
  3499. /* clear the old value */
  3500. val &= ~mask;
  3501. /* set the new one */
  3502. val |= ((val1 << shift) & mask);
  3503. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3504. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3505. }
  3506. /**
  3507. * bnx2x_clear_pf_load - clear pf load mark
  3508. *
  3509. * @bp: driver handle
  3510. *
  3511. * Should be run under rtnl lock.
  3512. * Decrements the load counter for the current engine. Returns
  3513. * whether other functions are still loaded
  3514. */
  3515. bool bnx2x_clear_pf_load(struct bnx2x *bp)
  3516. {
  3517. u32 val1, val;
  3518. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3519. BNX2X_PATH0_LOAD_CNT_MASK;
  3520. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3521. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3522. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3523. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3524. DP(NETIF_MSG_IFDOWN, "Old GEN_REG_VAL=0x%08x\n", val);
  3525. /* get the current counter value */
  3526. val1 = (val & mask) >> shift;
  3527. /* clear bit of that PF */
  3528. val1 &= ~(1 << bp->pf_num);
  3529. /* clear the old value */
  3530. val &= ~mask;
  3531. /* set the new one */
  3532. val |= ((val1 << shift) & mask);
  3533. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3534. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3535. return val1 != 0;
  3536. }
  3537. /*
  3538. * Read the load status for the current engine.
  3539. *
  3540. * should be run under rtnl lock
  3541. */
  3542. static bool bnx2x_get_load_status(struct bnx2x *bp, int engine)
  3543. {
  3544. u32 mask = (engine ? BNX2X_PATH1_LOAD_CNT_MASK :
  3545. BNX2X_PATH0_LOAD_CNT_MASK);
  3546. u32 shift = (engine ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3547. BNX2X_PATH0_LOAD_CNT_SHIFT);
  3548. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3549. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "GLOB_REG=0x%08x\n", val);
  3550. val = (val & mask) >> shift;
  3551. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "load mask for engine %d = 0x%x\n",
  3552. engine, val);
  3553. return val != 0;
  3554. }
  3555. static void _print_next_block(int idx, const char *blk)
  3556. {
  3557. pr_cont("%s%s", idx ? ", " : "", blk);
  3558. }
  3559. static int bnx2x_check_blocks_with_parity0(u32 sig, int par_num,
  3560. bool print)
  3561. {
  3562. int i = 0;
  3563. u32 cur_bit = 0;
  3564. for (i = 0; sig; i++) {
  3565. cur_bit = ((u32)0x1 << i);
  3566. if (sig & cur_bit) {
  3567. switch (cur_bit) {
  3568. case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR:
  3569. if (print)
  3570. _print_next_block(par_num++, "BRB");
  3571. break;
  3572. case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR:
  3573. if (print)
  3574. _print_next_block(par_num++, "PARSER");
  3575. break;
  3576. case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR:
  3577. if (print)
  3578. _print_next_block(par_num++, "TSDM");
  3579. break;
  3580. case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR:
  3581. if (print)
  3582. _print_next_block(par_num++,
  3583. "SEARCHER");
  3584. break;
  3585. case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR:
  3586. if (print)
  3587. _print_next_block(par_num++, "TCM");
  3588. break;
  3589. case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR:
  3590. if (print)
  3591. _print_next_block(par_num++, "TSEMI");
  3592. break;
  3593. case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR:
  3594. if (print)
  3595. _print_next_block(par_num++, "XPB");
  3596. break;
  3597. }
  3598. /* Clear the bit */
  3599. sig &= ~cur_bit;
  3600. }
  3601. }
  3602. return par_num;
  3603. }
  3604. static int bnx2x_check_blocks_with_parity1(u32 sig, int par_num,
  3605. bool *global, bool print)
  3606. {
  3607. int i = 0;
  3608. u32 cur_bit = 0;
  3609. for (i = 0; sig; i++) {
  3610. cur_bit = ((u32)0x1 << i);
  3611. if (sig & cur_bit) {
  3612. switch (cur_bit) {
  3613. case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR:
  3614. if (print)
  3615. _print_next_block(par_num++, "PBF");
  3616. break;
  3617. case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR:
  3618. if (print)
  3619. _print_next_block(par_num++, "QM");
  3620. break;
  3621. case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR:
  3622. if (print)
  3623. _print_next_block(par_num++, "TM");
  3624. break;
  3625. case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR:
  3626. if (print)
  3627. _print_next_block(par_num++, "XSDM");
  3628. break;
  3629. case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR:
  3630. if (print)
  3631. _print_next_block(par_num++, "XCM");
  3632. break;
  3633. case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR:
  3634. if (print)
  3635. _print_next_block(par_num++, "XSEMI");
  3636. break;
  3637. case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR:
  3638. if (print)
  3639. _print_next_block(par_num++,
  3640. "DOORBELLQ");
  3641. break;
  3642. case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR:
  3643. if (print)
  3644. _print_next_block(par_num++, "NIG");
  3645. break;
  3646. case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR:
  3647. if (print)
  3648. _print_next_block(par_num++,
  3649. "VAUX PCI CORE");
  3650. *global = true;
  3651. break;
  3652. case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR:
  3653. if (print)
  3654. _print_next_block(par_num++, "DEBUG");
  3655. break;
  3656. case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR:
  3657. if (print)
  3658. _print_next_block(par_num++, "USDM");
  3659. break;
  3660. case AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR:
  3661. if (print)
  3662. _print_next_block(par_num++, "UCM");
  3663. break;
  3664. case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR:
  3665. if (print)
  3666. _print_next_block(par_num++, "USEMI");
  3667. break;
  3668. case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR:
  3669. if (print)
  3670. _print_next_block(par_num++, "UPB");
  3671. break;
  3672. case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR:
  3673. if (print)
  3674. _print_next_block(par_num++, "CSDM");
  3675. break;
  3676. case AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR:
  3677. if (print)
  3678. _print_next_block(par_num++, "CCM");
  3679. break;
  3680. }
  3681. /* Clear the bit */
  3682. sig &= ~cur_bit;
  3683. }
  3684. }
  3685. return par_num;
  3686. }
  3687. static int bnx2x_check_blocks_with_parity2(u32 sig, int par_num,
  3688. bool print)
  3689. {
  3690. int i = 0;
  3691. u32 cur_bit = 0;
  3692. for (i = 0; sig; i++) {
  3693. cur_bit = ((u32)0x1 << i);
  3694. if (sig & cur_bit) {
  3695. switch (cur_bit) {
  3696. case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR:
  3697. if (print)
  3698. _print_next_block(par_num++, "CSEMI");
  3699. break;
  3700. case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR:
  3701. if (print)
  3702. _print_next_block(par_num++, "PXP");
  3703. break;
  3704. case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR:
  3705. if (print)
  3706. _print_next_block(par_num++,
  3707. "PXPPCICLOCKCLIENT");
  3708. break;
  3709. case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR:
  3710. if (print)
  3711. _print_next_block(par_num++, "CFC");
  3712. break;
  3713. case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR:
  3714. if (print)
  3715. _print_next_block(par_num++, "CDU");
  3716. break;
  3717. case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR:
  3718. if (print)
  3719. _print_next_block(par_num++, "DMAE");
  3720. break;
  3721. case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR:
  3722. if (print)
  3723. _print_next_block(par_num++, "IGU");
  3724. break;
  3725. case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR:
  3726. if (print)
  3727. _print_next_block(par_num++, "MISC");
  3728. break;
  3729. }
  3730. /* Clear the bit */
  3731. sig &= ~cur_bit;
  3732. }
  3733. }
  3734. return par_num;
  3735. }
  3736. static int bnx2x_check_blocks_with_parity3(u32 sig, int par_num,
  3737. bool *global, bool print)
  3738. {
  3739. int i = 0;
  3740. u32 cur_bit = 0;
  3741. for (i = 0; sig; i++) {
  3742. cur_bit = ((u32)0x1 << i);
  3743. if (sig & cur_bit) {
  3744. switch (cur_bit) {
  3745. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY:
  3746. if (print)
  3747. _print_next_block(par_num++, "MCP ROM");
  3748. *global = true;
  3749. break;
  3750. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY:
  3751. if (print)
  3752. _print_next_block(par_num++,
  3753. "MCP UMP RX");
  3754. *global = true;
  3755. break;
  3756. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY:
  3757. if (print)
  3758. _print_next_block(par_num++,
  3759. "MCP UMP TX");
  3760. *global = true;
  3761. break;
  3762. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY:
  3763. if (print)
  3764. _print_next_block(par_num++,
  3765. "MCP SCPAD");
  3766. *global = true;
  3767. break;
  3768. }
  3769. /* Clear the bit */
  3770. sig &= ~cur_bit;
  3771. }
  3772. }
  3773. return par_num;
  3774. }
  3775. static int bnx2x_check_blocks_with_parity4(u32 sig, int par_num,
  3776. bool print)
  3777. {
  3778. int i = 0;
  3779. u32 cur_bit = 0;
  3780. for (i = 0; sig; i++) {
  3781. cur_bit = ((u32)0x1 << i);
  3782. if (sig & cur_bit) {
  3783. switch (cur_bit) {
  3784. case AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR:
  3785. if (print)
  3786. _print_next_block(par_num++, "PGLUE_B");
  3787. break;
  3788. case AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR:
  3789. if (print)
  3790. _print_next_block(par_num++, "ATC");
  3791. break;
  3792. }
  3793. /* Clear the bit */
  3794. sig &= ~cur_bit;
  3795. }
  3796. }
  3797. return par_num;
  3798. }
  3799. static bool bnx2x_parity_attn(struct bnx2x *bp, bool *global, bool print,
  3800. u32 *sig)
  3801. {
  3802. if ((sig[0] & HW_PRTY_ASSERT_SET_0) ||
  3803. (sig[1] & HW_PRTY_ASSERT_SET_1) ||
  3804. (sig[2] & HW_PRTY_ASSERT_SET_2) ||
  3805. (sig[3] & HW_PRTY_ASSERT_SET_3) ||
  3806. (sig[4] & HW_PRTY_ASSERT_SET_4)) {
  3807. int par_num = 0;
  3808. DP(NETIF_MSG_HW, "Was parity error: HW block parity attention:\n"
  3809. "[0]:0x%08x [1]:0x%08x [2]:0x%08x [3]:0x%08x [4]:0x%08x\n",
  3810. sig[0] & HW_PRTY_ASSERT_SET_0,
  3811. sig[1] & HW_PRTY_ASSERT_SET_1,
  3812. sig[2] & HW_PRTY_ASSERT_SET_2,
  3813. sig[3] & HW_PRTY_ASSERT_SET_3,
  3814. sig[4] & HW_PRTY_ASSERT_SET_4);
  3815. if (print)
  3816. netdev_err(bp->dev,
  3817. "Parity errors detected in blocks: ");
  3818. par_num = bnx2x_check_blocks_with_parity0(
  3819. sig[0] & HW_PRTY_ASSERT_SET_0, par_num, print);
  3820. par_num = bnx2x_check_blocks_with_parity1(
  3821. sig[1] & HW_PRTY_ASSERT_SET_1, par_num, global, print);
  3822. par_num = bnx2x_check_blocks_with_parity2(
  3823. sig[2] & HW_PRTY_ASSERT_SET_2, par_num, print);
  3824. par_num = bnx2x_check_blocks_with_parity3(
  3825. sig[3] & HW_PRTY_ASSERT_SET_3, par_num, global, print);
  3826. par_num = bnx2x_check_blocks_with_parity4(
  3827. sig[4] & HW_PRTY_ASSERT_SET_4, par_num, print);
  3828. if (print)
  3829. pr_cont("\n");
  3830. return true;
  3831. } else
  3832. return false;
  3833. }
  3834. /**
  3835. * bnx2x_chk_parity_attn - checks for parity attentions.
  3836. *
  3837. * @bp: driver handle
  3838. * @global: true if there was a global attention
  3839. * @print: show parity attention in syslog
  3840. */
  3841. bool bnx2x_chk_parity_attn(struct bnx2x *bp, bool *global, bool print)
  3842. {
  3843. struct attn_route attn = { {0} };
  3844. int port = BP_PORT(bp);
  3845. attn.sig[0] = REG_RD(bp,
  3846. MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 +
  3847. port*4);
  3848. attn.sig[1] = REG_RD(bp,
  3849. MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 +
  3850. port*4);
  3851. attn.sig[2] = REG_RD(bp,
  3852. MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 +
  3853. port*4);
  3854. attn.sig[3] = REG_RD(bp,
  3855. MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 +
  3856. port*4);
  3857. if (!CHIP_IS_E1x(bp))
  3858. attn.sig[4] = REG_RD(bp,
  3859. MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 +
  3860. port*4);
  3861. return bnx2x_parity_attn(bp, global, print, attn.sig);
  3862. }
  3863. static void bnx2x_attn_int_deasserted4(struct bnx2x *bp, u32 attn)
  3864. {
  3865. u32 val;
  3866. if (attn & AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT) {
  3867. val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS_CLR);
  3868. BNX2X_ERR("PGLUE hw attention 0x%x\n", val);
  3869. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR)
  3870. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR\n");
  3871. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR)
  3872. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR\n");
  3873. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN)
  3874. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN\n");
  3875. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN)
  3876. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN\n");
  3877. if (val &
  3878. PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN)
  3879. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN\n");
  3880. if (val &
  3881. PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN)
  3882. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN\n");
  3883. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN)
  3884. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN\n");
  3885. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN)
  3886. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN\n");
  3887. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW)
  3888. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW\n");
  3889. }
  3890. if (attn & AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT) {
  3891. val = REG_RD(bp, ATC_REG_ATC_INT_STS_CLR);
  3892. BNX2X_ERR("ATC hw attention 0x%x\n", val);
  3893. if (val & ATC_ATC_INT_STS_REG_ADDRESS_ERROR)
  3894. BNX2X_ERR("ATC_ATC_INT_STS_REG_ADDRESS_ERROR\n");
  3895. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND)
  3896. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND\n");
  3897. if (val & ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS)
  3898. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS\n");
  3899. if (val & ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT)
  3900. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT\n");
  3901. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR)
  3902. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR\n");
  3903. if (val & ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU)
  3904. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU\n");
  3905. }
  3906. if (attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  3907. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)) {
  3908. BNX2X_ERR("FATAL parity attention set4 0x%x\n",
  3909. (u32)(attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  3910. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)));
  3911. }
  3912. }
  3913. static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted)
  3914. {
  3915. struct attn_route attn, *group_mask;
  3916. int port = BP_PORT(bp);
  3917. int index;
  3918. u32 reg_addr;
  3919. u32 val;
  3920. u32 aeu_mask;
  3921. bool global = false;
  3922. /* need to take HW lock because MCP or other port might also
  3923. try to handle this event */
  3924. bnx2x_acquire_alr(bp);
  3925. if (bnx2x_chk_parity_attn(bp, &global, true)) {
  3926. #ifndef BNX2X_STOP_ON_ERROR
  3927. bp->recovery_state = BNX2X_RECOVERY_INIT;
  3928. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  3929. /* Disable HW interrupts */
  3930. bnx2x_int_disable(bp);
  3931. /* In case of parity errors don't handle attentions so that
  3932. * other function would "see" parity errors.
  3933. */
  3934. #else
  3935. bnx2x_panic();
  3936. #endif
  3937. bnx2x_release_alr(bp);
  3938. return;
  3939. }
  3940. attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
  3941. attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
  3942. attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
  3943. attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
  3944. if (!CHIP_IS_E1x(bp))
  3945. attn.sig[4] =
  3946. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4);
  3947. else
  3948. attn.sig[4] = 0;
  3949. DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x %08x\n",
  3950. attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3], attn.sig[4]);
  3951. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  3952. if (deasserted & (1 << index)) {
  3953. group_mask = &bp->attn_group[index];
  3954. DP(NETIF_MSG_HW, "group[%d]: %08x %08x %08x %08x %08x\n",
  3955. index,
  3956. group_mask->sig[0], group_mask->sig[1],
  3957. group_mask->sig[2], group_mask->sig[3],
  3958. group_mask->sig[4]);
  3959. bnx2x_attn_int_deasserted4(bp,
  3960. attn.sig[4] & group_mask->sig[4]);
  3961. bnx2x_attn_int_deasserted3(bp,
  3962. attn.sig[3] & group_mask->sig[3]);
  3963. bnx2x_attn_int_deasserted1(bp,
  3964. attn.sig[1] & group_mask->sig[1]);
  3965. bnx2x_attn_int_deasserted2(bp,
  3966. attn.sig[2] & group_mask->sig[2]);
  3967. bnx2x_attn_int_deasserted0(bp,
  3968. attn.sig[0] & group_mask->sig[0]);
  3969. }
  3970. }
  3971. bnx2x_release_alr(bp);
  3972. if (bp->common.int_block == INT_BLOCK_HC)
  3973. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  3974. COMMAND_REG_ATTN_BITS_CLR);
  3975. else
  3976. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_CLR_UPPER*8);
  3977. val = ~deasserted;
  3978. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", val,
  3979. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  3980. REG_WR(bp, reg_addr, val);
  3981. if (~bp->attn_state & deasserted)
  3982. BNX2X_ERR("IGU ERROR\n");
  3983. reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  3984. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  3985. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3986. aeu_mask = REG_RD(bp, reg_addr);
  3987. DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n",
  3988. aeu_mask, deasserted);
  3989. aeu_mask |= (deasserted & 0x3ff);
  3990. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  3991. REG_WR(bp, reg_addr, aeu_mask);
  3992. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3993. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  3994. bp->attn_state &= ~deasserted;
  3995. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  3996. }
  3997. static void bnx2x_attn_int(struct bnx2x *bp)
  3998. {
  3999. /* read local copy of bits */
  4000. u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block.
  4001. attn_bits);
  4002. u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block.
  4003. attn_bits_ack);
  4004. u32 attn_state = bp->attn_state;
  4005. /* look for changed bits */
  4006. u32 asserted = attn_bits & ~attn_ack & ~attn_state;
  4007. u32 deasserted = ~attn_bits & attn_ack & attn_state;
  4008. DP(NETIF_MSG_HW,
  4009. "attn_bits %x attn_ack %x asserted %x deasserted %x\n",
  4010. attn_bits, attn_ack, asserted, deasserted);
  4011. if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state))
  4012. BNX2X_ERR("BAD attention state\n");
  4013. /* handle bits that were raised */
  4014. if (asserted)
  4015. bnx2x_attn_int_asserted(bp, asserted);
  4016. if (deasserted)
  4017. bnx2x_attn_int_deasserted(bp, deasserted);
  4018. }
  4019. void bnx2x_igu_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 segment,
  4020. u16 index, u8 op, u8 update)
  4021. {
  4022. u32 igu_addr = bp->igu_base_addr;
  4023. igu_addr += (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8;
  4024. bnx2x_igu_ack_sb_gen(bp, igu_sb_id, segment, index, op, update,
  4025. igu_addr);
  4026. }
  4027. static void bnx2x_update_eq_prod(struct bnx2x *bp, u16 prod)
  4028. {
  4029. /* No memory barriers */
  4030. storm_memset_eq_prod(bp, prod, BP_FUNC(bp));
  4031. mmiowb(); /* keep prod updates ordered */
  4032. }
  4033. static int bnx2x_cnic_handle_cfc_del(struct bnx2x *bp, u32 cid,
  4034. union event_ring_elem *elem)
  4035. {
  4036. u8 err = elem->message.error;
  4037. if (!bp->cnic_eth_dev.starting_cid ||
  4038. (cid < bp->cnic_eth_dev.starting_cid &&
  4039. cid != bp->cnic_eth_dev.iscsi_l2_cid))
  4040. return 1;
  4041. DP(BNX2X_MSG_SP, "got delete ramrod for CNIC CID %d\n", cid);
  4042. if (unlikely(err)) {
  4043. BNX2X_ERR("got delete ramrod for CNIC CID %d with error!\n",
  4044. cid);
  4045. bnx2x_panic_dump(bp, false);
  4046. }
  4047. bnx2x_cnic_cfc_comp(bp, cid, err);
  4048. return 0;
  4049. }
  4050. static void bnx2x_handle_mcast_eqe(struct bnx2x *bp)
  4051. {
  4052. struct bnx2x_mcast_ramrod_params rparam;
  4053. int rc;
  4054. memset(&rparam, 0, sizeof(rparam));
  4055. rparam.mcast_obj = &bp->mcast_obj;
  4056. netif_addr_lock_bh(bp->dev);
  4057. /* Clear pending state for the last command */
  4058. bp->mcast_obj.raw.clear_pending(&bp->mcast_obj.raw);
  4059. /* If there are pending mcast commands - send them */
  4060. if (bp->mcast_obj.check_pending(&bp->mcast_obj)) {
  4061. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT);
  4062. if (rc < 0)
  4063. BNX2X_ERR("Failed to send pending mcast commands: %d\n",
  4064. rc);
  4065. }
  4066. netif_addr_unlock_bh(bp->dev);
  4067. }
  4068. static void bnx2x_handle_classification_eqe(struct bnx2x *bp,
  4069. union event_ring_elem *elem)
  4070. {
  4071. unsigned long ramrod_flags = 0;
  4072. int rc = 0;
  4073. u32 cid = elem->message.data.eth_event.echo & BNX2X_SWCID_MASK;
  4074. struct bnx2x_vlan_mac_obj *vlan_mac_obj;
  4075. /* Always push next commands out, don't wait here */
  4076. __set_bit(RAMROD_CONT, &ramrod_flags);
  4077. switch (le32_to_cpu((__force __le32)elem->message.data.eth_event.echo)
  4078. >> BNX2X_SWCID_SHIFT) {
  4079. case BNX2X_FILTER_MAC_PENDING:
  4080. DP(BNX2X_MSG_SP, "Got SETUP_MAC completions\n");
  4081. if (CNIC_LOADED(bp) && (cid == BNX2X_ISCSI_ETH_CID(bp)))
  4082. vlan_mac_obj = &bp->iscsi_l2_mac_obj;
  4083. else
  4084. vlan_mac_obj = &bp->sp_objs[cid].mac_obj;
  4085. break;
  4086. case BNX2X_FILTER_MCAST_PENDING:
  4087. DP(BNX2X_MSG_SP, "Got SETUP_MCAST completions\n");
  4088. /* This is only relevant for 57710 where multicast MACs are
  4089. * configured as unicast MACs using the same ramrod.
  4090. */
  4091. bnx2x_handle_mcast_eqe(bp);
  4092. return;
  4093. default:
  4094. BNX2X_ERR("Unsupported classification command: %d\n",
  4095. elem->message.data.eth_event.echo);
  4096. return;
  4097. }
  4098. rc = vlan_mac_obj->complete(bp, vlan_mac_obj, elem, &ramrod_flags);
  4099. if (rc < 0)
  4100. BNX2X_ERR("Failed to schedule new commands: %d\n", rc);
  4101. else if (rc > 0)
  4102. DP(BNX2X_MSG_SP, "Scheduled next pending commands...\n");
  4103. }
  4104. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start);
  4105. static void bnx2x_handle_rx_mode_eqe(struct bnx2x *bp)
  4106. {
  4107. netif_addr_lock_bh(bp->dev);
  4108. clear_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  4109. /* Send rx_mode command again if was requested */
  4110. if (test_and_clear_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state))
  4111. bnx2x_set_storm_rx_mode(bp);
  4112. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED,
  4113. &bp->sp_state))
  4114. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  4115. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED,
  4116. &bp->sp_state))
  4117. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  4118. netif_addr_unlock_bh(bp->dev);
  4119. }
  4120. static void bnx2x_after_afex_vif_lists(struct bnx2x *bp,
  4121. union event_ring_elem *elem)
  4122. {
  4123. if (elem->message.data.vif_list_event.echo == VIF_LIST_RULE_GET) {
  4124. DP(BNX2X_MSG_SP,
  4125. "afex: ramrod completed VIF LIST_GET, addrs 0x%x\n",
  4126. elem->message.data.vif_list_event.func_bit_map);
  4127. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTGET_ACK,
  4128. elem->message.data.vif_list_event.func_bit_map);
  4129. } else if (elem->message.data.vif_list_event.echo ==
  4130. VIF_LIST_RULE_SET) {
  4131. DP(BNX2X_MSG_SP, "afex: ramrod completed VIF LIST_SET\n");
  4132. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTSET_ACK, 0);
  4133. }
  4134. }
  4135. /* called with rtnl_lock */
  4136. static void bnx2x_after_function_update(struct bnx2x *bp)
  4137. {
  4138. int q, rc;
  4139. struct bnx2x_fastpath *fp;
  4140. struct bnx2x_queue_state_params queue_params = {NULL};
  4141. struct bnx2x_queue_update_params *q_update_params =
  4142. &queue_params.params.update;
  4143. /* Send Q update command with afex vlan removal values for all Qs */
  4144. queue_params.cmd = BNX2X_Q_CMD_UPDATE;
  4145. /* set silent vlan removal values according to vlan mode */
  4146. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM_CHNG,
  4147. &q_update_params->update_flags);
  4148. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM,
  4149. &q_update_params->update_flags);
  4150. __set_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
  4151. /* in access mode mark mask and value are 0 to strip all vlans */
  4152. if (bp->afex_vlan_mode == FUNC_MF_CFG_AFEX_VLAN_ACCESS_MODE) {
  4153. q_update_params->silent_removal_value = 0;
  4154. q_update_params->silent_removal_mask = 0;
  4155. } else {
  4156. q_update_params->silent_removal_value =
  4157. (bp->afex_def_vlan_tag & VLAN_VID_MASK);
  4158. q_update_params->silent_removal_mask = VLAN_VID_MASK;
  4159. }
  4160. for_each_eth_queue(bp, q) {
  4161. /* Set the appropriate Queue object */
  4162. fp = &bp->fp[q];
  4163. queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  4164. /* send the ramrod */
  4165. rc = bnx2x_queue_state_change(bp, &queue_params);
  4166. if (rc < 0)
  4167. BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
  4168. q);
  4169. }
  4170. if (!NO_FCOE(bp) && CNIC_ENABLED(bp)) {
  4171. fp = &bp->fp[FCOE_IDX(bp)];
  4172. queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  4173. /* clear pending completion bit */
  4174. __clear_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
  4175. /* mark latest Q bit */
  4176. smp_mb__before_clear_bit();
  4177. set_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
  4178. smp_mb__after_clear_bit();
  4179. /* send Q update ramrod for FCoE Q */
  4180. rc = bnx2x_queue_state_change(bp, &queue_params);
  4181. if (rc < 0)
  4182. BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
  4183. q);
  4184. } else {
  4185. /* If no FCoE ring - ACK MCP now */
  4186. bnx2x_link_report(bp);
  4187. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  4188. }
  4189. }
  4190. static struct bnx2x_queue_sp_obj *bnx2x_cid_to_q_obj(
  4191. struct bnx2x *bp, u32 cid)
  4192. {
  4193. DP(BNX2X_MSG_SP, "retrieving fp from cid %d\n", cid);
  4194. if (CNIC_LOADED(bp) && (cid == BNX2X_FCOE_ETH_CID(bp)))
  4195. return &bnx2x_fcoe_sp_obj(bp, q_obj);
  4196. else
  4197. return &bp->sp_objs[CID_TO_FP(cid, bp)].q_obj;
  4198. }
  4199. static void bnx2x_eq_int(struct bnx2x *bp)
  4200. {
  4201. u16 hw_cons, sw_cons, sw_prod;
  4202. union event_ring_elem *elem;
  4203. u8 echo;
  4204. u32 cid;
  4205. u8 opcode;
  4206. int rc, spqe_cnt = 0;
  4207. struct bnx2x_queue_sp_obj *q_obj;
  4208. struct bnx2x_func_sp_obj *f_obj = &bp->func_obj;
  4209. struct bnx2x_raw_obj *rss_raw = &bp->rss_conf_obj.raw;
  4210. hw_cons = le16_to_cpu(*bp->eq_cons_sb);
  4211. /* The hw_cos range is 1-255, 257 - the sw_cons range is 0-254, 256.
  4212. * when we get the the next-page we nned to adjust so the loop
  4213. * condition below will be met. The next element is the size of a
  4214. * regular element and hence incrementing by 1
  4215. */
  4216. if ((hw_cons & EQ_DESC_MAX_PAGE) == EQ_DESC_MAX_PAGE)
  4217. hw_cons++;
  4218. /* This function may never run in parallel with itself for a
  4219. * specific bp, thus there is no need in "paired" read memory
  4220. * barrier here.
  4221. */
  4222. sw_cons = bp->eq_cons;
  4223. sw_prod = bp->eq_prod;
  4224. DP(BNX2X_MSG_SP, "EQ: hw_cons %u sw_cons %u bp->eq_spq_left %x\n",
  4225. hw_cons, sw_cons, atomic_read(&bp->eq_spq_left));
  4226. for (; sw_cons != hw_cons;
  4227. sw_prod = NEXT_EQ_IDX(sw_prod), sw_cons = NEXT_EQ_IDX(sw_cons)) {
  4228. elem = &bp->eq_ring[EQ_DESC(sw_cons)];
  4229. rc = bnx2x_iov_eq_sp_event(bp, elem);
  4230. if (!rc) {
  4231. DP(BNX2X_MSG_IOV, "bnx2x_iov_eq_sp_event returned %d\n",
  4232. rc);
  4233. goto next_spqe;
  4234. }
  4235. /* elem CID originates from FW; actually LE */
  4236. cid = SW_CID((__force __le32)
  4237. elem->message.data.cfc_del_event.cid);
  4238. opcode = elem->message.opcode;
  4239. /* handle eq element */
  4240. switch (opcode) {
  4241. case EVENT_RING_OPCODE_VF_PF_CHANNEL:
  4242. DP(BNX2X_MSG_IOV, "vf pf channel element on eq\n");
  4243. bnx2x_vf_mbx(bp, &elem->message.data.vf_pf_event);
  4244. continue;
  4245. case EVENT_RING_OPCODE_STAT_QUERY:
  4246. DP(BNX2X_MSG_SP | BNX2X_MSG_STATS,
  4247. "got statistics comp event %d\n",
  4248. bp->stats_comp++);
  4249. /* nothing to do with stats comp */
  4250. goto next_spqe;
  4251. case EVENT_RING_OPCODE_CFC_DEL:
  4252. /* handle according to cid range */
  4253. /*
  4254. * we may want to verify here that the bp state is
  4255. * HALTING
  4256. */
  4257. DP(BNX2X_MSG_SP,
  4258. "got delete ramrod for MULTI[%d]\n", cid);
  4259. if (CNIC_LOADED(bp) &&
  4260. !bnx2x_cnic_handle_cfc_del(bp, cid, elem))
  4261. goto next_spqe;
  4262. q_obj = bnx2x_cid_to_q_obj(bp, cid);
  4263. if (q_obj->complete_cmd(bp, q_obj, BNX2X_Q_CMD_CFC_DEL))
  4264. break;
  4265. goto next_spqe;
  4266. case EVENT_RING_OPCODE_STOP_TRAFFIC:
  4267. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got STOP TRAFFIC\n");
  4268. if (f_obj->complete_cmd(bp, f_obj,
  4269. BNX2X_F_CMD_TX_STOP))
  4270. break;
  4271. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_PAUSED);
  4272. goto next_spqe;
  4273. case EVENT_RING_OPCODE_START_TRAFFIC:
  4274. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got START TRAFFIC\n");
  4275. if (f_obj->complete_cmd(bp, f_obj,
  4276. BNX2X_F_CMD_TX_START))
  4277. break;
  4278. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_RELEASED);
  4279. goto next_spqe;
  4280. case EVENT_RING_OPCODE_FUNCTION_UPDATE:
  4281. echo = elem->message.data.function_update_event.echo;
  4282. if (echo == SWITCH_UPDATE) {
  4283. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4284. "got FUNC_SWITCH_UPDATE ramrod\n");
  4285. if (f_obj->complete_cmd(
  4286. bp, f_obj, BNX2X_F_CMD_SWITCH_UPDATE))
  4287. break;
  4288. } else {
  4289. DP(BNX2X_MSG_SP | BNX2X_MSG_MCP,
  4290. "AFEX: ramrod completed FUNCTION_UPDATE\n");
  4291. f_obj->complete_cmd(bp, f_obj,
  4292. BNX2X_F_CMD_AFEX_UPDATE);
  4293. /* We will perform the Queues update from
  4294. * sp_rtnl task as all Queue SP operations
  4295. * should run under rtnl_lock.
  4296. */
  4297. smp_mb__before_clear_bit();
  4298. set_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE,
  4299. &bp->sp_rtnl_state);
  4300. smp_mb__after_clear_bit();
  4301. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  4302. }
  4303. goto next_spqe;
  4304. case EVENT_RING_OPCODE_AFEX_VIF_LISTS:
  4305. f_obj->complete_cmd(bp, f_obj,
  4306. BNX2X_F_CMD_AFEX_VIFLISTS);
  4307. bnx2x_after_afex_vif_lists(bp, elem);
  4308. goto next_spqe;
  4309. case EVENT_RING_OPCODE_FUNCTION_START:
  4310. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4311. "got FUNC_START ramrod\n");
  4312. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_START))
  4313. break;
  4314. goto next_spqe;
  4315. case EVENT_RING_OPCODE_FUNCTION_STOP:
  4316. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4317. "got FUNC_STOP ramrod\n");
  4318. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_STOP))
  4319. break;
  4320. goto next_spqe;
  4321. }
  4322. switch (opcode | bp->state) {
  4323. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4324. BNX2X_STATE_OPEN):
  4325. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4326. BNX2X_STATE_OPENING_WAIT4_PORT):
  4327. cid = elem->message.data.eth_event.echo &
  4328. BNX2X_SWCID_MASK;
  4329. DP(BNX2X_MSG_SP, "got RSS_UPDATE ramrod. CID %d\n",
  4330. cid);
  4331. rss_raw->clear_pending(rss_raw);
  4332. break;
  4333. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_OPEN):
  4334. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_DIAG):
  4335. case (EVENT_RING_OPCODE_SET_MAC |
  4336. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4337. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4338. BNX2X_STATE_OPEN):
  4339. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4340. BNX2X_STATE_DIAG):
  4341. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4342. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4343. DP(BNX2X_MSG_SP, "got (un)set mac ramrod\n");
  4344. bnx2x_handle_classification_eqe(bp, elem);
  4345. break;
  4346. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4347. BNX2X_STATE_OPEN):
  4348. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4349. BNX2X_STATE_DIAG):
  4350. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4351. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4352. DP(BNX2X_MSG_SP, "got mcast ramrod\n");
  4353. bnx2x_handle_mcast_eqe(bp);
  4354. break;
  4355. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4356. BNX2X_STATE_OPEN):
  4357. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4358. BNX2X_STATE_DIAG):
  4359. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4360. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4361. DP(BNX2X_MSG_SP, "got rx_mode ramrod\n");
  4362. bnx2x_handle_rx_mode_eqe(bp);
  4363. break;
  4364. default:
  4365. /* unknown event log error and continue */
  4366. BNX2X_ERR("Unknown EQ event %d, bp->state 0x%x\n",
  4367. elem->message.opcode, bp->state);
  4368. }
  4369. next_spqe:
  4370. spqe_cnt++;
  4371. } /* for */
  4372. smp_mb__before_atomic_inc();
  4373. atomic_add(spqe_cnt, &bp->eq_spq_left);
  4374. bp->eq_cons = sw_cons;
  4375. bp->eq_prod = sw_prod;
  4376. /* Make sure that above mem writes were issued towards the memory */
  4377. smp_wmb();
  4378. /* update producer */
  4379. bnx2x_update_eq_prod(bp, bp->eq_prod);
  4380. }
  4381. static void bnx2x_sp_task(struct work_struct *work)
  4382. {
  4383. struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work);
  4384. DP(BNX2X_MSG_SP, "sp task invoked\n");
  4385. /* make sure the atomic interupt_occurred has been written */
  4386. smp_rmb();
  4387. if (atomic_read(&bp->interrupt_occurred)) {
  4388. /* what work needs to be performed? */
  4389. u16 status = bnx2x_update_dsb_idx(bp);
  4390. DP(BNX2X_MSG_SP, "status %x\n", status);
  4391. DP(BNX2X_MSG_SP, "setting interrupt_occurred to 0\n");
  4392. atomic_set(&bp->interrupt_occurred, 0);
  4393. /* HW attentions */
  4394. if (status & BNX2X_DEF_SB_ATT_IDX) {
  4395. bnx2x_attn_int(bp);
  4396. status &= ~BNX2X_DEF_SB_ATT_IDX;
  4397. }
  4398. /* SP events: STAT_QUERY and others */
  4399. if (status & BNX2X_DEF_SB_IDX) {
  4400. struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
  4401. if (FCOE_INIT(bp) &&
  4402. (bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp))) {
  4403. /* Prevent local bottom-halves from running as
  4404. * we are going to change the local NAPI list.
  4405. */
  4406. local_bh_disable();
  4407. napi_schedule(&bnx2x_fcoe(bp, napi));
  4408. local_bh_enable();
  4409. }
  4410. /* Handle EQ completions */
  4411. bnx2x_eq_int(bp);
  4412. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID,
  4413. le16_to_cpu(bp->def_idx), IGU_INT_NOP, 1);
  4414. status &= ~BNX2X_DEF_SB_IDX;
  4415. }
  4416. /* if status is non zero then perhaps something went wrong */
  4417. if (unlikely(status))
  4418. DP(BNX2X_MSG_SP,
  4419. "got an unknown interrupt! (status 0x%x)\n", status);
  4420. /* ack status block only if something was actually handled */
  4421. bnx2x_ack_sb(bp, bp->igu_dsb_id, ATTENTION_ID,
  4422. le16_to_cpu(bp->def_att_idx), IGU_INT_ENABLE, 1);
  4423. }
  4424. /* must be called after the EQ processing (since eq leads to sriov
  4425. * ramrod completion flows).
  4426. * This flow may have been scheduled by the arrival of a ramrod
  4427. * completion, or by the sriov code rescheduling itself.
  4428. */
  4429. bnx2x_iov_sp_task(bp);
  4430. /* afex - poll to check if VIFSET_ACK should be sent to MFW */
  4431. if (test_and_clear_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK,
  4432. &bp->sp_state)) {
  4433. bnx2x_link_report(bp);
  4434. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  4435. }
  4436. }
  4437. irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance)
  4438. {
  4439. struct net_device *dev = dev_instance;
  4440. struct bnx2x *bp = netdev_priv(dev);
  4441. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0,
  4442. IGU_INT_DISABLE, 0);
  4443. #ifdef BNX2X_STOP_ON_ERROR
  4444. if (unlikely(bp->panic))
  4445. return IRQ_HANDLED;
  4446. #endif
  4447. if (CNIC_LOADED(bp)) {
  4448. struct cnic_ops *c_ops;
  4449. rcu_read_lock();
  4450. c_ops = rcu_dereference(bp->cnic_ops);
  4451. if (c_ops)
  4452. c_ops->cnic_handler(bp->cnic_data, NULL);
  4453. rcu_read_unlock();
  4454. }
  4455. /* schedule sp task to perform default status block work, ack
  4456. * attentions and enable interrupts.
  4457. */
  4458. bnx2x_schedule_sp_task(bp);
  4459. return IRQ_HANDLED;
  4460. }
  4461. /* end of slow path */
  4462. void bnx2x_drv_pulse(struct bnx2x *bp)
  4463. {
  4464. SHMEM_WR(bp, func_mb[BP_FW_MB_IDX(bp)].drv_pulse_mb,
  4465. bp->fw_drv_pulse_wr_seq);
  4466. }
  4467. static void bnx2x_timer(unsigned long data)
  4468. {
  4469. struct bnx2x *bp = (struct bnx2x *) data;
  4470. if (!netif_running(bp->dev))
  4471. return;
  4472. if (IS_PF(bp) &&
  4473. !BP_NOMCP(bp)) {
  4474. int mb_idx = BP_FW_MB_IDX(bp);
  4475. u32 drv_pulse;
  4476. u32 mcp_pulse;
  4477. ++bp->fw_drv_pulse_wr_seq;
  4478. bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK;
  4479. /* TBD - add SYSTEM_TIME */
  4480. drv_pulse = bp->fw_drv_pulse_wr_seq;
  4481. bnx2x_drv_pulse(bp);
  4482. mcp_pulse = (SHMEM_RD(bp, func_mb[mb_idx].mcp_pulse_mb) &
  4483. MCP_PULSE_SEQ_MASK);
  4484. /* The delta between driver pulse and mcp response
  4485. * should be 1 (before mcp response) or 0 (after mcp response)
  4486. */
  4487. if ((drv_pulse != mcp_pulse) &&
  4488. (drv_pulse != ((mcp_pulse + 1) & MCP_PULSE_SEQ_MASK))) {
  4489. /* someone lost a heartbeat... */
  4490. BNX2X_ERR("drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
  4491. drv_pulse, mcp_pulse);
  4492. }
  4493. }
  4494. if (bp->state == BNX2X_STATE_OPEN)
  4495. bnx2x_stats_handle(bp, STATS_EVENT_UPDATE);
  4496. /* sample pf vf bulletin board for new posts from pf */
  4497. if (IS_VF(bp))
  4498. bnx2x_sample_bulletin(bp);
  4499. mod_timer(&bp->timer, jiffies + bp->current_interval);
  4500. }
  4501. /* end of Statistics */
  4502. /* nic init */
  4503. /*
  4504. * nic init service functions
  4505. */
  4506. static void bnx2x_fill(struct bnx2x *bp, u32 addr, int fill, u32 len)
  4507. {
  4508. u32 i;
  4509. if (!(len%4) && !(addr%4))
  4510. for (i = 0; i < len; i += 4)
  4511. REG_WR(bp, addr + i, fill);
  4512. else
  4513. for (i = 0; i < len; i++)
  4514. REG_WR8(bp, addr + i, fill);
  4515. }
  4516. /* helper: writes FP SP data to FW - data_size in dwords */
  4517. static void bnx2x_wr_fp_sb_data(struct bnx2x *bp,
  4518. int fw_sb_id,
  4519. u32 *sb_data_p,
  4520. u32 data_size)
  4521. {
  4522. int index;
  4523. for (index = 0; index < data_size; index++)
  4524. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4525. CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id) +
  4526. sizeof(u32)*index,
  4527. *(sb_data_p + index));
  4528. }
  4529. static void bnx2x_zero_fp_sb(struct bnx2x *bp, int fw_sb_id)
  4530. {
  4531. u32 *sb_data_p;
  4532. u32 data_size = 0;
  4533. struct hc_status_block_data_e2 sb_data_e2;
  4534. struct hc_status_block_data_e1x sb_data_e1x;
  4535. /* disable the function first */
  4536. if (!CHIP_IS_E1x(bp)) {
  4537. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  4538. sb_data_e2.common.state = SB_DISABLED;
  4539. sb_data_e2.common.p_func.vf_valid = false;
  4540. sb_data_p = (u32 *)&sb_data_e2;
  4541. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  4542. } else {
  4543. memset(&sb_data_e1x, 0,
  4544. sizeof(struct hc_status_block_data_e1x));
  4545. sb_data_e1x.common.state = SB_DISABLED;
  4546. sb_data_e1x.common.p_func.vf_valid = false;
  4547. sb_data_p = (u32 *)&sb_data_e1x;
  4548. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  4549. }
  4550. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  4551. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4552. CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id), 0,
  4553. CSTORM_STATUS_BLOCK_SIZE);
  4554. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4555. CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id), 0,
  4556. CSTORM_SYNC_BLOCK_SIZE);
  4557. }
  4558. /* helper: writes SP SB data to FW */
  4559. static void bnx2x_wr_sp_sb_data(struct bnx2x *bp,
  4560. struct hc_sp_status_block_data *sp_sb_data)
  4561. {
  4562. int func = BP_FUNC(bp);
  4563. int i;
  4564. for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
  4565. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4566. CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
  4567. i*sizeof(u32),
  4568. *((u32 *)sp_sb_data + i));
  4569. }
  4570. static void bnx2x_zero_sp_sb(struct bnx2x *bp)
  4571. {
  4572. int func = BP_FUNC(bp);
  4573. struct hc_sp_status_block_data sp_sb_data;
  4574. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  4575. sp_sb_data.state = SB_DISABLED;
  4576. sp_sb_data.p_func.vf_valid = false;
  4577. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  4578. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4579. CSTORM_SP_STATUS_BLOCK_OFFSET(func), 0,
  4580. CSTORM_SP_STATUS_BLOCK_SIZE);
  4581. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4582. CSTORM_SP_SYNC_BLOCK_OFFSET(func), 0,
  4583. CSTORM_SP_SYNC_BLOCK_SIZE);
  4584. }
  4585. static void bnx2x_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm,
  4586. int igu_sb_id, int igu_seg_id)
  4587. {
  4588. hc_sm->igu_sb_id = igu_sb_id;
  4589. hc_sm->igu_seg_id = igu_seg_id;
  4590. hc_sm->timer_value = 0xFF;
  4591. hc_sm->time_to_expire = 0xFFFFFFFF;
  4592. }
  4593. /* allocates state machine ids. */
  4594. static void bnx2x_map_sb_state_machines(struct hc_index_data *index_data)
  4595. {
  4596. /* zero out state machine indices */
  4597. /* rx indices */
  4598. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4599. /* tx indices */
  4600. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4601. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags &= ~HC_INDEX_DATA_SM_ID;
  4602. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags &= ~HC_INDEX_DATA_SM_ID;
  4603. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags &= ~HC_INDEX_DATA_SM_ID;
  4604. /* map indices */
  4605. /* rx indices */
  4606. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags |=
  4607. SM_RX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4608. /* tx indices */
  4609. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags |=
  4610. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4611. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags |=
  4612. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4613. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags |=
  4614. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4615. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags |=
  4616. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4617. }
  4618. void bnx2x_init_sb(struct bnx2x *bp, dma_addr_t mapping, int vfid,
  4619. u8 vf_valid, int fw_sb_id, int igu_sb_id)
  4620. {
  4621. int igu_seg_id;
  4622. struct hc_status_block_data_e2 sb_data_e2;
  4623. struct hc_status_block_data_e1x sb_data_e1x;
  4624. struct hc_status_block_sm *hc_sm_p;
  4625. int data_size;
  4626. u32 *sb_data_p;
  4627. if (CHIP_INT_MODE_IS_BC(bp))
  4628. igu_seg_id = HC_SEG_ACCESS_NORM;
  4629. else
  4630. igu_seg_id = IGU_SEG_ACCESS_NORM;
  4631. bnx2x_zero_fp_sb(bp, fw_sb_id);
  4632. if (!CHIP_IS_E1x(bp)) {
  4633. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  4634. sb_data_e2.common.state = SB_ENABLED;
  4635. sb_data_e2.common.p_func.pf_id = BP_FUNC(bp);
  4636. sb_data_e2.common.p_func.vf_id = vfid;
  4637. sb_data_e2.common.p_func.vf_valid = vf_valid;
  4638. sb_data_e2.common.p_func.vnic_id = BP_VN(bp);
  4639. sb_data_e2.common.same_igu_sb_1b = true;
  4640. sb_data_e2.common.host_sb_addr.hi = U64_HI(mapping);
  4641. sb_data_e2.common.host_sb_addr.lo = U64_LO(mapping);
  4642. hc_sm_p = sb_data_e2.common.state_machine;
  4643. sb_data_p = (u32 *)&sb_data_e2;
  4644. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  4645. bnx2x_map_sb_state_machines(sb_data_e2.index_data);
  4646. } else {
  4647. memset(&sb_data_e1x, 0,
  4648. sizeof(struct hc_status_block_data_e1x));
  4649. sb_data_e1x.common.state = SB_ENABLED;
  4650. sb_data_e1x.common.p_func.pf_id = BP_FUNC(bp);
  4651. sb_data_e1x.common.p_func.vf_id = 0xff;
  4652. sb_data_e1x.common.p_func.vf_valid = false;
  4653. sb_data_e1x.common.p_func.vnic_id = BP_VN(bp);
  4654. sb_data_e1x.common.same_igu_sb_1b = true;
  4655. sb_data_e1x.common.host_sb_addr.hi = U64_HI(mapping);
  4656. sb_data_e1x.common.host_sb_addr.lo = U64_LO(mapping);
  4657. hc_sm_p = sb_data_e1x.common.state_machine;
  4658. sb_data_p = (u32 *)&sb_data_e1x;
  4659. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  4660. bnx2x_map_sb_state_machines(sb_data_e1x.index_data);
  4661. }
  4662. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_RX_ID],
  4663. igu_sb_id, igu_seg_id);
  4664. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_TX_ID],
  4665. igu_sb_id, igu_seg_id);
  4666. DP(NETIF_MSG_IFUP, "Init FW SB %d\n", fw_sb_id);
  4667. /* write indices to HW - PCI guarantees endianity of regpairs */
  4668. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  4669. }
  4670. static void bnx2x_update_coalesce_sb(struct bnx2x *bp, u8 fw_sb_id,
  4671. u16 tx_usec, u16 rx_usec)
  4672. {
  4673. bnx2x_update_coalesce_sb_index(bp, fw_sb_id, HC_INDEX_ETH_RX_CQ_CONS,
  4674. false, rx_usec);
  4675. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4676. HC_INDEX_ETH_TX_CQ_CONS_COS0, false,
  4677. tx_usec);
  4678. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4679. HC_INDEX_ETH_TX_CQ_CONS_COS1, false,
  4680. tx_usec);
  4681. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4682. HC_INDEX_ETH_TX_CQ_CONS_COS2, false,
  4683. tx_usec);
  4684. }
  4685. static void bnx2x_init_def_sb(struct bnx2x *bp)
  4686. {
  4687. struct host_sp_status_block *def_sb = bp->def_status_blk;
  4688. dma_addr_t mapping = bp->def_status_blk_mapping;
  4689. int igu_sp_sb_index;
  4690. int igu_seg_id;
  4691. int port = BP_PORT(bp);
  4692. int func = BP_FUNC(bp);
  4693. int reg_offset, reg_offset_en5;
  4694. u64 section;
  4695. int index;
  4696. struct hc_sp_status_block_data sp_sb_data;
  4697. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  4698. if (CHIP_INT_MODE_IS_BC(bp)) {
  4699. igu_sp_sb_index = DEF_SB_IGU_ID;
  4700. igu_seg_id = HC_SEG_ACCESS_DEF;
  4701. } else {
  4702. igu_sp_sb_index = bp->igu_dsb_id;
  4703. igu_seg_id = IGU_SEG_ACCESS_DEF;
  4704. }
  4705. /* ATTN */
  4706. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  4707. atten_status_block);
  4708. def_sb->atten_status_block.status_block_id = igu_sp_sb_index;
  4709. bp->attn_state = 0;
  4710. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  4711. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  4712. reg_offset_en5 = (port ? MISC_REG_AEU_ENABLE5_FUNC_1_OUT_0 :
  4713. MISC_REG_AEU_ENABLE5_FUNC_0_OUT_0);
  4714. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  4715. int sindex;
  4716. /* take care of sig[0]..sig[4] */
  4717. for (sindex = 0; sindex < 4; sindex++)
  4718. bp->attn_group[index].sig[sindex] =
  4719. REG_RD(bp, reg_offset + sindex*0x4 + 0x10*index);
  4720. if (!CHIP_IS_E1x(bp))
  4721. /*
  4722. * enable5 is separate from the rest of the registers,
  4723. * and therefore the address skip is 4
  4724. * and not 16 between the different groups
  4725. */
  4726. bp->attn_group[index].sig[4] = REG_RD(bp,
  4727. reg_offset_en5 + 0x4*index);
  4728. else
  4729. bp->attn_group[index].sig[4] = 0;
  4730. }
  4731. if (bp->common.int_block == INT_BLOCK_HC) {
  4732. reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L :
  4733. HC_REG_ATTN_MSG0_ADDR_L);
  4734. REG_WR(bp, reg_offset, U64_LO(section));
  4735. REG_WR(bp, reg_offset + 4, U64_HI(section));
  4736. } else if (!CHIP_IS_E1x(bp)) {
  4737. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_L, U64_LO(section));
  4738. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_H, U64_HI(section));
  4739. }
  4740. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  4741. sp_sb);
  4742. bnx2x_zero_sp_sb(bp);
  4743. /* PCI guarantees endianity of regpairs */
  4744. sp_sb_data.state = SB_ENABLED;
  4745. sp_sb_data.host_sb_addr.lo = U64_LO(section);
  4746. sp_sb_data.host_sb_addr.hi = U64_HI(section);
  4747. sp_sb_data.igu_sb_id = igu_sp_sb_index;
  4748. sp_sb_data.igu_seg_id = igu_seg_id;
  4749. sp_sb_data.p_func.pf_id = func;
  4750. sp_sb_data.p_func.vnic_id = BP_VN(bp);
  4751. sp_sb_data.p_func.vf_id = 0xff;
  4752. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  4753. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0);
  4754. }
  4755. void bnx2x_update_coalesce(struct bnx2x *bp)
  4756. {
  4757. int i;
  4758. for_each_eth_queue(bp, i)
  4759. bnx2x_update_coalesce_sb(bp, bp->fp[i].fw_sb_id,
  4760. bp->tx_ticks, bp->rx_ticks);
  4761. }
  4762. static void bnx2x_init_sp_ring(struct bnx2x *bp)
  4763. {
  4764. spin_lock_init(&bp->spq_lock);
  4765. atomic_set(&bp->cq_spq_left, MAX_SPQ_PENDING);
  4766. bp->spq_prod_idx = 0;
  4767. bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX;
  4768. bp->spq_prod_bd = bp->spq;
  4769. bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT;
  4770. }
  4771. static void bnx2x_init_eq_ring(struct bnx2x *bp)
  4772. {
  4773. int i;
  4774. for (i = 1; i <= NUM_EQ_PAGES; i++) {
  4775. union event_ring_elem *elem =
  4776. &bp->eq_ring[EQ_DESC_CNT_PAGE * i - 1];
  4777. elem->next_page.addr.hi =
  4778. cpu_to_le32(U64_HI(bp->eq_mapping +
  4779. BCM_PAGE_SIZE * (i % NUM_EQ_PAGES)));
  4780. elem->next_page.addr.lo =
  4781. cpu_to_le32(U64_LO(bp->eq_mapping +
  4782. BCM_PAGE_SIZE*(i % NUM_EQ_PAGES)));
  4783. }
  4784. bp->eq_cons = 0;
  4785. bp->eq_prod = NUM_EQ_DESC;
  4786. bp->eq_cons_sb = BNX2X_EQ_INDEX;
  4787. /* we want a warning message before it gets rought... */
  4788. atomic_set(&bp->eq_spq_left,
  4789. min_t(int, MAX_SP_DESC_CNT - MAX_SPQ_PENDING, NUM_EQ_DESC) - 1);
  4790. }
  4791. /* called with netif_addr_lock_bh() */
  4792. int bnx2x_set_q_rx_mode(struct bnx2x *bp, u8 cl_id,
  4793. unsigned long rx_mode_flags,
  4794. unsigned long rx_accept_flags,
  4795. unsigned long tx_accept_flags,
  4796. unsigned long ramrod_flags)
  4797. {
  4798. struct bnx2x_rx_mode_ramrod_params ramrod_param;
  4799. int rc;
  4800. memset(&ramrod_param, 0, sizeof(ramrod_param));
  4801. /* Prepare ramrod parameters */
  4802. ramrod_param.cid = 0;
  4803. ramrod_param.cl_id = cl_id;
  4804. ramrod_param.rx_mode_obj = &bp->rx_mode_obj;
  4805. ramrod_param.func_id = BP_FUNC(bp);
  4806. ramrod_param.pstate = &bp->sp_state;
  4807. ramrod_param.state = BNX2X_FILTER_RX_MODE_PENDING;
  4808. ramrod_param.rdata = bnx2x_sp(bp, rx_mode_rdata);
  4809. ramrod_param.rdata_mapping = bnx2x_sp_mapping(bp, rx_mode_rdata);
  4810. set_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  4811. ramrod_param.ramrod_flags = ramrod_flags;
  4812. ramrod_param.rx_mode_flags = rx_mode_flags;
  4813. ramrod_param.rx_accept_flags = rx_accept_flags;
  4814. ramrod_param.tx_accept_flags = tx_accept_flags;
  4815. rc = bnx2x_config_rx_mode(bp, &ramrod_param);
  4816. if (rc < 0) {
  4817. BNX2X_ERR("Set rx_mode %d failed\n", bp->rx_mode);
  4818. return rc;
  4819. }
  4820. return 0;
  4821. }
  4822. static int bnx2x_fill_accept_flags(struct bnx2x *bp, u32 rx_mode,
  4823. unsigned long *rx_accept_flags,
  4824. unsigned long *tx_accept_flags)
  4825. {
  4826. /* Clear the flags first */
  4827. *rx_accept_flags = 0;
  4828. *tx_accept_flags = 0;
  4829. switch (rx_mode) {
  4830. case BNX2X_RX_MODE_NONE:
  4831. /*
  4832. * 'drop all' supersedes any accept flags that may have been
  4833. * passed to the function.
  4834. */
  4835. break;
  4836. case BNX2X_RX_MODE_NORMAL:
  4837. __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
  4838. __set_bit(BNX2X_ACCEPT_MULTICAST, rx_accept_flags);
  4839. __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
  4840. /* internal switching mode */
  4841. __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
  4842. __set_bit(BNX2X_ACCEPT_MULTICAST, tx_accept_flags);
  4843. __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
  4844. break;
  4845. case BNX2X_RX_MODE_ALLMULTI:
  4846. __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
  4847. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, rx_accept_flags);
  4848. __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
  4849. /* internal switching mode */
  4850. __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
  4851. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, tx_accept_flags);
  4852. __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
  4853. break;
  4854. case BNX2X_RX_MODE_PROMISC:
  4855. /* According to deffinition of SI mode, iface in promisc mode
  4856. * should receive matched and unmatched (in resolution of port)
  4857. * unicast packets.
  4858. */
  4859. __set_bit(BNX2X_ACCEPT_UNMATCHED, rx_accept_flags);
  4860. __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
  4861. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, rx_accept_flags);
  4862. __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
  4863. /* internal switching mode */
  4864. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, tx_accept_flags);
  4865. __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
  4866. if (IS_MF_SI(bp))
  4867. __set_bit(BNX2X_ACCEPT_ALL_UNICAST, tx_accept_flags);
  4868. else
  4869. __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
  4870. break;
  4871. default:
  4872. BNX2X_ERR("Unknown rx_mode: %d\n", rx_mode);
  4873. return -EINVAL;
  4874. }
  4875. /* Set ACCEPT_ANY_VLAN as we do not enable filtering by VLAN */
  4876. if (bp->rx_mode != BNX2X_RX_MODE_NONE) {
  4877. __set_bit(BNX2X_ACCEPT_ANY_VLAN, rx_accept_flags);
  4878. __set_bit(BNX2X_ACCEPT_ANY_VLAN, tx_accept_flags);
  4879. }
  4880. return 0;
  4881. }
  4882. /* called with netif_addr_lock_bh() */
  4883. int bnx2x_set_storm_rx_mode(struct bnx2x *bp)
  4884. {
  4885. unsigned long rx_mode_flags = 0, ramrod_flags = 0;
  4886. unsigned long rx_accept_flags = 0, tx_accept_flags = 0;
  4887. int rc;
  4888. if (!NO_FCOE(bp))
  4889. /* Configure rx_mode of FCoE Queue */
  4890. __set_bit(BNX2X_RX_MODE_FCOE_ETH, &rx_mode_flags);
  4891. rc = bnx2x_fill_accept_flags(bp, bp->rx_mode, &rx_accept_flags,
  4892. &tx_accept_flags);
  4893. if (rc)
  4894. return rc;
  4895. __set_bit(RAMROD_RX, &ramrod_flags);
  4896. __set_bit(RAMROD_TX, &ramrod_flags);
  4897. return bnx2x_set_q_rx_mode(bp, bp->fp->cl_id, rx_mode_flags,
  4898. rx_accept_flags, tx_accept_flags,
  4899. ramrod_flags);
  4900. }
  4901. static void bnx2x_init_internal_common(struct bnx2x *bp)
  4902. {
  4903. int i;
  4904. if (IS_MF_SI(bp))
  4905. /*
  4906. * In switch independent mode, the TSTORM needs to accept
  4907. * packets that failed classification, since approximate match
  4908. * mac addresses aren't written to NIG LLH
  4909. */
  4910. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  4911. TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 2);
  4912. else if (!CHIP_IS_E1(bp)) /* 57710 doesn't support MF */
  4913. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  4914. TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 0);
  4915. /* Zero this manually as its initialization is
  4916. currently missing in the initTool */
  4917. for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++)
  4918. REG_WR(bp, BAR_USTRORM_INTMEM +
  4919. USTORM_AGG_DATA_OFFSET + i * 4, 0);
  4920. if (!CHIP_IS_E1x(bp)) {
  4921. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_IGU_MODE_OFFSET,
  4922. CHIP_INT_MODE_IS_BC(bp) ?
  4923. HC_IGU_BC_MODE : HC_IGU_NBC_MODE);
  4924. }
  4925. }
  4926. static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code)
  4927. {
  4928. switch (load_code) {
  4929. case FW_MSG_CODE_DRV_LOAD_COMMON:
  4930. case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
  4931. bnx2x_init_internal_common(bp);
  4932. /* no break */
  4933. case FW_MSG_CODE_DRV_LOAD_PORT:
  4934. /* nothing to do */
  4935. /* no break */
  4936. case FW_MSG_CODE_DRV_LOAD_FUNCTION:
  4937. /* internal memory per function is
  4938. initialized inside bnx2x_pf_init */
  4939. break;
  4940. default:
  4941. BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
  4942. break;
  4943. }
  4944. }
  4945. static inline u8 bnx2x_fp_igu_sb_id(struct bnx2x_fastpath *fp)
  4946. {
  4947. return fp->bp->igu_base_sb + fp->index + CNIC_SUPPORT(fp->bp);
  4948. }
  4949. static inline u8 bnx2x_fp_fw_sb_id(struct bnx2x_fastpath *fp)
  4950. {
  4951. return fp->bp->base_fw_ndsb + fp->index + CNIC_SUPPORT(fp->bp);
  4952. }
  4953. static u8 bnx2x_fp_cl_id(struct bnx2x_fastpath *fp)
  4954. {
  4955. if (CHIP_IS_E1x(fp->bp))
  4956. return BP_L_ID(fp->bp) + fp->index;
  4957. else /* We want Client ID to be the same as IGU SB ID for 57712 */
  4958. return bnx2x_fp_igu_sb_id(fp);
  4959. }
  4960. static void bnx2x_init_eth_fp(struct bnx2x *bp, int fp_idx)
  4961. {
  4962. struct bnx2x_fastpath *fp = &bp->fp[fp_idx];
  4963. u8 cos;
  4964. unsigned long q_type = 0;
  4965. u32 cids[BNX2X_MULTI_TX_COS] = { 0 };
  4966. fp->rx_queue = fp_idx;
  4967. fp->cid = fp_idx;
  4968. fp->cl_id = bnx2x_fp_cl_id(fp);
  4969. fp->fw_sb_id = bnx2x_fp_fw_sb_id(fp);
  4970. fp->igu_sb_id = bnx2x_fp_igu_sb_id(fp);
  4971. /* qZone id equals to FW (per path) client id */
  4972. fp->cl_qzone_id = bnx2x_fp_qzone_id(fp);
  4973. /* init shortcut */
  4974. fp->ustorm_rx_prods_offset = bnx2x_rx_ustorm_prods_offset(fp);
  4975. /* Setup SB indicies */
  4976. fp->rx_cons_sb = BNX2X_RX_SB_INDEX;
  4977. /* Configure Queue State object */
  4978. __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
  4979. __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
  4980. BUG_ON(fp->max_cos > BNX2X_MULTI_TX_COS);
  4981. /* init tx data */
  4982. for_each_cos_in_tx_queue(fp, cos) {
  4983. bnx2x_init_txdata(bp, fp->txdata_ptr[cos],
  4984. CID_COS_TO_TX_ONLY_CID(fp->cid, cos, bp),
  4985. FP_COS_TO_TXQ(fp, cos, bp),
  4986. BNX2X_TX_SB_INDEX_BASE + cos, fp);
  4987. cids[cos] = fp->txdata_ptr[cos]->cid;
  4988. }
  4989. /* nothing more for vf to do here */
  4990. if (IS_VF(bp))
  4991. return;
  4992. bnx2x_init_sb(bp, fp->status_blk_mapping, BNX2X_VF_ID_INVALID, false,
  4993. fp->fw_sb_id, fp->igu_sb_id);
  4994. bnx2x_update_fpsb_idx(fp);
  4995. bnx2x_init_queue_obj(bp, &bnx2x_sp_obj(bp, fp).q_obj, fp->cl_id, cids,
  4996. fp->max_cos, BP_FUNC(bp), bnx2x_sp(bp, q_rdata),
  4997. bnx2x_sp_mapping(bp, q_rdata), q_type);
  4998. /**
  4999. * Configure classification DBs: Always enable Tx switching
  5000. */
  5001. bnx2x_init_vlan_mac_fp_objs(fp, BNX2X_OBJ_TYPE_RX_TX);
  5002. DP(NETIF_MSG_IFUP,
  5003. "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d fw_sb %d igu_sb %d\n",
  5004. fp_idx, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
  5005. fp->igu_sb_id);
  5006. }
  5007. static void bnx2x_init_tx_ring_one(struct bnx2x_fp_txdata *txdata)
  5008. {
  5009. int i;
  5010. for (i = 1; i <= NUM_TX_RINGS; i++) {
  5011. struct eth_tx_next_bd *tx_next_bd =
  5012. &txdata->tx_desc_ring[TX_DESC_CNT * i - 1].next_bd;
  5013. tx_next_bd->addr_hi =
  5014. cpu_to_le32(U64_HI(txdata->tx_desc_mapping +
  5015. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  5016. tx_next_bd->addr_lo =
  5017. cpu_to_le32(U64_LO(txdata->tx_desc_mapping +
  5018. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  5019. }
  5020. SET_FLAG(txdata->tx_db.data.header.header, DOORBELL_HDR_DB_TYPE, 1);
  5021. txdata->tx_db.data.zero_fill1 = 0;
  5022. txdata->tx_db.data.prod = 0;
  5023. txdata->tx_pkt_prod = 0;
  5024. txdata->tx_pkt_cons = 0;
  5025. txdata->tx_bd_prod = 0;
  5026. txdata->tx_bd_cons = 0;
  5027. txdata->tx_pkt = 0;
  5028. }
  5029. static void bnx2x_init_tx_rings_cnic(struct bnx2x *bp)
  5030. {
  5031. int i;
  5032. for_each_tx_queue_cnic(bp, i)
  5033. bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[0]);
  5034. }
  5035. static void bnx2x_init_tx_rings(struct bnx2x *bp)
  5036. {
  5037. int i;
  5038. u8 cos;
  5039. for_each_eth_queue(bp, i)
  5040. for_each_cos_in_tx_queue(&bp->fp[i], cos)
  5041. bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[cos]);
  5042. }
  5043. void bnx2x_nic_init_cnic(struct bnx2x *bp)
  5044. {
  5045. if (!NO_FCOE(bp))
  5046. bnx2x_init_fcoe_fp(bp);
  5047. bnx2x_init_sb(bp, bp->cnic_sb_mapping,
  5048. BNX2X_VF_ID_INVALID, false,
  5049. bnx2x_cnic_fw_sb_id(bp), bnx2x_cnic_igu_sb_id(bp));
  5050. /* ensure status block indices were read */
  5051. rmb();
  5052. bnx2x_init_rx_rings_cnic(bp);
  5053. bnx2x_init_tx_rings_cnic(bp);
  5054. /* flush all */
  5055. mb();
  5056. mmiowb();
  5057. }
  5058. void bnx2x_pre_irq_nic_init(struct bnx2x *bp)
  5059. {
  5060. int i;
  5061. /* Setup NIC internals and enable interrupts */
  5062. for_each_eth_queue(bp, i)
  5063. bnx2x_init_eth_fp(bp, i);
  5064. /* ensure status block indices were read */
  5065. rmb();
  5066. bnx2x_init_rx_rings(bp);
  5067. bnx2x_init_tx_rings(bp);
  5068. if (IS_VF(bp)) {
  5069. bnx2x_memset_stats(bp);
  5070. return;
  5071. }
  5072. if (IS_PF(bp)) {
  5073. /* Initialize MOD_ABS interrupts */
  5074. bnx2x_init_mod_abs_int(bp, &bp->link_vars, bp->common.chip_id,
  5075. bp->common.shmem_base,
  5076. bp->common.shmem2_base, BP_PORT(bp));
  5077. /* initialize the default status block and sp ring */
  5078. bnx2x_init_def_sb(bp);
  5079. bnx2x_update_dsb_idx(bp);
  5080. bnx2x_init_sp_ring(bp);
  5081. }
  5082. }
  5083. void bnx2x_post_irq_nic_init(struct bnx2x *bp, u32 load_code)
  5084. {
  5085. bnx2x_init_eq_ring(bp);
  5086. bnx2x_init_internal(bp, load_code);
  5087. bnx2x_pf_init(bp);
  5088. bnx2x_stats_init(bp);
  5089. /* flush all before enabling interrupts */
  5090. mb();
  5091. mmiowb();
  5092. bnx2x_int_enable(bp);
  5093. /* Check for SPIO5 */
  5094. bnx2x_attn_int_deasserted0(bp,
  5095. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + BP_PORT(bp)*4) &
  5096. AEU_INPUTS_ATTN_BITS_SPIO5);
  5097. }
  5098. /* gzip service functions */
  5099. static int bnx2x_gunzip_init(struct bnx2x *bp)
  5100. {
  5101. bp->gunzip_buf = dma_alloc_coherent(&bp->pdev->dev, FW_BUF_SIZE,
  5102. &bp->gunzip_mapping, GFP_KERNEL);
  5103. if (bp->gunzip_buf == NULL)
  5104. goto gunzip_nomem1;
  5105. bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL);
  5106. if (bp->strm == NULL)
  5107. goto gunzip_nomem2;
  5108. bp->strm->workspace = vmalloc(zlib_inflate_workspacesize());
  5109. if (bp->strm->workspace == NULL)
  5110. goto gunzip_nomem3;
  5111. return 0;
  5112. gunzip_nomem3:
  5113. kfree(bp->strm);
  5114. bp->strm = NULL;
  5115. gunzip_nomem2:
  5116. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  5117. bp->gunzip_mapping);
  5118. bp->gunzip_buf = NULL;
  5119. gunzip_nomem1:
  5120. BNX2X_ERR("Cannot allocate firmware buffer for un-compression\n");
  5121. return -ENOMEM;
  5122. }
  5123. static void bnx2x_gunzip_end(struct bnx2x *bp)
  5124. {
  5125. if (bp->strm) {
  5126. vfree(bp->strm->workspace);
  5127. kfree(bp->strm);
  5128. bp->strm = NULL;
  5129. }
  5130. if (bp->gunzip_buf) {
  5131. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  5132. bp->gunzip_mapping);
  5133. bp->gunzip_buf = NULL;
  5134. }
  5135. }
  5136. static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len)
  5137. {
  5138. int n, rc;
  5139. /* check gzip header */
  5140. if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED)) {
  5141. BNX2X_ERR("Bad gzip header\n");
  5142. return -EINVAL;
  5143. }
  5144. n = 10;
  5145. #define FNAME 0x8
  5146. if (zbuf[3] & FNAME)
  5147. while ((zbuf[n++] != 0) && (n < len));
  5148. bp->strm->next_in = (typeof(bp->strm->next_in))zbuf + n;
  5149. bp->strm->avail_in = len - n;
  5150. bp->strm->next_out = bp->gunzip_buf;
  5151. bp->strm->avail_out = FW_BUF_SIZE;
  5152. rc = zlib_inflateInit2(bp->strm, -MAX_WBITS);
  5153. if (rc != Z_OK)
  5154. return rc;
  5155. rc = zlib_inflate(bp->strm, Z_FINISH);
  5156. if ((rc != Z_OK) && (rc != Z_STREAM_END))
  5157. netdev_err(bp->dev, "Firmware decompression error: %s\n",
  5158. bp->strm->msg);
  5159. bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out);
  5160. if (bp->gunzip_outlen & 0x3)
  5161. netdev_err(bp->dev,
  5162. "Firmware decompression error: gunzip_outlen (%d) not aligned\n",
  5163. bp->gunzip_outlen);
  5164. bp->gunzip_outlen >>= 2;
  5165. zlib_inflateEnd(bp->strm);
  5166. if (rc == Z_STREAM_END)
  5167. return 0;
  5168. return rc;
  5169. }
  5170. /* nic load/unload */
  5171. /*
  5172. * General service functions
  5173. */
  5174. /* send a NIG loopback debug packet */
  5175. static void bnx2x_lb_pckt(struct bnx2x *bp)
  5176. {
  5177. u32 wb_write[3];
  5178. /* Ethernet source and destination addresses */
  5179. wb_write[0] = 0x55555555;
  5180. wb_write[1] = 0x55555555;
  5181. wb_write[2] = 0x20; /* SOP */
  5182. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  5183. /* NON-IP protocol */
  5184. wb_write[0] = 0x09000000;
  5185. wb_write[1] = 0x55555555;
  5186. wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */
  5187. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  5188. }
  5189. /* some of the internal memories
  5190. * are not directly readable from the driver
  5191. * to test them we send debug packets
  5192. */
  5193. static int bnx2x_int_mem_test(struct bnx2x *bp)
  5194. {
  5195. int factor;
  5196. int count, i;
  5197. u32 val = 0;
  5198. if (CHIP_REV_IS_FPGA(bp))
  5199. factor = 120;
  5200. else if (CHIP_REV_IS_EMUL(bp))
  5201. factor = 200;
  5202. else
  5203. factor = 1;
  5204. /* Disable inputs of parser neighbor blocks */
  5205. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  5206. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  5207. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  5208. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  5209. /* Write 0 to parser credits for CFC search request */
  5210. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  5211. /* send Ethernet packet */
  5212. bnx2x_lb_pckt(bp);
  5213. /* TODO do i reset NIG statistic? */
  5214. /* Wait until NIG register shows 1 packet of size 0x10 */
  5215. count = 1000 * factor;
  5216. while (count) {
  5217. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5218. val = *bnx2x_sp(bp, wb_data[0]);
  5219. if (val == 0x10)
  5220. break;
  5221. msleep(10);
  5222. count--;
  5223. }
  5224. if (val != 0x10) {
  5225. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  5226. return -1;
  5227. }
  5228. /* Wait until PRS register shows 1 packet */
  5229. count = 1000 * factor;
  5230. while (count) {
  5231. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5232. if (val == 1)
  5233. break;
  5234. msleep(10);
  5235. count--;
  5236. }
  5237. if (val != 0x1) {
  5238. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5239. return -2;
  5240. }
  5241. /* Reset and init BRB, PRS */
  5242. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  5243. msleep(50);
  5244. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  5245. msleep(50);
  5246. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5247. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5248. DP(NETIF_MSG_HW, "part2\n");
  5249. /* Disable inputs of parser neighbor blocks */
  5250. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  5251. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  5252. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  5253. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  5254. /* Write 0 to parser credits for CFC search request */
  5255. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  5256. /* send 10 Ethernet packets */
  5257. for (i = 0; i < 10; i++)
  5258. bnx2x_lb_pckt(bp);
  5259. /* Wait until NIG register shows 10 + 1
  5260. packets of size 11*0x10 = 0xb0 */
  5261. count = 1000 * factor;
  5262. while (count) {
  5263. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5264. val = *bnx2x_sp(bp, wb_data[0]);
  5265. if (val == 0xb0)
  5266. break;
  5267. msleep(10);
  5268. count--;
  5269. }
  5270. if (val != 0xb0) {
  5271. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  5272. return -3;
  5273. }
  5274. /* Wait until PRS register shows 2 packets */
  5275. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5276. if (val != 2)
  5277. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5278. /* Write 1 to parser credits for CFC search request */
  5279. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1);
  5280. /* Wait until PRS register shows 3 packets */
  5281. msleep(10 * factor);
  5282. /* Wait until NIG register shows 1 packet of size 0x10 */
  5283. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5284. if (val != 3)
  5285. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5286. /* clear NIG EOP FIFO */
  5287. for (i = 0; i < 11; i++)
  5288. REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO);
  5289. val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY);
  5290. if (val != 1) {
  5291. BNX2X_ERR("clear of NIG failed\n");
  5292. return -4;
  5293. }
  5294. /* Reset and init BRB, PRS, NIG */
  5295. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  5296. msleep(50);
  5297. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  5298. msleep(50);
  5299. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5300. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5301. if (!CNIC_SUPPORT(bp))
  5302. /* set NIC mode */
  5303. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  5304. /* Enable inputs of parser neighbor blocks */
  5305. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff);
  5306. REG_WR(bp, TCM_REG_PRS_IFEN, 0x1);
  5307. REG_WR(bp, CFC_REG_DEBUG0, 0x0);
  5308. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1);
  5309. DP(NETIF_MSG_HW, "done\n");
  5310. return 0; /* OK */
  5311. }
  5312. static void bnx2x_enable_blocks_attention(struct bnx2x *bp)
  5313. {
  5314. u32 val;
  5315. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5316. if (!CHIP_IS_E1x(bp))
  5317. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0x40);
  5318. else
  5319. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0);
  5320. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  5321. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  5322. /*
  5323. * mask read length error interrupts in brb for parser
  5324. * (parsing unit and 'checksum and crc' unit)
  5325. * these errors are legal (PU reads fixed length and CAC can cause
  5326. * read length error on truncated packets)
  5327. */
  5328. REG_WR(bp, BRB1_REG_BRB1_INT_MASK, 0xFC00);
  5329. REG_WR(bp, QM_REG_QM_INT_MASK, 0);
  5330. REG_WR(bp, TM_REG_TM_INT_MASK, 0);
  5331. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0);
  5332. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0);
  5333. REG_WR(bp, XCM_REG_XCM_INT_MASK, 0);
  5334. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */
  5335. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */
  5336. REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0);
  5337. REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0);
  5338. REG_WR(bp, UCM_REG_UCM_INT_MASK, 0);
  5339. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */
  5340. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */
  5341. REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0);
  5342. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0);
  5343. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0);
  5344. REG_WR(bp, CCM_REG_CCM_INT_MASK, 0);
  5345. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */
  5346. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */
  5347. val = PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT |
  5348. PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF |
  5349. PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN;
  5350. if (!CHIP_IS_E1x(bp))
  5351. val |= PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED |
  5352. PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED;
  5353. REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, val);
  5354. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0);
  5355. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0);
  5356. REG_WR(bp, TCM_REG_TCM_INT_MASK, 0);
  5357. /* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */
  5358. if (!CHIP_IS_E1x(bp))
  5359. /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */
  5360. REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0x07ff);
  5361. REG_WR(bp, CDU_REG_CDU_INT_MASK, 0);
  5362. REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0);
  5363. /* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */
  5364. REG_WR(bp, PBF_REG_PBF_INT_MASK, 0x18); /* bit 3,4 masked */
  5365. }
  5366. static void bnx2x_reset_common(struct bnx2x *bp)
  5367. {
  5368. u32 val = 0x1400;
  5369. /* reset_common */
  5370. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  5371. 0xd3ffff7f);
  5372. if (CHIP_IS_E3(bp)) {
  5373. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  5374. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  5375. }
  5376. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, val);
  5377. }
  5378. static void bnx2x_setup_dmae(struct bnx2x *bp)
  5379. {
  5380. bp->dmae_ready = 0;
  5381. spin_lock_init(&bp->dmae_lock);
  5382. }
  5383. static void bnx2x_init_pxp(struct bnx2x *bp)
  5384. {
  5385. u16 devctl;
  5386. int r_order, w_order;
  5387. pcie_capability_read_word(bp->pdev, PCI_EXP_DEVCTL, &devctl);
  5388. DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl);
  5389. w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
  5390. if (bp->mrrs == -1)
  5391. r_order = ((devctl & PCI_EXP_DEVCTL_READRQ) >> 12);
  5392. else {
  5393. DP(NETIF_MSG_HW, "force read order to %d\n", bp->mrrs);
  5394. r_order = bp->mrrs;
  5395. }
  5396. bnx2x_init_pxp_arb(bp, r_order, w_order);
  5397. }
  5398. static void bnx2x_setup_fan_failure_detection(struct bnx2x *bp)
  5399. {
  5400. int is_required;
  5401. u32 val;
  5402. int port;
  5403. if (BP_NOMCP(bp))
  5404. return;
  5405. is_required = 0;
  5406. val = SHMEM_RD(bp, dev_info.shared_hw_config.config2) &
  5407. SHARED_HW_CFG_FAN_FAILURE_MASK;
  5408. if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED)
  5409. is_required = 1;
  5410. /*
  5411. * The fan failure mechanism is usually related to the PHY type since
  5412. * the power consumption of the board is affected by the PHY. Currently,
  5413. * fan is required for most designs with SFX7101, BCM8727 and BCM8481.
  5414. */
  5415. else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE)
  5416. for (port = PORT_0; port < PORT_MAX; port++) {
  5417. is_required |=
  5418. bnx2x_fan_failure_det_req(
  5419. bp,
  5420. bp->common.shmem_base,
  5421. bp->common.shmem2_base,
  5422. port);
  5423. }
  5424. DP(NETIF_MSG_HW, "fan detection setting: %d\n", is_required);
  5425. if (is_required == 0)
  5426. return;
  5427. /* Fan failure is indicated by SPIO 5 */
  5428. bnx2x_set_spio(bp, MISC_SPIO_SPIO5, MISC_SPIO_INPUT_HI_Z);
  5429. /* set to active low mode */
  5430. val = REG_RD(bp, MISC_REG_SPIO_INT);
  5431. val |= (MISC_SPIO_SPIO5 << MISC_SPIO_INT_OLD_SET_POS);
  5432. REG_WR(bp, MISC_REG_SPIO_INT, val);
  5433. /* enable interrupt to signal the IGU */
  5434. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  5435. val |= MISC_SPIO_SPIO5;
  5436. REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val);
  5437. }
  5438. void bnx2x_pf_disable(struct bnx2x *bp)
  5439. {
  5440. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  5441. val &= ~IGU_PF_CONF_FUNC_EN;
  5442. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  5443. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  5444. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 0);
  5445. }
  5446. static void bnx2x__common_init_phy(struct bnx2x *bp)
  5447. {
  5448. u32 shmem_base[2], shmem2_base[2];
  5449. /* Avoid common init in case MFW supports LFA */
  5450. if (SHMEM2_RD(bp, size) >
  5451. (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
  5452. return;
  5453. shmem_base[0] = bp->common.shmem_base;
  5454. shmem2_base[0] = bp->common.shmem2_base;
  5455. if (!CHIP_IS_E1x(bp)) {
  5456. shmem_base[1] =
  5457. SHMEM2_RD(bp, other_shmem_base_addr);
  5458. shmem2_base[1] =
  5459. SHMEM2_RD(bp, other_shmem2_base_addr);
  5460. }
  5461. bnx2x_acquire_phy_lock(bp);
  5462. bnx2x_common_init_phy(bp, shmem_base, shmem2_base,
  5463. bp->common.chip_id);
  5464. bnx2x_release_phy_lock(bp);
  5465. }
  5466. /**
  5467. * bnx2x_init_hw_common - initialize the HW at the COMMON phase.
  5468. *
  5469. * @bp: driver handle
  5470. */
  5471. static int bnx2x_init_hw_common(struct bnx2x *bp)
  5472. {
  5473. u32 val;
  5474. DP(NETIF_MSG_HW, "starting common init func %d\n", BP_ABS_FUNC(bp));
  5475. /*
  5476. * take the RESET lock to protect undi_unload flow from accessing
  5477. * registers while we're resetting the chip
  5478. */
  5479. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5480. bnx2x_reset_common(bp);
  5481. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff);
  5482. val = 0xfffc;
  5483. if (CHIP_IS_E3(bp)) {
  5484. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  5485. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  5486. }
  5487. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, val);
  5488. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5489. bnx2x_init_block(bp, BLOCK_MISC, PHASE_COMMON);
  5490. if (!CHIP_IS_E1x(bp)) {
  5491. u8 abs_func_id;
  5492. /**
  5493. * 4-port mode or 2-port mode we need to turn of master-enable
  5494. * for everyone, after that, turn it back on for self.
  5495. * so, we disregard multi-function or not, and always disable
  5496. * for all functions on the given path, this means 0,2,4,6 for
  5497. * path 0 and 1,3,5,7 for path 1
  5498. */
  5499. for (abs_func_id = BP_PATH(bp);
  5500. abs_func_id < E2_FUNC_MAX*2; abs_func_id += 2) {
  5501. if (abs_func_id == BP_ABS_FUNC(bp)) {
  5502. REG_WR(bp,
  5503. PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER,
  5504. 1);
  5505. continue;
  5506. }
  5507. bnx2x_pretend_func(bp, abs_func_id);
  5508. /* clear pf enable */
  5509. bnx2x_pf_disable(bp);
  5510. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  5511. }
  5512. }
  5513. bnx2x_init_block(bp, BLOCK_PXP, PHASE_COMMON);
  5514. if (CHIP_IS_E1(bp)) {
  5515. /* enable HW interrupt from PXP on USDM overflow
  5516. bit 16 on INT_MASK_0 */
  5517. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5518. }
  5519. bnx2x_init_block(bp, BLOCK_PXP2, PHASE_COMMON);
  5520. bnx2x_init_pxp(bp);
  5521. #ifdef __BIG_ENDIAN
  5522. REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, 1);
  5523. REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, 1);
  5524. REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, 1);
  5525. REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, 1);
  5526. REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, 1);
  5527. /* make sure this value is 0 */
  5528. REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0);
  5529. /* REG_WR(bp, PXP2_REG_RD_PBF_SWAP_MODE, 1); */
  5530. REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, 1);
  5531. REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, 1);
  5532. REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, 1);
  5533. REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, 1);
  5534. #endif
  5535. bnx2x_ilt_init_page_size(bp, INITOP_SET);
  5536. if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp))
  5537. REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1);
  5538. /* let the HW do it's magic ... */
  5539. msleep(100);
  5540. /* finish PXP init */
  5541. val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE);
  5542. if (val != 1) {
  5543. BNX2X_ERR("PXP2 CFG failed\n");
  5544. return -EBUSY;
  5545. }
  5546. val = REG_RD(bp, PXP2_REG_RD_INIT_DONE);
  5547. if (val != 1) {
  5548. BNX2X_ERR("PXP2 RD_INIT failed\n");
  5549. return -EBUSY;
  5550. }
  5551. /* Timers bug workaround E2 only. We need to set the entire ILT to
  5552. * have entries with value "0" and valid bit on.
  5553. * This needs to be done by the first PF that is loaded in a path
  5554. * (i.e. common phase)
  5555. */
  5556. if (!CHIP_IS_E1x(bp)) {
  5557. /* In E2 there is a bug in the timers block that can cause function 6 / 7
  5558. * (i.e. vnic3) to start even if it is marked as "scan-off".
  5559. * This occurs when a different function (func2,3) is being marked
  5560. * as "scan-off". Real-life scenario for example: if a driver is being
  5561. * load-unloaded while func6,7 are down. This will cause the timer to access
  5562. * the ilt, translate to a logical address and send a request to read/write.
  5563. * Since the ilt for the function that is down is not valid, this will cause
  5564. * a translation error which is unrecoverable.
  5565. * The Workaround is intended to make sure that when this happens nothing fatal
  5566. * will occur. The workaround:
  5567. * 1. First PF driver which loads on a path will:
  5568. * a. After taking the chip out of reset, by using pretend,
  5569. * it will write "0" to the following registers of
  5570. * the other vnics.
  5571. * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  5572. * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0);
  5573. * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0);
  5574. * And for itself it will write '1' to
  5575. * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable
  5576. * dmae-operations (writing to pram for example.)
  5577. * note: can be done for only function 6,7 but cleaner this
  5578. * way.
  5579. * b. Write zero+valid to the entire ILT.
  5580. * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of
  5581. * VNIC3 (of that port). The range allocated will be the
  5582. * entire ILT. This is needed to prevent ILT range error.
  5583. * 2. Any PF driver load flow:
  5584. * a. ILT update with the physical addresses of the allocated
  5585. * logical pages.
  5586. * b. Wait 20msec. - note that this timeout is needed to make
  5587. * sure there are no requests in one of the PXP internal
  5588. * queues with "old" ILT addresses.
  5589. * c. PF enable in the PGLC.
  5590. * d. Clear the was_error of the PF in the PGLC. (could have
  5591. * occurred while driver was down)
  5592. * e. PF enable in the CFC (WEAK + STRONG)
  5593. * f. Timers scan enable
  5594. * 3. PF driver unload flow:
  5595. * a. Clear the Timers scan_en.
  5596. * b. Polling for scan_on=0 for that PF.
  5597. * c. Clear the PF enable bit in the PXP.
  5598. * d. Clear the PF enable in the CFC (WEAK + STRONG)
  5599. * e. Write zero+valid to all ILT entries (The valid bit must
  5600. * stay set)
  5601. * f. If this is VNIC 3 of a port then also init
  5602. * first_timers_ilt_entry to zero and last_timers_ilt_entry
  5603. * to the last enrty in the ILT.
  5604. *
  5605. * Notes:
  5606. * Currently the PF error in the PGLC is non recoverable.
  5607. * In the future the there will be a recovery routine for this error.
  5608. * Currently attention is masked.
  5609. * Having an MCP lock on the load/unload process does not guarantee that
  5610. * there is no Timer disable during Func6/7 enable. This is because the
  5611. * Timers scan is currently being cleared by the MCP on FLR.
  5612. * Step 2.d can be done only for PF6/7 and the driver can also check if
  5613. * there is error before clearing it. But the flow above is simpler and
  5614. * more general.
  5615. * All ILT entries are written by zero+valid and not just PF6/7
  5616. * ILT entries since in the future the ILT entries allocation for
  5617. * PF-s might be dynamic.
  5618. */
  5619. struct ilt_client_info ilt_cli;
  5620. struct bnx2x_ilt ilt;
  5621. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  5622. memset(&ilt, 0, sizeof(struct bnx2x_ilt));
  5623. /* initialize dummy TM client */
  5624. ilt_cli.start = 0;
  5625. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  5626. ilt_cli.client_num = ILT_CLIENT_TM;
  5627. /* Step 1: set zeroes to all ilt page entries with valid bit on
  5628. * Step 2: set the timers first/last ilt entry to point
  5629. * to the entire range to prevent ILT range error for 3rd/4th
  5630. * vnic (this code assumes existence of the vnic)
  5631. *
  5632. * both steps performed by call to bnx2x_ilt_client_init_op()
  5633. * with dummy TM client
  5634. *
  5635. * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT
  5636. * and his brother are split registers
  5637. */
  5638. bnx2x_pretend_func(bp, (BP_PATH(bp) + 6));
  5639. bnx2x_ilt_client_init_op_ilt(bp, &ilt, &ilt_cli, INITOP_CLEAR);
  5640. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  5641. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN, BNX2X_PXP_DRAM_ALIGN);
  5642. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_RD, BNX2X_PXP_DRAM_ALIGN);
  5643. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_SEL, 1);
  5644. }
  5645. REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0);
  5646. REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0);
  5647. if (!CHIP_IS_E1x(bp)) {
  5648. int factor = CHIP_REV_IS_EMUL(bp) ? 1000 :
  5649. (CHIP_REV_IS_FPGA(bp) ? 400 : 0);
  5650. bnx2x_init_block(bp, BLOCK_PGLUE_B, PHASE_COMMON);
  5651. bnx2x_init_block(bp, BLOCK_ATC, PHASE_COMMON);
  5652. /* let the HW do it's magic ... */
  5653. do {
  5654. msleep(200);
  5655. val = REG_RD(bp, ATC_REG_ATC_INIT_DONE);
  5656. } while (factor-- && (val != 1));
  5657. if (val != 1) {
  5658. BNX2X_ERR("ATC_INIT failed\n");
  5659. return -EBUSY;
  5660. }
  5661. }
  5662. bnx2x_init_block(bp, BLOCK_DMAE, PHASE_COMMON);
  5663. bnx2x_iov_init_dmae(bp);
  5664. /* clean the DMAE memory */
  5665. bp->dmae_ready = 1;
  5666. bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8, 1);
  5667. bnx2x_init_block(bp, BLOCK_TCM, PHASE_COMMON);
  5668. bnx2x_init_block(bp, BLOCK_UCM, PHASE_COMMON);
  5669. bnx2x_init_block(bp, BLOCK_CCM, PHASE_COMMON);
  5670. bnx2x_init_block(bp, BLOCK_XCM, PHASE_COMMON);
  5671. bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3);
  5672. bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3);
  5673. bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3);
  5674. bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3);
  5675. bnx2x_init_block(bp, BLOCK_QM, PHASE_COMMON);
  5676. /* QM queues pointers table */
  5677. bnx2x_qm_init_ptr_table(bp, bp->qm_cid_count, INITOP_SET);
  5678. /* soft reset pulse */
  5679. REG_WR(bp, QM_REG_SOFT_RESET, 1);
  5680. REG_WR(bp, QM_REG_SOFT_RESET, 0);
  5681. if (CNIC_SUPPORT(bp))
  5682. bnx2x_init_block(bp, BLOCK_TM, PHASE_COMMON);
  5683. bnx2x_init_block(bp, BLOCK_DORQ, PHASE_COMMON);
  5684. REG_WR(bp, DORQ_REG_DPM_CID_OFST, BNX2X_DB_SHIFT);
  5685. if (!CHIP_REV_IS_SLOW(bp))
  5686. /* enable hw interrupt from doorbell Q */
  5687. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  5688. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5689. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5690. REG_WR(bp, PRS_REG_A_PRSU_20, 0xf);
  5691. if (!CHIP_IS_E1(bp))
  5692. REG_WR(bp, PRS_REG_E1HOV_MODE, bp->path_has_ovlan);
  5693. if (!CHIP_IS_E1x(bp) && !CHIP_IS_E3B0(bp)) {
  5694. if (IS_MF_AFEX(bp)) {
  5695. /* configure that VNTag and VLAN headers must be
  5696. * received in afex mode
  5697. */
  5698. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC, 0xE);
  5699. REG_WR(bp, PRS_REG_MUST_HAVE_HDRS, 0xA);
  5700. REG_WR(bp, PRS_REG_HDRS_AFTER_TAG_0, 0x6);
  5701. REG_WR(bp, PRS_REG_TAG_ETHERTYPE_0, 0x8926);
  5702. REG_WR(bp, PRS_REG_TAG_LEN_0, 0x4);
  5703. } else {
  5704. /* Bit-map indicating which L2 hdrs may appear
  5705. * after the basic Ethernet header
  5706. */
  5707. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC,
  5708. bp->path_has_ovlan ? 7 : 6);
  5709. }
  5710. }
  5711. bnx2x_init_block(bp, BLOCK_TSDM, PHASE_COMMON);
  5712. bnx2x_init_block(bp, BLOCK_CSDM, PHASE_COMMON);
  5713. bnx2x_init_block(bp, BLOCK_USDM, PHASE_COMMON);
  5714. bnx2x_init_block(bp, BLOCK_XSDM, PHASE_COMMON);
  5715. if (!CHIP_IS_E1x(bp)) {
  5716. /* reset VFC memories */
  5717. REG_WR(bp, TSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  5718. VFC_MEMORIES_RST_REG_CAM_RST |
  5719. VFC_MEMORIES_RST_REG_RAM_RST);
  5720. REG_WR(bp, XSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  5721. VFC_MEMORIES_RST_REG_CAM_RST |
  5722. VFC_MEMORIES_RST_REG_RAM_RST);
  5723. msleep(20);
  5724. }
  5725. bnx2x_init_block(bp, BLOCK_TSEM, PHASE_COMMON);
  5726. bnx2x_init_block(bp, BLOCK_USEM, PHASE_COMMON);
  5727. bnx2x_init_block(bp, BLOCK_CSEM, PHASE_COMMON);
  5728. bnx2x_init_block(bp, BLOCK_XSEM, PHASE_COMMON);
  5729. /* sync semi rtc */
  5730. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  5731. 0x80000000);
  5732. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
  5733. 0x80000000);
  5734. bnx2x_init_block(bp, BLOCK_UPB, PHASE_COMMON);
  5735. bnx2x_init_block(bp, BLOCK_XPB, PHASE_COMMON);
  5736. bnx2x_init_block(bp, BLOCK_PBF, PHASE_COMMON);
  5737. if (!CHIP_IS_E1x(bp)) {
  5738. if (IS_MF_AFEX(bp)) {
  5739. /* configure that VNTag and VLAN headers must be
  5740. * sent in afex mode
  5741. */
  5742. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC, 0xE);
  5743. REG_WR(bp, PBF_REG_MUST_HAVE_HDRS, 0xA);
  5744. REG_WR(bp, PBF_REG_HDRS_AFTER_TAG_0, 0x6);
  5745. REG_WR(bp, PBF_REG_TAG_ETHERTYPE_0, 0x8926);
  5746. REG_WR(bp, PBF_REG_TAG_LEN_0, 0x4);
  5747. } else {
  5748. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC,
  5749. bp->path_has_ovlan ? 7 : 6);
  5750. }
  5751. }
  5752. REG_WR(bp, SRC_REG_SOFT_RST, 1);
  5753. bnx2x_init_block(bp, BLOCK_SRC, PHASE_COMMON);
  5754. if (CNIC_SUPPORT(bp)) {
  5755. REG_WR(bp, SRC_REG_KEYSEARCH_0, 0x63285672);
  5756. REG_WR(bp, SRC_REG_KEYSEARCH_1, 0x24b8f2cc);
  5757. REG_WR(bp, SRC_REG_KEYSEARCH_2, 0x223aef9b);
  5758. REG_WR(bp, SRC_REG_KEYSEARCH_3, 0x26001e3a);
  5759. REG_WR(bp, SRC_REG_KEYSEARCH_4, 0x7ae91116);
  5760. REG_WR(bp, SRC_REG_KEYSEARCH_5, 0x5ce5230b);
  5761. REG_WR(bp, SRC_REG_KEYSEARCH_6, 0x298d8adf);
  5762. REG_WR(bp, SRC_REG_KEYSEARCH_7, 0x6eb0ff09);
  5763. REG_WR(bp, SRC_REG_KEYSEARCH_8, 0x1830f82f);
  5764. REG_WR(bp, SRC_REG_KEYSEARCH_9, 0x01e46be7);
  5765. }
  5766. REG_WR(bp, SRC_REG_SOFT_RST, 0);
  5767. if (sizeof(union cdu_context) != 1024)
  5768. /* we currently assume that a context is 1024 bytes */
  5769. dev_alert(&bp->pdev->dev,
  5770. "please adjust the size of cdu_context(%ld)\n",
  5771. (long)sizeof(union cdu_context));
  5772. bnx2x_init_block(bp, BLOCK_CDU, PHASE_COMMON);
  5773. val = (4 << 24) + (0 << 12) + 1024;
  5774. REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val);
  5775. bnx2x_init_block(bp, BLOCK_CFC, PHASE_COMMON);
  5776. REG_WR(bp, CFC_REG_INIT_REG, 0x7FF);
  5777. /* enable context validation interrupt from CFC */
  5778. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  5779. /* set the thresholds to prevent CFC/CDU race */
  5780. REG_WR(bp, CFC_REG_DEBUG0, 0x20020000);
  5781. bnx2x_init_block(bp, BLOCK_HC, PHASE_COMMON);
  5782. if (!CHIP_IS_E1x(bp) && BP_NOMCP(bp))
  5783. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x36);
  5784. bnx2x_init_block(bp, BLOCK_IGU, PHASE_COMMON);
  5785. bnx2x_init_block(bp, BLOCK_MISC_AEU, PHASE_COMMON);
  5786. /* Reset PCIE errors for debug */
  5787. REG_WR(bp, 0x2814, 0xffffffff);
  5788. REG_WR(bp, 0x3820, 0xffffffff);
  5789. if (!CHIP_IS_E1x(bp)) {
  5790. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_CONTROL_5,
  5791. (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1 |
  5792. PXPCS_TL_CONTROL_5_ERR_UNSPPORT));
  5793. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC345_STAT,
  5794. (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4 |
  5795. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3 |
  5796. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2));
  5797. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC678_STAT,
  5798. (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7 |
  5799. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6 |
  5800. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5));
  5801. }
  5802. bnx2x_init_block(bp, BLOCK_NIG, PHASE_COMMON);
  5803. if (!CHIP_IS_E1(bp)) {
  5804. /* in E3 this done in per-port section */
  5805. if (!CHIP_IS_E3(bp))
  5806. REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_MF(bp));
  5807. }
  5808. if (CHIP_IS_E1H(bp))
  5809. /* not applicable for E2 (and above ...) */
  5810. REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_MF_SD(bp));
  5811. if (CHIP_REV_IS_SLOW(bp))
  5812. msleep(200);
  5813. /* finish CFC init */
  5814. val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10);
  5815. if (val != 1) {
  5816. BNX2X_ERR("CFC LL_INIT failed\n");
  5817. return -EBUSY;
  5818. }
  5819. val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10);
  5820. if (val != 1) {
  5821. BNX2X_ERR("CFC AC_INIT failed\n");
  5822. return -EBUSY;
  5823. }
  5824. val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10);
  5825. if (val != 1) {
  5826. BNX2X_ERR("CFC CAM_INIT failed\n");
  5827. return -EBUSY;
  5828. }
  5829. REG_WR(bp, CFC_REG_DEBUG0, 0);
  5830. if (CHIP_IS_E1(bp)) {
  5831. /* read NIG statistic
  5832. to see if this is our first up since powerup */
  5833. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5834. val = *bnx2x_sp(bp, wb_data[0]);
  5835. /* do internal memory self test */
  5836. if ((val == 0) && bnx2x_int_mem_test(bp)) {
  5837. BNX2X_ERR("internal mem self test failed\n");
  5838. return -EBUSY;
  5839. }
  5840. }
  5841. bnx2x_setup_fan_failure_detection(bp);
  5842. /* clear PXP2 attentions */
  5843. REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0);
  5844. bnx2x_enable_blocks_attention(bp);
  5845. bnx2x_enable_blocks_parity(bp);
  5846. if (!BP_NOMCP(bp)) {
  5847. if (CHIP_IS_E1x(bp))
  5848. bnx2x__common_init_phy(bp);
  5849. } else
  5850. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  5851. return 0;
  5852. }
  5853. /**
  5854. * bnx2x_init_hw_common_chip - init HW at the COMMON_CHIP phase.
  5855. *
  5856. * @bp: driver handle
  5857. */
  5858. static int bnx2x_init_hw_common_chip(struct bnx2x *bp)
  5859. {
  5860. int rc = bnx2x_init_hw_common(bp);
  5861. if (rc)
  5862. return rc;
  5863. /* In E2 2-PORT mode, same ext phy is used for the two paths */
  5864. if (!BP_NOMCP(bp))
  5865. bnx2x__common_init_phy(bp);
  5866. return 0;
  5867. }
  5868. static int bnx2x_init_hw_port(struct bnx2x *bp)
  5869. {
  5870. int port = BP_PORT(bp);
  5871. int init_phase = port ? PHASE_PORT1 : PHASE_PORT0;
  5872. u32 low, high;
  5873. u32 val;
  5874. DP(NETIF_MSG_HW, "starting port init port %d\n", port);
  5875. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  5876. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  5877. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  5878. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  5879. /* Timers bug workaround: disables the pf_master bit in pglue at
  5880. * common phase, we need to enable it here before any dmae access are
  5881. * attempted. Therefore we manually added the enable-master to the
  5882. * port phase (it also happens in the function phase)
  5883. */
  5884. if (!CHIP_IS_E1x(bp))
  5885. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  5886. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  5887. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  5888. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  5889. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  5890. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  5891. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  5892. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  5893. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  5894. /* QM cid (connection) count */
  5895. bnx2x_qm_init_cid_count(bp, bp->qm_cid_count, INITOP_SET);
  5896. if (CNIC_SUPPORT(bp)) {
  5897. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  5898. REG_WR(bp, TM_REG_LIN0_SCAN_TIME + port*4, 20);
  5899. REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31);
  5900. }
  5901. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  5902. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  5903. if (CHIP_IS_E1(bp) || CHIP_IS_E1H(bp)) {
  5904. if (IS_MF(bp))
  5905. low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246);
  5906. else if (bp->dev->mtu > 4096) {
  5907. if (bp->flags & ONE_PORT_FLAG)
  5908. low = 160;
  5909. else {
  5910. val = bp->dev->mtu;
  5911. /* (24*1024 + val*4)/256 */
  5912. low = 96 + (val/64) +
  5913. ((val % 64) ? 1 : 0);
  5914. }
  5915. } else
  5916. low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160);
  5917. high = low + 56; /* 14*1024/256 */
  5918. REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low);
  5919. REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high);
  5920. }
  5921. if (CHIP_MODE_IS_4_PORT(bp))
  5922. REG_WR(bp, (BP_PORT(bp) ?
  5923. BRB1_REG_MAC_GUARANTIED_1 :
  5924. BRB1_REG_MAC_GUARANTIED_0), 40);
  5925. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  5926. if (CHIP_IS_E3B0(bp)) {
  5927. if (IS_MF_AFEX(bp)) {
  5928. /* configure headers for AFEX mode */
  5929. REG_WR(bp, BP_PORT(bp) ?
  5930. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  5931. PRS_REG_HDRS_AFTER_BASIC_PORT_0, 0xE);
  5932. REG_WR(bp, BP_PORT(bp) ?
  5933. PRS_REG_HDRS_AFTER_TAG_0_PORT_1 :
  5934. PRS_REG_HDRS_AFTER_TAG_0_PORT_0, 0x6);
  5935. REG_WR(bp, BP_PORT(bp) ?
  5936. PRS_REG_MUST_HAVE_HDRS_PORT_1 :
  5937. PRS_REG_MUST_HAVE_HDRS_PORT_0, 0xA);
  5938. } else {
  5939. /* Ovlan exists only if we are in multi-function +
  5940. * switch-dependent mode, in switch-independent there
  5941. * is no ovlan headers
  5942. */
  5943. REG_WR(bp, BP_PORT(bp) ?
  5944. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  5945. PRS_REG_HDRS_AFTER_BASIC_PORT_0,
  5946. (bp->path_has_ovlan ? 7 : 6));
  5947. }
  5948. }
  5949. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  5950. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  5951. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  5952. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  5953. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  5954. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  5955. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  5956. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  5957. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  5958. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  5959. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  5960. if (CHIP_IS_E1x(bp)) {
  5961. /* configure PBF to work without PAUSE mtu 9000 */
  5962. REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
  5963. /* update threshold */
  5964. REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16));
  5965. /* update init credit */
  5966. REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22);
  5967. /* probe changes */
  5968. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1);
  5969. udelay(50);
  5970. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0);
  5971. }
  5972. if (CNIC_SUPPORT(bp))
  5973. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  5974. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  5975. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  5976. if (CHIP_IS_E1(bp)) {
  5977. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  5978. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  5979. }
  5980. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  5981. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  5982. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  5983. /* init aeu_mask_attn_func_0/1:
  5984. * - SF mode: bits 3-7 are masked. only bits 0-2 are in use
  5985. * - MF mode: bit 3 is masked. bits 0-2 are in use as in SF
  5986. * bits 4-7 are used for "per vn group attention" */
  5987. val = IS_MF(bp) ? 0xF7 : 0x7;
  5988. /* Enable DCBX attention for all but E1 */
  5989. val |= CHIP_IS_E1(bp) ? 0 : 0x10;
  5990. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, val);
  5991. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  5992. if (!CHIP_IS_E1x(bp)) {
  5993. /* Bit-map indicating which L2 hdrs may appear after the
  5994. * basic Ethernet header
  5995. */
  5996. if (IS_MF_AFEX(bp))
  5997. REG_WR(bp, BP_PORT(bp) ?
  5998. NIG_REG_P1_HDRS_AFTER_BASIC :
  5999. NIG_REG_P0_HDRS_AFTER_BASIC, 0xE);
  6000. else
  6001. REG_WR(bp, BP_PORT(bp) ?
  6002. NIG_REG_P1_HDRS_AFTER_BASIC :
  6003. NIG_REG_P0_HDRS_AFTER_BASIC,
  6004. IS_MF_SD(bp) ? 7 : 6);
  6005. if (CHIP_IS_E3(bp))
  6006. REG_WR(bp, BP_PORT(bp) ?
  6007. NIG_REG_LLH1_MF_MODE :
  6008. NIG_REG_LLH_MF_MODE, IS_MF(bp));
  6009. }
  6010. if (!CHIP_IS_E3(bp))
  6011. REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
  6012. if (!CHIP_IS_E1(bp)) {
  6013. /* 0x2 disable mf_ov, 0x1 enable */
  6014. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4,
  6015. (IS_MF_SD(bp) ? 0x1 : 0x2));
  6016. if (!CHIP_IS_E1x(bp)) {
  6017. val = 0;
  6018. switch (bp->mf_mode) {
  6019. case MULTI_FUNCTION_SD:
  6020. val = 1;
  6021. break;
  6022. case MULTI_FUNCTION_SI:
  6023. case MULTI_FUNCTION_AFEX:
  6024. val = 2;
  6025. break;
  6026. }
  6027. REG_WR(bp, (BP_PORT(bp) ? NIG_REG_LLH1_CLS_TYPE :
  6028. NIG_REG_LLH0_CLS_TYPE), val);
  6029. }
  6030. {
  6031. REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0);
  6032. REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0);
  6033. REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1);
  6034. }
  6035. }
  6036. /* If SPIO5 is set to generate interrupts, enable it for this port */
  6037. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  6038. if (val & MISC_SPIO_SPIO5) {
  6039. u32 reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  6040. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  6041. val = REG_RD(bp, reg_addr);
  6042. val |= AEU_INPUTS_ATTN_BITS_SPIO5;
  6043. REG_WR(bp, reg_addr, val);
  6044. }
  6045. return 0;
  6046. }
  6047. static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr)
  6048. {
  6049. int reg;
  6050. u32 wb_write[2];
  6051. if (CHIP_IS_E1(bp))
  6052. reg = PXP2_REG_RQ_ONCHIP_AT + index*8;
  6053. else
  6054. reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8;
  6055. wb_write[0] = ONCHIP_ADDR1(addr);
  6056. wb_write[1] = ONCHIP_ADDR2(addr);
  6057. REG_WR_DMAE(bp, reg, wb_write, 2);
  6058. }
  6059. void bnx2x_igu_clear_sb_gen(struct bnx2x *bp, u8 func, u8 idu_sb_id, bool is_pf)
  6060. {
  6061. u32 data, ctl, cnt = 100;
  6062. u32 igu_addr_data = IGU_REG_COMMAND_REG_32LSB_DATA;
  6063. u32 igu_addr_ctl = IGU_REG_COMMAND_REG_CTRL;
  6064. u32 igu_addr_ack = IGU_REG_CSTORM_TYPE_0_SB_CLEANUP + (idu_sb_id/32)*4;
  6065. u32 sb_bit = 1 << (idu_sb_id%32);
  6066. u32 func_encode = func | (is_pf ? 1 : 0) << IGU_FID_ENCODE_IS_PF_SHIFT;
  6067. u32 addr_encode = IGU_CMD_E2_PROD_UPD_BASE + idu_sb_id;
  6068. /* Not supported in BC mode */
  6069. if (CHIP_INT_MODE_IS_BC(bp))
  6070. return;
  6071. data = (IGU_USE_REGISTER_cstorm_type_0_sb_cleanup
  6072. << IGU_REGULAR_CLEANUP_TYPE_SHIFT) |
  6073. IGU_REGULAR_CLEANUP_SET |
  6074. IGU_REGULAR_BCLEANUP;
  6075. ctl = addr_encode << IGU_CTRL_REG_ADDRESS_SHIFT |
  6076. func_encode << IGU_CTRL_REG_FID_SHIFT |
  6077. IGU_CTRL_CMD_TYPE_WR << IGU_CTRL_REG_TYPE_SHIFT;
  6078. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  6079. data, igu_addr_data);
  6080. REG_WR(bp, igu_addr_data, data);
  6081. mmiowb();
  6082. barrier();
  6083. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  6084. ctl, igu_addr_ctl);
  6085. REG_WR(bp, igu_addr_ctl, ctl);
  6086. mmiowb();
  6087. barrier();
  6088. /* wait for clean up to finish */
  6089. while (!(REG_RD(bp, igu_addr_ack) & sb_bit) && --cnt)
  6090. msleep(20);
  6091. if (!(REG_RD(bp, igu_addr_ack) & sb_bit)) {
  6092. DP(NETIF_MSG_HW,
  6093. "Unable to finish IGU cleanup: idu_sb_id %d offset %d bit %d (cnt %d)\n",
  6094. idu_sb_id, idu_sb_id/32, idu_sb_id%32, cnt);
  6095. }
  6096. }
  6097. static void bnx2x_igu_clear_sb(struct bnx2x *bp, u8 idu_sb_id)
  6098. {
  6099. bnx2x_igu_clear_sb_gen(bp, BP_FUNC(bp), idu_sb_id, true /*PF*/);
  6100. }
  6101. static void bnx2x_clear_func_ilt(struct bnx2x *bp, u32 func)
  6102. {
  6103. u32 i, base = FUNC_ILT_BASE(func);
  6104. for (i = base; i < base + ILT_PER_FUNC; i++)
  6105. bnx2x_ilt_wr(bp, i, 0);
  6106. }
  6107. static void bnx2x_init_searcher(struct bnx2x *bp)
  6108. {
  6109. int port = BP_PORT(bp);
  6110. bnx2x_src_init_t2(bp, bp->t2, bp->t2_mapping, SRC_CONN_NUM);
  6111. /* T1 hash bits value determines the T1 number of entries */
  6112. REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + port*4, SRC_HASH_BITS);
  6113. }
  6114. static inline int bnx2x_func_switch_update(struct bnx2x *bp, int suspend)
  6115. {
  6116. int rc;
  6117. struct bnx2x_func_state_params func_params = {NULL};
  6118. struct bnx2x_func_switch_update_params *switch_update_params =
  6119. &func_params.params.switch_update;
  6120. /* Prepare parameters for function state transitions */
  6121. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  6122. __set_bit(RAMROD_RETRY, &func_params.ramrod_flags);
  6123. func_params.f_obj = &bp->func_obj;
  6124. func_params.cmd = BNX2X_F_CMD_SWITCH_UPDATE;
  6125. /* Function parameters */
  6126. switch_update_params->suspend = suspend;
  6127. rc = bnx2x_func_state_change(bp, &func_params);
  6128. return rc;
  6129. }
  6130. static int bnx2x_reset_nic_mode(struct bnx2x *bp)
  6131. {
  6132. int rc, i, port = BP_PORT(bp);
  6133. int vlan_en = 0, mac_en[NUM_MACS];
  6134. /* Close input from network */
  6135. if (bp->mf_mode == SINGLE_FUNCTION) {
  6136. bnx2x_set_rx_filter(&bp->link_params, 0);
  6137. } else {
  6138. vlan_en = REG_RD(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6139. NIG_REG_LLH0_FUNC_EN);
  6140. REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6141. NIG_REG_LLH0_FUNC_EN, 0);
  6142. for (i = 0; i < NUM_MACS; i++) {
  6143. mac_en[i] = REG_RD(bp, port ?
  6144. (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6145. 4 * i) :
  6146. (NIG_REG_LLH0_FUNC_MEM_ENABLE +
  6147. 4 * i));
  6148. REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6149. 4 * i) :
  6150. (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i), 0);
  6151. }
  6152. }
  6153. /* Close BMC to host */
  6154. REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
  6155. NIG_REG_P1_TX_MNG_HOST_ENABLE, 0);
  6156. /* Suspend Tx switching to the PF. Completion of this ramrod
  6157. * further guarantees that all the packets of that PF / child
  6158. * VFs in BRB were processed by the Parser, so it is safe to
  6159. * change the NIC_MODE register.
  6160. */
  6161. rc = bnx2x_func_switch_update(bp, 1);
  6162. if (rc) {
  6163. BNX2X_ERR("Can't suspend tx-switching!\n");
  6164. return rc;
  6165. }
  6166. /* Change NIC_MODE register */
  6167. REG_WR(bp, PRS_REG_NIC_MODE, 0);
  6168. /* Open input from network */
  6169. if (bp->mf_mode == SINGLE_FUNCTION) {
  6170. bnx2x_set_rx_filter(&bp->link_params, 1);
  6171. } else {
  6172. REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6173. NIG_REG_LLH0_FUNC_EN, vlan_en);
  6174. for (i = 0; i < NUM_MACS; i++) {
  6175. REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6176. 4 * i) :
  6177. (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i),
  6178. mac_en[i]);
  6179. }
  6180. }
  6181. /* Enable BMC to host */
  6182. REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
  6183. NIG_REG_P1_TX_MNG_HOST_ENABLE, 1);
  6184. /* Resume Tx switching to the PF */
  6185. rc = bnx2x_func_switch_update(bp, 0);
  6186. if (rc) {
  6187. BNX2X_ERR("Can't resume tx-switching!\n");
  6188. return rc;
  6189. }
  6190. DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
  6191. return 0;
  6192. }
  6193. int bnx2x_init_hw_func_cnic(struct bnx2x *bp)
  6194. {
  6195. int rc;
  6196. bnx2x_ilt_init_op_cnic(bp, INITOP_SET);
  6197. if (CONFIGURE_NIC_MODE(bp)) {
  6198. /* Configrue searcher as part of function hw init */
  6199. bnx2x_init_searcher(bp);
  6200. /* Reset NIC mode */
  6201. rc = bnx2x_reset_nic_mode(bp);
  6202. if (rc)
  6203. BNX2X_ERR("Can't change NIC mode!\n");
  6204. return rc;
  6205. }
  6206. return 0;
  6207. }
  6208. static int bnx2x_init_hw_func(struct bnx2x *bp)
  6209. {
  6210. int port = BP_PORT(bp);
  6211. int func = BP_FUNC(bp);
  6212. int init_phase = PHASE_PF0 + func;
  6213. struct bnx2x_ilt *ilt = BP_ILT(bp);
  6214. u16 cdu_ilt_start;
  6215. u32 addr, val;
  6216. u32 main_mem_base, main_mem_size, main_mem_prty_clr;
  6217. int i, main_mem_width, rc;
  6218. DP(NETIF_MSG_HW, "starting func init func %d\n", func);
  6219. /* FLR cleanup - hmmm */
  6220. if (!CHIP_IS_E1x(bp)) {
  6221. rc = bnx2x_pf_flr_clnup(bp);
  6222. if (rc) {
  6223. bnx2x_fw_dump(bp);
  6224. return rc;
  6225. }
  6226. }
  6227. /* set MSI reconfigure capability */
  6228. if (bp->common.int_block == INT_BLOCK_HC) {
  6229. addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0);
  6230. val = REG_RD(bp, addr);
  6231. val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0;
  6232. REG_WR(bp, addr, val);
  6233. }
  6234. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  6235. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  6236. ilt = BP_ILT(bp);
  6237. cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
  6238. if (IS_SRIOV(bp))
  6239. cdu_ilt_start += BNX2X_FIRST_VF_CID/ILT_PAGE_CIDS;
  6240. cdu_ilt_start = bnx2x_iov_init_ilt(bp, cdu_ilt_start);
  6241. /* since BNX2X_FIRST_VF_CID > 0 the PF L2 cids precedes
  6242. * those of the VFs, so start line should be reset
  6243. */
  6244. cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
  6245. for (i = 0; i < L2_ILT_LINES(bp); i++) {
  6246. ilt->lines[cdu_ilt_start + i].page = bp->context[i].vcxt;
  6247. ilt->lines[cdu_ilt_start + i].page_mapping =
  6248. bp->context[i].cxt_mapping;
  6249. ilt->lines[cdu_ilt_start + i].size = bp->context[i].size;
  6250. }
  6251. bnx2x_ilt_init_op(bp, INITOP_SET);
  6252. if (!CONFIGURE_NIC_MODE(bp)) {
  6253. bnx2x_init_searcher(bp);
  6254. REG_WR(bp, PRS_REG_NIC_MODE, 0);
  6255. DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
  6256. } else {
  6257. /* Set NIC mode */
  6258. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  6259. DP(NETIF_MSG_IFUP, "NIC MODE configrued\n");
  6260. }
  6261. if (!CHIP_IS_E1x(bp)) {
  6262. u32 pf_conf = IGU_PF_CONF_FUNC_EN;
  6263. /* Turn on a single ISR mode in IGU if driver is going to use
  6264. * INT#x or MSI
  6265. */
  6266. if (!(bp->flags & USING_MSIX_FLAG))
  6267. pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN;
  6268. /*
  6269. * Timers workaround bug: function init part.
  6270. * Need to wait 20msec after initializing ILT,
  6271. * needed to make sure there are no requests in
  6272. * one of the PXP internal queues with "old" ILT addresses
  6273. */
  6274. msleep(20);
  6275. /*
  6276. * Master enable - Due to WB DMAE writes performed before this
  6277. * register is re-initialized as part of the regular function
  6278. * init
  6279. */
  6280. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  6281. /* Enable the function in IGU */
  6282. REG_WR(bp, IGU_REG_PF_CONFIGURATION, pf_conf);
  6283. }
  6284. bp->dmae_ready = 1;
  6285. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  6286. if (!CHIP_IS_E1x(bp))
  6287. REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, func);
  6288. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  6289. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  6290. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  6291. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  6292. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  6293. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  6294. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  6295. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  6296. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  6297. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  6298. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  6299. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  6300. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  6301. if (!CHIP_IS_E1x(bp))
  6302. REG_WR(bp, QM_REG_PF_EN, 1);
  6303. if (!CHIP_IS_E1x(bp)) {
  6304. REG_WR(bp, TSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6305. REG_WR(bp, USEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6306. REG_WR(bp, CSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6307. REG_WR(bp, XSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6308. }
  6309. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  6310. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  6311. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  6312. bnx2x_iov_init_dq(bp);
  6313. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  6314. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  6315. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  6316. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  6317. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  6318. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  6319. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  6320. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  6321. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  6322. if (!CHIP_IS_E1x(bp))
  6323. REG_WR(bp, PBF_REG_DISABLE_PF, 0);
  6324. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  6325. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  6326. if (!CHIP_IS_E1x(bp))
  6327. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 1);
  6328. if (IS_MF(bp)) {
  6329. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
  6330. REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port*8, bp->mf_ov);
  6331. }
  6332. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  6333. /* HC init per function */
  6334. if (bp->common.int_block == INT_BLOCK_HC) {
  6335. if (CHIP_IS_E1H(bp)) {
  6336. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  6337. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  6338. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  6339. }
  6340. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  6341. } else {
  6342. int num_segs, sb_idx, prod_offset;
  6343. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  6344. if (!CHIP_IS_E1x(bp)) {
  6345. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  6346. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  6347. }
  6348. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  6349. if (!CHIP_IS_E1x(bp)) {
  6350. int dsb_idx = 0;
  6351. /**
  6352. * Producer memory:
  6353. * E2 mode: address 0-135 match to the mapping memory;
  6354. * 136 - PF0 default prod; 137 - PF1 default prod;
  6355. * 138 - PF2 default prod; 139 - PF3 default prod;
  6356. * 140 - PF0 attn prod; 141 - PF1 attn prod;
  6357. * 142 - PF2 attn prod; 143 - PF3 attn prod;
  6358. * 144-147 reserved.
  6359. *
  6360. * E1.5 mode - In backward compatible mode;
  6361. * for non default SB; each even line in the memory
  6362. * holds the U producer and each odd line hold
  6363. * the C producer. The first 128 producers are for
  6364. * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20
  6365. * producers are for the DSB for each PF.
  6366. * Each PF has five segments: (the order inside each
  6367. * segment is PF0; PF1; PF2; PF3) - 128-131 U prods;
  6368. * 132-135 C prods; 136-139 X prods; 140-143 T prods;
  6369. * 144-147 attn prods;
  6370. */
  6371. /* non-default-status-blocks */
  6372. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  6373. IGU_BC_NDSB_NUM_SEGS : IGU_NORM_NDSB_NUM_SEGS;
  6374. for (sb_idx = 0; sb_idx < bp->igu_sb_cnt; sb_idx++) {
  6375. prod_offset = (bp->igu_base_sb + sb_idx) *
  6376. num_segs;
  6377. for (i = 0; i < num_segs; i++) {
  6378. addr = IGU_REG_PROD_CONS_MEMORY +
  6379. (prod_offset + i) * 4;
  6380. REG_WR(bp, addr, 0);
  6381. }
  6382. /* send consumer update with value 0 */
  6383. bnx2x_ack_sb(bp, bp->igu_base_sb + sb_idx,
  6384. USTORM_ID, 0, IGU_INT_NOP, 1);
  6385. bnx2x_igu_clear_sb(bp,
  6386. bp->igu_base_sb + sb_idx);
  6387. }
  6388. /* default-status-blocks */
  6389. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  6390. IGU_BC_DSB_NUM_SEGS : IGU_NORM_DSB_NUM_SEGS;
  6391. if (CHIP_MODE_IS_4_PORT(bp))
  6392. dsb_idx = BP_FUNC(bp);
  6393. else
  6394. dsb_idx = BP_VN(bp);
  6395. prod_offset = (CHIP_INT_MODE_IS_BC(bp) ?
  6396. IGU_BC_BASE_DSB_PROD + dsb_idx :
  6397. IGU_NORM_BASE_DSB_PROD + dsb_idx);
  6398. /*
  6399. * igu prods come in chunks of E1HVN_MAX (4) -
  6400. * does not matters what is the current chip mode
  6401. */
  6402. for (i = 0; i < (num_segs * E1HVN_MAX);
  6403. i += E1HVN_MAX) {
  6404. addr = IGU_REG_PROD_CONS_MEMORY +
  6405. (prod_offset + i)*4;
  6406. REG_WR(bp, addr, 0);
  6407. }
  6408. /* send consumer update with 0 */
  6409. if (CHIP_INT_MODE_IS_BC(bp)) {
  6410. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6411. USTORM_ID, 0, IGU_INT_NOP, 1);
  6412. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6413. CSTORM_ID, 0, IGU_INT_NOP, 1);
  6414. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6415. XSTORM_ID, 0, IGU_INT_NOP, 1);
  6416. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6417. TSTORM_ID, 0, IGU_INT_NOP, 1);
  6418. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6419. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  6420. } else {
  6421. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6422. USTORM_ID, 0, IGU_INT_NOP, 1);
  6423. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6424. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  6425. }
  6426. bnx2x_igu_clear_sb(bp, bp->igu_dsb_id);
  6427. /* !!! these should become driver const once
  6428. rf-tool supports split-68 const */
  6429. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0);
  6430. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0);
  6431. REG_WR(bp, IGU_REG_SB_MASK_LSB, 0);
  6432. REG_WR(bp, IGU_REG_SB_MASK_MSB, 0);
  6433. REG_WR(bp, IGU_REG_PBA_STATUS_LSB, 0);
  6434. REG_WR(bp, IGU_REG_PBA_STATUS_MSB, 0);
  6435. }
  6436. }
  6437. /* Reset PCIE errors for debug */
  6438. REG_WR(bp, 0x2114, 0xffffffff);
  6439. REG_WR(bp, 0x2120, 0xffffffff);
  6440. if (CHIP_IS_E1x(bp)) {
  6441. main_mem_size = HC_REG_MAIN_MEMORY_SIZE / 2; /*dwords*/
  6442. main_mem_base = HC_REG_MAIN_MEMORY +
  6443. BP_PORT(bp) * (main_mem_size * 4);
  6444. main_mem_prty_clr = HC_REG_HC_PRTY_STS_CLR;
  6445. main_mem_width = 8;
  6446. val = REG_RD(bp, main_mem_prty_clr);
  6447. if (val)
  6448. DP(NETIF_MSG_HW,
  6449. "Hmmm... Parity errors in HC block during function init (0x%x)!\n",
  6450. val);
  6451. /* Clear "false" parity errors in MSI-X table */
  6452. for (i = main_mem_base;
  6453. i < main_mem_base + main_mem_size * 4;
  6454. i += main_mem_width) {
  6455. bnx2x_read_dmae(bp, i, main_mem_width / 4);
  6456. bnx2x_write_dmae(bp, bnx2x_sp_mapping(bp, wb_data),
  6457. i, main_mem_width / 4);
  6458. }
  6459. /* Clear HC parity attention */
  6460. REG_RD(bp, main_mem_prty_clr);
  6461. }
  6462. #ifdef BNX2X_STOP_ON_ERROR
  6463. /* Enable STORMs SP logging */
  6464. REG_WR8(bp, BAR_USTRORM_INTMEM +
  6465. USTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6466. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  6467. TSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6468. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6469. CSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6470. REG_WR8(bp, BAR_XSTRORM_INTMEM +
  6471. XSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6472. #endif
  6473. bnx2x_phy_probe(&bp->link_params);
  6474. return 0;
  6475. }
  6476. void bnx2x_free_mem_cnic(struct bnx2x *bp)
  6477. {
  6478. bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_FREE);
  6479. if (!CHIP_IS_E1x(bp))
  6480. BNX2X_PCI_FREE(bp->cnic_sb.e2_sb, bp->cnic_sb_mapping,
  6481. sizeof(struct host_hc_status_block_e2));
  6482. else
  6483. BNX2X_PCI_FREE(bp->cnic_sb.e1x_sb, bp->cnic_sb_mapping,
  6484. sizeof(struct host_hc_status_block_e1x));
  6485. BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
  6486. }
  6487. void bnx2x_free_mem(struct bnx2x *bp)
  6488. {
  6489. int i;
  6490. BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping,
  6491. sizeof(struct host_sp_status_block));
  6492. BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
  6493. bp->fw_stats_data_sz + bp->fw_stats_req_sz);
  6494. BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping,
  6495. sizeof(struct bnx2x_slowpath));
  6496. for (i = 0; i < L2_ILT_LINES(bp); i++)
  6497. BNX2X_PCI_FREE(bp->context[i].vcxt, bp->context[i].cxt_mapping,
  6498. bp->context[i].size);
  6499. bnx2x_ilt_mem_op(bp, ILT_MEMOP_FREE);
  6500. BNX2X_FREE(bp->ilt->lines);
  6501. BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE);
  6502. BNX2X_PCI_FREE(bp->eq_ring, bp->eq_mapping,
  6503. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  6504. BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
  6505. bnx2x_iov_free_mem(bp);
  6506. }
  6507. int bnx2x_alloc_mem_cnic(struct bnx2x *bp)
  6508. {
  6509. if (!CHIP_IS_E1x(bp))
  6510. /* size = the status block + ramrod buffers */
  6511. BNX2X_PCI_ALLOC(bp->cnic_sb.e2_sb, &bp->cnic_sb_mapping,
  6512. sizeof(struct host_hc_status_block_e2));
  6513. else
  6514. BNX2X_PCI_ALLOC(bp->cnic_sb.e1x_sb,
  6515. &bp->cnic_sb_mapping,
  6516. sizeof(struct
  6517. host_hc_status_block_e1x));
  6518. if (CONFIGURE_NIC_MODE(bp) && !bp->t2)
  6519. /* allocate searcher T2 table, as it wan't allocated before */
  6520. BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
  6521. /* write address to which L5 should insert its values */
  6522. bp->cnic_eth_dev.addr_drv_info_to_mcp =
  6523. &bp->slowpath->drv_info_to_mcp;
  6524. if (bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_ALLOC))
  6525. goto alloc_mem_err;
  6526. return 0;
  6527. alloc_mem_err:
  6528. bnx2x_free_mem_cnic(bp);
  6529. BNX2X_ERR("Can't allocate memory\n");
  6530. return -ENOMEM;
  6531. }
  6532. int bnx2x_alloc_mem(struct bnx2x *bp)
  6533. {
  6534. int i, allocated, context_size;
  6535. if (!CONFIGURE_NIC_MODE(bp) && !bp->t2)
  6536. /* allocate searcher T2 table */
  6537. BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
  6538. BNX2X_PCI_ALLOC(bp->def_status_blk, &bp->def_status_blk_mapping,
  6539. sizeof(struct host_sp_status_block));
  6540. BNX2X_PCI_ALLOC(bp->slowpath, &bp->slowpath_mapping,
  6541. sizeof(struct bnx2x_slowpath));
  6542. /* Allocate memory for CDU context:
  6543. * This memory is allocated separately and not in the generic ILT
  6544. * functions because CDU differs in few aspects:
  6545. * 1. There are multiple entities allocating memory for context -
  6546. * 'regular' driver, CNIC and SRIOV driver. Each separately controls
  6547. * its own ILT lines.
  6548. * 2. Since CDU page-size is not a single 4KB page (which is the case
  6549. * for the other ILT clients), to be efficient we want to support
  6550. * allocation of sub-page-size in the last entry.
  6551. * 3. Context pointers are used by the driver to pass to FW / update
  6552. * the context (for the other ILT clients the pointers are used just to
  6553. * free the memory during unload).
  6554. */
  6555. context_size = sizeof(union cdu_context) * BNX2X_L2_CID_COUNT(bp);
  6556. for (i = 0, allocated = 0; allocated < context_size; i++) {
  6557. bp->context[i].size = min(CDU_ILT_PAGE_SZ,
  6558. (context_size - allocated));
  6559. BNX2X_PCI_ALLOC(bp->context[i].vcxt,
  6560. &bp->context[i].cxt_mapping,
  6561. bp->context[i].size);
  6562. allocated += bp->context[i].size;
  6563. }
  6564. BNX2X_ALLOC(bp->ilt->lines, sizeof(struct ilt_line) * ILT_MAX_LINES);
  6565. if (bnx2x_ilt_mem_op(bp, ILT_MEMOP_ALLOC))
  6566. goto alloc_mem_err;
  6567. if (bnx2x_iov_alloc_mem(bp))
  6568. goto alloc_mem_err;
  6569. /* Slow path ring */
  6570. BNX2X_PCI_ALLOC(bp->spq, &bp->spq_mapping, BCM_PAGE_SIZE);
  6571. /* EQ */
  6572. BNX2X_PCI_ALLOC(bp->eq_ring, &bp->eq_mapping,
  6573. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  6574. return 0;
  6575. alloc_mem_err:
  6576. bnx2x_free_mem(bp);
  6577. BNX2X_ERR("Can't allocate memory\n");
  6578. return -ENOMEM;
  6579. }
  6580. /*
  6581. * Init service functions
  6582. */
  6583. int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac,
  6584. struct bnx2x_vlan_mac_obj *obj, bool set,
  6585. int mac_type, unsigned long *ramrod_flags)
  6586. {
  6587. int rc;
  6588. struct bnx2x_vlan_mac_ramrod_params ramrod_param;
  6589. memset(&ramrod_param, 0, sizeof(ramrod_param));
  6590. /* Fill general parameters */
  6591. ramrod_param.vlan_mac_obj = obj;
  6592. ramrod_param.ramrod_flags = *ramrod_flags;
  6593. /* Fill a user request section if needed */
  6594. if (!test_bit(RAMROD_CONT, ramrod_flags)) {
  6595. memcpy(ramrod_param.user_req.u.mac.mac, mac, ETH_ALEN);
  6596. __set_bit(mac_type, &ramrod_param.user_req.vlan_mac_flags);
  6597. /* Set the command: ADD or DEL */
  6598. if (set)
  6599. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD;
  6600. else
  6601. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_DEL;
  6602. }
  6603. rc = bnx2x_config_vlan_mac(bp, &ramrod_param);
  6604. if (rc == -EEXIST) {
  6605. DP(BNX2X_MSG_SP, "Failed to schedule ADD operations: %d\n", rc);
  6606. /* do not treat adding same MAC as error */
  6607. rc = 0;
  6608. } else if (rc < 0)
  6609. BNX2X_ERR("%s MAC failed\n", (set ? "Set" : "Del"));
  6610. return rc;
  6611. }
  6612. int bnx2x_del_all_macs(struct bnx2x *bp,
  6613. struct bnx2x_vlan_mac_obj *mac_obj,
  6614. int mac_type, bool wait_for_comp)
  6615. {
  6616. int rc;
  6617. unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
  6618. /* Wait for completion of requested */
  6619. if (wait_for_comp)
  6620. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  6621. /* Set the mac type of addresses we want to clear */
  6622. __set_bit(mac_type, &vlan_mac_flags);
  6623. rc = mac_obj->delete_all(bp, mac_obj, &vlan_mac_flags, &ramrod_flags);
  6624. if (rc < 0)
  6625. BNX2X_ERR("Failed to delete MACs: %d\n", rc);
  6626. return rc;
  6627. }
  6628. int bnx2x_set_eth_mac(struct bnx2x *bp, bool set)
  6629. {
  6630. if (is_zero_ether_addr(bp->dev->dev_addr) &&
  6631. (IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp))) {
  6632. DP(NETIF_MSG_IFUP | NETIF_MSG_IFDOWN,
  6633. "Ignoring Zero MAC for STORAGE SD mode\n");
  6634. return 0;
  6635. }
  6636. if (IS_PF(bp)) {
  6637. unsigned long ramrod_flags = 0;
  6638. DP(NETIF_MSG_IFUP, "Adding Eth MAC\n");
  6639. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  6640. return bnx2x_set_mac_one(bp, bp->dev->dev_addr,
  6641. &bp->sp_objs->mac_obj, set,
  6642. BNX2X_ETH_MAC, &ramrod_flags);
  6643. } else { /* vf */
  6644. return bnx2x_vfpf_config_mac(bp, bp->dev->dev_addr,
  6645. bp->fp->index, true);
  6646. }
  6647. }
  6648. int bnx2x_setup_leading(struct bnx2x *bp)
  6649. {
  6650. return bnx2x_setup_queue(bp, &bp->fp[0], 1);
  6651. }
  6652. /**
  6653. * bnx2x_set_int_mode - configure interrupt mode
  6654. *
  6655. * @bp: driver handle
  6656. *
  6657. * In case of MSI-X it will also try to enable MSI-X.
  6658. */
  6659. int bnx2x_set_int_mode(struct bnx2x *bp)
  6660. {
  6661. int rc = 0;
  6662. if (IS_VF(bp) && int_mode != BNX2X_INT_MODE_MSIX)
  6663. return -EINVAL;
  6664. switch (int_mode) {
  6665. case BNX2X_INT_MODE_MSIX:
  6666. /* attempt to enable msix */
  6667. rc = bnx2x_enable_msix(bp);
  6668. /* msix attained */
  6669. if (!rc)
  6670. return 0;
  6671. /* vfs use only msix */
  6672. if (rc && IS_VF(bp))
  6673. return rc;
  6674. /* failed to enable multiple MSI-X */
  6675. BNX2X_DEV_INFO("Failed to enable multiple MSI-X (%d), set number of queues to %d\n",
  6676. bp->num_queues,
  6677. 1 + bp->num_cnic_queues);
  6678. /* falling through... */
  6679. case BNX2X_INT_MODE_MSI:
  6680. bnx2x_enable_msi(bp);
  6681. /* falling through... */
  6682. case BNX2X_INT_MODE_INTX:
  6683. bp->num_ethernet_queues = 1;
  6684. bp->num_queues = bp->num_ethernet_queues + bp->num_cnic_queues;
  6685. BNX2X_DEV_INFO("set number of queues to 1\n");
  6686. break;
  6687. default:
  6688. BNX2X_DEV_INFO("unknown value in int_mode module parameter\n");
  6689. return -EINVAL;
  6690. }
  6691. return 0;
  6692. }
  6693. /* must be called prior to any HW initializations */
  6694. static inline u16 bnx2x_cid_ilt_lines(struct bnx2x *bp)
  6695. {
  6696. if (IS_SRIOV(bp))
  6697. return (BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)/ILT_PAGE_CIDS;
  6698. return L2_ILT_LINES(bp);
  6699. }
  6700. void bnx2x_ilt_set_info(struct bnx2x *bp)
  6701. {
  6702. struct ilt_client_info *ilt_client;
  6703. struct bnx2x_ilt *ilt = BP_ILT(bp);
  6704. u16 line = 0;
  6705. ilt->start_line = FUNC_ILT_BASE(BP_FUNC(bp));
  6706. DP(BNX2X_MSG_SP, "ilt starts at line %d\n", ilt->start_line);
  6707. /* CDU */
  6708. ilt_client = &ilt->clients[ILT_CLIENT_CDU];
  6709. ilt_client->client_num = ILT_CLIENT_CDU;
  6710. ilt_client->page_size = CDU_ILT_PAGE_SZ;
  6711. ilt_client->flags = ILT_CLIENT_SKIP_MEM;
  6712. ilt_client->start = line;
  6713. line += bnx2x_cid_ilt_lines(bp);
  6714. if (CNIC_SUPPORT(bp))
  6715. line += CNIC_ILT_LINES;
  6716. ilt_client->end = line - 1;
  6717. DP(NETIF_MSG_IFUP, "ilt client[CDU]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6718. ilt_client->start,
  6719. ilt_client->end,
  6720. ilt_client->page_size,
  6721. ilt_client->flags,
  6722. ilog2(ilt_client->page_size >> 12));
  6723. /* QM */
  6724. if (QM_INIT(bp->qm_cid_count)) {
  6725. ilt_client = &ilt->clients[ILT_CLIENT_QM];
  6726. ilt_client->client_num = ILT_CLIENT_QM;
  6727. ilt_client->page_size = QM_ILT_PAGE_SZ;
  6728. ilt_client->flags = 0;
  6729. ilt_client->start = line;
  6730. /* 4 bytes for each cid */
  6731. line += DIV_ROUND_UP(bp->qm_cid_count * QM_QUEUES_PER_FUNC * 4,
  6732. QM_ILT_PAGE_SZ);
  6733. ilt_client->end = line - 1;
  6734. DP(NETIF_MSG_IFUP,
  6735. "ilt client[QM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6736. ilt_client->start,
  6737. ilt_client->end,
  6738. ilt_client->page_size,
  6739. ilt_client->flags,
  6740. ilog2(ilt_client->page_size >> 12));
  6741. }
  6742. if (CNIC_SUPPORT(bp)) {
  6743. /* SRC */
  6744. ilt_client = &ilt->clients[ILT_CLIENT_SRC];
  6745. ilt_client->client_num = ILT_CLIENT_SRC;
  6746. ilt_client->page_size = SRC_ILT_PAGE_SZ;
  6747. ilt_client->flags = 0;
  6748. ilt_client->start = line;
  6749. line += SRC_ILT_LINES;
  6750. ilt_client->end = line - 1;
  6751. DP(NETIF_MSG_IFUP,
  6752. "ilt client[SRC]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6753. ilt_client->start,
  6754. ilt_client->end,
  6755. ilt_client->page_size,
  6756. ilt_client->flags,
  6757. ilog2(ilt_client->page_size >> 12));
  6758. /* TM */
  6759. ilt_client = &ilt->clients[ILT_CLIENT_TM];
  6760. ilt_client->client_num = ILT_CLIENT_TM;
  6761. ilt_client->page_size = TM_ILT_PAGE_SZ;
  6762. ilt_client->flags = 0;
  6763. ilt_client->start = line;
  6764. line += TM_ILT_LINES;
  6765. ilt_client->end = line - 1;
  6766. DP(NETIF_MSG_IFUP,
  6767. "ilt client[TM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6768. ilt_client->start,
  6769. ilt_client->end,
  6770. ilt_client->page_size,
  6771. ilt_client->flags,
  6772. ilog2(ilt_client->page_size >> 12));
  6773. }
  6774. BUG_ON(line > ILT_MAX_LINES);
  6775. }
  6776. /**
  6777. * bnx2x_pf_q_prep_init - prepare INIT transition parameters
  6778. *
  6779. * @bp: driver handle
  6780. * @fp: pointer to fastpath
  6781. * @init_params: pointer to parameters structure
  6782. *
  6783. * parameters configured:
  6784. * - HC configuration
  6785. * - Queue's CDU context
  6786. */
  6787. static void bnx2x_pf_q_prep_init(struct bnx2x *bp,
  6788. struct bnx2x_fastpath *fp, struct bnx2x_queue_init_params *init_params)
  6789. {
  6790. u8 cos;
  6791. int cxt_index, cxt_offset;
  6792. /* FCoE Queue uses Default SB, thus has no HC capabilities */
  6793. if (!IS_FCOE_FP(fp)) {
  6794. __set_bit(BNX2X_Q_FLG_HC, &init_params->rx.flags);
  6795. __set_bit(BNX2X_Q_FLG_HC, &init_params->tx.flags);
  6796. /* If HC is supporterd, enable host coalescing in the transition
  6797. * to INIT state.
  6798. */
  6799. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->rx.flags);
  6800. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->tx.flags);
  6801. /* HC rate */
  6802. init_params->rx.hc_rate = bp->rx_ticks ?
  6803. (1000000 / bp->rx_ticks) : 0;
  6804. init_params->tx.hc_rate = bp->tx_ticks ?
  6805. (1000000 / bp->tx_ticks) : 0;
  6806. /* FW SB ID */
  6807. init_params->rx.fw_sb_id = init_params->tx.fw_sb_id =
  6808. fp->fw_sb_id;
  6809. /*
  6810. * CQ index among the SB indices: FCoE clients uses the default
  6811. * SB, therefore it's different.
  6812. */
  6813. init_params->rx.sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  6814. init_params->tx.sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS;
  6815. }
  6816. /* set maximum number of COSs supported by this queue */
  6817. init_params->max_cos = fp->max_cos;
  6818. DP(NETIF_MSG_IFUP, "fp: %d setting queue params max cos to: %d\n",
  6819. fp->index, init_params->max_cos);
  6820. /* set the context pointers queue object */
  6821. for (cos = FIRST_TX_COS_INDEX; cos < init_params->max_cos; cos++) {
  6822. cxt_index = fp->txdata_ptr[cos]->cid / ILT_PAGE_CIDS;
  6823. cxt_offset = fp->txdata_ptr[cos]->cid - (cxt_index *
  6824. ILT_PAGE_CIDS);
  6825. init_params->cxts[cos] =
  6826. &bp->context[cxt_index].vcxt[cxt_offset].eth;
  6827. }
  6828. }
  6829. static int bnx2x_setup_tx_only(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  6830. struct bnx2x_queue_state_params *q_params,
  6831. struct bnx2x_queue_setup_tx_only_params *tx_only_params,
  6832. int tx_index, bool leading)
  6833. {
  6834. memset(tx_only_params, 0, sizeof(*tx_only_params));
  6835. /* Set the command */
  6836. q_params->cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  6837. /* Set tx-only QUEUE flags: don't zero statistics */
  6838. tx_only_params->flags = bnx2x_get_common_flags(bp, fp, false);
  6839. /* choose the index of the cid to send the slow path on */
  6840. tx_only_params->cid_index = tx_index;
  6841. /* Set general TX_ONLY_SETUP parameters */
  6842. bnx2x_pf_q_prep_general(bp, fp, &tx_only_params->gen_params, tx_index);
  6843. /* Set Tx TX_ONLY_SETUP parameters */
  6844. bnx2x_pf_tx_q_prep(bp, fp, &tx_only_params->txq_params, tx_index);
  6845. DP(NETIF_MSG_IFUP,
  6846. "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",
  6847. tx_index, q_params->q_obj->cids[FIRST_TX_COS_INDEX],
  6848. q_params->q_obj->cids[tx_index], q_params->q_obj->cl_id,
  6849. tx_only_params->gen_params.spcl_id, tx_only_params->flags);
  6850. /* send the ramrod */
  6851. return bnx2x_queue_state_change(bp, q_params);
  6852. }
  6853. /**
  6854. * bnx2x_setup_queue - setup queue
  6855. *
  6856. * @bp: driver handle
  6857. * @fp: pointer to fastpath
  6858. * @leading: is leading
  6859. *
  6860. * This function performs 2 steps in a Queue state machine
  6861. * actually: 1) RESET->INIT 2) INIT->SETUP
  6862. */
  6863. int bnx2x_setup_queue(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  6864. bool leading)
  6865. {
  6866. struct bnx2x_queue_state_params q_params = {NULL};
  6867. struct bnx2x_queue_setup_params *setup_params =
  6868. &q_params.params.setup;
  6869. struct bnx2x_queue_setup_tx_only_params *tx_only_params =
  6870. &q_params.params.tx_only;
  6871. int rc;
  6872. u8 tx_index;
  6873. DP(NETIF_MSG_IFUP, "setting up queue %d\n", fp->index);
  6874. /* reset IGU state skip FCoE L2 queue */
  6875. if (!IS_FCOE_FP(fp))
  6876. bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID, 0,
  6877. IGU_INT_ENABLE, 0);
  6878. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  6879. /* We want to wait for completion in this context */
  6880. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  6881. /* Prepare the INIT parameters */
  6882. bnx2x_pf_q_prep_init(bp, fp, &q_params.params.init);
  6883. /* Set the command */
  6884. q_params.cmd = BNX2X_Q_CMD_INIT;
  6885. /* Change the state to INIT */
  6886. rc = bnx2x_queue_state_change(bp, &q_params);
  6887. if (rc) {
  6888. BNX2X_ERR("Queue(%d) INIT failed\n", fp->index);
  6889. return rc;
  6890. }
  6891. DP(NETIF_MSG_IFUP, "init complete\n");
  6892. /* Now move the Queue to the SETUP state... */
  6893. memset(setup_params, 0, sizeof(*setup_params));
  6894. /* Set QUEUE flags */
  6895. setup_params->flags = bnx2x_get_q_flags(bp, fp, leading);
  6896. /* Set general SETUP parameters */
  6897. bnx2x_pf_q_prep_general(bp, fp, &setup_params->gen_params,
  6898. FIRST_TX_COS_INDEX);
  6899. bnx2x_pf_rx_q_prep(bp, fp, &setup_params->pause_params,
  6900. &setup_params->rxq_params);
  6901. bnx2x_pf_tx_q_prep(bp, fp, &setup_params->txq_params,
  6902. FIRST_TX_COS_INDEX);
  6903. /* Set the command */
  6904. q_params.cmd = BNX2X_Q_CMD_SETUP;
  6905. if (IS_FCOE_FP(fp))
  6906. bp->fcoe_init = true;
  6907. /* Change the state to SETUP */
  6908. rc = bnx2x_queue_state_change(bp, &q_params);
  6909. if (rc) {
  6910. BNX2X_ERR("Queue(%d) SETUP failed\n", fp->index);
  6911. return rc;
  6912. }
  6913. /* loop through the relevant tx-only indices */
  6914. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  6915. tx_index < fp->max_cos;
  6916. tx_index++) {
  6917. /* prepare and send tx-only ramrod*/
  6918. rc = bnx2x_setup_tx_only(bp, fp, &q_params,
  6919. tx_only_params, tx_index, leading);
  6920. if (rc) {
  6921. BNX2X_ERR("Queue(%d.%d) TX_ONLY_SETUP failed\n",
  6922. fp->index, tx_index);
  6923. return rc;
  6924. }
  6925. }
  6926. return rc;
  6927. }
  6928. static int bnx2x_stop_queue(struct bnx2x *bp, int index)
  6929. {
  6930. struct bnx2x_fastpath *fp = &bp->fp[index];
  6931. struct bnx2x_fp_txdata *txdata;
  6932. struct bnx2x_queue_state_params q_params = {NULL};
  6933. int rc, tx_index;
  6934. DP(NETIF_MSG_IFDOWN, "stopping queue %d cid %d\n", index, fp->cid);
  6935. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  6936. /* We want to wait for completion in this context */
  6937. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  6938. /* close tx-only connections */
  6939. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  6940. tx_index < fp->max_cos;
  6941. tx_index++){
  6942. /* ascertain this is a normal queue*/
  6943. txdata = fp->txdata_ptr[tx_index];
  6944. DP(NETIF_MSG_IFDOWN, "stopping tx-only queue %d\n",
  6945. txdata->txq_index);
  6946. /* send halt terminate on tx-only connection */
  6947. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  6948. memset(&q_params.params.terminate, 0,
  6949. sizeof(q_params.params.terminate));
  6950. q_params.params.terminate.cid_index = tx_index;
  6951. rc = bnx2x_queue_state_change(bp, &q_params);
  6952. if (rc)
  6953. return rc;
  6954. /* send halt terminate on tx-only connection */
  6955. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  6956. memset(&q_params.params.cfc_del, 0,
  6957. sizeof(q_params.params.cfc_del));
  6958. q_params.params.cfc_del.cid_index = tx_index;
  6959. rc = bnx2x_queue_state_change(bp, &q_params);
  6960. if (rc)
  6961. return rc;
  6962. }
  6963. /* Stop the primary connection: */
  6964. /* ...halt the connection */
  6965. q_params.cmd = BNX2X_Q_CMD_HALT;
  6966. rc = bnx2x_queue_state_change(bp, &q_params);
  6967. if (rc)
  6968. return rc;
  6969. /* ...terminate the connection */
  6970. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  6971. memset(&q_params.params.terminate, 0,
  6972. sizeof(q_params.params.terminate));
  6973. q_params.params.terminate.cid_index = FIRST_TX_COS_INDEX;
  6974. rc = bnx2x_queue_state_change(bp, &q_params);
  6975. if (rc)
  6976. return rc;
  6977. /* ...delete cfc entry */
  6978. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  6979. memset(&q_params.params.cfc_del, 0,
  6980. sizeof(q_params.params.cfc_del));
  6981. q_params.params.cfc_del.cid_index = FIRST_TX_COS_INDEX;
  6982. return bnx2x_queue_state_change(bp, &q_params);
  6983. }
  6984. static void bnx2x_reset_func(struct bnx2x *bp)
  6985. {
  6986. int port = BP_PORT(bp);
  6987. int func = BP_FUNC(bp);
  6988. int i;
  6989. /* Disable the function in the FW */
  6990. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0);
  6991. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0);
  6992. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0);
  6993. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0);
  6994. /* FP SBs */
  6995. for_each_eth_queue(bp, i) {
  6996. struct bnx2x_fastpath *fp = &bp->fp[i];
  6997. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6998. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id),
  6999. SB_DISABLED);
  7000. }
  7001. if (CNIC_LOADED(bp))
  7002. /* CNIC SB */
  7003. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  7004. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET
  7005. (bnx2x_cnic_fw_sb_id(bp)), SB_DISABLED);
  7006. /* SP SB */
  7007. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  7008. CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func),
  7009. SB_DISABLED);
  7010. for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++)
  7011. REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func),
  7012. 0);
  7013. /* Configure IGU */
  7014. if (bp->common.int_block == INT_BLOCK_HC) {
  7015. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  7016. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  7017. } else {
  7018. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  7019. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  7020. }
  7021. if (CNIC_LOADED(bp)) {
  7022. /* Disable Timer scan */
  7023. REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 0);
  7024. /*
  7025. * Wait for at least 10ms and up to 2 second for the timers
  7026. * scan to complete
  7027. */
  7028. for (i = 0; i < 200; i++) {
  7029. msleep(10);
  7030. if (!REG_RD(bp, TM_REG_LIN0_SCAN_ON + port*4))
  7031. break;
  7032. }
  7033. }
  7034. /* Clear ILT */
  7035. bnx2x_clear_func_ilt(bp, func);
  7036. /* Timers workaround bug for E2: if this is vnic-3,
  7037. * we need to set the entire ilt range for this timers.
  7038. */
  7039. if (!CHIP_IS_E1x(bp) && BP_VN(bp) == 3) {
  7040. struct ilt_client_info ilt_cli;
  7041. /* use dummy TM client */
  7042. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  7043. ilt_cli.start = 0;
  7044. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  7045. ilt_cli.client_num = ILT_CLIENT_TM;
  7046. bnx2x_ilt_boundry_init_op(bp, &ilt_cli, 0, INITOP_CLEAR);
  7047. }
  7048. /* this assumes that reset_port() called before reset_func()*/
  7049. if (!CHIP_IS_E1x(bp))
  7050. bnx2x_pf_disable(bp);
  7051. bp->dmae_ready = 0;
  7052. }
  7053. static void bnx2x_reset_port(struct bnx2x *bp)
  7054. {
  7055. int port = BP_PORT(bp);
  7056. u32 val;
  7057. /* Reset physical Link */
  7058. bnx2x__link_reset(bp);
  7059. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  7060. /* Do not rcv packets to BRB */
  7061. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0);
  7062. /* Do not direct rcv packets that are not for MCP to the BRB */
  7063. REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
  7064. NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
  7065. /* Configure AEU */
  7066. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0);
  7067. msleep(100);
  7068. /* Check for BRB port occupancy */
  7069. val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4);
  7070. if (val)
  7071. DP(NETIF_MSG_IFDOWN,
  7072. "BRB1 is not empty %d blocks are occupied\n", val);
  7073. /* TODO: Close Doorbell port? */
  7074. }
  7075. static int bnx2x_reset_hw(struct bnx2x *bp, u32 load_code)
  7076. {
  7077. struct bnx2x_func_state_params func_params = {NULL};
  7078. /* Prepare parameters for function state transitions */
  7079. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  7080. func_params.f_obj = &bp->func_obj;
  7081. func_params.cmd = BNX2X_F_CMD_HW_RESET;
  7082. func_params.params.hw_init.load_phase = load_code;
  7083. return bnx2x_func_state_change(bp, &func_params);
  7084. }
  7085. static int bnx2x_func_stop(struct bnx2x *bp)
  7086. {
  7087. struct bnx2x_func_state_params func_params = {NULL};
  7088. int rc;
  7089. /* Prepare parameters for function state transitions */
  7090. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  7091. func_params.f_obj = &bp->func_obj;
  7092. func_params.cmd = BNX2X_F_CMD_STOP;
  7093. /*
  7094. * Try to stop the function the 'good way'. If fails (in case
  7095. * of a parity error during bnx2x_chip_cleanup()) and we are
  7096. * not in a debug mode, perform a state transaction in order to
  7097. * enable further HW_RESET transaction.
  7098. */
  7099. rc = bnx2x_func_state_change(bp, &func_params);
  7100. if (rc) {
  7101. #ifdef BNX2X_STOP_ON_ERROR
  7102. return rc;
  7103. #else
  7104. BNX2X_ERR("FUNC_STOP ramrod failed. Running a dry transaction\n");
  7105. __set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags);
  7106. return bnx2x_func_state_change(bp, &func_params);
  7107. #endif
  7108. }
  7109. return 0;
  7110. }
  7111. /**
  7112. * bnx2x_send_unload_req - request unload mode from the MCP.
  7113. *
  7114. * @bp: driver handle
  7115. * @unload_mode: requested function's unload mode
  7116. *
  7117. * Return unload mode returned by the MCP: COMMON, PORT or FUNC.
  7118. */
  7119. u32 bnx2x_send_unload_req(struct bnx2x *bp, int unload_mode)
  7120. {
  7121. u32 reset_code = 0;
  7122. int port = BP_PORT(bp);
  7123. /* Select the UNLOAD request mode */
  7124. if (unload_mode == UNLOAD_NORMAL)
  7125. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  7126. else if (bp->flags & NO_WOL_FLAG)
  7127. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP;
  7128. else if (bp->wol) {
  7129. u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
  7130. u8 *mac_addr = bp->dev->dev_addr;
  7131. u32 val;
  7132. u16 pmc;
  7133. /* The mac address is written to entries 1-4 to
  7134. * preserve entry 0 which is used by the PMF
  7135. */
  7136. u8 entry = (BP_VN(bp) + 1)*8;
  7137. val = (mac_addr[0] << 8) | mac_addr[1];
  7138. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val);
  7139. val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
  7140. (mac_addr[4] << 8) | mac_addr[5];
  7141. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val);
  7142. /* Enable the PME and clear the status */
  7143. pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, &pmc);
  7144. pmc |= PCI_PM_CTRL_PME_ENABLE | PCI_PM_CTRL_PME_STATUS;
  7145. pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, pmc);
  7146. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN;
  7147. } else
  7148. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  7149. /* Send the request to the MCP */
  7150. if (!BP_NOMCP(bp))
  7151. reset_code = bnx2x_fw_command(bp, reset_code, 0);
  7152. else {
  7153. int path = BP_PATH(bp);
  7154. DP(NETIF_MSG_IFDOWN, "NO MCP - load counts[%d] %d, %d, %d\n",
  7155. path, load_count[path][0], load_count[path][1],
  7156. load_count[path][2]);
  7157. load_count[path][0]--;
  7158. load_count[path][1 + port]--;
  7159. DP(NETIF_MSG_IFDOWN, "NO MCP - new load counts[%d] %d, %d, %d\n",
  7160. path, load_count[path][0], load_count[path][1],
  7161. load_count[path][2]);
  7162. if (load_count[path][0] == 0)
  7163. reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON;
  7164. else if (load_count[path][1 + port] == 0)
  7165. reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT;
  7166. else
  7167. reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION;
  7168. }
  7169. return reset_code;
  7170. }
  7171. /**
  7172. * bnx2x_send_unload_done - send UNLOAD_DONE command to the MCP.
  7173. *
  7174. * @bp: driver handle
  7175. * @keep_link: true iff link should be kept up
  7176. */
  7177. void bnx2x_send_unload_done(struct bnx2x *bp, bool keep_link)
  7178. {
  7179. u32 reset_param = keep_link ? DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET : 0;
  7180. /* Report UNLOAD_DONE to MCP */
  7181. if (!BP_NOMCP(bp))
  7182. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, reset_param);
  7183. }
  7184. static int bnx2x_func_wait_started(struct bnx2x *bp)
  7185. {
  7186. int tout = 50;
  7187. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  7188. if (!bp->port.pmf)
  7189. return 0;
  7190. /*
  7191. * (assumption: No Attention from MCP at this stage)
  7192. * PMF probably in the middle of TXdisable/enable transaction
  7193. * 1. Sync IRS for default SB
  7194. * 2. Sync SP queue - this guarantes us that attention handling started
  7195. * 3. Wait, that TXdisable/enable transaction completes
  7196. *
  7197. * 1+2 guranty that if DCBx attention was scheduled it already changed
  7198. * pending bit of transaction from STARTED-->TX_STOPPED, if we alredy
  7199. * received complettion for the transaction the state is TX_STOPPED.
  7200. * State will return to STARTED after completion of TX_STOPPED-->STARTED
  7201. * transaction.
  7202. */
  7203. /* make sure default SB ISR is done */
  7204. if (msix)
  7205. synchronize_irq(bp->msix_table[0].vector);
  7206. else
  7207. synchronize_irq(bp->pdev->irq);
  7208. flush_workqueue(bnx2x_wq);
  7209. while (bnx2x_func_get_state(bp, &bp->func_obj) !=
  7210. BNX2X_F_STATE_STARTED && tout--)
  7211. msleep(20);
  7212. if (bnx2x_func_get_state(bp, &bp->func_obj) !=
  7213. BNX2X_F_STATE_STARTED) {
  7214. #ifdef BNX2X_STOP_ON_ERROR
  7215. BNX2X_ERR("Wrong function state\n");
  7216. return -EBUSY;
  7217. #else
  7218. /*
  7219. * Failed to complete the transaction in a "good way"
  7220. * Force both transactions with CLR bit
  7221. */
  7222. struct bnx2x_func_state_params func_params = {NULL};
  7223. DP(NETIF_MSG_IFDOWN,
  7224. "Hmmm... unexpected function state! Forcing STARTED-->TX_ST0PPED-->STARTED\n");
  7225. func_params.f_obj = &bp->func_obj;
  7226. __set_bit(RAMROD_DRV_CLR_ONLY,
  7227. &func_params.ramrod_flags);
  7228. /* STARTED-->TX_ST0PPED */
  7229. func_params.cmd = BNX2X_F_CMD_TX_STOP;
  7230. bnx2x_func_state_change(bp, &func_params);
  7231. /* TX_ST0PPED-->STARTED */
  7232. func_params.cmd = BNX2X_F_CMD_TX_START;
  7233. return bnx2x_func_state_change(bp, &func_params);
  7234. #endif
  7235. }
  7236. return 0;
  7237. }
  7238. void bnx2x_chip_cleanup(struct bnx2x *bp, int unload_mode, bool keep_link)
  7239. {
  7240. int port = BP_PORT(bp);
  7241. int i, rc = 0;
  7242. u8 cos;
  7243. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  7244. u32 reset_code;
  7245. /* Wait until tx fastpath tasks complete */
  7246. for_each_tx_queue(bp, i) {
  7247. struct bnx2x_fastpath *fp = &bp->fp[i];
  7248. for_each_cos_in_tx_queue(fp, cos)
  7249. rc = bnx2x_clean_tx_queue(bp, fp->txdata_ptr[cos]);
  7250. #ifdef BNX2X_STOP_ON_ERROR
  7251. if (rc)
  7252. return;
  7253. #endif
  7254. }
  7255. /* Give HW time to discard old tx messages */
  7256. usleep_range(1000, 2000);
  7257. /* Clean all ETH MACs */
  7258. rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_ETH_MAC,
  7259. false);
  7260. if (rc < 0)
  7261. BNX2X_ERR("Failed to delete all ETH macs: %d\n", rc);
  7262. /* Clean up UC list */
  7263. rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_UC_LIST_MAC,
  7264. true);
  7265. if (rc < 0)
  7266. BNX2X_ERR("Failed to schedule DEL commands for UC MACs list: %d\n",
  7267. rc);
  7268. /* Disable LLH */
  7269. if (!CHIP_IS_E1(bp))
  7270. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  7271. /* Set "drop all" (stop Rx).
  7272. * We need to take a netif_addr_lock() here in order to prevent
  7273. * a race between the completion code and this code.
  7274. */
  7275. netif_addr_lock_bh(bp->dev);
  7276. /* Schedule the rx_mode command */
  7277. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  7278. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  7279. else
  7280. bnx2x_set_storm_rx_mode(bp);
  7281. /* Cleanup multicast configuration */
  7282. rparam.mcast_obj = &bp->mcast_obj;
  7283. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  7284. if (rc < 0)
  7285. BNX2X_ERR("Failed to send DEL multicast command: %d\n", rc);
  7286. netif_addr_unlock_bh(bp->dev);
  7287. bnx2x_iov_chip_cleanup(bp);
  7288. /*
  7289. * Send the UNLOAD_REQUEST to the MCP. This will return if
  7290. * this function should perform FUNC, PORT or COMMON HW
  7291. * reset.
  7292. */
  7293. reset_code = bnx2x_send_unload_req(bp, unload_mode);
  7294. /*
  7295. * (assumption: No Attention from MCP at this stage)
  7296. * PMF probably in the middle of TXdisable/enable transaction
  7297. */
  7298. rc = bnx2x_func_wait_started(bp);
  7299. if (rc) {
  7300. BNX2X_ERR("bnx2x_func_wait_started failed\n");
  7301. #ifdef BNX2X_STOP_ON_ERROR
  7302. return;
  7303. #endif
  7304. }
  7305. /* Close multi and leading connections
  7306. * Completions for ramrods are collected in a synchronous way
  7307. */
  7308. for_each_eth_queue(bp, i)
  7309. if (bnx2x_stop_queue(bp, i))
  7310. #ifdef BNX2X_STOP_ON_ERROR
  7311. return;
  7312. #else
  7313. goto unload_error;
  7314. #endif
  7315. if (CNIC_LOADED(bp)) {
  7316. for_each_cnic_queue(bp, i)
  7317. if (bnx2x_stop_queue(bp, i))
  7318. #ifdef BNX2X_STOP_ON_ERROR
  7319. return;
  7320. #else
  7321. goto unload_error;
  7322. #endif
  7323. }
  7324. /* If SP settings didn't get completed so far - something
  7325. * very wrong has happen.
  7326. */
  7327. if (!bnx2x_wait_sp_comp(bp, ~0x0UL))
  7328. BNX2X_ERR("Hmmm... Common slow path ramrods got stuck!\n");
  7329. #ifndef BNX2X_STOP_ON_ERROR
  7330. unload_error:
  7331. #endif
  7332. rc = bnx2x_func_stop(bp);
  7333. if (rc) {
  7334. BNX2X_ERR("Function stop failed!\n");
  7335. #ifdef BNX2X_STOP_ON_ERROR
  7336. return;
  7337. #endif
  7338. }
  7339. /* Disable HW interrupts, NAPI */
  7340. bnx2x_netif_stop(bp, 1);
  7341. /* Delete all NAPI objects */
  7342. bnx2x_del_all_napi(bp);
  7343. if (CNIC_LOADED(bp))
  7344. bnx2x_del_all_napi_cnic(bp);
  7345. /* Release IRQs */
  7346. bnx2x_free_irq(bp);
  7347. /* Reset the chip */
  7348. rc = bnx2x_reset_hw(bp, reset_code);
  7349. if (rc)
  7350. BNX2X_ERR("HW_RESET failed\n");
  7351. /* Report UNLOAD_DONE to MCP */
  7352. bnx2x_send_unload_done(bp, keep_link);
  7353. }
  7354. void bnx2x_disable_close_the_gate(struct bnx2x *bp)
  7355. {
  7356. u32 val;
  7357. DP(NETIF_MSG_IFDOWN, "Disabling \"close the gates\"\n");
  7358. if (CHIP_IS_E1(bp)) {
  7359. int port = BP_PORT(bp);
  7360. u32 addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  7361. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  7362. val = REG_RD(bp, addr);
  7363. val &= ~(0x300);
  7364. REG_WR(bp, addr, val);
  7365. } else {
  7366. val = REG_RD(bp, MISC_REG_AEU_GENERAL_MASK);
  7367. val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK |
  7368. MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK);
  7369. REG_WR(bp, MISC_REG_AEU_GENERAL_MASK, val);
  7370. }
  7371. }
  7372. /* Close gates #2, #3 and #4: */
  7373. static void bnx2x_set_234_gates(struct bnx2x *bp, bool close)
  7374. {
  7375. u32 val;
  7376. /* Gates #2 and #4a are closed/opened for "not E1" only */
  7377. if (!CHIP_IS_E1(bp)) {
  7378. /* #4 */
  7379. REG_WR(bp, PXP_REG_HST_DISCARD_DOORBELLS, !!close);
  7380. /* #2 */
  7381. REG_WR(bp, PXP_REG_HST_DISCARD_INTERNAL_WRITES, !!close);
  7382. }
  7383. /* #3 */
  7384. if (CHIP_IS_E1x(bp)) {
  7385. /* Prevent interrupts from HC on both ports */
  7386. val = REG_RD(bp, HC_REG_CONFIG_1);
  7387. REG_WR(bp, HC_REG_CONFIG_1,
  7388. (!close) ? (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1) :
  7389. (val & ~(u32)HC_CONFIG_1_REG_BLOCK_DISABLE_1));
  7390. val = REG_RD(bp, HC_REG_CONFIG_0);
  7391. REG_WR(bp, HC_REG_CONFIG_0,
  7392. (!close) ? (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0) :
  7393. (val & ~(u32)HC_CONFIG_0_REG_BLOCK_DISABLE_0));
  7394. } else {
  7395. /* Prevent incoming interrupts in IGU */
  7396. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  7397. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION,
  7398. (!close) ?
  7399. (val | IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE) :
  7400. (val & ~(u32)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE));
  7401. }
  7402. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "%s gates #2, #3 and #4\n",
  7403. close ? "closing" : "opening");
  7404. mmiowb();
  7405. }
  7406. #define SHARED_MF_CLP_MAGIC 0x80000000 /* `magic' bit */
  7407. static void bnx2x_clp_reset_prep(struct bnx2x *bp, u32 *magic_val)
  7408. {
  7409. /* Do some magic... */
  7410. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  7411. *magic_val = val & SHARED_MF_CLP_MAGIC;
  7412. MF_CFG_WR(bp, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC);
  7413. }
  7414. /**
  7415. * bnx2x_clp_reset_done - restore the value of the `magic' bit.
  7416. *
  7417. * @bp: driver handle
  7418. * @magic_val: old value of the `magic' bit.
  7419. */
  7420. static void bnx2x_clp_reset_done(struct bnx2x *bp, u32 magic_val)
  7421. {
  7422. /* Restore the `magic' bit value... */
  7423. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  7424. MF_CFG_WR(bp, shared_mf_config.clp_mb,
  7425. (val & (~SHARED_MF_CLP_MAGIC)) | magic_val);
  7426. }
  7427. /**
  7428. * bnx2x_reset_mcp_prep - prepare for MCP reset.
  7429. *
  7430. * @bp: driver handle
  7431. * @magic_val: old value of 'magic' bit.
  7432. *
  7433. * Takes care of CLP configurations.
  7434. */
  7435. static void bnx2x_reset_mcp_prep(struct bnx2x *bp, u32 *magic_val)
  7436. {
  7437. u32 shmem;
  7438. u32 validity_offset;
  7439. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "Starting\n");
  7440. /* Set `magic' bit in order to save MF config */
  7441. if (!CHIP_IS_E1(bp))
  7442. bnx2x_clp_reset_prep(bp, magic_val);
  7443. /* Get shmem offset */
  7444. shmem = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  7445. validity_offset =
  7446. offsetof(struct shmem_region, validity_map[BP_PORT(bp)]);
  7447. /* Clear validity map flags */
  7448. if (shmem > 0)
  7449. REG_WR(bp, shmem + validity_offset, 0);
  7450. }
  7451. #define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */
  7452. #define MCP_ONE_TIMEOUT 100 /* 100 ms */
  7453. /**
  7454. * bnx2x_mcp_wait_one - wait for MCP_ONE_TIMEOUT
  7455. *
  7456. * @bp: driver handle
  7457. */
  7458. static void bnx2x_mcp_wait_one(struct bnx2x *bp)
  7459. {
  7460. /* special handling for emulation and FPGA,
  7461. wait 10 times longer */
  7462. if (CHIP_REV_IS_SLOW(bp))
  7463. msleep(MCP_ONE_TIMEOUT*10);
  7464. else
  7465. msleep(MCP_ONE_TIMEOUT);
  7466. }
  7467. /*
  7468. * initializes bp->common.shmem_base and waits for validity signature to appear
  7469. */
  7470. static int bnx2x_init_shmem(struct bnx2x *bp)
  7471. {
  7472. int cnt = 0;
  7473. u32 val = 0;
  7474. do {
  7475. bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  7476. if (bp->common.shmem_base) {
  7477. val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
  7478. if (val & SHR_MEM_VALIDITY_MB)
  7479. return 0;
  7480. }
  7481. bnx2x_mcp_wait_one(bp);
  7482. } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT));
  7483. BNX2X_ERR("BAD MCP validity signature\n");
  7484. return -ENODEV;
  7485. }
  7486. static int bnx2x_reset_mcp_comp(struct bnx2x *bp, u32 magic_val)
  7487. {
  7488. int rc = bnx2x_init_shmem(bp);
  7489. /* Restore the `magic' bit value */
  7490. if (!CHIP_IS_E1(bp))
  7491. bnx2x_clp_reset_done(bp, magic_val);
  7492. return rc;
  7493. }
  7494. static void bnx2x_pxp_prep(struct bnx2x *bp)
  7495. {
  7496. if (!CHIP_IS_E1(bp)) {
  7497. REG_WR(bp, PXP2_REG_RD_START_INIT, 0);
  7498. REG_WR(bp, PXP2_REG_RQ_RBC_DONE, 0);
  7499. mmiowb();
  7500. }
  7501. }
  7502. /*
  7503. * Reset the whole chip except for:
  7504. * - PCIE core
  7505. * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by
  7506. * one reset bit)
  7507. * - IGU
  7508. * - MISC (including AEU)
  7509. * - GRC
  7510. * - RBCN, RBCP
  7511. */
  7512. static void bnx2x_process_kill_chip_reset(struct bnx2x *bp, bool global)
  7513. {
  7514. u32 not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2;
  7515. u32 global_bits2, stay_reset2;
  7516. /*
  7517. * Bits that have to be set in reset_mask2 if we want to reset 'global'
  7518. * (per chip) blocks.
  7519. */
  7520. global_bits2 =
  7521. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU |
  7522. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE;
  7523. /* Don't reset the following blocks.
  7524. * Important: per port blocks (such as EMAC, BMAC, UMAC) can't be
  7525. * reset, as in 4 port device they might still be owned
  7526. * by the MCP (there is only one leader per path).
  7527. */
  7528. not_reset_mask1 =
  7529. MISC_REGISTERS_RESET_REG_1_RST_HC |
  7530. MISC_REGISTERS_RESET_REG_1_RST_PXPV |
  7531. MISC_REGISTERS_RESET_REG_1_RST_PXP;
  7532. not_reset_mask2 =
  7533. MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO |
  7534. MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE |
  7535. MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE |
  7536. MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE |
  7537. MISC_REGISTERS_RESET_REG_2_RST_RBCN |
  7538. MISC_REGISTERS_RESET_REG_2_RST_GRC |
  7539. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE |
  7540. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B |
  7541. MISC_REGISTERS_RESET_REG_2_RST_ATC |
  7542. MISC_REGISTERS_RESET_REG_2_PGLC |
  7543. MISC_REGISTERS_RESET_REG_2_RST_BMAC0 |
  7544. MISC_REGISTERS_RESET_REG_2_RST_BMAC1 |
  7545. MISC_REGISTERS_RESET_REG_2_RST_EMAC0 |
  7546. MISC_REGISTERS_RESET_REG_2_RST_EMAC1 |
  7547. MISC_REGISTERS_RESET_REG_2_UMAC0 |
  7548. MISC_REGISTERS_RESET_REG_2_UMAC1;
  7549. /*
  7550. * Keep the following blocks in reset:
  7551. * - all xxMACs are handled by the bnx2x_link code.
  7552. */
  7553. stay_reset2 =
  7554. MISC_REGISTERS_RESET_REG_2_XMAC |
  7555. MISC_REGISTERS_RESET_REG_2_XMAC_SOFT;
  7556. /* Full reset masks according to the chip */
  7557. reset_mask1 = 0xffffffff;
  7558. if (CHIP_IS_E1(bp))
  7559. reset_mask2 = 0xffff;
  7560. else if (CHIP_IS_E1H(bp))
  7561. reset_mask2 = 0x1ffff;
  7562. else if (CHIP_IS_E2(bp))
  7563. reset_mask2 = 0xfffff;
  7564. else /* CHIP_IS_E3 */
  7565. reset_mask2 = 0x3ffffff;
  7566. /* Don't reset global blocks unless we need to */
  7567. if (!global)
  7568. reset_mask2 &= ~global_bits2;
  7569. /*
  7570. * In case of attention in the QM, we need to reset PXP
  7571. * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM
  7572. * because otherwise QM reset would release 'close the gates' shortly
  7573. * before resetting the PXP, then the PSWRQ would send a write
  7574. * request to PGLUE. Then when PXP is reset, PGLUE would try to
  7575. * read the payload data from PSWWR, but PSWWR would not
  7576. * respond. The write queue in PGLUE would stuck, dmae commands
  7577. * would not return. Therefore it's important to reset the second
  7578. * reset register (containing the
  7579. * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the
  7580. * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM
  7581. * bit).
  7582. */
  7583. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
  7584. reset_mask2 & (~not_reset_mask2));
  7585. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  7586. reset_mask1 & (~not_reset_mask1));
  7587. barrier();
  7588. mmiowb();
  7589. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
  7590. reset_mask2 & (~stay_reset2));
  7591. barrier();
  7592. mmiowb();
  7593. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1);
  7594. mmiowb();
  7595. }
  7596. /**
  7597. * bnx2x_er_poll_igu_vq - poll for pending writes bit.
  7598. * It should get cleared in no more than 1s.
  7599. *
  7600. * @bp: driver handle
  7601. *
  7602. * It should get cleared in no more than 1s. Returns 0 if
  7603. * pending writes bit gets cleared.
  7604. */
  7605. static int bnx2x_er_poll_igu_vq(struct bnx2x *bp)
  7606. {
  7607. u32 cnt = 1000;
  7608. u32 pend_bits = 0;
  7609. do {
  7610. pend_bits = REG_RD(bp, IGU_REG_PENDING_BITS_STATUS);
  7611. if (pend_bits == 0)
  7612. break;
  7613. usleep_range(1000, 2000);
  7614. } while (cnt-- > 0);
  7615. if (cnt <= 0) {
  7616. BNX2X_ERR("Still pending IGU requests pend_bits=%x!\n",
  7617. pend_bits);
  7618. return -EBUSY;
  7619. }
  7620. return 0;
  7621. }
  7622. static int bnx2x_process_kill(struct bnx2x *bp, bool global)
  7623. {
  7624. int cnt = 1000;
  7625. u32 val = 0;
  7626. u32 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2;
  7627. u32 tags_63_32 = 0;
  7628. /* Empty the Tetris buffer, wait for 1s */
  7629. do {
  7630. sr_cnt = REG_RD(bp, PXP2_REG_RD_SR_CNT);
  7631. blk_cnt = REG_RD(bp, PXP2_REG_RD_BLK_CNT);
  7632. port_is_idle_0 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_0);
  7633. port_is_idle_1 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_1);
  7634. pgl_exp_rom2 = REG_RD(bp, PXP2_REG_PGL_EXP_ROM2);
  7635. if (CHIP_IS_E3(bp))
  7636. tags_63_32 = REG_RD(bp, PGLUE_B_REG_TAGS_63_32);
  7637. if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) &&
  7638. ((port_is_idle_0 & 0x1) == 0x1) &&
  7639. ((port_is_idle_1 & 0x1) == 0x1) &&
  7640. (pgl_exp_rom2 == 0xffffffff) &&
  7641. (!CHIP_IS_E3(bp) || (tags_63_32 == 0xffffffff)))
  7642. break;
  7643. usleep_range(1000, 2000);
  7644. } while (cnt-- > 0);
  7645. if (cnt <= 0) {
  7646. BNX2X_ERR("Tetris buffer didn't get empty or there are still outstanding read requests after 1s!\n");
  7647. 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",
  7648. sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1,
  7649. pgl_exp_rom2);
  7650. return -EAGAIN;
  7651. }
  7652. barrier();
  7653. /* Close gates #2, #3 and #4 */
  7654. bnx2x_set_234_gates(bp, true);
  7655. /* Poll for IGU VQs for 57712 and newer chips */
  7656. if (!CHIP_IS_E1x(bp) && bnx2x_er_poll_igu_vq(bp))
  7657. return -EAGAIN;
  7658. /* TBD: Indicate that "process kill" is in progress to MCP */
  7659. /* Clear "unprepared" bit */
  7660. REG_WR(bp, MISC_REG_UNPREPARED, 0);
  7661. barrier();
  7662. /* Make sure all is written to the chip before the reset */
  7663. mmiowb();
  7664. /* Wait for 1ms to empty GLUE and PCI-E core queues,
  7665. * PSWHST, GRC and PSWRD Tetris buffer.
  7666. */
  7667. usleep_range(1000, 2000);
  7668. /* Prepare to chip reset: */
  7669. /* MCP */
  7670. if (global)
  7671. bnx2x_reset_mcp_prep(bp, &val);
  7672. /* PXP */
  7673. bnx2x_pxp_prep(bp);
  7674. barrier();
  7675. /* reset the chip */
  7676. bnx2x_process_kill_chip_reset(bp, global);
  7677. barrier();
  7678. /* Recover after reset: */
  7679. /* MCP */
  7680. if (global && bnx2x_reset_mcp_comp(bp, val))
  7681. return -EAGAIN;
  7682. /* TBD: Add resetting the NO_MCP mode DB here */
  7683. /* Open the gates #2, #3 and #4 */
  7684. bnx2x_set_234_gates(bp, false);
  7685. /* TBD: IGU/AEU preparation bring back the AEU/IGU to a
  7686. * reset state, re-enable attentions. */
  7687. return 0;
  7688. }
  7689. static int bnx2x_leader_reset(struct bnx2x *bp)
  7690. {
  7691. int rc = 0;
  7692. bool global = bnx2x_reset_is_global(bp);
  7693. u32 load_code;
  7694. /* if not going to reset MCP - load "fake" driver to reset HW while
  7695. * driver is owner of the HW
  7696. */
  7697. if (!global && !BP_NOMCP(bp)) {
  7698. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_REQ,
  7699. DRV_MSG_CODE_LOAD_REQ_WITH_LFA);
  7700. if (!load_code) {
  7701. BNX2X_ERR("MCP response failure, aborting\n");
  7702. rc = -EAGAIN;
  7703. goto exit_leader_reset;
  7704. }
  7705. if ((load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) &&
  7706. (load_code != FW_MSG_CODE_DRV_LOAD_COMMON)) {
  7707. BNX2X_ERR("MCP unexpected resp, aborting\n");
  7708. rc = -EAGAIN;
  7709. goto exit_leader_reset2;
  7710. }
  7711. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE, 0);
  7712. if (!load_code) {
  7713. BNX2X_ERR("MCP response failure, aborting\n");
  7714. rc = -EAGAIN;
  7715. goto exit_leader_reset2;
  7716. }
  7717. }
  7718. /* Try to recover after the failure */
  7719. if (bnx2x_process_kill(bp, global)) {
  7720. BNX2X_ERR("Something bad had happen on engine %d! Aii!\n",
  7721. BP_PATH(bp));
  7722. rc = -EAGAIN;
  7723. goto exit_leader_reset2;
  7724. }
  7725. /*
  7726. * Clear RESET_IN_PROGRES and RESET_GLOBAL bits and update the driver
  7727. * state.
  7728. */
  7729. bnx2x_set_reset_done(bp);
  7730. if (global)
  7731. bnx2x_clear_reset_global(bp);
  7732. exit_leader_reset2:
  7733. /* unload "fake driver" if it was loaded */
  7734. if (!global && !BP_NOMCP(bp)) {
  7735. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0);
  7736. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
  7737. }
  7738. exit_leader_reset:
  7739. bp->is_leader = 0;
  7740. bnx2x_release_leader_lock(bp);
  7741. smp_mb();
  7742. return rc;
  7743. }
  7744. static void bnx2x_recovery_failed(struct bnx2x *bp)
  7745. {
  7746. netdev_err(bp->dev, "Recovery has failed. Power cycle is needed.\n");
  7747. /* Disconnect this device */
  7748. netif_device_detach(bp->dev);
  7749. /*
  7750. * Block ifup for all function on this engine until "process kill"
  7751. * or power cycle.
  7752. */
  7753. bnx2x_set_reset_in_progress(bp);
  7754. /* Shut down the power */
  7755. bnx2x_set_power_state(bp, PCI_D3hot);
  7756. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  7757. smp_mb();
  7758. }
  7759. /*
  7760. * Assumption: runs under rtnl lock. This together with the fact
  7761. * that it's called only from bnx2x_sp_rtnl() ensure that it
  7762. * will never be called when netif_running(bp->dev) is false.
  7763. */
  7764. static void bnx2x_parity_recover(struct bnx2x *bp)
  7765. {
  7766. bool global = false;
  7767. u32 error_recovered, error_unrecovered;
  7768. bool is_parity;
  7769. DP(NETIF_MSG_HW, "Handling parity\n");
  7770. while (1) {
  7771. switch (bp->recovery_state) {
  7772. case BNX2X_RECOVERY_INIT:
  7773. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_INIT\n");
  7774. is_parity = bnx2x_chk_parity_attn(bp, &global, false);
  7775. WARN_ON(!is_parity);
  7776. /* Try to get a LEADER_LOCK HW lock */
  7777. if (bnx2x_trylock_leader_lock(bp)) {
  7778. bnx2x_set_reset_in_progress(bp);
  7779. /*
  7780. * Check if there is a global attention and if
  7781. * there was a global attention, set the global
  7782. * reset bit.
  7783. */
  7784. if (global)
  7785. bnx2x_set_reset_global(bp);
  7786. bp->is_leader = 1;
  7787. }
  7788. /* Stop the driver */
  7789. /* If interface has been removed - break */
  7790. if (bnx2x_nic_unload(bp, UNLOAD_RECOVERY, false))
  7791. return;
  7792. bp->recovery_state = BNX2X_RECOVERY_WAIT;
  7793. /* Ensure "is_leader", MCP command sequence and
  7794. * "recovery_state" update values are seen on other
  7795. * CPUs.
  7796. */
  7797. smp_mb();
  7798. break;
  7799. case BNX2X_RECOVERY_WAIT:
  7800. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_WAIT\n");
  7801. if (bp->is_leader) {
  7802. int other_engine = BP_PATH(bp) ? 0 : 1;
  7803. bool other_load_status =
  7804. bnx2x_get_load_status(bp, other_engine);
  7805. bool load_status =
  7806. bnx2x_get_load_status(bp, BP_PATH(bp));
  7807. global = bnx2x_reset_is_global(bp);
  7808. /*
  7809. * In case of a parity in a global block, let
  7810. * the first leader that performs a
  7811. * leader_reset() reset the global blocks in
  7812. * order to clear global attentions. Otherwise
  7813. * the the gates will remain closed for that
  7814. * engine.
  7815. */
  7816. if (load_status ||
  7817. (global && other_load_status)) {
  7818. /* Wait until all other functions get
  7819. * down.
  7820. */
  7821. schedule_delayed_work(&bp->sp_rtnl_task,
  7822. HZ/10);
  7823. return;
  7824. } else {
  7825. /* If all other functions got down -
  7826. * try to bring the chip back to
  7827. * normal. In any case it's an exit
  7828. * point for a leader.
  7829. */
  7830. if (bnx2x_leader_reset(bp)) {
  7831. bnx2x_recovery_failed(bp);
  7832. return;
  7833. }
  7834. /* If we are here, means that the
  7835. * leader has succeeded and doesn't
  7836. * want to be a leader any more. Try
  7837. * to continue as a none-leader.
  7838. */
  7839. break;
  7840. }
  7841. } else { /* non-leader */
  7842. if (!bnx2x_reset_is_done(bp, BP_PATH(bp))) {
  7843. /* Try to get a LEADER_LOCK HW lock as
  7844. * long as a former leader may have
  7845. * been unloaded by the user or
  7846. * released a leadership by another
  7847. * reason.
  7848. */
  7849. if (bnx2x_trylock_leader_lock(bp)) {
  7850. /* I'm a leader now! Restart a
  7851. * switch case.
  7852. */
  7853. bp->is_leader = 1;
  7854. break;
  7855. }
  7856. schedule_delayed_work(&bp->sp_rtnl_task,
  7857. HZ/10);
  7858. return;
  7859. } else {
  7860. /*
  7861. * If there was a global attention, wait
  7862. * for it to be cleared.
  7863. */
  7864. if (bnx2x_reset_is_global(bp)) {
  7865. schedule_delayed_work(
  7866. &bp->sp_rtnl_task,
  7867. HZ/10);
  7868. return;
  7869. }
  7870. error_recovered =
  7871. bp->eth_stats.recoverable_error;
  7872. error_unrecovered =
  7873. bp->eth_stats.unrecoverable_error;
  7874. bp->recovery_state =
  7875. BNX2X_RECOVERY_NIC_LOADING;
  7876. if (bnx2x_nic_load(bp, LOAD_NORMAL)) {
  7877. error_unrecovered++;
  7878. netdev_err(bp->dev,
  7879. "Recovery failed. Power cycle needed\n");
  7880. /* Disconnect this device */
  7881. netif_device_detach(bp->dev);
  7882. /* Shut down the power */
  7883. bnx2x_set_power_state(
  7884. bp, PCI_D3hot);
  7885. smp_mb();
  7886. } else {
  7887. bp->recovery_state =
  7888. BNX2X_RECOVERY_DONE;
  7889. error_recovered++;
  7890. smp_mb();
  7891. }
  7892. bp->eth_stats.recoverable_error =
  7893. error_recovered;
  7894. bp->eth_stats.unrecoverable_error =
  7895. error_unrecovered;
  7896. return;
  7897. }
  7898. }
  7899. default:
  7900. return;
  7901. }
  7902. }
  7903. }
  7904. static int bnx2x_close(struct net_device *dev);
  7905. /* bnx2x_nic_unload() flushes the bnx2x_wq, thus reset task is
  7906. * scheduled on a general queue in order to prevent a dead lock.
  7907. */
  7908. static void bnx2x_sp_rtnl_task(struct work_struct *work)
  7909. {
  7910. struct bnx2x *bp = container_of(work, struct bnx2x, sp_rtnl_task.work);
  7911. rtnl_lock();
  7912. if (!netif_running(bp->dev)) {
  7913. rtnl_unlock();
  7914. return;
  7915. }
  7916. /* if stop on error is defined no recovery flows should be executed */
  7917. #ifdef BNX2X_STOP_ON_ERROR
  7918. BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
  7919. "you will need to reboot when done\n");
  7920. goto sp_rtnl_not_reset;
  7921. #endif
  7922. if (unlikely(bp->recovery_state != BNX2X_RECOVERY_DONE)) {
  7923. /*
  7924. * Clear all pending SP commands as we are going to reset the
  7925. * function anyway.
  7926. */
  7927. bp->sp_rtnl_state = 0;
  7928. smp_mb();
  7929. bnx2x_parity_recover(bp);
  7930. rtnl_unlock();
  7931. return;
  7932. }
  7933. if (test_and_clear_bit(BNX2X_SP_RTNL_TX_TIMEOUT, &bp->sp_rtnl_state)) {
  7934. /*
  7935. * Clear all pending SP commands as we are going to reset the
  7936. * function anyway.
  7937. */
  7938. bp->sp_rtnl_state = 0;
  7939. smp_mb();
  7940. bnx2x_nic_unload(bp, UNLOAD_NORMAL, true);
  7941. bnx2x_nic_load(bp, LOAD_NORMAL);
  7942. rtnl_unlock();
  7943. return;
  7944. }
  7945. #ifdef BNX2X_STOP_ON_ERROR
  7946. sp_rtnl_not_reset:
  7947. #endif
  7948. if (test_and_clear_bit(BNX2X_SP_RTNL_SETUP_TC, &bp->sp_rtnl_state))
  7949. bnx2x_setup_tc(bp->dev, bp->dcbx_port_params.ets.num_of_cos);
  7950. if (test_and_clear_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE, &bp->sp_rtnl_state))
  7951. bnx2x_after_function_update(bp);
  7952. /*
  7953. * in case of fan failure we need to reset id if the "stop on error"
  7954. * debug flag is set, since we trying to prevent permanent overheating
  7955. * damage
  7956. */
  7957. if (test_and_clear_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state)) {
  7958. DP(NETIF_MSG_HW, "fan failure detected. Unloading driver\n");
  7959. netif_device_detach(bp->dev);
  7960. bnx2x_close(bp->dev);
  7961. rtnl_unlock();
  7962. return;
  7963. }
  7964. if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_MCAST, &bp->sp_rtnl_state)) {
  7965. DP(BNX2X_MSG_SP,
  7966. "sending set mcast vf pf channel message from rtnl sp-task\n");
  7967. bnx2x_vfpf_set_mcast(bp->dev);
  7968. }
  7969. if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_STORM_RX_MODE,
  7970. &bp->sp_rtnl_state)) {
  7971. DP(BNX2X_MSG_SP,
  7972. "sending set storm rx mode vf pf channel message from rtnl sp-task\n");
  7973. bnx2x_vfpf_storm_rx_mode(bp);
  7974. }
  7975. if (test_and_clear_bit(BNX2X_SP_RTNL_HYPERVISOR_VLAN,
  7976. &bp->sp_rtnl_state))
  7977. bnx2x_pf_set_vfs_vlan(bp);
  7978. /* work which needs rtnl lock not-taken (as it takes the lock itself and
  7979. * can be called from other contexts as well)
  7980. */
  7981. rtnl_unlock();
  7982. /* enable SR-IOV if applicable */
  7983. if (IS_SRIOV(bp) && test_and_clear_bit(BNX2X_SP_RTNL_ENABLE_SRIOV,
  7984. &bp->sp_rtnl_state)) {
  7985. bnx2x_disable_sriov(bp);
  7986. bnx2x_enable_sriov(bp);
  7987. }
  7988. }
  7989. static void bnx2x_period_task(struct work_struct *work)
  7990. {
  7991. struct bnx2x *bp = container_of(work, struct bnx2x, period_task.work);
  7992. if (!netif_running(bp->dev))
  7993. goto period_task_exit;
  7994. if (CHIP_REV_IS_SLOW(bp)) {
  7995. BNX2X_ERR("period task called on emulation, ignoring\n");
  7996. goto period_task_exit;
  7997. }
  7998. bnx2x_acquire_phy_lock(bp);
  7999. /*
  8000. * The barrier is needed to ensure the ordering between the writing to
  8001. * the bp->port.pmf in the bnx2x_nic_load() or bnx2x_pmf_update() and
  8002. * the reading here.
  8003. */
  8004. smp_mb();
  8005. if (bp->port.pmf) {
  8006. bnx2x_period_func(&bp->link_params, &bp->link_vars);
  8007. /* Re-queue task in 1 sec */
  8008. queue_delayed_work(bnx2x_wq, &bp->period_task, 1*HZ);
  8009. }
  8010. bnx2x_release_phy_lock(bp);
  8011. period_task_exit:
  8012. return;
  8013. }
  8014. /*
  8015. * Init service functions
  8016. */
  8017. u32 bnx2x_get_pretend_reg(struct bnx2x *bp)
  8018. {
  8019. u32 base = PXP2_REG_PGL_PRETEND_FUNC_F0;
  8020. u32 stride = PXP2_REG_PGL_PRETEND_FUNC_F1 - base;
  8021. return base + (BP_ABS_FUNC(bp)) * stride;
  8022. }
  8023. static void bnx2x_prev_unload_close_mac(struct bnx2x *bp,
  8024. struct bnx2x_mac_vals *vals)
  8025. {
  8026. u32 val, base_addr, offset, mask, reset_reg;
  8027. bool mac_stopped = false;
  8028. u8 port = BP_PORT(bp);
  8029. /* reset addresses as they also mark which values were changed */
  8030. vals->bmac_addr = 0;
  8031. vals->umac_addr = 0;
  8032. vals->xmac_addr = 0;
  8033. vals->emac_addr = 0;
  8034. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_2);
  8035. if (!CHIP_IS_E3(bp)) {
  8036. val = REG_RD(bp, NIG_REG_BMAC0_REGS_OUT_EN + port * 4);
  8037. mask = MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port;
  8038. if ((mask & reset_reg) && val) {
  8039. u32 wb_data[2];
  8040. BNX2X_DEV_INFO("Disable bmac Rx\n");
  8041. base_addr = BP_PORT(bp) ? NIG_REG_INGRESS_BMAC1_MEM
  8042. : NIG_REG_INGRESS_BMAC0_MEM;
  8043. offset = CHIP_IS_E2(bp) ? BIGMAC2_REGISTER_BMAC_CONTROL
  8044. : BIGMAC_REGISTER_BMAC_CONTROL;
  8045. /*
  8046. * use rd/wr since we cannot use dmae. This is safe
  8047. * since MCP won't access the bus due to the request
  8048. * to unload, and no function on the path can be
  8049. * loaded at this time.
  8050. */
  8051. wb_data[0] = REG_RD(bp, base_addr + offset);
  8052. wb_data[1] = REG_RD(bp, base_addr + offset + 0x4);
  8053. vals->bmac_addr = base_addr + offset;
  8054. vals->bmac_val[0] = wb_data[0];
  8055. vals->bmac_val[1] = wb_data[1];
  8056. wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE;
  8057. REG_WR(bp, vals->bmac_addr, wb_data[0]);
  8058. REG_WR(bp, vals->bmac_addr + 0x4, wb_data[1]);
  8059. }
  8060. BNX2X_DEV_INFO("Disable emac Rx\n");
  8061. vals->emac_addr = NIG_REG_NIG_EMAC0_EN + BP_PORT(bp)*4;
  8062. vals->emac_val = REG_RD(bp, vals->emac_addr);
  8063. REG_WR(bp, vals->emac_addr, 0);
  8064. mac_stopped = true;
  8065. } else {
  8066. if (reset_reg & MISC_REGISTERS_RESET_REG_2_XMAC) {
  8067. BNX2X_DEV_INFO("Disable xmac Rx\n");
  8068. base_addr = BP_PORT(bp) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
  8069. val = REG_RD(bp, base_addr + XMAC_REG_PFC_CTRL_HI);
  8070. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  8071. val & ~(1 << 1));
  8072. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  8073. val | (1 << 1));
  8074. vals->xmac_addr = base_addr + XMAC_REG_CTRL;
  8075. vals->xmac_val = REG_RD(bp, vals->xmac_addr);
  8076. REG_WR(bp, vals->xmac_addr, 0);
  8077. mac_stopped = true;
  8078. }
  8079. mask = MISC_REGISTERS_RESET_REG_2_UMAC0 << port;
  8080. if (mask & reset_reg) {
  8081. BNX2X_DEV_INFO("Disable umac Rx\n");
  8082. base_addr = BP_PORT(bp) ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
  8083. vals->umac_addr = base_addr + UMAC_REG_COMMAND_CONFIG;
  8084. vals->umac_val = REG_RD(bp, vals->umac_addr);
  8085. REG_WR(bp, vals->umac_addr, 0);
  8086. mac_stopped = true;
  8087. }
  8088. }
  8089. if (mac_stopped)
  8090. msleep(20);
  8091. }
  8092. #define BNX2X_PREV_UNDI_PROD_ADDR(p) (BAR_TSTRORM_INTMEM + 0x1508 + ((p) << 4))
  8093. #define BNX2X_PREV_UNDI_RCQ(val) ((val) & 0xffff)
  8094. #define BNX2X_PREV_UNDI_BD(val) ((val) >> 16 & 0xffff)
  8095. #define BNX2X_PREV_UNDI_PROD(rcq, bd) ((bd) << 16 | (rcq))
  8096. static void bnx2x_prev_unload_undi_inc(struct bnx2x *bp, u8 port, u8 inc)
  8097. {
  8098. u16 rcq, bd;
  8099. u32 tmp_reg = REG_RD(bp, BNX2X_PREV_UNDI_PROD_ADDR(port));
  8100. rcq = BNX2X_PREV_UNDI_RCQ(tmp_reg) + inc;
  8101. bd = BNX2X_PREV_UNDI_BD(tmp_reg) + inc;
  8102. tmp_reg = BNX2X_PREV_UNDI_PROD(rcq, bd);
  8103. REG_WR(bp, BNX2X_PREV_UNDI_PROD_ADDR(port), tmp_reg);
  8104. BNX2X_DEV_INFO("UNDI producer [%d] rings bd -> 0x%04x, rcq -> 0x%04x\n",
  8105. port, bd, rcq);
  8106. }
  8107. static int bnx2x_prev_mcp_done(struct bnx2x *bp)
  8108. {
  8109. u32 rc = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE,
  8110. DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET);
  8111. if (!rc) {
  8112. BNX2X_ERR("MCP response failure, aborting\n");
  8113. return -EBUSY;
  8114. }
  8115. return 0;
  8116. }
  8117. static struct bnx2x_prev_path_list *
  8118. bnx2x_prev_path_get_entry(struct bnx2x *bp)
  8119. {
  8120. struct bnx2x_prev_path_list *tmp_list;
  8121. list_for_each_entry(tmp_list, &bnx2x_prev_list, list)
  8122. if (PCI_SLOT(bp->pdev->devfn) == tmp_list->slot &&
  8123. bp->pdev->bus->number == tmp_list->bus &&
  8124. BP_PATH(bp) == tmp_list->path)
  8125. return tmp_list;
  8126. return NULL;
  8127. }
  8128. static int bnx2x_prev_path_mark_eeh(struct bnx2x *bp)
  8129. {
  8130. struct bnx2x_prev_path_list *tmp_list;
  8131. int rc;
  8132. rc = down_interruptible(&bnx2x_prev_sem);
  8133. if (rc) {
  8134. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  8135. return rc;
  8136. }
  8137. tmp_list = bnx2x_prev_path_get_entry(bp);
  8138. if (tmp_list) {
  8139. tmp_list->aer = 1;
  8140. rc = 0;
  8141. } else {
  8142. BNX2X_ERR("path %d: Entry does not exist for eeh; Flow occurs before initial insmod is over ?\n",
  8143. BP_PATH(bp));
  8144. }
  8145. up(&bnx2x_prev_sem);
  8146. return rc;
  8147. }
  8148. static bool bnx2x_prev_is_path_marked(struct bnx2x *bp)
  8149. {
  8150. struct bnx2x_prev_path_list *tmp_list;
  8151. int rc = false;
  8152. if (down_trylock(&bnx2x_prev_sem))
  8153. return false;
  8154. tmp_list = bnx2x_prev_path_get_entry(bp);
  8155. if (tmp_list) {
  8156. if (tmp_list->aer) {
  8157. DP(NETIF_MSG_HW, "Path %d was marked by AER\n",
  8158. BP_PATH(bp));
  8159. } else {
  8160. rc = true;
  8161. BNX2X_DEV_INFO("Path %d was already cleaned from previous drivers\n",
  8162. BP_PATH(bp));
  8163. }
  8164. }
  8165. up(&bnx2x_prev_sem);
  8166. return rc;
  8167. }
  8168. bool bnx2x_port_after_undi(struct bnx2x *bp)
  8169. {
  8170. struct bnx2x_prev_path_list *entry;
  8171. bool val;
  8172. down(&bnx2x_prev_sem);
  8173. entry = bnx2x_prev_path_get_entry(bp);
  8174. val = !!(entry && (entry->undi & (1 << BP_PORT(bp))));
  8175. up(&bnx2x_prev_sem);
  8176. return val;
  8177. }
  8178. static int bnx2x_prev_mark_path(struct bnx2x *bp, bool after_undi)
  8179. {
  8180. struct bnx2x_prev_path_list *tmp_list;
  8181. int rc;
  8182. rc = down_interruptible(&bnx2x_prev_sem);
  8183. if (rc) {
  8184. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  8185. return rc;
  8186. }
  8187. /* Check whether the entry for this path already exists */
  8188. tmp_list = bnx2x_prev_path_get_entry(bp);
  8189. if (tmp_list) {
  8190. if (!tmp_list->aer) {
  8191. BNX2X_ERR("Re-Marking the path.\n");
  8192. } else {
  8193. DP(NETIF_MSG_HW, "Removing AER indication from path %d\n",
  8194. BP_PATH(bp));
  8195. tmp_list->aer = 0;
  8196. }
  8197. up(&bnx2x_prev_sem);
  8198. return 0;
  8199. }
  8200. up(&bnx2x_prev_sem);
  8201. /* Create an entry for this path and add it */
  8202. tmp_list = kmalloc(sizeof(struct bnx2x_prev_path_list), GFP_KERNEL);
  8203. if (!tmp_list) {
  8204. BNX2X_ERR("Failed to allocate 'bnx2x_prev_path_list'\n");
  8205. return -ENOMEM;
  8206. }
  8207. tmp_list->bus = bp->pdev->bus->number;
  8208. tmp_list->slot = PCI_SLOT(bp->pdev->devfn);
  8209. tmp_list->path = BP_PATH(bp);
  8210. tmp_list->aer = 0;
  8211. tmp_list->undi = after_undi ? (1 << BP_PORT(bp)) : 0;
  8212. rc = down_interruptible(&bnx2x_prev_sem);
  8213. if (rc) {
  8214. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  8215. kfree(tmp_list);
  8216. } else {
  8217. DP(NETIF_MSG_HW, "Marked path [%d] - finished previous unload\n",
  8218. BP_PATH(bp));
  8219. list_add(&tmp_list->list, &bnx2x_prev_list);
  8220. up(&bnx2x_prev_sem);
  8221. }
  8222. return rc;
  8223. }
  8224. static int bnx2x_do_flr(struct bnx2x *bp)
  8225. {
  8226. int i;
  8227. u16 status;
  8228. struct pci_dev *dev = bp->pdev;
  8229. if (CHIP_IS_E1x(bp)) {
  8230. BNX2X_DEV_INFO("FLR not supported in E1/E1H\n");
  8231. return -EINVAL;
  8232. }
  8233. /* only bootcode REQ_BC_VER_4_INITIATE_FLR and onwards support flr */
  8234. if (bp->common.bc_ver < REQ_BC_VER_4_INITIATE_FLR) {
  8235. BNX2X_ERR("FLR not supported by BC_VER: 0x%x\n",
  8236. bp->common.bc_ver);
  8237. return -EINVAL;
  8238. }
  8239. /* Wait for Transaction Pending bit clean */
  8240. for (i = 0; i < 4; i++) {
  8241. if (i)
  8242. msleep((1 << (i - 1)) * 100);
  8243. pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status);
  8244. if (!(status & PCI_EXP_DEVSTA_TRPND))
  8245. goto clear;
  8246. }
  8247. dev_err(&dev->dev,
  8248. "transaction is not cleared; proceeding with reset anyway\n");
  8249. clear:
  8250. BNX2X_DEV_INFO("Initiating FLR\n");
  8251. bnx2x_fw_command(bp, DRV_MSG_CODE_INITIATE_FLR, 0);
  8252. return 0;
  8253. }
  8254. static int bnx2x_prev_unload_uncommon(struct bnx2x *bp)
  8255. {
  8256. int rc;
  8257. BNX2X_DEV_INFO("Uncommon unload Flow\n");
  8258. /* Test if previous unload process was already finished for this path */
  8259. if (bnx2x_prev_is_path_marked(bp))
  8260. return bnx2x_prev_mcp_done(bp);
  8261. BNX2X_DEV_INFO("Path is unmarked\n");
  8262. /* If function has FLR capabilities, and existing FW version matches
  8263. * the one required, then FLR will be sufficient to clean any residue
  8264. * left by previous driver
  8265. */
  8266. rc = bnx2x_nic_load_analyze_req(bp, FW_MSG_CODE_DRV_LOAD_FUNCTION);
  8267. if (!rc) {
  8268. /* fw version is good */
  8269. BNX2X_DEV_INFO("FW version matches our own. Attempting FLR\n");
  8270. rc = bnx2x_do_flr(bp);
  8271. }
  8272. if (!rc) {
  8273. /* FLR was performed */
  8274. BNX2X_DEV_INFO("FLR successful\n");
  8275. return 0;
  8276. }
  8277. BNX2X_DEV_INFO("Could not FLR\n");
  8278. /* Close the MCP request, return failure*/
  8279. rc = bnx2x_prev_mcp_done(bp);
  8280. if (!rc)
  8281. rc = BNX2X_PREV_WAIT_NEEDED;
  8282. return rc;
  8283. }
  8284. static int bnx2x_prev_unload_common(struct bnx2x *bp)
  8285. {
  8286. u32 reset_reg, tmp_reg = 0, rc;
  8287. bool prev_undi = false;
  8288. struct bnx2x_mac_vals mac_vals;
  8289. /* It is possible a previous function received 'common' answer,
  8290. * but hasn't loaded yet, therefore creating a scenario of
  8291. * multiple functions receiving 'common' on the same path.
  8292. */
  8293. BNX2X_DEV_INFO("Common unload Flow\n");
  8294. memset(&mac_vals, 0, sizeof(mac_vals));
  8295. if (bnx2x_prev_is_path_marked(bp))
  8296. return bnx2x_prev_mcp_done(bp);
  8297. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
  8298. /* Reset should be performed after BRB is emptied */
  8299. if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_BRB1) {
  8300. u32 timer_count = 1000;
  8301. /* Close the MAC Rx to prevent BRB from filling up */
  8302. bnx2x_prev_unload_close_mac(bp, &mac_vals);
  8303. /* close LLH filters towards the BRB */
  8304. bnx2x_set_rx_filter(&bp->link_params, 0);
  8305. /* Check if the UNDI driver was previously loaded
  8306. * UNDI driver initializes CID offset for normal bell to 0x7
  8307. */
  8308. if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_DORQ) {
  8309. tmp_reg = REG_RD(bp, DORQ_REG_NORM_CID_OFST);
  8310. if (tmp_reg == 0x7) {
  8311. BNX2X_DEV_INFO("UNDI previously loaded\n");
  8312. prev_undi = true;
  8313. /* clear the UNDI indication */
  8314. REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0);
  8315. /* clear possible idle check errors */
  8316. REG_RD(bp, NIG_REG_NIG_INT_STS_CLR_0);
  8317. }
  8318. }
  8319. if (!CHIP_IS_E1x(bp))
  8320. /* block FW from writing to host */
  8321. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  8322. /* wait until BRB is empty */
  8323. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  8324. while (timer_count) {
  8325. u32 prev_brb = tmp_reg;
  8326. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  8327. if (!tmp_reg)
  8328. break;
  8329. BNX2X_DEV_INFO("BRB still has 0x%08x\n", tmp_reg);
  8330. /* reset timer as long as BRB actually gets emptied */
  8331. if (prev_brb > tmp_reg)
  8332. timer_count = 1000;
  8333. else
  8334. timer_count--;
  8335. /* If UNDI resides in memory, manually increment it */
  8336. if (prev_undi)
  8337. bnx2x_prev_unload_undi_inc(bp, BP_PORT(bp), 1);
  8338. udelay(10);
  8339. }
  8340. if (!timer_count)
  8341. BNX2X_ERR("Failed to empty BRB, hope for the best\n");
  8342. }
  8343. /* No packets are in the pipeline, path is ready for reset */
  8344. bnx2x_reset_common(bp);
  8345. if (mac_vals.xmac_addr)
  8346. REG_WR(bp, mac_vals.xmac_addr, mac_vals.xmac_val);
  8347. if (mac_vals.umac_addr)
  8348. REG_WR(bp, mac_vals.umac_addr, mac_vals.umac_val);
  8349. if (mac_vals.emac_addr)
  8350. REG_WR(bp, mac_vals.emac_addr, mac_vals.emac_val);
  8351. if (mac_vals.bmac_addr) {
  8352. REG_WR(bp, mac_vals.bmac_addr, mac_vals.bmac_val[0]);
  8353. REG_WR(bp, mac_vals.bmac_addr + 4, mac_vals.bmac_val[1]);
  8354. }
  8355. rc = bnx2x_prev_mark_path(bp, prev_undi);
  8356. if (rc) {
  8357. bnx2x_prev_mcp_done(bp);
  8358. return rc;
  8359. }
  8360. return bnx2x_prev_mcp_done(bp);
  8361. }
  8362. /* previous driver DMAE transaction may have occurred when pre-boot stage ended
  8363. * and boot began, or when kdump kernel was loaded. Either case would invalidate
  8364. * the addresses of the transaction, resulting in was-error bit set in the pci
  8365. * causing all hw-to-host pcie transactions to timeout. If this happened we want
  8366. * to clear the interrupt which detected this from the pglueb and the was done
  8367. * bit
  8368. */
  8369. static void bnx2x_prev_interrupted_dmae(struct bnx2x *bp)
  8370. {
  8371. if (!CHIP_IS_E1x(bp)) {
  8372. u32 val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS);
  8373. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN) {
  8374. DP(BNX2X_MSG_SP,
  8375. "'was error' bit was found to be set in pglueb upon startup. Clearing\n");
  8376. REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR,
  8377. 1 << BP_FUNC(bp));
  8378. }
  8379. }
  8380. }
  8381. static int bnx2x_prev_unload(struct bnx2x *bp)
  8382. {
  8383. int time_counter = 10;
  8384. u32 rc, fw, hw_lock_reg, hw_lock_val;
  8385. BNX2X_DEV_INFO("Entering Previous Unload Flow\n");
  8386. /* clear hw from errors which may have resulted from an interrupted
  8387. * dmae transaction.
  8388. */
  8389. bnx2x_prev_interrupted_dmae(bp);
  8390. /* Release previously held locks */
  8391. hw_lock_reg = (BP_FUNC(bp) <= 5) ?
  8392. (MISC_REG_DRIVER_CONTROL_1 + BP_FUNC(bp) * 8) :
  8393. (MISC_REG_DRIVER_CONTROL_7 + (BP_FUNC(bp) - 6) * 8);
  8394. hw_lock_val = (REG_RD(bp, hw_lock_reg));
  8395. if (hw_lock_val) {
  8396. if (hw_lock_val & HW_LOCK_RESOURCE_NVRAM) {
  8397. BNX2X_DEV_INFO("Release Previously held NVRAM lock\n");
  8398. REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
  8399. (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << BP_PORT(bp)));
  8400. }
  8401. BNX2X_DEV_INFO("Release Previously held hw lock\n");
  8402. REG_WR(bp, hw_lock_reg, 0xffffffff);
  8403. } else
  8404. BNX2X_DEV_INFO("No need to release hw/nvram locks\n");
  8405. if (MCPR_ACCESS_LOCK_LOCK & REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK)) {
  8406. BNX2X_DEV_INFO("Release previously held alr\n");
  8407. REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, 0);
  8408. }
  8409. do {
  8410. int aer = 0;
  8411. /* Lock MCP using an unload request */
  8412. fw = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS, 0);
  8413. if (!fw) {
  8414. BNX2X_ERR("MCP response failure, aborting\n");
  8415. rc = -EBUSY;
  8416. break;
  8417. }
  8418. rc = down_interruptible(&bnx2x_prev_sem);
  8419. if (rc) {
  8420. BNX2X_ERR("Cannot check for AER; Received %d when tried to take lock\n",
  8421. rc);
  8422. } else {
  8423. /* If Path is marked by EEH, ignore unload status */
  8424. aer = !!(bnx2x_prev_path_get_entry(bp) &&
  8425. bnx2x_prev_path_get_entry(bp)->aer);
  8426. up(&bnx2x_prev_sem);
  8427. }
  8428. if (fw == FW_MSG_CODE_DRV_UNLOAD_COMMON || aer) {
  8429. rc = bnx2x_prev_unload_common(bp);
  8430. break;
  8431. }
  8432. /* non-common reply from MCP night require looping */
  8433. rc = bnx2x_prev_unload_uncommon(bp);
  8434. if (rc != BNX2X_PREV_WAIT_NEEDED)
  8435. break;
  8436. msleep(20);
  8437. } while (--time_counter);
  8438. if (!time_counter || rc) {
  8439. BNX2X_ERR("Failed unloading previous driver, aborting\n");
  8440. rc = -EBUSY;
  8441. }
  8442. /* Mark function if its port was used to boot from SAN */
  8443. if (bnx2x_port_after_undi(bp))
  8444. bp->link_params.feature_config_flags |=
  8445. FEATURE_CONFIG_BOOT_FROM_SAN;
  8446. BNX2X_DEV_INFO("Finished Previous Unload Flow [%d]\n", rc);
  8447. return rc;
  8448. }
  8449. static void bnx2x_get_common_hwinfo(struct bnx2x *bp)
  8450. {
  8451. u32 val, val2, val3, val4, id, boot_mode;
  8452. u16 pmc;
  8453. /* Get the chip revision id and number. */
  8454. /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
  8455. val = REG_RD(bp, MISC_REG_CHIP_NUM);
  8456. id = ((val & 0xffff) << 16);
  8457. val = REG_RD(bp, MISC_REG_CHIP_REV);
  8458. id |= ((val & 0xf) << 12);
  8459. /* Metal is read from PCI regs, but we can't access >=0x400 from
  8460. * the configuration space (so we need to reg_rd)
  8461. */
  8462. val = REG_RD(bp, PCICFG_OFFSET + PCI_ID_VAL3);
  8463. id |= (((val >> 24) & 0xf) << 4);
  8464. val = REG_RD(bp, MISC_REG_BOND_ID);
  8465. id |= (val & 0xf);
  8466. bp->common.chip_id = id;
  8467. /* force 57811 according to MISC register */
  8468. if (REG_RD(bp, MISC_REG_CHIP_TYPE) & MISC_REG_CHIP_TYPE_57811_MASK) {
  8469. if (CHIP_IS_57810(bp))
  8470. bp->common.chip_id = (CHIP_NUM_57811 << 16) |
  8471. (bp->common.chip_id & 0x0000FFFF);
  8472. else if (CHIP_IS_57810_MF(bp))
  8473. bp->common.chip_id = (CHIP_NUM_57811_MF << 16) |
  8474. (bp->common.chip_id & 0x0000FFFF);
  8475. bp->common.chip_id |= 0x1;
  8476. }
  8477. /* Set doorbell size */
  8478. bp->db_size = (1 << BNX2X_DB_SHIFT);
  8479. if (!CHIP_IS_E1x(bp)) {
  8480. val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR);
  8481. if ((val & 1) == 0)
  8482. val = REG_RD(bp, MISC_REG_PORT4MODE_EN);
  8483. else
  8484. val = (val >> 1) & 1;
  8485. BNX2X_DEV_INFO("chip is in %s\n", val ? "4_PORT_MODE" :
  8486. "2_PORT_MODE");
  8487. bp->common.chip_port_mode = val ? CHIP_4_PORT_MODE :
  8488. CHIP_2_PORT_MODE;
  8489. if (CHIP_MODE_IS_4_PORT(bp))
  8490. bp->pfid = (bp->pf_num >> 1); /* 0..3 */
  8491. else
  8492. bp->pfid = (bp->pf_num & 0x6); /* 0, 2, 4, 6 */
  8493. } else {
  8494. bp->common.chip_port_mode = CHIP_PORT_MODE_NONE; /* N/A */
  8495. bp->pfid = bp->pf_num; /* 0..7 */
  8496. }
  8497. BNX2X_DEV_INFO("pf_id: %x", bp->pfid);
  8498. bp->link_params.chip_id = bp->common.chip_id;
  8499. BNX2X_DEV_INFO("chip ID is 0x%x\n", id);
  8500. val = (REG_RD(bp, 0x2874) & 0x55);
  8501. if ((bp->common.chip_id & 0x1) ||
  8502. (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) {
  8503. bp->flags |= ONE_PORT_FLAG;
  8504. BNX2X_DEV_INFO("single port device\n");
  8505. }
  8506. val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4);
  8507. bp->common.flash_size = (BNX2X_NVRAM_1MB_SIZE <<
  8508. (val & MCPR_NVM_CFG4_FLASH_SIZE));
  8509. BNX2X_DEV_INFO("flash_size 0x%x (%d)\n",
  8510. bp->common.flash_size, bp->common.flash_size);
  8511. bnx2x_init_shmem(bp);
  8512. bp->common.shmem2_base = REG_RD(bp, (BP_PATH(bp) ?
  8513. MISC_REG_GENERIC_CR_1 :
  8514. MISC_REG_GENERIC_CR_0));
  8515. bp->link_params.shmem_base = bp->common.shmem_base;
  8516. bp->link_params.shmem2_base = bp->common.shmem2_base;
  8517. if (SHMEM2_RD(bp, size) >
  8518. (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
  8519. bp->link_params.lfa_base =
  8520. REG_RD(bp, bp->common.shmem2_base +
  8521. (u32)offsetof(struct shmem2_region,
  8522. lfa_host_addr[BP_PORT(bp)]));
  8523. else
  8524. bp->link_params.lfa_base = 0;
  8525. BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n",
  8526. bp->common.shmem_base, bp->common.shmem2_base);
  8527. if (!bp->common.shmem_base) {
  8528. BNX2X_DEV_INFO("MCP not active\n");
  8529. bp->flags |= NO_MCP_FLAG;
  8530. return;
  8531. }
  8532. bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config);
  8533. BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config);
  8534. bp->link_params.hw_led_mode = ((bp->common.hw_config &
  8535. SHARED_HW_CFG_LED_MODE_MASK) >>
  8536. SHARED_HW_CFG_LED_MODE_SHIFT);
  8537. bp->link_params.feature_config_flags = 0;
  8538. val = SHMEM_RD(bp, dev_info.shared_feature_config.config);
  8539. if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED)
  8540. bp->link_params.feature_config_flags |=
  8541. FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  8542. else
  8543. bp->link_params.feature_config_flags &=
  8544. ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  8545. val = SHMEM_RD(bp, dev_info.bc_rev) >> 8;
  8546. bp->common.bc_ver = val;
  8547. BNX2X_DEV_INFO("bc_ver %X\n", val);
  8548. if (val < BNX2X_BC_VER) {
  8549. /* for now only warn
  8550. * later we might need to enforce this */
  8551. BNX2X_ERR("This driver needs bc_ver %X but found %X, please upgrade BC\n",
  8552. BNX2X_BC_VER, val);
  8553. }
  8554. bp->link_params.feature_config_flags |=
  8555. (val >= REQ_BC_VER_4_VRFY_FIRST_PHY_OPT_MDL) ?
  8556. FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY : 0;
  8557. bp->link_params.feature_config_flags |=
  8558. (val >= REQ_BC_VER_4_VRFY_SPECIFIC_PHY_OPT_MDL) ?
  8559. FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY : 0;
  8560. bp->link_params.feature_config_flags |=
  8561. (val >= REQ_BC_VER_4_VRFY_AFEX_SUPPORTED) ?
  8562. FEATURE_CONFIG_BC_SUPPORTS_AFEX : 0;
  8563. bp->link_params.feature_config_flags |=
  8564. (val >= REQ_BC_VER_4_SFP_TX_DISABLE_SUPPORTED) ?
  8565. FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED : 0;
  8566. bp->link_params.feature_config_flags |=
  8567. (val >= REQ_BC_VER_4_MT_SUPPORTED) ?
  8568. FEATURE_CONFIG_MT_SUPPORT : 0;
  8569. bp->flags |= (val >= REQ_BC_VER_4_PFC_STATS_SUPPORTED) ?
  8570. BC_SUPPORTS_PFC_STATS : 0;
  8571. bp->flags |= (val >= REQ_BC_VER_4_FCOE_FEATURES) ?
  8572. BC_SUPPORTS_FCOE_FEATURES : 0;
  8573. bp->flags |= (val >= REQ_BC_VER_4_DCBX_ADMIN_MSG_NON_PMF) ?
  8574. BC_SUPPORTS_DCBX_MSG_NON_PMF : 0;
  8575. boot_mode = SHMEM_RD(bp,
  8576. dev_info.port_feature_config[BP_PORT(bp)].mba_config) &
  8577. PORT_FEATURE_MBA_BOOT_AGENT_TYPE_MASK;
  8578. switch (boot_mode) {
  8579. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_PXE:
  8580. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_PXE;
  8581. break;
  8582. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_ISCSIB:
  8583. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_ISCSI;
  8584. break;
  8585. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_FCOE_BOOT:
  8586. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_FCOE;
  8587. break;
  8588. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_NONE:
  8589. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_NONE;
  8590. break;
  8591. }
  8592. pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_PMC, &pmc);
  8593. bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG;
  8594. BNX2X_DEV_INFO("%sWoL capable\n",
  8595. (bp->flags & NO_WOL_FLAG) ? "not " : "");
  8596. val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num);
  8597. val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]);
  8598. val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]);
  8599. val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]);
  8600. dev_info(&bp->pdev->dev, "part number %X-%X-%X-%X\n",
  8601. val, val2, val3, val4);
  8602. }
  8603. #define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID)
  8604. #define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR)
  8605. static int bnx2x_get_igu_cam_info(struct bnx2x *bp)
  8606. {
  8607. int pfid = BP_FUNC(bp);
  8608. int igu_sb_id;
  8609. u32 val;
  8610. u8 fid, igu_sb_cnt = 0;
  8611. bp->igu_base_sb = 0xff;
  8612. if (CHIP_INT_MODE_IS_BC(bp)) {
  8613. int vn = BP_VN(bp);
  8614. igu_sb_cnt = bp->igu_sb_cnt;
  8615. bp->igu_base_sb = (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn) *
  8616. FP_SB_MAX_E1x;
  8617. bp->igu_dsb_id = E1HVN_MAX * FP_SB_MAX_E1x +
  8618. (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn);
  8619. return 0;
  8620. }
  8621. /* IGU in normal mode - read CAM */
  8622. for (igu_sb_id = 0; igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE;
  8623. igu_sb_id++) {
  8624. val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4);
  8625. if (!(val & IGU_REG_MAPPING_MEMORY_VALID))
  8626. continue;
  8627. fid = IGU_FID(val);
  8628. if ((fid & IGU_FID_ENCODE_IS_PF)) {
  8629. if ((fid & IGU_FID_PF_NUM_MASK) != pfid)
  8630. continue;
  8631. if (IGU_VEC(val) == 0)
  8632. /* default status block */
  8633. bp->igu_dsb_id = igu_sb_id;
  8634. else {
  8635. if (bp->igu_base_sb == 0xff)
  8636. bp->igu_base_sb = igu_sb_id;
  8637. igu_sb_cnt++;
  8638. }
  8639. }
  8640. }
  8641. #ifdef CONFIG_PCI_MSI
  8642. /* Due to new PF resource allocation by MFW T7.4 and above, it's
  8643. * optional that number of CAM entries will not be equal to the value
  8644. * advertised in PCI.
  8645. * Driver should use the minimal value of both as the actual status
  8646. * block count
  8647. */
  8648. bp->igu_sb_cnt = min_t(int, bp->igu_sb_cnt, igu_sb_cnt);
  8649. #endif
  8650. if (igu_sb_cnt == 0) {
  8651. BNX2X_ERR("CAM configuration error\n");
  8652. return -EINVAL;
  8653. }
  8654. return 0;
  8655. }
  8656. static void bnx2x_link_settings_supported(struct bnx2x *bp, u32 switch_cfg)
  8657. {
  8658. int cfg_size = 0, idx, port = BP_PORT(bp);
  8659. /* Aggregation of supported attributes of all external phys */
  8660. bp->port.supported[0] = 0;
  8661. bp->port.supported[1] = 0;
  8662. switch (bp->link_params.num_phys) {
  8663. case 1:
  8664. bp->port.supported[0] = bp->link_params.phy[INT_PHY].supported;
  8665. cfg_size = 1;
  8666. break;
  8667. case 2:
  8668. bp->port.supported[0] = bp->link_params.phy[EXT_PHY1].supported;
  8669. cfg_size = 1;
  8670. break;
  8671. case 3:
  8672. if (bp->link_params.multi_phy_config &
  8673. PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
  8674. bp->port.supported[1] =
  8675. bp->link_params.phy[EXT_PHY1].supported;
  8676. bp->port.supported[0] =
  8677. bp->link_params.phy[EXT_PHY2].supported;
  8678. } else {
  8679. bp->port.supported[0] =
  8680. bp->link_params.phy[EXT_PHY1].supported;
  8681. bp->port.supported[1] =
  8682. bp->link_params.phy[EXT_PHY2].supported;
  8683. }
  8684. cfg_size = 2;
  8685. break;
  8686. }
  8687. if (!(bp->port.supported[0] || bp->port.supported[1])) {
  8688. BNX2X_ERR("NVRAM config error. BAD phy config. PHY1 config 0x%x, PHY2 config 0x%x\n",
  8689. SHMEM_RD(bp,
  8690. dev_info.port_hw_config[port].external_phy_config),
  8691. SHMEM_RD(bp,
  8692. dev_info.port_hw_config[port].external_phy_config2));
  8693. return;
  8694. }
  8695. if (CHIP_IS_E3(bp))
  8696. bp->port.phy_addr = REG_RD(bp, MISC_REG_WC0_CTRL_PHY_ADDR);
  8697. else {
  8698. switch (switch_cfg) {
  8699. case SWITCH_CFG_1G:
  8700. bp->port.phy_addr = REG_RD(
  8701. bp, NIG_REG_SERDES0_CTRL_PHY_ADDR + port*0x10);
  8702. break;
  8703. case SWITCH_CFG_10G:
  8704. bp->port.phy_addr = REG_RD(
  8705. bp, NIG_REG_XGXS0_CTRL_PHY_ADDR + port*0x18);
  8706. break;
  8707. default:
  8708. BNX2X_ERR("BAD switch_cfg link_config 0x%x\n",
  8709. bp->port.link_config[0]);
  8710. return;
  8711. }
  8712. }
  8713. BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
  8714. /* mask what we support according to speed_cap_mask per configuration */
  8715. for (idx = 0; idx < cfg_size; idx++) {
  8716. if (!(bp->link_params.speed_cap_mask[idx] &
  8717. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF))
  8718. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Half;
  8719. if (!(bp->link_params.speed_cap_mask[idx] &
  8720. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL))
  8721. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Full;
  8722. if (!(bp->link_params.speed_cap_mask[idx] &
  8723. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF))
  8724. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Half;
  8725. if (!(bp->link_params.speed_cap_mask[idx] &
  8726. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL))
  8727. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Full;
  8728. if (!(bp->link_params.speed_cap_mask[idx] &
  8729. PORT_HW_CFG_SPEED_CAPABILITY_D0_1G))
  8730. bp->port.supported[idx] &= ~(SUPPORTED_1000baseT_Half |
  8731. SUPPORTED_1000baseT_Full);
  8732. if (!(bp->link_params.speed_cap_mask[idx] &
  8733. PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
  8734. bp->port.supported[idx] &= ~SUPPORTED_2500baseX_Full;
  8735. if (!(bp->link_params.speed_cap_mask[idx] &
  8736. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G))
  8737. bp->port.supported[idx] &= ~SUPPORTED_10000baseT_Full;
  8738. }
  8739. BNX2X_DEV_INFO("supported 0x%x 0x%x\n", bp->port.supported[0],
  8740. bp->port.supported[1]);
  8741. }
  8742. static void bnx2x_link_settings_requested(struct bnx2x *bp)
  8743. {
  8744. u32 link_config, idx, cfg_size = 0;
  8745. bp->port.advertising[0] = 0;
  8746. bp->port.advertising[1] = 0;
  8747. switch (bp->link_params.num_phys) {
  8748. case 1:
  8749. case 2:
  8750. cfg_size = 1;
  8751. break;
  8752. case 3:
  8753. cfg_size = 2;
  8754. break;
  8755. }
  8756. for (idx = 0; idx < cfg_size; idx++) {
  8757. bp->link_params.req_duplex[idx] = DUPLEX_FULL;
  8758. link_config = bp->port.link_config[idx];
  8759. switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
  8760. case PORT_FEATURE_LINK_SPEED_AUTO:
  8761. if (bp->port.supported[idx] & SUPPORTED_Autoneg) {
  8762. bp->link_params.req_line_speed[idx] =
  8763. SPEED_AUTO_NEG;
  8764. bp->port.advertising[idx] |=
  8765. bp->port.supported[idx];
  8766. if (bp->link_params.phy[EXT_PHY1].type ==
  8767. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
  8768. bp->port.advertising[idx] |=
  8769. (SUPPORTED_100baseT_Half |
  8770. SUPPORTED_100baseT_Full);
  8771. } else {
  8772. /* force 10G, no AN */
  8773. bp->link_params.req_line_speed[idx] =
  8774. SPEED_10000;
  8775. bp->port.advertising[idx] |=
  8776. (ADVERTISED_10000baseT_Full |
  8777. ADVERTISED_FIBRE);
  8778. continue;
  8779. }
  8780. break;
  8781. case PORT_FEATURE_LINK_SPEED_10M_FULL:
  8782. if (bp->port.supported[idx] & SUPPORTED_10baseT_Full) {
  8783. bp->link_params.req_line_speed[idx] =
  8784. SPEED_10;
  8785. bp->port.advertising[idx] |=
  8786. (ADVERTISED_10baseT_Full |
  8787. ADVERTISED_TP);
  8788. } else {
  8789. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8790. link_config,
  8791. bp->link_params.speed_cap_mask[idx]);
  8792. return;
  8793. }
  8794. break;
  8795. case PORT_FEATURE_LINK_SPEED_10M_HALF:
  8796. if (bp->port.supported[idx] & SUPPORTED_10baseT_Half) {
  8797. bp->link_params.req_line_speed[idx] =
  8798. SPEED_10;
  8799. bp->link_params.req_duplex[idx] =
  8800. DUPLEX_HALF;
  8801. bp->port.advertising[idx] |=
  8802. (ADVERTISED_10baseT_Half |
  8803. ADVERTISED_TP);
  8804. } else {
  8805. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8806. link_config,
  8807. bp->link_params.speed_cap_mask[idx]);
  8808. return;
  8809. }
  8810. break;
  8811. case PORT_FEATURE_LINK_SPEED_100M_FULL:
  8812. if (bp->port.supported[idx] &
  8813. SUPPORTED_100baseT_Full) {
  8814. bp->link_params.req_line_speed[idx] =
  8815. SPEED_100;
  8816. bp->port.advertising[idx] |=
  8817. (ADVERTISED_100baseT_Full |
  8818. ADVERTISED_TP);
  8819. } else {
  8820. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8821. link_config,
  8822. bp->link_params.speed_cap_mask[idx]);
  8823. return;
  8824. }
  8825. break;
  8826. case PORT_FEATURE_LINK_SPEED_100M_HALF:
  8827. if (bp->port.supported[idx] &
  8828. SUPPORTED_100baseT_Half) {
  8829. bp->link_params.req_line_speed[idx] =
  8830. SPEED_100;
  8831. bp->link_params.req_duplex[idx] =
  8832. DUPLEX_HALF;
  8833. bp->port.advertising[idx] |=
  8834. (ADVERTISED_100baseT_Half |
  8835. ADVERTISED_TP);
  8836. } else {
  8837. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8838. link_config,
  8839. bp->link_params.speed_cap_mask[idx]);
  8840. return;
  8841. }
  8842. break;
  8843. case PORT_FEATURE_LINK_SPEED_1G:
  8844. if (bp->port.supported[idx] &
  8845. SUPPORTED_1000baseT_Full) {
  8846. bp->link_params.req_line_speed[idx] =
  8847. SPEED_1000;
  8848. bp->port.advertising[idx] |=
  8849. (ADVERTISED_1000baseT_Full |
  8850. ADVERTISED_TP);
  8851. } else {
  8852. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8853. link_config,
  8854. bp->link_params.speed_cap_mask[idx]);
  8855. return;
  8856. }
  8857. break;
  8858. case PORT_FEATURE_LINK_SPEED_2_5G:
  8859. if (bp->port.supported[idx] &
  8860. SUPPORTED_2500baseX_Full) {
  8861. bp->link_params.req_line_speed[idx] =
  8862. SPEED_2500;
  8863. bp->port.advertising[idx] |=
  8864. (ADVERTISED_2500baseX_Full |
  8865. ADVERTISED_TP);
  8866. } else {
  8867. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8868. link_config,
  8869. bp->link_params.speed_cap_mask[idx]);
  8870. return;
  8871. }
  8872. break;
  8873. case PORT_FEATURE_LINK_SPEED_10G_CX4:
  8874. if (bp->port.supported[idx] &
  8875. SUPPORTED_10000baseT_Full) {
  8876. bp->link_params.req_line_speed[idx] =
  8877. SPEED_10000;
  8878. bp->port.advertising[idx] |=
  8879. (ADVERTISED_10000baseT_Full |
  8880. ADVERTISED_FIBRE);
  8881. } else {
  8882. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8883. link_config,
  8884. bp->link_params.speed_cap_mask[idx]);
  8885. return;
  8886. }
  8887. break;
  8888. case PORT_FEATURE_LINK_SPEED_20G:
  8889. bp->link_params.req_line_speed[idx] = SPEED_20000;
  8890. break;
  8891. default:
  8892. BNX2X_ERR("NVRAM config error. BAD link speed link_config 0x%x\n",
  8893. link_config);
  8894. bp->link_params.req_line_speed[idx] =
  8895. SPEED_AUTO_NEG;
  8896. bp->port.advertising[idx] =
  8897. bp->port.supported[idx];
  8898. break;
  8899. }
  8900. bp->link_params.req_flow_ctrl[idx] = (link_config &
  8901. PORT_FEATURE_FLOW_CONTROL_MASK);
  8902. if (bp->link_params.req_flow_ctrl[idx] ==
  8903. BNX2X_FLOW_CTRL_AUTO) {
  8904. if (!(bp->port.supported[idx] & SUPPORTED_Autoneg))
  8905. bp->link_params.req_flow_ctrl[idx] =
  8906. BNX2X_FLOW_CTRL_NONE;
  8907. else
  8908. bnx2x_set_requested_fc(bp);
  8909. }
  8910. BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl 0x%x advertising 0x%x\n",
  8911. bp->link_params.req_line_speed[idx],
  8912. bp->link_params.req_duplex[idx],
  8913. bp->link_params.req_flow_ctrl[idx],
  8914. bp->port.advertising[idx]);
  8915. }
  8916. }
  8917. static void bnx2x_set_mac_buf(u8 *mac_buf, u32 mac_lo, u16 mac_hi)
  8918. {
  8919. __be16 mac_hi_be = cpu_to_be16(mac_hi);
  8920. __be32 mac_lo_be = cpu_to_be32(mac_lo);
  8921. memcpy(mac_buf, &mac_hi_be, sizeof(mac_hi_be));
  8922. memcpy(mac_buf + sizeof(mac_hi_be), &mac_lo_be, sizeof(mac_lo_be));
  8923. }
  8924. static void bnx2x_get_port_hwinfo(struct bnx2x *bp)
  8925. {
  8926. int port = BP_PORT(bp);
  8927. u32 config;
  8928. u32 ext_phy_type, ext_phy_config, eee_mode;
  8929. bp->link_params.bp = bp;
  8930. bp->link_params.port = port;
  8931. bp->link_params.lane_config =
  8932. SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config);
  8933. bp->link_params.speed_cap_mask[0] =
  8934. SHMEM_RD(bp,
  8935. dev_info.port_hw_config[port].speed_capability_mask) &
  8936. PORT_HW_CFG_SPEED_CAPABILITY_D0_MASK;
  8937. bp->link_params.speed_cap_mask[1] =
  8938. SHMEM_RD(bp,
  8939. dev_info.port_hw_config[port].speed_capability_mask2) &
  8940. PORT_HW_CFG_SPEED_CAPABILITY_D0_MASK;
  8941. bp->port.link_config[0] =
  8942. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config);
  8943. bp->port.link_config[1] =
  8944. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config2);
  8945. bp->link_params.multi_phy_config =
  8946. SHMEM_RD(bp, dev_info.port_hw_config[port].multi_phy_config);
  8947. /* If the device is capable of WoL, set the default state according
  8948. * to the HW
  8949. */
  8950. config = SHMEM_RD(bp, dev_info.port_feature_config[port].config);
  8951. bp->wol = (!(bp->flags & NO_WOL_FLAG) &&
  8952. (config & PORT_FEATURE_WOL_ENABLED));
  8953. if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) ==
  8954. PORT_FEAT_CFG_STORAGE_PERSONALITY_FCOE && !IS_MF(bp))
  8955. bp->flags |= NO_ISCSI_FLAG;
  8956. if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) ==
  8957. PORT_FEAT_CFG_STORAGE_PERSONALITY_ISCSI && !(IS_MF(bp)))
  8958. bp->flags |= NO_FCOE_FLAG;
  8959. BNX2X_DEV_INFO("lane_config 0x%08x speed_cap_mask0 0x%08x link_config0 0x%08x\n",
  8960. bp->link_params.lane_config,
  8961. bp->link_params.speed_cap_mask[0],
  8962. bp->port.link_config[0]);
  8963. bp->link_params.switch_cfg = (bp->port.link_config[0] &
  8964. PORT_FEATURE_CONNECTED_SWITCH_MASK);
  8965. bnx2x_phy_probe(&bp->link_params);
  8966. bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg);
  8967. bnx2x_link_settings_requested(bp);
  8968. /*
  8969. * If connected directly, work with the internal PHY, otherwise, work
  8970. * with the external PHY
  8971. */
  8972. ext_phy_config =
  8973. SHMEM_RD(bp,
  8974. dev_info.port_hw_config[port].external_phy_config);
  8975. ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
  8976. if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
  8977. bp->mdio.prtad = bp->port.phy_addr;
  8978. else if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) &&
  8979. (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
  8980. bp->mdio.prtad =
  8981. XGXS_EXT_PHY_ADDR(ext_phy_config);
  8982. /* Configure link feature according to nvram value */
  8983. eee_mode = (((SHMEM_RD(bp, dev_info.
  8984. port_feature_config[port].eee_power_mode)) &
  8985. PORT_FEAT_CFG_EEE_POWER_MODE_MASK) >>
  8986. PORT_FEAT_CFG_EEE_POWER_MODE_SHIFT);
  8987. if (eee_mode != PORT_FEAT_CFG_EEE_POWER_MODE_DISABLED) {
  8988. bp->link_params.eee_mode = EEE_MODE_ADV_LPI |
  8989. EEE_MODE_ENABLE_LPI |
  8990. EEE_MODE_OUTPUT_TIME;
  8991. } else {
  8992. bp->link_params.eee_mode = 0;
  8993. }
  8994. }
  8995. void bnx2x_get_iscsi_info(struct bnx2x *bp)
  8996. {
  8997. u32 no_flags = NO_ISCSI_FLAG;
  8998. int port = BP_PORT(bp);
  8999. u32 max_iscsi_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  9000. drv_lic_key[port].max_iscsi_conn);
  9001. if (!CNIC_SUPPORT(bp)) {
  9002. bp->flags |= no_flags;
  9003. return;
  9004. }
  9005. /* Get the number of maximum allowed iSCSI connections */
  9006. bp->cnic_eth_dev.max_iscsi_conn =
  9007. (max_iscsi_conn & BNX2X_MAX_ISCSI_INIT_CONN_MASK) >>
  9008. BNX2X_MAX_ISCSI_INIT_CONN_SHIFT;
  9009. BNX2X_DEV_INFO("max_iscsi_conn 0x%x\n",
  9010. bp->cnic_eth_dev.max_iscsi_conn);
  9011. /*
  9012. * If maximum allowed number of connections is zero -
  9013. * disable the feature.
  9014. */
  9015. if (!bp->cnic_eth_dev.max_iscsi_conn)
  9016. bp->flags |= no_flags;
  9017. }
  9018. static void bnx2x_get_ext_wwn_info(struct bnx2x *bp, int func)
  9019. {
  9020. /* Port info */
  9021. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  9022. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_upper);
  9023. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  9024. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_lower);
  9025. /* Node info */
  9026. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  9027. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_upper);
  9028. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  9029. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_lower);
  9030. }
  9031. static int bnx2x_shared_fcoe_funcs(struct bnx2x *bp)
  9032. {
  9033. u8 count = 0;
  9034. if (IS_MF(bp)) {
  9035. u8 fid;
  9036. /* iterate over absolute function ids for this path: */
  9037. for (fid = BP_PATH(bp); fid < E2_FUNC_MAX * 2; fid += 2) {
  9038. if (IS_MF_SD(bp)) {
  9039. u32 cfg = MF_CFG_RD(bp,
  9040. func_mf_config[fid].config);
  9041. if (!(cfg & FUNC_MF_CFG_FUNC_HIDE) &&
  9042. ((cfg & FUNC_MF_CFG_PROTOCOL_MASK) ==
  9043. FUNC_MF_CFG_PROTOCOL_FCOE))
  9044. count++;
  9045. } else {
  9046. u32 cfg = MF_CFG_RD(bp,
  9047. func_ext_config[fid].
  9048. func_cfg);
  9049. if ((cfg & MACP_FUNC_CFG_FLAGS_ENABLED) &&
  9050. (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD))
  9051. count++;
  9052. }
  9053. }
  9054. } else { /* SF */
  9055. int port, port_cnt = CHIP_MODE_IS_4_PORT(bp) ? 2 : 1;
  9056. for (port = 0; port < port_cnt; port++) {
  9057. u32 lic = SHMEM_RD(bp,
  9058. drv_lic_key[port].max_fcoe_conn) ^
  9059. FW_ENCODE_32BIT_PATTERN;
  9060. if (lic)
  9061. count++;
  9062. }
  9063. }
  9064. return count;
  9065. }
  9066. static void bnx2x_get_fcoe_info(struct bnx2x *bp)
  9067. {
  9068. int port = BP_PORT(bp);
  9069. int func = BP_ABS_FUNC(bp);
  9070. u32 max_fcoe_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  9071. drv_lic_key[port].max_fcoe_conn);
  9072. u8 num_fcoe_func = bnx2x_shared_fcoe_funcs(bp);
  9073. if (!CNIC_SUPPORT(bp)) {
  9074. bp->flags |= NO_FCOE_FLAG;
  9075. return;
  9076. }
  9077. /* Get the number of maximum allowed FCoE connections */
  9078. bp->cnic_eth_dev.max_fcoe_conn =
  9079. (max_fcoe_conn & BNX2X_MAX_FCOE_INIT_CONN_MASK) >>
  9080. BNX2X_MAX_FCOE_INIT_CONN_SHIFT;
  9081. /* Calculate the number of maximum allowed FCoE tasks */
  9082. bp->cnic_eth_dev.max_fcoe_exchanges = MAX_NUM_FCOE_TASKS_PER_ENGINE;
  9083. /* check if FCoE resources must be shared between different functions */
  9084. if (num_fcoe_func)
  9085. bp->cnic_eth_dev.max_fcoe_exchanges /= num_fcoe_func;
  9086. /* Read the WWN: */
  9087. if (!IS_MF(bp)) {
  9088. /* Port info */
  9089. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  9090. SHMEM_RD(bp,
  9091. dev_info.port_hw_config[port].
  9092. fcoe_wwn_port_name_upper);
  9093. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  9094. SHMEM_RD(bp,
  9095. dev_info.port_hw_config[port].
  9096. fcoe_wwn_port_name_lower);
  9097. /* Node info */
  9098. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  9099. SHMEM_RD(bp,
  9100. dev_info.port_hw_config[port].
  9101. fcoe_wwn_node_name_upper);
  9102. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  9103. SHMEM_RD(bp,
  9104. dev_info.port_hw_config[port].
  9105. fcoe_wwn_node_name_lower);
  9106. } else if (!IS_MF_SD(bp)) {
  9107. /*
  9108. * Read the WWN info only if the FCoE feature is enabled for
  9109. * this function.
  9110. */
  9111. if (BNX2X_MF_EXT_PROTOCOL_FCOE(bp) && !CHIP_IS_E1x(bp))
  9112. bnx2x_get_ext_wwn_info(bp, func);
  9113. } else if (IS_MF_FCOE_SD(bp) && !CHIP_IS_E1x(bp)) {
  9114. bnx2x_get_ext_wwn_info(bp, func);
  9115. }
  9116. BNX2X_DEV_INFO("max_fcoe_conn 0x%x\n", bp->cnic_eth_dev.max_fcoe_conn);
  9117. /*
  9118. * If maximum allowed number of connections is zero -
  9119. * disable the feature.
  9120. */
  9121. if (!bp->cnic_eth_dev.max_fcoe_conn)
  9122. bp->flags |= NO_FCOE_FLAG;
  9123. }
  9124. static void bnx2x_get_cnic_info(struct bnx2x *bp)
  9125. {
  9126. /*
  9127. * iSCSI may be dynamically disabled but reading
  9128. * info here we will decrease memory usage by driver
  9129. * if the feature is disabled for good
  9130. */
  9131. bnx2x_get_iscsi_info(bp);
  9132. bnx2x_get_fcoe_info(bp);
  9133. }
  9134. static void bnx2x_get_cnic_mac_hwinfo(struct bnx2x *bp)
  9135. {
  9136. u32 val, val2;
  9137. int func = BP_ABS_FUNC(bp);
  9138. int port = BP_PORT(bp);
  9139. u8 *iscsi_mac = bp->cnic_eth_dev.iscsi_mac;
  9140. u8 *fip_mac = bp->fip_mac;
  9141. if (IS_MF(bp)) {
  9142. /* iSCSI and FCoE NPAR MACs: if there is no either iSCSI or
  9143. * FCoE MAC then the appropriate feature should be disabled.
  9144. * In non SD mode features configuration comes from struct
  9145. * func_ext_config.
  9146. */
  9147. if (!IS_MF_SD(bp) && !CHIP_IS_E1x(bp)) {
  9148. u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
  9149. if (cfg & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) {
  9150. val2 = MF_CFG_RD(bp, func_ext_config[func].
  9151. iscsi_mac_addr_upper);
  9152. val = MF_CFG_RD(bp, func_ext_config[func].
  9153. iscsi_mac_addr_lower);
  9154. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  9155. BNX2X_DEV_INFO
  9156. ("Read iSCSI MAC: %pM\n", iscsi_mac);
  9157. } else {
  9158. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  9159. }
  9160. if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) {
  9161. val2 = MF_CFG_RD(bp, func_ext_config[func].
  9162. fcoe_mac_addr_upper);
  9163. val = MF_CFG_RD(bp, func_ext_config[func].
  9164. fcoe_mac_addr_lower);
  9165. bnx2x_set_mac_buf(fip_mac, val, val2);
  9166. BNX2X_DEV_INFO
  9167. ("Read FCoE L2 MAC: %pM\n", fip_mac);
  9168. } else {
  9169. bp->flags |= NO_FCOE_FLAG;
  9170. }
  9171. bp->mf_ext_config = cfg;
  9172. } else { /* SD MODE */
  9173. if (BNX2X_IS_MF_SD_PROTOCOL_ISCSI(bp)) {
  9174. /* use primary mac as iscsi mac */
  9175. memcpy(iscsi_mac, bp->dev->dev_addr, ETH_ALEN);
  9176. BNX2X_DEV_INFO("SD ISCSI MODE\n");
  9177. BNX2X_DEV_INFO
  9178. ("Read iSCSI MAC: %pM\n", iscsi_mac);
  9179. } else if (BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp)) {
  9180. /* use primary mac as fip mac */
  9181. memcpy(fip_mac, bp->dev->dev_addr, ETH_ALEN);
  9182. BNX2X_DEV_INFO("SD FCoE MODE\n");
  9183. BNX2X_DEV_INFO
  9184. ("Read FIP MAC: %pM\n", fip_mac);
  9185. }
  9186. }
  9187. /* If this is a storage-only interface, use SAN mac as
  9188. * primary MAC. Notice that for SD this is already the case,
  9189. * as the SAN mac was copied from the primary MAC.
  9190. */
  9191. if (IS_MF_FCOE_AFEX(bp))
  9192. memcpy(bp->dev->dev_addr, fip_mac, ETH_ALEN);
  9193. } else {
  9194. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9195. iscsi_mac_upper);
  9196. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9197. iscsi_mac_lower);
  9198. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  9199. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9200. fcoe_fip_mac_upper);
  9201. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9202. fcoe_fip_mac_lower);
  9203. bnx2x_set_mac_buf(fip_mac, val, val2);
  9204. }
  9205. /* Disable iSCSI OOO if MAC configuration is invalid. */
  9206. if (!is_valid_ether_addr(iscsi_mac)) {
  9207. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  9208. memset(iscsi_mac, 0, ETH_ALEN);
  9209. }
  9210. /* Disable FCoE if MAC configuration is invalid. */
  9211. if (!is_valid_ether_addr(fip_mac)) {
  9212. bp->flags |= NO_FCOE_FLAG;
  9213. memset(bp->fip_mac, 0, ETH_ALEN);
  9214. }
  9215. }
  9216. static void bnx2x_get_mac_hwinfo(struct bnx2x *bp)
  9217. {
  9218. u32 val, val2;
  9219. int func = BP_ABS_FUNC(bp);
  9220. int port = BP_PORT(bp);
  9221. /* Zero primary MAC configuration */
  9222. memset(bp->dev->dev_addr, 0, ETH_ALEN);
  9223. if (BP_NOMCP(bp)) {
  9224. BNX2X_ERROR("warning: random MAC workaround active\n");
  9225. eth_hw_addr_random(bp->dev);
  9226. } else if (IS_MF(bp)) {
  9227. val2 = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
  9228. val = MF_CFG_RD(bp, func_mf_config[func].mac_lower);
  9229. if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) &&
  9230. (val != FUNC_MF_CFG_LOWERMAC_DEFAULT))
  9231. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  9232. if (CNIC_SUPPORT(bp))
  9233. bnx2x_get_cnic_mac_hwinfo(bp);
  9234. } else {
  9235. /* in SF read MACs from port configuration */
  9236. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
  9237. val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
  9238. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  9239. if (CNIC_SUPPORT(bp))
  9240. bnx2x_get_cnic_mac_hwinfo(bp);
  9241. }
  9242. memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN);
  9243. if (!bnx2x_is_valid_ether_addr(bp, bp->dev->dev_addr))
  9244. dev_err(&bp->pdev->dev,
  9245. "bad Ethernet MAC address configuration: %pM\n"
  9246. "change it manually before bringing up the appropriate network interface\n",
  9247. bp->dev->dev_addr);
  9248. }
  9249. static bool bnx2x_get_dropless_info(struct bnx2x *bp)
  9250. {
  9251. int tmp;
  9252. u32 cfg;
  9253. if (IS_MF(bp) && !CHIP_IS_E1x(bp)) {
  9254. /* Take function: tmp = func */
  9255. tmp = BP_ABS_FUNC(bp);
  9256. cfg = MF_CFG_RD(bp, func_ext_config[tmp].func_cfg);
  9257. cfg = !!(cfg & MACP_FUNC_CFG_PAUSE_ON_HOST_RING);
  9258. } else {
  9259. /* Take port: tmp = port */
  9260. tmp = BP_PORT(bp);
  9261. cfg = SHMEM_RD(bp,
  9262. dev_info.port_hw_config[tmp].generic_features);
  9263. cfg = !!(cfg & PORT_HW_CFG_PAUSE_ON_HOST_RING_ENABLED);
  9264. }
  9265. return cfg;
  9266. }
  9267. static int bnx2x_get_hwinfo(struct bnx2x *bp)
  9268. {
  9269. int /*abs*/func = BP_ABS_FUNC(bp);
  9270. int vn;
  9271. u32 val = 0;
  9272. int rc = 0;
  9273. bnx2x_get_common_hwinfo(bp);
  9274. /*
  9275. * initialize IGU parameters
  9276. */
  9277. if (CHIP_IS_E1x(bp)) {
  9278. bp->common.int_block = INT_BLOCK_HC;
  9279. bp->igu_dsb_id = DEF_SB_IGU_ID;
  9280. bp->igu_base_sb = 0;
  9281. } else {
  9282. bp->common.int_block = INT_BLOCK_IGU;
  9283. /* do not allow device reset during IGU info preocessing */
  9284. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  9285. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  9286. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  9287. int tout = 5000;
  9288. BNX2X_DEV_INFO("FORCING Normal Mode\n");
  9289. val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN);
  9290. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION, val);
  9291. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x7f);
  9292. while (tout && REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  9293. tout--;
  9294. usleep_range(1000, 2000);
  9295. }
  9296. if (REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  9297. dev_err(&bp->pdev->dev,
  9298. "FORCING Normal Mode failed!!!\n");
  9299. bnx2x_release_hw_lock(bp,
  9300. HW_LOCK_RESOURCE_RESET);
  9301. return -EPERM;
  9302. }
  9303. }
  9304. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  9305. BNX2X_DEV_INFO("IGU Backward Compatible Mode\n");
  9306. bp->common.int_block |= INT_BLOCK_MODE_BW_COMP;
  9307. } else
  9308. BNX2X_DEV_INFO("IGU Normal Mode\n");
  9309. rc = bnx2x_get_igu_cam_info(bp);
  9310. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  9311. if (rc)
  9312. return rc;
  9313. }
  9314. /*
  9315. * set base FW non-default (fast path) status block id, this value is
  9316. * used to initialize the fw_sb_id saved on the fp/queue structure to
  9317. * determine the id used by the FW.
  9318. */
  9319. if (CHIP_IS_E1x(bp))
  9320. bp->base_fw_ndsb = BP_PORT(bp) * FP_SB_MAX_E1x + BP_L_ID(bp);
  9321. else /*
  9322. * 57712 - we currently use one FW SB per IGU SB (Rx and Tx of
  9323. * the same queue are indicated on the same IGU SB). So we prefer
  9324. * FW and IGU SBs to be the same value.
  9325. */
  9326. bp->base_fw_ndsb = bp->igu_base_sb;
  9327. BNX2X_DEV_INFO("igu_dsb_id %d igu_base_sb %d igu_sb_cnt %d\n"
  9328. "base_fw_ndsb %d\n", bp->igu_dsb_id, bp->igu_base_sb,
  9329. bp->igu_sb_cnt, bp->base_fw_ndsb);
  9330. /*
  9331. * Initialize MF configuration
  9332. */
  9333. bp->mf_ov = 0;
  9334. bp->mf_mode = 0;
  9335. vn = BP_VN(bp);
  9336. if (!CHIP_IS_E1(bp) && !BP_NOMCP(bp)) {
  9337. BNX2X_DEV_INFO("shmem2base 0x%x, size %d, mfcfg offset %d\n",
  9338. bp->common.shmem2_base, SHMEM2_RD(bp, size),
  9339. (u32)offsetof(struct shmem2_region, mf_cfg_addr));
  9340. if (SHMEM2_HAS(bp, mf_cfg_addr))
  9341. bp->common.mf_cfg_base = SHMEM2_RD(bp, mf_cfg_addr);
  9342. else
  9343. bp->common.mf_cfg_base = bp->common.shmem_base +
  9344. offsetof(struct shmem_region, func_mb) +
  9345. E1H_FUNC_MAX * sizeof(struct drv_func_mb);
  9346. /*
  9347. * get mf configuration:
  9348. * 1. existence of MF configuration
  9349. * 2. MAC address must be legal (check only upper bytes)
  9350. * for Switch-Independent mode;
  9351. * OVLAN must be legal for Switch-Dependent mode
  9352. * 3. SF_MODE configures specific MF mode
  9353. */
  9354. if (bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  9355. /* get mf configuration */
  9356. val = SHMEM_RD(bp,
  9357. dev_info.shared_feature_config.config);
  9358. val &= SHARED_FEAT_CFG_FORCE_SF_MODE_MASK;
  9359. switch (val) {
  9360. case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT:
  9361. val = MF_CFG_RD(bp, func_mf_config[func].
  9362. mac_upper);
  9363. /* check for legal mac (upper bytes)*/
  9364. if (val != 0xffff) {
  9365. bp->mf_mode = MULTI_FUNCTION_SI;
  9366. bp->mf_config[vn] = MF_CFG_RD(bp,
  9367. func_mf_config[func].config);
  9368. } else
  9369. BNX2X_DEV_INFO("illegal MAC address for SI\n");
  9370. break;
  9371. case SHARED_FEAT_CFG_FORCE_SF_MODE_AFEX_MODE:
  9372. if ((!CHIP_IS_E1x(bp)) &&
  9373. (MF_CFG_RD(bp, func_mf_config[func].
  9374. mac_upper) != 0xffff) &&
  9375. (SHMEM2_HAS(bp,
  9376. afex_driver_support))) {
  9377. bp->mf_mode = MULTI_FUNCTION_AFEX;
  9378. bp->mf_config[vn] = MF_CFG_RD(bp,
  9379. func_mf_config[func].config);
  9380. } else {
  9381. BNX2X_DEV_INFO("can not configure afex mode\n");
  9382. }
  9383. break;
  9384. case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED:
  9385. /* get OV configuration */
  9386. val = MF_CFG_RD(bp,
  9387. func_mf_config[FUNC_0].e1hov_tag);
  9388. val &= FUNC_MF_CFG_E1HOV_TAG_MASK;
  9389. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  9390. bp->mf_mode = MULTI_FUNCTION_SD;
  9391. bp->mf_config[vn] = MF_CFG_RD(bp,
  9392. func_mf_config[func].config);
  9393. } else
  9394. BNX2X_DEV_INFO("illegal OV for SD\n");
  9395. break;
  9396. case SHARED_FEAT_CFG_FORCE_SF_MODE_FORCED_SF:
  9397. bp->mf_config[vn] = 0;
  9398. break;
  9399. default:
  9400. /* Unknown configuration: reset mf_config */
  9401. bp->mf_config[vn] = 0;
  9402. BNX2X_DEV_INFO("unknown MF mode 0x%x\n", val);
  9403. }
  9404. }
  9405. BNX2X_DEV_INFO("%s function mode\n",
  9406. IS_MF(bp) ? "multi" : "single");
  9407. switch (bp->mf_mode) {
  9408. case MULTI_FUNCTION_SD:
  9409. val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  9410. FUNC_MF_CFG_E1HOV_TAG_MASK;
  9411. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  9412. bp->mf_ov = val;
  9413. bp->path_has_ovlan = true;
  9414. BNX2X_DEV_INFO("MF OV for func %d is %d (0x%04x)\n",
  9415. func, bp->mf_ov, bp->mf_ov);
  9416. } else {
  9417. dev_err(&bp->pdev->dev,
  9418. "No valid MF OV for func %d, aborting\n",
  9419. func);
  9420. return -EPERM;
  9421. }
  9422. break;
  9423. case MULTI_FUNCTION_AFEX:
  9424. BNX2X_DEV_INFO("func %d is in MF afex mode\n", func);
  9425. break;
  9426. case MULTI_FUNCTION_SI:
  9427. BNX2X_DEV_INFO("func %d is in MF switch-independent mode\n",
  9428. func);
  9429. break;
  9430. default:
  9431. if (vn) {
  9432. dev_err(&bp->pdev->dev,
  9433. "VN %d is in a single function mode, aborting\n",
  9434. vn);
  9435. return -EPERM;
  9436. }
  9437. break;
  9438. }
  9439. /* check if other port on the path needs ovlan:
  9440. * Since MF configuration is shared between ports
  9441. * Possible mixed modes are only
  9442. * {SF, SI} {SF, SD} {SD, SF} {SI, SF}
  9443. */
  9444. if (CHIP_MODE_IS_4_PORT(bp) &&
  9445. !bp->path_has_ovlan &&
  9446. !IS_MF(bp) &&
  9447. bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  9448. u8 other_port = !BP_PORT(bp);
  9449. u8 other_func = BP_PATH(bp) + 2*other_port;
  9450. val = MF_CFG_RD(bp,
  9451. func_mf_config[other_func].e1hov_tag);
  9452. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT)
  9453. bp->path_has_ovlan = true;
  9454. }
  9455. }
  9456. /* adjust igu_sb_cnt to MF for E1x */
  9457. if (CHIP_IS_E1x(bp) && IS_MF(bp))
  9458. bp->igu_sb_cnt /= E1HVN_MAX;
  9459. /* port info */
  9460. bnx2x_get_port_hwinfo(bp);
  9461. /* Get MAC addresses */
  9462. bnx2x_get_mac_hwinfo(bp);
  9463. bnx2x_get_cnic_info(bp);
  9464. return rc;
  9465. }
  9466. static void bnx2x_read_fwinfo(struct bnx2x *bp)
  9467. {
  9468. int cnt, i, block_end, rodi;
  9469. char vpd_start[BNX2X_VPD_LEN+1];
  9470. char str_id_reg[VENDOR_ID_LEN+1];
  9471. char str_id_cap[VENDOR_ID_LEN+1];
  9472. char *vpd_data;
  9473. char *vpd_extended_data = NULL;
  9474. u8 len;
  9475. cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_start);
  9476. memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
  9477. if (cnt < BNX2X_VPD_LEN)
  9478. goto out_not_found;
  9479. /* VPD RO tag should be first tag after identifier string, hence
  9480. * we should be able to find it in first BNX2X_VPD_LEN chars
  9481. */
  9482. i = pci_vpd_find_tag(vpd_start, 0, BNX2X_VPD_LEN,
  9483. PCI_VPD_LRDT_RO_DATA);
  9484. if (i < 0)
  9485. goto out_not_found;
  9486. block_end = i + PCI_VPD_LRDT_TAG_SIZE +
  9487. pci_vpd_lrdt_size(&vpd_start[i]);
  9488. i += PCI_VPD_LRDT_TAG_SIZE;
  9489. if (block_end > BNX2X_VPD_LEN) {
  9490. vpd_extended_data = kmalloc(block_end, GFP_KERNEL);
  9491. if (vpd_extended_data == NULL)
  9492. goto out_not_found;
  9493. /* read rest of vpd image into vpd_extended_data */
  9494. memcpy(vpd_extended_data, vpd_start, BNX2X_VPD_LEN);
  9495. cnt = pci_read_vpd(bp->pdev, BNX2X_VPD_LEN,
  9496. block_end - BNX2X_VPD_LEN,
  9497. vpd_extended_data + BNX2X_VPD_LEN);
  9498. if (cnt < (block_end - BNX2X_VPD_LEN))
  9499. goto out_not_found;
  9500. vpd_data = vpd_extended_data;
  9501. } else
  9502. vpd_data = vpd_start;
  9503. /* now vpd_data holds full vpd content in both cases */
  9504. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  9505. PCI_VPD_RO_KEYWORD_MFR_ID);
  9506. if (rodi < 0)
  9507. goto out_not_found;
  9508. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  9509. if (len != VENDOR_ID_LEN)
  9510. goto out_not_found;
  9511. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  9512. /* vendor specific info */
  9513. snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL);
  9514. snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL);
  9515. if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) ||
  9516. !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) {
  9517. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  9518. PCI_VPD_RO_KEYWORD_VENDOR0);
  9519. if (rodi >= 0) {
  9520. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  9521. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  9522. if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) {
  9523. memcpy(bp->fw_ver, &vpd_data[rodi], len);
  9524. bp->fw_ver[len] = ' ';
  9525. }
  9526. }
  9527. kfree(vpd_extended_data);
  9528. return;
  9529. }
  9530. out_not_found:
  9531. kfree(vpd_extended_data);
  9532. return;
  9533. }
  9534. static void bnx2x_set_modes_bitmap(struct bnx2x *bp)
  9535. {
  9536. u32 flags = 0;
  9537. if (CHIP_REV_IS_FPGA(bp))
  9538. SET_FLAGS(flags, MODE_FPGA);
  9539. else if (CHIP_REV_IS_EMUL(bp))
  9540. SET_FLAGS(flags, MODE_EMUL);
  9541. else
  9542. SET_FLAGS(flags, MODE_ASIC);
  9543. if (CHIP_MODE_IS_4_PORT(bp))
  9544. SET_FLAGS(flags, MODE_PORT4);
  9545. else
  9546. SET_FLAGS(flags, MODE_PORT2);
  9547. if (CHIP_IS_E2(bp))
  9548. SET_FLAGS(flags, MODE_E2);
  9549. else if (CHIP_IS_E3(bp)) {
  9550. SET_FLAGS(flags, MODE_E3);
  9551. if (CHIP_REV(bp) == CHIP_REV_Ax)
  9552. SET_FLAGS(flags, MODE_E3_A0);
  9553. else /*if (CHIP_REV(bp) == CHIP_REV_Bx)*/
  9554. SET_FLAGS(flags, MODE_E3_B0 | MODE_COS3);
  9555. }
  9556. if (IS_MF(bp)) {
  9557. SET_FLAGS(flags, MODE_MF);
  9558. switch (bp->mf_mode) {
  9559. case MULTI_FUNCTION_SD:
  9560. SET_FLAGS(flags, MODE_MF_SD);
  9561. break;
  9562. case MULTI_FUNCTION_SI:
  9563. SET_FLAGS(flags, MODE_MF_SI);
  9564. break;
  9565. case MULTI_FUNCTION_AFEX:
  9566. SET_FLAGS(flags, MODE_MF_AFEX);
  9567. break;
  9568. }
  9569. } else
  9570. SET_FLAGS(flags, MODE_SF);
  9571. #if defined(__LITTLE_ENDIAN)
  9572. SET_FLAGS(flags, MODE_LITTLE_ENDIAN);
  9573. #else /*(__BIG_ENDIAN)*/
  9574. SET_FLAGS(flags, MODE_BIG_ENDIAN);
  9575. #endif
  9576. INIT_MODE_FLAGS(bp) = flags;
  9577. }
  9578. static int bnx2x_init_bp(struct bnx2x *bp)
  9579. {
  9580. int func;
  9581. int rc;
  9582. mutex_init(&bp->port.phy_mutex);
  9583. mutex_init(&bp->fw_mb_mutex);
  9584. spin_lock_init(&bp->stats_lock);
  9585. INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task);
  9586. INIT_DELAYED_WORK(&bp->sp_rtnl_task, bnx2x_sp_rtnl_task);
  9587. INIT_DELAYED_WORK(&bp->period_task, bnx2x_period_task);
  9588. if (IS_PF(bp)) {
  9589. rc = bnx2x_get_hwinfo(bp);
  9590. if (rc)
  9591. return rc;
  9592. } else {
  9593. eth_zero_addr(bp->dev->dev_addr);
  9594. }
  9595. bnx2x_set_modes_bitmap(bp);
  9596. rc = bnx2x_alloc_mem_bp(bp);
  9597. if (rc)
  9598. return rc;
  9599. bnx2x_read_fwinfo(bp);
  9600. func = BP_FUNC(bp);
  9601. /* need to reset chip if undi was active */
  9602. if (IS_PF(bp) && !BP_NOMCP(bp)) {
  9603. /* init fw_seq */
  9604. bp->fw_seq =
  9605. SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
  9606. DRV_MSG_SEQ_NUMBER_MASK;
  9607. BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
  9608. bnx2x_prev_unload(bp);
  9609. }
  9610. if (CHIP_REV_IS_FPGA(bp))
  9611. dev_err(&bp->pdev->dev, "FPGA detected\n");
  9612. if (BP_NOMCP(bp) && (func == 0))
  9613. dev_err(&bp->pdev->dev, "MCP disabled, must load devices in order!\n");
  9614. bp->disable_tpa = disable_tpa;
  9615. bp->disable_tpa |= IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp);
  9616. /* Set TPA flags */
  9617. if (bp->disable_tpa) {
  9618. bp->flags &= ~(TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
  9619. bp->dev->features &= ~NETIF_F_LRO;
  9620. } else {
  9621. bp->flags |= (TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
  9622. bp->dev->features |= NETIF_F_LRO;
  9623. }
  9624. if (CHIP_IS_E1(bp))
  9625. bp->dropless_fc = 0;
  9626. else
  9627. bp->dropless_fc = dropless_fc | bnx2x_get_dropless_info(bp);
  9628. bp->mrrs = mrrs;
  9629. bp->tx_ring_size = IS_MF_FCOE_AFEX(bp) ? 0 : MAX_TX_AVAIL;
  9630. if (IS_VF(bp))
  9631. bp->rx_ring_size = MAX_RX_AVAIL;
  9632. /* make sure that the numbers are in the right granularity */
  9633. bp->tx_ticks = (50 / BNX2X_BTR) * BNX2X_BTR;
  9634. bp->rx_ticks = (25 / BNX2X_BTR) * BNX2X_BTR;
  9635. bp->current_interval = CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ;
  9636. init_timer(&bp->timer);
  9637. bp->timer.expires = jiffies + bp->current_interval;
  9638. bp->timer.data = (unsigned long) bp;
  9639. bp->timer.function = bnx2x_timer;
  9640. if (SHMEM2_HAS(bp, dcbx_lldp_params_offset) &&
  9641. SHMEM2_HAS(bp, dcbx_lldp_dcbx_stat_offset) &&
  9642. SHMEM2_RD(bp, dcbx_lldp_params_offset) &&
  9643. SHMEM2_RD(bp, dcbx_lldp_dcbx_stat_offset)) {
  9644. bnx2x_dcbx_set_state(bp, true, BNX2X_DCBX_ENABLED_ON_NEG_ON);
  9645. bnx2x_dcbx_init_params(bp);
  9646. } else {
  9647. bnx2x_dcbx_set_state(bp, false, BNX2X_DCBX_ENABLED_OFF);
  9648. }
  9649. if (CHIP_IS_E1x(bp))
  9650. bp->cnic_base_cl_id = FP_SB_MAX_E1x;
  9651. else
  9652. bp->cnic_base_cl_id = FP_SB_MAX_E2;
  9653. /* multiple tx priority */
  9654. if (IS_VF(bp))
  9655. bp->max_cos = 1;
  9656. else if (CHIP_IS_E1x(bp))
  9657. bp->max_cos = BNX2X_MULTI_TX_COS_E1X;
  9658. else if (CHIP_IS_E2(bp) || CHIP_IS_E3A0(bp))
  9659. bp->max_cos = BNX2X_MULTI_TX_COS_E2_E3A0;
  9660. else if (CHIP_IS_E3B0(bp))
  9661. bp->max_cos = BNX2X_MULTI_TX_COS_E3B0;
  9662. else
  9663. BNX2X_ERR("unknown chip %x revision %x\n",
  9664. CHIP_NUM(bp), CHIP_REV(bp));
  9665. BNX2X_DEV_INFO("set bp->max_cos to %d\n", bp->max_cos);
  9666. /* We need at least one default status block for slow-path events,
  9667. * second status block for the L2 queue, and a third status block for
  9668. * CNIC if supproted.
  9669. */
  9670. if (CNIC_SUPPORT(bp))
  9671. bp->min_msix_vec_cnt = 3;
  9672. else
  9673. bp->min_msix_vec_cnt = 2;
  9674. BNX2X_DEV_INFO("bp->min_msix_vec_cnt %d", bp->min_msix_vec_cnt);
  9675. return rc;
  9676. }
  9677. /****************************************************************************
  9678. * General service functions
  9679. ****************************************************************************/
  9680. /*
  9681. * net_device service functions
  9682. */
  9683. /* called with rtnl_lock */
  9684. static int bnx2x_open(struct net_device *dev)
  9685. {
  9686. struct bnx2x *bp = netdev_priv(dev);
  9687. bool global = false;
  9688. int other_engine = BP_PATH(bp) ? 0 : 1;
  9689. bool other_load_status, load_status;
  9690. int rc;
  9691. bp->stats_init = true;
  9692. netif_carrier_off(dev);
  9693. bnx2x_set_power_state(bp, PCI_D0);
  9694. /* If parity had happen during the unload, then attentions
  9695. * and/or RECOVERY_IN_PROGRES may still be set. In this case we
  9696. * want the first function loaded on the current engine to
  9697. * complete the recovery.
  9698. * Parity recovery is only relevant for PF driver.
  9699. */
  9700. if (IS_PF(bp)) {
  9701. other_load_status = bnx2x_get_load_status(bp, other_engine);
  9702. load_status = bnx2x_get_load_status(bp, BP_PATH(bp));
  9703. if (!bnx2x_reset_is_done(bp, BP_PATH(bp)) ||
  9704. bnx2x_chk_parity_attn(bp, &global, true)) {
  9705. do {
  9706. /* If there are attentions and they are in a
  9707. * global blocks, set the GLOBAL_RESET bit
  9708. * regardless whether it will be this function
  9709. * that will complete the recovery or not.
  9710. */
  9711. if (global)
  9712. bnx2x_set_reset_global(bp);
  9713. /* Only the first function on the current
  9714. * engine should try to recover in open. In case
  9715. * of attentions in global blocks only the first
  9716. * in the chip should try to recover.
  9717. */
  9718. if ((!load_status &&
  9719. (!global || !other_load_status)) &&
  9720. bnx2x_trylock_leader_lock(bp) &&
  9721. !bnx2x_leader_reset(bp)) {
  9722. netdev_info(bp->dev,
  9723. "Recovered in open\n");
  9724. break;
  9725. }
  9726. /* recovery has failed... */
  9727. bnx2x_set_power_state(bp, PCI_D3hot);
  9728. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  9729. BNX2X_ERR("Recovery flow hasn't been properly completed yet. Try again later.\n"
  9730. "If you still see this message after a few retries then power cycle is required.\n");
  9731. return -EAGAIN;
  9732. } while (0);
  9733. }
  9734. }
  9735. bp->recovery_state = BNX2X_RECOVERY_DONE;
  9736. rc = bnx2x_nic_load(bp, LOAD_OPEN);
  9737. if (rc)
  9738. return rc;
  9739. return bnx2x_open_epilog(bp);
  9740. }
  9741. /* called with rtnl_lock */
  9742. static int bnx2x_close(struct net_device *dev)
  9743. {
  9744. struct bnx2x *bp = netdev_priv(dev);
  9745. /* Unload the driver, release IRQs */
  9746. bnx2x_nic_unload(bp, UNLOAD_CLOSE, false);
  9747. return 0;
  9748. }
  9749. static int bnx2x_init_mcast_macs_list(struct bnx2x *bp,
  9750. struct bnx2x_mcast_ramrod_params *p)
  9751. {
  9752. int mc_count = netdev_mc_count(bp->dev);
  9753. struct bnx2x_mcast_list_elem *mc_mac =
  9754. kzalloc(sizeof(*mc_mac) * mc_count, GFP_ATOMIC);
  9755. struct netdev_hw_addr *ha;
  9756. if (!mc_mac)
  9757. return -ENOMEM;
  9758. INIT_LIST_HEAD(&p->mcast_list);
  9759. netdev_for_each_mc_addr(ha, bp->dev) {
  9760. mc_mac->mac = bnx2x_mc_addr(ha);
  9761. list_add_tail(&mc_mac->link, &p->mcast_list);
  9762. mc_mac++;
  9763. }
  9764. p->mcast_list_len = mc_count;
  9765. return 0;
  9766. }
  9767. static void bnx2x_free_mcast_macs_list(
  9768. struct bnx2x_mcast_ramrod_params *p)
  9769. {
  9770. struct bnx2x_mcast_list_elem *mc_mac =
  9771. list_first_entry(&p->mcast_list, struct bnx2x_mcast_list_elem,
  9772. link);
  9773. WARN_ON(!mc_mac);
  9774. kfree(mc_mac);
  9775. }
  9776. /**
  9777. * bnx2x_set_uc_list - configure a new unicast MACs list.
  9778. *
  9779. * @bp: driver handle
  9780. *
  9781. * We will use zero (0) as a MAC type for these MACs.
  9782. */
  9783. static int bnx2x_set_uc_list(struct bnx2x *bp)
  9784. {
  9785. int rc;
  9786. struct net_device *dev = bp->dev;
  9787. struct netdev_hw_addr *ha;
  9788. struct bnx2x_vlan_mac_obj *mac_obj = &bp->sp_objs->mac_obj;
  9789. unsigned long ramrod_flags = 0;
  9790. /* First schedule a cleanup up of old configuration */
  9791. rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, false);
  9792. if (rc < 0) {
  9793. BNX2X_ERR("Failed to schedule DELETE operations: %d\n", rc);
  9794. return rc;
  9795. }
  9796. netdev_for_each_uc_addr(ha, dev) {
  9797. rc = bnx2x_set_mac_one(bp, bnx2x_uc_addr(ha), mac_obj, true,
  9798. BNX2X_UC_LIST_MAC, &ramrod_flags);
  9799. if (rc == -EEXIST) {
  9800. DP(BNX2X_MSG_SP,
  9801. "Failed to schedule ADD operations: %d\n", rc);
  9802. /* do not treat adding same MAC as error */
  9803. rc = 0;
  9804. } else if (rc < 0) {
  9805. BNX2X_ERR("Failed to schedule ADD operations: %d\n",
  9806. rc);
  9807. return rc;
  9808. }
  9809. }
  9810. /* Execute the pending commands */
  9811. __set_bit(RAMROD_CONT, &ramrod_flags);
  9812. return bnx2x_set_mac_one(bp, NULL, mac_obj, false /* don't care */,
  9813. BNX2X_UC_LIST_MAC, &ramrod_flags);
  9814. }
  9815. static int bnx2x_set_mc_list(struct bnx2x *bp)
  9816. {
  9817. struct net_device *dev = bp->dev;
  9818. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  9819. int rc = 0;
  9820. rparam.mcast_obj = &bp->mcast_obj;
  9821. /* first, clear all configured multicast MACs */
  9822. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  9823. if (rc < 0) {
  9824. BNX2X_ERR("Failed to clear multicast configuration: %d\n", rc);
  9825. return rc;
  9826. }
  9827. /* then, configure a new MACs list */
  9828. if (netdev_mc_count(dev)) {
  9829. rc = bnx2x_init_mcast_macs_list(bp, &rparam);
  9830. if (rc) {
  9831. BNX2X_ERR("Failed to create multicast MACs list: %d\n",
  9832. rc);
  9833. return rc;
  9834. }
  9835. /* Now add the new MACs */
  9836. rc = bnx2x_config_mcast(bp, &rparam,
  9837. BNX2X_MCAST_CMD_ADD);
  9838. if (rc < 0)
  9839. BNX2X_ERR("Failed to set a new multicast configuration: %d\n",
  9840. rc);
  9841. bnx2x_free_mcast_macs_list(&rparam);
  9842. }
  9843. return rc;
  9844. }
  9845. /* If bp->state is OPEN, should be called with netif_addr_lock_bh() */
  9846. void bnx2x_set_rx_mode(struct net_device *dev)
  9847. {
  9848. struct bnx2x *bp = netdev_priv(dev);
  9849. u32 rx_mode = BNX2X_RX_MODE_NORMAL;
  9850. if (bp->state != BNX2X_STATE_OPEN) {
  9851. DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
  9852. return;
  9853. }
  9854. DP(NETIF_MSG_IFUP, "dev->flags = %x\n", bp->dev->flags);
  9855. if (dev->flags & IFF_PROMISC)
  9856. rx_mode = BNX2X_RX_MODE_PROMISC;
  9857. else if ((dev->flags & IFF_ALLMULTI) ||
  9858. ((netdev_mc_count(dev) > BNX2X_MAX_MULTICAST) &&
  9859. CHIP_IS_E1(bp)))
  9860. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  9861. else {
  9862. if (IS_PF(bp)) {
  9863. /* some multicasts */
  9864. if (bnx2x_set_mc_list(bp) < 0)
  9865. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  9866. if (bnx2x_set_uc_list(bp) < 0)
  9867. rx_mode = BNX2X_RX_MODE_PROMISC;
  9868. } else {
  9869. /* configuring mcast to a vf involves sleeping (when we
  9870. * wait for the pf's response). Since this function is
  9871. * called from non sleepable context we must schedule
  9872. * a work item for this purpose
  9873. */
  9874. smp_mb__before_clear_bit();
  9875. set_bit(BNX2X_SP_RTNL_VFPF_MCAST,
  9876. &bp->sp_rtnl_state);
  9877. smp_mb__after_clear_bit();
  9878. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  9879. }
  9880. }
  9881. bp->rx_mode = rx_mode;
  9882. /* handle ISCSI SD mode */
  9883. if (IS_MF_ISCSI_SD(bp))
  9884. bp->rx_mode = BNX2X_RX_MODE_NONE;
  9885. /* Schedule the rx_mode command */
  9886. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) {
  9887. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  9888. return;
  9889. }
  9890. if (IS_PF(bp)) {
  9891. bnx2x_set_storm_rx_mode(bp);
  9892. } else {
  9893. /* configuring rx mode to storms in a vf involves sleeping (when
  9894. * we wait for the pf's response). Since this function is
  9895. * called from non sleepable context we must schedule
  9896. * a work item for this purpose
  9897. */
  9898. smp_mb__before_clear_bit();
  9899. set_bit(BNX2X_SP_RTNL_VFPF_STORM_RX_MODE,
  9900. &bp->sp_rtnl_state);
  9901. smp_mb__after_clear_bit();
  9902. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  9903. }
  9904. }
  9905. /* called with rtnl_lock */
  9906. static int bnx2x_mdio_read(struct net_device *netdev, int prtad,
  9907. int devad, u16 addr)
  9908. {
  9909. struct bnx2x *bp = netdev_priv(netdev);
  9910. u16 value;
  9911. int rc;
  9912. DP(NETIF_MSG_LINK, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n",
  9913. prtad, devad, addr);
  9914. /* The HW expects different devad if CL22 is used */
  9915. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  9916. bnx2x_acquire_phy_lock(bp);
  9917. rc = bnx2x_phy_read(&bp->link_params, prtad, devad, addr, &value);
  9918. bnx2x_release_phy_lock(bp);
  9919. DP(NETIF_MSG_LINK, "mdio_read_val 0x%x rc = 0x%x\n", value, rc);
  9920. if (!rc)
  9921. rc = value;
  9922. return rc;
  9923. }
  9924. /* called with rtnl_lock */
  9925. static int bnx2x_mdio_write(struct net_device *netdev, int prtad, int devad,
  9926. u16 addr, u16 value)
  9927. {
  9928. struct bnx2x *bp = netdev_priv(netdev);
  9929. int rc;
  9930. DP(NETIF_MSG_LINK,
  9931. "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x, value 0x%x\n",
  9932. prtad, devad, addr, value);
  9933. /* The HW expects different devad if CL22 is used */
  9934. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  9935. bnx2x_acquire_phy_lock(bp);
  9936. rc = bnx2x_phy_write(&bp->link_params, prtad, devad, addr, value);
  9937. bnx2x_release_phy_lock(bp);
  9938. return rc;
  9939. }
  9940. /* called with rtnl_lock */
  9941. static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  9942. {
  9943. struct bnx2x *bp = netdev_priv(dev);
  9944. struct mii_ioctl_data *mdio = if_mii(ifr);
  9945. DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n",
  9946. mdio->phy_id, mdio->reg_num, mdio->val_in);
  9947. if (!netif_running(dev))
  9948. return -EAGAIN;
  9949. return mdio_mii_ioctl(&bp->mdio, mdio, cmd);
  9950. }
  9951. #ifdef CONFIG_NET_POLL_CONTROLLER
  9952. static void poll_bnx2x(struct net_device *dev)
  9953. {
  9954. struct bnx2x *bp = netdev_priv(dev);
  9955. int i;
  9956. for_each_eth_queue(bp, i) {
  9957. struct bnx2x_fastpath *fp = &bp->fp[i];
  9958. napi_schedule(&bnx2x_fp(bp, fp->index, napi));
  9959. }
  9960. }
  9961. #endif
  9962. static int bnx2x_validate_addr(struct net_device *dev)
  9963. {
  9964. struct bnx2x *bp = netdev_priv(dev);
  9965. /* query the bulletin board for mac address configured by the PF */
  9966. if (IS_VF(bp))
  9967. bnx2x_sample_bulletin(bp);
  9968. if (!bnx2x_is_valid_ether_addr(bp, dev->dev_addr)) {
  9969. BNX2X_ERR("Non-valid Ethernet address\n");
  9970. return -EADDRNOTAVAIL;
  9971. }
  9972. return 0;
  9973. }
  9974. static const struct net_device_ops bnx2x_netdev_ops = {
  9975. .ndo_open = bnx2x_open,
  9976. .ndo_stop = bnx2x_close,
  9977. .ndo_start_xmit = bnx2x_start_xmit,
  9978. .ndo_select_queue = bnx2x_select_queue,
  9979. .ndo_set_rx_mode = bnx2x_set_rx_mode,
  9980. .ndo_set_mac_address = bnx2x_change_mac_addr,
  9981. .ndo_validate_addr = bnx2x_validate_addr,
  9982. .ndo_do_ioctl = bnx2x_ioctl,
  9983. .ndo_change_mtu = bnx2x_change_mtu,
  9984. .ndo_fix_features = bnx2x_fix_features,
  9985. .ndo_set_features = bnx2x_set_features,
  9986. .ndo_tx_timeout = bnx2x_tx_timeout,
  9987. #ifdef CONFIG_NET_POLL_CONTROLLER
  9988. .ndo_poll_controller = poll_bnx2x,
  9989. #endif
  9990. .ndo_setup_tc = bnx2x_setup_tc,
  9991. #ifdef CONFIG_BNX2X_SRIOV
  9992. .ndo_set_vf_mac = bnx2x_set_vf_mac,
  9993. .ndo_set_vf_vlan = bnx2x_set_vf_vlan,
  9994. .ndo_get_vf_config = bnx2x_get_vf_config,
  9995. #endif
  9996. #ifdef NETDEV_FCOE_WWNN
  9997. .ndo_fcoe_get_wwn = bnx2x_fcoe_get_wwn,
  9998. #endif
  9999. };
  10000. static int bnx2x_set_coherency_mask(struct bnx2x *bp)
  10001. {
  10002. struct device *dev = &bp->pdev->dev;
  10003. if (dma_set_mask(dev, DMA_BIT_MASK(64)) == 0) {
  10004. bp->flags |= USING_DAC_FLAG;
  10005. if (dma_set_coherent_mask(dev, DMA_BIT_MASK(64)) != 0) {
  10006. dev_err(dev, "dma_set_coherent_mask failed, aborting\n");
  10007. return -EIO;
  10008. }
  10009. } else if (dma_set_mask(dev, DMA_BIT_MASK(32)) != 0) {
  10010. dev_err(dev, "System does not support DMA, aborting\n");
  10011. return -EIO;
  10012. }
  10013. return 0;
  10014. }
  10015. static int bnx2x_init_dev(struct bnx2x *bp, struct pci_dev *pdev,
  10016. struct net_device *dev, unsigned long board_type)
  10017. {
  10018. int rc;
  10019. u32 pci_cfg_dword;
  10020. bool chip_is_e1x = (board_type == BCM57710 ||
  10021. board_type == BCM57711 ||
  10022. board_type == BCM57711E);
  10023. SET_NETDEV_DEV(dev, &pdev->dev);
  10024. bp->dev = dev;
  10025. bp->pdev = pdev;
  10026. rc = pci_enable_device(pdev);
  10027. if (rc) {
  10028. dev_err(&bp->pdev->dev,
  10029. "Cannot enable PCI device, aborting\n");
  10030. goto err_out;
  10031. }
  10032. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  10033. dev_err(&bp->pdev->dev,
  10034. "Cannot find PCI device base address, aborting\n");
  10035. rc = -ENODEV;
  10036. goto err_out_disable;
  10037. }
  10038. if (IS_PF(bp) && !(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
  10039. dev_err(&bp->pdev->dev, "Cannot find second PCI device base address, aborting\n");
  10040. rc = -ENODEV;
  10041. goto err_out_disable;
  10042. }
  10043. pci_read_config_dword(pdev, PCICFG_REVISION_ID_OFFSET, &pci_cfg_dword);
  10044. if ((pci_cfg_dword & PCICFG_REVESION_ID_MASK) ==
  10045. PCICFG_REVESION_ID_ERROR_VAL) {
  10046. pr_err("PCI device error, probably due to fan failure, aborting\n");
  10047. rc = -ENODEV;
  10048. goto err_out_disable;
  10049. }
  10050. if (atomic_read(&pdev->enable_cnt) == 1) {
  10051. rc = pci_request_regions(pdev, DRV_MODULE_NAME);
  10052. if (rc) {
  10053. dev_err(&bp->pdev->dev,
  10054. "Cannot obtain PCI resources, aborting\n");
  10055. goto err_out_disable;
  10056. }
  10057. pci_set_master(pdev);
  10058. pci_save_state(pdev);
  10059. }
  10060. if (IS_PF(bp)) {
  10061. bp->pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
  10062. if (bp->pm_cap == 0) {
  10063. dev_err(&bp->pdev->dev,
  10064. "Cannot find power management capability, aborting\n");
  10065. rc = -EIO;
  10066. goto err_out_release;
  10067. }
  10068. }
  10069. if (!pci_is_pcie(pdev)) {
  10070. dev_err(&bp->pdev->dev, "Not PCI Express, aborting\n");
  10071. rc = -EIO;
  10072. goto err_out_release;
  10073. }
  10074. rc = bnx2x_set_coherency_mask(bp);
  10075. if (rc)
  10076. goto err_out_release;
  10077. dev->mem_start = pci_resource_start(pdev, 0);
  10078. dev->base_addr = dev->mem_start;
  10079. dev->mem_end = pci_resource_end(pdev, 0);
  10080. dev->irq = pdev->irq;
  10081. bp->regview = pci_ioremap_bar(pdev, 0);
  10082. if (!bp->regview) {
  10083. dev_err(&bp->pdev->dev,
  10084. "Cannot map register space, aborting\n");
  10085. rc = -ENOMEM;
  10086. goto err_out_release;
  10087. }
  10088. /* In E1/E1H use pci device function given by kernel.
  10089. * In E2/E3 read physical function from ME register since these chips
  10090. * support Physical Device Assignment where kernel BDF maybe arbitrary
  10091. * (depending on hypervisor).
  10092. */
  10093. if (chip_is_e1x) {
  10094. bp->pf_num = PCI_FUNC(pdev->devfn);
  10095. } else {
  10096. /* chip is E2/3*/
  10097. pci_read_config_dword(bp->pdev,
  10098. PCICFG_ME_REGISTER, &pci_cfg_dword);
  10099. bp->pf_num = (u8)((pci_cfg_dword & ME_REG_ABS_PF_NUM) >>
  10100. ME_REG_ABS_PF_NUM_SHIFT);
  10101. }
  10102. BNX2X_DEV_INFO("me reg PF num: %d\n", bp->pf_num);
  10103. bnx2x_set_power_state(bp, PCI_D0);
  10104. /* clean indirect addresses */
  10105. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  10106. PCICFG_VENDOR_ID_OFFSET);
  10107. /*
  10108. * Clean the following indirect addresses for all functions since it
  10109. * is not used by the driver.
  10110. */
  10111. if (IS_PF(bp)) {
  10112. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0, 0);
  10113. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0, 0);
  10114. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0, 0);
  10115. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0, 0);
  10116. if (chip_is_e1x) {
  10117. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F1, 0);
  10118. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F1, 0);
  10119. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F1, 0);
  10120. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F1, 0);
  10121. }
  10122. /* Enable internal target-read (in case we are probed after PF
  10123. * FLR). Must be done prior to any BAR read access. Only for
  10124. * 57712 and up
  10125. */
  10126. if (!chip_is_e1x)
  10127. REG_WR(bp,
  10128. PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  10129. }
  10130. dev->watchdog_timeo = TX_TIMEOUT;
  10131. dev->netdev_ops = &bnx2x_netdev_ops;
  10132. bnx2x_set_ethtool_ops(bp, dev);
  10133. dev->priv_flags |= IFF_UNICAST_FLT;
  10134. dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  10135. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
  10136. NETIF_F_RXCSUM | NETIF_F_LRO | NETIF_F_GRO |
  10137. NETIF_F_RXHASH | NETIF_F_HW_VLAN_CTAG_TX;
  10138. if (!CHIP_IS_E1x(bp)) {
  10139. dev->hw_features |= NETIF_F_GSO_GRE | NETIF_F_GSO_UDP_TUNNEL;
  10140. dev->hw_enc_features =
  10141. NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_SG |
  10142. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
  10143. NETIF_F_GSO_GRE | NETIF_F_GSO_UDP_TUNNEL;
  10144. }
  10145. dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  10146. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_HIGHDMA;
  10147. dev->features |= dev->hw_features | NETIF_F_HW_VLAN_CTAG_RX;
  10148. if (bp->flags & USING_DAC_FLAG)
  10149. dev->features |= NETIF_F_HIGHDMA;
  10150. /* Add Loopback capability to the device */
  10151. dev->hw_features |= NETIF_F_LOOPBACK;
  10152. #ifdef BCM_DCBNL
  10153. dev->dcbnl_ops = &bnx2x_dcbnl_ops;
  10154. #endif
  10155. /* get_port_hwinfo() will set prtad and mmds properly */
  10156. bp->mdio.prtad = MDIO_PRTAD_NONE;
  10157. bp->mdio.mmds = 0;
  10158. bp->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
  10159. bp->mdio.dev = dev;
  10160. bp->mdio.mdio_read = bnx2x_mdio_read;
  10161. bp->mdio.mdio_write = bnx2x_mdio_write;
  10162. return 0;
  10163. err_out_release:
  10164. if (atomic_read(&pdev->enable_cnt) == 1)
  10165. pci_release_regions(pdev);
  10166. err_out_disable:
  10167. pci_disable_device(pdev);
  10168. pci_set_drvdata(pdev, NULL);
  10169. err_out:
  10170. return rc;
  10171. }
  10172. static void bnx2x_get_pcie_width_speed(struct bnx2x *bp, int *width,
  10173. enum bnx2x_pci_bus_speed *speed)
  10174. {
  10175. u32 link_speed, val = 0;
  10176. pci_read_config_dword(bp->pdev, PCICFG_LINK_CONTROL, &val);
  10177. *width = (val & PCICFG_LINK_WIDTH) >> PCICFG_LINK_WIDTH_SHIFT;
  10178. link_speed = (val & PCICFG_LINK_SPEED) >> PCICFG_LINK_SPEED_SHIFT;
  10179. switch (link_speed) {
  10180. case 3:
  10181. *speed = BNX2X_PCI_LINK_SPEED_8000;
  10182. break;
  10183. case 2:
  10184. *speed = BNX2X_PCI_LINK_SPEED_5000;
  10185. break;
  10186. default:
  10187. *speed = BNX2X_PCI_LINK_SPEED_2500;
  10188. }
  10189. }
  10190. static int bnx2x_check_firmware(struct bnx2x *bp)
  10191. {
  10192. const struct firmware *firmware = bp->firmware;
  10193. struct bnx2x_fw_file_hdr *fw_hdr;
  10194. struct bnx2x_fw_file_section *sections;
  10195. u32 offset, len, num_ops;
  10196. __be16 *ops_offsets;
  10197. int i;
  10198. const u8 *fw_ver;
  10199. if (firmware->size < sizeof(struct bnx2x_fw_file_hdr)) {
  10200. BNX2X_ERR("Wrong FW size\n");
  10201. return -EINVAL;
  10202. }
  10203. fw_hdr = (struct bnx2x_fw_file_hdr *)firmware->data;
  10204. sections = (struct bnx2x_fw_file_section *)fw_hdr;
  10205. /* Make sure none of the offsets and sizes make us read beyond
  10206. * the end of the firmware data */
  10207. for (i = 0; i < sizeof(*fw_hdr) / sizeof(*sections); i++) {
  10208. offset = be32_to_cpu(sections[i].offset);
  10209. len = be32_to_cpu(sections[i].len);
  10210. if (offset + len > firmware->size) {
  10211. BNX2X_ERR("Section %d length is out of bounds\n", i);
  10212. return -EINVAL;
  10213. }
  10214. }
  10215. /* Likewise for the init_ops offsets */
  10216. offset = be32_to_cpu(fw_hdr->init_ops_offsets.offset);
  10217. ops_offsets = (__force __be16 *)(firmware->data + offset);
  10218. num_ops = be32_to_cpu(fw_hdr->init_ops.len) / sizeof(struct raw_op);
  10219. for (i = 0; i < be32_to_cpu(fw_hdr->init_ops_offsets.len) / 2; i++) {
  10220. if (be16_to_cpu(ops_offsets[i]) > num_ops) {
  10221. BNX2X_ERR("Section offset %d is out of bounds\n", i);
  10222. return -EINVAL;
  10223. }
  10224. }
  10225. /* Check FW version */
  10226. offset = be32_to_cpu(fw_hdr->fw_version.offset);
  10227. fw_ver = firmware->data + offset;
  10228. if ((fw_ver[0] != BCM_5710_FW_MAJOR_VERSION) ||
  10229. (fw_ver[1] != BCM_5710_FW_MINOR_VERSION) ||
  10230. (fw_ver[2] != BCM_5710_FW_REVISION_VERSION) ||
  10231. (fw_ver[3] != BCM_5710_FW_ENGINEERING_VERSION)) {
  10232. BNX2X_ERR("Bad FW version:%d.%d.%d.%d. Should be %d.%d.%d.%d\n",
  10233. fw_ver[0], fw_ver[1], fw_ver[2], fw_ver[3],
  10234. BCM_5710_FW_MAJOR_VERSION,
  10235. BCM_5710_FW_MINOR_VERSION,
  10236. BCM_5710_FW_REVISION_VERSION,
  10237. BCM_5710_FW_ENGINEERING_VERSION);
  10238. return -EINVAL;
  10239. }
  10240. return 0;
  10241. }
  10242. static void be32_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  10243. {
  10244. const __be32 *source = (const __be32 *)_source;
  10245. u32 *target = (u32 *)_target;
  10246. u32 i;
  10247. for (i = 0; i < n/4; i++)
  10248. target[i] = be32_to_cpu(source[i]);
  10249. }
  10250. /*
  10251. Ops array is stored in the following format:
  10252. {op(8bit), offset(24bit, big endian), data(32bit, big endian)}
  10253. */
  10254. static void bnx2x_prep_ops(const u8 *_source, u8 *_target, u32 n)
  10255. {
  10256. const __be32 *source = (const __be32 *)_source;
  10257. struct raw_op *target = (struct raw_op *)_target;
  10258. u32 i, j, tmp;
  10259. for (i = 0, j = 0; i < n/8; i++, j += 2) {
  10260. tmp = be32_to_cpu(source[j]);
  10261. target[i].op = (tmp >> 24) & 0xff;
  10262. target[i].offset = tmp & 0xffffff;
  10263. target[i].raw_data = be32_to_cpu(source[j + 1]);
  10264. }
  10265. }
  10266. /* IRO array is stored in the following format:
  10267. * {base(24bit), m1(16bit), m2(16bit), m3(16bit), size(16bit) }
  10268. */
  10269. static void bnx2x_prep_iro(const u8 *_source, u8 *_target, u32 n)
  10270. {
  10271. const __be32 *source = (const __be32 *)_source;
  10272. struct iro *target = (struct iro *)_target;
  10273. u32 i, j, tmp;
  10274. for (i = 0, j = 0; i < n/sizeof(struct iro); i++) {
  10275. target[i].base = be32_to_cpu(source[j]);
  10276. j++;
  10277. tmp = be32_to_cpu(source[j]);
  10278. target[i].m1 = (tmp >> 16) & 0xffff;
  10279. target[i].m2 = tmp & 0xffff;
  10280. j++;
  10281. tmp = be32_to_cpu(source[j]);
  10282. target[i].m3 = (tmp >> 16) & 0xffff;
  10283. target[i].size = tmp & 0xffff;
  10284. j++;
  10285. }
  10286. }
  10287. static void be16_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  10288. {
  10289. const __be16 *source = (const __be16 *)_source;
  10290. u16 *target = (u16 *)_target;
  10291. u32 i;
  10292. for (i = 0; i < n/2; i++)
  10293. target[i] = be16_to_cpu(source[i]);
  10294. }
  10295. #define BNX2X_ALLOC_AND_SET(arr, lbl, func) \
  10296. do { \
  10297. u32 len = be32_to_cpu(fw_hdr->arr.len); \
  10298. bp->arr = kmalloc(len, GFP_KERNEL); \
  10299. if (!bp->arr) \
  10300. goto lbl; \
  10301. func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \
  10302. (u8 *)bp->arr, len); \
  10303. } while (0)
  10304. static int bnx2x_init_firmware(struct bnx2x *bp)
  10305. {
  10306. const char *fw_file_name;
  10307. struct bnx2x_fw_file_hdr *fw_hdr;
  10308. int rc;
  10309. if (bp->firmware)
  10310. return 0;
  10311. if (CHIP_IS_E1(bp))
  10312. fw_file_name = FW_FILE_NAME_E1;
  10313. else if (CHIP_IS_E1H(bp))
  10314. fw_file_name = FW_FILE_NAME_E1H;
  10315. else if (!CHIP_IS_E1x(bp))
  10316. fw_file_name = FW_FILE_NAME_E2;
  10317. else {
  10318. BNX2X_ERR("Unsupported chip revision\n");
  10319. return -EINVAL;
  10320. }
  10321. BNX2X_DEV_INFO("Loading %s\n", fw_file_name);
  10322. rc = request_firmware(&bp->firmware, fw_file_name, &bp->pdev->dev);
  10323. if (rc) {
  10324. BNX2X_ERR("Can't load firmware file %s\n",
  10325. fw_file_name);
  10326. goto request_firmware_exit;
  10327. }
  10328. rc = bnx2x_check_firmware(bp);
  10329. if (rc) {
  10330. BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name);
  10331. goto request_firmware_exit;
  10332. }
  10333. fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data;
  10334. /* Initialize the pointers to the init arrays */
  10335. /* Blob */
  10336. BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n);
  10337. /* Opcodes */
  10338. BNX2X_ALLOC_AND_SET(init_ops, init_ops_alloc_err, bnx2x_prep_ops);
  10339. /* Offsets */
  10340. BNX2X_ALLOC_AND_SET(init_ops_offsets, init_offsets_alloc_err,
  10341. be16_to_cpu_n);
  10342. /* STORMs firmware */
  10343. INIT_TSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10344. be32_to_cpu(fw_hdr->tsem_int_table_data.offset);
  10345. INIT_TSEM_PRAM_DATA(bp) = bp->firmware->data +
  10346. be32_to_cpu(fw_hdr->tsem_pram_data.offset);
  10347. INIT_USEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10348. be32_to_cpu(fw_hdr->usem_int_table_data.offset);
  10349. INIT_USEM_PRAM_DATA(bp) = bp->firmware->data +
  10350. be32_to_cpu(fw_hdr->usem_pram_data.offset);
  10351. INIT_XSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10352. be32_to_cpu(fw_hdr->xsem_int_table_data.offset);
  10353. INIT_XSEM_PRAM_DATA(bp) = bp->firmware->data +
  10354. be32_to_cpu(fw_hdr->xsem_pram_data.offset);
  10355. INIT_CSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10356. be32_to_cpu(fw_hdr->csem_int_table_data.offset);
  10357. INIT_CSEM_PRAM_DATA(bp) = bp->firmware->data +
  10358. be32_to_cpu(fw_hdr->csem_pram_data.offset);
  10359. /* IRO */
  10360. BNX2X_ALLOC_AND_SET(iro_arr, iro_alloc_err, bnx2x_prep_iro);
  10361. return 0;
  10362. iro_alloc_err:
  10363. kfree(bp->init_ops_offsets);
  10364. init_offsets_alloc_err:
  10365. kfree(bp->init_ops);
  10366. init_ops_alloc_err:
  10367. kfree(bp->init_data);
  10368. request_firmware_exit:
  10369. release_firmware(bp->firmware);
  10370. bp->firmware = NULL;
  10371. return rc;
  10372. }
  10373. static void bnx2x_release_firmware(struct bnx2x *bp)
  10374. {
  10375. kfree(bp->init_ops_offsets);
  10376. kfree(bp->init_ops);
  10377. kfree(bp->init_data);
  10378. release_firmware(bp->firmware);
  10379. bp->firmware = NULL;
  10380. }
  10381. static struct bnx2x_func_sp_drv_ops bnx2x_func_sp_drv = {
  10382. .init_hw_cmn_chip = bnx2x_init_hw_common_chip,
  10383. .init_hw_cmn = bnx2x_init_hw_common,
  10384. .init_hw_port = bnx2x_init_hw_port,
  10385. .init_hw_func = bnx2x_init_hw_func,
  10386. .reset_hw_cmn = bnx2x_reset_common,
  10387. .reset_hw_port = bnx2x_reset_port,
  10388. .reset_hw_func = bnx2x_reset_func,
  10389. .gunzip_init = bnx2x_gunzip_init,
  10390. .gunzip_end = bnx2x_gunzip_end,
  10391. .init_fw = bnx2x_init_firmware,
  10392. .release_fw = bnx2x_release_firmware,
  10393. };
  10394. void bnx2x__init_func_obj(struct bnx2x *bp)
  10395. {
  10396. /* Prepare DMAE related driver resources */
  10397. bnx2x_setup_dmae(bp);
  10398. bnx2x_init_func_obj(bp, &bp->func_obj,
  10399. bnx2x_sp(bp, func_rdata),
  10400. bnx2x_sp_mapping(bp, func_rdata),
  10401. bnx2x_sp(bp, func_afex_rdata),
  10402. bnx2x_sp_mapping(bp, func_afex_rdata),
  10403. &bnx2x_func_sp_drv);
  10404. }
  10405. /* must be called after sriov-enable */
  10406. static int bnx2x_set_qm_cid_count(struct bnx2x *bp)
  10407. {
  10408. int cid_count = BNX2X_L2_MAX_CID(bp);
  10409. if (IS_SRIOV(bp))
  10410. cid_count += BNX2X_VF_CIDS;
  10411. if (CNIC_SUPPORT(bp))
  10412. cid_count += CNIC_CID_MAX;
  10413. return roundup(cid_count, QM_CID_ROUND);
  10414. }
  10415. /**
  10416. * bnx2x_get_num_none_def_sbs - return the number of none default SBs
  10417. *
  10418. * @dev: pci device
  10419. *
  10420. */
  10421. static int bnx2x_get_num_non_def_sbs(struct pci_dev *pdev,
  10422. int cnic_cnt, bool is_vf)
  10423. {
  10424. int pos, index;
  10425. u16 control = 0;
  10426. pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
  10427. /*
  10428. * If MSI-X is not supported - return number of SBs needed to support
  10429. * one fast path queue: one FP queue + SB for CNIC
  10430. */
  10431. if (!pos) {
  10432. dev_info(&pdev->dev, "no msix capability found\n");
  10433. return 1 + cnic_cnt;
  10434. }
  10435. dev_info(&pdev->dev, "msix capability found\n");
  10436. /*
  10437. * The value in the PCI configuration space is the index of the last
  10438. * entry, namely one less than the actual size of the table, which is
  10439. * exactly what we want to return from this function: number of all SBs
  10440. * without the default SB.
  10441. * For VFs there is no default SB, then we return (index+1).
  10442. */
  10443. pci_read_config_word(pdev, pos + PCI_MSI_FLAGS, &control);
  10444. index = control & PCI_MSIX_FLAGS_QSIZE;
  10445. return is_vf ? index + 1 : index;
  10446. }
  10447. static int set_max_cos_est(int chip_id)
  10448. {
  10449. switch (chip_id) {
  10450. case BCM57710:
  10451. case BCM57711:
  10452. case BCM57711E:
  10453. return BNX2X_MULTI_TX_COS_E1X;
  10454. case BCM57712:
  10455. case BCM57712_MF:
  10456. case BCM57712_VF:
  10457. return BNX2X_MULTI_TX_COS_E2_E3A0;
  10458. case BCM57800:
  10459. case BCM57800_MF:
  10460. case BCM57800_VF:
  10461. case BCM57810:
  10462. case BCM57810_MF:
  10463. case BCM57840_4_10:
  10464. case BCM57840_2_20:
  10465. case BCM57840_O:
  10466. case BCM57840_MFO:
  10467. case BCM57810_VF:
  10468. case BCM57840_MF:
  10469. case BCM57840_VF:
  10470. case BCM57811:
  10471. case BCM57811_MF:
  10472. case BCM57811_VF:
  10473. return BNX2X_MULTI_TX_COS_E3B0;
  10474. return 1;
  10475. default:
  10476. pr_err("Unknown board_type (%d), aborting\n", chip_id);
  10477. return -ENODEV;
  10478. }
  10479. }
  10480. static int set_is_vf(int chip_id)
  10481. {
  10482. switch (chip_id) {
  10483. case BCM57712_VF:
  10484. case BCM57800_VF:
  10485. case BCM57810_VF:
  10486. case BCM57840_VF:
  10487. case BCM57811_VF:
  10488. return true;
  10489. default:
  10490. return false;
  10491. }
  10492. }
  10493. struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev);
  10494. static int bnx2x_init_one(struct pci_dev *pdev,
  10495. const struct pci_device_id *ent)
  10496. {
  10497. struct net_device *dev = NULL;
  10498. struct bnx2x *bp;
  10499. int pcie_width;
  10500. enum bnx2x_pci_bus_speed pcie_speed;
  10501. int rc, max_non_def_sbs;
  10502. int rx_count, tx_count, rss_count, doorbell_size;
  10503. int max_cos_est;
  10504. bool is_vf;
  10505. int cnic_cnt;
  10506. /* An estimated maximum supported CoS number according to the chip
  10507. * version.
  10508. * We will try to roughly estimate the maximum number of CoSes this chip
  10509. * may support in order to minimize the memory allocated for Tx
  10510. * netdev_queue's. This number will be accurately calculated during the
  10511. * initialization of bp->max_cos based on the chip versions AND chip
  10512. * revision in the bnx2x_init_bp().
  10513. */
  10514. max_cos_est = set_max_cos_est(ent->driver_data);
  10515. if (max_cos_est < 0)
  10516. return max_cos_est;
  10517. is_vf = set_is_vf(ent->driver_data);
  10518. cnic_cnt = is_vf ? 0 : 1;
  10519. max_non_def_sbs = bnx2x_get_num_non_def_sbs(pdev, cnic_cnt, is_vf);
  10520. /* Maximum number of RSS queues: one IGU SB goes to CNIC */
  10521. rss_count = is_vf ? 1 : max_non_def_sbs - cnic_cnt;
  10522. if (rss_count < 1)
  10523. return -EINVAL;
  10524. /* Maximum number of netdev Rx queues: RSS + FCoE L2 */
  10525. rx_count = rss_count + cnic_cnt;
  10526. /* Maximum number of netdev Tx queues:
  10527. * Maximum TSS queues * Maximum supported number of CoS + FCoE L2
  10528. */
  10529. tx_count = rss_count * max_cos_est + cnic_cnt;
  10530. /* dev zeroed in init_etherdev */
  10531. dev = alloc_etherdev_mqs(sizeof(*bp), tx_count, rx_count);
  10532. if (!dev)
  10533. return -ENOMEM;
  10534. bp = netdev_priv(dev);
  10535. bp->flags = 0;
  10536. if (is_vf)
  10537. bp->flags |= IS_VF_FLAG;
  10538. bp->igu_sb_cnt = max_non_def_sbs;
  10539. bp->igu_base_addr = IS_VF(bp) ? PXP_VF_ADDR_IGU_START : BAR_IGU_INTMEM;
  10540. bp->msg_enable = debug;
  10541. bp->cnic_support = cnic_cnt;
  10542. bp->cnic_probe = bnx2x_cnic_probe;
  10543. pci_set_drvdata(pdev, dev);
  10544. rc = bnx2x_init_dev(bp, pdev, dev, ent->driver_data);
  10545. if (rc < 0) {
  10546. free_netdev(dev);
  10547. return rc;
  10548. }
  10549. BNX2X_DEV_INFO("This is a %s function\n",
  10550. IS_PF(bp) ? "physical" : "virtual");
  10551. BNX2X_DEV_INFO("Cnic support is %s\n", CNIC_SUPPORT(bp) ? "on" : "off");
  10552. BNX2X_DEV_INFO("Max num of status blocks %d\n", max_non_def_sbs);
  10553. BNX2X_DEV_INFO("Allocated netdev with %d tx and %d rx queues\n",
  10554. tx_count, rx_count);
  10555. rc = bnx2x_init_bp(bp);
  10556. if (rc)
  10557. goto init_one_exit;
  10558. /* Map doorbells here as we need the real value of bp->max_cos which
  10559. * is initialized in bnx2x_init_bp() to determine the number of
  10560. * l2 connections.
  10561. */
  10562. if (IS_VF(bp)) {
  10563. bp->doorbells = bnx2x_vf_doorbells(bp);
  10564. rc = bnx2x_vf_pci_alloc(bp);
  10565. if (rc)
  10566. goto init_one_exit;
  10567. } else {
  10568. doorbell_size = BNX2X_L2_MAX_CID(bp) * (1 << BNX2X_DB_SHIFT);
  10569. if (doorbell_size > pci_resource_len(pdev, 2)) {
  10570. dev_err(&bp->pdev->dev,
  10571. "Cannot map doorbells, bar size too small, aborting\n");
  10572. rc = -ENOMEM;
  10573. goto init_one_exit;
  10574. }
  10575. bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2),
  10576. doorbell_size);
  10577. }
  10578. if (!bp->doorbells) {
  10579. dev_err(&bp->pdev->dev,
  10580. "Cannot map doorbell space, aborting\n");
  10581. rc = -ENOMEM;
  10582. goto init_one_exit;
  10583. }
  10584. if (IS_VF(bp)) {
  10585. rc = bnx2x_vfpf_acquire(bp, tx_count, rx_count);
  10586. if (rc)
  10587. goto init_one_exit;
  10588. }
  10589. /* Enable SRIOV if capability found in configuration space */
  10590. rc = bnx2x_iov_init_one(bp, int_mode, BNX2X_MAX_NUM_OF_VFS);
  10591. if (rc)
  10592. goto init_one_exit;
  10593. /* calc qm_cid_count */
  10594. bp->qm_cid_count = bnx2x_set_qm_cid_count(bp);
  10595. BNX2X_DEV_INFO("qm_cid_count %d\n", bp->qm_cid_count);
  10596. /* disable FCOE L2 queue for E1x*/
  10597. if (CHIP_IS_E1x(bp))
  10598. bp->flags |= NO_FCOE_FLAG;
  10599. /* Set bp->num_queues for MSI-X mode*/
  10600. bnx2x_set_num_queues(bp);
  10601. /* Configure interrupt mode: try to enable MSI-X/MSI if
  10602. * needed.
  10603. */
  10604. rc = bnx2x_set_int_mode(bp);
  10605. if (rc) {
  10606. dev_err(&pdev->dev, "Cannot set interrupts\n");
  10607. goto init_one_exit;
  10608. }
  10609. BNX2X_DEV_INFO("set interrupts successfully\n");
  10610. /* register the net device */
  10611. rc = register_netdev(dev);
  10612. if (rc) {
  10613. dev_err(&pdev->dev, "Cannot register net device\n");
  10614. goto init_one_exit;
  10615. }
  10616. BNX2X_DEV_INFO("device name after netdev register %s\n", dev->name);
  10617. if (!NO_FCOE(bp)) {
  10618. /* Add storage MAC address */
  10619. rtnl_lock();
  10620. dev_addr_add(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  10621. rtnl_unlock();
  10622. }
  10623. bnx2x_get_pcie_width_speed(bp, &pcie_width, &pcie_speed);
  10624. BNX2X_DEV_INFO("got pcie width %d and speed %d\n",
  10625. pcie_width, pcie_speed);
  10626. BNX2X_DEV_INFO("%s (%c%d) PCI-E x%d %s found at mem %lx, IRQ %d, node addr %pM\n",
  10627. board_info[ent->driver_data].name,
  10628. (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4),
  10629. pcie_width,
  10630. pcie_speed == BNX2X_PCI_LINK_SPEED_2500 ? "2.5GHz" :
  10631. pcie_speed == BNX2X_PCI_LINK_SPEED_5000 ? "5.0GHz" :
  10632. pcie_speed == BNX2X_PCI_LINK_SPEED_8000 ? "8.0GHz" :
  10633. "Unknown",
  10634. dev->base_addr, bp->pdev->irq, dev->dev_addr);
  10635. return 0;
  10636. init_one_exit:
  10637. if (bp->regview)
  10638. iounmap(bp->regview);
  10639. if (IS_PF(bp) && bp->doorbells)
  10640. iounmap(bp->doorbells);
  10641. free_netdev(dev);
  10642. if (atomic_read(&pdev->enable_cnt) == 1)
  10643. pci_release_regions(pdev);
  10644. pci_disable_device(pdev);
  10645. pci_set_drvdata(pdev, NULL);
  10646. return rc;
  10647. }
  10648. static void __bnx2x_remove(struct pci_dev *pdev,
  10649. struct net_device *dev,
  10650. struct bnx2x *bp,
  10651. bool remove_netdev)
  10652. {
  10653. /* Delete storage MAC address */
  10654. if (!NO_FCOE(bp)) {
  10655. rtnl_lock();
  10656. dev_addr_del(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  10657. rtnl_unlock();
  10658. }
  10659. #ifdef BCM_DCBNL
  10660. /* Delete app tlvs from dcbnl */
  10661. bnx2x_dcbnl_update_applist(bp, true);
  10662. #endif
  10663. /* Close the interface - either directly or implicitly */
  10664. if (remove_netdev) {
  10665. unregister_netdev(dev);
  10666. } else {
  10667. rtnl_lock();
  10668. if (netif_running(dev))
  10669. bnx2x_close(dev);
  10670. rtnl_unlock();
  10671. }
  10672. /* Power on: we can't let PCI layer write to us while we are in D3 */
  10673. if (IS_PF(bp))
  10674. bnx2x_set_power_state(bp, PCI_D0);
  10675. /* Disable MSI/MSI-X */
  10676. bnx2x_disable_msi(bp);
  10677. /* Power off */
  10678. if (IS_PF(bp))
  10679. bnx2x_set_power_state(bp, PCI_D3hot);
  10680. /* Make sure RESET task is not scheduled before continuing */
  10681. cancel_delayed_work_sync(&bp->sp_rtnl_task);
  10682. bnx2x_iov_remove_one(bp);
  10683. /* send message via vfpf channel to release the resources of this vf */
  10684. if (IS_VF(bp))
  10685. bnx2x_vfpf_release(bp);
  10686. /* Assumes no further PCIe PM changes will occur */
  10687. if (system_state == SYSTEM_POWER_OFF) {
  10688. pci_wake_from_d3(pdev, bp->wol);
  10689. pci_set_power_state(pdev, PCI_D3hot);
  10690. }
  10691. if (bp->regview)
  10692. iounmap(bp->regview);
  10693. /* for vf doorbells are part of the regview and were unmapped along with
  10694. * it. FW is only loaded by PF.
  10695. */
  10696. if (IS_PF(bp)) {
  10697. if (bp->doorbells)
  10698. iounmap(bp->doorbells);
  10699. bnx2x_release_firmware(bp);
  10700. }
  10701. bnx2x_free_mem_bp(bp);
  10702. if (remove_netdev)
  10703. free_netdev(dev);
  10704. if (atomic_read(&pdev->enable_cnt) == 1)
  10705. pci_release_regions(pdev);
  10706. pci_disable_device(pdev);
  10707. pci_set_drvdata(pdev, NULL);
  10708. }
  10709. static void bnx2x_remove_one(struct pci_dev *pdev)
  10710. {
  10711. struct net_device *dev = pci_get_drvdata(pdev);
  10712. struct bnx2x *bp;
  10713. if (!dev) {
  10714. dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n");
  10715. return;
  10716. }
  10717. bp = netdev_priv(dev);
  10718. __bnx2x_remove(pdev, dev, bp, true);
  10719. }
  10720. static int bnx2x_eeh_nic_unload(struct bnx2x *bp)
  10721. {
  10722. bp->state = BNX2X_STATE_CLOSING_WAIT4_HALT;
  10723. bp->rx_mode = BNX2X_RX_MODE_NONE;
  10724. if (CNIC_LOADED(bp))
  10725. bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD);
  10726. /* Stop Tx */
  10727. bnx2x_tx_disable(bp);
  10728. /* Delete all NAPI objects */
  10729. bnx2x_del_all_napi(bp);
  10730. if (CNIC_LOADED(bp))
  10731. bnx2x_del_all_napi_cnic(bp);
  10732. netdev_reset_tc(bp->dev);
  10733. del_timer_sync(&bp->timer);
  10734. cancel_delayed_work(&bp->sp_task);
  10735. cancel_delayed_work(&bp->period_task);
  10736. spin_lock_bh(&bp->stats_lock);
  10737. bp->stats_state = STATS_STATE_DISABLED;
  10738. spin_unlock_bh(&bp->stats_lock);
  10739. bnx2x_save_statistics(bp);
  10740. netif_carrier_off(bp->dev);
  10741. return 0;
  10742. }
  10743. /**
  10744. * bnx2x_io_error_detected - called when PCI error is detected
  10745. * @pdev: Pointer to PCI device
  10746. * @state: The current pci connection state
  10747. *
  10748. * This function is called after a PCI bus error affecting
  10749. * this device has been detected.
  10750. */
  10751. static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev,
  10752. pci_channel_state_t state)
  10753. {
  10754. struct net_device *dev = pci_get_drvdata(pdev);
  10755. struct bnx2x *bp = netdev_priv(dev);
  10756. rtnl_lock();
  10757. BNX2X_ERR("IO error detected\n");
  10758. netif_device_detach(dev);
  10759. if (state == pci_channel_io_perm_failure) {
  10760. rtnl_unlock();
  10761. return PCI_ERS_RESULT_DISCONNECT;
  10762. }
  10763. if (netif_running(dev))
  10764. bnx2x_eeh_nic_unload(bp);
  10765. bnx2x_prev_path_mark_eeh(bp);
  10766. pci_disable_device(pdev);
  10767. rtnl_unlock();
  10768. /* Request a slot reset */
  10769. return PCI_ERS_RESULT_NEED_RESET;
  10770. }
  10771. /**
  10772. * bnx2x_io_slot_reset - called after the PCI bus has been reset
  10773. * @pdev: Pointer to PCI device
  10774. *
  10775. * Restart the card from scratch, as if from a cold-boot.
  10776. */
  10777. static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev)
  10778. {
  10779. struct net_device *dev = pci_get_drvdata(pdev);
  10780. struct bnx2x *bp = netdev_priv(dev);
  10781. int i;
  10782. rtnl_lock();
  10783. BNX2X_ERR("IO slot reset initializing...\n");
  10784. if (pci_enable_device(pdev)) {
  10785. dev_err(&pdev->dev,
  10786. "Cannot re-enable PCI device after reset\n");
  10787. rtnl_unlock();
  10788. return PCI_ERS_RESULT_DISCONNECT;
  10789. }
  10790. pci_set_master(pdev);
  10791. pci_restore_state(pdev);
  10792. pci_save_state(pdev);
  10793. if (netif_running(dev))
  10794. bnx2x_set_power_state(bp, PCI_D0);
  10795. if (netif_running(dev)) {
  10796. BNX2X_ERR("IO slot reset --> driver unload\n");
  10797. /* MCP should have been reset; Need to wait for validity */
  10798. bnx2x_init_shmem(bp);
  10799. if (IS_PF(bp) && SHMEM2_HAS(bp, drv_capabilities_flag)) {
  10800. u32 v;
  10801. v = SHMEM2_RD(bp,
  10802. drv_capabilities_flag[BP_FW_MB_IDX(bp)]);
  10803. SHMEM2_WR(bp, drv_capabilities_flag[BP_FW_MB_IDX(bp)],
  10804. v & ~DRV_FLAGS_CAPABILITIES_LOADED_L2);
  10805. }
  10806. bnx2x_drain_tx_queues(bp);
  10807. bnx2x_send_unload_req(bp, UNLOAD_RECOVERY);
  10808. bnx2x_netif_stop(bp, 1);
  10809. bnx2x_free_irq(bp);
  10810. /* Report UNLOAD_DONE to MCP */
  10811. bnx2x_send_unload_done(bp, true);
  10812. bp->sp_state = 0;
  10813. bp->port.pmf = 0;
  10814. bnx2x_prev_unload(bp);
  10815. /* We should have resetted the engine, so It's fair to
  10816. * assume the FW will no longer write to the bnx2x driver.
  10817. */
  10818. bnx2x_squeeze_objects(bp);
  10819. bnx2x_free_skbs(bp);
  10820. for_each_rx_queue(bp, i)
  10821. bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
  10822. bnx2x_free_fp_mem(bp);
  10823. bnx2x_free_mem(bp);
  10824. bp->state = BNX2X_STATE_CLOSED;
  10825. }
  10826. rtnl_unlock();
  10827. return PCI_ERS_RESULT_RECOVERED;
  10828. }
  10829. /**
  10830. * bnx2x_io_resume - called when traffic can start flowing again
  10831. * @pdev: Pointer to PCI device
  10832. *
  10833. * This callback is called when the error recovery driver tells us that
  10834. * its OK to resume normal operation.
  10835. */
  10836. static void bnx2x_io_resume(struct pci_dev *pdev)
  10837. {
  10838. struct net_device *dev = pci_get_drvdata(pdev);
  10839. struct bnx2x *bp = netdev_priv(dev);
  10840. if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
  10841. netdev_err(bp->dev, "Handling parity error recovery. Try again later\n");
  10842. return;
  10843. }
  10844. rtnl_lock();
  10845. bp->fw_seq = SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
  10846. DRV_MSG_SEQ_NUMBER_MASK;
  10847. if (netif_running(dev))
  10848. bnx2x_nic_load(bp, LOAD_NORMAL);
  10849. netif_device_attach(dev);
  10850. rtnl_unlock();
  10851. }
  10852. static const struct pci_error_handlers bnx2x_err_handler = {
  10853. .error_detected = bnx2x_io_error_detected,
  10854. .slot_reset = bnx2x_io_slot_reset,
  10855. .resume = bnx2x_io_resume,
  10856. };
  10857. static void bnx2x_shutdown(struct pci_dev *pdev)
  10858. {
  10859. struct net_device *dev = pci_get_drvdata(pdev);
  10860. struct bnx2x *bp;
  10861. if (!dev)
  10862. return;
  10863. bp = netdev_priv(dev);
  10864. if (!bp)
  10865. return;
  10866. rtnl_lock();
  10867. netif_device_detach(dev);
  10868. rtnl_unlock();
  10869. /* Don't remove the netdevice, as there are scenarios which will cause
  10870. * the kernel to hang, e.g., when trying to remove bnx2i while the
  10871. * rootfs is mounted from SAN.
  10872. */
  10873. __bnx2x_remove(pdev, dev, bp, false);
  10874. }
  10875. static struct pci_driver bnx2x_pci_driver = {
  10876. .name = DRV_MODULE_NAME,
  10877. .id_table = bnx2x_pci_tbl,
  10878. .probe = bnx2x_init_one,
  10879. .remove = bnx2x_remove_one,
  10880. .suspend = bnx2x_suspend,
  10881. .resume = bnx2x_resume,
  10882. .err_handler = &bnx2x_err_handler,
  10883. #ifdef CONFIG_BNX2X_SRIOV
  10884. .sriov_configure = bnx2x_sriov_configure,
  10885. #endif
  10886. .shutdown = bnx2x_shutdown,
  10887. };
  10888. static int __init bnx2x_init(void)
  10889. {
  10890. int ret;
  10891. pr_info("%s", version);
  10892. bnx2x_wq = create_singlethread_workqueue("bnx2x");
  10893. if (bnx2x_wq == NULL) {
  10894. pr_err("Cannot create workqueue\n");
  10895. return -ENOMEM;
  10896. }
  10897. ret = pci_register_driver(&bnx2x_pci_driver);
  10898. if (ret) {
  10899. pr_err("Cannot register driver\n");
  10900. destroy_workqueue(bnx2x_wq);
  10901. }
  10902. return ret;
  10903. }
  10904. static void __exit bnx2x_cleanup(void)
  10905. {
  10906. struct list_head *pos, *q;
  10907. pci_unregister_driver(&bnx2x_pci_driver);
  10908. destroy_workqueue(bnx2x_wq);
  10909. /* Free globablly allocated resources */
  10910. list_for_each_safe(pos, q, &bnx2x_prev_list) {
  10911. struct bnx2x_prev_path_list *tmp =
  10912. list_entry(pos, struct bnx2x_prev_path_list, list);
  10913. list_del(pos);
  10914. kfree(tmp);
  10915. }
  10916. }
  10917. void bnx2x_notify_link_changed(struct bnx2x *bp)
  10918. {
  10919. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + BP_FUNC(bp)*sizeof(u32), 1);
  10920. }
  10921. module_init(bnx2x_init);
  10922. module_exit(bnx2x_cleanup);
  10923. /**
  10924. * bnx2x_set_iscsi_eth_mac_addr - set iSCSI MAC(s).
  10925. *
  10926. * @bp: driver handle
  10927. * @set: set or clear the CAM entry
  10928. *
  10929. * This function will wait until the ramdord completion returns.
  10930. * Return 0 if success, -ENODEV if ramrod doesn't return.
  10931. */
  10932. static int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp)
  10933. {
  10934. unsigned long ramrod_flags = 0;
  10935. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  10936. return bnx2x_set_mac_one(bp, bp->cnic_eth_dev.iscsi_mac,
  10937. &bp->iscsi_l2_mac_obj, true,
  10938. BNX2X_ISCSI_ETH_MAC, &ramrod_flags);
  10939. }
  10940. /* count denotes the number of new completions we have seen */
  10941. static void bnx2x_cnic_sp_post(struct bnx2x *bp, int count)
  10942. {
  10943. struct eth_spe *spe;
  10944. int cxt_index, cxt_offset;
  10945. #ifdef BNX2X_STOP_ON_ERROR
  10946. if (unlikely(bp->panic))
  10947. return;
  10948. #endif
  10949. spin_lock_bh(&bp->spq_lock);
  10950. BUG_ON(bp->cnic_spq_pending < count);
  10951. bp->cnic_spq_pending -= count;
  10952. for (; bp->cnic_kwq_pending; bp->cnic_kwq_pending--) {
  10953. u16 type = (le16_to_cpu(bp->cnic_kwq_cons->hdr.type)
  10954. & SPE_HDR_CONN_TYPE) >>
  10955. SPE_HDR_CONN_TYPE_SHIFT;
  10956. u8 cmd = (le32_to_cpu(bp->cnic_kwq_cons->hdr.conn_and_cmd_data)
  10957. >> SPE_HDR_CMD_ID_SHIFT) & 0xff;
  10958. /* Set validation for iSCSI L2 client before sending SETUP
  10959. * ramrod
  10960. */
  10961. if (type == ETH_CONNECTION_TYPE) {
  10962. if (cmd == RAMROD_CMD_ID_ETH_CLIENT_SETUP) {
  10963. cxt_index = BNX2X_ISCSI_ETH_CID(bp) /
  10964. ILT_PAGE_CIDS;
  10965. cxt_offset = BNX2X_ISCSI_ETH_CID(bp) -
  10966. (cxt_index * ILT_PAGE_CIDS);
  10967. bnx2x_set_ctx_validation(bp,
  10968. &bp->context[cxt_index].
  10969. vcxt[cxt_offset].eth,
  10970. BNX2X_ISCSI_ETH_CID(bp));
  10971. }
  10972. }
  10973. /*
  10974. * There may be not more than 8 L2, not more than 8 L5 SPEs
  10975. * and in the air. We also check that number of outstanding
  10976. * COMMON ramrods is not more than the EQ and SPQ can
  10977. * accommodate.
  10978. */
  10979. if (type == ETH_CONNECTION_TYPE) {
  10980. if (!atomic_read(&bp->cq_spq_left))
  10981. break;
  10982. else
  10983. atomic_dec(&bp->cq_spq_left);
  10984. } else if (type == NONE_CONNECTION_TYPE) {
  10985. if (!atomic_read(&bp->eq_spq_left))
  10986. break;
  10987. else
  10988. atomic_dec(&bp->eq_spq_left);
  10989. } else if ((type == ISCSI_CONNECTION_TYPE) ||
  10990. (type == FCOE_CONNECTION_TYPE)) {
  10991. if (bp->cnic_spq_pending >=
  10992. bp->cnic_eth_dev.max_kwqe_pending)
  10993. break;
  10994. else
  10995. bp->cnic_spq_pending++;
  10996. } else {
  10997. BNX2X_ERR("Unknown SPE type: %d\n", type);
  10998. bnx2x_panic();
  10999. break;
  11000. }
  11001. spe = bnx2x_sp_get_next(bp);
  11002. *spe = *bp->cnic_kwq_cons;
  11003. DP(BNX2X_MSG_SP, "pending on SPQ %d, on KWQ %d count %d\n",
  11004. bp->cnic_spq_pending, bp->cnic_kwq_pending, count);
  11005. if (bp->cnic_kwq_cons == bp->cnic_kwq_last)
  11006. bp->cnic_kwq_cons = bp->cnic_kwq;
  11007. else
  11008. bp->cnic_kwq_cons++;
  11009. }
  11010. bnx2x_sp_prod_update(bp);
  11011. spin_unlock_bh(&bp->spq_lock);
  11012. }
  11013. static int bnx2x_cnic_sp_queue(struct net_device *dev,
  11014. struct kwqe_16 *kwqes[], u32 count)
  11015. {
  11016. struct bnx2x *bp = netdev_priv(dev);
  11017. int i;
  11018. #ifdef BNX2X_STOP_ON_ERROR
  11019. if (unlikely(bp->panic)) {
  11020. BNX2X_ERR("Can't post to SP queue while panic\n");
  11021. return -EIO;
  11022. }
  11023. #endif
  11024. if ((bp->recovery_state != BNX2X_RECOVERY_DONE) &&
  11025. (bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  11026. BNX2X_ERR("Handling parity error recovery. Try again later\n");
  11027. return -EAGAIN;
  11028. }
  11029. spin_lock_bh(&bp->spq_lock);
  11030. for (i = 0; i < count; i++) {
  11031. struct eth_spe *spe = (struct eth_spe *)kwqes[i];
  11032. if (bp->cnic_kwq_pending == MAX_SP_DESC_CNT)
  11033. break;
  11034. *bp->cnic_kwq_prod = *spe;
  11035. bp->cnic_kwq_pending++;
  11036. DP(BNX2X_MSG_SP, "L5 SPQE %x %x %x:%x pos %d\n",
  11037. spe->hdr.conn_and_cmd_data, spe->hdr.type,
  11038. spe->data.update_data_addr.hi,
  11039. spe->data.update_data_addr.lo,
  11040. bp->cnic_kwq_pending);
  11041. if (bp->cnic_kwq_prod == bp->cnic_kwq_last)
  11042. bp->cnic_kwq_prod = bp->cnic_kwq;
  11043. else
  11044. bp->cnic_kwq_prod++;
  11045. }
  11046. spin_unlock_bh(&bp->spq_lock);
  11047. if (bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending)
  11048. bnx2x_cnic_sp_post(bp, 0);
  11049. return i;
  11050. }
  11051. static int bnx2x_cnic_ctl_send(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  11052. {
  11053. struct cnic_ops *c_ops;
  11054. int rc = 0;
  11055. mutex_lock(&bp->cnic_mutex);
  11056. c_ops = rcu_dereference_protected(bp->cnic_ops,
  11057. lockdep_is_held(&bp->cnic_mutex));
  11058. if (c_ops)
  11059. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  11060. mutex_unlock(&bp->cnic_mutex);
  11061. return rc;
  11062. }
  11063. static int bnx2x_cnic_ctl_send_bh(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  11064. {
  11065. struct cnic_ops *c_ops;
  11066. int rc = 0;
  11067. rcu_read_lock();
  11068. c_ops = rcu_dereference(bp->cnic_ops);
  11069. if (c_ops)
  11070. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  11071. rcu_read_unlock();
  11072. return rc;
  11073. }
  11074. /*
  11075. * for commands that have no data
  11076. */
  11077. int bnx2x_cnic_notify(struct bnx2x *bp, int cmd)
  11078. {
  11079. struct cnic_ctl_info ctl = {0};
  11080. ctl.cmd = cmd;
  11081. return bnx2x_cnic_ctl_send(bp, &ctl);
  11082. }
  11083. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err)
  11084. {
  11085. struct cnic_ctl_info ctl = {0};
  11086. /* first we tell CNIC and only then we count this as a completion */
  11087. ctl.cmd = CNIC_CTL_COMPLETION_CMD;
  11088. ctl.data.comp.cid = cid;
  11089. ctl.data.comp.error = err;
  11090. bnx2x_cnic_ctl_send_bh(bp, &ctl);
  11091. bnx2x_cnic_sp_post(bp, 0);
  11092. }
  11093. /* Called with netif_addr_lock_bh() taken.
  11094. * Sets an rx_mode config for an iSCSI ETH client.
  11095. * Doesn't block.
  11096. * Completion should be checked outside.
  11097. */
  11098. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start)
  11099. {
  11100. unsigned long accept_flags = 0, ramrod_flags = 0;
  11101. u8 cl_id = bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  11102. int sched_state = BNX2X_FILTER_ISCSI_ETH_STOP_SCHED;
  11103. if (start) {
  11104. /* Start accepting on iSCSI L2 ring. Accept all multicasts
  11105. * because it's the only way for UIO Queue to accept
  11106. * multicasts (in non-promiscuous mode only one Queue per
  11107. * function will receive multicast packets (leading in our
  11108. * case).
  11109. */
  11110. __set_bit(BNX2X_ACCEPT_UNICAST, &accept_flags);
  11111. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept_flags);
  11112. __set_bit(BNX2X_ACCEPT_BROADCAST, &accept_flags);
  11113. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags);
  11114. /* Clear STOP_PENDING bit if START is requested */
  11115. clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &bp->sp_state);
  11116. sched_state = BNX2X_FILTER_ISCSI_ETH_START_SCHED;
  11117. } else
  11118. /* Clear START_PENDING bit if STOP is requested */
  11119. clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &bp->sp_state);
  11120. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  11121. set_bit(sched_state, &bp->sp_state);
  11122. else {
  11123. __set_bit(RAMROD_RX, &ramrod_flags);
  11124. bnx2x_set_q_rx_mode(bp, cl_id, 0, accept_flags, 0,
  11125. ramrod_flags);
  11126. }
  11127. }
  11128. static int bnx2x_drv_ctl(struct net_device *dev, struct drv_ctl_info *ctl)
  11129. {
  11130. struct bnx2x *bp = netdev_priv(dev);
  11131. int rc = 0;
  11132. switch (ctl->cmd) {
  11133. case DRV_CTL_CTXTBL_WR_CMD: {
  11134. u32 index = ctl->data.io.offset;
  11135. dma_addr_t addr = ctl->data.io.dma_addr;
  11136. bnx2x_ilt_wr(bp, index, addr);
  11137. break;
  11138. }
  11139. case DRV_CTL_RET_L5_SPQ_CREDIT_CMD: {
  11140. int count = ctl->data.credit.credit_count;
  11141. bnx2x_cnic_sp_post(bp, count);
  11142. break;
  11143. }
  11144. /* rtnl_lock is held. */
  11145. case DRV_CTL_START_L2_CMD: {
  11146. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11147. unsigned long sp_bits = 0;
  11148. /* Configure the iSCSI classification object */
  11149. bnx2x_init_mac_obj(bp, &bp->iscsi_l2_mac_obj,
  11150. cp->iscsi_l2_client_id,
  11151. cp->iscsi_l2_cid, BP_FUNC(bp),
  11152. bnx2x_sp(bp, mac_rdata),
  11153. bnx2x_sp_mapping(bp, mac_rdata),
  11154. BNX2X_FILTER_MAC_PENDING,
  11155. &bp->sp_state, BNX2X_OBJ_TYPE_RX,
  11156. &bp->macs_pool);
  11157. /* Set iSCSI MAC address */
  11158. rc = bnx2x_set_iscsi_eth_mac_addr(bp);
  11159. if (rc)
  11160. break;
  11161. mmiowb();
  11162. barrier();
  11163. /* Start accepting on iSCSI L2 ring */
  11164. netif_addr_lock_bh(dev);
  11165. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  11166. netif_addr_unlock_bh(dev);
  11167. /* bits to wait on */
  11168. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  11169. __set_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &sp_bits);
  11170. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  11171. BNX2X_ERR("rx_mode completion timed out!\n");
  11172. break;
  11173. }
  11174. /* rtnl_lock is held. */
  11175. case DRV_CTL_STOP_L2_CMD: {
  11176. unsigned long sp_bits = 0;
  11177. /* Stop accepting on iSCSI L2 ring */
  11178. netif_addr_lock_bh(dev);
  11179. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  11180. netif_addr_unlock_bh(dev);
  11181. /* bits to wait on */
  11182. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  11183. __set_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &sp_bits);
  11184. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  11185. BNX2X_ERR("rx_mode completion timed out!\n");
  11186. mmiowb();
  11187. barrier();
  11188. /* Unset iSCSI L2 MAC */
  11189. rc = bnx2x_del_all_macs(bp, &bp->iscsi_l2_mac_obj,
  11190. BNX2X_ISCSI_ETH_MAC, true);
  11191. break;
  11192. }
  11193. case DRV_CTL_RET_L2_SPQ_CREDIT_CMD: {
  11194. int count = ctl->data.credit.credit_count;
  11195. smp_mb__before_atomic_inc();
  11196. atomic_add(count, &bp->cq_spq_left);
  11197. smp_mb__after_atomic_inc();
  11198. break;
  11199. }
  11200. case DRV_CTL_ULP_REGISTER_CMD: {
  11201. int ulp_type = ctl->data.register_data.ulp_type;
  11202. if (CHIP_IS_E3(bp)) {
  11203. int idx = BP_FW_MB_IDX(bp);
  11204. u32 cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  11205. int path = BP_PATH(bp);
  11206. int port = BP_PORT(bp);
  11207. int i;
  11208. u32 scratch_offset;
  11209. u32 *host_addr;
  11210. /* first write capability to shmem2 */
  11211. if (ulp_type == CNIC_ULP_ISCSI)
  11212. cap |= DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  11213. else if (ulp_type == CNIC_ULP_FCOE)
  11214. cap |= DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  11215. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  11216. if ((ulp_type != CNIC_ULP_FCOE) ||
  11217. (!SHMEM2_HAS(bp, ncsi_oem_data_addr)) ||
  11218. (!(bp->flags & BC_SUPPORTS_FCOE_FEATURES)))
  11219. break;
  11220. /* if reached here - should write fcoe capabilities */
  11221. scratch_offset = SHMEM2_RD(bp, ncsi_oem_data_addr);
  11222. if (!scratch_offset)
  11223. break;
  11224. scratch_offset += offsetof(struct glob_ncsi_oem_data,
  11225. fcoe_features[path][port]);
  11226. host_addr = (u32 *) &(ctl->data.register_data.
  11227. fcoe_features);
  11228. for (i = 0; i < sizeof(struct fcoe_capabilities);
  11229. i += 4)
  11230. REG_WR(bp, scratch_offset + i,
  11231. *(host_addr + i/4));
  11232. }
  11233. break;
  11234. }
  11235. case DRV_CTL_ULP_UNREGISTER_CMD: {
  11236. int ulp_type = ctl->data.ulp_type;
  11237. if (CHIP_IS_E3(bp)) {
  11238. int idx = BP_FW_MB_IDX(bp);
  11239. u32 cap;
  11240. cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  11241. if (ulp_type == CNIC_ULP_ISCSI)
  11242. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  11243. else if (ulp_type == CNIC_ULP_FCOE)
  11244. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  11245. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  11246. }
  11247. break;
  11248. }
  11249. default:
  11250. BNX2X_ERR("unknown command %x\n", ctl->cmd);
  11251. rc = -EINVAL;
  11252. }
  11253. return rc;
  11254. }
  11255. void bnx2x_setup_cnic_irq_info(struct bnx2x *bp)
  11256. {
  11257. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11258. if (bp->flags & USING_MSIX_FLAG) {
  11259. cp->drv_state |= CNIC_DRV_STATE_USING_MSIX;
  11260. cp->irq_arr[0].irq_flags |= CNIC_IRQ_FL_MSIX;
  11261. cp->irq_arr[0].vector = bp->msix_table[1].vector;
  11262. } else {
  11263. cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX;
  11264. cp->irq_arr[0].irq_flags &= ~CNIC_IRQ_FL_MSIX;
  11265. }
  11266. if (!CHIP_IS_E1x(bp))
  11267. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e2_sb;
  11268. else
  11269. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e1x_sb;
  11270. cp->irq_arr[0].status_blk_num = bnx2x_cnic_fw_sb_id(bp);
  11271. cp->irq_arr[0].status_blk_num2 = bnx2x_cnic_igu_sb_id(bp);
  11272. cp->irq_arr[1].status_blk = bp->def_status_blk;
  11273. cp->irq_arr[1].status_blk_num = DEF_SB_ID;
  11274. cp->irq_arr[1].status_blk_num2 = DEF_SB_IGU_ID;
  11275. cp->num_irq = 2;
  11276. }
  11277. void bnx2x_setup_cnic_info(struct bnx2x *bp)
  11278. {
  11279. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11280. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  11281. bnx2x_cid_ilt_lines(bp);
  11282. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  11283. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
  11284. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
  11285. if (NO_ISCSI_OOO(bp))
  11286. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  11287. }
  11288. static int bnx2x_register_cnic(struct net_device *dev, struct cnic_ops *ops,
  11289. void *data)
  11290. {
  11291. struct bnx2x *bp = netdev_priv(dev);
  11292. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11293. int rc;
  11294. DP(NETIF_MSG_IFUP, "Register_cnic called\n");
  11295. if (ops == NULL) {
  11296. BNX2X_ERR("NULL ops received\n");
  11297. return -EINVAL;
  11298. }
  11299. if (!CNIC_SUPPORT(bp)) {
  11300. BNX2X_ERR("Can't register CNIC when not supported\n");
  11301. return -EOPNOTSUPP;
  11302. }
  11303. if (!CNIC_LOADED(bp)) {
  11304. rc = bnx2x_load_cnic(bp);
  11305. if (rc) {
  11306. BNX2X_ERR("CNIC-related load failed\n");
  11307. return rc;
  11308. }
  11309. }
  11310. bp->cnic_enabled = true;
  11311. bp->cnic_kwq = kzalloc(PAGE_SIZE, GFP_KERNEL);
  11312. if (!bp->cnic_kwq)
  11313. return -ENOMEM;
  11314. bp->cnic_kwq_cons = bp->cnic_kwq;
  11315. bp->cnic_kwq_prod = bp->cnic_kwq;
  11316. bp->cnic_kwq_last = bp->cnic_kwq + MAX_SP_DESC_CNT;
  11317. bp->cnic_spq_pending = 0;
  11318. bp->cnic_kwq_pending = 0;
  11319. bp->cnic_data = data;
  11320. cp->num_irq = 0;
  11321. cp->drv_state |= CNIC_DRV_STATE_REGD;
  11322. cp->iro_arr = bp->iro_arr;
  11323. bnx2x_setup_cnic_irq_info(bp);
  11324. rcu_assign_pointer(bp->cnic_ops, ops);
  11325. return 0;
  11326. }
  11327. static int bnx2x_unregister_cnic(struct net_device *dev)
  11328. {
  11329. struct bnx2x *bp = netdev_priv(dev);
  11330. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11331. mutex_lock(&bp->cnic_mutex);
  11332. cp->drv_state = 0;
  11333. RCU_INIT_POINTER(bp->cnic_ops, NULL);
  11334. mutex_unlock(&bp->cnic_mutex);
  11335. synchronize_rcu();
  11336. bp->cnic_enabled = false;
  11337. kfree(bp->cnic_kwq);
  11338. bp->cnic_kwq = NULL;
  11339. return 0;
  11340. }
  11341. struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev)
  11342. {
  11343. struct bnx2x *bp = netdev_priv(dev);
  11344. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11345. /* If both iSCSI and FCoE are disabled - return NULL in
  11346. * order to indicate CNIC that it should not try to work
  11347. * with this device.
  11348. */
  11349. if (NO_ISCSI(bp) && NO_FCOE(bp))
  11350. return NULL;
  11351. cp->drv_owner = THIS_MODULE;
  11352. cp->chip_id = CHIP_ID(bp);
  11353. cp->pdev = bp->pdev;
  11354. cp->io_base = bp->regview;
  11355. cp->io_base2 = bp->doorbells;
  11356. cp->max_kwqe_pending = 8;
  11357. cp->ctx_blk_size = CDU_ILT_PAGE_SZ;
  11358. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  11359. bnx2x_cid_ilt_lines(bp);
  11360. cp->ctx_tbl_len = CNIC_ILT_LINES;
  11361. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  11362. cp->drv_submit_kwqes_16 = bnx2x_cnic_sp_queue;
  11363. cp->drv_ctl = bnx2x_drv_ctl;
  11364. cp->drv_register_cnic = bnx2x_register_cnic;
  11365. cp->drv_unregister_cnic = bnx2x_unregister_cnic;
  11366. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
  11367. cp->iscsi_l2_client_id =
  11368. bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  11369. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
  11370. if (NO_ISCSI_OOO(bp))
  11371. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  11372. if (NO_ISCSI(bp))
  11373. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI;
  11374. if (NO_FCOE(bp))
  11375. cp->drv_state |= CNIC_DRV_STATE_NO_FCOE;
  11376. BNX2X_DEV_INFO(
  11377. "page_size %d, tbl_offset %d, tbl_lines %d, starting cid %d\n",
  11378. cp->ctx_blk_size,
  11379. cp->ctx_tbl_offset,
  11380. cp->ctx_tbl_len,
  11381. cp->starting_cid);
  11382. return cp;
  11383. }
  11384. u32 bnx2x_rx_ustorm_prods_offset(struct bnx2x_fastpath *fp)
  11385. {
  11386. struct bnx2x *bp = fp->bp;
  11387. u32 offset = BAR_USTRORM_INTMEM;
  11388. if (IS_VF(bp))
  11389. return bnx2x_vf_ustorm_prods_offset(bp, fp);
  11390. else if (!CHIP_IS_E1x(bp))
  11391. offset += USTORM_RX_PRODS_E2_OFFSET(fp->cl_qzone_id);
  11392. else
  11393. offset += USTORM_RX_PRODS_E1X_OFFSET(BP_PORT(bp), fp->cl_id);
  11394. return offset;
  11395. }
  11396. /* called only on E1H or E2.
  11397. * When pretending to be PF, the pretend value is the function number 0...7
  11398. * When pretending to be VF, the pretend val is the PF-num:VF-valid:ABS-VFID
  11399. * combination
  11400. */
  11401. int bnx2x_pretend_func(struct bnx2x *bp, u16 pretend_func_val)
  11402. {
  11403. u32 pretend_reg;
  11404. if (CHIP_IS_E1H(bp) && pretend_func_val >= E1H_FUNC_MAX)
  11405. return -1;
  11406. /* get my own pretend register */
  11407. pretend_reg = bnx2x_get_pretend_reg(bp);
  11408. REG_WR(bp, pretend_reg, pretend_func_val);
  11409. REG_RD(bp, pretend_reg);
  11410. return 0;
  11411. }