bnx2.c 196 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087
  1. /* bnx2.c: Broadcom NX2 network driver.
  2. *
  3. * Copyright (c) 2004-2009 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. * Written by: Michael Chan (mchan@broadcom.com)
  10. */
  11. #include <linux/module.h>
  12. #include <linux/moduleparam.h>
  13. #include <linux/kernel.h>
  14. #include <linux/timer.h>
  15. #include <linux/errno.h>
  16. #include <linux/ioport.h>
  17. #include <linux/slab.h>
  18. #include <linux/vmalloc.h>
  19. #include <linux/interrupt.h>
  20. #include <linux/pci.h>
  21. #include <linux/init.h>
  22. #include <linux/netdevice.h>
  23. #include <linux/etherdevice.h>
  24. #include <linux/skbuff.h>
  25. #include <linux/dma-mapping.h>
  26. #include <linux/bitops.h>
  27. #include <asm/io.h>
  28. #include <asm/irq.h>
  29. #include <linux/delay.h>
  30. #include <asm/byteorder.h>
  31. #include <asm/page.h>
  32. #include <linux/time.h>
  33. #include <linux/ethtool.h>
  34. #include <linux/mii.h>
  35. #include <linux/if_vlan.h>
  36. #if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
  37. #define BCM_VLAN 1
  38. #endif
  39. #include <net/ip.h>
  40. #include <net/tcp.h>
  41. #include <net/checksum.h>
  42. #include <linux/workqueue.h>
  43. #include <linux/crc32.h>
  44. #include <linux/prefetch.h>
  45. #include <linux/cache.h>
  46. #include <linux/firmware.h>
  47. #include <linux/log2.h>
  48. #include "bnx2.h"
  49. #include "bnx2_fw.h"
  50. #define DRV_MODULE_NAME "bnx2"
  51. #define PFX DRV_MODULE_NAME ": "
  52. #define DRV_MODULE_VERSION "2.0.0"
  53. #define DRV_MODULE_RELDATE "April 2, 2009"
  54. #define FW_MIPS_FILE_06 "bnx2/bnx2-mips-06-4.6.16.fw"
  55. #define FW_RV2P_FILE_06 "bnx2/bnx2-rv2p-06-4.6.16.fw"
  56. #define FW_MIPS_FILE_09 "bnx2/bnx2-mips-09-4.6.17.fw"
  57. #define FW_RV2P_FILE_09 "bnx2/bnx2-rv2p-09-4.6.15.fw"
  58. #define RUN_AT(x) (jiffies + (x))
  59. /* Time in jiffies before concluding the transmitter is hung. */
  60. #define TX_TIMEOUT (5*HZ)
  61. static char version[] __devinitdata =
  62. "Broadcom NetXtreme II Gigabit Ethernet Driver " DRV_MODULE_NAME " v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
  63. MODULE_AUTHOR("Michael Chan <mchan@broadcom.com>");
  64. MODULE_DESCRIPTION("Broadcom NetXtreme II BCM5706/5708/5709/5716 Driver");
  65. MODULE_LICENSE("GPL");
  66. MODULE_VERSION(DRV_MODULE_VERSION);
  67. MODULE_FIRMWARE(FW_MIPS_FILE_06);
  68. MODULE_FIRMWARE(FW_RV2P_FILE_06);
  69. MODULE_FIRMWARE(FW_MIPS_FILE_09);
  70. MODULE_FIRMWARE(FW_RV2P_FILE_09);
  71. static int disable_msi = 0;
  72. module_param(disable_msi, int, 0);
  73. MODULE_PARM_DESC(disable_msi, "Disable Message Signaled Interrupt (MSI)");
  74. typedef enum {
  75. BCM5706 = 0,
  76. NC370T,
  77. NC370I,
  78. BCM5706S,
  79. NC370F,
  80. BCM5708,
  81. BCM5708S,
  82. BCM5709,
  83. BCM5709S,
  84. BCM5716,
  85. BCM5716S,
  86. } board_t;
  87. /* indexed by board_t, above */
  88. static struct {
  89. char *name;
  90. } board_info[] __devinitdata = {
  91. { "Broadcom NetXtreme II BCM5706 1000Base-T" },
  92. { "HP NC370T Multifunction Gigabit Server Adapter" },
  93. { "HP NC370i Multifunction Gigabit Server Adapter" },
  94. { "Broadcom NetXtreme II BCM5706 1000Base-SX" },
  95. { "HP NC370F Multifunction Gigabit Server Adapter" },
  96. { "Broadcom NetXtreme II BCM5708 1000Base-T" },
  97. { "Broadcom NetXtreme II BCM5708 1000Base-SX" },
  98. { "Broadcom NetXtreme II BCM5709 1000Base-T" },
  99. { "Broadcom NetXtreme II BCM5709 1000Base-SX" },
  100. { "Broadcom NetXtreme II BCM5716 1000Base-T" },
  101. { "Broadcom NetXtreme II BCM5716 1000Base-SX" },
  102. };
  103. static DEFINE_PCI_DEVICE_TABLE(bnx2_pci_tbl) = {
  104. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_5706,
  105. PCI_VENDOR_ID_HP, 0x3101, 0, 0, NC370T },
  106. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_5706,
  107. PCI_VENDOR_ID_HP, 0x3106, 0, 0, NC370I },
  108. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_5706,
  109. PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5706 },
  110. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_5708,
  111. PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5708 },
  112. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_5706S,
  113. PCI_VENDOR_ID_HP, 0x3102, 0, 0, NC370F },
  114. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_5706S,
  115. PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5706S },
  116. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_5708S,
  117. PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5708S },
  118. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_5709,
  119. PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5709 },
  120. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_5709S,
  121. PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5709S },
  122. { PCI_VENDOR_ID_BROADCOM, 0x163b,
  123. PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5716 },
  124. { PCI_VENDOR_ID_BROADCOM, 0x163c,
  125. PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5716S },
  126. { 0, }
  127. };
  128. static struct flash_spec flash_table[] =
  129. {
  130. #define BUFFERED_FLAGS (BNX2_NV_BUFFERED | BNX2_NV_TRANSLATE)
  131. #define NONBUFFERED_FLAGS (BNX2_NV_WREN)
  132. /* Slow EEPROM */
  133. {0x00000000, 0x40830380, 0x009f0081, 0xa184a053, 0xaf000400,
  134. BUFFERED_FLAGS, SEEPROM_PAGE_BITS, SEEPROM_PAGE_SIZE,
  135. SEEPROM_BYTE_ADDR_MASK, SEEPROM_TOTAL_SIZE,
  136. "EEPROM - slow"},
  137. /* Expansion entry 0001 */
  138. {0x08000002, 0x4b808201, 0x00050081, 0x03840253, 0xaf020406,
  139. NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
  140. SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
  141. "Entry 0001"},
  142. /* Saifun SA25F010 (non-buffered flash) */
  143. /* strap, cfg1, & write1 need updates */
  144. {0x04000001, 0x47808201, 0x00050081, 0x03840253, 0xaf020406,
  145. NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
  146. SAIFUN_FLASH_BYTE_ADDR_MASK, SAIFUN_FLASH_BASE_TOTAL_SIZE*2,
  147. "Non-buffered flash (128kB)"},
  148. /* Saifun SA25F020 (non-buffered flash) */
  149. /* strap, cfg1, & write1 need updates */
  150. {0x0c000003, 0x4f808201, 0x00050081, 0x03840253, 0xaf020406,
  151. NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
  152. SAIFUN_FLASH_BYTE_ADDR_MASK, SAIFUN_FLASH_BASE_TOTAL_SIZE*4,
  153. "Non-buffered flash (256kB)"},
  154. /* Expansion entry 0100 */
  155. {0x11000000, 0x53808201, 0x00050081, 0x03840253, 0xaf020406,
  156. NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
  157. SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
  158. "Entry 0100"},
  159. /* Entry 0101: ST M45PE10 (non-buffered flash, TetonII B0) */
  160. {0x19000002, 0x5b808201, 0x000500db, 0x03840253, 0xaf020406,
  161. NONBUFFERED_FLAGS, ST_MICRO_FLASH_PAGE_BITS, ST_MICRO_FLASH_PAGE_SIZE,
  162. ST_MICRO_FLASH_BYTE_ADDR_MASK, ST_MICRO_FLASH_BASE_TOTAL_SIZE*2,
  163. "Entry 0101: ST M45PE10 (128kB non-bufferred)"},
  164. /* Entry 0110: ST M45PE20 (non-buffered flash)*/
  165. {0x15000001, 0x57808201, 0x000500db, 0x03840253, 0xaf020406,
  166. NONBUFFERED_FLAGS, ST_MICRO_FLASH_PAGE_BITS, ST_MICRO_FLASH_PAGE_SIZE,
  167. ST_MICRO_FLASH_BYTE_ADDR_MASK, ST_MICRO_FLASH_BASE_TOTAL_SIZE*4,
  168. "Entry 0110: ST M45PE20 (256kB non-bufferred)"},
  169. /* Saifun SA25F005 (non-buffered flash) */
  170. /* strap, cfg1, & write1 need updates */
  171. {0x1d000003, 0x5f808201, 0x00050081, 0x03840253, 0xaf020406,
  172. NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
  173. SAIFUN_FLASH_BYTE_ADDR_MASK, SAIFUN_FLASH_BASE_TOTAL_SIZE,
  174. "Non-buffered flash (64kB)"},
  175. /* Fast EEPROM */
  176. {0x22000000, 0x62808380, 0x009f0081, 0xa184a053, 0xaf000400,
  177. BUFFERED_FLAGS, SEEPROM_PAGE_BITS, SEEPROM_PAGE_SIZE,
  178. SEEPROM_BYTE_ADDR_MASK, SEEPROM_TOTAL_SIZE,
  179. "EEPROM - fast"},
  180. /* Expansion entry 1001 */
  181. {0x2a000002, 0x6b808201, 0x00050081, 0x03840253, 0xaf020406,
  182. NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
  183. SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
  184. "Entry 1001"},
  185. /* Expansion entry 1010 */
  186. {0x26000001, 0x67808201, 0x00050081, 0x03840253, 0xaf020406,
  187. NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
  188. SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
  189. "Entry 1010"},
  190. /* ATMEL AT45DB011B (buffered flash) */
  191. {0x2e000003, 0x6e808273, 0x00570081, 0x68848353, 0xaf000400,
  192. BUFFERED_FLAGS, BUFFERED_FLASH_PAGE_BITS, BUFFERED_FLASH_PAGE_SIZE,
  193. BUFFERED_FLASH_BYTE_ADDR_MASK, BUFFERED_FLASH_TOTAL_SIZE,
  194. "Buffered flash (128kB)"},
  195. /* Expansion entry 1100 */
  196. {0x33000000, 0x73808201, 0x00050081, 0x03840253, 0xaf020406,
  197. NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
  198. SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
  199. "Entry 1100"},
  200. /* Expansion entry 1101 */
  201. {0x3b000002, 0x7b808201, 0x00050081, 0x03840253, 0xaf020406,
  202. NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
  203. SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
  204. "Entry 1101"},
  205. /* Ateml Expansion entry 1110 */
  206. {0x37000001, 0x76808273, 0x00570081, 0x68848353, 0xaf000400,
  207. BUFFERED_FLAGS, BUFFERED_FLASH_PAGE_BITS, BUFFERED_FLASH_PAGE_SIZE,
  208. BUFFERED_FLASH_BYTE_ADDR_MASK, 0,
  209. "Entry 1110 (Atmel)"},
  210. /* ATMEL AT45DB021B (buffered flash) */
  211. {0x3f000003, 0x7e808273, 0x00570081, 0x68848353, 0xaf000400,
  212. BUFFERED_FLAGS, BUFFERED_FLASH_PAGE_BITS, BUFFERED_FLASH_PAGE_SIZE,
  213. BUFFERED_FLASH_BYTE_ADDR_MASK, BUFFERED_FLASH_TOTAL_SIZE*2,
  214. "Buffered flash (256kB)"},
  215. };
  216. static struct flash_spec flash_5709 = {
  217. .flags = BNX2_NV_BUFFERED,
  218. .page_bits = BCM5709_FLASH_PAGE_BITS,
  219. .page_size = BCM5709_FLASH_PAGE_SIZE,
  220. .addr_mask = BCM5709_FLASH_BYTE_ADDR_MASK,
  221. .total_size = BUFFERED_FLASH_TOTAL_SIZE*2,
  222. .name = "5709 Buffered flash (256kB)",
  223. };
  224. MODULE_DEVICE_TABLE(pci, bnx2_pci_tbl);
  225. static inline u32 bnx2_tx_avail(struct bnx2 *bp, struct bnx2_tx_ring_info *txr)
  226. {
  227. u32 diff;
  228. smp_mb();
  229. /* The ring uses 256 indices for 255 entries, one of them
  230. * needs to be skipped.
  231. */
  232. diff = txr->tx_prod - txr->tx_cons;
  233. if (unlikely(diff >= TX_DESC_CNT)) {
  234. diff &= 0xffff;
  235. if (diff == TX_DESC_CNT)
  236. diff = MAX_TX_DESC_CNT;
  237. }
  238. return (bp->tx_ring_size - diff);
  239. }
  240. static u32
  241. bnx2_reg_rd_ind(struct bnx2 *bp, u32 offset)
  242. {
  243. u32 val;
  244. spin_lock_bh(&bp->indirect_lock);
  245. REG_WR(bp, BNX2_PCICFG_REG_WINDOW_ADDRESS, offset);
  246. val = REG_RD(bp, BNX2_PCICFG_REG_WINDOW);
  247. spin_unlock_bh(&bp->indirect_lock);
  248. return val;
  249. }
  250. static void
  251. bnx2_reg_wr_ind(struct bnx2 *bp, u32 offset, u32 val)
  252. {
  253. spin_lock_bh(&bp->indirect_lock);
  254. REG_WR(bp, BNX2_PCICFG_REG_WINDOW_ADDRESS, offset);
  255. REG_WR(bp, BNX2_PCICFG_REG_WINDOW, val);
  256. spin_unlock_bh(&bp->indirect_lock);
  257. }
  258. static void
  259. bnx2_shmem_wr(struct bnx2 *bp, u32 offset, u32 val)
  260. {
  261. bnx2_reg_wr_ind(bp, bp->shmem_base + offset, val);
  262. }
  263. static u32
  264. bnx2_shmem_rd(struct bnx2 *bp, u32 offset)
  265. {
  266. return (bnx2_reg_rd_ind(bp, bp->shmem_base + offset));
  267. }
  268. static void
  269. bnx2_ctx_wr(struct bnx2 *bp, u32 cid_addr, u32 offset, u32 val)
  270. {
  271. offset += cid_addr;
  272. spin_lock_bh(&bp->indirect_lock);
  273. if (CHIP_NUM(bp) == CHIP_NUM_5709) {
  274. int i;
  275. REG_WR(bp, BNX2_CTX_CTX_DATA, val);
  276. REG_WR(bp, BNX2_CTX_CTX_CTRL,
  277. offset | BNX2_CTX_CTX_CTRL_WRITE_REQ);
  278. for (i = 0; i < 5; i++) {
  279. val = REG_RD(bp, BNX2_CTX_CTX_CTRL);
  280. if ((val & BNX2_CTX_CTX_CTRL_WRITE_REQ) == 0)
  281. break;
  282. udelay(5);
  283. }
  284. } else {
  285. REG_WR(bp, BNX2_CTX_DATA_ADR, offset);
  286. REG_WR(bp, BNX2_CTX_DATA, val);
  287. }
  288. spin_unlock_bh(&bp->indirect_lock);
  289. }
  290. static int
  291. bnx2_read_phy(struct bnx2 *bp, u32 reg, u32 *val)
  292. {
  293. u32 val1;
  294. int i, ret;
  295. if (bp->phy_flags & BNX2_PHY_FLAG_INT_MODE_AUTO_POLLING) {
  296. val1 = REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  297. val1 &= ~BNX2_EMAC_MDIO_MODE_AUTO_POLL;
  298. REG_WR(bp, BNX2_EMAC_MDIO_MODE, val1);
  299. REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  300. udelay(40);
  301. }
  302. val1 = (bp->phy_addr << 21) | (reg << 16) |
  303. BNX2_EMAC_MDIO_COMM_COMMAND_READ | BNX2_EMAC_MDIO_COMM_DISEXT |
  304. BNX2_EMAC_MDIO_COMM_START_BUSY;
  305. REG_WR(bp, BNX2_EMAC_MDIO_COMM, val1);
  306. for (i = 0; i < 50; i++) {
  307. udelay(10);
  308. val1 = REG_RD(bp, BNX2_EMAC_MDIO_COMM);
  309. if (!(val1 & BNX2_EMAC_MDIO_COMM_START_BUSY)) {
  310. udelay(5);
  311. val1 = REG_RD(bp, BNX2_EMAC_MDIO_COMM);
  312. val1 &= BNX2_EMAC_MDIO_COMM_DATA;
  313. break;
  314. }
  315. }
  316. if (val1 & BNX2_EMAC_MDIO_COMM_START_BUSY) {
  317. *val = 0x0;
  318. ret = -EBUSY;
  319. }
  320. else {
  321. *val = val1;
  322. ret = 0;
  323. }
  324. if (bp->phy_flags & BNX2_PHY_FLAG_INT_MODE_AUTO_POLLING) {
  325. val1 = REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  326. val1 |= BNX2_EMAC_MDIO_MODE_AUTO_POLL;
  327. REG_WR(bp, BNX2_EMAC_MDIO_MODE, val1);
  328. REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  329. udelay(40);
  330. }
  331. return ret;
  332. }
  333. static int
  334. bnx2_write_phy(struct bnx2 *bp, u32 reg, u32 val)
  335. {
  336. u32 val1;
  337. int i, ret;
  338. if (bp->phy_flags & BNX2_PHY_FLAG_INT_MODE_AUTO_POLLING) {
  339. val1 = REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  340. val1 &= ~BNX2_EMAC_MDIO_MODE_AUTO_POLL;
  341. REG_WR(bp, BNX2_EMAC_MDIO_MODE, val1);
  342. REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  343. udelay(40);
  344. }
  345. val1 = (bp->phy_addr << 21) | (reg << 16) | val |
  346. BNX2_EMAC_MDIO_COMM_COMMAND_WRITE |
  347. BNX2_EMAC_MDIO_COMM_START_BUSY | BNX2_EMAC_MDIO_COMM_DISEXT;
  348. REG_WR(bp, BNX2_EMAC_MDIO_COMM, val1);
  349. for (i = 0; i < 50; i++) {
  350. udelay(10);
  351. val1 = REG_RD(bp, BNX2_EMAC_MDIO_COMM);
  352. if (!(val1 & BNX2_EMAC_MDIO_COMM_START_BUSY)) {
  353. udelay(5);
  354. break;
  355. }
  356. }
  357. if (val1 & BNX2_EMAC_MDIO_COMM_START_BUSY)
  358. ret = -EBUSY;
  359. else
  360. ret = 0;
  361. if (bp->phy_flags & BNX2_PHY_FLAG_INT_MODE_AUTO_POLLING) {
  362. val1 = REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  363. val1 |= BNX2_EMAC_MDIO_MODE_AUTO_POLL;
  364. REG_WR(bp, BNX2_EMAC_MDIO_MODE, val1);
  365. REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  366. udelay(40);
  367. }
  368. return ret;
  369. }
  370. static void
  371. bnx2_disable_int(struct bnx2 *bp)
  372. {
  373. int i;
  374. struct bnx2_napi *bnapi;
  375. for (i = 0; i < bp->irq_nvecs; i++) {
  376. bnapi = &bp->bnx2_napi[i];
  377. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD, bnapi->int_num |
  378. BNX2_PCICFG_INT_ACK_CMD_MASK_INT);
  379. }
  380. REG_RD(bp, BNX2_PCICFG_INT_ACK_CMD);
  381. }
  382. static void
  383. bnx2_enable_int(struct bnx2 *bp)
  384. {
  385. int i;
  386. struct bnx2_napi *bnapi;
  387. for (i = 0; i < bp->irq_nvecs; i++) {
  388. bnapi = &bp->bnx2_napi[i];
  389. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD, bnapi->int_num |
  390. BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID |
  391. BNX2_PCICFG_INT_ACK_CMD_MASK_INT |
  392. bnapi->last_status_idx);
  393. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD, bnapi->int_num |
  394. BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID |
  395. bnapi->last_status_idx);
  396. }
  397. REG_WR(bp, BNX2_HC_COMMAND, bp->hc_cmd | BNX2_HC_COMMAND_COAL_NOW);
  398. }
  399. static void
  400. bnx2_disable_int_sync(struct bnx2 *bp)
  401. {
  402. int i;
  403. atomic_inc(&bp->intr_sem);
  404. bnx2_disable_int(bp);
  405. for (i = 0; i < bp->irq_nvecs; i++)
  406. synchronize_irq(bp->irq_tbl[i].vector);
  407. }
  408. static void
  409. bnx2_napi_disable(struct bnx2 *bp)
  410. {
  411. int i;
  412. for (i = 0; i < bp->irq_nvecs; i++)
  413. napi_disable(&bp->bnx2_napi[i].napi);
  414. }
  415. static void
  416. bnx2_napi_enable(struct bnx2 *bp)
  417. {
  418. int i;
  419. for (i = 0; i < bp->irq_nvecs; i++)
  420. napi_enable(&bp->bnx2_napi[i].napi);
  421. }
  422. static void
  423. bnx2_netif_stop(struct bnx2 *bp)
  424. {
  425. bnx2_disable_int_sync(bp);
  426. if (netif_running(bp->dev)) {
  427. bnx2_napi_disable(bp);
  428. netif_tx_disable(bp->dev);
  429. bp->dev->trans_start = jiffies; /* prevent tx timeout */
  430. }
  431. }
  432. static void
  433. bnx2_netif_start(struct bnx2 *bp)
  434. {
  435. if (atomic_dec_and_test(&bp->intr_sem)) {
  436. if (netif_running(bp->dev)) {
  437. netif_tx_wake_all_queues(bp->dev);
  438. bnx2_napi_enable(bp);
  439. bnx2_enable_int(bp);
  440. }
  441. }
  442. }
  443. static void
  444. bnx2_free_tx_mem(struct bnx2 *bp)
  445. {
  446. int i;
  447. for (i = 0; i < bp->num_tx_rings; i++) {
  448. struct bnx2_napi *bnapi = &bp->bnx2_napi[i];
  449. struct bnx2_tx_ring_info *txr = &bnapi->tx_ring;
  450. if (txr->tx_desc_ring) {
  451. pci_free_consistent(bp->pdev, TXBD_RING_SIZE,
  452. txr->tx_desc_ring,
  453. txr->tx_desc_mapping);
  454. txr->tx_desc_ring = NULL;
  455. }
  456. kfree(txr->tx_buf_ring);
  457. txr->tx_buf_ring = NULL;
  458. }
  459. }
  460. static void
  461. bnx2_free_rx_mem(struct bnx2 *bp)
  462. {
  463. int i;
  464. for (i = 0; i < bp->num_rx_rings; i++) {
  465. struct bnx2_napi *bnapi = &bp->bnx2_napi[i];
  466. struct bnx2_rx_ring_info *rxr = &bnapi->rx_ring;
  467. int j;
  468. for (j = 0; j < bp->rx_max_ring; j++) {
  469. if (rxr->rx_desc_ring[j])
  470. pci_free_consistent(bp->pdev, RXBD_RING_SIZE,
  471. rxr->rx_desc_ring[j],
  472. rxr->rx_desc_mapping[j]);
  473. rxr->rx_desc_ring[j] = NULL;
  474. }
  475. if (rxr->rx_buf_ring)
  476. vfree(rxr->rx_buf_ring);
  477. rxr->rx_buf_ring = NULL;
  478. for (j = 0; j < bp->rx_max_pg_ring; j++) {
  479. if (rxr->rx_pg_desc_ring[j])
  480. pci_free_consistent(bp->pdev, RXBD_RING_SIZE,
  481. rxr->rx_pg_desc_ring[j],
  482. rxr->rx_pg_desc_mapping[j]);
  483. rxr->rx_pg_desc_ring[j] = NULL;
  484. }
  485. if (rxr->rx_pg_ring)
  486. vfree(rxr->rx_pg_ring);
  487. rxr->rx_pg_ring = NULL;
  488. }
  489. }
  490. static int
  491. bnx2_alloc_tx_mem(struct bnx2 *bp)
  492. {
  493. int i;
  494. for (i = 0; i < bp->num_tx_rings; i++) {
  495. struct bnx2_napi *bnapi = &bp->bnx2_napi[i];
  496. struct bnx2_tx_ring_info *txr = &bnapi->tx_ring;
  497. txr->tx_buf_ring = kzalloc(SW_TXBD_RING_SIZE, GFP_KERNEL);
  498. if (txr->tx_buf_ring == NULL)
  499. return -ENOMEM;
  500. txr->tx_desc_ring =
  501. pci_alloc_consistent(bp->pdev, TXBD_RING_SIZE,
  502. &txr->tx_desc_mapping);
  503. if (txr->tx_desc_ring == NULL)
  504. return -ENOMEM;
  505. }
  506. return 0;
  507. }
  508. static int
  509. bnx2_alloc_rx_mem(struct bnx2 *bp)
  510. {
  511. int i;
  512. for (i = 0; i < bp->num_rx_rings; i++) {
  513. struct bnx2_napi *bnapi = &bp->bnx2_napi[i];
  514. struct bnx2_rx_ring_info *rxr = &bnapi->rx_ring;
  515. int j;
  516. rxr->rx_buf_ring =
  517. vmalloc(SW_RXBD_RING_SIZE * bp->rx_max_ring);
  518. if (rxr->rx_buf_ring == NULL)
  519. return -ENOMEM;
  520. memset(rxr->rx_buf_ring, 0,
  521. SW_RXBD_RING_SIZE * bp->rx_max_ring);
  522. for (j = 0; j < bp->rx_max_ring; j++) {
  523. rxr->rx_desc_ring[j] =
  524. pci_alloc_consistent(bp->pdev, RXBD_RING_SIZE,
  525. &rxr->rx_desc_mapping[j]);
  526. if (rxr->rx_desc_ring[j] == NULL)
  527. return -ENOMEM;
  528. }
  529. if (bp->rx_pg_ring_size) {
  530. rxr->rx_pg_ring = vmalloc(SW_RXPG_RING_SIZE *
  531. bp->rx_max_pg_ring);
  532. if (rxr->rx_pg_ring == NULL)
  533. return -ENOMEM;
  534. memset(rxr->rx_pg_ring, 0, SW_RXPG_RING_SIZE *
  535. bp->rx_max_pg_ring);
  536. }
  537. for (j = 0; j < bp->rx_max_pg_ring; j++) {
  538. rxr->rx_pg_desc_ring[j] =
  539. pci_alloc_consistent(bp->pdev, RXBD_RING_SIZE,
  540. &rxr->rx_pg_desc_mapping[j]);
  541. if (rxr->rx_pg_desc_ring[j] == NULL)
  542. return -ENOMEM;
  543. }
  544. }
  545. return 0;
  546. }
  547. static void
  548. bnx2_free_mem(struct bnx2 *bp)
  549. {
  550. int i;
  551. struct bnx2_napi *bnapi = &bp->bnx2_napi[0];
  552. bnx2_free_tx_mem(bp);
  553. bnx2_free_rx_mem(bp);
  554. for (i = 0; i < bp->ctx_pages; i++) {
  555. if (bp->ctx_blk[i]) {
  556. pci_free_consistent(bp->pdev, BCM_PAGE_SIZE,
  557. bp->ctx_blk[i],
  558. bp->ctx_blk_mapping[i]);
  559. bp->ctx_blk[i] = NULL;
  560. }
  561. }
  562. if (bnapi->status_blk.msi) {
  563. pci_free_consistent(bp->pdev, bp->status_stats_size,
  564. bnapi->status_blk.msi,
  565. bp->status_blk_mapping);
  566. bnapi->status_blk.msi = NULL;
  567. bp->stats_blk = NULL;
  568. }
  569. }
  570. static int
  571. bnx2_alloc_mem(struct bnx2 *bp)
  572. {
  573. int i, status_blk_size, err;
  574. struct bnx2_napi *bnapi;
  575. void *status_blk;
  576. /* Combine status and statistics blocks into one allocation. */
  577. status_blk_size = L1_CACHE_ALIGN(sizeof(struct status_block));
  578. if (bp->flags & BNX2_FLAG_MSIX_CAP)
  579. status_blk_size = L1_CACHE_ALIGN(BNX2_MAX_MSIX_HW_VEC *
  580. BNX2_SBLK_MSIX_ALIGN_SIZE);
  581. bp->status_stats_size = status_blk_size +
  582. sizeof(struct statistics_block);
  583. status_blk = pci_alloc_consistent(bp->pdev, bp->status_stats_size,
  584. &bp->status_blk_mapping);
  585. if (status_blk == NULL)
  586. goto alloc_mem_err;
  587. memset(status_blk, 0, bp->status_stats_size);
  588. bnapi = &bp->bnx2_napi[0];
  589. bnapi->status_blk.msi = status_blk;
  590. bnapi->hw_tx_cons_ptr =
  591. &bnapi->status_blk.msi->status_tx_quick_consumer_index0;
  592. bnapi->hw_rx_cons_ptr =
  593. &bnapi->status_blk.msi->status_rx_quick_consumer_index0;
  594. if (bp->flags & BNX2_FLAG_MSIX_CAP) {
  595. for (i = 1; i < BNX2_MAX_MSIX_VEC; i++) {
  596. struct status_block_msix *sblk;
  597. bnapi = &bp->bnx2_napi[i];
  598. sblk = (void *) (status_blk +
  599. BNX2_SBLK_MSIX_ALIGN_SIZE * i);
  600. bnapi->status_blk.msix = sblk;
  601. bnapi->hw_tx_cons_ptr =
  602. &sblk->status_tx_quick_consumer_index;
  603. bnapi->hw_rx_cons_ptr =
  604. &sblk->status_rx_quick_consumer_index;
  605. bnapi->int_num = i << 24;
  606. }
  607. }
  608. bp->stats_blk = status_blk + status_blk_size;
  609. bp->stats_blk_mapping = bp->status_blk_mapping + status_blk_size;
  610. if (CHIP_NUM(bp) == CHIP_NUM_5709) {
  611. bp->ctx_pages = 0x2000 / BCM_PAGE_SIZE;
  612. if (bp->ctx_pages == 0)
  613. bp->ctx_pages = 1;
  614. for (i = 0; i < bp->ctx_pages; i++) {
  615. bp->ctx_blk[i] = pci_alloc_consistent(bp->pdev,
  616. BCM_PAGE_SIZE,
  617. &bp->ctx_blk_mapping[i]);
  618. if (bp->ctx_blk[i] == NULL)
  619. goto alloc_mem_err;
  620. }
  621. }
  622. err = bnx2_alloc_rx_mem(bp);
  623. if (err)
  624. goto alloc_mem_err;
  625. err = bnx2_alloc_tx_mem(bp);
  626. if (err)
  627. goto alloc_mem_err;
  628. return 0;
  629. alloc_mem_err:
  630. bnx2_free_mem(bp);
  631. return -ENOMEM;
  632. }
  633. static void
  634. bnx2_report_fw_link(struct bnx2 *bp)
  635. {
  636. u32 fw_link_status = 0;
  637. if (bp->phy_flags & BNX2_PHY_FLAG_REMOTE_PHY_CAP)
  638. return;
  639. if (bp->link_up) {
  640. u32 bmsr;
  641. switch (bp->line_speed) {
  642. case SPEED_10:
  643. if (bp->duplex == DUPLEX_HALF)
  644. fw_link_status = BNX2_LINK_STATUS_10HALF;
  645. else
  646. fw_link_status = BNX2_LINK_STATUS_10FULL;
  647. break;
  648. case SPEED_100:
  649. if (bp->duplex == DUPLEX_HALF)
  650. fw_link_status = BNX2_LINK_STATUS_100HALF;
  651. else
  652. fw_link_status = BNX2_LINK_STATUS_100FULL;
  653. break;
  654. case SPEED_1000:
  655. if (bp->duplex == DUPLEX_HALF)
  656. fw_link_status = BNX2_LINK_STATUS_1000HALF;
  657. else
  658. fw_link_status = BNX2_LINK_STATUS_1000FULL;
  659. break;
  660. case SPEED_2500:
  661. if (bp->duplex == DUPLEX_HALF)
  662. fw_link_status = BNX2_LINK_STATUS_2500HALF;
  663. else
  664. fw_link_status = BNX2_LINK_STATUS_2500FULL;
  665. break;
  666. }
  667. fw_link_status |= BNX2_LINK_STATUS_LINK_UP;
  668. if (bp->autoneg) {
  669. fw_link_status |= BNX2_LINK_STATUS_AN_ENABLED;
  670. bnx2_read_phy(bp, bp->mii_bmsr, &bmsr);
  671. bnx2_read_phy(bp, bp->mii_bmsr, &bmsr);
  672. if (!(bmsr & BMSR_ANEGCOMPLETE) ||
  673. bp->phy_flags & BNX2_PHY_FLAG_PARALLEL_DETECT)
  674. fw_link_status |= BNX2_LINK_STATUS_PARALLEL_DET;
  675. else
  676. fw_link_status |= BNX2_LINK_STATUS_AN_COMPLETE;
  677. }
  678. }
  679. else
  680. fw_link_status = BNX2_LINK_STATUS_LINK_DOWN;
  681. bnx2_shmem_wr(bp, BNX2_LINK_STATUS, fw_link_status);
  682. }
  683. static char *
  684. bnx2_xceiver_str(struct bnx2 *bp)
  685. {
  686. return ((bp->phy_port == PORT_FIBRE) ? "SerDes" :
  687. ((bp->phy_flags & BNX2_PHY_FLAG_SERDES) ? "Remote Copper" :
  688. "Copper"));
  689. }
  690. static void
  691. bnx2_report_link(struct bnx2 *bp)
  692. {
  693. if (bp->link_up) {
  694. netif_carrier_on(bp->dev);
  695. printk(KERN_INFO PFX "%s NIC %s Link is Up, ", bp->dev->name,
  696. bnx2_xceiver_str(bp));
  697. printk("%d Mbps ", bp->line_speed);
  698. if (bp->duplex == DUPLEX_FULL)
  699. printk("full duplex");
  700. else
  701. printk("half duplex");
  702. if (bp->flow_ctrl) {
  703. if (bp->flow_ctrl & FLOW_CTRL_RX) {
  704. printk(", receive ");
  705. if (bp->flow_ctrl & FLOW_CTRL_TX)
  706. printk("& transmit ");
  707. }
  708. else {
  709. printk(", transmit ");
  710. }
  711. printk("flow control ON");
  712. }
  713. printk("\n");
  714. }
  715. else {
  716. netif_carrier_off(bp->dev);
  717. printk(KERN_ERR PFX "%s NIC %s Link is Down\n", bp->dev->name,
  718. bnx2_xceiver_str(bp));
  719. }
  720. bnx2_report_fw_link(bp);
  721. }
  722. static void
  723. bnx2_resolve_flow_ctrl(struct bnx2 *bp)
  724. {
  725. u32 local_adv, remote_adv;
  726. bp->flow_ctrl = 0;
  727. if ((bp->autoneg & (AUTONEG_SPEED | AUTONEG_FLOW_CTRL)) !=
  728. (AUTONEG_SPEED | AUTONEG_FLOW_CTRL)) {
  729. if (bp->duplex == DUPLEX_FULL) {
  730. bp->flow_ctrl = bp->req_flow_ctrl;
  731. }
  732. return;
  733. }
  734. if (bp->duplex != DUPLEX_FULL) {
  735. return;
  736. }
  737. if ((bp->phy_flags & BNX2_PHY_FLAG_SERDES) &&
  738. (CHIP_NUM(bp) == CHIP_NUM_5708)) {
  739. u32 val;
  740. bnx2_read_phy(bp, BCM5708S_1000X_STAT1, &val);
  741. if (val & BCM5708S_1000X_STAT1_TX_PAUSE)
  742. bp->flow_ctrl |= FLOW_CTRL_TX;
  743. if (val & BCM5708S_1000X_STAT1_RX_PAUSE)
  744. bp->flow_ctrl |= FLOW_CTRL_RX;
  745. return;
  746. }
  747. bnx2_read_phy(bp, bp->mii_adv, &local_adv);
  748. bnx2_read_phy(bp, bp->mii_lpa, &remote_adv);
  749. if (bp->phy_flags & BNX2_PHY_FLAG_SERDES) {
  750. u32 new_local_adv = 0;
  751. u32 new_remote_adv = 0;
  752. if (local_adv & ADVERTISE_1000XPAUSE)
  753. new_local_adv |= ADVERTISE_PAUSE_CAP;
  754. if (local_adv & ADVERTISE_1000XPSE_ASYM)
  755. new_local_adv |= ADVERTISE_PAUSE_ASYM;
  756. if (remote_adv & ADVERTISE_1000XPAUSE)
  757. new_remote_adv |= ADVERTISE_PAUSE_CAP;
  758. if (remote_adv & ADVERTISE_1000XPSE_ASYM)
  759. new_remote_adv |= ADVERTISE_PAUSE_ASYM;
  760. local_adv = new_local_adv;
  761. remote_adv = new_remote_adv;
  762. }
  763. /* See Table 28B-3 of 802.3ab-1999 spec. */
  764. if (local_adv & ADVERTISE_PAUSE_CAP) {
  765. if(local_adv & ADVERTISE_PAUSE_ASYM) {
  766. if (remote_adv & ADVERTISE_PAUSE_CAP) {
  767. bp->flow_ctrl = FLOW_CTRL_TX | FLOW_CTRL_RX;
  768. }
  769. else if (remote_adv & ADVERTISE_PAUSE_ASYM) {
  770. bp->flow_ctrl = FLOW_CTRL_RX;
  771. }
  772. }
  773. else {
  774. if (remote_adv & ADVERTISE_PAUSE_CAP) {
  775. bp->flow_ctrl = FLOW_CTRL_TX | FLOW_CTRL_RX;
  776. }
  777. }
  778. }
  779. else if (local_adv & ADVERTISE_PAUSE_ASYM) {
  780. if ((remote_adv & ADVERTISE_PAUSE_CAP) &&
  781. (remote_adv & ADVERTISE_PAUSE_ASYM)) {
  782. bp->flow_ctrl = FLOW_CTRL_TX;
  783. }
  784. }
  785. }
  786. static int
  787. bnx2_5709s_linkup(struct bnx2 *bp)
  788. {
  789. u32 val, speed;
  790. bp->link_up = 1;
  791. bnx2_write_phy(bp, MII_BNX2_BLK_ADDR, MII_BNX2_BLK_ADDR_GP_STATUS);
  792. bnx2_read_phy(bp, MII_BNX2_GP_TOP_AN_STATUS1, &val);
  793. bnx2_write_phy(bp, MII_BNX2_BLK_ADDR, MII_BNX2_BLK_ADDR_COMBO_IEEEB0);
  794. if ((bp->autoneg & AUTONEG_SPEED) == 0) {
  795. bp->line_speed = bp->req_line_speed;
  796. bp->duplex = bp->req_duplex;
  797. return 0;
  798. }
  799. speed = val & MII_BNX2_GP_TOP_AN_SPEED_MSK;
  800. switch (speed) {
  801. case MII_BNX2_GP_TOP_AN_SPEED_10:
  802. bp->line_speed = SPEED_10;
  803. break;
  804. case MII_BNX2_GP_TOP_AN_SPEED_100:
  805. bp->line_speed = SPEED_100;
  806. break;
  807. case MII_BNX2_GP_TOP_AN_SPEED_1G:
  808. case MII_BNX2_GP_TOP_AN_SPEED_1GKV:
  809. bp->line_speed = SPEED_1000;
  810. break;
  811. case MII_BNX2_GP_TOP_AN_SPEED_2_5G:
  812. bp->line_speed = SPEED_2500;
  813. break;
  814. }
  815. if (val & MII_BNX2_GP_TOP_AN_FD)
  816. bp->duplex = DUPLEX_FULL;
  817. else
  818. bp->duplex = DUPLEX_HALF;
  819. return 0;
  820. }
  821. static int
  822. bnx2_5708s_linkup(struct bnx2 *bp)
  823. {
  824. u32 val;
  825. bp->link_up = 1;
  826. bnx2_read_phy(bp, BCM5708S_1000X_STAT1, &val);
  827. switch (val & BCM5708S_1000X_STAT1_SPEED_MASK) {
  828. case BCM5708S_1000X_STAT1_SPEED_10:
  829. bp->line_speed = SPEED_10;
  830. break;
  831. case BCM5708S_1000X_STAT1_SPEED_100:
  832. bp->line_speed = SPEED_100;
  833. break;
  834. case BCM5708S_1000X_STAT1_SPEED_1G:
  835. bp->line_speed = SPEED_1000;
  836. break;
  837. case BCM5708S_1000X_STAT1_SPEED_2G5:
  838. bp->line_speed = SPEED_2500;
  839. break;
  840. }
  841. if (val & BCM5708S_1000X_STAT1_FD)
  842. bp->duplex = DUPLEX_FULL;
  843. else
  844. bp->duplex = DUPLEX_HALF;
  845. return 0;
  846. }
  847. static int
  848. bnx2_5706s_linkup(struct bnx2 *bp)
  849. {
  850. u32 bmcr, local_adv, remote_adv, common;
  851. bp->link_up = 1;
  852. bp->line_speed = SPEED_1000;
  853. bnx2_read_phy(bp, bp->mii_bmcr, &bmcr);
  854. if (bmcr & BMCR_FULLDPLX) {
  855. bp->duplex = DUPLEX_FULL;
  856. }
  857. else {
  858. bp->duplex = DUPLEX_HALF;
  859. }
  860. if (!(bmcr & BMCR_ANENABLE)) {
  861. return 0;
  862. }
  863. bnx2_read_phy(bp, bp->mii_adv, &local_adv);
  864. bnx2_read_phy(bp, bp->mii_lpa, &remote_adv);
  865. common = local_adv & remote_adv;
  866. if (common & (ADVERTISE_1000XHALF | ADVERTISE_1000XFULL)) {
  867. if (common & ADVERTISE_1000XFULL) {
  868. bp->duplex = DUPLEX_FULL;
  869. }
  870. else {
  871. bp->duplex = DUPLEX_HALF;
  872. }
  873. }
  874. return 0;
  875. }
  876. static int
  877. bnx2_copper_linkup(struct bnx2 *bp)
  878. {
  879. u32 bmcr;
  880. bnx2_read_phy(bp, bp->mii_bmcr, &bmcr);
  881. if (bmcr & BMCR_ANENABLE) {
  882. u32 local_adv, remote_adv, common;
  883. bnx2_read_phy(bp, MII_CTRL1000, &local_adv);
  884. bnx2_read_phy(bp, MII_STAT1000, &remote_adv);
  885. common = local_adv & (remote_adv >> 2);
  886. if (common & ADVERTISE_1000FULL) {
  887. bp->line_speed = SPEED_1000;
  888. bp->duplex = DUPLEX_FULL;
  889. }
  890. else if (common & ADVERTISE_1000HALF) {
  891. bp->line_speed = SPEED_1000;
  892. bp->duplex = DUPLEX_HALF;
  893. }
  894. else {
  895. bnx2_read_phy(bp, bp->mii_adv, &local_adv);
  896. bnx2_read_phy(bp, bp->mii_lpa, &remote_adv);
  897. common = local_adv & remote_adv;
  898. if (common & ADVERTISE_100FULL) {
  899. bp->line_speed = SPEED_100;
  900. bp->duplex = DUPLEX_FULL;
  901. }
  902. else if (common & ADVERTISE_100HALF) {
  903. bp->line_speed = SPEED_100;
  904. bp->duplex = DUPLEX_HALF;
  905. }
  906. else if (common & ADVERTISE_10FULL) {
  907. bp->line_speed = SPEED_10;
  908. bp->duplex = DUPLEX_FULL;
  909. }
  910. else if (common & ADVERTISE_10HALF) {
  911. bp->line_speed = SPEED_10;
  912. bp->duplex = DUPLEX_HALF;
  913. }
  914. else {
  915. bp->line_speed = 0;
  916. bp->link_up = 0;
  917. }
  918. }
  919. }
  920. else {
  921. if (bmcr & BMCR_SPEED100) {
  922. bp->line_speed = SPEED_100;
  923. }
  924. else {
  925. bp->line_speed = SPEED_10;
  926. }
  927. if (bmcr & BMCR_FULLDPLX) {
  928. bp->duplex = DUPLEX_FULL;
  929. }
  930. else {
  931. bp->duplex = DUPLEX_HALF;
  932. }
  933. }
  934. return 0;
  935. }
  936. static void
  937. bnx2_init_rx_context(struct bnx2 *bp, u32 cid)
  938. {
  939. u32 val, rx_cid_addr = GET_CID_ADDR(cid);
  940. val = BNX2_L2CTX_CTX_TYPE_CTX_BD_CHN_TYPE_VALUE;
  941. val |= BNX2_L2CTX_CTX_TYPE_SIZE_L2;
  942. val |= 0x02 << 8;
  943. if (CHIP_NUM(bp) == CHIP_NUM_5709) {
  944. u32 lo_water, hi_water;
  945. if (bp->flow_ctrl & FLOW_CTRL_TX)
  946. lo_water = BNX2_L2CTX_LO_WATER_MARK_DEFAULT;
  947. else
  948. lo_water = BNX2_L2CTX_LO_WATER_MARK_DIS;
  949. if (lo_water >= bp->rx_ring_size)
  950. lo_water = 0;
  951. hi_water = bp->rx_ring_size / 4;
  952. if (hi_water <= lo_water)
  953. lo_water = 0;
  954. hi_water /= BNX2_L2CTX_HI_WATER_MARK_SCALE;
  955. lo_water /= BNX2_L2CTX_LO_WATER_MARK_SCALE;
  956. if (hi_water > 0xf)
  957. hi_water = 0xf;
  958. else if (hi_water == 0)
  959. lo_water = 0;
  960. val |= lo_water | (hi_water << BNX2_L2CTX_HI_WATER_MARK_SHIFT);
  961. }
  962. bnx2_ctx_wr(bp, rx_cid_addr, BNX2_L2CTX_CTX_TYPE, val);
  963. }
  964. static void
  965. bnx2_init_all_rx_contexts(struct bnx2 *bp)
  966. {
  967. int i;
  968. u32 cid;
  969. for (i = 0, cid = RX_CID; i < bp->num_rx_rings; i++, cid++) {
  970. if (i == 1)
  971. cid = RX_RSS_CID;
  972. bnx2_init_rx_context(bp, cid);
  973. }
  974. }
  975. static void
  976. bnx2_set_mac_link(struct bnx2 *bp)
  977. {
  978. u32 val;
  979. REG_WR(bp, BNX2_EMAC_TX_LENGTHS, 0x2620);
  980. if (bp->link_up && (bp->line_speed == SPEED_1000) &&
  981. (bp->duplex == DUPLEX_HALF)) {
  982. REG_WR(bp, BNX2_EMAC_TX_LENGTHS, 0x26ff);
  983. }
  984. /* Configure the EMAC mode register. */
  985. val = REG_RD(bp, BNX2_EMAC_MODE);
  986. val &= ~(BNX2_EMAC_MODE_PORT | BNX2_EMAC_MODE_HALF_DUPLEX |
  987. BNX2_EMAC_MODE_MAC_LOOP | BNX2_EMAC_MODE_FORCE_LINK |
  988. BNX2_EMAC_MODE_25G_MODE);
  989. if (bp->link_up) {
  990. switch (bp->line_speed) {
  991. case SPEED_10:
  992. if (CHIP_NUM(bp) != CHIP_NUM_5706) {
  993. val |= BNX2_EMAC_MODE_PORT_MII_10M;
  994. break;
  995. }
  996. /* fall through */
  997. case SPEED_100:
  998. val |= BNX2_EMAC_MODE_PORT_MII;
  999. break;
  1000. case SPEED_2500:
  1001. val |= BNX2_EMAC_MODE_25G_MODE;
  1002. /* fall through */
  1003. case SPEED_1000:
  1004. val |= BNX2_EMAC_MODE_PORT_GMII;
  1005. break;
  1006. }
  1007. }
  1008. else {
  1009. val |= BNX2_EMAC_MODE_PORT_GMII;
  1010. }
  1011. /* Set the MAC to operate in the appropriate duplex mode. */
  1012. if (bp->duplex == DUPLEX_HALF)
  1013. val |= BNX2_EMAC_MODE_HALF_DUPLEX;
  1014. REG_WR(bp, BNX2_EMAC_MODE, val);
  1015. /* Enable/disable rx PAUSE. */
  1016. bp->rx_mode &= ~BNX2_EMAC_RX_MODE_FLOW_EN;
  1017. if (bp->flow_ctrl & FLOW_CTRL_RX)
  1018. bp->rx_mode |= BNX2_EMAC_RX_MODE_FLOW_EN;
  1019. REG_WR(bp, BNX2_EMAC_RX_MODE, bp->rx_mode);
  1020. /* Enable/disable tx PAUSE. */
  1021. val = REG_RD(bp, BNX2_EMAC_TX_MODE);
  1022. val &= ~BNX2_EMAC_TX_MODE_FLOW_EN;
  1023. if (bp->flow_ctrl & FLOW_CTRL_TX)
  1024. val |= BNX2_EMAC_TX_MODE_FLOW_EN;
  1025. REG_WR(bp, BNX2_EMAC_TX_MODE, val);
  1026. /* Acknowledge the interrupt. */
  1027. REG_WR(bp, BNX2_EMAC_STATUS, BNX2_EMAC_STATUS_LINK_CHANGE);
  1028. if (CHIP_NUM(bp) == CHIP_NUM_5709)
  1029. bnx2_init_all_rx_contexts(bp);
  1030. }
  1031. static void
  1032. bnx2_enable_bmsr1(struct bnx2 *bp)
  1033. {
  1034. if ((bp->phy_flags & BNX2_PHY_FLAG_SERDES) &&
  1035. (CHIP_NUM(bp) == CHIP_NUM_5709))
  1036. bnx2_write_phy(bp, MII_BNX2_BLK_ADDR,
  1037. MII_BNX2_BLK_ADDR_GP_STATUS);
  1038. }
  1039. static void
  1040. bnx2_disable_bmsr1(struct bnx2 *bp)
  1041. {
  1042. if ((bp->phy_flags & BNX2_PHY_FLAG_SERDES) &&
  1043. (CHIP_NUM(bp) == CHIP_NUM_5709))
  1044. bnx2_write_phy(bp, MII_BNX2_BLK_ADDR,
  1045. MII_BNX2_BLK_ADDR_COMBO_IEEEB0);
  1046. }
  1047. static int
  1048. bnx2_test_and_enable_2g5(struct bnx2 *bp)
  1049. {
  1050. u32 up1;
  1051. int ret = 1;
  1052. if (!(bp->phy_flags & BNX2_PHY_FLAG_2_5G_CAPABLE))
  1053. return 0;
  1054. if (bp->autoneg & AUTONEG_SPEED)
  1055. bp->advertising |= ADVERTISED_2500baseX_Full;
  1056. if (CHIP_NUM(bp) == CHIP_NUM_5709)
  1057. bnx2_write_phy(bp, MII_BNX2_BLK_ADDR, MII_BNX2_BLK_ADDR_OVER1G);
  1058. bnx2_read_phy(bp, bp->mii_up1, &up1);
  1059. if (!(up1 & BCM5708S_UP1_2G5)) {
  1060. up1 |= BCM5708S_UP1_2G5;
  1061. bnx2_write_phy(bp, bp->mii_up1, up1);
  1062. ret = 0;
  1063. }
  1064. if (CHIP_NUM(bp) == CHIP_NUM_5709)
  1065. bnx2_write_phy(bp, MII_BNX2_BLK_ADDR,
  1066. MII_BNX2_BLK_ADDR_COMBO_IEEEB0);
  1067. return ret;
  1068. }
  1069. static int
  1070. bnx2_test_and_disable_2g5(struct bnx2 *bp)
  1071. {
  1072. u32 up1;
  1073. int ret = 0;
  1074. if (!(bp->phy_flags & BNX2_PHY_FLAG_2_5G_CAPABLE))
  1075. return 0;
  1076. if (CHIP_NUM(bp) == CHIP_NUM_5709)
  1077. bnx2_write_phy(bp, MII_BNX2_BLK_ADDR, MII_BNX2_BLK_ADDR_OVER1G);
  1078. bnx2_read_phy(bp, bp->mii_up1, &up1);
  1079. if (up1 & BCM5708S_UP1_2G5) {
  1080. up1 &= ~BCM5708S_UP1_2G5;
  1081. bnx2_write_phy(bp, bp->mii_up1, up1);
  1082. ret = 1;
  1083. }
  1084. if (CHIP_NUM(bp) == CHIP_NUM_5709)
  1085. bnx2_write_phy(bp, MII_BNX2_BLK_ADDR,
  1086. MII_BNX2_BLK_ADDR_COMBO_IEEEB0);
  1087. return ret;
  1088. }
  1089. static void
  1090. bnx2_enable_forced_2g5(struct bnx2 *bp)
  1091. {
  1092. u32 bmcr;
  1093. if (!(bp->phy_flags & BNX2_PHY_FLAG_2_5G_CAPABLE))
  1094. return;
  1095. if (CHIP_NUM(bp) == CHIP_NUM_5709) {
  1096. u32 val;
  1097. bnx2_write_phy(bp, MII_BNX2_BLK_ADDR,
  1098. MII_BNX2_BLK_ADDR_SERDES_DIG);
  1099. bnx2_read_phy(bp, MII_BNX2_SERDES_DIG_MISC1, &val);
  1100. val &= ~MII_BNX2_SD_MISC1_FORCE_MSK;
  1101. val |= MII_BNX2_SD_MISC1_FORCE | MII_BNX2_SD_MISC1_FORCE_2_5G;
  1102. bnx2_write_phy(bp, MII_BNX2_SERDES_DIG_MISC1, val);
  1103. bnx2_write_phy(bp, MII_BNX2_BLK_ADDR,
  1104. MII_BNX2_BLK_ADDR_COMBO_IEEEB0);
  1105. bnx2_read_phy(bp, bp->mii_bmcr, &bmcr);
  1106. } else if (CHIP_NUM(bp) == CHIP_NUM_5708) {
  1107. bnx2_read_phy(bp, bp->mii_bmcr, &bmcr);
  1108. bmcr |= BCM5708S_BMCR_FORCE_2500;
  1109. }
  1110. if (bp->autoneg & AUTONEG_SPEED) {
  1111. bmcr &= ~BMCR_ANENABLE;
  1112. if (bp->req_duplex == DUPLEX_FULL)
  1113. bmcr |= BMCR_FULLDPLX;
  1114. }
  1115. bnx2_write_phy(bp, bp->mii_bmcr, bmcr);
  1116. }
  1117. static void
  1118. bnx2_disable_forced_2g5(struct bnx2 *bp)
  1119. {
  1120. u32 bmcr;
  1121. if (!(bp->phy_flags & BNX2_PHY_FLAG_2_5G_CAPABLE))
  1122. return;
  1123. if (CHIP_NUM(bp) == CHIP_NUM_5709) {
  1124. u32 val;
  1125. bnx2_write_phy(bp, MII_BNX2_BLK_ADDR,
  1126. MII_BNX2_BLK_ADDR_SERDES_DIG);
  1127. bnx2_read_phy(bp, MII_BNX2_SERDES_DIG_MISC1, &val);
  1128. val &= ~MII_BNX2_SD_MISC1_FORCE;
  1129. bnx2_write_phy(bp, MII_BNX2_SERDES_DIG_MISC1, val);
  1130. bnx2_write_phy(bp, MII_BNX2_BLK_ADDR,
  1131. MII_BNX2_BLK_ADDR_COMBO_IEEEB0);
  1132. bnx2_read_phy(bp, bp->mii_bmcr, &bmcr);
  1133. } else if (CHIP_NUM(bp) == CHIP_NUM_5708) {
  1134. bnx2_read_phy(bp, bp->mii_bmcr, &bmcr);
  1135. bmcr &= ~BCM5708S_BMCR_FORCE_2500;
  1136. }
  1137. if (bp->autoneg & AUTONEG_SPEED)
  1138. bmcr |= BMCR_SPEED1000 | BMCR_ANENABLE | BMCR_ANRESTART;
  1139. bnx2_write_phy(bp, bp->mii_bmcr, bmcr);
  1140. }
  1141. static void
  1142. bnx2_5706s_force_link_dn(struct bnx2 *bp, int start)
  1143. {
  1144. u32 val;
  1145. bnx2_write_phy(bp, MII_BNX2_DSP_ADDRESS, MII_EXPAND_SERDES_CTL);
  1146. bnx2_read_phy(bp, MII_BNX2_DSP_RW_PORT, &val);
  1147. if (start)
  1148. bnx2_write_phy(bp, MII_BNX2_DSP_RW_PORT, val & 0xff0f);
  1149. else
  1150. bnx2_write_phy(bp, MII_BNX2_DSP_RW_PORT, val | 0xc0);
  1151. }
  1152. static int
  1153. bnx2_set_link(struct bnx2 *bp)
  1154. {
  1155. u32 bmsr;
  1156. u8 link_up;
  1157. if (bp->loopback == MAC_LOOPBACK || bp->loopback == PHY_LOOPBACK) {
  1158. bp->link_up = 1;
  1159. return 0;
  1160. }
  1161. if (bp->phy_flags & BNX2_PHY_FLAG_REMOTE_PHY_CAP)
  1162. return 0;
  1163. link_up = bp->link_up;
  1164. bnx2_enable_bmsr1(bp);
  1165. bnx2_read_phy(bp, bp->mii_bmsr1, &bmsr);
  1166. bnx2_read_phy(bp, bp->mii_bmsr1, &bmsr);
  1167. bnx2_disable_bmsr1(bp);
  1168. if ((bp->phy_flags & BNX2_PHY_FLAG_SERDES) &&
  1169. (CHIP_NUM(bp) == CHIP_NUM_5706)) {
  1170. u32 val, an_dbg;
  1171. if (bp->phy_flags & BNX2_PHY_FLAG_FORCED_DOWN) {
  1172. bnx2_5706s_force_link_dn(bp, 0);
  1173. bp->phy_flags &= ~BNX2_PHY_FLAG_FORCED_DOWN;
  1174. }
  1175. val = REG_RD(bp, BNX2_EMAC_STATUS);
  1176. bnx2_write_phy(bp, MII_BNX2_MISC_SHADOW, MISC_SHDW_AN_DBG);
  1177. bnx2_read_phy(bp, MII_BNX2_MISC_SHADOW, &an_dbg);
  1178. bnx2_read_phy(bp, MII_BNX2_MISC_SHADOW, &an_dbg);
  1179. if ((val & BNX2_EMAC_STATUS_LINK) &&
  1180. !(an_dbg & MISC_SHDW_AN_DBG_NOSYNC))
  1181. bmsr |= BMSR_LSTATUS;
  1182. else
  1183. bmsr &= ~BMSR_LSTATUS;
  1184. }
  1185. if (bmsr & BMSR_LSTATUS) {
  1186. bp->link_up = 1;
  1187. if (bp->phy_flags & BNX2_PHY_FLAG_SERDES) {
  1188. if (CHIP_NUM(bp) == CHIP_NUM_5706)
  1189. bnx2_5706s_linkup(bp);
  1190. else if (CHIP_NUM(bp) == CHIP_NUM_5708)
  1191. bnx2_5708s_linkup(bp);
  1192. else if (CHIP_NUM(bp) == CHIP_NUM_5709)
  1193. bnx2_5709s_linkup(bp);
  1194. }
  1195. else {
  1196. bnx2_copper_linkup(bp);
  1197. }
  1198. bnx2_resolve_flow_ctrl(bp);
  1199. }
  1200. else {
  1201. if ((bp->phy_flags & BNX2_PHY_FLAG_SERDES) &&
  1202. (bp->autoneg & AUTONEG_SPEED))
  1203. bnx2_disable_forced_2g5(bp);
  1204. if (bp->phy_flags & BNX2_PHY_FLAG_PARALLEL_DETECT) {
  1205. u32 bmcr;
  1206. bnx2_read_phy(bp, bp->mii_bmcr, &bmcr);
  1207. bmcr |= BMCR_ANENABLE;
  1208. bnx2_write_phy(bp, bp->mii_bmcr, bmcr);
  1209. bp->phy_flags &= ~BNX2_PHY_FLAG_PARALLEL_DETECT;
  1210. }
  1211. bp->link_up = 0;
  1212. }
  1213. if (bp->link_up != link_up) {
  1214. bnx2_report_link(bp);
  1215. }
  1216. bnx2_set_mac_link(bp);
  1217. return 0;
  1218. }
  1219. static int
  1220. bnx2_reset_phy(struct bnx2 *bp)
  1221. {
  1222. int i;
  1223. u32 reg;
  1224. bnx2_write_phy(bp, bp->mii_bmcr, BMCR_RESET);
  1225. #define PHY_RESET_MAX_WAIT 100
  1226. for (i = 0; i < PHY_RESET_MAX_WAIT; i++) {
  1227. udelay(10);
  1228. bnx2_read_phy(bp, bp->mii_bmcr, &reg);
  1229. if (!(reg & BMCR_RESET)) {
  1230. udelay(20);
  1231. break;
  1232. }
  1233. }
  1234. if (i == PHY_RESET_MAX_WAIT) {
  1235. return -EBUSY;
  1236. }
  1237. return 0;
  1238. }
  1239. static u32
  1240. bnx2_phy_get_pause_adv(struct bnx2 *bp)
  1241. {
  1242. u32 adv = 0;
  1243. if ((bp->req_flow_ctrl & (FLOW_CTRL_RX | FLOW_CTRL_TX)) ==
  1244. (FLOW_CTRL_RX | FLOW_CTRL_TX)) {
  1245. if (bp->phy_flags & BNX2_PHY_FLAG_SERDES) {
  1246. adv = ADVERTISE_1000XPAUSE;
  1247. }
  1248. else {
  1249. adv = ADVERTISE_PAUSE_CAP;
  1250. }
  1251. }
  1252. else if (bp->req_flow_ctrl & FLOW_CTRL_TX) {
  1253. if (bp->phy_flags & BNX2_PHY_FLAG_SERDES) {
  1254. adv = ADVERTISE_1000XPSE_ASYM;
  1255. }
  1256. else {
  1257. adv = ADVERTISE_PAUSE_ASYM;
  1258. }
  1259. }
  1260. else if (bp->req_flow_ctrl & FLOW_CTRL_RX) {
  1261. if (bp->phy_flags & BNX2_PHY_FLAG_SERDES) {
  1262. adv = ADVERTISE_1000XPAUSE | ADVERTISE_1000XPSE_ASYM;
  1263. }
  1264. else {
  1265. adv = ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
  1266. }
  1267. }
  1268. return adv;
  1269. }
  1270. static int bnx2_fw_sync(struct bnx2 *, u32, int, int);
  1271. static int
  1272. bnx2_setup_remote_phy(struct bnx2 *bp, u8 port)
  1273. __releases(&bp->phy_lock)
  1274. __acquires(&bp->phy_lock)
  1275. {
  1276. u32 speed_arg = 0, pause_adv;
  1277. pause_adv = bnx2_phy_get_pause_adv(bp);
  1278. if (bp->autoneg & AUTONEG_SPEED) {
  1279. speed_arg |= BNX2_NETLINK_SET_LINK_ENABLE_AUTONEG;
  1280. if (bp->advertising & ADVERTISED_10baseT_Half)
  1281. speed_arg |= BNX2_NETLINK_SET_LINK_SPEED_10HALF;
  1282. if (bp->advertising & ADVERTISED_10baseT_Full)
  1283. speed_arg |= BNX2_NETLINK_SET_LINK_SPEED_10FULL;
  1284. if (bp->advertising & ADVERTISED_100baseT_Half)
  1285. speed_arg |= BNX2_NETLINK_SET_LINK_SPEED_100HALF;
  1286. if (bp->advertising & ADVERTISED_100baseT_Full)
  1287. speed_arg |= BNX2_NETLINK_SET_LINK_SPEED_100FULL;
  1288. if (bp->advertising & ADVERTISED_1000baseT_Full)
  1289. speed_arg |= BNX2_NETLINK_SET_LINK_SPEED_1GFULL;
  1290. if (bp->advertising & ADVERTISED_2500baseX_Full)
  1291. speed_arg |= BNX2_NETLINK_SET_LINK_SPEED_2G5FULL;
  1292. } else {
  1293. if (bp->req_line_speed == SPEED_2500)
  1294. speed_arg = BNX2_NETLINK_SET_LINK_SPEED_2G5FULL;
  1295. else if (bp->req_line_speed == SPEED_1000)
  1296. speed_arg = BNX2_NETLINK_SET_LINK_SPEED_1GFULL;
  1297. else if (bp->req_line_speed == SPEED_100) {
  1298. if (bp->req_duplex == DUPLEX_FULL)
  1299. speed_arg = BNX2_NETLINK_SET_LINK_SPEED_100FULL;
  1300. else
  1301. speed_arg = BNX2_NETLINK_SET_LINK_SPEED_100HALF;
  1302. } else if (bp->req_line_speed == SPEED_10) {
  1303. if (bp->req_duplex == DUPLEX_FULL)
  1304. speed_arg = BNX2_NETLINK_SET_LINK_SPEED_10FULL;
  1305. else
  1306. speed_arg = BNX2_NETLINK_SET_LINK_SPEED_10HALF;
  1307. }
  1308. }
  1309. if (pause_adv & (ADVERTISE_1000XPAUSE | ADVERTISE_PAUSE_CAP))
  1310. speed_arg |= BNX2_NETLINK_SET_LINK_FC_SYM_PAUSE;
  1311. if (pause_adv & (ADVERTISE_1000XPSE_ASYM | ADVERTISE_PAUSE_ASYM))
  1312. speed_arg |= BNX2_NETLINK_SET_LINK_FC_ASYM_PAUSE;
  1313. if (port == PORT_TP)
  1314. speed_arg |= BNX2_NETLINK_SET_LINK_PHY_APP_REMOTE |
  1315. BNX2_NETLINK_SET_LINK_ETH_AT_WIRESPEED;
  1316. bnx2_shmem_wr(bp, BNX2_DRV_MB_ARG0, speed_arg);
  1317. spin_unlock_bh(&bp->phy_lock);
  1318. bnx2_fw_sync(bp, BNX2_DRV_MSG_CODE_CMD_SET_LINK, 1, 0);
  1319. spin_lock_bh(&bp->phy_lock);
  1320. return 0;
  1321. }
  1322. static int
  1323. bnx2_setup_serdes_phy(struct bnx2 *bp, u8 port)
  1324. __releases(&bp->phy_lock)
  1325. __acquires(&bp->phy_lock)
  1326. {
  1327. u32 adv, bmcr;
  1328. u32 new_adv = 0;
  1329. if (bp->phy_flags & BNX2_PHY_FLAG_REMOTE_PHY_CAP)
  1330. return (bnx2_setup_remote_phy(bp, port));
  1331. if (!(bp->autoneg & AUTONEG_SPEED)) {
  1332. u32 new_bmcr;
  1333. int force_link_down = 0;
  1334. if (bp->req_line_speed == SPEED_2500) {
  1335. if (!bnx2_test_and_enable_2g5(bp))
  1336. force_link_down = 1;
  1337. } else if (bp->req_line_speed == SPEED_1000) {
  1338. if (bnx2_test_and_disable_2g5(bp))
  1339. force_link_down = 1;
  1340. }
  1341. bnx2_read_phy(bp, bp->mii_adv, &adv);
  1342. adv &= ~(ADVERTISE_1000XFULL | ADVERTISE_1000XHALF);
  1343. bnx2_read_phy(bp, bp->mii_bmcr, &bmcr);
  1344. new_bmcr = bmcr & ~BMCR_ANENABLE;
  1345. new_bmcr |= BMCR_SPEED1000;
  1346. if (CHIP_NUM(bp) == CHIP_NUM_5709) {
  1347. if (bp->req_line_speed == SPEED_2500)
  1348. bnx2_enable_forced_2g5(bp);
  1349. else if (bp->req_line_speed == SPEED_1000) {
  1350. bnx2_disable_forced_2g5(bp);
  1351. new_bmcr &= ~0x2000;
  1352. }
  1353. } else if (CHIP_NUM(bp) == CHIP_NUM_5708) {
  1354. if (bp->req_line_speed == SPEED_2500)
  1355. new_bmcr |= BCM5708S_BMCR_FORCE_2500;
  1356. else
  1357. new_bmcr = bmcr & ~BCM5708S_BMCR_FORCE_2500;
  1358. }
  1359. if (bp->req_duplex == DUPLEX_FULL) {
  1360. adv |= ADVERTISE_1000XFULL;
  1361. new_bmcr |= BMCR_FULLDPLX;
  1362. }
  1363. else {
  1364. adv |= ADVERTISE_1000XHALF;
  1365. new_bmcr &= ~BMCR_FULLDPLX;
  1366. }
  1367. if ((new_bmcr != bmcr) || (force_link_down)) {
  1368. /* Force a link down visible on the other side */
  1369. if (bp->link_up) {
  1370. bnx2_write_phy(bp, bp->mii_adv, adv &
  1371. ~(ADVERTISE_1000XFULL |
  1372. ADVERTISE_1000XHALF));
  1373. bnx2_write_phy(bp, bp->mii_bmcr, bmcr |
  1374. BMCR_ANRESTART | BMCR_ANENABLE);
  1375. bp->link_up = 0;
  1376. netif_carrier_off(bp->dev);
  1377. bnx2_write_phy(bp, bp->mii_bmcr, new_bmcr);
  1378. bnx2_report_link(bp);
  1379. }
  1380. bnx2_write_phy(bp, bp->mii_adv, adv);
  1381. bnx2_write_phy(bp, bp->mii_bmcr, new_bmcr);
  1382. } else {
  1383. bnx2_resolve_flow_ctrl(bp);
  1384. bnx2_set_mac_link(bp);
  1385. }
  1386. return 0;
  1387. }
  1388. bnx2_test_and_enable_2g5(bp);
  1389. if (bp->advertising & ADVERTISED_1000baseT_Full)
  1390. new_adv |= ADVERTISE_1000XFULL;
  1391. new_adv |= bnx2_phy_get_pause_adv(bp);
  1392. bnx2_read_phy(bp, bp->mii_adv, &adv);
  1393. bnx2_read_phy(bp, bp->mii_bmcr, &bmcr);
  1394. bp->serdes_an_pending = 0;
  1395. if ((adv != new_adv) || ((bmcr & BMCR_ANENABLE) == 0)) {
  1396. /* Force a link down visible on the other side */
  1397. if (bp->link_up) {
  1398. bnx2_write_phy(bp, bp->mii_bmcr, BMCR_LOOPBACK);
  1399. spin_unlock_bh(&bp->phy_lock);
  1400. msleep(20);
  1401. spin_lock_bh(&bp->phy_lock);
  1402. }
  1403. bnx2_write_phy(bp, bp->mii_adv, new_adv);
  1404. bnx2_write_phy(bp, bp->mii_bmcr, bmcr | BMCR_ANRESTART |
  1405. BMCR_ANENABLE);
  1406. /* Speed up link-up time when the link partner
  1407. * does not autonegotiate which is very common
  1408. * in blade servers. Some blade servers use
  1409. * IPMI for kerboard input and it's important
  1410. * to minimize link disruptions. Autoneg. involves
  1411. * exchanging base pages plus 3 next pages and
  1412. * normally completes in about 120 msec.
  1413. */
  1414. bp->current_interval = BNX2_SERDES_AN_TIMEOUT;
  1415. bp->serdes_an_pending = 1;
  1416. mod_timer(&bp->timer, jiffies + bp->current_interval);
  1417. } else {
  1418. bnx2_resolve_flow_ctrl(bp);
  1419. bnx2_set_mac_link(bp);
  1420. }
  1421. return 0;
  1422. }
  1423. #define ETHTOOL_ALL_FIBRE_SPEED \
  1424. (bp->phy_flags & BNX2_PHY_FLAG_2_5G_CAPABLE) ? \
  1425. (ADVERTISED_2500baseX_Full | ADVERTISED_1000baseT_Full) :\
  1426. (ADVERTISED_1000baseT_Full)
  1427. #define ETHTOOL_ALL_COPPER_SPEED \
  1428. (ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full | \
  1429. ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full | \
  1430. ADVERTISED_1000baseT_Full)
  1431. #define PHY_ALL_10_100_SPEED (ADVERTISE_10HALF | ADVERTISE_10FULL | \
  1432. ADVERTISE_100HALF | ADVERTISE_100FULL | ADVERTISE_CSMA)
  1433. #define PHY_ALL_1000_SPEED (ADVERTISE_1000HALF | ADVERTISE_1000FULL)
  1434. static void
  1435. bnx2_set_default_remote_link(struct bnx2 *bp)
  1436. {
  1437. u32 link;
  1438. if (bp->phy_port == PORT_TP)
  1439. link = bnx2_shmem_rd(bp, BNX2_RPHY_COPPER_LINK);
  1440. else
  1441. link = bnx2_shmem_rd(bp, BNX2_RPHY_SERDES_LINK);
  1442. if (link & BNX2_NETLINK_SET_LINK_ENABLE_AUTONEG) {
  1443. bp->req_line_speed = 0;
  1444. bp->autoneg |= AUTONEG_SPEED;
  1445. bp->advertising = ADVERTISED_Autoneg;
  1446. if (link & BNX2_NETLINK_SET_LINK_SPEED_10HALF)
  1447. bp->advertising |= ADVERTISED_10baseT_Half;
  1448. if (link & BNX2_NETLINK_SET_LINK_SPEED_10FULL)
  1449. bp->advertising |= ADVERTISED_10baseT_Full;
  1450. if (link & BNX2_NETLINK_SET_LINK_SPEED_100HALF)
  1451. bp->advertising |= ADVERTISED_100baseT_Half;
  1452. if (link & BNX2_NETLINK_SET_LINK_SPEED_100FULL)
  1453. bp->advertising |= ADVERTISED_100baseT_Full;
  1454. if (link & BNX2_NETLINK_SET_LINK_SPEED_1GFULL)
  1455. bp->advertising |= ADVERTISED_1000baseT_Full;
  1456. if (link & BNX2_NETLINK_SET_LINK_SPEED_2G5FULL)
  1457. bp->advertising |= ADVERTISED_2500baseX_Full;
  1458. } else {
  1459. bp->autoneg = 0;
  1460. bp->advertising = 0;
  1461. bp->req_duplex = DUPLEX_FULL;
  1462. if (link & BNX2_NETLINK_SET_LINK_SPEED_10) {
  1463. bp->req_line_speed = SPEED_10;
  1464. if (link & BNX2_NETLINK_SET_LINK_SPEED_10HALF)
  1465. bp->req_duplex = DUPLEX_HALF;
  1466. }
  1467. if (link & BNX2_NETLINK_SET_LINK_SPEED_100) {
  1468. bp->req_line_speed = SPEED_100;
  1469. if (link & BNX2_NETLINK_SET_LINK_SPEED_100HALF)
  1470. bp->req_duplex = DUPLEX_HALF;
  1471. }
  1472. if (link & BNX2_NETLINK_SET_LINK_SPEED_1GFULL)
  1473. bp->req_line_speed = SPEED_1000;
  1474. if (link & BNX2_NETLINK_SET_LINK_SPEED_2G5FULL)
  1475. bp->req_line_speed = SPEED_2500;
  1476. }
  1477. }
  1478. static void
  1479. bnx2_set_default_link(struct bnx2 *bp)
  1480. {
  1481. if (bp->phy_flags & BNX2_PHY_FLAG_REMOTE_PHY_CAP) {
  1482. bnx2_set_default_remote_link(bp);
  1483. return;
  1484. }
  1485. bp->autoneg = AUTONEG_SPEED | AUTONEG_FLOW_CTRL;
  1486. bp->req_line_speed = 0;
  1487. if (bp->phy_flags & BNX2_PHY_FLAG_SERDES) {
  1488. u32 reg;
  1489. bp->advertising = ETHTOOL_ALL_FIBRE_SPEED | ADVERTISED_Autoneg;
  1490. reg = bnx2_shmem_rd(bp, BNX2_PORT_HW_CFG_CONFIG);
  1491. reg &= BNX2_PORT_HW_CFG_CFG_DFLT_LINK_MASK;
  1492. if (reg == BNX2_PORT_HW_CFG_CFG_DFLT_LINK_1G) {
  1493. bp->autoneg = 0;
  1494. bp->req_line_speed = bp->line_speed = SPEED_1000;
  1495. bp->req_duplex = DUPLEX_FULL;
  1496. }
  1497. } else
  1498. bp->advertising = ETHTOOL_ALL_COPPER_SPEED | ADVERTISED_Autoneg;
  1499. }
  1500. static void
  1501. bnx2_send_heart_beat(struct bnx2 *bp)
  1502. {
  1503. u32 msg;
  1504. u32 addr;
  1505. spin_lock(&bp->indirect_lock);
  1506. msg = (u32) (++bp->fw_drv_pulse_wr_seq & BNX2_DRV_PULSE_SEQ_MASK);
  1507. addr = bp->shmem_base + BNX2_DRV_PULSE_MB;
  1508. REG_WR(bp, BNX2_PCICFG_REG_WINDOW_ADDRESS, addr);
  1509. REG_WR(bp, BNX2_PCICFG_REG_WINDOW, msg);
  1510. spin_unlock(&bp->indirect_lock);
  1511. }
  1512. static void
  1513. bnx2_remote_phy_event(struct bnx2 *bp)
  1514. {
  1515. u32 msg;
  1516. u8 link_up = bp->link_up;
  1517. u8 old_port;
  1518. msg = bnx2_shmem_rd(bp, BNX2_LINK_STATUS);
  1519. if (msg & BNX2_LINK_STATUS_HEART_BEAT_EXPIRED)
  1520. bnx2_send_heart_beat(bp);
  1521. msg &= ~BNX2_LINK_STATUS_HEART_BEAT_EXPIRED;
  1522. if ((msg & BNX2_LINK_STATUS_LINK_UP) == BNX2_LINK_STATUS_LINK_DOWN)
  1523. bp->link_up = 0;
  1524. else {
  1525. u32 speed;
  1526. bp->link_up = 1;
  1527. speed = msg & BNX2_LINK_STATUS_SPEED_MASK;
  1528. bp->duplex = DUPLEX_FULL;
  1529. switch (speed) {
  1530. case BNX2_LINK_STATUS_10HALF:
  1531. bp->duplex = DUPLEX_HALF;
  1532. case BNX2_LINK_STATUS_10FULL:
  1533. bp->line_speed = SPEED_10;
  1534. break;
  1535. case BNX2_LINK_STATUS_100HALF:
  1536. bp->duplex = DUPLEX_HALF;
  1537. case BNX2_LINK_STATUS_100BASE_T4:
  1538. case BNX2_LINK_STATUS_100FULL:
  1539. bp->line_speed = SPEED_100;
  1540. break;
  1541. case BNX2_LINK_STATUS_1000HALF:
  1542. bp->duplex = DUPLEX_HALF;
  1543. case BNX2_LINK_STATUS_1000FULL:
  1544. bp->line_speed = SPEED_1000;
  1545. break;
  1546. case BNX2_LINK_STATUS_2500HALF:
  1547. bp->duplex = DUPLEX_HALF;
  1548. case BNX2_LINK_STATUS_2500FULL:
  1549. bp->line_speed = SPEED_2500;
  1550. break;
  1551. default:
  1552. bp->line_speed = 0;
  1553. break;
  1554. }
  1555. bp->flow_ctrl = 0;
  1556. if ((bp->autoneg & (AUTONEG_SPEED | AUTONEG_FLOW_CTRL)) !=
  1557. (AUTONEG_SPEED | AUTONEG_FLOW_CTRL)) {
  1558. if (bp->duplex == DUPLEX_FULL)
  1559. bp->flow_ctrl = bp->req_flow_ctrl;
  1560. } else {
  1561. if (msg & BNX2_LINK_STATUS_TX_FC_ENABLED)
  1562. bp->flow_ctrl |= FLOW_CTRL_TX;
  1563. if (msg & BNX2_LINK_STATUS_RX_FC_ENABLED)
  1564. bp->flow_ctrl |= FLOW_CTRL_RX;
  1565. }
  1566. old_port = bp->phy_port;
  1567. if (msg & BNX2_LINK_STATUS_SERDES_LINK)
  1568. bp->phy_port = PORT_FIBRE;
  1569. else
  1570. bp->phy_port = PORT_TP;
  1571. if (old_port != bp->phy_port)
  1572. bnx2_set_default_link(bp);
  1573. }
  1574. if (bp->link_up != link_up)
  1575. bnx2_report_link(bp);
  1576. bnx2_set_mac_link(bp);
  1577. }
  1578. static int
  1579. bnx2_set_remote_link(struct bnx2 *bp)
  1580. {
  1581. u32 evt_code;
  1582. evt_code = bnx2_shmem_rd(bp, BNX2_FW_EVT_CODE_MB);
  1583. switch (evt_code) {
  1584. case BNX2_FW_EVT_CODE_LINK_EVENT:
  1585. bnx2_remote_phy_event(bp);
  1586. break;
  1587. case BNX2_FW_EVT_CODE_SW_TIMER_EXPIRATION_EVENT:
  1588. default:
  1589. bnx2_send_heart_beat(bp);
  1590. break;
  1591. }
  1592. return 0;
  1593. }
  1594. static int
  1595. bnx2_setup_copper_phy(struct bnx2 *bp)
  1596. __releases(&bp->phy_lock)
  1597. __acquires(&bp->phy_lock)
  1598. {
  1599. u32 bmcr;
  1600. u32 new_bmcr;
  1601. bnx2_read_phy(bp, bp->mii_bmcr, &bmcr);
  1602. if (bp->autoneg & AUTONEG_SPEED) {
  1603. u32 adv_reg, adv1000_reg;
  1604. u32 new_adv_reg = 0;
  1605. u32 new_adv1000_reg = 0;
  1606. bnx2_read_phy(bp, bp->mii_adv, &adv_reg);
  1607. adv_reg &= (PHY_ALL_10_100_SPEED | ADVERTISE_PAUSE_CAP |
  1608. ADVERTISE_PAUSE_ASYM);
  1609. bnx2_read_phy(bp, MII_CTRL1000, &adv1000_reg);
  1610. adv1000_reg &= PHY_ALL_1000_SPEED;
  1611. if (bp->advertising & ADVERTISED_10baseT_Half)
  1612. new_adv_reg |= ADVERTISE_10HALF;
  1613. if (bp->advertising & ADVERTISED_10baseT_Full)
  1614. new_adv_reg |= ADVERTISE_10FULL;
  1615. if (bp->advertising & ADVERTISED_100baseT_Half)
  1616. new_adv_reg |= ADVERTISE_100HALF;
  1617. if (bp->advertising & ADVERTISED_100baseT_Full)
  1618. new_adv_reg |= ADVERTISE_100FULL;
  1619. if (bp->advertising & ADVERTISED_1000baseT_Full)
  1620. new_adv1000_reg |= ADVERTISE_1000FULL;
  1621. new_adv_reg |= ADVERTISE_CSMA;
  1622. new_adv_reg |= bnx2_phy_get_pause_adv(bp);
  1623. if ((adv1000_reg != new_adv1000_reg) ||
  1624. (adv_reg != new_adv_reg) ||
  1625. ((bmcr & BMCR_ANENABLE) == 0)) {
  1626. bnx2_write_phy(bp, bp->mii_adv, new_adv_reg);
  1627. bnx2_write_phy(bp, MII_CTRL1000, new_adv1000_reg);
  1628. bnx2_write_phy(bp, bp->mii_bmcr, BMCR_ANRESTART |
  1629. BMCR_ANENABLE);
  1630. }
  1631. else if (bp->link_up) {
  1632. /* Flow ctrl may have changed from auto to forced */
  1633. /* or vice-versa. */
  1634. bnx2_resolve_flow_ctrl(bp);
  1635. bnx2_set_mac_link(bp);
  1636. }
  1637. return 0;
  1638. }
  1639. new_bmcr = 0;
  1640. if (bp->req_line_speed == SPEED_100) {
  1641. new_bmcr |= BMCR_SPEED100;
  1642. }
  1643. if (bp->req_duplex == DUPLEX_FULL) {
  1644. new_bmcr |= BMCR_FULLDPLX;
  1645. }
  1646. if (new_bmcr != bmcr) {
  1647. u32 bmsr;
  1648. bnx2_read_phy(bp, bp->mii_bmsr, &bmsr);
  1649. bnx2_read_phy(bp, bp->mii_bmsr, &bmsr);
  1650. if (bmsr & BMSR_LSTATUS) {
  1651. /* Force link down */
  1652. bnx2_write_phy(bp, bp->mii_bmcr, BMCR_LOOPBACK);
  1653. spin_unlock_bh(&bp->phy_lock);
  1654. msleep(50);
  1655. spin_lock_bh(&bp->phy_lock);
  1656. bnx2_read_phy(bp, bp->mii_bmsr, &bmsr);
  1657. bnx2_read_phy(bp, bp->mii_bmsr, &bmsr);
  1658. }
  1659. bnx2_write_phy(bp, bp->mii_bmcr, new_bmcr);
  1660. /* Normally, the new speed is setup after the link has
  1661. * gone down and up again. In some cases, link will not go
  1662. * down so we need to set up the new speed here.
  1663. */
  1664. if (bmsr & BMSR_LSTATUS) {
  1665. bp->line_speed = bp->req_line_speed;
  1666. bp->duplex = bp->req_duplex;
  1667. bnx2_resolve_flow_ctrl(bp);
  1668. bnx2_set_mac_link(bp);
  1669. }
  1670. } else {
  1671. bnx2_resolve_flow_ctrl(bp);
  1672. bnx2_set_mac_link(bp);
  1673. }
  1674. return 0;
  1675. }
  1676. static int
  1677. bnx2_setup_phy(struct bnx2 *bp, u8 port)
  1678. __releases(&bp->phy_lock)
  1679. __acquires(&bp->phy_lock)
  1680. {
  1681. if (bp->loopback == MAC_LOOPBACK)
  1682. return 0;
  1683. if (bp->phy_flags & BNX2_PHY_FLAG_SERDES) {
  1684. return (bnx2_setup_serdes_phy(bp, port));
  1685. }
  1686. else {
  1687. return (bnx2_setup_copper_phy(bp));
  1688. }
  1689. }
  1690. static int
  1691. bnx2_init_5709s_phy(struct bnx2 *bp, int reset_phy)
  1692. {
  1693. u32 val;
  1694. bp->mii_bmcr = MII_BMCR + 0x10;
  1695. bp->mii_bmsr = MII_BMSR + 0x10;
  1696. bp->mii_bmsr1 = MII_BNX2_GP_TOP_AN_STATUS1;
  1697. bp->mii_adv = MII_ADVERTISE + 0x10;
  1698. bp->mii_lpa = MII_LPA + 0x10;
  1699. bp->mii_up1 = MII_BNX2_OVER1G_UP1;
  1700. bnx2_write_phy(bp, MII_BNX2_BLK_ADDR, MII_BNX2_BLK_ADDR_AER);
  1701. bnx2_write_phy(bp, MII_BNX2_AER_AER, MII_BNX2_AER_AER_AN_MMD);
  1702. bnx2_write_phy(bp, MII_BNX2_BLK_ADDR, MII_BNX2_BLK_ADDR_COMBO_IEEEB0);
  1703. if (reset_phy)
  1704. bnx2_reset_phy(bp);
  1705. bnx2_write_phy(bp, MII_BNX2_BLK_ADDR, MII_BNX2_BLK_ADDR_SERDES_DIG);
  1706. bnx2_read_phy(bp, MII_BNX2_SERDES_DIG_1000XCTL1, &val);
  1707. val &= ~MII_BNX2_SD_1000XCTL1_AUTODET;
  1708. val |= MII_BNX2_SD_1000XCTL1_FIBER;
  1709. bnx2_write_phy(bp, MII_BNX2_SERDES_DIG_1000XCTL1, val);
  1710. bnx2_write_phy(bp, MII_BNX2_BLK_ADDR, MII_BNX2_BLK_ADDR_OVER1G);
  1711. bnx2_read_phy(bp, MII_BNX2_OVER1G_UP1, &val);
  1712. if (bp->phy_flags & BNX2_PHY_FLAG_2_5G_CAPABLE)
  1713. val |= BCM5708S_UP1_2G5;
  1714. else
  1715. val &= ~BCM5708S_UP1_2G5;
  1716. bnx2_write_phy(bp, MII_BNX2_OVER1G_UP1, val);
  1717. bnx2_write_phy(bp, MII_BNX2_BLK_ADDR, MII_BNX2_BLK_ADDR_BAM_NXTPG);
  1718. bnx2_read_phy(bp, MII_BNX2_BAM_NXTPG_CTL, &val);
  1719. val |= MII_BNX2_NXTPG_CTL_T2 | MII_BNX2_NXTPG_CTL_BAM;
  1720. bnx2_write_phy(bp, MII_BNX2_BAM_NXTPG_CTL, val);
  1721. bnx2_write_phy(bp, MII_BNX2_BLK_ADDR, MII_BNX2_BLK_ADDR_CL73_USERB0);
  1722. val = MII_BNX2_CL73_BAM_EN | MII_BNX2_CL73_BAM_STA_MGR_EN |
  1723. MII_BNX2_CL73_BAM_NP_AFT_BP_EN;
  1724. bnx2_write_phy(bp, MII_BNX2_CL73_BAM_CTL1, val);
  1725. bnx2_write_phy(bp, MII_BNX2_BLK_ADDR, MII_BNX2_BLK_ADDR_COMBO_IEEEB0);
  1726. return 0;
  1727. }
  1728. static int
  1729. bnx2_init_5708s_phy(struct bnx2 *bp, int reset_phy)
  1730. {
  1731. u32 val;
  1732. if (reset_phy)
  1733. bnx2_reset_phy(bp);
  1734. bp->mii_up1 = BCM5708S_UP1;
  1735. bnx2_write_phy(bp, BCM5708S_BLK_ADDR, BCM5708S_BLK_ADDR_DIG3);
  1736. bnx2_write_phy(bp, BCM5708S_DIG_3_0, BCM5708S_DIG_3_0_USE_IEEE);
  1737. bnx2_write_phy(bp, BCM5708S_BLK_ADDR, BCM5708S_BLK_ADDR_DIG);
  1738. bnx2_read_phy(bp, BCM5708S_1000X_CTL1, &val);
  1739. val |= BCM5708S_1000X_CTL1_FIBER_MODE | BCM5708S_1000X_CTL1_AUTODET_EN;
  1740. bnx2_write_phy(bp, BCM5708S_1000X_CTL1, val);
  1741. bnx2_read_phy(bp, BCM5708S_1000X_CTL2, &val);
  1742. val |= BCM5708S_1000X_CTL2_PLLEL_DET_EN;
  1743. bnx2_write_phy(bp, BCM5708S_1000X_CTL2, val);
  1744. if (bp->phy_flags & BNX2_PHY_FLAG_2_5G_CAPABLE) {
  1745. bnx2_read_phy(bp, BCM5708S_UP1, &val);
  1746. val |= BCM5708S_UP1_2G5;
  1747. bnx2_write_phy(bp, BCM5708S_UP1, val);
  1748. }
  1749. if ((CHIP_ID(bp) == CHIP_ID_5708_A0) ||
  1750. (CHIP_ID(bp) == CHIP_ID_5708_B0) ||
  1751. (CHIP_ID(bp) == CHIP_ID_5708_B1)) {
  1752. /* increase tx signal amplitude */
  1753. bnx2_write_phy(bp, BCM5708S_BLK_ADDR,
  1754. BCM5708S_BLK_ADDR_TX_MISC);
  1755. bnx2_read_phy(bp, BCM5708S_TX_ACTL1, &val);
  1756. val &= ~BCM5708S_TX_ACTL1_DRIVER_VCM;
  1757. bnx2_write_phy(bp, BCM5708S_TX_ACTL1, val);
  1758. bnx2_write_phy(bp, BCM5708S_BLK_ADDR, BCM5708S_BLK_ADDR_DIG);
  1759. }
  1760. val = bnx2_shmem_rd(bp, BNX2_PORT_HW_CFG_CONFIG) &
  1761. BNX2_PORT_HW_CFG_CFG_TXCTL3_MASK;
  1762. if (val) {
  1763. u32 is_backplane;
  1764. is_backplane = bnx2_shmem_rd(bp, BNX2_SHARED_HW_CFG_CONFIG);
  1765. if (is_backplane & BNX2_SHARED_HW_CFG_PHY_BACKPLANE) {
  1766. bnx2_write_phy(bp, BCM5708S_BLK_ADDR,
  1767. BCM5708S_BLK_ADDR_TX_MISC);
  1768. bnx2_write_phy(bp, BCM5708S_TX_ACTL3, val);
  1769. bnx2_write_phy(bp, BCM5708S_BLK_ADDR,
  1770. BCM5708S_BLK_ADDR_DIG);
  1771. }
  1772. }
  1773. return 0;
  1774. }
  1775. static int
  1776. bnx2_init_5706s_phy(struct bnx2 *bp, int reset_phy)
  1777. {
  1778. if (reset_phy)
  1779. bnx2_reset_phy(bp);
  1780. bp->phy_flags &= ~BNX2_PHY_FLAG_PARALLEL_DETECT;
  1781. if (CHIP_NUM(bp) == CHIP_NUM_5706)
  1782. REG_WR(bp, BNX2_MISC_GP_HW_CTL0, 0x300);
  1783. if (bp->dev->mtu > 1500) {
  1784. u32 val;
  1785. /* Set extended packet length bit */
  1786. bnx2_write_phy(bp, 0x18, 0x7);
  1787. bnx2_read_phy(bp, 0x18, &val);
  1788. bnx2_write_phy(bp, 0x18, (val & 0xfff8) | 0x4000);
  1789. bnx2_write_phy(bp, 0x1c, 0x6c00);
  1790. bnx2_read_phy(bp, 0x1c, &val);
  1791. bnx2_write_phy(bp, 0x1c, (val & 0x3ff) | 0xec02);
  1792. }
  1793. else {
  1794. u32 val;
  1795. bnx2_write_phy(bp, 0x18, 0x7);
  1796. bnx2_read_phy(bp, 0x18, &val);
  1797. bnx2_write_phy(bp, 0x18, val & ~0x4007);
  1798. bnx2_write_phy(bp, 0x1c, 0x6c00);
  1799. bnx2_read_phy(bp, 0x1c, &val);
  1800. bnx2_write_phy(bp, 0x1c, (val & 0x3fd) | 0xec00);
  1801. }
  1802. return 0;
  1803. }
  1804. static int
  1805. bnx2_init_copper_phy(struct bnx2 *bp, int reset_phy)
  1806. {
  1807. u32 val;
  1808. if (reset_phy)
  1809. bnx2_reset_phy(bp);
  1810. if (bp->phy_flags & BNX2_PHY_FLAG_CRC_FIX) {
  1811. bnx2_write_phy(bp, 0x18, 0x0c00);
  1812. bnx2_write_phy(bp, 0x17, 0x000a);
  1813. bnx2_write_phy(bp, 0x15, 0x310b);
  1814. bnx2_write_phy(bp, 0x17, 0x201f);
  1815. bnx2_write_phy(bp, 0x15, 0x9506);
  1816. bnx2_write_phy(bp, 0x17, 0x401f);
  1817. bnx2_write_phy(bp, 0x15, 0x14e2);
  1818. bnx2_write_phy(bp, 0x18, 0x0400);
  1819. }
  1820. if (bp->phy_flags & BNX2_PHY_FLAG_DIS_EARLY_DAC) {
  1821. bnx2_write_phy(bp, MII_BNX2_DSP_ADDRESS,
  1822. MII_BNX2_DSP_EXPAND_REG | 0x8);
  1823. bnx2_read_phy(bp, MII_BNX2_DSP_RW_PORT, &val);
  1824. val &= ~(1 << 8);
  1825. bnx2_write_phy(bp, MII_BNX2_DSP_RW_PORT, val);
  1826. }
  1827. if (bp->dev->mtu > 1500) {
  1828. /* Set extended packet length bit */
  1829. bnx2_write_phy(bp, 0x18, 0x7);
  1830. bnx2_read_phy(bp, 0x18, &val);
  1831. bnx2_write_phy(bp, 0x18, val | 0x4000);
  1832. bnx2_read_phy(bp, 0x10, &val);
  1833. bnx2_write_phy(bp, 0x10, val | 0x1);
  1834. }
  1835. else {
  1836. bnx2_write_phy(bp, 0x18, 0x7);
  1837. bnx2_read_phy(bp, 0x18, &val);
  1838. bnx2_write_phy(bp, 0x18, val & ~0x4007);
  1839. bnx2_read_phy(bp, 0x10, &val);
  1840. bnx2_write_phy(bp, 0x10, val & ~0x1);
  1841. }
  1842. /* ethernet@wirespeed */
  1843. bnx2_write_phy(bp, 0x18, 0x7007);
  1844. bnx2_read_phy(bp, 0x18, &val);
  1845. bnx2_write_phy(bp, 0x18, val | (1 << 15) | (1 << 4));
  1846. return 0;
  1847. }
  1848. static int
  1849. bnx2_init_phy(struct bnx2 *bp, int reset_phy)
  1850. __releases(&bp->phy_lock)
  1851. __acquires(&bp->phy_lock)
  1852. {
  1853. u32 val;
  1854. int rc = 0;
  1855. bp->phy_flags &= ~BNX2_PHY_FLAG_INT_MODE_MASK;
  1856. bp->phy_flags |= BNX2_PHY_FLAG_INT_MODE_LINK_READY;
  1857. bp->mii_bmcr = MII_BMCR;
  1858. bp->mii_bmsr = MII_BMSR;
  1859. bp->mii_bmsr1 = MII_BMSR;
  1860. bp->mii_adv = MII_ADVERTISE;
  1861. bp->mii_lpa = MII_LPA;
  1862. REG_WR(bp, BNX2_EMAC_ATTENTION_ENA, BNX2_EMAC_ATTENTION_ENA_LINK);
  1863. if (bp->phy_flags & BNX2_PHY_FLAG_REMOTE_PHY_CAP)
  1864. goto setup_phy;
  1865. bnx2_read_phy(bp, MII_PHYSID1, &val);
  1866. bp->phy_id = val << 16;
  1867. bnx2_read_phy(bp, MII_PHYSID2, &val);
  1868. bp->phy_id |= val & 0xffff;
  1869. if (bp->phy_flags & BNX2_PHY_FLAG_SERDES) {
  1870. if (CHIP_NUM(bp) == CHIP_NUM_5706)
  1871. rc = bnx2_init_5706s_phy(bp, reset_phy);
  1872. else if (CHIP_NUM(bp) == CHIP_NUM_5708)
  1873. rc = bnx2_init_5708s_phy(bp, reset_phy);
  1874. else if (CHIP_NUM(bp) == CHIP_NUM_5709)
  1875. rc = bnx2_init_5709s_phy(bp, reset_phy);
  1876. }
  1877. else {
  1878. rc = bnx2_init_copper_phy(bp, reset_phy);
  1879. }
  1880. setup_phy:
  1881. if (!rc)
  1882. rc = bnx2_setup_phy(bp, bp->phy_port);
  1883. return rc;
  1884. }
  1885. static int
  1886. bnx2_set_mac_loopback(struct bnx2 *bp)
  1887. {
  1888. u32 mac_mode;
  1889. mac_mode = REG_RD(bp, BNX2_EMAC_MODE);
  1890. mac_mode &= ~BNX2_EMAC_MODE_PORT;
  1891. mac_mode |= BNX2_EMAC_MODE_MAC_LOOP | BNX2_EMAC_MODE_FORCE_LINK;
  1892. REG_WR(bp, BNX2_EMAC_MODE, mac_mode);
  1893. bp->link_up = 1;
  1894. return 0;
  1895. }
  1896. static int bnx2_test_link(struct bnx2 *);
  1897. static int
  1898. bnx2_set_phy_loopback(struct bnx2 *bp)
  1899. {
  1900. u32 mac_mode;
  1901. int rc, i;
  1902. spin_lock_bh(&bp->phy_lock);
  1903. rc = bnx2_write_phy(bp, bp->mii_bmcr, BMCR_LOOPBACK | BMCR_FULLDPLX |
  1904. BMCR_SPEED1000);
  1905. spin_unlock_bh(&bp->phy_lock);
  1906. if (rc)
  1907. return rc;
  1908. for (i = 0; i < 10; i++) {
  1909. if (bnx2_test_link(bp) == 0)
  1910. break;
  1911. msleep(100);
  1912. }
  1913. mac_mode = REG_RD(bp, BNX2_EMAC_MODE);
  1914. mac_mode &= ~(BNX2_EMAC_MODE_PORT | BNX2_EMAC_MODE_HALF_DUPLEX |
  1915. BNX2_EMAC_MODE_MAC_LOOP | BNX2_EMAC_MODE_FORCE_LINK |
  1916. BNX2_EMAC_MODE_25G_MODE);
  1917. mac_mode |= BNX2_EMAC_MODE_PORT_GMII;
  1918. REG_WR(bp, BNX2_EMAC_MODE, mac_mode);
  1919. bp->link_up = 1;
  1920. return 0;
  1921. }
  1922. static int
  1923. bnx2_fw_sync(struct bnx2 *bp, u32 msg_data, int ack, int silent)
  1924. {
  1925. int i;
  1926. u32 val;
  1927. bp->fw_wr_seq++;
  1928. msg_data |= bp->fw_wr_seq;
  1929. bnx2_shmem_wr(bp, BNX2_DRV_MB, msg_data);
  1930. if (!ack)
  1931. return 0;
  1932. /* wait for an acknowledgement. */
  1933. for (i = 0; i < (BNX2_FW_ACK_TIME_OUT_MS / 10); i++) {
  1934. msleep(10);
  1935. val = bnx2_shmem_rd(bp, BNX2_FW_MB);
  1936. if ((val & BNX2_FW_MSG_ACK) == (msg_data & BNX2_DRV_MSG_SEQ))
  1937. break;
  1938. }
  1939. if ((msg_data & BNX2_DRV_MSG_DATA) == BNX2_DRV_MSG_DATA_WAIT0)
  1940. return 0;
  1941. /* If we timed out, inform the firmware that this is the case. */
  1942. if ((val & BNX2_FW_MSG_ACK) != (msg_data & BNX2_DRV_MSG_SEQ)) {
  1943. if (!silent)
  1944. printk(KERN_ERR PFX "fw sync timeout, reset code = "
  1945. "%x\n", msg_data);
  1946. msg_data &= ~BNX2_DRV_MSG_CODE;
  1947. msg_data |= BNX2_DRV_MSG_CODE_FW_TIMEOUT;
  1948. bnx2_shmem_wr(bp, BNX2_DRV_MB, msg_data);
  1949. return -EBUSY;
  1950. }
  1951. if ((val & BNX2_FW_MSG_STATUS_MASK) != BNX2_FW_MSG_STATUS_OK)
  1952. return -EIO;
  1953. return 0;
  1954. }
  1955. static int
  1956. bnx2_init_5709_context(struct bnx2 *bp)
  1957. {
  1958. int i, ret = 0;
  1959. u32 val;
  1960. val = BNX2_CTX_COMMAND_ENABLED | BNX2_CTX_COMMAND_MEM_INIT | (1 << 12);
  1961. val |= (BCM_PAGE_BITS - 8) << 16;
  1962. REG_WR(bp, BNX2_CTX_COMMAND, val);
  1963. for (i = 0; i < 10; i++) {
  1964. val = REG_RD(bp, BNX2_CTX_COMMAND);
  1965. if (!(val & BNX2_CTX_COMMAND_MEM_INIT))
  1966. break;
  1967. udelay(2);
  1968. }
  1969. if (val & BNX2_CTX_COMMAND_MEM_INIT)
  1970. return -EBUSY;
  1971. for (i = 0; i < bp->ctx_pages; i++) {
  1972. int j;
  1973. if (bp->ctx_blk[i])
  1974. memset(bp->ctx_blk[i], 0, BCM_PAGE_SIZE);
  1975. else
  1976. return -ENOMEM;
  1977. REG_WR(bp, BNX2_CTX_HOST_PAGE_TBL_DATA0,
  1978. (bp->ctx_blk_mapping[i] & 0xffffffff) |
  1979. BNX2_CTX_HOST_PAGE_TBL_DATA0_VALID);
  1980. REG_WR(bp, BNX2_CTX_HOST_PAGE_TBL_DATA1,
  1981. (u64) bp->ctx_blk_mapping[i] >> 32);
  1982. REG_WR(bp, BNX2_CTX_HOST_PAGE_TBL_CTRL, i |
  1983. BNX2_CTX_HOST_PAGE_TBL_CTRL_WRITE_REQ);
  1984. for (j = 0; j < 10; j++) {
  1985. val = REG_RD(bp, BNX2_CTX_HOST_PAGE_TBL_CTRL);
  1986. if (!(val & BNX2_CTX_HOST_PAGE_TBL_CTRL_WRITE_REQ))
  1987. break;
  1988. udelay(5);
  1989. }
  1990. if (val & BNX2_CTX_HOST_PAGE_TBL_CTRL_WRITE_REQ) {
  1991. ret = -EBUSY;
  1992. break;
  1993. }
  1994. }
  1995. return ret;
  1996. }
  1997. static void
  1998. bnx2_init_context(struct bnx2 *bp)
  1999. {
  2000. u32 vcid;
  2001. vcid = 96;
  2002. while (vcid) {
  2003. u32 vcid_addr, pcid_addr, offset;
  2004. int i;
  2005. vcid--;
  2006. if (CHIP_ID(bp) == CHIP_ID_5706_A0) {
  2007. u32 new_vcid;
  2008. vcid_addr = GET_PCID_ADDR(vcid);
  2009. if (vcid & 0x8) {
  2010. new_vcid = 0x60 + (vcid & 0xf0) + (vcid & 0x7);
  2011. }
  2012. else {
  2013. new_vcid = vcid;
  2014. }
  2015. pcid_addr = GET_PCID_ADDR(new_vcid);
  2016. }
  2017. else {
  2018. vcid_addr = GET_CID_ADDR(vcid);
  2019. pcid_addr = vcid_addr;
  2020. }
  2021. for (i = 0; i < (CTX_SIZE / PHY_CTX_SIZE); i++) {
  2022. vcid_addr += (i << PHY_CTX_SHIFT);
  2023. pcid_addr += (i << PHY_CTX_SHIFT);
  2024. REG_WR(bp, BNX2_CTX_VIRT_ADDR, vcid_addr);
  2025. REG_WR(bp, BNX2_CTX_PAGE_TBL, pcid_addr);
  2026. /* Zero out the context. */
  2027. for (offset = 0; offset < PHY_CTX_SIZE; offset += 4)
  2028. bnx2_ctx_wr(bp, vcid_addr, offset, 0);
  2029. }
  2030. }
  2031. }
  2032. static int
  2033. bnx2_alloc_bad_rbuf(struct bnx2 *bp)
  2034. {
  2035. u16 *good_mbuf;
  2036. u32 good_mbuf_cnt;
  2037. u32 val;
  2038. good_mbuf = kmalloc(512 * sizeof(u16), GFP_KERNEL);
  2039. if (good_mbuf == NULL) {
  2040. printk(KERN_ERR PFX "Failed to allocate memory in "
  2041. "bnx2_alloc_bad_rbuf\n");
  2042. return -ENOMEM;
  2043. }
  2044. REG_WR(bp, BNX2_MISC_ENABLE_SET_BITS,
  2045. BNX2_MISC_ENABLE_SET_BITS_RX_MBUF_ENABLE);
  2046. good_mbuf_cnt = 0;
  2047. /* Allocate a bunch of mbufs and save the good ones in an array. */
  2048. val = bnx2_reg_rd_ind(bp, BNX2_RBUF_STATUS1);
  2049. while (val & BNX2_RBUF_STATUS1_FREE_COUNT) {
  2050. bnx2_reg_wr_ind(bp, BNX2_RBUF_COMMAND,
  2051. BNX2_RBUF_COMMAND_ALLOC_REQ);
  2052. val = bnx2_reg_rd_ind(bp, BNX2_RBUF_FW_BUF_ALLOC);
  2053. val &= BNX2_RBUF_FW_BUF_ALLOC_VALUE;
  2054. /* The addresses with Bit 9 set are bad memory blocks. */
  2055. if (!(val & (1 << 9))) {
  2056. good_mbuf[good_mbuf_cnt] = (u16) val;
  2057. good_mbuf_cnt++;
  2058. }
  2059. val = bnx2_reg_rd_ind(bp, BNX2_RBUF_STATUS1);
  2060. }
  2061. /* Free the good ones back to the mbuf pool thus discarding
  2062. * all the bad ones. */
  2063. while (good_mbuf_cnt) {
  2064. good_mbuf_cnt--;
  2065. val = good_mbuf[good_mbuf_cnt];
  2066. val = (val << 9) | val | 1;
  2067. bnx2_reg_wr_ind(bp, BNX2_RBUF_FW_BUF_FREE, val);
  2068. }
  2069. kfree(good_mbuf);
  2070. return 0;
  2071. }
  2072. static void
  2073. bnx2_set_mac_addr(struct bnx2 *bp, u8 *mac_addr, u32 pos)
  2074. {
  2075. u32 val;
  2076. val = (mac_addr[0] << 8) | mac_addr[1];
  2077. REG_WR(bp, BNX2_EMAC_MAC_MATCH0 + (pos * 8), val);
  2078. val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
  2079. (mac_addr[4] << 8) | mac_addr[5];
  2080. REG_WR(bp, BNX2_EMAC_MAC_MATCH1 + (pos * 8), val);
  2081. }
  2082. static inline int
  2083. bnx2_alloc_rx_page(struct bnx2 *bp, struct bnx2_rx_ring_info *rxr, u16 index)
  2084. {
  2085. dma_addr_t mapping;
  2086. struct sw_pg *rx_pg = &rxr->rx_pg_ring[index];
  2087. struct rx_bd *rxbd =
  2088. &rxr->rx_pg_desc_ring[RX_RING(index)][RX_IDX(index)];
  2089. struct page *page = alloc_page(GFP_ATOMIC);
  2090. if (!page)
  2091. return -ENOMEM;
  2092. mapping = pci_map_page(bp->pdev, page, 0, PAGE_SIZE,
  2093. PCI_DMA_FROMDEVICE);
  2094. if (pci_dma_mapping_error(bp->pdev, mapping)) {
  2095. __free_page(page);
  2096. return -EIO;
  2097. }
  2098. rx_pg->page = page;
  2099. pci_unmap_addr_set(rx_pg, mapping, mapping);
  2100. rxbd->rx_bd_haddr_hi = (u64) mapping >> 32;
  2101. rxbd->rx_bd_haddr_lo = (u64) mapping & 0xffffffff;
  2102. return 0;
  2103. }
  2104. static void
  2105. bnx2_free_rx_page(struct bnx2 *bp, struct bnx2_rx_ring_info *rxr, u16 index)
  2106. {
  2107. struct sw_pg *rx_pg = &rxr->rx_pg_ring[index];
  2108. struct page *page = rx_pg->page;
  2109. if (!page)
  2110. return;
  2111. pci_unmap_page(bp->pdev, pci_unmap_addr(rx_pg, mapping), PAGE_SIZE,
  2112. PCI_DMA_FROMDEVICE);
  2113. __free_page(page);
  2114. rx_pg->page = NULL;
  2115. }
  2116. static inline int
  2117. bnx2_alloc_rx_skb(struct bnx2 *bp, struct bnx2_rx_ring_info *rxr, u16 index)
  2118. {
  2119. struct sk_buff *skb;
  2120. struct sw_bd *rx_buf = &rxr->rx_buf_ring[index];
  2121. dma_addr_t mapping;
  2122. struct rx_bd *rxbd = &rxr->rx_desc_ring[RX_RING(index)][RX_IDX(index)];
  2123. unsigned long align;
  2124. skb = netdev_alloc_skb(bp->dev, bp->rx_buf_size);
  2125. if (skb == NULL) {
  2126. return -ENOMEM;
  2127. }
  2128. if (unlikely((align = (unsigned long) skb->data & (BNX2_RX_ALIGN - 1))))
  2129. skb_reserve(skb, BNX2_RX_ALIGN - align);
  2130. mapping = pci_map_single(bp->pdev, skb->data, bp->rx_buf_use_size,
  2131. PCI_DMA_FROMDEVICE);
  2132. if (pci_dma_mapping_error(bp->pdev, mapping)) {
  2133. dev_kfree_skb(skb);
  2134. return -EIO;
  2135. }
  2136. rx_buf->skb = skb;
  2137. pci_unmap_addr_set(rx_buf, mapping, mapping);
  2138. rxbd->rx_bd_haddr_hi = (u64) mapping >> 32;
  2139. rxbd->rx_bd_haddr_lo = (u64) mapping & 0xffffffff;
  2140. rxr->rx_prod_bseq += bp->rx_buf_use_size;
  2141. return 0;
  2142. }
  2143. static int
  2144. bnx2_phy_event_is_set(struct bnx2 *bp, struct bnx2_napi *bnapi, u32 event)
  2145. {
  2146. struct status_block *sblk = bnapi->status_blk.msi;
  2147. u32 new_link_state, old_link_state;
  2148. int is_set = 1;
  2149. new_link_state = sblk->status_attn_bits & event;
  2150. old_link_state = sblk->status_attn_bits_ack & event;
  2151. if (new_link_state != old_link_state) {
  2152. if (new_link_state)
  2153. REG_WR(bp, BNX2_PCICFG_STATUS_BIT_SET_CMD, event);
  2154. else
  2155. REG_WR(bp, BNX2_PCICFG_STATUS_BIT_CLEAR_CMD, event);
  2156. } else
  2157. is_set = 0;
  2158. return is_set;
  2159. }
  2160. static void
  2161. bnx2_phy_int(struct bnx2 *bp, struct bnx2_napi *bnapi)
  2162. {
  2163. spin_lock(&bp->phy_lock);
  2164. if (bnx2_phy_event_is_set(bp, bnapi, STATUS_ATTN_BITS_LINK_STATE))
  2165. bnx2_set_link(bp);
  2166. if (bnx2_phy_event_is_set(bp, bnapi, STATUS_ATTN_BITS_TIMER_ABORT))
  2167. bnx2_set_remote_link(bp);
  2168. spin_unlock(&bp->phy_lock);
  2169. }
  2170. static inline u16
  2171. bnx2_get_hw_tx_cons(struct bnx2_napi *bnapi)
  2172. {
  2173. u16 cons;
  2174. /* Tell compiler that status block fields can change. */
  2175. barrier();
  2176. cons = *bnapi->hw_tx_cons_ptr;
  2177. if (unlikely((cons & MAX_TX_DESC_CNT) == MAX_TX_DESC_CNT))
  2178. cons++;
  2179. return cons;
  2180. }
  2181. static int
  2182. bnx2_tx_int(struct bnx2 *bp, struct bnx2_napi *bnapi, int budget)
  2183. {
  2184. struct bnx2_tx_ring_info *txr = &bnapi->tx_ring;
  2185. u16 hw_cons, sw_cons, sw_ring_cons;
  2186. int tx_pkt = 0, index;
  2187. struct netdev_queue *txq;
  2188. index = (bnapi - bp->bnx2_napi);
  2189. txq = netdev_get_tx_queue(bp->dev, index);
  2190. hw_cons = bnx2_get_hw_tx_cons(bnapi);
  2191. sw_cons = txr->tx_cons;
  2192. while (sw_cons != hw_cons) {
  2193. struct sw_tx_bd *tx_buf;
  2194. struct sk_buff *skb;
  2195. int i, last;
  2196. sw_ring_cons = TX_RING_IDX(sw_cons);
  2197. tx_buf = &txr->tx_buf_ring[sw_ring_cons];
  2198. skb = tx_buf->skb;
  2199. /* partial BD completions possible with TSO packets */
  2200. if (skb_is_gso(skb)) {
  2201. u16 last_idx, last_ring_idx;
  2202. last_idx = sw_cons +
  2203. skb_shinfo(skb)->nr_frags + 1;
  2204. last_ring_idx = sw_ring_cons +
  2205. skb_shinfo(skb)->nr_frags + 1;
  2206. if (unlikely(last_ring_idx >= MAX_TX_DESC_CNT)) {
  2207. last_idx++;
  2208. }
  2209. if (((s16) ((s16) last_idx - (s16) hw_cons)) > 0) {
  2210. break;
  2211. }
  2212. }
  2213. skb_dma_unmap(&bp->pdev->dev, skb, DMA_TO_DEVICE);
  2214. tx_buf->skb = NULL;
  2215. last = skb_shinfo(skb)->nr_frags;
  2216. for (i = 0; i < last; i++) {
  2217. sw_cons = NEXT_TX_BD(sw_cons);
  2218. }
  2219. sw_cons = NEXT_TX_BD(sw_cons);
  2220. dev_kfree_skb(skb);
  2221. tx_pkt++;
  2222. if (tx_pkt == budget)
  2223. break;
  2224. hw_cons = bnx2_get_hw_tx_cons(bnapi);
  2225. }
  2226. txr->hw_tx_cons = hw_cons;
  2227. txr->tx_cons = sw_cons;
  2228. /* Need to make the tx_cons update visible to bnx2_start_xmit()
  2229. * before checking for netif_tx_queue_stopped(). Without the
  2230. * memory barrier, there is a small possibility that bnx2_start_xmit()
  2231. * will miss it and cause the queue to be stopped forever.
  2232. */
  2233. smp_mb();
  2234. if (unlikely(netif_tx_queue_stopped(txq)) &&
  2235. (bnx2_tx_avail(bp, txr) > bp->tx_wake_thresh)) {
  2236. __netif_tx_lock(txq, smp_processor_id());
  2237. if ((netif_tx_queue_stopped(txq)) &&
  2238. (bnx2_tx_avail(bp, txr) > bp->tx_wake_thresh))
  2239. netif_tx_wake_queue(txq);
  2240. __netif_tx_unlock(txq);
  2241. }
  2242. return tx_pkt;
  2243. }
  2244. static void
  2245. bnx2_reuse_rx_skb_pages(struct bnx2 *bp, struct bnx2_rx_ring_info *rxr,
  2246. struct sk_buff *skb, int count)
  2247. {
  2248. struct sw_pg *cons_rx_pg, *prod_rx_pg;
  2249. struct rx_bd *cons_bd, *prod_bd;
  2250. int i;
  2251. u16 hw_prod, prod;
  2252. u16 cons = rxr->rx_pg_cons;
  2253. cons_rx_pg = &rxr->rx_pg_ring[cons];
  2254. /* The caller was unable to allocate a new page to replace the
  2255. * last one in the frags array, so we need to recycle that page
  2256. * and then free the skb.
  2257. */
  2258. if (skb) {
  2259. struct page *page;
  2260. struct skb_shared_info *shinfo;
  2261. shinfo = skb_shinfo(skb);
  2262. shinfo->nr_frags--;
  2263. page = shinfo->frags[shinfo->nr_frags].page;
  2264. shinfo->frags[shinfo->nr_frags].page = NULL;
  2265. cons_rx_pg->page = page;
  2266. dev_kfree_skb(skb);
  2267. }
  2268. hw_prod = rxr->rx_pg_prod;
  2269. for (i = 0; i < count; i++) {
  2270. prod = RX_PG_RING_IDX(hw_prod);
  2271. prod_rx_pg = &rxr->rx_pg_ring[prod];
  2272. cons_rx_pg = &rxr->rx_pg_ring[cons];
  2273. cons_bd = &rxr->rx_pg_desc_ring[RX_RING(cons)][RX_IDX(cons)];
  2274. prod_bd = &rxr->rx_pg_desc_ring[RX_RING(prod)][RX_IDX(prod)];
  2275. if (prod != cons) {
  2276. prod_rx_pg->page = cons_rx_pg->page;
  2277. cons_rx_pg->page = NULL;
  2278. pci_unmap_addr_set(prod_rx_pg, mapping,
  2279. pci_unmap_addr(cons_rx_pg, mapping));
  2280. prod_bd->rx_bd_haddr_hi = cons_bd->rx_bd_haddr_hi;
  2281. prod_bd->rx_bd_haddr_lo = cons_bd->rx_bd_haddr_lo;
  2282. }
  2283. cons = RX_PG_RING_IDX(NEXT_RX_BD(cons));
  2284. hw_prod = NEXT_RX_BD(hw_prod);
  2285. }
  2286. rxr->rx_pg_prod = hw_prod;
  2287. rxr->rx_pg_cons = cons;
  2288. }
  2289. static inline void
  2290. bnx2_reuse_rx_skb(struct bnx2 *bp, struct bnx2_rx_ring_info *rxr,
  2291. struct sk_buff *skb, u16 cons, u16 prod)
  2292. {
  2293. struct sw_bd *cons_rx_buf, *prod_rx_buf;
  2294. struct rx_bd *cons_bd, *prod_bd;
  2295. cons_rx_buf = &rxr->rx_buf_ring[cons];
  2296. prod_rx_buf = &rxr->rx_buf_ring[prod];
  2297. pci_dma_sync_single_for_device(bp->pdev,
  2298. pci_unmap_addr(cons_rx_buf, mapping),
  2299. BNX2_RX_OFFSET + BNX2_RX_COPY_THRESH, PCI_DMA_FROMDEVICE);
  2300. rxr->rx_prod_bseq += bp->rx_buf_use_size;
  2301. prod_rx_buf->skb = skb;
  2302. if (cons == prod)
  2303. return;
  2304. pci_unmap_addr_set(prod_rx_buf, mapping,
  2305. pci_unmap_addr(cons_rx_buf, mapping));
  2306. cons_bd = &rxr->rx_desc_ring[RX_RING(cons)][RX_IDX(cons)];
  2307. prod_bd = &rxr->rx_desc_ring[RX_RING(prod)][RX_IDX(prod)];
  2308. prod_bd->rx_bd_haddr_hi = cons_bd->rx_bd_haddr_hi;
  2309. prod_bd->rx_bd_haddr_lo = cons_bd->rx_bd_haddr_lo;
  2310. }
  2311. static int
  2312. bnx2_rx_skb(struct bnx2 *bp, struct bnx2_rx_ring_info *rxr, struct sk_buff *skb,
  2313. unsigned int len, unsigned int hdr_len, dma_addr_t dma_addr,
  2314. u32 ring_idx)
  2315. {
  2316. int err;
  2317. u16 prod = ring_idx & 0xffff;
  2318. err = bnx2_alloc_rx_skb(bp, rxr, prod);
  2319. if (unlikely(err)) {
  2320. bnx2_reuse_rx_skb(bp, rxr, skb, (u16) (ring_idx >> 16), prod);
  2321. if (hdr_len) {
  2322. unsigned int raw_len = len + 4;
  2323. int pages = PAGE_ALIGN(raw_len - hdr_len) >> PAGE_SHIFT;
  2324. bnx2_reuse_rx_skb_pages(bp, rxr, NULL, pages);
  2325. }
  2326. return err;
  2327. }
  2328. skb_reserve(skb, BNX2_RX_OFFSET);
  2329. pci_unmap_single(bp->pdev, dma_addr, bp->rx_buf_use_size,
  2330. PCI_DMA_FROMDEVICE);
  2331. if (hdr_len == 0) {
  2332. skb_put(skb, len);
  2333. return 0;
  2334. } else {
  2335. unsigned int i, frag_len, frag_size, pages;
  2336. struct sw_pg *rx_pg;
  2337. u16 pg_cons = rxr->rx_pg_cons;
  2338. u16 pg_prod = rxr->rx_pg_prod;
  2339. frag_size = len + 4 - hdr_len;
  2340. pages = PAGE_ALIGN(frag_size) >> PAGE_SHIFT;
  2341. skb_put(skb, hdr_len);
  2342. for (i = 0; i < pages; i++) {
  2343. dma_addr_t mapping_old;
  2344. frag_len = min(frag_size, (unsigned int) PAGE_SIZE);
  2345. if (unlikely(frag_len <= 4)) {
  2346. unsigned int tail = 4 - frag_len;
  2347. rxr->rx_pg_cons = pg_cons;
  2348. rxr->rx_pg_prod = pg_prod;
  2349. bnx2_reuse_rx_skb_pages(bp, rxr, NULL,
  2350. pages - i);
  2351. skb->len -= tail;
  2352. if (i == 0) {
  2353. skb->tail -= tail;
  2354. } else {
  2355. skb_frag_t *frag =
  2356. &skb_shinfo(skb)->frags[i - 1];
  2357. frag->size -= tail;
  2358. skb->data_len -= tail;
  2359. skb->truesize -= tail;
  2360. }
  2361. return 0;
  2362. }
  2363. rx_pg = &rxr->rx_pg_ring[pg_cons];
  2364. /* Don't unmap yet. If we're unable to allocate a new
  2365. * page, we need to recycle the page and the DMA addr.
  2366. */
  2367. mapping_old = pci_unmap_addr(rx_pg, mapping);
  2368. if (i == pages - 1)
  2369. frag_len -= 4;
  2370. skb_fill_page_desc(skb, i, rx_pg->page, 0, frag_len);
  2371. rx_pg->page = NULL;
  2372. err = bnx2_alloc_rx_page(bp, rxr,
  2373. RX_PG_RING_IDX(pg_prod));
  2374. if (unlikely(err)) {
  2375. rxr->rx_pg_cons = pg_cons;
  2376. rxr->rx_pg_prod = pg_prod;
  2377. bnx2_reuse_rx_skb_pages(bp, rxr, skb,
  2378. pages - i);
  2379. return err;
  2380. }
  2381. pci_unmap_page(bp->pdev, mapping_old,
  2382. PAGE_SIZE, PCI_DMA_FROMDEVICE);
  2383. frag_size -= frag_len;
  2384. skb->data_len += frag_len;
  2385. skb->truesize += frag_len;
  2386. skb->len += frag_len;
  2387. pg_prod = NEXT_RX_BD(pg_prod);
  2388. pg_cons = RX_PG_RING_IDX(NEXT_RX_BD(pg_cons));
  2389. }
  2390. rxr->rx_pg_prod = pg_prod;
  2391. rxr->rx_pg_cons = pg_cons;
  2392. }
  2393. return 0;
  2394. }
  2395. static inline u16
  2396. bnx2_get_hw_rx_cons(struct bnx2_napi *bnapi)
  2397. {
  2398. u16 cons;
  2399. /* Tell compiler that status block fields can change. */
  2400. barrier();
  2401. cons = *bnapi->hw_rx_cons_ptr;
  2402. if (unlikely((cons & MAX_RX_DESC_CNT) == MAX_RX_DESC_CNT))
  2403. cons++;
  2404. return cons;
  2405. }
  2406. static int
  2407. bnx2_rx_int(struct bnx2 *bp, struct bnx2_napi *bnapi, int budget)
  2408. {
  2409. struct bnx2_rx_ring_info *rxr = &bnapi->rx_ring;
  2410. u16 hw_cons, sw_cons, sw_ring_cons, sw_prod, sw_ring_prod;
  2411. struct l2_fhdr *rx_hdr;
  2412. int rx_pkt = 0, pg_ring_used = 0;
  2413. hw_cons = bnx2_get_hw_rx_cons(bnapi);
  2414. sw_cons = rxr->rx_cons;
  2415. sw_prod = rxr->rx_prod;
  2416. /* Memory barrier necessary as speculative reads of the rx
  2417. * buffer can be ahead of the index in the status block
  2418. */
  2419. rmb();
  2420. while (sw_cons != hw_cons) {
  2421. unsigned int len, hdr_len;
  2422. u32 status;
  2423. struct sw_bd *rx_buf;
  2424. struct sk_buff *skb;
  2425. dma_addr_t dma_addr;
  2426. u16 vtag = 0;
  2427. int hw_vlan __maybe_unused = 0;
  2428. sw_ring_cons = RX_RING_IDX(sw_cons);
  2429. sw_ring_prod = RX_RING_IDX(sw_prod);
  2430. rx_buf = &rxr->rx_buf_ring[sw_ring_cons];
  2431. skb = rx_buf->skb;
  2432. rx_buf->skb = NULL;
  2433. dma_addr = pci_unmap_addr(rx_buf, mapping);
  2434. pci_dma_sync_single_for_cpu(bp->pdev, dma_addr,
  2435. BNX2_RX_OFFSET + BNX2_RX_COPY_THRESH,
  2436. PCI_DMA_FROMDEVICE);
  2437. rx_hdr = (struct l2_fhdr *) skb->data;
  2438. len = rx_hdr->l2_fhdr_pkt_len;
  2439. status = rx_hdr->l2_fhdr_status;
  2440. hdr_len = 0;
  2441. if (status & L2_FHDR_STATUS_SPLIT) {
  2442. hdr_len = rx_hdr->l2_fhdr_ip_xsum;
  2443. pg_ring_used = 1;
  2444. } else if (len > bp->rx_jumbo_thresh) {
  2445. hdr_len = bp->rx_jumbo_thresh;
  2446. pg_ring_used = 1;
  2447. }
  2448. if (unlikely(status & (L2_FHDR_ERRORS_BAD_CRC |
  2449. L2_FHDR_ERRORS_PHY_DECODE |
  2450. L2_FHDR_ERRORS_ALIGNMENT |
  2451. L2_FHDR_ERRORS_TOO_SHORT |
  2452. L2_FHDR_ERRORS_GIANT_FRAME))) {
  2453. bnx2_reuse_rx_skb(bp, rxr, skb, sw_ring_cons,
  2454. sw_ring_prod);
  2455. if (pg_ring_used) {
  2456. int pages;
  2457. pages = PAGE_ALIGN(len - hdr_len) >> PAGE_SHIFT;
  2458. bnx2_reuse_rx_skb_pages(bp, rxr, NULL, pages);
  2459. }
  2460. goto next_rx;
  2461. }
  2462. len -= 4;
  2463. if (len <= bp->rx_copy_thresh) {
  2464. struct sk_buff *new_skb;
  2465. new_skb = netdev_alloc_skb(bp->dev, len + 6);
  2466. if (new_skb == NULL) {
  2467. bnx2_reuse_rx_skb(bp, rxr, skb, sw_ring_cons,
  2468. sw_ring_prod);
  2469. goto next_rx;
  2470. }
  2471. /* aligned copy */
  2472. skb_copy_from_linear_data_offset(skb,
  2473. BNX2_RX_OFFSET - 6,
  2474. new_skb->data, len + 6);
  2475. skb_reserve(new_skb, 6);
  2476. skb_put(new_skb, len);
  2477. bnx2_reuse_rx_skb(bp, rxr, skb,
  2478. sw_ring_cons, sw_ring_prod);
  2479. skb = new_skb;
  2480. } else if (unlikely(bnx2_rx_skb(bp, rxr, skb, len, hdr_len,
  2481. dma_addr, (sw_ring_cons << 16) | sw_ring_prod)))
  2482. goto next_rx;
  2483. if ((status & L2_FHDR_STATUS_L2_VLAN_TAG) &&
  2484. !(bp->rx_mode & BNX2_EMAC_RX_MODE_KEEP_VLAN_TAG)) {
  2485. vtag = rx_hdr->l2_fhdr_vlan_tag;
  2486. #ifdef BCM_VLAN
  2487. if (bp->vlgrp)
  2488. hw_vlan = 1;
  2489. else
  2490. #endif
  2491. {
  2492. struct vlan_ethhdr *ve = (struct vlan_ethhdr *)
  2493. __skb_push(skb, 4);
  2494. memmove(ve, skb->data + 4, ETH_ALEN * 2);
  2495. ve->h_vlan_proto = htons(ETH_P_8021Q);
  2496. ve->h_vlan_TCI = htons(vtag);
  2497. len += 4;
  2498. }
  2499. }
  2500. skb->protocol = eth_type_trans(skb, bp->dev);
  2501. if ((len > (bp->dev->mtu + ETH_HLEN)) &&
  2502. (ntohs(skb->protocol) != 0x8100)) {
  2503. dev_kfree_skb(skb);
  2504. goto next_rx;
  2505. }
  2506. skb->ip_summed = CHECKSUM_NONE;
  2507. if (bp->rx_csum &&
  2508. (status & (L2_FHDR_STATUS_TCP_SEGMENT |
  2509. L2_FHDR_STATUS_UDP_DATAGRAM))) {
  2510. if (likely((status & (L2_FHDR_ERRORS_TCP_XSUM |
  2511. L2_FHDR_ERRORS_UDP_XSUM)) == 0))
  2512. skb->ip_summed = CHECKSUM_UNNECESSARY;
  2513. }
  2514. skb_record_rx_queue(skb, bnapi - &bp->bnx2_napi[0]);
  2515. #ifdef BCM_VLAN
  2516. if (hw_vlan)
  2517. vlan_hwaccel_receive_skb(skb, bp->vlgrp, vtag);
  2518. else
  2519. #endif
  2520. netif_receive_skb(skb);
  2521. rx_pkt++;
  2522. next_rx:
  2523. sw_cons = NEXT_RX_BD(sw_cons);
  2524. sw_prod = NEXT_RX_BD(sw_prod);
  2525. if ((rx_pkt == budget))
  2526. break;
  2527. /* Refresh hw_cons to see if there is new work */
  2528. if (sw_cons == hw_cons) {
  2529. hw_cons = bnx2_get_hw_rx_cons(bnapi);
  2530. rmb();
  2531. }
  2532. }
  2533. rxr->rx_cons = sw_cons;
  2534. rxr->rx_prod = sw_prod;
  2535. if (pg_ring_used)
  2536. REG_WR16(bp, rxr->rx_pg_bidx_addr, rxr->rx_pg_prod);
  2537. REG_WR16(bp, rxr->rx_bidx_addr, sw_prod);
  2538. REG_WR(bp, rxr->rx_bseq_addr, rxr->rx_prod_bseq);
  2539. mmiowb();
  2540. return rx_pkt;
  2541. }
  2542. /* MSI ISR - The only difference between this and the INTx ISR
  2543. * is that the MSI interrupt is always serviced.
  2544. */
  2545. static irqreturn_t
  2546. bnx2_msi(int irq, void *dev_instance)
  2547. {
  2548. struct bnx2_napi *bnapi = dev_instance;
  2549. struct bnx2 *bp = bnapi->bp;
  2550. prefetch(bnapi->status_blk.msi);
  2551. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD,
  2552. BNX2_PCICFG_INT_ACK_CMD_USE_INT_HC_PARAM |
  2553. BNX2_PCICFG_INT_ACK_CMD_MASK_INT);
  2554. /* Return here if interrupt is disabled. */
  2555. if (unlikely(atomic_read(&bp->intr_sem) != 0))
  2556. return IRQ_HANDLED;
  2557. napi_schedule(&bnapi->napi);
  2558. return IRQ_HANDLED;
  2559. }
  2560. static irqreturn_t
  2561. bnx2_msi_1shot(int irq, void *dev_instance)
  2562. {
  2563. struct bnx2_napi *bnapi = dev_instance;
  2564. struct bnx2 *bp = bnapi->bp;
  2565. prefetch(bnapi->status_blk.msi);
  2566. /* Return here if interrupt is disabled. */
  2567. if (unlikely(atomic_read(&bp->intr_sem) != 0))
  2568. return IRQ_HANDLED;
  2569. napi_schedule(&bnapi->napi);
  2570. return IRQ_HANDLED;
  2571. }
  2572. static irqreturn_t
  2573. bnx2_interrupt(int irq, void *dev_instance)
  2574. {
  2575. struct bnx2_napi *bnapi = dev_instance;
  2576. struct bnx2 *bp = bnapi->bp;
  2577. struct status_block *sblk = bnapi->status_blk.msi;
  2578. /* When using INTx, it is possible for the interrupt to arrive
  2579. * at the CPU before the status block posted prior to the
  2580. * interrupt. Reading a register will flush the status block.
  2581. * When using MSI, the MSI message will always complete after
  2582. * the status block write.
  2583. */
  2584. if ((sblk->status_idx == bnapi->last_status_idx) &&
  2585. (REG_RD(bp, BNX2_PCICFG_MISC_STATUS) &
  2586. BNX2_PCICFG_MISC_STATUS_INTA_VALUE))
  2587. return IRQ_NONE;
  2588. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD,
  2589. BNX2_PCICFG_INT_ACK_CMD_USE_INT_HC_PARAM |
  2590. BNX2_PCICFG_INT_ACK_CMD_MASK_INT);
  2591. /* Read back to deassert IRQ immediately to avoid too many
  2592. * spurious interrupts.
  2593. */
  2594. REG_RD(bp, BNX2_PCICFG_INT_ACK_CMD);
  2595. /* Return here if interrupt is shared and is disabled. */
  2596. if (unlikely(atomic_read(&bp->intr_sem) != 0))
  2597. return IRQ_HANDLED;
  2598. if (napi_schedule_prep(&bnapi->napi)) {
  2599. bnapi->last_status_idx = sblk->status_idx;
  2600. __napi_schedule(&bnapi->napi);
  2601. }
  2602. return IRQ_HANDLED;
  2603. }
  2604. static inline int
  2605. bnx2_has_fast_work(struct bnx2_napi *bnapi)
  2606. {
  2607. struct bnx2_tx_ring_info *txr = &bnapi->tx_ring;
  2608. struct bnx2_rx_ring_info *rxr = &bnapi->rx_ring;
  2609. if ((bnx2_get_hw_rx_cons(bnapi) != rxr->rx_cons) ||
  2610. (bnx2_get_hw_tx_cons(bnapi) != txr->hw_tx_cons))
  2611. return 1;
  2612. return 0;
  2613. }
  2614. #define STATUS_ATTN_EVENTS (STATUS_ATTN_BITS_LINK_STATE | \
  2615. STATUS_ATTN_BITS_TIMER_ABORT)
  2616. static inline int
  2617. bnx2_has_work(struct bnx2_napi *bnapi)
  2618. {
  2619. struct status_block *sblk = bnapi->status_blk.msi;
  2620. if (bnx2_has_fast_work(bnapi))
  2621. return 1;
  2622. if ((sblk->status_attn_bits & STATUS_ATTN_EVENTS) !=
  2623. (sblk->status_attn_bits_ack & STATUS_ATTN_EVENTS))
  2624. return 1;
  2625. return 0;
  2626. }
  2627. static void
  2628. bnx2_chk_missed_msi(struct bnx2 *bp)
  2629. {
  2630. struct bnx2_napi *bnapi = &bp->bnx2_napi[0];
  2631. u32 msi_ctrl;
  2632. if (bnx2_has_work(bnapi)) {
  2633. msi_ctrl = REG_RD(bp, BNX2_PCICFG_MSI_CONTROL);
  2634. if (!(msi_ctrl & BNX2_PCICFG_MSI_CONTROL_ENABLE))
  2635. return;
  2636. if (bnapi->last_status_idx == bp->idle_chk_status_idx) {
  2637. REG_WR(bp, BNX2_PCICFG_MSI_CONTROL, msi_ctrl &
  2638. ~BNX2_PCICFG_MSI_CONTROL_ENABLE);
  2639. REG_WR(bp, BNX2_PCICFG_MSI_CONTROL, msi_ctrl);
  2640. bnx2_msi(bp->irq_tbl[0].vector, bnapi);
  2641. }
  2642. }
  2643. bp->idle_chk_status_idx = bnapi->last_status_idx;
  2644. }
  2645. static void bnx2_poll_link(struct bnx2 *bp, struct bnx2_napi *bnapi)
  2646. {
  2647. struct status_block *sblk = bnapi->status_blk.msi;
  2648. u32 status_attn_bits = sblk->status_attn_bits;
  2649. u32 status_attn_bits_ack = sblk->status_attn_bits_ack;
  2650. if ((status_attn_bits & STATUS_ATTN_EVENTS) !=
  2651. (status_attn_bits_ack & STATUS_ATTN_EVENTS)) {
  2652. bnx2_phy_int(bp, bnapi);
  2653. /* This is needed to take care of transient status
  2654. * during link changes.
  2655. */
  2656. REG_WR(bp, BNX2_HC_COMMAND,
  2657. bp->hc_cmd | BNX2_HC_COMMAND_COAL_NOW_WO_INT);
  2658. REG_RD(bp, BNX2_HC_COMMAND);
  2659. }
  2660. }
  2661. static int bnx2_poll_work(struct bnx2 *bp, struct bnx2_napi *bnapi,
  2662. int work_done, int budget)
  2663. {
  2664. struct bnx2_tx_ring_info *txr = &bnapi->tx_ring;
  2665. struct bnx2_rx_ring_info *rxr = &bnapi->rx_ring;
  2666. if (bnx2_get_hw_tx_cons(bnapi) != txr->hw_tx_cons)
  2667. bnx2_tx_int(bp, bnapi, 0);
  2668. if (bnx2_get_hw_rx_cons(bnapi) != rxr->rx_cons)
  2669. work_done += bnx2_rx_int(bp, bnapi, budget - work_done);
  2670. return work_done;
  2671. }
  2672. static int bnx2_poll_msix(struct napi_struct *napi, int budget)
  2673. {
  2674. struct bnx2_napi *bnapi = container_of(napi, struct bnx2_napi, napi);
  2675. struct bnx2 *bp = bnapi->bp;
  2676. int work_done = 0;
  2677. struct status_block_msix *sblk = bnapi->status_blk.msix;
  2678. while (1) {
  2679. work_done = bnx2_poll_work(bp, bnapi, work_done, budget);
  2680. if (unlikely(work_done >= budget))
  2681. break;
  2682. bnapi->last_status_idx = sblk->status_idx;
  2683. /* status idx must be read before checking for more work. */
  2684. rmb();
  2685. if (likely(!bnx2_has_fast_work(bnapi))) {
  2686. napi_complete(napi);
  2687. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD, bnapi->int_num |
  2688. BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID |
  2689. bnapi->last_status_idx);
  2690. break;
  2691. }
  2692. }
  2693. return work_done;
  2694. }
  2695. static int bnx2_poll(struct napi_struct *napi, int budget)
  2696. {
  2697. struct bnx2_napi *bnapi = container_of(napi, struct bnx2_napi, napi);
  2698. struct bnx2 *bp = bnapi->bp;
  2699. int work_done = 0;
  2700. struct status_block *sblk = bnapi->status_blk.msi;
  2701. while (1) {
  2702. bnx2_poll_link(bp, bnapi);
  2703. work_done = bnx2_poll_work(bp, bnapi, work_done, budget);
  2704. /* bnapi->last_status_idx is used below to tell the hw how
  2705. * much work has been processed, so we must read it before
  2706. * checking for more work.
  2707. */
  2708. bnapi->last_status_idx = sblk->status_idx;
  2709. if (unlikely(work_done >= budget))
  2710. break;
  2711. rmb();
  2712. if (likely(!bnx2_has_work(bnapi))) {
  2713. napi_complete(napi);
  2714. if (likely(bp->flags & BNX2_FLAG_USING_MSI_OR_MSIX)) {
  2715. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD,
  2716. BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID |
  2717. bnapi->last_status_idx);
  2718. break;
  2719. }
  2720. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD,
  2721. BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID |
  2722. BNX2_PCICFG_INT_ACK_CMD_MASK_INT |
  2723. bnapi->last_status_idx);
  2724. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD,
  2725. BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID |
  2726. bnapi->last_status_idx);
  2727. break;
  2728. }
  2729. }
  2730. return work_done;
  2731. }
  2732. /* Called with rtnl_lock from vlan functions and also netif_tx_lock
  2733. * from set_multicast.
  2734. */
  2735. static void
  2736. bnx2_set_rx_mode(struct net_device *dev)
  2737. {
  2738. struct bnx2 *bp = netdev_priv(dev);
  2739. u32 rx_mode, sort_mode;
  2740. struct dev_addr_list *uc_ptr;
  2741. int i;
  2742. if (!netif_running(dev))
  2743. return;
  2744. spin_lock_bh(&bp->phy_lock);
  2745. rx_mode = bp->rx_mode & ~(BNX2_EMAC_RX_MODE_PROMISCUOUS |
  2746. BNX2_EMAC_RX_MODE_KEEP_VLAN_TAG);
  2747. sort_mode = 1 | BNX2_RPM_SORT_USER0_BC_EN;
  2748. #ifdef BCM_VLAN
  2749. if (!bp->vlgrp && (bp->flags & BNX2_FLAG_CAN_KEEP_VLAN))
  2750. rx_mode |= BNX2_EMAC_RX_MODE_KEEP_VLAN_TAG;
  2751. #else
  2752. if (bp->flags & BNX2_FLAG_CAN_KEEP_VLAN)
  2753. rx_mode |= BNX2_EMAC_RX_MODE_KEEP_VLAN_TAG;
  2754. #endif
  2755. if (dev->flags & IFF_PROMISC) {
  2756. /* Promiscuous mode. */
  2757. rx_mode |= BNX2_EMAC_RX_MODE_PROMISCUOUS;
  2758. sort_mode |= BNX2_RPM_SORT_USER0_PROM_EN |
  2759. BNX2_RPM_SORT_USER0_PROM_VLAN;
  2760. }
  2761. else if (dev->flags & IFF_ALLMULTI) {
  2762. for (i = 0; i < NUM_MC_HASH_REGISTERS; i++) {
  2763. REG_WR(bp, BNX2_EMAC_MULTICAST_HASH0 + (i * 4),
  2764. 0xffffffff);
  2765. }
  2766. sort_mode |= BNX2_RPM_SORT_USER0_MC_EN;
  2767. }
  2768. else {
  2769. /* Accept one or more multicast(s). */
  2770. struct dev_mc_list *mclist;
  2771. u32 mc_filter[NUM_MC_HASH_REGISTERS];
  2772. u32 regidx;
  2773. u32 bit;
  2774. u32 crc;
  2775. memset(mc_filter, 0, 4 * NUM_MC_HASH_REGISTERS);
  2776. for (i = 0, mclist = dev->mc_list; mclist && i < dev->mc_count;
  2777. i++, mclist = mclist->next) {
  2778. crc = ether_crc_le(ETH_ALEN, mclist->dmi_addr);
  2779. bit = crc & 0xff;
  2780. regidx = (bit & 0xe0) >> 5;
  2781. bit &= 0x1f;
  2782. mc_filter[regidx] |= (1 << bit);
  2783. }
  2784. for (i = 0; i < NUM_MC_HASH_REGISTERS; i++) {
  2785. REG_WR(bp, BNX2_EMAC_MULTICAST_HASH0 + (i * 4),
  2786. mc_filter[i]);
  2787. }
  2788. sort_mode |= BNX2_RPM_SORT_USER0_MC_HSH_EN;
  2789. }
  2790. uc_ptr = NULL;
  2791. if (dev->uc_count > BNX2_MAX_UNICAST_ADDRESSES) {
  2792. rx_mode |= BNX2_EMAC_RX_MODE_PROMISCUOUS;
  2793. sort_mode |= BNX2_RPM_SORT_USER0_PROM_EN |
  2794. BNX2_RPM_SORT_USER0_PROM_VLAN;
  2795. } else if (!(dev->flags & IFF_PROMISC)) {
  2796. uc_ptr = dev->uc_list;
  2797. /* Add all entries into to the match filter list */
  2798. for (i = 0; i < dev->uc_count; i++) {
  2799. bnx2_set_mac_addr(bp, uc_ptr->da_addr,
  2800. i + BNX2_START_UNICAST_ADDRESS_INDEX);
  2801. sort_mode |= (1 <<
  2802. (i + BNX2_START_UNICAST_ADDRESS_INDEX));
  2803. uc_ptr = uc_ptr->next;
  2804. }
  2805. }
  2806. if (rx_mode != bp->rx_mode) {
  2807. bp->rx_mode = rx_mode;
  2808. REG_WR(bp, BNX2_EMAC_RX_MODE, rx_mode);
  2809. }
  2810. REG_WR(bp, BNX2_RPM_SORT_USER0, 0x0);
  2811. REG_WR(bp, BNX2_RPM_SORT_USER0, sort_mode);
  2812. REG_WR(bp, BNX2_RPM_SORT_USER0, sort_mode | BNX2_RPM_SORT_USER0_ENA);
  2813. spin_unlock_bh(&bp->phy_lock);
  2814. }
  2815. static int __devinit
  2816. check_fw_section(const struct firmware *fw,
  2817. const struct bnx2_fw_file_section *section,
  2818. u32 alignment, bool non_empty)
  2819. {
  2820. u32 offset = be32_to_cpu(section->offset);
  2821. u32 len = be32_to_cpu(section->len);
  2822. if ((offset == 0 && len != 0) || offset >= fw->size || offset & 3)
  2823. return -EINVAL;
  2824. if ((non_empty && len == 0) || len > fw->size - offset ||
  2825. len & (alignment - 1))
  2826. return -EINVAL;
  2827. return 0;
  2828. }
  2829. static int __devinit
  2830. check_mips_fw_entry(const struct firmware *fw,
  2831. const struct bnx2_mips_fw_file_entry *entry)
  2832. {
  2833. if (check_fw_section(fw, &entry->text, 4, true) ||
  2834. check_fw_section(fw, &entry->data, 4, false) ||
  2835. check_fw_section(fw, &entry->rodata, 4, false))
  2836. return -EINVAL;
  2837. return 0;
  2838. }
  2839. static int __devinit
  2840. bnx2_request_firmware(struct bnx2 *bp)
  2841. {
  2842. const char *mips_fw_file, *rv2p_fw_file;
  2843. const struct bnx2_mips_fw_file *mips_fw;
  2844. const struct bnx2_rv2p_fw_file *rv2p_fw;
  2845. int rc;
  2846. if (CHIP_NUM(bp) == CHIP_NUM_5709) {
  2847. mips_fw_file = FW_MIPS_FILE_09;
  2848. rv2p_fw_file = FW_RV2P_FILE_09;
  2849. } else {
  2850. mips_fw_file = FW_MIPS_FILE_06;
  2851. rv2p_fw_file = FW_RV2P_FILE_06;
  2852. }
  2853. rc = request_firmware(&bp->mips_firmware, mips_fw_file, &bp->pdev->dev);
  2854. if (rc) {
  2855. printk(KERN_ERR PFX "Can't load firmware file \"%s\"\n",
  2856. mips_fw_file);
  2857. return rc;
  2858. }
  2859. rc = request_firmware(&bp->rv2p_firmware, rv2p_fw_file, &bp->pdev->dev);
  2860. if (rc) {
  2861. printk(KERN_ERR PFX "Can't load firmware file \"%s\"\n",
  2862. rv2p_fw_file);
  2863. return rc;
  2864. }
  2865. mips_fw = (const struct bnx2_mips_fw_file *) bp->mips_firmware->data;
  2866. rv2p_fw = (const struct bnx2_rv2p_fw_file *) bp->rv2p_firmware->data;
  2867. if (bp->mips_firmware->size < sizeof(*mips_fw) ||
  2868. check_mips_fw_entry(bp->mips_firmware, &mips_fw->com) ||
  2869. check_mips_fw_entry(bp->mips_firmware, &mips_fw->cp) ||
  2870. check_mips_fw_entry(bp->mips_firmware, &mips_fw->rxp) ||
  2871. check_mips_fw_entry(bp->mips_firmware, &mips_fw->tpat) ||
  2872. check_mips_fw_entry(bp->mips_firmware, &mips_fw->txp)) {
  2873. printk(KERN_ERR PFX "Firmware file \"%s\" is invalid\n",
  2874. mips_fw_file);
  2875. return -EINVAL;
  2876. }
  2877. if (bp->rv2p_firmware->size < sizeof(*rv2p_fw) ||
  2878. check_fw_section(bp->rv2p_firmware, &rv2p_fw->proc1.rv2p, 8, true) ||
  2879. check_fw_section(bp->rv2p_firmware, &rv2p_fw->proc2.rv2p, 8, true)) {
  2880. printk(KERN_ERR PFX "Firmware file \"%s\" is invalid\n",
  2881. rv2p_fw_file);
  2882. return -EINVAL;
  2883. }
  2884. return 0;
  2885. }
  2886. static u32
  2887. rv2p_fw_fixup(u32 rv2p_proc, int idx, u32 loc, u32 rv2p_code)
  2888. {
  2889. switch (idx) {
  2890. case RV2P_P1_FIXUP_PAGE_SIZE_IDX:
  2891. rv2p_code &= ~RV2P_BD_PAGE_SIZE_MSK;
  2892. rv2p_code |= RV2P_BD_PAGE_SIZE;
  2893. break;
  2894. }
  2895. return rv2p_code;
  2896. }
  2897. static int
  2898. load_rv2p_fw(struct bnx2 *bp, u32 rv2p_proc,
  2899. const struct bnx2_rv2p_fw_file_entry *fw_entry)
  2900. {
  2901. u32 rv2p_code_len, file_offset;
  2902. __be32 *rv2p_code;
  2903. int i;
  2904. u32 val, cmd, addr;
  2905. rv2p_code_len = be32_to_cpu(fw_entry->rv2p.len);
  2906. file_offset = be32_to_cpu(fw_entry->rv2p.offset);
  2907. rv2p_code = (__be32 *)(bp->rv2p_firmware->data + file_offset);
  2908. if (rv2p_proc == RV2P_PROC1) {
  2909. cmd = BNX2_RV2P_PROC1_ADDR_CMD_RDWR;
  2910. addr = BNX2_RV2P_PROC1_ADDR_CMD;
  2911. } else {
  2912. cmd = BNX2_RV2P_PROC2_ADDR_CMD_RDWR;
  2913. addr = BNX2_RV2P_PROC2_ADDR_CMD;
  2914. }
  2915. for (i = 0; i < rv2p_code_len; i += 8) {
  2916. REG_WR(bp, BNX2_RV2P_INSTR_HIGH, be32_to_cpu(*rv2p_code));
  2917. rv2p_code++;
  2918. REG_WR(bp, BNX2_RV2P_INSTR_LOW, be32_to_cpu(*rv2p_code));
  2919. rv2p_code++;
  2920. val = (i / 8) | cmd;
  2921. REG_WR(bp, addr, val);
  2922. }
  2923. rv2p_code = (__be32 *)(bp->rv2p_firmware->data + file_offset);
  2924. for (i = 0; i < 8; i++) {
  2925. u32 loc, code;
  2926. loc = be32_to_cpu(fw_entry->fixup[i]);
  2927. if (loc && ((loc * 4) < rv2p_code_len)) {
  2928. code = be32_to_cpu(*(rv2p_code + loc - 1));
  2929. REG_WR(bp, BNX2_RV2P_INSTR_HIGH, code);
  2930. code = be32_to_cpu(*(rv2p_code + loc));
  2931. code = rv2p_fw_fixup(rv2p_proc, i, loc, code);
  2932. REG_WR(bp, BNX2_RV2P_INSTR_LOW, code);
  2933. val = (loc / 2) | cmd;
  2934. REG_WR(bp, addr, val);
  2935. }
  2936. }
  2937. /* Reset the processor, un-stall is done later. */
  2938. if (rv2p_proc == RV2P_PROC1) {
  2939. REG_WR(bp, BNX2_RV2P_COMMAND, BNX2_RV2P_COMMAND_PROC1_RESET);
  2940. }
  2941. else {
  2942. REG_WR(bp, BNX2_RV2P_COMMAND, BNX2_RV2P_COMMAND_PROC2_RESET);
  2943. }
  2944. return 0;
  2945. }
  2946. static int
  2947. load_cpu_fw(struct bnx2 *bp, const struct cpu_reg *cpu_reg,
  2948. const struct bnx2_mips_fw_file_entry *fw_entry)
  2949. {
  2950. u32 addr, len, file_offset;
  2951. __be32 *data;
  2952. u32 offset;
  2953. u32 val;
  2954. /* Halt the CPU. */
  2955. val = bnx2_reg_rd_ind(bp, cpu_reg->mode);
  2956. val |= cpu_reg->mode_value_halt;
  2957. bnx2_reg_wr_ind(bp, cpu_reg->mode, val);
  2958. bnx2_reg_wr_ind(bp, cpu_reg->state, cpu_reg->state_value_clear);
  2959. /* Load the Text area. */
  2960. addr = be32_to_cpu(fw_entry->text.addr);
  2961. len = be32_to_cpu(fw_entry->text.len);
  2962. file_offset = be32_to_cpu(fw_entry->text.offset);
  2963. data = (__be32 *)(bp->mips_firmware->data + file_offset);
  2964. offset = cpu_reg->spad_base + (addr - cpu_reg->mips_view_base);
  2965. if (len) {
  2966. int j;
  2967. for (j = 0; j < (len / 4); j++, offset += 4)
  2968. bnx2_reg_wr_ind(bp, offset, be32_to_cpu(data[j]));
  2969. }
  2970. /* Load the Data area. */
  2971. addr = be32_to_cpu(fw_entry->data.addr);
  2972. len = be32_to_cpu(fw_entry->data.len);
  2973. file_offset = be32_to_cpu(fw_entry->data.offset);
  2974. data = (__be32 *)(bp->mips_firmware->data + file_offset);
  2975. offset = cpu_reg->spad_base + (addr - cpu_reg->mips_view_base);
  2976. if (len) {
  2977. int j;
  2978. for (j = 0; j < (len / 4); j++, offset += 4)
  2979. bnx2_reg_wr_ind(bp, offset, be32_to_cpu(data[j]));
  2980. }
  2981. /* Load the Read-Only area. */
  2982. addr = be32_to_cpu(fw_entry->rodata.addr);
  2983. len = be32_to_cpu(fw_entry->rodata.len);
  2984. file_offset = be32_to_cpu(fw_entry->rodata.offset);
  2985. data = (__be32 *)(bp->mips_firmware->data + file_offset);
  2986. offset = cpu_reg->spad_base + (addr - cpu_reg->mips_view_base);
  2987. if (len) {
  2988. int j;
  2989. for (j = 0; j < (len / 4); j++, offset += 4)
  2990. bnx2_reg_wr_ind(bp, offset, be32_to_cpu(data[j]));
  2991. }
  2992. /* Clear the pre-fetch instruction. */
  2993. bnx2_reg_wr_ind(bp, cpu_reg->inst, 0);
  2994. val = be32_to_cpu(fw_entry->start_addr);
  2995. bnx2_reg_wr_ind(bp, cpu_reg->pc, val);
  2996. /* Start the CPU. */
  2997. val = bnx2_reg_rd_ind(bp, cpu_reg->mode);
  2998. val &= ~cpu_reg->mode_value_halt;
  2999. bnx2_reg_wr_ind(bp, cpu_reg->state, cpu_reg->state_value_clear);
  3000. bnx2_reg_wr_ind(bp, cpu_reg->mode, val);
  3001. return 0;
  3002. }
  3003. static int
  3004. bnx2_init_cpus(struct bnx2 *bp)
  3005. {
  3006. const struct bnx2_mips_fw_file *mips_fw =
  3007. (const struct bnx2_mips_fw_file *) bp->mips_firmware->data;
  3008. const struct bnx2_rv2p_fw_file *rv2p_fw =
  3009. (const struct bnx2_rv2p_fw_file *) bp->rv2p_firmware->data;
  3010. int rc;
  3011. /* Initialize the RV2P processor. */
  3012. load_rv2p_fw(bp, RV2P_PROC1, &rv2p_fw->proc1);
  3013. load_rv2p_fw(bp, RV2P_PROC2, &rv2p_fw->proc2);
  3014. /* Initialize the RX Processor. */
  3015. rc = load_cpu_fw(bp, &cpu_reg_rxp, &mips_fw->rxp);
  3016. if (rc)
  3017. goto init_cpu_err;
  3018. /* Initialize the TX Processor. */
  3019. rc = load_cpu_fw(bp, &cpu_reg_txp, &mips_fw->txp);
  3020. if (rc)
  3021. goto init_cpu_err;
  3022. /* Initialize the TX Patch-up Processor. */
  3023. rc = load_cpu_fw(bp, &cpu_reg_tpat, &mips_fw->tpat);
  3024. if (rc)
  3025. goto init_cpu_err;
  3026. /* Initialize the Completion Processor. */
  3027. rc = load_cpu_fw(bp, &cpu_reg_com, &mips_fw->com);
  3028. if (rc)
  3029. goto init_cpu_err;
  3030. /* Initialize the Command Processor. */
  3031. rc = load_cpu_fw(bp, &cpu_reg_cp, &mips_fw->cp);
  3032. init_cpu_err:
  3033. return rc;
  3034. }
  3035. static int
  3036. bnx2_set_power_state(struct bnx2 *bp, pci_power_t state)
  3037. {
  3038. u16 pmcsr;
  3039. pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, &pmcsr);
  3040. switch (state) {
  3041. case PCI_D0: {
  3042. u32 val;
  3043. pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL,
  3044. (pmcsr & ~PCI_PM_CTRL_STATE_MASK) |
  3045. PCI_PM_CTRL_PME_STATUS);
  3046. if (pmcsr & PCI_PM_CTRL_STATE_MASK)
  3047. /* delay required during transition out of D3hot */
  3048. msleep(20);
  3049. val = REG_RD(bp, BNX2_EMAC_MODE);
  3050. val |= BNX2_EMAC_MODE_MPKT_RCVD | BNX2_EMAC_MODE_ACPI_RCVD;
  3051. val &= ~BNX2_EMAC_MODE_MPKT;
  3052. REG_WR(bp, BNX2_EMAC_MODE, val);
  3053. val = REG_RD(bp, BNX2_RPM_CONFIG);
  3054. val &= ~BNX2_RPM_CONFIG_ACPI_ENA;
  3055. REG_WR(bp, BNX2_RPM_CONFIG, val);
  3056. break;
  3057. }
  3058. case PCI_D3hot: {
  3059. int i;
  3060. u32 val, wol_msg;
  3061. if (bp->wol) {
  3062. u32 advertising;
  3063. u8 autoneg;
  3064. autoneg = bp->autoneg;
  3065. advertising = bp->advertising;
  3066. if (bp->phy_port == PORT_TP) {
  3067. bp->autoneg = AUTONEG_SPEED;
  3068. bp->advertising = ADVERTISED_10baseT_Half |
  3069. ADVERTISED_10baseT_Full |
  3070. ADVERTISED_100baseT_Half |
  3071. ADVERTISED_100baseT_Full |
  3072. ADVERTISED_Autoneg;
  3073. }
  3074. spin_lock_bh(&bp->phy_lock);
  3075. bnx2_setup_phy(bp, bp->phy_port);
  3076. spin_unlock_bh(&bp->phy_lock);
  3077. bp->autoneg = autoneg;
  3078. bp->advertising = advertising;
  3079. bnx2_set_mac_addr(bp, bp->dev->dev_addr, 0);
  3080. val = REG_RD(bp, BNX2_EMAC_MODE);
  3081. /* Enable port mode. */
  3082. val &= ~BNX2_EMAC_MODE_PORT;
  3083. val |= BNX2_EMAC_MODE_MPKT_RCVD |
  3084. BNX2_EMAC_MODE_ACPI_RCVD |
  3085. BNX2_EMAC_MODE_MPKT;
  3086. if (bp->phy_port == PORT_TP)
  3087. val |= BNX2_EMAC_MODE_PORT_MII;
  3088. else {
  3089. val |= BNX2_EMAC_MODE_PORT_GMII;
  3090. if (bp->line_speed == SPEED_2500)
  3091. val |= BNX2_EMAC_MODE_25G_MODE;
  3092. }
  3093. REG_WR(bp, BNX2_EMAC_MODE, val);
  3094. /* receive all multicast */
  3095. for (i = 0; i < NUM_MC_HASH_REGISTERS; i++) {
  3096. REG_WR(bp, BNX2_EMAC_MULTICAST_HASH0 + (i * 4),
  3097. 0xffffffff);
  3098. }
  3099. REG_WR(bp, BNX2_EMAC_RX_MODE,
  3100. BNX2_EMAC_RX_MODE_SORT_MODE);
  3101. val = 1 | BNX2_RPM_SORT_USER0_BC_EN |
  3102. BNX2_RPM_SORT_USER0_MC_EN;
  3103. REG_WR(bp, BNX2_RPM_SORT_USER0, 0x0);
  3104. REG_WR(bp, BNX2_RPM_SORT_USER0, val);
  3105. REG_WR(bp, BNX2_RPM_SORT_USER0, val |
  3106. BNX2_RPM_SORT_USER0_ENA);
  3107. /* Need to enable EMAC and RPM for WOL. */
  3108. REG_WR(bp, BNX2_MISC_ENABLE_SET_BITS,
  3109. BNX2_MISC_ENABLE_SET_BITS_RX_PARSER_MAC_ENABLE |
  3110. BNX2_MISC_ENABLE_SET_BITS_TX_HEADER_Q_ENABLE |
  3111. BNX2_MISC_ENABLE_SET_BITS_EMAC_ENABLE);
  3112. val = REG_RD(bp, BNX2_RPM_CONFIG);
  3113. val &= ~BNX2_RPM_CONFIG_ACPI_ENA;
  3114. REG_WR(bp, BNX2_RPM_CONFIG, val);
  3115. wol_msg = BNX2_DRV_MSG_CODE_SUSPEND_WOL;
  3116. }
  3117. else {
  3118. wol_msg = BNX2_DRV_MSG_CODE_SUSPEND_NO_WOL;
  3119. }
  3120. if (!(bp->flags & BNX2_FLAG_NO_WOL))
  3121. bnx2_fw_sync(bp, BNX2_DRV_MSG_DATA_WAIT3 | wol_msg,
  3122. 1, 0);
  3123. pmcsr &= ~PCI_PM_CTRL_STATE_MASK;
  3124. if ((CHIP_ID(bp) == CHIP_ID_5706_A0) ||
  3125. (CHIP_ID(bp) == CHIP_ID_5706_A1)) {
  3126. if (bp->wol)
  3127. pmcsr |= 3;
  3128. }
  3129. else {
  3130. pmcsr |= 3;
  3131. }
  3132. if (bp->wol) {
  3133. pmcsr |= PCI_PM_CTRL_PME_ENABLE;
  3134. }
  3135. pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL,
  3136. pmcsr);
  3137. /* No more memory access after this point until
  3138. * device is brought back to D0.
  3139. */
  3140. udelay(50);
  3141. break;
  3142. }
  3143. default:
  3144. return -EINVAL;
  3145. }
  3146. return 0;
  3147. }
  3148. static int
  3149. bnx2_acquire_nvram_lock(struct bnx2 *bp)
  3150. {
  3151. u32 val;
  3152. int j;
  3153. /* Request access to the flash interface. */
  3154. REG_WR(bp, BNX2_NVM_SW_ARB, BNX2_NVM_SW_ARB_ARB_REQ_SET2);
  3155. for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
  3156. val = REG_RD(bp, BNX2_NVM_SW_ARB);
  3157. if (val & BNX2_NVM_SW_ARB_ARB_ARB2)
  3158. break;
  3159. udelay(5);
  3160. }
  3161. if (j >= NVRAM_TIMEOUT_COUNT)
  3162. return -EBUSY;
  3163. return 0;
  3164. }
  3165. static int
  3166. bnx2_release_nvram_lock(struct bnx2 *bp)
  3167. {
  3168. int j;
  3169. u32 val;
  3170. /* Relinquish nvram interface. */
  3171. REG_WR(bp, BNX2_NVM_SW_ARB, BNX2_NVM_SW_ARB_ARB_REQ_CLR2);
  3172. for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
  3173. val = REG_RD(bp, BNX2_NVM_SW_ARB);
  3174. if (!(val & BNX2_NVM_SW_ARB_ARB_ARB2))
  3175. break;
  3176. udelay(5);
  3177. }
  3178. if (j >= NVRAM_TIMEOUT_COUNT)
  3179. return -EBUSY;
  3180. return 0;
  3181. }
  3182. static int
  3183. bnx2_enable_nvram_write(struct bnx2 *bp)
  3184. {
  3185. u32 val;
  3186. val = REG_RD(bp, BNX2_MISC_CFG);
  3187. REG_WR(bp, BNX2_MISC_CFG, val | BNX2_MISC_CFG_NVM_WR_EN_PCI);
  3188. if (bp->flash_info->flags & BNX2_NV_WREN) {
  3189. int j;
  3190. REG_WR(bp, BNX2_NVM_COMMAND, BNX2_NVM_COMMAND_DONE);
  3191. REG_WR(bp, BNX2_NVM_COMMAND,
  3192. BNX2_NVM_COMMAND_WREN | BNX2_NVM_COMMAND_DOIT);
  3193. for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
  3194. udelay(5);
  3195. val = REG_RD(bp, BNX2_NVM_COMMAND);
  3196. if (val & BNX2_NVM_COMMAND_DONE)
  3197. break;
  3198. }
  3199. if (j >= NVRAM_TIMEOUT_COUNT)
  3200. return -EBUSY;
  3201. }
  3202. return 0;
  3203. }
  3204. static void
  3205. bnx2_disable_nvram_write(struct bnx2 *bp)
  3206. {
  3207. u32 val;
  3208. val = REG_RD(bp, BNX2_MISC_CFG);
  3209. REG_WR(bp, BNX2_MISC_CFG, val & ~BNX2_MISC_CFG_NVM_WR_EN);
  3210. }
  3211. static void
  3212. bnx2_enable_nvram_access(struct bnx2 *bp)
  3213. {
  3214. u32 val;
  3215. val = REG_RD(bp, BNX2_NVM_ACCESS_ENABLE);
  3216. /* Enable both bits, even on read. */
  3217. REG_WR(bp, BNX2_NVM_ACCESS_ENABLE,
  3218. val | BNX2_NVM_ACCESS_ENABLE_EN | BNX2_NVM_ACCESS_ENABLE_WR_EN);
  3219. }
  3220. static void
  3221. bnx2_disable_nvram_access(struct bnx2 *bp)
  3222. {
  3223. u32 val;
  3224. val = REG_RD(bp, BNX2_NVM_ACCESS_ENABLE);
  3225. /* Disable both bits, even after read. */
  3226. REG_WR(bp, BNX2_NVM_ACCESS_ENABLE,
  3227. val & ~(BNX2_NVM_ACCESS_ENABLE_EN |
  3228. BNX2_NVM_ACCESS_ENABLE_WR_EN));
  3229. }
  3230. static int
  3231. bnx2_nvram_erase_page(struct bnx2 *bp, u32 offset)
  3232. {
  3233. u32 cmd;
  3234. int j;
  3235. if (bp->flash_info->flags & BNX2_NV_BUFFERED)
  3236. /* Buffered flash, no erase needed */
  3237. return 0;
  3238. /* Build an erase command */
  3239. cmd = BNX2_NVM_COMMAND_ERASE | BNX2_NVM_COMMAND_WR |
  3240. BNX2_NVM_COMMAND_DOIT;
  3241. /* Need to clear DONE bit separately. */
  3242. REG_WR(bp, BNX2_NVM_COMMAND, BNX2_NVM_COMMAND_DONE);
  3243. /* Address of the NVRAM to read from. */
  3244. REG_WR(bp, BNX2_NVM_ADDR, offset & BNX2_NVM_ADDR_NVM_ADDR_VALUE);
  3245. /* Issue an erase command. */
  3246. REG_WR(bp, BNX2_NVM_COMMAND, cmd);
  3247. /* Wait for completion. */
  3248. for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
  3249. u32 val;
  3250. udelay(5);
  3251. val = REG_RD(bp, BNX2_NVM_COMMAND);
  3252. if (val & BNX2_NVM_COMMAND_DONE)
  3253. break;
  3254. }
  3255. if (j >= NVRAM_TIMEOUT_COUNT)
  3256. return -EBUSY;
  3257. return 0;
  3258. }
  3259. static int
  3260. bnx2_nvram_read_dword(struct bnx2 *bp, u32 offset, u8 *ret_val, u32 cmd_flags)
  3261. {
  3262. u32 cmd;
  3263. int j;
  3264. /* Build the command word. */
  3265. cmd = BNX2_NVM_COMMAND_DOIT | cmd_flags;
  3266. /* Calculate an offset of a buffered flash, not needed for 5709. */
  3267. if (bp->flash_info->flags & BNX2_NV_TRANSLATE) {
  3268. offset = ((offset / bp->flash_info->page_size) <<
  3269. bp->flash_info->page_bits) +
  3270. (offset % bp->flash_info->page_size);
  3271. }
  3272. /* Need to clear DONE bit separately. */
  3273. REG_WR(bp, BNX2_NVM_COMMAND, BNX2_NVM_COMMAND_DONE);
  3274. /* Address of the NVRAM to read from. */
  3275. REG_WR(bp, BNX2_NVM_ADDR, offset & BNX2_NVM_ADDR_NVM_ADDR_VALUE);
  3276. /* Issue a read command. */
  3277. REG_WR(bp, BNX2_NVM_COMMAND, cmd);
  3278. /* Wait for completion. */
  3279. for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
  3280. u32 val;
  3281. udelay(5);
  3282. val = REG_RD(bp, BNX2_NVM_COMMAND);
  3283. if (val & BNX2_NVM_COMMAND_DONE) {
  3284. __be32 v = cpu_to_be32(REG_RD(bp, BNX2_NVM_READ));
  3285. memcpy(ret_val, &v, 4);
  3286. break;
  3287. }
  3288. }
  3289. if (j >= NVRAM_TIMEOUT_COUNT)
  3290. return -EBUSY;
  3291. return 0;
  3292. }
  3293. static int
  3294. bnx2_nvram_write_dword(struct bnx2 *bp, u32 offset, u8 *val, u32 cmd_flags)
  3295. {
  3296. u32 cmd;
  3297. __be32 val32;
  3298. int j;
  3299. /* Build the command word. */
  3300. cmd = BNX2_NVM_COMMAND_DOIT | BNX2_NVM_COMMAND_WR | cmd_flags;
  3301. /* Calculate an offset of a buffered flash, not needed for 5709. */
  3302. if (bp->flash_info->flags & BNX2_NV_TRANSLATE) {
  3303. offset = ((offset / bp->flash_info->page_size) <<
  3304. bp->flash_info->page_bits) +
  3305. (offset % bp->flash_info->page_size);
  3306. }
  3307. /* Need to clear DONE bit separately. */
  3308. REG_WR(bp, BNX2_NVM_COMMAND, BNX2_NVM_COMMAND_DONE);
  3309. memcpy(&val32, val, 4);
  3310. /* Write the data. */
  3311. REG_WR(bp, BNX2_NVM_WRITE, be32_to_cpu(val32));
  3312. /* Address of the NVRAM to write to. */
  3313. REG_WR(bp, BNX2_NVM_ADDR, offset & BNX2_NVM_ADDR_NVM_ADDR_VALUE);
  3314. /* Issue the write command. */
  3315. REG_WR(bp, BNX2_NVM_COMMAND, cmd);
  3316. /* Wait for completion. */
  3317. for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
  3318. udelay(5);
  3319. if (REG_RD(bp, BNX2_NVM_COMMAND) & BNX2_NVM_COMMAND_DONE)
  3320. break;
  3321. }
  3322. if (j >= NVRAM_TIMEOUT_COUNT)
  3323. return -EBUSY;
  3324. return 0;
  3325. }
  3326. static int
  3327. bnx2_init_nvram(struct bnx2 *bp)
  3328. {
  3329. u32 val;
  3330. int j, entry_count, rc = 0;
  3331. struct flash_spec *flash;
  3332. if (CHIP_NUM(bp) == CHIP_NUM_5709) {
  3333. bp->flash_info = &flash_5709;
  3334. goto get_flash_size;
  3335. }
  3336. /* Determine the selected interface. */
  3337. val = REG_RD(bp, BNX2_NVM_CFG1);
  3338. entry_count = ARRAY_SIZE(flash_table);
  3339. if (val & 0x40000000) {
  3340. /* Flash interface has been reconfigured */
  3341. for (j = 0, flash = &flash_table[0]; j < entry_count;
  3342. j++, flash++) {
  3343. if ((val & FLASH_BACKUP_STRAP_MASK) ==
  3344. (flash->config1 & FLASH_BACKUP_STRAP_MASK)) {
  3345. bp->flash_info = flash;
  3346. break;
  3347. }
  3348. }
  3349. }
  3350. else {
  3351. u32 mask;
  3352. /* Not yet been reconfigured */
  3353. if (val & (1 << 23))
  3354. mask = FLASH_BACKUP_STRAP_MASK;
  3355. else
  3356. mask = FLASH_STRAP_MASK;
  3357. for (j = 0, flash = &flash_table[0]; j < entry_count;
  3358. j++, flash++) {
  3359. if ((val & mask) == (flash->strapping & mask)) {
  3360. bp->flash_info = flash;
  3361. /* Request access to the flash interface. */
  3362. if ((rc = bnx2_acquire_nvram_lock(bp)) != 0)
  3363. return rc;
  3364. /* Enable access to flash interface */
  3365. bnx2_enable_nvram_access(bp);
  3366. /* Reconfigure the flash interface */
  3367. REG_WR(bp, BNX2_NVM_CFG1, flash->config1);
  3368. REG_WR(bp, BNX2_NVM_CFG2, flash->config2);
  3369. REG_WR(bp, BNX2_NVM_CFG3, flash->config3);
  3370. REG_WR(bp, BNX2_NVM_WRITE1, flash->write1);
  3371. /* Disable access to flash interface */
  3372. bnx2_disable_nvram_access(bp);
  3373. bnx2_release_nvram_lock(bp);
  3374. break;
  3375. }
  3376. }
  3377. } /* if (val & 0x40000000) */
  3378. if (j == entry_count) {
  3379. bp->flash_info = NULL;
  3380. printk(KERN_ALERT PFX "Unknown flash/EEPROM type.\n");
  3381. return -ENODEV;
  3382. }
  3383. get_flash_size:
  3384. val = bnx2_shmem_rd(bp, BNX2_SHARED_HW_CFG_CONFIG2);
  3385. val &= BNX2_SHARED_HW_CFG2_NVM_SIZE_MASK;
  3386. if (val)
  3387. bp->flash_size = val;
  3388. else
  3389. bp->flash_size = bp->flash_info->total_size;
  3390. return rc;
  3391. }
  3392. static int
  3393. bnx2_nvram_read(struct bnx2 *bp, u32 offset, u8 *ret_buf,
  3394. int buf_size)
  3395. {
  3396. int rc = 0;
  3397. u32 cmd_flags, offset32, len32, extra;
  3398. if (buf_size == 0)
  3399. return 0;
  3400. /* Request access to the flash interface. */
  3401. if ((rc = bnx2_acquire_nvram_lock(bp)) != 0)
  3402. return rc;
  3403. /* Enable access to flash interface */
  3404. bnx2_enable_nvram_access(bp);
  3405. len32 = buf_size;
  3406. offset32 = offset;
  3407. extra = 0;
  3408. cmd_flags = 0;
  3409. if (offset32 & 3) {
  3410. u8 buf[4];
  3411. u32 pre_len;
  3412. offset32 &= ~3;
  3413. pre_len = 4 - (offset & 3);
  3414. if (pre_len >= len32) {
  3415. pre_len = len32;
  3416. cmd_flags = BNX2_NVM_COMMAND_FIRST |
  3417. BNX2_NVM_COMMAND_LAST;
  3418. }
  3419. else {
  3420. cmd_flags = BNX2_NVM_COMMAND_FIRST;
  3421. }
  3422. rc = bnx2_nvram_read_dword(bp, offset32, buf, cmd_flags);
  3423. if (rc)
  3424. return rc;
  3425. memcpy(ret_buf, buf + (offset & 3), pre_len);
  3426. offset32 += 4;
  3427. ret_buf += pre_len;
  3428. len32 -= pre_len;
  3429. }
  3430. if (len32 & 3) {
  3431. extra = 4 - (len32 & 3);
  3432. len32 = (len32 + 4) & ~3;
  3433. }
  3434. if (len32 == 4) {
  3435. u8 buf[4];
  3436. if (cmd_flags)
  3437. cmd_flags = BNX2_NVM_COMMAND_LAST;
  3438. else
  3439. cmd_flags = BNX2_NVM_COMMAND_FIRST |
  3440. BNX2_NVM_COMMAND_LAST;
  3441. rc = bnx2_nvram_read_dword(bp, offset32, buf, cmd_flags);
  3442. memcpy(ret_buf, buf, 4 - extra);
  3443. }
  3444. else if (len32 > 0) {
  3445. u8 buf[4];
  3446. /* Read the first word. */
  3447. if (cmd_flags)
  3448. cmd_flags = 0;
  3449. else
  3450. cmd_flags = BNX2_NVM_COMMAND_FIRST;
  3451. rc = bnx2_nvram_read_dword(bp, offset32, ret_buf, cmd_flags);
  3452. /* Advance to the next dword. */
  3453. offset32 += 4;
  3454. ret_buf += 4;
  3455. len32 -= 4;
  3456. while (len32 > 4 && rc == 0) {
  3457. rc = bnx2_nvram_read_dword(bp, offset32, ret_buf, 0);
  3458. /* Advance to the next dword. */
  3459. offset32 += 4;
  3460. ret_buf += 4;
  3461. len32 -= 4;
  3462. }
  3463. if (rc)
  3464. return rc;
  3465. cmd_flags = BNX2_NVM_COMMAND_LAST;
  3466. rc = bnx2_nvram_read_dword(bp, offset32, buf, cmd_flags);
  3467. memcpy(ret_buf, buf, 4 - extra);
  3468. }
  3469. /* Disable access to flash interface */
  3470. bnx2_disable_nvram_access(bp);
  3471. bnx2_release_nvram_lock(bp);
  3472. return rc;
  3473. }
  3474. static int
  3475. bnx2_nvram_write(struct bnx2 *bp, u32 offset, u8 *data_buf,
  3476. int buf_size)
  3477. {
  3478. u32 written, offset32, len32;
  3479. u8 *buf, start[4], end[4], *align_buf = NULL, *flash_buffer = NULL;
  3480. int rc = 0;
  3481. int align_start, align_end;
  3482. buf = data_buf;
  3483. offset32 = offset;
  3484. len32 = buf_size;
  3485. align_start = align_end = 0;
  3486. if ((align_start = (offset32 & 3))) {
  3487. offset32 &= ~3;
  3488. len32 += align_start;
  3489. if (len32 < 4)
  3490. len32 = 4;
  3491. if ((rc = bnx2_nvram_read(bp, offset32, start, 4)))
  3492. return rc;
  3493. }
  3494. if (len32 & 3) {
  3495. align_end = 4 - (len32 & 3);
  3496. len32 += align_end;
  3497. if ((rc = bnx2_nvram_read(bp, offset32 + len32 - 4, end, 4)))
  3498. return rc;
  3499. }
  3500. if (align_start || align_end) {
  3501. align_buf = kmalloc(len32, GFP_KERNEL);
  3502. if (align_buf == NULL)
  3503. return -ENOMEM;
  3504. if (align_start) {
  3505. memcpy(align_buf, start, 4);
  3506. }
  3507. if (align_end) {
  3508. memcpy(align_buf + len32 - 4, end, 4);
  3509. }
  3510. memcpy(align_buf + align_start, data_buf, buf_size);
  3511. buf = align_buf;
  3512. }
  3513. if (!(bp->flash_info->flags & BNX2_NV_BUFFERED)) {
  3514. flash_buffer = kmalloc(264, GFP_KERNEL);
  3515. if (flash_buffer == NULL) {
  3516. rc = -ENOMEM;
  3517. goto nvram_write_end;
  3518. }
  3519. }
  3520. written = 0;
  3521. while ((written < len32) && (rc == 0)) {
  3522. u32 page_start, page_end, data_start, data_end;
  3523. u32 addr, cmd_flags;
  3524. int i;
  3525. /* Find the page_start addr */
  3526. page_start = offset32 + written;
  3527. page_start -= (page_start % bp->flash_info->page_size);
  3528. /* Find the page_end addr */
  3529. page_end = page_start + bp->flash_info->page_size;
  3530. /* Find the data_start addr */
  3531. data_start = (written == 0) ? offset32 : page_start;
  3532. /* Find the data_end addr */
  3533. data_end = (page_end > offset32 + len32) ?
  3534. (offset32 + len32) : page_end;
  3535. /* Request access to the flash interface. */
  3536. if ((rc = bnx2_acquire_nvram_lock(bp)) != 0)
  3537. goto nvram_write_end;
  3538. /* Enable access to flash interface */
  3539. bnx2_enable_nvram_access(bp);
  3540. cmd_flags = BNX2_NVM_COMMAND_FIRST;
  3541. if (!(bp->flash_info->flags & BNX2_NV_BUFFERED)) {
  3542. int j;
  3543. /* Read the whole page into the buffer
  3544. * (non-buffer flash only) */
  3545. for (j = 0; j < bp->flash_info->page_size; j += 4) {
  3546. if (j == (bp->flash_info->page_size - 4)) {
  3547. cmd_flags |= BNX2_NVM_COMMAND_LAST;
  3548. }
  3549. rc = bnx2_nvram_read_dword(bp,
  3550. page_start + j,
  3551. &flash_buffer[j],
  3552. cmd_flags);
  3553. if (rc)
  3554. goto nvram_write_end;
  3555. cmd_flags = 0;
  3556. }
  3557. }
  3558. /* Enable writes to flash interface (unlock write-protect) */
  3559. if ((rc = bnx2_enable_nvram_write(bp)) != 0)
  3560. goto nvram_write_end;
  3561. /* Loop to write back the buffer data from page_start to
  3562. * data_start */
  3563. i = 0;
  3564. if (!(bp->flash_info->flags & BNX2_NV_BUFFERED)) {
  3565. /* Erase the page */
  3566. if ((rc = bnx2_nvram_erase_page(bp, page_start)) != 0)
  3567. goto nvram_write_end;
  3568. /* Re-enable the write again for the actual write */
  3569. bnx2_enable_nvram_write(bp);
  3570. for (addr = page_start; addr < data_start;
  3571. addr += 4, i += 4) {
  3572. rc = bnx2_nvram_write_dword(bp, addr,
  3573. &flash_buffer[i], cmd_flags);
  3574. if (rc != 0)
  3575. goto nvram_write_end;
  3576. cmd_flags = 0;
  3577. }
  3578. }
  3579. /* Loop to write the new data from data_start to data_end */
  3580. for (addr = data_start; addr < data_end; addr += 4, i += 4) {
  3581. if ((addr == page_end - 4) ||
  3582. ((bp->flash_info->flags & BNX2_NV_BUFFERED) &&
  3583. (addr == data_end - 4))) {
  3584. cmd_flags |= BNX2_NVM_COMMAND_LAST;
  3585. }
  3586. rc = bnx2_nvram_write_dword(bp, addr, buf,
  3587. cmd_flags);
  3588. if (rc != 0)
  3589. goto nvram_write_end;
  3590. cmd_flags = 0;
  3591. buf += 4;
  3592. }
  3593. /* Loop to write back the buffer data from data_end
  3594. * to page_end */
  3595. if (!(bp->flash_info->flags & BNX2_NV_BUFFERED)) {
  3596. for (addr = data_end; addr < page_end;
  3597. addr += 4, i += 4) {
  3598. if (addr == page_end-4) {
  3599. cmd_flags = BNX2_NVM_COMMAND_LAST;
  3600. }
  3601. rc = bnx2_nvram_write_dword(bp, addr,
  3602. &flash_buffer[i], cmd_flags);
  3603. if (rc != 0)
  3604. goto nvram_write_end;
  3605. cmd_flags = 0;
  3606. }
  3607. }
  3608. /* Disable writes to flash interface (lock write-protect) */
  3609. bnx2_disable_nvram_write(bp);
  3610. /* Disable access to flash interface */
  3611. bnx2_disable_nvram_access(bp);
  3612. bnx2_release_nvram_lock(bp);
  3613. /* Increment written */
  3614. written += data_end - data_start;
  3615. }
  3616. nvram_write_end:
  3617. kfree(flash_buffer);
  3618. kfree(align_buf);
  3619. return rc;
  3620. }
  3621. static void
  3622. bnx2_init_fw_cap(struct bnx2 *bp)
  3623. {
  3624. u32 val, sig = 0;
  3625. bp->phy_flags &= ~BNX2_PHY_FLAG_REMOTE_PHY_CAP;
  3626. bp->flags &= ~BNX2_FLAG_CAN_KEEP_VLAN;
  3627. if (!(bp->flags & BNX2_FLAG_ASF_ENABLE))
  3628. bp->flags |= BNX2_FLAG_CAN_KEEP_VLAN;
  3629. val = bnx2_shmem_rd(bp, BNX2_FW_CAP_MB);
  3630. if ((val & BNX2_FW_CAP_SIGNATURE_MASK) != BNX2_FW_CAP_SIGNATURE)
  3631. return;
  3632. if ((val & BNX2_FW_CAP_CAN_KEEP_VLAN) == BNX2_FW_CAP_CAN_KEEP_VLAN) {
  3633. bp->flags |= BNX2_FLAG_CAN_KEEP_VLAN;
  3634. sig |= BNX2_DRV_ACK_CAP_SIGNATURE | BNX2_FW_CAP_CAN_KEEP_VLAN;
  3635. }
  3636. if ((bp->phy_flags & BNX2_PHY_FLAG_SERDES) &&
  3637. (val & BNX2_FW_CAP_REMOTE_PHY_CAPABLE)) {
  3638. u32 link;
  3639. bp->phy_flags |= BNX2_PHY_FLAG_REMOTE_PHY_CAP;
  3640. link = bnx2_shmem_rd(bp, BNX2_LINK_STATUS);
  3641. if (link & BNX2_LINK_STATUS_SERDES_LINK)
  3642. bp->phy_port = PORT_FIBRE;
  3643. else
  3644. bp->phy_port = PORT_TP;
  3645. sig |= BNX2_DRV_ACK_CAP_SIGNATURE |
  3646. BNX2_FW_CAP_REMOTE_PHY_CAPABLE;
  3647. }
  3648. if (netif_running(bp->dev) && sig)
  3649. bnx2_shmem_wr(bp, BNX2_DRV_ACK_CAP_MB, sig);
  3650. }
  3651. static void
  3652. bnx2_setup_msix_tbl(struct bnx2 *bp)
  3653. {
  3654. REG_WR(bp, BNX2_PCI_GRC_WINDOW_ADDR, BNX2_PCI_GRC_WINDOW_ADDR_SEP_WIN);
  3655. REG_WR(bp, BNX2_PCI_GRC_WINDOW2_ADDR, BNX2_MSIX_TABLE_ADDR);
  3656. REG_WR(bp, BNX2_PCI_GRC_WINDOW3_ADDR, BNX2_MSIX_PBA_ADDR);
  3657. }
  3658. static int
  3659. bnx2_reset_chip(struct bnx2 *bp, u32 reset_code)
  3660. {
  3661. u32 val;
  3662. int i, rc = 0;
  3663. u8 old_port;
  3664. /* Wait for the current PCI transaction to complete before
  3665. * issuing a reset. */
  3666. REG_WR(bp, BNX2_MISC_ENABLE_CLR_BITS,
  3667. BNX2_MISC_ENABLE_CLR_BITS_TX_DMA_ENABLE |
  3668. BNX2_MISC_ENABLE_CLR_BITS_DMA_ENGINE_ENABLE |
  3669. BNX2_MISC_ENABLE_CLR_BITS_RX_DMA_ENABLE |
  3670. BNX2_MISC_ENABLE_CLR_BITS_HOST_COALESCE_ENABLE);
  3671. val = REG_RD(bp, BNX2_MISC_ENABLE_CLR_BITS);
  3672. udelay(5);
  3673. /* Wait for the firmware to tell us it is ok to issue a reset. */
  3674. bnx2_fw_sync(bp, BNX2_DRV_MSG_DATA_WAIT0 | reset_code, 1, 1);
  3675. /* Deposit a driver reset signature so the firmware knows that
  3676. * this is a soft reset. */
  3677. bnx2_shmem_wr(bp, BNX2_DRV_RESET_SIGNATURE,
  3678. BNX2_DRV_RESET_SIGNATURE_MAGIC);
  3679. /* Do a dummy read to force the chip to complete all current transaction
  3680. * before we issue a reset. */
  3681. val = REG_RD(bp, BNX2_MISC_ID);
  3682. if (CHIP_NUM(bp) == CHIP_NUM_5709) {
  3683. REG_WR(bp, BNX2_MISC_COMMAND, BNX2_MISC_COMMAND_SW_RESET);
  3684. REG_RD(bp, BNX2_MISC_COMMAND);
  3685. udelay(5);
  3686. val = BNX2_PCICFG_MISC_CONFIG_REG_WINDOW_ENA |
  3687. BNX2_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP;
  3688. pci_write_config_dword(bp->pdev, BNX2_PCICFG_MISC_CONFIG, val);
  3689. } else {
  3690. val = BNX2_PCICFG_MISC_CONFIG_CORE_RST_REQ |
  3691. BNX2_PCICFG_MISC_CONFIG_REG_WINDOW_ENA |
  3692. BNX2_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP;
  3693. /* Chip reset. */
  3694. REG_WR(bp, BNX2_PCICFG_MISC_CONFIG, val);
  3695. /* Reading back any register after chip reset will hang the
  3696. * bus on 5706 A0 and A1. The msleep below provides plenty
  3697. * of margin for write posting.
  3698. */
  3699. if ((CHIP_ID(bp) == CHIP_ID_5706_A0) ||
  3700. (CHIP_ID(bp) == CHIP_ID_5706_A1))
  3701. msleep(20);
  3702. /* Reset takes approximate 30 usec */
  3703. for (i = 0; i < 10; i++) {
  3704. val = REG_RD(bp, BNX2_PCICFG_MISC_CONFIG);
  3705. if ((val & (BNX2_PCICFG_MISC_CONFIG_CORE_RST_REQ |
  3706. BNX2_PCICFG_MISC_CONFIG_CORE_RST_BSY)) == 0)
  3707. break;
  3708. udelay(10);
  3709. }
  3710. if (val & (BNX2_PCICFG_MISC_CONFIG_CORE_RST_REQ |
  3711. BNX2_PCICFG_MISC_CONFIG_CORE_RST_BSY)) {
  3712. printk(KERN_ERR PFX "Chip reset did not complete\n");
  3713. return -EBUSY;
  3714. }
  3715. }
  3716. /* Make sure byte swapping is properly configured. */
  3717. val = REG_RD(bp, BNX2_PCI_SWAP_DIAG0);
  3718. if (val != 0x01020304) {
  3719. printk(KERN_ERR PFX "Chip not in correct endian mode\n");
  3720. return -ENODEV;
  3721. }
  3722. /* Wait for the firmware to finish its initialization. */
  3723. rc = bnx2_fw_sync(bp, BNX2_DRV_MSG_DATA_WAIT1 | reset_code, 1, 0);
  3724. if (rc)
  3725. return rc;
  3726. spin_lock_bh(&bp->phy_lock);
  3727. old_port = bp->phy_port;
  3728. bnx2_init_fw_cap(bp);
  3729. if ((bp->phy_flags & BNX2_PHY_FLAG_REMOTE_PHY_CAP) &&
  3730. old_port != bp->phy_port)
  3731. bnx2_set_default_remote_link(bp);
  3732. spin_unlock_bh(&bp->phy_lock);
  3733. if (CHIP_ID(bp) == CHIP_ID_5706_A0) {
  3734. /* Adjust the voltage regular to two steps lower. The default
  3735. * of this register is 0x0000000e. */
  3736. REG_WR(bp, BNX2_MISC_VREG_CONTROL, 0x000000fa);
  3737. /* Remove bad rbuf memory from the free pool. */
  3738. rc = bnx2_alloc_bad_rbuf(bp);
  3739. }
  3740. if (bp->flags & BNX2_FLAG_USING_MSIX)
  3741. bnx2_setup_msix_tbl(bp);
  3742. return rc;
  3743. }
  3744. static int
  3745. bnx2_init_chip(struct bnx2 *bp)
  3746. {
  3747. u32 val, mtu;
  3748. int rc, i;
  3749. /* Make sure the interrupt is not active. */
  3750. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD, BNX2_PCICFG_INT_ACK_CMD_MASK_INT);
  3751. val = BNX2_DMA_CONFIG_DATA_BYTE_SWAP |
  3752. BNX2_DMA_CONFIG_DATA_WORD_SWAP |
  3753. #ifdef __BIG_ENDIAN
  3754. BNX2_DMA_CONFIG_CNTL_BYTE_SWAP |
  3755. #endif
  3756. BNX2_DMA_CONFIG_CNTL_WORD_SWAP |
  3757. DMA_READ_CHANS << 12 |
  3758. DMA_WRITE_CHANS << 16;
  3759. val |= (0x2 << 20) | (1 << 11);
  3760. if ((bp->flags & BNX2_FLAG_PCIX) && (bp->bus_speed_mhz == 133))
  3761. val |= (1 << 23);
  3762. if ((CHIP_NUM(bp) == CHIP_NUM_5706) &&
  3763. (CHIP_ID(bp) != CHIP_ID_5706_A0) && !(bp->flags & BNX2_FLAG_PCIX))
  3764. val |= BNX2_DMA_CONFIG_CNTL_PING_PONG_DMA;
  3765. REG_WR(bp, BNX2_DMA_CONFIG, val);
  3766. if (CHIP_ID(bp) == CHIP_ID_5706_A0) {
  3767. val = REG_RD(bp, BNX2_TDMA_CONFIG);
  3768. val |= BNX2_TDMA_CONFIG_ONE_DMA;
  3769. REG_WR(bp, BNX2_TDMA_CONFIG, val);
  3770. }
  3771. if (bp->flags & BNX2_FLAG_PCIX) {
  3772. u16 val16;
  3773. pci_read_config_word(bp->pdev, bp->pcix_cap + PCI_X_CMD,
  3774. &val16);
  3775. pci_write_config_word(bp->pdev, bp->pcix_cap + PCI_X_CMD,
  3776. val16 & ~PCI_X_CMD_ERO);
  3777. }
  3778. REG_WR(bp, BNX2_MISC_ENABLE_SET_BITS,
  3779. BNX2_MISC_ENABLE_SET_BITS_HOST_COALESCE_ENABLE |
  3780. BNX2_MISC_ENABLE_STATUS_BITS_RX_V2P_ENABLE |
  3781. BNX2_MISC_ENABLE_STATUS_BITS_CONTEXT_ENABLE);
  3782. /* Initialize context mapping and zero out the quick contexts. The
  3783. * context block must have already been enabled. */
  3784. if (CHIP_NUM(bp) == CHIP_NUM_5709) {
  3785. rc = bnx2_init_5709_context(bp);
  3786. if (rc)
  3787. return rc;
  3788. } else
  3789. bnx2_init_context(bp);
  3790. if ((rc = bnx2_init_cpus(bp)) != 0)
  3791. return rc;
  3792. bnx2_init_nvram(bp);
  3793. bnx2_set_mac_addr(bp, bp->dev->dev_addr, 0);
  3794. val = REG_RD(bp, BNX2_MQ_CONFIG);
  3795. val &= ~BNX2_MQ_CONFIG_KNL_BYP_BLK_SIZE;
  3796. val |= BNX2_MQ_CONFIG_KNL_BYP_BLK_SIZE_256;
  3797. if (CHIP_ID(bp) == CHIP_ID_5709_A0 || CHIP_ID(bp) == CHIP_ID_5709_A1)
  3798. val |= BNX2_MQ_CONFIG_HALT_DIS;
  3799. REG_WR(bp, BNX2_MQ_CONFIG, val);
  3800. val = 0x10000 + (MAX_CID_CNT * MB_KERNEL_CTX_SIZE);
  3801. REG_WR(bp, BNX2_MQ_KNL_BYP_WIND_START, val);
  3802. REG_WR(bp, BNX2_MQ_KNL_WIND_END, val);
  3803. val = (BCM_PAGE_BITS - 8) << 24;
  3804. REG_WR(bp, BNX2_RV2P_CONFIG, val);
  3805. /* Configure page size. */
  3806. val = REG_RD(bp, BNX2_TBDR_CONFIG);
  3807. val &= ~BNX2_TBDR_CONFIG_PAGE_SIZE;
  3808. val |= (BCM_PAGE_BITS - 8) << 24 | 0x40;
  3809. REG_WR(bp, BNX2_TBDR_CONFIG, val);
  3810. val = bp->mac_addr[0] +
  3811. (bp->mac_addr[1] << 8) +
  3812. (bp->mac_addr[2] << 16) +
  3813. bp->mac_addr[3] +
  3814. (bp->mac_addr[4] << 8) +
  3815. (bp->mac_addr[5] << 16);
  3816. REG_WR(bp, BNX2_EMAC_BACKOFF_SEED, val);
  3817. /* Program the MTU. Also include 4 bytes for CRC32. */
  3818. mtu = bp->dev->mtu;
  3819. val = mtu + ETH_HLEN + ETH_FCS_LEN;
  3820. if (val > (MAX_ETHERNET_PACKET_SIZE + 4))
  3821. val |= BNX2_EMAC_RX_MTU_SIZE_JUMBO_ENA;
  3822. REG_WR(bp, BNX2_EMAC_RX_MTU_SIZE, val);
  3823. if (mtu < 1500)
  3824. mtu = 1500;
  3825. bnx2_reg_wr_ind(bp, BNX2_RBUF_CONFIG, BNX2_RBUF_CONFIG_VAL(mtu));
  3826. bnx2_reg_wr_ind(bp, BNX2_RBUF_CONFIG2, BNX2_RBUF_CONFIG2_VAL(mtu));
  3827. bnx2_reg_wr_ind(bp, BNX2_RBUF_CONFIG3, BNX2_RBUF_CONFIG3_VAL(mtu));
  3828. for (i = 0; i < BNX2_MAX_MSIX_VEC; i++)
  3829. bp->bnx2_napi[i].last_status_idx = 0;
  3830. bp->idle_chk_status_idx = 0xffff;
  3831. bp->rx_mode = BNX2_EMAC_RX_MODE_SORT_MODE;
  3832. /* Set up how to generate a link change interrupt. */
  3833. REG_WR(bp, BNX2_EMAC_ATTENTION_ENA, BNX2_EMAC_ATTENTION_ENA_LINK);
  3834. REG_WR(bp, BNX2_HC_STATUS_ADDR_L,
  3835. (u64) bp->status_blk_mapping & 0xffffffff);
  3836. REG_WR(bp, BNX2_HC_STATUS_ADDR_H, (u64) bp->status_blk_mapping >> 32);
  3837. REG_WR(bp, BNX2_HC_STATISTICS_ADDR_L,
  3838. (u64) bp->stats_blk_mapping & 0xffffffff);
  3839. REG_WR(bp, BNX2_HC_STATISTICS_ADDR_H,
  3840. (u64) bp->stats_blk_mapping >> 32);
  3841. REG_WR(bp, BNX2_HC_TX_QUICK_CONS_TRIP,
  3842. (bp->tx_quick_cons_trip_int << 16) | bp->tx_quick_cons_trip);
  3843. REG_WR(bp, BNX2_HC_RX_QUICK_CONS_TRIP,
  3844. (bp->rx_quick_cons_trip_int << 16) | bp->rx_quick_cons_trip);
  3845. REG_WR(bp, BNX2_HC_COMP_PROD_TRIP,
  3846. (bp->comp_prod_trip_int << 16) | bp->comp_prod_trip);
  3847. REG_WR(bp, BNX2_HC_TX_TICKS, (bp->tx_ticks_int << 16) | bp->tx_ticks);
  3848. REG_WR(bp, BNX2_HC_RX_TICKS, (bp->rx_ticks_int << 16) | bp->rx_ticks);
  3849. REG_WR(bp, BNX2_HC_COM_TICKS,
  3850. (bp->com_ticks_int << 16) | bp->com_ticks);
  3851. REG_WR(bp, BNX2_HC_CMD_TICKS,
  3852. (bp->cmd_ticks_int << 16) | bp->cmd_ticks);
  3853. if (CHIP_NUM(bp) == CHIP_NUM_5708)
  3854. REG_WR(bp, BNX2_HC_STATS_TICKS, 0);
  3855. else
  3856. REG_WR(bp, BNX2_HC_STATS_TICKS, bp->stats_ticks);
  3857. REG_WR(bp, BNX2_HC_STAT_COLLECT_TICKS, 0xbb8); /* 3ms */
  3858. if (CHIP_ID(bp) == CHIP_ID_5706_A1)
  3859. val = BNX2_HC_CONFIG_COLLECT_STATS;
  3860. else {
  3861. val = BNX2_HC_CONFIG_RX_TMR_MODE | BNX2_HC_CONFIG_TX_TMR_MODE |
  3862. BNX2_HC_CONFIG_COLLECT_STATS;
  3863. }
  3864. if (bp->irq_nvecs > 1) {
  3865. REG_WR(bp, BNX2_HC_MSIX_BIT_VECTOR,
  3866. BNX2_HC_MSIX_BIT_VECTOR_VAL);
  3867. val |= BNX2_HC_CONFIG_SB_ADDR_INC_128B;
  3868. }
  3869. if (bp->flags & BNX2_FLAG_ONE_SHOT_MSI)
  3870. val |= BNX2_HC_CONFIG_ONE_SHOT;
  3871. REG_WR(bp, BNX2_HC_CONFIG, val);
  3872. for (i = 1; i < bp->irq_nvecs; i++) {
  3873. u32 base = ((i - 1) * BNX2_HC_SB_CONFIG_SIZE) +
  3874. BNX2_HC_SB_CONFIG_1;
  3875. REG_WR(bp, base,
  3876. BNX2_HC_SB_CONFIG_1_TX_TMR_MODE |
  3877. BNX2_HC_SB_CONFIG_1_RX_TMR_MODE |
  3878. BNX2_HC_SB_CONFIG_1_ONE_SHOT);
  3879. REG_WR(bp, base + BNX2_HC_TX_QUICK_CONS_TRIP_OFF,
  3880. (bp->tx_quick_cons_trip_int << 16) |
  3881. bp->tx_quick_cons_trip);
  3882. REG_WR(bp, base + BNX2_HC_TX_TICKS_OFF,
  3883. (bp->tx_ticks_int << 16) | bp->tx_ticks);
  3884. REG_WR(bp, base + BNX2_HC_RX_QUICK_CONS_TRIP_OFF,
  3885. (bp->rx_quick_cons_trip_int << 16) |
  3886. bp->rx_quick_cons_trip);
  3887. REG_WR(bp, base + BNX2_HC_RX_TICKS_OFF,
  3888. (bp->rx_ticks_int << 16) | bp->rx_ticks);
  3889. }
  3890. /* Clear internal stats counters. */
  3891. REG_WR(bp, BNX2_HC_COMMAND, BNX2_HC_COMMAND_CLR_STAT_NOW);
  3892. REG_WR(bp, BNX2_HC_ATTN_BITS_ENABLE, STATUS_ATTN_EVENTS);
  3893. /* Initialize the receive filter. */
  3894. bnx2_set_rx_mode(bp->dev);
  3895. if (CHIP_NUM(bp) == CHIP_NUM_5709) {
  3896. val = REG_RD(bp, BNX2_MISC_NEW_CORE_CTL);
  3897. val |= BNX2_MISC_NEW_CORE_CTL_DMA_ENABLE;
  3898. REG_WR(bp, BNX2_MISC_NEW_CORE_CTL, val);
  3899. }
  3900. rc = bnx2_fw_sync(bp, BNX2_DRV_MSG_DATA_WAIT2 | BNX2_DRV_MSG_CODE_RESET,
  3901. 1, 0);
  3902. REG_WR(bp, BNX2_MISC_ENABLE_SET_BITS, BNX2_MISC_ENABLE_DEFAULT);
  3903. REG_RD(bp, BNX2_MISC_ENABLE_SET_BITS);
  3904. udelay(20);
  3905. bp->hc_cmd = REG_RD(bp, BNX2_HC_COMMAND);
  3906. return rc;
  3907. }
  3908. static void
  3909. bnx2_clear_ring_states(struct bnx2 *bp)
  3910. {
  3911. struct bnx2_napi *bnapi;
  3912. struct bnx2_tx_ring_info *txr;
  3913. struct bnx2_rx_ring_info *rxr;
  3914. int i;
  3915. for (i = 0; i < BNX2_MAX_MSIX_VEC; i++) {
  3916. bnapi = &bp->bnx2_napi[i];
  3917. txr = &bnapi->tx_ring;
  3918. rxr = &bnapi->rx_ring;
  3919. txr->tx_cons = 0;
  3920. txr->hw_tx_cons = 0;
  3921. rxr->rx_prod_bseq = 0;
  3922. rxr->rx_prod = 0;
  3923. rxr->rx_cons = 0;
  3924. rxr->rx_pg_prod = 0;
  3925. rxr->rx_pg_cons = 0;
  3926. }
  3927. }
  3928. static void
  3929. bnx2_init_tx_context(struct bnx2 *bp, u32 cid, struct bnx2_tx_ring_info *txr)
  3930. {
  3931. u32 val, offset0, offset1, offset2, offset3;
  3932. u32 cid_addr = GET_CID_ADDR(cid);
  3933. if (CHIP_NUM(bp) == CHIP_NUM_5709) {
  3934. offset0 = BNX2_L2CTX_TYPE_XI;
  3935. offset1 = BNX2_L2CTX_CMD_TYPE_XI;
  3936. offset2 = BNX2_L2CTX_TBDR_BHADDR_HI_XI;
  3937. offset3 = BNX2_L2CTX_TBDR_BHADDR_LO_XI;
  3938. } else {
  3939. offset0 = BNX2_L2CTX_TYPE;
  3940. offset1 = BNX2_L2CTX_CMD_TYPE;
  3941. offset2 = BNX2_L2CTX_TBDR_BHADDR_HI;
  3942. offset3 = BNX2_L2CTX_TBDR_BHADDR_LO;
  3943. }
  3944. val = BNX2_L2CTX_TYPE_TYPE_L2 | BNX2_L2CTX_TYPE_SIZE_L2;
  3945. bnx2_ctx_wr(bp, cid_addr, offset0, val);
  3946. val = BNX2_L2CTX_CMD_TYPE_TYPE_L2 | (8 << 16);
  3947. bnx2_ctx_wr(bp, cid_addr, offset1, val);
  3948. val = (u64) txr->tx_desc_mapping >> 32;
  3949. bnx2_ctx_wr(bp, cid_addr, offset2, val);
  3950. val = (u64) txr->tx_desc_mapping & 0xffffffff;
  3951. bnx2_ctx_wr(bp, cid_addr, offset3, val);
  3952. }
  3953. static void
  3954. bnx2_init_tx_ring(struct bnx2 *bp, int ring_num)
  3955. {
  3956. struct tx_bd *txbd;
  3957. u32 cid = TX_CID;
  3958. struct bnx2_napi *bnapi;
  3959. struct bnx2_tx_ring_info *txr;
  3960. bnapi = &bp->bnx2_napi[ring_num];
  3961. txr = &bnapi->tx_ring;
  3962. if (ring_num == 0)
  3963. cid = TX_CID;
  3964. else
  3965. cid = TX_TSS_CID + ring_num - 1;
  3966. bp->tx_wake_thresh = bp->tx_ring_size / 2;
  3967. txbd = &txr->tx_desc_ring[MAX_TX_DESC_CNT];
  3968. txbd->tx_bd_haddr_hi = (u64) txr->tx_desc_mapping >> 32;
  3969. txbd->tx_bd_haddr_lo = (u64) txr->tx_desc_mapping & 0xffffffff;
  3970. txr->tx_prod = 0;
  3971. txr->tx_prod_bseq = 0;
  3972. txr->tx_bidx_addr = MB_GET_CID_ADDR(cid) + BNX2_L2CTX_TX_HOST_BIDX;
  3973. txr->tx_bseq_addr = MB_GET_CID_ADDR(cid) + BNX2_L2CTX_TX_HOST_BSEQ;
  3974. bnx2_init_tx_context(bp, cid, txr);
  3975. }
  3976. static void
  3977. bnx2_init_rxbd_rings(struct rx_bd *rx_ring[], dma_addr_t dma[], u32 buf_size,
  3978. int num_rings)
  3979. {
  3980. int i;
  3981. struct rx_bd *rxbd;
  3982. for (i = 0; i < num_rings; i++) {
  3983. int j;
  3984. rxbd = &rx_ring[i][0];
  3985. for (j = 0; j < MAX_RX_DESC_CNT; j++, rxbd++) {
  3986. rxbd->rx_bd_len = buf_size;
  3987. rxbd->rx_bd_flags = RX_BD_FLAGS_START | RX_BD_FLAGS_END;
  3988. }
  3989. if (i == (num_rings - 1))
  3990. j = 0;
  3991. else
  3992. j = i + 1;
  3993. rxbd->rx_bd_haddr_hi = (u64) dma[j] >> 32;
  3994. rxbd->rx_bd_haddr_lo = (u64) dma[j] & 0xffffffff;
  3995. }
  3996. }
  3997. static void
  3998. bnx2_init_rx_ring(struct bnx2 *bp, int ring_num)
  3999. {
  4000. int i;
  4001. u16 prod, ring_prod;
  4002. u32 cid, rx_cid_addr, val;
  4003. struct bnx2_napi *bnapi = &bp->bnx2_napi[ring_num];
  4004. struct bnx2_rx_ring_info *rxr = &bnapi->rx_ring;
  4005. if (ring_num == 0)
  4006. cid = RX_CID;
  4007. else
  4008. cid = RX_RSS_CID + ring_num - 1;
  4009. rx_cid_addr = GET_CID_ADDR(cid);
  4010. bnx2_init_rxbd_rings(rxr->rx_desc_ring, rxr->rx_desc_mapping,
  4011. bp->rx_buf_use_size, bp->rx_max_ring);
  4012. bnx2_init_rx_context(bp, cid);
  4013. if (CHIP_NUM(bp) == CHIP_NUM_5709) {
  4014. val = REG_RD(bp, BNX2_MQ_MAP_L2_5);
  4015. REG_WR(bp, BNX2_MQ_MAP_L2_5, val | BNX2_MQ_MAP_L2_5_ARM);
  4016. }
  4017. bnx2_ctx_wr(bp, rx_cid_addr, BNX2_L2CTX_PG_BUF_SIZE, 0);
  4018. if (bp->rx_pg_ring_size) {
  4019. bnx2_init_rxbd_rings(rxr->rx_pg_desc_ring,
  4020. rxr->rx_pg_desc_mapping,
  4021. PAGE_SIZE, bp->rx_max_pg_ring);
  4022. val = (bp->rx_buf_use_size << 16) | PAGE_SIZE;
  4023. bnx2_ctx_wr(bp, rx_cid_addr, BNX2_L2CTX_PG_BUF_SIZE, val);
  4024. bnx2_ctx_wr(bp, rx_cid_addr, BNX2_L2CTX_RBDC_KEY,
  4025. BNX2_L2CTX_RBDC_JUMBO_KEY - ring_num);
  4026. val = (u64) rxr->rx_pg_desc_mapping[0] >> 32;
  4027. bnx2_ctx_wr(bp, rx_cid_addr, BNX2_L2CTX_NX_PG_BDHADDR_HI, val);
  4028. val = (u64) rxr->rx_pg_desc_mapping[0] & 0xffffffff;
  4029. bnx2_ctx_wr(bp, rx_cid_addr, BNX2_L2CTX_NX_PG_BDHADDR_LO, val);
  4030. if (CHIP_NUM(bp) == CHIP_NUM_5709)
  4031. REG_WR(bp, BNX2_MQ_MAP_L2_3, BNX2_MQ_MAP_L2_3_DEFAULT);
  4032. }
  4033. val = (u64) rxr->rx_desc_mapping[0] >> 32;
  4034. bnx2_ctx_wr(bp, rx_cid_addr, BNX2_L2CTX_NX_BDHADDR_HI, val);
  4035. val = (u64) rxr->rx_desc_mapping[0] & 0xffffffff;
  4036. bnx2_ctx_wr(bp, rx_cid_addr, BNX2_L2CTX_NX_BDHADDR_LO, val);
  4037. ring_prod = prod = rxr->rx_pg_prod;
  4038. for (i = 0; i < bp->rx_pg_ring_size; i++) {
  4039. if (bnx2_alloc_rx_page(bp, rxr, ring_prod) < 0)
  4040. break;
  4041. prod = NEXT_RX_BD(prod);
  4042. ring_prod = RX_PG_RING_IDX(prod);
  4043. }
  4044. rxr->rx_pg_prod = prod;
  4045. ring_prod = prod = rxr->rx_prod;
  4046. for (i = 0; i < bp->rx_ring_size; i++) {
  4047. if (bnx2_alloc_rx_skb(bp, rxr, ring_prod) < 0)
  4048. break;
  4049. prod = NEXT_RX_BD(prod);
  4050. ring_prod = RX_RING_IDX(prod);
  4051. }
  4052. rxr->rx_prod = prod;
  4053. rxr->rx_bidx_addr = MB_GET_CID_ADDR(cid) + BNX2_L2CTX_HOST_BDIDX;
  4054. rxr->rx_bseq_addr = MB_GET_CID_ADDR(cid) + BNX2_L2CTX_HOST_BSEQ;
  4055. rxr->rx_pg_bidx_addr = MB_GET_CID_ADDR(cid) + BNX2_L2CTX_HOST_PG_BDIDX;
  4056. REG_WR16(bp, rxr->rx_pg_bidx_addr, rxr->rx_pg_prod);
  4057. REG_WR16(bp, rxr->rx_bidx_addr, prod);
  4058. REG_WR(bp, rxr->rx_bseq_addr, rxr->rx_prod_bseq);
  4059. }
  4060. static void
  4061. bnx2_init_all_rings(struct bnx2 *bp)
  4062. {
  4063. int i;
  4064. u32 val;
  4065. bnx2_clear_ring_states(bp);
  4066. REG_WR(bp, BNX2_TSCH_TSS_CFG, 0);
  4067. for (i = 0; i < bp->num_tx_rings; i++)
  4068. bnx2_init_tx_ring(bp, i);
  4069. if (bp->num_tx_rings > 1)
  4070. REG_WR(bp, BNX2_TSCH_TSS_CFG, ((bp->num_tx_rings - 1) << 24) |
  4071. (TX_TSS_CID << 7));
  4072. REG_WR(bp, BNX2_RLUP_RSS_CONFIG, 0);
  4073. bnx2_reg_wr_ind(bp, BNX2_RXP_SCRATCH_RSS_TBL_SZ, 0);
  4074. for (i = 0; i < bp->num_rx_rings; i++)
  4075. bnx2_init_rx_ring(bp, i);
  4076. if (bp->num_rx_rings > 1) {
  4077. u32 tbl_32;
  4078. u8 *tbl = (u8 *) &tbl_32;
  4079. bnx2_reg_wr_ind(bp, BNX2_RXP_SCRATCH_RSS_TBL_SZ,
  4080. BNX2_RXP_SCRATCH_RSS_TBL_MAX_ENTRIES);
  4081. for (i = 0; i < BNX2_RXP_SCRATCH_RSS_TBL_MAX_ENTRIES; i++) {
  4082. tbl[i % 4] = i % (bp->num_rx_rings - 1);
  4083. if ((i % 4) == 3)
  4084. bnx2_reg_wr_ind(bp,
  4085. BNX2_RXP_SCRATCH_RSS_TBL + i,
  4086. cpu_to_be32(tbl_32));
  4087. }
  4088. val = BNX2_RLUP_RSS_CONFIG_IPV4_RSS_TYPE_ALL_XI |
  4089. BNX2_RLUP_RSS_CONFIG_IPV6_RSS_TYPE_ALL_XI;
  4090. REG_WR(bp, BNX2_RLUP_RSS_CONFIG, val);
  4091. }
  4092. }
  4093. static u32 bnx2_find_max_ring(u32 ring_size, u32 max_size)
  4094. {
  4095. u32 max, num_rings = 1;
  4096. while (ring_size > MAX_RX_DESC_CNT) {
  4097. ring_size -= MAX_RX_DESC_CNT;
  4098. num_rings++;
  4099. }
  4100. /* round to next power of 2 */
  4101. max = max_size;
  4102. while ((max & num_rings) == 0)
  4103. max >>= 1;
  4104. if (num_rings != max)
  4105. max <<= 1;
  4106. return max;
  4107. }
  4108. static void
  4109. bnx2_set_rx_ring_size(struct bnx2 *bp, u32 size)
  4110. {
  4111. u32 rx_size, rx_space, jumbo_size;
  4112. /* 8 for CRC and VLAN */
  4113. rx_size = bp->dev->mtu + ETH_HLEN + BNX2_RX_OFFSET + 8;
  4114. rx_space = SKB_DATA_ALIGN(rx_size + BNX2_RX_ALIGN) + NET_SKB_PAD +
  4115. sizeof(struct skb_shared_info);
  4116. bp->rx_copy_thresh = BNX2_RX_COPY_THRESH;
  4117. bp->rx_pg_ring_size = 0;
  4118. bp->rx_max_pg_ring = 0;
  4119. bp->rx_max_pg_ring_idx = 0;
  4120. if ((rx_space > PAGE_SIZE) && !(bp->flags & BNX2_FLAG_JUMBO_BROKEN)) {
  4121. int pages = PAGE_ALIGN(bp->dev->mtu - 40) >> PAGE_SHIFT;
  4122. jumbo_size = size * pages;
  4123. if (jumbo_size > MAX_TOTAL_RX_PG_DESC_CNT)
  4124. jumbo_size = MAX_TOTAL_RX_PG_DESC_CNT;
  4125. bp->rx_pg_ring_size = jumbo_size;
  4126. bp->rx_max_pg_ring = bnx2_find_max_ring(jumbo_size,
  4127. MAX_RX_PG_RINGS);
  4128. bp->rx_max_pg_ring_idx = (bp->rx_max_pg_ring * RX_DESC_CNT) - 1;
  4129. rx_size = BNX2_RX_COPY_THRESH + BNX2_RX_OFFSET;
  4130. bp->rx_copy_thresh = 0;
  4131. }
  4132. bp->rx_buf_use_size = rx_size;
  4133. /* hw alignment */
  4134. bp->rx_buf_size = bp->rx_buf_use_size + BNX2_RX_ALIGN;
  4135. bp->rx_jumbo_thresh = rx_size - BNX2_RX_OFFSET;
  4136. bp->rx_ring_size = size;
  4137. bp->rx_max_ring = bnx2_find_max_ring(size, MAX_RX_RINGS);
  4138. bp->rx_max_ring_idx = (bp->rx_max_ring * RX_DESC_CNT) - 1;
  4139. }
  4140. static void
  4141. bnx2_free_tx_skbs(struct bnx2 *bp)
  4142. {
  4143. int i;
  4144. for (i = 0; i < bp->num_tx_rings; i++) {
  4145. struct bnx2_napi *bnapi = &bp->bnx2_napi[i];
  4146. struct bnx2_tx_ring_info *txr = &bnapi->tx_ring;
  4147. int j;
  4148. if (txr->tx_buf_ring == NULL)
  4149. continue;
  4150. for (j = 0; j < TX_DESC_CNT; ) {
  4151. struct sw_tx_bd *tx_buf = &txr->tx_buf_ring[j];
  4152. struct sk_buff *skb = tx_buf->skb;
  4153. if (skb == NULL) {
  4154. j++;
  4155. continue;
  4156. }
  4157. skb_dma_unmap(&bp->pdev->dev, skb, DMA_TO_DEVICE);
  4158. tx_buf->skb = NULL;
  4159. j += skb_shinfo(skb)->nr_frags + 1;
  4160. dev_kfree_skb(skb);
  4161. }
  4162. }
  4163. }
  4164. static void
  4165. bnx2_free_rx_skbs(struct bnx2 *bp)
  4166. {
  4167. int i;
  4168. for (i = 0; i < bp->num_rx_rings; i++) {
  4169. struct bnx2_napi *bnapi = &bp->bnx2_napi[i];
  4170. struct bnx2_rx_ring_info *rxr = &bnapi->rx_ring;
  4171. int j;
  4172. if (rxr->rx_buf_ring == NULL)
  4173. return;
  4174. for (j = 0; j < bp->rx_max_ring_idx; j++) {
  4175. struct sw_bd *rx_buf = &rxr->rx_buf_ring[j];
  4176. struct sk_buff *skb = rx_buf->skb;
  4177. if (skb == NULL)
  4178. continue;
  4179. pci_unmap_single(bp->pdev,
  4180. pci_unmap_addr(rx_buf, mapping),
  4181. bp->rx_buf_use_size,
  4182. PCI_DMA_FROMDEVICE);
  4183. rx_buf->skb = NULL;
  4184. dev_kfree_skb(skb);
  4185. }
  4186. for (j = 0; j < bp->rx_max_pg_ring_idx; j++)
  4187. bnx2_free_rx_page(bp, rxr, j);
  4188. }
  4189. }
  4190. static void
  4191. bnx2_free_skbs(struct bnx2 *bp)
  4192. {
  4193. bnx2_free_tx_skbs(bp);
  4194. bnx2_free_rx_skbs(bp);
  4195. }
  4196. static int
  4197. bnx2_reset_nic(struct bnx2 *bp, u32 reset_code)
  4198. {
  4199. int rc;
  4200. rc = bnx2_reset_chip(bp, reset_code);
  4201. bnx2_free_skbs(bp);
  4202. if (rc)
  4203. return rc;
  4204. if ((rc = bnx2_init_chip(bp)) != 0)
  4205. return rc;
  4206. bnx2_init_all_rings(bp);
  4207. return 0;
  4208. }
  4209. static int
  4210. bnx2_init_nic(struct bnx2 *bp, int reset_phy)
  4211. {
  4212. int rc;
  4213. if ((rc = bnx2_reset_nic(bp, BNX2_DRV_MSG_CODE_RESET)) != 0)
  4214. return rc;
  4215. spin_lock_bh(&bp->phy_lock);
  4216. bnx2_init_phy(bp, reset_phy);
  4217. bnx2_set_link(bp);
  4218. if (bp->phy_flags & BNX2_PHY_FLAG_REMOTE_PHY_CAP)
  4219. bnx2_remote_phy_event(bp);
  4220. spin_unlock_bh(&bp->phy_lock);
  4221. return 0;
  4222. }
  4223. static int
  4224. bnx2_shutdown_chip(struct bnx2 *bp)
  4225. {
  4226. u32 reset_code;
  4227. if (bp->flags & BNX2_FLAG_NO_WOL)
  4228. reset_code = BNX2_DRV_MSG_CODE_UNLOAD_LNK_DN;
  4229. else if (bp->wol)
  4230. reset_code = BNX2_DRV_MSG_CODE_SUSPEND_WOL;
  4231. else
  4232. reset_code = BNX2_DRV_MSG_CODE_SUSPEND_NO_WOL;
  4233. return bnx2_reset_chip(bp, reset_code);
  4234. }
  4235. static int
  4236. bnx2_test_registers(struct bnx2 *bp)
  4237. {
  4238. int ret;
  4239. int i, is_5709;
  4240. static const struct {
  4241. u16 offset;
  4242. u16 flags;
  4243. #define BNX2_FL_NOT_5709 1
  4244. u32 rw_mask;
  4245. u32 ro_mask;
  4246. } reg_tbl[] = {
  4247. { 0x006c, 0, 0x00000000, 0x0000003f },
  4248. { 0x0090, 0, 0xffffffff, 0x00000000 },
  4249. { 0x0094, 0, 0x00000000, 0x00000000 },
  4250. { 0x0404, BNX2_FL_NOT_5709, 0x00003f00, 0x00000000 },
  4251. { 0x0418, BNX2_FL_NOT_5709, 0x00000000, 0xffffffff },
  4252. { 0x041c, BNX2_FL_NOT_5709, 0x00000000, 0xffffffff },
  4253. { 0x0420, BNX2_FL_NOT_5709, 0x00000000, 0x80ffffff },
  4254. { 0x0424, BNX2_FL_NOT_5709, 0x00000000, 0x00000000 },
  4255. { 0x0428, BNX2_FL_NOT_5709, 0x00000000, 0x00000001 },
  4256. { 0x0450, BNX2_FL_NOT_5709, 0x00000000, 0x0000ffff },
  4257. { 0x0454, BNX2_FL_NOT_5709, 0x00000000, 0xffffffff },
  4258. { 0x0458, BNX2_FL_NOT_5709, 0x00000000, 0xffffffff },
  4259. { 0x0808, BNX2_FL_NOT_5709, 0x00000000, 0xffffffff },
  4260. { 0x0854, BNX2_FL_NOT_5709, 0x00000000, 0xffffffff },
  4261. { 0x0868, BNX2_FL_NOT_5709, 0x00000000, 0x77777777 },
  4262. { 0x086c, BNX2_FL_NOT_5709, 0x00000000, 0x77777777 },
  4263. { 0x0870, BNX2_FL_NOT_5709, 0x00000000, 0x77777777 },
  4264. { 0x0874, BNX2_FL_NOT_5709, 0x00000000, 0x77777777 },
  4265. { 0x0c00, BNX2_FL_NOT_5709, 0x00000000, 0x00000001 },
  4266. { 0x0c04, BNX2_FL_NOT_5709, 0x00000000, 0x03ff0001 },
  4267. { 0x0c08, BNX2_FL_NOT_5709, 0x0f0ff073, 0x00000000 },
  4268. { 0x1000, 0, 0x00000000, 0x00000001 },
  4269. { 0x1004, BNX2_FL_NOT_5709, 0x00000000, 0x000f0001 },
  4270. { 0x1408, 0, 0x01c00800, 0x00000000 },
  4271. { 0x149c, 0, 0x8000ffff, 0x00000000 },
  4272. { 0x14a8, 0, 0x00000000, 0x000001ff },
  4273. { 0x14ac, 0, 0x0fffffff, 0x10000000 },
  4274. { 0x14b0, 0, 0x00000002, 0x00000001 },
  4275. { 0x14b8, 0, 0x00000000, 0x00000000 },
  4276. { 0x14c0, 0, 0x00000000, 0x00000009 },
  4277. { 0x14c4, 0, 0x00003fff, 0x00000000 },
  4278. { 0x14cc, 0, 0x00000000, 0x00000001 },
  4279. { 0x14d0, 0, 0xffffffff, 0x00000000 },
  4280. { 0x1800, 0, 0x00000000, 0x00000001 },
  4281. { 0x1804, 0, 0x00000000, 0x00000003 },
  4282. { 0x2800, 0, 0x00000000, 0x00000001 },
  4283. { 0x2804, 0, 0x00000000, 0x00003f01 },
  4284. { 0x2808, 0, 0x0f3f3f03, 0x00000000 },
  4285. { 0x2810, 0, 0xffff0000, 0x00000000 },
  4286. { 0x2814, 0, 0xffff0000, 0x00000000 },
  4287. { 0x2818, 0, 0xffff0000, 0x00000000 },
  4288. { 0x281c, 0, 0xffff0000, 0x00000000 },
  4289. { 0x2834, 0, 0xffffffff, 0x00000000 },
  4290. { 0x2840, 0, 0x00000000, 0xffffffff },
  4291. { 0x2844, 0, 0x00000000, 0xffffffff },
  4292. { 0x2848, 0, 0xffffffff, 0x00000000 },
  4293. { 0x284c, 0, 0xf800f800, 0x07ff07ff },
  4294. { 0x2c00, 0, 0x00000000, 0x00000011 },
  4295. { 0x2c04, 0, 0x00000000, 0x00030007 },
  4296. { 0x3c00, 0, 0x00000000, 0x00000001 },
  4297. { 0x3c04, 0, 0x00000000, 0x00070000 },
  4298. { 0x3c08, 0, 0x00007f71, 0x07f00000 },
  4299. { 0x3c0c, 0, 0x1f3ffffc, 0x00000000 },
  4300. { 0x3c10, 0, 0xffffffff, 0x00000000 },
  4301. { 0x3c14, 0, 0x00000000, 0xffffffff },
  4302. { 0x3c18, 0, 0x00000000, 0xffffffff },
  4303. { 0x3c1c, 0, 0xfffff000, 0x00000000 },
  4304. { 0x3c20, 0, 0xffffff00, 0x00000000 },
  4305. { 0x5004, 0, 0x00000000, 0x0000007f },
  4306. { 0x5008, 0, 0x0f0007ff, 0x00000000 },
  4307. { 0x5c00, 0, 0x00000000, 0x00000001 },
  4308. { 0x5c04, 0, 0x00000000, 0x0003000f },
  4309. { 0x5c08, 0, 0x00000003, 0x00000000 },
  4310. { 0x5c0c, 0, 0x0000fff8, 0x00000000 },
  4311. { 0x5c10, 0, 0x00000000, 0xffffffff },
  4312. { 0x5c80, 0, 0x00000000, 0x0f7113f1 },
  4313. { 0x5c84, 0, 0x00000000, 0x0000f333 },
  4314. { 0x5c88, 0, 0x00000000, 0x00077373 },
  4315. { 0x5c8c, 0, 0x00000000, 0x0007f737 },
  4316. { 0x6808, 0, 0x0000ff7f, 0x00000000 },
  4317. { 0x680c, 0, 0xffffffff, 0x00000000 },
  4318. { 0x6810, 0, 0xffffffff, 0x00000000 },
  4319. { 0x6814, 0, 0xffffffff, 0x00000000 },
  4320. { 0x6818, 0, 0xffffffff, 0x00000000 },
  4321. { 0x681c, 0, 0xffffffff, 0x00000000 },
  4322. { 0x6820, 0, 0x00ff00ff, 0x00000000 },
  4323. { 0x6824, 0, 0x00ff00ff, 0x00000000 },
  4324. { 0x6828, 0, 0x00ff00ff, 0x00000000 },
  4325. { 0x682c, 0, 0x03ff03ff, 0x00000000 },
  4326. { 0x6830, 0, 0x03ff03ff, 0x00000000 },
  4327. { 0x6834, 0, 0x03ff03ff, 0x00000000 },
  4328. { 0x6838, 0, 0x03ff03ff, 0x00000000 },
  4329. { 0x683c, 0, 0x0000ffff, 0x00000000 },
  4330. { 0x6840, 0, 0x00000ff0, 0x00000000 },
  4331. { 0x6844, 0, 0x00ffff00, 0x00000000 },
  4332. { 0x684c, 0, 0xffffffff, 0x00000000 },
  4333. { 0x6850, 0, 0x7f7f7f7f, 0x00000000 },
  4334. { 0x6854, 0, 0x7f7f7f7f, 0x00000000 },
  4335. { 0x6858, 0, 0x7f7f7f7f, 0x00000000 },
  4336. { 0x685c, 0, 0x7f7f7f7f, 0x00000000 },
  4337. { 0x6908, 0, 0x00000000, 0x0001ff0f },
  4338. { 0x690c, 0, 0x00000000, 0x0ffe00f0 },
  4339. { 0xffff, 0, 0x00000000, 0x00000000 },
  4340. };
  4341. ret = 0;
  4342. is_5709 = 0;
  4343. if (CHIP_NUM(bp) == CHIP_NUM_5709)
  4344. is_5709 = 1;
  4345. for (i = 0; reg_tbl[i].offset != 0xffff; i++) {
  4346. u32 offset, rw_mask, ro_mask, save_val, val;
  4347. u16 flags = reg_tbl[i].flags;
  4348. if (is_5709 && (flags & BNX2_FL_NOT_5709))
  4349. continue;
  4350. offset = (u32) reg_tbl[i].offset;
  4351. rw_mask = reg_tbl[i].rw_mask;
  4352. ro_mask = reg_tbl[i].ro_mask;
  4353. save_val = readl(bp->regview + offset);
  4354. writel(0, bp->regview + offset);
  4355. val = readl(bp->regview + offset);
  4356. if ((val & rw_mask) != 0) {
  4357. goto reg_test_err;
  4358. }
  4359. if ((val & ro_mask) != (save_val & ro_mask)) {
  4360. goto reg_test_err;
  4361. }
  4362. writel(0xffffffff, bp->regview + offset);
  4363. val = readl(bp->regview + offset);
  4364. if ((val & rw_mask) != rw_mask) {
  4365. goto reg_test_err;
  4366. }
  4367. if ((val & ro_mask) != (save_val & ro_mask)) {
  4368. goto reg_test_err;
  4369. }
  4370. writel(save_val, bp->regview + offset);
  4371. continue;
  4372. reg_test_err:
  4373. writel(save_val, bp->regview + offset);
  4374. ret = -ENODEV;
  4375. break;
  4376. }
  4377. return ret;
  4378. }
  4379. static int
  4380. bnx2_do_mem_test(struct bnx2 *bp, u32 start, u32 size)
  4381. {
  4382. static const u32 test_pattern[] = { 0x00000000, 0xffffffff, 0x55555555,
  4383. 0xaaaaaaaa , 0xaa55aa55, 0x55aa55aa };
  4384. int i;
  4385. for (i = 0; i < sizeof(test_pattern) / 4; i++) {
  4386. u32 offset;
  4387. for (offset = 0; offset < size; offset += 4) {
  4388. bnx2_reg_wr_ind(bp, start + offset, test_pattern[i]);
  4389. if (bnx2_reg_rd_ind(bp, start + offset) !=
  4390. test_pattern[i]) {
  4391. return -ENODEV;
  4392. }
  4393. }
  4394. }
  4395. return 0;
  4396. }
  4397. static int
  4398. bnx2_test_memory(struct bnx2 *bp)
  4399. {
  4400. int ret = 0;
  4401. int i;
  4402. static struct mem_entry {
  4403. u32 offset;
  4404. u32 len;
  4405. } mem_tbl_5706[] = {
  4406. { 0x60000, 0x4000 },
  4407. { 0xa0000, 0x3000 },
  4408. { 0xe0000, 0x4000 },
  4409. { 0x120000, 0x4000 },
  4410. { 0x1a0000, 0x4000 },
  4411. { 0x160000, 0x4000 },
  4412. { 0xffffffff, 0 },
  4413. },
  4414. mem_tbl_5709[] = {
  4415. { 0x60000, 0x4000 },
  4416. { 0xa0000, 0x3000 },
  4417. { 0xe0000, 0x4000 },
  4418. { 0x120000, 0x4000 },
  4419. { 0x1a0000, 0x4000 },
  4420. { 0xffffffff, 0 },
  4421. };
  4422. struct mem_entry *mem_tbl;
  4423. if (CHIP_NUM(bp) == CHIP_NUM_5709)
  4424. mem_tbl = mem_tbl_5709;
  4425. else
  4426. mem_tbl = mem_tbl_5706;
  4427. for (i = 0; mem_tbl[i].offset != 0xffffffff; i++) {
  4428. if ((ret = bnx2_do_mem_test(bp, mem_tbl[i].offset,
  4429. mem_tbl[i].len)) != 0) {
  4430. return ret;
  4431. }
  4432. }
  4433. return ret;
  4434. }
  4435. #define BNX2_MAC_LOOPBACK 0
  4436. #define BNX2_PHY_LOOPBACK 1
  4437. static int
  4438. bnx2_run_loopback(struct bnx2 *bp, int loopback_mode)
  4439. {
  4440. unsigned int pkt_size, num_pkts, i;
  4441. struct sk_buff *skb, *rx_skb;
  4442. unsigned char *packet;
  4443. u16 rx_start_idx, rx_idx;
  4444. dma_addr_t map;
  4445. struct tx_bd *txbd;
  4446. struct sw_bd *rx_buf;
  4447. struct l2_fhdr *rx_hdr;
  4448. int ret = -ENODEV;
  4449. struct bnx2_napi *bnapi = &bp->bnx2_napi[0], *tx_napi;
  4450. struct bnx2_tx_ring_info *txr = &bnapi->tx_ring;
  4451. struct bnx2_rx_ring_info *rxr = &bnapi->rx_ring;
  4452. tx_napi = bnapi;
  4453. txr = &tx_napi->tx_ring;
  4454. rxr = &bnapi->rx_ring;
  4455. if (loopback_mode == BNX2_MAC_LOOPBACK) {
  4456. bp->loopback = MAC_LOOPBACK;
  4457. bnx2_set_mac_loopback(bp);
  4458. }
  4459. else if (loopback_mode == BNX2_PHY_LOOPBACK) {
  4460. if (bp->phy_flags & BNX2_PHY_FLAG_REMOTE_PHY_CAP)
  4461. return 0;
  4462. bp->loopback = PHY_LOOPBACK;
  4463. bnx2_set_phy_loopback(bp);
  4464. }
  4465. else
  4466. return -EINVAL;
  4467. pkt_size = min(bp->dev->mtu + ETH_HLEN, bp->rx_jumbo_thresh - 4);
  4468. skb = netdev_alloc_skb(bp->dev, pkt_size);
  4469. if (!skb)
  4470. return -ENOMEM;
  4471. packet = skb_put(skb, pkt_size);
  4472. memcpy(packet, bp->dev->dev_addr, 6);
  4473. memset(packet + 6, 0x0, 8);
  4474. for (i = 14; i < pkt_size; i++)
  4475. packet[i] = (unsigned char) (i & 0xff);
  4476. if (skb_dma_map(&bp->pdev->dev, skb, DMA_TO_DEVICE)) {
  4477. dev_kfree_skb(skb);
  4478. return -EIO;
  4479. }
  4480. map = skb_shinfo(skb)->dma_maps[0];
  4481. REG_WR(bp, BNX2_HC_COMMAND,
  4482. bp->hc_cmd | BNX2_HC_COMMAND_COAL_NOW_WO_INT);
  4483. REG_RD(bp, BNX2_HC_COMMAND);
  4484. udelay(5);
  4485. rx_start_idx = bnx2_get_hw_rx_cons(bnapi);
  4486. num_pkts = 0;
  4487. txbd = &txr->tx_desc_ring[TX_RING_IDX(txr->tx_prod)];
  4488. txbd->tx_bd_haddr_hi = (u64) map >> 32;
  4489. txbd->tx_bd_haddr_lo = (u64) map & 0xffffffff;
  4490. txbd->tx_bd_mss_nbytes = pkt_size;
  4491. txbd->tx_bd_vlan_tag_flags = TX_BD_FLAGS_START | TX_BD_FLAGS_END;
  4492. num_pkts++;
  4493. txr->tx_prod = NEXT_TX_BD(txr->tx_prod);
  4494. txr->tx_prod_bseq += pkt_size;
  4495. REG_WR16(bp, txr->tx_bidx_addr, txr->tx_prod);
  4496. REG_WR(bp, txr->tx_bseq_addr, txr->tx_prod_bseq);
  4497. udelay(100);
  4498. REG_WR(bp, BNX2_HC_COMMAND,
  4499. bp->hc_cmd | BNX2_HC_COMMAND_COAL_NOW_WO_INT);
  4500. REG_RD(bp, BNX2_HC_COMMAND);
  4501. udelay(5);
  4502. skb_dma_unmap(&bp->pdev->dev, skb, DMA_TO_DEVICE);
  4503. dev_kfree_skb(skb);
  4504. if (bnx2_get_hw_tx_cons(tx_napi) != txr->tx_prod)
  4505. goto loopback_test_done;
  4506. rx_idx = bnx2_get_hw_rx_cons(bnapi);
  4507. if (rx_idx != rx_start_idx + num_pkts) {
  4508. goto loopback_test_done;
  4509. }
  4510. rx_buf = &rxr->rx_buf_ring[rx_start_idx];
  4511. rx_skb = rx_buf->skb;
  4512. rx_hdr = (struct l2_fhdr *) rx_skb->data;
  4513. skb_reserve(rx_skb, BNX2_RX_OFFSET);
  4514. pci_dma_sync_single_for_cpu(bp->pdev,
  4515. pci_unmap_addr(rx_buf, mapping),
  4516. bp->rx_buf_size, PCI_DMA_FROMDEVICE);
  4517. if (rx_hdr->l2_fhdr_status &
  4518. (L2_FHDR_ERRORS_BAD_CRC |
  4519. L2_FHDR_ERRORS_PHY_DECODE |
  4520. L2_FHDR_ERRORS_ALIGNMENT |
  4521. L2_FHDR_ERRORS_TOO_SHORT |
  4522. L2_FHDR_ERRORS_GIANT_FRAME)) {
  4523. goto loopback_test_done;
  4524. }
  4525. if ((rx_hdr->l2_fhdr_pkt_len - 4) != pkt_size) {
  4526. goto loopback_test_done;
  4527. }
  4528. for (i = 14; i < pkt_size; i++) {
  4529. if (*(rx_skb->data + i) != (unsigned char) (i & 0xff)) {
  4530. goto loopback_test_done;
  4531. }
  4532. }
  4533. ret = 0;
  4534. loopback_test_done:
  4535. bp->loopback = 0;
  4536. return ret;
  4537. }
  4538. #define BNX2_MAC_LOOPBACK_FAILED 1
  4539. #define BNX2_PHY_LOOPBACK_FAILED 2
  4540. #define BNX2_LOOPBACK_FAILED (BNX2_MAC_LOOPBACK_FAILED | \
  4541. BNX2_PHY_LOOPBACK_FAILED)
  4542. static int
  4543. bnx2_test_loopback(struct bnx2 *bp)
  4544. {
  4545. int rc = 0;
  4546. if (!netif_running(bp->dev))
  4547. return BNX2_LOOPBACK_FAILED;
  4548. bnx2_reset_nic(bp, BNX2_DRV_MSG_CODE_RESET);
  4549. spin_lock_bh(&bp->phy_lock);
  4550. bnx2_init_phy(bp, 1);
  4551. spin_unlock_bh(&bp->phy_lock);
  4552. if (bnx2_run_loopback(bp, BNX2_MAC_LOOPBACK))
  4553. rc |= BNX2_MAC_LOOPBACK_FAILED;
  4554. if (bnx2_run_loopback(bp, BNX2_PHY_LOOPBACK))
  4555. rc |= BNX2_PHY_LOOPBACK_FAILED;
  4556. return rc;
  4557. }
  4558. #define NVRAM_SIZE 0x200
  4559. #define CRC32_RESIDUAL 0xdebb20e3
  4560. static int
  4561. bnx2_test_nvram(struct bnx2 *bp)
  4562. {
  4563. __be32 buf[NVRAM_SIZE / 4];
  4564. u8 *data = (u8 *) buf;
  4565. int rc = 0;
  4566. u32 magic, csum;
  4567. if ((rc = bnx2_nvram_read(bp, 0, data, 4)) != 0)
  4568. goto test_nvram_done;
  4569. magic = be32_to_cpu(buf[0]);
  4570. if (magic != 0x669955aa) {
  4571. rc = -ENODEV;
  4572. goto test_nvram_done;
  4573. }
  4574. if ((rc = bnx2_nvram_read(bp, 0x100, data, NVRAM_SIZE)) != 0)
  4575. goto test_nvram_done;
  4576. csum = ether_crc_le(0x100, data);
  4577. if (csum != CRC32_RESIDUAL) {
  4578. rc = -ENODEV;
  4579. goto test_nvram_done;
  4580. }
  4581. csum = ether_crc_le(0x100, data + 0x100);
  4582. if (csum != CRC32_RESIDUAL) {
  4583. rc = -ENODEV;
  4584. }
  4585. test_nvram_done:
  4586. return rc;
  4587. }
  4588. static int
  4589. bnx2_test_link(struct bnx2 *bp)
  4590. {
  4591. u32 bmsr;
  4592. if (!netif_running(bp->dev))
  4593. return -ENODEV;
  4594. if (bp->phy_flags & BNX2_PHY_FLAG_REMOTE_PHY_CAP) {
  4595. if (bp->link_up)
  4596. return 0;
  4597. return -ENODEV;
  4598. }
  4599. spin_lock_bh(&bp->phy_lock);
  4600. bnx2_enable_bmsr1(bp);
  4601. bnx2_read_phy(bp, bp->mii_bmsr1, &bmsr);
  4602. bnx2_read_phy(bp, bp->mii_bmsr1, &bmsr);
  4603. bnx2_disable_bmsr1(bp);
  4604. spin_unlock_bh(&bp->phy_lock);
  4605. if (bmsr & BMSR_LSTATUS) {
  4606. return 0;
  4607. }
  4608. return -ENODEV;
  4609. }
  4610. static int
  4611. bnx2_test_intr(struct bnx2 *bp)
  4612. {
  4613. int i;
  4614. u16 status_idx;
  4615. if (!netif_running(bp->dev))
  4616. return -ENODEV;
  4617. status_idx = REG_RD(bp, BNX2_PCICFG_INT_ACK_CMD) & 0xffff;
  4618. /* This register is not touched during run-time. */
  4619. REG_WR(bp, BNX2_HC_COMMAND, bp->hc_cmd | BNX2_HC_COMMAND_COAL_NOW);
  4620. REG_RD(bp, BNX2_HC_COMMAND);
  4621. for (i = 0; i < 10; i++) {
  4622. if ((REG_RD(bp, BNX2_PCICFG_INT_ACK_CMD) & 0xffff) !=
  4623. status_idx) {
  4624. break;
  4625. }
  4626. msleep_interruptible(10);
  4627. }
  4628. if (i < 10)
  4629. return 0;
  4630. return -ENODEV;
  4631. }
  4632. /* Determining link for parallel detection. */
  4633. static int
  4634. bnx2_5706_serdes_has_link(struct bnx2 *bp)
  4635. {
  4636. u32 mode_ctl, an_dbg, exp;
  4637. if (bp->phy_flags & BNX2_PHY_FLAG_NO_PARALLEL)
  4638. return 0;
  4639. bnx2_write_phy(bp, MII_BNX2_MISC_SHADOW, MISC_SHDW_MODE_CTL);
  4640. bnx2_read_phy(bp, MII_BNX2_MISC_SHADOW, &mode_ctl);
  4641. if (!(mode_ctl & MISC_SHDW_MODE_CTL_SIG_DET))
  4642. return 0;
  4643. bnx2_write_phy(bp, MII_BNX2_MISC_SHADOW, MISC_SHDW_AN_DBG);
  4644. bnx2_read_phy(bp, MII_BNX2_MISC_SHADOW, &an_dbg);
  4645. bnx2_read_phy(bp, MII_BNX2_MISC_SHADOW, &an_dbg);
  4646. if (an_dbg & (MISC_SHDW_AN_DBG_NOSYNC | MISC_SHDW_AN_DBG_RUDI_INVALID))
  4647. return 0;
  4648. bnx2_write_phy(bp, MII_BNX2_DSP_ADDRESS, MII_EXPAND_REG1);
  4649. bnx2_read_phy(bp, MII_BNX2_DSP_RW_PORT, &exp);
  4650. bnx2_read_phy(bp, MII_BNX2_DSP_RW_PORT, &exp);
  4651. if (exp & MII_EXPAND_REG1_RUDI_C) /* receiving CONFIG */
  4652. return 0;
  4653. return 1;
  4654. }
  4655. static void
  4656. bnx2_5706_serdes_timer(struct bnx2 *bp)
  4657. {
  4658. int check_link = 1;
  4659. spin_lock(&bp->phy_lock);
  4660. if (bp->serdes_an_pending) {
  4661. bp->serdes_an_pending--;
  4662. check_link = 0;
  4663. } else if ((bp->link_up == 0) && (bp->autoneg & AUTONEG_SPEED)) {
  4664. u32 bmcr;
  4665. bp->current_interval = BNX2_TIMER_INTERVAL;
  4666. bnx2_read_phy(bp, bp->mii_bmcr, &bmcr);
  4667. if (bmcr & BMCR_ANENABLE) {
  4668. if (bnx2_5706_serdes_has_link(bp)) {
  4669. bmcr &= ~BMCR_ANENABLE;
  4670. bmcr |= BMCR_SPEED1000 | BMCR_FULLDPLX;
  4671. bnx2_write_phy(bp, bp->mii_bmcr, bmcr);
  4672. bp->phy_flags |= BNX2_PHY_FLAG_PARALLEL_DETECT;
  4673. }
  4674. }
  4675. }
  4676. else if ((bp->link_up) && (bp->autoneg & AUTONEG_SPEED) &&
  4677. (bp->phy_flags & BNX2_PHY_FLAG_PARALLEL_DETECT)) {
  4678. u32 phy2;
  4679. bnx2_write_phy(bp, 0x17, 0x0f01);
  4680. bnx2_read_phy(bp, 0x15, &phy2);
  4681. if (phy2 & 0x20) {
  4682. u32 bmcr;
  4683. bnx2_read_phy(bp, bp->mii_bmcr, &bmcr);
  4684. bmcr |= BMCR_ANENABLE;
  4685. bnx2_write_phy(bp, bp->mii_bmcr, bmcr);
  4686. bp->phy_flags &= ~BNX2_PHY_FLAG_PARALLEL_DETECT;
  4687. }
  4688. } else
  4689. bp->current_interval = BNX2_TIMER_INTERVAL;
  4690. if (check_link) {
  4691. u32 val;
  4692. bnx2_write_phy(bp, MII_BNX2_MISC_SHADOW, MISC_SHDW_AN_DBG);
  4693. bnx2_read_phy(bp, MII_BNX2_MISC_SHADOW, &val);
  4694. bnx2_read_phy(bp, MII_BNX2_MISC_SHADOW, &val);
  4695. if (bp->link_up && (val & MISC_SHDW_AN_DBG_NOSYNC)) {
  4696. if (!(bp->phy_flags & BNX2_PHY_FLAG_FORCED_DOWN)) {
  4697. bnx2_5706s_force_link_dn(bp, 1);
  4698. bp->phy_flags |= BNX2_PHY_FLAG_FORCED_DOWN;
  4699. } else
  4700. bnx2_set_link(bp);
  4701. } else if (!bp->link_up && !(val & MISC_SHDW_AN_DBG_NOSYNC))
  4702. bnx2_set_link(bp);
  4703. }
  4704. spin_unlock(&bp->phy_lock);
  4705. }
  4706. static void
  4707. bnx2_5708_serdes_timer(struct bnx2 *bp)
  4708. {
  4709. if (bp->phy_flags & BNX2_PHY_FLAG_REMOTE_PHY_CAP)
  4710. return;
  4711. if ((bp->phy_flags & BNX2_PHY_FLAG_2_5G_CAPABLE) == 0) {
  4712. bp->serdes_an_pending = 0;
  4713. return;
  4714. }
  4715. spin_lock(&bp->phy_lock);
  4716. if (bp->serdes_an_pending)
  4717. bp->serdes_an_pending--;
  4718. else if ((bp->link_up == 0) && (bp->autoneg & AUTONEG_SPEED)) {
  4719. u32 bmcr;
  4720. bnx2_read_phy(bp, bp->mii_bmcr, &bmcr);
  4721. if (bmcr & BMCR_ANENABLE) {
  4722. bnx2_enable_forced_2g5(bp);
  4723. bp->current_interval = BNX2_SERDES_FORCED_TIMEOUT;
  4724. } else {
  4725. bnx2_disable_forced_2g5(bp);
  4726. bp->serdes_an_pending = 2;
  4727. bp->current_interval = BNX2_TIMER_INTERVAL;
  4728. }
  4729. } else
  4730. bp->current_interval = BNX2_TIMER_INTERVAL;
  4731. spin_unlock(&bp->phy_lock);
  4732. }
  4733. static void
  4734. bnx2_timer(unsigned long data)
  4735. {
  4736. struct bnx2 *bp = (struct bnx2 *) data;
  4737. if (!netif_running(bp->dev))
  4738. return;
  4739. if (atomic_read(&bp->intr_sem) != 0)
  4740. goto bnx2_restart_timer;
  4741. if ((bp->flags & (BNX2_FLAG_USING_MSI | BNX2_FLAG_ONE_SHOT_MSI)) ==
  4742. BNX2_FLAG_USING_MSI)
  4743. bnx2_chk_missed_msi(bp);
  4744. bnx2_send_heart_beat(bp);
  4745. bp->stats_blk->stat_FwRxDrop =
  4746. bnx2_reg_rd_ind(bp, BNX2_FW_RX_DROP_COUNT);
  4747. /* workaround occasional corrupted counters */
  4748. if (CHIP_NUM(bp) == CHIP_NUM_5708 && bp->stats_ticks)
  4749. REG_WR(bp, BNX2_HC_COMMAND, bp->hc_cmd |
  4750. BNX2_HC_COMMAND_STATS_NOW);
  4751. if (bp->phy_flags & BNX2_PHY_FLAG_SERDES) {
  4752. if (CHIP_NUM(bp) == CHIP_NUM_5706)
  4753. bnx2_5706_serdes_timer(bp);
  4754. else
  4755. bnx2_5708_serdes_timer(bp);
  4756. }
  4757. bnx2_restart_timer:
  4758. mod_timer(&bp->timer, jiffies + bp->current_interval);
  4759. }
  4760. static int
  4761. bnx2_request_irq(struct bnx2 *bp)
  4762. {
  4763. unsigned long flags;
  4764. struct bnx2_irq *irq;
  4765. int rc = 0, i;
  4766. if (bp->flags & BNX2_FLAG_USING_MSI_OR_MSIX)
  4767. flags = 0;
  4768. else
  4769. flags = IRQF_SHARED;
  4770. for (i = 0; i < bp->irq_nvecs; i++) {
  4771. irq = &bp->irq_tbl[i];
  4772. rc = request_irq(irq->vector, irq->handler, flags, irq->name,
  4773. &bp->bnx2_napi[i]);
  4774. if (rc)
  4775. break;
  4776. irq->requested = 1;
  4777. }
  4778. return rc;
  4779. }
  4780. static void
  4781. bnx2_free_irq(struct bnx2 *bp)
  4782. {
  4783. struct bnx2_irq *irq;
  4784. int i;
  4785. for (i = 0; i < bp->irq_nvecs; i++) {
  4786. irq = &bp->irq_tbl[i];
  4787. if (irq->requested)
  4788. free_irq(irq->vector, &bp->bnx2_napi[i]);
  4789. irq->requested = 0;
  4790. }
  4791. if (bp->flags & BNX2_FLAG_USING_MSI)
  4792. pci_disable_msi(bp->pdev);
  4793. else if (bp->flags & BNX2_FLAG_USING_MSIX)
  4794. pci_disable_msix(bp->pdev);
  4795. bp->flags &= ~(BNX2_FLAG_USING_MSI_OR_MSIX | BNX2_FLAG_ONE_SHOT_MSI);
  4796. }
  4797. static void
  4798. bnx2_enable_msix(struct bnx2 *bp, int msix_vecs)
  4799. {
  4800. int i, rc;
  4801. struct msix_entry msix_ent[BNX2_MAX_MSIX_VEC];
  4802. struct net_device *dev = bp->dev;
  4803. const int len = sizeof(bp->irq_tbl[0].name);
  4804. bnx2_setup_msix_tbl(bp);
  4805. REG_WR(bp, BNX2_PCI_MSIX_CONTROL, BNX2_MAX_MSIX_HW_VEC - 1);
  4806. REG_WR(bp, BNX2_PCI_MSIX_TBL_OFF_BIR, BNX2_PCI_GRC_WINDOW2_BASE);
  4807. REG_WR(bp, BNX2_PCI_MSIX_PBA_OFF_BIT, BNX2_PCI_GRC_WINDOW3_BASE);
  4808. for (i = 0; i < BNX2_MAX_MSIX_VEC; i++) {
  4809. msix_ent[i].entry = i;
  4810. msix_ent[i].vector = 0;
  4811. }
  4812. rc = pci_enable_msix(bp->pdev, msix_ent, BNX2_MAX_MSIX_VEC);
  4813. if (rc != 0)
  4814. return;
  4815. bp->irq_nvecs = msix_vecs;
  4816. bp->flags |= BNX2_FLAG_USING_MSIX | BNX2_FLAG_ONE_SHOT_MSI;
  4817. for (i = 0; i < BNX2_MAX_MSIX_VEC; i++) {
  4818. bp->irq_tbl[i].vector = msix_ent[i].vector;
  4819. snprintf(bp->irq_tbl[i].name, len, "%s-%d", dev->name, i);
  4820. bp->irq_tbl[i].handler = bnx2_msi_1shot;
  4821. }
  4822. }
  4823. static void
  4824. bnx2_setup_int_mode(struct bnx2 *bp, int dis_msi)
  4825. {
  4826. int cpus = num_online_cpus();
  4827. int msix_vecs = min(cpus + 1, RX_MAX_RINGS);
  4828. bp->irq_tbl[0].handler = bnx2_interrupt;
  4829. strcpy(bp->irq_tbl[0].name, bp->dev->name);
  4830. bp->irq_nvecs = 1;
  4831. bp->irq_tbl[0].vector = bp->pdev->irq;
  4832. if ((bp->flags & BNX2_FLAG_MSIX_CAP) && !dis_msi && cpus > 1)
  4833. bnx2_enable_msix(bp, msix_vecs);
  4834. if ((bp->flags & BNX2_FLAG_MSI_CAP) && !dis_msi &&
  4835. !(bp->flags & BNX2_FLAG_USING_MSIX)) {
  4836. if (pci_enable_msi(bp->pdev) == 0) {
  4837. bp->flags |= BNX2_FLAG_USING_MSI;
  4838. if (CHIP_NUM(bp) == CHIP_NUM_5709) {
  4839. bp->flags |= BNX2_FLAG_ONE_SHOT_MSI;
  4840. bp->irq_tbl[0].handler = bnx2_msi_1shot;
  4841. } else
  4842. bp->irq_tbl[0].handler = bnx2_msi;
  4843. bp->irq_tbl[0].vector = bp->pdev->irq;
  4844. }
  4845. }
  4846. bp->num_tx_rings = rounddown_pow_of_two(bp->irq_nvecs);
  4847. bp->dev->real_num_tx_queues = bp->num_tx_rings;
  4848. bp->num_rx_rings = bp->irq_nvecs;
  4849. }
  4850. /* Called with rtnl_lock */
  4851. static int
  4852. bnx2_open(struct net_device *dev)
  4853. {
  4854. struct bnx2 *bp = netdev_priv(dev);
  4855. int rc;
  4856. netif_carrier_off(dev);
  4857. bnx2_set_power_state(bp, PCI_D0);
  4858. bnx2_disable_int(bp);
  4859. bnx2_setup_int_mode(bp, disable_msi);
  4860. bnx2_napi_enable(bp);
  4861. rc = bnx2_alloc_mem(bp);
  4862. if (rc)
  4863. goto open_err;
  4864. rc = bnx2_request_irq(bp);
  4865. if (rc)
  4866. goto open_err;
  4867. rc = bnx2_init_nic(bp, 1);
  4868. if (rc)
  4869. goto open_err;
  4870. mod_timer(&bp->timer, jiffies + bp->current_interval);
  4871. atomic_set(&bp->intr_sem, 0);
  4872. bnx2_enable_int(bp);
  4873. if (bp->flags & BNX2_FLAG_USING_MSI) {
  4874. /* Test MSI to make sure it is working
  4875. * If MSI test fails, go back to INTx mode
  4876. */
  4877. if (bnx2_test_intr(bp) != 0) {
  4878. printk(KERN_WARNING PFX "%s: No interrupt was generated"
  4879. " using MSI, switching to INTx mode. Please"
  4880. " report this failure to the PCI maintainer"
  4881. " and include system chipset information.\n",
  4882. bp->dev->name);
  4883. bnx2_disable_int(bp);
  4884. bnx2_free_irq(bp);
  4885. bnx2_setup_int_mode(bp, 1);
  4886. rc = bnx2_init_nic(bp, 0);
  4887. if (!rc)
  4888. rc = bnx2_request_irq(bp);
  4889. if (rc) {
  4890. del_timer_sync(&bp->timer);
  4891. goto open_err;
  4892. }
  4893. bnx2_enable_int(bp);
  4894. }
  4895. }
  4896. if (bp->flags & BNX2_FLAG_USING_MSI)
  4897. printk(KERN_INFO PFX "%s: using MSI\n", dev->name);
  4898. else if (bp->flags & BNX2_FLAG_USING_MSIX)
  4899. printk(KERN_INFO PFX "%s: using MSIX\n", dev->name);
  4900. netif_tx_start_all_queues(dev);
  4901. return 0;
  4902. open_err:
  4903. bnx2_napi_disable(bp);
  4904. bnx2_free_skbs(bp);
  4905. bnx2_free_irq(bp);
  4906. bnx2_free_mem(bp);
  4907. return rc;
  4908. }
  4909. static void
  4910. bnx2_reset_task(struct work_struct *work)
  4911. {
  4912. struct bnx2 *bp = container_of(work, struct bnx2, reset_task);
  4913. if (!netif_running(bp->dev))
  4914. return;
  4915. bnx2_netif_stop(bp);
  4916. bnx2_init_nic(bp, 1);
  4917. atomic_set(&bp->intr_sem, 1);
  4918. bnx2_netif_start(bp);
  4919. }
  4920. static void
  4921. bnx2_tx_timeout(struct net_device *dev)
  4922. {
  4923. struct bnx2 *bp = netdev_priv(dev);
  4924. /* This allows the netif to be shutdown gracefully before resetting */
  4925. schedule_work(&bp->reset_task);
  4926. }
  4927. #ifdef BCM_VLAN
  4928. /* Called with rtnl_lock */
  4929. static void
  4930. bnx2_vlan_rx_register(struct net_device *dev, struct vlan_group *vlgrp)
  4931. {
  4932. struct bnx2 *bp = netdev_priv(dev);
  4933. bnx2_netif_stop(bp);
  4934. bp->vlgrp = vlgrp;
  4935. bnx2_set_rx_mode(dev);
  4936. if (bp->flags & BNX2_FLAG_CAN_KEEP_VLAN)
  4937. bnx2_fw_sync(bp, BNX2_DRV_MSG_CODE_KEEP_VLAN_UPDATE, 0, 1);
  4938. bnx2_netif_start(bp);
  4939. }
  4940. #endif
  4941. /* Called with netif_tx_lock.
  4942. * bnx2_tx_int() runs without netif_tx_lock unless it needs to call
  4943. * netif_wake_queue().
  4944. */
  4945. static int
  4946. bnx2_start_xmit(struct sk_buff *skb, struct net_device *dev)
  4947. {
  4948. struct bnx2 *bp = netdev_priv(dev);
  4949. dma_addr_t mapping;
  4950. struct tx_bd *txbd;
  4951. struct sw_tx_bd *tx_buf;
  4952. u32 len, vlan_tag_flags, last_frag, mss;
  4953. u16 prod, ring_prod;
  4954. int i;
  4955. struct bnx2_napi *bnapi;
  4956. struct bnx2_tx_ring_info *txr;
  4957. struct netdev_queue *txq;
  4958. struct skb_shared_info *sp;
  4959. /* Determine which tx ring we will be placed on */
  4960. i = skb_get_queue_mapping(skb);
  4961. bnapi = &bp->bnx2_napi[i];
  4962. txr = &bnapi->tx_ring;
  4963. txq = netdev_get_tx_queue(dev, i);
  4964. if (unlikely(bnx2_tx_avail(bp, txr) <
  4965. (skb_shinfo(skb)->nr_frags + 1))) {
  4966. netif_tx_stop_queue(txq);
  4967. printk(KERN_ERR PFX "%s: BUG! Tx ring full when queue awake!\n",
  4968. dev->name);
  4969. return NETDEV_TX_BUSY;
  4970. }
  4971. len = skb_headlen(skb);
  4972. prod = txr->tx_prod;
  4973. ring_prod = TX_RING_IDX(prod);
  4974. vlan_tag_flags = 0;
  4975. if (skb->ip_summed == CHECKSUM_PARTIAL) {
  4976. vlan_tag_flags |= TX_BD_FLAGS_TCP_UDP_CKSUM;
  4977. }
  4978. #ifdef BCM_VLAN
  4979. if (bp->vlgrp && vlan_tx_tag_present(skb)) {
  4980. vlan_tag_flags |=
  4981. (TX_BD_FLAGS_VLAN_TAG | (vlan_tx_tag_get(skb) << 16));
  4982. }
  4983. #endif
  4984. if ((mss = skb_shinfo(skb)->gso_size)) {
  4985. u32 tcp_opt_len;
  4986. struct iphdr *iph;
  4987. vlan_tag_flags |= TX_BD_FLAGS_SW_LSO;
  4988. tcp_opt_len = tcp_optlen(skb);
  4989. if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6) {
  4990. u32 tcp_off = skb_transport_offset(skb) -
  4991. sizeof(struct ipv6hdr) - ETH_HLEN;
  4992. vlan_tag_flags |= ((tcp_opt_len >> 2) << 8) |
  4993. TX_BD_FLAGS_SW_FLAGS;
  4994. if (likely(tcp_off == 0))
  4995. vlan_tag_flags &= ~TX_BD_FLAGS_TCP6_OFF0_MSK;
  4996. else {
  4997. tcp_off >>= 3;
  4998. vlan_tag_flags |= ((tcp_off & 0x3) <<
  4999. TX_BD_FLAGS_TCP6_OFF0_SHL) |
  5000. ((tcp_off & 0x10) <<
  5001. TX_BD_FLAGS_TCP6_OFF4_SHL);
  5002. mss |= (tcp_off & 0xc) << TX_BD_TCP6_OFF2_SHL;
  5003. }
  5004. } else {
  5005. iph = ip_hdr(skb);
  5006. if (tcp_opt_len || (iph->ihl > 5)) {
  5007. vlan_tag_flags |= ((iph->ihl - 5) +
  5008. (tcp_opt_len >> 2)) << 8;
  5009. }
  5010. }
  5011. } else
  5012. mss = 0;
  5013. if (skb_dma_map(&bp->pdev->dev, skb, DMA_TO_DEVICE)) {
  5014. dev_kfree_skb(skb);
  5015. return NETDEV_TX_OK;
  5016. }
  5017. sp = skb_shinfo(skb);
  5018. mapping = sp->dma_maps[0];
  5019. tx_buf = &txr->tx_buf_ring[ring_prod];
  5020. tx_buf->skb = skb;
  5021. txbd = &txr->tx_desc_ring[ring_prod];
  5022. txbd->tx_bd_haddr_hi = (u64) mapping >> 32;
  5023. txbd->tx_bd_haddr_lo = (u64) mapping & 0xffffffff;
  5024. txbd->tx_bd_mss_nbytes = len | (mss << 16);
  5025. txbd->tx_bd_vlan_tag_flags = vlan_tag_flags | TX_BD_FLAGS_START;
  5026. last_frag = skb_shinfo(skb)->nr_frags;
  5027. for (i = 0; i < last_frag; i++) {
  5028. skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  5029. prod = NEXT_TX_BD(prod);
  5030. ring_prod = TX_RING_IDX(prod);
  5031. txbd = &txr->tx_desc_ring[ring_prod];
  5032. len = frag->size;
  5033. mapping = sp->dma_maps[i + 1];
  5034. txbd->tx_bd_haddr_hi = (u64) mapping >> 32;
  5035. txbd->tx_bd_haddr_lo = (u64) mapping & 0xffffffff;
  5036. txbd->tx_bd_mss_nbytes = len | (mss << 16);
  5037. txbd->tx_bd_vlan_tag_flags = vlan_tag_flags;
  5038. }
  5039. txbd->tx_bd_vlan_tag_flags |= TX_BD_FLAGS_END;
  5040. prod = NEXT_TX_BD(prod);
  5041. txr->tx_prod_bseq += skb->len;
  5042. REG_WR16(bp, txr->tx_bidx_addr, prod);
  5043. REG_WR(bp, txr->tx_bseq_addr, txr->tx_prod_bseq);
  5044. mmiowb();
  5045. txr->tx_prod = prod;
  5046. dev->trans_start = jiffies;
  5047. if (unlikely(bnx2_tx_avail(bp, txr) <= MAX_SKB_FRAGS)) {
  5048. netif_tx_stop_queue(txq);
  5049. if (bnx2_tx_avail(bp, txr) > bp->tx_wake_thresh)
  5050. netif_tx_wake_queue(txq);
  5051. }
  5052. return NETDEV_TX_OK;
  5053. }
  5054. /* Called with rtnl_lock */
  5055. static int
  5056. bnx2_close(struct net_device *dev)
  5057. {
  5058. struct bnx2 *bp = netdev_priv(dev);
  5059. cancel_work_sync(&bp->reset_task);
  5060. bnx2_disable_int_sync(bp);
  5061. bnx2_napi_disable(bp);
  5062. del_timer_sync(&bp->timer);
  5063. bnx2_shutdown_chip(bp);
  5064. bnx2_free_irq(bp);
  5065. bnx2_free_skbs(bp);
  5066. bnx2_free_mem(bp);
  5067. bp->link_up = 0;
  5068. netif_carrier_off(bp->dev);
  5069. bnx2_set_power_state(bp, PCI_D3hot);
  5070. return 0;
  5071. }
  5072. #define GET_NET_STATS64(ctr) \
  5073. (unsigned long) ((unsigned long) (ctr##_hi) << 32) + \
  5074. (unsigned long) (ctr##_lo)
  5075. #define GET_NET_STATS32(ctr) \
  5076. (ctr##_lo)
  5077. #if (BITS_PER_LONG == 64)
  5078. #define GET_NET_STATS GET_NET_STATS64
  5079. #else
  5080. #define GET_NET_STATS GET_NET_STATS32
  5081. #endif
  5082. static struct net_device_stats *
  5083. bnx2_get_stats(struct net_device *dev)
  5084. {
  5085. struct bnx2 *bp = netdev_priv(dev);
  5086. struct statistics_block *stats_blk = bp->stats_blk;
  5087. struct net_device_stats *net_stats = &dev->stats;
  5088. if (bp->stats_blk == NULL) {
  5089. return net_stats;
  5090. }
  5091. net_stats->rx_packets =
  5092. GET_NET_STATS(stats_blk->stat_IfHCInUcastPkts) +
  5093. GET_NET_STATS(stats_blk->stat_IfHCInMulticastPkts) +
  5094. GET_NET_STATS(stats_blk->stat_IfHCInBroadcastPkts);
  5095. net_stats->tx_packets =
  5096. GET_NET_STATS(stats_blk->stat_IfHCOutUcastPkts) +
  5097. GET_NET_STATS(stats_blk->stat_IfHCOutMulticastPkts) +
  5098. GET_NET_STATS(stats_blk->stat_IfHCOutBroadcastPkts);
  5099. net_stats->rx_bytes =
  5100. GET_NET_STATS(stats_blk->stat_IfHCInOctets);
  5101. net_stats->tx_bytes =
  5102. GET_NET_STATS(stats_blk->stat_IfHCOutOctets);
  5103. net_stats->multicast =
  5104. GET_NET_STATS(stats_blk->stat_IfHCOutMulticastPkts);
  5105. net_stats->collisions =
  5106. (unsigned long) stats_blk->stat_EtherStatsCollisions;
  5107. net_stats->rx_length_errors =
  5108. (unsigned long) (stats_blk->stat_EtherStatsUndersizePkts +
  5109. stats_blk->stat_EtherStatsOverrsizePkts);
  5110. net_stats->rx_over_errors =
  5111. (unsigned long) stats_blk->stat_IfInMBUFDiscards;
  5112. net_stats->rx_frame_errors =
  5113. (unsigned long) stats_blk->stat_Dot3StatsAlignmentErrors;
  5114. net_stats->rx_crc_errors =
  5115. (unsigned long) stats_blk->stat_Dot3StatsFCSErrors;
  5116. net_stats->rx_errors = net_stats->rx_length_errors +
  5117. net_stats->rx_over_errors + net_stats->rx_frame_errors +
  5118. net_stats->rx_crc_errors;
  5119. net_stats->tx_aborted_errors =
  5120. (unsigned long) (stats_blk->stat_Dot3StatsExcessiveCollisions +
  5121. stats_blk->stat_Dot3StatsLateCollisions);
  5122. if ((CHIP_NUM(bp) == CHIP_NUM_5706) ||
  5123. (CHIP_ID(bp) == CHIP_ID_5708_A0))
  5124. net_stats->tx_carrier_errors = 0;
  5125. else {
  5126. net_stats->tx_carrier_errors =
  5127. (unsigned long)
  5128. stats_blk->stat_Dot3StatsCarrierSenseErrors;
  5129. }
  5130. net_stats->tx_errors =
  5131. (unsigned long)
  5132. stats_blk->stat_emac_tx_stat_dot3statsinternalmactransmiterrors
  5133. +
  5134. net_stats->tx_aborted_errors +
  5135. net_stats->tx_carrier_errors;
  5136. net_stats->rx_missed_errors =
  5137. (unsigned long) (stats_blk->stat_IfInMBUFDiscards +
  5138. stats_blk->stat_FwRxDrop);
  5139. return net_stats;
  5140. }
  5141. /* All ethtool functions called with rtnl_lock */
  5142. static int
  5143. bnx2_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  5144. {
  5145. struct bnx2 *bp = netdev_priv(dev);
  5146. int support_serdes = 0, support_copper = 0;
  5147. cmd->supported = SUPPORTED_Autoneg;
  5148. if (bp->phy_flags & BNX2_PHY_FLAG_REMOTE_PHY_CAP) {
  5149. support_serdes = 1;
  5150. support_copper = 1;
  5151. } else if (bp->phy_port == PORT_FIBRE)
  5152. support_serdes = 1;
  5153. else
  5154. support_copper = 1;
  5155. if (support_serdes) {
  5156. cmd->supported |= SUPPORTED_1000baseT_Full |
  5157. SUPPORTED_FIBRE;
  5158. if (bp->phy_flags & BNX2_PHY_FLAG_2_5G_CAPABLE)
  5159. cmd->supported |= SUPPORTED_2500baseX_Full;
  5160. }
  5161. if (support_copper) {
  5162. cmd->supported |= SUPPORTED_10baseT_Half |
  5163. SUPPORTED_10baseT_Full |
  5164. SUPPORTED_100baseT_Half |
  5165. SUPPORTED_100baseT_Full |
  5166. SUPPORTED_1000baseT_Full |
  5167. SUPPORTED_TP;
  5168. }
  5169. spin_lock_bh(&bp->phy_lock);
  5170. cmd->port = bp->phy_port;
  5171. cmd->advertising = bp->advertising;
  5172. if (bp->autoneg & AUTONEG_SPEED) {
  5173. cmd->autoneg = AUTONEG_ENABLE;
  5174. }
  5175. else {
  5176. cmd->autoneg = AUTONEG_DISABLE;
  5177. }
  5178. if (netif_carrier_ok(dev)) {
  5179. cmd->speed = bp->line_speed;
  5180. cmd->duplex = bp->duplex;
  5181. }
  5182. else {
  5183. cmd->speed = -1;
  5184. cmd->duplex = -1;
  5185. }
  5186. spin_unlock_bh(&bp->phy_lock);
  5187. cmd->transceiver = XCVR_INTERNAL;
  5188. cmd->phy_address = bp->phy_addr;
  5189. return 0;
  5190. }
  5191. static int
  5192. bnx2_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  5193. {
  5194. struct bnx2 *bp = netdev_priv(dev);
  5195. u8 autoneg = bp->autoneg;
  5196. u8 req_duplex = bp->req_duplex;
  5197. u16 req_line_speed = bp->req_line_speed;
  5198. u32 advertising = bp->advertising;
  5199. int err = -EINVAL;
  5200. spin_lock_bh(&bp->phy_lock);
  5201. if (cmd->port != PORT_TP && cmd->port != PORT_FIBRE)
  5202. goto err_out_unlock;
  5203. if (cmd->port != bp->phy_port &&
  5204. !(bp->phy_flags & BNX2_PHY_FLAG_REMOTE_PHY_CAP))
  5205. goto err_out_unlock;
  5206. /* If device is down, we can store the settings only if the user
  5207. * is setting the currently active port.
  5208. */
  5209. if (!netif_running(dev) && cmd->port != bp->phy_port)
  5210. goto err_out_unlock;
  5211. if (cmd->autoneg == AUTONEG_ENABLE) {
  5212. autoneg |= AUTONEG_SPEED;
  5213. cmd->advertising &= ETHTOOL_ALL_COPPER_SPEED;
  5214. /* allow advertising 1 speed */
  5215. if ((cmd->advertising == ADVERTISED_10baseT_Half) ||
  5216. (cmd->advertising == ADVERTISED_10baseT_Full) ||
  5217. (cmd->advertising == ADVERTISED_100baseT_Half) ||
  5218. (cmd->advertising == ADVERTISED_100baseT_Full)) {
  5219. if (cmd->port == PORT_FIBRE)
  5220. goto err_out_unlock;
  5221. advertising = cmd->advertising;
  5222. } else if (cmd->advertising == ADVERTISED_2500baseX_Full) {
  5223. if (!(bp->phy_flags & BNX2_PHY_FLAG_2_5G_CAPABLE) ||
  5224. (cmd->port == PORT_TP))
  5225. goto err_out_unlock;
  5226. } else if (cmd->advertising == ADVERTISED_1000baseT_Full)
  5227. advertising = cmd->advertising;
  5228. else if (cmd->advertising == ADVERTISED_1000baseT_Half)
  5229. goto err_out_unlock;
  5230. else {
  5231. if (cmd->port == PORT_FIBRE)
  5232. advertising = ETHTOOL_ALL_FIBRE_SPEED;
  5233. else
  5234. advertising = ETHTOOL_ALL_COPPER_SPEED;
  5235. }
  5236. advertising |= ADVERTISED_Autoneg;
  5237. }
  5238. else {
  5239. if (cmd->port == PORT_FIBRE) {
  5240. if ((cmd->speed != SPEED_1000 &&
  5241. cmd->speed != SPEED_2500) ||
  5242. (cmd->duplex != DUPLEX_FULL))
  5243. goto err_out_unlock;
  5244. if (cmd->speed == SPEED_2500 &&
  5245. !(bp->phy_flags & BNX2_PHY_FLAG_2_5G_CAPABLE))
  5246. goto err_out_unlock;
  5247. }
  5248. else if (cmd->speed == SPEED_1000 || cmd->speed == SPEED_2500)
  5249. goto err_out_unlock;
  5250. autoneg &= ~AUTONEG_SPEED;
  5251. req_line_speed = cmd->speed;
  5252. req_duplex = cmd->duplex;
  5253. advertising = 0;
  5254. }
  5255. bp->autoneg = autoneg;
  5256. bp->advertising = advertising;
  5257. bp->req_line_speed = req_line_speed;
  5258. bp->req_duplex = req_duplex;
  5259. err = 0;
  5260. /* If device is down, the new settings will be picked up when it is
  5261. * brought up.
  5262. */
  5263. if (netif_running(dev))
  5264. err = bnx2_setup_phy(bp, cmd->port);
  5265. err_out_unlock:
  5266. spin_unlock_bh(&bp->phy_lock);
  5267. return err;
  5268. }
  5269. static void
  5270. bnx2_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
  5271. {
  5272. struct bnx2 *bp = netdev_priv(dev);
  5273. strcpy(info->driver, DRV_MODULE_NAME);
  5274. strcpy(info->version, DRV_MODULE_VERSION);
  5275. strcpy(info->bus_info, pci_name(bp->pdev));
  5276. strcpy(info->fw_version, bp->fw_version);
  5277. }
  5278. #define BNX2_REGDUMP_LEN (32 * 1024)
  5279. static int
  5280. bnx2_get_regs_len(struct net_device *dev)
  5281. {
  5282. return BNX2_REGDUMP_LEN;
  5283. }
  5284. static void
  5285. bnx2_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *_p)
  5286. {
  5287. u32 *p = _p, i, offset;
  5288. u8 *orig_p = _p;
  5289. struct bnx2 *bp = netdev_priv(dev);
  5290. u32 reg_boundaries[] = { 0x0000, 0x0098, 0x0400, 0x045c,
  5291. 0x0800, 0x0880, 0x0c00, 0x0c10,
  5292. 0x0c30, 0x0d08, 0x1000, 0x101c,
  5293. 0x1040, 0x1048, 0x1080, 0x10a4,
  5294. 0x1400, 0x1490, 0x1498, 0x14f0,
  5295. 0x1500, 0x155c, 0x1580, 0x15dc,
  5296. 0x1600, 0x1658, 0x1680, 0x16d8,
  5297. 0x1800, 0x1820, 0x1840, 0x1854,
  5298. 0x1880, 0x1894, 0x1900, 0x1984,
  5299. 0x1c00, 0x1c0c, 0x1c40, 0x1c54,
  5300. 0x1c80, 0x1c94, 0x1d00, 0x1d84,
  5301. 0x2000, 0x2030, 0x23c0, 0x2400,
  5302. 0x2800, 0x2820, 0x2830, 0x2850,
  5303. 0x2b40, 0x2c10, 0x2fc0, 0x3058,
  5304. 0x3c00, 0x3c94, 0x4000, 0x4010,
  5305. 0x4080, 0x4090, 0x43c0, 0x4458,
  5306. 0x4c00, 0x4c18, 0x4c40, 0x4c54,
  5307. 0x4fc0, 0x5010, 0x53c0, 0x5444,
  5308. 0x5c00, 0x5c18, 0x5c80, 0x5c90,
  5309. 0x5fc0, 0x6000, 0x6400, 0x6428,
  5310. 0x6800, 0x6848, 0x684c, 0x6860,
  5311. 0x6888, 0x6910, 0x8000 };
  5312. regs->version = 0;
  5313. memset(p, 0, BNX2_REGDUMP_LEN);
  5314. if (!netif_running(bp->dev))
  5315. return;
  5316. i = 0;
  5317. offset = reg_boundaries[0];
  5318. p += offset;
  5319. while (offset < BNX2_REGDUMP_LEN) {
  5320. *p++ = REG_RD(bp, offset);
  5321. offset += 4;
  5322. if (offset == reg_boundaries[i + 1]) {
  5323. offset = reg_boundaries[i + 2];
  5324. p = (u32 *) (orig_p + offset);
  5325. i += 2;
  5326. }
  5327. }
  5328. }
  5329. static void
  5330. bnx2_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  5331. {
  5332. struct bnx2 *bp = netdev_priv(dev);
  5333. if (bp->flags & BNX2_FLAG_NO_WOL) {
  5334. wol->supported = 0;
  5335. wol->wolopts = 0;
  5336. }
  5337. else {
  5338. wol->supported = WAKE_MAGIC;
  5339. if (bp->wol)
  5340. wol->wolopts = WAKE_MAGIC;
  5341. else
  5342. wol->wolopts = 0;
  5343. }
  5344. memset(&wol->sopass, 0, sizeof(wol->sopass));
  5345. }
  5346. static int
  5347. bnx2_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  5348. {
  5349. struct bnx2 *bp = netdev_priv(dev);
  5350. if (wol->wolopts & ~WAKE_MAGIC)
  5351. return -EINVAL;
  5352. if (wol->wolopts & WAKE_MAGIC) {
  5353. if (bp->flags & BNX2_FLAG_NO_WOL)
  5354. return -EINVAL;
  5355. bp->wol = 1;
  5356. }
  5357. else {
  5358. bp->wol = 0;
  5359. }
  5360. return 0;
  5361. }
  5362. static int
  5363. bnx2_nway_reset(struct net_device *dev)
  5364. {
  5365. struct bnx2 *bp = netdev_priv(dev);
  5366. u32 bmcr;
  5367. if (!netif_running(dev))
  5368. return -EAGAIN;
  5369. if (!(bp->autoneg & AUTONEG_SPEED)) {
  5370. return -EINVAL;
  5371. }
  5372. spin_lock_bh(&bp->phy_lock);
  5373. if (bp->phy_flags & BNX2_PHY_FLAG_REMOTE_PHY_CAP) {
  5374. int rc;
  5375. rc = bnx2_setup_remote_phy(bp, bp->phy_port);
  5376. spin_unlock_bh(&bp->phy_lock);
  5377. return rc;
  5378. }
  5379. /* Force a link down visible on the other side */
  5380. if (bp->phy_flags & BNX2_PHY_FLAG_SERDES) {
  5381. bnx2_write_phy(bp, bp->mii_bmcr, BMCR_LOOPBACK);
  5382. spin_unlock_bh(&bp->phy_lock);
  5383. msleep(20);
  5384. spin_lock_bh(&bp->phy_lock);
  5385. bp->current_interval = BNX2_SERDES_AN_TIMEOUT;
  5386. bp->serdes_an_pending = 1;
  5387. mod_timer(&bp->timer, jiffies + bp->current_interval);
  5388. }
  5389. bnx2_read_phy(bp, bp->mii_bmcr, &bmcr);
  5390. bmcr &= ~BMCR_LOOPBACK;
  5391. bnx2_write_phy(bp, bp->mii_bmcr, bmcr | BMCR_ANRESTART | BMCR_ANENABLE);
  5392. spin_unlock_bh(&bp->phy_lock);
  5393. return 0;
  5394. }
  5395. static int
  5396. bnx2_get_eeprom_len(struct net_device *dev)
  5397. {
  5398. struct bnx2 *bp = netdev_priv(dev);
  5399. if (bp->flash_info == NULL)
  5400. return 0;
  5401. return (int) bp->flash_size;
  5402. }
  5403. static int
  5404. bnx2_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
  5405. u8 *eebuf)
  5406. {
  5407. struct bnx2 *bp = netdev_priv(dev);
  5408. int rc;
  5409. if (!netif_running(dev))
  5410. return -EAGAIN;
  5411. /* parameters already validated in ethtool_get_eeprom */
  5412. rc = bnx2_nvram_read(bp, eeprom->offset, eebuf, eeprom->len);
  5413. return rc;
  5414. }
  5415. static int
  5416. bnx2_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
  5417. u8 *eebuf)
  5418. {
  5419. struct bnx2 *bp = netdev_priv(dev);
  5420. int rc;
  5421. if (!netif_running(dev))
  5422. return -EAGAIN;
  5423. /* parameters already validated in ethtool_set_eeprom */
  5424. rc = bnx2_nvram_write(bp, eeprom->offset, eebuf, eeprom->len);
  5425. return rc;
  5426. }
  5427. static int
  5428. bnx2_get_coalesce(struct net_device *dev, struct ethtool_coalesce *coal)
  5429. {
  5430. struct bnx2 *bp = netdev_priv(dev);
  5431. memset(coal, 0, sizeof(struct ethtool_coalesce));
  5432. coal->rx_coalesce_usecs = bp->rx_ticks;
  5433. coal->rx_max_coalesced_frames = bp->rx_quick_cons_trip;
  5434. coal->rx_coalesce_usecs_irq = bp->rx_ticks_int;
  5435. coal->rx_max_coalesced_frames_irq = bp->rx_quick_cons_trip_int;
  5436. coal->tx_coalesce_usecs = bp->tx_ticks;
  5437. coal->tx_max_coalesced_frames = bp->tx_quick_cons_trip;
  5438. coal->tx_coalesce_usecs_irq = bp->tx_ticks_int;
  5439. coal->tx_max_coalesced_frames_irq = bp->tx_quick_cons_trip_int;
  5440. coal->stats_block_coalesce_usecs = bp->stats_ticks;
  5441. return 0;
  5442. }
  5443. static int
  5444. bnx2_set_coalesce(struct net_device *dev, struct ethtool_coalesce *coal)
  5445. {
  5446. struct bnx2 *bp = netdev_priv(dev);
  5447. bp->rx_ticks = (u16) coal->rx_coalesce_usecs;
  5448. if (bp->rx_ticks > 0x3ff) bp->rx_ticks = 0x3ff;
  5449. bp->rx_quick_cons_trip = (u16) coal->rx_max_coalesced_frames;
  5450. if (bp->rx_quick_cons_trip > 0xff) bp->rx_quick_cons_trip = 0xff;
  5451. bp->rx_ticks_int = (u16) coal->rx_coalesce_usecs_irq;
  5452. if (bp->rx_ticks_int > 0x3ff) bp->rx_ticks_int = 0x3ff;
  5453. bp->rx_quick_cons_trip_int = (u16) coal->rx_max_coalesced_frames_irq;
  5454. if (bp->rx_quick_cons_trip_int > 0xff)
  5455. bp->rx_quick_cons_trip_int = 0xff;
  5456. bp->tx_ticks = (u16) coal->tx_coalesce_usecs;
  5457. if (bp->tx_ticks > 0x3ff) bp->tx_ticks = 0x3ff;
  5458. bp->tx_quick_cons_trip = (u16) coal->tx_max_coalesced_frames;
  5459. if (bp->tx_quick_cons_trip > 0xff) bp->tx_quick_cons_trip = 0xff;
  5460. bp->tx_ticks_int = (u16) coal->tx_coalesce_usecs_irq;
  5461. if (bp->tx_ticks_int > 0x3ff) bp->tx_ticks_int = 0x3ff;
  5462. bp->tx_quick_cons_trip_int = (u16) coal->tx_max_coalesced_frames_irq;
  5463. if (bp->tx_quick_cons_trip_int > 0xff) bp->tx_quick_cons_trip_int =
  5464. 0xff;
  5465. bp->stats_ticks = coal->stats_block_coalesce_usecs;
  5466. if (CHIP_NUM(bp) == CHIP_NUM_5708) {
  5467. if (bp->stats_ticks != 0 && bp->stats_ticks != USEC_PER_SEC)
  5468. bp->stats_ticks = USEC_PER_SEC;
  5469. }
  5470. if (bp->stats_ticks > BNX2_HC_STATS_TICKS_HC_STAT_TICKS)
  5471. bp->stats_ticks = BNX2_HC_STATS_TICKS_HC_STAT_TICKS;
  5472. bp->stats_ticks &= BNX2_HC_STATS_TICKS_HC_STAT_TICKS;
  5473. if (netif_running(bp->dev)) {
  5474. bnx2_netif_stop(bp);
  5475. bnx2_init_nic(bp, 0);
  5476. bnx2_netif_start(bp);
  5477. }
  5478. return 0;
  5479. }
  5480. static void
  5481. bnx2_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ering)
  5482. {
  5483. struct bnx2 *bp = netdev_priv(dev);
  5484. ering->rx_max_pending = MAX_TOTAL_RX_DESC_CNT;
  5485. ering->rx_mini_max_pending = 0;
  5486. ering->rx_jumbo_max_pending = MAX_TOTAL_RX_PG_DESC_CNT;
  5487. ering->rx_pending = bp->rx_ring_size;
  5488. ering->rx_mini_pending = 0;
  5489. ering->rx_jumbo_pending = bp->rx_pg_ring_size;
  5490. ering->tx_max_pending = MAX_TX_DESC_CNT;
  5491. ering->tx_pending = bp->tx_ring_size;
  5492. }
  5493. static int
  5494. bnx2_change_ring_size(struct bnx2 *bp, u32 rx, u32 tx)
  5495. {
  5496. if (netif_running(bp->dev)) {
  5497. bnx2_netif_stop(bp);
  5498. bnx2_reset_chip(bp, BNX2_DRV_MSG_CODE_RESET);
  5499. bnx2_free_skbs(bp);
  5500. bnx2_free_mem(bp);
  5501. }
  5502. bnx2_set_rx_ring_size(bp, rx);
  5503. bp->tx_ring_size = tx;
  5504. if (netif_running(bp->dev)) {
  5505. int rc;
  5506. rc = bnx2_alloc_mem(bp);
  5507. if (rc)
  5508. return rc;
  5509. bnx2_init_nic(bp, 0);
  5510. bnx2_netif_start(bp);
  5511. }
  5512. return 0;
  5513. }
  5514. static int
  5515. bnx2_set_ringparam(struct net_device *dev, struct ethtool_ringparam *ering)
  5516. {
  5517. struct bnx2 *bp = netdev_priv(dev);
  5518. int rc;
  5519. if ((ering->rx_pending > MAX_TOTAL_RX_DESC_CNT) ||
  5520. (ering->tx_pending > MAX_TX_DESC_CNT) ||
  5521. (ering->tx_pending <= MAX_SKB_FRAGS)) {
  5522. return -EINVAL;
  5523. }
  5524. rc = bnx2_change_ring_size(bp, ering->rx_pending, ering->tx_pending);
  5525. return rc;
  5526. }
  5527. static void
  5528. bnx2_get_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause)
  5529. {
  5530. struct bnx2 *bp = netdev_priv(dev);
  5531. epause->autoneg = ((bp->autoneg & AUTONEG_FLOW_CTRL) != 0);
  5532. epause->rx_pause = ((bp->flow_ctrl & FLOW_CTRL_RX) != 0);
  5533. epause->tx_pause = ((bp->flow_ctrl & FLOW_CTRL_TX) != 0);
  5534. }
  5535. static int
  5536. bnx2_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause)
  5537. {
  5538. struct bnx2 *bp = netdev_priv(dev);
  5539. bp->req_flow_ctrl = 0;
  5540. if (epause->rx_pause)
  5541. bp->req_flow_ctrl |= FLOW_CTRL_RX;
  5542. if (epause->tx_pause)
  5543. bp->req_flow_ctrl |= FLOW_CTRL_TX;
  5544. if (epause->autoneg) {
  5545. bp->autoneg |= AUTONEG_FLOW_CTRL;
  5546. }
  5547. else {
  5548. bp->autoneg &= ~AUTONEG_FLOW_CTRL;
  5549. }
  5550. if (netif_running(dev)) {
  5551. spin_lock_bh(&bp->phy_lock);
  5552. bnx2_setup_phy(bp, bp->phy_port);
  5553. spin_unlock_bh(&bp->phy_lock);
  5554. }
  5555. return 0;
  5556. }
  5557. static u32
  5558. bnx2_get_rx_csum(struct net_device *dev)
  5559. {
  5560. struct bnx2 *bp = netdev_priv(dev);
  5561. return bp->rx_csum;
  5562. }
  5563. static int
  5564. bnx2_set_rx_csum(struct net_device *dev, u32 data)
  5565. {
  5566. struct bnx2 *bp = netdev_priv(dev);
  5567. bp->rx_csum = data;
  5568. return 0;
  5569. }
  5570. static int
  5571. bnx2_set_tso(struct net_device *dev, u32 data)
  5572. {
  5573. struct bnx2 *bp = netdev_priv(dev);
  5574. if (data) {
  5575. dev->features |= NETIF_F_TSO | NETIF_F_TSO_ECN;
  5576. if (CHIP_NUM(bp) == CHIP_NUM_5709)
  5577. dev->features |= NETIF_F_TSO6;
  5578. } else
  5579. dev->features &= ~(NETIF_F_TSO | NETIF_F_TSO6 |
  5580. NETIF_F_TSO_ECN);
  5581. return 0;
  5582. }
  5583. #define BNX2_NUM_STATS 46
  5584. static struct {
  5585. char string[ETH_GSTRING_LEN];
  5586. } bnx2_stats_str_arr[BNX2_NUM_STATS] = {
  5587. { "rx_bytes" },
  5588. { "rx_error_bytes" },
  5589. { "tx_bytes" },
  5590. { "tx_error_bytes" },
  5591. { "rx_ucast_packets" },
  5592. { "rx_mcast_packets" },
  5593. { "rx_bcast_packets" },
  5594. { "tx_ucast_packets" },
  5595. { "tx_mcast_packets" },
  5596. { "tx_bcast_packets" },
  5597. { "tx_mac_errors" },
  5598. { "tx_carrier_errors" },
  5599. { "rx_crc_errors" },
  5600. { "rx_align_errors" },
  5601. { "tx_single_collisions" },
  5602. { "tx_multi_collisions" },
  5603. { "tx_deferred" },
  5604. { "tx_excess_collisions" },
  5605. { "tx_late_collisions" },
  5606. { "tx_total_collisions" },
  5607. { "rx_fragments" },
  5608. { "rx_jabbers" },
  5609. { "rx_undersize_packets" },
  5610. { "rx_oversize_packets" },
  5611. { "rx_64_byte_packets" },
  5612. { "rx_65_to_127_byte_packets" },
  5613. { "rx_128_to_255_byte_packets" },
  5614. { "rx_256_to_511_byte_packets" },
  5615. { "rx_512_to_1023_byte_packets" },
  5616. { "rx_1024_to_1522_byte_packets" },
  5617. { "rx_1523_to_9022_byte_packets" },
  5618. { "tx_64_byte_packets" },
  5619. { "tx_65_to_127_byte_packets" },
  5620. { "tx_128_to_255_byte_packets" },
  5621. { "tx_256_to_511_byte_packets" },
  5622. { "tx_512_to_1023_byte_packets" },
  5623. { "tx_1024_to_1522_byte_packets" },
  5624. { "tx_1523_to_9022_byte_packets" },
  5625. { "rx_xon_frames" },
  5626. { "rx_xoff_frames" },
  5627. { "tx_xon_frames" },
  5628. { "tx_xoff_frames" },
  5629. { "rx_mac_ctrl_frames" },
  5630. { "rx_filtered_packets" },
  5631. { "rx_discards" },
  5632. { "rx_fw_discards" },
  5633. };
  5634. #define STATS_OFFSET32(offset_name) (offsetof(struct statistics_block, offset_name) / 4)
  5635. static const unsigned long bnx2_stats_offset_arr[BNX2_NUM_STATS] = {
  5636. STATS_OFFSET32(stat_IfHCInOctets_hi),
  5637. STATS_OFFSET32(stat_IfHCInBadOctets_hi),
  5638. STATS_OFFSET32(stat_IfHCOutOctets_hi),
  5639. STATS_OFFSET32(stat_IfHCOutBadOctets_hi),
  5640. STATS_OFFSET32(stat_IfHCInUcastPkts_hi),
  5641. STATS_OFFSET32(stat_IfHCInMulticastPkts_hi),
  5642. STATS_OFFSET32(stat_IfHCInBroadcastPkts_hi),
  5643. STATS_OFFSET32(stat_IfHCOutUcastPkts_hi),
  5644. STATS_OFFSET32(stat_IfHCOutMulticastPkts_hi),
  5645. STATS_OFFSET32(stat_IfHCOutBroadcastPkts_hi),
  5646. STATS_OFFSET32(stat_emac_tx_stat_dot3statsinternalmactransmiterrors),
  5647. STATS_OFFSET32(stat_Dot3StatsCarrierSenseErrors),
  5648. STATS_OFFSET32(stat_Dot3StatsFCSErrors),
  5649. STATS_OFFSET32(stat_Dot3StatsAlignmentErrors),
  5650. STATS_OFFSET32(stat_Dot3StatsSingleCollisionFrames),
  5651. STATS_OFFSET32(stat_Dot3StatsMultipleCollisionFrames),
  5652. STATS_OFFSET32(stat_Dot3StatsDeferredTransmissions),
  5653. STATS_OFFSET32(stat_Dot3StatsExcessiveCollisions),
  5654. STATS_OFFSET32(stat_Dot3StatsLateCollisions),
  5655. STATS_OFFSET32(stat_EtherStatsCollisions),
  5656. STATS_OFFSET32(stat_EtherStatsFragments),
  5657. STATS_OFFSET32(stat_EtherStatsJabbers),
  5658. STATS_OFFSET32(stat_EtherStatsUndersizePkts),
  5659. STATS_OFFSET32(stat_EtherStatsOverrsizePkts),
  5660. STATS_OFFSET32(stat_EtherStatsPktsRx64Octets),
  5661. STATS_OFFSET32(stat_EtherStatsPktsRx65Octetsto127Octets),
  5662. STATS_OFFSET32(stat_EtherStatsPktsRx128Octetsto255Octets),
  5663. STATS_OFFSET32(stat_EtherStatsPktsRx256Octetsto511Octets),
  5664. STATS_OFFSET32(stat_EtherStatsPktsRx512Octetsto1023Octets),
  5665. STATS_OFFSET32(stat_EtherStatsPktsRx1024Octetsto1522Octets),
  5666. STATS_OFFSET32(stat_EtherStatsPktsRx1523Octetsto9022Octets),
  5667. STATS_OFFSET32(stat_EtherStatsPktsTx64Octets),
  5668. STATS_OFFSET32(stat_EtherStatsPktsTx65Octetsto127Octets),
  5669. STATS_OFFSET32(stat_EtherStatsPktsTx128Octetsto255Octets),
  5670. STATS_OFFSET32(stat_EtherStatsPktsTx256Octetsto511Octets),
  5671. STATS_OFFSET32(stat_EtherStatsPktsTx512Octetsto1023Octets),
  5672. STATS_OFFSET32(stat_EtherStatsPktsTx1024Octetsto1522Octets),
  5673. STATS_OFFSET32(stat_EtherStatsPktsTx1523Octetsto9022Octets),
  5674. STATS_OFFSET32(stat_XonPauseFramesReceived),
  5675. STATS_OFFSET32(stat_XoffPauseFramesReceived),
  5676. STATS_OFFSET32(stat_OutXonSent),
  5677. STATS_OFFSET32(stat_OutXoffSent),
  5678. STATS_OFFSET32(stat_MacControlFramesReceived),
  5679. STATS_OFFSET32(stat_IfInFramesL2FilterDiscards),
  5680. STATS_OFFSET32(stat_IfInMBUFDiscards),
  5681. STATS_OFFSET32(stat_FwRxDrop),
  5682. };
  5683. /* stat_IfHCInBadOctets and stat_Dot3StatsCarrierSenseErrors are
  5684. * skipped because of errata.
  5685. */
  5686. static u8 bnx2_5706_stats_len_arr[BNX2_NUM_STATS] = {
  5687. 8,0,8,8,8,8,8,8,8,8,
  5688. 4,0,4,4,4,4,4,4,4,4,
  5689. 4,4,4,4,4,4,4,4,4,4,
  5690. 4,4,4,4,4,4,4,4,4,4,
  5691. 4,4,4,4,4,4,
  5692. };
  5693. static u8 bnx2_5708_stats_len_arr[BNX2_NUM_STATS] = {
  5694. 8,0,8,8,8,8,8,8,8,8,
  5695. 4,4,4,4,4,4,4,4,4,4,
  5696. 4,4,4,4,4,4,4,4,4,4,
  5697. 4,4,4,4,4,4,4,4,4,4,
  5698. 4,4,4,4,4,4,
  5699. };
  5700. #define BNX2_NUM_TESTS 6
  5701. static struct {
  5702. char string[ETH_GSTRING_LEN];
  5703. } bnx2_tests_str_arr[BNX2_NUM_TESTS] = {
  5704. { "register_test (offline)" },
  5705. { "memory_test (offline)" },
  5706. { "loopback_test (offline)" },
  5707. { "nvram_test (online)" },
  5708. { "interrupt_test (online)" },
  5709. { "link_test (online)" },
  5710. };
  5711. static int
  5712. bnx2_get_sset_count(struct net_device *dev, int sset)
  5713. {
  5714. switch (sset) {
  5715. case ETH_SS_TEST:
  5716. return BNX2_NUM_TESTS;
  5717. case ETH_SS_STATS:
  5718. return BNX2_NUM_STATS;
  5719. default:
  5720. return -EOPNOTSUPP;
  5721. }
  5722. }
  5723. static void
  5724. bnx2_self_test(struct net_device *dev, struct ethtool_test *etest, u64 *buf)
  5725. {
  5726. struct bnx2 *bp = netdev_priv(dev);
  5727. bnx2_set_power_state(bp, PCI_D0);
  5728. memset(buf, 0, sizeof(u64) * BNX2_NUM_TESTS);
  5729. if (etest->flags & ETH_TEST_FL_OFFLINE) {
  5730. int i;
  5731. bnx2_netif_stop(bp);
  5732. bnx2_reset_chip(bp, BNX2_DRV_MSG_CODE_DIAG);
  5733. bnx2_free_skbs(bp);
  5734. if (bnx2_test_registers(bp) != 0) {
  5735. buf[0] = 1;
  5736. etest->flags |= ETH_TEST_FL_FAILED;
  5737. }
  5738. if (bnx2_test_memory(bp) != 0) {
  5739. buf[1] = 1;
  5740. etest->flags |= ETH_TEST_FL_FAILED;
  5741. }
  5742. if ((buf[2] = bnx2_test_loopback(bp)) != 0)
  5743. etest->flags |= ETH_TEST_FL_FAILED;
  5744. if (!netif_running(bp->dev))
  5745. bnx2_shutdown_chip(bp);
  5746. else {
  5747. bnx2_init_nic(bp, 1);
  5748. bnx2_netif_start(bp);
  5749. }
  5750. /* wait for link up */
  5751. for (i = 0; i < 7; i++) {
  5752. if (bp->link_up)
  5753. break;
  5754. msleep_interruptible(1000);
  5755. }
  5756. }
  5757. if (bnx2_test_nvram(bp) != 0) {
  5758. buf[3] = 1;
  5759. etest->flags |= ETH_TEST_FL_FAILED;
  5760. }
  5761. if (bnx2_test_intr(bp) != 0) {
  5762. buf[4] = 1;
  5763. etest->flags |= ETH_TEST_FL_FAILED;
  5764. }
  5765. if (bnx2_test_link(bp) != 0) {
  5766. buf[5] = 1;
  5767. etest->flags |= ETH_TEST_FL_FAILED;
  5768. }
  5769. if (!netif_running(bp->dev))
  5770. bnx2_set_power_state(bp, PCI_D3hot);
  5771. }
  5772. static void
  5773. bnx2_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
  5774. {
  5775. switch (stringset) {
  5776. case ETH_SS_STATS:
  5777. memcpy(buf, bnx2_stats_str_arr,
  5778. sizeof(bnx2_stats_str_arr));
  5779. break;
  5780. case ETH_SS_TEST:
  5781. memcpy(buf, bnx2_tests_str_arr,
  5782. sizeof(bnx2_tests_str_arr));
  5783. break;
  5784. }
  5785. }
  5786. static void
  5787. bnx2_get_ethtool_stats(struct net_device *dev,
  5788. struct ethtool_stats *stats, u64 *buf)
  5789. {
  5790. struct bnx2 *bp = netdev_priv(dev);
  5791. int i;
  5792. u32 *hw_stats = (u32 *) bp->stats_blk;
  5793. u8 *stats_len_arr = NULL;
  5794. if (hw_stats == NULL) {
  5795. memset(buf, 0, sizeof(u64) * BNX2_NUM_STATS);
  5796. return;
  5797. }
  5798. if ((CHIP_ID(bp) == CHIP_ID_5706_A0) ||
  5799. (CHIP_ID(bp) == CHIP_ID_5706_A1) ||
  5800. (CHIP_ID(bp) == CHIP_ID_5706_A2) ||
  5801. (CHIP_ID(bp) == CHIP_ID_5708_A0))
  5802. stats_len_arr = bnx2_5706_stats_len_arr;
  5803. else
  5804. stats_len_arr = bnx2_5708_stats_len_arr;
  5805. for (i = 0; i < BNX2_NUM_STATS; i++) {
  5806. if (stats_len_arr[i] == 0) {
  5807. /* skip this counter */
  5808. buf[i] = 0;
  5809. continue;
  5810. }
  5811. if (stats_len_arr[i] == 4) {
  5812. /* 4-byte counter */
  5813. buf[i] = (u64)
  5814. *(hw_stats + bnx2_stats_offset_arr[i]);
  5815. continue;
  5816. }
  5817. /* 8-byte counter */
  5818. buf[i] = (((u64) *(hw_stats +
  5819. bnx2_stats_offset_arr[i])) << 32) +
  5820. *(hw_stats + bnx2_stats_offset_arr[i] + 1);
  5821. }
  5822. }
  5823. static int
  5824. bnx2_phys_id(struct net_device *dev, u32 data)
  5825. {
  5826. struct bnx2 *bp = netdev_priv(dev);
  5827. int i;
  5828. u32 save;
  5829. bnx2_set_power_state(bp, PCI_D0);
  5830. if (data == 0)
  5831. data = 2;
  5832. save = REG_RD(bp, BNX2_MISC_CFG);
  5833. REG_WR(bp, BNX2_MISC_CFG, BNX2_MISC_CFG_LEDMODE_MAC);
  5834. for (i = 0; i < (data * 2); i++) {
  5835. if ((i % 2) == 0) {
  5836. REG_WR(bp, BNX2_EMAC_LED, BNX2_EMAC_LED_OVERRIDE);
  5837. }
  5838. else {
  5839. REG_WR(bp, BNX2_EMAC_LED, BNX2_EMAC_LED_OVERRIDE |
  5840. BNX2_EMAC_LED_1000MB_OVERRIDE |
  5841. BNX2_EMAC_LED_100MB_OVERRIDE |
  5842. BNX2_EMAC_LED_10MB_OVERRIDE |
  5843. BNX2_EMAC_LED_TRAFFIC_OVERRIDE |
  5844. BNX2_EMAC_LED_TRAFFIC);
  5845. }
  5846. msleep_interruptible(500);
  5847. if (signal_pending(current))
  5848. break;
  5849. }
  5850. REG_WR(bp, BNX2_EMAC_LED, 0);
  5851. REG_WR(bp, BNX2_MISC_CFG, save);
  5852. if (!netif_running(dev))
  5853. bnx2_set_power_state(bp, PCI_D3hot);
  5854. return 0;
  5855. }
  5856. static int
  5857. bnx2_set_tx_csum(struct net_device *dev, u32 data)
  5858. {
  5859. struct bnx2 *bp = netdev_priv(dev);
  5860. if (CHIP_NUM(bp) == CHIP_NUM_5709)
  5861. return (ethtool_op_set_tx_ipv6_csum(dev, data));
  5862. else
  5863. return (ethtool_op_set_tx_csum(dev, data));
  5864. }
  5865. static const struct ethtool_ops bnx2_ethtool_ops = {
  5866. .get_settings = bnx2_get_settings,
  5867. .set_settings = bnx2_set_settings,
  5868. .get_drvinfo = bnx2_get_drvinfo,
  5869. .get_regs_len = bnx2_get_regs_len,
  5870. .get_regs = bnx2_get_regs,
  5871. .get_wol = bnx2_get_wol,
  5872. .set_wol = bnx2_set_wol,
  5873. .nway_reset = bnx2_nway_reset,
  5874. .get_link = ethtool_op_get_link,
  5875. .get_eeprom_len = bnx2_get_eeprom_len,
  5876. .get_eeprom = bnx2_get_eeprom,
  5877. .set_eeprom = bnx2_set_eeprom,
  5878. .get_coalesce = bnx2_get_coalesce,
  5879. .set_coalesce = bnx2_set_coalesce,
  5880. .get_ringparam = bnx2_get_ringparam,
  5881. .set_ringparam = bnx2_set_ringparam,
  5882. .get_pauseparam = bnx2_get_pauseparam,
  5883. .set_pauseparam = bnx2_set_pauseparam,
  5884. .get_rx_csum = bnx2_get_rx_csum,
  5885. .set_rx_csum = bnx2_set_rx_csum,
  5886. .set_tx_csum = bnx2_set_tx_csum,
  5887. .set_sg = ethtool_op_set_sg,
  5888. .set_tso = bnx2_set_tso,
  5889. .self_test = bnx2_self_test,
  5890. .get_strings = bnx2_get_strings,
  5891. .phys_id = bnx2_phys_id,
  5892. .get_ethtool_stats = bnx2_get_ethtool_stats,
  5893. .get_sset_count = bnx2_get_sset_count,
  5894. };
  5895. /* Called with rtnl_lock */
  5896. static int
  5897. bnx2_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  5898. {
  5899. struct mii_ioctl_data *data = if_mii(ifr);
  5900. struct bnx2 *bp = netdev_priv(dev);
  5901. int err;
  5902. switch(cmd) {
  5903. case SIOCGMIIPHY:
  5904. data->phy_id = bp->phy_addr;
  5905. /* fallthru */
  5906. case SIOCGMIIREG: {
  5907. u32 mii_regval;
  5908. if (bp->phy_flags & BNX2_PHY_FLAG_REMOTE_PHY_CAP)
  5909. return -EOPNOTSUPP;
  5910. if (!netif_running(dev))
  5911. return -EAGAIN;
  5912. spin_lock_bh(&bp->phy_lock);
  5913. err = bnx2_read_phy(bp, data->reg_num & 0x1f, &mii_regval);
  5914. spin_unlock_bh(&bp->phy_lock);
  5915. data->val_out = mii_regval;
  5916. return err;
  5917. }
  5918. case SIOCSMIIREG:
  5919. if (!capable(CAP_NET_ADMIN))
  5920. return -EPERM;
  5921. if (bp->phy_flags & BNX2_PHY_FLAG_REMOTE_PHY_CAP)
  5922. return -EOPNOTSUPP;
  5923. if (!netif_running(dev))
  5924. return -EAGAIN;
  5925. spin_lock_bh(&bp->phy_lock);
  5926. err = bnx2_write_phy(bp, data->reg_num & 0x1f, data->val_in);
  5927. spin_unlock_bh(&bp->phy_lock);
  5928. return err;
  5929. default:
  5930. /* do nothing */
  5931. break;
  5932. }
  5933. return -EOPNOTSUPP;
  5934. }
  5935. /* Called with rtnl_lock */
  5936. static int
  5937. bnx2_change_mac_addr(struct net_device *dev, void *p)
  5938. {
  5939. struct sockaddr *addr = p;
  5940. struct bnx2 *bp = netdev_priv(dev);
  5941. if (!is_valid_ether_addr(addr->sa_data))
  5942. return -EINVAL;
  5943. memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
  5944. if (netif_running(dev))
  5945. bnx2_set_mac_addr(bp, bp->dev->dev_addr, 0);
  5946. return 0;
  5947. }
  5948. /* Called with rtnl_lock */
  5949. static int
  5950. bnx2_change_mtu(struct net_device *dev, int new_mtu)
  5951. {
  5952. struct bnx2 *bp = netdev_priv(dev);
  5953. if (((new_mtu + ETH_HLEN) > MAX_ETHERNET_JUMBO_PACKET_SIZE) ||
  5954. ((new_mtu + ETH_HLEN) < MIN_ETHERNET_PACKET_SIZE))
  5955. return -EINVAL;
  5956. dev->mtu = new_mtu;
  5957. return (bnx2_change_ring_size(bp, bp->rx_ring_size, bp->tx_ring_size));
  5958. }
  5959. #if defined(HAVE_POLL_CONTROLLER) || defined(CONFIG_NET_POLL_CONTROLLER)
  5960. static void
  5961. poll_bnx2(struct net_device *dev)
  5962. {
  5963. struct bnx2 *bp = netdev_priv(dev);
  5964. int i;
  5965. for (i = 0; i < bp->irq_nvecs; i++) {
  5966. disable_irq(bp->irq_tbl[i].vector);
  5967. bnx2_interrupt(bp->irq_tbl[i].vector, &bp->bnx2_napi[i]);
  5968. enable_irq(bp->irq_tbl[i].vector);
  5969. }
  5970. }
  5971. #endif
  5972. static void __devinit
  5973. bnx2_get_5709_media(struct bnx2 *bp)
  5974. {
  5975. u32 val = REG_RD(bp, BNX2_MISC_DUAL_MEDIA_CTRL);
  5976. u32 bond_id = val & BNX2_MISC_DUAL_MEDIA_CTRL_BOND_ID;
  5977. u32 strap;
  5978. if (bond_id == BNX2_MISC_DUAL_MEDIA_CTRL_BOND_ID_C)
  5979. return;
  5980. else if (bond_id == BNX2_MISC_DUAL_MEDIA_CTRL_BOND_ID_S) {
  5981. bp->phy_flags |= BNX2_PHY_FLAG_SERDES;
  5982. return;
  5983. }
  5984. if (val & BNX2_MISC_DUAL_MEDIA_CTRL_STRAP_OVERRIDE)
  5985. strap = (val & BNX2_MISC_DUAL_MEDIA_CTRL_PHY_CTRL) >> 21;
  5986. else
  5987. strap = (val & BNX2_MISC_DUAL_MEDIA_CTRL_PHY_CTRL_STRAP) >> 8;
  5988. if (PCI_FUNC(bp->pdev->devfn) == 0) {
  5989. switch (strap) {
  5990. case 0x4:
  5991. case 0x5:
  5992. case 0x6:
  5993. bp->phy_flags |= BNX2_PHY_FLAG_SERDES;
  5994. return;
  5995. }
  5996. } else {
  5997. switch (strap) {
  5998. case 0x1:
  5999. case 0x2:
  6000. case 0x4:
  6001. bp->phy_flags |= BNX2_PHY_FLAG_SERDES;
  6002. return;
  6003. }
  6004. }
  6005. }
  6006. static void __devinit
  6007. bnx2_get_pci_speed(struct bnx2 *bp)
  6008. {
  6009. u32 reg;
  6010. reg = REG_RD(bp, BNX2_PCICFG_MISC_STATUS);
  6011. if (reg & BNX2_PCICFG_MISC_STATUS_PCIX_DET) {
  6012. u32 clkreg;
  6013. bp->flags |= BNX2_FLAG_PCIX;
  6014. clkreg = REG_RD(bp, BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS);
  6015. clkreg &= BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET;
  6016. switch (clkreg) {
  6017. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_133MHZ:
  6018. bp->bus_speed_mhz = 133;
  6019. break;
  6020. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_95MHZ:
  6021. bp->bus_speed_mhz = 100;
  6022. break;
  6023. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_66MHZ:
  6024. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_80MHZ:
  6025. bp->bus_speed_mhz = 66;
  6026. break;
  6027. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_48MHZ:
  6028. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_55MHZ:
  6029. bp->bus_speed_mhz = 50;
  6030. break;
  6031. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_LOW:
  6032. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_32MHZ:
  6033. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_38MHZ:
  6034. bp->bus_speed_mhz = 33;
  6035. break;
  6036. }
  6037. }
  6038. else {
  6039. if (reg & BNX2_PCICFG_MISC_STATUS_M66EN)
  6040. bp->bus_speed_mhz = 66;
  6041. else
  6042. bp->bus_speed_mhz = 33;
  6043. }
  6044. if (reg & BNX2_PCICFG_MISC_STATUS_32BIT_DET)
  6045. bp->flags |= BNX2_FLAG_PCI_32BIT;
  6046. }
  6047. static int __devinit
  6048. bnx2_init_board(struct pci_dev *pdev, struct net_device *dev)
  6049. {
  6050. struct bnx2 *bp;
  6051. unsigned long mem_len;
  6052. int rc, i, j;
  6053. u32 reg;
  6054. u64 dma_mask, persist_dma_mask;
  6055. SET_NETDEV_DEV(dev, &pdev->dev);
  6056. bp = netdev_priv(dev);
  6057. bp->flags = 0;
  6058. bp->phy_flags = 0;
  6059. /* enable device (incl. PCI PM wakeup), and bus-mastering */
  6060. rc = pci_enable_device(pdev);
  6061. if (rc) {
  6062. dev_err(&pdev->dev, "Cannot enable PCI device, aborting.\n");
  6063. goto err_out;
  6064. }
  6065. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  6066. dev_err(&pdev->dev,
  6067. "Cannot find PCI device base address, aborting.\n");
  6068. rc = -ENODEV;
  6069. goto err_out_disable;
  6070. }
  6071. rc = pci_request_regions(pdev, DRV_MODULE_NAME);
  6072. if (rc) {
  6073. dev_err(&pdev->dev, "Cannot obtain PCI resources, aborting.\n");
  6074. goto err_out_disable;
  6075. }
  6076. pci_set_master(pdev);
  6077. pci_save_state(pdev);
  6078. bp->pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
  6079. if (bp->pm_cap == 0) {
  6080. dev_err(&pdev->dev,
  6081. "Cannot find power management capability, aborting.\n");
  6082. rc = -EIO;
  6083. goto err_out_release;
  6084. }
  6085. bp->dev = dev;
  6086. bp->pdev = pdev;
  6087. spin_lock_init(&bp->phy_lock);
  6088. spin_lock_init(&bp->indirect_lock);
  6089. INIT_WORK(&bp->reset_task, bnx2_reset_task);
  6090. dev->base_addr = dev->mem_start = pci_resource_start(pdev, 0);
  6091. mem_len = MB_GET_CID_ADDR(TX_TSS_CID + TX_MAX_TSS_RINGS);
  6092. dev->mem_end = dev->mem_start + mem_len;
  6093. dev->irq = pdev->irq;
  6094. bp->regview = ioremap_nocache(dev->base_addr, mem_len);
  6095. if (!bp->regview) {
  6096. dev_err(&pdev->dev, "Cannot map register space, aborting.\n");
  6097. rc = -ENOMEM;
  6098. goto err_out_release;
  6099. }
  6100. /* Configure byte swap and enable write to the reg_window registers.
  6101. * Rely on CPU to do target byte swapping on big endian systems
  6102. * The chip's target access swapping will not swap all accesses
  6103. */
  6104. pci_write_config_dword(bp->pdev, BNX2_PCICFG_MISC_CONFIG,
  6105. BNX2_PCICFG_MISC_CONFIG_REG_WINDOW_ENA |
  6106. BNX2_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP);
  6107. bnx2_set_power_state(bp, PCI_D0);
  6108. bp->chip_id = REG_RD(bp, BNX2_MISC_ID);
  6109. if (CHIP_NUM(bp) == CHIP_NUM_5709) {
  6110. if (pci_find_capability(pdev, PCI_CAP_ID_EXP) == 0) {
  6111. dev_err(&pdev->dev,
  6112. "Cannot find PCIE capability, aborting.\n");
  6113. rc = -EIO;
  6114. goto err_out_unmap;
  6115. }
  6116. bp->flags |= BNX2_FLAG_PCIE;
  6117. if (CHIP_REV(bp) == CHIP_REV_Ax)
  6118. bp->flags |= BNX2_FLAG_JUMBO_BROKEN;
  6119. } else {
  6120. bp->pcix_cap = pci_find_capability(pdev, PCI_CAP_ID_PCIX);
  6121. if (bp->pcix_cap == 0) {
  6122. dev_err(&pdev->dev,
  6123. "Cannot find PCIX capability, aborting.\n");
  6124. rc = -EIO;
  6125. goto err_out_unmap;
  6126. }
  6127. }
  6128. if (CHIP_NUM(bp) == CHIP_NUM_5709 && CHIP_REV(bp) != CHIP_REV_Ax) {
  6129. if (pci_find_capability(pdev, PCI_CAP_ID_MSIX))
  6130. bp->flags |= BNX2_FLAG_MSIX_CAP;
  6131. }
  6132. if (CHIP_ID(bp) != CHIP_ID_5706_A0 && CHIP_ID(bp) != CHIP_ID_5706_A1) {
  6133. if (pci_find_capability(pdev, PCI_CAP_ID_MSI))
  6134. bp->flags |= BNX2_FLAG_MSI_CAP;
  6135. }
  6136. /* 5708 cannot support DMA addresses > 40-bit. */
  6137. if (CHIP_NUM(bp) == CHIP_NUM_5708)
  6138. persist_dma_mask = dma_mask = DMA_BIT_MASK(40);
  6139. else
  6140. persist_dma_mask = dma_mask = DMA_BIT_MASK(64);
  6141. /* Configure DMA attributes. */
  6142. if (pci_set_dma_mask(pdev, dma_mask) == 0) {
  6143. dev->features |= NETIF_F_HIGHDMA;
  6144. rc = pci_set_consistent_dma_mask(pdev, persist_dma_mask);
  6145. if (rc) {
  6146. dev_err(&pdev->dev,
  6147. "pci_set_consistent_dma_mask failed, aborting.\n");
  6148. goto err_out_unmap;
  6149. }
  6150. } else if ((rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) != 0) {
  6151. dev_err(&pdev->dev, "System does not support DMA, aborting.\n");
  6152. goto err_out_unmap;
  6153. }
  6154. if (!(bp->flags & BNX2_FLAG_PCIE))
  6155. bnx2_get_pci_speed(bp);
  6156. /* 5706A0 may falsely detect SERR and PERR. */
  6157. if (CHIP_ID(bp) == CHIP_ID_5706_A0) {
  6158. reg = REG_RD(bp, PCI_COMMAND);
  6159. reg &= ~(PCI_COMMAND_SERR | PCI_COMMAND_PARITY);
  6160. REG_WR(bp, PCI_COMMAND, reg);
  6161. }
  6162. else if ((CHIP_ID(bp) == CHIP_ID_5706_A1) &&
  6163. !(bp->flags & BNX2_FLAG_PCIX)) {
  6164. dev_err(&pdev->dev,
  6165. "5706 A1 can only be used in a PCIX bus, aborting.\n");
  6166. goto err_out_unmap;
  6167. }
  6168. bnx2_init_nvram(bp);
  6169. reg = bnx2_reg_rd_ind(bp, BNX2_SHM_HDR_SIGNATURE);
  6170. if ((reg & BNX2_SHM_HDR_SIGNATURE_SIG_MASK) ==
  6171. BNX2_SHM_HDR_SIGNATURE_SIG) {
  6172. u32 off = PCI_FUNC(pdev->devfn) << 2;
  6173. bp->shmem_base = bnx2_reg_rd_ind(bp, BNX2_SHM_HDR_ADDR_0 + off);
  6174. } else
  6175. bp->shmem_base = HOST_VIEW_SHMEM_BASE;
  6176. /* Get the permanent MAC address. First we need to make sure the
  6177. * firmware is actually running.
  6178. */
  6179. reg = bnx2_shmem_rd(bp, BNX2_DEV_INFO_SIGNATURE);
  6180. if ((reg & BNX2_DEV_INFO_SIGNATURE_MAGIC_MASK) !=
  6181. BNX2_DEV_INFO_SIGNATURE_MAGIC) {
  6182. dev_err(&pdev->dev, "Firmware not running, aborting.\n");
  6183. rc = -ENODEV;
  6184. goto err_out_unmap;
  6185. }
  6186. reg = bnx2_shmem_rd(bp, BNX2_DEV_INFO_BC_REV);
  6187. for (i = 0, j = 0; i < 3; i++) {
  6188. u8 num, k, skip0;
  6189. num = (u8) (reg >> (24 - (i * 8)));
  6190. for (k = 100, skip0 = 1; k >= 1; num %= k, k /= 10) {
  6191. if (num >= k || !skip0 || k == 1) {
  6192. bp->fw_version[j++] = (num / k) + '0';
  6193. skip0 = 0;
  6194. }
  6195. }
  6196. if (i != 2)
  6197. bp->fw_version[j++] = '.';
  6198. }
  6199. reg = bnx2_shmem_rd(bp, BNX2_PORT_FEATURE);
  6200. if (reg & BNX2_PORT_FEATURE_WOL_ENABLED)
  6201. bp->wol = 1;
  6202. if (reg & BNX2_PORT_FEATURE_ASF_ENABLED) {
  6203. bp->flags |= BNX2_FLAG_ASF_ENABLE;
  6204. for (i = 0; i < 30; i++) {
  6205. reg = bnx2_shmem_rd(bp, BNX2_BC_STATE_CONDITION);
  6206. if (reg & BNX2_CONDITION_MFW_RUN_MASK)
  6207. break;
  6208. msleep(10);
  6209. }
  6210. }
  6211. reg = bnx2_shmem_rd(bp, BNX2_BC_STATE_CONDITION);
  6212. reg &= BNX2_CONDITION_MFW_RUN_MASK;
  6213. if (reg != BNX2_CONDITION_MFW_RUN_UNKNOWN &&
  6214. reg != BNX2_CONDITION_MFW_RUN_NONE) {
  6215. u32 addr = bnx2_shmem_rd(bp, BNX2_MFW_VER_PTR);
  6216. bp->fw_version[j++] = ' ';
  6217. for (i = 0; i < 3; i++) {
  6218. reg = bnx2_reg_rd_ind(bp, addr + i * 4);
  6219. reg = swab32(reg);
  6220. memcpy(&bp->fw_version[j], &reg, 4);
  6221. j += 4;
  6222. }
  6223. }
  6224. reg = bnx2_shmem_rd(bp, BNX2_PORT_HW_CFG_MAC_UPPER);
  6225. bp->mac_addr[0] = (u8) (reg >> 8);
  6226. bp->mac_addr[1] = (u8) reg;
  6227. reg = bnx2_shmem_rd(bp, BNX2_PORT_HW_CFG_MAC_LOWER);
  6228. bp->mac_addr[2] = (u8) (reg >> 24);
  6229. bp->mac_addr[3] = (u8) (reg >> 16);
  6230. bp->mac_addr[4] = (u8) (reg >> 8);
  6231. bp->mac_addr[5] = (u8) reg;
  6232. bp->tx_ring_size = MAX_TX_DESC_CNT;
  6233. bnx2_set_rx_ring_size(bp, 255);
  6234. bp->rx_csum = 1;
  6235. bp->tx_quick_cons_trip_int = 20;
  6236. bp->tx_quick_cons_trip = 20;
  6237. bp->tx_ticks_int = 80;
  6238. bp->tx_ticks = 80;
  6239. bp->rx_quick_cons_trip_int = 6;
  6240. bp->rx_quick_cons_trip = 6;
  6241. bp->rx_ticks_int = 18;
  6242. bp->rx_ticks = 18;
  6243. bp->stats_ticks = USEC_PER_SEC & BNX2_HC_STATS_TICKS_HC_STAT_TICKS;
  6244. bp->current_interval = BNX2_TIMER_INTERVAL;
  6245. bp->phy_addr = 1;
  6246. /* Disable WOL support if we are running on a SERDES chip. */
  6247. if (CHIP_NUM(bp) == CHIP_NUM_5709)
  6248. bnx2_get_5709_media(bp);
  6249. else if (CHIP_BOND_ID(bp) & CHIP_BOND_ID_SERDES_BIT)
  6250. bp->phy_flags |= BNX2_PHY_FLAG_SERDES;
  6251. bp->phy_port = PORT_TP;
  6252. if (bp->phy_flags & BNX2_PHY_FLAG_SERDES) {
  6253. bp->phy_port = PORT_FIBRE;
  6254. reg = bnx2_shmem_rd(bp, BNX2_SHARED_HW_CFG_CONFIG);
  6255. if (!(reg & BNX2_SHARED_HW_CFG_GIG_LINK_ON_VAUX)) {
  6256. bp->flags |= BNX2_FLAG_NO_WOL;
  6257. bp->wol = 0;
  6258. }
  6259. if (CHIP_NUM(bp) == CHIP_NUM_5706) {
  6260. /* Don't do parallel detect on this board because of
  6261. * some board problems. The link will not go down
  6262. * if we do parallel detect.
  6263. */
  6264. if (pdev->subsystem_vendor == PCI_VENDOR_ID_HP &&
  6265. pdev->subsystem_device == 0x310c)
  6266. bp->phy_flags |= BNX2_PHY_FLAG_NO_PARALLEL;
  6267. } else {
  6268. bp->phy_addr = 2;
  6269. if (reg & BNX2_SHARED_HW_CFG_PHY_2_5G)
  6270. bp->phy_flags |= BNX2_PHY_FLAG_2_5G_CAPABLE;
  6271. }
  6272. } else if (CHIP_NUM(bp) == CHIP_NUM_5706 ||
  6273. CHIP_NUM(bp) == CHIP_NUM_5708)
  6274. bp->phy_flags |= BNX2_PHY_FLAG_CRC_FIX;
  6275. else if (CHIP_NUM(bp) == CHIP_NUM_5709 &&
  6276. (CHIP_REV(bp) == CHIP_REV_Ax ||
  6277. CHIP_REV(bp) == CHIP_REV_Bx))
  6278. bp->phy_flags |= BNX2_PHY_FLAG_DIS_EARLY_DAC;
  6279. bnx2_init_fw_cap(bp);
  6280. if ((CHIP_ID(bp) == CHIP_ID_5708_A0) ||
  6281. (CHIP_ID(bp) == CHIP_ID_5708_B0) ||
  6282. (CHIP_ID(bp) == CHIP_ID_5708_B1) ||
  6283. !(REG_RD(bp, BNX2_PCI_CONFIG_3) & BNX2_PCI_CONFIG_3_VAUX_PRESET)) {
  6284. bp->flags |= BNX2_FLAG_NO_WOL;
  6285. bp->wol = 0;
  6286. }
  6287. if (CHIP_ID(bp) == CHIP_ID_5706_A0) {
  6288. bp->tx_quick_cons_trip_int =
  6289. bp->tx_quick_cons_trip;
  6290. bp->tx_ticks_int = bp->tx_ticks;
  6291. bp->rx_quick_cons_trip_int =
  6292. bp->rx_quick_cons_trip;
  6293. bp->rx_ticks_int = bp->rx_ticks;
  6294. bp->comp_prod_trip_int = bp->comp_prod_trip;
  6295. bp->com_ticks_int = bp->com_ticks;
  6296. bp->cmd_ticks_int = bp->cmd_ticks;
  6297. }
  6298. /* Disable MSI on 5706 if AMD 8132 bridge is found.
  6299. *
  6300. * MSI is defined to be 32-bit write. The 5706 does 64-bit MSI writes
  6301. * with byte enables disabled on the unused 32-bit word. This is legal
  6302. * but causes problems on the AMD 8132 which will eventually stop
  6303. * responding after a while.
  6304. *
  6305. * AMD believes this incompatibility is unique to the 5706, and
  6306. * prefers to locally disable MSI rather than globally disabling it.
  6307. */
  6308. if (CHIP_NUM(bp) == CHIP_NUM_5706 && disable_msi == 0) {
  6309. struct pci_dev *amd_8132 = NULL;
  6310. while ((amd_8132 = pci_get_device(PCI_VENDOR_ID_AMD,
  6311. PCI_DEVICE_ID_AMD_8132_BRIDGE,
  6312. amd_8132))) {
  6313. if (amd_8132->revision >= 0x10 &&
  6314. amd_8132->revision <= 0x13) {
  6315. disable_msi = 1;
  6316. pci_dev_put(amd_8132);
  6317. break;
  6318. }
  6319. }
  6320. }
  6321. bnx2_set_default_link(bp);
  6322. bp->req_flow_ctrl = FLOW_CTRL_RX | FLOW_CTRL_TX;
  6323. init_timer(&bp->timer);
  6324. bp->timer.expires = RUN_AT(BNX2_TIMER_INTERVAL);
  6325. bp->timer.data = (unsigned long) bp;
  6326. bp->timer.function = bnx2_timer;
  6327. return 0;
  6328. err_out_unmap:
  6329. if (bp->regview) {
  6330. iounmap(bp->regview);
  6331. bp->regview = NULL;
  6332. }
  6333. err_out_release:
  6334. pci_release_regions(pdev);
  6335. err_out_disable:
  6336. pci_disable_device(pdev);
  6337. pci_set_drvdata(pdev, NULL);
  6338. err_out:
  6339. return rc;
  6340. }
  6341. static char * __devinit
  6342. bnx2_bus_string(struct bnx2 *bp, char *str)
  6343. {
  6344. char *s = str;
  6345. if (bp->flags & BNX2_FLAG_PCIE) {
  6346. s += sprintf(s, "PCI Express");
  6347. } else {
  6348. s += sprintf(s, "PCI");
  6349. if (bp->flags & BNX2_FLAG_PCIX)
  6350. s += sprintf(s, "-X");
  6351. if (bp->flags & BNX2_FLAG_PCI_32BIT)
  6352. s += sprintf(s, " 32-bit");
  6353. else
  6354. s += sprintf(s, " 64-bit");
  6355. s += sprintf(s, " %dMHz", bp->bus_speed_mhz);
  6356. }
  6357. return str;
  6358. }
  6359. static void __devinit
  6360. bnx2_init_napi(struct bnx2 *bp)
  6361. {
  6362. int i;
  6363. for (i = 0; i < BNX2_MAX_MSIX_VEC; i++) {
  6364. struct bnx2_napi *bnapi = &bp->bnx2_napi[i];
  6365. int (*poll)(struct napi_struct *, int);
  6366. if (i == 0)
  6367. poll = bnx2_poll;
  6368. else
  6369. poll = bnx2_poll_msix;
  6370. netif_napi_add(bp->dev, &bp->bnx2_napi[i].napi, poll, 64);
  6371. bnapi->bp = bp;
  6372. }
  6373. }
  6374. static const struct net_device_ops bnx2_netdev_ops = {
  6375. .ndo_open = bnx2_open,
  6376. .ndo_start_xmit = bnx2_start_xmit,
  6377. .ndo_stop = bnx2_close,
  6378. .ndo_get_stats = bnx2_get_stats,
  6379. .ndo_set_rx_mode = bnx2_set_rx_mode,
  6380. .ndo_do_ioctl = bnx2_ioctl,
  6381. .ndo_validate_addr = eth_validate_addr,
  6382. .ndo_set_mac_address = bnx2_change_mac_addr,
  6383. .ndo_change_mtu = bnx2_change_mtu,
  6384. .ndo_tx_timeout = bnx2_tx_timeout,
  6385. #ifdef BCM_VLAN
  6386. .ndo_vlan_rx_register = bnx2_vlan_rx_register,
  6387. #endif
  6388. #if defined(HAVE_POLL_CONTROLLER) || defined(CONFIG_NET_POLL_CONTROLLER)
  6389. .ndo_poll_controller = poll_bnx2,
  6390. #endif
  6391. };
  6392. static int __devinit
  6393. bnx2_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
  6394. {
  6395. static int version_printed = 0;
  6396. struct net_device *dev = NULL;
  6397. struct bnx2 *bp;
  6398. int rc;
  6399. char str[40];
  6400. if (version_printed++ == 0)
  6401. printk(KERN_INFO "%s", version);
  6402. /* dev zeroed in init_etherdev */
  6403. dev = alloc_etherdev_mq(sizeof(*bp), TX_MAX_RINGS);
  6404. if (!dev)
  6405. return -ENOMEM;
  6406. rc = bnx2_init_board(pdev, dev);
  6407. if (rc < 0) {
  6408. free_netdev(dev);
  6409. return rc;
  6410. }
  6411. dev->netdev_ops = &bnx2_netdev_ops;
  6412. dev->watchdog_timeo = TX_TIMEOUT;
  6413. dev->ethtool_ops = &bnx2_ethtool_ops;
  6414. bp = netdev_priv(dev);
  6415. bnx2_init_napi(bp);
  6416. pci_set_drvdata(pdev, dev);
  6417. rc = bnx2_request_firmware(bp);
  6418. if (rc)
  6419. goto error;
  6420. memcpy(dev->dev_addr, bp->mac_addr, 6);
  6421. memcpy(dev->perm_addr, bp->mac_addr, 6);
  6422. dev->features |= NETIF_F_IP_CSUM | NETIF_F_SG;
  6423. if (CHIP_NUM(bp) == CHIP_NUM_5709)
  6424. dev->features |= NETIF_F_IPV6_CSUM;
  6425. #ifdef BCM_VLAN
  6426. dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
  6427. #endif
  6428. dev->features |= NETIF_F_TSO | NETIF_F_TSO_ECN;
  6429. if (CHIP_NUM(bp) == CHIP_NUM_5709)
  6430. dev->features |= NETIF_F_TSO6;
  6431. if ((rc = register_netdev(dev))) {
  6432. dev_err(&pdev->dev, "Cannot register net device\n");
  6433. goto error;
  6434. }
  6435. printk(KERN_INFO "%s: %s (%c%d) %s found at mem %lx, "
  6436. "IRQ %d, node addr %pM\n",
  6437. dev->name,
  6438. board_info[ent->driver_data].name,
  6439. ((CHIP_ID(bp) & 0xf000) >> 12) + 'A',
  6440. ((CHIP_ID(bp) & 0x0ff0) >> 4),
  6441. bnx2_bus_string(bp, str),
  6442. dev->base_addr,
  6443. bp->pdev->irq, dev->dev_addr);
  6444. return 0;
  6445. error:
  6446. if (bp->mips_firmware)
  6447. release_firmware(bp->mips_firmware);
  6448. if (bp->rv2p_firmware)
  6449. release_firmware(bp->rv2p_firmware);
  6450. if (bp->regview)
  6451. iounmap(bp->regview);
  6452. pci_release_regions(pdev);
  6453. pci_disable_device(pdev);
  6454. pci_set_drvdata(pdev, NULL);
  6455. free_netdev(dev);
  6456. return rc;
  6457. }
  6458. static void __devexit
  6459. bnx2_remove_one(struct pci_dev *pdev)
  6460. {
  6461. struct net_device *dev = pci_get_drvdata(pdev);
  6462. struct bnx2 *bp = netdev_priv(dev);
  6463. flush_scheduled_work();
  6464. unregister_netdev(dev);
  6465. if (bp->mips_firmware)
  6466. release_firmware(bp->mips_firmware);
  6467. if (bp->rv2p_firmware)
  6468. release_firmware(bp->rv2p_firmware);
  6469. if (bp->regview)
  6470. iounmap(bp->regview);
  6471. free_netdev(dev);
  6472. pci_release_regions(pdev);
  6473. pci_disable_device(pdev);
  6474. pci_set_drvdata(pdev, NULL);
  6475. }
  6476. static int
  6477. bnx2_suspend(struct pci_dev *pdev, pm_message_t state)
  6478. {
  6479. struct net_device *dev = pci_get_drvdata(pdev);
  6480. struct bnx2 *bp = netdev_priv(dev);
  6481. /* PCI register 4 needs to be saved whether netif_running() or not.
  6482. * MSI address and data need to be saved if using MSI and
  6483. * netif_running().
  6484. */
  6485. pci_save_state(pdev);
  6486. if (!netif_running(dev))
  6487. return 0;
  6488. flush_scheduled_work();
  6489. bnx2_netif_stop(bp);
  6490. netif_device_detach(dev);
  6491. del_timer_sync(&bp->timer);
  6492. bnx2_shutdown_chip(bp);
  6493. bnx2_free_skbs(bp);
  6494. bnx2_set_power_state(bp, pci_choose_state(pdev, state));
  6495. return 0;
  6496. }
  6497. static int
  6498. bnx2_resume(struct pci_dev *pdev)
  6499. {
  6500. struct net_device *dev = pci_get_drvdata(pdev);
  6501. struct bnx2 *bp = netdev_priv(dev);
  6502. pci_restore_state(pdev);
  6503. if (!netif_running(dev))
  6504. return 0;
  6505. bnx2_set_power_state(bp, PCI_D0);
  6506. netif_device_attach(dev);
  6507. bnx2_init_nic(bp, 1);
  6508. bnx2_netif_start(bp);
  6509. return 0;
  6510. }
  6511. /**
  6512. * bnx2_io_error_detected - called when PCI error is detected
  6513. * @pdev: Pointer to PCI device
  6514. * @state: The current pci connection state
  6515. *
  6516. * This function is called after a PCI bus error affecting
  6517. * this device has been detected.
  6518. */
  6519. static pci_ers_result_t bnx2_io_error_detected(struct pci_dev *pdev,
  6520. pci_channel_state_t state)
  6521. {
  6522. struct net_device *dev = pci_get_drvdata(pdev);
  6523. struct bnx2 *bp = netdev_priv(dev);
  6524. rtnl_lock();
  6525. netif_device_detach(dev);
  6526. if (netif_running(dev)) {
  6527. bnx2_netif_stop(bp);
  6528. del_timer_sync(&bp->timer);
  6529. bnx2_reset_nic(bp, BNX2_DRV_MSG_CODE_RESET);
  6530. }
  6531. pci_disable_device(pdev);
  6532. rtnl_unlock();
  6533. /* Request a slot slot reset. */
  6534. return PCI_ERS_RESULT_NEED_RESET;
  6535. }
  6536. /**
  6537. * bnx2_io_slot_reset - called after the pci bus has been reset.
  6538. * @pdev: Pointer to PCI device
  6539. *
  6540. * Restart the card from scratch, as if from a cold-boot.
  6541. */
  6542. static pci_ers_result_t bnx2_io_slot_reset(struct pci_dev *pdev)
  6543. {
  6544. struct net_device *dev = pci_get_drvdata(pdev);
  6545. struct bnx2 *bp = netdev_priv(dev);
  6546. rtnl_lock();
  6547. if (pci_enable_device(pdev)) {
  6548. dev_err(&pdev->dev,
  6549. "Cannot re-enable PCI device after reset.\n");
  6550. rtnl_unlock();
  6551. return PCI_ERS_RESULT_DISCONNECT;
  6552. }
  6553. pci_set_master(pdev);
  6554. pci_restore_state(pdev);
  6555. if (netif_running(dev)) {
  6556. bnx2_set_power_state(bp, PCI_D0);
  6557. bnx2_init_nic(bp, 1);
  6558. }
  6559. rtnl_unlock();
  6560. return PCI_ERS_RESULT_RECOVERED;
  6561. }
  6562. /**
  6563. * bnx2_io_resume - called when traffic can start flowing again.
  6564. * @pdev: Pointer to PCI device
  6565. *
  6566. * This callback is called when the error recovery driver tells us that
  6567. * its OK to resume normal operation.
  6568. */
  6569. static void bnx2_io_resume(struct pci_dev *pdev)
  6570. {
  6571. struct net_device *dev = pci_get_drvdata(pdev);
  6572. struct bnx2 *bp = netdev_priv(dev);
  6573. rtnl_lock();
  6574. if (netif_running(dev))
  6575. bnx2_netif_start(bp);
  6576. netif_device_attach(dev);
  6577. rtnl_unlock();
  6578. }
  6579. static struct pci_error_handlers bnx2_err_handler = {
  6580. .error_detected = bnx2_io_error_detected,
  6581. .slot_reset = bnx2_io_slot_reset,
  6582. .resume = bnx2_io_resume,
  6583. };
  6584. static struct pci_driver bnx2_pci_driver = {
  6585. .name = DRV_MODULE_NAME,
  6586. .id_table = bnx2_pci_tbl,
  6587. .probe = bnx2_init_one,
  6588. .remove = __devexit_p(bnx2_remove_one),
  6589. .suspend = bnx2_suspend,
  6590. .resume = bnx2_resume,
  6591. .err_handler = &bnx2_err_handler,
  6592. };
  6593. static int __init bnx2_init(void)
  6594. {
  6595. return pci_register_driver(&bnx2_pci_driver);
  6596. }
  6597. static void __exit bnx2_cleanup(void)
  6598. {
  6599. pci_unregister_driver(&bnx2_pci_driver);
  6600. }
  6601. module_init(bnx2_init);
  6602. module_exit(bnx2_cleanup);