bnx2.c 192 KB

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