r8169.c 115 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891
  1. /*
  2. * r8169.c: RealTek 8169/8168/8101 ethernet driver.
  3. *
  4. * Copyright (c) 2002 ShuChen <shuchen@realtek.com.tw>
  5. * Copyright (c) 2003 - 2007 Francois Romieu <romieu@fr.zoreil.com>
  6. * Copyright (c) a lot of people too. Please respect their work.
  7. *
  8. * See MAINTAINERS file for support contact information.
  9. */
  10. #include <linux/module.h>
  11. #include <linux/moduleparam.h>
  12. #include <linux/pci.h>
  13. #include <linux/netdevice.h>
  14. #include <linux/etherdevice.h>
  15. #include <linux/delay.h>
  16. #include <linux/ethtool.h>
  17. #include <linux/mii.h>
  18. #include <linux/if_vlan.h>
  19. #include <linux/crc32.h>
  20. #include <linux/in.h>
  21. #include <linux/ip.h>
  22. #include <linux/tcp.h>
  23. #include <linux/init.h>
  24. #include <linux/dma-mapping.h>
  25. #include <asm/system.h>
  26. #include <asm/io.h>
  27. #include <asm/irq.h>
  28. #define RTL8169_VERSION "2.3LK-NAPI"
  29. #define MODULENAME "r8169"
  30. #define PFX MODULENAME ": "
  31. #ifdef RTL8169_DEBUG
  32. #define assert(expr) \
  33. if (!(expr)) { \
  34. printk( "Assertion failed! %s,%s,%s,line=%d\n", \
  35. #expr,__FILE__,__func__,__LINE__); \
  36. }
  37. #define dprintk(fmt, args...) \
  38. do { printk(KERN_DEBUG PFX fmt, ## args); } while (0)
  39. #else
  40. #define assert(expr) do {} while (0)
  41. #define dprintk(fmt, args...) do {} while (0)
  42. #endif /* RTL8169_DEBUG */
  43. #define R8169_MSG_DEFAULT \
  44. (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_IFUP | NETIF_MSG_IFDOWN)
  45. #define TX_BUFFS_AVAIL(tp) \
  46. (tp->dirty_tx + NUM_TX_DESC - tp->cur_tx - 1)
  47. /* Maximum number of multicast addresses to filter (vs. Rx-all-multicast).
  48. The RTL chips use a 64 element hash table based on the Ethernet CRC. */
  49. static const int multicast_filter_limit = 32;
  50. /* MAC address length */
  51. #define MAC_ADDR_LEN 6
  52. #define MAX_READ_REQUEST_SHIFT 12
  53. #define RX_FIFO_THRESH 7 /* 7 means NO threshold, Rx buffer level before first PCI xfer. */
  54. #define RX_DMA_BURST 6 /* Maximum PCI burst, '6' is 1024 */
  55. #define TX_DMA_BURST 6 /* Maximum PCI burst, '6' is 1024 */
  56. #define EarlyTxThld 0x3F /* 0x3F means NO early transmit */
  57. #define SafeMtu 0x1c20 /* ... actually life sucks beyond ~7k */
  58. #define InterFrameGap 0x03 /* 3 means InterFrameGap = the shortest one */
  59. #define R8169_REGS_SIZE 256
  60. #define R8169_NAPI_WEIGHT 64
  61. #define NUM_TX_DESC 64 /* Number of Tx descriptor registers */
  62. #define NUM_RX_DESC 256 /* Number of Rx descriptor registers */
  63. #define RX_BUF_SIZE 1536 /* Rx Buffer size */
  64. #define R8169_TX_RING_BYTES (NUM_TX_DESC * sizeof(struct TxDesc))
  65. #define R8169_RX_RING_BYTES (NUM_RX_DESC * sizeof(struct RxDesc))
  66. #define RTL8169_TX_TIMEOUT (6*HZ)
  67. #define RTL8169_PHY_TIMEOUT (10*HZ)
  68. #define RTL_EEPROM_SIG cpu_to_le32(0x8129)
  69. #define RTL_EEPROM_SIG_MASK cpu_to_le32(0xffff)
  70. #define RTL_EEPROM_SIG_ADDR 0x0000
  71. /* write/read MMIO register */
  72. #define RTL_W8(reg, val8) writeb ((val8), ioaddr + (reg))
  73. #define RTL_W16(reg, val16) writew ((val16), ioaddr + (reg))
  74. #define RTL_W32(reg, val32) writel ((val32), ioaddr + (reg))
  75. #define RTL_R8(reg) readb (ioaddr + (reg))
  76. #define RTL_R16(reg) readw (ioaddr + (reg))
  77. #define RTL_R32(reg) ((unsigned long) readl (ioaddr + (reg)))
  78. enum mac_version {
  79. RTL_GIGA_MAC_NONE = 0x00,
  80. RTL_GIGA_MAC_VER_01 = 0x01, // 8169
  81. RTL_GIGA_MAC_VER_02 = 0x02, // 8169S
  82. RTL_GIGA_MAC_VER_03 = 0x03, // 8110S
  83. RTL_GIGA_MAC_VER_04 = 0x04, // 8169SB
  84. RTL_GIGA_MAC_VER_05 = 0x05, // 8110SCd
  85. RTL_GIGA_MAC_VER_06 = 0x06, // 8110SCe
  86. RTL_GIGA_MAC_VER_07 = 0x07, // 8102e
  87. RTL_GIGA_MAC_VER_08 = 0x08, // 8102e
  88. RTL_GIGA_MAC_VER_09 = 0x09, // 8102e
  89. RTL_GIGA_MAC_VER_10 = 0x0a, // 8101e
  90. RTL_GIGA_MAC_VER_11 = 0x0b, // 8168Bb
  91. RTL_GIGA_MAC_VER_12 = 0x0c, // 8168Be
  92. RTL_GIGA_MAC_VER_13 = 0x0d, // 8101Eb
  93. RTL_GIGA_MAC_VER_14 = 0x0e, // 8101 ?
  94. RTL_GIGA_MAC_VER_15 = 0x0f, // 8101 ?
  95. RTL_GIGA_MAC_VER_16 = 0x11, // 8101Ec
  96. RTL_GIGA_MAC_VER_17 = 0x10, // 8168Bf
  97. RTL_GIGA_MAC_VER_18 = 0x12, // 8168CP
  98. RTL_GIGA_MAC_VER_19 = 0x13, // 8168C
  99. RTL_GIGA_MAC_VER_20 = 0x14, // 8168C
  100. RTL_GIGA_MAC_VER_21 = 0x15, // 8168C
  101. RTL_GIGA_MAC_VER_22 = 0x16, // 8168C
  102. RTL_GIGA_MAC_VER_23 = 0x17, // 8168CP
  103. RTL_GIGA_MAC_VER_24 = 0x18, // 8168CP
  104. RTL_GIGA_MAC_VER_25 = 0x19, // 8168D
  105. RTL_GIGA_MAC_VER_26 = 0x1a, // 8168D
  106. RTL_GIGA_MAC_VER_27 = 0x1b // 8168DP
  107. };
  108. #define _R(NAME,MAC,MASK) \
  109. { .name = NAME, .mac_version = MAC, .RxConfigMask = MASK }
  110. static const struct {
  111. const char *name;
  112. u8 mac_version;
  113. u32 RxConfigMask; /* Clears the bits supported by this chip */
  114. } rtl_chip_info[] = {
  115. _R("RTL8169", RTL_GIGA_MAC_VER_01, 0xff7e1880), // 8169
  116. _R("RTL8169s", RTL_GIGA_MAC_VER_02, 0xff7e1880), // 8169S
  117. _R("RTL8110s", RTL_GIGA_MAC_VER_03, 0xff7e1880), // 8110S
  118. _R("RTL8169sb/8110sb", RTL_GIGA_MAC_VER_04, 0xff7e1880), // 8169SB
  119. _R("RTL8169sc/8110sc", RTL_GIGA_MAC_VER_05, 0xff7e1880), // 8110SCd
  120. _R("RTL8169sc/8110sc", RTL_GIGA_MAC_VER_06, 0xff7e1880), // 8110SCe
  121. _R("RTL8102e", RTL_GIGA_MAC_VER_07, 0xff7e1880), // PCI-E
  122. _R("RTL8102e", RTL_GIGA_MAC_VER_08, 0xff7e1880), // PCI-E
  123. _R("RTL8102e", RTL_GIGA_MAC_VER_09, 0xff7e1880), // PCI-E
  124. _R("RTL8101e", RTL_GIGA_MAC_VER_10, 0xff7e1880), // PCI-E
  125. _R("RTL8168b/8111b", RTL_GIGA_MAC_VER_11, 0xff7e1880), // PCI-E
  126. _R("RTL8168b/8111b", RTL_GIGA_MAC_VER_12, 0xff7e1880), // PCI-E
  127. _R("RTL8101e", RTL_GIGA_MAC_VER_13, 0xff7e1880), // PCI-E 8139
  128. _R("RTL8100e", RTL_GIGA_MAC_VER_14, 0xff7e1880), // PCI-E 8139
  129. _R("RTL8100e", RTL_GIGA_MAC_VER_15, 0xff7e1880), // PCI-E 8139
  130. _R("RTL8168b/8111b", RTL_GIGA_MAC_VER_17, 0xff7e1880), // PCI-E
  131. _R("RTL8101e", RTL_GIGA_MAC_VER_16, 0xff7e1880), // PCI-E
  132. _R("RTL8168cp/8111cp", RTL_GIGA_MAC_VER_18, 0xff7e1880), // PCI-E
  133. _R("RTL8168c/8111c", RTL_GIGA_MAC_VER_19, 0xff7e1880), // PCI-E
  134. _R("RTL8168c/8111c", RTL_GIGA_MAC_VER_20, 0xff7e1880), // PCI-E
  135. _R("RTL8168c/8111c", RTL_GIGA_MAC_VER_21, 0xff7e1880), // PCI-E
  136. _R("RTL8168c/8111c", RTL_GIGA_MAC_VER_22, 0xff7e1880), // PCI-E
  137. _R("RTL8168cp/8111cp", RTL_GIGA_MAC_VER_23, 0xff7e1880), // PCI-E
  138. _R("RTL8168cp/8111cp", RTL_GIGA_MAC_VER_24, 0xff7e1880), // PCI-E
  139. _R("RTL8168d/8111d", RTL_GIGA_MAC_VER_25, 0xff7e1880), // PCI-E
  140. _R("RTL8168d/8111d", RTL_GIGA_MAC_VER_26, 0xff7e1880), // PCI-E
  141. _R("RTL8168dp/8111dp", RTL_GIGA_MAC_VER_27, 0xff7e1880) // PCI-E
  142. };
  143. #undef _R
  144. enum cfg_version {
  145. RTL_CFG_0 = 0x00,
  146. RTL_CFG_1,
  147. RTL_CFG_2
  148. };
  149. static void rtl_hw_start_8169(struct net_device *);
  150. static void rtl_hw_start_8168(struct net_device *);
  151. static void rtl_hw_start_8101(struct net_device *);
  152. static DEFINE_PCI_DEVICE_TABLE(rtl8169_pci_tbl) = {
  153. { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8129), 0, 0, RTL_CFG_0 },
  154. { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8136), 0, 0, RTL_CFG_2 },
  155. { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8167), 0, 0, RTL_CFG_0 },
  156. { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8168), 0, 0, RTL_CFG_1 },
  157. { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8169), 0, 0, RTL_CFG_0 },
  158. { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4300), 0, 0, RTL_CFG_0 },
  159. { PCI_DEVICE(PCI_VENDOR_ID_AT, 0xc107), 0, 0, RTL_CFG_0 },
  160. { PCI_DEVICE(0x16ec, 0x0116), 0, 0, RTL_CFG_0 },
  161. { PCI_VENDOR_ID_LINKSYS, 0x1032,
  162. PCI_ANY_ID, 0x0024, 0, 0, RTL_CFG_0 },
  163. { 0x0001, 0x8168,
  164. PCI_ANY_ID, 0x2410, 0, 0, RTL_CFG_2 },
  165. {0,},
  166. };
  167. MODULE_DEVICE_TABLE(pci, rtl8169_pci_tbl);
  168. static int rx_copybreak = 200;
  169. static int use_dac = -1;
  170. static struct {
  171. u32 msg_enable;
  172. } debug = { -1 };
  173. enum rtl_registers {
  174. MAC0 = 0, /* Ethernet hardware address. */
  175. MAC4 = 4,
  176. MAR0 = 8, /* Multicast filter. */
  177. CounterAddrLow = 0x10,
  178. CounterAddrHigh = 0x14,
  179. TxDescStartAddrLow = 0x20,
  180. TxDescStartAddrHigh = 0x24,
  181. TxHDescStartAddrLow = 0x28,
  182. TxHDescStartAddrHigh = 0x2c,
  183. FLASH = 0x30,
  184. ERSR = 0x36,
  185. ChipCmd = 0x37,
  186. TxPoll = 0x38,
  187. IntrMask = 0x3c,
  188. IntrStatus = 0x3e,
  189. TxConfig = 0x40,
  190. RxConfig = 0x44,
  191. RxMissed = 0x4c,
  192. Cfg9346 = 0x50,
  193. Config0 = 0x51,
  194. Config1 = 0x52,
  195. Config2 = 0x53,
  196. Config3 = 0x54,
  197. Config4 = 0x55,
  198. Config5 = 0x56,
  199. MultiIntr = 0x5c,
  200. PHYAR = 0x60,
  201. PHYstatus = 0x6c,
  202. RxMaxSize = 0xda,
  203. CPlusCmd = 0xe0,
  204. IntrMitigate = 0xe2,
  205. RxDescAddrLow = 0xe4,
  206. RxDescAddrHigh = 0xe8,
  207. EarlyTxThres = 0xec,
  208. FuncEvent = 0xf0,
  209. FuncEventMask = 0xf4,
  210. FuncPresetState = 0xf8,
  211. FuncForceEvent = 0xfc,
  212. };
  213. enum rtl8110_registers {
  214. TBICSR = 0x64,
  215. TBI_ANAR = 0x68,
  216. TBI_LPAR = 0x6a,
  217. };
  218. enum rtl8168_8101_registers {
  219. CSIDR = 0x64,
  220. CSIAR = 0x68,
  221. #define CSIAR_FLAG 0x80000000
  222. #define CSIAR_WRITE_CMD 0x80000000
  223. #define CSIAR_BYTE_ENABLE 0x0f
  224. #define CSIAR_BYTE_ENABLE_SHIFT 12
  225. #define CSIAR_ADDR_MASK 0x0fff
  226. EPHYAR = 0x80,
  227. #define EPHYAR_FLAG 0x80000000
  228. #define EPHYAR_WRITE_CMD 0x80000000
  229. #define EPHYAR_REG_MASK 0x1f
  230. #define EPHYAR_REG_SHIFT 16
  231. #define EPHYAR_DATA_MASK 0xffff
  232. DBG_REG = 0xd1,
  233. #define FIX_NAK_1 (1 << 4)
  234. #define FIX_NAK_2 (1 << 3)
  235. EFUSEAR = 0xdc,
  236. #define EFUSEAR_FLAG 0x80000000
  237. #define EFUSEAR_WRITE_CMD 0x80000000
  238. #define EFUSEAR_READ_CMD 0x00000000
  239. #define EFUSEAR_REG_MASK 0x03ff
  240. #define EFUSEAR_REG_SHIFT 8
  241. #define EFUSEAR_DATA_MASK 0xff
  242. };
  243. enum rtl_register_content {
  244. /* InterruptStatusBits */
  245. SYSErr = 0x8000,
  246. PCSTimeout = 0x4000,
  247. SWInt = 0x0100,
  248. TxDescUnavail = 0x0080,
  249. RxFIFOOver = 0x0040,
  250. LinkChg = 0x0020,
  251. RxOverflow = 0x0010,
  252. TxErr = 0x0008,
  253. TxOK = 0x0004,
  254. RxErr = 0x0002,
  255. RxOK = 0x0001,
  256. /* RxStatusDesc */
  257. RxFOVF = (1 << 23),
  258. RxRWT = (1 << 22),
  259. RxRES = (1 << 21),
  260. RxRUNT = (1 << 20),
  261. RxCRC = (1 << 19),
  262. /* ChipCmdBits */
  263. CmdReset = 0x10,
  264. CmdRxEnb = 0x08,
  265. CmdTxEnb = 0x04,
  266. RxBufEmpty = 0x01,
  267. /* TXPoll register p.5 */
  268. HPQ = 0x80, /* Poll cmd on the high prio queue */
  269. NPQ = 0x40, /* Poll cmd on the low prio queue */
  270. FSWInt = 0x01, /* Forced software interrupt */
  271. /* Cfg9346Bits */
  272. Cfg9346_Lock = 0x00,
  273. Cfg9346_Unlock = 0xc0,
  274. /* rx_mode_bits */
  275. AcceptErr = 0x20,
  276. AcceptRunt = 0x10,
  277. AcceptBroadcast = 0x08,
  278. AcceptMulticast = 0x04,
  279. AcceptMyPhys = 0x02,
  280. AcceptAllPhys = 0x01,
  281. /* RxConfigBits */
  282. RxCfgFIFOShift = 13,
  283. RxCfgDMAShift = 8,
  284. /* TxConfigBits */
  285. TxInterFrameGapShift = 24,
  286. TxDMAShift = 8, /* DMA burst value (0-7) is shift this many bits */
  287. /* Config1 register p.24 */
  288. LEDS1 = (1 << 7),
  289. LEDS0 = (1 << 6),
  290. MSIEnable = (1 << 5), /* Enable Message Signaled Interrupt */
  291. Speed_down = (1 << 4),
  292. MEMMAP = (1 << 3),
  293. IOMAP = (1 << 2),
  294. VPD = (1 << 1),
  295. PMEnable = (1 << 0), /* Power Management Enable */
  296. /* Config2 register p. 25 */
  297. PCI_Clock_66MHz = 0x01,
  298. PCI_Clock_33MHz = 0x00,
  299. /* Config3 register p.25 */
  300. MagicPacket = (1 << 5), /* Wake up when receives a Magic Packet */
  301. LinkUp = (1 << 4), /* Wake up when the cable connection is re-established */
  302. Beacon_en = (1 << 0), /* 8168 only. Reserved in the 8168b */
  303. /* Config5 register p.27 */
  304. BWF = (1 << 6), /* Accept Broadcast wakeup frame */
  305. MWF = (1 << 5), /* Accept Multicast wakeup frame */
  306. UWF = (1 << 4), /* Accept Unicast wakeup frame */
  307. LanWake = (1 << 1), /* LanWake enable/disable */
  308. PMEStatus = (1 << 0), /* PME status can be reset by PCI RST# */
  309. /* TBICSR p.28 */
  310. TBIReset = 0x80000000,
  311. TBILoopback = 0x40000000,
  312. TBINwEnable = 0x20000000,
  313. TBINwRestart = 0x10000000,
  314. TBILinkOk = 0x02000000,
  315. TBINwComplete = 0x01000000,
  316. /* CPlusCmd p.31 */
  317. EnableBist = (1 << 15), // 8168 8101
  318. Mac_dbgo_oe = (1 << 14), // 8168 8101
  319. Normal_mode = (1 << 13), // unused
  320. Force_half_dup = (1 << 12), // 8168 8101
  321. Force_rxflow_en = (1 << 11), // 8168 8101
  322. Force_txflow_en = (1 << 10), // 8168 8101
  323. Cxpl_dbg_sel = (1 << 9), // 8168 8101
  324. ASF = (1 << 8), // 8168 8101
  325. PktCntrDisable = (1 << 7), // 8168 8101
  326. Mac_dbgo_sel = 0x001c, // 8168
  327. RxVlan = (1 << 6),
  328. RxChkSum = (1 << 5),
  329. PCIDAC = (1 << 4),
  330. PCIMulRW = (1 << 3),
  331. INTT_0 = 0x0000, // 8168
  332. INTT_1 = 0x0001, // 8168
  333. INTT_2 = 0x0002, // 8168
  334. INTT_3 = 0x0003, // 8168
  335. /* rtl8169_PHYstatus */
  336. TBI_Enable = 0x80,
  337. TxFlowCtrl = 0x40,
  338. RxFlowCtrl = 0x20,
  339. _1000bpsF = 0x10,
  340. _100bps = 0x08,
  341. _10bps = 0x04,
  342. LinkStatus = 0x02,
  343. FullDup = 0x01,
  344. /* _TBICSRBit */
  345. TBILinkOK = 0x02000000,
  346. /* DumpCounterCommand */
  347. CounterDump = 0x8,
  348. };
  349. enum desc_status_bit {
  350. DescOwn = (1 << 31), /* Descriptor is owned by NIC */
  351. RingEnd = (1 << 30), /* End of descriptor ring */
  352. FirstFrag = (1 << 29), /* First segment of a packet */
  353. LastFrag = (1 << 28), /* Final segment of a packet */
  354. /* Tx private */
  355. LargeSend = (1 << 27), /* TCP Large Send Offload (TSO) */
  356. MSSShift = 16, /* MSS value position */
  357. MSSMask = 0xfff, /* MSS value + LargeSend bit: 12 bits */
  358. IPCS = (1 << 18), /* Calculate IP checksum */
  359. UDPCS = (1 << 17), /* Calculate UDP/IP checksum */
  360. TCPCS = (1 << 16), /* Calculate TCP/IP checksum */
  361. TxVlanTag = (1 << 17), /* Add VLAN tag */
  362. /* Rx private */
  363. PID1 = (1 << 18), /* Protocol ID bit 1/2 */
  364. PID0 = (1 << 17), /* Protocol ID bit 2/2 */
  365. #define RxProtoUDP (PID1)
  366. #define RxProtoTCP (PID0)
  367. #define RxProtoIP (PID1 | PID0)
  368. #define RxProtoMask RxProtoIP
  369. IPFail = (1 << 16), /* IP checksum failed */
  370. UDPFail = (1 << 15), /* UDP/IP checksum failed */
  371. TCPFail = (1 << 14), /* TCP/IP checksum failed */
  372. RxVlanTag = (1 << 16), /* VLAN tag available */
  373. };
  374. #define RsvdMask 0x3fffc000
  375. struct TxDesc {
  376. __le32 opts1;
  377. __le32 opts2;
  378. __le64 addr;
  379. };
  380. struct RxDesc {
  381. __le32 opts1;
  382. __le32 opts2;
  383. __le64 addr;
  384. };
  385. struct ring_info {
  386. struct sk_buff *skb;
  387. u32 len;
  388. u8 __pad[sizeof(void *) - sizeof(u32)];
  389. };
  390. enum features {
  391. RTL_FEATURE_WOL = (1 << 0),
  392. RTL_FEATURE_MSI = (1 << 1),
  393. RTL_FEATURE_GMII = (1 << 2),
  394. };
  395. struct rtl8169_counters {
  396. __le64 tx_packets;
  397. __le64 rx_packets;
  398. __le64 tx_errors;
  399. __le32 rx_errors;
  400. __le16 rx_missed;
  401. __le16 align_errors;
  402. __le32 tx_one_collision;
  403. __le32 tx_multi_collision;
  404. __le64 rx_unicast;
  405. __le64 rx_broadcast;
  406. __le32 rx_multicast;
  407. __le16 tx_aborted;
  408. __le16 tx_underun;
  409. };
  410. struct rtl8169_private {
  411. void __iomem *mmio_addr; /* memory map physical address */
  412. struct pci_dev *pci_dev; /* Index of PCI device */
  413. struct net_device *dev;
  414. struct napi_struct napi;
  415. spinlock_t lock; /* spin lock flag */
  416. u32 msg_enable;
  417. int chipset;
  418. int mac_version;
  419. u32 cur_rx; /* Index into the Rx descriptor buffer of next Rx pkt. */
  420. u32 cur_tx; /* Index into the Tx descriptor buffer of next Rx pkt. */
  421. u32 dirty_rx;
  422. u32 dirty_tx;
  423. struct TxDesc *TxDescArray; /* 256-aligned Tx descriptor ring */
  424. struct RxDesc *RxDescArray; /* 256-aligned Rx descriptor ring */
  425. dma_addr_t TxPhyAddr;
  426. dma_addr_t RxPhyAddr;
  427. struct sk_buff *Rx_skbuff[NUM_RX_DESC]; /* Rx data buffers */
  428. struct ring_info tx_skb[NUM_TX_DESC]; /* Tx data buffers */
  429. unsigned align;
  430. unsigned rx_buf_sz;
  431. struct timer_list timer;
  432. u16 cp_cmd;
  433. u16 intr_event;
  434. u16 napi_event;
  435. u16 intr_mask;
  436. int phy_1000_ctrl_reg;
  437. #ifdef CONFIG_R8169_VLAN
  438. struct vlan_group *vlgrp;
  439. #endif
  440. int (*set_speed)(struct net_device *, u8 autoneg, u16 speed, u8 duplex);
  441. int (*get_settings)(struct net_device *, struct ethtool_cmd *);
  442. void (*phy_reset_enable)(void __iomem *);
  443. void (*hw_start)(struct net_device *);
  444. unsigned int (*phy_reset_pending)(void __iomem *);
  445. unsigned int (*link_ok)(void __iomem *);
  446. int (*do_ioctl)(struct rtl8169_private *tp, struct mii_ioctl_data *data, int cmd);
  447. int pcie_cap;
  448. struct delayed_work task;
  449. unsigned features;
  450. struct mii_if_info mii;
  451. struct rtl8169_counters counters;
  452. };
  453. MODULE_AUTHOR("Realtek and the Linux r8169 crew <netdev@vger.kernel.org>");
  454. MODULE_DESCRIPTION("RealTek RTL-8169 Gigabit Ethernet driver");
  455. module_param(rx_copybreak, int, 0);
  456. MODULE_PARM_DESC(rx_copybreak, "Copy breakpoint for copy-only-tiny-frames");
  457. module_param(use_dac, int, 0);
  458. MODULE_PARM_DESC(use_dac, "Enable PCI DAC. -1 defaults on for PCI Express only."
  459. " Unsafe on 32 bit PCI slot.");
  460. module_param_named(debug, debug.msg_enable, int, 0);
  461. MODULE_PARM_DESC(debug, "Debug verbosity level (0=none, ..., 16=all)");
  462. MODULE_LICENSE("GPL");
  463. MODULE_VERSION(RTL8169_VERSION);
  464. static int rtl8169_open(struct net_device *dev);
  465. static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb,
  466. struct net_device *dev);
  467. static irqreturn_t rtl8169_interrupt(int irq, void *dev_instance);
  468. static int rtl8169_init_ring(struct net_device *dev);
  469. static void rtl_hw_start(struct net_device *dev);
  470. static int rtl8169_close(struct net_device *dev);
  471. static void rtl_set_rx_mode(struct net_device *dev);
  472. static void rtl8169_tx_timeout(struct net_device *dev);
  473. static struct net_device_stats *rtl8169_get_stats(struct net_device *dev);
  474. static int rtl8169_rx_interrupt(struct net_device *, struct rtl8169_private *,
  475. void __iomem *, u32 budget);
  476. static int rtl8169_change_mtu(struct net_device *dev, int new_mtu);
  477. static void rtl8169_down(struct net_device *dev);
  478. static void rtl8169_rx_clear(struct rtl8169_private *tp);
  479. static int rtl8169_poll(struct napi_struct *napi, int budget);
  480. static const unsigned int rtl8169_rx_config =
  481. (RX_FIFO_THRESH << RxCfgFIFOShift) | (RX_DMA_BURST << RxCfgDMAShift);
  482. static void mdio_write(void __iomem *ioaddr, int reg_addr, int value)
  483. {
  484. int i;
  485. RTL_W32(PHYAR, 0x80000000 | (reg_addr & 0x1f) << 16 | (value & 0xffff));
  486. for (i = 20; i > 0; i--) {
  487. /*
  488. * Check if the RTL8169 has completed writing to the specified
  489. * MII register.
  490. */
  491. if (!(RTL_R32(PHYAR) & 0x80000000))
  492. break;
  493. udelay(25);
  494. }
  495. }
  496. static int mdio_read(void __iomem *ioaddr, int reg_addr)
  497. {
  498. int i, value = -1;
  499. RTL_W32(PHYAR, 0x0 | (reg_addr & 0x1f) << 16);
  500. for (i = 20; i > 0; i--) {
  501. /*
  502. * Check if the RTL8169 has completed retrieving data from
  503. * the specified MII register.
  504. */
  505. if (RTL_R32(PHYAR) & 0x80000000) {
  506. value = RTL_R32(PHYAR) & 0xffff;
  507. break;
  508. }
  509. udelay(25);
  510. }
  511. return value;
  512. }
  513. static void mdio_patch(void __iomem *ioaddr, int reg_addr, int value)
  514. {
  515. mdio_write(ioaddr, reg_addr, mdio_read(ioaddr, reg_addr) | value);
  516. }
  517. static void mdio_plus_minus(void __iomem *ioaddr, int reg_addr, int p, int m)
  518. {
  519. int val;
  520. val = mdio_read(ioaddr, reg_addr);
  521. mdio_write(ioaddr, reg_addr, (val | p) & ~m);
  522. }
  523. static void rtl_mdio_write(struct net_device *dev, int phy_id, int location,
  524. int val)
  525. {
  526. struct rtl8169_private *tp = netdev_priv(dev);
  527. void __iomem *ioaddr = tp->mmio_addr;
  528. mdio_write(ioaddr, location, val);
  529. }
  530. static int rtl_mdio_read(struct net_device *dev, int phy_id, int location)
  531. {
  532. struct rtl8169_private *tp = netdev_priv(dev);
  533. void __iomem *ioaddr = tp->mmio_addr;
  534. return mdio_read(ioaddr, location);
  535. }
  536. static void rtl_ephy_write(void __iomem *ioaddr, int reg_addr, int value)
  537. {
  538. unsigned int i;
  539. RTL_W32(EPHYAR, EPHYAR_WRITE_CMD | (value & EPHYAR_DATA_MASK) |
  540. (reg_addr & EPHYAR_REG_MASK) << EPHYAR_REG_SHIFT);
  541. for (i = 0; i < 100; i++) {
  542. if (!(RTL_R32(EPHYAR) & EPHYAR_FLAG))
  543. break;
  544. udelay(10);
  545. }
  546. }
  547. static u16 rtl_ephy_read(void __iomem *ioaddr, int reg_addr)
  548. {
  549. u16 value = 0xffff;
  550. unsigned int i;
  551. RTL_W32(EPHYAR, (reg_addr & EPHYAR_REG_MASK) << EPHYAR_REG_SHIFT);
  552. for (i = 0; i < 100; i++) {
  553. if (RTL_R32(EPHYAR) & EPHYAR_FLAG) {
  554. value = RTL_R32(EPHYAR) & EPHYAR_DATA_MASK;
  555. break;
  556. }
  557. udelay(10);
  558. }
  559. return value;
  560. }
  561. static void rtl_csi_write(void __iomem *ioaddr, int addr, int value)
  562. {
  563. unsigned int i;
  564. RTL_W32(CSIDR, value);
  565. RTL_W32(CSIAR, CSIAR_WRITE_CMD | (addr & CSIAR_ADDR_MASK) |
  566. CSIAR_BYTE_ENABLE << CSIAR_BYTE_ENABLE_SHIFT);
  567. for (i = 0; i < 100; i++) {
  568. if (!(RTL_R32(CSIAR) & CSIAR_FLAG))
  569. break;
  570. udelay(10);
  571. }
  572. }
  573. static u32 rtl_csi_read(void __iomem *ioaddr, int addr)
  574. {
  575. u32 value = ~0x00;
  576. unsigned int i;
  577. RTL_W32(CSIAR, (addr & CSIAR_ADDR_MASK) |
  578. CSIAR_BYTE_ENABLE << CSIAR_BYTE_ENABLE_SHIFT);
  579. for (i = 0; i < 100; i++) {
  580. if (RTL_R32(CSIAR) & CSIAR_FLAG) {
  581. value = RTL_R32(CSIDR);
  582. break;
  583. }
  584. udelay(10);
  585. }
  586. return value;
  587. }
  588. static u8 rtl8168d_efuse_read(void __iomem *ioaddr, int reg_addr)
  589. {
  590. u8 value = 0xff;
  591. unsigned int i;
  592. RTL_W32(EFUSEAR, (reg_addr & EFUSEAR_REG_MASK) << EFUSEAR_REG_SHIFT);
  593. for (i = 0; i < 300; i++) {
  594. if (RTL_R32(EFUSEAR) & EFUSEAR_FLAG) {
  595. value = RTL_R32(EFUSEAR) & EFUSEAR_DATA_MASK;
  596. break;
  597. }
  598. udelay(100);
  599. }
  600. return value;
  601. }
  602. static void rtl8169_irq_mask_and_ack(void __iomem *ioaddr)
  603. {
  604. RTL_W16(IntrMask, 0x0000);
  605. RTL_W16(IntrStatus, 0xffff);
  606. }
  607. static void rtl8169_asic_down(void __iomem *ioaddr)
  608. {
  609. RTL_W8(ChipCmd, 0x00);
  610. rtl8169_irq_mask_and_ack(ioaddr);
  611. RTL_R16(CPlusCmd);
  612. }
  613. static unsigned int rtl8169_tbi_reset_pending(void __iomem *ioaddr)
  614. {
  615. return RTL_R32(TBICSR) & TBIReset;
  616. }
  617. static unsigned int rtl8169_xmii_reset_pending(void __iomem *ioaddr)
  618. {
  619. return mdio_read(ioaddr, MII_BMCR) & BMCR_RESET;
  620. }
  621. static unsigned int rtl8169_tbi_link_ok(void __iomem *ioaddr)
  622. {
  623. return RTL_R32(TBICSR) & TBILinkOk;
  624. }
  625. static unsigned int rtl8169_xmii_link_ok(void __iomem *ioaddr)
  626. {
  627. return RTL_R8(PHYstatus) & LinkStatus;
  628. }
  629. static void rtl8169_tbi_reset_enable(void __iomem *ioaddr)
  630. {
  631. RTL_W32(TBICSR, RTL_R32(TBICSR) | TBIReset);
  632. }
  633. static void rtl8169_xmii_reset_enable(void __iomem *ioaddr)
  634. {
  635. unsigned int val;
  636. val = mdio_read(ioaddr, MII_BMCR) | BMCR_RESET;
  637. mdio_write(ioaddr, MII_BMCR, val & 0xffff);
  638. }
  639. static void rtl8169_check_link_status(struct net_device *dev,
  640. struct rtl8169_private *tp,
  641. void __iomem *ioaddr)
  642. {
  643. unsigned long flags;
  644. spin_lock_irqsave(&tp->lock, flags);
  645. if (tp->link_ok(ioaddr)) {
  646. netif_carrier_on(dev);
  647. netif_info(tp, ifup, dev, "link up\n");
  648. } else {
  649. netif_carrier_off(dev);
  650. netif_info(tp, ifdown, dev, "link down\n");
  651. }
  652. spin_unlock_irqrestore(&tp->lock, flags);
  653. }
  654. static void rtl8169_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  655. {
  656. struct rtl8169_private *tp = netdev_priv(dev);
  657. void __iomem *ioaddr = tp->mmio_addr;
  658. u8 options;
  659. wol->wolopts = 0;
  660. #define WAKE_ANY (WAKE_PHY | WAKE_MAGIC | WAKE_UCAST | WAKE_BCAST | WAKE_MCAST)
  661. wol->supported = WAKE_ANY;
  662. spin_lock_irq(&tp->lock);
  663. options = RTL_R8(Config1);
  664. if (!(options & PMEnable))
  665. goto out_unlock;
  666. options = RTL_R8(Config3);
  667. if (options & LinkUp)
  668. wol->wolopts |= WAKE_PHY;
  669. if (options & MagicPacket)
  670. wol->wolopts |= WAKE_MAGIC;
  671. options = RTL_R8(Config5);
  672. if (options & UWF)
  673. wol->wolopts |= WAKE_UCAST;
  674. if (options & BWF)
  675. wol->wolopts |= WAKE_BCAST;
  676. if (options & MWF)
  677. wol->wolopts |= WAKE_MCAST;
  678. out_unlock:
  679. spin_unlock_irq(&tp->lock);
  680. }
  681. static int rtl8169_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  682. {
  683. struct rtl8169_private *tp = netdev_priv(dev);
  684. void __iomem *ioaddr = tp->mmio_addr;
  685. unsigned int i;
  686. static const struct {
  687. u32 opt;
  688. u16 reg;
  689. u8 mask;
  690. } cfg[] = {
  691. { WAKE_ANY, Config1, PMEnable },
  692. { WAKE_PHY, Config3, LinkUp },
  693. { WAKE_MAGIC, Config3, MagicPacket },
  694. { WAKE_UCAST, Config5, UWF },
  695. { WAKE_BCAST, Config5, BWF },
  696. { WAKE_MCAST, Config5, MWF },
  697. { WAKE_ANY, Config5, LanWake }
  698. };
  699. spin_lock_irq(&tp->lock);
  700. RTL_W8(Cfg9346, Cfg9346_Unlock);
  701. for (i = 0; i < ARRAY_SIZE(cfg); i++) {
  702. u8 options = RTL_R8(cfg[i].reg) & ~cfg[i].mask;
  703. if (wol->wolopts & cfg[i].opt)
  704. options |= cfg[i].mask;
  705. RTL_W8(cfg[i].reg, options);
  706. }
  707. RTL_W8(Cfg9346, Cfg9346_Lock);
  708. if (wol->wolopts)
  709. tp->features |= RTL_FEATURE_WOL;
  710. else
  711. tp->features &= ~RTL_FEATURE_WOL;
  712. device_set_wakeup_enable(&tp->pci_dev->dev, wol->wolopts);
  713. spin_unlock_irq(&tp->lock);
  714. return 0;
  715. }
  716. static void rtl8169_get_drvinfo(struct net_device *dev,
  717. struct ethtool_drvinfo *info)
  718. {
  719. struct rtl8169_private *tp = netdev_priv(dev);
  720. strcpy(info->driver, MODULENAME);
  721. strcpy(info->version, RTL8169_VERSION);
  722. strcpy(info->bus_info, pci_name(tp->pci_dev));
  723. }
  724. static int rtl8169_get_regs_len(struct net_device *dev)
  725. {
  726. return R8169_REGS_SIZE;
  727. }
  728. static int rtl8169_set_speed_tbi(struct net_device *dev,
  729. u8 autoneg, u16 speed, u8 duplex)
  730. {
  731. struct rtl8169_private *tp = netdev_priv(dev);
  732. void __iomem *ioaddr = tp->mmio_addr;
  733. int ret = 0;
  734. u32 reg;
  735. reg = RTL_R32(TBICSR);
  736. if ((autoneg == AUTONEG_DISABLE) && (speed == SPEED_1000) &&
  737. (duplex == DUPLEX_FULL)) {
  738. RTL_W32(TBICSR, reg & ~(TBINwEnable | TBINwRestart));
  739. } else if (autoneg == AUTONEG_ENABLE)
  740. RTL_W32(TBICSR, reg | TBINwEnable | TBINwRestart);
  741. else {
  742. netif_warn(tp, link, dev,
  743. "incorrect speed setting refused in TBI mode\n");
  744. ret = -EOPNOTSUPP;
  745. }
  746. return ret;
  747. }
  748. static int rtl8169_set_speed_xmii(struct net_device *dev,
  749. u8 autoneg, u16 speed, u8 duplex)
  750. {
  751. struct rtl8169_private *tp = netdev_priv(dev);
  752. void __iomem *ioaddr = tp->mmio_addr;
  753. int giga_ctrl, bmcr;
  754. if (autoneg == AUTONEG_ENABLE) {
  755. int auto_nego;
  756. auto_nego = mdio_read(ioaddr, MII_ADVERTISE);
  757. auto_nego |= (ADVERTISE_10HALF | ADVERTISE_10FULL |
  758. ADVERTISE_100HALF | ADVERTISE_100FULL);
  759. auto_nego |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
  760. giga_ctrl = mdio_read(ioaddr, MII_CTRL1000);
  761. giga_ctrl &= ~(ADVERTISE_1000FULL | ADVERTISE_1000HALF);
  762. /* The 8100e/8101e/8102e do Fast Ethernet only. */
  763. if ((tp->mac_version != RTL_GIGA_MAC_VER_07) &&
  764. (tp->mac_version != RTL_GIGA_MAC_VER_08) &&
  765. (tp->mac_version != RTL_GIGA_MAC_VER_09) &&
  766. (tp->mac_version != RTL_GIGA_MAC_VER_10) &&
  767. (tp->mac_version != RTL_GIGA_MAC_VER_13) &&
  768. (tp->mac_version != RTL_GIGA_MAC_VER_14) &&
  769. (tp->mac_version != RTL_GIGA_MAC_VER_15) &&
  770. (tp->mac_version != RTL_GIGA_MAC_VER_16)) {
  771. giga_ctrl |= ADVERTISE_1000FULL | ADVERTISE_1000HALF;
  772. } else {
  773. netif_info(tp, link, dev,
  774. "PHY does not support 1000Mbps\n");
  775. }
  776. bmcr = BMCR_ANENABLE | BMCR_ANRESTART;
  777. if ((tp->mac_version == RTL_GIGA_MAC_VER_11) ||
  778. (tp->mac_version == RTL_GIGA_MAC_VER_12) ||
  779. (tp->mac_version >= RTL_GIGA_MAC_VER_17)) {
  780. /*
  781. * Wake up the PHY.
  782. * Vendor specific (0x1f) and reserved (0x0e) MII
  783. * registers.
  784. */
  785. mdio_write(ioaddr, 0x1f, 0x0000);
  786. mdio_write(ioaddr, 0x0e, 0x0000);
  787. }
  788. mdio_write(ioaddr, MII_ADVERTISE, auto_nego);
  789. mdio_write(ioaddr, MII_CTRL1000, giga_ctrl);
  790. } else {
  791. giga_ctrl = 0;
  792. if (speed == SPEED_10)
  793. bmcr = 0;
  794. else if (speed == SPEED_100)
  795. bmcr = BMCR_SPEED100;
  796. else
  797. return -EINVAL;
  798. if (duplex == DUPLEX_FULL)
  799. bmcr |= BMCR_FULLDPLX;
  800. mdio_write(ioaddr, 0x1f, 0x0000);
  801. }
  802. tp->phy_1000_ctrl_reg = giga_ctrl;
  803. mdio_write(ioaddr, MII_BMCR, bmcr);
  804. if ((tp->mac_version == RTL_GIGA_MAC_VER_02) ||
  805. (tp->mac_version == RTL_GIGA_MAC_VER_03)) {
  806. if ((speed == SPEED_100) && (autoneg != AUTONEG_ENABLE)) {
  807. mdio_write(ioaddr, 0x17, 0x2138);
  808. mdio_write(ioaddr, 0x0e, 0x0260);
  809. } else {
  810. mdio_write(ioaddr, 0x17, 0x2108);
  811. mdio_write(ioaddr, 0x0e, 0x0000);
  812. }
  813. }
  814. return 0;
  815. }
  816. static int rtl8169_set_speed(struct net_device *dev,
  817. u8 autoneg, u16 speed, u8 duplex)
  818. {
  819. struct rtl8169_private *tp = netdev_priv(dev);
  820. int ret;
  821. ret = tp->set_speed(dev, autoneg, speed, duplex);
  822. if (netif_running(dev) && (tp->phy_1000_ctrl_reg & ADVERTISE_1000FULL))
  823. mod_timer(&tp->timer, jiffies + RTL8169_PHY_TIMEOUT);
  824. return ret;
  825. }
  826. static int rtl8169_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  827. {
  828. struct rtl8169_private *tp = netdev_priv(dev);
  829. unsigned long flags;
  830. int ret;
  831. spin_lock_irqsave(&tp->lock, flags);
  832. ret = rtl8169_set_speed(dev, cmd->autoneg, cmd->speed, cmd->duplex);
  833. spin_unlock_irqrestore(&tp->lock, flags);
  834. return ret;
  835. }
  836. static u32 rtl8169_get_rx_csum(struct net_device *dev)
  837. {
  838. struct rtl8169_private *tp = netdev_priv(dev);
  839. return tp->cp_cmd & RxChkSum;
  840. }
  841. static int rtl8169_set_rx_csum(struct net_device *dev, u32 data)
  842. {
  843. struct rtl8169_private *tp = netdev_priv(dev);
  844. void __iomem *ioaddr = tp->mmio_addr;
  845. unsigned long flags;
  846. spin_lock_irqsave(&tp->lock, flags);
  847. if (data)
  848. tp->cp_cmd |= RxChkSum;
  849. else
  850. tp->cp_cmd &= ~RxChkSum;
  851. RTL_W16(CPlusCmd, tp->cp_cmd);
  852. RTL_R16(CPlusCmd);
  853. spin_unlock_irqrestore(&tp->lock, flags);
  854. return 0;
  855. }
  856. #ifdef CONFIG_R8169_VLAN
  857. static inline u32 rtl8169_tx_vlan_tag(struct rtl8169_private *tp,
  858. struct sk_buff *skb)
  859. {
  860. return (tp->vlgrp && vlan_tx_tag_present(skb)) ?
  861. TxVlanTag | swab16(vlan_tx_tag_get(skb)) : 0x00;
  862. }
  863. static void rtl8169_vlan_rx_register(struct net_device *dev,
  864. struct vlan_group *grp)
  865. {
  866. struct rtl8169_private *tp = netdev_priv(dev);
  867. void __iomem *ioaddr = tp->mmio_addr;
  868. unsigned long flags;
  869. spin_lock_irqsave(&tp->lock, flags);
  870. tp->vlgrp = grp;
  871. /*
  872. * Do not disable RxVlan on 8110SCd.
  873. */
  874. if (tp->vlgrp || (tp->mac_version == RTL_GIGA_MAC_VER_05))
  875. tp->cp_cmd |= RxVlan;
  876. else
  877. tp->cp_cmd &= ~RxVlan;
  878. RTL_W16(CPlusCmd, tp->cp_cmd);
  879. RTL_R16(CPlusCmd);
  880. spin_unlock_irqrestore(&tp->lock, flags);
  881. }
  882. static int rtl8169_rx_vlan_skb(struct rtl8169_private *tp, struct RxDesc *desc,
  883. struct sk_buff *skb)
  884. {
  885. u32 opts2 = le32_to_cpu(desc->opts2);
  886. struct vlan_group *vlgrp = tp->vlgrp;
  887. int ret;
  888. if (vlgrp && (opts2 & RxVlanTag)) {
  889. vlan_hwaccel_receive_skb(skb, vlgrp, swab16(opts2 & 0xffff));
  890. ret = 0;
  891. } else
  892. ret = -1;
  893. desc->opts2 = 0;
  894. return ret;
  895. }
  896. #else /* !CONFIG_R8169_VLAN */
  897. static inline u32 rtl8169_tx_vlan_tag(struct rtl8169_private *tp,
  898. struct sk_buff *skb)
  899. {
  900. return 0;
  901. }
  902. static int rtl8169_rx_vlan_skb(struct rtl8169_private *tp, struct RxDesc *desc,
  903. struct sk_buff *skb)
  904. {
  905. return -1;
  906. }
  907. #endif
  908. static int rtl8169_gset_tbi(struct net_device *dev, struct ethtool_cmd *cmd)
  909. {
  910. struct rtl8169_private *tp = netdev_priv(dev);
  911. void __iomem *ioaddr = tp->mmio_addr;
  912. u32 status;
  913. cmd->supported =
  914. SUPPORTED_1000baseT_Full | SUPPORTED_Autoneg | SUPPORTED_FIBRE;
  915. cmd->port = PORT_FIBRE;
  916. cmd->transceiver = XCVR_INTERNAL;
  917. status = RTL_R32(TBICSR);
  918. cmd->advertising = (status & TBINwEnable) ? ADVERTISED_Autoneg : 0;
  919. cmd->autoneg = !!(status & TBINwEnable);
  920. cmd->speed = SPEED_1000;
  921. cmd->duplex = DUPLEX_FULL; /* Always set */
  922. return 0;
  923. }
  924. static int rtl8169_gset_xmii(struct net_device *dev, struct ethtool_cmd *cmd)
  925. {
  926. struct rtl8169_private *tp = netdev_priv(dev);
  927. return mii_ethtool_gset(&tp->mii, cmd);
  928. }
  929. static int rtl8169_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  930. {
  931. struct rtl8169_private *tp = netdev_priv(dev);
  932. unsigned long flags;
  933. int rc;
  934. spin_lock_irqsave(&tp->lock, flags);
  935. rc = tp->get_settings(dev, cmd);
  936. spin_unlock_irqrestore(&tp->lock, flags);
  937. return rc;
  938. }
  939. static void rtl8169_get_regs(struct net_device *dev, struct ethtool_regs *regs,
  940. void *p)
  941. {
  942. struct rtl8169_private *tp = netdev_priv(dev);
  943. unsigned long flags;
  944. if (regs->len > R8169_REGS_SIZE)
  945. regs->len = R8169_REGS_SIZE;
  946. spin_lock_irqsave(&tp->lock, flags);
  947. memcpy_fromio(p, tp->mmio_addr, regs->len);
  948. spin_unlock_irqrestore(&tp->lock, flags);
  949. }
  950. static u32 rtl8169_get_msglevel(struct net_device *dev)
  951. {
  952. struct rtl8169_private *tp = netdev_priv(dev);
  953. return tp->msg_enable;
  954. }
  955. static void rtl8169_set_msglevel(struct net_device *dev, u32 value)
  956. {
  957. struct rtl8169_private *tp = netdev_priv(dev);
  958. tp->msg_enable = value;
  959. }
  960. static const char rtl8169_gstrings[][ETH_GSTRING_LEN] = {
  961. "tx_packets",
  962. "rx_packets",
  963. "tx_errors",
  964. "rx_errors",
  965. "rx_missed",
  966. "align_errors",
  967. "tx_single_collisions",
  968. "tx_multi_collisions",
  969. "unicast",
  970. "broadcast",
  971. "multicast",
  972. "tx_aborted",
  973. "tx_underrun",
  974. };
  975. static int rtl8169_get_sset_count(struct net_device *dev, int sset)
  976. {
  977. switch (sset) {
  978. case ETH_SS_STATS:
  979. return ARRAY_SIZE(rtl8169_gstrings);
  980. default:
  981. return -EOPNOTSUPP;
  982. }
  983. }
  984. static void rtl8169_update_counters(struct net_device *dev)
  985. {
  986. struct rtl8169_private *tp = netdev_priv(dev);
  987. void __iomem *ioaddr = tp->mmio_addr;
  988. struct rtl8169_counters *counters;
  989. dma_addr_t paddr;
  990. u32 cmd;
  991. int wait = 1000;
  992. /*
  993. * Some chips are unable to dump tally counters when the receiver
  994. * is disabled.
  995. */
  996. if ((RTL_R8(ChipCmd) & CmdRxEnb) == 0)
  997. return;
  998. counters = pci_alloc_consistent(tp->pci_dev, sizeof(*counters), &paddr);
  999. if (!counters)
  1000. return;
  1001. RTL_W32(CounterAddrHigh, (u64)paddr >> 32);
  1002. cmd = (u64)paddr & DMA_BIT_MASK(32);
  1003. RTL_W32(CounterAddrLow, cmd);
  1004. RTL_W32(CounterAddrLow, cmd | CounterDump);
  1005. while (wait--) {
  1006. if ((RTL_R32(CounterAddrLow) & CounterDump) == 0) {
  1007. /* copy updated counters */
  1008. memcpy(&tp->counters, counters, sizeof(*counters));
  1009. break;
  1010. }
  1011. udelay(10);
  1012. }
  1013. RTL_W32(CounterAddrLow, 0);
  1014. RTL_W32(CounterAddrHigh, 0);
  1015. pci_free_consistent(tp->pci_dev, sizeof(*counters), counters, paddr);
  1016. }
  1017. static void rtl8169_get_ethtool_stats(struct net_device *dev,
  1018. struct ethtool_stats *stats, u64 *data)
  1019. {
  1020. struct rtl8169_private *tp = netdev_priv(dev);
  1021. ASSERT_RTNL();
  1022. rtl8169_update_counters(dev);
  1023. data[0] = le64_to_cpu(tp->counters.tx_packets);
  1024. data[1] = le64_to_cpu(tp->counters.rx_packets);
  1025. data[2] = le64_to_cpu(tp->counters.tx_errors);
  1026. data[3] = le32_to_cpu(tp->counters.rx_errors);
  1027. data[4] = le16_to_cpu(tp->counters.rx_missed);
  1028. data[5] = le16_to_cpu(tp->counters.align_errors);
  1029. data[6] = le32_to_cpu(tp->counters.tx_one_collision);
  1030. data[7] = le32_to_cpu(tp->counters.tx_multi_collision);
  1031. data[8] = le64_to_cpu(tp->counters.rx_unicast);
  1032. data[9] = le64_to_cpu(tp->counters.rx_broadcast);
  1033. data[10] = le32_to_cpu(tp->counters.rx_multicast);
  1034. data[11] = le16_to_cpu(tp->counters.tx_aborted);
  1035. data[12] = le16_to_cpu(tp->counters.tx_underun);
  1036. }
  1037. static void rtl8169_get_strings(struct net_device *dev, u32 stringset, u8 *data)
  1038. {
  1039. switch(stringset) {
  1040. case ETH_SS_STATS:
  1041. memcpy(data, *rtl8169_gstrings, sizeof(rtl8169_gstrings));
  1042. break;
  1043. }
  1044. }
  1045. static const struct ethtool_ops rtl8169_ethtool_ops = {
  1046. .get_drvinfo = rtl8169_get_drvinfo,
  1047. .get_regs_len = rtl8169_get_regs_len,
  1048. .get_link = ethtool_op_get_link,
  1049. .get_settings = rtl8169_get_settings,
  1050. .set_settings = rtl8169_set_settings,
  1051. .get_msglevel = rtl8169_get_msglevel,
  1052. .set_msglevel = rtl8169_set_msglevel,
  1053. .get_rx_csum = rtl8169_get_rx_csum,
  1054. .set_rx_csum = rtl8169_set_rx_csum,
  1055. .set_tx_csum = ethtool_op_set_tx_csum,
  1056. .set_sg = ethtool_op_set_sg,
  1057. .set_tso = ethtool_op_set_tso,
  1058. .get_regs = rtl8169_get_regs,
  1059. .get_wol = rtl8169_get_wol,
  1060. .set_wol = rtl8169_set_wol,
  1061. .get_strings = rtl8169_get_strings,
  1062. .get_sset_count = rtl8169_get_sset_count,
  1063. .get_ethtool_stats = rtl8169_get_ethtool_stats,
  1064. };
  1065. static void rtl8169_get_mac_version(struct rtl8169_private *tp,
  1066. void __iomem *ioaddr)
  1067. {
  1068. /*
  1069. * The driver currently handles the 8168Bf and the 8168Be identically
  1070. * but they can be identified more specifically through the test below
  1071. * if needed:
  1072. *
  1073. * (RTL_R32(TxConfig) & 0x700000) == 0x500000 ? 8168Bf : 8168Be
  1074. *
  1075. * Same thing for the 8101Eb and the 8101Ec:
  1076. *
  1077. * (RTL_R32(TxConfig) & 0x700000) == 0x200000 ? 8101Eb : 8101Ec
  1078. */
  1079. static const struct {
  1080. u32 mask;
  1081. u32 val;
  1082. int mac_version;
  1083. } mac_info[] = {
  1084. /* 8168D family. */
  1085. { 0x7cf00000, 0x28300000, RTL_GIGA_MAC_VER_26 },
  1086. { 0x7cf00000, 0x28100000, RTL_GIGA_MAC_VER_25 },
  1087. { 0x7c800000, 0x28800000, RTL_GIGA_MAC_VER_27 },
  1088. { 0x7c800000, 0x28000000, RTL_GIGA_MAC_VER_26 },
  1089. /* 8168C family. */
  1090. { 0x7cf00000, 0x3ca00000, RTL_GIGA_MAC_VER_24 },
  1091. { 0x7cf00000, 0x3c900000, RTL_GIGA_MAC_VER_23 },
  1092. { 0x7cf00000, 0x3c800000, RTL_GIGA_MAC_VER_18 },
  1093. { 0x7c800000, 0x3c800000, RTL_GIGA_MAC_VER_24 },
  1094. { 0x7cf00000, 0x3c000000, RTL_GIGA_MAC_VER_19 },
  1095. { 0x7cf00000, 0x3c200000, RTL_GIGA_MAC_VER_20 },
  1096. { 0x7cf00000, 0x3c300000, RTL_GIGA_MAC_VER_21 },
  1097. { 0x7cf00000, 0x3c400000, RTL_GIGA_MAC_VER_22 },
  1098. { 0x7c800000, 0x3c000000, RTL_GIGA_MAC_VER_22 },
  1099. /* 8168B family. */
  1100. { 0x7cf00000, 0x38000000, RTL_GIGA_MAC_VER_12 },
  1101. { 0x7cf00000, 0x38500000, RTL_GIGA_MAC_VER_17 },
  1102. { 0x7c800000, 0x38000000, RTL_GIGA_MAC_VER_17 },
  1103. { 0x7c800000, 0x30000000, RTL_GIGA_MAC_VER_11 },
  1104. /* 8101 family. */
  1105. { 0x7cf00000, 0x34a00000, RTL_GIGA_MAC_VER_09 },
  1106. { 0x7cf00000, 0x24a00000, RTL_GIGA_MAC_VER_09 },
  1107. { 0x7cf00000, 0x34900000, RTL_GIGA_MAC_VER_08 },
  1108. { 0x7cf00000, 0x24900000, RTL_GIGA_MAC_VER_08 },
  1109. { 0x7cf00000, 0x34800000, RTL_GIGA_MAC_VER_07 },
  1110. { 0x7cf00000, 0x24800000, RTL_GIGA_MAC_VER_07 },
  1111. { 0x7cf00000, 0x34000000, RTL_GIGA_MAC_VER_13 },
  1112. { 0x7cf00000, 0x34300000, RTL_GIGA_MAC_VER_10 },
  1113. { 0x7cf00000, 0x34200000, RTL_GIGA_MAC_VER_16 },
  1114. { 0x7c800000, 0x34800000, RTL_GIGA_MAC_VER_09 },
  1115. { 0x7c800000, 0x24800000, RTL_GIGA_MAC_VER_09 },
  1116. { 0x7c800000, 0x34000000, RTL_GIGA_MAC_VER_16 },
  1117. /* FIXME: where did these entries come from ? -- FR */
  1118. { 0xfc800000, 0x38800000, RTL_GIGA_MAC_VER_15 },
  1119. { 0xfc800000, 0x30800000, RTL_GIGA_MAC_VER_14 },
  1120. /* 8110 family. */
  1121. { 0xfc800000, 0x98000000, RTL_GIGA_MAC_VER_06 },
  1122. { 0xfc800000, 0x18000000, RTL_GIGA_MAC_VER_05 },
  1123. { 0xfc800000, 0x10000000, RTL_GIGA_MAC_VER_04 },
  1124. { 0xfc800000, 0x04000000, RTL_GIGA_MAC_VER_03 },
  1125. { 0xfc800000, 0x00800000, RTL_GIGA_MAC_VER_02 },
  1126. { 0xfc800000, 0x00000000, RTL_GIGA_MAC_VER_01 },
  1127. /* Catch-all */
  1128. { 0x00000000, 0x00000000, RTL_GIGA_MAC_NONE }
  1129. }, *p = mac_info;
  1130. u32 reg;
  1131. reg = RTL_R32(TxConfig);
  1132. while ((reg & p->mask) != p->val)
  1133. p++;
  1134. tp->mac_version = p->mac_version;
  1135. }
  1136. static void rtl8169_print_mac_version(struct rtl8169_private *tp)
  1137. {
  1138. dprintk("mac_version = 0x%02x\n", tp->mac_version);
  1139. }
  1140. struct phy_reg {
  1141. u16 reg;
  1142. u16 val;
  1143. };
  1144. static void rtl_phy_write(void __iomem *ioaddr, const struct phy_reg *regs, int len)
  1145. {
  1146. while (len-- > 0) {
  1147. mdio_write(ioaddr, regs->reg, regs->val);
  1148. regs++;
  1149. }
  1150. }
  1151. static void rtl8169s_hw_phy_config(void __iomem *ioaddr)
  1152. {
  1153. static const struct phy_reg phy_reg_init[] = {
  1154. { 0x1f, 0x0001 },
  1155. { 0x06, 0x006e },
  1156. { 0x08, 0x0708 },
  1157. { 0x15, 0x4000 },
  1158. { 0x18, 0x65c7 },
  1159. { 0x1f, 0x0001 },
  1160. { 0x03, 0x00a1 },
  1161. { 0x02, 0x0008 },
  1162. { 0x01, 0x0120 },
  1163. { 0x00, 0x1000 },
  1164. { 0x04, 0x0800 },
  1165. { 0x04, 0x0000 },
  1166. { 0x03, 0xff41 },
  1167. { 0x02, 0xdf60 },
  1168. { 0x01, 0x0140 },
  1169. { 0x00, 0x0077 },
  1170. { 0x04, 0x7800 },
  1171. { 0x04, 0x7000 },
  1172. { 0x03, 0x802f },
  1173. { 0x02, 0x4f02 },
  1174. { 0x01, 0x0409 },
  1175. { 0x00, 0xf0f9 },
  1176. { 0x04, 0x9800 },
  1177. { 0x04, 0x9000 },
  1178. { 0x03, 0xdf01 },
  1179. { 0x02, 0xdf20 },
  1180. { 0x01, 0xff95 },
  1181. { 0x00, 0xba00 },
  1182. { 0x04, 0xa800 },
  1183. { 0x04, 0xa000 },
  1184. { 0x03, 0xff41 },
  1185. { 0x02, 0xdf20 },
  1186. { 0x01, 0x0140 },
  1187. { 0x00, 0x00bb },
  1188. { 0x04, 0xb800 },
  1189. { 0x04, 0xb000 },
  1190. { 0x03, 0xdf41 },
  1191. { 0x02, 0xdc60 },
  1192. { 0x01, 0x6340 },
  1193. { 0x00, 0x007d },
  1194. { 0x04, 0xd800 },
  1195. { 0x04, 0xd000 },
  1196. { 0x03, 0xdf01 },
  1197. { 0x02, 0xdf20 },
  1198. { 0x01, 0x100a },
  1199. { 0x00, 0xa0ff },
  1200. { 0x04, 0xf800 },
  1201. { 0x04, 0xf000 },
  1202. { 0x1f, 0x0000 },
  1203. { 0x0b, 0x0000 },
  1204. { 0x00, 0x9200 }
  1205. };
  1206. rtl_phy_write(ioaddr, phy_reg_init, ARRAY_SIZE(phy_reg_init));
  1207. }
  1208. static void rtl8169sb_hw_phy_config(void __iomem *ioaddr)
  1209. {
  1210. static const struct phy_reg phy_reg_init[] = {
  1211. { 0x1f, 0x0002 },
  1212. { 0x01, 0x90d0 },
  1213. { 0x1f, 0x0000 }
  1214. };
  1215. rtl_phy_write(ioaddr, phy_reg_init, ARRAY_SIZE(phy_reg_init));
  1216. }
  1217. static void rtl8169scd_hw_phy_config_quirk(struct rtl8169_private *tp,
  1218. void __iomem *ioaddr)
  1219. {
  1220. struct pci_dev *pdev = tp->pci_dev;
  1221. u16 vendor_id, device_id;
  1222. pci_read_config_word(pdev, PCI_SUBSYSTEM_VENDOR_ID, &vendor_id);
  1223. pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &device_id);
  1224. if ((vendor_id != PCI_VENDOR_ID_GIGABYTE) || (device_id != 0xe000))
  1225. return;
  1226. mdio_write(ioaddr, 0x1f, 0x0001);
  1227. mdio_write(ioaddr, 0x10, 0xf01b);
  1228. mdio_write(ioaddr, 0x1f, 0x0000);
  1229. }
  1230. static void rtl8169scd_hw_phy_config(struct rtl8169_private *tp,
  1231. void __iomem *ioaddr)
  1232. {
  1233. static const struct phy_reg phy_reg_init[] = {
  1234. { 0x1f, 0x0001 },
  1235. { 0x04, 0x0000 },
  1236. { 0x03, 0x00a1 },
  1237. { 0x02, 0x0008 },
  1238. { 0x01, 0x0120 },
  1239. { 0x00, 0x1000 },
  1240. { 0x04, 0x0800 },
  1241. { 0x04, 0x9000 },
  1242. { 0x03, 0x802f },
  1243. { 0x02, 0x4f02 },
  1244. { 0x01, 0x0409 },
  1245. { 0x00, 0xf099 },
  1246. { 0x04, 0x9800 },
  1247. { 0x04, 0xa000 },
  1248. { 0x03, 0xdf01 },
  1249. { 0x02, 0xdf20 },
  1250. { 0x01, 0xff95 },
  1251. { 0x00, 0xba00 },
  1252. { 0x04, 0xa800 },
  1253. { 0x04, 0xf000 },
  1254. { 0x03, 0xdf01 },
  1255. { 0x02, 0xdf20 },
  1256. { 0x01, 0x101a },
  1257. { 0x00, 0xa0ff },
  1258. { 0x04, 0xf800 },
  1259. { 0x04, 0x0000 },
  1260. { 0x1f, 0x0000 },
  1261. { 0x1f, 0x0001 },
  1262. { 0x10, 0xf41b },
  1263. { 0x14, 0xfb54 },
  1264. { 0x18, 0xf5c7 },
  1265. { 0x1f, 0x0000 },
  1266. { 0x1f, 0x0001 },
  1267. { 0x17, 0x0cc0 },
  1268. { 0x1f, 0x0000 }
  1269. };
  1270. rtl_phy_write(ioaddr, phy_reg_init, ARRAY_SIZE(phy_reg_init));
  1271. rtl8169scd_hw_phy_config_quirk(tp, ioaddr);
  1272. }
  1273. static void rtl8169sce_hw_phy_config(void __iomem *ioaddr)
  1274. {
  1275. static const struct phy_reg phy_reg_init[] = {
  1276. { 0x1f, 0x0001 },
  1277. { 0x04, 0x0000 },
  1278. { 0x03, 0x00a1 },
  1279. { 0x02, 0x0008 },
  1280. { 0x01, 0x0120 },
  1281. { 0x00, 0x1000 },
  1282. { 0x04, 0x0800 },
  1283. { 0x04, 0x9000 },
  1284. { 0x03, 0x802f },
  1285. { 0x02, 0x4f02 },
  1286. { 0x01, 0x0409 },
  1287. { 0x00, 0xf099 },
  1288. { 0x04, 0x9800 },
  1289. { 0x04, 0xa000 },
  1290. { 0x03, 0xdf01 },
  1291. { 0x02, 0xdf20 },
  1292. { 0x01, 0xff95 },
  1293. { 0x00, 0xba00 },
  1294. { 0x04, 0xa800 },
  1295. { 0x04, 0xf000 },
  1296. { 0x03, 0xdf01 },
  1297. { 0x02, 0xdf20 },
  1298. { 0x01, 0x101a },
  1299. { 0x00, 0xa0ff },
  1300. { 0x04, 0xf800 },
  1301. { 0x04, 0x0000 },
  1302. { 0x1f, 0x0000 },
  1303. { 0x1f, 0x0001 },
  1304. { 0x0b, 0x8480 },
  1305. { 0x1f, 0x0000 },
  1306. { 0x1f, 0x0001 },
  1307. { 0x18, 0x67c7 },
  1308. { 0x04, 0x2000 },
  1309. { 0x03, 0x002f },
  1310. { 0x02, 0x4360 },
  1311. { 0x01, 0x0109 },
  1312. { 0x00, 0x3022 },
  1313. { 0x04, 0x2800 },
  1314. { 0x1f, 0x0000 },
  1315. { 0x1f, 0x0001 },
  1316. { 0x17, 0x0cc0 },
  1317. { 0x1f, 0x0000 }
  1318. };
  1319. rtl_phy_write(ioaddr, phy_reg_init, ARRAY_SIZE(phy_reg_init));
  1320. }
  1321. static void rtl8168bb_hw_phy_config(void __iomem *ioaddr)
  1322. {
  1323. static const struct phy_reg phy_reg_init[] = {
  1324. { 0x10, 0xf41b },
  1325. { 0x1f, 0x0000 }
  1326. };
  1327. mdio_write(ioaddr, 0x1f, 0x0001);
  1328. mdio_patch(ioaddr, 0x16, 1 << 0);
  1329. rtl_phy_write(ioaddr, phy_reg_init, ARRAY_SIZE(phy_reg_init));
  1330. }
  1331. static void rtl8168bef_hw_phy_config(void __iomem *ioaddr)
  1332. {
  1333. static const struct phy_reg phy_reg_init[] = {
  1334. { 0x1f, 0x0001 },
  1335. { 0x10, 0xf41b },
  1336. { 0x1f, 0x0000 }
  1337. };
  1338. rtl_phy_write(ioaddr, phy_reg_init, ARRAY_SIZE(phy_reg_init));
  1339. }
  1340. static void rtl8168cp_1_hw_phy_config(void __iomem *ioaddr)
  1341. {
  1342. static const struct phy_reg phy_reg_init[] = {
  1343. { 0x1f, 0x0000 },
  1344. { 0x1d, 0x0f00 },
  1345. { 0x1f, 0x0002 },
  1346. { 0x0c, 0x1ec8 },
  1347. { 0x1f, 0x0000 }
  1348. };
  1349. rtl_phy_write(ioaddr, phy_reg_init, ARRAY_SIZE(phy_reg_init));
  1350. }
  1351. static void rtl8168cp_2_hw_phy_config(void __iomem *ioaddr)
  1352. {
  1353. static const struct phy_reg phy_reg_init[] = {
  1354. { 0x1f, 0x0001 },
  1355. { 0x1d, 0x3d98 },
  1356. { 0x1f, 0x0000 }
  1357. };
  1358. mdio_write(ioaddr, 0x1f, 0x0000);
  1359. mdio_patch(ioaddr, 0x14, 1 << 5);
  1360. mdio_patch(ioaddr, 0x0d, 1 << 5);
  1361. rtl_phy_write(ioaddr, phy_reg_init, ARRAY_SIZE(phy_reg_init));
  1362. }
  1363. static void rtl8168c_1_hw_phy_config(void __iomem *ioaddr)
  1364. {
  1365. static const struct phy_reg phy_reg_init[] = {
  1366. { 0x1f, 0x0001 },
  1367. { 0x12, 0x2300 },
  1368. { 0x1f, 0x0002 },
  1369. { 0x00, 0x88d4 },
  1370. { 0x01, 0x82b1 },
  1371. { 0x03, 0x7002 },
  1372. { 0x08, 0x9e30 },
  1373. { 0x09, 0x01f0 },
  1374. { 0x0a, 0x5500 },
  1375. { 0x0c, 0x00c8 },
  1376. { 0x1f, 0x0003 },
  1377. { 0x12, 0xc096 },
  1378. { 0x16, 0x000a },
  1379. { 0x1f, 0x0000 },
  1380. { 0x1f, 0x0000 },
  1381. { 0x09, 0x2000 },
  1382. { 0x09, 0x0000 }
  1383. };
  1384. rtl_phy_write(ioaddr, phy_reg_init, ARRAY_SIZE(phy_reg_init));
  1385. mdio_patch(ioaddr, 0x14, 1 << 5);
  1386. mdio_patch(ioaddr, 0x0d, 1 << 5);
  1387. mdio_write(ioaddr, 0x1f, 0x0000);
  1388. }
  1389. static void rtl8168c_2_hw_phy_config(void __iomem *ioaddr)
  1390. {
  1391. static const struct phy_reg phy_reg_init[] = {
  1392. { 0x1f, 0x0001 },
  1393. { 0x12, 0x2300 },
  1394. { 0x03, 0x802f },
  1395. { 0x02, 0x4f02 },
  1396. { 0x01, 0x0409 },
  1397. { 0x00, 0xf099 },
  1398. { 0x04, 0x9800 },
  1399. { 0x04, 0x9000 },
  1400. { 0x1d, 0x3d98 },
  1401. { 0x1f, 0x0002 },
  1402. { 0x0c, 0x7eb8 },
  1403. { 0x06, 0x0761 },
  1404. { 0x1f, 0x0003 },
  1405. { 0x16, 0x0f0a },
  1406. { 0x1f, 0x0000 }
  1407. };
  1408. rtl_phy_write(ioaddr, phy_reg_init, ARRAY_SIZE(phy_reg_init));
  1409. mdio_patch(ioaddr, 0x16, 1 << 0);
  1410. mdio_patch(ioaddr, 0x14, 1 << 5);
  1411. mdio_patch(ioaddr, 0x0d, 1 << 5);
  1412. mdio_write(ioaddr, 0x1f, 0x0000);
  1413. }
  1414. static void rtl8168c_3_hw_phy_config(void __iomem *ioaddr)
  1415. {
  1416. static const struct phy_reg phy_reg_init[] = {
  1417. { 0x1f, 0x0001 },
  1418. { 0x12, 0x2300 },
  1419. { 0x1d, 0x3d98 },
  1420. { 0x1f, 0x0002 },
  1421. { 0x0c, 0x7eb8 },
  1422. { 0x06, 0x5461 },
  1423. { 0x1f, 0x0003 },
  1424. { 0x16, 0x0f0a },
  1425. { 0x1f, 0x0000 }
  1426. };
  1427. rtl_phy_write(ioaddr, phy_reg_init, ARRAY_SIZE(phy_reg_init));
  1428. mdio_patch(ioaddr, 0x16, 1 << 0);
  1429. mdio_patch(ioaddr, 0x14, 1 << 5);
  1430. mdio_patch(ioaddr, 0x0d, 1 << 5);
  1431. mdio_write(ioaddr, 0x1f, 0x0000);
  1432. }
  1433. static void rtl8168c_4_hw_phy_config(void __iomem *ioaddr)
  1434. {
  1435. rtl8168c_3_hw_phy_config(ioaddr);
  1436. }
  1437. static void rtl8168d_1_hw_phy_config(void __iomem *ioaddr)
  1438. {
  1439. static const struct phy_reg phy_reg_init_0[] = {
  1440. { 0x1f, 0x0001 },
  1441. { 0x06, 0x4064 },
  1442. { 0x07, 0x2863 },
  1443. { 0x08, 0x059c },
  1444. { 0x09, 0x26b4 },
  1445. { 0x0a, 0x6a19 },
  1446. { 0x0b, 0xdcc8 },
  1447. { 0x10, 0xf06d },
  1448. { 0x14, 0x7f68 },
  1449. { 0x18, 0x7fd9 },
  1450. { 0x1c, 0xf0ff },
  1451. { 0x1d, 0x3d9c },
  1452. { 0x1f, 0x0003 },
  1453. { 0x12, 0xf49f },
  1454. { 0x13, 0x070b },
  1455. { 0x1a, 0x05ad },
  1456. { 0x14, 0x94c0 }
  1457. };
  1458. static const struct phy_reg phy_reg_init_1[] = {
  1459. { 0x1f, 0x0002 },
  1460. { 0x06, 0x5561 },
  1461. { 0x1f, 0x0005 },
  1462. { 0x05, 0x8332 },
  1463. { 0x06, 0x5561 }
  1464. };
  1465. static const struct phy_reg phy_reg_init_2[] = {
  1466. { 0x1f, 0x0005 },
  1467. { 0x05, 0xffc2 },
  1468. { 0x1f, 0x0005 },
  1469. { 0x05, 0x8000 },
  1470. { 0x06, 0xf8f9 },
  1471. { 0x06, 0xfaef },
  1472. { 0x06, 0x59ee },
  1473. { 0x06, 0xf8ea },
  1474. { 0x06, 0x00ee },
  1475. { 0x06, 0xf8eb },
  1476. { 0x06, 0x00e0 },
  1477. { 0x06, 0xf87c },
  1478. { 0x06, 0xe1f8 },
  1479. { 0x06, 0x7d59 },
  1480. { 0x06, 0x0fef },
  1481. { 0x06, 0x0139 },
  1482. { 0x06, 0x029e },
  1483. { 0x06, 0x06ef },
  1484. { 0x06, 0x1039 },
  1485. { 0x06, 0x089f },
  1486. { 0x06, 0x2aee },
  1487. { 0x06, 0xf8ea },
  1488. { 0x06, 0x00ee },
  1489. { 0x06, 0xf8eb },
  1490. { 0x06, 0x01e0 },
  1491. { 0x06, 0xf87c },
  1492. { 0x06, 0xe1f8 },
  1493. { 0x06, 0x7d58 },
  1494. { 0x06, 0x409e },
  1495. { 0x06, 0x0f39 },
  1496. { 0x06, 0x46aa },
  1497. { 0x06, 0x0bbf },
  1498. { 0x06, 0x8290 },
  1499. { 0x06, 0xd682 },
  1500. { 0x06, 0x9802 },
  1501. { 0x06, 0x014f },
  1502. { 0x06, 0xae09 },
  1503. { 0x06, 0xbf82 },
  1504. { 0x06, 0x98d6 },
  1505. { 0x06, 0x82a0 },
  1506. { 0x06, 0x0201 },
  1507. { 0x06, 0x4fef },
  1508. { 0x06, 0x95fe },
  1509. { 0x06, 0xfdfc },
  1510. { 0x06, 0x05f8 },
  1511. { 0x06, 0xf9fa },
  1512. { 0x06, 0xeef8 },
  1513. { 0x06, 0xea00 },
  1514. { 0x06, 0xeef8 },
  1515. { 0x06, 0xeb00 },
  1516. { 0x06, 0xe2f8 },
  1517. { 0x06, 0x7ce3 },
  1518. { 0x06, 0xf87d },
  1519. { 0x06, 0xa511 },
  1520. { 0x06, 0x1112 },
  1521. { 0x06, 0xd240 },
  1522. { 0x06, 0xd644 },
  1523. { 0x06, 0x4402 },
  1524. { 0x06, 0x8217 },
  1525. { 0x06, 0xd2a0 },
  1526. { 0x06, 0xd6aa },
  1527. { 0x06, 0xaa02 },
  1528. { 0x06, 0x8217 },
  1529. { 0x06, 0xae0f },
  1530. { 0x06, 0xa544 },
  1531. { 0x06, 0x4402 },
  1532. { 0x06, 0xae4d },
  1533. { 0x06, 0xa5aa },
  1534. { 0x06, 0xaa02 },
  1535. { 0x06, 0xae47 },
  1536. { 0x06, 0xaf82 },
  1537. { 0x06, 0x13ee },
  1538. { 0x06, 0x834e },
  1539. { 0x06, 0x00ee },
  1540. { 0x06, 0x834d },
  1541. { 0x06, 0x0fee },
  1542. { 0x06, 0x834c },
  1543. { 0x06, 0x0fee },
  1544. { 0x06, 0x834f },
  1545. { 0x06, 0x00ee },
  1546. { 0x06, 0x8351 },
  1547. { 0x06, 0x00ee },
  1548. { 0x06, 0x834a },
  1549. { 0x06, 0xffee },
  1550. { 0x06, 0x834b },
  1551. { 0x06, 0xffe0 },
  1552. { 0x06, 0x8330 },
  1553. { 0x06, 0xe183 },
  1554. { 0x06, 0x3158 },
  1555. { 0x06, 0xfee4 },
  1556. { 0x06, 0xf88a },
  1557. { 0x06, 0xe5f8 },
  1558. { 0x06, 0x8be0 },
  1559. { 0x06, 0x8332 },
  1560. { 0x06, 0xe183 },
  1561. { 0x06, 0x3359 },
  1562. { 0x06, 0x0fe2 },
  1563. { 0x06, 0x834d },
  1564. { 0x06, 0x0c24 },
  1565. { 0x06, 0x5af0 },
  1566. { 0x06, 0x1e12 },
  1567. { 0x06, 0xe4f8 },
  1568. { 0x06, 0x8ce5 },
  1569. { 0x06, 0xf88d },
  1570. { 0x06, 0xaf82 },
  1571. { 0x06, 0x13e0 },
  1572. { 0x06, 0x834f },
  1573. { 0x06, 0x10e4 },
  1574. { 0x06, 0x834f },
  1575. { 0x06, 0xe083 },
  1576. { 0x06, 0x4e78 },
  1577. { 0x06, 0x009f },
  1578. { 0x06, 0x0ae0 },
  1579. { 0x06, 0x834f },
  1580. { 0x06, 0xa010 },
  1581. { 0x06, 0xa5ee },
  1582. { 0x06, 0x834e },
  1583. { 0x06, 0x01e0 },
  1584. { 0x06, 0x834e },
  1585. { 0x06, 0x7805 },
  1586. { 0x06, 0x9e9a },
  1587. { 0x06, 0xe083 },
  1588. { 0x06, 0x4e78 },
  1589. { 0x06, 0x049e },
  1590. { 0x06, 0x10e0 },
  1591. { 0x06, 0x834e },
  1592. { 0x06, 0x7803 },
  1593. { 0x06, 0x9e0f },
  1594. { 0x06, 0xe083 },
  1595. { 0x06, 0x4e78 },
  1596. { 0x06, 0x019e },
  1597. { 0x06, 0x05ae },
  1598. { 0x06, 0x0caf },
  1599. { 0x06, 0x81f8 },
  1600. { 0x06, 0xaf81 },
  1601. { 0x06, 0xa3af },
  1602. { 0x06, 0x81dc },
  1603. { 0x06, 0xaf82 },
  1604. { 0x06, 0x13ee },
  1605. { 0x06, 0x8348 },
  1606. { 0x06, 0x00ee },
  1607. { 0x06, 0x8349 },
  1608. { 0x06, 0x00e0 },
  1609. { 0x06, 0x8351 },
  1610. { 0x06, 0x10e4 },
  1611. { 0x06, 0x8351 },
  1612. { 0x06, 0x5801 },
  1613. { 0x06, 0x9fea },
  1614. { 0x06, 0xd000 },
  1615. { 0x06, 0xd180 },
  1616. { 0x06, 0x1f66 },
  1617. { 0x06, 0xe2f8 },
  1618. { 0x06, 0xeae3 },
  1619. { 0x06, 0xf8eb },
  1620. { 0x06, 0x5af8 },
  1621. { 0x06, 0x1e20 },
  1622. { 0x06, 0xe6f8 },
  1623. { 0x06, 0xeae5 },
  1624. { 0x06, 0xf8eb },
  1625. { 0x06, 0xd302 },
  1626. { 0x06, 0xb3fe },
  1627. { 0x06, 0xe2f8 },
  1628. { 0x06, 0x7cef },
  1629. { 0x06, 0x325b },
  1630. { 0x06, 0x80e3 },
  1631. { 0x06, 0xf87d },
  1632. { 0x06, 0x9e03 },
  1633. { 0x06, 0x7dff },
  1634. { 0x06, 0xff0d },
  1635. { 0x06, 0x581c },
  1636. { 0x06, 0x551a },
  1637. { 0x06, 0x6511 },
  1638. { 0x06, 0xa190 },
  1639. { 0x06, 0xd3e2 },
  1640. { 0x06, 0x8348 },
  1641. { 0x06, 0xe383 },
  1642. { 0x06, 0x491b },
  1643. { 0x06, 0x56ab },
  1644. { 0x06, 0x08ef },
  1645. { 0x06, 0x56e6 },
  1646. { 0x06, 0x8348 },
  1647. { 0x06, 0xe783 },
  1648. { 0x06, 0x4910 },
  1649. { 0x06, 0xd180 },
  1650. { 0x06, 0x1f66 },
  1651. { 0x06, 0xa004 },
  1652. { 0x06, 0xb9e2 },
  1653. { 0x06, 0x8348 },
  1654. { 0x06, 0xe383 },
  1655. { 0x06, 0x49ef },
  1656. { 0x06, 0x65e2 },
  1657. { 0x06, 0x834a },
  1658. { 0x06, 0xe383 },
  1659. { 0x06, 0x4b1b },
  1660. { 0x06, 0x56aa },
  1661. { 0x06, 0x0eef },
  1662. { 0x06, 0x56e6 },
  1663. { 0x06, 0x834a },
  1664. { 0x06, 0xe783 },
  1665. { 0x06, 0x4be2 },
  1666. { 0x06, 0x834d },
  1667. { 0x06, 0xe683 },
  1668. { 0x06, 0x4ce0 },
  1669. { 0x06, 0x834d },
  1670. { 0x06, 0xa000 },
  1671. { 0x06, 0x0caf },
  1672. { 0x06, 0x81dc },
  1673. { 0x06, 0xe083 },
  1674. { 0x06, 0x4d10 },
  1675. { 0x06, 0xe483 },
  1676. { 0x06, 0x4dae },
  1677. { 0x06, 0x0480 },
  1678. { 0x06, 0xe483 },
  1679. { 0x06, 0x4de0 },
  1680. { 0x06, 0x834e },
  1681. { 0x06, 0x7803 },
  1682. { 0x06, 0x9e0b },
  1683. { 0x06, 0xe083 },
  1684. { 0x06, 0x4e78 },
  1685. { 0x06, 0x049e },
  1686. { 0x06, 0x04ee },
  1687. { 0x06, 0x834e },
  1688. { 0x06, 0x02e0 },
  1689. { 0x06, 0x8332 },
  1690. { 0x06, 0xe183 },
  1691. { 0x06, 0x3359 },
  1692. { 0x06, 0x0fe2 },
  1693. { 0x06, 0x834d },
  1694. { 0x06, 0x0c24 },
  1695. { 0x06, 0x5af0 },
  1696. { 0x06, 0x1e12 },
  1697. { 0x06, 0xe4f8 },
  1698. { 0x06, 0x8ce5 },
  1699. { 0x06, 0xf88d },
  1700. { 0x06, 0xe083 },
  1701. { 0x06, 0x30e1 },
  1702. { 0x06, 0x8331 },
  1703. { 0x06, 0x6801 },
  1704. { 0x06, 0xe4f8 },
  1705. { 0x06, 0x8ae5 },
  1706. { 0x06, 0xf88b },
  1707. { 0x06, 0xae37 },
  1708. { 0x06, 0xee83 },
  1709. { 0x06, 0x4e03 },
  1710. { 0x06, 0xe083 },
  1711. { 0x06, 0x4ce1 },
  1712. { 0x06, 0x834d },
  1713. { 0x06, 0x1b01 },
  1714. { 0x06, 0x9e04 },
  1715. { 0x06, 0xaaa1 },
  1716. { 0x06, 0xaea8 },
  1717. { 0x06, 0xee83 },
  1718. { 0x06, 0x4e04 },
  1719. { 0x06, 0xee83 },
  1720. { 0x06, 0x4f00 },
  1721. { 0x06, 0xaeab },
  1722. { 0x06, 0xe083 },
  1723. { 0x06, 0x4f78 },
  1724. { 0x06, 0x039f },
  1725. { 0x06, 0x14ee },
  1726. { 0x06, 0x834e },
  1727. { 0x06, 0x05d2 },
  1728. { 0x06, 0x40d6 },
  1729. { 0x06, 0x5554 },
  1730. { 0x06, 0x0282 },
  1731. { 0x06, 0x17d2 },
  1732. { 0x06, 0xa0d6 },
  1733. { 0x06, 0xba00 },
  1734. { 0x06, 0x0282 },
  1735. { 0x06, 0x17fe },
  1736. { 0x06, 0xfdfc },
  1737. { 0x06, 0x05f8 },
  1738. { 0x06, 0xe0f8 },
  1739. { 0x06, 0x60e1 },
  1740. { 0x06, 0xf861 },
  1741. { 0x06, 0x6802 },
  1742. { 0x06, 0xe4f8 },
  1743. { 0x06, 0x60e5 },
  1744. { 0x06, 0xf861 },
  1745. { 0x06, 0xe0f8 },
  1746. { 0x06, 0x48e1 },
  1747. { 0x06, 0xf849 },
  1748. { 0x06, 0x580f },
  1749. { 0x06, 0x1e02 },
  1750. { 0x06, 0xe4f8 },
  1751. { 0x06, 0x48e5 },
  1752. { 0x06, 0xf849 },
  1753. { 0x06, 0xd000 },
  1754. { 0x06, 0x0282 },
  1755. { 0x06, 0x5bbf },
  1756. { 0x06, 0x8350 },
  1757. { 0x06, 0xef46 },
  1758. { 0x06, 0xdc19 },
  1759. { 0x06, 0xddd0 },
  1760. { 0x06, 0x0102 },
  1761. { 0x06, 0x825b },
  1762. { 0x06, 0x0282 },
  1763. { 0x06, 0x77e0 },
  1764. { 0x06, 0xf860 },
  1765. { 0x06, 0xe1f8 },
  1766. { 0x06, 0x6158 },
  1767. { 0x06, 0xfde4 },
  1768. { 0x06, 0xf860 },
  1769. { 0x06, 0xe5f8 },
  1770. { 0x06, 0x61fc },
  1771. { 0x06, 0x04f9 },
  1772. { 0x06, 0xfafb },
  1773. { 0x06, 0xc6bf },
  1774. { 0x06, 0xf840 },
  1775. { 0x06, 0xbe83 },
  1776. { 0x06, 0x50a0 },
  1777. { 0x06, 0x0101 },
  1778. { 0x06, 0x071b },
  1779. { 0x06, 0x89cf },
  1780. { 0x06, 0xd208 },
  1781. { 0x06, 0xebdb },
  1782. { 0x06, 0x19b2 },
  1783. { 0x06, 0xfbff },
  1784. { 0x06, 0xfefd },
  1785. { 0x06, 0x04f8 },
  1786. { 0x06, 0xe0f8 },
  1787. { 0x06, 0x48e1 },
  1788. { 0x06, 0xf849 },
  1789. { 0x06, 0x6808 },
  1790. { 0x06, 0xe4f8 },
  1791. { 0x06, 0x48e5 },
  1792. { 0x06, 0xf849 },
  1793. { 0x06, 0x58f7 },
  1794. { 0x06, 0xe4f8 },
  1795. { 0x06, 0x48e5 },
  1796. { 0x06, 0xf849 },
  1797. { 0x06, 0xfc04 },
  1798. { 0x06, 0x4d20 },
  1799. { 0x06, 0x0002 },
  1800. { 0x06, 0x4e22 },
  1801. { 0x06, 0x0002 },
  1802. { 0x06, 0x4ddf },
  1803. { 0x06, 0xff01 },
  1804. { 0x06, 0x4edd },
  1805. { 0x06, 0xff01 },
  1806. { 0x05, 0x83d4 },
  1807. { 0x06, 0x8000 },
  1808. { 0x05, 0x83d8 },
  1809. { 0x06, 0x8051 },
  1810. { 0x02, 0x6010 },
  1811. { 0x03, 0xdc00 },
  1812. { 0x05, 0xfff6 },
  1813. { 0x06, 0x00fc },
  1814. { 0x1f, 0x0000 },
  1815. { 0x1f, 0x0000 },
  1816. { 0x0d, 0xf880 },
  1817. { 0x1f, 0x0000 }
  1818. };
  1819. rtl_phy_write(ioaddr, phy_reg_init_0, ARRAY_SIZE(phy_reg_init_0));
  1820. mdio_write(ioaddr, 0x1f, 0x0002);
  1821. mdio_plus_minus(ioaddr, 0x0b, 0x0010, 0x00ef);
  1822. mdio_plus_minus(ioaddr, 0x0c, 0xa200, 0x5d00);
  1823. rtl_phy_write(ioaddr, phy_reg_init_1, ARRAY_SIZE(phy_reg_init_1));
  1824. if (rtl8168d_efuse_read(ioaddr, 0x01) == 0xb1) {
  1825. static const struct phy_reg phy_reg_init[] = {
  1826. { 0x1f, 0x0002 },
  1827. { 0x05, 0x669a },
  1828. { 0x1f, 0x0005 },
  1829. { 0x05, 0x8330 },
  1830. { 0x06, 0x669a },
  1831. { 0x1f, 0x0002 }
  1832. };
  1833. int val;
  1834. rtl_phy_write(ioaddr, phy_reg_init, ARRAY_SIZE(phy_reg_init));
  1835. val = mdio_read(ioaddr, 0x0d);
  1836. if ((val & 0x00ff) != 0x006c) {
  1837. static const u32 set[] = {
  1838. 0x0065, 0x0066, 0x0067, 0x0068,
  1839. 0x0069, 0x006a, 0x006b, 0x006c
  1840. };
  1841. int i;
  1842. mdio_write(ioaddr, 0x1f, 0x0002);
  1843. val &= 0xff00;
  1844. for (i = 0; i < ARRAY_SIZE(set); i++)
  1845. mdio_write(ioaddr, 0x0d, val | set[i]);
  1846. }
  1847. } else {
  1848. static const struct phy_reg phy_reg_init[] = {
  1849. { 0x1f, 0x0002 },
  1850. { 0x05, 0x6662 },
  1851. { 0x1f, 0x0005 },
  1852. { 0x05, 0x8330 },
  1853. { 0x06, 0x6662 }
  1854. };
  1855. rtl_phy_write(ioaddr, phy_reg_init, ARRAY_SIZE(phy_reg_init));
  1856. }
  1857. mdio_write(ioaddr, 0x1f, 0x0002);
  1858. mdio_patch(ioaddr, 0x0d, 0x0300);
  1859. mdio_patch(ioaddr, 0x0f, 0x0010);
  1860. mdio_write(ioaddr, 0x1f, 0x0002);
  1861. mdio_plus_minus(ioaddr, 0x02, 0x0100, 0x0600);
  1862. mdio_plus_minus(ioaddr, 0x03, 0x0000, 0xe000);
  1863. rtl_phy_write(ioaddr, phy_reg_init_2, ARRAY_SIZE(phy_reg_init_2));
  1864. }
  1865. static void rtl8168d_2_hw_phy_config(void __iomem *ioaddr)
  1866. {
  1867. static const struct phy_reg phy_reg_init_0[] = {
  1868. { 0x1f, 0x0001 },
  1869. { 0x06, 0x4064 },
  1870. { 0x07, 0x2863 },
  1871. { 0x08, 0x059c },
  1872. { 0x09, 0x26b4 },
  1873. { 0x0a, 0x6a19 },
  1874. { 0x0b, 0xdcc8 },
  1875. { 0x10, 0xf06d },
  1876. { 0x14, 0x7f68 },
  1877. { 0x18, 0x7fd9 },
  1878. { 0x1c, 0xf0ff },
  1879. { 0x1d, 0x3d9c },
  1880. { 0x1f, 0x0003 },
  1881. { 0x12, 0xf49f },
  1882. { 0x13, 0x070b },
  1883. { 0x1a, 0x05ad },
  1884. { 0x14, 0x94c0 },
  1885. { 0x1f, 0x0002 },
  1886. { 0x06, 0x5561 },
  1887. { 0x1f, 0x0005 },
  1888. { 0x05, 0x8332 },
  1889. { 0x06, 0x5561 }
  1890. };
  1891. static const struct phy_reg phy_reg_init_1[] = {
  1892. { 0x1f, 0x0005 },
  1893. { 0x05, 0xffc2 },
  1894. { 0x1f, 0x0005 },
  1895. { 0x05, 0x8000 },
  1896. { 0x06, 0xf8f9 },
  1897. { 0x06, 0xfaee },
  1898. { 0x06, 0xf8ea },
  1899. { 0x06, 0x00ee },
  1900. { 0x06, 0xf8eb },
  1901. { 0x06, 0x00e2 },
  1902. { 0x06, 0xf87c },
  1903. { 0x06, 0xe3f8 },
  1904. { 0x06, 0x7da5 },
  1905. { 0x06, 0x1111 },
  1906. { 0x06, 0x12d2 },
  1907. { 0x06, 0x40d6 },
  1908. { 0x06, 0x4444 },
  1909. { 0x06, 0x0281 },
  1910. { 0x06, 0xc6d2 },
  1911. { 0x06, 0xa0d6 },
  1912. { 0x06, 0xaaaa },
  1913. { 0x06, 0x0281 },
  1914. { 0x06, 0xc6ae },
  1915. { 0x06, 0x0fa5 },
  1916. { 0x06, 0x4444 },
  1917. { 0x06, 0x02ae },
  1918. { 0x06, 0x4da5 },
  1919. { 0x06, 0xaaaa },
  1920. { 0x06, 0x02ae },
  1921. { 0x06, 0x47af },
  1922. { 0x06, 0x81c2 },
  1923. { 0x06, 0xee83 },
  1924. { 0x06, 0x4e00 },
  1925. { 0x06, 0xee83 },
  1926. { 0x06, 0x4d0f },
  1927. { 0x06, 0xee83 },
  1928. { 0x06, 0x4c0f },
  1929. { 0x06, 0xee83 },
  1930. { 0x06, 0x4f00 },
  1931. { 0x06, 0xee83 },
  1932. { 0x06, 0x5100 },
  1933. { 0x06, 0xee83 },
  1934. { 0x06, 0x4aff },
  1935. { 0x06, 0xee83 },
  1936. { 0x06, 0x4bff },
  1937. { 0x06, 0xe083 },
  1938. { 0x06, 0x30e1 },
  1939. { 0x06, 0x8331 },
  1940. { 0x06, 0x58fe },
  1941. { 0x06, 0xe4f8 },
  1942. { 0x06, 0x8ae5 },
  1943. { 0x06, 0xf88b },
  1944. { 0x06, 0xe083 },
  1945. { 0x06, 0x32e1 },
  1946. { 0x06, 0x8333 },
  1947. { 0x06, 0x590f },
  1948. { 0x06, 0xe283 },
  1949. { 0x06, 0x4d0c },
  1950. { 0x06, 0x245a },
  1951. { 0x06, 0xf01e },
  1952. { 0x06, 0x12e4 },
  1953. { 0x06, 0xf88c },
  1954. { 0x06, 0xe5f8 },
  1955. { 0x06, 0x8daf },
  1956. { 0x06, 0x81c2 },
  1957. { 0x06, 0xe083 },
  1958. { 0x06, 0x4f10 },
  1959. { 0x06, 0xe483 },
  1960. { 0x06, 0x4fe0 },
  1961. { 0x06, 0x834e },
  1962. { 0x06, 0x7800 },
  1963. { 0x06, 0x9f0a },
  1964. { 0x06, 0xe083 },
  1965. { 0x06, 0x4fa0 },
  1966. { 0x06, 0x10a5 },
  1967. { 0x06, 0xee83 },
  1968. { 0x06, 0x4e01 },
  1969. { 0x06, 0xe083 },
  1970. { 0x06, 0x4e78 },
  1971. { 0x06, 0x059e },
  1972. { 0x06, 0x9ae0 },
  1973. { 0x06, 0x834e },
  1974. { 0x06, 0x7804 },
  1975. { 0x06, 0x9e10 },
  1976. { 0x06, 0xe083 },
  1977. { 0x06, 0x4e78 },
  1978. { 0x06, 0x039e },
  1979. { 0x06, 0x0fe0 },
  1980. { 0x06, 0x834e },
  1981. { 0x06, 0x7801 },
  1982. { 0x06, 0x9e05 },
  1983. { 0x06, 0xae0c },
  1984. { 0x06, 0xaf81 },
  1985. { 0x06, 0xa7af },
  1986. { 0x06, 0x8152 },
  1987. { 0x06, 0xaf81 },
  1988. { 0x06, 0x8baf },
  1989. { 0x06, 0x81c2 },
  1990. { 0x06, 0xee83 },
  1991. { 0x06, 0x4800 },
  1992. { 0x06, 0xee83 },
  1993. { 0x06, 0x4900 },
  1994. { 0x06, 0xe083 },
  1995. { 0x06, 0x5110 },
  1996. { 0x06, 0xe483 },
  1997. { 0x06, 0x5158 },
  1998. { 0x06, 0x019f },
  1999. { 0x06, 0xead0 },
  2000. { 0x06, 0x00d1 },
  2001. { 0x06, 0x801f },
  2002. { 0x06, 0x66e2 },
  2003. { 0x06, 0xf8ea },
  2004. { 0x06, 0xe3f8 },
  2005. { 0x06, 0xeb5a },
  2006. { 0x06, 0xf81e },
  2007. { 0x06, 0x20e6 },
  2008. { 0x06, 0xf8ea },
  2009. { 0x06, 0xe5f8 },
  2010. { 0x06, 0xebd3 },
  2011. { 0x06, 0x02b3 },
  2012. { 0x06, 0xfee2 },
  2013. { 0x06, 0xf87c },
  2014. { 0x06, 0xef32 },
  2015. { 0x06, 0x5b80 },
  2016. { 0x06, 0xe3f8 },
  2017. { 0x06, 0x7d9e },
  2018. { 0x06, 0x037d },
  2019. { 0x06, 0xffff },
  2020. { 0x06, 0x0d58 },
  2021. { 0x06, 0x1c55 },
  2022. { 0x06, 0x1a65 },
  2023. { 0x06, 0x11a1 },
  2024. { 0x06, 0x90d3 },
  2025. { 0x06, 0xe283 },
  2026. { 0x06, 0x48e3 },
  2027. { 0x06, 0x8349 },
  2028. { 0x06, 0x1b56 },
  2029. { 0x06, 0xab08 },
  2030. { 0x06, 0xef56 },
  2031. { 0x06, 0xe683 },
  2032. { 0x06, 0x48e7 },
  2033. { 0x06, 0x8349 },
  2034. { 0x06, 0x10d1 },
  2035. { 0x06, 0x801f },
  2036. { 0x06, 0x66a0 },
  2037. { 0x06, 0x04b9 },
  2038. { 0x06, 0xe283 },
  2039. { 0x06, 0x48e3 },
  2040. { 0x06, 0x8349 },
  2041. { 0x06, 0xef65 },
  2042. { 0x06, 0xe283 },
  2043. { 0x06, 0x4ae3 },
  2044. { 0x06, 0x834b },
  2045. { 0x06, 0x1b56 },
  2046. { 0x06, 0xaa0e },
  2047. { 0x06, 0xef56 },
  2048. { 0x06, 0xe683 },
  2049. { 0x06, 0x4ae7 },
  2050. { 0x06, 0x834b },
  2051. { 0x06, 0xe283 },
  2052. { 0x06, 0x4de6 },
  2053. { 0x06, 0x834c },
  2054. { 0x06, 0xe083 },
  2055. { 0x06, 0x4da0 },
  2056. { 0x06, 0x000c },
  2057. { 0x06, 0xaf81 },
  2058. { 0x06, 0x8be0 },
  2059. { 0x06, 0x834d },
  2060. { 0x06, 0x10e4 },
  2061. { 0x06, 0x834d },
  2062. { 0x06, 0xae04 },
  2063. { 0x06, 0x80e4 },
  2064. { 0x06, 0x834d },
  2065. { 0x06, 0xe083 },
  2066. { 0x06, 0x4e78 },
  2067. { 0x06, 0x039e },
  2068. { 0x06, 0x0be0 },
  2069. { 0x06, 0x834e },
  2070. { 0x06, 0x7804 },
  2071. { 0x06, 0x9e04 },
  2072. { 0x06, 0xee83 },
  2073. { 0x06, 0x4e02 },
  2074. { 0x06, 0xe083 },
  2075. { 0x06, 0x32e1 },
  2076. { 0x06, 0x8333 },
  2077. { 0x06, 0x590f },
  2078. { 0x06, 0xe283 },
  2079. { 0x06, 0x4d0c },
  2080. { 0x06, 0x245a },
  2081. { 0x06, 0xf01e },
  2082. { 0x06, 0x12e4 },
  2083. { 0x06, 0xf88c },
  2084. { 0x06, 0xe5f8 },
  2085. { 0x06, 0x8de0 },
  2086. { 0x06, 0x8330 },
  2087. { 0x06, 0xe183 },
  2088. { 0x06, 0x3168 },
  2089. { 0x06, 0x01e4 },
  2090. { 0x06, 0xf88a },
  2091. { 0x06, 0xe5f8 },
  2092. { 0x06, 0x8bae },
  2093. { 0x06, 0x37ee },
  2094. { 0x06, 0x834e },
  2095. { 0x06, 0x03e0 },
  2096. { 0x06, 0x834c },
  2097. { 0x06, 0xe183 },
  2098. { 0x06, 0x4d1b },
  2099. { 0x06, 0x019e },
  2100. { 0x06, 0x04aa },
  2101. { 0x06, 0xa1ae },
  2102. { 0x06, 0xa8ee },
  2103. { 0x06, 0x834e },
  2104. { 0x06, 0x04ee },
  2105. { 0x06, 0x834f },
  2106. { 0x06, 0x00ae },
  2107. { 0x06, 0xabe0 },
  2108. { 0x06, 0x834f },
  2109. { 0x06, 0x7803 },
  2110. { 0x06, 0x9f14 },
  2111. { 0x06, 0xee83 },
  2112. { 0x06, 0x4e05 },
  2113. { 0x06, 0xd240 },
  2114. { 0x06, 0xd655 },
  2115. { 0x06, 0x5402 },
  2116. { 0x06, 0x81c6 },
  2117. { 0x06, 0xd2a0 },
  2118. { 0x06, 0xd6ba },
  2119. { 0x06, 0x0002 },
  2120. { 0x06, 0x81c6 },
  2121. { 0x06, 0xfefd },
  2122. { 0x06, 0xfc05 },
  2123. { 0x06, 0xf8e0 },
  2124. { 0x06, 0xf860 },
  2125. { 0x06, 0xe1f8 },
  2126. { 0x06, 0x6168 },
  2127. { 0x06, 0x02e4 },
  2128. { 0x06, 0xf860 },
  2129. { 0x06, 0xe5f8 },
  2130. { 0x06, 0x61e0 },
  2131. { 0x06, 0xf848 },
  2132. { 0x06, 0xe1f8 },
  2133. { 0x06, 0x4958 },
  2134. { 0x06, 0x0f1e },
  2135. { 0x06, 0x02e4 },
  2136. { 0x06, 0xf848 },
  2137. { 0x06, 0xe5f8 },
  2138. { 0x06, 0x49d0 },
  2139. { 0x06, 0x0002 },
  2140. { 0x06, 0x820a },
  2141. { 0x06, 0xbf83 },
  2142. { 0x06, 0x50ef },
  2143. { 0x06, 0x46dc },
  2144. { 0x06, 0x19dd },
  2145. { 0x06, 0xd001 },
  2146. { 0x06, 0x0282 },
  2147. { 0x06, 0x0a02 },
  2148. { 0x06, 0x8226 },
  2149. { 0x06, 0xe0f8 },
  2150. { 0x06, 0x60e1 },
  2151. { 0x06, 0xf861 },
  2152. { 0x06, 0x58fd },
  2153. { 0x06, 0xe4f8 },
  2154. { 0x06, 0x60e5 },
  2155. { 0x06, 0xf861 },
  2156. { 0x06, 0xfc04 },
  2157. { 0x06, 0xf9fa },
  2158. { 0x06, 0xfbc6 },
  2159. { 0x06, 0xbff8 },
  2160. { 0x06, 0x40be },
  2161. { 0x06, 0x8350 },
  2162. { 0x06, 0xa001 },
  2163. { 0x06, 0x0107 },
  2164. { 0x06, 0x1b89 },
  2165. { 0x06, 0xcfd2 },
  2166. { 0x06, 0x08eb },
  2167. { 0x06, 0xdb19 },
  2168. { 0x06, 0xb2fb },
  2169. { 0x06, 0xfffe },
  2170. { 0x06, 0xfd04 },
  2171. { 0x06, 0xf8e0 },
  2172. { 0x06, 0xf848 },
  2173. { 0x06, 0xe1f8 },
  2174. { 0x06, 0x4968 },
  2175. { 0x06, 0x08e4 },
  2176. { 0x06, 0xf848 },
  2177. { 0x06, 0xe5f8 },
  2178. { 0x06, 0x4958 },
  2179. { 0x06, 0xf7e4 },
  2180. { 0x06, 0xf848 },
  2181. { 0x06, 0xe5f8 },
  2182. { 0x06, 0x49fc },
  2183. { 0x06, 0x044d },
  2184. { 0x06, 0x2000 },
  2185. { 0x06, 0x024e },
  2186. { 0x06, 0x2200 },
  2187. { 0x06, 0x024d },
  2188. { 0x06, 0xdfff },
  2189. { 0x06, 0x014e },
  2190. { 0x06, 0xddff },
  2191. { 0x06, 0x0100 },
  2192. { 0x05, 0x83d8 },
  2193. { 0x06, 0x8000 },
  2194. { 0x03, 0xdc00 },
  2195. { 0x05, 0xfff6 },
  2196. { 0x06, 0x00fc },
  2197. { 0x1f, 0x0000 },
  2198. { 0x1f, 0x0000 },
  2199. { 0x0d, 0xf880 },
  2200. { 0x1f, 0x0000 }
  2201. };
  2202. rtl_phy_write(ioaddr, phy_reg_init_0, ARRAY_SIZE(phy_reg_init_0));
  2203. if (rtl8168d_efuse_read(ioaddr, 0x01) == 0xb1) {
  2204. static const struct phy_reg phy_reg_init[] = {
  2205. { 0x1f, 0x0002 },
  2206. { 0x05, 0x669a },
  2207. { 0x1f, 0x0005 },
  2208. { 0x05, 0x8330 },
  2209. { 0x06, 0x669a },
  2210. { 0x1f, 0x0002 }
  2211. };
  2212. int val;
  2213. rtl_phy_write(ioaddr, phy_reg_init, ARRAY_SIZE(phy_reg_init));
  2214. val = mdio_read(ioaddr, 0x0d);
  2215. if ((val & 0x00ff) != 0x006c) {
  2216. u32 set[] = {
  2217. 0x0065, 0x0066, 0x0067, 0x0068,
  2218. 0x0069, 0x006a, 0x006b, 0x006c
  2219. };
  2220. int i;
  2221. mdio_write(ioaddr, 0x1f, 0x0002);
  2222. val &= 0xff00;
  2223. for (i = 0; i < ARRAY_SIZE(set); i++)
  2224. mdio_write(ioaddr, 0x0d, val | set[i]);
  2225. }
  2226. } else {
  2227. static const struct phy_reg phy_reg_init[] = {
  2228. { 0x1f, 0x0002 },
  2229. { 0x05, 0x2642 },
  2230. { 0x1f, 0x0005 },
  2231. { 0x05, 0x8330 },
  2232. { 0x06, 0x2642 }
  2233. };
  2234. rtl_phy_write(ioaddr, phy_reg_init, ARRAY_SIZE(phy_reg_init));
  2235. }
  2236. mdio_write(ioaddr, 0x1f, 0x0002);
  2237. mdio_plus_minus(ioaddr, 0x02, 0x0100, 0x0600);
  2238. mdio_plus_minus(ioaddr, 0x03, 0x0000, 0xe000);
  2239. mdio_write(ioaddr, 0x1f, 0x0001);
  2240. mdio_write(ioaddr, 0x17, 0x0cc0);
  2241. mdio_write(ioaddr, 0x1f, 0x0002);
  2242. mdio_patch(ioaddr, 0x0f, 0x0017);
  2243. rtl_phy_write(ioaddr, phy_reg_init_1, ARRAY_SIZE(phy_reg_init_1));
  2244. }
  2245. static void rtl8168d_3_hw_phy_config(void __iomem *ioaddr)
  2246. {
  2247. static const struct phy_reg phy_reg_init[] = {
  2248. { 0x1f, 0x0002 },
  2249. { 0x10, 0x0008 },
  2250. { 0x0d, 0x006c },
  2251. { 0x1f, 0x0000 },
  2252. { 0x0d, 0xf880 },
  2253. { 0x1f, 0x0001 },
  2254. { 0x17, 0x0cc0 },
  2255. { 0x1f, 0x0001 },
  2256. { 0x0b, 0xa4d8 },
  2257. { 0x09, 0x281c },
  2258. { 0x07, 0x2883 },
  2259. { 0x0a, 0x6b35 },
  2260. { 0x1d, 0x3da4 },
  2261. { 0x1c, 0xeffd },
  2262. { 0x14, 0x7f52 },
  2263. { 0x18, 0x7fc6 },
  2264. { 0x08, 0x0601 },
  2265. { 0x06, 0x4063 },
  2266. { 0x10, 0xf074 },
  2267. { 0x1f, 0x0003 },
  2268. { 0x13, 0x0789 },
  2269. { 0x12, 0xf4bd },
  2270. { 0x1a, 0x04fd },
  2271. { 0x14, 0x84b0 },
  2272. { 0x1f, 0x0000 },
  2273. { 0x00, 0x9200 },
  2274. { 0x1f, 0x0005 },
  2275. { 0x01, 0x0340 },
  2276. { 0x1f, 0x0001 },
  2277. { 0x04, 0x4000 },
  2278. { 0x03, 0x1d21 },
  2279. { 0x02, 0x0c32 },
  2280. { 0x01, 0x0200 },
  2281. { 0x00, 0x5554 },
  2282. { 0x04, 0x4800 },
  2283. { 0x04, 0x4000 },
  2284. { 0x04, 0xf000 },
  2285. { 0x03, 0xdf01 },
  2286. { 0x02, 0xdf20 },
  2287. { 0x01, 0x101a },
  2288. { 0x00, 0xa0ff },
  2289. { 0x04, 0xf800 },
  2290. { 0x04, 0xf000 },
  2291. { 0x1f, 0x0000 },
  2292. { 0x1f, 0x0007 },
  2293. { 0x1e, 0x0023 },
  2294. { 0x16, 0x0000 },
  2295. { 0x1f, 0x0000 }
  2296. };
  2297. rtl_phy_write(ioaddr, phy_reg_init, ARRAY_SIZE(phy_reg_init));
  2298. }
  2299. static void rtl8102e_hw_phy_config(void __iomem *ioaddr)
  2300. {
  2301. static const struct phy_reg phy_reg_init[] = {
  2302. { 0x1f, 0x0003 },
  2303. { 0x08, 0x441d },
  2304. { 0x01, 0x9100 },
  2305. { 0x1f, 0x0000 }
  2306. };
  2307. mdio_write(ioaddr, 0x1f, 0x0000);
  2308. mdio_patch(ioaddr, 0x11, 1 << 12);
  2309. mdio_patch(ioaddr, 0x19, 1 << 13);
  2310. mdio_patch(ioaddr, 0x10, 1 << 15);
  2311. rtl_phy_write(ioaddr, phy_reg_init, ARRAY_SIZE(phy_reg_init));
  2312. }
  2313. static void rtl_hw_phy_config(struct net_device *dev)
  2314. {
  2315. struct rtl8169_private *tp = netdev_priv(dev);
  2316. void __iomem *ioaddr = tp->mmio_addr;
  2317. rtl8169_print_mac_version(tp);
  2318. switch (tp->mac_version) {
  2319. case RTL_GIGA_MAC_VER_01:
  2320. break;
  2321. case RTL_GIGA_MAC_VER_02:
  2322. case RTL_GIGA_MAC_VER_03:
  2323. rtl8169s_hw_phy_config(ioaddr);
  2324. break;
  2325. case RTL_GIGA_MAC_VER_04:
  2326. rtl8169sb_hw_phy_config(ioaddr);
  2327. break;
  2328. case RTL_GIGA_MAC_VER_05:
  2329. rtl8169scd_hw_phy_config(tp, ioaddr);
  2330. break;
  2331. case RTL_GIGA_MAC_VER_06:
  2332. rtl8169sce_hw_phy_config(ioaddr);
  2333. break;
  2334. case RTL_GIGA_MAC_VER_07:
  2335. case RTL_GIGA_MAC_VER_08:
  2336. case RTL_GIGA_MAC_VER_09:
  2337. rtl8102e_hw_phy_config(ioaddr);
  2338. break;
  2339. case RTL_GIGA_MAC_VER_11:
  2340. rtl8168bb_hw_phy_config(ioaddr);
  2341. break;
  2342. case RTL_GIGA_MAC_VER_12:
  2343. rtl8168bef_hw_phy_config(ioaddr);
  2344. break;
  2345. case RTL_GIGA_MAC_VER_17:
  2346. rtl8168bef_hw_phy_config(ioaddr);
  2347. break;
  2348. case RTL_GIGA_MAC_VER_18:
  2349. rtl8168cp_1_hw_phy_config(ioaddr);
  2350. break;
  2351. case RTL_GIGA_MAC_VER_19:
  2352. rtl8168c_1_hw_phy_config(ioaddr);
  2353. break;
  2354. case RTL_GIGA_MAC_VER_20:
  2355. rtl8168c_2_hw_phy_config(ioaddr);
  2356. break;
  2357. case RTL_GIGA_MAC_VER_21:
  2358. rtl8168c_3_hw_phy_config(ioaddr);
  2359. break;
  2360. case RTL_GIGA_MAC_VER_22:
  2361. rtl8168c_4_hw_phy_config(ioaddr);
  2362. break;
  2363. case RTL_GIGA_MAC_VER_23:
  2364. case RTL_GIGA_MAC_VER_24:
  2365. rtl8168cp_2_hw_phy_config(ioaddr);
  2366. break;
  2367. case RTL_GIGA_MAC_VER_25:
  2368. rtl8168d_1_hw_phy_config(ioaddr);
  2369. break;
  2370. case RTL_GIGA_MAC_VER_26:
  2371. rtl8168d_2_hw_phy_config(ioaddr);
  2372. break;
  2373. case RTL_GIGA_MAC_VER_27:
  2374. rtl8168d_3_hw_phy_config(ioaddr);
  2375. break;
  2376. default:
  2377. break;
  2378. }
  2379. }
  2380. static void rtl8169_phy_timer(unsigned long __opaque)
  2381. {
  2382. struct net_device *dev = (struct net_device *)__opaque;
  2383. struct rtl8169_private *tp = netdev_priv(dev);
  2384. struct timer_list *timer = &tp->timer;
  2385. void __iomem *ioaddr = tp->mmio_addr;
  2386. unsigned long timeout = RTL8169_PHY_TIMEOUT;
  2387. assert(tp->mac_version > RTL_GIGA_MAC_VER_01);
  2388. if (!(tp->phy_1000_ctrl_reg & ADVERTISE_1000FULL))
  2389. return;
  2390. spin_lock_irq(&tp->lock);
  2391. if (tp->phy_reset_pending(ioaddr)) {
  2392. /*
  2393. * A busy loop could burn quite a few cycles on nowadays CPU.
  2394. * Let's delay the execution of the timer for a few ticks.
  2395. */
  2396. timeout = HZ/10;
  2397. goto out_mod_timer;
  2398. }
  2399. if (tp->link_ok(ioaddr))
  2400. goto out_unlock;
  2401. netif_warn(tp, link, dev, "PHY reset until link up\n");
  2402. tp->phy_reset_enable(ioaddr);
  2403. out_mod_timer:
  2404. mod_timer(timer, jiffies + timeout);
  2405. out_unlock:
  2406. spin_unlock_irq(&tp->lock);
  2407. }
  2408. static inline void rtl8169_delete_timer(struct net_device *dev)
  2409. {
  2410. struct rtl8169_private *tp = netdev_priv(dev);
  2411. struct timer_list *timer = &tp->timer;
  2412. if (tp->mac_version <= RTL_GIGA_MAC_VER_01)
  2413. return;
  2414. del_timer_sync(timer);
  2415. }
  2416. static inline void rtl8169_request_timer(struct net_device *dev)
  2417. {
  2418. struct rtl8169_private *tp = netdev_priv(dev);
  2419. struct timer_list *timer = &tp->timer;
  2420. if (tp->mac_version <= RTL_GIGA_MAC_VER_01)
  2421. return;
  2422. mod_timer(timer, jiffies + RTL8169_PHY_TIMEOUT);
  2423. }
  2424. #ifdef CONFIG_NET_POLL_CONTROLLER
  2425. /*
  2426. * Polling 'interrupt' - used by things like netconsole to send skbs
  2427. * without having to re-enable interrupts. It's not called while
  2428. * the interrupt routine is executing.
  2429. */
  2430. static void rtl8169_netpoll(struct net_device *dev)
  2431. {
  2432. struct rtl8169_private *tp = netdev_priv(dev);
  2433. struct pci_dev *pdev = tp->pci_dev;
  2434. disable_irq(pdev->irq);
  2435. rtl8169_interrupt(pdev->irq, dev);
  2436. enable_irq(pdev->irq);
  2437. }
  2438. #endif
  2439. static void rtl8169_release_board(struct pci_dev *pdev, struct net_device *dev,
  2440. void __iomem *ioaddr)
  2441. {
  2442. iounmap(ioaddr);
  2443. pci_release_regions(pdev);
  2444. pci_disable_device(pdev);
  2445. free_netdev(dev);
  2446. }
  2447. static void rtl8169_phy_reset(struct net_device *dev,
  2448. struct rtl8169_private *tp)
  2449. {
  2450. void __iomem *ioaddr = tp->mmio_addr;
  2451. unsigned int i;
  2452. tp->phy_reset_enable(ioaddr);
  2453. for (i = 0; i < 100; i++) {
  2454. if (!tp->phy_reset_pending(ioaddr))
  2455. return;
  2456. msleep(1);
  2457. }
  2458. netif_err(tp, link, dev, "PHY reset failed\n");
  2459. }
  2460. static void rtl8169_init_phy(struct net_device *dev, struct rtl8169_private *tp)
  2461. {
  2462. void __iomem *ioaddr = tp->mmio_addr;
  2463. rtl_hw_phy_config(dev);
  2464. if (tp->mac_version <= RTL_GIGA_MAC_VER_06) {
  2465. dprintk("Set MAC Reg C+CR Offset 0x82h = 0x01h\n");
  2466. RTL_W8(0x82, 0x01);
  2467. }
  2468. pci_write_config_byte(tp->pci_dev, PCI_LATENCY_TIMER, 0x40);
  2469. if (tp->mac_version <= RTL_GIGA_MAC_VER_06)
  2470. pci_write_config_byte(tp->pci_dev, PCI_CACHE_LINE_SIZE, 0x08);
  2471. if (tp->mac_version == RTL_GIGA_MAC_VER_02) {
  2472. dprintk("Set MAC Reg C+CR Offset 0x82h = 0x01h\n");
  2473. RTL_W8(0x82, 0x01);
  2474. dprintk("Set PHY Reg 0x0bh = 0x00h\n");
  2475. mdio_write(ioaddr, 0x0b, 0x0000); //w 0x0b 15 0 0
  2476. }
  2477. rtl8169_phy_reset(dev, tp);
  2478. /*
  2479. * rtl8169_set_speed_xmii takes good care of the Fast Ethernet
  2480. * only 8101. Don't panic.
  2481. */
  2482. rtl8169_set_speed(dev, AUTONEG_ENABLE, SPEED_1000, DUPLEX_FULL);
  2483. if (RTL_R8(PHYstatus) & TBI_Enable)
  2484. netif_info(tp, link, dev, "TBI auto-negotiating\n");
  2485. }
  2486. static void rtl_rar_set(struct rtl8169_private *tp, u8 *addr)
  2487. {
  2488. void __iomem *ioaddr = tp->mmio_addr;
  2489. u32 high;
  2490. u32 low;
  2491. low = addr[0] | (addr[1] << 8) | (addr[2] << 16) | (addr[3] << 24);
  2492. high = addr[4] | (addr[5] << 8);
  2493. spin_lock_irq(&tp->lock);
  2494. RTL_W8(Cfg9346, Cfg9346_Unlock);
  2495. RTL_W32(MAC0, low);
  2496. RTL_W32(MAC4, high);
  2497. RTL_W8(Cfg9346, Cfg9346_Lock);
  2498. spin_unlock_irq(&tp->lock);
  2499. }
  2500. static int rtl_set_mac_address(struct net_device *dev, void *p)
  2501. {
  2502. struct rtl8169_private *tp = netdev_priv(dev);
  2503. struct sockaddr *addr = p;
  2504. if (!is_valid_ether_addr(addr->sa_data))
  2505. return -EADDRNOTAVAIL;
  2506. memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
  2507. rtl_rar_set(tp, dev->dev_addr);
  2508. return 0;
  2509. }
  2510. static int rtl8169_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  2511. {
  2512. struct rtl8169_private *tp = netdev_priv(dev);
  2513. struct mii_ioctl_data *data = if_mii(ifr);
  2514. return netif_running(dev) ? tp->do_ioctl(tp, data, cmd) : -ENODEV;
  2515. }
  2516. static int rtl_xmii_ioctl(struct rtl8169_private *tp, struct mii_ioctl_data *data, int cmd)
  2517. {
  2518. switch (cmd) {
  2519. case SIOCGMIIPHY:
  2520. data->phy_id = 32; /* Internal PHY */
  2521. return 0;
  2522. case SIOCGMIIREG:
  2523. data->val_out = mdio_read(tp->mmio_addr, data->reg_num & 0x1f);
  2524. return 0;
  2525. case SIOCSMIIREG:
  2526. mdio_write(tp->mmio_addr, data->reg_num & 0x1f, data->val_in);
  2527. return 0;
  2528. }
  2529. return -EOPNOTSUPP;
  2530. }
  2531. static int rtl_tbi_ioctl(struct rtl8169_private *tp, struct mii_ioctl_data *data, int cmd)
  2532. {
  2533. return -EOPNOTSUPP;
  2534. }
  2535. static const struct rtl_cfg_info {
  2536. void (*hw_start)(struct net_device *);
  2537. unsigned int region;
  2538. unsigned int align;
  2539. u16 intr_event;
  2540. u16 napi_event;
  2541. unsigned features;
  2542. u8 default_ver;
  2543. } rtl_cfg_infos [] = {
  2544. [RTL_CFG_0] = {
  2545. .hw_start = rtl_hw_start_8169,
  2546. .region = 1,
  2547. .align = 0,
  2548. .intr_event = SYSErr | LinkChg | RxOverflow |
  2549. RxFIFOOver | TxErr | TxOK | RxOK | RxErr,
  2550. .napi_event = RxFIFOOver | TxErr | TxOK | RxOK | RxOverflow,
  2551. .features = RTL_FEATURE_GMII,
  2552. .default_ver = RTL_GIGA_MAC_VER_01,
  2553. },
  2554. [RTL_CFG_1] = {
  2555. .hw_start = rtl_hw_start_8168,
  2556. .region = 2,
  2557. .align = 8,
  2558. .intr_event = SYSErr | LinkChg | RxOverflow |
  2559. TxErr | TxOK | RxOK | RxErr,
  2560. .napi_event = TxErr | TxOK | RxOK | RxOverflow,
  2561. .features = RTL_FEATURE_GMII | RTL_FEATURE_MSI,
  2562. .default_ver = RTL_GIGA_MAC_VER_11,
  2563. },
  2564. [RTL_CFG_2] = {
  2565. .hw_start = rtl_hw_start_8101,
  2566. .region = 2,
  2567. .align = 8,
  2568. .intr_event = SYSErr | LinkChg | RxOverflow | PCSTimeout |
  2569. RxFIFOOver | TxErr | TxOK | RxOK | RxErr,
  2570. .napi_event = RxFIFOOver | TxErr | TxOK | RxOK | RxOverflow,
  2571. .features = RTL_FEATURE_MSI,
  2572. .default_ver = RTL_GIGA_MAC_VER_13,
  2573. }
  2574. };
  2575. /* Cfg9346_Unlock assumed. */
  2576. static unsigned rtl_try_msi(struct pci_dev *pdev, void __iomem *ioaddr,
  2577. const struct rtl_cfg_info *cfg)
  2578. {
  2579. unsigned msi = 0;
  2580. u8 cfg2;
  2581. cfg2 = RTL_R8(Config2) & ~MSIEnable;
  2582. if (cfg->features & RTL_FEATURE_MSI) {
  2583. if (pci_enable_msi(pdev)) {
  2584. dev_info(&pdev->dev, "no MSI. Back to INTx.\n");
  2585. } else {
  2586. cfg2 |= MSIEnable;
  2587. msi = RTL_FEATURE_MSI;
  2588. }
  2589. }
  2590. RTL_W8(Config2, cfg2);
  2591. return msi;
  2592. }
  2593. static void rtl_disable_msi(struct pci_dev *pdev, struct rtl8169_private *tp)
  2594. {
  2595. if (tp->features & RTL_FEATURE_MSI) {
  2596. pci_disable_msi(pdev);
  2597. tp->features &= ~RTL_FEATURE_MSI;
  2598. }
  2599. }
  2600. static const struct net_device_ops rtl8169_netdev_ops = {
  2601. .ndo_open = rtl8169_open,
  2602. .ndo_stop = rtl8169_close,
  2603. .ndo_get_stats = rtl8169_get_stats,
  2604. .ndo_start_xmit = rtl8169_start_xmit,
  2605. .ndo_tx_timeout = rtl8169_tx_timeout,
  2606. .ndo_validate_addr = eth_validate_addr,
  2607. .ndo_change_mtu = rtl8169_change_mtu,
  2608. .ndo_set_mac_address = rtl_set_mac_address,
  2609. .ndo_do_ioctl = rtl8169_ioctl,
  2610. .ndo_set_multicast_list = rtl_set_rx_mode,
  2611. #ifdef CONFIG_R8169_VLAN
  2612. .ndo_vlan_rx_register = rtl8169_vlan_rx_register,
  2613. #endif
  2614. #ifdef CONFIG_NET_POLL_CONTROLLER
  2615. .ndo_poll_controller = rtl8169_netpoll,
  2616. #endif
  2617. };
  2618. static int __devinit
  2619. rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
  2620. {
  2621. const struct rtl_cfg_info *cfg = rtl_cfg_infos + ent->driver_data;
  2622. const unsigned int region = cfg->region;
  2623. struct rtl8169_private *tp;
  2624. struct mii_if_info *mii;
  2625. struct net_device *dev;
  2626. void __iomem *ioaddr;
  2627. unsigned int i;
  2628. int rc;
  2629. int this_use_dac = use_dac;
  2630. if (netif_msg_drv(&debug)) {
  2631. printk(KERN_INFO "%s Gigabit Ethernet driver %s loaded\n",
  2632. MODULENAME, RTL8169_VERSION);
  2633. }
  2634. dev = alloc_etherdev(sizeof (*tp));
  2635. if (!dev) {
  2636. if (netif_msg_drv(&debug))
  2637. dev_err(&pdev->dev, "unable to alloc new ethernet\n");
  2638. rc = -ENOMEM;
  2639. goto out;
  2640. }
  2641. SET_NETDEV_DEV(dev, &pdev->dev);
  2642. dev->netdev_ops = &rtl8169_netdev_ops;
  2643. tp = netdev_priv(dev);
  2644. tp->dev = dev;
  2645. tp->pci_dev = pdev;
  2646. tp->msg_enable = netif_msg_init(debug.msg_enable, R8169_MSG_DEFAULT);
  2647. mii = &tp->mii;
  2648. mii->dev = dev;
  2649. mii->mdio_read = rtl_mdio_read;
  2650. mii->mdio_write = rtl_mdio_write;
  2651. mii->phy_id_mask = 0x1f;
  2652. mii->reg_num_mask = 0x1f;
  2653. mii->supports_gmii = !!(cfg->features & RTL_FEATURE_GMII);
  2654. /* enable device (incl. PCI PM wakeup and hotplug setup) */
  2655. rc = pci_enable_device(pdev);
  2656. if (rc < 0) {
  2657. netif_err(tp, probe, dev, "enable failure\n");
  2658. goto err_out_free_dev_1;
  2659. }
  2660. rc = pci_set_mwi(pdev);
  2661. if (rc < 0)
  2662. goto err_out_disable_2;
  2663. /* make sure PCI base addr 1 is MMIO */
  2664. if (!(pci_resource_flags(pdev, region) & IORESOURCE_MEM)) {
  2665. netif_err(tp, probe, dev,
  2666. "region #%d not an MMIO resource, aborting\n",
  2667. region);
  2668. rc = -ENODEV;
  2669. goto err_out_mwi_3;
  2670. }
  2671. /* check for weird/broken PCI region reporting */
  2672. if (pci_resource_len(pdev, region) < R8169_REGS_SIZE) {
  2673. netif_err(tp, probe, dev,
  2674. "Invalid PCI region size(s), aborting\n");
  2675. rc = -ENODEV;
  2676. goto err_out_mwi_3;
  2677. }
  2678. rc = pci_request_regions(pdev, MODULENAME);
  2679. if (rc < 0) {
  2680. netif_err(tp, probe, dev, "could not request regions\n");
  2681. goto err_out_mwi_3;
  2682. }
  2683. tp->cp_cmd = PCIMulRW | RxChkSum;
  2684. tp->pcie_cap = pci_find_capability(pdev, PCI_CAP_ID_EXP);
  2685. if (!tp->pcie_cap)
  2686. netif_info(tp, probe, dev, "no PCI Express capability\n");
  2687. if (this_use_dac < 0)
  2688. this_use_dac = tp->pcie_cap != 0;
  2689. if ((sizeof(dma_addr_t) > 4) &&
  2690. this_use_dac &&
  2691. !pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) {
  2692. netif_info(tp, probe, dev, "using 64-bit DMA\n");
  2693. tp->cp_cmd |= PCIDAC;
  2694. dev->features |= NETIF_F_HIGHDMA;
  2695. } else {
  2696. rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  2697. if (rc < 0) {
  2698. netif_err(tp, probe, dev, "DMA configuration failed\n");
  2699. goto err_out_free_res_4;
  2700. }
  2701. }
  2702. /* ioremap MMIO region */
  2703. ioaddr = ioremap(pci_resource_start(pdev, region), R8169_REGS_SIZE);
  2704. if (!ioaddr) {
  2705. netif_err(tp, probe, dev, "cannot remap MMIO, aborting\n");
  2706. rc = -EIO;
  2707. goto err_out_free_res_4;
  2708. }
  2709. RTL_W16(IntrMask, 0x0000);
  2710. /* Soft reset the chip. */
  2711. RTL_W8(ChipCmd, CmdReset);
  2712. /* Check that the chip has finished the reset. */
  2713. for (i = 0; i < 100; i++) {
  2714. if ((RTL_R8(ChipCmd) & CmdReset) == 0)
  2715. break;
  2716. msleep_interruptible(1);
  2717. }
  2718. RTL_W16(IntrStatus, 0xffff);
  2719. pci_set_master(pdev);
  2720. /* Identify chip attached to board */
  2721. rtl8169_get_mac_version(tp, ioaddr);
  2722. /* Use appropriate default if unknown */
  2723. if (tp->mac_version == RTL_GIGA_MAC_NONE) {
  2724. netif_notice(tp, probe, dev,
  2725. "unknown MAC, using family default\n");
  2726. tp->mac_version = cfg->default_ver;
  2727. }
  2728. rtl8169_print_mac_version(tp);
  2729. for (i = 0; i < ARRAY_SIZE(rtl_chip_info); i++) {
  2730. if (tp->mac_version == rtl_chip_info[i].mac_version)
  2731. break;
  2732. }
  2733. if (i == ARRAY_SIZE(rtl_chip_info)) {
  2734. dev_err(&pdev->dev,
  2735. "driver bug, MAC version not found in rtl_chip_info\n");
  2736. goto err_out_msi_5;
  2737. }
  2738. tp->chipset = i;
  2739. RTL_W8(Cfg9346, Cfg9346_Unlock);
  2740. RTL_W8(Config1, RTL_R8(Config1) | PMEnable);
  2741. RTL_W8(Config5, RTL_R8(Config5) & PMEStatus);
  2742. if ((RTL_R8(Config3) & (LinkUp | MagicPacket)) != 0)
  2743. tp->features |= RTL_FEATURE_WOL;
  2744. if ((RTL_R8(Config5) & (UWF | BWF | MWF)) != 0)
  2745. tp->features |= RTL_FEATURE_WOL;
  2746. tp->features |= rtl_try_msi(pdev, ioaddr, cfg);
  2747. RTL_W8(Cfg9346, Cfg9346_Lock);
  2748. if ((tp->mac_version <= RTL_GIGA_MAC_VER_06) &&
  2749. (RTL_R8(PHYstatus) & TBI_Enable)) {
  2750. tp->set_speed = rtl8169_set_speed_tbi;
  2751. tp->get_settings = rtl8169_gset_tbi;
  2752. tp->phy_reset_enable = rtl8169_tbi_reset_enable;
  2753. tp->phy_reset_pending = rtl8169_tbi_reset_pending;
  2754. tp->link_ok = rtl8169_tbi_link_ok;
  2755. tp->do_ioctl = rtl_tbi_ioctl;
  2756. tp->phy_1000_ctrl_reg = ADVERTISE_1000FULL; /* Implied by TBI */
  2757. } else {
  2758. tp->set_speed = rtl8169_set_speed_xmii;
  2759. tp->get_settings = rtl8169_gset_xmii;
  2760. tp->phy_reset_enable = rtl8169_xmii_reset_enable;
  2761. tp->phy_reset_pending = rtl8169_xmii_reset_pending;
  2762. tp->link_ok = rtl8169_xmii_link_ok;
  2763. tp->do_ioctl = rtl_xmii_ioctl;
  2764. }
  2765. spin_lock_init(&tp->lock);
  2766. tp->mmio_addr = ioaddr;
  2767. /* Get MAC address */
  2768. for (i = 0; i < MAC_ADDR_LEN; i++)
  2769. dev->dev_addr[i] = RTL_R8(MAC0 + i);
  2770. memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
  2771. SET_ETHTOOL_OPS(dev, &rtl8169_ethtool_ops);
  2772. dev->watchdog_timeo = RTL8169_TX_TIMEOUT;
  2773. dev->irq = pdev->irq;
  2774. dev->base_addr = (unsigned long) ioaddr;
  2775. netif_napi_add(dev, &tp->napi, rtl8169_poll, R8169_NAPI_WEIGHT);
  2776. #ifdef CONFIG_R8169_VLAN
  2777. dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
  2778. #endif
  2779. tp->intr_mask = 0xffff;
  2780. tp->align = cfg->align;
  2781. tp->hw_start = cfg->hw_start;
  2782. tp->intr_event = cfg->intr_event;
  2783. tp->napi_event = cfg->napi_event;
  2784. init_timer(&tp->timer);
  2785. tp->timer.data = (unsigned long) dev;
  2786. tp->timer.function = rtl8169_phy_timer;
  2787. rc = register_netdev(dev);
  2788. if (rc < 0)
  2789. goto err_out_msi_5;
  2790. pci_set_drvdata(pdev, dev);
  2791. netif_info(tp, probe, dev, "%s at 0x%lx, %pM, XID %08x IRQ %d\n",
  2792. rtl_chip_info[tp->chipset].name,
  2793. dev->base_addr, dev->dev_addr,
  2794. (u32)(RTL_R32(TxConfig) & 0x9cf0f8ff), dev->irq);
  2795. rtl8169_init_phy(dev, tp);
  2796. /*
  2797. * Pretend we are using VLANs; This bypasses a nasty bug where
  2798. * Interrupts stop flowing on high load on 8110SCd controllers.
  2799. */
  2800. if (tp->mac_version == RTL_GIGA_MAC_VER_05)
  2801. RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) | RxVlan);
  2802. device_set_wakeup_enable(&pdev->dev, tp->features & RTL_FEATURE_WOL);
  2803. out:
  2804. return rc;
  2805. err_out_msi_5:
  2806. rtl_disable_msi(pdev, tp);
  2807. iounmap(ioaddr);
  2808. err_out_free_res_4:
  2809. pci_release_regions(pdev);
  2810. err_out_mwi_3:
  2811. pci_clear_mwi(pdev);
  2812. err_out_disable_2:
  2813. pci_disable_device(pdev);
  2814. err_out_free_dev_1:
  2815. free_netdev(dev);
  2816. goto out;
  2817. }
  2818. static void __devexit rtl8169_remove_one(struct pci_dev *pdev)
  2819. {
  2820. struct net_device *dev = pci_get_drvdata(pdev);
  2821. struct rtl8169_private *tp = netdev_priv(dev);
  2822. flush_scheduled_work();
  2823. unregister_netdev(dev);
  2824. /* restore original MAC address */
  2825. rtl_rar_set(tp, dev->perm_addr);
  2826. rtl_disable_msi(pdev, tp);
  2827. rtl8169_release_board(pdev, dev, tp->mmio_addr);
  2828. pci_set_drvdata(pdev, NULL);
  2829. }
  2830. static void rtl8169_set_rxbufsize(struct rtl8169_private *tp,
  2831. struct net_device *dev)
  2832. {
  2833. unsigned int max_frame = dev->mtu + VLAN_ETH_HLEN + ETH_FCS_LEN;
  2834. tp->rx_buf_sz = (max_frame > RX_BUF_SIZE) ? max_frame : RX_BUF_SIZE;
  2835. }
  2836. static int rtl8169_open(struct net_device *dev)
  2837. {
  2838. struct rtl8169_private *tp = netdev_priv(dev);
  2839. struct pci_dev *pdev = tp->pci_dev;
  2840. int retval = -ENOMEM;
  2841. rtl8169_set_rxbufsize(tp, dev);
  2842. /*
  2843. * Rx and Tx desscriptors needs 256 bytes alignment.
  2844. * pci_alloc_consistent provides more.
  2845. */
  2846. tp->TxDescArray = pci_alloc_consistent(pdev, R8169_TX_RING_BYTES,
  2847. &tp->TxPhyAddr);
  2848. if (!tp->TxDescArray)
  2849. goto out;
  2850. tp->RxDescArray = pci_alloc_consistent(pdev, R8169_RX_RING_BYTES,
  2851. &tp->RxPhyAddr);
  2852. if (!tp->RxDescArray)
  2853. goto err_free_tx_0;
  2854. retval = rtl8169_init_ring(dev);
  2855. if (retval < 0)
  2856. goto err_free_rx_1;
  2857. INIT_DELAYED_WORK(&tp->task, NULL);
  2858. smp_mb();
  2859. retval = request_irq(dev->irq, rtl8169_interrupt,
  2860. (tp->features & RTL_FEATURE_MSI) ? 0 : IRQF_SHARED,
  2861. dev->name, dev);
  2862. if (retval < 0)
  2863. goto err_release_ring_2;
  2864. napi_enable(&tp->napi);
  2865. rtl_hw_start(dev);
  2866. rtl8169_request_timer(dev);
  2867. rtl8169_check_link_status(dev, tp, tp->mmio_addr);
  2868. out:
  2869. return retval;
  2870. err_release_ring_2:
  2871. rtl8169_rx_clear(tp);
  2872. err_free_rx_1:
  2873. pci_free_consistent(pdev, R8169_RX_RING_BYTES, tp->RxDescArray,
  2874. tp->RxPhyAddr);
  2875. err_free_tx_0:
  2876. pci_free_consistent(pdev, R8169_TX_RING_BYTES, tp->TxDescArray,
  2877. tp->TxPhyAddr);
  2878. goto out;
  2879. }
  2880. static void rtl8169_hw_reset(void __iomem *ioaddr)
  2881. {
  2882. /* Disable interrupts */
  2883. rtl8169_irq_mask_and_ack(ioaddr);
  2884. /* Reset the chipset */
  2885. RTL_W8(ChipCmd, CmdReset);
  2886. /* PCI commit */
  2887. RTL_R8(ChipCmd);
  2888. }
  2889. static void rtl_set_rx_tx_config_registers(struct rtl8169_private *tp)
  2890. {
  2891. void __iomem *ioaddr = tp->mmio_addr;
  2892. u32 cfg = rtl8169_rx_config;
  2893. cfg |= (RTL_R32(RxConfig) & rtl_chip_info[tp->chipset].RxConfigMask);
  2894. RTL_W32(RxConfig, cfg);
  2895. /* Set DMA burst size and Interframe Gap Time */
  2896. RTL_W32(TxConfig, (TX_DMA_BURST << TxDMAShift) |
  2897. (InterFrameGap << TxInterFrameGapShift));
  2898. }
  2899. static void rtl_hw_start(struct net_device *dev)
  2900. {
  2901. struct rtl8169_private *tp = netdev_priv(dev);
  2902. void __iomem *ioaddr = tp->mmio_addr;
  2903. unsigned int i;
  2904. /* Soft reset the chip. */
  2905. RTL_W8(ChipCmd, CmdReset);
  2906. /* Check that the chip has finished the reset. */
  2907. for (i = 0; i < 100; i++) {
  2908. if ((RTL_R8(ChipCmd) & CmdReset) == 0)
  2909. break;
  2910. msleep_interruptible(1);
  2911. }
  2912. tp->hw_start(dev);
  2913. netif_start_queue(dev);
  2914. }
  2915. static void rtl_set_rx_tx_desc_registers(struct rtl8169_private *tp,
  2916. void __iomem *ioaddr)
  2917. {
  2918. /*
  2919. * Magic spell: some iop3xx ARM board needs the TxDescAddrHigh
  2920. * register to be written before TxDescAddrLow to work.
  2921. * Switching from MMIO to I/O access fixes the issue as well.
  2922. */
  2923. RTL_W32(TxDescStartAddrHigh, ((u64) tp->TxPhyAddr) >> 32);
  2924. RTL_W32(TxDescStartAddrLow, ((u64) tp->TxPhyAddr) & DMA_BIT_MASK(32));
  2925. RTL_W32(RxDescAddrHigh, ((u64) tp->RxPhyAddr) >> 32);
  2926. RTL_W32(RxDescAddrLow, ((u64) tp->RxPhyAddr) & DMA_BIT_MASK(32));
  2927. }
  2928. static u16 rtl_rw_cpluscmd(void __iomem *ioaddr)
  2929. {
  2930. u16 cmd;
  2931. cmd = RTL_R16(CPlusCmd);
  2932. RTL_W16(CPlusCmd, cmd);
  2933. return cmd;
  2934. }
  2935. static void rtl_set_rx_max_size(void __iomem *ioaddr, unsigned int rx_buf_sz)
  2936. {
  2937. /* Low hurts. Let's disable the filtering. */
  2938. RTL_W16(RxMaxSize, rx_buf_sz + 1);
  2939. }
  2940. static void rtl8169_set_magic_reg(void __iomem *ioaddr, unsigned mac_version)
  2941. {
  2942. static const struct {
  2943. u32 mac_version;
  2944. u32 clk;
  2945. u32 val;
  2946. } cfg2_info [] = {
  2947. { RTL_GIGA_MAC_VER_05, PCI_Clock_33MHz, 0x000fff00 }, // 8110SCd
  2948. { RTL_GIGA_MAC_VER_05, PCI_Clock_66MHz, 0x000fffff },
  2949. { RTL_GIGA_MAC_VER_06, PCI_Clock_33MHz, 0x00ffff00 }, // 8110SCe
  2950. { RTL_GIGA_MAC_VER_06, PCI_Clock_66MHz, 0x00ffffff }
  2951. }, *p = cfg2_info;
  2952. unsigned int i;
  2953. u32 clk;
  2954. clk = RTL_R8(Config2) & PCI_Clock_66MHz;
  2955. for (i = 0; i < ARRAY_SIZE(cfg2_info); i++, p++) {
  2956. if ((p->mac_version == mac_version) && (p->clk == clk)) {
  2957. RTL_W32(0x7c, p->val);
  2958. break;
  2959. }
  2960. }
  2961. }
  2962. static void rtl_hw_start_8169(struct net_device *dev)
  2963. {
  2964. struct rtl8169_private *tp = netdev_priv(dev);
  2965. void __iomem *ioaddr = tp->mmio_addr;
  2966. struct pci_dev *pdev = tp->pci_dev;
  2967. if (tp->mac_version == RTL_GIGA_MAC_VER_05) {
  2968. RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) | PCIMulRW);
  2969. pci_write_config_byte(pdev, PCI_CACHE_LINE_SIZE, 0x08);
  2970. }
  2971. RTL_W8(Cfg9346, Cfg9346_Unlock);
  2972. if ((tp->mac_version == RTL_GIGA_MAC_VER_01) ||
  2973. (tp->mac_version == RTL_GIGA_MAC_VER_02) ||
  2974. (tp->mac_version == RTL_GIGA_MAC_VER_03) ||
  2975. (tp->mac_version == RTL_GIGA_MAC_VER_04))
  2976. RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb);
  2977. RTL_W8(EarlyTxThres, EarlyTxThld);
  2978. rtl_set_rx_max_size(ioaddr, tp->rx_buf_sz);
  2979. if ((tp->mac_version == RTL_GIGA_MAC_VER_01) ||
  2980. (tp->mac_version == RTL_GIGA_MAC_VER_02) ||
  2981. (tp->mac_version == RTL_GIGA_MAC_VER_03) ||
  2982. (tp->mac_version == RTL_GIGA_MAC_VER_04))
  2983. rtl_set_rx_tx_config_registers(tp);
  2984. tp->cp_cmd |= rtl_rw_cpluscmd(ioaddr) | PCIMulRW;
  2985. if ((tp->mac_version == RTL_GIGA_MAC_VER_02) ||
  2986. (tp->mac_version == RTL_GIGA_MAC_VER_03)) {
  2987. dprintk("Set MAC Reg C+CR Offset 0xE0. "
  2988. "Bit-3 and bit-14 MUST be 1\n");
  2989. tp->cp_cmd |= (1 << 14);
  2990. }
  2991. RTL_W16(CPlusCmd, tp->cp_cmd);
  2992. rtl8169_set_magic_reg(ioaddr, tp->mac_version);
  2993. /*
  2994. * Undocumented corner. Supposedly:
  2995. * (TxTimer << 12) | (TxPackets << 8) | (RxTimer << 4) | RxPackets
  2996. */
  2997. RTL_W16(IntrMitigate, 0x0000);
  2998. rtl_set_rx_tx_desc_registers(tp, ioaddr);
  2999. if ((tp->mac_version != RTL_GIGA_MAC_VER_01) &&
  3000. (tp->mac_version != RTL_GIGA_MAC_VER_02) &&
  3001. (tp->mac_version != RTL_GIGA_MAC_VER_03) &&
  3002. (tp->mac_version != RTL_GIGA_MAC_VER_04)) {
  3003. RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb);
  3004. rtl_set_rx_tx_config_registers(tp);
  3005. }
  3006. RTL_W8(Cfg9346, Cfg9346_Lock);
  3007. /* Initially a 10 us delay. Turned it into a PCI commit. - FR */
  3008. RTL_R8(IntrMask);
  3009. RTL_W32(RxMissed, 0);
  3010. rtl_set_rx_mode(dev);
  3011. /* no early-rx interrupts */
  3012. RTL_W16(MultiIntr, RTL_R16(MultiIntr) & 0xF000);
  3013. /* Enable all known interrupts by setting the interrupt mask. */
  3014. RTL_W16(IntrMask, tp->intr_event);
  3015. }
  3016. static void rtl_tx_performance_tweak(struct pci_dev *pdev, u16 force)
  3017. {
  3018. struct net_device *dev = pci_get_drvdata(pdev);
  3019. struct rtl8169_private *tp = netdev_priv(dev);
  3020. int cap = tp->pcie_cap;
  3021. if (cap) {
  3022. u16 ctl;
  3023. pci_read_config_word(pdev, cap + PCI_EXP_DEVCTL, &ctl);
  3024. ctl = (ctl & ~PCI_EXP_DEVCTL_READRQ) | force;
  3025. pci_write_config_word(pdev, cap + PCI_EXP_DEVCTL, ctl);
  3026. }
  3027. }
  3028. static void rtl_csi_access_enable(void __iomem *ioaddr)
  3029. {
  3030. u32 csi;
  3031. csi = rtl_csi_read(ioaddr, 0x070c) & 0x00ffffff;
  3032. rtl_csi_write(ioaddr, 0x070c, csi | 0x27000000);
  3033. }
  3034. struct ephy_info {
  3035. unsigned int offset;
  3036. u16 mask;
  3037. u16 bits;
  3038. };
  3039. static void rtl_ephy_init(void __iomem *ioaddr, const struct ephy_info *e, int len)
  3040. {
  3041. u16 w;
  3042. while (len-- > 0) {
  3043. w = (rtl_ephy_read(ioaddr, e->offset) & ~e->mask) | e->bits;
  3044. rtl_ephy_write(ioaddr, e->offset, w);
  3045. e++;
  3046. }
  3047. }
  3048. static void rtl_disable_clock_request(struct pci_dev *pdev)
  3049. {
  3050. struct net_device *dev = pci_get_drvdata(pdev);
  3051. struct rtl8169_private *tp = netdev_priv(dev);
  3052. int cap = tp->pcie_cap;
  3053. if (cap) {
  3054. u16 ctl;
  3055. pci_read_config_word(pdev, cap + PCI_EXP_LNKCTL, &ctl);
  3056. ctl &= ~PCI_EXP_LNKCTL_CLKREQ_EN;
  3057. pci_write_config_word(pdev, cap + PCI_EXP_LNKCTL, ctl);
  3058. }
  3059. }
  3060. #define R8168_CPCMD_QUIRK_MASK (\
  3061. EnableBist | \
  3062. Mac_dbgo_oe | \
  3063. Force_half_dup | \
  3064. Force_rxflow_en | \
  3065. Force_txflow_en | \
  3066. Cxpl_dbg_sel | \
  3067. ASF | \
  3068. PktCntrDisable | \
  3069. Mac_dbgo_sel)
  3070. static void rtl_hw_start_8168bb(void __iomem *ioaddr, struct pci_dev *pdev)
  3071. {
  3072. RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en);
  3073. RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK);
  3074. rtl_tx_performance_tweak(pdev,
  3075. (0x5 << MAX_READ_REQUEST_SHIFT) | PCI_EXP_DEVCTL_NOSNOOP_EN);
  3076. }
  3077. static void rtl_hw_start_8168bef(void __iomem *ioaddr, struct pci_dev *pdev)
  3078. {
  3079. rtl_hw_start_8168bb(ioaddr, pdev);
  3080. RTL_W8(EarlyTxThres, EarlyTxThld);
  3081. RTL_W8(Config4, RTL_R8(Config4) & ~(1 << 0));
  3082. }
  3083. static void __rtl_hw_start_8168cp(void __iomem *ioaddr, struct pci_dev *pdev)
  3084. {
  3085. RTL_W8(Config1, RTL_R8(Config1) | Speed_down);
  3086. RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en);
  3087. rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT);
  3088. rtl_disable_clock_request(pdev);
  3089. RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK);
  3090. }
  3091. static void rtl_hw_start_8168cp_1(void __iomem *ioaddr, struct pci_dev *pdev)
  3092. {
  3093. static const struct ephy_info e_info_8168cp[] = {
  3094. { 0x01, 0, 0x0001 },
  3095. { 0x02, 0x0800, 0x1000 },
  3096. { 0x03, 0, 0x0042 },
  3097. { 0x06, 0x0080, 0x0000 },
  3098. { 0x07, 0, 0x2000 }
  3099. };
  3100. rtl_csi_access_enable(ioaddr);
  3101. rtl_ephy_init(ioaddr, e_info_8168cp, ARRAY_SIZE(e_info_8168cp));
  3102. __rtl_hw_start_8168cp(ioaddr, pdev);
  3103. }
  3104. static void rtl_hw_start_8168cp_2(void __iomem *ioaddr, struct pci_dev *pdev)
  3105. {
  3106. rtl_csi_access_enable(ioaddr);
  3107. RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en);
  3108. rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT);
  3109. RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK);
  3110. }
  3111. static void rtl_hw_start_8168cp_3(void __iomem *ioaddr, struct pci_dev *pdev)
  3112. {
  3113. rtl_csi_access_enable(ioaddr);
  3114. RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en);
  3115. /* Magic. */
  3116. RTL_W8(DBG_REG, 0x20);
  3117. RTL_W8(EarlyTxThres, EarlyTxThld);
  3118. rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT);
  3119. RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK);
  3120. }
  3121. static void rtl_hw_start_8168c_1(void __iomem *ioaddr, struct pci_dev *pdev)
  3122. {
  3123. static const struct ephy_info e_info_8168c_1[] = {
  3124. { 0x02, 0x0800, 0x1000 },
  3125. { 0x03, 0, 0x0002 },
  3126. { 0x06, 0x0080, 0x0000 }
  3127. };
  3128. rtl_csi_access_enable(ioaddr);
  3129. RTL_W8(DBG_REG, 0x06 | FIX_NAK_1 | FIX_NAK_2);
  3130. rtl_ephy_init(ioaddr, e_info_8168c_1, ARRAY_SIZE(e_info_8168c_1));
  3131. __rtl_hw_start_8168cp(ioaddr, pdev);
  3132. }
  3133. static void rtl_hw_start_8168c_2(void __iomem *ioaddr, struct pci_dev *pdev)
  3134. {
  3135. static const struct ephy_info e_info_8168c_2[] = {
  3136. { 0x01, 0, 0x0001 },
  3137. { 0x03, 0x0400, 0x0220 }
  3138. };
  3139. rtl_csi_access_enable(ioaddr);
  3140. rtl_ephy_init(ioaddr, e_info_8168c_2, ARRAY_SIZE(e_info_8168c_2));
  3141. __rtl_hw_start_8168cp(ioaddr, pdev);
  3142. }
  3143. static void rtl_hw_start_8168c_3(void __iomem *ioaddr, struct pci_dev *pdev)
  3144. {
  3145. rtl_hw_start_8168c_2(ioaddr, pdev);
  3146. }
  3147. static void rtl_hw_start_8168c_4(void __iomem *ioaddr, struct pci_dev *pdev)
  3148. {
  3149. rtl_csi_access_enable(ioaddr);
  3150. __rtl_hw_start_8168cp(ioaddr, pdev);
  3151. }
  3152. static void rtl_hw_start_8168d(void __iomem *ioaddr, struct pci_dev *pdev)
  3153. {
  3154. rtl_csi_access_enable(ioaddr);
  3155. rtl_disable_clock_request(pdev);
  3156. RTL_W8(EarlyTxThres, EarlyTxThld);
  3157. rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT);
  3158. RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK);
  3159. }
  3160. static void rtl_hw_start_8168(struct net_device *dev)
  3161. {
  3162. struct rtl8169_private *tp = netdev_priv(dev);
  3163. void __iomem *ioaddr = tp->mmio_addr;
  3164. struct pci_dev *pdev = tp->pci_dev;
  3165. RTL_W8(Cfg9346, Cfg9346_Unlock);
  3166. RTL_W8(EarlyTxThres, EarlyTxThld);
  3167. rtl_set_rx_max_size(ioaddr, tp->rx_buf_sz);
  3168. tp->cp_cmd |= RTL_R16(CPlusCmd) | PktCntrDisable | INTT_1;
  3169. RTL_W16(CPlusCmd, tp->cp_cmd);
  3170. RTL_W16(IntrMitigate, 0x5151);
  3171. /* Work around for RxFIFO overflow. */
  3172. if (tp->mac_version == RTL_GIGA_MAC_VER_11) {
  3173. tp->intr_event |= RxFIFOOver | PCSTimeout;
  3174. tp->intr_event &= ~RxOverflow;
  3175. }
  3176. rtl_set_rx_tx_desc_registers(tp, ioaddr);
  3177. rtl_set_rx_mode(dev);
  3178. RTL_W32(TxConfig, (TX_DMA_BURST << TxDMAShift) |
  3179. (InterFrameGap << TxInterFrameGapShift));
  3180. RTL_R8(IntrMask);
  3181. switch (tp->mac_version) {
  3182. case RTL_GIGA_MAC_VER_11:
  3183. rtl_hw_start_8168bb(ioaddr, pdev);
  3184. break;
  3185. case RTL_GIGA_MAC_VER_12:
  3186. case RTL_GIGA_MAC_VER_17:
  3187. rtl_hw_start_8168bef(ioaddr, pdev);
  3188. break;
  3189. case RTL_GIGA_MAC_VER_18:
  3190. rtl_hw_start_8168cp_1(ioaddr, pdev);
  3191. break;
  3192. case RTL_GIGA_MAC_VER_19:
  3193. rtl_hw_start_8168c_1(ioaddr, pdev);
  3194. break;
  3195. case RTL_GIGA_MAC_VER_20:
  3196. rtl_hw_start_8168c_2(ioaddr, pdev);
  3197. break;
  3198. case RTL_GIGA_MAC_VER_21:
  3199. rtl_hw_start_8168c_3(ioaddr, pdev);
  3200. break;
  3201. case RTL_GIGA_MAC_VER_22:
  3202. rtl_hw_start_8168c_4(ioaddr, pdev);
  3203. break;
  3204. case RTL_GIGA_MAC_VER_23:
  3205. rtl_hw_start_8168cp_2(ioaddr, pdev);
  3206. break;
  3207. case RTL_GIGA_MAC_VER_24:
  3208. rtl_hw_start_8168cp_3(ioaddr, pdev);
  3209. break;
  3210. case RTL_GIGA_MAC_VER_25:
  3211. case RTL_GIGA_MAC_VER_26:
  3212. case RTL_GIGA_MAC_VER_27:
  3213. rtl_hw_start_8168d(ioaddr, pdev);
  3214. break;
  3215. default:
  3216. printk(KERN_ERR PFX "%s: unknown chipset (mac_version = %d).\n",
  3217. dev->name, tp->mac_version);
  3218. break;
  3219. }
  3220. RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb);
  3221. RTL_W8(Cfg9346, Cfg9346_Lock);
  3222. RTL_W16(MultiIntr, RTL_R16(MultiIntr) & 0xF000);
  3223. RTL_W16(IntrMask, tp->intr_event);
  3224. }
  3225. #define R810X_CPCMD_QUIRK_MASK (\
  3226. EnableBist | \
  3227. Mac_dbgo_oe | \
  3228. Force_half_dup | \
  3229. Force_rxflow_en | \
  3230. Force_txflow_en | \
  3231. Cxpl_dbg_sel | \
  3232. ASF | \
  3233. PktCntrDisable | \
  3234. PCIDAC | \
  3235. PCIMulRW)
  3236. static void rtl_hw_start_8102e_1(void __iomem *ioaddr, struct pci_dev *pdev)
  3237. {
  3238. static const struct ephy_info e_info_8102e_1[] = {
  3239. { 0x01, 0, 0x6e65 },
  3240. { 0x02, 0, 0x091f },
  3241. { 0x03, 0, 0xc2f9 },
  3242. { 0x06, 0, 0xafb5 },
  3243. { 0x07, 0, 0x0e00 },
  3244. { 0x19, 0, 0xec80 },
  3245. { 0x01, 0, 0x2e65 },
  3246. { 0x01, 0, 0x6e65 }
  3247. };
  3248. u8 cfg1;
  3249. rtl_csi_access_enable(ioaddr);
  3250. RTL_W8(DBG_REG, FIX_NAK_1);
  3251. rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT);
  3252. RTL_W8(Config1,
  3253. LEDS1 | LEDS0 | Speed_down | MEMMAP | IOMAP | VPD | PMEnable);
  3254. RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en);
  3255. cfg1 = RTL_R8(Config1);
  3256. if ((cfg1 & LEDS0) && (cfg1 & LEDS1))
  3257. RTL_W8(Config1, cfg1 & ~LEDS0);
  3258. RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R810X_CPCMD_QUIRK_MASK);
  3259. rtl_ephy_init(ioaddr, e_info_8102e_1, ARRAY_SIZE(e_info_8102e_1));
  3260. }
  3261. static void rtl_hw_start_8102e_2(void __iomem *ioaddr, struct pci_dev *pdev)
  3262. {
  3263. rtl_csi_access_enable(ioaddr);
  3264. rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT);
  3265. RTL_W8(Config1, MEMMAP | IOMAP | VPD | PMEnable);
  3266. RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en);
  3267. RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R810X_CPCMD_QUIRK_MASK);
  3268. }
  3269. static void rtl_hw_start_8102e_3(void __iomem *ioaddr, struct pci_dev *pdev)
  3270. {
  3271. rtl_hw_start_8102e_2(ioaddr, pdev);
  3272. rtl_ephy_write(ioaddr, 0x03, 0xc2f9);
  3273. }
  3274. static void rtl_hw_start_8101(struct net_device *dev)
  3275. {
  3276. struct rtl8169_private *tp = netdev_priv(dev);
  3277. void __iomem *ioaddr = tp->mmio_addr;
  3278. struct pci_dev *pdev = tp->pci_dev;
  3279. if ((tp->mac_version == RTL_GIGA_MAC_VER_13) ||
  3280. (tp->mac_version == RTL_GIGA_MAC_VER_16)) {
  3281. int cap = tp->pcie_cap;
  3282. if (cap) {
  3283. pci_write_config_word(pdev, cap + PCI_EXP_DEVCTL,
  3284. PCI_EXP_DEVCTL_NOSNOOP_EN);
  3285. }
  3286. }
  3287. switch (tp->mac_version) {
  3288. case RTL_GIGA_MAC_VER_07:
  3289. rtl_hw_start_8102e_1(ioaddr, pdev);
  3290. break;
  3291. case RTL_GIGA_MAC_VER_08:
  3292. rtl_hw_start_8102e_3(ioaddr, pdev);
  3293. break;
  3294. case RTL_GIGA_MAC_VER_09:
  3295. rtl_hw_start_8102e_2(ioaddr, pdev);
  3296. break;
  3297. }
  3298. RTL_W8(Cfg9346, Cfg9346_Unlock);
  3299. RTL_W8(EarlyTxThres, EarlyTxThld);
  3300. rtl_set_rx_max_size(ioaddr, tp->rx_buf_sz);
  3301. tp->cp_cmd |= rtl_rw_cpluscmd(ioaddr) | PCIMulRW;
  3302. RTL_W16(CPlusCmd, tp->cp_cmd);
  3303. RTL_W16(IntrMitigate, 0x0000);
  3304. rtl_set_rx_tx_desc_registers(tp, ioaddr);
  3305. RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb);
  3306. rtl_set_rx_tx_config_registers(tp);
  3307. RTL_W8(Cfg9346, Cfg9346_Lock);
  3308. RTL_R8(IntrMask);
  3309. rtl_set_rx_mode(dev);
  3310. RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb);
  3311. RTL_W16(MultiIntr, RTL_R16(MultiIntr) & 0xf000);
  3312. RTL_W16(IntrMask, tp->intr_event);
  3313. }
  3314. static int rtl8169_change_mtu(struct net_device *dev, int new_mtu)
  3315. {
  3316. struct rtl8169_private *tp = netdev_priv(dev);
  3317. int ret = 0;
  3318. if (new_mtu < ETH_ZLEN || new_mtu > SafeMtu)
  3319. return -EINVAL;
  3320. dev->mtu = new_mtu;
  3321. if (!netif_running(dev))
  3322. goto out;
  3323. rtl8169_down(dev);
  3324. rtl8169_set_rxbufsize(tp, dev);
  3325. ret = rtl8169_init_ring(dev);
  3326. if (ret < 0)
  3327. goto out;
  3328. napi_enable(&tp->napi);
  3329. rtl_hw_start(dev);
  3330. rtl8169_request_timer(dev);
  3331. out:
  3332. return ret;
  3333. }
  3334. static inline void rtl8169_make_unusable_by_asic(struct RxDesc *desc)
  3335. {
  3336. desc->addr = cpu_to_le64(0x0badbadbadbadbadull);
  3337. desc->opts1 &= ~cpu_to_le32(DescOwn | RsvdMask);
  3338. }
  3339. static void rtl8169_free_rx_skb(struct rtl8169_private *tp,
  3340. struct sk_buff **sk_buff, struct RxDesc *desc)
  3341. {
  3342. struct pci_dev *pdev = tp->pci_dev;
  3343. pci_unmap_single(pdev, le64_to_cpu(desc->addr), tp->rx_buf_sz,
  3344. PCI_DMA_FROMDEVICE);
  3345. dev_kfree_skb(*sk_buff);
  3346. *sk_buff = NULL;
  3347. rtl8169_make_unusable_by_asic(desc);
  3348. }
  3349. static inline void rtl8169_mark_to_asic(struct RxDesc *desc, u32 rx_buf_sz)
  3350. {
  3351. u32 eor = le32_to_cpu(desc->opts1) & RingEnd;
  3352. desc->opts1 = cpu_to_le32(DescOwn | eor | rx_buf_sz);
  3353. }
  3354. static inline void rtl8169_map_to_asic(struct RxDesc *desc, dma_addr_t mapping,
  3355. u32 rx_buf_sz)
  3356. {
  3357. desc->addr = cpu_to_le64(mapping);
  3358. wmb();
  3359. rtl8169_mark_to_asic(desc, rx_buf_sz);
  3360. }
  3361. static struct sk_buff *rtl8169_alloc_rx_skb(struct pci_dev *pdev,
  3362. struct net_device *dev,
  3363. struct RxDesc *desc, int rx_buf_sz,
  3364. unsigned int align)
  3365. {
  3366. struct sk_buff *skb;
  3367. dma_addr_t mapping;
  3368. unsigned int pad;
  3369. pad = align ? align : NET_IP_ALIGN;
  3370. skb = netdev_alloc_skb(dev, rx_buf_sz + pad);
  3371. if (!skb)
  3372. goto err_out;
  3373. skb_reserve(skb, align ? ((pad - 1) & (unsigned long)skb->data) : pad);
  3374. mapping = pci_map_single(pdev, skb->data, rx_buf_sz,
  3375. PCI_DMA_FROMDEVICE);
  3376. rtl8169_map_to_asic(desc, mapping, rx_buf_sz);
  3377. out:
  3378. return skb;
  3379. err_out:
  3380. rtl8169_make_unusable_by_asic(desc);
  3381. goto out;
  3382. }
  3383. static void rtl8169_rx_clear(struct rtl8169_private *tp)
  3384. {
  3385. unsigned int i;
  3386. for (i = 0; i < NUM_RX_DESC; i++) {
  3387. if (tp->Rx_skbuff[i]) {
  3388. rtl8169_free_rx_skb(tp, tp->Rx_skbuff + i,
  3389. tp->RxDescArray + i);
  3390. }
  3391. }
  3392. }
  3393. static u32 rtl8169_rx_fill(struct rtl8169_private *tp, struct net_device *dev,
  3394. u32 start, u32 end)
  3395. {
  3396. u32 cur;
  3397. for (cur = start; end - cur != 0; cur++) {
  3398. struct sk_buff *skb;
  3399. unsigned int i = cur % NUM_RX_DESC;
  3400. WARN_ON((s32)(end - cur) < 0);
  3401. if (tp->Rx_skbuff[i])
  3402. continue;
  3403. skb = rtl8169_alloc_rx_skb(tp->pci_dev, dev,
  3404. tp->RxDescArray + i,
  3405. tp->rx_buf_sz, tp->align);
  3406. if (!skb)
  3407. break;
  3408. tp->Rx_skbuff[i] = skb;
  3409. }
  3410. return cur - start;
  3411. }
  3412. static inline void rtl8169_mark_as_last_descriptor(struct RxDesc *desc)
  3413. {
  3414. desc->opts1 |= cpu_to_le32(RingEnd);
  3415. }
  3416. static void rtl8169_init_ring_indexes(struct rtl8169_private *tp)
  3417. {
  3418. tp->dirty_tx = tp->dirty_rx = tp->cur_tx = tp->cur_rx = 0;
  3419. }
  3420. static int rtl8169_init_ring(struct net_device *dev)
  3421. {
  3422. struct rtl8169_private *tp = netdev_priv(dev);
  3423. rtl8169_init_ring_indexes(tp);
  3424. memset(tp->tx_skb, 0x0, NUM_TX_DESC * sizeof(struct ring_info));
  3425. memset(tp->Rx_skbuff, 0x0, NUM_RX_DESC * sizeof(struct sk_buff *));
  3426. if (rtl8169_rx_fill(tp, dev, 0, NUM_RX_DESC) != NUM_RX_DESC)
  3427. goto err_out;
  3428. rtl8169_mark_as_last_descriptor(tp->RxDescArray + NUM_RX_DESC - 1);
  3429. return 0;
  3430. err_out:
  3431. rtl8169_rx_clear(tp);
  3432. return -ENOMEM;
  3433. }
  3434. static void rtl8169_unmap_tx_skb(struct pci_dev *pdev, struct ring_info *tx_skb,
  3435. struct TxDesc *desc)
  3436. {
  3437. unsigned int len = tx_skb->len;
  3438. pci_unmap_single(pdev, le64_to_cpu(desc->addr), len, PCI_DMA_TODEVICE);
  3439. desc->opts1 = 0x00;
  3440. desc->opts2 = 0x00;
  3441. desc->addr = 0x00;
  3442. tx_skb->len = 0;
  3443. }
  3444. static void rtl8169_tx_clear(struct rtl8169_private *tp)
  3445. {
  3446. unsigned int i;
  3447. for (i = tp->dirty_tx; i < tp->dirty_tx + NUM_TX_DESC; i++) {
  3448. unsigned int entry = i % NUM_TX_DESC;
  3449. struct ring_info *tx_skb = tp->tx_skb + entry;
  3450. unsigned int len = tx_skb->len;
  3451. if (len) {
  3452. struct sk_buff *skb = tx_skb->skb;
  3453. rtl8169_unmap_tx_skb(tp->pci_dev, tx_skb,
  3454. tp->TxDescArray + entry);
  3455. if (skb) {
  3456. dev_kfree_skb(skb);
  3457. tx_skb->skb = NULL;
  3458. }
  3459. tp->dev->stats.tx_dropped++;
  3460. }
  3461. }
  3462. tp->cur_tx = tp->dirty_tx = 0;
  3463. }
  3464. static void rtl8169_schedule_work(struct net_device *dev, work_func_t task)
  3465. {
  3466. struct rtl8169_private *tp = netdev_priv(dev);
  3467. PREPARE_DELAYED_WORK(&tp->task, task);
  3468. schedule_delayed_work(&tp->task, 4);
  3469. }
  3470. static void rtl8169_wait_for_quiescence(struct net_device *dev)
  3471. {
  3472. struct rtl8169_private *tp = netdev_priv(dev);
  3473. void __iomem *ioaddr = tp->mmio_addr;
  3474. synchronize_irq(dev->irq);
  3475. /* Wait for any pending NAPI task to complete */
  3476. napi_disable(&tp->napi);
  3477. rtl8169_irq_mask_and_ack(ioaddr);
  3478. tp->intr_mask = 0xffff;
  3479. RTL_W16(IntrMask, tp->intr_event);
  3480. napi_enable(&tp->napi);
  3481. }
  3482. static void rtl8169_reinit_task(struct work_struct *work)
  3483. {
  3484. struct rtl8169_private *tp =
  3485. container_of(work, struct rtl8169_private, task.work);
  3486. struct net_device *dev = tp->dev;
  3487. int ret;
  3488. rtnl_lock();
  3489. if (!netif_running(dev))
  3490. goto out_unlock;
  3491. rtl8169_wait_for_quiescence(dev);
  3492. rtl8169_close(dev);
  3493. ret = rtl8169_open(dev);
  3494. if (unlikely(ret < 0)) {
  3495. if (net_ratelimit())
  3496. netif_err(tp, drv, dev,
  3497. "reinit failure (status = %d). Rescheduling\n",
  3498. ret);
  3499. rtl8169_schedule_work(dev, rtl8169_reinit_task);
  3500. }
  3501. out_unlock:
  3502. rtnl_unlock();
  3503. }
  3504. static void rtl8169_reset_task(struct work_struct *work)
  3505. {
  3506. struct rtl8169_private *tp =
  3507. container_of(work, struct rtl8169_private, task.work);
  3508. struct net_device *dev = tp->dev;
  3509. rtnl_lock();
  3510. if (!netif_running(dev))
  3511. goto out_unlock;
  3512. rtl8169_wait_for_quiescence(dev);
  3513. rtl8169_rx_interrupt(dev, tp, tp->mmio_addr, ~(u32)0);
  3514. rtl8169_tx_clear(tp);
  3515. if (tp->dirty_rx == tp->cur_rx) {
  3516. rtl8169_init_ring_indexes(tp);
  3517. rtl_hw_start(dev);
  3518. netif_wake_queue(dev);
  3519. rtl8169_check_link_status(dev, tp, tp->mmio_addr);
  3520. } else {
  3521. if (net_ratelimit())
  3522. netif_emerg(tp, intr, dev, "Rx buffers shortage\n");
  3523. rtl8169_schedule_work(dev, rtl8169_reset_task);
  3524. }
  3525. out_unlock:
  3526. rtnl_unlock();
  3527. }
  3528. static void rtl8169_tx_timeout(struct net_device *dev)
  3529. {
  3530. struct rtl8169_private *tp = netdev_priv(dev);
  3531. rtl8169_hw_reset(tp->mmio_addr);
  3532. /* Let's wait a bit while any (async) irq lands on */
  3533. rtl8169_schedule_work(dev, rtl8169_reset_task);
  3534. }
  3535. static int rtl8169_xmit_frags(struct rtl8169_private *tp, struct sk_buff *skb,
  3536. u32 opts1)
  3537. {
  3538. struct skb_shared_info *info = skb_shinfo(skb);
  3539. unsigned int cur_frag, entry;
  3540. struct TxDesc * uninitialized_var(txd);
  3541. entry = tp->cur_tx;
  3542. for (cur_frag = 0; cur_frag < info->nr_frags; cur_frag++) {
  3543. skb_frag_t *frag = info->frags + cur_frag;
  3544. dma_addr_t mapping;
  3545. u32 status, len;
  3546. void *addr;
  3547. entry = (entry + 1) % NUM_TX_DESC;
  3548. txd = tp->TxDescArray + entry;
  3549. len = frag->size;
  3550. addr = ((void *) page_address(frag->page)) + frag->page_offset;
  3551. mapping = pci_map_single(tp->pci_dev, addr, len, PCI_DMA_TODEVICE);
  3552. /* anti gcc 2.95.3 bugware (sic) */
  3553. status = opts1 | len | (RingEnd * !((entry + 1) % NUM_TX_DESC));
  3554. txd->opts1 = cpu_to_le32(status);
  3555. txd->addr = cpu_to_le64(mapping);
  3556. tp->tx_skb[entry].len = len;
  3557. }
  3558. if (cur_frag) {
  3559. tp->tx_skb[entry].skb = skb;
  3560. txd->opts1 |= cpu_to_le32(LastFrag);
  3561. }
  3562. return cur_frag;
  3563. }
  3564. static inline u32 rtl8169_tso_csum(struct sk_buff *skb, struct net_device *dev)
  3565. {
  3566. if (dev->features & NETIF_F_TSO) {
  3567. u32 mss = skb_shinfo(skb)->gso_size;
  3568. if (mss)
  3569. return LargeSend | ((mss & MSSMask) << MSSShift);
  3570. }
  3571. if (skb->ip_summed == CHECKSUM_PARTIAL) {
  3572. const struct iphdr *ip = ip_hdr(skb);
  3573. if (ip->protocol == IPPROTO_TCP)
  3574. return IPCS | TCPCS;
  3575. else if (ip->protocol == IPPROTO_UDP)
  3576. return IPCS | UDPCS;
  3577. WARN_ON(1); /* we need a WARN() */
  3578. }
  3579. return 0;
  3580. }
  3581. static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb,
  3582. struct net_device *dev)
  3583. {
  3584. struct rtl8169_private *tp = netdev_priv(dev);
  3585. unsigned int frags, entry = tp->cur_tx % NUM_TX_DESC;
  3586. struct TxDesc *txd = tp->TxDescArray + entry;
  3587. void __iomem *ioaddr = tp->mmio_addr;
  3588. dma_addr_t mapping;
  3589. u32 status, len;
  3590. u32 opts1;
  3591. if (unlikely(TX_BUFFS_AVAIL(tp) < skb_shinfo(skb)->nr_frags)) {
  3592. netif_err(tp, drv, dev, "BUG! Tx Ring full when queue awake!\n");
  3593. goto err_stop;
  3594. }
  3595. if (unlikely(le32_to_cpu(txd->opts1) & DescOwn))
  3596. goto err_stop;
  3597. opts1 = DescOwn | rtl8169_tso_csum(skb, dev);
  3598. frags = rtl8169_xmit_frags(tp, skb, opts1);
  3599. if (frags) {
  3600. len = skb_headlen(skb);
  3601. opts1 |= FirstFrag;
  3602. } else {
  3603. len = skb->len;
  3604. opts1 |= FirstFrag | LastFrag;
  3605. tp->tx_skb[entry].skb = skb;
  3606. }
  3607. mapping = pci_map_single(tp->pci_dev, skb->data, len, PCI_DMA_TODEVICE);
  3608. tp->tx_skb[entry].len = len;
  3609. txd->addr = cpu_to_le64(mapping);
  3610. txd->opts2 = cpu_to_le32(rtl8169_tx_vlan_tag(tp, skb));
  3611. wmb();
  3612. /* anti gcc 2.95.3 bugware (sic) */
  3613. status = opts1 | len | (RingEnd * !((entry + 1) % NUM_TX_DESC));
  3614. txd->opts1 = cpu_to_le32(status);
  3615. tp->cur_tx += frags + 1;
  3616. smp_wmb();
  3617. RTL_W8(TxPoll, NPQ); /* set polling bit */
  3618. if (TX_BUFFS_AVAIL(tp) < MAX_SKB_FRAGS) {
  3619. netif_stop_queue(dev);
  3620. smp_rmb();
  3621. if (TX_BUFFS_AVAIL(tp) >= MAX_SKB_FRAGS)
  3622. netif_wake_queue(dev);
  3623. }
  3624. return NETDEV_TX_OK;
  3625. err_stop:
  3626. netif_stop_queue(dev);
  3627. dev->stats.tx_dropped++;
  3628. return NETDEV_TX_BUSY;
  3629. }
  3630. static void rtl8169_pcierr_interrupt(struct net_device *dev)
  3631. {
  3632. struct rtl8169_private *tp = netdev_priv(dev);
  3633. struct pci_dev *pdev = tp->pci_dev;
  3634. void __iomem *ioaddr = tp->mmio_addr;
  3635. u16 pci_status, pci_cmd;
  3636. pci_read_config_word(pdev, PCI_COMMAND, &pci_cmd);
  3637. pci_read_config_word(pdev, PCI_STATUS, &pci_status);
  3638. netif_err(tp, intr, dev, "PCI error (cmd = 0x%04x, status = 0x%04x)\n",
  3639. pci_cmd, pci_status);
  3640. /*
  3641. * The recovery sequence below admits a very elaborated explanation:
  3642. * - it seems to work;
  3643. * - I did not see what else could be done;
  3644. * - it makes iop3xx happy.
  3645. *
  3646. * Feel free to adjust to your needs.
  3647. */
  3648. if (pdev->broken_parity_status)
  3649. pci_cmd &= ~PCI_COMMAND_PARITY;
  3650. else
  3651. pci_cmd |= PCI_COMMAND_SERR | PCI_COMMAND_PARITY;
  3652. pci_write_config_word(pdev, PCI_COMMAND, pci_cmd);
  3653. pci_write_config_word(pdev, PCI_STATUS,
  3654. pci_status & (PCI_STATUS_DETECTED_PARITY |
  3655. PCI_STATUS_SIG_SYSTEM_ERROR | PCI_STATUS_REC_MASTER_ABORT |
  3656. PCI_STATUS_REC_TARGET_ABORT | PCI_STATUS_SIG_TARGET_ABORT));
  3657. /* The infamous DAC f*ckup only happens at boot time */
  3658. if ((tp->cp_cmd & PCIDAC) && !tp->dirty_rx && !tp->cur_rx) {
  3659. netif_info(tp, intr, dev, "disabling PCI DAC\n");
  3660. tp->cp_cmd &= ~PCIDAC;
  3661. RTL_W16(CPlusCmd, tp->cp_cmd);
  3662. dev->features &= ~NETIF_F_HIGHDMA;
  3663. }
  3664. rtl8169_hw_reset(ioaddr);
  3665. rtl8169_schedule_work(dev, rtl8169_reinit_task);
  3666. }
  3667. static void rtl8169_tx_interrupt(struct net_device *dev,
  3668. struct rtl8169_private *tp,
  3669. void __iomem *ioaddr)
  3670. {
  3671. unsigned int dirty_tx, tx_left;
  3672. dirty_tx = tp->dirty_tx;
  3673. smp_rmb();
  3674. tx_left = tp->cur_tx - dirty_tx;
  3675. while (tx_left > 0) {
  3676. unsigned int entry = dirty_tx % NUM_TX_DESC;
  3677. struct ring_info *tx_skb = tp->tx_skb + entry;
  3678. u32 len = tx_skb->len;
  3679. u32 status;
  3680. rmb();
  3681. status = le32_to_cpu(tp->TxDescArray[entry].opts1);
  3682. if (status & DescOwn)
  3683. break;
  3684. dev->stats.tx_bytes += len;
  3685. dev->stats.tx_packets++;
  3686. rtl8169_unmap_tx_skb(tp->pci_dev, tx_skb, tp->TxDescArray + entry);
  3687. if (status & LastFrag) {
  3688. dev_kfree_skb(tx_skb->skb);
  3689. tx_skb->skb = NULL;
  3690. }
  3691. dirty_tx++;
  3692. tx_left--;
  3693. }
  3694. if (tp->dirty_tx != dirty_tx) {
  3695. tp->dirty_tx = dirty_tx;
  3696. smp_wmb();
  3697. if (netif_queue_stopped(dev) &&
  3698. (TX_BUFFS_AVAIL(tp) >= MAX_SKB_FRAGS)) {
  3699. netif_wake_queue(dev);
  3700. }
  3701. /*
  3702. * 8168 hack: TxPoll requests are lost when the Tx packets are
  3703. * too close. Let's kick an extra TxPoll request when a burst
  3704. * of start_xmit activity is detected (if it is not detected,
  3705. * it is slow enough). -- FR
  3706. */
  3707. smp_rmb();
  3708. if (tp->cur_tx != dirty_tx)
  3709. RTL_W8(TxPoll, NPQ);
  3710. }
  3711. }
  3712. static inline int rtl8169_fragmented_frame(u32 status)
  3713. {
  3714. return (status & (FirstFrag | LastFrag)) != (FirstFrag | LastFrag);
  3715. }
  3716. static inline void rtl8169_rx_csum(struct sk_buff *skb, struct RxDesc *desc)
  3717. {
  3718. u32 opts1 = le32_to_cpu(desc->opts1);
  3719. u32 status = opts1 & RxProtoMask;
  3720. if (((status == RxProtoTCP) && !(opts1 & TCPFail)) ||
  3721. ((status == RxProtoUDP) && !(opts1 & UDPFail)) ||
  3722. ((status == RxProtoIP) && !(opts1 & IPFail)))
  3723. skb->ip_summed = CHECKSUM_UNNECESSARY;
  3724. else
  3725. skb->ip_summed = CHECKSUM_NONE;
  3726. }
  3727. static inline bool rtl8169_try_rx_copy(struct sk_buff **sk_buff,
  3728. struct rtl8169_private *tp, int pkt_size,
  3729. dma_addr_t addr)
  3730. {
  3731. struct sk_buff *skb;
  3732. bool done = false;
  3733. if (pkt_size >= rx_copybreak)
  3734. goto out;
  3735. skb = netdev_alloc_skb_ip_align(tp->dev, pkt_size);
  3736. if (!skb)
  3737. goto out;
  3738. pci_dma_sync_single_for_cpu(tp->pci_dev, addr, pkt_size,
  3739. PCI_DMA_FROMDEVICE);
  3740. skb_copy_from_linear_data(*sk_buff, skb->data, pkt_size);
  3741. *sk_buff = skb;
  3742. done = true;
  3743. out:
  3744. return done;
  3745. }
  3746. static int rtl8169_rx_interrupt(struct net_device *dev,
  3747. struct rtl8169_private *tp,
  3748. void __iomem *ioaddr, u32 budget)
  3749. {
  3750. unsigned int cur_rx, rx_left;
  3751. unsigned int delta, count;
  3752. cur_rx = tp->cur_rx;
  3753. rx_left = NUM_RX_DESC + tp->dirty_rx - cur_rx;
  3754. rx_left = min(rx_left, budget);
  3755. for (; rx_left > 0; rx_left--, cur_rx++) {
  3756. unsigned int entry = cur_rx % NUM_RX_DESC;
  3757. struct RxDesc *desc = tp->RxDescArray + entry;
  3758. u32 status;
  3759. rmb();
  3760. status = le32_to_cpu(desc->opts1);
  3761. if (status & DescOwn)
  3762. break;
  3763. if (unlikely(status & RxRES)) {
  3764. netif_info(tp, rx_err, dev, "Rx ERROR. status = %08x\n",
  3765. status);
  3766. dev->stats.rx_errors++;
  3767. if (status & (RxRWT | RxRUNT))
  3768. dev->stats.rx_length_errors++;
  3769. if (status & RxCRC)
  3770. dev->stats.rx_crc_errors++;
  3771. if (status & RxFOVF) {
  3772. rtl8169_schedule_work(dev, rtl8169_reset_task);
  3773. dev->stats.rx_fifo_errors++;
  3774. }
  3775. rtl8169_mark_to_asic(desc, tp->rx_buf_sz);
  3776. } else {
  3777. struct sk_buff *skb = tp->Rx_skbuff[entry];
  3778. dma_addr_t addr = le64_to_cpu(desc->addr);
  3779. int pkt_size = (status & 0x00001FFF) - 4;
  3780. struct pci_dev *pdev = tp->pci_dev;
  3781. /*
  3782. * The driver does not support incoming fragmented
  3783. * frames. They are seen as a symptom of over-mtu
  3784. * sized frames.
  3785. */
  3786. if (unlikely(rtl8169_fragmented_frame(status))) {
  3787. dev->stats.rx_dropped++;
  3788. dev->stats.rx_length_errors++;
  3789. rtl8169_mark_to_asic(desc, tp->rx_buf_sz);
  3790. continue;
  3791. }
  3792. rtl8169_rx_csum(skb, desc);
  3793. if (rtl8169_try_rx_copy(&skb, tp, pkt_size, addr)) {
  3794. pci_dma_sync_single_for_device(pdev, addr,
  3795. pkt_size, PCI_DMA_FROMDEVICE);
  3796. rtl8169_mark_to_asic(desc, tp->rx_buf_sz);
  3797. } else {
  3798. pci_unmap_single(pdev, addr, tp->rx_buf_sz,
  3799. PCI_DMA_FROMDEVICE);
  3800. tp->Rx_skbuff[entry] = NULL;
  3801. }
  3802. skb_put(skb, pkt_size);
  3803. skb->protocol = eth_type_trans(skb, dev);
  3804. if (rtl8169_rx_vlan_skb(tp, desc, skb) < 0)
  3805. netif_receive_skb(skb);
  3806. dev->stats.rx_bytes += pkt_size;
  3807. dev->stats.rx_packets++;
  3808. }
  3809. /* Work around for AMD plateform. */
  3810. if ((desc->opts2 & cpu_to_le32(0xfffe000)) &&
  3811. (tp->mac_version == RTL_GIGA_MAC_VER_05)) {
  3812. desc->opts2 = 0;
  3813. cur_rx++;
  3814. }
  3815. }
  3816. count = cur_rx - tp->cur_rx;
  3817. tp->cur_rx = cur_rx;
  3818. delta = rtl8169_rx_fill(tp, dev, tp->dirty_rx, tp->cur_rx);
  3819. if (!delta && count)
  3820. netif_info(tp, intr, dev, "no Rx buffer allocated\n");
  3821. tp->dirty_rx += delta;
  3822. /*
  3823. * FIXME: until there is periodic timer to try and refill the ring,
  3824. * a temporary shortage may definitely kill the Rx process.
  3825. * - disable the asic to try and avoid an overflow and kick it again
  3826. * after refill ?
  3827. * - how do others driver handle this condition (Uh oh...).
  3828. */
  3829. if (tp->dirty_rx + NUM_RX_DESC == tp->cur_rx)
  3830. netif_emerg(tp, intr, dev, "Rx buffers exhausted\n");
  3831. return count;
  3832. }
  3833. static irqreturn_t rtl8169_interrupt(int irq, void *dev_instance)
  3834. {
  3835. struct net_device *dev = dev_instance;
  3836. struct rtl8169_private *tp = netdev_priv(dev);
  3837. void __iomem *ioaddr = tp->mmio_addr;
  3838. int handled = 0;
  3839. int status;
  3840. /* loop handling interrupts until we have no new ones or
  3841. * we hit a invalid/hotplug case.
  3842. */
  3843. status = RTL_R16(IntrStatus);
  3844. while (status && status != 0xffff) {
  3845. handled = 1;
  3846. /* Handle all of the error cases first. These will reset
  3847. * the chip, so just exit the loop.
  3848. */
  3849. if (unlikely(!netif_running(dev))) {
  3850. rtl8169_asic_down(ioaddr);
  3851. break;
  3852. }
  3853. /* Work around for rx fifo overflow */
  3854. if (unlikely(status & RxFIFOOver) &&
  3855. (tp->mac_version == RTL_GIGA_MAC_VER_11)) {
  3856. netif_stop_queue(dev);
  3857. rtl8169_tx_timeout(dev);
  3858. break;
  3859. }
  3860. if (unlikely(status & SYSErr)) {
  3861. rtl8169_pcierr_interrupt(dev);
  3862. break;
  3863. }
  3864. if (status & LinkChg)
  3865. rtl8169_check_link_status(dev, tp, ioaddr);
  3866. /* We need to see the lastest version of tp->intr_mask to
  3867. * avoid ignoring an MSI interrupt and having to wait for
  3868. * another event which may never come.
  3869. */
  3870. smp_rmb();
  3871. if (status & tp->intr_mask & tp->napi_event) {
  3872. RTL_W16(IntrMask, tp->intr_event & ~tp->napi_event);
  3873. tp->intr_mask = ~tp->napi_event;
  3874. if (likely(napi_schedule_prep(&tp->napi)))
  3875. __napi_schedule(&tp->napi);
  3876. else
  3877. netif_info(tp, intr, dev,
  3878. "interrupt %04x in poll\n", status);
  3879. }
  3880. /* We only get a new MSI interrupt when all active irq
  3881. * sources on the chip have been acknowledged. So, ack
  3882. * everything we've seen and check if new sources have become
  3883. * active to avoid blocking all interrupts from the chip.
  3884. */
  3885. RTL_W16(IntrStatus,
  3886. (status & RxFIFOOver) ? (status | RxOverflow) : status);
  3887. status = RTL_R16(IntrStatus);
  3888. }
  3889. return IRQ_RETVAL(handled);
  3890. }
  3891. static int rtl8169_poll(struct napi_struct *napi, int budget)
  3892. {
  3893. struct rtl8169_private *tp = container_of(napi, struct rtl8169_private, napi);
  3894. struct net_device *dev = tp->dev;
  3895. void __iomem *ioaddr = tp->mmio_addr;
  3896. int work_done;
  3897. work_done = rtl8169_rx_interrupt(dev, tp, ioaddr, (u32) budget);
  3898. rtl8169_tx_interrupt(dev, tp, ioaddr);
  3899. if (work_done < budget) {
  3900. napi_complete(napi);
  3901. /* We need for force the visibility of tp->intr_mask
  3902. * for other CPUs, as we can loose an MSI interrupt
  3903. * and potentially wait for a retransmit timeout if we don't.
  3904. * The posted write to IntrMask is safe, as it will
  3905. * eventually make it to the chip and we won't loose anything
  3906. * until it does.
  3907. */
  3908. tp->intr_mask = 0xffff;
  3909. smp_wmb();
  3910. RTL_W16(IntrMask, tp->intr_event);
  3911. }
  3912. return work_done;
  3913. }
  3914. static void rtl8169_rx_missed(struct net_device *dev, void __iomem *ioaddr)
  3915. {
  3916. struct rtl8169_private *tp = netdev_priv(dev);
  3917. if (tp->mac_version > RTL_GIGA_MAC_VER_06)
  3918. return;
  3919. dev->stats.rx_missed_errors += (RTL_R32(RxMissed) & 0xffffff);
  3920. RTL_W32(RxMissed, 0);
  3921. }
  3922. static void rtl8169_down(struct net_device *dev)
  3923. {
  3924. struct rtl8169_private *tp = netdev_priv(dev);
  3925. void __iomem *ioaddr = tp->mmio_addr;
  3926. unsigned int intrmask;
  3927. rtl8169_delete_timer(dev);
  3928. netif_stop_queue(dev);
  3929. napi_disable(&tp->napi);
  3930. core_down:
  3931. spin_lock_irq(&tp->lock);
  3932. rtl8169_asic_down(ioaddr);
  3933. rtl8169_rx_missed(dev, ioaddr);
  3934. spin_unlock_irq(&tp->lock);
  3935. synchronize_irq(dev->irq);
  3936. /* Give a racing hard_start_xmit a few cycles to complete. */
  3937. synchronize_sched(); /* FIXME: should this be synchronize_irq()? */
  3938. /*
  3939. * And now for the 50k$ question: are IRQ disabled or not ?
  3940. *
  3941. * Two paths lead here:
  3942. * 1) dev->close
  3943. * -> netif_running() is available to sync the current code and the
  3944. * IRQ handler. See rtl8169_interrupt for details.
  3945. * 2) dev->change_mtu
  3946. * -> rtl8169_poll can not be issued again and re-enable the
  3947. * interruptions. Let's simply issue the IRQ down sequence again.
  3948. *
  3949. * No loop if hotpluged or major error (0xffff).
  3950. */
  3951. intrmask = RTL_R16(IntrMask);
  3952. if (intrmask && (intrmask != 0xffff))
  3953. goto core_down;
  3954. rtl8169_tx_clear(tp);
  3955. rtl8169_rx_clear(tp);
  3956. }
  3957. static int rtl8169_close(struct net_device *dev)
  3958. {
  3959. struct rtl8169_private *tp = netdev_priv(dev);
  3960. struct pci_dev *pdev = tp->pci_dev;
  3961. /* update counters before going down */
  3962. rtl8169_update_counters(dev);
  3963. rtl8169_down(dev);
  3964. free_irq(dev->irq, dev);
  3965. pci_free_consistent(pdev, R8169_RX_RING_BYTES, tp->RxDescArray,
  3966. tp->RxPhyAddr);
  3967. pci_free_consistent(pdev, R8169_TX_RING_BYTES, tp->TxDescArray,
  3968. tp->TxPhyAddr);
  3969. tp->TxDescArray = NULL;
  3970. tp->RxDescArray = NULL;
  3971. return 0;
  3972. }
  3973. static void rtl_set_rx_mode(struct net_device *dev)
  3974. {
  3975. struct rtl8169_private *tp = netdev_priv(dev);
  3976. void __iomem *ioaddr = tp->mmio_addr;
  3977. unsigned long flags;
  3978. u32 mc_filter[2]; /* Multicast hash filter */
  3979. int rx_mode;
  3980. u32 tmp = 0;
  3981. if (dev->flags & IFF_PROMISC) {
  3982. /* Unconditionally log net taps. */
  3983. netif_notice(tp, link, dev, "Promiscuous mode enabled\n");
  3984. rx_mode =
  3985. AcceptBroadcast | AcceptMulticast | AcceptMyPhys |
  3986. AcceptAllPhys;
  3987. mc_filter[1] = mc_filter[0] = 0xffffffff;
  3988. } else if ((netdev_mc_count(dev) > multicast_filter_limit) ||
  3989. (dev->flags & IFF_ALLMULTI)) {
  3990. /* Too many to filter perfectly -- accept all multicasts. */
  3991. rx_mode = AcceptBroadcast | AcceptMulticast | AcceptMyPhys;
  3992. mc_filter[1] = mc_filter[0] = 0xffffffff;
  3993. } else {
  3994. struct dev_mc_list *mclist;
  3995. rx_mode = AcceptBroadcast | AcceptMyPhys;
  3996. mc_filter[1] = mc_filter[0] = 0;
  3997. netdev_for_each_mc_addr(mclist, dev) {
  3998. int bit_nr = ether_crc(ETH_ALEN, mclist->dmi_addr) >> 26;
  3999. mc_filter[bit_nr >> 5] |= 1 << (bit_nr & 31);
  4000. rx_mode |= AcceptMulticast;
  4001. }
  4002. }
  4003. spin_lock_irqsave(&tp->lock, flags);
  4004. tmp = rtl8169_rx_config | rx_mode |
  4005. (RTL_R32(RxConfig) & rtl_chip_info[tp->chipset].RxConfigMask);
  4006. if (tp->mac_version > RTL_GIGA_MAC_VER_06) {
  4007. u32 data = mc_filter[0];
  4008. mc_filter[0] = swab32(mc_filter[1]);
  4009. mc_filter[1] = swab32(data);
  4010. }
  4011. RTL_W32(MAR0 + 0, mc_filter[0]);
  4012. RTL_W32(MAR0 + 4, mc_filter[1]);
  4013. RTL_W32(RxConfig, tmp);
  4014. spin_unlock_irqrestore(&tp->lock, flags);
  4015. }
  4016. /**
  4017. * rtl8169_get_stats - Get rtl8169 read/write statistics
  4018. * @dev: The Ethernet Device to get statistics for
  4019. *
  4020. * Get TX/RX statistics for rtl8169
  4021. */
  4022. static struct net_device_stats *rtl8169_get_stats(struct net_device *dev)
  4023. {
  4024. struct rtl8169_private *tp = netdev_priv(dev);
  4025. void __iomem *ioaddr = tp->mmio_addr;
  4026. unsigned long flags;
  4027. if (netif_running(dev)) {
  4028. spin_lock_irqsave(&tp->lock, flags);
  4029. rtl8169_rx_missed(dev, ioaddr);
  4030. spin_unlock_irqrestore(&tp->lock, flags);
  4031. }
  4032. return &dev->stats;
  4033. }
  4034. static void rtl8169_net_suspend(struct net_device *dev)
  4035. {
  4036. if (!netif_running(dev))
  4037. return;
  4038. netif_device_detach(dev);
  4039. netif_stop_queue(dev);
  4040. }
  4041. #ifdef CONFIG_PM
  4042. static int rtl8169_suspend(struct device *device)
  4043. {
  4044. struct pci_dev *pdev = to_pci_dev(device);
  4045. struct net_device *dev = pci_get_drvdata(pdev);
  4046. rtl8169_net_suspend(dev);
  4047. return 0;
  4048. }
  4049. static int rtl8169_resume(struct device *device)
  4050. {
  4051. struct pci_dev *pdev = to_pci_dev(device);
  4052. struct net_device *dev = pci_get_drvdata(pdev);
  4053. if (!netif_running(dev))
  4054. goto out;
  4055. netif_device_attach(dev);
  4056. rtl8169_schedule_work(dev, rtl8169_reset_task);
  4057. out:
  4058. return 0;
  4059. }
  4060. static const struct dev_pm_ops rtl8169_pm_ops = {
  4061. .suspend = rtl8169_suspend,
  4062. .resume = rtl8169_resume,
  4063. .freeze = rtl8169_suspend,
  4064. .thaw = rtl8169_resume,
  4065. .poweroff = rtl8169_suspend,
  4066. .restore = rtl8169_resume,
  4067. };
  4068. #define RTL8169_PM_OPS (&rtl8169_pm_ops)
  4069. #else /* !CONFIG_PM */
  4070. #define RTL8169_PM_OPS NULL
  4071. #endif /* !CONFIG_PM */
  4072. static void rtl_shutdown(struct pci_dev *pdev)
  4073. {
  4074. struct net_device *dev = pci_get_drvdata(pdev);
  4075. struct rtl8169_private *tp = netdev_priv(dev);
  4076. void __iomem *ioaddr = tp->mmio_addr;
  4077. rtl8169_net_suspend(dev);
  4078. /* restore original MAC address */
  4079. rtl_rar_set(tp, dev->perm_addr);
  4080. spin_lock_irq(&tp->lock);
  4081. rtl8169_asic_down(ioaddr);
  4082. spin_unlock_irq(&tp->lock);
  4083. if (system_state == SYSTEM_POWER_OFF) {
  4084. /* WoL fails with some 8168 when the receiver is disabled. */
  4085. if (tp->features & RTL_FEATURE_WOL) {
  4086. pci_clear_master(pdev);
  4087. RTL_W8(ChipCmd, CmdRxEnb);
  4088. /* PCI commit */
  4089. RTL_R8(ChipCmd);
  4090. }
  4091. pci_wake_from_d3(pdev, true);
  4092. pci_set_power_state(pdev, PCI_D3hot);
  4093. }
  4094. }
  4095. static struct pci_driver rtl8169_pci_driver = {
  4096. .name = MODULENAME,
  4097. .id_table = rtl8169_pci_tbl,
  4098. .probe = rtl8169_init_one,
  4099. .remove = __devexit_p(rtl8169_remove_one),
  4100. .shutdown = rtl_shutdown,
  4101. .driver.pm = RTL8169_PM_OPS,
  4102. };
  4103. static int __init rtl8169_init_module(void)
  4104. {
  4105. return pci_register_driver(&rtl8169_pci_driver);
  4106. }
  4107. static void __exit rtl8169_cleanup_module(void)
  4108. {
  4109. pci_unregister_driver(&rtl8169_pci_driver);
  4110. }
  4111. module_init(rtl8169_init_module);
  4112. module_exit(rtl8169_cleanup_module);