bnx2.c 134 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570
  1. /* bnx2.c: Broadcom NX2 network driver.
  2. *
  3. * Copyright (c) 2004, 2005 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 "bnx2.h"
  12. #include "bnx2_fw.h"
  13. #define DRV_MODULE_NAME "bnx2"
  14. #define PFX DRV_MODULE_NAME ": "
  15. #define DRV_MODULE_VERSION "1.2.19"
  16. #define DRV_MODULE_RELDATE "May 23, 2005"
  17. #define RUN_AT(x) (jiffies + (x))
  18. /* Time in jiffies before concluding the transmitter is hung. */
  19. #define TX_TIMEOUT (5*HZ)
  20. static char version[] __devinitdata =
  21. "Broadcom NetXtreme II Gigabit Ethernet Driver " DRV_MODULE_NAME " v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
  22. MODULE_AUTHOR("Michael Chan <mchan@broadcom.com>");
  23. MODULE_DESCRIPTION("Broadcom NetXtreme II BCM5706 Driver");
  24. MODULE_LICENSE("GPL");
  25. MODULE_VERSION(DRV_MODULE_VERSION);
  26. static int disable_msi = 0;
  27. module_param(disable_msi, int, 0);
  28. MODULE_PARM_DESC(disable_msi, "Disable Message Signaled Interrupt (MSI)");
  29. typedef enum {
  30. BCM5706 = 0,
  31. NC370T,
  32. NC370I,
  33. BCM5706S,
  34. NC370F,
  35. } board_t;
  36. /* indexed by board_t, above */
  37. static struct {
  38. char *name;
  39. } board_info[] __devinitdata = {
  40. { "Broadcom NetXtreme II BCM5706 1000Base-T" },
  41. { "HP NC370T Multifunction Gigabit Server Adapter" },
  42. { "HP NC370i Multifunction Gigabit Server Adapter" },
  43. { "Broadcom NetXtreme II BCM5706 1000Base-SX" },
  44. { "HP NC370F Multifunction Gigabit Server Adapter" },
  45. };
  46. static struct pci_device_id bnx2_pci_tbl[] = {
  47. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_5706,
  48. PCI_VENDOR_ID_HP, 0x3101, 0, 0, NC370T },
  49. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_5706,
  50. PCI_VENDOR_ID_HP, 0x3106, 0, 0, NC370I },
  51. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_5706,
  52. PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5706 },
  53. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_5706S,
  54. PCI_VENDOR_ID_HP, 0x3102, 0, 0, NC370F },
  55. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_5706S,
  56. PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5706S },
  57. { 0, }
  58. };
  59. static struct flash_spec flash_table[] =
  60. {
  61. /* Slow EEPROM */
  62. {0x00000000, 0x40030380, 0x009f0081, 0xa184a053, 0xaf000400,
  63. 1, SEEPROM_PAGE_BITS, SEEPROM_PAGE_SIZE,
  64. SEEPROM_BYTE_ADDR_MASK, SEEPROM_TOTAL_SIZE,
  65. "EEPROM - slow"},
  66. /* Fast EEPROM */
  67. {0x02000000, 0x62008380, 0x009f0081, 0xa184a053, 0xaf000400,
  68. 1, SEEPROM_PAGE_BITS, SEEPROM_PAGE_SIZE,
  69. SEEPROM_BYTE_ADDR_MASK, SEEPROM_TOTAL_SIZE,
  70. "EEPROM - fast"},
  71. /* ATMEL AT45DB011B (buffered flash) */
  72. {0x02000003, 0x6e008173, 0x00570081, 0x68848353, 0xaf000400,
  73. 1, BUFFERED_FLASH_PAGE_BITS, BUFFERED_FLASH_PAGE_SIZE,
  74. BUFFERED_FLASH_BYTE_ADDR_MASK, BUFFERED_FLASH_TOTAL_SIZE,
  75. "Buffered flash"},
  76. /* Saifun SA25F005 (non-buffered flash) */
  77. /* strap, cfg1, & write1 need updates */
  78. {0x01000003, 0x5f008081, 0x00050081, 0x03840253, 0xaf020406,
  79. 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
  80. SAIFUN_FLASH_BYTE_ADDR_MASK, SAIFUN_FLASH_BASE_TOTAL_SIZE,
  81. "Non-buffered flash (64kB)"},
  82. /* Saifun SA25F010 (non-buffered flash) */
  83. /* strap, cfg1, & write1 need updates */
  84. {0x00000001, 0x47008081, 0x00050081, 0x03840253, 0xaf020406,
  85. 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
  86. SAIFUN_FLASH_BYTE_ADDR_MASK, SAIFUN_FLASH_BASE_TOTAL_SIZE*2,
  87. "Non-buffered flash (128kB)"},
  88. /* Saifun SA25F020 (non-buffered flash) */
  89. /* strap, cfg1, & write1 need updates */
  90. {0x00000003, 0x4f008081, 0x00050081, 0x03840253, 0xaf020406,
  91. 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
  92. SAIFUN_FLASH_BYTE_ADDR_MASK, SAIFUN_FLASH_BASE_TOTAL_SIZE*4,
  93. "Non-buffered flash (256kB)"},
  94. };
  95. MODULE_DEVICE_TABLE(pci, bnx2_pci_tbl);
  96. static u32
  97. bnx2_reg_rd_ind(struct bnx2 *bp, u32 offset)
  98. {
  99. REG_WR(bp, BNX2_PCICFG_REG_WINDOW_ADDRESS, offset);
  100. return (REG_RD(bp, BNX2_PCICFG_REG_WINDOW));
  101. }
  102. static void
  103. bnx2_reg_wr_ind(struct bnx2 *bp, u32 offset, u32 val)
  104. {
  105. REG_WR(bp, BNX2_PCICFG_REG_WINDOW_ADDRESS, offset);
  106. REG_WR(bp, BNX2_PCICFG_REG_WINDOW, val);
  107. }
  108. static void
  109. bnx2_ctx_wr(struct bnx2 *bp, u32 cid_addr, u32 offset, u32 val)
  110. {
  111. offset += cid_addr;
  112. REG_WR(bp, BNX2_CTX_DATA_ADR, offset);
  113. REG_WR(bp, BNX2_CTX_DATA, val);
  114. }
  115. static int
  116. bnx2_read_phy(struct bnx2 *bp, u32 reg, u32 *val)
  117. {
  118. u32 val1;
  119. int i, ret;
  120. if (bp->phy_flags & PHY_INT_MODE_AUTO_POLLING_FLAG) {
  121. val1 = REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  122. val1 &= ~BNX2_EMAC_MDIO_MODE_AUTO_POLL;
  123. REG_WR(bp, BNX2_EMAC_MDIO_MODE, val1);
  124. REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  125. udelay(40);
  126. }
  127. val1 = (bp->phy_addr << 21) | (reg << 16) |
  128. BNX2_EMAC_MDIO_COMM_COMMAND_READ | BNX2_EMAC_MDIO_COMM_DISEXT |
  129. BNX2_EMAC_MDIO_COMM_START_BUSY;
  130. REG_WR(bp, BNX2_EMAC_MDIO_COMM, val1);
  131. for (i = 0; i < 50; i++) {
  132. udelay(10);
  133. val1 = REG_RD(bp, BNX2_EMAC_MDIO_COMM);
  134. if (!(val1 & BNX2_EMAC_MDIO_COMM_START_BUSY)) {
  135. udelay(5);
  136. val1 = REG_RD(bp, BNX2_EMAC_MDIO_COMM);
  137. val1 &= BNX2_EMAC_MDIO_COMM_DATA;
  138. break;
  139. }
  140. }
  141. if (val1 & BNX2_EMAC_MDIO_COMM_START_BUSY) {
  142. *val = 0x0;
  143. ret = -EBUSY;
  144. }
  145. else {
  146. *val = val1;
  147. ret = 0;
  148. }
  149. if (bp->phy_flags & PHY_INT_MODE_AUTO_POLLING_FLAG) {
  150. val1 = REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  151. val1 |= BNX2_EMAC_MDIO_MODE_AUTO_POLL;
  152. REG_WR(bp, BNX2_EMAC_MDIO_MODE, val1);
  153. REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  154. udelay(40);
  155. }
  156. return ret;
  157. }
  158. static int
  159. bnx2_write_phy(struct bnx2 *bp, u32 reg, u32 val)
  160. {
  161. u32 val1;
  162. int i, ret;
  163. if (bp->phy_flags & PHY_INT_MODE_AUTO_POLLING_FLAG) {
  164. val1 = REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  165. val1 &= ~BNX2_EMAC_MDIO_MODE_AUTO_POLL;
  166. REG_WR(bp, BNX2_EMAC_MDIO_MODE, val1);
  167. REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  168. udelay(40);
  169. }
  170. val1 = (bp->phy_addr << 21) | (reg << 16) | val |
  171. BNX2_EMAC_MDIO_COMM_COMMAND_WRITE |
  172. BNX2_EMAC_MDIO_COMM_START_BUSY | BNX2_EMAC_MDIO_COMM_DISEXT;
  173. REG_WR(bp, BNX2_EMAC_MDIO_COMM, val1);
  174. for (i = 0; i < 50; i++) {
  175. udelay(10);
  176. val1 = REG_RD(bp, BNX2_EMAC_MDIO_COMM);
  177. if (!(val1 & BNX2_EMAC_MDIO_COMM_START_BUSY)) {
  178. udelay(5);
  179. break;
  180. }
  181. }
  182. if (val1 & BNX2_EMAC_MDIO_COMM_START_BUSY)
  183. ret = -EBUSY;
  184. else
  185. ret = 0;
  186. if (bp->phy_flags & PHY_INT_MODE_AUTO_POLLING_FLAG) {
  187. val1 = REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  188. val1 |= BNX2_EMAC_MDIO_MODE_AUTO_POLL;
  189. REG_WR(bp, BNX2_EMAC_MDIO_MODE, val1);
  190. REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  191. udelay(40);
  192. }
  193. return ret;
  194. }
  195. static void
  196. bnx2_disable_int(struct bnx2 *bp)
  197. {
  198. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD,
  199. BNX2_PCICFG_INT_ACK_CMD_MASK_INT);
  200. REG_RD(bp, BNX2_PCICFG_INT_ACK_CMD);
  201. }
  202. static void
  203. bnx2_enable_int(struct bnx2 *bp)
  204. {
  205. u32 val;
  206. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD,
  207. BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID | bp->last_status_idx);
  208. val = REG_RD(bp, BNX2_HC_COMMAND);
  209. REG_WR(bp, BNX2_HC_COMMAND, val | BNX2_HC_COMMAND_COAL_NOW);
  210. }
  211. static void
  212. bnx2_disable_int_sync(struct bnx2 *bp)
  213. {
  214. atomic_inc(&bp->intr_sem);
  215. bnx2_disable_int(bp);
  216. synchronize_irq(bp->pdev->irq);
  217. }
  218. static void
  219. bnx2_netif_stop(struct bnx2 *bp)
  220. {
  221. bnx2_disable_int_sync(bp);
  222. if (netif_running(bp->dev)) {
  223. netif_poll_disable(bp->dev);
  224. netif_tx_disable(bp->dev);
  225. bp->dev->trans_start = jiffies; /* prevent tx timeout */
  226. }
  227. }
  228. static void
  229. bnx2_netif_start(struct bnx2 *bp)
  230. {
  231. if (atomic_dec_and_test(&bp->intr_sem)) {
  232. if (netif_running(bp->dev)) {
  233. netif_wake_queue(bp->dev);
  234. netif_poll_enable(bp->dev);
  235. bnx2_enable_int(bp);
  236. }
  237. }
  238. }
  239. static void
  240. bnx2_free_mem(struct bnx2 *bp)
  241. {
  242. if (bp->stats_blk) {
  243. pci_free_consistent(bp->pdev, sizeof(struct statistics_block),
  244. bp->stats_blk, bp->stats_blk_mapping);
  245. bp->stats_blk = NULL;
  246. }
  247. if (bp->status_blk) {
  248. pci_free_consistent(bp->pdev, sizeof(struct status_block),
  249. bp->status_blk, bp->status_blk_mapping);
  250. bp->status_blk = NULL;
  251. }
  252. if (bp->tx_desc_ring) {
  253. pci_free_consistent(bp->pdev,
  254. sizeof(struct tx_bd) * TX_DESC_CNT,
  255. bp->tx_desc_ring, bp->tx_desc_mapping);
  256. bp->tx_desc_ring = NULL;
  257. }
  258. if (bp->tx_buf_ring) {
  259. kfree(bp->tx_buf_ring);
  260. bp->tx_buf_ring = NULL;
  261. }
  262. if (bp->rx_desc_ring) {
  263. pci_free_consistent(bp->pdev,
  264. sizeof(struct rx_bd) * RX_DESC_CNT,
  265. bp->rx_desc_ring, bp->rx_desc_mapping);
  266. bp->rx_desc_ring = NULL;
  267. }
  268. if (bp->rx_buf_ring) {
  269. kfree(bp->rx_buf_ring);
  270. bp->rx_buf_ring = NULL;
  271. }
  272. }
  273. static int
  274. bnx2_alloc_mem(struct bnx2 *bp)
  275. {
  276. bp->tx_buf_ring = kmalloc(sizeof(struct sw_bd) * TX_DESC_CNT,
  277. GFP_KERNEL);
  278. if (bp->tx_buf_ring == NULL)
  279. return -ENOMEM;
  280. memset(bp->tx_buf_ring, 0, sizeof(struct sw_bd) * TX_DESC_CNT);
  281. bp->tx_desc_ring = pci_alloc_consistent(bp->pdev,
  282. sizeof(struct tx_bd) *
  283. TX_DESC_CNT,
  284. &bp->tx_desc_mapping);
  285. if (bp->tx_desc_ring == NULL)
  286. goto alloc_mem_err;
  287. bp->rx_buf_ring = kmalloc(sizeof(struct sw_bd) * RX_DESC_CNT,
  288. GFP_KERNEL);
  289. if (bp->rx_buf_ring == NULL)
  290. goto alloc_mem_err;
  291. memset(bp->rx_buf_ring, 0, sizeof(struct sw_bd) * RX_DESC_CNT);
  292. bp->rx_desc_ring = pci_alloc_consistent(bp->pdev,
  293. sizeof(struct rx_bd) *
  294. RX_DESC_CNT,
  295. &bp->rx_desc_mapping);
  296. if (bp->rx_desc_ring == NULL)
  297. goto alloc_mem_err;
  298. bp->status_blk = pci_alloc_consistent(bp->pdev,
  299. sizeof(struct status_block),
  300. &bp->status_blk_mapping);
  301. if (bp->status_blk == NULL)
  302. goto alloc_mem_err;
  303. memset(bp->status_blk, 0, sizeof(struct status_block));
  304. bp->stats_blk = pci_alloc_consistent(bp->pdev,
  305. sizeof(struct statistics_block),
  306. &bp->stats_blk_mapping);
  307. if (bp->stats_blk == NULL)
  308. goto alloc_mem_err;
  309. memset(bp->stats_blk, 0, sizeof(struct statistics_block));
  310. return 0;
  311. alloc_mem_err:
  312. bnx2_free_mem(bp);
  313. return -ENOMEM;
  314. }
  315. static void
  316. bnx2_report_link(struct bnx2 *bp)
  317. {
  318. if (bp->link_up) {
  319. netif_carrier_on(bp->dev);
  320. printk(KERN_INFO PFX "%s NIC Link is Up, ", bp->dev->name);
  321. printk("%d Mbps ", bp->line_speed);
  322. if (bp->duplex == DUPLEX_FULL)
  323. printk("full duplex");
  324. else
  325. printk("half duplex");
  326. if (bp->flow_ctrl) {
  327. if (bp->flow_ctrl & FLOW_CTRL_RX) {
  328. printk(", receive ");
  329. if (bp->flow_ctrl & FLOW_CTRL_TX)
  330. printk("& transmit ");
  331. }
  332. else {
  333. printk(", transmit ");
  334. }
  335. printk("flow control ON");
  336. }
  337. printk("\n");
  338. }
  339. else {
  340. netif_carrier_off(bp->dev);
  341. printk(KERN_ERR PFX "%s NIC Link is Down\n", bp->dev->name);
  342. }
  343. }
  344. static void
  345. bnx2_resolve_flow_ctrl(struct bnx2 *bp)
  346. {
  347. u32 local_adv, remote_adv;
  348. bp->flow_ctrl = 0;
  349. if ((bp->autoneg & (AUTONEG_SPEED | AUTONEG_FLOW_CTRL)) !=
  350. (AUTONEG_SPEED | AUTONEG_FLOW_CTRL)) {
  351. if (bp->duplex == DUPLEX_FULL) {
  352. bp->flow_ctrl = bp->req_flow_ctrl;
  353. }
  354. return;
  355. }
  356. if (bp->duplex != DUPLEX_FULL) {
  357. return;
  358. }
  359. bnx2_read_phy(bp, MII_ADVERTISE, &local_adv);
  360. bnx2_read_phy(bp, MII_LPA, &remote_adv);
  361. if (bp->phy_flags & PHY_SERDES_FLAG) {
  362. u32 new_local_adv = 0;
  363. u32 new_remote_adv = 0;
  364. if (local_adv & ADVERTISE_1000XPAUSE)
  365. new_local_adv |= ADVERTISE_PAUSE_CAP;
  366. if (local_adv & ADVERTISE_1000XPSE_ASYM)
  367. new_local_adv |= ADVERTISE_PAUSE_ASYM;
  368. if (remote_adv & ADVERTISE_1000XPAUSE)
  369. new_remote_adv |= ADVERTISE_PAUSE_CAP;
  370. if (remote_adv & ADVERTISE_1000XPSE_ASYM)
  371. new_remote_adv |= ADVERTISE_PAUSE_ASYM;
  372. local_adv = new_local_adv;
  373. remote_adv = new_remote_adv;
  374. }
  375. /* See Table 28B-3 of 802.3ab-1999 spec. */
  376. if (local_adv & ADVERTISE_PAUSE_CAP) {
  377. if(local_adv & ADVERTISE_PAUSE_ASYM) {
  378. if (remote_adv & ADVERTISE_PAUSE_CAP) {
  379. bp->flow_ctrl = FLOW_CTRL_TX | FLOW_CTRL_RX;
  380. }
  381. else if (remote_adv & ADVERTISE_PAUSE_ASYM) {
  382. bp->flow_ctrl = FLOW_CTRL_RX;
  383. }
  384. }
  385. else {
  386. if (remote_adv & ADVERTISE_PAUSE_CAP) {
  387. bp->flow_ctrl = FLOW_CTRL_TX | FLOW_CTRL_RX;
  388. }
  389. }
  390. }
  391. else if (local_adv & ADVERTISE_PAUSE_ASYM) {
  392. if ((remote_adv & ADVERTISE_PAUSE_CAP) &&
  393. (remote_adv & ADVERTISE_PAUSE_ASYM)) {
  394. bp->flow_ctrl = FLOW_CTRL_TX;
  395. }
  396. }
  397. }
  398. static int
  399. bnx2_serdes_linkup(struct bnx2 *bp)
  400. {
  401. u32 bmcr, local_adv, remote_adv, common;
  402. bp->link_up = 1;
  403. bp->line_speed = SPEED_1000;
  404. bnx2_read_phy(bp, MII_BMCR, &bmcr);
  405. if (bmcr & BMCR_FULLDPLX) {
  406. bp->duplex = DUPLEX_FULL;
  407. }
  408. else {
  409. bp->duplex = DUPLEX_HALF;
  410. }
  411. if (!(bmcr & BMCR_ANENABLE)) {
  412. return 0;
  413. }
  414. bnx2_read_phy(bp, MII_ADVERTISE, &local_adv);
  415. bnx2_read_phy(bp, MII_LPA, &remote_adv);
  416. common = local_adv & remote_adv;
  417. if (common & (ADVERTISE_1000XHALF | ADVERTISE_1000XFULL)) {
  418. if (common & ADVERTISE_1000XFULL) {
  419. bp->duplex = DUPLEX_FULL;
  420. }
  421. else {
  422. bp->duplex = DUPLEX_HALF;
  423. }
  424. }
  425. return 0;
  426. }
  427. static int
  428. bnx2_copper_linkup(struct bnx2 *bp)
  429. {
  430. u32 bmcr;
  431. bnx2_read_phy(bp, MII_BMCR, &bmcr);
  432. if (bmcr & BMCR_ANENABLE) {
  433. u32 local_adv, remote_adv, common;
  434. bnx2_read_phy(bp, MII_CTRL1000, &local_adv);
  435. bnx2_read_phy(bp, MII_STAT1000, &remote_adv);
  436. common = local_adv & (remote_adv >> 2);
  437. if (common & ADVERTISE_1000FULL) {
  438. bp->line_speed = SPEED_1000;
  439. bp->duplex = DUPLEX_FULL;
  440. }
  441. else if (common & ADVERTISE_1000HALF) {
  442. bp->line_speed = SPEED_1000;
  443. bp->duplex = DUPLEX_HALF;
  444. }
  445. else {
  446. bnx2_read_phy(bp, MII_ADVERTISE, &local_adv);
  447. bnx2_read_phy(bp, MII_LPA, &remote_adv);
  448. common = local_adv & remote_adv;
  449. if (common & ADVERTISE_100FULL) {
  450. bp->line_speed = SPEED_100;
  451. bp->duplex = DUPLEX_FULL;
  452. }
  453. else if (common & ADVERTISE_100HALF) {
  454. bp->line_speed = SPEED_100;
  455. bp->duplex = DUPLEX_HALF;
  456. }
  457. else if (common & ADVERTISE_10FULL) {
  458. bp->line_speed = SPEED_10;
  459. bp->duplex = DUPLEX_FULL;
  460. }
  461. else if (common & ADVERTISE_10HALF) {
  462. bp->line_speed = SPEED_10;
  463. bp->duplex = DUPLEX_HALF;
  464. }
  465. else {
  466. bp->line_speed = 0;
  467. bp->link_up = 0;
  468. }
  469. }
  470. }
  471. else {
  472. if (bmcr & BMCR_SPEED100) {
  473. bp->line_speed = SPEED_100;
  474. }
  475. else {
  476. bp->line_speed = SPEED_10;
  477. }
  478. if (bmcr & BMCR_FULLDPLX) {
  479. bp->duplex = DUPLEX_FULL;
  480. }
  481. else {
  482. bp->duplex = DUPLEX_HALF;
  483. }
  484. }
  485. return 0;
  486. }
  487. static int
  488. bnx2_set_mac_link(struct bnx2 *bp)
  489. {
  490. u32 val;
  491. REG_WR(bp, BNX2_EMAC_TX_LENGTHS, 0x2620);
  492. if (bp->link_up && (bp->line_speed == SPEED_1000) &&
  493. (bp->duplex == DUPLEX_HALF)) {
  494. REG_WR(bp, BNX2_EMAC_TX_LENGTHS, 0x26ff);
  495. }
  496. /* Configure the EMAC mode register. */
  497. val = REG_RD(bp, BNX2_EMAC_MODE);
  498. val &= ~(BNX2_EMAC_MODE_PORT | BNX2_EMAC_MODE_HALF_DUPLEX |
  499. BNX2_EMAC_MODE_MAC_LOOP | BNX2_EMAC_MODE_FORCE_LINK);
  500. if (bp->link_up) {
  501. if (bp->line_speed != SPEED_1000)
  502. val |= BNX2_EMAC_MODE_PORT_MII;
  503. else
  504. val |= BNX2_EMAC_MODE_PORT_GMII;
  505. }
  506. else {
  507. val |= BNX2_EMAC_MODE_PORT_GMII;
  508. }
  509. /* Set the MAC to operate in the appropriate duplex mode. */
  510. if (bp->duplex == DUPLEX_HALF)
  511. val |= BNX2_EMAC_MODE_HALF_DUPLEX;
  512. REG_WR(bp, BNX2_EMAC_MODE, val);
  513. /* Enable/disable rx PAUSE. */
  514. bp->rx_mode &= ~BNX2_EMAC_RX_MODE_FLOW_EN;
  515. if (bp->flow_ctrl & FLOW_CTRL_RX)
  516. bp->rx_mode |= BNX2_EMAC_RX_MODE_FLOW_EN;
  517. REG_WR(bp, BNX2_EMAC_RX_MODE, bp->rx_mode);
  518. /* Enable/disable tx PAUSE. */
  519. val = REG_RD(bp, BNX2_EMAC_TX_MODE);
  520. val &= ~BNX2_EMAC_TX_MODE_FLOW_EN;
  521. if (bp->flow_ctrl & FLOW_CTRL_TX)
  522. val |= BNX2_EMAC_TX_MODE_FLOW_EN;
  523. REG_WR(bp, BNX2_EMAC_TX_MODE, val);
  524. /* Acknowledge the interrupt. */
  525. REG_WR(bp, BNX2_EMAC_STATUS, BNX2_EMAC_STATUS_LINK_CHANGE);
  526. return 0;
  527. }
  528. static int
  529. bnx2_set_link(struct bnx2 *bp)
  530. {
  531. u32 bmsr;
  532. u8 link_up;
  533. if (bp->loopback == MAC_LOOPBACK) {
  534. bp->link_up = 1;
  535. return 0;
  536. }
  537. link_up = bp->link_up;
  538. bnx2_read_phy(bp, MII_BMSR, &bmsr);
  539. bnx2_read_phy(bp, MII_BMSR, &bmsr);
  540. if ((bp->phy_flags & PHY_SERDES_FLAG) &&
  541. (CHIP_NUM(bp) == CHIP_NUM_5706)) {
  542. u32 val;
  543. val = REG_RD(bp, BNX2_EMAC_STATUS);
  544. if (val & BNX2_EMAC_STATUS_LINK)
  545. bmsr |= BMSR_LSTATUS;
  546. else
  547. bmsr &= ~BMSR_LSTATUS;
  548. }
  549. if (bmsr & BMSR_LSTATUS) {
  550. bp->link_up = 1;
  551. if (bp->phy_flags & PHY_SERDES_FLAG) {
  552. bnx2_serdes_linkup(bp);
  553. }
  554. else {
  555. bnx2_copper_linkup(bp);
  556. }
  557. bnx2_resolve_flow_ctrl(bp);
  558. }
  559. else {
  560. if ((bp->phy_flags & PHY_SERDES_FLAG) &&
  561. (bp->autoneg & AUTONEG_SPEED)) {
  562. u32 bmcr;
  563. bnx2_read_phy(bp, MII_BMCR, &bmcr);
  564. if (!(bmcr & BMCR_ANENABLE)) {
  565. bnx2_write_phy(bp, MII_BMCR, bmcr |
  566. BMCR_ANENABLE);
  567. }
  568. }
  569. bp->phy_flags &= ~PHY_PARALLEL_DETECT_FLAG;
  570. bp->link_up = 0;
  571. }
  572. if (bp->link_up != link_up) {
  573. bnx2_report_link(bp);
  574. }
  575. bnx2_set_mac_link(bp);
  576. return 0;
  577. }
  578. static int
  579. bnx2_reset_phy(struct bnx2 *bp)
  580. {
  581. int i;
  582. u32 reg;
  583. bnx2_write_phy(bp, MII_BMCR, BMCR_RESET);
  584. #define PHY_RESET_MAX_WAIT 100
  585. for (i = 0; i < PHY_RESET_MAX_WAIT; i++) {
  586. udelay(10);
  587. bnx2_read_phy(bp, MII_BMCR, &reg);
  588. if (!(reg & BMCR_RESET)) {
  589. udelay(20);
  590. break;
  591. }
  592. }
  593. if (i == PHY_RESET_MAX_WAIT) {
  594. return -EBUSY;
  595. }
  596. return 0;
  597. }
  598. static u32
  599. bnx2_phy_get_pause_adv(struct bnx2 *bp)
  600. {
  601. u32 adv = 0;
  602. if ((bp->req_flow_ctrl & (FLOW_CTRL_RX | FLOW_CTRL_TX)) ==
  603. (FLOW_CTRL_RX | FLOW_CTRL_TX)) {
  604. if (bp->phy_flags & PHY_SERDES_FLAG) {
  605. adv = ADVERTISE_1000XPAUSE;
  606. }
  607. else {
  608. adv = ADVERTISE_PAUSE_CAP;
  609. }
  610. }
  611. else if (bp->req_flow_ctrl & FLOW_CTRL_TX) {
  612. if (bp->phy_flags & PHY_SERDES_FLAG) {
  613. adv = ADVERTISE_1000XPSE_ASYM;
  614. }
  615. else {
  616. adv = ADVERTISE_PAUSE_ASYM;
  617. }
  618. }
  619. else if (bp->req_flow_ctrl & FLOW_CTRL_RX) {
  620. if (bp->phy_flags & PHY_SERDES_FLAG) {
  621. adv = ADVERTISE_1000XPAUSE | ADVERTISE_1000XPSE_ASYM;
  622. }
  623. else {
  624. adv = ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
  625. }
  626. }
  627. return adv;
  628. }
  629. static int
  630. bnx2_setup_serdes_phy(struct bnx2 *bp)
  631. {
  632. u32 adv, bmcr;
  633. u32 new_adv = 0;
  634. if (!(bp->autoneg & AUTONEG_SPEED)) {
  635. u32 new_bmcr;
  636. bnx2_read_phy(bp, MII_BMCR, &bmcr);
  637. new_bmcr = bmcr & ~BMCR_ANENABLE;
  638. new_bmcr |= BMCR_SPEED1000;
  639. if (bp->req_duplex == DUPLEX_FULL) {
  640. new_bmcr |= BMCR_FULLDPLX;
  641. }
  642. else {
  643. new_bmcr &= ~BMCR_FULLDPLX;
  644. }
  645. if (new_bmcr != bmcr) {
  646. /* Force a link down visible on the other side */
  647. if (bp->link_up) {
  648. bnx2_read_phy(bp, MII_ADVERTISE, &adv);
  649. adv &= ~(ADVERTISE_1000XFULL |
  650. ADVERTISE_1000XHALF);
  651. bnx2_write_phy(bp, MII_ADVERTISE, adv);
  652. bnx2_write_phy(bp, MII_BMCR, bmcr |
  653. BMCR_ANRESTART | BMCR_ANENABLE);
  654. bp->link_up = 0;
  655. netif_carrier_off(bp->dev);
  656. }
  657. bnx2_write_phy(bp, MII_BMCR, new_bmcr);
  658. }
  659. return 0;
  660. }
  661. if (bp->advertising & ADVERTISED_1000baseT_Full)
  662. new_adv |= ADVERTISE_1000XFULL;
  663. new_adv |= bnx2_phy_get_pause_adv(bp);
  664. bnx2_read_phy(bp, MII_ADVERTISE, &adv);
  665. bnx2_read_phy(bp, MII_BMCR, &bmcr);
  666. bp->serdes_an_pending = 0;
  667. if ((adv != new_adv) || ((bmcr & BMCR_ANENABLE) == 0)) {
  668. /* Force a link down visible on the other side */
  669. if (bp->link_up) {
  670. int i;
  671. bnx2_write_phy(bp, MII_BMCR, BMCR_LOOPBACK);
  672. for (i = 0; i < 110; i++) {
  673. udelay(100);
  674. }
  675. }
  676. bnx2_write_phy(bp, MII_ADVERTISE, new_adv);
  677. bnx2_write_phy(bp, MII_BMCR, bmcr | BMCR_ANRESTART |
  678. BMCR_ANENABLE);
  679. if (CHIP_NUM(bp) == CHIP_NUM_5706) {
  680. /* Speed up link-up time when the link partner
  681. * does not autonegotiate which is very common
  682. * in blade servers. Some blade servers use
  683. * IPMI for kerboard input and it's important
  684. * to minimize link disruptions. Autoneg. involves
  685. * exchanging base pages plus 3 next pages and
  686. * normally completes in about 120 msec.
  687. */
  688. bp->current_interval = SERDES_AN_TIMEOUT;
  689. bp->serdes_an_pending = 1;
  690. mod_timer(&bp->timer, jiffies + bp->current_interval);
  691. }
  692. }
  693. return 0;
  694. }
  695. #define ETHTOOL_ALL_FIBRE_SPEED \
  696. (ADVERTISED_1000baseT_Full)
  697. #define ETHTOOL_ALL_COPPER_SPEED \
  698. (ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full | \
  699. ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full | \
  700. ADVERTISED_1000baseT_Full)
  701. #define PHY_ALL_10_100_SPEED (ADVERTISE_10HALF | ADVERTISE_10FULL | \
  702. ADVERTISE_100HALF | ADVERTISE_100FULL | ADVERTISE_CSMA)
  703. #define PHY_ALL_1000_SPEED (ADVERTISE_1000HALF | ADVERTISE_1000FULL)
  704. static int
  705. bnx2_setup_copper_phy(struct bnx2 *bp)
  706. {
  707. u32 bmcr;
  708. u32 new_bmcr;
  709. bnx2_read_phy(bp, MII_BMCR, &bmcr);
  710. if (bp->autoneg & AUTONEG_SPEED) {
  711. u32 adv_reg, adv1000_reg;
  712. u32 new_adv_reg = 0;
  713. u32 new_adv1000_reg = 0;
  714. bnx2_read_phy(bp, MII_ADVERTISE, &adv_reg);
  715. adv_reg &= (PHY_ALL_10_100_SPEED | ADVERTISE_PAUSE_CAP |
  716. ADVERTISE_PAUSE_ASYM);
  717. bnx2_read_phy(bp, MII_CTRL1000, &adv1000_reg);
  718. adv1000_reg &= PHY_ALL_1000_SPEED;
  719. if (bp->advertising & ADVERTISED_10baseT_Half)
  720. new_adv_reg |= ADVERTISE_10HALF;
  721. if (bp->advertising & ADVERTISED_10baseT_Full)
  722. new_adv_reg |= ADVERTISE_10FULL;
  723. if (bp->advertising & ADVERTISED_100baseT_Half)
  724. new_adv_reg |= ADVERTISE_100HALF;
  725. if (bp->advertising & ADVERTISED_100baseT_Full)
  726. new_adv_reg |= ADVERTISE_100FULL;
  727. if (bp->advertising & ADVERTISED_1000baseT_Full)
  728. new_adv1000_reg |= ADVERTISE_1000FULL;
  729. new_adv_reg |= ADVERTISE_CSMA;
  730. new_adv_reg |= bnx2_phy_get_pause_adv(bp);
  731. if ((adv1000_reg != new_adv1000_reg) ||
  732. (adv_reg != new_adv_reg) ||
  733. ((bmcr & BMCR_ANENABLE) == 0)) {
  734. bnx2_write_phy(bp, MII_ADVERTISE, new_adv_reg);
  735. bnx2_write_phy(bp, MII_CTRL1000, new_adv1000_reg);
  736. bnx2_write_phy(bp, MII_BMCR, BMCR_ANRESTART |
  737. BMCR_ANENABLE);
  738. }
  739. else if (bp->link_up) {
  740. /* Flow ctrl may have changed from auto to forced */
  741. /* or vice-versa. */
  742. bnx2_resolve_flow_ctrl(bp);
  743. bnx2_set_mac_link(bp);
  744. }
  745. return 0;
  746. }
  747. new_bmcr = 0;
  748. if (bp->req_line_speed == SPEED_100) {
  749. new_bmcr |= BMCR_SPEED100;
  750. }
  751. if (bp->req_duplex == DUPLEX_FULL) {
  752. new_bmcr |= BMCR_FULLDPLX;
  753. }
  754. if (new_bmcr != bmcr) {
  755. u32 bmsr;
  756. int i = 0;
  757. bnx2_read_phy(bp, MII_BMSR, &bmsr);
  758. bnx2_read_phy(bp, MII_BMSR, &bmsr);
  759. if (bmsr & BMSR_LSTATUS) {
  760. /* Force link down */
  761. bnx2_write_phy(bp, MII_BMCR, BMCR_LOOPBACK);
  762. do {
  763. udelay(100);
  764. bnx2_read_phy(bp, MII_BMSR, &bmsr);
  765. bnx2_read_phy(bp, MII_BMSR, &bmsr);
  766. i++;
  767. } while ((bmsr & BMSR_LSTATUS) && (i < 620));
  768. }
  769. bnx2_write_phy(bp, MII_BMCR, new_bmcr);
  770. /* Normally, the new speed is setup after the link has
  771. * gone down and up again. In some cases, link will not go
  772. * down so we need to set up the new speed here.
  773. */
  774. if (bmsr & BMSR_LSTATUS) {
  775. bp->line_speed = bp->req_line_speed;
  776. bp->duplex = bp->req_duplex;
  777. bnx2_resolve_flow_ctrl(bp);
  778. bnx2_set_mac_link(bp);
  779. }
  780. }
  781. return 0;
  782. }
  783. static int
  784. bnx2_setup_phy(struct bnx2 *bp)
  785. {
  786. if (bp->loopback == MAC_LOOPBACK)
  787. return 0;
  788. if (bp->phy_flags & PHY_SERDES_FLAG) {
  789. return (bnx2_setup_serdes_phy(bp));
  790. }
  791. else {
  792. return (bnx2_setup_copper_phy(bp));
  793. }
  794. }
  795. static int
  796. bnx2_init_serdes_phy(struct bnx2 *bp)
  797. {
  798. bp->phy_flags &= ~PHY_PARALLEL_DETECT_FLAG;
  799. if (CHIP_NUM(bp) == CHIP_NUM_5706) {
  800. REG_WR(bp, BNX2_MISC_UNUSED0, 0x300);
  801. }
  802. if (bp->dev->mtu > 1500) {
  803. u32 val;
  804. /* Set extended packet length bit */
  805. bnx2_write_phy(bp, 0x18, 0x7);
  806. bnx2_read_phy(bp, 0x18, &val);
  807. bnx2_write_phy(bp, 0x18, (val & 0xfff8) | 0x4000);
  808. bnx2_write_phy(bp, 0x1c, 0x6c00);
  809. bnx2_read_phy(bp, 0x1c, &val);
  810. bnx2_write_phy(bp, 0x1c, (val & 0x3ff) | 0xec02);
  811. }
  812. else {
  813. u32 val;
  814. bnx2_write_phy(bp, 0x18, 0x7);
  815. bnx2_read_phy(bp, 0x18, &val);
  816. bnx2_write_phy(bp, 0x18, val & ~0x4007);
  817. bnx2_write_phy(bp, 0x1c, 0x6c00);
  818. bnx2_read_phy(bp, 0x1c, &val);
  819. bnx2_write_phy(bp, 0x1c, (val & 0x3fd) | 0xec00);
  820. }
  821. return 0;
  822. }
  823. static int
  824. bnx2_init_copper_phy(struct bnx2 *bp)
  825. {
  826. bp->phy_flags |= PHY_CRC_FIX_FLAG;
  827. if (bp->phy_flags & PHY_CRC_FIX_FLAG) {
  828. bnx2_write_phy(bp, 0x18, 0x0c00);
  829. bnx2_write_phy(bp, 0x17, 0x000a);
  830. bnx2_write_phy(bp, 0x15, 0x310b);
  831. bnx2_write_phy(bp, 0x17, 0x201f);
  832. bnx2_write_phy(bp, 0x15, 0x9506);
  833. bnx2_write_phy(bp, 0x17, 0x401f);
  834. bnx2_write_phy(bp, 0x15, 0x14e2);
  835. bnx2_write_phy(bp, 0x18, 0x0400);
  836. }
  837. if (bp->dev->mtu > 1500) {
  838. u32 val;
  839. /* Set extended packet length bit */
  840. bnx2_write_phy(bp, 0x18, 0x7);
  841. bnx2_read_phy(bp, 0x18, &val);
  842. bnx2_write_phy(bp, 0x18, val | 0x4000);
  843. bnx2_read_phy(bp, 0x10, &val);
  844. bnx2_write_phy(bp, 0x10, val | 0x1);
  845. }
  846. else {
  847. u32 val;
  848. bnx2_write_phy(bp, 0x18, 0x7);
  849. bnx2_read_phy(bp, 0x18, &val);
  850. bnx2_write_phy(bp, 0x18, val & ~0x4007);
  851. bnx2_read_phy(bp, 0x10, &val);
  852. bnx2_write_phy(bp, 0x10, val & ~0x1);
  853. }
  854. return 0;
  855. }
  856. static int
  857. bnx2_init_phy(struct bnx2 *bp)
  858. {
  859. u32 val;
  860. int rc = 0;
  861. bp->phy_flags &= ~PHY_INT_MODE_MASK_FLAG;
  862. bp->phy_flags |= PHY_INT_MODE_LINK_READY_FLAG;
  863. REG_WR(bp, BNX2_EMAC_ATTENTION_ENA, BNX2_EMAC_ATTENTION_ENA_LINK);
  864. bnx2_reset_phy(bp);
  865. bnx2_read_phy(bp, MII_PHYSID1, &val);
  866. bp->phy_id = val << 16;
  867. bnx2_read_phy(bp, MII_PHYSID2, &val);
  868. bp->phy_id |= val & 0xffff;
  869. if (bp->phy_flags & PHY_SERDES_FLAG) {
  870. rc = bnx2_init_serdes_phy(bp);
  871. }
  872. else {
  873. rc = bnx2_init_copper_phy(bp);
  874. }
  875. bnx2_setup_phy(bp);
  876. return rc;
  877. }
  878. static int
  879. bnx2_set_mac_loopback(struct bnx2 *bp)
  880. {
  881. u32 mac_mode;
  882. mac_mode = REG_RD(bp, BNX2_EMAC_MODE);
  883. mac_mode &= ~BNX2_EMAC_MODE_PORT;
  884. mac_mode |= BNX2_EMAC_MODE_MAC_LOOP | BNX2_EMAC_MODE_FORCE_LINK;
  885. REG_WR(bp, BNX2_EMAC_MODE, mac_mode);
  886. bp->link_up = 1;
  887. return 0;
  888. }
  889. static int
  890. bnx2_fw_sync(struct bnx2 *bp, u32 msg_data)
  891. {
  892. int i;
  893. u32 val;
  894. if (bp->fw_timed_out)
  895. return -EBUSY;
  896. bp->fw_wr_seq++;
  897. msg_data |= bp->fw_wr_seq;
  898. REG_WR_IND(bp, HOST_VIEW_SHMEM_BASE + BNX2_DRV_MB, msg_data);
  899. /* wait for an acknowledgement. */
  900. for (i = 0; i < (FW_ACK_TIME_OUT_MS * 1000)/5; i++) {
  901. udelay(5);
  902. val = REG_RD_IND(bp, HOST_VIEW_SHMEM_BASE + BNX2_FW_MB);
  903. if ((val & BNX2_FW_MSG_ACK) == (msg_data & BNX2_DRV_MSG_SEQ))
  904. break;
  905. }
  906. /* If we timed out, inform the firmware that this is the case. */
  907. if (((val & BNX2_FW_MSG_ACK) != (msg_data & BNX2_DRV_MSG_SEQ)) &&
  908. ((msg_data & BNX2_DRV_MSG_DATA) != BNX2_DRV_MSG_DATA_WAIT0)) {
  909. msg_data &= ~BNX2_DRV_MSG_CODE;
  910. msg_data |= BNX2_DRV_MSG_CODE_FW_TIMEOUT;
  911. REG_WR_IND(bp, HOST_VIEW_SHMEM_BASE + BNX2_DRV_MB, msg_data);
  912. bp->fw_timed_out = 1;
  913. return -EBUSY;
  914. }
  915. return 0;
  916. }
  917. static void
  918. bnx2_init_context(struct bnx2 *bp)
  919. {
  920. u32 vcid;
  921. vcid = 96;
  922. while (vcid) {
  923. u32 vcid_addr, pcid_addr, offset;
  924. vcid--;
  925. if (CHIP_ID(bp) == CHIP_ID_5706_A0) {
  926. u32 new_vcid;
  927. vcid_addr = GET_PCID_ADDR(vcid);
  928. if (vcid & 0x8) {
  929. new_vcid = 0x60 + (vcid & 0xf0) + (vcid & 0x7);
  930. }
  931. else {
  932. new_vcid = vcid;
  933. }
  934. pcid_addr = GET_PCID_ADDR(new_vcid);
  935. }
  936. else {
  937. vcid_addr = GET_CID_ADDR(vcid);
  938. pcid_addr = vcid_addr;
  939. }
  940. REG_WR(bp, BNX2_CTX_VIRT_ADDR, 0x00);
  941. REG_WR(bp, BNX2_CTX_PAGE_TBL, pcid_addr);
  942. /* Zero out the context. */
  943. for (offset = 0; offset < PHY_CTX_SIZE; offset += 4) {
  944. CTX_WR(bp, 0x00, offset, 0);
  945. }
  946. REG_WR(bp, BNX2_CTX_VIRT_ADDR, vcid_addr);
  947. REG_WR(bp, BNX2_CTX_PAGE_TBL, pcid_addr);
  948. }
  949. }
  950. static int
  951. bnx2_alloc_bad_rbuf(struct bnx2 *bp)
  952. {
  953. u16 *good_mbuf;
  954. u32 good_mbuf_cnt;
  955. u32 val;
  956. good_mbuf = kmalloc(512 * sizeof(u16), GFP_KERNEL);
  957. if (good_mbuf == NULL) {
  958. printk(KERN_ERR PFX "Failed to allocate memory in "
  959. "bnx2_alloc_bad_rbuf\n");
  960. return -ENOMEM;
  961. }
  962. REG_WR(bp, BNX2_MISC_ENABLE_SET_BITS,
  963. BNX2_MISC_ENABLE_SET_BITS_RX_MBUF_ENABLE);
  964. good_mbuf_cnt = 0;
  965. /* Allocate a bunch of mbufs and save the good ones in an array. */
  966. val = REG_RD_IND(bp, BNX2_RBUF_STATUS1);
  967. while (val & BNX2_RBUF_STATUS1_FREE_COUNT) {
  968. REG_WR_IND(bp, BNX2_RBUF_COMMAND, BNX2_RBUF_COMMAND_ALLOC_REQ);
  969. val = REG_RD_IND(bp, BNX2_RBUF_FW_BUF_ALLOC);
  970. val &= BNX2_RBUF_FW_BUF_ALLOC_VALUE;
  971. /* The addresses with Bit 9 set are bad memory blocks. */
  972. if (!(val & (1 << 9))) {
  973. good_mbuf[good_mbuf_cnt] = (u16) val;
  974. good_mbuf_cnt++;
  975. }
  976. val = REG_RD_IND(bp, BNX2_RBUF_STATUS1);
  977. }
  978. /* Free the good ones back to the mbuf pool thus discarding
  979. * all the bad ones. */
  980. while (good_mbuf_cnt) {
  981. good_mbuf_cnt--;
  982. val = good_mbuf[good_mbuf_cnt];
  983. val = (val << 9) | val | 1;
  984. REG_WR_IND(bp, BNX2_RBUF_FW_BUF_FREE, val);
  985. }
  986. kfree(good_mbuf);
  987. return 0;
  988. }
  989. static void
  990. bnx2_set_mac_addr(struct bnx2 *bp)
  991. {
  992. u32 val;
  993. u8 *mac_addr = bp->dev->dev_addr;
  994. val = (mac_addr[0] << 8) | mac_addr[1];
  995. REG_WR(bp, BNX2_EMAC_MAC_MATCH0, val);
  996. val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
  997. (mac_addr[4] << 8) | mac_addr[5];
  998. REG_WR(bp, BNX2_EMAC_MAC_MATCH1, val);
  999. }
  1000. static inline int
  1001. bnx2_alloc_rx_skb(struct bnx2 *bp, u16 index)
  1002. {
  1003. struct sk_buff *skb;
  1004. struct sw_bd *rx_buf = &bp->rx_buf_ring[index];
  1005. dma_addr_t mapping;
  1006. struct rx_bd *rxbd = &bp->rx_desc_ring[index];
  1007. unsigned long align;
  1008. skb = dev_alloc_skb(bp->rx_buf_size);
  1009. if (skb == NULL) {
  1010. return -ENOMEM;
  1011. }
  1012. if (unlikely((align = (unsigned long) skb->data & 0x7))) {
  1013. skb_reserve(skb, 8 - align);
  1014. }
  1015. skb->dev = bp->dev;
  1016. mapping = pci_map_single(bp->pdev, skb->data, bp->rx_buf_use_size,
  1017. PCI_DMA_FROMDEVICE);
  1018. rx_buf->skb = skb;
  1019. pci_unmap_addr_set(rx_buf, mapping, mapping);
  1020. rxbd->rx_bd_haddr_hi = (u64) mapping >> 32;
  1021. rxbd->rx_bd_haddr_lo = (u64) mapping & 0xffffffff;
  1022. bp->rx_prod_bseq += bp->rx_buf_use_size;
  1023. return 0;
  1024. }
  1025. static void
  1026. bnx2_phy_int(struct bnx2 *bp)
  1027. {
  1028. u32 new_link_state, old_link_state;
  1029. new_link_state = bp->status_blk->status_attn_bits &
  1030. STATUS_ATTN_BITS_LINK_STATE;
  1031. old_link_state = bp->status_blk->status_attn_bits_ack &
  1032. STATUS_ATTN_BITS_LINK_STATE;
  1033. if (new_link_state != old_link_state) {
  1034. if (new_link_state) {
  1035. REG_WR(bp, BNX2_PCICFG_STATUS_BIT_SET_CMD,
  1036. STATUS_ATTN_BITS_LINK_STATE);
  1037. }
  1038. else {
  1039. REG_WR(bp, BNX2_PCICFG_STATUS_BIT_CLEAR_CMD,
  1040. STATUS_ATTN_BITS_LINK_STATE);
  1041. }
  1042. bnx2_set_link(bp);
  1043. }
  1044. }
  1045. static void
  1046. bnx2_tx_int(struct bnx2 *bp)
  1047. {
  1048. u16 hw_cons, sw_cons, sw_ring_cons;
  1049. int tx_free_bd = 0;
  1050. hw_cons = bp->status_blk->status_tx_quick_consumer_index0;
  1051. if ((hw_cons & MAX_TX_DESC_CNT) == MAX_TX_DESC_CNT) {
  1052. hw_cons++;
  1053. }
  1054. sw_cons = bp->tx_cons;
  1055. while (sw_cons != hw_cons) {
  1056. struct sw_bd *tx_buf;
  1057. struct sk_buff *skb;
  1058. int i, last;
  1059. sw_ring_cons = TX_RING_IDX(sw_cons);
  1060. tx_buf = &bp->tx_buf_ring[sw_ring_cons];
  1061. skb = tx_buf->skb;
  1062. #ifdef BCM_TSO
  1063. /* partial BD completions possible with TSO packets */
  1064. if (skb_shinfo(skb)->tso_size) {
  1065. u16 last_idx, last_ring_idx;
  1066. last_idx = sw_cons +
  1067. skb_shinfo(skb)->nr_frags + 1;
  1068. last_ring_idx = sw_ring_cons +
  1069. skb_shinfo(skb)->nr_frags + 1;
  1070. if (unlikely(last_ring_idx >= MAX_TX_DESC_CNT)) {
  1071. last_idx++;
  1072. }
  1073. if (((s16) ((s16) last_idx - (s16) hw_cons)) > 0) {
  1074. break;
  1075. }
  1076. }
  1077. #endif
  1078. pci_unmap_single(bp->pdev, pci_unmap_addr(tx_buf, mapping),
  1079. skb_headlen(skb), PCI_DMA_TODEVICE);
  1080. tx_buf->skb = NULL;
  1081. last = skb_shinfo(skb)->nr_frags;
  1082. for (i = 0; i < last; i++) {
  1083. sw_cons = NEXT_TX_BD(sw_cons);
  1084. pci_unmap_page(bp->pdev,
  1085. pci_unmap_addr(
  1086. &bp->tx_buf_ring[TX_RING_IDX(sw_cons)],
  1087. mapping),
  1088. skb_shinfo(skb)->frags[i].size,
  1089. PCI_DMA_TODEVICE);
  1090. }
  1091. sw_cons = NEXT_TX_BD(sw_cons);
  1092. tx_free_bd += last + 1;
  1093. dev_kfree_skb_irq(skb);
  1094. hw_cons = bp->status_blk->status_tx_quick_consumer_index0;
  1095. if ((hw_cons & MAX_TX_DESC_CNT) == MAX_TX_DESC_CNT) {
  1096. hw_cons++;
  1097. }
  1098. }
  1099. atomic_add(tx_free_bd, &bp->tx_avail_bd);
  1100. if (unlikely(netif_queue_stopped(bp->dev))) {
  1101. unsigned long flags;
  1102. spin_lock_irqsave(&bp->tx_lock, flags);
  1103. if ((netif_queue_stopped(bp->dev)) &&
  1104. (atomic_read(&bp->tx_avail_bd) > MAX_SKB_FRAGS)) {
  1105. netif_wake_queue(bp->dev);
  1106. }
  1107. spin_unlock_irqrestore(&bp->tx_lock, flags);
  1108. }
  1109. bp->tx_cons = sw_cons;
  1110. }
  1111. static inline void
  1112. bnx2_reuse_rx_skb(struct bnx2 *bp, struct sk_buff *skb,
  1113. u16 cons, u16 prod)
  1114. {
  1115. struct sw_bd *cons_rx_buf = &bp->rx_buf_ring[cons];
  1116. struct sw_bd *prod_rx_buf = &bp->rx_buf_ring[prod];
  1117. struct rx_bd *cons_bd = &bp->rx_desc_ring[cons];
  1118. struct rx_bd *prod_bd = &bp->rx_desc_ring[prod];
  1119. pci_dma_sync_single_for_device(bp->pdev,
  1120. pci_unmap_addr(cons_rx_buf, mapping),
  1121. bp->rx_offset + RX_COPY_THRESH, PCI_DMA_FROMDEVICE);
  1122. prod_rx_buf->skb = cons_rx_buf->skb;
  1123. pci_unmap_addr_set(prod_rx_buf, mapping,
  1124. pci_unmap_addr(cons_rx_buf, mapping));
  1125. memcpy(prod_bd, cons_bd, 8);
  1126. bp->rx_prod_bseq += bp->rx_buf_use_size;
  1127. }
  1128. static int
  1129. bnx2_rx_int(struct bnx2 *bp, int budget)
  1130. {
  1131. u16 hw_cons, sw_cons, sw_ring_cons, sw_prod, sw_ring_prod;
  1132. struct l2_fhdr *rx_hdr;
  1133. int rx_pkt = 0;
  1134. hw_cons = bp->status_blk->status_rx_quick_consumer_index0;
  1135. if ((hw_cons & MAX_RX_DESC_CNT) == MAX_RX_DESC_CNT) {
  1136. hw_cons++;
  1137. }
  1138. sw_cons = bp->rx_cons;
  1139. sw_prod = bp->rx_prod;
  1140. /* Memory barrier necessary as speculative reads of the rx
  1141. * buffer can be ahead of the index in the status block
  1142. */
  1143. rmb();
  1144. while (sw_cons != hw_cons) {
  1145. unsigned int len;
  1146. u16 status;
  1147. struct sw_bd *rx_buf;
  1148. struct sk_buff *skb;
  1149. sw_ring_cons = RX_RING_IDX(sw_cons);
  1150. sw_ring_prod = RX_RING_IDX(sw_prod);
  1151. rx_buf = &bp->rx_buf_ring[sw_ring_cons];
  1152. skb = rx_buf->skb;
  1153. pci_dma_sync_single_for_cpu(bp->pdev,
  1154. pci_unmap_addr(rx_buf, mapping),
  1155. bp->rx_offset + RX_COPY_THRESH, PCI_DMA_FROMDEVICE);
  1156. rx_hdr = (struct l2_fhdr *) skb->data;
  1157. len = rx_hdr->l2_fhdr_pkt_len - 4;
  1158. if (rx_hdr->l2_fhdr_errors &
  1159. (L2_FHDR_ERRORS_BAD_CRC |
  1160. L2_FHDR_ERRORS_PHY_DECODE |
  1161. L2_FHDR_ERRORS_ALIGNMENT |
  1162. L2_FHDR_ERRORS_TOO_SHORT |
  1163. L2_FHDR_ERRORS_GIANT_FRAME)) {
  1164. goto reuse_rx;
  1165. }
  1166. /* Since we don't have a jumbo ring, copy small packets
  1167. * if mtu > 1500
  1168. */
  1169. if ((bp->dev->mtu > 1500) && (len <= RX_COPY_THRESH)) {
  1170. struct sk_buff *new_skb;
  1171. new_skb = dev_alloc_skb(len + 2);
  1172. if (new_skb == NULL)
  1173. goto reuse_rx;
  1174. /* aligned copy */
  1175. memcpy(new_skb->data,
  1176. skb->data + bp->rx_offset - 2,
  1177. len + 2);
  1178. skb_reserve(new_skb, 2);
  1179. skb_put(new_skb, len);
  1180. new_skb->dev = bp->dev;
  1181. bnx2_reuse_rx_skb(bp, skb,
  1182. sw_ring_cons, sw_ring_prod);
  1183. skb = new_skb;
  1184. }
  1185. else if (bnx2_alloc_rx_skb(bp, sw_ring_prod) == 0) {
  1186. pci_unmap_single(bp->pdev,
  1187. pci_unmap_addr(rx_buf, mapping),
  1188. bp->rx_buf_use_size, PCI_DMA_FROMDEVICE);
  1189. skb_reserve(skb, bp->rx_offset);
  1190. skb_put(skb, len);
  1191. }
  1192. else {
  1193. reuse_rx:
  1194. bnx2_reuse_rx_skb(bp, skb,
  1195. sw_ring_cons, sw_ring_prod);
  1196. goto next_rx;
  1197. }
  1198. skb->protocol = eth_type_trans(skb, bp->dev);
  1199. if ((len > (bp->dev->mtu + ETH_HLEN)) &&
  1200. (htons(skb->protocol) != 0x8100)) {
  1201. dev_kfree_skb_irq(skb);
  1202. goto next_rx;
  1203. }
  1204. status = rx_hdr->l2_fhdr_status;
  1205. skb->ip_summed = CHECKSUM_NONE;
  1206. if (bp->rx_csum &&
  1207. (status & (L2_FHDR_STATUS_TCP_SEGMENT |
  1208. L2_FHDR_STATUS_UDP_DATAGRAM))) {
  1209. u16 cksum = rx_hdr->l2_fhdr_tcp_udp_xsum;
  1210. if (cksum == 0xffff)
  1211. skb->ip_summed = CHECKSUM_UNNECESSARY;
  1212. }
  1213. #ifdef BCM_VLAN
  1214. if ((status & L2_FHDR_STATUS_L2_VLAN_TAG) && (bp->vlgrp != 0)) {
  1215. vlan_hwaccel_receive_skb(skb, bp->vlgrp,
  1216. rx_hdr->l2_fhdr_vlan_tag);
  1217. }
  1218. else
  1219. #endif
  1220. netif_receive_skb(skb);
  1221. bp->dev->last_rx = jiffies;
  1222. rx_pkt++;
  1223. next_rx:
  1224. rx_buf->skb = NULL;
  1225. sw_cons = NEXT_RX_BD(sw_cons);
  1226. sw_prod = NEXT_RX_BD(sw_prod);
  1227. if ((rx_pkt == budget))
  1228. break;
  1229. }
  1230. bp->rx_cons = sw_cons;
  1231. bp->rx_prod = sw_prod;
  1232. REG_WR16(bp, MB_RX_CID_ADDR + BNX2_L2CTX_HOST_BDIDX, sw_prod);
  1233. REG_WR(bp, MB_RX_CID_ADDR + BNX2_L2CTX_HOST_BSEQ, bp->rx_prod_bseq);
  1234. mmiowb();
  1235. return rx_pkt;
  1236. }
  1237. /* MSI ISR - The only difference between this and the INTx ISR
  1238. * is that the MSI interrupt is always serviced.
  1239. */
  1240. static irqreturn_t
  1241. bnx2_msi(int irq, void *dev_instance, struct pt_regs *regs)
  1242. {
  1243. struct net_device *dev = dev_instance;
  1244. struct bnx2 *bp = dev->priv;
  1245. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD,
  1246. BNX2_PCICFG_INT_ACK_CMD_USE_INT_HC_PARAM |
  1247. BNX2_PCICFG_INT_ACK_CMD_MASK_INT);
  1248. /* Return here if interrupt is disabled. */
  1249. if (unlikely(atomic_read(&bp->intr_sem) != 0)) {
  1250. return IRQ_RETVAL(1);
  1251. }
  1252. if (netif_rx_schedule_prep(dev)) {
  1253. __netif_rx_schedule(dev);
  1254. }
  1255. return IRQ_RETVAL(1);
  1256. }
  1257. static irqreturn_t
  1258. bnx2_interrupt(int irq, void *dev_instance, struct pt_regs *regs)
  1259. {
  1260. struct net_device *dev = dev_instance;
  1261. struct bnx2 *bp = dev->priv;
  1262. /* When using INTx, it is possible for the interrupt to arrive
  1263. * at the CPU before the status block posted prior to the
  1264. * interrupt. Reading a register will flush the status block.
  1265. * When using MSI, the MSI message will always complete after
  1266. * the status block write.
  1267. */
  1268. if ((bp->status_blk->status_idx == bp->last_status_idx) ||
  1269. (REG_RD(bp, BNX2_PCICFG_MISC_STATUS) &
  1270. BNX2_PCICFG_MISC_STATUS_INTA_VALUE))
  1271. return IRQ_RETVAL(0);
  1272. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD,
  1273. BNX2_PCICFG_INT_ACK_CMD_USE_INT_HC_PARAM |
  1274. BNX2_PCICFG_INT_ACK_CMD_MASK_INT);
  1275. /* Return here if interrupt is shared and is disabled. */
  1276. if (unlikely(atomic_read(&bp->intr_sem) != 0)) {
  1277. return IRQ_RETVAL(1);
  1278. }
  1279. if (netif_rx_schedule_prep(dev)) {
  1280. __netif_rx_schedule(dev);
  1281. }
  1282. return IRQ_RETVAL(1);
  1283. }
  1284. static int
  1285. bnx2_poll(struct net_device *dev, int *budget)
  1286. {
  1287. struct bnx2 *bp = dev->priv;
  1288. int rx_done = 1;
  1289. bp->last_status_idx = bp->status_blk->status_idx;
  1290. rmb();
  1291. if ((bp->status_blk->status_attn_bits &
  1292. STATUS_ATTN_BITS_LINK_STATE) !=
  1293. (bp->status_blk->status_attn_bits_ack &
  1294. STATUS_ATTN_BITS_LINK_STATE)) {
  1295. unsigned long flags;
  1296. spin_lock_irqsave(&bp->phy_lock, flags);
  1297. bnx2_phy_int(bp);
  1298. spin_unlock_irqrestore(&bp->phy_lock, flags);
  1299. }
  1300. if (bp->status_blk->status_tx_quick_consumer_index0 != bp->tx_cons) {
  1301. bnx2_tx_int(bp);
  1302. }
  1303. if (bp->status_blk->status_rx_quick_consumer_index0 != bp->rx_cons) {
  1304. int orig_budget = *budget;
  1305. int work_done;
  1306. if (orig_budget > dev->quota)
  1307. orig_budget = dev->quota;
  1308. work_done = bnx2_rx_int(bp, orig_budget);
  1309. *budget -= work_done;
  1310. dev->quota -= work_done;
  1311. if (work_done >= orig_budget) {
  1312. rx_done = 0;
  1313. }
  1314. }
  1315. if (rx_done) {
  1316. netif_rx_complete(dev);
  1317. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD,
  1318. BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID |
  1319. bp->last_status_idx);
  1320. return 0;
  1321. }
  1322. return 1;
  1323. }
  1324. /* Called with rtnl_lock from vlan functions and also dev->xmit_lock
  1325. * from set_multicast.
  1326. */
  1327. static void
  1328. bnx2_set_rx_mode(struct net_device *dev)
  1329. {
  1330. struct bnx2 *bp = dev->priv;
  1331. u32 rx_mode, sort_mode;
  1332. int i;
  1333. unsigned long flags;
  1334. spin_lock_irqsave(&bp->phy_lock, flags);
  1335. rx_mode = bp->rx_mode & ~(BNX2_EMAC_RX_MODE_PROMISCUOUS |
  1336. BNX2_EMAC_RX_MODE_KEEP_VLAN_TAG);
  1337. sort_mode = 1 | BNX2_RPM_SORT_USER0_BC_EN;
  1338. #ifdef BCM_VLAN
  1339. if (!bp->vlgrp) {
  1340. rx_mode |= BNX2_EMAC_RX_MODE_KEEP_VLAN_TAG;
  1341. }
  1342. #else
  1343. rx_mode |= BNX2_EMAC_RX_MODE_KEEP_VLAN_TAG;
  1344. #endif
  1345. if (dev->flags & IFF_PROMISC) {
  1346. /* Promiscuous mode. */
  1347. rx_mode |= BNX2_EMAC_RX_MODE_PROMISCUOUS;
  1348. sort_mode |= BNX2_RPM_SORT_USER0_PROM_EN;
  1349. }
  1350. else if (dev->flags & IFF_ALLMULTI) {
  1351. for (i = 0; i < NUM_MC_HASH_REGISTERS; i++) {
  1352. REG_WR(bp, BNX2_EMAC_MULTICAST_HASH0 + (i * 4),
  1353. 0xffffffff);
  1354. }
  1355. sort_mode |= BNX2_RPM_SORT_USER0_MC_EN;
  1356. }
  1357. else {
  1358. /* Accept one or more multicast(s). */
  1359. struct dev_mc_list *mclist;
  1360. u32 mc_filter[NUM_MC_HASH_REGISTERS];
  1361. u32 regidx;
  1362. u32 bit;
  1363. u32 crc;
  1364. memset(mc_filter, 0, 4 * NUM_MC_HASH_REGISTERS);
  1365. for (i = 0, mclist = dev->mc_list; mclist && i < dev->mc_count;
  1366. i++, mclist = mclist->next) {
  1367. crc = ether_crc_le(ETH_ALEN, mclist->dmi_addr);
  1368. bit = crc & 0xff;
  1369. regidx = (bit & 0xe0) >> 5;
  1370. bit &= 0x1f;
  1371. mc_filter[regidx] |= (1 << bit);
  1372. }
  1373. for (i = 0; i < NUM_MC_HASH_REGISTERS; i++) {
  1374. REG_WR(bp, BNX2_EMAC_MULTICAST_HASH0 + (i * 4),
  1375. mc_filter[i]);
  1376. }
  1377. sort_mode |= BNX2_RPM_SORT_USER0_MC_HSH_EN;
  1378. }
  1379. if (rx_mode != bp->rx_mode) {
  1380. bp->rx_mode = rx_mode;
  1381. REG_WR(bp, BNX2_EMAC_RX_MODE, rx_mode);
  1382. }
  1383. REG_WR(bp, BNX2_RPM_SORT_USER0, 0x0);
  1384. REG_WR(bp, BNX2_RPM_SORT_USER0, sort_mode);
  1385. REG_WR(bp, BNX2_RPM_SORT_USER0, sort_mode | BNX2_RPM_SORT_USER0_ENA);
  1386. spin_unlock_irqrestore(&bp->phy_lock, flags);
  1387. }
  1388. static void
  1389. load_rv2p_fw(struct bnx2 *bp, u32 *rv2p_code, u32 rv2p_code_len,
  1390. u32 rv2p_proc)
  1391. {
  1392. int i;
  1393. u32 val;
  1394. for (i = 0; i < rv2p_code_len; i += 8) {
  1395. REG_WR(bp, BNX2_RV2P_INSTR_HIGH, *rv2p_code);
  1396. rv2p_code++;
  1397. REG_WR(bp, BNX2_RV2P_INSTR_LOW, *rv2p_code);
  1398. rv2p_code++;
  1399. if (rv2p_proc == RV2P_PROC1) {
  1400. val = (i / 8) | BNX2_RV2P_PROC1_ADDR_CMD_RDWR;
  1401. REG_WR(bp, BNX2_RV2P_PROC1_ADDR_CMD, val);
  1402. }
  1403. else {
  1404. val = (i / 8) | BNX2_RV2P_PROC2_ADDR_CMD_RDWR;
  1405. REG_WR(bp, BNX2_RV2P_PROC2_ADDR_CMD, val);
  1406. }
  1407. }
  1408. /* Reset the processor, un-stall is done later. */
  1409. if (rv2p_proc == RV2P_PROC1) {
  1410. REG_WR(bp, BNX2_RV2P_COMMAND, BNX2_RV2P_COMMAND_PROC1_RESET);
  1411. }
  1412. else {
  1413. REG_WR(bp, BNX2_RV2P_COMMAND, BNX2_RV2P_COMMAND_PROC2_RESET);
  1414. }
  1415. }
  1416. static void
  1417. load_cpu_fw(struct bnx2 *bp, struct cpu_reg *cpu_reg, struct fw_info *fw)
  1418. {
  1419. u32 offset;
  1420. u32 val;
  1421. /* Halt the CPU. */
  1422. val = REG_RD_IND(bp, cpu_reg->mode);
  1423. val |= cpu_reg->mode_value_halt;
  1424. REG_WR_IND(bp, cpu_reg->mode, val);
  1425. REG_WR_IND(bp, cpu_reg->state, cpu_reg->state_value_clear);
  1426. /* Load the Text area. */
  1427. offset = cpu_reg->spad_base + (fw->text_addr - cpu_reg->mips_view_base);
  1428. if (fw->text) {
  1429. int j;
  1430. for (j = 0; j < (fw->text_len / 4); j++, offset += 4) {
  1431. REG_WR_IND(bp, offset, fw->text[j]);
  1432. }
  1433. }
  1434. /* Load the Data area. */
  1435. offset = cpu_reg->spad_base + (fw->data_addr - cpu_reg->mips_view_base);
  1436. if (fw->data) {
  1437. int j;
  1438. for (j = 0; j < (fw->data_len / 4); j++, offset += 4) {
  1439. REG_WR_IND(bp, offset, fw->data[j]);
  1440. }
  1441. }
  1442. /* Load the SBSS area. */
  1443. offset = cpu_reg->spad_base + (fw->sbss_addr - cpu_reg->mips_view_base);
  1444. if (fw->sbss) {
  1445. int j;
  1446. for (j = 0; j < (fw->sbss_len / 4); j++, offset += 4) {
  1447. REG_WR_IND(bp, offset, fw->sbss[j]);
  1448. }
  1449. }
  1450. /* Load the BSS area. */
  1451. offset = cpu_reg->spad_base + (fw->bss_addr - cpu_reg->mips_view_base);
  1452. if (fw->bss) {
  1453. int j;
  1454. for (j = 0; j < (fw->bss_len/4); j++, offset += 4) {
  1455. REG_WR_IND(bp, offset, fw->bss[j]);
  1456. }
  1457. }
  1458. /* Load the Read-Only area. */
  1459. offset = cpu_reg->spad_base +
  1460. (fw->rodata_addr - cpu_reg->mips_view_base);
  1461. if (fw->rodata) {
  1462. int j;
  1463. for (j = 0; j < (fw->rodata_len / 4); j++, offset += 4) {
  1464. REG_WR_IND(bp, offset, fw->rodata[j]);
  1465. }
  1466. }
  1467. /* Clear the pre-fetch instruction. */
  1468. REG_WR_IND(bp, cpu_reg->inst, 0);
  1469. REG_WR_IND(bp, cpu_reg->pc, fw->start_addr);
  1470. /* Start the CPU. */
  1471. val = REG_RD_IND(bp, cpu_reg->mode);
  1472. val &= ~cpu_reg->mode_value_halt;
  1473. REG_WR_IND(bp, cpu_reg->state, cpu_reg->state_value_clear);
  1474. REG_WR_IND(bp, cpu_reg->mode, val);
  1475. }
  1476. static void
  1477. bnx2_init_cpus(struct bnx2 *bp)
  1478. {
  1479. struct cpu_reg cpu_reg;
  1480. struct fw_info fw;
  1481. /* Initialize the RV2P processor. */
  1482. load_rv2p_fw(bp, bnx2_rv2p_proc1, sizeof(bnx2_rv2p_proc1), RV2P_PROC1);
  1483. load_rv2p_fw(bp, bnx2_rv2p_proc2, sizeof(bnx2_rv2p_proc2), RV2P_PROC2);
  1484. /* Initialize the RX Processor. */
  1485. cpu_reg.mode = BNX2_RXP_CPU_MODE;
  1486. cpu_reg.mode_value_halt = BNX2_RXP_CPU_MODE_SOFT_HALT;
  1487. cpu_reg.mode_value_sstep = BNX2_RXP_CPU_MODE_STEP_ENA;
  1488. cpu_reg.state = BNX2_RXP_CPU_STATE;
  1489. cpu_reg.state_value_clear = 0xffffff;
  1490. cpu_reg.gpr0 = BNX2_RXP_CPU_REG_FILE;
  1491. cpu_reg.evmask = BNX2_RXP_CPU_EVENT_MASK;
  1492. cpu_reg.pc = BNX2_RXP_CPU_PROGRAM_COUNTER;
  1493. cpu_reg.inst = BNX2_RXP_CPU_INSTRUCTION;
  1494. cpu_reg.bp = BNX2_RXP_CPU_HW_BREAKPOINT;
  1495. cpu_reg.spad_base = BNX2_RXP_SCRATCH;
  1496. cpu_reg.mips_view_base = 0x8000000;
  1497. fw.ver_major = bnx2_RXP_b06FwReleaseMajor;
  1498. fw.ver_minor = bnx2_RXP_b06FwReleaseMinor;
  1499. fw.ver_fix = bnx2_RXP_b06FwReleaseFix;
  1500. fw.start_addr = bnx2_RXP_b06FwStartAddr;
  1501. fw.text_addr = bnx2_RXP_b06FwTextAddr;
  1502. fw.text_len = bnx2_RXP_b06FwTextLen;
  1503. fw.text_index = 0;
  1504. fw.text = bnx2_RXP_b06FwText;
  1505. fw.data_addr = bnx2_RXP_b06FwDataAddr;
  1506. fw.data_len = bnx2_RXP_b06FwDataLen;
  1507. fw.data_index = 0;
  1508. fw.data = bnx2_RXP_b06FwData;
  1509. fw.sbss_addr = bnx2_RXP_b06FwSbssAddr;
  1510. fw.sbss_len = bnx2_RXP_b06FwSbssLen;
  1511. fw.sbss_index = 0;
  1512. fw.sbss = bnx2_RXP_b06FwSbss;
  1513. fw.bss_addr = bnx2_RXP_b06FwBssAddr;
  1514. fw.bss_len = bnx2_RXP_b06FwBssLen;
  1515. fw.bss_index = 0;
  1516. fw.bss = bnx2_RXP_b06FwBss;
  1517. fw.rodata_addr = bnx2_RXP_b06FwRodataAddr;
  1518. fw.rodata_len = bnx2_RXP_b06FwRodataLen;
  1519. fw.rodata_index = 0;
  1520. fw.rodata = bnx2_RXP_b06FwRodata;
  1521. load_cpu_fw(bp, &cpu_reg, &fw);
  1522. /* Initialize the TX Processor. */
  1523. cpu_reg.mode = BNX2_TXP_CPU_MODE;
  1524. cpu_reg.mode_value_halt = BNX2_TXP_CPU_MODE_SOFT_HALT;
  1525. cpu_reg.mode_value_sstep = BNX2_TXP_CPU_MODE_STEP_ENA;
  1526. cpu_reg.state = BNX2_TXP_CPU_STATE;
  1527. cpu_reg.state_value_clear = 0xffffff;
  1528. cpu_reg.gpr0 = BNX2_TXP_CPU_REG_FILE;
  1529. cpu_reg.evmask = BNX2_TXP_CPU_EVENT_MASK;
  1530. cpu_reg.pc = BNX2_TXP_CPU_PROGRAM_COUNTER;
  1531. cpu_reg.inst = BNX2_TXP_CPU_INSTRUCTION;
  1532. cpu_reg.bp = BNX2_TXP_CPU_HW_BREAKPOINT;
  1533. cpu_reg.spad_base = BNX2_TXP_SCRATCH;
  1534. cpu_reg.mips_view_base = 0x8000000;
  1535. fw.ver_major = bnx2_TXP_b06FwReleaseMajor;
  1536. fw.ver_minor = bnx2_TXP_b06FwReleaseMinor;
  1537. fw.ver_fix = bnx2_TXP_b06FwReleaseFix;
  1538. fw.start_addr = bnx2_TXP_b06FwStartAddr;
  1539. fw.text_addr = bnx2_TXP_b06FwTextAddr;
  1540. fw.text_len = bnx2_TXP_b06FwTextLen;
  1541. fw.text_index = 0;
  1542. fw.text = bnx2_TXP_b06FwText;
  1543. fw.data_addr = bnx2_TXP_b06FwDataAddr;
  1544. fw.data_len = bnx2_TXP_b06FwDataLen;
  1545. fw.data_index = 0;
  1546. fw.data = bnx2_TXP_b06FwData;
  1547. fw.sbss_addr = bnx2_TXP_b06FwSbssAddr;
  1548. fw.sbss_len = bnx2_TXP_b06FwSbssLen;
  1549. fw.sbss_index = 0;
  1550. fw.sbss = bnx2_TXP_b06FwSbss;
  1551. fw.bss_addr = bnx2_TXP_b06FwBssAddr;
  1552. fw.bss_len = bnx2_TXP_b06FwBssLen;
  1553. fw.bss_index = 0;
  1554. fw.bss = bnx2_TXP_b06FwBss;
  1555. fw.rodata_addr = bnx2_TXP_b06FwRodataAddr;
  1556. fw.rodata_len = bnx2_TXP_b06FwRodataLen;
  1557. fw.rodata_index = 0;
  1558. fw.rodata = bnx2_TXP_b06FwRodata;
  1559. load_cpu_fw(bp, &cpu_reg, &fw);
  1560. /* Initialize the TX Patch-up Processor. */
  1561. cpu_reg.mode = BNX2_TPAT_CPU_MODE;
  1562. cpu_reg.mode_value_halt = BNX2_TPAT_CPU_MODE_SOFT_HALT;
  1563. cpu_reg.mode_value_sstep = BNX2_TPAT_CPU_MODE_STEP_ENA;
  1564. cpu_reg.state = BNX2_TPAT_CPU_STATE;
  1565. cpu_reg.state_value_clear = 0xffffff;
  1566. cpu_reg.gpr0 = BNX2_TPAT_CPU_REG_FILE;
  1567. cpu_reg.evmask = BNX2_TPAT_CPU_EVENT_MASK;
  1568. cpu_reg.pc = BNX2_TPAT_CPU_PROGRAM_COUNTER;
  1569. cpu_reg.inst = BNX2_TPAT_CPU_INSTRUCTION;
  1570. cpu_reg.bp = BNX2_TPAT_CPU_HW_BREAKPOINT;
  1571. cpu_reg.spad_base = BNX2_TPAT_SCRATCH;
  1572. cpu_reg.mips_view_base = 0x8000000;
  1573. fw.ver_major = bnx2_TPAT_b06FwReleaseMajor;
  1574. fw.ver_minor = bnx2_TPAT_b06FwReleaseMinor;
  1575. fw.ver_fix = bnx2_TPAT_b06FwReleaseFix;
  1576. fw.start_addr = bnx2_TPAT_b06FwStartAddr;
  1577. fw.text_addr = bnx2_TPAT_b06FwTextAddr;
  1578. fw.text_len = bnx2_TPAT_b06FwTextLen;
  1579. fw.text_index = 0;
  1580. fw.text = bnx2_TPAT_b06FwText;
  1581. fw.data_addr = bnx2_TPAT_b06FwDataAddr;
  1582. fw.data_len = bnx2_TPAT_b06FwDataLen;
  1583. fw.data_index = 0;
  1584. fw.data = bnx2_TPAT_b06FwData;
  1585. fw.sbss_addr = bnx2_TPAT_b06FwSbssAddr;
  1586. fw.sbss_len = bnx2_TPAT_b06FwSbssLen;
  1587. fw.sbss_index = 0;
  1588. fw.sbss = bnx2_TPAT_b06FwSbss;
  1589. fw.bss_addr = bnx2_TPAT_b06FwBssAddr;
  1590. fw.bss_len = bnx2_TPAT_b06FwBssLen;
  1591. fw.bss_index = 0;
  1592. fw.bss = bnx2_TPAT_b06FwBss;
  1593. fw.rodata_addr = bnx2_TPAT_b06FwRodataAddr;
  1594. fw.rodata_len = bnx2_TPAT_b06FwRodataLen;
  1595. fw.rodata_index = 0;
  1596. fw.rodata = bnx2_TPAT_b06FwRodata;
  1597. load_cpu_fw(bp, &cpu_reg, &fw);
  1598. /* Initialize the Completion Processor. */
  1599. cpu_reg.mode = BNX2_COM_CPU_MODE;
  1600. cpu_reg.mode_value_halt = BNX2_COM_CPU_MODE_SOFT_HALT;
  1601. cpu_reg.mode_value_sstep = BNX2_COM_CPU_MODE_STEP_ENA;
  1602. cpu_reg.state = BNX2_COM_CPU_STATE;
  1603. cpu_reg.state_value_clear = 0xffffff;
  1604. cpu_reg.gpr0 = BNX2_COM_CPU_REG_FILE;
  1605. cpu_reg.evmask = BNX2_COM_CPU_EVENT_MASK;
  1606. cpu_reg.pc = BNX2_COM_CPU_PROGRAM_COUNTER;
  1607. cpu_reg.inst = BNX2_COM_CPU_INSTRUCTION;
  1608. cpu_reg.bp = BNX2_COM_CPU_HW_BREAKPOINT;
  1609. cpu_reg.spad_base = BNX2_COM_SCRATCH;
  1610. cpu_reg.mips_view_base = 0x8000000;
  1611. fw.ver_major = bnx2_COM_b06FwReleaseMajor;
  1612. fw.ver_minor = bnx2_COM_b06FwReleaseMinor;
  1613. fw.ver_fix = bnx2_COM_b06FwReleaseFix;
  1614. fw.start_addr = bnx2_COM_b06FwStartAddr;
  1615. fw.text_addr = bnx2_COM_b06FwTextAddr;
  1616. fw.text_len = bnx2_COM_b06FwTextLen;
  1617. fw.text_index = 0;
  1618. fw.text = bnx2_COM_b06FwText;
  1619. fw.data_addr = bnx2_COM_b06FwDataAddr;
  1620. fw.data_len = bnx2_COM_b06FwDataLen;
  1621. fw.data_index = 0;
  1622. fw.data = bnx2_COM_b06FwData;
  1623. fw.sbss_addr = bnx2_COM_b06FwSbssAddr;
  1624. fw.sbss_len = bnx2_COM_b06FwSbssLen;
  1625. fw.sbss_index = 0;
  1626. fw.sbss = bnx2_COM_b06FwSbss;
  1627. fw.bss_addr = bnx2_COM_b06FwBssAddr;
  1628. fw.bss_len = bnx2_COM_b06FwBssLen;
  1629. fw.bss_index = 0;
  1630. fw.bss = bnx2_COM_b06FwBss;
  1631. fw.rodata_addr = bnx2_COM_b06FwRodataAddr;
  1632. fw.rodata_len = bnx2_COM_b06FwRodataLen;
  1633. fw.rodata_index = 0;
  1634. fw.rodata = bnx2_COM_b06FwRodata;
  1635. load_cpu_fw(bp, &cpu_reg, &fw);
  1636. }
  1637. static int
  1638. bnx2_set_power_state(struct bnx2 *bp, int state)
  1639. {
  1640. u16 pmcsr;
  1641. pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, &pmcsr);
  1642. switch (state) {
  1643. case 0: {
  1644. u32 val;
  1645. pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL,
  1646. (pmcsr & ~PCI_PM_CTRL_STATE_MASK) |
  1647. PCI_PM_CTRL_PME_STATUS);
  1648. if (pmcsr & PCI_PM_CTRL_STATE_MASK)
  1649. /* delay required during transition out of D3hot */
  1650. msleep(20);
  1651. val = REG_RD(bp, BNX2_EMAC_MODE);
  1652. val |= BNX2_EMAC_MODE_MPKT_RCVD | BNX2_EMAC_MODE_ACPI_RCVD;
  1653. val &= ~BNX2_EMAC_MODE_MPKT;
  1654. REG_WR(bp, BNX2_EMAC_MODE, val);
  1655. val = REG_RD(bp, BNX2_RPM_CONFIG);
  1656. val &= ~BNX2_RPM_CONFIG_ACPI_ENA;
  1657. REG_WR(bp, BNX2_RPM_CONFIG, val);
  1658. break;
  1659. }
  1660. case 3: {
  1661. int i;
  1662. u32 val, wol_msg;
  1663. if (bp->wol) {
  1664. u32 advertising;
  1665. u8 autoneg;
  1666. autoneg = bp->autoneg;
  1667. advertising = bp->advertising;
  1668. bp->autoneg = AUTONEG_SPEED;
  1669. bp->advertising = ADVERTISED_10baseT_Half |
  1670. ADVERTISED_10baseT_Full |
  1671. ADVERTISED_100baseT_Half |
  1672. ADVERTISED_100baseT_Full |
  1673. ADVERTISED_Autoneg;
  1674. bnx2_setup_copper_phy(bp);
  1675. bp->autoneg = autoneg;
  1676. bp->advertising = advertising;
  1677. bnx2_set_mac_addr(bp);
  1678. val = REG_RD(bp, BNX2_EMAC_MODE);
  1679. /* Enable port mode. */
  1680. val &= ~BNX2_EMAC_MODE_PORT;
  1681. val |= BNX2_EMAC_MODE_PORT_MII |
  1682. BNX2_EMAC_MODE_MPKT_RCVD |
  1683. BNX2_EMAC_MODE_ACPI_RCVD |
  1684. BNX2_EMAC_MODE_FORCE_LINK |
  1685. BNX2_EMAC_MODE_MPKT;
  1686. REG_WR(bp, BNX2_EMAC_MODE, val);
  1687. /* receive all multicast */
  1688. for (i = 0; i < NUM_MC_HASH_REGISTERS; i++) {
  1689. REG_WR(bp, BNX2_EMAC_MULTICAST_HASH0 + (i * 4),
  1690. 0xffffffff);
  1691. }
  1692. REG_WR(bp, BNX2_EMAC_RX_MODE,
  1693. BNX2_EMAC_RX_MODE_SORT_MODE);
  1694. val = 1 | BNX2_RPM_SORT_USER0_BC_EN |
  1695. BNX2_RPM_SORT_USER0_MC_EN;
  1696. REG_WR(bp, BNX2_RPM_SORT_USER0, 0x0);
  1697. REG_WR(bp, BNX2_RPM_SORT_USER0, val);
  1698. REG_WR(bp, BNX2_RPM_SORT_USER0, val |
  1699. BNX2_RPM_SORT_USER0_ENA);
  1700. /* Need to enable EMAC and RPM for WOL. */
  1701. REG_WR(bp, BNX2_MISC_ENABLE_SET_BITS,
  1702. BNX2_MISC_ENABLE_SET_BITS_RX_PARSER_MAC_ENABLE |
  1703. BNX2_MISC_ENABLE_SET_BITS_TX_HEADER_Q_ENABLE |
  1704. BNX2_MISC_ENABLE_SET_BITS_EMAC_ENABLE);
  1705. val = REG_RD(bp, BNX2_RPM_CONFIG);
  1706. val &= ~BNX2_RPM_CONFIG_ACPI_ENA;
  1707. REG_WR(bp, BNX2_RPM_CONFIG, val);
  1708. wol_msg = BNX2_DRV_MSG_CODE_SUSPEND_WOL;
  1709. }
  1710. else {
  1711. wol_msg = BNX2_DRV_MSG_CODE_SUSPEND_NO_WOL;
  1712. }
  1713. bnx2_fw_sync(bp, BNX2_DRV_MSG_DATA_WAIT3 | wol_msg);
  1714. pmcsr &= ~PCI_PM_CTRL_STATE_MASK;
  1715. if ((CHIP_ID(bp) == CHIP_ID_5706_A0) ||
  1716. (CHIP_ID(bp) == CHIP_ID_5706_A1)) {
  1717. if (bp->wol)
  1718. pmcsr |= 3;
  1719. }
  1720. else {
  1721. pmcsr |= 3;
  1722. }
  1723. if (bp->wol) {
  1724. pmcsr |= PCI_PM_CTRL_PME_ENABLE;
  1725. }
  1726. pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL,
  1727. pmcsr);
  1728. /* No more memory access after this point until
  1729. * device is brought back to D0.
  1730. */
  1731. udelay(50);
  1732. break;
  1733. }
  1734. default:
  1735. return -EINVAL;
  1736. }
  1737. return 0;
  1738. }
  1739. static int
  1740. bnx2_acquire_nvram_lock(struct bnx2 *bp)
  1741. {
  1742. u32 val;
  1743. int j;
  1744. /* Request access to the flash interface. */
  1745. REG_WR(bp, BNX2_NVM_SW_ARB, BNX2_NVM_SW_ARB_ARB_REQ_SET2);
  1746. for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
  1747. val = REG_RD(bp, BNX2_NVM_SW_ARB);
  1748. if (val & BNX2_NVM_SW_ARB_ARB_ARB2)
  1749. break;
  1750. udelay(5);
  1751. }
  1752. if (j >= NVRAM_TIMEOUT_COUNT)
  1753. return -EBUSY;
  1754. return 0;
  1755. }
  1756. static int
  1757. bnx2_release_nvram_lock(struct bnx2 *bp)
  1758. {
  1759. int j;
  1760. u32 val;
  1761. /* Relinquish nvram interface. */
  1762. REG_WR(bp, BNX2_NVM_SW_ARB, BNX2_NVM_SW_ARB_ARB_REQ_CLR2);
  1763. for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
  1764. val = REG_RD(bp, BNX2_NVM_SW_ARB);
  1765. if (!(val & BNX2_NVM_SW_ARB_ARB_ARB2))
  1766. break;
  1767. udelay(5);
  1768. }
  1769. if (j >= NVRAM_TIMEOUT_COUNT)
  1770. return -EBUSY;
  1771. return 0;
  1772. }
  1773. static int
  1774. bnx2_enable_nvram_write(struct bnx2 *bp)
  1775. {
  1776. u32 val;
  1777. val = REG_RD(bp, BNX2_MISC_CFG);
  1778. REG_WR(bp, BNX2_MISC_CFG, val | BNX2_MISC_CFG_NVM_WR_EN_PCI);
  1779. if (!bp->flash_info->buffered) {
  1780. int j;
  1781. REG_WR(bp, BNX2_NVM_COMMAND, BNX2_NVM_COMMAND_DONE);
  1782. REG_WR(bp, BNX2_NVM_COMMAND,
  1783. BNX2_NVM_COMMAND_WREN | BNX2_NVM_COMMAND_DOIT);
  1784. for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
  1785. udelay(5);
  1786. val = REG_RD(bp, BNX2_NVM_COMMAND);
  1787. if (val & BNX2_NVM_COMMAND_DONE)
  1788. break;
  1789. }
  1790. if (j >= NVRAM_TIMEOUT_COUNT)
  1791. return -EBUSY;
  1792. }
  1793. return 0;
  1794. }
  1795. static void
  1796. bnx2_disable_nvram_write(struct bnx2 *bp)
  1797. {
  1798. u32 val;
  1799. val = REG_RD(bp, BNX2_MISC_CFG);
  1800. REG_WR(bp, BNX2_MISC_CFG, val & ~BNX2_MISC_CFG_NVM_WR_EN);
  1801. }
  1802. static void
  1803. bnx2_enable_nvram_access(struct bnx2 *bp)
  1804. {
  1805. u32 val;
  1806. val = REG_RD(bp, BNX2_NVM_ACCESS_ENABLE);
  1807. /* Enable both bits, even on read. */
  1808. REG_WR(bp, BNX2_NVM_ACCESS_ENABLE,
  1809. val | BNX2_NVM_ACCESS_ENABLE_EN | BNX2_NVM_ACCESS_ENABLE_WR_EN);
  1810. }
  1811. static void
  1812. bnx2_disable_nvram_access(struct bnx2 *bp)
  1813. {
  1814. u32 val;
  1815. val = REG_RD(bp, BNX2_NVM_ACCESS_ENABLE);
  1816. /* Disable both bits, even after read. */
  1817. REG_WR(bp, BNX2_NVM_ACCESS_ENABLE,
  1818. val & ~(BNX2_NVM_ACCESS_ENABLE_EN |
  1819. BNX2_NVM_ACCESS_ENABLE_WR_EN));
  1820. }
  1821. static int
  1822. bnx2_nvram_erase_page(struct bnx2 *bp, u32 offset)
  1823. {
  1824. u32 cmd;
  1825. int j;
  1826. if (bp->flash_info->buffered)
  1827. /* Buffered flash, no erase needed */
  1828. return 0;
  1829. /* Build an erase command */
  1830. cmd = BNX2_NVM_COMMAND_ERASE | BNX2_NVM_COMMAND_WR |
  1831. BNX2_NVM_COMMAND_DOIT;
  1832. /* Need to clear DONE bit separately. */
  1833. REG_WR(bp, BNX2_NVM_COMMAND, BNX2_NVM_COMMAND_DONE);
  1834. /* Address of the NVRAM to read from. */
  1835. REG_WR(bp, BNX2_NVM_ADDR, offset & BNX2_NVM_ADDR_NVM_ADDR_VALUE);
  1836. /* Issue an erase command. */
  1837. REG_WR(bp, BNX2_NVM_COMMAND, cmd);
  1838. /* Wait for completion. */
  1839. for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
  1840. u32 val;
  1841. udelay(5);
  1842. val = REG_RD(bp, BNX2_NVM_COMMAND);
  1843. if (val & BNX2_NVM_COMMAND_DONE)
  1844. break;
  1845. }
  1846. if (j >= NVRAM_TIMEOUT_COUNT)
  1847. return -EBUSY;
  1848. return 0;
  1849. }
  1850. static int
  1851. bnx2_nvram_read_dword(struct bnx2 *bp, u32 offset, u8 *ret_val, u32 cmd_flags)
  1852. {
  1853. u32 cmd;
  1854. int j;
  1855. /* Build the command word. */
  1856. cmd = BNX2_NVM_COMMAND_DOIT | cmd_flags;
  1857. /* Calculate an offset of a buffered flash. */
  1858. if (bp->flash_info->buffered) {
  1859. offset = ((offset / bp->flash_info->page_size) <<
  1860. bp->flash_info->page_bits) +
  1861. (offset % bp->flash_info->page_size);
  1862. }
  1863. /* Need to clear DONE bit separately. */
  1864. REG_WR(bp, BNX2_NVM_COMMAND, BNX2_NVM_COMMAND_DONE);
  1865. /* Address of the NVRAM to read from. */
  1866. REG_WR(bp, BNX2_NVM_ADDR, offset & BNX2_NVM_ADDR_NVM_ADDR_VALUE);
  1867. /* Issue a read command. */
  1868. REG_WR(bp, BNX2_NVM_COMMAND, cmd);
  1869. /* Wait for completion. */
  1870. for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
  1871. u32 val;
  1872. udelay(5);
  1873. val = REG_RD(bp, BNX2_NVM_COMMAND);
  1874. if (val & BNX2_NVM_COMMAND_DONE) {
  1875. val = REG_RD(bp, BNX2_NVM_READ);
  1876. val = be32_to_cpu(val);
  1877. memcpy(ret_val, &val, 4);
  1878. break;
  1879. }
  1880. }
  1881. if (j >= NVRAM_TIMEOUT_COUNT)
  1882. return -EBUSY;
  1883. return 0;
  1884. }
  1885. static int
  1886. bnx2_nvram_write_dword(struct bnx2 *bp, u32 offset, u8 *val, u32 cmd_flags)
  1887. {
  1888. u32 cmd, val32;
  1889. int j;
  1890. /* Build the command word. */
  1891. cmd = BNX2_NVM_COMMAND_DOIT | BNX2_NVM_COMMAND_WR | cmd_flags;
  1892. /* Calculate an offset of a buffered flash. */
  1893. if (bp->flash_info->buffered) {
  1894. offset = ((offset / bp->flash_info->page_size) <<
  1895. bp->flash_info->page_bits) +
  1896. (offset % bp->flash_info->page_size);
  1897. }
  1898. /* Need to clear DONE bit separately. */
  1899. REG_WR(bp, BNX2_NVM_COMMAND, BNX2_NVM_COMMAND_DONE);
  1900. memcpy(&val32, val, 4);
  1901. val32 = cpu_to_be32(val32);
  1902. /* Write the data. */
  1903. REG_WR(bp, BNX2_NVM_WRITE, val32);
  1904. /* Address of the NVRAM to write to. */
  1905. REG_WR(bp, BNX2_NVM_ADDR, offset & BNX2_NVM_ADDR_NVM_ADDR_VALUE);
  1906. /* Issue the write command. */
  1907. REG_WR(bp, BNX2_NVM_COMMAND, cmd);
  1908. /* Wait for completion. */
  1909. for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
  1910. udelay(5);
  1911. if (REG_RD(bp, BNX2_NVM_COMMAND) & BNX2_NVM_COMMAND_DONE)
  1912. break;
  1913. }
  1914. if (j >= NVRAM_TIMEOUT_COUNT)
  1915. return -EBUSY;
  1916. return 0;
  1917. }
  1918. static int
  1919. bnx2_init_nvram(struct bnx2 *bp)
  1920. {
  1921. u32 val;
  1922. int j, entry_count, rc;
  1923. struct flash_spec *flash;
  1924. /* Determine the selected interface. */
  1925. val = REG_RD(bp, BNX2_NVM_CFG1);
  1926. entry_count = sizeof(flash_table) / sizeof(struct flash_spec);
  1927. rc = 0;
  1928. if (val & 0x40000000) {
  1929. /* Flash interface has been reconfigured */
  1930. for (j = 0, flash = &flash_table[0]; j < entry_count;
  1931. j++, flash++) {
  1932. if (val == flash->config1) {
  1933. bp->flash_info = flash;
  1934. break;
  1935. }
  1936. }
  1937. }
  1938. else {
  1939. /* Not yet been reconfigured */
  1940. for (j = 0, flash = &flash_table[0]; j < entry_count;
  1941. j++, flash++) {
  1942. if ((val & FLASH_STRAP_MASK) == flash->strapping) {
  1943. bp->flash_info = flash;
  1944. /* Request access to the flash interface. */
  1945. if ((rc = bnx2_acquire_nvram_lock(bp)) != 0)
  1946. return rc;
  1947. /* Enable access to flash interface */
  1948. bnx2_enable_nvram_access(bp);
  1949. /* Reconfigure the flash interface */
  1950. REG_WR(bp, BNX2_NVM_CFG1, flash->config1);
  1951. REG_WR(bp, BNX2_NVM_CFG2, flash->config2);
  1952. REG_WR(bp, BNX2_NVM_CFG3, flash->config3);
  1953. REG_WR(bp, BNX2_NVM_WRITE1, flash->write1);
  1954. /* Disable access to flash interface */
  1955. bnx2_disable_nvram_access(bp);
  1956. bnx2_release_nvram_lock(bp);
  1957. break;
  1958. }
  1959. }
  1960. } /* if (val & 0x40000000) */
  1961. if (j == entry_count) {
  1962. bp->flash_info = NULL;
  1963. printk(KERN_ALERT "Unknown flash/EEPROM type.\n");
  1964. rc = -ENODEV;
  1965. }
  1966. return rc;
  1967. }
  1968. static int
  1969. bnx2_nvram_read(struct bnx2 *bp, u32 offset, u8 *ret_buf,
  1970. int buf_size)
  1971. {
  1972. int rc = 0;
  1973. u32 cmd_flags, offset32, len32, extra;
  1974. if (buf_size == 0)
  1975. return 0;
  1976. /* Request access to the flash interface. */
  1977. if ((rc = bnx2_acquire_nvram_lock(bp)) != 0)
  1978. return rc;
  1979. /* Enable access to flash interface */
  1980. bnx2_enable_nvram_access(bp);
  1981. len32 = buf_size;
  1982. offset32 = offset;
  1983. extra = 0;
  1984. cmd_flags = 0;
  1985. if (offset32 & 3) {
  1986. u8 buf[4];
  1987. u32 pre_len;
  1988. offset32 &= ~3;
  1989. pre_len = 4 - (offset & 3);
  1990. if (pre_len >= len32) {
  1991. pre_len = len32;
  1992. cmd_flags = BNX2_NVM_COMMAND_FIRST |
  1993. BNX2_NVM_COMMAND_LAST;
  1994. }
  1995. else {
  1996. cmd_flags = BNX2_NVM_COMMAND_FIRST;
  1997. }
  1998. rc = bnx2_nvram_read_dword(bp, offset32, buf, cmd_flags);
  1999. if (rc)
  2000. return rc;
  2001. memcpy(ret_buf, buf + (offset & 3), pre_len);
  2002. offset32 += 4;
  2003. ret_buf += pre_len;
  2004. len32 -= pre_len;
  2005. }
  2006. if (len32 & 3) {
  2007. extra = 4 - (len32 & 3);
  2008. len32 = (len32 + 4) & ~3;
  2009. }
  2010. if (len32 == 4) {
  2011. u8 buf[4];
  2012. if (cmd_flags)
  2013. cmd_flags = BNX2_NVM_COMMAND_LAST;
  2014. else
  2015. cmd_flags = BNX2_NVM_COMMAND_FIRST |
  2016. BNX2_NVM_COMMAND_LAST;
  2017. rc = bnx2_nvram_read_dword(bp, offset32, buf, cmd_flags);
  2018. memcpy(ret_buf, buf, 4 - extra);
  2019. }
  2020. else if (len32 > 0) {
  2021. u8 buf[4];
  2022. /* Read the first word. */
  2023. if (cmd_flags)
  2024. cmd_flags = 0;
  2025. else
  2026. cmd_flags = BNX2_NVM_COMMAND_FIRST;
  2027. rc = bnx2_nvram_read_dword(bp, offset32, ret_buf, cmd_flags);
  2028. /* Advance to the next dword. */
  2029. offset32 += 4;
  2030. ret_buf += 4;
  2031. len32 -= 4;
  2032. while (len32 > 4 && rc == 0) {
  2033. rc = bnx2_nvram_read_dword(bp, offset32, ret_buf, 0);
  2034. /* Advance to the next dword. */
  2035. offset32 += 4;
  2036. ret_buf += 4;
  2037. len32 -= 4;
  2038. }
  2039. if (rc)
  2040. return rc;
  2041. cmd_flags = BNX2_NVM_COMMAND_LAST;
  2042. rc = bnx2_nvram_read_dword(bp, offset32, buf, cmd_flags);
  2043. memcpy(ret_buf, buf, 4 - extra);
  2044. }
  2045. /* Disable access to flash interface */
  2046. bnx2_disable_nvram_access(bp);
  2047. bnx2_release_nvram_lock(bp);
  2048. return rc;
  2049. }
  2050. static int
  2051. bnx2_nvram_write(struct bnx2 *bp, u32 offset, u8 *data_buf,
  2052. int buf_size)
  2053. {
  2054. u32 written, offset32, len32;
  2055. u8 *buf, start[4], end[4];
  2056. int rc = 0;
  2057. int align_start, align_end;
  2058. buf = data_buf;
  2059. offset32 = offset;
  2060. len32 = buf_size;
  2061. align_start = align_end = 0;
  2062. if ((align_start = (offset32 & 3))) {
  2063. offset32 &= ~3;
  2064. len32 += align_start;
  2065. if ((rc = bnx2_nvram_read(bp, offset32, start, 4)))
  2066. return rc;
  2067. }
  2068. if (len32 & 3) {
  2069. if ((len32 > 4) || !align_start) {
  2070. align_end = 4 - (len32 & 3);
  2071. len32 += align_end;
  2072. if ((rc = bnx2_nvram_read(bp, offset32 + len32 - 4,
  2073. end, 4))) {
  2074. return rc;
  2075. }
  2076. }
  2077. }
  2078. if (align_start || align_end) {
  2079. buf = kmalloc(len32, GFP_KERNEL);
  2080. if (buf == 0)
  2081. return -ENOMEM;
  2082. if (align_start) {
  2083. memcpy(buf, start, 4);
  2084. }
  2085. if (align_end) {
  2086. memcpy(buf + len32 - 4, end, 4);
  2087. }
  2088. memcpy(buf + align_start, data_buf, buf_size);
  2089. }
  2090. written = 0;
  2091. while ((written < len32) && (rc == 0)) {
  2092. u32 page_start, page_end, data_start, data_end;
  2093. u32 addr, cmd_flags;
  2094. int i;
  2095. u8 flash_buffer[264];
  2096. /* Find the page_start addr */
  2097. page_start = offset32 + written;
  2098. page_start -= (page_start % bp->flash_info->page_size);
  2099. /* Find the page_end addr */
  2100. page_end = page_start + bp->flash_info->page_size;
  2101. /* Find the data_start addr */
  2102. data_start = (written == 0) ? offset32 : page_start;
  2103. /* Find the data_end addr */
  2104. data_end = (page_end > offset32 + len32) ?
  2105. (offset32 + len32) : page_end;
  2106. /* Request access to the flash interface. */
  2107. if ((rc = bnx2_acquire_nvram_lock(bp)) != 0)
  2108. goto nvram_write_end;
  2109. /* Enable access to flash interface */
  2110. bnx2_enable_nvram_access(bp);
  2111. cmd_flags = BNX2_NVM_COMMAND_FIRST;
  2112. if (bp->flash_info->buffered == 0) {
  2113. int j;
  2114. /* Read the whole page into the buffer
  2115. * (non-buffer flash only) */
  2116. for (j = 0; j < bp->flash_info->page_size; j += 4) {
  2117. if (j == (bp->flash_info->page_size - 4)) {
  2118. cmd_flags |= BNX2_NVM_COMMAND_LAST;
  2119. }
  2120. rc = bnx2_nvram_read_dword(bp,
  2121. page_start + j,
  2122. &flash_buffer[j],
  2123. cmd_flags);
  2124. if (rc)
  2125. goto nvram_write_end;
  2126. cmd_flags = 0;
  2127. }
  2128. }
  2129. /* Enable writes to flash interface (unlock write-protect) */
  2130. if ((rc = bnx2_enable_nvram_write(bp)) != 0)
  2131. goto nvram_write_end;
  2132. /* Erase the page */
  2133. if ((rc = bnx2_nvram_erase_page(bp, page_start)) != 0)
  2134. goto nvram_write_end;
  2135. /* Re-enable the write again for the actual write */
  2136. bnx2_enable_nvram_write(bp);
  2137. /* Loop to write back the buffer data from page_start to
  2138. * data_start */
  2139. i = 0;
  2140. if (bp->flash_info->buffered == 0) {
  2141. for (addr = page_start; addr < data_start;
  2142. addr += 4, i += 4) {
  2143. rc = bnx2_nvram_write_dword(bp, addr,
  2144. &flash_buffer[i], cmd_flags);
  2145. if (rc != 0)
  2146. goto nvram_write_end;
  2147. cmd_flags = 0;
  2148. }
  2149. }
  2150. /* Loop to write the new data from data_start to data_end */
  2151. for (addr = data_start; addr < data_end; addr += 4, i++) {
  2152. if ((addr == page_end - 4) ||
  2153. ((bp->flash_info->buffered) &&
  2154. (addr == data_end - 4))) {
  2155. cmd_flags |= BNX2_NVM_COMMAND_LAST;
  2156. }
  2157. rc = bnx2_nvram_write_dword(bp, addr, buf,
  2158. cmd_flags);
  2159. if (rc != 0)
  2160. goto nvram_write_end;
  2161. cmd_flags = 0;
  2162. buf += 4;
  2163. }
  2164. /* Loop to write back the buffer data from data_end
  2165. * to page_end */
  2166. if (bp->flash_info->buffered == 0) {
  2167. for (addr = data_end; addr < page_end;
  2168. addr += 4, i += 4) {
  2169. if (addr == page_end-4) {
  2170. cmd_flags = BNX2_NVM_COMMAND_LAST;
  2171. }
  2172. rc = bnx2_nvram_write_dword(bp, addr,
  2173. &flash_buffer[i], cmd_flags);
  2174. if (rc != 0)
  2175. goto nvram_write_end;
  2176. cmd_flags = 0;
  2177. }
  2178. }
  2179. /* Disable writes to flash interface (lock write-protect) */
  2180. bnx2_disable_nvram_write(bp);
  2181. /* Disable access to flash interface */
  2182. bnx2_disable_nvram_access(bp);
  2183. bnx2_release_nvram_lock(bp);
  2184. /* Increment written */
  2185. written += data_end - data_start;
  2186. }
  2187. nvram_write_end:
  2188. if (align_start || align_end)
  2189. kfree(buf);
  2190. return rc;
  2191. }
  2192. static int
  2193. bnx2_reset_chip(struct bnx2 *bp, u32 reset_code)
  2194. {
  2195. u32 val;
  2196. int i, rc = 0;
  2197. /* Wait for the current PCI transaction to complete before
  2198. * issuing a reset. */
  2199. REG_WR(bp, BNX2_MISC_ENABLE_CLR_BITS,
  2200. BNX2_MISC_ENABLE_CLR_BITS_TX_DMA_ENABLE |
  2201. BNX2_MISC_ENABLE_CLR_BITS_DMA_ENGINE_ENABLE |
  2202. BNX2_MISC_ENABLE_CLR_BITS_RX_DMA_ENABLE |
  2203. BNX2_MISC_ENABLE_CLR_BITS_HOST_COALESCE_ENABLE);
  2204. val = REG_RD(bp, BNX2_MISC_ENABLE_CLR_BITS);
  2205. udelay(5);
  2206. /* Deposit a driver reset signature so the firmware knows that
  2207. * this is a soft reset. */
  2208. REG_WR_IND(bp, HOST_VIEW_SHMEM_BASE + BNX2_DRV_RESET_SIGNATURE,
  2209. BNX2_DRV_RESET_SIGNATURE_MAGIC);
  2210. bp->fw_timed_out = 0;
  2211. /* Wait for the firmware to tell us it is ok to issue a reset. */
  2212. bnx2_fw_sync(bp, BNX2_DRV_MSG_DATA_WAIT0 | reset_code);
  2213. /* Do a dummy read to force the chip to complete all current transaction
  2214. * before we issue a reset. */
  2215. val = REG_RD(bp, BNX2_MISC_ID);
  2216. val = BNX2_PCICFG_MISC_CONFIG_CORE_RST_REQ |
  2217. BNX2_PCICFG_MISC_CONFIG_REG_WINDOW_ENA |
  2218. BNX2_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP;
  2219. /* Chip reset. */
  2220. REG_WR(bp, BNX2_PCICFG_MISC_CONFIG, val);
  2221. if ((CHIP_ID(bp) == CHIP_ID_5706_A0) ||
  2222. (CHIP_ID(bp) == CHIP_ID_5706_A1))
  2223. msleep(15);
  2224. /* Reset takes approximate 30 usec */
  2225. for (i = 0; i < 10; i++) {
  2226. val = REG_RD(bp, BNX2_PCICFG_MISC_CONFIG);
  2227. if ((val & (BNX2_PCICFG_MISC_CONFIG_CORE_RST_REQ |
  2228. BNX2_PCICFG_MISC_CONFIG_CORE_RST_BSY)) == 0) {
  2229. break;
  2230. }
  2231. udelay(10);
  2232. }
  2233. if (val & (BNX2_PCICFG_MISC_CONFIG_CORE_RST_REQ |
  2234. BNX2_PCICFG_MISC_CONFIG_CORE_RST_BSY)) {
  2235. printk(KERN_ERR PFX "Chip reset did not complete\n");
  2236. return -EBUSY;
  2237. }
  2238. /* Make sure byte swapping is properly configured. */
  2239. val = REG_RD(bp, BNX2_PCI_SWAP_DIAG0);
  2240. if (val != 0x01020304) {
  2241. printk(KERN_ERR PFX "Chip not in correct endian mode\n");
  2242. return -ENODEV;
  2243. }
  2244. bp->fw_timed_out = 0;
  2245. /* Wait for the firmware to finish its initialization. */
  2246. bnx2_fw_sync(bp, BNX2_DRV_MSG_DATA_WAIT1 | reset_code);
  2247. if (CHIP_ID(bp) == CHIP_ID_5706_A0) {
  2248. /* Adjust the voltage regular to two steps lower. The default
  2249. * of this register is 0x0000000e. */
  2250. REG_WR(bp, BNX2_MISC_VREG_CONTROL, 0x000000fa);
  2251. /* Remove bad rbuf memory from the free pool. */
  2252. rc = bnx2_alloc_bad_rbuf(bp);
  2253. }
  2254. return rc;
  2255. }
  2256. static int
  2257. bnx2_init_chip(struct bnx2 *bp)
  2258. {
  2259. u32 val;
  2260. /* Make sure the interrupt is not active. */
  2261. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD, BNX2_PCICFG_INT_ACK_CMD_MASK_INT);
  2262. val = BNX2_DMA_CONFIG_DATA_BYTE_SWAP |
  2263. BNX2_DMA_CONFIG_DATA_WORD_SWAP |
  2264. #ifdef __BIG_ENDIAN
  2265. BNX2_DMA_CONFIG_CNTL_BYTE_SWAP |
  2266. #endif
  2267. BNX2_DMA_CONFIG_CNTL_WORD_SWAP |
  2268. DMA_READ_CHANS << 12 |
  2269. DMA_WRITE_CHANS << 16;
  2270. val |= (0x2 << 20) | (1 << 11);
  2271. if ((bp->flags & PCIX_FLAG) && (bp->bus_speed_mhz = 133))
  2272. val |= (1 << 23);
  2273. if ((CHIP_NUM(bp) == CHIP_NUM_5706) &&
  2274. (CHIP_ID(bp) != CHIP_ID_5706_A0) && !(bp->flags & PCIX_FLAG))
  2275. val |= BNX2_DMA_CONFIG_CNTL_PING_PONG_DMA;
  2276. REG_WR(bp, BNX2_DMA_CONFIG, val);
  2277. if (CHIP_ID(bp) == CHIP_ID_5706_A0) {
  2278. val = REG_RD(bp, BNX2_TDMA_CONFIG);
  2279. val |= BNX2_TDMA_CONFIG_ONE_DMA;
  2280. REG_WR(bp, BNX2_TDMA_CONFIG, val);
  2281. }
  2282. if (bp->flags & PCIX_FLAG) {
  2283. u16 val16;
  2284. pci_read_config_word(bp->pdev, bp->pcix_cap + PCI_X_CMD,
  2285. &val16);
  2286. pci_write_config_word(bp->pdev, bp->pcix_cap + PCI_X_CMD,
  2287. val16 & ~PCI_X_CMD_ERO);
  2288. }
  2289. REG_WR(bp, BNX2_MISC_ENABLE_SET_BITS,
  2290. BNX2_MISC_ENABLE_SET_BITS_HOST_COALESCE_ENABLE |
  2291. BNX2_MISC_ENABLE_STATUS_BITS_RX_V2P_ENABLE |
  2292. BNX2_MISC_ENABLE_STATUS_BITS_CONTEXT_ENABLE);
  2293. /* Initialize context mapping and zero out the quick contexts. The
  2294. * context block must have already been enabled. */
  2295. bnx2_init_context(bp);
  2296. bnx2_init_cpus(bp);
  2297. bnx2_init_nvram(bp);
  2298. bnx2_set_mac_addr(bp);
  2299. val = REG_RD(bp, BNX2_MQ_CONFIG);
  2300. val &= ~BNX2_MQ_CONFIG_KNL_BYP_BLK_SIZE;
  2301. val |= BNX2_MQ_CONFIG_KNL_BYP_BLK_SIZE_256;
  2302. REG_WR(bp, BNX2_MQ_CONFIG, val);
  2303. val = 0x10000 + (MAX_CID_CNT * MB_KERNEL_CTX_SIZE);
  2304. REG_WR(bp, BNX2_MQ_KNL_BYP_WIND_START, val);
  2305. REG_WR(bp, BNX2_MQ_KNL_WIND_END, val);
  2306. val = (BCM_PAGE_BITS - 8) << 24;
  2307. REG_WR(bp, BNX2_RV2P_CONFIG, val);
  2308. /* Configure page size. */
  2309. val = REG_RD(bp, BNX2_TBDR_CONFIG);
  2310. val &= ~BNX2_TBDR_CONFIG_PAGE_SIZE;
  2311. val |= (BCM_PAGE_BITS - 8) << 24 | 0x40;
  2312. REG_WR(bp, BNX2_TBDR_CONFIG, val);
  2313. val = bp->mac_addr[0] +
  2314. (bp->mac_addr[1] << 8) +
  2315. (bp->mac_addr[2] << 16) +
  2316. bp->mac_addr[3] +
  2317. (bp->mac_addr[4] << 8) +
  2318. (bp->mac_addr[5] << 16);
  2319. REG_WR(bp, BNX2_EMAC_BACKOFF_SEED, val);
  2320. /* Program the MTU. Also include 4 bytes for CRC32. */
  2321. val = bp->dev->mtu + ETH_HLEN + 4;
  2322. if (val > (MAX_ETHERNET_PACKET_SIZE + 4))
  2323. val |= BNX2_EMAC_RX_MTU_SIZE_JUMBO_ENA;
  2324. REG_WR(bp, BNX2_EMAC_RX_MTU_SIZE, val);
  2325. bp->last_status_idx = 0;
  2326. bp->rx_mode = BNX2_EMAC_RX_MODE_SORT_MODE;
  2327. /* Set up how to generate a link change interrupt. */
  2328. REG_WR(bp, BNX2_EMAC_ATTENTION_ENA, BNX2_EMAC_ATTENTION_ENA_LINK);
  2329. REG_WR(bp, BNX2_HC_STATUS_ADDR_L,
  2330. (u64) bp->status_blk_mapping & 0xffffffff);
  2331. REG_WR(bp, BNX2_HC_STATUS_ADDR_H, (u64) bp->status_blk_mapping >> 32);
  2332. REG_WR(bp, BNX2_HC_STATISTICS_ADDR_L,
  2333. (u64) bp->stats_blk_mapping & 0xffffffff);
  2334. REG_WR(bp, BNX2_HC_STATISTICS_ADDR_H,
  2335. (u64) bp->stats_blk_mapping >> 32);
  2336. REG_WR(bp, BNX2_HC_TX_QUICK_CONS_TRIP,
  2337. (bp->tx_quick_cons_trip_int << 16) | bp->tx_quick_cons_trip);
  2338. REG_WR(bp, BNX2_HC_RX_QUICK_CONS_TRIP,
  2339. (bp->rx_quick_cons_trip_int << 16) | bp->rx_quick_cons_trip);
  2340. REG_WR(bp, BNX2_HC_COMP_PROD_TRIP,
  2341. (bp->comp_prod_trip_int << 16) | bp->comp_prod_trip);
  2342. REG_WR(bp, BNX2_HC_TX_TICKS, (bp->tx_ticks_int << 16) | bp->tx_ticks);
  2343. REG_WR(bp, BNX2_HC_RX_TICKS, (bp->rx_ticks_int << 16) | bp->rx_ticks);
  2344. REG_WR(bp, BNX2_HC_COM_TICKS,
  2345. (bp->com_ticks_int << 16) | bp->com_ticks);
  2346. REG_WR(bp, BNX2_HC_CMD_TICKS,
  2347. (bp->cmd_ticks_int << 16) | bp->cmd_ticks);
  2348. REG_WR(bp, BNX2_HC_STATS_TICKS, bp->stats_ticks & 0xffff00);
  2349. REG_WR(bp, BNX2_HC_STAT_COLLECT_TICKS, 0xbb8); /* 3ms */
  2350. if (CHIP_ID(bp) == CHIP_ID_5706_A1)
  2351. REG_WR(bp, BNX2_HC_CONFIG, BNX2_HC_CONFIG_COLLECT_STATS);
  2352. else {
  2353. REG_WR(bp, BNX2_HC_CONFIG, BNX2_HC_CONFIG_RX_TMR_MODE |
  2354. BNX2_HC_CONFIG_TX_TMR_MODE |
  2355. BNX2_HC_CONFIG_COLLECT_STATS);
  2356. }
  2357. /* Clear internal stats counters. */
  2358. REG_WR(bp, BNX2_HC_COMMAND, BNX2_HC_COMMAND_CLR_STAT_NOW);
  2359. REG_WR(bp, BNX2_HC_ATTN_BITS_ENABLE, STATUS_ATTN_BITS_LINK_STATE);
  2360. /* Initialize the receive filter. */
  2361. bnx2_set_rx_mode(bp->dev);
  2362. bnx2_fw_sync(bp, BNX2_DRV_MSG_DATA_WAIT2 | BNX2_DRV_MSG_CODE_RESET);
  2363. REG_WR(bp, BNX2_MISC_ENABLE_SET_BITS, 0x5ffffff);
  2364. REG_RD(bp, BNX2_MISC_ENABLE_SET_BITS);
  2365. udelay(20);
  2366. return 0;
  2367. }
  2368. static void
  2369. bnx2_init_tx_ring(struct bnx2 *bp)
  2370. {
  2371. struct tx_bd *txbd;
  2372. u32 val;
  2373. txbd = &bp->tx_desc_ring[MAX_TX_DESC_CNT];
  2374. txbd->tx_bd_haddr_hi = (u64) bp->tx_desc_mapping >> 32;
  2375. txbd->tx_bd_haddr_lo = (u64) bp->tx_desc_mapping & 0xffffffff;
  2376. bp->tx_prod = 0;
  2377. bp->tx_cons = 0;
  2378. bp->tx_prod_bseq = 0;
  2379. atomic_set(&bp->tx_avail_bd, bp->tx_ring_size);
  2380. val = BNX2_L2CTX_TYPE_TYPE_L2;
  2381. val |= BNX2_L2CTX_TYPE_SIZE_L2;
  2382. CTX_WR(bp, GET_CID_ADDR(TX_CID), BNX2_L2CTX_TYPE, val);
  2383. val = BNX2_L2CTX_CMD_TYPE_TYPE_L2;
  2384. val |= 8 << 16;
  2385. CTX_WR(bp, GET_CID_ADDR(TX_CID), BNX2_L2CTX_CMD_TYPE, val);
  2386. val = (u64) bp->tx_desc_mapping >> 32;
  2387. CTX_WR(bp, GET_CID_ADDR(TX_CID), BNX2_L2CTX_TBDR_BHADDR_HI, val);
  2388. val = (u64) bp->tx_desc_mapping & 0xffffffff;
  2389. CTX_WR(bp, GET_CID_ADDR(TX_CID), BNX2_L2CTX_TBDR_BHADDR_LO, val);
  2390. }
  2391. static void
  2392. bnx2_init_rx_ring(struct bnx2 *bp)
  2393. {
  2394. struct rx_bd *rxbd;
  2395. int i;
  2396. u16 prod, ring_prod;
  2397. u32 val;
  2398. /* 8 for CRC and VLAN */
  2399. bp->rx_buf_use_size = bp->dev->mtu + ETH_HLEN + bp->rx_offset + 8;
  2400. /* 8 for alignment */
  2401. bp->rx_buf_size = bp->rx_buf_use_size + 8;
  2402. ring_prod = prod = bp->rx_prod = 0;
  2403. bp->rx_cons = 0;
  2404. bp->rx_prod_bseq = 0;
  2405. rxbd = &bp->rx_desc_ring[0];
  2406. for (i = 0; i < MAX_RX_DESC_CNT; i++, rxbd++) {
  2407. rxbd->rx_bd_len = bp->rx_buf_use_size;
  2408. rxbd->rx_bd_flags = RX_BD_FLAGS_START | RX_BD_FLAGS_END;
  2409. }
  2410. rxbd->rx_bd_haddr_hi = (u64) bp->rx_desc_mapping >> 32;
  2411. rxbd->rx_bd_haddr_lo = (u64) bp->rx_desc_mapping & 0xffffffff;
  2412. val = BNX2_L2CTX_CTX_TYPE_CTX_BD_CHN_TYPE_VALUE;
  2413. val |= BNX2_L2CTX_CTX_TYPE_SIZE_L2;
  2414. val |= 0x02 << 8;
  2415. CTX_WR(bp, GET_CID_ADDR(RX_CID), BNX2_L2CTX_CTX_TYPE, val);
  2416. val = (u64) bp->rx_desc_mapping >> 32;
  2417. CTX_WR(bp, GET_CID_ADDR(RX_CID), BNX2_L2CTX_NX_BDHADDR_HI, val);
  2418. val = (u64) bp->rx_desc_mapping & 0xffffffff;
  2419. CTX_WR(bp, GET_CID_ADDR(RX_CID), BNX2_L2CTX_NX_BDHADDR_LO, val);
  2420. for ( ;ring_prod < bp->rx_ring_size; ) {
  2421. if (bnx2_alloc_rx_skb(bp, ring_prod) < 0) {
  2422. break;
  2423. }
  2424. prod = NEXT_RX_BD(prod);
  2425. ring_prod = RX_RING_IDX(prod);
  2426. }
  2427. bp->rx_prod = prod;
  2428. REG_WR16(bp, MB_RX_CID_ADDR + BNX2_L2CTX_HOST_BDIDX, prod);
  2429. REG_WR(bp, MB_RX_CID_ADDR + BNX2_L2CTX_HOST_BSEQ, bp->rx_prod_bseq);
  2430. }
  2431. static void
  2432. bnx2_free_tx_skbs(struct bnx2 *bp)
  2433. {
  2434. int i;
  2435. if (bp->tx_buf_ring == NULL)
  2436. return;
  2437. for (i = 0; i < TX_DESC_CNT; ) {
  2438. struct sw_bd *tx_buf = &bp->tx_buf_ring[i];
  2439. struct sk_buff *skb = tx_buf->skb;
  2440. int j, last;
  2441. if (skb == NULL) {
  2442. i++;
  2443. continue;
  2444. }
  2445. pci_unmap_single(bp->pdev, pci_unmap_addr(tx_buf, mapping),
  2446. skb_headlen(skb), PCI_DMA_TODEVICE);
  2447. tx_buf->skb = NULL;
  2448. last = skb_shinfo(skb)->nr_frags;
  2449. for (j = 0; j < last; j++) {
  2450. tx_buf = &bp->tx_buf_ring[i + j + 1];
  2451. pci_unmap_page(bp->pdev,
  2452. pci_unmap_addr(tx_buf, mapping),
  2453. skb_shinfo(skb)->frags[j].size,
  2454. PCI_DMA_TODEVICE);
  2455. }
  2456. dev_kfree_skb_any(skb);
  2457. i += j + 1;
  2458. }
  2459. }
  2460. static void
  2461. bnx2_free_rx_skbs(struct bnx2 *bp)
  2462. {
  2463. int i;
  2464. if (bp->rx_buf_ring == NULL)
  2465. return;
  2466. for (i = 0; i < RX_DESC_CNT; i++) {
  2467. struct sw_bd *rx_buf = &bp->rx_buf_ring[i];
  2468. struct sk_buff *skb = rx_buf->skb;
  2469. if (skb == 0)
  2470. continue;
  2471. pci_unmap_single(bp->pdev, pci_unmap_addr(rx_buf, mapping),
  2472. bp->rx_buf_use_size, PCI_DMA_FROMDEVICE);
  2473. rx_buf->skb = NULL;
  2474. dev_kfree_skb_any(skb);
  2475. }
  2476. }
  2477. static void
  2478. bnx2_free_skbs(struct bnx2 *bp)
  2479. {
  2480. bnx2_free_tx_skbs(bp);
  2481. bnx2_free_rx_skbs(bp);
  2482. }
  2483. static int
  2484. bnx2_reset_nic(struct bnx2 *bp, u32 reset_code)
  2485. {
  2486. int rc;
  2487. rc = bnx2_reset_chip(bp, reset_code);
  2488. bnx2_free_skbs(bp);
  2489. if (rc)
  2490. return rc;
  2491. bnx2_init_chip(bp);
  2492. bnx2_init_tx_ring(bp);
  2493. bnx2_init_rx_ring(bp);
  2494. return 0;
  2495. }
  2496. static int
  2497. bnx2_init_nic(struct bnx2 *bp)
  2498. {
  2499. int rc;
  2500. if ((rc = bnx2_reset_nic(bp, BNX2_DRV_MSG_CODE_RESET)) != 0)
  2501. return rc;
  2502. bnx2_init_phy(bp);
  2503. bnx2_set_link(bp);
  2504. return 0;
  2505. }
  2506. static int
  2507. bnx2_test_registers(struct bnx2 *bp)
  2508. {
  2509. int ret;
  2510. int i;
  2511. static struct {
  2512. u16 offset;
  2513. u16 flags;
  2514. u32 rw_mask;
  2515. u32 ro_mask;
  2516. } reg_tbl[] = {
  2517. { 0x006c, 0, 0x00000000, 0x0000003f },
  2518. { 0x0090, 0, 0xffffffff, 0x00000000 },
  2519. { 0x0094, 0, 0x00000000, 0x00000000 },
  2520. { 0x0404, 0, 0x00003f00, 0x00000000 },
  2521. { 0x0418, 0, 0x00000000, 0xffffffff },
  2522. { 0x041c, 0, 0x00000000, 0xffffffff },
  2523. { 0x0420, 0, 0x00000000, 0x80ffffff },
  2524. { 0x0424, 0, 0x00000000, 0x00000000 },
  2525. { 0x0428, 0, 0x00000000, 0x00000001 },
  2526. { 0x0450, 0, 0x00000000, 0x0000ffff },
  2527. { 0x0454, 0, 0x00000000, 0xffffffff },
  2528. { 0x0458, 0, 0x00000000, 0xffffffff },
  2529. { 0x0808, 0, 0x00000000, 0xffffffff },
  2530. { 0x0854, 0, 0x00000000, 0xffffffff },
  2531. { 0x0868, 0, 0x00000000, 0x77777777 },
  2532. { 0x086c, 0, 0x00000000, 0x77777777 },
  2533. { 0x0870, 0, 0x00000000, 0x77777777 },
  2534. { 0x0874, 0, 0x00000000, 0x77777777 },
  2535. { 0x0c00, 0, 0x00000000, 0x00000001 },
  2536. { 0x0c04, 0, 0x00000000, 0x03ff0001 },
  2537. { 0x0c08, 0, 0x0f0ff073, 0x00000000 },
  2538. { 0x0c0c, 0, 0x00ffffff, 0x00000000 },
  2539. { 0x0c30, 0, 0x00000000, 0xffffffff },
  2540. { 0x0c34, 0, 0x00000000, 0xffffffff },
  2541. { 0x0c38, 0, 0x00000000, 0xffffffff },
  2542. { 0x0c3c, 0, 0x00000000, 0xffffffff },
  2543. { 0x0c40, 0, 0x00000000, 0xffffffff },
  2544. { 0x0c44, 0, 0x00000000, 0xffffffff },
  2545. { 0x0c48, 0, 0x00000000, 0x0007ffff },
  2546. { 0x0c4c, 0, 0x00000000, 0xffffffff },
  2547. { 0x0c50, 0, 0x00000000, 0xffffffff },
  2548. { 0x0c54, 0, 0x00000000, 0xffffffff },
  2549. { 0x0c58, 0, 0x00000000, 0xffffffff },
  2550. { 0x0c5c, 0, 0x00000000, 0xffffffff },
  2551. { 0x0c60, 0, 0x00000000, 0xffffffff },
  2552. { 0x0c64, 0, 0x00000000, 0xffffffff },
  2553. { 0x0c68, 0, 0x00000000, 0xffffffff },
  2554. { 0x0c6c, 0, 0x00000000, 0xffffffff },
  2555. { 0x0c70, 0, 0x00000000, 0xffffffff },
  2556. { 0x0c74, 0, 0x00000000, 0xffffffff },
  2557. { 0x0c78, 0, 0x00000000, 0xffffffff },
  2558. { 0x0c7c, 0, 0x00000000, 0xffffffff },
  2559. { 0x0c80, 0, 0x00000000, 0xffffffff },
  2560. { 0x0c84, 0, 0x00000000, 0xffffffff },
  2561. { 0x0c88, 0, 0x00000000, 0xffffffff },
  2562. { 0x0c8c, 0, 0x00000000, 0xffffffff },
  2563. { 0x0c90, 0, 0x00000000, 0xffffffff },
  2564. { 0x0c94, 0, 0x00000000, 0xffffffff },
  2565. { 0x0c98, 0, 0x00000000, 0xffffffff },
  2566. { 0x0c9c, 0, 0x00000000, 0xffffffff },
  2567. { 0x0ca0, 0, 0x00000000, 0xffffffff },
  2568. { 0x0ca4, 0, 0x00000000, 0xffffffff },
  2569. { 0x0ca8, 0, 0x00000000, 0x0007ffff },
  2570. { 0x0cac, 0, 0x00000000, 0xffffffff },
  2571. { 0x0cb0, 0, 0x00000000, 0xffffffff },
  2572. { 0x0cb4, 0, 0x00000000, 0xffffffff },
  2573. { 0x0cb8, 0, 0x00000000, 0xffffffff },
  2574. { 0x0cbc, 0, 0x00000000, 0xffffffff },
  2575. { 0x0cc0, 0, 0x00000000, 0xffffffff },
  2576. { 0x0cc4, 0, 0x00000000, 0xffffffff },
  2577. { 0x0cc8, 0, 0x00000000, 0xffffffff },
  2578. { 0x0ccc, 0, 0x00000000, 0xffffffff },
  2579. { 0x0cd0, 0, 0x00000000, 0xffffffff },
  2580. { 0x0cd4, 0, 0x00000000, 0xffffffff },
  2581. { 0x0cd8, 0, 0x00000000, 0xffffffff },
  2582. { 0x0cdc, 0, 0x00000000, 0xffffffff },
  2583. { 0x0ce0, 0, 0x00000000, 0xffffffff },
  2584. { 0x0ce4, 0, 0x00000000, 0xffffffff },
  2585. { 0x0ce8, 0, 0x00000000, 0xffffffff },
  2586. { 0x0cec, 0, 0x00000000, 0xffffffff },
  2587. { 0x0cf0, 0, 0x00000000, 0xffffffff },
  2588. { 0x0cf4, 0, 0x00000000, 0xffffffff },
  2589. { 0x0cf8, 0, 0x00000000, 0xffffffff },
  2590. { 0x0cfc, 0, 0x00000000, 0xffffffff },
  2591. { 0x0d00, 0, 0x00000000, 0xffffffff },
  2592. { 0x0d04, 0, 0x00000000, 0xffffffff },
  2593. { 0x1000, 0, 0x00000000, 0x00000001 },
  2594. { 0x1004, 0, 0x00000000, 0x000f0001 },
  2595. { 0x1044, 0, 0x00000000, 0xffc003ff },
  2596. { 0x1080, 0, 0x00000000, 0x0001ffff },
  2597. { 0x1084, 0, 0x00000000, 0xffffffff },
  2598. { 0x1088, 0, 0x00000000, 0xffffffff },
  2599. { 0x108c, 0, 0x00000000, 0xffffffff },
  2600. { 0x1090, 0, 0x00000000, 0xffffffff },
  2601. { 0x1094, 0, 0x00000000, 0xffffffff },
  2602. { 0x1098, 0, 0x00000000, 0xffffffff },
  2603. { 0x109c, 0, 0x00000000, 0xffffffff },
  2604. { 0x10a0, 0, 0x00000000, 0xffffffff },
  2605. { 0x1408, 0, 0x01c00800, 0x00000000 },
  2606. { 0x149c, 0, 0x8000ffff, 0x00000000 },
  2607. { 0x14a8, 0, 0x00000000, 0x000001ff },
  2608. { 0x14ac, 0, 0x4fffffff, 0x10000000 },
  2609. { 0x14b0, 0, 0x00000002, 0x00000001 },
  2610. { 0x14b8, 0, 0x00000000, 0x00000000 },
  2611. { 0x14c0, 0, 0x00000000, 0x00000009 },
  2612. { 0x14c4, 0, 0x00003fff, 0x00000000 },
  2613. { 0x14cc, 0, 0x00000000, 0x00000001 },
  2614. { 0x14d0, 0, 0xffffffff, 0x00000000 },
  2615. { 0x1500, 0, 0x00000000, 0xffffffff },
  2616. { 0x1504, 0, 0x00000000, 0xffffffff },
  2617. { 0x1508, 0, 0x00000000, 0xffffffff },
  2618. { 0x150c, 0, 0x00000000, 0xffffffff },
  2619. { 0x1510, 0, 0x00000000, 0xffffffff },
  2620. { 0x1514, 0, 0x00000000, 0xffffffff },
  2621. { 0x1518, 0, 0x00000000, 0xffffffff },
  2622. { 0x151c, 0, 0x00000000, 0xffffffff },
  2623. { 0x1520, 0, 0x00000000, 0xffffffff },
  2624. { 0x1524, 0, 0x00000000, 0xffffffff },
  2625. { 0x1528, 0, 0x00000000, 0xffffffff },
  2626. { 0x152c, 0, 0x00000000, 0xffffffff },
  2627. { 0x1530, 0, 0x00000000, 0xffffffff },
  2628. { 0x1534, 0, 0x00000000, 0xffffffff },
  2629. { 0x1538, 0, 0x00000000, 0xffffffff },
  2630. { 0x153c, 0, 0x00000000, 0xffffffff },
  2631. { 0x1540, 0, 0x00000000, 0xffffffff },
  2632. { 0x1544, 0, 0x00000000, 0xffffffff },
  2633. { 0x1548, 0, 0x00000000, 0xffffffff },
  2634. { 0x154c, 0, 0x00000000, 0xffffffff },
  2635. { 0x1550, 0, 0x00000000, 0xffffffff },
  2636. { 0x1554, 0, 0x00000000, 0xffffffff },
  2637. { 0x1558, 0, 0x00000000, 0xffffffff },
  2638. { 0x1600, 0, 0x00000000, 0xffffffff },
  2639. { 0x1604, 0, 0x00000000, 0xffffffff },
  2640. { 0x1608, 0, 0x00000000, 0xffffffff },
  2641. { 0x160c, 0, 0x00000000, 0xffffffff },
  2642. { 0x1610, 0, 0x00000000, 0xffffffff },
  2643. { 0x1614, 0, 0x00000000, 0xffffffff },
  2644. { 0x1618, 0, 0x00000000, 0xffffffff },
  2645. { 0x161c, 0, 0x00000000, 0xffffffff },
  2646. { 0x1620, 0, 0x00000000, 0xffffffff },
  2647. { 0x1624, 0, 0x00000000, 0xffffffff },
  2648. { 0x1628, 0, 0x00000000, 0xffffffff },
  2649. { 0x162c, 0, 0x00000000, 0xffffffff },
  2650. { 0x1630, 0, 0x00000000, 0xffffffff },
  2651. { 0x1634, 0, 0x00000000, 0xffffffff },
  2652. { 0x1638, 0, 0x00000000, 0xffffffff },
  2653. { 0x163c, 0, 0x00000000, 0xffffffff },
  2654. { 0x1640, 0, 0x00000000, 0xffffffff },
  2655. { 0x1644, 0, 0x00000000, 0xffffffff },
  2656. { 0x1648, 0, 0x00000000, 0xffffffff },
  2657. { 0x164c, 0, 0x00000000, 0xffffffff },
  2658. { 0x1650, 0, 0x00000000, 0xffffffff },
  2659. { 0x1654, 0, 0x00000000, 0xffffffff },
  2660. { 0x1800, 0, 0x00000000, 0x00000001 },
  2661. { 0x1804, 0, 0x00000000, 0x00000003 },
  2662. { 0x1840, 0, 0x00000000, 0xffffffff },
  2663. { 0x1844, 0, 0x00000000, 0xffffffff },
  2664. { 0x1848, 0, 0x00000000, 0xffffffff },
  2665. { 0x184c, 0, 0x00000000, 0xffffffff },
  2666. { 0x1850, 0, 0x00000000, 0xffffffff },
  2667. { 0x1900, 0, 0x7ffbffff, 0x00000000 },
  2668. { 0x1904, 0, 0xffffffff, 0x00000000 },
  2669. { 0x190c, 0, 0xffffffff, 0x00000000 },
  2670. { 0x1914, 0, 0xffffffff, 0x00000000 },
  2671. { 0x191c, 0, 0xffffffff, 0x00000000 },
  2672. { 0x1924, 0, 0xffffffff, 0x00000000 },
  2673. { 0x192c, 0, 0xffffffff, 0x00000000 },
  2674. { 0x1934, 0, 0xffffffff, 0x00000000 },
  2675. { 0x193c, 0, 0xffffffff, 0x00000000 },
  2676. { 0x1944, 0, 0xffffffff, 0x00000000 },
  2677. { 0x194c, 0, 0xffffffff, 0x00000000 },
  2678. { 0x1954, 0, 0xffffffff, 0x00000000 },
  2679. { 0x195c, 0, 0xffffffff, 0x00000000 },
  2680. { 0x1964, 0, 0xffffffff, 0x00000000 },
  2681. { 0x196c, 0, 0xffffffff, 0x00000000 },
  2682. { 0x1974, 0, 0xffffffff, 0x00000000 },
  2683. { 0x197c, 0, 0xffffffff, 0x00000000 },
  2684. { 0x1980, 0, 0x0700ffff, 0x00000000 },
  2685. { 0x1c00, 0, 0x00000000, 0x00000001 },
  2686. { 0x1c04, 0, 0x00000000, 0x00000003 },
  2687. { 0x1c08, 0, 0x0000000f, 0x00000000 },
  2688. { 0x1c40, 0, 0x00000000, 0xffffffff },
  2689. { 0x1c44, 0, 0x00000000, 0xffffffff },
  2690. { 0x1c48, 0, 0x00000000, 0xffffffff },
  2691. { 0x1c4c, 0, 0x00000000, 0xffffffff },
  2692. { 0x1c50, 0, 0x00000000, 0xffffffff },
  2693. { 0x1d00, 0, 0x7ffbffff, 0x00000000 },
  2694. { 0x1d04, 0, 0xffffffff, 0x00000000 },
  2695. { 0x1d0c, 0, 0xffffffff, 0x00000000 },
  2696. { 0x1d14, 0, 0xffffffff, 0x00000000 },
  2697. { 0x1d1c, 0, 0xffffffff, 0x00000000 },
  2698. { 0x1d24, 0, 0xffffffff, 0x00000000 },
  2699. { 0x1d2c, 0, 0xffffffff, 0x00000000 },
  2700. { 0x1d34, 0, 0xffffffff, 0x00000000 },
  2701. { 0x1d3c, 0, 0xffffffff, 0x00000000 },
  2702. { 0x1d44, 0, 0xffffffff, 0x00000000 },
  2703. { 0x1d4c, 0, 0xffffffff, 0x00000000 },
  2704. { 0x1d54, 0, 0xffffffff, 0x00000000 },
  2705. { 0x1d5c, 0, 0xffffffff, 0x00000000 },
  2706. { 0x1d64, 0, 0xffffffff, 0x00000000 },
  2707. { 0x1d6c, 0, 0xffffffff, 0x00000000 },
  2708. { 0x1d74, 0, 0xffffffff, 0x00000000 },
  2709. { 0x1d7c, 0, 0xffffffff, 0x00000000 },
  2710. { 0x1d80, 0, 0x0700ffff, 0x00000000 },
  2711. { 0x2004, 0, 0x00000000, 0x0337000f },
  2712. { 0x2008, 0, 0xffffffff, 0x00000000 },
  2713. { 0x200c, 0, 0xffffffff, 0x00000000 },
  2714. { 0x2010, 0, 0xffffffff, 0x00000000 },
  2715. { 0x2014, 0, 0x801fff80, 0x00000000 },
  2716. { 0x2018, 0, 0x000003ff, 0x00000000 },
  2717. { 0x2800, 0, 0x00000000, 0x00000001 },
  2718. { 0x2804, 0, 0x00000000, 0x00003f01 },
  2719. { 0x2808, 0, 0x0f3f3f03, 0x00000000 },
  2720. { 0x2810, 0, 0xffff0000, 0x00000000 },
  2721. { 0x2814, 0, 0xffff0000, 0x00000000 },
  2722. { 0x2818, 0, 0xffff0000, 0x00000000 },
  2723. { 0x281c, 0, 0xffff0000, 0x00000000 },
  2724. { 0x2834, 0, 0xffffffff, 0x00000000 },
  2725. { 0x2840, 0, 0x00000000, 0xffffffff },
  2726. { 0x2844, 0, 0x00000000, 0xffffffff },
  2727. { 0x2848, 0, 0xffffffff, 0x00000000 },
  2728. { 0x284c, 0, 0xf800f800, 0x07ff07ff },
  2729. { 0x2c00, 0, 0x00000000, 0x00000011 },
  2730. { 0x2c04, 0, 0x00000000, 0x00030007 },
  2731. { 0x3000, 0, 0x00000000, 0x00000001 },
  2732. { 0x3004, 0, 0x00000000, 0x007007ff },
  2733. { 0x3008, 0, 0x00000003, 0x00000000 },
  2734. { 0x300c, 0, 0xffffffff, 0x00000000 },
  2735. { 0x3010, 0, 0xffffffff, 0x00000000 },
  2736. { 0x3014, 0, 0xffffffff, 0x00000000 },
  2737. { 0x3034, 0, 0xffffffff, 0x00000000 },
  2738. { 0x3038, 0, 0xffffffff, 0x00000000 },
  2739. { 0x3050, 0, 0x00000001, 0x00000000 },
  2740. { 0x3c00, 0, 0x00000000, 0x00000001 },
  2741. { 0x3c04, 0, 0x00000000, 0x00070000 },
  2742. { 0x3c08, 0, 0x00007f71, 0x07f00000 },
  2743. { 0x3c0c, 0, 0x1f3ffffc, 0x00000000 },
  2744. { 0x3c10, 0, 0xffffffff, 0x00000000 },
  2745. { 0x3c14, 0, 0x00000000, 0xffffffff },
  2746. { 0x3c18, 0, 0x00000000, 0xffffffff },
  2747. { 0x3c1c, 0, 0xfffff000, 0x00000000 },
  2748. { 0x3c20, 0, 0xffffff00, 0x00000000 },
  2749. { 0x3c24, 0, 0xffffffff, 0x00000000 },
  2750. { 0x3c28, 0, 0xffffffff, 0x00000000 },
  2751. { 0x3c2c, 0, 0xffffffff, 0x00000000 },
  2752. { 0x3c30, 0, 0xffffffff, 0x00000000 },
  2753. { 0x3c34, 0, 0xffffffff, 0x00000000 },
  2754. { 0x3c38, 0, 0xffffffff, 0x00000000 },
  2755. { 0x3c3c, 0, 0xffffffff, 0x00000000 },
  2756. { 0x3c40, 0, 0xffffffff, 0x00000000 },
  2757. { 0x3c44, 0, 0xffffffff, 0x00000000 },
  2758. { 0x3c48, 0, 0xffffffff, 0x00000000 },
  2759. { 0x3c4c, 0, 0xffffffff, 0x00000000 },
  2760. { 0x3c50, 0, 0xffffffff, 0x00000000 },
  2761. { 0x3c54, 0, 0xffffffff, 0x00000000 },
  2762. { 0x3c58, 0, 0xffffffff, 0x00000000 },
  2763. { 0x3c5c, 0, 0xffffffff, 0x00000000 },
  2764. { 0x3c60, 0, 0xffffffff, 0x00000000 },
  2765. { 0x3c64, 0, 0xffffffff, 0x00000000 },
  2766. { 0x3c68, 0, 0xffffffff, 0x00000000 },
  2767. { 0x3c6c, 0, 0xffffffff, 0x00000000 },
  2768. { 0x3c70, 0, 0xffffffff, 0x00000000 },
  2769. { 0x3c74, 0, 0x0000003f, 0x00000000 },
  2770. { 0x3c78, 0, 0x00000000, 0x00000000 },
  2771. { 0x3c7c, 0, 0x00000000, 0x00000000 },
  2772. { 0x3c80, 0, 0x3fffffff, 0x00000000 },
  2773. { 0x3c84, 0, 0x0000003f, 0x00000000 },
  2774. { 0x3c88, 0, 0x00000000, 0xffffffff },
  2775. { 0x3c8c, 0, 0x00000000, 0xffffffff },
  2776. { 0x4000, 0, 0x00000000, 0x00000001 },
  2777. { 0x4004, 0, 0x00000000, 0x00030000 },
  2778. { 0x4008, 0, 0x00000ff0, 0x00000000 },
  2779. { 0x400c, 0, 0xffffffff, 0x00000000 },
  2780. { 0x4088, 0, 0x00000000, 0x00070303 },
  2781. { 0x4400, 0, 0x00000000, 0x00000001 },
  2782. { 0x4404, 0, 0x00000000, 0x00003f01 },
  2783. { 0x4408, 0, 0x7fff00ff, 0x00000000 },
  2784. { 0x440c, 0, 0xffffffff, 0x00000000 },
  2785. { 0x4410, 0, 0xffff, 0x0000 },
  2786. { 0x4414, 0, 0xffff, 0x0000 },
  2787. { 0x4418, 0, 0xffff, 0x0000 },
  2788. { 0x441c, 0, 0xffff, 0x0000 },
  2789. { 0x4428, 0, 0xffffffff, 0x00000000 },
  2790. { 0x442c, 0, 0xffffffff, 0x00000000 },
  2791. { 0x4430, 0, 0xffffffff, 0x00000000 },
  2792. { 0x4434, 0, 0xffffffff, 0x00000000 },
  2793. { 0x4438, 0, 0xffffffff, 0x00000000 },
  2794. { 0x443c, 0, 0xffffffff, 0x00000000 },
  2795. { 0x4440, 0, 0xffffffff, 0x00000000 },
  2796. { 0x4444, 0, 0xffffffff, 0x00000000 },
  2797. { 0x4c00, 0, 0x00000000, 0x00000001 },
  2798. { 0x4c04, 0, 0x00000000, 0x0000003f },
  2799. { 0x4c08, 0, 0xffffffff, 0x00000000 },
  2800. { 0x4c0c, 0, 0x0007fc00, 0x00000000 },
  2801. { 0x4c10, 0, 0x80003fe0, 0x00000000 },
  2802. { 0x4c14, 0, 0xffffffff, 0x00000000 },
  2803. { 0x4c44, 0, 0x00000000, 0x9fff9fff },
  2804. { 0x4c48, 0, 0x00000000, 0xb3009fff },
  2805. { 0x4c4c, 0, 0x00000000, 0x77f33b30 },
  2806. { 0x4c50, 0, 0x00000000, 0xffffffff },
  2807. { 0x5004, 0, 0x00000000, 0x0000007f },
  2808. { 0x5008, 0, 0x0f0007ff, 0x00000000 },
  2809. { 0x500c, 0, 0xf800f800, 0x07ff07ff },
  2810. { 0x5400, 0, 0x00000008, 0x00000001 },
  2811. { 0x5404, 0, 0x00000000, 0x0000003f },
  2812. { 0x5408, 0, 0x0000001f, 0x00000000 },
  2813. { 0x540c, 0, 0xffffffff, 0x00000000 },
  2814. { 0x5410, 0, 0xffffffff, 0x00000000 },
  2815. { 0x5414, 0, 0x0000ffff, 0x00000000 },
  2816. { 0x5418, 0, 0x0000ffff, 0x00000000 },
  2817. { 0x541c, 0, 0x0000ffff, 0x00000000 },
  2818. { 0x5420, 0, 0x0000ffff, 0x00000000 },
  2819. { 0x5428, 0, 0x000000ff, 0x00000000 },
  2820. { 0x542c, 0, 0xff00ffff, 0x00000000 },
  2821. { 0x5430, 0, 0x001fff80, 0x00000000 },
  2822. { 0x5438, 0, 0xffffffff, 0x00000000 },
  2823. { 0x543c, 0, 0xffffffff, 0x00000000 },
  2824. { 0x5440, 0, 0xf800f800, 0x07ff07ff },
  2825. { 0x5c00, 0, 0x00000000, 0x00000001 },
  2826. { 0x5c04, 0, 0x00000000, 0x0003000f },
  2827. { 0x5c08, 0, 0x00000003, 0x00000000 },
  2828. { 0x5c0c, 0, 0x0000fff8, 0x00000000 },
  2829. { 0x5c10, 0, 0x00000000, 0xffffffff },
  2830. { 0x5c80, 0, 0x00000000, 0x0f7113f1 },
  2831. { 0x5c84, 0, 0x00000000, 0x0000f333 },
  2832. { 0x5c88, 0, 0x00000000, 0x00077373 },
  2833. { 0x5c8c, 0, 0x00000000, 0x0007f737 },
  2834. { 0x6808, 0, 0x0000ff7f, 0x00000000 },
  2835. { 0x680c, 0, 0xffffffff, 0x00000000 },
  2836. { 0x6810, 0, 0xffffffff, 0x00000000 },
  2837. { 0x6814, 0, 0xffffffff, 0x00000000 },
  2838. { 0x6818, 0, 0xffffffff, 0x00000000 },
  2839. { 0x681c, 0, 0xffffffff, 0x00000000 },
  2840. { 0x6820, 0, 0x00ff00ff, 0x00000000 },
  2841. { 0x6824, 0, 0x00ff00ff, 0x00000000 },
  2842. { 0x6828, 0, 0x00ff00ff, 0x00000000 },
  2843. { 0x682c, 0, 0x03ff03ff, 0x00000000 },
  2844. { 0x6830, 0, 0x03ff03ff, 0x00000000 },
  2845. { 0x6834, 0, 0x03ff03ff, 0x00000000 },
  2846. { 0x6838, 0, 0x03ff03ff, 0x00000000 },
  2847. { 0x683c, 0, 0x0000ffff, 0x00000000 },
  2848. { 0x6840, 0, 0x00000ff0, 0x00000000 },
  2849. { 0x6844, 0, 0x00ffff00, 0x00000000 },
  2850. { 0x684c, 0, 0xffffffff, 0x00000000 },
  2851. { 0x6850, 0, 0x7f7f7f7f, 0x00000000 },
  2852. { 0x6854, 0, 0x7f7f7f7f, 0x00000000 },
  2853. { 0x6858, 0, 0x7f7f7f7f, 0x00000000 },
  2854. { 0x685c, 0, 0x7f7f7f7f, 0x00000000 },
  2855. { 0x6908, 0, 0x00000000, 0x0001ff0f },
  2856. { 0x690c, 0, 0x00000000, 0x0ffe00f0 },
  2857. { 0xffff, 0, 0x00000000, 0x00000000 },
  2858. };
  2859. ret = 0;
  2860. for (i = 0; reg_tbl[i].offset != 0xffff; i++) {
  2861. u32 offset, rw_mask, ro_mask, save_val, val;
  2862. offset = (u32) reg_tbl[i].offset;
  2863. rw_mask = reg_tbl[i].rw_mask;
  2864. ro_mask = reg_tbl[i].ro_mask;
  2865. save_val = readl(bp->regview + offset);
  2866. writel(0, bp->regview + offset);
  2867. val = readl(bp->regview + offset);
  2868. if ((val & rw_mask) != 0) {
  2869. goto reg_test_err;
  2870. }
  2871. if ((val & ro_mask) != (save_val & ro_mask)) {
  2872. goto reg_test_err;
  2873. }
  2874. writel(0xffffffff, bp->regview + offset);
  2875. val = readl(bp->regview + offset);
  2876. if ((val & rw_mask) != rw_mask) {
  2877. goto reg_test_err;
  2878. }
  2879. if ((val & ro_mask) != (save_val & ro_mask)) {
  2880. goto reg_test_err;
  2881. }
  2882. writel(save_val, bp->regview + offset);
  2883. continue;
  2884. reg_test_err:
  2885. writel(save_val, bp->regview + offset);
  2886. ret = -ENODEV;
  2887. break;
  2888. }
  2889. return ret;
  2890. }
  2891. static int
  2892. bnx2_do_mem_test(struct bnx2 *bp, u32 start, u32 size)
  2893. {
  2894. static u32 test_pattern[] = { 0x00000000, 0xffffffff, 0x55555555,
  2895. 0xaaaaaaaa , 0xaa55aa55, 0x55aa55aa };
  2896. int i;
  2897. for (i = 0; i < sizeof(test_pattern) / 4; i++) {
  2898. u32 offset;
  2899. for (offset = 0; offset < size; offset += 4) {
  2900. REG_WR_IND(bp, start + offset, test_pattern[i]);
  2901. if (REG_RD_IND(bp, start + offset) !=
  2902. test_pattern[i]) {
  2903. return -ENODEV;
  2904. }
  2905. }
  2906. }
  2907. return 0;
  2908. }
  2909. static int
  2910. bnx2_test_memory(struct bnx2 *bp)
  2911. {
  2912. int ret = 0;
  2913. int i;
  2914. static struct {
  2915. u32 offset;
  2916. u32 len;
  2917. } mem_tbl[] = {
  2918. { 0x60000, 0x4000 },
  2919. { 0xa0000, 0x4000 },
  2920. { 0xe0000, 0x4000 },
  2921. { 0x120000, 0x4000 },
  2922. { 0x1a0000, 0x4000 },
  2923. { 0x160000, 0x4000 },
  2924. { 0xffffffff, 0 },
  2925. };
  2926. for (i = 0; mem_tbl[i].offset != 0xffffffff; i++) {
  2927. if ((ret = bnx2_do_mem_test(bp, mem_tbl[i].offset,
  2928. mem_tbl[i].len)) != 0) {
  2929. return ret;
  2930. }
  2931. }
  2932. return ret;
  2933. }
  2934. static int
  2935. bnx2_test_loopback(struct bnx2 *bp)
  2936. {
  2937. unsigned int pkt_size, num_pkts, i;
  2938. struct sk_buff *skb, *rx_skb;
  2939. unsigned char *packet;
  2940. u16 rx_start_idx, rx_idx, send_idx;
  2941. u32 send_bseq, val;
  2942. dma_addr_t map;
  2943. struct tx_bd *txbd;
  2944. struct sw_bd *rx_buf;
  2945. struct l2_fhdr *rx_hdr;
  2946. int ret = -ENODEV;
  2947. if (!netif_running(bp->dev))
  2948. return -ENODEV;
  2949. bp->loopback = MAC_LOOPBACK;
  2950. bnx2_reset_nic(bp, BNX2_DRV_MSG_CODE_DIAG);
  2951. bnx2_set_mac_loopback(bp);
  2952. pkt_size = 1514;
  2953. skb = dev_alloc_skb(pkt_size);
  2954. packet = skb_put(skb, pkt_size);
  2955. memcpy(packet, bp->mac_addr, 6);
  2956. memset(packet + 6, 0x0, 8);
  2957. for (i = 14; i < pkt_size; i++)
  2958. packet[i] = (unsigned char) (i & 0xff);
  2959. map = pci_map_single(bp->pdev, skb->data, pkt_size,
  2960. PCI_DMA_TODEVICE);
  2961. val = REG_RD(bp, BNX2_HC_COMMAND);
  2962. REG_WR(bp, BNX2_HC_COMMAND, val | BNX2_HC_COMMAND_COAL_NOW_WO_INT);
  2963. REG_RD(bp, BNX2_HC_COMMAND);
  2964. udelay(5);
  2965. rx_start_idx = bp->status_blk->status_rx_quick_consumer_index0;
  2966. send_idx = 0;
  2967. send_bseq = 0;
  2968. num_pkts = 0;
  2969. txbd = &bp->tx_desc_ring[send_idx];
  2970. txbd->tx_bd_haddr_hi = (u64) map >> 32;
  2971. txbd->tx_bd_haddr_lo = (u64) map & 0xffffffff;
  2972. txbd->tx_bd_mss_nbytes = pkt_size;
  2973. txbd->tx_bd_vlan_tag_flags = TX_BD_FLAGS_START | TX_BD_FLAGS_END;
  2974. num_pkts++;
  2975. send_idx = NEXT_TX_BD(send_idx);
  2976. send_bseq += pkt_size;
  2977. REG_WR16(bp, MB_TX_CID_ADDR + BNX2_L2CTX_TX_HOST_BIDX, send_idx);
  2978. REG_WR(bp, MB_TX_CID_ADDR + BNX2_L2CTX_TX_HOST_BSEQ, send_bseq);
  2979. udelay(100);
  2980. val = REG_RD(bp, BNX2_HC_COMMAND);
  2981. REG_WR(bp, BNX2_HC_COMMAND, val | BNX2_HC_COMMAND_COAL_NOW_WO_INT);
  2982. REG_RD(bp, BNX2_HC_COMMAND);
  2983. udelay(5);
  2984. pci_unmap_single(bp->pdev, map, pkt_size, PCI_DMA_TODEVICE);
  2985. dev_kfree_skb_irq(skb);
  2986. if (bp->status_blk->status_tx_quick_consumer_index0 != send_idx) {
  2987. goto loopback_test_done;
  2988. }
  2989. rx_idx = bp->status_blk->status_rx_quick_consumer_index0;
  2990. if (rx_idx != rx_start_idx + num_pkts) {
  2991. goto loopback_test_done;
  2992. }
  2993. rx_buf = &bp->rx_buf_ring[rx_start_idx];
  2994. rx_skb = rx_buf->skb;
  2995. rx_hdr = (struct l2_fhdr *) rx_skb->data;
  2996. skb_reserve(rx_skb, bp->rx_offset);
  2997. pci_dma_sync_single_for_cpu(bp->pdev,
  2998. pci_unmap_addr(rx_buf, mapping),
  2999. bp->rx_buf_size, PCI_DMA_FROMDEVICE);
  3000. if (rx_hdr->l2_fhdr_errors &
  3001. (L2_FHDR_ERRORS_BAD_CRC |
  3002. L2_FHDR_ERRORS_PHY_DECODE |
  3003. L2_FHDR_ERRORS_ALIGNMENT |
  3004. L2_FHDR_ERRORS_TOO_SHORT |
  3005. L2_FHDR_ERRORS_GIANT_FRAME)) {
  3006. goto loopback_test_done;
  3007. }
  3008. if ((rx_hdr->l2_fhdr_pkt_len - 4) != pkt_size) {
  3009. goto loopback_test_done;
  3010. }
  3011. for (i = 14; i < pkt_size; i++) {
  3012. if (*(rx_skb->data + i) != (unsigned char) (i & 0xff)) {
  3013. goto loopback_test_done;
  3014. }
  3015. }
  3016. ret = 0;
  3017. loopback_test_done:
  3018. bp->loopback = 0;
  3019. return ret;
  3020. }
  3021. #define NVRAM_SIZE 0x200
  3022. #define CRC32_RESIDUAL 0xdebb20e3
  3023. static int
  3024. bnx2_test_nvram(struct bnx2 *bp)
  3025. {
  3026. u32 buf[NVRAM_SIZE / 4];
  3027. u8 *data = (u8 *) buf;
  3028. int rc = 0;
  3029. u32 magic, csum;
  3030. if ((rc = bnx2_nvram_read(bp, 0, data, 4)) != 0)
  3031. goto test_nvram_done;
  3032. magic = be32_to_cpu(buf[0]);
  3033. if (magic != 0x669955aa) {
  3034. rc = -ENODEV;
  3035. goto test_nvram_done;
  3036. }
  3037. if ((rc = bnx2_nvram_read(bp, 0x100, data, NVRAM_SIZE)) != 0)
  3038. goto test_nvram_done;
  3039. csum = ether_crc_le(0x100, data);
  3040. if (csum != CRC32_RESIDUAL) {
  3041. rc = -ENODEV;
  3042. goto test_nvram_done;
  3043. }
  3044. csum = ether_crc_le(0x100, data + 0x100);
  3045. if (csum != CRC32_RESIDUAL) {
  3046. rc = -ENODEV;
  3047. }
  3048. test_nvram_done:
  3049. return rc;
  3050. }
  3051. static int
  3052. bnx2_test_link(struct bnx2 *bp)
  3053. {
  3054. u32 bmsr;
  3055. spin_lock_irq(&bp->phy_lock);
  3056. bnx2_read_phy(bp, MII_BMSR, &bmsr);
  3057. bnx2_read_phy(bp, MII_BMSR, &bmsr);
  3058. spin_unlock_irq(&bp->phy_lock);
  3059. if (bmsr & BMSR_LSTATUS) {
  3060. return 0;
  3061. }
  3062. return -ENODEV;
  3063. }
  3064. static int
  3065. bnx2_test_intr(struct bnx2 *bp)
  3066. {
  3067. int i;
  3068. u32 val;
  3069. u16 status_idx;
  3070. if (!netif_running(bp->dev))
  3071. return -ENODEV;
  3072. status_idx = REG_RD(bp, BNX2_PCICFG_INT_ACK_CMD) & 0xffff;
  3073. /* This register is not touched during run-time. */
  3074. val = REG_RD(bp, BNX2_HC_COMMAND);
  3075. REG_WR(bp, BNX2_HC_COMMAND, val | BNX2_HC_COMMAND_COAL_NOW);
  3076. REG_RD(bp, BNX2_HC_COMMAND);
  3077. for (i = 0; i < 10; i++) {
  3078. if ((REG_RD(bp, BNX2_PCICFG_INT_ACK_CMD) & 0xffff) !=
  3079. status_idx) {
  3080. break;
  3081. }
  3082. msleep_interruptible(10);
  3083. }
  3084. if (i < 10)
  3085. return 0;
  3086. return -ENODEV;
  3087. }
  3088. static void
  3089. bnx2_timer(unsigned long data)
  3090. {
  3091. struct bnx2 *bp = (struct bnx2 *) data;
  3092. u32 msg;
  3093. if (!netif_running(bp->dev))
  3094. return;
  3095. if (atomic_read(&bp->intr_sem) != 0)
  3096. goto bnx2_restart_timer;
  3097. msg = (u32) ++bp->fw_drv_pulse_wr_seq;
  3098. REG_WR_IND(bp, HOST_VIEW_SHMEM_BASE + BNX2_DRV_PULSE_MB, msg);
  3099. if ((bp->phy_flags & PHY_SERDES_FLAG) &&
  3100. (CHIP_NUM(bp) == CHIP_NUM_5706)) {
  3101. unsigned long flags;
  3102. spin_lock_irqsave(&bp->phy_lock, flags);
  3103. if (bp->serdes_an_pending) {
  3104. bp->serdes_an_pending--;
  3105. }
  3106. else if ((bp->link_up == 0) && (bp->autoneg & AUTONEG_SPEED)) {
  3107. u32 bmcr;
  3108. bp->current_interval = bp->timer_interval;
  3109. bnx2_read_phy(bp, MII_BMCR, &bmcr);
  3110. if (bmcr & BMCR_ANENABLE) {
  3111. u32 phy1, phy2;
  3112. bnx2_write_phy(bp, 0x1c, 0x7c00);
  3113. bnx2_read_phy(bp, 0x1c, &phy1);
  3114. bnx2_write_phy(bp, 0x17, 0x0f01);
  3115. bnx2_read_phy(bp, 0x15, &phy2);
  3116. bnx2_write_phy(bp, 0x17, 0x0f01);
  3117. bnx2_read_phy(bp, 0x15, &phy2);
  3118. if ((phy1 & 0x10) && /* SIGNAL DETECT */
  3119. !(phy2 & 0x20)) { /* no CONFIG */
  3120. bmcr &= ~BMCR_ANENABLE;
  3121. bmcr |= BMCR_SPEED1000 |
  3122. BMCR_FULLDPLX;
  3123. bnx2_write_phy(bp, MII_BMCR, bmcr);
  3124. bp->phy_flags |=
  3125. PHY_PARALLEL_DETECT_FLAG;
  3126. }
  3127. }
  3128. }
  3129. else if ((bp->link_up) && (bp->autoneg & AUTONEG_SPEED) &&
  3130. (bp->phy_flags & PHY_PARALLEL_DETECT_FLAG)) {
  3131. u32 phy2;
  3132. bnx2_write_phy(bp, 0x17, 0x0f01);
  3133. bnx2_read_phy(bp, 0x15, &phy2);
  3134. if (phy2 & 0x20) {
  3135. u32 bmcr;
  3136. bnx2_read_phy(bp, MII_BMCR, &bmcr);
  3137. bmcr |= BMCR_ANENABLE;
  3138. bnx2_write_phy(bp, MII_BMCR, bmcr);
  3139. bp->phy_flags &= ~PHY_PARALLEL_DETECT_FLAG;
  3140. }
  3141. }
  3142. else
  3143. bp->current_interval = bp->timer_interval;
  3144. spin_unlock_irqrestore(&bp->phy_lock, flags);
  3145. }
  3146. bnx2_restart_timer:
  3147. mod_timer(&bp->timer, jiffies + bp->current_interval);
  3148. }
  3149. /* Called with rtnl_lock */
  3150. static int
  3151. bnx2_open(struct net_device *dev)
  3152. {
  3153. struct bnx2 *bp = dev->priv;
  3154. int rc;
  3155. bnx2_set_power_state(bp, 0);
  3156. bnx2_disable_int(bp);
  3157. rc = bnx2_alloc_mem(bp);
  3158. if (rc)
  3159. return rc;
  3160. if ((CHIP_ID(bp) != CHIP_ID_5706_A0) &&
  3161. (CHIP_ID(bp) != CHIP_ID_5706_A1) &&
  3162. !disable_msi) {
  3163. if (pci_enable_msi(bp->pdev) == 0) {
  3164. bp->flags |= USING_MSI_FLAG;
  3165. rc = request_irq(bp->pdev->irq, bnx2_msi, 0, dev->name,
  3166. dev);
  3167. }
  3168. else {
  3169. rc = request_irq(bp->pdev->irq, bnx2_interrupt,
  3170. SA_SHIRQ, dev->name, dev);
  3171. }
  3172. }
  3173. else {
  3174. rc = request_irq(bp->pdev->irq, bnx2_interrupt, SA_SHIRQ,
  3175. dev->name, dev);
  3176. }
  3177. if (rc) {
  3178. bnx2_free_mem(bp);
  3179. return rc;
  3180. }
  3181. rc = bnx2_init_nic(bp);
  3182. if (rc) {
  3183. free_irq(bp->pdev->irq, dev);
  3184. if (bp->flags & USING_MSI_FLAG) {
  3185. pci_disable_msi(bp->pdev);
  3186. bp->flags &= ~USING_MSI_FLAG;
  3187. }
  3188. bnx2_free_skbs(bp);
  3189. bnx2_free_mem(bp);
  3190. return rc;
  3191. }
  3192. mod_timer(&bp->timer, jiffies + bp->current_interval);
  3193. atomic_set(&bp->intr_sem, 0);
  3194. bnx2_enable_int(bp);
  3195. if (bp->flags & USING_MSI_FLAG) {
  3196. /* Test MSI to make sure it is working
  3197. * If MSI test fails, go back to INTx mode
  3198. */
  3199. if (bnx2_test_intr(bp) != 0) {
  3200. printk(KERN_WARNING PFX "%s: No interrupt was generated"
  3201. " using MSI, switching to INTx mode. Please"
  3202. " report this failure to the PCI maintainer"
  3203. " and include system chipset information.\n",
  3204. bp->dev->name);
  3205. bnx2_disable_int(bp);
  3206. free_irq(bp->pdev->irq, dev);
  3207. pci_disable_msi(bp->pdev);
  3208. bp->flags &= ~USING_MSI_FLAG;
  3209. rc = bnx2_init_nic(bp);
  3210. if (!rc) {
  3211. rc = request_irq(bp->pdev->irq, bnx2_interrupt,
  3212. SA_SHIRQ, dev->name, dev);
  3213. }
  3214. if (rc) {
  3215. bnx2_free_skbs(bp);
  3216. bnx2_free_mem(bp);
  3217. del_timer_sync(&bp->timer);
  3218. return rc;
  3219. }
  3220. bnx2_enable_int(bp);
  3221. }
  3222. }
  3223. if (bp->flags & USING_MSI_FLAG) {
  3224. printk(KERN_INFO PFX "%s: using MSI\n", dev->name);
  3225. }
  3226. netif_start_queue(dev);
  3227. return 0;
  3228. }
  3229. static void
  3230. bnx2_reset_task(void *data)
  3231. {
  3232. struct bnx2 *bp = data;
  3233. if (!netif_running(bp->dev))
  3234. return;
  3235. bp->in_reset_task = 1;
  3236. bnx2_netif_stop(bp);
  3237. bnx2_init_nic(bp);
  3238. atomic_set(&bp->intr_sem, 1);
  3239. bnx2_netif_start(bp);
  3240. bp->in_reset_task = 0;
  3241. }
  3242. static void
  3243. bnx2_tx_timeout(struct net_device *dev)
  3244. {
  3245. struct bnx2 *bp = dev->priv;
  3246. /* This allows the netif to be shutdown gracefully before resetting */
  3247. schedule_work(&bp->reset_task);
  3248. }
  3249. #ifdef BCM_VLAN
  3250. /* Called with rtnl_lock */
  3251. static void
  3252. bnx2_vlan_rx_register(struct net_device *dev, struct vlan_group *vlgrp)
  3253. {
  3254. struct bnx2 *bp = dev->priv;
  3255. bnx2_netif_stop(bp);
  3256. bp->vlgrp = vlgrp;
  3257. bnx2_set_rx_mode(dev);
  3258. bnx2_netif_start(bp);
  3259. }
  3260. /* Called with rtnl_lock */
  3261. static void
  3262. bnx2_vlan_rx_kill_vid(struct net_device *dev, uint16_t vid)
  3263. {
  3264. struct bnx2 *bp = dev->priv;
  3265. bnx2_netif_stop(bp);
  3266. if (bp->vlgrp)
  3267. bp->vlgrp->vlan_devices[vid] = NULL;
  3268. bnx2_set_rx_mode(dev);
  3269. bnx2_netif_start(bp);
  3270. }
  3271. #endif
  3272. /* Called with dev->xmit_lock.
  3273. * hard_start_xmit is pseudo-lockless - a lock is only required when
  3274. * the tx queue is full. This way, we get the benefit of lockless
  3275. * operations most of the time without the complexities to handle
  3276. * netif_stop_queue/wake_queue race conditions.
  3277. */
  3278. static int
  3279. bnx2_start_xmit(struct sk_buff *skb, struct net_device *dev)
  3280. {
  3281. struct bnx2 *bp = dev->priv;
  3282. dma_addr_t mapping;
  3283. struct tx_bd *txbd;
  3284. struct sw_bd *tx_buf;
  3285. u32 len, vlan_tag_flags, last_frag, mss;
  3286. u16 prod, ring_prod;
  3287. int i;
  3288. if (unlikely(atomic_read(&bp->tx_avail_bd) <
  3289. (skb_shinfo(skb)->nr_frags + 1))) {
  3290. netif_stop_queue(dev);
  3291. printk(KERN_ERR PFX "%s: BUG! Tx ring full when queue awake!\n",
  3292. dev->name);
  3293. return NETDEV_TX_BUSY;
  3294. }
  3295. len = skb_headlen(skb);
  3296. prod = bp->tx_prod;
  3297. ring_prod = TX_RING_IDX(prod);
  3298. vlan_tag_flags = 0;
  3299. if (skb->ip_summed == CHECKSUM_HW) {
  3300. vlan_tag_flags |= TX_BD_FLAGS_TCP_UDP_CKSUM;
  3301. }
  3302. if (bp->vlgrp != 0 && vlan_tx_tag_present(skb)) {
  3303. vlan_tag_flags |=
  3304. (TX_BD_FLAGS_VLAN_TAG | (vlan_tx_tag_get(skb) << 16));
  3305. }
  3306. #ifdef BCM_TSO
  3307. if ((mss = skb_shinfo(skb)->tso_size) &&
  3308. (skb->len > (bp->dev->mtu + ETH_HLEN))) {
  3309. u32 tcp_opt_len, ip_tcp_len;
  3310. if (skb_header_cloned(skb) &&
  3311. pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) {
  3312. dev_kfree_skb(skb);
  3313. return NETDEV_TX_OK;
  3314. }
  3315. tcp_opt_len = ((skb->h.th->doff - 5) * 4);
  3316. vlan_tag_flags |= TX_BD_FLAGS_SW_LSO;
  3317. tcp_opt_len = 0;
  3318. if (skb->h.th->doff > 5) {
  3319. tcp_opt_len = (skb->h.th->doff - 5) << 2;
  3320. }
  3321. ip_tcp_len = (skb->nh.iph->ihl << 2) + sizeof(struct tcphdr);
  3322. skb->nh.iph->check = 0;
  3323. skb->nh.iph->tot_len = ntohs(mss + ip_tcp_len + tcp_opt_len);
  3324. skb->h.th->check =
  3325. ~csum_tcpudp_magic(skb->nh.iph->saddr,
  3326. skb->nh.iph->daddr,
  3327. 0, IPPROTO_TCP, 0);
  3328. if (tcp_opt_len || (skb->nh.iph->ihl > 5)) {
  3329. vlan_tag_flags |= ((skb->nh.iph->ihl - 5) +
  3330. (tcp_opt_len >> 2)) << 8;
  3331. }
  3332. }
  3333. else
  3334. #endif
  3335. {
  3336. mss = 0;
  3337. }
  3338. mapping = pci_map_single(bp->pdev, skb->data, len, PCI_DMA_TODEVICE);
  3339. tx_buf = &bp->tx_buf_ring[ring_prod];
  3340. tx_buf->skb = skb;
  3341. pci_unmap_addr_set(tx_buf, mapping, mapping);
  3342. txbd = &bp->tx_desc_ring[ring_prod];
  3343. txbd->tx_bd_haddr_hi = (u64) mapping >> 32;
  3344. txbd->tx_bd_haddr_lo = (u64) mapping & 0xffffffff;
  3345. txbd->tx_bd_mss_nbytes = len | (mss << 16);
  3346. txbd->tx_bd_vlan_tag_flags = vlan_tag_flags | TX_BD_FLAGS_START;
  3347. last_frag = skb_shinfo(skb)->nr_frags;
  3348. for (i = 0; i < last_frag; i++) {
  3349. skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  3350. prod = NEXT_TX_BD(prod);
  3351. ring_prod = TX_RING_IDX(prod);
  3352. txbd = &bp->tx_desc_ring[ring_prod];
  3353. len = frag->size;
  3354. mapping = pci_map_page(bp->pdev, frag->page, frag->page_offset,
  3355. len, PCI_DMA_TODEVICE);
  3356. pci_unmap_addr_set(&bp->tx_buf_ring[ring_prod],
  3357. mapping, mapping);
  3358. txbd->tx_bd_haddr_hi = (u64) mapping >> 32;
  3359. txbd->tx_bd_haddr_lo = (u64) mapping & 0xffffffff;
  3360. txbd->tx_bd_mss_nbytes = len | (mss << 16);
  3361. txbd->tx_bd_vlan_tag_flags = vlan_tag_flags;
  3362. }
  3363. txbd->tx_bd_vlan_tag_flags |= TX_BD_FLAGS_END;
  3364. prod = NEXT_TX_BD(prod);
  3365. bp->tx_prod_bseq += skb->len;
  3366. atomic_sub(last_frag + 1, &bp->tx_avail_bd);
  3367. REG_WR16(bp, MB_TX_CID_ADDR + BNX2_L2CTX_TX_HOST_BIDX, prod);
  3368. REG_WR(bp, MB_TX_CID_ADDR + BNX2_L2CTX_TX_HOST_BSEQ, bp->tx_prod_bseq);
  3369. mmiowb();
  3370. bp->tx_prod = prod;
  3371. dev->trans_start = jiffies;
  3372. if (unlikely(atomic_read(&bp->tx_avail_bd) <= MAX_SKB_FRAGS)) {
  3373. unsigned long flags;
  3374. spin_lock_irqsave(&bp->tx_lock, flags);
  3375. if (atomic_read(&bp->tx_avail_bd) <= MAX_SKB_FRAGS) {
  3376. netif_stop_queue(dev);
  3377. if (atomic_read(&bp->tx_avail_bd) > MAX_SKB_FRAGS)
  3378. netif_wake_queue(dev);
  3379. }
  3380. spin_unlock_irqrestore(&bp->tx_lock, flags);
  3381. }
  3382. return NETDEV_TX_OK;
  3383. }
  3384. /* Called with rtnl_lock */
  3385. static int
  3386. bnx2_close(struct net_device *dev)
  3387. {
  3388. struct bnx2 *bp = dev->priv;
  3389. u32 reset_code;
  3390. /* Calling flush_scheduled_work() may deadlock because
  3391. * linkwatch_event() may be on the workqueue and it will try to get
  3392. * the rtnl_lock which we are holding.
  3393. */
  3394. while (bp->in_reset_task)
  3395. msleep(1);
  3396. bnx2_netif_stop(bp);
  3397. del_timer_sync(&bp->timer);
  3398. if (bp->wol)
  3399. reset_code = BNX2_DRV_MSG_CODE_SUSPEND_WOL;
  3400. else
  3401. reset_code = BNX2_DRV_MSG_CODE_SUSPEND_NO_WOL;
  3402. bnx2_reset_chip(bp, reset_code);
  3403. free_irq(bp->pdev->irq, dev);
  3404. if (bp->flags & USING_MSI_FLAG) {
  3405. pci_disable_msi(bp->pdev);
  3406. bp->flags &= ~USING_MSI_FLAG;
  3407. }
  3408. bnx2_free_skbs(bp);
  3409. bnx2_free_mem(bp);
  3410. bp->link_up = 0;
  3411. netif_carrier_off(bp->dev);
  3412. bnx2_set_power_state(bp, 3);
  3413. return 0;
  3414. }
  3415. #define GET_NET_STATS64(ctr) \
  3416. (unsigned long) ((unsigned long) (ctr##_hi) << 32) + \
  3417. (unsigned long) (ctr##_lo)
  3418. #define GET_NET_STATS32(ctr) \
  3419. (ctr##_lo)
  3420. #if (BITS_PER_LONG == 64)
  3421. #define GET_NET_STATS GET_NET_STATS64
  3422. #else
  3423. #define GET_NET_STATS GET_NET_STATS32
  3424. #endif
  3425. static struct net_device_stats *
  3426. bnx2_get_stats(struct net_device *dev)
  3427. {
  3428. struct bnx2 *bp = dev->priv;
  3429. struct statistics_block *stats_blk = bp->stats_blk;
  3430. struct net_device_stats *net_stats = &bp->net_stats;
  3431. if (bp->stats_blk == NULL) {
  3432. return net_stats;
  3433. }
  3434. net_stats->rx_packets =
  3435. GET_NET_STATS(stats_blk->stat_IfHCInUcastPkts) +
  3436. GET_NET_STATS(stats_blk->stat_IfHCInMulticastPkts) +
  3437. GET_NET_STATS(stats_blk->stat_IfHCInBroadcastPkts);
  3438. net_stats->tx_packets =
  3439. GET_NET_STATS(stats_blk->stat_IfHCOutUcastPkts) +
  3440. GET_NET_STATS(stats_blk->stat_IfHCOutMulticastPkts) +
  3441. GET_NET_STATS(stats_blk->stat_IfHCOutBroadcastPkts);
  3442. net_stats->rx_bytes =
  3443. GET_NET_STATS(stats_blk->stat_IfHCInOctets);
  3444. net_stats->tx_bytes =
  3445. GET_NET_STATS(stats_blk->stat_IfHCOutOctets);
  3446. net_stats->multicast =
  3447. GET_NET_STATS(stats_blk->stat_IfHCOutMulticastPkts);
  3448. net_stats->collisions =
  3449. (unsigned long) stats_blk->stat_EtherStatsCollisions;
  3450. net_stats->rx_length_errors =
  3451. (unsigned long) (stats_blk->stat_EtherStatsUndersizePkts +
  3452. stats_blk->stat_EtherStatsOverrsizePkts);
  3453. net_stats->rx_over_errors =
  3454. (unsigned long) stats_blk->stat_IfInMBUFDiscards;
  3455. net_stats->rx_frame_errors =
  3456. (unsigned long) stats_blk->stat_Dot3StatsAlignmentErrors;
  3457. net_stats->rx_crc_errors =
  3458. (unsigned long) stats_blk->stat_Dot3StatsFCSErrors;
  3459. net_stats->rx_errors = net_stats->rx_length_errors +
  3460. net_stats->rx_over_errors + net_stats->rx_frame_errors +
  3461. net_stats->rx_crc_errors;
  3462. net_stats->tx_aborted_errors =
  3463. (unsigned long) (stats_blk->stat_Dot3StatsExcessiveCollisions +
  3464. stats_blk->stat_Dot3StatsLateCollisions);
  3465. if (CHIP_NUM(bp) == CHIP_NUM_5706)
  3466. net_stats->tx_carrier_errors = 0;
  3467. else {
  3468. net_stats->tx_carrier_errors =
  3469. (unsigned long)
  3470. stats_blk->stat_Dot3StatsCarrierSenseErrors;
  3471. }
  3472. net_stats->tx_errors =
  3473. (unsigned long)
  3474. stats_blk->stat_emac_tx_stat_dot3statsinternalmactransmiterrors
  3475. +
  3476. net_stats->tx_aborted_errors +
  3477. net_stats->tx_carrier_errors;
  3478. return net_stats;
  3479. }
  3480. /* All ethtool functions called with rtnl_lock */
  3481. static int
  3482. bnx2_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  3483. {
  3484. struct bnx2 *bp = dev->priv;
  3485. cmd->supported = SUPPORTED_Autoneg;
  3486. if (bp->phy_flags & PHY_SERDES_FLAG) {
  3487. cmd->supported |= SUPPORTED_1000baseT_Full |
  3488. SUPPORTED_FIBRE;
  3489. cmd->port = PORT_FIBRE;
  3490. }
  3491. else {
  3492. cmd->supported |= SUPPORTED_10baseT_Half |
  3493. SUPPORTED_10baseT_Full |
  3494. SUPPORTED_100baseT_Half |
  3495. SUPPORTED_100baseT_Full |
  3496. SUPPORTED_1000baseT_Full |
  3497. SUPPORTED_TP;
  3498. cmd->port = PORT_TP;
  3499. }
  3500. cmd->advertising = bp->advertising;
  3501. if (bp->autoneg & AUTONEG_SPEED) {
  3502. cmd->autoneg = AUTONEG_ENABLE;
  3503. }
  3504. else {
  3505. cmd->autoneg = AUTONEG_DISABLE;
  3506. }
  3507. if (netif_carrier_ok(dev)) {
  3508. cmd->speed = bp->line_speed;
  3509. cmd->duplex = bp->duplex;
  3510. }
  3511. else {
  3512. cmd->speed = -1;
  3513. cmd->duplex = -1;
  3514. }
  3515. cmd->transceiver = XCVR_INTERNAL;
  3516. cmd->phy_address = bp->phy_addr;
  3517. return 0;
  3518. }
  3519. static int
  3520. bnx2_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  3521. {
  3522. struct bnx2 *bp = dev->priv;
  3523. u8 autoneg = bp->autoneg;
  3524. u8 req_duplex = bp->req_duplex;
  3525. u16 req_line_speed = bp->req_line_speed;
  3526. u32 advertising = bp->advertising;
  3527. if (cmd->autoneg == AUTONEG_ENABLE) {
  3528. autoneg |= AUTONEG_SPEED;
  3529. cmd->advertising &= ETHTOOL_ALL_COPPER_SPEED;
  3530. /* allow advertising 1 speed */
  3531. if ((cmd->advertising == ADVERTISED_10baseT_Half) ||
  3532. (cmd->advertising == ADVERTISED_10baseT_Full) ||
  3533. (cmd->advertising == ADVERTISED_100baseT_Half) ||
  3534. (cmd->advertising == ADVERTISED_100baseT_Full)) {
  3535. if (bp->phy_flags & PHY_SERDES_FLAG)
  3536. return -EINVAL;
  3537. advertising = cmd->advertising;
  3538. }
  3539. else if (cmd->advertising == ADVERTISED_1000baseT_Full) {
  3540. advertising = cmd->advertising;
  3541. }
  3542. else if (cmd->advertising == ADVERTISED_1000baseT_Half) {
  3543. return -EINVAL;
  3544. }
  3545. else {
  3546. if (bp->phy_flags & PHY_SERDES_FLAG) {
  3547. advertising = ETHTOOL_ALL_FIBRE_SPEED;
  3548. }
  3549. else {
  3550. advertising = ETHTOOL_ALL_COPPER_SPEED;
  3551. }
  3552. }
  3553. advertising |= ADVERTISED_Autoneg;
  3554. }
  3555. else {
  3556. if (bp->phy_flags & PHY_SERDES_FLAG) {
  3557. if ((cmd->speed != SPEED_1000) ||
  3558. (cmd->duplex != DUPLEX_FULL)) {
  3559. return -EINVAL;
  3560. }
  3561. }
  3562. else if (cmd->speed == SPEED_1000) {
  3563. return -EINVAL;
  3564. }
  3565. autoneg &= ~AUTONEG_SPEED;
  3566. req_line_speed = cmd->speed;
  3567. req_duplex = cmd->duplex;
  3568. advertising = 0;
  3569. }
  3570. bp->autoneg = autoneg;
  3571. bp->advertising = advertising;
  3572. bp->req_line_speed = req_line_speed;
  3573. bp->req_duplex = req_duplex;
  3574. spin_lock_irq(&bp->phy_lock);
  3575. bnx2_setup_phy(bp);
  3576. spin_unlock_irq(&bp->phy_lock);
  3577. return 0;
  3578. }
  3579. static void
  3580. bnx2_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
  3581. {
  3582. struct bnx2 *bp = dev->priv;
  3583. strcpy(info->driver, DRV_MODULE_NAME);
  3584. strcpy(info->version, DRV_MODULE_VERSION);
  3585. strcpy(info->bus_info, pci_name(bp->pdev));
  3586. info->fw_version[0] = ((bp->fw_ver & 0xff000000) >> 24) + '0';
  3587. info->fw_version[2] = ((bp->fw_ver & 0xff0000) >> 16) + '0';
  3588. info->fw_version[4] = ((bp->fw_ver & 0xff00) >> 8) + '0';
  3589. info->fw_version[6] = (bp->fw_ver & 0xff) + '0';
  3590. info->fw_version[1] = info->fw_version[3] = info->fw_version[5] = '.';
  3591. info->fw_version[7] = 0;
  3592. }
  3593. static void
  3594. bnx2_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  3595. {
  3596. struct bnx2 *bp = dev->priv;
  3597. if (bp->flags & NO_WOL_FLAG) {
  3598. wol->supported = 0;
  3599. wol->wolopts = 0;
  3600. }
  3601. else {
  3602. wol->supported = WAKE_MAGIC;
  3603. if (bp->wol)
  3604. wol->wolopts = WAKE_MAGIC;
  3605. else
  3606. wol->wolopts = 0;
  3607. }
  3608. memset(&wol->sopass, 0, sizeof(wol->sopass));
  3609. }
  3610. static int
  3611. bnx2_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  3612. {
  3613. struct bnx2 *bp = dev->priv;
  3614. if (wol->wolopts & ~WAKE_MAGIC)
  3615. return -EINVAL;
  3616. if (wol->wolopts & WAKE_MAGIC) {
  3617. if (bp->flags & NO_WOL_FLAG)
  3618. return -EINVAL;
  3619. bp->wol = 1;
  3620. }
  3621. else {
  3622. bp->wol = 0;
  3623. }
  3624. return 0;
  3625. }
  3626. static int
  3627. bnx2_nway_reset(struct net_device *dev)
  3628. {
  3629. struct bnx2 *bp = dev->priv;
  3630. u32 bmcr;
  3631. if (!(bp->autoneg & AUTONEG_SPEED)) {
  3632. return -EINVAL;
  3633. }
  3634. spin_lock_irq(&bp->phy_lock);
  3635. /* Force a link down visible on the other side */
  3636. if (bp->phy_flags & PHY_SERDES_FLAG) {
  3637. bnx2_write_phy(bp, MII_BMCR, BMCR_LOOPBACK);
  3638. spin_unlock_irq(&bp->phy_lock);
  3639. msleep(20);
  3640. spin_lock_irq(&bp->phy_lock);
  3641. if (CHIP_NUM(bp) == CHIP_NUM_5706) {
  3642. bp->current_interval = SERDES_AN_TIMEOUT;
  3643. bp->serdes_an_pending = 1;
  3644. mod_timer(&bp->timer, jiffies + bp->current_interval);
  3645. }
  3646. }
  3647. bnx2_read_phy(bp, MII_BMCR, &bmcr);
  3648. bmcr &= ~BMCR_LOOPBACK;
  3649. bnx2_write_phy(bp, MII_BMCR, bmcr | BMCR_ANRESTART | BMCR_ANENABLE);
  3650. spin_unlock_irq(&bp->phy_lock);
  3651. return 0;
  3652. }
  3653. static int
  3654. bnx2_get_eeprom_len(struct net_device *dev)
  3655. {
  3656. struct bnx2 *bp = dev->priv;
  3657. if (bp->flash_info == 0)
  3658. return 0;
  3659. return (int) bp->flash_info->total_size;
  3660. }
  3661. static int
  3662. bnx2_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
  3663. u8 *eebuf)
  3664. {
  3665. struct bnx2 *bp = dev->priv;
  3666. int rc;
  3667. if (eeprom->offset > bp->flash_info->total_size)
  3668. return -EINVAL;
  3669. if ((eeprom->offset + eeprom->len) > bp->flash_info->total_size)
  3670. eeprom->len = bp->flash_info->total_size - eeprom->offset;
  3671. rc = bnx2_nvram_read(bp, eeprom->offset, eebuf, eeprom->len);
  3672. return rc;
  3673. }
  3674. static int
  3675. bnx2_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
  3676. u8 *eebuf)
  3677. {
  3678. struct bnx2 *bp = dev->priv;
  3679. int rc;
  3680. if (eeprom->offset > bp->flash_info->total_size)
  3681. return -EINVAL;
  3682. if ((eeprom->offset + eeprom->len) > bp->flash_info->total_size)
  3683. eeprom->len = bp->flash_info->total_size - eeprom->offset;
  3684. rc = bnx2_nvram_write(bp, eeprom->offset, eebuf, eeprom->len);
  3685. return rc;
  3686. }
  3687. static int
  3688. bnx2_get_coalesce(struct net_device *dev, struct ethtool_coalesce *coal)
  3689. {
  3690. struct bnx2 *bp = dev->priv;
  3691. memset(coal, 0, sizeof(struct ethtool_coalesce));
  3692. coal->rx_coalesce_usecs = bp->rx_ticks;
  3693. coal->rx_max_coalesced_frames = bp->rx_quick_cons_trip;
  3694. coal->rx_coalesce_usecs_irq = bp->rx_ticks_int;
  3695. coal->rx_max_coalesced_frames_irq = bp->rx_quick_cons_trip_int;
  3696. coal->tx_coalesce_usecs = bp->tx_ticks;
  3697. coal->tx_max_coalesced_frames = bp->tx_quick_cons_trip;
  3698. coal->tx_coalesce_usecs_irq = bp->tx_ticks_int;
  3699. coal->tx_max_coalesced_frames_irq = bp->tx_quick_cons_trip_int;
  3700. coal->stats_block_coalesce_usecs = bp->stats_ticks;
  3701. return 0;
  3702. }
  3703. static int
  3704. bnx2_set_coalesce(struct net_device *dev, struct ethtool_coalesce *coal)
  3705. {
  3706. struct bnx2 *bp = dev->priv;
  3707. bp->rx_ticks = (u16) coal->rx_coalesce_usecs;
  3708. if (bp->rx_ticks > 0x3ff) bp->rx_ticks = 0x3ff;
  3709. bp->rx_quick_cons_trip = (u16) coal->rx_max_coalesced_frames;
  3710. if (bp->rx_quick_cons_trip > 0xff) bp->rx_quick_cons_trip = 0xff;
  3711. bp->rx_ticks_int = (u16) coal->rx_coalesce_usecs_irq;
  3712. if (bp->rx_ticks_int > 0x3ff) bp->rx_ticks_int = 0x3ff;
  3713. bp->rx_quick_cons_trip_int = (u16) coal->rx_max_coalesced_frames_irq;
  3714. if (bp->rx_quick_cons_trip_int > 0xff)
  3715. bp->rx_quick_cons_trip_int = 0xff;
  3716. bp->tx_ticks = (u16) coal->tx_coalesce_usecs;
  3717. if (bp->tx_ticks > 0x3ff) bp->tx_ticks = 0x3ff;
  3718. bp->tx_quick_cons_trip = (u16) coal->tx_max_coalesced_frames;
  3719. if (bp->tx_quick_cons_trip > 0xff) bp->tx_quick_cons_trip = 0xff;
  3720. bp->tx_ticks_int = (u16) coal->tx_coalesce_usecs_irq;
  3721. if (bp->tx_ticks_int > 0x3ff) bp->tx_ticks_int = 0x3ff;
  3722. bp->tx_quick_cons_trip_int = (u16) coal->tx_max_coalesced_frames_irq;
  3723. if (bp->tx_quick_cons_trip_int > 0xff) bp->tx_quick_cons_trip_int =
  3724. 0xff;
  3725. bp->stats_ticks = coal->stats_block_coalesce_usecs;
  3726. if (bp->stats_ticks > 0xffff00) bp->stats_ticks = 0xffff00;
  3727. bp->stats_ticks &= 0xffff00;
  3728. if (netif_running(bp->dev)) {
  3729. bnx2_netif_stop(bp);
  3730. bnx2_init_nic(bp);
  3731. bnx2_netif_start(bp);
  3732. }
  3733. return 0;
  3734. }
  3735. static void
  3736. bnx2_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ering)
  3737. {
  3738. struct bnx2 *bp = dev->priv;
  3739. ering->rx_max_pending = MAX_RX_DESC_CNT;
  3740. ering->rx_mini_max_pending = 0;
  3741. ering->rx_jumbo_max_pending = 0;
  3742. ering->rx_pending = bp->rx_ring_size;
  3743. ering->rx_mini_pending = 0;
  3744. ering->rx_jumbo_pending = 0;
  3745. ering->tx_max_pending = MAX_TX_DESC_CNT;
  3746. ering->tx_pending = bp->tx_ring_size;
  3747. }
  3748. static int
  3749. bnx2_set_ringparam(struct net_device *dev, struct ethtool_ringparam *ering)
  3750. {
  3751. struct bnx2 *bp = dev->priv;
  3752. if ((ering->rx_pending > MAX_RX_DESC_CNT) ||
  3753. (ering->tx_pending > MAX_TX_DESC_CNT) ||
  3754. (ering->tx_pending <= MAX_SKB_FRAGS)) {
  3755. return -EINVAL;
  3756. }
  3757. bp->rx_ring_size = ering->rx_pending;
  3758. bp->tx_ring_size = ering->tx_pending;
  3759. if (netif_running(bp->dev)) {
  3760. bnx2_netif_stop(bp);
  3761. bnx2_init_nic(bp);
  3762. bnx2_netif_start(bp);
  3763. }
  3764. return 0;
  3765. }
  3766. static void
  3767. bnx2_get_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause)
  3768. {
  3769. struct bnx2 *bp = dev->priv;
  3770. epause->autoneg = ((bp->autoneg & AUTONEG_FLOW_CTRL) != 0);
  3771. epause->rx_pause = ((bp->flow_ctrl & FLOW_CTRL_RX) != 0);
  3772. epause->tx_pause = ((bp->flow_ctrl & FLOW_CTRL_TX) != 0);
  3773. }
  3774. static int
  3775. bnx2_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause)
  3776. {
  3777. struct bnx2 *bp = dev->priv;
  3778. bp->req_flow_ctrl = 0;
  3779. if (epause->rx_pause)
  3780. bp->req_flow_ctrl |= FLOW_CTRL_RX;
  3781. if (epause->tx_pause)
  3782. bp->req_flow_ctrl |= FLOW_CTRL_TX;
  3783. if (epause->autoneg) {
  3784. bp->autoneg |= AUTONEG_FLOW_CTRL;
  3785. }
  3786. else {
  3787. bp->autoneg &= ~AUTONEG_FLOW_CTRL;
  3788. }
  3789. spin_lock_irq(&bp->phy_lock);
  3790. bnx2_setup_phy(bp);
  3791. spin_unlock_irq(&bp->phy_lock);
  3792. return 0;
  3793. }
  3794. static u32
  3795. bnx2_get_rx_csum(struct net_device *dev)
  3796. {
  3797. struct bnx2 *bp = dev->priv;
  3798. return bp->rx_csum;
  3799. }
  3800. static int
  3801. bnx2_set_rx_csum(struct net_device *dev, u32 data)
  3802. {
  3803. struct bnx2 *bp = dev->priv;
  3804. bp->rx_csum = data;
  3805. return 0;
  3806. }
  3807. #define BNX2_NUM_STATS 45
  3808. static struct {
  3809. char string[ETH_GSTRING_LEN];
  3810. } bnx2_stats_str_arr[BNX2_NUM_STATS] = {
  3811. { "rx_bytes" },
  3812. { "rx_error_bytes" },
  3813. { "tx_bytes" },
  3814. { "tx_error_bytes" },
  3815. { "rx_ucast_packets" },
  3816. { "rx_mcast_packets" },
  3817. { "rx_bcast_packets" },
  3818. { "tx_ucast_packets" },
  3819. { "tx_mcast_packets" },
  3820. { "tx_bcast_packets" },
  3821. { "tx_mac_errors" },
  3822. { "tx_carrier_errors" },
  3823. { "rx_crc_errors" },
  3824. { "rx_align_errors" },
  3825. { "tx_single_collisions" },
  3826. { "tx_multi_collisions" },
  3827. { "tx_deferred" },
  3828. { "tx_excess_collisions" },
  3829. { "tx_late_collisions" },
  3830. { "tx_total_collisions" },
  3831. { "rx_fragments" },
  3832. { "rx_jabbers" },
  3833. { "rx_undersize_packets" },
  3834. { "rx_oversize_packets" },
  3835. { "rx_64_byte_packets" },
  3836. { "rx_65_to_127_byte_packets" },
  3837. { "rx_128_to_255_byte_packets" },
  3838. { "rx_256_to_511_byte_packets" },
  3839. { "rx_512_to_1023_byte_packets" },
  3840. { "rx_1024_to_1522_byte_packets" },
  3841. { "rx_1523_to_9022_byte_packets" },
  3842. { "tx_64_byte_packets" },
  3843. { "tx_65_to_127_byte_packets" },
  3844. { "tx_128_to_255_byte_packets" },
  3845. { "tx_256_to_511_byte_packets" },
  3846. { "tx_512_to_1023_byte_packets" },
  3847. { "tx_1024_to_1522_byte_packets" },
  3848. { "tx_1523_to_9022_byte_packets" },
  3849. { "rx_xon_frames" },
  3850. { "rx_xoff_frames" },
  3851. { "tx_xon_frames" },
  3852. { "tx_xoff_frames" },
  3853. { "rx_mac_ctrl_frames" },
  3854. { "rx_filtered_packets" },
  3855. { "rx_discards" },
  3856. };
  3857. #define STATS_OFFSET32(offset_name) (offsetof(struct statistics_block, offset_name) / 4)
  3858. static unsigned long bnx2_stats_offset_arr[BNX2_NUM_STATS] = {
  3859. STATS_OFFSET32(stat_IfHCInOctets_hi),
  3860. STATS_OFFSET32(stat_IfHCInBadOctets_hi),
  3861. STATS_OFFSET32(stat_IfHCOutOctets_hi),
  3862. STATS_OFFSET32(stat_IfHCOutBadOctets_hi),
  3863. STATS_OFFSET32(stat_IfHCInUcastPkts_hi),
  3864. STATS_OFFSET32(stat_IfHCInMulticastPkts_hi),
  3865. STATS_OFFSET32(stat_IfHCInBroadcastPkts_hi),
  3866. STATS_OFFSET32(stat_IfHCOutUcastPkts_hi),
  3867. STATS_OFFSET32(stat_IfHCOutMulticastPkts_hi),
  3868. STATS_OFFSET32(stat_IfHCOutBroadcastPkts_hi),
  3869. STATS_OFFSET32(stat_emac_tx_stat_dot3statsinternalmactransmiterrors),
  3870. STATS_OFFSET32(stat_Dot3StatsCarrierSenseErrors),
  3871. STATS_OFFSET32(stat_Dot3StatsFCSErrors),
  3872. STATS_OFFSET32(stat_Dot3StatsAlignmentErrors),
  3873. STATS_OFFSET32(stat_Dot3StatsSingleCollisionFrames),
  3874. STATS_OFFSET32(stat_Dot3StatsMultipleCollisionFrames),
  3875. STATS_OFFSET32(stat_Dot3StatsDeferredTransmissions),
  3876. STATS_OFFSET32(stat_Dot3StatsExcessiveCollisions),
  3877. STATS_OFFSET32(stat_Dot3StatsLateCollisions),
  3878. STATS_OFFSET32(stat_EtherStatsCollisions),
  3879. STATS_OFFSET32(stat_EtherStatsFragments),
  3880. STATS_OFFSET32(stat_EtherStatsJabbers),
  3881. STATS_OFFSET32(stat_EtherStatsUndersizePkts),
  3882. STATS_OFFSET32(stat_EtherStatsOverrsizePkts),
  3883. STATS_OFFSET32(stat_EtherStatsPktsRx64Octets),
  3884. STATS_OFFSET32(stat_EtherStatsPktsRx65Octetsto127Octets),
  3885. STATS_OFFSET32(stat_EtherStatsPktsRx128Octetsto255Octets),
  3886. STATS_OFFSET32(stat_EtherStatsPktsRx256Octetsto511Octets),
  3887. STATS_OFFSET32(stat_EtherStatsPktsRx512Octetsto1023Octets),
  3888. STATS_OFFSET32(stat_EtherStatsPktsRx1024Octetsto1522Octets),
  3889. STATS_OFFSET32(stat_EtherStatsPktsRx1523Octetsto9022Octets),
  3890. STATS_OFFSET32(stat_EtherStatsPktsTx64Octets),
  3891. STATS_OFFSET32(stat_EtherStatsPktsTx65Octetsto127Octets),
  3892. STATS_OFFSET32(stat_EtherStatsPktsTx128Octetsto255Octets),
  3893. STATS_OFFSET32(stat_EtherStatsPktsTx256Octetsto511Octets),
  3894. STATS_OFFSET32(stat_EtherStatsPktsTx512Octetsto1023Octets),
  3895. STATS_OFFSET32(stat_EtherStatsPktsTx1024Octetsto1522Octets),
  3896. STATS_OFFSET32(stat_EtherStatsPktsTx1523Octetsto9022Octets),
  3897. STATS_OFFSET32(stat_XonPauseFramesReceived),
  3898. STATS_OFFSET32(stat_XoffPauseFramesReceived),
  3899. STATS_OFFSET32(stat_OutXonSent),
  3900. STATS_OFFSET32(stat_OutXoffSent),
  3901. STATS_OFFSET32(stat_MacControlFramesReceived),
  3902. STATS_OFFSET32(stat_IfInFramesL2FilterDiscards),
  3903. STATS_OFFSET32(stat_IfInMBUFDiscards),
  3904. };
  3905. /* stat_IfHCInBadOctets and stat_Dot3StatsCarrierSenseErrors are
  3906. * skipped because of errata.
  3907. */
  3908. static u8 bnx2_5706_stats_len_arr[BNX2_NUM_STATS] = {
  3909. 8,0,8,8,8,8,8,8,8,8,
  3910. 4,0,4,4,4,4,4,4,4,4,
  3911. 4,4,4,4,4,4,4,4,4,4,
  3912. 4,4,4,4,4,4,4,4,4,4,
  3913. 4,4,4,4,4,
  3914. };
  3915. #define BNX2_NUM_TESTS 6
  3916. static struct {
  3917. char string[ETH_GSTRING_LEN];
  3918. } bnx2_tests_str_arr[BNX2_NUM_TESTS] = {
  3919. { "register_test (offline)" },
  3920. { "memory_test (offline)" },
  3921. { "loopback_test (offline)" },
  3922. { "nvram_test (online)" },
  3923. { "interrupt_test (online)" },
  3924. { "link_test (online)" },
  3925. };
  3926. static int
  3927. bnx2_self_test_count(struct net_device *dev)
  3928. {
  3929. return BNX2_NUM_TESTS;
  3930. }
  3931. static void
  3932. bnx2_self_test(struct net_device *dev, struct ethtool_test *etest, u64 *buf)
  3933. {
  3934. struct bnx2 *bp = dev->priv;
  3935. memset(buf, 0, sizeof(u64) * BNX2_NUM_TESTS);
  3936. if (etest->flags & ETH_TEST_FL_OFFLINE) {
  3937. bnx2_netif_stop(bp);
  3938. bnx2_reset_chip(bp, BNX2_DRV_MSG_CODE_DIAG);
  3939. bnx2_free_skbs(bp);
  3940. if (bnx2_test_registers(bp) != 0) {
  3941. buf[0] = 1;
  3942. etest->flags |= ETH_TEST_FL_FAILED;
  3943. }
  3944. if (bnx2_test_memory(bp) != 0) {
  3945. buf[1] = 1;
  3946. etest->flags |= ETH_TEST_FL_FAILED;
  3947. }
  3948. if (bnx2_test_loopback(bp) != 0) {
  3949. buf[2] = 1;
  3950. etest->flags |= ETH_TEST_FL_FAILED;
  3951. }
  3952. if (!netif_running(bp->dev)) {
  3953. bnx2_reset_chip(bp, BNX2_DRV_MSG_CODE_RESET);
  3954. }
  3955. else {
  3956. bnx2_init_nic(bp);
  3957. bnx2_netif_start(bp);
  3958. }
  3959. /* wait for link up */
  3960. msleep_interruptible(3000);
  3961. if ((!bp->link_up) && !(bp->phy_flags & PHY_SERDES_FLAG))
  3962. msleep_interruptible(4000);
  3963. }
  3964. if (bnx2_test_nvram(bp) != 0) {
  3965. buf[3] = 1;
  3966. etest->flags |= ETH_TEST_FL_FAILED;
  3967. }
  3968. if (bnx2_test_intr(bp) != 0) {
  3969. buf[4] = 1;
  3970. etest->flags |= ETH_TEST_FL_FAILED;
  3971. }
  3972. if (bnx2_test_link(bp) != 0) {
  3973. buf[5] = 1;
  3974. etest->flags |= ETH_TEST_FL_FAILED;
  3975. }
  3976. }
  3977. static void
  3978. bnx2_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
  3979. {
  3980. switch (stringset) {
  3981. case ETH_SS_STATS:
  3982. memcpy(buf, bnx2_stats_str_arr,
  3983. sizeof(bnx2_stats_str_arr));
  3984. break;
  3985. case ETH_SS_TEST:
  3986. memcpy(buf, bnx2_tests_str_arr,
  3987. sizeof(bnx2_tests_str_arr));
  3988. break;
  3989. }
  3990. }
  3991. static int
  3992. bnx2_get_stats_count(struct net_device *dev)
  3993. {
  3994. return BNX2_NUM_STATS;
  3995. }
  3996. static void
  3997. bnx2_get_ethtool_stats(struct net_device *dev,
  3998. struct ethtool_stats *stats, u64 *buf)
  3999. {
  4000. struct bnx2 *bp = dev->priv;
  4001. int i;
  4002. u32 *hw_stats = (u32 *) bp->stats_blk;
  4003. u8 *stats_len_arr = NULL;
  4004. if (hw_stats == NULL) {
  4005. memset(buf, 0, sizeof(u64) * BNX2_NUM_STATS);
  4006. return;
  4007. }
  4008. if (CHIP_NUM(bp) == CHIP_NUM_5706)
  4009. stats_len_arr = bnx2_5706_stats_len_arr;
  4010. for (i = 0; i < BNX2_NUM_STATS; i++) {
  4011. if (stats_len_arr[i] == 0) {
  4012. /* skip this counter */
  4013. buf[i] = 0;
  4014. continue;
  4015. }
  4016. if (stats_len_arr[i] == 4) {
  4017. /* 4-byte counter */
  4018. buf[i] = (u64)
  4019. *(hw_stats + bnx2_stats_offset_arr[i]);
  4020. continue;
  4021. }
  4022. /* 8-byte counter */
  4023. buf[i] = (((u64) *(hw_stats +
  4024. bnx2_stats_offset_arr[i])) << 32) +
  4025. *(hw_stats + bnx2_stats_offset_arr[i] + 1);
  4026. }
  4027. }
  4028. static int
  4029. bnx2_phys_id(struct net_device *dev, u32 data)
  4030. {
  4031. struct bnx2 *bp = dev->priv;
  4032. int i;
  4033. u32 save;
  4034. if (data == 0)
  4035. data = 2;
  4036. save = REG_RD(bp, BNX2_MISC_CFG);
  4037. REG_WR(bp, BNX2_MISC_CFG, BNX2_MISC_CFG_LEDMODE_MAC);
  4038. for (i = 0; i < (data * 2); i++) {
  4039. if ((i % 2) == 0) {
  4040. REG_WR(bp, BNX2_EMAC_LED, BNX2_EMAC_LED_OVERRIDE);
  4041. }
  4042. else {
  4043. REG_WR(bp, BNX2_EMAC_LED, BNX2_EMAC_LED_OVERRIDE |
  4044. BNX2_EMAC_LED_1000MB_OVERRIDE |
  4045. BNX2_EMAC_LED_100MB_OVERRIDE |
  4046. BNX2_EMAC_LED_10MB_OVERRIDE |
  4047. BNX2_EMAC_LED_TRAFFIC_OVERRIDE |
  4048. BNX2_EMAC_LED_TRAFFIC);
  4049. }
  4050. msleep_interruptible(500);
  4051. if (signal_pending(current))
  4052. break;
  4053. }
  4054. REG_WR(bp, BNX2_EMAC_LED, 0);
  4055. REG_WR(bp, BNX2_MISC_CFG, save);
  4056. return 0;
  4057. }
  4058. static struct ethtool_ops bnx2_ethtool_ops = {
  4059. .get_settings = bnx2_get_settings,
  4060. .set_settings = bnx2_set_settings,
  4061. .get_drvinfo = bnx2_get_drvinfo,
  4062. .get_wol = bnx2_get_wol,
  4063. .set_wol = bnx2_set_wol,
  4064. .nway_reset = bnx2_nway_reset,
  4065. .get_link = ethtool_op_get_link,
  4066. .get_eeprom_len = bnx2_get_eeprom_len,
  4067. .get_eeprom = bnx2_get_eeprom,
  4068. .set_eeprom = bnx2_set_eeprom,
  4069. .get_coalesce = bnx2_get_coalesce,
  4070. .set_coalesce = bnx2_set_coalesce,
  4071. .get_ringparam = bnx2_get_ringparam,
  4072. .set_ringparam = bnx2_set_ringparam,
  4073. .get_pauseparam = bnx2_get_pauseparam,
  4074. .set_pauseparam = bnx2_set_pauseparam,
  4075. .get_rx_csum = bnx2_get_rx_csum,
  4076. .set_rx_csum = bnx2_set_rx_csum,
  4077. .get_tx_csum = ethtool_op_get_tx_csum,
  4078. .set_tx_csum = ethtool_op_set_tx_csum,
  4079. .get_sg = ethtool_op_get_sg,
  4080. .set_sg = ethtool_op_set_sg,
  4081. #ifdef BCM_TSO
  4082. .get_tso = ethtool_op_get_tso,
  4083. .set_tso = ethtool_op_set_tso,
  4084. #endif
  4085. .self_test_count = bnx2_self_test_count,
  4086. .self_test = bnx2_self_test,
  4087. .get_strings = bnx2_get_strings,
  4088. .phys_id = bnx2_phys_id,
  4089. .get_stats_count = bnx2_get_stats_count,
  4090. .get_ethtool_stats = bnx2_get_ethtool_stats,
  4091. };
  4092. /* Called with rtnl_lock */
  4093. static int
  4094. bnx2_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  4095. {
  4096. struct mii_ioctl_data *data = if_mii(ifr);
  4097. struct bnx2 *bp = dev->priv;
  4098. int err;
  4099. switch(cmd) {
  4100. case SIOCGMIIPHY:
  4101. data->phy_id = bp->phy_addr;
  4102. /* fallthru */
  4103. case SIOCGMIIREG: {
  4104. u32 mii_regval;
  4105. spin_lock_irq(&bp->phy_lock);
  4106. err = bnx2_read_phy(bp, data->reg_num & 0x1f, &mii_regval);
  4107. spin_unlock_irq(&bp->phy_lock);
  4108. data->val_out = mii_regval;
  4109. return err;
  4110. }
  4111. case SIOCSMIIREG:
  4112. if (!capable(CAP_NET_ADMIN))
  4113. return -EPERM;
  4114. spin_lock_irq(&bp->phy_lock);
  4115. err = bnx2_write_phy(bp, data->reg_num & 0x1f, data->val_in);
  4116. spin_unlock_irq(&bp->phy_lock);
  4117. return err;
  4118. default:
  4119. /* do nothing */
  4120. break;
  4121. }
  4122. return -EOPNOTSUPP;
  4123. }
  4124. /* Called with rtnl_lock */
  4125. static int
  4126. bnx2_change_mac_addr(struct net_device *dev, void *p)
  4127. {
  4128. struct sockaddr *addr = p;
  4129. struct bnx2 *bp = dev->priv;
  4130. memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
  4131. if (netif_running(dev))
  4132. bnx2_set_mac_addr(bp);
  4133. return 0;
  4134. }
  4135. /* Called with rtnl_lock */
  4136. static int
  4137. bnx2_change_mtu(struct net_device *dev, int new_mtu)
  4138. {
  4139. struct bnx2 *bp = dev->priv;
  4140. if (((new_mtu + ETH_HLEN) > MAX_ETHERNET_JUMBO_PACKET_SIZE) ||
  4141. ((new_mtu + ETH_HLEN) < MIN_ETHERNET_PACKET_SIZE))
  4142. return -EINVAL;
  4143. dev->mtu = new_mtu;
  4144. if (netif_running(dev)) {
  4145. bnx2_netif_stop(bp);
  4146. bnx2_init_nic(bp);
  4147. bnx2_netif_start(bp);
  4148. }
  4149. return 0;
  4150. }
  4151. #if defined(HAVE_POLL_CONTROLLER) || defined(CONFIG_NET_POLL_CONTROLLER)
  4152. static void
  4153. poll_bnx2(struct net_device *dev)
  4154. {
  4155. struct bnx2 *bp = dev->priv;
  4156. disable_irq(bp->pdev->irq);
  4157. bnx2_interrupt(bp->pdev->irq, dev, NULL);
  4158. enable_irq(bp->pdev->irq);
  4159. }
  4160. #endif
  4161. static int __devinit
  4162. bnx2_init_board(struct pci_dev *pdev, struct net_device *dev)
  4163. {
  4164. struct bnx2 *bp;
  4165. unsigned long mem_len;
  4166. int rc;
  4167. u32 reg;
  4168. SET_MODULE_OWNER(dev);
  4169. SET_NETDEV_DEV(dev, &pdev->dev);
  4170. bp = dev->priv;
  4171. bp->flags = 0;
  4172. bp->phy_flags = 0;
  4173. /* enable device (incl. PCI PM wakeup), and bus-mastering */
  4174. rc = pci_enable_device(pdev);
  4175. if (rc) {
  4176. printk(KERN_ERR PFX "Cannot enable PCI device, aborting.");
  4177. goto err_out;
  4178. }
  4179. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  4180. printk(KERN_ERR PFX "Cannot find PCI device base address, "
  4181. "aborting.\n");
  4182. rc = -ENODEV;
  4183. goto err_out_disable;
  4184. }
  4185. rc = pci_request_regions(pdev, DRV_MODULE_NAME);
  4186. if (rc) {
  4187. printk(KERN_ERR PFX "Cannot obtain PCI resources, aborting.\n");
  4188. goto err_out_disable;
  4189. }
  4190. pci_set_master(pdev);
  4191. bp->pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
  4192. if (bp->pm_cap == 0) {
  4193. printk(KERN_ERR PFX "Cannot find power management capability, "
  4194. "aborting.\n");
  4195. rc = -EIO;
  4196. goto err_out_release;
  4197. }
  4198. bp->pcix_cap = pci_find_capability(pdev, PCI_CAP_ID_PCIX);
  4199. if (bp->pcix_cap == 0) {
  4200. printk(KERN_ERR PFX "Cannot find PCIX capability, aborting.\n");
  4201. rc = -EIO;
  4202. goto err_out_release;
  4203. }
  4204. if (pci_set_dma_mask(pdev, DMA_64BIT_MASK) == 0) {
  4205. bp->flags |= USING_DAC_FLAG;
  4206. if (pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK) != 0) {
  4207. printk(KERN_ERR PFX "pci_set_consistent_dma_mask "
  4208. "failed, aborting.\n");
  4209. rc = -EIO;
  4210. goto err_out_release;
  4211. }
  4212. }
  4213. else if (pci_set_dma_mask(pdev, DMA_32BIT_MASK) != 0) {
  4214. printk(KERN_ERR PFX "System does not support DMA, aborting.\n");
  4215. rc = -EIO;
  4216. goto err_out_release;
  4217. }
  4218. bp->dev = dev;
  4219. bp->pdev = pdev;
  4220. spin_lock_init(&bp->phy_lock);
  4221. spin_lock_init(&bp->tx_lock);
  4222. INIT_WORK(&bp->reset_task, bnx2_reset_task, bp);
  4223. dev->base_addr = dev->mem_start = pci_resource_start(pdev, 0);
  4224. mem_len = MB_GET_CID_ADDR(17);
  4225. dev->mem_end = dev->mem_start + mem_len;
  4226. dev->irq = pdev->irq;
  4227. bp->regview = ioremap_nocache(dev->base_addr, mem_len);
  4228. if (!bp->regview) {
  4229. printk(KERN_ERR PFX "Cannot map register space, aborting.\n");
  4230. rc = -ENOMEM;
  4231. goto err_out_release;
  4232. }
  4233. /* Configure byte swap and enable write to the reg_window registers.
  4234. * Rely on CPU to do target byte swapping on big endian systems
  4235. * The chip's target access swapping will not swap all accesses
  4236. */
  4237. pci_write_config_dword(bp->pdev, BNX2_PCICFG_MISC_CONFIG,
  4238. BNX2_PCICFG_MISC_CONFIG_REG_WINDOW_ENA |
  4239. BNX2_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP);
  4240. bnx2_set_power_state(bp, 0);
  4241. bp->chip_id = REG_RD(bp, BNX2_MISC_ID);
  4242. bp->phy_addr = 1;
  4243. /* Get bus information. */
  4244. reg = REG_RD(bp, BNX2_PCICFG_MISC_STATUS);
  4245. if (reg & BNX2_PCICFG_MISC_STATUS_PCIX_DET) {
  4246. u32 clkreg;
  4247. bp->flags |= PCIX_FLAG;
  4248. clkreg = REG_RD(bp, BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS);
  4249. clkreg &= BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET;
  4250. switch (clkreg) {
  4251. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_133MHZ:
  4252. bp->bus_speed_mhz = 133;
  4253. break;
  4254. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_95MHZ:
  4255. bp->bus_speed_mhz = 100;
  4256. break;
  4257. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_66MHZ:
  4258. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_80MHZ:
  4259. bp->bus_speed_mhz = 66;
  4260. break;
  4261. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_48MHZ:
  4262. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_55MHZ:
  4263. bp->bus_speed_mhz = 50;
  4264. break;
  4265. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_LOW:
  4266. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_32MHZ:
  4267. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_38MHZ:
  4268. bp->bus_speed_mhz = 33;
  4269. break;
  4270. }
  4271. }
  4272. else {
  4273. if (reg & BNX2_PCICFG_MISC_STATUS_M66EN)
  4274. bp->bus_speed_mhz = 66;
  4275. else
  4276. bp->bus_speed_mhz = 33;
  4277. }
  4278. if (reg & BNX2_PCICFG_MISC_STATUS_32BIT_DET)
  4279. bp->flags |= PCI_32BIT_FLAG;
  4280. /* 5706A0 may falsely detect SERR and PERR. */
  4281. if (CHIP_ID(bp) == CHIP_ID_5706_A0) {
  4282. reg = REG_RD(bp, PCI_COMMAND);
  4283. reg &= ~(PCI_COMMAND_SERR | PCI_COMMAND_PARITY);
  4284. REG_WR(bp, PCI_COMMAND, reg);
  4285. }
  4286. else if ((CHIP_ID(bp) == CHIP_ID_5706_A1) &&
  4287. !(bp->flags & PCIX_FLAG)) {
  4288. printk(KERN_ERR PFX "5706 A1 can only be used in a PCIX bus, "
  4289. "aborting.\n");
  4290. goto err_out_unmap;
  4291. }
  4292. bnx2_init_nvram(bp);
  4293. /* Get the permanent MAC address. First we need to make sure the
  4294. * firmware is actually running.
  4295. */
  4296. reg = REG_RD_IND(bp, HOST_VIEW_SHMEM_BASE + BNX2_DEV_INFO_SIGNATURE);
  4297. if ((reg & BNX2_DEV_INFO_SIGNATURE_MAGIC_MASK) !=
  4298. BNX2_DEV_INFO_SIGNATURE_MAGIC) {
  4299. printk(KERN_ERR PFX "Firmware not running, aborting.\n");
  4300. rc = -ENODEV;
  4301. goto err_out_unmap;
  4302. }
  4303. bp->fw_ver = REG_RD_IND(bp, HOST_VIEW_SHMEM_BASE +
  4304. BNX2_DEV_INFO_BC_REV);
  4305. reg = REG_RD_IND(bp, HOST_VIEW_SHMEM_BASE + BNX2_PORT_HW_CFG_MAC_UPPER);
  4306. bp->mac_addr[0] = (u8) (reg >> 8);
  4307. bp->mac_addr[1] = (u8) reg;
  4308. reg = REG_RD_IND(bp, HOST_VIEW_SHMEM_BASE + BNX2_PORT_HW_CFG_MAC_LOWER);
  4309. bp->mac_addr[2] = (u8) (reg >> 24);
  4310. bp->mac_addr[3] = (u8) (reg >> 16);
  4311. bp->mac_addr[4] = (u8) (reg >> 8);
  4312. bp->mac_addr[5] = (u8) reg;
  4313. bp->tx_ring_size = MAX_TX_DESC_CNT;
  4314. bp->rx_ring_size = 100;
  4315. bp->rx_csum = 1;
  4316. bp->rx_offset = sizeof(struct l2_fhdr) + 2;
  4317. bp->tx_quick_cons_trip_int = 20;
  4318. bp->tx_quick_cons_trip = 20;
  4319. bp->tx_ticks_int = 80;
  4320. bp->tx_ticks = 80;
  4321. bp->rx_quick_cons_trip_int = 6;
  4322. bp->rx_quick_cons_trip = 6;
  4323. bp->rx_ticks_int = 18;
  4324. bp->rx_ticks = 18;
  4325. bp->stats_ticks = 1000000 & 0xffff00;
  4326. bp->timer_interval = HZ;
  4327. bp->current_interval = HZ;
  4328. /* Disable WOL support if we are running on a SERDES chip. */
  4329. if (CHIP_BOND_ID(bp) & CHIP_BOND_ID_SERDES_BIT) {
  4330. bp->phy_flags |= PHY_SERDES_FLAG;
  4331. bp->flags |= NO_WOL_FLAG;
  4332. }
  4333. if (CHIP_ID(bp) == CHIP_ID_5706_A0) {
  4334. bp->tx_quick_cons_trip_int =
  4335. bp->tx_quick_cons_trip;
  4336. bp->tx_ticks_int = bp->tx_ticks;
  4337. bp->rx_quick_cons_trip_int =
  4338. bp->rx_quick_cons_trip;
  4339. bp->rx_ticks_int = bp->rx_ticks;
  4340. bp->comp_prod_trip_int = bp->comp_prod_trip;
  4341. bp->com_ticks_int = bp->com_ticks;
  4342. bp->cmd_ticks_int = bp->cmd_ticks;
  4343. }
  4344. bp->autoneg = AUTONEG_SPEED | AUTONEG_FLOW_CTRL;
  4345. bp->req_line_speed = 0;
  4346. if (bp->phy_flags & PHY_SERDES_FLAG) {
  4347. bp->advertising = ETHTOOL_ALL_FIBRE_SPEED | ADVERTISED_Autoneg;
  4348. reg = REG_RD_IND(bp, HOST_VIEW_SHMEM_BASE +
  4349. BNX2_PORT_HW_CFG_CONFIG);
  4350. reg &= BNX2_PORT_HW_CFG_CFG_DFLT_LINK_MASK;
  4351. if (reg == BNX2_PORT_HW_CFG_CFG_DFLT_LINK_1G) {
  4352. bp->autoneg = 0;
  4353. bp->req_line_speed = bp->line_speed = SPEED_1000;
  4354. bp->req_duplex = DUPLEX_FULL;
  4355. }
  4356. }
  4357. else {
  4358. bp->advertising = ETHTOOL_ALL_COPPER_SPEED | ADVERTISED_Autoneg;
  4359. }
  4360. bp->req_flow_ctrl = FLOW_CTRL_RX | FLOW_CTRL_TX;
  4361. init_timer(&bp->timer);
  4362. bp->timer.expires = RUN_AT(bp->timer_interval);
  4363. bp->timer.data = (unsigned long) bp;
  4364. bp->timer.function = bnx2_timer;
  4365. return 0;
  4366. err_out_unmap:
  4367. if (bp->regview) {
  4368. iounmap(bp->regview);
  4369. }
  4370. err_out_release:
  4371. pci_release_regions(pdev);
  4372. err_out_disable:
  4373. pci_disable_device(pdev);
  4374. pci_set_drvdata(pdev, NULL);
  4375. err_out:
  4376. return rc;
  4377. }
  4378. static int __devinit
  4379. bnx2_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
  4380. {
  4381. static int version_printed = 0;
  4382. struct net_device *dev = NULL;
  4383. struct bnx2 *bp;
  4384. int rc, i;
  4385. if (version_printed++ == 0)
  4386. printk(KERN_INFO "%s", version);
  4387. /* dev zeroed in init_etherdev */
  4388. dev = alloc_etherdev(sizeof(*bp));
  4389. if (!dev)
  4390. return -ENOMEM;
  4391. rc = bnx2_init_board(pdev, dev);
  4392. if (rc < 0) {
  4393. free_netdev(dev);
  4394. return rc;
  4395. }
  4396. dev->open = bnx2_open;
  4397. dev->hard_start_xmit = bnx2_start_xmit;
  4398. dev->stop = bnx2_close;
  4399. dev->get_stats = bnx2_get_stats;
  4400. dev->set_multicast_list = bnx2_set_rx_mode;
  4401. dev->do_ioctl = bnx2_ioctl;
  4402. dev->set_mac_address = bnx2_change_mac_addr;
  4403. dev->change_mtu = bnx2_change_mtu;
  4404. dev->tx_timeout = bnx2_tx_timeout;
  4405. dev->watchdog_timeo = TX_TIMEOUT;
  4406. #ifdef BCM_VLAN
  4407. dev->vlan_rx_register = bnx2_vlan_rx_register;
  4408. dev->vlan_rx_kill_vid = bnx2_vlan_rx_kill_vid;
  4409. #endif
  4410. dev->poll = bnx2_poll;
  4411. dev->ethtool_ops = &bnx2_ethtool_ops;
  4412. dev->weight = 64;
  4413. bp = dev->priv;
  4414. #if defined(HAVE_POLL_CONTROLLER) || defined(CONFIG_NET_POLL_CONTROLLER)
  4415. dev->poll_controller = poll_bnx2;
  4416. #endif
  4417. if ((rc = register_netdev(dev))) {
  4418. printk(KERN_ERR PFX "Cannot register net device\n");
  4419. if (bp->regview)
  4420. iounmap(bp->regview);
  4421. pci_release_regions(pdev);
  4422. pci_disable_device(pdev);
  4423. pci_set_drvdata(pdev, NULL);
  4424. free_netdev(dev);
  4425. return rc;
  4426. }
  4427. pci_set_drvdata(pdev, dev);
  4428. memcpy(dev->dev_addr, bp->mac_addr, 6);
  4429. bp->name = board_info[ent->driver_data].name,
  4430. printk(KERN_INFO "%s: %s (%c%d) PCI%s %s %dMHz found at mem %lx, "
  4431. "IRQ %d, ",
  4432. dev->name,
  4433. bp->name,
  4434. ((CHIP_ID(bp) & 0xf000) >> 12) + 'A',
  4435. ((CHIP_ID(bp) & 0x0ff0) >> 4),
  4436. ((bp->flags & PCIX_FLAG) ? "-X" : ""),
  4437. ((bp->flags & PCI_32BIT_FLAG) ? "32-bit" : "64-bit"),
  4438. bp->bus_speed_mhz,
  4439. dev->base_addr,
  4440. bp->pdev->irq);
  4441. printk("node addr ");
  4442. for (i = 0; i < 6; i++)
  4443. printk("%2.2x", dev->dev_addr[i]);
  4444. printk("\n");
  4445. dev->features |= NETIF_F_SG;
  4446. if (bp->flags & USING_DAC_FLAG)
  4447. dev->features |= NETIF_F_HIGHDMA;
  4448. dev->features |= NETIF_F_IP_CSUM;
  4449. #ifdef BCM_VLAN
  4450. dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
  4451. #endif
  4452. #ifdef BCM_TSO
  4453. dev->features |= NETIF_F_TSO;
  4454. #endif
  4455. netif_carrier_off(bp->dev);
  4456. return 0;
  4457. }
  4458. static void __devexit
  4459. bnx2_remove_one(struct pci_dev *pdev)
  4460. {
  4461. struct net_device *dev = pci_get_drvdata(pdev);
  4462. struct bnx2 *bp = dev->priv;
  4463. flush_scheduled_work();
  4464. unregister_netdev(dev);
  4465. if (bp->regview)
  4466. iounmap(bp->regview);
  4467. free_netdev(dev);
  4468. pci_release_regions(pdev);
  4469. pci_disable_device(pdev);
  4470. pci_set_drvdata(pdev, NULL);
  4471. }
  4472. static int
  4473. bnx2_suspend(struct pci_dev *pdev, u32 state)
  4474. {
  4475. struct net_device *dev = pci_get_drvdata(pdev);
  4476. struct bnx2 *bp = dev->priv;
  4477. u32 reset_code;
  4478. if (!netif_running(dev))
  4479. return 0;
  4480. bnx2_netif_stop(bp);
  4481. netif_device_detach(dev);
  4482. del_timer_sync(&bp->timer);
  4483. if (bp->wol)
  4484. reset_code = BNX2_DRV_MSG_CODE_SUSPEND_WOL;
  4485. else
  4486. reset_code = BNX2_DRV_MSG_CODE_SUSPEND_NO_WOL;
  4487. bnx2_reset_chip(bp, reset_code);
  4488. bnx2_free_skbs(bp);
  4489. bnx2_set_power_state(bp, state);
  4490. return 0;
  4491. }
  4492. static int
  4493. bnx2_resume(struct pci_dev *pdev)
  4494. {
  4495. struct net_device *dev = pci_get_drvdata(pdev);
  4496. struct bnx2 *bp = dev->priv;
  4497. if (!netif_running(dev))
  4498. return 0;
  4499. bnx2_set_power_state(bp, 0);
  4500. netif_device_attach(dev);
  4501. bnx2_init_nic(bp);
  4502. bnx2_netif_start(bp);
  4503. return 0;
  4504. }
  4505. static struct pci_driver bnx2_pci_driver = {
  4506. .name = DRV_MODULE_NAME,
  4507. .id_table = bnx2_pci_tbl,
  4508. .probe = bnx2_init_one,
  4509. .remove = __devexit_p(bnx2_remove_one),
  4510. .suspend = bnx2_suspend,
  4511. .resume = bnx2_resume,
  4512. };
  4513. static int __init bnx2_init(void)
  4514. {
  4515. return pci_module_init(&bnx2_pci_driver);
  4516. }
  4517. static void __exit bnx2_cleanup(void)
  4518. {
  4519. pci_unregister_driver(&bnx2_pci_driver);
  4520. }
  4521. module_init(bnx2_init);
  4522. module_exit(bnx2_cleanup);