bnx2x_main.c 363 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435
  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. #define MAC_LEADING_ZERO_CNT (ALIGN(ETH_ALEN, sizeof(u32)) - ETH_ALEN)
  74. /* Time in jiffies before concluding the transmitter is hung */
  75. #define TX_TIMEOUT (5*HZ)
  76. static char version[] =
  77. "Broadcom NetXtreme II 5771x/578xx 10/20-Gigabit Ethernet Driver "
  78. DRV_MODULE_NAME " " DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
  79. MODULE_AUTHOR("Eliezer Tamir");
  80. MODULE_DESCRIPTION("Broadcom NetXtreme II "
  81. "BCM57710/57711/57711E/"
  82. "57712/57712_MF/57800/57800_MF/57810/57810_MF/"
  83. "57840/57840_MF Driver");
  84. MODULE_LICENSE("GPL");
  85. MODULE_VERSION(DRV_MODULE_VERSION);
  86. MODULE_FIRMWARE(FW_FILE_NAME_E1);
  87. MODULE_FIRMWARE(FW_FILE_NAME_E1H);
  88. MODULE_FIRMWARE(FW_FILE_NAME_E2);
  89. int num_queues;
  90. module_param(num_queues, int, 0);
  91. MODULE_PARM_DESC(num_queues,
  92. " Set number of queues (default is as a number of CPUs)");
  93. static int disable_tpa;
  94. module_param(disable_tpa, int, 0);
  95. MODULE_PARM_DESC(disable_tpa, " Disable the TPA (LRO) feature");
  96. #define INT_MODE_INTx 1
  97. #define INT_MODE_MSI 2
  98. int int_mode;
  99. module_param(int_mode, int, 0);
  100. MODULE_PARM_DESC(int_mode, " Force interrupt mode other than MSI-X "
  101. "(1 INT#x; 2 MSI)");
  102. static int dropless_fc;
  103. module_param(dropless_fc, int, 0);
  104. MODULE_PARM_DESC(dropless_fc, " Pause on exhausted host ring");
  105. static int mrrs = -1;
  106. module_param(mrrs, int, 0);
  107. MODULE_PARM_DESC(mrrs, " Force Max Read Req Size (0..3) (for debug)");
  108. static int debug;
  109. module_param(debug, int, 0);
  110. MODULE_PARM_DESC(debug, " Default debug msglevel");
  111. struct workqueue_struct *bnx2x_wq;
  112. struct bnx2x_mac_vals {
  113. u32 xmac_addr;
  114. u32 xmac_val;
  115. u32 emac_addr;
  116. u32 emac_val;
  117. u32 umac_addr;
  118. u32 umac_val;
  119. u32 bmac_addr;
  120. u32 bmac_val[2];
  121. };
  122. enum bnx2x_board_type {
  123. BCM57710 = 0,
  124. BCM57711,
  125. BCM57711E,
  126. BCM57712,
  127. BCM57712_MF,
  128. BCM57712_VF,
  129. BCM57800,
  130. BCM57800_MF,
  131. BCM57800_VF,
  132. BCM57810,
  133. BCM57810_MF,
  134. BCM57810_VF,
  135. BCM57840_4_10,
  136. BCM57840_2_20,
  137. BCM57840_MF,
  138. BCM57840_VF,
  139. BCM57811,
  140. BCM57811_MF,
  141. BCM57840_O,
  142. BCM57840_MFO,
  143. BCM57811_VF
  144. };
  145. /* indexed by board_type, above */
  146. static struct {
  147. char *name;
  148. } board_info[] = {
  149. [BCM57710] = { "Broadcom NetXtreme II BCM57710 10 Gigabit PCIe [Everest]" },
  150. [BCM57711] = { "Broadcom NetXtreme II BCM57711 10 Gigabit PCIe" },
  151. [BCM57711E] = { "Broadcom NetXtreme II BCM57711E 10 Gigabit PCIe" },
  152. [BCM57712] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet" },
  153. [BCM57712_MF] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Multi Function" },
  154. [BCM57712_VF] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Virtual Function" },
  155. [BCM57800] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet" },
  156. [BCM57800_MF] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Multi Function" },
  157. [BCM57800_VF] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Virtual Function" },
  158. [BCM57810] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet" },
  159. [BCM57810_MF] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Multi Function" },
  160. [BCM57810_VF] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Virtual Function" },
  161. [BCM57840_4_10] = { "Broadcom NetXtreme II BCM57840 10 Gigabit Ethernet" },
  162. [BCM57840_2_20] = { "Broadcom NetXtreme II BCM57840 20 Gigabit Ethernet" },
  163. [BCM57840_MF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function" },
  164. [BCM57840_VF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Virtual Function" },
  165. [BCM57811] = { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet" },
  166. [BCM57811_MF] = { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet Multi Function" },
  167. [BCM57840_O] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet" },
  168. [BCM57840_MFO] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function" },
  169. [BCM57811_VF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Virtual Function" }
  170. };
  171. #ifndef PCI_DEVICE_ID_NX2_57710
  172. #define PCI_DEVICE_ID_NX2_57710 CHIP_NUM_57710
  173. #endif
  174. #ifndef PCI_DEVICE_ID_NX2_57711
  175. #define PCI_DEVICE_ID_NX2_57711 CHIP_NUM_57711
  176. #endif
  177. #ifndef PCI_DEVICE_ID_NX2_57711E
  178. #define PCI_DEVICE_ID_NX2_57711E CHIP_NUM_57711E
  179. #endif
  180. #ifndef PCI_DEVICE_ID_NX2_57712
  181. #define PCI_DEVICE_ID_NX2_57712 CHIP_NUM_57712
  182. #endif
  183. #ifndef PCI_DEVICE_ID_NX2_57712_MF
  184. #define PCI_DEVICE_ID_NX2_57712_MF CHIP_NUM_57712_MF
  185. #endif
  186. #ifndef PCI_DEVICE_ID_NX2_57712_VF
  187. #define PCI_DEVICE_ID_NX2_57712_VF CHIP_NUM_57712_VF
  188. #endif
  189. #ifndef PCI_DEVICE_ID_NX2_57800
  190. #define PCI_DEVICE_ID_NX2_57800 CHIP_NUM_57800
  191. #endif
  192. #ifndef PCI_DEVICE_ID_NX2_57800_MF
  193. #define PCI_DEVICE_ID_NX2_57800_MF CHIP_NUM_57800_MF
  194. #endif
  195. #ifndef PCI_DEVICE_ID_NX2_57800_VF
  196. #define PCI_DEVICE_ID_NX2_57800_VF CHIP_NUM_57800_VF
  197. #endif
  198. #ifndef PCI_DEVICE_ID_NX2_57810
  199. #define PCI_DEVICE_ID_NX2_57810 CHIP_NUM_57810
  200. #endif
  201. #ifndef PCI_DEVICE_ID_NX2_57810_MF
  202. #define PCI_DEVICE_ID_NX2_57810_MF CHIP_NUM_57810_MF
  203. #endif
  204. #ifndef PCI_DEVICE_ID_NX2_57840_O
  205. #define PCI_DEVICE_ID_NX2_57840_O CHIP_NUM_57840_OBSOLETE
  206. #endif
  207. #ifndef PCI_DEVICE_ID_NX2_57810_VF
  208. #define PCI_DEVICE_ID_NX2_57810_VF CHIP_NUM_57810_VF
  209. #endif
  210. #ifndef PCI_DEVICE_ID_NX2_57840_4_10
  211. #define PCI_DEVICE_ID_NX2_57840_4_10 CHIP_NUM_57840_4_10
  212. #endif
  213. #ifndef PCI_DEVICE_ID_NX2_57840_2_20
  214. #define PCI_DEVICE_ID_NX2_57840_2_20 CHIP_NUM_57840_2_20
  215. #endif
  216. #ifndef PCI_DEVICE_ID_NX2_57840_MFO
  217. #define PCI_DEVICE_ID_NX2_57840_MFO CHIP_NUM_57840_MF_OBSOLETE
  218. #endif
  219. #ifndef PCI_DEVICE_ID_NX2_57840_MF
  220. #define PCI_DEVICE_ID_NX2_57840_MF CHIP_NUM_57840_MF
  221. #endif
  222. #ifndef PCI_DEVICE_ID_NX2_57840_VF
  223. #define PCI_DEVICE_ID_NX2_57840_VF CHIP_NUM_57840_VF
  224. #endif
  225. #ifndef PCI_DEVICE_ID_NX2_57811
  226. #define PCI_DEVICE_ID_NX2_57811 CHIP_NUM_57811
  227. #endif
  228. #ifndef PCI_DEVICE_ID_NX2_57811_MF
  229. #define PCI_DEVICE_ID_NX2_57811_MF CHIP_NUM_57811_MF
  230. #endif
  231. #ifndef PCI_DEVICE_ID_NX2_57811_VF
  232. #define PCI_DEVICE_ID_NX2_57811_VF CHIP_NUM_57811_VF
  233. #endif
  234. static DEFINE_PCI_DEVICE_TABLE(bnx2x_pci_tbl) = {
  235. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57710), BCM57710 },
  236. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711), BCM57711 },
  237. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711E), BCM57711E },
  238. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712), BCM57712 },
  239. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_MF), BCM57712_MF },
  240. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_VF), BCM57712_VF },
  241. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800), BCM57800 },
  242. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_MF), BCM57800_MF },
  243. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_VF), BCM57800_VF },
  244. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810), BCM57810 },
  245. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_MF), BCM57810_MF },
  246. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_O), BCM57840_O },
  247. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_4_10), BCM57840_4_10 },
  248. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_2_20), BCM57840_2_20 },
  249. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_VF), BCM57810_VF },
  250. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MFO), BCM57840_MFO },
  251. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MF), BCM57840_MF },
  252. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_VF), BCM57840_VF },
  253. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811), BCM57811 },
  254. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_MF), BCM57811_MF },
  255. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_VF), BCM57811_VF },
  256. { 0 }
  257. };
  258. MODULE_DEVICE_TABLE(pci, bnx2x_pci_tbl);
  259. /* Global resources for unloading a previously loaded device */
  260. #define BNX2X_PREV_WAIT_NEEDED 1
  261. static DEFINE_SEMAPHORE(bnx2x_prev_sem);
  262. static LIST_HEAD(bnx2x_prev_list);
  263. /****************************************************************************
  264. * General service functions
  265. ****************************************************************************/
  266. static void __storm_memset_dma_mapping(struct bnx2x *bp,
  267. u32 addr, dma_addr_t mapping)
  268. {
  269. REG_WR(bp, addr, U64_LO(mapping));
  270. REG_WR(bp, addr + 4, U64_HI(mapping));
  271. }
  272. static void storm_memset_spq_addr(struct bnx2x *bp,
  273. dma_addr_t mapping, u16 abs_fid)
  274. {
  275. u32 addr = XSEM_REG_FAST_MEMORY +
  276. XSTORM_SPQ_PAGE_BASE_OFFSET(abs_fid);
  277. __storm_memset_dma_mapping(bp, addr, mapping);
  278. }
  279. static void storm_memset_vf_to_pf(struct bnx2x *bp, u16 abs_fid,
  280. u16 pf_id)
  281. {
  282. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_VF_TO_PF_OFFSET(abs_fid),
  283. pf_id);
  284. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_VF_TO_PF_OFFSET(abs_fid),
  285. pf_id);
  286. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_VF_TO_PF_OFFSET(abs_fid),
  287. pf_id);
  288. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_VF_TO_PF_OFFSET(abs_fid),
  289. pf_id);
  290. }
  291. static void storm_memset_func_en(struct bnx2x *bp, u16 abs_fid,
  292. u8 enable)
  293. {
  294. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(abs_fid),
  295. enable);
  296. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(abs_fid),
  297. enable);
  298. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(abs_fid),
  299. enable);
  300. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(abs_fid),
  301. enable);
  302. }
  303. static void storm_memset_eq_data(struct bnx2x *bp,
  304. struct event_ring_data *eq_data,
  305. u16 pfid)
  306. {
  307. size_t size = sizeof(struct event_ring_data);
  308. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_DATA_OFFSET(pfid);
  309. __storm_memset_struct(bp, addr, size, (u32 *)eq_data);
  310. }
  311. static void storm_memset_eq_prod(struct bnx2x *bp, u16 eq_prod,
  312. u16 pfid)
  313. {
  314. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_PROD_OFFSET(pfid);
  315. REG_WR16(bp, addr, eq_prod);
  316. }
  317. /* used only at init
  318. * locking is done by mcp
  319. */
  320. static void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val)
  321. {
  322. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  323. pci_write_config_dword(bp->pdev, PCICFG_GRC_DATA, val);
  324. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  325. PCICFG_VENDOR_ID_OFFSET);
  326. }
  327. static u32 bnx2x_reg_rd_ind(struct bnx2x *bp, u32 addr)
  328. {
  329. u32 val;
  330. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  331. pci_read_config_dword(bp->pdev, PCICFG_GRC_DATA, &val);
  332. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  333. PCICFG_VENDOR_ID_OFFSET);
  334. return val;
  335. }
  336. #define DMAE_DP_SRC_GRC "grc src_addr [%08x]"
  337. #define DMAE_DP_SRC_PCI "pci src_addr [%x:%08x]"
  338. #define DMAE_DP_DST_GRC "grc dst_addr [%08x]"
  339. #define DMAE_DP_DST_PCI "pci dst_addr [%x:%08x]"
  340. #define DMAE_DP_DST_NONE "dst_addr [none]"
  341. void bnx2x_dp_dmae(struct bnx2x *bp, struct dmae_command *dmae, int msglvl)
  342. {
  343. u32 src_type = dmae->opcode & DMAE_COMMAND_SRC;
  344. switch (dmae->opcode & DMAE_COMMAND_DST) {
  345. case DMAE_CMD_DST_PCI:
  346. if (src_type == DMAE_CMD_SRC_PCI)
  347. DP(msglvl, "DMAE: opcode 0x%08x\n"
  348. "src [%x:%08x], len [%d*4], dst [%x:%08x]\n"
  349. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  350. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  351. dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
  352. dmae->comp_addr_hi, dmae->comp_addr_lo,
  353. dmae->comp_val);
  354. else
  355. DP(msglvl, "DMAE: opcode 0x%08x\n"
  356. "src [%08x], len [%d*4], dst [%x:%08x]\n"
  357. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  358. dmae->opcode, dmae->src_addr_lo >> 2,
  359. dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
  360. dmae->comp_addr_hi, dmae->comp_addr_lo,
  361. dmae->comp_val);
  362. break;
  363. case DMAE_CMD_DST_GRC:
  364. if (src_type == DMAE_CMD_SRC_PCI)
  365. DP(msglvl, "DMAE: opcode 0x%08x\n"
  366. "src [%x:%08x], len [%d*4], dst_addr [%08x]\n"
  367. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  368. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  369. dmae->len, dmae->dst_addr_lo >> 2,
  370. dmae->comp_addr_hi, dmae->comp_addr_lo,
  371. dmae->comp_val);
  372. else
  373. DP(msglvl, "DMAE: opcode 0x%08x\n"
  374. "src [%08x], len [%d*4], dst [%08x]\n"
  375. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  376. dmae->opcode, dmae->src_addr_lo >> 2,
  377. dmae->len, dmae->dst_addr_lo >> 2,
  378. dmae->comp_addr_hi, dmae->comp_addr_lo,
  379. dmae->comp_val);
  380. break;
  381. default:
  382. if (src_type == DMAE_CMD_SRC_PCI)
  383. DP(msglvl, "DMAE: opcode 0x%08x\n"
  384. "src_addr [%x:%08x] len [%d * 4] dst_addr [none]\n"
  385. "comp_addr [%x:%08x] comp_val 0x%08x\n",
  386. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  387. dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
  388. dmae->comp_val);
  389. else
  390. DP(msglvl, "DMAE: opcode 0x%08x\n"
  391. "src_addr [%08x] len [%d * 4] dst_addr [none]\n"
  392. "comp_addr [%x:%08x] comp_val 0x%08x\n",
  393. dmae->opcode, dmae->src_addr_lo >> 2,
  394. dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
  395. dmae->comp_val);
  396. break;
  397. }
  398. }
  399. /* copy command into DMAE command memory and set DMAE command go */
  400. void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae, int idx)
  401. {
  402. u32 cmd_offset;
  403. int i;
  404. cmd_offset = (DMAE_REG_CMD_MEM + sizeof(struct dmae_command) * idx);
  405. for (i = 0; i < (sizeof(struct dmae_command)/4); i++) {
  406. REG_WR(bp, cmd_offset + i*4, *(((u32 *)dmae) + i));
  407. }
  408. REG_WR(bp, dmae_reg_go_c[idx], 1);
  409. }
  410. u32 bnx2x_dmae_opcode_add_comp(u32 opcode, u8 comp_type)
  411. {
  412. return opcode | ((comp_type << DMAE_COMMAND_C_DST_SHIFT) |
  413. DMAE_CMD_C_ENABLE);
  414. }
  415. u32 bnx2x_dmae_opcode_clr_src_reset(u32 opcode)
  416. {
  417. return opcode & ~DMAE_CMD_SRC_RESET;
  418. }
  419. u32 bnx2x_dmae_opcode(struct bnx2x *bp, u8 src_type, u8 dst_type,
  420. bool with_comp, u8 comp_type)
  421. {
  422. u32 opcode = 0;
  423. opcode |= ((src_type << DMAE_COMMAND_SRC_SHIFT) |
  424. (dst_type << DMAE_COMMAND_DST_SHIFT));
  425. opcode |= (DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET);
  426. opcode |= (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0);
  427. opcode |= ((BP_VN(bp) << DMAE_CMD_E1HVN_SHIFT) |
  428. (BP_VN(bp) << DMAE_COMMAND_DST_VN_SHIFT));
  429. opcode |= (DMAE_COM_SET_ERR << DMAE_COMMAND_ERR_POLICY_SHIFT);
  430. #ifdef __BIG_ENDIAN
  431. opcode |= DMAE_CMD_ENDIANITY_B_DW_SWAP;
  432. #else
  433. opcode |= DMAE_CMD_ENDIANITY_DW_SWAP;
  434. #endif
  435. if (with_comp)
  436. opcode = bnx2x_dmae_opcode_add_comp(opcode, comp_type);
  437. return opcode;
  438. }
  439. void bnx2x_prep_dmae_with_comp(struct bnx2x *bp,
  440. struct dmae_command *dmae,
  441. u8 src_type, u8 dst_type)
  442. {
  443. memset(dmae, 0, sizeof(struct dmae_command));
  444. /* set the opcode */
  445. dmae->opcode = bnx2x_dmae_opcode(bp, src_type, dst_type,
  446. true, DMAE_COMP_PCI);
  447. /* fill in the completion parameters */
  448. dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp));
  449. dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp));
  450. dmae->comp_val = DMAE_COMP_VAL;
  451. }
  452. /* issue a dmae command over the init-channel and wait for completion */
  453. int bnx2x_issue_dmae_with_comp(struct bnx2x *bp, struct dmae_command *dmae)
  454. {
  455. u32 *wb_comp = bnx2x_sp(bp, wb_comp);
  456. int cnt = CHIP_REV_IS_SLOW(bp) ? (400000) : 4000;
  457. int rc = 0;
  458. /*
  459. * Lock the dmae channel. Disable BHs to prevent a dead-lock
  460. * as long as this code is called both from syscall context and
  461. * from ndo_set_rx_mode() flow that may be called from BH.
  462. */
  463. spin_lock_bh(&bp->dmae_lock);
  464. /* reset completion */
  465. *wb_comp = 0;
  466. /* post the command on the channel used for initializations */
  467. bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp));
  468. /* wait for completion */
  469. udelay(5);
  470. while ((*wb_comp & ~DMAE_PCI_ERR_FLAG) != DMAE_COMP_VAL) {
  471. if (!cnt ||
  472. (bp->recovery_state != BNX2X_RECOVERY_DONE &&
  473. bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  474. BNX2X_ERR("DMAE timeout!\n");
  475. rc = DMAE_TIMEOUT;
  476. goto unlock;
  477. }
  478. cnt--;
  479. udelay(50);
  480. }
  481. if (*wb_comp & DMAE_PCI_ERR_FLAG) {
  482. BNX2X_ERR("DMAE PCI error!\n");
  483. rc = DMAE_PCI_ERROR;
  484. }
  485. unlock:
  486. spin_unlock_bh(&bp->dmae_lock);
  487. return rc;
  488. }
  489. void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr,
  490. u32 len32)
  491. {
  492. struct dmae_command dmae;
  493. if (!bp->dmae_ready) {
  494. u32 *data = bnx2x_sp(bp, wb_data[0]);
  495. if (CHIP_IS_E1(bp))
  496. bnx2x_init_ind_wr(bp, dst_addr, data, len32);
  497. else
  498. bnx2x_init_str_wr(bp, dst_addr, data, len32);
  499. return;
  500. }
  501. /* set opcode and fixed command fields */
  502. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_GRC);
  503. /* fill in addresses and len */
  504. dmae.src_addr_lo = U64_LO(dma_addr);
  505. dmae.src_addr_hi = U64_HI(dma_addr);
  506. dmae.dst_addr_lo = dst_addr >> 2;
  507. dmae.dst_addr_hi = 0;
  508. dmae.len = len32;
  509. /* issue the command and wait for completion */
  510. bnx2x_issue_dmae_with_comp(bp, &dmae);
  511. }
  512. void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32)
  513. {
  514. struct dmae_command dmae;
  515. if (!bp->dmae_ready) {
  516. u32 *data = bnx2x_sp(bp, wb_data[0]);
  517. int i;
  518. if (CHIP_IS_E1(bp))
  519. for (i = 0; i < len32; i++)
  520. data[i] = bnx2x_reg_rd_ind(bp, src_addr + i*4);
  521. else
  522. for (i = 0; i < len32; i++)
  523. data[i] = REG_RD(bp, src_addr + i*4);
  524. return;
  525. }
  526. /* set opcode and fixed command fields */
  527. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_GRC, DMAE_DST_PCI);
  528. /* fill in addresses and len */
  529. dmae.src_addr_lo = src_addr >> 2;
  530. dmae.src_addr_hi = 0;
  531. dmae.dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_data));
  532. dmae.dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_data));
  533. dmae.len = len32;
  534. /* issue the command and wait for completion */
  535. bnx2x_issue_dmae_with_comp(bp, &dmae);
  536. }
  537. static void bnx2x_write_dmae_phys_len(struct bnx2x *bp, dma_addr_t phys_addr,
  538. u32 addr, u32 len)
  539. {
  540. int dmae_wr_max = DMAE_LEN32_WR_MAX(bp);
  541. int offset = 0;
  542. while (len > dmae_wr_max) {
  543. bnx2x_write_dmae(bp, phys_addr + offset,
  544. addr + offset, dmae_wr_max);
  545. offset += dmae_wr_max * 4;
  546. len -= dmae_wr_max;
  547. }
  548. bnx2x_write_dmae(bp, phys_addr + offset, addr + offset, len);
  549. }
  550. static int bnx2x_mc_assert(struct bnx2x *bp)
  551. {
  552. char last_idx;
  553. int i, rc = 0;
  554. u32 row0, row1, row2, row3;
  555. /* XSTORM */
  556. last_idx = REG_RD8(bp, BAR_XSTRORM_INTMEM +
  557. XSTORM_ASSERT_LIST_INDEX_OFFSET);
  558. if (last_idx)
  559. BNX2X_ERR("XSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  560. /* print the asserts */
  561. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  562. row0 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  563. XSTORM_ASSERT_LIST_OFFSET(i));
  564. row1 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  565. XSTORM_ASSERT_LIST_OFFSET(i) + 4);
  566. row2 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  567. XSTORM_ASSERT_LIST_OFFSET(i) + 8);
  568. row3 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  569. XSTORM_ASSERT_LIST_OFFSET(i) + 12);
  570. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  571. BNX2X_ERR("XSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  572. i, row3, row2, row1, row0);
  573. rc++;
  574. } else {
  575. break;
  576. }
  577. }
  578. /* TSTORM */
  579. last_idx = REG_RD8(bp, BAR_TSTRORM_INTMEM +
  580. TSTORM_ASSERT_LIST_INDEX_OFFSET);
  581. if (last_idx)
  582. BNX2X_ERR("TSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  583. /* print the asserts */
  584. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  585. row0 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  586. TSTORM_ASSERT_LIST_OFFSET(i));
  587. row1 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  588. TSTORM_ASSERT_LIST_OFFSET(i) + 4);
  589. row2 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  590. TSTORM_ASSERT_LIST_OFFSET(i) + 8);
  591. row3 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  592. TSTORM_ASSERT_LIST_OFFSET(i) + 12);
  593. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  594. BNX2X_ERR("TSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  595. i, row3, row2, row1, row0);
  596. rc++;
  597. } else {
  598. break;
  599. }
  600. }
  601. /* CSTORM */
  602. last_idx = REG_RD8(bp, BAR_CSTRORM_INTMEM +
  603. CSTORM_ASSERT_LIST_INDEX_OFFSET);
  604. if (last_idx)
  605. BNX2X_ERR("CSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  606. /* print the asserts */
  607. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  608. row0 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  609. CSTORM_ASSERT_LIST_OFFSET(i));
  610. row1 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  611. CSTORM_ASSERT_LIST_OFFSET(i) + 4);
  612. row2 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  613. CSTORM_ASSERT_LIST_OFFSET(i) + 8);
  614. row3 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  615. CSTORM_ASSERT_LIST_OFFSET(i) + 12);
  616. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  617. BNX2X_ERR("CSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  618. i, row3, row2, row1, row0);
  619. rc++;
  620. } else {
  621. break;
  622. }
  623. }
  624. /* USTORM */
  625. last_idx = REG_RD8(bp, BAR_USTRORM_INTMEM +
  626. USTORM_ASSERT_LIST_INDEX_OFFSET);
  627. if (last_idx)
  628. BNX2X_ERR("USTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  629. /* print the asserts */
  630. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  631. row0 = REG_RD(bp, BAR_USTRORM_INTMEM +
  632. USTORM_ASSERT_LIST_OFFSET(i));
  633. row1 = REG_RD(bp, BAR_USTRORM_INTMEM +
  634. USTORM_ASSERT_LIST_OFFSET(i) + 4);
  635. row2 = REG_RD(bp, BAR_USTRORM_INTMEM +
  636. USTORM_ASSERT_LIST_OFFSET(i) + 8);
  637. row3 = REG_RD(bp, BAR_USTRORM_INTMEM +
  638. USTORM_ASSERT_LIST_OFFSET(i) + 12);
  639. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  640. BNX2X_ERR("USTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  641. i, row3, row2, row1, row0);
  642. rc++;
  643. } else {
  644. break;
  645. }
  646. }
  647. return rc;
  648. }
  649. void bnx2x_fw_dump_lvl(struct bnx2x *bp, const char *lvl)
  650. {
  651. u32 addr, val;
  652. u32 mark, offset;
  653. __be32 data[9];
  654. int word;
  655. u32 trace_shmem_base;
  656. if (BP_NOMCP(bp)) {
  657. BNX2X_ERR("NO MCP - can not dump\n");
  658. return;
  659. }
  660. netdev_printk(lvl, bp->dev, "bc %d.%d.%d\n",
  661. (bp->common.bc_ver & 0xff0000) >> 16,
  662. (bp->common.bc_ver & 0xff00) >> 8,
  663. (bp->common.bc_ver & 0xff));
  664. val = REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER);
  665. if (val == REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER))
  666. BNX2X_ERR("%s" "MCP PC at 0x%x\n", lvl, val);
  667. if (BP_PATH(bp) == 0)
  668. trace_shmem_base = bp->common.shmem_base;
  669. else
  670. trace_shmem_base = SHMEM2_RD(bp, other_shmem_base_addr);
  671. addr = trace_shmem_base - 0x800;
  672. /* validate TRCB signature */
  673. mark = REG_RD(bp, addr);
  674. if (mark != MFW_TRACE_SIGNATURE) {
  675. BNX2X_ERR("Trace buffer signature is missing.");
  676. return ;
  677. }
  678. /* read cyclic buffer pointer */
  679. addr += 4;
  680. mark = REG_RD(bp, addr);
  681. mark = (CHIP_IS_E1x(bp) ? MCP_REG_MCPR_SCRATCH : MCP_A_REG_MCPR_SCRATCH)
  682. + ((mark + 0x3) & ~0x3) - 0x08000000;
  683. printk("%s" "begin fw dump (mark 0x%x)\n", lvl, mark);
  684. printk("%s", lvl);
  685. /* dump buffer after the mark */
  686. for (offset = mark; offset <= trace_shmem_base; offset += 0x8*4) {
  687. for (word = 0; word < 8; word++)
  688. data[word] = htonl(REG_RD(bp, offset + 4*word));
  689. data[8] = 0x0;
  690. pr_cont("%s", (char *)data);
  691. }
  692. /* dump buffer before the mark */
  693. for (offset = addr + 4; offset <= mark; offset += 0x8*4) {
  694. for (word = 0; word < 8; word++)
  695. data[word] = htonl(REG_RD(bp, offset + 4*word));
  696. data[8] = 0x0;
  697. pr_cont("%s", (char *)data);
  698. }
  699. printk("%s" "end of fw dump\n", lvl);
  700. }
  701. static void bnx2x_fw_dump(struct bnx2x *bp)
  702. {
  703. bnx2x_fw_dump_lvl(bp, KERN_ERR);
  704. }
  705. static void bnx2x_hc_int_disable(struct bnx2x *bp)
  706. {
  707. int port = BP_PORT(bp);
  708. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  709. u32 val = REG_RD(bp, addr);
  710. /* in E1 we must use only PCI configuration space to disable
  711. * MSI/MSIX capablility
  712. * It's forbitten to disable IGU_PF_CONF_MSI_MSIX_EN in HC block
  713. */
  714. if (CHIP_IS_E1(bp)) {
  715. /* Since IGU_PF_CONF_MSI_MSIX_EN still always on
  716. * Use mask register to prevent from HC sending interrupts
  717. * after we exit the function
  718. */
  719. REG_WR(bp, HC_REG_INT_MASK + port*4, 0);
  720. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  721. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  722. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  723. } else
  724. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  725. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  726. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  727. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  728. DP(NETIF_MSG_IFDOWN,
  729. "write %x to HC %d (addr 0x%x)\n",
  730. val, port, addr);
  731. /* flush all outstanding writes */
  732. mmiowb();
  733. REG_WR(bp, addr, val);
  734. if (REG_RD(bp, addr) != val)
  735. BNX2X_ERR("BUG! proper val not read from IGU!\n");
  736. }
  737. static void bnx2x_igu_int_disable(struct bnx2x *bp)
  738. {
  739. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  740. val &= ~(IGU_PF_CONF_MSI_MSIX_EN |
  741. IGU_PF_CONF_INT_LINE_EN |
  742. IGU_PF_CONF_ATTN_BIT_EN);
  743. DP(NETIF_MSG_IFDOWN, "write %x to IGU\n", val);
  744. /* flush all outstanding writes */
  745. mmiowb();
  746. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  747. if (REG_RD(bp, IGU_REG_PF_CONFIGURATION) != val)
  748. BNX2X_ERR("BUG! proper val not read from IGU!\n");
  749. }
  750. static void bnx2x_int_disable(struct bnx2x *bp)
  751. {
  752. if (bp->common.int_block == INT_BLOCK_HC)
  753. bnx2x_hc_int_disable(bp);
  754. else
  755. bnx2x_igu_int_disable(bp);
  756. }
  757. void bnx2x_panic_dump(struct bnx2x *bp, bool disable_int)
  758. {
  759. int i;
  760. u16 j;
  761. struct hc_sp_status_block_data sp_sb_data;
  762. int func = BP_FUNC(bp);
  763. #ifdef BNX2X_STOP_ON_ERROR
  764. u16 start = 0, end = 0;
  765. u8 cos;
  766. #endif
  767. if (disable_int)
  768. bnx2x_int_disable(bp);
  769. bp->stats_state = STATS_STATE_DISABLED;
  770. bp->eth_stats.unrecoverable_error++;
  771. DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n");
  772. BNX2X_ERR("begin crash dump -----------------\n");
  773. /* Indices */
  774. /* Common */
  775. 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",
  776. bp->def_idx, bp->def_att_idx, bp->attn_state,
  777. bp->spq_prod_idx, bp->stats_counter);
  778. BNX2X_ERR("DSB: attn bits(0x%x) ack(0x%x) id(0x%x) idx(0x%x)\n",
  779. bp->def_status_blk->atten_status_block.attn_bits,
  780. bp->def_status_blk->atten_status_block.attn_bits_ack,
  781. bp->def_status_blk->atten_status_block.status_block_id,
  782. bp->def_status_blk->atten_status_block.attn_bits_index);
  783. BNX2X_ERR(" def (");
  784. for (i = 0; i < HC_SP_SB_MAX_INDICES; i++)
  785. pr_cont("0x%x%s",
  786. bp->def_status_blk->sp_sb.index_values[i],
  787. (i == HC_SP_SB_MAX_INDICES - 1) ? ") " : " ");
  788. for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
  789. *((u32 *)&sp_sb_data + i) = REG_RD(bp, BAR_CSTRORM_INTMEM +
  790. CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
  791. i*sizeof(u32));
  792. 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",
  793. sp_sb_data.igu_sb_id,
  794. sp_sb_data.igu_seg_id,
  795. sp_sb_data.p_func.pf_id,
  796. sp_sb_data.p_func.vnic_id,
  797. sp_sb_data.p_func.vf_id,
  798. sp_sb_data.p_func.vf_valid,
  799. sp_sb_data.state);
  800. for_each_eth_queue(bp, i) {
  801. struct bnx2x_fastpath *fp = &bp->fp[i];
  802. int loop;
  803. struct hc_status_block_data_e2 sb_data_e2;
  804. struct hc_status_block_data_e1x sb_data_e1x;
  805. struct hc_status_block_sm *hc_sm_p =
  806. CHIP_IS_E1x(bp) ?
  807. sb_data_e1x.common.state_machine :
  808. sb_data_e2.common.state_machine;
  809. struct hc_index_data *hc_index_p =
  810. CHIP_IS_E1x(bp) ?
  811. sb_data_e1x.index_data :
  812. sb_data_e2.index_data;
  813. u8 data_size, cos;
  814. u32 *sb_data_p;
  815. struct bnx2x_fp_txdata txdata;
  816. /* Rx */
  817. 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",
  818. i, fp->rx_bd_prod, fp->rx_bd_cons,
  819. fp->rx_comp_prod,
  820. fp->rx_comp_cons, le16_to_cpu(*fp->rx_cons_sb));
  821. BNX2X_ERR(" rx_sge_prod(0x%x) last_max_sge(0x%x) fp_hc_idx(0x%x)\n",
  822. fp->rx_sge_prod, fp->last_max_sge,
  823. le16_to_cpu(fp->fp_hc_idx));
  824. /* Tx */
  825. for_each_cos_in_tx_queue(fp, cos)
  826. {
  827. txdata = *fp->txdata_ptr[cos];
  828. 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",
  829. i, txdata.tx_pkt_prod,
  830. txdata.tx_pkt_cons, txdata.tx_bd_prod,
  831. txdata.tx_bd_cons,
  832. le16_to_cpu(*txdata.tx_cons_sb));
  833. }
  834. loop = CHIP_IS_E1x(bp) ?
  835. HC_SB_MAX_INDICES_E1X : HC_SB_MAX_INDICES_E2;
  836. /* host sb data */
  837. if (IS_FCOE_FP(fp))
  838. continue;
  839. BNX2X_ERR(" run indexes (");
  840. for (j = 0; j < HC_SB_MAX_SM; j++)
  841. pr_cont("0x%x%s",
  842. fp->sb_running_index[j],
  843. (j == HC_SB_MAX_SM - 1) ? ")" : " ");
  844. BNX2X_ERR(" indexes (");
  845. for (j = 0; j < loop; j++)
  846. pr_cont("0x%x%s",
  847. fp->sb_index_values[j],
  848. (j == loop - 1) ? ")" : " ");
  849. /* fw sb data */
  850. data_size = CHIP_IS_E1x(bp) ?
  851. sizeof(struct hc_status_block_data_e1x) :
  852. sizeof(struct hc_status_block_data_e2);
  853. data_size /= sizeof(u32);
  854. sb_data_p = CHIP_IS_E1x(bp) ?
  855. (u32 *)&sb_data_e1x :
  856. (u32 *)&sb_data_e2;
  857. /* copy sb data in here */
  858. for (j = 0; j < data_size; j++)
  859. *(sb_data_p + j) = REG_RD(bp, BAR_CSTRORM_INTMEM +
  860. CSTORM_STATUS_BLOCK_DATA_OFFSET(fp->fw_sb_id) +
  861. j * sizeof(u32));
  862. if (!CHIP_IS_E1x(bp)) {
  863. 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",
  864. sb_data_e2.common.p_func.pf_id,
  865. sb_data_e2.common.p_func.vf_id,
  866. sb_data_e2.common.p_func.vf_valid,
  867. sb_data_e2.common.p_func.vnic_id,
  868. sb_data_e2.common.same_igu_sb_1b,
  869. sb_data_e2.common.state);
  870. } else {
  871. 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",
  872. sb_data_e1x.common.p_func.pf_id,
  873. sb_data_e1x.common.p_func.vf_id,
  874. sb_data_e1x.common.p_func.vf_valid,
  875. sb_data_e1x.common.p_func.vnic_id,
  876. sb_data_e1x.common.same_igu_sb_1b,
  877. sb_data_e1x.common.state);
  878. }
  879. /* SB_SMs data */
  880. for (j = 0; j < HC_SB_MAX_SM; j++) {
  881. 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",
  882. j, hc_sm_p[j].__flags,
  883. hc_sm_p[j].igu_sb_id,
  884. hc_sm_p[j].igu_seg_id,
  885. hc_sm_p[j].time_to_expire,
  886. hc_sm_p[j].timer_value);
  887. }
  888. /* Indecies data */
  889. for (j = 0; j < loop; j++) {
  890. pr_cont("INDEX[%d] flags (0x%x) timeout (0x%x)\n", j,
  891. hc_index_p[j].flags,
  892. hc_index_p[j].timeout);
  893. }
  894. }
  895. #ifdef BNX2X_STOP_ON_ERROR
  896. /* event queue */
  897. for (i = 0; i < NUM_EQ_DESC; i++) {
  898. u32 *data = (u32 *)&bp->eq_ring[i].message.data;
  899. BNX2X_ERR("event queue [%d]: header: opcode %d, error %d\n",
  900. i, bp->eq_ring[i].message.opcode,
  901. bp->eq_ring[i].message.error);
  902. BNX2X_ERR("data: %x %x %x\n", data[0], data[1], data[2]);
  903. }
  904. /* Rings */
  905. /* Rx */
  906. for_each_valid_rx_queue(bp, i) {
  907. struct bnx2x_fastpath *fp = &bp->fp[i];
  908. start = RX_BD(le16_to_cpu(*fp->rx_cons_sb) - 10);
  909. end = RX_BD(le16_to_cpu(*fp->rx_cons_sb) + 503);
  910. for (j = start; j != end; j = RX_BD(j + 1)) {
  911. u32 *rx_bd = (u32 *)&fp->rx_desc_ring[j];
  912. struct sw_rx_bd *sw_bd = &fp->rx_buf_ring[j];
  913. BNX2X_ERR("fp%d: rx_bd[%x]=[%x:%x] sw_bd=[%p]\n",
  914. i, j, rx_bd[1], rx_bd[0], sw_bd->data);
  915. }
  916. start = RX_SGE(fp->rx_sge_prod);
  917. end = RX_SGE(fp->last_max_sge);
  918. for (j = start; j != end; j = RX_SGE(j + 1)) {
  919. u32 *rx_sge = (u32 *)&fp->rx_sge_ring[j];
  920. struct sw_rx_page *sw_page = &fp->rx_page_ring[j];
  921. BNX2X_ERR("fp%d: rx_sge[%x]=[%x:%x] sw_page=[%p]\n",
  922. i, j, rx_sge[1], rx_sge[0], sw_page->page);
  923. }
  924. start = RCQ_BD(fp->rx_comp_cons - 10);
  925. end = RCQ_BD(fp->rx_comp_cons + 503);
  926. for (j = start; j != end; j = RCQ_BD(j + 1)) {
  927. u32 *cqe = (u32 *)&fp->rx_comp_ring[j];
  928. BNX2X_ERR("fp%d: cqe[%x]=[%x:%x:%x:%x]\n",
  929. i, j, cqe[0], cqe[1], cqe[2], cqe[3]);
  930. }
  931. }
  932. /* Tx */
  933. for_each_valid_tx_queue(bp, i) {
  934. struct bnx2x_fastpath *fp = &bp->fp[i];
  935. for_each_cos_in_tx_queue(fp, cos) {
  936. struct bnx2x_fp_txdata *txdata = fp->txdata_ptr[cos];
  937. start = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) - 10);
  938. end = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) + 245);
  939. for (j = start; j != end; j = TX_BD(j + 1)) {
  940. struct sw_tx_bd *sw_bd =
  941. &txdata->tx_buf_ring[j];
  942. BNX2X_ERR("fp%d: txdata %d, packet[%x]=[%p,%x]\n",
  943. i, cos, j, sw_bd->skb,
  944. sw_bd->first_bd);
  945. }
  946. start = TX_BD(txdata->tx_bd_cons - 10);
  947. end = TX_BD(txdata->tx_bd_cons + 254);
  948. for (j = start; j != end; j = TX_BD(j + 1)) {
  949. u32 *tx_bd = (u32 *)&txdata->tx_desc_ring[j];
  950. BNX2X_ERR("fp%d: txdata %d, tx_bd[%x]=[%x:%x:%x:%x]\n",
  951. i, cos, j, tx_bd[0], tx_bd[1],
  952. tx_bd[2], tx_bd[3]);
  953. }
  954. }
  955. }
  956. #endif
  957. bnx2x_fw_dump(bp);
  958. bnx2x_mc_assert(bp);
  959. BNX2X_ERR("end crash dump -----------------\n");
  960. }
  961. /*
  962. * FLR Support for E2
  963. *
  964. * bnx2x_pf_flr_clnup() is called during nic_load in the per function HW
  965. * initialization.
  966. */
  967. #define FLR_WAIT_USEC 10000 /* 10 miliseconds */
  968. #define FLR_WAIT_INTERVAL 50 /* usec */
  969. #define FLR_POLL_CNT (FLR_WAIT_USEC/FLR_WAIT_INTERVAL) /* 200 */
  970. struct pbf_pN_buf_regs {
  971. int pN;
  972. u32 init_crd;
  973. u32 crd;
  974. u32 crd_freed;
  975. };
  976. struct pbf_pN_cmd_regs {
  977. int pN;
  978. u32 lines_occup;
  979. u32 lines_freed;
  980. };
  981. static void bnx2x_pbf_pN_buf_flushed(struct bnx2x *bp,
  982. struct pbf_pN_buf_regs *regs,
  983. u32 poll_count)
  984. {
  985. u32 init_crd, crd, crd_start, crd_freed, crd_freed_start;
  986. u32 cur_cnt = poll_count;
  987. crd_freed = crd_freed_start = REG_RD(bp, regs->crd_freed);
  988. crd = crd_start = REG_RD(bp, regs->crd);
  989. init_crd = REG_RD(bp, regs->init_crd);
  990. DP(BNX2X_MSG_SP, "INIT CREDIT[%d] : %x\n", regs->pN, init_crd);
  991. DP(BNX2X_MSG_SP, "CREDIT[%d] : s:%x\n", regs->pN, crd);
  992. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: s:%x\n", regs->pN, crd_freed);
  993. while ((crd != init_crd) && ((u32)SUB_S32(crd_freed, crd_freed_start) <
  994. (init_crd - crd_start))) {
  995. if (cur_cnt--) {
  996. udelay(FLR_WAIT_INTERVAL);
  997. crd = REG_RD(bp, regs->crd);
  998. crd_freed = REG_RD(bp, regs->crd_freed);
  999. } else {
  1000. DP(BNX2X_MSG_SP, "PBF tx buffer[%d] timed out\n",
  1001. regs->pN);
  1002. DP(BNX2X_MSG_SP, "CREDIT[%d] : c:%x\n",
  1003. regs->pN, crd);
  1004. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: c:%x\n",
  1005. regs->pN, crd_freed);
  1006. break;
  1007. }
  1008. }
  1009. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF tx buffer[%d]\n",
  1010. poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
  1011. }
  1012. static void bnx2x_pbf_pN_cmd_flushed(struct bnx2x *bp,
  1013. struct pbf_pN_cmd_regs *regs,
  1014. u32 poll_count)
  1015. {
  1016. u32 occup, to_free, freed, freed_start;
  1017. u32 cur_cnt = poll_count;
  1018. occup = to_free = REG_RD(bp, regs->lines_occup);
  1019. freed = freed_start = REG_RD(bp, regs->lines_freed);
  1020. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n", regs->pN, occup);
  1021. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n", regs->pN, freed);
  1022. while (occup && ((u32)SUB_S32(freed, freed_start) < to_free)) {
  1023. if (cur_cnt--) {
  1024. udelay(FLR_WAIT_INTERVAL);
  1025. occup = REG_RD(bp, regs->lines_occup);
  1026. freed = REG_RD(bp, regs->lines_freed);
  1027. } else {
  1028. DP(BNX2X_MSG_SP, "PBF cmd queue[%d] timed out\n",
  1029. regs->pN);
  1030. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n",
  1031. regs->pN, occup);
  1032. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n",
  1033. regs->pN, freed);
  1034. break;
  1035. }
  1036. }
  1037. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF cmd queue[%d]\n",
  1038. poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
  1039. }
  1040. static u32 bnx2x_flr_clnup_reg_poll(struct bnx2x *bp, u32 reg,
  1041. u32 expected, u32 poll_count)
  1042. {
  1043. u32 cur_cnt = poll_count;
  1044. u32 val;
  1045. while ((val = REG_RD(bp, reg)) != expected && cur_cnt--)
  1046. udelay(FLR_WAIT_INTERVAL);
  1047. return val;
  1048. }
  1049. int bnx2x_flr_clnup_poll_hw_counter(struct bnx2x *bp, u32 reg,
  1050. char *msg, u32 poll_cnt)
  1051. {
  1052. u32 val = bnx2x_flr_clnup_reg_poll(bp, reg, 0, poll_cnt);
  1053. if (val != 0) {
  1054. BNX2X_ERR("%s usage count=%d\n", msg, val);
  1055. return 1;
  1056. }
  1057. return 0;
  1058. }
  1059. /* Common routines with VF FLR cleanup */
  1060. u32 bnx2x_flr_clnup_poll_count(struct bnx2x *bp)
  1061. {
  1062. /* adjust polling timeout */
  1063. if (CHIP_REV_IS_EMUL(bp))
  1064. return FLR_POLL_CNT * 2000;
  1065. if (CHIP_REV_IS_FPGA(bp))
  1066. return FLR_POLL_CNT * 120;
  1067. return FLR_POLL_CNT;
  1068. }
  1069. void bnx2x_tx_hw_flushed(struct bnx2x *bp, u32 poll_count)
  1070. {
  1071. struct pbf_pN_cmd_regs cmd_regs[] = {
  1072. {0, (CHIP_IS_E3B0(bp)) ?
  1073. PBF_REG_TQ_OCCUPANCY_Q0 :
  1074. PBF_REG_P0_TQ_OCCUPANCY,
  1075. (CHIP_IS_E3B0(bp)) ?
  1076. PBF_REG_TQ_LINES_FREED_CNT_Q0 :
  1077. PBF_REG_P0_TQ_LINES_FREED_CNT},
  1078. {1, (CHIP_IS_E3B0(bp)) ?
  1079. PBF_REG_TQ_OCCUPANCY_Q1 :
  1080. PBF_REG_P1_TQ_OCCUPANCY,
  1081. (CHIP_IS_E3B0(bp)) ?
  1082. PBF_REG_TQ_LINES_FREED_CNT_Q1 :
  1083. PBF_REG_P1_TQ_LINES_FREED_CNT},
  1084. {4, (CHIP_IS_E3B0(bp)) ?
  1085. PBF_REG_TQ_OCCUPANCY_LB_Q :
  1086. PBF_REG_P4_TQ_OCCUPANCY,
  1087. (CHIP_IS_E3B0(bp)) ?
  1088. PBF_REG_TQ_LINES_FREED_CNT_LB_Q :
  1089. PBF_REG_P4_TQ_LINES_FREED_CNT}
  1090. };
  1091. struct pbf_pN_buf_regs buf_regs[] = {
  1092. {0, (CHIP_IS_E3B0(bp)) ?
  1093. PBF_REG_INIT_CRD_Q0 :
  1094. PBF_REG_P0_INIT_CRD ,
  1095. (CHIP_IS_E3B0(bp)) ?
  1096. PBF_REG_CREDIT_Q0 :
  1097. PBF_REG_P0_CREDIT,
  1098. (CHIP_IS_E3B0(bp)) ?
  1099. PBF_REG_INTERNAL_CRD_FREED_CNT_Q0 :
  1100. PBF_REG_P0_INTERNAL_CRD_FREED_CNT},
  1101. {1, (CHIP_IS_E3B0(bp)) ?
  1102. PBF_REG_INIT_CRD_Q1 :
  1103. PBF_REG_P1_INIT_CRD,
  1104. (CHIP_IS_E3B0(bp)) ?
  1105. PBF_REG_CREDIT_Q1 :
  1106. PBF_REG_P1_CREDIT,
  1107. (CHIP_IS_E3B0(bp)) ?
  1108. PBF_REG_INTERNAL_CRD_FREED_CNT_Q1 :
  1109. PBF_REG_P1_INTERNAL_CRD_FREED_CNT},
  1110. {4, (CHIP_IS_E3B0(bp)) ?
  1111. PBF_REG_INIT_CRD_LB_Q :
  1112. PBF_REG_P4_INIT_CRD,
  1113. (CHIP_IS_E3B0(bp)) ?
  1114. PBF_REG_CREDIT_LB_Q :
  1115. PBF_REG_P4_CREDIT,
  1116. (CHIP_IS_E3B0(bp)) ?
  1117. PBF_REG_INTERNAL_CRD_FREED_CNT_LB_Q :
  1118. PBF_REG_P4_INTERNAL_CRD_FREED_CNT},
  1119. };
  1120. int i;
  1121. /* Verify the command queues are flushed P0, P1, P4 */
  1122. for (i = 0; i < ARRAY_SIZE(cmd_regs); i++)
  1123. bnx2x_pbf_pN_cmd_flushed(bp, &cmd_regs[i], poll_count);
  1124. /* Verify the transmission buffers are flushed P0, P1, P4 */
  1125. for (i = 0; i < ARRAY_SIZE(buf_regs); i++)
  1126. bnx2x_pbf_pN_buf_flushed(bp, &buf_regs[i], poll_count);
  1127. }
  1128. #define OP_GEN_PARAM(param) \
  1129. (((param) << SDM_OP_GEN_COMP_PARAM_SHIFT) & SDM_OP_GEN_COMP_PARAM)
  1130. #define OP_GEN_TYPE(type) \
  1131. (((type) << SDM_OP_GEN_COMP_TYPE_SHIFT) & SDM_OP_GEN_COMP_TYPE)
  1132. #define OP_GEN_AGG_VECT(index) \
  1133. (((index) << SDM_OP_GEN_AGG_VECT_IDX_SHIFT) & SDM_OP_GEN_AGG_VECT_IDX)
  1134. int bnx2x_send_final_clnup(struct bnx2x *bp, u8 clnup_func, u32 poll_cnt)
  1135. {
  1136. struct sdm_op_gen op_gen = {0};
  1137. u32 comp_addr = BAR_CSTRORM_INTMEM +
  1138. CSTORM_FINAL_CLEANUP_COMPLETE_OFFSET(clnup_func);
  1139. int ret = 0;
  1140. if (REG_RD(bp, comp_addr)) {
  1141. BNX2X_ERR("Cleanup complete was not 0 before sending\n");
  1142. return 1;
  1143. }
  1144. op_gen.command |= OP_GEN_PARAM(XSTORM_AGG_INT_FINAL_CLEANUP_INDEX);
  1145. op_gen.command |= OP_GEN_TYPE(XSTORM_AGG_INT_FINAL_CLEANUP_COMP_TYPE);
  1146. op_gen.command |= OP_GEN_AGG_VECT(clnup_func);
  1147. op_gen.command |= 1 << SDM_OP_GEN_AGG_VECT_IDX_VALID_SHIFT;
  1148. DP(BNX2X_MSG_SP, "sending FW Final cleanup\n");
  1149. REG_WR(bp, XSDM_REG_OPERATION_GEN, op_gen.command);
  1150. if (bnx2x_flr_clnup_reg_poll(bp, comp_addr, 1, poll_cnt) != 1) {
  1151. BNX2X_ERR("FW final cleanup did not succeed\n");
  1152. DP(BNX2X_MSG_SP, "At timeout completion address contained %x\n",
  1153. (REG_RD(bp, comp_addr)));
  1154. bnx2x_panic();
  1155. return 1;
  1156. }
  1157. /* Zero completion for nxt FLR */
  1158. REG_WR(bp, comp_addr, 0);
  1159. return ret;
  1160. }
  1161. u8 bnx2x_is_pcie_pending(struct pci_dev *dev)
  1162. {
  1163. u16 status;
  1164. pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status);
  1165. return status & PCI_EXP_DEVSTA_TRPND;
  1166. }
  1167. /* PF FLR specific routines
  1168. */
  1169. static int bnx2x_poll_hw_usage_counters(struct bnx2x *bp, u32 poll_cnt)
  1170. {
  1171. /* wait for CFC PF usage-counter to zero (includes all the VFs) */
  1172. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1173. CFC_REG_NUM_LCIDS_INSIDE_PF,
  1174. "CFC PF usage counter timed out",
  1175. poll_cnt))
  1176. return 1;
  1177. /* Wait for DQ PF usage-counter to zero (until DQ cleanup) */
  1178. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1179. DORQ_REG_PF_USAGE_CNT,
  1180. "DQ PF usage counter timed out",
  1181. poll_cnt))
  1182. return 1;
  1183. /* Wait for QM PF usage-counter to zero (until DQ cleanup) */
  1184. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1185. QM_REG_PF_USG_CNT_0 + 4*BP_FUNC(bp),
  1186. "QM PF usage counter timed out",
  1187. poll_cnt))
  1188. return 1;
  1189. /* Wait for Timer PF usage-counters to zero (until DQ cleanup) */
  1190. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1191. TM_REG_LIN0_VNIC_UC + 4*BP_PORT(bp),
  1192. "Timers VNIC usage counter timed out",
  1193. poll_cnt))
  1194. return 1;
  1195. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1196. TM_REG_LIN0_NUM_SCANS + 4*BP_PORT(bp),
  1197. "Timers NUM_SCANS usage counter timed out",
  1198. poll_cnt))
  1199. return 1;
  1200. /* Wait DMAE PF usage counter to zero */
  1201. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1202. dmae_reg_go_c[INIT_DMAE_C(bp)],
  1203. "DMAE dommand register timed out",
  1204. poll_cnt))
  1205. return 1;
  1206. return 0;
  1207. }
  1208. static void bnx2x_hw_enable_status(struct bnx2x *bp)
  1209. {
  1210. u32 val;
  1211. val = REG_RD(bp, CFC_REG_WEAK_ENABLE_PF);
  1212. DP(BNX2X_MSG_SP, "CFC_REG_WEAK_ENABLE_PF is 0x%x\n", val);
  1213. val = REG_RD(bp, PBF_REG_DISABLE_PF);
  1214. DP(BNX2X_MSG_SP, "PBF_REG_DISABLE_PF is 0x%x\n", val);
  1215. val = REG_RD(bp, IGU_REG_PCI_PF_MSI_EN);
  1216. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSI_EN is 0x%x\n", val);
  1217. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_EN);
  1218. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_EN is 0x%x\n", val);
  1219. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_FUNC_MASK);
  1220. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_FUNC_MASK is 0x%x\n", val);
  1221. val = REG_RD(bp, PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR);
  1222. DP(BNX2X_MSG_SP, "PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR is 0x%x\n", val);
  1223. val = REG_RD(bp, PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR);
  1224. DP(BNX2X_MSG_SP, "PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR is 0x%x\n", val);
  1225. val = REG_RD(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
  1226. DP(BNX2X_MSG_SP, "PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER is 0x%x\n",
  1227. val);
  1228. }
  1229. static int bnx2x_pf_flr_clnup(struct bnx2x *bp)
  1230. {
  1231. u32 poll_cnt = bnx2x_flr_clnup_poll_count(bp);
  1232. DP(BNX2X_MSG_SP, "Cleanup after FLR PF[%d]\n", BP_ABS_FUNC(bp));
  1233. /* Re-enable PF target read access */
  1234. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  1235. /* Poll HW usage counters */
  1236. DP(BNX2X_MSG_SP, "Polling usage counters\n");
  1237. if (bnx2x_poll_hw_usage_counters(bp, poll_cnt))
  1238. return -EBUSY;
  1239. /* Zero the igu 'trailing edge' and 'leading edge' */
  1240. /* Send the FW cleanup command */
  1241. if (bnx2x_send_final_clnup(bp, (u8)BP_FUNC(bp), poll_cnt))
  1242. return -EBUSY;
  1243. /* ATC cleanup */
  1244. /* Verify TX hw is flushed */
  1245. bnx2x_tx_hw_flushed(bp, poll_cnt);
  1246. /* Wait 100ms (not adjusted according to platform) */
  1247. msleep(100);
  1248. /* Verify no pending pci transactions */
  1249. if (bnx2x_is_pcie_pending(bp->pdev))
  1250. BNX2X_ERR("PCIE Transactions still pending\n");
  1251. /* Debug */
  1252. bnx2x_hw_enable_status(bp);
  1253. /*
  1254. * Master enable - Due to WB DMAE writes performed before this
  1255. * register is re-initialized as part of the regular function init
  1256. */
  1257. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  1258. return 0;
  1259. }
  1260. static void bnx2x_hc_int_enable(struct bnx2x *bp)
  1261. {
  1262. int port = BP_PORT(bp);
  1263. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  1264. u32 val = REG_RD(bp, addr);
  1265. bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
  1266. bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
  1267. bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
  1268. if (msix) {
  1269. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1270. HC_CONFIG_0_REG_INT_LINE_EN_0);
  1271. val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1272. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1273. if (single_msix)
  1274. val |= HC_CONFIG_0_REG_SINGLE_ISR_EN_0;
  1275. } else if (msi) {
  1276. val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0;
  1277. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1278. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1279. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1280. } else {
  1281. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1282. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1283. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  1284. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1285. if (!CHIP_IS_E1(bp)) {
  1286. DP(NETIF_MSG_IFUP,
  1287. "write %x to HC %d (addr 0x%x)\n", val, port, addr);
  1288. REG_WR(bp, addr, val);
  1289. val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0;
  1290. }
  1291. }
  1292. if (CHIP_IS_E1(bp))
  1293. REG_WR(bp, HC_REG_INT_MASK + port*4, 0x1FFFF);
  1294. DP(NETIF_MSG_IFUP,
  1295. "write %x to HC %d (addr 0x%x) mode %s\n", val, port, addr,
  1296. (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1297. REG_WR(bp, addr, val);
  1298. /*
  1299. * Ensure that HC_CONFIG is written before leading/trailing edge config
  1300. */
  1301. mmiowb();
  1302. barrier();
  1303. if (!CHIP_IS_E1(bp)) {
  1304. /* init leading/trailing edge */
  1305. if (IS_MF(bp)) {
  1306. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1307. if (bp->port.pmf)
  1308. /* enable nig and gpio3 attention */
  1309. val |= 0x1100;
  1310. } else
  1311. val = 0xffff;
  1312. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  1313. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  1314. }
  1315. /* Make sure that interrupts are indeed enabled from here on */
  1316. mmiowb();
  1317. }
  1318. static void bnx2x_igu_int_enable(struct bnx2x *bp)
  1319. {
  1320. u32 val;
  1321. bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
  1322. bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
  1323. bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
  1324. val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  1325. if (msix) {
  1326. val &= ~(IGU_PF_CONF_INT_LINE_EN |
  1327. IGU_PF_CONF_SINGLE_ISR_EN);
  1328. val |= (IGU_PF_CONF_MSI_MSIX_EN |
  1329. IGU_PF_CONF_ATTN_BIT_EN);
  1330. if (single_msix)
  1331. val |= IGU_PF_CONF_SINGLE_ISR_EN;
  1332. } else if (msi) {
  1333. val &= ~IGU_PF_CONF_INT_LINE_EN;
  1334. val |= (IGU_PF_CONF_MSI_MSIX_EN |
  1335. IGU_PF_CONF_ATTN_BIT_EN |
  1336. IGU_PF_CONF_SINGLE_ISR_EN);
  1337. } else {
  1338. val &= ~IGU_PF_CONF_MSI_MSIX_EN;
  1339. val |= (IGU_PF_CONF_INT_LINE_EN |
  1340. IGU_PF_CONF_ATTN_BIT_EN |
  1341. IGU_PF_CONF_SINGLE_ISR_EN);
  1342. }
  1343. /* Clean previous status - need to configure igu prior to ack*/
  1344. if ((!msix) || single_msix) {
  1345. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1346. bnx2x_ack_int(bp);
  1347. }
  1348. val |= IGU_PF_CONF_FUNC_EN;
  1349. DP(NETIF_MSG_IFUP, "write 0x%x to IGU mode %s\n",
  1350. val, (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1351. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1352. if (val & IGU_PF_CONF_INT_LINE_EN)
  1353. pci_intx(bp->pdev, true);
  1354. barrier();
  1355. /* init leading/trailing edge */
  1356. if (IS_MF(bp)) {
  1357. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1358. if (bp->port.pmf)
  1359. /* enable nig and gpio3 attention */
  1360. val |= 0x1100;
  1361. } else
  1362. val = 0xffff;
  1363. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  1364. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  1365. /* Make sure that interrupts are indeed enabled from here on */
  1366. mmiowb();
  1367. }
  1368. void bnx2x_int_enable(struct bnx2x *bp)
  1369. {
  1370. if (bp->common.int_block == INT_BLOCK_HC)
  1371. bnx2x_hc_int_enable(bp);
  1372. else
  1373. bnx2x_igu_int_enable(bp);
  1374. }
  1375. void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw)
  1376. {
  1377. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  1378. int i, offset;
  1379. if (disable_hw)
  1380. /* prevent the HW from sending interrupts */
  1381. bnx2x_int_disable(bp);
  1382. /* make sure all ISRs are done */
  1383. if (msix) {
  1384. synchronize_irq(bp->msix_table[0].vector);
  1385. offset = 1;
  1386. if (CNIC_SUPPORT(bp))
  1387. offset++;
  1388. for_each_eth_queue(bp, i)
  1389. synchronize_irq(bp->msix_table[offset++].vector);
  1390. } else
  1391. synchronize_irq(bp->pdev->irq);
  1392. /* make sure sp_task is not running */
  1393. cancel_delayed_work(&bp->sp_task);
  1394. cancel_delayed_work(&bp->period_task);
  1395. flush_workqueue(bnx2x_wq);
  1396. }
  1397. /* fast path */
  1398. /*
  1399. * General service functions
  1400. */
  1401. /* Return true if succeeded to acquire the lock */
  1402. static bool bnx2x_trylock_hw_lock(struct bnx2x *bp, u32 resource)
  1403. {
  1404. u32 lock_status;
  1405. u32 resource_bit = (1 << resource);
  1406. int func = BP_FUNC(bp);
  1407. u32 hw_lock_control_reg;
  1408. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1409. "Trying to take a lock on resource %d\n", resource);
  1410. /* Validating that the resource is within range */
  1411. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1412. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1413. "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1414. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1415. return false;
  1416. }
  1417. if (func <= 5)
  1418. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1419. else
  1420. hw_lock_control_reg =
  1421. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1422. /* Try to acquire the lock */
  1423. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1424. lock_status = REG_RD(bp, hw_lock_control_reg);
  1425. if (lock_status & resource_bit)
  1426. return true;
  1427. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1428. "Failed to get a lock on resource %d\n", resource);
  1429. return false;
  1430. }
  1431. /**
  1432. * bnx2x_get_leader_lock_resource - get the recovery leader resource id
  1433. *
  1434. * @bp: driver handle
  1435. *
  1436. * Returns the recovery leader resource id according to the engine this function
  1437. * belongs to. Currently only only 2 engines is supported.
  1438. */
  1439. static int bnx2x_get_leader_lock_resource(struct bnx2x *bp)
  1440. {
  1441. if (BP_PATH(bp))
  1442. return HW_LOCK_RESOURCE_RECOVERY_LEADER_1;
  1443. else
  1444. return HW_LOCK_RESOURCE_RECOVERY_LEADER_0;
  1445. }
  1446. /**
  1447. * bnx2x_trylock_leader_lock- try to acquire a leader lock.
  1448. *
  1449. * @bp: driver handle
  1450. *
  1451. * Tries to acquire a leader lock for current engine.
  1452. */
  1453. static bool bnx2x_trylock_leader_lock(struct bnx2x *bp)
  1454. {
  1455. return bnx2x_trylock_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1456. }
  1457. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err);
  1458. /* schedule the sp task and mark that interrupt occurred (runs from ISR) */
  1459. static int bnx2x_schedule_sp_task(struct bnx2x *bp)
  1460. {
  1461. /* Set the interrupt occurred bit for the sp-task to recognize it
  1462. * must ack the interrupt and transition according to the IGU
  1463. * state machine.
  1464. */
  1465. atomic_set(&bp->interrupt_occurred, 1);
  1466. /* The sp_task must execute only after this bit
  1467. * is set, otherwise we will get out of sync and miss all
  1468. * further interrupts. Hence, the barrier.
  1469. */
  1470. smp_wmb();
  1471. /* schedule sp_task to workqueue */
  1472. return queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
  1473. }
  1474. void bnx2x_sp_event(struct bnx2x_fastpath *fp, union eth_rx_cqe *rr_cqe)
  1475. {
  1476. struct bnx2x *bp = fp->bp;
  1477. int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1478. int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1479. enum bnx2x_queue_cmd drv_cmd = BNX2X_Q_CMD_MAX;
  1480. struct bnx2x_queue_sp_obj *q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  1481. DP(BNX2X_MSG_SP,
  1482. "fp %d cid %d got ramrod #%d state is %x type is %d\n",
  1483. fp->index, cid, command, bp->state,
  1484. rr_cqe->ramrod_cqe.ramrod_type);
  1485. /* If cid is within VF range, replace the slowpath object with the
  1486. * one corresponding to this VF
  1487. */
  1488. if (cid >= BNX2X_FIRST_VF_CID &&
  1489. cid < BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)
  1490. bnx2x_iov_set_queue_sp_obj(bp, cid, &q_obj);
  1491. switch (command) {
  1492. case (RAMROD_CMD_ID_ETH_CLIENT_UPDATE):
  1493. DP(BNX2X_MSG_SP, "got UPDATE ramrod. CID %d\n", cid);
  1494. drv_cmd = BNX2X_Q_CMD_UPDATE;
  1495. break;
  1496. case (RAMROD_CMD_ID_ETH_CLIENT_SETUP):
  1497. DP(BNX2X_MSG_SP, "got MULTI[%d] setup ramrod\n", cid);
  1498. drv_cmd = BNX2X_Q_CMD_SETUP;
  1499. break;
  1500. case (RAMROD_CMD_ID_ETH_TX_QUEUE_SETUP):
  1501. DP(BNX2X_MSG_SP, "got MULTI[%d] tx-only setup ramrod\n", cid);
  1502. drv_cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  1503. break;
  1504. case (RAMROD_CMD_ID_ETH_HALT):
  1505. DP(BNX2X_MSG_SP, "got MULTI[%d] halt ramrod\n", cid);
  1506. drv_cmd = BNX2X_Q_CMD_HALT;
  1507. break;
  1508. case (RAMROD_CMD_ID_ETH_TERMINATE):
  1509. DP(BNX2X_MSG_SP, "got MULTI[%d] teminate ramrod\n", cid);
  1510. drv_cmd = BNX2X_Q_CMD_TERMINATE;
  1511. break;
  1512. case (RAMROD_CMD_ID_ETH_EMPTY):
  1513. DP(BNX2X_MSG_SP, "got MULTI[%d] empty ramrod\n", cid);
  1514. drv_cmd = BNX2X_Q_CMD_EMPTY;
  1515. break;
  1516. default:
  1517. BNX2X_ERR("unexpected MC reply (%d) on fp[%d]\n",
  1518. command, fp->index);
  1519. return;
  1520. }
  1521. if ((drv_cmd != BNX2X_Q_CMD_MAX) &&
  1522. q_obj->complete_cmd(bp, q_obj, drv_cmd))
  1523. /* q_obj->complete_cmd() failure means that this was
  1524. * an unexpected completion.
  1525. *
  1526. * In this case we don't want to increase the bp->spq_left
  1527. * because apparently we haven't sent this command the first
  1528. * place.
  1529. */
  1530. #ifdef BNX2X_STOP_ON_ERROR
  1531. bnx2x_panic();
  1532. #else
  1533. return;
  1534. #endif
  1535. /* SRIOV: reschedule any 'in_progress' operations */
  1536. bnx2x_iov_sp_event(bp, cid, true);
  1537. smp_mb__before_atomic_inc();
  1538. atomic_inc(&bp->cq_spq_left);
  1539. /* push the change in bp->spq_left and towards the memory */
  1540. smp_mb__after_atomic_inc();
  1541. DP(BNX2X_MSG_SP, "bp->cq_spq_left %x\n", atomic_read(&bp->cq_spq_left));
  1542. if ((drv_cmd == BNX2X_Q_CMD_UPDATE) && (IS_FCOE_FP(fp)) &&
  1543. (!!test_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state))) {
  1544. /* if Q update ramrod is completed for last Q in AFEX vif set
  1545. * flow, then ACK MCP at the end
  1546. *
  1547. * mark pending ACK to MCP bit.
  1548. * prevent case that both bits are cleared.
  1549. * At the end of load/unload driver checks that
  1550. * sp_state is cleared, and this order prevents
  1551. * races
  1552. */
  1553. smp_mb__before_clear_bit();
  1554. set_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK, &bp->sp_state);
  1555. wmb();
  1556. clear_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
  1557. smp_mb__after_clear_bit();
  1558. /* schedule the sp task as mcp ack is required */
  1559. bnx2x_schedule_sp_task(bp);
  1560. }
  1561. return;
  1562. }
  1563. irqreturn_t bnx2x_interrupt(int irq, void *dev_instance)
  1564. {
  1565. struct bnx2x *bp = netdev_priv(dev_instance);
  1566. u16 status = bnx2x_ack_int(bp);
  1567. u16 mask;
  1568. int i;
  1569. u8 cos;
  1570. /* Return here if interrupt is shared and it's not for us */
  1571. if (unlikely(status == 0)) {
  1572. DP(NETIF_MSG_INTR, "not our interrupt!\n");
  1573. return IRQ_NONE;
  1574. }
  1575. DP(NETIF_MSG_INTR, "got an interrupt status 0x%x\n", status);
  1576. #ifdef BNX2X_STOP_ON_ERROR
  1577. if (unlikely(bp->panic))
  1578. return IRQ_HANDLED;
  1579. #endif
  1580. for_each_eth_queue(bp, i) {
  1581. struct bnx2x_fastpath *fp = &bp->fp[i];
  1582. mask = 0x2 << (fp->index + CNIC_SUPPORT(bp));
  1583. if (status & mask) {
  1584. /* Handle Rx or Tx according to SB id */
  1585. prefetch(fp->rx_cons_sb);
  1586. for_each_cos_in_tx_queue(fp, cos)
  1587. prefetch(fp->txdata_ptr[cos]->tx_cons_sb);
  1588. prefetch(&fp->sb_running_index[SM_RX_ID]);
  1589. napi_schedule(&bnx2x_fp(bp, fp->index, napi));
  1590. status &= ~mask;
  1591. }
  1592. }
  1593. if (CNIC_SUPPORT(bp)) {
  1594. mask = 0x2;
  1595. if (status & (mask | 0x1)) {
  1596. struct cnic_ops *c_ops = NULL;
  1597. if (likely(bp->state == BNX2X_STATE_OPEN)) {
  1598. rcu_read_lock();
  1599. c_ops = rcu_dereference(bp->cnic_ops);
  1600. if (c_ops)
  1601. c_ops->cnic_handler(bp->cnic_data,
  1602. NULL);
  1603. rcu_read_unlock();
  1604. }
  1605. status &= ~mask;
  1606. }
  1607. }
  1608. if (unlikely(status & 0x1)) {
  1609. /* schedule sp task to perform default status block work, ack
  1610. * attentions and enable interrupts.
  1611. */
  1612. bnx2x_schedule_sp_task(bp);
  1613. status &= ~0x1;
  1614. if (!status)
  1615. return IRQ_HANDLED;
  1616. }
  1617. if (unlikely(status))
  1618. DP(NETIF_MSG_INTR, "got an unknown interrupt! (status 0x%x)\n",
  1619. status);
  1620. return IRQ_HANDLED;
  1621. }
  1622. /* Link */
  1623. /*
  1624. * General service functions
  1625. */
  1626. int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource)
  1627. {
  1628. u32 lock_status;
  1629. u32 resource_bit = (1 << resource);
  1630. int func = BP_FUNC(bp);
  1631. u32 hw_lock_control_reg;
  1632. int cnt;
  1633. /* Validating that the resource is within range */
  1634. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1635. BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1636. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1637. return -EINVAL;
  1638. }
  1639. if (func <= 5) {
  1640. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1641. } else {
  1642. hw_lock_control_reg =
  1643. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1644. }
  1645. /* Validating that the resource is not already taken */
  1646. lock_status = REG_RD(bp, hw_lock_control_reg);
  1647. if (lock_status & resource_bit) {
  1648. BNX2X_ERR("lock_status 0x%x resource_bit 0x%x\n",
  1649. lock_status, resource_bit);
  1650. return -EEXIST;
  1651. }
  1652. /* Try for 5 second every 5ms */
  1653. for (cnt = 0; cnt < 1000; cnt++) {
  1654. /* Try to acquire the lock */
  1655. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1656. lock_status = REG_RD(bp, hw_lock_control_reg);
  1657. if (lock_status & resource_bit)
  1658. return 0;
  1659. msleep(5);
  1660. }
  1661. BNX2X_ERR("Timeout\n");
  1662. return -EAGAIN;
  1663. }
  1664. int bnx2x_release_leader_lock(struct bnx2x *bp)
  1665. {
  1666. return bnx2x_release_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1667. }
  1668. int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource)
  1669. {
  1670. u32 lock_status;
  1671. u32 resource_bit = (1 << resource);
  1672. int func = BP_FUNC(bp);
  1673. u32 hw_lock_control_reg;
  1674. /* Validating that the resource is within range */
  1675. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1676. BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1677. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1678. return -EINVAL;
  1679. }
  1680. if (func <= 5) {
  1681. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1682. } else {
  1683. hw_lock_control_reg =
  1684. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1685. }
  1686. /* Validating that the resource is currently taken */
  1687. lock_status = REG_RD(bp, hw_lock_control_reg);
  1688. if (!(lock_status & resource_bit)) {
  1689. BNX2X_ERR("lock_status 0x%x resource_bit 0x%x. unlock was called but lock wasn't taken!\n",
  1690. lock_status, resource_bit);
  1691. return -EFAULT;
  1692. }
  1693. REG_WR(bp, hw_lock_control_reg, resource_bit);
  1694. return 0;
  1695. }
  1696. int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port)
  1697. {
  1698. /* The GPIO should be swapped if swap register is set and active */
  1699. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1700. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1701. int gpio_shift = gpio_num +
  1702. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1703. u32 gpio_mask = (1 << gpio_shift);
  1704. u32 gpio_reg;
  1705. int value;
  1706. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1707. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1708. return -EINVAL;
  1709. }
  1710. /* read GPIO value */
  1711. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1712. /* get the requested pin value */
  1713. if ((gpio_reg & gpio_mask) == gpio_mask)
  1714. value = 1;
  1715. else
  1716. value = 0;
  1717. DP(NETIF_MSG_LINK, "pin %d value 0x%x\n", gpio_num, value);
  1718. return value;
  1719. }
  1720. int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1721. {
  1722. /* The GPIO should be swapped if swap register is set and active */
  1723. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1724. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1725. int gpio_shift = gpio_num +
  1726. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1727. u32 gpio_mask = (1 << gpio_shift);
  1728. u32 gpio_reg;
  1729. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1730. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1731. return -EINVAL;
  1732. }
  1733. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1734. /* read GPIO and mask except the float bits */
  1735. gpio_reg = (REG_RD(bp, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT);
  1736. switch (mode) {
  1737. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1738. DP(NETIF_MSG_LINK,
  1739. "Set GPIO %d (shift %d) -> output low\n",
  1740. gpio_num, gpio_shift);
  1741. /* clear FLOAT and set CLR */
  1742. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1743. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS);
  1744. break;
  1745. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1746. DP(NETIF_MSG_LINK,
  1747. "Set GPIO %d (shift %d) -> output high\n",
  1748. gpio_num, gpio_shift);
  1749. /* clear FLOAT and set SET */
  1750. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1751. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS);
  1752. break;
  1753. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1754. DP(NETIF_MSG_LINK,
  1755. "Set GPIO %d (shift %d) -> input\n",
  1756. gpio_num, gpio_shift);
  1757. /* set FLOAT */
  1758. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1759. break;
  1760. default:
  1761. break;
  1762. }
  1763. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1764. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1765. return 0;
  1766. }
  1767. int bnx2x_set_mult_gpio(struct bnx2x *bp, u8 pins, u32 mode)
  1768. {
  1769. u32 gpio_reg = 0;
  1770. int rc = 0;
  1771. /* Any port swapping should be handled by caller. */
  1772. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1773. /* read GPIO and mask except the float bits */
  1774. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1775. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1776. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_CLR_POS);
  1777. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_SET_POS);
  1778. switch (mode) {
  1779. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1780. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output low\n", pins);
  1781. /* set CLR */
  1782. gpio_reg |= (pins << MISC_REGISTERS_GPIO_CLR_POS);
  1783. break;
  1784. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1785. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output high\n", pins);
  1786. /* set SET */
  1787. gpio_reg |= (pins << MISC_REGISTERS_GPIO_SET_POS);
  1788. break;
  1789. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1790. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> input\n", pins);
  1791. /* set FLOAT */
  1792. gpio_reg |= (pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1793. break;
  1794. default:
  1795. BNX2X_ERR("Invalid GPIO mode assignment %d\n", mode);
  1796. rc = -EINVAL;
  1797. break;
  1798. }
  1799. if (rc == 0)
  1800. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1801. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1802. return rc;
  1803. }
  1804. int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1805. {
  1806. /* The GPIO should be swapped if swap register is set and active */
  1807. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1808. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1809. int gpio_shift = gpio_num +
  1810. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1811. u32 gpio_mask = (1 << gpio_shift);
  1812. u32 gpio_reg;
  1813. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1814. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1815. return -EINVAL;
  1816. }
  1817. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1818. /* read GPIO int */
  1819. gpio_reg = REG_RD(bp, MISC_REG_GPIO_INT);
  1820. switch (mode) {
  1821. case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR:
  1822. DP(NETIF_MSG_LINK,
  1823. "Clear GPIO INT %d (shift %d) -> output low\n",
  1824. gpio_num, gpio_shift);
  1825. /* clear SET and set CLR */
  1826. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1827. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1828. break;
  1829. case MISC_REGISTERS_GPIO_INT_OUTPUT_SET:
  1830. DP(NETIF_MSG_LINK,
  1831. "Set GPIO INT %d (shift %d) -> output high\n",
  1832. gpio_num, gpio_shift);
  1833. /* clear CLR and set SET */
  1834. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1835. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1836. break;
  1837. default:
  1838. break;
  1839. }
  1840. REG_WR(bp, MISC_REG_GPIO_INT, gpio_reg);
  1841. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1842. return 0;
  1843. }
  1844. static int bnx2x_set_spio(struct bnx2x *bp, int spio, u32 mode)
  1845. {
  1846. u32 spio_reg;
  1847. /* Only 2 SPIOs are configurable */
  1848. if ((spio != MISC_SPIO_SPIO4) && (spio != MISC_SPIO_SPIO5)) {
  1849. BNX2X_ERR("Invalid SPIO 0x%x\n", spio);
  1850. return -EINVAL;
  1851. }
  1852. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1853. /* read SPIO and mask except the float bits */
  1854. spio_reg = (REG_RD(bp, MISC_REG_SPIO) & MISC_SPIO_FLOAT);
  1855. switch (mode) {
  1856. case MISC_SPIO_OUTPUT_LOW:
  1857. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output low\n", spio);
  1858. /* clear FLOAT and set CLR */
  1859. spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
  1860. spio_reg |= (spio << MISC_SPIO_CLR_POS);
  1861. break;
  1862. case MISC_SPIO_OUTPUT_HIGH:
  1863. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output high\n", spio);
  1864. /* clear FLOAT and set SET */
  1865. spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
  1866. spio_reg |= (spio << MISC_SPIO_SET_POS);
  1867. break;
  1868. case MISC_SPIO_INPUT_HI_Z:
  1869. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> input\n", spio);
  1870. /* set FLOAT */
  1871. spio_reg |= (spio << MISC_SPIO_FLOAT_POS);
  1872. break;
  1873. default:
  1874. break;
  1875. }
  1876. REG_WR(bp, MISC_REG_SPIO, spio_reg);
  1877. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1878. return 0;
  1879. }
  1880. void bnx2x_calc_fc_adv(struct bnx2x *bp)
  1881. {
  1882. u8 cfg_idx = bnx2x_get_link_cfg_idx(bp);
  1883. switch (bp->link_vars.ieee_fc &
  1884. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) {
  1885. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE:
  1886. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1887. ADVERTISED_Pause);
  1888. break;
  1889. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH:
  1890. bp->port.advertising[cfg_idx] |= (ADVERTISED_Asym_Pause |
  1891. ADVERTISED_Pause);
  1892. break;
  1893. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC:
  1894. bp->port.advertising[cfg_idx] |= ADVERTISED_Asym_Pause;
  1895. break;
  1896. default:
  1897. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1898. ADVERTISED_Pause);
  1899. break;
  1900. }
  1901. }
  1902. static void bnx2x_set_requested_fc(struct bnx2x *bp)
  1903. {
  1904. /* Initialize link parameters structure variables
  1905. * It is recommended to turn off RX FC for jumbo frames
  1906. * for better performance
  1907. */
  1908. if (CHIP_IS_E1x(bp) && (bp->dev->mtu > 5000))
  1909. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_TX;
  1910. else
  1911. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH;
  1912. }
  1913. int bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode)
  1914. {
  1915. int rc, cfx_idx = bnx2x_get_link_cfg_idx(bp);
  1916. u16 req_line_speed = bp->link_params.req_line_speed[cfx_idx];
  1917. if (!BP_NOMCP(bp)) {
  1918. bnx2x_set_requested_fc(bp);
  1919. bnx2x_acquire_phy_lock(bp);
  1920. if (load_mode == LOAD_DIAG) {
  1921. struct link_params *lp = &bp->link_params;
  1922. lp->loopback_mode = LOOPBACK_XGXS;
  1923. /* do PHY loopback at 10G speed, if possible */
  1924. if (lp->req_line_speed[cfx_idx] < SPEED_10000) {
  1925. if (lp->speed_cap_mask[cfx_idx] &
  1926. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
  1927. lp->req_line_speed[cfx_idx] =
  1928. SPEED_10000;
  1929. else
  1930. lp->req_line_speed[cfx_idx] =
  1931. SPEED_1000;
  1932. }
  1933. }
  1934. if (load_mode == LOAD_LOOPBACK_EXT) {
  1935. struct link_params *lp = &bp->link_params;
  1936. lp->loopback_mode = LOOPBACK_EXT;
  1937. }
  1938. rc = bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  1939. bnx2x_release_phy_lock(bp);
  1940. bnx2x_calc_fc_adv(bp);
  1941. if (bp->link_vars.link_up) {
  1942. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  1943. bnx2x_link_report(bp);
  1944. }
  1945. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  1946. bp->link_params.req_line_speed[cfx_idx] = req_line_speed;
  1947. return rc;
  1948. }
  1949. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  1950. return -EINVAL;
  1951. }
  1952. void bnx2x_link_set(struct bnx2x *bp)
  1953. {
  1954. if (!BP_NOMCP(bp)) {
  1955. bnx2x_acquire_phy_lock(bp);
  1956. bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  1957. bnx2x_release_phy_lock(bp);
  1958. bnx2x_calc_fc_adv(bp);
  1959. } else
  1960. BNX2X_ERR("Bootcode is missing - can not set link\n");
  1961. }
  1962. static void bnx2x__link_reset(struct bnx2x *bp)
  1963. {
  1964. if (!BP_NOMCP(bp)) {
  1965. bnx2x_acquire_phy_lock(bp);
  1966. bnx2x_lfa_reset(&bp->link_params, &bp->link_vars);
  1967. bnx2x_release_phy_lock(bp);
  1968. } else
  1969. BNX2X_ERR("Bootcode is missing - can not reset link\n");
  1970. }
  1971. void bnx2x_force_link_reset(struct bnx2x *bp)
  1972. {
  1973. bnx2x_acquire_phy_lock(bp);
  1974. bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
  1975. bnx2x_release_phy_lock(bp);
  1976. }
  1977. u8 bnx2x_link_test(struct bnx2x *bp, u8 is_serdes)
  1978. {
  1979. u8 rc = 0;
  1980. if (!BP_NOMCP(bp)) {
  1981. bnx2x_acquire_phy_lock(bp);
  1982. rc = bnx2x_test_link(&bp->link_params, &bp->link_vars,
  1983. is_serdes);
  1984. bnx2x_release_phy_lock(bp);
  1985. } else
  1986. BNX2X_ERR("Bootcode is missing - can not test link\n");
  1987. return rc;
  1988. }
  1989. /* Calculates the sum of vn_min_rates.
  1990. It's needed for further normalizing of the min_rates.
  1991. Returns:
  1992. sum of vn_min_rates.
  1993. or
  1994. 0 - if all the min_rates are 0.
  1995. In the later case fainess algorithm should be deactivated.
  1996. If not all min_rates are zero then those that are zeroes will be set to 1.
  1997. */
  1998. static void bnx2x_calc_vn_min(struct bnx2x *bp,
  1999. struct cmng_init_input *input)
  2000. {
  2001. int all_zero = 1;
  2002. int vn;
  2003. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2004. u32 vn_cfg = bp->mf_config[vn];
  2005. u32 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
  2006. FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
  2007. /* Skip hidden vns */
  2008. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  2009. vn_min_rate = 0;
  2010. /* If min rate is zero - set it to 1 */
  2011. else if (!vn_min_rate)
  2012. vn_min_rate = DEF_MIN_RATE;
  2013. else
  2014. all_zero = 0;
  2015. input->vnic_min_rate[vn] = vn_min_rate;
  2016. }
  2017. /* if ETS or all min rates are zeros - disable fairness */
  2018. if (BNX2X_IS_ETS_ENABLED(bp)) {
  2019. input->flags.cmng_enables &=
  2020. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2021. DP(NETIF_MSG_IFUP, "Fairness will be disabled due to ETS\n");
  2022. } else if (all_zero) {
  2023. input->flags.cmng_enables &=
  2024. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2025. DP(NETIF_MSG_IFUP,
  2026. "All MIN values are zeroes fairness will be disabled\n");
  2027. } else
  2028. input->flags.cmng_enables |=
  2029. CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2030. }
  2031. static void bnx2x_calc_vn_max(struct bnx2x *bp, int vn,
  2032. struct cmng_init_input *input)
  2033. {
  2034. u16 vn_max_rate;
  2035. u32 vn_cfg = bp->mf_config[vn];
  2036. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  2037. vn_max_rate = 0;
  2038. else {
  2039. u32 maxCfg = bnx2x_extract_max_cfg(bp, vn_cfg);
  2040. if (IS_MF_SI(bp)) {
  2041. /* maxCfg in percents of linkspeed */
  2042. vn_max_rate = (bp->link_vars.line_speed * maxCfg) / 100;
  2043. } else /* SD modes */
  2044. /* maxCfg is absolute in 100Mb units */
  2045. vn_max_rate = maxCfg * 100;
  2046. }
  2047. DP(NETIF_MSG_IFUP, "vn %d: vn_max_rate %d\n", vn, vn_max_rate);
  2048. input->vnic_max_rate[vn] = vn_max_rate;
  2049. }
  2050. static int bnx2x_get_cmng_fns_mode(struct bnx2x *bp)
  2051. {
  2052. if (CHIP_REV_IS_SLOW(bp))
  2053. return CMNG_FNS_NONE;
  2054. if (IS_MF(bp))
  2055. return CMNG_FNS_MINMAX;
  2056. return CMNG_FNS_NONE;
  2057. }
  2058. void bnx2x_read_mf_cfg(struct bnx2x *bp)
  2059. {
  2060. int vn, n = (CHIP_MODE_IS_4_PORT(bp) ? 2 : 1);
  2061. if (BP_NOMCP(bp))
  2062. return; /* what should be the default bvalue in this case */
  2063. /* For 2 port configuration the absolute function number formula
  2064. * is:
  2065. * abs_func = 2 * vn + BP_PORT + BP_PATH
  2066. *
  2067. * and there are 4 functions per port
  2068. *
  2069. * For 4 port configuration it is
  2070. * abs_func = 4 * vn + 2 * BP_PORT + BP_PATH
  2071. *
  2072. * and there are 2 functions per port
  2073. */
  2074. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2075. int /*abs*/func = n * (2 * vn + BP_PORT(bp)) + BP_PATH(bp);
  2076. if (func >= E1H_FUNC_MAX)
  2077. break;
  2078. bp->mf_config[vn] =
  2079. MF_CFG_RD(bp, func_mf_config[func].config);
  2080. }
  2081. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  2082. DP(NETIF_MSG_IFUP, "mf_cfg function disabled\n");
  2083. bp->flags |= MF_FUNC_DIS;
  2084. } else {
  2085. DP(NETIF_MSG_IFUP, "mf_cfg function enabled\n");
  2086. bp->flags &= ~MF_FUNC_DIS;
  2087. }
  2088. }
  2089. static void bnx2x_cmng_fns_init(struct bnx2x *bp, u8 read_cfg, u8 cmng_type)
  2090. {
  2091. struct cmng_init_input input;
  2092. memset(&input, 0, sizeof(struct cmng_init_input));
  2093. input.port_rate = bp->link_vars.line_speed;
  2094. if (cmng_type == CMNG_FNS_MINMAX) {
  2095. int vn;
  2096. /* read mf conf from shmem */
  2097. if (read_cfg)
  2098. bnx2x_read_mf_cfg(bp);
  2099. /* vn_weight_sum and enable fairness if not 0 */
  2100. bnx2x_calc_vn_min(bp, &input);
  2101. /* calculate and set min-max rate for each vn */
  2102. if (bp->port.pmf)
  2103. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++)
  2104. bnx2x_calc_vn_max(bp, vn, &input);
  2105. /* always enable rate shaping and fairness */
  2106. input.flags.cmng_enables |=
  2107. CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN;
  2108. bnx2x_init_cmng(&input, &bp->cmng);
  2109. return;
  2110. }
  2111. /* rate shaping and fairness are disabled */
  2112. DP(NETIF_MSG_IFUP,
  2113. "rate shaping and fairness are disabled\n");
  2114. }
  2115. static void storm_memset_cmng(struct bnx2x *bp,
  2116. struct cmng_init *cmng,
  2117. u8 port)
  2118. {
  2119. int vn;
  2120. size_t size = sizeof(struct cmng_struct_per_port);
  2121. u32 addr = BAR_XSTRORM_INTMEM +
  2122. XSTORM_CMNG_PER_PORT_VARS_OFFSET(port);
  2123. __storm_memset_struct(bp, addr, size, (u32 *)&cmng->port);
  2124. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2125. int func = func_by_vn(bp, vn);
  2126. addr = BAR_XSTRORM_INTMEM +
  2127. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func);
  2128. size = sizeof(struct rate_shaping_vars_per_vn);
  2129. __storm_memset_struct(bp, addr, size,
  2130. (u32 *)&cmng->vnic.vnic_max_rate[vn]);
  2131. addr = BAR_XSTRORM_INTMEM +
  2132. XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func);
  2133. size = sizeof(struct fairness_vars_per_vn);
  2134. __storm_memset_struct(bp, addr, size,
  2135. (u32 *)&cmng->vnic.vnic_min_rate[vn]);
  2136. }
  2137. }
  2138. /* This function is called upon link interrupt */
  2139. static void bnx2x_link_attn(struct bnx2x *bp)
  2140. {
  2141. /* Make sure that we are synced with the current statistics */
  2142. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2143. bnx2x_link_update(&bp->link_params, &bp->link_vars);
  2144. if (bp->link_vars.link_up) {
  2145. /* dropless flow control */
  2146. if (!CHIP_IS_E1(bp) && bp->dropless_fc) {
  2147. int port = BP_PORT(bp);
  2148. u32 pause_enabled = 0;
  2149. if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX)
  2150. pause_enabled = 1;
  2151. REG_WR(bp, BAR_USTRORM_INTMEM +
  2152. USTORM_ETH_PAUSE_ENABLED_OFFSET(port),
  2153. pause_enabled);
  2154. }
  2155. if (bp->link_vars.mac_type != MAC_TYPE_EMAC) {
  2156. struct host_port_stats *pstats;
  2157. pstats = bnx2x_sp(bp, port_stats);
  2158. /* reset old mac stats */
  2159. memset(&(pstats->mac_stx[0]), 0,
  2160. sizeof(struct mac_stx));
  2161. }
  2162. if (bp->state == BNX2X_STATE_OPEN)
  2163. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2164. }
  2165. if (bp->link_vars.link_up && bp->link_vars.line_speed) {
  2166. int cmng_fns = bnx2x_get_cmng_fns_mode(bp);
  2167. if (cmng_fns != CMNG_FNS_NONE) {
  2168. bnx2x_cmng_fns_init(bp, false, cmng_fns);
  2169. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2170. } else
  2171. /* rate shaping and fairness are disabled */
  2172. DP(NETIF_MSG_IFUP,
  2173. "single function mode without fairness\n");
  2174. }
  2175. __bnx2x_link_report(bp);
  2176. if (IS_MF(bp))
  2177. bnx2x_link_sync_notify(bp);
  2178. }
  2179. void bnx2x__link_status_update(struct bnx2x *bp)
  2180. {
  2181. if (bp->state != BNX2X_STATE_OPEN)
  2182. return;
  2183. /* read updated dcb configuration */
  2184. if (IS_PF(bp)) {
  2185. bnx2x_dcbx_pmf_update(bp);
  2186. bnx2x_link_status_update(&bp->link_params, &bp->link_vars);
  2187. if (bp->link_vars.link_up)
  2188. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2189. else
  2190. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2191. /* indicate link status */
  2192. bnx2x_link_report(bp);
  2193. } else { /* VF */
  2194. bp->port.supported[0] |= (SUPPORTED_10baseT_Half |
  2195. SUPPORTED_10baseT_Full |
  2196. SUPPORTED_100baseT_Half |
  2197. SUPPORTED_100baseT_Full |
  2198. SUPPORTED_1000baseT_Full |
  2199. SUPPORTED_2500baseX_Full |
  2200. SUPPORTED_10000baseT_Full |
  2201. SUPPORTED_TP |
  2202. SUPPORTED_FIBRE |
  2203. SUPPORTED_Autoneg |
  2204. SUPPORTED_Pause |
  2205. SUPPORTED_Asym_Pause);
  2206. bp->port.advertising[0] = bp->port.supported[0];
  2207. bp->link_params.bp = bp;
  2208. bp->link_params.port = BP_PORT(bp);
  2209. bp->link_params.req_duplex[0] = DUPLEX_FULL;
  2210. bp->link_params.req_flow_ctrl[0] = BNX2X_FLOW_CTRL_NONE;
  2211. bp->link_params.req_line_speed[0] = SPEED_10000;
  2212. bp->link_params.speed_cap_mask[0] = 0x7f0000;
  2213. bp->link_params.switch_cfg = SWITCH_CFG_10G;
  2214. bp->link_vars.mac_type = MAC_TYPE_BMAC;
  2215. bp->link_vars.line_speed = SPEED_10000;
  2216. bp->link_vars.link_status =
  2217. (LINK_STATUS_LINK_UP |
  2218. LINK_STATUS_SPEED_AND_DUPLEX_10GTFD);
  2219. bp->link_vars.link_up = 1;
  2220. bp->link_vars.duplex = DUPLEX_FULL;
  2221. bp->link_vars.flow_ctrl = BNX2X_FLOW_CTRL_NONE;
  2222. __bnx2x_link_report(bp);
  2223. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2224. }
  2225. }
  2226. static int bnx2x_afex_func_update(struct bnx2x *bp, u16 vifid,
  2227. u16 vlan_val, u8 allowed_prio)
  2228. {
  2229. struct bnx2x_func_state_params func_params = {0};
  2230. struct bnx2x_func_afex_update_params *f_update_params =
  2231. &func_params.params.afex_update;
  2232. func_params.f_obj = &bp->func_obj;
  2233. func_params.cmd = BNX2X_F_CMD_AFEX_UPDATE;
  2234. /* no need to wait for RAMROD completion, so don't
  2235. * set RAMROD_COMP_WAIT flag
  2236. */
  2237. f_update_params->vif_id = vifid;
  2238. f_update_params->afex_default_vlan = vlan_val;
  2239. f_update_params->allowed_priorities = allowed_prio;
  2240. /* if ramrod can not be sent, response to MCP immediately */
  2241. if (bnx2x_func_state_change(bp, &func_params) < 0)
  2242. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  2243. return 0;
  2244. }
  2245. static int bnx2x_afex_handle_vif_list_cmd(struct bnx2x *bp, u8 cmd_type,
  2246. u16 vif_index, u8 func_bit_map)
  2247. {
  2248. struct bnx2x_func_state_params func_params = {0};
  2249. struct bnx2x_func_afex_viflists_params *update_params =
  2250. &func_params.params.afex_viflists;
  2251. int rc;
  2252. u32 drv_msg_code;
  2253. /* validate only LIST_SET and LIST_GET are received from switch */
  2254. if ((cmd_type != VIF_LIST_RULE_GET) && (cmd_type != VIF_LIST_RULE_SET))
  2255. BNX2X_ERR("BUG! afex_handle_vif_list_cmd invalid type 0x%x\n",
  2256. cmd_type);
  2257. func_params.f_obj = &bp->func_obj;
  2258. func_params.cmd = BNX2X_F_CMD_AFEX_VIFLISTS;
  2259. /* set parameters according to cmd_type */
  2260. update_params->afex_vif_list_command = cmd_type;
  2261. update_params->vif_list_index = cpu_to_le16(vif_index);
  2262. update_params->func_bit_map =
  2263. (cmd_type == VIF_LIST_RULE_GET) ? 0 : func_bit_map;
  2264. update_params->func_to_clear = 0;
  2265. drv_msg_code =
  2266. (cmd_type == VIF_LIST_RULE_GET) ?
  2267. DRV_MSG_CODE_AFEX_LISTGET_ACK :
  2268. DRV_MSG_CODE_AFEX_LISTSET_ACK;
  2269. /* if ramrod can not be sent, respond to MCP immediately for
  2270. * SET and GET requests (other are not triggered from MCP)
  2271. */
  2272. rc = bnx2x_func_state_change(bp, &func_params);
  2273. if (rc < 0)
  2274. bnx2x_fw_command(bp, drv_msg_code, 0);
  2275. return 0;
  2276. }
  2277. static void bnx2x_handle_afex_cmd(struct bnx2x *bp, u32 cmd)
  2278. {
  2279. struct afex_stats afex_stats;
  2280. u32 func = BP_ABS_FUNC(bp);
  2281. u32 mf_config;
  2282. u16 vlan_val;
  2283. u32 vlan_prio;
  2284. u16 vif_id;
  2285. u8 allowed_prio;
  2286. u8 vlan_mode;
  2287. u32 addr_to_write, vifid, addrs, stats_type, i;
  2288. if (cmd & DRV_STATUS_AFEX_LISTGET_REQ) {
  2289. vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2290. DP(BNX2X_MSG_MCP,
  2291. "afex: got MCP req LISTGET_REQ for vifid 0x%x\n", vifid);
  2292. bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_GET, vifid, 0);
  2293. }
  2294. if (cmd & DRV_STATUS_AFEX_LISTSET_REQ) {
  2295. vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2296. addrs = SHMEM2_RD(bp, afex_param2_to_driver[BP_FW_MB_IDX(bp)]);
  2297. DP(BNX2X_MSG_MCP,
  2298. "afex: got MCP req LISTSET_REQ for vifid 0x%x addrs 0x%x\n",
  2299. vifid, addrs);
  2300. bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_SET, vifid,
  2301. addrs);
  2302. }
  2303. if (cmd & DRV_STATUS_AFEX_STATSGET_REQ) {
  2304. addr_to_write = SHMEM2_RD(bp,
  2305. afex_scratchpad_addr_to_write[BP_FW_MB_IDX(bp)]);
  2306. stats_type = SHMEM2_RD(bp,
  2307. afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2308. DP(BNX2X_MSG_MCP,
  2309. "afex: got MCP req STATSGET_REQ, write to addr 0x%x\n",
  2310. addr_to_write);
  2311. bnx2x_afex_collect_stats(bp, (void *)&afex_stats, stats_type);
  2312. /* write response to scratchpad, for MCP */
  2313. for (i = 0; i < (sizeof(struct afex_stats)/sizeof(u32)); i++)
  2314. REG_WR(bp, addr_to_write + i*sizeof(u32),
  2315. *(((u32 *)(&afex_stats))+i));
  2316. /* send ack message to MCP */
  2317. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_STATSGET_ACK, 0);
  2318. }
  2319. if (cmd & DRV_STATUS_AFEX_VIFSET_REQ) {
  2320. mf_config = MF_CFG_RD(bp, func_mf_config[func].config);
  2321. bp->mf_config[BP_VN(bp)] = mf_config;
  2322. DP(BNX2X_MSG_MCP,
  2323. "afex: got MCP req VIFSET_REQ, mf_config 0x%x\n",
  2324. mf_config);
  2325. /* if VIF_SET is "enabled" */
  2326. if (!(mf_config & FUNC_MF_CFG_FUNC_DISABLED)) {
  2327. /* set rate limit directly to internal RAM */
  2328. struct cmng_init_input cmng_input;
  2329. struct rate_shaping_vars_per_vn m_rs_vn;
  2330. size_t size = sizeof(struct rate_shaping_vars_per_vn);
  2331. u32 addr = BAR_XSTRORM_INTMEM +
  2332. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(BP_FUNC(bp));
  2333. bp->mf_config[BP_VN(bp)] = mf_config;
  2334. bnx2x_calc_vn_max(bp, BP_VN(bp), &cmng_input);
  2335. m_rs_vn.vn_counter.rate =
  2336. cmng_input.vnic_max_rate[BP_VN(bp)];
  2337. m_rs_vn.vn_counter.quota =
  2338. (m_rs_vn.vn_counter.rate *
  2339. RS_PERIODIC_TIMEOUT_USEC) / 8;
  2340. __storm_memset_struct(bp, addr, size, (u32 *)&m_rs_vn);
  2341. /* read relevant values from mf_cfg struct in shmem */
  2342. vif_id =
  2343. (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2344. FUNC_MF_CFG_E1HOV_TAG_MASK) >>
  2345. FUNC_MF_CFG_E1HOV_TAG_SHIFT;
  2346. vlan_val =
  2347. (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2348. FUNC_MF_CFG_AFEX_VLAN_MASK) >>
  2349. FUNC_MF_CFG_AFEX_VLAN_SHIFT;
  2350. vlan_prio = (mf_config &
  2351. FUNC_MF_CFG_TRANSMIT_PRIORITY_MASK) >>
  2352. FUNC_MF_CFG_TRANSMIT_PRIORITY_SHIFT;
  2353. vlan_val |= (vlan_prio << VLAN_PRIO_SHIFT);
  2354. vlan_mode =
  2355. (MF_CFG_RD(bp,
  2356. func_mf_config[func].afex_config) &
  2357. FUNC_MF_CFG_AFEX_VLAN_MODE_MASK) >>
  2358. FUNC_MF_CFG_AFEX_VLAN_MODE_SHIFT;
  2359. allowed_prio =
  2360. (MF_CFG_RD(bp,
  2361. func_mf_config[func].afex_config) &
  2362. FUNC_MF_CFG_AFEX_COS_FILTER_MASK) >>
  2363. FUNC_MF_CFG_AFEX_COS_FILTER_SHIFT;
  2364. /* send ramrod to FW, return in case of failure */
  2365. if (bnx2x_afex_func_update(bp, vif_id, vlan_val,
  2366. allowed_prio))
  2367. return;
  2368. bp->afex_def_vlan_tag = vlan_val;
  2369. bp->afex_vlan_mode = vlan_mode;
  2370. } else {
  2371. /* notify link down because BP->flags is disabled */
  2372. bnx2x_link_report(bp);
  2373. /* send INVALID VIF ramrod to FW */
  2374. bnx2x_afex_func_update(bp, 0xFFFF, 0, 0);
  2375. /* Reset the default afex VLAN */
  2376. bp->afex_def_vlan_tag = -1;
  2377. }
  2378. }
  2379. }
  2380. static void bnx2x_pmf_update(struct bnx2x *bp)
  2381. {
  2382. int port = BP_PORT(bp);
  2383. u32 val;
  2384. bp->port.pmf = 1;
  2385. DP(BNX2X_MSG_MCP, "pmf %d\n", bp->port.pmf);
  2386. /*
  2387. * We need the mb() to ensure the ordering between the writing to
  2388. * bp->port.pmf here and reading it from the bnx2x_periodic_task().
  2389. */
  2390. smp_mb();
  2391. /* queue a periodic task */
  2392. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  2393. bnx2x_dcbx_pmf_update(bp);
  2394. /* enable nig attention */
  2395. val = (0xff0f | (1 << (BP_VN(bp) + 4)));
  2396. if (bp->common.int_block == INT_BLOCK_HC) {
  2397. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  2398. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  2399. } else if (!CHIP_IS_E1x(bp)) {
  2400. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  2401. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  2402. }
  2403. bnx2x_stats_handle(bp, STATS_EVENT_PMF);
  2404. }
  2405. /* end of Link */
  2406. /* slow path */
  2407. /*
  2408. * General service functions
  2409. */
  2410. /* send the MCP a request, block until there is a reply */
  2411. u32 bnx2x_fw_command(struct bnx2x *bp, u32 command, u32 param)
  2412. {
  2413. int mb_idx = BP_FW_MB_IDX(bp);
  2414. u32 seq;
  2415. u32 rc = 0;
  2416. u32 cnt = 1;
  2417. u8 delay = CHIP_REV_IS_SLOW(bp) ? 100 : 10;
  2418. mutex_lock(&bp->fw_mb_mutex);
  2419. seq = ++bp->fw_seq;
  2420. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_param, param);
  2421. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_header, (command | seq));
  2422. DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB param 0x%08x\n",
  2423. (command | seq), param);
  2424. do {
  2425. /* let the FW do it's magic ... */
  2426. msleep(delay);
  2427. rc = SHMEM_RD(bp, func_mb[mb_idx].fw_mb_header);
  2428. /* Give the FW up to 5 second (500*10ms) */
  2429. } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500));
  2430. DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n",
  2431. cnt*delay, rc, seq);
  2432. /* is this a reply to our command? */
  2433. if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK))
  2434. rc &= FW_MSG_CODE_MASK;
  2435. else {
  2436. /* FW BUG! */
  2437. BNX2X_ERR("FW failed to respond!\n");
  2438. bnx2x_fw_dump(bp);
  2439. rc = 0;
  2440. }
  2441. mutex_unlock(&bp->fw_mb_mutex);
  2442. return rc;
  2443. }
  2444. static void storm_memset_func_cfg(struct bnx2x *bp,
  2445. struct tstorm_eth_function_common_config *tcfg,
  2446. u16 abs_fid)
  2447. {
  2448. size_t size = sizeof(struct tstorm_eth_function_common_config);
  2449. u32 addr = BAR_TSTRORM_INTMEM +
  2450. TSTORM_FUNCTION_COMMON_CONFIG_OFFSET(abs_fid);
  2451. __storm_memset_struct(bp, addr, size, (u32 *)tcfg);
  2452. }
  2453. void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p)
  2454. {
  2455. if (CHIP_IS_E1x(bp)) {
  2456. struct tstorm_eth_function_common_config tcfg = {0};
  2457. storm_memset_func_cfg(bp, &tcfg, p->func_id);
  2458. }
  2459. /* Enable the function in the FW */
  2460. storm_memset_vf_to_pf(bp, p->func_id, p->pf_id);
  2461. storm_memset_func_en(bp, p->func_id, 1);
  2462. /* spq */
  2463. if (p->func_flgs & FUNC_FLG_SPQ) {
  2464. storm_memset_spq_addr(bp, p->spq_map, p->func_id);
  2465. REG_WR(bp, XSEM_REG_FAST_MEMORY +
  2466. XSTORM_SPQ_PROD_OFFSET(p->func_id), p->spq_prod);
  2467. }
  2468. }
  2469. /**
  2470. * bnx2x_get_tx_only_flags - Return common flags
  2471. *
  2472. * @bp device handle
  2473. * @fp queue handle
  2474. * @zero_stats TRUE if statistics zeroing is needed
  2475. *
  2476. * Return the flags that are common for the Tx-only and not normal connections.
  2477. */
  2478. static unsigned long bnx2x_get_common_flags(struct bnx2x *bp,
  2479. struct bnx2x_fastpath *fp,
  2480. bool zero_stats)
  2481. {
  2482. unsigned long flags = 0;
  2483. /* PF driver will always initialize the Queue to an ACTIVE state */
  2484. __set_bit(BNX2X_Q_FLG_ACTIVE, &flags);
  2485. /* tx only connections collect statistics (on the same index as the
  2486. * parent connection). The statistics are zeroed when the parent
  2487. * connection is initialized.
  2488. */
  2489. __set_bit(BNX2X_Q_FLG_STATS, &flags);
  2490. if (zero_stats)
  2491. __set_bit(BNX2X_Q_FLG_ZERO_STATS, &flags);
  2492. #ifdef BNX2X_STOP_ON_ERROR
  2493. __set_bit(BNX2X_Q_FLG_TX_SEC, &flags);
  2494. #endif
  2495. return flags;
  2496. }
  2497. static unsigned long bnx2x_get_q_flags(struct bnx2x *bp,
  2498. struct bnx2x_fastpath *fp,
  2499. bool leading)
  2500. {
  2501. unsigned long flags = 0;
  2502. /* calculate other queue flags */
  2503. if (IS_MF_SD(bp))
  2504. __set_bit(BNX2X_Q_FLG_OV, &flags);
  2505. if (IS_FCOE_FP(fp)) {
  2506. __set_bit(BNX2X_Q_FLG_FCOE, &flags);
  2507. /* For FCoE - force usage of default priority (for afex) */
  2508. __set_bit(BNX2X_Q_FLG_FORCE_DEFAULT_PRI, &flags);
  2509. }
  2510. if (!fp->disable_tpa) {
  2511. __set_bit(BNX2X_Q_FLG_TPA, &flags);
  2512. __set_bit(BNX2X_Q_FLG_TPA_IPV6, &flags);
  2513. if (fp->mode == TPA_MODE_GRO)
  2514. __set_bit(BNX2X_Q_FLG_TPA_GRO, &flags);
  2515. }
  2516. if (leading) {
  2517. __set_bit(BNX2X_Q_FLG_LEADING_RSS, &flags);
  2518. __set_bit(BNX2X_Q_FLG_MCAST, &flags);
  2519. }
  2520. /* Always set HW VLAN stripping */
  2521. __set_bit(BNX2X_Q_FLG_VLAN, &flags);
  2522. /* configure silent vlan removal */
  2523. if (IS_MF_AFEX(bp))
  2524. __set_bit(BNX2X_Q_FLG_SILENT_VLAN_REM, &flags);
  2525. return flags | bnx2x_get_common_flags(bp, fp, true);
  2526. }
  2527. static void bnx2x_pf_q_prep_general(struct bnx2x *bp,
  2528. struct bnx2x_fastpath *fp, struct bnx2x_general_setup_params *gen_init,
  2529. u8 cos)
  2530. {
  2531. gen_init->stat_id = bnx2x_stats_id(fp);
  2532. gen_init->spcl_id = fp->cl_id;
  2533. /* Always use mini-jumbo MTU for FCoE L2 ring */
  2534. if (IS_FCOE_FP(fp))
  2535. gen_init->mtu = BNX2X_FCOE_MINI_JUMBO_MTU;
  2536. else
  2537. gen_init->mtu = bp->dev->mtu;
  2538. gen_init->cos = cos;
  2539. }
  2540. static void bnx2x_pf_rx_q_prep(struct bnx2x *bp,
  2541. struct bnx2x_fastpath *fp, struct rxq_pause_params *pause,
  2542. struct bnx2x_rxq_setup_params *rxq_init)
  2543. {
  2544. u8 max_sge = 0;
  2545. u16 sge_sz = 0;
  2546. u16 tpa_agg_size = 0;
  2547. if (!fp->disable_tpa) {
  2548. pause->sge_th_lo = SGE_TH_LO(bp);
  2549. pause->sge_th_hi = SGE_TH_HI(bp);
  2550. /* validate SGE ring has enough to cross high threshold */
  2551. WARN_ON(bp->dropless_fc &&
  2552. pause->sge_th_hi + FW_PREFETCH_CNT >
  2553. MAX_RX_SGE_CNT * NUM_RX_SGE_PAGES);
  2554. tpa_agg_size = TPA_AGG_SIZE;
  2555. max_sge = SGE_PAGE_ALIGN(bp->dev->mtu) >>
  2556. SGE_PAGE_SHIFT;
  2557. max_sge = ((max_sge + PAGES_PER_SGE - 1) &
  2558. (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
  2559. sge_sz = (u16)min_t(u32, SGE_PAGES, 0xffff);
  2560. }
  2561. /* pause - not for e1 */
  2562. if (!CHIP_IS_E1(bp)) {
  2563. pause->bd_th_lo = BD_TH_LO(bp);
  2564. pause->bd_th_hi = BD_TH_HI(bp);
  2565. pause->rcq_th_lo = RCQ_TH_LO(bp);
  2566. pause->rcq_th_hi = RCQ_TH_HI(bp);
  2567. /*
  2568. * validate that rings have enough entries to cross
  2569. * high thresholds
  2570. */
  2571. WARN_ON(bp->dropless_fc &&
  2572. pause->bd_th_hi + FW_PREFETCH_CNT >
  2573. bp->rx_ring_size);
  2574. WARN_ON(bp->dropless_fc &&
  2575. pause->rcq_th_hi + FW_PREFETCH_CNT >
  2576. NUM_RCQ_RINGS * MAX_RCQ_DESC_CNT);
  2577. pause->pri_map = 1;
  2578. }
  2579. /* rxq setup */
  2580. rxq_init->dscr_map = fp->rx_desc_mapping;
  2581. rxq_init->sge_map = fp->rx_sge_mapping;
  2582. rxq_init->rcq_map = fp->rx_comp_mapping;
  2583. rxq_init->rcq_np_map = fp->rx_comp_mapping + BCM_PAGE_SIZE;
  2584. /* This should be a maximum number of data bytes that may be
  2585. * placed on the BD (not including paddings).
  2586. */
  2587. rxq_init->buf_sz = fp->rx_buf_size - BNX2X_FW_RX_ALIGN_START -
  2588. BNX2X_FW_RX_ALIGN_END - IP_HEADER_ALIGNMENT_PADDING;
  2589. rxq_init->cl_qzone_id = fp->cl_qzone_id;
  2590. rxq_init->tpa_agg_sz = tpa_agg_size;
  2591. rxq_init->sge_buf_sz = sge_sz;
  2592. rxq_init->max_sges_pkt = max_sge;
  2593. rxq_init->rss_engine_id = BP_FUNC(bp);
  2594. rxq_init->mcast_engine_id = BP_FUNC(bp);
  2595. /* Maximum number or simultaneous TPA aggregation for this Queue.
  2596. *
  2597. * For PF Clients it should be the maximum available number.
  2598. * VF driver(s) may want to define it to a smaller value.
  2599. */
  2600. rxq_init->max_tpa_queues = MAX_AGG_QS(bp);
  2601. rxq_init->cache_line_log = BNX2X_RX_ALIGN_SHIFT;
  2602. rxq_init->fw_sb_id = fp->fw_sb_id;
  2603. if (IS_FCOE_FP(fp))
  2604. rxq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS;
  2605. else
  2606. rxq_init->sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  2607. /* configure silent vlan removal
  2608. * if multi function mode is afex, then mask default vlan
  2609. */
  2610. if (IS_MF_AFEX(bp)) {
  2611. rxq_init->silent_removal_value = bp->afex_def_vlan_tag;
  2612. rxq_init->silent_removal_mask = VLAN_VID_MASK;
  2613. }
  2614. }
  2615. static void bnx2x_pf_tx_q_prep(struct bnx2x *bp,
  2616. struct bnx2x_fastpath *fp, struct bnx2x_txq_setup_params *txq_init,
  2617. u8 cos)
  2618. {
  2619. txq_init->dscr_map = fp->txdata_ptr[cos]->tx_desc_mapping;
  2620. txq_init->sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS + cos;
  2621. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_NW;
  2622. txq_init->fw_sb_id = fp->fw_sb_id;
  2623. /*
  2624. * set the tss leading client id for TX classfication ==
  2625. * leading RSS client id
  2626. */
  2627. txq_init->tss_leading_cl_id = bnx2x_fp(bp, 0, cl_id);
  2628. if (IS_FCOE_FP(fp)) {
  2629. txq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS;
  2630. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_FCOE;
  2631. }
  2632. }
  2633. static void bnx2x_pf_init(struct bnx2x *bp)
  2634. {
  2635. struct bnx2x_func_init_params func_init = {0};
  2636. struct event_ring_data eq_data = { {0} };
  2637. u16 flags;
  2638. if (!CHIP_IS_E1x(bp)) {
  2639. /* reset IGU PF statistics: MSIX + ATTN */
  2640. /* PF */
  2641. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2642. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2643. (CHIP_MODE_IS_4_PORT(bp) ?
  2644. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2645. /* ATTN */
  2646. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2647. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2648. BNX2X_IGU_STAS_MSG_PF_CNT*4 +
  2649. (CHIP_MODE_IS_4_PORT(bp) ?
  2650. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2651. }
  2652. /* function setup flags */
  2653. flags = (FUNC_FLG_STATS | FUNC_FLG_LEADING | FUNC_FLG_SPQ);
  2654. /* This flag is relevant for E1x only.
  2655. * E2 doesn't have a TPA configuration in a function level.
  2656. */
  2657. flags |= (bp->flags & TPA_ENABLE_FLAG) ? FUNC_FLG_TPA : 0;
  2658. func_init.func_flgs = flags;
  2659. func_init.pf_id = BP_FUNC(bp);
  2660. func_init.func_id = BP_FUNC(bp);
  2661. func_init.spq_map = bp->spq_mapping;
  2662. func_init.spq_prod = bp->spq_prod_idx;
  2663. bnx2x_func_init(bp, &func_init);
  2664. memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port));
  2665. /*
  2666. * Congestion management values depend on the link rate
  2667. * There is no active link so initial link rate is set to 10 Gbps.
  2668. * When the link comes up The congestion management values are
  2669. * re-calculated according to the actual link rate.
  2670. */
  2671. bp->link_vars.line_speed = SPEED_10000;
  2672. bnx2x_cmng_fns_init(bp, true, bnx2x_get_cmng_fns_mode(bp));
  2673. /* Only the PMF sets the HW */
  2674. if (bp->port.pmf)
  2675. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2676. /* init Event Queue */
  2677. eq_data.base_addr.hi = U64_HI(bp->eq_mapping);
  2678. eq_data.base_addr.lo = U64_LO(bp->eq_mapping);
  2679. eq_data.producer = bp->eq_prod;
  2680. eq_data.index_id = HC_SP_INDEX_EQ_CONS;
  2681. eq_data.sb_id = DEF_SB_ID;
  2682. storm_memset_eq_data(bp, &eq_data, BP_FUNC(bp));
  2683. }
  2684. static void bnx2x_e1h_disable(struct bnx2x *bp)
  2685. {
  2686. int port = BP_PORT(bp);
  2687. bnx2x_tx_disable(bp);
  2688. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  2689. }
  2690. static void bnx2x_e1h_enable(struct bnx2x *bp)
  2691. {
  2692. int port = BP_PORT(bp);
  2693. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
  2694. /* Tx queue should be only reenabled */
  2695. netif_tx_wake_all_queues(bp->dev);
  2696. /*
  2697. * Should not call netif_carrier_on since it will be called if the link
  2698. * is up when checking for link state
  2699. */
  2700. }
  2701. #define DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED 3
  2702. static void bnx2x_drv_info_ether_stat(struct bnx2x *bp)
  2703. {
  2704. struct eth_stats_info *ether_stat =
  2705. &bp->slowpath->drv_info_to_mcp.ether_stat;
  2706. strlcpy(ether_stat->version, DRV_MODULE_VERSION,
  2707. ETH_STAT_INFO_VERSION_LEN);
  2708. bp->sp_objs[0].mac_obj.get_n_elements(bp, &bp->sp_objs[0].mac_obj,
  2709. DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED,
  2710. ether_stat->mac_local);
  2711. ether_stat->mtu_size = bp->dev->mtu;
  2712. if (bp->dev->features & NETIF_F_RXCSUM)
  2713. ether_stat->feature_flags |= FEATURE_ETH_CHKSUM_OFFLOAD_MASK;
  2714. if (bp->dev->features & NETIF_F_TSO)
  2715. ether_stat->feature_flags |= FEATURE_ETH_LSO_MASK;
  2716. ether_stat->feature_flags |= bp->common.boot_mode;
  2717. ether_stat->promiscuous_mode = (bp->dev->flags & IFF_PROMISC) ? 1 : 0;
  2718. ether_stat->txq_size = bp->tx_ring_size;
  2719. ether_stat->rxq_size = bp->rx_ring_size;
  2720. }
  2721. static void bnx2x_drv_info_fcoe_stat(struct bnx2x *bp)
  2722. {
  2723. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2724. struct fcoe_stats_info *fcoe_stat =
  2725. &bp->slowpath->drv_info_to_mcp.fcoe_stat;
  2726. if (!CNIC_LOADED(bp))
  2727. return;
  2728. memcpy(fcoe_stat->mac_local + MAC_LEADING_ZERO_CNT,
  2729. bp->fip_mac, ETH_ALEN);
  2730. fcoe_stat->qos_priority =
  2731. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_FCOE];
  2732. /* insert FCoE stats from ramrod response */
  2733. if (!NO_FCOE(bp)) {
  2734. struct tstorm_per_queue_stats *fcoe_q_tstorm_stats =
  2735. &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
  2736. tstorm_queue_statistics;
  2737. struct xstorm_per_queue_stats *fcoe_q_xstorm_stats =
  2738. &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
  2739. xstorm_queue_statistics;
  2740. struct fcoe_statistics_params *fw_fcoe_stat =
  2741. &bp->fw_stats_data->fcoe;
  2742. ADD_64(fcoe_stat->rx_bytes_hi, 0, fcoe_stat->rx_bytes_lo,
  2743. fw_fcoe_stat->rx_stat0.fcoe_rx_byte_cnt);
  2744. ADD_64(fcoe_stat->rx_bytes_hi,
  2745. fcoe_q_tstorm_stats->rcv_ucast_bytes.hi,
  2746. fcoe_stat->rx_bytes_lo,
  2747. fcoe_q_tstorm_stats->rcv_ucast_bytes.lo);
  2748. ADD_64(fcoe_stat->rx_bytes_hi,
  2749. fcoe_q_tstorm_stats->rcv_bcast_bytes.hi,
  2750. fcoe_stat->rx_bytes_lo,
  2751. fcoe_q_tstorm_stats->rcv_bcast_bytes.lo);
  2752. ADD_64(fcoe_stat->rx_bytes_hi,
  2753. fcoe_q_tstorm_stats->rcv_mcast_bytes.hi,
  2754. fcoe_stat->rx_bytes_lo,
  2755. fcoe_q_tstorm_stats->rcv_mcast_bytes.lo);
  2756. ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
  2757. fw_fcoe_stat->rx_stat0.fcoe_rx_pkt_cnt);
  2758. ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
  2759. fcoe_q_tstorm_stats->rcv_ucast_pkts);
  2760. ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
  2761. fcoe_q_tstorm_stats->rcv_bcast_pkts);
  2762. ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
  2763. fcoe_q_tstorm_stats->rcv_mcast_pkts);
  2764. ADD_64(fcoe_stat->tx_bytes_hi, 0, fcoe_stat->tx_bytes_lo,
  2765. fw_fcoe_stat->tx_stat.fcoe_tx_byte_cnt);
  2766. ADD_64(fcoe_stat->tx_bytes_hi,
  2767. fcoe_q_xstorm_stats->ucast_bytes_sent.hi,
  2768. fcoe_stat->tx_bytes_lo,
  2769. fcoe_q_xstorm_stats->ucast_bytes_sent.lo);
  2770. ADD_64(fcoe_stat->tx_bytes_hi,
  2771. fcoe_q_xstorm_stats->bcast_bytes_sent.hi,
  2772. fcoe_stat->tx_bytes_lo,
  2773. fcoe_q_xstorm_stats->bcast_bytes_sent.lo);
  2774. ADD_64(fcoe_stat->tx_bytes_hi,
  2775. fcoe_q_xstorm_stats->mcast_bytes_sent.hi,
  2776. fcoe_stat->tx_bytes_lo,
  2777. fcoe_q_xstorm_stats->mcast_bytes_sent.lo);
  2778. ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
  2779. fw_fcoe_stat->tx_stat.fcoe_tx_pkt_cnt);
  2780. ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
  2781. fcoe_q_xstorm_stats->ucast_pkts_sent);
  2782. ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
  2783. fcoe_q_xstorm_stats->bcast_pkts_sent);
  2784. ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
  2785. fcoe_q_xstorm_stats->mcast_pkts_sent);
  2786. }
  2787. /* ask L5 driver to add data to the struct */
  2788. bnx2x_cnic_notify(bp, CNIC_CTL_FCOE_STATS_GET_CMD);
  2789. }
  2790. static void bnx2x_drv_info_iscsi_stat(struct bnx2x *bp)
  2791. {
  2792. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2793. struct iscsi_stats_info *iscsi_stat =
  2794. &bp->slowpath->drv_info_to_mcp.iscsi_stat;
  2795. if (!CNIC_LOADED(bp))
  2796. return;
  2797. memcpy(iscsi_stat->mac_local + MAC_LEADING_ZERO_CNT,
  2798. bp->cnic_eth_dev.iscsi_mac, ETH_ALEN);
  2799. iscsi_stat->qos_priority =
  2800. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_ISCSI];
  2801. /* ask L5 driver to add data to the struct */
  2802. bnx2x_cnic_notify(bp, CNIC_CTL_ISCSI_STATS_GET_CMD);
  2803. }
  2804. /* called due to MCP event (on pmf):
  2805. * reread new bandwidth configuration
  2806. * configure FW
  2807. * notify others function about the change
  2808. */
  2809. static void bnx2x_config_mf_bw(struct bnx2x *bp)
  2810. {
  2811. if (bp->link_vars.link_up) {
  2812. bnx2x_cmng_fns_init(bp, true, CMNG_FNS_MINMAX);
  2813. bnx2x_link_sync_notify(bp);
  2814. }
  2815. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2816. }
  2817. static void bnx2x_set_mf_bw(struct bnx2x *bp)
  2818. {
  2819. bnx2x_config_mf_bw(bp);
  2820. bnx2x_fw_command(bp, DRV_MSG_CODE_SET_MF_BW_ACK, 0);
  2821. }
  2822. static void bnx2x_handle_eee_event(struct bnx2x *bp)
  2823. {
  2824. DP(BNX2X_MSG_MCP, "EEE - LLDP event\n");
  2825. bnx2x_fw_command(bp, DRV_MSG_CODE_EEE_RESULTS_ACK, 0);
  2826. }
  2827. static void bnx2x_handle_drv_info_req(struct bnx2x *bp)
  2828. {
  2829. enum drv_info_opcode op_code;
  2830. u32 drv_info_ctl = SHMEM2_RD(bp, drv_info_control);
  2831. /* if drv_info version supported by MFW doesn't match - send NACK */
  2832. if ((drv_info_ctl & DRV_INFO_CONTROL_VER_MASK) != DRV_INFO_CUR_VER) {
  2833. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  2834. return;
  2835. }
  2836. op_code = (drv_info_ctl & DRV_INFO_CONTROL_OP_CODE_MASK) >>
  2837. DRV_INFO_CONTROL_OP_CODE_SHIFT;
  2838. memset(&bp->slowpath->drv_info_to_mcp, 0,
  2839. sizeof(union drv_info_to_mcp));
  2840. switch (op_code) {
  2841. case ETH_STATS_OPCODE:
  2842. bnx2x_drv_info_ether_stat(bp);
  2843. break;
  2844. case FCOE_STATS_OPCODE:
  2845. bnx2x_drv_info_fcoe_stat(bp);
  2846. break;
  2847. case ISCSI_STATS_OPCODE:
  2848. bnx2x_drv_info_iscsi_stat(bp);
  2849. break;
  2850. default:
  2851. /* if op code isn't supported - send NACK */
  2852. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  2853. return;
  2854. }
  2855. /* if we got drv_info attn from MFW then these fields are defined in
  2856. * shmem2 for sure
  2857. */
  2858. SHMEM2_WR(bp, drv_info_host_addr_lo,
  2859. U64_LO(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  2860. SHMEM2_WR(bp, drv_info_host_addr_hi,
  2861. U64_HI(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  2862. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_ACK, 0);
  2863. }
  2864. static void bnx2x_dcc_event(struct bnx2x *bp, u32 dcc_event)
  2865. {
  2866. DP(BNX2X_MSG_MCP, "dcc_event 0x%x\n", dcc_event);
  2867. if (dcc_event & DRV_STATUS_DCC_DISABLE_ENABLE_PF) {
  2868. /*
  2869. * This is the only place besides the function initialization
  2870. * where the bp->flags can change so it is done without any
  2871. * locks
  2872. */
  2873. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  2874. DP(BNX2X_MSG_MCP, "mf_cfg function disabled\n");
  2875. bp->flags |= MF_FUNC_DIS;
  2876. bnx2x_e1h_disable(bp);
  2877. } else {
  2878. DP(BNX2X_MSG_MCP, "mf_cfg function enabled\n");
  2879. bp->flags &= ~MF_FUNC_DIS;
  2880. bnx2x_e1h_enable(bp);
  2881. }
  2882. dcc_event &= ~DRV_STATUS_DCC_DISABLE_ENABLE_PF;
  2883. }
  2884. if (dcc_event & DRV_STATUS_DCC_BANDWIDTH_ALLOCATION) {
  2885. bnx2x_config_mf_bw(bp);
  2886. dcc_event &= ~DRV_STATUS_DCC_BANDWIDTH_ALLOCATION;
  2887. }
  2888. /* Report results to MCP */
  2889. if (dcc_event)
  2890. bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_FAILURE, 0);
  2891. else
  2892. bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_OK, 0);
  2893. }
  2894. /* must be called under the spq lock */
  2895. static struct eth_spe *bnx2x_sp_get_next(struct bnx2x *bp)
  2896. {
  2897. struct eth_spe *next_spe = bp->spq_prod_bd;
  2898. if (bp->spq_prod_bd == bp->spq_last_bd) {
  2899. bp->spq_prod_bd = bp->spq;
  2900. bp->spq_prod_idx = 0;
  2901. DP(BNX2X_MSG_SP, "end of spq\n");
  2902. } else {
  2903. bp->spq_prod_bd++;
  2904. bp->spq_prod_idx++;
  2905. }
  2906. return next_spe;
  2907. }
  2908. /* must be called under the spq lock */
  2909. static void bnx2x_sp_prod_update(struct bnx2x *bp)
  2910. {
  2911. int func = BP_FUNC(bp);
  2912. /*
  2913. * Make sure that BD data is updated before writing the producer:
  2914. * BD data is written to the memory, the producer is read from the
  2915. * memory, thus we need a full memory barrier to ensure the ordering.
  2916. */
  2917. mb();
  2918. REG_WR16(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func),
  2919. bp->spq_prod_idx);
  2920. mmiowb();
  2921. }
  2922. /**
  2923. * bnx2x_is_contextless_ramrod - check if the current command ends on EQ
  2924. *
  2925. * @cmd: command to check
  2926. * @cmd_type: command type
  2927. */
  2928. static bool bnx2x_is_contextless_ramrod(int cmd, int cmd_type)
  2929. {
  2930. if ((cmd_type == NONE_CONNECTION_TYPE) ||
  2931. (cmd == RAMROD_CMD_ID_ETH_FORWARD_SETUP) ||
  2932. (cmd == RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES) ||
  2933. (cmd == RAMROD_CMD_ID_ETH_FILTER_RULES) ||
  2934. (cmd == RAMROD_CMD_ID_ETH_MULTICAST_RULES) ||
  2935. (cmd == RAMROD_CMD_ID_ETH_SET_MAC) ||
  2936. (cmd == RAMROD_CMD_ID_ETH_RSS_UPDATE))
  2937. return true;
  2938. else
  2939. return false;
  2940. }
  2941. /**
  2942. * bnx2x_sp_post - place a single command on an SP ring
  2943. *
  2944. * @bp: driver handle
  2945. * @command: command to place (e.g. SETUP, FILTER_RULES, etc.)
  2946. * @cid: SW CID the command is related to
  2947. * @data_hi: command private data address (high 32 bits)
  2948. * @data_lo: command private data address (low 32 bits)
  2949. * @cmd_type: command type (e.g. NONE, ETH)
  2950. *
  2951. * SP data is handled as if it's always an address pair, thus data fields are
  2952. * not swapped to little endian in upper functions. Instead this function swaps
  2953. * data as if it's two u32 fields.
  2954. */
  2955. int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
  2956. u32 data_hi, u32 data_lo, int cmd_type)
  2957. {
  2958. struct eth_spe *spe;
  2959. u16 type;
  2960. bool common = bnx2x_is_contextless_ramrod(command, cmd_type);
  2961. #ifdef BNX2X_STOP_ON_ERROR
  2962. if (unlikely(bp->panic)) {
  2963. BNX2X_ERR("Can't post SP when there is panic\n");
  2964. return -EIO;
  2965. }
  2966. #endif
  2967. spin_lock_bh(&bp->spq_lock);
  2968. if (common) {
  2969. if (!atomic_read(&bp->eq_spq_left)) {
  2970. BNX2X_ERR("BUG! EQ ring full!\n");
  2971. spin_unlock_bh(&bp->spq_lock);
  2972. bnx2x_panic();
  2973. return -EBUSY;
  2974. }
  2975. } else if (!atomic_read(&bp->cq_spq_left)) {
  2976. BNX2X_ERR("BUG! SPQ ring full!\n");
  2977. spin_unlock_bh(&bp->spq_lock);
  2978. bnx2x_panic();
  2979. return -EBUSY;
  2980. }
  2981. spe = bnx2x_sp_get_next(bp);
  2982. /* CID needs port number to be encoded int it */
  2983. spe->hdr.conn_and_cmd_data =
  2984. cpu_to_le32((command << SPE_HDR_CMD_ID_SHIFT) |
  2985. HW_CID(bp, cid));
  2986. type = (cmd_type << SPE_HDR_CONN_TYPE_SHIFT) & SPE_HDR_CONN_TYPE;
  2987. type |= ((BP_FUNC(bp) << SPE_HDR_FUNCTION_ID_SHIFT) &
  2988. SPE_HDR_FUNCTION_ID);
  2989. spe->hdr.type = cpu_to_le16(type);
  2990. spe->data.update_data_addr.hi = cpu_to_le32(data_hi);
  2991. spe->data.update_data_addr.lo = cpu_to_le32(data_lo);
  2992. /*
  2993. * It's ok if the actual decrement is issued towards the memory
  2994. * somewhere between the spin_lock and spin_unlock. Thus no
  2995. * more explict memory barrier is needed.
  2996. */
  2997. if (common)
  2998. atomic_dec(&bp->eq_spq_left);
  2999. else
  3000. atomic_dec(&bp->cq_spq_left);
  3001. DP(BNX2X_MSG_SP,
  3002. "SPQE[%x] (%x:%x) (cmd, common?) (%d,%d) hw_cid %x data (%x:%x) type(0x%x) left (CQ, EQ) (%x,%x)\n",
  3003. bp->spq_prod_idx, (u32)U64_HI(bp->spq_mapping),
  3004. (u32)(U64_LO(bp->spq_mapping) +
  3005. (void *)bp->spq_prod_bd - (void *)bp->spq), command, common,
  3006. HW_CID(bp, cid), data_hi, data_lo, type,
  3007. atomic_read(&bp->cq_spq_left), atomic_read(&bp->eq_spq_left));
  3008. bnx2x_sp_prod_update(bp);
  3009. spin_unlock_bh(&bp->spq_lock);
  3010. return 0;
  3011. }
  3012. /* acquire split MCP access lock register */
  3013. static int bnx2x_acquire_alr(struct bnx2x *bp)
  3014. {
  3015. u32 j, val;
  3016. int rc = 0;
  3017. might_sleep();
  3018. for (j = 0; j < 1000; j++) {
  3019. val = (1UL << 31);
  3020. REG_WR(bp, GRCBASE_MCP + 0x9c, val);
  3021. val = REG_RD(bp, GRCBASE_MCP + 0x9c);
  3022. if (val & (1L << 31))
  3023. break;
  3024. msleep(5);
  3025. }
  3026. if (!(val & (1L << 31))) {
  3027. BNX2X_ERR("Cannot acquire MCP access lock register\n");
  3028. rc = -EBUSY;
  3029. }
  3030. return rc;
  3031. }
  3032. /* release split MCP access lock register */
  3033. static void bnx2x_release_alr(struct bnx2x *bp)
  3034. {
  3035. REG_WR(bp, GRCBASE_MCP + 0x9c, 0);
  3036. }
  3037. #define BNX2X_DEF_SB_ATT_IDX 0x0001
  3038. #define BNX2X_DEF_SB_IDX 0x0002
  3039. static u16 bnx2x_update_dsb_idx(struct bnx2x *bp)
  3040. {
  3041. struct host_sp_status_block *def_sb = bp->def_status_blk;
  3042. u16 rc = 0;
  3043. barrier(); /* status block is written to by the chip */
  3044. if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) {
  3045. bp->def_att_idx = def_sb->atten_status_block.attn_bits_index;
  3046. rc |= BNX2X_DEF_SB_ATT_IDX;
  3047. }
  3048. if (bp->def_idx != def_sb->sp_sb.running_index) {
  3049. bp->def_idx = def_sb->sp_sb.running_index;
  3050. rc |= BNX2X_DEF_SB_IDX;
  3051. }
  3052. /* Do not reorder: indecies reading should complete before handling */
  3053. barrier();
  3054. return rc;
  3055. }
  3056. /*
  3057. * slow path service functions
  3058. */
  3059. static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted)
  3060. {
  3061. int port = BP_PORT(bp);
  3062. u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  3063. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  3064. u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 :
  3065. NIG_REG_MASK_INTERRUPT_PORT0;
  3066. u32 aeu_mask;
  3067. u32 nig_mask = 0;
  3068. u32 reg_addr;
  3069. if (bp->attn_state & asserted)
  3070. BNX2X_ERR("IGU ERROR\n");
  3071. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3072. aeu_mask = REG_RD(bp, aeu_addr);
  3073. DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n",
  3074. aeu_mask, asserted);
  3075. aeu_mask &= ~(asserted & 0x3ff);
  3076. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  3077. REG_WR(bp, aeu_addr, aeu_mask);
  3078. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3079. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  3080. bp->attn_state |= asserted;
  3081. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  3082. if (asserted & ATTN_HARD_WIRED_MASK) {
  3083. if (asserted & ATTN_NIG_FOR_FUNC) {
  3084. bnx2x_acquire_phy_lock(bp);
  3085. /* save nig interrupt mask */
  3086. nig_mask = REG_RD(bp, nig_int_mask_addr);
  3087. /* If nig_mask is not set, no need to call the update
  3088. * function.
  3089. */
  3090. if (nig_mask) {
  3091. REG_WR(bp, nig_int_mask_addr, 0);
  3092. bnx2x_link_attn(bp);
  3093. }
  3094. /* handle unicore attn? */
  3095. }
  3096. if (asserted & ATTN_SW_TIMER_4_FUNC)
  3097. DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n");
  3098. if (asserted & GPIO_2_FUNC)
  3099. DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n");
  3100. if (asserted & GPIO_3_FUNC)
  3101. DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n");
  3102. if (asserted & GPIO_4_FUNC)
  3103. DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n");
  3104. if (port == 0) {
  3105. if (asserted & ATTN_GENERAL_ATTN_1) {
  3106. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n");
  3107. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0);
  3108. }
  3109. if (asserted & ATTN_GENERAL_ATTN_2) {
  3110. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n");
  3111. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0);
  3112. }
  3113. if (asserted & ATTN_GENERAL_ATTN_3) {
  3114. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n");
  3115. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0);
  3116. }
  3117. } else {
  3118. if (asserted & ATTN_GENERAL_ATTN_4) {
  3119. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n");
  3120. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0);
  3121. }
  3122. if (asserted & ATTN_GENERAL_ATTN_5) {
  3123. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n");
  3124. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0);
  3125. }
  3126. if (asserted & ATTN_GENERAL_ATTN_6) {
  3127. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n");
  3128. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0);
  3129. }
  3130. }
  3131. } /* if hardwired */
  3132. if (bp->common.int_block == INT_BLOCK_HC)
  3133. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  3134. COMMAND_REG_ATTN_BITS_SET);
  3135. else
  3136. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_SET_UPPER*8);
  3137. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", asserted,
  3138. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  3139. REG_WR(bp, reg_addr, asserted);
  3140. /* now set back the mask */
  3141. if (asserted & ATTN_NIG_FOR_FUNC) {
  3142. /* Verify that IGU ack through BAR was written before restoring
  3143. * NIG mask. This loop should exit after 2-3 iterations max.
  3144. */
  3145. if (bp->common.int_block != INT_BLOCK_HC) {
  3146. u32 cnt = 0, igu_acked;
  3147. do {
  3148. igu_acked = REG_RD(bp,
  3149. IGU_REG_ATTENTION_ACK_BITS);
  3150. } while (((igu_acked & ATTN_NIG_FOR_FUNC) == 0) &&
  3151. (++cnt < MAX_IGU_ATTN_ACK_TO));
  3152. if (!igu_acked)
  3153. DP(NETIF_MSG_HW,
  3154. "Failed to verify IGU ack on time\n");
  3155. barrier();
  3156. }
  3157. REG_WR(bp, nig_int_mask_addr, nig_mask);
  3158. bnx2x_release_phy_lock(bp);
  3159. }
  3160. }
  3161. static void bnx2x_fan_failure(struct bnx2x *bp)
  3162. {
  3163. int port = BP_PORT(bp);
  3164. u32 ext_phy_config;
  3165. /* mark the failure */
  3166. ext_phy_config =
  3167. SHMEM_RD(bp,
  3168. dev_info.port_hw_config[port].external_phy_config);
  3169. ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
  3170. ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE;
  3171. SHMEM_WR(bp, dev_info.port_hw_config[port].external_phy_config,
  3172. ext_phy_config);
  3173. /* log the failure */
  3174. netdev_err(bp->dev, "Fan Failure on Network Controller has caused the driver to shutdown the card to prevent permanent damage.\n"
  3175. "Please contact OEM Support for assistance\n");
  3176. /*
  3177. * Schedule device reset (unload)
  3178. * This is due to some boards consuming sufficient power when driver is
  3179. * up to overheat if fan fails.
  3180. */
  3181. smp_mb__before_clear_bit();
  3182. set_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state);
  3183. smp_mb__after_clear_bit();
  3184. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  3185. }
  3186. static void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn)
  3187. {
  3188. int port = BP_PORT(bp);
  3189. int reg_offset;
  3190. u32 val;
  3191. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  3192. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  3193. if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) {
  3194. val = REG_RD(bp, reg_offset);
  3195. val &= ~AEU_INPUTS_ATTN_BITS_SPIO5;
  3196. REG_WR(bp, reg_offset, val);
  3197. BNX2X_ERR("SPIO5 hw attention\n");
  3198. /* Fan failure attention */
  3199. bnx2x_hw_reset_phy(&bp->link_params);
  3200. bnx2x_fan_failure(bp);
  3201. }
  3202. if ((attn & bp->link_vars.aeu_int_mask) && bp->port.pmf) {
  3203. bnx2x_acquire_phy_lock(bp);
  3204. bnx2x_handle_module_detect_int(&bp->link_params);
  3205. bnx2x_release_phy_lock(bp);
  3206. }
  3207. if (attn & HW_INTERRUT_ASSERT_SET_0) {
  3208. val = REG_RD(bp, reg_offset);
  3209. val &= ~(attn & HW_INTERRUT_ASSERT_SET_0);
  3210. REG_WR(bp, reg_offset, val);
  3211. BNX2X_ERR("FATAL HW block attention set0 0x%x\n",
  3212. (u32)(attn & HW_INTERRUT_ASSERT_SET_0));
  3213. bnx2x_panic();
  3214. }
  3215. }
  3216. static void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn)
  3217. {
  3218. u32 val;
  3219. if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) {
  3220. val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR);
  3221. BNX2X_ERR("DB hw attention 0x%x\n", val);
  3222. /* DORQ discard attention */
  3223. if (val & 0x2)
  3224. BNX2X_ERR("FATAL error from DORQ\n");
  3225. }
  3226. if (attn & HW_INTERRUT_ASSERT_SET_1) {
  3227. int port = BP_PORT(bp);
  3228. int reg_offset;
  3229. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 :
  3230. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1);
  3231. val = REG_RD(bp, reg_offset);
  3232. val &= ~(attn & HW_INTERRUT_ASSERT_SET_1);
  3233. REG_WR(bp, reg_offset, val);
  3234. BNX2X_ERR("FATAL HW block attention set1 0x%x\n",
  3235. (u32)(attn & HW_INTERRUT_ASSERT_SET_1));
  3236. bnx2x_panic();
  3237. }
  3238. }
  3239. static void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn)
  3240. {
  3241. u32 val;
  3242. if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) {
  3243. val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR);
  3244. BNX2X_ERR("CFC hw attention 0x%x\n", val);
  3245. /* CFC error attention */
  3246. if (val & 0x2)
  3247. BNX2X_ERR("FATAL error from CFC\n");
  3248. }
  3249. if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) {
  3250. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0);
  3251. BNX2X_ERR("PXP hw attention-0 0x%x\n", val);
  3252. /* RQ_USDMDP_FIFO_OVERFLOW */
  3253. if (val & 0x18000)
  3254. BNX2X_ERR("FATAL error from PXP\n");
  3255. if (!CHIP_IS_E1x(bp)) {
  3256. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_1);
  3257. BNX2X_ERR("PXP hw attention-1 0x%x\n", val);
  3258. }
  3259. }
  3260. if (attn & HW_INTERRUT_ASSERT_SET_2) {
  3261. int port = BP_PORT(bp);
  3262. int reg_offset;
  3263. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 :
  3264. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2);
  3265. val = REG_RD(bp, reg_offset);
  3266. val &= ~(attn & HW_INTERRUT_ASSERT_SET_2);
  3267. REG_WR(bp, reg_offset, val);
  3268. BNX2X_ERR("FATAL HW block attention set2 0x%x\n",
  3269. (u32)(attn & HW_INTERRUT_ASSERT_SET_2));
  3270. bnx2x_panic();
  3271. }
  3272. }
  3273. static void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn)
  3274. {
  3275. u32 val;
  3276. if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) {
  3277. if (attn & BNX2X_PMF_LINK_ASSERT) {
  3278. int func = BP_FUNC(bp);
  3279. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  3280. bnx2x_read_mf_cfg(bp);
  3281. bp->mf_config[BP_VN(bp)] = MF_CFG_RD(bp,
  3282. func_mf_config[BP_ABS_FUNC(bp)].config);
  3283. val = SHMEM_RD(bp,
  3284. func_mb[BP_FW_MB_IDX(bp)].drv_status);
  3285. if (val & DRV_STATUS_DCC_EVENT_MASK)
  3286. bnx2x_dcc_event(bp,
  3287. (val & DRV_STATUS_DCC_EVENT_MASK));
  3288. if (val & DRV_STATUS_SET_MF_BW)
  3289. bnx2x_set_mf_bw(bp);
  3290. if (val & DRV_STATUS_DRV_INFO_REQ)
  3291. bnx2x_handle_drv_info_req(bp);
  3292. if (val & DRV_STATUS_VF_DISABLED)
  3293. bnx2x_vf_handle_flr_event(bp);
  3294. if ((bp->port.pmf == 0) && (val & DRV_STATUS_PMF))
  3295. bnx2x_pmf_update(bp);
  3296. if (bp->port.pmf &&
  3297. (val & DRV_STATUS_DCBX_NEGOTIATION_RESULTS) &&
  3298. bp->dcbx_enabled > 0)
  3299. /* start dcbx state machine */
  3300. bnx2x_dcbx_set_params(bp,
  3301. BNX2X_DCBX_STATE_NEG_RECEIVED);
  3302. if (val & DRV_STATUS_AFEX_EVENT_MASK)
  3303. bnx2x_handle_afex_cmd(bp,
  3304. val & DRV_STATUS_AFEX_EVENT_MASK);
  3305. if (val & DRV_STATUS_EEE_NEGOTIATION_RESULTS)
  3306. bnx2x_handle_eee_event(bp);
  3307. if (bp->link_vars.periodic_flags &
  3308. PERIODIC_FLAGS_LINK_EVENT) {
  3309. /* sync with link */
  3310. bnx2x_acquire_phy_lock(bp);
  3311. bp->link_vars.periodic_flags &=
  3312. ~PERIODIC_FLAGS_LINK_EVENT;
  3313. bnx2x_release_phy_lock(bp);
  3314. if (IS_MF(bp))
  3315. bnx2x_link_sync_notify(bp);
  3316. bnx2x_link_report(bp);
  3317. }
  3318. /* Always call it here: bnx2x_link_report() will
  3319. * prevent the link indication duplication.
  3320. */
  3321. bnx2x__link_status_update(bp);
  3322. } else if (attn & BNX2X_MC_ASSERT_BITS) {
  3323. BNX2X_ERR("MC assert!\n");
  3324. bnx2x_mc_assert(bp);
  3325. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0);
  3326. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0);
  3327. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0);
  3328. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0);
  3329. bnx2x_panic();
  3330. } else if (attn & BNX2X_MCP_ASSERT) {
  3331. BNX2X_ERR("MCP assert!\n");
  3332. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0);
  3333. bnx2x_fw_dump(bp);
  3334. } else
  3335. BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn);
  3336. }
  3337. if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) {
  3338. BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn);
  3339. if (attn & BNX2X_GRC_TIMEOUT) {
  3340. val = CHIP_IS_E1(bp) ? 0 :
  3341. REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN);
  3342. BNX2X_ERR("GRC time-out 0x%08x\n", val);
  3343. }
  3344. if (attn & BNX2X_GRC_RSV) {
  3345. val = CHIP_IS_E1(bp) ? 0 :
  3346. REG_RD(bp, MISC_REG_GRC_RSV_ATTN);
  3347. BNX2X_ERR("GRC reserved 0x%08x\n", val);
  3348. }
  3349. REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff);
  3350. }
  3351. }
  3352. /*
  3353. * Bits map:
  3354. * 0-7 - Engine0 load counter.
  3355. * 8-15 - Engine1 load counter.
  3356. * 16 - Engine0 RESET_IN_PROGRESS bit.
  3357. * 17 - Engine1 RESET_IN_PROGRESS bit.
  3358. * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active function
  3359. * on the engine
  3360. * 19 - Engine1 ONE_IS_LOADED.
  3361. * 20 - Chip reset flow bit. When set none-leader must wait for both engines
  3362. * leader to complete (check for both RESET_IN_PROGRESS bits and not for
  3363. * just the one belonging to its engine).
  3364. *
  3365. */
  3366. #define BNX2X_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1
  3367. #define BNX2X_PATH0_LOAD_CNT_MASK 0x000000ff
  3368. #define BNX2X_PATH0_LOAD_CNT_SHIFT 0
  3369. #define BNX2X_PATH1_LOAD_CNT_MASK 0x0000ff00
  3370. #define BNX2X_PATH1_LOAD_CNT_SHIFT 8
  3371. #define BNX2X_PATH0_RST_IN_PROG_BIT 0x00010000
  3372. #define BNX2X_PATH1_RST_IN_PROG_BIT 0x00020000
  3373. #define BNX2X_GLOBAL_RESET_BIT 0x00040000
  3374. /*
  3375. * Set the GLOBAL_RESET bit.
  3376. *
  3377. * Should be run under rtnl lock
  3378. */
  3379. void bnx2x_set_reset_global(struct bnx2x *bp)
  3380. {
  3381. u32 val;
  3382. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3383. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3384. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val | BNX2X_GLOBAL_RESET_BIT);
  3385. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3386. }
  3387. /*
  3388. * Clear the GLOBAL_RESET bit.
  3389. *
  3390. * Should be run under rtnl lock
  3391. */
  3392. static void bnx2x_clear_reset_global(struct bnx2x *bp)
  3393. {
  3394. u32 val;
  3395. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3396. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3397. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~BNX2X_GLOBAL_RESET_BIT));
  3398. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3399. }
  3400. /*
  3401. * Checks the GLOBAL_RESET bit.
  3402. *
  3403. * should be run under rtnl lock
  3404. */
  3405. static bool bnx2x_reset_is_global(struct bnx2x *bp)
  3406. {
  3407. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3408. DP(NETIF_MSG_HW, "GEN_REG_VAL=0x%08x\n", val);
  3409. return (val & BNX2X_GLOBAL_RESET_BIT) ? true : false;
  3410. }
  3411. /*
  3412. * Clear RESET_IN_PROGRESS bit for the current engine.
  3413. *
  3414. * Should be run under rtnl lock
  3415. */
  3416. static void bnx2x_set_reset_done(struct bnx2x *bp)
  3417. {
  3418. u32 val;
  3419. u32 bit = BP_PATH(bp) ?
  3420. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3421. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3422. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3423. /* Clear the bit */
  3424. val &= ~bit;
  3425. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3426. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3427. }
  3428. /*
  3429. * Set RESET_IN_PROGRESS for the current engine.
  3430. *
  3431. * should be run under rtnl lock
  3432. */
  3433. void bnx2x_set_reset_in_progress(struct bnx2x *bp)
  3434. {
  3435. u32 val;
  3436. u32 bit = BP_PATH(bp) ?
  3437. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3438. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3439. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3440. /* Set the bit */
  3441. val |= bit;
  3442. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3443. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3444. }
  3445. /*
  3446. * Checks the RESET_IN_PROGRESS bit for the given engine.
  3447. * should be run under rtnl lock
  3448. */
  3449. bool bnx2x_reset_is_done(struct bnx2x *bp, int engine)
  3450. {
  3451. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3452. u32 bit = engine ?
  3453. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3454. /* return false if bit is set */
  3455. return (val & bit) ? false : true;
  3456. }
  3457. /*
  3458. * set pf load for the current pf.
  3459. *
  3460. * should be run under rtnl lock
  3461. */
  3462. void bnx2x_set_pf_load(struct bnx2x *bp)
  3463. {
  3464. u32 val1, val;
  3465. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3466. BNX2X_PATH0_LOAD_CNT_MASK;
  3467. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3468. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3469. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3470. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3471. DP(NETIF_MSG_IFUP, "Old GEN_REG_VAL=0x%08x\n", val);
  3472. /* get the current counter value */
  3473. val1 = (val & mask) >> shift;
  3474. /* set bit of that PF */
  3475. val1 |= (1 << bp->pf_num);
  3476. /* clear the old value */
  3477. val &= ~mask;
  3478. /* set the new one */
  3479. val |= ((val1 << shift) & mask);
  3480. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3481. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3482. }
  3483. /**
  3484. * bnx2x_clear_pf_load - clear pf load mark
  3485. *
  3486. * @bp: driver handle
  3487. *
  3488. * Should be run under rtnl lock.
  3489. * Decrements the load counter for the current engine. Returns
  3490. * whether other functions are still loaded
  3491. */
  3492. bool bnx2x_clear_pf_load(struct bnx2x *bp)
  3493. {
  3494. u32 val1, val;
  3495. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3496. BNX2X_PATH0_LOAD_CNT_MASK;
  3497. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3498. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3499. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3500. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3501. DP(NETIF_MSG_IFDOWN, "Old GEN_REG_VAL=0x%08x\n", val);
  3502. /* get the current counter value */
  3503. val1 = (val & mask) >> shift;
  3504. /* clear bit of that PF */
  3505. val1 &= ~(1 << bp->pf_num);
  3506. /* clear the old value */
  3507. val &= ~mask;
  3508. /* set the new one */
  3509. val |= ((val1 << shift) & mask);
  3510. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3511. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3512. return val1 != 0;
  3513. }
  3514. /*
  3515. * Read the load status for the current engine.
  3516. *
  3517. * should be run under rtnl lock
  3518. */
  3519. static bool bnx2x_get_load_status(struct bnx2x *bp, int engine)
  3520. {
  3521. u32 mask = (engine ? BNX2X_PATH1_LOAD_CNT_MASK :
  3522. BNX2X_PATH0_LOAD_CNT_MASK);
  3523. u32 shift = (engine ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3524. BNX2X_PATH0_LOAD_CNT_SHIFT);
  3525. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3526. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "GLOB_REG=0x%08x\n", val);
  3527. val = (val & mask) >> shift;
  3528. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "load mask for engine %d = 0x%x\n",
  3529. engine, val);
  3530. return val != 0;
  3531. }
  3532. static void _print_next_block(int idx, const char *blk)
  3533. {
  3534. pr_cont("%s%s", idx ? ", " : "", blk);
  3535. }
  3536. static int bnx2x_check_blocks_with_parity0(u32 sig, int par_num,
  3537. bool print)
  3538. {
  3539. int i = 0;
  3540. u32 cur_bit = 0;
  3541. for (i = 0; sig; i++) {
  3542. cur_bit = ((u32)0x1 << i);
  3543. if (sig & cur_bit) {
  3544. switch (cur_bit) {
  3545. case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR:
  3546. if (print)
  3547. _print_next_block(par_num++, "BRB");
  3548. break;
  3549. case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR:
  3550. if (print)
  3551. _print_next_block(par_num++, "PARSER");
  3552. break;
  3553. case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR:
  3554. if (print)
  3555. _print_next_block(par_num++, "TSDM");
  3556. break;
  3557. case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR:
  3558. if (print)
  3559. _print_next_block(par_num++,
  3560. "SEARCHER");
  3561. break;
  3562. case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR:
  3563. if (print)
  3564. _print_next_block(par_num++, "TCM");
  3565. break;
  3566. case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR:
  3567. if (print)
  3568. _print_next_block(par_num++, "TSEMI");
  3569. break;
  3570. case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR:
  3571. if (print)
  3572. _print_next_block(par_num++, "XPB");
  3573. break;
  3574. }
  3575. /* Clear the bit */
  3576. sig &= ~cur_bit;
  3577. }
  3578. }
  3579. return par_num;
  3580. }
  3581. static int bnx2x_check_blocks_with_parity1(u32 sig, int par_num,
  3582. bool *global, bool print)
  3583. {
  3584. int i = 0;
  3585. u32 cur_bit = 0;
  3586. for (i = 0; sig; i++) {
  3587. cur_bit = ((u32)0x1 << i);
  3588. if (sig & cur_bit) {
  3589. switch (cur_bit) {
  3590. case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR:
  3591. if (print)
  3592. _print_next_block(par_num++, "PBF");
  3593. break;
  3594. case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR:
  3595. if (print)
  3596. _print_next_block(par_num++, "QM");
  3597. break;
  3598. case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR:
  3599. if (print)
  3600. _print_next_block(par_num++, "TM");
  3601. break;
  3602. case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR:
  3603. if (print)
  3604. _print_next_block(par_num++, "XSDM");
  3605. break;
  3606. case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR:
  3607. if (print)
  3608. _print_next_block(par_num++, "XCM");
  3609. break;
  3610. case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR:
  3611. if (print)
  3612. _print_next_block(par_num++, "XSEMI");
  3613. break;
  3614. case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR:
  3615. if (print)
  3616. _print_next_block(par_num++,
  3617. "DOORBELLQ");
  3618. break;
  3619. case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR:
  3620. if (print)
  3621. _print_next_block(par_num++, "NIG");
  3622. break;
  3623. case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR:
  3624. if (print)
  3625. _print_next_block(par_num++,
  3626. "VAUX PCI CORE");
  3627. *global = true;
  3628. break;
  3629. case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR:
  3630. if (print)
  3631. _print_next_block(par_num++, "DEBUG");
  3632. break;
  3633. case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR:
  3634. if (print)
  3635. _print_next_block(par_num++, "USDM");
  3636. break;
  3637. case AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR:
  3638. if (print)
  3639. _print_next_block(par_num++, "UCM");
  3640. break;
  3641. case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR:
  3642. if (print)
  3643. _print_next_block(par_num++, "USEMI");
  3644. break;
  3645. case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR:
  3646. if (print)
  3647. _print_next_block(par_num++, "UPB");
  3648. break;
  3649. case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR:
  3650. if (print)
  3651. _print_next_block(par_num++, "CSDM");
  3652. break;
  3653. case AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR:
  3654. if (print)
  3655. _print_next_block(par_num++, "CCM");
  3656. break;
  3657. }
  3658. /* Clear the bit */
  3659. sig &= ~cur_bit;
  3660. }
  3661. }
  3662. return par_num;
  3663. }
  3664. static int bnx2x_check_blocks_with_parity2(u32 sig, int par_num,
  3665. bool print)
  3666. {
  3667. int i = 0;
  3668. u32 cur_bit = 0;
  3669. for (i = 0; sig; i++) {
  3670. cur_bit = ((u32)0x1 << i);
  3671. if (sig & cur_bit) {
  3672. switch (cur_bit) {
  3673. case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR:
  3674. if (print)
  3675. _print_next_block(par_num++, "CSEMI");
  3676. break;
  3677. case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR:
  3678. if (print)
  3679. _print_next_block(par_num++, "PXP");
  3680. break;
  3681. case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR:
  3682. if (print)
  3683. _print_next_block(par_num++,
  3684. "PXPPCICLOCKCLIENT");
  3685. break;
  3686. case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR:
  3687. if (print)
  3688. _print_next_block(par_num++, "CFC");
  3689. break;
  3690. case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR:
  3691. if (print)
  3692. _print_next_block(par_num++, "CDU");
  3693. break;
  3694. case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR:
  3695. if (print)
  3696. _print_next_block(par_num++, "DMAE");
  3697. break;
  3698. case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR:
  3699. if (print)
  3700. _print_next_block(par_num++, "IGU");
  3701. break;
  3702. case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR:
  3703. if (print)
  3704. _print_next_block(par_num++, "MISC");
  3705. break;
  3706. }
  3707. /* Clear the bit */
  3708. sig &= ~cur_bit;
  3709. }
  3710. }
  3711. return par_num;
  3712. }
  3713. static int bnx2x_check_blocks_with_parity3(u32 sig, int par_num,
  3714. bool *global, bool print)
  3715. {
  3716. int i = 0;
  3717. u32 cur_bit = 0;
  3718. for (i = 0; sig; i++) {
  3719. cur_bit = ((u32)0x1 << i);
  3720. if (sig & cur_bit) {
  3721. switch (cur_bit) {
  3722. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY:
  3723. if (print)
  3724. _print_next_block(par_num++, "MCP ROM");
  3725. *global = true;
  3726. break;
  3727. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY:
  3728. if (print)
  3729. _print_next_block(par_num++,
  3730. "MCP UMP RX");
  3731. *global = true;
  3732. break;
  3733. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY:
  3734. if (print)
  3735. _print_next_block(par_num++,
  3736. "MCP UMP TX");
  3737. *global = true;
  3738. break;
  3739. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY:
  3740. if (print)
  3741. _print_next_block(par_num++,
  3742. "MCP SCPAD");
  3743. *global = true;
  3744. break;
  3745. }
  3746. /* Clear the bit */
  3747. sig &= ~cur_bit;
  3748. }
  3749. }
  3750. return par_num;
  3751. }
  3752. static int bnx2x_check_blocks_with_parity4(u32 sig, int par_num,
  3753. bool print)
  3754. {
  3755. int i = 0;
  3756. u32 cur_bit = 0;
  3757. for (i = 0; sig; i++) {
  3758. cur_bit = ((u32)0x1 << i);
  3759. if (sig & cur_bit) {
  3760. switch (cur_bit) {
  3761. case AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR:
  3762. if (print)
  3763. _print_next_block(par_num++, "PGLUE_B");
  3764. break;
  3765. case AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR:
  3766. if (print)
  3767. _print_next_block(par_num++, "ATC");
  3768. break;
  3769. }
  3770. /* Clear the bit */
  3771. sig &= ~cur_bit;
  3772. }
  3773. }
  3774. return par_num;
  3775. }
  3776. static bool bnx2x_parity_attn(struct bnx2x *bp, bool *global, bool print,
  3777. u32 *sig)
  3778. {
  3779. if ((sig[0] & HW_PRTY_ASSERT_SET_0) ||
  3780. (sig[1] & HW_PRTY_ASSERT_SET_1) ||
  3781. (sig[2] & HW_PRTY_ASSERT_SET_2) ||
  3782. (sig[3] & HW_PRTY_ASSERT_SET_3) ||
  3783. (sig[4] & HW_PRTY_ASSERT_SET_4)) {
  3784. int par_num = 0;
  3785. DP(NETIF_MSG_HW, "Was parity error: HW block parity attention:\n"
  3786. "[0]:0x%08x [1]:0x%08x [2]:0x%08x [3]:0x%08x [4]:0x%08x\n",
  3787. sig[0] & HW_PRTY_ASSERT_SET_0,
  3788. sig[1] & HW_PRTY_ASSERT_SET_1,
  3789. sig[2] & HW_PRTY_ASSERT_SET_2,
  3790. sig[3] & HW_PRTY_ASSERT_SET_3,
  3791. sig[4] & HW_PRTY_ASSERT_SET_4);
  3792. if (print)
  3793. netdev_err(bp->dev,
  3794. "Parity errors detected in blocks: ");
  3795. par_num = bnx2x_check_blocks_with_parity0(
  3796. sig[0] & HW_PRTY_ASSERT_SET_0, par_num, print);
  3797. par_num = bnx2x_check_blocks_with_parity1(
  3798. sig[1] & HW_PRTY_ASSERT_SET_1, par_num, global, print);
  3799. par_num = bnx2x_check_blocks_with_parity2(
  3800. sig[2] & HW_PRTY_ASSERT_SET_2, par_num, print);
  3801. par_num = bnx2x_check_blocks_with_parity3(
  3802. sig[3] & HW_PRTY_ASSERT_SET_3, par_num, global, print);
  3803. par_num = bnx2x_check_blocks_with_parity4(
  3804. sig[4] & HW_PRTY_ASSERT_SET_4, par_num, print);
  3805. if (print)
  3806. pr_cont("\n");
  3807. return true;
  3808. } else
  3809. return false;
  3810. }
  3811. /**
  3812. * bnx2x_chk_parity_attn - checks for parity attentions.
  3813. *
  3814. * @bp: driver handle
  3815. * @global: true if there was a global attention
  3816. * @print: show parity attention in syslog
  3817. */
  3818. bool bnx2x_chk_parity_attn(struct bnx2x *bp, bool *global, bool print)
  3819. {
  3820. struct attn_route attn = { {0} };
  3821. int port = BP_PORT(bp);
  3822. attn.sig[0] = REG_RD(bp,
  3823. MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 +
  3824. port*4);
  3825. attn.sig[1] = REG_RD(bp,
  3826. MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 +
  3827. port*4);
  3828. attn.sig[2] = REG_RD(bp,
  3829. MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 +
  3830. port*4);
  3831. attn.sig[3] = REG_RD(bp,
  3832. MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 +
  3833. port*4);
  3834. if (!CHIP_IS_E1x(bp))
  3835. attn.sig[4] = REG_RD(bp,
  3836. MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 +
  3837. port*4);
  3838. return bnx2x_parity_attn(bp, global, print, attn.sig);
  3839. }
  3840. static void bnx2x_attn_int_deasserted4(struct bnx2x *bp, u32 attn)
  3841. {
  3842. u32 val;
  3843. if (attn & AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT) {
  3844. val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS_CLR);
  3845. BNX2X_ERR("PGLUE hw attention 0x%x\n", val);
  3846. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR)
  3847. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR\n");
  3848. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR)
  3849. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR\n");
  3850. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN)
  3851. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN\n");
  3852. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN)
  3853. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN\n");
  3854. if (val &
  3855. PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN)
  3856. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN\n");
  3857. if (val &
  3858. PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN)
  3859. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN\n");
  3860. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN)
  3861. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN\n");
  3862. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN)
  3863. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN\n");
  3864. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW)
  3865. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW\n");
  3866. }
  3867. if (attn & AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT) {
  3868. val = REG_RD(bp, ATC_REG_ATC_INT_STS_CLR);
  3869. BNX2X_ERR("ATC hw attention 0x%x\n", val);
  3870. if (val & ATC_ATC_INT_STS_REG_ADDRESS_ERROR)
  3871. BNX2X_ERR("ATC_ATC_INT_STS_REG_ADDRESS_ERROR\n");
  3872. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND)
  3873. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND\n");
  3874. if (val & ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS)
  3875. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS\n");
  3876. if (val & ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT)
  3877. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT\n");
  3878. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR)
  3879. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR\n");
  3880. if (val & ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU)
  3881. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU\n");
  3882. }
  3883. if (attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  3884. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)) {
  3885. BNX2X_ERR("FATAL parity attention set4 0x%x\n",
  3886. (u32)(attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  3887. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)));
  3888. }
  3889. }
  3890. static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted)
  3891. {
  3892. struct attn_route attn, *group_mask;
  3893. int port = BP_PORT(bp);
  3894. int index;
  3895. u32 reg_addr;
  3896. u32 val;
  3897. u32 aeu_mask;
  3898. bool global = false;
  3899. /* need to take HW lock because MCP or other port might also
  3900. try to handle this event */
  3901. bnx2x_acquire_alr(bp);
  3902. if (bnx2x_chk_parity_attn(bp, &global, true)) {
  3903. #ifndef BNX2X_STOP_ON_ERROR
  3904. bp->recovery_state = BNX2X_RECOVERY_INIT;
  3905. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  3906. /* Disable HW interrupts */
  3907. bnx2x_int_disable(bp);
  3908. /* In case of parity errors don't handle attentions so that
  3909. * other function would "see" parity errors.
  3910. */
  3911. #else
  3912. bnx2x_panic();
  3913. #endif
  3914. bnx2x_release_alr(bp);
  3915. return;
  3916. }
  3917. attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
  3918. attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
  3919. attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
  3920. attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
  3921. if (!CHIP_IS_E1x(bp))
  3922. attn.sig[4] =
  3923. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4);
  3924. else
  3925. attn.sig[4] = 0;
  3926. DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x %08x\n",
  3927. attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3], attn.sig[4]);
  3928. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  3929. if (deasserted & (1 << index)) {
  3930. group_mask = &bp->attn_group[index];
  3931. DP(NETIF_MSG_HW, "group[%d]: %08x %08x %08x %08x %08x\n",
  3932. index,
  3933. group_mask->sig[0], group_mask->sig[1],
  3934. group_mask->sig[2], group_mask->sig[3],
  3935. group_mask->sig[4]);
  3936. bnx2x_attn_int_deasserted4(bp,
  3937. attn.sig[4] & group_mask->sig[4]);
  3938. bnx2x_attn_int_deasserted3(bp,
  3939. attn.sig[3] & group_mask->sig[3]);
  3940. bnx2x_attn_int_deasserted1(bp,
  3941. attn.sig[1] & group_mask->sig[1]);
  3942. bnx2x_attn_int_deasserted2(bp,
  3943. attn.sig[2] & group_mask->sig[2]);
  3944. bnx2x_attn_int_deasserted0(bp,
  3945. attn.sig[0] & group_mask->sig[0]);
  3946. }
  3947. }
  3948. bnx2x_release_alr(bp);
  3949. if (bp->common.int_block == INT_BLOCK_HC)
  3950. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  3951. COMMAND_REG_ATTN_BITS_CLR);
  3952. else
  3953. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_CLR_UPPER*8);
  3954. val = ~deasserted;
  3955. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", val,
  3956. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  3957. REG_WR(bp, reg_addr, val);
  3958. if (~bp->attn_state & deasserted)
  3959. BNX2X_ERR("IGU ERROR\n");
  3960. reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  3961. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  3962. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3963. aeu_mask = REG_RD(bp, reg_addr);
  3964. DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n",
  3965. aeu_mask, deasserted);
  3966. aeu_mask |= (deasserted & 0x3ff);
  3967. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  3968. REG_WR(bp, reg_addr, aeu_mask);
  3969. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3970. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  3971. bp->attn_state &= ~deasserted;
  3972. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  3973. }
  3974. static void bnx2x_attn_int(struct bnx2x *bp)
  3975. {
  3976. /* read local copy of bits */
  3977. u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block.
  3978. attn_bits);
  3979. u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block.
  3980. attn_bits_ack);
  3981. u32 attn_state = bp->attn_state;
  3982. /* look for changed bits */
  3983. u32 asserted = attn_bits & ~attn_ack & ~attn_state;
  3984. u32 deasserted = ~attn_bits & attn_ack & attn_state;
  3985. DP(NETIF_MSG_HW,
  3986. "attn_bits %x attn_ack %x asserted %x deasserted %x\n",
  3987. attn_bits, attn_ack, asserted, deasserted);
  3988. if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state))
  3989. BNX2X_ERR("BAD attention state\n");
  3990. /* handle bits that were raised */
  3991. if (asserted)
  3992. bnx2x_attn_int_asserted(bp, asserted);
  3993. if (deasserted)
  3994. bnx2x_attn_int_deasserted(bp, deasserted);
  3995. }
  3996. void bnx2x_igu_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 segment,
  3997. u16 index, u8 op, u8 update)
  3998. {
  3999. u32 igu_addr = bp->igu_base_addr;
  4000. igu_addr += (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8;
  4001. bnx2x_igu_ack_sb_gen(bp, igu_sb_id, segment, index, op, update,
  4002. igu_addr);
  4003. }
  4004. static void bnx2x_update_eq_prod(struct bnx2x *bp, u16 prod)
  4005. {
  4006. /* No memory barriers */
  4007. storm_memset_eq_prod(bp, prod, BP_FUNC(bp));
  4008. mmiowb(); /* keep prod updates ordered */
  4009. }
  4010. static int bnx2x_cnic_handle_cfc_del(struct bnx2x *bp, u32 cid,
  4011. union event_ring_elem *elem)
  4012. {
  4013. u8 err = elem->message.error;
  4014. if (!bp->cnic_eth_dev.starting_cid ||
  4015. (cid < bp->cnic_eth_dev.starting_cid &&
  4016. cid != bp->cnic_eth_dev.iscsi_l2_cid))
  4017. return 1;
  4018. DP(BNX2X_MSG_SP, "got delete ramrod for CNIC CID %d\n", cid);
  4019. if (unlikely(err)) {
  4020. BNX2X_ERR("got delete ramrod for CNIC CID %d with error!\n",
  4021. cid);
  4022. bnx2x_panic_dump(bp, false);
  4023. }
  4024. bnx2x_cnic_cfc_comp(bp, cid, err);
  4025. return 0;
  4026. }
  4027. static void bnx2x_handle_mcast_eqe(struct bnx2x *bp)
  4028. {
  4029. struct bnx2x_mcast_ramrod_params rparam;
  4030. int rc;
  4031. memset(&rparam, 0, sizeof(rparam));
  4032. rparam.mcast_obj = &bp->mcast_obj;
  4033. netif_addr_lock_bh(bp->dev);
  4034. /* Clear pending state for the last command */
  4035. bp->mcast_obj.raw.clear_pending(&bp->mcast_obj.raw);
  4036. /* If there are pending mcast commands - send them */
  4037. if (bp->mcast_obj.check_pending(&bp->mcast_obj)) {
  4038. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT);
  4039. if (rc < 0)
  4040. BNX2X_ERR("Failed to send pending mcast commands: %d\n",
  4041. rc);
  4042. }
  4043. netif_addr_unlock_bh(bp->dev);
  4044. }
  4045. static void bnx2x_handle_classification_eqe(struct bnx2x *bp,
  4046. union event_ring_elem *elem)
  4047. {
  4048. unsigned long ramrod_flags = 0;
  4049. int rc = 0;
  4050. u32 cid = elem->message.data.eth_event.echo & BNX2X_SWCID_MASK;
  4051. struct bnx2x_vlan_mac_obj *vlan_mac_obj;
  4052. /* Always push next commands out, don't wait here */
  4053. __set_bit(RAMROD_CONT, &ramrod_flags);
  4054. switch (elem->message.data.eth_event.echo >> BNX2X_SWCID_SHIFT) {
  4055. case BNX2X_FILTER_MAC_PENDING:
  4056. DP(BNX2X_MSG_SP, "Got SETUP_MAC completions\n");
  4057. if (CNIC_LOADED(bp) && (cid == BNX2X_ISCSI_ETH_CID(bp)))
  4058. vlan_mac_obj = &bp->iscsi_l2_mac_obj;
  4059. else
  4060. vlan_mac_obj = &bp->sp_objs[cid].mac_obj;
  4061. break;
  4062. case BNX2X_FILTER_MCAST_PENDING:
  4063. DP(BNX2X_MSG_SP, "Got SETUP_MCAST completions\n");
  4064. /* This is only relevant for 57710 where multicast MACs are
  4065. * configured as unicast MACs using the same ramrod.
  4066. */
  4067. bnx2x_handle_mcast_eqe(bp);
  4068. return;
  4069. default:
  4070. BNX2X_ERR("Unsupported classification command: %d\n",
  4071. elem->message.data.eth_event.echo);
  4072. return;
  4073. }
  4074. rc = vlan_mac_obj->complete(bp, vlan_mac_obj, elem, &ramrod_flags);
  4075. if (rc < 0)
  4076. BNX2X_ERR("Failed to schedule new commands: %d\n", rc);
  4077. else if (rc > 0)
  4078. DP(BNX2X_MSG_SP, "Scheduled next pending commands...\n");
  4079. }
  4080. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start);
  4081. static void bnx2x_handle_rx_mode_eqe(struct bnx2x *bp)
  4082. {
  4083. netif_addr_lock_bh(bp->dev);
  4084. clear_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  4085. /* Send rx_mode command again if was requested */
  4086. if (test_and_clear_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state))
  4087. bnx2x_set_storm_rx_mode(bp);
  4088. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED,
  4089. &bp->sp_state))
  4090. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  4091. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED,
  4092. &bp->sp_state))
  4093. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  4094. netif_addr_unlock_bh(bp->dev);
  4095. }
  4096. static void bnx2x_after_afex_vif_lists(struct bnx2x *bp,
  4097. union event_ring_elem *elem)
  4098. {
  4099. if (elem->message.data.vif_list_event.echo == VIF_LIST_RULE_GET) {
  4100. DP(BNX2X_MSG_SP,
  4101. "afex: ramrod completed VIF LIST_GET, addrs 0x%x\n",
  4102. elem->message.data.vif_list_event.func_bit_map);
  4103. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTGET_ACK,
  4104. elem->message.data.vif_list_event.func_bit_map);
  4105. } else if (elem->message.data.vif_list_event.echo ==
  4106. VIF_LIST_RULE_SET) {
  4107. DP(BNX2X_MSG_SP, "afex: ramrod completed VIF LIST_SET\n");
  4108. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTSET_ACK, 0);
  4109. }
  4110. }
  4111. /* called with rtnl_lock */
  4112. static void bnx2x_after_function_update(struct bnx2x *bp)
  4113. {
  4114. int q, rc;
  4115. struct bnx2x_fastpath *fp;
  4116. struct bnx2x_queue_state_params queue_params = {NULL};
  4117. struct bnx2x_queue_update_params *q_update_params =
  4118. &queue_params.params.update;
  4119. /* Send Q update command with afex vlan removal values for all Qs */
  4120. queue_params.cmd = BNX2X_Q_CMD_UPDATE;
  4121. /* set silent vlan removal values according to vlan mode */
  4122. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM_CHNG,
  4123. &q_update_params->update_flags);
  4124. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM,
  4125. &q_update_params->update_flags);
  4126. __set_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
  4127. /* in access mode mark mask and value are 0 to strip all vlans */
  4128. if (bp->afex_vlan_mode == FUNC_MF_CFG_AFEX_VLAN_ACCESS_MODE) {
  4129. q_update_params->silent_removal_value = 0;
  4130. q_update_params->silent_removal_mask = 0;
  4131. } else {
  4132. q_update_params->silent_removal_value =
  4133. (bp->afex_def_vlan_tag & VLAN_VID_MASK);
  4134. q_update_params->silent_removal_mask = VLAN_VID_MASK;
  4135. }
  4136. for_each_eth_queue(bp, q) {
  4137. /* Set the appropriate Queue object */
  4138. fp = &bp->fp[q];
  4139. queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  4140. /* send the ramrod */
  4141. rc = bnx2x_queue_state_change(bp, &queue_params);
  4142. if (rc < 0)
  4143. BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
  4144. q);
  4145. }
  4146. if (!NO_FCOE(bp)) {
  4147. fp = &bp->fp[FCOE_IDX(bp)];
  4148. queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  4149. /* clear pending completion bit */
  4150. __clear_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
  4151. /* mark latest Q bit */
  4152. smp_mb__before_clear_bit();
  4153. set_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
  4154. smp_mb__after_clear_bit();
  4155. /* send Q update ramrod for FCoE Q */
  4156. rc = bnx2x_queue_state_change(bp, &queue_params);
  4157. if (rc < 0)
  4158. BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
  4159. q);
  4160. } else {
  4161. /* If no FCoE ring - ACK MCP now */
  4162. bnx2x_link_report(bp);
  4163. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  4164. }
  4165. }
  4166. static struct bnx2x_queue_sp_obj *bnx2x_cid_to_q_obj(
  4167. struct bnx2x *bp, u32 cid)
  4168. {
  4169. DP(BNX2X_MSG_SP, "retrieving fp from cid %d\n", cid);
  4170. if (CNIC_LOADED(bp) && (cid == BNX2X_FCOE_ETH_CID(bp)))
  4171. return &bnx2x_fcoe_sp_obj(bp, q_obj);
  4172. else
  4173. return &bp->sp_objs[CID_TO_FP(cid, bp)].q_obj;
  4174. }
  4175. static void bnx2x_eq_int(struct bnx2x *bp)
  4176. {
  4177. u16 hw_cons, sw_cons, sw_prod;
  4178. union event_ring_elem *elem;
  4179. u8 echo;
  4180. u32 cid;
  4181. u8 opcode;
  4182. int rc, spqe_cnt = 0;
  4183. struct bnx2x_queue_sp_obj *q_obj;
  4184. struct bnx2x_func_sp_obj *f_obj = &bp->func_obj;
  4185. struct bnx2x_raw_obj *rss_raw = &bp->rss_conf_obj.raw;
  4186. hw_cons = le16_to_cpu(*bp->eq_cons_sb);
  4187. /* The hw_cos range is 1-255, 257 - the sw_cons range is 0-254, 256.
  4188. * when we get the the next-page we nned to adjust so the loop
  4189. * condition below will be met. The next element is the size of a
  4190. * regular element and hence incrementing by 1
  4191. */
  4192. if ((hw_cons & EQ_DESC_MAX_PAGE) == EQ_DESC_MAX_PAGE)
  4193. hw_cons++;
  4194. /* This function may never run in parallel with itself for a
  4195. * specific bp, thus there is no need in "paired" read memory
  4196. * barrier here.
  4197. */
  4198. sw_cons = bp->eq_cons;
  4199. sw_prod = bp->eq_prod;
  4200. DP(BNX2X_MSG_SP, "EQ: hw_cons %u sw_cons %u bp->eq_spq_left %x\n",
  4201. hw_cons, sw_cons, atomic_read(&bp->eq_spq_left));
  4202. for (; sw_cons != hw_cons;
  4203. sw_prod = NEXT_EQ_IDX(sw_prod), sw_cons = NEXT_EQ_IDX(sw_cons)) {
  4204. elem = &bp->eq_ring[EQ_DESC(sw_cons)];
  4205. rc = bnx2x_iov_eq_sp_event(bp, elem);
  4206. if (!rc) {
  4207. DP(BNX2X_MSG_IOV, "bnx2x_iov_eq_sp_event returned %d\n",
  4208. rc);
  4209. goto next_spqe;
  4210. }
  4211. cid = SW_CID(elem->message.data.cfc_del_event.cid);
  4212. opcode = elem->message.opcode;
  4213. /* handle eq element */
  4214. switch (opcode) {
  4215. case EVENT_RING_OPCODE_VF_PF_CHANNEL:
  4216. DP(BNX2X_MSG_IOV, "vf pf channel element on eq\n");
  4217. bnx2x_vf_mbx(bp, &elem->message.data.vf_pf_event);
  4218. continue;
  4219. case EVENT_RING_OPCODE_STAT_QUERY:
  4220. DP(BNX2X_MSG_SP | BNX2X_MSG_STATS,
  4221. "got statistics comp event %d\n",
  4222. bp->stats_comp++);
  4223. /* nothing to do with stats comp */
  4224. goto next_spqe;
  4225. case EVENT_RING_OPCODE_CFC_DEL:
  4226. /* handle according to cid range */
  4227. /*
  4228. * we may want to verify here that the bp state is
  4229. * HALTING
  4230. */
  4231. DP(BNX2X_MSG_SP,
  4232. "got delete ramrod for MULTI[%d]\n", cid);
  4233. if (CNIC_LOADED(bp) &&
  4234. !bnx2x_cnic_handle_cfc_del(bp, cid, elem))
  4235. goto next_spqe;
  4236. q_obj = bnx2x_cid_to_q_obj(bp, cid);
  4237. if (q_obj->complete_cmd(bp, q_obj, BNX2X_Q_CMD_CFC_DEL))
  4238. break;
  4239. goto next_spqe;
  4240. case EVENT_RING_OPCODE_STOP_TRAFFIC:
  4241. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got STOP TRAFFIC\n");
  4242. if (f_obj->complete_cmd(bp, f_obj,
  4243. BNX2X_F_CMD_TX_STOP))
  4244. break;
  4245. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_PAUSED);
  4246. goto next_spqe;
  4247. case EVENT_RING_OPCODE_START_TRAFFIC:
  4248. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got START TRAFFIC\n");
  4249. if (f_obj->complete_cmd(bp, f_obj,
  4250. BNX2X_F_CMD_TX_START))
  4251. break;
  4252. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_RELEASED);
  4253. goto next_spqe;
  4254. case EVENT_RING_OPCODE_FUNCTION_UPDATE:
  4255. echo = elem->message.data.function_update_event.echo;
  4256. if (echo == SWITCH_UPDATE) {
  4257. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4258. "got FUNC_SWITCH_UPDATE ramrod\n");
  4259. if (f_obj->complete_cmd(
  4260. bp, f_obj, BNX2X_F_CMD_SWITCH_UPDATE))
  4261. break;
  4262. } else {
  4263. DP(BNX2X_MSG_SP | BNX2X_MSG_MCP,
  4264. "AFEX: ramrod completed FUNCTION_UPDATE\n");
  4265. f_obj->complete_cmd(bp, f_obj,
  4266. BNX2X_F_CMD_AFEX_UPDATE);
  4267. /* We will perform the Queues update from
  4268. * sp_rtnl task as all Queue SP operations
  4269. * should run under rtnl_lock.
  4270. */
  4271. smp_mb__before_clear_bit();
  4272. set_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE,
  4273. &bp->sp_rtnl_state);
  4274. smp_mb__after_clear_bit();
  4275. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  4276. }
  4277. goto next_spqe;
  4278. case EVENT_RING_OPCODE_AFEX_VIF_LISTS:
  4279. f_obj->complete_cmd(bp, f_obj,
  4280. BNX2X_F_CMD_AFEX_VIFLISTS);
  4281. bnx2x_after_afex_vif_lists(bp, elem);
  4282. goto next_spqe;
  4283. case EVENT_RING_OPCODE_FUNCTION_START:
  4284. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4285. "got FUNC_START ramrod\n");
  4286. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_START))
  4287. break;
  4288. goto next_spqe;
  4289. case EVENT_RING_OPCODE_FUNCTION_STOP:
  4290. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4291. "got FUNC_STOP ramrod\n");
  4292. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_STOP))
  4293. break;
  4294. goto next_spqe;
  4295. }
  4296. switch (opcode | bp->state) {
  4297. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4298. BNX2X_STATE_OPEN):
  4299. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4300. BNX2X_STATE_OPENING_WAIT4_PORT):
  4301. cid = elem->message.data.eth_event.echo &
  4302. BNX2X_SWCID_MASK;
  4303. DP(BNX2X_MSG_SP, "got RSS_UPDATE ramrod. CID %d\n",
  4304. cid);
  4305. rss_raw->clear_pending(rss_raw);
  4306. break;
  4307. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_OPEN):
  4308. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_DIAG):
  4309. case (EVENT_RING_OPCODE_SET_MAC |
  4310. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4311. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4312. BNX2X_STATE_OPEN):
  4313. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4314. BNX2X_STATE_DIAG):
  4315. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4316. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4317. DP(BNX2X_MSG_SP, "got (un)set mac ramrod\n");
  4318. bnx2x_handle_classification_eqe(bp, elem);
  4319. break;
  4320. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4321. BNX2X_STATE_OPEN):
  4322. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4323. BNX2X_STATE_DIAG):
  4324. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4325. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4326. DP(BNX2X_MSG_SP, "got mcast ramrod\n");
  4327. bnx2x_handle_mcast_eqe(bp);
  4328. break;
  4329. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4330. BNX2X_STATE_OPEN):
  4331. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4332. BNX2X_STATE_DIAG):
  4333. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4334. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4335. DP(BNX2X_MSG_SP, "got rx_mode ramrod\n");
  4336. bnx2x_handle_rx_mode_eqe(bp);
  4337. break;
  4338. default:
  4339. /* unknown event log error and continue */
  4340. BNX2X_ERR("Unknown EQ event %d, bp->state 0x%x\n",
  4341. elem->message.opcode, bp->state);
  4342. }
  4343. next_spqe:
  4344. spqe_cnt++;
  4345. } /* for */
  4346. smp_mb__before_atomic_inc();
  4347. atomic_add(spqe_cnt, &bp->eq_spq_left);
  4348. bp->eq_cons = sw_cons;
  4349. bp->eq_prod = sw_prod;
  4350. /* Make sure that above mem writes were issued towards the memory */
  4351. smp_wmb();
  4352. /* update producer */
  4353. bnx2x_update_eq_prod(bp, bp->eq_prod);
  4354. }
  4355. static void bnx2x_sp_task(struct work_struct *work)
  4356. {
  4357. struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work);
  4358. DP(BNX2X_MSG_SP, "sp task invoked\n");
  4359. /* make sure the atomic interupt_occurred has been written */
  4360. smp_rmb();
  4361. if (atomic_read(&bp->interrupt_occurred)) {
  4362. /* what work needs to be performed? */
  4363. u16 status = bnx2x_update_dsb_idx(bp);
  4364. DP(BNX2X_MSG_SP, "status %x\n", status);
  4365. DP(BNX2X_MSG_SP, "setting interrupt_occurred to 0\n");
  4366. atomic_set(&bp->interrupt_occurred, 0);
  4367. /* HW attentions */
  4368. if (status & BNX2X_DEF_SB_ATT_IDX) {
  4369. bnx2x_attn_int(bp);
  4370. status &= ~BNX2X_DEF_SB_ATT_IDX;
  4371. }
  4372. /* SP events: STAT_QUERY and others */
  4373. if (status & BNX2X_DEF_SB_IDX) {
  4374. struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
  4375. if (FCOE_INIT(bp) &&
  4376. (bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp))) {
  4377. /* Prevent local bottom-halves from running as
  4378. * we are going to change the local NAPI list.
  4379. */
  4380. local_bh_disable();
  4381. napi_schedule(&bnx2x_fcoe(bp, napi));
  4382. local_bh_enable();
  4383. }
  4384. /* Handle EQ completions */
  4385. bnx2x_eq_int(bp);
  4386. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID,
  4387. le16_to_cpu(bp->def_idx), IGU_INT_NOP, 1);
  4388. status &= ~BNX2X_DEF_SB_IDX;
  4389. }
  4390. /* if status is non zero then perhaps something went wrong */
  4391. if (unlikely(status))
  4392. DP(BNX2X_MSG_SP,
  4393. "got an unknown interrupt! (status 0x%x)\n", status);
  4394. /* ack status block only if something was actually handled */
  4395. bnx2x_ack_sb(bp, bp->igu_dsb_id, ATTENTION_ID,
  4396. le16_to_cpu(bp->def_att_idx), IGU_INT_ENABLE, 1);
  4397. }
  4398. /* must be called after the EQ processing (since eq leads to sriov
  4399. * ramrod completion flows).
  4400. * This flow may have been scheduled by the arrival of a ramrod
  4401. * completion, or by the sriov code rescheduling itself.
  4402. */
  4403. bnx2x_iov_sp_task(bp);
  4404. /* afex - poll to check if VIFSET_ACK should be sent to MFW */
  4405. if (test_and_clear_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK,
  4406. &bp->sp_state)) {
  4407. bnx2x_link_report(bp);
  4408. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  4409. }
  4410. }
  4411. irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance)
  4412. {
  4413. struct net_device *dev = dev_instance;
  4414. struct bnx2x *bp = netdev_priv(dev);
  4415. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0,
  4416. IGU_INT_DISABLE, 0);
  4417. #ifdef BNX2X_STOP_ON_ERROR
  4418. if (unlikely(bp->panic))
  4419. return IRQ_HANDLED;
  4420. #endif
  4421. if (CNIC_LOADED(bp)) {
  4422. struct cnic_ops *c_ops;
  4423. rcu_read_lock();
  4424. c_ops = rcu_dereference(bp->cnic_ops);
  4425. if (c_ops)
  4426. c_ops->cnic_handler(bp->cnic_data, NULL);
  4427. rcu_read_unlock();
  4428. }
  4429. /* schedule sp task to perform default status block work, ack
  4430. * attentions and enable interrupts.
  4431. */
  4432. bnx2x_schedule_sp_task(bp);
  4433. return IRQ_HANDLED;
  4434. }
  4435. /* end of slow path */
  4436. void bnx2x_drv_pulse(struct bnx2x *bp)
  4437. {
  4438. SHMEM_WR(bp, func_mb[BP_FW_MB_IDX(bp)].drv_pulse_mb,
  4439. bp->fw_drv_pulse_wr_seq);
  4440. }
  4441. static void bnx2x_timer(unsigned long data)
  4442. {
  4443. struct bnx2x *bp = (struct bnx2x *) data;
  4444. if (!netif_running(bp->dev))
  4445. return;
  4446. if (IS_PF(bp) &&
  4447. !BP_NOMCP(bp)) {
  4448. int mb_idx = BP_FW_MB_IDX(bp);
  4449. u32 drv_pulse;
  4450. u32 mcp_pulse;
  4451. ++bp->fw_drv_pulse_wr_seq;
  4452. bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK;
  4453. /* TBD - add SYSTEM_TIME */
  4454. drv_pulse = bp->fw_drv_pulse_wr_seq;
  4455. bnx2x_drv_pulse(bp);
  4456. mcp_pulse = (SHMEM_RD(bp, func_mb[mb_idx].mcp_pulse_mb) &
  4457. MCP_PULSE_SEQ_MASK);
  4458. /* The delta between driver pulse and mcp response
  4459. * should be 1 (before mcp response) or 0 (after mcp response)
  4460. */
  4461. if ((drv_pulse != mcp_pulse) &&
  4462. (drv_pulse != ((mcp_pulse + 1) & MCP_PULSE_SEQ_MASK))) {
  4463. /* someone lost a heartbeat... */
  4464. BNX2X_ERR("drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
  4465. drv_pulse, mcp_pulse);
  4466. }
  4467. }
  4468. if (bp->state == BNX2X_STATE_OPEN)
  4469. bnx2x_stats_handle(bp, STATS_EVENT_UPDATE);
  4470. /* sample pf vf bulletin board for new posts from pf */
  4471. if (IS_VF(bp))
  4472. bnx2x_sample_bulletin(bp);
  4473. mod_timer(&bp->timer, jiffies + bp->current_interval);
  4474. }
  4475. /* end of Statistics */
  4476. /* nic init */
  4477. /*
  4478. * nic init service functions
  4479. */
  4480. static void bnx2x_fill(struct bnx2x *bp, u32 addr, int fill, u32 len)
  4481. {
  4482. u32 i;
  4483. if (!(len%4) && !(addr%4))
  4484. for (i = 0; i < len; i += 4)
  4485. REG_WR(bp, addr + i, fill);
  4486. else
  4487. for (i = 0; i < len; i++)
  4488. REG_WR8(bp, addr + i, fill);
  4489. }
  4490. /* helper: writes FP SP data to FW - data_size in dwords */
  4491. static void bnx2x_wr_fp_sb_data(struct bnx2x *bp,
  4492. int fw_sb_id,
  4493. u32 *sb_data_p,
  4494. u32 data_size)
  4495. {
  4496. int index;
  4497. for (index = 0; index < data_size; index++)
  4498. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4499. CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id) +
  4500. sizeof(u32)*index,
  4501. *(sb_data_p + index));
  4502. }
  4503. static void bnx2x_zero_fp_sb(struct bnx2x *bp, int fw_sb_id)
  4504. {
  4505. u32 *sb_data_p;
  4506. u32 data_size = 0;
  4507. struct hc_status_block_data_e2 sb_data_e2;
  4508. struct hc_status_block_data_e1x sb_data_e1x;
  4509. /* disable the function first */
  4510. if (!CHIP_IS_E1x(bp)) {
  4511. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  4512. sb_data_e2.common.state = SB_DISABLED;
  4513. sb_data_e2.common.p_func.vf_valid = false;
  4514. sb_data_p = (u32 *)&sb_data_e2;
  4515. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  4516. } else {
  4517. memset(&sb_data_e1x, 0,
  4518. sizeof(struct hc_status_block_data_e1x));
  4519. sb_data_e1x.common.state = SB_DISABLED;
  4520. sb_data_e1x.common.p_func.vf_valid = false;
  4521. sb_data_p = (u32 *)&sb_data_e1x;
  4522. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  4523. }
  4524. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  4525. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4526. CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id), 0,
  4527. CSTORM_STATUS_BLOCK_SIZE);
  4528. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4529. CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id), 0,
  4530. CSTORM_SYNC_BLOCK_SIZE);
  4531. }
  4532. /* helper: writes SP SB data to FW */
  4533. static void bnx2x_wr_sp_sb_data(struct bnx2x *bp,
  4534. struct hc_sp_status_block_data *sp_sb_data)
  4535. {
  4536. int func = BP_FUNC(bp);
  4537. int i;
  4538. for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
  4539. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4540. CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
  4541. i*sizeof(u32),
  4542. *((u32 *)sp_sb_data + i));
  4543. }
  4544. static void bnx2x_zero_sp_sb(struct bnx2x *bp)
  4545. {
  4546. int func = BP_FUNC(bp);
  4547. struct hc_sp_status_block_data sp_sb_data;
  4548. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  4549. sp_sb_data.state = SB_DISABLED;
  4550. sp_sb_data.p_func.vf_valid = false;
  4551. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  4552. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4553. CSTORM_SP_STATUS_BLOCK_OFFSET(func), 0,
  4554. CSTORM_SP_STATUS_BLOCK_SIZE);
  4555. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4556. CSTORM_SP_SYNC_BLOCK_OFFSET(func), 0,
  4557. CSTORM_SP_SYNC_BLOCK_SIZE);
  4558. }
  4559. static void bnx2x_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm,
  4560. int igu_sb_id, int igu_seg_id)
  4561. {
  4562. hc_sm->igu_sb_id = igu_sb_id;
  4563. hc_sm->igu_seg_id = igu_seg_id;
  4564. hc_sm->timer_value = 0xFF;
  4565. hc_sm->time_to_expire = 0xFFFFFFFF;
  4566. }
  4567. /* allocates state machine ids. */
  4568. static void bnx2x_map_sb_state_machines(struct hc_index_data *index_data)
  4569. {
  4570. /* zero out state machine indices */
  4571. /* rx indices */
  4572. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4573. /* tx indices */
  4574. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4575. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags &= ~HC_INDEX_DATA_SM_ID;
  4576. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags &= ~HC_INDEX_DATA_SM_ID;
  4577. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags &= ~HC_INDEX_DATA_SM_ID;
  4578. /* map indices */
  4579. /* rx indices */
  4580. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags |=
  4581. SM_RX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4582. /* tx indices */
  4583. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags |=
  4584. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4585. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags |=
  4586. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4587. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags |=
  4588. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4589. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags |=
  4590. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4591. }
  4592. void bnx2x_init_sb(struct bnx2x *bp, dma_addr_t mapping, int vfid,
  4593. u8 vf_valid, int fw_sb_id, int igu_sb_id)
  4594. {
  4595. int igu_seg_id;
  4596. struct hc_status_block_data_e2 sb_data_e2;
  4597. struct hc_status_block_data_e1x sb_data_e1x;
  4598. struct hc_status_block_sm *hc_sm_p;
  4599. int data_size;
  4600. u32 *sb_data_p;
  4601. if (CHIP_INT_MODE_IS_BC(bp))
  4602. igu_seg_id = HC_SEG_ACCESS_NORM;
  4603. else
  4604. igu_seg_id = IGU_SEG_ACCESS_NORM;
  4605. bnx2x_zero_fp_sb(bp, fw_sb_id);
  4606. if (!CHIP_IS_E1x(bp)) {
  4607. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  4608. sb_data_e2.common.state = SB_ENABLED;
  4609. sb_data_e2.common.p_func.pf_id = BP_FUNC(bp);
  4610. sb_data_e2.common.p_func.vf_id = vfid;
  4611. sb_data_e2.common.p_func.vf_valid = vf_valid;
  4612. sb_data_e2.common.p_func.vnic_id = BP_VN(bp);
  4613. sb_data_e2.common.same_igu_sb_1b = true;
  4614. sb_data_e2.common.host_sb_addr.hi = U64_HI(mapping);
  4615. sb_data_e2.common.host_sb_addr.lo = U64_LO(mapping);
  4616. hc_sm_p = sb_data_e2.common.state_machine;
  4617. sb_data_p = (u32 *)&sb_data_e2;
  4618. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  4619. bnx2x_map_sb_state_machines(sb_data_e2.index_data);
  4620. } else {
  4621. memset(&sb_data_e1x, 0,
  4622. sizeof(struct hc_status_block_data_e1x));
  4623. sb_data_e1x.common.state = SB_ENABLED;
  4624. sb_data_e1x.common.p_func.pf_id = BP_FUNC(bp);
  4625. sb_data_e1x.common.p_func.vf_id = 0xff;
  4626. sb_data_e1x.common.p_func.vf_valid = false;
  4627. sb_data_e1x.common.p_func.vnic_id = BP_VN(bp);
  4628. sb_data_e1x.common.same_igu_sb_1b = true;
  4629. sb_data_e1x.common.host_sb_addr.hi = U64_HI(mapping);
  4630. sb_data_e1x.common.host_sb_addr.lo = U64_LO(mapping);
  4631. hc_sm_p = sb_data_e1x.common.state_machine;
  4632. sb_data_p = (u32 *)&sb_data_e1x;
  4633. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  4634. bnx2x_map_sb_state_machines(sb_data_e1x.index_data);
  4635. }
  4636. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_RX_ID],
  4637. igu_sb_id, igu_seg_id);
  4638. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_TX_ID],
  4639. igu_sb_id, igu_seg_id);
  4640. DP(NETIF_MSG_IFUP, "Init FW SB %d\n", fw_sb_id);
  4641. /* write indecies to HW */
  4642. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  4643. }
  4644. static void bnx2x_update_coalesce_sb(struct bnx2x *bp, u8 fw_sb_id,
  4645. u16 tx_usec, u16 rx_usec)
  4646. {
  4647. bnx2x_update_coalesce_sb_index(bp, fw_sb_id, HC_INDEX_ETH_RX_CQ_CONS,
  4648. false, rx_usec);
  4649. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4650. HC_INDEX_ETH_TX_CQ_CONS_COS0, false,
  4651. tx_usec);
  4652. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4653. HC_INDEX_ETH_TX_CQ_CONS_COS1, false,
  4654. tx_usec);
  4655. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4656. HC_INDEX_ETH_TX_CQ_CONS_COS2, false,
  4657. tx_usec);
  4658. }
  4659. static void bnx2x_init_def_sb(struct bnx2x *bp)
  4660. {
  4661. struct host_sp_status_block *def_sb = bp->def_status_blk;
  4662. dma_addr_t mapping = bp->def_status_blk_mapping;
  4663. int igu_sp_sb_index;
  4664. int igu_seg_id;
  4665. int port = BP_PORT(bp);
  4666. int func = BP_FUNC(bp);
  4667. int reg_offset, reg_offset_en5;
  4668. u64 section;
  4669. int index;
  4670. struct hc_sp_status_block_data sp_sb_data;
  4671. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  4672. if (CHIP_INT_MODE_IS_BC(bp)) {
  4673. igu_sp_sb_index = DEF_SB_IGU_ID;
  4674. igu_seg_id = HC_SEG_ACCESS_DEF;
  4675. } else {
  4676. igu_sp_sb_index = bp->igu_dsb_id;
  4677. igu_seg_id = IGU_SEG_ACCESS_DEF;
  4678. }
  4679. /* ATTN */
  4680. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  4681. atten_status_block);
  4682. def_sb->atten_status_block.status_block_id = igu_sp_sb_index;
  4683. bp->attn_state = 0;
  4684. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  4685. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  4686. reg_offset_en5 = (port ? MISC_REG_AEU_ENABLE5_FUNC_1_OUT_0 :
  4687. MISC_REG_AEU_ENABLE5_FUNC_0_OUT_0);
  4688. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  4689. int sindex;
  4690. /* take care of sig[0]..sig[4] */
  4691. for (sindex = 0; sindex < 4; sindex++)
  4692. bp->attn_group[index].sig[sindex] =
  4693. REG_RD(bp, reg_offset + sindex*0x4 + 0x10*index);
  4694. if (!CHIP_IS_E1x(bp))
  4695. /*
  4696. * enable5 is separate from the rest of the registers,
  4697. * and therefore the address skip is 4
  4698. * and not 16 between the different groups
  4699. */
  4700. bp->attn_group[index].sig[4] = REG_RD(bp,
  4701. reg_offset_en5 + 0x4*index);
  4702. else
  4703. bp->attn_group[index].sig[4] = 0;
  4704. }
  4705. if (bp->common.int_block == INT_BLOCK_HC) {
  4706. reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L :
  4707. HC_REG_ATTN_MSG0_ADDR_L);
  4708. REG_WR(bp, reg_offset, U64_LO(section));
  4709. REG_WR(bp, reg_offset + 4, U64_HI(section));
  4710. } else if (!CHIP_IS_E1x(bp)) {
  4711. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_L, U64_LO(section));
  4712. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_H, U64_HI(section));
  4713. }
  4714. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  4715. sp_sb);
  4716. bnx2x_zero_sp_sb(bp);
  4717. sp_sb_data.state = SB_ENABLED;
  4718. sp_sb_data.host_sb_addr.lo = U64_LO(section);
  4719. sp_sb_data.host_sb_addr.hi = U64_HI(section);
  4720. sp_sb_data.igu_sb_id = igu_sp_sb_index;
  4721. sp_sb_data.igu_seg_id = igu_seg_id;
  4722. sp_sb_data.p_func.pf_id = func;
  4723. sp_sb_data.p_func.vnic_id = BP_VN(bp);
  4724. sp_sb_data.p_func.vf_id = 0xff;
  4725. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  4726. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0);
  4727. }
  4728. void bnx2x_update_coalesce(struct bnx2x *bp)
  4729. {
  4730. int i;
  4731. for_each_eth_queue(bp, i)
  4732. bnx2x_update_coalesce_sb(bp, bp->fp[i].fw_sb_id,
  4733. bp->tx_ticks, bp->rx_ticks);
  4734. }
  4735. static void bnx2x_init_sp_ring(struct bnx2x *bp)
  4736. {
  4737. spin_lock_init(&bp->spq_lock);
  4738. atomic_set(&bp->cq_spq_left, MAX_SPQ_PENDING);
  4739. bp->spq_prod_idx = 0;
  4740. bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX;
  4741. bp->spq_prod_bd = bp->spq;
  4742. bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT;
  4743. }
  4744. static void bnx2x_init_eq_ring(struct bnx2x *bp)
  4745. {
  4746. int i;
  4747. for (i = 1; i <= NUM_EQ_PAGES; i++) {
  4748. union event_ring_elem *elem =
  4749. &bp->eq_ring[EQ_DESC_CNT_PAGE * i - 1];
  4750. elem->next_page.addr.hi =
  4751. cpu_to_le32(U64_HI(bp->eq_mapping +
  4752. BCM_PAGE_SIZE * (i % NUM_EQ_PAGES)));
  4753. elem->next_page.addr.lo =
  4754. cpu_to_le32(U64_LO(bp->eq_mapping +
  4755. BCM_PAGE_SIZE*(i % NUM_EQ_PAGES)));
  4756. }
  4757. bp->eq_cons = 0;
  4758. bp->eq_prod = NUM_EQ_DESC;
  4759. bp->eq_cons_sb = BNX2X_EQ_INDEX;
  4760. /* we want a warning message before it gets rought... */
  4761. atomic_set(&bp->eq_spq_left,
  4762. min_t(int, MAX_SP_DESC_CNT - MAX_SPQ_PENDING, NUM_EQ_DESC) - 1);
  4763. }
  4764. /* called with netif_addr_lock_bh() */
  4765. int bnx2x_set_q_rx_mode(struct bnx2x *bp, u8 cl_id,
  4766. unsigned long rx_mode_flags,
  4767. unsigned long rx_accept_flags,
  4768. unsigned long tx_accept_flags,
  4769. unsigned long ramrod_flags)
  4770. {
  4771. struct bnx2x_rx_mode_ramrod_params ramrod_param;
  4772. int rc;
  4773. memset(&ramrod_param, 0, sizeof(ramrod_param));
  4774. /* Prepare ramrod parameters */
  4775. ramrod_param.cid = 0;
  4776. ramrod_param.cl_id = cl_id;
  4777. ramrod_param.rx_mode_obj = &bp->rx_mode_obj;
  4778. ramrod_param.func_id = BP_FUNC(bp);
  4779. ramrod_param.pstate = &bp->sp_state;
  4780. ramrod_param.state = BNX2X_FILTER_RX_MODE_PENDING;
  4781. ramrod_param.rdata = bnx2x_sp(bp, rx_mode_rdata);
  4782. ramrod_param.rdata_mapping = bnx2x_sp_mapping(bp, rx_mode_rdata);
  4783. set_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  4784. ramrod_param.ramrod_flags = ramrod_flags;
  4785. ramrod_param.rx_mode_flags = rx_mode_flags;
  4786. ramrod_param.rx_accept_flags = rx_accept_flags;
  4787. ramrod_param.tx_accept_flags = tx_accept_flags;
  4788. rc = bnx2x_config_rx_mode(bp, &ramrod_param);
  4789. if (rc < 0) {
  4790. BNX2X_ERR("Set rx_mode %d failed\n", bp->rx_mode);
  4791. return rc;
  4792. }
  4793. return 0;
  4794. }
  4795. int bnx2x_fill_accept_flags(struct bnx2x *bp, u32 rx_mode,
  4796. unsigned long *rx_accept_flags,
  4797. unsigned long *tx_accept_flags)
  4798. {
  4799. /* Clear the flags first */
  4800. *rx_accept_flags = 0;
  4801. *tx_accept_flags = 0;
  4802. switch (rx_mode) {
  4803. case BNX2X_RX_MODE_NONE:
  4804. /*
  4805. * 'drop all' supersedes any accept flags that may have been
  4806. * passed to the function.
  4807. */
  4808. break;
  4809. case BNX2X_RX_MODE_NORMAL:
  4810. __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
  4811. __set_bit(BNX2X_ACCEPT_MULTICAST, rx_accept_flags);
  4812. __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
  4813. /* internal switching mode */
  4814. __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
  4815. __set_bit(BNX2X_ACCEPT_MULTICAST, tx_accept_flags);
  4816. __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
  4817. break;
  4818. case BNX2X_RX_MODE_ALLMULTI:
  4819. __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
  4820. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, rx_accept_flags);
  4821. __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
  4822. /* internal switching mode */
  4823. __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
  4824. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, tx_accept_flags);
  4825. __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
  4826. break;
  4827. case BNX2X_RX_MODE_PROMISC:
  4828. /* According to deffinition of SI mode, iface in promisc mode
  4829. * should receive matched and unmatched (in resolution of port)
  4830. * unicast packets.
  4831. */
  4832. __set_bit(BNX2X_ACCEPT_UNMATCHED, rx_accept_flags);
  4833. __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
  4834. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, rx_accept_flags);
  4835. __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
  4836. /* internal switching mode */
  4837. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, tx_accept_flags);
  4838. __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
  4839. if (IS_MF_SI(bp))
  4840. __set_bit(BNX2X_ACCEPT_ALL_UNICAST, tx_accept_flags);
  4841. else
  4842. __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
  4843. break;
  4844. default:
  4845. BNX2X_ERR("Unknown rx_mode: %d\n", rx_mode);
  4846. return -EINVAL;
  4847. }
  4848. /* Set ACCEPT_ANY_VLAN as we do not enable filtering by VLAN */
  4849. if (bp->rx_mode != BNX2X_RX_MODE_NONE) {
  4850. __set_bit(BNX2X_ACCEPT_ANY_VLAN, rx_accept_flags);
  4851. __set_bit(BNX2X_ACCEPT_ANY_VLAN, tx_accept_flags);
  4852. }
  4853. return 0;
  4854. }
  4855. /* called with netif_addr_lock_bh() */
  4856. int bnx2x_set_storm_rx_mode(struct bnx2x *bp)
  4857. {
  4858. unsigned long rx_mode_flags = 0, ramrod_flags = 0;
  4859. unsigned long rx_accept_flags = 0, tx_accept_flags = 0;
  4860. int rc;
  4861. if (!NO_FCOE(bp))
  4862. /* Configure rx_mode of FCoE Queue */
  4863. __set_bit(BNX2X_RX_MODE_FCOE_ETH, &rx_mode_flags);
  4864. rc = bnx2x_fill_accept_flags(bp, bp->rx_mode, &rx_accept_flags,
  4865. &tx_accept_flags);
  4866. if (rc)
  4867. return rc;
  4868. __set_bit(RAMROD_RX, &ramrod_flags);
  4869. __set_bit(RAMROD_TX, &ramrod_flags);
  4870. return bnx2x_set_q_rx_mode(bp, bp->fp->cl_id, rx_mode_flags,
  4871. rx_accept_flags, tx_accept_flags,
  4872. ramrod_flags);
  4873. }
  4874. static void bnx2x_init_internal_common(struct bnx2x *bp)
  4875. {
  4876. int i;
  4877. if (IS_MF_SI(bp))
  4878. /*
  4879. * In switch independent mode, the TSTORM needs to accept
  4880. * packets that failed classification, since approximate match
  4881. * mac addresses aren't written to NIG LLH
  4882. */
  4883. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  4884. TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 2);
  4885. else if (!CHIP_IS_E1(bp)) /* 57710 doesn't support MF */
  4886. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  4887. TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 0);
  4888. /* Zero this manually as its initialization is
  4889. currently missing in the initTool */
  4890. for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++)
  4891. REG_WR(bp, BAR_USTRORM_INTMEM +
  4892. USTORM_AGG_DATA_OFFSET + i * 4, 0);
  4893. if (!CHIP_IS_E1x(bp)) {
  4894. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_IGU_MODE_OFFSET,
  4895. CHIP_INT_MODE_IS_BC(bp) ?
  4896. HC_IGU_BC_MODE : HC_IGU_NBC_MODE);
  4897. }
  4898. }
  4899. static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code)
  4900. {
  4901. switch (load_code) {
  4902. case FW_MSG_CODE_DRV_LOAD_COMMON:
  4903. case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
  4904. bnx2x_init_internal_common(bp);
  4905. /* no break */
  4906. case FW_MSG_CODE_DRV_LOAD_PORT:
  4907. /* nothing to do */
  4908. /* no break */
  4909. case FW_MSG_CODE_DRV_LOAD_FUNCTION:
  4910. /* internal memory per function is
  4911. initialized inside bnx2x_pf_init */
  4912. break;
  4913. default:
  4914. BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
  4915. break;
  4916. }
  4917. }
  4918. static inline u8 bnx2x_fp_igu_sb_id(struct bnx2x_fastpath *fp)
  4919. {
  4920. return fp->bp->igu_base_sb + fp->index + CNIC_SUPPORT(fp->bp);
  4921. }
  4922. static inline u8 bnx2x_fp_fw_sb_id(struct bnx2x_fastpath *fp)
  4923. {
  4924. return fp->bp->base_fw_ndsb + fp->index + CNIC_SUPPORT(fp->bp);
  4925. }
  4926. static u8 bnx2x_fp_cl_id(struct bnx2x_fastpath *fp)
  4927. {
  4928. if (CHIP_IS_E1x(fp->bp))
  4929. return BP_L_ID(fp->bp) + fp->index;
  4930. else /* We want Client ID to be the same as IGU SB ID for 57712 */
  4931. return bnx2x_fp_igu_sb_id(fp);
  4932. }
  4933. static void bnx2x_init_eth_fp(struct bnx2x *bp, int fp_idx)
  4934. {
  4935. struct bnx2x_fastpath *fp = &bp->fp[fp_idx];
  4936. u8 cos;
  4937. unsigned long q_type = 0;
  4938. u32 cids[BNX2X_MULTI_TX_COS] = { 0 };
  4939. fp->rx_queue = fp_idx;
  4940. fp->cid = fp_idx;
  4941. fp->cl_id = bnx2x_fp_cl_id(fp);
  4942. fp->fw_sb_id = bnx2x_fp_fw_sb_id(fp);
  4943. fp->igu_sb_id = bnx2x_fp_igu_sb_id(fp);
  4944. /* qZone id equals to FW (per path) client id */
  4945. fp->cl_qzone_id = bnx2x_fp_qzone_id(fp);
  4946. /* init shortcut */
  4947. fp->ustorm_rx_prods_offset = bnx2x_rx_ustorm_prods_offset(fp);
  4948. /* Setup SB indicies */
  4949. fp->rx_cons_sb = BNX2X_RX_SB_INDEX;
  4950. /* Configure Queue State object */
  4951. __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
  4952. __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
  4953. BUG_ON(fp->max_cos > BNX2X_MULTI_TX_COS);
  4954. /* init tx data */
  4955. for_each_cos_in_tx_queue(fp, cos) {
  4956. bnx2x_init_txdata(bp, fp->txdata_ptr[cos],
  4957. CID_COS_TO_TX_ONLY_CID(fp->cid, cos, bp),
  4958. FP_COS_TO_TXQ(fp, cos, bp),
  4959. BNX2X_TX_SB_INDEX_BASE + cos, fp);
  4960. cids[cos] = fp->txdata_ptr[cos]->cid;
  4961. }
  4962. /* nothing more for vf to do here */
  4963. if (IS_VF(bp))
  4964. return;
  4965. bnx2x_init_sb(bp, fp->status_blk_mapping, BNX2X_VF_ID_INVALID, false,
  4966. fp->fw_sb_id, fp->igu_sb_id);
  4967. bnx2x_update_fpsb_idx(fp);
  4968. bnx2x_init_queue_obj(bp, &bnx2x_sp_obj(bp, fp).q_obj, fp->cl_id, cids,
  4969. fp->max_cos, BP_FUNC(bp), bnx2x_sp(bp, q_rdata),
  4970. bnx2x_sp_mapping(bp, q_rdata), q_type);
  4971. /**
  4972. * Configure classification DBs: Always enable Tx switching
  4973. */
  4974. bnx2x_init_vlan_mac_fp_objs(fp, BNX2X_OBJ_TYPE_RX_TX);
  4975. DP(NETIF_MSG_IFUP,
  4976. "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d fw_sb %d igu_sb %d\n",
  4977. fp_idx, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
  4978. fp->igu_sb_id);
  4979. }
  4980. static void bnx2x_init_tx_ring_one(struct bnx2x_fp_txdata *txdata)
  4981. {
  4982. int i;
  4983. for (i = 1; i <= NUM_TX_RINGS; i++) {
  4984. struct eth_tx_next_bd *tx_next_bd =
  4985. &txdata->tx_desc_ring[TX_DESC_CNT * i - 1].next_bd;
  4986. tx_next_bd->addr_hi =
  4987. cpu_to_le32(U64_HI(txdata->tx_desc_mapping +
  4988. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  4989. tx_next_bd->addr_lo =
  4990. cpu_to_le32(U64_LO(txdata->tx_desc_mapping +
  4991. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  4992. }
  4993. SET_FLAG(txdata->tx_db.data.header.header, DOORBELL_HDR_DB_TYPE, 1);
  4994. txdata->tx_db.data.zero_fill1 = 0;
  4995. txdata->tx_db.data.prod = 0;
  4996. txdata->tx_pkt_prod = 0;
  4997. txdata->tx_pkt_cons = 0;
  4998. txdata->tx_bd_prod = 0;
  4999. txdata->tx_bd_cons = 0;
  5000. txdata->tx_pkt = 0;
  5001. }
  5002. static void bnx2x_init_tx_rings_cnic(struct bnx2x *bp)
  5003. {
  5004. int i;
  5005. for_each_tx_queue_cnic(bp, i)
  5006. bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[0]);
  5007. }
  5008. static void bnx2x_init_tx_rings(struct bnx2x *bp)
  5009. {
  5010. int i;
  5011. u8 cos;
  5012. for_each_eth_queue(bp, i)
  5013. for_each_cos_in_tx_queue(&bp->fp[i], cos)
  5014. bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[cos]);
  5015. }
  5016. void bnx2x_nic_init_cnic(struct bnx2x *bp)
  5017. {
  5018. if (!NO_FCOE(bp))
  5019. bnx2x_init_fcoe_fp(bp);
  5020. bnx2x_init_sb(bp, bp->cnic_sb_mapping,
  5021. BNX2X_VF_ID_INVALID, false,
  5022. bnx2x_cnic_fw_sb_id(bp), bnx2x_cnic_igu_sb_id(bp));
  5023. /* ensure status block indices were read */
  5024. rmb();
  5025. bnx2x_init_rx_rings_cnic(bp);
  5026. bnx2x_init_tx_rings_cnic(bp);
  5027. /* flush all */
  5028. mb();
  5029. mmiowb();
  5030. }
  5031. void bnx2x_nic_init(struct bnx2x *bp, u32 load_code)
  5032. {
  5033. int i;
  5034. for_each_eth_queue(bp, i)
  5035. bnx2x_init_eth_fp(bp, i);
  5036. /* ensure status block indices were read */
  5037. rmb();
  5038. bnx2x_init_rx_rings(bp);
  5039. bnx2x_init_tx_rings(bp);
  5040. if (IS_VF(bp))
  5041. return;
  5042. /* Initialize MOD_ABS interrupts */
  5043. bnx2x_init_mod_abs_int(bp, &bp->link_vars, bp->common.chip_id,
  5044. bp->common.shmem_base, bp->common.shmem2_base,
  5045. BP_PORT(bp));
  5046. bnx2x_init_def_sb(bp);
  5047. bnx2x_update_dsb_idx(bp);
  5048. bnx2x_init_sp_ring(bp);
  5049. bnx2x_init_eq_ring(bp);
  5050. bnx2x_init_internal(bp, load_code);
  5051. bnx2x_pf_init(bp);
  5052. bnx2x_stats_init(bp);
  5053. /* flush all before enabling interrupts */
  5054. mb();
  5055. mmiowb();
  5056. bnx2x_int_enable(bp);
  5057. /* Check for SPIO5 */
  5058. bnx2x_attn_int_deasserted0(bp,
  5059. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + BP_PORT(bp)*4) &
  5060. AEU_INPUTS_ATTN_BITS_SPIO5);
  5061. }
  5062. /* end of nic init */
  5063. /*
  5064. * gzip service functions
  5065. */
  5066. static int bnx2x_gunzip_init(struct bnx2x *bp)
  5067. {
  5068. bp->gunzip_buf = dma_alloc_coherent(&bp->pdev->dev, FW_BUF_SIZE,
  5069. &bp->gunzip_mapping, GFP_KERNEL);
  5070. if (bp->gunzip_buf == NULL)
  5071. goto gunzip_nomem1;
  5072. bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL);
  5073. if (bp->strm == NULL)
  5074. goto gunzip_nomem2;
  5075. bp->strm->workspace = vmalloc(zlib_inflate_workspacesize());
  5076. if (bp->strm->workspace == NULL)
  5077. goto gunzip_nomem3;
  5078. return 0;
  5079. gunzip_nomem3:
  5080. kfree(bp->strm);
  5081. bp->strm = NULL;
  5082. gunzip_nomem2:
  5083. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  5084. bp->gunzip_mapping);
  5085. bp->gunzip_buf = NULL;
  5086. gunzip_nomem1:
  5087. BNX2X_ERR("Cannot allocate firmware buffer for un-compression\n");
  5088. return -ENOMEM;
  5089. }
  5090. static void bnx2x_gunzip_end(struct bnx2x *bp)
  5091. {
  5092. if (bp->strm) {
  5093. vfree(bp->strm->workspace);
  5094. kfree(bp->strm);
  5095. bp->strm = NULL;
  5096. }
  5097. if (bp->gunzip_buf) {
  5098. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  5099. bp->gunzip_mapping);
  5100. bp->gunzip_buf = NULL;
  5101. }
  5102. }
  5103. static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len)
  5104. {
  5105. int n, rc;
  5106. /* check gzip header */
  5107. if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED)) {
  5108. BNX2X_ERR("Bad gzip header\n");
  5109. return -EINVAL;
  5110. }
  5111. n = 10;
  5112. #define FNAME 0x8
  5113. if (zbuf[3] & FNAME)
  5114. while ((zbuf[n++] != 0) && (n < len));
  5115. bp->strm->next_in = (typeof(bp->strm->next_in))zbuf + n;
  5116. bp->strm->avail_in = len - n;
  5117. bp->strm->next_out = bp->gunzip_buf;
  5118. bp->strm->avail_out = FW_BUF_SIZE;
  5119. rc = zlib_inflateInit2(bp->strm, -MAX_WBITS);
  5120. if (rc != Z_OK)
  5121. return rc;
  5122. rc = zlib_inflate(bp->strm, Z_FINISH);
  5123. if ((rc != Z_OK) && (rc != Z_STREAM_END))
  5124. netdev_err(bp->dev, "Firmware decompression error: %s\n",
  5125. bp->strm->msg);
  5126. bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out);
  5127. if (bp->gunzip_outlen & 0x3)
  5128. netdev_err(bp->dev,
  5129. "Firmware decompression error: gunzip_outlen (%d) not aligned\n",
  5130. bp->gunzip_outlen);
  5131. bp->gunzip_outlen >>= 2;
  5132. zlib_inflateEnd(bp->strm);
  5133. if (rc == Z_STREAM_END)
  5134. return 0;
  5135. return rc;
  5136. }
  5137. /* nic load/unload */
  5138. /*
  5139. * General service functions
  5140. */
  5141. /* send a NIG loopback debug packet */
  5142. static void bnx2x_lb_pckt(struct bnx2x *bp)
  5143. {
  5144. u32 wb_write[3];
  5145. /* Ethernet source and destination addresses */
  5146. wb_write[0] = 0x55555555;
  5147. wb_write[1] = 0x55555555;
  5148. wb_write[2] = 0x20; /* SOP */
  5149. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  5150. /* NON-IP protocol */
  5151. wb_write[0] = 0x09000000;
  5152. wb_write[1] = 0x55555555;
  5153. wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */
  5154. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  5155. }
  5156. /* some of the internal memories
  5157. * are not directly readable from the driver
  5158. * to test them we send debug packets
  5159. */
  5160. static int bnx2x_int_mem_test(struct bnx2x *bp)
  5161. {
  5162. int factor;
  5163. int count, i;
  5164. u32 val = 0;
  5165. if (CHIP_REV_IS_FPGA(bp))
  5166. factor = 120;
  5167. else if (CHIP_REV_IS_EMUL(bp))
  5168. factor = 200;
  5169. else
  5170. factor = 1;
  5171. /* Disable inputs of parser neighbor blocks */
  5172. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  5173. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  5174. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  5175. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  5176. /* Write 0 to parser credits for CFC search request */
  5177. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  5178. /* send Ethernet packet */
  5179. bnx2x_lb_pckt(bp);
  5180. /* TODO do i reset NIG statistic? */
  5181. /* Wait until NIG register shows 1 packet of size 0x10 */
  5182. count = 1000 * factor;
  5183. while (count) {
  5184. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5185. val = *bnx2x_sp(bp, wb_data[0]);
  5186. if (val == 0x10)
  5187. break;
  5188. msleep(10);
  5189. count--;
  5190. }
  5191. if (val != 0x10) {
  5192. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  5193. return -1;
  5194. }
  5195. /* Wait until PRS register shows 1 packet */
  5196. count = 1000 * factor;
  5197. while (count) {
  5198. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5199. if (val == 1)
  5200. break;
  5201. msleep(10);
  5202. count--;
  5203. }
  5204. if (val != 0x1) {
  5205. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5206. return -2;
  5207. }
  5208. /* Reset and init BRB, PRS */
  5209. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  5210. msleep(50);
  5211. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  5212. msleep(50);
  5213. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5214. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5215. DP(NETIF_MSG_HW, "part2\n");
  5216. /* Disable inputs of parser neighbor blocks */
  5217. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  5218. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  5219. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  5220. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  5221. /* Write 0 to parser credits for CFC search request */
  5222. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  5223. /* send 10 Ethernet packets */
  5224. for (i = 0; i < 10; i++)
  5225. bnx2x_lb_pckt(bp);
  5226. /* Wait until NIG register shows 10 + 1
  5227. packets of size 11*0x10 = 0xb0 */
  5228. count = 1000 * factor;
  5229. while (count) {
  5230. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5231. val = *bnx2x_sp(bp, wb_data[0]);
  5232. if (val == 0xb0)
  5233. break;
  5234. msleep(10);
  5235. count--;
  5236. }
  5237. if (val != 0xb0) {
  5238. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  5239. return -3;
  5240. }
  5241. /* Wait until PRS register shows 2 packets */
  5242. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5243. if (val != 2)
  5244. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5245. /* Write 1 to parser credits for CFC search request */
  5246. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1);
  5247. /* Wait until PRS register shows 3 packets */
  5248. msleep(10 * factor);
  5249. /* Wait until NIG register shows 1 packet of size 0x10 */
  5250. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5251. if (val != 3)
  5252. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5253. /* clear NIG EOP FIFO */
  5254. for (i = 0; i < 11; i++)
  5255. REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO);
  5256. val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY);
  5257. if (val != 1) {
  5258. BNX2X_ERR("clear of NIG failed\n");
  5259. return -4;
  5260. }
  5261. /* Reset and init BRB, PRS, NIG */
  5262. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  5263. msleep(50);
  5264. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  5265. msleep(50);
  5266. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5267. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5268. if (!CNIC_SUPPORT(bp))
  5269. /* set NIC mode */
  5270. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  5271. /* Enable inputs of parser neighbor blocks */
  5272. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff);
  5273. REG_WR(bp, TCM_REG_PRS_IFEN, 0x1);
  5274. REG_WR(bp, CFC_REG_DEBUG0, 0x0);
  5275. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1);
  5276. DP(NETIF_MSG_HW, "done\n");
  5277. return 0; /* OK */
  5278. }
  5279. static void bnx2x_enable_blocks_attention(struct bnx2x *bp)
  5280. {
  5281. u32 val;
  5282. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5283. if (!CHIP_IS_E1x(bp))
  5284. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0x40);
  5285. else
  5286. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0);
  5287. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  5288. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  5289. /*
  5290. * mask read length error interrupts in brb for parser
  5291. * (parsing unit and 'checksum and crc' unit)
  5292. * these errors are legal (PU reads fixed length and CAC can cause
  5293. * read length error on truncated packets)
  5294. */
  5295. REG_WR(bp, BRB1_REG_BRB1_INT_MASK, 0xFC00);
  5296. REG_WR(bp, QM_REG_QM_INT_MASK, 0);
  5297. REG_WR(bp, TM_REG_TM_INT_MASK, 0);
  5298. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0);
  5299. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0);
  5300. REG_WR(bp, XCM_REG_XCM_INT_MASK, 0);
  5301. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */
  5302. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */
  5303. REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0);
  5304. REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0);
  5305. REG_WR(bp, UCM_REG_UCM_INT_MASK, 0);
  5306. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */
  5307. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */
  5308. REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0);
  5309. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0);
  5310. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0);
  5311. REG_WR(bp, CCM_REG_CCM_INT_MASK, 0);
  5312. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */
  5313. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */
  5314. val = PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT |
  5315. PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF |
  5316. PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN;
  5317. if (!CHIP_IS_E1x(bp))
  5318. val |= PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED |
  5319. PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED;
  5320. REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, val);
  5321. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0);
  5322. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0);
  5323. REG_WR(bp, TCM_REG_TCM_INT_MASK, 0);
  5324. /* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */
  5325. if (!CHIP_IS_E1x(bp))
  5326. /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */
  5327. REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0x07ff);
  5328. REG_WR(bp, CDU_REG_CDU_INT_MASK, 0);
  5329. REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0);
  5330. /* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */
  5331. REG_WR(bp, PBF_REG_PBF_INT_MASK, 0x18); /* bit 3,4 masked */
  5332. }
  5333. static void bnx2x_reset_common(struct bnx2x *bp)
  5334. {
  5335. u32 val = 0x1400;
  5336. /* reset_common */
  5337. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  5338. 0xd3ffff7f);
  5339. if (CHIP_IS_E3(bp)) {
  5340. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  5341. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  5342. }
  5343. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, val);
  5344. }
  5345. static void bnx2x_setup_dmae(struct bnx2x *bp)
  5346. {
  5347. bp->dmae_ready = 0;
  5348. spin_lock_init(&bp->dmae_lock);
  5349. }
  5350. static void bnx2x_init_pxp(struct bnx2x *bp)
  5351. {
  5352. u16 devctl;
  5353. int r_order, w_order;
  5354. pcie_capability_read_word(bp->pdev, PCI_EXP_DEVCTL, &devctl);
  5355. DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl);
  5356. w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
  5357. if (bp->mrrs == -1)
  5358. r_order = ((devctl & PCI_EXP_DEVCTL_READRQ) >> 12);
  5359. else {
  5360. DP(NETIF_MSG_HW, "force read order to %d\n", bp->mrrs);
  5361. r_order = bp->mrrs;
  5362. }
  5363. bnx2x_init_pxp_arb(bp, r_order, w_order);
  5364. }
  5365. static void bnx2x_setup_fan_failure_detection(struct bnx2x *bp)
  5366. {
  5367. int is_required;
  5368. u32 val;
  5369. int port;
  5370. if (BP_NOMCP(bp))
  5371. return;
  5372. is_required = 0;
  5373. val = SHMEM_RD(bp, dev_info.shared_hw_config.config2) &
  5374. SHARED_HW_CFG_FAN_FAILURE_MASK;
  5375. if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED)
  5376. is_required = 1;
  5377. /*
  5378. * The fan failure mechanism is usually related to the PHY type since
  5379. * the power consumption of the board is affected by the PHY. Currently,
  5380. * fan is required for most designs with SFX7101, BCM8727 and BCM8481.
  5381. */
  5382. else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE)
  5383. for (port = PORT_0; port < PORT_MAX; port++) {
  5384. is_required |=
  5385. bnx2x_fan_failure_det_req(
  5386. bp,
  5387. bp->common.shmem_base,
  5388. bp->common.shmem2_base,
  5389. port);
  5390. }
  5391. DP(NETIF_MSG_HW, "fan detection setting: %d\n", is_required);
  5392. if (is_required == 0)
  5393. return;
  5394. /* Fan failure is indicated by SPIO 5 */
  5395. bnx2x_set_spio(bp, MISC_SPIO_SPIO5, MISC_SPIO_INPUT_HI_Z);
  5396. /* set to active low mode */
  5397. val = REG_RD(bp, MISC_REG_SPIO_INT);
  5398. val |= (MISC_SPIO_SPIO5 << MISC_SPIO_INT_OLD_SET_POS);
  5399. REG_WR(bp, MISC_REG_SPIO_INT, val);
  5400. /* enable interrupt to signal the IGU */
  5401. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  5402. val |= MISC_SPIO_SPIO5;
  5403. REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val);
  5404. }
  5405. void bnx2x_pf_disable(struct bnx2x *bp)
  5406. {
  5407. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  5408. val &= ~IGU_PF_CONF_FUNC_EN;
  5409. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  5410. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  5411. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 0);
  5412. }
  5413. static void bnx2x__common_init_phy(struct bnx2x *bp)
  5414. {
  5415. u32 shmem_base[2], shmem2_base[2];
  5416. /* Avoid common init in case MFW supports LFA */
  5417. if (SHMEM2_RD(bp, size) >
  5418. (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
  5419. return;
  5420. shmem_base[0] = bp->common.shmem_base;
  5421. shmem2_base[0] = bp->common.shmem2_base;
  5422. if (!CHIP_IS_E1x(bp)) {
  5423. shmem_base[1] =
  5424. SHMEM2_RD(bp, other_shmem_base_addr);
  5425. shmem2_base[1] =
  5426. SHMEM2_RD(bp, other_shmem2_base_addr);
  5427. }
  5428. bnx2x_acquire_phy_lock(bp);
  5429. bnx2x_common_init_phy(bp, shmem_base, shmem2_base,
  5430. bp->common.chip_id);
  5431. bnx2x_release_phy_lock(bp);
  5432. }
  5433. /**
  5434. * bnx2x_init_hw_common - initialize the HW at the COMMON phase.
  5435. *
  5436. * @bp: driver handle
  5437. */
  5438. static int bnx2x_init_hw_common(struct bnx2x *bp)
  5439. {
  5440. u32 val;
  5441. DP(NETIF_MSG_HW, "starting common init func %d\n", BP_ABS_FUNC(bp));
  5442. /*
  5443. * take the RESET lock to protect undi_unload flow from accessing
  5444. * registers while we're resetting the chip
  5445. */
  5446. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5447. bnx2x_reset_common(bp);
  5448. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff);
  5449. val = 0xfffc;
  5450. if (CHIP_IS_E3(bp)) {
  5451. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  5452. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  5453. }
  5454. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, val);
  5455. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5456. bnx2x_init_block(bp, BLOCK_MISC, PHASE_COMMON);
  5457. if (!CHIP_IS_E1x(bp)) {
  5458. u8 abs_func_id;
  5459. /**
  5460. * 4-port mode or 2-port mode we need to turn of master-enable
  5461. * for everyone, after that, turn it back on for self.
  5462. * so, we disregard multi-function or not, and always disable
  5463. * for all functions on the given path, this means 0,2,4,6 for
  5464. * path 0 and 1,3,5,7 for path 1
  5465. */
  5466. for (abs_func_id = BP_PATH(bp);
  5467. abs_func_id < E2_FUNC_MAX*2; abs_func_id += 2) {
  5468. if (abs_func_id == BP_ABS_FUNC(bp)) {
  5469. REG_WR(bp,
  5470. PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER,
  5471. 1);
  5472. continue;
  5473. }
  5474. bnx2x_pretend_func(bp, abs_func_id);
  5475. /* clear pf enable */
  5476. bnx2x_pf_disable(bp);
  5477. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  5478. }
  5479. }
  5480. bnx2x_init_block(bp, BLOCK_PXP, PHASE_COMMON);
  5481. if (CHIP_IS_E1(bp)) {
  5482. /* enable HW interrupt from PXP on USDM overflow
  5483. bit 16 on INT_MASK_0 */
  5484. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5485. }
  5486. bnx2x_init_block(bp, BLOCK_PXP2, PHASE_COMMON);
  5487. bnx2x_init_pxp(bp);
  5488. #ifdef __BIG_ENDIAN
  5489. REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, 1);
  5490. REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, 1);
  5491. REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, 1);
  5492. REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, 1);
  5493. REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, 1);
  5494. /* make sure this value is 0 */
  5495. REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0);
  5496. /* REG_WR(bp, PXP2_REG_RD_PBF_SWAP_MODE, 1); */
  5497. REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, 1);
  5498. REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, 1);
  5499. REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, 1);
  5500. REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, 1);
  5501. #endif
  5502. bnx2x_ilt_init_page_size(bp, INITOP_SET);
  5503. if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp))
  5504. REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1);
  5505. /* let the HW do it's magic ... */
  5506. msleep(100);
  5507. /* finish PXP init */
  5508. val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE);
  5509. if (val != 1) {
  5510. BNX2X_ERR("PXP2 CFG failed\n");
  5511. return -EBUSY;
  5512. }
  5513. val = REG_RD(bp, PXP2_REG_RD_INIT_DONE);
  5514. if (val != 1) {
  5515. BNX2X_ERR("PXP2 RD_INIT failed\n");
  5516. return -EBUSY;
  5517. }
  5518. /* Timers bug workaround E2 only. We need to set the entire ILT to
  5519. * have entries with value "0" and valid bit on.
  5520. * This needs to be done by the first PF that is loaded in a path
  5521. * (i.e. common phase)
  5522. */
  5523. if (!CHIP_IS_E1x(bp)) {
  5524. /* In E2 there is a bug in the timers block that can cause function 6 / 7
  5525. * (i.e. vnic3) to start even if it is marked as "scan-off".
  5526. * This occurs when a different function (func2,3) is being marked
  5527. * as "scan-off". Real-life scenario for example: if a driver is being
  5528. * load-unloaded while func6,7 are down. This will cause the timer to access
  5529. * the ilt, translate to a logical address and send a request to read/write.
  5530. * Since the ilt for the function that is down is not valid, this will cause
  5531. * a translation error which is unrecoverable.
  5532. * The Workaround is intended to make sure that when this happens nothing fatal
  5533. * will occur. The workaround:
  5534. * 1. First PF driver which loads on a path will:
  5535. * a. After taking the chip out of reset, by using pretend,
  5536. * it will write "0" to the following registers of
  5537. * the other vnics.
  5538. * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  5539. * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0);
  5540. * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0);
  5541. * And for itself it will write '1' to
  5542. * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable
  5543. * dmae-operations (writing to pram for example.)
  5544. * note: can be done for only function 6,7 but cleaner this
  5545. * way.
  5546. * b. Write zero+valid to the entire ILT.
  5547. * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of
  5548. * VNIC3 (of that port). The range allocated will be the
  5549. * entire ILT. This is needed to prevent ILT range error.
  5550. * 2. Any PF driver load flow:
  5551. * a. ILT update with the physical addresses of the allocated
  5552. * logical pages.
  5553. * b. Wait 20msec. - note that this timeout is needed to make
  5554. * sure there are no requests in one of the PXP internal
  5555. * queues with "old" ILT addresses.
  5556. * c. PF enable in the PGLC.
  5557. * d. Clear the was_error of the PF in the PGLC. (could have
  5558. * occurred while driver was down)
  5559. * e. PF enable in the CFC (WEAK + STRONG)
  5560. * f. Timers scan enable
  5561. * 3. PF driver unload flow:
  5562. * a. Clear the Timers scan_en.
  5563. * b. Polling for scan_on=0 for that PF.
  5564. * c. Clear the PF enable bit in the PXP.
  5565. * d. Clear the PF enable in the CFC (WEAK + STRONG)
  5566. * e. Write zero+valid to all ILT entries (The valid bit must
  5567. * stay set)
  5568. * f. If this is VNIC 3 of a port then also init
  5569. * first_timers_ilt_entry to zero and last_timers_ilt_entry
  5570. * to the last enrty in the ILT.
  5571. *
  5572. * Notes:
  5573. * Currently the PF error in the PGLC is non recoverable.
  5574. * In the future the there will be a recovery routine for this error.
  5575. * Currently attention is masked.
  5576. * Having an MCP lock on the load/unload process does not guarantee that
  5577. * there is no Timer disable during Func6/7 enable. This is because the
  5578. * Timers scan is currently being cleared by the MCP on FLR.
  5579. * Step 2.d can be done only for PF6/7 and the driver can also check if
  5580. * there is error before clearing it. But the flow above is simpler and
  5581. * more general.
  5582. * All ILT entries are written by zero+valid and not just PF6/7
  5583. * ILT entries since in the future the ILT entries allocation for
  5584. * PF-s might be dynamic.
  5585. */
  5586. struct ilt_client_info ilt_cli;
  5587. struct bnx2x_ilt ilt;
  5588. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  5589. memset(&ilt, 0, sizeof(struct bnx2x_ilt));
  5590. /* initialize dummy TM client */
  5591. ilt_cli.start = 0;
  5592. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  5593. ilt_cli.client_num = ILT_CLIENT_TM;
  5594. /* Step 1: set zeroes to all ilt page entries with valid bit on
  5595. * Step 2: set the timers first/last ilt entry to point
  5596. * to the entire range to prevent ILT range error for 3rd/4th
  5597. * vnic (this code assumes existence of the vnic)
  5598. *
  5599. * both steps performed by call to bnx2x_ilt_client_init_op()
  5600. * with dummy TM client
  5601. *
  5602. * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT
  5603. * and his brother are split registers
  5604. */
  5605. bnx2x_pretend_func(bp, (BP_PATH(bp) + 6));
  5606. bnx2x_ilt_client_init_op_ilt(bp, &ilt, &ilt_cli, INITOP_CLEAR);
  5607. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  5608. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN, BNX2X_PXP_DRAM_ALIGN);
  5609. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_RD, BNX2X_PXP_DRAM_ALIGN);
  5610. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_SEL, 1);
  5611. }
  5612. REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0);
  5613. REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0);
  5614. if (!CHIP_IS_E1x(bp)) {
  5615. int factor = CHIP_REV_IS_EMUL(bp) ? 1000 :
  5616. (CHIP_REV_IS_FPGA(bp) ? 400 : 0);
  5617. bnx2x_init_block(bp, BLOCK_PGLUE_B, PHASE_COMMON);
  5618. bnx2x_init_block(bp, BLOCK_ATC, PHASE_COMMON);
  5619. /* let the HW do it's magic ... */
  5620. do {
  5621. msleep(200);
  5622. val = REG_RD(bp, ATC_REG_ATC_INIT_DONE);
  5623. } while (factor-- && (val != 1));
  5624. if (val != 1) {
  5625. BNX2X_ERR("ATC_INIT failed\n");
  5626. return -EBUSY;
  5627. }
  5628. }
  5629. bnx2x_init_block(bp, BLOCK_DMAE, PHASE_COMMON);
  5630. bnx2x_iov_init_dmae(bp);
  5631. /* clean the DMAE memory */
  5632. bp->dmae_ready = 1;
  5633. bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8, 1);
  5634. bnx2x_init_block(bp, BLOCK_TCM, PHASE_COMMON);
  5635. bnx2x_init_block(bp, BLOCK_UCM, PHASE_COMMON);
  5636. bnx2x_init_block(bp, BLOCK_CCM, PHASE_COMMON);
  5637. bnx2x_init_block(bp, BLOCK_XCM, PHASE_COMMON);
  5638. bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3);
  5639. bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3);
  5640. bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3);
  5641. bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3);
  5642. bnx2x_init_block(bp, BLOCK_QM, PHASE_COMMON);
  5643. /* QM queues pointers table */
  5644. bnx2x_qm_init_ptr_table(bp, bp->qm_cid_count, INITOP_SET);
  5645. /* soft reset pulse */
  5646. REG_WR(bp, QM_REG_SOFT_RESET, 1);
  5647. REG_WR(bp, QM_REG_SOFT_RESET, 0);
  5648. if (CNIC_SUPPORT(bp))
  5649. bnx2x_init_block(bp, BLOCK_TM, PHASE_COMMON);
  5650. bnx2x_init_block(bp, BLOCK_DORQ, PHASE_COMMON);
  5651. REG_WR(bp, DORQ_REG_DPM_CID_OFST, BNX2X_DB_SHIFT);
  5652. if (!CHIP_REV_IS_SLOW(bp))
  5653. /* enable hw interrupt from doorbell Q */
  5654. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  5655. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5656. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5657. REG_WR(bp, PRS_REG_A_PRSU_20, 0xf);
  5658. if (!CHIP_IS_E1(bp))
  5659. REG_WR(bp, PRS_REG_E1HOV_MODE, bp->path_has_ovlan);
  5660. if (!CHIP_IS_E1x(bp) && !CHIP_IS_E3B0(bp)) {
  5661. if (IS_MF_AFEX(bp)) {
  5662. /* configure that VNTag and VLAN headers must be
  5663. * received in afex mode
  5664. */
  5665. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC, 0xE);
  5666. REG_WR(bp, PRS_REG_MUST_HAVE_HDRS, 0xA);
  5667. REG_WR(bp, PRS_REG_HDRS_AFTER_TAG_0, 0x6);
  5668. REG_WR(bp, PRS_REG_TAG_ETHERTYPE_0, 0x8926);
  5669. REG_WR(bp, PRS_REG_TAG_LEN_0, 0x4);
  5670. } else {
  5671. /* Bit-map indicating which L2 hdrs may appear
  5672. * after the basic Ethernet header
  5673. */
  5674. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC,
  5675. bp->path_has_ovlan ? 7 : 6);
  5676. }
  5677. }
  5678. bnx2x_init_block(bp, BLOCK_TSDM, PHASE_COMMON);
  5679. bnx2x_init_block(bp, BLOCK_CSDM, PHASE_COMMON);
  5680. bnx2x_init_block(bp, BLOCK_USDM, PHASE_COMMON);
  5681. bnx2x_init_block(bp, BLOCK_XSDM, PHASE_COMMON);
  5682. if (!CHIP_IS_E1x(bp)) {
  5683. /* reset VFC memories */
  5684. REG_WR(bp, TSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  5685. VFC_MEMORIES_RST_REG_CAM_RST |
  5686. VFC_MEMORIES_RST_REG_RAM_RST);
  5687. REG_WR(bp, XSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  5688. VFC_MEMORIES_RST_REG_CAM_RST |
  5689. VFC_MEMORIES_RST_REG_RAM_RST);
  5690. msleep(20);
  5691. }
  5692. bnx2x_init_block(bp, BLOCK_TSEM, PHASE_COMMON);
  5693. bnx2x_init_block(bp, BLOCK_USEM, PHASE_COMMON);
  5694. bnx2x_init_block(bp, BLOCK_CSEM, PHASE_COMMON);
  5695. bnx2x_init_block(bp, BLOCK_XSEM, PHASE_COMMON);
  5696. /* sync semi rtc */
  5697. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  5698. 0x80000000);
  5699. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
  5700. 0x80000000);
  5701. bnx2x_init_block(bp, BLOCK_UPB, PHASE_COMMON);
  5702. bnx2x_init_block(bp, BLOCK_XPB, PHASE_COMMON);
  5703. bnx2x_init_block(bp, BLOCK_PBF, PHASE_COMMON);
  5704. if (!CHIP_IS_E1x(bp)) {
  5705. if (IS_MF_AFEX(bp)) {
  5706. /* configure that VNTag and VLAN headers must be
  5707. * sent in afex mode
  5708. */
  5709. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC, 0xE);
  5710. REG_WR(bp, PBF_REG_MUST_HAVE_HDRS, 0xA);
  5711. REG_WR(bp, PBF_REG_HDRS_AFTER_TAG_0, 0x6);
  5712. REG_WR(bp, PBF_REG_TAG_ETHERTYPE_0, 0x8926);
  5713. REG_WR(bp, PBF_REG_TAG_LEN_0, 0x4);
  5714. } else {
  5715. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC,
  5716. bp->path_has_ovlan ? 7 : 6);
  5717. }
  5718. }
  5719. REG_WR(bp, SRC_REG_SOFT_RST, 1);
  5720. bnx2x_init_block(bp, BLOCK_SRC, PHASE_COMMON);
  5721. if (CNIC_SUPPORT(bp)) {
  5722. REG_WR(bp, SRC_REG_KEYSEARCH_0, 0x63285672);
  5723. REG_WR(bp, SRC_REG_KEYSEARCH_1, 0x24b8f2cc);
  5724. REG_WR(bp, SRC_REG_KEYSEARCH_2, 0x223aef9b);
  5725. REG_WR(bp, SRC_REG_KEYSEARCH_3, 0x26001e3a);
  5726. REG_WR(bp, SRC_REG_KEYSEARCH_4, 0x7ae91116);
  5727. REG_WR(bp, SRC_REG_KEYSEARCH_5, 0x5ce5230b);
  5728. REG_WR(bp, SRC_REG_KEYSEARCH_6, 0x298d8adf);
  5729. REG_WR(bp, SRC_REG_KEYSEARCH_7, 0x6eb0ff09);
  5730. REG_WR(bp, SRC_REG_KEYSEARCH_8, 0x1830f82f);
  5731. REG_WR(bp, SRC_REG_KEYSEARCH_9, 0x01e46be7);
  5732. }
  5733. REG_WR(bp, SRC_REG_SOFT_RST, 0);
  5734. if (sizeof(union cdu_context) != 1024)
  5735. /* we currently assume that a context is 1024 bytes */
  5736. dev_alert(&bp->pdev->dev,
  5737. "please adjust the size of cdu_context(%ld)\n",
  5738. (long)sizeof(union cdu_context));
  5739. bnx2x_init_block(bp, BLOCK_CDU, PHASE_COMMON);
  5740. val = (4 << 24) + (0 << 12) + 1024;
  5741. REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val);
  5742. bnx2x_init_block(bp, BLOCK_CFC, PHASE_COMMON);
  5743. REG_WR(bp, CFC_REG_INIT_REG, 0x7FF);
  5744. /* enable context validation interrupt from CFC */
  5745. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  5746. /* set the thresholds to prevent CFC/CDU race */
  5747. REG_WR(bp, CFC_REG_DEBUG0, 0x20020000);
  5748. bnx2x_init_block(bp, BLOCK_HC, PHASE_COMMON);
  5749. if (!CHIP_IS_E1x(bp) && BP_NOMCP(bp))
  5750. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x36);
  5751. bnx2x_init_block(bp, BLOCK_IGU, PHASE_COMMON);
  5752. bnx2x_init_block(bp, BLOCK_MISC_AEU, PHASE_COMMON);
  5753. /* Reset PCIE errors for debug */
  5754. REG_WR(bp, 0x2814, 0xffffffff);
  5755. REG_WR(bp, 0x3820, 0xffffffff);
  5756. if (!CHIP_IS_E1x(bp)) {
  5757. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_CONTROL_5,
  5758. (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1 |
  5759. PXPCS_TL_CONTROL_5_ERR_UNSPPORT));
  5760. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC345_STAT,
  5761. (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4 |
  5762. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3 |
  5763. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2));
  5764. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC678_STAT,
  5765. (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7 |
  5766. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6 |
  5767. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5));
  5768. }
  5769. bnx2x_init_block(bp, BLOCK_NIG, PHASE_COMMON);
  5770. if (!CHIP_IS_E1(bp)) {
  5771. /* in E3 this done in per-port section */
  5772. if (!CHIP_IS_E3(bp))
  5773. REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_MF(bp));
  5774. }
  5775. if (CHIP_IS_E1H(bp))
  5776. /* not applicable for E2 (and above ...) */
  5777. REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_MF_SD(bp));
  5778. if (CHIP_REV_IS_SLOW(bp))
  5779. msleep(200);
  5780. /* finish CFC init */
  5781. val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10);
  5782. if (val != 1) {
  5783. BNX2X_ERR("CFC LL_INIT failed\n");
  5784. return -EBUSY;
  5785. }
  5786. val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10);
  5787. if (val != 1) {
  5788. BNX2X_ERR("CFC AC_INIT failed\n");
  5789. return -EBUSY;
  5790. }
  5791. val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10);
  5792. if (val != 1) {
  5793. BNX2X_ERR("CFC CAM_INIT failed\n");
  5794. return -EBUSY;
  5795. }
  5796. REG_WR(bp, CFC_REG_DEBUG0, 0);
  5797. if (CHIP_IS_E1(bp)) {
  5798. /* read NIG statistic
  5799. to see if this is our first up since powerup */
  5800. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5801. val = *bnx2x_sp(bp, wb_data[0]);
  5802. /* do internal memory self test */
  5803. if ((val == 0) && bnx2x_int_mem_test(bp)) {
  5804. BNX2X_ERR("internal mem self test failed\n");
  5805. return -EBUSY;
  5806. }
  5807. }
  5808. bnx2x_setup_fan_failure_detection(bp);
  5809. /* clear PXP2 attentions */
  5810. REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0);
  5811. bnx2x_enable_blocks_attention(bp);
  5812. bnx2x_enable_blocks_parity(bp);
  5813. if (!BP_NOMCP(bp)) {
  5814. if (CHIP_IS_E1x(bp))
  5815. bnx2x__common_init_phy(bp);
  5816. } else
  5817. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  5818. return 0;
  5819. }
  5820. /**
  5821. * bnx2x_init_hw_common_chip - init HW at the COMMON_CHIP phase.
  5822. *
  5823. * @bp: driver handle
  5824. */
  5825. static int bnx2x_init_hw_common_chip(struct bnx2x *bp)
  5826. {
  5827. int rc = bnx2x_init_hw_common(bp);
  5828. if (rc)
  5829. return rc;
  5830. /* In E2 2-PORT mode, same ext phy is used for the two paths */
  5831. if (!BP_NOMCP(bp))
  5832. bnx2x__common_init_phy(bp);
  5833. return 0;
  5834. }
  5835. static int bnx2x_init_hw_port(struct bnx2x *bp)
  5836. {
  5837. int port = BP_PORT(bp);
  5838. int init_phase = port ? PHASE_PORT1 : PHASE_PORT0;
  5839. u32 low, high;
  5840. u32 val;
  5841. DP(NETIF_MSG_HW, "starting port init port %d\n", port);
  5842. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  5843. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  5844. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  5845. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  5846. /* Timers bug workaround: disables the pf_master bit in pglue at
  5847. * common phase, we need to enable it here before any dmae access are
  5848. * attempted. Therefore we manually added the enable-master to the
  5849. * port phase (it also happens in the function phase)
  5850. */
  5851. if (!CHIP_IS_E1x(bp))
  5852. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  5853. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  5854. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  5855. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  5856. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  5857. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  5858. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  5859. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  5860. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  5861. /* QM cid (connection) count */
  5862. bnx2x_qm_init_cid_count(bp, bp->qm_cid_count, INITOP_SET);
  5863. if (CNIC_SUPPORT(bp)) {
  5864. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  5865. REG_WR(bp, TM_REG_LIN0_SCAN_TIME + port*4, 20);
  5866. REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31);
  5867. }
  5868. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  5869. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  5870. if (CHIP_IS_E1(bp) || CHIP_IS_E1H(bp)) {
  5871. if (IS_MF(bp))
  5872. low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246);
  5873. else if (bp->dev->mtu > 4096) {
  5874. if (bp->flags & ONE_PORT_FLAG)
  5875. low = 160;
  5876. else {
  5877. val = bp->dev->mtu;
  5878. /* (24*1024 + val*4)/256 */
  5879. low = 96 + (val/64) +
  5880. ((val % 64) ? 1 : 0);
  5881. }
  5882. } else
  5883. low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160);
  5884. high = low + 56; /* 14*1024/256 */
  5885. REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low);
  5886. REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high);
  5887. }
  5888. if (CHIP_MODE_IS_4_PORT(bp))
  5889. REG_WR(bp, (BP_PORT(bp) ?
  5890. BRB1_REG_MAC_GUARANTIED_1 :
  5891. BRB1_REG_MAC_GUARANTIED_0), 40);
  5892. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  5893. if (CHIP_IS_E3B0(bp)) {
  5894. if (IS_MF_AFEX(bp)) {
  5895. /* configure headers for AFEX mode */
  5896. REG_WR(bp, BP_PORT(bp) ?
  5897. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  5898. PRS_REG_HDRS_AFTER_BASIC_PORT_0, 0xE);
  5899. REG_WR(bp, BP_PORT(bp) ?
  5900. PRS_REG_HDRS_AFTER_TAG_0_PORT_1 :
  5901. PRS_REG_HDRS_AFTER_TAG_0_PORT_0, 0x6);
  5902. REG_WR(bp, BP_PORT(bp) ?
  5903. PRS_REG_MUST_HAVE_HDRS_PORT_1 :
  5904. PRS_REG_MUST_HAVE_HDRS_PORT_0, 0xA);
  5905. } else {
  5906. /* Ovlan exists only if we are in multi-function +
  5907. * switch-dependent mode, in switch-independent there
  5908. * is no ovlan headers
  5909. */
  5910. REG_WR(bp, BP_PORT(bp) ?
  5911. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  5912. PRS_REG_HDRS_AFTER_BASIC_PORT_0,
  5913. (bp->path_has_ovlan ? 7 : 6));
  5914. }
  5915. }
  5916. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  5917. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  5918. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  5919. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  5920. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  5921. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  5922. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  5923. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  5924. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  5925. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  5926. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  5927. if (CHIP_IS_E1x(bp)) {
  5928. /* configure PBF to work without PAUSE mtu 9000 */
  5929. REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
  5930. /* update threshold */
  5931. REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16));
  5932. /* update init credit */
  5933. REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22);
  5934. /* probe changes */
  5935. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1);
  5936. udelay(50);
  5937. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0);
  5938. }
  5939. if (CNIC_SUPPORT(bp))
  5940. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  5941. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  5942. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  5943. if (CHIP_IS_E1(bp)) {
  5944. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  5945. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  5946. }
  5947. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  5948. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  5949. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  5950. /* init aeu_mask_attn_func_0/1:
  5951. * - SF mode: bits 3-7 are masked. only bits 0-2 are in use
  5952. * - MF mode: bit 3 is masked. bits 0-2 are in use as in SF
  5953. * bits 4-7 are used for "per vn group attention" */
  5954. val = IS_MF(bp) ? 0xF7 : 0x7;
  5955. /* Enable DCBX attention for all but E1 */
  5956. val |= CHIP_IS_E1(bp) ? 0 : 0x10;
  5957. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, val);
  5958. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  5959. if (!CHIP_IS_E1x(bp)) {
  5960. /* Bit-map indicating which L2 hdrs may appear after the
  5961. * basic Ethernet header
  5962. */
  5963. if (IS_MF_AFEX(bp))
  5964. REG_WR(bp, BP_PORT(bp) ?
  5965. NIG_REG_P1_HDRS_AFTER_BASIC :
  5966. NIG_REG_P0_HDRS_AFTER_BASIC, 0xE);
  5967. else
  5968. REG_WR(bp, BP_PORT(bp) ?
  5969. NIG_REG_P1_HDRS_AFTER_BASIC :
  5970. NIG_REG_P0_HDRS_AFTER_BASIC,
  5971. IS_MF_SD(bp) ? 7 : 6);
  5972. if (CHIP_IS_E3(bp))
  5973. REG_WR(bp, BP_PORT(bp) ?
  5974. NIG_REG_LLH1_MF_MODE :
  5975. NIG_REG_LLH_MF_MODE, IS_MF(bp));
  5976. }
  5977. if (!CHIP_IS_E3(bp))
  5978. REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
  5979. if (!CHIP_IS_E1(bp)) {
  5980. /* 0x2 disable mf_ov, 0x1 enable */
  5981. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4,
  5982. (IS_MF_SD(bp) ? 0x1 : 0x2));
  5983. if (!CHIP_IS_E1x(bp)) {
  5984. val = 0;
  5985. switch (bp->mf_mode) {
  5986. case MULTI_FUNCTION_SD:
  5987. val = 1;
  5988. break;
  5989. case MULTI_FUNCTION_SI:
  5990. case MULTI_FUNCTION_AFEX:
  5991. val = 2;
  5992. break;
  5993. }
  5994. REG_WR(bp, (BP_PORT(bp) ? NIG_REG_LLH1_CLS_TYPE :
  5995. NIG_REG_LLH0_CLS_TYPE), val);
  5996. }
  5997. {
  5998. REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0);
  5999. REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0);
  6000. REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1);
  6001. }
  6002. }
  6003. /* If SPIO5 is set to generate interrupts, enable it for this port */
  6004. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  6005. if (val & MISC_SPIO_SPIO5) {
  6006. u32 reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  6007. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  6008. val = REG_RD(bp, reg_addr);
  6009. val |= AEU_INPUTS_ATTN_BITS_SPIO5;
  6010. REG_WR(bp, reg_addr, val);
  6011. }
  6012. return 0;
  6013. }
  6014. static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr)
  6015. {
  6016. int reg;
  6017. u32 wb_write[2];
  6018. if (CHIP_IS_E1(bp))
  6019. reg = PXP2_REG_RQ_ONCHIP_AT + index*8;
  6020. else
  6021. reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8;
  6022. wb_write[0] = ONCHIP_ADDR1(addr);
  6023. wb_write[1] = ONCHIP_ADDR2(addr);
  6024. REG_WR_DMAE(bp, reg, wb_write, 2);
  6025. }
  6026. void bnx2x_igu_clear_sb_gen(struct bnx2x *bp, u8 func, u8 idu_sb_id, bool is_pf)
  6027. {
  6028. u32 data, ctl, cnt = 100;
  6029. u32 igu_addr_data = IGU_REG_COMMAND_REG_32LSB_DATA;
  6030. u32 igu_addr_ctl = IGU_REG_COMMAND_REG_CTRL;
  6031. u32 igu_addr_ack = IGU_REG_CSTORM_TYPE_0_SB_CLEANUP + (idu_sb_id/32)*4;
  6032. u32 sb_bit = 1 << (idu_sb_id%32);
  6033. u32 func_encode = func | (is_pf ? 1 : 0) << IGU_FID_ENCODE_IS_PF_SHIFT;
  6034. u32 addr_encode = IGU_CMD_E2_PROD_UPD_BASE + idu_sb_id;
  6035. /* Not supported in BC mode */
  6036. if (CHIP_INT_MODE_IS_BC(bp))
  6037. return;
  6038. data = (IGU_USE_REGISTER_cstorm_type_0_sb_cleanup
  6039. << IGU_REGULAR_CLEANUP_TYPE_SHIFT) |
  6040. IGU_REGULAR_CLEANUP_SET |
  6041. IGU_REGULAR_BCLEANUP;
  6042. ctl = addr_encode << IGU_CTRL_REG_ADDRESS_SHIFT |
  6043. func_encode << IGU_CTRL_REG_FID_SHIFT |
  6044. IGU_CTRL_CMD_TYPE_WR << IGU_CTRL_REG_TYPE_SHIFT;
  6045. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  6046. data, igu_addr_data);
  6047. REG_WR(bp, igu_addr_data, data);
  6048. mmiowb();
  6049. barrier();
  6050. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  6051. ctl, igu_addr_ctl);
  6052. REG_WR(bp, igu_addr_ctl, ctl);
  6053. mmiowb();
  6054. barrier();
  6055. /* wait for clean up to finish */
  6056. while (!(REG_RD(bp, igu_addr_ack) & sb_bit) && --cnt)
  6057. msleep(20);
  6058. if (!(REG_RD(bp, igu_addr_ack) & sb_bit)) {
  6059. DP(NETIF_MSG_HW,
  6060. "Unable to finish IGU cleanup: idu_sb_id %d offset %d bit %d (cnt %d)\n",
  6061. idu_sb_id, idu_sb_id/32, idu_sb_id%32, cnt);
  6062. }
  6063. }
  6064. static void bnx2x_igu_clear_sb(struct bnx2x *bp, u8 idu_sb_id)
  6065. {
  6066. bnx2x_igu_clear_sb_gen(bp, BP_FUNC(bp), idu_sb_id, true /*PF*/);
  6067. }
  6068. static void bnx2x_clear_func_ilt(struct bnx2x *bp, u32 func)
  6069. {
  6070. u32 i, base = FUNC_ILT_BASE(func);
  6071. for (i = base; i < base + ILT_PER_FUNC; i++)
  6072. bnx2x_ilt_wr(bp, i, 0);
  6073. }
  6074. static void bnx2x_init_searcher(struct bnx2x *bp)
  6075. {
  6076. int port = BP_PORT(bp);
  6077. bnx2x_src_init_t2(bp, bp->t2, bp->t2_mapping, SRC_CONN_NUM);
  6078. /* T1 hash bits value determines the T1 number of entries */
  6079. REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + port*4, SRC_HASH_BITS);
  6080. }
  6081. static inline int bnx2x_func_switch_update(struct bnx2x *bp, int suspend)
  6082. {
  6083. int rc;
  6084. struct bnx2x_func_state_params func_params = {NULL};
  6085. struct bnx2x_func_switch_update_params *switch_update_params =
  6086. &func_params.params.switch_update;
  6087. /* Prepare parameters for function state transitions */
  6088. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  6089. __set_bit(RAMROD_RETRY, &func_params.ramrod_flags);
  6090. func_params.f_obj = &bp->func_obj;
  6091. func_params.cmd = BNX2X_F_CMD_SWITCH_UPDATE;
  6092. /* Function parameters */
  6093. switch_update_params->suspend = suspend;
  6094. rc = bnx2x_func_state_change(bp, &func_params);
  6095. return rc;
  6096. }
  6097. static int bnx2x_reset_nic_mode(struct bnx2x *bp)
  6098. {
  6099. int rc, i, port = BP_PORT(bp);
  6100. int vlan_en = 0, mac_en[NUM_MACS];
  6101. /* Close input from network */
  6102. if (bp->mf_mode == SINGLE_FUNCTION) {
  6103. bnx2x_set_rx_filter(&bp->link_params, 0);
  6104. } else {
  6105. vlan_en = REG_RD(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6106. NIG_REG_LLH0_FUNC_EN);
  6107. REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6108. NIG_REG_LLH0_FUNC_EN, 0);
  6109. for (i = 0; i < NUM_MACS; i++) {
  6110. mac_en[i] = REG_RD(bp, port ?
  6111. (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6112. 4 * i) :
  6113. (NIG_REG_LLH0_FUNC_MEM_ENABLE +
  6114. 4 * i));
  6115. REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6116. 4 * i) :
  6117. (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i), 0);
  6118. }
  6119. }
  6120. /* Close BMC to host */
  6121. REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
  6122. NIG_REG_P1_TX_MNG_HOST_ENABLE, 0);
  6123. /* Suspend Tx switching to the PF. Completion of this ramrod
  6124. * further guarantees that all the packets of that PF / child
  6125. * VFs in BRB were processed by the Parser, so it is safe to
  6126. * change the NIC_MODE register.
  6127. */
  6128. rc = bnx2x_func_switch_update(bp, 1);
  6129. if (rc) {
  6130. BNX2X_ERR("Can't suspend tx-switching!\n");
  6131. return rc;
  6132. }
  6133. /* Change NIC_MODE register */
  6134. REG_WR(bp, PRS_REG_NIC_MODE, 0);
  6135. /* Open input from network */
  6136. if (bp->mf_mode == SINGLE_FUNCTION) {
  6137. bnx2x_set_rx_filter(&bp->link_params, 1);
  6138. } else {
  6139. REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6140. NIG_REG_LLH0_FUNC_EN, vlan_en);
  6141. for (i = 0; i < NUM_MACS; i++) {
  6142. REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6143. 4 * i) :
  6144. (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i),
  6145. mac_en[i]);
  6146. }
  6147. }
  6148. /* Enable BMC to host */
  6149. REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
  6150. NIG_REG_P1_TX_MNG_HOST_ENABLE, 1);
  6151. /* Resume Tx switching to the PF */
  6152. rc = bnx2x_func_switch_update(bp, 0);
  6153. if (rc) {
  6154. BNX2X_ERR("Can't resume tx-switching!\n");
  6155. return rc;
  6156. }
  6157. DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
  6158. return 0;
  6159. }
  6160. int bnx2x_init_hw_func_cnic(struct bnx2x *bp)
  6161. {
  6162. int rc;
  6163. bnx2x_ilt_init_op_cnic(bp, INITOP_SET);
  6164. if (CONFIGURE_NIC_MODE(bp)) {
  6165. /* Configrue searcher as part of function hw init */
  6166. bnx2x_init_searcher(bp);
  6167. /* Reset NIC mode */
  6168. rc = bnx2x_reset_nic_mode(bp);
  6169. if (rc)
  6170. BNX2X_ERR("Can't change NIC mode!\n");
  6171. return rc;
  6172. }
  6173. return 0;
  6174. }
  6175. static int bnx2x_init_hw_func(struct bnx2x *bp)
  6176. {
  6177. int port = BP_PORT(bp);
  6178. int func = BP_FUNC(bp);
  6179. int init_phase = PHASE_PF0 + func;
  6180. struct bnx2x_ilt *ilt = BP_ILT(bp);
  6181. u16 cdu_ilt_start;
  6182. u32 addr, val;
  6183. u32 main_mem_base, main_mem_size, main_mem_prty_clr;
  6184. int i, main_mem_width, rc;
  6185. DP(NETIF_MSG_HW, "starting func init func %d\n", func);
  6186. /* FLR cleanup - hmmm */
  6187. if (!CHIP_IS_E1x(bp)) {
  6188. rc = bnx2x_pf_flr_clnup(bp);
  6189. if (rc) {
  6190. bnx2x_fw_dump(bp);
  6191. return rc;
  6192. }
  6193. }
  6194. /* set MSI reconfigure capability */
  6195. if (bp->common.int_block == INT_BLOCK_HC) {
  6196. addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0);
  6197. val = REG_RD(bp, addr);
  6198. val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0;
  6199. REG_WR(bp, addr, val);
  6200. }
  6201. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  6202. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  6203. ilt = BP_ILT(bp);
  6204. cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
  6205. if (IS_SRIOV(bp))
  6206. cdu_ilt_start += BNX2X_FIRST_VF_CID/ILT_PAGE_CIDS;
  6207. cdu_ilt_start = bnx2x_iov_init_ilt(bp, cdu_ilt_start);
  6208. /* since BNX2X_FIRST_VF_CID > 0 the PF L2 cids precedes
  6209. * those of the VFs, so start line should be reset
  6210. */
  6211. cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
  6212. for (i = 0; i < L2_ILT_LINES(bp); i++) {
  6213. ilt->lines[cdu_ilt_start + i].page = bp->context[i].vcxt;
  6214. ilt->lines[cdu_ilt_start + i].page_mapping =
  6215. bp->context[i].cxt_mapping;
  6216. ilt->lines[cdu_ilt_start + i].size = bp->context[i].size;
  6217. }
  6218. bnx2x_ilt_init_op(bp, INITOP_SET);
  6219. if (!CONFIGURE_NIC_MODE(bp)) {
  6220. bnx2x_init_searcher(bp);
  6221. REG_WR(bp, PRS_REG_NIC_MODE, 0);
  6222. DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
  6223. } else {
  6224. /* Set NIC mode */
  6225. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  6226. DP(NETIF_MSG_IFUP, "NIC MODE configrued\n");
  6227. }
  6228. if (!CHIP_IS_E1x(bp)) {
  6229. u32 pf_conf = IGU_PF_CONF_FUNC_EN;
  6230. /* Turn on a single ISR mode in IGU if driver is going to use
  6231. * INT#x or MSI
  6232. */
  6233. if (!(bp->flags & USING_MSIX_FLAG))
  6234. pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN;
  6235. /*
  6236. * Timers workaround bug: function init part.
  6237. * Need to wait 20msec after initializing ILT,
  6238. * needed to make sure there are no requests in
  6239. * one of the PXP internal queues with "old" ILT addresses
  6240. */
  6241. msleep(20);
  6242. /*
  6243. * Master enable - Due to WB DMAE writes performed before this
  6244. * register is re-initialized as part of the regular function
  6245. * init
  6246. */
  6247. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  6248. /* Enable the function in IGU */
  6249. REG_WR(bp, IGU_REG_PF_CONFIGURATION, pf_conf);
  6250. }
  6251. bp->dmae_ready = 1;
  6252. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  6253. if (!CHIP_IS_E1x(bp))
  6254. REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, func);
  6255. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  6256. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  6257. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  6258. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  6259. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  6260. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  6261. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  6262. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  6263. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  6264. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  6265. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  6266. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  6267. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  6268. if (!CHIP_IS_E1x(bp))
  6269. REG_WR(bp, QM_REG_PF_EN, 1);
  6270. if (!CHIP_IS_E1x(bp)) {
  6271. REG_WR(bp, TSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6272. REG_WR(bp, USEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6273. REG_WR(bp, CSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6274. REG_WR(bp, XSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6275. }
  6276. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  6277. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  6278. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  6279. bnx2x_iov_init_dq(bp);
  6280. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  6281. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  6282. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  6283. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  6284. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  6285. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  6286. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  6287. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  6288. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  6289. if (!CHIP_IS_E1x(bp))
  6290. REG_WR(bp, PBF_REG_DISABLE_PF, 0);
  6291. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  6292. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  6293. if (!CHIP_IS_E1x(bp))
  6294. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 1);
  6295. if (IS_MF(bp)) {
  6296. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
  6297. REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port*8, bp->mf_ov);
  6298. }
  6299. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  6300. /* HC init per function */
  6301. if (bp->common.int_block == INT_BLOCK_HC) {
  6302. if (CHIP_IS_E1H(bp)) {
  6303. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  6304. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  6305. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  6306. }
  6307. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  6308. } else {
  6309. int num_segs, sb_idx, prod_offset;
  6310. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  6311. if (!CHIP_IS_E1x(bp)) {
  6312. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  6313. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  6314. }
  6315. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  6316. if (!CHIP_IS_E1x(bp)) {
  6317. int dsb_idx = 0;
  6318. /**
  6319. * Producer memory:
  6320. * E2 mode: address 0-135 match to the mapping memory;
  6321. * 136 - PF0 default prod; 137 - PF1 default prod;
  6322. * 138 - PF2 default prod; 139 - PF3 default prod;
  6323. * 140 - PF0 attn prod; 141 - PF1 attn prod;
  6324. * 142 - PF2 attn prod; 143 - PF3 attn prod;
  6325. * 144-147 reserved.
  6326. *
  6327. * E1.5 mode - In backward compatible mode;
  6328. * for non default SB; each even line in the memory
  6329. * holds the U producer and each odd line hold
  6330. * the C producer. The first 128 producers are for
  6331. * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20
  6332. * producers are for the DSB for each PF.
  6333. * Each PF has five segments: (the order inside each
  6334. * segment is PF0; PF1; PF2; PF3) - 128-131 U prods;
  6335. * 132-135 C prods; 136-139 X prods; 140-143 T prods;
  6336. * 144-147 attn prods;
  6337. */
  6338. /* non-default-status-blocks */
  6339. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  6340. IGU_BC_NDSB_NUM_SEGS : IGU_NORM_NDSB_NUM_SEGS;
  6341. for (sb_idx = 0; sb_idx < bp->igu_sb_cnt; sb_idx++) {
  6342. prod_offset = (bp->igu_base_sb + sb_idx) *
  6343. num_segs;
  6344. for (i = 0; i < num_segs; i++) {
  6345. addr = IGU_REG_PROD_CONS_MEMORY +
  6346. (prod_offset + i) * 4;
  6347. REG_WR(bp, addr, 0);
  6348. }
  6349. /* send consumer update with value 0 */
  6350. bnx2x_ack_sb(bp, bp->igu_base_sb + sb_idx,
  6351. USTORM_ID, 0, IGU_INT_NOP, 1);
  6352. bnx2x_igu_clear_sb(bp,
  6353. bp->igu_base_sb + sb_idx);
  6354. }
  6355. /* default-status-blocks */
  6356. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  6357. IGU_BC_DSB_NUM_SEGS : IGU_NORM_DSB_NUM_SEGS;
  6358. if (CHIP_MODE_IS_4_PORT(bp))
  6359. dsb_idx = BP_FUNC(bp);
  6360. else
  6361. dsb_idx = BP_VN(bp);
  6362. prod_offset = (CHIP_INT_MODE_IS_BC(bp) ?
  6363. IGU_BC_BASE_DSB_PROD + dsb_idx :
  6364. IGU_NORM_BASE_DSB_PROD + dsb_idx);
  6365. /*
  6366. * igu prods come in chunks of E1HVN_MAX (4) -
  6367. * does not matters what is the current chip mode
  6368. */
  6369. for (i = 0; i < (num_segs * E1HVN_MAX);
  6370. i += E1HVN_MAX) {
  6371. addr = IGU_REG_PROD_CONS_MEMORY +
  6372. (prod_offset + i)*4;
  6373. REG_WR(bp, addr, 0);
  6374. }
  6375. /* send consumer update with 0 */
  6376. if (CHIP_INT_MODE_IS_BC(bp)) {
  6377. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6378. USTORM_ID, 0, IGU_INT_NOP, 1);
  6379. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6380. CSTORM_ID, 0, IGU_INT_NOP, 1);
  6381. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6382. XSTORM_ID, 0, IGU_INT_NOP, 1);
  6383. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6384. TSTORM_ID, 0, IGU_INT_NOP, 1);
  6385. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6386. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  6387. } else {
  6388. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6389. USTORM_ID, 0, IGU_INT_NOP, 1);
  6390. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6391. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  6392. }
  6393. bnx2x_igu_clear_sb(bp, bp->igu_dsb_id);
  6394. /* !!! these should become driver const once
  6395. rf-tool supports split-68 const */
  6396. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0);
  6397. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0);
  6398. REG_WR(bp, IGU_REG_SB_MASK_LSB, 0);
  6399. REG_WR(bp, IGU_REG_SB_MASK_MSB, 0);
  6400. REG_WR(bp, IGU_REG_PBA_STATUS_LSB, 0);
  6401. REG_WR(bp, IGU_REG_PBA_STATUS_MSB, 0);
  6402. }
  6403. }
  6404. /* Reset PCIE errors for debug */
  6405. REG_WR(bp, 0x2114, 0xffffffff);
  6406. REG_WR(bp, 0x2120, 0xffffffff);
  6407. if (CHIP_IS_E1x(bp)) {
  6408. main_mem_size = HC_REG_MAIN_MEMORY_SIZE / 2; /*dwords*/
  6409. main_mem_base = HC_REG_MAIN_MEMORY +
  6410. BP_PORT(bp) * (main_mem_size * 4);
  6411. main_mem_prty_clr = HC_REG_HC_PRTY_STS_CLR;
  6412. main_mem_width = 8;
  6413. val = REG_RD(bp, main_mem_prty_clr);
  6414. if (val)
  6415. DP(NETIF_MSG_HW,
  6416. "Hmmm... Parity errors in HC block during function init (0x%x)!\n",
  6417. val);
  6418. /* Clear "false" parity errors in MSI-X table */
  6419. for (i = main_mem_base;
  6420. i < main_mem_base + main_mem_size * 4;
  6421. i += main_mem_width) {
  6422. bnx2x_read_dmae(bp, i, main_mem_width / 4);
  6423. bnx2x_write_dmae(bp, bnx2x_sp_mapping(bp, wb_data),
  6424. i, main_mem_width / 4);
  6425. }
  6426. /* Clear HC parity attention */
  6427. REG_RD(bp, main_mem_prty_clr);
  6428. }
  6429. #ifdef BNX2X_STOP_ON_ERROR
  6430. /* Enable STORMs SP logging */
  6431. REG_WR8(bp, BAR_USTRORM_INTMEM +
  6432. USTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6433. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  6434. TSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6435. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6436. CSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6437. REG_WR8(bp, BAR_XSTRORM_INTMEM +
  6438. XSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6439. #endif
  6440. bnx2x_phy_probe(&bp->link_params);
  6441. return 0;
  6442. }
  6443. void bnx2x_free_mem_cnic(struct bnx2x *bp)
  6444. {
  6445. bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_FREE);
  6446. if (!CHIP_IS_E1x(bp))
  6447. BNX2X_PCI_FREE(bp->cnic_sb.e2_sb, bp->cnic_sb_mapping,
  6448. sizeof(struct host_hc_status_block_e2));
  6449. else
  6450. BNX2X_PCI_FREE(bp->cnic_sb.e1x_sb, bp->cnic_sb_mapping,
  6451. sizeof(struct host_hc_status_block_e1x));
  6452. BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
  6453. }
  6454. void bnx2x_free_mem(struct bnx2x *bp)
  6455. {
  6456. int i;
  6457. /* fastpath */
  6458. bnx2x_free_fp_mem(bp);
  6459. /* end of fastpath */
  6460. BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping,
  6461. sizeof(struct host_sp_status_block));
  6462. BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
  6463. bp->fw_stats_data_sz + bp->fw_stats_req_sz);
  6464. BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping,
  6465. sizeof(struct bnx2x_slowpath));
  6466. for (i = 0; i < L2_ILT_LINES(bp); i++)
  6467. BNX2X_PCI_FREE(bp->context[i].vcxt, bp->context[i].cxt_mapping,
  6468. bp->context[i].size);
  6469. bnx2x_ilt_mem_op(bp, ILT_MEMOP_FREE);
  6470. BNX2X_FREE(bp->ilt->lines);
  6471. BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE);
  6472. BNX2X_PCI_FREE(bp->eq_ring, bp->eq_mapping,
  6473. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  6474. }
  6475. int bnx2x_alloc_mem_cnic(struct bnx2x *bp)
  6476. {
  6477. if (!CHIP_IS_E1x(bp))
  6478. /* size = the status block + ramrod buffers */
  6479. BNX2X_PCI_ALLOC(bp->cnic_sb.e2_sb, &bp->cnic_sb_mapping,
  6480. sizeof(struct host_hc_status_block_e2));
  6481. else
  6482. BNX2X_PCI_ALLOC(bp->cnic_sb.e1x_sb,
  6483. &bp->cnic_sb_mapping,
  6484. sizeof(struct
  6485. host_hc_status_block_e1x));
  6486. if (CONFIGURE_NIC_MODE(bp))
  6487. /* allocate searcher T2 table, as it wan't allocated before */
  6488. BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
  6489. /* write address to which L5 should insert its values */
  6490. bp->cnic_eth_dev.addr_drv_info_to_mcp =
  6491. &bp->slowpath->drv_info_to_mcp;
  6492. if (bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_ALLOC))
  6493. goto alloc_mem_err;
  6494. return 0;
  6495. alloc_mem_err:
  6496. bnx2x_free_mem_cnic(bp);
  6497. BNX2X_ERR("Can't allocate memory\n");
  6498. return -ENOMEM;
  6499. }
  6500. int bnx2x_alloc_mem(struct bnx2x *bp)
  6501. {
  6502. int i, allocated, context_size;
  6503. if (!CONFIGURE_NIC_MODE(bp))
  6504. /* allocate searcher T2 table */
  6505. BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
  6506. BNX2X_PCI_ALLOC(bp->def_status_blk, &bp->def_status_blk_mapping,
  6507. sizeof(struct host_sp_status_block));
  6508. BNX2X_PCI_ALLOC(bp->slowpath, &bp->slowpath_mapping,
  6509. sizeof(struct bnx2x_slowpath));
  6510. /* Allocate memory for CDU context:
  6511. * This memory is allocated separately and not in the generic ILT
  6512. * functions because CDU differs in few aspects:
  6513. * 1. There are multiple entities allocating memory for context -
  6514. * 'regular' driver, CNIC and SRIOV driver. Each separately controls
  6515. * its own ILT lines.
  6516. * 2. Since CDU page-size is not a single 4KB page (which is the case
  6517. * for the other ILT clients), to be efficient we want to support
  6518. * allocation of sub-page-size in the last entry.
  6519. * 3. Context pointers are used by the driver to pass to FW / update
  6520. * the context (for the other ILT clients the pointers are used just to
  6521. * free the memory during unload).
  6522. */
  6523. context_size = sizeof(union cdu_context) * BNX2X_L2_CID_COUNT(bp);
  6524. for (i = 0, allocated = 0; allocated < context_size; i++) {
  6525. bp->context[i].size = min(CDU_ILT_PAGE_SZ,
  6526. (context_size - allocated));
  6527. BNX2X_PCI_ALLOC(bp->context[i].vcxt,
  6528. &bp->context[i].cxt_mapping,
  6529. bp->context[i].size);
  6530. allocated += bp->context[i].size;
  6531. }
  6532. BNX2X_ALLOC(bp->ilt->lines, sizeof(struct ilt_line) * ILT_MAX_LINES);
  6533. if (bnx2x_ilt_mem_op(bp, ILT_MEMOP_ALLOC))
  6534. goto alloc_mem_err;
  6535. if (bnx2x_iov_alloc_mem(bp))
  6536. goto alloc_mem_err;
  6537. /* Slow path ring */
  6538. BNX2X_PCI_ALLOC(bp->spq, &bp->spq_mapping, BCM_PAGE_SIZE);
  6539. /* EQ */
  6540. BNX2X_PCI_ALLOC(bp->eq_ring, &bp->eq_mapping,
  6541. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  6542. return 0;
  6543. alloc_mem_err:
  6544. bnx2x_free_mem(bp);
  6545. BNX2X_ERR("Can't allocate memory\n");
  6546. return -ENOMEM;
  6547. }
  6548. /*
  6549. * Init service functions
  6550. */
  6551. int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac,
  6552. struct bnx2x_vlan_mac_obj *obj, bool set,
  6553. int mac_type, unsigned long *ramrod_flags)
  6554. {
  6555. int rc;
  6556. struct bnx2x_vlan_mac_ramrod_params ramrod_param;
  6557. memset(&ramrod_param, 0, sizeof(ramrod_param));
  6558. /* Fill general parameters */
  6559. ramrod_param.vlan_mac_obj = obj;
  6560. ramrod_param.ramrod_flags = *ramrod_flags;
  6561. /* Fill a user request section if needed */
  6562. if (!test_bit(RAMROD_CONT, ramrod_flags)) {
  6563. memcpy(ramrod_param.user_req.u.mac.mac, mac, ETH_ALEN);
  6564. __set_bit(mac_type, &ramrod_param.user_req.vlan_mac_flags);
  6565. /* Set the command: ADD or DEL */
  6566. if (set)
  6567. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD;
  6568. else
  6569. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_DEL;
  6570. }
  6571. rc = bnx2x_config_vlan_mac(bp, &ramrod_param);
  6572. if (rc == -EEXIST) {
  6573. DP(BNX2X_MSG_SP, "Failed to schedule ADD operations: %d\n", rc);
  6574. /* do not treat adding same MAC as error */
  6575. rc = 0;
  6576. } else if (rc < 0)
  6577. BNX2X_ERR("%s MAC failed\n", (set ? "Set" : "Del"));
  6578. return rc;
  6579. }
  6580. int bnx2x_del_all_macs(struct bnx2x *bp,
  6581. struct bnx2x_vlan_mac_obj *mac_obj,
  6582. int mac_type, bool wait_for_comp)
  6583. {
  6584. int rc;
  6585. unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
  6586. /* Wait for completion of requested */
  6587. if (wait_for_comp)
  6588. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  6589. /* Set the mac type of addresses we want to clear */
  6590. __set_bit(mac_type, &vlan_mac_flags);
  6591. rc = mac_obj->delete_all(bp, mac_obj, &vlan_mac_flags, &ramrod_flags);
  6592. if (rc < 0)
  6593. BNX2X_ERR("Failed to delete MACs: %d\n", rc);
  6594. return rc;
  6595. }
  6596. int bnx2x_set_eth_mac(struct bnx2x *bp, bool set)
  6597. {
  6598. unsigned long ramrod_flags = 0;
  6599. if (is_zero_ether_addr(bp->dev->dev_addr) &&
  6600. (IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp))) {
  6601. DP(NETIF_MSG_IFUP | NETIF_MSG_IFDOWN,
  6602. "Ignoring Zero MAC for STORAGE SD mode\n");
  6603. return 0;
  6604. }
  6605. DP(NETIF_MSG_IFUP, "Adding Eth MAC\n");
  6606. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  6607. /* Eth MAC is set on RSS leading client (fp[0]) */
  6608. return bnx2x_set_mac_one(bp, bp->dev->dev_addr, &bp->sp_objs->mac_obj,
  6609. set, BNX2X_ETH_MAC, &ramrod_flags);
  6610. }
  6611. int bnx2x_setup_leading(struct bnx2x *bp)
  6612. {
  6613. return bnx2x_setup_queue(bp, &bp->fp[0], 1);
  6614. }
  6615. /**
  6616. * bnx2x_set_int_mode - configure interrupt mode
  6617. *
  6618. * @bp: driver handle
  6619. *
  6620. * In case of MSI-X it will also try to enable MSI-X.
  6621. */
  6622. int bnx2x_set_int_mode(struct bnx2x *bp)
  6623. {
  6624. int rc = 0;
  6625. if (IS_VF(bp) && int_mode != BNX2X_INT_MODE_MSIX)
  6626. return -EINVAL;
  6627. switch (int_mode) {
  6628. case BNX2X_INT_MODE_MSIX:
  6629. /* attempt to enable msix */
  6630. rc = bnx2x_enable_msix(bp);
  6631. /* msix attained */
  6632. if (!rc)
  6633. return 0;
  6634. /* vfs use only msix */
  6635. if (rc && IS_VF(bp))
  6636. return rc;
  6637. /* failed to enable multiple MSI-X */
  6638. BNX2X_DEV_INFO("Failed to enable multiple MSI-X (%d), set number of queues to %d\n",
  6639. bp->num_queues,
  6640. 1 + bp->num_cnic_queues);
  6641. /* falling through... */
  6642. case BNX2X_INT_MODE_MSI:
  6643. bnx2x_enable_msi(bp);
  6644. /* falling through... */
  6645. case BNX2X_INT_MODE_INTX:
  6646. bp->num_ethernet_queues = 1;
  6647. bp->num_queues = bp->num_ethernet_queues + bp->num_cnic_queues;
  6648. BNX2X_DEV_INFO("set number of queues to 1\n");
  6649. break;
  6650. default:
  6651. BNX2X_DEV_INFO("unknown value in int_mode module parameter\n");
  6652. return -EINVAL;
  6653. }
  6654. return 0;
  6655. }
  6656. /* must be called prior to any HW initializations */
  6657. static inline u16 bnx2x_cid_ilt_lines(struct bnx2x *bp)
  6658. {
  6659. if (IS_SRIOV(bp))
  6660. return (BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)/ILT_PAGE_CIDS;
  6661. return L2_ILT_LINES(bp);
  6662. }
  6663. void bnx2x_ilt_set_info(struct bnx2x *bp)
  6664. {
  6665. struct ilt_client_info *ilt_client;
  6666. struct bnx2x_ilt *ilt = BP_ILT(bp);
  6667. u16 line = 0;
  6668. ilt->start_line = FUNC_ILT_BASE(BP_FUNC(bp));
  6669. DP(BNX2X_MSG_SP, "ilt starts at line %d\n", ilt->start_line);
  6670. /* CDU */
  6671. ilt_client = &ilt->clients[ILT_CLIENT_CDU];
  6672. ilt_client->client_num = ILT_CLIENT_CDU;
  6673. ilt_client->page_size = CDU_ILT_PAGE_SZ;
  6674. ilt_client->flags = ILT_CLIENT_SKIP_MEM;
  6675. ilt_client->start = line;
  6676. line += bnx2x_cid_ilt_lines(bp);
  6677. if (CNIC_SUPPORT(bp))
  6678. line += CNIC_ILT_LINES;
  6679. ilt_client->end = line - 1;
  6680. DP(NETIF_MSG_IFUP, "ilt client[CDU]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6681. ilt_client->start,
  6682. ilt_client->end,
  6683. ilt_client->page_size,
  6684. ilt_client->flags,
  6685. ilog2(ilt_client->page_size >> 12));
  6686. /* QM */
  6687. if (QM_INIT(bp->qm_cid_count)) {
  6688. ilt_client = &ilt->clients[ILT_CLIENT_QM];
  6689. ilt_client->client_num = ILT_CLIENT_QM;
  6690. ilt_client->page_size = QM_ILT_PAGE_SZ;
  6691. ilt_client->flags = 0;
  6692. ilt_client->start = line;
  6693. /* 4 bytes for each cid */
  6694. line += DIV_ROUND_UP(bp->qm_cid_count * QM_QUEUES_PER_FUNC * 4,
  6695. QM_ILT_PAGE_SZ);
  6696. ilt_client->end = line - 1;
  6697. DP(NETIF_MSG_IFUP,
  6698. "ilt client[QM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6699. ilt_client->start,
  6700. ilt_client->end,
  6701. ilt_client->page_size,
  6702. ilt_client->flags,
  6703. ilog2(ilt_client->page_size >> 12));
  6704. }
  6705. if (CNIC_SUPPORT(bp)) {
  6706. /* SRC */
  6707. ilt_client = &ilt->clients[ILT_CLIENT_SRC];
  6708. ilt_client->client_num = ILT_CLIENT_SRC;
  6709. ilt_client->page_size = SRC_ILT_PAGE_SZ;
  6710. ilt_client->flags = 0;
  6711. ilt_client->start = line;
  6712. line += SRC_ILT_LINES;
  6713. ilt_client->end = line - 1;
  6714. DP(NETIF_MSG_IFUP,
  6715. "ilt client[SRC]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6716. ilt_client->start,
  6717. ilt_client->end,
  6718. ilt_client->page_size,
  6719. ilt_client->flags,
  6720. ilog2(ilt_client->page_size >> 12));
  6721. /* TM */
  6722. ilt_client = &ilt->clients[ILT_CLIENT_TM];
  6723. ilt_client->client_num = ILT_CLIENT_TM;
  6724. ilt_client->page_size = TM_ILT_PAGE_SZ;
  6725. ilt_client->flags = 0;
  6726. ilt_client->start = line;
  6727. line += TM_ILT_LINES;
  6728. ilt_client->end = line - 1;
  6729. DP(NETIF_MSG_IFUP,
  6730. "ilt client[TM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6731. ilt_client->start,
  6732. ilt_client->end,
  6733. ilt_client->page_size,
  6734. ilt_client->flags,
  6735. ilog2(ilt_client->page_size >> 12));
  6736. }
  6737. BUG_ON(line > ILT_MAX_LINES);
  6738. }
  6739. /**
  6740. * bnx2x_pf_q_prep_init - prepare INIT transition parameters
  6741. *
  6742. * @bp: driver handle
  6743. * @fp: pointer to fastpath
  6744. * @init_params: pointer to parameters structure
  6745. *
  6746. * parameters configured:
  6747. * - HC configuration
  6748. * - Queue's CDU context
  6749. */
  6750. static void bnx2x_pf_q_prep_init(struct bnx2x *bp,
  6751. struct bnx2x_fastpath *fp, struct bnx2x_queue_init_params *init_params)
  6752. {
  6753. u8 cos;
  6754. int cxt_index, cxt_offset;
  6755. /* FCoE Queue uses Default SB, thus has no HC capabilities */
  6756. if (!IS_FCOE_FP(fp)) {
  6757. __set_bit(BNX2X_Q_FLG_HC, &init_params->rx.flags);
  6758. __set_bit(BNX2X_Q_FLG_HC, &init_params->tx.flags);
  6759. /* If HC is supporterd, enable host coalescing in the transition
  6760. * to INIT state.
  6761. */
  6762. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->rx.flags);
  6763. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->tx.flags);
  6764. /* HC rate */
  6765. init_params->rx.hc_rate = bp->rx_ticks ?
  6766. (1000000 / bp->rx_ticks) : 0;
  6767. init_params->tx.hc_rate = bp->tx_ticks ?
  6768. (1000000 / bp->tx_ticks) : 0;
  6769. /* FW SB ID */
  6770. init_params->rx.fw_sb_id = init_params->tx.fw_sb_id =
  6771. fp->fw_sb_id;
  6772. /*
  6773. * CQ index among the SB indices: FCoE clients uses the default
  6774. * SB, therefore it's different.
  6775. */
  6776. init_params->rx.sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  6777. init_params->tx.sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS;
  6778. }
  6779. /* set maximum number of COSs supported by this queue */
  6780. init_params->max_cos = fp->max_cos;
  6781. DP(NETIF_MSG_IFUP, "fp: %d setting queue params max cos to: %d\n",
  6782. fp->index, init_params->max_cos);
  6783. /* set the context pointers queue object */
  6784. for (cos = FIRST_TX_COS_INDEX; cos < init_params->max_cos; cos++) {
  6785. cxt_index = fp->txdata_ptr[cos]->cid / ILT_PAGE_CIDS;
  6786. cxt_offset = fp->txdata_ptr[cos]->cid - (cxt_index *
  6787. ILT_PAGE_CIDS);
  6788. init_params->cxts[cos] =
  6789. &bp->context[cxt_index].vcxt[cxt_offset].eth;
  6790. }
  6791. }
  6792. static int bnx2x_setup_tx_only(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  6793. struct bnx2x_queue_state_params *q_params,
  6794. struct bnx2x_queue_setup_tx_only_params *tx_only_params,
  6795. int tx_index, bool leading)
  6796. {
  6797. memset(tx_only_params, 0, sizeof(*tx_only_params));
  6798. /* Set the command */
  6799. q_params->cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  6800. /* Set tx-only QUEUE flags: don't zero statistics */
  6801. tx_only_params->flags = bnx2x_get_common_flags(bp, fp, false);
  6802. /* choose the index of the cid to send the slow path on */
  6803. tx_only_params->cid_index = tx_index;
  6804. /* Set general TX_ONLY_SETUP parameters */
  6805. bnx2x_pf_q_prep_general(bp, fp, &tx_only_params->gen_params, tx_index);
  6806. /* Set Tx TX_ONLY_SETUP parameters */
  6807. bnx2x_pf_tx_q_prep(bp, fp, &tx_only_params->txq_params, tx_index);
  6808. DP(NETIF_MSG_IFUP,
  6809. "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",
  6810. tx_index, q_params->q_obj->cids[FIRST_TX_COS_INDEX],
  6811. q_params->q_obj->cids[tx_index], q_params->q_obj->cl_id,
  6812. tx_only_params->gen_params.spcl_id, tx_only_params->flags);
  6813. /* send the ramrod */
  6814. return bnx2x_queue_state_change(bp, q_params);
  6815. }
  6816. /**
  6817. * bnx2x_setup_queue - setup queue
  6818. *
  6819. * @bp: driver handle
  6820. * @fp: pointer to fastpath
  6821. * @leading: is leading
  6822. *
  6823. * This function performs 2 steps in a Queue state machine
  6824. * actually: 1) RESET->INIT 2) INIT->SETUP
  6825. */
  6826. int bnx2x_setup_queue(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  6827. bool leading)
  6828. {
  6829. struct bnx2x_queue_state_params q_params = {NULL};
  6830. struct bnx2x_queue_setup_params *setup_params =
  6831. &q_params.params.setup;
  6832. struct bnx2x_queue_setup_tx_only_params *tx_only_params =
  6833. &q_params.params.tx_only;
  6834. int rc;
  6835. u8 tx_index;
  6836. DP(NETIF_MSG_IFUP, "setting up queue %d\n", fp->index);
  6837. /* reset IGU state skip FCoE L2 queue */
  6838. if (!IS_FCOE_FP(fp))
  6839. bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID, 0,
  6840. IGU_INT_ENABLE, 0);
  6841. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  6842. /* We want to wait for completion in this context */
  6843. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  6844. /* Prepare the INIT parameters */
  6845. bnx2x_pf_q_prep_init(bp, fp, &q_params.params.init);
  6846. /* Set the command */
  6847. q_params.cmd = BNX2X_Q_CMD_INIT;
  6848. /* Change the state to INIT */
  6849. rc = bnx2x_queue_state_change(bp, &q_params);
  6850. if (rc) {
  6851. BNX2X_ERR("Queue(%d) INIT failed\n", fp->index);
  6852. return rc;
  6853. }
  6854. DP(NETIF_MSG_IFUP, "init complete\n");
  6855. /* Now move the Queue to the SETUP state... */
  6856. memset(setup_params, 0, sizeof(*setup_params));
  6857. /* Set QUEUE flags */
  6858. setup_params->flags = bnx2x_get_q_flags(bp, fp, leading);
  6859. /* Set general SETUP parameters */
  6860. bnx2x_pf_q_prep_general(bp, fp, &setup_params->gen_params,
  6861. FIRST_TX_COS_INDEX);
  6862. bnx2x_pf_rx_q_prep(bp, fp, &setup_params->pause_params,
  6863. &setup_params->rxq_params);
  6864. bnx2x_pf_tx_q_prep(bp, fp, &setup_params->txq_params,
  6865. FIRST_TX_COS_INDEX);
  6866. /* Set the command */
  6867. q_params.cmd = BNX2X_Q_CMD_SETUP;
  6868. if (IS_FCOE_FP(fp))
  6869. bp->fcoe_init = true;
  6870. /* Change the state to SETUP */
  6871. rc = bnx2x_queue_state_change(bp, &q_params);
  6872. if (rc) {
  6873. BNX2X_ERR("Queue(%d) SETUP failed\n", fp->index);
  6874. return rc;
  6875. }
  6876. /* loop through the relevant tx-only indices */
  6877. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  6878. tx_index < fp->max_cos;
  6879. tx_index++) {
  6880. /* prepare and send tx-only ramrod*/
  6881. rc = bnx2x_setup_tx_only(bp, fp, &q_params,
  6882. tx_only_params, tx_index, leading);
  6883. if (rc) {
  6884. BNX2X_ERR("Queue(%d.%d) TX_ONLY_SETUP failed\n",
  6885. fp->index, tx_index);
  6886. return rc;
  6887. }
  6888. }
  6889. return rc;
  6890. }
  6891. static int bnx2x_stop_queue(struct bnx2x *bp, int index)
  6892. {
  6893. struct bnx2x_fastpath *fp = &bp->fp[index];
  6894. struct bnx2x_fp_txdata *txdata;
  6895. struct bnx2x_queue_state_params q_params = {NULL};
  6896. int rc, tx_index;
  6897. DP(NETIF_MSG_IFDOWN, "stopping queue %d cid %d\n", index, fp->cid);
  6898. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  6899. /* We want to wait for completion in this context */
  6900. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  6901. /* close tx-only connections */
  6902. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  6903. tx_index < fp->max_cos;
  6904. tx_index++){
  6905. /* ascertain this is a normal queue*/
  6906. txdata = fp->txdata_ptr[tx_index];
  6907. DP(NETIF_MSG_IFDOWN, "stopping tx-only queue %d\n",
  6908. txdata->txq_index);
  6909. /* send halt terminate on tx-only connection */
  6910. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  6911. memset(&q_params.params.terminate, 0,
  6912. sizeof(q_params.params.terminate));
  6913. q_params.params.terminate.cid_index = tx_index;
  6914. rc = bnx2x_queue_state_change(bp, &q_params);
  6915. if (rc)
  6916. return rc;
  6917. /* send halt terminate on tx-only connection */
  6918. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  6919. memset(&q_params.params.cfc_del, 0,
  6920. sizeof(q_params.params.cfc_del));
  6921. q_params.params.cfc_del.cid_index = tx_index;
  6922. rc = bnx2x_queue_state_change(bp, &q_params);
  6923. if (rc)
  6924. return rc;
  6925. }
  6926. /* Stop the primary connection: */
  6927. /* ...halt the connection */
  6928. q_params.cmd = BNX2X_Q_CMD_HALT;
  6929. rc = bnx2x_queue_state_change(bp, &q_params);
  6930. if (rc)
  6931. return rc;
  6932. /* ...terminate the connection */
  6933. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  6934. memset(&q_params.params.terminate, 0,
  6935. sizeof(q_params.params.terminate));
  6936. q_params.params.terminate.cid_index = FIRST_TX_COS_INDEX;
  6937. rc = bnx2x_queue_state_change(bp, &q_params);
  6938. if (rc)
  6939. return rc;
  6940. /* ...delete cfc entry */
  6941. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  6942. memset(&q_params.params.cfc_del, 0,
  6943. sizeof(q_params.params.cfc_del));
  6944. q_params.params.cfc_del.cid_index = FIRST_TX_COS_INDEX;
  6945. return bnx2x_queue_state_change(bp, &q_params);
  6946. }
  6947. static void bnx2x_reset_func(struct bnx2x *bp)
  6948. {
  6949. int port = BP_PORT(bp);
  6950. int func = BP_FUNC(bp);
  6951. int i;
  6952. /* Disable the function in the FW */
  6953. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0);
  6954. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0);
  6955. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0);
  6956. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0);
  6957. /* FP SBs */
  6958. for_each_eth_queue(bp, i) {
  6959. struct bnx2x_fastpath *fp = &bp->fp[i];
  6960. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6961. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id),
  6962. SB_DISABLED);
  6963. }
  6964. if (CNIC_LOADED(bp))
  6965. /* CNIC SB */
  6966. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6967. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET
  6968. (bnx2x_cnic_fw_sb_id(bp)), SB_DISABLED);
  6969. /* SP SB */
  6970. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6971. CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func),
  6972. SB_DISABLED);
  6973. for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++)
  6974. REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func),
  6975. 0);
  6976. /* Configure IGU */
  6977. if (bp->common.int_block == INT_BLOCK_HC) {
  6978. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  6979. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  6980. } else {
  6981. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  6982. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  6983. }
  6984. if (CNIC_LOADED(bp)) {
  6985. /* Disable Timer scan */
  6986. REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 0);
  6987. /*
  6988. * Wait for at least 10ms and up to 2 second for the timers
  6989. * scan to complete
  6990. */
  6991. for (i = 0; i < 200; i++) {
  6992. msleep(10);
  6993. if (!REG_RD(bp, TM_REG_LIN0_SCAN_ON + port*4))
  6994. break;
  6995. }
  6996. }
  6997. /* Clear ILT */
  6998. bnx2x_clear_func_ilt(bp, func);
  6999. /* Timers workaround bug for E2: if this is vnic-3,
  7000. * we need to set the entire ilt range for this timers.
  7001. */
  7002. if (!CHIP_IS_E1x(bp) && BP_VN(bp) == 3) {
  7003. struct ilt_client_info ilt_cli;
  7004. /* use dummy TM client */
  7005. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  7006. ilt_cli.start = 0;
  7007. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  7008. ilt_cli.client_num = ILT_CLIENT_TM;
  7009. bnx2x_ilt_boundry_init_op(bp, &ilt_cli, 0, INITOP_CLEAR);
  7010. }
  7011. /* this assumes that reset_port() called before reset_func()*/
  7012. if (!CHIP_IS_E1x(bp))
  7013. bnx2x_pf_disable(bp);
  7014. bp->dmae_ready = 0;
  7015. }
  7016. static void bnx2x_reset_port(struct bnx2x *bp)
  7017. {
  7018. int port = BP_PORT(bp);
  7019. u32 val;
  7020. /* Reset physical Link */
  7021. bnx2x__link_reset(bp);
  7022. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  7023. /* Do not rcv packets to BRB */
  7024. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0);
  7025. /* Do not direct rcv packets that are not for MCP to the BRB */
  7026. REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
  7027. NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
  7028. /* Configure AEU */
  7029. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0);
  7030. msleep(100);
  7031. /* Check for BRB port occupancy */
  7032. val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4);
  7033. if (val)
  7034. DP(NETIF_MSG_IFDOWN,
  7035. "BRB1 is not empty %d blocks are occupied\n", val);
  7036. /* TODO: Close Doorbell port? */
  7037. }
  7038. static int bnx2x_reset_hw(struct bnx2x *bp, u32 load_code)
  7039. {
  7040. struct bnx2x_func_state_params func_params = {NULL};
  7041. /* Prepare parameters for function state transitions */
  7042. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  7043. func_params.f_obj = &bp->func_obj;
  7044. func_params.cmd = BNX2X_F_CMD_HW_RESET;
  7045. func_params.params.hw_init.load_phase = load_code;
  7046. return bnx2x_func_state_change(bp, &func_params);
  7047. }
  7048. static int bnx2x_func_stop(struct bnx2x *bp)
  7049. {
  7050. struct bnx2x_func_state_params func_params = {NULL};
  7051. int rc;
  7052. /* Prepare parameters for function state transitions */
  7053. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  7054. func_params.f_obj = &bp->func_obj;
  7055. func_params.cmd = BNX2X_F_CMD_STOP;
  7056. /*
  7057. * Try to stop the function the 'good way'. If fails (in case
  7058. * of a parity error during bnx2x_chip_cleanup()) and we are
  7059. * not in a debug mode, perform a state transaction in order to
  7060. * enable further HW_RESET transaction.
  7061. */
  7062. rc = bnx2x_func_state_change(bp, &func_params);
  7063. if (rc) {
  7064. #ifdef BNX2X_STOP_ON_ERROR
  7065. return rc;
  7066. #else
  7067. BNX2X_ERR("FUNC_STOP ramrod failed. Running a dry transaction\n");
  7068. __set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags);
  7069. return bnx2x_func_state_change(bp, &func_params);
  7070. #endif
  7071. }
  7072. return 0;
  7073. }
  7074. /**
  7075. * bnx2x_send_unload_req - request unload mode from the MCP.
  7076. *
  7077. * @bp: driver handle
  7078. * @unload_mode: requested function's unload mode
  7079. *
  7080. * Return unload mode returned by the MCP: COMMON, PORT or FUNC.
  7081. */
  7082. u32 bnx2x_send_unload_req(struct bnx2x *bp, int unload_mode)
  7083. {
  7084. u32 reset_code = 0;
  7085. int port = BP_PORT(bp);
  7086. /* Select the UNLOAD request mode */
  7087. if (unload_mode == UNLOAD_NORMAL)
  7088. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  7089. else if (bp->flags & NO_WOL_FLAG)
  7090. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP;
  7091. else if (bp->wol) {
  7092. u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
  7093. u8 *mac_addr = bp->dev->dev_addr;
  7094. u32 val;
  7095. u16 pmc;
  7096. /* The mac address is written to entries 1-4 to
  7097. * preserve entry 0 which is used by the PMF
  7098. */
  7099. u8 entry = (BP_VN(bp) + 1)*8;
  7100. val = (mac_addr[0] << 8) | mac_addr[1];
  7101. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val);
  7102. val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
  7103. (mac_addr[4] << 8) | mac_addr[5];
  7104. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val);
  7105. /* Enable the PME and clear the status */
  7106. pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, &pmc);
  7107. pmc |= PCI_PM_CTRL_PME_ENABLE | PCI_PM_CTRL_PME_STATUS;
  7108. pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, pmc);
  7109. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN;
  7110. } else
  7111. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  7112. /* Send the request to the MCP */
  7113. if (!BP_NOMCP(bp))
  7114. reset_code = bnx2x_fw_command(bp, reset_code, 0);
  7115. else {
  7116. int path = BP_PATH(bp);
  7117. DP(NETIF_MSG_IFDOWN, "NO MCP - load counts[%d] %d, %d, %d\n",
  7118. path, load_count[path][0], load_count[path][1],
  7119. load_count[path][2]);
  7120. load_count[path][0]--;
  7121. load_count[path][1 + port]--;
  7122. DP(NETIF_MSG_IFDOWN, "NO MCP - new load counts[%d] %d, %d, %d\n",
  7123. path, load_count[path][0], load_count[path][1],
  7124. load_count[path][2]);
  7125. if (load_count[path][0] == 0)
  7126. reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON;
  7127. else if (load_count[path][1 + port] == 0)
  7128. reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT;
  7129. else
  7130. reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION;
  7131. }
  7132. return reset_code;
  7133. }
  7134. /**
  7135. * bnx2x_send_unload_done - send UNLOAD_DONE command to the MCP.
  7136. *
  7137. * @bp: driver handle
  7138. * @keep_link: true iff link should be kept up
  7139. */
  7140. void bnx2x_send_unload_done(struct bnx2x *bp, bool keep_link)
  7141. {
  7142. u32 reset_param = keep_link ? DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET : 0;
  7143. /* Report UNLOAD_DONE to MCP */
  7144. if (!BP_NOMCP(bp))
  7145. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, reset_param);
  7146. }
  7147. static int bnx2x_func_wait_started(struct bnx2x *bp)
  7148. {
  7149. int tout = 50;
  7150. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  7151. if (!bp->port.pmf)
  7152. return 0;
  7153. /*
  7154. * (assumption: No Attention from MCP at this stage)
  7155. * PMF probably in the middle of TXdisable/enable transaction
  7156. * 1. Sync IRS for default SB
  7157. * 2. Sync SP queue - this guarantes us that attention handling started
  7158. * 3. Wait, that TXdisable/enable transaction completes
  7159. *
  7160. * 1+2 guranty that if DCBx attention was scheduled it already changed
  7161. * pending bit of transaction from STARTED-->TX_STOPPED, if we alredy
  7162. * received complettion for the transaction the state is TX_STOPPED.
  7163. * State will return to STARTED after completion of TX_STOPPED-->STARTED
  7164. * transaction.
  7165. */
  7166. /* make sure default SB ISR is done */
  7167. if (msix)
  7168. synchronize_irq(bp->msix_table[0].vector);
  7169. else
  7170. synchronize_irq(bp->pdev->irq);
  7171. flush_workqueue(bnx2x_wq);
  7172. while (bnx2x_func_get_state(bp, &bp->func_obj) !=
  7173. BNX2X_F_STATE_STARTED && tout--)
  7174. msleep(20);
  7175. if (bnx2x_func_get_state(bp, &bp->func_obj) !=
  7176. BNX2X_F_STATE_STARTED) {
  7177. #ifdef BNX2X_STOP_ON_ERROR
  7178. BNX2X_ERR("Wrong function state\n");
  7179. return -EBUSY;
  7180. #else
  7181. /*
  7182. * Failed to complete the transaction in a "good way"
  7183. * Force both transactions with CLR bit
  7184. */
  7185. struct bnx2x_func_state_params func_params = {NULL};
  7186. DP(NETIF_MSG_IFDOWN,
  7187. "Hmmm... unexpected function state! Forcing STARTED-->TX_ST0PPED-->STARTED\n");
  7188. func_params.f_obj = &bp->func_obj;
  7189. __set_bit(RAMROD_DRV_CLR_ONLY,
  7190. &func_params.ramrod_flags);
  7191. /* STARTED-->TX_ST0PPED */
  7192. func_params.cmd = BNX2X_F_CMD_TX_STOP;
  7193. bnx2x_func_state_change(bp, &func_params);
  7194. /* TX_ST0PPED-->STARTED */
  7195. func_params.cmd = BNX2X_F_CMD_TX_START;
  7196. return bnx2x_func_state_change(bp, &func_params);
  7197. #endif
  7198. }
  7199. return 0;
  7200. }
  7201. void bnx2x_chip_cleanup(struct bnx2x *bp, int unload_mode, bool keep_link)
  7202. {
  7203. int port = BP_PORT(bp);
  7204. int i, rc = 0;
  7205. u8 cos;
  7206. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  7207. u32 reset_code;
  7208. /* Wait until tx fastpath tasks complete */
  7209. for_each_tx_queue(bp, i) {
  7210. struct bnx2x_fastpath *fp = &bp->fp[i];
  7211. for_each_cos_in_tx_queue(fp, cos)
  7212. rc = bnx2x_clean_tx_queue(bp, fp->txdata_ptr[cos]);
  7213. #ifdef BNX2X_STOP_ON_ERROR
  7214. if (rc)
  7215. return;
  7216. #endif
  7217. }
  7218. /* Give HW time to discard old tx messages */
  7219. usleep_range(1000, 2000);
  7220. /* Clean all ETH MACs */
  7221. rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_ETH_MAC,
  7222. false);
  7223. if (rc < 0)
  7224. BNX2X_ERR("Failed to delete all ETH macs: %d\n", rc);
  7225. /* Clean up UC list */
  7226. rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_UC_LIST_MAC,
  7227. true);
  7228. if (rc < 0)
  7229. BNX2X_ERR("Failed to schedule DEL commands for UC MACs list: %d\n",
  7230. rc);
  7231. /* Disable LLH */
  7232. if (!CHIP_IS_E1(bp))
  7233. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  7234. /* Set "drop all" (stop Rx).
  7235. * We need to take a netif_addr_lock() here in order to prevent
  7236. * a race between the completion code and this code.
  7237. */
  7238. netif_addr_lock_bh(bp->dev);
  7239. /* Schedule the rx_mode command */
  7240. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  7241. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  7242. else
  7243. bnx2x_set_storm_rx_mode(bp);
  7244. /* Cleanup multicast configuration */
  7245. rparam.mcast_obj = &bp->mcast_obj;
  7246. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  7247. if (rc < 0)
  7248. BNX2X_ERR("Failed to send DEL multicast command: %d\n", rc);
  7249. netif_addr_unlock_bh(bp->dev);
  7250. bnx2x_iov_chip_cleanup(bp);
  7251. /*
  7252. * Send the UNLOAD_REQUEST to the MCP. This will return if
  7253. * this function should perform FUNC, PORT or COMMON HW
  7254. * reset.
  7255. */
  7256. reset_code = bnx2x_send_unload_req(bp, unload_mode);
  7257. /*
  7258. * (assumption: No Attention from MCP at this stage)
  7259. * PMF probably in the middle of TXdisable/enable transaction
  7260. */
  7261. rc = bnx2x_func_wait_started(bp);
  7262. if (rc) {
  7263. BNX2X_ERR("bnx2x_func_wait_started failed\n");
  7264. #ifdef BNX2X_STOP_ON_ERROR
  7265. return;
  7266. #endif
  7267. }
  7268. /* Close multi and leading connections
  7269. * Completions for ramrods are collected in a synchronous way
  7270. */
  7271. for_each_eth_queue(bp, i)
  7272. if (bnx2x_stop_queue(bp, i))
  7273. #ifdef BNX2X_STOP_ON_ERROR
  7274. return;
  7275. #else
  7276. goto unload_error;
  7277. #endif
  7278. if (CNIC_LOADED(bp)) {
  7279. for_each_cnic_queue(bp, i)
  7280. if (bnx2x_stop_queue(bp, i))
  7281. #ifdef BNX2X_STOP_ON_ERROR
  7282. return;
  7283. #else
  7284. goto unload_error;
  7285. #endif
  7286. }
  7287. /* If SP settings didn't get completed so far - something
  7288. * very wrong has happen.
  7289. */
  7290. if (!bnx2x_wait_sp_comp(bp, ~0x0UL))
  7291. BNX2X_ERR("Hmmm... Common slow path ramrods got stuck!\n");
  7292. #ifndef BNX2X_STOP_ON_ERROR
  7293. unload_error:
  7294. #endif
  7295. rc = bnx2x_func_stop(bp);
  7296. if (rc) {
  7297. BNX2X_ERR("Function stop failed!\n");
  7298. #ifdef BNX2X_STOP_ON_ERROR
  7299. return;
  7300. #endif
  7301. }
  7302. /* Disable HW interrupts, NAPI */
  7303. bnx2x_netif_stop(bp, 1);
  7304. /* Delete all NAPI objects */
  7305. bnx2x_del_all_napi(bp);
  7306. if (CNIC_LOADED(bp))
  7307. bnx2x_del_all_napi_cnic(bp);
  7308. /* Release IRQs */
  7309. bnx2x_free_irq(bp);
  7310. /* Reset the chip */
  7311. rc = bnx2x_reset_hw(bp, reset_code);
  7312. if (rc)
  7313. BNX2X_ERR("HW_RESET failed\n");
  7314. /* Report UNLOAD_DONE to MCP */
  7315. bnx2x_send_unload_done(bp, keep_link);
  7316. }
  7317. void bnx2x_disable_close_the_gate(struct bnx2x *bp)
  7318. {
  7319. u32 val;
  7320. DP(NETIF_MSG_IFDOWN, "Disabling \"close the gates\"\n");
  7321. if (CHIP_IS_E1(bp)) {
  7322. int port = BP_PORT(bp);
  7323. u32 addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  7324. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  7325. val = REG_RD(bp, addr);
  7326. val &= ~(0x300);
  7327. REG_WR(bp, addr, val);
  7328. } else {
  7329. val = REG_RD(bp, MISC_REG_AEU_GENERAL_MASK);
  7330. val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK |
  7331. MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK);
  7332. REG_WR(bp, MISC_REG_AEU_GENERAL_MASK, val);
  7333. }
  7334. }
  7335. /* Close gates #2, #3 and #4: */
  7336. static void bnx2x_set_234_gates(struct bnx2x *bp, bool close)
  7337. {
  7338. u32 val;
  7339. /* Gates #2 and #4a are closed/opened for "not E1" only */
  7340. if (!CHIP_IS_E1(bp)) {
  7341. /* #4 */
  7342. REG_WR(bp, PXP_REG_HST_DISCARD_DOORBELLS, !!close);
  7343. /* #2 */
  7344. REG_WR(bp, PXP_REG_HST_DISCARD_INTERNAL_WRITES, !!close);
  7345. }
  7346. /* #3 */
  7347. if (CHIP_IS_E1x(bp)) {
  7348. /* Prevent interrupts from HC on both ports */
  7349. val = REG_RD(bp, HC_REG_CONFIG_1);
  7350. REG_WR(bp, HC_REG_CONFIG_1,
  7351. (!close) ? (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1) :
  7352. (val & ~(u32)HC_CONFIG_1_REG_BLOCK_DISABLE_1));
  7353. val = REG_RD(bp, HC_REG_CONFIG_0);
  7354. REG_WR(bp, HC_REG_CONFIG_0,
  7355. (!close) ? (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0) :
  7356. (val & ~(u32)HC_CONFIG_0_REG_BLOCK_DISABLE_0));
  7357. } else {
  7358. /* Prevent incomming interrupts in IGU */
  7359. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  7360. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION,
  7361. (!close) ?
  7362. (val | IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE) :
  7363. (val & ~(u32)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE));
  7364. }
  7365. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "%s gates #2, #3 and #4\n",
  7366. close ? "closing" : "opening");
  7367. mmiowb();
  7368. }
  7369. #define SHARED_MF_CLP_MAGIC 0x80000000 /* `magic' bit */
  7370. static void bnx2x_clp_reset_prep(struct bnx2x *bp, u32 *magic_val)
  7371. {
  7372. /* Do some magic... */
  7373. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  7374. *magic_val = val & SHARED_MF_CLP_MAGIC;
  7375. MF_CFG_WR(bp, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC);
  7376. }
  7377. /**
  7378. * bnx2x_clp_reset_done - restore the value of the `magic' bit.
  7379. *
  7380. * @bp: driver handle
  7381. * @magic_val: old value of the `magic' bit.
  7382. */
  7383. static void bnx2x_clp_reset_done(struct bnx2x *bp, u32 magic_val)
  7384. {
  7385. /* Restore the `magic' bit value... */
  7386. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  7387. MF_CFG_WR(bp, shared_mf_config.clp_mb,
  7388. (val & (~SHARED_MF_CLP_MAGIC)) | magic_val);
  7389. }
  7390. /**
  7391. * bnx2x_reset_mcp_prep - prepare for MCP reset.
  7392. *
  7393. * @bp: driver handle
  7394. * @magic_val: old value of 'magic' bit.
  7395. *
  7396. * Takes care of CLP configurations.
  7397. */
  7398. static void bnx2x_reset_mcp_prep(struct bnx2x *bp, u32 *magic_val)
  7399. {
  7400. u32 shmem;
  7401. u32 validity_offset;
  7402. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "Starting\n");
  7403. /* Set `magic' bit in order to save MF config */
  7404. if (!CHIP_IS_E1(bp))
  7405. bnx2x_clp_reset_prep(bp, magic_val);
  7406. /* Get shmem offset */
  7407. shmem = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  7408. validity_offset =
  7409. offsetof(struct shmem_region, validity_map[BP_PORT(bp)]);
  7410. /* Clear validity map flags */
  7411. if (shmem > 0)
  7412. REG_WR(bp, shmem + validity_offset, 0);
  7413. }
  7414. #define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */
  7415. #define MCP_ONE_TIMEOUT 100 /* 100 ms */
  7416. /**
  7417. * bnx2x_mcp_wait_one - wait for MCP_ONE_TIMEOUT
  7418. *
  7419. * @bp: driver handle
  7420. */
  7421. static void bnx2x_mcp_wait_one(struct bnx2x *bp)
  7422. {
  7423. /* special handling for emulation and FPGA,
  7424. wait 10 times longer */
  7425. if (CHIP_REV_IS_SLOW(bp))
  7426. msleep(MCP_ONE_TIMEOUT*10);
  7427. else
  7428. msleep(MCP_ONE_TIMEOUT);
  7429. }
  7430. /*
  7431. * initializes bp->common.shmem_base and waits for validity signature to appear
  7432. */
  7433. static int bnx2x_init_shmem(struct bnx2x *bp)
  7434. {
  7435. int cnt = 0;
  7436. u32 val = 0;
  7437. do {
  7438. bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  7439. if (bp->common.shmem_base) {
  7440. val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
  7441. if (val & SHR_MEM_VALIDITY_MB)
  7442. return 0;
  7443. }
  7444. bnx2x_mcp_wait_one(bp);
  7445. } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT));
  7446. BNX2X_ERR("BAD MCP validity signature\n");
  7447. return -ENODEV;
  7448. }
  7449. static int bnx2x_reset_mcp_comp(struct bnx2x *bp, u32 magic_val)
  7450. {
  7451. int rc = bnx2x_init_shmem(bp);
  7452. /* Restore the `magic' bit value */
  7453. if (!CHIP_IS_E1(bp))
  7454. bnx2x_clp_reset_done(bp, magic_val);
  7455. return rc;
  7456. }
  7457. static void bnx2x_pxp_prep(struct bnx2x *bp)
  7458. {
  7459. if (!CHIP_IS_E1(bp)) {
  7460. REG_WR(bp, PXP2_REG_RD_START_INIT, 0);
  7461. REG_WR(bp, PXP2_REG_RQ_RBC_DONE, 0);
  7462. mmiowb();
  7463. }
  7464. }
  7465. /*
  7466. * Reset the whole chip except for:
  7467. * - PCIE core
  7468. * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by
  7469. * one reset bit)
  7470. * - IGU
  7471. * - MISC (including AEU)
  7472. * - GRC
  7473. * - RBCN, RBCP
  7474. */
  7475. static void bnx2x_process_kill_chip_reset(struct bnx2x *bp, bool global)
  7476. {
  7477. u32 not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2;
  7478. u32 global_bits2, stay_reset2;
  7479. /*
  7480. * Bits that have to be set in reset_mask2 if we want to reset 'global'
  7481. * (per chip) blocks.
  7482. */
  7483. global_bits2 =
  7484. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU |
  7485. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE;
  7486. /* Don't reset the following blocks.
  7487. * Important: per port blocks (such as EMAC, BMAC, UMAC) can't be
  7488. * reset, as in 4 port device they might still be owned
  7489. * by the MCP (there is only one leader per path).
  7490. */
  7491. not_reset_mask1 =
  7492. MISC_REGISTERS_RESET_REG_1_RST_HC |
  7493. MISC_REGISTERS_RESET_REG_1_RST_PXPV |
  7494. MISC_REGISTERS_RESET_REG_1_RST_PXP;
  7495. not_reset_mask2 =
  7496. MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO |
  7497. MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE |
  7498. MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE |
  7499. MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE |
  7500. MISC_REGISTERS_RESET_REG_2_RST_RBCN |
  7501. MISC_REGISTERS_RESET_REG_2_RST_GRC |
  7502. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE |
  7503. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B |
  7504. MISC_REGISTERS_RESET_REG_2_RST_ATC |
  7505. MISC_REGISTERS_RESET_REG_2_PGLC |
  7506. MISC_REGISTERS_RESET_REG_2_RST_BMAC0 |
  7507. MISC_REGISTERS_RESET_REG_2_RST_BMAC1 |
  7508. MISC_REGISTERS_RESET_REG_2_RST_EMAC0 |
  7509. MISC_REGISTERS_RESET_REG_2_RST_EMAC1 |
  7510. MISC_REGISTERS_RESET_REG_2_UMAC0 |
  7511. MISC_REGISTERS_RESET_REG_2_UMAC1;
  7512. /*
  7513. * Keep the following blocks in reset:
  7514. * - all xxMACs are handled by the bnx2x_link code.
  7515. */
  7516. stay_reset2 =
  7517. MISC_REGISTERS_RESET_REG_2_XMAC |
  7518. MISC_REGISTERS_RESET_REG_2_XMAC_SOFT;
  7519. /* Full reset masks according to the chip */
  7520. reset_mask1 = 0xffffffff;
  7521. if (CHIP_IS_E1(bp))
  7522. reset_mask2 = 0xffff;
  7523. else if (CHIP_IS_E1H(bp))
  7524. reset_mask2 = 0x1ffff;
  7525. else if (CHIP_IS_E2(bp))
  7526. reset_mask2 = 0xfffff;
  7527. else /* CHIP_IS_E3 */
  7528. reset_mask2 = 0x3ffffff;
  7529. /* Don't reset global blocks unless we need to */
  7530. if (!global)
  7531. reset_mask2 &= ~global_bits2;
  7532. /*
  7533. * In case of attention in the QM, we need to reset PXP
  7534. * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM
  7535. * because otherwise QM reset would release 'close the gates' shortly
  7536. * before resetting the PXP, then the PSWRQ would send a write
  7537. * request to PGLUE. Then when PXP is reset, PGLUE would try to
  7538. * read the payload data from PSWWR, but PSWWR would not
  7539. * respond. The write queue in PGLUE would stuck, dmae commands
  7540. * would not return. Therefore it's important to reset the second
  7541. * reset register (containing the
  7542. * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the
  7543. * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM
  7544. * bit).
  7545. */
  7546. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
  7547. reset_mask2 & (~not_reset_mask2));
  7548. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  7549. reset_mask1 & (~not_reset_mask1));
  7550. barrier();
  7551. mmiowb();
  7552. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
  7553. reset_mask2 & (~stay_reset2));
  7554. barrier();
  7555. mmiowb();
  7556. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1);
  7557. mmiowb();
  7558. }
  7559. /**
  7560. * bnx2x_er_poll_igu_vq - poll for pending writes bit.
  7561. * It should get cleared in no more than 1s.
  7562. *
  7563. * @bp: driver handle
  7564. *
  7565. * It should get cleared in no more than 1s. Returns 0 if
  7566. * pending writes bit gets cleared.
  7567. */
  7568. static int bnx2x_er_poll_igu_vq(struct bnx2x *bp)
  7569. {
  7570. u32 cnt = 1000;
  7571. u32 pend_bits = 0;
  7572. do {
  7573. pend_bits = REG_RD(bp, IGU_REG_PENDING_BITS_STATUS);
  7574. if (pend_bits == 0)
  7575. break;
  7576. usleep_range(1000, 2000);
  7577. } while (cnt-- > 0);
  7578. if (cnt <= 0) {
  7579. BNX2X_ERR("Still pending IGU requests pend_bits=%x!\n",
  7580. pend_bits);
  7581. return -EBUSY;
  7582. }
  7583. return 0;
  7584. }
  7585. static int bnx2x_process_kill(struct bnx2x *bp, bool global)
  7586. {
  7587. int cnt = 1000;
  7588. u32 val = 0;
  7589. u32 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2;
  7590. u32 tags_63_32 = 0;
  7591. /* Empty the Tetris buffer, wait for 1s */
  7592. do {
  7593. sr_cnt = REG_RD(bp, PXP2_REG_RD_SR_CNT);
  7594. blk_cnt = REG_RD(bp, PXP2_REG_RD_BLK_CNT);
  7595. port_is_idle_0 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_0);
  7596. port_is_idle_1 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_1);
  7597. pgl_exp_rom2 = REG_RD(bp, PXP2_REG_PGL_EXP_ROM2);
  7598. if (CHIP_IS_E3(bp))
  7599. tags_63_32 = REG_RD(bp, PGLUE_B_REG_TAGS_63_32);
  7600. if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) &&
  7601. ((port_is_idle_0 & 0x1) == 0x1) &&
  7602. ((port_is_idle_1 & 0x1) == 0x1) &&
  7603. (pgl_exp_rom2 == 0xffffffff) &&
  7604. (!CHIP_IS_E3(bp) || (tags_63_32 == 0xffffffff)))
  7605. break;
  7606. usleep_range(1000, 2000);
  7607. } while (cnt-- > 0);
  7608. if (cnt <= 0) {
  7609. BNX2X_ERR("Tetris buffer didn't get empty or there are still outstanding read requests after 1s!\n");
  7610. 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",
  7611. sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1,
  7612. pgl_exp_rom2);
  7613. return -EAGAIN;
  7614. }
  7615. barrier();
  7616. /* Close gates #2, #3 and #4 */
  7617. bnx2x_set_234_gates(bp, true);
  7618. /* Poll for IGU VQs for 57712 and newer chips */
  7619. if (!CHIP_IS_E1x(bp) && bnx2x_er_poll_igu_vq(bp))
  7620. return -EAGAIN;
  7621. /* TBD: Indicate that "process kill" is in progress to MCP */
  7622. /* Clear "unprepared" bit */
  7623. REG_WR(bp, MISC_REG_UNPREPARED, 0);
  7624. barrier();
  7625. /* Make sure all is written to the chip before the reset */
  7626. mmiowb();
  7627. /* Wait for 1ms to empty GLUE and PCI-E core queues,
  7628. * PSWHST, GRC and PSWRD Tetris buffer.
  7629. */
  7630. usleep_range(1000, 2000);
  7631. /* Prepare to chip reset: */
  7632. /* MCP */
  7633. if (global)
  7634. bnx2x_reset_mcp_prep(bp, &val);
  7635. /* PXP */
  7636. bnx2x_pxp_prep(bp);
  7637. barrier();
  7638. /* reset the chip */
  7639. bnx2x_process_kill_chip_reset(bp, global);
  7640. barrier();
  7641. /* Recover after reset: */
  7642. /* MCP */
  7643. if (global && bnx2x_reset_mcp_comp(bp, val))
  7644. return -EAGAIN;
  7645. /* TBD: Add resetting the NO_MCP mode DB here */
  7646. /* Open the gates #2, #3 and #4 */
  7647. bnx2x_set_234_gates(bp, false);
  7648. /* TBD: IGU/AEU preparation bring back the AEU/IGU to a
  7649. * reset state, re-enable attentions. */
  7650. return 0;
  7651. }
  7652. static int bnx2x_leader_reset(struct bnx2x *bp)
  7653. {
  7654. int rc = 0;
  7655. bool global = bnx2x_reset_is_global(bp);
  7656. u32 load_code;
  7657. /* if not going to reset MCP - load "fake" driver to reset HW while
  7658. * driver is owner of the HW
  7659. */
  7660. if (!global && !BP_NOMCP(bp)) {
  7661. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_REQ,
  7662. DRV_MSG_CODE_LOAD_REQ_WITH_LFA);
  7663. if (!load_code) {
  7664. BNX2X_ERR("MCP response failure, aborting\n");
  7665. rc = -EAGAIN;
  7666. goto exit_leader_reset;
  7667. }
  7668. if ((load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) &&
  7669. (load_code != FW_MSG_CODE_DRV_LOAD_COMMON)) {
  7670. BNX2X_ERR("MCP unexpected resp, aborting\n");
  7671. rc = -EAGAIN;
  7672. goto exit_leader_reset2;
  7673. }
  7674. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE, 0);
  7675. if (!load_code) {
  7676. BNX2X_ERR("MCP response failure, aborting\n");
  7677. rc = -EAGAIN;
  7678. goto exit_leader_reset2;
  7679. }
  7680. }
  7681. /* Try to recover after the failure */
  7682. if (bnx2x_process_kill(bp, global)) {
  7683. BNX2X_ERR("Something bad had happen on engine %d! Aii!\n",
  7684. BP_PATH(bp));
  7685. rc = -EAGAIN;
  7686. goto exit_leader_reset2;
  7687. }
  7688. /*
  7689. * Clear RESET_IN_PROGRES and RESET_GLOBAL bits and update the driver
  7690. * state.
  7691. */
  7692. bnx2x_set_reset_done(bp);
  7693. if (global)
  7694. bnx2x_clear_reset_global(bp);
  7695. exit_leader_reset2:
  7696. /* unload "fake driver" if it was loaded */
  7697. if (!global && !BP_NOMCP(bp)) {
  7698. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0);
  7699. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
  7700. }
  7701. exit_leader_reset:
  7702. bp->is_leader = 0;
  7703. bnx2x_release_leader_lock(bp);
  7704. smp_mb();
  7705. return rc;
  7706. }
  7707. static void bnx2x_recovery_failed(struct bnx2x *bp)
  7708. {
  7709. netdev_err(bp->dev, "Recovery has failed. Power cycle is needed.\n");
  7710. /* Disconnect this device */
  7711. netif_device_detach(bp->dev);
  7712. /*
  7713. * Block ifup for all function on this engine until "process kill"
  7714. * or power cycle.
  7715. */
  7716. bnx2x_set_reset_in_progress(bp);
  7717. /* Shut down the power */
  7718. bnx2x_set_power_state(bp, PCI_D3hot);
  7719. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  7720. smp_mb();
  7721. }
  7722. /*
  7723. * Assumption: runs under rtnl lock. This together with the fact
  7724. * that it's called only from bnx2x_sp_rtnl() ensure that it
  7725. * will never be called when netif_running(bp->dev) is false.
  7726. */
  7727. static void bnx2x_parity_recover(struct bnx2x *bp)
  7728. {
  7729. bool global = false;
  7730. u32 error_recovered, error_unrecovered;
  7731. bool is_parity;
  7732. DP(NETIF_MSG_HW, "Handling parity\n");
  7733. while (1) {
  7734. switch (bp->recovery_state) {
  7735. case BNX2X_RECOVERY_INIT:
  7736. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_INIT\n");
  7737. is_parity = bnx2x_chk_parity_attn(bp, &global, false);
  7738. WARN_ON(!is_parity);
  7739. /* Try to get a LEADER_LOCK HW lock */
  7740. if (bnx2x_trylock_leader_lock(bp)) {
  7741. bnx2x_set_reset_in_progress(bp);
  7742. /*
  7743. * Check if there is a global attention and if
  7744. * there was a global attention, set the global
  7745. * reset bit.
  7746. */
  7747. if (global)
  7748. bnx2x_set_reset_global(bp);
  7749. bp->is_leader = 1;
  7750. }
  7751. /* Stop the driver */
  7752. /* If interface has been removed - break */
  7753. if (bnx2x_nic_unload(bp, UNLOAD_RECOVERY, false))
  7754. return;
  7755. bp->recovery_state = BNX2X_RECOVERY_WAIT;
  7756. /* Ensure "is_leader", MCP command sequence and
  7757. * "recovery_state" update values are seen on other
  7758. * CPUs.
  7759. */
  7760. smp_mb();
  7761. break;
  7762. case BNX2X_RECOVERY_WAIT:
  7763. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_WAIT\n");
  7764. if (bp->is_leader) {
  7765. int other_engine = BP_PATH(bp) ? 0 : 1;
  7766. bool other_load_status =
  7767. bnx2x_get_load_status(bp, other_engine);
  7768. bool load_status =
  7769. bnx2x_get_load_status(bp, BP_PATH(bp));
  7770. global = bnx2x_reset_is_global(bp);
  7771. /*
  7772. * In case of a parity in a global block, let
  7773. * the first leader that performs a
  7774. * leader_reset() reset the global blocks in
  7775. * order to clear global attentions. Otherwise
  7776. * the the gates will remain closed for that
  7777. * engine.
  7778. */
  7779. if (load_status ||
  7780. (global && other_load_status)) {
  7781. /* Wait until all other functions get
  7782. * down.
  7783. */
  7784. schedule_delayed_work(&bp->sp_rtnl_task,
  7785. HZ/10);
  7786. return;
  7787. } else {
  7788. /* If all other functions got down -
  7789. * try to bring the chip back to
  7790. * normal. In any case it's an exit
  7791. * point for a leader.
  7792. */
  7793. if (bnx2x_leader_reset(bp)) {
  7794. bnx2x_recovery_failed(bp);
  7795. return;
  7796. }
  7797. /* If we are here, means that the
  7798. * leader has succeeded and doesn't
  7799. * want to be a leader any more. Try
  7800. * to continue as a none-leader.
  7801. */
  7802. break;
  7803. }
  7804. } else { /* non-leader */
  7805. if (!bnx2x_reset_is_done(bp, BP_PATH(bp))) {
  7806. /* Try to get a LEADER_LOCK HW lock as
  7807. * long as a former leader may have
  7808. * been unloaded by the user or
  7809. * released a leadership by another
  7810. * reason.
  7811. */
  7812. if (bnx2x_trylock_leader_lock(bp)) {
  7813. /* I'm a leader now! Restart a
  7814. * switch case.
  7815. */
  7816. bp->is_leader = 1;
  7817. break;
  7818. }
  7819. schedule_delayed_work(&bp->sp_rtnl_task,
  7820. HZ/10);
  7821. return;
  7822. } else {
  7823. /*
  7824. * If there was a global attention, wait
  7825. * for it to be cleared.
  7826. */
  7827. if (bnx2x_reset_is_global(bp)) {
  7828. schedule_delayed_work(
  7829. &bp->sp_rtnl_task,
  7830. HZ/10);
  7831. return;
  7832. }
  7833. error_recovered =
  7834. bp->eth_stats.recoverable_error;
  7835. error_unrecovered =
  7836. bp->eth_stats.unrecoverable_error;
  7837. bp->recovery_state =
  7838. BNX2X_RECOVERY_NIC_LOADING;
  7839. if (bnx2x_nic_load(bp, LOAD_NORMAL)) {
  7840. error_unrecovered++;
  7841. netdev_err(bp->dev,
  7842. "Recovery failed. Power cycle needed\n");
  7843. /* Disconnect this device */
  7844. netif_device_detach(bp->dev);
  7845. /* Shut down the power */
  7846. bnx2x_set_power_state(
  7847. bp, PCI_D3hot);
  7848. smp_mb();
  7849. } else {
  7850. bp->recovery_state =
  7851. BNX2X_RECOVERY_DONE;
  7852. error_recovered++;
  7853. smp_mb();
  7854. }
  7855. bp->eth_stats.recoverable_error =
  7856. error_recovered;
  7857. bp->eth_stats.unrecoverable_error =
  7858. error_unrecovered;
  7859. return;
  7860. }
  7861. }
  7862. default:
  7863. return;
  7864. }
  7865. }
  7866. }
  7867. static int bnx2x_close(struct net_device *dev);
  7868. /* bnx2x_nic_unload() flushes the bnx2x_wq, thus reset task is
  7869. * scheduled on a general queue in order to prevent a dead lock.
  7870. */
  7871. static void bnx2x_sp_rtnl_task(struct work_struct *work)
  7872. {
  7873. struct bnx2x *bp = container_of(work, struct bnx2x, sp_rtnl_task.work);
  7874. rtnl_lock();
  7875. if (!netif_running(bp->dev)) {
  7876. rtnl_unlock();
  7877. return;
  7878. }
  7879. /* if stop on error is defined no recovery flows should be executed */
  7880. #ifdef BNX2X_STOP_ON_ERROR
  7881. BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
  7882. "you will need to reboot when done\n");
  7883. goto sp_rtnl_not_reset;
  7884. #endif
  7885. if (unlikely(bp->recovery_state != BNX2X_RECOVERY_DONE)) {
  7886. /*
  7887. * Clear all pending SP commands as we are going to reset the
  7888. * function anyway.
  7889. */
  7890. bp->sp_rtnl_state = 0;
  7891. smp_mb();
  7892. bnx2x_parity_recover(bp);
  7893. rtnl_unlock();
  7894. return;
  7895. }
  7896. if (test_and_clear_bit(BNX2X_SP_RTNL_TX_TIMEOUT, &bp->sp_rtnl_state)) {
  7897. /*
  7898. * Clear all pending SP commands as we are going to reset the
  7899. * function anyway.
  7900. */
  7901. bp->sp_rtnl_state = 0;
  7902. smp_mb();
  7903. bnx2x_nic_unload(bp, UNLOAD_NORMAL, true);
  7904. bnx2x_nic_load(bp, LOAD_NORMAL);
  7905. rtnl_unlock();
  7906. return;
  7907. }
  7908. #ifdef BNX2X_STOP_ON_ERROR
  7909. sp_rtnl_not_reset:
  7910. #endif
  7911. if (test_and_clear_bit(BNX2X_SP_RTNL_SETUP_TC, &bp->sp_rtnl_state))
  7912. bnx2x_setup_tc(bp->dev, bp->dcbx_port_params.ets.num_of_cos);
  7913. if (test_and_clear_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE, &bp->sp_rtnl_state))
  7914. bnx2x_after_function_update(bp);
  7915. /*
  7916. * in case of fan failure we need to reset id if the "stop on error"
  7917. * debug flag is set, since we trying to prevent permanent overheating
  7918. * damage
  7919. */
  7920. if (test_and_clear_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state)) {
  7921. DP(NETIF_MSG_HW, "fan failure detected. Unloading driver\n");
  7922. netif_device_detach(bp->dev);
  7923. bnx2x_close(bp->dev);
  7924. rtnl_unlock();
  7925. return;
  7926. }
  7927. if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_MCAST, &bp->sp_rtnl_state)) {
  7928. DP(BNX2X_MSG_SP,
  7929. "sending set mcast vf pf channel message from rtnl sp-task\n");
  7930. bnx2x_vfpf_set_mcast(bp->dev);
  7931. }
  7932. if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_STORM_RX_MODE,
  7933. &bp->sp_rtnl_state)) {
  7934. DP(BNX2X_MSG_SP,
  7935. "sending set storm rx mode vf pf channel message from rtnl sp-task\n");
  7936. bnx2x_vfpf_storm_rx_mode(bp);
  7937. }
  7938. /* work which needs rtnl lock not-taken (as it takes the lock itself and
  7939. * can be called from other contexts as well)
  7940. */
  7941. rtnl_unlock();
  7942. /* enable SR-IOV if applicable */
  7943. if (IS_SRIOV(bp) && test_and_clear_bit(BNX2X_SP_RTNL_ENABLE_SRIOV,
  7944. &bp->sp_rtnl_state))
  7945. bnx2x_enable_sriov(bp);
  7946. }
  7947. static void bnx2x_period_task(struct work_struct *work)
  7948. {
  7949. struct bnx2x *bp = container_of(work, struct bnx2x, period_task.work);
  7950. if (!netif_running(bp->dev))
  7951. goto period_task_exit;
  7952. if (CHIP_REV_IS_SLOW(bp)) {
  7953. BNX2X_ERR("period task called on emulation, ignoring\n");
  7954. goto period_task_exit;
  7955. }
  7956. bnx2x_acquire_phy_lock(bp);
  7957. /*
  7958. * The barrier is needed to ensure the ordering between the writing to
  7959. * the bp->port.pmf in the bnx2x_nic_load() or bnx2x_pmf_update() and
  7960. * the reading here.
  7961. */
  7962. smp_mb();
  7963. if (bp->port.pmf) {
  7964. bnx2x_period_func(&bp->link_params, &bp->link_vars);
  7965. /* Re-queue task in 1 sec */
  7966. queue_delayed_work(bnx2x_wq, &bp->period_task, 1*HZ);
  7967. }
  7968. bnx2x_release_phy_lock(bp);
  7969. period_task_exit:
  7970. return;
  7971. }
  7972. /*
  7973. * Init service functions
  7974. */
  7975. u32 bnx2x_get_pretend_reg(struct bnx2x *bp)
  7976. {
  7977. u32 base = PXP2_REG_PGL_PRETEND_FUNC_F0;
  7978. u32 stride = PXP2_REG_PGL_PRETEND_FUNC_F1 - base;
  7979. return base + (BP_ABS_FUNC(bp)) * stride;
  7980. }
  7981. static void bnx2x_prev_unload_close_mac(struct bnx2x *bp,
  7982. struct bnx2x_mac_vals *vals)
  7983. {
  7984. u32 val, base_addr, offset, mask, reset_reg;
  7985. bool mac_stopped = false;
  7986. u8 port = BP_PORT(bp);
  7987. /* reset addresses as they also mark which values were changed */
  7988. vals->bmac_addr = 0;
  7989. vals->umac_addr = 0;
  7990. vals->xmac_addr = 0;
  7991. vals->emac_addr = 0;
  7992. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_2);
  7993. if (!CHIP_IS_E3(bp)) {
  7994. val = REG_RD(bp, NIG_REG_BMAC0_REGS_OUT_EN + port * 4);
  7995. mask = MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port;
  7996. if ((mask & reset_reg) && val) {
  7997. u32 wb_data[2];
  7998. BNX2X_DEV_INFO("Disable bmac Rx\n");
  7999. base_addr = BP_PORT(bp) ? NIG_REG_INGRESS_BMAC1_MEM
  8000. : NIG_REG_INGRESS_BMAC0_MEM;
  8001. offset = CHIP_IS_E2(bp) ? BIGMAC2_REGISTER_BMAC_CONTROL
  8002. : BIGMAC_REGISTER_BMAC_CONTROL;
  8003. /*
  8004. * use rd/wr since we cannot use dmae. This is safe
  8005. * since MCP won't access the bus due to the request
  8006. * to unload, and no function on the path can be
  8007. * loaded at this time.
  8008. */
  8009. wb_data[0] = REG_RD(bp, base_addr + offset);
  8010. wb_data[1] = REG_RD(bp, base_addr + offset + 0x4);
  8011. vals->bmac_addr = base_addr + offset;
  8012. vals->bmac_val[0] = wb_data[0];
  8013. vals->bmac_val[1] = wb_data[1];
  8014. wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE;
  8015. REG_WR(bp, vals->bmac_addr, wb_data[0]);
  8016. REG_WR(bp, vals->bmac_addr + 0x4, wb_data[1]);
  8017. }
  8018. BNX2X_DEV_INFO("Disable emac Rx\n");
  8019. vals->emac_addr = NIG_REG_NIG_EMAC0_EN + BP_PORT(bp)*4;
  8020. vals->emac_val = REG_RD(bp, vals->emac_addr);
  8021. REG_WR(bp, vals->emac_addr, 0);
  8022. mac_stopped = true;
  8023. } else {
  8024. if (reset_reg & MISC_REGISTERS_RESET_REG_2_XMAC) {
  8025. BNX2X_DEV_INFO("Disable xmac Rx\n");
  8026. base_addr = BP_PORT(bp) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
  8027. val = REG_RD(bp, base_addr + XMAC_REG_PFC_CTRL_HI);
  8028. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  8029. val & ~(1 << 1));
  8030. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  8031. val | (1 << 1));
  8032. vals->xmac_addr = base_addr + XMAC_REG_CTRL;
  8033. vals->xmac_val = REG_RD(bp, vals->xmac_addr);
  8034. REG_WR(bp, vals->xmac_addr, 0);
  8035. mac_stopped = true;
  8036. }
  8037. mask = MISC_REGISTERS_RESET_REG_2_UMAC0 << port;
  8038. if (mask & reset_reg) {
  8039. BNX2X_DEV_INFO("Disable umac Rx\n");
  8040. base_addr = BP_PORT(bp) ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
  8041. vals->umac_addr = base_addr + UMAC_REG_COMMAND_CONFIG;
  8042. vals->umac_val = REG_RD(bp, vals->umac_addr);
  8043. REG_WR(bp, vals->umac_addr, 0);
  8044. mac_stopped = true;
  8045. }
  8046. }
  8047. if (mac_stopped)
  8048. msleep(20);
  8049. }
  8050. #define BNX2X_PREV_UNDI_PROD_ADDR(p) (BAR_TSTRORM_INTMEM + 0x1508 + ((p) << 4))
  8051. #define BNX2X_PREV_UNDI_RCQ(val) ((val) & 0xffff)
  8052. #define BNX2X_PREV_UNDI_BD(val) ((val) >> 16 & 0xffff)
  8053. #define BNX2X_PREV_UNDI_PROD(rcq, bd) ((bd) << 16 | (rcq))
  8054. static void bnx2x_prev_unload_undi_inc(struct bnx2x *bp, u8 port, u8 inc)
  8055. {
  8056. u16 rcq, bd;
  8057. u32 tmp_reg = REG_RD(bp, BNX2X_PREV_UNDI_PROD_ADDR(port));
  8058. rcq = BNX2X_PREV_UNDI_RCQ(tmp_reg) + inc;
  8059. bd = BNX2X_PREV_UNDI_BD(tmp_reg) + inc;
  8060. tmp_reg = BNX2X_PREV_UNDI_PROD(rcq, bd);
  8061. REG_WR(bp, BNX2X_PREV_UNDI_PROD_ADDR(port), tmp_reg);
  8062. BNX2X_DEV_INFO("UNDI producer [%d] rings bd -> 0x%04x, rcq -> 0x%04x\n",
  8063. port, bd, rcq);
  8064. }
  8065. static int bnx2x_prev_mcp_done(struct bnx2x *bp)
  8066. {
  8067. u32 rc = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE,
  8068. DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET);
  8069. if (!rc) {
  8070. BNX2X_ERR("MCP response failure, aborting\n");
  8071. return -EBUSY;
  8072. }
  8073. return 0;
  8074. }
  8075. static struct bnx2x_prev_path_list *
  8076. bnx2x_prev_path_get_entry(struct bnx2x *bp)
  8077. {
  8078. struct bnx2x_prev_path_list *tmp_list;
  8079. list_for_each_entry(tmp_list, &bnx2x_prev_list, list)
  8080. if (PCI_SLOT(bp->pdev->devfn) == tmp_list->slot &&
  8081. bp->pdev->bus->number == tmp_list->bus &&
  8082. BP_PATH(bp) == tmp_list->path)
  8083. return tmp_list;
  8084. return NULL;
  8085. }
  8086. static bool bnx2x_prev_is_path_marked(struct bnx2x *bp)
  8087. {
  8088. struct bnx2x_prev_path_list *tmp_list;
  8089. int rc = false;
  8090. if (down_trylock(&bnx2x_prev_sem))
  8091. return false;
  8092. list_for_each_entry(tmp_list, &bnx2x_prev_list, list) {
  8093. if (PCI_SLOT(bp->pdev->devfn) == tmp_list->slot &&
  8094. bp->pdev->bus->number == tmp_list->bus &&
  8095. BP_PATH(bp) == tmp_list->path) {
  8096. rc = true;
  8097. BNX2X_DEV_INFO("Path %d was already cleaned from previous drivers\n",
  8098. BP_PATH(bp));
  8099. break;
  8100. }
  8101. }
  8102. up(&bnx2x_prev_sem);
  8103. return rc;
  8104. }
  8105. static int bnx2x_prev_mark_path(struct bnx2x *bp, bool after_undi)
  8106. {
  8107. struct bnx2x_prev_path_list *tmp_list;
  8108. int rc;
  8109. tmp_list = kmalloc(sizeof(struct bnx2x_prev_path_list), GFP_KERNEL);
  8110. if (!tmp_list) {
  8111. BNX2X_ERR("Failed to allocate 'bnx2x_prev_path_list'\n");
  8112. return -ENOMEM;
  8113. }
  8114. tmp_list->bus = bp->pdev->bus->number;
  8115. tmp_list->slot = PCI_SLOT(bp->pdev->devfn);
  8116. tmp_list->path = BP_PATH(bp);
  8117. tmp_list->undi = after_undi ? (1 << BP_PORT(bp)) : 0;
  8118. rc = down_interruptible(&bnx2x_prev_sem);
  8119. if (rc) {
  8120. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  8121. kfree(tmp_list);
  8122. } else {
  8123. BNX2X_DEV_INFO("Marked path [%d] - finished previous unload\n",
  8124. BP_PATH(bp));
  8125. list_add(&tmp_list->list, &bnx2x_prev_list);
  8126. up(&bnx2x_prev_sem);
  8127. }
  8128. return rc;
  8129. }
  8130. static int bnx2x_do_flr(struct bnx2x *bp)
  8131. {
  8132. int i;
  8133. u16 status;
  8134. struct pci_dev *dev = bp->pdev;
  8135. if (CHIP_IS_E1x(bp)) {
  8136. BNX2X_DEV_INFO("FLR not supported in E1/E1H\n");
  8137. return -EINVAL;
  8138. }
  8139. /* only bootcode REQ_BC_VER_4_INITIATE_FLR and onwards support flr */
  8140. if (bp->common.bc_ver < REQ_BC_VER_4_INITIATE_FLR) {
  8141. BNX2X_ERR("FLR not supported by BC_VER: 0x%x\n",
  8142. bp->common.bc_ver);
  8143. return -EINVAL;
  8144. }
  8145. /* Wait for Transaction Pending bit clean */
  8146. for (i = 0; i < 4; i++) {
  8147. if (i)
  8148. msleep((1 << (i - 1)) * 100);
  8149. pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status);
  8150. if (!(status & PCI_EXP_DEVSTA_TRPND))
  8151. goto clear;
  8152. }
  8153. dev_err(&dev->dev,
  8154. "transaction is not cleared; proceeding with reset anyway\n");
  8155. clear:
  8156. BNX2X_DEV_INFO("Initiating FLR\n");
  8157. bnx2x_fw_command(bp, DRV_MSG_CODE_INITIATE_FLR, 0);
  8158. return 0;
  8159. }
  8160. static int bnx2x_prev_unload_uncommon(struct bnx2x *bp)
  8161. {
  8162. int rc;
  8163. BNX2X_DEV_INFO("Uncommon unload Flow\n");
  8164. /* Test if previous unload process was already finished for this path */
  8165. if (bnx2x_prev_is_path_marked(bp))
  8166. return bnx2x_prev_mcp_done(bp);
  8167. BNX2X_DEV_INFO("Path is unmarked\n");
  8168. /* If function has FLR capabilities, and existing FW version matches
  8169. * the one required, then FLR will be sufficient to clean any residue
  8170. * left by previous driver
  8171. */
  8172. rc = bnx2x_nic_load_analyze_req(bp, FW_MSG_CODE_DRV_LOAD_FUNCTION);
  8173. if (!rc) {
  8174. /* fw version is good */
  8175. BNX2X_DEV_INFO("FW version matches our own. Attempting FLR\n");
  8176. rc = bnx2x_do_flr(bp);
  8177. }
  8178. if (!rc) {
  8179. /* FLR was performed */
  8180. BNX2X_DEV_INFO("FLR successful\n");
  8181. return 0;
  8182. }
  8183. BNX2X_DEV_INFO("Could not FLR\n");
  8184. /* Close the MCP request, return failure*/
  8185. rc = bnx2x_prev_mcp_done(bp);
  8186. if (!rc)
  8187. rc = BNX2X_PREV_WAIT_NEEDED;
  8188. return rc;
  8189. }
  8190. static int bnx2x_prev_unload_common(struct bnx2x *bp)
  8191. {
  8192. u32 reset_reg, tmp_reg = 0, rc;
  8193. bool prev_undi = false;
  8194. struct bnx2x_mac_vals mac_vals;
  8195. /* It is possible a previous function received 'common' answer,
  8196. * but hasn't loaded yet, therefore creating a scenario of
  8197. * multiple functions receiving 'common' on the same path.
  8198. */
  8199. BNX2X_DEV_INFO("Common unload Flow\n");
  8200. memset(&mac_vals, 0, sizeof(mac_vals));
  8201. if (bnx2x_prev_is_path_marked(bp))
  8202. return bnx2x_prev_mcp_done(bp);
  8203. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
  8204. /* Reset should be performed after BRB is emptied */
  8205. if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_BRB1) {
  8206. u32 timer_count = 1000;
  8207. /* Close the MAC Rx to prevent BRB from filling up */
  8208. bnx2x_prev_unload_close_mac(bp, &mac_vals);
  8209. /* close LLH filters towards the BRB */
  8210. bnx2x_set_rx_filter(&bp->link_params, 0);
  8211. /* Check if the UNDI driver was previously loaded
  8212. * UNDI driver initializes CID offset for normal bell to 0x7
  8213. */
  8214. if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_DORQ) {
  8215. tmp_reg = REG_RD(bp, DORQ_REG_NORM_CID_OFST);
  8216. if (tmp_reg == 0x7) {
  8217. BNX2X_DEV_INFO("UNDI previously loaded\n");
  8218. prev_undi = true;
  8219. /* clear the UNDI indication */
  8220. REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0);
  8221. /* clear possible idle check errors */
  8222. REG_RD(bp, NIG_REG_NIG_INT_STS_CLR_0);
  8223. }
  8224. }
  8225. /* wait until BRB is empty */
  8226. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  8227. while (timer_count) {
  8228. u32 prev_brb = tmp_reg;
  8229. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  8230. if (!tmp_reg)
  8231. break;
  8232. BNX2X_DEV_INFO("BRB still has 0x%08x\n", tmp_reg);
  8233. /* reset timer as long as BRB actually gets emptied */
  8234. if (prev_brb > tmp_reg)
  8235. timer_count = 1000;
  8236. else
  8237. timer_count--;
  8238. /* If UNDI resides in memory, manually increment it */
  8239. if (prev_undi)
  8240. bnx2x_prev_unload_undi_inc(bp, BP_PORT(bp), 1);
  8241. udelay(10);
  8242. }
  8243. if (!timer_count)
  8244. BNX2X_ERR("Failed to empty BRB, hope for the best\n");
  8245. }
  8246. /* No packets are in the pipeline, path is ready for reset */
  8247. bnx2x_reset_common(bp);
  8248. if (mac_vals.xmac_addr)
  8249. REG_WR(bp, mac_vals.xmac_addr, mac_vals.xmac_val);
  8250. if (mac_vals.umac_addr)
  8251. REG_WR(bp, mac_vals.umac_addr, mac_vals.umac_val);
  8252. if (mac_vals.emac_addr)
  8253. REG_WR(bp, mac_vals.emac_addr, mac_vals.emac_val);
  8254. if (mac_vals.bmac_addr) {
  8255. REG_WR(bp, mac_vals.bmac_addr, mac_vals.bmac_val[0]);
  8256. REG_WR(bp, mac_vals.bmac_addr + 4, mac_vals.bmac_val[1]);
  8257. }
  8258. rc = bnx2x_prev_mark_path(bp, prev_undi);
  8259. if (rc) {
  8260. bnx2x_prev_mcp_done(bp);
  8261. return rc;
  8262. }
  8263. return bnx2x_prev_mcp_done(bp);
  8264. }
  8265. /* previous driver DMAE transaction may have occurred when pre-boot stage ended
  8266. * and boot began, or when kdump kernel was loaded. Either case would invalidate
  8267. * the addresses of the transaction, resulting in was-error bit set in the pci
  8268. * causing all hw-to-host pcie transactions to timeout. If this happened we want
  8269. * to clear the interrupt which detected this from the pglueb and the was done
  8270. * bit
  8271. */
  8272. static void bnx2x_prev_interrupted_dmae(struct bnx2x *bp)
  8273. {
  8274. if (!CHIP_IS_E1x(bp)) {
  8275. u32 val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS);
  8276. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN) {
  8277. DP(BNX2X_MSG_SP,
  8278. "'was error' bit was found to be set in pglueb upon startup. Clearing\n");
  8279. REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR,
  8280. 1 << BP_FUNC(bp));
  8281. }
  8282. }
  8283. }
  8284. static int bnx2x_prev_unload(struct bnx2x *bp)
  8285. {
  8286. int time_counter = 10;
  8287. u32 rc, fw, hw_lock_reg, hw_lock_val;
  8288. struct bnx2x_prev_path_list *prev_list;
  8289. BNX2X_DEV_INFO("Entering Previous Unload Flow\n");
  8290. /* clear hw from errors which may have resulted from an interrupted
  8291. * dmae transaction.
  8292. */
  8293. bnx2x_prev_interrupted_dmae(bp);
  8294. /* Release previously held locks */
  8295. hw_lock_reg = (BP_FUNC(bp) <= 5) ?
  8296. (MISC_REG_DRIVER_CONTROL_1 + BP_FUNC(bp) * 8) :
  8297. (MISC_REG_DRIVER_CONTROL_7 + (BP_FUNC(bp) - 6) * 8);
  8298. hw_lock_val = (REG_RD(bp, hw_lock_reg));
  8299. if (hw_lock_val) {
  8300. if (hw_lock_val & HW_LOCK_RESOURCE_NVRAM) {
  8301. BNX2X_DEV_INFO("Release Previously held NVRAM lock\n");
  8302. REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
  8303. (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << BP_PORT(bp)));
  8304. }
  8305. BNX2X_DEV_INFO("Release Previously held hw lock\n");
  8306. REG_WR(bp, hw_lock_reg, 0xffffffff);
  8307. } else
  8308. BNX2X_DEV_INFO("No need to release hw/nvram locks\n");
  8309. if (MCPR_ACCESS_LOCK_LOCK & REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK)) {
  8310. BNX2X_DEV_INFO("Release previously held alr\n");
  8311. REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, 0);
  8312. }
  8313. do {
  8314. /* Lock MCP using an unload request */
  8315. fw = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS, 0);
  8316. if (!fw) {
  8317. BNX2X_ERR("MCP response failure, aborting\n");
  8318. rc = -EBUSY;
  8319. break;
  8320. }
  8321. if (fw == FW_MSG_CODE_DRV_UNLOAD_COMMON) {
  8322. rc = bnx2x_prev_unload_common(bp);
  8323. break;
  8324. }
  8325. /* non-common reply from MCP night require looping */
  8326. rc = bnx2x_prev_unload_uncommon(bp);
  8327. if (rc != BNX2X_PREV_WAIT_NEEDED)
  8328. break;
  8329. msleep(20);
  8330. } while (--time_counter);
  8331. if (!time_counter || rc) {
  8332. BNX2X_ERR("Failed unloading previous driver, aborting\n");
  8333. rc = -EBUSY;
  8334. }
  8335. /* Mark function if its port was used to boot from SAN */
  8336. prev_list = bnx2x_prev_path_get_entry(bp);
  8337. if (prev_list && (prev_list->undi & (1 << BP_PORT(bp))))
  8338. bp->link_params.feature_config_flags |=
  8339. FEATURE_CONFIG_BOOT_FROM_SAN;
  8340. BNX2X_DEV_INFO("Finished Previous Unload Flow [%d]\n", rc);
  8341. return rc;
  8342. }
  8343. static void bnx2x_get_common_hwinfo(struct bnx2x *bp)
  8344. {
  8345. u32 val, val2, val3, val4, id, boot_mode;
  8346. u16 pmc;
  8347. /* Get the chip revision id and number. */
  8348. /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
  8349. val = REG_RD(bp, MISC_REG_CHIP_NUM);
  8350. id = ((val & 0xffff) << 16);
  8351. val = REG_RD(bp, MISC_REG_CHIP_REV);
  8352. id |= ((val & 0xf) << 12);
  8353. val = REG_RD(bp, MISC_REG_CHIP_METAL);
  8354. id |= ((val & 0xff) << 4);
  8355. val = REG_RD(bp, MISC_REG_BOND_ID);
  8356. id |= (val & 0xf);
  8357. bp->common.chip_id = id;
  8358. /* force 57811 according to MISC register */
  8359. if (REG_RD(bp, MISC_REG_CHIP_TYPE) & MISC_REG_CHIP_TYPE_57811_MASK) {
  8360. if (CHIP_IS_57810(bp))
  8361. bp->common.chip_id = (CHIP_NUM_57811 << 16) |
  8362. (bp->common.chip_id & 0x0000FFFF);
  8363. else if (CHIP_IS_57810_MF(bp))
  8364. bp->common.chip_id = (CHIP_NUM_57811_MF << 16) |
  8365. (bp->common.chip_id & 0x0000FFFF);
  8366. bp->common.chip_id |= 0x1;
  8367. }
  8368. /* Set doorbell size */
  8369. bp->db_size = (1 << BNX2X_DB_SHIFT);
  8370. if (!CHIP_IS_E1x(bp)) {
  8371. val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR);
  8372. if ((val & 1) == 0)
  8373. val = REG_RD(bp, MISC_REG_PORT4MODE_EN);
  8374. else
  8375. val = (val >> 1) & 1;
  8376. BNX2X_DEV_INFO("chip is in %s\n", val ? "4_PORT_MODE" :
  8377. "2_PORT_MODE");
  8378. bp->common.chip_port_mode = val ? CHIP_4_PORT_MODE :
  8379. CHIP_2_PORT_MODE;
  8380. if (CHIP_MODE_IS_4_PORT(bp))
  8381. bp->pfid = (bp->pf_num >> 1); /* 0..3 */
  8382. else
  8383. bp->pfid = (bp->pf_num & 0x6); /* 0, 2, 4, 6 */
  8384. } else {
  8385. bp->common.chip_port_mode = CHIP_PORT_MODE_NONE; /* N/A */
  8386. bp->pfid = bp->pf_num; /* 0..7 */
  8387. }
  8388. BNX2X_DEV_INFO("pf_id: %x", bp->pfid);
  8389. bp->link_params.chip_id = bp->common.chip_id;
  8390. BNX2X_DEV_INFO("chip ID is 0x%x\n", id);
  8391. val = (REG_RD(bp, 0x2874) & 0x55);
  8392. if ((bp->common.chip_id & 0x1) ||
  8393. (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) {
  8394. bp->flags |= ONE_PORT_FLAG;
  8395. BNX2X_DEV_INFO("single port device\n");
  8396. }
  8397. val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4);
  8398. bp->common.flash_size = (BNX2X_NVRAM_1MB_SIZE <<
  8399. (val & MCPR_NVM_CFG4_FLASH_SIZE));
  8400. BNX2X_DEV_INFO("flash_size 0x%x (%d)\n",
  8401. bp->common.flash_size, bp->common.flash_size);
  8402. bnx2x_init_shmem(bp);
  8403. bp->common.shmem2_base = REG_RD(bp, (BP_PATH(bp) ?
  8404. MISC_REG_GENERIC_CR_1 :
  8405. MISC_REG_GENERIC_CR_0));
  8406. bp->link_params.shmem_base = bp->common.shmem_base;
  8407. bp->link_params.shmem2_base = bp->common.shmem2_base;
  8408. if (SHMEM2_RD(bp, size) >
  8409. (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
  8410. bp->link_params.lfa_base =
  8411. REG_RD(bp, bp->common.shmem2_base +
  8412. (u32)offsetof(struct shmem2_region,
  8413. lfa_host_addr[BP_PORT(bp)]));
  8414. else
  8415. bp->link_params.lfa_base = 0;
  8416. BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n",
  8417. bp->common.shmem_base, bp->common.shmem2_base);
  8418. if (!bp->common.shmem_base) {
  8419. BNX2X_DEV_INFO("MCP not active\n");
  8420. bp->flags |= NO_MCP_FLAG;
  8421. return;
  8422. }
  8423. bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config);
  8424. BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config);
  8425. bp->link_params.hw_led_mode = ((bp->common.hw_config &
  8426. SHARED_HW_CFG_LED_MODE_MASK) >>
  8427. SHARED_HW_CFG_LED_MODE_SHIFT);
  8428. bp->link_params.feature_config_flags = 0;
  8429. val = SHMEM_RD(bp, dev_info.shared_feature_config.config);
  8430. if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED)
  8431. bp->link_params.feature_config_flags |=
  8432. FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  8433. else
  8434. bp->link_params.feature_config_flags &=
  8435. ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  8436. val = SHMEM_RD(bp, dev_info.bc_rev) >> 8;
  8437. bp->common.bc_ver = val;
  8438. BNX2X_DEV_INFO("bc_ver %X\n", val);
  8439. if (val < BNX2X_BC_VER) {
  8440. /* for now only warn
  8441. * later we might need to enforce this */
  8442. BNX2X_ERR("This driver needs bc_ver %X but found %X, please upgrade BC\n",
  8443. BNX2X_BC_VER, val);
  8444. }
  8445. bp->link_params.feature_config_flags |=
  8446. (val >= REQ_BC_VER_4_VRFY_FIRST_PHY_OPT_MDL) ?
  8447. FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY : 0;
  8448. bp->link_params.feature_config_flags |=
  8449. (val >= REQ_BC_VER_4_VRFY_SPECIFIC_PHY_OPT_MDL) ?
  8450. FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY : 0;
  8451. bp->link_params.feature_config_flags |=
  8452. (val >= REQ_BC_VER_4_VRFY_AFEX_SUPPORTED) ?
  8453. FEATURE_CONFIG_BC_SUPPORTS_AFEX : 0;
  8454. bp->link_params.feature_config_flags |=
  8455. (val >= REQ_BC_VER_4_SFP_TX_DISABLE_SUPPORTED) ?
  8456. FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED : 0;
  8457. bp->link_params.feature_config_flags |=
  8458. (val >= REQ_BC_VER_4_MT_SUPPORTED) ?
  8459. FEATURE_CONFIG_MT_SUPPORT : 0;
  8460. bp->flags |= (val >= REQ_BC_VER_4_PFC_STATS_SUPPORTED) ?
  8461. BC_SUPPORTS_PFC_STATS : 0;
  8462. bp->flags |= (val >= REQ_BC_VER_4_FCOE_FEATURES) ?
  8463. BC_SUPPORTS_FCOE_FEATURES : 0;
  8464. bp->flags |= (val >= REQ_BC_VER_4_DCBX_ADMIN_MSG_NON_PMF) ?
  8465. BC_SUPPORTS_DCBX_MSG_NON_PMF : 0;
  8466. boot_mode = SHMEM_RD(bp,
  8467. dev_info.port_feature_config[BP_PORT(bp)].mba_config) &
  8468. PORT_FEATURE_MBA_BOOT_AGENT_TYPE_MASK;
  8469. switch (boot_mode) {
  8470. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_PXE:
  8471. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_PXE;
  8472. break;
  8473. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_ISCSIB:
  8474. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_ISCSI;
  8475. break;
  8476. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_FCOE_BOOT:
  8477. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_FCOE;
  8478. break;
  8479. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_NONE:
  8480. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_NONE;
  8481. break;
  8482. }
  8483. pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_PMC, &pmc);
  8484. bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG;
  8485. BNX2X_DEV_INFO("%sWoL capable\n",
  8486. (bp->flags & NO_WOL_FLAG) ? "not " : "");
  8487. val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num);
  8488. val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]);
  8489. val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]);
  8490. val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]);
  8491. dev_info(&bp->pdev->dev, "part number %X-%X-%X-%X\n",
  8492. val, val2, val3, val4);
  8493. }
  8494. #define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID)
  8495. #define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR)
  8496. static int bnx2x_get_igu_cam_info(struct bnx2x *bp)
  8497. {
  8498. int pfid = BP_FUNC(bp);
  8499. int igu_sb_id;
  8500. u32 val;
  8501. u8 fid, igu_sb_cnt = 0;
  8502. bp->igu_base_sb = 0xff;
  8503. if (CHIP_INT_MODE_IS_BC(bp)) {
  8504. int vn = BP_VN(bp);
  8505. igu_sb_cnt = bp->igu_sb_cnt;
  8506. bp->igu_base_sb = (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn) *
  8507. FP_SB_MAX_E1x;
  8508. bp->igu_dsb_id = E1HVN_MAX * FP_SB_MAX_E1x +
  8509. (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn);
  8510. return 0;
  8511. }
  8512. /* IGU in normal mode - read CAM */
  8513. for (igu_sb_id = 0; igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE;
  8514. igu_sb_id++) {
  8515. val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4);
  8516. if (!(val & IGU_REG_MAPPING_MEMORY_VALID))
  8517. continue;
  8518. fid = IGU_FID(val);
  8519. if ((fid & IGU_FID_ENCODE_IS_PF)) {
  8520. if ((fid & IGU_FID_PF_NUM_MASK) != pfid)
  8521. continue;
  8522. if (IGU_VEC(val) == 0)
  8523. /* default status block */
  8524. bp->igu_dsb_id = igu_sb_id;
  8525. else {
  8526. if (bp->igu_base_sb == 0xff)
  8527. bp->igu_base_sb = igu_sb_id;
  8528. igu_sb_cnt++;
  8529. }
  8530. }
  8531. }
  8532. #ifdef CONFIG_PCI_MSI
  8533. /* Due to new PF resource allocation by MFW T7.4 and above, it's
  8534. * optional that number of CAM entries will not be equal to the value
  8535. * advertised in PCI.
  8536. * Driver should use the minimal value of both as the actual status
  8537. * block count
  8538. */
  8539. bp->igu_sb_cnt = min_t(int, bp->igu_sb_cnt, igu_sb_cnt);
  8540. #endif
  8541. if (igu_sb_cnt == 0) {
  8542. BNX2X_ERR("CAM configuration error\n");
  8543. return -EINVAL;
  8544. }
  8545. return 0;
  8546. }
  8547. static void bnx2x_link_settings_supported(struct bnx2x *bp, u32 switch_cfg)
  8548. {
  8549. int cfg_size = 0, idx, port = BP_PORT(bp);
  8550. /* Aggregation of supported attributes of all external phys */
  8551. bp->port.supported[0] = 0;
  8552. bp->port.supported[1] = 0;
  8553. switch (bp->link_params.num_phys) {
  8554. case 1:
  8555. bp->port.supported[0] = bp->link_params.phy[INT_PHY].supported;
  8556. cfg_size = 1;
  8557. break;
  8558. case 2:
  8559. bp->port.supported[0] = bp->link_params.phy[EXT_PHY1].supported;
  8560. cfg_size = 1;
  8561. break;
  8562. case 3:
  8563. if (bp->link_params.multi_phy_config &
  8564. PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
  8565. bp->port.supported[1] =
  8566. bp->link_params.phy[EXT_PHY1].supported;
  8567. bp->port.supported[0] =
  8568. bp->link_params.phy[EXT_PHY2].supported;
  8569. } else {
  8570. bp->port.supported[0] =
  8571. bp->link_params.phy[EXT_PHY1].supported;
  8572. bp->port.supported[1] =
  8573. bp->link_params.phy[EXT_PHY2].supported;
  8574. }
  8575. cfg_size = 2;
  8576. break;
  8577. }
  8578. if (!(bp->port.supported[0] || bp->port.supported[1])) {
  8579. BNX2X_ERR("NVRAM config error. BAD phy config. PHY1 config 0x%x, PHY2 config 0x%x\n",
  8580. SHMEM_RD(bp,
  8581. dev_info.port_hw_config[port].external_phy_config),
  8582. SHMEM_RD(bp,
  8583. dev_info.port_hw_config[port].external_phy_config2));
  8584. return;
  8585. }
  8586. if (CHIP_IS_E3(bp))
  8587. bp->port.phy_addr = REG_RD(bp, MISC_REG_WC0_CTRL_PHY_ADDR);
  8588. else {
  8589. switch (switch_cfg) {
  8590. case SWITCH_CFG_1G:
  8591. bp->port.phy_addr = REG_RD(
  8592. bp, NIG_REG_SERDES0_CTRL_PHY_ADDR + port*0x10);
  8593. break;
  8594. case SWITCH_CFG_10G:
  8595. bp->port.phy_addr = REG_RD(
  8596. bp, NIG_REG_XGXS0_CTRL_PHY_ADDR + port*0x18);
  8597. break;
  8598. default:
  8599. BNX2X_ERR("BAD switch_cfg link_config 0x%x\n",
  8600. bp->port.link_config[0]);
  8601. return;
  8602. }
  8603. }
  8604. BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
  8605. /* mask what we support according to speed_cap_mask per configuration */
  8606. for (idx = 0; idx < cfg_size; idx++) {
  8607. if (!(bp->link_params.speed_cap_mask[idx] &
  8608. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF))
  8609. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Half;
  8610. if (!(bp->link_params.speed_cap_mask[idx] &
  8611. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL))
  8612. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Full;
  8613. if (!(bp->link_params.speed_cap_mask[idx] &
  8614. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF))
  8615. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Half;
  8616. if (!(bp->link_params.speed_cap_mask[idx] &
  8617. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL))
  8618. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Full;
  8619. if (!(bp->link_params.speed_cap_mask[idx] &
  8620. PORT_HW_CFG_SPEED_CAPABILITY_D0_1G))
  8621. bp->port.supported[idx] &= ~(SUPPORTED_1000baseT_Half |
  8622. SUPPORTED_1000baseT_Full);
  8623. if (!(bp->link_params.speed_cap_mask[idx] &
  8624. PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
  8625. bp->port.supported[idx] &= ~SUPPORTED_2500baseX_Full;
  8626. if (!(bp->link_params.speed_cap_mask[idx] &
  8627. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G))
  8628. bp->port.supported[idx] &= ~SUPPORTED_10000baseT_Full;
  8629. }
  8630. BNX2X_DEV_INFO("supported 0x%x 0x%x\n", bp->port.supported[0],
  8631. bp->port.supported[1]);
  8632. }
  8633. static void bnx2x_link_settings_requested(struct bnx2x *bp)
  8634. {
  8635. u32 link_config, idx, cfg_size = 0;
  8636. bp->port.advertising[0] = 0;
  8637. bp->port.advertising[1] = 0;
  8638. switch (bp->link_params.num_phys) {
  8639. case 1:
  8640. case 2:
  8641. cfg_size = 1;
  8642. break;
  8643. case 3:
  8644. cfg_size = 2;
  8645. break;
  8646. }
  8647. for (idx = 0; idx < cfg_size; idx++) {
  8648. bp->link_params.req_duplex[idx] = DUPLEX_FULL;
  8649. link_config = bp->port.link_config[idx];
  8650. switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
  8651. case PORT_FEATURE_LINK_SPEED_AUTO:
  8652. if (bp->port.supported[idx] & SUPPORTED_Autoneg) {
  8653. bp->link_params.req_line_speed[idx] =
  8654. SPEED_AUTO_NEG;
  8655. bp->port.advertising[idx] |=
  8656. bp->port.supported[idx];
  8657. if (bp->link_params.phy[EXT_PHY1].type ==
  8658. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
  8659. bp->port.advertising[idx] |=
  8660. (SUPPORTED_100baseT_Half |
  8661. SUPPORTED_100baseT_Full);
  8662. } else {
  8663. /* force 10G, no AN */
  8664. bp->link_params.req_line_speed[idx] =
  8665. SPEED_10000;
  8666. bp->port.advertising[idx] |=
  8667. (ADVERTISED_10000baseT_Full |
  8668. ADVERTISED_FIBRE);
  8669. continue;
  8670. }
  8671. break;
  8672. case PORT_FEATURE_LINK_SPEED_10M_FULL:
  8673. if (bp->port.supported[idx] & SUPPORTED_10baseT_Full) {
  8674. bp->link_params.req_line_speed[idx] =
  8675. SPEED_10;
  8676. bp->port.advertising[idx] |=
  8677. (ADVERTISED_10baseT_Full |
  8678. ADVERTISED_TP);
  8679. } else {
  8680. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8681. link_config,
  8682. bp->link_params.speed_cap_mask[idx]);
  8683. return;
  8684. }
  8685. break;
  8686. case PORT_FEATURE_LINK_SPEED_10M_HALF:
  8687. if (bp->port.supported[idx] & SUPPORTED_10baseT_Half) {
  8688. bp->link_params.req_line_speed[idx] =
  8689. SPEED_10;
  8690. bp->link_params.req_duplex[idx] =
  8691. DUPLEX_HALF;
  8692. bp->port.advertising[idx] |=
  8693. (ADVERTISED_10baseT_Half |
  8694. ADVERTISED_TP);
  8695. } else {
  8696. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8697. link_config,
  8698. bp->link_params.speed_cap_mask[idx]);
  8699. return;
  8700. }
  8701. break;
  8702. case PORT_FEATURE_LINK_SPEED_100M_FULL:
  8703. if (bp->port.supported[idx] &
  8704. SUPPORTED_100baseT_Full) {
  8705. bp->link_params.req_line_speed[idx] =
  8706. SPEED_100;
  8707. bp->port.advertising[idx] |=
  8708. (ADVERTISED_100baseT_Full |
  8709. ADVERTISED_TP);
  8710. } else {
  8711. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8712. link_config,
  8713. bp->link_params.speed_cap_mask[idx]);
  8714. return;
  8715. }
  8716. break;
  8717. case PORT_FEATURE_LINK_SPEED_100M_HALF:
  8718. if (bp->port.supported[idx] &
  8719. SUPPORTED_100baseT_Half) {
  8720. bp->link_params.req_line_speed[idx] =
  8721. SPEED_100;
  8722. bp->link_params.req_duplex[idx] =
  8723. DUPLEX_HALF;
  8724. bp->port.advertising[idx] |=
  8725. (ADVERTISED_100baseT_Half |
  8726. ADVERTISED_TP);
  8727. } else {
  8728. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8729. link_config,
  8730. bp->link_params.speed_cap_mask[idx]);
  8731. return;
  8732. }
  8733. break;
  8734. case PORT_FEATURE_LINK_SPEED_1G:
  8735. if (bp->port.supported[idx] &
  8736. SUPPORTED_1000baseT_Full) {
  8737. bp->link_params.req_line_speed[idx] =
  8738. SPEED_1000;
  8739. bp->port.advertising[idx] |=
  8740. (ADVERTISED_1000baseT_Full |
  8741. ADVERTISED_TP);
  8742. } else {
  8743. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8744. link_config,
  8745. bp->link_params.speed_cap_mask[idx]);
  8746. return;
  8747. }
  8748. break;
  8749. case PORT_FEATURE_LINK_SPEED_2_5G:
  8750. if (bp->port.supported[idx] &
  8751. SUPPORTED_2500baseX_Full) {
  8752. bp->link_params.req_line_speed[idx] =
  8753. SPEED_2500;
  8754. bp->port.advertising[idx] |=
  8755. (ADVERTISED_2500baseX_Full |
  8756. ADVERTISED_TP);
  8757. } else {
  8758. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8759. link_config,
  8760. bp->link_params.speed_cap_mask[idx]);
  8761. return;
  8762. }
  8763. break;
  8764. case PORT_FEATURE_LINK_SPEED_10G_CX4:
  8765. if (bp->port.supported[idx] &
  8766. SUPPORTED_10000baseT_Full) {
  8767. bp->link_params.req_line_speed[idx] =
  8768. SPEED_10000;
  8769. bp->port.advertising[idx] |=
  8770. (ADVERTISED_10000baseT_Full |
  8771. ADVERTISED_FIBRE);
  8772. } else {
  8773. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8774. link_config,
  8775. bp->link_params.speed_cap_mask[idx]);
  8776. return;
  8777. }
  8778. break;
  8779. case PORT_FEATURE_LINK_SPEED_20G:
  8780. bp->link_params.req_line_speed[idx] = SPEED_20000;
  8781. break;
  8782. default:
  8783. BNX2X_ERR("NVRAM config error. BAD link speed link_config 0x%x\n",
  8784. link_config);
  8785. bp->link_params.req_line_speed[idx] =
  8786. SPEED_AUTO_NEG;
  8787. bp->port.advertising[idx] =
  8788. bp->port.supported[idx];
  8789. break;
  8790. }
  8791. bp->link_params.req_flow_ctrl[idx] = (link_config &
  8792. PORT_FEATURE_FLOW_CONTROL_MASK);
  8793. if (bp->link_params.req_flow_ctrl[idx] ==
  8794. BNX2X_FLOW_CTRL_AUTO) {
  8795. if (!(bp->port.supported[idx] & SUPPORTED_Autoneg))
  8796. bp->link_params.req_flow_ctrl[idx] =
  8797. BNX2X_FLOW_CTRL_NONE;
  8798. else
  8799. bnx2x_set_requested_fc(bp);
  8800. }
  8801. BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl 0x%x advertising 0x%x\n",
  8802. bp->link_params.req_line_speed[idx],
  8803. bp->link_params.req_duplex[idx],
  8804. bp->link_params.req_flow_ctrl[idx],
  8805. bp->port.advertising[idx]);
  8806. }
  8807. }
  8808. static void bnx2x_set_mac_buf(u8 *mac_buf, u32 mac_lo, u16 mac_hi)
  8809. {
  8810. mac_hi = cpu_to_be16(mac_hi);
  8811. mac_lo = cpu_to_be32(mac_lo);
  8812. memcpy(mac_buf, &mac_hi, sizeof(mac_hi));
  8813. memcpy(mac_buf + sizeof(mac_hi), &mac_lo, sizeof(mac_lo));
  8814. }
  8815. static void bnx2x_get_port_hwinfo(struct bnx2x *bp)
  8816. {
  8817. int port = BP_PORT(bp);
  8818. u32 config;
  8819. u32 ext_phy_type, ext_phy_config, eee_mode;
  8820. bp->link_params.bp = bp;
  8821. bp->link_params.port = port;
  8822. bp->link_params.lane_config =
  8823. SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config);
  8824. bp->link_params.speed_cap_mask[0] =
  8825. SHMEM_RD(bp,
  8826. dev_info.port_hw_config[port].speed_capability_mask);
  8827. bp->link_params.speed_cap_mask[1] =
  8828. SHMEM_RD(bp,
  8829. dev_info.port_hw_config[port].speed_capability_mask2);
  8830. bp->port.link_config[0] =
  8831. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config);
  8832. bp->port.link_config[1] =
  8833. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config2);
  8834. bp->link_params.multi_phy_config =
  8835. SHMEM_RD(bp, dev_info.port_hw_config[port].multi_phy_config);
  8836. /* If the device is capable of WoL, set the default state according
  8837. * to the HW
  8838. */
  8839. config = SHMEM_RD(bp, dev_info.port_feature_config[port].config);
  8840. bp->wol = (!(bp->flags & NO_WOL_FLAG) &&
  8841. (config & PORT_FEATURE_WOL_ENABLED));
  8842. if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) ==
  8843. PORT_FEAT_CFG_STORAGE_PERSONALITY_FCOE && !IS_MF(bp))
  8844. bp->flags |= NO_ISCSI_FLAG;
  8845. if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) ==
  8846. PORT_FEAT_CFG_STORAGE_PERSONALITY_ISCSI && !(IS_MF(bp)))
  8847. bp->flags |= NO_FCOE_FLAG;
  8848. BNX2X_DEV_INFO("lane_config 0x%08x speed_cap_mask0 0x%08x link_config0 0x%08x\n",
  8849. bp->link_params.lane_config,
  8850. bp->link_params.speed_cap_mask[0],
  8851. bp->port.link_config[0]);
  8852. bp->link_params.switch_cfg = (bp->port.link_config[0] &
  8853. PORT_FEATURE_CONNECTED_SWITCH_MASK);
  8854. bnx2x_phy_probe(&bp->link_params);
  8855. bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg);
  8856. bnx2x_link_settings_requested(bp);
  8857. /*
  8858. * If connected directly, work with the internal PHY, otherwise, work
  8859. * with the external PHY
  8860. */
  8861. ext_phy_config =
  8862. SHMEM_RD(bp,
  8863. dev_info.port_hw_config[port].external_phy_config);
  8864. ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
  8865. if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
  8866. bp->mdio.prtad = bp->port.phy_addr;
  8867. else if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) &&
  8868. (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
  8869. bp->mdio.prtad =
  8870. XGXS_EXT_PHY_ADDR(ext_phy_config);
  8871. /* Configure link feature according to nvram value */
  8872. eee_mode = (((SHMEM_RD(bp, dev_info.
  8873. port_feature_config[port].eee_power_mode)) &
  8874. PORT_FEAT_CFG_EEE_POWER_MODE_MASK) >>
  8875. PORT_FEAT_CFG_EEE_POWER_MODE_SHIFT);
  8876. if (eee_mode != PORT_FEAT_CFG_EEE_POWER_MODE_DISABLED) {
  8877. bp->link_params.eee_mode = EEE_MODE_ADV_LPI |
  8878. EEE_MODE_ENABLE_LPI |
  8879. EEE_MODE_OUTPUT_TIME;
  8880. } else {
  8881. bp->link_params.eee_mode = 0;
  8882. }
  8883. }
  8884. void bnx2x_get_iscsi_info(struct bnx2x *bp)
  8885. {
  8886. u32 no_flags = NO_ISCSI_FLAG;
  8887. int port = BP_PORT(bp);
  8888. u32 max_iscsi_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  8889. drv_lic_key[port].max_iscsi_conn);
  8890. if (!CNIC_SUPPORT(bp)) {
  8891. bp->flags |= no_flags;
  8892. return;
  8893. }
  8894. /* Get the number of maximum allowed iSCSI connections */
  8895. bp->cnic_eth_dev.max_iscsi_conn =
  8896. (max_iscsi_conn & BNX2X_MAX_ISCSI_INIT_CONN_MASK) >>
  8897. BNX2X_MAX_ISCSI_INIT_CONN_SHIFT;
  8898. BNX2X_DEV_INFO("max_iscsi_conn 0x%x\n",
  8899. bp->cnic_eth_dev.max_iscsi_conn);
  8900. /*
  8901. * If maximum allowed number of connections is zero -
  8902. * disable the feature.
  8903. */
  8904. if (!bp->cnic_eth_dev.max_iscsi_conn)
  8905. bp->flags |= no_flags;
  8906. }
  8907. static void bnx2x_get_ext_wwn_info(struct bnx2x *bp, int func)
  8908. {
  8909. /* Port info */
  8910. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  8911. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_upper);
  8912. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  8913. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_lower);
  8914. /* Node info */
  8915. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  8916. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_upper);
  8917. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  8918. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_lower);
  8919. }
  8920. static void bnx2x_get_fcoe_info(struct bnx2x *bp)
  8921. {
  8922. int port = BP_PORT(bp);
  8923. int func = BP_ABS_FUNC(bp);
  8924. u32 max_fcoe_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  8925. drv_lic_key[port].max_fcoe_conn);
  8926. if (!CNIC_SUPPORT(bp)) {
  8927. bp->flags |= NO_FCOE_FLAG;
  8928. return;
  8929. }
  8930. /* Get the number of maximum allowed FCoE connections */
  8931. bp->cnic_eth_dev.max_fcoe_conn =
  8932. (max_fcoe_conn & BNX2X_MAX_FCOE_INIT_CONN_MASK) >>
  8933. BNX2X_MAX_FCOE_INIT_CONN_SHIFT;
  8934. /* Read the WWN: */
  8935. if (!IS_MF(bp)) {
  8936. /* Port info */
  8937. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  8938. SHMEM_RD(bp,
  8939. dev_info.port_hw_config[port].
  8940. fcoe_wwn_port_name_upper);
  8941. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  8942. SHMEM_RD(bp,
  8943. dev_info.port_hw_config[port].
  8944. fcoe_wwn_port_name_lower);
  8945. /* Node info */
  8946. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  8947. SHMEM_RD(bp,
  8948. dev_info.port_hw_config[port].
  8949. fcoe_wwn_node_name_upper);
  8950. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  8951. SHMEM_RD(bp,
  8952. dev_info.port_hw_config[port].
  8953. fcoe_wwn_node_name_lower);
  8954. } else if (!IS_MF_SD(bp)) {
  8955. /*
  8956. * Read the WWN info only if the FCoE feature is enabled for
  8957. * this function.
  8958. */
  8959. if (BNX2X_MF_EXT_PROTOCOL_FCOE(bp) && !CHIP_IS_E1x(bp))
  8960. bnx2x_get_ext_wwn_info(bp, func);
  8961. } else if (IS_MF_FCOE_SD(bp) && !CHIP_IS_E1x(bp)) {
  8962. bnx2x_get_ext_wwn_info(bp, func);
  8963. }
  8964. BNX2X_DEV_INFO("max_fcoe_conn 0x%x\n", bp->cnic_eth_dev.max_fcoe_conn);
  8965. /*
  8966. * If maximum allowed number of connections is zero -
  8967. * disable the feature.
  8968. */
  8969. if (!bp->cnic_eth_dev.max_fcoe_conn)
  8970. bp->flags |= NO_FCOE_FLAG;
  8971. }
  8972. static void bnx2x_get_cnic_info(struct bnx2x *bp)
  8973. {
  8974. /*
  8975. * iSCSI may be dynamically disabled but reading
  8976. * info here we will decrease memory usage by driver
  8977. * if the feature is disabled for good
  8978. */
  8979. bnx2x_get_iscsi_info(bp);
  8980. bnx2x_get_fcoe_info(bp);
  8981. }
  8982. static void bnx2x_get_cnic_mac_hwinfo(struct bnx2x *bp)
  8983. {
  8984. u32 val, val2;
  8985. int func = BP_ABS_FUNC(bp);
  8986. int port = BP_PORT(bp);
  8987. u8 *iscsi_mac = bp->cnic_eth_dev.iscsi_mac;
  8988. u8 *fip_mac = bp->fip_mac;
  8989. if (IS_MF(bp)) {
  8990. /* iSCSI and FCoE NPAR MACs: if there is no either iSCSI or
  8991. * FCoE MAC then the appropriate feature should be disabled.
  8992. * In non SD mode features configuration comes from struct
  8993. * func_ext_config.
  8994. */
  8995. if (!IS_MF_SD(bp) && !CHIP_IS_E1x(bp)) {
  8996. u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
  8997. if (cfg & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) {
  8998. val2 = MF_CFG_RD(bp, func_ext_config[func].
  8999. iscsi_mac_addr_upper);
  9000. val = MF_CFG_RD(bp, func_ext_config[func].
  9001. iscsi_mac_addr_lower);
  9002. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  9003. BNX2X_DEV_INFO
  9004. ("Read iSCSI MAC: %pM\n", iscsi_mac);
  9005. } else {
  9006. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  9007. }
  9008. if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) {
  9009. val2 = MF_CFG_RD(bp, func_ext_config[func].
  9010. fcoe_mac_addr_upper);
  9011. val = MF_CFG_RD(bp, func_ext_config[func].
  9012. fcoe_mac_addr_lower);
  9013. bnx2x_set_mac_buf(fip_mac, val, val2);
  9014. BNX2X_DEV_INFO
  9015. ("Read FCoE L2 MAC: %pM\n", fip_mac);
  9016. } else {
  9017. bp->flags |= NO_FCOE_FLAG;
  9018. }
  9019. bp->mf_ext_config = cfg;
  9020. } else { /* SD MODE */
  9021. if (BNX2X_IS_MF_SD_PROTOCOL_ISCSI(bp)) {
  9022. /* use primary mac as iscsi mac */
  9023. memcpy(iscsi_mac, bp->dev->dev_addr, ETH_ALEN);
  9024. BNX2X_DEV_INFO("SD ISCSI MODE\n");
  9025. BNX2X_DEV_INFO
  9026. ("Read iSCSI MAC: %pM\n", iscsi_mac);
  9027. } else if (BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp)) {
  9028. /* use primary mac as fip mac */
  9029. memcpy(fip_mac, bp->dev->dev_addr, ETH_ALEN);
  9030. BNX2X_DEV_INFO("SD FCoE MODE\n");
  9031. BNX2X_DEV_INFO
  9032. ("Read FIP MAC: %pM\n", fip_mac);
  9033. }
  9034. }
  9035. if (IS_MF_STORAGE_SD(bp))
  9036. /* Zero primary MAC configuration */
  9037. memset(bp->dev->dev_addr, 0, ETH_ALEN);
  9038. if (IS_MF_FCOE_AFEX(bp) || IS_MF_FCOE_SD(bp))
  9039. /* use FIP MAC as primary MAC */
  9040. memcpy(bp->dev->dev_addr, fip_mac, ETH_ALEN);
  9041. } else {
  9042. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9043. iscsi_mac_upper);
  9044. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9045. iscsi_mac_lower);
  9046. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  9047. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9048. fcoe_fip_mac_upper);
  9049. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9050. fcoe_fip_mac_lower);
  9051. bnx2x_set_mac_buf(fip_mac, val, val2);
  9052. }
  9053. /* Disable iSCSI OOO if MAC configuration is invalid. */
  9054. if (!is_valid_ether_addr(iscsi_mac)) {
  9055. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  9056. memset(iscsi_mac, 0, ETH_ALEN);
  9057. }
  9058. /* Disable FCoE if MAC configuration is invalid. */
  9059. if (!is_valid_ether_addr(fip_mac)) {
  9060. bp->flags |= NO_FCOE_FLAG;
  9061. memset(bp->fip_mac, 0, ETH_ALEN);
  9062. }
  9063. }
  9064. static void bnx2x_get_mac_hwinfo(struct bnx2x *bp)
  9065. {
  9066. u32 val, val2;
  9067. int func = BP_ABS_FUNC(bp);
  9068. int port = BP_PORT(bp);
  9069. /* Zero primary MAC configuration */
  9070. memset(bp->dev->dev_addr, 0, ETH_ALEN);
  9071. if (BP_NOMCP(bp)) {
  9072. BNX2X_ERROR("warning: random MAC workaround active\n");
  9073. eth_hw_addr_random(bp->dev);
  9074. } else if (IS_MF(bp)) {
  9075. val2 = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
  9076. val = MF_CFG_RD(bp, func_mf_config[func].mac_lower);
  9077. if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) &&
  9078. (val != FUNC_MF_CFG_LOWERMAC_DEFAULT))
  9079. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  9080. if (CNIC_SUPPORT(bp))
  9081. bnx2x_get_cnic_mac_hwinfo(bp);
  9082. } else {
  9083. /* in SF read MACs from port configuration */
  9084. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
  9085. val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
  9086. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  9087. if (CNIC_SUPPORT(bp))
  9088. bnx2x_get_cnic_mac_hwinfo(bp);
  9089. }
  9090. memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN);
  9091. if (!bnx2x_is_valid_ether_addr(bp, bp->dev->dev_addr))
  9092. dev_err(&bp->pdev->dev,
  9093. "bad Ethernet MAC address configuration: %pM\n"
  9094. "change it manually before bringing up the appropriate network interface\n",
  9095. bp->dev->dev_addr);
  9096. }
  9097. static bool bnx2x_get_dropless_info(struct bnx2x *bp)
  9098. {
  9099. int tmp;
  9100. u32 cfg;
  9101. if (IS_MF(bp) && !CHIP_IS_E1x(bp)) {
  9102. /* Take function: tmp = func */
  9103. tmp = BP_ABS_FUNC(bp);
  9104. cfg = MF_CFG_RD(bp, func_ext_config[tmp].func_cfg);
  9105. cfg = !!(cfg & MACP_FUNC_CFG_PAUSE_ON_HOST_RING);
  9106. } else {
  9107. /* Take port: tmp = port */
  9108. tmp = BP_PORT(bp);
  9109. cfg = SHMEM_RD(bp,
  9110. dev_info.port_hw_config[tmp].generic_features);
  9111. cfg = !!(cfg & PORT_HW_CFG_PAUSE_ON_HOST_RING_ENABLED);
  9112. }
  9113. return cfg;
  9114. }
  9115. static int bnx2x_get_hwinfo(struct bnx2x *bp)
  9116. {
  9117. int /*abs*/func = BP_ABS_FUNC(bp);
  9118. int vn;
  9119. u32 val = 0;
  9120. int rc = 0;
  9121. bnx2x_get_common_hwinfo(bp);
  9122. /*
  9123. * initialize IGU parameters
  9124. */
  9125. if (CHIP_IS_E1x(bp)) {
  9126. bp->common.int_block = INT_BLOCK_HC;
  9127. bp->igu_dsb_id = DEF_SB_IGU_ID;
  9128. bp->igu_base_sb = 0;
  9129. } else {
  9130. bp->common.int_block = INT_BLOCK_IGU;
  9131. /* do not allow device reset during IGU info preocessing */
  9132. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  9133. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  9134. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  9135. int tout = 5000;
  9136. BNX2X_DEV_INFO("FORCING Normal Mode\n");
  9137. val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN);
  9138. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION, val);
  9139. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x7f);
  9140. while (tout && REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  9141. tout--;
  9142. usleep_range(1000, 2000);
  9143. }
  9144. if (REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  9145. dev_err(&bp->pdev->dev,
  9146. "FORCING Normal Mode failed!!!\n");
  9147. bnx2x_release_hw_lock(bp,
  9148. HW_LOCK_RESOURCE_RESET);
  9149. return -EPERM;
  9150. }
  9151. }
  9152. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  9153. BNX2X_DEV_INFO("IGU Backward Compatible Mode\n");
  9154. bp->common.int_block |= INT_BLOCK_MODE_BW_COMP;
  9155. } else
  9156. BNX2X_DEV_INFO("IGU Normal Mode\n");
  9157. rc = bnx2x_get_igu_cam_info(bp);
  9158. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  9159. if (rc)
  9160. return rc;
  9161. }
  9162. /*
  9163. * set base FW non-default (fast path) status block id, this value is
  9164. * used to initialize the fw_sb_id saved on the fp/queue structure to
  9165. * determine the id used by the FW.
  9166. */
  9167. if (CHIP_IS_E1x(bp))
  9168. bp->base_fw_ndsb = BP_PORT(bp) * FP_SB_MAX_E1x + BP_L_ID(bp);
  9169. else /*
  9170. * 57712 - we currently use one FW SB per IGU SB (Rx and Tx of
  9171. * the same queue are indicated on the same IGU SB). So we prefer
  9172. * FW and IGU SBs to be the same value.
  9173. */
  9174. bp->base_fw_ndsb = bp->igu_base_sb;
  9175. BNX2X_DEV_INFO("igu_dsb_id %d igu_base_sb %d igu_sb_cnt %d\n"
  9176. "base_fw_ndsb %d\n", bp->igu_dsb_id, bp->igu_base_sb,
  9177. bp->igu_sb_cnt, bp->base_fw_ndsb);
  9178. /*
  9179. * Initialize MF configuration
  9180. */
  9181. bp->mf_ov = 0;
  9182. bp->mf_mode = 0;
  9183. vn = BP_VN(bp);
  9184. if (!CHIP_IS_E1(bp) && !BP_NOMCP(bp)) {
  9185. BNX2X_DEV_INFO("shmem2base 0x%x, size %d, mfcfg offset %d\n",
  9186. bp->common.shmem2_base, SHMEM2_RD(bp, size),
  9187. (u32)offsetof(struct shmem2_region, mf_cfg_addr));
  9188. if (SHMEM2_HAS(bp, mf_cfg_addr))
  9189. bp->common.mf_cfg_base = SHMEM2_RD(bp, mf_cfg_addr);
  9190. else
  9191. bp->common.mf_cfg_base = bp->common.shmem_base +
  9192. offsetof(struct shmem_region, func_mb) +
  9193. E1H_FUNC_MAX * sizeof(struct drv_func_mb);
  9194. /*
  9195. * get mf configuration:
  9196. * 1. existence of MF configuration
  9197. * 2. MAC address must be legal (check only upper bytes)
  9198. * for Switch-Independent mode;
  9199. * OVLAN must be legal for Switch-Dependent mode
  9200. * 3. SF_MODE configures specific MF mode
  9201. */
  9202. if (bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  9203. /* get mf configuration */
  9204. val = SHMEM_RD(bp,
  9205. dev_info.shared_feature_config.config);
  9206. val &= SHARED_FEAT_CFG_FORCE_SF_MODE_MASK;
  9207. switch (val) {
  9208. case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT:
  9209. val = MF_CFG_RD(bp, func_mf_config[func].
  9210. mac_upper);
  9211. /* check for legal mac (upper bytes)*/
  9212. if (val != 0xffff) {
  9213. bp->mf_mode = MULTI_FUNCTION_SI;
  9214. bp->mf_config[vn] = MF_CFG_RD(bp,
  9215. func_mf_config[func].config);
  9216. } else
  9217. BNX2X_DEV_INFO("illegal MAC address for SI\n");
  9218. break;
  9219. case SHARED_FEAT_CFG_FORCE_SF_MODE_AFEX_MODE:
  9220. if ((!CHIP_IS_E1x(bp)) &&
  9221. (MF_CFG_RD(bp, func_mf_config[func].
  9222. mac_upper) != 0xffff) &&
  9223. (SHMEM2_HAS(bp,
  9224. afex_driver_support))) {
  9225. bp->mf_mode = MULTI_FUNCTION_AFEX;
  9226. bp->mf_config[vn] = MF_CFG_RD(bp,
  9227. func_mf_config[func].config);
  9228. } else {
  9229. BNX2X_DEV_INFO("can not configure afex mode\n");
  9230. }
  9231. break;
  9232. case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED:
  9233. /* get OV configuration */
  9234. val = MF_CFG_RD(bp,
  9235. func_mf_config[FUNC_0].e1hov_tag);
  9236. val &= FUNC_MF_CFG_E1HOV_TAG_MASK;
  9237. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  9238. bp->mf_mode = MULTI_FUNCTION_SD;
  9239. bp->mf_config[vn] = MF_CFG_RD(bp,
  9240. func_mf_config[func].config);
  9241. } else
  9242. BNX2X_DEV_INFO("illegal OV for SD\n");
  9243. break;
  9244. default:
  9245. /* Unknown configuration: reset mf_config */
  9246. bp->mf_config[vn] = 0;
  9247. BNX2X_DEV_INFO("unknown MF mode 0x%x\n", val);
  9248. }
  9249. }
  9250. BNX2X_DEV_INFO("%s function mode\n",
  9251. IS_MF(bp) ? "multi" : "single");
  9252. switch (bp->mf_mode) {
  9253. case MULTI_FUNCTION_SD:
  9254. val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  9255. FUNC_MF_CFG_E1HOV_TAG_MASK;
  9256. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  9257. bp->mf_ov = val;
  9258. bp->path_has_ovlan = true;
  9259. BNX2X_DEV_INFO("MF OV for func %d is %d (0x%04x)\n",
  9260. func, bp->mf_ov, bp->mf_ov);
  9261. } else {
  9262. dev_err(&bp->pdev->dev,
  9263. "No valid MF OV for func %d, aborting\n",
  9264. func);
  9265. return -EPERM;
  9266. }
  9267. break;
  9268. case MULTI_FUNCTION_AFEX:
  9269. BNX2X_DEV_INFO("func %d is in MF afex mode\n", func);
  9270. break;
  9271. case MULTI_FUNCTION_SI:
  9272. BNX2X_DEV_INFO("func %d is in MF switch-independent mode\n",
  9273. func);
  9274. break;
  9275. default:
  9276. if (vn) {
  9277. dev_err(&bp->pdev->dev,
  9278. "VN %d is in a single function mode, aborting\n",
  9279. vn);
  9280. return -EPERM;
  9281. }
  9282. break;
  9283. }
  9284. /* check if other port on the path needs ovlan:
  9285. * Since MF configuration is shared between ports
  9286. * Possible mixed modes are only
  9287. * {SF, SI} {SF, SD} {SD, SF} {SI, SF}
  9288. */
  9289. if (CHIP_MODE_IS_4_PORT(bp) &&
  9290. !bp->path_has_ovlan &&
  9291. !IS_MF(bp) &&
  9292. bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  9293. u8 other_port = !BP_PORT(bp);
  9294. u8 other_func = BP_PATH(bp) + 2*other_port;
  9295. val = MF_CFG_RD(bp,
  9296. func_mf_config[other_func].e1hov_tag);
  9297. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT)
  9298. bp->path_has_ovlan = true;
  9299. }
  9300. }
  9301. /* adjust igu_sb_cnt to MF for E1x */
  9302. if (CHIP_IS_E1x(bp) && IS_MF(bp))
  9303. bp->igu_sb_cnt /= E1HVN_MAX;
  9304. /* port info */
  9305. bnx2x_get_port_hwinfo(bp);
  9306. /* Get MAC addresses */
  9307. bnx2x_get_mac_hwinfo(bp);
  9308. bnx2x_get_cnic_info(bp);
  9309. return rc;
  9310. }
  9311. static void bnx2x_read_fwinfo(struct bnx2x *bp)
  9312. {
  9313. int cnt, i, block_end, rodi;
  9314. char vpd_start[BNX2X_VPD_LEN+1];
  9315. char str_id_reg[VENDOR_ID_LEN+1];
  9316. char str_id_cap[VENDOR_ID_LEN+1];
  9317. char *vpd_data;
  9318. char *vpd_extended_data = NULL;
  9319. u8 len;
  9320. cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_start);
  9321. memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
  9322. if (cnt < BNX2X_VPD_LEN)
  9323. goto out_not_found;
  9324. /* VPD RO tag should be first tag after identifier string, hence
  9325. * we should be able to find it in first BNX2X_VPD_LEN chars
  9326. */
  9327. i = pci_vpd_find_tag(vpd_start, 0, BNX2X_VPD_LEN,
  9328. PCI_VPD_LRDT_RO_DATA);
  9329. if (i < 0)
  9330. goto out_not_found;
  9331. block_end = i + PCI_VPD_LRDT_TAG_SIZE +
  9332. pci_vpd_lrdt_size(&vpd_start[i]);
  9333. i += PCI_VPD_LRDT_TAG_SIZE;
  9334. if (block_end > BNX2X_VPD_LEN) {
  9335. vpd_extended_data = kmalloc(block_end, GFP_KERNEL);
  9336. if (vpd_extended_data == NULL)
  9337. goto out_not_found;
  9338. /* read rest of vpd image into vpd_extended_data */
  9339. memcpy(vpd_extended_data, vpd_start, BNX2X_VPD_LEN);
  9340. cnt = pci_read_vpd(bp->pdev, BNX2X_VPD_LEN,
  9341. block_end - BNX2X_VPD_LEN,
  9342. vpd_extended_data + BNX2X_VPD_LEN);
  9343. if (cnt < (block_end - BNX2X_VPD_LEN))
  9344. goto out_not_found;
  9345. vpd_data = vpd_extended_data;
  9346. } else
  9347. vpd_data = vpd_start;
  9348. /* now vpd_data holds full vpd content in both cases */
  9349. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  9350. PCI_VPD_RO_KEYWORD_MFR_ID);
  9351. if (rodi < 0)
  9352. goto out_not_found;
  9353. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  9354. if (len != VENDOR_ID_LEN)
  9355. goto out_not_found;
  9356. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  9357. /* vendor specific info */
  9358. snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL);
  9359. snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL);
  9360. if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) ||
  9361. !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) {
  9362. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  9363. PCI_VPD_RO_KEYWORD_VENDOR0);
  9364. if (rodi >= 0) {
  9365. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  9366. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  9367. if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) {
  9368. memcpy(bp->fw_ver, &vpd_data[rodi], len);
  9369. bp->fw_ver[len] = ' ';
  9370. }
  9371. }
  9372. kfree(vpd_extended_data);
  9373. return;
  9374. }
  9375. out_not_found:
  9376. kfree(vpd_extended_data);
  9377. return;
  9378. }
  9379. static void bnx2x_set_modes_bitmap(struct bnx2x *bp)
  9380. {
  9381. u32 flags = 0;
  9382. if (CHIP_REV_IS_FPGA(bp))
  9383. SET_FLAGS(flags, MODE_FPGA);
  9384. else if (CHIP_REV_IS_EMUL(bp))
  9385. SET_FLAGS(flags, MODE_EMUL);
  9386. else
  9387. SET_FLAGS(flags, MODE_ASIC);
  9388. if (CHIP_MODE_IS_4_PORT(bp))
  9389. SET_FLAGS(flags, MODE_PORT4);
  9390. else
  9391. SET_FLAGS(flags, MODE_PORT2);
  9392. if (CHIP_IS_E2(bp))
  9393. SET_FLAGS(flags, MODE_E2);
  9394. else if (CHIP_IS_E3(bp)) {
  9395. SET_FLAGS(flags, MODE_E3);
  9396. if (CHIP_REV(bp) == CHIP_REV_Ax)
  9397. SET_FLAGS(flags, MODE_E3_A0);
  9398. else /*if (CHIP_REV(bp) == CHIP_REV_Bx)*/
  9399. SET_FLAGS(flags, MODE_E3_B0 | MODE_COS3);
  9400. }
  9401. if (IS_MF(bp)) {
  9402. SET_FLAGS(flags, MODE_MF);
  9403. switch (bp->mf_mode) {
  9404. case MULTI_FUNCTION_SD:
  9405. SET_FLAGS(flags, MODE_MF_SD);
  9406. break;
  9407. case MULTI_FUNCTION_SI:
  9408. SET_FLAGS(flags, MODE_MF_SI);
  9409. break;
  9410. case MULTI_FUNCTION_AFEX:
  9411. SET_FLAGS(flags, MODE_MF_AFEX);
  9412. break;
  9413. }
  9414. } else
  9415. SET_FLAGS(flags, MODE_SF);
  9416. #if defined(__LITTLE_ENDIAN)
  9417. SET_FLAGS(flags, MODE_LITTLE_ENDIAN);
  9418. #else /*(__BIG_ENDIAN)*/
  9419. SET_FLAGS(flags, MODE_BIG_ENDIAN);
  9420. #endif
  9421. INIT_MODE_FLAGS(bp) = flags;
  9422. }
  9423. static int bnx2x_init_bp(struct bnx2x *bp)
  9424. {
  9425. int func;
  9426. int rc;
  9427. mutex_init(&bp->port.phy_mutex);
  9428. mutex_init(&bp->fw_mb_mutex);
  9429. spin_lock_init(&bp->stats_lock);
  9430. INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task);
  9431. INIT_DELAYED_WORK(&bp->sp_rtnl_task, bnx2x_sp_rtnl_task);
  9432. INIT_DELAYED_WORK(&bp->period_task, bnx2x_period_task);
  9433. if (IS_PF(bp)) {
  9434. rc = bnx2x_get_hwinfo(bp);
  9435. if (rc)
  9436. return rc;
  9437. } else {
  9438. random_ether_addr(bp->dev->dev_addr);
  9439. }
  9440. bnx2x_set_modes_bitmap(bp);
  9441. rc = bnx2x_alloc_mem_bp(bp);
  9442. if (rc)
  9443. return rc;
  9444. bnx2x_read_fwinfo(bp);
  9445. func = BP_FUNC(bp);
  9446. /* need to reset chip if undi was active */
  9447. if (IS_PF(bp) && !BP_NOMCP(bp)) {
  9448. /* init fw_seq */
  9449. bp->fw_seq =
  9450. SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
  9451. DRV_MSG_SEQ_NUMBER_MASK;
  9452. BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
  9453. bnx2x_prev_unload(bp);
  9454. }
  9455. if (CHIP_REV_IS_FPGA(bp))
  9456. dev_err(&bp->pdev->dev, "FPGA detected\n");
  9457. if (BP_NOMCP(bp) && (func == 0))
  9458. dev_err(&bp->pdev->dev, "MCP disabled, must load devices in order!\n");
  9459. bp->disable_tpa = disable_tpa;
  9460. bp->disable_tpa |= IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp);
  9461. /* Set TPA flags */
  9462. if (bp->disable_tpa) {
  9463. bp->flags &= ~(TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
  9464. bp->dev->features &= ~NETIF_F_LRO;
  9465. } else {
  9466. bp->flags |= (TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
  9467. bp->dev->features |= NETIF_F_LRO;
  9468. }
  9469. if (CHIP_IS_E1(bp))
  9470. bp->dropless_fc = 0;
  9471. else
  9472. bp->dropless_fc = dropless_fc | bnx2x_get_dropless_info(bp);
  9473. bp->mrrs = mrrs;
  9474. bp->tx_ring_size = IS_MF_FCOE_AFEX(bp) ? 0 : MAX_TX_AVAIL;
  9475. if (IS_VF(bp))
  9476. bp->rx_ring_size = MAX_RX_AVAIL;
  9477. /* make sure that the numbers are in the right granularity */
  9478. bp->tx_ticks = (50 / BNX2X_BTR) * BNX2X_BTR;
  9479. bp->rx_ticks = (25 / BNX2X_BTR) * BNX2X_BTR;
  9480. bp->current_interval = CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ;
  9481. init_timer(&bp->timer);
  9482. bp->timer.expires = jiffies + bp->current_interval;
  9483. bp->timer.data = (unsigned long) bp;
  9484. bp->timer.function = bnx2x_timer;
  9485. if (SHMEM2_HAS(bp, dcbx_lldp_params_offset) &&
  9486. SHMEM2_HAS(bp, dcbx_lldp_dcbx_stat_offset) &&
  9487. SHMEM2_RD(bp, dcbx_lldp_params_offset) &&
  9488. SHMEM2_RD(bp, dcbx_lldp_dcbx_stat_offset)) {
  9489. bnx2x_dcbx_set_state(bp, true, BNX2X_DCBX_ENABLED_ON_NEG_ON);
  9490. bnx2x_dcbx_init_params(bp);
  9491. } else {
  9492. bnx2x_dcbx_set_state(bp, false, BNX2X_DCBX_ENABLED_OFF);
  9493. }
  9494. if (CHIP_IS_E1x(bp))
  9495. bp->cnic_base_cl_id = FP_SB_MAX_E1x;
  9496. else
  9497. bp->cnic_base_cl_id = FP_SB_MAX_E2;
  9498. /* multiple tx priority */
  9499. if (IS_VF(bp))
  9500. bp->max_cos = 1;
  9501. else if (CHIP_IS_E1x(bp))
  9502. bp->max_cos = BNX2X_MULTI_TX_COS_E1X;
  9503. else if (CHIP_IS_E2(bp) || CHIP_IS_E3A0(bp))
  9504. bp->max_cos = BNX2X_MULTI_TX_COS_E2_E3A0;
  9505. else if (CHIP_IS_E3B0(bp))
  9506. bp->max_cos = BNX2X_MULTI_TX_COS_E3B0;
  9507. else
  9508. BNX2X_ERR("unknown chip %x revision %x\n",
  9509. CHIP_NUM(bp), CHIP_REV(bp));
  9510. BNX2X_DEV_INFO("set bp->max_cos to %d\n", bp->max_cos);
  9511. /* We need at least one default status block for slow-path events,
  9512. * second status block for the L2 queue, and a third status block for
  9513. * CNIC if supproted.
  9514. */
  9515. if (CNIC_SUPPORT(bp))
  9516. bp->min_msix_vec_cnt = 3;
  9517. else
  9518. bp->min_msix_vec_cnt = 2;
  9519. BNX2X_DEV_INFO("bp->min_msix_vec_cnt %d", bp->min_msix_vec_cnt);
  9520. return rc;
  9521. }
  9522. /****************************************************************************
  9523. * General service functions
  9524. ****************************************************************************/
  9525. /*
  9526. * net_device service functions
  9527. */
  9528. static int bnx2x_open_epilog(struct bnx2x *bp)
  9529. {
  9530. /* Enable sriov via delayed work. This must be done via delayed work
  9531. * because it causes the probe of the vf devices to be run, which invoke
  9532. * register_netdevice which must have rtnl lock taken. As we are holding
  9533. * the lock right now, that could only work if the probe would not take
  9534. * the lock. However, as the probe of the vf may be called from other
  9535. * contexts as well (such as passthrough to vm failes) it can't assume
  9536. * the lock is being held for it. Using delayed work here allows the
  9537. * probe code to simply take the lock (i.e. wait for it to be released
  9538. * if it is being held).
  9539. */
  9540. smp_mb__before_clear_bit();
  9541. set_bit(BNX2X_SP_RTNL_ENABLE_SRIOV, &bp->sp_rtnl_state);
  9542. smp_mb__after_clear_bit();
  9543. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  9544. return 0;
  9545. }
  9546. /* called with rtnl_lock */
  9547. static int bnx2x_open(struct net_device *dev)
  9548. {
  9549. struct bnx2x *bp = netdev_priv(dev);
  9550. bool global = false;
  9551. int other_engine = BP_PATH(bp) ? 0 : 1;
  9552. bool other_load_status, load_status;
  9553. int rc;
  9554. bp->stats_init = true;
  9555. netif_carrier_off(dev);
  9556. bnx2x_set_power_state(bp, PCI_D0);
  9557. /* If parity had happen during the unload, then attentions
  9558. * and/or RECOVERY_IN_PROGRES may still be set. In this case we
  9559. * want the first function loaded on the current engine to
  9560. * complete the recovery.
  9561. * Parity recovery is only relevant for PF driver.
  9562. */
  9563. if (IS_PF(bp)) {
  9564. other_load_status = bnx2x_get_load_status(bp, other_engine);
  9565. load_status = bnx2x_get_load_status(bp, BP_PATH(bp));
  9566. if (!bnx2x_reset_is_done(bp, BP_PATH(bp)) ||
  9567. bnx2x_chk_parity_attn(bp, &global, true)) {
  9568. do {
  9569. /* If there are attentions and they are in a
  9570. * global blocks, set the GLOBAL_RESET bit
  9571. * regardless whether it will be this function
  9572. * that will complete the recovery or not.
  9573. */
  9574. if (global)
  9575. bnx2x_set_reset_global(bp);
  9576. /* Only the first function on the current
  9577. * engine should try to recover in open. In case
  9578. * of attentions in global blocks only the first
  9579. * in the chip should try to recover.
  9580. */
  9581. if ((!load_status &&
  9582. (!global || !other_load_status)) &&
  9583. bnx2x_trylock_leader_lock(bp) &&
  9584. !bnx2x_leader_reset(bp)) {
  9585. netdev_info(bp->dev,
  9586. "Recovered in open\n");
  9587. break;
  9588. }
  9589. /* recovery has failed... */
  9590. bnx2x_set_power_state(bp, PCI_D3hot);
  9591. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  9592. BNX2X_ERR("Recovery flow hasn't been properly completed yet. Try again later.\n"
  9593. "If you still see this message after a few retries then power cycle is required.\n");
  9594. return -EAGAIN;
  9595. } while (0);
  9596. }
  9597. }
  9598. bp->recovery_state = BNX2X_RECOVERY_DONE;
  9599. rc = bnx2x_nic_load(bp, LOAD_OPEN);
  9600. if (rc)
  9601. return rc;
  9602. return bnx2x_open_epilog(bp);
  9603. }
  9604. /* called with rtnl_lock */
  9605. static int bnx2x_close(struct net_device *dev)
  9606. {
  9607. struct bnx2x *bp = netdev_priv(dev);
  9608. /* Unload the driver, release IRQs */
  9609. bnx2x_nic_unload(bp, UNLOAD_CLOSE, false);
  9610. /* Power off */
  9611. bnx2x_set_power_state(bp, PCI_D3hot);
  9612. return 0;
  9613. }
  9614. static int bnx2x_init_mcast_macs_list(struct bnx2x *bp,
  9615. struct bnx2x_mcast_ramrod_params *p)
  9616. {
  9617. int mc_count = netdev_mc_count(bp->dev);
  9618. struct bnx2x_mcast_list_elem *mc_mac =
  9619. kzalloc(sizeof(*mc_mac) * mc_count, GFP_ATOMIC);
  9620. struct netdev_hw_addr *ha;
  9621. if (!mc_mac)
  9622. return -ENOMEM;
  9623. INIT_LIST_HEAD(&p->mcast_list);
  9624. netdev_for_each_mc_addr(ha, bp->dev) {
  9625. mc_mac->mac = bnx2x_mc_addr(ha);
  9626. list_add_tail(&mc_mac->link, &p->mcast_list);
  9627. mc_mac++;
  9628. }
  9629. p->mcast_list_len = mc_count;
  9630. return 0;
  9631. }
  9632. static void bnx2x_free_mcast_macs_list(
  9633. struct bnx2x_mcast_ramrod_params *p)
  9634. {
  9635. struct bnx2x_mcast_list_elem *mc_mac =
  9636. list_first_entry(&p->mcast_list, struct bnx2x_mcast_list_elem,
  9637. link);
  9638. WARN_ON(!mc_mac);
  9639. kfree(mc_mac);
  9640. }
  9641. /**
  9642. * bnx2x_set_uc_list - configure a new unicast MACs list.
  9643. *
  9644. * @bp: driver handle
  9645. *
  9646. * We will use zero (0) as a MAC type for these MACs.
  9647. */
  9648. static int bnx2x_set_uc_list(struct bnx2x *bp)
  9649. {
  9650. int rc;
  9651. struct net_device *dev = bp->dev;
  9652. struct netdev_hw_addr *ha;
  9653. struct bnx2x_vlan_mac_obj *mac_obj = &bp->sp_objs->mac_obj;
  9654. unsigned long ramrod_flags = 0;
  9655. /* First schedule a cleanup up of old configuration */
  9656. rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, false);
  9657. if (rc < 0) {
  9658. BNX2X_ERR("Failed to schedule DELETE operations: %d\n", rc);
  9659. return rc;
  9660. }
  9661. netdev_for_each_uc_addr(ha, dev) {
  9662. rc = bnx2x_set_mac_one(bp, bnx2x_uc_addr(ha), mac_obj, true,
  9663. BNX2X_UC_LIST_MAC, &ramrod_flags);
  9664. if (rc == -EEXIST) {
  9665. DP(BNX2X_MSG_SP,
  9666. "Failed to schedule ADD operations: %d\n", rc);
  9667. /* do not treat adding same MAC as error */
  9668. rc = 0;
  9669. } else if (rc < 0) {
  9670. BNX2X_ERR("Failed to schedule ADD operations: %d\n",
  9671. rc);
  9672. return rc;
  9673. }
  9674. }
  9675. /* Execute the pending commands */
  9676. __set_bit(RAMROD_CONT, &ramrod_flags);
  9677. return bnx2x_set_mac_one(bp, NULL, mac_obj, false /* don't care */,
  9678. BNX2X_UC_LIST_MAC, &ramrod_flags);
  9679. }
  9680. static int bnx2x_set_mc_list(struct bnx2x *bp)
  9681. {
  9682. struct net_device *dev = bp->dev;
  9683. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  9684. int rc = 0;
  9685. rparam.mcast_obj = &bp->mcast_obj;
  9686. /* first, clear all configured multicast MACs */
  9687. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  9688. if (rc < 0) {
  9689. BNX2X_ERR("Failed to clear multicast configuration: %d\n", rc);
  9690. return rc;
  9691. }
  9692. /* then, configure a new MACs list */
  9693. if (netdev_mc_count(dev)) {
  9694. rc = bnx2x_init_mcast_macs_list(bp, &rparam);
  9695. if (rc) {
  9696. BNX2X_ERR("Failed to create multicast MACs list: %d\n",
  9697. rc);
  9698. return rc;
  9699. }
  9700. /* Now add the new MACs */
  9701. rc = bnx2x_config_mcast(bp, &rparam,
  9702. BNX2X_MCAST_CMD_ADD);
  9703. if (rc < 0)
  9704. BNX2X_ERR("Failed to set a new multicast configuration: %d\n",
  9705. rc);
  9706. bnx2x_free_mcast_macs_list(&rparam);
  9707. }
  9708. return rc;
  9709. }
  9710. /* If bp->state is OPEN, should be called with netif_addr_lock_bh() */
  9711. void bnx2x_set_rx_mode(struct net_device *dev)
  9712. {
  9713. struct bnx2x *bp = netdev_priv(dev);
  9714. u32 rx_mode = BNX2X_RX_MODE_NORMAL;
  9715. if (bp->state != BNX2X_STATE_OPEN) {
  9716. DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
  9717. return;
  9718. }
  9719. DP(NETIF_MSG_IFUP, "dev->flags = %x\n", bp->dev->flags);
  9720. if (dev->flags & IFF_PROMISC)
  9721. rx_mode = BNX2X_RX_MODE_PROMISC;
  9722. else if ((dev->flags & IFF_ALLMULTI) ||
  9723. ((netdev_mc_count(dev) > BNX2X_MAX_MULTICAST) &&
  9724. CHIP_IS_E1(bp)))
  9725. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  9726. else {
  9727. if (IS_PF(bp)) {
  9728. /* some multicasts */
  9729. if (bnx2x_set_mc_list(bp) < 0)
  9730. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  9731. if (bnx2x_set_uc_list(bp) < 0)
  9732. rx_mode = BNX2X_RX_MODE_PROMISC;
  9733. } else {
  9734. /* configuring mcast to a vf involves sleeping (when we
  9735. * wait for the pf's response). Since this function is
  9736. * called from non sleepable context we must schedule
  9737. * a work item for this purpose
  9738. */
  9739. smp_mb__before_clear_bit();
  9740. set_bit(BNX2X_SP_RTNL_VFPF_MCAST,
  9741. &bp->sp_rtnl_state);
  9742. smp_mb__after_clear_bit();
  9743. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  9744. }
  9745. }
  9746. bp->rx_mode = rx_mode;
  9747. /* handle ISCSI SD mode */
  9748. if (IS_MF_ISCSI_SD(bp))
  9749. bp->rx_mode = BNX2X_RX_MODE_NONE;
  9750. /* Schedule the rx_mode command */
  9751. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) {
  9752. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  9753. return;
  9754. }
  9755. if (IS_PF(bp)) {
  9756. bnx2x_set_storm_rx_mode(bp);
  9757. } else {
  9758. /* configuring rx mode to storms in a vf involves sleeping (when
  9759. * we wait for the pf's response). Since this function is
  9760. * called from non sleepable context we must schedule
  9761. * a work item for this purpose
  9762. */
  9763. smp_mb__before_clear_bit();
  9764. set_bit(BNX2X_SP_RTNL_VFPF_STORM_RX_MODE,
  9765. &bp->sp_rtnl_state);
  9766. smp_mb__after_clear_bit();
  9767. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  9768. }
  9769. }
  9770. /* called with rtnl_lock */
  9771. static int bnx2x_mdio_read(struct net_device *netdev, int prtad,
  9772. int devad, u16 addr)
  9773. {
  9774. struct bnx2x *bp = netdev_priv(netdev);
  9775. u16 value;
  9776. int rc;
  9777. DP(NETIF_MSG_LINK, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n",
  9778. prtad, devad, addr);
  9779. /* The HW expects different devad if CL22 is used */
  9780. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  9781. bnx2x_acquire_phy_lock(bp);
  9782. rc = bnx2x_phy_read(&bp->link_params, prtad, devad, addr, &value);
  9783. bnx2x_release_phy_lock(bp);
  9784. DP(NETIF_MSG_LINK, "mdio_read_val 0x%x rc = 0x%x\n", value, rc);
  9785. if (!rc)
  9786. rc = value;
  9787. return rc;
  9788. }
  9789. /* called with rtnl_lock */
  9790. static int bnx2x_mdio_write(struct net_device *netdev, int prtad, int devad,
  9791. u16 addr, u16 value)
  9792. {
  9793. struct bnx2x *bp = netdev_priv(netdev);
  9794. int rc;
  9795. DP(NETIF_MSG_LINK,
  9796. "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x, value 0x%x\n",
  9797. prtad, devad, addr, value);
  9798. /* The HW expects different devad if CL22 is used */
  9799. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  9800. bnx2x_acquire_phy_lock(bp);
  9801. rc = bnx2x_phy_write(&bp->link_params, prtad, devad, addr, value);
  9802. bnx2x_release_phy_lock(bp);
  9803. return rc;
  9804. }
  9805. /* called with rtnl_lock */
  9806. static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  9807. {
  9808. struct bnx2x *bp = netdev_priv(dev);
  9809. struct mii_ioctl_data *mdio = if_mii(ifr);
  9810. DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n",
  9811. mdio->phy_id, mdio->reg_num, mdio->val_in);
  9812. if (!netif_running(dev))
  9813. return -EAGAIN;
  9814. return mdio_mii_ioctl(&bp->mdio, mdio, cmd);
  9815. }
  9816. #ifdef CONFIG_NET_POLL_CONTROLLER
  9817. static void poll_bnx2x(struct net_device *dev)
  9818. {
  9819. struct bnx2x *bp = netdev_priv(dev);
  9820. int i;
  9821. for_each_eth_queue(bp, i) {
  9822. struct bnx2x_fastpath *fp = &bp->fp[i];
  9823. napi_schedule(&bnx2x_fp(bp, fp->index, napi));
  9824. }
  9825. }
  9826. #endif
  9827. static int bnx2x_validate_addr(struct net_device *dev)
  9828. {
  9829. struct bnx2x *bp = netdev_priv(dev);
  9830. if (!bnx2x_is_valid_ether_addr(bp, dev->dev_addr)) {
  9831. BNX2X_ERR("Non-valid Ethernet address\n");
  9832. return -EADDRNOTAVAIL;
  9833. }
  9834. return 0;
  9835. }
  9836. static const struct net_device_ops bnx2x_netdev_ops = {
  9837. .ndo_open = bnx2x_open,
  9838. .ndo_stop = bnx2x_close,
  9839. .ndo_start_xmit = bnx2x_start_xmit,
  9840. .ndo_select_queue = bnx2x_select_queue,
  9841. .ndo_set_rx_mode = bnx2x_set_rx_mode,
  9842. .ndo_set_mac_address = bnx2x_change_mac_addr,
  9843. .ndo_validate_addr = bnx2x_validate_addr,
  9844. .ndo_do_ioctl = bnx2x_ioctl,
  9845. .ndo_change_mtu = bnx2x_change_mtu,
  9846. .ndo_fix_features = bnx2x_fix_features,
  9847. .ndo_set_features = bnx2x_set_features,
  9848. .ndo_tx_timeout = bnx2x_tx_timeout,
  9849. #ifdef CONFIG_NET_POLL_CONTROLLER
  9850. .ndo_poll_controller = poll_bnx2x,
  9851. #endif
  9852. .ndo_setup_tc = bnx2x_setup_tc,
  9853. #ifdef CONFIG_BNX2X_SRIOV
  9854. .ndo_set_vf_mac = bnx2x_set_vf_mac,
  9855. #endif
  9856. #ifdef NETDEV_FCOE_WWNN
  9857. .ndo_fcoe_get_wwn = bnx2x_fcoe_get_wwn,
  9858. #endif
  9859. };
  9860. static int bnx2x_set_coherency_mask(struct bnx2x *bp)
  9861. {
  9862. struct device *dev = &bp->pdev->dev;
  9863. if (dma_set_mask(dev, DMA_BIT_MASK(64)) == 0) {
  9864. bp->flags |= USING_DAC_FLAG;
  9865. if (dma_set_coherent_mask(dev, DMA_BIT_MASK(64)) != 0) {
  9866. dev_err(dev, "dma_set_coherent_mask failed, aborting\n");
  9867. return -EIO;
  9868. }
  9869. } else if (dma_set_mask(dev, DMA_BIT_MASK(32)) != 0) {
  9870. dev_err(dev, "System does not support DMA, aborting\n");
  9871. return -EIO;
  9872. }
  9873. return 0;
  9874. }
  9875. static int bnx2x_init_dev(struct bnx2x *bp, struct pci_dev *pdev,
  9876. struct net_device *dev, unsigned long board_type)
  9877. {
  9878. int rc;
  9879. u32 pci_cfg_dword;
  9880. bool chip_is_e1x = (board_type == BCM57710 ||
  9881. board_type == BCM57711 ||
  9882. board_type == BCM57711E);
  9883. SET_NETDEV_DEV(dev, &pdev->dev);
  9884. bp->dev = dev;
  9885. bp->pdev = pdev;
  9886. rc = pci_enable_device(pdev);
  9887. if (rc) {
  9888. dev_err(&bp->pdev->dev,
  9889. "Cannot enable PCI device, aborting\n");
  9890. goto err_out;
  9891. }
  9892. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  9893. dev_err(&bp->pdev->dev,
  9894. "Cannot find PCI device base address, aborting\n");
  9895. rc = -ENODEV;
  9896. goto err_out_disable;
  9897. }
  9898. if (IS_PF(bp) && !(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
  9899. dev_err(&bp->pdev->dev, "Cannot find second PCI device base address, aborting\n");
  9900. rc = -ENODEV;
  9901. goto err_out_disable;
  9902. }
  9903. pci_read_config_dword(pdev, PCICFG_REVISION_ID_OFFSET, &pci_cfg_dword);
  9904. if ((pci_cfg_dword & PCICFG_REVESION_ID_MASK) ==
  9905. PCICFG_REVESION_ID_ERROR_VAL) {
  9906. pr_err("PCI device error, probably due to fan failure, aborting\n");
  9907. rc = -ENODEV;
  9908. goto err_out_disable;
  9909. }
  9910. if (atomic_read(&pdev->enable_cnt) == 1) {
  9911. rc = pci_request_regions(pdev, DRV_MODULE_NAME);
  9912. if (rc) {
  9913. dev_err(&bp->pdev->dev,
  9914. "Cannot obtain PCI resources, aborting\n");
  9915. goto err_out_disable;
  9916. }
  9917. pci_set_master(pdev);
  9918. pci_save_state(pdev);
  9919. }
  9920. if (IS_PF(bp)) {
  9921. bp->pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
  9922. if (bp->pm_cap == 0) {
  9923. dev_err(&bp->pdev->dev,
  9924. "Cannot find power management capability, aborting\n");
  9925. rc = -EIO;
  9926. goto err_out_release;
  9927. }
  9928. }
  9929. if (!pci_is_pcie(pdev)) {
  9930. dev_err(&bp->pdev->dev, "Not PCI Express, aborting\n");
  9931. rc = -EIO;
  9932. goto err_out_release;
  9933. }
  9934. rc = bnx2x_set_coherency_mask(bp);
  9935. if (rc)
  9936. goto err_out_release;
  9937. dev->mem_start = pci_resource_start(pdev, 0);
  9938. dev->base_addr = dev->mem_start;
  9939. dev->mem_end = pci_resource_end(pdev, 0);
  9940. dev->irq = pdev->irq;
  9941. bp->regview = pci_ioremap_bar(pdev, 0);
  9942. if (!bp->regview) {
  9943. dev_err(&bp->pdev->dev,
  9944. "Cannot map register space, aborting\n");
  9945. rc = -ENOMEM;
  9946. goto err_out_release;
  9947. }
  9948. /* In E1/E1H use pci device function given by kernel.
  9949. * In E2/E3 read physical function from ME register since these chips
  9950. * support Physical Device Assignment where kernel BDF maybe arbitrary
  9951. * (depending on hypervisor).
  9952. */
  9953. if (chip_is_e1x) {
  9954. bp->pf_num = PCI_FUNC(pdev->devfn);
  9955. } else {
  9956. /* chip is E2/3*/
  9957. pci_read_config_dword(bp->pdev,
  9958. PCICFG_ME_REGISTER, &pci_cfg_dword);
  9959. bp->pf_num = (u8)((pci_cfg_dword & ME_REG_ABS_PF_NUM) >>
  9960. ME_REG_ABS_PF_NUM_SHIFT);
  9961. }
  9962. BNX2X_DEV_INFO("me reg PF num: %d\n", bp->pf_num);
  9963. bnx2x_set_power_state(bp, PCI_D0);
  9964. /* clean indirect addresses */
  9965. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  9966. PCICFG_VENDOR_ID_OFFSET);
  9967. /*
  9968. * Clean the following indirect addresses for all functions since it
  9969. * is not used by the driver.
  9970. */
  9971. if (IS_PF(bp)) {
  9972. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0, 0);
  9973. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0, 0);
  9974. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0, 0);
  9975. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0, 0);
  9976. if (chip_is_e1x) {
  9977. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F1, 0);
  9978. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F1, 0);
  9979. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F1, 0);
  9980. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F1, 0);
  9981. }
  9982. /* Enable internal target-read (in case we are probed after PF
  9983. * FLR). Must be done prior to any BAR read access. Only for
  9984. * 57712 and up
  9985. */
  9986. if (!chip_is_e1x)
  9987. REG_WR(bp,
  9988. PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  9989. }
  9990. dev->watchdog_timeo = TX_TIMEOUT;
  9991. dev->netdev_ops = &bnx2x_netdev_ops;
  9992. bnx2x_set_ethtool_ops(dev);
  9993. dev->priv_flags |= IFF_UNICAST_FLT;
  9994. dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  9995. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
  9996. NETIF_F_RXCSUM | NETIF_F_LRO | NETIF_F_GRO |
  9997. NETIF_F_RXHASH | NETIF_F_HW_VLAN_TX;
  9998. dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  9999. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_HIGHDMA;
  10000. dev->features |= dev->hw_features | NETIF_F_HW_VLAN_RX;
  10001. if (bp->flags & USING_DAC_FLAG)
  10002. dev->features |= NETIF_F_HIGHDMA;
  10003. /* Add Loopback capability to the device */
  10004. dev->hw_features |= NETIF_F_LOOPBACK;
  10005. #ifdef BCM_DCBNL
  10006. dev->dcbnl_ops = &bnx2x_dcbnl_ops;
  10007. #endif
  10008. /* get_port_hwinfo() will set prtad and mmds properly */
  10009. bp->mdio.prtad = MDIO_PRTAD_NONE;
  10010. bp->mdio.mmds = 0;
  10011. bp->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
  10012. bp->mdio.dev = dev;
  10013. bp->mdio.mdio_read = bnx2x_mdio_read;
  10014. bp->mdio.mdio_write = bnx2x_mdio_write;
  10015. return 0;
  10016. err_out_release:
  10017. if (atomic_read(&pdev->enable_cnt) == 1)
  10018. pci_release_regions(pdev);
  10019. err_out_disable:
  10020. pci_disable_device(pdev);
  10021. pci_set_drvdata(pdev, NULL);
  10022. err_out:
  10023. return rc;
  10024. }
  10025. static void bnx2x_get_pcie_width_speed(struct bnx2x *bp, int *width, int *speed)
  10026. {
  10027. u32 val = 0;
  10028. pci_read_config_dword(bp->pdev, PCICFG_LINK_CONTROL, &val);
  10029. *width = (val & PCICFG_LINK_WIDTH) >> PCICFG_LINK_WIDTH_SHIFT;
  10030. /* return value of 1=2.5GHz 2=5GHz */
  10031. *speed = (val & PCICFG_LINK_SPEED) >> PCICFG_LINK_SPEED_SHIFT;
  10032. }
  10033. static int bnx2x_check_firmware(struct bnx2x *bp)
  10034. {
  10035. const struct firmware *firmware = bp->firmware;
  10036. struct bnx2x_fw_file_hdr *fw_hdr;
  10037. struct bnx2x_fw_file_section *sections;
  10038. u32 offset, len, num_ops;
  10039. u16 *ops_offsets;
  10040. int i;
  10041. const u8 *fw_ver;
  10042. if (firmware->size < sizeof(struct bnx2x_fw_file_hdr)) {
  10043. BNX2X_ERR("Wrong FW size\n");
  10044. return -EINVAL;
  10045. }
  10046. fw_hdr = (struct bnx2x_fw_file_hdr *)firmware->data;
  10047. sections = (struct bnx2x_fw_file_section *)fw_hdr;
  10048. /* Make sure none of the offsets and sizes make us read beyond
  10049. * the end of the firmware data */
  10050. for (i = 0; i < sizeof(*fw_hdr) / sizeof(*sections); i++) {
  10051. offset = be32_to_cpu(sections[i].offset);
  10052. len = be32_to_cpu(sections[i].len);
  10053. if (offset + len > firmware->size) {
  10054. BNX2X_ERR("Section %d length is out of bounds\n", i);
  10055. return -EINVAL;
  10056. }
  10057. }
  10058. /* Likewise for the init_ops offsets */
  10059. offset = be32_to_cpu(fw_hdr->init_ops_offsets.offset);
  10060. ops_offsets = (u16 *)(firmware->data + offset);
  10061. num_ops = be32_to_cpu(fw_hdr->init_ops.len) / sizeof(struct raw_op);
  10062. for (i = 0; i < be32_to_cpu(fw_hdr->init_ops_offsets.len) / 2; i++) {
  10063. if (be16_to_cpu(ops_offsets[i]) > num_ops) {
  10064. BNX2X_ERR("Section offset %d is out of bounds\n", i);
  10065. return -EINVAL;
  10066. }
  10067. }
  10068. /* Check FW version */
  10069. offset = be32_to_cpu(fw_hdr->fw_version.offset);
  10070. fw_ver = firmware->data + offset;
  10071. if ((fw_ver[0] != BCM_5710_FW_MAJOR_VERSION) ||
  10072. (fw_ver[1] != BCM_5710_FW_MINOR_VERSION) ||
  10073. (fw_ver[2] != BCM_5710_FW_REVISION_VERSION) ||
  10074. (fw_ver[3] != BCM_5710_FW_ENGINEERING_VERSION)) {
  10075. BNX2X_ERR("Bad FW version:%d.%d.%d.%d. Should be %d.%d.%d.%d\n",
  10076. fw_ver[0], fw_ver[1], fw_ver[2], fw_ver[3],
  10077. BCM_5710_FW_MAJOR_VERSION,
  10078. BCM_5710_FW_MINOR_VERSION,
  10079. BCM_5710_FW_REVISION_VERSION,
  10080. BCM_5710_FW_ENGINEERING_VERSION);
  10081. return -EINVAL;
  10082. }
  10083. return 0;
  10084. }
  10085. static void be32_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  10086. {
  10087. const __be32 *source = (const __be32 *)_source;
  10088. u32 *target = (u32 *)_target;
  10089. u32 i;
  10090. for (i = 0; i < n/4; i++)
  10091. target[i] = be32_to_cpu(source[i]);
  10092. }
  10093. /*
  10094. Ops array is stored in the following format:
  10095. {op(8bit), offset(24bit, big endian), data(32bit, big endian)}
  10096. */
  10097. static void bnx2x_prep_ops(const u8 *_source, u8 *_target, u32 n)
  10098. {
  10099. const __be32 *source = (const __be32 *)_source;
  10100. struct raw_op *target = (struct raw_op *)_target;
  10101. u32 i, j, tmp;
  10102. for (i = 0, j = 0; i < n/8; i++, j += 2) {
  10103. tmp = be32_to_cpu(source[j]);
  10104. target[i].op = (tmp >> 24) & 0xff;
  10105. target[i].offset = tmp & 0xffffff;
  10106. target[i].raw_data = be32_to_cpu(source[j + 1]);
  10107. }
  10108. }
  10109. /* IRO array is stored in the following format:
  10110. * {base(24bit), m1(16bit), m2(16bit), m3(16bit), size(16bit) }
  10111. */
  10112. static void bnx2x_prep_iro(const u8 *_source, u8 *_target, u32 n)
  10113. {
  10114. const __be32 *source = (const __be32 *)_source;
  10115. struct iro *target = (struct iro *)_target;
  10116. u32 i, j, tmp;
  10117. for (i = 0, j = 0; i < n/sizeof(struct iro); i++) {
  10118. target[i].base = be32_to_cpu(source[j]);
  10119. j++;
  10120. tmp = be32_to_cpu(source[j]);
  10121. target[i].m1 = (tmp >> 16) & 0xffff;
  10122. target[i].m2 = tmp & 0xffff;
  10123. j++;
  10124. tmp = be32_to_cpu(source[j]);
  10125. target[i].m3 = (tmp >> 16) & 0xffff;
  10126. target[i].size = tmp & 0xffff;
  10127. j++;
  10128. }
  10129. }
  10130. static void be16_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  10131. {
  10132. const __be16 *source = (const __be16 *)_source;
  10133. u16 *target = (u16 *)_target;
  10134. u32 i;
  10135. for (i = 0; i < n/2; i++)
  10136. target[i] = be16_to_cpu(source[i]);
  10137. }
  10138. #define BNX2X_ALLOC_AND_SET(arr, lbl, func) \
  10139. do { \
  10140. u32 len = be32_to_cpu(fw_hdr->arr.len); \
  10141. bp->arr = kmalloc(len, GFP_KERNEL); \
  10142. if (!bp->arr) \
  10143. goto lbl; \
  10144. func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \
  10145. (u8 *)bp->arr, len); \
  10146. } while (0)
  10147. static int bnx2x_init_firmware(struct bnx2x *bp)
  10148. {
  10149. const char *fw_file_name;
  10150. struct bnx2x_fw_file_hdr *fw_hdr;
  10151. int rc;
  10152. if (bp->firmware)
  10153. return 0;
  10154. if (CHIP_IS_E1(bp))
  10155. fw_file_name = FW_FILE_NAME_E1;
  10156. else if (CHIP_IS_E1H(bp))
  10157. fw_file_name = FW_FILE_NAME_E1H;
  10158. else if (!CHIP_IS_E1x(bp))
  10159. fw_file_name = FW_FILE_NAME_E2;
  10160. else {
  10161. BNX2X_ERR("Unsupported chip revision\n");
  10162. return -EINVAL;
  10163. }
  10164. BNX2X_DEV_INFO("Loading %s\n", fw_file_name);
  10165. rc = request_firmware(&bp->firmware, fw_file_name, &bp->pdev->dev);
  10166. if (rc) {
  10167. BNX2X_ERR("Can't load firmware file %s\n",
  10168. fw_file_name);
  10169. goto request_firmware_exit;
  10170. }
  10171. rc = bnx2x_check_firmware(bp);
  10172. if (rc) {
  10173. BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name);
  10174. goto request_firmware_exit;
  10175. }
  10176. fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data;
  10177. /* Initialize the pointers to the init arrays */
  10178. /* Blob */
  10179. BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n);
  10180. /* Opcodes */
  10181. BNX2X_ALLOC_AND_SET(init_ops, init_ops_alloc_err, bnx2x_prep_ops);
  10182. /* Offsets */
  10183. BNX2X_ALLOC_AND_SET(init_ops_offsets, init_offsets_alloc_err,
  10184. be16_to_cpu_n);
  10185. /* STORMs firmware */
  10186. INIT_TSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10187. be32_to_cpu(fw_hdr->tsem_int_table_data.offset);
  10188. INIT_TSEM_PRAM_DATA(bp) = bp->firmware->data +
  10189. be32_to_cpu(fw_hdr->tsem_pram_data.offset);
  10190. INIT_USEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10191. be32_to_cpu(fw_hdr->usem_int_table_data.offset);
  10192. INIT_USEM_PRAM_DATA(bp) = bp->firmware->data +
  10193. be32_to_cpu(fw_hdr->usem_pram_data.offset);
  10194. INIT_XSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10195. be32_to_cpu(fw_hdr->xsem_int_table_data.offset);
  10196. INIT_XSEM_PRAM_DATA(bp) = bp->firmware->data +
  10197. be32_to_cpu(fw_hdr->xsem_pram_data.offset);
  10198. INIT_CSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10199. be32_to_cpu(fw_hdr->csem_int_table_data.offset);
  10200. INIT_CSEM_PRAM_DATA(bp) = bp->firmware->data +
  10201. be32_to_cpu(fw_hdr->csem_pram_data.offset);
  10202. /* IRO */
  10203. BNX2X_ALLOC_AND_SET(iro_arr, iro_alloc_err, bnx2x_prep_iro);
  10204. return 0;
  10205. iro_alloc_err:
  10206. kfree(bp->init_ops_offsets);
  10207. init_offsets_alloc_err:
  10208. kfree(bp->init_ops);
  10209. init_ops_alloc_err:
  10210. kfree(bp->init_data);
  10211. request_firmware_exit:
  10212. release_firmware(bp->firmware);
  10213. bp->firmware = NULL;
  10214. return rc;
  10215. }
  10216. static void bnx2x_release_firmware(struct bnx2x *bp)
  10217. {
  10218. kfree(bp->init_ops_offsets);
  10219. kfree(bp->init_ops);
  10220. kfree(bp->init_data);
  10221. release_firmware(bp->firmware);
  10222. bp->firmware = NULL;
  10223. }
  10224. static struct bnx2x_func_sp_drv_ops bnx2x_func_sp_drv = {
  10225. .init_hw_cmn_chip = bnx2x_init_hw_common_chip,
  10226. .init_hw_cmn = bnx2x_init_hw_common,
  10227. .init_hw_port = bnx2x_init_hw_port,
  10228. .init_hw_func = bnx2x_init_hw_func,
  10229. .reset_hw_cmn = bnx2x_reset_common,
  10230. .reset_hw_port = bnx2x_reset_port,
  10231. .reset_hw_func = bnx2x_reset_func,
  10232. .gunzip_init = bnx2x_gunzip_init,
  10233. .gunzip_end = bnx2x_gunzip_end,
  10234. .init_fw = bnx2x_init_firmware,
  10235. .release_fw = bnx2x_release_firmware,
  10236. };
  10237. void bnx2x__init_func_obj(struct bnx2x *bp)
  10238. {
  10239. /* Prepare DMAE related driver resources */
  10240. bnx2x_setup_dmae(bp);
  10241. bnx2x_init_func_obj(bp, &bp->func_obj,
  10242. bnx2x_sp(bp, func_rdata),
  10243. bnx2x_sp_mapping(bp, func_rdata),
  10244. bnx2x_sp(bp, func_afex_rdata),
  10245. bnx2x_sp_mapping(bp, func_afex_rdata),
  10246. &bnx2x_func_sp_drv);
  10247. }
  10248. /* must be called after sriov-enable */
  10249. static int bnx2x_set_qm_cid_count(struct bnx2x *bp)
  10250. {
  10251. int cid_count = BNX2X_L2_MAX_CID(bp);
  10252. if (IS_SRIOV(bp))
  10253. cid_count += BNX2X_VF_CIDS;
  10254. if (CNIC_SUPPORT(bp))
  10255. cid_count += CNIC_CID_MAX;
  10256. return roundup(cid_count, QM_CID_ROUND);
  10257. }
  10258. /**
  10259. * bnx2x_get_num_none_def_sbs - return the number of none default SBs
  10260. *
  10261. * @dev: pci device
  10262. *
  10263. */
  10264. static int bnx2x_get_num_non_def_sbs(struct pci_dev *pdev,
  10265. int cnic_cnt, bool is_vf)
  10266. {
  10267. int pos, index;
  10268. u16 control = 0;
  10269. pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
  10270. /*
  10271. * If MSI-X is not supported - return number of SBs needed to support
  10272. * one fast path queue: one FP queue + SB for CNIC
  10273. */
  10274. if (!pos) {
  10275. dev_info(&pdev->dev, "no msix capability found\n");
  10276. return 1 + cnic_cnt;
  10277. }
  10278. dev_info(&pdev->dev, "msix capability found\n");
  10279. /*
  10280. * The value in the PCI configuration space is the index of the last
  10281. * entry, namely one less than the actual size of the table, which is
  10282. * exactly what we want to return from this function: number of all SBs
  10283. * without the default SB.
  10284. * For VFs there is no default SB, then we return (index+1).
  10285. */
  10286. pci_read_config_word(pdev, pos + PCI_MSI_FLAGS, &control);
  10287. index = control & PCI_MSIX_FLAGS_QSIZE;
  10288. return is_vf ? index + 1 : index;
  10289. }
  10290. static int set_max_cos_est(int chip_id)
  10291. {
  10292. switch (chip_id) {
  10293. case BCM57710:
  10294. case BCM57711:
  10295. case BCM57711E:
  10296. return BNX2X_MULTI_TX_COS_E1X;
  10297. case BCM57712:
  10298. case BCM57712_MF:
  10299. case BCM57712_VF:
  10300. return BNX2X_MULTI_TX_COS_E2_E3A0;
  10301. case BCM57800:
  10302. case BCM57800_MF:
  10303. case BCM57800_VF:
  10304. case BCM57810:
  10305. case BCM57810_MF:
  10306. case BCM57840_4_10:
  10307. case BCM57840_2_20:
  10308. case BCM57840_O:
  10309. case BCM57840_MFO:
  10310. case BCM57810_VF:
  10311. case BCM57840_MF:
  10312. case BCM57840_VF:
  10313. case BCM57811:
  10314. case BCM57811_MF:
  10315. case BCM57811_VF:
  10316. return BNX2X_MULTI_TX_COS_E3B0;
  10317. return 1;
  10318. default:
  10319. pr_err("Unknown board_type (%d), aborting\n", chip_id);
  10320. return -ENODEV;
  10321. }
  10322. }
  10323. static int set_is_vf(int chip_id)
  10324. {
  10325. switch (chip_id) {
  10326. case BCM57712_VF:
  10327. case BCM57800_VF:
  10328. case BCM57810_VF:
  10329. case BCM57840_VF:
  10330. case BCM57811_VF:
  10331. return true;
  10332. default:
  10333. return false;
  10334. }
  10335. }
  10336. struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev);
  10337. static int bnx2x_init_one(struct pci_dev *pdev,
  10338. const struct pci_device_id *ent)
  10339. {
  10340. struct net_device *dev = NULL;
  10341. struct bnx2x *bp;
  10342. int pcie_width, pcie_speed;
  10343. int rc, max_non_def_sbs;
  10344. int rx_count, tx_count, rss_count, doorbell_size;
  10345. int max_cos_est;
  10346. bool is_vf;
  10347. int cnic_cnt;
  10348. /* An estimated maximum supported CoS number according to the chip
  10349. * version.
  10350. * We will try to roughly estimate the maximum number of CoSes this chip
  10351. * may support in order to minimize the memory allocated for Tx
  10352. * netdev_queue's. This number will be accurately calculated during the
  10353. * initialization of bp->max_cos based on the chip versions AND chip
  10354. * revision in the bnx2x_init_bp().
  10355. */
  10356. max_cos_est = set_max_cos_est(ent->driver_data);
  10357. if (max_cos_est < 0)
  10358. return max_cos_est;
  10359. is_vf = set_is_vf(ent->driver_data);
  10360. cnic_cnt = is_vf ? 0 : 1;
  10361. max_non_def_sbs = bnx2x_get_num_non_def_sbs(pdev, cnic_cnt, is_vf);
  10362. /* Maximum number of RSS queues: one IGU SB goes to CNIC */
  10363. rss_count = is_vf ? 1 : max_non_def_sbs - cnic_cnt;
  10364. if (rss_count < 1)
  10365. return -EINVAL;
  10366. /* Maximum number of netdev Rx queues: RSS + FCoE L2 */
  10367. rx_count = rss_count + cnic_cnt;
  10368. /* Maximum number of netdev Tx queues:
  10369. * Maximum TSS queues * Maximum supported number of CoS + FCoE L2
  10370. */
  10371. tx_count = rss_count * max_cos_est + cnic_cnt;
  10372. /* dev zeroed in init_etherdev */
  10373. dev = alloc_etherdev_mqs(sizeof(*bp), tx_count, rx_count);
  10374. if (!dev)
  10375. return -ENOMEM;
  10376. bp = netdev_priv(dev);
  10377. bp->flags = 0;
  10378. if (is_vf)
  10379. bp->flags |= IS_VF_FLAG;
  10380. bp->igu_sb_cnt = max_non_def_sbs;
  10381. bp->igu_base_addr = IS_VF(bp) ? PXP_VF_ADDR_IGU_START : BAR_IGU_INTMEM;
  10382. bp->msg_enable = debug;
  10383. bp->cnic_support = cnic_cnt;
  10384. bp->cnic_probe = bnx2x_cnic_probe;
  10385. pci_set_drvdata(pdev, dev);
  10386. rc = bnx2x_init_dev(bp, pdev, dev, ent->driver_data);
  10387. if (rc < 0) {
  10388. free_netdev(dev);
  10389. return rc;
  10390. }
  10391. BNX2X_DEV_INFO("This is a %s function\n",
  10392. IS_PF(bp) ? "physical" : "virtual");
  10393. BNX2X_DEV_INFO("Cnic support is %s\n", CNIC_SUPPORT(bp) ? "on" : "off");
  10394. BNX2X_DEV_INFO("Max num of status blocks %d\n", max_non_def_sbs);
  10395. BNX2X_DEV_INFO("Allocated netdev with %d tx and %d rx queues\n",
  10396. tx_count, rx_count);
  10397. rc = bnx2x_init_bp(bp);
  10398. if (rc)
  10399. goto init_one_exit;
  10400. /* Map doorbells here as we need the real value of bp->max_cos which
  10401. * is initialized in bnx2x_init_bp() to determine the number of
  10402. * l2 connections.
  10403. */
  10404. if (IS_VF(bp)) {
  10405. bnx2x_vf_map_doorbells(bp);
  10406. rc = bnx2x_vf_pci_alloc(bp);
  10407. if (rc)
  10408. goto init_one_exit;
  10409. } else {
  10410. doorbell_size = BNX2X_L2_MAX_CID(bp) * (1 << BNX2X_DB_SHIFT);
  10411. if (doorbell_size > pci_resource_len(pdev, 2)) {
  10412. dev_err(&bp->pdev->dev,
  10413. "Cannot map doorbells, bar size too small, aborting\n");
  10414. rc = -ENOMEM;
  10415. goto init_one_exit;
  10416. }
  10417. bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2),
  10418. doorbell_size);
  10419. }
  10420. if (!bp->doorbells) {
  10421. dev_err(&bp->pdev->dev,
  10422. "Cannot map doorbell space, aborting\n");
  10423. rc = -ENOMEM;
  10424. goto init_one_exit;
  10425. }
  10426. if (IS_VF(bp)) {
  10427. rc = bnx2x_vfpf_acquire(bp, tx_count, rx_count);
  10428. if (rc)
  10429. goto init_one_exit;
  10430. }
  10431. /* Enable SRIOV if capability found in configuration space.
  10432. * Once the generic SR-IOV framework makes it in from the
  10433. * pci tree this will be revised, to allow dynamic control
  10434. * over the number of VFs. Right now, change the num of vfs
  10435. * param below to enable SR-IOV.
  10436. */
  10437. rc = bnx2x_iov_init_one(bp, int_mode, 0/*num vfs*/);
  10438. if (rc)
  10439. goto init_one_exit;
  10440. /* calc qm_cid_count */
  10441. bp->qm_cid_count = bnx2x_set_qm_cid_count(bp);
  10442. BNX2X_DEV_INFO("qm_cid_count %d\n", bp->qm_cid_count);
  10443. /* disable FCOE L2 queue for E1x*/
  10444. if (CHIP_IS_E1x(bp))
  10445. bp->flags |= NO_FCOE_FLAG;
  10446. /* disable FCOE for 57840 device, until FW supports it */
  10447. switch (ent->driver_data) {
  10448. case BCM57840_O:
  10449. case BCM57840_4_10:
  10450. case BCM57840_2_20:
  10451. case BCM57840_MFO:
  10452. case BCM57840_MF:
  10453. bp->flags |= NO_FCOE_FLAG;
  10454. }
  10455. /* Set bp->num_queues for MSI-X mode*/
  10456. bnx2x_set_num_queues(bp);
  10457. /* Configure interrupt mode: try to enable MSI-X/MSI if
  10458. * needed.
  10459. */
  10460. rc = bnx2x_set_int_mode(bp);
  10461. if (rc) {
  10462. dev_err(&pdev->dev, "Cannot set interrupts\n");
  10463. goto init_one_exit;
  10464. }
  10465. BNX2X_DEV_INFO("set interrupts successfully\n");
  10466. /* register the net device */
  10467. rc = register_netdev(dev);
  10468. if (rc) {
  10469. dev_err(&pdev->dev, "Cannot register net device\n");
  10470. goto init_one_exit;
  10471. }
  10472. BNX2X_DEV_INFO("device name after netdev register %s\n", dev->name);
  10473. if (!NO_FCOE(bp)) {
  10474. /* Add storage MAC address */
  10475. rtnl_lock();
  10476. dev_addr_add(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  10477. rtnl_unlock();
  10478. }
  10479. bnx2x_get_pcie_width_speed(bp, &pcie_width, &pcie_speed);
  10480. BNX2X_DEV_INFO("got pcie width %d and speed %d\n",
  10481. pcie_width, pcie_speed);
  10482. BNX2X_DEV_INFO(
  10483. "%s (%c%d) PCI-E x%d %s found at mem %lx, IRQ %d, node addr %pM\n",
  10484. board_info[ent->driver_data].name,
  10485. (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4),
  10486. pcie_width,
  10487. ((!CHIP_IS_E2(bp) && pcie_speed == 2) ||
  10488. (CHIP_IS_E2(bp) && pcie_speed == 1)) ?
  10489. "5GHz (Gen2)" : "2.5GHz",
  10490. dev->base_addr, bp->pdev->irq, dev->dev_addr);
  10491. return 0;
  10492. init_one_exit:
  10493. if (bp->regview)
  10494. iounmap(bp->regview);
  10495. if (IS_PF(bp) && bp->doorbells)
  10496. iounmap(bp->doorbells);
  10497. free_netdev(dev);
  10498. if (atomic_read(&pdev->enable_cnt) == 1)
  10499. pci_release_regions(pdev);
  10500. pci_disable_device(pdev);
  10501. pci_set_drvdata(pdev, NULL);
  10502. return rc;
  10503. }
  10504. static void bnx2x_remove_one(struct pci_dev *pdev)
  10505. {
  10506. struct net_device *dev = pci_get_drvdata(pdev);
  10507. struct bnx2x *bp;
  10508. if (!dev) {
  10509. dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n");
  10510. return;
  10511. }
  10512. bp = netdev_priv(dev);
  10513. /* Delete storage MAC address */
  10514. if (!NO_FCOE(bp)) {
  10515. rtnl_lock();
  10516. dev_addr_del(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  10517. rtnl_unlock();
  10518. }
  10519. #ifdef BCM_DCBNL
  10520. /* Delete app tlvs from dcbnl */
  10521. bnx2x_dcbnl_update_applist(bp, true);
  10522. #endif
  10523. unregister_netdev(dev);
  10524. /* Power on: we can't let PCI layer write to us while we are in D3 */
  10525. if (IS_PF(bp))
  10526. bnx2x_set_power_state(bp, PCI_D0);
  10527. /* Disable MSI/MSI-X */
  10528. bnx2x_disable_msi(bp);
  10529. /* Power off */
  10530. if (IS_PF(bp))
  10531. bnx2x_set_power_state(bp, PCI_D3hot);
  10532. /* Make sure RESET task is not scheduled before continuing */
  10533. cancel_delayed_work_sync(&bp->sp_rtnl_task);
  10534. bnx2x_iov_remove_one(bp);
  10535. /* send message via vfpf channel to release the resources of this vf */
  10536. if (IS_VF(bp))
  10537. bnx2x_vfpf_release(bp);
  10538. if (bp->regview)
  10539. iounmap(bp->regview);
  10540. /* for vf doorbells are part of the regview and were unmapped along with
  10541. * it. FW is only loaded by PF.
  10542. */
  10543. if (IS_PF(bp)) {
  10544. if (bp->doorbells)
  10545. iounmap(bp->doorbells);
  10546. bnx2x_release_firmware(bp);
  10547. }
  10548. bnx2x_free_mem_bp(bp);
  10549. free_netdev(dev);
  10550. if (atomic_read(&pdev->enable_cnt) == 1)
  10551. pci_release_regions(pdev);
  10552. pci_disable_device(pdev);
  10553. pci_set_drvdata(pdev, NULL);
  10554. }
  10555. static int bnx2x_eeh_nic_unload(struct bnx2x *bp)
  10556. {
  10557. int i;
  10558. bp->state = BNX2X_STATE_ERROR;
  10559. bp->rx_mode = BNX2X_RX_MODE_NONE;
  10560. if (CNIC_LOADED(bp))
  10561. bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD);
  10562. /* Stop Tx */
  10563. bnx2x_tx_disable(bp);
  10564. bnx2x_netif_stop(bp, 0);
  10565. /* Delete all NAPI objects */
  10566. bnx2x_del_all_napi(bp);
  10567. if (CNIC_LOADED(bp))
  10568. bnx2x_del_all_napi_cnic(bp);
  10569. del_timer_sync(&bp->timer);
  10570. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  10571. /* Release IRQs */
  10572. bnx2x_free_irq(bp);
  10573. /* Free SKBs, SGEs, TPA pool and driver internals */
  10574. bnx2x_free_skbs(bp);
  10575. for_each_rx_queue(bp, i)
  10576. bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
  10577. bnx2x_free_mem(bp);
  10578. bp->state = BNX2X_STATE_CLOSED;
  10579. netif_carrier_off(bp->dev);
  10580. return 0;
  10581. }
  10582. static void bnx2x_eeh_recover(struct bnx2x *bp)
  10583. {
  10584. u32 val;
  10585. mutex_init(&bp->port.phy_mutex);
  10586. val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
  10587. if ((val & (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
  10588. != (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
  10589. BNX2X_ERR("BAD MCP validity signature\n");
  10590. }
  10591. /**
  10592. * bnx2x_io_error_detected - called when PCI error is detected
  10593. * @pdev: Pointer to PCI device
  10594. * @state: The current pci connection state
  10595. *
  10596. * This function is called after a PCI bus error affecting
  10597. * this device has been detected.
  10598. */
  10599. static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev,
  10600. pci_channel_state_t state)
  10601. {
  10602. struct net_device *dev = pci_get_drvdata(pdev);
  10603. struct bnx2x *bp = netdev_priv(dev);
  10604. rtnl_lock();
  10605. netif_device_detach(dev);
  10606. if (state == pci_channel_io_perm_failure) {
  10607. rtnl_unlock();
  10608. return PCI_ERS_RESULT_DISCONNECT;
  10609. }
  10610. if (netif_running(dev))
  10611. bnx2x_eeh_nic_unload(bp);
  10612. pci_disable_device(pdev);
  10613. rtnl_unlock();
  10614. /* Request a slot reset */
  10615. return PCI_ERS_RESULT_NEED_RESET;
  10616. }
  10617. /**
  10618. * bnx2x_io_slot_reset - called after the PCI bus has been reset
  10619. * @pdev: Pointer to PCI device
  10620. *
  10621. * Restart the card from scratch, as if from a cold-boot.
  10622. */
  10623. static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev)
  10624. {
  10625. struct net_device *dev = pci_get_drvdata(pdev);
  10626. struct bnx2x *bp = netdev_priv(dev);
  10627. rtnl_lock();
  10628. if (pci_enable_device(pdev)) {
  10629. dev_err(&pdev->dev,
  10630. "Cannot re-enable PCI device after reset\n");
  10631. rtnl_unlock();
  10632. return PCI_ERS_RESULT_DISCONNECT;
  10633. }
  10634. pci_set_master(pdev);
  10635. pci_restore_state(pdev);
  10636. if (netif_running(dev))
  10637. bnx2x_set_power_state(bp, PCI_D0);
  10638. rtnl_unlock();
  10639. return PCI_ERS_RESULT_RECOVERED;
  10640. }
  10641. /**
  10642. * bnx2x_io_resume - called when traffic can start flowing again
  10643. * @pdev: Pointer to PCI device
  10644. *
  10645. * This callback is called when the error recovery driver tells us that
  10646. * its OK to resume normal operation.
  10647. */
  10648. static void bnx2x_io_resume(struct pci_dev *pdev)
  10649. {
  10650. struct net_device *dev = pci_get_drvdata(pdev);
  10651. struct bnx2x *bp = netdev_priv(dev);
  10652. if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
  10653. netdev_err(bp->dev, "Handling parity error recovery. Try again later\n");
  10654. return;
  10655. }
  10656. rtnl_lock();
  10657. bnx2x_eeh_recover(bp);
  10658. if (netif_running(dev))
  10659. bnx2x_nic_load(bp, LOAD_NORMAL);
  10660. netif_device_attach(dev);
  10661. rtnl_unlock();
  10662. }
  10663. static const struct pci_error_handlers bnx2x_err_handler = {
  10664. .error_detected = bnx2x_io_error_detected,
  10665. .slot_reset = bnx2x_io_slot_reset,
  10666. .resume = bnx2x_io_resume,
  10667. };
  10668. static struct pci_driver bnx2x_pci_driver = {
  10669. .name = DRV_MODULE_NAME,
  10670. .id_table = bnx2x_pci_tbl,
  10671. .probe = bnx2x_init_one,
  10672. .remove = bnx2x_remove_one,
  10673. .suspend = bnx2x_suspend,
  10674. .resume = bnx2x_resume,
  10675. .err_handler = &bnx2x_err_handler,
  10676. };
  10677. static int __init bnx2x_init(void)
  10678. {
  10679. int ret;
  10680. pr_info("%s", version);
  10681. bnx2x_wq = create_singlethread_workqueue("bnx2x");
  10682. if (bnx2x_wq == NULL) {
  10683. pr_err("Cannot create workqueue\n");
  10684. return -ENOMEM;
  10685. }
  10686. ret = pci_register_driver(&bnx2x_pci_driver);
  10687. if (ret) {
  10688. pr_err("Cannot register driver\n");
  10689. destroy_workqueue(bnx2x_wq);
  10690. }
  10691. return ret;
  10692. }
  10693. static void __exit bnx2x_cleanup(void)
  10694. {
  10695. struct list_head *pos, *q;
  10696. pci_unregister_driver(&bnx2x_pci_driver);
  10697. destroy_workqueue(bnx2x_wq);
  10698. /* Free globablly allocated resources */
  10699. list_for_each_safe(pos, q, &bnx2x_prev_list) {
  10700. struct bnx2x_prev_path_list *tmp =
  10701. list_entry(pos, struct bnx2x_prev_path_list, list);
  10702. list_del(pos);
  10703. kfree(tmp);
  10704. }
  10705. }
  10706. void bnx2x_notify_link_changed(struct bnx2x *bp)
  10707. {
  10708. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + BP_FUNC(bp)*sizeof(u32), 1);
  10709. }
  10710. module_init(bnx2x_init);
  10711. module_exit(bnx2x_cleanup);
  10712. /**
  10713. * bnx2x_set_iscsi_eth_mac_addr - set iSCSI MAC(s).
  10714. *
  10715. * @bp: driver handle
  10716. * @set: set or clear the CAM entry
  10717. *
  10718. * This function will wait until the ramdord completion returns.
  10719. * Return 0 if success, -ENODEV if ramrod doesn't return.
  10720. */
  10721. static int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp)
  10722. {
  10723. unsigned long ramrod_flags = 0;
  10724. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  10725. return bnx2x_set_mac_one(bp, bp->cnic_eth_dev.iscsi_mac,
  10726. &bp->iscsi_l2_mac_obj, true,
  10727. BNX2X_ISCSI_ETH_MAC, &ramrod_flags);
  10728. }
  10729. /* count denotes the number of new completions we have seen */
  10730. static void bnx2x_cnic_sp_post(struct bnx2x *bp, int count)
  10731. {
  10732. struct eth_spe *spe;
  10733. int cxt_index, cxt_offset;
  10734. #ifdef BNX2X_STOP_ON_ERROR
  10735. if (unlikely(bp->panic))
  10736. return;
  10737. #endif
  10738. spin_lock_bh(&bp->spq_lock);
  10739. BUG_ON(bp->cnic_spq_pending < count);
  10740. bp->cnic_spq_pending -= count;
  10741. for (; bp->cnic_kwq_pending; bp->cnic_kwq_pending--) {
  10742. u16 type = (le16_to_cpu(bp->cnic_kwq_cons->hdr.type)
  10743. & SPE_HDR_CONN_TYPE) >>
  10744. SPE_HDR_CONN_TYPE_SHIFT;
  10745. u8 cmd = (le32_to_cpu(bp->cnic_kwq_cons->hdr.conn_and_cmd_data)
  10746. >> SPE_HDR_CMD_ID_SHIFT) & 0xff;
  10747. /* Set validation for iSCSI L2 client before sending SETUP
  10748. * ramrod
  10749. */
  10750. if (type == ETH_CONNECTION_TYPE) {
  10751. if (cmd == RAMROD_CMD_ID_ETH_CLIENT_SETUP) {
  10752. cxt_index = BNX2X_ISCSI_ETH_CID(bp) /
  10753. ILT_PAGE_CIDS;
  10754. cxt_offset = BNX2X_ISCSI_ETH_CID(bp) -
  10755. (cxt_index * ILT_PAGE_CIDS);
  10756. bnx2x_set_ctx_validation(bp,
  10757. &bp->context[cxt_index].
  10758. vcxt[cxt_offset].eth,
  10759. BNX2X_ISCSI_ETH_CID(bp));
  10760. }
  10761. }
  10762. /*
  10763. * There may be not more than 8 L2, not more than 8 L5 SPEs
  10764. * and in the air. We also check that number of outstanding
  10765. * COMMON ramrods is not more than the EQ and SPQ can
  10766. * accommodate.
  10767. */
  10768. if (type == ETH_CONNECTION_TYPE) {
  10769. if (!atomic_read(&bp->cq_spq_left))
  10770. break;
  10771. else
  10772. atomic_dec(&bp->cq_spq_left);
  10773. } else if (type == NONE_CONNECTION_TYPE) {
  10774. if (!atomic_read(&bp->eq_spq_left))
  10775. break;
  10776. else
  10777. atomic_dec(&bp->eq_spq_left);
  10778. } else if ((type == ISCSI_CONNECTION_TYPE) ||
  10779. (type == FCOE_CONNECTION_TYPE)) {
  10780. if (bp->cnic_spq_pending >=
  10781. bp->cnic_eth_dev.max_kwqe_pending)
  10782. break;
  10783. else
  10784. bp->cnic_spq_pending++;
  10785. } else {
  10786. BNX2X_ERR("Unknown SPE type: %d\n", type);
  10787. bnx2x_panic();
  10788. break;
  10789. }
  10790. spe = bnx2x_sp_get_next(bp);
  10791. *spe = *bp->cnic_kwq_cons;
  10792. DP(BNX2X_MSG_SP, "pending on SPQ %d, on KWQ %d count %d\n",
  10793. bp->cnic_spq_pending, bp->cnic_kwq_pending, count);
  10794. if (bp->cnic_kwq_cons == bp->cnic_kwq_last)
  10795. bp->cnic_kwq_cons = bp->cnic_kwq;
  10796. else
  10797. bp->cnic_kwq_cons++;
  10798. }
  10799. bnx2x_sp_prod_update(bp);
  10800. spin_unlock_bh(&bp->spq_lock);
  10801. }
  10802. static int bnx2x_cnic_sp_queue(struct net_device *dev,
  10803. struct kwqe_16 *kwqes[], u32 count)
  10804. {
  10805. struct bnx2x *bp = netdev_priv(dev);
  10806. int i;
  10807. #ifdef BNX2X_STOP_ON_ERROR
  10808. if (unlikely(bp->panic)) {
  10809. BNX2X_ERR("Can't post to SP queue while panic\n");
  10810. return -EIO;
  10811. }
  10812. #endif
  10813. if ((bp->recovery_state != BNX2X_RECOVERY_DONE) &&
  10814. (bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  10815. BNX2X_ERR("Handling parity error recovery. Try again later\n");
  10816. return -EAGAIN;
  10817. }
  10818. spin_lock_bh(&bp->spq_lock);
  10819. for (i = 0; i < count; i++) {
  10820. struct eth_spe *spe = (struct eth_spe *)kwqes[i];
  10821. if (bp->cnic_kwq_pending == MAX_SP_DESC_CNT)
  10822. break;
  10823. *bp->cnic_kwq_prod = *spe;
  10824. bp->cnic_kwq_pending++;
  10825. DP(BNX2X_MSG_SP, "L5 SPQE %x %x %x:%x pos %d\n",
  10826. spe->hdr.conn_and_cmd_data, spe->hdr.type,
  10827. spe->data.update_data_addr.hi,
  10828. spe->data.update_data_addr.lo,
  10829. bp->cnic_kwq_pending);
  10830. if (bp->cnic_kwq_prod == bp->cnic_kwq_last)
  10831. bp->cnic_kwq_prod = bp->cnic_kwq;
  10832. else
  10833. bp->cnic_kwq_prod++;
  10834. }
  10835. spin_unlock_bh(&bp->spq_lock);
  10836. if (bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending)
  10837. bnx2x_cnic_sp_post(bp, 0);
  10838. return i;
  10839. }
  10840. static int bnx2x_cnic_ctl_send(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  10841. {
  10842. struct cnic_ops *c_ops;
  10843. int rc = 0;
  10844. mutex_lock(&bp->cnic_mutex);
  10845. c_ops = rcu_dereference_protected(bp->cnic_ops,
  10846. lockdep_is_held(&bp->cnic_mutex));
  10847. if (c_ops)
  10848. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  10849. mutex_unlock(&bp->cnic_mutex);
  10850. return rc;
  10851. }
  10852. static int bnx2x_cnic_ctl_send_bh(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  10853. {
  10854. struct cnic_ops *c_ops;
  10855. int rc = 0;
  10856. rcu_read_lock();
  10857. c_ops = rcu_dereference(bp->cnic_ops);
  10858. if (c_ops)
  10859. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  10860. rcu_read_unlock();
  10861. return rc;
  10862. }
  10863. /*
  10864. * for commands that have no data
  10865. */
  10866. int bnx2x_cnic_notify(struct bnx2x *bp, int cmd)
  10867. {
  10868. struct cnic_ctl_info ctl = {0};
  10869. ctl.cmd = cmd;
  10870. return bnx2x_cnic_ctl_send(bp, &ctl);
  10871. }
  10872. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err)
  10873. {
  10874. struct cnic_ctl_info ctl = {0};
  10875. /* first we tell CNIC and only then we count this as a completion */
  10876. ctl.cmd = CNIC_CTL_COMPLETION_CMD;
  10877. ctl.data.comp.cid = cid;
  10878. ctl.data.comp.error = err;
  10879. bnx2x_cnic_ctl_send_bh(bp, &ctl);
  10880. bnx2x_cnic_sp_post(bp, 0);
  10881. }
  10882. /* Called with netif_addr_lock_bh() taken.
  10883. * Sets an rx_mode config for an iSCSI ETH client.
  10884. * Doesn't block.
  10885. * Completion should be checked outside.
  10886. */
  10887. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start)
  10888. {
  10889. unsigned long accept_flags = 0, ramrod_flags = 0;
  10890. u8 cl_id = bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  10891. int sched_state = BNX2X_FILTER_ISCSI_ETH_STOP_SCHED;
  10892. if (start) {
  10893. /* Start accepting on iSCSI L2 ring. Accept all multicasts
  10894. * because it's the only way for UIO Queue to accept
  10895. * multicasts (in non-promiscuous mode only one Queue per
  10896. * function will receive multicast packets (leading in our
  10897. * case).
  10898. */
  10899. __set_bit(BNX2X_ACCEPT_UNICAST, &accept_flags);
  10900. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept_flags);
  10901. __set_bit(BNX2X_ACCEPT_BROADCAST, &accept_flags);
  10902. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags);
  10903. /* Clear STOP_PENDING bit if START is requested */
  10904. clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &bp->sp_state);
  10905. sched_state = BNX2X_FILTER_ISCSI_ETH_START_SCHED;
  10906. } else
  10907. /* Clear START_PENDING bit if STOP is requested */
  10908. clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &bp->sp_state);
  10909. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  10910. set_bit(sched_state, &bp->sp_state);
  10911. else {
  10912. __set_bit(RAMROD_RX, &ramrod_flags);
  10913. bnx2x_set_q_rx_mode(bp, cl_id, 0, accept_flags, 0,
  10914. ramrod_flags);
  10915. }
  10916. }
  10917. static int bnx2x_drv_ctl(struct net_device *dev, struct drv_ctl_info *ctl)
  10918. {
  10919. struct bnx2x *bp = netdev_priv(dev);
  10920. int rc = 0;
  10921. switch (ctl->cmd) {
  10922. case DRV_CTL_CTXTBL_WR_CMD: {
  10923. u32 index = ctl->data.io.offset;
  10924. dma_addr_t addr = ctl->data.io.dma_addr;
  10925. bnx2x_ilt_wr(bp, index, addr);
  10926. break;
  10927. }
  10928. case DRV_CTL_RET_L5_SPQ_CREDIT_CMD: {
  10929. int count = ctl->data.credit.credit_count;
  10930. bnx2x_cnic_sp_post(bp, count);
  10931. break;
  10932. }
  10933. /* rtnl_lock is held. */
  10934. case DRV_CTL_START_L2_CMD: {
  10935. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  10936. unsigned long sp_bits = 0;
  10937. /* Configure the iSCSI classification object */
  10938. bnx2x_init_mac_obj(bp, &bp->iscsi_l2_mac_obj,
  10939. cp->iscsi_l2_client_id,
  10940. cp->iscsi_l2_cid, BP_FUNC(bp),
  10941. bnx2x_sp(bp, mac_rdata),
  10942. bnx2x_sp_mapping(bp, mac_rdata),
  10943. BNX2X_FILTER_MAC_PENDING,
  10944. &bp->sp_state, BNX2X_OBJ_TYPE_RX,
  10945. &bp->macs_pool);
  10946. /* Set iSCSI MAC address */
  10947. rc = bnx2x_set_iscsi_eth_mac_addr(bp);
  10948. if (rc)
  10949. break;
  10950. mmiowb();
  10951. barrier();
  10952. /* Start accepting on iSCSI L2 ring */
  10953. netif_addr_lock_bh(dev);
  10954. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  10955. netif_addr_unlock_bh(dev);
  10956. /* bits to wait on */
  10957. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  10958. __set_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &sp_bits);
  10959. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  10960. BNX2X_ERR("rx_mode completion timed out!\n");
  10961. break;
  10962. }
  10963. /* rtnl_lock is held. */
  10964. case DRV_CTL_STOP_L2_CMD: {
  10965. unsigned long sp_bits = 0;
  10966. /* Stop accepting on iSCSI L2 ring */
  10967. netif_addr_lock_bh(dev);
  10968. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  10969. netif_addr_unlock_bh(dev);
  10970. /* bits to wait on */
  10971. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  10972. __set_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &sp_bits);
  10973. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  10974. BNX2X_ERR("rx_mode completion timed out!\n");
  10975. mmiowb();
  10976. barrier();
  10977. /* Unset iSCSI L2 MAC */
  10978. rc = bnx2x_del_all_macs(bp, &bp->iscsi_l2_mac_obj,
  10979. BNX2X_ISCSI_ETH_MAC, true);
  10980. break;
  10981. }
  10982. case DRV_CTL_RET_L2_SPQ_CREDIT_CMD: {
  10983. int count = ctl->data.credit.credit_count;
  10984. smp_mb__before_atomic_inc();
  10985. atomic_add(count, &bp->cq_spq_left);
  10986. smp_mb__after_atomic_inc();
  10987. break;
  10988. }
  10989. case DRV_CTL_ULP_REGISTER_CMD: {
  10990. int ulp_type = ctl->data.register_data.ulp_type;
  10991. if (CHIP_IS_E3(bp)) {
  10992. int idx = BP_FW_MB_IDX(bp);
  10993. u32 cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  10994. int path = BP_PATH(bp);
  10995. int port = BP_PORT(bp);
  10996. int i;
  10997. u32 scratch_offset;
  10998. u32 *host_addr;
  10999. /* first write capability to shmem2 */
  11000. if (ulp_type == CNIC_ULP_ISCSI)
  11001. cap |= DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  11002. else if (ulp_type == CNIC_ULP_FCOE)
  11003. cap |= DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  11004. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  11005. if ((ulp_type != CNIC_ULP_FCOE) ||
  11006. (!SHMEM2_HAS(bp, ncsi_oem_data_addr)) ||
  11007. (!(bp->flags & BC_SUPPORTS_FCOE_FEATURES)))
  11008. break;
  11009. /* if reached here - should write fcoe capabilities */
  11010. scratch_offset = SHMEM2_RD(bp, ncsi_oem_data_addr);
  11011. if (!scratch_offset)
  11012. break;
  11013. scratch_offset += offsetof(struct glob_ncsi_oem_data,
  11014. fcoe_features[path][port]);
  11015. host_addr = (u32 *) &(ctl->data.register_data.
  11016. fcoe_features);
  11017. for (i = 0; i < sizeof(struct fcoe_capabilities);
  11018. i += 4)
  11019. REG_WR(bp, scratch_offset + i,
  11020. *(host_addr + i/4));
  11021. }
  11022. break;
  11023. }
  11024. case DRV_CTL_ULP_UNREGISTER_CMD: {
  11025. int ulp_type = ctl->data.ulp_type;
  11026. if (CHIP_IS_E3(bp)) {
  11027. int idx = BP_FW_MB_IDX(bp);
  11028. u32 cap;
  11029. cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  11030. if (ulp_type == CNIC_ULP_ISCSI)
  11031. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  11032. else if (ulp_type == CNIC_ULP_FCOE)
  11033. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  11034. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  11035. }
  11036. break;
  11037. }
  11038. default:
  11039. BNX2X_ERR("unknown command %x\n", ctl->cmd);
  11040. rc = -EINVAL;
  11041. }
  11042. return rc;
  11043. }
  11044. void bnx2x_setup_cnic_irq_info(struct bnx2x *bp)
  11045. {
  11046. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11047. if (bp->flags & USING_MSIX_FLAG) {
  11048. cp->drv_state |= CNIC_DRV_STATE_USING_MSIX;
  11049. cp->irq_arr[0].irq_flags |= CNIC_IRQ_FL_MSIX;
  11050. cp->irq_arr[0].vector = bp->msix_table[1].vector;
  11051. } else {
  11052. cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX;
  11053. cp->irq_arr[0].irq_flags &= ~CNIC_IRQ_FL_MSIX;
  11054. }
  11055. if (!CHIP_IS_E1x(bp))
  11056. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e2_sb;
  11057. else
  11058. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e1x_sb;
  11059. cp->irq_arr[0].status_blk_num = bnx2x_cnic_fw_sb_id(bp);
  11060. cp->irq_arr[0].status_blk_num2 = bnx2x_cnic_igu_sb_id(bp);
  11061. cp->irq_arr[1].status_blk = bp->def_status_blk;
  11062. cp->irq_arr[1].status_blk_num = DEF_SB_ID;
  11063. cp->irq_arr[1].status_blk_num2 = DEF_SB_IGU_ID;
  11064. cp->num_irq = 2;
  11065. }
  11066. void bnx2x_setup_cnic_info(struct bnx2x *bp)
  11067. {
  11068. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11069. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  11070. bnx2x_cid_ilt_lines(bp);
  11071. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  11072. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
  11073. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
  11074. if (NO_ISCSI_OOO(bp))
  11075. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  11076. }
  11077. static int bnx2x_register_cnic(struct net_device *dev, struct cnic_ops *ops,
  11078. void *data)
  11079. {
  11080. struct bnx2x *bp = netdev_priv(dev);
  11081. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11082. int rc;
  11083. DP(NETIF_MSG_IFUP, "Register_cnic called\n");
  11084. if (ops == NULL) {
  11085. BNX2X_ERR("NULL ops received\n");
  11086. return -EINVAL;
  11087. }
  11088. if (!CNIC_SUPPORT(bp)) {
  11089. BNX2X_ERR("Can't register CNIC when not supported\n");
  11090. return -EOPNOTSUPP;
  11091. }
  11092. if (!CNIC_LOADED(bp)) {
  11093. rc = bnx2x_load_cnic(bp);
  11094. if (rc) {
  11095. BNX2X_ERR("CNIC-related load failed\n");
  11096. return rc;
  11097. }
  11098. }
  11099. bp->cnic_enabled = true;
  11100. bp->cnic_kwq = kzalloc(PAGE_SIZE, GFP_KERNEL);
  11101. if (!bp->cnic_kwq)
  11102. return -ENOMEM;
  11103. bp->cnic_kwq_cons = bp->cnic_kwq;
  11104. bp->cnic_kwq_prod = bp->cnic_kwq;
  11105. bp->cnic_kwq_last = bp->cnic_kwq + MAX_SP_DESC_CNT;
  11106. bp->cnic_spq_pending = 0;
  11107. bp->cnic_kwq_pending = 0;
  11108. bp->cnic_data = data;
  11109. cp->num_irq = 0;
  11110. cp->drv_state |= CNIC_DRV_STATE_REGD;
  11111. cp->iro_arr = bp->iro_arr;
  11112. bnx2x_setup_cnic_irq_info(bp);
  11113. rcu_assign_pointer(bp->cnic_ops, ops);
  11114. return 0;
  11115. }
  11116. static int bnx2x_unregister_cnic(struct net_device *dev)
  11117. {
  11118. struct bnx2x *bp = netdev_priv(dev);
  11119. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11120. mutex_lock(&bp->cnic_mutex);
  11121. cp->drv_state = 0;
  11122. RCU_INIT_POINTER(bp->cnic_ops, NULL);
  11123. mutex_unlock(&bp->cnic_mutex);
  11124. synchronize_rcu();
  11125. kfree(bp->cnic_kwq);
  11126. bp->cnic_kwq = NULL;
  11127. return 0;
  11128. }
  11129. struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev)
  11130. {
  11131. struct bnx2x *bp = netdev_priv(dev);
  11132. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11133. /* If both iSCSI and FCoE are disabled - return NULL in
  11134. * order to indicate CNIC that it should not try to work
  11135. * with this device.
  11136. */
  11137. if (NO_ISCSI(bp) && NO_FCOE(bp))
  11138. return NULL;
  11139. cp->drv_owner = THIS_MODULE;
  11140. cp->chip_id = CHIP_ID(bp);
  11141. cp->pdev = bp->pdev;
  11142. cp->io_base = bp->regview;
  11143. cp->io_base2 = bp->doorbells;
  11144. cp->max_kwqe_pending = 8;
  11145. cp->ctx_blk_size = CDU_ILT_PAGE_SZ;
  11146. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  11147. bnx2x_cid_ilt_lines(bp);
  11148. cp->ctx_tbl_len = CNIC_ILT_LINES;
  11149. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  11150. cp->drv_submit_kwqes_16 = bnx2x_cnic_sp_queue;
  11151. cp->drv_ctl = bnx2x_drv_ctl;
  11152. cp->drv_register_cnic = bnx2x_register_cnic;
  11153. cp->drv_unregister_cnic = bnx2x_unregister_cnic;
  11154. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
  11155. cp->iscsi_l2_client_id =
  11156. bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  11157. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
  11158. if (NO_ISCSI_OOO(bp))
  11159. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  11160. if (NO_ISCSI(bp))
  11161. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI;
  11162. if (NO_FCOE(bp))
  11163. cp->drv_state |= CNIC_DRV_STATE_NO_FCOE;
  11164. BNX2X_DEV_INFO(
  11165. "page_size %d, tbl_offset %d, tbl_lines %d, starting cid %d\n",
  11166. cp->ctx_blk_size,
  11167. cp->ctx_tbl_offset,
  11168. cp->ctx_tbl_len,
  11169. cp->starting_cid);
  11170. return cp;
  11171. }
  11172. u32 bnx2x_rx_ustorm_prods_offset(struct bnx2x_fastpath *fp)
  11173. {
  11174. struct bnx2x *bp = fp->bp;
  11175. u32 offset = BAR_USTRORM_INTMEM;
  11176. if (IS_VF(bp))
  11177. return bnx2x_vf_ustorm_prods_offset(bp, fp);
  11178. else if (!CHIP_IS_E1x(bp))
  11179. offset += USTORM_RX_PRODS_E2_OFFSET(fp->cl_qzone_id);
  11180. else
  11181. offset += USTORM_RX_PRODS_E1X_OFFSET(BP_PORT(bp), fp->cl_id);
  11182. return offset;
  11183. }
  11184. /* called only on E1H or E2.
  11185. * When pretending to be PF, the pretend value is the function number 0...7
  11186. * When pretending to be VF, the pretend val is the PF-num:VF-valid:ABS-VFID
  11187. * combination
  11188. */
  11189. int bnx2x_pretend_func(struct bnx2x *bp, u16 pretend_func_val)
  11190. {
  11191. u32 pretend_reg;
  11192. if (CHIP_IS_E1H(bp) && pretend_func_val >= E1H_FUNC_MAX)
  11193. return -1;
  11194. /* get my own pretend register */
  11195. pretend_reg = bnx2x_get_pretend_reg(bp);
  11196. REG_WR(bp, pretend_reg, pretend_func_val);
  11197. REG_RD(bp, pretend_reg);
  11198. return 0;
  11199. }