r8169.c 116 KB

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