bnx2.c 134 KB

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